refactor(tools): unify tool APIs and result handling (#38367)
This commit is contained in:
parent
8cac010bac
commit
79c1544072
133 changed files with 3602 additions and 2770 deletions
|
|
@ -7,7 +7,7 @@ const echo = (description: string, result: string) =>
|
|||
description,
|
||||
input: Schema.Struct({}),
|
||||
output: Schema.String,
|
||||
run: () => Effect.succeed(result),
|
||||
execute: () => Effect.succeed(result),
|
||||
})
|
||||
|
||||
const value = async (runtime: CodeMode.Runtime, code: string) => {
|
||||
|
|
@ -88,7 +88,7 @@ describe("callable namespaces", () => {
|
|||
expect(diagnostic.message).toContain("Unknown tool 'issues.missing'")
|
||||
})
|
||||
|
||||
test("a namespace without its own definition stays non-callable", async () => {
|
||||
test("a namespace without its own tool stays non-callable", async () => {
|
||||
const nested = CodeMode.make({ tools: { "issues.list": echo("List issues", "list") } })
|
||||
const diagnostic = await failure(nested, `return await tools.issues({})`)
|
||||
expect(diagnostic.kind).toBe("UnknownTool")
|
||||
|
|
@ -114,9 +114,9 @@ describe("blocked member names on tool paths", () => {
|
|||
expect(await value(runtime, `return Object.keys(tools.issues)`)).toEqual(["constructor"])
|
||||
})
|
||||
|
||||
test("a literal __proto__ key cannot poison a namespace into a fake definition", async () => {
|
||||
test("a literal __proto__ key cannot poison a namespace into a fake tool", async () => {
|
||||
const poisoned = CodeMode.make({
|
||||
tools: { ns: { "__proto__": echo("Hidden", "hidden"), real: echo("Real tool", "real") } },
|
||||
tools: { ns: { __proto__: echo("Hidden", "hidden"), real: echo("Real tool", "real") } },
|
||||
})
|
||||
expect(poisoned.catalog().map((tool) => tool.path)).toEqual(["ns.real"])
|
||||
expect(await value(poisoned, `return await tools.ns.real({})`)).toBe("real")
|
||||
|
|
@ -138,7 +138,7 @@ describe("empty segments", () => {
|
|||
})
|
||||
|
||||
describe("canonical path collisions", () => {
|
||||
test("the last definition supplied for a canonical path wins", async () => {
|
||||
test("the last tool supplied for a canonical path wins", async () => {
|
||||
const runtime = CodeMode.make({
|
||||
tools: { "issues.list": echo("First", "first"), issues: { list: echo("Second", "second") } },
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue