@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/fold.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { isNumber, isObjectLike, isString } from "./predicates.js";
|
|
2
|
+
const str = (value) => isString(value) ? value : value == null ? "" : String(value);
|
|
3
|
+
/** Display text for a node/job error, which the kernel sends in several shapes. */
|
|
4
|
+
export const errorText = (value) => {
|
|
5
|
+
if (value == null)
|
|
6
|
+
return "";
|
|
7
|
+
if (isString(value))
|
|
8
|
+
return value.trim();
|
|
9
|
+
if (value instanceof Error)
|
|
10
|
+
return value.message;
|
|
11
|
+
if (isObjectLike(value)) {
|
|
12
|
+
const record = value;
|
|
13
|
+
for (const field of ["message", "error", "detail"]) {
|
|
14
|
+
const candidate = record[field];
|
|
15
|
+
if (isString(candidate) && candidate.trim() !== "") {
|
|
16
|
+
return candidate.trim();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return "";
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Fan one node value out to whatever it is wired to: the display slot, the
|
|
24
|
+
* variable, or both. Neither wired means the message carries nothing this app
|
|
25
|
+
* shows.
|
|
26
|
+
*/
|
|
27
|
+
const valueEvents = (ctx, invocation, nodeId, value, disposition, done) => {
|
|
28
|
+
const key = ctx.outputKey(invocation.operationId, nodeId);
|
|
29
|
+
const variableId = ctx.outputVariable?.(invocation.operationId, nodeId) ?? null;
|
|
30
|
+
const events = [];
|
|
31
|
+
if (key) {
|
|
32
|
+
events.push({
|
|
33
|
+
type: "outputValue",
|
|
34
|
+
key,
|
|
35
|
+
invocationId: invocation.id,
|
|
36
|
+
value,
|
|
37
|
+
disposition,
|
|
38
|
+
done
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (variableId) {
|
|
42
|
+
events.push({
|
|
43
|
+
type: "setVariable",
|
|
44
|
+
variableId,
|
|
45
|
+
value,
|
|
46
|
+
disposition,
|
|
47
|
+
invocationId: invocation.id
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return events;
|
|
51
|
+
};
|
|
52
|
+
/** A short human-readable label for what a streaming run is doing right now. */
|
|
53
|
+
const activityLabel = (type, message) => {
|
|
54
|
+
switch (type) {
|
|
55
|
+
case "tool_call_update": {
|
|
56
|
+
const note = str(message.message).trim();
|
|
57
|
+
return note || str(message.name).trim();
|
|
58
|
+
}
|
|
59
|
+
case "planning_update": {
|
|
60
|
+
const phase = str(message.phase).trim();
|
|
61
|
+
const status = str(message.status).trim();
|
|
62
|
+
return phase && status ? `${phase}: ${status}` : phase || status;
|
|
63
|
+
}
|
|
64
|
+
case "task_update": {
|
|
65
|
+
const step = message.step;
|
|
66
|
+
const task = message.task;
|
|
67
|
+
const stepName = str(step?.name).trim();
|
|
68
|
+
const taskTitle = str(task?.title).trim() || str(task?.name).trim();
|
|
69
|
+
if (stepName && taskTitle)
|
|
70
|
+
return `${taskTitle}: ${stepName}`;
|
|
71
|
+
return stepName || taskTitle || str(message.event).replace(/_/g, " ");
|
|
72
|
+
}
|
|
73
|
+
default:
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const TERMINAL_JOB_STATUS = {
|
|
78
|
+
completed: "completed",
|
|
79
|
+
failed: "failed",
|
|
80
|
+
cancelled: "cancelled",
|
|
81
|
+
timed_out: "failed",
|
|
82
|
+
error: "failed"
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Fold one processing message into zero or more state events.
|
|
86
|
+
*
|
|
87
|
+
* `output_update` follows the protocol default: an absent `disposition`
|
|
88
|
+
* appends (older servers omit it on streamed chunks); only an explicit
|
|
89
|
+
* `"replace"` replaces.
|
|
90
|
+
*
|
|
91
|
+
* `tool_call_update`, `planning_update`, and `task_update` carry no value —
|
|
92
|
+
* they become the invocation's activity label, which is all an app can show of
|
|
93
|
+
* an agent's work in progress.
|
|
94
|
+
*/
|
|
95
|
+
export const messageToEvents = (message, ctx) => {
|
|
96
|
+
const type = message.type;
|
|
97
|
+
if (!isString(type))
|
|
98
|
+
return [];
|
|
99
|
+
const invocation = ctx.resolveInvocation(isString(message.job_id) ? message.job_id : null);
|
|
100
|
+
if (!invocation)
|
|
101
|
+
return [];
|
|
102
|
+
switch (type) {
|
|
103
|
+
case "output_update":
|
|
104
|
+
return valueEvents(ctx, invocation, str(message.node_id), message.value, message.disposition === "replace" ? "replace" : "append", message.done === true);
|
|
105
|
+
case "chunk": {
|
|
106
|
+
// Only text chunks fold into a display value; audio/video chunks are
|
|
107
|
+
// consumed by their own players.
|
|
108
|
+
if (message.content_type && message.content_type !== "text")
|
|
109
|
+
return [];
|
|
110
|
+
return valueEvents(ctx, invocation, str(message.node_id), str(message.content), "append", message.done === true);
|
|
111
|
+
}
|
|
112
|
+
case "node_progress": {
|
|
113
|
+
const { progress, total } = message;
|
|
114
|
+
const hasRatio = isNumber(progress) && isNumber(total) && total > 0;
|
|
115
|
+
return [
|
|
116
|
+
{
|
|
117
|
+
type: "invocationProgress",
|
|
118
|
+
invocationId: invocation.id,
|
|
119
|
+
progress: hasRatio ? progress / total : undefined
|
|
120
|
+
}
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
case "node_update": {
|
|
124
|
+
const error = errorText(message.error);
|
|
125
|
+
if (!error)
|
|
126
|
+
return [];
|
|
127
|
+
return [{ type: "invocationError", invocationId: invocation.id, error }];
|
|
128
|
+
}
|
|
129
|
+
case "error": {
|
|
130
|
+
const error = errorText(message.message) || errorText(message.error);
|
|
131
|
+
if (!error)
|
|
132
|
+
return [];
|
|
133
|
+
return [{ type: "invocationError", invocationId: invocation.id, error }];
|
|
134
|
+
}
|
|
135
|
+
case "tool_call_update":
|
|
136
|
+
case "planning_update":
|
|
137
|
+
case "task_update": {
|
|
138
|
+
const label = activityLabel(type, message);
|
|
139
|
+
if (!label)
|
|
140
|
+
return [];
|
|
141
|
+
return [
|
|
142
|
+
{ type: "invocationActivity", invocationId: invocation.id, label }
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
case "job_update": {
|
|
146
|
+
const status = str(message.status);
|
|
147
|
+
const mapped = TERMINAL_JOB_STATUS[status];
|
|
148
|
+
if (!mapped) {
|
|
149
|
+
return status === "running"
|
|
150
|
+
? [
|
|
151
|
+
{
|
|
152
|
+
type: "invocationStatus",
|
|
153
|
+
invocationId: invocation.id,
|
|
154
|
+
status: "running"
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
: [];
|
|
158
|
+
}
|
|
159
|
+
const error = errorText(message.error);
|
|
160
|
+
const statusEffect = {
|
|
161
|
+
type: "invocationStatus",
|
|
162
|
+
invocationId: invocation.id,
|
|
163
|
+
status: mapped
|
|
164
|
+
};
|
|
165
|
+
if (error) {
|
|
166
|
+
statusEffect.error = error;
|
|
167
|
+
}
|
|
168
|
+
return [statusEffect];
|
|
169
|
+
}
|
|
170
|
+
default:
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
export const messagesToEvents = (messages, ctx) => messages.flatMap((message) => messageToEvents(message, ctx));
|
|
175
|
+
//# sourceMappingURL=fold.js.map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,MAAM,YAAY,GAAuB;gBACvC,IAAI,EAAE,kBAAkB;gBACxB,YAAY,EAAE,UAAU,CAAC,EAAE;gBAC3B,MAAM,EAAE,MAAM;aACf,CAAC;YACF,IAAI,KAAK,EAAE,CAAC;gBACV,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;YAC7B,CAAC;YACD,OAAO,CAAC,YAAY,CAAC,CAAC;QACxB,CAAC;QAED;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,QAAgD,EAChD,GAAgB,EACC,EAAE,CACnB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-independent runtime core for NodeTool mini apps.
|
|
3
|
+
*
|
|
4
|
+
* An application is a UI document plus typed bindings to workflow operations
|
|
5
|
+
* and resources. All computation stays in workflow graphs; the only logic this
|
|
6
|
+
* layer holds is a closed vocabulary of widget props. This package owns the
|
|
7
|
+
* shared semantics — document parsing, binding resolution, instance state, the
|
|
8
|
+
* streaming fold, run policy, conditions, and the widget catalog — so the web
|
|
9
|
+
* runtime, the CLI `app debug` harness, and the eval suites cannot drift apart.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./document.js";
|
|
12
|
+
export * from "./bindings.js";
|
|
13
|
+
export * from "./state.js";
|
|
14
|
+
export * from "./operations.js";
|
|
15
|
+
export * from "./fold.js";
|
|
16
|
+
export * from "./policy.js";
|
|
17
|
+
export * from "./conditions.js";
|
|
18
|
+
export * from "./actions.js";
|
|
19
|
+
export * from "./widgets.js";
|
|
20
|
+
export * from "./chat.js";
|
|
21
|
+
export * from "./documents.js";
|
|
22
|
+
export * from "./doc-ops.js";
|
|
23
|
+
export * from "./bundle.js";
|
|
24
|
+
export * from "./script-run.js";
|
|
25
|
+
export * from "./input-validation.js";
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-independent runtime core for NodeTool mini apps.
|
|
3
|
+
*
|
|
4
|
+
* An application is a UI document plus typed bindings to workflow operations
|
|
5
|
+
* and resources. All computation stays in workflow graphs; the only logic this
|
|
6
|
+
* layer holds is a closed vocabulary of widget props. This package owns the
|
|
7
|
+
* shared semantics — document parsing, binding resolution, instance state, the
|
|
8
|
+
* streaming fold, run policy, conditions, and the widget catalog — so the web
|
|
9
|
+
* runtime, the CLI `app debug` harness, and the eval suites cannot drift apart.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./document.js";
|
|
12
|
+
export * from "./bindings.js";
|
|
13
|
+
export * from "./state.js";
|
|
14
|
+
export * from "./operations.js";
|
|
15
|
+
export * from "./fold.js";
|
|
16
|
+
export * from "./policy.js";
|
|
17
|
+
export * from "./conditions.js";
|
|
18
|
+
export * from "./actions.js";
|
|
19
|
+
export * from "./widgets.js";
|
|
20
|
+
export * from "./chat.js";
|
|
21
|
+
export * from "./documents.js";
|
|
22
|
+
export * from "./doc-ops.js";
|
|
23
|
+
export * from "./bundle.js";
|
|
24
|
+
export * from "./script-run.js";
|
|
25
|
+
export * from "./input-validation.js";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Input admission shared by browser and headless app runtimes. */
|
|
2
|
+
/** True when a required media input has no usable value to send. */
|
|
3
|
+
export declare const isMissingRequiredMediaValue: (nodeType: string, value: unknown) => boolean;
|
|
4
|
+
//# sourceMappingURL=input-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-validation.d.ts","sourceRoot":"","sources":["../src/input-validation.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAuBnE,oEAAoE;AACpE,eAAO,MAAM,2BAA2B,aAC5B,MAAM,SACT,OAAO,KACb,OAAyE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Input admission shared by browser and headless app runtimes. */
|
|
2
|
+
import { isRecord, isString } from "./predicates.js";
|
|
3
|
+
const REQUIRED_MEDIA_NODE_TYPES = new Set([
|
|
4
|
+
"nodetool.input.ImageInput",
|
|
5
|
+
"nodetool.input.ImageListInput",
|
|
6
|
+
"nodetool.input.VideoInput",
|
|
7
|
+
"nodetool.input.VideoListInput",
|
|
8
|
+
"nodetool.input.AudioInput",
|
|
9
|
+
"nodetool.input.AudioListInput",
|
|
10
|
+
"nodetool.input.RealtimeAudioInput",
|
|
11
|
+
"nodetool.input.DocumentInput"
|
|
12
|
+
]);
|
|
13
|
+
const isEmptyValue = (value) => {
|
|
14
|
+
if (value == null)
|
|
15
|
+
return true;
|
|
16
|
+
if (isString(value))
|
|
17
|
+
return value.trim().length === 0;
|
|
18
|
+
if (Array.isArray(value))
|
|
19
|
+
return value.length === 0;
|
|
20
|
+
if (isRecord(value))
|
|
21
|
+
return Object.keys(value).length === 0;
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
/** True when a required media input has no usable value to send. */
|
|
25
|
+
export const isMissingRequiredMediaValue = (nodeType, value) => REQUIRED_MEDIA_NODE_TYPES.has(nodeType) && isEmptyValue(value);
|
|
26
|
+
//# sourceMappingURL=input-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-validation.js","sourceRoot":"","sources":["../src/input-validation.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAErD,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC;IACxC,2BAA2B;IAC3B,+BAA+B;IAC/B,2BAA2B;IAC3B,+BAA+B;IAC/B,2BAA2B;IAC3B,+BAA+B;IAC/B,mCAAmC;IACnC,8BAA8B;CAC/B,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,CAAC,KAAc,EAAW,EAAE;IAC/C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,IAAI,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC;IACtD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACpD,IAAI,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,oEAAoE;AACpE,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,QAAgB,EAChB,KAAc,EACL,EAAE,CAAC,yBAAyB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The same shape with its `readonly` modifiers dropped, so an object can be
|
|
3
|
+
* built one property at a time and the optional ones left out entirely.
|
|
4
|
+
*/
|
|
5
|
+
export type Mutable<T> = {
|
|
6
|
+
-readonly [K in keyof T]: T[K];
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=mutable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutable.d.ts","sourceRoot":"","sources":["../src/mutable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC"}
|
package/dist/mutable.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutable.js","sourceRoot":"","sources":["../src/mutable.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning an operation binding into a run.
|
|
3
|
+
*
|
|
4
|
+
* Bindings key on node IDs; the run protocol wants a name-keyed `params`
|
|
5
|
+
* object. That translation happens here, at the execution boundary, which is
|
|
6
|
+
* exactly why a graph rename never reaches the app document.
|
|
7
|
+
*/
|
|
8
|
+
import type { OperationBinding, ResourceRef, VariableDeclaration } from "./document.js";
|
|
9
|
+
import type { AppInstanceState } from "./state.js";
|
|
10
|
+
export interface ResolveParamsContext {
|
|
11
|
+
operation: OperationBinding;
|
|
12
|
+
state: AppInstanceState;
|
|
13
|
+
/** Input node id → the name the run protocol expects for it. */
|
|
14
|
+
inputName: (nodeId: string) => string | undefined;
|
|
15
|
+
/** Node ids of the operation's inputs, in graph order. */
|
|
16
|
+
inputNodeIds: ReadonlyArray<string>;
|
|
17
|
+
/** The resource a binding currently points at, when one is selected. */
|
|
18
|
+
resourceRef?: (resourceBindingId: string) => ResourceRef | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build the name-keyed `params` for one operation's run. An input with no
|
|
22
|
+
* explicit mapping takes the bound widget's value, which is the common case
|
|
23
|
+
* and what a legacy single-operation app does for every input.
|
|
24
|
+
*/
|
|
25
|
+
export declare const resolveOperationParams: (ctx: ResolveParamsContext) => Record<string, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Where an operation's outputs land. An output mapped `to: "variable"` writes
|
|
28
|
+
* app state — that is how "run analysis, let the user review, then publish"
|
|
29
|
+
* works without a procedure language: operation A writes a variable, a display
|
|
30
|
+
* widget shows it, and operation B reads it.
|
|
31
|
+
*/
|
|
32
|
+
export declare const outputVariableTargets: (operation: OperationBinding) => Array<{
|
|
33
|
+
nodeId: string;
|
|
34
|
+
variableId: string;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* The declared defaults an instance starts from: variable id → `default`, for
|
|
38
|
+
* every variable that declares one. Feed it to the `seedVariables` event, which
|
|
39
|
+
* never clobbers — so a restored user-scoped value, seeded first, wins over the
|
|
40
|
+
* document's default.
|
|
41
|
+
*/
|
|
42
|
+
export declare const initialVariableValues: (variables: ReadonlyArray<VariableDeclaration>) => Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* The operation a legacy single-workflow app runs: every input takes its bound
|
|
45
|
+
* widget's value, every output displays. Lets one code path serve both a
|
|
46
|
+
* document with explicit operations and one imported from `workflow.app_doc`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const implicitOperation: (workflowId: string) => OperationBinding;
|
|
49
|
+
/** Variables a document declares, plus the SetVariable channels a graph publishes. */
|
|
50
|
+
export declare const mergeVariables: (declared: ReadonlyArray<VariableDeclaration>, channelNames: ReadonlyArray<string>) => VariableDeclaration[];
|
|
51
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,gBAAgB,CAAC;IAC5B,KAAK,EAAE,gBAAgB,CAAC;IACxB,gEAAgE;IAChE,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAClD,0DAA0D;IAC1D,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,wEAAwE;IACxE,WAAW,CAAC,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;CACtE;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAC5B,oBAAoB,4BAoC1B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,cACrB,gBAAgB,KAC1B,KAAK,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAK5C,CAAC;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,cACrB,aAAa,CAAC,mBAAmB,CAAC,4BAQ9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,gBAOrD,CAAC;AAEH,sFAAsF;AACtF,eAAO,MAAM,cAAc,aACf,aAAa,CAAC,mBAAmB,CAAC,gBAC9B,aAAa,CAAC,MAAM,CAAC,KAClC,mBAAmB,EAarB,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { DEFAULT_OPERATION_ID } from "./document.js";
|
|
2
|
+
import { stateKey } from "./bindings.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build the name-keyed `params` for one operation's run. An input with no
|
|
5
|
+
* explicit mapping takes the bound widget's value, which is the common case
|
|
6
|
+
* and what a legacy single-operation app does for every input.
|
|
7
|
+
*/
|
|
8
|
+
export const resolveOperationParams = (ctx) => {
|
|
9
|
+
const { operation, state } = ctx;
|
|
10
|
+
const params = {};
|
|
11
|
+
for (const nodeId of ctx.inputNodeIds) {
|
|
12
|
+
const name = ctx.inputName(nodeId);
|
|
13
|
+
if (!name)
|
|
14
|
+
continue;
|
|
15
|
+
const mapping = operation.inputs[nodeId] ?? { from: "widget" };
|
|
16
|
+
let value;
|
|
17
|
+
switch (mapping.from) {
|
|
18
|
+
case "variable":
|
|
19
|
+
value = state.variables[mapping.variableId];
|
|
20
|
+
break;
|
|
21
|
+
case "constant":
|
|
22
|
+
value = mapping.value;
|
|
23
|
+
break;
|
|
24
|
+
case "resource":
|
|
25
|
+
value = ctx.resourceRef?.(mapping.resourceBindingId);
|
|
26
|
+
break;
|
|
27
|
+
case "widget":
|
|
28
|
+
default:
|
|
29
|
+
value =
|
|
30
|
+
state.inputs[stateKey({
|
|
31
|
+
kind: "input",
|
|
32
|
+
operationId: operation.id,
|
|
33
|
+
nodeId
|
|
34
|
+
})]?.value;
|
|
35
|
+
}
|
|
36
|
+
if (value !== undefined)
|
|
37
|
+
params[name] = value;
|
|
38
|
+
}
|
|
39
|
+
return params;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Where an operation's outputs land. An output mapped `to: "variable"` writes
|
|
43
|
+
* app state — that is how "run analysis, let the user review, then publish"
|
|
44
|
+
* works without a procedure language: operation A writes a variable, a display
|
|
45
|
+
* widget shows it, and operation B reads it.
|
|
46
|
+
*/
|
|
47
|
+
export const outputVariableTargets = (operation) => Object.entries(operation.outputs).flatMap(([nodeId, mapping]) => mapping.to === "variable"
|
|
48
|
+
? [{ nodeId, variableId: mapping.variableId }]
|
|
49
|
+
: []);
|
|
50
|
+
/**
|
|
51
|
+
* The declared defaults an instance starts from: variable id → `default`, for
|
|
52
|
+
* every variable that declares one. Feed it to the `seedVariables` event, which
|
|
53
|
+
* never clobbers — so a restored user-scoped value, seeded first, wins over the
|
|
54
|
+
* document's default.
|
|
55
|
+
*/
|
|
56
|
+
export const initialVariableValues = (variables) => {
|
|
57
|
+
const values = {};
|
|
58
|
+
for (const variable of variables) {
|
|
59
|
+
if (variable.default === undefined)
|
|
60
|
+
continue;
|
|
61
|
+
values[variable.id] = variable.default;
|
|
62
|
+
}
|
|
63
|
+
return values;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The operation a legacy single-workflow app runs: every input takes its bound
|
|
67
|
+
* widget's value, every output displays. Lets one code path serve both a
|
|
68
|
+
* document with explicit operations and one imported from `workflow.app_doc`.
|
|
69
|
+
*/
|
|
70
|
+
export const implicitOperation = (workflowId) => ({
|
|
71
|
+
id: DEFAULT_OPERATION_ID,
|
|
72
|
+
name: "Run",
|
|
73
|
+
workflowId,
|
|
74
|
+
inputs: {},
|
|
75
|
+
outputs: {},
|
|
76
|
+
policy: "replace"
|
|
77
|
+
});
|
|
78
|
+
/** Variables a document declares, plus the SetVariable channels a graph publishes. */
|
|
79
|
+
export const mergeVariables = (declared, channelNames) => {
|
|
80
|
+
const byId = new Map(declared.map((v) => [v.id, v]));
|
|
81
|
+
for (const name of channelNames) {
|
|
82
|
+
if (byId.has(name))
|
|
83
|
+
continue;
|
|
84
|
+
if (declared.some((v) => v.name === name))
|
|
85
|
+
continue;
|
|
86
|
+
byId.set(name, {
|
|
87
|
+
id: name,
|
|
88
|
+
name,
|
|
89
|
+
scope: "instance",
|
|
90
|
+
persist: false
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return [...byId.values()];
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAczC;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,GAAyB,EACzB,EAAE;IACF,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;IACjC,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,QAAiB,EAAE,CAAC;QAExE,IAAI,KAAc,CAAC;QACnB,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,KAAK,UAAU;gBACb,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAC5C,MAAM;YACR,KAAK,UAAU;gBACb,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;gBACtB,MAAM;YACR,KAAK,UAAU;gBACb,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;gBACrD,MAAM;YACR,KAAK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IACX,MAAM,EAAE,SAAS;CAClB,CAAC,CAAC;AAEH,sFAAsF;AACtF,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,QAA4C,EAC5C,YAAmC,EACZ,EAAE;IACzB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,SAAS;QAC7B,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;YAAE,SAAS;QACpD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YACb,EAAE,EAAE,IAAI;YACR,IAAI;YACJ,KAAK,EAAE,UAAU;YACjB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAC5B,CAAC,CAAC"}
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to do when an operation is asked to run while it is already running.
|
|
3
|
+
*
|
|
4
|
+
* The document declares the intent (`OperationPolicy`); this decides, against
|
|
5
|
+
* the live invocations, what the caller must do first. It stays pure: the
|
|
6
|
+
* runtime owns cancelling and awaiting, this only says which invocations those
|
|
7
|
+
* verbs apply to.
|
|
8
|
+
*/
|
|
9
|
+
import type { OperationBinding } from "./document.js";
|
|
10
|
+
import type { AppInstanceState } from "./state.js";
|
|
11
|
+
export type RunDecision = {
|
|
12
|
+
kind: "start";
|
|
13
|
+
}
|
|
14
|
+
/** Cancel these invocations, then start. */
|
|
15
|
+
| {
|
|
16
|
+
kind: "replace";
|
|
17
|
+
cancel: string[];
|
|
18
|
+
}
|
|
19
|
+
/** Wait for these invocations to settle, then start. */
|
|
20
|
+
| {
|
|
21
|
+
kind: "queue";
|
|
22
|
+
after: string[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* With nothing in flight every policy starts immediately — the policy only
|
|
26
|
+
* describes the collision.
|
|
27
|
+
*/
|
|
28
|
+
export declare const decideRun: (state: AppInstanceState, operation: OperationBinding) => RunDecision;
|
|
29
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE;AACnB,4CAA4C;GAC1C;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE;AACvC,wDAAwD;GACtD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,SAAS,UACb,gBAAgB,aACZ,gBAAgB,KAC1B,WASF,CAAC"}
|
package/dist/policy.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { liveInvocations } from "./state.js";
|
|
2
|
+
/**
|
|
3
|
+
* With nothing in flight every policy starts immediately — the policy only
|
|
4
|
+
* describes the collision.
|
|
5
|
+
*/
|
|
6
|
+
export const decideRun = (state, operation) => {
|
|
7
|
+
if (operation.policy === "parallel")
|
|
8
|
+
return { kind: "start" };
|
|
9
|
+
const live = liveInvocations(state, operation.id).map((i) => i.id);
|
|
10
|
+
if (live.length === 0)
|
|
11
|
+
return { kind: "start" };
|
|
12
|
+
return operation.policy === "queue"
|
|
13
|
+
? { kind: "queue", after: live }
|
|
14
|
+
: { kind: "replace", cancel: live };
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAS7C;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAuB,EACvB,SAA2B,EACd,EAAE;IACf,IAAI,SAAS,CAAC,MAAM,KAAK,UAAU;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAE9D,MAAM,IAAI,GAAG,eAAe,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACnE,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAEhD,OAAO,SAAS,CAAC,MAAM,KAAK,OAAO;QACjC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE;QAChC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AACxC,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named type predicates for the representation checks the app runtime makes on
|
|
3
|
+
* stored application documents, which arrive as unparsed JSON.
|
|
4
|
+
*
|
|
5
|
+
* These duplicate `@nodetool-ai/protocol`'s definitions on purpose: this
|
|
6
|
+
* package declares no dependencies so mobile's Metro bundler can compile it
|
|
7
|
+
* from source. Keep the semantics identical to protocol's.
|
|
8
|
+
*/
|
|
9
|
+
export declare const isString: (value: unknown) => value is string;
|
|
10
|
+
/** An id or name that is present — an empty string names nothing. */
|
|
11
|
+
export declare const isNonEmptyString: (value: unknown) => value is string;
|
|
12
|
+
export declare const isNumber: (value: unknown) => value is number;
|
|
13
|
+
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
14
|
+
export declare const isInteger: (value: unknown) => value is number;
|
|
15
|
+
export declare const isCallable: (value: unknown) => value is (...args: never[]) => void;
|
|
16
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
17
|
+
/** Anything `typeof` calls an object, `null` aside — an array passes. */
|
|
18
|
+
export declare const isObjectLike: (value: unknown) => value is Record<string, unknown>;
|
|
19
|
+
//# sourceMappingURL=predicates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MACxB,CAAC;AAE5B,qEAAqE;AACrE,eAAO,MAAM,gBAAgB,UAAW,OAAO,KAAG,KAAK,IAAI,MACZ,CAAC;AAEhD,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MACxB,CAAC;AAE5B,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,KAAK,IAAI,OACxB,CAAC;AAE7B,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,KAAK,IAAI,MACE,CAAC;AAEvD,eAAO,MAAM,UAAU,UACd,OAAO,KACb,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,IAAmC,CAAC;AAEtE,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACH,CAAC;AAEvE,yEAAyE;AACzE,eAAO,MAAM,YAAY,UAChB,OAAO,KACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACW,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named type predicates for the representation checks the app runtime makes on
|
|
3
|
+
* stored application documents, which arrive as unparsed JSON.
|
|
4
|
+
*
|
|
5
|
+
* These duplicate `@nodetool-ai/protocol`'s definitions on purpose: this
|
|
6
|
+
* package declares no dependencies so mobile's Metro bundler can compile it
|
|
7
|
+
* from source. Keep the semantics identical to protocol's.
|
|
8
|
+
*/
|
|
9
|
+
export const isString = (value) => typeof value === "string";
|
|
10
|
+
/** An id or name that is present — an empty string names nothing. */
|
|
11
|
+
export const isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
|
|
12
|
+
export const isNumber = (value) => typeof value === "number";
|
|
13
|
+
export const isBoolean = (value) => typeof value === "boolean";
|
|
14
|
+
export const isInteger = (value) => typeof value === "number" && Number.isInteger(value);
|
|
15
|
+
export const isCallable = (value) => typeof value === "function";
|
|
16
|
+
export const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
/** Anything `typeof` calls an object, `null` aside — an array passes. */
|
|
18
|
+
export const isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
19
|
+
//# sourceMappingURL=predicates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAC1D,OAAO,KAAK,KAAK,QAAQ,CAAC;AAE5B,qEAAqE;AACrE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAmB,EAAE,CAClE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAEhD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAC1D,OAAO,KAAK,KAAK,QAAQ,CAAC;AAE5B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAoB,EAAE,CAC5D,OAAO,KAAK,KAAK,SAAS,CAAC;AAE7B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAmB,EAAE,CAC3D,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAc,EACuB,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC;AAEtE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAC3E,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,yEAAyE;AACzE,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAAc,EACoB,EAAE,CACpC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC"}
|