@arbidocs/sdk 0.4.25 → 0.4.28

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/index.js CHANGED
@@ -3505,19 +3505,21 @@ function apiErrorDetail(apiError) {
3505
3505
  return detailText(body.detail) || (typeof body.message === "string" ? body.message : void 0);
3506
3506
  }
3507
3507
  var ArbiApiError = class extends ArbiError {
3508
+ status;
3508
3509
  apiError;
3509
3510
  /** Why the server refused, in its words (e.g. "run_at must be in the future"), when it said. */
3510
3511
  detail;
3511
- constructor(message, apiError) {
3512
+ constructor(message, apiError, status) {
3512
3513
  super(message);
3513
3514
  this.name = "ArbiApiError";
3514
3515
  this.apiError = apiError;
3516
+ this.status = status;
3515
3517
  this.detail = apiErrorDetail(apiError);
3516
3518
  }
3517
3519
  };
3518
3520
  function requireData(result, message) {
3519
3521
  if (result.error || !result.data) {
3520
- throw new ArbiApiError(message, result.error);
3522
+ throw new ArbiApiError(message, result.error, result.response?.status);
3521
3523
  }
3522
3524
  return result.data;
3523
3525
  }
@@ -5413,6 +5415,7 @@ __export(assistant_exports, {
5413
5415
  buildRetrievalChunkTool: () => buildRetrievalChunkTool,
5414
5416
  buildRetrievalFullContextTool: () => buildRetrievalFullContextTool,
5415
5417
  buildRetrievalTocTool: () => buildRetrievalTocTool,
5418
+ cancelAssistantRun: () => cancelAssistantRun,
5416
5419
  filterSkills: () => filterSkills,
5417
5420
  listCommands: () => listCommands,
5418
5421
  listSkills: () => listSkills,
@@ -5488,6 +5491,9 @@ async function queryAssistant(options) {
5488
5491
  question,
5489
5492
  docIds,
5490
5493
  previousResponseId,
5494
+ conversationId,
5495
+ assistantMode,
5496
+ agentId,
5491
5497
  model,
5492
5498
  mentions,
5493
5499
  signal,
@@ -5498,14 +5504,17 @@ async function queryAssistant(options) {
5498
5504
  input: question,
5499
5505
  ...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
5500
5506
  workspace_ext_id: workspaceId,
5507
+ ...agentId ? { agent_ext_id: agentId } : {},
5501
5508
  stream: true,
5502
5509
  background: false,
5503
5510
  store: true,
5504
- tools: {
5511
+ tools: agentId ? {} : {
5505
5512
  retrieval_chunk: buildRetrievalChunkTool(docIds),
5506
5513
  retrieval_full_context: buildRetrievalFullContextTool([])
5507
5514
  },
5508
5515
  ...previousResponseId ? { previous_response_id: previousResponseId } : {},
5516
+ ...conversationId ? { conversation_ext_id: conversationId } : {},
5517
+ ...assistantMode ? { assistant_mode: assistantMode } : {},
5509
5518
  ...model ? { model } : {},
5510
5519
  ...mentions && mentions.length > 0 ? { mentions } : {}
5511
5520
  };
@@ -5567,6 +5576,91 @@ function filterSkills(items, query, pinned = []) {
5567
5576
  });
5568
5577
  return matched;
5569
5578
  }
5579
+ async function cancelAssistantRun(auth, responseId) {
5580
+ await authenticatedFetch({
5581
+ ...auth,
5582
+ path: `/v1/assistant/run/${encodeURIComponent(responseId)}/cancel`,
5583
+ method: "POST"
5584
+ });
5585
+ }
5586
+
5587
+ // src/operations/responses.ts
5588
+ var responses_exports = {};
5589
+ __export(responses_exports, {
5590
+ extractResponseText: () => extractResponseText,
5591
+ getResponse: () => getResponse,
5592
+ submitBackgroundQuery: () => submitBackgroundQuery
5593
+ });
5594
+ async function submitBackgroundQuery(options) {
5595
+ const {
5596
+ workspaceId,
5597
+ question,
5598
+ docIds,
5599
+ previousResponseId,
5600
+ model,
5601
+ task,
5602
+ conversationId,
5603
+ mentions,
5604
+ activeArtifactExtId,
5605
+ ...auth
5606
+ } = options;
5607
+ const tools = {};
5608
+ if (docIds.length > 0) {
5609
+ tools.retrieval_chunk = {
5610
+ name: "retrieval_chunk",
5611
+ description: "retrieval chunk",
5612
+ tool_args: { doc_ext_ids: docIds },
5613
+ tool_responses: {}
5614
+ };
5615
+ tools.retrieval_full_context = {
5616
+ name: "retrieval_full_context",
5617
+ description: "retrieval full context",
5618
+ tool_args: { doc_ext_ids: docIds },
5619
+ tool_responses: {}
5620
+ };
5621
+ }
5622
+ const body = {
5623
+ input: question,
5624
+ workspace_ext_id: workspaceId,
5625
+ stream: false,
5626
+ background: true,
5627
+ store: true,
5628
+ tools,
5629
+ ...task !== void 0 ? { task } : {},
5630
+ ...conversationId ? { conversation_ext_id: conversationId } : {},
5631
+ ...mentions !== void 0 ? { mentions } : {},
5632
+ ...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
5633
+ ...previousResponseId ? { previous_response_id: previousResponseId } : {},
5634
+ ...model ? { model } : {}
5635
+ };
5636
+ const res = await authenticatedFetch({
5637
+ ...auth,
5638
+ path: "/v1/responses",
5639
+ method: "POST",
5640
+ body: JSON.stringify(body),
5641
+ headers: { "Content-Type": "application/json" }
5642
+ });
5643
+ return await res.json();
5644
+ }
5645
+ async function getResponse(auth, responseId) {
5646
+ const res = await authenticatedFetch({
5647
+ ...auth,
5648
+ path: `/v1/responses/${responseId}`,
5649
+ method: "GET"
5650
+ });
5651
+ return await res.json();
5652
+ }
5653
+ function extractResponseText(response) {
5654
+ const parts = [];
5655
+ for (const msg of response.output) {
5656
+ for (const item of msg.content) {
5657
+ if ("type" in item && item.type === "output_text" && "text" in item) {
5658
+ parts.push(item.text);
5659
+ }
5660
+ }
5661
+ }
5662
+ return parts.join("");
5663
+ }
5570
5664
 
5571
5665
  // src/operations/tags.ts
5572
5666
  var tags_exports = {};
@@ -5711,12 +5805,17 @@ __export(dm_exports, {
5711
5805
  var agents_exports = {};
5712
5806
  __export(agents_exports, {
5713
5807
  authorizeAgent: () => authorizeAgent,
5808
+ closeAgentSession: () => closeAgentSession,
5714
5809
  createAgent: () => createAgent,
5715
5810
  deleteAgents: () => deleteAgents,
5716
5811
  getAgentConfig: () => getAgentConfig,
5812
+ getAgentSession: () => getAgentSession,
5717
5813
  getAuthorizeLimits: () => getAuthorizeLimits,
5814
+ listAgentChats: () => listAgentChats,
5718
5815
  listAgentWorkspaces: () => listAgentWorkspaces,
5719
- listAgents: () => listAgents
5816
+ listAgents: () => listAgents,
5817
+ stageAgentFile: () => stageAgentFile,
5818
+ startAgentSession: () => startAgentSession
5720
5819
  });
5721
5820
  async function listAgents(arbi) {
5722
5821
  return requireData(await arbi.fetch.GET("/v1/agents"), "Failed to fetch agents");
@@ -5764,6 +5863,48 @@ async function getAuthorizeLimits(arbi) {
5764
5863
  "Failed to fetch authorize limits"
5765
5864
  );
5766
5865
  }
5866
+ async function getAgentSession(arbi, agentId) {
5867
+ return requireData(
5868
+ await arbi.fetch.GET("/v1/agents/{agent_ext_id}/session", {
5869
+ params: { path: { agent_ext_id: agentId } }
5870
+ }),
5871
+ "Failed to read agent session"
5872
+ );
5873
+ }
5874
+ async function startAgentSession(arbi, agentId, workspaceId) {
5875
+ return requireData(
5876
+ await arbi.fetch.POST("/v1/agents/{agent_ext_id}/session", {
5877
+ params: { path: { agent_ext_id: agentId } },
5878
+ body: { workspace_ext_id: workspaceId ?? null }
5879
+ }),
5880
+ "Failed to start agent session"
5881
+ );
5882
+ }
5883
+ async function closeAgentSession(arbi, agentId) {
5884
+ const { error } = await arbi.fetch.DELETE("/v1/agents/{agent_ext_id}/session", {
5885
+ params: { path: { agent_ext_id: agentId } }
5886
+ });
5887
+ if (error) throw new Error("Failed to close agent session");
5888
+ }
5889
+ async function listAgentChats(arbi, agentId) {
5890
+ return requireData(
5891
+ await arbi.fetch.GET("/v1/agents/{agent_ext_id}/chats", {
5892
+ params: { path: { agent_ext_id: agentId } }
5893
+ }),
5894
+ "Failed to read agent chats"
5895
+ );
5896
+ }
5897
+ async function stageAgentFile(auth, agentId, file, name) {
5898
+ const body = new FormData();
5899
+ body.append("file", file, name);
5900
+ const response = await authenticatedFetch({
5901
+ ...auth,
5902
+ path: `/v1/agents/${encodeURIComponent(agentId)}/files`,
5903
+ method: "POST",
5904
+ body
5905
+ });
5906
+ return response.json();
5907
+ }
5767
5908
 
5768
5909
  // src/operations/dm.ts
5769
5910
  function createDmCryptoContext(arbi, signingPrivateKeyBytes, userExtId) {
@@ -6473,6 +6614,18 @@ var Arbi = class {
6473
6614
  this.loginResult = await client.auth.loginWithKey({ email, signingPrivateKey });
6474
6615
  this.userProfile = this.loginResult.profile ?? null;
6475
6616
  }
6617
+ /** Recover browser authentication using the encrypted signing key already in IndexedDB. */
6618
+ async restoreSession(email) {
6619
+ const client = await this.init();
6620
+ const saved = await client.storage.getSession();
6621
+ if (!saved?.signingPrivateKey) return false;
6622
+ this.loginResult = await client.auth.loginWithKey({
6623
+ email,
6624
+ signingPrivateKey: saved.signingPrivateKey
6625
+ });
6626
+ this.userProfile = this.loginResult.profile ?? null;
6627
+ return true;
6628
+ }
6476
6629
  /** A workspace's key, sealed to the caller's own session (what `/open` and `POST /workspace/users` take). */
6477
6630
  async sealWorkspaceKey(workspaceId) {
6478
6631
  const client = this.requireClient();
@@ -6920,19 +7073,38 @@ var Arbi = class {
6920
7073
  };
6921
7074
  // ── Assistant ─────────────────────────────────────────────────────────
6922
7075
  assistant = {
7076
+ cancelRun: (responseId) => this.recovering(() => cancelAssistantRun(this.getAuthHeaders(), responseId)),
7077
+ /** Start a durable background turn; task options make its thread a reviewable work item. */
7078
+ submit: (question, options) => {
7079
+ const workspaceId = this.requireWorkspace();
7080
+ return this.recovering(
7081
+ () => submitBackgroundQuery({
7082
+ ...this.getAuthHeaders(),
7083
+ ...options,
7084
+ workspaceId,
7085
+ question
7086
+ })
7087
+ );
7088
+ },
7089
+ /** Read the status of a background turn. */
7090
+ getResponse: (id) => this.recovering(() => getResponse(this.getAuthHeaders(), id)),
6923
7091
  /**
6924
7092
  * Send a question to the RAG assistant with streaming support.
6925
7093
  * Returns the accumulated result after the stream completes.
6926
7094
  */
6927
7095
  query: async (question, options) => {
6928
- const workspaceId = this.requireWorkspace();
7096
+ const workspaceId = options.workspaceId ?? this.requireWorkspace();
6929
7097
  const response = await this.recovering(
6930
7098
  () => queryAssistant({
6931
7099
  ...this.getAuthHeaders(),
6932
7100
  workspaceId,
6933
7101
  question,
7102
+ agentId: options.agentId,
6934
7103
  docIds: options.docIds,
6935
7104
  previousResponseId: options.previousResponseId,
7105
+ conversationId: options.conversationId,
7106
+ assistantMode: options.assistantMode,
7107
+ mentions: options.mentions,
6936
7108
  model: options.model,
6937
7109
  activeArtifactExtId: options.activeArtifactExtId,
6938
7110
  signal: options.signal
@@ -7110,6 +7282,11 @@ var Arbi = class {
7110
7282
  };
7111
7283
  // ── Agents ──────────────────────────────────────────────────────────
7112
7284
  agents = {
7285
+ getSession: (agentId) => getAgentSession(this.requireClient(), agentId),
7286
+ startSession: (agentId, workspaceId) => startAgentSession(this.requireClient(), agentId, workspaceId),
7287
+ closeSession: (agentId) => closeAgentSession(this.requireClient(), agentId),
7288
+ listChats: (agentId) => listAgentChats(this.requireClient(), agentId),
7289
+ stageFile: (agentId, file, name) => this.recovering(() => stageAgentFile(this.getAuthHeaders(), agentId, file, name)),
7113
7290
  list: () => listAgents(this.requireClient()),
7114
7291
  create: (name) => createAgent(this.requireClient(), name),
7115
7292
  getConfig: (agentExtId) => getAgentConfig(this.requireClient(), agentExtId),
@@ -7941,69 +8118,6 @@ async function uploadArchive(auth, archivePath, options) {
7941
8118
  }
7942
8119
  }
7943
8120
 
7944
- // src/operations/responses.ts
7945
- var responses_exports = {};
7946
- __export(responses_exports, {
7947
- extractResponseText: () => extractResponseText,
7948
- getResponse: () => getResponse,
7949
- submitBackgroundQuery: () => submitBackgroundQuery
7950
- });
7951
- async function submitBackgroundQuery(options) {
7952
- const { workspaceId, question, docIds, previousResponseId, model, ...auth } = options;
7953
- const tools = {};
7954
- if (docIds.length > 0) {
7955
- tools.retrieval_chunk = {
7956
- name: "retrieval_chunk",
7957
- description: "retrieval chunk",
7958
- tool_args: { doc_ext_ids: docIds },
7959
- tool_responses: {}
7960
- };
7961
- tools.retrieval_full_context = {
7962
- name: "retrieval_full_context",
7963
- description: "retrieval full context",
7964
- tool_args: { doc_ext_ids: [] },
7965
- tool_responses: {}
7966
- };
7967
- }
7968
- const body = {
7969
- input: question,
7970
- workspace_ext_id: workspaceId,
7971
- stream: false,
7972
- background: true,
7973
- store: true,
7974
- tools,
7975
- ...previousResponseId ? { previous_response_id: previousResponseId } : {},
7976
- ...model ? { model } : {}
7977
- };
7978
- const res = await authenticatedFetch({
7979
- ...auth,
7980
- path: "/v1/responses",
7981
- method: "POST",
7982
- body: JSON.stringify(body),
7983
- headers: { "Content-Type": "application/json" }
7984
- });
7985
- return await res.json();
7986
- }
7987
- async function getResponse(auth, responseId) {
7988
- const res = await authenticatedFetch({
7989
- ...auth,
7990
- path: `/v1/responses/${responseId}`,
7991
- method: "GET"
7992
- });
7993
- return await res.json();
7994
- }
7995
- function extractResponseText(response) {
7996
- const parts = [];
7997
- for (const msg of response.output) {
7998
- for (const item of msg.content) {
7999
- if ("type" in item && item.type === "output_text" && "text" in item) {
8000
- parts.push(item.text);
8001
- }
8002
- }
8003
- }
8004
- return parts.join("");
8005
- }
8006
-
8007
8121
  // src/listen/index.ts
8008
8122
  var listen_exports = {};
8009
8123
  __export(listen_exports, {