@arbidocs/sdk 0.5.80 → 0.5.82

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.cjs CHANGED
@@ -3652,6 +3652,21 @@ function requireData(result, message) {
3652
3652
  }
3653
3653
  return result.data;
3654
3654
  }
3655
+ var WORKSPACE_REQUEST_CONFLICT_MESSAGES = {
3656
+ workspace_mismatch: "This belongs to another workspace, so nothing was saved.",
3657
+ workspace_key_required: "This workspace isn't unlocked in this session, so nothing was saved or read. Open the workspace and try again."
3658
+ };
3659
+ function requireWorkspaceData(result, message, conflicts = WORKSPACE_REQUEST_CONFLICT_MESSAGES) {
3660
+ const status = result.response?.status;
3661
+ const conflict = result.error && status === 409 ? workspaceConflictOf(result.error) : null;
3662
+ if (conflict) {
3663
+ throw new ArbiApiError(conflicts[conflict.code], result.error, status, {
3664
+ code: conflict.code,
3665
+ requestId: result.response?.headers?.get("x-request-id") ?? void 0
3666
+ });
3667
+ }
3668
+ return requireData(result, message);
3669
+ }
3655
3670
  function requireOk(result, message) {
3656
3671
  if (result.error) {
3657
3672
  throw new ArbiApiError(message, result.error, result.response?.status, {
@@ -6253,19 +6268,7 @@ var UPLOAD_WORKSPACE_CONFLICT_MESSAGES = {
6253
6268
  workspace_key_required: "The workspace couldn't be unlocked for this upload, so the files were not saved."
6254
6269
  };
6255
6270
  function requireUploadData(result, message) {
6256
- const status = result.response?.status;
6257
- const conflict = result.error && status === 409 ? workspaceConflictOf(result.error) : null;
6258
- if (conflict) {
6259
- throw new ArbiApiError(
6260
- UPLOAD_WORKSPACE_CONFLICT_MESSAGES[conflict.code],
6261
- result.error,
6262
- status,
6263
- {
6264
- code: conflict.code
6265
- }
6266
- );
6267
- }
6268
- return requireData(result, message);
6271
+ return requireWorkspaceData(result, message, UPLOAD_WORKSPACE_CONFLICT_MESSAGES);
6269
6272
  }
6270
6273
  async function uploadDocuments(arbi, files, options = {}) {
6271
6274
  const query2 = {};
@@ -7183,15 +7186,27 @@ __export(conversations_exports, {
7183
7186
  searchConversations: () => searchConversations,
7184
7187
  updateConversationAssistantMode: () => updateConversationAssistantMode
7185
7188
  });
7186
- async function listConversations(arbi) {
7187
- return requireData(await arbi.fetch.GET("/v1/conversation/list"), "Failed to fetch conversations");
7189
+
7190
+ // src/operations/workspace-query.ts
7191
+ var workspaceQuery = (workspaceExtId) => workspaceExtId ? { workspace_ext_id: workspaceExtId } : {};
7192
+
7193
+ // src/operations/conversations.ts
7194
+ async function listConversations(arbi, workspaceExtId) {
7195
+ return requireWorkspaceData(
7196
+ await arbi.fetch.GET("/v1/conversation/list", {
7197
+ params: { query: workspaceQuery(workspaceExtId) }
7198
+ }),
7199
+ "Failed to fetch conversations"
7200
+ );
7188
7201
  }
7189
- async function importConversations(auth, fileData, fileName, source = "auto") {
7202
+ async function importConversations(auth, fileData, fileName, source = "auto", workspaceExtId) {
7190
7203
  const formData = new FormData();
7191
7204
  formData.append("file", fileData, fileName);
7205
+ const query2 = new URLSearchParams({ source });
7206
+ if (workspaceExtId) query2.set("workspace_ext_id", workspaceExtId);
7192
7207
  const res = await authenticatedFetch({
7193
7208
  ...auth,
7194
- path: `/v1/conversation/import?source=${encodeURIComponent(source)}`,
7209
+ path: `/v1/conversation/import?${query2}`,
7195
7210
  method: "POST",
7196
7211
  body: formData
7197
7212
  });
@@ -7213,9 +7228,12 @@ async function deleteConversation(arbi, conversationId) {
7213
7228
  "Failed to delete conversation"
7214
7229
  );
7215
7230
  }
7216
- async function searchConversations(arbi, body) {
7217
- return requireData(
7218
- await arbi.fetch.POST("/v1/conversation/search", { body }),
7231
+ async function searchConversations(arbi, body, workspaceExtId) {
7232
+ return requireWorkspaceData(
7233
+ await arbi.fetch.POST("/v1/conversation/search", {
7234
+ params: { query: workspaceQuery(workspaceExtId) },
7235
+ body
7236
+ }),
7219
7237
  "Failed to search conversations"
7220
7238
  );
7221
7239
  }
@@ -7578,9 +7596,14 @@ async function interject(arbi, assistantMessageExtId, answer) {
7578
7596
  );
7579
7597
  }
7580
7598
  async function listSkills(arbi, options) {
7581
- const result = requireData(
7599
+ const result = requireWorkspaceData(
7582
7600
  await arbi.fetch.GET("/v1/assistant/skills", {
7583
- params: { query: { include_hidden: options?.includeHidden ?? false } }
7601
+ params: {
7602
+ query: {
7603
+ include_hidden: options?.includeHidden ?? false,
7604
+ ...workspaceQuery(options?.workspaceExtId)
7605
+ }
7606
+ }
7584
7607
  }),
7585
7608
  "Failed to list skills"
7586
7609
  );
@@ -9072,9 +9095,10 @@ __export(files_exports, {
9072
9095
  uploadFile: () => uploadFile2
9073
9096
  });
9074
9097
  async function listFiles(arbi, options) {
9075
- return requireData(
9098
+ const { workspaceExtId, ...query2 } = options ?? {};
9099
+ return requireWorkspaceData(
9076
9100
  await arbi.fetch.GET("/v1/files", {
9077
- params: { query: options ?? {} }
9101
+ params: { query: { ...query2, ...workspaceQuery(workspaceExtId) } }
9078
9102
  }),
9079
9103
  "Failed to list files"
9080
9104
  );
@@ -9095,13 +9119,13 @@ async function deleteFile(arbi, fileId) {
9095
9119
  "Failed to delete file"
9096
9120
  );
9097
9121
  }
9098
- async function uploadFile2(auth, fileData, fileName, purpose = "assistants") {
9122
+ async function uploadFile2(auth, fileData, fileName, purpose = "assistants", workspaceExtId) {
9099
9123
  const formData = new FormData();
9100
9124
  formData.append("file", fileData, fileName);
9101
9125
  formData.append("purpose", purpose);
9102
9126
  const res = await authenticatedFetch({
9103
9127
  ...auth,
9104
- path: "/v1/files",
9128
+ path: workspaceExtId ? `/v1/files?workspace_ext_id=${encodeURIComponent(workspaceExtId)}` : "/v1/files",
9105
9129
  method: "POST",
9106
9130
  body: formData
9107
9131
  });
@@ -10183,22 +10207,31 @@ function stepsPlan(steps) {
10183
10207
  }
10184
10208
 
10185
10209
  // src/operations/work.ts
10210
+ var TASK_WORKSPACE_CONFLICT_MESSAGES = {
10211
+ ...WORKSPACE_REQUEST_CONFLICT_MESSAGES,
10212
+ workspace_mismatch: "The parent task is in another workspace, so the task was not saved. Choose a parent in the same workspace."
10213
+ };
10186
10214
  var byId = (conversationId) => ({
10187
10215
  params: { path: { conversation_ext_id: conversationId } }
10188
10216
  });
10189
10217
  async function updateConversation(arbi, conversationId, body) {
10190
- return requireData(
10218
+ return requireWorkspaceData(
10191
10219
  await arbi.fetch.PATCH("/v1/conversation/{conversation_ext_id}", {
10192
10220
  ...byId(conversationId),
10193
10221
  body
10194
10222
  }),
10195
- "Failed to update conversation"
10223
+ "Failed to update conversation",
10224
+ TASK_WORKSPACE_CONFLICT_MESSAGES
10196
10225
  );
10197
10226
  }
10198
- async function createWork(arbi, body) {
10199
- return requireData(
10200
- await arbi.fetch.POST("/v1/conversation/work", { body }),
10201
- "Failed to create task"
10227
+ async function createWork(arbi, body, workspaceExtId) {
10228
+ return requireWorkspaceData(
10229
+ await arbi.fetch.POST("/v1/conversation/work", {
10230
+ params: { query: workspaceQuery(workspaceExtId) },
10231
+ body
10232
+ }),
10233
+ "Failed to create task",
10234
+ TASK_WORKSPACE_CONFLICT_MESSAGES
10202
10235
  );
10203
10236
  }
10204
10237
  async function runConversation(arbi, conversationId) {
@@ -10264,9 +10297,12 @@ async function getActivity(arbi, conversationId) {
10264
10297
  "Failed to read the task activity"
10265
10298
  );
10266
10299
  }
10267
- async function planWork(arbi, body) {
10268
- return requireData(
10269
- await arbi.fetch.POST("/v1/conversation/work/plan", { body }),
10300
+ async function planWork(arbi, body, workspaceExtId) {
10301
+ return requireWorkspaceData(
10302
+ await arbi.fetch.POST("/v1/conversation/work/plan", {
10303
+ params: { query: workspaceQuery(workspaceExtId) },
10304
+ body
10305
+ }),
10270
10306
  "Failed to draft a plan"
10271
10307
  );
10272
10308
  }
@@ -10386,14 +10422,26 @@ __export(facts_exports, {
10386
10422
  searchFacts: () => searchFacts,
10387
10423
  updateFact: () => updateFact
10388
10424
  });
10389
- async function createFact(arbi, body) {
10390
- return requireData(await arbi.fetch.POST("/v1/facts/", { body }), "Failed to create note");
10425
+ async function createFact(arbi, body, workspaceExtId) {
10426
+ return requireWorkspaceData(
10427
+ await arbi.fetch.POST("/v1/facts/", {
10428
+ params: { query: workspaceQuery(workspaceExtId) },
10429
+ body
10430
+ }),
10431
+ "Failed to create note"
10432
+ );
10391
10433
  }
10392
- async function createFactsBatch(arbi, body) {
10393
- return requireData(await arbi.fetch.POST("/v1/facts/batch", { body }), "Failed to create notes");
10434
+ async function createFactsBatch(arbi, body, workspaceExtId) {
10435
+ return requireWorkspaceData(
10436
+ await arbi.fetch.POST("/v1/facts/batch", {
10437
+ params: { query: workspaceQuery(workspaceExtId) },
10438
+ body
10439
+ }),
10440
+ "Failed to create notes"
10441
+ );
10394
10442
  }
10395
10443
  async function listFacts(arbi, options) {
10396
- return requireData(
10444
+ return requireWorkspaceData(
10397
10445
  await arbi.fetch.GET("/v1/facts/list", {
10398
10446
  params: {
10399
10447
  query: {
@@ -10403,18 +10451,25 @@ async function listFacts(arbi, options) {
10403
10451
  tag_ext_id: options?.tagExtIds,
10404
10452
  doc_ext_id: options?.docExtId,
10405
10453
  limit: options?.limit,
10406
- offset: options?.offset
10454
+ offset: options?.offset,
10455
+ ...workspaceQuery(options?.workspaceExtId)
10407
10456
  }
10408
10457
  }
10409
10458
  }),
10410
10459
  "Failed to list notes"
10411
10460
  );
10412
10461
  }
10413
- async function searchFacts(arbi, body) {
10414
- return requireData(await arbi.fetch.POST("/v1/facts/search", { body }), "Failed to search notes");
10462
+ async function searchFacts(arbi, body, workspaceExtId) {
10463
+ return requireWorkspaceData(
10464
+ await arbi.fetch.POST("/v1/facts/search", {
10465
+ params: { query: workspaceQuery(workspaceExtId) },
10466
+ body
10467
+ }),
10468
+ "Failed to search notes"
10469
+ );
10415
10470
  }
10416
10471
  async function updateFact(arbi, factId, body) {
10417
- return requireData(
10472
+ return requireWorkspaceData(
10418
10473
  await arbi.fetch.PATCH("/v1/facts/{fact_ext_id}", {
10419
10474
  params: { path: { fact_ext_id: factId } },
10420
10475
  body
@@ -10429,7 +10484,7 @@ async function deleteFact(arbi, factId) {
10429
10484
  if (error) throw new Error("Failed to delete note");
10430
10485
  }
10431
10486
  async function remindFact(arbi, factId, options = {}) {
10432
- return requireData(
10487
+ return requireWorkspaceData(
10433
10488
  await arbi.fetch.POST("/v1/facts/{fact_ext_id}/remind", {
10434
10489
  params: { path: { fact_ext_id: factId } },
10435
10490
  body: {
@@ -12868,11 +12923,22 @@ var Arbi = class {
12868
12923
  };
12869
12924
  // ── Conversations ─────────────────────────────────────────────────────
12870
12925
  conversations = {
12871
- list: () => listConversations(this.requireClient()),
12926
+ /** The current workspace's conversations, or `options.workspaceId`'s (opened, not switched to). */
12927
+ list: async (options) => listConversations(
12928
+ this.requireClient(),
12929
+ await this.requireTargetWorkspace(options?.workspaceId)
12930
+ ),
12872
12931
  getThreads: (conversationId) => getConversationThreads(this.requireClient(), conversationId),
12873
12932
  delete: (conversationId) => deleteConversation(this.requireClient(), conversationId),
12874
- /** Search the open workspace's past conversation messages (keyword + semantic), grouped. */
12875
- search: (body) => searchConversations(this.requireClient(), body),
12933
+ /**
12934
+ * Search the past conversation messages (keyword + semantic, grouped) of the current
12935
+ * workspace, or `options.workspaceId` (opened for this session, not switched to).
12936
+ */
12937
+ search: async (body, options) => searchConversations(
12938
+ this.requireClient(),
12939
+ body,
12940
+ await this.requireTargetWorkspace(options?.workspaceId)
12941
+ ),
12876
12942
  /**
12877
12943
  * Patch a conversation: `title`, `shared` (owner only), its bound document
12878
12944
  * (`bound_document_ext_id`, `null` unbinds), and the work fields (`description`, `due_at`,
@@ -12880,8 +12946,16 @@ var Arbi = class {
12880
12946
  * and attaching a thread to a document.
12881
12947
  */
12882
12948
  update: (conversationId, body) => updateConversation(this.requireClient(), conversationId, body),
12883
- /** Create a work item: a plain to-do, or (with a prompt / skill) agent work that starts now. */
12884
- createWork: (body) => createWork(this.requireClient(), body),
12949
+ /**
12950
+ * Create a work item: a plain to-do, or (with a prompt / skill) agent work that starts now. It
12951
+ * is made in the current workspace, or `options.workspaceId` (opened, not switched to), which
12952
+ * the request names: a switch while it is sent cannot move it.
12953
+ */
12954
+ createWork: async (body, options) => createWork(
12955
+ this.requireClient(),
12956
+ body,
12957
+ await this.requireTargetWorkspace(options?.workspaceId)
12958
+ ),
12885
12959
  /** Run a work item now, or retry it. */
12886
12960
  run: (conversationId) => runConversation(this.requireClient(), conversationId),
12887
12961
  /** The session key an unattended run waits for the owner to allow; 404 when nothing waits. */
@@ -12902,8 +12976,12 @@ var Arbi = class {
12902
12976
  usage: (conversationId) => getConversationUsage(this.requireClient(), conversationId),
12903
12977
  /** Notify people about a conversation (each gets a notification); resolves with who was. */
12904
12978
  notify: (conversationId, userIds) => notifyConversation(this.requireClient(), conversationId, userIds),
12905
- /** Draft an editable plan from an objective. */
12906
- plan: (body) => planWork(this.requireClient(), body),
12979
+ /** Draft an editable plan from an objective, in the current workspace or `options.workspaceId`. */
12980
+ plan: async (body, options) => planWork(
12981
+ this.requireClient(),
12982
+ body,
12983
+ await this.requireTargetWorkspace(options?.workspaceId)
12984
+ ),
12907
12985
  /**
12908
12986
  * Run a work item and, when the run is parked waiting for workspace access, grant the agent's
12909
12987
  * run session a temporary key and run it again. Work that needs no access grant returns from the
@@ -13377,8 +13455,15 @@ var Arbi = class {
13377
13455
  },
13378
13456
  /** Read the status of a background turn. */
13379
13457
  getResponse: (id) => this.recovering(() => getResponse(this.getAuthHeaders(), id)),
13380
- /** The skills the caller can run (own + shared marketplace), metadata only. */
13381
- listSkills: (options) => listSkills(this.requireClient(), options),
13458
+ /**
13459
+ * The skills the caller can run (own + shared marketplace), metadata only. Without a
13460
+ * marketplace they are the current workspace's, or `options.workspaceId`'s (opened, not
13461
+ * switched to).
13462
+ */
13463
+ listSkills: async (options) => listSkills(this.requireClient(), {
13464
+ includeHidden: options?.includeHidden,
13465
+ workspaceExtId: await this.targetWorkspace(options?.workspaceId)
13466
+ }),
13382
13467
  /**
13383
13468
  * Save a SKILL.md as the caller's skill ``slug``: private unless ``shared`` (pass
13384
13469
  * ``shared: isSharedSkill(skill)`` when changing an existing skill, so a shared one stays shared).
@@ -14014,12 +14099,23 @@ var Arbi = class {
14014
14099
  };
14015
14100
  // ── Files (OpenAI-compatible) ────────────────────────────────────────
14016
14101
  files = {
14017
- list: (options) => listFiles(this.requireClient(), options),
14102
+ /** The current workspace's files, or `options.workspaceId`'s (opened, not switched to). */
14103
+ list: async (options) => {
14104
+ const { workspaceId, ...rest } = options ?? {};
14105
+ return listFiles(this.requireClient(), {
14106
+ ...rest,
14107
+ workspaceExtId: await this.targetWorkspace(workspaceId)
14108
+ });
14109
+ },
14018
14110
  get: (fileId) => getFile(this.requireClient(), fileId),
14019
14111
  delete: (fileId) => deleteFile(this.requireClient(), fileId),
14020
- upload: (fileData, fileName, purpose) => this.recovering(
14021
- () => uploadFile2(this.getAuthHeaders(), fileData, fileName, purpose)
14022
- ),
14112
+ /** Upload a file into the current workspace, or `options.workspaceId` (opened, not switched to). */
14113
+ upload: async (fileData, fileName, purpose, options) => {
14114
+ const workspaceExtId = await this.targetWorkspace(options?.workspaceId);
14115
+ return this.recovering(
14116
+ () => uploadFile2(this.getAuthHeaders(), fileData, fileName, purpose, workspaceExtId)
14117
+ );
14118
+ },
14023
14119
  getContent: (fileId) => this.recovering(() => getFileContent(this.getAuthHeaders(), fileId))
14024
14120
  };
14025
14121
  // ── Agents ──────────────────────────────────────────────────────────
@@ -14155,15 +14251,38 @@ var Arbi = class {
14155
14251
  export: (databaseId, format) => exportDatabase(this.requireClient(), databaseId, format)
14156
14252
  };
14157
14253
  // ── Workspace facts ─────────────────────────────────────────────────
14254
+ /**
14255
+ * Notes. Create, list and search act in the current workspace, or `workspaceId` (opened for this
14256
+ * session, not switched to), which the request names; update, delete and remind act in the
14257
+ * note's own workspace, which the server derives from it.
14258
+ */
14158
14259
  facts = {
14159
- create: (body) => createFact(this.requireClient(), body),
14260
+ create: async (body, options) => createFact(
14261
+ this.requireClient(),
14262
+ body,
14263
+ await this.requireTargetWorkspace(options?.workspaceId)
14264
+ ),
14160
14265
  /** Create up to 200 notes in one all-or-nothing request. */
14161
- createBatch: (body) => createFactsBatch(this.requireClient(), body),
14266
+ createBatch: async (body, options) => createFactsBatch(
14267
+ this.requireClient(),
14268
+ body,
14269
+ await this.requireTargetWorkspace(options?.workspaceId)
14270
+ ),
14162
14271
  /** Pass `from`/`to`/`datedOnly` for the timeline view — dated notes only,
14163
14272
  * ordered by when they happened. `tagExtIds` / `docExtId` narrow the list;
14164
14273
  * `limit` / `offset` page it. */
14165
- list: (options) => listFacts(this.requireClient(), options),
14166
- search: (body) => searchFacts(this.requireClient(), body),
14274
+ list: async (options) => {
14275
+ const { workspaceId, ...filter } = options ?? {};
14276
+ return listFacts(this.requireClient(), {
14277
+ ...filter,
14278
+ workspaceExtId: await this.requireTargetWorkspace(workspaceId)
14279
+ });
14280
+ },
14281
+ search: async (body, options) => searchFacts(
14282
+ this.requireClient(),
14283
+ body,
14284
+ await this.requireTargetWorkspace(options?.workspaceId)
14285
+ ),
14167
14286
  update: (factId, body) => updateFact(this.requireClient(), factId, body),
14168
14287
  delete: (factId) => deleteFact(this.requireClient(), factId),
14169
14288
  /** One-off reminder on a dated note: an explicit `remindAt`, or