@dsh-cc/tools 0.5.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.
Files changed (121) hide show
  1. package/LICENSE +201 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +209 -0
  4. package/README.zh.md +200 -0
  5. package/lib/abort-utils.d.ts +80 -0
  6. package/lib/abort-utils.d.ts.map +1 -0
  7. package/lib/abort-utils.js +186 -0
  8. package/lib/abort-utils.js.map +1 -0
  9. package/lib/cc-names.d.ts +100 -0
  10. package/lib/cc-names.d.ts.map +1 -0
  11. package/lib/cc-names.js +197 -0
  12. package/lib/cc-names.js.map +1 -0
  13. package/lib/code-mode.d.ts +46 -0
  14. package/lib/code-mode.d.ts.map +1 -0
  15. package/lib/code-mode.js +380 -0
  16. package/lib/code-mode.js.map +1 -0
  17. package/lib/define-tool.d.ts +103 -0
  18. package/lib/define-tool.d.ts.map +1 -0
  19. package/lib/define-tool.js +354 -0
  20. package/lib/define-tool.js.map +1 -0
  21. package/lib/index.d.ts +348 -0
  22. package/lib/index.d.ts.map +1 -0
  23. package/lib/index.js +289 -0
  24. package/lib/index.js.map +1 -0
  25. package/lib/invariant.d.ts +13 -0
  26. package/lib/invariant.d.ts.map +1 -0
  27. package/lib/invariant.js +123 -0
  28. package/lib/invariant.js.map +1 -0
  29. package/lib/json-render.d.ts +18 -0
  30. package/lib/json-render.d.ts.map +1 -0
  31. package/lib/json-render.js +111 -0
  32. package/lib/json-render.js.map +1 -0
  33. package/lib/json-schema-value.d.ts +18 -0
  34. package/lib/json-schema-value.d.ts.map +1 -0
  35. package/lib/json-schema-value.js +238 -0
  36. package/lib/json-schema-value.js.map +1 -0
  37. package/lib/json-schema.d.ts +101 -0
  38. package/lib/json-schema.d.ts.map +1 -0
  39. package/lib/json-schema.js +351 -0
  40. package/lib/json-schema.js.map +1 -0
  41. package/lib/presentation.d.ts +367 -0
  42. package/lib/presentation.d.ts.map +1 -0
  43. package/lib/presentation.js +8 -0
  44. package/lib/presentation.js.map +1 -0
  45. package/lib/py-names.d.ts +163 -0
  46. package/lib/py-names.d.ts.map +1 -0
  47. package/lib/py-names.js +236 -0
  48. package/lib/py-names.js.map +1 -0
  49. package/lib/py-render.d.ts +23 -0
  50. package/lib/py-render.d.ts.map +1 -0
  51. package/lib/py-render.js +434 -0
  52. package/lib/py-render.js.map +1 -0
  53. package/lib/py-sdk-doc.d.ts +29 -0
  54. package/lib/py-sdk-doc.d.ts.map +1 -0
  55. package/lib/py-sdk-doc.js +114 -0
  56. package/lib/py-sdk-doc.js.map +1 -0
  57. package/lib/py-types.d.ts +34 -0
  58. package/lib/py-types.d.ts.map +1 -0
  59. package/lib/py-types.js +40 -0
  60. package/lib/py-types.js.map +1 -0
  61. package/lib/run-code-defs.d.ts +77 -0
  62. package/lib/run-code-defs.d.ts.map +1 -0
  63. package/lib/run-code-defs.js +98 -0
  64. package/lib/run-code-defs.js.map +1 -0
  65. package/lib/runtime-code.d.ts +65 -0
  66. package/lib/runtime-code.d.ts.map +1 -0
  67. package/lib/runtime-code.js +129 -0
  68. package/lib/runtime-code.js.map +1 -0
  69. package/lib/runtime-core.d.ts +130 -0
  70. package/lib/runtime-core.d.ts.map +1 -0
  71. package/lib/runtime-core.js +33 -0
  72. package/lib/runtime-core.js.map +1 -0
  73. package/lib/runtime-execute.d.ts +82 -0
  74. package/lib/runtime-execute.d.ts.map +1 -0
  75. package/lib/runtime-execute.js +333 -0
  76. package/lib/runtime-execute.js.map +1 -0
  77. package/lib/runtime-registry.d.ts +131 -0
  78. package/lib/runtime-registry.d.ts.map +1 -0
  79. package/lib/runtime-registry.js +269 -0
  80. package/lib/runtime-registry.js.map +1 -0
  81. package/lib/runtime-results.d.ts +32 -0
  82. package/lib/runtime-results.d.ts.map +1 -0
  83. package/lib/runtime-results.js +163 -0
  84. package/lib/runtime-results.js.map +1 -0
  85. package/lib/runtime-schemas.d.ts +112 -0
  86. package/lib/runtime-schemas.d.ts.map +1 -0
  87. package/lib/runtime-schemas.js +222 -0
  88. package/lib/runtime-schemas.js.map +1 -0
  89. package/lib/scheduler.d.ts +22 -0
  90. package/lib/scheduler.d.ts.map +1 -0
  91. package/lib/scheduler.js +21 -0
  92. package/lib/scheduler.js.map +1 -0
  93. package/lib/schema-spec.d.ts +154 -0
  94. package/lib/schema-spec.d.ts.map +1 -0
  95. package/lib/schema-spec.js +9 -0
  96. package/lib/schema-spec.js.map +1 -0
  97. package/lib/schema.d.ts +5 -0
  98. package/lib/schema.d.ts.map +1 -0
  99. package/lib/schema.js +3 -0
  100. package/lib/schema.js.map +1 -0
  101. package/lib/testing.d.ts +25 -0
  102. package/lib/testing.d.ts.map +1 -0
  103. package/lib/testing.js +25 -0
  104. package/lib/testing.js.map +1 -0
  105. package/lib/tool-layer.d.ts +49 -0
  106. package/lib/tool-layer.d.ts.map +1 -0
  107. package/lib/tool-layer.js +57 -0
  108. package/lib/tool-layer.js.map +1 -0
  109. package/lib/tool-types.d.ts +385 -0
  110. package/lib/tool-types.d.ts.map +1 -0
  111. package/lib/tool-types.js +11 -0
  112. package/lib/tool-types.js.map +1 -0
  113. package/lib/ts-types.d.ts +37 -0
  114. package/lib/ts-types.d.ts.map +1 -0
  115. package/lib/ts-types.js +265 -0
  116. package/lib/ts-types.js.map +1 -0
  117. package/lib/types.d.ts +55 -0
  118. package/lib/types.d.ts.map +1 -0
  119. package/lib/types.js +7 -0
  120. package/lib/types.js.map +1 -0
  121. package/package.json +65 -0
@@ -0,0 +1,57 @@
1
+ /**
2
+ * One scope's tool-registry contribution: visibility, reservations,
3
+ * restrictions, guards, and per-scope presentation shadowing.
4
+ * @module tool-layer
5
+ */
6
+ import { AnonymousEntries, NamedEntries } from '@deepseek-ai/dsh-scope';
7
+ /** One scope's complete tool-registry contribution. */
8
+ export class ToolLayer {
9
+ tools;
10
+ /** Known-but-invisible capability names, so a scoped restriction can gate a tool before it loads. */
11
+ reserved = new NamedEntries(name => new Error(`tool name "${name}" is already reserved in this scope`));
12
+ restrictions = new AnonymousEntries();
13
+ guards = new AnonymousEntries();
14
+ /**
15
+ * Presentation this scope's agent declared for itself, shadowing the
16
+ * deployment default. One cell rather than an entry table: two answers to
17
+ * "which form does the model see" is a contradiction, not a merge.
18
+ */
19
+ mode;
20
+ constructor(scope) {
21
+ this.tools = new NamedEntries(name => new Error(scope === undefined
22
+ ? `tool "${name}" is already registered (for a per-agent variant, register through that agent's \`agent.ctx\` instead)`
23
+ : `tool "${name}" is already registered in this scope`));
24
+ }
25
+ /** Whether every contribution table in this aggregate layer is empty. */
26
+ isEmpty() {
27
+ return this.tools.isEmpty() && this.reserved.isEmpty() && this.restrictions.isEmpty()
28
+ && this.guards.isEmpty() && this.mode === undefined;
29
+ }
30
+ /** Whether every compiled restriction in this layer admits a global tool name. */
31
+ admits(name) {
32
+ for (const filter of this.restrictions.values()) {
33
+ if ((filter.allow !== undefined && !filter.allow.has(name))
34
+ || (filter.deny !== undefined && filter.deny.has(name)))
35
+ return false;
36
+ }
37
+ return true;
38
+ }
39
+ /** First monotonic denial from this layer's live guard registrations. */
40
+ guardReason(exec) {
41
+ for (const guard of this.guards.values()) {
42
+ const reason = guard(exec);
43
+ if (reason !== undefined)
44
+ return reason;
45
+ }
46
+ return undefined;
47
+ }
48
+ }
49
+ /** Resolve the run_code overlap cap at the owning config boundary (direct construction bypasses the Loader schema). */
50
+ export function resolveMaxParallelSubCalls(value) {
51
+ const maxParallelSubCalls = value ?? 10;
52
+ if (!Number.isInteger(maxParallelSubCalls) || maxParallelSubCalls < 1) {
53
+ throw new Error('maxParallelSubCalls must be a positive integer');
54
+ }
55
+ return maxParallelSubCalls;
56
+ }
57
+ //# sourceMappingURL=tool-layer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-layer.js","sourceRoot":"","sources":["../src/tool-layer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAIvE,uDAA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IAAmB;QAC7B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;YAC1B,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,MAAM,CAAA;QACzC,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AAoBD,uHAAuH;AACvH,MAAM,UAAU,0BAA0B,CAAC,KAAyB;IAClE,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE,CAAA;IACvC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,GAAG,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAA;IACnE,CAAC;IACD,OAAO,mBAAmB,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,385 @@
1
+ /**
2
+ * Public tool type vocabulary: definitions, results, execution contexts,
3
+ * scheduler contracts, restriction/config shapes, and value projection
4
+ * helpers shared by the registry and its pipeline.
5
+ * @module tool-types
6
+ */
7
+ import type { Agent } from '@deepseek-ai/dsh-agent';
8
+ import type { CallId, ContentBlock, ToolSchema } from '@deepseek-ai/dsh-llm';
9
+ import type { JsonValue, UserMessage } from '@deepseek-ai/dsh-session';
10
+ import type { ToolCallView, ToolResultView } from './presentation.ts';
11
+ import type { ToolFailure } from './abort-utils.ts';
12
+ import type { JsonSchemaNode } from './json-schema.ts';
13
+ /** Tool-owned canonical output contract used after the body returns a JSON value. */
14
+ export interface ToolOutputDefinition {
15
+ /** Raw supported JSON Schema enforced against every successful canonical value. */
16
+ readonly schema: JsonSchemaNode;
17
+ /** Pure projection from validated arguments and value to Native/model content. */
18
+ render(args: unknown, value: JsonValue): ContentBlock[];
19
+ /** Pure replayable presentation projection, computed only for top-level calls. */
20
+ presentationMeta?(args: unknown, value: JsonValue): JsonValue;
21
+ }
22
+ /** A registered tool: its schema plus the execution function. */
23
+ export interface ToolDefinition extends ToolSchema {
24
+ /** Mandatory canonical output declaration. */
25
+ readonly output: ToolOutputDefinition;
26
+ /**
27
+ * Run one accepted call and return only its canonical lossless-JSON value.
28
+ * Async work must observe or forward `exec.signal` and settle only after its
29
+ * owned work reaches quiescence. The registry preserves caller cancellation
30
+ * through around-dispatch signal replacement and does not abandon this
31
+ * promise, but it cannot hard-kill same-process code.
32
+ * @param args - losslessly snapshotted, frozen model arguments.
33
+ * @param exec - execution identity, cancellation signal, and context deferral.
34
+ * @returns the canonical value declared by `output.schema`.
35
+ */
36
+ execute(args: unknown, exec: ToolRunContext): Promise<unknown>;
37
+ /**
38
+ * Synchronous last-mile transform for model-facing content. The registry
39
+ * snapshots this callback when execution starts and invokes it exactly once
40
+ * for every normalized outcome, including pipeline failures that bypass
41
+ * `tools/post-execute`, immediately before lossless materialization.
42
+ * Returning `undefined` preserves the content; every other result field
43
+ * remains registry-owned. The callback must be total and must not throw.
44
+ * @param exec - immutable execution identity and arguments.
45
+ * @param result - complete normalized outcome before materialization.
46
+ * @returns replacement content, or `undefined` to preserve it.
47
+ */
48
+ finalizeContent?(exec: Readonly<ToolExecution>, result: Readonly<ToolExecutionResult>): ContentBlock[] | undefined;
49
+ /**
50
+ * Cooperative tool-call timeout budget in milliseconds. Omit for no deadline.
51
+ * Enforced by `@deepseek-ai/dsh-tool-call-timeout-policy` (a `tools/execute` wrapper); it
52
+ * is NEVER sent to the model — `schemas()` whitelists only name/description/
53
+ * parameters. Declaring it asserts this tool forwards `exec.signal` to a
54
+ * cooperative implementation that can reach quiescence when the signal aborts.
55
+ */
56
+ timeoutMs?: number;
57
+ /**
58
+ * Pure synchronous classifier for overlap with sibling tool calls. Only
59
+ * `true` opts in; omission, exceptions, non-`true` returns, and invalid
60
+ * `defineTool` arguments are exclusive. This metadata is never model-visible.
61
+ *
62
+ * Opted-in executions must not mutate parent-owned state. Shared state must
63
+ * tolerate concurrent dispatch; recorder races are permitted only when they
64
+ * commute or fail closed. See the
65
+ * [parallel-tool-call Agent Note](../../../../.agents/notes/implemented/feature/2026-07-10-parallel-tool-call-execution.md)
66
+ * for the full contract.
67
+ * @param args - parsed arguments; `defineTool` validates before calling.
68
+ * @returns Whether this call may join a parallel group.
69
+ */
70
+ isConcurrencySafe?(args: unknown): boolean;
71
+ /**
72
+ * Optional: how to present the PENDING state of one call in a UI, derived from
73
+ * the call's `args` (parsed arguments, `unknown` — the tool validates/narrows
74
+ * its own input). Returns a {@link ToolCallView} (a `card`-tagged render intent),
75
+ * or `undefined` (or omit the method) to fall back to a generic presentation
76
+ * (title = tool name, raw args as input). Pure and side-effect-free: a UI may
77
+ * call it during live streaming AND a session-log replay, so it must depend
78
+ * only on `args`.
79
+ */
80
+ presentCall?(args: unknown): ToolCallView | undefined;
81
+ /**
82
+ * Optional: how to present the COMPLETED state, given the same `args` and the
83
+ * durable result projection (`content`, failure state, and optional `meta`). Returns a
84
+ * {@link ToolResultView}, or `undefined` (or omit the method) to keep the
85
+ * pending title and render the raw result content. Pure and side-effect-free
86
+ * for the same replay reason.
87
+ */
88
+ presentResult?(args: unknown, result: ToolResult): ToolResultView | undefined;
89
+ }
90
+ /** The completed outcome handed to {@link ToolDefinition.presentResult}. */
91
+ export interface ToolResult {
92
+ /** The final model-facing content (or the rendered error text on failure). */
93
+ content: ContentBlock[];
94
+ /** Whether the call failed. */
95
+ isError: boolean;
96
+ /**
97
+ * The tool-private presentation payload projected by its output declaration
98
+ * and threaded verbatim from the `tool/result` event. Absent when the tool
99
+ * declared no projector or the call was nested under a composite transport.
100
+ */
101
+ meta?: JsonValue;
102
+ }
103
+ declare const toolExecutionTokenBrand: unique symbol;
104
+ /** Opaque call identity that permits correlation without exposing mutable execution state. */
105
+ export type ToolExecutionToken = symbol & {
106
+ readonly [toolExecutionTokenBrand]: true;
107
+ };
108
+ /**
109
+ * Caller-supplied description of one tool call. {@link ToolRuntime.execute}
110
+ * adds the registry-owned token to form a pipeline {@link ToolExecution};
111
+ * callers do not choose that token.
112
+ */
113
+ export interface ToolExecutionInput {
114
+ readonly callId: CallId;
115
+ /**
116
+ * Root model-requested call owning this execution tree. Callers omit it for
117
+ * a root execution; nested dispatchers propagate the enclosing value.
118
+ */
119
+ readonly rootCallId?: CallId;
120
+ readonly name: string;
121
+ /** Losslessly JSON-serializable parsed arguments (tools validate their own schema). */
122
+ readonly arguments: unknown;
123
+ /** The agent on whose behalf the call runs (set by the agent loop). */
124
+ readonly agent?: Agent;
125
+ /**
126
+ * Opaque token of the enclosing transport execution, when one exists. Code
127
+ * Mode sets this on SDK sub-dispatches so commit-style observers can wait for
128
+ * the outer `run_code` outcome without receiving its live mutable execution.
129
+ * The token also marks the call as a transport sub-dispatch rather than a
130
+ * model-direct call: under `mode: 'code'`, only calls WITH a parent may
131
+ * execute a native tool name — a model-direct call (no parent) is denied as
132
+ * `UNKNOWN_TOOL` before the policy pipeline. See {@link ToolRuntime.execute}.
133
+ */
134
+ readonly parent?: ToolExecutionToken;
135
+ /** Required caller-owned cancellation for this invocation. */
136
+ readonly signal: AbortSignal;
137
+ }
138
+ /**
139
+ * Scheduling mode for one pending call. `parallel` may overlap with siblings;
140
+ * `exclusive` runs alone and forms an ordering barrier.
141
+ */
142
+ export type ToolExecutionMode = {
143
+ kind: 'parallel';
144
+ } | {
145
+ kind: 'exclusive';
146
+ };
147
+ /**
148
+ * One settled `run_code` sub-dispatch about to be logged, as seen by the
149
+ * `tools/code-dispatch-log` waterfall: the parent execution (session owner,
150
+ * outer call identity), the sub-call identity, and the outcome whose durable
151
+ * copy a listener may reshape. `content` is the RENDERED result projection
152
+ * (what a native `tool/result` would carry) — the program itself received
153
+ * the structured `value` (or just the error message on failure); only the
154
+ * `tool/code-dispatch` event's copy changes.
155
+ */
156
+ export interface CodeDispatchLog {
157
+ /** The outer `run_code` execution. */
158
+ readonly exec: ToolExecution;
159
+ /** The calling agent (the scope routing key and the spill owner), when the outer call has one. */
160
+ readonly agent?: Agent;
161
+ /** Deterministic sub-call id (`<parent>:code:<n>`). */
162
+ readonly subCallId: CallId;
163
+ /** The dispatched sub-tool name. */
164
+ readonly name: string;
165
+ /** Whether the sub-call settled as an error. */
166
+ readonly isError: boolean;
167
+ /** The sub-call's complete model-facing content (the settle event's default payload). */
168
+ readonly content: ContentBlock[];
169
+ }
170
+ /**
171
+ * One pending tool call inside the registry pipeline. Parsed arguments cross
172
+ * one lossless-JSON materialization boundary before policy and are deep-frozen;
173
+ * call identity, the caller signal, and the registry-assigned {@link token} are
174
+ * readonly. The registry freezes the complete object before `tools/result`
175
+ * observers run.
176
+ */
177
+ export interface ToolExecution extends ToolExecutionInput {
178
+ /** Root model-requested call, resolved for every root and nested execution. */
179
+ readonly rootCallId: CallId;
180
+ /** Registry-assigned identity shared with nested calls only as their opaque `parent` token. */
181
+ readonly token: ToolExecutionToken;
182
+ }
183
+ /**
184
+ * Around-dispatch view of a {@link ToolExecution}. A `tools/execute` wrapper
185
+ * may replace the signal for its delegated lifetime, but it cannot remove it.
186
+ * The registry fuses every replacement with the captured caller signal.
187
+ */
188
+ export interface ToolDispatchExecution extends Omit<ToolExecution, 'signal'> {
189
+ /** Cancellation signal visible to the next wrapper or tool body. */
190
+ signal: AbortSignal;
191
+ }
192
+ /**
193
+ * Runtime context handed to a tool implementation after the registry has
194
+ * accepted a {@link ToolExecution}. {@link deferContext} attaches context to
195
+ * this execution's own result — a composite tool ferries nested-dispatch
196
+ * context back to the outer result, and a leaf tool may mint a fresh
197
+ * plugin-sourced instruction; the loop appends it only after the
198
+ * `tool/result`.
199
+ */
200
+ export interface ToolRunContext extends ToolExecution {
201
+ /**
202
+ * Defer one context — typically a nested-dispatch context ferried by a
203
+ * composite tool, or a fresh plugin-sourced instruction — until this tool's
204
+ * final result reaches the agent loop. Contexts retain their individual
205
+ * source and metadata and are emitted in call order.
206
+ */
207
+ deferContext(context: UserMessage): void;
208
+ /**
209
+ * Mark a successful final result as terminal for the current agent turn.
210
+ * The marker rides this execution's own result (`concludesTurn` exists only
211
+ * on {@link ToolExecutionSuccess}); a composite that dispatches nested
212
+ * calls forwards it from the nested result, exactly like
213
+ * `additionalContexts`, so only an authoritative nested success can
214
+ * conclude the enclosing run.
215
+ */
216
+ concludeTurn(): void;
217
+ }
218
+ /** Registry-owned live execution object; public pipeline views stay readonly. */
219
+ export type MutableToolRunContext = Omit<ToolRunContext, 'signal'> & {
220
+ signal: AbortSignal;
221
+ };
222
+ /**
223
+ * Scheduler-only result after ordered pre-execute and guards. A `post-result`
224
+ * still receives post-execute; a `final-result` bypasses it.
225
+ * @internal
226
+ */
227
+ export type ScheduledToolPreparation = {
228
+ kind: 'dispatch';
229
+ exec: ToolRunContext;
230
+ } | {
231
+ kind: 'post-result';
232
+ exec: ToolRunContext;
233
+ result: ToolExecutionResult;
234
+ } | {
235
+ kind: 'final-result';
236
+ exec: ToolRunContext;
237
+ result: ToolExecutionResult;
238
+ };
239
+ /**
240
+ * Scheduler-only dispatch result. A `post-result` still receives post-execute;
241
+ * a `final-result` already matches {@link ToolRuntime.execute} failure semantics.
242
+ * @internal
243
+ */
244
+ export type ScheduledToolDispatch = {
245
+ kind: 'post-result';
246
+ result: ToolExecutionResult;
247
+ } | {
248
+ kind: 'final-result';
249
+ result: ToolExecutionResult;
250
+ };
251
+ /**
252
+ * Symbol-keyed scheduler view that keeps pre/post policy ordered while
253
+ * overlapping dispatch. Ordinary callers use {@link ToolRuntime.execute};
254
+ * this is not a plugin extension point.
255
+ * @internal
256
+ */
257
+ export interface ToolRuntimeScheduler {
258
+ /** Materialize input, run the ordered pre-execute/guard gate, and decide what stage follows. */
259
+ prepare(exec: ToolExecutionInput): Promise<ScheduledToolPreparation>;
260
+ /** Run only the around-dispatch/body stage. */
261
+ dispatch(exec: ToolRunContext): Promise<ScheduledToolDispatch>;
262
+ /** Run post-execute and definition-owned content finalization, then materialize and notify. */
263
+ finalize(exec: ToolRunContext, result: ToolExecutionResult): Promise<ToolExecutionResult>;
264
+ /** Run definition-owned content finalization, then materialize and notify without post-execute. */
265
+ finish(exec: ToolRunContext, result: ToolExecutionResult): ToolExecutionResult;
266
+ }
267
+ /** Successful canonical tool execution, including its Native/model projection. */
268
+ export interface ToolExecutionSuccess {
269
+ readonly isError: false;
270
+ /** Execution-local canonical value; deliberately omitted from durable events. */
271
+ readonly value: JsonValue;
272
+ readonly content: ContentBlock[];
273
+ readonly error?: never;
274
+ readonly meta?: JsonValue;
275
+ readonly additionalContexts?: UserMessage[];
276
+ /** The agent loop stops after committing this successful result batch. */
277
+ readonly concludesTurn?: true;
278
+ }
279
+ /** Failed canonical tool execution; failures never carry a successful value. */
280
+ export interface ToolExecutionFailure {
281
+ readonly isError: true;
282
+ readonly error: ToolFailure;
283
+ readonly value?: never;
284
+ readonly content: ContentBlock[];
285
+ readonly meta?: JsonValue;
286
+ readonly additionalContexts?: UserMessage[];
287
+ readonly concludesTurn?: never;
288
+ }
289
+ /** The discriminated, execution-local outcome of one tool call. */
290
+ export type ToolExecutionResult = ToolExecutionSuccess | ToolExecutionFailure;
291
+ /**
292
+ * Pre-dispatch decision. `allow` runs the call; `deny` materializes an error;
293
+ * `ask` runs only after an approval service returns `allowed-once` and otherwise
294
+ * denies. Input rewriting is excluded because arguments are already logged and
295
+ * presented.
296
+ */
297
+ export type PreToolDecision = {
298
+ kind: 'allow';
299
+ } | {
300
+ kind: 'deny';
301
+ reason: string;
302
+ } | {
303
+ kind: 'ask';
304
+ reason?: string;
305
+ };
306
+ /**
307
+ * Post-dispatch decision: accept, replace one projection, attach context for the
308
+ * next request, or block by turning corrective feedback into an error result.
309
+ */
310
+ export type PostToolDecision = {
311
+ kind: 'accept';
312
+ content?: ContentBlock[];
313
+ value?: never;
314
+ additionalContexts?: UserMessage[];
315
+ } | {
316
+ kind: 'accept';
317
+ value: JsonValue;
318
+ content?: never;
319
+ additionalContexts?: UserMessage[];
320
+ } | {
321
+ kind: 'block';
322
+ feedback: ContentBlock[];
323
+ additionalContexts?: UserMessage[];
324
+ };
325
+ /** Snapshot and freeze one durable tool-result projection or reject lossy data. */
326
+ export declare function materializePresentation<T>(candidate: T): T;
327
+ /** How the registry presents its tools to the model (see {@link Config.mode}). */
328
+ export type ToolPresentationMode = 'native' | 'code' | 'both';
329
+ /** Plugin config: how the registered tools are presented to the model. */
330
+ export interface Config {
331
+ /**
332
+ * Model presentation. `native` (default) sends every visible schema; `code`
333
+ * sends only `run_code` plus a generated SDK prompt and collapses the
334
+ * executor to the same surface (a model-direct call may only name
335
+ * `run_code`; `run_code` SDK sub-dispatches keep every visible tool); `both`
336
+ * sends both forms. Code modes require a `ctx.codeRuntime` whose `language`
337
+ * has a registered SDK renderer (TypeScript or Python) and fail prompt
338
+ * assembly when it is absent or has no renderer. Under `code`, native names
339
+ * in `toolOrder` are invalid.
340
+ */
341
+ mode?: ToolPresentationMode;
342
+ /**
343
+ * Concurrency cap for a `run_code` program's overlapping sub-calls
344
+ * (default 10, the loop scheduler's own default). Sub-calls follow the
345
+ * native scheduling contract — only calls whose tools classify
346
+ * concurrency-safe overlap; exclusive calls form barriers — so `1`
347
+ * restores strictly serial dispatch. Must be a positive integer.
348
+ */
349
+ maxParallelSubCalls?: number;
350
+ }
351
+ /**
352
+ * Per-scope filter over global tools. Restrictions intersect and do not affect
353
+ * scoped registrations or the reserved Code Mode transport.
354
+ */
355
+ export interface ToolRestriction {
356
+ /** Global tool names that stay visible; everything else is removed. */
357
+ readonly allow?: readonly string[];
358
+ /** Global tool names removed from visibility. */
359
+ readonly deny?: readonly string[];
360
+ }
361
+ /** One restriction compiled at registration for repeated live-global lookup. */
362
+ export interface CompiledToolRestriction {
363
+ readonly allow?: ReadonlySet<string>;
364
+ readonly deny?: ReadonlySet<string>;
365
+ }
366
+ /** One scope's complete registry view, derived in a single layer traversal. */
367
+ export interface ToolView {
368
+ /** Visible definitions after restrictions, scoped shadowing, and transport insertion. */
369
+ readonly visible: ReadonlyMap<string, ToolDefinition>;
370
+ /** Pre-restriction capability names used by prompt-order validation. */
371
+ readonly knownNames: ReadonlySet<string>;
372
+ /** Current global names that a scoped restriction may name. */
373
+ readonly restrictableNames: ReadonlySet<string>;
374
+ }
375
+ /**
376
+ * A monotonic execution guard evaluated after every `tools/pre-execute`
377
+ * listener and before the tool body. Returning a reason denies the call;
378
+ * returning `undefined` leaves it unchanged. Because guards have no allow
379
+ * result, listener ordering cannot turn a denial back into permission.
380
+ * @param execution - the identity-protected call after extensible pre-execute policy completed.
381
+ * @returns a final denial reason, or `undefined` to leave the call allowed.
382
+ */
383
+ export type ToolGuard = (execution: Readonly<ToolExecution>) => string | undefined;
384
+ export {};
385
+ //# sourceMappingURL=tool-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-types.d.ts","sourceRoot":"","sources":["../src/tool-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,qFAAqF;AACrF,MAAM,WAAW,oBAAoB;IACnC,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;IAC/B,kFAAkF;IAClF,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,YAAY,EAAE,CAAA;IACvD,kFAAkF;IAClF,gBAAgB,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,SAAS,CAAA;CAC9D;AAED,iEAAiE;AACjE,MAAM,WAAW,cAAe,SAAQ,UAAU;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Q,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IACxC,+DAA+D;IAC/D,QAAQ,CAAC,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAChD;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC,KAAK,MAAM,GAAG,SAAS,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { deepFreeze } from '@deepseek-ai/dsh-llm';
2
+ import { snapshotJsonValue } from '@deepseek-ai/dsh-session';
3
+ /** Snapshot and freeze one durable tool-result projection or reject lossy data. */
4
+ export function materializePresentation(candidate) {
5
+ const detached = snapshotJsonValue(candidate);
6
+ if (detached === undefined) {
7
+ throw new TypeError('tool result must be losslessly JSON-serializable');
8
+ }
9
+ return deepFreeze(detached);
10
+ }
11
+ //# sourceMappingURL=tool-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-types.js","sourceRoot":"","sources":["../src/tool-types.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AA+S5D,mFAAmF;AACnF,MAAM,UAAU,uBAAuB,CAAI,SAAY;IACrD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAA;IAC7C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,SAAS,CAAC,kDAAkD,CAAC,CAAA;IACzE,CAAC;IACD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Code Mode codegen: the pure projection from registered tool schemas to the TypeScript SDK
3
+ * text the model programs against (the `tools:sdk` prompt section). Sibling of
4
+ * `json-schema.ts` — `schemas()` (native function calling) and this module (the generated
5
+ * `declare const tools` API) are two projections of the same store.
6
+ * @module @dsh-cc/tools/src/ts-types
7
+ */
8
+ import type { ToolSchema } from '@deepseek-ai/dsh-llm';
9
+ import type { JsonSchemaNode } from './json-schema.ts';
10
+ /** Internal Code Mode projection: the model-facing schema plus the canonical output schema. */
11
+ export interface ToolSdkSchema extends ToolSchema {
12
+ /** Validated canonical value returned by the tool binding. */
13
+ output: JsonSchemaNode;
14
+ }
15
+ /**
16
+ * Map one enforced JSON-Schema node to a TypeScript type literal. Supports
17
+ * every unified schema construct and returns `unknown` for malformed or
18
+ * unsupported inputs without throwing.
19
+ * @param schema - the JSON-Schema node (any shape; hostile inputs degrade).
20
+ * @param indent - the indentation level for nested object members.
21
+ * @returns the TS type text (multi-line for objects with properties).
22
+ */
23
+ export declare function jsonSchemaToTs(schema: unknown, indent?: number): string;
24
+ /**
25
+ * Render the full `tools:sdk` prompt section: the fixed usage instructions
26
+ * plus one `declare const tools` interface covering every given tool.
27
+ * Deterministic — tools are emitted in lexicographic name order, so an
28
+ * unchanged tool set produces byte-identical text across assemblies. The sort
29
+ * is not a total order on byte-equal names, so two schemas sharing a name
30
+ * would render in argument order; the caller's visible-capability map is keyed
31
+ * by name, so the input never carries a duplicate.
32
+ * @param schemas - the tool schemas to declare (the caller excludes
33
+ * `run_code` itself).
34
+ * @returns the complete section text.
35
+ */
36
+ export declare function renderToolsSdk(schemas: ToolSdkSchema[]): string;
37
+ //# sourceMappingURL=ts-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-types.d.ts","sourceRoot":"","sources":["../src/ts-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,kBAAkB,CAAA;AACxE,+FAA+F;AAC/F,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,8DAA8D;IAC9D,MAAM,EAAE,cAAc,CAAA;CACvB;AAwND;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,SAAI,GAAG,MAAM,CAOlE;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,CAoB/D"}