@try-works/dsh-model-as-tool 0.1.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +614 -0
- package/client/index.js +1717 -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 +325 -0
- package/lib/extension-dependencies.d.ts.map +1 -0
- package/lib/extension-dependencies.js +858 -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 +221 -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 +367 -0
- package/lib/extensions-service.d.ts.map +1 -0
- package/lib/extensions-service.js +1527 -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 +271 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2644 -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/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/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.map +1 -1
- package/node_modules/@try-works/tool-mode-contracts/lib/dsh.js +69 -55
- package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts +4 -1
- package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts.map +1 -1
- package/node_modules/@try-works/tool-mode-contracts/lib/index.js +26 -2
- package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts +28 -2
- package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts.map +1 -1
- package/node_modules/@try-works/tool-mode-contracts/lib/registry.js +93 -10
- package/node_modules/@try-works/tool-mode-contracts/package.json +0 -1
- 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 +32 -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 +32 -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 +191 -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/tar-gzip-source.d.ts +44 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/tar-gzip-source.d.ts.map +1 -0
- package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/tar-gzip-source.js +243 -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 +43 -15
- package/remote/spec.mjs +462 -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,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A REAL DSH-backed {@link LlmProvider} for the harness broker (HLM-01).
|
|
3
|
+
*
|
|
4
|
+
* The broker has been tested only against fake providers; this adapter runs a
|
|
5
|
+
* recipe through the DSH harness's ACTUAL LLM service — `ctx.llm`
|
|
6
|
+
* (`@deepseek-ai/dsh-llm`'s `LlmRuntime`): `resolveModelInfo` for the model's
|
|
7
|
+
* own capability descriptors and `stream` for the chunk stream, including the
|
|
8
|
+
* `llm/stream` waterfall. The recipes package still ships NO import of the DSH
|
|
9
|
+
* packages: the surface below is a STRUCTURAL MIRROR of the DSH vocabulary,
|
|
10
|
+
* declared here so the published package stays dependency-free, and the
|
|
11
|
+
* conformance is proven in tests/dsh-adapter.test.ts by running the adapter
|
|
12
|
+
* through the REAL LlmRuntime with a registered LlmAdapter subclass.
|
|
13
|
+
*
|
|
14
|
+
* The mirrored DSH vocabulary (node_modules/@deepseek-ai/dsh-llm/src/types.ts):
|
|
15
|
+
* - `DshModelDescriptor` mirrors `LlmResolvedModelInfo` (types.ts:410-421):
|
|
16
|
+
* `inputModalities`, `context.contextWindow`, `defaultMaxTokens`.
|
|
17
|
+
* - `DshContentPart` mirrors `ContentBlock`'s text/image members (types.ts:62-89):
|
|
18
|
+
* text carries `{ type: 'text', text }`; images are `{ type: 'image',
|
|
19
|
+
* attachment }` — an ATTACHMENT REFERENCE owned by DSH's attachment service,
|
|
20
|
+
* which a recipes-only package cannot mint. Images therefore travel only
|
|
21
|
+
* through the deployment-supplied `images` hook (see below).
|
|
22
|
+
* - `DshCompletionRequest` mirrors the consumed subset of `GenerateOptions`
|
|
23
|
+
* (types.ts:511-553): provider/model/messages/maxTokens/signal.
|
|
24
|
+
* - `DshStreamChunk` mirrors `StreamChunk` (types.ts:452-464): text-delta,
|
|
25
|
+
* tool-call-delta, usage, finish; block-start/block-end/reasoning-delta are
|
|
26
|
+
* admitted as ignored passthroughs. `finish.reason.kind` mirrors
|
|
27
|
+
* `FinishReasonMap` (types.ts:156-162): stop, tool-calls, max-tokens,
|
|
28
|
+
* aborted{ failure }, error{ failure }.
|
|
29
|
+
*
|
|
30
|
+
* Mappings to the broker's vocabulary (RCP-11):
|
|
31
|
+
* - text-delta accumulation + finish `stop` -> { kind: 'text', text, usage }
|
|
32
|
+
* - finish `max-tokens` -> { kind: 'truncated', text }
|
|
33
|
+
* - finish `tool-calls` (or a tool-call-delta) -> { kind: 'tool_call', toolName }
|
|
34
|
+
* — NEVER executed (HLM-06); the broker refuses it as UNEXPECTED_MODEL_TOOL_CALL
|
|
35
|
+
* - finish `aborted` -> thrown; the broker reports CANCELLED
|
|
36
|
+
* when the caller's signal aborted, PROVIDER_FAILED otherwise
|
|
37
|
+
* - finish `error` / an unknown finish -> thrown with the failure facts; the
|
|
38
|
+
* broker reports PROVIDER_FAILED
|
|
39
|
+
*
|
|
40
|
+
* HLM-02: the provider carries a GENERATION. A deployment wires the generation
|
|
41
|
+
* to its adapter registration (or reload count), so an authorization issued
|
|
42
|
+
* against an old adapter cannot be satisfied by a new one.
|
|
43
|
+
*
|
|
44
|
+
* Capabilities are READ from the model descriptor, never hardcoded: an
|
|
45
|
+
* explicit `inputModalities` omission is negative capability (`images:
|
|
46
|
+
* 'unsupported'`), an absent descriptor field is the honest `unknown`, and a
|
|
47
|
+
* declared `image` modality is `supported` ONLY when the deployment also
|
|
48
|
+
* supplied the `images` transport hook — a model that can see images but has
|
|
49
|
+
* no transport for them must not have them silently dropped.
|
|
50
|
+
*
|
|
51
|
+
* @module @try-works/tool-mode-recipes/dsh-adapter
|
|
52
|
+
*/
|
|
53
|
+
import type { ProviderDestination } from './broker.ts';
|
|
54
|
+
import type { BrokerImage, BrokerRequest, LlmCompletion, LlmProvider, ProviderCapabilities } from './broker.ts';
|
|
55
|
+
/** The model descriptor this adapter reads capabilities from (mirrors `LlmResolvedModelInfo`). */
|
|
56
|
+
export interface DshModelDescriptor {
|
|
57
|
+
/** The owning provider route; must equal the provider this adapter was built for. */
|
|
58
|
+
readonly provider: string;
|
|
59
|
+
/** The exact model id. */
|
|
60
|
+
readonly id: string;
|
|
61
|
+
/** Human-readable name. */
|
|
62
|
+
readonly name: string;
|
|
63
|
+
/** Accepted input modalities; absent means unknown, an explicit omission is negative capability. */
|
|
64
|
+
readonly inputModalities?: readonly ('text' | 'image')[];
|
|
65
|
+
/** Provider-owned context capacity, when known. */
|
|
66
|
+
readonly context?: {
|
|
67
|
+
readonly contextWindow: number;
|
|
68
|
+
};
|
|
69
|
+
/** Adapter-configured per-request output cap materialized when callers omit one. */
|
|
70
|
+
readonly defaultMaxTokens?: number;
|
|
71
|
+
}
|
|
72
|
+
/** A text part of a user message (mirrors `TextBlock`). */
|
|
73
|
+
export interface DshTextPart {
|
|
74
|
+
readonly type: 'text';
|
|
75
|
+
readonly text: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* An image part of a user message (mirrors `ImageBlock`).
|
|
79
|
+
*
|
|
80
|
+
* The attachment reference is OPAQUE here: it is minted by DSH's attachment
|
|
81
|
+
* service, which the recipes package cannot reach. The deployment supplies the
|
|
82
|
+
* bytes-to-part transport (see {@link DshImageTransport}); this type merely
|
|
83
|
+
* says what the transport must produce.
|
|
84
|
+
*/
|
|
85
|
+
export interface DshImagePart {
|
|
86
|
+
readonly type: 'image';
|
|
87
|
+
readonly attachment: unknown;
|
|
88
|
+
}
|
|
89
|
+
/** One content part, text or image. */
|
|
90
|
+
export type DshContentPart = DshTextPart | DshImagePart;
|
|
91
|
+
/** One user message in a completion request (mirrors `RequestUserInput`). */
|
|
92
|
+
export interface DshUserMessage {
|
|
93
|
+
readonly role: 'user';
|
|
94
|
+
readonly content: readonly DshContentPart[];
|
|
95
|
+
}
|
|
96
|
+
/** The completion request (mirrors the consumed subset of `GenerateOptions`). */
|
|
97
|
+
export interface DshCompletionRequest {
|
|
98
|
+
readonly provider: string;
|
|
99
|
+
readonly model: string;
|
|
100
|
+
/** Exactly the messages the adapter sends: one user message per recipe call. */
|
|
101
|
+
readonly messages: readonly DshUserMessage[];
|
|
102
|
+
readonly maxTokens?: number;
|
|
103
|
+
readonly signal?: AbortSignal;
|
|
104
|
+
}
|
|
105
|
+
/** The failure facts a terminal chunk carries (mirrors `LlmFailure`). */
|
|
106
|
+
export interface DshFailure {
|
|
107
|
+
readonly message: string;
|
|
108
|
+
readonly code: string;
|
|
109
|
+
readonly status?: number;
|
|
110
|
+
}
|
|
111
|
+
/** The terminal finish reason (mirrors `FinishReasonMap`, with an unknown-kind catch-all). */
|
|
112
|
+
export type DshFinishReason = {
|
|
113
|
+
readonly kind: 'stop';
|
|
114
|
+
} | {
|
|
115
|
+
readonly kind: 'tool-calls';
|
|
116
|
+
} | {
|
|
117
|
+
readonly kind: 'max-tokens';
|
|
118
|
+
} | {
|
|
119
|
+
readonly kind: 'aborted';
|
|
120
|
+
readonly failure: DshFailure;
|
|
121
|
+
} | {
|
|
122
|
+
readonly kind: 'error';
|
|
123
|
+
readonly failure: DshFailure;
|
|
124
|
+
} | {
|
|
125
|
+
readonly kind: string;
|
|
126
|
+
};
|
|
127
|
+
/** The stream chunk vocabulary (mirrors `StreamChunk`; passthrough members are ignored). */
|
|
128
|
+
export type DshStreamChunk = {
|
|
129
|
+
readonly type: 'text-delta';
|
|
130
|
+
readonly index: number;
|
|
131
|
+
readonly text: string;
|
|
132
|
+
} | {
|
|
133
|
+
readonly type: 'reasoning-delta';
|
|
134
|
+
readonly index: number;
|
|
135
|
+
readonly text: string;
|
|
136
|
+
} | {
|
|
137
|
+
readonly type: 'tool-call-delta';
|
|
138
|
+
readonly index: number;
|
|
139
|
+
readonly name?: string;
|
|
140
|
+
readonly argumentsDelta: string;
|
|
141
|
+
} | {
|
|
142
|
+
readonly type: 'block-start';
|
|
143
|
+
readonly index: number;
|
|
144
|
+
readonly blockType: string;
|
|
145
|
+
} | {
|
|
146
|
+
readonly type: 'block-end';
|
|
147
|
+
readonly index: number;
|
|
148
|
+
readonly block: unknown;
|
|
149
|
+
} | {
|
|
150
|
+
readonly type: 'usage';
|
|
151
|
+
readonly usage: {
|
|
152
|
+
readonly inputTokens: number;
|
|
153
|
+
readonly outputTokens: number;
|
|
154
|
+
};
|
|
155
|
+
} | {
|
|
156
|
+
readonly type: 'finish';
|
|
157
|
+
readonly reason: DshFinishReason;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* The DSH LLM surface this adapter consumes.
|
|
161
|
+
*
|
|
162
|
+
* `ctx.llm` (an `LlmRuntime`) satisfies this structurally; the conformance
|
|
163
|
+
* test proves it by driving a REAL LlmRuntime through this interface. The
|
|
164
|
+
* declared property-style functions keep the check contravariant, so an
|
|
165
|
+
* incompatible DSH version fails to type, not fails at runtime.
|
|
166
|
+
*/
|
|
167
|
+
export interface DshLlmSurface {
|
|
168
|
+
/** Resolve one exact model's descriptor (mirrors `LlmRuntime.resolveModelInfo`). */
|
|
169
|
+
readonly resolveModelInfo: (provider: string, model: string, signal?: AbortSignal) => Promise<DshModelDescriptor>;
|
|
170
|
+
/** Stream one call (mirrors `LlmRuntime.stream`). */
|
|
171
|
+
readonly stream: (request: DshCompletionRequest) => AsyncIterable<DshStreamChunk>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The deployment-supplied image transport (HLM-11).
|
|
175
|
+
*
|
|
176
|
+
* A recipes-only package cannot mint DSH attachment references, so the
|
|
177
|
+
* deployment supplies this hook (in the host: reach `ctx.get('attachments')`
|
|
178
|
+
* and mint the reference there). Without the hook an image-capable model
|
|
179
|
+
* reports `images: 'unknown'`, and the broker refuses image recipes with
|
|
180
|
+
* EXECUTOR_CAPABILITY_UNKNOWN instead of dropping the image silently.
|
|
181
|
+
*/
|
|
182
|
+
export type DshImageTransport = (image: BrokerImage) => DshImagePart | Promise<DshImagePart>;
|
|
183
|
+
/** Options for {@link DshLlmProvider.create}. */
|
|
184
|
+
export interface DshProviderOptions {
|
|
185
|
+
/** The DSH LLM surface (the deployment's `ctx.llm`, or a test double). */
|
|
186
|
+
readonly llm: DshLlmSurface;
|
|
187
|
+
/** The registered adapter route, e.g. `deepseek`. */
|
|
188
|
+
readonly provider: string;
|
|
189
|
+
/** The exact model id the recipes run against. */
|
|
190
|
+
readonly model: string;
|
|
191
|
+
/** Where this provider runs; defaults to `remote` (a harness model is not local). */
|
|
192
|
+
readonly destination?: ProviderDestination;
|
|
193
|
+
/**
|
|
194
|
+
* The adapter generation (HLM-02). The deployment should tie this to its DSH
|
|
195
|
+
* adapter registration so an old authorization cannot ride a new adapter.
|
|
196
|
+
* Defaults to 1.
|
|
197
|
+
*/
|
|
198
|
+
readonly generation?: number;
|
|
199
|
+
/** The image transport hook; without it images are `unknown`, never dropped. */
|
|
200
|
+
readonly images?: DshImageTransport;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* A DSH-backed {@link LlmProvider}, built against a resolved model descriptor.
|
|
204
|
+
*/
|
|
205
|
+
export declare class DshLlmProvider implements LlmProvider {
|
|
206
|
+
#private;
|
|
207
|
+
readonly id: string;
|
|
208
|
+
readonly generation: number;
|
|
209
|
+
readonly destination: ProviderDestination;
|
|
210
|
+
private constructor();
|
|
211
|
+
/**
|
|
212
|
+
* Resolve the model descriptor and build the provider (HLM-02).
|
|
213
|
+
*
|
|
214
|
+
* The descriptor is resolved ONCE, at creation: capabilities are the model
|
|
215
|
+
* facts as of this generation, not whatever the endpoint happens to report
|
|
216
|
+
* mid-run.
|
|
217
|
+
* @param options - the surface, route, model and transports.
|
|
218
|
+
* @returns the provider.
|
|
219
|
+
* @throws when the descriptor cannot be resolved or names another route.
|
|
220
|
+
*/
|
|
221
|
+
static create(options: DshProviderOptions): Promise<DshLlmProvider>;
|
|
222
|
+
/** The frozen descriptor-derived facts. */
|
|
223
|
+
capabilities(): ProviderCapabilities;
|
|
224
|
+
/**
|
|
225
|
+
* Perform one isolated call through the DSH stream.
|
|
226
|
+
*
|
|
227
|
+
* The request is one user message — the rendered prompt plus one attachment
|
|
228
|
+
* part per bound image via the transport hook — with no system prompt, no
|
|
229
|
+
* tools and no history, exactly as the broker's isolation invariant requires
|
|
230
|
+
* (HLM-05). Chunks are assembled per block index; the terminal finish maps
|
|
231
|
+
* to the broker's completion vocabulary.
|
|
232
|
+
* @param request - the broker request.
|
|
233
|
+
* @returns the completion.
|
|
234
|
+
*/
|
|
235
|
+
complete(request: BrokerRequest): Promise<LlmCompletion>;
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=dsh-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dsh-adapter.d.ts","sourceRoot":"","sources":["../src/dsh-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAmB,aAAa,EAAE,WAAW,EAAY,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAE1I,kGAAkG;AAClG,MAAM,WAAW,kBAAkB;IACjC,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,2BAA2B;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,oGAAoG;IACpG,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAA;IACxD,mDAAmD;IACnD,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE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mB,CAAA;IAQzC,OAAO;IA4BP;;;;;;;;;OASG;WACU,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAWzE,2CAA2C;IAC3C,YAAY,IAAI,oBAAoB;IAIpC;;;;;;;;;;OAUG;IACG,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CA0E/D"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A REAL DSH-backed {@link LlmProvider} for the harness broker (HLM-01).
|
|
3
|
+
*
|
|
4
|
+
* The broker has been tested only against fake providers; this adapter runs a
|
|
5
|
+
* recipe through the DSH harness's ACTUAL LLM service — `ctx.llm`
|
|
6
|
+
* (`@deepseek-ai/dsh-llm`'s `LlmRuntime`): `resolveModelInfo` for the model's
|
|
7
|
+
* own capability descriptors and `stream` for the chunk stream, including the
|
|
8
|
+
* `llm/stream` waterfall. The recipes package still ships NO import of the DSH
|
|
9
|
+
* packages: the surface below is a STRUCTURAL MIRROR of the DSH vocabulary,
|
|
10
|
+
* declared here so the published package stays dependency-free, and the
|
|
11
|
+
* conformance is proven in tests/dsh-adapter.test.ts by running the adapter
|
|
12
|
+
* through the REAL LlmRuntime with a registered LlmAdapter subclass.
|
|
13
|
+
*
|
|
14
|
+
* The mirrored DSH vocabulary (node_modules/@deepseek-ai/dsh-llm/src/types.ts):
|
|
15
|
+
* - `DshModelDescriptor` mirrors `LlmResolvedModelInfo` (types.ts:410-421):
|
|
16
|
+
* `inputModalities`, `context.contextWindow`, `defaultMaxTokens`.
|
|
17
|
+
* - `DshContentPart` mirrors `ContentBlock`'s text/image members (types.ts:62-89):
|
|
18
|
+
* text carries `{ type: 'text', text }`; images are `{ type: 'image',
|
|
19
|
+
* attachment }` — an ATTACHMENT REFERENCE owned by DSH's attachment service,
|
|
20
|
+
* which a recipes-only package cannot mint. Images therefore travel only
|
|
21
|
+
* through the deployment-supplied `images` hook (see below).
|
|
22
|
+
* - `DshCompletionRequest` mirrors the consumed subset of `GenerateOptions`
|
|
23
|
+
* (types.ts:511-553): provider/model/messages/maxTokens/signal.
|
|
24
|
+
* - `DshStreamChunk` mirrors `StreamChunk` (types.ts:452-464): text-delta,
|
|
25
|
+
* tool-call-delta, usage, finish; block-start/block-end/reasoning-delta are
|
|
26
|
+
* admitted as ignored passthroughs. `finish.reason.kind` mirrors
|
|
27
|
+
* `FinishReasonMap` (types.ts:156-162): stop, tool-calls, max-tokens,
|
|
28
|
+
* aborted{ failure }, error{ failure }.
|
|
29
|
+
*
|
|
30
|
+
* Mappings to the broker's vocabulary (RCP-11):
|
|
31
|
+
* - text-delta accumulation + finish `stop` -> { kind: 'text', text, usage }
|
|
32
|
+
* - finish `max-tokens` -> { kind: 'truncated', text }
|
|
33
|
+
* - finish `tool-calls` (or a tool-call-delta) -> { kind: 'tool_call', toolName }
|
|
34
|
+
* — NEVER executed (HLM-06); the broker refuses it as UNEXPECTED_MODEL_TOOL_CALL
|
|
35
|
+
* - finish `aborted` -> thrown; the broker reports CANCELLED
|
|
36
|
+
* when the caller's signal aborted, PROVIDER_FAILED otherwise
|
|
37
|
+
* - finish `error` / an unknown finish -> thrown with the failure facts; the
|
|
38
|
+
* broker reports PROVIDER_FAILED
|
|
39
|
+
*
|
|
40
|
+
* HLM-02: the provider carries a GENERATION. A deployment wires the generation
|
|
41
|
+
* to its adapter registration (or reload count), so an authorization issued
|
|
42
|
+
* against an old adapter cannot be satisfied by a new one.
|
|
43
|
+
*
|
|
44
|
+
* Capabilities are READ from the model descriptor, never hardcoded: an
|
|
45
|
+
* explicit `inputModalities` omission is negative capability (`images:
|
|
46
|
+
* 'unsupported'`), an absent descriptor field is the honest `unknown`, and a
|
|
47
|
+
* declared `image` modality is `supported` ONLY when the deployment also
|
|
48
|
+
* supplied the `images` transport hook — a model that can see images but has
|
|
49
|
+
* no transport for them must not have them silently dropped.
|
|
50
|
+
*
|
|
51
|
+
* @module @try-works/tool-mode-recipes/dsh-adapter
|
|
52
|
+
*/
|
|
53
|
+
import { INITIAL_MAX_OUTPUT_TOKENS } from "./recipe-format.js";
|
|
54
|
+
/**
|
|
55
|
+
* A DSH-backed {@link LlmProvider}, built against a resolved model descriptor.
|
|
56
|
+
*/
|
|
57
|
+
export class DshLlmProvider {
|
|
58
|
+
id;
|
|
59
|
+
generation;
|
|
60
|
+
destination;
|
|
61
|
+
#llm;
|
|
62
|
+
#provider;
|
|
63
|
+
#model;
|
|
64
|
+
#images;
|
|
65
|
+
/** The frozen capability facts, derived from the descriptor at creation. */
|
|
66
|
+
#capabilities;
|
|
67
|
+
constructor(options, descriptor) {
|
|
68
|
+
this.id = `dsh:${options.provider}/${options.model}`;
|
|
69
|
+
this.generation = options.generation ?? 1;
|
|
70
|
+
this.destination = options.destination ?? 'remote';
|
|
71
|
+
this.#llm = options.llm;
|
|
72
|
+
this.#provider = options.provider;
|
|
73
|
+
this.#model = options.model;
|
|
74
|
+
this.#images = options.images;
|
|
75
|
+
// Capabilities are READ from the model's own descriptor, never hardcoded
|
|
76
|
+
// (HLM-02's capability half): an explicit modality omission is negative
|
|
77
|
+
// capability, an absent descriptor field is the honest `unknown`, and an
|
|
78
|
+
// image-capable model without a transport hook is `unknown` rather than a
|
|
79
|
+
// promise the transport cannot keep.
|
|
80
|
+
const declared = descriptor.inputModalities;
|
|
81
|
+
const images = declared === undefined
|
|
82
|
+
? 'unknown'
|
|
83
|
+
: declared.includes('image')
|
|
84
|
+
? this.#images === undefined ? 'unknown' : 'supported'
|
|
85
|
+
: 'unsupported';
|
|
86
|
+
this.#capabilities = Object.freeze({
|
|
87
|
+
images,
|
|
88
|
+
// The model's own per-request output default; the RES-10 ceiling is the
|
|
89
|
+
// fallback for a descriptor that discloses none.
|
|
90
|
+
maxOutputTokens: descriptor.defaultMaxTokens ?? INITIAL_MAX_OUTPUT_TOKENS,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Resolve the model descriptor and build the provider (HLM-02).
|
|
95
|
+
*
|
|
96
|
+
* The descriptor is resolved ONCE, at creation: capabilities are the model
|
|
97
|
+
* facts as of this generation, not whatever the endpoint happens to report
|
|
98
|
+
* mid-run.
|
|
99
|
+
* @param options - the surface, route, model and transports.
|
|
100
|
+
* @returns the provider.
|
|
101
|
+
* @throws when the descriptor cannot be resolved or names another route.
|
|
102
|
+
*/
|
|
103
|
+
static async create(options) {
|
|
104
|
+
const descriptor = await options.llm.resolveModelInfo(options.provider, options.model);
|
|
105
|
+
if (descriptor.provider !== options.provider || descriptor.id !== options.model) {
|
|
106
|
+
throw new Error(`the DSH surface resolved ${descriptor.provider}/${descriptor.id}, not the requested `
|
|
107
|
+
+ `${options.provider}/${options.model}; capabilities would be read from the wrong model`);
|
|
108
|
+
}
|
|
109
|
+
return new DshLlmProvider(options, descriptor);
|
|
110
|
+
}
|
|
111
|
+
/** The frozen descriptor-derived facts. */
|
|
112
|
+
capabilities() {
|
|
113
|
+
return this.#capabilities;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Perform one isolated call through the DSH stream.
|
|
117
|
+
*
|
|
118
|
+
* The request is one user message — the rendered prompt plus one attachment
|
|
119
|
+
* part per bound image via the transport hook — with no system prompt, no
|
|
120
|
+
* tools and no history, exactly as the broker's isolation invariant requires
|
|
121
|
+
* (HLM-05). Chunks are assembled per block index; the terminal finish maps
|
|
122
|
+
* to the broker's completion vocabulary.
|
|
123
|
+
* @param request - the broker request.
|
|
124
|
+
* @returns the completion.
|
|
125
|
+
*/
|
|
126
|
+
async complete(request) {
|
|
127
|
+
const content = [{ type: 'text', text: request.prompt }];
|
|
128
|
+
if (request.images !== undefined && request.images.length > 0) {
|
|
129
|
+
if (this.#images === undefined) {
|
|
130
|
+
// Unreachable through the broker (capabilities say 'unknown'), but a
|
|
131
|
+
// caller bypassing the preflight must not silently drop the image.
|
|
132
|
+
throw new Error('the DSH provider has no image transport; the image inputs were not sent');
|
|
133
|
+
}
|
|
134
|
+
for (const image of request.images) {
|
|
135
|
+
content.push(await this.#images(image));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const text = new Map();
|
|
139
|
+
let toolName;
|
|
140
|
+
let usage;
|
|
141
|
+
for await (const chunk of this.#llm.stream({
|
|
142
|
+
provider: this.#provider,
|
|
143
|
+
model: this.#model,
|
|
144
|
+
messages: [{ role: 'user', content }],
|
|
145
|
+
maxTokens: request.maxOutputTokens,
|
|
146
|
+
signal: request.signal,
|
|
147
|
+
})) {
|
|
148
|
+
switch (chunk.type) {
|
|
149
|
+
case 'text-delta': {
|
|
150
|
+
text.set(chunk.index, (text.get(chunk.index) ?? '') + chunk.text);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case 'tool-call-delta': {
|
|
154
|
+
toolName = chunk.name ?? toolName;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case 'usage': {
|
|
158
|
+
usage = { known: true, inputTokens: chunk.usage.inputTokens, outputTokens: chunk.usage.outputTokens };
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
case 'finish': {
|
|
162
|
+
const assembled = [...text.entries()].sort((left, right) => left[0] - right[0]).map(([, value]) => value).join('');
|
|
163
|
+
switch (chunk.reason.kind) {
|
|
164
|
+
case 'stop': {
|
|
165
|
+
return { kind: 'text', text: assembled, ...usage === undefined ? {} : { usage } };
|
|
166
|
+
}
|
|
167
|
+
case 'max-tokens': {
|
|
168
|
+
// Generation was cut short: an error, never a short result.
|
|
169
|
+
return { kind: 'truncated', text: assembled };
|
|
170
|
+
}
|
|
171
|
+
case 'tool-calls': {
|
|
172
|
+
// HLM-06: a tool call from a recipe model is never executed.
|
|
173
|
+
return { kind: 'tool_call', toolName: toolName ?? '(unnamed)' };
|
|
174
|
+
}
|
|
175
|
+
case 'aborted':
|
|
176
|
+
case 'error': {
|
|
177
|
+
// The catch-all union member (unknown adapter-specific kinds)
|
|
178
|
+
// keeps TS from narrowing failure onto these literal cases, so
|
|
179
|
+
// the fact is read defensively: the core DSH vocabulary always
|
|
180
|
+
// carries it for aborted/error (types.ts:160-161).
|
|
181
|
+
const failure = chunk.reason.failure;
|
|
182
|
+
const summary = `${failure?.message ?? 'no message'} (${failure?.code ?? 'UNKNOWN'})`;
|
|
183
|
+
throw new Error(`the DSH stream ${chunk.reason.kind === 'aborted' ? 'aborted' : 'failed'} the call: ${summary}`);
|
|
184
|
+
}
|
|
185
|
+
default: {
|
|
186
|
+
throw new Error(`the DSH stream finished with an unknown reason ${JSON.stringify(chunk.reason.kind)}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
default: {
|
|
191
|
+
// block-start, block-end, reasoning-delta: assembly metadata, not content.
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// The stream ended without a finish chunk: a broken transport, not a result.
|
|
197
|
+
throw new Error('the DSH stream ended without a finish chunk');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=dsh-adapter.js.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The deterministic fixture provider for `tool-mode-recipe test` (RCP-08).
|
|
3
|
+
*
|
|
4
|
+
* The test command runs the REAL broker against a SCRIPTED fake provider — the
|
|
5
|
+
* broker's binding, policy, budget and failure vocabulary are exercised
|
|
6
|
+
* end-to-end without any real model, network or installation. Every fixture
|
|
7
|
+
* declares its own expected outcome (kind and failure code), and the provider
|
|
8
|
+
* counts every call against a declared ceiling so a recipe that silently
|
|
9
|
+
* outgrows its budget fails the suite instead of passing quietly.
|
|
10
|
+
*
|
|
11
|
+
* This is a TEST CORPUS: a scripted provider, never a real model. A real
|
|
12
|
+
* inference result is outside this module's claim by construction.
|
|
13
|
+
*
|
|
14
|
+
* @module @try-works/tool-mode-recipes/fixture-provider
|
|
15
|
+
*/
|
|
16
|
+
import type { BrokerErrorCode, BrokerHostPolicy, BrokerRequest, CapabilityState, LlmCompletion, LlmProvider, ProviderCapabilities, ProviderDestination } from './broker.ts';
|
|
17
|
+
import type { RecipeManifest } from './recipe-format.ts';
|
|
18
|
+
import type { RecipeCliIo } from './cli.ts';
|
|
19
|
+
/** The scripted completions the fake provider can play. */
|
|
20
|
+
export type FixtureScript = 'echo' | 'refuse' | 'truncate' | 'tool-call' | 'empty' | 'unused';
|
|
21
|
+
/** One expected outcome in a fixture case. */
|
|
22
|
+
export interface FixtureExpectation {
|
|
23
|
+
readonly kind: 'completed' | 'failed' | 'cancelled';
|
|
24
|
+
/** Required for a failed expectation: the exact code the broker must report. */
|
|
25
|
+
readonly code?: BrokerErrorCode;
|
|
26
|
+
}
|
|
27
|
+
/** One fixture case. */
|
|
28
|
+
export interface FixtureCase {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly args: unknown;
|
|
31
|
+
readonly script: FixtureScript;
|
|
32
|
+
readonly expect: FixtureExpectation;
|
|
33
|
+
}
|
|
34
|
+
/** The fixture document's provider stanza. */
|
|
35
|
+
export interface FixtureProvider {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly destination: ProviderDestination;
|
|
38
|
+
readonly images: CapabilityState;
|
|
39
|
+
readonly maxCalls: number;
|
|
40
|
+
}
|
|
41
|
+
/** The fixture document. */
|
|
42
|
+
export interface FixtureDocument {
|
|
43
|
+
readonly provider: FixtureProvider;
|
|
44
|
+
readonly cases: readonly FixtureCase[];
|
|
45
|
+
}
|
|
46
|
+
/** Validate a decoded fixture document; a malformed fixture is a refusal. */
|
|
47
|
+
export declare function validateFixtureDocument(raw: unknown): {
|
|
48
|
+
document?: FixtureDocument;
|
|
49
|
+
error?: string;
|
|
50
|
+
};
|
|
51
|
+
/** Raised when the scripted provider's call ceiling is exceeded. */
|
|
52
|
+
export declare class FixtureCeilingExceededError extends Error {
|
|
53
|
+
readonly name = "FixtureCeilingExceededError";
|
|
54
|
+
}
|
|
55
|
+
/** A scripted fake provider: deterministic, counting, never a real model. */
|
|
56
|
+
export declare class ScriptedFixtureProvider implements LlmProvider {
|
|
57
|
+
#private;
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly generation = 1;
|
|
60
|
+
readonly destination: ProviderDestination;
|
|
61
|
+
constructor(stanza: FixtureProvider);
|
|
62
|
+
/** The number of provider calls made so far (the create-command guard reads this). */
|
|
63
|
+
get callCount(): number;
|
|
64
|
+
get maxCalls(): number;
|
|
65
|
+
/** Direct the next completion. */
|
|
66
|
+
direct(script: FixtureScript): void;
|
|
67
|
+
capabilities(): ProviderCapabilities;
|
|
68
|
+
complete(request: BrokerRequest): Promise<LlmCompletion>;
|
|
69
|
+
}
|
|
70
|
+
/** One case's verdict. */
|
|
71
|
+
export interface FixtureVerdict {
|
|
72
|
+
readonly caseId: string;
|
|
73
|
+
readonly pass: boolean;
|
|
74
|
+
readonly detail: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Run one recipe against a fixture document through the REAL broker.
|
|
78
|
+
* @param recipe - the recipe under test.
|
|
79
|
+
* @param fixture - the validated fixture document.
|
|
80
|
+
* @param io - the output sinks.
|
|
81
|
+
* @param policy - the broker policy to run under (defaults to the initial policy with recording).
|
|
82
|
+
* @returns the per-case verdicts, in fixture order.
|
|
83
|
+
*/
|
|
84
|
+
export declare function runFixtureSuite(recipe: RecipeManifest, fixture: FixtureDocument, io: RecipeCliIo, policy: BrokerHostPolicy): Promise<readonly FixtureVerdict[]>;
|
|
85
|
+
//# sourceMappingURL=fixture-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-provider.d.ts","sourceRoot":"","sources":["../src/fixture-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAEhB,aAAa,EACb,eAAe,EACf,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,cAAc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