@arbidocs/sdk 0.4.20 → 0.4.29
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-DY8mQOdF.d.cts → browser-AwN8DBBO.d.cts} +556 -45
- package/dist/{browser-DY8mQOdF.d.ts → browser-AwN8DBBO.d.ts} +556 -45
- package/dist/browser.cjs +227 -70
- 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 +227 -70
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +233 -71
- 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 +233 -71
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/browser.cjs
CHANGED
|
@@ -3502,19 +3502,21 @@ function apiErrorDetail(apiError) {
|
|
|
3502
3502
|
return detailText(body.detail) || (typeof body.message === "string" ? body.message : void 0);
|
|
3503
3503
|
}
|
|
3504
3504
|
var ArbiApiError = class extends ArbiError {
|
|
3505
|
+
status;
|
|
3505
3506
|
apiError;
|
|
3506
3507
|
/** Why the server refused, in its words (e.g. "run_at must be in the future"), when it said. */
|
|
3507
3508
|
detail;
|
|
3508
|
-
constructor(message, apiError) {
|
|
3509
|
+
constructor(message, apiError, status) {
|
|
3509
3510
|
super(message);
|
|
3510
3511
|
this.name = "ArbiApiError";
|
|
3511
3512
|
this.apiError = apiError;
|
|
3513
|
+
this.status = status;
|
|
3512
3514
|
this.detail = apiErrorDetail(apiError);
|
|
3513
3515
|
}
|
|
3514
3516
|
};
|
|
3515
3517
|
function requireData(result, message) {
|
|
3516
3518
|
if (result.error || !result.data) {
|
|
3517
|
-
throw new ArbiApiError(message, result.error);
|
|
3519
|
+
throw new ArbiApiError(message, result.error, result.response?.status);
|
|
3518
3520
|
}
|
|
3519
3521
|
return result.data;
|
|
3520
3522
|
}
|
|
@@ -4873,6 +4875,7 @@ __export(assistant_exports, {
|
|
|
4873
4875
|
buildRetrievalChunkTool: () => buildRetrievalChunkTool,
|
|
4874
4876
|
buildRetrievalFullContextTool: () => buildRetrievalFullContextTool,
|
|
4875
4877
|
buildRetrievalTocTool: () => buildRetrievalTocTool,
|
|
4878
|
+
cancelAssistantRun: () => cancelAssistantRun,
|
|
4876
4879
|
filterSkills: () => filterSkills,
|
|
4877
4880
|
listCommands: () => listCommands,
|
|
4878
4881
|
listSkills: () => listSkills,
|
|
@@ -4943,18 +4946,35 @@ async function retrieve(options) {
|
|
|
4943
4946
|
return data;
|
|
4944
4947
|
}
|
|
4945
4948
|
async function queryAssistant(options) {
|
|
4946
|
-
const {
|
|
4949
|
+
const {
|
|
4950
|
+
workspaceId,
|
|
4951
|
+
question,
|
|
4952
|
+
docIds,
|
|
4953
|
+
previousResponseId,
|
|
4954
|
+
conversationId,
|
|
4955
|
+
assistantMode,
|
|
4956
|
+
agentId,
|
|
4957
|
+
model,
|
|
4958
|
+
mentions,
|
|
4959
|
+
signal,
|
|
4960
|
+
activeArtifactExtId,
|
|
4961
|
+
...auth
|
|
4962
|
+
} = options;
|
|
4947
4963
|
const body = {
|
|
4948
4964
|
input: question,
|
|
4965
|
+
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
4949
4966
|
workspace_ext_id: workspaceId,
|
|
4967
|
+
...agentId ? { agent_ext_id: agentId } : {},
|
|
4950
4968
|
stream: true,
|
|
4951
4969
|
background: false,
|
|
4952
4970
|
store: true,
|
|
4953
|
-
tools: {
|
|
4971
|
+
tools: agentId ? {} : {
|
|
4954
4972
|
retrieval_chunk: buildRetrievalChunkTool(docIds),
|
|
4955
4973
|
retrieval_full_context: buildRetrievalFullContextTool([])
|
|
4956
4974
|
},
|
|
4957
4975
|
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
4976
|
+
...conversationId ? { conversation_ext_id: conversationId } : {},
|
|
4977
|
+
...assistantMode ? { assistant_mode: assistantMode } : {},
|
|
4958
4978
|
...model ? { model } : {},
|
|
4959
4979
|
...mentions && mentions.length > 0 ? { mentions } : {}
|
|
4960
4980
|
};
|
|
@@ -5016,6 +5036,91 @@ function filterSkills(items, query, pinned = []) {
|
|
|
5016
5036
|
});
|
|
5017
5037
|
return matched;
|
|
5018
5038
|
}
|
|
5039
|
+
async function cancelAssistantRun(auth, responseId) {
|
|
5040
|
+
await authenticatedFetch({
|
|
5041
|
+
...auth,
|
|
5042
|
+
path: `/v1/assistant/run/${encodeURIComponent(responseId)}/cancel`,
|
|
5043
|
+
method: "POST"
|
|
5044
|
+
});
|
|
5045
|
+
}
|
|
5046
|
+
|
|
5047
|
+
// src/operations/responses.ts
|
|
5048
|
+
var responses_exports = {};
|
|
5049
|
+
__export(responses_exports, {
|
|
5050
|
+
extractResponseText: () => extractResponseText,
|
|
5051
|
+
getResponse: () => getResponse,
|
|
5052
|
+
submitBackgroundQuery: () => submitBackgroundQuery
|
|
5053
|
+
});
|
|
5054
|
+
async function submitBackgroundQuery(options) {
|
|
5055
|
+
const {
|
|
5056
|
+
workspaceId,
|
|
5057
|
+
question,
|
|
5058
|
+
docIds,
|
|
5059
|
+
previousResponseId,
|
|
5060
|
+
model,
|
|
5061
|
+
task,
|
|
5062
|
+
conversationId,
|
|
5063
|
+
mentions,
|
|
5064
|
+
activeArtifactExtId,
|
|
5065
|
+
...auth
|
|
5066
|
+
} = options;
|
|
5067
|
+
const tools = {};
|
|
5068
|
+
if (docIds.length > 0) {
|
|
5069
|
+
tools.retrieval_chunk = {
|
|
5070
|
+
name: "retrieval_chunk",
|
|
5071
|
+
description: "retrieval chunk",
|
|
5072
|
+
tool_args: { doc_ext_ids: docIds },
|
|
5073
|
+
tool_responses: {}
|
|
5074
|
+
};
|
|
5075
|
+
tools.retrieval_full_context = {
|
|
5076
|
+
name: "retrieval_full_context",
|
|
5077
|
+
description: "retrieval full context",
|
|
5078
|
+
tool_args: { doc_ext_ids: docIds },
|
|
5079
|
+
tool_responses: {}
|
|
5080
|
+
};
|
|
5081
|
+
}
|
|
5082
|
+
const body = {
|
|
5083
|
+
input: question,
|
|
5084
|
+
workspace_ext_id: workspaceId,
|
|
5085
|
+
stream: false,
|
|
5086
|
+
background: true,
|
|
5087
|
+
store: true,
|
|
5088
|
+
tools,
|
|
5089
|
+
...task !== void 0 ? { task } : {},
|
|
5090
|
+
...conversationId ? { conversation_ext_id: conversationId } : {},
|
|
5091
|
+
...mentions !== void 0 ? { mentions } : {},
|
|
5092
|
+
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
5093
|
+
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
5094
|
+
...model ? { model } : {}
|
|
5095
|
+
};
|
|
5096
|
+
const res = await authenticatedFetch({
|
|
5097
|
+
...auth,
|
|
5098
|
+
path: "/v1/responses",
|
|
5099
|
+
method: "POST",
|
|
5100
|
+
body: JSON.stringify(body),
|
|
5101
|
+
headers: { "Content-Type": "application/json" }
|
|
5102
|
+
});
|
|
5103
|
+
return await res.json();
|
|
5104
|
+
}
|
|
5105
|
+
async function getResponse(auth, responseId) {
|
|
5106
|
+
const res = await authenticatedFetch({
|
|
5107
|
+
...auth,
|
|
5108
|
+
path: `/v1/responses/${responseId}`,
|
|
5109
|
+
method: "GET"
|
|
5110
|
+
});
|
|
5111
|
+
return await res.json();
|
|
5112
|
+
}
|
|
5113
|
+
function extractResponseText(response) {
|
|
5114
|
+
const parts = [];
|
|
5115
|
+
for (const msg of response.output) {
|
|
5116
|
+
for (const item of msg.content) {
|
|
5117
|
+
if ("type" in item && item.type === "output_text" && "text" in item) {
|
|
5118
|
+
parts.push(item.text);
|
|
5119
|
+
}
|
|
5120
|
+
}
|
|
5121
|
+
}
|
|
5122
|
+
return parts.join("");
|
|
5123
|
+
}
|
|
5019
5124
|
|
|
5020
5125
|
// src/operations/tags.ts
|
|
5021
5126
|
var tags_exports = {};
|
|
@@ -5203,6 +5308,48 @@ async function getAuthorizeLimits(arbi) {
|
|
|
5203
5308
|
"Failed to fetch authorize limits"
|
|
5204
5309
|
);
|
|
5205
5310
|
}
|
|
5311
|
+
async function getAgentSession(arbi, agentId) {
|
|
5312
|
+
return requireData(
|
|
5313
|
+
await arbi.fetch.GET("/v1/agents/{agent_ext_id}/session", {
|
|
5314
|
+
params: { path: { agent_ext_id: agentId } }
|
|
5315
|
+
}),
|
|
5316
|
+
"Failed to read agent session"
|
|
5317
|
+
);
|
|
5318
|
+
}
|
|
5319
|
+
async function startAgentSession(arbi, agentId, workspaceId) {
|
|
5320
|
+
return requireData(
|
|
5321
|
+
await arbi.fetch.POST("/v1/agents/{agent_ext_id}/session", {
|
|
5322
|
+
params: { path: { agent_ext_id: agentId } },
|
|
5323
|
+
body: { workspace_ext_id: workspaceId ?? null }
|
|
5324
|
+
}),
|
|
5325
|
+
"Failed to start agent session"
|
|
5326
|
+
);
|
|
5327
|
+
}
|
|
5328
|
+
async function closeAgentSession(arbi, agentId) {
|
|
5329
|
+
const { error } = await arbi.fetch.DELETE("/v1/agents/{agent_ext_id}/session", {
|
|
5330
|
+
params: { path: { agent_ext_id: agentId } }
|
|
5331
|
+
});
|
|
5332
|
+
if (error) throw new Error("Failed to close agent session");
|
|
5333
|
+
}
|
|
5334
|
+
async function listAgentChats(arbi, agentId) {
|
|
5335
|
+
return requireData(
|
|
5336
|
+
await arbi.fetch.GET("/v1/agents/{agent_ext_id}/chats", {
|
|
5337
|
+
params: { path: { agent_ext_id: agentId } }
|
|
5338
|
+
}),
|
|
5339
|
+
"Failed to read agent chats"
|
|
5340
|
+
);
|
|
5341
|
+
}
|
|
5342
|
+
async function stageAgentFile(auth, agentId, file, name) {
|
|
5343
|
+
const body = new FormData();
|
|
5344
|
+
body.append("file", file, name);
|
|
5345
|
+
const response = await authenticatedFetch({
|
|
5346
|
+
...auth,
|
|
5347
|
+
path: `/v1/agents/${encodeURIComponent(agentId)}/files`,
|
|
5348
|
+
method: "POST",
|
|
5349
|
+
body
|
|
5350
|
+
});
|
|
5351
|
+
return response.json();
|
|
5352
|
+
}
|
|
5206
5353
|
|
|
5207
5354
|
// src/operations/dm.ts
|
|
5208
5355
|
function createDmCryptoContext(arbi, signingPrivateKeyBytes, userExtId) {
|
|
@@ -5312,7 +5459,9 @@ async function sendEncryptedDM(arbi, messages, crypto) {
|
|
|
5312
5459
|
}))
|
|
5313
5460
|
);
|
|
5314
5461
|
const created = requireData(
|
|
5315
|
-
await arbi.fetch.POST("/v1/notifications/", {
|
|
5462
|
+
await arbi.fetch.POST("/v1/notifications/", {
|
|
5463
|
+
body: { messages: encrypted, context_only: false }
|
|
5464
|
+
}),
|
|
5316
5465
|
"Failed to send message"
|
|
5317
5466
|
);
|
|
5318
5467
|
return created.map((n2) => ({
|
|
@@ -5345,7 +5494,7 @@ async function requestWorkspaceAccess(arbi, params, crypto) {
|
|
|
5345
5494
|
async function sendDM(arbi, messages) {
|
|
5346
5495
|
return requireData(
|
|
5347
5496
|
await arbi.fetch.POST("/v1/notifications/", {
|
|
5348
|
-
body: { messages }
|
|
5497
|
+
body: { messages, context_only: false }
|
|
5349
5498
|
}),
|
|
5350
5499
|
"Failed to send message"
|
|
5351
5500
|
);
|
|
@@ -5910,6 +6059,18 @@ var Arbi = class {
|
|
|
5910
6059
|
this.loginResult = await client.auth.loginWithKey({ email, signingPrivateKey });
|
|
5911
6060
|
this.userProfile = this.loginResult.profile ?? null;
|
|
5912
6061
|
}
|
|
6062
|
+
/** Recover browser authentication using the encrypted signing key already in IndexedDB. */
|
|
6063
|
+
async restoreSession(email) {
|
|
6064
|
+
const client = await this.init();
|
|
6065
|
+
const saved = await client.storage.getSession();
|
|
6066
|
+
if (!saved?.signingPrivateKey) return false;
|
|
6067
|
+
this.loginResult = await client.auth.loginWithKey({
|
|
6068
|
+
email,
|
|
6069
|
+
signingPrivateKey: saved.signingPrivateKey
|
|
6070
|
+
});
|
|
6071
|
+
this.userProfile = this.loginResult.profile ?? null;
|
|
6072
|
+
return true;
|
|
6073
|
+
}
|
|
5913
6074
|
/** A workspace's key, sealed to the caller's own session (what `/open` and `POST /workspace/users` take). */
|
|
5914
6075
|
async sealWorkspaceKey(workspaceId) {
|
|
5915
6076
|
const client = this.requireClient();
|
|
@@ -6321,22 +6482,76 @@ var Arbi = class {
|
|
|
6321
6482
|
assistantMode
|
|
6322
6483
|
)
|
|
6323
6484
|
};
|
|
6485
|
+
/** Persisted notifications also arrive on the normal workspace WebSocket. */
|
|
6486
|
+
notifications = {
|
|
6487
|
+
list: async (type) => {
|
|
6488
|
+
const { data, error } = await this.requireClient().fetch.GET("/v1/notifications/", {
|
|
6489
|
+
params: { query: { ...type ? { type } : {}, limit: 100 } }
|
|
6490
|
+
});
|
|
6491
|
+
if (error) throw new ArbiError("Could not load notifications");
|
|
6492
|
+
return data || [];
|
|
6493
|
+
},
|
|
6494
|
+
markRead: async (ids) => {
|
|
6495
|
+
if (!ids.length) return;
|
|
6496
|
+
const { error } = await this.requireClient().fetch.PATCH("/v1/notifications/", {
|
|
6497
|
+
body: { updates: ids.map((external_id) => ({ external_id, read: true })) }
|
|
6498
|
+
});
|
|
6499
|
+
if (error) throw new ArbiError("Could not mark notifications read");
|
|
6500
|
+
}
|
|
6501
|
+
};
|
|
6502
|
+
/** Authenticated native Word transport, with normal session recovery. */
|
|
6503
|
+
editor = {
|
|
6504
|
+
request: (path, options = {}) => this.recovering(async () => {
|
|
6505
|
+
const { baseUrl, accessToken } = this.getAuthHeaders();
|
|
6506
|
+
const headers = new Headers(options.headers);
|
|
6507
|
+
headers.set("Authorization", `Bearer ${accessToken}`);
|
|
6508
|
+
const response = await fetch(`${baseUrl}/v1/editor${path}`, { ...options, headers });
|
|
6509
|
+
if (!response.ok) {
|
|
6510
|
+
const body = await response.json().catch(() => null);
|
|
6511
|
+
throw new ArbiApiError(body?.detail || `Document request failed (${response.status})`, {
|
|
6512
|
+
status: response.status,
|
|
6513
|
+
statusText: response.statusText
|
|
6514
|
+
});
|
|
6515
|
+
}
|
|
6516
|
+
return response;
|
|
6517
|
+
})
|
|
6518
|
+
};
|
|
6324
6519
|
// ── Assistant ─────────────────────────────────────────────────────────
|
|
6325
6520
|
assistant = {
|
|
6521
|
+
cancelRun: (responseId) => this.recovering(() => cancelAssistantRun(this.getAuthHeaders(), responseId)),
|
|
6522
|
+
/** Start a durable background turn; task options make its thread a reviewable work item. */
|
|
6523
|
+
submit: (question, options) => {
|
|
6524
|
+
const workspaceId = this.requireWorkspace();
|
|
6525
|
+
return this.recovering(
|
|
6526
|
+
() => submitBackgroundQuery({
|
|
6527
|
+
...this.getAuthHeaders(),
|
|
6528
|
+
...options,
|
|
6529
|
+
workspaceId,
|
|
6530
|
+
question
|
|
6531
|
+
})
|
|
6532
|
+
);
|
|
6533
|
+
},
|
|
6534
|
+
/** Read the status of a background turn. */
|
|
6535
|
+
getResponse: (id) => this.recovering(() => getResponse(this.getAuthHeaders(), id)),
|
|
6326
6536
|
/**
|
|
6327
6537
|
* Send a question to the RAG assistant with streaming support.
|
|
6328
6538
|
* Returns the accumulated result after the stream completes.
|
|
6329
6539
|
*/
|
|
6330
6540
|
query: async (question, options) => {
|
|
6331
|
-
const workspaceId = this.requireWorkspace();
|
|
6541
|
+
const workspaceId = options.workspaceId ?? this.requireWorkspace();
|
|
6332
6542
|
const response = await this.recovering(
|
|
6333
6543
|
() => queryAssistant({
|
|
6334
6544
|
...this.getAuthHeaders(),
|
|
6335
6545
|
workspaceId,
|
|
6336
6546
|
question,
|
|
6547
|
+
agentId: options.agentId,
|
|
6337
6548
|
docIds: options.docIds,
|
|
6338
6549
|
previousResponseId: options.previousResponseId,
|
|
6550
|
+
conversationId: options.conversationId,
|
|
6551
|
+
assistantMode: options.assistantMode,
|
|
6552
|
+
mentions: options.mentions,
|
|
6339
6553
|
model: options.model,
|
|
6554
|
+
activeArtifactExtId: options.activeArtifactExtId,
|
|
6340
6555
|
signal: options.signal
|
|
6341
6556
|
})
|
|
6342
6557
|
);
|
|
@@ -6512,6 +6727,11 @@ var Arbi = class {
|
|
|
6512
6727
|
};
|
|
6513
6728
|
// ── Agents ──────────────────────────────────────────────────────────
|
|
6514
6729
|
agents = {
|
|
6730
|
+
getSession: (agentId) => getAgentSession(this.requireClient(), agentId),
|
|
6731
|
+
startSession: (agentId, workspaceId) => startAgentSession(this.requireClient(), agentId, workspaceId),
|
|
6732
|
+
closeSession: (agentId) => closeAgentSession(this.requireClient(), agentId),
|
|
6733
|
+
listChats: (agentId) => listAgentChats(this.requireClient(), agentId),
|
|
6734
|
+
stageFile: (agentId, file, name) => this.recovering(() => stageAgentFile(this.getAuthHeaders(), agentId, file, name)),
|
|
6515
6735
|
list: () => listAgents(this.requireClient()),
|
|
6516
6736
|
create: (name) => createAgent(this.requireClient(), name),
|
|
6517
6737
|
getConfig: (agentExtId) => getAgentConfig(this.requireClient(), agentExtId),
|
|
@@ -6598,69 +6818,6 @@ var Arbi = class {
|
|
|
6598
6818
|
}
|
|
6599
6819
|
};
|
|
6600
6820
|
|
|
6601
|
-
// src/operations/responses.ts
|
|
6602
|
-
var responses_exports = {};
|
|
6603
|
-
__export(responses_exports, {
|
|
6604
|
-
extractResponseText: () => extractResponseText,
|
|
6605
|
-
getResponse: () => getResponse,
|
|
6606
|
-
submitBackgroundQuery: () => submitBackgroundQuery
|
|
6607
|
-
});
|
|
6608
|
-
async function submitBackgroundQuery(options) {
|
|
6609
|
-
const { workspaceId, question, docIds, previousResponseId, model, ...auth } = options;
|
|
6610
|
-
const tools = {};
|
|
6611
|
-
if (docIds.length > 0) {
|
|
6612
|
-
tools.retrieval_chunk = {
|
|
6613
|
-
name: "retrieval_chunk",
|
|
6614
|
-
description: "retrieval chunk",
|
|
6615
|
-
tool_args: { doc_ext_ids: docIds },
|
|
6616
|
-
tool_responses: {}
|
|
6617
|
-
};
|
|
6618
|
-
tools.retrieval_full_context = {
|
|
6619
|
-
name: "retrieval_full_context",
|
|
6620
|
-
description: "retrieval full context",
|
|
6621
|
-
tool_args: { doc_ext_ids: [] },
|
|
6622
|
-
tool_responses: {}
|
|
6623
|
-
};
|
|
6624
|
-
}
|
|
6625
|
-
const body = {
|
|
6626
|
-
input: question,
|
|
6627
|
-
workspace_ext_id: workspaceId,
|
|
6628
|
-
stream: false,
|
|
6629
|
-
background: true,
|
|
6630
|
-
store: true,
|
|
6631
|
-
tools,
|
|
6632
|
-
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
6633
|
-
...model ? { model } : {}
|
|
6634
|
-
};
|
|
6635
|
-
const res = await authenticatedFetch({
|
|
6636
|
-
...auth,
|
|
6637
|
-
path: "/v1/responses",
|
|
6638
|
-
method: "POST",
|
|
6639
|
-
body: JSON.stringify(body),
|
|
6640
|
-
headers: { "Content-Type": "application/json" }
|
|
6641
|
-
});
|
|
6642
|
-
return await res.json();
|
|
6643
|
-
}
|
|
6644
|
-
async function getResponse(auth, responseId) {
|
|
6645
|
-
const res = await authenticatedFetch({
|
|
6646
|
-
...auth,
|
|
6647
|
-
path: `/v1/responses/${responseId}`,
|
|
6648
|
-
method: "GET"
|
|
6649
|
-
});
|
|
6650
|
-
return await res.json();
|
|
6651
|
-
}
|
|
6652
|
-
function extractResponseText(response) {
|
|
6653
|
-
const parts = [];
|
|
6654
|
-
for (const msg of response.output) {
|
|
6655
|
-
for (const item of msg.content) {
|
|
6656
|
-
if ("type" in item && item.type === "output_text" && "text" in item) {
|
|
6657
|
-
parts.push(item.text);
|
|
6658
|
-
}
|
|
6659
|
-
}
|
|
6660
|
-
}
|
|
6661
|
-
return parts.join("");
|
|
6662
|
-
}
|
|
6663
|
-
|
|
6664
6821
|
exports.Arbi = Arbi;
|
|
6665
6822
|
exports.ArbiApiError = ArbiApiError;
|
|
6666
6823
|
exports.ArbiError = ArbiError;
|