@noetic-tools/core 5.19.1-next.1 → 5.19.2

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 (150) hide show
  1. package/dist/adapters/openrouter.js +5 -0
  2. package/dist/builders/control-flow-builders.d.ts +15 -6
  3. package/dist/builders/control-flow-builders.js +8 -0
  4. package/dist/builders/decide-builders.d.ts +2 -5
  5. package/dist/builders/dynamic-workflow.d.ts +16 -1
  6. package/dist/builders/dynamic-workflow.js +222 -11
  7. package/dist/builders/every.d.ts +3 -3
  8. package/dist/builders/every.js +2 -1
  9. package/dist/builders/provide-builder.d.ts +3 -2
  10. package/dist/builders/provide-builder.js +2 -1
  11. package/dist/builders/sequence.d.ts +14 -0
  12. package/dist/builders/sequence.js +103 -0
  13. package/dist/builders/spawn-builder.d.ts +3 -2
  14. package/dist/builders/spawn-builder.js +3 -2
  15. package/dist/builders/step-builders.d.ts +80 -1
  16. package/dist/builders/step-builders.js +115 -1
  17. package/dist/builders/verify-builder.d.ts +79 -0
  18. package/dist/builders/verify-builder.js +69 -0
  19. package/dist/builders/workflow-child-nodes.d.ts +21 -0
  20. package/dist/builders/workflow-child-nodes.js +335 -0
  21. package/dist/builders/workflow-connection-nodes.d.ts +17 -0
  22. package/dist/builders/workflow-connection-nodes.js +160 -0
  23. package/dist/builders/workflow-connections.d.ts +90 -0
  24. package/dist/builders/workflow-connections.js +560 -0
  25. package/dist/builders/workflow-control-nodes.d.ts +13 -0
  26. package/dist/builders/workflow-control-nodes.js +213 -0
  27. package/dist/builders/workflow-hydrator.d.ts +44 -3
  28. package/dist/builders/workflow-hydrator.js +53 -495
  29. package/dist/builders/workflow-verify.d.ts +19 -0
  30. package/dist/builders/workflow-verify.js +194 -0
  31. package/dist/conditions/conditions.d.ts +7 -5
  32. package/dist/conditions/conditions.js +7 -4
  33. package/dist/connections/blobs.d.ts +33 -0
  34. package/dist/connections/blobs.js +77 -0
  35. package/dist/connections/cron-schedule.d.ts +32 -0
  36. package/dist/connections/cron-schedule.js +213 -0
  37. package/dist/connections/durability.d.ts +65 -0
  38. package/dist/connections/durability.js +54 -0
  39. package/dist/connections/errors.d.ts +30 -0
  40. package/dist/connections/errors.js +100 -0
  41. package/dist/connections/event-stream.d.ts +24 -0
  42. package/dist/connections/event-stream.js +176 -0
  43. package/dist/connections/gates.d.ts +94 -0
  44. package/dist/connections/gates.js +271 -0
  45. package/dist/connections/glob.d.ts +10 -0
  46. package/dist/connections/glob.js +46 -0
  47. package/dist/connections/handle.d.ts +22 -0
  48. package/dist/connections/handle.js +84 -0
  49. package/dist/connections/harness-wiring.d.ts +52 -0
  50. package/dist/connections/harness-wiring.js +143 -0
  51. package/dist/connections/in-memory-connection.d.ts +147 -0
  52. package/dist/connections/in-memory-connection.js +593 -0
  53. package/dist/connections/index.d.ts +34 -0
  54. package/dist/connections/index.js +23 -0
  55. package/dist/connections/json-schema.d.ts +28 -0
  56. package/dist/connections/json-schema.js +338 -0
  57. package/dist/connections/model-tools.d.ts +46 -0
  58. package/dist/connections/model-tools.js +466 -0
  59. package/dist/connections/negotiation.d.ts +30 -0
  60. package/dist/connections/negotiation.js +159 -0
  61. package/dist/connections/policy.d.ts +21 -0
  62. package/dist/connections/policy.js +34 -0
  63. package/dist/connections/pool.d.ts +111 -0
  64. package/dist/connections/pool.js +339 -0
  65. package/dist/connections/refs.d.ts +74 -0
  66. package/dist/connections/refs.js +316 -0
  67. package/dist/connections/registry-types.d.ts +141 -0
  68. package/dist/connections/registry-types.js +14 -0
  69. package/dist/connections/registry.d.ts +125 -0
  70. package/dist/connections/registry.js +775 -0
  71. package/dist/connections/secrets.d.ts +59 -0
  72. package/dist/connections/secrets.js +153 -0
  73. package/dist/connections/settle.d.ts +9 -0
  74. package/dist/connections/settle.js +26 -0
  75. package/dist/connections/sources.d.ts +27 -0
  76. package/dist/connections/sources.js +300 -0
  77. package/dist/connections/triggers.d.ts +78 -0
  78. package/dist/connections/triggers.js +310 -0
  79. package/dist/connections/values.d.ts +26 -0
  80. package/dist/connections/values.js +93 -0
  81. package/dist/connections/views.d.ts +31 -0
  82. package/dist/connections/views.js +176 -0
  83. package/dist/expression/check.js +80 -1
  84. package/dist/expression/jsonata.d.ts +14 -4
  85. package/dist/expression/jsonata.js +27 -9
  86. package/dist/expression/step-outputs.d.ts +25 -0
  87. package/dist/expression/step-outputs.js +78 -0
  88. package/dist/harness/agent-harness.d.ts +69 -166
  89. package/dist/harness/agent-harness.js +170 -262
  90. package/dist/harness/call-span-collector.d.ts +33 -0
  91. package/dist/harness/call-span-collector.js +83 -0
  92. package/dist/harness/call-spend.d.ts +2 -0
  93. package/dist/harness/call-spend.js +10 -14
  94. package/dist/harness/connection-gate.d.ts +78 -0
  95. package/dist/harness/connection-gate.js +169 -0
  96. package/dist/harness/deps/interpreter.d.ts +1 -0
  97. package/dist/harness/deps/interpreter.js +1 -0
  98. package/dist/harness/deps/runtime.d.ts +1 -1
  99. package/dist/harness/deps/types.d.ts +1 -1
  100. package/dist/harness/harness-options.d.ts +153 -0
  101. package/dist/harness/harness-options.js +36 -0
  102. package/dist/harness/harness-tracing.d.ts +16 -0
  103. package/dist/harness/harness-tracing.js +35 -0
  104. package/dist/harness/llm-client.d.ts +71 -0
  105. package/dist/harness/llm-client.js +218 -0
  106. package/dist/harness/model-call.d.ts +2 -7
  107. package/dist/harness/model-call.js +141 -558
  108. package/dist/harness/model-request.d.ts +42 -0
  109. package/dist/harness/model-request.js +159 -0
  110. package/dist/harness/model-rounds.d.ts +18 -2
  111. package/dist/harness/model-rounds.js +39 -8
  112. package/dist/harness/model-stream.d.ts +39 -0
  113. package/dist/harness/model-stream.js +131 -0
  114. package/dist/harness/model-tool-round.d.ts +37 -0
  115. package/dist/harness/model-tool-round.js +197 -0
  116. package/dist/harness/spend.d.ts +2 -0
  117. package/dist/harness/spend.js +5 -1
  118. package/dist/index.d.ts +31 -6
  119. package/dist/index.js +18 -1
  120. package/dist/interpreter/connection-steps.d.ts +194 -0
  121. package/dist/interpreter/connection-steps.js +537 -0
  122. package/dist/interpreter/execute-action.d.ts +2 -8
  123. package/dist/interpreter/execute-action.js +3 -178
  124. package/dist/interpreter/execute-call.d.ts +19 -0
  125. package/dist/interpreter/execute-call.js +99 -0
  126. package/dist/interpreter/execute-control.d.ts +6 -1
  127. package/dist/interpreter/execute-control.js +14 -0
  128. package/dist/interpreter/execute-invoke-tool.d.ts +11 -0
  129. package/dist/interpreter/execute-invoke-tool.js +183 -0
  130. package/dist/interpreter/execute-verify.d.ts +21 -0
  131. package/dist/interpreter/execute-verify.js +391 -0
  132. package/dist/interpreter/execute-wait.d.ts +21 -0
  133. package/dist/interpreter/execute-wait.js +233 -0
  134. package/dist/interpreter/execute.js +24 -133
  135. package/dist/interpreter/step-kind-dispatch.d.ts +24 -0
  136. package/dist/interpreter/step-kind-dispatch.js +157 -0
  137. package/dist/interpreter/step-walk.d.ts +2 -0
  138. package/dist/interpreter/step-walk.js +24 -0
  139. package/dist/interpreter/verify-host.d.ts +40 -0
  140. package/dist/interpreter/verify-host.js +245 -0
  141. package/dist/runtime/durable/step-ledger.d.ts +34 -2
  142. package/dist/runtime/durable/step-ledger.js +97 -3
  143. package/dist/runtime/in-memory-artifact-store.d.ts +24 -0
  144. package/dist/runtime/in-memory-artifact-store.js +240 -0
  145. package/dist/schemas/workflow.d.ts +2 -2
  146. package/dist/schemas/workflow.js +1 -1
  147. package/dist/util/harness-internals.d.ts +23 -0
  148. package/dist/util/harness-internals.js +35 -0
  149. package/package.json +3 -3
  150. package/schema/noetic-workflow.schema.json +1170 -92
@@ -0,0 +1,197 @@
1
+ /**
2
+ * The tool round of a model call: run each function call the model made (or
3
+ * answer it unrun when a steer arrives first), append its result item to the
4
+ * conversation, and record the tool span.
5
+ */
6
+ import { SteerPoint } from '@noetic-tools/types';
7
+ import { executeToolCall, itemsToInput } from '../adapters/openrouter.js';
8
+ import { isFunctionCall } from '../interpreter/typeguards.js';
9
+ import { drainsOf } from '../runtime/drain.js';
10
+ import { findTool } from './model-request.js';
11
+ import { createToolResultItem } from './model-schema.js';
12
+ //#endregion
13
+ //#region Tool Round
14
+ const SKIPPED_FOR_STEER_OUTPUT = 'Skipped: a new message arrived before this tool call ran.';
15
+ /**
16
+ * Tool rounds replay only their function calls. A round a steer follows must
17
+ * also replay what the model said, or the next round starts without it.
18
+ * Function calls are left to the tool round, which adds each with its output.
19
+ */
20
+ export function replayOutput(input, roundItems) {
21
+ input.push(...itemsToInput(roundItems.filter((item) => !isFunctionCall(item))));
22
+ }
23
+ /** Whether a round asked for any tool calls. */
24
+ export function hasFunctionCalls(roundItems) {
25
+ return roundItems.some(isFunctionCall);
26
+ }
27
+ /** Run the round's function calls. Returns `false` when there were none to run. */
28
+ export async function runToolRound(scope, params) {
29
+ const functionCalls = params.roundItems.filter(isFunctionCall);
30
+ if (functionCalls.length === 0 || !params.request.tools) {
31
+ return false;
32
+ }
33
+ await executeToolRound(scope, {
34
+ functionCalls,
35
+ request: params.request,
36
+ allowedTools: params.prepared.allowedTools,
37
+ allItems: params.allItems,
38
+ conversationInput: params.conversationInput,
39
+ round: params.round,
40
+ emitIfAllowed: params.prepared.emitIfAllowed,
41
+ spans: params.spans,
42
+ modelSpan: params.modelSpan,
43
+ steers: params.steers,
44
+ });
45
+ return true;
46
+ }
47
+ async function executeToolRound(scope, params) {
48
+ const { functionCalls, request, allowedTools, allItems, conversationInput, spans, modelSpan, steers, } = params;
49
+ params.emitIfAllowed('tool_round_started', {
50
+ round: params.round,
51
+ toolCount: functionCalls.length,
52
+ });
53
+ for (const fc of functionCalls) {
54
+ conversationInput.push({
55
+ type: 'function_call',
56
+ callId: fc.callId,
57
+ id: fc.id ?? crypto.randomUUID(),
58
+ name: fc.name,
59
+ arguments: fc.arguments,
60
+ });
61
+ }
62
+ for (const [index, fc] of functionCalls.entries()) {
63
+ await drainsOf(request.ctx)?.hold(request.ctx);
64
+ if (request.signal?.aborted) {
65
+ break;
66
+ }
67
+ const remaining = functionCalls.slice(index);
68
+ if (steers?.hasQueued() && (await steers.offer(SteerPoint.BeforeToolCall, remaining))) {
69
+ for (const skipped of remaining) {
70
+ recordSkippedToolCall(scope, {
71
+ fc: skipped,
72
+ request,
73
+ allowedTools,
74
+ allItems,
75
+ conversationInput,
76
+ emitIfAllowed: params.emitIfAllowed,
77
+ });
78
+ }
79
+ break;
80
+ }
81
+ const toolForCall = findTool(allowedTools, fc.name);
82
+ const approval = await executeFunctionCall(scope, {
83
+ fc,
84
+ request,
85
+ allowedTools,
86
+ allItems,
87
+ conversationInput,
88
+ emitIfAllowed: params.emitIfAllowed,
89
+ });
90
+ spans.recordToolSpan(modelSpan, fc.name, toolForCall?.needsApproval ?? false, approval);
91
+ }
92
+ params.emitIfAllowed('tool_round_completed', {
93
+ round: params.round,
94
+ toolCount: functionCalls.length,
95
+ });
96
+ }
97
+ async function executeFunctionCall(scope, params) {
98
+ const { fc, request, allowedTools, allItems, conversationInput } = params;
99
+ params.emitIfAllowed('tool_call_started', {
100
+ name: fc.name,
101
+ callId: fc.callId,
102
+ });
103
+ let parsedArgs;
104
+ try {
105
+ parsedArgs = JSON.parse(fc.arguments);
106
+ }
107
+ catch {
108
+ recordUnrunToolCall(scope, {
109
+ fc,
110
+ output: `Error: malformed JSON in tool arguments: ${fc.arguments}`,
111
+ request,
112
+ allowedTools,
113
+ allItems,
114
+ conversationInput,
115
+ emitIfAllowed: params.emitIfAllowed,
116
+ });
117
+ return undefined;
118
+ }
119
+ if (!request.tools) {
120
+ throw new Error(`executeFunctionCall invoked without tools on CallModelRequest (tool name: ${fc.name}).`);
121
+ }
122
+ const toolForCall = findTool(allowedTools, fc.name);
123
+ const toolResult = await executeToolCall({
124
+ toolName: fc.name,
125
+ args: parsedArgs,
126
+ tools: allowedTools,
127
+ context: request.ctx,
128
+ harness: scope.harness,
129
+ layers: request.layers,
130
+ callId: fc.callId,
131
+ });
132
+ // Owner-scoped result validation: a tool's `toolResults` schemas apply
133
+ // only to that tool's own result items. Harness-level `opts.itemSchemas`
134
+ // stay global by design; sibling tools' schemas never reject this item.
135
+ const outputItem = createToolResultItem({
136
+ output: toolResult.output,
137
+ callId: fc.callId,
138
+ roundItemSchemas: scope.itemSchemas.extend(toolForCall?.itemSchemas),
139
+ tool: toolForCall,
140
+ callItem: fc,
141
+ args: parsedArgs,
142
+ result: toolResult.result,
143
+ error: toolResult.error,
144
+ });
145
+ allItems.push(outputItem);
146
+ conversationInput.push({
147
+ type: 'function_call_output',
148
+ callId: fc.callId,
149
+ output: toolResult.output,
150
+ });
151
+ scope.emitItemAppended(request.ctx, outputItem);
152
+ params.emitIfAllowed('tool_call_completed', {
153
+ name: fc.name,
154
+ callId: fc.callId,
155
+ error: toolResult.error === true,
156
+ output: toolResult.output,
157
+ });
158
+ return toolResult.approval;
159
+ }
160
+ function recordSkippedToolCall(scope, params) {
161
+ params.emitIfAllowed('tool_call_started', {
162
+ name: params.fc.name,
163
+ callId: params.fc.callId,
164
+ });
165
+ recordUnrunToolCall(scope, {
166
+ ...params,
167
+ output: SKIPPED_FOR_STEER_OUTPUT,
168
+ });
169
+ }
170
+ /** Answer a call that never ran, so every call in the history has an output. */
171
+ function recordUnrunToolCall(scope, params) {
172
+ const { fc, request, allowedTools, allItems, conversationInput } = params;
173
+ const toolForCall = findTool(allowedTools, fc.name);
174
+ // Owner-scoped result validation (see executeFunctionCall).
175
+ const outputItem = createToolResultItem({
176
+ output: params.output,
177
+ callId: fc.callId,
178
+ roundItemSchemas: scope.itemSchemas.extend(toolForCall?.itemSchemas),
179
+ tool: toolForCall,
180
+ callItem: fc,
181
+ error: true,
182
+ });
183
+ allItems.push(outputItem);
184
+ conversationInput.push({
185
+ type: 'function_call_output',
186
+ callId: fc.callId,
187
+ output: params.output,
188
+ });
189
+ scope.emitItemAppended(request.ctx, outputItem);
190
+ params.emitIfAllowed('tool_call_completed', {
191
+ name: fc.name,
192
+ callId: fc.callId,
193
+ error: true,
194
+ output: params.output,
195
+ });
196
+ }
197
+ //#endregion
@@ -136,6 +136,8 @@ export declare class Dispatch {
136
136
  /** Request headers that tie the response back to this dispatch. */
137
137
  get headers(): Record<string, string>;
138
138
  noteGeneration(generationId: string): Promise<void>;
139
+ /** The provider refused the call before generating anything, so nothing was billed. */
140
+ wasRefused(err: unknown): boolean;
139
141
  /** The call's bill reached the run, or the provider refused it: drop the record. */
140
142
  settle(): Promise<void>;
141
143
  /** The call is over. Without a settled bill its record stays, pending. */
@@ -12,7 +12,7 @@ import { recordUsage, SpendKind } from '@noetic-tools/types';
12
12
  import { emitFrameworkEvent, getBroadcaster } from '../runtime/broadcaster-utils.js';
13
13
  import { isUnreadable } from '../runtime/durable/spend-log.js';
14
14
  import { hashText } from '../runtime/durable/step-ledger.js';
15
- import { statusOf } from '../util/status-code.js';
15
+ import { isErrorStatus, statusOf } from '../util/status-code.js';
16
16
  import { ContextImpl, laneBase } from './deps/runtime.js';
17
17
  import { ceilingOf, createPriceBook, LOOKUP_TIMEOUT_MS, measureRequest } from './model-price.js';
18
18
  import { roundPath } from './model-rounds.js';
@@ -437,6 +437,10 @@ export class Dispatch {
437
437
  this.record.generationId = generationId;
438
438
  return this.queue('write', () => this.log.put(this.record));
439
439
  }
440
+ /** The provider refused the call before generating anything, so nothing was billed. */
441
+ wasRefused(err) {
442
+ return isErrorStatus(err) && this.record.generationId === undefined;
443
+ }
440
444
  /** The call's bill reached the run, or the provider refused it: drop the record. */
441
445
  settle() {
442
446
  if (this.ended) {
package/dist/index.d.ts CHANGED
@@ -43,15 +43,19 @@ export type { SpawnOpts } from './builders/spawn-builder.js';
43
43
  /** @public */
44
44
  export { spawn } from './builders/spawn-builder.js';
45
45
  /** @public */
46
- export type { CallModelOpts, InvokeToolOpts, RunCodeOpts } from './builders/step-builders.js';
46
+ export type { CallInput, CallModelOpts, CallOpName, CallOpts, CallOutput, InvokeToolOpts, RunCodeOpts, WaitOpts, } from './builders/step-builders.js';
47
47
  /** @public */
48
48
  export { callModel, invokeTool, runCode, step } from './builders/step-builders.js';
49
49
  /** @public */
50
50
  export { tool, toolWithGenerator } from './builders/tool-builder.js';
51
51
  /** @public */
52
+ export type { VerifyConnectionRef, VerifyEachOutput, VerifyMatcherLike, VerifyOpts, } from './builders/verify-builder.js';
53
+ /** @public */
54
+ export { verify } from './builders/verify-builder.js';
55
+ /** @public */
52
56
  export type { HydrationContext } from './builders/workflow-hydrator.js';
53
57
  /** @public */
54
- export { hydrateNode, hydrateWorkflow } from './builders/workflow-hydrator.js';
58
+ export { hydrateNode, hydrateStepList, hydrateWorkflow } from './builders/workflow-hydrator.js';
55
59
  /** @public */
56
60
  export type { TypedWorkflowStep, WorkflowDocumentInput, WorkflowOpts, } from './builders/workflow-step.js';
57
61
  /** @public */
@@ -104,14 +108,14 @@ export type { DynamicWorkflowOpts, ParseAndRunWorkflowOpts } from './builders/dy
104
108
  /** @public */
105
109
  export { dynamicWorkflow, parseAndRunWorkflow } from './builders/dynamic-workflow.js';
106
110
  /** @public */
107
- export type { ExpressionLimits } from './expression/jsonata.js';
111
+ export type { ExpressionBindings, ExpressionLimits } from './expression/jsonata.js';
108
112
  /** @public */
109
113
  export { DEFAULT_EXPRESSION_LIMITS } from './expression/jsonata.js';
110
114
  /** @public */
111
- export type { AgentEnvironmentConfig, StorageEnvironmentConfig, } from './harness/agent-harness.js';
112
- /** @public */
113
115
  export { AgentHarness } from './harness/agent-harness.js';
114
116
  /** @public */
117
+ export type { AgentEnvironmentConfig, StorageEnvironmentConfig, } from './harness/harness-options.js';
118
+ /** @public */
115
119
  export type { AfterFirstTurnContext, CheckpointStore, CreateCheckpointStoreOptions, CreateNudgeMessageOpts, DetachedSignal, RunnableLoopHarness, RunnableLoopOpts, SessionSeedHarness, StallNudgeOpts, StepLedgerRetention, StepLedgerStats, } from './runtime/durable/index.js';
116
120
  /** @public */
117
121
  export { CheckpointKeys, createCheckpointStore, createDetachedSignal, createNudgeMessage, createStallNudgeHook, DEFAULT_NUDGE_MESSAGE_TEXT, DEFAULT_STEP_LEDGER_RETENTION, runnableLoop, seedFromItems, } from './runtime/durable/index.js';
@@ -174,7 +178,7 @@ export type { AfterModelCallParams, AfterModelCallResult, ApproveToolCallParams,
174
178
  /** @public */
175
179
  export { LedgerEntryKind, SteerAction, SteeringAction, SteerPoint } from '@noetic-tools/types';
176
180
  /** @public */
177
- export type { CustomItem, CustomItemEventOf, CustomItemMap, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomItemType, CustomStreamingItem, DeclaredItems, DeepReadonly, DocumentCustomItems, EmitHook, EmitHookResult, ExecuteStepFn, FromJsonSchema, InferShape, ItemShape, JsonSchema, MergeFn, PlainEmitHook, RunCodeExecute, SettleResult, Snapshot, Step, StepAcpAgent, StepCallModel, StepConditional, StepEmitItems, StepEmitItemsConfig, StepEmitItemsFn, StepEmitItemsOption, StepEmitItemsResult, StepInParallel, StepInParallelAll, StepInParallelRace, StepInParallelSettle, StepInvokeTool, StepLoop, StepReplay, StepRunCode, StepSpawn, StepWithContext, Until, UntilRun, 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, StepTypes, StepVerify, StepVerifyAct, StepVerifySubject, StepWait, StepWaitFilter, StepWaitOutput, StepWithContext, Until, UntilRun, ValidStepChain, Verdict, } from '@noetic-tools/types';
178
182
  /** @public */
179
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';
180
184
  /** @public */
@@ -201,6 +205,27 @@ export { createLiveHandles } from './adapters/live-handles.js';
201
205
  /** @public */
202
206
  export type { ToolContext, ToolExecutionContext } from '@noetic-tools/types';
203
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';
209
+ /** @public */
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';
212
+ /** @public */
213
+ export { connection, isConnectionHandle } from './connections/handle.js';
214
+ /** @public */
215
+ export type { InMemoryCallContext, InMemoryCallRecord, InMemoryConnection, InMemoryConnectionOptions, InMemoryConnectionProvider, InMemoryEventType, InMemoryOperation, InMemoryResource, InMemoryTaskStep, } from './connections/in-memory-connection.js';
216
+ /** @public */
217
+ export { createInMemoryConnection, InMemoryRefusal, inMemoryRefusal, } from './connections/in-memory-connection.js';
218
+ /** @public */
219
+ export type { ConnectionToolsOptions } from './connections/model-tools.js';
220
+ /** @public */
221
+ export { connectionTools } from './connections/model-tools.js';
222
+ /** @public */
223
+ export { cron, defineSource } from './connections/sources.js';
224
+ /** @public */
225
+ export type { InMemoryArtifactStoreOptions } from './runtime/in-memory-artifact-store.js';
226
+ /** @public */
227
+ export { createInMemoryArtifactStore } from './runtime/in-memory-artifact-store.js';
228
+ /** @public */
204
229
  export { all, any } from './until/combinators.js';
205
230
  /** @public */
206
231
  export type { ConvergeConfig, VerifyFn } from './until/predicates.js';
package/dist/index.js CHANGED
@@ -38,7 +38,9 @@ export { callModel, invokeTool, runCode, step } from './builders/step-builders.j
38
38
  /** @public */
39
39
  export { tool, toolWithGenerator } from './builders/tool-builder.js';
40
40
  /** @public */
41
- export { hydrateNode, hydrateWorkflow } from './builders/workflow-hydrator.js';
41
+ export { verify } from './builders/verify-builder.js';
42
+ /** @public */
43
+ export { hydrateNode, hydrateStepList, hydrateWorkflow } from './builders/workflow-hydrator.js';
42
44
  /** @public */
43
45
  export { workflow } from './builders/workflow-step.js';
44
46
  /** @public */
@@ -85,6 +87,8 @@ export { createInMemoryStorage } from './runtime/in-memory-storage.js';
85
87
  export { dynamicWorkflow, parseAndRunWorkflow } from './builders/dynamic-workflow.js';
86
88
  /** @public */
87
89
  export { DEFAULT_EXPRESSION_LIMITS } from './expression/jsonata.js';
90
+ //#endregion
91
+ //#region Runtime
88
92
  /** @public */
89
93
  export { AgentHarness } from './harness/agent-harness.js';
90
94
  /** @public */
@@ -120,6 +124,19 @@ export { TIMEOUT_ERROR_PREFIX } from '@noetic-tools/types';
120
124
  export { serializeError } from './adapters/in-memory-subprocess/metadata.js';
121
125
  /** @public */
122
126
  export { createLiveHandles } from './adapters/live-handles.js';
127
+ /** @public */
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';
130
+ /** @public */
131
+ export { connection, isConnectionHandle } from './connections/handle.js';
132
+ /** @public */
133
+ export { createInMemoryConnection, InMemoryRefusal, inMemoryRefusal, } from './connections/in-memory-connection.js';
134
+ /** @public */
135
+ export { connectionTools } from './connections/model-tools.js';
136
+ /** @public */
137
+ export { cron, defineSource } from './connections/sources.js';
138
+ /** @public */
139
+ export { createInMemoryArtifactStore } from './runtime/in-memory-artifact-store.js';
123
140
  //#endregion
124
141
  //#region Until
125
142
  /** @public */
@@ -0,0 +1,194 @@
1
+ /**
2
+ * What `call` and `wait` steps share (spec 35 § Steps, § Durability; spec 23a
3
+ * § Connection Steps): finding the harness registry, resolving the step's
4
+ * connection through it, deriving idempotency keys, and the pending ledger
5
+ * entries a resumed run picks up from.
6
+ *
7
+ * Steps never hold a provider's `Connection`: everything goes through the
8
+ * registry contract in `connections/registry-types.ts`.
9
+ */
10
+ import type { AnyProfile, ConnectionHandle, ConnectionIdentity, ConnectionRequirement, Context, Step, StepConnectionTarget, StorageAdapter } from '@noetic-tools/types';
11
+ import { z } from 'zod';
12
+ import type { ResumeDecision } from '../connections/durability.js';
13
+ import type { ConnectionRegistry, ConnectionScope, ResolvedConnection } from '../connections/registry-types.js';
14
+ /** A step's connection after its target is evaluated. */
15
+ export interface ConnectionTargetInfo {
16
+ /** The name the step uses: a handle's name, or a harness connection name. */
17
+ name: string;
18
+ handle?: ConnectionHandle;
19
+ }
20
+ /** What a step needs of its connection beyond its handle: the operation or event it uses. */
21
+ export interface StepUse {
22
+ op?: string;
23
+ event?: string;
24
+ }
25
+ /** A connection step's resolved connection plus the run facts it records against. */
26
+ export interface StepConnection {
27
+ resolved: ResolvedConnection;
28
+ scope: ConnectionScope;
29
+ /** Run-and-step idempotency key, stable across a resume. */
30
+ idempotencyKey: string;
31
+ pending: PendingEntries | undefined;
32
+ }
33
+ /** A pending ledger entry: what a `call` or `wait` recorded before it reached a server. */
34
+ export type PendingEntry = z.infer<typeof PendingEntrySchema>;
35
+ declare const PendingEntrySchema: z.ZodObject<{
36
+ stepId: z.ZodString;
37
+ kind: z.ZodEnum<{
38
+ call: "call";
39
+ wait: "wait";
40
+ }>;
41
+ connection: z.ZodString;
42
+ key: z.ZodString;
43
+ identity: z.ZodObject<{
44
+ surface: z.ZodString;
45
+ instance: z.ZodString;
46
+ epoch: z.ZodOptional<z.ZodNumber>;
47
+ }, z.core.$strip>;
48
+ taskId: z.ZodOptional<z.ZodString>;
49
+ leaseId: z.ZodOptional<z.ZodString>;
50
+ cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
51
+ deadline: z.ZodOptional<z.ZodNumber>;
52
+ }, z.core.$strip>;
53
+ /**
54
+ * The harness's connection registry.
55
+ *
56
+ * @throws `NoeticConfigError` `CONNECTION_UNKNOWN` when the harness has no connections.
57
+ */
58
+ export declare function connectionRegistryOf(ctx: Context, name: string): ConnectionRegistry;
59
+ /** The topmost ancestor of `ctx`: the run's root context, whose id names the run. */
60
+ export declare function runRootOf(ctx: Context): Context;
61
+ /** The abort signal of `ctx`, or one that never fires for a context without one (test stubs). */
62
+ export declare function signalOf(ctx: Context): AbortSignal;
63
+ /**
64
+ * The lease scope of a resolution. `fresh: 'run'` scopes to the run; `fresh:
65
+ * 'path'` to the parallel path the step runs on (the nearest context that is not
66
+ * the run root — each `inParallel` path runs in its own child context).
67
+ */
68
+ export declare function scopeFor(ctx: Context, fresh: 'run' | 'path' | undefined): ConnectionScope;
69
+ /** The lease scope key of a `fresh: 'path'` connection drawn on `ctx`. */
70
+ export declare function pathScopeKey(ctx: Context): string;
71
+ /**
72
+ * Returns every `fresh: 'path'` lease the given parallel path contexts hold
73
+ * (spec 35 § Fresh connections: "gives it back when the scope ends"). A no-op
74
+ * when the harness has no connections.
75
+ */
76
+ export declare function releasePathLeases(paths: ReadonlyArray<Context>): Promise<void>;
77
+ /** The ledger path of the step running on `ctx`, when it runs on a lane. */
78
+ export declare function stepPathOf(ctx: Context): string | undefined;
79
+ /** The run-and-step key a call carries, stable across a resume of the same run (spec 35 § Durability). */
80
+ export declare function idempotencyKeyFor(ctx: Context, stepId: string, ledgerKey?: string): string;
81
+ /**
82
+ * Evaluates a step's connection target.
83
+ *
84
+ * @throws `NoeticConfigError` `CONNECTION_INVALID` when it gives neither a handle nor a non-empty name.
85
+ */
86
+ export declare function evaluateTarget<TContext, I>(target: StepConnectionTarget<TContext, I>, input: I, ctx: Context<TContext>, stepId: string): Promise<ConnectionTargetInfo>;
87
+ /** What a handle (or a bare name) requires for one use: its profile and extensions, plus the op or event. */
88
+ export declare function requirementFor(target: ConnectionTargetInfo, use: StepUse): ConnectionRequirement;
89
+ /** What a harness graph needs of one connection, found before it runs. */
90
+ export interface GraphConnectionNeed {
91
+ /** The harness connection (or pool) the handle binds to. */
92
+ readonly name: string;
93
+ readonly profile?: AnyProfile;
94
+ readonly requirement: ConnectionRequirement;
95
+ /**
96
+ * Whether the handle passes a pool a setup. A pool's provider may offer a
97
+ * different manifest per setup, so such a need is checked on the lease.
98
+ */
99
+ readonly setup: boolean;
100
+ }
101
+ /**
102
+ * Every connection need a graph states up front: each `call` and `wait` whose
103
+ * connection is a static handle, with its profile and requirement. The harness
104
+ * registers these profiles (ref kinds) and requirements (start-time
105
+ * negotiation, renegotiated on a manifest change) when it is built.
106
+ */
107
+ export declare function graphConnectionNeeds(graph: Step): GraphConnectionNeed[];
108
+ /**
109
+ * Resolves the step's connection through the registry and prepares what a
110
+ * gated call or listen needs. Throws whatever `registry.resolve` throws.
111
+ */
112
+ export declare function resolveStepConnection(opts: {
113
+ ctx: Context;
114
+ stepId: string;
115
+ target: ConnectionTargetInfo;
116
+ use: StepUse;
117
+ ledgerKey: string | undefined;
118
+ }): Promise<StepConnection>;
119
+ /**
120
+ * Runs `fn` (a verify's `act`) with `witnesses` guarded: any `call` on one of
121
+ * them that has effects — however its connection was named, by a function or
122
+ * an expression too — is refused with `VERIFY_INVALID` (spec 37 § Witnesses).
123
+ */
124
+ export declare function withWitnessGuard<T>(ctx: Context, witnesses: ReadonlyArray<string>, fn: () => Promise<T>): Promise<T>;
125
+ /**
126
+ * Refuses a call on a witness inside a verify's `act` unless the operation is
127
+ * declared without effects.
128
+ *
129
+ * @throws `NoeticConfigError` `VERIFY_INVALID`.
130
+ */
131
+ export declare function refuseWitnessAct(ctx: Context, resolved: ResolvedConnection, op: string): void;
132
+ /**
133
+ * Pending ledger entries for one run (spec 23a § Connection Steps): written
134
+ * before a call or wait reaches a server, removed once it has a result. Kept
135
+ * in the harness `StorageAdapter` next to the run's ledger.
136
+ */
137
+ export declare class PendingEntries {
138
+ private readonly storage;
139
+ private readonly key;
140
+ constructor(storage: StorageAdapter, key: string);
141
+ /** The entry a previous attempt left, or undefined when there is none (or it does not parse). */
142
+ load(): Promise<PendingEntry | undefined>;
143
+ write(entry: PendingEntry): Promise<void>;
144
+ clear(): Promise<void>;
145
+ }
146
+ /** The storage key of a step's pending entry. */
147
+ export declare function pendingEntryKey(executionId: string, ledgerKey: string): string;
148
+ /**
149
+ * Deletes every pending entry a completed run left behind (an entry is normally
150
+ * cleared when its step gets a result; this catches steps a run never resumed).
151
+ */
152
+ export declare function clearPendingEntries(storage: StorageAdapter, executionId: string): Promise<void>;
153
+ /**
154
+ * Decides what a resumed step does with the pending entry a previous attempt
155
+ * left (spec 35 § Durability), through the one resume policy in
156
+ * `connections/durability.ts`. Against the same identity instance it returns the
157
+ * entry so the step picks up where it was. Against a replaced connection:
158
+ * `harness.restore(id, { rerun })` naming it, or `replayPrefix: 'free'`, runs
159
+ * live; `'costly'` with a reset resets first; anything else — including a
160
+ * connection that declares no determinism — refuses.
161
+ *
162
+ * @throws `NoeticErrorImpl` `connection_resume_refused` when the replaced connection cannot be driven again.
163
+ */
164
+ export declare function reconcilePending(connection: StepConnection, signal: AbortSignal, ctx?: Context): Promise<PendingEntry | undefined>;
165
+ /** What run-level reconciliation needs of the registry. */
166
+ export interface ResumeChecker {
167
+ checkResume(params: {
168
+ readonly executionId: string;
169
+ readonly name: string;
170
+ readonly recorded: ConnectionIdentity;
171
+ readonly signal: AbortSignal;
172
+ }): Promise<ResumeDecision>;
173
+ }
174
+ /**
175
+ * Before a resumed run replays anything, checks every connection its ledger
176
+ * and pending entries were recorded against (spec 35 § Durability). For a
177
+ * replaced connection that may run live (after a reset when that is the
178
+ * decision), the ledger is discarded from the first entry that used it —
179
+ * everything after runs live too, model rounds included — and its pending
180
+ * entries are dropped (their idempotency keys derive from the run and step,
181
+ * so `once` calls still carry their original keys). Resolves the number of
182
+ * ledger entries discarded.
183
+ *
184
+ * @throws `NoeticErrorImpl` `connection_resume_refused` when a replaced connection cannot be driven again.
185
+ */
186
+ export declare function reconcileResumedConnections(opts: {
187
+ ctx: Context;
188
+ registry: ResumeChecker;
189
+ storage: StorageAdapter | undefined;
190
+ signal: AbortSignal;
191
+ }): Promise<number>;
192
+ /** Emits a connection framework event (`connection_event`, `connection_task`, `stream_changed`). */
193
+ export declare function emitConnectionEvent(ctx: Context, eventType: string, data: Record<string, unknown>): void;
194
+ export {};