@autonome-research/thread-phase 3.0.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.
- package/LICENSE +21 -0
- package/README.md +226 -0
- package/dist/agent/index.d.ts +28 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +28 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/openai-adapter.d.ts +15 -0
- package/dist/agent/openai-adapter.d.ts.map +1 -0
- package/dist/agent/openai-adapter.js +57 -0
- package/dist/agent/openai-adapter.js.map +1 -0
- package/dist/agent/parse-json.d.ts +12 -0
- package/dist/agent/parse-json.d.ts.map +1 -0
- package/dist/agent/parse-json.js +31 -0
- package/dist/agent/parse-json.js.map +1 -0
- package/dist/agent/retry.d.ts +15 -0
- package/dist/agent/retry.d.ts.map +1 -0
- package/dist/agent/retry.js +35 -0
- package/dist/agent/retry.js.map +1 -0
- package/dist/agent/runner.d.ts +25 -0
- package/dist/agent/runner.d.ts.map +1 -0
- package/dist/agent/runner.js +270 -0
- package/dist/agent/runner.js.map +1 -0
- package/dist/agent/stream-consumer.d.ts +57 -0
- package/dist/agent/stream-consumer.d.ts.map +1 -0
- package/dist/agent/stream-consumer.js +126 -0
- package/dist/agent/stream-consumer.js.map +1 -0
- package/dist/agent/types.d.ts +135 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +9 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent-runner.d.ts +10 -0
- package/dist/agent-runner.d.ts.map +1 -0
- package/dist/agent-runner.js +10 -0
- package/dist/agent-runner.js.map +1 -0
- package/dist/agents/capability.d.ts +36 -0
- package/dist/agents/capability.d.ts.map +1 -0
- package/dist/agents/capability.js +51 -0
- package/dist/agents/capability.js.map +1 -0
- package/dist/agents/event-bus.d.ts +20 -0
- package/dist/agents/event-bus.d.ts.map +1 -0
- package/dist/agents/event-bus.js +40 -0
- package/dist/agents/event-bus.js.map +1 -0
- package/dist/agents/index.d.ts +23 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +33 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/inference-adapter.d.ts +52 -0
- package/dist/agents/inference-adapter.d.ts.map +1 -0
- package/dist/agents/inference-adapter.js +209 -0
- package/dist/agents/inference-adapter.js.map +1 -0
- package/dist/agents/job-store-bridge.d.ts +44 -0
- package/dist/agents/job-store-bridge.d.ts.map +1 -0
- package/dist/agents/job-store-bridge.js +58 -0
- package/dist/agents/job-store-bridge.js.map +1 -0
- package/dist/agents/memory.d.ts +40 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +14 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/protocol.d.ts +302 -0
- package/dist/agents/protocol.d.ts.map +1 -0
- package/dist/agents/protocol.js +36 -0
- package/dist/agents/protocol.js.map +1 -0
- package/dist/agents/run-helpers.d.ts +70 -0
- package/dist/agents/run-helpers.d.ts.map +1 -0
- package/dist/agents/run-helpers.js +131 -0
- package/dist/agents/run-helpers.js.map +1 -0
- package/dist/agents/serialize-error.d.ts +18 -0
- package/dist/agents/serialize-error.d.ts.map +1 -0
- package/dist/agents/serialize-error.js +27 -0
- package/dist/agents/serialize-error.js.map +1 -0
- package/dist/agents/structured-output.d.ts +90 -0
- package/dist/agents/structured-output.d.ts.map +1 -0
- package/dist/agents/structured-output.js +101 -0
- package/dist/agents/structured-output.js.map +1 -0
- package/dist/agents/test-utils/conformance.d.ts +59 -0
- package/dist/agents/test-utils/conformance.d.ts.map +1 -0
- package/dist/agents/test-utils/conformance.js +207 -0
- package/dist/agents/test-utils/conformance.js.map +1 -0
- package/dist/agents/test-utils/index.d.ts +12 -0
- package/dist/agents/test-utils/index.d.ts.map +1 -0
- package/dist/agents/test-utils/index.js +12 -0
- package/dist/agents/test-utils/index.js.map +1 -0
- package/dist/agents/test-utils/mock-agent.d.ts +66 -0
- package/dist/agents/test-utils/mock-agent.d.ts.map +1 -0
- package/dist/agents/test-utils/mock-agent.js +244 -0
- package/dist/agents/test-utils/mock-agent.js.map +1 -0
- package/dist/agents/thread.d.ts +57 -0
- package/dist/agents/thread.d.ts.map +1 -0
- package/dist/agents/thread.js +128 -0
- package/dist/agents/thread.js.map +1 -0
- package/dist/agents/turn-accumulator.d.ts +94 -0
- package/dist/agents/turn-accumulator.d.ts.map +1 -0
- package/dist/agents/turn-accumulator.js +150 -0
- package/dist/agents/turn-accumulator.js.map +1 -0
- package/dist/agents/with-memory.d.ts +55 -0
- package/dist/agents/with-memory.d.ts.map +1 -0
- package/dist/agents/with-memory.js +155 -0
- package/dist/agents/with-memory.js.map +1 -0
- package/dist/agents/with-thread.d.ts +45 -0
- package/dist/agents/with-thread.d.ts.map +1 -0
- package/dist/agents/with-thread.js +70 -0
- package/dist/agents/with-thread.js.map +1 -0
- package/dist/cache.d.ts +47 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +81 -0
- package/dist/cache.js.map +1 -0
- package/dist/context/compressor.d.ts +36 -0
- package/dist/context/compressor.d.ts.map +1 -0
- package/dist/context/compressor.js +158 -0
- package/dist/context/compressor.js.map +1 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +4 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/result-capper.d.ts +32 -0
- package/dist/context/result-capper.d.ts.map +1 -0
- package/dist/context/result-capper.js +50 -0
- package/dist/context/result-capper.js.map +1 -0
- package/dist/context/token-budget.d.ts +81 -0
- package/dist/context/token-budget.d.ts.map +1 -0
- package/dist/context/token-budget.js +99 -0
- package/dist/context/token-budget.js.map +1 -0
- package/dist/helpers/caller.d.ts +18 -0
- package/dist/helpers/caller.d.ts.map +1 -0
- package/dist/helpers/caller.js +40 -0
- package/dist/helpers/caller.js.map +1 -0
- package/dist/helpers/hook.d.ts +73 -0
- package/dist/helpers/hook.d.ts.map +1 -0
- package/dist/helpers/hook.js +244 -0
- package/dist/helpers/hook.js.map +1 -0
- package/dist/helpers/index.d.ts +12 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +11 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/one-shot.d.ts +27 -0
- package/dist/helpers/one-shot.d.ts.map +1 -0
- package/dist/helpers/one-shot.js +43 -0
- package/dist/helpers/one-shot.js.map +1 -0
- package/dist/helpers/schedule.d.ts +59 -0
- package/dist/helpers/schedule.d.ts.map +1 -0
- package/dist/helpers/schedule.js +118 -0
- package/dist/helpers/schedule.js.map +1 -0
- package/dist/helpers/types.d.ts +34 -0
- package/dist/helpers/types.d.ts.map +1 -0
- package/dist/helpers/types.js +11 -0
- package/dist/helpers/types.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/inference.d.ts +27 -0
- package/dist/inference.d.ts.map +1 -0
- package/dist/inference.js +34 -0
- package/dist/inference.js.map +1 -0
- package/dist/messages.d.ts +64 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +17 -0
- package/dist/messages.js.map +1 -0
- package/dist/orchestrator.d.ts +56 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +62 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/patterns/bounded-fanout-of.d.ts +61 -0
- package/dist/patterns/bounded-fanout-of.d.ts.map +1 -0
- package/dist/patterns/bounded-fanout-of.js +142 -0
- package/dist/patterns/bounded-fanout-of.js.map +1 -0
- package/dist/patterns/bounded-fanout.d.ts +111 -0
- package/dist/patterns/bounded-fanout.d.ts.map +1 -0
- package/dist/patterns/bounded-fanout.js +151 -0
- package/dist/patterns/bounded-fanout.js.map +1 -0
- package/dist/patterns/index.d.ts +14 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +13 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/intent-gate.d.ts +27 -0
- package/dist/patterns/intent-gate.d.ts.map +1 -0
- package/dist/patterns/intent-gate.js +32 -0
- package/dist/patterns/intent-gate.js.map +1 -0
- package/dist/patterns/match.d.ts +30 -0
- package/dist/patterns/match.d.ts.map +1 -0
- package/dist/patterns/match.js +58 -0
- package/dist/patterns/match.js.map +1 -0
- package/dist/patterns/parallel-fanout.d.ts +28 -0
- package/dist/patterns/parallel-fanout.d.ts.map +1 -0
- package/dist/patterns/parallel-fanout.js +24 -0
- package/dist/patterns/parallel-fanout.js.map +1 -0
- package/dist/patterns/parallel-phases.d.ts +27 -0
- package/dist/patterns/parallel-phases.d.ts.map +1 -0
- package/dist/patterns/parallel-phases.js +77 -0
- package/dist/patterns/parallel-phases.js.map +1 -0
- package/dist/patterns/preflight-confidence.d.ts +20 -0
- package/dist/patterns/preflight-confidence.d.ts.map +1 -0
- package/dist/patterns/preflight-confidence.js +38 -0
- package/dist/patterns/preflight-confidence.js.map +1 -0
- package/dist/patterns/spot-check.d.ts +19 -0
- package/dist/patterns/spot-check.d.ts.map +1 -0
- package/dist/patterns/spot-check.js +33 -0
- package/dist/patterns/spot-check.js.map +1 -0
- package/dist/patterns/sub-pipeline.d.ts +84 -0
- package/dist/patterns/sub-pipeline.d.ts.map +1 -0
- package/dist/patterns/sub-pipeline.js +90 -0
- package/dist/patterns/sub-pipeline.js.map +1 -0
- package/dist/patterns/synthesize-with-followup.d.ts +35 -0
- package/dist/patterns/synthesize-with-followup.d.ts.map +1 -0
- package/dist/patterns/synthesize-with-followup.js +45 -0
- package/dist/patterns/synthesize-with-followup.js.map +1 -0
- package/dist/patterns/while-condition.d.ts +31 -0
- package/dist/patterns/while-condition.d.ts.map +1 -0
- package/dist/patterns/while-condition.js +59 -0
- package/dist/patterns/while-condition.js.map +1 -0
- package/dist/patterns/with-retry.d.ts +37 -0
- package/dist/patterns/with-retry.d.ts.map +1 -0
- package/dist/patterns/with-retry.js +73 -0
- package/dist/patterns/with-retry.js.map +1 -0
- package/dist/phase.d.ts +78 -0
- package/dist/phase.d.ts.map +1 -0
- package/dist/phase.js +36 -0
- package/dist/phase.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +4 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/job-runner.d.ts +67 -0
- package/dist/session/job-runner.d.ts.map +1 -0
- package/dist/session/job-runner.js +131 -0
- package/dist/session/job-runner.js.map +1 -0
- package/dist/session/job-store.d.ts +98 -0
- package/dist/session/job-store.d.ts.map +1 -0
- package/dist/session/job-store.js +37 -0
- package/dist/session/job-store.js.map +1 -0
- package/dist/session/sqlite-job-store.d.ts +40 -0
- package/dist/session/sqlite-job-store.d.ts.map +1 -0
- package/dist/session/sqlite-job-store.js +200 -0
- package/dist/session/sqlite-job-store.js.map +1 -0
- package/dist/session/sse.d.ts +60 -0
- package/dist/session/sse.d.ts.map +1 -0
- package/dist/session/sse.js +97 -0
- package/dist/session/sse.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +44 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +74 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/triggers/index.d.ts +15 -0
- package/dist/triggers/index.d.ts.map +1 -0
- package/dist/triggers/index.js +14 -0
- package/dist/triggers/index.js.map +1 -0
- package/dist/triggers/run-trigger.d.ts +86 -0
- package/dist/triggers/run-trigger.d.ts.map +1 -0
- package/dist/triggers/run-trigger.js +146 -0
- package/dist/triggers/run-trigger.js.map +1 -0
- package/dist/triggers/timer-trigger.d.ts +46 -0
- package/dist/triggers/timer-trigger.d.ts.map +1 -0
- package/dist/triggers/timer-trigger.js +74 -0
- package/dist/triggers/timer-trigger.js.map +1 -0
- package/dist/triggers/types.d.ts +61 -0
- package/dist/triggers/types.d.ts.map +1 -0
- package/dist/triggers/types.js +23 -0
- package/dist/triggers/types.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable cross-run memory.
|
|
3
|
+
*
|
|
4
|
+
* thread-phase ships no implementations; callers wire one in via
|
|
5
|
+
* `AgentRunOptions.memoryProvider`. The interface intentionally maps to
|
|
6
|
+
* the lowest common denominator across backends like Honcho, Letta, and
|
|
7
|
+
* Mem0 — `recall` returns a string (the backend's distilled summary or
|
|
8
|
+
* raw recall blob), and `remember` ingests an event window from the run
|
|
9
|
+
* that just completed.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
import type { AgentEvent } from './protocol.js';
|
|
14
|
+
/**
|
|
15
|
+
* Scope key for a memory provider. `userId` is the partition every
|
|
16
|
+
* backend expects; `appId` and `sessionId` narrow further when supported.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export interface MemoryScope {
|
|
21
|
+
userId: string;
|
|
22
|
+
appId?: string;
|
|
23
|
+
sessionId?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The provider contract.
|
|
27
|
+
*
|
|
28
|
+
* Note: implementations are not required to provide read-your-writes
|
|
29
|
+
* consistency. A `remember()` immediately followed by a `recall()` may
|
|
30
|
+
* not see the new content if the backend does async indexing (Honcho's
|
|
31
|
+
* derivers, for example). Callers that need strict ordering should
|
|
32
|
+
* persist their own representation alongside the provider.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export interface MemoryProvider {
|
|
37
|
+
recall(scope: MemoryScope, query?: string): Promise<string>;
|
|
38
|
+
remember(scope: MemoryScope, events: ReadonlyArray<AgentEvent>): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/agents/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5D,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable cross-run memory.
|
|
3
|
+
*
|
|
4
|
+
* thread-phase ships no implementations; callers wire one in via
|
|
5
|
+
* `AgentRunOptions.memoryProvider`. The interface intentionally maps to
|
|
6
|
+
* the lowest common denominator across backends like Honcho, Letta, and
|
|
7
|
+
* Mem0 — `recall` returns a string (the backend's distilled summary or
|
|
8
|
+
* raw recall blob), and `remember` ingests an event window from the run
|
|
9
|
+
* that just completed.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/agents/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentAdapter protocol — the type surface every adapter speaks.
|
|
3
|
+
*
|
|
4
|
+
* Adapters wrap heterogeneous coding-agent runtimes (the in-tree inference
|
|
5
|
+
* loop, pi, Claude Code, OpenAI Agents SDK, ...) behind a single shape so
|
|
6
|
+
* thread-phase patterns can compose them uniformly. The protocol is types
|
|
7
|
+
* and pure utilities; runtime adapters live in sibling packages.
|
|
8
|
+
*
|
|
9
|
+
* @internal — surface is in development and not covered by semver until
|
|
10
|
+
* AgentAdapter v1 ships. See `potential_feature.md` for the design spec.
|
|
11
|
+
*/
|
|
12
|
+
import type { ActivityEntry, FinishReason, UsageInfo } from '../agent/types.js';
|
|
13
|
+
import type { ToolCall } from '../messages.js';
|
|
14
|
+
import type { MemoryProvider, MemoryScope } from './memory.js';
|
|
15
|
+
export type { MemoryProvider, MemoryScope } from './memory.js';
|
|
16
|
+
/**
|
|
17
|
+
* Hint an adapter can persist to resume a conversation in a later run.
|
|
18
|
+
*
|
|
19
|
+
* - `response-id` matches OpenAI's `previous_response_id` continuation.
|
|
20
|
+
* - `session-file` is the on-disk transcript used by pi and Claude Code.
|
|
21
|
+
* - `opaque` is the fallback for adapters with proprietary continuation state.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export type ResumeToken = {
|
|
26
|
+
kind: 'response-id';
|
|
27
|
+
id: string;
|
|
28
|
+
provider: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'session-file';
|
|
31
|
+
path: string;
|
|
32
|
+
messageIndex?: number;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'opaque';
|
|
35
|
+
data: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Cross-process-friendly error shape. Subprocess adapters can only surface
|
|
39
|
+
* serialized errors anyway, so making it uniform avoids a footgun where
|
|
40
|
+
* callers conditionally have raw `Error` instances vs. plain objects.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export interface SerializableError {
|
|
45
|
+
name: string;
|
|
46
|
+
message: string;
|
|
47
|
+
stack?: string;
|
|
48
|
+
cause?: SerializableError;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Canonical event vocabulary. Every adapter translates its native event
|
|
52
|
+
* stream into this discriminated union. The `native` variant is the escape
|
|
53
|
+
* hatch for adapter-specific signals (pi compaction, OpenAI handoffs, etc.) —
|
|
54
|
+
* consumers filter by `source` to handle them safely.
|
|
55
|
+
*
|
|
56
|
+
* Ordering invariant: `agent_start` is the first non-`native` event,
|
|
57
|
+
* `agent_end` the last; exactly one of each per run.
|
|
58
|
+
*
|
|
59
|
+
* The `thinking` variant is for adapters that surface reasoning content
|
|
60
|
+
* separately from final text (Anthropic extended thinking, OpenAI Responses
|
|
61
|
+
* reasoning items, pi inner monologue). The in-tree `inferenceAgent` never
|
|
62
|
+
* emits it; OpenAI-compatible chat-completions has no reasoning channel.
|
|
63
|
+
*
|
|
64
|
+
* The `error.transient` flag distinguishes recoverable failures (rate limits,
|
|
65
|
+
* upstream 5xx, intermittent network) from terminal ones (invalid auth,
|
|
66
|
+
* malformed request, schema violation). Adapter authors set `true` only when
|
|
67
|
+
* a sensible retry policy could succeed without user intervention.
|
|
68
|
+
*
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export type AgentEvent = {
|
|
72
|
+
type: 'agent_start';
|
|
73
|
+
source: string;
|
|
74
|
+
traceId?: string;
|
|
75
|
+
resumeToken?: ResumeToken;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'text';
|
|
78
|
+
source: string;
|
|
79
|
+
traceId?: string;
|
|
80
|
+
delta: string;
|
|
81
|
+
} | {
|
|
82
|
+
type: 'thinking';
|
|
83
|
+
source: string;
|
|
84
|
+
traceId?: string;
|
|
85
|
+
delta: string;
|
|
86
|
+
} | {
|
|
87
|
+
type: 'tool_call';
|
|
88
|
+
source: string;
|
|
89
|
+
traceId?: string;
|
|
90
|
+
id: string;
|
|
91
|
+
name: string;
|
|
92
|
+
input: unknown;
|
|
93
|
+
} | {
|
|
94
|
+
type: 'tool_result';
|
|
95
|
+
source: string;
|
|
96
|
+
traceId?: string;
|
|
97
|
+
id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
output: unknown;
|
|
100
|
+
isError: boolean;
|
|
101
|
+
} | {
|
|
102
|
+
type: 'turn_end';
|
|
103
|
+
source: string;
|
|
104
|
+
traceId?: string;
|
|
105
|
+
assistantText: string;
|
|
106
|
+
usage?: UsageInfo;
|
|
107
|
+
toolCallCount: number;
|
|
108
|
+
} | {
|
|
109
|
+
type: 'agent_end';
|
|
110
|
+
source: string;
|
|
111
|
+
traceId?: string;
|
|
112
|
+
reason: AgentFinishReason;
|
|
113
|
+
resumeToken?: ResumeToken;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'error';
|
|
116
|
+
source: string;
|
|
117
|
+
traceId?: string;
|
|
118
|
+
error: SerializableError;
|
|
119
|
+
transient: boolean;
|
|
120
|
+
} | {
|
|
121
|
+
type: 'native';
|
|
122
|
+
source: string;
|
|
123
|
+
traceId?: string;
|
|
124
|
+
kind: string;
|
|
125
|
+
payload: unknown;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Adapter finish reasons. Extends the existing runner `FinishReason` with
|
|
129
|
+
* `'aborted'` so cancellation has a first-class encoding instead of being
|
|
130
|
+
* folded into `'error'`.
|
|
131
|
+
*
|
|
132
|
+
* @internal
|
|
133
|
+
*/
|
|
134
|
+
export type AgentFinishReason = FinishReason | 'aborted';
|
|
135
|
+
/**
|
|
136
|
+
* Adapter run result. Structural superset of the runner `AgentRunResult`:
|
|
137
|
+
* the runner's required fields appear here with the same shapes, and adapter
|
|
138
|
+
* additions (`activity`, `parsed`, `resumeToken`, `messages`) are optional so
|
|
139
|
+
* non-runner adapters can omit fields they don't naturally produce.
|
|
140
|
+
*
|
|
141
|
+
* The runner's `AgentRunResult` is assignable to this type without change
|
|
142
|
+
* (required → optional is widening); adapters that don't emit activity entries
|
|
143
|
+
* simply leave the field undefined.
|
|
144
|
+
*
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
export interface AgentRunResult {
|
|
148
|
+
/** Final text output. May be JSON; callers parseJSON or parseStructured. */
|
|
149
|
+
text: string;
|
|
150
|
+
/** Reason the agent stopped, widened with `'aborted'`. */
|
|
151
|
+
finishReason: AgentFinishReason;
|
|
152
|
+
/** Token usage summed across rounds. */
|
|
153
|
+
usage: UsageInfo;
|
|
154
|
+
/** Every tool call the adapter actually executed, in order. */
|
|
155
|
+
executedToolCalls: ToolCall[];
|
|
156
|
+
/** Adapter-native activity log; optional because not every adapter produces one. */
|
|
157
|
+
activity?: ReadonlyArray<ActivityEntry>;
|
|
158
|
+
/** Populated when the adapter was given an `outputSchema` and parsing succeeded. */
|
|
159
|
+
parsed?: unknown;
|
|
160
|
+
/**
|
|
161
|
+
* Populated when the adapter was given an `outputSchema` and parsing
|
|
162
|
+
* FAILED. Mutually exclusive with `parsed` — at most one is set. Callers
|
|
163
|
+
* detect parse failure via `parsed === undefined && parseError !== undefined`
|
|
164
|
+
* and decide whether to retry (typically via `followUp()` on a
|
|
165
|
+
* `SteerableAgentRun`). Parse failures are NOT emitted as `error` events
|
|
166
|
+
* because the agent did its job — the output simply didn't match the schema.
|
|
167
|
+
*/
|
|
168
|
+
parseError?: SerializableError;
|
|
169
|
+
/** Adapter-produced continuation hint, persisted for a later run. */
|
|
170
|
+
resumeToken?: ResumeToken;
|
|
171
|
+
/**
|
|
172
|
+
* Adapter-native message log when available. Typed loosely because each
|
|
173
|
+
* adapter preserves a different fidelity (Claude Code content arrays,
|
|
174
|
+
* OpenAI reasoning items, etc.); consumers that need typed access
|
|
175
|
+
* deserialize per `source`.
|
|
176
|
+
*/
|
|
177
|
+
messages?: ReadonlyArray<unknown>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Static introspection over adapter abilities. Patterns and the JobRunner
|
|
181
|
+
* call `requireCapability` against this at construction time so pipelines
|
|
182
|
+
* fail fast before any LLM tokens are spent.
|
|
183
|
+
*
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
export interface AgentCapabilities {
|
|
187
|
+
streaming: 'text' | 'turns' | 'final-only';
|
|
188
|
+
cancellation: 'cooperative' | 'forceful' | 'none';
|
|
189
|
+
resumption: 'response-id' | 'session-file' | 'opaque' | 'none';
|
|
190
|
+
structuredOutput: 'native' | 'prompted' | 'none';
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Cross-cutting event sink. Orchestrators (JobRunner, audit consumers)
|
|
194
|
+
* create one bus and pass it to every adapter under their scope to observe
|
|
195
|
+
* heterogeneous adapter events through a single seam.
|
|
196
|
+
*
|
|
197
|
+
* Distinct from `AgentRun.events`, which is a single-consumer stream owned
|
|
198
|
+
* by the caller of an individual adapter run. The bus is the multi-subscriber
|
|
199
|
+
* fan-out; the run's events iterable is consumed once.
|
|
200
|
+
*
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
export interface AgentEventBus {
|
|
204
|
+
emit(event: AgentEvent): void;
|
|
205
|
+
on(handler: (event: AgentEvent) => void | Promise<void>): () => void;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Options passed to every adapter invocation. All fields are optional;
|
|
209
|
+
* adapters ignore the ones they can't honor (after declaring so via
|
|
210
|
+
* `AgentCapabilities`).
|
|
211
|
+
*
|
|
212
|
+
* @internal
|
|
213
|
+
*/
|
|
214
|
+
export interface AgentRunOptions {
|
|
215
|
+
signal?: AbortSignal;
|
|
216
|
+
eventBus?: AgentEventBus;
|
|
217
|
+
traceId?: string;
|
|
218
|
+
memoryProvider?: MemoryProvider;
|
|
219
|
+
memoryScope?: MemoryScope;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Handle for a single adapter invocation.
|
|
223
|
+
*
|
|
224
|
+
* Lifecycle invariants:
|
|
225
|
+
* - `events` is a single-consumer `AsyncIterable`; iterate it once. Use
|
|
226
|
+
* `AgentEventBus` for multi-subscriber fan-out.
|
|
227
|
+
* - `result` always resolves, never rejects. Errors are encoded as
|
|
228
|
+
* `finishReason: 'error'` with a prior `error` event.
|
|
229
|
+
* - `abort()` is idempotent.
|
|
230
|
+
*
|
|
231
|
+
* @internal
|
|
232
|
+
*/
|
|
233
|
+
export interface AgentRun<TResult extends AgentRunResult = AgentRunResult> {
|
|
234
|
+
readonly events: AsyncIterable<AgentEvent>;
|
|
235
|
+
readonly result: Promise<TResult>;
|
|
236
|
+
abort(reason?: string): void;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Subtype for adapters that support mid-stream steering or post-turn
|
|
240
|
+
* follow-up. Sibling packages (the `@autonome-research/thread-phase-agents` extension surface)
|
|
241
|
+
* return this from adapters whose underlying runtime accepts these calls —
|
|
242
|
+
* e.g. ACP sessions, which can take multiple `session/prompt` requests
|
|
243
|
+
* before the session is closed.
|
|
244
|
+
*
|
|
245
|
+
* `AgentAdapter`'s declared return type stays `AgentRun` for variance
|
|
246
|
+
* (SteerableAgentRun is a subtype). Consumers narrow at the call site
|
|
247
|
+
* via `isSteerable(run)`.
|
|
248
|
+
*
|
|
249
|
+
* @internal
|
|
250
|
+
*/
|
|
251
|
+
export interface SteerableAgentRun<TResult extends AgentRunResult = AgentRunResult> extends AgentRun<TResult> {
|
|
252
|
+
/**
|
|
253
|
+
* Send a steering message mid-stream — only meaningful for runtimes
|
|
254
|
+
* that accept in-flight input (currently none in the bundled adapter
|
|
255
|
+
* set; ACP-based adapters reject with a clear capability error).
|
|
256
|
+
*/
|
|
257
|
+
steer(message: string): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Queue an additional prompt to send after the current prompt response
|
|
260
|
+
* completes. Multiple follow-ups can stack; the chassis drains the
|
|
261
|
+
* queue between turns. Throws after the run has reached `agent_end`.
|
|
262
|
+
*/
|
|
263
|
+
followUp(message: string): Promise<void>;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Type guard for `SteerableAgentRun`. Use at consumer call sites to
|
|
267
|
+
* safely narrow an `AgentRun` returned by an adapter that may or may
|
|
268
|
+
* not be steerable:
|
|
269
|
+
*
|
|
270
|
+
* const run = hermesAgent.adapter(...);
|
|
271
|
+
* if (isSteerable(run)) await run.followUp('also do X');
|
|
272
|
+
*
|
|
273
|
+
* @internal
|
|
274
|
+
*/
|
|
275
|
+
export declare function isSteerable<TResult extends AgentRunResult>(run: AgentRun<TResult>): run is SteerableAgentRun<TResult>;
|
|
276
|
+
/**
|
|
277
|
+
* The adapter signature. Must return synchronously — the run starts lazily
|
|
278
|
+
* when either `events` is iterated or `result` is awaited.
|
|
279
|
+
*
|
|
280
|
+
* @internal
|
|
281
|
+
*/
|
|
282
|
+
export type AgentAdapter<TConfig, TResult extends AgentRunResult = AgentRunResult> = (config: TConfig, options?: AgentRunOptions) => AgentRun<TResult>;
|
|
283
|
+
/**
|
|
284
|
+
* Adapter registration metadata. Bundles a stable `id` (used as `source` on
|
|
285
|
+
* every emitted event), a declared `capabilities` descriptor, and the
|
|
286
|
+
* adapter function itself.
|
|
287
|
+
*
|
|
288
|
+
* @internal
|
|
289
|
+
*/
|
|
290
|
+
export interface AgentAdapterMeta<TConfig, TResult extends AgentRunResult = AgentRunResult> {
|
|
291
|
+
readonly id: string;
|
|
292
|
+
readonly capabilities: AgentCapabilities;
|
|
293
|
+
readonly adapter: AgentAdapter<TConfig, TResult>;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Identity at runtime; exists for inference and as a hook for future
|
|
297
|
+
* telemetry. Modeled on Vitest's `defineConfig`.
|
|
298
|
+
*
|
|
299
|
+
* @internal
|
|
300
|
+
*/
|
|
301
|
+
export declare function defineAgentAdapter<TConfig, TResult extends AgentRunResult = AgentRunResult>(meta: AgentAdapterMeta<TConfig, TResult>): AgentAdapterMeta<TConfig, TResult>;
|
|
302
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/agents/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,E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EAAE,OAAO,CAAC,CAAC;CAClD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,SAAS,cAAc,GAAG,cAAc,EACzF,IAAI,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GACvC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAEpC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentAdapter protocol — the type surface every adapter speaks.
|
|
3
|
+
*
|
|
4
|
+
* Adapters wrap heterogeneous coding-agent runtimes (the in-tree inference
|
|
5
|
+
* loop, pi, Claude Code, OpenAI Agents SDK, ...) behind a single shape so
|
|
6
|
+
* thread-phase patterns can compose them uniformly. The protocol is types
|
|
7
|
+
* and pure utilities; runtime adapters live in sibling packages.
|
|
8
|
+
*
|
|
9
|
+
* @internal — surface is in development and not covered by semver until
|
|
10
|
+
* AgentAdapter v1 ships. See `potential_feature.md` for the design spec.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Type guard for `SteerableAgentRun`. Use at consumer call sites to
|
|
14
|
+
* safely narrow an `AgentRun` returned by an adapter that may or may
|
|
15
|
+
* not be steerable:
|
|
16
|
+
*
|
|
17
|
+
* const run = hermesAgent.adapter(...);
|
|
18
|
+
* if (isSteerable(run)) await run.followUp('also do X');
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export function isSteerable(run) {
|
|
23
|
+
const candidate = run;
|
|
24
|
+
return (typeof candidate.followUp === 'function' &&
|
|
25
|
+
typeof candidate.steer === 'function');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Identity at runtime; exists for inference and as a hook for future
|
|
29
|
+
* telemetry. Modeled on Vitest's `defineConfig`.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export function defineAgentAdapter(meta) {
|
|
34
|
+
return meta;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/agents/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAsPH;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CACzB,GAAsB;IAEtB,MAAM,SAAS,GAAG,GAA0C,CAAC;IAC7D,OAAO,CACL,OAAO,SAAS,CAAC,QAAQ,KAAK,UAAU;QACxC,OAAO,SAAS,CAAC,KAAK,KAAK,UAAU,CACtC,CAAC;AACJ,CAAC;AA0BD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAwC;IAExC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for adapter authors.
|
|
3
|
+
*
|
|
4
|
+
* Every `AgentAdapter` does the same three things at construction:
|
|
5
|
+
* 1. Compose its abort signal — options.signal plus an internal controller
|
|
6
|
+
* driven by the returned `abort()` method.
|
|
7
|
+
* 2. Set up a queue-backed `AsyncIterable<AgentEvent>` with a producer
|
|
8
|
+
* that doesn't block and a consumer that's single-shot (multi-cast
|
|
9
|
+
* goes through `AgentEventBus`).
|
|
10
|
+
* 3. Defer the actual work to a lazy `runOnce()` that starts when either
|
|
11
|
+
* `events` is iterated or `result` is awaited, whichever comes first.
|
|
12
|
+
*
|
|
13
|
+
* These helpers capture those patterns so per-adapter code only describes
|
|
14
|
+
* the translation between its underlying runtime and canonical
|
|
15
|
+
* `AgentEvent`s. The patterns themselves stay invariant.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
import type { AgentEvent, AgentEventBus } from './protocol.js';
|
|
20
|
+
/** @internal */
|
|
21
|
+
export interface CompositeAbort {
|
|
22
|
+
/** Signal an adapter passes down to its underlying runtime. Aborts when EITHER input does. */
|
|
23
|
+
readonly signal: AbortSignal;
|
|
24
|
+
/** The internal controller driven by the adapter's `abort()` method. */
|
|
25
|
+
readonly controller: AbortController;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compose an optional external `AbortSignal` (from `AgentRunOptions.signal`)
|
|
29
|
+
* with an internal controller into a single signal. Uses `AbortSignal.any`
|
|
30
|
+
* (Node 20+), so there's no manual listener that would pin a closure if
|
|
31
|
+
* the external signal outlives the run.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare function composeAbort(external?: AbortSignal): CompositeAbort;
|
|
36
|
+
/** @internal */
|
|
37
|
+
export interface EventQueue {
|
|
38
|
+
/** Producer — emit an event. Mirrors to the bus if one was supplied. Non-blocking. */
|
|
39
|
+
push(event: AgentEvent): void;
|
|
40
|
+
/** Mark the stream complete. Drains parked waiters with `done: true`. Idempotent. */
|
|
41
|
+
close(): void;
|
|
42
|
+
/** Whether `close()` has been called. */
|
|
43
|
+
isClosed(): boolean;
|
|
44
|
+
/** The consumer-side iterable. Single-shot — vending twice throws. */
|
|
45
|
+
readonly events: AsyncIterable<AgentEvent>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Single-producer / single-consumer queue with optional `AgentEventBus`
|
|
49
|
+
* mirroring. The producer never blocks; events queue when no consumer is
|
|
50
|
+
* waiting. The consumer is single-shot — vending the iterator twice
|
|
51
|
+
* throws (use `AgentEventBus` for multi-subscriber fan-out).
|
|
52
|
+
*
|
|
53
|
+
* Bus errors are swallowed: the producer must never fail because of a
|
|
54
|
+
* misbehaving subscriber. Bus implementations are responsible for
|
|
55
|
+
* containing their own handler errors.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export declare function createEventQueue(bus?: AgentEventBus): EventQueue;
|
|
60
|
+
/**
|
|
61
|
+
* Wrap an inner iterable so that iterating it triggers a lazy-start
|
|
62
|
+
* callback. Adapter `events` property uses this to ensure that iterating
|
|
63
|
+
* events alone (without awaiting `result`) still kicks off the run —
|
|
64
|
+
* otherwise the iterator would park a waiter on an empty queue with no
|
|
65
|
+
* producer, deadlocking.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export declare function lazyEvents(inner: AsyncIterable<AgentEvent>, start: () => void): AsyncIterable<AgentEvent>;
|
|
70
|
+
//# sourceMappingURL=run-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-helpers.d.ts","sourceRoot":"","sources":["../../src/agents/run-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAM/D,gBAAgB;AAChB,MAAM,WAAW,cAAc;IAC7B,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,WAAW,GAAG,cAAc,CAMnE;AAMD,gBAAgB;AAChB,MAAM,WAAW,UAAU;IACzB,sFAAsF;IACtF,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAC9B,qFAAqF;IACrF,KAAK,IAAI,IAAI,CAAC;IACd,yCAAyC;IACzC,QAAQ,IAAI,OAAO,CAAC;IACpB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;CAC5C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,CAAC,EAAE,aAAa,GAAG,UAAU,CAkEhE;AAMD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,EAChC,KAAK,EAAE,MAAM,IAAI,GAChB,aAAa,CAAC,UAAU,CAAC,CAO3B"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for adapter authors.
|
|
3
|
+
*
|
|
4
|
+
* Every `AgentAdapter` does the same three things at construction:
|
|
5
|
+
* 1. Compose its abort signal — options.signal plus an internal controller
|
|
6
|
+
* driven by the returned `abort()` method.
|
|
7
|
+
* 2. Set up a queue-backed `AsyncIterable<AgentEvent>` with a producer
|
|
8
|
+
* that doesn't block and a consumer that's single-shot (multi-cast
|
|
9
|
+
* goes through `AgentEventBus`).
|
|
10
|
+
* 3. Defer the actual work to a lazy `runOnce()` that starts when either
|
|
11
|
+
* `events` is iterated or `result` is awaited, whichever comes first.
|
|
12
|
+
*
|
|
13
|
+
* These helpers capture those patterns so per-adapter code only describes
|
|
14
|
+
* the translation between its underlying runtime and canonical
|
|
15
|
+
* `AgentEvent`s. The patterns themselves stay invariant.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Compose an optional external `AbortSignal` (from `AgentRunOptions.signal`)
|
|
21
|
+
* with an internal controller into a single signal. Uses `AbortSignal.any`
|
|
22
|
+
* (Node 20+), so there's no manual listener that would pin a closure if
|
|
23
|
+
* the external signal outlives the run.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export function composeAbort(external) {
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
const signal = external
|
|
30
|
+
? AbortSignal.any([external, controller.signal])
|
|
31
|
+
: controller.signal;
|
|
32
|
+
return { signal, controller };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Single-producer / single-consumer queue with optional `AgentEventBus`
|
|
36
|
+
* mirroring. The producer never blocks; events queue when no consumer is
|
|
37
|
+
* waiting. The consumer is single-shot — vending the iterator twice
|
|
38
|
+
* throws (use `AgentEventBus` for multi-subscriber fan-out).
|
|
39
|
+
*
|
|
40
|
+
* Bus errors are swallowed: the producer must never fail because of a
|
|
41
|
+
* misbehaving subscriber. Bus implementations are responsible for
|
|
42
|
+
* containing their own handler errors.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export function createEventQueue(bus) {
|
|
47
|
+
const queued = [];
|
|
48
|
+
const waiters = [];
|
|
49
|
+
let closed = false;
|
|
50
|
+
let iteratorVended = false;
|
|
51
|
+
const push = (event) => {
|
|
52
|
+
if (closed)
|
|
53
|
+
return;
|
|
54
|
+
if (bus) {
|
|
55
|
+
try {
|
|
56
|
+
bus.emit(event);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// bus implementation handles its own subscriber errors
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const next = waiters.shift();
|
|
63
|
+
if (next) {
|
|
64
|
+
next({ value: event, done: false });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
queued.push(event);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const close = () => {
|
|
71
|
+
if (closed)
|
|
72
|
+
return;
|
|
73
|
+
closed = true;
|
|
74
|
+
while (waiters.length > 0) {
|
|
75
|
+
const w = waiters.shift();
|
|
76
|
+
w({ value: undefined, done: true });
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const events = {
|
|
80
|
+
[Symbol.asyncIterator]() {
|
|
81
|
+
if (iteratorVended) {
|
|
82
|
+
throw new Error('AgentRun.events is single-consumer; iterate it once. Use AgentEventBus (options.eventBus) for multi-subscriber fan-out.');
|
|
83
|
+
}
|
|
84
|
+
iteratorVended = true;
|
|
85
|
+
return {
|
|
86
|
+
next() {
|
|
87
|
+
if (queued.length > 0) {
|
|
88
|
+
return Promise.resolve({ value: queued.shift(), done: false });
|
|
89
|
+
}
|
|
90
|
+
if (closed) {
|
|
91
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
92
|
+
}
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
waiters.push(resolve);
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
return() {
|
|
98
|
+
close();
|
|
99
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
push,
|
|
106
|
+
close,
|
|
107
|
+
isClosed: () => closed,
|
|
108
|
+
events,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// lazyEvents
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* Wrap an inner iterable so that iterating it triggers a lazy-start
|
|
116
|
+
* callback. Adapter `events` property uses this to ensure that iterating
|
|
117
|
+
* events alone (without awaiting `result`) still kicks off the run —
|
|
118
|
+
* otherwise the iterator would park a waiter on an empty queue with no
|
|
119
|
+
* producer, deadlocking.
|
|
120
|
+
*
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
export function lazyEvents(inner, start) {
|
|
124
|
+
return {
|
|
125
|
+
[Symbol.asyncIterator]() {
|
|
126
|
+
start();
|
|
127
|
+
return inner[Symbol.asyncIterator]();
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=run-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-helpers.js","sourceRoot":"","sources":["../../src/agents/run-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAgBH;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,QAAsB;IACjD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,QAAQ;QACrB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,EA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D,cAAc,GAAG,IAAI,CAAC;YACtB,OAAO;gBACL,IAAI;oBACF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBACtB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;oBAClE,CAAC;oBACD,IAAI,MAAM,EAAE,CAAC;wBACX,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;oBAC3D,CAAC;oBACD,OAAO,IAAI,OAAO,CAA6B,CAAC,OAAO,EAAE,EAAE;wBACzD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBACxB,CAAC,CAAC,CAAC;gBACL,CAAC;gBACD,MAAM;oBACJ,KAAK,EAAE,CAAC;oBACR,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3D,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,KAAK;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;QACtB,MAAM;KACP,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,KAAgC,EAChC,KAAiB;IAEjB,OAAO;QACL,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,KAAK,EAAE,CAAC;YACR,OAAO,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a thrown value into the wire-friendly `SerializableError` shape
|
|
3
|
+
* that adapters emit on `error` events. Walks the `cause` chain so wrapped
|
|
4
|
+
* errors don't lose context across the subprocess boundary.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
import type { SerializableError } from './protocol.js';
|
|
9
|
+
/**
|
|
10
|
+
* Normalize any thrown value to a `SerializableError`. Non-`Error` throws
|
|
11
|
+
* become `{ name: 'NonError', message: String(err) }` so the field shape
|
|
12
|
+
* stays uniform — consumers can rely on `name` and `message` always being
|
|
13
|
+
* present.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function serializeError(err: unknown): SerializableError;
|
|
18
|
+
//# sourceMappingURL=serialize-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-error.d.ts","sourceRoot":"","sources":["../../src/agents/serialize-error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,iBAAiB,CAU9D"}
|