@linnlabs/linnkit 0.41.0 → 0.43.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 (78) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/cli.cjs +17 -202
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +17 -202
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager.cjs +0 -1
  7. package/dist/context-manager.cjs.map +1 -1
  8. package/dist/context-manager.js +0 -1
  9. package/dist/context-manager.js.map +1 -1
  10. package/dist/contracts/agentSpec.d.cts +5 -5
  11. package/dist/contracts/agentSpec.d.ts +5 -5
  12. package/dist/contracts/audit.d.cts +10 -10
  13. package/dist/contracts/audit.d.ts +10 -10
  14. package/dist/contracts/contextPolicy.d.cts +14 -14
  15. package/dist/contracts/contextPolicy.d.ts +14 -14
  16. package/dist/contracts/events.d.cts +117 -117
  17. package/dist/contracts/events.d.ts +117 -117
  18. package/dist/contracts/execution.d.cts +2 -2
  19. package/dist/contracts/execution.d.ts +2 -2
  20. package/dist/contracts/llm-retry.d.cts +2 -2
  21. package/dist/contracts/llm-retry.d.ts +2 -2
  22. package/dist/contracts/messages.d.cts +32 -32
  23. package/dist/contracts/messages.d.ts +32 -32
  24. package/dist/contracts/sse.d.cts +97 -97
  25. package/dist/contracts/sse.d.ts +97 -97
  26. package/dist/contracts/sub-run-trace-payload.d.cts +8 -8
  27. package/dist/contracts/sub-run-trace-payload.d.ts +8 -8
  28. package/dist/contracts/token-accounting.d.cts +12 -12
  29. package/dist/contracts/token-accounting.d.ts +12 -12
  30. package/dist/index.cjs +18 -212
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.js +18 -212
  33. package/dist/index.js.map +1 -1
  34. package/dist/quickstart.cjs +17 -202
  35. package/dist/quickstart.cjs.map +1 -1
  36. package/dist/quickstart.js +17 -202
  37. package/dist/quickstart.js.map +1 -1
  38. package/dist/runtime-kernel/child-runs/childRunInvoker.d.cts +1 -3
  39. package/dist/runtime-kernel/child-runs/childRunInvoker.d.ts +1 -3
  40. package/dist/runtime-kernel/events/agentEvents.d.cts +2 -2
  41. package/dist/runtime-kernel/events/agentEvents.d.ts +2 -2
  42. package/dist/runtime-kernel/graph-engine/engine.d.cts +1 -0
  43. package/dist/runtime-kernel/graph-engine/engine.d.ts +1 -0
  44. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.cts +1 -3
  45. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.ts +1 -3
  46. package/dist/runtime-kernel/testkit/defaultGraphExecutor.d.cts +1 -2
  47. package/dist/runtime-kernel/testkit/defaultGraphExecutor.d.ts +1 -2
  48. package/dist/runtime-kernel/testkit/graphLoopHarness.d.cts +1 -2
  49. package/dist/runtime-kernel/testkit/graphLoopHarness.d.ts +1 -2
  50. package/dist/runtime-kernel/tools/index.d.cts +1 -2
  51. package/dist/runtime-kernel/tools/index.d.ts +1 -2
  52. package/dist/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.d.cts +4 -3
  53. package/dist/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.d.ts +4 -3
  54. package/dist/runtime-kernel/tools/ports.d.cts +1 -28
  55. package/dist/runtime-kernel/tools/ports.d.ts +1 -28
  56. package/dist/runtime-kernel/tools/toolContextRuntime.d.cts +1 -1
  57. package/dist/runtime-kernel/tools/toolContextRuntime.d.ts +1 -1
  58. package/dist/runtime-kernel/tools/toolContracts.d.cts +0 -6
  59. package/dist/runtime-kernel/tools/toolContracts.d.ts +0 -6
  60. package/dist/runtime-kernel/tools/toolExecutionContext.d.cts +0 -7
  61. package/dist/runtime-kernel/tools/toolExecutionContext.d.ts +0 -7
  62. package/dist/runtime-kernel.cjs +17 -207
  63. package/dist/runtime-kernel.cjs.map +1 -1
  64. package/dist/runtime-kernel.d.cts +1 -2
  65. package/dist/runtime-kernel.d.ts +1 -2
  66. package/dist/runtime-kernel.js +17 -207
  67. package/dist/runtime-kernel.js.map +1 -1
  68. package/dist/testkit/agent-harness/scriptedInferenceHarness.d.cts +1 -1
  69. package/dist/testkit/agent-harness/scriptedInferenceHarness.d.ts +1 -1
  70. package/dist/testkit.cjs +17 -207
  71. package/dist/testkit.cjs.map +1 -1
  72. package/dist/testkit.js +17 -207
  73. package/dist/testkit.js.map +1 -1
  74. package/docs/integration/tool-development-guide.md +8 -23
  75. package/docs/integration/tools.md +2 -5
  76. package/package.json +2 -2
  77. package/dist/runtime-kernel/tools/model-input/definitions/toolModelInputPolicy.d.cts +0 -17
  78. package/dist/runtime-kernel/tools/model-input/definitions/toolModelInputPolicy.d.ts +0 -17
@@ -9,14 +9,14 @@ import { SerializableJsonValue } from './json.cjs';
9
9
  */
10
10
  declare const SubRunTraceKind: z.ZodEnum<{
11
11
  error: "error";
12
+ history_summary: "history_summary";
13
+ final_answer: "final_answer";
14
+ tool_output: "tool_output";
12
15
  tool_call_decision: "tool_call_decision";
13
16
  tool_process: "tool_process";
14
- tool_output: "tool_output";
15
17
  thought_delta: "thought_delta";
16
18
  thought_complete: "thought_complete";
17
19
  final_answer_chunk: "final_answer_chunk";
18
- final_answer: "final_answer";
19
- history_summary: "history_summary";
20
20
  llm_retry: "llm_retry";
21
21
  }>;
22
22
  type SubRunTraceKind = z.infer<typeof SubRunTraceKind>;
@@ -33,25 +33,25 @@ declare const SubRunTracePayload: z.ZodObject<{
33
33
  source_event_id: z.ZodString;
34
34
  kind: z.ZodEnum<{
35
35
  error: "error";
36
+ history_summary: "history_summary";
37
+ final_answer: "final_answer";
38
+ tool_output: "tool_output";
36
39
  tool_call_decision: "tool_call_decision";
37
40
  tool_process: "tool_process";
38
- tool_output: "tool_output";
39
41
  thought_delta: "thought_delta";
40
42
  thought_complete: "thought_complete";
41
43
  final_answer_chunk: "final_answer_chunk";
42
- final_answer: "final_answer";
43
- history_summary: "history_summary";
44
44
  llm_retry: "llm_retry";
45
45
  }>;
46
46
  retry: z.ZodOptional<z.ZodObject<{
47
47
  retry_id: z.ZodString;
48
48
  status: z.ZodEnum<{
49
+ failed: "failed";
50
+ cancelled: "cancelled";
49
51
  waiting: "waiting";
50
52
  retrying: "retrying";
51
53
  succeeded: "succeeded";
52
54
  exhausted: "exhausted";
53
- failed: "failed";
54
- cancelled: "cancelled";
55
55
  }>;
56
56
  category: z.ZodEnum<{
57
57
  output: "output";
@@ -9,14 +9,14 @@ import { SerializableJsonValue } from './json.js';
9
9
  */
10
10
  declare const SubRunTraceKind: z.ZodEnum<{
11
11
  error: "error";
12
+ history_summary: "history_summary";
13
+ final_answer: "final_answer";
14
+ tool_output: "tool_output";
12
15
  tool_call_decision: "tool_call_decision";
13
16
  tool_process: "tool_process";
14
- tool_output: "tool_output";
15
17
  thought_delta: "thought_delta";
16
18
  thought_complete: "thought_complete";
17
19
  final_answer_chunk: "final_answer_chunk";
18
- final_answer: "final_answer";
19
- history_summary: "history_summary";
20
20
  llm_retry: "llm_retry";
21
21
  }>;
22
22
  type SubRunTraceKind = z.infer<typeof SubRunTraceKind>;
@@ -33,25 +33,25 @@ declare const SubRunTracePayload: z.ZodObject<{
33
33
  source_event_id: z.ZodString;
34
34
  kind: z.ZodEnum<{
35
35
  error: "error";
36
+ history_summary: "history_summary";
37
+ final_answer: "final_answer";
38
+ tool_output: "tool_output";
36
39
  tool_call_decision: "tool_call_decision";
37
40
  tool_process: "tool_process";
38
- tool_output: "tool_output";
39
41
  thought_delta: "thought_delta";
40
42
  thought_complete: "thought_complete";
41
43
  final_answer_chunk: "final_answer_chunk";
42
- final_answer: "final_answer";
43
- history_summary: "history_summary";
44
44
  llm_retry: "llm_retry";
45
45
  }>;
46
46
  retry: z.ZodOptional<z.ZodObject<{
47
47
  retry_id: z.ZodString;
48
48
  status: z.ZodEnum<{
49
+ failed: "failed";
50
+ cancelled: "cancelled";
49
51
  waiting: "waiting";
50
52
  retrying: "retrying";
51
53
  succeeded: "succeeded";
52
54
  exhausted: "exhausted";
53
- failed: "failed";
54
- cancelled: "cancelled";
55
55
  }>;
56
56
  category: z.ZodEnum<{
57
57
  output: "output";
@@ -6,11 +6,11 @@ declare const TokenLedgerEntryKind: z.ZodEnum<{
6
6
  }>;
7
7
  type TokenLedgerEntryKind = z.infer<typeof TokenLedgerEntryKind>;
8
8
  declare const ContextTokenComponentKind: z.ZodEnum<{
9
- user: "user";
10
9
  system: "system";
11
- other: "other";
12
- tool: "tool";
10
+ user: "user";
13
11
  assistant: "assistant";
12
+ tool: "tool";
13
+ other: "other";
14
14
  "context-injection": "context-injection";
15
15
  "history-summary": "history-summary";
16
16
  "working-memory": "working-memory";
@@ -33,11 +33,11 @@ type TokenUsageTotals = z.infer<typeof TokenUsageTotals>;
33
33
  declare const ContextTokenComponent: z.ZodObject<{
34
34
  componentId: z.ZodString;
35
35
  kind: z.ZodEnum<{
36
- user: "user";
37
36
  system: "system";
38
- other: "other";
39
- tool: "tool";
37
+ user: "user";
40
38
  assistant: "assistant";
39
+ tool: "tool";
40
+ other: "other";
41
41
  "context-injection": "context-injection";
42
42
  "history-summary": "history-summary";
43
43
  "working-memory": "working-memory";
@@ -149,11 +149,11 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
149
149
  components: z.ZodArray<z.ZodObject<{
150
150
  componentId: z.ZodString;
151
151
  kind: z.ZodEnum<{
152
- user: "user";
153
152
  system: "system";
154
- other: "other";
155
- tool: "tool";
153
+ user: "user";
156
154
  assistant: "assistant";
155
+ tool: "tool";
156
+ other: "other";
157
157
  "context-injection": "context-injection";
158
158
  "history-summary": "history-summary";
159
159
  "working-memory": "working-memory";
@@ -265,11 +265,11 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<[z.ZodObject<{
265
265
  components: z.ZodArray<z.ZodObject<{
266
266
  componentId: z.ZodString;
267
267
  kind: z.ZodEnum<{
268
- user: "user";
269
268
  system: "system";
270
- other: "other";
271
- tool: "tool";
269
+ user: "user";
272
270
  assistant: "assistant";
271
+ tool: "tool";
272
+ other: "other";
273
273
  "context-injection": "context-injection";
274
274
  "history-summary": "history-summary";
275
275
  "working-memory": "working-memory";
@@ -6,11 +6,11 @@ declare const TokenLedgerEntryKind: z.ZodEnum<{
6
6
  }>;
7
7
  type TokenLedgerEntryKind = z.infer<typeof TokenLedgerEntryKind>;
8
8
  declare const ContextTokenComponentKind: z.ZodEnum<{
9
- user: "user";
10
9
  system: "system";
11
- other: "other";
12
- tool: "tool";
10
+ user: "user";
13
11
  assistant: "assistant";
12
+ tool: "tool";
13
+ other: "other";
14
14
  "context-injection": "context-injection";
15
15
  "history-summary": "history-summary";
16
16
  "working-memory": "working-memory";
@@ -33,11 +33,11 @@ type TokenUsageTotals = z.infer<typeof TokenUsageTotals>;
33
33
  declare const ContextTokenComponent: z.ZodObject<{
34
34
  componentId: z.ZodString;
35
35
  kind: z.ZodEnum<{
36
- user: "user";
37
36
  system: "system";
38
- other: "other";
39
- tool: "tool";
37
+ user: "user";
40
38
  assistant: "assistant";
39
+ tool: "tool";
40
+ other: "other";
41
41
  "context-injection": "context-injection";
42
42
  "history-summary": "history-summary";
43
43
  "working-memory": "working-memory";
@@ -149,11 +149,11 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
149
149
  components: z.ZodArray<z.ZodObject<{
150
150
  componentId: z.ZodString;
151
151
  kind: z.ZodEnum<{
152
- user: "user";
153
152
  system: "system";
154
- other: "other";
155
- tool: "tool";
153
+ user: "user";
156
154
  assistant: "assistant";
155
+ tool: "tool";
156
+ other: "other";
157
157
  "context-injection": "context-injection";
158
158
  "history-summary": "history-summary";
159
159
  "working-memory": "working-memory";
@@ -265,11 +265,11 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<[z.ZodObject<{
265
265
  components: z.ZodArray<z.ZodObject<{
266
266
  componentId: z.ZodString;
267
267
  kind: z.ZodEnum<{
268
- user: "user";
269
268
  system: "system";
270
- other: "other";
271
- tool: "tool";
269
+ user: "user";
272
270
  assistant: "assistant";
271
+ tool: "tool";
272
+ other: "other";
273
273
  "context-injection": "context-injection";
274
274
  "history-summary": "history-summary";
275
275
  "working-memory": "working-memory";
package/dist/index.cjs CHANGED
@@ -4024,6 +4024,16 @@ function mergeResumeSessionLocal(persistedLocal, localPatch) {
4024
4024
  }
4025
4025
  };
4026
4026
  }
4027
+ function resolveResumeNodeId(local, requested) {
4028
+ const pending = local?.pendingToolCalls;
4029
+ if (!Array.isArray(pending) || pending.length === 0) return requested ?? "llm";
4030
+ if (requested !== void 0 && requested !== "tool") {
4031
+ throw new Error(
4032
+ `Graph resume must first run ${pending.length} pending tool call(s) from the interrupted batch: requested node=${requested}`
4033
+ );
4034
+ }
4035
+ return "tool";
4036
+ }
4027
4037
  var GraphExecutor = class {
4028
4038
  constructor(checkpointer, config = {}) {
4029
4039
  this.checkpointer = checkpointer;
@@ -4136,13 +4146,14 @@ var GraphExecutor = class {
4136
4146
  );
4137
4147
  }
4138
4148
  const resumedLocal = mergeResumeSessionLocal(current.local, input.localPatch);
4149
+ const nodeId = resolveResumeNodeId(resumedLocal, input.nodeId);
4139
4150
  if (this.executionCheckpointPort && current.local?.executorLocal) {
4140
4151
  resumedLocal.executorLocal = { ...current.local.executorLocal };
4141
4152
  }
4142
4153
  this.ephemeralLocals.set(checkpointKey, resumedLocal);
4143
4154
  await this.commitCheckpoint(checkpointKey, {
4144
4155
  ...current,
4145
- nodeId: input.nodeId ?? "llm",
4156
+ nodeId,
4146
4157
  ...this.executionCheckpointPort ? { executionStatus: "ready" } : {},
4147
4158
  revision: currentRevision + 1,
4148
4159
  local: sanitizeCheckpointLocal(resumedLocal)
@@ -5033,7 +5044,6 @@ var tickPipelineContextKeys = [
5033
5044
  "runtimeEventCommitPort",
5034
5045
  "modelId",
5035
5046
  "toolSchemas",
5036
- "toolModelInputRequirement",
5037
5047
  "toolCallStreamingPolicies",
5038
5048
  "llmOptions",
5039
5049
  "toolDefinitionTokens",
@@ -6154,7 +6164,6 @@ function createExecuteLlmStage(dependencies) {
6154
6164
  "outputProcessor",
6155
6165
  "modelId",
6156
6166
  "llmMessages",
6157
- "toolModelInputRequirement",
6158
6167
  "toolCallStreamingPolicies",
6159
6168
  "imageInputAdmissionEvidence",
6160
6169
  "llmOptions",
@@ -6213,7 +6222,6 @@ function createExecuteLlmStage(dependencies) {
6213
6222
  },
6214
6223
  {
6215
6224
  imageInputAdmissionEvidence: ctx.imageInputAdmissionEvidence,
6216
- additionalModelInputRequirement: ctx.toolModelInputRequirement,
6217
6225
  toolCallStreamingPolicies: ctx.toolCallStreamingPolicies,
6218
6226
  ...promptBudget && promptUsageMeasurementPolicy ? {
6219
6227
  measurePromptUsage: async (activeModelId, messages) => {
@@ -7198,29 +7206,6 @@ function createCommitContextCompactionStage() {
7198
7206
  });
7199
7207
  }
7200
7208
 
7201
- // src/runtime-kernel/graph-engine/functions/prepareModelCompatibleTools.ts
7202
- function prepareModelCompatibleTools(input) {
7203
- const schemas = [];
7204
- const requirements = [];
7205
- for (const schema of input.schemas) {
7206
- const definition = input.getToolDefinition(schema.function.name);
7207
- const requirement = definition?.modelInputRequirement;
7208
- const delivery = definition?.modelInputDelivery ?? "required";
7209
- const isRequired = delivery === "required";
7210
- if (requirement && isRequired && !evaluateModelInputCompatibility(input.model, requirement).compatible) {
7211
- continue;
7212
- }
7213
- schemas.push(schema);
7214
- if (requirement && isRequired) {
7215
- requirements.push(requirement);
7216
- }
7217
- }
7218
- return {
7219
- schemas: Object.freeze(schemas),
7220
- requirement: requirements.length > 0 ? mergeModelInputRequirements(...requirements) : EMPTY_MODEL_INPUT_REQUIREMENT
7221
- };
7222
- }
7223
-
7224
7209
  // src/runtime-kernel/graph-engine/tick-pipeline/stages/prepareCallStage.ts
7225
7210
  function createPrepareCallStage(dependencies) {
7226
7211
  return defineTickStage({
@@ -7238,7 +7223,6 @@ function createPrepareCallStage(dependencies) {
7238
7223
  writes: [
7239
7224
  "modelId",
7240
7225
  "toolSchemas",
7241
- "toolModelInputRequirement",
7242
7226
  "toolCallStreamingPolicies",
7243
7227
  "llmOptions",
7244
7228
  "toolDefinitionTokens"
@@ -7278,12 +7262,7 @@ function createPrepareCallStage(dependencies) {
7278
7262
  invocation: ctx.request
7279
7263
  });
7280
7264
  const modelConfig = dependencies.modelCatalog.getModelById(modelId);
7281
- const toolPreparation = prepareModelCompatibleTools({
7282
- schemas: candidateToolSchemas,
7283
- model: modelConfig,
7284
- getToolDefinition: (toolName) => dependencies.toolCatalog.getToolDefinition(toolName)
7285
- });
7286
- const toolSchemas = [...toolPreparation.schemas];
7265
+ const toolSchemas = [...candidateToolSchemas];
7287
7266
  const toolCallStreamingPolicies = deriveToolCallStreamingPolicies(
7288
7267
  toolSchemas,
7289
7268
  dependencies.toolCatalog
@@ -7327,7 +7306,6 @@ function createPrepareCallStage(dependencies) {
7327
7306
  return {
7328
7307
  modelId,
7329
7308
  toolSchemas,
7330
- toolModelInputRequirement: toolPreparation.requirement,
7331
7309
  toolCallStreamingPolicies,
7332
7310
  llmOptions,
7333
7311
  toolDefinitionTokens
@@ -7501,7 +7479,6 @@ var GraphAgentExecutor = class {
7501
7479
  modelId: "",
7502
7480
  toolSchemas: [],
7503
7481
  toolCallStreamingPolicies: {},
7504
- toolModelInputRequirement: void 0,
7505
7482
  llmOptions: {},
7506
7483
  toolDefinitionTokens: 0,
7507
7484
  llmMessages: [],
@@ -8753,10 +8730,6 @@ function parseToolModelInputDeclaration(value) {
8753
8730
  }
8754
8731
 
8755
8732
  // src/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.ts
8756
- var TOOL_RESULT_IMAGE_REQUIREMENT = {
8757
- requires_image_input: true,
8758
- placements: ["tool_result_image"]
8759
- };
8760
8733
  async function resolveToolModelInput(input) {
8761
8734
  if (!input.selections) {
8762
8735
  return void 0;
@@ -8777,16 +8750,6 @@ async function resolveToolModelInput(input) {
8777
8750
  if (parsed.data.some((reference, index) => reference.id !== input.selections?.[index]?.id)) {
8778
8751
  throw new ToolModelInputResolutionError("Tool model input resolver changed attachment identity or order.");
8779
8752
  }
8780
- if (!input.activeModelId) {
8781
- throw new ToolModelInputResolutionError("Missing successful LLM model for tool input validation.");
8782
- }
8783
- if (!input.capabilityValidator) {
8784
- throw new ToolModelInputResolutionError("Tool model input validator is not configured.");
8785
- }
8786
- input.capabilityValidator.assertCompatible({
8787
- activeModelId: input.activeModelId,
8788
- requirement: TOOL_RESULT_IMAGE_REQUIREMENT
8789
- });
8790
8753
  return Object.freeze(parsed.data.map((reference) => Object.freeze(reference)));
8791
8754
  }
8792
8755
 
@@ -9251,8 +9214,7 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
9251
9214
  "parentRunId",
9252
9215
  "childRunDepth",
9253
9216
  "childRunContextInjections",
9254
- "parentToolCallId",
9255
- "modelInputAdmission"
9217
+ "parentToolCallId"
9256
9218
  ];
9257
9219
  var TOOL_CONTEXT_RUNTIME_BINDINGS_KEY = /* @__PURE__ */ Symbol.for(
9258
9220
  "@linnlabs/linnkit/tool-context-runtime-bindings/v1"
@@ -9553,7 +9515,6 @@ var ToolNodeEventBridge = class {
9553
9515
 
9554
9516
  // src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
9555
9517
  var logger10 = new Logger("ToolNode");
9556
- var MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR = "tool.model_input.requirement_resolution_failed: Tool model input requirement could not be resolved";
9557
9518
  function parseToolArgs(call) {
9558
9519
  const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
9559
9520
  if (!rawArguments.trim()) {
@@ -9657,12 +9618,6 @@ function prepareToolExecution(params) {
9657
9618
  toolArgs,
9658
9619
  idempotencyKey
9659
9620
  });
9660
- const modelInputRequirement = resolveModelInputRequirement({
9661
- toolDefinition,
9662
- toolArgs,
9663
- hasProtocolError: protocolError !== void 0,
9664
- toolName
9665
- });
9666
9621
  return {
9667
9622
  call: params.call,
9668
9623
  toolName,
@@ -9671,30 +9626,9 @@ function prepareToolExecution(params) {
9671
9626
  toolArgs,
9672
9627
  protocolError,
9673
9628
  idempotencyKey,
9674
- ...modelInputRequirement.requirement ? { modelInputRequirement: modelInputRequirement.requirement } : {},
9675
- modelInputDelivery: toolDefinition?.modelInputDelivery ?? "required",
9676
- ...modelInputRequirement.error ? { modelInputRequirementError: modelInputRequirement.error } : {},
9677
9629
  bridge
9678
9630
  };
9679
9631
  }
9680
- function resolveModelInputRequirement(params) {
9681
- if (params.hasProtocolError) {
9682
- return {};
9683
- }
9684
- if (!params.toolDefinition?.resolveModelInputRequirement) {
9685
- return params.toolDefinition?.modelInputRequirement ? { requirement: params.toolDefinition.modelInputRequirement } : {};
9686
- }
9687
- try {
9688
- const requirement = params.toolDefinition.resolveModelInputRequirement(params.toolArgs);
9689
- return requirement ? { requirement } : {};
9690
- } catch (error) {
9691
- logger10.warn("dynamic model input requirement resolution failed", {
9692
- toolName: params.toolName,
9693
- errorName: error instanceof Error ? error.name : "UnknownError"
9694
- });
9695
- return { error: MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR };
9696
- }
9697
- }
9698
9632
  function attachWorkingHistoryView(params) {
9699
9633
  const historyEvents = parseRuntimeEvents(
9700
9634
  params.state.local?.history ?? []
@@ -9933,14 +9867,6 @@ function readToolObservationPolicy(local) {
9933
9867
  function readHistoryEvents(local) {
9934
9868
  return parseRuntimeEvents(local.history ?? []);
9935
9869
  }
9936
- function readLastSuccessfulLlmModelId(local) {
9937
- const executorLocal = local.executorLocal;
9938
- if (!isRecord9(executorLocal)) {
9939
- return void 0;
9940
- }
9941
- const value = executorLocal.lastSuccessfulLlmModelId;
9942
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
9943
- }
9944
9870
  function formatCapabilityError(error) {
9945
9871
  if (isRecord9(error)) {
9946
9872
  const codeValue = error.errorCode ?? error.code;
@@ -9952,29 +9878,12 @@ function formatCapabilityError(error) {
9952
9878
  }
9953
9879
  return error instanceof Error ? error.message : String(error);
9954
9880
  }
9955
- function bindModelInputAdmission(input) {
9956
- input.context.modelInputAdmission = Object.freeze({
9957
- requirement: Object.freeze({
9958
- ...input.requirement,
9959
- placements: Object.freeze([...input.requirement.placements])
9960
- }),
9961
- delivery: input.delivery,
9962
- admitted: input.admitted
9963
- });
9964
- }
9965
- function isOptionalImageInputIncompatibility(reason) {
9966
- return reason === "image_input_unsupported" || reason === "placement_unsupported";
9967
- }
9968
- function shouldDeliverToolModelInput(input) {
9969
- return input.delivery === "required" || input.context.modelInputAdmission?.admitted === true;
9970
- }
9971
9881
  var ToolNode = class {
9972
9882
  id = "tool";
9973
9883
  toolRuntime;
9974
9884
  observationPreview;
9975
9885
  telemetryPort;
9976
9886
  auditPort;
9977
- modelInputCapabilityValidator;
9978
9887
  modelInputResolver;
9979
9888
  idempotencyInFlight = /* @__PURE__ */ new Map();
9980
9889
  constructor(dependencies) {
@@ -9982,7 +9891,6 @@ var ToolNode = class {
9982
9891
  this.observationPreview = dependencies.observationPreview;
9983
9892
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
9984
9893
  this.auditPort = dependencies.auditPort ?? noopAudit;
9985
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
9986
9894
  this.modelInputResolver = dependencies.modelInputResolver;
9987
9895
  }
9988
9896
  /**
@@ -10148,7 +10056,6 @@ var ToolNode = class {
10148
10056
  logger11.warn("no tool name found in call");
10149
10057
  return { kind: "yield", events: [] };
10150
10058
  }
10151
- delete prepared.toolContext.modelInputAdmission;
10152
10059
  if (typeof execution.protocolError === "string") {
10153
10060
  return this.handleError({
10154
10061
  ...prepared,
@@ -10166,88 +10073,6 @@ var ToolNode = class {
10166
10073
  bridge: execution.bridge
10167
10074
  });
10168
10075
  }
10169
- if (typeof execution.modelInputRequirementError === "string") {
10170
- return this.handleError({
10171
- ...prepared,
10172
- calls,
10173
- call,
10174
- toolName: execution.toolName,
10175
- toolCallId: execution.toolCallId,
10176
- toolArgs: execution.toolArgs,
10177
- exec: {
10178
- success: false,
10179
- error: execution.modelInputRequirementError,
10180
- errorKind: "capability",
10181
- durationMs: 0
10182
- },
10183
- bridge: execution.bridge
10184
- });
10185
- }
10186
- if (execution.modelInputRequirement?.requires_image_input === true) {
10187
- const activeModelId = readLastSuccessfulLlmModelId(prepared.local);
10188
- let capabilityError;
10189
- let admitted = true;
10190
- if (!activeModelId) {
10191
- capabilityError = "llm.unsupported_capability: missing successful LLM model for tool input validation";
10192
- } else if (!this.modelInputCapabilityValidator) {
10193
- capabilityError = "llm.unsupported_capability: tool model input validator is not configured";
10194
- } else {
10195
- const validationInput = {
10196
- activeModelId,
10197
- requirement: execution.modelInputRequirement
10198
- };
10199
- if (execution.modelInputDelivery === "when_supported") {
10200
- try {
10201
- const compatibility = this.modelInputCapabilityValidator.evaluate(validationInput);
10202
- if (!compatibility.compatible) {
10203
- if (isOptionalImageInputIncompatibility(compatibility.reason)) {
10204
- admitted = false;
10205
- logger11.debug("optional tool model input omitted for incompatible active model", {
10206
- toolName: execution.toolName,
10207
- activeModelId,
10208
- reason: compatibility.reason,
10209
- placements: execution.modelInputRequirement.placements
10210
- });
10211
- } else {
10212
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
10213
- capabilityError = "llm.unsupported_capability: active model is not eligible";
10214
- }
10215
- }
10216
- } catch (error) {
10217
- capabilityError = formatCapabilityError(error);
10218
- }
10219
- } else {
10220
- try {
10221
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
10222
- } catch (error) {
10223
- capabilityError = formatCapabilityError(error);
10224
- }
10225
- }
10226
- }
10227
- if (capabilityError) {
10228
- return this.handleError({
10229
- ...prepared,
10230
- calls,
10231
- call,
10232
- toolName: execution.toolName,
10233
- toolCallId: execution.toolCallId,
10234
- toolArgs: execution.toolArgs,
10235
- exec: {
10236
- success: false,
10237
- error: capabilityError,
10238
- errorKind: "capability",
10239
- durationMs: 0
10240
- },
10241
- bridge: execution.bridge
10242
- });
10243
- }
10244
- bindModelInputAdmission({
10245
- context: prepared.toolContext,
10246
- requirement: execution.modelInputRequirement,
10247
- delivery: execution.modelInputDelivery,
10248
- admitted
10249
- });
10250
- }
10251
10076
  await this.emitToolDecisionAudit({
10252
10077
  action: "tool.allow",
10253
10078
  toolName: execution.toolName,
@@ -10299,21 +10124,15 @@ var ToolNode = class {
10299
10124
  bridge: execution.bridge
10300
10125
  });
10301
10126
  }
10302
- const deliverModelInput = shouldDeliverToolModelInput({
10303
- context: prepared.toolContext,
10304
- delivery: execution.modelInputDelivery
10305
- });
10306
- let attachments = deliverModelInput ? exec.cachedAttachments : void 0;
10127
+ let attachments = exec.cachedAttachments;
10307
10128
  try {
10308
- if (deliverModelInput && !attachments) {
10129
+ if (!attachments) {
10309
10130
  attachments = await resolveToolModelInput({
10310
- activeModelId: readLastSuccessfulLlmModelId(prepared.local),
10311
10131
  toolName: execution.toolName,
10312
10132
  toolCallId: execution.toolCallId,
10313
10133
  selections: contract.modelInputAttachments,
10314
10134
  context: prepared.toolContext,
10315
- resolver: this.modelInputResolver,
10316
- capabilityValidator: this.modelInputCapabilityValidator
10135
+ resolver: this.modelInputResolver
10317
10136
  });
10318
10137
  }
10319
10138
  } catch (error) {
@@ -11022,10 +10841,6 @@ function formatUnknownToolArguments(fields, allowedFields) {
11022
10841
  // src/runtime-kernel/tools/toolContracts.ts
11023
10842
  var BaseTool = class {
11024
10843
  idempotency;
11025
- modelInputRequirement;
11026
- /** 模型输入是工具成功的必要结果,还是仅在当前模型支持时提供的增强反馈。 */
11027
- modelInputDelivery;
11028
- resolveModelInputRequirement;
11029
10844
  streaming;
11030
10845
  getExecutionSummary(output) {
11031
10846
  const FULL_CONTENT_THRESHOLD = 200;
@@ -13303,7 +13118,6 @@ var ChildRunInvoker = class {
13303
13118
  createLlmNode;
13304
13119
  toolRuntime;
13305
13120
  observationPreview;
13306
- modelInputCapabilityValidator;
13307
13121
  modelInputResolver;
13308
13122
  eventToMessageConverter;
13309
13123
  defaultJudgeToolName;
@@ -13314,7 +13128,6 @@ var ChildRunInvoker = class {
13314
13128
  this.createLlmNode = dependencies.createLlmNode;
13315
13129
  this.toolRuntime = dependencies.toolRuntime;
13316
13130
  this.observationPreview = dependencies.observationPreview;
13317
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
13318
13131
  this.modelInputResolver = dependencies.modelInputResolver;
13319
13132
  this.eventToMessageConverter = dependencies.eventToMessageConverter;
13320
13133
  this.defaultJudgeToolName = dependencies.defaultJudgeToolName;
@@ -13577,7 +13390,6 @@ var ChildRunInvoker = class {
13577
13390
  observationPreview: this.observationPreview,
13578
13391
  telemetryPort: this.telemetryPort,
13579
13392
  auditPort: this.auditPort,
13580
- modelInputCapabilityValidator: this.modelInputCapabilityValidator,
13581
13393
  modelInputResolver: this.modelInputResolver
13582
13394
  }));
13583
13395
  graph.registerNode(new WaitUserNode({ auditPort: this.auditPort }));
@@ -15687,7 +15499,6 @@ function createDefaultGraphExecutor(options) {
15687
15499
  observationPreview: options.observationPreview,
15688
15500
  auditPort: options.auditPort,
15689
15501
  telemetryPort: options.telemetryPort,
15690
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
15691
15502
  modelInputResolver: options.modelInputResolver
15692
15503
  }));
15693
15504
  executor2.registerNode(new WaitUserNode({ auditPort: options.auditPort }));
@@ -15726,7 +15537,6 @@ function createGraphLoopHarness(options) {
15726
15537
  maxSteps,
15727
15538
  auditPort: options.auditPort,
15728
15539
  telemetryPort: options.telemetryPort,
15729
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
15730
15540
  modelInputResolver: options.modelInputResolver
15731
15541
  });
15732
15542
  const local = {
@@ -16000,11 +15810,7 @@ var QuickstartMemoryToolRuntime = class {
16000
15810
  return {
16001
15811
  parameters: tool.parameters,
16002
15812
  validateArguments: (args) => tool["validateArguments"](args),
16003
- idempotency: tool.idempotency,
16004
- modelInputRequirement: tool.modelInputRequirement,
16005
- ...tool.resolveModelInputRequirement ? {
16006
- resolveModelInputRequirement: (args) => tool.resolveModelInputRequirement?.(args)
16007
- } : {}
15813
+ idempotency: tool.idempotency
16008
15814
  };
16009
15815
  }
16010
15816
  async executeTool(toolName, args, context) {