@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/testkit.js CHANGED
@@ -4196,7 +4196,6 @@ var tickPipelineContextKeys = [
4196
4196
  "runtimeEventCommitPort",
4197
4197
  "modelId",
4198
4198
  "toolSchemas",
4199
- "toolModelInputRequirement",
4200
4199
  "toolCallStreamingPolicies",
4201
4200
  "llmOptions",
4202
4201
  "toolDefinitionTokens",
@@ -5317,7 +5316,6 @@ function createExecuteLlmStage(dependencies) {
5317
5316
  "outputProcessor",
5318
5317
  "modelId",
5319
5318
  "llmMessages",
5320
- "toolModelInputRequirement",
5321
5319
  "toolCallStreamingPolicies",
5322
5320
  "imageInputAdmissionEvidence",
5323
5321
  "llmOptions",
@@ -5376,7 +5374,6 @@ function createExecuteLlmStage(dependencies) {
5376
5374
  },
5377
5375
  {
5378
5376
  imageInputAdmissionEvidence: ctx.imageInputAdmissionEvidence,
5379
- additionalModelInputRequirement: ctx.toolModelInputRequirement,
5380
5377
  toolCallStreamingPolicies: ctx.toolCallStreamingPolicies,
5381
5378
  ...promptBudget && promptUsageMeasurementPolicy ? {
5382
5379
  measurePromptUsage: async (activeModelId, messages) => {
@@ -6361,29 +6358,6 @@ function createCommitContextCompactionStage() {
6361
6358
  });
6362
6359
  }
6363
6360
 
6364
- // src/runtime-kernel/graph-engine/functions/prepareModelCompatibleTools.ts
6365
- function prepareModelCompatibleTools(input) {
6366
- const schemas = [];
6367
- const requirements = [];
6368
- for (const schema of input.schemas) {
6369
- const definition = input.getToolDefinition(schema.function.name);
6370
- const requirement = definition?.modelInputRequirement;
6371
- const delivery = definition?.modelInputDelivery ?? "required";
6372
- const isRequired = delivery === "required";
6373
- if (requirement && isRequired && !evaluateModelInputCompatibility(input.model, requirement).compatible) {
6374
- continue;
6375
- }
6376
- schemas.push(schema);
6377
- if (requirement && isRequired) {
6378
- requirements.push(requirement);
6379
- }
6380
- }
6381
- return {
6382
- schemas: Object.freeze(schemas),
6383
- requirement: requirements.length > 0 ? mergeModelInputRequirements(...requirements) : EMPTY_MODEL_INPUT_REQUIREMENT
6384
- };
6385
- }
6386
-
6387
6361
  // src/runtime-kernel/graph-engine/tick-pipeline/stages/prepareCallStage.ts
6388
6362
  function createPrepareCallStage(dependencies) {
6389
6363
  return defineTickStage({
@@ -6401,7 +6375,6 @@ function createPrepareCallStage(dependencies) {
6401
6375
  writes: [
6402
6376
  "modelId",
6403
6377
  "toolSchemas",
6404
- "toolModelInputRequirement",
6405
6378
  "toolCallStreamingPolicies",
6406
6379
  "llmOptions",
6407
6380
  "toolDefinitionTokens"
@@ -6441,12 +6414,7 @@ function createPrepareCallStage(dependencies) {
6441
6414
  invocation: ctx.request
6442
6415
  });
6443
6416
  const modelConfig = dependencies.modelCatalog.getModelById(modelId);
6444
- const toolPreparation = prepareModelCompatibleTools({
6445
- schemas: candidateToolSchemas,
6446
- model: modelConfig,
6447
- getToolDefinition: (toolName) => dependencies.toolCatalog.getToolDefinition(toolName)
6448
- });
6449
- const toolSchemas = [...toolPreparation.schemas];
6417
+ const toolSchemas = [...candidateToolSchemas];
6450
6418
  const toolCallStreamingPolicies = deriveToolCallStreamingPolicies(
6451
6419
  toolSchemas,
6452
6420
  dependencies.toolCatalog
@@ -6490,7 +6458,6 @@ function createPrepareCallStage(dependencies) {
6490
6458
  return {
6491
6459
  modelId,
6492
6460
  toolSchemas,
6493
- toolModelInputRequirement: toolPreparation.requirement,
6494
6461
  toolCallStreamingPolicies,
6495
6462
  llmOptions,
6496
6463
  toolDefinitionTokens
@@ -6664,7 +6631,6 @@ var GraphAgentExecutor = class {
6664
6631
  modelId: "",
6665
6632
  toolSchemas: [],
6666
6633
  toolCallStreamingPolicies: {},
6667
- toolModelInputRequirement: void 0,
6668
6634
  llmOptions: {},
6669
6635
  toolDefinitionTokens: 0,
6670
6636
  llmMessages: [],
@@ -7916,10 +7882,6 @@ function parseToolModelInputDeclaration(value) {
7916
7882
  }
7917
7883
 
7918
7884
  // src/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.ts
7919
- var TOOL_RESULT_IMAGE_REQUIREMENT = {
7920
- requires_image_input: true,
7921
- placements: ["tool_result_image"]
7922
- };
7923
7885
  async function resolveToolModelInput(input) {
7924
7886
  if (!input.selections) {
7925
7887
  return void 0;
@@ -7940,16 +7902,6 @@ async function resolveToolModelInput(input) {
7940
7902
  if (parsed.data.some((reference, index) => reference.id !== input.selections?.[index]?.id)) {
7941
7903
  throw new ToolModelInputResolutionError("Tool model input resolver changed attachment identity or order.");
7942
7904
  }
7943
- if (!input.activeModelId) {
7944
- throw new ToolModelInputResolutionError("Missing successful LLM model for tool input validation.");
7945
- }
7946
- if (!input.capabilityValidator) {
7947
- throw new ToolModelInputResolutionError("Tool model input validator is not configured.");
7948
- }
7949
- input.capabilityValidator.assertCompatible({
7950
- activeModelId: input.activeModelId,
7951
- requirement: TOOL_RESULT_IMAGE_REQUIREMENT
7952
- });
7953
7905
  return Object.freeze(parsed.data.map((reference) => Object.freeze(reference)));
7954
7906
  }
7955
7907
 
@@ -8414,8 +8366,7 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
8414
8366
  "parentRunId",
8415
8367
  "childRunDepth",
8416
8368
  "childRunContextInjections",
8417
- "parentToolCallId",
8418
- "modelInputAdmission"
8369
+ "parentToolCallId"
8419
8370
  ];
8420
8371
  var TOOL_CONTEXT_RUNTIME_BINDINGS_KEY = /* @__PURE__ */ Symbol.for(
8421
8372
  "@linnlabs/linnkit/tool-context-runtime-bindings/v1"
@@ -8716,7 +8667,6 @@ var ToolNodeEventBridge = class {
8716
8667
 
8717
8668
  // src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
8718
8669
  var logger10 = new Logger("ToolNode");
8719
- var MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR = "tool.model_input.requirement_resolution_failed: Tool model input requirement could not be resolved";
8720
8670
  function parseToolArgs(call) {
8721
8671
  const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
8722
8672
  if (!rawArguments.trim()) {
@@ -8820,12 +8770,6 @@ function prepareToolExecution(params) {
8820
8770
  toolArgs,
8821
8771
  idempotencyKey
8822
8772
  });
8823
- const modelInputRequirement = resolveModelInputRequirement({
8824
- toolDefinition,
8825
- toolArgs,
8826
- hasProtocolError: protocolError !== void 0,
8827
- toolName
8828
- });
8829
8773
  return {
8830
8774
  call: params.call,
8831
8775
  toolName,
@@ -8834,30 +8778,9 @@ function prepareToolExecution(params) {
8834
8778
  toolArgs,
8835
8779
  protocolError,
8836
8780
  idempotencyKey,
8837
- ...modelInputRequirement.requirement ? { modelInputRequirement: modelInputRequirement.requirement } : {},
8838
- modelInputDelivery: toolDefinition?.modelInputDelivery ?? "required",
8839
- ...modelInputRequirement.error ? { modelInputRequirementError: modelInputRequirement.error } : {},
8840
8781
  bridge
8841
8782
  };
8842
8783
  }
8843
- function resolveModelInputRequirement(params) {
8844
- if (params.hasProtocolError) {
8845
- return {};
8846
- }
8847
- if (!params.toolDefinition?.resolveModelInputRequirement) {
8848
- return params.toolDefinition?.modelInputRequirement ? { requirement: params.toolDefinition.modelInputRequirement } : {};
8849
- }
8850
- try {
8851
- const requirement = params.toolDefinition.resolveModelInputRequirement(params.toolArgs);
8852
- return requirement ? { requirement } : {};
8853
- } catch (error) {
8854
- logger10.warn("dynamic model input requirement resolution failed", {
8855
- toolName: params.toolName,
8856
- errorName: error instanceof Error ? error.name : "UnknownError"
8857
- });
8858
- return { error: MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR };
8859
- }
8860
- }
8861
8784
  function attachWorkingHistoryView(params) {
8862
8785
  const historyEvents = parseRuntimeEvents(
8863
8786
  params.state.local?.history ?? []
@@ -9089,14 +9012,6 @@ function readToolObservationPolicy(local) {
9089
9012
  function readHistoryEvents(local) {
9090
9013
  return parseRuntimeEvents(local.history ?? []);
9091
9014
  }
9092
- function readLastSuccessfulLlmModelId(local) {
9093
- const executorLocal = local.executorLocal;
9094
- if (!isRecord9(executorLocal)) {
9095
- return void 0;
9096
- }
9097
- const value = executorLocal.lastSuccessfulLlmModelId;
9098
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
9099
- }
9100
9015
  function formatCapabilityError(error) {
9101
9016
  if (isRecord9(error)) {
9102
9017
  const codeValue = error.errorCode ?? error.code;
@@ -9108,29 +9023,12 @@ function formatCapabilityError(error) {
9108
9023
  }
9109
9024
  return error instanceof Error ? error.message : String(error);
9110
9025
  }
9111
- function bindModelInputAdmission(input) {
9112
- input.context.modelInputAdmission = Object.freeze({
9113
- requirement: Object.freeze({
9114
- ...input.requirement,
9115
- placements: Object.freeze([...input.requirement.placements])
9116
- }),
9117
- delivery: input.delivery,
9118
- admitted: input.admitted
9119
- });
9120
- }
9121
- function isOptionalImageInputIncompatibility(reason) {
9122
- return reason === "image_input_unsupported" || reason === "placement_unsupported";
9123
- }
9124
- function shouldDeliverToolModelInput(input) {
9125
- return input.delivery === "required" || input.context.modelInputAdmission?.admitted === true;
9126
- }
9127
9026
  var ToolNode = class {
9128
9027
  id = "tool";
9129
9028
  toolRuntime;
9130
9029
  observationPreview;
9131
9030
  telemetryPort;
9132
9031
  auditPort;
9133
- modelInputCapabilityValidator;
9134
9032
  modelInputResolver;
9135
9033
  idempotencyInFlight = /* @__PURE__ */ new Map();
9136
9034
  constructor(dependencies) {
@@ -9138,7 +9036,6 @@ var ToolNode = class {
9138
9036
  this.observationPreview = dependencies.observationPreview;
9139
9037
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
9140
9038
  this.auditPort = dependencies.auditPort ?? noopAudit;
9141
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
9142
9039
  this.modelInputResolver = dependencies.modelInputResolver;
9143
9040
  }
9144
9041
  /**
@@ -9304,7 +9201,6 @@ var ToolNode = class {
9304
9201
  logger11.warn("no tool name found in call");
9305
9202
  return { kind: "yield", events: [] };
9306
9203
  }
9307
- delete prepared.toolContext.modelInputAdmission;
9308
9204
  if (typeof execution.protocolError === "string") {
9309
9205
  return this.handleError({
9310
9206
  ...prepared,
@@ -9322,88 +9218,6 @@ var ToolNode = class {
9322
9218
  bridge: execution.bridge
9323
9219
  });
9324
9220
  }
9325
- if (typeof execution.modelInputRequirementError === "string") {
9326
- return this.handleError({
9327
- ...prepared,
9328
- calls,
9329
- call,
9330
- toolName: execution.toolName,
9331
- toolCallId: execution.toolCallId,
9332
- toolArgs: execution.toolArgs,
9333
- exec: {
9334
- success: false,
9335
- error: execution.modelInputRequirementError,
9336
- errorKind: "capability",
9337
- durationMs: 0
9338
- },
9339
- bridge: execution.bridge
9340
- });
9341
- }
9342
- if (execution.modelInputRequirement?.requires_image_input === true) {
9343
- const activeModelId = readLastSuccessfulLlmModelId(prepared.local);
9344
- let capabilityError;
9345
- let admitted = true;
9346
- if (!activeModelId) {
9347
- capabilityError = "llm.unsupported_capability: missing successful LLM model for tool input validation";
9348
- } else if (!this.modelInputCapabilityValidator) {
9349
- capabilityError = "llm.unsupported_capability: tool model input validator is not configured";
9350
- } else {
9351
- const validationInput = {
9352
- activeModelId,
9353
- requirement: execution.modelInputRequirement
9354
- };
9355
- if (execution.modelInputDelivery === "when_supported") {
9356
- try {
9357
- const compatibility = this.modelInputCapabilityValidator.evaluate(validationInput);
9358
- if (!compatibility.compatible) {
9359
- if (isOptionalImageInputIncompatibility(compatibility.reason)) {
9360
- admitted = false;
9361
- logger11.debug("optional tool model input omitted for incompatible active model", {
9362
- toolName: execution.toolName,
9363
- activeModelId,
9364
- reason: compatibility.reason,
9365
- placements: execution.modelInputRequirement.placements
9366
- });
9367
- } else {
9368
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
9369
- capabilityError = "llm.unsupported_capability: active model is not eligible";
9370
- }
9371
- }
9372
- } catch (error) {
9373
- capabilityError = formatCapabilityError(error);
9374
- }
9375
- } else {
9376
- try {
9377
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
9378
- } catch (error) {
9379
- capabilityError = formatCapabilityError(error);
9380
- }
9381
- }
9382
- }
9383
- if (capabilityError) {
9384
- return this.handleError({
9385
- ...prepared,
9386
- calls,
9387
- call,
9388
- toolName: execution.toolName,
9389
- toolCallId: execution.toolCallId,
9390
- toolArgs: execution.toolArgs,
9391
- exec: {
9392
- success: false,
9393
- error: capabilityError,
9394
- errorKind: "capability",
9395
- durationMs: 0
9396
- },
9397
- bridge: execution.bridge
9398
- });
9399
- }
9400
- bindModelInputAdmission({
9401
- context: prepared.toolContext,
9402
- requirement: execution.modelInputRequirement,
9403
- delivery: execution.modelInputDelivery,
9404
- admitted
9405
- });
9406
- }
9407
9221
  await this.emitToolDecisionAudit({
9408
9222
  action: "tool.allow",
9409
9223
  toolName: execution.toolName,
@@ -9455,21 +9269,15 @@ var ToolNode = class {
9455
9269
  bridge: execution.bridge
9456
9270
  });
9457
9271
  }
9458
- const deliverModelInput = shouldDeliverToolModelInput({
9459
- context: prepared.toolContext,
9460
- delivery: execution.modelInputDelivery
9461
- });
9462
- let attachments = deliverModelInput ? exec.cachedAttachments : void 0;
9272
+ let attachments = exec.cachedAttachments;
9463
9273
  try {
9464
- if (deliverModelInput && !attachments) {
9274
+ if (!attachments) {
9465
9275
  attachments = await resolveToolModelInput({
9466
- activeModelId: readLastSuccessfulLlmModelId(prepared.local),
9467
9276
  toolName: execution.toolName,
9468
9277
  toolCallId: execution.toolCallId,
9469
9278
  selections: contract.modelInputAttachments,
9470
9279
  context: prepared.toolContext,
9471
- resolver: this.modelInputResolver,
9472
- capabilityValidator: this.modelInputCapabilityValidator
9280
+ resolver: this.modelInputResolver
9473
9281
  });
9474
9282
  }
9475
9283
  } catch (error) {
@@ -10178,10 +9986,6 @@ function formatUnknownToolArguments(fields, allowedFields) {
10178
9986
  // src/runtime-kernel/tools/toolContracts.ts
10179
9987
  var BaseTool = class {
10180
9988
  idempotency;
10181
- modelInputRequirement;
10182
- /** 模型输入是工具成功的必要结果,还是仅在当前模型支持时提供的增强反馈。 */
10183
- modelInputDelivery;
10184
- resolveModelInputRequirement;
10185
9989
  streaming;
10186
9990
  getExecutionSummary(output) {
10187
9991
  const FULL_CONTENT_THRESHOLD = 200;
@@ -12459,7 +12263,6 @@ var ChildRunInvoker = class {
12459
12263
  createLlmNode;
12460
12264
  toolRuntime;
12461
12265
  observationPreview;
12462
- modelInputCapabilityValidator;
12463
12266
  modelInputResolver;
12464
12267
  eventToMessageConverter;
12465
12268
  defaultJudgeToolName;
@@ -12470,7 +12273,6 @@ var ChildRunInvoker = class {
12470
12273
  this.createLlmNode = dependencies.createLlmNode;
12471
12274
  this.toolRuntime = dependencies.toolRuntime;
12472
12275
  this.observationPreview = dependencies.observationPreview;
12473
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
12474
12276
  this.modelInputResolver = dependencies.modelInputResolver;
12475
12277
  this.eventToMessageConverter = dependencies.eventToMessageConverter;
12476
12278
  this.defaultJudgeToolName = dependencies.defaultJudgeToolName;
@@ -12733,7 +12535,6 @@ var ChildRunInvoker = class {
12733
12535
  observationPreview: this.observationPreview,
12734
12536
  telemetryPort: this.telemetryPort,
12735
12537
  auditPort: this.auditPort,
12736
- modelInputCapabilityValidator: this.modelInputCapabilityValidator,
12737
12538
  modelInputResolver: this.modelInputResolver
12738
12539
  }));
12739
12540
  graph.registerNode(new WaitUserNode({ auditPort: this.auditPort }));
@@ -14843,7 +14644,6 @@ function createDefaultGraphExecutor(options) {
14843
14644
  observationPreview: options.observationPreview,
14844
14645
  auditPort: options.auditPort,
14845
14646
  telemetryPort: options.telemetryPort,
14846
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
14847
14647
  modelInputResolver: options.modelInputResolver
14848
14648
  }));
14849
14649
  executor2.registerNode(new WaitUserNode({ auditPort: options.auditPort }));
@@ -14882,7 +14682,6 @@ function createGraphLoopHarness(options) {
14882
14682
  maxSteps,
14883
14683
  auditPort: options.auditPort,
14884
14684
  telemetryPort: options.telemetryPort,
14885
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
14886
14685
  modelInputResolver: options.modelInputResolver
14887
14686
  });
14888
14687
  const local = {