@gentiq/core 1.0.0-beta.2 → 1.0.0-beta.4
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 +65 -43
- package/dist/composer/composerDrafts.es.js +77 -34
- package/dist/composer/runSelection.es.js +142 -0
- package/dist/errors.es.js +5 -0
- package/dist/index.d.ts +1109 -42
- package/dist/index.es.js +45 -42
- package/dist/internal.d.ts +1015 -55
- package/dist/protocol/chatRequest.es.js +47 -38
- package/dist/thread/chatTransport.es.js +28 -17
- package/dist/thread/threadController.es.js +200 -184
- package/package.json +1 -1
|
@@ -1,295 +1,311 @@
|
|
|
1
|
-
import { generateId as
|
|
2
|
-
import { nanoid as
|
|
3
|
-
import { isGentiqError as
|
|
4
|
-
import { isAwaitingOutput as
|
|
5
|
-
import { toGentiqMessages as
|
|
6
|
-
import { logDisconnected as
|
|
7
|
-
import { createChatTransport as
|
|
8
|
-
import { shareUnchanged as
|
|
9
|
-
import { isTurnActive as
|
|
10
|
-
const
|
|
11
|
-
function
|
|
1
|
+
import { generateId as W, readUIMessageStream as ft } from "ai";
|
|
2
|
+
import { nanoid as pt } from "nanoid";
|
|
3
|
+
import { isGentiqError as at, GentiqErrorCode as N, GentiqError as yt } from "../errors.es.js";
|
|
4
|
+
import { isAwaitingOutput as mt, isAwaitingApproval as gt, resolveMessageId as G, messageFeedback as X, isAwaitingUser as ht, attachmentFilePart as $ } from "../protocol/messages.es.js";
|
|
5
|
+
import { toGentiqMessages as tt } from "../protocol/storedMessages.es.js";
|
|
6
|
+
import { logDisconnected as bt, logChatError as wt } from "./chatDiagnostics.es.js";
|
|
7
|
+
import { createChatTransport as et } from "./chatTransport.es.js";
|
|
8
|
+
import { shareUnchanged as Tt } from "./shareUnchanged.es.js";
|
|
9
|
+
import { isTurnActive as Et, newThreadState as vt, storedThreadState as It, threadReducer as Rt } from "./threadReducer.es.js";
|
|
10
|
+
const rt = 50, nt = [250, 500, 1e3, 2e3, 4e3, 8e3];
|
|
11
|
+
function Ht({
|
|
12
12
|
http: n,
|
|
13
13
|
attachments: o,
|
|
14
|
-
threadId:
|
|
15
|
-
throttleMs:
|
|
16
|
-
onStart:
|
|
17
|
-
onTurnEnd:
|
|
18
|
-
getRunOptions:
|
|
14
|
+
threadId: h,
|
|
15
|
+
throttleMs: p = 0,
|
|
16
|
+
onStart: U,
|
|
17
|
+
onTurnEnd: A,
|
|
18
|
+
getRunOptions: v
|
|
19
19
|
}) {
|
|
20
|
-
let s =
|
|
21
|
-
const
|
|
22
|
-
let
|
|
23
|
-
const
|
|
24
|
-
let
|
|
25
|
-
const
|
|
26
|
-
let
|
|
27
|
-
function
|
|
28
|
-
const e =
|
|
29
|
-
e !== s && (s = e,
|
|
20
|
+
let s = h === null ? vt() : It(h);
|
|
21
|
+
const C = /* @__PURE__ */ new Set(), S = [];
|
|
22
|
+
let O;
|
|
23
|
+
const D = /* @__PURE__ */ new Set();
|
|
24
|
+
let T, j = 0, H, Y;
|
|
25
|
+
const M = /* @__PURE__ */ new Map();
|
|
26
|
+
let f = !1, I, R;
|
|
27
|
+
function u(t) {
|
|
28
|
+
const e = Rt(s, t);
|
|
29
|
+
e !== s && (s = e, C.forEach((r) => r()));
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
if (clearTimeout(
|
|
31
|
+
function k() {
|
|
32
|
+
if (clearTimeout(R), R = void 0, !I) return;
|
|
33
33
|
const { turn: t, message: e } = I;
|
|
34
|
-
I = void 0,
|
|
34
|
+
I = void 0, u({ type: "reply", turn: t, message: e });
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
if (
|
|
38
|
-
I = { turn: t, message: e },
|
|
39
|
-
|
|
40
|
-
},
|
|
36
|
+
function ot(t, e) {
|
|
37
|
+
if (p <= 0) return u({ type: "reply", turn: t, message: e });
|
|
38
|
+
I = { turn: t, message: e }, R === void 0 && (k(), R = setTimeout(function r() {
|
|
39
|
+
R = void 0, I && (k(), R = setTimeout(r, p));
|
|
40
|
+
}, p));
|
|
41
41
|
}
|
|
42
|
-
async function
|
|
43
|
-
return
|
|
42
|
+
async function Z(t) {
|
|
43
|
+
return S.push(t), o.acquire(t);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function z(t) {
|
|
46
46
|
t.forEach((e) => o.release(e));
|
|
47
47
|
}
|
|
48
|
-
async function
|
|
49
|
-
return t.file ? (
|
|
48
|
+
async function ut(t) {
|
|
49
|
+
return t.file ? (S.push(t.id), $(t, o.adopt(t.id, t.file))) : $(t, await Z(t.id));
|
|
50
50
|
}
|
|
51
|
-
function
|
|
52
|
-
return
|
|
51
|
+
function B(t, e, r, a, i) {
|
|
52
|
+
return et(n, t, {
|
|
53
53
|
lastRequest: a,
|
|
54
54
|
resume: { turnId: e, after: r },
|
|
55
55
|
abortSignal: i
|
|
56
56
|
}).reconnectToStream({ chatId: t });
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function dt(t, e, {
|
|
59
59
|
turnId: r,
|
|
60
60
|
signal: a,
|
|
61
61
|
lastRequest: i,
|
|
62
|
-
onTurn:
|
|
62
|
+
onTurn: d
|
|
63
63
|
}) {
|
|
64
|
-
let
|
|
64
|
+
let l = r, g = 0, w = e.getReader();
|
|
65
65
|
return new ReadableStream({
|
|
66
|
-
async pull(
|
|
67
|
-
let
|
|
66
|
+
async pull(b) {
|
|
67
|
+
let y = 0;
|
|
68
68
|
for (; ; )
|
|
69
69
|
try {
|
|
70
|
-
const { done:
|
|
71
|
-
return
|
|
72
|
-
} catch (
|
|
73
|
-
if (a.aborted ||
|
|
74
|
-
await
|
|
70
|
+
const { done: c, value: m } = await w.read();
|
|
71
|
+
return c ? b.close() : (g += 1, m.type === "data-turn" && St(m.data) && (l = m.data.turn_id, d(l)), b.enqueue(m));
|
|
72
|
+
} catch (c) {
|
|
73
|
+
if (a.aborted || l === void 0 || !F(c) || y >= nt.length) throw c;
|
|
74
|
+
await At(nt[y], a), y += 1;
|
|
75
75
|
try {
|
|
76
|
-
const
|
|
77
|
-
if (!
|
|
78
|
-
|
|
79
|
-
} catch (
|
|
80
|
-
if (a.aborted || !
|
|
76
|
+
const m = await B(t, l, g, i, a);
|
|
77
|
+
if (!m) return b.close();
|
|
78
|
+
w = m.getReader();
|
|
79
|
+
} catch (m) {
|
|
80
|
+
if (a.aborted || !Ot(m)) throw m;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
|
-
cancel(
|
|
85
|
-
return
|
|
84
|
+
cancel(b) {
|
|
85
|
+
return w.cancel(b);
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
async function
|
|
90
|
-
|
|
91
|
-
a
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
async function x(t, e, {
|
|
90
|
+
start: r = !1,
|
|
91
|
+
resume: a,
|
|
92
|
+
mode: i,
|
|
93
|
+
capabilities: d,
|
|
94
|
+
useLastSelection: l = !1
|
|
95
|
+
} = {}) {
|
|
96
|
+
const g = l ? i ?? H : i, w = l ? d ?? Y : d, b = a ? [] : [...M.values()];
|
|
97
|
+
a || M.clear(), j += 1;
|
|
98
|
+
const y = j, c = new AbortController(), m = { turn: y, abort: c, threadId: t, turnId: a };
|
|
99
|
+
T = m, u(
|
|
100
|
+
r ? { type: "start", threadId: t, messages: e, turn: y } : { type: "send", messages: e, turn: y }
|
|
95
101
|
);
|
|
96
|
-
const
|
|
97
|
-
let
|
|
102
|
+
const q = {};
|
|
103
|
+
let P, _;
|
|
98
104
|
try {
|
|
99
|
-
const
|
|
100
|
-
lastRequest:
|
|
101
|
-
toolOutputs:
|
|
102
|
-
runOptions:
|
|
105
|
+
const E = a ? await B(t, a, 0, q, c.signal) : await et(n, t, {
|
|
106
|
+
lastRequest: q,
|
|
107
|
+
toolOutputs: b,
|
|
108
|
+
runOptions: v?.(),
|
|
109
|
+
mode: g,
|
|
110
|
+
capabilities: w
|
|
103
111
|
}).sendMessages({
|
|
104
112
|
trigger: "submit-message",
|
|
105
113
|
chatId: t,
|
|
106
114
|
messageId: void 0,
|
|
107
115
|
messages: [...e],
|
|
108
|
-
abortSignal:
|
|
109
|
-
}),
|
|
116
|
+
abortSignal: c.signal
|
|
117
|
+
}), lt = dt(t, E ?? qt(), {
|
|
110
118
|
turnId: a,
|
|
111
|
-
signal:
|
|
112
|
-
lastRequest:
|
|
113
|
-
onTurn: (
|
|
114
|
-
m.turnId =
|
|
119
|
+
signal: c.signal,
|
|
120
|
+
lastRequest: q,
|
|
121
|
+
onTurn: (L) => {
|
|
122
|
+
m.turnId = L;
|
|
115
123
|
}
|
|
116
|
-
}),
|
|
117
|
-
message:
|
|
118
|
-
stream:
|
|
124
|
+
}), Q = e.at(-1), ct = ft({
|
|
125
|
+
message: Q?.role === "assistant" ? xt(Q) : { id: W(), role: "assistant", parts: [] },
|
|
126
|
+
stream: lt,
|
|
119
127
|
terminateOnError: !0
|
|
120
128
|
});
|
|
121
|
-
for await (const
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
|
|
129
|
+
for await (const L of ct) {
|
|
130
|
+
if (c.signal.aborted) continue;
|
|
131
|
+
const V = Tt(P, L);
|
|
132
|
+
P = V, ot(y, V);
|
|
125
133
|
}
|
|
126
|
-
|
|
127
|
-
} catch (
|
|
128
|
-
|
|
134
|
+
_ = c.signal.aborted ? { outcome: "stopped" } : { outcome: "finished" };
|
|
135
|
+
} catch (E) {
|
|
136
|
+
c.signal.aborted || E instanceof Error && E.name === "AbortError" ? _ = { outcome: "stopped" } : (F(E) && bt(q.trace), E instanceof Error && wt(q.trace, E), _ = { outcome: "failed", error: Ct(E) });
|
|
129
137
|
}
|
|
130
|
-
|
|
138
|
+
T?.turn === y && (T = void 0), I?.turn === y && k(), _.outcome === "failed" ? u({ type: "fail", turn: y, error: _.error }) : u({ type: _.outcome === "stopped" ? "stop" : "finish", turn: y }), f || A?.({ threadId: t, ..._, reply: P, ...kt(P) });
|
|
131
139
|
}
|
|
132
|
-
async function
|
|
140
|
+
async function J() {
|
|
133
141
|
if (s.status !== "ready" && s.status !== "error") return;
|
|
134
142
|
const t = s.messages.at(-1);
|
|
135
|
-
if (!(!t || t.parts.some(
|
|
136
|
-
return
|
|
143
|
+
if (!(!t || t.parts.some(ht)))
|
|
144
|
+
return x(s.threadId, s.messages, { useLastSelection: !0 });
|
|
137
145
|
}
|
|
138
|
-
const
|
|
146
|
+
const K = {
|
|
139
147
|
getState: () => s,
|
|
140
148
|
subscribe(t) {
|
|
141
|
-
return
|
|
142
|
-
|
|
149
|
+
return C.add(t), () => {
|
|
150
|
+
C.delete(t);
|
|
143
151
|
};
|
|
144
152
|
},
|
|
145
153
|
async load() {
|
|
146
|
-
if (
|
|
154
|
+
if (f || s.status !== "unloaded" && s.status !== "load-failed") return;
|
|
147
155
|
const { threadId: t } = s, e = new AbortController();
|
|
148
|
-
|
|
156
|
+
O = e, u({ type: "load" });
|
|
149
157
|
try {
|
|
150
158
|
const r = await n.request("get", "/chat/threads/{thread_id}", {
|
|
151
159
|
path: { thread_id: t },
|
|
152
|
-
query: { limit:
|
|
160
|
+
query: { limit: rt },
|
|
153
161
|
signal: e.signal
|
|
154
162
|
});
|
|
155
163
|
if (e.signal.aborted) return;
|
|
156
|
-
const a = r.turn?.status === "failed" ?
|
|
157
|
-
|
|
164
|
+
const a = r.turn?.status === "failed" ? it(r.turn) : void 0;
|
|
165
|
+
u({
|
|
158
166
|
type: "loaded",
|
|
159
|
-
messages:
|
|
167
|
+
messages: tt(r.items),
|
|
160
168
|
cursor: r.next_cursor,
|
|
161
169
|
...a ? { error: a } : {}
|
|
162
170
|
});
|
|
163
|
-
const i =
|
|
164
|
-
r.turn?.status === "running" && i.status === "ready" &&
|
|
171
|
+
const i = K.getState();
|
|
172
|
+
r.turn?.status === "running" && i.status === "ready" && x(t, i.messages, { resume: r.turn.id });
|
|
165
173
|
} catch (r) {
|
|
166
|
-
e.signal.aborted ||
|
|
174
|
+
e.signal.aborted || u({ type: "load-failed", error: r });
|
|
167
175
|
} finally {
|
|
168
|
-
|
|
176
|
+
O === e && (O = void 0);
|
|
169
177
|
}
|
|
170
178
|
},
|
|
171
179
|
async loadEarlier() {
|
|
172
180
|
const { threadId: t, earlier: e } = s;
|
|
173
|
-
if (!(
|
|
181
|
+
if (!(f || t === null || e.cursor === null) && e.status !== "loading" && (u({ type: "earlier-load" }), s.earlier.status === "loading"))
|
|
174
182
|
try {
|
|
175
183
|
const r = await n.request("get", "/chat/threads/{thread_id}", {
|
|
176
184
|
path: { thread_id: t },
|
|
177
|
-
query: { limit:
|
|
185
|
+
query: { limit: rt, before: e.cursor }
|
|
178
186
|
});
|
|
179
|
-
if (
|
|
180
|
-
|
|
187
|
+
if (f) return;
|
|
188
|
+
u({
|
|
181
189
|
type: "earlier-loaded",
|
|
182
|
-
messages:
|
|
190
|
+
messages: tt(r.items),
|
|
183
191
|
cursor: r.next_cursor
|
|
184
192
|
});
|
|
185
193
|
} catch (r) {
|
|
186
|
-
|
|
194
|
+
f || u({ type: "earlier-failed", error: r });
|
|
187
195
|
}
|
|
188
196
|
},
|
|
189
197
|
loadAttachment(t) {
|
|
190
|
-
|
|
191
|
-
!
|
|
198
|
+
f || D.has(t) || (D.add(t), Z(t).then((e) => {
|
|
199
|
+
!f && e && u({ type: "attachment", attachmentId: t, url: e }), e || D.delete(t);
|
|
192
200
|
}));
|
|
193
201
|
},
|
|
194
|
-
async send({
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
202
|
+
async send({
|
|
203
|
+
text: t,
|
|
204
|
+
attachments: e = [],
|
|
205
|
+
references: r = [],
|
|
206
|
+
voiceInputs: a = [],
|
|
207
|
+
mode: i,
|
|
208
|
+
capabilities: d
|
|
209
|
+
}) {
|
|
210
|
+
if (!st(s) || f) return;
|
|
211
|
+
const l = t.trim();
|
|
212
|
+
if (!l && e.length === 0 && r.length === 0) return;
|
|
213
|
+
const g = S.length, w = await Promise.all(e.map(ut));
|
|
214
|
+
if (!st(s) || f) {
|
|
215
|
+
z(S.splice(g));
|
|
201
216
|
return;
|
|
202
217
|
}
|
|
203
|
-
|
|
218
|
+
H = i, Y = d;
|
|
219
|
+
const b = {
|
|
204
220
|
...r.length > 0 ? { references: r } : {},
|
|
205
221
|
...a.length > 0 ? { voice_inputs: a } : {}
|
|
206
|
-
},
|
|
207
|
-
id:
|
|
222
|
+
}, y = {
|
|
223
|
+
id: W(),
|
|
208
224
|
role: "user",
|
|
209
225
|
parts: [
|
|
210
|
-
...r.map((
|
|
211
|
-
...
|
|
212
|
-
{ type: "text", text:
|
|
226
|
+
...r.map((c) => ({ type: "data-reference", data: c })),
|
|
227
|
+
...w,
|
|
228
|
+
{ type: "text", text: l }
|
|
213
229
|
],
|
|
214
|
-
...Object.keys(
|
|
230
|
+
...Object.keys(b).length > 0 ? { metadata: b } : {}
|
|
215
231
|
};
|
|
216
232
|
if (s.status === "new") {
|
|
217
|
-
const
|
|
218
|
-
return
|
|
233
|
+
const c = pt();
|
|
234
|
+
return U?.(c, y), x(c, [y], { start: !0, mode: i, capabilities: d });
|
|
219
235
|
}
|
|
220
|
-
return
|
|
236
|
+
return x(s.threadId, [...s.messages, y], { mode: i, capabilities: d });
|
|
221
237
|
},
|
|
222
238
|
async retry(t) {
|
|
223
|
-
if (
|
|
239
|
+
if (f || s.status !== "ready" && s.status !== "error") return;
|
|
224
240
|
const { messages: e, threadId: r } = s, a = e.findIndex(
|
|
225
|
-
(
|
|
241
|
+
(d) => d.role === "assistant" && (d.id === t || G(d) === t)
|
|
226
242
|
);
|
|
227
243
|
if (a === -1) return;
|
|
228
244
|
let i = a - 1;
|
|
229
245
|
for (; i >= 0 && e[i].role !== "user"; ) i -= 1;
|
|
230
246
|
if (i !== -1)
|
|
231
|
-
return
|
|
247
|
+
return x(r, e.slice(0, i + 1), { useLastSelection: !0 });
|
|
232
248
|
},
|
|
233
249
|
async edit(t, { text: e }) {
|
|
234
|
-
if (
|
|
250
|
+
if (f || s.status !== "ready" && s.status !== "error") return;
|
|
235
251
|
const { messages: r, threadId: a } = s, i = r.findIndex(
|
|
236
|
-
(
|
|
252
|
+
(g) => g.role === "user" && g.id === t
|
|
237
253
|
);
|
|
238
254
|
if (i === -1) return;
|
|
239
|
-
const
|
|
240
|
-
if (
|
|
241
|
-
const
|
|
242
|
-
return
|
|
255
|
+
const d = _t(r[i].parts, e.trim());
|
|
256
|
+
if (d.length === 0) return;
|
|
257
|
+
const l = { ...r[i], parts: d };
|
|
258
|
+
return x(a, [...r.slice(0, i), l], { useLastSelection: !0 });
|
|
243
259
|
},
|
|
244
260
|
async setFeedback(t, e) {
|
|
245
261
|
const { threadId: r } = s;
|
|
246
|
-
if (
|
|
262
|
+
if (f || r === null) return;
|
|
247
263
|
const a = s.messages.find(
|
|
248
|
-
(
|
|
264
|
+
(l) => l.role === "assistant" && (l.id === t || G(l) === t)
|
|
249
265
|
);
|
|
250
266
|
if (!a) return;
|
|
251
|
-
const i =
|
|
252
|
-
|
|
267
|
+
const i = X(a), d = e ?? void 0;
|
|
268
|
+
u({ type: "feedback", messageId: a.id, feedback: d });
|
|
253
269
|
try {
|
|
254
270
|
await n.request("post", "/chat/feedback", {
|
|
255
|
-
body: { thread_id: r, message_id:
|
|
271
|
+
body: { thread_id: r, message_id: G(a), sentiment: e }
|
|
256
272
|
});
|
|
257
|
-
} catch (
|
|
258
|
-
const
|
|
259
|
-
throw
|
|
273
|
+
} catch (l) {
|
|
274
|
+
const g = s.messages.find((w) => w.id === a.id);
|
|
275
|
+
throw g && X(g) === d && u({ type: "feedback", messageId: a.id, feedback: i }), l;
|
|
260
276
|
}
|
|
261
277
|
},
|
|
262
278
|
async addToolApprovalResponse(t) {
|
|
263
|
-
if (!(
|
|
264
|
-
return
|
|
279
|
+
if (!(f || s.status !== "ready" && s.status !== "error" || !s.messages.at(-1)?.parts.some((r) => gt(r, t.id))))
|
|
280
|
+
return u({ type: "approval", response: t }), J();
|
|
265
281
|
},
|
|
266
282
|
async addToolOutput(t) {
|
|
267
|
-
if (!(
|
|
268
|
-
return
|
|
283
|
+
if (!(f || s.status !== "ready" && s.status !== "error" || !s.messages.at(-1)?.parts.some((r) => mt(r, t.toolCallId))))
|
|
284
|
+
return M.set(t.toolCallId, t), u({ type: "tool-output", response: t }), J();
|
|
269
285
|
},
|
|
270
286
|
stop() {
|
|
271
|
-
if (!
|
|
272
|
-
const { turn: t, abort: e, threadId: r } =
|
|
273
|
-
|
|
274
|
-
|
|
287
|
+
if (!T || !Et(s)) return;
|
|
288
|
+
const { turn: t, abort: e, threadId: r } = T;
|
|
289
|
+
T = void 0, e.abort(), I?.turn === t && k(), u({ type: "stop", turn: t }), n.request("post", "/chat/threads/{thread_id}/stop", { path: { thread_id: r } }).catch((a) => {
|
|
290
|
+
at(a) && a.status === 404 || f || u({ type: "stop-failed", error: a });
|
|
275
291
|
});
|
|
276
292
|
},
|
|
277
293
|
dismissError() {
|
|
278
|
-
|
|
294
|
+
u({ type: "dismiss-error" });
|
|
279
295
|
},
|
|
280
296
|
dispose() {
|
|
281
|
-
|
|
297
|
+
f || (f = !0, O?.abort(), T?.abort.abort(), T = void 0, clearTimeout(R), C.clear(), z(S.splice(0)));
|
|
282
298
|
}
|
|
283
299
|
};
|
|
284
|
-
return
|
|
300
|
+
return K;
|
|
285
301
|
}
|
|
286
|
-
function
|
|
287
|
-
const
|
|
288
|
-
if (!o) return
|
|
289
|
-
const
|
|
290
|
-
return [...
|
|
302
|
+
function _t(n, o) {
|
|
303
|
+
const h = n.findIndex((v) => v.type === "text"), p = n.filter((v) => v.type !== "text");
|
|
304
|
+
if (!o) return p;
|
|
305
|
+
const U = { type: "text", text: o }, A = h === -1 ? p.length : n.slice(0, h).filter((v) => v.type !== "text").length;
|
|
306
|
+
return [...p.slice(0, A), U, ...p.slice(A)];
|
|
291
307
|
}
|
|
292
|
-
function
|
|
308
|
+
function xt(n) {
|
|
293
309
|
return {
|
|
294
310
|
...n,
|
|
295
311
|
parts: n.parts.filter(
|
|
@@ -297,45 +313,45 @@ function wt(n) {
|
|
|
297
313
|
)
|
|
298
314
|
};
|
|
299
315
|
}
|
|
300
|
-
function
|
|
316
|
+
function st(n) {
|
|
301
317
|
return n.status === "new" || n.status === "ready" || n.status === "error";
|
|
302
318
|
}
|
|
303
|
-
function
|
|
319
|
+
function St(n) {
|
|
304
320
|
return typeof n == "object" && n !== null && typeof n.turn_id == "string";
|
|
305
321
|
}
|
|
306
|
-
function
|
|
322
|
+
function qt() {
|
|
307
323
|
return new ReadableStream({ start: (n) => n.close() });
|
|
308
324
|
}
|
|
309
|
-
function
|
|
310
|
-
return new Promise((
|
|
311
|
-
const
|
|
325
|
+
function At(n, o) {
|
|
326
|
+
return new Promise((h) => {
|
|
327
|
+
const p = setTimeout(h, n);
|
|
312
328
|
o.addEventListener("abort", () => {
|
|
313
|
-
clearTimeout(
|
|
329
|
+
clearTimeout(p), h();
|
|
314
330
|
});
|
|
315
331
|
});
|
|
316
332
|
}
|
|
317
|
-
function
|
|
318
|
-
return n instanceof Error && n.message ===
|
|
333
|
+
function Ct(n) {
|
|
334
|
+
return n instanceof Error && n.message === N.TURN_INTERRUPTED ? it({ error: N.TURN_INTERRUPTED }) : n;
|
|
319
335
|
}
|
|
320
|
-
function
|
|
321
|
-
const o = n.error ??
|
|
322
|
-
return new
|
|
336
|
+
function it(n) {
|
|
337
|
+
const o = n.error ?? N.INTERNAL_ERROR;
|
|
338
|
+
return new yt({ error: { code: o, message: "The turn broke off." } });
|
|
323
339
|
}
|
|
324
|
-
function
|
|
340
|
+
function F(n) {
|
|
325
341
|
if (!(n instanceof TypeError)) return !1;
|
|
326
342
|
const o = n.message.toLowerCase();
|
|
327
343
|
return o.includes("fetch") || o.includes("network") || o.includes("load failed") || o.includes("stream");
|
|
328
344
|
}
|
|
329
|
-
function
|
|
330
|
-
return
|
|
345
|
+
function Ot(n) {
|
|
346
|
+
return F(n) ? !0 : at(n) ? n.code === N.TIMEOUT || n.status === 502 || n.status === 503 || n.status === 504 : !1;
|
|
331
347
|
}
|
|
332
|
-
function
|
|
333
|
-
let o,
|
|
334
|
-
for (const
|
|
335
|
-
|
|
336
|
-
return { ...o ? { title: o } : {}, titlePending:
|
|
348
|
+
function kt(n) {
|
|
349
|
+
let o, h = !1;
|
|
350
|
+
for (const p of n?.parts ?? [])
|
|
351
|
+
p.type === "data-title" && p.data.title && (o = p.data.title), p.type === "data-chat-finished" && p.data.title_pending && (h = !0);
|
|
352
|
+
return { ...o ? { title: o } : {}, titlePending: h };
|
|
337
353
|
}
|
|
338
354
|
export {
|
|
339
|
-
|
|
340
|
-
|
|
355
|
+
rt as THREAD_PAGE_SIZE,
|
|
356
|
+
Ht as createThreadController
|
|
341
357
|
};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"provenance": false
|
|
12
12
|
},
|
|
13
13
|
"description": "Framework-free core of the Gentiq SDK: the API client, the chat protocol and the thread controller.",
|
|
14
|
-
"version": "1.0.0-beta.
|
|
14
|
+
"version": "1.0.0-beta.4",
|
|
15
15
|
"license": "Apache-2.0",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"files": [
|