@caupulican/pi-agent-core 0.90.12 → 0.91.2
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/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +28 -8
- package/dist/agent-loop.js.map +1 -1
- package/dist/degenerate-assistant-text.d.ts +18 -0
- package/dist/degenerate-assistant-text.d.ts.map +1 -0
- package/dist/degenerate-assistant-text.js +110 -0
- package/dist/degenerate-assistant-text.js.map +1 -0
- package/dist/tool-failure-memory.d.ts +2 -4
- package/dist/tool-failure-memory.d.ts.map +1 -1
- package/dist/tool-failure-memory.js +49 -3
- package/dist/tool-failure-memory.js.map +1 -1
- package/dist/tool-failure-recovery-gate.d.ts.map +1 -1
- package/dist/tool-failure-recovery-gate.js +7 -3
- package/dist/tool-failure-recovery-gate.js.map +1 -1
- package/dist/utils/truncate.d.ts +19 -0
- package/dist/utils/truncate.d.ts.map +1 -1
- package/dist/utils/truncate.js +124 -0
- package/dist/utils/truncate.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"degenerate-assistant-text.d.ts","sourceRoot":"","sources":["../src/degenerate-assistant-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,8GAA8G;AAC9G,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C,qGAAqG;AACrG,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAyD7C;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKjE;AAID,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAa9F;AAED,2EAA2E;AAC3E,wBAAgB,qCAAqC,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAExF;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAKtE"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Consecutive identical non-empty units (lines or sentences) at or above this run count are degeneration. */
|
|
2
|
+
export const DEGENERATE_REPEATED_LINE_MIN = 4;
|
|
3
|
+
/** Mid-stream abort once a generation loop is already this long; cheaper than waiting for `done`. */
|
|
4
|
+
export const DEGENERATE_STREAM_ABORT_RUN = 8;
|
|
5
|
+
function collapseRepeatedUnits(units, joinWith) {
|
|
6
|
+
if (units.length < DEGENERATE_REPEATED_LINE_MIN)
|
|
7
|
+
return units.join(joinWith);
|
|
8
|
+
const out = [];
|
|
9
|
+
let index = 0;
|
|
10
|
+
while (index < units.length) {
|
|
11
|
+
const unit = units[index];
|
|
12
|
+
let run = 1;
|
|
13
|
+
while (index + run < units.length && units[index + run] === unit)
|
|
14
|
+
run++;
|
|
15
|
+
if (unit.trim() !== "" && run >= DEGENERATE_REPEATED_LINE_MIN) {
|
|
16
|
+
out.push(unit);
|
|
17
|
+
index += run;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (index + 1 < units.length) {
|
|
21
|
+
const next = units[index + 1];
|
|
22
|
+
if (unit.trim() !== "" && next.trim() !== "" && unit !== next) {
|
|
23
|
+
let pairs = 1;
|
|
24
|
+
while (index + (pairs + 1) * 2 <= units.length &&
|
|
25
|
+
units[index + pairs * 2] === unit &&
|
|
26
|
+
units[index + pairs * 2 + 1] === next) {
|
|
27
|
+
pairs++;
|
|
28
|
+
}
|
|
29
|
+
if (pairs >= DEGENERATE_REPEATED_LINE_MIN) {
|
|
30
|
+
out.push(unit, next);
|
|
31
|
+
index += pairs * 2;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
out.push(unit);
|
|
37
|
+
index++;
|
|
38
|
+
}
|
|
39
|
+
return out.join(joinWith);
|
|
40
|
+
}
|
|
41
|
+
function maxRepeatedUnitRun(units) {
|
|
42
|
+
let maxRun = 1;
|
|
43
|
+
let run = 1;
|
|
44
|
+
for (let index = 1; index < units.length; index++) {
|
|
45
|
+
if (units[index] === units[index - 1] && units[index].trim() !== "") {
|
|
46
|
+
run++;
|
|
47
|
+
if (run > maxRun)
|
|
48
|
+
maxRun = run;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
run = 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return units.length === 0 ? 0 : maxRun;
|
|
55
|
+
}
|
|
56
|
+
function splitSentences(text) {
|
|
57
|
+
return text.split(/(?<=[.!?])\s+/);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Collapse consecutive identical assistant lines, period-2 ABAB line runs, and the same
|
|
61
|
+
* sentence repeated inside one paragraph. Session 01a0016f stored 551 copies of one
|
|
62
|
+
* sentence as a single line; newline-only collapse cannot see that.
|
|
63
|
+
*/
|
|
64
|
+
export function collapseRepeatedLines(text) {
|
|
65
|
+
const lineCollapsed = collapseRepeatedUnits(text.split("\n"), "\n");
|
|
66
|
+
return lineCollapsed
|
|
67
|
+
.split("\n")
|
|
68
|
+
.map((line) => collapseRepeatedUnits(splitSentences(line), " "))
|
|
69
|
+
.join("\n");
|
|
70
|
+
}
|
|
71
|
+
export function isDegenerateRepeatedText(text) {
|
|
72
|
+
return collapseRepeatedLines(text) !== text;
|
|
73
|
+
}
|
|
74
|
+
export function shouldAbortDegenerateStream(text) {
|
|
75
|
+
if (text.length < 400)
|
|
76
|
+
return false;
|
|
77
|
+
const sentences = splitSentences(text);
|
|
78
|
+
if (maxRepeatedUnitRun(sentences) >= DEGENERATE_STREAM_ABORT_RUN)
|
|
79
|
+
return true;
|
|
80
|
+
return maxRepeatedUnitRun(text.split("\n")) >= DEGENERATE_STREAM_ABORT_RUN;
|
|
81
|
+
}
|
|
82
|
+
const collapsedDegenerateMessages = new WeakSet();
|
|
83
|
+
export function collapseDegenerateAssistantMessage(message) {
|
|
84
|
+
let changed = false;
|
|
85
|
+
const content = message.content.map((block) => {
|
|
86
|
+
if (block.type !== "text")
|
|
87
|
+
return block;
|
|
88
|
+
const collapsed = collapseRepeatedLines(block.text);
|
|
89
|
+
if (collapsed === block.text)
|
|
90
|
+
return block;
|
|
91
|
+
changed = true;
|
|
92
|
+
return { ...block, text: collapsed };
|
|
93
|
+
});
|
|
94
|
+
if (!changed)
|
|
95
|
+
return message;
|
|
96
|
+
const next = { ...message, content };
|
|
97
|
+
collapsedDegenerateMessages.add(next);
|
|
98
|
+
return next;
|
|
99
|
+
}
|
|
100
|
+
/** True when this message is (or was collapsed from) a generation loop. */
|
|
101
|
+
export function isCollapsedDegenerateAssistantMessage(message) {
|
|
102
|
+
return collapsedDegenerateMessages.has(message);
|
|
103
|
+
}
|
|
104
|
+
export function assistantMessageText(message) {
|
|
105
|
+
return message.content
|
|
106
|
+
.filter((block) => block.type === "text")
|
|
107
|
+
.map((block) => block.text)
|
|
108
|
+
.join("\n");
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=degenerate-assistant-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"degenerate-assistant-text.js","sourceRoot":"","sources":["../src/degenerate-assistant-text.ts"],"names":[],"mappings":"AAEA,8GAA8G;AAC9G,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAE9C,qGAAqG;AACrG,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAE7C,SAAS,qBAAqB,CAAC,KAAwB,EAAE,QAAgB;IACxE,IAAI,KAAK,CAAC,MAAM,GAAG,4BAA4B;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7E,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,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AC9E,OAAO,2BAA2B,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC7D,OAAO,OAAO,CAAC,OAAO;SACpB,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;SACxC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","sourcesContent":["import type { AssistantMessage } from \"@caupulican/pi-ai/types\";\n\n/** Consecutive identical non-empty units (lines or sentences) at or above this run count are degeneration. */\nexport const DEGENERATE_REPEATED_LINE_MIN = 4;\n\n/** Mid-stream abort once a generation loop is already this long; cheaper than waiting for `done`. */\nexport const DEGENERATE_STREAM_ABORT_RUN = 8;\n\nfunction collapseRepeatedUnits(units: readonly string[], joinWith: string): string {\n\tif (units.length < DEGENERATE_REPEATED_LINE_MIN) return units.join(joinWith);\n\tconst out: string[] = [];\n\tlet index = 0;\n\twhile (index < units.length) {\n\t\tconst unit = units[index];\n\t\tlet run = 1;\n\t\twhile (index + run < units.length && units[index + run] === unit) run++;\n\t\tif (unit.trim() !== \"\" && run >= DEGENERATE_REPEATED_LINE_MIN) {\n\t\t\tout.push(unit);\n\t\t\tindex += run;\n\t\t\tcontinue;\n\t\t}\n\t\tif (index + 1 < units.length) {\n\t\t\tconst next = units[index + 1];\n\t\t\tif (unit.trim() !== \"\" && next.trim() !== \"\" && unit !== next) {\n\t\t\t\tlet pairs = 1;\n\t\t\t\twhile (\n\t\t\t\t\tindex + (pairs + 1) * 2 <= units.length &&\n\t\t\t\t\tunits[index + pairs * 2] === unit &&\n\t\t\t\t\tunits[index + pairs * 2 + 1] === next\n\t\t\t\t) {\n\t\t\t\t\tpairs++;\n\t\t\t\t}\n\t\t\t\tif (pairs >= DEGENERATE_REPEATED_LINE_MIN) {\n\t\t\t\t\tout.push(unit, next);\n\t\t\t\t\tindex += pairs * 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.push(unit);\n\t\tindex++;\n\t}\n\treturn out.join(joinWith);\n}\n\nfunction maxRepeatedUnitRun(units: readonly string[]): number {\n\tlet maxRun = 1;\n\tlet run = 1;\n\tfor (let index = 1; index < units.length; index++) {\n\t\tif (units[index] === units[index - 1] && units[index].trim() !== \"\") {\n\t\t\trun++;\n\t\t\tif (run > maxRun) maxRun = run;\n\t\t} else {\n\t\t\trun = 1;\n\t\t}\n\t}\n\treturn units.length === 0 ? 0 : maxRun;\n}\n\nfunction splitSentences(text: string): string[] {\n\treturn text.split(/(?<=[.!?])\\s+/);\n}\n\n/**\n * Collapse consecutive identical assistant lines, period-2 ABAB line runs, and the same\n * sentence repeated inside one paragraph. Session 01a0016f stored 551 copies of one\n * sentence as a single line; newline-only collapse cannot see that.\n */\nexport function collapseRepeatedLines(text: string): string {\n\tconst lineCollapsed = collapseRepeatedUnits(text.split(\"\\n\"), \"\\n\");\n\treturn lineCollapsed\n\t\t.split(\"\\n\")\n\t\t.map((line) => collapseRepeatedUnits(splitSentences(line), \" \"))\n\t\t.join(\"\\n\");\n}\n\nexport function isDegenerateRepeatedText(text: string): boolean {\n\treturn collapseRepeatedLines(text) !== text;\n}\n\nexport function shouldAbortDegenerateStream(text: string): boolean {\n\tif (text.length < 400) return false;\n\tconst sentences = splitSentences(text);\n\tif (maxRepeatedUnitRun(sentences) >= DEGENERATE_STREAM_ABORT_RUN) return true;\n\treturn maxRepeatedUnitRun(text.split(\"\\n\")) >= DEGENERATE_STREAM_ABORT_RUN;\n}\n\nconst collapsedDegenerateMessages = new WeakSet<AssistantMessage>();\n\nexport function collapseDegenerateAssistantMessage(message: AssistantMessage): AssistantMessage {\n\tlet changed = false;\n\tconst content = message.content.map((block) => {\n\t\tif (block.type !== \"text\") return block;\n\t\tconst collapsed = collapseRepeatedLines(block.text);\n\t\tif (collapsed === block.text) return block;\n\t\tchanged = true;\n\t\treturn { ...block, text: collapsed };\n\t});\n\tif (!changed) return message;\n\tconst next = { ...message, content };\n\tcollapsedDegenerateMessages.add(next);\n\treturn next;\n}\n\n/** True when this message is (or was collapsed from) a generation loop. */\nexport function isCollapsedDegenerateAssistantMessage(message: AssistantMessage): boolean {\n\treturn collapsedDegenerateMessages.has(message);\n}\n\nexport function assistantMessageText(message: AssistantMessage): string {\n\treturn message.content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n}\n"]}
|
|
@@ -37,16 +37,14 @@ export interface ToolFailureDirectiveDetails {
|
|
|
37
37
|
}
|
|
38
38
|
export type ToolFailureResultDetails = ToolFailureMemoryDetails | ToolFailureDirectiveDetails;
|
|
39
39
|
export type ToolFailureMemoryTracker = Map<string, ToolFailureMemoryRecord>;
|
|
40
|
-
/**
|
|
41
|
-
* Fingerprint a tool operation without materializing or retaining its serialized payload.
|
|
42
|
-
* Volatile identifiers normalize before hashing; short numbers and ordinary paths remain significant.
|
|
43
|
-
*/
|
|
44
40
|
export declare function normalizeToolSignature(pairs: Array<[string, unknown]>): string;
|
|
45
41
|
export declare function getToolExecutionKey(tool: string, args: unknown): string;
|
|
46
42
|
export declare function getToolFailureRecordExecutionKey(record: ToolFailureMemoryRecord): string | undefined;
|
|
47
43
|
export declare function getUnresolvedToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown): ToolFailureMemoryRecord | undefined;
|
|
48
44
|
export declare function readVisibleToolFailureCode(result: ToolResultMessage): string | undefined;
|
|
49
45
|
export declare function isClosedOperationFailureCode(code: string | undefined): boolean;
|
|
46
|
+
/** Failures that only a new owner prompt can clear. Do not restore their circuit across user turns. */
|
|
47
|
+
export declare function isPromptScopedFailureCode(code: string | undefined): boolean;
|
|
50
48
|
export declare function restoreToolFailureRecord(result: ToolResultMessage, tool: string, args: unknown): ToolFailureMemoryRecord;
|
|
51
49
|
export interface PairedToolResult {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G,oBAAoB,GAAG,SAAS,CAoB3F;AA4LD,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,wBAAwB,CAEjG;AAED,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,wBAAwB,EACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,gBAAgB,EACvB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,GAAE,gBAA4D,GACjE,uBAAuB,CAqDzB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAKrG;AA2BD,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,uBAAuB,EAC/B,SAAS,CAAC,EAAE,OAAO,GACjB,eAAe,CAAC,wBAAwB,CAAC,CAuB3C;AAED,wBAAgB,+BAA+B,CAC9C,MAAM,EAAE,uBAAuB,GAC7B,eAAe,CAAC,wBAAwB,CAAC,CAsB3C;AAED,wBAAgB,wCAAwC,CACvD,MAAM,EAAE,uBAAuB,EAC/B,UAAU,EAAE,MAAM,GAChB,eAAe,CAAC,wBAAwB,CAAC,CAiB3C;AAED,wBAAgB,yCAAyC,CACxD,MAAM,EAAE,uBAAuB,EAC/B,UAAU,EAAE,MAAM,GAChB,eAAe,CAAC,wBAAwB,CAAC,CAkB3C;AAcD,wBAAgB,0BAA0B,CACzC,QAAQ,EAAE,YAAY,EAAE,EACxB,YAAY,EAAE,MAAM,GAClB;IAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAqCpD"}
|
|
@@ -243,10 +243,49 @@ function boundedJsonPreview(value, maxChars) {
|
|
|
243
243
|
* Fingerprint a tool operation without materializing or retaining its serialized payload.
|
|
244
244
|
* Volatile identifiers normalize before hashing; short numbers and ordinary paths remain significant.
|
|
245
245
|
*/
|
|
246
|
+
/**
|
|
247
|
+
* Resource-envelope fields are not the operation. Changing `timeout` (or a sibling wait bound)
|
|
248
|
+
* must not mint a new execution identity — that is how a failed command is replayed forever.
|
|
249
|
+
*/
|
|
250
|
+
const OPERATION_ENVELOPE_KEYS = new Set([
|
|
251
|
+
"timeout",
|
|
252
|
+
"timeoutms",
|
|
253
|
+
"timeout_ms",
|
|
254
|
+
"timeoutsec",
|
|
255
|
+
"timeout_sec",
|
|
256
|
+
"timeoutseconds",
|
|
257
|
+
"timeout_seconds",
|
|
258
|
+
"maxwait",
|
|
259
|
+
"max_wait",
|
|
260
|
+
"maxwaitms",
|
|
261
|
+
"max_wait_ms",
|
|
262
|
+
"waitms",
|
|
263
|
+
"wait_ms",
|
|
264
|
+
"waitsec",
|
|
265
|
+
"wait_sec",
|
|
266
|
+
"waitseconds",
|
|
267
|
+
"wait_seconds",
|
|
268
|
+
]);
|
|
269
|
+
function omitOperationEnvelopeFields(value) {
|
|
270
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
271
|
+
return value;
|
|
272
|
+
const record = value;
|
|
273
|
+
let changed = false;
|
|
274
|
+
const next = {};
|
|
275
|
+
for (const [key, entry] of Object.entries(record)) {
|
|
276
|
+
if (OPERATION_ENVELOPE_KEYS.has(key.toLowerCase())) {
|
|
277
|
+
changed = true;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
next[key] = entry;
|
|
281
|
+
}
|
|
282
|
+
return changed ? next : value;
|
|
283
|
+
}
|
|
246
284
|
export function normalizeToolSignature(pairs) {
|
|
247
|
-
return structuredHash(pairs, true);
|
|
285
|
+
return structuredHash(pairs.map(([name, args]) => [name, omitOperationEnvelopeFields(args)]), true);
|
|
248
286
|
}
|
|
249
287
|
function toolOperationKey(tool, args, normalizeVolatile) {
|
|
288
|
+
const identityArgs = omitOperationEnvelopeFields(args);
|
|
250
289
|
const boundedTool = truncate(tool, MAX_TOOL_NAME_CHARS);
|
|
251
290
|
const hash = createSignatureHash();
|
|
252
291
|
const updateHashString = normalizeVolatile ? updateNormalizedHashString : updateExactHashString;
|
|
@@ -254,7 +293,7 @@ function toolOperationKey(tool, args, normalizeVolatile) {
|
|
|
254
293
|
// Preserve the stable structured-hash wire identity without allocating the two synthetic arrays.
|
|
255
294
|
updateHashRange(hash, "array:1[array:2[");
|
|
256
295
|
updateStructuredHash(hash, tool, active, 2, updateHashString);
|
|
257
|
-
updateStructuredHash(hash,
|
|
296
|
+
updateStructuredHash(hash, identityArgs, active, 2, updateHashString);
|
|
258
297
|
updateHashRange(hash, "];];");
|
|
259
298
|
const signature = renderSignatureHash(hash);
|
|
260
299
|
return `${boundedTool}:${signature}`;
|
|
@@ -292,6 +331,10 @@ export function readVisibleToolFailureCode(result) {
|
|
|
292
331
|
export function isClosedOperationFailureCode(code) {
|
|
293
332
|
return code === "operation_recovery_exhausted" || code === "recovery_exhausted";
|
|
294
333
|
}
|
|
334
|
+
/** Failures that only a new owner prompt can clear. Do not restore their circuit across user turns. */
|
|
335
|
+
export function isPromptScopedFailureCode(code) {
|
|
336
|
+
return code === "owner_authorization_required";
|
|
337
|
+
}
|
|
295
338
|
export function restoreToolFailureRecord(result, tool, args) {
|
|
296
339
|
const executionKey = getToolExecutionKey(tool, args);
|
|
297
340
|
const persisted = readFailureRecord(result.details);
|
|
@@ -404,8 +447,11 @@ function inferToolFailurePhase(state, failureCode) {
|
|
|
404
447
|
if (failureCode === "malformed_call" || failureCode === "unknown_tool" || failureCode === "invalid_arguments") {
|
|
405
448
|
return "validation";
|
|
406
449
|
}
|
|
407
|
-
if (failureCode === "blocked" ||
|
|
450
|
+
if (failureCode === "blocked" ||
|
|
451
|
+
failureCode === "permission_denied" ||
|
|
452
|
+
failureCode === "owner_authorization_required") {
|
|
408
453
|
return "policy";
|
|
454
|
+
}
|
|
409
455
|
if (failureCode === "preflight_error")
|
|
410
456
|
return "preflight";
|
|
411
457
|
if (failureCode === "aborted" || failureCode === "cancelled")
|