@arbidocs/sdk 0.4.2 → 0.4.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/{browser-U90kdb7T.d.cts → browser-4VHbRx1J.d.cts} +20 -1
- package/dist/{browser-U90kdb7T.d.ts → browser-4VHbRx1J.d.ts} +20 -1
- package/dist/browser.cjs +95 -20
- 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 +95 -20
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +96 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +96 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as AgentStepEvent, c as Arbi, d as ArbiApiError, e as ArbiError, g as ArbiOptions, h as
|
|
1
|
+
import { q as ConfigStore, n as CliConfig, o as CliCredentials, C as ChatSession, ac as SkippedFile, al as UploadResult, k as AuthHeaders, ah as UploadBatchResult, ak as UploadOptions, ai as UploadDirectOptions, aj as UploadDirectResult, aa as SUPPORTED_EXTENSIONS, w as DmCryptoContext } from './browser-4VHbRx1J.cjs';
|
|
2
|
+
export { b as AgentStepEvent, c as Arbi, d as ArbiApiError, e as ArbiError, g as ArbiOptions, h as ArbiSessionExpiredError, i as ArtifactEvent, j as AuthContext, l as AuthenticatedClient, m as CitationSummary, p as CommandDescriptor, r as ConnectOptions, D as DOC_TERMINAL_STATUSES, x as DocNameMap, y as DocumentListFields, z as DocumentListOrder, B as DocumentWaiter, E as DocumentWaiterOptions, I as FormattedWsMessage, L as ListAllOptions, K as ListPaginatedOptions, M as MessageLevel, N as MessageMetadataPayload, O as MessageQueuedEvent, P as OutputTokensDetails, Q as ParsedSlashCommand, S as ProjectInvoicesResponse, T as ProjectUsageResponse, U as QueryOptions, V as ReconnectOptions, W as ReconnectableWsConnection, X as ResolvedCitation, Y as ResolvedRecipient, Z as ResponseCompletedEvent, _ as ResponseContentPartAddedEvent, $ as ResponseCreatedEvent, a0 as ResponseFailedEvent, a1 as ResponseOutputItemAddedEvent, a2 as ResponseOutputItemDoneEvent, a3 as ResponseOutputTextDeltaEvent, a4 as ResponseOutputTextDoneEvent, a5 as ResponseUsage, a6 as SSEEvent, a7 as SSEStreamCallbacks, a8 as SSEStreamResult, a9 as SSEStreamStartData, ab as SkillSummary, ae as TokenBudgetContext, am as UserDailyUsageResponse, an as UserInfo, ao as UserInputRequestEvent, ap as UserMessageEvent, aq as WebSocketAuthError, ar as WorkspaceContext, as as WsConnection, at as agentconfig, au as assistant, av as authenticatedFetch, aw as buildDocNameMap, ax as buildRetrievalChunkTool, ay as buildRetrievalFullContextTool, az as buildRetrievalTocTool, aA as connectWebSocket, aB as connectWithReconnect, aC as consumeSSEStream, aD as contacts, aE as conversations, aF as countCitations, aG as createAuthenticatedClient, aH as createDocumentWaiter, aI as dm, aJ as doctags, aK as documents, aL as facts, aM as files, aN as filterSkills, aO as formatAgentStepLabel, aP as formatFileSize, aQ as formatItemLabel, aR as formatStreamSummary, aS as formatUserName, aT as formatWorkspaceChoices, aU as formatWsMessage, aV as generateEncryptedWorkspaceKey, aW as generateNewWorkspaceKey, aX as getErrorCode, aY as getErrorMessage, aZ as getRawWorkspaceKey, a_ as health, a$ as parseSSEEvents, b0 as parseSlashCommand, b1 as parseSlashTokenInProgress, b2 as performPasswordLogin, b3 as performSigningKeyLogin, b4 as performSsoDeviceFlowLogin, b5 as projects, b6 as requireData, b7 as requireOk, b8 as resolveAuth, b9 as resolveCitations, ba as resolveWorkspace, bb as responses, bc as selectWorkspace, bd as selectWorkspaceById, be as settings, bf as streamSSE, bg as stripCitationMarkdown, bh as summarizeCitations, bi as tags, bj as tasks, bk as workspaces } from './browser-4VHbRx1J.cjs';
|
|
3
3
|
import { SessionStorageProvider, ArbiClient, components } from '@arbidocs/client';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as AgentStepEvent, c as Arbi, d as ArbiApiError, e as ArbiError, g as ArbiOptions, h as
|
|
1
|
+
import { q as ConfigStore, n as CliConfig, o as CliCredentials, C as ChatSession, ac as SkippedFile, al as UploadResult, k as AuthHeaders, ah as UploadBatchResult, ak as UploadOptions, ai as UploadDirectOptions, aj as UploadDirectResult, aa as SUPPORTED_EXTENSIONS, w as DmCryptoContext } from './browser-4VHbRx1J.js';
|
|
2
|
+
export { b as AgentStepEvent, c as Arbi, d as ArbiApiError, e as ArbiError, g as ArbiOptions, h as ArbiSessionExpiredError, i as ArtifactEvent, j as AuthContext, l as AuthenticatedClient, m as CitationSummary, p as CommandDescriptor, r as ConnectOptions, D as DOC_TERMINAL_STATUSES, x as DocNameMap, y as DocumentListFields, z as DocumentListOrder, B as DocumentWaiter, E as DocumentWaiterOptions, I as FormattedWsMessage, L as ListAllOptions, K as ListPaginatedOptions, M as MessageLevel, N as MessageMetadataPayload, O as MessageQueuedEvent, P as OutputTokensDetails, Q as ParsedSlashCommand, S as ProjectInvoicesResponse, T as ProjectUsageResponse, U as QueryOptions, V as ReconnectOptions, W as ReconnectableWsConnection, X as ResolvedCitation, Y as ResolvedRecipient, Z as ResponseCompletedEvent, _ as ResponseContentPartAddedEvent, $ as ResponseCreatedEvent, a0 as ResponseFailedEvent, a1 as ResponseOutputItemAddedEvent, a2 as ResponseOutputItemDoneEvent, a3 as ResponseOutputTextDeltaEvent, a4 as ResponseOutputTextDoneEvent, a5 as ResponseUsage, a6 as SSEEvent, a7 as SSEStreamCallbacks, a8 as SSEStreamResult, a9 as SSEStreamStartData, ab as SkillSummary, ae as TokenBudgetContext, am as UserDailyUsageResponse, an as UserInfo, ao as UserInputRequestEvent, ap as UserMessageEvent, aq as WebSocketAuthError, ar as WorkspaceContext, as as WsConnection, at as agentconfig, au as assistant, av as authenticatedFetch, aw as buildDocNameMap, ax as buildRetrievalChunkTool, ay as buildRetrievalFullContextTool, az as buildRetrievalTocTool, aA as connectWebSocket, aB as connectWithReconnect, aC as consumeSSEStream, aD as contacts, aE as conversations, aF as countCitations, aG as createAuthenticatedClient, aH as createDocumentWaiter, aI as dm, aJ as doctags, aK as documents, aL as facts, aM as files, aN as filterSkills, aO as formatAgentStepLabel, aP as formatFileSize, aQ as formatItemLabel, aR as formatStreamSummary, aS as formatUserName, aT as formatWorkspaceChoices, aU as formatWsMessage, aV as generateEncryptedWorkspaceKey, aW as generateNewWorkspaceKey, aX as getErrorCode, aY as getErrorMessage, aZ as getRawWorkspaceKey, a_ as health, a$ as parseSSEEvents, b0 as parseSlashCommand, b1 as parseSlashTokenInProgress, b2 as performPasswordLogin, b3 as performSigningKeyLogin, b4 as performSsoDeviceFlowLogin, b5 as projects, b6 as requireData, b7 as requireOk, b8 as resolveAuth, b9 as resolveCitations, ba as resolveWorkspace, bb as responses, bc as selectWorkspace, bd as selectWorkspaceById, be as settings, bf as streamSSE, bg as stripCitationMarkdown, bh as summarizeCitations, bi as tags, bj as tasks, bk as workspaces } from './browser-4VHbRx1J.js';
|
|
3
3
|
import { SessionStorageProvider, ArbiClient, components } from '@arbidocs/client';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/index.js
CHANGED
|
@@ -3487,6 +3487,12 @@ var ArbiError = class extends Error {
|
|
|
3487
3487
|
this.name = "ArbiError";
|
|
3488
3488
|
}
|
|
3489
3489
|
};
|
|
3490
|
+
var ArbiSessionExpiredError = class extends ArbiError {
|
|
3491
|
+
constructor(message = "Your session expired. Sign in again.") {
|
|
3492
|
+
super(message);
|
|
3493
|
+
this.name = "ArbiSessionExpiredError";
|
|
3494
|
+
}
|
|
3495
|
+
};
|
|
3490
3496
|
var ArbiApiError = class extends ArbiError {
|
|
3491
3497
|
apiError;
|
|
3492
3498
|
constructor(message, apiError) {
|
|
@@ -6182,11 +6188,23 @@ async function remindFact(arbi, factId, options = {}) {
|
|
|
6182
6188
|
}
|
|
6183
6189
|
|
|
6184
6190
|
// src/arbi.ts
|
|
6191
|
+
function tokenExpiresWithin(token, seconds) {
|
|
6192
|
+
const payload = token?.split(".")[1];
|
|
6193
|
+
if (!payload) return false;
|
|
6194
|
+
try {
|
|
6195
|
+
const json = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
|
|
6196
|
+
const { exp } = JSON.parse(json);
|
|
6197
|
+
return typeof exp === "number" && exp * 1e3 - Date.now() < seconds * 1e3;
|
|
6198
|
+
} catch {
|
|
6199
|
+
return false;
|
|
6200
|
+
}
|
|
6201
|
+
}
|
|
6185
6202
|
var Arbi = class {
|
|
6186
6203
|
client = null;
|
|
6187
6204
|
loginResult = null;
|
|
6188
6205
|
currentWorkspaceId = null;
|
|
6189
6206
|
dmCryptoContext = null;
|
|
6207
|
+
sessionExpiredListeners = /* @__PURE__ */ new Set();
|
|
6190
6208
|
options;
|
|
6191
6209
|
constructor(options) {
|
|
6192
6210
|
this.options = options;
|
|
@@ -6199,7 +6217,13 @@ var Arbi = class {
|
|
|
6199
6217
|
this.client = createArbiClient({
|
|
6200
6218
|
baseUrl: this.options.url,
|
|
6201
6219
|
deploymentDomain: domain,
|
|
6202
|
-
credentials: this.options.credentials ?? "omit"
|
|
6220
|
+
credentials: this.options.credentials ?? "omit",
|
|
6221
|
+
// A silent re-login rotates the server session key: keep ours in step, or the next
|
|
6222
|
+
// workspace open would seal the key for a session the server no longer has.
|
|
6223
|
+
onReloginSuccess: ({ serverSessionKey }) => {
|
|
6224
|
+
if (this.loginResult) this.loginResult = { ...this.loginResult, serverSessionKey };
|
|
6225
|
+
},
|
|
6226
|
+
onSessionExpired: () => this.expireSession()
|
|
6203
6227
|
});
|
|
6204
6228
|
await this.client.crypto.initSodium();
|
|
6205
6229
|
return this.client;
|
|
@@ -6262,6 +6286,52 @@ var Arbi = class {
|
|
|
6262
6286
|
});
|
|
6263
6287
|
this.currentWorkspaceId = ws.external_id;
|
|
6264
6288
|
}
|
|
6289
|
+
/**
|
|
6290
|
+
* Subscribe to "the session cannot be recovered". Fires when a request failed with 401 or
|
|
6291
|
+
* "No active workspace" and neither a workspace re-open nor a silent re-login was possible
|
|
6292
|
+
* (the server refused; an unreachable server does not fire). The local session is already
|
|
6293
|
+
* cleared when it fires: show "Your session expired, sign in again". Returns an unsubscribe.
|
|
6294
|
+
*/
|
|
6295
|
+
onSessionExpired(listener) {
|
|
6296
|
+
this.sessionExpiredListeners.add(listener);
|
|
6297
|
+
return () => this.sessionExpiredListeners.delete(listener);
|
|
6298
|
+
}
|
|
6299
|
+
expireSession() {
|
|
6300
|
+
if (this.loginResult) {
|
|
6301
|
+
this.loginResult.signingPrivateKey.fill(0);
|
|
6302
|
+
this.loginResult.serverSessionKey.fill(0);
|
|
6303
|
+
}
|
|
6304
|
+
this.loginResult = null;
|
|
6305
|
+
this.currentWorkspaceId = null;
|
|
6306
|
+
this.dmCryptoContext = null;
|
|
6307
|
+
this.client?.session.clear();
|
|
6308
|
+
for (const listener of [...this.sessionExpiredListeners]) listener();
|
|
6309
|
+
}
|
|
6310
|
+
/**
|
|
6311
|
+
* Run a raw-fetch operation (streaming, multipart: no middleware) and, when it fails because
|
|
6312
|
+
* the token expired or the server lost the open workspace, recover once and run it again.
|
|
6313
|
+
* `run` must read the auth headers itself so the retry carries the fresh token.
|
|
6314
|
+
*/
|
|
6315
|
+
async recovering(run) {
|
|
6316
|
+
if (this.client && tokenExpiresWithin(this.client.session.getState().accessToken, 30)) {
|
|
6317
|
+
await this.client.auth.relogin();
|
|
6318
|
+
}
|
|
6319
|
+
try {
|
|
6320
|
+
return await run();
|
|
6321
|
+
} catch (error) {
|
|
6322
|
+
const message = error instanceof Error ? error.message : "";
|
|
6323
|
+
const noWorkspace = /no active workspace/i.test(message);
|
|
6324
|
+
const unauthorised = /\b401\b|token has expired/i.test(message);
|
|
6325
|
+
if (!(error instanceof ArbiApiError) || !(noWorkspace || unauthorised)) throw error;
|
|
6326
|
+
const client = this.requireClient();
|
|
6327
|
+
const recovered = noWorkspace && await client.auth.reopenWorkspace() || await client.auth.relogin() !== null;
|
|
6328
|
+
if (!recovered) {
|
|
6329
|
+
this.expireSession();
|
|
6330
|
+
throw new ArbiSessionExpiredError();
|
|
6331
|
+
}
|
|
6332
|
+
return run();
|
|
6333
|
+
}
|
|
6334
|
+
}
|
|
6265
6335
|
/** Log out and clear internal state. */
|
|
6266
6336
|
async logout() {
|
|
6267
6337
|
if (this.client) {
|
|
@@ -6428,16 +6498,18 @@ var Arbi = class {
|
|
|
6428
6498
|
},
|
|
6429
6499
|
uploadFile: (fileData, fileName, options) => {
|
|
6430
6500
|
this.requireWorkspace();
|
|
6431
|
-
return
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6501
|
+
return this.recovering(
|
|
6502
|
+
() => uploadFile(
|
|
6503
|
+
this.getAuthHeaders(),
|
|
6504
|
+
fileData,
|
|
6505
|
+
fileName,
|
|
6506
|
+
options?.folder ? { folder: options.folder } : void 0
|
|
6507
|
+
)
|
|
6436
6508
|
);
|
|
6437
6509
|
},
|
|
6438
|
-
download: (docId) => downloadDocument(this.getAuthHeaders(), docId),
|
|
6439
|
-
getParsedContent: (docId, stage) => getParsedContent(this.getAuthHeaders(), docId, stage),
|
|
6440
|
-
getThumbnails: (docIds) => getThumbnails(this.getAuthHeaders(), docIds)
|
|
6510
|
+
download: (docId) => this.recovering(() => downloadDocument(this.getAuthHeaders(), docId)),
|
|
6511
|
+
getParsedContent: (docId, stage) => this.recovering(() => getParsedContent(this.getAuthHeaders(), docId, stage)),
|
|
6512
|
+
getThumbnails: (docIds) => this.recovering(() => getThumbnails(this.getAuthHeaders(), docIds))
|
|
6441
6513
|
};
|
|
6442
6514
|
// ── Conversations ─────────────────────────────────────────────────────
|
|
6443
6515
|
conversations = {
|
|
@@ -6456,16 +6528,17 @@ var Arbi = class {
|
|
|
6456
6528
|
* Returns the accumulated result after the stream completes.
|
|
6457
6529
|
*/
|
|
6458
6530
|
query: async (question, options) => {
|
|
6459
|
-
const auth = this.getAuthHeaders();
|
|
6460
6531
|
const workspaceId = this.requireWorkspace();
|
|
6461
|
-
const response = await
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6532
|
+
const response = await this.recovering(
|
|
6533
|
+
() => queryAssistant({
|
|
6534
|
+
...this.getAuthHeaders(),
|
|
6535
|
+
workspaceId,
|
|
6536
|
+
question,
|
|
6537
|
+
docIds: options.docIds,
|
|
6538
|
+
previousResponseId: options.previousResponseId,
|
|
6539
|
+
model: options.model
|
|
6540
|
+
})
|
|
6541
|
+
);
|
|
6469
6542
|
const callbacks = {
|
|
6470
6543
|
onToken: options.onToken,
|
|
6471
6544
|
onStreamStart: options.onStreamStart,
|
|
@@ -6629,8 +6702,10 @@ var Arbi = class {
|
|
|
6629
6702
|
list: (options) => listFiles(this.requireClient(), options),
|
|
6630
6703
|
get: (fileId) => getFile(this.requireClient(), fileId),
|
|
6631
6704
|
delete: (fileId) => deleteFile(this.requireClient(), fileId),
|
|
6632
|
-
upload: (fileData, fileName, purpose) =>
|
|
6633
|
-
|
|
6705
|
+
upload: (fileData, fileName, purpose) => this.recovering(
|
|
6706
|
+
() => uploadFile2(this.getAuthHeaders(), fileData, fileName, purpose)
|
|
6707
|
+
),
|
|
6708
|
+
getContent: (fileId) => this.recovering(() => getFileContent(this.getAuthHeaders(), fileId))
|
|
6634
6709
|
};
|
|
6635
6710
|
// ── Agents ──────────────────────────────────────────────────────────
|
|
6636
6711
|
agents = {
|
|
@@ -7812,6 +7887,6 @@ async function startDmListener(options) {
|
|
|
7812
7887
|
};
|
|
7813
7888
|
}
|
|
7814
7889
|
|
|
7815
|
-
export { Arbi, ArbiApiError, ArbiError, ClaudeOrchestrator, DOC_TERMINAL_STATUSES, FileConfigStore, OpenClawOrchestrator, WebSocketAuthError, agentconfig_exports as agentconfig, agents_exports as agents, assistant_exports as assistant, authenticatedFetch, buildDocNameMap, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts_exports as contacts, conversations_exports as conversations, countCitations, createAuthenticatedClient, createDocumentWaiter, device_flow_exports as deviceFlow, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, documents_node_exports as documentsNode, facts_exports as facts, files_exports as files, filterSkills, formatAgentStepLabel, formatFileSize, formatItemLabel, formatStreamSummary, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, generateNewWorkspaceKey, getErrorCode, getErrorMessage, getRawWorkspaceKey, health_exports as health, listen_exports as listen, parseSSEEvents, parseSlashCommand, parseSlashTokenInProgress, performPasswordLogin, performSigningKeyLogin, performSsoDeviceFlowLogin, profile_exports as profile, projects_exports as projects, requireData, requireOk, resolveAuth, resolveCitations, resolveWorkspace, responses_exports as responses, selectWorkspace, selectWorkspaceById, sessions_exports as sessions, settings_exports as settings, startDmListener, streamSSE, stripCitationMarkdown, summarizeCitations, tags_exports as tags, tasks_exports as tasks, workspaces_exports as workspaces };
|
|
7890
|
+
export { Arbi, ArbiApiError, ArbiError, ArbiSessionExpiredError, ClaudeOrchestrator, DOC_TERMINAL_STATUSES, FileConfigStore, OpenClawOrchestrator, WebSocketAuthError, agentconfig_exports as agentconfig, agents_exports as agents, assistant_exports as assistant, authenticatedFetch, buildDocNameMap, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, connectWebSocket, connectWithReconnect, consumeSSEStream, contacts_exports as contacts, conversations_exports as conversations, countCitations, createAuthenticatedClient, createDocumentWaiter, device_flow_exports as deviceFlow, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, documents_node_exports as documentsNode, facts_exports as facts, files_exports as files, filterSkills, formatAgentStepLabel, formatFileSize, formatItemLabel, formatStreamSummary, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, generateNewWorkspaceKey, getErrorCode, getErrorMessage, getRawWorkspaceKey, health_exports as health, listen_exports as listen, parseSSEEvents, parseSlashCommand, parseSlashTokenInProgress, performPasswordLogin, performSigningKeyLogin, performSsoDeviceFlowLogin, profile_exports as profile, projects_exports as projects, requireData, requireOk, resolveAuth, resolveCitations, resolveWorkspace, responses_exports as responses, selectWorkspace, selectWorkspaceById, sessions_exports as sessions, settings_exports as settings, startDmListener, streamSSE, stripCitationMarkdown, summarizeCitations, tags_exports as tags, tasks_exports as tasks, workspaces_exports as workspaces };
|
|
7816
7891
|
//# sourceMappingURL=index.js.map
|
|
7817
7892
|
//# sourceMappingURL=index.js.map
|