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