@noetic-tools/core 5.20.0-next.1 → 5.21.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 (92) hide show
  1. package/dist/adapters/openrouter.d.ts +1 -48
  2. package/dist/adapters/openrouter.js +3 -204
  3. package/dist/builders/acp-agent-checks.d.ts +20 -0
  4. package/dist/builders/acp-agent-checks.js +68 -0
  5. package/dist/builders/acp-agent-tool.d.ts +4 -3
  6. package/dist/builders/acp-agent-tool.js +5 -2
  7. package/dist/builders/connection-ceiling.d.ts +13 -0
  8. package/dist/builders/connection-ceiling.js +17 -0
  9. package/dist/builders/document-entries.d.ts +13 -0
  10. package/dist/builders/document-entries.js +18 -0
  11. package/dist/builders/dynamic-workflow.d.ts +53 -8
  12. package/dist/builders/dynamic-workflow.js +53 -25
  13. package/dist/builders/mcp-url-pattern.d.ts +13 -0
  14. package/dist/builders/mcp-url-pattern.js +85 -0
  15. package/dist/builders/step-builders.d.ts +14 -6
  16. package/dist/builders/step-builders.js +25 -2
  17. package/dist/builders/workflow-acp-grants.d.ts +42 -0
  18. package/dist/builders/workflow-acp-grants.js +224 -0
  19. package/dist/builders/workflow-child-nodes.js +8 -0
  20. package/dist/builders/workflow-connection-nodes.d.ts +13 -3
  21. package/dist/builders/workflow-connection-nodes.js +129 -3
  22. package/dist/builders/workflow-connections.js +2 -1
  23. package/dist/builders/workflow-hydrator.d.ts +24 -1
  24. package/dist/builders/workflow-hydrator.js +8 -167
  25. package/dist/builders/workflow-mcp-servers.d.ts +44 -0
  26. package/dist/builders/workflow-mcp-servers.js +327 -0
  27. package/dist/builders/workflow-tool-entries.d.ts +84 -0
  28. package/dist/builders/workflow-tool-entries.js +216 -0
  29. package/dist/connections/durability.d.ts +11 -1
  30. package/dist/connections/durability.js +34 -0
  31. package/dist/connections/entries.d.ts +33 -0
  32. package/dist/connections/entries.js +118 -0
  33. package/dist/connections/errors.d.ts +6 -0
  34. package/dist/connections/errors.js +12 -0
  35. package/dist/connections/harness-wiring.d.ts +4 -4
  36. package/dist/connections/harness-wiring.js +1 -1
  37. package/dist/connections/in-memory-connection.d.ts +2 -0
  38. package/dist/connections/in-memory-connection.js +5 -0
  39. package/dist/connections/model-tools.d.ts +35 -12
  40. package/dist/connections/model-tools.js +348 -202
  41. package/dist/connections/registry-types.d.ts +7 -0
  42. package/dist/connections/registry.d.ts +35 -6
  43. package/dist/connections/registry.js +183 -39
  44. package/dist/connections/step-tools.d.ts +64 -0
  45. package/dist/connections/step-tools.js +154 -0
  46. package/dist/connections/views.d.ts +3 -2
  47. package/dist/connections/views.js +15 -6
  48. package/dist/harness/agent-harness.d.ts +11 -1
  49. package/dist/harness/agent-harness.js +69 -8
  50. package/dist/harness/connection-gate.d.ts +49 -8
  51. package/dist/harness/connection-gate.js +137 -26
  52. package/dist/harness/deps/interpreter.d.ts +3 -3
  53. package/dist/harness/deps/interpreter.js +3 -3
  54. package/dist/harness/harness-options.d.ts +4 -3
  55. package/dist/harness/model-call.d.ts +0 -1
  56. package/dist/harness/model-call.js +0 -48
  57. package/dist/harness/model-request.js +3 -1
  58. package/dist/harness/model-schema.d.ts +1 -19
  59. package/dist/harness/model-schema.js +0 -28
  60. package/dist/harness/model-tool-round.js +2 -2
  61. package/dist/index.d.ts +5 -5
  62. package/dist/index.js +1 -1
  63. package/dist/interpreter/acp-events.d.ts +25 -1
  64. package/dist/interpreter/acp-events.js +53 -1
  65. package/dist/interpreter/acp-layers.d.ts +20 -0
  66. package/dist/interpreter/acp-layers.js +55 -0
  67. package/dist/interpreter/acp-tools.d.ts +108 -0
  68. package/dist/interpreter/acp-tools.js +462 -0
  69. package/dist/interpreter/collect-tools.d.ts +28 -0
  70. package/dist/interpreter/collect-tools.js +112 -15
  71. package/dist/interpreter/connection-steps.d.ts +0 -2
  72. package/dist/interpreter/connection-steps.js +30 -8
  73. package/dist/interpreter/execute-acp-agent.js +263 -72
  74. package/dist/interpreter/execute-action.d.ts +76 -1
  75. package/dist/interpreter/execute-action.js +35 -42
  76. package/dist/interpreter/execute.d.ts +2 -0
  77. package/dist/interpreter/execute.js +24 -1
  78. package/dist/interpreter/verify-host.js +2 -1
  79. package/dist/runtime/tool-call.d.ts +67 -0
  80. package/dist/runtime/tool-call.js +244 -0
  81. package/dist/runtime/tool-context.d.ts +1 -2
  82. package/dist/runtime/tool-context.js +6 -2
  83. package/dist/schemas/workflow.d.ts +1 -1
  84. package/dist/types/connection-entry.d.ts +22 -0
  85. package/dist/types/connection-entry.js +8 -0
  86. package/dist/util/harness-internals.d.ts +2 -0
  87. package/dist/util/root-context.d.ts +3 -0
  88. package/dist/util/root-context.js +8 -0
  89. package/dist/util/tool-name.d.ts +8 -0
  90. package/dist/util/tool-name.js +10 -0
  91. package/package.json +3 -3
  92. package/schema/noetic-workflow.schema.json +498 -128
@@ -11,7 +11,6 @@ import { buildItemSchemaRegistry } from './model-schema.js';
11
11
  import { awaitWithAbort, hasUsableResponseOutput, noteStreamGeneration, pipeStreamEventsToBroadcaster, providerTerminalError, } from './model-stream.js';
12
12
  import { hasFunctionCalls, replayOutput, runToolRound } from './model-tool-round.js';
13
13
  import { openSteerInbox } from './steer-inbox.js';
14
- const MAX_TOOL_ROUNDS = 32;
15
14
  const MAX_RECOVERY_CONTINUATIONS = 3;
16
15
  const EPHEMERAL_CONTINUE_INPUT = 'continue';
17
16
  function itemIds(items) {
@@ -190,7 +189,6 @@ export class AgentHarnessModelCaller {
190
189
  : undefined;
191
190
  let round = 0;
192
191
  let invalidRecoveryContinuations = 0;
193
- let toolLimitRecoveryContinuations = 0;
194
192
  let useEphemeralContinue = false;
195
193
  const drains = drainsOf(request.ctx);
196
194
  const replaySchemas = buildItemSchemaRegistry({
@@ -323,15 +321,6 @@ export class AgentHarnessModelCaller {
323
321
  await recordRound(spend.keep());
324
322
  }
325
323
  round += 1;
326
- const replayLimit = this.handleToolRoundLimit({
327
- round,
328
- toolLimitRecoveryContinuations,
329
- emitIfAllowed: prepared.emitIfAllowed,
330
- });
331
- if (replayLimit.kind === 'continue') {
332
- toolLimitRecoveryContinuations = replayLimit.toolLimitRecoveryContinuations;
333
- useEphemeralContinue = true;
334
- }
335
324
  continue;
336
325
  }
337
326
  if (marks.round !== round) {
@@ -552,15 +541,6 @@ export class AgentHarnessModelCaller {
552
541
  });
553
542
  await recordRound(bill);
554
543
  round += 1;
555
- const cutLimitRecovery = this.handleToolRoundLimit({
556
- round,
557
- toolLimitRecoveryContinuations,
558
- emitIfAllowed: prepared.emitIfAllowed,
559
- });
560
- if (cutLimitRecovery.kind === 'continue') {
561
- toolLimitRecoveryContinuations = cutLimitRecovery.toolLimitRecoveryContinuations;
562
- useEphemeralContinue = true;
563
- }
564
544
  continue;
565
545
  }
566
546
  const recovery = await rejectRound(() => this.handleModelRecovery({
@@ -619,15 +599,6 @@ export class AgentHarnessModelCaller {
619
599
  }
620
600
  await recordRound(bill);
621
601
  round += 1;
622
- const limitRecovery = this.handleToolRoundLimit({
623
- round,
624
- toolLimitRecoveryContinuations,
625
- emitIfAllowed: prepared.emitIfAllowed,
626
- });
627
- if (limitRecovery.kind === 'continue') {
628
- toolLimitRecoveryContinuations = limitRecovery.toolLimitRecoveryContinuations;
629
- useEphemeralContinue = true;
630
- }
631
602
  }
632
603
  return {
633
604
  items: allItems,
@@ -733,23 +704,4 @@ export class AgentHarnessModelCaller {
733
704
  invalidRecoveryContinuations: next,
734
705
  };
735
706
  }
736
- handleToolRoundLimit(params) {
737
- if (params.round < MAX_TOOL_ROUNDS) {
738
- return {
739
- kind: 'ok',
740
- };
741
- }
742
- params.emitIfAllowed('tool_round_limit_exceeded', {
743
- maxToolRounds: MAX_TOOL_ROUNDS,
744
- attempt: params.toolLimitRecoveryContinuations + 1,
745
- maxAttempts: MAX_RECOVERY_CONTINUATIONS,
746
- });
747
- if (params.toolLimitRecoveryContinuations >= MAX_RECOVERY_CONTINUATIONS) {
748
- throw new Error(`LLM exceeded maximum tool rounds (${MAX_TOOL_ROUNDS})`);
749
- }
750
- return {
751
- kind: 'continue',
752
- toolLimitRecoveryContinuations: params.toolLimitRecoveryContinuations + 1,
753
- };
754
- }
755
707
  }
@@ -1,7 +1,9 @@
1
1
  import { frameworkCast, NoeticConfigError, ToolChoiceMode } from '@noetic-tools/types';
2
2
  import { serverTool } from '@openrouter/agent';
3
- import { convertTools, extractSystemInstruction, resolveWireJsonSchema, sanitizeToolNameForWire, } from '../adapters/openrouter.js';
3
+ import { convertTools, extractSystemInstruction } from '../adapters/openrouter.js';
4
4
  import { emitFrameworkEvent, getBroadcaster, shouldEmit } from '../runtime/broadcaster-utils.js';
5
+ import { resolveWireJsonSchema } from '../runtime/tool-call.js';
6
+ import { sanitizeToolNameForWire } from '../util/tool-name.js';
5
7
  /**
6
8
  * Shapes a `callModel` request for the wire: system instructions, the SDK tool
7
9
  * list, the per-round tool choice, and the structured-output text format.
@@ -1,25 +1,7 @@
1
1
  import type { ContextLayer } from '@noetic-tools/context';
2
- import type { Item, ItemSchemaRegistry, Tool } from '@noetic-tools/types';
2
+ import type { ItemSchemaRegistry, Tool } from '@noetic-tools/types';
3
3
  export declare function buildItemSchemaRegistry({ base, layers, tools, }: {
4
4
  base: ItemSchemaRegistry;
5
5
  layers?: ReadonlyArray<ContextLayer>;
6
6
  tools?: ReadonlyArray<Tool>;
7
7
  }): ItemSchemaRegistry;
8
- /**
9
- * Build and validate a `function_call_output` item for a tool result.
10
- *
11
- * `roundItemSchemas` must be the OWNER-SCOPED registry for the called tool
12
- * (harness base extended with only that tool's `itemSchemas`), so one tool's
13
- * `toolResults` schemas never reject a sibling tool's result items. Tools
14
- * without `itemSchemas` fall back to the base structural parse.
15
- */
16
- export declare function createToolResultItem({ output, callId, roundItemSchemas, tool, callItem, args, result, error, }: {
17
- output: string;
18
- callId: string;
19
- roundItemSchemas: ItemSchemaRegistry;
20
- tool?: Tool;
21
- callItem?: Item;
22
- args?: unknown;
23
- result?: unknown;
24
- error?: boolean;
25
- }): Item;
@@ -24,31 +24,3 @@ export function buildItemSchemaRegistry({ base, layers, tools, }) {
24
24
  .extend(collectLayerItemSchemaExtensions(layers))
25
25
  .extend(collectToolItemSchemaExtensions(tools));
26
26
  }
27
- /**
28
- * Build and validate a `function_call_output` item for a tool result.
29
- *
30
- * `roundItemSchemas` must be the OWNER-SCOPED registry for the called tool
31
- * (harness base extended with only that tool's `itemSchemas`), so one tool's
32
- * `toolResults` schemas never reject a sibling tool's result items. Tools
33
- * without `itemSchemas` fall back to the base structural parse.
34
- */
35
- export function createToolResultItem({ output, callId, roundItemSchemas, tool, callItem, args, result, error, }) {
36
- const baseItem = {
37
- id: crypto.randomUUID(),
38
- status: 'completed',
39
- type: 'function_call_output',
40
- callId,
41
- output,
42
- };
43
- const decorated = tool?.decorateResultItem && callItem?.type === 'function_call'
44
- ? tool.decorateResultItem({
45
- baseItem,
46
- callItem,
47
- args,
48
- result,
49
- output,
50
- error,
51
- })
52
- : baseItem;
53
- return roundItemSchemas.parseWithCategory(decorated, 'toolResults');
54
- }
@@ -4,11 +4,11 @@
4
4
  * conversation, and record the tool span.
5
5
  */
6
6
  import { SteerPoint } from '@noetic-tools/types';
7
- import { executeToolCall, itemsToInput } from '../adapters/openrouter.js';
7
+ import { itemsToInput } from '../adapters/openrouter.js';
8
8
  import { isFunctionCall } from '../interpreter/typeguards.js';
9
9
  import { drainsOf } from '../runtime/drain.js';
10
+ import { createToolResultItem, executeToolCall } from '../runtime/tool-call.js';
10
11
  import { findTool } from './model-request.js';
11
- import { createToolResultItem } from './model-schema.js';
12
12
  //#endregion
13
13
  //#region Tool Round
14
14
  const SKIPPED_FOR_STEER_OUTPUT = 'Skipped: a new message arrived before this tool call ran.';
package/dist/index.d.ts CHANGED
@@ -127,7 +127,7 @@ export type { Expression } from '@noetic-tools/types';
127
127
  /** @public */
128
128
  export { defaultItemSchemaRegistry, ExpressionSchema, ItemSchema, ItemSchemaRegistry, } from '@noetic-tools/types';
129
129
  /** @public */
130
- export type { AcpAgentWorkflowNode, CallModelWorkflowNode, ComputeWorkflowNode, ConditionalRoute, ConditionalWorkflowNode, DecideWorkflowNode, InParallelWorkflowNode, InvokeToolWorkflowNode, LoopWorkflowNode, MergeStrategy, RouteSwitchWorkflowNode, ScheduleWorkflowNode, SequenceWorkflowNode, SpawnWorkflowNode, SubflowWorkflowNode, UntilPredicate, WithContextWorkflowNode, WorkflowCustomItem, WorkflowDocument, WorkflowEmitItems, WorkflowNode, } from './schemas/workflow.js';
130
+ export type { AcpAgentWorkflowNode, CallModelWorkflowNode, ComputeWorkflowNode, ConditionalRoute, ConditionalWorkflowNode, DecideWorkflowNode, InParallelWorkflowNode, InvokeToolWorkflowNode, LoopWorkflowNode, MergeStrategy, RouteSwitchWorkflowNode, ScheduleWorkflowNode, SequenceWorkflowNode, SpawnWorkflowNode, SubflowDocument, SubflowWorkflowNode, UntilPredicate, WithContextWorkflowNode, WorkflowConnectionToolEntry, WorkflowCustomItem, WorkflowDocument, WorkflowEmitItems, WorkflowMcpServer, WorkflowMcpToolEntry, WorkflowNode, WorkflowStepConnectionEntry, WorkflowToolEntry, WorkflowTypedToolEntry, } from './schemas/workflow.js';
131
131
  /** @public */
132
132
  export { MergeStrategySchema, UntilPredicateSchema, validateWorkflow, WorkflowDocumentSchema, WorkflowNodeSchema, walkWorkflow, workflowDepth, } from './schemas/workflow.js';
133
133
  /** @public */
@@ -178,7 +178,7 @@ export type { AfterModelCallParams, AfterModelCallResult, ApproveToolCallParams,
178
178
  /** @public */
179
179
  export { LedgerEntryKind, SteerAction, SteeringAction, SteerPoint } from '@noetic-tools/types';
180
180
  /** @public */
181
- export type { CustomItem, CustomItemEventOf, CustomItemMap, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomItemType, CustomStreamingItem, DeclaredItems, DeepReadonly, DocumentCustomItems, EmitHook, EmitHookResult, ExecuteStepFn, FromJsonSchema, HomogeneousSteps, InferShape, ItemShape, JsonSchema, MergeFn, PlainEmitHook, RunCodeExecute, SettleResult, Snapshot, Step, StepAcpAgent, StepArray, StepArrayInput, StepArrayOutput, StepCall, StepCallArgs, StepCallModel, StepChain, StepChainMismatch, StepConditional, StepConnectionTarget, StepEmitItems, StepEmitItemsConfig, StepEmitItemsFn, StepEmitItemsOption, StepEmitItemsResult, StepGiving, StepInParallel, StepInParallelAll, StepInParallelRace, StepInParallelSettle, StepInvokeTool, StepLike, StepLoop, StepReplay, StepRunCode, StepSequence, StepSpawn, Steps, StepsInput, StepsOutput, StepTaking, StepTypes, StepVerify, StepVerifyAct, StepVerifySubject, StepWait, StepWaitFilter, StepWaitOutput, StepWithContext, Until, UntilRun, ValidStepChain, Verdict, } from '@noetic-tools/types';
181
+ export type { CustomItem, CustomItemEventOf, CustomItemMap, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomItemType, CustomStreamingItem, DeclaredItems, DeepReadonly, DocumentCustomItems, EmitHook, EmitHookResult, ExecuteStepFn, FromJsonSchema, HomogeneousSteps, InferShape, ItemShape, JsonSchema, MergeFn, PlainEmitHook, RunCodeExecute, SettleResult, Snapshot, Step, StepAcpAgent, StepArray, StepArrayInput, StepArrayOutput, StepCall, StepCallArgs, StepCallModel, StepChain, StepChainMismatch, StepConditional, StepConnectionTarget, StepEmitItems, StepEmitItemsConfig, StepEmitItemsFn, StepEmitItemsOption, StepEmitItemsResult, StepGiving, StepInParallel, StepInParallelAll, StepInParallelRace, StepInParallelSettle, StepInvokeTool, StepLike, StepLoop, StepReplay, StepRunCode, StepSequence, StepSpawn, Steps, StepsInput, StepsOutput, StepTaking, StepToolEntry, StepTypes, StepVerify, StepVerifyAct, StepVerifySubject, StepWait, StepWaitFilter, StepWaitOutput, StepWithContext, Until, UntilRun, ValidStepChain, Verdict, } from '@noetic-tools/types';
182
182
  /** @public */
183
183
  export type { AnsweredAll, AnswerFor, BooleanAnswer, BooleanQuestion, CaseKeyOf, ChoiceAnswer, ChoiceQuestion, ChoiceValues, DecideAnswer, DecideAnswers, DecideQuestion, DecideQuestions, DecideRequest, DecideResponse, DecideStatePart, DecideStep, DecideView, DecisionMeta, DecisionRecord, DecisionSource, LevelLabels, OnDecisionParams, RecallOptions, ScoreAnswer, ScoreLevel, ScoreQuestion, StepDecide, } from '@noetic-tools/types';
184
184
  /** @public */
@@ -186,7 +186,7 @@ export { BooleanQuestionSchema, ChoiceQuestionSchema, choiceValues, DECIDE_LIMIT
186
186
  /** @public */
187
187
  export type { RouteSwitchByFunctionOpts, RouteSwitchByKeyOpts, StepDecideOpts, StepInput, StepOutput, } from './builders/decide-builders.js';
188
188
  /** @public */
189
- export type { AcpAgent, AcpAgentCapabilities, AcpAgentConnection, AcpAuthMethod, AcpAvailableCommand, AcpBoundPermissionHandler, AcpClientCapabilityConfig, AcpClientHost, AcpConnectOptions, AcpContentBlock, AcpKeepAlive, AcpLiveSession, AcpLoadSessionOptions, AcpMcpServer, AcpNewSessionOptions, AcpPermissionHandler, AcpPermissionOption, AcpPermissionOutcome, AcpPermissionPolicy, AcpPermissionRequestInfo, AcpPermissionRule, AcpPermissionSteerer, AcpPlanEntry, AcpPromptCapabilities, AcpPromptOptions, AcpRequestPermissionRequest, AcpSession, AcpSessionDisposer, AcpSessionInfo, AcpSessionMode, AcpSessionModeState, AcpSessionNotification, AcpSessionPolicy, AcpStopReason, AcpToolCallContent, AcpToolCallStatus, AcpToolKind, AcpTransport, AcpTransportFactory, AcpTransportOptions, AcpTurnResult, } from '@noetic-tools/types';
189
+ export type { AcpAgent, AcpAgentCapabilities, AcpAgentConnection, AcpAgentGrant, AcpAllowlist, AcpAuthMethod, AcpAvailableCommand, AcpBoundPermissionHandler, AcpCapabilityGrant, AcpClientCapabilityConfig, AcpClientHost, AcpConnectOptions, AcpContentBlock, AcpKeepAlive, AcpLiveSession, AcpLoadSessionOptions, AcpMachine, AcpMachineFactory, AcpMcpServer, AcpNewSessionOptions, AcpPermissionGrant, AcpPermissionHandler, AcpPermissionOption, AcpPermissionOutcome, AcpPermissionPolicy, AcpPermissionRequestInfo, AcpPermissionRule, AcpPermissionSteerer, AcpPlanEntry, AcpPromptCapabilities, AcpPromptOptions, AcpRequestPermissionRequest, AcpSession, AcpSessionDisposer, AcpSessionGrant, AcpSessionInfo, AcpSessionMode, AcpSessionModeState, AcpSessionNotification, AcpSessionPolicy, AcpStopReason, AcpToolCallContent, AcpToolCallStatus, AcpToolKind, AcpToolRefusal, AcpTransport, AcpTransportFactory, AcpTransportOptions, AcpTurnResult, ByteStream, Spawn, SpawnCommand, ToolBridgeAddress, } from '@noetic-tools/types';
190
190
  /** @public */
191
191
  export { ACP_AGENT_STEP_KIND, AcpCapabilityError, AcpConnectError, AcpPermissionDecision, isAcpCapabilityError, isAcpConnectError, } from '@noetic-tools/types';
192
192
  /** @public */
@@ -205,10 +205,10 @@ export { createLiveHandles } from './adapters/live-handles.js';
205
205
  /** @public */
206
206
  export type { ToolContext, ToolExecutionContext } from '@noetic-tools/types';
207
207
  /** @public */
208
- export type { ArtifactLink, ArtifactMeta, ArtifactRecord, ArtifactRetention, ArtifactStore, BlobRef, BlobRefBody, BlobReference, CallOptions, CallOutcome, CallResult, Connection, ConnectionAllowlist, ConnectionAllowlistEntry, ConnectionConfig, ConnectionEntry, ConnectionEvent, ConnectionEventInfo, ConnectionEventInit, ConnectionExpose, ConnectionHandle, ConnectionHandleOptions, ConnectionIdentity, ConnectionLease, ConnectionLook, ConnectionManifest, ConnectionMissing, ConnectionOperationInfo, ConnectionPolicy, ConnectionPoolConfig, ConnectionProvider, ConnectionRequirement, ConnectionResourceInfo, ConnectionSource, ConnectionState, ConnectionStatus, ConnectionsConfig, ConnectionTaskStatus, ConnectionTasks, ConnectionTrigger, ConnectOptions, CronOptions, CronTick, Determinism, EventStream, EventStreamMessage, FreshScope, ListenRequest, Locator, Receipt, Ref, RefBody, Secret, SecretResolver, SourceDefinition, SourceEmitEvent, Target, } from '@noetic-tools/types';
208
+ export type { ArtifactLink, ArtifactMeta, ArtifactRecord, ArtifactRetention, ArtifactStore, BlobRef, BlobRefBody, BlobReference, CallOptions, CallOutcome, CallResult, Connection, ConnectionAllowlist, ConnectionAllowlistEntry, ConnectionConfig, ConnectionEntries, ConnectionEntry, ConnectionEvent, ConnectionEventInfo, ConnectionEventInit, ConnectionExpose, ConnectionHandle, ConnectionHandleOptions, ConnectionIdentity, ConnectionLease, ConnectionLook, ConnectionManifest, ConnectionMissing, ConnectionOperationAnnotations, ConnectionOperationInfo, ConnectionPick, ConnectionPolicy, ConnectionPoolConfig, ConnectionProvider, ConnectionRequirement, ConnectionResourceInfo, ConnectionSource, ConnectionState, ConnectionStatus, ConnectionsConfig, ConnectionTaskStatus, ConnectionTasks, ConnectionTrigger, ConnectOptions, CronOptions, CronTick, Determinism, EventStream, EventStreamMessage, FreshScope, GrantedMcpServer, ListenRequest, Locator, McpAllowlist, McpCommandGrant, McpNamedValue, McpUrlGrant, Receipt, Ref, RefBody, Secret, SecretResolver, SourceDefinition, SourceEmitEvent, Target, } from '@noetic-tools/types';
209
209
  /** @public */
210
210
  /** @public */
211
- export { ARTIFACT_URI_PREFIX, artifactDigest, artifactUri, ConnectionUnsatisfiedError, DEFAULT_ARTIFACT_MAX_BYTES_PER_RUN, DEFAULT_ARTIFACT_MAX_COUNT_PER_RUN, isBlobRef, isConnectionUnsatisfiedError, isRef, isSecret, refId, secret, } from '@noetic-tools/types';
211
+ export { ARTIFACT_URI_PREFIX, artifactDigest, artifactUri, ConnectionUnsatisfiedError, DEFAULT_ARTIFACT_MAX_BYTES_PER_RUN, DEFAULT_ARTIFACT_MAX_COUNT_PER_RUN, isBlobRef, isConnectionEntry, isConnectionPick, isConnectionUnsatisfiedError, isRef, isSecret, refId, secret, } from '@noetic-tools/types';
212
212
  /** @public */
213
213
  export { connection, isConnectionHandle } from './connections/handle.js';
214
214
  /** @public */
package/dist/index.js CHANGED
@@ -126,7 +126,7 @@ export { serializeError } from './adapters/in-memory-subprocess/metadata.js';
126
126
  export { createLiveHandles } from './adapters/live-handles.js';
127
127
  /** @public */
128
128
  /** @public */
129
- export { ARTIFACT_URI_PREFIX, artifactDigest, artifactUri, ConnectionUnsatisfiedError, DEFAULT_ARTIFACT_MAX_BYTES_PER_RUN, DEFAULT_ARTIFACT_MAX_COUNT_PER_RUN, isBlobRef, isConnectionUnsatisfiedError, isRef, isSecret, refId, secret, } from '@noetic-tools/types';
129
+ export { ARTIFACT_URI_PREFIX, artifactDigest, artifactUri, ConnectionUnsatisfiedError, DEFAULT_ARTIFACT_MAX_BYTES_PER_RUN, DEFAULT_ARTIFACT_MAX_COUNT_PER_RUN, isBlobRef, isConnectionEntry, isConnectionPick, isConnectionUnsatisfiedError, isRef, isSecret, refId, secret, } from '@noetic-tools/types';
130
130
  /** @public */
131
131
  export { connection, isConnectionHandle } from './connections/handle.js';
132
132
  /** @public */
@@ -13,7 +13,7 @@
13
13
  * stop reason without streaming any text or tool calls, the result's content is
14
14
  * synthesized into events.
15
15
  */
16
- import type { AcpClientActivity, AcpSessionNotification, AcpTurnResult, Context, ContextData, StepAcpAgent } from '@noetic-tools/types';
16
+ import type { AcpClientActivity, AcpSessionNotification, AcpTurnResult, Context, ContextData, Item, StepAcpAgent } from '@noetic-tools/types';
17
17
  export declare class AcpEventBridge {
18
18
  private readonly broadcaster?;
19
19
  private readonly agentName;
@@ -27,6 +27,8 @@ export declare class AcpEventBridge {
27
27
  private sawText;
28
28
  /** Tool call ids already announced, so a `tool_call_update` never re-opens one. */
29
29
  private readonly announcedToolCalls;
30
+ /** Maps an agent's title for a bridged tool call to the tool's wire name. */
31
+ private toolNameOf;
30
32
  constructor(step: Pick<StepAcpAgent, 'id' | 'emit'>, agentId: string, ctx: Context<ContextData>);
31
33
  /**
32
34
  * Open the turn on the event surface. Emits `response.created` so every turn
@@ -39,6 +41,28 @@ export declare class AcpEventBridge {
39
41
  * actually asked us to do, refusals included.
40
42
  */
41
43
  forwardActivity(activity: AcpClientActivity): void;
44
+ /**
45
+ * Name bridged tool calls by their wire name on the stream, as the
46
+ * `callModel` stream names calls, rather than by the agent's display title.
47
+ */
48
+ nameToolCalls(nameOf: (title: string) => string | undefined): void;
49
+ /**
50
+ * Treat these call ids as announced: each is a bridged call standing in the
51
+ * turn's items where the agent's own record was, already on the stream
52
+ * under the agent's id.
53
+ */
54
+ adoptToolCalls(callIds: ReadonlyArray<string>): void;
55
+ /**
56
+ * Emit a bridged tool call's lifecycle event with the same payload the
57
+ * `callModel` tool loop emits, filtered by the step's `emit` option.
58
+ */
59
+ toolEvent(eventType: string, data: Record<string, unknown>): void;
60
+ /**
61
+ * Broadcast a bridged tool's result item so `getItemStream` carries it.
62
+ * Unfiltered, like the `callModel` path: item streaming is not subject to
63
+ * `step.emit`.
64
+ */
65
+ itemAppended(item: Item): void;
42
66
  /** Forward one notification: a structured framework event + the mapped sdk events. */
43
67
  forward(notification: AcpSessionNotification): void;
44
68
  /**
@@ -41,6 +41,8 @@ export class AcpEventBridge {
41
41
  sawText = false;
42
42
  /** Tool call ids already announced, so a `tool_call_update` never re-opens one. */
43
43
  announcedToolCalls = new Set();
44
+ /** Maps an agent's title for a bridged tool call to the tool's wire name. */
45
+ toolNameOf = () => undefined;
44
46
  constructor(step, agentId, ctx) {
45
47
  this.broadcaster = getBroadcaster(ctx);
46
48
  this.agentName = ctx.harness.config.name;
@@ -65,6 +67,56 @@ export class AcpEventBridge {
65
67
  ...activity,
66
68
  });
67
69
  }
70
+ /**
71
+ * Name bridged tool calls by their wire name on the stream, as the
72
+ * `callModel` stream names calls, rather than by the agent's display title.
73
+ */
74
+ nameToolCalls(nameOf) {
75
+ this.toolNameOf = nameOf;
76
+ }
77
+ /**
78
+ * Treat these call ids as announced: each is a bridged call standing in the
79
+ * turn's items where the agent's own record was, already on the stream
80
+ * under the agent's id.
81
+ */
82
+ adoptToolCalls(callIds) {
83
+ for (const callId of callIds) {
84
+ this.announcedToolCalls.add(callId);
85
+ }
86
+ }
87
+ /**
88
+ * Emit a bridged tool call's lifecycle event with the same payload the
89
+ * `callModel` tool loop emits, filtered by the step's `emit` option.
90
+ */
91
+ toolEvent(eventType, data) {
92
+ if (!this.broadcaster || !shouldEmit(this.emitOption, eventType, data)) {
93
+ return;
94
+ }
95
+ emitFrameworkEvent({
96
+ broadcaster: this.broadcaster,
97
+ agentName: this.agentName,
98
+ eventType,
99
+ data,
100
+ });
101
+ }
102
+ /**
103
+ * Broadcast a bridged tool's result item so `getItemStream` carries it.
104
+ * Unfiltered, like the `callModel` path: item streaming is not subject to
105
+ * `step.emit`.
106
+ */
107
+ itemAppended(item) {
108
+ if (!this.broadcaster) {
109
+ return;
110
+ }
111
+ emitFrameworkEvent({
112
+ broadcaster: this.broadcaster,
113
+ agentName: this.agentName,
114
+ eventType: 'item_appended',
115
+ data: {
116
+ item,
117
+ },
118
+ });
119
+ }
68
120
  /** Forward one notification: a structured framework event + the mapped sdk events. */
69
121
  forward(notification) {
70
122
  if (!this.broadcaster) {
@@ -243,7 +295,7 @@ export class AcpEventBridge {
243
295
  }
244
296
  if (update.sessionUpdate === 'tool_call') {
245
297
  this.closeMessage();
246
- this.emitToolCall(update.toolCallId, update.title, update.rawInput);
298
+ this.emitToolCall(update.toolCallId, this.toolNameOf(update.title) ?? update.title, update.rawInput);
247
299
  return;
248
300
  }
249
301
  // `user_message_chunk` (replayed history), `tool_call_update`, `plan`,
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Context layers on an ACP turn, as on a `callModel` call: the user input goes
3
+ * through the layers' append pipeline, recall runs before the turn and its
4
+ * output reaches the agent in the prompt, and the after-call hooks see the
5
+ * turn's result.
6
+ *
7
+ * A model receives layer output as items in its request. An agent takes only a
8
+ * prompt, so each turn's recall is rendered into it as a `<context>` block.
9
+ */
10
+ import type { Context, ContextData, ContextLayer, ContextRerenderRequest } from '@noetic-tools/types';
11
+ /**
12
+ * Run the layers' recall for this turn and render its output as the block the
13
+ * agent's prompt starts with, or `''` when the layers have nothing to say.
14
+ */
15
+ export declare function renderLayerContext(params: {
16
+ ctx: Context<ContextData>;
17
+ layers: ContextLayer[] | undefined;
18
+ query: string;
19
+ rerenderRequests: ContextRerenderRequest[];
20
+ }): Promise<string>;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Context layers on an ACP turn, as on a `callModel` call: the user input goes
3
+ * through the layers' append pipeline, recall runs before the turn and its
4
+ * output reaches the agent in the prompt, and the after-call hooks see the
5
+ * turn's result.
6
+ *
7
+ * A model receives layer output as items in its request. An agent takes only a
8
+ * prompt, so each turn's recall is rendered into it as a `<context>` block.
9
+ */
10
+ import { DEFAULT_PROJECTION } from './action-deps.js';
11
+ import { computeBudgetMap, gatherRecallResults } from './execute-action.js';
12
+ //#region Helpers
13
+ function itemText(item) {
14
+ if (item.type !== 'message') {
15
+ return '';
16
+ }
17
+ return item.content
18
+ .map((part) => ('text' in part && typeof part.text === 'string' ? part.text : ''))
19
+ .join('');
20
+ }
21
+ //#endregion
22
+ //#region Public API
23
+ /**
24
+ * Run the layers' recall for this turn and render its output as the block the
25
+ * agent's prompt starts with, or `''` when the layers have nothing to say.
26
+ */
27
+ export async function renderLayerContext(params) {
28
+ const { ctx, layers } = params;
29
+ if (!layers || layers.length === 0) {
30
+ return '';
31
+ }
32
+ const policy = ctx.harness.config.projection ?? DEFAULT_PROJECTION;
33
+ const recall = await gatherRecallResults({
34
+ ctx,
35
+ layers,
36
+ recallQuery: params.query,
37
+ budgetMap: computeBudgetMap({
38
+ layers,
39
+ policy,
40
+ systemPromptTokens: 0,
41
+ }),
42
+ slotOf: new Map(layers.map((layer) => [
43
+ layer.id,
44
+ layer.slot,
45
+ ])),
46
+ rerenderRequests: params.rerenderRequests,
47
+ });
48
+ const text = recall
49
+ .flatMap((output) => output.items)
50
+ .map(itemText)
51
+ .filter((chunk) => chunk.trim().length > 0)
52
+ .join('\n\n');
53
+ return text.length > 0 ? `<context>\n${text}\n</context>` : '';
54
+ }
55
+ //#endregion
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Runs Noetic tools on an ACP agent's behalf.
3
+ *
4
+ * The agent reaches the tools over MCP; each call it makes lands here and runs
5
+ * through the same pipeline as a `callModel` tool call — the drain hold, the
6
+ * `beforeToolCall` layers, validation, `needsApproval`, execution, the result
7
+ * item, its events and span — so the agent's model sees exactly the string a
8
+ * model would, and the host sees the same record.
9
+ */
10
+ import type { AcpSessionNotification, AcpTool, AcpToolCall, AcpToolHost, AcpToolResult, Context, ContextData, ContextLayer, FunctionCallItem, Item, StepAcpAgent, Tool } from '@noetic-tools/types';
11
+ import type { AcpEventBridge } from './acp-events.js';
12
+ /** The step a bridged call runs in. Rebound before each turn. */
13
+ export interface AcpToolBinding {
14
+ stepId: string;
15
+ ctx: Context<ContextData>;
16
+ layers?: ContextLayer[];
17
+ events: AcpEventBridge;
18
+ /**
19
+ * Called when the pipeline itself throws — not the tool, whose errors are
20
+ * results. A `callModel` step fails on such an error, so the turn must too.
21
+ */
22
+ fail: (error: unknown) => void;
23
+ }
24
+ /** One finished bridged call: the pair of items it adds to the log. */
25
+ interface BridgedCall {
26
+ readonly wireName: string;
27
+ readonly callItem: FunctionCallItem;
28
+ readonly outputItem: Item;
29
+ }
30
+ type SessionUpdate = AcpSessionNotification['update'];
31
+ /**
32
+ * Replace the agent's account of each bridged call with the bridge's own pair,
33
+ * in the agent's place in the turn. The pair keeps the bridge's `callId` — the
34
+ * one its events and approval saw — and joins the agent's record by that id,
35
+ * or else by the first unclaimed exact title. A call the agent never reported
36
+ * is appended.
37
+ */
38
+ export declare function mergeBridgedItems(items: ReadonlyArray<Item>, calls: ReadonlyArray<BridgedCall>): {
39
+ items: Item[];
40
+ /** Bridge `callId`s now standing where an agent record with another id was. */
41
+ adopted: string[];
42
+ };
43
+ /**
44
+ * The tool host a connection serves. Calls run one at a time, in arrival
45
+ * order — the `callModel` tool loop never runs two at once, and agents that
46
+ * call in parallel would otherwise race on shared state.
47
+ */
48
+ export declare class AcpToolRunner implements AcpToolHost {
49
+ private readonly source;
50
+ readonly serverName = "noetic";
51
+ readonly tools: ReadonlyArray<AcpTool>;
52
+ private readonly byWireName;
53
+ private readonly wrapped;
54
+ private binding;
55
+ private queue;
56
+ private finished;
57
+ private round;
58
+ /** Set when a call's pipeline threw: the turn is failing, so no further call runs. */
59
+ private failed;
60
+ /** The agent's announced tool calls, by id, with their titles. */
61
+ private readonly announced;
62
+ /** Ids already given to a call this session; an agent may not reuse one. */
63
+ private readonly claimed;
64
+ constructor(source: ReadonlyArray<Tool>);
65
+ /** Point the runner at the step whose turn is about to start. */
66
+ bind(binding: AcpToolBinding): void;
67
+ /** Stop running calls: the turn they belonged to has ended. */
68
+ unbind(): void;
69
+ /**
70
+ * Settles once no call is queued or running. An agent may end its turn
71
+ * while a call it gave up on still runs; that call still belongs to the
72
+ * turn, as an in-flight `callModel` call belongs to its aborted round.
73
+ */
74
+ idle(): Promise<void>;
75
+ /** The tool's wire name when `title` is how an agent titles a call to it. */
76
+ wireNameOf(title: string): string | undefined;
77
+ /** Note an agent `tool_call`, so a call without an id in `_meta` can take its id. */
78
+ observe(update: SessionUpdate): void;
79
+ /** The calls finished since the last take, in the order they ran. */
80
+ takeFinished(): BridgedCall[];
81
+ readonly call: (call: AcpToolCall) => Promise<AcpToolResult>;
82
+ private run;
83
+ private runInRound;
84
+ /**
85
+ * The agent's own id for the call: from its MCP request when it sent one,
86
+ * else from its matching announced `tool_call`, so events, approval, and
87
+ * items all carry the id the agent's own records use. A call the agent never
88
+ * named gets one from the step and its order, which a resumed step repeats.
89
+ */
90
+ private callIdFor;
91
+ private announcedId;
92
+ private unwrap;
93
+ private execute;
94
+ }
95
+ /**
96
+ * Resolve the step's tools into a runner, or `undefined` when it serves none.
97
+ * The set is what a `callModel` step's model may call: `tools: []` is none;
98
+ * `tools` given are those tools and the tools of the connections they list,
99
+ * by their harness names, plus the context layers' tools when the run has no
100
+ * unified tool set; no `tools` is every tool the run offers. A tool that runs
101
+ * this very step is left out, the same tool listed twice counts once, and
102
+ * server tools and colliding wire names are configuration errors.
103
+ *
104
+ * @throws NoeticConfigError `CONNECTION_INVALID` when function-form `tools`
105
+ * name a connection the turn never attached.
106
+ */
107
+ export declare function resolveAcpTools<TContext, I, O>(step: StepAcpAgent<TContext, I, O>, ctx: Context<TContext>, layers: ContextLayer[] | undefined): Promise<AcpToolRunner | undefined>;
108
+ export {};