@nodetool-ai/app-runtime 0.8.1
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 +104 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/actions.d.ts +85 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +65 -0
- package/dist/actions.js.map +1 -0
- package/dist/bindings.d.ts +109 -0
- package/dist/bindings.d.ts.map +1 -0
- package/dist/bindings.js +257 -0
- package/dist/bindings.js.map +1 -0
- package/dist/bundle.d.ts +167 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +289 -0
- package/dist/bundle.js.map +1 -0
- package/dist/chat.d.ts +33 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +77 -0
- package/dist/chat.js.map +1 -0
- package/dist/conditions.d.ts +66 -0
- package/dist/conditions.d.ts.map +1 -0
- package/dist/conditions.js +221 -0
- package/dist/conditions.js.map +1 -0
- package/dist/doc-ops.d.ts +205 -0
- package/dist/doc-ops.d.ts.map +1 -0
- package/dist/doc-ops.js +304 -0
- package/dist/doc-ops.js.map +1 -0
- package/dist/document.d.ts +186 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +326 -0
- package/dist/document.js.map +1 -0
- package/dist/documents.d.ts +38 -0
- package/dist/documents.d.ts.map +1 -0
- package/dist/documents.js +108 -0
- package/dist/documents.js.map +1 -0
- package/dist/fold.d.ts +50 -0
- package/dist/fold.d.ts.map +1 -0
- package/dist/fold.js +175 -0
- package/dist/fold.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/input-validation.d.ts +4 -0
- package/dist/input-validation.d.ts.map +1 -0
- package/dist/input-validation.js +26 -0
- package/dist/input-validation.js.map +1 -0
- package/dist/mutable.d.ts +8 -0
- package/dist/mutable.d.ts.map +1 -0
- package/dist/mutable.js +2 -0
- package/dist/mutable.js.map +1 -0
- package/dist/operations.d.ts +51 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +95 -0
- package/dist/operations.js.map +1 -0
- package/dist/policy.d.ts +29 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +16 -0
- package/dist/policy.js.map +1 -0
- package/dist/predicates.d.ts +19 -0
- package/dist/predicates.d.ts.map +1 -0
- package/dist/predicates.js +19 -0
- package/dist/predicates.js.map +1 -0
- package/dist/script-run.d.ts +86 -0
- package/dist/script-run.d.ts.map +1 -0
- package/dist/script-run.js +113 -0
- package/dist/script-run.js.map +1 -0
- package/dist/state.d.ts +176 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +357 -0
- package/dist/state.js.map +1 -0
- package/dist/widgets.d.ts +89 -0
- package/dist/widgets.d.ts.map +1 -0
- package/dist/widgets.js +667 -0
- package/dist/widgets.js.map +1 -0
- package/package.json +55 -0
package/dist/document.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { isInteger, isNonEmptyString, isNumber, isRecord, isString } from "./predicates.js";
|
|
2
|
+
/** Bumped whenever the parser needs a new branch. */
|
|
3
|
+
export const APP_SCHEMA_VERSION = 4;
|
|
4
|
+
/** What a binding runs, normalized — the one place the union is derived. */
|
|
5
|
+
export const operationTarget = (binding) => binding.target ?? workflowTarget(binding);
|
|
6
|
+
/** The implicit workflow target of a binding that names no explicit one. */
|
|
7
|
+
const workflowTarget = (binding) => {
|
|
8
|
+
const target = {
|
|
9
|
+
kind: "workflow",
|
|
10
|
+
workflowId: binding.workflowId
|
|
11
|
+
};
|
|
12
|
+
if (binding.workflowVersion !== undefined) {
|
|
13
|
+
target.workflowVersion = binding.workflowVersion;
|
|
14
|
+
}
|
|
15
|
+
return target;
|
|
16
|
+
};
|
|
17
|
+
/** True when the operation runs a JS script rather than a workflow. */
|
|
18
|
+
export const isScriptOperation = (binding) => operationTarget(binding).kind === "script";
|
|
19
|
+
export const createEmptyPuckData = (title) => ({
|
|
20
|
+
root: { props: title ? { title } : {} },
|
|
21
|
+
content: [],
|
|
22
|
+
zones: {}
|
|
23
|
+
});
|
|
24
|
+
export const createEmptyDocument = (title) => ({
|
|
25
|
+
schemaVersion: APP_SCHEMA_VERSION,
|
|
26
|
+
ui: createEmptyPuckData(title),
|
|
27
|
+
operations: [],
|
|
28
|
+
resources: [],
|
|
29
|
+
variables: []
|
|
30
|
+
});
|
|
31
|
+
const isPuckData = (value) => isRecord(value) && isRecord(value.root) && Array.isArray(value.content);
|
|
32
|
+
/**
|
|
33
|
+
* Parse one input mapping, or null when the entry is not a mapping the union
|
|
34
|
+
* describes: a non-record, an unknown `from`, or a `variable`/`resource`
|
|
35
|
+
* mapping with no id to read. A `constant` keeps whatever `value` it carries,
|
|
36
|
+
* `undefined` included — that is a legitimate constant, and
|
|
37
|
+
* `resolveOperationParams` already omits undefined values from the run params.
|
|
38
|
+
*/
|
|
39
|
+
const parseInputMapping = (value) => {
|
|
40
|
+
if (!isRecord(value))
|
|
41
|
+
return null;
|
|
42
|
+
switch (value.from) {
|
|
43
|
+
case "widget":
|
|
44
|
+
return { from: "widget" };
|
|
45
|
+
case "variable":
|
|
46
|
+
return isNonEmptyString(value.variableId)
|
|
47
|
+
? { from: "variable", variableId: value.variableId }
|
|
48
|
+
: null;
|
|
49
|
+
case "constant":
|
|
50
|
+
return { from: "constant", value: value.value };
|
|
51
|
+
case "resource":
|
|
52
|
+
return isNonEmptyString(value.resourceBindingId)
|
|
53
|
+
? { from: "resource", resourceBindingId: value.resourceBindingId }
|
|
54
|
+
: null;
|
|
55
|
+
default:
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Parse one output mapping, or null when the entry is not a mapping the union
|
|
61
|
+
* describes: a non-record, an unknown `to`, or a `variable` mapping with no id
|
|
62
|
+
* to write.
|
|
63
|
+
*/
|
|
64
|
+
const parseOutputMapping = (value) => {
|
|
65
|
+
if (!isRecord(value))
|
|
66
|
+
return null;
|
|
67
|
+
switch (value.to) {
|
|
68
|
+
case "display":
|
|
69
|
+
return { to: "display" };
|
|
70
|
+
case "variable":
|
|
71
|
+
return isNonEmptyString(value.variableId)
|
|
72
|
+
? { to: "variable", variableId: value.variableId }
|
|
73
|
+
: null;
|
|
74
|
+
default:
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Parse a node-id-keyed mapping record, dropping every entry the mapping
|
|
80
|
+
* parser rejects. A dropped entry leaves the node unmapped, which is the
|
|
81
|
+
* documented default: an input takes its bound widget's value, an output
|
|
82
|
+
* displays. Losing one mapping is contained; rejecting the operation — and
|
|
83
|
+
* with it every other mapping and the widgets bound to it — is not.
|
|
84
|
+
*/
|
|
85
|
+
const parseMappings = (value, parse) => {
|
|
86
|
+
if (!isRecord(value))
|
|
87
|
+
return {};
|
|
88
|
+
const mappings = {};
|
|
89
|
+
for (const [nodeId, entry] of Object.entries(value)) {
|
|
90
|
+
const mapping = parse(entry);
|
|
91
|
+
if (mapping !== null)
|
|
92
|
+
mappings[nodeId] = mapping;
|
|
93
|
+
}
|
|
94
|
+
return mappings;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Parse one operation binding, or null when it carries no id or no workflow id.
|
|
98
|
+
*
|
|
99
|
+
* Every input and output mapping is parsed against its union, never cast:
|
|
100
|
+
* a malformed entry is dropped, so the returned binding's `inputs`/`outputs`
|
|
101
|
+
* only ever hold mappings with the ids their variant requires. That is what
|
|
102
|
+
* lets `resolveOperationParams` and `outputVariableTargets` read
|
|
103
|
+
* `mapping.variableId` without checking it — documents reach this parser from
|
|
104
|
+
* untrusted input (bundle import), and an id-less mapping used to become a
|
|
105
|
+
* read or a write keyed `undefined`.
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* Parse a stored `target`, or null when the entry is not one the union
|
|
109
|
+
* describes. A workflow target is folded back onto `workflowId`, so the two
|
|
110
|
+
* spellings of the same thing produce one binding shape; only a script target
|
|
111
|
+
* survives as a stored `target`.
|
|
112
|
+
*/
|
|
113
|
+
const parseScriptTarget = (value) => {
|
|
114
|
+
if (!isRecord(value) || value.kind !== "script")
|
|
115
|
+
return null;
|
|
116
|
+
const { scriptId, scriptVersion } = value;
|
|
117
|
+
if (!isNonEmptyString(scriptId))
|
|
118
|
+
return null;
|
|
119
|
+
if (!isInteger(scriptVersion)) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return { kind: "script", scriptId, scriptVersion };
|
|
123
|
+
};
|
|
124
|
+
/** The workflow id a stored `target` names, when it names one. */
|
|
125
|
+
const targetWorkflowId = (value) => {
|
|
126
|
+
if (!isRecord(value) || value.kind !== "workflow")
|
|
127
|
+
return null;
|
|
128
|
+
return isString(value.workflowId) ? value.workflowId : null;
|
|
129
|
+
};
|
|
130
|
+
const parseOperation = (value, hostWorkflowId) => {
|
|
131
|
+
if (!isRecord(value))
|
|
132
|
+
return null;
|
|
133
|
+
const { id, name, policy } = value;
|
|
134
|
+
if (!isString(id))
|
|
135
|
+
return null;
|
|
136
|
+
const script = parseScriptTarget(value.target);
|
|
137
|
+
// v3 stored only `workflowId`; v4 may carry an explicit workflow target
|
|
138
|
+
// instead. Either way the workflow id ends up in one place.
|
|
139
|
+
const workflowId = isString(value.workflowId)
|
|
140
|
+
? value.workflowId
|
|
141
|
+
: targetWorkflowId(value.target);
|
|
142
|
+
if (!script && workflowId === null)
|
|
143
|
+
return null;
|
|
144
|
+
const binding = {
|
|
145
|
+
id,
|
|
146
|
+
name: isString(name) ? name : id,
|
|
147
|
+
// A document that ships without a workflow — a template, which has no id
|
|
148
|
+
// until it is installed — binds to whatever workflow hosts it. A script
|
|
149
|
+
// operation binds no workflow at all.
|
|
150
|
+
workflowId: script ? "" : workflowId || hostWorkflowId || "",
|
|
151
|
+
workflowVersion: isNumber(value.workflowVersion)
|
|
152
|
+
? value.workflowVersion
|
|
153
|
+
: undefined,
|
|
154
|
+
inputs: parseMappings(value.inputs, parseInputMapping),
|
|
155
|
+
outputs: parseMappings(value.outputs, parseOutputMapping),
|
|
156
|
+
policy: policy === "parallel" || policy === "queue" ? policy : "replace",
|
|
157
|
+
timeoutMs: isNumber(value.timeoutMs) ? value.timeoutMs : undefined
|
|
158
|
+
};
|
|
159
|
+
if (script) {
|
|
160
|
+
binding.target = script;
|
|
161
|
+
}
|
|
162
|
+
return binding;
|
|
163
|
+
};
|
|
164
|
+
const parseVariable = (value) => {
|
|
165
|
+
if (!isRecord(value))
|
|
166
|
+
return null;
|
|
167
|
+
const { id } = value;
|
|
168
|
+
if (!isNonEmptyString(id))
|
|
169
|
+
return null;
|
|
170
|
+
const scope = value.scope === "user" ? "user" : "instance";
|
|
171
|
+
return {
|
|
172
|
+
id,
|
|
173
|
+
name: isString(value.name) ? value.name : id,
|
|
174
|
+
type: isRecord(value.type) && isString(value.type.type)
|
|
175
|
+
? { type: value.type.type, optional: value.type.optional === true }
|
|
176
|
+
: null,
|
|
177
|
+
default: value.default,
|
|
178
|
+
scope,
|
|
179
|
+
// Only user-scoped variables may persist, whatever the document claims.
|
|
180
|
+
persist: scope === "user" && value.persist === true
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const parseResource = (value) => {
|
|
184
|
+
if (!isRecord(value))
|
|
185
|
+
return null;
|
|
186
|
+
const { id, kind } = value;
|
|
187
|
+
if (!isString(id))
|
|
188
|
+
return null;
|
|
189
|
+
if (kind !== "asset" &&
|
|
190
|
+
kind !== "timeline" &&
|
|
191
|
+
kind !== "storyboard" &&
|
|
192
|
+
kind !== "sketch") {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
const operations = Array.isArray(value.operations)
|
|
196
|
+
? value.operations.filter((op) => op === "read" || op === "create" || op === "update" || op === "delete")
|
|
197
|
+
: ["read"];
|
|
198
|
+
return {
|
|
199
|
+
id,
|
|
200
|
+
name: isString(value.name) ? value.name : id,
|
|
201
|
+
kind,
|
|
202
|
+
scope: isRecord(value.scope)
|
|
203
|
+
? {
|
|
204
|
+
projectId: isString(value.scope.projectId)
|
|
205
|
+
? value.scope.projectId
|
|
206
|
+
: undefined,
|
|
207
|
+
fixedId: isString(value.scope.fixedId)
|
|
208
|
+
? value.scope.fixedId
|
|
209
|
+
: undefined
|
|
210
|
+
}
|
|
211
|
+
: {},
|
|
212
|
+
operations
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
/** The default operation id a migrated single-workflow app gets. */
|
|
216
|
+
export const DEFAULT_OPERATION_ID = "main";
|
|
217
|
+
/**
|
|
218
|
+
* Parse an unknown value into an {@link ApplicationDocument}, or null.
|
|
219
|
+
*
|
|
220
|
+
* Version branching is real: a v1/v2 `{ version, data }` document (the legacy
|
|
221
|
+
* `workflow.app_doc` shape) is lifted into a v3 document with one operation
|
|
222
|
+
* bound to the host workflow. Widget bindings inside `ui` are left as stored —
|
|
223
|
+
* they are resolved to node IDs against the live graph by `resolveBinding`,
|
|
224
|
+
* which is where a missing name becomes a validation error rather than a
|
|
225
|
+
* silent no-op.
|
|
226
|
+
*
|
|
227
|
+
* Everything outside `ui` is parsed, never cast. Malformed operations,
|
|
228
|
+
* variables, and resources are dropped; so is any single input/output mapping
|
|
229
|
+
* that does not match its union, which leaves that node on the documented
|
|
230
|
+
* default (an input reads its widget, an output displays). So a parsed
|
|
231
|
+
* document's mappings always carry the ids their variant requires — the
|
|
232
|
+
* runtimes can read `variableId` and `resourceBindingId` directly.
|
|
233
|
+
*/
|
|
234
|
+
export const parseApplicationDocument = (value, options = {}) => {
|
|
235
|
+
if (!isRecord(value))
|
|
236
|
+
return null;
|
|
237
|
+
// v3+: the native shape.
|
|
238
|
+
if (isPuckData(value.ui)) {
|
|
239
|
+
const schemaVersion = isNumber(value.schemaVersion)
|
|
240
|
+
? value.schemaVersion
|
|
241
|
+
: APP_SCHEMA_VERSION;
|
|
242
|
+
if (schemaVersion > APP_SCHEMA_VERSION)
|
|
243
|
+
return null;
|
|
244
|
+
return {
|
|
245
|
+
schemaVersion: APP_SCHEMA_VERSION,
|
|
246
|
+
ui: value.ui,
|
|
247
|
+
operations: Array.isArray(value.operations)
|
|
248
|
+
? value.operations
|
|
249
|
+
.map((op) => parseOperation(op, options.hostWorkflowId))
|
|
250
|
+
.filter((op) => op !== null)
|
|
251
|
+
: [],
|
|
252
|
+
resources: Array.isArray(value.resources)
|
|
253
|
+
? value.resources
|
|
254
|
+
.map(parseResource)
|
|
255
|
+
.filter((r) => r !== null)
|
|
256
|
+
: [],
|
|
257
|
+
variables: Array.isArray(value.variables)
|
|
258
|
+
? value.variables
|
|
259
|
+
.map(parseVariable)
|
|
260
|
+
.filter((v) => v !== null)
|
|
261
|
+
: [],
|
|
262
|
+
theme: isRecord(value.theme) && isString(value.theme.id)
|
|
263
|
+
? { id: value.theme.id }
|
|
264
|
+
: undefined
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
// v1/v2: `{ version, data }` on `workflow.app_doc`.
|
|
268
|
+
if (isPuckData(value.data)) {
|
|
269
|
+
return {
|
|
270
|
+
schemaVersion: APP_SCHEMA_VERSION,
|
|
271
|
+
ui: value.data,
|
|
272
|
+
operations: options.hostWorkflowId
|
|
273
|
+
? [
|
|
274
|
+
{
|
|
275
|
+
id: DEFAULT_OPERATION_ID,
|
|
276
|
+
name: "Run",
|
|
277
|
+
workflowId: options.hostWorkflowId,
|
|
278
|
+
inputs: {},
|
|
279
|
+
outputs: {},
|
|
280
|
+
policy: "replace"
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
: [],
|
|
284
|
+
resources: [],
|
|
285
|
+
variables: []
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Lift a legacy `workflow.app_doc` into a standalone {@link ApplicationDocument}
|
|
292
|
+
* ready to insert as an application row. Returns null when the workflow carries
|
|
293
|
+
* no document or the stored value cannot be parsed.
|
|
294
|
+
*
|
|
295
|
+
* `app_doc` is stored as JSON text in some databases and as an object in
|
|
296
|
+
* others, so both are accepted. The workflow's id becomes the host id: v1/v2
|
|
297
|
+
* documents get a single operation bound to it, and v3 operations that ship
|
|
298
|
+
* without a workflow (templates, which have no id until installed) bind to it.
|
|
299
|
+
*/
|
|
300
|
+
export const liftLegacyAppDoc = (workflow) => {
|
|
301
|
+
const raw = workflow?.app_doc;
|
|
302
|
+
if (raw === null || raw === undefined || raw === "")
|
|
303
|
+
return null;
|
|
304
|
+
const hostWorkflowId = workflow?.id ?? "";
|
|
305
|
+
let value = raw;
|
|
306
|
+
if (isString(raw)) {
|
|
307
|
+
try {
|
|
308
|
+
value = JSON.parse(raw);
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const document = parseApplicationDocument(value, { hostWorkflowId });
|
|
315
|
+
if (!document)
|
|
316
|
+
return null;
|
|
317
|
+
return {
|
|
318
|
+
...document,
|
|
319
|
+
operations: document.operations.map((op) => op.workflowId || isScriptOperation(op)
|
|
320
|
+
? op
|
|
321
|
+
: { ...op, workflowId: hostWorkflowId })
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
/** True when the document has at least one placed component. */
|
|
325
|
+
export const isRenderableUi = (ui) => Boolean(ui && Array.isArray(ui.content) && ui.content.length > 0);
|
|
326
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,QAAQ,EACT,MAAM,iBAAiB,CAAC;AAkBzB,qDAAqD;AACrD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAU,CAAC;AA2D7C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAA4E,EAC3D,EAAE,CAAC,OAAO,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,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC;YACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,wBAAwB,CAAC,KAAK,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;IACrE,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,OAAO;QACL,GAAG,QAAQ;QACX,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACzC,EAAE,CAAC,UAAU,IAAI,iBAAiB,CAAC,EAAE,CAAC;YACpC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,CAC1C;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,gEAAgE;AAChE,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,EAA+B,EACf,EAAE,CAClB,OAAO,CAAC,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading sketch and timeline refs out of a bound value.
|
|
3
|
+
*
|
|
4
|
+
* A node emits these documents as a ref — `{ type: "sketch", id }` — but the
|
|
5
|
+
* payload can also arrive inline, wrapped in a `document`/`sketch`/`sequence`
|
|
6
|
+
* envelope depending on which node produced it. These helpers unwrap both
|
|
7
|
+
* shapes and describe what they found, so a surface that cannot render the
|
|
8
|
+
* document itself still has something true to show.
|
|
9
|
+
*/
|
|
10
|
+
/** What a widget needs to know about a bound sketch/timeline value. */
|
|
11
|
+
export interface DocumentBinding<TDoc> {
|
|
12
|
+
/** The inline document, when the value carried one. */
|
|
13
|
+
document: TDoc | null;
|
|
14
|
+
/** The persisted document's id, when the value carried one. */
|
|
15
|
+
id: string | null;
|
|
16
|
+
}
|
|
17
|
+
export interface SketchSummary {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
layerCount: number;
|
|
21
|
+
}
|
|
22
|
+
export interface TimelineSummary {
|
|
23
|
+
name: string;
|
|
24
|
+
durationMs: number;
|
|
25
|
+
trackCount: number;
|
|
26
|
+
clipCount: number;
|
|
27
|
+
}
|
|
28
|
+
export declare const isSketchDocumentLike: (value: unknown) => boolean;
|
|
29
|
+
export declare const isTimelineSequenceLike: (value: unknown) => boolean;
|
|
30
|
+
/** Read a bound value as a sketch: its inline document, its id, or neither. */
|
|
31
|
+
export declare const readSketchBinding: (value: unknown) => DocumentBinding<Record<string, unknown>>;
|
|
32
|
+
/** Read a bound value as a timeline: its inline sequence, its id, or neither. */
|
|
33
|
+
export declare const readTimelineBinding: (value: unknown) => DocumentBinding<Record<string, unknown>>;
|
|
34
|
+
export declare const sketchSummary: (document: unknown) => SketchSummary | null;
|
|
35
|
+
export declare const timelineSummary: (document: unknown) => TimelineSummary | null;
|
|
36
|
+
/** `m:ss` for a clip/sequence duration, the form the timeline editor uses. */
|
|
37
|
+
export declare const formatDuration: (ms: number) => string;
|
|
38
|
+
//# sourceMappingURL=documents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../src/documents.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,uEAAuE;AACvE,MAAM,WAAW,eAAe,CAAC,IAAI;IACnC,uDAAuD;IACvD,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,+DAA+D;IAC/D,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AA0CD,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,OAWrD,CAAC;AAEF,eAAO,MAAM,sBAAsB,UAAW,OAAO,KAAG,OAI5B,CAAC;AAE7B,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,UACrB,OAAO,KACb,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAczC,CAAC;AAEF,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,UACvB,OAAO,KACb,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAczC,CAAC;AAEF,eAAO,MAAM,aAAa,aAAc,OAAO,KAAG,aAAa,GAAG,IAWjE,CAAC;AAEF,eAAO,MAAM,eAAe,aAAc,OAAO,KAAG,eAAe,GAAG,IAWrE,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,cAAc,OAAQ,MAAM,KAAG,MAK3C,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading sketch and timeline refs out of a bound value.
|
|
3
|
+
*
|
|
4
|
+
* A node emits these documents as a ref — `{ type: "sketch", id }` — but the
|
|
5
|
+
* payload can also arrive inline, wrapped in a `document`/`sketch`/`sequence`
|
|
6
|
+
* envelope depending on which node produced it. These helpers unwrap both
|
|
7
|
+
* shapes and describe what they found, so a surface that cannot render the
|
|
8
|
+
* document itself still has something true to show.
|
|
9
|
+
*/
|
|
10
|
+
import { isNonEmptyString, isNumber, isRecord, isString } from "./predicates.js";
|
|
11
|
+
/** A bound output holds one value or an accumulated list of streamed items. */
|
|
12
|
+
const lastItem = (value) => Array.isArray(value) ? value[value.length - 1] : value;
|
|
13
|
+
const refId = (value) => {
|
|
14
|
+
if (!isRecord(value)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return isNonEmptyString(value.id) ? value.id : null;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Walk the envelopes a document can arrive in. Depth is bounded because these
|
|
21
|
+
* values come off the wire, where a self-referential object is possible.
|
|
22
|
+
*/
|
|
23
|
+
// HOLDOUT (anti-slop/no-unknown-returns): the walk ends on whatever envelope
|
|
24
|
+
// key held the document, and what a bound output carries is the open
|
|
25
|
+
// workflow-value domain — NodeTool has no named union for it. `isDoc` is the
|
|
26
|
+
// caller's own check on the result.
|
|
27
|
+
const unwrap = (value, keys, refType, isDoc, depth = 0) => {
|
|
28
|
+
if (depth > 4 || isDoc(value) || !isRecord(value)) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
if (key in value) {
|
|
33
|
+
return unwrap(value[key], keys, refType, isDoc, depth + 1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (value.type === refType && "data" in value) {
|
|
37
|
+
return unwrap(value.data, keys, refType, isDoc, depth + 1);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
};
|
|
41
|
+
export const isSketchDocumentLike = (value) => {
|
|
42
|
+
if (!isRecord(value)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const canvas = value.canvas;
|
|
46
|
+
return (isRecord(canvas) &&
|
|
47
|
+
isNumber(canvas.width) &&
|
|
48
|
+
isNumber(canvas.height) &&
|
|
49
|
+
Array.isArray(value.layers));
|
|
50
|
+
};
|
|
51
|
+
export const isTimelineSequenceLike = (value) => isRecord(value) &&
|
|
52
|
+
isNumber(value.durationMs) &&
|
|
53
|
+
Array.isArray(value.tracks) &&
|
|
54
|
+
Array.isArray(value.clips);
|
|
55
|
+
/** Read a bound value as a sketch: its inline document, its id, or neither. */
|
|
56
|
+
export const readSketchBinding = (value) => {
|
|
57
|
+
const bound = lastItem(value);
|
|
58
|
+
const candidate = unwrap(bound, ["document", "sketch"], "sketch", isSketchDocumentLike);
|
|
59
|
+
return {
|
|
60
|
+
document: isSketchDocumentLike(candidate)
|
|
61
|
+
? candidate
|
|
62
|
+
: null,
|
|
63
|
+
id: refId(bound)
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/** Read a bound value as a timeline: its inline sequence, its id, or neither. */
|
|
67
|
+
export const readTimelineBinding = (value) => {
|
|
68
|
+
const bound = lastItem(value);
|
|
69
|
+
const candidate = unwrap(bound, ["sequence", "document", "timeline"], "timeline", isTimelineSequenceLike);
|
|
70
|
+
return {
|
|
71
|
+
document: isTimelineSequenceLike(candidate)
|
|
72
|
+
? candidate
|
|
73
|
+
: null,
|
|
74
|
+
id: refId(bound)
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export const sketchSummary = (document) => {
|
|
78
|
+
if (!isSketchDocumentLike(document)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const doc = document;
|
|
82
|
+
const canvas = doc.canvas;
|
|
83
|
+
return {
|
|
84
|
+
width: canvas.width,
|
|
85
|
+
height: canvas.height,
|
|
86
|
+
layerCount: doc.layers.length
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export const timelineSummary = (document) => {
|
|
90
|
+
if (!isTimelineSequenceLike(document)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const doc = document;
|
|
94
|
+
return {
|
|
95
|
+
name: isString(doc.name) ? doc.name : "",
|
|
96
|
+
durationMs: doc.durationMs,
|
|
97
|
+
trackCount: doc.tracks.length,
|
|
98
|
+
clipCount: doc.clips.length
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/** `m:ss` for a clip/sequence duration, the form the timeline editor uses. */
|
|
102
|
+
export const formatDuration = (ms) => {
|
|
103
|
+
const total = Math.max(0, Math.round(ms / 1000));
|
|
104
|
+
const minutes = Math.floor(total / 60);
|
|
105
|
+
const seconds = total % 60;
|
|
106
|
+
return `${minutes}:${String(seconds).padStart(2, "0")}`;
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=documents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../src/documents.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,QAAQ,EACT,MAAM,iBAAiB,CAAC;AAuBzB,+EAA+E;AAC/E,MAAM,QAAQ,GAAG,CAAQ,KAAsB,EAAqB,EAAE,CACpE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAEzD,MAAM,KAAK,GAAG,CAAC,KAAc,EAAiB,EAAE;IAC9C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACtD,CAAC,CAAC;AAEF;;;GAGG;AACH,6EAA6E;AAC7E,qEAAqE;AACrE,6EAA6E;AAC7E,oCAAoC;AACpC,MAAM,MAAM,GAAG,CACb,KAAc,EACd,IAA2B,EAC3B,OAAe,EACf,KAAsC,EACtC,KAAK,GAAG,CAAC,EACA,EAAE;IACX,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,IAAI,KAAK,EAAE,CAAC;YACjB,OAAO,M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AAC;IACd,CAAC;IACD,MAAM,GAAG,GAAG,QAAmC,CAAC;IAChD,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QACxC,UAAU,EAAE,GAAG,CAAC,UAAoB;QACpC,UAAU,EAAG,GAAG,CAAC,MAAoB,CAAC,MAAM;QAC5C,SAAS,EAAG,GAAG,CAAC,KAAmB,CAAC,MAAM;KAC3C,CAAC;AACJ,CAAC,CAAC;AAEF,8EAA8E;AAC9E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAU,EAAU,EAAE;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,KAAK,GAAG,EAAE,CAAC;IAC3B,OAAO,GAAG,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAC1D,CAAC,CAAC"}
|
package/dist/fold.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The streaming fold: one place that turns a run's processing messages into
|
|
3
|
+
* state events.
|
|
4
|
+
*
|
|
5
|
+
* This used to exist three times — the web runtime, the CLI `app debug`
|
|
6
|
+
* harness, and the eval suites each folded messages their own way, and they
|
|
7
|
+
* drifted. Everything now goes through `messageToEvents`.
|
|
8
|
+
*
|
|
9
|
+
* Messages are matched to an invocation by `job_id`. A message whose job the
|
|
10
|
+
* instance did not start is dropped: that is how a second tab, an overlapping
|
|
11
|
+
* run, or a run started in the graph editor stops contaminating the app's
|
|
12
|
+
* values.
|
|
13
|
+
*
|
|
14
|
+
* A node's value can land in two places at once: the output slot a display
|
|
15
|
+
* widget reads, and — when the operation maps that output `to: "variable"` —
|
|
16
|
+
* an app variable. Both get the same value, streamed chunks accumulating the
|
|
17
|
+
* same way in each.
|
|
18
|
+
*/
|
|
19
|
+
import type { AppStateEvent, InvocationState } from "./state.js";
|
|
20
|
+
export interface FoldContext {
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a message's `job_id` to an invocation this instance owns, or null
|
|
23
|
+
* to drop the message. Implementations may accept an absent `job_id` (an
|
|
24
|
+
* older server that does not stamp it) when only one invocation is live.
|
|
25
|
+
*/
|
|
26
|
+
resolveInvocation: (jobId: string | null | undefined) => InvocationState | null;
|
|
27
|
+
/** The output state key for a node within an operation, or null if unbound. */
|
|
28
|
+
outputKey: (operationId: string, nodeId: string) => string | null;
|
|
29
|
+
/**
|
|
30
|
+
* The variable a node's output writes, or null when it writes none. Built
|
|
31
|
+
* from `outputVariableTargets` of the running operation.
|
|
32
|
+
*/
|
|
33
|
+
outputVariable?: (operationId: string, nodeId: string) => string | null;
|
|
34
|
+
}
|
|
35
|
+
/** Display text for a node/job error, which the kernel sends in several shapes. */
|
|
36
|
+
export declare const errorText: (value: unknown) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Fold one processing message into zero or more state events.
|
|
39
|
+
*
|
|
40
|
+
* `output_update` follows the protocol default: an absent `disposition`
|
|
41
|
+
* appends (older servers omit it on streamed chunks); only an explicit
|
|
42
|
+
* `"replace"` replaces.
|
|
43
|
+
*
|
|
44
|
+
* `tool_call_update`, `planning_update`, and `task_update` carry no value —
|
|
45
|
+
* they become the invocation's activity label, which is all an app can show of
|
|
46
|
+
* an agent's work in progress.
|
|
47
|
+
*/
|
|
48
|
+
export declare const messageToEvents: (message: Record<string, unknown>, ctx: FoldContext) => AppStateEvent[];
|
|
49
|
+
export declare const messagesToEvents: (messages: ReadonlyArray<Record<string, unknown>>, ctx: FoldContext) => AppStateEvent[];
|
|
50
|
+
//# sourceMappingURL=fold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fold.d.ts","sourceRoot":"","sources":["../src/fold.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAe,eAAe,EAAE,MAAM,YAAY,CAAC;AAG9E,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,iBAAiB,EAAE,CACjB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,KAC7B,eAAe,GAAG,IAAI,CAAC;IAC5B,+EAA+E;IAC/E,SAAS,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IAClE;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACzE;AAKD,mFAAmF;AACnF,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,MAc1C,CAAC;AA6EF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,YACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAC3B,WAAW,KACf,aAAa,EAoGf,CAAC;AAEF,eAAO,MAAM,gBAAgB,aACjB,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,OAC3C,WAAW,KACf,aAAa,EAC8C,CAAC"}
|