@noetic-tools/core 5.19.1-next.1 → 5.20.0-next.1
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.
- package/dist/adapters/openrouter.js +5 -0
- package/dist/builders/control-flow-builders.d.ts +15 -6
- package/dist/builders/control-flow-builders.js +8 -0
- package/dist/builders/decide-builders.d.ts +2 -5
- package/dist/builders/dynamic-workflow.d.ts +16 -1
- package/dist/builders/dynamic-workflow.js +222 -11
- package/dist/builders/every.d.ts +3 -3
- package/dist/builders/every.js +2 -1
- package/dist/builders/provide-builder.d.ts +3 -2
- package/dist/builders/provide-builder.js +2 -1
- package/dist/builders/sequence.d.ts +14 -0
- package/dist/builders/sequence.js +103 -0
- package/dist/builders/spawn-builder.d.ts +3 -2
- package/dist/builders/spawn-builder.js +3 -2
- package/dist/builders/step-builders.d.ts +80 -1
- package/dist/builders/step-builders.js +115 -1
- package/dist/builders/verify-builder.d.ts +79 -0
- package/dist/builders/verify-builder.js +69 -0
- package/dist/builders/workflow-child-nodes.d.ts +21 -0
- package/dist/builders/workflow-child-nodes.js +335 -0
- package/dist/builders/workflow-connection-nodes.d.ts +17 -0
- package/dist/builders/workflow-connection-nodes.js +160 -0
- package/dist/builders/workflow-connections.d.ts +90 -0
- package/dist/builders/workflow-connections.js +560 -0
- package/dist/builders/workflow-control-nodes.d.ts +13 -0
- package/dist/builders/workflow-control-nodes.js +213 -0
- package/dist/builders/workflow-hydrator.d.ts +44 -3
- package/dist/builders/workflow-hydrator.js +53 -495
- package/dist/builders/workflow-verify.d.ts +19 -0
- package/dist/builders/workflow-verify.js +194 -0
- package/dist/conditions/conditions.d.ts +7 -5
- package/dist/conditions/conditions.js +7 -4
- package/dist/connections/blobs.d.ts +33 -0
- package/dist/connections/blobs.js +77 -0
- package/dist/connections/cron-schedule.d.ts +32 -0
- package/dist/connections/cron-schedule.js +213 -0
- package/dist/connections/durability.d.ts +65 -0
- package/dist/connections/durability.js +54 -0
- package/dist/connections/errors.d.ts +30 -0
- package/dist/connections/errors.js +100 -0
- package/dist/connections/event-stream.d.ts +24 -0
- package/dist/connections/event-stream.js +176 -0
- package/dist/connections/gates.d.ts +94 -0
- package/dist/connections/gates.js +271 -0
- package/dist/connections/glob.d.ts +10 -0
- package/dist/connections/glob.js +46 -0
- package/dist/connections/handle.d.ts +22 -0
- package/dist/connections/handle.js +84 -0
- package/dist/connections/harness-wiring.d.ts +52 -0
- package/dist/connections/harness-wiring.js +143 -0
- package/dist/connections/in-memory-connection.d.ts +147 -0
- package/dist/connections/in-memory-connection.js +593 -0
- package/dist/connections/index.d.ts +34 -0
- package/dist/connections/index.js +23 -0
- package/dist/connections/json-schema.d.ts +28 -0
- package/dist/connections/json-schema.js +338 -0
- package/dist/connections/model-tools.d.ts +46 -0
- package/dist/connections/model-tools.js +466 -0
- package/dist/connections/negotiation.d.ts +30 -0
- package/dist/connections/negotiation.js +159 -0
- package/dist/connections/policy.d.ts +21 -0
- package/dist/connections/policy.js +34 -0
- package/dist/connections/pool.d.ts +111 -0
- package/dist/connections/pool.js +339 -0
- package/dist/connections/refs.d.ts +74 -0
- package/dist/connections/refs.js +316 -0
- package/dist/connections/registry-types.d.ts +141 -0
- package/dist/connections/registry-types.js +14 -0
- package/dist/connections/registry.d.ts +125 -0
- package/dist/connections/registry.js +775 -0
- package/dist/connections/secrets.d.ts +59 -0
- package/dist/connections/secrets.js +153 -0
- package/dist/connections/settle.d.ts +9 -0
- package/dist/connections/settle.js +26 -0
- package/dist/connections/sources.d.ts +27 -0
- package/dist/connections/sources.js +300 -0
- package/dist/connections/triggers.d.ts +78 -0
- package/dist/connections/triggers.js +310 -0
- package/dist/connections/values.d.ts +26 -0
- package/dist/connections/values.js +93 -0
- package/dist/connections/views.d.ts +31 -0
- package/dist/connections/views.js +176 -0
- package/dist/expression/check.js +80 -1
- package/dist/expression/jsonata.d.ts +14 -4
- package/dist/expression/jsonata.js +27 -9
- package/dist/expression/step-outputs.d.ts +25 -0
- package/dist/expression/step-outputs.js +78 -0
- package/dist/harness/agent-harness.d.ts +69 -166
- package/dist/harness/agent-harness.js +170 -262
- package/dist/harness/call-span-collector.d.ts +33 -0
- package/dist/harness/call-span-collector.js +83 -0
- package/dist/harness/call-spend.d.ts +2 -0
- package/dist/harness/call-spend.js +10 -14
- package/dist/harness/connection-gate.d.ts +78 -0
- package/dist/harness/connection-gate.js +169 -0
- package/dist/harness/deps/interpreter.d.ts +1 -0
- package/dist/harness/deps/interpreter.js +1 -0
- package/dist/harness/deps/runtime.d.ts +1 -1
- package/dist/harness/deps/types.d.ts +1 -1
- package/dist/harness/harness-options.d.ts +153 -0
- package/dist/harness/harness-options.js +36 -0
- package/dist/harness/harness-tracing.d.ts +16 -0
- package/dist/harness/harness-tracing.js +35 -0
- package/dist/harness/llm-client.d.ts +71 -0
- package/dist/harness/llm-client.js +218 -0
- package/dist/harness/model-call.d.ts +2 -7
- package/dist/harness/model-call.js +141 -558
- package/dist/harness/model-request.d.ts +42 -0
- package/dist/harness/model-request.js +159 -0
- package/dist/harness/model-rounds.d.ts +18 -2
- package/dist/harness/model-rounds.js +39 -8
- package/dist/harness/model-stream.d.ts +39 -0
- package/dist/harness/model-stream.js +131 -0
- package/dist/harness/model-tool-round.d.ts +37 -0
- package/dist/harness/model-tool-round.js +197 -0
- package/dist/harness/spend.d.ts +2 -0
- package/dist/harness/spend.js +5 -1
- package/dist/index.d.ts +31 -6
- package/dist/index.js +18 -1
- package/dist/interpreter/connection-steps.d.ts +194 -0
- package/dist/interpreter/connection-steps.js +537 -0
- package/dist/interpreter/execute-action.d.ts +2 -8
- package/dist/interpreter/execute-action.js +3 -178
- package/dist/interpreter/execute-call.d.ts +19 -0
- package/dist/interpreter/execute-call.js +99 -0
- package/dist/interpreter/execute-control.d.ts +6 -1
- package/dist/interpreter/execute-control.js +14 -0
- package/dist/interpreter/execute-invoke-tool.d.ts +11 -0
- package/dist/interpreter/execute-invoke-tool.js +183 -0
- package/dist/interpreter/execute-verify.d.ts +21 -0
- package/dist/interpreter/execute-verify.js +391 -0
- package/dist/interpreter/execute-wait.d.ts +21 -0
- package/dist/interpreter/execute-wait.js +233 -0
- package/dist/interpreter/execute.js +24 -133
- package/dist/interpreter/step-kind-dispatch.d.ts +24 -0
- package/dist/interpreter/step-kind-dispatch.js +157 -0
- package/dist/interpreter/step-walk.d.ts +2 -0
- package/dist/interpreter/step-walk.js +24 -0
- package/dist/interpreter/verify-host.d.ts +40 -0
- package/dist/interpreter/verify-host.js +245 -0
- package/dist/runtime/durable/step-ledger.d.ts +34 -2
- package/dist/runtime/durable/step-ledger.js +97 -3
- package/dist/runtime/in-memory-artifact-store.d.ts +24 -0
- package/dist/runtime/in-memory-artifact-store.js +240 -0
- package/dist/schemas/workflow.d.ts +2 -2
- package/dist/schemas/workflow.js +1 -1
- package/dist/util/harness-internals.d.ts +23 -0
- package/dist/util/harness-internals.js +35 -0
- package/package.json +2 -2
- package/schema/noetic-workflow.schema.json +1170 -92
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { GenAI, NoeticAttr, ToolAttr } from '../observability/genai-attributes.js';
|
|
2
|
+
import { exportSpans } from './deps/context.js';
|
|
3
|
+
//#region Call span collector
|
|
4
|
+
/**
|
|
5
|
+
* Per-`callModel` span accumulator. Spans are created lazily from the calling
|
|
6
|
+
* context's span (so the trace tree mirrors the execution tree) and flushed to
|
|
7
|
+
* the harness `traceExporter` once the call settles — see issue #50, where the
|
|
8
|
+
* exporter was stored but never invoked.
|
|
9
|
+
*/
|
|
10
|
+
export class CallSpanCollector {
|
|
11
|
+
harness;
|
|
12
|
+
exporter;
|
|
13
|
+
parent;
|
|
14
|
+
nodeId;
|
|
15
|
+
firstSpanAttributes;
|
|
16
|
+
spans = [];
|
|
17
|
+
constructor(harness, exporter, parent, nodeId,
|
|
18
|
+
/** Stamped on the first model span only, then dropped. */
|
|
19
|
+
firstSpanAttributes) {
|
|
20
|
+
this.harness = harness;
|
|
21
|
+
this.exporter = exporter;
|
|
22
|
+
this.parent = parent;
|
|
23
|
+
this.nodeId = nodeId;
|
|
24
|
+
this.firstSpanAttributes = firstSpanAttributes;
|
|
25
|
+
}
|
|
26
|
+
/** Link a span back to its declared workflow node, when the call carries one. */
|
|
27
|
+
stampNode(span) {
|
|
28
|
+
if (this.nodeId !== undefined) {
|
|
29
|
+
span.setAttribute(NoeticAttr.NODE_ID, this.nodeId);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Open a model-call span stamped with GenAI semantic-convention attributes. */
|
|
33
|
+
startModelSpan(model) {
|
|
34
|
+
const span = this.harness.createSpan('llm.call', this.parent);
|
|
35
|
+
span.setAttribute(GenAI.SYSTEM, 'openrouter');
|
|
36
|
+
span.setAttribute(GenAI.REQUEST_MODEL, model);
|
|
37
|
+
this.stampNode(span);
|
|
38
|
+
for (const [key, value] of Object.entries(this.firstSpanAttributes ?? {})) {
|
|
39
|
+
span.setAttribute(key, value);
|
|
40
|
+
}
|
|
41
|
+
this.firstSpanAttributes = undefined;
|
|
42
|
+
this.spans.push(span);
|
|
43
|
+
return span;
|
|
44
|
+
}
|
|
45
|
+
/** Record usage + cost on a model-call span. */
|
|
46
|
+
finishModelSpan(span, usage, cost) {
|
|
47
|
+
span.setAttribute(GenAI.USAGE_INPUT_TOKENS, usage.inputTokens);
|
|
48
|
+
span.setAttribute(GenAI.USAGE_OUTPUT_TOKENS, usage.outputTokens);
|
|
49
|
+
if (usage.cachedTokens !== undefined) {
|
|
50
|
+
span.setAttribute(GenAI.USAGE_CACHED_INPUT_TOKENS, usage.cachedTokens);
|
|
51
|
+
}
|
|
52
|
+
if (usage.cacheWriteTokens !== undefined) {
|
|
53
|
+
span.setAttribute(GenAI.USAGE_CACHE_WRITE_TOKENS, usage.cacheWriteTokens);
|
|
54
|
+
}
|
|
55
|
+
if (cost !== undefined) {
|
|
56
|
+
span.setAttribute(GenAI.COST, cost);
|
|
57
|
+
}
|
|
58
|
+
span.end();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Open and immediately close a tool-call span under the given model span, or under
|
|
62
|
+
* the call's parent when the round's model call ran in an earlier attempt.
|
|
63
|
+
*/
|
|
64
|
+
recordToolSpan(parent, toolName, needsApproval, approval) {
|
|
65
|
+
const span = this.harness.createSpan('tool.call', parent ?? this.parent);
|
|
66
|
+
span.setAttribute(ToolAttr.NAME, toolName);
|
|
67
|
+
span.setAttribute(ToolAttr.NEEDS_APPROVAL, needsApproval);
|
|
68
|
+
if (approval !== undefined) {
|
|
69
|
+
span.setAttribute(ToolAttr.APPROVAL, approval);
|
|
70
|
+
}
|
|
71
|
+
this.stampNode(span);
|
|
72
|
+
span.end();
|
|
73
|
+
this.spans.push(span);
|
|
74
|
+
}
|
|
75
|
+
/** Flush all accumulated spans to the exporter. */
|
|
76
|
+
async flush() {
|
|
77
|
+
if (this.spans.length === 0) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
await exportSpans(this.exporter, this.spans);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
@@ -4,6 +4,8 @@ export interface Bill {
|
|
|
4
4
|
usage: RoundUsage;
|
|
5
5
|
cost: number;
|
|
6
6
|
}
|
|
7
|
+
/** The bill of a round the provider never reported on. */
|
|
8
|
+
export declare const noBill: Bill;
|
|
7
9
|
/**
|
|
8
10
|
* What one model call's rounds used and cost. Every round the provider answered
|
|
9
11
|
* counts, including one the loop rejected and asked again: the provider billed it.
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/** The bill of a round the provider never reported on. */
|
|
2
|
+
export const noBill = {
|
|
3
|
+
usage: {
|
|
4
|
+
inputTokens: 0,
|
|
5
|
+
outputTokens: 0,
|
|
6
|
+
},
|
|
7
|
+
cost: 0,
|
|
8
|
+
};
|
|
1
9
|
/**
|
|
2
10
|
* What one model call's rounds used and cost. Every round the provider answered
|
|
3
11
|
* counts, including one the loop rejected and asked again: the provider billed it.
|
|
@@ -22,13 +30,7 @@ export class CallSpend {
|
|
|
22
30
|
* round ledger to record.
|
|
23
31
|
*/
|
|
24
32
|
keep() {
|
|
25
|
-
const bill = this.held ??
|
|
26
|
-
usage: {
|
|
27
|
-
inputTokens: 0,
|
|
28
|
-
outputTokens: 0,
|
|
29
|
-
},
|
|
30
|
-
cost: 0,
|
|
31
|
-
};
|
|
33
|
+
const bill = this.held ?? noBill;
|
|
32
34
|
if (this.held) {
|
|
33
35
|
this.rounds.push({
|
|
34
36
|
...this.held,
|
|
@@ -77,13 +79,7 @@ export class CallSpend {
|
|
|
77
79
|
*/
|
|
78
80
|
charge() {
|
|
79
81
|
const paid = this.rounds.filter((round) => !round.replayed);
|
|
80
|
-
const bill = addBills(this.held, ...paid) ??
|
|
81
|
-
usage: {
|
|
82
|
-
inputTokens: 0,
|
|
83
|
-
outputTokens: 0,
|
|
84
|
-
},
|
|
85
|
-
cost: 0,
|
|
86
|
-
};
|
|
82
|
+
const bill = addBills(this.held, ...paid) ?? noBill;
|
|
87
83
|
return {
|
|
88
84
|
...bill.usage,
|
|
89
85
|
cost: bill.cost,
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ConnectionStatus } from '@noetic-tools/types';
|
|
2
|
+
import type { HarnessConnectionsOptions } from '../connections/harness-wiring.js';
|
|
3
|
+
import type { ConnectionRuntime } from '../connections/registry.js';
|
|
4
|
+
import type { Context, ContextLayer, Step, StorageAdapter, Tool } from './deps/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* A harness's connections, as the harness drives them: providers and triggers,
|
|
7
|
+
* negotiation of each run root's needs, and the rerun allowances restores grant
|
|
8
|
+
* (spec 35). The harness holds it in a true private field, so nothing holding
|
|
9
|
+
* `ctx.harness` reaches the registry (spec 35 § Gates).
|
|
10
|
+
*/
|
|
11
|
+
export declare class ConnectionGate {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* Wires the harness's connections and triggers, when it has any, and records
|
|
15
|
+
* the registry and `verifier` as the harness's private internals, where steps
|
|
16
|
+
* and tools find them without anything public on the harness.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options: HarnessConnectionsOptions & {
|
|
19
|
+
readonly verifier?: unknown;
|
|
20
|
+
});
|
|
21
|
+
/** The connection registry, absent on a harness without connections or triggers. */
|
|
22
|
+
get registry(): ConnectionRuntime | undefined;
|
|
23
|
+
/** One view layer per non-pool connection. */
|
|
24
|
+
get views(): ReadonlyArray<ContextLayer>;
|
|
25
|
+
/** This turn's connection tools. */
|
|
26
|
+
tools(): Tool[];
|
|
27
|
+
/** Connects providers and starts triggers. Idempotent. */
|
|
28
|
+
start(): Promise<void>;
|
|
29
|
+
/** Each connection's state, identity and pool usage; one entry for `name`, or all. */
|
|
30
|
+
status(name?: string): ReadonlyArray<ConnectionStatus>;
|
|
31
|
+
/** Stops triggers and releases every connection. */
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Registers what the agent graph's handles need: their profiles (ref kinds) and
|
|
35
|
+
* requirements, negotiated at start and again on every manifest change
|
|
36
|
+
* (spec 35 § Connection registry). Names the harness lacks are left to fail
|
|
37
|
+
* with `CONNECTION_UNKNOWN` when the step runs.
|
|
38
|
+
*/
|
|
39
|
+
registerGraphNeeds(agentGraph: Step | undefined): void;
|
|
40
|
+
/**
|
|
41
|
+
* Negotiates a `run()` root that is not the agent graph after the providers
|
|
42
|
+
* have connected: registers its handles' profiles and checks its requirements
|
|
43
|
+
* against each connection's manifest, so a root that needs more than a
|
|
44
|
+
* connection offers fails before it executes, as a document does (spec 35
|
|
45
|
+
* § Negotiation). A root is remembered as negotiated only once every
|
|
46
|
+
* connection it needs was checked; one whose connection was down (or whose
|
|
47
|
+
* pool has provisioned nothing yet) is checked again on its next run.
|
|
48
|
+
*
|
|
49
|
+
* @throws `NoeticConfigError` `CONNECTION_UNSATISFIED` when a connection falls short.
|
|
50
|
+
*/
|
|
51
|
+
negotiateRoot(root: Step): void;
|
|
52
|
+
/** Holds the rerun allowance a restore grants on the context it returns. */
|
|
53
|
+
holdReruns(ctx: Context, rerun: ReadonlyArray<string>): void;
|
|
54
|
+
/** Ends the rerun allowance `ctx` carries, for a run that failed before executing. */
|
|
55
|
+
dropReruns(ctx: Context): void;
|
|
56
|
+
/**
|
|
57
|
+
* Hands the rerun allowance a restore left on `ctx` to its run, which ends it
|
|
58
|
+
* when it finishes (released or orphaned, see `endRun`).
|
|
59
|
+
*/
|
|
60
|
+
grantReruns(ctx: Context): void;
|
|
61
|
+
/**
|
|
62
|
+
* Before a resumed run replays anything, checks the connections its ledger and
|
|
63
|
+
* pending entries were recorded against, discarding the ledger from the first
|
|
64
|
+
* entry whose connection was replaced (spec 35 § Durability).
|
|
65
|
+
*
|
|
66
|
+
* @throws NoeticErrorImpl `connection_resume_refused` when a replaced connection is unsafe to drive again.
|
|
67
|
+
*/
|
|
68
|
+
reconcile(ctx: Context, storage: StorageAdapter | undefined): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Ends a root run's hold on its connections. A failed run keeps its pool
|
|
71
|
+
* leases, unrenewed, so a resume within the reclaim window gets the same
|
|
72
|
+
* connections back and an abandoned one frees them (spec 35 § Pools and
|
|
73
|
+
* leases); a finished run releases them.
|
|
74
|
+
*/
|
|
75
|
+
orphanRun(executionId: string): void;
|
|
76
|
+
/** Releases a finished root run's connections and pool leases. */
|
|
77
|
+
releaseRun(executionId: string): Promise<void>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createHarnessConnections } from '../connections/harness-wiring.js';
|
|
2
|
+
import { setHarnessInternals } from '../util/harness-internals.js';
|
|
3
|
+
import { graphConnectionNeeds, reconcileResumedConnections } from './deps/interpreter.js';
|
|
4
|
+
import { ContextImpl } from './deps/runtime.js';
|
|
5
|
+
/**
|
|
6
|
+
* A harness's connections, as the harness drives them: providers and triggers,
|
|
7
|
+
* negotiation of each run root's needs, and the rerun allowances restores grant
|
|
8
|
+
* (spec 35). The harness holds it in a true private field, so nothing holding
|
|
9
|
+
* `ctx.harness` reaches the registry (spec 35 § Gates).
|
|
10
|
+
*/
|
|
11
|
+
export class ConnectionGate {
|
|
12
|
+
#connections;
|
|
13
|
+
/** Roots whose connection needs are already registered or checked. */
|
|
14
|
+
#negotiatedRoots = new WeakSet();
|
|
15
|
+
/**
|
|
16
|
+
* Connections a `restore(id, { rerun })` let its restored context drive again
|
|
17
|
+
* live, held on that context until its run starts (then granted to the run,
|
|
18
|
+
* and ended with it), so a later plain restore of the same id never inherits
|
|
19
|
+
* them (spec 35 § Durability).
|
|
20
|
+
*/
|
|
21
|
+
#reruns = new WeakMap();
|
|
22
|
+
/**
|
|
23
|
+
* Wires the harness's connections and triggers, when it has any, and records
|
|
24
|
+
* the registry and `verifier` as the harness's private internals, where steps
|
|
25
|
+
* and tools find them without anything public on the harness.
|
|
26
|
+
*/
|
|
27
|
+
constructor(options) {
|
|
28
|
+
if (options.connections || (options.triggers && options.triggers.length > 0)) {
|
|
29
|
+
this.#connections = createHarnessConnections(options);
|
|
30
|
+
}
|
|
31
|
+
setHarnessInternals(options.harness, {
|
|
32
|
+
connectionRegistry: this.#connections?.registry,
|
|
33
|
+
verifier: options.verifier,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** The connection registry, absent on a harness without connections or triggers. */
|
|
37
|
+
get registry() {
|
|
38
|
+
return this.#connections?.registry;
|
|
39
|
+
}
|
|
40
|
+
/** One view layer per non-pool connection. */
|
|
41
|
+
get views() {
|
|
42
|
+
return this.#connections?.views ?? [];
|
|
43
|
+
}
|
|
44
|
+
/** This turn's connection tools. */
|
|
45
|
+
tools() {
|
|
46
|
+
return this.#connections?.tools() ?? [];
|
|
47
|
+
}
|
|
48
|
+
/** Connects providers and starts triggers. Idempotent. */
|
|
49
|
+
async start() {
|
|
50
|
+
await this.#connections?.start();
|
|
51
|
+
}
|
|
52
|
+
/** Each connection's state, identity and pool usage; one entry for `name`, or all. */
|
|
53
|
+
status(name) {
|
|
54
|
+
return this.#connections?.registry.status(name) ?? [];
|
|
55
|
+
}
|
|
56
|
+
/** Stops triggers and releases every connection. */
|
|
57
|
+
async close() {
|
|
58
|
+
await this.#connections?.close();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Registers what the agent graph's handles need: their profiles (ref kinds) and
|
|
62
|
+
* requirements, negotiated at start and again on every manifest change
|
|
63
|
+
* (spec 35 § Connection registry). Names the harness lacks are left to fail
|
|
64
|
+
* with `CONNECTION_UNKNOWN` when the step runs.
|
|
65
|
+
*/
|
|
66
|
+
registerGraphNeeds(agentGraph) {
|
|
67
|
+
const registry = this.#connections?.registry;
|
|
68
|
+
if (!registry || !agentGraph) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.#negotiatedRoots.add(agentGraph);
|
|
72
|
+
const known = new Set(registry.names());
|
|
73
|
+
for (const need of graphConnectionNeeds(agentGraph)) {
|
|
74
|
+
if (need.profile) {
|
|
75
|
+
registry.registerProfile(need.profile);
|
|
76
|
+
}
|
|
77
|
+
if (known.has(need.name)) {
|
|
78
|
+
registry.require(need.name, need.requirement, {
|
|
79
|
+
setup: need.setup,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Negotiates a `run()` root that is not the agent graph after the providers
|
|
86
|
+
* have connected: registers its handles' profiles and checks its requirements
|
|
87
|
+
* against each connection's manifest, so a root that needs more than a
|
|
88
|
+
* connection offers fails before it executes, as a document does (spec 35
|
|
89
|
+
* § Negotiation). A root is remembered as negotiated only once every
|
|
90
|
+
* connection it needs was checked; one whose connection was down (or whose
|
|
91
|
+
* pool has provisioned nothing yet) is checked again on its next run.
|
|
92
|
+
*
|
|
93
|
+
* @throws `NoeticConfigError` `CONNECTION_UNSATISFIED` when a connection falls short.
|
|
94
|
+
*/
|
|
95
|
+
negotiateRoot(root) {
|
|
96
|
+
const registry = this.#connections?.registry;
|
|
97
|
+
if (!registry || this.#negotiatedRoots.has(root)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const known = new Set(registry.names());
|
|
101
|
+
let checkedAll = true;
|
|
102
|
+
for (const need of graphConnectionNeeds(root)) {
|
|
103
|
+
if (need.profile) {
|
|
104
|
+
registry.registerProfile(need.profile);
|
|
105
|
+
}
|
|
106
|
+
if (known.has(need.name) &&
|
|
107
|
+
!registry.check(need.name, need.requirement, {
|
|
108
|
+
setup: need.setup,
|
|
109
|
+
})) {
|
|
110
|
+
checkedAll = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (checkedAll) {
|
|
114
|
+
this.#negotiatedRoots.add(root);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Holds the rerun allowance a restore grants on the context it returns. */
|
|
118
|
+
holdReruns(ctx, rerun) {
|
|
119
|
+
this.#reruns.set(ctx, rerun);
|
|
120
|
+
}
|
|
121
|
+
/** Ends the rerun allowance `ctx` carries, for a run that failed before executing. */
|
|
122
|
+
dropReruns(ctx) {
|
|
123
|
+
this.#reruns.delete(ctx);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Hands the rerun allowance a restore left on `ctx` to its run, which ends it
|
|
127
|
+
* when it finishes (released or orphaned, see `endRun`).
|
|
128
|
+
*/
|
|
129
|
+
grantReruns(ctx) {
|
|
130
|
+
const rerun = this.#reruns.get(ctx);
|
|
131
|
+
if (!rerun) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
this.#reruns.delete(ctx);
|
|
135
|
+
this.#connections?.registry.allowRerun(ctx.id, rerun);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Before a resumed run replays anything, checks the connections its ledger and
|
|
139
|
+
* pending entries were recorded against, discarding the ledger from the first
|
|
140
|
+
* entry whose connection was replaced (spec 35 § Durability).
|
|
141
|
+
*
|
|
142
|
+
* @throws NoeticErrorImpl `connection_resume_refused` when a replaced connection is unsafe to drive again.
|
|
143
|
+
*/
|
|
144
|
+
async reconcile(ctx, storage) {
|
|
145
|
+
const registry = this.#connections?.registry;
|
|
146
|
+
if (!registry || !(ctx instanceof ContextImpl) || !ctx.ledger) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
await reconcileResumedConnections({
|
|
150
|
+
ctx,
|
|
151
|
+
registry,
|
|
152
|
+
storage,
|
|
153
|
+
signal: ctx.abortSignal,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Ends a root run's hold on its connections. A failed run keeps its pool
|
|
158
|
+
* leases, unrenewed, so a resume within the reclaim window gets the same
|
|
159
|
+
* connections back and an abandoned one frees them (spec 35 § Pools and
|
|
160
|
+
* leases); a finished run releases them.
|
|
161
|
+
*/
|
|
162
|
+
orphanRun(executionId) {
|
|
163
|
+
this.#connections?.registry.orphanRun?.(executionId);
|
|
164
|
+
}
|
|
165
|
+
/** Releases a finished root run's connections and pool leases. */
|
|
166
|
+
async releaseRun(executionId) {
|
|
167
|
+
await this.#connections?.registry.releaseRun(executionId);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
|
|
2
|
+
export { clearPendingEntries, graphConnectionNeeds, reconcileResumedConnections, } from '../../interpreter/connection-steps.js';
|
|
2
3
|
export { prepareBandedView } from '../../interpreter/context-assembly.js';
|
|
3
4
|
export { collectCustomItems } from '../../interpreter/emit-items.js';
|
|
4
5
|
export { execute } from '../../interpreter/execute.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { collectAllTools, deduplicateTools } from '../../interpreter/collect-tools.js';
|
|
2
|
+
export { clearPendingEntries, graphConnectionNeeds, reconcileResumedConnections, } from '../../interpreter/connection-steps.js';
|
|
2
3
|
export { prepareBandedView } from '../../interpreter/context-assembly.js';
|
|
3
4
|
export { collectCustomItems } from '../../interpreter/emit-items.js';
|
|
4
5
|
export { execute } from '../../interpreter/execute.js';
|
|
@@ -3,7 +3,7 @@ export { ChannelStore, warnToConsole } from '../../runtime/channel-store.js';
|
|
|
3
3
|
export { ContextImpl, collectContextTree, laneBase, rootIdOf } from '../../runtime/context-impl.js';
|
|
4
4
|
export { snapshotCwdState } from '../../runtime/cwd-helpers.js';
|
|
5
5
|
export { Drains } from '../../runtime/drain.js';
|
|
6
|
-
export type { CheckpointStore } from '../../runtime/durable/
|
|
6
|
+
export type { CheckpointStore } from '../../runtime/durable/checkpoint-store.js';
|
|
7
7
|
export { createCheckpointStore } from '../../runtime/durable/checkpoint-store.js';
|
|
8
8
|
export type { RestoreCheckpointOptions } from '../../runtime/durable/harness-checkpoints.js';
|
|
9
9
|
export { captureCheckpoint, clearCheckpoint, restoreFromCheckpoint, } from '../../runtime/durable/harness-checkpoints.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { ContextCacheConfig, ContextCacheStore, ContextData, ContextLayer, ExecutionContext, ProjectionPolicy, StorageAdapter, } from '@noetic-tools/context';
|
|
2
|
-
export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, CancelOptions, Channel, ChannelHandle, Context, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DeliveryMode, DetachedHandle, DrainReport, ExecuteInput, ExecuteOptions, ExecutionScope, ExecutionStatus, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, PendingSpend, RecallLayerOutput, RecallOptions, ReconcileSpendOptions, SessionScope, SessionUsage, ShellAdapter, Span, SpendSettlement, SteeringDecision, SteerVerdict, Step, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, UsageCharge, WriteOffSpendOptions, } from '@noetic-tools/types';
|
|
2
|
+
export type { AcpKeepAlive, AcpLiveSession, AcpSessionInfo, AgentConfig, AgentHarnessContract, AgentHooks, CallModelRequest, CancelOptions, Channel, ChannelHandle, Context, CustomItem, CustomItemOf, CustomItemStreamEvent, CustomItemsBrand, CustomStreamingItem, CwdState, DecideRequest, DecideResponse, DecisionRecord, DeclaredItems, DeliveryMode, DetachedHandle, DrainReport, ExecuteInput, ExecuteOptions, ExecutionScope, ExecutionStatus, ExternalChannel, FsAdapter, HarnessResponse, HarnessStatus, Item, ItemSchemaConfig, ItemSchemaExtensions, LLMResponse, LlmProviderConfig, OnSteerParams, PendingSpend, RecallLayerOutput, RecallOptions, ReconcileSpendOptions, SessionScope, SessionUsage, ShellAdapter, Span, SpendSettlement, SteeringDecision, SteerVerdict, Step, StepLike, Steps, StepsInput, StepsOutput, StreamEvent, StreamingItem, SubprocessAdapter, Tool, ToolApprover, TraceExporter, UsageCharge, ValidStepChain, WriteOffSpendOptions, } from '@noetic-tools/types';
|
|
3
3
|
export { SteeringAction } from '@noetic-tools/types';
|
|
4
4
|
export type { ZodType } from 'zod';
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { ArtifactStore, ConnectionsConfig, ConnectionTrigger, SecretResolver } from '@noetic-tools/types';
|
|
2
|
+
import type { Verifier } from '@noetic-tools/types/verify';
|
|
3
|
+
import type { LayerStateStore } from './deps/context.js';
|
|
4
|
+
import type { CheckpointStore, StepLedgerRetention } from './deps/runtime.js';
|
|
5
|
+
import type { AgentHooks, CallModelRequest, ContextCacheConfig, ContextData, ContextLayer, CustomItem, CustomItemsBrand, DecideRequest, DecideResponse, DeliveryMode, FsAdapter, ItemSchemaConfig, LLMResponse, LlmProviderConfig, ProjectionPolicy, ShellAdapter, Steps, StorageAdapter, SubprocessAdapter, Tool, ToolApprover, TraceExporter, ZodType } from './deps/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Storage-scoped environment configuration for `AgentHarness`.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface StorageEnvironmentConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Key-value storage adapter backing context-layer persistence and the
|
|
14
|
+
* step-completion ledger. Defaults to an in-memory adapter.
|
|
15
|
+
*/
|
|
16
|
+
adapter?: StorageAdapter;
|
|
17
|
+
/**
|
|
18
|
+
* Checkpoint store used by `harness.checkpoint(ctx)` / `harness.restore()`.
|
|
19
|
+
* Defaults to a store over `adapter` when one is given, so configuring durable
|
|
20
|
+
* storage is enough for a later harness on the same storage to resume this one's
|
|
21
|
+
* executions (see the harness `durability` option to turn that off). With no
|
|
22
|
+
* adapter and no store, checkpoint/restore are no-ops — a zero-config harness keeps
|
|
23
|
+
* its ephemeral semantics.
|
|
24
|
+
*/
|
|
25
|
+
checkpointStore?: CheckpointStore;
|
|
26
|
+
/** Layer-state store override. Defaults to an in-memory store. */
|
|
27
|
+
layerStateStore?: LayerStateStore;
|
|
28
|
+
/**
|
|
29
|
+
* Bounds on the step-completion ledger that backs step-level resume. Only meaningful
|
|
30
|
+
* when durability is on (a `checkpointStore`, given or defaulted). Defaults to `DEFAULT_STEP_LEDGER_RETENTION` — 128 KiB
|
|
31
|
+
* per entry, 1000 entries per execution — so an unbounded run cannot grow an unbounded
|
|
32
|
+
* ledger. Exceeding either cap costs resumability for the affected steps (they re-run),
|
|
33
|
+
* never correctness.
|
|
34
|
+
*/
|
|
35
|
+
stepLedgerRetention?: StepLedgerRetention;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Execution-environment configuration for `AgentHarness`: the storage,
|
|
39
|
+
* filesystem, shell, and subprocess surfaces the agent runs against.
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export interface AgentEnvironmentConfig {
|
|
44
|
+
/** Storage configuration: adapter, durability stores, ledger retention. */
|
|
45
|
+
storage?: StorageEnvironmentConfig;
|
|
46
|
+
/** Filesystem adapter. Defaults to an in-memory adapter. */
|
|
47
|
+
fs?: FsAdapter;
|
|
48
|
+
/** Shell adapter. Defaults to an in-memory adapter. */
|
|
49
|
+
shell?: ShellAdapter;
|
|
50
|
+
/** Subprocess adapter. Defaults to an in-memory, same-process adapter. */
|
|
51
|
+
subprocess?: SubprocessAdapter;
|
|
52
|
+
/** Resolves `secret()` names immediately before a connection call is sent (spec 35 § Secrets). */
|
|
53
|
+
secrets?: SecretResolver;
|
|
54
|
+
/** Where binary content is stored (spec 08 § Artifact Store). Defaults to an in-memory store. */
|
|
55
|
+
artifacts?: ArtifactStore;
|
|
56
|
+
}
|
|
57
|
+
/** `AgentHarness` constructor options. */
|
|
58
|
+
export interface AgentHarnessOpts<TParams extends Record<string, unknown> = Record<string, unknown>, TItem extends CustomItem = CustomItem> {
|
|
59
|
+
name: string;
|
|
60
|
+
/**
|
|
61
|
+
* Root step tree executed for every turn submitted via `execute()`. The custom items
|
|
62
|
+
* it declares (a `workflow()` step's brand) type `getItemStream`, `getFullStream`,
|
|
63
|
+
* and `getAgentResponse` (spec 34).
|
|
64
|
+
*/
|
|
65
|
+
agentGraph?: Steps<ContextData, string, string> & CustomItemsBrand<TItem>;
|
|
66
|
+
/** Default context layers applied to every context created via `createContext()` / `execute()`. */
|
|
67
|
+
contextLayers?: ContextLayer[];
|
|
68
|
+
/**
|
|
69
|
+
* Whether runs and sessions are durable: checkpointed, recorded to the step ledger,
|
|
70
|
+
* and resumable on a later harness over the same storage. Defaults to true whenever
|
|
71
|
+
* `environment.storage` gives an adapter or a checkpoint store. `false` turns every
|
|
72
|
+
* durability surface off even then — the adapter still backs context-layer
|
|
73
|
+
* persistence.
|
|
74
|
+
*/
|
|
75
|
+
durability?: boolean;
|
|
76
|
+
hooks?: AgentHooks;
|
|
77
|
+
/**
|
|
78
|
+
* Harness-wide tool pool. Merged (identity-deduplicated) with tools
|
|
79
|
+
* collected from `agentGraph` to form every context's `unifiedTools`.
|
|
80
|
+
* Use this when the workflow step tree is static and tools are supplied
|
|
81
|
+
* per harness instance rather than baked into individual `step.callModel` calls.
|
|
82
|
+
*/
|
|
83
|
+
tools?: Tool[];
|
|
84
|
+
params: TParams;
|
|
85
|
+
paramsSchema?: ZodType<TParams>;
|
|
86
|
+
/** Execution environment: storage, filesystem, shell, subprocess. */
|
|
87
|
+
environment?: AgentEnvironmentConfig;
|
|
88
|
+
/** Default provider configuration for model calls made through this harness. */
|
|
89
|
+
callModelDefaults?: LlmProviderConfig;
|
|
90
|
+
/** Harness-wide item schema extensions and validation strictness. */
|
|
91
|
+
itemSchemas?: ItemSchemaConfig;
|
|
92
|
+
/** Default projection policy for all LLM steps. Individual steps override via `step.projection`. */
|
|
93
|
+
projection?: ProjectionPolicy;
|
|
94
|
+
/** When true, every layer is recalled atomically regardless of its `recallMode`. */
|
|
95
|
+
forceAtomicRecall?: boolean;
|
|
96
|
+
/** Tuning for prompt-cache anchoring. See `ContextCacheConfig` for the defaults. */
|
|
97
|
+
contextCache?: ContextCacheConfig;
|
|
98
|
+
traceExporter?: TraceExporter;
|
|
99
|
+
/** Default delivery mode for messages that don't specify one. Defaults to `next-turn`. */
|
|
100
|
+
defaultDeliveryMode?: DeliveryMode;
|
|
101
|
+
/**
|
|
102
|
+
* Initial working directory for the harness. Used as the seed value for the
|
|
103
|
+
* shared `cwdState.cwd` on every Context this harness creates, including
|
|
104
|
+
* those produced by spawn/fork. Defaults to `process.cwd()`.
|
|
105
|
+
*/
|
|
106
|
+
initialCwd?: string;
|
|
107
|
+
/** Default model for `decide` steps. */
|
|
108
|
+
decisionModel?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Whether a resumed run streams again the items its replayed steps emitted
|
|
111
|
+
* (`step.emitItems`), as `item_appended`. Defaults to `false`: a replay rebuilds the
|
|
112
|
+
* log quietly. Set it when a client that reconnects to a resumed run should see
|
|
113
|
+
* the progress it missed.
|
|
114
|
+
*/
|
|
115
|
+
emitItemsOnReplay?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Approves or refuses calls to tools that declare `needsApproval`, after the
|
|
118
|
+
* `beforeToolCall` layers allow them. Without one, those calls run
|
|
119
|
+
* unapproved and the harness warns once per tool name.
|
|
120
|
+
*/
|
|
121
|
+
approveToolCall?: ToolApprover;
|
|
122
|
+
/**
|
|
123
|
+
* The live things the agent works with — browsers, devices, apps, chat workspaces,
|
|
124
|
+
* sources — by name (spec 35). Providers connect in `start()`.
|
|
125
|
+
*/
|
|
126
|
+
connections?: ConnectionsConfig;
|
|
127
|
+
/** Connection events that start or join a turn (spec 35 § Triggers). */
|
|
128
|
+
triggers?: ReadonlyArray<ConnectionTrigger>;
|
|
129
|
+
/** The verifier `step.verify` uses (spec 37). */
|
|
130
|
+
verification?: Verifier;
|
|
131
|
+
/** @internal Test-only escape hatch to inject a mock callModel implementation. */
|
|
132
|
+
_testCallModel?: (request: CallModelRequest) => Promise<LLMResponse>;
|
|
133
|
+
/** @internal Test-only escape hatch to inject a mock decide implementation. */
|
|
134
|
+
_testDecide?: (request: DecideRequest) => Promise<DecideResponse>;
|
|
135
|
+
}
|
|
136
|
+
/** The platform surfaces a harness runs against, defaults filled in. */
|
|
137
|
+
export interface EnvironmentAdapters {
|
|
138
|
+
fs: FsAdapter;
|
|
139
|
+
shell: ShellAdapter;
|
|
140
|
+
subprocess: SubprocessAdapter;
|
|
141
|
+
artifacts: ArtifactStore;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The filesystem, shell, subprocess, and artifact store an environment configures,
|
|
145
|
+
* each defaulting to an in-memory implementation.
|
|
146
|
+
*/
|
|
147
|
+
export declare function resolveEnvironmentAdapters(environment: AgentEnvironmentConfig | undefined): EnvironmentAdapters;
|
|
148
|
+
/**
|
|
149
|
+
* The checkpoint store a harness runs with: the one given, else a store over the
|
|
150
|
+
* configured storage adapter, so durable storage alone turns resume on. None when
|
|
151
|
+
* the harness sets `durability: false`.
|
|
152
|
+
*/
|
|
153
|
+
export declare function resolveCheckpointStore(storage: StorageEnvironmentConfig | undefined, durability: boolean | undefined): CheckpointStore | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createInMemoryArtifactStore } from '../runtime/in-memory-artifact-store.js';
|
|
2
|
+
import { createInMemoryFsAdapter, createInMemoryShellAdapter, createInMemorySubprocessAdapter, } from './deps/adapters.js';
|
|
3
|
+
import { createCheckpointStore } from './deps/runtime.js';
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region Resolution
|
|
6
|
+
/**
|
|
7
|
+
* The filesystem, shell, subprocess, and artifact store an environment configures,
|
|
8
|
+
* each defaulting to an in-memory implementation.
|
|
9
|
+
*/
|
|
10
|
+
export function resolveEnvironmentAdapters(environment) {
|
|
11
|
+
return {
|
|
12
|
+
fs: environment?.fs ?? createInMemoryFsAdapter(),
|
|
13
|
+
shell: environment?.shell ?? createInMemoryShellAdapter(),
|
|
14
|
+
subprocess: environment?.subprocess ?? createInMemorySubprocessAdapter(),
|
|
15
|
+
artifacts: environment?.artifacts ?? createInMemoryArtifactStore(),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The checkpoint store a harness runs with: the one given, else a store over the
|
|
20
|
+
* configured storage adapter, so durable storage alone turns resume on. None when
|
|
21
|
+
* the harness sets `durability: false`.
|
|
22
|
+
*/
|
|
23
|
+
export function resolveCheckpointStore(storage, durability) {
|
|
24
|
+
if (durability === false) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (storage?.checkpointStore) {
|
|
28
|
+
return storage.checkpointStore;
|
|
29
|
+
}
|
|
30
|
+
return storage?.adapter
|
|
31
|
+
? createCheckpointStore({
|
|
32
|
+
storage: storage.adapter,
|
|
33
|
+
})
|
|
34
|
+
: undefined;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChannelWarning } from './deps/runtime.js';
|
|
2
|
+
import type { Context, Span, TraceExporter } from './deps/types.js';
|
|
3
|
+
/** The exporter a harness flushes spans to: the one configured, else a no-op exporter. */
|
|
4
|
+
export declare function resolveTraceExporter(exporter: TraceExporter | undefined): TraceExporter;
|
|
5
|
+
/** A harness span: one the harness's trace exporter receives. */
|
|
6
|
+
export declare function createHarnessSpan(name: string, parent: Span | null): Span;
|
|
7
|
+
/**
|
|
8
|
+
* Channel state is shared by every root on a harness, so a channel warning is
|
|
9
|
+
* recorded as a `channel.warning` event on each live root's span (spec 10). A
|
|
10
|
+
* root span counts only if it will reach the trace exporter — a harness span
|
|
11
|
+
* (`SpanImpl`) with a real exporter configured. With no such span the warning
|
|
12
|
+
* goes to the console, so it is never lost.
|
|
13
|
+
*/
|
|
14
|
+
export declare function recordChannelWarning(warning: ChannelWarning, traceExporter: TraceExporter, liveRoots: Iterable<{
|
|
15
|
+
ctx: Context;
|
|
16
|
+
}>): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { NoeticEvent } from '../observability/genai-attributes.js';
|
|
2
|
+
import { SpanImpl } from '../observability/span-impl.js';
|
|
3
|
+
import { NoopExporter } from '../observability/trace-exporter.js';
|
|
4
|
+
import { warnToConsole } from './deps/runtime.js';
|
|
5
|
+
/** The exporter a harness flushes spans to: the one configured, else a no-op exporter. */
|
|
6
|
+
export function resolveTraceExporter(exporter) {
|
|
7
|
+
return exporter ?? new NoopExporter();
|
|
8
|
+
}
|
|
9
|
+
/** A harness span: one the harness's trace exporter receives. */
|
|
10
|
+
export function createHarnessSpan(name, parent) {
|
|
11
|
+
return new SpanImpl(name, parent);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Channel state is shared by every root on a harness, so a channel warning is
|
|
15
|
+
* recorded as a `channel.warning` event on each live root's span (spec 10). A
|
|
16
|
+
* root span counts only if it will reach the trace exporter — a harness span
|
|
17
|
+
* (`SpanImpl`) with a real exporter configured. With no such span the warning
|
|
18
|
+
* goes to the console, so it is never lost.
|
|
19
|
+
*/
|
|
20
|
+
export function recordChannelWarning(warning, traceExporter, liveRoots) {
|
|
21
|
+
const traced = traceExporter instanceof NoopExporter
|
|
22
|
+
? []
|
|
23
|
+
: [
|
|
24
|
+
...liveRoots,
|
|
25
|
+
].filter(({ ctx }) => ctx.span instanceof SpanImpl);
|
|
26
|
+
if (traced.length === 0) {
|
|
27
|
+
warnToConsole(warning);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
for (const { ctx } of traced) {
|
|
31
|
+
ctx.span.addEvent(NoeticEvent.CHANNEL_WARNING, {
|
|
32
|
+
...warning,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|