@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.
- package/dist/client/api.es.js +65 -43
- package/dist/client/brandingUrl.es.js +22 -0
- 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 +1301 -229
- package/dist/index.es.js +45 -42
- package/dist/internal.d.ts +1202 -219
- package/dist/internal.es.js +39 -35
- 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
package/dist/internal.es.js
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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
|
-
|
|
19
|
+
c as BRANDING_URL_PREFIX,
|
|
20
|
+
s as composerScope,
|
|
19
21
|
o as createGentiqRuntime,
|
|
20
|
-
|
|
22
|
+
i as createHttpClient,
|
|
21
23
|
a as createLocalStorageAuthAdapter,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
2
|
-
import { resolveMessageId as
|
|
3
|
-
function
|
|
4
|
-
const t =
|
|
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((
|
|
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:
|
|
10
|
+
parentMessageId: o ? f(o) : null,
|
|
11
11
|
message: {
|
|
12
12
|
id: t.id,
|
|
13
13
|
role: "user",
|
|
14
|
-
parts: t.parts.flatMap(
|
|
15
|
-
...
|
|
14
|
+
parts: t.parts.flatMap(y),
|
|
15
|
+
...c ? { metadata: c } : {}
|
|
16
16
|
},
|
|
17
|
-
...
|
|
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
|
|
21
|
-
toolOutputs:
|
|
22
|
-
options: t
|
|
22
|
+
function x(e, r, {
|
|
23
|
+
toolOutputs: n = [],
|
|
24
|
+
options: t,
|
|
25
|
+
mode: s,
|
|
26
|
+
capabilities: a
|
|
23
27
|
} = {}) {
|
|
24
|
-
const
|
|
25
|
-
(
|
|
28
|
+
const i = r.parts.flatMap(
|
|
29
|
+
(o) => u(o) && o.state === "approval-responded" ? [
|
|
26
30
|
{
|
|
27
|
-
id:
|
|
28
|
-
approved:
|
|
29
|
-
...
|
|
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:
|
|
36
|
-
...
|
|
37
|
-
...
|
|
38
|
-
toolOutputs:
|
|
39
|
-
id:
|
|
40
|
-
output:
|
|
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
|
|
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 [
|
|
62
|
+
return [v(e)];
|
|
54
63
|
default:
|
|
55
64
|
return [];
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
|
-
function
|
|
59
|
-
const { mediaType:
|
|
60
|
-
return { type: "file", mediaType:
|
|
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
|
|
71
|
+
function g(e) {
|
|
63
72
|
if (typeof e != "object" || e === null) return;
|
|
64
|
-
const { references:
|
|
65
|
-
...Array.isArray(
|
|
66
|
-
...Array.isArray(
|
|
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
|
|
79
|
+
function l(e) {
|
|
71
80
|
if (typeof e != "object" || e === null) return !1;
|
|
72
|
-
const { id:
|
|
73
|
-
return [
|
|
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
|
-
|
|
77
|
-
|
|
85
|
+
x as answersRequestBody,
|
|
86
|
+
b as chatRequestBody
|
|
78
87
|
};
|
|
@@ -1,53 +1,64 @@
|
|
|
1
|
-
import { DefaultChatTransport as
|
|
2
|
-
import { errorFromResponse as
|
|
3
|
-
import { answersRequestBody as
|
|
4
|
-
import { startTrace as
|
|
5
|
-
function
|
|
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
|
|
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" ?
|
|
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 ?
|
|
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
|
|
28
|
-
c.trace = a,
|
|
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(
|
|
42
|
+
t = await n.fetch(l, {
|
|
32
43
|
...o,
|
|
33
44
|
signal: i ?? o?.signal,
|
|
34
|
-
headers:
|
|
45
|
+
headers: m
|
|
35
46
|
});
|
|
36
47
|
} catch (e) {
|
|
37
|
-
throw
|
|
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
|
|
53
|
+
throw S(a, t, e), d(w(t, e));
|
|
43
54
|
}
|
|
44
|
-
return
|
|
55
|
+
return $(a, t);
|
|
45
56
|
}
|
|
46
57
|
});
|
|
47
58
|
}
|
|
48
|
-
function
|
|
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
|
-
|
|
63
|
+
I as createChatTransport
|
|
53
64
|
};
|