@agent-relay/harness-driver 7.1.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/README.md +9 -0
- package/dist/actions.d.ts +10 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +140 -0
- package/dist/actions.js.map +1 -0
- package/dist/broker-driver.d.ts +17 -0
- package/dist/broker-driver.d.ts.map +1 -0
- package/dist/broker-driver.js +56 -0
- package/dist/broker-driver.js.map +1 -0
- package/dist/broker-path.d.ts +31 -0
- package/dist/broker-path.d.ts.map +1 -0
- package/dist/broker-path.js +216 -0
- package/dist/broker-path.js.map +1 -0
- package/dist/client.d.ts +293 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +892 -0
- package/dist/client.js.map +1 -0
- package/dist/driver-types.d.ts +43 -0
- package/dist/driver-types.d.ts.map +1 -0
- package/dist/driver-types.js +2 -0
- package/dist/driver-types.js.map +1 -0
- package/dist/event-bus.d.ts +57 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +76 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/harness.d.ts +82 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +96 -0
- package/dist/harness.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle-hooks.d.ts +166 -0
- package/dist/lifecycle-hooks.d.ts.map +1 -0
- package/dist/lifecycle-hooks.js +25 -0
- package/dist/lifecycle-hooks.js.map +1 -0
- package/dist/protocol.d.ts +527 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +2 -0
- package/dist/protocol.js.map +1 -0
- package/dist/transport.d.ts +104 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +520 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +120 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed lifecycle-hook surface for the managed driver client.
|
|
3
|
+
*
|
|
4
|
+
* Two kinds of events flow through the same registry:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Broker events** — `agentSpawned`, `agentReleased`, `agentExited`,
|
|
7
|
+
* `agentReady`, `agentIdle`, `agentExitRequested`,
|
|
8
|
+
* `agentActivityChanged`, `agentResult`, `messageReceived`,
|
|
9
|
+
* `messageSent`, `workerOutput`, `deliveryUpdate`, `channelSubscribed`,
|
|
10
|
+
* `channelUnsubscribed`. These fire when the broker emits the
|
|
11
|
+
* corresponding event over the WS stream.
|
|
12
|
+
* 2. **Call-site hooks** — `beforeAgentSpawn`, `afterAgentSpawn`,
|
|
13
|
+
* `beforeAgentRelease`, `afterAgentRelease`. These fire at the SDK
|
|
14
|
+
* call site (before / after the HTTP request), so handlers can
|
|
15
|
+
* observe — and, for `beforeAgentSpawn`, *modify* — the spawn input
|
|
16
|
+
* before it reaches the broker.
|
|
17
|
+
*
|
|
18
|
+
* The `beforeAgentSpawn` contract is the only one that supports
|
|
19
|
+
* mutation: handlers may return a {@link SpawnPatch} to merge into the
|
|
20
|
+
* input via shallow merge in registration order. All other hooks are
|
|
21
|
+
* observe-only — return type `void | Promise<void>`.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
import type { AgentRuntime, BrokerEvent, MessageInjectionMode } from './protocol.js';
|
|
25
|
+
import type { SpawnAgentResult, SpawnCliInput, SpawnPtyInput } from './types.js';
|
|
26
|
+
type SpawnInput = SpawnPtyInput | SpawnCliInput;
|
|
27
|
+
/**
|
|
28
|
+
* The subset of {@link SpawnPtyInput} / {@link SpawnCliInput} fields a
|
|
29
|
+
* `beforeAgentSpawn` handler may patch. Keeping this narrower than the full
|
|
30
|
+
* input type stops handlers from rewriting identity (`name`, `cli`,
|
|
31
|
+
* `cwd`) — those need to come from the caller.
|
|
32
|
+
*
|
|
33
|
+
* For array fields (`args`, `channels`) a patch *replaces* the array. To
|
|
34
|
+
* extend rather than replace, spread the current value:
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* relay.addListener('beforeAgentSpawn', (ctx) => ({
|
|
38
|
+
* args: [...(ctx.input.args ?? []), '--session-id', uuid],
|
|
39
|
+
* }));
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* When multiple handlers return patches, allowed patch fields merge in
|
|
43
|
+
* registration order; later handlers override earlier ones for the same key.
|
|
44
|
+
*/
|
|
45
|
+
export type SpawnPatch = Partial<Pick<SpawnPtyInput & SpawnCliInput, 'args' | 'channels' | 'task' | 'model' | 'team' | 'agentToken' | 'harnessConfig'>>;
|
|
46
|
+
export interface BeforeAgentSpawnContext<TInput extends SpawnInput = SpawnInput> {
|
|
47
|
+
/** Which spawn API was called. */
|
|
48
|
+
kind: 'pty' | 'cli' | 'headless';
|
|
49
|
+
/** Raw input the caller passed in. Treat as read-only — return a {@link SpawnPatch} to modify. */
|
|
50
|
+
input: Readonly<TInput>;
|
|
51
|
+
/** `process.pid` of the calling Node process. Useful for burn-style stamping. */
|
|
52
|
+
spawnerPid: number;
|
|
53
|
+
/** ISO timestamp captured the instant the hook chain started. */
|
|
54
|
+
spawnStartTs: string;
|
|
55
|
+
/** Resolved broker base URL the spawn will POST to. */
|
|
56
|
+
baseUrl: string;
|
|
57
|
+
}
|
|
58
|
+
export type BeforeAgentSpawnHandler = (ctx: BeforeAgentSpawnContext) => void | SpawnPatch | Promise<void | SpawnPatch>;
|
|
59
|
+
export interface AfterAgentSpawnContext<TInput extends SpawnInput = SpawnInput> extends BeforeAgentSpawnContext<TInput> {
|
|
60
|
+
/** Final input that was sent to the broker — original input merged with every handler's patch. */
|
|
61
|
+
resolvedInput: TInput;
|
|
62
|
+
/** Broker reply on success. */
|
|
63
|
+
result?: SpawnAgentResult;
|
|
64
|
+
/** Set when the broker call rejected. Mutually exclusive with `result`. */
|
|
65
|
+
error?: Error;
|
|
66
|
+
/** Wall-clock duration from `beforeAgentSpawn` start to here. */
|
|
67
|
+
durationMs: number;
|
|
68
|
+
}
|
|
69
|
+
export interface BeforeAgentReleaseContext {
|
|
70
|
+
name: string;
|
|
71
|
+
reason?: string;
|
|
72
|
+
baseUrl: string;
|
|
73
|
+
}
|
|
74
|
+
export interface AfterAgentReleaseContext extends BeforeAgentReleaseContext {
|
|
75
|
+
error?: Error;
|
|
76
|
+
durationMs: number;
|
|
77
|
+
}
|
|
78
|
+
export interface AgentIdlePayload {
|
|
79
|
+
name: string;
|
|
80
|
+
idleSecs: number;
|
|
81
|
+
}
|
|
82
|
+
export interface AgentExitRequestedPayload {
|
|
83
|
+
name: string;
|
|
84
|
+
reason: string;
|
|
85
|
+
}
|
|
86
|
+
export interface WorkerOutputPayload {
|
|
87
|
+
name: string;
|
|
88
|
+
stream: string;
|
|
89
|
+
chunk: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Object-shaped payload for channel subscribe / unsubscribe events. The
|
|
93
|
+
* pre-2.x single-callback fields took two positional args
|
|
94
|
+
* (`(agent, channels) => void`); the registry standardizes on an object
|
|
95
|
+
* payload so all events share the one-arg shape and future fields can be
|
|
96
|
+
* added without breaking handlers.
|
|
97
|
+
*/
|
|
98
|
+
export interface ChannelSubscriptionPayload {
|
|
99
|
+
agent: string;
|
|
100
|
+
channels: string[];
|
|
101
|
+
}
|
|
102
|
+
export interface DriverMessage {
|
|
103
|
+
eventId: string;
|
|
104
|
+
from: string;
|
|
105
|
+
to: string;
|
|
106
|
+
text: string;
|
|
107
|
+
threadId?: string;
|
|
108
|
+
data?: Record<string, unknown>;
|
|
109
|
+
mode?: MessageInjectionMode;
|
|
110
|
+
}
|
|
111
|
+
export interface DriverAgent {
|
|
112
|
+
readonly name: string;
|
|
113
|
+
readonly runtime: AgentRuntime;
|
|
114
|
+
readonly channels: string[];
|
|
115
|
+
readonly sessionId?: string;
|
|
116
|
+
readonly pid?: number;
|
|
117
|
+
readonly status?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface DriverAgentResult<T = unknown> {
|
|
120
|
+
name: string;
|
|
121
|
+
resultId: string;
|
|
122
|
+
final: boolean;
|
|
123
|
+
data: T;
|
|
124
|
+
metadata?: unknown;
|
|
125
|
+
}
|
|
126
|
+
export type DriverAgentActivityReason = 'delivery_queued' | 'delivery_injected' | 'delivery_active' | 'delivery_ack' | 'delivery_failed' | 'message_delivery_confirmed' | 'message_delivery_failed' | 'relay_inbound' | 'agent_idle' | 'agent_exited' | 'agent_released';
|
|
127
|
+
export interface DriverAgentActivityChange {
|
|
128
|
+
name: string;
|
|
129
|
+
active: boolean;
|
|
130
|
+
pendingDeliveries: number;
|
|
131
|
+
reason: DriverAgentActivityReason;
|
|
132
|
+
eventId?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Typed event map consumed by the {@link EventBus} that backs
|
|
136
|
+
* `AgentRelay.addListener` / `removeListener`.
|
|
137
|
+
*
|
|
138
|
+
* Each entry's tuple is the handler argument list (always length 1 here —
|
|
139
|
+
* payloads are objects rather than positional args).
|
|
140
|
+
*
|
|
141
|
+
* Declared as a `type` alias rather than an `interface` so it satisfies
|
|
142
|
+
* the `EventBus<E extends EventMap>` constraint without requiring callers
|
|
143
|
+
* to spell out an index signature.
|
|
144
|
+
*/
|
|
145
|
+
export type HarnessDriverEvents = {
|
|
146
|
+
messageReceived: [DriverMessage];
|
|
147
|
+
messageSent: [DriverMessage];
|
|
148
|
+
agentSpawned: [DriverAgent];
|
|
149
|
+
agentReleased: [DriverAgent];
|
|
150
|
+
agentExited: [DriverAgent];
|
|
151
|
+
agentReady: [DriverAgent];
|
|
152
|
+
workerOutput: [WorkerOutputPayload];
|
|
153
|
+
deliveryUpdate: [BrokerEvent];
|
|
154
|
+
agentExitRequested: [AgentExitRequestedPayload];
|
|
155
|
+
agentIdle: [AgentIdlePayload];
|
|
156
|
+
agentResult: [DriverAgentResult];
|
|
157
|
+
agentActivityChanged: [DriverAgentActivityChange];
|
|
158
|
+
channelSubscribed: [ChannelSubscriptionPayload];
|
|
159
|
+
channelUnsubscribed: [ChannelSubscriptionPayload];
|
|
160
|
+
beforeAgentSpawn: [BeforeAgentSpawnContext];
|
|
161
|
+
afterAgentSpawn: [AfterAgentSpawnContext];
|
|
162
|
+
beforeAgentRelease: [BeforeAgentReleaseContext];
|
|
163
|
+
afterAgentRelease: [AfterAgentReleaseContext];
|
|
164
|
+
};
|
|
165
|
+
export {};
|
|
166
|
+
//# sourceMappingURL=lifecycle-hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-hooks.d.ts","sourceRoot":"","sources":["../src/lifecycle-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEjF,KAAK,UAAU,GAAG,aAAa,GAAG,aAAa,CAAC;AAIhD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAC9B,IAAI,CACF,aAAa,GAAG,aAAa,EAC7B,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,YAAY,GAAG,eAAe,CACjF,CACF,CAAC;AAIF,MAAM,WAAW,uBAAuB,CAAC,MAAM,SAAS,UAAU,GAAG,UAAU;IAC7E,kCAAkC;IAClC,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,UAAU,CAAC;IACjC,kGAAkG;IAClG,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,iFAAiF;IACjF,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,YAAY,EAAE,MAAM,C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CAAC,CAAC;IAC7B,YAAY,EAAE,CAAC,WAAW,CAAC,CAAC;IAC5B,aAAa,EAAE,CAAC,WAAW,CAAC,CAAC;IAC7B,WAAW,EAAE,CAAC,WAAW,CAAC,CAAC;IAC3B,UAAU,EAAE,CAAC,WAAW,CAAC,CAAC;IAC1B,YAAY,EAAE,CAAC,mBAAmB,CAAC,CAAC;IACpC,cAAc,EAAE,CAAC,WAAW,CAAC,CAAC;IAC9B,kBAAkB,EAAE,CAAC,yBAAyB,CAAC,CAAC;IAChD,SAAS,EAAE,CAAC,gBAAgB,CAAC,CAAC;IAC9B,WAAW,EAAE,CAAC,iBAAiB,CAAC,CAAC;IACjC,oBAAoB,EAAE,CAAC,yBAAyB,CAAC,CAAC;IAClD,iBAAiB,EAAE,CAAC,0BAA0B,CAAC,CAAC;IAChD,mBAAmB,EAAE,CAAC,0BAA0B,CAAC,CAAC;IAGlD,gBAAgB,EAAE,CAAC,uBAAuB,CAAC,CAAC;IAC5C,eAAe,EAAE,CAAC,sBAAsB,CAAC,CAAC;IAC1C,kBAAkB,EAAE,CAAC,yBAAyB,CAAC,CAAC;IAChD,iBAAiB,EAAE,CAAC,wBAAwB,CAAC,CAAC;CAC/C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed lifecycle-hook surface for the managed driver client.
|
|
3
|
+
*
|
|
4
|
+
* Two kinds of events flow through the same registry:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Broker events** — `agentSpawned`, `agentReleased`, `agentExited`,
|
|
7
|
+
* `agentReady`, `agentIdle`, `agentExitRequested`,
|
|
8
|
+
* `agentActivityChanged`, `agentResult`, `messageReceived`,
|
|
9
|
+
* `messageSent`, `workerOutput`, `deliveryUpdate`, `channelSubscribed`,
|
|
10
|
+
* `channelUnsubscribed`. These fire when the broker emits the
|
|
11
|
+
* corresponding event over the WS stream.
|
|
12
|
+
* 2. **Call-site hooks** — `beforeAgentSpawn`, `afterAgentSpawn`,
|
|
13
|
+
* `beforeAgentRelease`, `afterAgentRelease`. These fire at the SDK
|
|
14
|
+
* call site (before / after the HTTP request), so handlers can
|
|
15
|
+
* observe — and, for `beforeAgentSpawn`, *modify* — the spawn input
|
|
16
|
+
* before it reaches the broker.
|
|
17
|
+
*
|
|
18
|
+
* The `beforeAgentSpawn` contract is the only one that supports
|
|
19
|
+
* mutation: handlers may return a {@link SpawnPatch} to merge into the
|
|
20
|
+
* input via shallow merge in registration order. All other hooks are
|
|
21
|
+
* observe-only — return type `void | Promise<void>`.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=lifecycle-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-hooks.js","sourceRoot":"","sources":["../src/lifecycle-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG"}
|