@anchrd/colab-sdk 0.1.52 → 0.1.53
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/action-blocks/action-blocks.d.ts +6 -0
- package/dist/action-blocks/action-blocks.js +7 -2
- package/dist/actions/actions.d.ts +3 -0
- package/dist/conversations/conversations.d.ts +8 -0
- package/dist/conversations/conversations.js +5 -0
- package/dist/error/error.js +48 -3
- package/dist/flows/flow-runs.d.ts +2313 -0
- package/dist/flows/flow-runs.js +424 -0
- package/dist/flows/flows.d.ts +2761 -0
- package/dist/flows/flows.js +471 -0
- package/dist/goals/goals.d.ts +3 -0
- package/dist/grammar/grammar.d.ts +1 -0
- package/dist/grammar/grammar.js +4 -0
- package/dist/nodes/nodes.d.ts +8 -1
- package/dist/nodes/nodes.js +2 -0
- package/dist/relations/relations.d.ts +2 -0
- package/dist/schedule/schedule.d.ts +1 -0
- package/dist/schedule/schedule.js +1 -1
- package/dist/sdk.d.ts +2 -0
- package/dist/sdk.js +2 -0
- package/dist/tree-order/tree-order.d.ts +1 -1
- package/dist/tree-order/tree-order.js +1 -0
- package/dist/written/written.d.ts +4 -0
- package/dist/written/written.js +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Flag, Limit } from "../list-input.js";
|
|
3
|
+
import { NodeId, NodePerson } from "../nodes/nodes.js";
|
|
4
|
+
import { IdempotencyKey } from "../primitives/primitives.js";
|
|
5
|
+
import { RunId } from "../runs/runs.js";
|
|
6
|
+
import { FlowAction, FlowReachedPath, FlowSecretName, FlowStepId, FlowTarget } from "./flows.js";
|
|
7
|
+
// The runs of a flow (#1229, E274, E275, Nodes › Flow › Läufe und Runner): what the runner keeps of
|
|
8
|
+
// each run and each step it played, the inputs of `intelligence_flow_run_*`, and the messages of the
|
|
9
|
+
// live view's WebSocket.
|
|
10
|
+
//
|
|
11
|
+
// ⚠️ Nothing here carries a secret's value or read data: a step keeps its actions as they stand (a
|
|
12
|
+
// `fill` names its secret under `credential`) and its result as counts.
|
|
13
|
+
const FlowId = NodeId.describe("The flow's id, a `node_…` of kind flow.");
|
|
14
|
+
export const FlowRunId = RunId.describe("A run of the flow, `run_…`.");
|
|
15
|
+
// fixed: the live version's steps replayed without a model (#1229). free: a model goes on from an
|
|
16
|
+
// open step (#1230).
|
|
17
|
+
export const flowRunKinds = ["fixed", "free"];
|
|
18
|
+
export const flowRunTriggers = ["manual", "schedule"];
|
|
19
|
+
// open: a fixed run met an open step and ended there; the next free run goes on from it.
|
|
20
|
+
export const flowRunStatuses = [
|
|
21
|
+
"queued",
|
|
22
|
+
"running",
|
|
23
|
+
"succeeded",
|
|
24
|
+
"failed",
|
|
25
|
+
"cancelled",
|
|
26
|
+
"open",
|
|
27
|
+
];
|
|
28
|
+
export const flowRunStepStatuses = ["running", "succeeded", "failed", "open", "cancelled"];
|
|
29
|
+
// What a step produced, as counts: read data passes the model and stays in no run.
|
|
30
|
+
export const FlowRunStepResult = z.object({
|
|
31
|
+
// Per `read` of the step: under which name, how many entries.
|
|
32
|
+
read: z.array(z.object({ into: z.string(), entries: z.int() })).optional(),
|
|
33
|
+
// Per `write`: into which node, how many entries the step had, how many were new.
|
|
34
|
+
written: z.array(z.object({ nodeId: NodeId, entries: z.int(), added: z.int() })).optional(),
|
|
35
|
+
// A step with `repeat`: how many rounds ran, and whether `max` stopped it.
|
|
36
|
+
rounds: z.int().optional(),
|
|
37
|
+
limited: z.boolean().optional(),
|
|
38
|
+
});
|
|
39
|
+
// A rectangle in the pixels of a step's picture.
|
|
40
|
+
export const FlowBox = z.object({
|
|
41
|
+
x: z.number(),
|
|
42
|
+
y: z.number(),
|
|
43
|
+
width: z.number(),
|
|
44
|
+
height: z.number(),
|
|
45
|
+
});
|
|
46
|
+
// One step as the run played it, per round of a `repeat`. `index` counts the run's steps from 0 in
|
|
47
|
+
// the order they ran; the picture of a failed one is at `pictureUrl`.
|
|
48
|
+
export const FlowRunStep = z.object({
|
|
49
|
+
index: z.int(),
|
|
50
|
+
stepId: FlowStepId,
|
|
51
|
+
// The top-level step this one hangs under, null for a top-level step.
|
|
52
|
+
parentStepId: FlowStepId.nullable(),
|
|
53
|
+
// The round of the parent's `repeat`, from 1; null outside a repeat.
|
|
54
|
+
round: z.int().nullable(),
|
|
55
|
+
title: z.string(),
|
|
56
|
+
// A free run's step (#1230): what the model said it does and how to tell it worked, the texts its
|
|
57
|
+
// step in the draft takes. Absent in a fixed run, whose texts stand in the version.
|
|
58
|
+
instruction: z.string().optional(),
|
|
59
|
+
success: z.string().optional(),
|
|
60
|
+
status: z.enum(flowRunStepStatuses),
|
|
61
|
+
startedAt: z.iso.datetime(),
|
|
62
|
+
durationMs: z.int().nullable(),
|
|
63
|
+
// The actions it ran, as they stand in the version; a `fill` names its secret, never the value.
|
|
64
|
+
actions: z.array(FlowAction),
|
|
65
|
+
result: FlowRunStepResult.nullable(),
|
|
66
|
+
// On failure: what went wrong (a secret's value struck), on which address.
|
|
67
|
+
error: z.object({ message: z.string(), url: z.string().nullable() }).nullable(),
|
|
68
|
+
// `/api/intelligence/flows/:flowId/runs/:runId/steps/:index/picture`, JPEG, or null.
|
|
69
|
+
pictureUrl: z.string().nullable(),
|
|
70
|
+
// Where the element of the action that failed stands in that picture, in its pixels, so a view can
|
|
71
|
+
// mark it; null without a picture or when the page had no such element. Optional only so readers
|
|
72
|
+
// built before it (#1231) still type; the server always sends it.
|
|
73
|
+
targetBox: FlowBox.nullable().optional(),
|
|
74
|
+
// Which try of the step this is within its round, from 1. A fixed run tries once; a free run
|
|
75
|
+
// (#1230) tries again and marks a try it threw away as discarded, with why.
|
|
76
|
+
attempt: z
|
|
77
|
+
.object({
|
|
78
|
+
number: z.int(),
|
|
79
|
+
discarded: z.boolean(),
|
|
80
|
+
reason: z.string().nullable(),
|
|
81
|
+
})
|
|
82
|
+
.optional(),
|
|
83
|
+
// fixed: replayed without a model; free: a model played it (#1230), and `playedBy` says who.
|
|
84
|
+
mode: z.enum(flowRunKinds).optional(),
|
|
85
|
+
playedBy: NodePerson.nullable().optional(),
|
|
86
|
+
// Per action it ran, in the order of `actions`: how it ended and how long it took.
|
|
87
|
+
actionResults: z
|
|
88
|
+
.array(z.object({
|
|
89
|
+
status: z.enum(["succeeded", "failed"]),
|
|
90
|
+
durationMs: z.int(),
|
|
91
|
+
// Why it failed, a secret's value struck: a free run keeps the failed action (#1230).
|
|
92
|
+
message: z.string().optional(),
|
|
93
|
+
}))
|
|
94
|
+
.optional(),
|
|
95
|
+
});
|
|
96
|
+
export const FlowRun = z.object({
|
|
97
|
+
runId: FlowRunId,
|
|
98
|
+
flowId: FlowId,
|
|
99
|
+
kind: z.enum(flowRunKinds),
|
|
100
|
+
trigger: z.enum(flowRunTriggers),
|
|
101
|
+
status: z.enum(flowRunStatuses),
|
|
102
|
+
// The live version it plays.
|
|
103
|
+
version: z.int(),
|
|
104
|
+
fromStepId: FlowStepId.nullable(),
|
|
105
|
+
// Whose rights it acts with: the starter, or on a schedule the responsible, else the publisher.
|
|
106
|
+
actsAs: NodePerson,
|
|
107
|
+
queuedAt: z.iso.datetime(),
|
|
108
|
+
startedAt: z.iso.datetime().nullable(),
|
|
109
|
+
endedAt: z.iso.datetime().nullable(),
|
|
110
|
+
// Why it failed or stopped, a secret's value struck.
|
|
111
|
+
message: z.string().nullable(),
|
|
112
|
+
// What the run read and wrote new, summed when it ended (0 while it runs), for the list.
|
|
113
|
+
read: z.int().optional(),
|
|
114
|
+
added: z.int().optional(),
|
|
115
|
+
// A free run's model use (#1230); null in a fixed run.
|
|
116
|
+
tokens: z.int().nullable().optional(),
|
|
117
|
+
costUsd: z.number().nullable().optional(),
|
|
118
|
+
// Where a free run took over from the fixed steps ("ab Schritt n frei", #1230); null otherwise.
|
|
119
|
+
freeFromStepId: FlowStepId.nullable().optional(),
|
|
120
|
+
// The WebSocket of the live view while its browser is open, `/live/flows/:flowId/runs/:runId`.
|
|
121
|
+
liveUrl: z.string(),
|
|
122
|
+
});
|
|
123
|
+
export const FlowRunDetail = FlowRun.extend({ steps: z.array(FlowRunStep) });
|
|
124
|
+
export const FlowRunList = z.object({ items: z.array(FlowRun), nextCursor: z.string().nullable() });
|
|
125
|
+
// ---- The tools' inputs ----
|
|
126
|
+
export const FlowRunCreateInput = z.strictObject({
|
|
127
|
+
flowId: FlowId,
|
|
128
|
+
fromStepId: FlowStepId.optional().describe("Start at this top-level step of the live version; the steps before it do not run. Leaving it out starts at the first."),
|
|
129
|
+
kind: z
|
|
130
|
+
.enum(flowRunKinds)
|
|
131
|
+
.optional()
|
|
132
|
+
.describe("fixed (the default): the live steps replay without a model, in the background. free: you steer the browser yourself: the fixed steps play up to the first open step (or up to freeFromStepId, or to the end), then the run waits for your intelligence_flow_run_step_create and intelligence_flow_run_action_create calls, and the answer carries the page."),
|
|
133
|
+
freeFromStepId: FlowStepId.optional().describe("Only with kind free: take over at this top-level step of the live version, even when it is fixed. Leaving it out takes over at the first open step, or after the last step."),
|
|
134
|
+
idempotencyKey: IdempotencyKey,
|
|
135
|
+
});
|
|
136
|
+
export const FlowRunListInput = z.strictObject({
|
|
137
|
+
flowId: FlowId,
|
|
138
|
+
cursor: z.string().max(200).optional(),
|
|
139
|
+
limit: Limit.optional(),
|
|
140
|
+
});
|
|
141
|
+
export const FlowRunGetInput = z.strictObject({ flowId: FlowId, runId: FlowRunId });
|
|
142
|
+
export const FlowRunCancelInput = z.strictObject({ flowId: FlowId, runId: FlowRunId });
|
|
143
|
+
// ---- The free run (#1230) ----
|
|
144
|
+
// An element number of the page as an answer showed it (`aria-ref`), like e12 or f1e3 in a frame.
|
|
145
|
+
export const FlowElementRef = z
|
|
146
|
+
.string()
|
|
147
|
+
.regex(/^(?:f\d+)?e\d+$/, "An element number like e12, as the page showed it.")
|
|
148
|
+
.describe("An element number as the last answer showed the page, like e12. It holds until the page changes; after a new address read the page again.");
|
|
149
|
+
const RefOrTarget = {
|
|
150
|
+
ref: FlowElementRef.optional(),
|
|
151
|
+
target: FlowTarget.optional().describe("The element described durably instead of ref: role and name, label or text."),
|
|
152
|
+
};
|
|
153
|
+
// What a model does in a free run: open, click and fill act on an element number (`ref`) or a target;
|
|
154
|
+
// read and write are the actions of the flow as they are stored. The runner keeps every action with
|
|
155
|
+
// a durable target, never a number.
|
|
156
|
+
export const FlowFreeAction = z
|
|
157
|
+
.union([
|
|
158
|
+
z.strictObject({ type: z.literal("click"), ...RefOrTarget }),
|
|
159
|
+
z.strictObject({
|
|
160
|
+
type: z.literal("fill"),
|
|
161
|
+
...RefOrTarget,
|
|
162
|
+
value: z
|
|
163
|
+
.union([
|
|
164
|
+
z.strictObject({ text: z.string().max(10_000).describe("The text to type.") }),
|
|
165
|
+
z.strictObject({
|
|
166
|
+
credential: FlowSecretName.describe("The NAME of one of the flow's secrets; the runner fills in its value, which you never see."),
|
|
167
|
+
}),
|
|
168
|
+
])
|
|
169
|
+
.describe("What to type: { text } or { credential: the name of a secret }."),
|
|
170
|
+
}),
|
|
171
|
+
FlowAction,
|
|
172
|
+
])
|
|
173
|
+
.describe("One action: open { url }, click { ref or target }, fill { ref or target, value }, read { into, rows, fields } (the entries stay in the run, you get counts) or write { from, nodeId, unique } (into a table). No repeat: a free run repeats by acting again.");
|
|
174
|
+
// The page as a model reads it: its address and ONE of the views, the smaller the better.
|
|
175
|
+
export const FlowRunPage = z.object({
|
|
176
|
+
url: z.string(),
|
|
177
|
+
// The short tree: one line per element to act on and each heading, `e12 button "Anmelden"`.
|
|
178
|
+
tree: z.string().optional(),
|
|
179
|
+
// After an action: only what changed in the short tree, `+` new and `-` gone lines; when that is
|
|
180
|
+
// larger than the tree, `tree` comes instead.
|
|
181
|
+
change: z.string().optional(),
|
|
182
|
+
// `find`: the lines of the whole page that hold the text, each with the number of its element.
|
|
183
|
+
found: z.string().optional(),
|
|
184
|
+
// `ref`: the part of the whole page under that element.
|
|
185
|
+
section: z.string().optional(),
|
|
186
|
+
// A long list cut short: how many lines were left out.
|
|
187
|
+
omitted: z.int().optional(),
|
|
188
|
+
// The page shows a captcha or a bot check: a flow does not pass it (decision 9 of #1226).
|
|
189
|
+
blocked: z.string().optional(),
|
|
190
|
+
});
|
|
191
|
+
// A picture of the page, asked for on its own (`picture: true`); `/mcp` hands it over as an image.
|
|
192
|
+
export const FlowRunPicture = z.object({
|
|
193
|
+
url: z.string(),
|
|
194
|
+
image: z.object({ data: z.string(), mimeType: z.literal("image/jpeg") }),
|
|
195
|
+
});
|
|
196
|
+
export const FlowRunPageGetInput = z.strictObject({
|
|
197
|
+
flowId: FlowId,
|
|
198
|
+
runId: FlowRunId,
|
|
199
|
+
find: z
|
|
200
|
+
.string()
|
|
201
|
+
.min(1)
|
|
202
|
+
.max(200)
|
|
203
|
+
.optional()
|
|
204
|
+
.describe("Show the lines of the whole page that hold this text, with their element numbers."),
|
|
205
|
+
ref: FlowElementRef.optional().describe("Show the whole page under this element, like one row of a list or a form."),
|
|
206
|
+
picture: Flag.optional().describe("Answer a picture of the page instead of text. Costs far more tokens than the tree: only when the tree cannot tell you what you need."),
|
|
207
|
+
});
|
|
208
|
+
export const FlowRunActionCreateInput = z.strictObject({
|
|
209
|
+
flowId: FlowId,
|
|
210
|
+
runId: FlowRunId,
|
|
211
|
+
action: FlowFreeAction,
|
|
212
|
+
});
|
|
213
|
+
// What one action did: the action as the run keeps it (a durable target in place of the number),
|
|
214
|
+
// whether it worked, what a read or a write counted, and the page after it.
|
|
215
|
+
export const FlowRunActed = z.object({
|
|
216
|
+
index: z.int(),
|
|
217
|
+
action: FlowAction,
|
|
218
|
+
status: z.enum(["succeeded", "failed"]),
|
|
219
|
+
// Why it failed, a secret's value struck. Not `error`: that is the shape of a refusal.
|
|
220
|
+
failure: z.string().optional(),
|
|
221
|
+
// A read: what stands under its name now (entries, per field how many carry a value) and what this
|
|
222
|
+
// read found (`read`); a second read of a name in the same step replaces the first. A write: how
|
|
223
|
+
// many entries and how many were new. Never the data itself.
|
|
224
|
+
result: z
|
|
225
|
+
.object({
|
|
226
|
+
read: z.int().optional(),
|
|
227
|
+
entries: z.int().optional(),
|
|
228
|
+
filled: z.record(z.string(), z.int()).optional(),
|
|
229
|
+
added: z.int().optional(),
|
|
230
|
+
})
|
|
231
|
+
.optional(),
|
|
232
|
+
page: FlowRunPage,
|
|
233
|
+
});
|
|
234
|
+
export const FlowRunStepCreateInput = z.strictObject({
|
|
235
|
+
flowId: FlowId,
|
|
236
|
+
runId: FlowRunId,
|
|
237
|
+
// With stepId all three may be left out (#1230, acceptance): they come from that step of the flow.
|
|
238
|
+
title: z
|
|
239
|
+
.string()
|
|
240
|
+
.min(1)
|
|
241
|
+
.max(200)
|
|
242
|
+
.optional()
|
|
243
|
+
.describe("The step's title, a few words, like Anmelden. Required for a new step; with stepId it defaults to that step's."),
|
|
244
|
+
instruction: z
|
|
245
|
+
.string()
|
|
246
|
+
.min(1)
|
|
247
|
+
.max(4000)
|
|
248
|
+
.optional()
|
|
249
|
+
.describe("What happens in this step, in plain words a person can change later. Required for a new step; with stepId it defaults to that step's."),
|
|
250
|
+
success: z
|
|
251
|
+
.string()
|
|
252
|
+
.max(2000)
|
|
253
|
+
.optional()
|
|
254
|
+
.describe('How to tell that it worked ("Geklappt, wenn"), in plain words; with stepId it defaults to that step\'s.'),
|
|
255
|
+
stepId: FlowStepId.optional().describe("The step of the flow this one does: the step you took over at, or one you try again after discarding a try; its title, instruction and success come along unless you send your own. Leaving it out makes a new step in the draft."),
|
|
256
|
+
reachedPath: FlowReachedPath.optional(),
|
|
257
|
+
});
|
|
258
|
+
export const FlowRunStepStarted = z.object({
|
|
259
|
+
index: z.int(),
|
|
260
|
+
stepId: FlowStepId,
|
|
261
|
+
attempt: z.int(),
|
|
262
|
+
// The step before ended failed: its page did not stand at its reachedPath.
|
|
263
|
+
previous: z.string().optional(),
|
|
264
|
+
// A hint (#1230, acceptance): the step taken over at is not played yet, and this one is a new one.
|
|
265
|
+
notice: z.string().optional(),
|
|
266
|
+
});
|
|
267
|
+
export const FlowRunStepUpdateInput = z.strictObject({
|
|
268
|
+
flowId: FlowId,
|
|
269
|
+
runId: FlowRunId,
|
|
270
|
+
stepId: FlowStepId.describe("The step as intelligence_flow_run_step_create named it."),
|
|
271
|
+
attempt: z
|
|
272
|
+
.int()
|
|
273
|
+
.min(1)
|
|
274
|
+
.optional()
|
|
275
|
+
.describe("Which try of that step; leaving it out takes its latest."),
|
|
276
|
+
title: z.string().min(1).max(200).optional(),
|
|
277
|
+
instruction: z.string().min(1).max(4000).optional(),
|
|
278
|
+
success: z.string().max(2000).optional(),
|
|
279
|
+
reachedPath: FlowReachedPath.nullable().optional(),
|
|
280
|
+
discard: z
|
|
281
|
+
.string()
|
|
282
|
+
.min(1)
|
|
283
|
+
.max(500)
|
|
284
|
+
.optional()
|
|
285
|
+
.describe("Throw this try away, with why (a sentence). It stays in the run as a discarded try and stays out of the draft; then try again with intelligence_flow_run_step_create and the same stepId."),
|
|
286
|
+
});
|
|
287
|
+
export const FlowRunCompleteInput = z.strictObject({
|
|
288
|
+
flowId: FlowId,
|
|
289
|
+
runId: FlowRunId,
|
|
290
|
+
outcome: z
|
|
291
|
+
.enum(["succeeded", "failed"])
|
|
292
|
+
.describe("succeeded: the task is done, and the steps you played become the draft of the flow. failed: you could not do it; nothing changes in the draft."),
|
|
293
|
+
message: z.string().max(2000).optional().describe("Why it failed, or a note for the run."),
|
|
294
|
+
tokens: z
|
|
295
|
+
.int()
|
|
296
|
+
.min(0)
|
|
297
|
+
.optional()
|
|
298
|
+
.describe("The tokens this free run cost you, if you know them; otherwise the run keeps its own estimate of your tool answers."),
|
|
299
|
+
costUsd: z.number().min(0).optional().describe("What those tokens cost, in US dollars."),
|
|
300
|
+
});
|
|
301
|
+
export const FlowRunCompleted = z.object({
|
|
302
|
+
// First, in words (#1230, acceptance): how it ended, read and new, the draft and what it needs.
|
|
303
|
+
summary: z.string(),
|
|
304
|
+
// Steps of the draft that stay open: the next run goes on freely at them.
|
|
305
|
+
open: z.array(z.object({ stepId: FlowStepId, title: z.string() })),
|
|
306
|
+
run: FlowRun,
|
|
307
|
+
// The draft as the run left it, step by step; null when nothing was written.
|
|
308
|
+
draft: z
|
|
309
|
+
.object({
|
|
310
|
+
steps: z.array(z.object({ stepId: FlowStepId, title: z.string(), state: z.string() })),
|
|
311
|
+
})
|
|
312
|
+
.nullable(),
|
|
313
|
+
});
|
|
314
|
+
// The answer of a free run's start: the run, the step it waits at, and the page.
|
|
315
|
+
export const FlowRunStarted = FlowRunDetail.extend({
|
|
316
|
+
// What to do first, in one sentence (#1230, acceptance).
|
|
317
|
+
next: z.string().optional(),
|
|
318
|
+
takeover: z
|
|
319
|
+
.object({
|
|
320
|
+
stepId: FlowStepId,
|
|
321
|
+
title: z.string(),
|
|
322
|
+
instruction: z.string(),
|
|
323
|
+
success: z.string(),
|
|
324
|
+
})
|
|
325
|
+
.nullable()
|
|
326
|
+
.optional(),
|
|
327
|
+
page: FlowRunPage.optional(),
|
|
328
|
+
});
|
|
329
|
+
// ---- The live view (E275) ----
|
|
330
|
+
// What the Durable Object of a run sends over `/live/flows/:flowId/runs/:runId`: a picture of the page
|
|
331
|
+
// (a CDP screencast frame, JPEG as Base64, the page's size in CSS pixels) while somebody watches, and
|
|
332
|
+
// `end` when the browser closed or never opens. ⚠️ Only pictures: the run's steps and state are read
|
|
333
|
+
// by polling `intelligence_flow_run_get` (E275 (2)).
|
|
334
|
+
export const FlowLiveServerMessage = z.discriminatedUnion("type", [
|
|
335
|
+
z.object({
|
|
336
|
+
type: z.literal("frame"),
|
|
337
|
+
data: z.string(),
|
|
338
|
+
width: z.int(),
|
|
339
|
+
height: z.int(),
|
|
340
|
+
}),
|
|
341
|
+
z.object({ type: z.literal("end") }),
|
|
342
|
+
// A step of the run began or ended (#1230): the view reads the run again, so its cards keep up
|
|
343
|
+
// with the browser instead of waiting for the next poll.
|
|
344
|
+
z.object({
|
|
345
|
+
type: z.literal("step"),
|
|
346
|
+
index: z.int(),
|
|
347
|
+
stepId: FlowStepId,
|
|
348
|
+
status: z.enum(flowRunStepStatuses),
|
|
349
|
+
}),
|
|
350
|
+
// "Selbst steuern" (#1233): who steers the browser now; null: nobody, the AI may act again.
|
|
351
|
+
// `you`: this socket's own person steers (the view shows the controls).
|
|
352
|
+
z.object({
|
|
353
|
+
type: z.literal("steer"),
|
|
354
|
+
by: NodePerson.nullable(),
|
|
355
|
+
you: z.boolean(),
|
|
356
|
+
// Whether this socket may take over at all: its person may change the flow, signed in in
|
|
357
|
+
// the browser, and the run waits for a model.
|
|
358
|
+
allowed: z.boolean(),
|
|
359
|
+
}),
|
|
360
|
+
// A step the person's click or input made, already in the run (its `step` message follows):
|
|
361
|
+
// the action as kept, or null for what could not be recorded (an open step with its
|
|
362
|
+
// instruction only).
|
|
363
|
+
z.object({
|
|
364
|
+
type: z.literal("recorded"),
|
|
365
|
+
index: z.int(),
|
|
366
|
+
stepId: FlowStepId,
|
|
367
|
+
action: FlowAction.nullable(),
|
|
368
|
+
// The title and instruction proposed from the action, in the person's language (#1233).
|
|
369
|
+
title: z.string().optional(),
|
|
370
|
+
instruction: z.string(),
|
|
371
|
+
}),
|
|
372
|
+
// The person typed into a password field: the value stays with the browser until they say
|
|
373
|
+
// which secret of the flow it is, or name a new one for it (`secret` from the client).
|
|
374
|
+
z.object({
|
|
375
|
+
type: z.literal("secretAsk"),
|
|
376
|
+
field: z.string(),
|
|
377
|
+
names: z.array(z.string()),
|
|
378
|
+
}),
|
|
379
|
+
// Done in the browser, not recorded: a scroll, a click on nothing with a role and a name.
|
|
380
|
+
z.object({ type: z.literal("unrecorded"), reason: z.string() }),
|
|
381
|
+
// The address the page stands at now (#1233), on connect and after every navigation, for the
|
|
382
|
+
// address bar: origin and path only. A query or a hash may carry a token or a session id, and
|
|
383
|
+
// the bar only orients; the address a step opens stays whole in its `open` action.
|
|
384
|
+
z.object({ type: z.literal("page"), url: z.string() }),
|
|
385
|
+
// A message of this socket was refused, with why (not steering, a host outside the flow's, …).
|
|
386
|
+
z.object({ type: z.literal("refused"), message: z.string() }),
|
|
387
|
+
]);
|
|
388
|
+
// What a viewer sends (#1233, "Selbst steuern"), only while it steers, except `take`. Coordinates
|
|
389
|
+
// are in the pixels of the picture (1024 x 640, the browser's viewport).
|
|
390
|
+
export const FlowLiveClientMessage = z.discriminatedUnion("type", [
|
|
391
|
+
// Take the browser over; the AI's tools wait. And give it back; the same run goes on.
|
|
392
|
+
z.strictObject({ type: z.literal("take") }),
|
|
393
|
+
z.strictObject({ type: z.literal("give") }),
|
|
394
|
+
z.strictObject({ type: z.literal("click"), x: z.number(), y: z.number() }),
|
|
395
|
+
// Typed text, inserted where the cursor is; recorded as one fill with the field's last value.
|
|
396
|
+
z.strictObject({ type: z.literal("text"), text: z.string().min(1).max(2000) }),
|
|
397
|
+
z.strictObject({
|
|
398
|
+
type: z.literal("key"),
|
|
399
|
+
key: z.enum(["Enter", "Tab", "Backspace", "Escape", "ArrowUp", "ArrowDown"]),
|
|
400
|
+
}),
|
|
401
|
+
z.strictObject({
|
|
402
|
+
type: z.literal("scroll"),
|
|
403
|
+
x: z.number(),
|
|
404
|
+
y: z.number(),
|
|
405
|
+
deltaY: z.number(),
|
|
406
|
+
}),
|
|
407
|
+
// An address typed into the address bar: on the flow's hosts only.
|
|
408
|
+
z.strictObject({ type: z.literal("open"), url: z.string().max(2000) }),
|
|
409
|
+
// The answer to `secretAsk`: an existing secret's name, or with `create` a new secret of that
|
|
410
|
+
// name holding what was typed. Only a person signed in in the browser.
|
|
411
|
+
z.strictObject({
|
|
412
|
+
type: z.literal("secret"),
|
|
413
|
+
name: FlowSecretName,
|
|
414
|
+
create: z.boolean().optional(),
|
|
415
|
+
}),
|
|
416
|
+
]);
|
|
417
|
+
// The address of a run's live view, for the runner's answers and the UI.
|
|
418
|
+
export function flowLivePath(flowId, runId) {
|
|
419
|
+
return `/live/flows/${flowId}/runs/${runId}`;
|
|
420
|
+
}
|
|
421
|
+
// The address of the picture of a failed step.
|
|
422
|
+
export function flowPicturePath(flowId, runId, index) {
|
|
423
|
+
return `/api/intelligence/flows/${flowId}/runs/${runId}/steps/${index}/picture`;
|
|
424
|
+
}
|