@arbidocs/sdk 0.4.147 → 0.4.150

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
@@ -3533,6 +3533,10 @@ var ArbiApiError = class extends ArbiError {
3533
3533
  this.detail = apiErrorDetail(apiError);
3534
3534
  }
3535
3535
  };
3536
+ function refusalReason(err, fallback) {
3537
+ if (err instanceof ArbiApiError) return err.detail || fallback;
3538
+ return apiErrorDetail(err) || fallback;
3539
+ }
3536
3540
  function requireData(result, message) {
3537
3541
  if (result.error || !result.data) {
3538
3542
  throw new ArbiApiError(message, result.error, result.response?.status);
@@ -5539,6 +5543,7 @@ async function listHouseTemplateCandidates(arbi) {
5539
5543
  // src/operations/workspaces.ts
5540
5544
  var workspaces_exports = {};
5541
5545
  __export(workspaces_exports, {
5546
+ addWorkspaceMembers: () => addWorkspaceMembers,
5542
5547
  addWorkspaceUsers: () => addWorkspaceUsers,
5543
5548
  copyDocuments: () => copyDocuments,
5544
5549
  createWorkspace: () => createWorkspace,
@@ -5586,6 +5591,12 @@ async function updateWorkspace(arbi, body) {
5586
5591
  async function listWorkspaceUsers(arbi) {
5587
5592
  return requireData(await arbi.fetch.GET("/v1/workspace/users"), "Failed to fetch workspace users");
5588
5593
  }
5594
+ async function addWorkspaceMembers(arbi, request) {
5595
+ return requireData(
5596
+ await arbi.fetch.POST("/v1/workspace/users", { body: request }),
5597
+ "Failed to add users"
5598
+ );
5599
+ }
5589
5600
  async function addWorkspaceUsers(arbi, emails, role = "collaborator", target, confirmInvite = false) {
5590
5601
  const invite = confirmInvite ? { confirm_invite: true } : {};
5591
5602
  return requireData(
@@ -5741,6 +5752,7 @@ async function updateConversationAssistantMode(arbi, conversationId, assistantMo
5741
5752
  // src/operations/assistant.ts
5742
5753
  var assistant_exports = {};
5743
5754
  __export(assistant_exports, {
5755
+ MAX_RETRIEVE_DOC_IDS: () => MAX_RETRIEVE_DOC_IDS,
5744
5756
  buildFactsContextTool: () => buildFactsContextTool,
5745
5757
  buildRetrievalChunkTool: () => buildRetrievalChunkTool,
5746
5758
  buildRetrievalFullContextTool: () => buildRetrievalFullContextTool,
@@ -5755,6 +5767,7 @@ __export(assistant_exports, {
5755
5767
  queryAssistant: () => queryAssistant,
5756
5768
  respondToAgent: () => respondToAgent,
5757
5769
  retrieve: () => retrieve,
5770
+ searchChunks: () => searchChunks,
5758
5771
  uploadSkill: () => uploadSkill
5759
5772
  });
5760
5773
  function buildRetrievalChunkTool(docIds, searchMode) {
@@ -5788,8 +5801,19 @@ function buildRetrievalTocTool(docIds) {
5788
5801
  tool_responses: {}
5789
5802
  };
5790
5803
  }
5804
+ var MAX_RETRIEVE_DOC_IDS = 5e3;
5791
5805
  async function retrieve(options) {
5792
- const { arbi, workspaceId, query, docIds, searchMode, fullContextDocIds, tocDocIds, model } = options;
5806
+ const {
5807
+ arbi,
5808
+ workspaceId,
5809
+ query,
5810
+ docIds,
5811
+ searchMode,
5812
+ fullContextDocIds,
5813
+ tocDocIds,
5814
+ model,
5815
+ store = true
5816
+ } = options;
5793
5817
  const tools = {
5794
5818
  retrieval_chunk: buildRetrievalChunkTool(docIds, searchMode)
5795
5819
  };
@@ -5804,7 +5828,7 @@ async function retrieve(options) {
5804
5828
  workspace_ext_id: workspaceId,
5805
5829
  stream: false,
5806
5830
  background: false,
5807
- store: true,
5831
+ store,
5808
5832
  tools,
5809
5833
  ...model ? { model } : {}
5810
5834
  };
@@ -5824,6 +5848,34 @@ async function retrieve(options) {
5824
5848
  }
5825
5849
  return data;
5826
5850
  }
5851
+ function isReadablePassage(content) {
5852
+ return content.length > 10 && content !== "-" && !/^[|\-\s]+$/.test(content);
5853
+ }
5854
+ function searchChunks(result) {
5855
+ const byId3 = /* @__PURE__ */ new Map();
5856
+ for (const [title, chunks] of Object.entries(result?.retrieval_chunk?.tool_responses ?? {})) {
5857
+ if (!Array.isArray(chunks)) continue;
5858
+ chunks.forEach((chunk2, index) => {
5859
+ if (!chunk2 || typeof chunk2 !== "object") return;
5860
+ const content = chunk2.content?.trim() ?? "";
5861
+ if (!isReadablePassage(content)) return;
5862
+ const meta = chunk2.metadata ?? {};
5863
+ const docId = meta.doc_ext_id || title;
5864
+ const rerank = meta.rerank_score;
5865
+ byId3.set(meta.chunk_ext_id || `${docId}_${index}`, {
5866
+ id: meta.chunk_ext_id || `${docId}_${index}`,
5867
+ ...meta.chunk_ext_id ? { chunkExtId: meta.chunk_ext_id } : {},
5868
+ docId,
5869
+ docTitle: meta.doc_title || title,
5870
+ ...meta.page_number != null ? { page: meta.page_number } : {},
5871
+ score: rerank && rerank > 0 ? rerank : meta.score ?? 0,
5872
+ index,
5873
+ content
5874
+ });
5875
+ });
5876
+ }
5877
+ return Array.from(byId3.values()).sort((a2, b2) => b2.score - a2.score);
5878
+ }
5827
5879
  async function queryAssistant(options) {
5828
5880
  const {
5829
5881
  workspaceId,
@@ -7515,6 +7567,11 @@ async function remove(arbi) {
7515
7567
  // src/operations/projects.ts
7516
7568
  var projects_exports = {};
7517
7569
  __export(projects_exports, {
7570
+ addAddonBlock: () => addAddonBlock,
7571
+ billingPortal: () => billingPortal,
7572
+ cancelSubscription: () => cancelSubscription,
7573
+ changePlan: () => changePlan,
7574
+ createCheckout: () => createCheckout,
7518
7575
  createProject: () => createProject,
7519
7576
  deleteProject: () => deleteProject,
7520
7577
  formatBudget: () => formatBudget,
@@ -7522,11 +7579,17 @@ __export(projects_exports, {
7522
7579
  getProjectInvoices: () => getProjectInvoices,
7523
7580
  getProjectUsage: () => getProjectUsage,
7524
7581
  getUserUsageToday: () => getUserUsageToday,
7582
+ listProducts: () => listProducts,
7525
7583
  listProjectEvents: () => listProjectEvents,
7526
7584
  listProjects: () => listProjects,
7527
7585
  parseBudget: () => parseBudget,
7586
+ previewPlanChange: () => previewPlanChange,
7587
+ quoteAddon: () => quoteAddon,
7588
+ quotePlan: () => quotePlan,
7528
7589
  refreshProject: () => refreshProject,
7529
7590
  renameProject: () => renameProject,
7591
+ setNextPeriodAddons: () => setNextPeriodAddons,
7592
+ updateAddonSettings: () => updateAddonSettings,
7530
7593
  updateProject: () => updateProject
7531
7594
  });
7532
7595
  async function listProjects(arbi, filters = {}) {
@@ -7649,6 +7712,95 @@ async function getProjectInvoices(arbi, projectExtId) {
7649
7712
  async function getUserUsageToday(arbi) {
7650
7713
  return requireData(await arbi.fetch.GET("/v1/user/me/usage/today"), "Failed to fetch today usage");
7651
7714
  }
7715
+ var projectPath = (projectExtId) => ({ path: { project_ext_id: projectExtId } });
7716
+ async function listProducts(arbi) {
7717
+ return requireData(await arbi.fetch.GET("/v1/user/products"), "Failed to load the plans");
7718
+ }
7719
+ async function quotePlan(arbi, projectExtId, body) {
7720
+ return requireData(
7721
+ projectExtId ? await arbi.fetch.POST("/v1/user/projects/{project_ext_id}/checkout/quote", {
7722
+ params: projectPath(projectExtId),
7723
+ body
7724
+ }) : await arbi.fetch.POST("/v1/user/projects/quote", { body }),
7725
+ "Failed to price the plan"
7726
+ );
7727
+ }
7728
+ async function createCheckout(arbi, projectExtId, body) {
7729
+ return requireData(
7730
+ await arbi.fetch.POST("/v1/user/projects/{project_ext_id}/checkout", {
7731
+ params: projectPath(projectExtId),
7732
+ body
7733
+ }),
7734
+ "Failed to start the checkout"
7735
+ );
7736
+ }
7737
+ async function changePlan(arbi, projectExtId, body) {
7738
+ return requireData(
7739
+ await arbi.fetch.POST("/v1/user/projects/{project_ext_id}/change-plan", {
7740
+ params: projectPath(projectExtId),
7741
+ body
7742
+ }),
7743
+ "Failed to change the plan"
7744
+ );
7745
+ }
7746
+ async function previewPlanChange(arbi, projectExtId, body) {
7747
+ return requireData(
7748
+ await arbi.fetch.POST("/v1/user/projects/{project_ext_id}/plan/preview", {
7749
+ params: projectPath(projectExtId),
7750
+ body
7751
+ }),
7752
+ "Failed to price the plan change"
7753
+ );
7754
+ }
7755
+ async function quoteAddon(arbi, projectExtId, kind) {
7756
+ return requireData(
7757
+ await arbi.fetch.GET("/v1/user/projects/{project_ext_id}/addons/quote", {
7758
+ params: { ...projectPath(projectExtId), query: { kind } }
7759
+ }),
7760
+ "Failed to price the add-on"
7761
+ );
7762
+ }
7763
+ async function billingPortal(arbi, projectExtId) {
7764
+ return requireData(
7765
+ await arbi.fetch.POST("/v1/user/projects/{project_ext_id}/billing-portal", {
7766
+ params: projectPath(projectExtId)
7767
+ }),
7768
+ "Failed to open the billing portal"
7769
+ );
7770
+ }
7771
+ async function addAddonBlock(arbi, projectExtId, kind) {
7772
+ const params = projectPath(projectExtId);
7773
+ return requireData(
7774
+ kind === "ai_usage" ? await arbi.fetch.POST("/v1/user/projects/{project_ext_id}/addons/ai-usage", { params }) : await arbi.fetch.POST("/v1/user/projects/{project_ext_id}/addons/storage", { params }),
7775
+ "Failed to add the add-on"
7776
+ );
7777
+ }
7778
+ async function setNextPeriodAddons(arbi, projectExtId, body) {
7779
+ return requireData(
7780
+ await arbi.fetch.PUT("/v1/user/projects/{project_ext_id}/addons/next-period", {
7781
+ params: projectPath(projectExtId),
7782
+ body
7783
+ }),
7784
+ "Failed to change the add-ons"
7785
+ );
7786
+ }
7787
+ async function updateAddonSettings(arbi, projectExtId, body) {
7788
+ return requireData(
7789
+ await arbi.fetch.PUT("/v1/user/projects/{project_ext_id}/addons/settings", {
7790
+ params: projectPath(projectExtId),
7791
+ body
7792
+ }),
7793
+ "Failed to save the add-on settings"
7794
+ );
7795
+ }
7796
+ async function cancelSubscription(arbi, projectExtId) {
7797
+ return requireData(
7798
+ await arbi.fetch.POST("/v1/user/projects/{project_ext_id}/cancel", {
7799
+ params: projectPath(projectExtId)
7800
+ }),
7801
+ "Failed to cancel the subscription"
7802
+ );
7803
+ }
7652
7804
 
7653
7805
  // src/operations/work.ts
7654
7806
  var work_exports = {};
@@ -8740,10 +8892,8 @@ __export(calendar_exports, {
8740
8892
  cancelPublicBooking: () => cancelPublicBooking,
8741
8893
  connectCalDavAccount: () => connectCalDavAccount,
8742
8894
  connectOAuthAccount: () => connectOAuthAccount,
8743
- createAppPassword: () => createAppPassword,
8744
8895
  createCalendar: () => createCalendar,
8745
8896
  createEvent: () => createEvent,
8746
- createFeed: () => createFeed,
8747
8897
  createRoom: () => createRoom,
8748
8898
  decideCounter: () => decideCounter,
8749
8899
  deleteBookingPage: () => deleteBookingPage,
@@ -8760,7 +8910,6 @@ __export(calendar_exports, {
8760
8910
  getPublicBookingPage: () => getPublicBookingPage,
8761
8911
  importCalendarIcs: () => importCalendarIcs,
8762
8912
  listAccounts: () => listAccounts,
8763
- listAppPasswords: () => listAppPasswords,
8764
8913
  listBookingPages: () => listBookingPages,
8765
8914
  listCalDavProfiles: () => listCalDavProfiles,
8766
8915
  listCalendars: () => listCalendars,
@@ -8778,9 +8927,7 @@ __export(calendar_exports, {
8778
8927
  putCalendarSettings: () => putCalendarSettings,
8779
8928
  refreshCalendar: () => refreshCalendar,
8780
8929
  respondToEvent: () => respondToEvent,
8781
- revokeAppPassword: () => revokeAppPassword,
8782
8930
  shareCalendar: () => shareCalendar,
8783
- splitAppPasswords: () => splitAppPasswords,
8784
8931
  subscribeCalendar: () => subscribeCalendar,
8785
8932
  syncAccount: () => syncAccount,
8786
8933
  unlockCalendarKeys: () => unlockCalendarKeys,
@@ -9168,46 +9315,6 @@ async function publishCalendarToAccount(client, accId, calendarId) {
9168
9315
  "Publishing the calendar"
9169
9316
  );
9170
9317
  }
9171
- async function listAppPasswords(client) {
9172
- return take(await client.fetch.GET("/v1/calendar/app-passwords"), "Loading app passwords");
9173
- }
9174
- async function createAppPassword(client, body) {
9175
- return take(
9176
- await client.fetch.POST("/v1/calendar/app-passwords", {
9177
- body: {
9178
- label: body.label.trim(),
9179
- calendar_ids: body.calendar_ids?.length ? body.calendar_ids : null
9180
- }
9181
- }),
9182
- "Creating the app password"
9183
- );
9184
- }
9185
- async function createFeed(client, body) {
9186
- return take(
9187
- await client.fetch.POST("/v1/calendar/feeds", {
9188
- body: {
9189
- calendar_id: body.calendar_id,
9190
- level: body.level,
9191
- label: body.label?.trim() || (body.level === "full" ? "Feed" : "Free/busy feed")
9192
- }
9193
- }),
9194
- "Creating the feed"
9195
- );
9196
- }
9197
- async function revokeAppPassword(client, apwId) {
9198
- take(
9199
- await client.fetch.DELETE("/v1/calendar/app-passwords/{apw_id}", {
9200
- params: { path: { apw_id: apwId } }
9201
- }),
9202
- "Revoking"
9203
- );
9204
- }
9205
- function splitAppPasswords(rows) {
9206
- return {
9207
- devices: rows.filter((r2) => r2.kind === "dav"),
9208
- feeds: rows.filter((r2) => r2.kind === "feed" || r2.kind === "freebusy")
9209
- };
9210
- }
9211
9318
  async function listBookingPages(client) {
9212
9319
  return take(await client.fetch.GET("/v1/calendar/booking-pages"), "Loading booking pages");
9213
9320
  }
@@ -9576,7 +9683,23 @@ var Arbi = class {
9576
9683
  /** AI usage + spend breakdown for a project's billing period. */
9577
9684
  usage: (projectExtId, monthsBack) => getProjectUsage(this.requireClient(), projectExtId, monthsBack),
9578
9685
  /** Stripe invoices for a project's subscription. */
9579
- invoices: (projectExtId) => getProjectInvoices(this.requireClient(), projectExtId)
9686
+ invoices: (projectExtId) => getProjectInvoices(this.requireClient(), projectExtId),
9687
+ /** Delete a project (only when empty: no workspaces, no subscription). */
9688
+ delete: (projectExtId) => deleteProject(this.requireClient(), projectExtId),
9689
+ /** The plans and add-ons on sale. */
9690
+ products: () => listProducts(this.requireClient()),
9691
+ /** The taxed total of a Pro purchase (a new project when `projectExtId` is null). */
9692
+ quotePlan: (projectExtId, body) => quotePlan(this.requireClient(), projectExtId, body),
9693
+ /** Start an embedded Stripe checkout; returns its `client_secret`. */
9694
+ checkout: (projectExtId, body) => createCheckout(this.requireClient(), projectExtId, body),
9695
+ changePlan: (projectExtId, body) => changePlan(this.requireClient(), projectExtId, body),
9696
+ previewPlanChange: (projectExtId, body) => previewPlanChange(this.requireClient(), projectExtId, body),
9697
+ quoteAddon: (projectExtId, kind) => quoteAddon(this.requireClient(), projectExtId, kind),
9698
+ billingPortal: (projectExtId) => billingPortal(this.requireClient(), projectExtId),
9699
+ addAddonBlock: (projectExtId, kind) => addAddonBlock(this.requireClient(), projectExtId, kind),
9700
+ setNextPeriodAddons: (projectExtId, body) => setNextPeriodAddons(this.requireClient(), projectExtId, body),
9701
+ updateAddonSettings: (projectExtId, body) => updateAddonSettings(this.requireClient(), projectExtId, body),
9702
+ cancelSubscription: (projectExtId) => cancelSubscription(this.requireClient(), projectExtId)
9580
9703
  };
9581
9704
  // ── User (account-scoped usage) ───────────────────────────────────────
9582
9705
  user = {
@@ -9760,6 +9883,11 @@ var Arbi = class {
9760
9883
  void 0,
9761
9884
  options?.confirmInvite
9762
9885
  ),
9886
+ /**
9887
+ * `POST /v1/workspace/users` with the whole request (another workspace with its sealed key, a
9888
+ * session-scoped grant, an invitation, a resource share): see `addWorkspaceMembers`.
9889
+ */
9890
+ addMembers: (request) => addWorkspaceMembers(this.requireClient(), request),
9763
9891
  /**
9764
9892
  * Grant users a temporary key scoped to ONE session (identified by its public key), for
9765
9893
  * example an agent's run session minted by `agents.authorize()`. Nothing standing is created:
@@ -10068,7 +10196,8 @@ var Arbi = class {
10068
10196
  /** The skills the caller can run (own + shared marketplace), metadata only. */
10069
10197
  listSkills: (options) => listSkills(this.requireClient(), options),
10070
10198
  /**
10071
- * Search documents without LLM generation (retrieval only).
10199
+ * Search documents without LLM generation (retrieval only). No `docIds` searches the whole
10200
+ * workspace; `searchChunks(result)` ranks the passages found.
10072
10201
  */
10073
10202
  retrieve: (query, docIds, options) => retrieve({
10074
10203
  arbi: this.requireClient(),
@@ -10198,10 +10327,6 @@ var Arbi = class {
10198
10327
  syncAccount: (accId) => this.withCalendarKeys((c2) => syncAccount(c2, accId)),
10199
10328
  disconnectAccount: (accId) => this.withCalendarKeys((c2) => disconnectAccount(c2, accId)),
10200
10329
  publishToAccount: (accId, calendarId) => this.withCalendarKeys((c2) => publishCalendarToAccount(c2, accId, calendarId)),
10201
- listAppPasswords: () => this.withCalendarKeys((c2) => listAppPasswords(c2)),
10202
- createAppPassword: (body) => this.withCalendarKeys((c2) => createAppPassword(c2, body)),
10203
- createFeed: (body) => this.withCalendarKeys((c2) => createFeed(c2, body)),
10204
- revokeAppPassword: (apwId) => this.withCalendarKeys((c2) => revokeAppPassword(c2, apwId)),
10205
10330
  listBookingPages: () => this.withCalendarKeys((c2) => listBookingPages(c2)),
10206
10331
  putBookingPage: (body) => this.withCalendarKeys((c2) => putBookingPage(c2, body)),
10207
10332
  deleteBookingPage: (slug) => this.withCalendarKeys((c2) => deleteBookingPage(c2, slug))
@@ -11276,6 +11401,116 @@ function attachmentFromFile(filePath) {
11276
11401
  );
11277
11402
  }
11278
11403
 
11404
+ // src/tag-helpers.ts
11405
+ var ENTITY_KINDS = ["person", "organisation"];
11406
+ var PRESENCE_KINDS = ["label", "issue", "person", "organisation"];
11407
+ function defaultKindForFormat(format) {
11408
+ if (format === "checkbox") return "label";
11409
+ if (format === "search") return "search";
11410
+ return "annotation";
11411
+ }
11412
+ function tagUseCount(tag) {
11413
+ return (tag.doctag_count ?? 0) + (tag.facttag_count ?? 0) + (tag.convotag_count ?? 0);
11414
+ }
11415
+ function filterDocumentTags(tags) {
11416
+ return tags.filter((tag) => tag.kind !== "search");
11417
+ }
11418
+ function isPresenceTag(tag) {
11419
+ return PRESENCE_KINDS.includes(tag.kind);
11420
+ }
11421
+ function isLabelTag(tag) {
11422
+ return tag.kind === "label";
11423
+ }
11424
+ function isAnnotationTag(tag) {
11425
+ return tag.kind === "annotation";
11426
+ }
11427
+ function isEntityTag(tag) {
11428
+ return ENTITY_KINDS.includes(tag.kind);
11429
+ }
11430
+ function tagsOfGroup(tags, group) {
11431
+ return tags.filter(group === "label" ? isLabelTag : isAnnotationTag);
11432
+ }
11433
+ function tagsForScope(tags, scope) {
11434
+ return tags.filter((tag) => {
11435
+ const onDocs = (tag.doctag_count ?? 0) > 0;
11436
+ const onFacts = (tag.facttag_count ?? 0) > 0;
11437
+ if (!onDocs && !onFacts) return true;
11438
+ return scope === "document" ? onDocs : onFacts;
11439
+ });
11440
+ }
11441
+ var TAG_NESTING_MAX_DEPTH = 2;
11442
+ function indexByExternalId(tags) {
11443
+ return new Map(tags.map((tag) => [tag.external_id, tag]));
11444
+ }
11445
+ function resolveParentId(tag, byId3) {
11446
+ const parentId = tag.parent_ext_id;
11447
+ if (!parentId || parentId === tag.external_id) return null;
11448
+ return byId3.has(parentId) ? parentId : null;
11449
+ }
11450
+ function buildChildIndex(tags) {
11451
+ const byId3 = indexByExternalId(tags);
11452
+ const childrenOf = /* @__PURE__ */ new Map();
11453
+ for (const tag of tags) {
11454
+ const parentId = resolveParentId(tag, byId3);
11455
+ if (!parentId) continue;
11456
+ const siblings = childrenOf.get(parentId);
11457
+ if (siblings) siblings.push(tag);
11458
+ else childrenOf.set(parentId, [tag]);
11459
+ }
11460
+ return childrenOf;
11461
+ }
11462
+ function getChildTags(tags, tagId) {
11463
+ return buildChildIndex(tags).get(tagId) ?? [];
11464
+ }
11465
+ function getTagDescendantIds(tags, tagId) {
11466
+ const childrenOf = buildChildIndex(tags);
11467
+ const found = /* @__PURE__ */ new Set();
11468
+ const queue = [...childrenOf.get(tagId) ?? []];
11469
+ while (queue.length > 0) {
11470
+ const tag = queue.shift();
11471
+ if (tag.external_id === tagId || found.has(tag.external_id)) continue;
11472
+ found.add(tag.external_id);
11473
+ queue.push(...childrenOf.get(tag.external_id) ?? []);
11474
+ }
11475
+ return found;
11476
+ }
11477
+ function flattenTagTree(tags) {
11478
+ const byId3 = indexByExternalId(tags);
11479
+ const childrenOf = buildChildIndex(tags);
11480
+ const rows = [];
11481
+ const emitted = /* @__PURE__ */ new Set();
11482
+ const visit = (tag, depth) => {
11483
+ if (emitted.has(tag.external_id)) return;
11484
+ emitted.add(tag.external_id);
11485
+ const children = childrenOf.get(tag.external_id) ?? [];
11486
+ rows.push({ tag, depth, childCount: children.length });
11487
+ for (const child of children) visit(child, depth + 1);
11488
+ };
11489
+ for (const tag of tags) {
11490
+ if (resolveParentId(tag, byId3) === null) visit(tag, 0);
11491
+ }
11492
+ for (const tag of tags) visit(tag, 0);
11493
+ return rows;
11494
+ }
11495
+ var isFlatKind = (kind) => FLAT_TAG_KINDS.includes(kind);
11496
+ function getEligibleParentTags(tags, tagId) {
11497
+ const byId3 = indexByExternalId(tags);
11498
+ const blocked = tagId ? getTagDescendantIds(tags, tagId) : /* @__PURE__ */ new Set();
11499
+ if (tagId) blocked.add(tagId);
11500
+ return tags.filter(
11501
+ (tag) => !blocked.has(tag.external_id) && resolveParentId(tag, byId3) === null && // Issues, people and organisations are flat: never a parent (the API refuses it).
11502
+ !isFlatKind(tag.kind)
11503
+ );
11504
+ }
11505
+ function wouldCreateTagCycle(tags, tagId, parentId) {
11506
+ if (!parentId) return false;
11507
+ if (parentId === tagId) return true;
11508
+ return getTagDescendantIds(tags, tagId).has(parentId);
11509
+ }
11510
+ function canTagHaveParent(tags, tagId) {
11511
+ return getChildTags(tags, tagId).length === 0;
11512
+ }
11513
+
11279
11514
  // src/listen/index.ts
11280
11515
  var listen_exports = {};
11281
11516
  __export(listen_exports, {
@@ -11598,18 +11833,22 @@ exports.ClaudeOrchestrator = ClaudeOrchestrator;
11598
11833
  exports.DEFAULT_AI_USD_PER_GBP = DEFAULT_AI_USD_PER_GBP;
11599
11834
  exports.DOC_TERMINAL_STATUSES = DOC_TERMINAL_STATUSES;
11600
11835
  exports.DRIVE_SYNC_VENDORS = DRIVE_SYNC_VENDORS;
11836
+ exports.ENTITY_KINDS = ENTITY_KINDS;
11601
11837
  exports.FLAT_TAG_KINDS = FLAT_TAG_KINDS;
11602
11838
  exports.FileConfigStore = FileConfigStore;
11603
11839
  exports.GOOGLE_VENDORS = GOOGLE_VENDORS;
11604
11840
  exports.IMANAGE_VENDORS = IMANAGE_VENDORS;
11605
11841
  exports.MAILBOX_SYNC_VENDORS = MAILBOX_SYNC_VENDORS;
11842
+ exports.MAX_RETRIEVE_DOC_IDS = MAX_RETRIEVE_DOC_IDS;
11606
11843
  exports.MICROSOFT_VENDORS = MICROSOFT_VENDORS;
11607
11844
  exports.OpenClawOrchestrator = OpenClawOrchestrator;
11845
+ exports.PRESENCE_KINDS = PRESENCE_KINDS;
11608
11846
  exports.PlanStepsError = PlanStepsError;
11609
11847
  exports.PublicBookingError = PublicBookingError;
11610
11848
  exports.SHAREPOINT_VENDORS = SHAREPOINT_VENDORS;
11611
11849
  exports.STEP_FIELD_OPTION_TONES = STEP_FIELD_OPTION_TONES;
11612
11850
  exports.TAG_KINDS = TAG_KINDS;
11851
+ exports.TAG_NESTING_MAX_DEPTH = TAG_NESTING_MAX_DEPTH;
11613
11852
  exports.WebSocketAuthError = WebSocketAuthError;
11614
11853
  exports.account = account_exports;
11615
11854
  exports.agentconfig = agentconfig_exports;
@@ -11624,6 +11863,7 @@ exports.buildRetrievalChunkTool = buildRetrievalChunkTool;
11624
11863
  exports.buildRetrievalFullContextTool = buildRetrievalFullContextTool;
11625
11864
  exports.buildRetrievalTocTool = buildRetrievalTocTool;
11626
11865
  exports.calendar = calendar_exports;
11866
+ exports.canTagHaveParent = canTagHaveParent;
11627
11867
  exports.cancelPublicBooking = cancelPublicBooking;
11628
11868
  exports.chats = chats_exports;
11629
11869
  exports.connectErrorMessage = connectErrorMessage;
@@ -11636,14 +11876,17 @@ exports.conversations = conversations_exports;
11636
11876
  exports.countCitations = countCitations;
11637
11877
  exports.createAuthenticatedClient = createAuthenticatedClient;
11638
11878
  exports.createDocumentWaiter = createDocumentWaiter;
11879
+ exports.defaultKindForFormat = defaultKindForFormat;
11639
11880
  exports.deviceFlow = device_flow_exports;
11640
11881
  exports.doctags = doctags_exports;
11641
11882
  exports.documents = documents_exports;
11642
11883
  exports.documentsNode = documents_node_exports;
11643
11884
  exports.facts = facts_exports;
11644
11885
  exports.files = files_exports;
11886
+ exports.filterDocumentTags = filterDocumentTags;
11645
11887
  exports.filterSkills = filterSkills;
11646
11888
  exports.firm = firm_exports;
11889
+ exports.flattenTagTree = flattenTagTree;
11647
11890
  exports.formatAgentStepLabel = formatAgentStepLabel;
11648
11891
  exports.formatFileSize = formatFileSize;
11649
11892
  exports.formatGbp = formatGbp;
@@ -11655,17 +11898,25 @@ exports.formatWorkspaceChoices = formatWorkspaceChoices;
11655
11898
  exports.formatWsMessage = formatWsMessage;
11656
11899
  exports.generateEncryptedWorkspaceKey = generateEncryptedWorkspaceKey;
11657
11900
  exports.generateNewWorkspaceKey = generateNewWorkspaceKey;
11901
+ exports.getChildTags = getChildTags;
11902
+ exports.getEligibleParentTags = getEligibleParentTags;
11658
11903
  exports.getErrorCode = getErrorCode;
11659
11904
  exports.getErrorMessage = getErrorMessage;
11660
11905
  exports.getPublicBookingPage = getPublicBookingPage;
11661
11906
  exports.getRawWorkspaceKey = getRawWorkspaceKey;
11907
+ exports.getTagDescendantIds = getTagDescendantIds;
11662
11908
  exports.health = health_exports;
11663
11909
  exports.houseTemplates = house_template_exports;
11664
11910
  exports.identityErrorCode = identityErrorCode;
11665
11911
  exports.identityVerification = identity_exports;
11912
+ exports.isAnnotationTag = isAnnotationTag;
11666
11913
  exports.isConnectorVendorVisible = isConnectorVendorVisible;
11667
11914
  exports.isDriveSyncVendor = isDriveSyncVendor;
11915
+ exports.isEntityTag = isEntityTag;
11916
+ exports.isFlatKind = isFlatKind;
11917
+ exports.isLabelTag = isLabelTag;
11668
11918
  exports.isMailboxSyncVendor = isMailboxSyncVendor;
11919
+ exports.isPresenceTag = isPresenceTag;
11669
11920
  exports.isSharePointVendor = isSharePointVendor;
11670
11921
  exports.isSharedSkill = isSharedSkill;
11671
11922
  exports.listen = listen_exports;
@@ -11680,28 +11931,33 @@ exports.performSigningKeyLogin = performSigningKeyLogin;
11680
11931
  exports.performSsoDeviceFlowLogin = performSsoDeviceFlowLogin;
11681
11932
  exports.profile = profile_exports;
11682
11933
  exports.projects = projects_exports;
11934
+ exports.refusalReason = refusalReason;
11683
11935
  exports.requireData = requireData;
11684
11936
  exports.requireOk = requireOk;
11685
11937
  exports.resolveAuth = resolveAuth;
11686
11938
  exports.resolveCitations = resolveCitations;
11687
11939
  exports.resolveWorkspace = resolveWorkspace;
11688
11940
  exports.responses = responses_exports;
11941
+ exports.searchChunks = searchChunks;
11689
11942
  exports.selectWorkspace = selectWorkspace;
11690
11943
  exports.selectWorkspaceById = selectWorkspaceById;
11691
11944
  exports.sessions = sessions_exports;
11692
11945
  exports.settings = settings_exports;
11693
11946
  exports.signatureRequests = signature_requests_exports;
11694
- exports.splitAppPasswords = splitAppPasswords;
11695
11947
  exports.startDmListener = startDmListener;
11696
11948
  exports.streamSSE = streamSSE;
11697
11949
  exports.stripCitationMarkdown = stripCitationMarkdown;
11698
11950
  exports.summarizeCitations = summarizeCitations;
11951
+ exports.tagUseCount = tagUseCount;
11699
11952
  exports.tags = tags_exports;
11953
+ exports.tagsForScope = tagsForScope;
11954
+ exports.tagsOfGroup = tagsOfGroup;
11700
11955
  exports.uploadSkill = uploadSkill;
11701
11956
  exports.usdToGbp = usdToGbp;
11702
11957
  exports.work = work_exports;
11703
11958
  exports.workflowSteps = workflow_steps_exports;
11704
11959
  exports.workflows = workflows_exports;
11705
11960
  exports.workspaces = workspaces_exports;
11961
+ exports.wouldCreateTagCycle = wouldCreateTagCycle;
11706
11962
  //# sourceMappingURL=index.cjs.map
11707
11963
  //# sourceMappingURL=index.cjs.map