@try-works/dsh-model-as-tool 0.1.2 → 0.3.6
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/bin/dsh-tool-mode-credentials.mjs +20 -0
- package/bin/dsh-tool-mode.mjs +202 -0
- package/catalog/desert-ant-models.json +693 -693
- package/client/client.model-tools.js +592 -0
- package/client/index.js +1679 -0
- package/lib/adapters/index.d.ts.map +1 -1
- package/lib/adapters/index.js +4 -4
- package/lib/bindings.d.ts.map +1 -1
- package/lib/bindings.js +26 -25
- package/lib/capability.d.ts.map +1 -1
- package/lib/capability.js +17 -0
- package/lib/capture-path.d.ts +97 -0
- package/lib/capture-path.d.ts.map +1 -0
- package/lib/capture-path.js +152 -0
- package/lib/diagnostics.d.ts +166 -0
- package/lib/diagnostics.d.ts.map +1 -0
- package/lib/diagnostics.js +135 -0
- package/lib/extension-dependencies.d.ts +197 -0
- package/lib/extension-dependencies.d.ts.map +1 -0
- package/lib/extension-dependencies.js +369 -0
- package/lib/extension-dispatch.d.ts +117 -0
- package/lib/extension-dispatch.d.ts.map +1 -0
- package/lib/extension-dispatch.js +124 -0
- package/lib/extension-registrar.d.ts +100 -0
- package/lib/extension-registrar.d.ts.map +1 -0
- package/lib/extension-registrar.js +134 -0
- package/lib/extensions-api.d.ts +217 -0
- package/lib/extensions-api.d.ts.map +1 -0
- package/lib/extensions-api.js +17 -0
- package/lib/extensions-remote.d.ts +54 -0
- package/lib/extensions-remote.d.ts.map +1 -0
- package/lib/extensions-remote.js +66 -0
- package/lib/extensions-service.d.ts +334 -0
- package/lib/extensions-service.d.ts.map +1 -0
- package/lib/extensions-service.js +1351 -0
- package/lib/harness-llm.d.ts +138 -0
- package/lib/harness-llm.d.ts.map +1 -0
- package/lib/harness-llm.js +218 -0
- package/lib/harness-serving.d.ts +95 -0
- package/lib/harness-serving.d.ts.map +1 -0
- package/lib/harness-serving.js +157 -0
- package/lib/headless.d.ts +97 -0
- package/lib/headless.d.ts.map +1 -0
- package/lib/headless.js +349 -0
- package/lib/http-acquisition.d.ts +27 -0
- package/lib/http-acquisition.d.ts.map +1 -0
- package/lib/http-acquisition.js +136 -0
- package/lib/index.d.ts +250 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2625 -70
- package/lib/invocation-accounting.d.ts +169 -0
- package/lib/invocation-accounting.d.ts.map +1 -0
- package/lib/invocation-accounting.js +148 -0
- package/lib/legacy-migration.d.ts +95 -0
- package/lib/legacy-migration.d.ts.map +1 -0
- package/lib/legacy-migration.js +429 -0
- package/lib/managed-workers.d.ts +151 -0
- package/lib/managed-workers.d.ts.map +1 -0
- package/lib/managed-workers.js +249 -0
- package/lib/mcp/client-grant.d.ts +74 -0
- package/lib/mcp/client-grant.d.ts.map +1 -0
- package/lib/mcp/client-grant.js +60 -0
- package/lib/mcp/credential-cli.d.ts +38 -0
- package/lib/mcp/credential-cli.d.ts.map +1 -0
- package/lib/mcp/credential-cli.js +148 -0
- package/lib/mcp/credential-store.d.ts +143 -0
- package/lib/mcp/credential-store.d.ts.map +1 -0
- package/lib/mcp/credential-store.js +454 -0
- package/lib/mcp/host-binding.d.ts +25 -0
- package/lib/mcp/host-binding.d.ts.map +1 -1
- package/lib/mcp/host-binding.js +107 -14
- package/lib/mcp/http.d.ts +68 -18
- package/lib/mcp/http.d.ts.map +1 -1
- package/lib/mcp/http.js +390 -62
- package/lib/mcp/oauth.d.ts +149 -0
- package/lib/mcp/oauth.d.ts.map +1 -0
- package/lib/mcp/oauth.js +396 -0
- package/lib/mcp/protocol.d.ts +46 -7
- package/lib/mcp/protocol.d.ts.map +1 -1
- package/lib/mcp/protocol.js +63 -16
- package/lib/mcp/rate-limit.d.ts +68 -0
- package/lib/mcp/rate-limit.d.ts.map +1 -0
- package/lib/mcp/rate-limit.js +114 -0
- package/lib/mcp/sdk-v2.d.ts +17 -0
- package/lib/mcp/sdk-v2.d.ts.map +1 -0
- package/lib/mcp/sdk-v2.js +181 -0
- package/lib/mcp/server.d.ts +11 -1
- package/lib/mcp/server.d.ts.map +1 -1
- package/lib/mcp/server.js +80 -13
- package/lib/mcp/stdio.d.ts.map +1 -1
- package/lib/mcp/stdio.js +9 -1
- package/lib/mcp/subscriptions.d.ts +43 -1
- package/lib/mcp/subscriptions.d.ts.map +1 -1
- package/lib/mcp/subscriptions.js +90 -9
- package/lib/model-qualification.d.ts +192 -0
- package/lib/model-qualification.d.ts.map +1 -0
- package/lib/model-qualification.js +178 -0
- package/lib/planning.d.ts +246 -0
- package/lib/planning.d.ts.map +1 -0
- package/lib/planning.js +457 -0
- package/lib/prepared-assets.d.ts +178 -0
- package/lib/prepared-assets.d.ts.map +1 -0
- package/lib/prepared-assets.js +286 -0
- package/lib/provider-bridge.d.ts +37 -0
- package/lib/provider-bridge.d.ts.map +1 -1
- package/lib/provider-bridge.js +189 -12
- package/lib/ptc-authority.d.ts +140 -0
- package/lib/ptc-authority.d.ts.map +1 -0
- package/lib/ptc-authority.js +216 -0
- package/lib/ptc-runtime.d.ts +156 -0
- package/lib/ptc-runtime.d.ts.map +1 -0
- package/lib/ptc-runtime.js +191 -0
- package/lib/publication.d.ts +2 -1
- package/lib/publication.d.ts.map +1 -1
- package/lib/publication.js +13 -5
- package/lib/receipt.d.ts.map +1 -1
- package/lib/receipt.js +8 -0
- package/lib/title-proposal.d.ts +194 -0
- package/lib/title-proposal.d.ts.map +1 -0
- package/lib/title-proposal.js +244 -0
- package/lib/tool-mode-run.d.ts +235 -0
- package/lib/tool-mode-run.d.ts.map +1 -0
- package/lib/tool-mode-run.js +283 -0
- package/lib/types.d.ts +3 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/update-surface.d.ts +79 -0
- package/lib/update-surface.d.ts.map +1 -0
- package/lib/update-surface.js +224 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.d.ts +16 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.js +85 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts +38 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.js +445 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.d.ts +20 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.js +112 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts +14 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.js +63 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts +14 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.js +76 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts +82 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/dsh.js +274 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts +26 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/index.js +48 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/meta.d.ts +104 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/meta.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/meta.js +55 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts +107 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-contracts/lib/registry.js +246 -0
- package/node_modules/@try-works/tool-mode-contracts/package.json +34 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/bin/dsh-tool-mode.mjs +20 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts +80 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.js +533 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts +83 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.js +125 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts +70 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.js +201 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts +57 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.js +83 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts +31 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.js +31 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts +86 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.js +185 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts +126 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.js +297 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts +216 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.js +800 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts +210 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.js +368 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts +63 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.js +149 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts +35 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.js +179 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts +179 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.js +235 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts +367 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.js +807 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts +185 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.js +504 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts +17 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.js +80 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts +52 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.js +102 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts +171 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.js +271 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts +242 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.js +58 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts +118 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.js +113 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts +2 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.js +351 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts +150 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.js +670 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/package.json +53 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/schema/extension-manifest-1.1.0.schema.json +253 -0
- package/node_modules/@try-works/tool-mode-recipes/bin/tool-mode-recipe.mjs +15 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts +427 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/broker.js +592 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts +60 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/cli.js +936 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts +237 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.js +200 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts +85 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.js +176 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts +105 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/images.js +129 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts +25 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/index.js +25 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts +325 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.js +1310 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts +51 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/templates.js +310 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts +227 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-recipes/lib/titles.js +407 -0
- package/node_modules/@try-works/tool-mode-recipes/package.json +56 -0
- package/node_modules/@try-works/tool-mode-recipes/recipes/describe-image.json +38 -0
- package/node_modules/@try-works/tool-mode-recipes/recipes/text-title.json +45 -0
- package/node_modules/@try-works/tool-mode-recipes/schema/harness-model-recipe.schema.json +273 -0
- package/package.json +50 -17
- package/remote/spec.mjs +439 -0
- package/remote/typert.host.mjs +14 -0
- package/remote/typert.remote-client.mjs +16 -0
- package/lib/adapters/tongue.d.ts +0 -31
- package/lib/adapters/tongue.d.ts.map +0 -1
- package/lib/adapters/tongue.js +0 -93
- package/lib/adapters/voz.d.ts +0 -28
- package/lib/adapters/voz.d.ts.map +0 -1
- package/lib/adapters/voz.js +0 -102
- /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.d.ts +0 -0
- /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.d.ts.map +0 -0
- /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.js +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@try-works/tool-mode-contracts` — model-free standard tool contracts.
|
|
3
|
+
*
|
|
4
|
+
* This package contains no model bindings, no weights and no host code. It is the
|
|
5
|
+
* shared vocabulary that the Tool Mode host registers, that MCP clients read, and
|
|
6
|
+
* that extension packages implement against (DECL-01).
|
|
7
|
+
*
|
|
8
|
+
* @module @try-works/tool-mode-contracts
|
|
9
|
+
*/
|
|
10
|
+
export { assertValidContract, assertValidInput, assertValidOutput, assertAgainstSchema, compileSchema, ContractError, ContractViolationError, TOOL_META_SCHEMA, type ToolContract, } from './registry.ts';
|
|
11
|
+
export { withMeta, type ExecutionLocation, type ToolMeta } from './meta.ts';
|
|
12
|
+
export { crossFieldRules, ProjectionError, projectSchemaToDsh, projectToDsh, toDshParameters, type CrossFieldRule, type DshParameters, type DshProjection, } from './dsh.ts';
|
|
13
|
+
export { sttTranscribe, STT_ADMITTED_FORMATS } from './contracts/stt-transcribe.ts';
|
|
14
|
+
export { langDetect } from './contracts/lang-detect.ts';
|
|
15
|
+
export { textEmbed } from './contracts/text-embed.ts';
|
|
16
|
+
export { textRerank } from './contracts/text-rerank.ts';
|
|
17
|
+
export { textTitle, imageDescribe, multimodalEmbed, semanticSimilarity, semanticRank, semanticClassify, semanticDeduplicate, mediaFindMoments, decisionChoose, decisionTest, decisionScore, structuredExtract, toolsPlan, } from './contracts/standard.ts';
|
|
18
|
+
import type { ToolContract } from './registry.ts';
|
|
19
|
+
/**
|
|
20
|
+
* The standard contracts every Tool Mode host knows how to register.
|
|
21
|
+
*
|
|
22
|
+
* A host iterates this list; it does not switch on model names, which is what
|
|
23
|
+
* ARCH-02 and EXT-01 require of model-independent code.
|
|
24
|
+
*/
|
|
25
|
+
export declare const STANDARD_CONTRACTS: readonly ToolContract[];
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,KAAK,YAAY,GAClB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,KAAK,iBAAiB,EAAE,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE3E,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACvD,OAAO,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,SAAS,GACV,MAAM,yBAAyB,CAAA;AAqBhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,YAAY,EAkBrD,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@try-works/tool-mode-contracts` — model-free standard tool contracts.
|
|
3
|
+
*
|
|
4
|
+
* This package contains no model bindings, no weights and no host code. It is the
|
|
5
|
+
* shared vocabulary that the Tool Mode host registers, that MCP clients read, and
|
|
6
|
+
* that extension packages implement against (DECL-01).
|
|
7
|
+
*
|
|
8
|
+
* @module @try-works/tool-mode-contracts
|
|
9
|
+
*/
|
|
10
|
+
export { assertValidContract, assertValidInput, assertValidOutput, assertAgainstSchema, compileSchema, ContractError, ContractViolationError, TOOL_META_SCHEMA, } from "./registry.js";
|
|
11
|
+
export { withMeta } from "./meta.js";
|
|
12
|
+
export { crossFieldRules, ProjectionError, projectSchemaToDsh, projectToDsh, toDshParameters, } from "./dsh.js";
|
|
13
|
+
export { sttTranscribe, STT_ADMITTED_FORMATS } from "./contracts/stt-transcribe.js";
|
|
14
|
+
export { langDetect } from "./contracts/lang-detect.js";
|
|
15
|
+
export { textEmbed } from "./contracts/text-embed.js";
|
|
16
|
+
export { textRerank } from "./contracts/text-rerank.js";
|
|
17
|
+
export { textTitle, imageDescribe, multimodalEmbed, semanticSimilarity, semanticRank, semanticClassify, semanticDeduplicate, mediaFindMoments, decisionChoose, decisionTest, decisionScore, structuredExtract, toolsPlan, } from "./contracts/standard.js";
|
|
18
|
+
import { sttTranscribe } from "./contracts/stt-transcribe.js";
|
|
19
|
+
import { langDetect } from "./contracts/lang-detect.js";
|
|
20
|
+
import { textEmbed } from "./contracts/text-embed.js";
|
|
21
|
+
import { textRerank } from "./contracts/text-rerank.js";
|
|
22
|
+
import { textTitle, imageDescribe, multimodalEmbed, semanticSimilarity, semanticRank, semanticClassify, semanticDeduplicate, mediaFindMoments, decisionChoose, decisionTest, decisionScore, structuredExtract, toolsPlan, } from "./contracts/standard.js";
|
|
23
|
+
/**
|
|
24
|
+
* The standard contracts every Tool Mode host knows how to register.
|
|
25
|
+
*
|
|
26
|
+
* A host iterates this list; it does not switch on model names, which is what
|
|
27
|
+
* ARCH-02 and EXT-01 require of model-independent code.
|
|
28
|
+
*/
|
|
29
|
+
export const STANDARD_CONTRACTS = [
|
|
30
|
+
sttTranscribe,
|
|
31
|
+
langDetect,
|
|
32
|
+
textEmbed,
|
|
33
|
+
textRerank,
|
|
34
|
+
textTitle,
|
|
35
|
+
imageDescribe,
|
|
36
|
+
multimodalEmbed,
|
|
37
|
+
semanticSimilarity,
|
|
38
|
+
semanticRank,
|
|
39
|
+
semanticClassify,
|
|
40
|
+
semanticDeduplicate,
|
|
41
|
+
mediaFindMoments,
|
|
42
|
+
decisionChoose,
|
|
43
|
+
decisionTest,
|
|
44
|
+
decisionScore,
|
|
45
|
+
structuredExtract,
|
|
46
|
+
toolsPlan,
|
|
47
|
+
];
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared result envelope every Tool Mode tool returns (DECL-03).
|
|
3
|
+
*
|
|
4
|
+
* The envelope is what makes a result self-describing: a caller can tell which
|
|
5
|
+
* contract and version produced it, which implementation actually ran, where it
|
|
6
|
+
* ran, and whether the host attached any warnings. The host stamps the
|
|
7
|
+
* authoritative provenance fields; an implementation cannot forge another
|
|
8
|
+
* package's identity.
|
|
9
|
+
*
|
|
10
|
+
* DECL-04 is the reason `warnings` exists but a universal `confidence` does not:
|
|
11
|
+
* a successful call means a valid result was produced, not that it is correct,
|
|
12
|
+
* and a fabricated confidence number would claim more than the model supplied.
|
|
13
|
+
*
|
|
14
|
+
* @module @try-works/tool-mode-contracts/meta
|
|
15
|
+
*/
|
|
16
|
+
/** Where an implementation executed, relative to the caller (SPEC §6). */
|
|
17
|
+
export type ExecutionLocation =
|
|
18
|
+
/** The harness host process itself. */
|
|
19
|
+
'host'
|
|
20
|
+
/** The user's own device. */
|
|
21
|
+
| 'device'
|
|
22
|
+
/** A user-controlled server on the local network. */
|
|
23
|
+
| 'team-server'
|
|
24
|
+
/** A remote service outside the user's control. */
|
|
25
|
+
| 'remote';
|
|
26
|
+
/** Provenance and status metadata shared by every tool result. */
|
|
27
|
+
export interface ToolMeta {
|
|
28
|
+
/** Contract identity, e.g. `stt.transcribe`. */
|
|
29
|
+
readonly contract: string;
|
|
30
|
+
/** Semantic version of the CONTRACT, independent of the host release. */
|
|
31
|
+
readonly contractVersion: string;
|
|
32
|
+
/** The implementation that actually executed, e.g. `voz-onnx`. */
|
|
33
|
+
readonly implementationId: string;
|
|
34
|
+
/** Owning extension package identity. */
|
|
35
|
+
readonly extension: string;
|
|
36
|
+
/** Extension version, stamped by the host. */
|
|
37
|
+
readonly extensionVersion: string;
|
|
38
|
+
/** Which activation generation produced this result (DECL-08). */
|
|
39
|
+
readonly activationGeneration: number;
|
|
40
|
+
/** Where the work happened. */
|
|
41
|
+
readonly executionLocation: ExecutionLocation;
|
|
42
|
+
/** Host-issued receipt identity, for correlation and audit. */
|
|
43
|
+
readonly receiptId: string;
|
|
44
|
+
/** Non-fatal conditions the caller should know about. */
|
|
45
|
+
readonly warnings: readonly string[];
|
|
46
|
+
}
|
|
47
|
+
/** The JSON Schema for {@link ToolMeta}, used to validate every result. */
|
|
48
|
+
export declare const TOOL_META_SCHEMA: {
|
|
49
|
+
readonly type: "object";
|
|
50
|
+
readonly additionalProperties: false;
|
|
51
|
+
readonly required: readonly ["contract", "contractVersion", "implementationId", "extension", "extensionVersion", "activationGeneration", "executionLocation", "receiptId", "warnings"];
|
|
52
|
+
readonly properties: {
|
|
53
|
+
readonly contract: {
|
|
54
|
+
readonly type: "string";
|
|
55
|
+
readonly minLength: 1;
|
|
56
|
+
};
|
|
57
|
+
readonly contractVersion: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
readonly pattern: "^\\d+\\.\\d+\\.\\d+$";
|
|
60
|
+
};
|
|
61
|
+
readonly implementationId: {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
readonly minLength: 1;
|
|
64
|
+
};
|
|
65
|
+
readonly extension: {
|
|
66
|
+
readonly type: "string";
|
|
67
|
+
readonly minLength: 1;
|
|
68
|
+
};
|
|
69
|
+
readonly extensionVersion: {
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
readonly pattern: "^\\d+\\.\\d+\\.\\d+";
|
|
72
|
+
};
|
|
73
|
+
readonly activationGeneration: {
|
|
74
|
+
readonly type: "integer";
|
|
75
|
+
readonly minimum: 0;
|
|
76
|
+
};
|
|
77
|
+
readonly executionLocation: {
|
|
78
|
+
readonly type: "string";
|
|
79
|
+
readonly enum: readonly ["host", "device", "team-server", "remote"];
|
|
80
|
+
};
|
|
81
|
+
readonly receiptId: {
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
readonly minLength: 1;
|
|
84
|
+
};
|
|
85
|
+
readonly warnings: {
|
|
86
|
+
readonly type: "array";
|
|
87
|
+
readonly items: {
|
|
88
|
+
readonly type: "string";
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Attach a `meta` property to a result schema.
|
|
95
|
+
*
|
|
96
|
+
* Contracts declare their own payload; the envelope is identical everywhere, so
|
|
97
|
+
* it is composed here rather than retyped in each contract — retyping it is how
|
|
98
|
+
* the shapes drift apart.
|
|
99
|
+
* @param payload - the contract's payload schema properties.
|
|
100
|
+
* @param requiredPayload - payload property names that are required.
|
|
101
|
+
* @returns a closed object schema containing the payload plus `meta`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function withMeta(payload: Record<string, unknown>, requiredPayload?: readonly string[]): Record<string, unknown>;
|
|
104
|
+
//# sourceMappingURL=meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../src/meta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB;AAC3B,uCAAuC;AACrC,MAAM;AACR,6BAA6B;GAC3B,QAAQ;AACV,qDAAqD;GACnD,aAAa;AACf,mDAAmD;GACjD,QAAQ,CAAA;AAEZ,kEAAkE;AAClE,MAAM,WAAW,QAAQ;IACvB,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,yEAAyE;IACzE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,kEAAkE;IAClE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,kEAAkE;IAClE,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAA;IACrC,+BAA+B;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAA;IAC7C,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CACrC;AAED,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmBnB,CAAA;AAEV;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,eAAe,GAAE,SAAS,MAAM,EAAO,GACtC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared result envelope every Tool Mode tool returns (DECL-03).
|
|
3
|
+
*
|
|
4
|
+
* The envelope is what makes a result self-describing: a caller can tell which
|
|
5
|
+
* contract and version produced it, which implementation actually ran, where it
|
|
6
|
+
* ran, and whether the host attached any warnings. The host stamps the
|
|
7
|
+
* authoritative provenance fields; an implementation cannot forge another
|
|
8
|
+
* package's identity.
|
|
9
|
+
*
|
|
10
|
+
* DECL-04 is the reason `warnings` exists but a universal `confidence` does not:
|
|
11
|
+
* a successful call means a valid result was produced, not that it is correct,
|
|
12
|
+
* and a fabricated confidence number would claim more than the model supplied.
|
|
13
|
+
*
|
|
14
|
+
* @module @try-works/tool-mode-contracts/meta
|
|
15
|
+
*/
|
|
16
|
+
/** The JSON Schema for {@link ToolMeta}, used to validate every result. */
|
|
17
|
+
export const TOOL_META_SCHEMA = {
|
|
18
|
+
type: 'object',
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
required: [
|
|
21
|
+
'contract', 'contractVersion', 'implementationId', 'extension',
|
|
22
|
+
'extensionVersion', 'activationGeneration', 'executionLocation',
|
|
23
|
+
'receiptId', 'warnings',
|
|
24
|
+
],
|
|
25
|
+
properties: {
|
|
26
|
+
contract: { type: 'string', minLength: 1 },
|
|
27
|
+
contractVersion: { type: 'string', pattern: '^\\d+\\.\\d+\\.\\d+$' },
|
|
28
|
+
implementationId: { type: 'string', minLength: 1 },
|
|
29
|
+
extension: { type: 'string', minLength: 1 },
|
|
30
|
+
extensionVersion: { type: 'string', pattern: '^\\d+\\.\\d+\\.\\d+' },
|
|
31
|
+
activationGeneration: { type: 'integer', minimum: 0 },
|
|
32
|
+
executionLocation: { type: 'string', enum: ['host', 'device', 'team-server', 'remote'] },
|
|
33
|
+
receiptId: { type: 'string', minLength: 1 },
|
|
34
|
+
warnings: { type: 'array', items: { type: 'string' } },
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Attach a `meta` property to a result schema.
|
|
39
|
+
*
|
|
40
|
+
* Contracts declare their own payload; the envelope is identical everywhere, so
|
|
41
|
+
* it is composed here rather than retyped in each contract — retyping it is how
|
|
42
|
+
* the shapes drift apart.
|
|
43
|
+
* @param payload - the contract's payload schema properties.
|
|
44
|
+
* @param requiredPayload - payload property names that are required.
|
|
45
|
+
* @returns a closed object schema containing the payload plus `meta`.
|
|
46
|
+
*/
|
|
47
|
+
export function withMeta(payload, requiredPayload = []) {
|
|
48
|
+
return {
|
|
49
|
+
type: 'object',
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
required: [...requiredPayload, 'meta'],
|
|
52
|
+
properties: { ...payload, meta: TOOL_META_SCHEMA },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=meta.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract definitions and their runtime validation.
|
|
3
|
+
*
|
|
4
|
+
* A contract is the tool's public identity: stable name, version, input and
|
|
5
|
+
* output schema, semantics, limits and policy metadata (DECL-01). It is
|
|
6
|
+
* deliberately model-free — implementations bind to it, it does not know about
|
|
7
|
+
* them — which is what lets two models serve one `stt_transcribe` instead of
|
|
8
|
+
* producing a duplicate tool each (BASE-02).
|
|
9
|
+
*
|
|
10
|
+
* Milestone A is explicit that "a copied schema with no runtime validation is not
|
|
11
|
+
* completion", so this module validates both directions: the contract DEFINITION
|
|
12
|
+
* is checked when registered, and every RESULT is checked against the declared
|
|
13
|
+
* output schema before it reaches a caller.
|
|
14
|
+
*
|
|
15
|
+
* @module @try-works/tool-mode-contracts/registry
|
|
16
|
+
*/
|
|
17
|
+
import { TOOL_META_SCHEMA } from './meta.ts';
|
|
18
|
+
/** One tool contract: the authored-once public identity (DECL-01). */
|
|
19
|
+
export interface ToolContract {
|
|
20
|
+
/** Contract identity, e.g. `stt.transcribe`. Never a model name. */
|
|
21
|
+
readonly contract: string;
|
|
22
|
+
/** Semantic version, independent of any host release number. */
|
|
23
|
+
readonly version: string;
|
|
24
|
+
/** The tool name callers see, e.g. `stt_transcribe`. */
|
|
25
|
+
readonly toolName: string;
|
|
26
|
+
/** Concise description, used verbatim for DSH registration. */
|
|
27
|
+
readonly description: string;
|
|
28
|
+
/** Input schema as JSON Schema. The object root is closed. */
|
|
29
|
+
readonly inputSchema: Record<string, unknown>;
|
|
30
|
+
/** Output schema as JSON Schema, including the `meta` envelope. */
|
|
31
|
+
readonly outputSchema: Record<string, unknown>;
|
|
32
|
+
/** Declared semantics a caller must be able to rely on. */
|
|
33
|
+
readonly semantics: Readonly<Record<string, string | number | boolean>>;
|
|
34
|
+
/** Admitted resource limits, in the units the schema declares. */
|
|
35
|
+
readonly limits: Readonly<Record<string, number>>;
|
|
36
|
+
/** Unsupported cases the caller should be told about. */
|
|
37
|
+
readonly unsupported: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
/** A contract that failed validation, with every reason. */
|
|
40
|
+
export declare class ContractError extends Error {
|
|
41
|
+
readonly name = "ContractError";
|
|
42
|
+
/** The individual violations, in declaration order. */
|
|
43
|
+
readonly violations: readonly string[];
|
|
44
|
+
constructor(subject: string, violations: readonly string[]);
|
|
45
|
+
}
|
|
46
|
+
/** A value that did not satisfy a declared schema. */
|
|
47
|
+
export declare class ContractViolationError extends Error {
|
|
48
|
+
readonly name = "ContractViolationError";
|
|
49
|
+
readonly violations: readonly string[];
|
|
50
|
+
constructor(subject: string, violations: readonly string[]);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validate a contract definition.
|
|
54
|
+
*
|
|
55
|
+
* This is deliberately strict about the identity fields: a contract whose
|
|
56
|
+
* `toolName` is not a legal tool name, or whose version is not semver, would
|
|
57
|
+
* register a tool that callers cannot address consistently.
|
|
58
|
+
* @param contract - the definition to check.
|
|
59
|
+
* @throws ContractError listing every violation.
|
|
60
|
+
*/
|
|
61
|
+
export declare function assertValidContract(contract: ToolContract): void;
|
|
62
|
+
/**
|
|
63
|
+
* Validate caller arguments against the contract's input schema.
|
|
64
|
+
* @param contract - the contract to check against.
|
|
65
|
+
* @param args - the candidate arguments.
|
|
66
|
+
* @throws ContractViolationError listing every violation.
|
|
67
|
+
*/
|
|
68
|
+
export declare function assertValidInput(contract: ToolContract, args: unknown): void;
|
|
69
|
+
/**
|
|
70
|
+
* Validate a result against the contract's output schema.
|
|
71
|
+
*
|
|
72
|
+
* This runs before the value reaches a caller, so a violation surfaces as a
|
|
73
|
+
* tool failure rather than as malformed data downstream (AT-11).
|
|
74
|
+
* @param contract - the contract to check against.
|
|
75
|
+
* @param value - the candidate result.
|
|
76
|
+
* @throws ContractViolationError listing every violation.
|
|
77
|
+
*/
|
|
78
|
+
export declare function assertValidOutput(contract: ToolContract, value: unknown): void;
|
|
79
|
+
/** The meta envelope's own schema, exported for contract authors. */
|
|
80
|
+
export { TOOL_META_SCHEMA };
|
|
81
|
+
/**
|
|
82
|
+
* Compile an arbitrary JSON Schema once, for a host that serves manifest-declared
|
|
83
|
+
* tool schemas rather than registered contracts.
|
|
84
|
+
*
|
|
85
|
+
* Compiling at REGISTRATION (in the host's try/catch) means a malformed schema
|
|
86
|
+
* fails when the tool is registered, not on the first caller's event-loop tick —
|
|
87
|
+
* and it is never re-compiled per call, which a per-call text-keyed cache could
|
|
88
|
+
* not guarantee.
|
|
89
|
+
* @param schema - the JSON Schema to compile.
|
|
90
|
+
* @throws ContractError when the schema does not compile.
|
|
91
|
+
* @returns a validator whose violations are rendered by {@link assertAgainstSchema}.
|
|
92
|
+
*/
|
|
93
|
+
export declare function compileSchema(schema: Readonly<Record<string, unknown>>): (value: unknown) => readonly string[];
|
|
94
|
+
/**
|
|
95
|
+
* Validate an arbitrary value against a compiled declared schema.
|
|
96
|
+
*
|
|
97
|
+
* The full-schema counterpart of {@link assertValidInput}/{@link assertValidOutput}:
|
|
98
|
+
* the projected advertisement the DSH registry validates is deliberately LOOSER
|
|
99
|
+
* (union members become `json`, unsupported keywords are dropped), so without this
|
|
100
|
+
* the dropped keywords are enforced nowhere for manifest-declared tools.
|
|
101
|
+
* @param subject - the tool or schema name used in the violation message.
|
|
102
|
+
* @param validate - the compiled validator, from {@link compileSchema}.
|
|
103
|
+
* @param value - the candidate value.
|
|
104
|
+
* @throws ContractViolationError listing every violation.
|
|
105
|
+
*/
|
|
106
|
+
export declare function assertAgainstSchema(subject: string, validate: (value: unknown) => readonly string[], value: unknown): void;
|
|
107
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAE5C,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,8DAA8D;IAC9D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7C,mEAAmE;IACnE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9C,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CAAA;IACvE,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACjD,yDAAyD;IACzD,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;CACxC;AAED,4DAA4D;AAC5D,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAkB,IAAI,mBAAkB;IACxC,uDAAuD;IACvD,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;gBAC1B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE;CAI3D;AAED,sDAAsD;AACtD,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,SAAkB,IAAI,4BAA2B;IACjD,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;gBAC1B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE;CAI3D;AA0ED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAmDhE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAM5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAM9E;AAED,qEAAqE;AACrE,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAE3B;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,MAAM,EAAE,CAQ9G;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,SAAS,MAAM,EAAE,EAC/C,KAAK,EAAE,OAAO,GACb,IAAI,CAGN"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract definitions and their runtime validation.
|
|
3
|
+
*
|
|
4
|
+
* A contract is the tool's public identity: stable name, version, input and
|
|
5
|
+
* output schema, semantics, limits and policy metadata (DECL-01). It is
|
|
6
|
+
* deliberately model-free — implementations bind to it, it does not know about
|
|
7
|
+
* them — which is what lets two models serve one `stt_transcribe` instead of
|
|
8
|
+
* producing a duplicate tool each (BASE-02).
|
|
9
|
+
*
|
|
10
|
+
* Milestone A is explicit that "a copied schema with no runtime validation is not
|
|
11
|
+
* completion", so this module validates both directions: the contract DEFINITION
|
|
12
|
+
* is checked when registered, and every RESULT is checked against the declared
|
|
13
|
+
* output schema before it reaches a caller.
|
|
14
|
+
*
|
|
15
|
+
* @module @try-works/tool-mode-contracts/registry
|
|
16
|
+
*/
|
|
17
|
+
// The explicit `.js` suffix is REQUIRED for packed installs: plain Node ESM does
|
|
18
|
+
// not apply extension resolution to package subpaths, and the workspace's tsx
|
|
19
|
+
// loader masks that (the round-67 packed-orchestration run caught exactly this
|
|
20
|
+
// failure). extension-needle's validation.ts uses the same spelling.
|
|
21
|
+
import Ajv2020 from 'ajv/dist/2020.js';
|
|
22
|
+
import { TOOL_META_SCHEMA } from "./meta.js";
|
|
23
|
+
/** A contract that failed validation, with every reason. */
|
|
24
|
+
export class ContractError extends Error {
|
|
25
|
+
name = 'ContractError';
|
|
26
|
+
/** The individual violations, in declaration order. */
|
|
27
|
+
violations;
|
|
28
|
+
constructor(subject, violations) {
|
|
29
|
+
super(`${subject} is not a valid contract: ${violations.join('; ')}`);
|
|
30
|
+
this.violations = violations;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A value that did not satisfy a declared schema. */
|
|
34
|
+
export class ContractViolationError extends Error {
|
|
35
|
+
name = 'ContractViolationError';
|
|
36
|
+
violations;
|
|
37
|
+
constructor(subject, violations) {
|
|
38
|
+
super(`value violates the ${subject} schema: ${violations.join('; ')}`);
|
|
39
|
+
this.violations = violations;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The validator, on the 2020-12 dialect.
|
|
44
|
+
*
|
|
45
|
+
* 2020-12 rather than draft-07 because extension-declared schemas ship as
|
|
46
|
+
* 2020-12 documents (`$schema`, `$id`, `$defs` — the extension-needle package's
|
|
47
|
+
* tools-plan/structured-extract schemas are the concrete case): a draft-07
|
|
48
|
+
* compiler cannot resolve `#/$defs/...` references, so those real packages
|
|
49
|
+
* could not be activated in the host. `strict: false` for the same reason as
|
|
50
|
+
* before — contract schemas annotate keywords Ajv's strict mode rejects when
|
|
51
|
+
* they are merely descriptive, and a strict-mode THROW on an annotation would
|
|
52
|
+
* refuse a schema that validates fine. A schema that does not COMPILE (an
|
|
53
|
+
* unresolvable `$ref`, a structurally broken keyword) still throws at
|
|
54
|
+
* registration, so a bad schema refuses loudly rather than being accepted.
|
|
55
|
+
* `allowUnionTypes` admits `type: ["number", "null"]`-style unions, which the
|
|
56
|
+
* shipped needle schemas use for nullable fields. `allErrors` keeps the
|
|
57
|
+
* violation report listing every problem rather than the first.
|
|
58
|
+
*/
|
|
59
|
+
function createAjv() {
|
|
60
|
+
return new Ajv2020({ allErrors: true, strict: false, allowUnionTypes: true });
|
|
61
|
+
}
|
|
62
|
+
const ajv = createAjv();
|
|
63
|
+
const outputValidators = new Map();
|
|
64
|
+
const inputValidators = new Map();
|
|
65
|
+
/**
|
|
66
|
+
* Validators for $id-bearing schemas, keyed by the id itself.
|
|
67
|
+
*
|
|
68
|
+
* Ajv registers a compiled schema under its `$id`, and compiling the same id a
|
|
69
|
+
* second time THROWS "already exists" — which would make re-activating an
|
|
70
|
+
* extension (or two tools sharing one declared schema file) fail on the second
|
|
71
|
+
* compile. Identical content re-compiles to the same validator; DIFFERENT
|
|
72
|
+
* content under one id is a refusal, because two schemas sharing an id is
|
|
73
|
+
* exactly the drift a caller must never silently inherit.
|
|
74
|
+
*/
|
|
75
|
+
const compiledById = new Map();
|
|
76
|
+
/** Compile a schema, tolerating a repeat compile of identical $id content. */
|
|
77
|
+
function compileTracked(schema) {
|
|
78
|
+
const id = typeof schema.$id === 'string' ? schema.$id : undefined;
|
|
79
|
+
if (id === undefined)
|
|
80
|
+
return ajv.compile(schema);
|
|
81
|
+
const serialized = JSON.stringify(schema);
|
|
82
|
+
const cached = compiledById.get(id);
|
|
83
|
+
if (cached !== undefined) {
|
|
84
|
+
if (cached.serialized !== serialized) {
|
|
85
|
+
throw new ContractError('declared-schema', [`a schema with $id ${JSON.stringify(id)} was already compiled from different content; two different schemas must not share an id`]);
|
|
86
|
+
}
|
|
87
|
+
return cached.validate;
|
|
88
|
+
}
|
|
89
|
+
const validate = ajv.compile(schema);
|
|
90
|
+
compiledById.set(id, { serialized, validate });
|
|
91
|
+
return validate;
|
|
92
|
+
}
|
|
93
|
+
/** Render Ajv errors as stable, deduplicated strings. */
|
|
94
|
+
function renderErrors(errors) {
|
|
95
|
+
const seen = new Set();
|
|
96
|
+
const out = [];
|
|
97
|
+
for (const error of errors ?? []) {
|
|
98
|
+
const path = error.instancePath === '' ? '(root)' : error.instancePath;
|
|
99
|
+
const line = `${path} ${error.message ?? 'is invalid'}`;
|
|
100
|
+
if (!seen.has(line)) {
|
|
101
|
+
seen.add(line);
|
|
102
|
+
out.push(line);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Validate a contract definition.
|
|
109
|
+
*
|
|
110
|
+
* This is deliberately strict about the identity fields: a contract whose
|
|
111
|
+
* `toolName` is not a legal tool name, or whose version is not semver, would
|
|
112
|
+
* register a tool that callers cannot address consistently.
|
|
113
|
+
* @param contract - the definition to check.
|
|
114
|
+
* @throws ContractError listing every violation.
|
|
115
|
+
*/
|
|
116
|
+
export function assertValidContract(contract) {
|
|
117
|
+
const violations = [];
|
|
118
|
+
if (!/^[a-z][a-z0-9_]*$/.test(contract.toolName)) {
|
|
119
|
+
violations.push(`toolName ${JSON.stringify(contract.toolName)} must be lower snake_case`);
|
|
120
|
+
}
|
|
121
|
+
if (!/^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/.test(contract.contract)) {
|
|
122
|
+
violations.push(`contract ${JSON.stringify(contract.contract)} must be a dotted lower-case identity `
|
|
123
|
+
+ '(for example "stt.transcribe" or "text.language_detect")');
|
|
124
|
+
}
|
|
125
|
+
if (!/^\d+\.\d+\.\d+$/.test(contract.version)) {
|
|
126
|
+
violations.push(`version ${JSON.stringify(contract.version)} must be semantic (x.y.z)`);
|
|
127
|
+
}
|
|
128
|
+
if (contract.description.trim().length < 10) {
|
|
129
|
+
violations.push('description must be a real sentence, not a placeholder');
|
|
130
|
+
}
|
|
131
|
+
const input = contract.inputSchema;
|
|
132
|
+
if (input.type !== 'object') {
|
|
133
|
+
violations.push('inputSchema root must be an object (clients require an object argument)');
|
|
134
|
+
}
|
|
135
|
+
const output = contract.outputSchema;
|
|
136
|
+
if (output.type !== 'object') {
|
|
137
|
+
violations.push('outputSchema root must be an object for broad client compatibility (DECL-02)');
|
|
138
|
+
}
|
|
139
|
+
else if (output.properties?.meta === undefined) {
|
|
140
|
+
violations.push('outputSchema must include the shared `meta` envelope (DECL-03)');
|
|
141
|
+
}
|
|
142
|
+
// DECL-02: an unconstrained open object is not an adequate leaf-tool contract.
|
|
143
|
+
if (output.additionalProperties !== false) {
|
|
144
|
+
violations.push('outputSchema must be closed (additionalProperties: false), not a generic open object (DECL-02)');
|
|
145
|
+
}
|
|
146
|
+
if (contract.unsupported.length === 0) {
|
|
147
|
+
violations.push('unsupported must name at least one case; an empty list claims universal support');
|
|
148
|
+
}
|
|
149
|
+
if (violations.length > 0)
|
|
150
|
+
throw new ContractError(contract.contract, violations);
|
|
151
|
+
// Schemas must be compilable, or the contract is unenforceable.
|
|
152
|
+
try {
|
|
153
|
+
inputValidators.set(contract.contract, compileTracked(contract.inputSchema));
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
throw new ContractError(contract.contract, [`inputSchema does not compile: ${message(error)}`]);
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
outputValidators.set(contract.contract, compileTracked(contract.outputSchema));
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw new ContractError(contract.contract, [`outputSchema does not compile: ${message(error)}`]);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Validate caller arguments against the contract's input schema.
|
|
167
|
+
* @param contract - the contract to check against.
|
|
168
|
+
* @param args - the candidate arguments.
|
|
169
|
+
* @throws ContractViolationError listing every violation.
|
|
170
|
+
*/
|
|
171
|
+
export function assertValidInput(contract, args) {
|
|
172
|
+
const validate = inputValidators.get(contract.contract);
|
|
173
|
+
if (validate === undefined) {
|
|
174
|
+
throw new ContractError(contract.contract, ['input was validated before the contract was registered']);
|
|
175
|
+
}
|
|
176
|
+
if (!validate(args))
|
|
177
|
+
throw new ContractViolationError(contract.contract, renderErrors(validate.errors));
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Validate a result against the contract's output schema.
|
|
181
|
+
*
|
|
182
|
+
* This runs before the value reaches a caller, so a violation surfaces as a
|
|
183
|
+
* tool failure rather than as malformed data downstream (AT-11).
|
|
184
|
+
* @param contract - the contract to check against.
|
|
185
|
+
* @param value - the candidate result.
|
|
186
|
+
* @throws ContractViolationError listing every violation.
|
|
187
|
+
*/
|
|
188
|
+
export function assertValidOutput(contract, value) {
|
|
189
|
+
const validate = outputValidators.get(contract.contract);
|
|
190
|
+
if (validate === undefined) {
|
|
191
|
+
throw new ContractError(contract.contract, ['result was validated before the contract was registered']);
|
|
192
|
+
}
|
|
193
|
+
if (!validate(value))
|
|
194
|
+
throw new ContractViolationError(contract.contract, renderErrors(validate.errors));
|
|
195
|
+
}
|
|
196
|
+
/** The meta envelope's own schema, exported for contract authors. */
|
|
197
|
+
export { TOOL_META_SCHEMA };
|
|
198
|
+
/**
|
|
199
|
+
* Compile an arbitrary JSON Schema once, for a host that serves manifest-declared
|
|
200
|
+
* tool schemas rather than registered contracts.
|
|
201
|
+
*
|
|
202
|
+
* Compiling at REGISTRATION (in the host's try/catch) means a malformed schema
|
|
203
|
+
* fails when the tool is registered, not on the first caller's event-loop tick —
|
|
204
|
+
* and it is never re-compiled per call, which a per-call text-keyed cache could
|
|
205
|
+
* not guarantee.
|
|
206
|
+
* @param schema - the JSON Schema to compile.
|
|
207
|
+
* @throws ContractError when the schema does not compile.
|
|
208
|
+
* @returns a validator whose violations are rendered by {@link assertAgainstSchema}.
|
|
209
|
+
*/
|
|
210
|
+
export function compileSchema(schema) {
|
|
211
|
+
let validate;
|
|
212
|
+
try {
|
|
213
|
+
validate = compileTracked(schema);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
throw new ContractError('declared-schema', [`schema does not compile: ${message(error)}`]);
|
|
217
|
+
}
|
|
218
|
+
return value => (validate(value) ? [] : renderErrors(validate.errors));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Validate an arbitrary value against a compiled declared schema.
|
|
222
|
+
*
|
|
223
|
+
* The full-schema counterpart of {@link assertValidInput}/{@link assertValidOutput}:
|
|
224
|
+
* the projected advertisement the DSH registry validates is deliberately LOOSER
|
|
225
|
+
* (union members become `json`, unsupported keywords are dropped), so without this
|
|
226
|
+
* the dropped keywords are enforced nowhere for manifest-declared tools.
|
|
227
|
+
* @param subject - the tool or schema name used in the violation message.
|
|
228
|
+
* @param validate - the compiled validator, from {@link compileSchema}.
|
|
229
|
+
* @param value - the candidate value.
|
|
230
|
+
* @throws ContractViolationError listing every violation.
|
|
231
|
+
*/
|
|
232
|
+
export function assertAgainstSchema(subject, validate, value) {
|
|
233
|
+
const violations = validate(value);
|
|
234
|
+
if (violations.length > 0)
|
|
235
|
+
throw new ContractViolationError(subject, violations);
|
|
236
|
+
}
|
|
237
|
+
/** Best-effort message from an arbitrary thrown value. */
|
|
238
|
+
function message(error) {
|
|
239
|
+
try {
|
|
240
|
+
return error instanceof Error ? error.message : String(error);
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return '<unrenderable>';
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@try-works/tool-mode-contracts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Model-free standard tool contracts for Tool Mode: identities, schemas, semantics and runtime validation",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/try-works/dsh-model-as-tool.git",
|
|
10
|
+
"directory": "packages/tool-mode-contracts"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "lib/index.js",
|
|
14
|
+
"types": "lib/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": { "types": "./lib/index.d.ts", "default": "./lib/index.js" },
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": ["lib/**/*.js", "lib/**/*.d.ts", "lib/**/*.d.ts.map", "README.md"],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"ajv": "^8.20.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.build.json",
|
|
25
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
26
|
+
"test": "tsx --test tests/*.test.ts",
|
|
27
|
+
"prepack": "tsc -p tsconfig.build.json",
|
|
28
|
+
"prepare": "tsc -p tsconfig.build.json"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^24.0.0",
|
|
32
|
+
"typescript": "^5.9.0"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The `dsh-tool-mode` executable (EXT-31).
|
|
4
|
+
*
|
|
5
|
+
* A thin shim: it wires real process streams into the tested CLI and translates
|
|
6
|
+
* the returned code into an exit status. All the logic lives in the library, so
|
|
7
|
+
* every path — including the refusals — is exercised by tests rather than only by
|
|
8
|
+
* running the binary by hand.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { runToolModeCli } from '../lib/cli.js'
|
|
12
|
+
|
|
13
|
+
const code = await runToolModeCli(
|
|
14
|
+
process.argv.slice(2),
|
|
15
|
+
{
|
|
16
|
+
out: line => process.stdout.write(`${line}\n`),
|
|
17
|
+
err: line => process.stderr.write(`${line}\n`),
|
|
18
|
+
},
|
|
19
|
+
)
|
|
20
|
+
process.exitCode = code
|