@linnlabs/linnkit 0.41.0 → 0.42.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 (54) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cli.cjs +5 -201
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +5 -201
  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/index.cjs +6 -211
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.js +6 -211
  13. package/dist/index.js.map +1 -1
  14. package/dist/quickstart.cjs +5 -201
  15. package/dist/quickstart.cjs.map +1 -1
  16. package/dist/quickstart.js +5 -201
  17. package/dist/quickstart.js.map +1 -1
  18. package/dist/runtime-kernel/child-runs/childRunInvoker.d.cts +1 -3
  19. package/dist/runtime-kernel/child-runs/childRunInvoker.d.ts +1 -3
  20. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.cts +1 -3
  21. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.ts +1 -3
  22. package/dist/runtime-kernel/testkit/defaultGraphExecutor.d.cts +1 -2
  23. package/dist/runtime-kernel/testkit/defaultGraphExecutor.d.ts +1 -2
  24. package/dist/runtime-kernel/testkit/graphLoopHarness.d.cts +1 -2
  25. package/dist/runtime-kernel/testkit/graphLoopHarness.d.ts +1 -2
  26. package/dist/runtime-kernel/tools/index.d.cts +1 -2
  27. package/dist/runtime-kernel/tools/index.d.ts +1 -2
  28. package/dist/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.d.cts +4 -3
  29. package/dist/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.d.ts +4 -3
  30. package/dist/runtime-kernel/tools/ports.d.cts +1 -28
  31. package/dist/runtime-kernel/tools/ports.d.ts +1 -28
  32. package/dist/runtime-kernel/tools/toolContextRuntime.d.cts +1 -1
  33. package/dist/runtime-kernel/tools/toolContextRuntime.d.ts +1 -1
  34. package/dist/runtime-kernel/tools/toolContracts.d.cts +0 -6
  35. package/dist/runtime-kernel/tools/toolContracts.d.ts +0 -6
  36. package/dist/runtime-kernel/tools/toolExecutionContext.d.cts +0 -7
  37. package/dist/runtime-kernel/tools/toolExecutionContext.d.ts +0 -7
  38. package/dist/runtime-kernel.cjs +5 -206
  39. package/dist/runtime-kernel.cjs.map +1 -1
  40. package/dist/runtime-kernel.d.cts +1 -2
  41. package/dist/runtime-kernel.d.ts +1 -2
  42. package/dist/runtime-kernel.js +5 -206
  43. package/dist/runtime-kernel.js.map +1 -1
  44. package/dist/testkit/agent-harness/scriptedInferenceHarness.d.cts +1 -1
  45. package/dist/testkit/agent-harness/scriptedInferenceHarness.d.ts +1 -1
  46. package/dist/testkit.cjs +5 -206
  47. package/dist/testkit.cjs.map +1 -1
  48. package/dist/testkit.js +5 -206
  49. package/dist/testkit.js.map +1 -1
  50. package/docs/integration/tool-development-guide.md +7 -23
  51. package/docs/integration/tools.md +2 -5
  52. package/package.json +2 -2
  53. package/dist/runtime-kernel/tools/model-input/definitions/toolModelInputPolicy.d.cts +0 -17
  54. package/dist/runtime-kernel/tools/model-input/definitions/toolModelInputPolicy.d.ts +0 -17
package/dist/index.cjs CHANGED
@@ -5033,7 +5033,6 @@ var tickPipelineContextKeys = [
5033
5033
  "runtimeEventCommitPort",
5034
5034
  "modelId",
5035
5035
  "toolSchemas",
5036
- "toolModelInputRequirement",
5037
5036
  "toolCallStreamingPolicies",
5038
5037
  "llmOptions",
5039
5038
  "toolDefinitionTokens",
@@ -6154,7 +6153,6 @@ function createExecuteLlmStage(dependencies) {
6154
6153
  "outputProcessor",
6155
6154
  "modelId",
6156
6155
  "llmMessages",
6157
- "toolModelInputRequirement",
6158
6156
  "toolCallStreamingPolicies",
6159
6157
  "imageInputAdmissionEvidence",
6160
6158
  "llmOptions",
@@ -6213,7 +6211,6 @@ function createExecuteLlmStage(dependencies) {
6213
6211
  },
6214
6212
  {
6215
6213
  imageInputAdmissionEvidence: ctx.imageInputAdmissionEvidence,
6216
- additionalModelInputRequirement: ctx.toolModelInputRequirement,
6217
6214
  toolCallStreamingPolicies: ctx.toolCallStreamingPolicies,
6218
6215
  ...promptBudget && promptUsageMeasurementPolicy ? {
6219
6216
  measurePromptUsage: async (activeModelId, messages) => {
@@ -7198,29 +7195,6 @@ function createCommitContextCompactionStage() {
7198
7195
  });
7199
7196
  }
7200
7197
 
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
7198
  // src/runtime-kernel/graph-engine/tick-pipeline/stages/prepareCallStage.ts
7225
7199
  function createPrepareCallStage(dependencies) {
7226
7200
  return defineTickStage({
@@ -7238,7 +7212,6 @@ function createPrepareCallStage(dependencies) {
7238
7212
  writes: [
7239
7213
  "modelId",
7240
7214
  "toolSchemas",
7241
- "toolModelInputRequirement",
7242
7215
  "toolCallStreamingPolicies",
7243
7216
  "llmOptions",
7244
7217
  "toolDefinitionTokens"
@@ -7278,12 +7251,7 @@ function createPrepareCallStage(dependencies) {
7278
7251
  invocation: ctx.request
7279
7252
  });
7280
7253
  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];
7254
+ const toolSchemas = [...candidateToolSchemas];
7287
7255
  const toolCallStreamingPolicies = deriveToolCallStreamingPolicies(
7288
7256
  toolSchemas,
7289
7257
  dependencies.toolCatalog
@@ -7327,7 +7295,6 @@ function createPrepareCallStage(dependencies) {
7327
7295
  return {
7328
7296
  modelId,
7329
7297
  toolSchemas,
7330
- toolModelInputRequirement: toolPreparation.requirement,
7331
7298
  toolCallStreamingPolicies,
7332
7299
  llmOptions,
7333
7300
  toolDefinitionTokens
@@ -7501,7 +7468,6 @@ var GraphAgentExecutor = class {
7501
7468
  modelId: "",
7502
7469
  toolSchemas: [],
7503
7470
  toolCallStreamingPolicies: {},
7504
- toolModelInputRequirement: void 0,
7505
7471
  llmOptions: {},
7506
7472
  toolDefinitionTokens: 0,
7507
7473
  llmMessages: [],
@@ -8753,10 +8719,6 @@ function parseToolModelInputDeclaration(value) {
8753
8719
  }
8754
8720
 
8755
8721
  // 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
8722
  async function resolveToolModelInput(input) {
8761
8723
  if (!input.selections) {
8762
8724
  return void 0;
@@ -8777,16 +8739,6 @@ async function resolveToolModelInput(input) {
8777
8739
  if (parsed.data.some((reference, index) => reference.id !== input.selections?.[index]?.id)) {
8778
8740
  throw new ToolModelInputResolutionError("Tool model input resolver changed attachment identity or order.");
8779
8741
  }
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
8742
  return Object.freeze(parsed.data.map((reference) => Object.freeze(reference)));
8791
8743
  }
8792
8744
 
@@ -9251,8 +9203,7 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
9251
9203
  "parentRunId",
9252
9204
  "childRunDepth",
9253
9205
  "childRunContextInjections",
9254
- "parentToolCallId",
9255
- "modelInputAdmission"
9206
+ "parentToolCallId"
9256
9207
  ];
9257
9208
  var TOOL_CONTEXT_RUNTIME_BINDINGS_KEY = /* @__PURE__ */ Symbol.for(
9258
9209
  "@linnlabs/linnkit/tool-context-runtime-bindings/v1"
@@ -9553,7 +9504,6 @@ var ToolNodeEventBridge = class {
9553
9504
 
9554
9505
  // src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
9555
9506
  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
9507
  function parseToolArgs(call) {
9558
9508
  const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
9559
9509
  if (!rawArguments.trim()) {
@@ -9657,12 +9607,6 @@ function prepareToolExecution(params) {
9657
9607
  toolArgs,
9658
9608
  idempotencyKey
9659
9609
  });
9660
- const modelInputRequirement = resolveModelInputRequirement({
9661
- toolDefinition,
9662
- toolArgs,
9663
- hasProtocolError: protocolError !== void 0,
9664
- toolName
9665
- });
9666
9610
  return {
9667
9611
  call: params.call,
9668
9612
  toolName,
@@ -9671,30 +9615,9 @@ function prepareToolExecution(params) {
9671
9615
  toolArgs,
9672
9616
  protocolError,
9673
9617
  idempotencyKey,
9674
- ...modelInputRequirement.requirement ? { modelInputRequirement: modelInputRequirement.requirement } : {},
9675
- modelInputDelivery: toolDefinition?.modelInputDelivery ?? "required",
9676
- ...modelInputRequirement.error ? { modelInputRequirementError: modelInputRequirement.error } : {},
9677
9618
  bridge
9678
9619
  };
9679
9620
  }
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
9621
  function attachWorkingHistoryView(params) {
9699
9622
  const historyEvents = parseRuntimeEvents(
9700
9623
  params.state.local?.history ?? []
@@ -9933,14 +9856,6 @@ function readToolObservationPolicy(local) {
9933
9856
  function readHistoryEvents(local) {
9934
9857
  return parseRuntimeEvents(local.history ?? []);
9935
9858
  }
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
9859
  function formatCapabilityError(error) {
9945
9860
  if (isRecord9(error)) {
9946
9861
  const codeValue = error.errorCode ?? error.code;
@@ -9952,29 +9867,12 @@ function formatCapabilityError(error) {
9952
9867
  }
9953
9868
  return error instanceof Error ? error.message : String(error);
9954
9869
  }
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
9870
  var ToolNode = class {
9972
9871
  id = "tool";
9973
9872
  toolRuntime;
9974
9873
  observationPreview;
9975
9874
  telemetryPort;
9976
9875
  auditPort;
9977
- modelInputCapabilityValidator;
9978
9876
  modelInputResolver;
9979
9877
  idempotencyInFlight = /* @__PURE__ */ new Map();
9980
9878
  constructor(dependencies) {
@@ -9982,7 +9880,6 @@ var ToolNode = class {
9982
9880
  this.observationPreview = dependencies.observationPreview;
9983
9881
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
9984
9882
  this.auditPort = dependencies.auditPort ?? noopAudit;
9985
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
9986
9883
  this.modelInputResolver = dependencies.modelInputResolver;
9987
9884
  }
9988
9885
  /**
@@ -10148,7 +10045,6 @@ var ToolNode = class {
10148
10045
  logger11.warn("no tool name found in call");
10149
10046
  return { kind: "yield", events: [] };
10150
10047
  }
10151
- delete prepared.toolContext.modelInputAdmission;
10152
10048
  if (typeof execution.protocolError === "string") {
10153
10049
  return this.handleError({
10154
10050
  ...prepared,
@@ -10166,88 +10062,6 @@ var ToolNode = class {
10166
10062
  bridge: execution.bridge
10167
10063
  });
10168
10064
  }
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
10065
  await this.emitToolDecisionAudit({
10252
10066
  action: "tool.allow",
10253
10067
  toolName: execution.toolName,
@@ -10299,21 +10113,15 @@ var ToolNode = class {
10299
10113
  bridge: execution.bridge
10300
10114
  });
10301
10115
  }
10302
- const deliverModelInput = shouldDeliverToolModelInput({
10303
- context: prepared.toolContext,
10304
- delivery: execution.modelInputDelivery
10305
- });
10306
- let attachments = deliverModelInput ? exec.cachedAttachments : void 0;
10116
+ let attachments = exec.cachedAttachments;
10307
10117
  try {
10308
- if (deliverModelInput && !attachments) {
10118
+ if (!attachments) {
10309
10119
  attachments = await resolveToolModelInput({
10310
- activeModelId: readLastSuccessfulLlmModelId(prepared.local),
10311
10120
  toolName: execution.toolName,
10312
10121
  toolCallId: execution.toolCallId,
10313
10122
  selections: contract.modelInputAttachments,
10314
10123
  context: prepared.toolContext,
10315
- resolver: this.modelInputResolver,
10316
- capabilityValidator: this.modelInputCapabilityValidator
10124
+ resolver: this.modelInputResolver
10317
10125
  });
10318
10126
  }
10319
10127
  } catch (error) {
@@ -11022,10 +10830,6 @@ function formatUnknownToolArguments(fields, allowedFields) {
11022
10830
  // src/runtime-kernel/tools/toolContracts.ts
11023
10831
  var BaseTool = class {
11024
10832
  idempotency;
11025
- modelInputRequirement;
11026
- /** 模型输入是工具成功的必要结果,还是仅在当前模型支持时提供的增强反馈。 */
11027
- modelInputDelivery;
11028
- resolveModelInputRequirement;
11029
10833
  streaming;
11030
10834
  getExecutionSummary(output) {
11031
10835
  const FULL_CONTENT_THRESHOLD = 200;
@@ -13303,7 +13107,6 @@ var ChildRunInvoker = class {
13303
13107
  createLlmNode;
13304
13108
  toolRuntime;
13305
13109
  observationPreview;
13306
- modelInputCapabilityValidator;
13307
13110
  modelInputResolver;
13308
13111
  eventToMessageConverter;
13309
13112
  defaultJudgeToolName;
@@ -13314,7 +13117,6 @@ var ChildRunInvoker = class {
13314
13117
  this.createLlmNode = dependencies.createLlmNode;
13315
13118
  this.toolRuntime = dependencies.toolRuntime;
13316
13119
  this.observationPreview = dependencies.observationPreview;
13317
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
13318
13120
  this.modelInputResolver = dependencies.modelInputResolver;
13319
13121
  this.eventToMessageConverter = dependencies.eventToMessageConverter;
13320
13122
  this.defaultJudgeToolName = dependencies.defaultJudgeToolName;
@@ -13577,7 +13379,6 @@ var ChildRunInvoker = class {
13577
13379
  observationPreview: this.observationPreview,
13578
13380
  telemetryPort: this.telemetryPort,
13579
13381
  auditPort: this.auditPort,
13580
- modelInputCapabilityValidator: this.modelInputCapabilityValidator,
13581
13382
  modelInputResolver: this.modelInputResolver
13582
13383
  }));
13583
13384
  graph.registerNode(new WaitUserNode({ auditPort: this.auditPort }));
@@ -15687,7 +15488,6 @@ function createDefaultGraphExecutor(options) {
15687
15488
  observationPreview: options.observationPreview,
15688
15489
  auditPort: options.auditPort,
15689
15490
  telemetryPort: options.telemetryPort,
15690
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
15691
15491
  modelInputResolver: options.modelInputResolver
15692
15492
  }));
15693
15493
  executor2.registerNode(new WaitUserNode({ auditPort: options.auditPort }));
@@ -15726,7 +15526,6 @@ function createGraphLoopHarness(options) {
15726
15526
  maxSteps,
15727
15527
  auditPort: options.auditPort,
15728
15528
  telemetryPort: options.telemetryPort,
15729
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
15730
15529
  modelInputResolver: options.modelInputResolver
15731
15530
  });
15732
15531
  const local = {
@@ -16000,11 +15799,7 @@ var QuickstartMemoryToolRuntime = class {
16000
15799
  return {
16001
15800
  parameters: tool.parameters,
16002
15801
  validateArguments: (args) => tool["validateArguments"](args),
16003
- idempotency: tool.idempotency,
16004
- modelInputRequirement: tool.modelInputRequirement,
16005
- ...tool.resolveModelInputRequirement ? {
16006
- resolveModelInputRequirement: (args) => tool.resolveModelInputRequirement?.(args)
16007
- } : {}
15802
+ idempotency: tool.idempotency
16008
15803
  };
16009
15804
  }
16010
15805
  async executeTool(toolName, args, context) {