@alineo-labs/schema 0.0.0-stage → 0.2.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/README.md +126 -3
- package/dist/agent-spec-BeNVCYXF.d.mts +518 -0
- package/dist/agent-spec-iZ9p1pjI.mjs +1057 -0
- package/dist/alineod.d.mts +625 -0
- package/dist/alineod.mjs +309 -0
- package/dist/index-DJ7T_9Z-.d.mts +480 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +179 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +47 -4
package/dist/alineod.mjs
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { s as allEvents, t as AgentSpecSchema } from "./agent-spec-iZ9p1pjI.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/alineod.ts
|
|
4
|
+
/**
|
|
5
|
+
* alineod's wire contract, as Zod.
|
|
6
|
+
*
|
|
7
|
+
* Here rather than inside `apps/alineod` because three things need it and only one of them
|
|
8
|
+
* is the daemon: alineod's own route validators, the emitted `apps/alineod/spec/openapi.json`,
|
|
9
|
+
* and `alineo-mcp`, which talks to alineod over HTTP like any other client.
|
|
10
|
+
*
|
|
11
|
+
* `alineo-mcp` used to mirror eleven of these shapes by hand, documented as deliberate —
|
|
12
|
+
* "typed against the wire contract, not against alineod's internal Zod schemas". That was a
|
|
13
|
+
* fair objection while the schemas were an app's internals. It stops being one now the
|
|
14
|
+
* contract is a published package, which is the whole reason this file moved.
|
|
15
|
+
*
|
|
16
|
+
* Types and Zod only. The routes, the projections and the engine stay in `apps/alineod`.
|
|
17
|
+
*/
|
|
18
|
+
/** The real spec, not a re-model. See `agent-spec.ts`. */
|
|
19
|
+
const AgentSpec = AgentSpecSchema;
|
|
20
|
+
const BudgetOverride = z.object({
|
|
21
|
+
spawnDepth: z.number().int().nonnegative().optional(),
|
|
22
|
+
maxAgents: z.number().int().nonnegative().optional()
|
|
23
|
+
}).describe("Overrides the spec's own spawnDepth / maxAgents (flag-beats-config).");
|
|
24
|
+
const CloseWhen = z.enum(["explicit", "quiescent"]).describe("\"explicit\" (default): the run stays open until a client deletes it. \"quiescent\": the run closes itself the moment every agent in it is terminal and has nothing left to deliver.");
|
|
25
|
+
const CreateRunBody = z.object({
|
|
26
|
+
spec: AgentSpec,
|
|
27
|
+
prompt: z.string().optional().describe("If set, drive one turn on the root agent after load."),
|
|
28
|
+
budget: BudgetOverride.optional(),
|
|
29
|
+
closeWhen: CloseWhen.default("explicit")
|
|
30
|
+
});
|
|
31
|
+
const CreateRunResponse = z.object({
|
|
32
|
+
runId: z.string(),
|
|
33
|
+
rootAgentId: z.string(),
|
|
34
|
+
state: z.string().describe("Always \"provisioning\" at return time (the route is async) — poll for the real state.")
|
|
35
|
+
});
|
|
36
|
+
const WaitMode = z.enum([
|
|
37
|
+
"settled",
|
|
38
|
+
"all",
|
|
39
|
+
"any",
|
|
40
|
+
"quorum"
|
|
41
|
+
]).describe("settled: every agent terminal, any outcome · all: every agent succeeded · any: the first to settle · quorum: k successes.");
|
|
42
|
+
const WaitForSpec = z.object({
|
|
43
|
+
agents: z.array(z.string()).min(1),
|
|
44
|
+
mode: WaitMode.optional(),
|
|
45
|
+
k: z.number().int().positive().optional().describe("quorum: how many successes are needed (default: all)."),
|
|
46
|
+
onDepFailure: z.enum(["fail", "proceed"]).optional().describe("all / quorum: what a failed dependency (or an unreachable quorum) does. Default fail."),
|
|
47
|
+
deadlineSec: z.number().positive().optional(),
|
|
48
|
+
onDeadline: z.enum(["proceed", "fail"]).optional().describe("At the deadline: proceed with whatever settled (partial), or fail. Default proceed.")
|
|
49
|
+
});
|
|
50
|
+
const RunAwaitBody = z.object({
|
|
51
|
+
agents: z.array(z.string()).min(1).optional(),
|
|
52
|
+
subtree: z.string().optional().describe("Wait for this agent's subtree to become quiescent instead."),
|
|
53
|
+
mode: WaitMode.optional(),
|
|
54
|
+
k: z.number().int().positive().optional(),
|
|
55
|
+
onDepFailure: z.enum(["fail", "proceed"]).optional(),
|
|
56
|
+
wait: z.number().min(0).optional().describe("Seconds to hold the request (capped server-side).")
|
|
57
|
+
}).refine((b) => b.agents ? !b.subtree : !!b.subtree, { message: "give exactly one of agents or subtree" });
|
|
58
|
+
const RunAwaitResponse = z.object({
|
|
59
|
+
outcome: z.enum([
|
|
60
|
+
"satisfied",
|
|
61
|
+
"partial",
|
|
62
|
+
"depfail",
|
|
63
|
+
"pending"
|
|
64
|
+
]),
|
|
65
|
+
selected: z.array(z.string()),
|
|
66
|
+
settled: z.array(z.object({
|
|
67
|
+
agentId: z.string(),
|
|
68
|
+
outcome: z.string().nullable()
|
|
69
|
+
})),
|
|
70
|
+
pending: z.array(z.string())
|
|
71
|
+
});
|
|
72
|
+
const QuiescenceView = z.object({
|
|
73
|
+
rootAgentId: z.string(),
|
|
74
|
+
quiescent: z.boolean().describe("Every member terminal and none still being spawned. Paused members count as not quiescent."),
|
|
75
|
+
asOf: z.number(),
|
|
76
|
+
members: z.array(z.object({
|
|
77
|
+
agentId: z.string(),
|
|
78
|
+
state: z.string(),
|
|
79
|
+
outcome: z.string().nullable(),
|
|
80
|
+
resultRef: z.string().nullable()
|
|
81
|
+
})),
|
|
82
|
+
blockedOnPaused: z.array(z.string())
|
|
83
|
+
});
|
|
84
|
+
const SpawnAgentBody = z.object({
|
|
85
|
+
spec: AgentSpec,
|
|
86
|
+
parentAgentId: z.string(),
|
|
87
|
+
waitFor: z.union([z.array(z.string()), WaitForSpec]).optional().describe("Hold the spawn until the named agents resolve (hold-then-spawn, D-c). A plain array means mode \"settled\": every agent terminal, any outcome."),
|
|
88
|
+
prompt: z.string().optional(),
|
|
89
|
+
notifyOn: z.array(z.string()).optional().describe("Tell this child when each named agent finishes, without blocking it (per-agent inbox): steered in if it's running, held while paused, prepended to its next prompt if idle."),
|
|
90
|
+
budget: BudgetOverride.optional(),
|
|
91
|
+
idempotencyKey: z.string().optional().describe("D-f: a retried POST with the same key returns the original spawn instead of creating a second child.")
|
|
92
|
+
});
|
|
93
|
+
const SpawnAgentResponse = z.object({
|
|
94
|
+
agentId: z.string(),
|
|
95
|
+
state: z.string().describe("\"spawning\" if waitFor is set, else \"provisioning\" — poll for the real state.")
|
|
96
|
+
});
|
|
97
|
+
const AgentView = z.object({
|
|
98
|
+
agentId: z.string(),
|
|
99
|
+
runId: z.string(),
|
|
100
|
+
parentAgentId: z.string().nullable(),
|
|
101
|
+
depth: z.number().int(),
|
|
102
|
+
spawnIndex: z.number().int(),
|
|
103
|
+
state: z.string(),
|
|
104
|
+
specName: z.string(),
|
|
105
|
+
sandboxId: z.string().nullable(),
|
|
106
|
+
createdAt: z.number(),
|
|
107
|
+
endedAt: z.number().nullable(),
|
|
108
|
+
outcome: z.string().nullable(),
|
|
109
|
+
pausedBy: z.string().nullable().describe("While paused: \"operator\" (it was the target) or \"cascade\" (a subtree pause reached it).")
|
|
110
|
+
});
|
|
111
|
+
const TreeView = z.object({
|
|
112
|
+
runId: z.string(),
|
|
113
|
+
rootAgentId: z.string().nullable(),
|
|
114
|
+
agents: z.array(AgentView),
|
|
115
|
+
asOf: z.number().describe("Highest ledger seq reflected in this projection."),
|
|
116
|
+
closeWhen: CloseWhen,
|
|
117
|
+
state: z.enum(["open", "closed"]).describe("\"closed\": a client deleted it, or it reached quiescence under closeWhen: \"quiescent\".")
|
|
118
|
+
});
|
|
119
|
+
const AgentDetail = AgentView.extend({ sessionStats: z.unknown().optional() });
|
|
120
|
+
const ControlScopeBody = z.object({
|
|
121
|
+
scope: z.enum(["agent", "subtree"]).default("agent").describe("\"agent\" (default): the named agent only. \"subtree\": the agent and every descendant — pause parents-first, resume children-first."),
|
|
122
|
+
idempotencyKey: z.string().optional().describe("A retried request with the same key returns the original response instead of acting twice. scope: \"agent\" only — a subtree op does not support per-request idempotency.")
|
|
123
|
+
}).default({ scope: "agent" });
|
|
124
|
+
const SubtreeOpResult = z.object({
|
|
125
|
+
asOf: z.number().describe("Highest ledger seq when the subtree's membership was resolved."),
|
|
126
|
+
results: z.array(z.object({
|
|
127
|
+
agentId: z.string(),
|
|
128
|
+
outcome: z.enum([
|
|
129
|
+
"applied",
|
|
130
|
+
"skipped",
|
|
131
|
+
"failed"
|
|
132
|
+
]),
|
|
133
|
+
reason: z.string().optional()
|
|
134
|
+
}))
|
|
135
|
+
}).describe("Best-effort, per member: one member failing doesn't undo or block the rest.");
|
|
136
|
+
const NotifyOnBody = z.object({
|
|
137
|
+
agents: z.array(z.string()).min(1),
|
|
138
|
+
wake: z.boolean().optional().describe("If the subscriber is idle when a notification arrives, start a turn with it instead of queueing it.")
|
|
139
|
+
});
|
|
140
|
+
const StopAgentBody = z.object({
|
|
141
|
+
mode: z.enum(["abort", "drain"]).default("abort"),
|
|
142
|
+
scope: z.enum(["agent", "subtree"]).default("agent").describe("\"subtree\": the agent and every descendant, leaves first, with one result per member."),
|
|
143
|
+
idempotencyKey: z.string().optional().describe("A retried request with the same key returns the original response instead of acting twice. scope: \"agent\" only — a subtree op does not support per-request idempotency.")
|
|
144
|
+
}).default({
|
|
145
|
+
mode: "abort",
|
|
146
|
+
scope: "agent"
|
|
147
|
+
});
|
|
148
|
+
const PromptBody = z.object({ text: z.string().min(1) });
|
|
149
|
+
const SteerBody = z.object({
|
|
150
|
+
message: z.string().min(1),
|
|
151
|
+
scope: z.enum(["agent", "subtree"]).default("agent").describe("\"subtree\": deliver ONE message to this agent — your text plus a roster of its direct children — so it re-plans and redirects each child itself. Never a broadcast."),
|
|
152
|
+
idempotencyKey: z.string().optional().describe("A retried delivery with the same key is not delivered twice, and returns the same acknowledgement. scope: \"agent\" only — a subtree steer does not support per-request idempotency.")
|
|
153
|
+
}).describe("Injected into the agent's current turn (research/swarm-control.md §8).");
|
|
154
|
+
const SubtreeSteerResponse = z.object({
|
|
155
|
+
deliveredAs: z.enum([
|
|
156
|
+
"steer",
|
|
157
|
+
"turn",
|
|
158
|
+
"queued"
|
|
159
|
+
]).describe("steer: into its running turn · turn: a new turn (it was idle) · queued: it's paused; delivered on resume"),
|
|
160
|
+
roster: z.array(z.object({
|
|
161
|
+
agentId: z.string(),
|
|
162
|
+
sandboxId: z.string().nullable(),
|
|
163
|
+
specName: z.string(),
|
|
164
|
+
state: z.string(),
|
|
165
|
+
outcome: z.string().nullable()
|
|
166
|
+
}))
|
|
167
|
+
});
|
|
168
|
+
const ResultResponse = z.object({
|
|
169
|
+
agentId: z.string(),
|
|
170
|
+
state: z.enum(["pending", "settled"]),
|
|
171
|
+
outcome: z.string().nullable(),
|
|
172
|
+
resultRef: z.string().nullable(),
|
|
173
|
+
result: z.string().nullable().describe("The result text, inline.")
|
|
174
|
+
});
|
|
175
|
+
/** Bounds enforced at the wire, so one request can't park an unbounded blob in the store. */
|
|
176
|
+
const MEMORY_KEY_MAX_CHARS = 256;
|
|
177
|
+
const MEMORY_VALUE_MAX_BYTES = 65536;
|
|
178
|
+
const FACT_CONTENT_MAX_CHARS = 8192;
|
|
179
|
+
const ResourceRefView = z.object({
|
|
180
|
+
resourceId: z.string(),
|
|
181
|
+
teamId: z.string().optional()
|
|
182
|
+
});
|
|
183
|
+
const MemoryView = z.object({
|
|
184
|
+
agentId: z.string(),
|
|
185
|
+
resourceRef: ResourceRefView.describe("The scope every memory call below is keyed by: the agent spec's `resourceId` (default: its `name`) and `teamId`. Memory outlives the sandbox, so it stays readable after the agent ends."),
|
|
186
|
+
semantic: z.boolean().describe("Whether semantic memory (facts) is configured on this alineod."),
|
|
187
|
+
working: z.record(z.string(), z.unknown()).describe("One page of entries, in sorted key order. See `nextAfter`."),
|
|
188
|
+
nextAfter: z.string().optional().describe("Present when more keys follow: pass it as `?after=` to read the next page.")
|
|
189
|
+
});
|
|
190
|
+
const MemoryValueBody = z.object({ value: z.unknown().superRefine((v, ctx) => {
|
|
191
|
+
if (v === void 0) {
|
|
192
|
+
ctx.addIssue({
|
|
193
|
+
code: "custom",
|
|
194
|
+
message: "value is required"
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
let json;
|
|
199
|
+
try {
|
|
200
|
+
json = JSON.stringify(v);
|
|
201
|
+
} catch {
|
|
202
|
+
json = void 0;
|
|
203
|
+
}
|
|
204
|
+
if (json === void 0) ctx.addIssue({
|
|
205
|
+
code: "custom",
|
|
206
|
+
message: "value must be JSON-serializable"
|
|
207
|
+
});
|
|
208
|
+
else if (new TextEncoder().encode(json).byteLength > 65536) ctx.addIssue({
|
|
209
|
+
code: "custom",
|
|
210
|
+
message: `value must be at most ${MEMORY_VALUE_MAX_BYTES} bytes as JSON`
|
|
211
|
+
});
|
|
212
|
+
}) });
|
|
213
|
+
const MemoryValueResponse = z.object({
|
|
214
|
+
key: z.string(),
|
|
215
|
+
value: z.unknown()
|
|
216
|
+
});
|
|
217
|
+
const AddFactBody = z.object({
|
|
218
|
+
content: z.string().min(1).max(FACT_CONTENT_MAX_CHARS),
|
|
219
|
+
sourceRef: z.object({
|
|
220
|
+
sandboxId: z.string().min(1),
|
|
221
|
+
entryIndex: z.number().int().nonnegative()
|
|
222
|
+
}).optional().describe("Ties the fact to the ledger entry it came from. Only a fact with a `sourceRef` is `verified` — that flag is computed, never caller-set.")
|
|
223
|
+
});
|
|
224
|
+
const FactView = z.object({
|
|
225
|
+
id: z.string().optional(),
|
|
226
|
+
content: z.string(),
|
|
227
|
+
sourceRef: z.object({
|
|
228
|
+
sandboxId: z.string(),
|
|
229
|
+
entryIndex: z.number().int()
|
|
230
|
+
}).optional(),
|
|
231
|
+
verified: z.boolean().optional(),
|
|
232
|
+
rememberedAt: z.number().optional().describe("Epoch ms the fact was remembered. The shipped providers set it on every fact they return, recall and listing alike; optional only because the contract doesn't promise it of every possible provider.")
|
|
233
|
+
});
|
|
234
|
+
const FactsResponse = z.object({
|
|
235
|
+
agentId: z.string(),
|
|
236
|
+
query: z.string().nullable().describe("Echo of `?query=`; null when listing every fact."),
|
|
237
|
+
facts: z.array(FactView)
|
|
238
|
+
});
|
|
239
|
+
const CompactionBody = z.object({
|
|
240
|
+
maxFacts: z.number().int().positive().optional(),
|
|
241
|
+
maxAgeMs: z.number().int().positive().optional()
|
|
242
|
+
}).describe("Both optional and combinable; neither set removes nothing.");
|
|
243
|
+
const CompactionResultView = z.object({
|
|
244
|
+
removed: z.number().int(),
|
|
245
|
+
remaining: z.number().int(),
|
|
246
|
+
summarized: z.number().int()
|
|
247
|
+
});
|
|
248
|
+
const TranscriptMessage = z.discriminatedUnion("role", [
|
|
249
|
+
z.object({
|
|
250
|
+
role: z.literal("user"),
|
|
251
|
+
text: z.string()
|
|
252
|
+
}),
|
|
253
|
+
z.object({
|
|
254
|
+
role: z.literal("assistant"),
|
|
255
|
+
text: z.string(),
|
|
256
|
+
toolCalls: z.array(z.object({
|
|
257
|
+
name: z.string(),
|
|
258
|
+
arguments: z.unknown()
|
|
259
|
+
})),
|
|
260
|
+
stopReason: z.string().nullable(),
|
|
261
|
+
errorMessage: z.string().nullable(),
|
|
262
|
+
thinking: z.string().optional().describe("Only with `?full=1`.")
|
|
263
|
+
}),
|
|
264
|
+
z.object({
|
|
265
|
+
role: z.literal("tool"),
|
|
266
|
+
toolName: z.string(),
|
|
267
|
+
text: z.string(),
|
|
268
|
+
isError: z.boolean()
|
|
269
|
+
})
|
|
270
|
+
]);
|
|
271
|
+
const TranscriptResponse = z.object({
|
|
272
|
+
agentId: z.string(),
|
|
273
|
+
turns: z.array(z.object({
|
|
274
|
+
seq: z.number().int().describe("Ledger seq of the turn's `agent_end`."),
|
|
275
|
+
ts: z.number().int().describe("Epoch ms."),
|
|
276
|
+
messages: z.array(TranscriptMessage)
|
|
277
|
+
}))
|
|
278
|
+
});
|
|
279
|
+
const ALINEOD_SUBJECTS = [
|
|
280
|
+
"run",
|
|
281
|
+
"agent",
|
|
282
|
+
"handle",
|
|
283
|
+
"wait",
|
|
284
|
+
"inbox",
|
|
285
|
+
"notify",
|
|
286
|
+
"budget"
|
|
287
|
+
];
|
|
288
|
+
/**
|
|
289
|
+
* Every control-plane definition, as `{ event: "<type>", ...data }`.
|
|
290
|
+
*
|
|
291
|
+
* `definition.schema` is typed `z.ZodType` because a definition may hold any schema; every
|
|
292
|
+
* event's is in fact an object, and `.extend()` needs that. Narrowed with `instanceof` rather
|
|
293
|
+
* than an assertion, so a definition that ever stops being an object schema fails here loudly
|
|
294
|
+
* instead of at parse time.
|
|
295
|
+
*/
|
|
296
|
+
function alineodEventMembers() {
|
|
297
|
+
const members = [];
|
|
298
|
+
for (const definition of allEvents()) {
|
|
299
|
+
if (!ALINEOD_SUBJECTS.includes(definition.type.split(".")[0])) continue;
|
|
300
|
+
if (!(definition.schema instanceof z.ZodObject)) throw new Error(`Event "${definition.type}" is not defined with an object schema, so it cannot carry the "event" discriminator this union is built on.`);
|
|
301
|
+
members.push(definition.schema.extend({ event: z.literal(definition.type) }));
|
|
302
|
+
}
|
|
303
|
+
if (members.length === 0) throw new Error("No alineod event definitions are registered. Did this module load without ./events?");
|
|
304
|
+
return members;
|
|
305
|
+
}
|
|
306
|
+
const [firstMember, ...restMembers] = alineodEventMembers();
|
|
307
|
+
const AlineodEvent = z.discriminatedUnion("event", [firstMember, ...restMembers]);
|
|
308
|
+
//#endregion
|
|
309
|
+
export { AddFactBody, AgentDetail, AgentSpec, AgentView, AlineodEvent, BudgetOverride, CloseWhen, CompactionBody, CompactionResultView, ControlScopeBody, CreateRunBody, CreateRunResponse, FACT_CONTENT_MAX_CHARS, FactView, FactsResponse, MEMORY_KEY_MAX_CHARS, MEMORY_VALUE_MAX_BYTES, MemoryValueBody, MemoryValueResponse, MemoryView, NotifyOnBody, PromptBody, QuiescenceView, ResultResponse, RunAwaitBody, RunAwaitResponse, SpawnAgentBody, SpawnAgentResponse, SteerBody, StopAgentBody, SubtreeOpResult, SubtreeSteerResponse, TranscriptMessage, TranscriptResponse, TreeView, WaitForSpec, WaitMode };
|