@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/browser.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as AgentControlStateEvent, a as AgentStepDeltaEvent, b as AgentStepEvent, c as Arbi, d as ArbiApiError, e as ArbiError, f as ArbiErrorEvent, g as ArbiOptions,
|
|
1
|
+
export { A as AgentControlStateEvent, a as AgentStepDeltaEvent, b as AgentStepEvent, c as Arbi, d as ArbiApiError, e as ArbiError, f as ArbiErrorEvent, g as ArbiOptions, i as ArtifactEvent, j as AuthContext, k as AuthHeaders, l as AuthenticatedClient, C as ChatSession, m as CitationSummary, n as CliConfig, o as CliCredentials, p as CommandDescriptor, q as ConfigStore, r as ConnectOptions, s as CreateFactRequest, t as CreateFactsRequest, u as CreateTaskRequest, v as DeferredInterjectionEvent, F as FactResponse, G as FactSearchRequest, H as FactSearchResponse, J as ListFactsOptions, N as MessageMetadataPayload, O as MessageQueuedEvent, P as OutputTokensDetails, Q as ParsedSlashCommand, R as ProbeAnswerEvent, S as ProjectInvoicesResponse, T as ProjectUsageResponse, U as QueryOptions, V as ReconnectOptions, W as ReconnectableWsConnection, X as ResolvedCitation, 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, ad as TaskResponse, ae as TokenBudgetContext, af as UpdateFactRequest, ag as UpdateTaskRequest, 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, 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, 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, aS as formatUserName, aT as formatWorkspaceChoices, aY as getErrorMessage, aZ as getRawWorkspaceKey, a_ as health, a$ as parseSSEEvents, b0 as parseSlashCommand, b1 as parseSlashTokenInProgress, b2 as performPasswordLogin, 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';
|
|
2
2
|
import '@arbidocs/client';
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { A as AgentControlStateEvent, a as AgentStepDeltaEvent, b as AgentStepEvent, c as Arbi, d as ArbiApiError, e as ArbiError, f as ArbiErrorEvent, g as ArbiOptions,
|
|
1
|
+
export { A as AgentControlStateEvent, a as AgentStepDeltaEvent, b as AgentStepEvent, c as Arbi, d as ArbiApiError, e as ArbiError, f as ArbiErrorEvent, g as ArbiOptions, i as ArtifactEvent, j as AuthContext, k as AuthHeaders, l as AuthenticatedClient, C as ChatSession, m as CitationSummary, n as CliConfig, o as CliCredentials, p as CommandDescriptor, q as ConfigStore, r as ConnectOptions, s as CreateFactRequest, t as CreateFactsRequest, u as CreateTaskRequest, v as DeferredInterjectionEvent, F as FactResponse, G as FactSearchRequest, H as FactSearchResponse, J as ListFactsOptions, N as MessageMetadataPayload, O as MessageQueuedEvent, P as OutputTokensDetails, Q as ParsedSlashCommand, R as ProbeAnswerEvent, S as ProjectInvoicesResponse, T as ProjectUsageResponse, U as QueryOptions, V as ReconnectOptions, W as ReconnectableWsConnection, X as ResolvedCitation, 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, ad as TaskResponse, ae as TokenBudgetContext, af as UpdateFactRequest, ag as UpdateTaskRequest, 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, 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, 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, aS as formatUserName, aT as formatWorkspaceChoices, aY as getErrorMessage, aZ as getRawWorkspaceKey, a_ as health, a$ as parseSSEEvents, b0 as parseSlashCommand, b1 as parseSlashTokenInProgress, b2 as performPasswordLogin, 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';
|
|
2
2
|
import '@arbidocs/client';
|
package/dist/browser.js
CHANGED
|
@@ -3481,6 +3481,12 @@ var ArbiError = class extends Error {
|
|
|
3481
3481
|
this.name = "ArbiError";
|
|
3482
3482
|
}
|
|
3483
3483
|
};
|
|
3484
|
+
var ArbiSessionExpiredError = class extends ArbiError {
|
|
3485
|
+
constructor(message = "Your session expired. Sign in again.") {
|
|
3486
|
+
super(message);
|
|
3487
|
+
this.name = "ArbiSessionExpiredError";
|
|
3488
|
+
}
|
|
3489
|
+
};
|
|
3484
3490
|
var ArbiApiError = class extends ArbiError {
|
|
3485
3491
|
apiError;
|
|
3486
3492
|
constructor(message, apiError) {
|
|
@@ -5617,11 +5623,23 @@ async function remindFact(arbi, factId, options = {}) {
|
|
|
5617
5623
|
}
|
|
5618
5624
|
|
|
5619
5625
|
// src/arbi.ts
|
|
5626
|
+
function tokenExpiresWithin(token, seconds) {
|
|
5627
|
+
const payload = token?.split(".")[1];
|
|
5628
|
+
if (!payload) return false;
|
|
5629
|
+
try {
|
|
5630
|
+
const json = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
|
|
5631
|
+
const { exp } = JSON.parse(json);
|
|
5632
|
+
return typeof exp === "number" && exp * 1e3 - Date.now() < seconds * 1e3;
|
|
5633
|
+
} catch {
|
|
5634
|
+
return false;
|
|
5635
|
+
}
|
|
5636
|
+
}
|
|
5620
5637
|
var Arbi = class {
|
|
5621
5638
|
client = null;
|
|
5622
5639
|
loginResult = null;
|
|
5623
5640
|
currentWorkspaceId = null;
|
|
5624
5641
|
dmCryptoContext = null;
|
|
5642
|
+
sessionExpiredListeners = /* @__PURE__ */ new Set();
|
|
5625
5643
|
options;
|
|
5626
5644
|
constructor(options) {
|
|
5627
5645
|
this.options = options;
|
|
@@ -5634,7 +5652,13 @@ var Arbi = class {
|
|
|
5634
5652
|
this.client = createArbiClient({
|
|
5635
5653
|
baseUrl: this.options.url,
|
|
5636
5654
|
deploymentDomain: domain,
|
|
5637
|
-
credentials: this.options.credentials ?? "omit"
|
|
5655
|
+
credentials: this.options.credentials ?? "omit",
|
|
5656
|
+
// A silent re-login rotates the server session key: keep ours in step, or the next
|
|
5657
|
+
// workspace open would seal the key for a session the server no longer has.
|
|
5658
|
+
onReloginSuccess: ({ serverSessionKey }) => {
|
|
5659
|
+
if (this.loginResult) this.loginResult = { ...this.loginResult, serverSessionKey };
|
|
5660
|
+
},
|
|
5661
|
+
onSessionExpired: () => this.expireSession()
|
|
5638
5662
|
});
|
|
5639
5663
|
await this.client.crypto.initSodium();
|
|
5640
5664
|
return this.client;
|
|
@@ -5697,6 +5721,52 @@ var Arbi = class {
|
|
|
5697
5721
|
});
|
|
5698
5722
|
this.currentWorkspaceId = ws.external_id;
|
|
5699
5723
|
}
|
|
5724
|
+
/**
|
|
5725
|
+
* Subscribe to "the session cannot be recovered". Fires when a request failed with 401 or
|
|
5726
|
+
* "No active workspace" and neither a workspace re-open nor a silent re-login was possible
|
|
5727
|
+
* (the server refused; an unreachable server does not fire). The local session is already
|
|
5728
|
+
* cleared when it fires: show "Your session expired, sign in again". Returns an unsubscribe.
|
|
5729
|
+
*/
|
|
5730
|
+
onSessionExpired(listener) {
|
|
5731
|
+
this.sessionExpiredListeners.add(listener);
|
|
5732
|
+
return () => this.sessionExpiredListeners.delete(listener);
|
|
5733
|
+
}
|
|
5734
|
+
expireSession() {
|
|
5735
|
+
if (this.loginResult) {
|
|
5736
|
+
this.loginResult.signingPrivateKey.fill(0);
|
|
5737
|
+
this.loginResult.serverSessionKey.fill(0);
|
|
5738
|
+
}
|
|
5739
|
+
this.loginResult = null;
|
|
5740
|
+
this.currentWorkspaceId = null;
|
|
5741
|
+
this.dmCryptoContext = null;
|
|
5742
|
+
this.client?.session.clear();
|
|
5743
|
+
for (const listener of [...this.sessionExpiredListeners]) listener();
|
|
5744
|
+
}
|
|
5745
|
+
/**
|
|
5746
|
+
* Run a raw-fetch operation (streaming, multipart: no middleware) and, when it fails because
|
|
5747
|
+
* the token expired or the server lost the open workspace, recover once and run it again.
|
|
5748
|
+
* `run` must read the auth headers itself so the retry carries the fresh token.
|
|
5749
|
+
*/
|
|
5750
|
+
async recovering(run) {
|
|
5751
|
+
if (this.client && tokenExpiresWithin(this.client.session.getState().accessToken, 30)) {
|
|
5752
|
+
await this.client.auth.relogin();
|
|
5753
|
+
}
|
|
5754
|
+
try {
|
|
5755
|
+
return await run();
|
|
5756
|
+
} catch (error) {
|
|
5757
|
+
const message = error instanceof Error ? error.message : "";
|
|
5758
|
+
const noWorkspace = /no active workspace/i.test(message);
|
|
5759
|
+
const unauthorised = /\b401\b|token has expired/i.test(message);
|
|
5760
|
+
if (!(error instanceof ArbiApiError) || !(noWorkspace || unauthorised)) throw error;
|
|
5761
|
+
const client = this.requireClient();
|
|
5762
|
+
const recovered = noWorkspace && await client.auth.reopenWorkspace() || await client.auth.relogin() !== null;
|
|
5763
|
+
if (!recovered) {
|
|
5764
|
+
this.expireSession();
|
|
5765
|
+
throw new ArbiSessionExpiredError();
|
|
5766
|
+
}
|
|
5767
|
+
return run();
|
|
5768
|
+
}
|
|
5769
|
+
}
|
|
5700
5770
|
/** Log out and clear internal state. */
|
|
5701
5771
|
async logout() {
|
|
5702
5772
|
if (this.client) {
|
|
@@ -5863,16 +5933,18 @@ var Arbi = class {
|
|
|
5863
5933
|
},
|
|
5864
5934
|
uploadFile: (fileData, fileName, options) => {
|
|
5865
5935
|
this.requireWorkspace();
|
|
5866
|
-
return
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5936
|
+
return this.recovering(
|
|
5937
|
+
() => uploadFile(
|
|
5938
|
+
this.getAuthHeaders(),
|
|
5939
|
+
fileData,
|
|
5940
|
+
fileName,
|
|
5941
|
+
options?.folder ? { folder: options.folder } : void 0
|
|
5942
|
+
)
|
|
5871
5943
|
);
|
|
5872
5944
|
},
|
|
5873
|
-
download: (docId) => downloadDocument(this.getAuthHeaders(), docId),
|
|
5874
|
-
getParsedContent: (docId, stage) => getParsedContent(this.getAuthHeaders(), docId, stage),
|
|
5875
|
-
getThumbnails: (docIds) => getThumbnails(this.getAuthHeaders(), docIds)
|
|
5945
|
+
download: (docId) => this.recovering(() => downloadDocument(this.getAuthHeaders(), docId)),
|
|
5946
|
+
getParsedContent: (docId, stage) => this.recovering(() => getParsedContent(this.getAuthHeaders(), docId, stage)),
|
|
5947
|
+
getThumbnails: (docIds) => this.recovering(() => getThumbnails(this.getAuthHeaders(), docIds))
|
|
5876
5948
|
};
|
|
5877
5949
|
// ── Conversations ─────────────────────────────────────────────────────
|
|
5878
5950
|
conversations = {
|
|
@@ -5891,16 +5963,17 @@ var Arbi = class {
|
|
|
5891
5963
|
* Returns the accumulated result after the stream completes.
|
|
5892
5964
|
*/
|
|
5893
5965
|
query: async (question, options) => {
|
|
5894
|
-
const auth = this.getAuthHeaders();
|
|
5895
5966
|
const workspaceId = this.requireWorkspace();
|
|
5896
|
-
const response = await
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5967
|
+
const response = await this.recovering(
|
|
5968
|
+
() => queryAssistant({
|
|
5969
|
+
...this.getAuthHeaders(),
|
|
5970
|
+
workspaceId,
|
|
5971
|
+
question,
|
|
5972
|
+
docIds: options.docIds,
|
|
5973
|
+
previousResponseId: options.previousResponseId,
|
|
5974
|
+
model: options.model
|
|
5975
|
+
})
|
|
5976
|
+
);
|
|
5904
5977
|
const callbacks = {
|
|
5905
5978
|
onToken: options.onToken,
|
|
5906
5979
|
onStreamStart: options.onStreamStart,
|
|
@@ -6064,8 +6137,10 @@ var Arbi = class {
|
|
|
6064
6137
|
list: (options) => listFiles(this.requireClient(), options),
|
|
6065
6138
|
get: (fileId) => getFile(this.requireClient(), fileId),
|
|
6066
6139
|
delete: (fileId) => deleteFile(this.requireClient(), fileId),
|
|
6067
|
-
upload: (fileData, fileName, purpose) =>
|
|
6068
|
-
|
|
6140
|
+
upload: (fileData, fileName, purpose) => this.recovering(
|
|
6141
|
+
() => uploadFile2(this.getAuthHeaders(), fileData, fileName, purpose)
|
|
6142
|
+
),
|
|
6143
|
+
getContent: (fileId) => this.recovering(() => getFileContent(this.getAuthHeaders(), fileId))
|
|
6069
6144
|
};
|
|
6070
6145
|
// ── Agents ──────────────────────────────────────────────────────────
|
|
6071
6146
|
agents = {
|