@ui-calling/anthropic 0.1.0-preview.2 → 0.1.0-preview.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -3
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,14 +7,19 @@ type AnthropicAdapterOptions = {
|
|
|
7
7
|
onLink?: (link: SurfaceLink) => void;
|
|
8
8
|
/** Offer only some surfaces, e.g. hide everything but an account-linking screen until the user is known. */
|
|
9
9
|
filter?: (toolName: string) => boolean;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Set on every turn if your agent runs on screen events: `true` when a screen started it, `false` when the user wrote.
|
|
12
|
+
* `stay_silent` is then always offered (the tool list never changes) and refused on the user's turns.
|
|
13
|
+
*/
|
|
11
14
|
woken?: boolean;
|
|
12
15
|
/** Called when the model calls `stay_silent`: send nothing this turn, whatever text it writes after. */
|
|
13
16
|
onSilent?: (reason: string) => void;
|
|
14
17
|
};
|
|
15
18
|
/**
|
|
16
|
-
* Tool definitions for a manual loop with `client.messages.create({ tools })`.
|
|
17
|
-
* `{ woken
|
|
19
|
+
* Tool definitions for a manual loop with `client.messages.create({ tools })`. If your agent runs on screen
|
|
20
|
+
* events, pass `{ woken }` on every turn: `stay_silent` is then always in the list, which models with preserved
|
|
21
|
+
* thinking need. Give `anthropicToolResult` the same turn in `who` (`{ ...who, woken }`), so it refuses
|
|
22
|
+
* `stay_silent` on the user's turns and returns `run.silent` on woken ones.
|
|
18
23
|
*/
|
|
19
24
|
declare function anthropicTools(ui: UiCalling, filter?: (toolName: string) => boolean, turn?: {
|
|
20
25
|
woken?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,8 @@ function anthropicRunnableTools(ui, who, opts = {}) {
|
|
|
17
17
|
description: t.description,
|
|
18
18
|
inputSchema: t.input_schema,
|
|
19
19
|
run: async (input) => {
|
|
20
|
-
const
|
|
20
|
+
const resolved = typeof who === "function" ? who() : who;
|
|
21
|
+
const run = await ui.runTool(t.name, input, opts.woken === void 0 ? resolved : { ...resolved, woken: opts.woken });
|
|
21
22
|
if (run.ok && run.silent) opts.onSilent?.(run.reason);
|
|
22
23
|
else if (run.ok) opts.onLink?.(run.link);
|
|
23
24
|
return run.content;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type Anthropic from \"@anthropic-ai/sdk\";\nimport { betaTool } from \"@anthropic-ai/sdk/helpers/beta/json-schema\";\nimport type { SurfaceLink, ToolRun, UiCalling, Who } from \"@ui-calling/core\";\n\nexport type AnthropicAdapterOptions = {\n /** Called with every link a tool call creates: deliver it on your channel (e.g. as a WhatsApp button). */\n onLink?: (link: SurfaceLink) => void;\n /** Offer only some surfaces, e.g. hide everything but an account-linking screen until the user is known. */\n filter?: (toolName: string) => boolean;\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type Anthropic from \"@anthropic-ai/sdk\";\nimport { betaTool } from \"@anthropic-ai/sdk/helpers/beta/json-schema\";\nimport type { SurfaceLink, ToolRun, UiCalling, Who } from \"@ui-calling/core\";\n\nexport type AnthropicAdapterOptions = {\n /** Called with every link a tool call creates: deliver it on your channel (e.g. as a WhatsApp button). */\n onLink?: (link: SurfaceLink) => void;\n /** Offer only some surfaces, e.g. hide everything but an account-linking screen until the user is known. */\n filter?: (toolName: string) => boolean;\n /**\n * Set on every turn if your agent runs on screen events: `true` when a screen started it, `false` when the user wrote.\n * `stay_silent` is then always offered (the tool list never changes) and refused on the user's turns.\n */\n woken?: boolean;\n /** Called when the model calls `stay_silent`: send nothing this turn, whatever text it writes after. */\n onSilent?: (reason: string) => void;\n};\n\n/**\n * Tool definitions for a manual loop with `client.messages.create({ tools })`. If your agent runs on screen\n * events, pass `{ woken }` on every turn: `stay_silent` is then always in the list, which models with preserved\n * thinking need. Give `anthropicToolResult` the same turn in `who` (`{ ...who, woken }`), so it refuses\n * `stay_silent` on the user's turns and returns `run.silent` on woken ones.\n */\nexport function anthropicTools(ui: UiCalling, filter?: (toolName: string) => boolean, turn: { woken?: boolean } = {}): Anthropic.Tool[] {\n return ui\n .tools({ ...turn, filter })\n .map((t) => ({ name: t.name, description: t.description, input_schema: t.input_schema as Anthropic.Tool.InputSchema }));\n}\n\n/**\n * Run one `tool_use` block from a manual loop. Returns the `tool_result` block to send back and the\n * run: deliver `run.link` when `run.ok`, and send nothing this turn when `run.silent`. Failures come back\n * as `is_error` results, never throws.\n * Pass the `filter` you gave `anthropicTools`, so a tool the model wasn't offered is refused.\n */\nexport async function anthropicToolResult(\n ui: UiCalling,\n block: { id: string; name: string; input: unknown },\n who: Who,\n filter?: (toolName: string) => boolean,\n): Promise<{ result: Anthropic.ToolResultBlockParam; run: ToolRun }> {\n const run = await ui.runTool(block.name, block.input, who, filter);\n return {\n result: { type: \"tool_result\", tool_use_id: block.id, content: run.content, ...(run.ok ? {} : { is_error: true }) },\n run,\n };\n}\n\n/**\n * Runnable tools for the SDK's tool runner, which loops for you:\n *\n * const links: SurfaceLink[] = [];\n * const final = await client.beta.messages.toolRunner({\n * model, max_tokens, messages,\n * tools: anthropicRunnableTools(ui, { conversationId, subject }, { onLink: (l) => links.push(l) }),\n * });\n * // send the final text, with links[] as buttons\n */\nexport function anthropicRunnableTools(ui: UiCalling, who: Who | (() => Who), opts: AnthropicAdapterOptions = {}) {\n return ui\n .tools({ woken: opts.woken, filter: opts.filter })\n .map((t) =>\n betaTool({\n name: t.name,\n description: t.description,\n inputSchema: t.input_schema as { type: \"object\" },\n run: async (input) => {\n const resolved = typeof who === \"function\" ? who() : who;\n const run = await ui.runTool(t.name, input, opts.woken === undefined ? resolved : { ...resolved, woken: opts.woken });\n if (run.ok && run.silent) opts.onSilent?.(run.reason);\n else if (run.ok) opts.onLink?.(run.link);\n return run.content;\n },\n }),\n );\n}\n"],"mappings":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-preview.
|
|
3
|
+
"version": "0.1.0-preview.3",
|
|
4
4
|
"description": "Use ui-calling surfaces as tools with the Anthropic SDK (tool runner or manual loop).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"removeNodeProtocol": false
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@ui-calling/core": "^0.1.0-preview.
|
|
52
|
+
"@ui-calling/core": "^0.1.0-preview.3"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@anthropic-ai/sdk": ">=1.0.0"
|