@arbidocs/sdk 0.3.16 → 0.3.17
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/README.md +58 -81
- package/dist/{browser-DFRwcoc1.d.cts → browser-BtAHbiq_.d.cts} +78 -5
- package/dist/{browser-DFRwcoc1.d.ts → browser-BtAHbiq_.d.ts} +78 -5
- package/dist/browser.cjs +77 -0
- 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 +74 -1
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +108 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +104 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, A as AuthHeaders, U as UploadBatchResult, d as UploadOptions, e as UploadResult } from './browser-
|
|
2
|
-
export { f as AgentStepEvent, g as Arbi, h as ArbiApiError, i as ArbiError, j as ArbiOptions, k as ArtifactEvent, l as AuthContext, m as AuthenticatedClient, n as ConnectOptions, D as DocumentWaiter,
|
|
1
|
+
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, A as AuthHeaders, U as UploadBatchResult, d as UploadOptions, e as UploadResult } from './browser-BtAHbiq_.cjs';
|
|
2
|
+
export { f as AgentStepEvent, g as Arbi, h as ArbiApiError, i as ArbiError, j as ArbiOptions, k as ArtifactEvent, l as AuthContext, m as AuthenticatedClient, n as CitationSummary, o as ConnectOptions, D as DocumentWaiter, p as DocumentWaiterOptions, F as FormattedWsMessage, L as LIFECYCLE_LABELS, M as MessageLevel, q as MessageMetadataPayload, r as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, s as ReconnectableWsConnection, t as ResolvedCitation, u as ResponseCompletedEvent, v as ResponseContentPartAddedEvent, w as ResponseCreatedEvent, x as ResponseFailedEvent, y as ResponseOutputItemAddedEvent, z as ResponseOutputItemDoneEvent, B as ResponseOutputTextDeltaEvent, E as ResponseOutputTextDoneEvent, G as ResponseUsage, S as SSEEvent, H as SSEStreamCallbacks, I as SSEStreamResult, J as SSEStreamStartData, T as TOOL_LABELS, K as UserInfo, N as UserInputRequestEvent, P as UserMessageEvent, W as WorkspaceContext, V as WsConnection, X as agentconfig, Y as assistant, Z as authenticatedFetch, _ as buildRetrievalChunkTool, $ as buildRetrievalFullContextTool, a0 as buildRetrievalTocTool, a1 as connectWebSocket, a2 as connectWithReconnect, a3 as consumeSSEStream, a4 as contacts, a5 as conversations, a6 as countCitations, a7 as createAuthenticatedClient, a8 as createDocumentWaiter, a9 as dm, aa as doctags, ab as documents, ac as files, ad as formatAgentStepLabel, ae as formatFileSize, af as formatStreamSummary, ag as formatUserName, ah as formatWorkspaceChoices, ai as formatWsMessage, aj as generateEncryptedWorkspaceKey, ak as getErrorCode, al as getErrorMessage, am as health, an as parseSSEEvents, ao as performPasswordLogin, ap as requireData, aq as requireOk, ar as resolveAuth, as as resolveCitations, at as resolveWorkspace, au as responses, av as selectWorkspace, aw as selectWorkspaceById, ax as settings, ay as streamSSE, az as stripCitationMarkdown, aA as summarizeCitations, aB as tags, aC as workspaces } from './browser-BtAHbiq_.cjs';
|
|
3
3
|
import '@arbidocs/client';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,6 +13,7 @@ declare class FileConfigStore implements ConfigStore {
|
|
|
13
13
|
private readonly configFile;
|
|
14
14
|
private readonly credentialsFile;
|
|
15
15
|
private readonly sessionFile;
|
|
16
|
+
private readonly metadataFile;
|
|
16
17
|
constructor(configDir?: string);
|
|
17
18
|
private ensureConfigDir;
|
|
18
19
|
private writeSecureFile;
|
|
@@ -29,6 +30,8 @@ declare class FileConfigStore implements ConfigStore {
|
|
|
29
30
|
saveChatSession(session: ChatSession): void;
|
|
30
31
|
updateChatSession(updates: Partial<ChatSession>): void;
|
|
31
32
|
clearChatSession(): void;
|
|
33
|
+
saveLastMetadata(metadata: unknown): void;
|
|
34
|
+
loadLastMetadata(): unknown | null;
|
|
32
35
|
/**
|
|
33
36
|
* Try to resolve config from multiple sources, in priority order:
|
|
34
37
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, A as AuthHeaders, U as UploadBatchResult, d as UploadOptions, e as UploadResult } from './browser-
|
|
2
|
-
export { f as AgentStepEvent, g as Arbi, h as ArbiApiError, i as ArbiError, j as ArbiOptions, k as ArtifactEvent, l as AuthContext, m as AuthenticatedClient, n as ConnectOptions, D as DocumentWaiter,
|
|
1
|
+
import { C as ConfigStore, a as CliConfig, b as CliCredentials, c as ChatSession, A as AuthHeaders, U as UploadBatchResult, d as UploadOptions, e as UploadResult } from './browser-BtAHbiq_.js';
|
|
2
|
+
export { f as AgentStepEvent, g as Arbi, h as ArbiApiError, i as ArbiError, j as ArbiOptions, k as ArtifactEvent, l as AuthContext, m as AuthenticatedClient, n as CitationSummary, o as ConnectOptions, D as DocumentWaiter, p as DocumentWaiterOptions, F as FormattedWsMessage, L as LIFECYCLE_LABELS, M as MessageLevel, q as MessageMetadataPayload, r as MessageQueuedEvent, O as OutputTokensDetails, Q as QueryOptions, R as ReconnectOptions, s as ReconnectableWsConnection, t as ResolvedCitation, u as ResponseCompletedEvent, v as ResponseContentPartAddedEvent, w as ResponseCreatedEvent, x as ResponseFailedEvent, y as ResponseOutputItemAddedEvent, z as ResponseOutputItemDoneEvent, B as ResponseOutputTextDeltaEvent, E as ResponseOutputTextDoneEvent, G as ResponseUsage, S as SSEEvent, H as SSEStreamCallbacks, I as SSEStreamResult, J as SSEStreamStartData, T as TOOL_LABELS, K as UserInfo, N as UserInputRequestEvent, P as UserMessageEvent, W as WorkspaceContext, V as WsConnection, X as agentconfig, Y as assistant, Z as authenticatedFetch, _ as buildRetrievalChunkTool, $ as buildRetrievalFullContextTool, a0 as buildRetrievalTocTool, a1 as connectWebSocket, a2 as connectWithReconnect, a3 as consumeSSEStream, a4 as contacts, a5 as conversations, a6 as countCitations, a7 as createAuthenticatedClient, a8 as createDocumentWaiter, a9 as dm, aa as doctags, ab as documents, ac as files, ad as formatAgentStepLabel, ae as formatFileSize, af as formatStreamSummary, ag as formatUserName, ah as formatWorkspaceChoices, ai as formatWsMessage, aj as generateEncryptedWorkspaceKey, ak as getErrorCode, al as getErrorMessage, am as health, an as parseSSEEvents, ao as performPasswordLogin, ap as requireData, aq as requireOk, ar as resolveAuth, as as resolveCitations, at as resolveWorkspace, au as responses, av as selectWorkspace, aw as selectWorkspaceById, ax as settings, ay as streamSSE, az as stripCitationMarkdown, aA as summarizeCitations, aB as tags, aC as workspaces } from './browser-BtAHbiq_.js';
|
|
3
3
|
import '@arbidocs/client';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -13,6 +13,7 @@ declare class FileConfigStore implements ConfigStore {
|
|
|
13
13
|
private readonly configFile;
|
|
14
14
|
private readonly credentialsFile;
|
|
15
15
|
private readonly sessionFile;
|
|
16
|
+
private readonly metadataFile;
|
|
16
17
|
constructor(configDir?: string);
|
|
17
18
|
private ensureConfigDir;
|
|
18
19
|
private writeSecureFile;
|
|
@@ -29,6 +30,8 @@ declare class FileConfigStore implements ConfigStore {
|
|
|
29
30
|
saveChatSession(session: ChatSession): void;
|
|
30
31
|
updateChatSession(updates: Partial<ChatSession>): void;
|
|
31
32
|
clearChatSession(): void;
|
|
33
|
+
saveLastMetadata(metadata: unknown): void;
|
|
34
|
+
loadLastMetadata(): unknown | null;
|
|
32
35
|
/**
|
|
33
36
|
* Try to resolve config from multiple sources, in priority order:
|
|
34
37
|
*
|
package/dist/index.js
CHANGED
|
@@ -121,11 +121,13 @@ var FileConfigStore = class {
|
|
|
121
121
|
configFile;
|
|
122
122
|
credentialsFile;
|
|
123
123
|
sessionFile;
|
|
124
|
+
metadataFile;
|
|
124
125
|
constructor(configDir) {
|
|
125
126
|
this.configDir = configDir ?? process.env.ARBI_CONFIG_DIR ?? path2.join(os.homedir(), ".arbi");
|
|
126
127
|
this.configFile = path2.join(this.configDir, "config.json");
|
|
127
128
|
this.credentialsFile = path2.join(this.configDir, "credentials.json");
|
|
128
129
|
this.sessionFile = path2.join(this.configDir, "session.json");
|
|
130
|
+
this.metadataFile = path2.join(this.configDir, "last-metadata.json");
|
|
129
131
|
}
|
|
130
132
|
ensureConfigDir() {
|
|
131
133
|
if (!fs.existsSync(this.configDir)) {
|
|
@@ -196,6 +198,13 @@ var FileConfigStore = class {
|
|
|
196
198
|
clearChatSession() {
|
|
197
199
|
this.saveChatSession({ ...DEFAULT_SESSION });
|
|
198
200
|
}
|
|
201
|
+
// ── Last metadata (for citation browsing) ────────────────────────────────
|
|
202
|
+
saveLastMetadata(metadata) {
|
|
203
|
+
this.writeSecureFile(this.metadataFile, metadata);
|
|
204
|
+
}
|
|
205
|
+
loadLastMetadata() {
|
|
206
|
+
return this.readJsonFile(this.metadataFile);
|
|
207
|
+
}
|
|
199
208
|
/**
|
|
200
209
|
* Try to resolve config from multiple sources, in priority order:
|
|
201
210
|
*
|
|
@@ -644,6 +653,27 @@ async function streamSSE(response, callbacks = {}) {
|
|
|
644
653
|
context
|
|
645
654
|
};
|
|
646
655
|
}
|
|
656
|
+
function formatStreamSummary(result, elapsedTime) {
|
|
657
|
+
const parts = [];
|
|
658
|
+
if (result.agentSteps.length > 0) {
|
|
659
|
+
let stepLabel = `${result.agentSteps.length} step${result.agentSteps.length === 1 ? "" : "s"}`;
|
|
660
|
+
if (result.toolCallCount > 0) {
|
|
661
|
+
stepLabel += ` (${result.toolCallCount} tool call${result.toolCallCount === 1 ? "" : "s"})`;
|
|
662
|
+
}
|
|
663
|
+
parts.push(stepLabel);
|
|
664
|
+
}
|
|
665
|
+
if (result.usage) {
|
|
666
|
+
parts.push(`${result.usage.total_tokens.toLocaleString()} tokens`);
|
|
667
|
+
}
|
|
668
|
+
if (result.context && result.context.context_window > 0) {
|
|
669
|
+
const used = result.context.all_llm_calls?.last_input_tokens ?? result.context.total_input;
|
|
670
|
+
parts.push(`${used.toLocaleString()}/${result.context.context_window.toLocaleString()} context`);
|
|
671
|
+
}
|
|
672
|
+
if (elapsedTime != null) {
|
|
673
|
+
parts.push(`${elapsedTime.toFixed(1)}s`);
|
|
674
|
+
}
|
|
675
|
+
return parts.length > 0 ? parts.join(" \xB7 ") : "";
|
|
676
|
+
}
|
|
647
677
|
var consumeSSEStream = streamSSE;
|
|
648
678
|
var AUTH_TIMEOUT_MS = 1e4;
|
|
649
679
|
var MAX_BACKOFF_MS = 3e4;
|
|
@@ -868,6 +898,66 @@ function formatUserName(user) {
|
|
|
868
898
|
return [user.given_name, user.family_name].filter(Boolean).join(" ");
|
|
869
899
|
}
|
|
870
900
|
|
|
901
|
+
// src/citations.ts
|
|
902
|
+
function resolveCitations(metadata) {
|
|
903
|
+
if (!metadata?.tools) return [];
|
|
904
|
+
const tools = metadata.tools;
|
|
905
|
+
const modelCitations = tools.model_citations;
|
|
906
|
+
const citationMap = modelCitations?.tool_responses;
|
|
907
|
+
if (!citationMap || Object.keys(citationMap).length === 0) return [];
|
|
908
|
+
const chunkLookup = buildChunkLookup(tools);
|
|
909
|
+
const resolved = [];
|
|
910
|
+
for (const [citationNum, citationData] of Object.entries(citationMap)) {
|
|
911
|
+
const chunks = [];
|
|
912
|
+
for (const chunkId of citationData.chunk_ids ?? []) {
|
|
913
|
+
const chunk = chunkLookup.get(chunkId);
|
|
914
|
+
if (chunk) chunks.push(chunk);
|
|
915
|
+
}
|
|
916
|
+
resolved.push({ citationNum, citationData, chunks });
|
|
917
|
+
}
|
|
918
|
+
resolved.sort((a, b) => Number(a.citationNum) - Number(b.citationNum));
|
|
919
|
+
return resolved;
|
|
920
|
+
}
|
|
921
|
+
function summarizeCitations(resolved) {
|
|
922
|
+
return resolved.map((r) => {
|
|
923
|
+
const firstChunk = r.chunks[0];
|
|
924
|
+
return {
|
|
925
|
+
citationNum: r.citationNum,
|
|
926
|
+
statement: r.citationData.statement ?? "",
|
|
927
|
+
docTitle: firstChunk?.metadata?.doc_title ?? "Unknown document",
|
|
928
|
+
pageNumber: firstChunk?.metadata?.page_number ?? null,
|
|
929
|
+
chunkCount: r.chunks.length
|
|
930
|
+
};
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
function countCitations(metadata) {
|
|
934
|
+
if (!metadata?.tools) return 0;
|
|
935
|
+
const tools = metadata.tools;
|
|
936
|
+
const modelCitations = tools.model_citations;
|
|
937
|
+
const responses = modelCitations?.tool_responses;
|
|
938
|
+
return responses ? Object.keys(responses).length : 0;
|
|
939
|
+
}
|
|
940
|
+
function stripCitationMarkdown(text) {
|
|
941
|
+
return text.replace(/\[([^\]]+)\]\(#cite-(\d+)\)/g, "$1[$2]");
|
|
942
|
+
}
|
|
943
|
+
function buildChunkLookup(tools) {
|
|
944
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
945
|
+
for (const toolName of ["retrieval_chunk", "retrieval_full_context"]) {
|
|
946
|
+
const tool = tools[toolName];
|
|
947
|
+
if (!tool?.tool_responses) continue;
|
|
948
|
+
for (const chunks of Object.values(tool.tool_responses)) {
|
|
949
|
+
if (!Array.isArray(chunks)) continue;
|
|
950
|
+
for (const chunk of chunks) {
|
|
951
|
+
const id = chunk.metadata?.chunk_ext_id;
|
|
952
|
+
if (id && !lookup.has(id)) {
|
|
953
|
+
lookup.set(id, chunk);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
return lookup;
|
|
959
|
+
}
|
|
960
|
+
|
|
871
961
|
// src/operations/documents.ts
|
|
872
962
|
var documents_exports = {};
|
|
873
963
|
__export(documents_exports, {
|
|
@@ -1565,6 +1655,19 @@ var Arbi = class {
|
|
|
1565
1655
|
lr.serverSessionKey,
|
|
1566
1656
|
signingPrivateKeyBase64
|
|
1567
1657
|
);
|
|
1658
|
+
const workspaceKeyHeader = client.session.getWorkspaceKeyHeader();
|
|
1659
|
+
if (workspaceKeyHeader) {
|
|
1660
|
+
const { data: openResult, error: openError } = await client.fetch.POST(
|
|
1661
|
+
"/v1/workspace/{workspace_ext_id}/open",
|
|
1662
|
+
{
|
|
1663
|
+
params: { path: { workspace_ext_id: ws.external_id } },
|
|
1664
|
+
body: { workspace_key: workspaceKeyHeader }
|
|
1665
|
+
}
|
|
1666
|
+
);
|
|
1667
|
+
if (!openError && openResult?.access_token) {
|
|
1668
|
+
client.session.setAccessToken(openResult.access_token);
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1568
1671
|
this.currentWorkspaceId = ws.external_id;
|
|
1569
1672
|
}
|
|
1570
1673
|
/** Log out and clear internal state. */
|
|
@@ -1966,6 +2069,6 @@ function extractResponseText(response) {
|
|
|
1966
2069
|
return parts.join("");
|
|
1967
2070
|
}
|
|
1968
2071
|
|
|
1969
|
-
export { Arbi, ArbiApiError, ArbiError, FileConfigStore, 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, createDocumentWaiter, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, documents_node_exports as documentsNode, files_exports as files, formatAgentStepLabel, formatFileSize, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, getErrorCode, 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 };
|
|
2072
|
+
export { Arbi, ArbiApiError, ArbiError, FileConfigStore, 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, countCitations, createAuthenticatedClient, createDocumentWaiter, dm_exports as dm, doctags_exports as doctags, documents_exports as documents, documents_node_exports as documentsNode, files_exports as files, formatAgentStepLabel, formatFileSize, formatStreamSummary, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, getErrorCode, getErrorMessage, health_exports as health, parseSSEEvents, performPasswordLogin, requireData, requireOk, resolveAuth, resolveCitations, resolveWorkspace, responses_exports as responses, selectWorkspace, selectWorkspaceById, settings_exports as settings, streamSSE, stripCitationMarkdown, summarizeCitations, tags_exports as tags, workspaces_exports as workspaces };
|
|
1970
2073
|
//# sourceMappingURL=index.js.map
|
|
1971
2074
|
//# sourceMappingURL=index.js.map
|