@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,42 +1,46 @@
1
1
  import { createGentiqRuntime as o } from "./client/api.es.js";
2
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";
3
+ import { BRANDING_URL_PREFIX as c, isValidIconUrl as m, resolveBrandingUrl as x } from "./client/brandingUrl.es.js";
4
+ import { createHttpClient as i } from "./client/http.es.js";
5
+ import { exchangeLoginCodeOnce as g } from "./client/loginCode.es.js";
6
+ import { composerScope as s } from "./composer/composerDrafts.es.js";
7
+ import { normalizeReference as h, normalizeWhitespace as R, sourceTextSignature as S, truncateReferenceText as L } from "./composer/references.es.js";
8
+ import { createVoiceRecorder as T, isVoiceRecordingSupported as B } from "./composer/voiceRecorder.es.js";
9
+ import { getDateLocale as U, getNumberLocale as b } from "./datetime.es.js";
10
+ import { debugLog as D } from "./debugLog.es.js";
11
+ import { warnOnceInDevelopment as P } from "./devWarning.es.js";
12
+ import { getLanguageBadge as q } from "./languages.es.js";
13
+ import { messageFeedback as z } from "./protocol/messages.es.js";
14
+ import { isStoredPart as F, isStoredToolPart as G } from "./protocol/storedMessages.es.js";
15
+ import { shareUnchanged as _ } from "./thread/shareUnchanged.es.js";
16
+ import { newThreadState as y, storedThreadState as E } from "./thread/threadReducer.es.js";
17
+ import { uniqueBy as W } from "./uniqueBy.es.js";
17
18
  export {
18
- d as composerScope,
19
+ c as BRANDING_URL_PREFIX,
20
+ s as composerScope,
19
21
  o as createGentiqRuntime,
20
- m as createHttpClient,
22
+ i as createHttpClient,
21
23
  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,
24
+ T as createVoiceRecorder,
25
+ D as debugLog,
26
+ g as exchangeLoginCodeOnce,
27
+ U as getDateLocale,
28
+ q as getLanguageBadge,
29
+ b as getNumberLocale,
30
+ F as isStoredPart,
31
+ G as isStoredToolPart,
32
+ m as isValidIconUrl,
33
+ B as isVoiceRecordingSupported,
34
+ z as messageFeedback,
35
+ y as newThreadState,
36
+ h as normalizeReference,
37
+ R as normalizeWhitespace,
35
38
  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
39
+ x as resolveBrandingUrl,
40
+ _ as shareUnchanged,
41
+ S as sourceTextSignature,
42
+ E as storedThreadState,
43
+ L as truncateReferenceText,
44
+ W as uniqueBy,
45
+ P as warnOnceInDevelopment
42
46
  };
@@ -1,78 +1,87 @@
1
- import { isToolUIPart as l } from "ai";
2
- import { resolveMessageId as c } from "./messages.es.js";
3
- function v(e, n, r) {
4
- const t = n.at(-1);
1
+ import { isToolUIPart as u } from "ai";
2
+ import { resolveMessageId as f } from "./messages.es.js";
3
+ function b(e, r, n) {
4
+ const t = r.at(-1);
5
5
  if (!t || t.role !== "user")
6
6
  throw new Error("Only a user message can be sent");
7
- const s = n.slice(0, -1).reverse().find((o) => o.role === "assistant"), a = f(t.metadata);
7
+ const { options: s, mode: a, capabilities: i } = d(n), o = r.slice(0, -1).reverse().find((p) => p.role === "assistant"), c = g(t.metadata);
8
8
  return {
9
9
  threadId: e,
10
- parentMessageId: s ? c(s) : null,
10
+ parentMessageId: o ? f(o) : null,
11
11
  message: {
12
12
  id: t.id,
13
13
  role: "user",
14
- parts: t.parts.flatMap(p),
15
- ...a ? { metadata: a } : {}
14
+ parts: t.parts.flatMap(y),
15
+ ...c ? { metadata: c } : {}
16
16
  },
17
- ...r ? { options: r } : {}
17
+ ...s ? { options: s } : {},
18
+ ...a !== void 0 ? { mode: a } : {},
19
+ ...i && Object.keys(i).length > 0 ? { capabilities: i } : {}
18
20
  };
19
21
  }
20
- function g(e, n, {
21
- toolOutputs: r = [],
22
- options: t
22
+ function x(e, r, {
23
+ toolOutputs: n = [],
24
+ options: t,
25
+ mode: s,
26
+ capabilities: a
23
27
  } = {}) {
24
- const s = n.parts.flatMap(
25
- (a) => l(a) && a.state === "approval-responded" ? [
28
+ const i = r.parts.flatMap(
29
+ (o) => u(o) && o.state === "approval-responded" ? [
26
30
  {
27
- id: a.approval.id,
28
- approved: a.approval.approved,
29
- ...a.approval.reason ? { reason: a.approval.reason } : {}
31
+ id: o.approval.id,
32
+ approved: o.approval.approved,
33
+ ...o.approval.reason ? { reason: o.approval.reason } : {}
30
34
  }
31
35
  ] : []
32
36
  );
33
37
  return {
34
38
  threadId: e,
35
- parentMessageId: c(n),
36
- ...s.length > 0 ? { approvals: s } : {},
37
- ...r.length > 0 ? {
38
- toolOutputs: r.map(({ toolCallId: a, output: o }) => ({
39
- id: a,
40
- output: o
39
+ parentMessageId: f(r),
40
+ ...i.length > 0 ? { approvals: i } : {},
41
+ ...n.length > 0 ? {
42
+ toolOutputs: n.map(({ toolCallId: o, output: c }) => ({
43
+ id: o,
44
+ output: c
41
45
  }))
42
46
  } : {},
43
- ...t ? { options: t } : {}
47
+ ...t ? { options: t } : {},
48
+ ...s !== void 0 ? { mode: s } : {},
49
+ ...a && Object.keys(a).length > 0 ? { capabilities: a } : {}
44
50
  };
45
51
  }
46
- function p(e) {
52
+ function d(e) {
53
+ return e ? "options" in e || "mode" in e || "capabilities" in e ? e : { options: e } : {};
54
+ }
55
+ function y(e) {
47
56
  switch (e.type) {
48
57
  case "text":
49
58
  return [{ type: "text", text: e.text }];
50
59
  case "data-reference":
51
60
  return [{ type: "data-reference", data: e.data }];
52
61
  case "file":
53
- return [u(e)];
62
+ return [v(e)];
54
63
  default:
55
64
  return [];
56
65
  }
57
66
  }
58
- function u(e) {
59
- const { mediaType: n, filename: r, attachmentId: t } = e, s = t ? { attachmentId: t } : { url: e.url };
60
- return { type: "file", mediaType: n, ...r ? { filename: r } : {}, ...s };
67
+ function v(e) {
68
+ const { mediaType: r, filename: n, attachmentId: t } = e, s = t ? { attachmentId: t } : { url: e.url };
69
+ return { type: "file", mediaType: r, ...n ? { filename: n } : {}, ...s };
61
70
  }
62
- function f(e) {
71
+ function g(e) {
63
72
  if (typeof e != "object" || e === null) return;
64
- const { references: n, voice_inputs: r } = e, t = {
65
- ...Array.isArray(n) && n.some(i) ? { references: n.filter(i) } : {},
66
- ...Array.isArray(r) && r.length > 0 ? { voice_inputs: r.filter((s) => typeof s == "string") } : {}
73
+ const { references: r, voice_inputs: n } = e, t = {
74
+ ...Array.isArray(r) && r.some(l) ? { references: r.filter(l) } : {},
75
+ ...Array.isArray(n) && n.length > 0 ? { voice_inputs: n.filter((s) => typeof s == "string") } : {}
67
76
  };
68
77
  return Object.keys(t).length > 0 ? t : void 0;
69
78
  }
70
- function i(e) {
79
+ function l(e) {
71
80
  if (typeof e != "object" || e === null) return !1;
72
- const { id: n, kind: r, label: t, excerpt: s } = e;
73
- return [n, r, t, s].every((a) => typeof a == "string");
81
+ const { id: r, kind: n, label: t, excerpt: s } = e;
82
+ return [r, n, t, s].every((a) => typeof a == "string");
74
83
  }
75
84
  export {
76
- g as answersRequestBody,
77
- v as chatRequestBody
85
+ x as answersRequestBody,
86
+ b as chatRequestBody
78
87
  };
@@ -1,53 +1,64 @@
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, {
1
+ import { DefaultChatTransport as q } from "ai";
2
+ import { errorFromResponse as w } from "../client/http.es.js";
3
+ import { answersRequestBody as y, chatRequestBody as g } from "../protocol/chatRequest.es.js";
4
+ import { startTrace as C, logRequestFailed as T, markReported as d, logRequestRefused as S, monitorChatResponse as $ } from "./chatDiagnostics.es.js";
5
+ function I(n, r, {
6
6
  lastRequest: c,
7
7
  toolOutputs: h = [],
8
8
  runOptions: u,
9
+ mode: f,
10
+ capabilities: R,
9
11
  resume: p,
10
12
  abortSignal: i
11
13
  }) {
12
- return new d({
14
+ return new q({
13
15
  api: "/chat",
14
16
  // The server holds the thread's history, so only the message being sent goes, or, when the
15
17
  // last message is an answer, the user's answers to the tool calls it waits on.
16
18
  prepareSendMessagesRequest: ({ messages: s }) => {
17
19
  const o = s.at(-1);
18
20
  return {
19
- body: o?.role === "assistant" ? q(r, o, { toolOutputs: h, options: u }) : w(r, s, u)
21
+ body: o?.role === "assistant" ? y(r, o, {
22
+ toolOutputs: h,
23
+ options: u,
24
+ mode: f,
25
+ capabilities: R
26
+ }) : g(r, s, {
27
+ options: u,
28
+ mode: f,
29
+ capabilities: R
30
+ })
20
31
  };
21
32
  },
22
33
  prepareReconnectToStreamRequest: () => ({
23
- api: p ? S(r, p.turnId, p.after) : "/chat"
34
+ api: p ? k(r, p.turnId, p.after) : "/chat"
24
35
  }),
25
36
  // The transport passes one of the paths above.
26
37
  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);
38
+ const l = typeof s == "string" ? s : "/chat", m = new Headers(o?.headers), a = C(r);
39
+ c.trace = a, m.set("X-Request-ID", a.requestId);
29
40
  let t;
30
41
  try {
31
- t = await n.fetch(m, {
42
+ t = await n.fetch(l, {
32
43
  ...o,
33
44
  signal: i ?? o?.signal,
34
- headers: f
45
+ headers: m
35
46
  });
36
47
  } catch (e) {
37
- throw g(a, e), e instanceof Error ? R(e) : e;
48
+ throw T(a, e), e instanceof Error ? d(e) : e;
38
49
  }
39
50
  if (!t.ok) {
40
51
  a.status = t.status;
41
52
  const e = await t.text().catch(() => "");
42
- throw C(a, t, e), R(l(t, e));
53
+ throw S(a, t, e), d(w(t, e));
43
54
  }
44
- return T(a, t);
55
+ return $(a, t);
45
56
  }
46
57
  });
47
58
  }
48
- function S(n, r, c) {
59
+ function k(n, r, c) {
49
60
  return `/chat/threads/${encodeURIComponent(n)}/turns/${encodeURIComponent(r)}/stream?after=${c}`;
50
61
  }
51
62
  export {
52
- B as createChatTransport
63
+ I as createChatTransport
53
64
  };