toolsplice 0.0.0-stage → 0.0.2

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.
Files changed (172) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -2
  3. package/dist/abortable.d.ts +6 -0
  4. package/dist/abortable.js +50 -0
  5. package/dist/adaptive-read.d.ts +50 -0
  6. package/dist/adaptive-read.js +780 -0
  7. package/dist/answer-wait.d.ts +7 -0
  8. package/dist/answer-wait.js +45 -0
  9. package/dist/cache-reads.d.ts +18 -0
  10. package/dist/cache-reads.js +89 -0
  11. package/dist/calibration-ledger.d.ts +37 -0
  12. package/dist/calibration-ledger.js +148 -0
  13. package/dist/calibration-marker.d.ts +4 -0
  14. package/dist/calibration-marker.js +77 -0
  15. package/dist/catalog-setup.d.ts +33 -0
  16. package/dist/catalog-setup.js +89 -0
  17. package/dist/catalog.d.ts +10 -0
  18. package/dist/catalog.js +42 -0
  19. package/dist/checkpoint-files.d.ts +15 -0
  20. package/dist/checkpoint-files.js +99 -0
  21. package/dist/cli.d.ts +2 -0
  22. package/dist/cli.js +1454 -0
  23. package/dist/coalesce-reads.d.ts +6 -0
  24. package/dist/coalesce-reads.js +33 -0
  25. package/dist/codegen.d.ts +44 -0
  26. package/dist/codegen.js +479 -0
  27. package/dist/contract-caller.d.ts +23 -0
  28. package/dist/contract-caller.js +326 -0
  29. package/dist/contract-corrections.d.ts +35 -0
  30. package/dist/contract-corrections.js +159 -0
  31. package/dist/contract-schema.d.ts +7 -0
  32. package/dist/contract-schema.js +156 -0
  33. package/dist/contracts.d.ts +72 -0
  34. package/dist/contracts.js +370 -0
  35. package/dist/core.d.ts +44 -0
  36. package/dist/core.js +43 -0
  37. package/dist/db-final-answer.d.ts +9 -0
  38. package/dist/db-final-answer.js +62 -0
  39. package/dist/define.d.ts +78 -0
  40. package/dist/define.js +14 -0
  41. package/dist/doctor.d.ts +22 -0
  42. package/dist/doctor.js +91 -0
  43. package/dist/drift.d.ts +23 -0
  44. package/dist/drift.js +111 -0
  45. package/dist/execution.d.ts +38 -0
  46. package/dist/execution.js +66 -0
  47. package/dist/extract.d.ts +34 -0
  48. package/dist/extract.js +73 -0
  49. package/dist/final-answer-stores.d.ts +71 -0
  50. package/dist/final-answer-stores.js +72 -0
  51. package/dist/final-answer.d.ts +32 -0
  52. package/dist/final-answer.js +104 -0
  53. package/dist/impact.d.ts +48 -0
  54. package/dist/impact.js +71 -0
  55. package/dist/index.d.ts +51 -0
  56. package/dist/index.js +47 -0
  57. package/dist/local-tool.d.ts +18 -0
  58. package/dist/local-tool.js +32 -0
  59. package/dist/mcp-apps.d.ts +53 -0
  60. package/dist/mcp-apps.js +32 -0
  61. package/dist/mcp-event-delivery.d.ts +98 -0
  62. package/dist/mcp-event-delivery.js +211 -0
  63. package/dist/mcp-extensions.d.ts +46 -0
  64. package/dist/mcp-extensions.js +200 -0
  65. package/dist/mcp-peer.d.ts +45 -0
  66. package/dist/mcp-peer.js +207 -0
  67. package/dist/mcp-server-card.d.ts +21 -0
  68. package/dist/mcp-server-card.js +54 -0
  69. package/dist/ordered-transport.d.ts +12 -0
  70. package/dist/ordered-transport.js +106 -0
  71. package/dist/page-checkpoint.d.ts +71 -0
  72. package/dist/page-checkpoint.js +286 -0
  73. package/dist/page-read-gate.d.ts +15 -0
  74. package/dist/page-read-gate.js +48 -0
  75. package/dist/pattern.d.ts +3 -0
  76. package/dist/pattern.js +54 -0
  77. package/dist/postgres.d.ts +41 -0
  78. package/dist/postgres.js +264 -0
  79. package/dist/probe.d.ts +29 -0
  80. package/dist/probe.js +121 -0
  81. package/dist/proxy.d.ts +40 -0
  82. package/dist/proxy.js +436 -0
  83. package/dist/read-pages.d.ts +25 -0
  84. package/dist/read-pages.js +85 -0
  85. package/dist/read-policy.d.ts +6 -0
  86. package/dist/read-policy.js +16 -0
  87. package/dist/read-steps.d.ts +12 -0
  88. package/dist/read-steps.js +36 -0
  89. package/dist/result-session.d.ts +109 -0
  90. package/dist/result-session.js +620 -0
  91. package/dist/route-checkpoint.d.ts +3 -0
  92. package/dist/route-checkpoint.js +80 -0
  93. package/dist/route-driver-cli.d.ts +3 -0
  94. package/dist/route-driver-cli.js +43 -0
  95. package/dist/route-evaluation.d.ts +141 -0
  96. package/dist/route-evaluation.js +329 -0
  97. package/dist/row-groups.d.ts +17 -0
  98. package/dist/row-groups.js +79 -0
  99. package/dist/row-query.d.ts +62 -0
  100. package/dist/row-query.js +172 -0
  101. package/dist/rules.d.ts +30 -0
  102. package/dist/rules.js +72 -0
  103. package/dist/run-diagnostics.d.ts +75 -0
  104. package/dist/run-diagnostics.js +212 -0
  105. package/dist/runtime.d.ts +6 -0
  106. package/dist/runtime.js +26 -0
  107. package/dist/schema.d.ts +17 -0
  108. package/dist/schema.js +299 -0
  109. package/dist/search-fetch.d.ts +50 -0
  110. package/dist/search-fetch.js +264 -0
  111. package/dist/shape.d.ts +91 -0
  112. package/dist/shape.js +499 -0
  113. package/dist/skill-files.d.ts +9 -0
  114. package/dist/skill-files.js +49 -0
  115. package/dist/splice-diagnostics.d.ts +44 -0
  116. package/dist/splice-diagnostics.js +88 -0
  117. package/dist/splice-measure.d.ts +33 -0
  118. package/dist/splice-measure.js +55 -0
  119. package/dist/splice-project.d.ts +125 -0
  120. package/dist/splice-project.js +348 -0
  121. package/dist/splice-recording.d.ts +132 -0
  122. package/dist/splice-recording.js +481 -0
  123. package/dist/splice.d.ts +181 -0
  124. package/dist/splice.js +1263 -0
  125. package/dist/sqlite-checkpoint-store.d.ts +5 -0
  126. package/dist/sqlite-checkpoint-store.js +91 -0
  127. package/dist/sqlite-checkpoint-worker.d.ts +1 -0
  128. package/dist/sqlite-checkpoint-worker.js +115 -0
  129. package/dist/storage.d.ts +17 -0
  130. package/dist/storage.js +1 -0
  131. package/dist/store.d.ts +151 -0
  132. package/dist/store.js +735 -0
  133. package/dist/test-difference.d.ts +13 -0
  134. package/dist/test-difference.js +42 -0
  135. package/dist/testing.d.ts +122 -0
  136. package/dist/testing.js +261 -0
  137. package/dist/text-pages.d.ts +24 -0
  138. package/dist/text-pages.js +36 -0
  139. package/dist/tool-discovery.d.ts +59 -0
  140. package/dist/tool-discovery.js +136 -0
  141. package/dist/unevaluated.d.ts +7 -0
  142. package/dist/unevaluated.js +156 -0
  143. package/dist/v2.d.ts +49 -0
  144. package/dist/v2.js +413 -0
  145. package/dist/validate-output.d.ts +3 -0
  146. package/dist/validate-output.js +73 -0
  147. package/dist/version.d.ts +1 -0
  148. package/dist/version.js +1 -0
  149. package/dist/workflow-json.d.ts +8 -0
  150. package/dist/workflow-json.js +74 -0
  151. package/docs/AGENT-FRAMEWORKS.md +431 -0
  152. package/docs/BENCHMARKS.md +43 -0
  153. package/docs/INTEGRATION-QUICKSTART.md +859 -0
  154. package/docs/LEARNING-AND-STORAGE.md +393 -0
  155. package/docs/MCP.md +204 -0
  156. package/docs/PROJECTS-AND-UPGRADES.md +173 -0
  157. package/docs/PYTHON-REFERENCE.md +348 -0
  158. package/docs/PYTHON.md +120 -0
  159. package/docs/RECORDING-AND-CORRECTIONS.md +205 -0
  160. package/docs/TESTING.md +259 -0
  161. package/examples/mcp-app/build.mjs +11 -0
  162. package/examples/mcp-app/view.mjs +22 -0
  163. package/examples/quickstart.mjs +43 -0
  164. package/examples/route-driver.mjs +67 -0
  165. package/integrations/ai.d.mts +36 -0
  166. package/integrations/ai.mjs +178 -0
  167. package/integrations/call-options.mjs +9 -0
  168. package/integrations/langchain.d.mts +31 -0
  169. package/integrations/langchain.mjs +114 -0
  170. package/integrations/managed.mjs +154 -0
  171. package/integrations/types.d.mts +13 -0
  172. package/package.json +139 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 toolsplice contributors
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,105 @@
1
- # Temporary Holding Version
1
+ # Toolsplice
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
+ Toolsplice connects the output of one MCP tool to the input of another. Your application defines the field mapping and validates it before a destination runs. An agent can then call the whole workflow as one tool. The same workflow can connect a remote tool to an ordinary function.
4
+
5
+ Use a checked handoff when the steps are known. For open-ended questions, wrap the agent's existing tools so it can receive a small result directly or inspect selected fields from a larger response. For jobs that span workers, save completed answers or page progress under a stable job ID.
6
+
7
+ ## Install
8
+
9
+ Requires Node.js 22 or later and ES modules.
10
+
11
+ ```sh
12
+ npm install toolsplice@0.0.2
13
+ npx toolsplice init ./my-handoff
14
+ npx toolsplice test ./my-handoff
15
+ ```
16
+
17
+ The two starter cases run offline. One checks the mapped arguments. The other checks that an invalid source prevents a destination call.
18
+
19
+ ## Connect a read to a local function
20
+
21
+ This runnable example maps a document's `text` to a counter's `content` argument. The mock source checks the public tool boundary offline. Save it as `count.mjs` and run `node count.mjs`.
22
+
23
+ ```js
24
+ import { createMockCaller, defineLocalTool, defineSplice } from "toolsplice";
25
+
26
+ const string = { type: "string" };
27
+ const fields = (name) => ({
28
+ type: "object", properties: { [name]: string }, required: [name],
29
+ });
30
+ const count = defineLocalTool({
31
+ name: "count_words", inputSchema: fields("content"), outputSchema: { type: "integer" },
32
+ }, ({ content }) => content.trim().split(/\s+/u).filter(Boolean).length);
33
+
34
+ const handoff = defineSplice({
35
+ source: { server: "docs", tool: "read", inputSchema: fields("id"), outputSchema: fields("text") },
36
+ target: { server: "local", tool: "count_words", inputSchema: fields("content"), outputSchema: { type: "integer" } },
37
+ bindings: [{ from: "/text", to: "/content" }],
38
+ });
39
+
40
+ const read = createMockCaller([{
41
+ name: "read", arguments: { id: "a1" }, result: { structuredContent: { text: "one two three" } },
42
+ }]);
43
+ console.log(await handoff.run(read, count.caller, { id: "a1" })); // [3]
44
+ read.assertDone();
45
+ ```
46
+
47
+ For an existing MCP v1 client, replace `read` with `createToolCaller(client)`. To expose the handoff to an agent, use `handoff.asTool({ name: "document_word_count", source: read, target: count.caller })`. Review `handoff.report` when either endpoint has incomplete contracts or the plan includes application rules.
48
+
49
+ ## Add Toolsplice to an existing agent
50
+
51
+ Each example uses your existing `model`, authorized tools and user `question`. The wrapper creates and closes a result session for the request.
52
+
53
+ ### Vercel AI SDK
54
+
55
+ Install `ai` (v6 or v7) alongside Toolsplice. Pass the tool map from your application or MCP client.
56
+
57
+ ```js
58
+ import { generateText, stepCountIs } from "ai";
59
+ import { withAiTools } from "toolsplice/ai";
60
+
61
+ const { text } = await withAiTools(existingTools, question, (tools, activeTools) =>
62
+ generateText({
63
+ model, tools, prompt: question, stopWhen: stepCountIs(6),
64
+ prepareStep: () => ({ activeTools: activeTools() }),
65
+ })
66
+ );
67
+ ```
68
+
69
+ ### LangChain
70
+
71
+ Install `langchain` and `@langchain/core@^1`. Pass the tool array you already supply to the agent.
72
+
73
+ ```js
74
+ import { createAgent } from "langchain";
75
+ import { withLangChainTools } from "toolsplice/langchain";
76
+
77
+ const state = await withLangChainTools(existingTools, question, tools =>
78
+ createAgent({ model, tools }).invoke({ messages: [{ role: "user", content: question }] })
79
+ );
80
+ console.log(state.messages.at(-1).content);
81
+ ```
82
+
83
+ ## Connect real tools
84
+
85
+ Use the two `tools/list` catalogs from MCP clients that your application has already authorized. Choose a source and destination, then map source JSON pointers to destination arguments. The CLI can scaffold the mapping and its first regression test. [Start from two catalogs](https://cdn.jsdelivr.net/npm/toolsplice@0.0.2/docs/TESTING.md#start-from-two-real-tools)
86
+
87
+ A search followed by a fetch is a common example. Register both reads once, restrict the allowed origins, and expose the combined tool to the model. One model-visible invocation still performs the underlying search and fetch. [Search and fetch guide](https://cdn.jsdelivr.net/npm/toolsplice@0.0.2/docs/INTEGRATION-QUICKSTART.md#search-and-fetch-in-one-model-tool-call)
88
+
89
+ Normal calls use an in-memory result store. To resume work after a restart, choose a persistent directory or a supported checkpoint database. Give each job a stable ID and bind the tenant, inputs and workflow version to its checkpoint. Authorize access on every replay. [Recovery with files, PostgreSQL or MongoDB](https://cdn.jsdelivr.net/npm/toolsplice@0.0.2/docs/INTEGRATION-QUICKSTART.md#recover-a-completed-answer-after-a-restart)
90
+
91
+ ## Benchmarks
92
+
93
+ In 20 live Microsoft Learn lookups per configuration, all three approaches returned the exact URL, heading and literal count every time. The conventional loop made two model calls per lookup. Both early-return approaches made one, with two MCP reads in every configuration.
94
+
95
+ | Implementation | Vercel AI SDK p95 | Agno p95 | Mean model USD/lookup |
96
+ | --- | ---: | ---: | ---: |
97
+ | Native agent loop | 6.379 s | 7.892 s | 0.0000680 |
98
+ | Native early return | 4.491 s | 5.912 s | 0.0000264 |
99
+ | Toolsplice with checkpoint | 4.039 s | 4.988 s | 0.0000264 |
100
+
101
+ A separate ten-page recovery test matched native on accuracy, model calls and cost. Toolsplice had a lower observed wall p95 with Vercel and a higher one with Agno. The sample was four jobs per configuration. [Full tables, controls and timing boundaries](https://cdn.jsdelivr.net/npm/toolsplice@0.0.2/docs/BENCHMARKS.md)
102
+
103
+ The Python distribution includes native Agno and LangChain integrations. The smaller Node package provides the handoff runtime for applications that supply their own transport. [Python SDK](https://pypi.org/project/toolsplice/) · [Standalone Node runtime](https://www.npmjs.com/package/toolsplice-core) · [Integration guide](https://cdn.jsdelivr.net/npm/toolsplice@0.0.2/docs/INTEGRATION-QUICKSTART.md)
104
+
105
+ [Python API and CLI reference](https://cdn.jsdelivr.net/npm/toolsplice@0.0.2/docs/PYTHON-REFERENCE.md)
@@ -0,0 +1,6 @@
1
+ import { type BindingCallOptions } from "./execution.js";
2
+ /** Stop awaiting an application callback when its caller aborts. */
3
+ export declare function abortable<T>(action: () => T | PromiseLike<T>, signal?: AbortSignal): Promise<T>;
4
+ export declare function isReadDeadline(error: unknown): boolean;
5
+ /** Apply one optional deadline across application callbacks and propagate caller cancellation. */
6
+ export declare function withCallDeadline<T, O extends BindingCallOptions>(options: O | undefined, message: string, action: (options?: O) => T | PromiseLike<T>): Promise<T>;
@@ -0,0 +1,50 @@
1
+ import { bindingOptions } from "./execution.js";
2
+ /** Stop awaiting an application callback when its caller aborts. */
3
+ export async function abortable(action, signal) {
4
+ if (!signal)
5
+ return action();
6
+ signal.throwIfAborted();
7
+ let onAbort;
8
+ const aborted = new Promise((_, reject) => {
9
+ onAbort = () => reject(signal.reason);
10
+ signal.addEventListener("abort", onAbort, { once: true });
11
+ });
12
+ try {
13
+ return await Promise.race([
14
+ Promise.resolve().then(() => {
15
+ signal.throwIfAborted();
16
+ return action();
17
+ }),
18
+ aborted,
19
+ ]);
20
+ }
21
+ finally {
22
+ signal.removeEventListener("abort", onAbort);
23
+ }
24
+ }
25
+ const localDeadlines = new WeakSet();
26
+ export function isReadDeadline(error) {
27
+ return error instanceof DOMException && localDeadlines.has(error);
28
+ }
29
+ function readDeadline(message) {
30
+ const error = new DOMException(message, "TimeoutError");
31
+ localDeadlines.add(error);
32
+ return error;
33
+ }
34
+ /** Apply one optional deadline across application callbacks and propagate caller cancellation. */
35
+ export async function withCallDeadline(options, message, action) {
36
+ if (options?.timeoutMs === undefined)
37
+ return abortable(() => action(options), options?.signal);
38
+ const { timeout } = bindingOptions(options);
39
+ const deadline = new AbortController();
40
+ const signal = options.signal
41
+ ? AbortSignal.any([options.signal, deadline.signal])
42
+ : deadline.signal;
43
+ const timer = setTimeout(() => deadline.abort(readDeadline(message)), timeout);
44
+ try {
45
+ return await abortable(() => action({ ...options, signal }), signal);
46
+ }
47
+ finally {
48
+ clearTimeout(timer);
49
+ }
50
+ }
@@ -0,0 +1,50 @@
1
+ export declare function literalCount(text: string, literal: string): {
2
+ literal: string;
3
+ count: number;
4
+ complete: boolean;
5
+ caseSensitive: boolean;
6
+ };
7
+ /** A declared Markdown projection scans the complete document, including fenced text for literal counts. */
8
+ export declare function markdownPageFacts(raw: unknown, literal?: string, headingLevel?: number): {
9
+ heading: string | null;
10
+ literal?: string | undefined;
11
+ count?: number | undefined;
12
+ };
13
+ /** Bind only a submitted document URL. Never substitute a provider-reported redirect. */
14
+ export declare function requestedPageUrl(args: Record<string, unknown>): string | undefined;
15
+ export declare function isPageResult(raw: unknown): raw is string | Record<string, unknown>;
16
+ /** Build a bounded, explicitly partial view. All routing inputs stay in the host. */
17
+ export declare function prepareAdaptiveRead(question: string): (raw: unknown, fallbackSize?: number, requestedUrl?: string) => {
18
+ readonly native: false;
19
+ readonly selection: {
20
+ headings?: {
21
+ syntax: string;
22
+ coverage?: string | undefined;
23
+ level: number;
24
+ count: number;
25
+ complete: boolean;
26
+ first?: string | null | undefined;
27
+ last?: string | null | undefined;
28
+ } | undefined;
29
+ occurrences?: {
30
+ literal: string;
31
+ count: number;
32
+ complete: boolean;
33
+ caseSensitive: boolean;
34
+ } | undefined;
35
+ heading?: string | undefined;
36
+ metadata?: {
37
+ [k: string]: unknown;
38
+ } | undefined;
39
+ };
40
+ readonly headingEvidence?: string | undefined;
41
+ readonly value?: undefined;
42
+ } | {
43
+ readonly native: true;
44
+ readonly value: unknown;
45
+ readonly selection?: undefined;
46
+ } | {
47
+ readonly value?: undefined;
48
+ readonly native: false;
49
+ readonly selection: unknown;
50
+ };