eve 0.30.0 → 0.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/src/channel/routes.d.ts +11 -4
- package/dist/src/channel/send.js +1 -1
- package/dist/src/channel/types.d.ts +6 -3
- package/dist/src/compiler/extension-compatibility.d.ts +10 -10
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/manifest.d.ts +13 -2
- package/dist/src/compiler/manifest.js +1 -1
- package/dist/src/compiler/normalize-extension.js +1 -1
- package/dist/src/compiler/normalize-manifest.js +2 -2
- package/dist/src/compiler/normalize-tool.d.ts +3 -0
- package/dist/src/compiler/normalize-tool.js +1 -1
- package/dist/src/execution/agent-handle-dispatch.d.ts +32 -0
- package/dist/src/execution/agent-handle-dispatch.js +1 -0
- package/dist/src/execution/cancel-descendant-turns-step.d.ts +1 -1
- package/dist/src/execution/cancel-descendant-turns-step.js +1 -1
- package/dist/src/execution/delegated-parent-notification.d.ts +2 -2
- package/dist/src/execution/delegated-parent-result.d.ts +4 -4
- package/dist/src/execution/delegated-parent-result.js +1 -1
- package/dist/src/execution/dispatch-runtime-actions-step.d.ts +8 -6
- package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
- package/dist/src/execution/dispatch-workflow-runtime-actions-step.d.ts +2 -2
- package/dist/src/execution/dispatch-workflow-runtime-actions-step.js +1 -1
- package/dist/src/execution/durable-session-migrations/turn-workflow.d.ts +10 -2
- package/dist/src/execution/node-step.js +1 -1
- package/dist/src/execution/remote-agent-dispatch.d.ts +7 -2
- package/dist/src/execution/remote-agent-dispatch.js +1 -1
- package/dist/src/execution/sandbox/bindings/vercel.js +1 -1
- package/dist/src/execution/session-callback-step.js +1 -1
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/turn-execution-cursor.d.ts +3 -3
- package/dist/src/execution/turn-workflow.js +1 -1
- package/dist/src/execution/workflow-steps.js +1 -1
- package/dist/src/harness/agent-handle-errors.d.ts +25 -0
- package/dist/src/harness/agent-handle-errors.js +1 -0
- package/dist/src/harness/handles/operation-id.d.ts +15 -0
- package/dist/src/harness/handles/operation-id.js +1 -0
- package/dist/src/harness/handles/prompt.d.ts +21 -0
- package/dist/src/harness/handles/prompt.js +2 -0
- package/dist/src/harness/handles/query.d.ts +41 -0
- package/dist/src/harness/handles/query.js +1 -0
- package/dist/src/harness/handles/state-key.d.ts +8 -0
- package/dist/src/harness/handles/state-key.js +1 -0
- package/dist/src/harness/handles/store.d.ts +132 -0
- package/dist/src/harness/handles/store.js +1 -0
- package/dist/src/harness/handles/transitions.d.ts +107 -0
- package/dist/src/harness/handles/transitions.js +1 -0
- package/dist/src/harness/input-requests.js +1 -1
- package/dist/src/harness/provider-tools.d.ts +4 -3
- package/dist/src/harness/provider-tools.js +1 -1
- package/dist/src/harness/runtime-actions.d.ts +4 -25
- package/dist/src/harness/runtime-actions.js +1 -1
- package/dist/src/harness/tool-loop.d.ts +22 -0
- package/dist/src/harness/tool-loop.js +2 -2
- package/dist/src/harness/tools.d.ts +2 -0
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/harness/types.d.ts +9 -0
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-definition/schema-backed.d.ts +3 -0
- package/dist/src/internal/authored-definition/schema-backed.js +1 -1
- package/dist/src/protocol/agent-handle-error.d.ts +13 -0
- package/dist/src/protocol/agent-handle-error.js +1 -0
- package/dist/src/public/channels/eve.js +1 -1
- package/dist/src/public/tools/defaults.d.ts +0 -12
- package/dist/src/public/tools/defaults.js +1 -1
- package/dist/src/public/tools/index.d.ts +1 -0
- package/dist/src/public/tools/index.js +1 -1
- package/dist/src/public/tools/web-search.d.ts +36 -0
- package/dist/src/public/tools/web-search.js +1 -0
- package/dist/src/runtime/actions/results.d.ts +6 -0
- package/dist/src/runtime/actions/results.js +1 -0
- package/dist/src/runtime/actions/types.d.ts +40 -7
- package/dist/src/runtime/actions/types.js +1 -1
- package/dist/src/runtime/framework-tools/web-search.d.ts +4 -0
- package/dist/src/runtime/framework-tools/web-search.js +1 -1
- package/dist/src/runtime/resolve-agent.js +1 -1
- package/dist/src/runtime/session-callback-route.js +1 -1
- package/dist/src/runtime/types.d.ts +3 -0
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/shared/web-search.d.ts +2 -0
- package/dist/src/shared/web-search.js +1 -0
- package/docs/concepts/default-harness.md +12 -2
- package/docs/reference/typescript-api.md +1 -1
- package/package.json +1 -1
- package/dist/src/harness/agent-handles.d.ts +0 -238
- package/dist/src/harness/agent-handles.js +0 -2
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import type { HarnessSession, SessionStateMap } from "#harness/types.js";
|
|
2
|
-
import type { AgentTurnOutcome } from "#shared/agent-turn-outcome.js";
|
|
3
|
-
/** Session-state key for delegated agent handles. */
|
|
4
|
-
export declare const AGENT_HANDLES_STATE_KEY = "eve.agent.handles";
|
|
5
|
-
/** Error code for a requested agent id that is not registered. */
|
|
6
|
-
export declare const AGENT_UNKNOWN = "AGENT_UNKNOWN";
|
|
7
|
-
/** Error code for an agent id invoked through the wrong subagent tool. */
|
|
8
|
-
export declare const AGENT_MISMATCH = "AGENT_MISMATCH";
|
|
9
|
-
/** Error code for a registered agent that cannot be reached. */
|
|
10
|
-
export declare const AGENT_UNREACHABLE = "AGENT_UNREACHABLE";
|
|
11
|
-
/** Error code for an agent that is starting or already running a turn. */
|
|
12
|
-
export declare const AGENT_BUSY = "AGENT_BUSY";
|
|
13
|
-
/**
|
|
14
|
-
* Stable identity of one delegated child, minted before its start side
|
|
15
|
-
* effect runs. The model-visible `id` derives from the first start
|
|
16
|
-
* operation, never from the child session id, so it exists before the
|
|
17
|
-
* child does and cannot collide on externally supplied session suffixes.
|
|
18
|
-
*/
|
|
19
|
-
export interface AgentIdentity {
|
|
20
|
-
/** Model-visible identifier: `ag_<name>:<operation-hash>`. */
|
|
21
|
-
readonly id: string;
|
|
22
|
-
/** Subagent tool name. */
|
|
23
|
-
readonly name: string;
|
|
24
|
-
/** Agent-graph node used to re-resolve delivery configuration. */
|
|
25
|
-
readonly nodeId: string;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* One dispatch the parent intends to perform or has performed. Repeating
|
|
29
|
-
* the same operation is a replay; a different operation against a
|
|
30
|
-
* starting/running handle is a busy conflict.
|
|
31
|
-
*/
|
|
32
|
-
export interface StartOperation {
|
|
33
|
-
readonly kind: "start";
|
|
34
|
-
/** Derived via {@link deriveAgentOperationId}; stable across replays. */
|
|
35
|
-
readonly id: string;
|
|
36
|
-
readonly callId: string;
|
|
37
|
-
readonly parentTurnId: string;
|
|
38
|
-
}
|
|
39
|
-
/** A continuation delivery against a parked handle. */
|
|
40
|
-
export interface ContinueOperation {
|
|
41
|
-
readonly kind: "continue";
|
|
42
|
-
/** Derived via {@link deriveAgentOperationId}; stable across replays. */
|
|
43
|
-
readonly id: string;
|
|
44
|
-
readonly callId: string;
|
|
45
|
-
readonly parentTurnId: string;
|
|
46
|
-
/**
|
|
47
|
-
* Status the handle showed before this delivery, restored when the
|
|
48
|
-
* delivery is rejected as retryable so the handle returns to `parked`
|
|
49
|
-
* without optional state.
|
|
50
|
-
*/
|
|
51
|
-
readonly previousStatus: string;
|
|
52
|
-
}
|
|
53
|
-
/** Where a fresh child will be started. No session exists yet. */
|
|
54
|
-
export type AgentStartTarget = {
|
|
55
|
-
readonly kind: "agent/local";
|
|
56
|
-
/** Deterministic child continuation token chosen at dispatch. */
|
|
57
|
-
readonly continuationToken: string;
|
|
58
|
-
} | {
|
|
59
|
-
readonly kind: "agent/self";
|
|
60
|
-
readonly continuationToken: string;
|
|
61
|
-
} | {
|
|
62
|
-
readonly kind: "agent/remote";
|
|
63
|
-
/** Deliver target base URL; never model-visible. */
|
|
64
|
-
readonly url: string;
|
|
65
|
-
/** Callback base URL stub captured at dispatch; never model-visible. */
|
|
66
|
-
readonly callbackBaseUrl: string;
|
|
67
|
-
};
|
|
68
|
-
/** Confirmed delivery coordinates of a started child. */
|
|
69
|
-
export type AgentAddress = {
|
|
70
|
-
readonly kind: "agent/local";
|
|
71
|
-
readonly sessionId: string;
|
|
72
|
-
readonly continuationToken: string;
|
|
73
|
-
} | {
|
|
74
|
-
readonly kind: "agent/self";
|
|
75
|
-
readonly sessionId: string;
|
|
76
|
-
readonly continuationToken: string;
|
|
77
|
-
} | {
|
|
78
|
-
readonly kind: "agent/remote";
|
|
79
|
-
readonly sessionId: string;
|
|
80
|
-
readonly continuationToken: string;
|
|
81
|
-
readonly url: string;
|
|
82
|
-
readonly callbackBaseUrl: string;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Durable ownership record for one delegated child.
|
|
86
|
-
*
|
|
87
|
-
* The store owns the full nonterminal lifecycle:
|
|
88
|
-
*
|
|
89
|
-
* - `starting` — the parent committed intent to start; the child may or
|
|
90
|
-
* may not exist yet.
|
|
91
|
-
* - `running` — one identified child turn is outstanding.
|
|
92
|
-
* - `parked` — the child is idle and resumable; only this phase is
|
|
93
|
-
* model-visible.
|
|
94
|
-
*
|
|
95
|
-
* A terminal child has no handle: settlement deletes it.
|
|
96
|
-
*/
|
|
97
|
-
export type AgentHandle = {
|
|
98
|
-
readonly phase: "starting";
|
|
99
|
-
readonly identity: AgentIdentity;
|
|
100
|
-
readonly operation: StartOperation;
|
|
101
|
-
readonly target: AgentStartTarget;
|
|
102
|
-
} | {
|
|
103
|
-
readonly phase: "running";
|
|
104
|
-
readonly identity: AgentIdentity;
|
|
105
|
-
readonly operation: StartOperation | ContinueOperation;
|
|
106
|
-
readonly address: AgentAddress;
|
|
107
|
-
} | {
|
|
108
|
-
readonly phase: "parked";
|
|
109
|
-
readonly identity: AgentIdentity;
|
|
110
|
-
readonly address: AgentAddress;
|
|
111
|
-
readonly lastStatus: string;
|
|
112
|
-
};
|
|
113
|
-
/** Lifecycle phase of a delegated agent handle. */
|
|
114
|
-
export type AgentHandlePhase = AgentHandle["phase"];
|
|
115
|
-
/** Session-state collection of delegated agent handles. */
|
|
116
|
-
export interface AgentHandleStore {
|
|
117
|
-
readonly handles: readonly AgentHandle[];
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Derives the stable operation id for one dispatch. All three inputs are
|
|
121
|
-
* parent-controlled, so the id exists before any child does and replaying
|
|
122
|
-
* the same call produces the same operation.
|
|
123
|
-
*/
|
|
124
|
-
export declare function deriveAgentOperationId(input: {
|
|
125
|
-
readonly callId: string;
|
|
126
|
-
readonly parentSessionId: string;
|
|
127
|
-
readonly parentTurnId: string;
|
|
128
|
-
}): string;
|
|
129
|
-
/** Derives the model-visible agent id from the first start operation. */
|
|
130
|
-
export declare function deriveAgentId(name: string, startOperationId: string): string;
|
|
131
|
-
/** Collapses whitespace and truncates output into a handle status line. */
|
|
132
|
-
export declare function formatAgentStatus(output: unknown): string;
|
|
133
|
-
/**
|
|
134
|
-
* Reads and validates the agent handle store from session state.
|
|
135
|
-
*
|
|
136
|
-
* Returns `undefined` only when no store has been written. A present but
|
|
137
|
-
* invalid store throws: treating corruption as absence would let the next
|
|
138
|
-
* transition silently replace every delegated child's delivery coordinates.
|
|
139
|
-
*/
|
|
140
|
-
export declare function getAgentHandleStore(state: SessionStateMap | undefined): AgentHandleStore | undefined;
|
|
141
|
-
/**
|
|
142
|
-
* Records intent to start a fresh child. Must commit before the start
|
|
143
|
-
* side effect runs so a crashed dispatch never orphans an unowned child.
|
|
144
|
-
*
|
|
145
|
-
* Throws when the identity or operation already exists: fresh starts mint
|
|
146
|
-
* a new identity, so a collision means corrupted derivation, not a replay.
|
|
147
|
-
*/
|
|
148
|
-
export declare function prepareAgentStart(session: HarnessSession, input: {
|
|
149
|
-
readonly identity: AgentIdentity;
|
|
150
|
-
readonly operation: StartOperation;
|
|
151
|
-
readonly target: AgentStartTarget;
|
|
152
|
-
}): HarnessSession;
|
|
153
|
-
/** Result of preparing a continuation against an existing handle. */
|
|
154
|
-
export type PrepareAgentContinuationResult = {
|
|
155
|
-
readonly kind: "ready";
|
|
156
|
-
readonly session: HarnessSession;
|
|
157
|
-
readonly handle: Extract<AgentHandle, {
|
|
158
|
-
phase: "running";
|
|
159
|
-
}>;
|
|
160
|
-
} | {
|
|
161
|
-
readonly kind: "unknown";
|
|
162
|
-
} | {
|
|
163
|
-
readonly kind: "mismatch";
|
|
164
|
-
} | {
|
|
165
|
-
readonly kind: "busy";
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Records intent to deliver a follow-up turn to a parked child. Must
|
|
169
|
-
* commit before the delivery side effect runs.
|
|
170
|
-
*
|
|
171
|
-
* `unknown`, `mismatch`, and `busy` do not change the session; the caller
|
|
172
|
-
* maps them onto {@link AGENT_UNKNOWN}, {@link AGENT_MISMATCH}, and
|
|
173
|
-
* {@link AGENT_BUSY} results. Replaying the operation already recorded on
|
|
174
|
-
* a running handle returns `ready` with the unchanged session.
|
|
175
|
-
*/
|
|
176
|
-
export declare function prepareAgentContinuation(session: HarnessSession, input: {
|
|
177
|
-
readonly agentId: string;
|
|
178
|
-
readonly invokedName: string;
|
|
179
|
-
readonly operation: ContinueOperation;
|
|
180
|
-
}): PrepareAgentContinuationResult;
|
|
181
|
-
/**
|
|
182
|
-
* Confirms a started child: `starting` becomes `running` with the child's
|
|
183
|
-
* confirmed address. Throws when no starting handle carries the operation,
|
|
184
|
-
* because confirming an unprepared start means ownership was never
|
|
185
|
-
* committed. Re-confirming an already-running handle with the same
|
|
186
|
-
* operation and address is a replay no-op.
|
|
187
|
-
*/
|
|
188
|
-
export declare function confirmAgentStarted(session: HarnessSession, input: {
|
|
189
|
-
readonly operationId: string;
|
|
190
|
-
readonly address: AgentAddress;
|
|
191
|
-
}): HarnessSession;
|
|
192
|
-
/**
|
|
193
|
-
* Resolves a dispatch that definitively failed.
|
|
194
|
-
*
|
|
195
|
-
* - A dead start or dead continuation deletes the handle: there is no
|
|
196
|
-
* child left to own.
|
|
197
|
-
* - A retryable continuation failure restores `parked` with the status the
|
|
198
|
-
* handle showed before the delivery, so the model may retry the same
|
|
199
|
-
* `agentId` later.
|
|
200
|
-
*
|
|
201
|
-
* Unknown operations are a no-op: the failure raced a settlement that
|
|
202
|
-
* already resolved the handle.
|
|
203
|
-
*/
|
|
204
|
-
export declare function rejectAgentEffect(session: HarnessSession, input: {
|
|
205
|
-
readonly operationId: string;
|
|
206
|
-
readonly disposition: "dead" | "retryable";
|
|
207
|
-
}): HarnessSession;
|
|
208
|
-
/** Result of applying a settled child turn to the store. */
|
|
209
|
-
export type SettleAgentTurnResult = {
|
|
210
|
-
readonly kind: "settled";
|
|
211
|
-
readonly session: HarnessSession;
|
|
212
|
-
} | {
|
|
213
|
-
readonly kind: "ignored";
|
|
214
|
-
readonly reason: "unknown-operation" | "session-mismatch";
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* Applies one settled child turn: `running` becomes `parked` for a parked
|
|
218
|
-
* outcome or is deleted for a terminal outcome.
|
|
219
|
-
*
|
|
220
|
-
* The settlement must carry the operation currently recorded on the
|
|
221
|
-
* running handle and the child session the address confirms; anything else
|
|
222
|
-
* is ignored so a stale or forged delivery can never move a newer turn.
|
|
223
|
-
*/
|
|
224
|
-
export declare function settleAgentTurn(session: HarnessSession, input: {
|
|
225
|
-
readonly operationId: string;
|
|
226
|
-
readonly sessionId: string;
|
|
227
|
-
readonly outcome: AgentTurnOutcome;
|
|
228
|
-
}): SettleAgentTurnResult;
|
|
229
|
-
/** Returns the resumable handles: the only phase the model may continue. */
|
|
230
|
-
export declare function projectParkedAgentHandles(store: AgentHandleStore): readonly Extract<AgentHandle, {
|
|
231
|
-
phase: "parked";
|
|
232
|
-
}>[];
|
|
233
|
-
/**
|
|
234
|
-
* Renders the model-visible agent listing. Only parked handles appear:
|
|
235
|
-
* starting and running children cannot accept a continuation, and private
|
|
236
|
-
* delivery coordinates never render.
|
|
237
|
-
*/
|
|
238
|
-
export declare function renderAgentsSnippet(store: AgentHandleStore): string;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{createHash}from"node:crypto";import{z}from"#compiled/zod/index.js";const AGENT_HANDLES_STATE_KEY=`eve.agent.handles`,AGENT_UNKNOWN=`AGENT_UNKNOWN`,AGENT_MISMATCH=`AGENT_MISMATCH`,AGENT_UNREACHABLE=`AGENT_UNREACHABLE`,AGENT_BUSY=`AGENT_BUSY`,nonEmptyString=z.string().min(1),identitySchema=z.strictObject({id:nonEmptyString,name:nonEmptyString,nodeId:nonEmptyString}),startOperationSchema=z.strictObject({callId:nonEmptyString,id:nonEmptyString,kind:z.literal(`start`),parentTurnId:nonEmptyString}),continueOperationSchema=z.strictObject({callId:nonEmptyString,id:nonEmptyString,kind:z.literal(`continue`),parentTurnId:nonEmptyString,previousStatus:z.string().max(120)}),startTargetSchema=z.discriminatedUnion(`kind`,[z.strictObject({continuationToken:nonEmptyString,kind:z.literal(`agent/local`)}),z.strictObject({continuationToken:nonEmptyString,kind:z.literal(`agent/self`)}),z.strictObject({callbackBaseUrl:z.url(),kind:z.literal(`agent/remote`),url:z.url()})]),addressSchema=z.discriminatedUnion(`kind`,[z.strictObject({continuationToken:nonEmptyString,kind:z.literal(`agent/local`),sessionId:nonEmptyString}),z.strictObject({continuationToken:nonEmptyString,kind:z.literal(`agent/self`),sessionId:nonEmptyString}),z.strictObject({callbackBaseUrl:z.url(),continuationToken:nonEmptyString,kind:z.literal(`agent/remote`),sessionId:nonEmptyString,url:z.url()})]),agentHandleSchema=z.discriminatedUnion(`phase`,[z.strictObject({identity:identitySchema,operation:startOperationSchema,phase:z.literal(`starting`),target:startTargetSchema}),z.strictObject({address:addressSchema,identity:identitySchema,operation:z.discriminatedUnion(`kind`,[startOperationSchema,continueOperationSchema]),phase:z.literal(`running`)}),z.strictObject({address:addressSchema,identity:identitySchema,lastStatus:z.string().max(120),phase:z.literal(`parked`)})]),agentHandleStoreSchema=z.strictObject({handles:z.array(agentHandleSchema)}).refine(e=>new Set(e.handles.map(e=>e.identity.id)).size===e.handles.length,{message:`Agent handle ids must be unique.`});function deriveAgentOperationId(t){return createHash(`sha256`).update(`${t.parentSessionId}\0${t.parentTurnId}\0${t.callId}`).digest(`hex`)}function deriveAgentId(e,t){return`ag_${e}:${t.slice(0,12)}`}function formatAgentStatus(e){return(typeof e==`string`?e:JSON.stringify(e)??``).replaceAll(/\s+/g,` `).trim().slice(0,120)}function getAgentHandleStore(e){let t=e?.[AGENT_HANDLES_STATE_KEY];if(t===void 0)return;let r=agentHandleStoreSchema.safeParse(t);if(!r.success)throw Error(`Corrupt agent handle store under session state key "${AGENT_HANDLES_STATE_KEY}": ${r.error.message}`);return r.data}function prepareAgentStart(e,t){let n=getAgentHandleStore(e.state)?.handles??[];if(n.some(e=>e.identity.id===t.identity.id))throw Error(`Agent handle "${t.identity.id}" already exists.`);return writeHandles(e,[...n,{identity:t.identity,operation:t.operation,phase:`starting`,target:t.target}])}function prepareAgentContinuation(e,t){let n=getAgentHandleStore(e.state)?.handles??[],r=n.find(e=>e.identity.id===t.agentId);if(r===void 0)return{kind:`unknown`};if(r.identity.name!==t.invokedName)return{kind:`mismatch`};if(r.phase===`running`&&r.operation.id===t.operation.id)return{handle:r,kind:`ready`,session:e};if(r.phase!==`parked`)return{kind:`busy`};let i={address:r.address,identity:r.identity,operation:{...t.operation,previousStatus:r.lastStatus},phase:`running`};return{handle:i,kind:`ready`,session:writeHandles(e,n.map(e=>e.identity.id===t.agentId?i:e))}}function findActiveHandle(e,t){return e.find(e=>e.phase!==`parked`&&e.operation.id===t)}function confirmAgentStarted(e,t){let n=getAgentHandleStore(e.state)?.handles??[],r=findActiveHandle(n,t.operationId);if(r===void 0)throw Error(`No prepared agent handle for operation "${t.operationId}".`);return r.phase===`running`?e:writeHandles(e,n.map(e=>e===r?{address:t.address,identity:r.identity,operation:r.operation,phase:`running`}:e))}function rejectAgentEffect(e,t){let n=getAgentHandleStore(e.state)?.handles??[],r=findActiveHandle(n,t.operationId);if(r===void 0)return e;if(t.disposition===`retryable`&&r.phase===`running`){let{operation:t}=r;if(t.kind===`continue`)return writeHandles(e,n.map(e=>e===r?{address:r.address,identity:r.identity,lastStatus:t.previousStatus,phase:`parked`}:e))}return writeHandles(e,n.filter(e=>e!==r))}function settleAgentTurn(e,t){let n=getAgentHandleStore(e.state)?.handles??[],r=n.find(e=>e.phase===`running`&&e.operation.id===t.operationId);if(r===void 0||r.phase!==`running`)return{kind:`ignored`,reason:`unknown-operation`};if(r.address.sessionId!==t.sessionId)return{kind:`ignored`,reason:`session-mismatch`};if(t.outcome.kind===`terminal`)return{kind:`settled`,session:writeHandles(e,n.filter(e=>e!==r))};let{result:i}=t.outcome,a=i.kind===`succeeded`?formatAgentStatus(i.output):i.kind===`failed`?formatAgentStatus(i.error):`(cancelled)`;return{kind:`settled`,session:writeHandles(e,n.map(e=>e===r?{address:r.address,identity:r.identity,lastStatus:a,phase:`parked`}:e))}}function projectParkedAgentHandles(e){return e.handles.filter(e=>e.phase===`parked`)}function renderAgentsSnippet(e){return[`[Agents]`,`<agents>`,...projectParkedAgentHandles(e).map(e=>`<agent id="${escapeXml(e.identity.id)}" name="${escapeXml(e.identity.name)}">${escapeXml(e.lastStatus===``?`(no status)`:e.lastStatus)}</agent>`),`</agents>`].join(`
|
|
2
|
-
`)}function writeHandles(e,t){return{...e,state:{...e.state,[AGENT_HANDLES_STATE_KEY]:{handles:t}}}}function escapeXml(e){return e.replaceAll(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}export{AGENT_BUSY,AGENT_HANDLES_STATE_KEY,AGENT_MISMATCH,AGENT_UNKNOWN,AGENT_UNREACHABLE,confirmAgentStarted,deriveAgentId,deriveAgentOperationId,formatAgentStatus,getAgentHandleStore,prepareAgentContinuation,prepareAgentStart,projectParkedAgentHandles,rejectAgentEffect,renderAgentsSnippet,settleAgentTurn};
|