@buoy-gg/agent-core 7.0.34 → 7.0.36
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 +10 -7
- package/lib/commonjs/blocks/receipts.js +83 -24
- package/lib/commonjs/blocks/receipts.js.map +1 -1
- package/lib/commonjs/blocks/runId.js +31 -0
- package/lib/commonjs/blocks/runId.js.map +1 -0
- package/lib/commonjs/blocks/types.js +23 -2
- package/lib/commonjs/blocks/types.js.map +1 -1
- package/lib/commonjs/blocks/uiTool.js +426 -12
- package/lib/commonjs/blocks/uiTool.js.map +1 -1
- package/lib/commonjs/catalog/catalog.g.js +121 -43
- package/lib/commonjs/catalog/catalog.g.js.map +1 -1
- package/lib/commonjs/catalog/catalog.source.json +121 -45
- package/lib/commonjs/catalog/catalog.types.g.js +44 -0
- package/lib/commonjs/catalog/catalog.types.g.js.map +1 -0
- package/lib/commonjs/catalog/normalizeParams.js +333 -0
- package/lib/commonjs/catalog/normalizeParams.js.map +1 -0
- package/lib/commonjs/catalog/signature.js +68 -0
- package/lib/commonjs/catalog/signature.js.map +1 -0
- package/lib/commonjs/catalog/snapshotReads.js +13 -6
- package/lib/commonjs/catalog/snapshotReads.js.map +1 -1
- package/lib/commonjs/catalog/toProviderTools.js +41 -5
- package/lib/commonjs/catalog/toProviderTools.js.map +1 -1
- package/lib/commonjs/context/buildContextPack.js +367 -19
- package/lib/commonjs/context/buildContextPack.js.map +1 -1
- package/lib/commonjs/effects/digest.js +34 -0
- package/lib/commonjs/effects/digest.js.map +1 -0
- package/lib/commonjs/effects/ledger.js +85 -1
- package/lib/commonjs/effects/ledger.js.map +1 -1
- package/lib/commonjs/engine/askGate.js +287 -0
- package/lib/commonjs/engine/askGate.js.map +1 -0
- package/lib/commonjs/engine/effectFor.js +82 -1
- package/lib/commonjs/engine/effectFor.js.map +1 -1
- package/lib/commonjs/engine/historyBudget.js +260 -0
- package/lib/commonjs/engine/historyBudget.js.map +1 -0
- package/lib/commonjs/engine/runAgentTurn.js +958 -88
- package/lib/commonjs/engine/runAgentTurn.js.map +1 -1
- package/lib/commonjs/engine/systemPrompt.js +72 -8
- package/lib/commonjs/engine/systemPrompt.js.map +1 -1
- package/lib/commonjs/engine/textToolCalls.js +276 -0
- package/lib/commonjs/engine/textToolCalls.js.map +1 -0
- package/lib/commonjs/index.js +81 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/policy/labels.js +19 -3
- package/lib/commonjs/policy/labels.js.map +1 -1
- package/lib/commonjs/policy/policy.js +6 -1
- package/lib/commonjs/policy/policy.js.map +1 -1
- package/lib/commonjs/policy/redact.js +42 -5
- package/lib/commonjs/policy/redact.js.map +1 -1
- package/lib/commonjs/providers/anthropic.js +340 -174
- package/lib/commonjs/providers/anthropic.js.map +1 -1
- package/lib/commonjs/providers/openai.js +229 -103
- package/lib/commonjs/providers/openai.js.map +1 -1
- package/lib/commonjs/providers/sse.js +164 -29
- package/lib/commonjs/providers/sse.js.map +1 -1
- package/lib/commonjs/providers/streamTimer.js +123 -0
- package/lib/commonjs/providers/streamTimer.js.map +1 -0
- package/lib/commonjs/providers/transport.js +107 -0
- package/lib/commonjs/providers/transport.js.map +1 -0
- package/lib/commonjs/providers/xhrStream.js +209 -0
- package/lib/commonjs/providers/xhrStream.js.map +1 -0
- package/lib/commonjs/session.js +245 -52
- package/lib/commonjs/session.js.map +1 -1
- package/lib/module/blocks/receipts.js +83 -24
- package/lib/module/blocks/receipts.js.map +1 -1
- package/lib/module/blocks/runId.js +26 -0
- package/lib/module/blocks/runId.js.map +1 -0
- package/lib/module/blocks/types.js +23 -2
- package/lib/module/blocks/types.js.map +1 -1
- package/lib/module/blocks/uiTool.js +424 -12
- package/lib/module/blocks/uiTool.js.map +1 -1
- package/lib/module/catalog/catalog.g.js +121 -43
- package/lib/module/catalog/catalog.g.js.map +1 -1
- package/lib/module/catalog/catalog.source.json +121 -45
- package/lib/module/catalog/catalog.types.g.js +40 -0
- package/lib/module/catalog/catalog.types.g.js.map +1 -0
- package/lib/module/catalog/normalizeParams.js +327 -0
- package/lib/module/catalog/normalizeParams.js.map +1 -0
- package/lib/module/catalog/signature.js +63 -0
- package/lib/module/catalog/signature.js.map +1 -0
- package/lib/module/catalog/snapshotReads.js +13 -6
- package/lib/module/catalog/snapshotReads.js.map +1 -1
- package/lib/module/catalog/toProviderTools.js +41 -5
- package/lib/module/catalog/toProviderTools.js.map +1 -1
- package/lib/module/context/buildContextPack.js +366 -19
- package/lib/module/context/buildContextPack.js.map +1 -1
- package/lib/module/effects/digest.js +29 -0
- package/lib/module/effects/digest.js.map +1 -0
- package/lib/module/effects/ledger.js +85 -1
- package/lib/module/effects/ledger.js.map +1 -1
- package/lib/module/engine/askGate.js +280 -0
- package/lib/module/engine/askGate.js.map +1 -0
- package/lib/module/engine/effectFor.js +83 -1
- package/lib/module/engine/effectFor.js.map +1 -1
- package/lib/module/engine/historyBudget.js +251 -0
- package/lib/module/engine/historyBudget.js.map +1 -0
- package/lib/module/engine/runAgentTurn.js +954 -88
- package/lib/module/engine/runAgentTurn.js.map +1 -1
- package/lib/module/engine/systemPrompt.js +71 -8
- package/lib/module/engine/systemPrompt.js.map +1 -1
- package/lib/module/engine/textToolCalls.js +270 -0
- package/lib/module/engine/textToolCalls.js.map +1 -0
- package/lib/module/index.js +7 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/policy/labels.js +19 -3
- package/lib/module/policy/labels.js.map +1 -1
- package/lib/module/policy/policy.js +6 -1
- package/lib/module/policy/policy.js.map +1 -1
- package/lib/module/policy/redact.js +42 -5
- package/lib/module/policy/redact.js.map +1 -1
- package/lib/module/providers/anthropic.js +341 -175
- package/lib/module/providers/anthropic.js.map +1 -1
- package/lib/module/providers/openai.js +230 -104
- package/lib/module/providers/openai.js.map +1 -1
- package/lib/module/providers/sse.js +160 -29
- package/lib/module/providers/sse.js.map +1 -1
- package/lib/module/providers/streamTimer.js +118 -0
- package/lib/module/providers/streamTimer.js.map +1 -0
- package/lib/module/providers/transport.js +103 -0
- package/lib/module/providers/transport.js.map +1 -0
- package/lib/module/providers/xhrStream.js +204 -0
- package/lib/module/providers/xhrStream.js.map +1 -0
- package/lib/module/session.js +228 -54
- package/lib/module/session.js.map +1 -1
- package/lib/typescript/blocks/receipts.d.ts +5 -10
- package/lib/typescript/blocks/receipts.d.ts.map +1 -1
- package/lib/typescript/blocks/runId.d.ts +20 -0
- package/lib/typescript/blocks/runId.d.ts.map +1 -0
- package/lib/typescript/blocks/types.d.ts +23 -2
- package/lib/typescript/blocks/types.d.ts.map +1 -1
- package/lib/typescript/blocks/uiTool.d.ts +11 -2
- package/lib/typescript/blocks/uiTool.d.ts.map +1 -1
- package/lib/typescript/catalog/catalog.g.d.ts.map +1 -1
- package/lib/typescript/catalog/catalog.types.g.d.ts +40 -0
- package/lib/typescript/catalog/catalog.types.g.d.ts.map +1 -0
- package/lib/typescript/catalog/normalizeParams.d.ts +43 -0
- package/lib/typescript/catalog/normalizeParams.d.ts.map +1 -0
- package/lib/typescript/catalog/signature.d.ts +29 -0
- package/lib/typescript/catalog/signature.d.ts.map +1 -0
- package/lib/typescript/catalog/snapshotReads.d.ts.map +1 -1
- package/lib/typescript/catalog/toProviderTools.d.ts +28 -15
- package/lib/typescript/catalog/toProviderTools.d.ts.map +1 -1
- package/lib/typescript/context/buildContextPack.d.ts +24 -2
- package/lib/typescript/context/buildContextPack.d.ts.map +1 -1
- package/lib/typescript/effects/digest.d.ts +10 -0
- package/lib/typescript/effects/digest.d.ts.map +1 -0
- package/lib/typescript/effects/ledger.d.ts +55 -0
- package/lib/typescript/effects/ledger.d.ts.map +1 -1
- package/lib/typescript/engine/askGate.d.ts +29 -0
- package/lib/typescript/engine/askGate.d.ts.map +1 -0
- package/lib/typescript/engine/effectFor.d.ts +6 -1
- package/lib/typescript/engine/effectFor.d.ts.map +1 -1
- package/lib/typescript/engine/historyBudget.d.ts +92 -0
- package/lib/typescript/engine/historyBudget.d.ts.map +1 -0
- package/lib/typescript/engine/runAgentTurn.d.ts +115 -1
- package/lib/typescript/engine/runAgentTurn.d.ts.map +1 -1
- package/lib/typescript/engine/systemPrompt.d.ts +41 -0
- package/lib/typescript/engine/systemPrompt.d.ts.map +1 -1
- package/lib/typescript/engine/textToolCalls.d.ts +58 -0
- package/lib/typescript/engine/textToolCalls.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -5
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/policy/labels.d.ts.map +1 -1
- package/lib/typescript/policy/policy.d.ts.map +1 -1
- package/lib/typescript/policy/redact.d.ts.map +1 -1
- package/lib/typescript/providers/anthropic.d.ts +5 -0
- package/lib/typescript/providers/anthropic.d.ts.map +1 -1
- package/lib/typescript/providers/openai.d.ts +0 -16
- package/lib/typescript/providers/openai.d.ts.map +1 -1
- package/lib/typescript/providers/sse.d.ts +82 -1
- package/lib/typescript/providers/sse.d.ts.map +1 -1
- package/lib/typescript/providers/streamTimer.d.ts +59 -0
- package/lib/typescript/providers/streamTimer.d.ts.map +1 -0
- package/lib/typescript/providers/transport.d.ts +40 -0
- package/lib/typescript/providers/transport.d.ts.map +1 -0
- package/lib/typescript/providers/types.d.ts +116 -3
- package/lib/typescript/providers/types.d.ts.map +1 -1
- package/lib/typescript/providers/xhrStream.d.ts +43 -0
- package/lib/typescript/providers/xhrStream.d.ts.map +1 -0
- package/lib/typescript/session.d.ts +63 -2
- package/lib/typescript/session.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["parseChunk","buffer","rest","idx","search","raw","slice","event","dataLines","line","split","startsWith","trim","push","replace","length","data","join","readSse","response","body","getReader","text","
|
|
1
|
+
{"version":3,"names":["parseChunk","buffer","onFrame","rest","idx","search","raw","slice","event","dataLines","line","split","startsWith","trim","push","replace","length","data","join","drain","out","gen","next","done","value","framesFrom","chunks","options","status","leftover","chunk","truncated","readSse","response","signal","body","getReader","text","reader","decoder","TextDecoder","finished","aborted","Promise","_resolve","reject","fail","err","Error","name","addEventListener","once","undefined","catch","read","race","decode","stream","resolve","cancel","releaseLock","nonStreamProblem","type","headers","get","lowered","toLowerCase","includes","detail","errorBody","truncatedMessage","unparseableMessage","args","stopReason","tail"],"sourceRoot":"../../../src","sources":["providers/sse.ts"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA2CA,UAAUA,UAAUA,CAClBC,MAAc,EACdC,OAAoB,EACe;EACnC,IAAIC,IAAI,GAAGF,MAAM;EACjB,IAAIG,GAAW;EACf;EACA,OAAO,CAACA,GAAG,GAAGD,IAAI,CAACE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE;IAC/C,MAAMC,GAAG,GAAGH,IAAI,CAACI,KAAK,CAAC,CAAC,EAAEH,GAAG,CAAC;IAC9BD,IAAI,GAAGA,IAAI,CAACI,KAAK,CAACH,GAAG,IAAID,IAAI,CAACC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACrDF,OAAO,GAAG,CAAC;IAEX,IAAIM,KAAyB;IAC7B,MAAMC,SAAmB,GAAG,EAAE;IAC9B,KAAK,MAAMC,IAAI,IAAIJ,GAAG,CAACK,KAAK,CAAC,OAAO,CAAC,EAAE;MACrC,IAAID,IAAI,CAACE,UAAU,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC;MACpC,IAAIF,IAAI,CAACE,UAAU,CAAC,QAAQ,CAAC,EAAEJ,KAAK,GAAGE,IAAI,CAACH,KAAK,CAAC,CAAC,CAAC,CAACM,IAAI,CAAC,CAAC,CAAC,KACvD,IAAIH,IAAI,CAACE,UAAU,CAAC,OAAO,CAAC,EAAEH,SAAS,CAACK,IAAI,CAACJ,IAAI,CAACH,KAAK,CAAC,CAAC,CAAC,CAACQ,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACpF;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C,SAAS,GAAG0C,UAAU,KAAK,QAAQ;EACzC,MAAMC,IAAI,GAAGF,IAAI,CAACxD,MAAM,GAAG,GAAG,GAAG,IAAIwD,IAAI,CAACjE,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,GAAGiE,IAAI;EAC9D,OACE,wCAAwCvB,IAAI,EAAE,IAC7ClB,SAAS,GAAG,+DAA+D,GAAG,EAAE,CAAC,GAClF,WAAW0C,UAAU,IAAI,MAAM,KAAKD,IAAI,CAACxD,MAAM,WAAW0D,IAAI,EAAE;AAEpE","ignoreList":[]}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DEFAULT_IDLE_TIMEOUT_MS = exports.DEFAULT_CONNECT_TIMEOUT_MS = void 0;
|
|
7
|
+
exports.createStreamTimer = createStreamTimer;
|
|
8
|
+
/**
|
|
9
|
+
* The clock on a model request.
|
|
10
|
+
*
|
|
11
|
+
* There was none. A gateway that accepted the socket and then said nothing —
|
|
12
|
+
* an overloaded proxy, a dropped VPN, a laptop that slept mid-answer — left
|
|
13
|
+
* the turn running with the thinking strip animating until a person pressed
|
|
14
|
+
* Stop. The 180s turn deadline did not help: it is read at the TOP of a step
|
|
15
|
+
* (`runAgentTurn`), and a step parked inside `await fetch(...)` never reaches
|
|
16
|
+
* the next one.
|
|
17
|
+
*
|
|
18
|
+
* Two clocks, because the two silences mean different things:
|
|
19
|
+
*
|
|
20
|
+
* - CONNECT covers "no headers yet". Nothing has been generated, so nothing is
|
|
21
|
+
* lost by giving up; 30s is already long for a gateway to acknowledge a POST.
|
|
22
|
+
* - IDLE covers "headers arrived, then nothing". This one has to be generous.
|
|
23
|
+
* Anthropic sends `ping` frames, but an OpenAI-protocol reasoning model can
|
|
24
|
+
* legitimately emit nothing for a long stretch while it thinks, and cutting
|
|
25
|
+
* that off would look like a broken product. Any frame at all — a keepalive
|
|
26
|
+
* comment included — resets it, so only total silence trips it.
|
|
27
|
+
*
|
|
28
|
+
* A timeout is NOT a retry. Nothing is re-sent: the request may have reached
|
|
29
|
+
* the model, and a duplicate turn is a duplicate bill and possibly duplicate
|
|
30
|
+
* writes. The turn ends with an honest notice and a Continue button.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const DEFAULT_CONNECT_TIMEOUT_MS = exports.DEFAULT_CONNECT_TIMEOUT_MS = 30_000;
|
|
34
|
+
const DEFAULT_IDLE_TIMEOUT_MS = exports.DEFAULT_IDLE_TIMEOUT_MS = 90_000;
|
|
35
|
+
/**
|
|
36
|
+
* A timer over an optional caller signal.
|
|
37
|
+
*
|
|
38
|
+
* When no `AbortController` exists (a runtime old enough to lack it) this
|
|
39
|
+
* degrades to passing the caller's signal straight through with no clocks,
|
|
40
|
+
* rather than failing to send anything at all.
|
|
41
|
+
*/
|
|
42
|
+
function createStreamTimer(callerSignal, options = {}) {
|
|
43
|
+
const connectMs = options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
|
|
44
|
+
const idleMs = options.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS;
|
|
45
|
+
const Controller = typeof AbortController === "function" ? AbortController : undefined;
|
|
46
|
+
if (!Controller) {
|
|
47
|
+
return {
|
|
48
|
+
signal: callerSignal,
|
|
49
|
+
connected() {},
|
|
50
|
+
activity() {},
|
|
51
|
+
expired: undefined,
|
|
52
|
+
message: () => undefined,
|
|
53
|
+
dispose() {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const controller = new Controller();
|
|
57
|
+
let expired;
|
|
58
|
+
let handle;
|
|
59
|
+
let disposed = false;
|
|
60
|
+
const clear = () => {
|
|
61
|
+
if (handle !== undefined) {
|
|
62
|
+
clearTimeout(handle);
|
|
63
|
+
handle = undefined;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const arm = (ms, which) => {
|
|
67
|
+
clear();
|
|
68
|
+
if (disposed || !Number.isFinite(ms) || ms <= 0) return;
|
|
69
|
+
handle = setTimeout(() => {
|
|
70
|
+
handle = undefined;
|
|
71
|
+
expired = which;
|
|
72
|
+
// The abort is what actually unblocks `fetch` / `reader.read()`. The
|
|
73
|
+
// reason is tracked here rather than read back off the signal because
|
|
74
|
+
// `AbortSignal.reason` is not reliably present on React Native.
|
|
75
|
+
try {
|
|
76
|
+
controller.abort();
|
|
77
|
+
} catch {
|
|
78
|
+
/* already aborted */
|
|
79
|
+
}
|
|
80
|
+
}, ms);
|
|
81
|
+
};
|
|
82
|
+
const onCallerAbort = () => {
|
|
83
|
+
clear();
|
|
84
|
+
try {
|
|
85
|
+
controller.abort();
|
|
86
|
+
} catch {
|
|
87
|
+
/* already aborted */
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
if (callerSignal) {
|
|
91
|
+
if (callerSignal.aborted) onCallerAbort();else callerSignal.addEventListener?.("abort", onCallerAbort);
|
|
92
|
+
}
|
|
93
|
+
arm(connectMs, "connect");
|
|
94
|
+
return {
|
|
95
|
+
signal: controller.signal,
|
|
96
|
+
connected() {
|
|
97
|
+
arm(idleMs, "idle");
|
|
98
|
+
},
|
|
99
|
+
activity() {
|
|
100
|
+
// Only rearm a clock that is already running: a provider that reports
|
|
101
|
+
// activity after `dispose` must not resurrect the timer.
|
|
102
|
+
if (!disposed) arm(idleMs, "idle");
|
|
103
|
+
},
|
|
104
|
+
get expired() {
|
|
105
|
+
return expired;
|
|
106
|
+
},
|
|
107
|
+
message() {
|
|
108
|
+
if (expired === "connect") {
|
|
109
|
+
return `The model endpoint did not respond within ${Math.round(connectMs / 1000)}s. Nothing was generated, and nothing was re-sent.`;
|
|
110
|
+
}
|
|
111
|
+
if (expired === "idle") {
|
|
112
|
+
return `The model endpoint stopped sending after ${Math.round(idleMs / 1000)}s of silence. Whatever arrived is above; nothing was re-sent.`;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
},
|
|
116
|
+
dispose() {
|
|
117
|
+
disposed = true;
|
|
118
|
+
clear();
|
|
119
|
+
callerSignal?.removeEventListener?.("abort", onCallerAbort);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=streamTimer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_CONNECT_TIMEOUT_MS","exports","DEFAULT_IDLE_TIMEOUT_MS","createStreamTimer","callerSignal","options","connectMs","connectTimeoutMs","idleMs","idleTimeoutMs","Controller","AbortController","undefined","signal","connected","activity","expired","message","dispose","controller","handle","disposed","clear","clearTimeout","arm","ms","which","Number","isFinite","setTimeout","abort","onCallerAbort","aborted","addEventListener","Math","round","removeEventListener"],"sourceRoot":"../../../src","sources":["providers/streamTimer.ts"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,0BAA0B,GAAAC,OAAA,CAAAD,0BAAA,GAAG,MAAM;AACzC,MAAME,uBAAuB,GAAAD,OAAA,CAAAC,uBAAA,GAAG,MAAM;AA4B7C;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,iBAAiBA,CAC/BC,YAAqC,EACrCC,OAA2B,GAAG,CAAC,CAAC,EACnB;EACb,MAAMC,SAAS,GAAGD,OAAO,CAACE,gBAAgB,IAAIP,0BAA0B;EACxE,MAAMQ,MAAM,GAAGH,OAAO,CAACI,aAAa,IAAIP,uBAAuB;EAE/D,MAAMQ,UAAU,GAAG,OAAOC,eAAe,KAAK,UAAU,GAAGA,eAAe,GAAGC,SAAS;EACtF,IAAI,CAACF,UAAU,EAAE;IACf,OAAO;MACLG,MAAM,EAAET,YAAY;MACpBU,SAASA,CAAA,EAAG,CAAC,CAAC;MACdC,QAAQA,CAAA,EAAG,CAAC,CAAC;MACbC,OAAO,EAAEJ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AG,CAAChB,MAAM,EAAE,MAAM,CAAC;IACrB,CAAC;IACDO,QAAQA,CAAA,EAAG;MACT;MACA;MACA,IAAI,CAACM,QAAQ,EAAEG,GAAG,CAAChB,MAAM,EAAE,MAAM,CAAC;IACpC,CAAC;IACD,IAAIQ,OAAOA,CAAA,EAAG;MACZ,OAAOA,OAAO;IAChB,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAID,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO,6CAA6CkB,IAAI,CAACC,KAAK,CAAC7B,SAAS,GAAG,IAAI,CAAC,oDAAoD;MACtI;MACA,IAAIU,OAAO,KAAK,MAAM,EAAE;QACtB,OAAO,4CAA4CkB,IAAI,CAACC,KAAK,CAAC3B,MAAM,GAAG,IAAI,CAAC,+DAA+D;MAC7I;MACA,OAAOI,SAAS;IAClB,CAAC;IACDM,OAAOA,CAAA,EAAG;MACRG,QAAQ,GAAG,IAAI;MACfC,KAAK,CAAC,CAAC;MACPlB,YAAY,EAAEgC,mBAAmB,GAAG,OAAO,EAAEL,aAAa,CAAC;IAC7D;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createTransport = createTransport;
|
|
7
|
+
var _sse = require("./sse");
|
|
8
|
+
var _xhrStream = require("./xhrStream");
|
|
9
|
+
/**
|
|
10
|
+
* How a request is SENT, decided before it is sent.
|
|
11
|
+
*
|
|
12
|
+
* The obvious place to add XHR was inside `readSse`, once a missing
|
|
13
|
+
* `response.body` had already proved that `fetch` could not stream. That is
|
|
14
|
+
* the wrong boundary and would have been a real bug: the POST has already
|
|
15
|
+
* happened by then, the reader has neither the URL nor the headers nor the
|
|
16
|
+
* body to repeat it, and issuing a second one would ask the model to generate
|
|
17
|
+
* the same answer twice — billed twice, and for a turn that writes, acted on
|
|
18
|
+
* twice. Transport is chosen up front; a response that has started is consumed
|
|
19
|
+
* exactly once, whatever it turns out to be.
|
|
20
|
+
*
|
|
21
|
+
* `auto` therefore learns rather than probes. The first request goes through
|
|
22
|
+
* `fetch`; if that response has no reader, the answer is buffered (as it
|
|
23
|
+
* always was on that runtime) and the SESSION remembers, so every later
|
|
24
|
+
* request uses XHR and streams. One buffered reply at the start of a bare-RN
|
|
25
|
+
* session, and nothing to configure.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const EMPTY = async function* () {};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* One transport per provider instance, because the `auto` decision is worth
|
|
32
|
+
* remembering: re-learning it would buffer the first reply of every turn.
|
|
33
|
+
*/
|
|
34
|
+
function createTransport(config) {
|
|
35
|
+
const requested = config.transport ?? "auto";
|
|
36
|
+
/**
|
|
37
|
+
* Set once a `fetch` response has come back with no reader. Only ever
|
|
38
|
+
* flipped one way: a runtime does not gain streaming mid-session.
|
|
39
|
+
*/
|
|
40
|
+
let fetchCannotStream = false;
|
|
41
|
+
const useXhr = () => {
|
|
42
|
+
// A host-supplied `fetch` is never bypassed. It is how a harness keeps
|
|
43
|
+
// model traffic off the global (and out of the network interceptor), and
|
|
44
|
+
// routing around it would defeat the reason it was passed in.
|
|
45
|
+
if (config.fetch) return requested === "xhr" && (0, _xhrStream.xhrAvailable)();
|
|
46
|
+
if (requested === "xhr") return (0, _xhrStream.xhrAvailable)();
|
|
47
|
+
if (requested === "fetch") return false;
|
|
48
|
+
return fetchCannotStream && (0, _xhrStream.xhrAvailable)();
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
async open(req) {
|
|
52
|
+
if (useXhr()) {
|
|
53
|
+
const response = await (0, _xhrStream.xhrStream)({
|
|
54
|
+
url: config.endpoint,
|
|
55
|
+
headers: req.headers,
|
|
56
|
+
body: req.body,
|
|
57
|
+
signal: req.signal
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
const detail = (await response.text()).slice(0, 600);
|
|
61
|
+
return {
|
|
62
|
+
problem: `HTTP ${response.status}${detail ? ` — ${detail}` : ""}`,
|
|
63
|
+
frames: EMPTY
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const type = response.contentType.toLowerCase();
|
|
67
|
+
if (type && !type.includes("event-stream")) {
|
|
68
|
+
const detail = (await response.text()).slice(0, 600);
|
|
69
|
+
return {
|
|
70
|
+
problem: type.includes("json") ? `The endpoint answered with JSON instead of a stream — it may not support "stream": true.${detail ? ` — ${detail}` : ""}` : `The endpoint answered with ${response.contentType} instead of an event stream.${detail ? ` — ${detail}` : ""}`,
|
|
71
|
+
frames: EMPTY
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
frames: options => response.frames(options)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const response = await (config.fetch ?? fetch)(config.endpoint, {
|
|
79
|
+
method: "POST",
|
|
80
|
+
headers: req.headers,
|
|
81
|
+
signal: req.signal,
|
|
82
|
+
body: req.body
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) return {
|
|
85
|
+
problem: await (0, _sse.errorBody)(response),
|
|
86
|
+
frames: EMPTY
|
|
87
|
+
};
|
|
88
|
+
const problem = await (0, _sse.nonStreamProblem)(response);
|
|
89
|
+
if (problem) return {
|
|
90
|
+
problem,
|
|
91
|
+
frames: EMPTY
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Learn, for the NEXT request. This one is already in flight and is read
|
|
95
|
+
// through the buffered path — re-sending it is what this file exists to
|
|
96
|
+
// avoid.
|
|
97
|
+
const body = response.body;
|
|
98
|
+
if ((!body || typeof body.getReader !== "function") && !config.fetch) {
|
|
99
|
+
fetchCannotStream = true;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
frames: options => (0, _sse.readSse)(response, options)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_sse","require","_xhrStream","EMPTY","createTransport","config","requested","transport","fetchCannotStream","useXhr","fetch","xhrAvailable","open","req","response","xhrStream","url","endpoint","headers","body","signal","ok","detail","text","slice","problem","status","frames","type","contentType","toLowerCase","includes","options","method","errorBody","nonStreamProblem","getReader","readSse"],"sourceRoot":"../../../src","sources":["providers/transport.ts"],"mappings":";;;;;;AAmBA,IAAAA,IAAA,GAAAC,OAAA;AAOA,IAAAC,UAAA,GAAAD,OAAA;AA1BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA6BA,MAAME,KAAK,GAAG,gBAAAA,CAAA,EAAyD,CAAC,CAAC;;AAEzE;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAACC,MAAsB,EAAa;EACjE,MAAMC,SAAwB,GAAGD,MAAM,CAACE,SAAS,IAAI,MAAM;EAC3D;AACF;AACA;AACA;EACE,IAAIC,iBAAiB,GAAG,KAAK;EAE7B,MAAMC,MAAM,GAAGA,CAAA,KAAe;IAC5B;IACA;IACA;IACA,IAAIJ,MAAM,CAACK,KAAK,EAAE,OAAOJ,SAAS,KAAK,KAAK,IAAI,IAAAK,uBAAY,EAAC,CAAC;IAC9D,IAAIL,SAAS,KAAK,KAAK,EAAE,OAAO,IAAAK,uBAAY,EAAC,CAAC;IAC9C,IAAIL,SAAS,KAAK,OAAO,EAAE,OAAO,KAAK;IACvC,OAAOE,iBAAiB,IAAI,IAAAG,uBAAY,EAAC,CAAC;EAC5C,CAAC;EAED,OAAO;IACL,MAAMC,IAAIA,CAACC,GAAsB,EAA6B;MAC5D,IAAIJ,MAAM,CAAC,CAAC,EAAE;QACZ,MAAMK,QAAQ,GAAG,MAAM,IAAAC,oBAAS,EAAC;UAC/BC,GAAG,EAAEX,MAAM,CAACY,QAAQ;UACpBC,OAAO,EAAEL,GAAG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M;QAClBD,IAAI,EAAEN,GAAG,CAACM;MACZ,CAAC,CAAC;MAEF,IAAI,CAACL,QAAQ,CAACO,EAAE,EAAE,OAAO;QAAEI,OAAO,EAAE,MAAM,IAAAS,cAAS,EAACpB,QAAQ,CAAC;QAAEa,MAAM,EAAExB;MAAM,CAAC;MAE9E,MAAMsB,OAAO,GAAG,MAAM,IAAAU,qBAAgB,EAACrB,QAAQ,CAAC;MAChD,IAAIW,OAAO,EAAE,OAAO;QAAEA,OAAO;QAAEE,MAAM,EAAExB;MAAM,CAAC;;MAE9C;MACA;MACA;MACA,MAAMgB,IAAI,GAAIL,QAAQ,CAAkDK,IAAI;MAC5E,IAAI,CAAC,CAACA,IAAI,IAAI,OAAOA,IAAI,CAACiB,SAAS,KAAK,UAAU,KAAK,CAAC/B,MAAM,CAACK,KAAK,EAAE;QACpEF,iBAAiB,GAAG,IAAI;MAC1B;MAEA,OAAO;QAAEmB,MAAM,EAAGK,OAAO,IAAK,IAAAK,YAAO,EAACvB,QAAQ,EAAEkB,OAAO;MAAE,CAAC;IAC5D;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.xhrAvailable = xhrAvailable;
|
|
7
|
+
exports.xhrStream = xhrStream;
|
|
8
|
+
var _sse = require("./sse");
|
|
9
|
+
/**
|
|
10
|
+
* Streaming over `XMLHttpRequest`, for the runtimes where `fetch` cannot.
|
|
11
|
+
*
|
|
12
|
+
* React Native core still has no `response.body`: its `fetch` is the whatwg
|
|
13
|
+
* polyfill over XHR and resolves inside `xhr.onload`, i.e. after the ENTIRE
|
|
14
|
+
* body. Under Expo the global is `expo/fetch`, which does stream — but
|
|
15
|
+
* `EXPO_PUBLIC_USE_RN_FETCH=1` reverts that, and the bare-RN CLI, TV CLI and
|
|
16
|
+
* NativeScript lanes never had it at all. On those, every Ask Buoy answer
|
|
17
|
+
* appeared in one lump, however long the model took.
|
|
18
|
+
*
|
|
19
|
+
* XHR itself has streamed the whole time. `responseText` grows as bytes arrive
|
|
20
|
+
* and `onprogress` fires as it does, so slicing from the last offset gives the
|
|
21
|
+
* same incremental text a reader would. Two conditions, both easy to miss:
|
|
22
|
+
* the progress handler must be installed BEFORE `send()`, and `responseType`
|
|
23
|
+
* must stay text — anything else stops RN emitting progress at all.
|
|
24
|
+
*
|
|
25
|
+
* WHAT THIS IS NOT. It is not a second SSE parser: framing, the truncation
|
|
26
|
+
* rule and the terminal-marker contract all live in `sse.ts` and are shared
|
|
27
|
+
* verbatim. This file only produces text chunks.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** Beyond this the answer is not an answer any more; stop reading. */
|
|
31
|
+
const MAX_RESPONSE_CHARS = 8_000_000;
|
|
32
|
+
function xhrAvailable() {
|
|
33
|
+
return typeof XMLHttpRequest === "function";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Send the request and resolve once the HEADERS are in, so the caller can
|
|
38
|
+
* check the status and content type before deciding to read a stream — the
|
|
39
|
+
* same shape `fetch` offers, and the reason this can slot in beside it.
|
|
40
|
+
*/
|
|
41
|
+
function xhrStream(req) {
|
|
42
|
+
return new Promise((resolveHeaders, rejectHeaders) => {
|
|
43
|
+
const xhr = new XMLHttpRequest();
|
|
44
|
+
|
|
45
|
+
/** Text seen but not yet handed to a consumer. */
|
|
46
|
+
const queue = [];
|
|
47
|
+
/** Resolvers for a consumer parked on an empty queue. */
|
|
48
|
+
const waiters = [];
|
|
49
|
+
let offset = 0;
|
|
50
|
+
let done = false;
|
|
51
|
+
let failure;
|
|
52
|
+
let headersSeen = false;
|
|
53
|
+
let capped = false;
|
|
54
|
+
const wake = () => {
|
|
55
|
+
while (waiters.length) waiters.shift()();
|
|
56
|
+
};
|
|
57
|
+
const pull = () => {
|
|
58
|
+
// `responseText` is the WHOLE body so far, so the delta is everything
|
|
59
|
+
// past what was already taken. RN keeps the full string either way;
|
|
60
|
+
// the offset bounds the work, not the memory.
|
|
61
|
+
let text;
|
|
62
|
+
try {
|
|
63
|
+
text = xhr.responseText ?? "";
|
|
64
|
+
} catch {
|
|
65
|
+
return; // Not readable yet on some runtimes; the next event will do.
|
|
66
|
+
}
|
|
67
|
+
if (text.length <= offset) return;
|
|
68
|
+
if (text.length > MAX_RESPONSE_CHARS) {
|
|
69
|
+
capped = true;
|
|
70
|
+
failure = new Error("The endpoint sent more than this tool will read.");
|
|
71
|
+
done = true;
|
|
72
|
+
try {
|
|
73
|
+
xhr.abort();
|
|
74
|
+
} catch {
|
|
75
|
+
/* already gone */
|
|
76
|
+
}
|
|
77
|
+
wake();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
queue.push(text.slice(offset));
|
|
81
|
+
offset = text.length;
|
|
82
|
+
wake();
|
|
83
|
+
};
|
|
84
|
+
const settleHeaders = () => {
|
|
85
|
+
if (headersSeen) return;
|
|
86
|
+
headersSeen = true;
|
|
87
|
+
let contentType = "";
|
|
88
|
+
try {
|
|
89
|
+
contentType = xhr.getResponseHeader("content-type") ?? "";
|
|
90
|
+
} catch {
|
|
91
|
+
contentType = "";
|
|
92
|
+
}
|
|
93
|
+
resolveHeaders({
|
|
94
|
+
status: xhr.status,
|
|
95
|
+
ok: xhr.status >= 200 && xhr.status < 300,
|
|
96
|
+
contentType,
|
|
97
|
+
async text() {
|
|
98
|
+
// Whatever has arrived. For a non-2xx that is the error body; the
|
|
99
|
+
// request is over by the time anyone asks.
|
|
100
|
+
await new Promise(r => {
|
|
101
|
+
if (done) return r();
|
|
102
|
+
waiters.push(() => r());
|
|
103
|
+
});
|
|
104
|
+
try {
|
|
105
|
+
return xhr.responseText ?? "";
|
|
106
|
+
} catch {
|
|
107
|
+
return "";
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
frames(options) {
|
|
111
|
+
return (0, _sse.framesFrom)(chunks(), options);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
async function* chunks() {
|
|
116
|
+
try {
|
|
117
|
+
for (;;) {
|
|
118
|
+
while (queue.length) yield queue.shift();
|
|
119
|
+
if (done) break;
|
|
120
|
+
await new Promise(r => waiters.push(r));
|
|
121
|
+
}
|
|
122
|
+
while (queue.length) yield queue.shift();
|
|
123
|
+
if (failure) throw failure;
|
|
124
|
+
} finally {
|
|
125
|
+
if (!done) {
|
|
126
|
+
// The consumer left early — a completed turn, a Stop, a timeout.
|
|
127
|
+
// Nothing else will read this socket.
|
|
128
|
+
try {
|
|
129
|
+
xhr.abort();
|
|
130
|
+
} catch {
|
|
131
|
+
/* already gone */
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const onAbort = () => {
|
|
137
|
+
try {
|
|
138
|
+
xhr.abort();
|
|
139
|
+
} catch {
|
|
140
|
+
/* already gone */
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
xhr.onreadystatechange = () => {
|
|
144
|
+
// HEADERS_RECEIVED. Status and content type are known here, long before
|
|
145
|
+
// the body finishes — which is the whole point of using XHR directly.
|
|
146
|
+
if (xhr.readyState === 2) settleHeaders();
|
|
147
|
+
};
|
|
148
|
+
xhr.onprogress = () => {
|
|
149
|
+
settleHeaders();
|
|
150
|
+
pull();
|
|
151
|
+
};
|
|
152
|
+
xhr.onload = () => {
|
|
153
|
+
settleHeaders();
|
|
154
|
+
if (!capped) pull();
|
|
155
|
+
done = true;
|
|
156
|
+
wake();
|
|
157
|
+
};
|
|
158
|
+
xhr.onerror = () => {
|
|
159
|
+
failure = new Error("The request failed before it finished.");
|
|
160
|
+
done = true;
|
|
161
|
+
if (!headersSeen) {
|
|
162
|
+
headersSeen = true;
|
|
163
|
+
rejectHeaders(failure);
|
|
164
|
+
}
|
|
165
|
+
wake();
|
|
166
|
+
};
|
|
167
|
+
xhr.onabort = () => {
|
|
168
|
+
const err = new Error("Aborted");
|
|
169
|
+
err.name = "AbortError";
|
|
170
|
+
failure = err;
|
|
171
|
+
done = true;
|
|
172
|
+
if (!headersSeen) {
|
|
173
|
+
headersSeen = true;
|
|
174
|
+
rejectHeaders(err);
|
|
175
|
+
}
|
|
176
|
+
wake();
|
|
177
|
+
};
|
|
178
|
+
xhr.ontimeout = () => {
|
|
179
|
+
failure = new Error("The request timed out.");
|
|
180
|
+
done = true;
|
|
181
|
+
if (!headersSeen) {
|
|
182
|
+
headersSeen = true;
|
|
183
|
+
rejectHeaders(failure);
|
|
184
|
+
}
|
|
185
|
+
wake();
|
|
186
|
+
};
|
|
187
|
+
try {
|
|
188
|
+
xhr.open("POST", req.url, true);
|
|
189
|
+
// Text, and nothing else: RN emits no progress events for any other
|
|
190
|
+
// response type, which turns this back into a buffered read in silence.
|
|
191
|
+
xhr.responseType = "text";
|
|
192
|
+
for (const [k, v] of Object.entries(req.headers)) {
|
|
193
|
+
try {
|
|
194
|
+
xhr.setRequestHeader(k, v);
|
|
195
|
+
} catch {
|
|
196
|
+
/* a header the runtime forbids is not worth failing the turn over */
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (req.signal) {
|
|
200
|
+
if (req.signal.aborted) onAbort();else req.signal.addEventListener?.("abort", onAbort);
|
|
201
|
+
}
|
|
202
|
+
xhr.send(req.body);
|
|
203
|
+
} catch (err) {
|
|
204
|
+
headersSeen = true;
|
|
205
|
+
rejectHeaders(err instanceof Error ? err : new Error(String(err)));
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=xhrStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_sse","require","MAX_RESPONSE_CHARS","xhrAvailable","XMLHttpRequest","xhrStream","req","Promise","resolveHeaders","rejectHeaders","xhr","queue","waiters","offset","done","failure","headersSeen","capped","wake","length","shift","pull","text","responseText","Error","abort","push","slice","settleHeaders","contentType","getResponseHeader","status","ok","r","frames","options","framesFrom","chunks","onAbort","onreadystatechange","readyState","onprogress","onload","onerror","onabort","err","name","ontimeout","open","url","responseType","k","v","Object","entries","headers","setRequestHeader","signal","aborted","addEventListener","send","body","String"],"sourceRoot":"../../../src","sources":["providers/xhrStream.ts"],"mappings":";;;;;;;AAoBA,IAAAA,IAAA,GAAAC,OAAA;AApBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA,MAAMC,kBAAkB,GAAG,SAAS;AAkB7B,SAASC,YAAYA,CAAA,EAAY;EACtC,OAAO,OAAOC,cAAc,KAAK,UAAU;AAC7C;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,SAASA,CAACC,GAAqB,EAA8B;EAC3E,OAAO,IAAIC,OAAO,CAAoB,CAACC,cAAc,EAAEC,aAAa,KAAK;IACvE,MAAMC,GAAG,GAAG,IAAIN,cAAc,CAAC,CAAC;;IAEhC;IACA,MAAMO,KAAe,GAAG,EAAE;IAC1B;IACA,MAAMC,OAA0B,GAAG,EAAE;IACrC,IAAIC,MAAM,GAAG,CAAC;IACd,IAAIC,IAAI,GAAG,KAAK;IAChB,IAAIC,OAA0B;IAC9B,IAAIC,WAAW,GAAG,KAAK;IACvB,IAAIC,MAAM,GAAG,KAAK;IAElB,MAAMC,IAAI,GAAGA,CAAA,KAAM;MACjB,OAAON,OAAO,CAACO,MAAM,EAAEP,OAAO,CAACQ,KAAK,CAAC,CAAC,CAAE,CAAC;IAC3C,CAAC;IAED,MAAMC,IAAI,GAAGA,CAAA,KAAM;MACjB;MACA;MACA;MACA,IAAIC,IAAY;MAChB,IAAI;QACFA,IAAI,GAAGZ,GAAG,CAACa,YAAY,IAAI,EAAE;MAC/B,CAAC,CAAC,MAAM;QACN,OAAO,CAAC;MACV;MACA,IAAID,IAAI,CAACH,MAAM,IAAIN,MAAM,EAAE;MAC3B,IAAIS,IAAI,CAACH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