@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
@@ -4215,7 +4215,6 @@ var tickPipelineContextKeys = [
4215
4215
  "runtimeEventCommitPort",
4216
4216
  "modelId",
4217
4217
  "toolSchemas",
4218
- "toolModelInputRequirement",
4219
4218
  "toolCallStreamingPolicies",
4220
4219
  "llmOptions",
4221
4220
  "toolDefinitionTokens",
@@ -5118,7 +5117,6 @@ function createExecuteLlmStage(dependencies) {
5118
5117
  "outputProcessor",
5119
5118
  "modelId",
5120
5119
  "llmMessages",
5121
- "toolModelInputRequirement",
5122
5120
  "toolCallStreamingPolicies",
5123
5121
  "imageInputAdmissionEvidence",
5124
5122
  "llmOptions",
@@ -5177,7 +5175,6 @@ function createExecuteLlmStage(dependencies) {
5177
5175
  },
5178
5176
  {
5179
5177
  imageInputAdmissionEvidence: ctx.imageInputAdmissionEvidence,
5180
- additionalModelInputRequirement: ctx.toolModelInputRequirement,
5181
5178
  toolCallStreamingPolicies: ctx.toolCallStreamingPolicies,
5182
5179
  ...promptBudget && promptUsageMeasurementPolicy ? {
5183
5180
  measurePromptUsage: async (activeModelId, messages) => {
@@ -6162,29 +6159,6 @@ function createCommitContextCompactionStage() {
6162
6159
  });
6163
6160
  }
6164
6161
 
6165
- // src/runtime-kernel/graph-engine/functions/prepareModelCompatibleTools.ts
6166
- function prepareModelCompatibleTools(input) {
6167
- const schemas = [];
6168
- const requirements = [];
6169
- for (const schema of input.schemas) {
6170
- const definition = input.getToolDefinition(schema.function.name);
6171
- const requirement = definition?.modelInputRequirement;
6172
- const delivery = definition?.modelInputDelivery ?? "required";
6173
- const isRequired = delivery === "required";
6174
- if (requirement && isRequired && !evaluateModelInputCompatibility(input.model, requirement).compatible) {
6175
- continue;
6176
- }
6177
- schemas.push(schema);
6178
- if (requirement && isRequired) {
6179
- requirements.push(requirement);
6180
- }
6181
- }
6182
- return {
6183
- schemas: Object.freeze(schemas),
6184
- requirement: requirements.length > 0 ? mergeModelInputRequirements(...requirements) : EMPTY_MODEL_INPUT_REQUIREMENT
6185
- };
6186
- }
6187
-
6188
6162
  // src/runtime-kernel/graph-engine/tick-pipeline/stages/prepareCallStage.ts
6189
6163
  function createPrepareCallStage(dependencies) {
6190
6164
  return defineTickStage({
@@ -6202,7 +6176,6 @@ function createPrepareCallStage(dependencies) {
6202
6176
  writes: [
6203
6177
  "modelId",
6204
6178
  "toolSchemas",
6205
- "toolModelInputRequirement",
6206
6179
  "toolCallStreamingPolicies",
6207
6180
  "llmOptions",
6208
6181
  "toolDefinitionTokens"
@@ -6242,12 +6215,7 @@ function createPrepareCallStage(dependencies) {
6242
6215
  invocation: ctx.request
6243
6216
  });
6244
6217
  const modelConfig = dependencies.modelCatalog.getModelById(modelId);
6245
- const toolPreparation = prepareModelCompatibleTools({
6246
- schemas: candidateToolSchemas,
6247
- model: modelConfig,
6248
- getToolDefinition: (toolName) => dependencies.toolCatalog.getToolDefinition(toolName)
6249
- });
6250
- const toolSchemas = [...toolPreparation.schemas];
6218
+ const toolSchemas = [...candidateToolSchemas];
6251
6219
  const toolCallStreamingPolicies = deriveToolCallStreamingPolicies(
6252
6220
  toolSchemas,
6253
6221
  dependencies.toolCatalog
@@ -6291,7 +6259,6 @@ function createPrepareCallStage(dependencies) {
6291
6259
  return {
6292
6260
  modelId,
6293
6261
  toolSchemas,
6294
- toolModelInputRequirement: toolPreparation.requirement,
6295
6262
  toolCallStreamingPolicies,
6296
6263
  llmOptions,
6297
6264
  toolDefinitionTokens
@@ -6465,7 +6432,6 @@ var GraphAgentExecutor = class {
6465
6432
  modelId: "",
6466
6433
  toolSchemas: [],
6467
6434
  toolCallStreamingPolicies: {},
6468
- toolModelInputRequirement: void 0,
6469
6435
  llmOptions: {},
6470
6436
  toolDefinitionTokens: 0,
6471
6437
  llmMessages: [],
@@ -7717,10 +7683,6 @@ function parseToolModelInputDeclaration(value) {
7717
7683
  }
7718
7684
 
7719
7685
  // src/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.ts
7720
- var TOOL_RESULT_IMAGE_REQUIREMENT = {
7721
- requires_image_input: true,
7722
- placements: ["tool_result_image"]
7723
- };
7724
7686
  async function resolveToolModelInput(input) {
7725
7687
  if (!input.selections) {
7726
7688
  return void 0;
@@ -7741,16 +7703,6 @@ async function resolveToolModelInput(input) {
7741
7703
  if (parsed.data.some((reference, index) => reference.id !== input.selections?.[index]?.id)) {
7742
7704
  throw new ToolModelInputResolutionError("Tool model input resolver changed attachment identity or order.");
7743
7705
  }
7744
- if (!input.activeModelId) {
7745
- throw new ToolModelInputResolutionError("Missing successful LLM model for tool input validation.");
7746
- }
7747
- if (!input.capabilityValidator) {
7748
- throw new ToolModelInputResolutionError("Tool model input validator is not configured.");
7749
- }
7750
- input.capabilityValidator.assertCompatible({
7751
- activeModelId: input.activeModelId,
7752
- requirement: TOOL_RESULT_IMAGE_REQUIREMENT
7753
- });
7754
7706
  return Object.freeze(parsed.data.map((reference) => Object.freeze(reference)));
7755
7707
  }
7756
7708
 
@@ -8456,7 +8408,6 @@ var ToolNodeEventBridge = class {
8456
8408
 
8457
8409
  // src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
8458
8410
  var logger10 = new Logger("ToolNode");
8459
- var MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR = "tool.model_input.requirement_resolution_failed: Tool model input requirement could not be resolved";
8460
8411
  function parseToolArgs(call) {
8461
8412
  const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
8462
8413
  if (!rawArguments.trim()) {
@@ -8560,12 +8511,6 @@ function prepareToolExecution(params) {
8560
8511
  toolArgs,
8561
8512
  idempotencyKey
8562
8513
  });
8563
- const modelInputRequirement = resolveModelInputRequirement({
8564
- toolDefinition,
8565
- toolArgs,
8566
- hasProtocolError: protocolError !== void 0,
8567
- toolName
8568
- });
8569
8514
  return {
8570
8515
  call: params.call,
8571
8516
  toolName,
@@ -8574,30 +8519,9 @@ function prepareToolExecution(params) {
8574
8519
  toolArgs,
8575
8520
  protocolError,
8576
8521
  idempotencyKey,
8577
- ...modelInputRequirement.requirement ? { modelInputRequirement: modelInputRequirement.requirement } : {},
8578
- modelInputDelivery: toolDefinition?.modelInputDelivery ?? "required",
8579
- ...modelInputRequirement.error ? { modelInputRequirementError: modelInputRequirement.error } : {},
8580
8522
  bridge
8581
8523
  };
8582
8524
  }
8583
- function resolveModelInputRequirement(params) {
8584
- if (params.hasProtocolError) {
8585
- return {};
8586
- }
8587
- if (!params.toolDefinition?.resolveModelInputRequirement) {
8588
- return params.toolDefinition?.modelInputRequirement ? { requirement: params.toolDefinition.modelInputRequirement } : {};
8589
- }
8590
- try {
8591
- const requirement = params.toolDefinition.resolveModelInputRequirement(params.toolArgs);
8592
- return requirement ? { requirement } : {};
8593
- } catch (error) {
8594
- logger10.warn("dynamic model input requirement resolution failed", {
8595
- toolName: params.toolName,
8596
- errorName: error instanceof Error ? error.name : "UnknownError"
8597
- });
8598
- return { error: MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR };
8599
- }
8600
- }
8601
8525
  function attachWorkingHistoryView(params) {
8602
8526
  const historyEvents = parseRuntimeEvents(
8603
8527
  params.state.local?.history ?? []
@@ -8829,14 +8753,6 @@ function readToolObservationPolicy(local) {
8829
8753
  function readHistoryEvents(local) {
8830
8754
  return parseRuntimeEvents(local.history ?? []);
8831
8755
  }
8832
- function readLastSuccessfulLlmModelId(local) {
8833
- const executorLocal = local.executorLocal;
8834
- if (!isRecord9(executorLocal)) {
8835
- return void 0;
8836
- }
8837
- const value = executorLocal.lastSuccessfulLlmModelId;
8838
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
8839
- }
8840
8756
  function formatCapabilityError(error) {
8841
8757
  if (isRecord9(error)) {
8842
8758
  const codeValue = error.errorCode ?? error.code;
@@ -8848,29 +8764,12 @@ function formatCapabilityError(error) {
8848
8764
  }
8849
8765
  return error instanceof Error ? error.message : String(error);
8850
8766
  }
8851
- function bindModelInputAdmission(input) {
8852
- input.context.modelInputAdmission = Object.freeze({
8853
- requirement: Object.freeze({
8854
- ...input.requirement,
8855
- placements: Object.freeze([...input.requirement.placements])
8856
- }),
8857
- delivery: input.delivery,
8858
- admitted: input.admitted
8859
- });
8860
- }
8861
- function isOptionalImageInputIncompatibility(reason) {
8862
- return reason === "image_input_unsupported" || reason === "placement_unsupported";
8863
- }
8864
- function shouldDeliverToolModelInput(input) {
8865
- return input.delivery === "required" || input.context.modelInputAdmission?.admitted === true;
8866
- }
8867
8767
  var ToolNode = class {
8868
8768
  id = "tool";
8869
8769
  toolRuntime;
8870
8770
  observationPreview;
8871
8771
  telemetryPort;
8872
8772
  auditPort;
8873
- modelInputCapabilityValidator;
8874
8773
  modelInputResolver;
8875
8774
  idempotencyInFlight = /* @__PURE__ */ new Map();
8876
8775
  constructor(dependencies) {
@@ -8878,7 +8777,6 @@ var ToolNode = class {
8878
8777
  this.observationPreview = dependencies.observationPreview;
8879
8778
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
8880
8779
  this.auditPort = dependencies.auditPort ?? noopAudit;
8881
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
8882
8780
  this.modelInputResolver = dependencies.modelInputResolver;
8883
8781
  }
8884
8782
  /**
@@ -9044,7 +8942,6 @@ var ToolNode = class {
9044
8942
  logger11.warn("no tool name found in call");
9045
8943
  return { kind: "yield", events: [] };
9046
8944
  }
9047
- delete prepared.toolContext.modelInputAdmission;
9048
8945
  if (typeof execution.protocolError === "string") {
9049
8946
  return this.handleError({
9050
8947
  ...prepared,
@@ -9062,88 +8959,6 @@ var ToolNode = class {
9062
8959
  bridge: execution.bridge
9063
8960
  });
9064
8961
  }
9065
- if (typeof execution.modelInputRequirementError === "string") {
9066
- return this.handleError({
9067
- ...prepared,
9068
- calls,
9069
- call,
9070
- toolName: execution.toolName,
9071
- toolCallId: execution.toolCallId,
9072
- toolArgs: execution.toolArgs,
9073
- exec: {
9074
- success: false,
9075
- error: execution.modelInputRequirementError,
9076
- errorKind: "capability",
9077
- durationMs: 0
9078
- },
9079
- bridge: execution.bridge
9080
- });
9081
- }
9082
- if (execution.modelInputRequirement?.requires_image_input === true) {
9083
- const activeModelId = readLastSuccessfulLlmModelId(prepared.local);
9084
- let capabilityError;
9085
- let admitted = true;
9086
- if (!activeModelId) {
9087
- capabilityError = "llm.unsupported_capability: missing successful LLM model for tool input validation";
9088
- } else if (!this.modelInputCapabilityValidator) {
9089
- capabilityError = "llm.unsupported_capability: tool model input validator is not configured";
9090
- } else {
9091
- const validationInput = {
9092
- activeModelId,
9093
- requirement: execution.modelInputRequirement
9094
- };
9095
- if (execution.modelInputDelivery === "when_supported") {
9096
- try {
9097
- const compatibility = this.modelInputCapabilityValidator.evaluate(validationInput);
9098
- if (!compatibility.compatible) {
9099
- if (isOptionalImageInputIncompatibility(compatibility.reason)) {
9100
- admitted = false;
9101
- logger11.debug("optional tool model input omitted for incompatible active model", {
9102
- toolName: execution.toolName,
9103
- activeModelId,
9104
- reason: compatibility.reason,
9105
- placements: execution.modelInputRequirement.placements
9106
- });
9107
- } else {
9108
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
9109
- capabilityError = "llm.unsupported_capability: active model is not eligible";
9110
- }
9111
- }
9112
- } catch (error) {
9113
- capabilityError = formatCapabilityError(error);
9114
- }
9115
- } else {
9116
- try {
9117
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
9118
- } catch (error) {
9119
- capabilityError = formatCapabilityError(error);
9120
- }
9121
- }
9122
- }
9123
- if (capabilityError) {
9124
- return this.handleError({
9125
- ...prepared,
9126
- calls,
9127
- call,
9128
- toolName: execution.toolName,
9129
- toolCallId: execution.toolCallId,
9130
- toolArgs: execution.toolArgs,
9131
- exec: {
9132
- success: false,
9133
- error: capabilityError,
9134
- errorKind: "capability",
9135
- durationMs: 0
9136
- },
9137
- bridge: execution.bridge
9138
- });
9139
- }
9140
- bindModelInputAdmission({
9141
- context: prepared.toolContext,
9142
- requirement: execution.modelInputRequirement,
9143
- delivery: execution.modelInputDelivery,
9144
- admitted
9145
- });
9146
- }
9147
8962
  await this.emitToolDecisionAudit({
9148
8963
  action: "tool.allow",
9149
8964
  toolName: execution.toolName,
@@ -9195,21 +9010,15 @@ var ToolNode = class {
9195
9010
  bridge: execution.bridge
9196
9011
  });
9197
9012
  }
9198
- const deliverModelInput = shouldDeliverToolModelInput({
9199
- context: prepared.toolContext,
9200
- delivery: execution.modelInputDelivery
9201
- });
9202
- let attachments = deliverModelInput ? exec.cachedAttachments : void 0;
9013
+ let attachments = exec.cachedAttachments;
9203
9014
  try {
9204
- if (deliverModelInput && !attachments) {
9015
+ if (!attachments) {
9205
9016
  attachments = await resolveToolModelInput({
9206
- activeModelId: readLastSuccessfulLlmModelId(prepared.local),
9207
9017
  toolName: execution.toolName,
9208
9018
  toolCallId: execution.toolCallId,
9209
9019
  selections: contract.modelInputAttachments,
9210
9020
  context: prepared.toolContext,
9211
- resolver: this.modelInputResolver,
9212
- capabilityValidator: this.modelInputCapabilityValidator
9021
+ resolver: this.modelInputResolver
9213
9022
  });
9214
9023
  }
9215
9024
  } catch (error) {
@@ -13234,7 +13043,6 @@ function createDefaultGraphExecutor(options) {
13234
13043
  observationPreview: options.observationPreview,
13235
13044
  auditPort: options.auditPort,
13236
13045
  telemetryPort: options.telemetryPort,
13237
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
13238
13046
  modelInputResolver: options.modelInputResolver
13239
13047
  }));
13240
13048
  executor2.registerNode(new WaitUserNode({ auditPort: options.auditPort }));
@@ -13358,11 +13166,7 @@ var QuickstartMemoryToolRuntime = class {
13358
13166
  return {
13359
13167
  parameters: tool.parameters,
13360
13168
  validateArguments: (args) => tool["validateArguments"](args),
13361
- idempotency: tool.idempotency,
13362
- modelInputRequirement: tool.modelInputRequirement,
13363
- ...tool.resolveModelInputRequirement ? {
13364
- resolveModelInputRequirement: (args) => tool.resolveModelInputRequirement?.(args)
13365
- } : {}
13169
+ idempotency: tool.idempotency
13366
13170
  };
13367
13171
  }
13368
13172
  async executeTool(toolName, args, context) {