@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/cli.js CHANGED
@@ -4101,7 +4101,6 @@ var tickPipelineContextKeys = [
4101
4101
  "runtimeEventCommitPort",
4102
4102
  "modelId",
4103
4103
  "toolSchemas",
4104
- "toolModelInputRequirement",
4105
4104
  "toolCallStreamingPolicies",
4106
4105
  "llmOptions",
4107
4106
  "toolDefinitionTokens",
@@ -5004,7 +5003,6 @@ function createExecuteLlmStage(dependencies) {
5004
5003
  "outputProcessor",
5005
5004
  "modelId",
5006
5005
  "llmMessages",
5007
- "toolModelInputRequirement",
5008
5006
  "toolCallStreamingPolicies",
5009
5007
  "imageInputAdmissionEvidence",
5010
5008
  "llmOptions",
@@ -5063,7 +5061,6 @@ function createExecuteLlmStage(dependencies) {
5063
5061
  },
5064
5062
  {
5065
5063
  imageInputAdmissionEvidence: ctx.imageInputAdmissionEvidence,
5066
- additionalModelInputRequirement: ctx.toolModelInputRequirement,
5067
5064
  toolCallStreamingPolicies: ctx.toolCallStreamingPolicies,
5068
5065
  ...promptBudget && promptUsageMeasurementPolicy ? {
5069
5066
  measurePromptUsage: async (activeModelId, messages) => {
@@ -6048,29 +6045,6 @@ function createCommitContextCompactionStage() {
6048
6045
  });
6049
6046
  }
6050
6047
 
6051
- // src/runtime-kernel/graph-engine/functions/prepareModelCompatibleTools.ts
6052
- function prepareModelCompatibleTools(input) {
6053
- const schemas = [];
6054
- const requirements = [];
6055
- for (const schema of input.schemas) {
6056
- const definition = input.getToolDefinition(schema.function.name);
6057
- const requirement = definition?.modelInputRequirement;
6058
- const delivery = definition?.modelInputDelivery ?? "required";
6059
- const isRequired = delivery === "required";
6060
- if (requirement && isRequired && !evaluateModelInputCompatibility(input.model, requirement).compatible) {
6061
- continue;
6062
- }
6063
- schemas.push(schema);
6064
- if (requirement && isRequired) {
6065
- requirements.push(requirement);
6066
- }
6067
- }
6068
- return {
6069
- schemas: Object.freeze(schemas),
6070
- requirement: requirements.length > 0 ? mergeModelInputRequirements(...requirements) : EMPTY_MODEL_INPUT_REQUIREMENT
6071
- };
6072
- }
6073
-
6074
6048
  // src/runtime-kernel/graph-engine/tick-pipeline/stages/prepareCallStage.ts
6075
6049
  function createPrepareCallStage(dependencies) {
6076
6050
  return defineTickStage({
@@ -6088,7 +6062,6 @@ function createPrepareCallStage(dependencies) {
6088
6062
  writes: [
6089
6063
  "modelId",
6090
6064
  "toolSchemas",
6091
- "toolModelInputRequirement",
6092
6065
  "toolCallStreamingPolicies",
6093
6066
  "llmOptions",
6094
6067
  "toolDefinitionTokens"
@@ -6128,12 +6101,7 @@ function createPrepareCallStage(dependencies) {
6128
6101
  invocation: ctx.request
6129
6102
  });
6130
6103
  const modelConfig = dependencies.modelCatalog.getModelById(modelId);
6131
- const toolPreparation = prepareModelCompatibleTools({
6132
- schemas: candidateToolSchemas,
6133
- model: modelConfig,
6134
- getToolDefinition: (toolName) => dependencies.toolCatalog.getToolDefinition(toolName)
6135
- });
6136
- const toolSchemas = [...toolPreparation.schemas];
6104
+ const toolSchemas = [...candidateToolSchemas];
6137
6105
  const toolCallStreamingPolicies = deriveToolCallStreamingPolicies(
6138
6106
  toolSchemas,
6139
6107
  dependencies.toolCatalog
@@ -6177,7 +6145,6 @@ function createPrepareCallStage(dependencies) {
6177
6145
  return {
6178
6146
  modelId,
6179
6147
  toolSchemas,
6180
- toolModelInputRequirement: toolPreparation.requirement,
6181
6148
  toolCallStreamingPolicies,
6182
6149
  llmOptions,
6183
6150
  toolDefinitionTokens
@@ -6351,7 +6318,6 @@ var GraphAgentExecutor = class {
6351
6318
  modelId: "",
6352
6319
  toolSchemas: [],
6353
6320
  toolCallStreamingPolicies: {},
6354
- toolModelInputRequirement: void 0,
6355
6321
  llmOptions: {},
6356
6322
  toolDefinitionTokens: 0,
6357
6323
  llmMessages: [],
@@ -7603,10 +7569,6 @@ function parseToolModelInputDeclaration(value) {
7603
7569
  }
7604
7570
 
7605
7571
  // src/runtime-kernel/tools/model-input/orchestration/resolveToolModelInput.ts
7606
- var TOOL_RESULT_IMAGE_REQUIREMENT = {
7607
- requires_image_input: true,
7608
- placements: ["tool_result_image"]
7609
- };
7610
7572
  async function resolveToolModelInput(input) {
7611
7573
  if (!input.selections) {
7612
7574
  return void 0;
@@ -7627,16 +7589,6 @@ async function resolveToolModelInput(input) {
7627
7589
  if (parsed.data.some((reference, index) => reference.id !== input.selections?.[index]?.id)) {
7628
7590
  throw new ToolModelInputResolutionError("Tool model input resolver changed attachment identity or order.");
7629
7591
  }
7630
- if (!input.activeModelId) {
7631
- throw new ToolModelInputResolutionError("Missing successful LLM model for tool input validation.");
7632
- }
7633
- if (!input.capabilityValidator) {
7634
- throw new ToolModelInputResolutionError("Tool model input validator is not configured.");
7635
- }
7636
- input.capabilityValidator.assertCompatible({
7637
- activeModelId: input.activeModelId,
7638
- requirement: TOOL_RESULT_IMAGE_REQUIREMENT
7639
- });
7640
7592
  return Object.freeze(parsed.data.map((reference) => Object.freeze(reference)));
7641
7593
  }
7642
7594
 
@@ -8342,7 +8294,6 @@ var ToolNodeEventBridge = class {
8342
8294
 
8343
8295
  // src/runtime-kernel/graph-engine/nodes/toolNode.executionSetup.ts
8344
8296
  var logger10 = new Logger("ToolNode");
8345
- var MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR = "tool.model_input.requirement_resolution_failed: Tool model input requirement could not be resolved";
8346
8297
  function parseToolArgs(call) {
8347
8298
  const rawArguments = typeof call.function?.arguments === "string" ? call.function.arguments : "";
8348
8299
  if (!rawArguments.trim()) {
@@ -8446,12 +8397,6 @@ function prepareToolExecution(params) {
8446
8397
  toolArgs,
8447
8398
  idempotencyKey
8448
8399
  });
8449
- const modelInputRequirement = resolveModelInputRequirement({
8450
- toolDefinition,
8451
- toolArgs,
8452
- hasProtocolError: protocolError !== void 0,
8453
- toolName
8454
- });
8455
8400
  return {
8456
8401
  call: params.call,
8457
8402
  toolName,
@@ -8460,30 +8405,9 @@ function prepareToolExecution(params) {
8460
8405
  toolArgs,
8461
8406
  protocolError,
8462
8407
  idempotencyKey,
8463
- ...modelInputRequirement.requirement ? { modelInputRequirement: modelInputRequirement.requirement } : {},
8464
- modelInputDelivery: toolDefinition?.modelInputDelivery ?? "required",
8465
- ...modelInputRequirement.error ? { modelInputRequirementError: modelInputRequirement.error } : {},
8466
8408
  bridge
8467
8409
  };
8468
8410
  }
8469
- function resolveModelInputRequirement(params) {
8470
- if (params.hasProtocolError) {
8471
- return {};
8472
- }
8473
- if (!params.toolDefinition?.resolveModelInputRequirement) {
8474
- return params.toolDefinition?.modelInputRequirement ? { requirement: params.toolDefinition.modelInputRequirement } : {};
8475
- }
8476
- try {
8477
- const requirement = params.toolDefinition.resolveModelInputRequirement(params.toolArgs);
8478
- return requirement ? { requirement } : {};
8479
- } catch (error) {
8480
- logger10.warn("dynamic model input requirement resolution failed", {
8481
- toolName: params.toolName,
8482
- errorName: error instanceof Error ? error.name : "UnknownError"
8483
- });
8484
- return { error: MODEL_INPUT_REQUIREMENT_RESOLUTION_ERROR };
8485
- }
8486
- }
8487
8411
  function attachWorkingHistoryView(params) {
8488
8412
  const historyEvents = parseRuntimeEvents(
8489
8413
  params.state.local?.history ?? []
@@ -8715,14 +8639,6 @@ function readToolObservationPolicy(local) {
8715
8639
  function readHistoryEvents(local) {
8716
8640
  return parseRuntimeEvents(local.history ?? []);
8717
8641
  }
8718
- function readLastSuccessfulLlmModelId(local) {
8719
- const executorLocal = local.executorLocal;
8720
- if (!isRecord9(executorLocal)) {
8721
- return void 0;
8722
- }
8723
- const value = executorLocal.lastSuccessfulLlmModelId;
8724
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
8725
- }
8726
8642
  function formatCapabilityError(error) {
8727
8643
  if (isRecord9(error)) {
8728
8644
  const codeValue = error.errorCode ?? error.code;
@@ -8734,29 +8650,12 @@ function formatCapabilityError(error) {
8734
8650
  }
8735
8651
  return error instanceof Error ? error.message : String(error);
8736
8652
  }
8737
- function bindModelInputAdmission(input) {
8738
- input.context.modelInputAdmission = Object.freeze({
8739
- requirement: Object.freeze({
8740
- ...input.requirement,
8741
- placements: Object.freeze([...input.requirement.placements])
8742
- }),
8743
- delivery: input.delivery,
8744
- admitted: input.admitted
8745
- });
8746
- }
8747
- function isOptionalImageInputIncompatibility(reason) {
8748
- return reason === "image_input_unsupported" || reason === "placement_unsupported";
8749
- }
8750
- function shouldDeliverToolModelInput(input) {
8751
- return input.delivery === "required" || input.context.modelInputAdmission?.admitted === true;
8752
- }
8753
8653
  var ToolNode = class {
8754
8654
  id = "tool";
8755
8655
  toolRuntime;
8756
8656
  observationPreview;
8757
8657
  telemetryPort;
8758
8658
  auditPort;
8759
- modelInputCapabilityValidator;
8760
8659
  modelInputResolver;
8761
8660
  idempotencyInFlight = /* @__PURE__ */ new Map();
8762
8661
  constructor(dependencies) {
@@ -8764,7 +8663,6 @@ var ToolNode = class {
8764
8663
  this.observationPreview = dependencies.observationPreview;
8765
8664
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
8766
8665
  this.auditPort = dependencies.auditPort ?? noopAudit;
8767
- this.modelInputCapabilityValidator = dependencies.modelInputCapabilityValidator;
8768
8666
  this.modelInputResolver = dependencies.modelInputResolver;
8769
8667
  }
8770
8668
  /**
@@ -8930,7 +8828,6 @@ var ToolNode = class {
8930
8828
  logger11.warn("no tool name found in call");
8931
8829
  return { kind: "yield", events: [] };
8932
8830
  }
8933
- delete prepared.toolContext.modelInputAdmission;
8934
8831
  if (typeof execution.protocolError === "string") {
8935
8832
  return this.handleError({
8936
8833
  ...prepared,
@@ -8948,88 +8845,6 @@ var ToolNode = class {
8948
8845
  bridge: execution.bridge
8949
8846
  });
8950
8847
  }
8951
- if (typeof execution.modelInputRequirementError === "string") {
8952
- return this.handleError({
8953
- ...prepared,
8954
- calls,
8955
- call,
8956
- toolName: execution.toolName,
8957
- toolCallId: execution.toolCallId,
8958
- toolArgs: execution.toolArgs,
8959
- exec: {
8960
- success: false,
8961
- error: execution.modelInputRequirementError,
8962
- errorKind: "capability",
8963
- durationMs: 0
8964
- },
8965
- bridge: execution.bridge
8966
- });
8967
- }
8968
- if (execution.modelInputRequirement?.requires_image_input === true) {
8969
- const activeModelId = readLastSuccessfulLlmModelId(prepared.local);
8970
- let capabilityError;
8971
- let admitted = true;
8972
- if (!activeModelId) {
8973
- capabilityError = "llm.unsupported_capability: missing successful LLM model for tool input validation";
8974
- } else if (!this.modelInputCapabilityValidator) {
8975
- capabilityError = "llm.unsupported_capability: tool model input validator is not configured";
8976
- } else {
8977
- const validationInput = {
8978
- activeModelId,
8979
- requirement: execution.modelInputRequirement
8980
- };
8981
- if (execution.modelInputDelivery === "when_supported") {
8982
- try {
8983
- const compatibility = this.modelInputCapabilityValidator.evaluate(validationInput);
8984
- if (!compatibility.compatible) {
8985
- if (isOptionalImageInputIncompatibility(compatibility.reason)) {
8986
- admitted = false;
8987
- logger11.debug("optional tool model input omitted for incompatible active model", {
8988
- toolName: execution.toolName,
8989
- activeModelId,
8990
- reason: compatibility.reason,
8991
- placements: execution.modelInputRequirement.placements
8992
- });
8993
- } else {
8994
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
8995
- capabilityError = "llm.unsupported_capability: active model is not eligible";
8996
- }
8997
- }
8998
- } catch (error) {
8999
- capabilityError = formatCapabilityError(error);
9000
- }
9001
- } else {
9002
- try {
9003
- this.modelInputCapabilityValidator.assertCompatible(validationInput);
9004
- } catch (error) {
9005
- capabilityError = formatCapabilityError(error);
9006
- }
9007
- }
9008
- }
9009
- if (capabilityError) {
9010
- return this.handleError({
9011
- ...prepared,
9012
- calls,
9013
- call,
9014
- toolName: execution.toolName,
9015
- toolCallId: execution.toolCallId,
9016
- toolArgs: execution.toolArgs,
9017
- exec: {
9018
- success: false,
9019
- error: capabilityError,
9020
- errorKind: "capability",
9021
- durationMs: 0
9022
- },
9023
- bridge: execution.bridge
9024
- });
9025
- }
9026
- bindModelInputAdmission({
9027
- context: prepared.toolContext,
9028
- requirement: execution.modelInputRequirement,
9029
- delivery: execution.modelInputDelivery,
9030
- admitted
9031
- });
9032
- }
9033
8848
  await this.emitToolDecisionAudit({
9034
8849
  action: "tool.allow",
9035
8850
  toolName: execution.toolName,
@@ -9081,21 +8896,15 @@ var ToolNode = class {
9081
8896
  bridge: execution.bridge
9082
8897
  });
9083
8898
  }
9084
- const deliverModelInput = shouldDeliverToolModelInput({
9085
- context: prepared.toolContext,
9086
- delivery: execution.modelInputDelivery
9087
- });
9088
- let attachments = deliverModelInput ? exec.cachedAttachments : void 0;
8899
+ let attachments = exec.cachedAttachments;
9089
8900
  try {
9090
- if (deliverModelInput && !attachments) {
8901
+ if (!attachments) {
9091
8902
  attachments = await resolveToolModelInput({
9092
- activeModelId: readLastSuccessfulLlmModelId(prepared.local),
9093
8903
  toolName: execution.toolName,
9094
8904
  toolCallId: execution.toolCallId,
9095
8905
  selections: contract.modelInputAttachments,
9096
8906
  context: prepared.toolContext,
9097
- resolver: this.modelInputResolver,
9098
- capabilityValidator: this.modelInputCapabilityValidator
8907
+ resolver: this.modelInputResolver
9099
8908
  });
9100
8909
  }
9101
8910
  } catch (error) {
@@ -13120,7 +12929,6 @@ function createDefaultGraphExecutor(options) {
13120
12929
  observationPreview: options.observationPreview,
13121
12930
  auditPort: options.auditPort,
13122
12931
  telemetryPort: options.telemetryPort,
13123
- modelInputCapabilityValidator: options.modelInputCapabilityValidator,
13124
12932
  modelInputResolver: options.modelInputResolver
13125
12933
  }));
13126
12934
  executor2.registerNode(new WaitUserNode({ auditPort: options.auditPort }));
@@ -13244,11 +13052,7 @@ var QuickstartMemoryToolRuntime = class {
13244
13052
  return {
13245
13053
  parameters: tool.parameters,
13246
13054
  validateArguments: (args) => tool["validateArguments"](args),
13247
- idempotency: tool.idempotency,
13248
- modelInputRequirement: tool.modelInputRequirement,
13249
- ...tool.resolveModelInputRequirement ? {
13250
- resolveModelInputRequirement: (args) => tool.resolveModelInputRequirement?.(args)
13251
- } : {}
13055
+ idempotency: tool.idempotency
13252
13056
  };
13253
13057
  }
13254
13058
  async executeTool(toolName, args, context) {