@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
@@ -4010,7 +4010,6 @@ var tickPipelineContextKeys = [
4010
4010
  "runtimeEventCommitPort",
4011
4011
  "modelId",
4012
4012
  "toolSchemas",
4013
- "toolModelInputRequirement",
4014
4013
  "toolCallStreamingPolicies",
4015
4014
  "llmOptions",
4016
4015
  "toolDefinitionTokens",
@@ -5131,7 +5130,6 @@ function createExecuteLlmStage(dependencies) {
5131
5130
  "outputProcessor",
5132
5131
  "modelId",
5133
5132
  "llmMessages",
5134
- "toolModelInputRequirement",
5135
5133
  "toolCallStreamingPolicies",
5136
5134
  "imageInputAdmissionEvidence",
5137
5135
  "llmOptions",
@@ -5190,7 +5188,6 @@ function createExecuteLlmStage(dependencies) {
5190
5188
  },
5191
5189
  {
5192
5190
  imageInputAdmissionEvidence: ctx.imageInputAdmissionEvidence,
5193
- additionalModelInputRequirement: ctx.toolModelInputRequirement,
5194
5191
  toolCallStreamingPolicies: ctx.toolCallStreamingPolicies,
5195
5192
  ...promptBudget && promptUsageMeasurementPolicy ? {
5196
5193
  measurePromptUsage: async (activeModelId, messages) => {
@@ -6175,29 +6172,6 @@ function createCommitContextCompactionStage() {
6175
6172
  });
6176
6173
  }
6177
6174
 
6178
- // src/runtime-kernel/graph-engine/functions/prepareModelCompatibleTools.ts
6179
- function prepareModelCompatibleTools(input) {
6180
- const schemas = [];
6181
- const requirements = [];
6182
- for (const schema of input.schemas) {
6183
- const definition = input.getToolDefinition(schema.function.name);
6184
- const requirement = definition?.modelInputRequirement;
6185
- const delivery = definition?.modelInputDelivery ?? "required";
6186
- const isRequired = delivery === "required";
6187
- if (requirement && isRequired && !evaluateModelInputCompatibility(input.model, requirement).compatible) {
6188
- continue;
6189
- }
6190
- schemas.push(schema);
6191
- if (requirement && isRequired) {
6192
- requirements.push(requirement);
6193
- }
6194
- }
6195
- return {
6196
- schemas: Object.freeze(schemas),
6197
- requirement: requirements.length > 0 ? mergeModelInputRequirements(...requirements) : EMPTY_MODEL_INPUT_REQUIREMENT
6198
- };
6199
- }
6200
-
6201
6175
  // src/runtime-kernel/graph-engine/tick-pipeline/stages/prepareCallStage.ts
6202
6176
  function createPrepareCallStage(dependencies) {
6203
6177
  return defineTickStage({
@@ -6215,7 +6189,6 @@ function createPrepareCallStage(dependencies) {
6215
6189
  writes: [
6216
6190
  "modelId",
6217
6191
  "toolSchemas",
6218
- "toolModelInputRequirement",
6219
6192
  "toolCallStreamingPolicies",
6220
6193
  "llmOptions",
6221
6194
  "toolDefinitionTokens"
@@ -6255,12 +6228,7 @@ function createPrepareCallStage(dependencies) {
6255
6228
  invocation: ctx.request
6256
6229
  });
6257
6230
  const modelConfig = dependencies.modelCatalog.getModelById(modelId);
6258
- const toolPreparation = prepareModelCompatibleTools({
6259
- schemas: candidateToolSchemas,
6260
- model: modelConfig,
6261
- getToolDefinition: (toolName) => dependencies.toolCatalog.getToolDefinition(toolName)
6262
- });
6263
- const toolSchemas = [...toolPreparation.schemas];
6231
+ const toolSchemas = [...candidateToolSchemas];
6264
6232
  const toolCallStreamingPolicies = deriveToolCallStreamingPolicies(
6265
6233
  toolSchemas,
6266
6234
  dependencies.toolCatalog
@@ -6304,7 +6272,6 @@ function createPrepareCallStage(dependencies) {
6304
6272
  return {
6305
6273
  modelId,
6306
6274
  toolSchemas,
6307
- toolModelInputRequirement: toolPreparation.requirement,
6308
6275
  toolCallStreamingPolicies,
6309
6276
  llmOptions,
6310
6277
  toolDefinitionTokens
@@ -6478,7 +6445,6 @@ var GraphAgentExecutor = class {
6478
6445
  modelId: "",
6479
6446
  toolSchemas: [],
6480
6447
  toolCallStreamingPolicies: {},
6481
- toolModelInputRequirement: void 0,
6482
6448
  llmOptions: {},
6483
6449
  toolDefinitionTokens: 0,
6484
6450
  llmMessages: [],
@@ -7730,10 +7696,6 @@ function parseToolModelInputDeclaration(value) {
7730
7696
  }
7731
7697
 
7732
7698
  // src/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.ts
7733
- var TOOL_RESULT_IMAGE_REQUIREMENT = {
7734
- requires_image_input: true,
7735
- placements: ["tool_result_image"]
7736
- };
7737
7699
  async function resolveToolModelInput(input) {
7738
7700
  if (!input.selections) {
7739
7701
  return void 0;
@@ -7754,16 +7716,6 @@ async function resolveToolModelInput(input) {
7754
7716
  if (parsed.data.some((reference, index) => reference.id !== input.selections?.[index]?.id)) {
7755
7717
  throw new ToolModelInputResolutionError("Tool model input resolver changed attachment identity or order.");
7756
7718
  }
7757
- if (!input.activeModelId) {
7758
- throw new ToolModelInputResolutionError("Missing successful LLM model for tool input validation.");
7759
- }
7760
- if (!input.capabilityValidator) {
7761
- throw new ToolModelInputResolutionError("Tool model input validator is not configured.");
7762
- }
7763
- input.capabilityValidator.assertCompatible({
7764
- activeModelId: input.activeModelId,
7765
- requirement: TOOL_RESULT_IMAGE_REQUIREMENT
7766
- });
7767
7719
  return Object.freeze(parsed.data.map((reference) => Object.freeze(reference)));
7768
7720
  }
7769
7721
 
@@ -8228,8 +8180,7 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
8228
8180
  "parentRunId",
8229
8181
  "childRunDepth",
8230
8182
  "childRunContextInjections",
8231
- "parentToolCallId",
8232
- "modelInputAdmission"
8183
+ "parentToolCallId"
8233
8184
  ];
8234
8185
  var TOOL_CONTEXT_RUNTIME_BINDINGS_KEY = /* @__PURE__ */ Symbol.for(
8235
8186
  "@linnlabs/linnkit/tool-context-runtime-bindings/v1"
@@ -8530,7 +8481,6 @@ var ToolNodeEventBridge = class {
8530
8481
 
8531
8482
  // src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
8532
8483
  var logger10 = new Logger("ToolNode");
8533
- var MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR = "tool.model_input.requirement_resolution_failed: Tool model input requirement could not be resolved";
8534
8484
  function parseToolArgs(call) {
8535
8485
  const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
8536
8486
  if (!rawArguments.trim()) {
@@ -8634,12 +8584,6 @@ function prepareToolExecution(params) {
8634
8584
  toolArgs,
8635
8585
  idempotencyKey
8636
8586
  });
8637
- const modelInputRequirement = resolveModelInputRequirement({
8638
- toolDefinition,
8639
- toolArgs,
8640
- hasProtocolError: protocolError !== void 0,
8641
- toolName
8642
- });
8643
8587
  return {
8644
8588
  call: params.call,
8645
8589
  toolName,
@@ -8648,30 +8592,9 @@ function prepareToolExecution(params) {
8648
8592
  toolArgs,
8649
8593
  protocolError,
8650
8594
  idempotencyKey,
8651
- ...modelInputRequirement.requirement ? { modelInputRequirement: modelInputRequirement.requirement } : {},
8652
- modelInputDelivery: toolDefinition?.modelInputDelivery ?? "required",
8653
- ...modelInputRequirement.error ? { modelInputRequirementError: modelInputRequirement.error } : {},
8654
8595
  bridge
8655
8596
  };
8656
8597
  }
8657
- function resolveModelInputRequirement(params) {
8658
- if (params.hasProtocolError) {
8659
- return {};
8660
- }
8661
- if (!params.toolDefinition?.resolveModelInputRequirement) {
8662
- return params.toolDefinition?.modelInputRequirement ? { requirement: params.toolDefinition.modelInputRequirement } : {};
8663
- }
8664
- try {
8665
- const requirement = params.toolDefinition.resolveModelInputRequirement(params.toolArgs);
8666
- return requirement ? { requirement } : {};
8667
- } catch (error) {
8668
- logger10.warn("dynamic model input requirement resolution failed", {
8669
- toolName: params.toolName,
8670
- errorName: error instanceof Error ? error.name : "UnknownError"
8671
- });
8672
- return { error: MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR };
8673
- }
8674
- }
8675
8598
  function attachWorkingHistoryView(params) {
8676
8599
  const historyEvents = parseRuntimeEvents(
8677
8600
  params.state.local?.history ?? []
@@ -8903,14 +8826,6 @@ function readToolObservationPolicy(local) {
8903
8826
  function readHistoryEvents(local) {
8904
8827
  return parseRuntimeEvents(local.history ?? []);
8905
8828
  }
8906
- function readLastSuccessfulLlmModelId(local) {
8907
- const executorLocal = local.executorLocal;
8908
- if (!isRecord9(executorLocal)) {
8909
- return void 0;
8910
- }
8911
- const value = executorLocal.lastSuccessfulLlmModelId;
8912
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
8913
- }
8914
8829
  function formatCapabilityError(error) {
8915
8830
  if (isRecord9(error)) {
8916
8831
  const codeValue = error.errorCode ?? error.code;
@@ -8922,29 +8837,12 @@ function formatCapabilityError(error) {
8922
8837
  }
8923
8838
  return error instanceof Error ? error.message : String(error);
8924
8839
  }
8925
- function bindModelInputAdmission(input) {
8926
- input.context.modelInputAdmission = Object.freeze({
8927
- requirement: Object.freeze({
8928
- ...input.requirement,
8929
- placements: Object.freeze([...input.requirement.placements])
8930
- }),
8931
- delivery: input.delivery,
8932
- admitted: input.admitted
8933
- });
8934
- }
8935
- function isOptionalImageInputIncompatibility(reason) {
8936
- return reason === "image_input_unsupported" || reason === "placement_unsupported";
8937
- }
8938
- function shouldDeliverToolModelInput(input) {
8939
- return input.delivery === "required" || input.context.modelInputAdmission?.admitted === true;
8940
- }
8941
8840
  var ToolNode = class {
8942
8841
  id = "tool";
8943
8842
  toolRuntime;
8944
8843
  observationPreview;
8945
8844
  telemetryPort;
8946
8845
  auditPort;
8947
- modelInputCapabilityValidator;
8948
8846
  modelInputResolver;
8949
8847
  idempotencyInFlight = /* @__PURE__ */ new Map();
8950
8848
  constructor(dependencies) {
@@ -8952,7 +8850,6 @@ var ToolNode = class {
8952
8850
  this.observationPreview = dependencies.observationPreview;
8953
8851
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
8954
8852
  this.auditPort = dependencies.auditPort ?? noopAudit;
8955
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
8956
8853
  this.modelInputResolver = dependencies.modelInputResolver;
8957
8854
  }
8958
8855
  /**
@@ -9118,7 +9015,6 @@ var ToolNode = class {
9118
9015
  logger11.warn("no tool name found in call");
9119
9016
  return { kind: "yield", events: [] };
9120
9017
  }
9121
- delete prepared.toolContext.modelInputAdmission;
9122
9018
  if (typeof execution.protocolError === "string") {
9123
9019
  return this.handleError({
9124
9020
  ...prepared,
@@ -9136,88 +9032,6 @@ var ToolNode = class {
9136
9032
  bridge: execution.bridge
9137
9033
  });
9138
9034
  }
9139
- if (typeof execution.modelInputRequirementError === "string") {
9140
- return this.handleError({
9141
- ...prepared,
9142
- calls,
9143
- call,
9144
- toolName: execution.toolName,
9145
- toolCallId: execution.toolCallId,
9146
- toolArgs: execution.toolArgs,
9147
- exec: {
9148
- success: false,
9149
- error: execution.modelInputRequirementError,
9150
- errorKind: "capability",
9151
- durationMs: 0
9152
- },
9153
- bridge: execution.bridge
9154
- });
9155
- }
9156
- if (execution.modelInputRequirement?.requires_image_input === true) {
9157
- const activeModelId = readLastSuccessfulLlmModelId(prepared.local);
9158
- let capabilityError;
9159
- let admitted = true;
9160
- if (!activeModelId) {
9161
- capabilityError = "llm.unsupported_capability: missing successful LLM model for tool input validation";
9162
- } else if (!this.modelInputCapabilityValidator) {
9163
- capabilityError = "llm.unsupported_capability: tool model input validator is not configured";
9164
- } else {
9165
- const validationInput = {
9166
- activeModelId,
9167
- requirement: execution.modelInputRequirement
9168
- };
9169
- if (execution.modelInputDelivery === "when_supported") {
9170
- try {
9171
- const compatibility = this.modelInputCapabilityValidator.evaluate(validationInput);
9172
- if (!compatibility.compatible) {
9173
- if (isOptionalImageInputIncompatibility(compatibility.reason)) {
9174
- admitted = false;
9175
- logger11.debug("optional tool model input omitted for incompatible active model", {
9176
- toolName: execution.toolName,
9177
- activeModelId,
9178
- reason: compatibility.reason,
9179
- placements: execution.modelInputRequirement.placements
9180
- });
9181
- } else {
9182
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
9183
- capabilityError = "llm.unsupported_capability: active model is not eligible";
9184
- }
9185
- }
9186
- } catch (error) {
9187
- capabilityError = formatCapabilityError(error);
9188
- }
9189
- } else {
9190
- try {
9191
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
9192
- } catch (error) {
9193
- capabilityError = formatCapabilityError(error);
9194
- }
9195
- }
9196
- }
9197
- if (capabilityError) {
9198
- return this.handleError({
9199
- ...prepared,
9200
- calls,
9201
- call,
9202
- toolName: execution.toolName,
9203
- toolCallId: execution.toolCallId,
9204
- toolArgs: execution.toolArgs,
9205
- exec: {
9206
- success: false,
9207
- error: capabilityError,
9208
- errorKind: "capability",
9209
- durationMs: 0
9210
- },
9211
- bridge: execution.bridge
9212
- });
9213
- }
9214
- bindModelInputAdmission({
9215
- context: prepared.toolContext,
9216
- requirement: execution.modelInputRequirement,
9217
- delivery: execution.modelInputDelivery,
9218
- admitted
9219
- });
9220
- }
9221
9035
  await this.emitToolDecisionAudit({
9222
9036
  action: "tool.allow",
9223
9037
  toolName: execution.toolName,
@@ -9269,21 +9083,15 @@ var ToolNode = class {
9269
9083
  bridge: execution.bridge
9270
9084
  });
9271
9085
  }
9272
- const deliverModelInput = shouldDeliverToolModelInput({
9273
- context: prepared.toolContext,
9274
- delivery: execution.modelInputDelivery
9275
- });
9276
- let attachments = deliverModelInput ? exec.cachedAttachments : void 0;
9086
+ let attachments = exec.cachedAttachments;
9277
9087
  try {
9278
- if (deliverModelInput && !attachments) {
9088
+ if (!attachments) {
9279
9089
  attachments = await resolveToolModelInput({
9280
- activeModelId: readLastSuccessfulLlmModelId(prepared.local),
9281
9090
  toolName: execution.toolName,
9282
9091
  toolCallId: execution.toolCallId,
9283
9092
  selections: contract.modelInputAttachments,
9284
9093
  context: prepared.toolContext,
9285
- resolver: this.modelInputResolver,
9286
- capabilityValidator: this.modelInputCapabilityValidator
9094
+ resolver: this.modelInputResolver
9287
9095
  });
9288
9096
  }
9289
9097
  } catch (error) {
@@ -9992,10 +9800,6 @@ function formatUnknownToolArguments(fields, allowedFields) {
9992
9800
  // src/runtime-kernel/tools/toolContracts.ts
9993
9801
  var BaseTool = class {
9994
9802
  idempotency;
9995
- modelInputRequirement;
9996
- /** 模型输入是工具成功的必要结果,还是仅在当前模型支持时提供的增强反馈。 */
9997
- modelInputDelivery;
9998
- resolveModelInputRequirement;
9999
9803
  streaming;
10000
9804
  getExecutionSummary(output) {
10001
9805
  const FULL_CONTENT_THRESHOLD = 200;
@@ -12273,7 +12077,6 @@ var ChildRunInvoker = class {
12273
12077
  createLlmNode;
12274
12078
  toolRuntime;
12275
12079
  observationPreview;
12276
- modelInputCapabilityValidator;
12277
12080
  modelInputResolver;
12278
12081
  eventToMessageConverter;
12279
12082
  defaultJudgeToolName;
@@ -12284,7 +12087,6 @@ var ChildRunInvoker = class {
12284
12087
  this.createLlmNode = dependencies.createLlmNode;
12285
12088
  this.toolRuntime = dependencies.toolRuntime;
12286
12089
  this.observationPreview = dependencies.observationPreview;
12287
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
12288
12090
  this.modelInputResolver = dependencies.modelInputResolver;
12289
12091
  this.eventToMessageConverter = dependencies.eventToMessageConverter;
12290
12092
  this.defaultJudgeToolName = dependencies.defaultJudgeToolName;
@@ -12547,7 +12349,6 @@ var ChildRunInvoker = class {
12547
12349
  observationPreview: this.observationPreview,
12548
12350
  telemetryPort: this.telemetryPort,
12549
12351
  auditPort: this.auditPort,
12550
- modelInputCapabilityValidator: this.modelInputCapabilityValidator,
12551
12352
  modelInputResolver: this.modelInputResolver
12552
12353
  }));
12553
12354
  graph.registerNode(new WaitUserNode({ auditPort: this.auditPort }));
@@ -14657,7 +14458,6 @@ function createDefaultGraphExecutor(options) {
14657
14458
  observationPreview: options.observationPreview,
14658
14459
  auditPort: options.auditPort,
14659
14460
  telemetryPort: options.telemetryPort,
14660
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
14661
14461
  modelInputResolver: options.modelInputResolver
14662
14462
  }));
14663
14463
  executor2.registerNode(new WaitUserNode({ auditPort: options.auditPort }));
@@ -14696,7 +14496,6 @@ function createGraphLoopHarness(options) {
14696
14496
  maxSteps,
14697
14497
  auditPort: options.auditPort,
14698
14498
  telemetryPort: options.telemetryPort,
14699
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
14700
14499
  modelInputResolver: options.modelInputResolver
14701
14500
  });
14702
14501
  const local = {