@arbidocs/sdk 0.3.11 → 0.3.14
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/browser-DtwXhEkG.d.cts +3230 -0
- package/dist/browser-DtwXhEkG.d.ts +3230 -0
- package/dist/browser.cjs +232 -26
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +229 -22
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +445 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -2973
- package/dist/index.d.ts +40 -2973
- package/dist/index.js +439 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/browser.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AgentStepEvent, Arbi, ArbiApiError, ArbiError, ArbiOptions, ArtifactEvent, AuthContext, AuthHeaders, AuthenticatedClient, ChatSession, CliConfig, CliCredentials, ConfigStore, ConnectOptions, MessageMetadataPayload, OutputTokensDetails, QueryOptions, ReconnectOptions, ReconnectableWsConnection, ResponseCompletedEvent, ResponseContentPartAddedEvent, ResponseCreatedEvent, ResponseFailedEvent, ResponseOutputItemAddedEvent, ResponseOutputItemDoneEvent, ResponseOutputTextDeltaEvent, ResponseOutputTextDoneEvent, ResponseUsage, SSEEvent, SSEStreamCallbacks, SSEStreamResult, SSEStreamStartData, UserInfo, UserInputRequestEvent, UserMessageEvent, WorkspaceContext, WsConnection, agentconfig, assistant, authenticatedFetch, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts, conversations, createAuthenticatedClient, dm, doctags, documents, files, formatFileSize, formatUserName, formatWorkspaceChoices, getErrorMessage, health, parseSSEEvents, performPasswordLogin, requireData, requireOk, resolveAuth, resolveWorkspace, selectWorkspace, selectWorkspaceById, settings, streamSSE, tags, workspaces } from './
|
|
1
|
+
export { f as AgentStepEvent, g as Arbi, h as ArbiApiError, i as ArbiError, j as ArbiOptions, k as ArtifactEvent, l as AuthContext, A as AuthHeaders, m as AuthenticatedClient, c as ChatSession, a as CliConfig, b as CliCredentials, C as ConfigStore, n as ConnectOptions, L as LIFECYCLE_LABELS, p as MessageMetadataPayload, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, q as ReconnectableWsConnection, r as ResponseCompletedEvent, s as ResponseContentPartAddedEvent, t as ResponseCreatedEvent, u as ResponseFailedEvent, v as ResponseOutputItemAddedEvent, w as ResponseOutputItemDoneEvent, x as ResponseOutputTextDeltaEvent, y as ResponseOutputTextDoneEvent, z as ResponseUsage, S as SSEEvent, B as SSEStreamCallbacks, E as SSEStreamResult, G as SSEStreamStartData, T as TOOL_LABELS, H as UserInfo, I as UserInputRequestEvent, J as UserMessageEvent, W as WorkspaceContext, K as WsConnection, N as agentconfig, P as assistant, V as authenticatedFetch, X as buildRetrievalChunkTool, Y as buildRetrievalFullContextTool, Z as buildRetrievalTocTool, _ as connectWebSocket, $ as connectWithReconnect, a0 as consumeSSEStream, a1 as contacts, a2 as conversations, a3 as createAuthenticatedClient, a5 as dm, a6 as doctags, a7 as documents, a8 as files, a9 as formatAgentStepLabel, aa as formatFileSize, ab as formatUserName, ac as formatWorkspaceChoices, ag as getErrorMessage, ah as health, ai as parseSSEEvents, aj as performPasswordLogin, ak as requireData, al as requireOk, am as resolveAuth, an as resolveWorkspace, ao as responses, ap as selectWorkspace, aq as selectWorkspaceById, ar as settings, as as streamSSE, at as tags, au as workspaces } from './browser-DtwXhEkG.cjs';
|
|
2
2
|
import '@arbidocs/client';
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AgentStepEvent, Arbi, ArbiApiError, ArbiError, ArbiOptions, ArtifactEvent, AuthContext, AuthHeaders, AuthenticatedClient, ChatSession, CliConfig, CliCredentials, ConfigStore, ConnectOptions, MessageMetadataPayload, OutputTokensDetails, QueryOptions, ReconnectOptions, ReconnectableWsConnection, ResponseCompletedEvent, ResponseContentPartAddedEvent, ResponseCreatedEvent, ResponseFailedEvent, ResponseOutputItemAddedEvent, ResponseOutputItemDoneEvent, ResponseOutputTextDeltaEvent, ResponseOutputTextDoneEvent, ResponseUsage, SSEEvent, SSEStreamCallbacks, SSEStreamResult, SSEStreamStartData, UserInfo, UserInputRequestEvent, UserMessageEvent, WorkspaceContext, WsConnection, agentconfig, assistant, authenticatedFetch, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts, conversations, createAuthenticatedClient, dm, doctags, documents, files, formatFileSize, formatUserName, formatWorkspaceChoices, getErrorMessage, health, parseSSEEvents, performPasswordLogin, requireData, requireOk, resolveAuth, resolveWorkspace, selectWorkspace, selectWorkspaceById, settings, streamSSE, tags, workspaces } from './
|
|
1
|
+
export { f as AgentStepEvent, g as Arbi, h as ArbiApiError, i as ArbiError, j as ArbiOptions, k as ArtifactEvent, l as AuthContext, A as AuthHeaders, m as AuthenticatedClient, c as ChatSession, a as CliConfig, b as CliCredentials, C as ConfigStore, n as ConnectOptions, L as LIFECYCLE_LABELS, p as MessageMetadataPayload, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, q as ReconnectableWsConnection, r as ResponseCompletedEvent, s as ResponseContentPartAddedEvent, t as ResponseCreatedEvent, u as ResponseFailedEvent, v as ResponseOutputItemAddedEvent, w as ResponseOutputItemDoneEvent, x as ResponseOutputTextDeltaEvent, y as ResponseOutputTextDoneEvent, z as ResponseUsage, S as SSEEvent, B as SSEStreamCallbacks, E as SSEStreamResult, G as SSEStreamStartData, T as TOOL_LABELS, H as UserInfo, I as UserInputRequestEvent, J as UserMessageEvent, W as WorkspaceContext, K as WsConnection, N as agentconfig, P as assistant, V as authenticatedFetch, X as buildRetrievalChunkTool, Y as buildRetrievalFullContextTool, Z as buildRetrievalTocTool, _ as connectWebSocket, $ as connectWithReconnect, a0 as consumeSSEStream, a1 as contacts, a2 as conversations, a3 as createAuthenticatedClient, a5 as dm, a6 as doctags, a7 as documents, a8 as files, a9 as formatAgentStepLabel, aa as formatFileSize, ab as formatUserName, ac as formatWorkspaceChoices, ag as getErrorMessage, ah as health, ai as parseSSEEvents, aj as performPasswordLogin, ak as requireData, al as requireOk, am as resolveAuth, an as resolveWorkspace, ao as responses, ap as selectWorkspace, aq as selectWorkspaceById, ar as settings, as as streamSSE, at as tags, au as workspaces } from './browser-DtwXhEkG.js';
|
|
2
2
|
import '@arbidocs/client';
|
package/dist/browser.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { createArbiClient, base64ToBytes, deriveEncryptionKeypairFromSigning, sealedBoxDecrypt, createWorkspaceKeyHeader, buildWebSocketUrl, createAuthMessage, parseServerMessage, isMessageType } from '@arbidocs/client';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
2
|
|
|
5
3
|
var __defProp = Object.defineProperty;
|
|
6
4
|
var __export = (target, all) => {
|
|
@@ -35,7 +33,24 @@ function requireOk(result, message) {
|
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
function getErrorMessage(err) {
|
|
38
|
-
|
|
36
|
+
if (!(err instanceof Error)) return String(err);
|
|
37
|
+
const rootCause = getDeepestCause(err);
|
|
38
|
+
if (rootCause !== err) {
|
|
39
|
+
const rootMsg = rootCause.message || String(rootCause);
|
|
40
|
+
if (err.message && !err.message.includes(rootMsg)) {
|
|
41
|
+
return `${err.message}: ${rootMsg}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return err.message;
|
|
45
|
+
}
|
|
46
|
+
function getDeepestCause(err) {
|
|
47
|
+
let current = err;
|
|
48
|
+
const seen = /* @__PURE__ */ new Set();
|
|
49
|
+
while (current.cause instanceof Error && !seen.has(current.cause)) {
|
|
50
|
+
seen.add(current);
|
|
51
|
+
current = current.cause;
|
|
52
|
+
}
|
|
53
|
+
return current;
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
// src/fetch.ts
|
|
@@ -65,8 +80,8 @@ async function extractErrorMessage(res) {
|
|
|
65
80
|
return `Request failed: ${res.status} ${res.statusText}`;
|
|
66
81
|
}
|
|
67
82
|
async function authenticatedFetch(options) {
|
|
68
|
-
const { baseUrl, accessToken, workspaceKeyHeader, path
|
|
69
|
-
const res = await fetch(`${baseUrl}${
|
|
83
|
+
const { baseUrl, accessToken, workspaceKeyHeader, path, method, body, headers } = options;
|
|
84
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
70
85
|
method: method ?? (body ? "POST" : "GET"),
|
|
71
86
|
headers: {
|
|
72
87
|
Authorization: `Bearer ${accessToken}`,
|
|
@@ -105,7 +120,11 @@ async function createAuthenticatedClient(config, creds, store) {
|
|
|
105
120
|
});
|
|
106
121
|
store.saveCredentials({
|
|
107
122
|
...creds,
|
|
108
|
-
serverSessionKeyBase64: arbi.crypto.bytesToBase64(loginResult.serverSessionKey)
|
|
123
|
+
serverSessionKeyBase64: arbi.crypto.bytesToBase64(loginResult.serverSessionKey),
|
|
124
|
+
accessToken: void 0,
|
|
125
|
+
workspaceKeyHeader: void 0,
|
|
126
|
+
workspaceId: void 0,
|
|
127
|
+
tokenTimestamp: void 0
|
|
109
128
|
});
|
|
110
129
|
return { arbi, loginResult };
|
|
111
130
|
}
|
|
@@ -120,7 +139,12 @@ async function performPasswordLogin(config, email, password, store) {
|
|
|
120
139
|
store.saveCredentials({
|
|
121
140
|
email,
|
|
122
141
|
signingPrivateKeyBase64: arbi.crypto.bytesToBase64(loginResult.signingPrivateKey),
|
|
123
|
-
serverSessionKeyBase64: arbi.crypto.bytesToBase64(loginResult.serverSessionKey)
|
|
142
|
+
serverSessionKeyBase64: arbi.crypto.bytesToBase64(loginResult.serverSessionKey),
|
|
143
|
+
// Clear any cached workspace tokens — new session key invalidates them
|
|
144
|
+
accessToken: void 0,
|
|
145
|
+
workspaceKeyHeader: void 0,
|
|
146
|
+
workspaceId: void 0,
|
|
147
|
+
tokenTimestamp: void 0
|
|
124
148
|
});
|
|
125
149
|
return { arbi, loginResult, config };
|
|
126
150
|
}
|
|
@@ -173,6 +197,10 @@ async function resolveAuth(store) {
|
|
|
173
197
|
const { arbi, loginResult } = await createAuthenticatedClient(config, creds, store);
|
|
174
198
|
return { arbi, loginResult, config };
|
|
175
199
|
}
|
|
200
|
+
var TOKEN_MAX_AGE_MS = 50 * 60 * 1e3;
|
|
201
|
+
function isCachedTokenValid(creds, workspaceId) {
|
|
202
|
+
return !!(creds.accessToken && creds.workspaceKeyHeader && creds.workspaceId === workspaceId && creds.tokenTimestamp && Date.now() - new Date(creds.tokenTimestamp).getTime() < TOKEN_MAX_AGE_MS);
|
|
203
|
+
}
|
|
176
204
|
async function resolveWorkspace(store, workspaceOpt) {
|
|
177
205
|
const config = store.requireConfig();
|
|
178
206
|
const creds = store.requireCredentials();
|
|
@@ -180,6 +208,32 @@ async function resolveWorkspace(store, workspaceOpt) {
|
|
|
180
208
|
if (!workspaceId) {
|
|
181
209
|
throw new ArbiError("No workspace selected. Run: arbi workspace select <id>");
|
|
182
210
|
}
|
|
211
|
+
if (isCachedTokenValid(creds, workspaceId)) {
|
|
212
|
+
const arbi2 = createArbiClient({
|
|
213
|
+
baseUrl: config.baseUrl,
|
|
214
|
+
deploymentDomain: config.deploymentDomain,
|
|
215
|
+
credentials: "omit"
|
|
216
|
+
});
|
|
217
|
+
await arbi2.crypto.initSodium();
|
|
218
|
+
arbi2.session.setSelectedWorkspace(workspaceId);
|
|
219
|
+
arbi2.session.setAccessToken(creds.accessToken);
|
|
220
|
+
arbi2.session.setCachedWorkspaceHeader(workspaceId, creds.workspaceKeyHeader);
|
|
221
|
+
const signingPrivateKey = base64ToBytes(creds.signingPrivateKeyBase64);
|
|
222
|
+
const serverSessionKey = base64ToBytes(creds.serverSessionKeyBase64);
|
|
223
|
+
const loginResult2 = {
|
|
224
|
+
accessToken: creds.accessToken,
|
|
225
|
+
signingPrivateKey,
|
|
226
|
+
serverSessionKey
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
arbi: arbi2,
|
|
230
|
+
loginResult: loginResult2,
|
|
231
|
+
config,
|
|
232
|
+
workspaceId,
|
|
233
|
+
accessToken: creds.accessToken,
|
|
234
|
+
workspaceKeyHeader: creds.workspaceKeyHeader
|
|
235
|
+
};
|
|
236
|
+
}
|
|
183
237
|
const { arbi, loginResult } = await createAuthenticatedClient(config, creds, store);
|
|
184
238
|
await selectWorkspaceById(
|
|
185
239
|
arbi,
|
|
@@ -192,10 +246,57 @@ async function resolveWorkspace(store, workspaceOpt) {
|
|
|
192
246
|
if (!accessToken || !workspaceKeyHeader) {
|
|
193
247
|
throw new ArbiError("Authentication error \u2014 missing token or workspace key");
|
|
194
248
|
}
|
|
249
|
+
store.saveCredentials({
|
|
250
|
+
...store.requireCredentials(),
|
|
251
|
+
accessToken,
|
|
252
|
+
workspaceKeyHeader,
|
|
253
|
+
workspaceId,
|
|
254
|
+
tokenTimestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
255
|
+
});
|
|
195
256
|
return { arbi, loginResult, config, workspaceId, accessToken, workspaceKeyHeader };
|
|
196
257
|
}
|
|
197
258
|
|
|
198
259
|
// src/sse.ts
|
|
260
|
+
var TOOL_LABELS = {
|
|
261
|
+
search_documents: "Searching documents",
|
|
262
|
+
get_document_passages: "Reading document",
|
|
263
|
+
get_table_of_contents: "Getting table of contents",
|
|
264
|
+
view_document_pages: "Viewing document pages",
|
|
265
|
+
get_full_document: "Reading full document",
|
|
266
|
+
web_search: "Searching the web",
|
|
267
|
+
read_url: "Reading web pages",
|
|
268
|
+
ask_user: "Asking user",
|
|
269
|
+
compaction: "Compacting conversation",
|
|
270
|
+
personal_agent: "Running agent",
|
|
271
|
+
create_artifact: "Creating artifact",
|
|
272
|
+
create_plan: "Creating plan",
|
|
273
|
+
save_skill: "Saving skill",
|
|
274
|
+
run_code: "Running code"
|
|
275
|
+
};
|
|
276
|
+
var LIFECYCLE_LABELS = {
|
|
277
|
+
evaluation: "Evaluating results",
|
|
278
|
+
answering: "Writing answer",
|
|
279
|
+
reviewing: "Reviewing answer",
|
|
280
|
+
planning: "Planning",
|
|
281
|
+
tool_progress: "Working"
|
|
282
|
+
};
|
|
283
|
+
function formatAgentStepLabel(step) {
|
|
284
|
+
if (step.focus) return step.focus;
|
|
285
|
+
const detail = step.detail;
|
|
286
|
+
if (step.step === "tool_progress" && detail && detail.length > 0) {
|
|
287
|
+
const toolName = detail[0].tool;
|
|
288
|
+
const label = toolName && TOOL_LABELS[toolName] || LIFECYCLE_LABELS.tool_progress;
|
|
289
|
+
const message = detail[0].message;
|
|
290
|
+
return message ? `${label}: ${message}` : label;
|
|
291
|
+
}
|
|
292
|
+
if (step.step) {
|
|
293
|
+
return LIFECYCLE_LABELS[step.step] || step.step;
|
|
294
|
+
}
|
|
295
|
+
if (detail && detail.length > 0 && detail[0].tool) {
|
|
296
|
+
return TOOL_LABELS[detail[0].tool] || detail[0].tool;
|
|
297
|
+
}
|
|
298
|
+
return "";
|
|
299
|
+
}
|
|
199
300
|
function parseSSEEvents(chunk, buffer) {
|
|
200
301
|
const combined = buffer + chunk;
|
|
201
302
|
const events = [];
|
|
@@ -223,11 +324,13 @@ async function streamSSE(response, callbacks = {}) {
|
|
|
223
324
|
let text = "";
|
|
224
325
|
let assistantMessageExtId = null;
|
|
225
326
|
const agentSteps = [];
|
|
327
|
+
let toolCallCount = 0;
|
|
226
328
|
const errors = [];
|
|
227
329
|
const artifacts = [];
|
|
228
330
|
let userMessage = null;
|
|
229
331
|
let metadata = null;
|
|
230
332
|
let usage = null;
|
|
333
|
+
let context = null;
|
|
231
334
|
const eventHandlers = {
|
|
232
335
|
// OpenAI Responses API events (dot-separated names from server)
|
|
233
336
|
"response.created": (raw) => {
|
|
@@ -271,6 +374,9 @@ async function streamSSE(response, callbacks = {}) {
|
|
|
271
374
|
metadata = meta;
|
|
272
375
|
callbacks.onMetadata?.(meta);
|
|
273
376
|
}
|
|
377
|
+
if (data.context) {
|
|
378
|
+
context = data.context;
|
|
379
|
+
}
|
|
274
380
|
if (data.t != null) callbacks.onElapsedTime?.(data.t);
|
|
275
381
|
callbacks.onComplete?.();
|
|
276
382
|
},
|
|
@@ -283,8 +389,12 @@ async function streamSSE(response, callbacks = {}) {
|
|
|
283
389
|
// ARBI-specific events (dot-prefixed from server)
|
|
284
390
|
"arbi.agent_step": (raw) => {
|
|
285
391
|
const data = JSON.parse(raw);
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
392
|
+
const label = formatAgentStepLabel(data);
|
|
393
|
+
if (label) agentSteps.push(label);
|
|
394
|
+
const detail = data.detail;
|
|
395
|
+
if (detail && Array.isArray(detail)) {
|
|
396
|
+
toolCallCount += detail.filter((d) => d.tool).length;
|
|
397
|
+
}
|
|
288
398
|
callbacks.onAgentStep?.(data);
|
|
289
399
|
if (data.t != null) callbacks.onElapsedTime?.(data.t);
|
|
290
400
|
},
|
|
@@ -335,11 +445,13 @@ async function streamSSE(response, callbacks = {}) {
|
|
|
335
445
|
text,
|
|
336
446
|
assistantMessageExtId,
|
|
337
447
|
agentSteps,
|
|
448
|
+
toolCallCount,
|
|
338
449
|
errors,
|
|
339
450
|
userMessage,
|
|
340
451
|
metadata,
|
|
341
452
|
artifacts,
|
|
342
|
-
usage
|
|
453
|
+
usage,
|
|
454
|
+
context
|
|
343
455
|
};
|
|
344
456
|
}
|
|
345
457
|
var consumeSSEStream = streamSSE;
|
|
@@ -463,16 +575,34 @@ function formatUserName(user) {
|
|
|
463
575
|
// src/operations/documents.ts
|
|
464
576
|
var documents_exports = {};
|
|
465
577
|
__export(documents_exports, {
|
|
578
|
+
SUPPORTED_EXTENSIONS: () => SUPPORTED_EXTENSIONS,
|
|
466
579
|
deleteDocuments: () => deleteDocuments,
|
|
467
580
|
downloadDocument: () => downloadDocument,
|
|
468
581
|
getDocuments: () => getDocuments,
|
|
469
582
|
getParsedContent: () => getParsedContent,
|
|
470
583
|
listDocuments: () => listDocuments,
|
|
584
|
+
sanitizeFolderPath: () => sanitizeFolderPath,
|
|
471
585
|
updateDocuments: () => updateDocuments,
|
|
472
586
|
uploadFile: () => uploadFile,
|
|
473
|
-
|
|
587
|
+
uploadFiles: () => uploadFiles,
|
|
474
588
|
uploadUrl: () => uploadUrl
|
|
475
589
|
});
|
|
590
|
+
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
591
|
+
".pdf",
|
|
592
|
+
".txt",
|
|
593
|
+
".md",
|
|
594
|
+
".html",
|
|
595
|
+
".doc",
|
|
596
|
+
".docx",
|
|
597
|
+
".rtf",
|
|
598
|
+
".ppt",
|
|
599
|
+
".pptx",
|
|
600
|
+
".xls",
|
|
601
|
+
".xlsx"
|
|
602
|
+
]);
|
|
603
|
+
function sanitizeFolderPath(folderPath) {
|
|
604
|
+
return folderPath.replace(/[^a-zA-Z0-9_\-/]/g, "_").replace(/_{2,}/g, "_");
|
|
605
|
+
}
|
|
476
606
|
async function listDocuments(arbi) {
|
|
477
607
|
return requireData(await arbi.fetch.GET("/v1/document/list"), "Failed to fetch documents");
|
|
478
608
|
}
|
|
@@ -511,22 +641,31 @@ async function getParsedContent(auth, docId, stage) {
|
|
|
511
641
|
});
|
|
512
642
|
return res.json();
|
|
513
643
|
}
|
|
514
|
-
async function uploadFile(auth, workspaceId, fileData, fileName) {
|
|
644
|
+
async function uploadFile(auth, workspaceId, fileData, fileName, options) {
|
|
515
645
|
const formData = new FormData();
|
|
516
646
|
formData.append("files", fileData, fileName);
|
|
647
|
+
const params = new URLSearchParams({ workspace_ext_id: workspaceId });
|
|
648
|
+
if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
|
|
517
649
|
const res = await authenticatedFetch({
|
|
518
650
|
...auth,
|
|
519
|
-
path: `/v1/document/upload
|
|
651
|
+
path: `/v1/document/upload?${params.toString()}`,
|
|
520
652
|
method: "POST",
|
|
521
653
|
body: formData
|
|
522
654
|
});
|
|
523
655
|
return res.json();
|
|
524
656
|
}
|
|
525
|
-
async function
|
|
526
|
-
const
|
|
527
|
-
const
|
|
528
|
-
const
|
|
529
|
-
|
|
657
|
+
async function uploadFiles(auth, workspaceId, files, options) {
|
|
658
|
+
const formData = new FormData();
|
|
659
|
+
for (const f of files) formData.append("files", f.data, f.name);
|
|
660
|
+
const params = new URLSearchParams({ workspace_ext_id: workspaceId });
|
|
661
|
+
if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
|
|
662
|
+
const res = await authenticatedFetch({
|
|
663
|
+
...auth,
|
|
664
|
+
path: `/v1/document/upload?${params.toString()}`,
|
|
665
|
+
method: "POST",
|
|
666
|
+
body: formData
|
|
667
|
+
});
|
|
668
|
+
return res.json();
|
|
530
669
|
}
|
|
531
670
|
async function downloadDocument(auth, docId) {
|
|
532
671
|
return authenticatedFetch({
|
|
@@ -726,6 +865,8 @@ async function retrieve(options) {
|
|
|
726
865
|
input: query,
|
|
727
866
|
workspace_ext_id: workspaceId,
|
|
728
867
|
stream: false,
|
|
868
|
+
background: false,
|
|
869
|
+
store: true,
|
|
729
870
|
tools,
|
|
730
871
|
...model ? { model } : {}
|
|
731
872
|
};
|
|
@@ -741,6 +882,8 @@ async function queryAssistant(options) {
|
|
|
741
882
|
input: question,
|
|
742
883
|
workspace_ext_id: workspaceId,
|
|
743
884
|
stream: true,
|
|
885
|
+
background: false,
|
|
886
|
+
store: true,
|
|
744
887
|
tools: {
|
|
745
888
|
retrieval_chunk: buildRetrievalChunkTool(docIds),
|
|
746
889
|
retrieval_full_context: buildRetrievalFullContextTool([])
|
|
@@ -1200,11 +1343,12 @@ var Arbi = class {
|
|
|
1200
1343
|
workspaceId ?? this.requireWorkspace(),
|
|
1201
1344
|
shared
|
|
1202
1345
|
),
|
|
1203
|
-
uploadFile: (fileData, fileName,
|
|
1346
|
+
uploadFile: (fileData, fileName, options) => uploadFile(
|
|
1204
1347
|
this.getAuthHeaders(),
|
|
1205
|
-
workspaceId ?? this.requireWorkspace(),
|
|
1348
|
+
options?.workspaceId ?? this.requireWorkspace(),
|
|
1206
1349
|
fileData,
|
|
1207
|
-
fileName
|
|
1350
|
+
fileName,
|
|
1351
|
+
options?.folder ? { folder: options.folder } : void 0
|
|
1208
1352
|
),
|
|
1209
1353
|
download: (docId) => downloadDocument(this.getAuthHeaders(), docId),
|
|
1210
1354
|
getParsedContent: (docId, stage) => getParsedContent(this.getAuthHeaders(), docId, stage)
|
|
@@ -1346,6 +1490,69 @@ var Arbi = class {
|
|
|
1346
1490
|
}
|
|
1347
1491
|
};
|
|
1348
1492
|
|
|
1349
|
-
|
|
1493
|
+
// src/operations/responses.ts
|
|
1494
|
+
var responses_exports = {};
|
|
1495
|
+
__export(responses_exports, {
|
|
1496
|
+
extractResponseText: () => extractResponseText,
|
|
1497
|
+
getResponse: () => getResponse,
|
|
1498
|
+
submitBackgroundQuery: () => submitBackgroundQuery
|
|
1499
|
+
});
|
|
1500
|
+
async function submitBackgroundQuery(options) {
|
|
1501
|
+
const { workspaceId, question, docIds, previousResponseId, model, ...auth } = options;
|
|
1502
|
+
const tools = {};
|
|
1503
|
+
if (docIds.length > 0) {
|
|
1504
|
+
tools.retrieval_chunk = {
|
|
1505
|
+
name: "retrieval_chunk",
|
|
1506
|
+
description: "retrieval chunk",
|
|
1507
|
+
tool_args: { doc_ext_ids: docIds },
|
|
1508
|
+
tool_responses: {}
|
|
1509
|
+
};
|
|
1510
|
+
tools.retrieval_full_context = {
|
|
1511
|
+
name: "retrieval_full_context",
|
|
1512
|
+
description: "retrieval full context",
|
|
1513
|
+
tool_args: { doc_ext_ids: [] },
|
|
1514
|
+
tool_responses: {}
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
const body = {
|
|
1518
|
+
input: question,
|
|
1519
|
+
workspace_ext_id: workspaceId,
|
|
1520
|
+
stream: false,
|
|
1521
|
+
background: true,
|
|
1522
|
+
store: true,
|
|
1523
|
+
tools,
|
|
1524
|
+
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
1525
|
+
...model ? { model } : {}
|
|
1526
|
+
};
|
|
1527
|
+
const res = await authenticatedFetch({
|
|
1528
|
+
...auth,
|
|
1529
|
+
path: "/v1/responses",
|
|
1530
|
+
method: "POST",
|
|
1531
|
+
body: JSON.stringify(body),
|
|
1532
|
+
headers: { "Content-Type": "application/json" }
|
|
1533
|
+
});
|
|
1534
|
+
return await res.json();
|
|
1535
|
+
}
|
|
1536
|
+
async function getResponse(auth, responseId) {
|
|
1537
|
+
const res = await authenticatedFetch({
|
|
1538
|
+
...auth,
|
|
1539
|
+
path: `/v1/responses/${responseId}`,
|
|
1540
|
+
method: "GET"
|
|
1541
|
+
});
|
|
1542
|
+
return await res.json();
|
|
1543
|
+
}
|
|
1544
|
+
function extractResponseText(response) {
|
|
1545
|
+
const parts = [];
|
|
1546
|
+
for (const msg of response.output) {
|
|
1547
|
+
for (const item of msg.content) {
|
|
1548
|
+
if ("type" in item && item.type === "output_text" && "text" in item) {
|
|
1549
|
+
parts.push(item.text);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
return parts.join("");
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
export { Arbi, ArbiApiError, ArbiError, LIFECYCLE_LABELS, TOOL_LABELS, agentconfig_exports as agentconfig, assistant_exports as assistant, authenticatedFetch, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts_exports as contacts, conversations_exports as conversations, createAuthenticatedClient, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, files_exports as files, formatAgentStepLabel, formatFileSize, formatUserName, formatWorkspaceChoices, getErrorMessage, health_exports as health, parseSSEEvents, performPasswordLogin, requireData, requireOk, resolveAuth, resolveWorkspace, responses_exports as responses, selectWorkspace, selectWorkspaceById, settings_exports as settings, streamSSE, tags_exports as tags, workspaces_exports as workspaces };
|
|
1350
1557
|
//# sourceMappingURL=browser.js.map
|
|
1351
1558
|
//# sourceMappingURL=browser.js.map
|