@gentiq/core 1.0.0-alpha.8 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/api.es.js +121 -55
- package/dist/composer/composerDrafts.es.js +35 -31
- package/dist/composer/composerFiles.es.js +35 -31
- package/dist/errors.es.js +20 -2
- package/dist/index.d.ts +4704 -791
- package/dist/index.es.js +42 -29
- package/dist/internal.d.ts +4597 -902
- package/dist/internal.es.js +40 -46
- package/dist/protocol/messages.es.js +16 -15
- package/dist/scheduleFormat.es.js +104 -0
- package/dist/thread/chatRuntime.es.js +42 -38
- package/dist/thread/chatTransport.es.js +26 -21
- package/dist/thread/shareUnchanged.es.js +12 -12
- package/dist/thread/threadController.es.js +91 -87
- package/dist/thread/threadReducer.es.js +48 -48
- package/package.json +3 -2
package/dist/internal.es.js
CHANGED
|
@@ -1,48 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { uniqueBy as K } from "./uniqueBy.es.js";
|
|
1
|
+
import { createGentiqRuntime as o } from "./client/api.es.js";
|
|
2
|
+
import { createLocalStorageAuthAdapter as a, resolveAuthAdapter as p } from "./client/auth.es.js";
|
|
3
|
+
import { createHttpClient as m } from "./client/http.es.js";
|
|
4
|
+
import { exchangeLoginCodeOnce as x } from "./client/loginCode.es.js";
|
|
5
|
+
import { composerScope as d } from "./composer/composerDrafts.es.js";
|
|
6
|
+
import { normalizeReference as i, normalizeWhitespace as u, sourceTextSignature as s, truncateReferenceText as l } from "./composer/references.es.js";
|
|
7
|
+
import { createVoiceRecorder as S, isVoiceRecordingSupported as L } from "./composer/voiceRecorder.es.js";
|
|
8
|
+
import { getDateLocale as T, getNumberLocale as A } from "./datetime.es.js";
|
|
9
|
+
import { debugLog as q } from "./debugLog.es.js";
|
|
10
|
+
import { warnOnceInDevelopment as w } from "./devWarning.es.js";
|
|
11
|
+
import { getLanguageBadge as B } from "./languages.es.js";
|
|
12
|
+
import { messageFeedback as D } from "./protocol/messages.es.js";
|
|
13
|
+
import { isStoredPart as P, isStoredToolPart as V } from "./protocol/storedMessages.es.js";
|
|
14
|
+
import { shareUnchanged as y } from "./thread/shareUnchanged.es.js";
|
|
15
|
+
import { newThreadState as G, storedThreadState as H } from "./thread/threadReducer.es.js";
|
|
16
|
+
import { uniqueBy as N } from "./uniqueBy.es.js";
|
|
18
17
|
export {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
V as
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
a as toLocalInput,
|
|
44
|
-
C as truncateReferenceText,
|
|
45
|
-
K as uniqueBy,
|
|
46
|
-
O as warnOnceInDevelopment,
|
|
47
|
-
p as weekStart
|
|
18
|
+
d as composerScope,
|
|
19
|
+
o as createGentiqRuntime,
|
|
20
|
+
m as createHttpClient,
|
|
21
|
+
a as createLocalStorageAuthAdapter,
|
|
22
|
+
S as createVoiceRecorder,
|
|
23
|
+
q as debugLog,
|
|
24
|
+
x as exchangeLoginCodeOnce,
|
|
25
|
+
T as getDateLocale,
|
|
26
|
+
B as getLanguageBadge,
|
|
27
|
+
A as getNumberLocale,
|
|
28
|
+
P as isStoredPart,
|
|
29
|
+
V as isStoredToolPart,
|
|
30
|
+
L as isVoiceRecordingSupported,
|
|
31
|
+
D as messageFeedback,
|
|
32
|
+
G as newThreadState,
|
|
33
|
+
i as normalizeReference,
|
|
34
|
+
u as normalizeWhitespace,
|
|
35
|
+
p as resolveAuthAdapter,
|
|
36
|
+
y as shareUnchanged,
|
|
37
|
+
s as sourceTextSignature,
|
|
38
|
+
H as storedThreadState,
|
|
39
|
+
l as truncateReferenceText,
|
|
40
|
+
N as uniqueBy,
|
|
41
|
+
w as warnOnceInDevelopment
|
|
48
42
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isToolUIPart as
|
|
2
|
-
function
|
|
1
|
+
import { isToolUIPart as n } from "ai";
|
|
2
|
+
function u(t, a) {
|
|
3
3
|
return {
|
|
4
4
|
type: "file",
|
|
5
5
|
mediaType: t.media_type,
|
|
@@ -9,35 +9,35 @@ function l(t, a) {
|
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
function d(t, a) {
|
|
12
|
-
return
|
|
12
|
+
return n(t) && t.state === "approval-requested" && (a === void 0 || t.approval.id === a);
|
|
13
13
|
}
|
|
14
14
|
function s(t, { id: a, approved: e, reason: i }) {
|
|
15
15
|
return {
|
|
16
16
|
...t,
|
|
17
17
|
parts: t.parts.map(
|
|
18
|
-
(
|
|
19
|
-
...
|
|
18
|
+
(o) => n(o) && o.state === "approval-requested" && o.approval.id === a ? {
|
|
19
|
+
...o,
|
|
20
20
|
state: "approval-responded",
|
|
21
|
-
approval: { ...
|
|
22
|
-
} :
|
|
21
|
+
approval: { ...o.approval, id: a, approved: e, ...i ? { reason: i } : {} }
|
|
22
|
+
} : o
|
|
23
23
|
)
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
function r(t, a) {
|
|
27
|
-
return
|
|
27
|
+
return n(t) && t.state === "input-available" && (a === void 0 || t.toolCallId === a);
|
|
28
28
|
}
|
|
29
29
|
function p(t) {
|
|
30
30
|
return d(t) || r(t);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function c(t, { toolCallId: a, output: e }) {
|
|
33
33
|
return {
|
|
34
34
|
...t,
|
|
35
35
|
parts: t.parts.map(
|
|
36
|
-
(i) =>
|
|
36
|
+
(i) => n(i) && i.state === "input-available" && i.toolCallId === a ? { ...i, state: "output-available", output: e } : i
|
|
37
37
|
)
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function f(t) {
|
|
41
41
|
const { metadata: a } = t;
|
|
42
42
|
if (typeof a != "object" || a === null || !("feedback" in a))
|
|
43
43
|
return;
|
|
@@ -57,17 +57,18 @@ const b = [
|
|
|
57
57
|
"data-progress-update",
|
|
58
58
|
"data-message-id",
|
|
59
59
|
"data-chat-finished",
|
|
60
|
-
"data-title"
|
|
60
|
+
"data-title",
|
|
61
|
+
"tool-load_connector_tools"
|
|
61
62
|
];
|
|
62
63
|
export {
|
|
63
64
|
b as HIDDEN_PART_TYPES,
|
|
64
|
-
|
|
65
|
+
u as attachmentFilePart,
|
|
65
66
|
d as isAwaitingApproval,
|
|
66
67
|
r as isAwaitingOutput,
|
|
67
68
|
p as isAwaitingUser,
|
|
68
|
-
|
|
69
|
+
f as messageFeedback,
|
|
69
70
|
m as resolveMessageId,
|
|
70
71
|
s as withApprovalResponse,
|
|
71
72
|
v as withFeedback,
|
|
72
|
-
|
|
73
|
+
c as withToolOutput
|
|
73
74
|
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { weekStart as m } from "./calendars.es.js";
|
|
2
|
+
import { createDateFormatter as f } from "./datetime.es.js";
|
|
3
|
+
function T() {
|
|
4
|
+
try {
|
|
5
|
+
const n = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
6
|
+
return n && n.trim() ? n : "UTC";
|
|
7
|
+
} catch {
|
|
8
|
+
return "UTC";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function d(n) {
|
|
12
|
+
const t = /* @__PURE__ */ new Set();
|
|
13
|
+
for (const r of n) {
|
|
14
|
+
const e = Math.floor(r);
|
|
15
|
+
e === 7 ? t.add(0) : e >= 0 && e <= 6 && t.add(e);
|
|
16
|
+
}
|
|
17
|
+
return Array.from(t).sort((r, e) => r - e);
|
|
18
|
+
}
|
|
19
|
+
function D(n) {
|
|
20
|
+
const t = Math.max(0, Math.min(59, Math.floor(n.minute))), r = Math.max(0, Math.min(23, Math.floor(n.hour)));
|
|
21
|
+
if (n.frequency === "daily") return `${t} ${r} * * *`;
|
|
22
|
+
const e = d(n.daysOfWeek);
|
|
23
|
+
return e.length === 0 ? `${t} ${r} * * 1` : e.length === 7 ? `${t} ${r} * * *` : `${t} ${r} * * ${e.join(",")}`;
|
|
24
|
+
}
|
|
25
|
+
function l(n) {
|
|
26
|
+
const t = /* @__PURE__ */ new Set();
|
|
27
|
+
for (const r of n.split(",")) {
|
|
28
|
+
const e = r.trim();
|
|
29
|
+
if (/^[0-7]$/.test(e)) {
|
|
30
|
+
t.add(Number(e) === 7 ? 0 : Number(e));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const o = /^([0-7])-([0-7])$/.exec(e);
|
|
34
|
+
if (!o) return null;
|
|
35
|
+
const c = Number(o[1]), u = Number(o[2]);
|
|
36
|
+
if (c > u) return null;
|
|
37
|
+
for (let s = c; s <= u; s += 1)
|
|
38
|
+
t.add(s === 7 ? 0 : s);
|
|
39
|
+
}
|
|
40
|
+
return t.size > 0 ? Array.from(t).sort((r, e) => r - e) : null;
|
|
41
|
+
}
|
|
42
|
+
function y(n) {
|
|
43
|
+
if (!n) return null;
|
|
44
|
+
const t = n.trim().split(/\s+/);
|
|
45
|
+
if (t.length !== 5) return null;
|
|
46
|
+
const [r, e, o, c, u] = t;
|
|
47
|
+
if (o !== "*" || c !== "*" || !/^\d+$/.test(r) || !/^\d+$/.test(e)) return null;
|
|
48
|
+
const s = Number(r), i = Number(e);
|
|
49
|
+
if (s < 0 || s > 59 || i < 0 || i > 23) return null;
|
|
50
|
+
if (u === "*") return { frequency: "daily", hour: i, minute: s };
|
|
51
|
+
const a = l(u);
|
|
52
|
+
return a ? a.length === 7 ? { frequency: "daily", hour: i, minute: s } : { frequency: "weekly", hour: i, minute: s, daysOfWeek: a } : null;
|
|
53
|
+
}
|
|
54
|
+
function h(n, t, r) {
|
|
55
|
+
const e = new Date(Date.UTC(2026, 0, 1, n, t));
|
|
56
|
+
return f(r, {
|
|
57
|
+
hour: "2-digit",
|
|
58
|
+
minute: "2-digit",
|
|
59
|
+
timeZone: "UTC"
|
|
60
|
+
}).format(e);
|
|
61
|
+
}
|
|
62
|
+
function $(n, t, r) {
|
|
63
|
+
const e = m(r), o = [...n].sort((s, i) => (s - e + 7) % 7 - (i - e + 7) % 7), c = f(r, { weekday: "short", timeZone: "UTC" });
|
|
64
|
+
return o.map((s) => {
|
|
65
|
+
try {
|
|
66
|
+
return c.format(new Date(Date.UTC(2024, 0, 7 + s)));
|
|
67
|
+
} catch {
|
|
68
|
+
return t(`schedules:days.${s}`);
|
|
69
|
+
}
|
|
70
|
+
}).join(", ");
|
|
71
|
+
}
|
|
72
|
+
function p(n, t, r) {
|
|
73
|
+
if (n.kind === "once") {
|
|
74
|
+
if (!n.run_at) return t("schedules:cadence.once");
|
|
75
|
+
const o = f(r, {
|
|
76
|
+
dateStyle: "medium",
|
|
77
|
+
timeStyle: "short",
|
|
78
|
+
timeZone: n.timezone || "UTC"
|
|
79
|
+
}).format(new Date(n.run_at));
|
|
80
|
+
return t("schedules:cadence.once_at", { datetime: o });
|
|
81
|
+
}
|
|
82
|
+
if (n.kind === "interval") {
|
|
83
|
+
const o = n.interval_minutes ?? 60;
|
|
84
|
+
return o % 60 === 0 ? t("schedules:cadence.every_hours", { hours: o / 60 }) : t("schedules:cadence.every_minutes", { minutes: o });
|
|
85
|
+
}
|
|
86
|
+
const e = y(n.cron);
|
|
87
|
+
if (e) {
|
|
88
|
+
const o = h(e.hour, e.minute, r);
|
|
89
|
+
return e.frequency === "daily" ? t("schedules:cadence.daily", { time: o }) : e.daysOfWeek.length === 1 ? t("schedules:cadence.weekly", {
|
|
90
|
+
day: t(`schedules:days.${e.daysOfWeek[0]}`),
|
|
91
|
+
time: o
|
|
92
|
+
}) : t("schedules:cadence.weekly", {
|
|
93
|
+
day: $(e.daysOfWeek, t, r),
|
|
94
|
+
time: o
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return n.cron ? t("schedules:cadence.custom", { cron: n.cron }) : t("schedules:cadence.custom_empty");
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
y as cronToPreset,
|
|
101
|
+
p as describeSchedule,
|
|
102
|
+
T as detectLocalTimezone,
|
|
103
|
+
D as presetToCron
|
|
104
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createAttachmentCache as
|
|
1
|
+
import { createAttachmentCache as y } from "../attachments/attachmentCache.es.js";
|
|
2
2
|
import { isTurnActive as T } from "./threadReducer.es.js";
|
|
3
3
|
import { createThreadController as w } from "./threadController.es.js";
|
|
4
|
-
const x = 3e4, C = 8,
|
|
4
|
+
const x = 3e4, C = 8, S = [];
|
|
5
5
|
function N({
|
|
6
6
|
http: A,
|
|
7
7
|
resolveAttachment: D,
|
|
@@ -9,70 +9,70 @@ function N({
|
|
|
9
9
|
getRunOptions: M,
|
|
10
10
|
now: u = Date.now
|
|
11
11
|
}) {
|
|
12
|
-
const _ =
|
|
13
|
-
let o, a =
|
|
14
|
-
const m = (e) =>
|
|
15
|
-
function
|
|
12
|
+
const _ = y(D), c = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
|
|
13
|
+
let o, a = S;
|
|
14
|
+
const m = (e) => f.forEach((t) => t(e)), h = /* @__PURE__ */ new Set(), d = () => h.forEach((e) => e());
|
|
15
|
+
function v() {
|
|
16
16
|
const e = [...c].filter(([, t]) => T(t.controller.getState())).map(([t]) => t).sort();
|
|
17
|
-
e.length === a.length && e.every((t,
|
|
17
|
+
e.length === a.length && e.every((t, r) => t === a[r]) || (a = e.length === 0 ? S : e, l.forEach((t) => t()));
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
19
|
+
function E(e, t) {
|
|
20
|
+
const r = {
|
|
21
21
|
controller: t,
|
|
22
22
|
idleSince: u(),
|
|
23
|
-
unsubscribe: t.subscribe(
|
|
23
|
+
unsubscribe: t.subscribe(v)
|
|
24
24
|
};
|
|
25
|
-
return c.set(e,
|
|
25
|
+
return c.set(e, r), d(), v(), r;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function b(e) {
|
|
28
28
|
const t = w({
|
|
29
29
|
http: A,
|
|
30
30
|
attachments: _,
|
|
31
31
|
threadId: e,
|
|
32
32
|
throttleMs: L,
|
|
33
33
|
getRunOptions: M,
|
|
34
|
-
onStart: (
|
|
35
|
-
o === t && (o = void 0),
|
|
34
|
+
onStart: (r, n) => {
|
|
35
|
+
o === t && (o = void 0), E(r, t), m({ type: "thread-started", threadId: r, message: n });
|
|
36
36
|
},
|
|
37
|
-
onTurnEnd: (
|
|
38
|
-
const
|
|
39
|
-
|
|
37
|
+
onTurnEnd: (r) => {
|
|
38
|
+
const n = c.get(r.threadId);
|
|
39
|
+
n && (n.idleSince = u()), m({ type: "turn-ended", ...r }), g();
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
return t;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
return (
|
|
44
|
+
function k(e) {
|
|
45
|
+
return (s.get(e.controller) ?? 0) === 0 && !T(e.controller.getState());
|
|
46
46
|
}
|
|
47
47
|
function p(e, t) {
|
|
48
|
-
c.delete(e), t.unsubscribe(), t.controller.dispose(),
|
|
48
|
+
c.delete(e), t.unsubscribe(), t.controller.dispose(), d();
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
const e = [...c].filter(([,
|
|
52
|
-
|
|
50
|
+
function g() {
|
|
51
|
+
const e = [...c].filter(([, n]) => k(n)), t = u() - x, r = e.filter(([n, i]) => i.idleSince > t ? !0 : (p(n, i), !1));
|
|
52
|
+
r.sort(([, n], [, i]) => n.idleSince - i.idleSince).slice(0, Math.max(0, r.length - C)).forEach(([n, i]) => p(n, i));
|
|
53
53
|
}
|
|
54
54
|
return {
|
|
55
55
|
thread(e) {
|
|
56
56
|
if (e === null)
|
|
57
|
-
return o || (o =
|
|
58
|
-
const t = c.get(e)?.controller ??
|
|
59
|
-
return
|
|
57
|
+
return o || (o = b(null), d()), o;
|
|
58
|
+
const t = c.get(e)?.controller ?? E(e, b(e)).controller;
|
|
59
|
+
return g(), t;
|
|
60
60
|
},
|
|
61
61
|
peek: (e) => e === null ? o : c.get(e)?.controller,
|
|
62
62
|
hold(e) {
|
|
63
|
-
|
|
63
|
+
s.set(e, (s.get(e) ?? 0) + 1);
|
|
64
64
|
let t = !1;
|
|
65
65
|
return () => {
|
|
66
66
|
if (t) return;
|
|
67
67
|
t = !0;
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
|
|
68
|
+
const r = (s.get(e) ?? 1) - 1;
|
|
69
|
+
if (r > 0) {
|
|
70
|
+
s.set(e, r);
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
73
|
+
s.delete(e);
|
|
74
|
+
const n = [...c.values()].find((i) => i.controller === e);
|
|
75
|
+
n && (n.idleSince = u()), g();
|
|
76
76
|
};
|
|
77
77
|
},
|
|
78
78
|
getActiveThreadIds: () => a,
|
|
@@ -82,18 +82,22 @@ function N({
|
|
|
82
82
|
};
|
|
83
83
|
},
|
|
84
84
|
subscribeThreads(e) {
|
|
85
|
-
return
|
|
86
|
-
|
|
85
|
+
return h.add(e), () => {
|
|
86
|
+
h.delete(e);
|
|
87
87
|
};
|
|
88
88
|
},
|
|
89
89
|
onEvent(e) {
|
|
90
|
-
return
|
|
91
|
-
|
|
90
|
+
return f.add(e), () => {
|
|
91
|
+
f.delete(e);
|
|
92
92
|
};
|
|
93
93
|
},
|
|
94
|
+
reset() {
|
|
95
|
+
for (const [e, t] of c) p(e, t);
|
|
96
|
+
o?.dispose(), o = void 0, s.clear(), a = S, l.forEach((e) => e()), d();
|
|
97
|
+
},
|
|
94
98
|
dispose() {
|
|
95
99
|
for (const [e, t] of c) p(e, t);
|
|
96
|
-
o?.dispose(), o = void 0,
|
|
100
|
+
o?.dispose(), o = void 0, s.clear(), f.clear(), a = S, l.forEach((e) => e()), l.clear(), d(), h.clear();
|
|
97
101
|
}
|
|
98
102
|
};
|
|
99
103
|
}
|
|
@@ -1,48 +1,53 @@
|
|
|
1
|
-
import { DefaultChatTransport as
|
|
2
|
-
import { errorFromResponse as
|
|
3
|
-
import { answersRequestBody as q, chatRequestBody as
|
|
4
|
-
import { startTrace as
|
|
5
|
-
function
|
|
1
|
+
import { DefaultChatTransport as d } from "ai";
|
|
2
|
+
import { errorFromResponse as l } from "../client/http.es.js";
|
|
3
|
+
import { answersRequestBody as q, chatRequestBody as w } from "../protocol/chatRequest.es.js";
|
|
4
|
+
import { startTrace as y, logRequestFailed as g, markReported as R, logRequestRefused as C, monitorChatResponse as T } from "./chatDiagnostics.es.js";
|
|
5
|
+
function B(n, r, {
|
|
6
6
|
lastRequest: c,
|
|
7
7
|
toolOutputs: h = [],
|
|
8
8
|
runOptions: u,
|
|
9
|
-
resume: p
|
|
9
|
+
resume: p,
|
|
10
|
+
abortSignal: i
|
|
10
11
|
}) {
|
|
11
|
-
return new
|
|
12
|
+
return new d({
|
|
12
13
|
api: "/chat",
|
|
13
14
|
// The server holds the thread's history, so only the message being sent goes, or, when the
|
|
14
15
|
// last message is an answer, the user's answers to the tool calls it waits on.
|
|
15
|
-
prepareSendMessagesRequest: ({ messages:
|
|
16
|
-
const
|
|
16
|
+
prepareSendMessagesRequest: ({ messages: s }) => {
|
|
17
|
+
const o = s.at(-1);
|
|
17
18
|
return {
|
|
18
|
-
body:
|
|
19
|
+
body: o?.role === "assistant" ? q(r, o, { toolOutputs: h, options: u }) : w(r, s, u)
|
|
19
20
|
};
|
|
20
21
|
},
|
|
21
22
|
prepareReconnectToStreamRequest: () => ({
|
|
22
|
-
api: p ?
|
|
23
|
+
api: p ? S(r, p.turnId, p.after) : "/chat"
|
|
23
24
|
}),
|
|
24
25
|
// The transport passes one of the paths above.
|
|
25
|
-
fetch: async (
|
|
26
|
-
const
|
|
27
|
-
c.trace =
|
|
26
|
+
fetch: async (s, o) => {
|
|
27
|
+
const m = typeof s == "string" ? s : "/chat", f = new Headers(o?.headers), a = y(r);
|
|
28
|
+
c.trace = a, f.set("X-Request-ID", a.requestId);
|
|
28
29
|
let t;
|
|
29
30
|
try {
|
|
30
|
-
t = await n.fetch(
|
|
31
|
+
t = await n.fetch(m, {
|
|
32
|
+
...o,
|
|
33
|
+
signal: i ?? o?.signal,
|
|
34
|
+
headers: f
|
|
35
|
+
});
|
|
31
36
|
} catch (e) {
|
|
32
|
-
throw
|
|
37
|
+
throw g(a, e), e instanceof Error ? R(e) : e;
|
|
33
38
|
}
|
|
34
39
|
if (!t.ok) {
|
|
35
|
-
|
|
40
|
+
a.status = t.status;
|
|
36
41
|
const e = await t.text().catch(() => "");
|
|
37
|
-
throw C(
|
|
42
|
+
throw C(a, t, e), R(l(t, e));
|
|
38
43
|
}
|
|
39
|
-
return T(
|
|
44
|
+
return T(a, t);
|
|
40
45
|
}
|
|
41
46
|
});
|
|
42
47
|
}
|
|
43
|
-
function
|
|
48
|
+
function S(n, r, c) {
|
|
44
49
|
return `/chat/threads/${encodeURIComponent(n)}/turns/${encodeURIComponent(r)}/stream?after=${c}`;
|
|
45
50
|
}
|
|
46
51
|
export {
|
|
47
|
-
|
|
52
|
+
B as createChatTransport
|
|
48
53
|
};
|
|
@@ -2,28 +2,28 @@ function l(t, r) {
|
|
|
2
2
|
if (Object.is(t, r)) return r;
|
|
3
3
|
if (Array.isArray(r)) {
|
|
4
4
|
if (!Array.isArray(t)) return r;
|
|
5
|
-
let
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
return
|
|
5
|
+
let e = t.length === r.length;
|
|
6
|
+
const c = r.map((a, n) => {
|
|
7
|
+
const f = l(t[n], a);
|
|
8
|
+
return f !== t[n] && (e = !1), f;
|
|
9
9
|
});
|
|
10
|
-
return
|
|
10
|
+
return e ? t : c;
|
|
11
11
|
}
|
|
12
12
|
if (y(r)) {
|
|
13
13
|
if (!y(t)) return r;
|
|
14
|
-
const
|
|
15
|
-
let
|
|
14
|
+
const e = Object.keys(r);
|
|
15
|
+
let c = e.length === Object.keys(t).length;
|
|
16
16
|
const a = {};
|
|
17
|
-
for (const
|
|
18
|
-
const
|
|
19
|
-
a[
|
|
17
|
+
for (const n of e) {
|
|
18
|
+
const f = l(t[n], r[n]);
|
|
19
|
+
a[n] = f, (f !== t[n] || !(n in t)) && (c = !1);
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return c ? t : a;
|
|
22
22
|
}
|
|
23
23
|
return r;
|
|
24
24
|
}
|
|
25
25
|
function y(t) {
|
|
26
|
-
if (typeof t != "object" || t === null) return !1;
|
|
26
|
+
if (typeof t != "object" || t === null || "$$typeof" in t) return !1;
|
|
27
27
|
const r = Object.getPrototypeOf(t);
|
|
28
28
|
return r === Object.prototype || r === null;
|
|
29
29
|
}
|