| 1 | import { defineTool } from "@deepseek-ai/dsh-tools"; |
| 2 | //#region lib/types/present.js |
| 3 | /** |
| 4 | * Render provider-directory inspection. |
| 5 | * @returns replay-safe generic call presentation. |
| 6 | */ |
| 7 | function presentInspectListCall() { |
| 8 | return { |
| 9 | card: "generic", |
| 10 | kind: "read", |
| 11 | title: "List Cordis Inspect Providers" |
| 12 | }; |
| 13 | } |
| 14 | /** |
| 15 | * Render one provider query. |
| 16 | * @param args - target platform, provider, and method. |
| 17 | * @returns replay-safe generic call presentation. |
| 18 | */ |
| 19 | function presentInspectQueryCall(args) { |
| 20 | return { |
| 21 | card: "generic", |
| 22 | kind: "read", |
| 23 | title: `Query Cordis ${args.platform} ${args.provider}.${args.method}` |
| 24 | }; |
| 25 | } |
| 26 | //#endregion |
| 27 | //#region lib/types/index.js |
| 28 | const name = "tool-cordis"; |
| 29 | const inject = ["tools", "cordisInspect"]; |
| 30 | function requireAgent(exec) { |
| 31 | if (exec.agent === void 0) throw new Error("Cordis inspection requires an Agent-backed session"); |
| 32 | return exec.agent; |
| 33 | } |
| 34 | /** Register read-only runtime inspection tools over the Host providers that |
| 35 | * `@deepseek-ai/dsh-tool-cordis/host` registers once per process. |
| 36 | * @param ctx Agent-scoped registration context. |
| 37 | */ |
| 38 | function apply(ctx) { |
| 39 | ctx.tools.register(defineTool({ |
| 40 | name: "cordis_inspect_list", |
| 41 | description: "List every Cordis Inspect Provider currently known to the Host, including local Host Providers and the latest manifests synchronized from the Client. Each entry includes its platform, purpose, read-only methods, and input/output schemas. Call this Tool before writing or configuring a plugin, then select the provider and method for cordis_inspect_query from its result. Do not guess names or treat an Inspect method as a business Service that Plugin code can call.", |
| 42 | parameters: {}, |
| 43 | output: { |
| 44 | schema: { type: "json" }, |
| 45 | render: (_args, value) => [{ |
| 46 | type: "text", |
| 47 | text: JSON.stringify(value, null, 2) |
| 48 | }] |
| 49 | }, |
| 50 | execute(_args, _exec) { |
| 51 | return Promise.resolve({ providers: ctx.cordisInspect.list() }); |
| 52 | }, |
| 53 | presentCall: presentInspectListCall |
| 54 | })); |
| 55 | ctx.tools.register(defineTool({ |
| 56 | name: "cordis_inspect_query", |
| 57 | description: "Run a read-only query declared by an Inspect Provider. platform, provider, and method must come from cordis_inspect_list, and input must satisfy that method's schema. Use this Tool before writing plugin code to read exact Service methods, Event modes, plugin Config schemas, Tool schemas, theme tokens, or live Slot trees and props. Host queries run locally. A Client query waits for the first valid page response within the configured timeout; otherwise it reports a Client failure or asks you to reconnect and retry. This Tool cannot invoke business Service methods or modify the runtime.", |
| 58 | parameters: { |
| 59 | platform: { |
| 60 | type: "string", |
| 61 | required: true, |
| 62 | enum: ["host", "client"], |
| 63 | description: "Runtime platform that owns the Provider." |
| 64 | }, |
| 65 | provider: { |
| 66 | type: "string", |
| 67 | required: true, |
| 68 | description: "Exact Provider ID returned by cordis_inspect_list." |
| 69 | }, |
| 70 | method: { |
| 71 | type: "string", |
| 72 | required: true, |
| 73 | description: "Exact method name declared by the Provider manifest." |
| 74 | }, |
| 75 | input: { |
| 76 | type: "json", |
| 77 | description: "Optional query input; it must satisfy the method input schema." |
| 78 | } |
| 79 | }, |
| 80 | output: { |
| 81 | schema: { type: "json" }, |
| 82 | render: (_args, value) => [{ |
| 83 | type: "text", |
| 84 | text: JSON.stringify(value, null, 2) |
| 85 | }] |
| 86 | }, |
| 87 | async execute(args, exec) { |
| 88 | const data = await ctx.cordisInspect.query(args.platform, args.provider, args.method, args.input, requireAgent(exec), exec.signal); |
| 89 | return { |
| 90 | platform: args.platform, |
| 91 | provider: args.provider, |
| 92 | method: args.method, |
| 93 | data |
| 94 | }; |
| 95 | }, |
| 96 | presentCall: presentInspectQueryCall |
| 97 | })); |
| 98 | } |
| 99 | //#endregion |
| 100 | export { apply, inject, name }; |
| 101 |