@arbidocs/sdk 0.4.25 → 0.4.31
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-C9-wve7D.d.cts → browser-CsCYLnPh.d.cts} +501 -45
- package/dist/{browser-C9-wve7D.d.ts → browser-CsCYLnPh.d.ts} +501 -45
- package/dist/browser.cjs +176 -67
- 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 +176 -67
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +182 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -335
- package/dist/index.d.ts +4 -335
- package/dist/index.js +182 -68
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -3514,19 +3514,21 @@ function apiErrorDetail(apiError) {
|
|
|
3514
3514
|
return detailText(body.detail) || (typeof body.message === "string" ? body.message : void 0);
|
|
3515
3515
|
}
|
|
3516
3516
|
var ArbiApiError = class extends ArbiError {
|
|
3517
|
+
status;
|
|
3517
3518
|
apiError;
|
|
3518
3519
|
/** Why the server refused, in its words (e.g. "run_at must be in the future"), when it said. */
|
|
3519
3520
|
detail;
|
|
3520
|
-
constructor(message, apiError) {
|
|
3521
|
+
constructor(message, apiError, status) {
|
|
3521
3522
|
super(message);
|
|
3522
3523
|
this.name = "ArbiApiError";
|
|
3523
3524
|
this.apiError = apiError;
|
|
3525
|
+
this.status = status;
|
|
3524
3526
|
this.detail = apiErrorDetail(apiError);
|
|
3525
3527
|
}
|
|
3526
3528
|
};
|
|
3527
3529
|
function requireData(result, message) {
|
|
3528
3530
|
if (result.error || !result.data) {
|
|
3529
|
-
throw new ArbiApiError(message, result.error);
|
|
3531
|
+
throw new ArbiApiError(message, result.error, result.response?.status);
|
|
3530
3532
|
}
|
|
3531
3533
|
return result.data;
|
|
3532
3534
|
}
|
|
@@ -5422,6 +5424,7 @@ __export(assistant_exports, {
|
|
|
5422
5424
|
buildRetrievalChunkTool: () => buildRetrievalChunkTool,
|
|
5423
5425
|
buildRetrievalFullContextTool: () => buildRetrievalFullContextTool,
|
|
5424
5426
|
buildRetrievalTocTool: () => buildRetrievalTocTool,
|
|
5427
|
+
cancelAssistantRun: () => cancelAssistantRun,
|
|
5425
5428
|
filterSkills: () => filterSkills,
|
|
5426
5429
|
listCommands: () => listCommands,
|
|
5427
5430
|
listSkills: () => listSkills,
|
|
@@ -5497,6 +5500,9 @@ async function queryAssistant(options) {
|
|
|
5497
5500
|
question,
|
|
5498
5501
|
docIds,
|
|
5499
5502
|
previousResponseId,
|
|
5503
|
+
conversationId,
|
|
5504
|
+
assistantMode,
|
|
5505
|
+
agentId,
|
|
5500
5506
|
model,
|
|
5501
5507
|
mentions,
|
|
5502
5508
|
signal,
|
|
@@ -5507,14 +5513,17 @@ async function queryAssistant(options) {
|
|
|
5507
5513
|
input: question,
|
|
5508
5514
|
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
5509
5515
|
workspace_ext_id: workspaceId,
|
|
5516
|
+
...agentId ? { agent_ext_id: agentId } : {},
|
|
5510
5517
|
stream: true,
|
|
5511
5518
|
background: false,
|
|
5512
5519
|
store: true,
|
|
5513
|
-
tools: {
|
|
5520
|
+
tools: agentId ? {} : {
|
|
5514
5521
|
retrieval_chunk: buildRetrievalChunkTool(docIds),
|
|
5515
5522
|
retrieval_full_context: buildRetrievalFullContextTool([])
|
|
5516
5523
|
},
|
|
5517
5524
|
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
5525
|
+
...conversationId ? { conversation_ext_id: conversationId } : {},
|
|
5526
|
+
...assistantMode ? { assistant_mode: assistantMode } : {},
|
|
5518
5527
|
...model ? { model } : {},
|
|
5519
5528
|
...mentions && mentions.length > 0 ? { mentions } : {}
|
|
5520
5529
|
};
|
|
@@ -5576,6 +5585,91 @@ function filterSkills(items, query, pinned = []) {
|
|
|
5576
5585
|
});
|
|
5577
5586
|
return matched;
|
|
5578
5587
|
}
|
|
5588
|
+
async function cancelAssistantRun(auth, responseId) {
|
|
5589
|
+
await authenticatedFetch({
|
|
5590
|
+
...auth,
|
|
5591
|
+
path: `/v1/assistant/run/${encodeURIComponent(responseId)}/cancel`,
|
|
5592
|
+
method: "POST"
|
|
5593
|
+
});
|
|
5594
|
+
}
|
|
5595
|
+
|
|
5596
|
+
// src/operations/responses.ts
|
|
5597
|
+
var responses_exports = {};
|
|
5598
|
+
__export(responses_exports, {
|
|
5599
|
+
extractResponseText: () => extractResponseText,
|
|
5600
|
+
getResponse: () => getResponse,
|
|
5601
|
+
submitBackgroundQuery: () => submitBackgroundQuery
|
|
5602
|
+
});
|
|
5603
|
+
async function submitBackgroundQuery(options) {
|
|
5604
|
+
const {
|
|
5605
|
+
workspaceId,
|
|
5606
|
+
question,
|
|
5607
|
+
docIds,
|
|
5608
|
+
previousResponseId,
|
|
5609
|
+
model,
|
|
5610
|
+
task,
|
|
5611
|
+
conversationId,
|
|
5612
|
+
mentions,
|
|
5613
|
+
activeArtifactExtId,
|
|
5614
|
+
...auth
|
|
5615
|
+
} = options;
|
|
5616
|
+
const tools = {};
|
|
5617
|
+
if (docIds.length > 0) {
|
|
5618
|
+
tools.retrieval_chunk = {
|
|
5619
|
+
name: "retrieval_chunk",
|
|
5620
|
+
description: "retrieval chunk",
|
|
5621
|
+
tool_args: { doc_ext_ids: docIds },
|
|
5622
|
+
tool_responses: {}
|
|
5623
|
+
};
|
|
5624
|
+
tools.retrieval_full_context = {
|
|
5625
|
+
name: "retrieval_full_context",
|
|
5626
|
+
description: "retrieval full context",
|
|
5627
|
+
tool_args: { doc_ext_ids: docIds },
|
|
5628
|
+
tool_responses: {}
|
|
5629
|
+
};
|
|
5630
|
+
}
|
|
5631
|
+
const body = {
|
|
5632
|
+
input: question,
|
|
5633
|
+
workspace_ext_id: workspaceId,
|
|
5634
|
+
stream: false,
|
|
5635
|
+
background: true,
|
|
5636
|
+
store: true,
|
|
5637
|
+
tools,
|
|
5638
|
+
...task !== void 0 ? { task } : {},
|
|
5639
|
+
...conversationId ? { conversation_ext_id: conversationId } : {},
|
|
5640
|
+
...mentions !== void 0 ? { mentions } : {},
|
|
5641
|
+
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
5642
|
+
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
5643
|
+
...model ? { model } : {}
|
|
5644
|
+
};
|
|
5645
|
+
const res = await authenticatedFetch({
|
|
5646
|
+
...auth,
|
|
5647
|
+
path: "/v1/responses",
|
|
5648
|
+
method: "POST",
|
|
5649
|
+
body: JSON.stringify(body),
|
|
5650
|
+
headers: { "Content-Type": "application/json" }
|
|
5651
|
+
});
|
|
5652
|
+
return await res.json();
|
|
5653
|
+
}
|
|
5654
|
+
async function getResponse(auth, responseId) {
|
|
5655
|
+
const res = await authenticatedFetch({
|
|
5656
|
+
...auth,
|
|
5657
|
+
path: `/v1/responses/${responseId}`,
|
|
5658
|
+
method: "GET"
|
|
5659
|
+
});
|
|
5660
|
+
return await res.json();
|
|
5661
|
+
}
|
|
5662
|
+
function extractResponseText(response) {
|
|
5663
|
+
const parts = [];
|
|
5664
|
+
for (const msg of response.output) {
|
|
5665
|
+
for (const item of msg.content) {
|
|
5666
|
+
if ("type" in item && item.type === "output_text" && "text" in item) {
|
|
5667
|
+
parts.push(item.text);
|
|
5668
|
+
}
|
|
5669
|
+
}
|
|
5670
|
+
}
|
|
5671
|
+
return parts.join("");
|
|
5672
|
+
}
|
|
5579
5673
|
|
|
5580
5674
|
// src/operations/tags.ts
|
|
5581
5675
|
var tags_exports = {};
|
|
@@ -5720,12 +5814,17 @@ __export(dm_exports, {
|
|
|
5720
5814
|
var agents_exports = {};
|
|
5721
5815
|
__export(agents_exports, {
|
|
5722
5816
|
authorizeAgent: () => authorizeAgent,
|
|
5817
|
+
closeAgentSession: () => closeAgentSession,
|
|
5723
5818
|
createAgent: () => createAgent,
|
|
5724
5819
|
deleteAgents: () => deleteAgents,
|
|
5725
5820
|
getAgentConfig: () => getAgentConfig,
|
|
5821
|
+
getAgentSession: () => getAgentSession,
|
|
5726
5822
|
getAuthorizeLimits: () => getAuthorizeLimits,
|
|
5823
|
+
listAgentChats: () => listAgentChats,
|
|
5727
5824
|
listAgentWorkspaces: () => listAgentWorkspaces,
|
|
5728
|
-
listAgents: () => listAgents
|
|
5825
|
+
listAgents: () => listAgents,
|
|
5826
|
+
stageAgentFile: () => stageAgentFile,
|
|
5827
|
+
startAgentSession: () => startAgentSession
|
|
5729
5828
|
});
|
|
5730
5829
|
async function listAgents(arbi) {
|
|
5731
5830
|
return requireData(await arbi.fetch.GET("/v1/agents"), "Failed to fetch agents");
|
|
@@ -5773,6 +5872,48 @@ async function getAuthorizeLimits(arbi) {
|
|
|
5773
5872
|
"Failed to fetch authorize limits"
|
|
5774
5873
|
);
|
|
5775
5874
|
}
|
|
5875
|
+
async function getAgentSession(arbi, agentId) {
|
|
5876
|
+
return requireData(
|
|
5877
|
+
await arbi.fetch.GET("/v1/agents/{agent_ext_id}/session", {
|
|
5878
|
+
params: { path: { agent_ext_id: agentId } }
|
|
5879
|
+
}),
|
|
5880
|
+
"Failed to read agent session"
|
|
5881
|
+
);
|
|
5882
|
+
}
|
|
5883
|
+
async function startAgentSession(arbi, agentId, workspaceId) {
|
|
5884
|
+
return requireData(
|
|
5885
|
+
await arbi.fetch.POST("/v1/agents/{agent_ext_id}/session", {
|
|
5886
|
+
params: { path: { agent_ext_id: agentId } },
|
|
5887
|
+
body: { workspace_ext_id: workspaceId ?? null }
|
|
5888
|
+
}),
|
|
5889
|
+
"Failed to start agent session"
|
|
5890
|
+
);
|
|
5891
|
+
}
|
|
5892
|
+
async function closeAgentSession(arbi, agentId) {
|
|
5893
|
+
const { error } = await arbi.fetch.DELETE("/v1/agents/{agent_ext_id}/session", {
|
|
5894
|
+
params: { path: { agent_ext_id: agentId } }
|
|
5895
|
+
});
|
|
5896
|
+
if (error) throw new Error("Failed to close agent session");
|
|
5897
|
+
}
|
|
5898
|
+
async function listAgentChats(arbi, agentId) {
|
|
5899
|
+
return requireData(
|
|
5900
|
+
await arbi.fetch.GET("/v1/agents/{agent_ext_id}/chats", {
|
|
5901
|
+
params: { path: { agent_ext_id: agentId } }
|
|
5902
|
+
}),
|
|
5903
|
+
"Failed to read agent chats"
|
|
5904
|
+
);
|
|
5905
|
+
}
|
|
5906
|
+
async function stageAgentFile(auth, agentId, file, name) {
|
|
5907
|
+
const body = new FormData();
|
|
5908
|
+
body.append("file", file, name);
|
|
5909
|
+
const response = await authenticatedFetch({
|
|
5910
|
+
...auth,
|
|
5911
|
+
path: `/v1/agents/${encodeURIComponent(agentId)}/files`,
|
|
5912
|
+
method: "POST",
|
|
5913
|
+
body
|
|
5914
|
+
});
|
|
5915
|
+
return response.json();
|
|
5916
|
+
}
|
|
5776
5917
|
|
|
5777
5918
|
// src/operations/dm.ts
|
|
5778
5919
|
function createDmCryptoContext(arbi, signingPrivateKeyBytes, userExtId) {
|
|
@@ -6482,6 +6623,18 @@ var Arbi = class {
|
|
|
6482
6623
|
this.loginResult = await client.auth.loginWithKey({ email, signingPrivateKey });
|
|
6483
6624
|
this.userProfile = this.loginResult.profile ?? null;
|
|
6484
6625
|
}
|
|
6626
|
+
/** Recover browser authentication using the encrypted signing key already in IndexedDB. */
|
|
6627
|
+
async restoreSession(email) {
|
|
6628
|
+
const client = await this.init();
|
|
6629
|
+
const saved = await client.storage.getSession();
|
|
6630
|
+
if (!saved?.signingPrivateKey) return false;
|
|
6631
|
+
this.loginResult = await client.auth.loginWithKey({
|
|
6632
|
+
email,
|
|
6633
|
+
signingPrivateKey: saved.signingPrivateKey
|
|
6634
|
+
});
|
|
6635
|
+
this.userProfile = this.loginResult.profile ?? null;
|
|
6636
|
+
return true;
|
|
6637
|
+
}
|
|
6485
6638
|
/** A workspace's key, sealed to the caller's own session (what `/open` and `POST /workspace/users` take). */
|
|
6486
6639
|
async sealWorkspaceKey(workspaceId) {
|
|
6487
6640
|
const client = this.requireClient();
|
|
@@ -6929,19 +7082,38 @@ var Arbi = class {
|
|
|
6929
7082
|
};
|
|
6930
7083
|
// ── Assistant ─────────────────────────────────────────────────────────
|
|
6931
7084
|
assistant = {
|
|
7085
|
+
cancelRun: (responseId) => this.recovering(() => cancelAssistantRun(this.getAuthHeaders(), responseId)),
|
|
7086
|
+
/** Start a durable background turn; task options make its thread a reviewable work item. */
|
|
7087
|
+
submit: (question, options) => {
|
|
7088
|
+
const workspaceId = this.requireWorkspace();
|
|
7089
|
+
return this.recovering(
|
|
7090
|
+
() => submitBackgroundQuery({
|
|
7091
|
+
...this.getAuthHeaders(),
|
|
7092
|
+
...options,
|
|
7093
|
+
workspaceId,
|
|
7094
|
+
question
|
|
7095
|
+
})
|
|
7096
|
+
);
|
|
7097
|
+
},
|
|
7098
|
+
/** Read the status of a background turn. */
|
|
7099
|
+
getResponse: (id) => this.recovering(() => getResponse(this.getAuthHeaders(), id)),
|
|
6932
7100
|
/**
|
|
6933
7101
|
* Send a question to the RAG assistant with streaming support.
|
|
6934
7102
|
* Returns the accumulated result after the stream completes.
|
|
6935
7103
|
*/
|
|
6936
7104
|
query: async (question, options) => {
|
|
6937
|
-
const workspaceId = this.requireWorkspace();
|
|
7105
|
+
const workspaceId = options.workspaceId ?? this.requireWorkspace();
|
|
6938
7106
|
const response = await this.recovering(
|
|
6939
7107
|
() => queryAssistant({
|
|
6940
7108
|
...this.getAuthHeaders(),
|
|
6941
7109
|
workspaceId,
|
|
6942
7110
|
question,
|
|
7111
|
+
agentId: options.agentId,
|
|
6943
7112
|
docIds: options.docIds,
|
|
6944
7113
|
previousResponseId: options.previousResponseId,
|
|
7114
|
+
conversationId: options.conversationId,
|
|
7115
|
+
assistantMode: options.assistantMode,
|
|
7116
|
+
mentions: options.mentions,
|
|
6945
7117
|
model: options.model,
|
|
6946
7118
|
activeArtifactExtId: options.activeArtifactExtId,
|
|
6947
7119
|
signal: options.signal
|
|
@@ -7119,6 +7291,11 @@ var Arbi = class {
|
|
|
7119
7291
|
};
|
|
7120
7292
|
// ── Agents ──────────────────────────────────────────────────────────
|
|
7121
7293
|
agents = {
|
|
7294
|
+
getSession: (agentId) => getAgentSession(this.requireClient(), agentId),
|
|
7295
|
+
startSession: (agentId, workspaceId) => startAgentSession(this.requireClient(), agentId, workspaceId),
|
|
7296
|
+
closeSession: (agentId) => closeAgentSession(this.requireClient(), agentId),
|
|
7297
|
+
listChats: (agentId) => listAgentChats(this.requireClient(), agentId),
|
|
7298
|
+
stageFile: (agentId, file, name) => this.recovering(() => stageAgentFile(this.getAuthHeaders(), agentId, file, name)),
|
|
7122
7299
|
list: () => listAgents(this.requireClient()),
|
|
7123
7300
|
create: (name) => createAgent(this.requireClient(), name),
|
|
7124
7301
|
getConfig: (agentExtId) => getAgentConfig(this.requireClient(), agentExtId),
|
|
@@ -7950,69 +8127,6 @@ async function uploadArchive(auth, archivePath, options) {
|
|
|
7950
8127
|
}
|
|
7951
8128
|
}
|
|
7952
8129
|
|
|
7953
|
-
// src/operations/responses.ts
|
|
7954
|
-
var responses_exports = {};
|
|
7955
|
-
__export(responses_exports, {
|
|
7956
|
-
extractResponseText: () => extractResponseText,
|
|
7957
|
-
getResponse: () => getResponse,
|
|
7958
|
-
submitBackgroundQuery: () => submitBackgroundQuery
|
|
7959
|
-
});
|
|
7960
|
-
async function submitBackgroundQuery(options) {
|
|
7961
|
-
const { workspaceId, question, docIds, previousResponseId, model, ...auth } = options;
|
|
7962
|
-
const tools = {};
|
|
7963
|
-
if (docIds.length > 0) {
|
|
7964
|
-
tools.retrieval_chunk = {
|
|
7965
|
-
name: "retrieval_chunk",
|
|
7966
|
-
description: "retrieval chunk",
|
|
7967
|
-
tool_args: { doc_ext_ids: docIds },
|
|
7968
|
-
tool_responses: {}
|
|
7969
|
-
};
|
|
7970
|
-
tools.retrieval_full_context = {
|
|
7971
|
-
name: "retrieval_full_context",
|
|
7972
|
-
description: "retrieval full context",
|
|
7973
|
-
tool_args: { doc_ext_ids: [] },
|
|
7974
|
-
tool_responses: {}
|
|
7975
|
-
};
|
|
7976
|
-
}
|
|
7977
|
-
const body = {
|
|
7978
|
-
input: question,
|
|
7979
|
-
workspace_ext_id: workspaceId,
|
|
7980
|
-
stream: false,
|
|
7981
|
-
background: true,
|
|
7982
|
-
store: true,
|
|
7983
|
-
tools,
|
|
7984
|
-
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
7985
|
-
...model ? { model } : {}
|
|
7986
|
-
};
|
|
7987
|
-
const res = await authenticatedFetch({
|
|
7988
|
-
...auth,
|
|
7989
|
-
path: "/v1/responses",
|
|
7990
|
-
method: "POST",
|
|
7991
|
-
body: JSON.stringify(body),
|
|
7992
|
-
headers: { "Content-Type": "application/json" }
|
|
7993
|
-
});
|
|
7994
|
-
return await res.json();
|
|
7995
|
-
}
|
|
7996
|
-
async function getResponse(auth, responseId) {
|
|
7997
|
-
const res = await authenticatedFetch({
|
|
7998
|
-
...auth,
|
|
7999
|
-
path: `/v1/responses/${responseId}`,
|
|
8000
|
-
method: "GET"
|
|
8001
|
-
});
|
|
8002
|
-
return await res.json();
|
|
8003
|
-
}
|
|
8004
|
-
function extractResponseText(response) {
|
|
8005
|
-
const parts = [];
|
|
8006
|
-
for (const msg of response.output) {
|
|
8007
|
-
for (const item of msg.content) {
|
|
8008
|
-
if ("type" in item && item.type === "output_text" && "text" in item) {
|
|
8009
|
-
parts.push(item.text);
|
|
8010
|
-
}
|
|
8011
|
-
}
|
|
8012
|
-
}
|
|
8013
|
-
return parts.join("");
|
|
8014
|
-
}
|
|
8015
|
-
|
|
8016
8130
|
// src/listen/index.ts
|
|
8017
8131
|
var listen_exports = {};
|
|
8018
8132
|
__export(listen_exports, {
|