@ui-calling/anthropic 0.0.0-stage → 0.1.0-preview.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 San Pau
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,14 @@
1
- # Temporary Holding Version
1
+ # @ui-calling/anthropic
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ui-calling surfaces as tools for the Anthropic SDK, with the tool runner or a manual loop.
4
+
5
+ ```ts
6
+ import { anthropicRunnableTools } from "@ui-calling/anthropic";
7
+
8
+ const runner = client.beta.messages.toolRunner({
9
+ model: "claude-opus-5-5", max_tokens: 16000, messages,
10
+ tools: anthropicRunnableTools(ui, { conversationId, subject }, { onLink: (link) => links.push(link) }),
11
+ });
12
+ ```
13
+
14
+ Manual loop: `anthropicTools(ui, filter?)` for `tools`, and `anthropicToolResult(ui, block, who, filter?)` for each `tool_use`, which returns `{ result, run }` and never throws. Both, with a whole loop: `npx ui-calling guide agent`. Turns started by the screens: `npx ui-calling guide running`.
@@ -0,0 +1,51 @@
1
+ import * as _anthropic_ai_sdk_lib_tools_BetaRunnableTool_mjs from '@anthropic-ai/sdk/lib/tools/BetaRunnableTool.mjs';
2
+ import Anthropic from '@anthropic-ai/sdk';
3
+ import { SurfaceLink, UiCalling, Who, ToolRun } from '@ui-calling/core';
4
+
5
+ type AnthropicAdapterOptions = {
6
+ /** Called with every link a tool call creates: deliver it on your channel (e.g. as a WhatsApp button). */
7
+ onLink?: (link: SurfaceLink) => void;
8
+ /** Offer only some surfaces, e.g. hide everything but an account-linking screen until the user is known. */
9
+ filter?: (toolName: string) => boolean;
10
+ /** A screen event started this turn, not a user message: also offer `stay_silent`. */
11
+ woken?: boolean;
12
+ /** Called when the model calls `stay_silent`: send nothing this turn, whatever text it writes after. */
13
+ onSilent?: (reason: string) => void;
14
+ };
15
+ /**
16
+ * Tool definitions for a manual loop with `client.messages.create({ tools })`. On a woken turn pass
17
+ * `{ woken: true }` to add `stay_silent`; `anthropicToolResult` then returns `run.silent` when it's called.
18
+ */
19
+ declare function anthropicTools(ui: UiCalling, filter?: (toolName: string) => boolean, turn?: {
20
+ woken?: boolean;
21
+ }): Anthropic.Tool[];
22
+ /**
23
+ * Run one `tool_use` block from a manual loop. Returns the `tool_result` block to send back and the
24
+ * run: deliver `run.link` when `run.ok`, and send nothing this turn when `run.silent`. Failures come back
25
+ * as `is_error` results, never throws.
26
+ * Pass the `filter` you gave `anthropicTools`, so a tool the model wasn't offered is refused.
27
+ */
28
+ declare function anthropicToolResult(ui: UiCalling, block: {
29
+ id: string;
30
+ name: string;
31
+ input: unknown;
32
+ }, who: Who, filter?: (toolName: string) => boolean): Promise<{
33
+ result: Anthropic.ToolResultBlockParam;
34
+ run: ToolRun;
35
+ }>;
36
+ /**
37
+ * Runnable tools for the SDK's tool runner, which loops for you:
38
+ *
39
+ * const links: SurfaceLink[] = [];
40
+ * const final = await client.beta.messages.toolRunner({
41
+ * model, max_tokens, messages,
42
+ * tools: anthropicRunnableTools(ui, { conversationId, subject }, { onLink: (l) => links.push(l) }),
43
+ * });
44
+ * // send the final text, with links[] as buttons
45
+ */
46
+ declare function anthropicRunnableTools(ui: UiCalling, who: Who | (() => Who), opts?: AnthropicAdapterOptions): _anthropic_ai_sdk_lib_tools_BetaRunnableTool_mjs.BetaRunnableTool<{
47
+ [x: string]: unknown;
48
+ }>[];
49
+
50
+ export { anthropicRunnableTools, anthropicToolResult, anthropicTools };
51
+ export type { AnthropicAdapterOptions };
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ // src/index.ts
2
+ import { betaTool } from "@anthropic-ai/sdk/helpers/beta/json-schema";
3
+ function anthropicTools(ui, filter, turn = {}) {
4
+ return ui.tools({ ...turn, filter }).map((t) => ({ name: t.name, description: t.description, input_schema: t.input_schema }));
5
+ }
6
+ async function anthropicToolResult(ui, block, who, filter) {
7
+ const run = await ui.runTool(block.name, block.input, who, filter);
8
+ return {
9
+ result: { type: "tool_result", tool_use_id: block.id, content: run.content, ...run.ok ? {} : { is_error: true } },
10
+ run
11
+ };
12
+ }
13
+ function anthropicRunnableTools(ui, who, opts = {}) {
14
+ return ui.tools({ woken: opts.woken, filter: opts.filter }).map(
15
+ (t) => betaTool({
16
+ name: t.name,
17
+ description: t.description,
18
+ inputSchema: t.input_schema,
19
+ run: async (input) => {
20
+ const run = await ui.runTool(t.name, input, typeof who === "function" ? who() : who);
21
+ if (run.ok && run.silent) opts.onSilent?.(run.reason);
22
+ else if (run.ok) opts.onLink?.(run.link);
23
+ return run.content;
24
+ }
25
+ })
26
+ );
27
+ }
28
+ export {
29
+ anthropicRunnableTools,
30
+ anthropicToolResult,
31
+ anthropicTools
32
+ };
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 /** A screen event started this turn, not a user message: also offer `stay_silent`. */\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 })`. On a woken turn pass\n * `{ woken: true }` to add `stay_silent`; `anthropicToolResult` then returns `run.silent` when it's called.\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 run = await ui.runTool(t.name, input, typeof who === \"function\" ? who() : who);\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":";AACA,SAAS,gBAAgB;AAkBlB,SAAS,eAAe,IAAe,QAAwC,OAA4B,CAAC,GAAqB;AACtI,SAAO,GACJ,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC,EACzB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,EAAE,aAAa,cAAc,EAAE,aAA2C,EAAE;AAC1H;AAQA,eAAsB,oBACpB,IACA,OACA,KACA,QACmE;AACnE,QAAM,MAAM,MAAM,GAAG,QAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,MAAM;AACjE,SAAO;AAAA,IACL,QAAQ,EAAE,MAAM,eAAe,aAAa,MAAM,IAAI,SAAS,IAAI,SAAS,GAAI,IAAI,KAAK,CAAC,IAAI,EAAE,UAAU,KAAK,EAAG;AAAA,IAClH;AAAA,EACF;AACF;AAYO,SAAS,uBAAuB,IAAe,KAAwB,OAAgC,CAAC,GAAG;AAChH,SAAO,GACJ,MAAM,EAAE,OAAO,KAAK,OAAO,QAAQ,KAAK,OAAO,CAAC,EAChD;AAAA,IAAI,CAAC,MACJ,SAAS;AAAA,MACP,MAAM,EAAE;AAAA,MACR,aAAa,EAAE;AAAA,MACf,aAAa,EAAE;AAAA,MACf,KAAK,OAAO,UAAU;AACpB,cAAM,MAAM,MAAM,GAAG,QAAQ,EAAE,MAAM,OAAO,OAAO,QAAQ,aAAa,IAAI,IAAI,GAAG;AACnF,YAAI,IAAI,MAAM,IAAI,OAAQ,MAAK,WAAW,IAAI,MAAM;AAAA,iBAC3C,IAAI,GAAI,MAAK,SAAS,IAAI,IAAI;AACvC,eAAO,IAAI;AAAA,MACb;AAAA,IACF,CAAC;AAAA,EACH;AACJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@ui-calling/anthropic",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-preview.0",
4
+ "description": "Use ui-calling surfaces as tools with the Anthropic SDK (tool runner or manual loop).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/pausanchez/ui-calling.git",
9
+ "directory": "packages/anthropic"
10
+ },
11
+ "homepage": "https://github.com/pausanchez/ui-calling#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/pausanchez/ui-calling/issues"
14
+ },
15
+ "keywords": [
16
+ "ui-calling",
17
+ "anthropic",
18
+ "claude",
19
+ "tools"
20
+ ],
21
+ "type": "module",
22
+ "exports": {
23
+ ".": {
24
+ "ui-calling-source": "./src/index.ts",
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ }
28
+ },
29
+ "types": "./dist/index.d.ts",
30
+ "files": [
31
+ "dist",
32
+ "LICENSE"
33
+ ],
34
+ "sideEffects": false,
35
+ "scripts": {
36
+ "build": "tsup"
37
+ },
38
+ "tsup": {
39
+ "entry": {
40
+ "index": "src/index.ts"
41
+ },
42
+ "format": [
43
+ "esm"
44
+ ],
45
+ "dts": true,
46
+ "clean": true,
47
+ "sourcemap": true,
48
+ "target": "es2022",
49
+ "removeNodeProtocol": false
50
+ },
51
+ "dependencies": {
52
+ "@ui-calling/core": "^0.1.0-preview.0"
53
+ },
54
+ "peerDependencies": {
55
+ "@anthropic-ai/sdk": ">=1.0.0"
56
+ },
57
+ "devDependencies": {
58
+ "@anthropic-ai/sdk": "^1.13.0"
59
+ },
60
+ "publishConfig": {
61
+ "access": "public"
62
+ }
63
+ }