@gentiq/core 1.0.0-beta.1 → 1.0.0-beta.3

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