@anchrd/intel-contract 0.12.0 → 0.14.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/dist/contract/bundle.d.ts +85 -0
- package/dist/contract/bundle.js +63 -0
- package/dist/contract/contract.d.ts +3 -3372
- package/dist/contract/contract.js +24 -1797
- package/dist/contract/flow-run.d.ts +346 -0
- package/dist/contract/flow-run.js +181 -0
- package/dist/contract/flow.d.ts +995 -0
- package/dist/contract/flow.js +417 -0
- package/dist/contract/node.d.ts +402 -0
- package/dist/contract/node.js +286 -0
- package/dist/contract/share.d.ts +142 -0
- package/dist/contract/share.js +67 -0
- package/dist/contract/table.d.ts +162 -0
- package/dist/contract/table.js +117 -0
- package/dist/contract/tool.d.ts +122 -0
- package/dist/contract/tool.js +172 -0
- package/package.json +29 -1
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { IdempotencyKey, IntelId, IsoDateTime, LinkConfiguration } from "./contract.js";
|
|
3
|
+
import { ToolName } from "./tool.js";
|
|
4
|
+
export const FlowNodeId = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$/);
|
|
5
|
+
export const FlowPosition = z.strictObject({ x: z.number().finite(), y: z.number().finite() });
|
|
6
|
+
// A node has a title and nothing else to write in prose (#39). A second free text beside it was
|
|
7
|
+
// kept half up to date on both sides, and for an instruction the same sentence already belongs in
|
|
8
|
+
// the instruction itself.
|
|
9
|
+
const FlowNodeBase = {
|
|
10
|
+
id: FlowNodeId,
|
|
11
|
+
position: FlowPosition,
|
|
12
|
+
label: z.string().trim().min(1).max(160),
|
|
13
|
+
};
|
|
14
|
+
// Which version of the callee a sub-flow call takes (ADR-0004 §5). Three states rather than an
|
|
15
|
+
// optional identifier, because the difference between them is a decision and has to be readable:
|
|
16
|
+
//
|
|
17
|
+
// - `latest` the draft default. Nobody should have to version things while building, and
|
|
18
|
+
// publishing turns this into `pinned` — visibly, before the author publishes.
|
|
19
|
+
// - `follows` "always latest", chosen on purpose. The call rides along with the callee, so a
|
|
20
|
+
// change to the building block changes this flow too. Publishing leaves it alone.
|
|
21
|
+
// - `pinned` one immutable version, whatever is published elsewhere.
|
|
22
|
+
//
|
|
23
|
+
// ⚠️ Without the freeze a change to a building block would silently change the behavior of every
|
|
24
|
+
// published flow using it, which contradicts the immutable versions and pinned schema fingerprints
|
|
25
|
+
// Intel otherwise guarantees. That is why `latest` cannot survive publishing.
|
|
26
|
+
export const SubflowVersionMode = z.enum(["latest", "follows", "pinned"]);
|
|
27
|
+
export const SubflowVersion = z.discriminatedUnion("mode", [
|
|
28
|
+
z.strictObject({ mode: z.literal("latest") }),
|
|
29
|
+
z.strictObject({ mode: z.literal("follows") }),
|
|
30
|
+
z.strictObject({ mode: z.literal("pinned"), versionId: IntelId }),
|
|
31
|
+
]);
|
|
32
|
+
// The three layers a node can belong to (D25). Which one a kind is in decides what it may carry and
|
|
33
|
+
// where it may sit, and both rules are enforced in `compileFlow` rather than only drawn in the
|
|
34
|
+
// editor — a graph arrives over MCP as readily as from the canvas.
|
|
35
|
+
//
|
|
36
|
+
// ⚠️ A LINK never stands in the chain. It hangs off a step on a `context` edge, and that is the
|
|
37
|
+
// distinction the graph has drawn since #37 without anyone enforcing it — which is exactly how a
|
|
38
|
+
// start with an attachment once began its run at the attachment (the "flow edges only" comments in
|
|
39
|
+
// `flows.ts`). Marker and step keep the chain; a link is what a step works with.
|
|
40
|
+
export const FlowNodeLayer = z.enum(["marker", "step", "link"]);
|
|
41
|
+
export const flowNodeLayer = {
|
|
42
|
+
trigger: "marker",
|
|
43
|
+
output: "marker",
|
|
44
|
+
instruction: "step",
|
|
45
|
+
condition: "step",
|
|
46
|
+
subflow: "step",
|
|
47
|
+
folder: "link",
|
|
48
|
+
document: "link",
|
|
49
|
+
upload: "link",
|
|
50
|
+
table: "link",
|
|
51
|
+
tool: "link",
|
|
52
|
+
};
|
|
53
|
+
export const FlowNode = z.discriminatedUnion("kind", [
|
|
54
|
+
z.strictObject({
|
|
55
|
+
...FlowNodeBase,
|
|
56
|
+
kind: z.literal("trigger"),
|
|
57
|
+
// ⚠️ `manual` is the only mode there is. `webhook` and `schedule` stood here and fired nothing:
|
|
58
|
+
// a flow is carried out by an external agent that brings its own schedule, which is what the
|
|
59
|
+
// code does rather than what it intends — `step()` hands back the current node, `completeStep`
|
|
60
|
+
// takes the result from outside, and the Cloudflare workflow waits rather than drives. #32 was
|
|
61
|
+
// closed on that basis, and a mode nothing triggers is a promise nobody keeps.
|
|
62
|
+
configuration: z.strictObject({ mode: z.literal("manual") }),
|
|
63
|
+
}),
|
|
64
|
+
z.strictObject({
|
|
65
|
+
...FlowNodeBase,
|
|
66
|
+
kind: z.literal("instruction"),
|
|
67
|
+
configuration: z.strictObject({ prompt: z.string().min(1).max(50_000) }),
|
|
68
|
+
}),
|
|
69
|
+
// The four link kinds that name something in the shared tree. They are separate kinds rather than
|
|
70
|
+
// one with a `kind` field so the canvas, the palette and the picker can each say what they mean
|
|
71
|
+
// without reading into a configuration — and so a stored graph says it too.
|
|
72
|
+
z.strictObject({ ...FlowNodeBase, kind: z.literal("folder"), configuration: LinkConfiguration }),
|
|
73
|
+
z.strictObject({
|
|
74
|
+
...FlowNodeBase,
|
|
75
|
+
kind: z.literal("document"),
|
|
76
|
+
configuration: LinkConfiguration,
|
|
77
|
+
}),
|
|
78
|
+
z.strictObject({ ...FlowNodeBase, kind: z.literal("upload"), configuration: LinkConfiguration }),
|
|
79
|
+
z.strictObject({ ...FlowNodeBase, kind: z.literal("table"), configuration: LinkConfiguration }),
|
|
80
|
+
z.strictObject({
|
|
81
|
+
...FlowNodeBase,
|
|
82
|
+
kind: z.literal("tool"),
|
|
83
|
+
configuration: z.strictObject({
|
|
84
|
+
toolName: ToolName,
|
|
85
|
+
fingerprint: z
|
|
86
|
+
.string()
|
|
87
|
+
.regex(/^[a-f0-9]{64}$/)
|
|
88
|
+
.nullable()
|
|
89
|
+
.default(null),
|
|
90
|
+
arguments: z.record(z.string(), z.unknown()).default({}),
|
|
91
|
+
}),
|
|
92
|
+
}),
|
|
93
|
+
z.strictObject({
|
|
94
|
+
...FlowNodeBase,
|
|
95
|
+
kind: z.literal("condition"),
|
|
96
|
+
configuration: z.strictObject({
|
|
97
|
+
mode: z.literal("semantic"),
|
|
98
|
+
instruction: z.string().min(1).max(10_000),
|
|
99
|
+
}),
|
|
100
|
+
}),
|
|
101
|
+
// ⚠️ There is no `approval` kind, and adding one back is a product decision rather than a schema
|
|
102
|
+
// addition (#73). It waited on a named person with a deadline, which needs a queue, a
|
|
103
|
+
// notification, a stand-in and an answer to "the deadline passed" — none of which exist. Without
|
|
104
|
+
// it, D24 holds without exception: nothing in Intel waits. A stored graph that still carries one
|
|
105
|
+
// is rewritten to a `condition` by migration 0007, because the question it asked is one the agent
|
|
106
|
+
// can answer.
|
|
107
|
+
//
|
|
108
|
+
// The seventh kind: one flow calls another (ADR-0004 §3). A schema addition, not hidden behavior
|
|
109
|
+
// in a generic code node — which flow is called has to be readable from the graph, or neither the
|
|
110
|
+
// publish-time call rule nor the sidebar could see it.
|
|
111
|
+
z.strictObject({
|
|
112
|
+
...FlowNodeBase,
|
|
113
|
+
kind: z.literal("subflow"),
|
|
114
|
+
// What the called flow is given travels through `StartFlowRunInput.input` — the schema every run
|
|
115
|
+
// already uses. A second, static input here would be a promise the execution does not keep.
|
|
116
|
+
configuration: z.strictObject({
|
|
117
|
+
flowId: IntelId,
|
|
118
|
+
version: SubflowVersion.default({ mode: "latest" }),
|
|
119
|
+
}),
|
|
120
|
+
}),
|
|
121
|
+
// ⚠️ The end marks, it does not make. It used to carry a `template` that nothing ever read, and a
|
|
122
|
+
// node called "Result" that appeared to produce one is what everybody read it as. The result of a
|
|
123
|
+
// run is what the last step before it hands in (D25) — `completeStep` carries that forward.
|
|
124
|
+
z.strictObject({
|
|
125
|
+
...FlowNodeBase,
|
|
126
|
+
kind: z.literal("output"),
|
|
127
|
+
configuration: z.strictObject({}),
|
|
128
|
+
}),
|
|
129
|
+
]);
|
|
130
|
+
// The two things an edge can mean (#37). `flow` is the order of work — "and then". `context` is what
|
|
131
|
+
// a step works with: a document consulted in exactly this step, an approval obtained in exactly this
|
|
132
|
+
// step, or, at the output, the table a result is written to.
|
|
133
|
+
//
|
|
134
|
+
// ⚠️ `flow` is the default, and that is the whole of the migration: every edge stored before this
|
|
135
|
+
// existed parses into the meaning it already had. Nothing about saved graphs has to be rewritten.
|
|
136
|
+
export const FlowEdgeKind = z.enum(["flow", "context"]);
|
|
137
|
+
export const FlowEdge = z.strictObject({
|
|
138
|
+
id: FlowNodeId,
|
|
139
|
+
source: FlowNodeId,
|
|
140
|
+
target: FlowNodeId,
|
|
141
|
+
kind: FlowEdgeKind.default("flow"),
|
|
142
|
+
label: z.string().trim().min(1).max(120).nullable().default(null),
|
|
143
|
+
sourceHandle: z.string().trim().min(1).max(120).nullable().default(null),
|
|
144
|
+
});
|
|
145
|
+
export const FlowGraph = z.strictObject({
|
|
146
|
+
nodes: z.array(FlowNode).min(2).max(200),
|
|
147
|
+
edges: z.array(FlowEdge).min(1).max(500),
|
|
148
|
+
});
|
|
149
|
+
export const Flow = z.strictObject({
|
|
150
|
+
id: IntelId,
|
|
151
|
+
// The one thing a Flow shares with a document: its place in the shared folder tree (ADR-0004).
|
|
152
|
+
// Everything else stays apart — versions, R2 body and Vectorize belong to the document, the graph,
|
|
153
|
+
// runs and approvals to the flow. `null` is the root of that same tree.
|
|
154
|
+
parentId: IntelId.nullable(),
|
|
155
|
+
title: z.string().min(1).max(240),
|
|
156
|
+
description: z.string().max(2_000).nullable(),
|
|
157
|
+
ownerId: IntelId,
|
|
158
|
+
currentVersionId: IntelId.nullable(),
|
|
159
|
+
publishedVersionId: IntelId.nullable(),
|
|
160
|
+
createdAt: IsoDateTime,
|
|
161
|
+
updatedAt: IsoDateTime,
|
|
162
|
+
archivedAt: IsoDateTime.nullable(),
|
|
163
|
+
});
|
|
164
|
+
export const FlowVersion = z.strictObject({
|
|
165
|
+
id: IntelId,
|
|
166
|
+
flowId: IntelId,
|
|
167
|
+
sequence: z.number().int().positive(),
|
|
168
|
+
graph: FlowGraph,
|
|
169
|
+
createdBy: IntelId,
|
|
170
|
+
createdAt: IsoDateTime,
|
|
171
|
+
});
|
|
172
|
+
export const FlowDocument = z.strictObject({
|
|
173
|
+
flow: Flow,
|
|
174
|
+
version: FlowVersion.nullable(),
|
|
175
|
+
});
|
|
176
|
+
// One version as the history shows it: the metadata without the graph it carries. A flow's history
|
|
177
|
+
// is as long as its edits, and a list that shipped every graph would pay for drawings nobody asked
|
|
178
|
+
// for — whoever needs one asks for that one version.
|
|
179
|
+
export const FlowVersionSummary = z.strictObject({
|
|
180
|
+
id: IntelId,
|
|
181
|
+
flowId: IntelId,
|
|
182
|
+
sequence: z.number().int().positive(),
|
|
183
|
+
createdBy: IntelId,
|
|
184
|
+
createdAt: IsoDateTime,
|
|
185
|
+
// Whether this is the version the flow currently publishes. Derived from the flow row when the
|
|
186
|
+
// list is read, never stored on the version: a version is immutable and "published" is not a
|
|
187
|
+
// property of it — it is the flow's choice, revocable without touching the version.
|
|
188
|
+
published: z.boolean(),
|
|
189
|
+
});
|
|
190
|
+
export const FlowVersionList = z.strictObject({
|
|
191
|
+
flowId: IntelId,
|
|
192
|
+
items: z.array(FlowVersionSummary),
|
|
193
|
+
});
|
|
194
|
+
// Both identifiers, deliberately: a version ID alone would resolve whatever version carries it,
|
|
195
|
+
// whichever flow it belongs to, and the ACL is answered on the flow. The pair makes a foreign
|
|
196
|
+
// version a 404 rather than a read.
|
|
197
|
+
export const GetFlowVersionInput = z.strictObject({
|
|
198
|
+
flowId: IntelId.describe("Flow the version belongs to. Named alongside the version so access is decided on the flow."),
|
|
199
|
+
versionId: IntelId.describe("Version to read, from flow_version_list."),
|
|
200
|
+
});
|
|
201
|
+
// The same for flows: which of them call another flow that this reader may also see (#59). An
|
|
202
|
+
// expand arrow on a flow whose calls are all hidden promises content that expanding it cannot
|
|
203
|
+
// deliver.
|
|
204
|
+
export const FlowList = z.strictObject({
|
|
205
|
+
items: z.array(Flow),
|
|
206
|
+
withCalls: z.array(IntelId).default([]),
|
|
207
|
+
});
|
|
208
|
+
export const ReferencedNode = z.strictObject({
|
|
209
|
+
id: IntelId,
|
|
210
|
+
title: z.string().min(1).max(240),
|
|
211
|
+
});
|
|
212
|
+
// What a flow touches: the documents its tree links name and the tools its Tool steps call,
|
|
213
|
+
// read straight out of the graph. Deliberately not a conflict report — there is no arithmetic here
|
|
214
|
+
// and nothing that can go stale, because the graph is the answer. Whether a given person may reach
|
|
215
|
+
// any of it is decided where it can be decided honestly: when the folder is shared, and at runtime
|
|
216
|
+
// (ADR-0004 §4). For tools it can only ever be the latter, because the catalog is a live query with
|
|
217
|
+
// the requesting user's own token (ADR-0003).
|
|
218
|
+
//
|
|
219
|
+
// ⚠️ `nodes` names only what the asking user may see. The rest is `hiddenNodes`, a count.
|
|
220
|
+
export const FlowRequirements = z.strictObject({
|
|
221
|
+
flowId: IntelId,
|
|
222
|
+
versionId: IntelId.nullable(),
|
|
223
|
+
nodes: z.array(ReferencedNode),
|
|
224
|
+
hiddenNodes: z.number().int().nonnegative(),
|
|
225
|
+
tools: z.array(ToolName),
|
|
226
|
+
});
|
|
227
|
+
// What stands between this flow and a run, asked on demand and answered for the person asking.
|
|
228
|
+
//
|
|
229
|
+
// ⚠️ A snapshot, and it says so. The tool catalog is a live query with the requesting user's own
|
|
230
|
+
// token (ADR-0003), so what is reachable now can be different tomorrow, and the same flow answers
|
|
231
|
+
// differently for two people. That is why this is a question one asks rather than a badge on the
|
|
232
|
+
// flow: a standing "this flow has conflicts" would be wrong for tools by construction (#72, D24).
|
|
233
|
+
export const FlowValidation = z.strictObject({
|
|
234
|
+
flowId: IntelId,
|
|
235
|
+
versionId: IntelId.nullable(),
|
|
236
|
+
// Empty means it would start now — for this person, at this moment.
|
|
237
|
+
problems: z.array(z.strictObject({
|
|
238
|
+
code: z.string().min(1).max(80),
|
|
239
|
+
detail: z.string().min(1).max(2_000),
|
|
240
|
+
})),
|
|
241
|
+
checkedAt: IsoDateTime,
|
|
242
|
+
});
|
|
243
|
+
export const CreateFlowInput = z.strictObject({
|
|
244
|
+
parentId: IntelId.nullable()
|
|
245
|
+
.default(null)
|
|
246
|
+
.describe("Folder to file the flow in. `null` puts it at the top level."),
|
|
247
|
+
title: z.string().trim().min(1).max(240).describe("What the flow is called."),
|
|
248
|
+
description: z
|
|
249
|
+
.string()
|
|
250
|
+
.trim()
|
|
251
|
+
.max(2_000)
|
|
252
|
+
.nullable()
|
|
253
|
+
.default(null)
|
|
254
|
+
.describe("Optional sentence about what the flow is for."),
|
|
255
|
+
idempotencyKey: IdempotencyKey,
|
|
256
|
+
});
|
|
257
|
+
// Renaming and moving a flow. Both are organization and nothing else: they touch no version, no
|
|
258
|
+
// published graph and no run, because organization has to stay free of consequence or nobody dares
|
|
259
|
+
// to reorganize (ADR-0004).
|
|
260
|
+
export const UpdateFlowInput = z
|
|
261
|
+
.strictObject({
|
|
262
|
+
flowId: IntelId.describe("Flow to rename or move."),
|
|
263
|
+
baseUpdatedAt: IsoDateTime.describe("`updatedAt` as flow_get last reported it. A newer value on the server means somebody else changed the flow first and the call is refused."),
|
|
264
|
+
title: z
|
|
265
|
+
.string()
|
|
266
|
+
.trim()
|
|
267
|
+
.min(1)
|
|
268
|
+
.max(240)
|
|
269
|
+
.optional()
|
|
270
|
+
.describe("New title. Omit to leave it as it is."),
|
|
271
|
+
description: z
|
|
272
|
+
.string()
|
|
273
|
+
.trim()
|
|
274
|
+
.max(2_000)
|
|
275
|
+
.nullable()
|
|
276
|
+
.optional()
|
|
277
|
+
.describe("New description, or `null` to clear it. Omit to leave it as it is."),
|
|
278
|
+
parentId: IntelId.nullable()
|
|
279
|
+
.optional()
|
|
280
|
+
.describe("Folder to move the flow into, or `null` for the top level. Omit to leave it where it is. Moving touches no version, no published graph and no run."),
|
|
281
|
+
idempotencyKey: IdempotencyKey,
|
|
282
|
+
})
|
|
283
|
+
.refine((input) => input.title !== undefined || input.description !== undefined || input.parentId !== undefined, { error: "At least one change is required" });
|
|
284
|
+
// Archiving a flow is the same shape as archiving a document, deliberately: `archived` is a boolean
|
|
285
|
+
// rather than a one-way verb, because an archive nothing returns from is a delete under a friendlier
|
|
286
|
+
// name. Restoring is the same call with `false`.
|
|
287
|
+
export const ArchiveFlowInput = z.strictObject({
|
|
288
|
+
flowId: IntelId.describe("Flow to archive or restore."),
|
|
289
|
+
baseUpdatedAt: IsoDateTime.describe("`updatedAt` as flow_get last reported it. A newer value on the server means somebody else changed the flow first and the call is refused."),
|
|
290
|
+
archived: z
|
|
291
|
+
.boolean()
|
|
292
|
+
.describe("`true` archives the flow, `false` restores it. Nothing is deleted and every version stays readable."),
|
|
293
|
+
idempotencyKey: IdempotencyKey,
|
|
294
|
+
});
|
|
295
|
+
// Three answers, not two: an absent `parentId` lists every visible flow (the search dialog asks
|
|
296
|
+
// that), `null` lists the root of the shared tree and an ID lists one folder (the sidebar tree asks
|
|
297
|
+
// per level, which is what keeps the tree off the N+1 it used to load with).
|
|
298
|
+
export const ListFlowsInput = z.strictObject({
|
|
299
|
+
parentId: IntelId.nullable()
|
|
300
|
+
.optional()
|
|
301
|
+
.describe("Three answers, not two: omit it to list every flow this reader may see, pass `null` for the top level, or a folder id for one level of it."),
|
|
302
|
+
// The only way back to an archived flow, and the only place that asks for one: the bounded read
|
|
303
|
+
// behind the relation graph has no such flag on purpose (#30). A drawing that includes what was
|
|
304
|
+
// archived says the tidying up never happened.
|
|
305
|
+
//
|
|
306
|
+
// ⚠️ `.optional()` rather than `.default(false)`, unlike `ListNodesInput`. This schema is
|
|
307
|
+
// the argument type of `listFlows` on three layers, and a default makes the field required in the
|
|
308
|
+
// *parsed* type — every existing caller that lists a folder would have to spell out the answer to
|
|
309
|
+
// a question it is not asking. Absent means "without the archive" everywhere it is read.
|
|
310
|
+
includeArchived: z
|
|
311
|
+
.boolean()
|
|
312
|
+
.optional()
|
|
313
|
+
.describe("Include archived flows beside the live ones. Absent means without them."),
|
|
314
|
+
// The same question for flows, and the same override of `parentId` — see `ListNodesInput`.
|
|
315
|
+
archivedOnly: z
|
|
316
|
+
.boolean()
|
|
317
|
+
.optional()
|
|
318
|
+
.describe("List only archived flows, across the whole tree. Overrides parentId rather than narrowing it."),
|
|
319
|
+
});
|
|
320
|
+
export const GetFlowInput = z.strictObject({
|
|
321
|
+
flowId: IntelId.describe("Flow to read, from flow_list."),
|
|
322
|
+
});
|
|
323
|
+
export const SaveFlowVersionInput = z.strictObject({
|
|
324
|
+
flowId: IntelId.describe("Flow to append a version to."),
|
|
325
|
+
baseVersionId: IntelId.nullable().describe("The version this edit was made against, from flow_get, or `null` for a flow that has none yet. If the flow has moved on since, the call is refused rather than overwriting the newer version."),
|
|
326
|
+
graph: FlowGraph.describe("The complete graph — nodes and edges — not a patch. It is validated before it is stored, so an unreachable node or a dangling edge is refused here rather than at run time."),
|
|
327
|
+
idempotencyKey: IdempotencyKey,
|
|
328
|
+
});
|
|
329
|
+
export const PublishFlowInput = z.strictObject({
|
|
330
|
+
flowId: IntelId.describe("Flow to publish a version of."),
|
|
331
|
+
versionId: IntelId.describe("Which version becomes the published one. Publishing freezes what it calls: a sub-flow call set to `latest` is pinned to the version current at this moment. flow_publish_preview shows that beforehand."),
|
|
332
|
+
idempotencyKey: IdempotencyKey,
|
|
333
|
+
});
|
|
334
|
+
// The way back out of a publication (#146). No versionId: what is withdrawn is whatever is
|
|
335
|
+
// published now, and naming one would invite a race between reading it and revoking it. Versions
|
|
336
|
+
// are untouched — republishing any of them is one `publish` away.
|
|
337
|
+
export const UnpublishFlowInput = z.strictObject({
|
|
338
|
+
flowId: IntelId.describe("Flow to withdraw. What is withdrawn is whatever is published now — there is no versionId, so there is no race between reading it and revoking it. Versions are untouched."),
|
|
339
|
+
idempotencyKey: IdempotencyKey,
|
|
340
|
+
});
|
|
341
|
+
export const PreviewFlowPublishInput = z.strictObject({
|
|
342
|
+
flowId: IntelId.describe("Flow the version belongs to."),
|
|
343
|
+
versionId: IntelId.describe("The version flow_publish would be called with. Nothing is changed by asking."),
|
|
344
|
+
});
|
|
345
|
+
// One sub-flow call as publishing will leave it (ADR-0004 §5). `freezes` is the whole point of the
|
|
346
|
+
// preview: it marks the calls whose `latest` publishing turns into `versionId`, so the author reads
|
|
347
|
+
// the decision before making it rather than after.
|
|
348
|
+
//
|
|
349
|
+
// ⚠️ Only callees the asking actor may reach are listed at all. A call whose callee they cannot see
|
|
350
|
+
// is left out rather than named, because a title is the thing an unreachable flow must not hand out.
|
|
351
|
+
export const FlowPublishCall = z.strictObject({
|
|
352
|
+
nodeId: FlowNodeId,
|
|
353
|
+
nodeLabel: z.string().min(1).max(160),
|
|
354
|
+
calleeId: IntelId,
|
|
355
|
+
calleeTitle: z.string().min(1).max(240),
|
|
356
|
+
mode: SubflowVersionMode,
|
|
357
|
+
// The version this call will take once published. `null` when it follows the callee, which is the
|
|
358
|
+
// one case where the answer is only known at run time.
|
|
359
|
+
versionId: IntelId.nullable(),
|
|
360
|
+
versionSequence: z.number().int().positive().nullable(),
|
|
361
|
+
freezes: z.boolean(),
|
|
362
|
+
// The callee has a published version to be called at all. `false` is what publishing will refuse.
|
|
363
|
+
available: z.boolean(),
|
|
364
|
+
});
|
|
365
|
+
export const FlowPublishPreview = z.strictObject({
|
|
366
|
+
flowId: IntelId,
|
|
367
|
+
versionId: IntelId,
|
|
368
|
+
calls: z.array(FlowPublishCall),
|
|
369
|
+
});
|
|
370
|
+
// A flow has no share schema of its own. A grant sits on the folder a flow is filed in and inherits
|
|
371
|
+
// down from there (ADR-0004 §2); a narrower grant beside it would destroy the subtree guarantee
|
|
372
|
+
// section 3 rests on, so per-flow grants were removed rather than deprecated.
|
|
373
|
+
// What accesses what, for one level of the shared tree (#19). A folder answers it for its contents,
|
|
374
|
+
// a single flow for itself. Documents and flows are two kinds of thing that share one tree
|
|
375
|
+
// (ADR-0004 §1), so the graph carries both and says which of them it is.
|
|
376
|
+
export const RelationNodeKind = z.enum(["folder", "document", "attachment", "table", "flow"]);
|
|
377
|
+
export const RelationNode = z.strictObject({
|
|
378
|
+
id: IntelId,
|
|
379
|
+
kind: RelationNodeKind,
|
|
380
|
+
title: z.string().min(1).max(240),
|
|
381
|
+
// Inside the level being shown, rather than something it reaches out to. A flow reading a policy
|
|
382
|
+
// document from another folder pulls that document in, and the difference should be legible.
|
|
383
|
+
inScope: z.boolean(),
|
|
384
|
+
});
|
|
385
|
+
export const RelationEdge = z.strictObject({
|
|
386
|
+
id: z.string().min(1).max(400),
|
|
387
|
+
source: IntelId,
|
|
388
|
+
target: IntelId,
|
|
389
|
+
relation: z.enum(["reads", "calls"]),
|
|
390
|
+
});
|
|
391
|
+
export const RelationGraphScope = z.discriminatedUnion("of", [
|
|
392
|
+
z.strictObject({ of: z.literal("folder"), folderId: IntelId.nullable() }),
|
|
393
|
+
z.strictObject({ of: z.literal("flow"), flowId: IntelId }),
|
|
394
|
+
]);
|
|
395
|
+
export const RelationGraphInput = z.strictObject({
|
|
396
|
+
scope: RelationGraphScope.describe("What to draw around: one folder — `null` for the whole tree — or one flow."),
|
|
397
|
+
// How much is drawn before the answer is summarized instead. A big folder has to stay usable, and
|
|
398
|
+
// the cut-off is reported rather than swallowed.
|
|
399
|
+
limit: z
|
|
400
|
+
.number()
|
|
401
|
+
.int()
|
|
402
|
+
.min(1)
|
|
403
|
+
.max(300)
|
|
404
|
+
.default(60)
|
|
405
|
+
.describe("How many nodes the drawing may carry before it is summarized instead. What was left out is reported in `omitted` rather than swallowed."),
|
|
406
|
+
});
|
|
407
|
+
// ⚠️ Only what the asking user may see is in here. A node they may not reach is absent, not greyed
|
|
408
|
+
// out and not counted: an edge to a placeholder would already tell them the thing exists, which is
|
|
409
|
+
// the leak this schema has to make impossible to write by accident. `omitted` is about the size
|
|
410
|
+
// limit alone, never about permissions.
|
|
411
|
+
export const RelationGraph = z.strictObject({
|
|
412
|
+
scope: RelationGraphScope,
|
|
413
|
+
nodes: z.array(RelationNode),
|
|
414
|
+
edges: z.array(RelationEdge),
|
|
415
|
+
omitted: z.number().int().nonnegative(),
|
|
416
|
+
limit: z.number().int().positive(),
|
|
417
|
+
});
|