toolsplice 0.0.1 → 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 (137) hide show
  1. package/README.md +62 -330
  2. package/dist/abortable.d.ts +6 -0
  3. package/dist/abortable.js +50 -0
  4. package/dist/adaptive-read.d.ts +50 -0
  5. package/dist/adaptive-read.js +780 -0
  6. package/dist/answer-wait.d.ts +7 -0
  7. package/dist/answer-wait.js +45 -0
  8. package/dist/cache-reads.d.ts +18 -0
  9. package/dist/cache-reads.js +89 -0
  10. package/dist/calibration-ledger.d.ts +37 -0
  11. package/dist/calibration-ledger.js +148 -0
  12. package/dist/calibration-marker.d.ts +4 -0
  13. package/dist/calibration-marker.js +77 -0
  14. package/dist/catalog-setup.d.ts +33 -0
  15. package/dist/catalog-setup.js +89 -0
  16. package/dist/catalog.d.ts +10 -0
  17. package/dist/catalog.js +42 -0
  18. package/dist/checkpoint-files.d.ts +15 -0
  19. package/dist/checkpoint-files.js +99 -0
  20. package/dist/cli.js +545 -14
  21. package/dist/coalesce-reads.d.ts +6 -0
  22. package/dist/coalesce-reads.js +33 -0
  23. package/dist/contract-caller.d.ts +2 -1
  24. package/dist/contract-caller.js +35 -16
  25. package/dist/contract-schema.d.ts +3 -1
  26. package/dist/contract-schema.js +34 -4
  27. package/dist/contracts.d.ts +1 -0
  28. package/dist/contracts.js +5 -1
  29. package/dist/core.d.ts +31 -1
  30. package/dist/core.js +27 -0
  31. package/dist/db-final-answer.d.ts +9 -0
  32. package/dist/db-final-answer.js +62 -0
  33. package/dist/define.d.ts +78 -0
  34. package/dist/define.js +14 -0
  35. package/dist/final-answer-stores.d.ts +71 -0
  36. package/dist/final-answer-stores.js +72 -0
  37. package/dist/final-answer.d.ts +32 -0
  38. package/dist/final-answer.js +104 -0
  39. package/dist/impact.d.ts +48 -0
  40. package/dist/impact.js +71 -0
  41. package/dist/index.d.ts +32 -1
  42. package/dist/index.js +28 -0
  43. package/dist/local-tool.d.ts +18 -0
  44. package/dist/local-tool.js +32 -0
  45. package/dist/mcp-apps.d.ts +53 -0
  46. package/dist/mcp-apps.js +32 -0
  47. package/dist/mcp-event-delivery.d.ts +98 -0
  48. package/dist/mcp-event-delivery.js +211 -0
  49. package/dist/mcp-extensions.d.ts +46 -0
  50. package/dist/mcp-extensions.js +200 -0
  51. package/dist/mcp-peer.d.ts +45 -0
  52. package/dist/mcp-peer.js +207 -0
  53. package/dist/mcp-server-card.d.ts +21 -0
  54. package/dist/mcp-server-card.js +54 -0
  55. package/dist/page-checkpoint.d.ts +71 -0
  56. package/dist/page-checkpoint.js +286 -0
  57. package/dist/page-read-gate.d.ts +15 -0
  58. package/dist/page-read-gate.js +48 -0
  59. package/dist/pattern.d.ts +1 -0
  60. package/dist/pattern.js +27 -5
  61. package/dist/probe.js +6 -19
  62. package/dist/read-pages.d.ts +25 -0
  63. package/dist/read-pages.js +85 -0
  64. package/dist/read-policy.d.ts +6 -0
  65. package/dist/read-policy.js +16 -0
  66. package/dist/read-steps.d.ts +12 -0
  67. package/dist/read-steps.js +36 -0
  68. package/dist/result-session.d.ts +109 -0
  69. package/dist/result-session.js +620 -0
  70. package/dist/route-checkpoint.d.ts +3 -0
  71. package/dist/route-checkpoint.js +80 -0
  72. package/dist/route-driver-cli.d.ts +3 -0
  73. package/dist/route-driver-cli.js +43 -0
  74. package/dist/route-evaluation.d.ts +141 -0
  75. package/dist/route-evaluation.js +329 -0
  76. package/dist/row-groups.d.ts +17 -0
  77. package/dist/row-groups.js +79 -0
  78. package/dist/row-query.d.ts +62 -0
  79. package/dist/row-query.js +172 -0
  80. package/dist/rules.d.ts +30 -0
  81. package/dist/rules.js +72 -0
  82. package/dist/run-diagnostics.d.ts +75 -0
  83. package/dist/run-diagnostics.js +212 -0
  84. package/dist/search-fetch.d.ts +50 -0
  85. package/dist/search-fetch.js +264 -0
  86. package/dist/skill-files.d.ts +9 -0
  87. package/dist/skill-files.js +49 -0
  88. package/dist/splice-diagnostics.d.ts +4 -0
  89. package/dist/splice-diagnostics.js +24 -16
  90. package/dist/splice-measure.d.ts +33 -0
  91. package/dist/splice-measure.js +55 -0
  92. package/dist/splice-project.d.ts +12 -6
  93. package/dist/splice-project.js +72 -20
  94. package/dist/splice-recording.d.ts +29 -2
  95. package/dist/splice-recording.js +22 -5
  96. package/dist/splice.d.ts +98 -1
  97. package/dist/splice.js +225 -27
  98. package/dist/sqlite-checkpoint-store.d.ts +5 -0
  99. package/dist/sqlite-checkpoint-store.js +91 -0
  100. package/dist/sqlite-checkpoint-worker.d.ts +1 -0
  101. package/dist/sqlite-checkpoint-worker.js +115 -0
  102. package/dist/test-difference.d.ts +13 -0
  103. package/dist/test-difference.js +42 -0
  104. package/dist/testing.d.ts +122 -0
  105. package/dist/testing.js +261 -0
  106. package/dist/text-pages.d.ts +24 -0
  107. package/dist/text-pages.js +36 -0
  108. package/dist/tool-discovery.d.ts +59 -0
  109. package/dist/tool-discovery.js +136 -0
  110. package/dist/unevaluated.d.ts +7 -0
  111. package/dist/unevaluated.js +156 -0
  112. package/dist/v2.js +25 -8
  113. package/dist/version.d.ts +1 -1
  114. package/dist/version.js +1 -1
  115. package/dist/workflow-json.js +1 -1
  116. package/docs/AGENT-FRAMEWORKS.md +431 -0
  117. package/docs/BENCHMARKS.md +43 -0
  118. package/docs/INTEGRATION-QUICKSTART.md +859 -0
  119. package/docs/LEARNING-AND-STORAGE.md +393 -0
  120. package/docs/MCP.md +204 -0
  121. package/docs/PROJECTS-AND-UPGRADES.md +67 -9
  122. package/docs/PYTHON-REFERENCE.md +348 -0
  123. package/docs/PYTHON.md +120 -0
  124. package/docs/RECORDING-AND-CORRECTIONS.md +30 -1
  125. package/docs/TESTING.md +259 -0
  126. package/examples/mcp-app/build.mjs +11 -0
  127. package/examples/mcp-app/view.mjs +22 -0
  128. package/examples/quickstart.mjs +43 -0
  129. package/examples/route-driver.mjs +67 -0
  130. package/integrations/ai.d.mts +36 -0
  131. package/integrations/ai.mjs +178 -0
  132. package/integrations/call-options.mjs +9 -0
  133. package/integrations/langchain.d.mts +31 -0
  134. package/integrations/langchain.mjs +114 -0
  135. package/integrations/managed.mjs +154 -0
  136. package/integrations/types.d.mts +13 -0
  137. package/package.json +47 -3
@@ -0,0 +1,114 @@
1
+ import {
2
+ DynamicStructuredTool,
3
+ DynamicTool,
4
+ tool,
5
+ } from "@langchain/core/tools";
6
+ import {
7
+ managedTools,
8
+ activeTools,
9
+ checkNames,
10
+ visibleContent,
11
+ withRun,
12
+ streamRun,
13
+ } from "./managed.mjs";
14
+ import { callOptions } from "./call-options.mjs";
15
+
16
+ /** Register a workflow as one LangChain structured tool. */
17
+ export function asLangChainTool(workflow, options = {}) {
18
+ const { name, description, inputSchema } = workflow.definition;
19
+ const { returnDirect = false, ...runOptions } = options;
20
+ if (typeof returnDirect !== "boolean")
21
+ throw new TypeError("returnDirect must be boolean.");
22
+ return tool(
23
+ (input, config) =>
24
+ workflow.execute(input, callOptions(runOptions, config?.signal)),
25
+ {
26
+ name,
27
+ description: description ?? name,
28
+ schema: inputSchema,
29
+ returnDirect,
30
+ },
31
+ );
32
+ }
33
+
34
+ /** Run a LangChain agent with its existing tools and a private result scope. */
35
+ export async function withLangChainTools(
36
+ existing,
37
+ question,
38
+ use,
39
+ { enabled = true, diagnostics } = {},
40
+ ) {
41
+ if (diagnostics) return diagnostics.run(enabled ? "adaptive" : "native", () => withLangChainTools(existing, question, use, {enabled}));
42
+ if (!enabled) {
43
+ const native = nativeTools(existing);
44
+ return use(native, () => activeTools(native, true));
45
+ }
46
+ return withRun(question, buildTools(existing, question), use);
47
+ }
48
+
49
+ /** Stream a run and release retained results on completion, failure or early return. */
50
+ export async function* streamLangChainTools(
51
+ existing,
52
+ question,
53
+ use,
54
+ { enabled = true, diagnostics } = {},
55
+ ) {
56
+ if (diagnostics) {
57
+ yield* diagnostics.stream(enabled ? "adaptive" : "native", () => streamLangChainTools(existing, question, use, {enabled}));
58
+ return;
59
+ }
60
+ if (!enabled) {
61
+ const native = nativeTools(existing);
62
+ yield* await use(native, () => activeTools(native, true));
63
+ return;
64
+ }
65
+ yield* streamRun(question, buildTools(existing, question), use);
66
+ }
67
+
68
+ function nativeTools(existing) {
69
+ return existing.some((t) => t.definition && typeof t.execute === "function")
70
+ ? existing.map((t) =>
71
+ t.definition && typeof t.execute === "function"
72
+ ? asLangChainTool(t)
73
+ : t,
74
+ )
75
+ : existing;
76
+ }
77
+
78
+ function buildTools(existing, question) {
79
+ return (session, begin) => {
80
+ const sources = existing.filter(
81
+ (t) => t.definition && typeof t.execute === "function",
82
+ );
83
+ const registered = managedTools(session, sources, question);
84
+ const wrapped = new Map(
85
+ registered.map((t) => [t.definition.name, asLangChainTool(t)]),
86
+ );
87
+ const tools = existing.map((native) => {
88
+ if (native.definition && typeof native.execute === "function")
89
+ return wrapped.get(native.definition.name);
90
+ if (
91
+ native.returnDirect ||
92
+ ![DynamicTool, DynamicStructuredTool].includes(native.constructor)
93
+ )
94
+ return native;
95
+ return new native.constructor({
96
+ ...native,
97
+ async func(input, ...rest) {
98
+ const present = begin(native.name, input ?? {});
99
+ const output = await native.func(input, ...rest);
100
+ if (
101
+ native.responseFormat === "content_and_artifact" &&
102
+ Array.isArray(output) &&
103
+ output.length === 2
104
+ )
105
+ return [visibleContent(output[0], present), output[1]];
106
+ return visibleContent(output, present);
107
+ },
108
+ });
109
+ });
110
+ tools.push(wrapped.get("inspect_result"));
111
+ checkNames(tools.map((t) => t.name));
112
+ return tools;
113
+ };
114
+ }
@@ -0,0 +1,154 @@
1
+ import { ResultSession } from "../dist/core.js";
2
+
3
+ // Vercel expects names in prepareStep. LangChain middleware accepts tool objects.
4
+ export function activeTools(tools, showInspector) {
5
+ if (Array.isArray(tools))
6
+ return showInspector
7
+ ? [...tools]
8
+ : tools.filter((t) => t.name !== "inspect_result");
9
+ return Object.keys(tools).filter(
10
+ (name) => showInspector || name !== "inspect_result",
11
+ );
12
+ }
13
+
14
+ export async function withRun(question, build, use) {
15
+ const session = new ResultSession({ nativeOnCapacity: true });
16
+ const cleanup = [];
17
+ try {
18
+ const present = session.adaptivePresenter(question);
19
+ const tools = build(session, present, cleanup);
20
+ return await use(tools, () =>
21
+ activeTools(tools, session.hasRetainedResults),
22
+ );
23
+ } finally {
24
+ session.close();
25
+ for (const release of cleanup) release();
26
+ }
27
+ }
28
+
29
+ export async function* streamRun(question, build, use) {
30
+ const session = new ResultSession({ nativeOnCapacity: true });
31
+ const cleanup = [];
32
+ try {
33
+ const tools = build(session, session.adaptivePresenter(question), cleanup);
34
+ yield* await use(tools, () =>
35
+ activeTools(tools, session.hasRetainedResults),
36
+ );
37
+ } finally {
38
+ session.close();
39
+ for (const release of cleanup) release();
40
+ }
41
+ }
42
+
43
+ export function checkNames(names) {
44
+ if (new Set(names).size !== names.length)
45
+ throw new Error("Duplicate or reserved session tool name.");
46
+ }
47
+
48
+ // Native MCP adapters can carry media and framework-specific blocks alongside text.
49
+ // Preserve that representation and keep private artifacts outside retained values.
50
+ export function visibleContent(value, present) {
51
+ if (value?.isError === true) return value;
52
+ if (
53
+ Array.isArray(value) &&
54
+ value.some((part) => part && typeof part.type === "string")
55
+ ) {
56
+ if (!value.every((p) => p?.type === "text" && typeof p.text === "string"))
57
+ return value;
58
+ if (value.length > 1) {
59
+ if (
60
+ value.some((p) =>
61
+ Object.keys(p).some((k) => k !== "type" && k !== "text"),
62
+ )
63
+ )
64
+ return value;
65
+ const view = present(value);
66
+ return Array.isArray(view)
67
+ ? view
68
+ : [{ type: "text", text: JSON.stringify(view) }];
69
+ }
70
+ const text = present(value[0].text);
71
+ return [
72
+ {
73
+ ...value[0],
74
+ text: typeof text === "string" ? text : JSON.stringify(text),
75
+ },
76
+ ];
77
+ }
78
+ if (
79
+ value === undefined ||
80
+ (value !== null &&
81
+ typeof value === "object" &&
82
+ !Array.isArray(value) &&
83
+ ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
84
+ )
85
+ return value;
86
+ return present(value);
87
+ }
88
+
89
+ /** Two required scalar arguments also work with hosts that enforce strict tool schemas. */
90
+ export function managedTools(session, sources, question) {
91
+ const tools = session.tools(sources, { adaptiveRead: question });
92
+ const index = tools.findIndex((t) => t.definition.name === "inspect_result");
93
+ const [inspect] = tools.splice(index, 1);
94
+ tools.push({
95
+ definition: {
96
+ name: "inspect_result",
97
+ description:
98
+ "Read missing evidence from this run without fetching again. If selection already contains the requested facts, answer directly. requestedUrl is the exact URL used; complete counts cover the entire selected text.",
99
+ inputSchema: {
100
+ type: "object",
101
+ properties: {
102
+ ref: {
103
+ type: "string",
104
+ description: "A ref returned by a tool in this run.",
105
+ },
106
+ query: {
107
+ type: "string",
108
+ maxLength: 4096,
109
+ description:
110
+ 'Use a JSON Pointer such as /items/0, an empty string for the root, or a JSON selector string such as {"contains":"needle","limit":120}, {"countMatches":"literal"}, or {"path":"/rows","fields":["id"]}.',
111
+ },
112
+ },
113
+ required: ["ref", "query"],
114
+ additionalProperties: false,
115
+ },
116
+ annotations: { readOnlyHint: true },
117
+ },
118
+ async execute({ ref, query }, options) {
119
+ if (typeof query !== "string" || query.length > 4096)
120
+ return {
121
+ error:
122
+ "Use a JSON Pointer or a JSON selector string of up to 4096 characters.",
123
+ };
124
+ let selector;
125
+ try {
126
+ selector =
127
+ query === "" || query.startsWith("/")
128
+ ? { path: query }
129
+ : JSON.parse(query);
130
+ } catch {
131
+ return {
132
+ error: "Invalid query. Use a JSON Pointer or a JSON selector string.",
133
+ };
134
+ }
135
+ if (
136
+ !selector ||
137
+ typeof selector !== "object" ||
138
+ Array.isArray(selector) ||
139
+ Object.hasOwn(selector, "ref")
140
+ )
141
+ return {
142
+ error:
143
+ "Pass ref separately and use a JSON Pointer or a selector object in query.",
144
+ };
145
+ try {
146
+ return await inspect.execute({ ...selector, ref }, options);
147
+ } catch (error) {
148
+ if (options?.signal?.aborted) throw error;
149
+ return { error: error.message };
150
+ }
151
+ },
152
+ });
153
+ return tools;
154
+ }
@@ -0,0 +1,13 @@
1
+ import type { SpliceRunOptions } from "../dist/core.js";
2
+
3
+ export interface ExecutableTool<Result> {
4
+ definition: {
5
+ name: string;
6
+ description?: string;
7
+ inputSchema: Record<string, unknown>;
8
+ };
9
+ execute(
10
+ args: Record<string, unknown>,
11
+ options?: SpliceRunOptions,
12
+ ): Promise<Result>;
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolsplice",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Check, dry-run, and generate guarded adapters between MCP tools using declared or learned output shapes.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -13,9 +13,21 @@
13
13
  "types": "dist/index.d.ts",
14
14
  "files": [
15
15
  "dist",
16
+ "docs/TESTING.md",
17
+ "docs/MCP.md",
18
+ "examples/mcp-app",
19
+ "docs/PYTHON.md",
16
20
  "docs/RECORDING-AND-CORRECTIONS.md",
17
21
  "docs/PROJECTS-AND-UPGRADES.md",
18
- "LICENSE"
22
+ "docs/LEARNING-AND-STORAGE.md",
23
+ "examples/quickstart.mjs",
24
+ "examples/route-driver.mjs",
25
+ "LICENSE",
26
+ "integrations",
27
+ "docs/AGENT-FRAMEWORKS.md",
28
+ "docs/BENCHMARKS.md",
29
+ "docs/PYTHON-REFERENCE.md",
30
+ "docs/INTEGRATION-QUICKSTART.md"
19
31
  ],
20
32
  "scripts": {
21
33
  "build": "tsc -p tsconfig.json && node scripts/prepare-package.mjs && node scripts/build-core.mjs",
@@ -76,6 +88,14 @@
76
88
  "./postgres": {
77
89
  "types": "./dist/postgres.d.ts",
78
90
  "import": "./dist/postgres.js"
91
+ },
92
+ "./ai": {
93
+ "types": "./integrations/ai.d.mts",
94
+ "import": "./integrations/ai.mjs"
95
+ },
96
+ "./langchain": {
97
+ "types": "./integrations/langchain.d.mts",
98
+ "import": "./integrations/langchain.mjs"
79
99
  }
80
100
  },
81
101
  "optionalDependencies": {
@@ -93,5 +113,29 @@
93
113
  "schema-compatibility",
94
114
  "adapter",
95
115
  "preflight"
96
- ]
116
+ ],
117
+ "peerDependencies": {
118
+ "@modelcontextprotocol/client": "^2.3.1",
119
+ "standardwebhooks": "^1.3.0",
120
+ "yaml": "^2.8.0",
121
+ "ai": ">=6 <8",
122
+ "@langchain/core": ">=1 <2"
123
+ },
124
+ "peerDependenciesMeta": {
125
+ "@modelcontextprotocol/client": {
126
+ "optional": true
127
+ },
128
+ "standardwebhooks": {
129
+ "optional": true
130
+ },
131
+ "yaml": {
132
+ "optional": true
133
+ },
134
+ "ai": {
135
+ "optional": true
136
+ },
137
+ "@langchain/core": {
138
+ "optional": true
139
+ }
140
+ }
97
141
  }