@selvajs/solve 2.0.0-beta.8 → 2.0.0
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 +17 -11
- package/dist/abort-CNJ8Sn4g.js +13 -0
- package/dist/abort-CNJ8Sn4g.js.map +1 -0
- package/dist/client.d.ts +34 -135
- package/dist/client.js +968 -1
- package/dist/client.js.map +1 -1
- package/dist/{outcome-DsNmx27P.d.ts → outcome-Bk9mnMi0.d.ts} +9 -28
- package/dist/outcome-DNrffAXp.js +169 -0
- package/dist/outcome-DNrffAXp.js.map +1 -0
- package/dist/server.d.ts +98 -230
- package/dist/server.js +984 -1
- package/dist/server.js.map +1 -1
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +1 -1
- package/package.json +16 -41
- package/dist/client.cjs +0 -2
- package/dist/client.cjs.map +0 -1
- package/dist/client.d.cts +0 -429
- package/dist/outcome-BOrAeRAQ.js +0 -2
- package/dist/outcome-BOrAeRAQ.js.map +0 -1
- package/dist/outcome-DUHQoZqq.cjs +0 -2
- package/dist/outcome-DUHQoZqq.cjs.map +0 -1
- package/dist/outcome-DsNmx27P.d.cts +0 -92
- package/dist/server.cjs +0 -2
- package/dist/server.cjs.map +0 -1
- package/dist/server.d.cts +0 -419
- package/dist/shared.cjs +0 -1
- package/dist/shared.d.cts +0 -3
- package/dist/solve-input-CUjVGYPC.d.cts +0 -11
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// src/shared/solve-fn.ts
|
|
2
|
+
/**
|
|
3
|
+
* The solve contract — what a solve returns and what a caller supplies to run one.
|
|
4
|
+
*
|
|
5
|
+
* Lives in `shared/` because both halves of the package speak it: `client/` calls a `SolveFn` and
|
|
6
|
+
* stores its `SolveResult`; `server/` produces the payload one is built from.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Marker the Grasshopper Message component prepends to a blocking error.
|
|
10
|
+
*
|
|
11
|
+
* Rhino.Compute flattens runtime messages to plain strings with no component attribution, so
|
|
12
|
+
* this is the only way that path can tell a deliberate block from any other solve error. The
|
|
13
|
+
* local WebSocket path carries `isGate` structurally and does not need it — but the component
|
|
14
|
+
* writes the marker unconditionally, because the same definition runs on both.
|
|
15
|
+
*
|
|
16
|
+
* Changing this string breaks blocking on deployed Selva for every already-published
|
|
17
|
+
* definition, since the text is baked into the .gh file's solve output, not the plugin.
|
|
18
|
+
*/
|
|
19
|
+
const SOLVE_BLOCKED_MARKER = "[Selva:blocked]";
|
|
20
|
+
/**
|
|
21
|
+
* Marker the Message component prepends to a remark or warning — the non-blocking levels.
|
|
22
|
+
*
|
|
23
|
+
* Same reason as `SOLVE_BLOCKED_MARKER`: on Rhino.Compute nothing structural survives, and the
|
|
24
|
+
* UI has to tell a message the author chose to write from an incidental Grasshopper warning.
|
|
25
|
+
* Definitions saved before this existed lack it, so the reader falls back to the component name.
|
|
26
|
+
*/
|
|
27
|
+
const SOLVE_AUTHORED_MARKER = "[Selva:msg]";
|
|
28
|
+
/**
|
|
29
|
+
* Marker for an authored message whose author chose Notify = Log.
|
|
30
|
+
*
|
|
31
|
+
* Still theirs — it keeps its attribution and its place in the message list — but it does not
|
|
32
|
+
* interrupt. Errors never carry it: their result is withheld, so they always interrupt.
|
|
33
|
+
*/
|
|
34
|
+
const SOLVE_LOG_ONLY_MARKER = "[Selva:log]";
|
|
35
|
+
// src/shared/compute-diagnostics.ts
|
|
36
|
+
/**
|
|
37
|
+
* Compute's per-message attribution suffix. Anchored to the end and requiring the parenthesised
|
|
38
|
+
* GUID, so an author who writes `component "x"` mid-sentence keeps their text intact.
|
|
39
|
+
*/
|
|
40
|
+
const ATTRIBUTION = /:\s*component\s+"([^"]*)"\s*\(([0-9a-fA-F-]{36}|\.\.\.)\)\s*$/;
|
|
41
|
+
/** The Selva Message component's own name, as `LogRuntimeMessages` reports it. */
|
|
42
|
+
const MESSAGE_COMPONENT_NAME = "Message";
|
|
43
|
+
/**
|
|
44
|
+
* Splits one Compute message string into the author's text and its attribution.
|
|
45
|
+
*
|
|
46
|
+
* Leaves the text alone when the suffix is absent — an exception thrown by a script component
|
|
47
|
+
* has no attribution and must not be truncated on a guess.
|
|
48
|
+
*/
|
|
49
|
+
function parseComputeMessage(raw) {
|
|
50
|
+
const blocked = raw.includes(SOLVE_BLOCKED_MARKER);
|
|
51
|
+
const logOnly = !blocked && raw.includes("[Selva:log]");
|
|
52
|
+
const authored = blocked || logOnly || raw.includes("[Selva:msg]");
|
|
53
|
+
let message = raw;
|
|
54
|
+
let source;
|
|
55
|
+
const attribution = ATTRIBUTION.exec(message);
|
|
56
|
+
if (attribution) {
|
|
57
|
+
source = attribution[1] || void 0;
|
|
58
|
+
message = message.slice(0, attribution.index);
|
|
59
|
+
}
|
|
60
|
+
if (authored) message = message.replace(SOLVE_BLOCKED_MARKER, "").replace(SOLVE_AUTHORED_MARKER, "").replace(SOLVE_LOG_ONLY_MARKER, "").replace(/^\s*\d+\.\s*Solution exception:\s*/, "");
|
|
61
|
+
return {
|
|
62
|
+
message: message.replace(/\s{2,}/g, " ").trim(),
|
|
63
|
+
source,
|
|
64
|
+
blocked,
|
|
65
|
+
authored,
|
|
66
|
+
logOnly
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Rebuilds structured diagnostics from Compute's `errors`/`warnings` arrays.
|
|
71
|
+
*
|
|
72
|
+
* `isGate` comes from the marker the component writes. The component-name fallback is for
|
|
73
|
+
* definitions saved before the non-blocking marker existed; `obj.Name` is the component's type
|
|
74
|
+
* name, not its nickname, so renaming one on the canvas cannot change how it behaves.
|
|
75
|
+
*/
|
|
76
|
+
function parseComputeDiagnostics(errors, warnings) {
|
|
77
|
+
const build = (raw, level) => {
|
|
78
|
+
const { message, source, authored, logOnly } = parseComputeMessage(raw);
|
|
79
|
+
const isGate = (authored || source === MESSAGE_COMPONENT_NAME) && !logOnly;
|
|
80
|
+
return {
|
|
81
|
+
level,
|
|
82
|
+
message,
|
|
83
|
+
...source ? { source } : {},
|
|
84
|
+
...isGate ? { isGate } : {}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
return [...errors.map((raw) => build(raw, "error")), ...warnings.map((raw) => build(raw, "warning"))];
|
|
88
|
+
}
|
|
89
|
+
// src/shared/outcome.ts
|
|
90
|
+
function isLevel(value) {
|
|
91
|
+
return value === "error" || value === "warning" || value === "remark";
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* One wire diagnostic, normalized: an unknown level reads as a remark, text is trimmed, and
|
|
95
|
+
* `source`/`isGate` are omitted rather than null or false. Null when it carries no message.
|
|
96
|
+
*/
|
|
97
|
+
function decodeDiagnostic(entry) {
|
|
98
|
+
if (!entry || typeof entry !== "object") return null;
|
|
99
|
+
const d = entry;
|
|
100
|
+
const message = typeof d.message === "string" ? d.message.trim() : "";
|
|
101
|
+
if (!message) return null;
|
|
102
|
+
const source = typeof d.source === "string" && d.source ? d.source : void 0;
|
|
103
|
+
return {
|
|
104
|
+
level: isLevel(d.level) ? d.level : "remark",
|
|
105
|
+
message,
|
|
106
|
+
...source ? { source } : {},
|
|
107
|
+
...d.isGate === true ? { isGate: true } : {}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function normalizeOutcome(entries, blocked, aborted) {
|
|
111
|
+
const seen = /* @__PURE__ */ new Set();
|
|
112
|
+
const diagnostics = [];
|
|
113
|
+
for (const entry of entries) {
|
|
114
|
+
const d = decodeDiagnostic(entry);
|
|
115
|
+
if (!d) continue;
|
|
116
|
+
const key = `${d.level}\u0000${d.message}\u0000${d.source ?? ""}\u0000${d.isGate === true}`;
|
|
117
|
+
if (seen.has(key)) continue;
|
|
118
|
+
seen.add(key);
|
|
119
|
+
diagnostics.push(d);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
diagnostics,
|
|
123
|
+
blocked: blocked || aborted,
|
|
124
|
+
aborted
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Normalizes a wire outcome with `decodeDiagnostic`, dropping exact repeats, so the same verdict
|
|
129
|
+
* decodes to the same object from either transport. Null when `wire` is not an outcome at all;
|
|
130
|
+
* the caller then falls back. A verdict without a diagnostic list still counts: reading a refusal
|
|
131
|
+
* as "no outcome" would let the solve through.
|
|
132
|
+
*/
|
|
133
|
+
function decodeOutcome(wire) {
|
|
134
|
+
if (!wire || typeof wire !== "object") return null;
|
|
135
|
+
const { diagnostics, blocked, aborted } = wire;
|
|
136
|
+
const hasList = Array.isArray(diagnostics);
|
|
137
|
+
if (!hasList && blocked === void 0 && aborted === void 0) return null;
|
|
138
|
+
const isTrue = (flag) => flag === true || flag === "true";
|
|
139
|
+
return normalizeOutcome(hasList ? diagnostics : [], isTrue(blocked), isTrue(aborted));
|
|
140
|
+
}
|
|
141
|
+
/** The legacy verdict, read from Compute's flattened `errors`/`warnings` and their markers. */
|
|
142
|
+
function outcomeFromComputeMessages(errors, warnings) {
|
|
143
|
+
const strings = (list) => list.filter((m) => typeof m === "string");
|
|
144
|
+
const errorText = strings(errors);
|
|
145
|
+
return normalizeOutcome(parseComputeDiagnostics(errorText, strings(warnings)), errorText.some((e) => e.includes(SOLVE_BLOCKED_MARKER)), false);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Builds the result a driver reports. A blocked or aborted outcome is "no result" whatever the
|
|
149
|
+
* transport sent along: no outputs, no `source` (it holds the withheld outputs), and an empty mesh
|
|
150
|
+
* list so the viewer clears. `errors` and `warnings` are derived from the diagnostics for hosts
|
|
151
|
+
* that only want text.
|
|
152
|
+
*/
|
|
153
|
+
function finalizeResult(partial, outcome) {
|
|
154
|
+
const rejected = outcome.blocked || outcome.aborted;
|
|
155
|
+
const meshes = rejected ? [] : partial.meshes;
|
|
156
|
+
return {
|
|
157
|
+
outputs: rejected ? {} : partial.outputs,
|
|
158
|
+
...meshes !== void 0 ? { meshes } : {},
|
|
159
|
+
errors: outcome.diagnostics.filter((d) => d.level === "error").map((d) => d.message),
|
|
160
|
+
warnings: outcome.diagnostics.filter((d) => d.level === "warning").map((d) => d.message),
|
|
161
|
+
diagnostics: outcome.diagnostics,
|
|
162
|
+
blocked: outcome.blocked,
|
|
163
|
+
aborted: outcome.aborted,
|
|
164
|
+
...partial.source !== void 0 && !rejected ? { source: partial.source } : {}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
export { outcomeFromComputeMessages as i, decodeOutcome as n, finalizeResult as r, decodeDiagnostic as t };
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=outcome-DNrffAXp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outcome-DNrffAXp.js","names":[],"sources":["../src/shared/solve-fn.ts","../src/shared/compute-diagnostics.ts","../src/shared/outcome.ts"],"sourcesContent":["import type { SolveDiagnostic } from '@selvajs/schemas';\n\n/**\n * The solve contract — what a solve returns and what a caller supplies to run one.\n *\n * Lives in `shared/` because both halves of the package speak it: `client/` calls a `SolveFn` and\n * stores its `SolveResult`; `server/` produces the payload one is built from.\n */\n\n/**\n * Marker the Grasshopper Message component prepends to a blocking error.\n *\n * Rhino.Compute flattens runtime messages to plain strings with no component attribution, so\n * this is the only way that path can tell a deliberate block from any other solve error. The\n * local WebSocket path carries `isGate` structurally and does not need it — but the component\n * writes the marker unconditionally, because the same definition runs on both.\n *\n * Changing this string breaks blocking on deployed Selva for every already-published\n * definition, since the text is baked into the .gh file's solve output, not the plugin.\n */\nexport const SOLVE_BLOCKED_MARKER = '[Selva:blocked]';\n\n/**\n * Marker the Message component prepends to a remark or warning — the non-blocking levels.\n *\n * Same reason as `SOLVE_BLOCKED_MARKER`: on Rhino.Compute nothing structural survives, and the\n * UI has to tell a message the author chose to write from an incidental Grasshopper warning.\n * Definitions saved before this existed lack it, so the reader falls back to the component name.\n */\nexport const SOLVE_AUTHORED_MARKER = '[Selva:msg]';\n\n/**\n * Marker for an authored message whose author chose Notify = Log.\n *\n * Still theirs — it keeps its attribution and its place in the message list — but it does not\n * interrupt. Errors never carry it: their result is withheld, so they always interrupt.\n */\nexport const SOLVE_LOG_ONLY_MARKER = '[Selva:log]';\n\n/**\n * One message a solve raised, with who raised it and whether it was deliberate (`isGate`).\n * Generated from `wire-schema.json`; both transports decode into it (see `outcome.ts`).\n */\nexport type { SolveDiagnostic };\n\n/**\n * `TMesh` is deliberately opaque and defaults to `unknown`: this package never inspects meshes, and\n * typing them would drag a renderer dependency into a package whose whole point is not having one.\n * The app that owns assembly (parse → `THREE.Object3D[]`) is the only place that knows the concrete\n * type, and it narrows by writing `SolveResult<THREE.Object3D>` at its own seam.\n */\nexport interface SolveResult<TMesh = unknown, TSource = unknown> {\n\toutputs: Record<string, unknown>;\n\tmeshes?: TMesh[];\n\terrors?: string[];\n\twarnings?: string[];\n\t/** Structured form of `errors`/`warnings`, including remarks. Absent from transports that report neither. */\n\tdiagnostics?: SolveDiagnostic[];\n\t/**\n\t * The definition refused this solve — a guard in the definition raised an error and its\n\t * outputs were withheld deliberately. Distinct from an errored solve that still returned\n\t * values, and from a transport failure: the solve ran and its answer is \"no\". Consumers\n\t * should show `errors` instead of treating the empty outputs as a result.\n\t */\n\tblocked?: boolean;\n\t/**\n\t * The solve was stopped before it finished. Always also `blocked`: what computed before\n\t * the stop is not a result. Absent from a transport that cannot tell.\n\t */\n\taborted?: boolean;\n\t/**\n\t * The unparsed payload this result was built from, passed through verbatim. Opaque here for the\n\t * same reason as `TMesh`: a consumer that must persist or re-submit exactly what it showed the\n\t * user narrows it at its own seam. Travels with the result through the driver's memo, so a\n\t * cached hit carries the source that produced it. Unlike `meshes` it needs no ownership policy —\n\t * it is inert data, not a GPU-backed handle.\n\t *\n\t * Supplied by the `SolveFn`, so it is present only when the one in use sets it\n\t * (`createComputeFetchSolveFn` does). A transport with no raw payload to hand back leaves it\n\t * absent — see `values` on telling absent from unsupported.\n\t */\n\tsource?: TSource;\n\t/**\n\t * The input set that produced this result, stamped by the driver rather than the `SolveFn` — a\n\t * memo hit never calls the `SolveFn`, so a consumer reading values captured inside it would pair\n\t * the on-screen result with whatever solved last. Keeping the pair atomic is the point: a commit\n\t * path holding a `SolveResult` cannot mismatch artifact and inputs.\n\t *\n\t * Present only from a driver that owns a request/response pair (`createRequestResponseDriver`).\n\t * A push driver cannot attribute an incoming frame to a request and must leave this absent\n\t * rather than guess — so `undefined` means \"this transport does not supply it\", not \"no solve\n\t * yet\", and a consumer that needs the pair requires a request/response driver. See `SolveDriver`.\n\t */\n\tvalues?: Record<string, unknown>;\n}\n\n/** Implementations should listen to `signal` and abort/clean up when it fires. */\nexport type SolveFn<TMesh = unknown, TSource = unknown> = (\n\tvalues: Record<string, unknown>,\n\tsignal: AbortSignal\n) => Promise<SolveResult<TMesh, TSource>>;\n","// Rhino.Compute reports runtime messages as flat strings, so everything the UI needs to tell a\n// deliberate message from incidental noise has to be recovered from the text. This is the one\n// place that parsing happens.\n//\n// Two decorations are applied by the server, in this order:\n// \"<author's text>: component \\\"<Name>\\\" (<guid>)\" — LogRuntimeMessages, every message\n// \"<n>. Solution exception:<marker> ...\" — the numbered-error wrapper\n// The local WebSocket path carries the same facts structurally and never comes through here.\n\nimport {\n\tSOLVE_AUTHORED_MARKER,\n\tSOLVE_BLOCKED_MARKER,\n\tSOLVE_LOG_ONLY_MARKER,\n\ttype SolveDiagnostic\n} from './solve-fn.js';\n\n/**\n * Compute's per-message attribution suffix. Anchored to the end and requiring the parenthesised\n * GUID, so an author who writes `component \"x\"` mid-sentence keeps their text intact.\n */\nconst ATTRIBUTION = /:\\s*component\\s+\"([^\"]*)\"\\s*\\(([0-9a-fA-F-]{36}|\\.\\.\\.)\\)\\s*$/;\n\n/** The Selva Message component's own name, as `LogRuntimeMessages` reports it. */\nconst MESSAGE_COMPONENT_NAME = 'Message';\n\nexport interface ParsedComputeMessage {\n\t/** The author's text, with the attribution suffix and any marker removed. */\n\tmessage: string;\n\t/** Component name from the attribution suffix, when present. */\n\tsource?: string;\n\t/** Carried the block marker: a Message component refused the solve. */\n\tblocked: boolean;\n\t/** Carried any marker: a Message component wrote this. */\n\tauthored: boolean;\n\t/** The author chose Notify = Log: list it, but do not interrupt. */\n\tlogOnly: boolean;\n}\n\n/**\n * Splits one Compute message string into the author's text and its attribution.\n *\n * Leaves the text alone when the suffix is absent — an exception thrown by a script component\n * has no attribution and must not be truncated on a guess.\n */\nexport function parseComputeMessage(raw: string): ParsedComputeMessage {\n\tconst blocked = raw.includes(SOLVE_BLOCKED_MARKER);\n\tconst logOnly = !blocked && raw.includes(SOLVE_LOG_ONLY_MARKER);\n\tconst authored = blocked || logOnly || raw.includes(SOLVE_AUTHORED_MARKER);\n\tlet message = raw;\n\n\tlet source: string | undefined;\n\tconst attribution = ATTRIBUTION.exec(message);\n\tif (attribution) {\n\t\tsource = attribution[1] || undefined;\n\t\tmessage = message.slice(0, attribution.index);\n\t}\n\n\tif (authored) {\n\t\tmessage = message\n\t\t\t.replace(SOLVE_BLOCKED_MARKER, '')\n\t\t\t.replace(SOLVE_AUTHORED_MARKER, '')\n\t\t\t.replace(SOLVE_LOG_ONLY_MARKER, '')\n\t\t\t// The numbered wrapper reads as noise next to the author's own sentence. Dropped only\n\t\t\t// when a marker proves the text is one of ours.\n\t\t\t.replace(/^\\s*\\d+\\.\\s*Solution exception:\\s*/, '');\n\t}\n\n\treturn { message: message.replace(/\\s{2,}/g, ' ').trim(), source, blocked, authored, logOnly };\n}\n\n/**\n * Rebuilds structured diagnostics from Compute's `errors`/`warnings` arrays.\n *\n * `isGate` comes from the marker the component writes. The component-name fallback is for\n * definitions saved before the non-blocking marker existed; `obj.Name` is the component's type\n * name, not its nickname, so renaming one on the canvas cannot change how it behaves.\n */\nexport function parseComputeDiagnostics(\n\terrors: readonly string[],\n\twarnings: readonly string[]\n): SolveDiagnostic[] {\n\tconst build = (raw: string, level: 'error' | 'warning'): SolveDiagnostic => {\n\t\tconst { message, source, authored, logOnly } = parseComputeMessage(raw);\n\t\tconst isGate = (authored || source === MESSAGE_COMPONENT_NAME) && !logOnly;\n\t\treturn { level, message, ...(source ? { source } : {}), ...(isGate ? { isGate } : {}) };\n\t};\n\treturn [\n\t\t...errors.map((raw) => build(raw, 'error')),\n\t\t...warnings.map((raw) => build(raw, 'warning'))\n\t];\n}\n","// The one place a solve's verdict becomes a `SolveResult`. The plugin decides the verdict\n// (`SolveOutcome`: diagnostics, blocked, aborted) once, and both transports carry it: the local\n// `outputs` envelope and the VektorNode fork's `selva` block. Each driver decodes it here, so a\n// rule about what a verdict means is written once rather than once per transport.\n//\n// A Compute response without a `selva` block (stock server, older plugin) falls back to\n// `outcomeFromComputeMessages`, which recovers what it can from the flattened strings. It cannot\n// see remarks or an abort.\n\nimport type { SolveOutcome } from '@selvajs/schemas';\nimport { parseComputeDiagnostics } from './compute-diagnostics.js';\nimport { SOLVE_BLOCKED_MARKER, type SolveDiagnostic, type SolveResult } from './solve-fn.js';\n\nexport type { SolveOutcome };\n\nfunction isLevel(value: unknown): value is SolveDiagnostic['level'] {\n\treturn value === 'error' || value === 'warning' || value === 'remark';\n}\n\n/**\n * One wire diagnostic, normalized: an unknown level reads as a remark, text is trimmed, and\n * `source`/`isGate` are omitted rather than null or false. Null when it carries no message.\n */\nexport function decodeDiagnostic(entry: unknown): SolveDiagnostic | null {\n\tif (!entry || typeof entry !== 'object') return null;\n\tconst d = entry as Record<string, unknown>;\n\tconst message = typeof d.message === 'string' ? d.message.trim() : '';\n\tif (!message) return null;\n\tconst source = typeof d.source === 'string' && d.source ? d.source : undefined;\n\treturn {\n\t\tlevel: isLevel(d.level) ? d.level : 'remark',\n\t\tmessage,\n\t\t...(source ? { source } : {}),\n\t\t...(d.isGate === true ? { isGate: true } : {})\n\t};\n}\n\nfunction normalizeOutcome(\n\tentries: readonly unknown[],\n\tblocked: boolean,\n\taborted: boolean\n): SolveOutcome {\n\tconst seen = new Set<string>();\n\tconst diagnostics: SolveDiagnostic[] = [];\n\tfor (const entry of entries) {\n\t\tconst d = decodeDiagnostic(entry);\n\t\tif (!d) continue;\n\t\tconst key = `${d.level}\\u0000${d.message}\\u0000${d.source ?? ''}\\u0000${d.isGate === true}`;\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tdiagnostics.push(d);\n\t}\n\treturn { diagnostics, blocked: blocked || aborted, aborted };\n}\n\n/**\n * Normalizes a wire outcome with `decodeDiagnostic`, dropping exact repeats, so the same verdict\n * decodes to the same object from either transport. Null when `wire` is not an outcome at all;\n * the caller then falls back. A verdict without a diagnostic list still counts: reading a refusal\n * as \"no outcome\" would let the solve through.\n */\nexport function decodeOutcome(wire: unknown): SolveOutcome | null {\n\tif (!wire || typeof wire !== 'object') return null;\n\tconst { diagnostics, blocked, aborted } = wire as Record<string, unknown>;\n\tconst hasList = Array.isArray(diagnostics);\n\tif (!hasList && blocked === undefined && aborted === undefined) return null;\n\t// `'true'` too: a flag that arrives stringified must fail closed, not let a refusal through.\n\tconst isTrue = (flag: unknown) => flag === true || flag === 'true';\n\treturn normalizeOutcome(hasList ? diagnostics : [], isTrue(blocked), isTrue(aborted));\n}\n\n/** The legacy verdict, read from Compute's flattened `errors`/`warnings` and their markers. */\nexport function outcomeFromComputeMessages(\n\terrors: readonly unknown[],\n\twarnings: readonly unknown[]\n): SolveOutcome {\n\tconst strings = (list: readonly unknown[]) => list.filter((m) => typeof m === 'string');\n\tconst errorText = strings(errors);\n\treturn normalizeOutcome(\n\t\tparseComputeDiagnostics(errorText, strings(warnings)),\n\t\t// Substring, not prefix: the server numbers each entry (\"1. Solution exception: ...\").\n\t\terrorText.some((e) => e.includes(SOLVE_BLOCKED_MARKER)),\n\t\tfalse\n\t);\n}\n\n/**\n * Builds the result a driver reports. A blocked or aborted outcome is \"no result\" whatever the\n * transport sent along: no outputs, no `source` (it holds the withheld outputs), and an empty mesh\n * list so the viewer clears. `errors` and `warnings` are derived from the diagnostics for hosts\n * that only want text.\n */\nexport function finalizeResult<TMesh, TSource>(\n\tpartial: { outputs: Record<string, unknown>; meshes?: TMesh[]; source?: TSource },\n\toutcome: SolveOutcome\n): SolveResult<TMesh, TSource> {\n\tconst rejected = outcome.blocked || outcome.aborted;\n\tconst meshes = rejected ? [] : partial.meshes;\n\treturn {\n\t\toutputs: rejected ? {} : partial.outputs,\n\t\t...(meshes !== undefined ? { meshes } : {}),\n\t\terrors: outcome.diagnostics.filter((d) => d.level === 'error').map((d) => d.message),\n\t\twarnings: outcome.diagnostics.filter((d) => d.level === 'warning').map((d) => d.message),\n\t\tdiagnostics: outcome.diagnostics,\n\t\tblocked: outcome.blocked,\n\t\taborted: outcome.aborted,\n\t\t...(partial.source !== undefined && !rejected ? { source: partial.source } : {})\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAa,uBAAuB;;;;;;;;AASpC,MAAa,wBAAwB;;;;;;;AAQrC,MAAa,wBAAwB;;;;;;ACjBrC,MAAM,cAAc;;AAGpB,MAAM,yBAAyB;;;;;;;AAqB/B,SAAgB,oBAAoB,KAAmC;CACtE,MAAM,UAAU,IAAI,SAAS,oBAAoB;CACjD,MAAM,UAAU,CAAC,WAAW,IAAI,SAAA,aAA8B;CAC9D,MAAM,WAAW,WAAW,WAAW,IAAI,SAAA,aAA8B;CACzE,IAAI,UAAU;CAEd,IAAI;CACJ,MAAM,cAAc,YAAY,KAAK,OAAO;CAC5C,IAAI,aAAa;EAChB,SAAS,YAAY,MAAM,KAAA;EAC3B,UAAU,QAAQ,MAAM,GAAG,YAAY,KAAK;CAC7C;CAEA,IAAI,UACH,UAAU,QACR,QAAQ,sBAAsB,EAAE,CAAC,CACjC,QAAQ,uBAAuB,EAAE,CAAC,CAClC,QAAQ,uBAAuB,EAAE,CAAC,CAGlC,QAAQ,sCAAsC,EAAE;CAGnD,OAAO;EAAE,SAAS,QAAQ,QAAQ,WAAW,GAAG,CAAC,CAAC,KAAK;EAAG;EAAQ;EAAS;EAAU;CAAQ;AAC9F;;;;;;;;AASA,SAAgB,wBACf,QACA,UACoB;CACpB,MAAM,SAAS,KAAa,UAAgD;EAC3E,MAAM,EAAE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