@gentiq/core 1.0.0-alpha.9 → 1.0.0-beta.2
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 -57
- package/dist/client/brandingUrl.es.js +22 -0
- 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 +3225 -512
- package/dist/index.es.js +44 -33
- package/dist/internal.d.ts +3094 -569
- package/dist/internal.es.js +40 -42
- 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/client/api.es.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { resolveAuthAdapter as m, createLocalStorageAuthAdapter as
|
|
2
|
-
import { createComposerDrafts as
|
|
3
|
-
import { createComposerFiles as
|
|
4
|
-
import { createChatRuntime as
|
|
5
|
-
import { createHttpClient as
|
|
1
|
+
import { resolveAuthAdapter as m, createLocalStorageAuthAdapter as p } from "./auth.es.js";
|
|
2
|
+
import { createComposerDrafts as _ } from "../composer/composerDrafts.es.js";
|
|
3
|
+
import { createComposerFiles as q } from "../composer/composerFiles.es.js";
|
|
4
|
+
import { createChatRuntime as g } from "../thread/chatRuntime.es.js";
|
|
5
|
+
import { createHttpClient as b, errorFromResponse as y } from "./http.es.js";
|
|
6
6
|
const h = 3e4;
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
t.authAdapter ??
|
|
10
|
-
),
|
|
7
|
+
function f(t = {}, a = {}) {
|
|
8
|
+
const c = m(
|
|
9
|
+
t.authAdapter ?? p(t.cacheNamespace ?? "gentiq")
|
|
10
|
+
), d = b({
|
|
11
11
|
basePath: t.basePath ?? "/api",
|
|
12
12
|
fetch: t.fetch,
|
|
13
13
|
timeout: t.timeout ?? h,
|
|
14
|
-
getHeaders:
|
|
15
|
-
credentials:
|
|
16
|
-
}),
|
|
17
|
-
http:
|
|
18
|
-
resolveAttachment: (
|
|
19
|
-
throttleMs:
|
|
20
|
-
getRunOptions:
|
|
14
|
+
getHeaders: c.getHeaders,
|
|
15
|
+
credentials: c.credentials
|
|
16
|
+
}), n = T(d, c, t), e = q((s, u) => n.uploadAttachment(s, u)), r = g({
|
|
17
|
+
http: d,
|
|
18
|
+
resolveAttachment: (s) => n.getAttachmentBlobUrl(s),
|
|
19
|
+
throttleMs: a.throttleMs,
|
|
20
|
+
getRunOptions: a.getRunOptions
|
|
21
21
|
});
|
|
22
|
-
return { api:
|
|
22
|
+
return { api: n, http: d, auth: c, options: t, composerFiles: e, composerDrafts: _(), chat: r };
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
return
|
|
24
|
+
function S(t) {
|
|
25
|
+
return f(t).api;
|
|
26
26
|
}
|
|
27
27
|
const o = (t) => t.replace(/^\//, "");
|
|
28
|
-
function T(t,
|
|
29
|
-
const
|
|
30
|
-
async function
|
|
28
|
+
function T(t, a, c) {
|
|
29
|
+
const d = c.timeout ?? h;
|
|
30
|
+
async function n(e) {
|
|
31
31
|
return URL.createObjectURL(await e.blob());
|
|
32
32
|
}
|
|
33
33
|
return {
|
|
@@ -44,29 +44,29 @@ function T(t, s, n) {
|
|
|
44
44
|
const e = await t.fetch("/auth/logout", { method: "POST" });
|
|
45
45
|
if (!e.ok && e.status !== 401)
|
|
46
46
|
throw y(e, await e.text().catch(() => ""));
|
|
47
|
-
|
|
47
|
+
a.clearToken();
|
|
48
48
|
},
|
|
49
49
|
/**
|
|
50
50
|
* Sign in. `identifier` is matched against every enabled login field on the backend (the
|
|
51
51
|
* combined "email or username" box).
|
|
52
52
|
*/
|
|
53
|
-
login: async (e,
|
|
54
|
-
const
|
|
55
|
-
body: { login: e, password:
|
|
53
|
+
login: async (e, r) => {
|
|
54
|
+
const s = await t.request("post", "/public/auth/login", {
|
|
55
|
+
body: { login: e, password: r },
|
|
56
56
|
auth: !1
|
|
57
57
|
});
|
|
58
|
-
return
|
|
58
|
+
return a.setToken(s.token), s;
|
|
59
59
|
},
|
|
60
60
|
/**
|
|
61
61
|
* Create an account and sign in. `values` maps each enabled login field to the value the
|
|
62
62
|
* user gave for it; the backend requires at least one.
|
|
63
63
|
*/
|
|
64
|
-
register: async (e,
|
|
64
|
+
register: async (e, r, s, u, l) => {
|
|
65
65
|
const i = await t.request("post", "/public/auth/register", {
|
|
66
|
-
body: { ...e, password:
|
|
66
|
+
body: { ...e, password: r, name: s, surname: u, metadata: l },
|
|
67
67
|
auth: !1
|
|
68
68
|
});
|
|
69
|
-
return
|
|
69
|
+
return a.setToken(i.token), i;
|
|
70
70
|
},
|
|
71
71
|
/** The signed-in user's access: their plan and its usage windows, or their credits. */
|
|
72
72
|
getEntitlement: (e) => t.request("get", "/users/me/entitlement", { signal: e }),
|
|
@@ -79,9 +79,9 @@ function T(t, s, n) {
|
|
|
79
79
|
* then hands the held session back (`resumed`), so a page reloaded with a spent code keeps
|
|
80
80
|
* its user signed in rather than signing them out.
|
|
81
81
|
*/
|
|
82
|
-
exchangeLoginCode: async (e,
|
|
83
|
-
const
|
|
84
|
-
return
|
|
82
|
+
exchangeLoginCode: async (e, r) => {
|
|
83
|
+
const s = await t.request("post", "/auth/exchange", { body: { code: e }, signal: r });
|
|
84
|
+
return s.token && a.setToken(s.token), s;
|
|
85
85
|
},
|
|
86
86
|
/**
|
|
87
87
|
* A page of the user's threads, pinned first and then by last activity; with `query`, only
|
|
@@ -90,27 +90,27 @@ function T(t, s, n) {
|
|
|
90
90
|
*/
|
|
91
91
|
getHistory: ({
|
|
92
92
|
cursor: e,
|
|
93
|
-
limit:
|
|
94
|
-
query:
|
|
95
|
-
} = {}) => t.request("get", "/chat/threads", { query: { cursor: e, limit:
|
|
93
|
+
limit: r = 50,
|
|
94
|
+
query: s
|
|
95
|
+
} = {}) => t.request("get", "/chat/threads", { query: { cursor: e, limit: r, q: s } }),
|
|
96
96
|
/**
|
|
97
97
|
* A page of a thread's messages, oldest first: its last `limit` (50 unless given), or with
|
|
98
98
|
* `before`, a page's `next_cursor`, the `limit` before that page.
|
|
99
99
|
*/
|
|
100
|
-
getThreadMessages: (e, { before:
|
|
100
|
+
getThreadMessages: (e, { before: r, limit: s } = {}) => t.request("get", "/chat/threads/{thread_id}", {
|
|
101
101
|
path: { thread_id: o(e) },
|
|
102
|
-
query: { before:
|
|
102
|
+
query: { before: r, limit: s }
|
|
103
103
|
}),
|
|
104
104
|
deleteThread: (e) => t.request("delete", "/chat/threads/{thread_id}", {
|
|
105
105
|
path: { thread_id: o(e) }
|
|
106
106
|
}),
|
|
107
|
-
updateThreadTitle: (e,
|
|
107
|
+
updateThreadTitle: (e, r) => t.request("patch", "/chat/threads/{thread_id}", {
|
|
108
108
|
path: { thread_id: o(e) },
|
|
109
|
-
body: { title:
|
|
109
|
+
body: { title: r }
|
|
110
110
|
}),
|
|
111
|
-
pinThread: (e,
|
|
111
|
+
pinThread: (e, r) => t.request("patch", "/chat/threads/{thread_id}", {
|
|
112
112
|
path: { thread_id: o(e) },
|
|
113
|
-
body: { pinned:
|
|
113
|
+
body: { pinned: r }
|
|
114
114
|
}),
|
|
115
115
|
shareThread: (e) => t.request("post", "/chat/threads/{thread_id}/share", {
|
|
116
116
|
path: { thread_id: o(e) }
|
|
@@ -129,28 +129,28 @@ function T(t, s, n) {
|
|
|
129
129
|
* Fetch an attachment and return a blob URL usable in `<img src>`. The caller revokes it
|
|
130
130
|
* with `URL.revokeObjectURL` when done.
|
|
131
131
|
*/
|
|
132
|
-
getAttachmentBlobUrl: async (e) =>
|
|
132
|
+
getAttachmentBlobUrl: async (e) => c.attachmentResolver ? c.attachmentResolver(e) : n(await t.send(`/chat/attachments/${e}`)),
|
|
133
133
|
/** Fetch an attachment of a shared snapshot and return a blob URL. */
|
|
134
|
-
getPublicAttachmentBlobUrl: async (e,
|
|
134
|
+
getPublicAttachmentBlobUrl: async (e, r) => n(
|
|
135
135
|
await t.send(
|
|
136
|
-
`/public/shared/${encodeURIComponent(e)}/attachments/${
|
|
136
|
+
`/public/shared/${encodeURIComponent(e)}/attachments/${r}`,
|
|
137
137
|
{
|
|
138
138
|
auth: !1
|
|
139
139
|
}
|
|
140
140
|
)
|
|
141
141
|
),
|
|
142
|
-
saveFeedback: (e,
|
|
143
|
-
body: { thread_id: o(e), message_id:
|
|
142
|
+
saveFeedback: (e, r, s) => t.request("post", "/chat/feedback", {
|
|
143
|
+
body: { thread_id: o(e), message_id: r, sentiment: s }
|
|
144
144
|
}),
|
|
145
145
|
/**
|
|
146
146
|
* Transcribe a recording of the user into text for the composer. The text is empty
|
|
147
147
|
* when no speech was heard. `id` names the transcription: a message sent with it in
|
|
148
148
|
* `metadata.voice_inputs` pays for it, and shows as dictated in the admin panel.
|
|
149
149
|
*/
|
|
150
|
-
transcribe: (e,
|
|
150
|
+
transcribe: (e, r) => t.request("post", "/chat/transcribe", {
|
|
151
151
|
blob: e.type ? e : new Blob([e], { type: "audio/webm" }),
|
|
152
|
-
signal:
|
|
153
|
-
timeout:
|
|
152
|
+
signal: r,
|
|
153
|
+
timeout: d * 4
|
|
154
154
|
}),
|
|
155
155
|
/**
|
|
156
156
|
* Upload a file for a message the user is about to send. A file part names the answer's `id`
|
|
@@ -158,26 +158,90 @@ function T(t, s, n) {
|
|
|
158
158
|
* refuses a type it doesn't accept (`unsupported_media_type`) and a file over its size limit
|
|
159
159
|
* (`request_too_large`); `getAppConfig()` lists both under `attachments`.
|
|
160
160
|
*/
|
|
161
|
-
uploadAttachment: async (e, { signal:
|
|
161
|
+
uploadAttachment: async (e, { signal: r, onProgress: s } = {}) => await (await t.upload(
|
|
162
162
|
`/chat/attachments?filename=${encodeURIComponent(e.name)}`,
|
|
163
163
|
e,
|
|
164
|
-
{ signal:
|
|
164
|
+
{ signal: r, onProgress: s }
|
|
165
165
|
)).json(),
|
|
166
166
|
/** @param signal Optional AbortSignal, so callers can cancel on unmount. */
|
|
167
167
|
getMe: (e) => t.request("get", "/users/me", { signal: e }),
|
|
168
168
|
updateMe: async (e) => {
|
|
169
|
-
const
|
|
170
|
-
return
|
|
169
|
+
const r = await t.request("patch", "/users/me", { body: e });
|
|
170
|
+
return r.token && a.setToken(r.token), r;
|
|
171
171
|
},
|
|
172
172
|
getAppConfig: (e) => t.request("get", "/config", { signal: e, auth: !1 }),
|
|
173
173
|
/** Whether the service is under maintenance. Public; polled by `useGentiqStatus`. */
|
|
174
174
|
getStatus: (e) => t.request("get", "/status", { signal: e, auth: !1 }),
|
|
175
175
|
/** Submit a bug report, feature request or general feedback from the signed-in user. */
|
|
176
|
-
submitUserReport: (e,
|
|
176
|
+
submitUserReport: (e, r) => t.request("post", "/users/me/reports", { body: e, signal: r }),
|
|
177
|
+
// --- Schedules ---
|
|
178
|
+
/** List all scheduled tasks belonging to the current user. */
|
|
179
|
+
listSchedules: (e) => t.request("get", "/schedules", { signal: e }),
|
|
180
|
+
/** Create a new scheduled task for the current user. */
|
|
181
|
+
createSchedule: (e) => t.request("post", "/schedules", { body: e }),
|
|
182
|
+
/** Fetch a single scheduled task by id. */
|
|
183
|
+
getSchedule: (e, r) => t.request("get", "/schedules/{schedule_id}", {
|
|
184
|
+
path: { schedule_id: e },
|
|
185
|
+
signal: r
|
|
186
|
+
}),
|
|
187
|
+
/** Update an existing scheduled task. */
|
|
188
|
+
updateSchedule: (e, r) => t.request("patch", "/schedules/{schedule_id}", {
|
|
189
|
+
path: { schedule_id: e },
|
|
190
|
+
body: r
|
|
191
|
+
}),
|
|
192
|
+
/** Delete a scheduled task and its run history. */
|
|
193
|
+
deleteSchedule: (e) => t.request("delete", "/schedules/{schedule_id}", { path: { schedule_id: e } }),
|
|
194
|
+
/** Pause an active scheduled task. */
|
|
195
|
+
pauseSchedule: (e) => t.request("post", "/schedules/{schedule_id}/pause", { path: { schedule_id: e } }),
|
|
196
|
+
/** Resume a paused scheduled task. */
|
|
197
|
+
resumeSchedule: (e) => t.request("post", "/schedules/{schedule_id}/resume", {
|
|
198
|
+
path: { schedule_id: e }
|
|
199
|
+
}),
|
|
200
|
+
/** Trigger an immediate run of a scheduled task. */
|
|
201
|
+
runScheduleNow: (e) => t.request("post", "/schedules/{schedule_id}/run", { path: { schedule_id: e } }),
|
|
202
|
+
/** List recent runs for a scheduled task. */
|
|
203
|
+
listScheduleRuns: (e, r = 20, s) => t.request("get", "/schedules/{schedule_id}/runs", {
|
|
204
|
+
path: { schedule_id: e },
|
|
205
|
+
query: { limit: r },
|
|
206
|
+
signal: s
|
|
207
|
+
}),
|
|
208
|
+
// --- Connectors ---
|
|
209
|
+
/** List external connectors available to the current user. */
|
|
210
|
+
listConnectors: (e) => t.request("get", "/connectors", { signal: e }),
|
|
211
|
+
/** Store an API key for a connector. */
|
|
212
|
+
connectConnector: (e, r) => t.request("post", "/connectors/{connector_id}/connect", {
|
|
213
|
+
path: { connector_id: e },
|
|
214
|
+
body: r
|
|
215
|
+
}),
|
|
216
|
+
/** Start an OAuth2 authorization flow for a connector. */
|
|
217
|
+
startConnectorOAuth: (e, r = "/") => t.request("post", "/connectors/{connector_id}/oauth/start", {
|
|
218
|
+
path: { connector_id: e },
|
|
219
|
+
body: { return_path: r }
|
|
220
|
+
}),
|
|
221
|
+
/** Wipe credentials and disable a connector. */
|
|
222
|
+
disconnectConnector: (e) => t.request("post", "/connectors/{connector_id}/disconnect", {
|
|
223
|
+
path: { connector_id: e }
|
|
224
|
+
}),
|
|
225
|
+
/** Enable/disable a connector or update per-tool approval overrides. */
|
|
226
|
+
updateConnector: (e, r) => t.request("patch", "/connectors/{connector_id}", {
|
|
227
|
+
path: { connector_id: e },
|
|
228
|
+
body: r
|
|
229
|
+
}),
|
|
230
|
+
/** List tools discovered from a connected connector. */
|
|
231
|
+
listConnectorTools: (e, r) => t.request("get", "/connectors/{connector_id}/tools", {
|
|
232
|
+
path: { connector_id: e },
|
|
233
|
+
signal: r
|
|
234
|
+
}),
|
|
235
|
+
/** Register a custom remote MCP server for the current user. */
|
|
236
|
+
createUserMCPConnector: (e) => t.request("post", "/connectors/user-mcp", { body: e }),
|
|
237
|
+
/** Delete a user-owned custom remote MCP server. */
|
|
238
|
+
deleteUserMCPConnector: (e) => t.request("delete", "/connectors/user-mcp/{connector_id}", {
|
|
239
|
+
path: { connector_id: e }
|
|
240
|
+
})
|
|
177
241
|
};
|
|
178
242
|
}
|
|
179
243
|
export {
|
|
180
244
|
h as DEFAULT_TIMEOUT_MS,
|
|
181
|
-
|
|
182
|
-
|
|
245
|
+
S as createGentiqApi,
|
|
246
|
+
f as createGentiqRuntime
|
|
183
247
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const n = "/api/public/branding/";
|
|
2
|
+
function s(e, t = "/api") {
|
|
3
|
+
return e.startsWith(n) ? `${t.replace(/\/+$/, "")}${e.slice(4)}` : e;
|
|
4
|
+
}
|
|
5
|
+
function o(e) {
|
|
6
|
+
const t = e.trim();
|
|
7
|
+
if (!t || t.length > 2048 || [...t].some((r) => /\s/.test(r) || r.charCodeAt(0) < 32))
|
|
8
|
+
return !1;
|
|
9
|
+
if (t.startsWith("/") && !t.startsWith("//"))
|
|
10
|
+
return !0;
|
|
11
|
+
try {
|
|
12
|
+
const r = new URL(t);
|
|
13
|
+
return (r.protocol === "http:" || r.protocol === "https:") && !!r.host;
|
|
14
|
+
} catch {
|
|
15
|
+
return !1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
n as BRANDING_URL_PREFIX,
|
|
20
|
+
o as isValidIconUrl,
|
|
21
|
+
s as resolveBrandingUrl
|
|
22
|
+
};
|
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { normalizeWhitespace as p } from "./references.es.js";
|
|
2
|
+
function x(t) {
|
|
3
|
+
return t ?? "";
|
|
3
4
|
}
|
|
4
|
-
const
|
|
5
|
-
function
|
|
5
|
+
const a = { text: "", references: [], voiceInputs: [] };
|
|
6
|
+
function u(t) {
|
|
6
7
|
return [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
].filter((
|
|
8
|
+
t.sourceId,
|
|
9
|
+
t.messageId,
|
|
10
|
+
t.partIndex,
|
|
11
|
+
t.kind,
|
|
12
|
+
p(t.excerpt)
|
|
13
|
+
].filter((c) => c !== void 0 && c !== "").join(":");
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
function
|
|
17
|
-
const n = o(e),
|
|
18
|
-
|
|
15
|
+
function I() {
|
|
16
|
+
const t = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set(), o = (e) => t.get(e) ?? a;
|
|
17
|
+
function i(e, r) {
|
|
18
|
+
const n = o(e), s = { ...n, ...r(n) };
|
|
19
|
+
s.text === "" && s.references.length === 0 && s.voiceInputs.length === 0 ? t.delete(e) : t.set(e, s), c.forEach((f) => f());
|
|
19
20
|
}
|
|
20
21
|
return {
|
|
21
22
|
get: o,
|
|
22
23
|
subscribe(e) {
|
|
23
|
-
return
|
|
24
|
-
|
|
24
|
+
return c.add(e), () => {
|
|
25
|
+
c.delete(e);
|
|
25
26
|
};
|
|
26
27
|
},
|
|
27
|
-
setText: (e,
|
|
28
|
-
o(e).text !==
|
|
28
|
+
setText: (e, r) => {
|
|
29
|
+
o(e).text !== r && i(e, () => ({ text: r }));
|
|
29
30
|
},
|
|
30
|
-
addReference: (e,
|
|
31
|
-
const
|
|
32
|
-
return { references: [
|
|
31
|
+
addReference: (e, r, n) => i(e, ({ references: s }) => {
|
|
32
|
+
const f = u(r), d = s.filter((l) => u(l) !== f);
|
|
33
|
+
return { references: [r, ...d].slice(0, n) };
|
|
33
34
|
}),
|
|
34
|
-
removeReference: (e,
|
|
35
|
-
references: n.filter((
|
|
35
|
+
removeReference: (e, r) => i(e, ({ references: n }) => ({
|
|
36
|
+
references: n.filter((s) => s.id !== r)
|
|
36
37
|
})),
|
|
37
38
|
clearReferences: (e) => {
|
|
38
|
-
o(e).references.length > 0 &&
|
|
39
|
+
o(e).references.length > 0 && i(e, () => ({ references: [] }));
|
|
39
40
|
},
|
|
40
|
-
addVoiceInput: (e,
|
|
41
|
+
addVoiceInput: (e, r) => i(e, ({ voiceInputs: n }) => ({ voiceInputs: [...n, r] })),
|
|
41
42
|
take: (e) => {
|
|
42
|
-
const
|
|
43
|
-
return
|
|
43
|
+
const r = o(e);
|
|
44
|
+
return r !== a && (t.delete(e), c.forEach((n) => n())), r;
|
|
45
|
+
},
|
|
46
|
+
clear() {
|
|
47
|
+
t.size !== 0 && (t.clear(), c.forEach((e) => e()));
|
|
44
48
|
}
|
|
45
49
|
};
|
|
46
50
|
}
|
|
47
51
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
x as composerScope,
|
|
53
|
+
I as createComposerDrafts,
|
|
54
|
+
u as referenceSourceKey
|
|
51
55
|
};
|
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
import { isClientError as y } from "../errors.es.js";
|
|
2
|
-
const
|
|
3
|
-
function m(
|
|
4
|
-
const
|
|
2
|
+
const i = [];
|
|
3
|
+
function m(g) {
|
|
4
|
+
const n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set();
|
|
5
5
|
let k = 0;
|
|
6
|
-
const
|
|
7
|
-
function f(e, t,
|
|
8
|
-
const r =
|
|
9
|
-
r?.some((l) => l.key === t) && (
|
|
6
|
+
const a = () => u.forEach((e) => e());
|
|
7
|
+
function f(e, t, s) {
|
|
8
|
+
const r = n.get(e);
|
|
9
|
+
r?.some((l) => l.key === t) && (n.set(
|
|
10
10
|
e,
|
|
11
|
-
r.map((l) => l.key === t ? { ...l, ...
|
|
12
|
-
),
|
|
11
|
+
r.map((l) => l.key === t ? { ...l, ...s } : l)
|
|
12
|
+
), a());
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
o.set(t.key,
|
|
17
|
-
signal:
|
|
14
|
+
function c(e, t) {
|
|
15
|
+
const s = new AbortController();
|
|
16
|
+
o.set(t.key, s), g(t.file, {
|
|
17
|
+
signal: s.signal,
|
|
18
18
|
onProgress: (r) => f(e, t.key, { progress: r })
|
|
19
19
|
}).then(
|
|
20
20
|
(r) => {
|
|
21
21
|
o.delete(t.key), f(e, t.key, { status: "uploaded", progress: 1, attachment: r });
|
|
22
22
|
},
|
|
23
23
|
(r) => {
|
|
24
|
-
o.delete(t.key), !
|
|
24
|
+
o.delete(t.key), !s.signal.aborted && f(e, t.key, { status: "failed", error: r, retryable: !y(r) });
|
|
25
25
|
}
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function d(e) {
|
|
29
29
|
for (const t of e)
|
|
30
30
|
o.get(t.key)?.abort(), o.delete(t.key);
|
|
31
31
|
}
|
|
32
32
|
return {
|
|
33
|
-
get: (e) =>
|
|
33
|
+
get: (e) => n.get(e) ?? i,
|
|
34
34
|
subscribe(e) {
|
|
35
|
-
return
|
|
36
|
-
|
|
35
|
+
return u.add(e), () => {
|
|
36
|
+
u.delete(e);
|
|
37
37
|
};
|
|
38
38
|
},
|
|
39
39
|
add(e, t) {
|
|
40
40
|
if (t.length === 0) return;
|
|
41
|
-
const
|
|
41
|
+
const s = t.map(
|
|
42
42
|
(r) => ({
|
|
43
43
|
key: `file-${k++}`,
|
|
44
44
|
file: r,
|
|
@@ -47,30 +47,34 @@ function m(c) {
|
|
|
47
47
|
retryable: !1
|
|
48
48
|
})
|
|
49
49
|
);
|
|
50
|
-
|
|
50
|
+
n.set(e, [...n.get(e) ?? i, ...s]), a(), s.forEach((r) => c(e, r));
|
|
51
51
|
},
|
|
52
52
|
remove(e, t) {
|
|
53
|
-
const
|
|
54
|
-
|
|
53
|
+
const s = n.get(e) ?? i;
|
|
54
|
+
d(s.filter((r) => r.key === t)), n.set(
|
|
55
55
|
e,
|
|
56
|
-
|
|
57
|
-
),
|
|
56
|
+
s.filter((r) => r.key !== t)
|
|
57
|
+
), a();
|
|
58
58
|
},
|
|
59
59
|
retry(e, t) {
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
60
|
+
const s = n.get(e)?.find((l) => l.key === t);
|
|
61
|
+
if (!s || s.status !== "failed") return;
|
|
62
62
|
const r = {
|
|
63
|
-
key:
|
|
64
|
-
file:
|
|
63
|
+
key: s.key,
|
|
64
|
+
file: s.file,
|
|
65
65
|
status: "uploading",
|
|
66
66
|
progress: null,
|
|
67
67
|
retryable: !1
|
|
68
68
|
};
|
|
69
|
-
f(e, t, { ...r, error: void 0, attachment: void 0 }),
|
|
69
|
+
f(e, t, { ...r, error: void 0, attachment: void 0 }), c(e, r);
|
|
70
70
|
},
|
|
71
71
|
take(e) {
|
|
72
|
-
const t =
|
|
73
|
-
return t.length === 0 ?
|
|
72
|
+
const t = n.get(e) ?? i;
|
|
73
|
+
return t.length === 0 ? i : (d(t), n.delete(e), a(), t);
|
|
74
|
+
},
|
|
75
|
+
clear() {
|
|
76
|
+
for (const e of n.values()) d(e);
|
|
77
|
+
n.size === 0 && o.size === 0 || (n.clear(), a());
|
|
74
78
|
}
|
|
75
79
|
};
|
|
76
80
|
}
|
package/dist/errors.es.js
CHANGED
|
@@ -53,6 +53,21 @@ const n = {
|
|
|
53
53
|
ADMIN_NOT_FOUND: "admin_not_found",
|
|
54
54
|
CANNOT_DELETE_SELF: "cannot_delete_self",
|
|
55
55
|
ADMIN_UPDATE_FAILED: "admin_update_failed",
|
|
56
|
+
JOB_NOT_FOUND: "job_not_found",
|
|
57
|
+
RAW_JOBS_DISABLED: "raw_jobs_disabled",
|
|
58
|
+
// Schedules
|
|
59
|
+
SCHEDULE_NOT_FOUND: "schedule_not_found",
|
|
60
|
+
SCHEDULE_LIMIT_REACHED: "schedule_limit_reached",
|
|
61
|
+
INVALID_SCHEDULE: "invalid_schedule",
|
|
62
|
+
// Connectors
|
|
63
|
+
CONNECTOR_NOT_FOUND: "connector_not_found",
|
|
64
|
+
CONNECTOR_ALREADY_EXISTS: "connector_already_exists",
|
|
65
|
+
CONNECTOR_READ_ONLY: "connector_read_only",
|
|
66
|
+
CONNECTOR_AUTH_FAILED: "connector_auth_failed",
|
|
67
|
+
CONNECTOR_UNREACHABLE: "connector_unreachable",
|
|
68
|
+
CONNECTOR_OAUTH_INVALID_STATE: "connector_oauth_invalid_state",
|
|
69
|
+
CONNECTOR_URL_BLOCKED: "connector_url_blocked",
|
|
70
|
+
USER_MCP_DISABLED: "user_mcp_disabled",
|
|
56
71
|
// System Errors
|
|
57
72
|
INTERNAL_ERROR: "internal_error",
|
|
58
73
|
VALIDATION_ERROR: "validation_error",
|
|
@@ -64,8 +79,11 @@ const n = {
|
|
|
64
79
|
TIMEOUT: "timeout"
|
|
65
80
|
};
|
|
66
81
|
class t extends Error {
|
|
82
|
+
/** Machine-readable error code returned by the backend (or `'timeout'`). */
|
|
67
83
|
code;
|
|
84
|
+
/** HTTP status code when the error came from a server response. */
|
|
68
85
|
status;
|
|
86
|
+
/** Optional structured error metadata returned by the backend. */
|
|
69
87
|
details;
|
|
70
88
|
constructor(_, E) {
|
|
71
89
|
super(_.error.message), this.name = "GentiqError", this.code = _.error.code, this.status = E, this.details = _.error.details;
|
|
@@ -74,13 +92,13 @@ class t extends Error {
|
|
|
74
92
|
function r(e) {
|
|
75
93
|
return e instanceof t;
|
|
76
94
|
}
|
|
77
|
-
function
|
|
95
|
+
function d(e) {
|
|
78
96
|
const _ = e?.status;
|
|
79
97
|
return typeof _ == "number" && _ >= 400 && _ < 500 && _ !== 408 && _ !== 429;
|
|
80
98
|
}
|
|
81
99
|
export {
|
|
82
100
|
t as GentiqError,
|
|
83
101
|
n as GentiqErrorCode,
|
|
84
|
-
|
|
102
|
+
d as isClientError,
|
|
85
103
|
r as isGentiqError
|
|
86
104
|
};
|