toolsplice-core 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 (111) hide show
  1. package/README.md +26 -17
  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/coalesce-reads.d.ts +6 -0
  21. package/dist/coalesce-reads.js +33 -0
  22. package/dist/contract-caller.d.ts +2 -1
  23. package/dist/contract-caller.js +35 -16
  24. package/dist/contract-schema.d.ts +3 -1
  25. package/dist/contract-schema.js +34 -4
  26. package/dist/contracts.d.ts +1 -0
  27. package/dist/contracts.js +5 -1
  28. package/dist/core.d.ts +31 -1
  29. package/dist/core.js +27 -0
  30. package/dist/db-final-answer.d.ts +9 -0
  31. package/dist/db-final-answer.js +62 -0
  32. package/dist/define.d.ts +78 -0
  33. package/dist/define.js +14 -0
  34. package/dist/final-answer-stores.d.ts +71 -0
  35. package/dist/final-answer-stores.js +72 -0
  36. package/dist/final-answer.d.ts +32 -0
  37. package/dist/final-answer.js +104 -0
  38. package/dist/impact.d.ts +48 -0
  39. package/dist/impact.js +71 -0
  40. package/dist/local-tool.d.ts +18 -0
  41. package/dist/local-tool.js +32 -0
  42. package/dist/mcp-apps.d.ts +53 -0
  43. package/dist/mcp-apps.js +32 -0
  44. package/dist/mcp-event-delivery.d.ts +98 -0
  45. package/dist/mcp-event-delivery.js +211 -0
  46. package/dist/mcp-extensions.d.ts +46 -0
  47. package/dist/mcp-extensions.js +200 -0
  48. package/dist/mcp-peer.d.ts +45 -0
  49. package/dist/mcp-peer.js +207 -0
  50. package/dist/mcp-server-card.d.ts +21 -0
  51. package/dist/mcp-server-card.js +54 -0
  52. package/dist/page-checkpoint.d.ts +71 -0
  53. package/dist/page-checkpoint.js +286 -0
  54. package/dist/page-read-gate.d.ts +15 -0
  55. package/dist/page-read-gate.js +48 -0
  56. package/dist/pattern.d.ts +1 -0
  57. package/dist/pattern.js +27 -5
  58. package/dist/read-pages.d.ts +25 -0
  59. package/dist/read-pages.js +85 -0
  60. package/dist/read-policy.d.ts +6 -0
  61. package/dist/read-policy.js +16 -0
  62. package/dist/read-steps.d.ts +12 -0
  63. package/dist/read-steps.js +36 -0
  64. package/dist/result-session.d.ts +109 -0
  65. package/dist/result-session.js +620 -0
  66. package/dist/route-checkpoint.d.ts +3 -0
  67. package/dist/route-checkpoint.js +80 -0
  68. package/dist/route-evaluation.d.ts +141 -0
  69. package/dist/route-evaluation.js +329 -0
  70. package/dist/row-groups.d.ts +17 -0
  71. package/dist/row-groups.js +79 -0
  72. package/dist/row-query.d.ts +62 -0
  73. package/dist/row-query.js +172 -0
  74. package/dist/rules.d.ts +30 -0
  75. package/dist/rules.js +72 -0
  76. package/dist/run-diagnostics.d.ts +75 -0
  77. package/dist/run-diagnostics.js +212 -0
  78. package/dist/search-fetch.d.ts +50 -0
  79. package/dist/search-fetch.js +264 -0
  80. package/dist/skill-files.d.ts +9 -0
  81. package/dist/skill-files.js +49 -0
  82. package/dist/splice-diagnostics.d.ts +4 -0
  83. package/dist/splice-diagnostics.js +24 -16
  84. package/dist/splice-recording.d.ts +29 -2
  85. package/dist/splice-recording.js +22 -5
  86. package/dist/splice.d.ts +98 -1
  87. package/dist/splice.js +225 -27
  88. package/dist/sqlite-checkpoint-store.d.ts +5 -0
  89. package/dist/sqlite-checkpoint-store.js +91 -0
  90. package/dist/sqlite-checkpoint-worker.js +115 -0
  91. package/dist/test-difference.d.ts +13 -0
  92. package/dist/test-difference.js +42 -0
  93. package/dist/testing.d.ts +122 -0
  94. package/dist/testing.js +261 -0
  95. package/dist/text-pages.d.ts +24 -0
  96. package/dist/text-pages.js +36 -0
  97. package/dist/tool-discovery.d.ts +59 -0
  98. package/dist/tool-discovery.js +136 -0
  99. package/dist/unevaluated.d.ts +7 -0
  100. package/dist/unevaluated.js +156 -0
  101. package/dist/version.d.ts +1 -1
  102. package/dist/version.js +1 -1
  103. package/dist/workflow-json.js +1 -1
  104. package/integrations/ai.d.mts +36 -0
  105. package/integrations/ai.mjs +178 -0
  106. package/integrations/call-options.mjs +9 -0
  107. package/integrations/langchain.d.mts +31 -0
  108. package/integrations/langchain.mjs +114 -0
  109. package/integrations/managed.mjs +154 -0
  110. package/integrations/types.d.mts +13 -0
  111. package/package.json +30 -1
package/README.md CHANGED
@@ -1,29 +1,38 @@
1
1
  # Toolsplice Core
2
2
 
3
- The standalone Node.js library for explicit MCP output-to-input handoffs. It includes validation, catalog contracts, generated typed adapters, recordings/replay, field-origin explanations and reviewed contract corrections.
3
+ Use this Node.js runtime to map one tool's output into another tool's arguments. Supply your own callers. Toolsplice checks the mapping against both contracts and validates the data before dispatch. Core includes offline replay, regression fixtures and typed adapter generation. The full package adds the CLI and MCP client adapters.
4
4
 
5
- **No MCP SDK, transport/server stack, Zod, PostgreSQL driver or Cloudflare service is required.** Production dependencies are Ajv and re2js. Your application supplies its own tool callers; the full `toolsplice` package supplies the CLI, SDK convenience adapters, learning proxy and optional PostgreSQL support.
5
+ ## Install
6
6
 
7
- Install with `npm install toolsplice-core@0.0.1`. For local development, build this checkout with `npm run build`, then pack `packages/core` and install that local tarball in your application.
7
+ ```sh
8
+ npm install toolsplice-core@0.0.2
9
+ ```
10
+
11
+ Requires Node.js 22 or later and ES modules.
12
+
13
+ ## Connect tools from two catalogs
14
+
15
+ Read the catalogs from your authorized MCP clients. The example assumes the document tool returns a `text` field and the note tool accepts `content`. Change the tool names and JSON pointers to match your catalogs.
8
16
 
9
- ```ts
10
- import { createContractFromCatalog, prepareSplice, type ToolCaller } from 'toolsplice-core';
17
+ ```js
18
+ import { createContractFromCatalog, prepareSplice } from "toolsplice-core";
11
19
 
12
- // Ordinary saved tools/list responses; identities are application-selected.
13
- const source = createContractFromCatalog({ name: 'documents' }, sourceCatalog);
14
- const target = createContractFromCatalog({ name: 'artifacts' }, targetCatalog);
15
- const adapter = prepareSplice(plan, source, target);
20
+ const docs = createContractFromCatalog({ name: "docs" }, sourceCatalog);
21
+ const notes = createContractFromCatalog({ name: "notes" }, targetCatalog);
22
+ const handoff = prepareSplice({
23
+ format: "toolsplice-splice", formatVersion: 1,
24
+ source: { server: "docs", tool: "read" },
25
+ target: { server: "notes", tool: "save" },
26
+ bindings: [{ from: "/text", to: "/content" }],
27
+ }, docs, notes);
16
28
 
17
- // Return raw MCP result objects. Authentication, authorization and connections stay in your app.
18
- const read: ToolCaller = (request, options) => yourClient.callSource(request, options);
19
- const write: ToolCaller = (request, options) => yourClient.callTarget(request, options);
20
- const result = await adapter.run(read, write, input, { allowReview: true });
29
+ const results = await handoff.run(readCaller, saveCaller, { id: "a1" });
21
30
  ```
22
31
 
23
- Use `emitSpliceModule(plan, source, target)` to generate a TypeScript adapter importing `toolsplice-core` by default. Supply `runtimeImport` explicitly to override it. Generated adapters and the library use the same runtime guards.
32
+ Both callers accept `{ name, arguments }` and return raw MCP result objects. Review `handoff.report` for incomplete schemas or application rules. If the report requires review, pass `{ allowReview: true }` after checking its assumptions. Runtime checks still apply to each row.
24
33
 
25
- `createSpliceRecorder` defaults to metadata only; explicitly opt in to payload capture. `replaySpliceRecording` consumes saved responses with no network connections. Pass `sourceContract` and/or `targetContract` to test captured cases against candidate contracts. `upgrade.status` distinguishes passed, failed and inconclusive checks; a previously failed recording cannot establish successful upgrade compatibility. Fixtures are evidence for those cases, not universal provider guarantees.
34
+ ## Test the handoff
26
35
 
27
- `applyContractCorrection` requires a pinned baseline, a reason and both accepted/rejected fixtures for every replacement. Applications explicitly choose corrected contracts. `explainSpliceError` reports field paths without literal values or raw causes.
36
+ Use `createMockCaller` to specify an expected tool name, arguments and result. Call `assertDone()` after the test to check that all expected calls occurred. Use `suiteFromRecording` to turn a complete payload recording into an offline regression. Metadata-only recording is the default. Payload fixtures can contain application data and should stay in storage you control.
28
37
 
29
- Redaction is configurable and is not guaranteed anonymization. Replay is not durable job recovery, rollback or proof of committed effects. The library makes no automatic semantic joins, coercions or retries. Node 22+, ESM.
38
+ Applications using Vercel AI SDK or LangChain can expose a prepared handoff with the adapters in `toolsplice-core/ai` and `toolsplice-core/langchain`. [Framework guide](https://cdn.jsdelivr.net/npm/toolsplice@0.0.2/docs/AGENT-FRAMEWORKS.md) · [Benchmark results and methodology](https://cdn.jsdelivr.net/npm/toolsplice@0.0.2/docs/BENCHMARKS.md) · [Full Node SDK](https://www.npmjs.com/package/toolsplice)
@@ -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
+ };