@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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The script-operation execution contract, shared by every host.
|
|
3
|
+
*
|
|
4
|
+
* A mini-app operation can run a JS script instead of a workflow. A script has
|
|
5
|
+
* no graph, so two things have to be manufactured: the bindable surface the
|
|
6
|
+
* binding layer resolves names against (its declared ports, which are its
|
|
7
|
+
* stable identifiers — a script has no node ids), and the message stream the
|
|
8
|
+
* fold consumes, because the run endpoint answers with plain JSON rather than
|
|
9
|
+
* streaming.
|
|
10
|
+
*
|
|
11
|
+
* Both live here, above the browser and above the simulator, so the two hosts
|
|
12
|
+
* cannot fold one script run two different ways. This package carries no
|
|
13
|
+
* dependencies, so the script document is typed structurally and the one fact
|
|
14
|
+
* that needs a parser — whether the body reads its inputs through `stream` —
|
|
15
|
+
* arrives as a flag from the caller.
|
|
16
|
+
*/
|
|
17
|
+
/** One declared port. `type` is a TypeMetadata name (`"str"`, `"list[str]"`). */
|
|
18
|
+
export interface ScriptPort {
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
}
|
|
22
|
+
/** The fields of a JS script document an app operation reads. */
|
|
23
|
+
export interface ScriptOperationDocument {
|
|
24
|
+
inputs: ScriptPort[];
|
|
25
|
+
outputs: ScriptPort[];
|
|
26
|
+
}
|
|
27
|
+
/** What one script run returned — the body `POST /api/js-scripts/:id/run` answers with. */
|
|
28
|
+
export interface ScriptRunResult {
|
|
29
|
+
ok: boolean;
|
|
30
|
+
outputs?: Record<string, unknown>;
|
|
31
|
+
/** `{name, value}` entries under the emit contract, in call order. */
|
|
32
|
+
streamed?: unknown[];
|
|
33
|
+
logs: string[];
|
|
34
|
+
error?: string;
|
|
35
|
+
duration_ms: number;
|
|
36
|
+
}
|
|
37
|
+
/** How one invocation's mapped values reach the body. */
|
|
38
|
+
export interface ScriptInvocationInput {
|
|
39
|
+
inputs: Record<string, unknown>;
|
|
40
|
+
/** Items staged per handle for a body that reads `stream`. */
|
|
41
|
+
inputStreams?: Record<string, unknown[]>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Split an operation's mapped values the way the body reads them.
|
|
45
|
+
*
|
|
46
|
+
* An app operation is one shot: a widget holds one value per input, not a
|
|
47
|
+
* stream of them. A body that reads `stream` still has to be fed through the
|
|
48
|
+
* inbox, so each mapped value is staged as a one-item stream and `inputs` stays
|
|
49
|
+
* empty — the split a graph run makes, where a connected handle is reachable
|
|
50
|
+
* through `stream` and never through `inputs`. A buffered body is untouched.
|
|
51
|
+
*/
|
|
52
|
+
export declare function scriptInvocationInput(inputs: Record<string, unknown>, usesStreamInputs: boolean): ScriptInvocationInput;
|
|
53
|
+
/**
|
|
54
|
+
* The message stream a script run would have produced: its emits in order,
|
|
55
|
+
* then its final outputs, then the job's terminal status.
|
|
56
|
+
*
|
|
57
|
+
* Emits append (they are one output handle streaming), finals replace and mark
|
|
58
|
+
* the handle done — the same dispositions the kernel sends for a streaming
|
|
59
|
+
* node followed by its final bag. A `jobId` stamps every message, because the
|
|
60
|
+
* fold resolves a message to its invocation by job id.
|
|
61
|
+
*/
|
|
62
|
+
export declare function scriptRunMessages(result: ScriptRunResult, jobId?: string): Array<Record<string, unknown>>;
|
|
63
|
+
/** A script port as the binding layer sees it: the name stands in for a node id. */
|
|
64
|
+
export interface ScriptPortIO {
|
|
65
|
+
nodeId: string;
|
|
66
|
+
nodeType: string;
|
|
67
|
+
name: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A script's bindable surface. Port names stand in for node ids: a script
|
|
71
|
+
* declares no nodes, and its port names are what every mapping already keys on.
|
|
72
|
+
*/
|
|
73
|
+
export declare function scriptPortIO(document: ScriptOperationDocument): {
|
|
74
|
+
inputs: {
|
|
75
|
+
nodeId: string;
|
|
76
|
+
nodeType: string;
|
|
77
|
+
name: string;
|
|
78
|
+
}[];
|
|
79
|
+
outputs: {
|
|
80
|
+
nodeId: string;
|
|
81
|
+
nodeType: string;
|
|
82
|
+
name: string;
|
|
83
|
+
}[];
|
|
84
|
+
nodeIds: string[];
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=script-run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-run.d.ts","sourceRoot":"","sources":["../src/script-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,iEAAiE;AACjE,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,2FAA2F;AAC3F,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,sEAAsE;IACtE,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,yDAAyD;AACzD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;CAC1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,gBAAgB,EAAE,OAAO,GACxB,qBAAqB,CAOvB;AAYD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,eAAe,EACvB,KAAK,CAAC,EAAE,MAAM,GACb,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAqChC;AAED,oFAAoF;AACpF,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,uBAAuB;IAE1D,MAAM;;;;;IAKN,OAAO;;;;;IAKP,OAAO;EAKV"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The script-operation execution contract, shared by every host.
|
|
3
|
+
*
|
|
4
|
+
* A mini-app operation can run a JS script instead of a workflow. A script has
|
|
5
|
+
* no graph, so two things have to be manufactured: the bindable surface the
|
|
6
|
+
* binding layer resolves names against (its declared ports, which are its
|
|
7
|
+
* stable identifiers — a script has no node ids), and the message stream the
|
|
8
|
+
* fold consumes, because the run endpoint answers with plain JSON rather than
|
|
9
|
+
* streaming.
|
|
10
|
+
*
|
|
11
|
+
* Both live here, above the browser and above the simulator, so the two hosts
|
|
12
|
+
* cannot fold one script run two different ways. This package carries no
|
|
13
|
+
* dependencies, so the script document is typed structurally and the one fact
|
|
14
|
+
* that needs a parser — whether the body reads its inputs through `stream` —
|
|
15
|
+
* arrives as a flag from the caller.
|
|
16
|
+
*/
|
|
17
|
+
import { isRecord, isString } from "./predicates.js";
|
|
18
|
+
/**
|
|
19
|
+
* Split an operation's mapped values the way the body reads them.
|
|
20
|
+
*
|
|
21
|
+
* An app operation is one shot: a widget holds one value per input, not a
|
|
22
|
+
* stream of them. A body that reads `stream` still has to be fed through the
|
|
23
|
+
* inbox, so each mapped value is staged as a one-item stream and `inputs` stays
|
|
24
|
+
* empty — the split a graph run makes, where a connected handle is reachable
|
|
25
|
+
* through `stream` and never through `inputs`. A buffered body is untouched.
|
|
26
|
+
*/
|
|
27
|
+
export function scriptInvocationInput(inputs, usesStreamInputs) {
|
|
28
|
+
if (!usesStreamInputs)
|
|
29
|
+
return { inputs };
|
|
30
|
+
const staged = {};
|
|
31
|
+
for (const [handle, value] of Object.entries(inputs)) {
|
|
32
|
+
staged[handle] = [value];
|
|
33
|
+
}
|
|
34
|
+
return { inputs: {}, inputStreams: staged };
|
|
35
|
+
}
|
|
36
|
+
const emitEntry = (item) => {
|
|
37
|
+
if (!isRecord(item)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const record = item;
|
|
41
|
+
return isString(record.name)
|
|
42
|
+
? { name: record.name, value: record.value }
|
|
43
|
+
: null;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The message stream a script run would have produced: its emits in order,
|
|
47
|
+
* then its final outputs, then the job's terminal status.
|
|
48
|
+
*
|
|
49
|
+
* Emits append (they are one output handle streaming), finals replace and mark
|
|
50
|
+
* the handle done — the same dispositions the kernel sends for a streaming
|
|
51
|
+
* node followed by its final bag. A `jobId` stamps every message, because the
|
|
52
|
+
* fold resolves a message to its invocation by job id.
|
|
53
|
+
*/
|
|
54
|
+
export function scriptRunMessages(result, jobId) {
|
|
55
|
+
const job = jobId === undefined ? {} : { job_id: jobId };
|
|
56
|
+
const messages = [];
|
|
57
|
+
for (const item of result.streamed ?? []) {
|
|
58
|
+
const entry = emitEntry(item);
|
|
59
|
+
if (!entry)
|
|
60
|
+
continue;
|
|
61
|
+
messages.push({
|
|
62
|
+
...job,
|
|
63
|
+
type: "output_update",
|
|
64
|
+
node_id: entry.name,
|
|
65
|
+
output_name: entry.name,
|
|
66
|
+
value: entry.value,
|
|
67
|
+
disposition: "append"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
for (const [name, value] of Object.entries(result.outputs ?? {})) {
|
|
71
|
+
messages.push({
|
|
72
|
+
...job,
|
|
73
|
+
type: "output_update",
|
|
74
|
+
node_id: name,
|
|
75
|
+
output_name: name,
|
|
76
|
+
value,
|
|
77
|
+
disposition: "replace",
|
|
78
|
+
done: true
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const jobUpdate = {
|
|
82
|
+
...job,
|
|
83
|
+
type: "job_update",
|
|
84
|
+
status: result.ok ? "completed" : "failed"
|
|
85
|
+
};
|
|
86
|
+
messages.push(result.error === undefined
|
|
87
|
+
? jobUpdate
|
|
88
|
+
: { ...jobUpdate, error: result.error });
|
|
89
|
+
return messages;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A script's bindable surface. Port names stand in for node ids: a script
|
|
93
|
+
* declares no nodes, and its port names are what every mapping already keys on.
|
|
94
|
+
*/
|
|
95
|
+
export function scriptPortIO(document) {
|
|
96
|
+
return {
|
|
97
|
+
inputs: document.inputs.map((port) => ({
|
|
98
|
+
nodeId: port.name,
|
|
99
|
+
nodeType: `jsscript.input.${port.type}`,
|
|
100
|
+
name: port.name
|
|
101
|
+
})),
|
|
102
|
+
outputs: document.outputs.map((port) => ({
|
|
103
|
+
nodeId: port.name,
|
|
104
|
+
nodeType: `jsscript.output.${port.type}`,
|
|
105
|
+
name: port.name
|
|
106
|
+
})),
|
|
107
|
+
nodeIds: [
|
|
108
|
+
...document.inputs.map((port) => port.name),
|
|
109
|
+
...document.outputs.map((port) => port.name)
|
|
110
|
+
]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=script-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-run.js","sourceRoot":"","sources":["../src/script-run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAgCrD;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAA+B,EAC/B,gBAAyB;IAEzB,IAAI,CAAC,gBAAgB;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACzC,MAAM,MAAM,GAA8B,EAAE,CAAC;IAC7C,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACrD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;AAC9C,CAAC;AAED,MAAM,SAAS,GAAG,CAAC,IAAa,EAA2C,EAAE;IAC3E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;QAC1B,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE;QAC5C,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAuB,EACvB,KAAc;IAEd,MAAM,GAAG,GAAG,KAAK,KAAK,SAAS,CAAC,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AAM,UAAU,YAAY,CAAC,QAAiC;IAC5D,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACrC,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,QAAQ,EAAE,kBAAkB,IAAI,CAAC,IAAI,EAAE;YACvC,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;QACH,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACvC,MAAM,EAAE,IAAI,CAAC,IAAI;YACjB,QAAQ,EAAE,mBAAmB,IAAI,CAAC,IAAI,EAAE;YACxC,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;QACH,OAAO,EAAE;YACP,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;YAC3C,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;SAC7C;KACF,CAAC;AACJ,CAAC"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app instance state and its reducer.
|
|
3
|
+
*
|
|
4
|
+
* One state object backs one open app. It is split into four namespaces
|
|
5
|
+
* instead of a single flat value bag, so a widget-local value can never
|
|
6
|
+
* collide with a workflow output and an output of one operation can never
|
|
7
|
+
* collide with the same node in another. Invocations are tracked separately
|
|
8
|
+
* and every streamed value carries the invocation that produced it — that is
|
|
9
|
+
* what keeps a second tab, an overlapping run, or a graph-editor run from
|
|
10
|
+
* contaminating what the app shows. Outputs and variables follow the same
|
|
11
|
+
* ownership rule: the newest run that writes a slot owns it, and a chunk from
|
|
12
|
+
* a run that a newer one superseded is dropped instead of folded in.
|
|
13
|
+
*
|
|
14
|
+
* Every function here is pure. The React store, the CLI harness, and the eval
|
|
15
|
+
* suites all drive the same reducer.
|
|
16
|
+
*
|
|
17
|
+
* Beside the four value namespaces the state carries what a run reports about
|
|
18
|
+
* itself: invocation status/progress/error, and `activity` — the latest
|
|
19
|
+
* human-readable label a streaming agent emitted (the tool it is calling, the
|
|
20
|
+
* planning phase it is in, the task step it is on). Without it an app over an
|
|
21
|
+
* agent workflow shows a spinner and nothing else.
|
|
22
|
+
*/
|
|
23
|
+
export type InvocationStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
24
|
+
export interface InvocationState {
|
|
25
|
+
/** Equals the run's `job_id`. */
|
|
26
|
+
id: string;
|
|
27
|
+
operationId: string;
|
|
28
|
+
status: InvocationStatus;
|
|
29
|
+
progress?: number;
|
|
30
|
+
error?: string;
|
|
31
|
+
startedAt: number;
|
|
32
|
+
/** Output-mapped variables that this run is responsible for producing. */
|
|
33
|
+
variableKeys?: ReadonlyArray<string>;
|
|
34
|
+
}
|
|
35
|
+
export interface InputSlot {
|
|
36
|
+
value: unknown;
|
|
37
|
+
/** True once a widget (rather than a seed or a default) wrote the value. */
|
|
38
|
+
dirty: boolean;
|
|
39
|
+
revision: number;
|
|
40
|
+
}
|
|
41
|
+
export type OutputStatus = "empty" | "pending" | "streaming" | "done";
|
|
42
|
+
export interface OutputSlot {
|
|
43
|
+
value: unknown;
|
|
44
|
+
invocationId: string | null;
|
|
45
|
+
status: OutputStatus;
|
|
46
|
+
revision: number;
|
|
47
|
+
}
|
|
48
|
+
export interface AppInstanceState {
|
|
49
|
+
/** Keyed `opId:nodeId` (and `opId:nodeId#prop` for node-property bindings). */
|
|
50
|
+
inputs: Record<string, InputSlot>;
|
|
51
|
+
/** Keyed `opId:nodeId`. */
|
|
52
|
+
outputs: Record<string, OutputSlot>;
|
|
53
|
+
/** Keyed by variable id. */
|
|
54
|
+
variables: Record<string, unknown>;
|
|
55
|
+
/** Keyed `componentId:prop`. Widget-local, never persisted. */
|
|
56
|
+
view: Record<string, unknown>;
|
|
57
|
+
/** Keyed by invocation id (== job id). */
|
|
58
|
+
invocations: Record<string, InvocationState>;
|
|
59
|
+
/** Most recent invocation per operation id. */
|
|
60
|
+
activeInvocation: Record<string, string>;
|
|
61
|
+
/** Client reservations promoted to provider job ids. */
|
|
62
|
+
invocationAliases: Record<string, string>;
|
|
63
|
+
/** Keyed by invocation id: the latest activity label the run reported. */
|
|
64
|
+
activity: Record<string, string>;
|
|
65
|
+
/**
|
|
66
|
+
* Keyed by variable id: the invocation whose stream last appended to it —
|
|
67
|
+
* the variable's current owner. A later run starts a fresh value instead of
|
|
68
|
+
* appending to the previous run's; an earlier one is superseded and dropped.
|
|
69
|
+
*/
|
|
70
|
+
variableWriters: Record<string, string>;
|
|
71
|
+
}
|
|
72
|
+
export declare const createInstanceState: () => AppInstanceState;
|
|
73
|
+
/** How a streamed value combines with what the slot already holds. */
|
|
74
|
+
export type Disposition = "append" | "replace";
|
|
75
|
+
export type AppStateEvent =
|
|
76
|
+
/** Seed values that have not been set yet (defaults); never clobbers. */
|
|
77
|
+
{
|
|
78
|
+
type: "seedInputs";
|
|
79
|
+
values: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Seed declared variable defaults (or a restored user-scoped value) into any
|
|
83
|
+
* variable that has none yet; never clobbers, same as `seedInputs`.
|
|
84
|
+
*/
|
|
85
|
+
| {
|
|
86
|
+
type: "seedVariables";
|
|
87
|
+
values: Record<string, unknown>;
|
|
88
|
+
} | {
|
|
89
|
+
type: "setInput";
|
|
90
|
+
key: string;
|
|
91
|
+
value: unknown;
|
|
92
|
+
dirty?: boolean;
|
|
93
|
+
} | {
|
|
94
|
+
type: "setVariable";
|
|
95
|
+
variableId: string;
|
|
96
|
+
value: unknown;
|
|
97
|
+
/**
|
|
98
|
+
* "append" accumulates the way an output slot does, so a streamed output
|
|
99
|
+
* mapped to a variable builds up instead of flickering one chunk at a
|
|
100
|
+
* time. Defaults to "replace" — a widget writing a variable overwrites.
|
|
101
|
+
*/
|
|
102
|
+
disposition?: Disposition;
|
|
103
|
+
/**
|
|
104
|
+
* The run doing the appending: a newer run restarts the accumulation, a
|
|
105
|
+
* superseded one is dropped. Absent for widget writes.
|
|
106
|
+
*/
|
|
107
|
+
invocationId?: string;
|
|
108
|
+
} | {
|
|
109
|
+
type: "toggleVariable";
|
|
110
|
+
variableId: string;
|
|
111
|
+
} | {
|
|
112
|
+
type: "setView";
|
|
113
|
+
key: string;
|
|
114
|
+
value: unknown;
|
|
115
|
+
}
|
|
116
|
+
/** Validate → snapshot → create invocation → mark outputs pending, atomically. */
|
|
117
|
+
| {
|
|
118
|
+
type: "runStarted";
|
|
119
|
+
invocation: InvocationState;
|
|
120
|
+
outputKeys: ReadonlyArray<string>;
|
|
121
|
+
variableKeys?: ReadonlyArray<string>;
|
|
122
|
+
} | {
|
|
123
|
+
type: "invocationAlias";
|
|
124
|
+
aliasId: string;
|
|
125
|
+
invocationId: string;
|
|
126
|
+
} | {
|
|
127
|
+
type: "invocationStatus";
|
|
128
|
+
invocationId: string;
|
|
129
|
+
status: InvocationStatus;
|
|
130
|
+
error?: string;
|
|
131
|
+
} | {
|
|
132
|
+
type: "invocationProgress";
|
|
133
|
+
invocationId: string;
|
|
134
|
+
progress?: number;
|
|
135
|
+
}
|
|
136
|
+
/** A node reported an error; the run may still be in flight. */
|
|
137
|
+
| {
|
|
138
|
+
type: "invocationError";
|
|
139
|
+
invocationId: string;
|
|
140
|
+
error: string;
|
|
141
|
+
}
|
|
142
|
+
/** The run reported what it is doing right now (tool, phase, step). */
|
|
143
|
+
| {
|
|
144
|
+
type: "invocationActivity";
|
|
145
|
+
invocationId: string;
|
|
146
|
+
label: string;
|
|
147
|
+
} | {
|
|
148
|
+
type: "outputValue";
|
|
149
|
+
key: string;
|
|
150
|
+
invocationId: string;
|
|
151
|
+
value: unknown;
|
|
152
|
+
disposition: Disposition;
|
|
153
|
+
done?: boolean;
|
|
154
|
+
} | {
|
|
155
|
+
type: "reset";
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Append semantics, matching the protocol: streamed text concatenates (one
|
|
159
|
+
* streamed string must render as one Markdown block, not N), while structured
|
|
160
|
+
* items collect into a list — one entry per emitted item.
|
|
161
|
+
*/
|
|
162
|
+
export declare const appendValue: (previous: unknown, next: unknown) => unknown;
|
|
163
|
+
export declare const applyEvent: (state: AppInstanceState, event: AppStateEvent) => AppInstanceState;
|
|
164
|
+
export declare const applyEvents: (state: AppInstanceState, events: ReadonlyArray<AppStateEvent>) => AppInstanceState;
|
|
165
|
+
/** Live invocations of an operation, newest first. */
|
|
166
|
+
export declare const invocationsOf: (state: AppInstanceState, operationId: string) => InvocationState[];
|
|
167
|
+
export declare const isLiveInvocation: (invocation: InvocationState) => boolean;
|
|
168
|
+
/** Invocations of an operation that have not settled yet, newest first. */
|
|
169
|
+
export declare const liveInvocations: (state: AppInstanceState, operationId: string) => InvocationState[];
|
|
170
|
+
export declare const isOperationRunning: (state: AppInstanceState, operationId: string) => boolean;
|
|
171
|
+
/** Aggregate progress of the operation's active invocation, if any. */
|
|
172
|
+
export declare const operationProgress: (state: AppInstanceState, operationId: string) => number | undefined;
|
|
173
|
+
export declare const operationError: (state: AppInstanceState, operationId: string) => string | undefined;
|
|
174
|
+
/** What the operation's active invocation last reported it was doing. */
|
|
175
|
+
export declare const operationActivity: (state: AppInstanceState, operationId: string) => string | undefined;
|
|
176
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,SAAS,GACT,WAAW,GACX,QAAQ,GACR,WAAW,CAAC;AAEhB,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,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