@nodetool-ai/execution 0.8.1 → 0.8.3
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 +23 -127
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/app-debug/app-spec.d.ts.map +1 -1
- package/dist/app-debug/app-spec.js +3 -0
- package/dist/app-debug/app-spec.js.map +1 -1
- package/dist/app-debug/application-target.d.ts +1 -1
- package/dist/app-debug/application-target.d.ts.map +1 -1
- package/dist/app-debug/application-target.js +5 -3
- package/dist/app-debug/application-target.js.map +1 -1
- package/dist/app-debug/index.d.ts +4 -2
- package/dist/app-debug/index.d.ts.map +1 -1
- package/dist/app-debug/index.js +3 -2
- package/dist/app-debug/index.js.map +1 -1
- package/dist/app-debug/run-recording.d.ts +20 -0
- package/dist/app-debug/run-recording.d.ts.map +1 -0
- package/dist/app-debug/run-recording.js +105 -0
- package/dist/app-debug/run-recording.js.map +1 -0
- package/dist/app-debug/runtime.d.ts +2 -0
- package/dist/app-debug/runtime.d.ts.map +1 -1
- package/dist/app-debug/runtime.js +19 -4
- package/dist/app-debug/runtime.js.map +1 -1
- package/dist/app-debug/simulate.d.ts +10 -1
- package/dist/app-debug/simulate.d.ts.map +1 -1
- package/dist/app-debug/simulate.js +67 -27
- package/dist/app-debug/simulate.js.map +1 -1
- package/dist/app-debug/summarize.d.ts +1 -0
- package/dist/app-debug/summarize.d.ts.map +1 -1
- package/dist/app-debug/summarize.js +1 -0
- package/dist/app-debug/summarize.js.map +1 -1
- package/dist/app-debug/types.d.ts +6 -4
- package/dist/app-debug/types.d.ts.map +1 -1
- package/dist/app-run-generation.d.ts +8 -0
- package/dist/app-run-generation.d.ts.map +1 -0
- package/dist/app-run-generation.js +61 -0
- package/dist/app-run-generation.js.map +1 -0
- package/dist/browser-app-run.d.ts +10 -0
- package/dist/browser-app-run.d.ts.map +1 -0
- package/dist/browser-app-run.js +108 -0
- package/dist/browser-app-run.js.map +1 -0
- package/dist/browser-run-spans.d.ts +4 -0
- package/dist/browser-run-spans.d.ts.map +1 -0
- package/dist/browser-run-spans.js +115 -0
- package/dist/browser-run-spans.js.map +1 -0
- package/dist/browser-trace-policy.d.ts +12 -0
- package/dist/browser-trace-policy.d.ts.map +1 -0
- package/dist/browser-trace-policy.js +40 -0
- package/dist/browser-trace-policy.js.map +1 -0
- package/dist/cost-ledger.d.ts +3 -0
- package/dist/cost-ledger.d.ts.map +1 -1
- package/dist/cost-ledger.js +23 -2
- package/dist/cost-ledger.js.map +1 -1
- package/dist/debug/types.d.ts +1 -0
- package/dist/debug/types.d.ts.map +1 -1
- package/dist/debug/verdict.d.ts +26 -1
- package/dist/debug/verdict.d.ts.map +1 -1
- package/dist/debug/verdict.js +36 -0
- package/dist/debug/verdict.js.map +1 -1
- package/dist/generation-lifecycle.d.ts +5 -4
- package/dist/generation-lifecycle.d.ts.map +1 -1
- package/dist/generation-lifecycle.js +71 -10
- package/dist/generation-lifecycle.js.map +1 -1
- package/dist/generation-recovery-worker.d.ts.map +1 -1
- package/dist/generation-recovery-worker.js +2 -0
- package/dist/generation-recovery-worker.js.map +1 -1
- package/dist/generation-tracker.d.ts +2 -15
- package/dist/generation-tracker.d.ts.map +1 -1
- package/dist/generation-tracker.js +92 -6
- package/dist/generation-tracker.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/js-script-debug/index.d.ts +1 -0
- package/dist/js-script-debug/index.d.ts.map +1 -1
- package/dist/js-script-debug/index.js +1 -0
- package/dist/js-script-debug/index.js.map +1 -1
- package/dist/js-script-debug/report.d.ts.map +1 -1
- package/dist/js-script-debug/report.js +9 -24
- package/dist/js-script-debug/report.js.map +1 -1
- package/dist/js-script-debug/type-check.d.ts +16 -0
- package/dist/js-script-debug/type-check.d.ts.map +1 -0
- package/dist/js-script-debug/type-check.js +150 -0
- package/dist/js-script-debug/type-check.js.map +1 -0
- package/dist/js-script-debug/validate.d.ts +8 -0
- package/dist/js-script-debug/validate.d.ts.map +1 -1
- package/dist/js-script-debug/validate.js +4 -0
- package/dist/js-script-debug/validate.js.map +1 -1
- package/dist/message-stream.d.ts +1 -32
- package/dist/message-stream.d.ts.map +1 -1
- package/dist/message-stream.js +1 -57
- package/dist/message-stream.js.map +1 -1
- package/dist/partial-run.d.ts +65 -0
- package/dist/partial-run.d.ts.map +1 -0
- package/dist/partial-run.js +300 -0
- package/dist/partial-run.js.map +1 -0
- package/dist/preflight.d.ts +43 -2
- package/dist/preflight.d.ts.map +1 -1
- package/dist/preflight.js +78 -4
- package/dist/preflight.js.map +1 -1
- package/dist/run-trace-store.d.ts +9 -0
- package/dist/run-trace-store.d.ts.map +1 -0
- package/dist/run-trace-store.js +57 -0
- package/dist/run-trace-store.js.map +1 -0
- package/dist/runs.d.ts +16 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +431 -0
- package/dist/runs.js.map +1 -0
- package/dist/service/app-debug-service.d.ts +4 -2
- package/dist/service/app-debug-service.d.ts.map +1 -1
- package/dist/service/app-debug-service.js +73 -31
- package/dist/service/app-debug-service.js.map +1 -1
- package/dist/service/app-operation.d.ts +39 -0
- package/dist/service/app-operation.d.ts.map +1 -0
- package/dist/service/app-operation.js +271 -0
- package/dist/service/app-operation.js.map +1 -0
- package/dist/service/app-run-server.d.ts +3 -1
- package/dist/service/app-run-server.d.ts.map +1 -1
- package/dist/service/app-run-server.js +22 -14
- package/dist/service/app-run-server.js.map +1 -1
- package/dist/service/index.d.ts +5 -1
- package/dist/service/index.d.ts.map +1 -1
- package/dist/service/index.js +2 -0
- package/dist/service/index.js.map +1 -1
- package/dist/service/run-trace-lifecycle.d.ts +34 -0
- package/dist/service/run-trace-lifecycle.d.ts.map +1 -0
- package/dist/service/run-trace-lifecycle.js +135 -0
- package/dist/service/run-trace-lifecycle.js.map +1 -0
- package/dist/service/workflow-run.d.ts +47 -16
- package/dist/service/workflow-run.d.ts.map +1 -1
- package/dist/service/workflow-run.js +210 -78
- package/dist/service/workflow-run.js.map +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +109 -100
- package/dist/session.js.map +1 -1
- package/dist/sketch-debug/markdown.d.ts.map +1 -1
- package/dist/sketch-debug/markdown.js +1 -0
- package/dist/sketch-debug/markdown.js.map +1 -1
- package/dist/sketch-debug/report.d.ts.map +1 -1
- package/dist/sketch-debug/report.js +19 -28
- package/dist/sketch-debug/report.js.map +1 -1
- package/dist/sketch-debug/types.d.ts +2 -0
- package/dist/sketch-debug/types.d.ts.map +1 -1
- package/dist/timeline-debug/frame-geometry.d.ts +120 -0
- package/dist/timeline-debug/frame-geometry.d.ts.map +1 -0
- package/dist/timeline-debug/frame-geometry.js +238 -0
- package/dist/timeline-debug/frame-geometry.js.map +1 -0
- package/dist/timeline-debug/index.d.ts +1 -0
- package/dist/timeline-debug/index.d.ts.map +1 -1
- package/dist/timeline-debug/index.js +1 -0
- package/dist/timeline-debug/index.js.map +1 -1
- package/dist/timeline-debug/legibility.d.ts +8 -4
- package/dist/timeline-debug/legibility.d.ts.map +1 -1
- package/dist/timeline-debug/legibility.js +47 -18
- package/dist/timeline-debug/legibility.js.map +1 -1
- package/dist/timeline-debug/report.d.ts.map +1 -1
- package/dist/timeline-debug/report.js +16 -25
- package/dist/timeline-debug/report.js.map +1 -1
- package/dist/timeline-debug/score.d.ts +110 -0
- package/dist/timeline-debug/score.d.ts.map +1 -0
- package/dist/timeline-debug/score.js +231 -0
- package/dist/timeline-debug/score.js.map +1 -0
- package/dist/timeline-debug/showcase.d.ts +12 -0
- package/dist/timeline-debug/showcase.d.ts.map +1 -1
- package/dist/timeline-debug/showcase.js +669 -13
- package/dist/timeline-debug/showcase.js.map +1 -1
- package/dist/timeline-debug/validate.d.ts.map +1 -1
- package/dist/timeline-debug/validate.js +121 -2
- package/dist/timeline-debug/validate.js.map +1 -1
- package/dist/types.d.ts +18 -10
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/js-script-debug/report.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,iCAAiC,EAAE,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/js-script-debug/report.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,iCAAiC,EAAE,MAAM,iDAAiD,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAU3D,OAAO,EACL,mBAAmB,EAEpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAK5D;;;GAGG;AACH,MAAM,aAAa,GAA0B;IAC3C,+HAA+H;IAC/H,kGAAkG;IAClG,oGAAoG;IACpG,mGAAmG;CACpG,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,MAAM,KAAK,GAAG,CAAC,KAAc,EAAU,EAAE,CACvC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1C,SAAS,gBAAgB,CAAC,QAAiB;IACzC,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,MAAM,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC;IACtC,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;QAChC,WAAW,EAAE,KAAK,CAAC,MAAM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,OAAO,CAAC,CAAC;IAC9D,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC;IAK9C,MAAM,MAAM,GAAiB;QAC3B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,QAAQ,CAAC;QAC7D,UAAU;QACV,YAAY;QACZ,YAAY,EAAE,CAAC,GAAG,aAAa,CAAC;QAChC,OAAO,EAAE,YAAY,CAAC,UAAU,EAAE,YAAY,EAAE,eAAe,CAAC;KACjE,CAAC;IACF,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IACvC,CAAC;IACD,IAAI,eAAe,EAAE,CAAC;QACpB,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsScriptDebugIssue } from "./types.js";
|
|
2
|
+
/** `specifier -> absolute path to the pack's shipped .d.ts`, e.g. `"@nodetool-ai/sandbox-timeline" -> ".../sandbox/index.d.ts"`. */
|
|
3
|
+
export type PackDtsSources = ReadonlyMap<string, string>;
|
|
4
|
+
/**
|
|
5
|
+
* Type-check `code` (a script or Code-node body) as an ES module against the
|
|
6
|
+
* `.d.ts` files in `packDtsSources`, keyed by the specifier a script imports
|
|
7
|
+
* them under. Returns one `js_script_type_error` per diagnostic on the
|
|
8
|
+
* script's own file, each naming the message TypeScript gives — which names
|
|
9
|
+
* the offending property (`caret` on an object-literal type mismatch) the
|
|
10
|
+
* way every other check in this module names the identifier it complains
|
|
11
|
+
* about. Never throws: a `typescript` failure to load or a filesystem error
|
|
12
|
+
* is swallowed and reported as nothing found, since this check is additive
|
|
13
|
+
* on top of the AST-level one in `validateCodeNodeBody`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function typeCheckAgainstPackDts(code: string, packDtsSources: PackDtsSources): Promise<JsScriptDebugIssue[]>;
|
|
16
|
+
//# sourceMappingURL=type-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-check.d.ts","sourceRoot":"","sources":["../../src/js-script-debug/type-check.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,oIAAoI;AACpI,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAkDzD;;;;;;;;;;GAUG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA+E/B"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-checks a JS script body against the `.d.ts` files installed sandbox
|
|
3
|
+
* packs ship, so an authoring mistake like `typewriter({ caret: true })`
|
|
4
|
+
* (`@nodetool-ai/sandbox-timeline`'s `caret` is an object, not a boolean)
|
|
5
|
+
* fails `nodetool jsscript validate` by name before the script ever runs.
|
|
6
|
+
*
|
|
7
|
+
* The body is not itself valid as a standalone module (it is the async
|
|
8
|
+
* function body `runCodeBody` wraps at execution time), but its own
|
|
9
|
+
* top-level `import` statements and any top-level `await` are ordinary ES
|
|
10
|
+
* module syntax, so writing it to a `.ts` file and type-checking that file
|
|
11
|
+
* as a module works without reconstructing the wrapper. Every sandbox
|
|
12
|
+
* global the body can read (`nodetool`, `emit`, `inputs`, `workspace`, …) is
|
|
13
|
+
* declared `any` in a a synthesized globals file so the checker never flags
|
|
14
|
+
* one as unknown — this only checks what an installed pack's own `.d.ts`
|
|
15
|
+
* commits to, nothing about the rest of the guest environment.
|
|
16
|
+
*/
|
|
17
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
18
|
+
import { tmpdir } from "node:os";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
/**
|
|
21
|
+
* Names the QuickJS sandbox and the Code/script node put in scope, loosely
|
|
22
|
+
* typed so the checker never reports one as undefined — mirrors
|
|
23
|
+
* `SANDBOX_GLOBALS` in `@nodetool-ai/node-sdk`'s `code-node-validation.ts`,
|
|
24
|
+
* which this package cannot import as a compile-time type (the dependency
|
|
25
|
+
* runs the other way). A name only needs to exist here, not match precisely:
|
|
26
|
+
* a wrong shape on a *sandbox* global is not this check's job, only a wrong
|
|
27
|
+
* shape passed to an *installed pack's* own declared API is.
|
|
28
|
+
*/
|
|
29
|
+
const SANDBOX_GLOBALS_DTS = `
|
|
30
|
+
declare const nodetool: any;
|
|
31
|
+
declare const tools: any;
|
|
32
|
+
declare const inputs: any;
|
|
33
|
+
declare const state: any;
|
|
34
|
+
declare const workspace: any;
|
|
35
|
+
declare function emit(name: string, value: unknown): Promise<void>;
|
|
36
|
+
declare function output(name: string, value: unknown): Promise<void>;
|
|
37
|
+
declare function stream(name: string): AsyncIterable<unknown> & { any: () => AsyncIterable<unknown> };
|
|
38
|
+
declare function progress(message: string, fraction?: number): void;
|
|
39
|
+
declare function getSecret(name: string): Promise<string | undefined>;
|
|
40
|
+
declare function sleep(ms: number): Promise<void>;
|
|
41
|
+
declare const format: any;
|
|
42
|
+
declare const image: any;
|
|
43
|
+
declare const audio: any;
|
|
44
|
+
declare const video: any;
|
|
45
|
+
declare const canvas: any;
|
|
46
|
+
declare const media: any;
|
|
47
|
+
declare function createCanvas(width: number, height: number): unknown;
|
|
48
|
+
declare function parallelMap<T, R>(items: readonly T[], fn: (item: T) => Promise<R>): Promise<R[]>;
|
|
49
|
+
declare function toBase64(bytes: Uint8Array): string;
|
|
50
|
+
declare function fromBase64(text: string): Uint8Array;
|
|
51
|
+
declare function toHex(bytes: Uint8Array): string;
|
|
52
|
+
declare function fromHex(text: string): Uint8Array;
|
|
53
|
+
declare function assetToSandbox(value: unknown): Promise<unknown>;
|
|
54
|
+
declare function sandboxToAsset(value: unknown): Promise<unknown>;
|
|
55
|
+
`;
|
|
56
|
+
/**
|
|
57
|
+
* "Cannot find module" (a named import, then a side-effect import). Only packs
|
|
58
|
+
* that ship a `.d.ts` are on the paths here, so every other import — a pack
|
|
59
|
+
* with no types, a host-mounted `@nodetool-ai/sandbox-nodetool/*` facade —
|
|
60
|
+
* fails to resolve in this program while resolving fine in the sandbox.
|
|
61
|
+
* Whether a specifier exists is the catalog check's job
|
|
62
|
+
* (`code_package_unavailable`); this check only holds a typed pack to its
|
|
63
|
+
* own declarations, and an unresolved import is `any` to it.
|
|
64
|
+
*/
|
|
65
|
+
const UNRESOLVED_MODULE_CODES = new Set([2307, 2882]);
|
|
66
|
+
/**
|
|
67
|
+
* Type-check `code` (a script or Code-node body) as an ES module against the
|
|
68
|
+
* `.d.ts` files in `packDtsSources`, keyed by the specifier a script imports
|
|
69
|
+
* them under. Returns one `js_script_type_error` per diagnostic on the
|
|
70
|
+
* script's own file, each naming the message TypeScript gives — which names
|
|
71
|
+
* the offending property (`caret` on an object-literal type mismatch) the
|
|
72
|
+
* way every other check in this module names the identifier it complains
|
|
73
|
+
* about. Never throws: a `typescript` failure to load or a filesystem error
|
|
74
|
+
* is swallowed and reported as nothing found, since this check is additive
|
|
75
|
+
* on top of the AST-level one in `validateCodeNodeBody`.
|
|
76
|
+
*/
|
|
77
|
+
export async function typeCheckAgainstPackDts(code, packDtsSources) {
|
|
78
|
+
if (code.trim() === "" || packDtsSources.size === 0)
|
|
79
|
+
return [];
|
|
80
|
+
let ts;
|
|
81
|
+
try {
|
|
82
|
+
ts = (await import("typescript")).default ?? (await import("typescript"));
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// `typescript` failing to load means this install cannot type-check at
|
|
86
|
+
// all — a warning, not an error, since that is not the script's fault and
|
|
87
|
+
// must not fail `validate` outright (the AST-level checks above already
|
|
88
|
+
// ran and still stand). `typescript` is only a runtime dependency of this
|
|
89
|
+
// package (`packages/execution/package.json`), and this dynamic import is
|
|
90
|
+
// the only place it is ever loaded — a validate call with no pack
|
|
91
|
+
// `.d.ts` sources, and every other caller of this package, never touches
|
|
92
|
+
// the module at all.
|
|
93
|
+
return [
|
|
94
|
+
{
|
|
95
|
+
severity: "warning",
|
|
96
|
+
code: "type_check_unavailable",
|
|
97
|
+
message: `Could not load the TypeScript compiler, so the script's imports were not type-checked against any installed pack's .d.ts: ${error instanceof Error ? error.message : String(error)}`
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
const dir = await mkdtemp(join(tmpdir(), "nodetool-jsscript-types-"));
|
|
102
|
+
try {
|
|
103
|
+
const globalsPath = join(dir, "sandbox-globals.d.ts");
|
|
104
|
+
const scriptPath = join(dir, "script.ts");
|
|
105
|
+
await writeFile(globalsPath, SANDBOX_GLOBALS_DTS, "utf8");
|
|
106
|
+
await writeFile(scriptPath, code, "utf8");
|
|
107
|
+
const paths = {};
|
|
108
|
+
for (const [specifier, dtsPath] of packDtsSources) {
|
|
109
|
+
paths[specifier] = [dtsPath];
|
|
110
|
+
}
|
|
111
|
+
let program;
|
|
112
|
+
try {
|
|
113
|
+
program = ts.createProgram([globalsPath, scriptPath], {
|
|
114
|
+
allowJs: false,
|
|
115
|
+
checkJs: false,
|
|
116
|
+
noEmit: true,
|
|
117
|
+
skipLibCheck: true,
|
|
118
|
+
strict: false,
|
|
119
|
+
target: ts.ScriptTarget.ES2022,
|
|
120
|
+
module: ts.ModuleKind.ESNext,
|
|
121
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
122
|
+
baseUrl: dir,
|
|
123
|
+
paths
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
const diagnostics = ts
|
|
130
|
+
.getPreEmitDiagnostics(program)
|
|
131
|
+
.filter((diagnostic) => diagnostic.file?.fileName === scriptPath &&
|
|
132
|
+
!UNRESOLVED_MODULE_CODES.has(diagnostic.code));
|
|
133
|
+
return diagnostics.map((diagnostic) => {
|
|
134
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, " ");
|
|
135
|
+
if (diagnostic.file !== undefined && diagnostic.start !== undefined) {
|
|
136
|
+
const { line } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
137
|
+
return {
|
|
138
|
+
severity: "error",
|
|
139
|
+
code: "js_script_type_error",
|
|
140
|
+
message: `line ${line + 1}: ${message}`
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return { severity: "error", code: "js_script_type_error", message };
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
await rm(dir, { recursive: true, force: true });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=type-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-check.js","sourceRoot":"","sources":["../../src/js-script-debug/type-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC;;;;;;;;GAQG;AACH,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0B3B,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,IAAY,EACZ,cAA8B;IAE9B,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,cAAc,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAE/D,IAAI,EA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C,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import type { SandboxModuleCatalog } from "@nodetool-ai/runtime";
|
|
22
22
|
import type { JsScriptValidation } from "./types.js";
|
|
23
|
+
import { type PackDtsSources } from "./type-check.js";
|
|
23
24
|
export interface JsScriptValidationOptions {
|
|
24
25
|
/**
|
|
25
26
|
* Secret names this install carries. A declared secret missing from the list
|
|
@@ -29,6 +30,13 @@ export interface JsScriptValidationOptions {
|
|
|
29
30
|
knownSecrets?: readonly string[];
|
|
30
31
|
/** The installed sandbox catalog, when the caller has one. */
|
|
31
32
|
sandboxModuleCatalog?: SandboxModuleCatalog | null;
|
|
33
|
+
/**
|
|
34
|
+
* `specifier -> absolute path to an installed pack's shipped .d.ts`, when
|
|
35
|
+
* the caller has resolved them. Given any, the body is type-checked as an
|
|
36
|
+
* ES module against those declarations — see `type-check.ts`. Omit to skip
|
|
37
|
+
* it entirely; an empty map is the same as omitting it.
|
|
38
|
+
*/
|
|
39
|
+
packDtsSources?: PackDtsSources;
|
|
32
40
|
}
|
|
33
41
|
/**
|
|
34
42
|
* Check a JS script document without running it. Returns findings rather than
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/js-script-debug/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAOH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAsB,kBAAkB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/js-script-debug/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAOH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAsB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAA2B,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE/E,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,8DAA8D;IAC9D,oBAAoB,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACnD;;;;;OAKG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAsED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,OAAO,EACjB,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,kBAAkB,CAAC,CAoE7B"}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* here, so a file target stays database-free.
|
|
20
20
|
*/
|
|
21
21
|
import { jsScriptDocument, validateJsScriptDocument } from "@nodetool-ai/protocol/api-schemas/js-scripts.js";
|
|
22
|
+
import { typeCheckAgainstPackDts } from "./type-check.js";
|
|
22
23
|
function split(issues) {
|
|
23
24
|
const errors = issues.filter((issue) => issue.severity === "error");
|
|
24
25
|
const warnings = issues.filter((issue) => issue.severity === "warning");
|
|
@@ -111,6 +112,9 @@ export async function validateJsScriptDoc(document, options = {}) {
|
|
|
111
112
|
message: issue.message
|
|
112
113
|
}));
|
|
113
114
|
const issues = [...shapeIssues, ...bodyIssues];
|
|
115
|
+
if (options.packDtsSources !== undefined && options.packDtsSources.size > 0) {
|
|
116
|
+
issues.push(...(await typeCheckAgainstPackDts(doc.code, options.packDtsSources)));
|
|
117
|
+
}
|
|
114
118
|
const streaming = usesStreamInputContract(doc.code);
|
|
115
119
|
// A streaming body on the return contract is already an error from the body
|
|
116
120
|
// check (`code_stream_return_contract`), which says the same thing.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/js-script-debug/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EAEzB,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/js-script-debug/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EAEzB,MAAM,iDAAiD,CAAC;AAGzD,OAAO,EAAE,uBAAuB,EAAuB,MAAM,iBAAiB,CAAC;AAoB/E,SAAS,KAAK,CAAC,MAAqC;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC;IACxE,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,GAAqB,EACrB,sBAAiD;IAEjD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,IAAI,KAAK,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzD,IAAI,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAClD,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,2BAA2B;QACjC,OAAO,EACL,qEAAqE;YACrE,qDAAqD;YACrD,qDAAqD;YACrD,8B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,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IACpF,CAAC;IAED,MAAM,SAAS,GAAG,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpD,4EAA4E;IAC5E,oEAAoE;IACpE,MAAM,MAAM,GAAG,SAAS;QACtB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,mBAAmB,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC;IACrD,IAAI,MAAM;QAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEhC,MAAM,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;IAEjD,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5C,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAC/B,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3C,MAAM,CAAC,IAAI,CAAC;oBACV,QAAQ,EAAE,SAAS;oBACnB,IAAI,EAAE,0BAA0B;oBAChC,OAAO,EAAE,oBAAoB,IAAI,0CAA0C;iBAC5E,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;AACvB,CAAC"}
|
package/dist/message-stream.d.ts
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Turns `ProcessingContext`'s push-based `addMessageListener` into a pull-based
|
|
3
|
-
* `AsyncIterable<ProcessingMessage>`. Modeled on the queue/wake pattern in
|
|
4
|
-
* `packages/workflow-runner/src/run.ts`'s `runWorkflow` generator — the one
|
|
5
|
-
* other place in the repo already streams a kernel run as an async sequence.
|
|
6
|
-
*
|
|
7
|
-
* The queue is bounded. A caller that opts into capture (see
|
|
8
|
-
* `ExecutionSessionOptions.captureMessages`) but never iterates would
|
|
9
|
-
* otherwise retain every message of the run — including real-time audio
|
|
10
|
-
* chunks, which the kernel's own message retention deliberately avoids
|
|
11
|
-
* holding (roughly 25 MB/minute). Past the limit the stream stops queueing
|
|
12
|
-
* and the iterator throws, so a non-draining consumer fails loudly instead of
|
|
13
|
-
* growing until the run ends.
|
|
14
|
-
*/
|
|
15
|
-
import type { ProcessingContext } from "@nodetool-ai/runtime";
|
|
16
|
-
import type { ProcessingMessage } from "@nodetool-ai/protocol";
|
|
17
|
-
/** Queued messages allowed to pile up before the stream gives up. */
|
|
18
|
-
export declare const DEFAULT_MESSAGE_BUFFER_LIMIT = 10000;
|
|
19
|
-
export declare class MessageStream implements AsyncIterable<ProcessingMessage> {
|
|
20
|
-
private readonly queue;
|
|
21
|
-
private waiter;
|
|
22
|
-
private closed;
|
|
23
|
-
private overflowedAt;
|
|
24
|
-
private readonly limit;
|
|
25
|
-
private readonly unsubscribe;
|
|
26
|
-
/** `limit` of 0 (or a negative number) means unbounded. */
|
|
27
|
-
constructor(context: ProcessingContext, limit?: number);
|
|
28
|
-
private wake;
|
|
29
|
-
/** Stop feeding new messages into the queue. Already-queued messages still drain. */
|
|
30
|
-
close(): void;
|
|
31
|
-
[Symbol.asyncIterator](): AsyncIterator<ProcessingMessage>;
|
|
32
|
-
}
|
|
1
|
+
export { MessageStream, DEFAULT_MESSAGE_BUFFER_LIMIT } from "@nodetool-ai/kernel";
|
|
33
2
|
//# sourceMappingURL=message-stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-stream.d.ts","sourceRoot":"","sources":["../src/message-stream.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"message-stream.d.ts","sourceRoot":"","sources":["../src/message-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/message-stream.js
CHANGED
|
@@ -1,58 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export const DEFAULT_MESSAGE_BUFFER_LIMIT = 10_000;
|
|
3
|
-
export class MessageStream {
|
|
4
|
-
queue = [];
|
|
5
|
-
waiter = null;
|
|
6
|
-
closed = false;
|
|
7
|
-
overflowedAt = null;
|
|
8
|
-
limit;
|
|
9
|
-
unsubscribe;
|
|
10
|
-
/** `limit` of 0 (or a negative number) means unbounded. */
|
|
11
|
-
constructor(context, limit = DEFAULT_MESSAGE_BUFFER_LIMIT) {
|
|
12
|
-
this.limit = limit > 0 ? limit : Number.POSITIVE_INFINITY;
|
|
13
|
-
this.unsubscribe = context.addMessageListener((message) => {
|
|
14
|
-
if (this.queue.length >= this.limit) {
|
|
15
|
-
if (this.overflowedAt === null) {
|
|
16
|
-
this.overflowedAt = this.queue.length;
|
|
17
|
-
this.unsubscribe();
|
|
18
|
-
}
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
this.queue.push(message);
|
|
22
|
-
this.wake();
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
wake() {
|
|
26
|
-
const w = this.waiter;
|
|
27
|
-
this.waiter = null;
|
|
28
|
-
w?.();
|
|
29
|
-
}
|
|
30
|
-
/** Stop feeding new messages into the queue. Already-queued messages still drain. */
|
|
31
|
-
close() {
|
|
32
|
-
if (this.closed)
|
|
33
|
-
return;
|
|
34
|
-
this.closed = true;
|
|
35
|
-
this.unsubscribe();
|
|
36
|
-
this.wake();
|
|
37
|
-
}
|
|
38
|
-
async *[Symbol.asyncIterator]() {
|
|
39
|
-
for (;;) {
|
|
40
|
-
while (this.queue.length > 0) {
|
|
41
|
-
yield this.queue.shift();
|
|
42
|
-
}
|
|
43
|
-
if (this.overflowedAt !== null) {
|
|
44
|
-
throw new Error(`ExecutionSession message stream overflowed after ${this.overflowedAt} ` +
|
|
45
|
-
`queued messages (limit ${this.limit}) — the consumer fell behind, ` +
|
|
46
|
-
"so messages past that point were dropped rather than retained. " +
|
|
47
|
-
"Iterate `session.messages` as the run progresses, or raise " +
|
|
48
|
-
"`limits.messageBufferLimit`.");
|
|
49
|
-
}
|
|
50
|
-
if (this.closed)
|
|
51
|
-
return;
|
|
52
|
-
await new Promise((resolve) => {
|
|
53
|
-
this.waiter = resolve;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
export { MessageStream, DEFAULT_MESSAGE_BUFFER_LIMIT } from "@nodetool-ai/kernel";
|
|
58
2
|
//# sourceMappingURL=message-stream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-stream.js","sourceRoot":"","sources":["../src/message-stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message-stream.js","sourceRoot":"","sources":["../src/message-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { GraphData, NodeDescriptor } from "@nodetool-ai/protocol";
|
|
2
|
+
import type { NodeMetadata } from "@nodetool-ai/node-sdk";
|
|
3
|
+
/** A previous generation of one node, as the run reuses it. */
|
|
4
|
+
export interface PreviousGeneration {
|
|
5
|
+
/** Output values keyed by output handle. */
|
|
6
|
+
outputs: Record<string, unknown>;
|
|
7
|
+
jobId: string | null;
|
|
8
|
+
assetIds: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface PartialRunDeps {
|
|
11
|
+
getMetadata: (nodeType: string) => NodeMetadata | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* The node's previous generation, or null when it has none. Omit to run
|
|
14
|
+
* every upstream node again.
|
|
15
|
+
*/
|
|
16
|
+
loadPreviousGeneration?: (node: NodeDescriptor, metadata: NodeMetadata) => Promise<PreviousGeneration | null>;
|
|
17
|
+
}
|
|
18
|
+
/** One upstream node whose saved output replaced its run. */
|
|
19
|
+
export interface ReusedNode {
|
|
20
|
+
node_id: string;
|
|
21
|
+
job_id: string | null;
|
|
22
|
+
asset_ids: string[];
|
|
23
|
+
}
|
|
24
|
+
export type PartialRunPlan = {
|
|
25
|
+
kind: "graph";
|
|
26
|
+
graph: GraphData;
|
|
27
|
+
/** Every node the narrowed graph runs. */
|
|
28
|
+
ran: string[];
|
|
29
|
+
reused: ReusedNode[];
|
|
30
|
+
} | {
|
|
31
|
+
kind: "unknown_nodes";
|
|
32
|
+
ids: string[];
|
|
33
|
+
};
|
|
34
|
+
/** The ids in `nodeIds` that name no node of `graph`. */
|
|
35
|
+
export declare function unknownNodeIds(graph: GraphData, nodeIds: readonly string[]): string[];
|
|
36
|
+
/**
|
|
37
|
+
* A generation's value for one output handle: the named handle, else the sole
|
|
38
|
+
* value of a single-output generation. Mirrors `outputOf` in
|
|
39
|
+
* `web/src/utils/nodeGenerations.ts`, except that a generation with several
|
|
40
|
+
* other handles yields nothing rather than the whole record.
|
|
41
|
+
*/
|
|
42
|
+
export declare function generationOutputFor(outputs: Record<string, unknown>, handle: string | null | undefined): unknown;
|
|
43
|
+
export declare function planPartialRun(graph: GraphData, nodeIds: readonly string[], deps: PartialRunDeps): Promise<PartialRunPlan>;
|
|
44
|
+
/** The asset fields a generation is rebuilt from. */
|
|
45
|
+
export interface GenerationAssetRow {
|
|
46
|
+
id: string;
|
|
47
|
+
job_id: string | null;
|
|
48
|
+
content_type: string;
|
|
49
|
+
size: number | null;
|
|
50
|
+
metadata: Record<string, unknown> | null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Rebuild a node's previous generation from the assets its auto-save wrote
|
|
54
|
+
* (`autoSaveAssets` in the websocket package), newest first. One generation is
|
|
55
|
+
* every asset one `generation_complete` produced: the same job and the same
|
|
56
|
+
* `generation_index`. Returns null when nothing usable is saved, so the node
|
|
57
|
+
* runs again:
|
|
58
|
+
*
|
|
59
|
+
* - `pinnedId` (the editor's `selected_generation`) names an asset not in
|
|
60
|
+
* `rows`;
|
|
61
|
+
* - a text generation was saved with a truncated inline copy;
|
|
62
|
+
* - a structured generation was too large to keep inline.
|
|
63
|
+
*/
|
|
64
|
+
export declare function previousGenerationFromAssets(rows: readonly GenerationAssetRow[], metadata: NodeMetadata, pinnedId?: string): PreviousGeneration | null;
|
|
65
|
+
//# sourceMappingURL=partial-run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"partial-run.d.ts","sourceRoot":"","sources":["../src/partial-run.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAQ,SAAS,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,uBAAuB,CAAC;AAExE,+DAA+D;AAC/D,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,YAAY,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,sBAAsB,CAAC,EAAE,CACvB,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,YAAY,KACnB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;CACzC;AAED,6DAA6D;AAC7D,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,SAAS,CAAC;IACjB,0CAA0C;IAC1C,GAAG,EAAE,MAAM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