@anchrd/intel-contract 0.4.2 → 0.5.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 +3 -3
- package/dist/contract/contract.d.ts +697 -78
- package/dist/contract/contract.js +396 -75
- package/package.json +1 -1
|
@@ -16,10 +16,22 @@ export const SessionUser = z.strictObject({
|
|
|
16
16
|
email: z.email(),
|
|
17
17
|
name: z.string().min(1).max(240).nullable(),
|
|
18
18
|
});
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
|
|
19
|
+
// What this installation is equipped to do — deployment facts, never the caller's permissions
|
|
20
|
+
// (those stay behind each door, where `/session` deliberately does not carry them). `agentRuntime`
|
|
21
|
+
// says whether an agent Worker is bound at all (#190): without it the UI offers no "New agent" and
|
|
22
|
+
// an agent node explains itself instead of rendering views that could only end in a 503.
|
|
23
|
+
export const IntelCapabilities = z.strictObject({
|
|
24
|
+
agentRuntime: z.boolean(),
|
|
25
|
+
});
|
|
26
|
+
// The fourth kind is `table` (#40) and the fifth is `agent` (#139). Each is a kind of node, not a
|
|
27
|
+
// kind of thing: it hangs in the same folder tree, inherits the same folder grants, carries the
|
|
28
|
+
// same immutable versions and the same R2 body as a document (ADR-0004 §1, ADR-0005 §1). Only the
|
|
29
|
+
// media type and the operations below differ.
|
|
30
|
+
//
|
|
31
|
+
// ⚠️ `agent` being optional is load-bearing (ADR-0005 §1): an installation without a single agent
|
|
32
|
+
// node is complete, not unfinished, and nothing here asks anyone to classify a document as a skill
|
|
33
|
+
// or a policy in order to file it.
|
|
34
|
+
export const NodeKind = z.enum(["folder", "document", "attachment", "table", "agent"]);
|
|
23
35
|
// ⚠️ There is no `ContextPolicy`, and it is not coming back in this shape (#76). It said whether a
|
|
24
36
|
// document should be pinned into a context, be found by relevance, or be named explicitly — an
|
|
25
37
|
// instruction to a retrieval Intel does not perform. Intel hands out references and the agent
|
|
@@ -34,10 +46,10 @@ export const SharePrincipal = z.discriminatedUnion("type", [
|
|
|
34
46
|
z.strictObject({ type: z.literal("email"), email: z.email() }),
|
|
35
47
|
z.strictObject({ type: z.literal("organization") }),
|
|
36
48
|
]);
|
|
37
|
-
export const
|
|
49
|
+
export const Node = z.strictObject({
|
|
38
50
|
id: IntelId,
|
|
39
51
|
parentId: IntelId.nullable(),
|
|
40
|
-
kind:
|
|
52
|
+
kind: NodeKind,
|
|
41
53
|
title: z.string().min(1).max(240),
|
|
42
54
|
description: z.string().max(2_000).nullable(),
|
|
43
55
|
ownerId: IntelId,
|
|
@@ -46,7 +58,14 @@ export const KnowledgeNode = z.strictObject({
|
|
|
46
58
|
updatedAt: IsoDateTime,
|
|
47
59
|
archivedAt: IsoDateTime.nullable(),
|
|
48
60
|
});
|
|
49
|
-
|
|
61
|
+
// What one table version carries (#135). An `append` holds only the rows one write added; a
|
|
62
|
+
// `snapshot` holds the complete table — header and every row — so reading starts at the newest
|
|
63
|
+
// snapshot and everything before it is history rather than content. Defining a table writes the
|
|
64
|
+
// first snapshot; updating, deleting, and redefining write the later ones. Documents and
|
|
65
|
+
// attachments carry `null`: each of their versions is complete by construction, and the word would
|
|
66
|
+
// say nothing about them.
|
|
67
|
+
export const NodeVersionSegment = z.enum(["append", "snapshot"]);
|
|
68
|
+
export const NodeVersion = z.strictObject({
|
|
50
69
|
id: IntelId,
|
|
51
70
|
nodeId: IntelId,
|
|
52
71
|
sequence: z.number().int().positive(),
|
|
@@ -54,10 +73,11 @@ export const KnowledgeVersion = z.strictObject({
|
|
|
54
73
|
mediaType: z.string().min(1).max(160),
|
|
55
74
|
contentHash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
56
75
|
size: z.number().int().nonnegative(),
|
|
76
|
+
segment: NodeVersionSegment.nullable(),
|
|
57
77
|
createdBy: IntelId,
|
|
58
78
|
createdAt: IsoDateTime,
|
|
59
79
|
});
|
|
60
|
-
export const
|
|
80
|
+
export const ListNodesInput = z.strictObject({
|
|
61
81
|
parentId: IntelId.nullable().default(null),
|
|
62
82
|
includeArchived: z.boolean().default(false),
|
|
63
83
|
// ⚠️ Overrides `parentId` rather than narrowing beside it: what is archived is asked for across
|
|
@@ -69,30 +89,33 @@ export const ListKnowledgeNodesInput = z.strictObject({
|
|
|
69
89
|
// caller would have to answer a question it is not asking.
|
|
70
90
|
archivedOnly: z.boolean().optional(),
|
|
71
91
|
});
|
|
72
|
-
export const
|
|
73
|
-
|
|
74
|
-
|
|
92
|
+
export const GetNodeInput = z.strictObject({ nodeId: IntelId });
|
|
93
|
+
// One pinned version of one node (#147). Both IDs, always: a version ID alone would let anyone
|
|
94
|
+
// holding an ID read content whose node-level ACL they never passed, and a citation names both.
|
|
95
|
+
export const GetNodeVersionInput = z.strictObject({ nodeId: IntelId, versionId: IntelId });
|
|
96
|
+
export const ListGrantsInput = z.strictObject({ resourceId: IntelId });
|
|
97
|
+
export const CreateNodeInput = z.strictObject({
|
|
75
98
|
parentId: IntelId.nullable().default(null),
|
|
76
|
-
kind:
|
|
99
|
+
kind: NodeKind,
|
|
77
100
|
title: z.string().trim().min(1).max(240),
|
|
78
101
|
description: z.string().trim().max(2_000).nullable().default(null),
|
|
79
102
|
idempotencyKey: z.string().min(8).max(200),
|
|
80
103
|
});
|
|
81
|
-
export const
|
|
104
|
+
export const SaveNodeVersionInput = z.strictObject({
|
|
82
105
|
nodeId: IntelId,
|
|
83
106
|
baseVersionId: IntelId.nullable(),
|
|
84
107
|
content: z.string().max(10_000_000),
|
|
85
108
|
mediaType: z.string().min(1).max(160).default("text/markdown"),
|
|
86
109
|
idempotencyKey: z.string().min(8).max(200),
|
|
87
110
|
});
|
|
88
|
-
export const
|
|
111
|
+
export const SaveAttachmentInput = z.strictObject({
|
|
89
112
|
nodeId: IntelId,
|
|
90
113
|
baseVersionId: IntelId.nullable(),
|
|
91
114
|
contentBase64: z.string().min(1).max(20_000_000),
|
|
92
115
|
mediaType: z.string().min(1).max(160),
|
|
93
116
|
idempotencyKey: z.string().min(8).max(200),
|
|
94
117
|
});
|
|
95
|
-
export const
|
|
118
|
+
export const UpdateNodeInput = z
|
|
96
119
|
.strictObject({
|
|
97
120
|
nodeId: IntelId,
|
|
98
121
|
baseUpdatedAt: IsoDateTime,
|
|
@@ -102,30 +125,30 @@ export const UpdateKnowledgeNodeInput = z
|
|
|
102
125
|
idempotencyKey: z.string().min(8).max(200),
|
|
103
126
|
})
|
|
104
127
|
.refine((input) => input.title !== undefined || input.description !== undefined || input.parentId !== undefined, { message: "At least one change is required" });
|
|
105
|
-
export const
|
|
128
|
+
export const ArchiveNodeInput = z.strictObject({
|
|
106
129
|
nodeId: IntelId,
|
|
107
130
|
baseUpdatedAt: IsoDateTime,
|
|
108
131
|
archived: z.boolean(),
|
|
109
132
|
idempotencyKey: z.string().min(8).max(200),
|
|
110
133
|
});
|
|
111
|
-
// ⚠️ `withChildren`
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
export const
|
|
116
|
-
items: z.array(
|
|
134
|
+
// ⚠️ `withChildren` belongs to the LEVEL, not to the node (#59). Whether something has children
|
|
135
|
+
// THIS reader may see is not a property of the thing — two readers get different answers. As a
|
|
136
|
+
// field on the node, every other place that returns a node would have to compute it as well or
|
|
137
|
+
// lie; as a list beside the entries it costs only the one answer that needs it.
|
|
138
|
+
export const NodeList = z.strictObject({
|
|
139
|
+
items: z.array(Node),
|
|
117
140
|
withChildren: z.array(IntelId).default([]),
|
|
118
141
|
});
|
|
119
|
-
export const
|
|
120
|
-
export const
|
|
121
|
-
node:
|
|
122
|
-
version:
|
|
142
|
+
export const NodeVersionList = z.strictObject({ items: z.array(NodeVersion) });
|
|
143
|
+
export const NodeDocument = z.strictObject({
|
|
144
|
+
node: Node,
|
|
145
|
+
version: NodeVersion.nullable(),
|
|
123
146
|
content: z.string().nullable(),
|
|
124
147
|
});
|
|
125
|
-
export const
|
|
126
|
-
node:
|
|
127
|
-
version:
|
|
128
|
-
resourceUri: z.string().regex(/^intel:\/\/
|
|
148
|
+
export const NodeAttachment = z.strictObject({
|
|
149
|
+
node: Node,
|
|
150
|
+
version: NodeVersion,
|
|
151
|
+
resourceUri: z.string().regex(/^intel:\/\/nodes\/[^/]+\/attachment$/),
|
|
129
152
|
});
|
|
130
153
|
// A table is CSV, and CSV is the whole format: it is what is stored, what is downloaded and what a
|
|
131
154
|
// machine reads. There is no second representation to keep in step with it (#40).
|
|
@@ -138,7 +161,7 @@ export const TableRow = z.array(TableCell).min(1).max(64);
|
|
|
138
161
|
// Writing the header, once. The columns are the contract (#40's comment), which is why this refuses
|
|
139
162
|
// on a table that already has one: changing the header would silently reinterpret every row that
|
|
140
163
|
// was appended under the old one.
|
|
141
|
-
export const
|
|
164
|
+
export const DefineTableInput = z.strictObject({
|
|
142
165
|
nodeId: IntelId,
|
|
143
166
|
columns: z
|
|
144
167
|
.array(TableColumn)
|
|
@@ -151,31 +174,233 @@ export const DefineKnowledgeTableInput = z.strictObject({
|
|
|
151
174
|
// to know which content it replaces; an append adds to the end and cannot collide with a second
|
|
152
175
|
// append, so demanding a base version would invent a conflict that does not exist and force the
|
|
153
176
|
// caller to read the whole table first — the exact cost #40 exists to remove.
|
|
154
|
-
export const
|
|
177
|
+
export const AppendTableRowsInput = z.strictObject({
|
|
155
178
|
nodeId: IntelId,
|
|
156
179
|
rows: z.array(TableRow).min(1).max(1_000),
|
|
157
180
|
idempotencyKey: z.string().min(8).max(200),
|
|
158
181
|
});
|
|
159
|
-
export const
|
|
182
|
+
export const GetTableInput = z.strictObject({ nodeId: IntelId });
|
|
160
183
|
// The table as a grid rather than as text: the server owns the one CSV reader, so no surface has to
|
|
161
184
|
// grow a second one that would disagree with it about quoting.
|
|
162
|
-
export const
|
|
163
|
-
node:
|
|
185
|
+
export const NodeTable = z.strictObject({
|
|
186
|
+
node: Node,
|
|
164
187
|
columns: z.array(z.string()),
|
|
165
188
|
rows: z.array(z.array(z.string())),
|
|
166
189
|
// The newest append, or `null` while the table has no header yet.
|
|
167
190
|
versionId: IntelId.nullable(),
|
|
168
191
|
});
|
|
169
|
-
export const
|
|
170
|
-
node:
|
|
171
|
-
version:
|
|
192
|
+
export const AppendTableRowsResult = z.strictObject({
|
|
193
|
+
node: Node,
|
|
194
|
+
version: NodeVersion,
|
|
172
195
|
appended: z.number().int().positive(),
|
|
173
196
|
});
|
|
197
|
+
// A row's address is its position among the table's current rows, counted from zero and without the
|
|
198
|
+
// header. Deliberately not an ID: rows carry no identity of their own (#135, and the same decision
|
|
199
|
+
// the grid documents), so every mutation instead pins the state its positions refer to.
|
|
200
|
+
export const TableRowPosition = z.number().int().nonnegative();
|
|
201
|
+
const distinctPositions = { error: "Row positions must be distinct" };
|
|
202
|
+
// Replacing rows in place (#135). `baseVersionId` is the version the caller read the positions
|
|
203
|
+
// from — required, never nullable, because a position into a table one has not read is a guess.
|
|
204
|
+
// A table that moved on since answers `version_conflict` rather than editing the wrong rows; that
|
|
205
|
+
// is the same optimistic concurrency the document save uses, and the deliberate opposite of
|
|
206
|
+
// `append`, which needs no base because it collides with nothing.
|
|
207
|
+
export const UpdateTableRowsInput = z.strictObject({
|
|
208
|
+
nodeId: IntelId,
|
|
209
|
+
baseVersionId: IntelId,
|
|
210
|
+
updates: z
|
|
211
|
+
.array(z.strictObject({ position: TableRowPosition, row: TableRow }))
|
|
212
|
+
.min(1)
|
|
213
|
+
.max(1_000)
|
|
214
|
+
.refine((updates) => new Set(updates.map((update) => update.position)).size === updates.length, distinctPositions),
|
|
215
|
+
idempotencyKey: z.string().min(8).max(200),
|
|
216
|
+
});
|
|
217
|
+
export const UpdateTableRowsResult = z.strictObject({
|
|
218
|
+
node: Node,
|
|
219
|
+
version: NodeVersion,
|
|
220
|
+
updated: z.number().int().positive(),
|
|
221
|
+
});
|
|
222
|
+
export const DeleteTableRowsInput = z.strictObject({
|
|
223
|
+
nodeId: IntelId,
|
|
224
|
+
baseVersionId: IntelId,
|
|
225
|
+
positions: z
|
|
226
|
+
.array(TableRowPosition)
|
|
227
|
+
.min(1)
|
|
228
|
+
.max(1_000)
|
|
229
|
+
.refine((positions) => new Set(positions).size === positions.length, distinctPositions),
|
|
230
|
+
idempotencyKey: z.string().min(8).max(200),
|
|
231
|
+
});
|
|
232
|
+
export const DeleteTableRowsResult = z.strictObject({
|
|
233
|
+
node: Node,
|
|
234
|
+
version: NodeVersion,
|
|
235
|
+
deleted: z.number().int().positive(),
|
|
236
|
+
});
|
|
237
|
+
// One entry per column the table will have afterwards, in order. `source` names the current column
|
|
238
|
+
// whose cells fill it; `null` adds an empty column, and a current column no entry names is removed
|
|
239
|
+
// together with its cells. Renaming is naming a source under a new name.
|
|
240
|
+
export const RedefineTableColumn = z.strictObject({
|
|
241
|
+
name: TableColumn,
|
|
242
|
+
source: TableColumn.nullable().default(null),
|
|
243
|
+
});
|
|
244
|
+
// Changing the header of a table that has one (#135). The mapping is explicit because it is the
|
|
245
|
+
// whole difference to the blind re-definition `defineTable` keeps refusing: without it a new header
|
|
246
|
+
// would silently reinterpret every stored row under names nobody matched to the old ones.
|
|
247
|
+
export const RedefineTableInput = z.strictObject({
|
|
248
|
+
nodeId: IntelId,
|
|
249
|
+
baseVersionId: IntelId,
|
|
250
|
+
columns: z
|
|
251
|
+
.array(RedefineTableColumn)
|
|
252
|
+
.min(1)
|
|
253
|
+
.max(64)
|
|
254
|
+
.refine((columns) => new Set(columns.map((column) => column.name.toLowerCase())).size === columns.length, { error: "Column names must be distinct" })
|
|
255
|
+
.refine((columns) => {
|
|
256
|
+
const sources = columns.map((column) => column.source).filter((source) => source !== null);
|
|
257
|
+
return new Set(sources).size === sources.length;
|
|
258
|
+
}, { error: "A current column can fill only one new column" }),
|
|
259
|
+
idempotencyKey: z.string().min(8).max(200),
|
|
260
|
+
});
|
|
261
|
+
// ── The agent definition (#139, ADR-0005 §4) ─────────────────────────────────────────────────────
|
|
262
|
+
//
|
|
263
|
+
// An agent's body is a definition, stored as an immutable version in R2 exactly like a document's.
|
|
264
|
+
// Its own media type exists so a reader can tell a definition from prose without parsing it.
|
|
265
|
+
export const AgentMediaType = "application/vnd.anchrd.agent+json";
|
|
266
|
+
// ⚠️ The role lives on the AGENT, never on the node it names, and that is the whole difference to
|
|
267
|
+
// the removed `context_policy` (ADR-0005 §2, #76). The same folder can be the system message for
|
|
268
|
+
// one agent and nothing but search space for another; a node has no opinion about how it is used.
|
|
269
|
+
// Any future field on a node saying how it should be loaded is `context_policy` under a new name.
|
|
270
|
+
//
|
|
271
|
+
// system-message prepended verbatim by the runtime
|
|
272
|
+
// semantic-context search space; the agent searches it when it decides to
|
|
273
|
+
// memory write target — ordinary Knowledge, versioned and readable like everything else
|
|
274
|
+
export const AgentReferenceRole = z.enum(["system-message", "semantic-context", "memory"]);
|
|
275
|
+
export const AgentReference = z.strictObject({ nodeId: IntelId, role: AgentReferenceRole });
|
|
276
|
+
// A `document` target means the content of that document is the instruction — a "skill" somebody
|
|
277
|
+
// wrote as ordinary text; a `flow` target means a run is started through Intel MCP and worked step
|
|
278
|
+
// by step. Both are references, so nothing in here goes stale (ADR-0005 §4).
|
|
279
|
+
//
|
|
280
|
+
// ⚠️ Intel stores a schedule as a declared fact and never fires it. The alarm lives in the runtime
|
|
281
|
+
// (ADR-0005 §3); Intel gains no scheduler, which is D24 confirmed rather than bent.
|
|
282
|
+
export const AgentScheduleTarget = z.strictObject({
|
|
283
|
+
kind: z.enum(["document", "flow"]),
|
|
284
|
+
id: IntelId,
|
|
285
|
+
});
|
|
286
|
+
export const AgentSchedule = z.strictObject({
|
|
287
|
+
cron: z.string().trim().min(1).max(120),
|
|
288
|
+
target: AgentScheduleTarget,
|
|
289
|
+
});
|
|
290
|
+
export const AgentModel = z.strictObject({
|
|
291
|
+
provider: z.enum(["workers-ai", "anthropic"]),
|
|
292
|
+
model: z.string().trim().min(1).max(120),
|
|
293
|
+
});
|
|
294
|
+
/**
|
|
295
|
+
* ⚠️ No accounts, no secrets, no channels, and no tools — and the reason is mechanical rather than
|
|
296
|
+
* tidy (ADR-0005 §4): this body is read, shared, exported and put into model context, so a secret
|
|
297
|
+
* in it is a secret in a citation. Identity is Gate's, accounts are the portal's, channels are
|
|
298
|
+
* runtime configuration, and the tool catalog is a live `tools/list` that is never mirrored.
|
|
299
|
+
*
|
|
300
|
+
* ⚠️ Strict on purpose, and deliberately stricter than the runtime's own reader
|
|
301
|
+
* (`packages/agent/src/definition/definition.ts`, which is `z.object`). Intel is the writer: an
|
|
302
|
+
* unknown field here is a caller's mistake and is refused at the boundary. The runtime is the
|
|
303
|
+
* reader and released separately, so it must keep starting agents when Intel adds a field
|
|
304
|
+
* tomorrow. The asymmetry is the point, not an oversight.
|
|
305
|
+
*/
|
|
306
|
+
export const AgentDefinition = z.strictObject({
|
|
307
|
+
references: z.array(AgentReference).max(200).default([]),
|
|
308
|
+
schedules: z.array(AgentSchedule).max(50).default([]),
|
|
309
|
+
model: AgentModel,
|
|
310
|
+
});
|
|
311
|
+
export const SaveAgentDefinitionInput = z.strictObject({
|
|
312
|
+
nodeId: IntelId,
|
|
313
|
+
baseVersionId: IntelId.nullable(),
|
|
314
|
+
definition: AgentDefinition,
|
|
315
|
+
idempotencyKey: z.string().min(8).max(200),
|
|
316
|
+
});
|
|
317
|
+
export const GetAgentInput = z.strictObject({ nodeId: IntelId });
|
|
318
|
+
// Switching an agent off and on again, and starting one run by hand. All three name only the agent
|
|
319
|
+
// and — for a run — which of the targets it already schedules.
|
|
320
|
+
//
|
|
321
|
+
// ⚠️ Intel holds none of this. Whether an agent is paused is state of its Durable Object, not a
|
|
322
|
+
// field of the definition: a definition is versioned, shared and read into model context (ADR-0005
|
|
323
|
+
// §4), so every pause would otherwise be a new version and would tell the agent it is switched off.
|
|
324
|
+
// These inputs are what Intel accepts and passes on, nothing that Intel stores.
|
|
325
|
+
export const PauseAgentInput = z.strictObject({ nodeId: IntelId });
|
|
326
|
+
export const RunAgentNowInput = z.strictObject({
|
|
327
|
+
nodeId: IntelId,
|
|
328
|
+
target: AgentScheduleTarget,
|
|
329
|
+
});
|
|
330
|
+
// ⚠️ Three states, not two, and the same three the flow list makes: omitted is the whole tree,
|
|
331
|
+
// `null` is the root level, an ID is that folder. "Which agents may I use" is a question about the
|
|
332
|
+
// tree rather than about one folder, so the useful answer has to be reachable without knowing where
|
|
333
|
+
// somebody filed them.
|
|
334
|
+
export const ListAgentsInput = z.strictObject({
|
|
335
|
+
parentId: IntelId.nullable().optional(),
|
|
336
|
+
includeArchived: z.boolean().default(false),
|
|
337
|
+
});
|
|
338
|
+
export const CreateAgentInput = z.strictObject({
|
|
339
|
+
parentId: IntelId.nullable().default(null),
|
|
340
|
+
title: z.string().trim().min(1).max(240),
|
|
341
|
+
description: z.string().trim().max(2_000).nullable().default(null),
|
|
342
|
+
definition: AgentDefinition,
|
|
343
|
+
idempotencyKey: z.string().min(8).max(200),
|
|
344
|
+
});
|
|
345
|
+
// The ID of the Gate Application an agent runs as. Deliberately NOT an `IntelId`: it is Better
|
|
346
|
+
// Auth's user ID, minted in Gate and only ever handed back to Gate, so validating it against
|
|
347
|
+
// Intel's own ID shape would be Intel inventing a rule about somebody else's identifier.
|
|
348
|
+
export const GateApplicationId = z.string().min(1).max(255);
|
|
349
|
+
// The definition is `null` exactly while the node exists and no version has been written yet — the
|
|
350
|
+
// same window in which a document's content is `null`.
|
|
351
|
+
//
|
|
352
|
+
// ⚠️ `applicationId` names the machine principal, it does not authenticate it (#182, D27). That is
|
|
353
|
+
// why the ID may be stored, listed and drawn while the key may not: one is a name, the other is the
|
|
354
|
+
// credential, and Gate hands the credential out exactly once and keeps only its hash. `null` means
|
|
355
|
+
// this agent has no Application — an agent node written before #182, restored from a bundle, or
|
|
356
|
+
// imported from another installation. Such an agent is not switched with its node, and giving it a
|
|
357
|
+
// principal is an operator's act in Gate.
|
|
358
|
+
export const NodeAgent = z.strictObject({
|
|
359
|
+
node: Node,
|
|
360
|
+
version: NodeVersion.nullable(),
|
|
361
|
+
definition: AgentDefinition.nullable(),
|
|
362
|
+
applicationId: GateApplicationId.nullable(),
|
|
363
|
+
});
|
|
364
|
+
/**
|
|
365
|
+
* The single value in Intel's wire formats that IS a credential (#182, D27).
|
|
366
|
+
*
|
|
367
|
+
* ⚠️ It exists for exactly one response — the one that created the agent — and for no other. Gate
|
|
368
|
+
* returns an Application key once in plain text and stores only its hash, so this is not a value
|
|
369
|
+
* Intel could fetch again later even if it wanted to; nothing in Intel writes it to D1, to R2, to
|
|
370
|
+
* an audit event or to a log, and no read surface has a field it could travel in. What the caller
|
|
371
|
+
* does with it is named in `notice` rather than left to them: it belongs in the agent runtime's
|
|
372
|
+
* `AGENT_APPLICATION_KEYS` secret, keyed by `agentId`, and nowhere else.
|
|
373
|
+
*
|
|
374
|
+
* ⚠️ `agentId` is the Intel node ID and not the Application ID, because that is the key the runtime
|
|
375
|
+
* looks an entry up by. Writing the Application ID into the runtime's map would produce a
|
|
376
|
+
* deployment that parses, starts, and then cannot find a single agent.
|
|
377
|
+
*/
|
|
378
|
+
export const AgentApplicationKey = z.strictObject({
|
|
379
|
+
agentId: IntelId,
|
|
380
|
+
applicationId: GateApplicationId,
|
|
381
|
+
key: z.string().min(1),
|
|
382
|
+
notice: z.string().min(1),
|
|
383
|
+
});
|
|
384
|
+
/**
|
|
385
|
+
* What `POST /nodes/agents` and `agent_create` answer, and the only shape carrying a key. Every
|
|
386
|
+
* other agent read answers with the plain `NodeAgent` above.
|
|
387
|
+
*
|
|
388
|
+
* ⚠️ `applicationKey` is `null` on a REPLAY, and that is the honest answer rather than a gap. An
|
|
389
|
+
* idempotency key repeated after the first response was lost still returns the agent that exists —
|
|
390
|
+
* the promise every create in Intel makes — but the key belonged to the one response that created
|
|
391
|
+
* it and is gone from Gate. Minting a second principal to fill this field would leave the
|
|
392
|
+
* installation with two machine accounts for one agent, one of which nobody would ever switch off.
|
|
393
|
+
* `application_rotate_key` in Gate is the way to a new key, and it is a deliberate act.
|
|
394
|
+
*/
|
|
395
|
+
export const CreatedAgent = NodeAgent.extend({
|
|
396
|
+
applicationKey: AgentApplicationKey.nullable(),
|
|
397
|
+
});
|
|
398
|
+
export const AgentList = z.strictObject({ items: z.array(Node) });
|
|
174
399
|
// ⚠️ Kept for what is already stored, not for what is written. Relations were picked in a dialog
|
|
175
400
|
// until #41; a link is now made where it is meant — in the text — and every link written from now
|
|
176
401
|
// on is a `references`. Rewriting the old rows would destroy a distinction somebody chose on
|
|
177
402
|
// purpose, and dropping the column would destroy it with them, so both stay readable.
|
|
178
|
-
export const
|
|
403
|
+
export const NodeLinkRelation = z.enum(["references", "related", "depends_on", "implements"]);
|
|
179
404
|
// Where the link came from. `text` links are derived from a document's content and are rewritten
|
|
180
405
|
// whenever it is saved; `manual` links were made in the dialog #41 removed and are now history.
|
|
181
406
|
//
|
|
@@ -183,28 +408,28 @@ export const KnowledgeLinkRelation = z.enum(["references", "related", "depends_o
|
|
|
183
408
|
// between them, and nothing may start writing `manual` again — that would be the two ways of saying
|
|
184
409
|
// one thing that #41 exists to end. It exists so that saving a document cannot delete a link
|
|
185
410
|
// somebody made before there was another way to make one.
|
|
186
|
-
export const
|
|
187
|
-
export const
|
|
411
|
+
export const NodeLinkOrigin = z.enum(["text", "manual"]);
|
|
412
|
+
export const NodeLink = z.strictObject({
|
|
188
413
|
id: IntelId,
|
|
189
414
|
sourceNodeId: IntelId,
|
|
190
415
|
targetNodeId: IntelId,
|
|
191
|
-
relation:
|
|
192
|
-
origin:
|
|
416
|
+
relation: NodeLinkRelation,
|
|
417
|
+
origin: NodeLinkOrigin,
|
|
193
418
|
label: z.string().trim().min(1).max(120).nullable(),
|
|
194
419
|
createdBy: IntelId,
|
|
195
420
|
createdAt: IsoDateTime,
|
|
196
421
|
});
|
|
197
|
-
export const
|
|
422
|
+
export const NodeLinkList = z.strictObject({ items: z.array(NodeLink) });
|
|
198
423
|
// The inline element a document link is, inside a BlockNote document (#41).
|
|
199
424
|
//
|
|
200
425
|
// ⚠️ The ID and nothing else. No title and no path travel with it: a stored title would go stale
|
|
201
426
|
// the moment the target is renamed, a stored path the moment it is moved — and either one would
|
|
202
427
|
// put a name the reader may not see into a document they may.
|
|
203
428
|
export const DocumentLinkInlineType = "documentLink";
|
|
204
|
-
export const
|
|
429
|
+
export const ResolveNodeLinksInput = z.strictObject({
|
|
205
430
|
nodeIds: z.array(IntelId).min(1).max(200),
|
|
206
431
|
});
|
|
207
|
-
export const
|
|
432
|
+
export const ResolvedNodeLink = z.strictObject({
|
|
208
433
|
nodeId: IntelId,
|
|
209
434
|
title: z.string().min(1).max(240),
|
|
210
435
|
});
|
|
@@ -213,15 +438,15 @@ export const ResolvedKnowledgeLink = z.strictObject({
|
|
|
213
438
|
// side of a document link is drawn from, and an entry that says "something is here" is exactly the
|
|
214
439
|
// leak this schema has to make impossible to write by accident. Deleted and unreadable therefore
|
|
215
440
|
// look identical from the outside, which is the point.
|
|
216
|
-
export const
|
|
217
|
-
items: z.array(
|
|
441
|
+
export const ResolveNodeLinksResult = z.strictObject({
|
|
442
|
+
items: z.array(ResolvedNodeLink),
|
|
218
443
|
});
|
|
219
|
-
export const
|
|
444
|
+
export const NodeGraphInput = z.strictObject({
|
|
220
445
|
limit: z.number().int().min(1).max(500).default(250),
|
|
221
446
|
});
|
|
222
|
-
export const
|
|
223
|
-
nodes: z.array(
|
|
224
|
-
links: z.array(
|
|
447
|
+
export const NodeGraph = z.strictObject({
|
|
448
|
+
nodes: z.array(Node),
|
|
449
|
+
links: z.array(NodeLink),
|
|
225
450
|
});
|
|
226
451
|
export const BlockNoteMediaType = "application/vnd.anchrd.intel.blocknote+json";
|
|
227
452
|
export const BlockNoteDocument = z.strictObject({
|
|
@@ -239,14 +464,14 @@ export const ResourceGrant = z.strictObject({
|
|
|
239
464
|
createdBy: IntelId,
|
|
240
465
|
createdAt: IsoDateTime,
|
|
241
466
|
});
|
|
242
|
-
export const
|
|
467
|
+
export const ShareInput = z.strictObject({
|
|
243
468
|
resourceId: IntelId,
|
|
244
469
|
principal: SharePrincipal,
|
|
245
470
|
verb: ResourceVerb,
|
|
246
471
|
expiresAt: IsoDateTime.nullable().default(null),
|
|
247
472
|
idempotencyKey: z.string().min(8).max(200),
|
|
248
473
|
});
|
|
249
|
-
export const
|
|
474
|
+
export const RevokeGrantInput = z.strictObject({
|
|
250
475
|
resourceId: IntelId,
|
|
251
476
|
grantId: IntelId,
|
|
252
477
|
idempotencyKey: z.string().min(8).max(200),
|
|
@@ -257,16 +482,16 @@ export const RevokeKnowledgeGrantInput = z.strictObject({
|
|
|
257
482
|
//
|
|
258
483
|
// ⚠️ `titles` holds only the documents the sharer may see; everything else is in `hidden` as a
|
|
259
484
|
// number. A warning must not become a way of reading titles out of the tree.
|
|
260
|
-
export const
|
|
485
|
+
export const UnreadableNodes = z.strictObject({
|
|
261
486
|
titles: z.array(z.string().min(1).max(240)),
|
|
262
487
|
hidden: z.number().int().nonnegative(),
|
|
263
488
|
});
|
|
264
489
|
// The grant is in the answer, so the warning cannot be mistaken for a refusal: it is written first
|
|
265
490
|
// and described afterwards. Blocking would force everyone who uses a central policy document to
|
|
266
491
|
// duplicate it, which is the opposite of what one tree is for (ADR-0004 §4).
|
|
267
|
-
export const
|
|
492
|
+
export const ShareResult = z.strictObject({
|
|
268
493
|
grant: ResourceGrant,
|
|
269
|
-
unreadable:
|
|
494
|
+
unreadable: UnreadableNodes,
|
|
270
495
|
});
|
|
271
496
|
// `applicableVerbs` travels with the list because the answer is the business layer's, not the
|
|
272
497
|
// screen's: a document has nothing to execute, so `execute` is not offered on one (ADR-0004 §2).
|
|
@@ -275,11 +500,16 @@ export const ResourceGrantList = z.strictObject({
|
|
|
275
500
|
applicableVerbs: z.array(ResourceVerb).min(1),
|
|
276
501
|
items: z.array(ResourceGrant),
|
|
277
502
|
});
|
|
278
|
-
|
|
503
|
+
// `scopeId` is a cut, never a grant (#126): it narrows an answer the actor is already entitled to
|
|
504
|
+
// and can only ever remove rows. Without it the search stays global over everything visible, which
|
|
505
|
+
// is why it is optional rather than nullable — an absent field and `null` would otherwise be two
|
|
506
|
+
// spellings of the same request.
|
|
507
|
+
export const SearchInput = z.strictObject({
|
|
279
508
|
query: z.string().trim().min(1).max(500),
|
|
280
509
|
limit: z.number().int().min(1).max(50).default(10),
|
|
510
|
+
scopeId: IntelId.optional().describe("Optional folder node id. When given, only nodes filed in that folder or beneath it are searched."),
|
|
281
511
|
});
|
|
282
|
-
export const
|
|
512
|
+
export const NodeCitation = z.strictObject({
|
|
283
513
|
nodeId: IntelId,
|
|
284
514
|
versionId: IntelId,
|
|
285
515
|
title: z.string(),
|
|
@@ -289,10 +519,10 @@ export const KnowledgeCitation = z.strictObject({
|
|
|
289
519
|
score: z.number().min(0).max(1),
|
|
290
520
|
match: z.enum(["lexical", "semantic", "hybrid"]),
|
|
291
521
|
});
|
|
292
|
-
export const
|
|
293
|
-
items: z.array(
|
|
522
|
+
export const SearchResult = z.strictObject({
|
|
523
|
+
items: z.array(NodeCitation),
|
|
294
524
|
});
|
|
295
|
-
export const
|
|
525
|
+
export const ReindexResult = z.strictObject({ queued: z.number().int().nonnegative() });
|
|
296
526
|
export const RevokeGrantResult = z.strictObject({ revoked: z.boolean() });
|
|
297
527
|
function isPrivateIpv4(hostname) {
|
|
298
528
|
const parts = hostname.split(".").map(Number);
|
|
@@ -526,7 +756,7 @@ export const FlowGraph = z.strictObject({
|
|
|
526
756
|
});
|
|
527
757
|
export const Flow = z.strictObject({
|
|
528
758
|
id: IntelId,
|
|
529
|
-
// The one thing a Flow shares with a document: its place in the
|
|
759
|
+
// The one thing a Flow shares with a document: its place in the shared folder tree (ADR-0004).
|
|
530
760
|
// Everything else stays apart — versions, R2 body and Vectorize belong to the document, the graph,
|
|
531
761
|
// runs and approvals to the flow. `null` is the root of that same tree.
|
|
532
762
|
parentId: IntelId.nullable(),
|
|
@@ -551,30 +781,52 @@ export const FlowDocument = z.strictObject({
|
|
|
551
781
|
flow: Flow,
|
|
552
782
|
version: FlowVersion.nullable(),
|
|
553
783
|
});
|
|
554
|
-
//
|
|
555
|
-
//
|
|
556
|
-
//
|
|
784
|
+
// One version as the history shows it: the metadata without the graph it carries. A flow's history
|
|
785
|
+
// is as long as its edits, and a list that shipped every graph would pay for drawings nobody asked
|
|
786
|
+
// for — whoever needs one asks for that one version.
|
|
787
|
+
export const FlowVersionSummary = z.strictObject({
|
|
788
|
+
id: IntelId,
|
|
789
|
+
flowId: IntelId,
|
|
790
|
+
sequence: z.number().int().positive(),
|
|
791
|
+
createdBy: IntelId,
|
|
792
|
+
createdAt: IsoDateTime,
|
|
793
|
+
// Whether this is the version the flow currently publishes. Derived from the flow row when the
|
|
794
|
+
// list is read, never stored on the version: a version is immutable and "published" is not a
|
|
795
|
+
// property of it — it is the flow's choice, revocable without touching the version.
|
|
796
|
+
published: z.boolean(),
|
|
797
|
+
});
|
|
798
|
+
export const FlowVersionList = z.strictObject({
|
|
799
|
+
flowId: IntelId,
|
|
800
|
+
items: z.array(FlowVersionSummary),
|
|
801
|
+
});
|
|
802
|
+
// Both identifiers, deliberately: a version ID alone would resolve whatever version carries it,
|
|
803
|
+
// whichever flow it belongs to, and the ACL is answered on the flow. The pair makes a foreign
|
|
804
|
+
// version a 404 rather than a read.
|
|
805
|
+
export const GetFlowVersionInput = z.strictObject({ flowId: IntelId, versionId: IntelId });
|
|
806
|
+
// The same for flows: which of them call another flow that this reader may also see (#59). An
|
|
807
|
+
// expand arrow on a flow whose calls are all hidden promises content that expanding it cannot
|
|
808
|
+
// deliver.
|
|
557
809
|
export const FlowList = z.strictObject({
|
|
558
810
|
items: z.array(Flow),
|
|
559
811
|
withCalls: z.array(IntelId).default([]),
|
|
560
812
|
});
|
|
561
|
-
export const
|
|
813
|
+
export const ReferencedNode = z.strictObject({
|
|
562
814
|
id: IntelId,
|
|
563
815
|
title: z.string().min(1).max(240),
|
|
564
816
|
});
|
|
565
|
-
// What a flow touches: the documents its
|
|
817
|
+
// What a flow touches: the documents its tree links name and the tools its Tool steps call,
|
|
566
818
|
// read straight out of the graph. Deliberately not a conflict report — there is no arithmetic here
|
|
567
819
|
// and nothing that can go stale, because the graph is the answer. Whether a given person may reach
|
|
568
820
|
// any of it is decided where it can be decided honestly: when the folder is shared, and at runtime
|
|
569
821
|
// (ADR-0004 §4). For tools it can only ever be the latter, because the catalog is a live query with
|
|
570
822
|
// the requesting user's own token (ADR-0003).
|
|
571
823
|
//
|
|
572
|
-
// ⚠️ `
|
|
824
|
+
// ⚠️ `nodes` names only what the asking user may see. The rest is `hiddenNodes`, a count.
|
|
573
825
|
export const FlowRequirements = z.strictObject({
|
|
574
826
|
flowId: IntelId,
|
|
575
827
|
versionId: IntelId.nullable(),
|
|
576
|
-
|
|
577
|
-
|
|
828
|
+
nodes: z.array(ReferencedNode),
|
|
829
|
+
hiddenNodes: z.number().int().nonnegative(),
|
|
578
830
|
tools: z.array(ToolName),
|
|
579
831
|
});
|
|
580
832
|
// What stands between this flow and a run, asked on demand and answered for the person asking.
|
|
@@ -630,12 +882,12 @@ export const ListFlowsInput = z.strictObject({
|
|
|
630
882
|
// behind the relation graph has no such flag on purpose (#30). A drawing that includes what was
|
|
631
883
|
// archived says the tidying up never happened.
|
|
632
884
|
//
|
|
633
|
-
// ⚠️ `.optional()` rather than `.default(false)`, unlike `
|
|
885
|
+
// ⚠️ `.optional()` rather than `.default(false)`, unlike `ListNodesInput`. This schema is
|
|
634
886
|
// the argument type of `listFlows` on three layers, and a default makes the field required in the
|
|
635
887
|
// *parsed* type — every existing caller that lists a folder would have to spell out the answer to
|
|
636
888
|
// a question it is not asking. Absent means "without the archive" everywhere it is read.
|
|
637
889
|
includeArchived: z.boolean().optional(),
|
|
638
|
-
// The same question for flows, and the same override of `parentId` — see `
|
|
890
|
+
// The same question for flows, and the same override of `parentId` — see `ListNodesInput`.
|
|
639
891
|
archivedOnly: z.boolean().optional(),
|
|
640
892
|
});
|
|
641
893
|
export const GetFlowInput = z.strictObject({ flowId: IntelId });
|
|
@@ -650,6 +902,13 @@ export const PublishFlowInput = z.strictObject({
|
|
|
650
902
|
versionId: IntelId,
|
|
651
903
|
idempotencyKey: z.string().min(8).max(200),
|
|
652
904
|
});
|
|
905
|
+
// The way back out of a publication (#146). No versionId: what is withdrawn is whatever is
|
|
906
|
+
// published now, and naming one would invite a race between reading it and revoking it. Versions
|
|
907
|
+
// are untouched — republishing any of them is one `publish` away.
|
|
908
|
+
export const UnpublishFlowInput = z.strictObject({
|
|
909
|
+
flowId: IntelId,
|
|
910
|
+
idempotencyKey: z.string().min(8).max(200),
|
|
911
|
+
});
|
|
653
912
|
export const PreviewFlowPublishInput = z.strictObject({ flowId: IntelId, versionId: IntelId });
|
|
654
913
|
// One sub-flow call as publishing will leave it (ADR-0004 §5). `freezes` is the whole point of the
|
|
655
914
|
// preview: it marks the calls whose `latest` publishing turns into `versionId`, so the author reads
|
|
@@ -682,7 +941,14 @@ export const FlowPublishPreview = z.strictObject({
|
|
|
682
941
|
// What accesses what, for one level of the shared tree (#19). A folder answers it for its contents,
|
|
683
942
|
// a single flow for itself. Documents and flows are two kinds of thing that share one tree
|
|
684
943
|
// (ADR-0004 §1), so the graph carries both and says which of them it is.
|
|
685
|
-
export const RelationNodeKind = z.enum([
|
|
944
|
+
export const RelationNodeKind = z.enum([
|
|
945
|
+
"folder",
|
|
946
|
+
"document",
|
|
947
|
+
"attachment",
|
|
948
|
+
"table",
|
|
949
|
+
"agent",
|
|
950
|
+
"flow",
|
|
951
|
+
]);
|
|
686
952
|
export const RelationNode = z.strictObject({
|
|
687
953
|
id: IntelId,
|
|
688
954
|
kind: RelationNodeKind,
|
|
@@ -767,6 +1033,13 @@ export const StartFlowRunInput = z.strictObject({
|
|
|
767
1033
|
idempotencyKey: z.string().min(8).max(200),
|
|
768
1034
|
});
|
|
769
1035
|
export const GetFlowRunInput = z.strictObject({ runId: IntelId });
|
|
1036
|
+
// Ending a run on purpose (#145). Until this existed the only way off a parked manual step was
|
|
1037
|
+
// `completeStep` with `outcome: "failed"` — which recorded a step failure that never happened.
|
|
1038
|
+
// Cancelling records nothing into the step history: the run ends, the history stays true.
|
|
1039
|
+
export const CancelFlowRunInput = z.strictObject({
|
|
1040
|
+
runId: IntelId,
|
|
1041
|
+
idempotencyKey: z.string().min(8).max(200),
|
|
1042
|
+
});
|
|
770
1043
|
export const CompleteFlowRunStepInput = z.strictObject({
|
|
771
1044
|
runId: IntelId,
|
|
772
1045
|
nodeId: FlowNodeId,
|
|
@@ -801,7 +1074,7 @@ export const FlowRunFailure = z.strictObject({
|
|
|
801
1074
|
});
|
|
802
1075
|
// One run as a list shows it: what it did, never what it produced.
|
|
803
1076
|
//
|
|
804
|
-
// ⚠️ Neither `input` nor `output` is in here, on purpose. A run reaches its
|
|
1077
|
+
// ⚠️ Neither `input` nor `output` is in here, on purpose. A run reaches its nodes and its tools
|
|
805
1078
|
// with the rights of whoever started it, so its result is a way to content the next reader of this
|
|
806
1079
|
// list may have no claim to. Whoever wants a result asks for the run itself, where the same rule
|
|
807
1080
|
// decides again.
|
|
@@ -854,3 +1127,51 @@ export const FlowRunHistory = z.strictObject({
|
|
|
854
1127
|
steps: z.array(FlowRunStepRecord),
|
|
855
1128
|
trail: z.array(FlowRunTrailEntry),
|
|
856
1129
|
});
|
|
1130
|
+
// ── Bundle export (#136) ────────────────────────────────────────────────────────────────────────
|
|
1131
|
+
// The one name the importer looks for at the zip root. A different spelling would make a bundle a
|
|
1132
|
+
// naked folder, so the constant lives in the contract rather than in each surface.
|
|
1133
|
+
export const BundleManifestFilename = "manifest.json";
|
|
1134
|
+
// What a bundle entry can be. `flow` joins the five node kinds because a flow shares the folder
|
|
1135
|
+
// tree without being a node (ADR-0004), and the bundle mirrors the tree, not the tables.
|
|
1136
|
+
export const BundleEntryKind = z.enum([
|
|
1137
|
+
"folder",
|
|
1138
|
+
"document",
|
|
1139
|
+
"table",
|
|
1140
|
+
"attachment",
|
|
1141
|
+
"agent",
|
|
1142
|
+
"flow",
|
|
1143
|
+
]);
|
|
1144
|
+
// One entry of the manifest: the identity a re-import needs, next to the relative path where the
|
|
1145
|
+
// bytes sit in the zip. A folder carries no media type — it has no bytes.
|
|
1146
|
+
export const BundleManifestEntry = z.strictObject({
|
|
1147
|
+
id: IntelId,
|
|
1148
|
+
kind: BundleEntryKind,
|
|
1149
|
+
title: z.string().min(1).max(240),
|
|
1150
|
+
description: z.string().max(2_000).nullable(),
|
|
1151
|
+
mediaType: z.string().min(1).max(160).nullable(),
|
|
1152
|
+
// Relative to the zip root, forward slashes, no leading slash. Folders end with a slash so an
|
|
1153
|
+
// empty folder still has an address.
|
|
1154
|
+
path: z.string().min(1).max(4_000),
|
|
1155
|
+
});
|
|
1156
|
+
// What an export leaves out on purpose, named so a bundle says it rather than a reader guessing:
|
|
1157
|
+
// version history, grants/shares, flow runs, and archived nodes are not in any bundle (#136).
|
|
1158
|
+
export const BundleExclusion = z.enum(["version-history", "grants", "flow-runs", "archived-nodes"]);
|
|
1159
|
+
export const BundleManifest = z.strictObject({
|
|
1160
|
+
version: z.literal(1),
|
|
1161
|
+
exportedAt: IsoDateTime,
|
|
1162
|
+
// The node the export started at; `null` is the root of the tree — the whole installation as the
|
|
1163
|
+
// exporting caller may read it.
|
|
1164
|
+
rootId: IntelId.nullable(),
|
|
1165
|
+
entries: z.array(BundleManifestEntry),
|
|
1166
|
+
excluded: z.array(BundleExclusion),
|
|
1167
|
+
});
|
|
1168
|
+
// ── Bundle import (#137) ────────────────────────────────────────────────────────────────────────
|
|
1169
|
+
// What one import made. Import always creates new nodes — no merge, no overwrite, no restored IDs
|
|
1170
|
+
// (#137, phase 1) — so the answer is counts and the new roots, never a diff. `replayed` marks the
|
|
1171
|
+
// idempotent second answer to the same key: nothing was created twice.
|
|
1172
|
+
export const BundleImportResult = z.strictObject({
|
|
1173
|
+
nodes: z.number().int().nonnegative(),
|
|
1174
|
+
flows: z.number().int().nonnegative(),
|
|
1175
|
+
rootNodeIds: z.array(IntelId),
|
|
1176
|
+
replayed: z.boolean(),
|
|
1177
|
+
});
|