@agen-ai/agent-orchestration 0.0.0-stage → 0.4.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 +413 -2
- package/dist/catalog/parse.d.ts +3 -0
- package/dist/catalog/parse.js +13 -0
- package/dist/catalog/schemas.d.ts +8 -0
- package/dist/catalog/schemas.js +78 -0
- package/dist/catalog/types.d.ts +53 -0
- package/dist/catalog/types.js +0 -0
- package/dist/coordinator/admission.d.ts +7 -0
- package/dist/coordinator/admission.js +189 -0
- package/dist/coordinator/cancel.d.ts +7 -0
- package/dist/coordinator/cancel.js +111 -0
- package/dist/coordinator/create.d.ts +3 -0
- package/dist/coordinator/create.js +87 -0
- package/dist/coordinator/parse.d.ts +10 -0
- package/dist/coordinator/parse.js +60 -0
- package/dist/coordinator/read.d.ts +4 -0
- package/dist/coordinator/read.js +267 -0
- package/dist/coordinator/recovery.d.ts +4 -0
- package/dist/coordinator/recovery.js +24 -0
- package/dist/coordinator/shutdown.d.ts +7 -0
- package/dist/coordinator/shutdown.js +66 -0
- package/dist/coordinator/types.d.ts +154 -0
- package/dist/coordinator/types.js +0 -0
- package/dist/delivery/calls.d.ts +4 -0
- package/dist/delivery/calls.js +34 -0
- package/dist/delivery/journal.d.ts +7 -0
- package/dist/delivery/journal.js +57 -0
- package/dist/delivery/parse.d.ts +4 -0
- package/dist/delivery/parse.js +31 -0
- package/dist/delivery/recovery.d.ts +3 -0
- package/dist/delivery/recovery.js +18 -0
- package/dist/delivery/scheduler.d.ts +3 -0
- package/dist/delivery/scheduler.js +123 -0
- package/dist/delivery/setup.d.ts +7 -0
- package/dist/delivery/setup.js +37 -0
- package/dist/delivery/types.d.ts +36 -0
- package/dist/delivery/types.js +0 -0
- package/dist/execution/authority.d.ts +16 -0
- package/dist/execution/authority.js +86 -0
- package/dist/execution/cleanup.d.ts +3 -0
- package/dist/execution/cleanup.js +75 -0
- package/dist/execution/control.d.ts +6 -0
- package/dist/execution/control.js +231 -0
- package/dist/execution/finish.d.ts +6 -0
- package/dist/execution/finish.js +49 -0
- package/dist/execution/journal.d.ts +19 -0
- package/dist/execution/journal.js +28 -0
- package/dist/execution/prepare.d.ts +3 -0
- package/dist/execution/prepare.js +153 -0
- package/dist/execution/scheduler.d.ts +4 -0
- package/dist/execution/scheduler.js +136 -0
- package/dist/execution/state.d.ts +107 -0
- package/dist/execution/state.js +120 -0
- package/dist/execution/stream.d.ts +9 -0
- package/dist/execution/stream.js +108 -0
- package/dist/host/types.d.ts +95 -0
- package/dist/host/types.js +0 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +58 -0
- package/dist/mcp/bridge.d.ts +4 -0
- package/dist/mcp/bridge.js +222 -0
- package/dist/mcp/http.d.ts +11 -0
- package/dist/mcp/http.js +74 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/limits.d.ts +10 -0
- package/dist/mcp/limits.js +30 -0
- package/dist/mcp/protocol.d.ts +50 -0
- package/dist/mcp/protocol.js +81 -0
- package/dist/mcp/types.d.ts +22 -0
- package/dist/mcp/types.js +0 -0
- package/dist/policy/matching.d.ts +4 -0
- package/dist/policy/matching.js +18 -0
- package/dist/policy/parse.d.ts +3 -0
- package/dist/policy/parse.js +13 -0
- package/dist/policy/resolve.d.ts +7 -0
- package/dist/policy/resolve.js +67 -0
- package/dist/policy/schemas.d.ts +5 -0
- package/dist/policy/schemas.js +59 -0
- package/dist/policy/types.d.ts +60 -0
- package/dist/policy/types.js +0 -0
- package/dist/shared/bounds.d.ts +6 -0
- package/dist/shared/bounds.js +88 -0
- package/dist/shared/errors.d.ts +9 -0
- package/dist/shared/errors.js +27 -0
- package/dist/shared/identity.d.ts +6 -0
- package/dist/shared/identity.js +32 -0
- package/dist/shared/immutable.d.ts +2 -0
- package/dist/shared/immutable.js +10 -0
- package/dist/shared/limits.d.ts +32 -0
- package/dist/shared/limits.js +69 -0
- package/dist/shared/operational-errors.d.ts +7 -0
- package/dist/shared/operational-errors.js +15 -0
- package/dist/shared/schemas.d.ts +11 -0
- package/dist/shared/schemas.js +23 -0
- package/dist/shared/text.d.ts +2 -0
- package/dist/shared/text.js +15 -0
- package/dist/store/memory.d.ts +7 -0
- package/dist/store/memory.js +215 -0
- package/dist/store/pages.d.ts +16 -0
- package/dist/store/pages.js +46 -0
- package/dist/store/parse.d.ts +5 -0
- package/dist/store/parse.js +137 -0
- package/dist/store/types.d.ts +219 -0
- package/dist/store/types.js +0 -0
- package/dist/store-adapter/admission.d.ts +6 -0
- package/dist/store-adapter/admission.js +90 -0
- package/dist/store-adapter/context.d.ts +20 -0
- package/dist/store-adapter/context.js +107 -0
- package/dist/store-adapter/delivery.d.ts +15 -0
- package/dist/store-adapter/delivery.js +81 -0
- package/dist/store-adapter/execution.d.ts +12 -0
- package/dist/store-adapter/execution.js +151 -0
- package/dist/store-adapter/index.d.ts +7 -0
- package/dist/store-adapter/index.js +27 -0
- package/dist/store-adapter/lifecycle.d.ts +15 -0
- package/dist/store-adapter/lifecycle.js +80 -0
- package/dist/store-adapter/plan.d.ts +7 -0
- package/dist/store-adapter/plan.js +168 -0
- package/dist/store-adapter/types.d.ts +45 -0
- package/dist/store-adapter/types.js +0 -0
- package/dist/tasks/failure.d.ts +4 -0
- package/dist/tasks/failure.js +24 -0
- package/dist/tasks/parse.d.ts +18 -0
- package/dist/tasks/parse.js +66 -0
- package/dist/tasks/schemas.d.ts +47 -0
- package/dist/tasks/schemas.js +215 -0
- package/dist/tasks/types.d.ts +192 -0
- package/dist/tasks/types.js +0 -0
- package/dist/tools/create.d.ts +4 -0
- package/dist/tools/create.js +69 -0
- package/dist/tools/errors.d.ts +4 -0
- package/dist/tools/errors.js +35 -0
- package/dist/tools/guidance.d.ts +4 -0
- package/dist/tools/guidance.js +28 -0
- package/dist/tools/handlers.d.ts +4 -0
- package/dist/tools/handlers.js +84 -0
- package/dist/tools/projection.d.ts +13 -0
- package/dist/tools/projection.js +72 -0
- package/dist/tools/schemas.d.ts +6 -0
- package/dist/tools/schemas.js +93 -0
- package/dist/tools/types.d.ts +28 -0
- package/dist/tools/types.js +0 -0
- package/package.json +64 -3
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { createDelegationId, delegationDataBytes, delegationInputDigest, delegationSubordinateId } from "../shared/identity.js";
|
|
2
|
+
import { freezeDelegationData } from "../shared/immutable.js";
|
|
3
|
+
import { parseDelegationLimits } from "../shared/limits.js";
|
|
4
|
+
import { failDelegation } from "../shared/operational-errors.js";
|
|
5
|
+
import { delegationSchemaError, invalidDelegationData } from "../shared/errors.js";
|
|
6
|
+
import { captureDelegationRecord, copyBoundedDelegationData } from "../shared/bounds.js";
|
|
7
|
+
import { parseDelegationOwnerToken } from "../tasks/parse.js";
|
|
8
|
+
import { StoreIdSchema } from "../tasks/schemas.js";
|
|
9
|
+
import { planDelegationStoreCommit } from "../store-adapter/plan.js";
|
|
10
|
+
import { criticalKinds } from "../store-adapter/context.js";
|
|
11
|
+
import { parseDelegationStoreCommand, parseDelegationStoreReadInput, parseDelegationStoreScanInput } from "./parse.js";
|
|
12
|
+
import { pageDelegationRows, summarizeDelegationRun } from "./pages.js";
|
|
13
|
+
function operationKey(parent, operationId) {
|
|
14
|
+
return JSON.stringify([parent.parentId, parent.scopeId, operationId]);
|
|
15
|
+
}
|
|
16
|
+
function observationKey(runId, index) {
|
|
17
|
+
return `${runId}:${index}`;
|
|
18
|
+
}
|
|
19
|
+
function runKey(run) {
|
|
20
|
+
return `${run.createdAt}:${run.runId}`;
|
|
21
|
+
}
|
|
22
|
+
function createInMemoryDelegationStore(options = {}) {
|
|
23
|
+
const capturedOptions = captureDelegationRecord(options);
|
|
24
|
+
if (Object.keys(capturedOptions).some((key) => key !== "limits" && key !== "storeId")) {
|
|
25
|
+
invalidDelegationData("invalid_data", [], "Volatile store options contain an unknown property.");
|
|
26
|
+
}
|
|
27
|
+
const limits = parseDelegationLimits(capturedOptions.limits ?? {});
|
|
28
|
+
const capturedStoreId = copyBoundedDelegationData(capturedOptions.storeId ?? createDelegationId());
|
|
29
|
+
const parsedStoreId = StoreIdSchema.safeParse(capturedStoreId);
|
|
30
|
+
if (!parsedStoreId.success) return delegationSchemaError(parsedStoreId.error, capturedStoreId);
|
|
31
|
+
const storeId = parsedStoreId.data;
|
|
32
|
+
let owner;
|
|
33
|
+
let epoch = 0;
|
|
34
|
+
let capacity = Object.freeze({
|
|
35
|
+
tasks: 0,
|
|
36
|
+
runs: 0,
|
|
37
|
+
activeRuns: 0,
|
|
38
|
+
queuedRuns: 0,
|
|
39
|
+
retainedInputBytes: 0,
|
|
40
|
+
observationBytes: 0,
|
|
41
|
+
ordinaryOperations: 0,
|
|
42
|
+
reservedBytes: 0,
|
|
43
|
+
criticalSlots: 0
|
|
44
|
+
});
|
|
45
|
+
const tasks = /* @__PURE__ */ new Map();
|
|
46
|
+
const runs = /* @__PURE__ */ new Map();
|
|
47
|
+
const operations = /* @__PURE__ */ new Map();
|
|
48
|
+
const observations = /* @__PURE__ */ new Map();
|
|
49
|
+
const notifications = /* @__PURE__ */ new Map();
|
|
50
|
+
const ceilings = /* @__PURE__ */ new Map();
|
|
51
|
+
const runOperations = (runId) => [...operations.values()].filter((operation) => operation.runId === runId);
|
|
52
|
+
const runObservations = (runId) => [...observations.values()].filter((observation) => observation.runId === runId);
|
|
53
|
+
const page = (query, rows, key, input, envelopeBytes = 0) => pageDelegationRows({ storeId, query, rows, key, limits, ...input, envelopeBytes });
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
contractVersion: 3,
|
|
56
|
+
persistence: "volatile",
|
|
57
|
+
storeId,
|
|
58
|
+
limits,
|
|
59
|
+
async acquireOwner() {
|
|
60
|
+
if (owner) failDelegation("owner_lost", "This volatile store already has an active owner.");
|
|
61
|
+
owner = parseDelegationOwnerToken({ storeId, epoch: ++epoch, nonce: createDelegationId() });
|
|
62
|
+
return owner;
|
|
63
|
+
},
|
|
64
|
+
async releaseOwner(input) {
|
|
65
|
+
if (!owner || input.storeId !== storeId || input.epoch !== owner.epoch || input.nonce !== owner.nonce) {
|
|
66
|
+
failDelegation("owner_lost", "The store owner fence is no longer current.");
|
|
67
|
+
}
|
|
68
|
+
owner = void 0;
|
|
69
|
+
},
|
|
70
|
+
async commit(input) {
|
|
71
|
+
const command = parseDelegationStoreCommand(input);
|
|
72
|
+
const task = tasks.get(command.taskId);
|
|
73
|
+
const parent = command.kind === "admit" ? command.admission.parent : task?.parent;
|
|
74
|
+
const runId = command.kind === "admit" ? command.admission.runId : command.runId;
|
|
75
|
+
const notificationId = command.kind === "delivery_claim" || command.kind === "delivery_receipt" ? command.notificationId : runId ? delegationSubordinateId(runId, "notification") : void 0;
|
|
76
|
+
const taskRuns = [...runs.values()].filter((run) => run.taskId === command.taskId);
|
|
77
|
+
const selectedOperations = runId ? runOperations(runId) : [];
|
|
78
|
+
const selectedObservations = command.kind === "observe" ? runObservations(command.observation.runId) : [];
|
|
79
|
+
const plan = planDelegationStoreCommit({ command, current: {
|
|
80
|
+
storeId,
|
|
81
|
+
owner,
|
|
82
|
+
limits,
|
|
83
|
+
capacity,
|
|
84
|
+
task,
|
|
85
|
+
runs: taskRuns,
|
|
86
|
+
operation: parent ? operations.get(operationKey(parent, command.operationId)) : void 0,
|
|
87
|
+
criticalOperations: selectedOperations.filter((operation) => criticalKinds.has(operation.kind)),
|
|
88
|
+
notification: notificationId ? notifications.get(notificationId) : void 0,
|
|
89
|
+
ceiling: command.kind === "admit" ? ceilings.get(command.admission.policyCeiling.ceilingId) : void 0,
|
|
90
|
+
observation: command.kind === "observe" ? observations.get(observationKey(command.observation.runId, command.observation.index)) : void 0,
|
|
91
|
+
omissionObservation: selectedObservations.find((observation) => observation.kind === "omitted"),
|
|
92
|
+
runIdExists: command.kind === "admit" && runs.has(command.admission.runId)
|
|
93
|
+
} });
|
|
94
|
+
for (const mutation of plan.mutations) {
|
|
95
|
+
switch (mutation.kind) {
|
|
96
|
+
case "task":
|
|
97
|
+
tasks.set(mutation.value.taskId, mutation.value);
|
|
98
|
+
break;
|
|
99
|
+
case "run":
|
|
100
|
+
runs.set(mutation.value.runId, mutation.value);
|
|
101
|
+
break;
|
|
102
|
+
case "operation":
|
|
103
|
+
operations.set(operationKey(mutation.value.parent, mutation.value.operationId), mutation.value);
|
|
104
|
+
break;
|
|
105
|
+
case "observation":
|
|
106
|
+
observations.set(observationKey(mutation.value.runId, mutation.value.index), mutation.value);
|
|
107
|
+
break;
|
|
108
|
+
case "notification":
|
|
109
|
+
notifications.set(mutation.value.envelope.notificationId, mutation.value);
|
|
110
|
+
break;
|
|
111
|
+
case "ceiling":
|
|
112
|
+
ceilings.set(mutation.value.ceilingId, mutation.value);
|
|
113
|
+
break;
|
|
114
|
+
case "capacity":
|
|
115
|
+
capacity = mutation.value;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return plan.receipt;
|
|
120
|
+
},
|
|
121
|
+
async read(input) {
|
|
122
|
+
const query = parseDelegationStoreReadInput(input);
|
|
123
|
+
let result;
|
|
124
|
+
switch (query.kind) {
|
|
125
|
+
case "capacity":
|
|
126
|
+
result = { kind: query.kind, capacity };
|
|
127
|
+
break;
|
|
128
|
+
case "task": {
|
|
129
|
+
const task = tasks.get(query.taskId);
|
|
130
|
+
result = { kind: query.kind, ...task ? { view: { task, runs: page(
|
|
131
|
+
{ kind: query.kind, taskId: query.taskId },
|
|
132
|
+
[...runs.values()].filter((run) => run.taskId === task.taskId).map(summarizeDelegationRun),
|
|
133
|
+
(run) => `${String(run.ordinal).padStart(16, "0")}:${run.runId}`,
|
|
134
|
+
query,
|
|
135
|
+
delegationDataBytes(task)
|
|
136
|
+
) } } : {} };
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case "run": {
|
|
140
|
+
const run = runs.get(query.runId);
|
|
141
|
+
result = { kind: query.kind, ...run?.taskId === query.taskId ? { run } : {} };
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case "operation": {
|
|
145
|
+
const operation = operations.get(operationKey(query.parent, query.operationId));
|
|
146
|
+
result = { kind: query.kind, ...operation ? { operation } : {} };
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case "operations":
|
|
150
|
+
result = { kind: query.kind, page: page(
|
|
151
|
+
{ kind: query.kind, taskId: query.taskId, runId: query.runId },
|
|
152
|
+
runs.get(query.runId)?.taskId === query.taskId ? runOperations(query.runId) : [],
|
|
153
|
+
(operation) => operation.operationId,
|
|
154
|
+
query
|
|
155
|
+
) };
|
|
156
|
+
break;
|
|
157
|
+
case "observations": {
|
|
158
|
+
const run = runs.get(query.runId);
|
|
159
|
+
const found = run?.taskId === query.taskId;
|
|
160
|
+
result = {
|
|
161
|
+
kind: query.kind,
|
|
162
|
+
page: page(
|
|
163
|
+
{ kind: query.kind, taskId: query.taskId, runId: query.runId },
|
|
164
|
+
found ? runObservations(query.runId) : [],
|
|
165
|
+
(observation) => String(observation.index).padStart(16, "0"),
|
|
166
|
+
query
|
|
167
|
+
),
|
|
168
|
+
latestIndex: found ? run.observationIndex : 0,
|
|
169
|
+
gap: found ? run.omittedObservations > 0 : false
|
|
170
|
+
};
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
case "notification": {
|
|
174
|
+
const notification = notifications.get(query.notificationId);
|
|
175
|
+
result = { kind: query.kind, ...notification ? { notification } : {} };
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case "ceiling": {
|
|
179
|
+
const ceiling = ceilings.get(query.ceilingId);
|
|
180
|
+
result = {
|
|
181
|
+
kind: query.kind,
|
|
182
|
+
ceilingId: query.ceilingId,
|
|
183
|
+
...ceiling ? { origin: ceiling.origin } : {},
|
|
184
|
+
page: page(
|
|
185
|
+
{ kind: query.kind, ceilingId: query.ceilingId },
|
|
186
|
+
ceiling?.targets ?? [],
|
|
187
|
+
delegationInputDigest,
|
|
188
|
+
query,
|
|
189
|
+
512
|
|
190
|
+
)
|
|
191
|
+
};
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return freezeDelegationData(result);
|
|
196
|
+
},
|
|
197
|
+
async scan(input) {
|
|
198
|
+
const query = parseDelegationStoreScanInput(input);
|
|
199
|
+
if (query.kind === "eligible_notifications") return freezeDelegationData({
|
|
200
|
+
kind: query.kind,
|
|
201
|
+
page: page(
|
|
202
|
+
{ kind: query.kind },
|
|
203
|
+
[...notifications.values()].filter((notification) => notification.state === "pending" || notification.state === "claimed" && notification.claim?.ownerEpoch !== owner?.epoch),
|
|
204
|
+
(notification) => notification.envelope.notificationId,
|
|
205
|
+
query
|
|
206
|
+
)
|
|
207
|
+
});
|
|
208
|
+
const selected = [...runs.values()].filter((run) => query.kind === "queued" ? run.phase === "queued" : run.phase !== "settled" && run.ownerEpoch !== owner?.epoch);
|
|
209
|
+
return freezeDelegationData({ kind: query.kind, page: page({ kind: query.kind }, selected, runKey, query) });
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
export {
|
|
214
|
+
createInMemoryDelegationStore
|
|
215
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DelegationLimits } from "../shared/limits.js";
|
|
2
|
+
import type { DelegationPage, DelegationRunRecord, DelegationRunSummary } from "../tasks/types.js";
|
|
3
|
+
export declare function summarizeDelegationRun(run: DelegationRunRecord): DelegationRunSummary;
|
|
4
|
+
export declare function delegationCursorPrefix(storeId: string, query: unknown): string;
|
|
5
|
+
export declare function parseDelegationPageCursor(storeId: string, query: unknown, cursor?: string): string | undefined;
|
|
6
|
+
export declare function pageDelegationRows<Value>(input: {
|
|
7
|
+
readonly storeId: string;
|
|
8
|
+
readonly query: unknown;
|
|
9
|
+
readonly rows: readonly Value[];
|
|
10
|
+
readonly key: (value: Value) => string;
|
|
11
|
+
readonly limits: DelegationLimits;
|
|
12
|
+
readonly cursor?: string;
|
|
13
|
+
readonly limit?: number;
|
|
14
|
+
readonly envelopeBytes?: number;
|
|
15
|
+
}): DelegationPage<Value>;
|
|
16
|
+
//# sourceMappingURL=pages.d.ts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { failDelegation } from "../shared/operational-errors.js";
|
|
2
|
+
import { delegationDataBytes, delegationInputDigest } from "../shared/identity.js";
|
|
3
|
+
function summarizeDelegationRun(run) {
|
|
4
|
+
const { input: _input, ...summary } = run;
|
|
5
|
+
return summary;
|
|
6
|
+
}
|
|
7
|
+
function delegationCursorPrefix(storeId, query) {
|
|
8
|
+
return `${storeId}:${delegationInputDigest(query).slice(0, 16)}:`;
|
|
9
|
+
}
|
|
10
|
+
function parseDelegationPageCursor(storeId, query, cursor) {
|
|
11
|
+
if (cursor === void 0) return void 0;
|
|
12
|
+
const prefix = delegationCursorPrefix(storeId, query);
|
|
13
|
+
if (!cursor.startsWith(prefix)) failDelegation("stale_revision", "The cursor belongs to a different store query.");
|
|
14
|
+
const key = cursor.slice(prefix.length);
|
|
15
|
+
if (!key || key.length > 128) failDelegation("stale_revision", "The retained cursor is invalid.");
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
function pageDelegationRows(input) {
|
|
19
|
+
const after = parseDelegationPageCursor(input.storeId, input.query, input.cursor);
|
|
20
|
+
const limit = Math.min(input.limit ?? input.limits.maxPageRecords, input.limits.maxPageRecords);
|
|
21
|
+
const rows = [...input.rows].sort((left, right) => {
|
|
22
|
+
const a = input.key(left), b = input.key(right);
|
|
23
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
24
|
+
});
|
|
25
|
+
const items = [];
|
|
26
|
+
let bytes = (input.envelopeBytes ?? 0) + 512;
|
|
27
|
+
let hasMore = false;
|
|
28
|
+
for (const row of rows) {
|
|
29
|
+
if (after !== void 0 && input.key(row) <= after) continue;
|
|
30
|
+
const size = delegationDataBytes(row) + 1;
|
|
31
|
+
if (items.length >= limit || bytes + size > input.limits.maxPageBytes) {
|
|
32
|
+
if (items.length === 0) failDelegation("capacity_exceeded", "A complete record exceeds this read page budget.");
|
|
33
|
+
hasMore = true;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
items.push(row);
|
|
37
|
+
bytes += size;
|
|
38
|
+
}
|
|
39
|
+
return { items, ...hasMore ? { cursor: `${delegationCursorPrefix(input.storeId, input.query)}${input.key(items.at(-1))}` } : {} };
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
delegationCursorPrefix,
|
|
43
|
+
pageDelegationRows,
|
|
44
|
+
parseDelegationPageCursor,
|
|
45
|
+
summarizeDelegationRun
|
|
46
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DelegationStoreCommand, DelegationStoreReadInput, DelegationStoreScanInput } from "./types.js";
|
|
2
|
+
export declare function parseDelegationStoreCommand(input: unknown): DelegationStoreCommand;
|
|
3
|
+
export declare const parseDelegationStoreReadInput: (input: unknown) => DelegationStoreReadInput;
|
|
4
|
+
export declare const parseDelegationStoreScanInput: (input: unknown) => DelegationStoreScanInput;
|
|
5
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { AgentTurnInputContentSchema } from "@agen-ai/agent-protocol/zod";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
import { copyBoundedDelegationData } from "../shared/bounds.js";
|
|
4
|
+
import { delegationSchemaError } from "../shared/errors.js";
|
|
5
|
+
import { freezeDelegationData } from "../shared/immutable.js";
|
|
6
|
+
import { parseDelegationPolicyCeiling } from "../tasks/parse.js";
|
|
7
|
+
import {
|
|
8
|
+
AtSchema,
|
|
9
|
+
CompletionPolicySchema,
|
|
10
|
+
CountSchema,
|
|
11
|
+
DigestSchema,
|
|
12
|
+
HistoricalRequestSchema,
|
|
13
|
+
ObservationSchema,
|
|
14
|
+
OpaqueIdSchema,
|
|
15
|
+
OwnerTokenSchema,
|
|
16
|
+
ParentScopeSchema,
|
|
17
|
+
PolicyCeilingSchema,
|
|
18
|
+
RunOutcomeSchema,
|
|
19
|
+
StoreIdSchema,
|
|
20
|
+
TargetReferenceSchema
|
|
21
|
+
} from "../tasks/schemas.js";
|
|
22
|
+
const fence = {
|
|
23
|
+
owner: OwnerTokenSchema,
|
|
24
|
+
operationId: StoreIdSchema,
|
|
25
|
+
inputDigest: DigestSchema,
|
|
26
|
+
taskId: StoreIdSchema,
|
|
27
|
+
expectedTaskRevision: CountSchema,
|
|
28
|
+
runId: StoreIdSchema.optional(),
|
|
29
|
+
expectedRunRevision: CountSchema.optional()
|
|
30
|
+
};
|
|
31
|
+
const admission = z.strictObject({
|
|
32
|
+
parent: ParentScopeSchema,
|
|
33
|
+
ancestorTaskId: StoreIdSchema.optional(),
|
|
34
|
+
depth: z.number().int().positive(),
|
|
35
|
+
policyCeiling: PolicyCeilingSchema,
|
|
36
|
+
completionPolicy: CompletionPolicySchema,
|
|
37
|
+
runId: StoreIdSchema,
|
|
38
|
+
previousRunId: StoreIdSchema.optional(),
|
|
39
|
+
continuationMode: z.enum(["next_turn", "follow_up"]).optional(),
|
|
40
|
+
target: TargetReferenceSchema,
|
|
41
|
+
policyRevision: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
42
|
+
originPolicyRevision: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
43
|
+
input: AgentTurnInputContentSchema,
|
|
44
|
+
createdAt: AtSchema,
|
|
45
|
+
deadlineAt: AtSchema,
|
|
46
|
+
queuedStartDeadlineAt: AtSchema
|
|
47
|
+
}).refine((value) => value.previousRunId !== void 0 === (value.continuationMode !== void 0), {
|
|
48
|
+
path: ["continuationMode"],
|
|
49
|
+
message: "A continuation mode requires exactly one previous run reference."
|
|
50
|
+
});
|
|
51
|
+
const deliveryResult = z.discriminatedUnion("status", [
|
|
52
|
+
z.strictObject({ status: z.literal("accepted"), inboxId: OpaqueIdSchema, acceptedAt: AtSchema }),
|
|
53
|
+
z.strictObject({ status: z.literal("blocked"), reason: z.enum(["busy", "authority_unavailable", "capacity"]), retryAt: AtSchema }),
|
|
54
|
+
z.strictObject({ status: z.literal("uncertain"), retryAt: AtSchema }),
|
|
55
|
+
z.strictObject({ status: z.enum(["rejected", "expired", "dismissed"]), reason: z.string().max(1e3) })
|
|
56
|
+
]);
|
|
57
|
+
const commandSchema = z.discriminatedUnion("kind", [
|
|
58
|
+
z.strictObject({ ...fence, kind: z.literal("admit"), admission }),
|
|
59
|
+
z.strictObject({
|
|
60
|
+
...fence,
|
|
61
|
+
kind: z.literal("dispatch_intent"),
|
|
62
|
+
operationKind: z.enum(["prepare", "configure", "turn", "steer", "request_resolution", "interrupt", "session_close", "binding_cleanup"]),
|
|
63
|
+
at: AtSchema,
|
|
64
|
+
appliedTarget: TargetReferenceSchema.optional(),
|
|
65
|
+
attempt: z.union([z.literal(1), z.literal(2)]).optional()
|
|
66
|
+
}),
|
|
67
|
+
z.strictObject({
|
|
68
|
+
...fence,
|
|
69
|
+
kind: z.literal("operation_receipt"),
|
|
70
|
+
disposition: z.enum(["delegated", "delivered", "rejected", "interruption_requested", "uncertain", "completed"]),
|
|
71
|
+
at: AtSchema,
|
|
72
|
+
message: z.string().max(1e3).optional(),
|
|
73
|
+
requestState: z.enum(["pending", "unavailable"]).optional()
|
|
74
|
+
}),
|
|
75
|
+
z.strictObject({ ...fence, kind: z.literal("observe"), observation: ObservationSchema }),
|
|
76
|
+
z.strictObject({
|
|
77
|
+
...fence,
|
|
78
|
+
kind: z.literal("request_state"),
|
|
79
|
+
state: z.enum(["opened", "resolution_intended", "resolved", "unavailable"]),
|
|
80
|
+
request: HistoricalRequestSchema,
|
|
81
|
+
at: AtSchema
|
|
82
|
+
}),
|
|
83
|
+
z.strictObject({ ...fence, kind: z.literal("cancel"), at: AtSchema, reason: z.string().min(1).max(1e3) }),
|
|
84
|
+
z.strictObject({ ...fence, kind: z.literal("settle"), outcome: RunOutcomeSchema, at: AtSchema }),
|
|
85
|
+
z.strictObject({
|
|
86
|
+
...fence,
|
|
87
|
+
kind: z.literal("delivery_claim"),
|
|
88
|
+
notificationId: StoreIdSchema,
|
|
89
|
+
expectedNotificationRevision: CountSchema,
|
|
90
|
+
attemptId: StoreIdSchema,
|
|
91
|
+
at: AtSchema
|
|
92
|
+
}),
|
|
93
|
+
z.strictObject({
|
|
94
|
+
...fence,
|
|
95
|
+
kind: z.literal("delivery_receipt"),
|
|
96
|
+
notificationId: StoreIdSchema,
|
|
97
|
+
expectedNotificationRevision: CountSchema,
|
|
98
|
+
attemptId: StoreIdSchema,
|
|
99
|
+
result: deliveryResult,
|
|
100
|
+
at: AtSchema
|
|
101
|
+
}),
|
|
102
|
+
z.strictObject({ ...fence, kind: z.literal("retire_recovery"), reason: z.string().min(1).max(1e3), at: AtSchema })
|
|
103
|
+
]);
|
|
104
|
+
const page = { cursor: z.string().max(256).optional(), limit: z.number().int().positive().max(100).optional() };
|
|
105
|
+
const readSchema = z.discriminatedUnion("kind", [
|
|
106
|
+
z.strictObject({ kind: z.literal("task"), taskId: StoreIdSchema, ...page }),
|
|
107
|
+
z.strictObject({ kind: z.literal("run"), taskId: StoreIdSchema, runId: StoreIdSchema }),
|
|
108
|
+
z.strictObject({ kind: z.literal("operation"), parent: ParentScopeSchema, operationId: StoreIdSchema }),
|
|
109
|
+
z.strictObject({ kind: z.literal("operations"), taskId: StoreIdSchema, runId: StoreIdSchema, ...page }),
|
|
110
|
+
z.strictObject({ kind: z.literal("observations"), taskId: StoreIdSchema, runId: StoreIdSchema, ...page }),
|
|
111
|
+
z.strictObject({ kind: z.literal("notification"), notificationId: StoreIdSchema }),
|
|
112
|
+
z.strictObject({ kind: z.literal("ceiling"), ceilingId: DigestSchema, ...page }),
|
|
113
|
+
z.strictObject({ kind: z.literal("capacity") })
|
|
114
|
+
]);
|
|
115
|
+
const scanSchema = z.strictObject({
|
|
116
|
+
kind: z.enum(["queued", "recoverable_runs", "eligible_notifications"]),
|
|
117
|
+
at: AtSchema,
|
|
118
|
+
...page
|
|
119
|
+
});
|
|
120
|
+
function parse(schema, input) {
|
|
121
|
+
const captured = copyBoundedDelegationData(input);
|
|
122
|
+
const parsed = schema.safeParse(captured);
|
|
123
|
+
if (!parsed.success) return delegationSchemaError(parsed.error, captured);
|
|
124
|
+
return freezeDelegationData(parsed.data);
|
|
125
|
+
}
|
|
126
|
+
function parseDelegationStoreCommand(input) {
|
|
127
|
+
const value = parse(commandSchema, input);
|
|
128
|
+
if (value.kind === "admit") parseDelegationPolicyCeiling(value.admission.policyCeiling);
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
const parseDelegationStoreReadInput = (input) => parse(readSchema, input);
|
|
132
|
+
const parseDelegationStoreScanInput = (input) => parse(scanSchema, input);
|
|
133
|
+
export {
|
|
134
|
+
parseDelegationStoreCommand,
|
|
135
|
+
parseDelegationStoreReadInput,
|
|
136
|
+
parseDelegationStoreScanInput
|
|
137
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { AgentTurnInputContent } from "@agen-ai/agent-protocol";
|
|
2
|
+
import type { DelegationTargetReference } from "../catalog/types.js";
|
|
3
|
+
import type { DelegationLimits } from "../shared/limits.js";
|
|
4
|
+
import type { DelegationCompletionPolicy, DelegationHistoricalRequest, DelegationNotificationRecord, DelegationOwnerToken, DelegationPage, DelegationParentScope, DelegationPersistence, DelegationPolicyCeiling, DelegationRunOutcome, DelegationRunRecord, DelegationTaskObservation, DelegationTaskView } from "../tasks/types.js";
|
|
5
|
+
export type DelegationOperationKind = "admit" | "prepare" | "configure" | "turn" | "steer" | "request_resolution" | "cancel" | "interrupt" | "session_close" | "binding_cleanup";
|
|
6
|
+
export type DelegationCriticalSlot = "cancel" | "interrupt" | "session_close" | "binding_cleanup";
|
|
7
|
+
export type DelegationOperationDisposition = "intent" | "delegated" | "delivered" | "rejected" | "interruption_requested" | "uncertain" | "completed";
|
|
8
|
+
export interface DelegationCommitReceipt {
|
|
9
|
+
readonly duplicate: boolean;
|
|
10
|
+
readonly status: "queued" | "preparing" | "running" | "waiting" | "settled" | "recorded" | "omitted" | "retired";
|
|
11
|
+
readonly taskId: string;
|
|
12
|
+
readonly taskRevision: number;
|
|
13
|
+
readonly runId?: string;
|
|
14
|
+
readonly runRevision?: number;
|
|
15
|
+
readonly operationId?: string;
|
|
16
|
+
readonly notificationId?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface DelegationOperationRecord {
|
|
19
|
+
readonly operationId: string;
|
|
20
|
+
readonly parent: DelegationParentScope;
|
|
21
|
+
readonly taskId: string;
|
|
22
|
+
readonly runId: string;
|
|
23
|
+
readonly kind: DelegationOperationKind;
|
|
24
|
+
readonly inputDigest: string;
|
|
25
|
+
readonly ownerEpoch: number;
|
|
26
|
+
readonly disposition: DelegationOperationDisposition;
|
|
27
|
+
readonly attempts: number;
|
|
28
|
+
readonly at: string;
|
|
29
|
+
readonly message?: string;
|
|
30
|
+
readonly request?: Readonly<Pick<DelegationHistoricalRequest, "requestId" | "requestKind">>;
|
|
31
|
+
readonly requestState?: "pending" | "unavailable";
|
|
32
|
+
readonly receipt: DelegationCommitReceipt;
|
|
33
|
+
}
|
|
34
|
+
export interface DelegationStoreCapacity {
|
|
35
|
+
readonly tasks: number;
|
|
36
|
+
readonly runs: number;
|
|
37
|
+
readonly activeRuns: number;
|
|
38
|
+
readonly queuedRuns: number;
|
|
39
|
+
readonly retainedInputBytes: number;
|
|
40
|
+
readonly observationBytes: number;
|
|
41
|
+
readonly ordinaryOperations: number;
|
|
42
|
+
readonly reservedBytes: number;
|
|
43
|
+
readonly criticalSlots: number;
|
|
44
|
+
}
|
|
45
|
+
export interface DelegationMutationFence {
|
|
46
|
+
readonly owner: DelegationOwnerToken;
|
|
47
|
+
readonly operationId: string;
|
|
48
|
+
readonly inputDigest: string;
|
|
49
|
+
readonly taskId: string;
|
|
50
|
+
readonly expectedTaskRevision: number;
|
|
51
|
+
readonly runId?: string;
|
|
52
|
+
readonly expectedRunRevision?: number;
|
|
53
|
+
}
|
|
54
|
+
export interface DelegationRunAdmission {
|
|
55
|
+
readonly parent: DelegationParentScope;
|
|
56
|
+
readonly ancestorTaskId?: string;
|
|
57
|
+
readonly depth: number;
|
|
58
|
+
readonly policyCeiling: DelegationPolicyCeiling;
|
|
59
|
+
readonly completionPolicy: DelegationCompletionPolicy;
|
|
60
|
+
readonly runId: string;
|
|
61
|
+
readonly previousRunId?: string;
|
|
62
|
+
readonly continuationMode?: "next_turn" | "follow_up";
|
|
63
|
+
readonly target: DelegationTargetReference;
|
|
64
|
+
readonly policyRevision: number;
|
|
65
|
+
readonly originPolicyRevision: number;
|
|
66
|
+
readonly input: AgentTurnInputContent;
|
|
67
|
+
readonly createdAt: string;
|
|
68
|
+
readonly deadlineAt: string;
|
|
69
|
+
readonly queuedStartDeadlineAt: string;
|
|
70
|
+
}
|
|
71
|
+
export type DelegationDeliveryResult = Readonly<{
|
|
72
|
+
status: "accepted";
|
|
73
|
+
inboxId: string;
|
|
74
|
+
acceptedAt: string;
|
|
75
|
+
}> | Readonly<{
|
|
76
|
+
status: "blocked";
|
|
77
|
+
reason: "busy" | "authority_unavailable" | "capacity";
|
|
78
|
+
retryAt: string;
|
|
79
|
+
}> | Readonly<{
|
|
80
|
+
status: "uncertain";
|
|
81
|
+
retryAt: string;
|
|
82
|
+
}> | Readonly<{
|
|
83
|
+
status: "rejected" | "expired" | "dismissed";
|
|
84
|
+
reason: string;
|
|
85
|
+
}>;
|
|
86
|
+
export type DelegationStoreCommand = DelegationMutationFence & (Readonly<{
|
|
87
|
+
kind: "admit";
|
|
88
|
+
admission: DelegationRunAdmission;
|
|
89
|
+
}> | Readonly<{
|
|
90
|
+
kind: "dispatch_intent";
|
|
91
|
+
operationKind: Exclude<DelegationOperationKind, "admit" | "cancel">;
|
|
92
|
+
at: string;
|
|
93
|
+
appliedTarget?: DelegationTargetReference;
|
|
94
|
+
attempt?: 1 | 2;
|
|
95
|
+
}> | Readonly<{
|
|
96
|
+
kind: "operation_receipt";
|
|
97
|
+
disposition: Exclude<DelegationOperationDisposition, "intent">;
|
|
98
|
+
at: string;
|
|
99
|
+
message?: string;
|
|
100
|
+
requestState?: "pending" | "unavailable";
|
|
101
|
+
}> | Readonly<{
|
|
102
|
+
kind: "observe";
|
|
103
|
+
observation: DelegationTaskObservation;
|
|
104
|
+
}> | Readonly<{
|
|
105
|
+
kind: "request_state";
|
|
106
|
+
state: "opened" | "resolution_intended" | "resolved" | "unavailable";
|
|
107
|
+
request: DelegationHistoricalRequest;
|
|
108
|
+
at: string;
|
|
109
|
+
}> | Readonly<{
|
|
110
|
+
kind: "cancel";
|
|
111
|
+
at: string;
|
|
112
|
+
reason: string;
|
|
113
|
+
}> | Readonly<{
|
|
114
|
+
kind: "settle";
|
|
115
|
+
outcome: DelegationRunOutcome;
|
|
116
|
+
at: string;
|
|
117
|
+
}> | Readonly<{
|
|
118
|
+
kind: "delivery_claim";
|
|
119
|
+
notificationId: string;
|
|
120
|
+
expectedNotificationRevision: number;
|
|
121
|
+
attemptId: string;
|
|
122
|
+
at: string;
|
|
123
|
+
}> | Readonly<{
|
|
124
|
+
kind: "delivery_receipt";
|
|
125
|
+
notificationId: string;
|
|
126
|
+
expectedNotificationRevision: number;
|
|
127
|
+
attemptId: string;
|
|
128
|
+
result: DelegationDeliveryResult;
|
|
129
|
+
at: string;
|
|
130
|
+
}> | Readonly<{
|
|
131
|
+
kind: "retire_recovery";
|
|
132
|
+
reason: string;
|
|
133
|
+
at: string;
|
|
134
|
+
}>);
|
|
135
|
+
interface DelegationPageInput {
|
|
136
|
+
readonly cursor?: string;
|
|
137
|
+
readonly limit?: number;
|
|
138
|
+
}
|
|
139
|
+
export type DelegationStoreReadInput = (Readonly<{
|
|
140
|
+
kind: "task";
|
|
141
|
+
taskId: string;
|
|
142
|
+
}> & DelegationPageInput) | Readonly<{
|
|
143
|
+
kind: "run";
|
|
144
|
+
taskId: string;
|
|
145
|
+
runId: string;
|
|
146
|
+
}> | Readonly<{
|
|
147
|
+
kind: "operation";
|
|
148
|
+
parent: DelegationParentScope;
|
|
149
|
+
operationId: string;
|
|
150
|
+
}> | (Readonly<{
|
|
151
|
+
kind: "operations";
|
|
152
|
+
taskId: string;
|
|
153
|
+
runId: string;
|
|
154
|
+
}> & DelegationPageInput) | (Readonly<{
|
|
155
|
+
kind: "observations";
|
|
156
|
+
taskId: string;
|
|
157
|
+
runId: string;
|
|
158
|
+
}> & DelegationPageInput) | Readonly<{
|
|
159
|
+
kind: "notification";
|
|
160
|
+
notificationId: string;
|
|
161
|
+
}> | (Readonly<{
|
|
162
|
+
kind: "ceiling";
|
|
163
|
+
ceilingId: string;
|
|
164
|
+
}> & DelegationPageInput) | Readonly<{
|
|
165
|
+
kind: "capacity";
|
|
166
|
+
}>;
|
|
167
|
+
export type DelegationStoreReadPage = Readonly<{
|
|
168
|
+
kind: "task";
|
|
169
|
+
view?: DelegationTaskView;
|
|
170
|
+
}> | Readonly<{
|
|
171
|
+
kind: "run";
|
|
172
|
+
run?: DelegationRunRecord;
|
|
173
|
+
}> | Readonly<{
|
|
174
|
+
kind: "operation";
|
|
175
|
+
operation?: DelegationOperationRecord;
|
|
176
|
+
}> | Readonly<{
|
|
177
|
+
kind: "operations";
|
|
178
|
+
page: DelegationPage<DelegationOperationRecord>;
|
|
179
|
+
}> | Readonly<{
|
|
180
|
+
kind: "observations";
|
|
181
|
+
page: DelegationPage<DelegationTaskObservation>;
|
|
182
|
+
latestIndex: number;
|
|
183
|
+
gap: boolean;
|
|
184
|
+
}> | Readonly<{
|
|
185
|
+
kind: "notification";
|
|
186
|
+
notification?: DelegationNotificationRecord;
|
|
187
|
+
}> | Readonly<{
|
|
188
|
+
kind: "ceiling";
|
|
189
|
+
ceilingId: string;
|
|
190
|
+
origin?: DelegationParentScope;
|
|
191
|
+
page: DelegationPage<DelegationTargetReference>;
|
|
192
|
+
}> | Readonly<{
|
|
193
|
+
kind: "capacity";
|
|
194
|
+
capacity: DelegationStoreCapacity;
|
|
195
|
+
}>;
|
|
196
|
+
export type DelegationStoreScanInput = DelegationPageInput & Readonly<{
|
|
197
|
+
kind: "queued" | "recoverable_runs" | "eligible_notifications";
|
|
198
|
+
at: string;
|
|
199
|
+
}>;
|
|
200
|
+
export type DelegationStoreScanPage = Readonly<{
|
|
201
|
+
kind: "queued" | "recoverable_runs";
|
|
202
|
+
page: DelegationPage<DelegationRunRecord>;
|
|
203
|
+
}> | Readonly<{
|
|
204
|
+
kind: "eligible_notifications";
|
|
205
|
+
page: DelegationPage<DelegationNotificationRecord>;
|
|
206
|
+
}>;
|
|
207
|
+
export interface DelegationStore {
|
|
208
|
+
readonly contractVersion: 3;
|
|
209
|
+
readonly persistence: DelegationPersistence;
|
|
210
|
+
readonly storeId: string;
|
|
211
|
+
readonly limits: DelegationLimits;
|
|
212
|
+
acquireOwner(): Promise<DelegationOwnerToken>;
|
|
213
|
+
commit(command: DelegationStoreCommand): Promise<DelegationCommitReceipt>;
|
|
214
|
+
read(input: DelegationStoreReadInput): Promise<DelegationStoreReadPage>;
|
|
215
|
+
scan(input: DelegationStoreScanInput): Promise<DelegationStoreScanPage>;
|
|
216
|
+
releaseOwner(owner: DelegationOwnerToken): Promise<void>;
|
|
217
|
+
}
|
|
218
|
+
export {};
|
|
219
|
+
//# sourceMappingURL=types.d.ts.map
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DelegationStoreCommand } from "../store/types.js";
|
|
2
|
+
import { type CommitContext } from "./context.js";
|
|
3
|
+
export declare function admitRun(context: CommitContext, command: Extract<DelegationStoreCommand, {
|
|
4
|
+
kind: "admit";
|
|
5
|
+
}>): void;
|
|
6
|
+
//# sourceMappingURL=admission.d.ts.map
|