@arbidocs/sdk 0.5.165 → 0.5.167

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
@@ -3489,6 +3489,75 @@ var init_libsodium_wrappers = __esm({
3489
3489
  }
3490
3490
  });
3491
3491
 
3492
+ // src/media-transcript.ts
3493
+ var record = (value) => !!value && typeof value === "object";
3494
+ var validTime = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0;
3495
+ function parseTimestampedTranscript(text2) {
3496
+ const segments = [];
3497
+ for (const line of text2.split("\n")) {
3498
+ const match = /^\s*`?(\d+:\d{2}(?::\d{2})?(?:\.\d+)?)`?\s+(?:\*\*([^*]+)\*\*:\s*)?(.*)$/.exec(
3499
+ line
3500
+ );
3501
+ if (match) {
3502
+ const parts = match[1].split(":").map(Number);
3503
+ if (parts.slice(1).some((part) => part >= 60)) continue;
3504
+ const start = parts.reduce((total, part) => total * 60 + part, 0);
3505
+ if (!validTime(start)) continue;
3506
+ segments.push({ start, end: null, speaker: match[2] || null, text: match[3].trim() });
3507
+ } else if (segments.length && line.trim()) {
3508
+ segments[segments.length - 1].text += "\n" + line.trim();
3509
+ }
3510
+ }
3511
+ return segments.filter((segment) => segment.text).sort((a2, b2) => a2.start - b2.start);
3512
+ }
3513
+ function documentTranscript(document) {
3514
+ if (!record(document) || !Array.isArray(document.chunks)) return [];
3515
+ const passages = document.chunks.flatMap((chunk2) => {
3516
+ if (!record(chunk2)) return [];
3517
+ const timing = record(chunk2.metadata) ? chunk2.metadata.transcript : null;
3518
+ if (record(timing) && validTime(timing.start) && typeof chunk2.content === "string" && (timing.end == null || validTime(timing.end) && timing.end >= timing.start)) {
3519
+ const prose = parseTimestampedTranscript(chunk2.content)[0];
3520
+ return [
3521
+ {
3522
+ start: timing.start,
3523
+ end: timing.end ?? null,
3524
+ speaker: prose?.speaker ?? null,
3525
+ text: prose?.text ?? chunk2.content
3526
+ }
3527
+ ];
3528
+ }
3529
+ return typeof chunk2.content === "string" ? parseTimestampedTranscript(chunk2.content) : [];
3530
+ }).sort((a2, b2) => a2.start - b2.start);
3531
+ const merged = [];
3532
+ for (const passage of passages) {
3533
+ const previous = merged[merged.length - 1];
3534
+ if (previous && previous.start === passage.start && previous.end === passage.end && (passage.speaker == null || passage.speaker === previous.speaker)) {
3535
+ previous.text += "\n" + passage.text;
3536
+ } else merged.push({ ...passage });
3537
+ }
3538
+ return merged;
3539
+ }
3540
+ function transcriptEnd(segments, index, duration) {
3541
+ return segments[index].end ?? segments[index + 1]?.start ?? (validTime(duration) ? duration : null);
3542
+ }
3543
+ var vttTime = (seconds) => {
3544
+ const ms = Math.round(seconds * 1e3);
3545
+ return `${String(Math.floor(ms / 36e5)).padStart(2, "0")}:${String(Math.floor(ms / 6e4) % 60).padStart(2, "0")}:${String(Math.floor(ms / 1e3) % 60).padStart(2, "0")}.${String(ms % 1e3).padStart(3, "0")}`;
3546
+ };
3547
+ function transcriptToWebVtt(segments, duration) {
3548
+ const escape2 = (text2) => text2.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
3549
+ return "WEBVTT\n\n" + segments.flatMap((segment, index) => {
3550
+ const end = transcriptEnd(segments, index, duration);
3551
+ if (end == null || end <= segment.start) return [];
3552
+ return [
3553
+ `${index + 1}
3554
+ ${vttTime(segment.start)} --> ${vttTime(end)}
3555
+ ${escape2(segment.speaker ? `${segment.speaker}: ${segment.text}` : segment.text)}
3556
+ `
3557
+ ];
3558
+ }).join("\n");
3559
+ }
3560
+
3492
3561
  // src/errors.ts
3493
3562
  var ArbiError = class extends Error {
3494
3563
  code;
@@ -5241,16 +5310,41 @@ async function createSupportTicket(arbi, input) {
5241
5310
  if (input.screenshot && (input.screenshot.type !== "image/png" || input.screenshot.size > 2 * 1024 * 1024))
5242
5311
  throw new ArbiError("The screenshot must be a PNG image no larger than 2 MB.");
5243
5312
  const screenshot = input.screenshot ? bytesToBase64(new Uint8Array(await input.screenshot.arrayBuffer())) : void 0;
5244
- return requireData(
5313
+ if (input.video && (!["video/webm", "video/mp4"].includes(input.video.type.split(";")[0]) || !input.video.size || input.video.size > 200 * 1024 * 1024))
5314
+ throw new ArbiError("Choose a WebM or MP4 video no larger than 200 MB.");
5315
+ if ((input.videoTranscript?.length ?? 0) > 1e4)
5316
+ throw new ArbiError("The video transcript is too long.");
5317
+ const receipt = requireData(
5245
5318
  await arbi.fetch.POST("/v1/support/tickets", {
5246
5319
  body: {
5247
5320
  description: input.description.trim(),
5248
5321
  idempotency_key: input.idempotencyKey ?? crypto.randomUUID(),
5249
- ...screenshot ? { screenshot_png: screenshot } : {}
5322
+ ...screenshot ? { screenshot_png: screenshot } : {},
5323
+ ...input.context ? { client_context: input.context } : {}
5250
5324
  }
5251
5325
  }),
5252
5326
  "Could not send your support request."
5253
5327
  );
5328
+ if (input.video) {
5329
+ requireData(
5330
+ await arbi.fetch.POST("/v1/support/tickets/{ticket_id}/video", {
5331
+ params: { path: { ticket_id: receipt.ticket_id } },
5332
+ body: { video: input.video, transcript: input.videoTranscript ?? "" },
5333
+ bodySerializer: (body) => {
5334
+ const form = new FormData();
5335
+ form.append(
5336
+ "video",
5337
+ body.video,
5338
+ input.video.type.startsWith("video/mp4") ? "support.mp4" : "support.webm"
5339
+ );
5340
+ form.append("transcript", body.transcript ?? "");
5341
+ return form;
5342
+ }
5343
+ }),
5344
+ "Your request was received, but its video could not be attached. Retry to attach it to the same request."
5345
+ );
5346
+ }
5347
+ return receipt;
5254
5348
  }
5255
5349
  async function listSupportTickets(arbi) {
5256
5350
  return requireData(
@@ -6643,8 +6737,7 @@ function requireUploadData(result, message) {
6643
6737
  return requireWorkspaceData(result, message, UPLOAD_WORKSPACE_CONFLICT_MESSAGES);
6644
6738
  }
6645
6739
  async function uploadDocuments(arbi, files, options = {}) {
6646
- const query2 = {};
6647
- if (options.shared !== void 0) query2.shared = options.shared;
6740
+ const query2 = { shared: options.shared ?? false };
6648
6741
  if (options.folder) query2.folder = sanitizeFolderPath(options.folder);
6649
6742
  if (options.configExtId) query2.config_ext_id = options.configExtId;
6650
6743
  if (options.wpType) query2.wp_type = options.wpType;
@@ -6706,7 +6799,7 @@ async function uploadFile(auth, fileData, fileName, options) {
6706
6799
  const formData = new FormData();
6707
6800
  formData.append("files", fileData, fileName);
6708
6801
  const params = new URLSearchParams();
6709
- if (options?.shared !== void 0) params.set("shared", String(options.shared));
6802
+ params.set("shared", String(options?.shared ?? false));
6710
6803
  if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
6711
6804
  if (options?.configExtId) params.set("config_ext_id", options.configExtId);
6712
6805
  if (options?.wpType) params.set("wp_type", options.wpType);
@@ -6731,7 +6824,7 @@ async function uploadFile(auth, fileData, fileName, options) {
6731
6824
  async function uploadFiles(auth, files, options) {
6732
6825
  const formData = new FormData();
6733
6826
  for (const f2 of files) formData.append("files", f2.data, f2.name);
6734
- const params = new URLSearchParams();
6827
+ const params = new URLSearchParams({ shared: String(options?.shared ?? false) });
6735
6828
  if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
6736
6829
  if (options?.configExtId) params.set("config_ext_id", options.configExtId);
6737
6830
  if (options?.wpType) params.set("wp_type", options.wpType);
@@ -6851,7 +6944,7 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
6851
6944
  }
6852
6945
  const initBody = {
6853
6946
  files: declared,
6854
- shared: options.shared !== false,
6947
+ shared: options.shared ?? false,
6855
6948
  config_ext_id: options.configExtId ?? null,
6856
6949
  // Only sent when set, so a plain upload is accepted by any server version.
6857
6950
  ...options.versionOf ? { version_of: options.versionOf } : {},
@@ -7461,6 +7554,7 @@ __export(assistant_exports, {
7461
7554
  WORKSPACE_CONFLICT_MESSAGES: () => WORKSPACE_CONFLICT_MESSAGES,
7462
7555
  cancelRun: () => cancelRun,
7463
7556
  filterSkills: () => filterSkills,
7557
+ getPlatformActions: () => getPlatformActions,
7464
7558
  interject: () => interject,
7465
7559
  isSharedSkill: () => isSharedSkill,
7466
7560
  listCommands: () => listCommands,
@@ -7809,15 +7903,24 @@ async function listCommands(arbi) {
7809
7903
  );
7810
7904
  return result.commands;
7811
7905
  }
7812
- async function transcribe(arbi, audio) {
7906
+ async function getPlatformActions(arbi, options) {
7907
+ return requireData(
7908
+ await arbi.fetch.GET("/v1/assistant/platform-actions", {
7909
+ params: { query: options }
7910
+ }),
7911
+ "Failed to discover platform actions"
7912
+ );
7913
+ }
7914
+ async function transcribe(arbi, audio, options = {}) {
7813
7915
  const result = requireData(
7814
7916
  await arbi.fetch.POST("/v1/assistant/transcribe", {
7815
7917
  // The generated type of a multipart binary field is `string`; the value is the Blob, sent as
7816
7918
  // real form data (openapi-fetch would JSON-encode a plain object).
7817
- body: { audio },
7919
+ body: { audio, diarize: options.diarize ?? false },
7818
7920
  bodySerializer: (body) => {
7819
7921
  const form = new FormData();
7820
7922
  form.append("audio", body.audio, "voice-input.webm");
7923
+ if (options.diarize) form.append("diarize", "true");
7821
7924
  return form;
7822
7925
  }
7823
7926
  }),
@@ -14030,8 +14133,10 @@ var Arbi = class {
14030
14133
  cancel: (responseId) => this.recovering(() => cancelRun(this.getAuthHeaders(), responseId)),
14031
14134
  /** The backend's built-in slash commands (`/compact`, `/goal`, …), for a slash menu. */
14032
14135
  commands: () => listCommands(this.requireClient()),
14136
+ /** Live domain operations and input schemas shared with tools, slash commands and the CLI. */
14137
+ platformActions: (options) => getPlatformActions(this.requireClient(), options),
14033
14138
  /** Transcribe a voice recording to text (empty when no speech was found). */
14034
- transcribe: (audio) => transcribe(this.requireClient(), audio),
14139
+ transcribe: (audio, options) => transcribe(this.requireClient(), audio, options),
14035
14140
  /** Start a durable background turn; task options make its thread a work item. */
14036
14141
  submit: (question, options) => {
14037
14142
  const workspaceId = options.workspaceId ?? this.requireWorkspace();
@@ -14779,9 +14884,9 @@ var Arbi = class {
14779
14884
  */
14780
14885
  get: async (workflowId) => {
14781
14886
  const client = this.requireClient();
14782
- const record = await getWorkflow(client, workflowId);
14783
- if (!record.workspace_ext_id || record.plan || record.source_workflow_ext_id) return record;
14784
- await this.primeOrFail(record.workspace_ext_id);
14887
+ const record2 = await getWorkflow(client, workflowId);
14888
+ if (!record2.workspace_ext_id || record2.plan || record2.source_workflow_ext_id) return record2;
14889
+ await this.primeOrFail(record2.workspace_ext_id);
14785
14890
  return getWorkflow(client, workflowId);
14786
14891
  },
14787
14892
  /**
@@ -14793,8 +14898,8 @@ var Arbi = class {
14793
14898
  */
14794
14899
  start: async (workflowId, options = {}) => {
14795
14900
  const client = this.requireClient();
14796
- const record = await getWorkflow(client, workflowId);
14797
- if (record.workspace_ext_id) await this.primeOrFail(record.workspace_ext_id);
14901
+ const record2 = await getWorkflow(client, workflowId);
14902
+ if (record2.workspace_ext_id) await this.primeOrFail(record2.workspace_ext_id);
14798
14903
  const target = await this.requireTargetWorkspace(options.workspaceId);
14799
14904
  return this.recovering(
14800
14905
  () => createWork(
@@ -16335,6 +16440,9 @@ function hydrateAgentSteps(message) {
16335
16440
  const streamEvents = tools["stream_events"];
16336
16441
  if (!streamEvents || !("events" in streamEvents)) return void 0;
16337
16442
  const events = streamEvents.events;
16443
+ return hydrateAgentEvents(events);
16444
+ }
16445
+ function hydrateAgentEvents(events) {
16338
16446
  if (!Array.isArray(events) || events.length === 0) return void 0;
16339
16447
  const hasV3 = events.some(
16340
16448
  (e) => typeof e === "object" && e !== null && e.type === "response.output_item.done"
@@ -16892,6 +17000,7 @@ exports.deviceFlow = device_flow_exports;
16892
17000
  exports.diagnoseSetup = diagnoseSetup;
16893
17001
  exports.doctags = doctags_exports;
16894
17002
  exports.documentTools = documentTools;
17003
+ exports.documentTranscript = documentTranscript;
16895
17004
  exports.documents = documents_exports;
16896
17005
  exports.documentsNode = documents_node_exports;
16897
17006
  exports.estimateDraftTokens = estimateDraftTokens;
@@ -16941,6 +17050,7 @@ exports.getSubagentBranchRecord = getSubagentBranchRecord;
16941
17050
  exports.getTagDescendantIds = getTagDescendantIds;
16942
17051
  exports.health = health_exports;
16943
17052
  exports.houseTemplates = house_template_exports;
17053
+ exports.hydrateAgentEvents = hydrateAgentEvents;
16944
17054
  exports.hydrateAgentSteps = hydrateAgentSteps;
16945
17055
  exports.identityErrorCode = identityErrorCode;
16946
17056
  exports.identityVerification = identity_exports;
@@ -16969,6 +17079,7 @@ exports.parseSSEEvents = parseSSEEvents;
16969
17079
  exports.parseSlashCommand = parseSlashCommand;
16970
17080
  exports.parseSlashTokenInProgress = parseSlashTokenInProgress;
16971
17081
  exports.parseStructuredResponse = parseStructuredResponse;
17082
+ exports.parseTimestampedTranscript = parseTimestampedTranscript;
16972
17083
  exports.performPasswordLogin = performPasswordLogin;
16973
17084
  exports.performSigningKeyLogin = performSigningKeyLogin;
16974
17085
  exports.performSsoDeviceFlowLogin = performSsoDeviceFlowLogin;
@@ -17007,6 +17118,8 @@ exports.tags = tags_exports;
17007
17118
  exports.tagsForScope = tagsForScope;
17008
17119
  exports.tagsOfGroup = tagsOfGroup;
17009
17120
  exports.topLevelAgentSteps = topLevelAgentSteps;
17121
+ exports.transcriptEnd = transcriptEnd;
17122
+ exports.transcriptToWebVtt = transcriptToWebVtt;
17010
17123
  exports.uploadSkill = uploadSkill;
17011
17124
  exports.usdToGbp = usdToGbp;
17012
17125
  exports.views = views_exports;