@arbidocs/sdk 0.5.102 → 0.5.104
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-cpW45ipJ.d.ts → browser-BzLWSu_d.d.ts} +111 -11
- package/dist/{browser-DxQ_g7eh.d.cts → browser-CchVT5yc.d.cts} +111 -11
- package/dist/browser.cjs +1890 -1790
- 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 +1890 -1790
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +1908 -1808
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1908 -1808
- package/dist/index.js.map +1 -1
- package/examples/human-review/package.json +1 -1
- package/examples/react-chat/package.json +2 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5274,1922 +5274,1938 @@ function withSupportNotificationReference(notification, domain) {
|
|
|
5274
5274
|
}
|
|
5275
5275
|
}
|
|
5276
5276
|
|
|
5277
|
-
// src/
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
const domain = body?.deployment?.domain;
|
|
5316
|
-
if (typeof domain !== "string" || !domain) {
|
|
5317
|
-
add(
|
|
5318
|
-
"deployment",
|
|
5319
|
-
"warning",
|
|
5320
|
-
"The deployment did not advertise its key-derivation domain.",
|
|
5321
|
-
"Confirm deploymentDomain with the deployment owner, especially when using a proxy."
|
|
5322
|
-
);
|
|
5323
|
-
} else if (domain !== (options.deploymentDomain ?? base.hostname)) {
|
|
5324
|
-
add(
|
|
5325
|
-
"deployment",
|
|
5326
|
-
"error",
|
|
5327
|
-
"The configured key-derivation domain differs from the deployment.",
|
|
5328
|
-
"Set deploymentDomain to the deployment\u2019s domain; a proxy hostname is not the key-derivation domain."
|
|
5329
|
-
);
|
|
5330
|
-
} else add("deployment", "ok", "The key-derivation domain matches the deployment.");
|
|
5331
|
-
}
|
|
5332
|
-
} catch {
|
|
5333
|
-
add(
|
|
5334
|
-
"connection",
|
|
5335
|
-
"error",
|
|
5336
|
-
"Could not read deployment configuration.",
|
|
5337
|
-
"Check DNS, TLS, proxy routing and connectivity. In a browser, inspect DevTools for CORS, mixed-content or private-network denial; fetch alone cannot distinguish them."
|
|
5338
|
-
);
|
|
5339
|
-
}
|
|
5340
|
-
if (!options.accessToken) {
|
|
5341
|
-
add(
|
|
5342
|
-
"authentication",
|
|
5343
|
-
"warning",
|
|
5344
|
-
"No live session token is available.",
|
|
5345
|
-
"Sign in explicitly when online. An offline-unlocked identity is not a verified server session."
|
|
5346
|
-
);
|
|
5347
|
-
add("workspace", "skipped", "Workspace access was not checked.");
|
|
5348
|
-
add("permissions", "skipped", "Permissions were not checked.");
|
|
5349
|
-
} else {
|
|
5350
|
-
let authenticated = false;
|
|
5351
|
-
try {
|
|
5352
|
-
const user = await request("/v1/user/me", true);
|
|
5353
|
-
if (!user.ok) {
|
|
5354
|
-
add(
|
|
5355
|
-
"authentication",
|
|
5356
|
-
"error",
|
|
5357
|
-
`Session check returned HTTP ${user.status}.`,
|
|
5358
|
-
user.status === 401 ? "Sign in explicitly to renew the session." : "Check deployment access and account permissions."
|
|
5359
|
-
);
|
|
5360
|
-
add("workspace", "skipped", "Workspace access was not checked.");
|
|
5361
|
-
add("permissions", "skipped", "Permissions were not checked.");
|
|
5362
|
-
} else {
|
|
5363
|
-
const profile = await user.json();
|
|
5364
|
-
authenticated = true;
|
|
5365
|
-
add("authentication", "ok", "The server accepts the current session.");
|
|
5366
|
-
if (!options.workspaceId) {
|
|
5367
|
-
add(
|
|
5368
|
-
"workspace",
|
|
5369
|
-
"warning",
|
|
5370
|
-
"No current workspace is selected.",
|
|
5371
|
-
"Choose a workspace explicitly before reading documents or starting work."
|
|
5372
|
-
);
|
|
5373
|
-
add("permissions", "skipped", "Select a workspace to check membership.");
|
|
5374
|
-
} else {
|
|
5375
|
-
const response = await request("/v1/user/workspaces", true);
|
|
5376
|
-
if (!response.ok) {
|
|
5377
|
-
add(
|
|
5378
|
-
"workspace",
|
|
5379
|
-
"error",
|
|
5380
|
-
`Workspace membership check returned HTTP ${response.status}.`,
|
|
5381
|
-
"Check current account access; diagnosis does not switch workspaces or grant access."
|
|
5382
|
-
);
|
|
5383
|
-
add("permissions", "skipped", "Membership could not be verified.");
|
|
5384
|
-
} else {
|
|
5385
|
-
const workspaces = await response.json();
|
|
5386
|
-
const workspace = Array.isArray(workspaces) ? workspaces.find((w2) => w2.external_id === options.workspaceId) : void 0;
|
|
5387
|
-
if (!workspace) {
|
|
5388
|
-
add(
|
|
5389
|
-
"workspace",
|
|
5390
|
-
"error",
|
|
5391
|
-
"The selected workspace is not in this account\u2019s workspace list.",
|
|
5392
|
-
"Choose an accessible workspace explicitly. Project visibility does not imply workspace access."
|
|
5393
|
-
);
|
|
5394
|
-
add("permissions", "skipped", "Workspace permissions could not be verified.");
|
|
5395
|
-
} else {
|
|
5396
|
-
add(
|
|
5397
|
-
"workspace",
|
|
5398
|
-
"ok",
|
|
5399
|
-
"The selected workspace appears in the account\u2019s workspace list."
|
|
5400
|
-
);
|
|
5401
|
-
const member = workspace.users?.find(
|
|
5402
|
-
(entry) => entry.user?.external_id === profile.external_id
|
|
5403
|
-
);
|
|
5404
|
-
const role = ["owner", "collaborator", "guest"].includes(member?.role) ? member.role : null;
|
|
5405
|
-
add(
|
|
5406
|
-
"permissions",
|
|
5407
|
-
role ? "ok" : "warning",
|
|
5408
|
-
role ? `Workspace membership role: ${role}.` : "No direct membership role was reported.",
|
|
5409
|
-
"This is a membership check, not proof of a live workspace key or authorization for an agent task. Temporary grants, expiry and execution permissions remain enforced by the API."
|
|
5410
|
-
);
|
|
5411
|
-
}
|
|
5412
|
-
}
|
|
5413
|
-
}
|
|
5414
|
-
}
|
|
5415
|
-
} catch {
|
|
5416
|
-
add(
|
|
5417
|
-
authenticated ? "workspace" : "authentication",
|
|
5418
|
-
"error",
|
|
5419
|
-
authenticated ? "The workspace membership check could not finish." : "The session check could not finish.",
|
|
5420
|
-
"Check connectivity and browser network policy. No login, workspace switch or grant was attempted."
|
|
5421
|
-
);
|
|
5422
|
-
if (authenticated)
|
|
5423
|
-
add("permissions", "skipped", "Workspace membership could not be verified.");
|
|
5424
|
-
}
|
|
5425
|
-
}
|
|
5426
|
-
return { ok: checks.every((c2) => c2.status === "ok"), checks };
|
|
5427
|
-
}
|
|
5428
|
-
|
|
5429
|
-
// src/operations/responses.ts
|
|
5430
|
-
var responses_exports = {};
|
|
5431
|
-
__export(responses_exports, {
|
|
5432
|
-
extractResponseText: () => extractResponseText,
|
|
5433
|
-
getResponse: () => getResponse,
|
|
5434
|
-
submitBackgroundQuery: () => submitBackgroundQuery
|
|
5435
|
-
});
|
|
5436
|
-
async function submitBackgroundQuery(options) {
|
|
5437
|
-
const {
|
|
5438
|
-
workspaceId,
|
|
5439
|
-
question,
|
|
5440
|
-
docIds,
|
|
5441
|
-
previousResponseId,
|
|
5442
|
-
model,
|
|
5443
|
-
text: text2,
|
|
5444
|
-
task,
|
|
5445
|
-
conversationId,
|
|
5446
|
-
mentions,
|
|
5447
|
-
activeArtifactExtId,
|
|
5448
|
-
fullContext = true,
|
|
5449
|
-
...auth
|
|
5450
|
-
} = options;
|
|
5451
|
-
const tools = {};
|
|
5452
|
-
if (docIds.length > 0) {
|
|
5453
|
-
tools.retrieval_chunk = {
|
|
5454
|
-
name: "retrieval_chunk",
|
|
5455
|
-
description: "retrieval chunk",
|
|
5456
|
-
tool_args: { doc_ext_ids: docIds },
|
|
5457
|
-
tool_responses: {}
|
|
5458
|
-
};
|
|
5459
|
-
if (fullContext)
|
|
5460
|
-
tools.retrieval_full_context = {
|
|
5461
|
-
name: "retrieval_full_context",
|
|
5462
|
-
description: "retrieval full context",
|
|
5463
|
-
tool_args: { doc_ext_ids: docIds },
|
|
5464
|
-
tool_responses: {}
|
|
5465
|
-
};
|
|
5466
|
-
}
|
|
5467
|
-
const body = {
|
|
5468
|
-
input: question,
|
|
5469
|
-
workspace_ext_id: workspaceId,
|
|
5470
|
-
stream: false,
|
|
5471
|
-
background: true,
|
|
5472
|
-
store: true,
|
|
5473
|
-
tools,
|
|
5474
|
-
...task !== void 0 ? { task } : {},
|
|
5475
|
-
...conversationId ? { conversation_ext_id: conversationId } : {},
|
|
5476
|
-
...mentions !== void 0 ? { mentions } : {},
|
|
5477
|
-
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
5478
|
-
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
5479
|
-
...model ? { model } : {},
|
|
5480
|
-
...text2 ? { text: text2 } : {}
|
|
5481
|
-
};
|
|
5482
|
-
const res = await authenticatedFetch({
|
|
5483
|
-
...auth,
|
|
5484
|
-
path: "/v1/responses",
|
|
5485
|
-
method: "POST",
|
|
5486
|
-
body: JSON.stringify(body),
|
|
5487
|
-
headers: { "Content-Type": "application/json" }
|
|
5488
|
-
});
|
|
5489
|
-
return await res.json();
|
|
5490
|
-
}
|
|
5491
|
-
async function getResponse(auth, responseId) {
|
|
5492
|
-
const res = await authenticatedFetch({
|
|
5493
|
-
...auth,
|
|
5494
|
-
path: `/v1/responses/${responseId}`,
|
|
5495
|
-
method: "GET"
|
|
5496
|
-
});
|
|
5497
|
-
return await res.json();
|
|
5498
|
-
}
|
|
5499
|
-
function extractResponseText(response) {
|
|
5500
|
-
const parts = [];
|
|
5501
|
-
for (const msg of Array.isArray(response.output) ? response.output : []) {
|
|
5502
|
-
if (msg.type !== "message" || !Array.isArray(msg.content)) continue;
|
|
5503
|
-
for (const item of msg.content) {
|
|
5504
|
-
if (item?.type === "output_text" && typeof item.text === "string") parts.push(item.text);
|
|
5505
|
-
}
|
|
5506
|
-
}
|
|
5507
|
-
return parts.join("");
|
|
5508
|
-
}
|
|
5509
|
-
|
|
5510
|
-
// src/responses-resource.ts
|
|
5511
|
-
function withOutputText(response, requestId) {
|
|
5512
|
-
return {
|
|
5513
|
-
...response,
|
|
5514
|
-
output_text: extractResponseText(response),
|
|
5515
|
-
...requestId ? { _request_id: requestId } : {}
|
|
5516
|
-
};
|
|
5517
|
-
}
|
|
5518
|
-
var ResponseStream = class {
|
|
5519
|
-
constructor(handle) {
|
|
5520
|
-
this.handle = handle;
|
|
5521
|
-
}
|
|
5522
|
-
handle;
|
|
5523
|
-
async *[Symbol.asyncIterator]() {
|
|
5524
|
-
try {
|
|
5525
|
-
for await (const frame of this.handle.events()) {
|
|
5526
|
-
const data = frame.data && typeof frame.data === "object" && !Array.isArray(frame.data) ? frame.data : { data: frame.data };
|
|
5527
|
-
yield {
|
|
5528
|
-
...data,
|
|
5529
|
-
type: typeof data.type === "string" ? data.type : frame.event
|
|
5530
|
-
};
|
|
5531
|
-
}
|
|
5532
|
-
const outcome = await this.handle.outcome;
|
|
5533
|
-
if (outcome.status === "disconnected")
|
|
5534
|
-
throw outcome.error ?? new ArbiTransportError(new Error("The response stream disconnected."), this.handle.id);
|
|
5535
|
-
} finally {
|
|
5536
|
-
this.handle.detach();
|
|
5537
|
-
}
|
|
5538
|
-
}
|
|
5539
|
-
};
|
|
5540
|
-
|
|
5541
|
-
// src/structured-output.ts
|
|
5542
|
-
var ArbiStructuredOutputError = class extends ArbiError {
|
|
5543
|
-
constructor(message, response, options) {
|
|
5544
|
-
const id = response && typeof response === "object" && "id" in response && typeof response.id === "string" ? response.id : void 0;
|
|
5545
|
-
super(message, { responseId: id, ...options });
|
|
5546
|
-
this.response = response;
|
|
5547
|
-
this.name = "ArbiStructuredOutputError";
|
|
5548
|
-
}
|
|
5549
|
-
response;
|
|
5277
|
+
// src/operations/workspaces.ts
|
|
5278
|
+
var workspaces_exports = {};
|
|
5279
|
+
__export(workspaces_exports, {
|
|
5280
|
+
EXTERNAL_ACCESS_SECONDS: () => EXTERNAL_ACCESS_SECONDS,
|
|
5281
|
+
WORKSPACE_ROLE_LABELS: () => WORKSPACE_ROLE_LABELS,
|
|
5282
|
+
addWorkspaceMembers: () => addWorkspaceMembers,
|
|
5283
|
+
addWorkspaceMembersBody: () => addWorkspaceMembersBody,
|
|
5284
|
+
addWorkspaceUsers: () => addWorkspaceUsers,
|
|
5285
|
+
archiveWorkspace: () => archiveWorkspace,
|
|
5286
|
+
cancelWorkspaceTransfer: () => cancelWorkspaceTransfer,
|
|
5287
|
+
copyDocuments: () => copyDocuments,
|
|
5288
|
+
createWorkspace: () => createWorkspace,
|
|
5289
|
+
deleteWorkspaces: () => deleteWorkspaces,
|
|
5290
|
+
exportWorkspaceData: () => exportWorkspaceData,
|
|
5291
|
+
getWorkspaceAccessStatus: () => getWorkspaceAccessStatus,
|
|
5292
|
+
getWorkspaceActivity: () => getWorkspaceActivity,
|
|
5293
|
+
getWorkspaceArchive: () => getWorkspaceArchive,
|
|
5294
|
+
getWorkspaceTransfer: () => getWorkspaceTransfer,
|
|
5295
|
+
grantTemporaryWorkspaceAccess: () => grantTemporaryWorkspaceAccess,
|
|
5296
|
+
listWorkspaceTransfers: () => listWorkspaceTransfers,
|
|
5297
|
+
listWorkspaceUsers: () => listWorkspaceUsers,
|
|
5298
|
+
listWorkspaces: () => listWorkspaces,
|
|
5299
|
+
moveWorkspaceToProject: () => moveWorkspaceToProject,
|
|
5300
|
+
parseWorkspaceRole: () => parseWorkspaceRole,
|
|
5301
|
+
planWorkspaceTransfer: () => planWorkspaceTransfer,
|
|
5302
|
+
primeWorkspaceKey: () => primeWorkspaceKey,
|
|
5303
|
+
removeWorkspaceUsers: () => removeWorkspaceUsers,
|
|
5304
|
+
resumeWorkspaceTransfer: () => resumeWorkspaceTransfer,
|
|
5305
|
+
setUserRole: () => setUserRole,
|
|
5306
|
+
startWorkspaceTransfer: () => startWorkspaceTransfer,
|
|
5307
|
+
unarchiveWorkspace: () => unarchiveWorkspace,
|
|
5308
|
+
updateWorkspace: () => updateWorkspace,
|
|
5309
|
+
workspaceRoleLabel: () => workspaceRoleLabel
|
|
5310
|
+
});
|
|
5311
|
+
var WORKSPACE_ROLE_LABELS = {
|
|
5312
|
+
owner: "Owner",
|
|
5313
|
+
collaborator: "Collaborator",
|
|
5314
|
+
guest: "Read only"
|
|
5550
5315
|
};
|
|
5551
|
-
function
|
|
5552
|
-
|
|
5553
|
-
value.forEach(localReferences);
|
|
5554
|
-
return;
|
|
5555
|
-
}
|
|
5556
|
-
if (!value || typeof value !== "object") return;
|
|
5557
|
-
for (const [key, child] of Object.entries(value)) {
|
|
5558
|
-
if ((key === "$ref" || key === "$dynamicRef") && (typeof child !== "string" || !child.startsWith("#")))
|
|
5559
|
-
throw new Error("Only local schema references are supported.");
|
|
5560
|
-
if (!["enum", "const", "default", "examples"].includes(key)) localReferences(child);
|
|
5561
|
-
}
|
|
5316
|
+
function workspaceRoleLabel(role) {
|
|
5317
|
+
return WORKSPACE_ROLE_LABELS[role] ?? role.charAt(0).toUpperCase() + role.slice(1);
|
|
5562
5318
|
}
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
Constructor = (await import('ajv/dist/2020.js')).default;
|
|
5568
|
-
} catch (cause) {
|
|
5569
|
-
throw new ArbiStructuredOutputError(
|
|
5570
|
-
"The JSON Schema validator could not be loaded.",
|
|
5571
|
-
void 0,
|
|
5572
|
-
{ code: "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE", cause }
|
|
5573
|
-
);
|
|
5574
|
-
}
|
|
5575
|
-
try {
|
|
5576
|
-
if (format.type !== "json_schema" || typeof format.name !== "string" || !/^[a-zA-Z0-9_-]{1,64}$/.test(format.name) || !format.schema || typeof format.schema !== "object" || Array.isArray(format.schema))
|
|
5577
|
-
throw new Error("Invalid structured output format.");
|
|
5578
|
-
if (format.schema.$schema !== void 0 && format.schema.$schema !== "https://json-schema.org/draft/2020-12/schema")
|
|
5579
|
-
throw new Error("Expected JSON Schema draft 2020-12.");
|
|
5580
|
-
localReferences(format.schema);
|
|
5581
|
-
validate = new Constructor({
|
|
5582
|
-
strict: false,
|
|
5583
|
-
logger: false,
|
|
5584
|
-
validateFormats: false,
|
|
5585
|
-
strictNumbers: true,
|
|
5586
|
-
addUsedSchema: false
|
|
5587
|
-
}).compile(format.schema);
|
|
5588
|
-
} catch (cause) {
|
|
5589
|
-
const unavailable = cause instanceof EvalError;
|
|
5590
|
-
throw new ArbiStructuredOutputError(
|
|
5591
|
-
unavailable ? "This runtime cannot compile JSON Schema validators." : "Invalid or unsupported output schema.",
|
|
5592
|
-
void 0,
|
|
5593
|
-
{
|
|
5594
|
-
code: unavailable ? "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE" : "STRUCTURED_OUTPUT_SCHEMA_INVALID",
|
|
5595
|
-
cause
|
|
5596
|
-
}
|
|
5597
|
-
);
|
|
5598
|
-
}
|
|
5599
|
-
return (response, options = {}) => {
|
|
5600
|
-
const fail = (code, message, cause) => {
|
|
5601
|
-
throw new ArbiStructuredOutputError(message, response, { ...options, code, cause });
|
|
5602
|
-
};
|
|
5603
|
-
if (!response || typeof response !== "object")
|
|
5604
|
-
fail("RESPONSE_INVALID_ENVELOPE", "Expected a Responses JSON object.");
|
|
5605
|
-
if (response.status === "incomplete")
|
|
5606
|
-
fail("RESPONSE_INCOMPLETE", "The response is incomplete; no validated data is available.");
|
|
5607
|
-
if (response.status === "cancelled")
|
|
5608
|
-
fail("RESPONSE_CANCELLED", "The response was cancelled; no validated data is available.");
|
|
5609
|
-
if (response.status === "failed")
|
|
5610
|
-
fail(
|
|
5611
|
-
typeof response.error?.code === "string" ? response.error.code : "RESPONSE_FAILED",
|
|
5612
|
-
typeof response.error?.message === "string" ? response.error.message : "The response failed."
|
|
5613
|
-
);
|
|
5614
|
-
if (response.status !== "completed")
|
|
5615
|
-
fail(
|
|
5616
|
-
"RESPONSE_NOT_COMPLETED",
|
|
5617
|
-
"Wait for a completed response before parsing structured output."
|
|
5618
|
-
);
|
|
5619
|
-
const messages = Array.isArray(response.output) ? response.output.filter(
|
|
5620
|
-
(item) => item && typeof item === "object" && item.type === "message" && item.role === "assistant"
|
|
5621
|
-
) : [];
|
|
5622
|
-
if (messages.some(
|
|
5623
|
-
(message) => !Array.isArray(message.content) || message.content.some((part) => !part || typeof part !== "object")
|
|
5624
|
-
))
|
|
5625
|
-
fail("RESPONSE_INVALID_ENVELOPE", "Invalid assistant output content.");
|
|
5626
|
-
if (messages.some((message) => message.content.some((part) => part.type === "refusal")))
|
|
5627
|
-
fail("RESPONSE_REFUSED", "The model refused this response.");
|
|
5628
|
-
const answers = messages.map(
|
|
5629
|
-
(message) => message.content.filter((part) => part.type === "output_text" && typeof part.text === "string").map((part) => part.text).join("")
|
|
5630
|
-
).filter((answer) => answer.length > 0);
|
|
5631
|
-
if (answers.length !== 1)
|
|
5632
|
-
fail(
|
|
5633
|
-
"STRUCTURED_OUTPUT_AMBIGUOUS",
|
|
5634
|
-
"Expected one final assistant output message; narrative and answer text are not joined."
|
|
5635
|
-
);
|
|
5636
|
-
let data;
|
|
5637
|
-
try {
|
|
5638
|
-
data = JSON.parse(answers[0]);
|
|
5639
|
-
} catch (cause) {
|
|
5640
|
-
fail("STRUCTURED_OUTPUT_INVALID_JSON", "The response is not valid JSON.", cause);
|
|
5641
|
-
}
|
|
5642
|
-
if (!validate(data))
|
|
5643
|
-
fail("STRUCTURED_OUTPUT_INVALID", "The response did not match the requested JSON schema.");
|
|
5644
|
-
return { data, response };
|
|
5645
|
-
};
|
|
5319
|
+
function parseWorkspaceRole(input) {
|
|
5320
|
+
const value = input.trim().toLowerCase();
|
|
5321
|
+
if (value === "owner" || value === "collaborator" || value === "guest") return value;
|
|
5322
|
+
return /^read[-_ ]?only$/.test(value) ? "guest" : null;
|
|
5646
5323
|
}
|
|
5647
|
-
async function
|
|
5648
|
-
return (await
|
|
5324
|
+
async function listWorkspaces(arbi) {
|
|
5325
|
+
return requireData(await arbi.fetch.GET("/v1/user/workspaces"), "Failed to fetch workspaces");
|
|
5649
5326
|
}
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5327
|
+
async function createWorkspace(arbi, name, encryptedWorkspaceKey, projectExtId, description, isPublic = false) {
|
|
5328
|
+
return requireData(
|
|
5329
|
+
await arbi.fetch.POST("/v1/workspace/create_protected", {
|
|
5330
|
+
body: {
|
|
5331
|
+
name,
|
|
5332
|
+
description: description ?? null,
|
|
5333
|
+
is_public: isPublic,
|
|
5334
|
+
workspace_key: encryptedWorkspaceKey,
|
|
5335
|
+
project_ext_id: projectExtId
|
|
5336
|
+
}
|
|
5337
|
+
}),
|
|
5338
|
+
"Failed to create workspace"
|
|
5339
|
+
);
|
|
5661
5340
|
}
|
|
5662
|
-
function
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5341
|
+
async function moveWorkspaceToProject(arbi, workspaceExtId, projectExtId) {
|
|
5342
|
+
return requireData(
|
|
5343
|
+
await arbi.fetch.PUT("/v1/workspace/{workspace_ext_id}/project", {
|
|
5344
|
+
params: { path: { workspace_ext_id: workspaceExtId } },
|
|
5345
|
+
body: { project_ext_id: projectExtId }
|
|
5346
|
+
}),
|
|
5347
|
+
"Failed to move workspace"
|
|
5348
|
+
);
|
|
5666
5349
|
}
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
}
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
return frames;
|
|
5714
|
-
}
|
|
5715
|
-
};
|
|
5716
|
-
function consumeResponse(response, controller, cancel, options = {}) {
|
|
5717
|
-
if (!response.body)
|
|
5718
|
-
return Promise.reject(
|
|
5719
|
-
new ArbiApiError("Response has no stream body.", void 0, response.status, {
|
|
5720
|
-
code: "MISSING_RESPONSE_BODY"
|
|
5721
|
-
})
|
|
5722
|
-
);
|
|
5723
|
-
const reader = response.body.getReader();
|
|
5724
|
-
let resolveStart;
|
|
5725
|
-
let rejectStart;
|
|
5726
|
-
const start = new Promise((resolve2, reject) => {
|
|
5727
|
-
resolveStart = resolve2;
|
|
5728
|
-
rejectStart = reject;
|
|
5729
|
-
});
|
|
5730
|
-
let resolveOutcome;
|
|
5731
|
-
const outcome = new Promise((resolve2) => {
|
|
5732
|
-
resolveOutcome = resolve2;
|
|
5733
|
-
});
|
|
5734
|
-
let state = immutable({
|
|
5735
|
-
id: options.id ?? "",
|
|
5736
|
-
conversationId: null,
|
|
5737
|
-
connection: "connecting",
|
|
5738
|
-
responseStatus: null,
|
|
5739
|
-
output: [],
|
|
5740
|
-
displayText: ""
|
|
5741
|
-
});
|
|
5742
|
-
let bound = false;
|
|
5743
|
-
let finished = false;
|
|
5744
|
-
let acknowledgement;
|
|
5745
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
5746
|
-
const queue = [];
|
|
5747
|
-
let capacityAvailable;
|
|
5748
|
-
const releaseCapacity = () => {
|
|
5749
|
-
capacityAvailable?.();
|
|
5750
|
-
capacityAvailable = void 0;
|
|
5751
|
-
};
|
|
5752
|
-
let claimed = false;
|
|
5753
|
-
let iteratorClosed = false;
|
|
5754
|
-
let iteratorError;
|
|
5755
|
-
let pending;
|
|
5756
|
-
const emit = (event) => {
|
|
5757
|
-
if (!claimed && !options.bufferEvents || iteratorClosed) return;
|
|
5758
|
-
if (pending) {
|
|
5759
|
-
pending.resolve({ value: immutable(event), done: false });
|
|
5760
|
-
pending = void 0;
|
|
5761
|
-
} else if (queue.length < 256) queue.push(immutable(event));
|
|
5762
|
-
else {
|
|
5763
|
-
iteratorError = new ArbiError("Raw response event consumer fell behind.", {
|
|
5764
|
-
code: "RESPONSE_EVENT_OVERFLOW"
|
|
5765
|
-
});
|
|
5766
|
-
queue.length = 0;
|
|
5767
|
-
iteratorClosed = true;
|
|
5768
|
-
}
|
|
5350
|
+
async function getWorkspaceArchive(arbi, workspaceExtId) {
|
|
5351
|
+
return requireData(
|
|
5352
|
+
await arbi.fetch.GET("/v1/workspace/{workspace_ext_id}/archive", {
|
|
5353
|
+
params: { path: { workspace_ext_id: workspaceExtId } }
|
|
5354
|
+
}),
|
|
5355
|
+
"Could not read the archive state"
|
|
5356
|
+
);
|
|
5357
|
+
}
|
|
5358
|
+
async function archiveWorkspace(arbi, workspaceExtId) {
|
|
5359
|
+
return requireData(
|
|
5360
|
+
await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/archive", {
|
|
5361
|
+
params: { path: { workspace_ext_id: workspaceExtId } }
|
|
5362
|
+
}),
|
|
5363
|
+
"Could not archive the workspace"
|
|
5364
|
+
);
|
|
5365
|
+
}
|
|
5366
|
+
async function unarchiveWorkspace(arbi, workspaceExtId) {
|
|
5367
|
+
return requireData(
|
|
5368
|
+
await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/unarchive", {
|
|
5369
|
+
params: { path: { workspace_ext_id: workspaceExtId } }
|
|
5370
|
+
}),
|
|
5371
|
+
"Could not unarchive the workspace"
|
|
5372
|
+
);
|
|
5373
|
+
}
|
|
5374
|
+
async function deleteWorkspaces(arbi, workspaceIds) {
|
|
5375
|
+
requireOk(
|
|
5376
|
+
await arbi.fetch.DELETE("/v1/workspace/", {
|
|
5377
|
+
body: { external_ids: workspaceIds }
|
|
5378
|
+
}),
|
|
5379
|
+
"Failed to delete workspace(s)"
|
|
5380
|
+
);
|
|
5381
|
+
}
|
|
5382
|
+
async function updateWorkspace(arbi, body) {
|
|
5383
|
+
return requireData(
|
|
5384
|
+
await arbi.fetch.PATCH("/v1/workspace/", { body }),
|
|
5385
|
+
"Failed to update workspace"
|
|
5386
|
+
);
|
|
5387
|
+
}
|
|
5388
|
+
async function listWorkspaceUsers(arbi) {
|
|
5389
|
+
return requireData(await arbi.fetch.GET("/v1/workspace/users"), "Failed to fetch workspace users");
|
|
5390
|
+
}
|
|
5391
|
+
var EXTERNAL_ACCESS_SECONDS = 86400;
|
|
5392
|
+
function addWorkspaceMembersBody(request) {
|
|
5393
|
+
return {
|
|
5394
|
+
...request,
|
|
5395
|
+
access_duration_seconds: request.access_duration_seconds ?? EXTERNAL_ACCESS_SECONDS
|
|
5769
5396
|
};
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5397
|
+
}
|
|
5398
|
+
async function addWorkspaceMembers(arbi, request) {
|
|
5399
|
+
return requireData(
|
|
5400
|
+
await arbi.fetch.POST("/v1/workspace/users", { body: addWorkspaceMembersBody(request) }),
|
|
5401
|
+
"Failed to add users"
|
|
5402
|
+
);
|
|
5403
|
+
}
|
|
5404
|
+
async function addWorkspaceUsers(arbi, emails, role = "collaborator", target, confirmInvite = false) {
|
|
5405
|
+
const invite = confirmInvite ? { confirm_invite: true } : {};
|
|
5406
|
+
return requireData(
|
|
5407
|
+
await arbi.fetch.POST("/v1/workspace/users", {
|
|
5408
|
+
body: addWorkspaceMembersBody(
|
|
5409
|
+
target ? {
|
|
5410
|
+
emails,
|
|
5411
|
+
role,
|
|
5412
|
+
workspace_ext_id: target.workspaceExtId,
|
|
5413
|
+
workspace_key: target.workspaceKey,
|
|
5414
|
+
...invite
|
|
5415
|
+
} : { emails, role, ...invite }
|
|
5416
|
+
)
|
|
5417
|
+
}),
|
|
5418
|
+
"Failed to add users"
|
|
5419
|
+
);
|
|
5420
|
+
}
|
|
5421
|
+
async function grantTemporaryWorkspaceAccess(arbi, params) {
|
|
5422
|
+
return requireData(
|
|
5423
|
+
await arbi.fetch.POST("/v1/workspace/users", {
|
|
5424
|
+
body: addWorkspaceMembersBody({
|
|
5425
|
+
emails: params.emails,
|
|
5426
|
+
role: params.role ?? "collaborator",
|
|
5427
|
+
workspace_ext_id: params.workspaceExtId,
|
|
5428
|
+
workspace_key: params.workspaceKey,
|
|
5429
|
+
session_pubkey_b64: params.sessionPubkeyB64
|
|
5430
|
+
})
|
|
5431
|
+
}),
|
|
5432
|
+
"Failed to grant temporary access"
|
|
5433
|
+
);
|
|
5434
|
+
}
|
|
5435
|
+
async function removeWorkspaceUsers(arbi, userIds, workspaceExtId) {
|
|
5436
|
+
requireOk(
|
|
5437
|
+
await arbi.fetch.DELETE("/v1/workspace/users", {
|
|
5438
|
+
body: {
|
|
5439
|
+
users: userIds.map((id) => ({ user_ext_id: id })),
|
|
5440
|
+
...workspaceExtId ? { workspace_ext_id: workspaceExtId } : {}
|
|
5776
5441
|
}
|
|
5777
|
-
}
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
void reader.cancel().catch(() => {
|
|
5797
|
-
});
|
|
5798
|
-
};
|
|
5799
|
-
const abort = () => {
|
|
5800
|
-
if (!bound) rejectStart(new DOMException("The operation was aborted.", "AbortError"));
|
|
5801
|
-
finish({ status: "disconnected", responseId: bound ? state.id : null, reason: "aborted" }, true);
|
|
5802
|
-
queue.length = 0;
|
|
5803
|
-
};
|
|
5804
|
-
const handle = {
|
|
5805
|
-
get id() {
|
|
5806
|
-
return state.id;
|
|
5807
|
-
},
|
|
5808
|
-
snapshot: () => state,
|
|
5809
|
-
subscribe(listener) {
|
|
5810
|
-
if (!finished) listeners.add(listener);
|
|
5811
|
-
try {
|
|
5812
|
-
listener(state);
|
|
5813
|
-
} catch (error) {
|
|
5814
|
-
reportObserverError(error);
|
|
5442
|
+
}),
|
|
5443
|
+
"Failed to remove users"
|
|
5444
|
+
);
|
|
5445
|
+
}
|
|
5446
|
+
async function setUserRole(arbi, userIds, role) {
|
|
5447
|
+
return requireData(
|
|
5448
|
+
await arbi.fetch.PATCH("/v1/workspace/users", {
|
|
5449
|
+
body: { user_ext_ids: userIds, role }
|
|
5450
|
+
}),
|
|
5451
|
+
"Failed to update roles"
|
|
5452
|
+
);
|
|
5453
|
+
}
|
|
5454
|
+
async function copyDocuments(arbi, targetWorkspaceId, docIds, targetWorkspaceKey) {
|
|
5455
|
+
return requireData(
|
|
5456
|
+
await arbi.fetch.POST("/v1/workspace/copy", {
|
|
5457
|
+
body: {
|
|
5458
|
+
target_workspace_ext_id: targetWorkspaceId,
|
|
5459
|
+
target_workspace_key: targetWorkspaceKey,
|
|
5460
|
+
items: docIds
|
|
5815
5461
|
}
|
|
5816
|
-
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5462
|
+
}),
|
|
5463
|
+
"Failed to copy documents"
|
|
5464
|
+
);
|
|
5465
|
+
}
|
|
5466
|
+
async function getWorkspaceActivity(arbi, workspaceExtId, options = {}) {
|
|
5467
|
+
return requireData(
|
|
5468
|
+
await arbi.fetch.GET("/v1/workspace/{workspace_ext_id}/activity", {
|
|
5469
|
+
params: {
|
|
5470
|
+
path: { workspace_ext_id: workspaceExtId },
|
|
5471
|
+
query: { cursor: options.cursor ?? void 0, limit: options.limit }
|
|
5472
|
+
}
|
|
5473
|
+
}),
|
|
5474
|
+
"Failed to fetch workspace activity"
|
|
5475
|
+
);
|
|
5476
|
+
}
|
|
5477
|
+
async function primeWorkspaceKey(arbi, workspaceExtId, sessionSealedKey) {
|
|
5478
|
+
requireOk(
|
|
5479
|
+
await arbi.fetch.POST("/v1/workspace/{workspace_ext_id}/prime-key", {
|
|
5480
|
+
params: { path: { workspace_ext_id: workspaceExtId } },
|
|
5481
|
+
body: { workspace_key: sessionSealedKey }
|
|
5482
|
+
}),
|
|
5483
|
+
"Failed to prime the workspace key"
|
|
5484
|
+
);
|
|
5485
|
+
}
|
|
5486
|
+
async function planWorkspaceTransfer(arbi, scope, mode) {
|
|
5487
|
+
return requireData(
|
|
5488
|
+
await arbi.fetch.POST("/v1/workspace/transfer/plan", { body: { scope, mode } }),
|
|
5489
|
+
"Failed to plan the transfer"
|
|
5490
|
+
);
|
|
5491
|
+
}
|
|
5492
|
+
async function startWorkspaceTransfer(arbi, params) {
|
|
5493
|
+
return requireData(
|
|
5494
|
+
await arbi.fetch.POST("/v1/workspace/transfer", {
|
|
5495
|
+
body: {
|
|
5496
|
+
scope: params.scope,
|
|
5497
|
+
mode: params.mode,
|
|
5498
|
+
target_workspace_ext_id: params.targetWorkspaceId,
|
|
5499
|
+
target_workspace_key: params.targetWorkspaceKey,
|
|
5500
|
+
on_conflict: params.onConflict ?? "skip"
|
|
5501
|
+
}
|
|
5502
|
+
}),
|
|
5503
|
+
"Failed to start the transfer"
|
|
5504
|
+
);
|
|
5505
|
+
}
|
|
5506
|
+
async function resumeWorkspaceTransfer(arbi, transferId, targetWorkspaceKey) {
|
|
5507
|
+
return requireData(
|
|
5508
|
+
await arbi.fetch.POST("/v1/workspace/transfer/{transfer_ext_id}/resume", {
|
|
5509
|
+
params: { path: { transfer_ext_id: transferId } },
|
|
5510
|
+
body: { target_workspace_key: targetWorkspaceKey }
|
|
5511
|
+
}),
|
|
5512
|
+
"Failed to resume the transfer"
|
|
5513
|
+
);
|
|
5514
|
+
}
|
|
5515
|
+
async function cancelWorkspaceTransfer(arbi, transferId) {
|
|
5516
|
+
return requireData(
|
|
5517
|
+
await arbi.fetch.POST("/v1/workspace/transfer/{transfer_ext_id}/cancel", {
|
|
5518
|
+
params: { path: { transfer_ext_id: transferId } }
|
|
5519
|
+
}),
|
|
5520
|
+
"Failed to cancel the transfer"
|
|
5521
|
+
);
|
|
5522
|
+
}
|
|
5523
|
+
async function getWorkspaceTransfer(arbi, transferId) {
|
|
5524
|
+
return requireData(
|
|
5525
|
+
await arbi.fetch.GET("/v1/workspace/transfer/{transfer_ext_id}", {
|
|
5526
|
+
params: { path: { transfer_ext_id: transferId } }
|
|
5527
|
+
}),
|
|
5528
|
+
"Failed to fetch the transfer"
|
|
5529
|
+
);
|
|
5530
|
+
}
|
|
5531
|
+
async function listWorkspaceTransfers(arbi) {
|
|
5532
|
+
return requireData(
|
|
5533
|
+
await arbi.fetch.GET("/v1/workspace/transfer", {}),
|
|
5534
|
+
"Failed to list transfers"
|
|
5535
|
+
);
|
|
5536
|
+
}
|
|
5537
|
+
async function exportWorkspaceData(arbi, scope) {
|
|
5538
|
+
return requireData(
|
|
5539
|
+
await arbi.fetch.POST("/v1/workspace/export", { body: { scope } }),
|
|
5540
|
+
"Failed to export the workspace"
|
|
5541
|
+
);
|
|
5542
|
+
}
|
|
5543
|
+
async function getWorkspaceAccessStatus(arbi, workspaceId) {
|
|
5544
|
+
return requireData(
|
|
5545
|
+
await arbi.fetch.GET("/v1/workspace/{workspace_ext_id}/access-status", {
|
|
5546
|
+
params: { path: { workspace_ext_id: workspaceId } }
|
|
5547
|
+
}),
|
|
5548
|
+
"Could not read workspace access"
|
|
5549
|
+
);
|
|
5550
|
+
}
|
|
5551
|
+
|
|
5552
|
+
// src/diagnostics.ts
|
|
5553
|
+
async function diagnoseSetup(options) {
|
|
5554
|
+
const checks = [];
|
|
5555
|
+
const add = (check, status, message, hint) => checks.push({ check, status, message, ...hint ? { hint } : {} });
|
|
5556
|
+
let base;
|
|
5557
|
+
try {
|
|
5558
|
+
base = new URL(options.url);
|
|
5559
|
+
if (!["http:", "https:"].includes(base.protocol) || base.username || base.password || base.search || base.hash)
|
|
5560
|
+
throw new Error("Invalid API URL");
|
|
5561
|
+
} catch {
|
|
5562
|
+
add(
|
|
5563
|
+
"connection",
|
|
5564
|
+
"error",
|
|
5565
|
+
"Invalid API URL.",
|
|
5566
|
+
"Use an absolute HTTP(S) API URL without credentials, query or fragment."
|
|
5567
|
+
);
|
|
5568
|
+
return { ok: false, checks };
|
|
5569
|
+
}
|
|
5570
|
+
const request = (path5, authenticated = false) => (options.fetch ?? globalThis.fetch)(`${base.href.replace(/\/$/, "")}${path5}`, {
|
|
5571
|
+
method: "GET",
|
|
5572
|
+
credentials: "omit",
|
|
5573
|
+
redirect: "error",
|
|
5574
|
+
cache: "no-store",
|
|
5575
|
+
headers: authenticated && options.accessToken ? { Authorization: `Bearer ${options.accessToken}` } : {},
|
|
5576
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
|
|
5577
|
+
});
|
|
5578
|
+
try {
|
|
5579
|
+
const config = await request("/config.json");
|
|
5580
|
+
if (!config.ok) {
|
|
5581
|
+
add(
|
|
5582
|
+
"connection",
|
|
5583
|
+
"error",
|
|
5584
|
+
`Deployment configuration returned HTTP ${config.status}.`,
|
|
5585
|
+
"Check the API base URL and proxy routing."
|
|
5586
|
+
);
|
|
5587
|
+
} else {
|
|
5588
|
+
const body = await config.json();
|
|
5589
|
+
add("connection", "ok", "Deployment configuration is reachable.");
|
|
5590
|
+
const domain = body?.deployment?.domain;
|
|
5591
|
+
if (typeof domain !== "string" || !domain) {
|
|
5592
|
+
add(
|
|
5593
|
+
"deployment",
|
|
5594
|
+
"warning",
|
|
5595
|
+
"The deployment did not advertise its key-derivation domain.",
|
|
5596
|
+
"Confirm deploymentDomain with the deployment owner, especially when using a proxy."
|
|
5597
|
+
);
|
|
5598
|
+
} else if (domain !== (options.deploymentDomain ?? base.hostname)) {
|
|
5599
|
+
add(
|
|
5600
|
+
"deployment",
|
|
5601
|
+
"error",
|
|
5602
|
+
"The configured key-derivation domain differs from the deployment.",
|
|
5603
|
+
"Set deploymentDomain to the deployment\u2019s domain; a proxy hostname is not the key-derivation domain."
|
|
5604
|
+
);
|
|
5605
|
+
} else add("deployment", "ok", "The key-derivation domain matches the deployment.");
|
|
5891
5606
|
}
|
|
5607
|
+
} catch {
|
|
5608
|
+
add(
|
|
5609
|
+
"connection",
|
|
5610
|
+
"error",
|
|
5611
|
+
"Could not read deployment configuration.",
|
|
5612
|
+
"Check DNS, TLS, proxy routing and connectivity. In a browser, inspect DevTools for CORS, mixed-content or private-network denial; fetch alone cannot distinguish them."
|
|
5613
|
+
);
|
|
5614
|
+
}
|
|
5615
|
+
if (!options.accessToken) {
|
|
5616
|
+
add(
|
|
5617
|
+
"authentication",
|
|
5618
|
+
"warning",
|
|
5619
|
+
"No live session token is available.",
|
|
5620
|
+
"Sign in explicitly when online. An offline-unlocked identity is not a verified server session."
|
|
5621
|
+
);
|
|
5622
|
+
add("workspace", "skipped", "Workspace access was not checked.");
|
|
5623
|
+
add("permissions", "skipped", "Permissions were not checked.");
|
|
5624
|
+
} else {
|
|
5625
|
+
let authenticated = false;
|
|
5892
5626
|
try {
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
const id = raw?.id;
|
|
5901
|
-
if (bound && typeof id === "string" && id !== state.id) {
|
|
5902
|
-
diagnostic("CONFLICTING_RESPONSE_ID", frame);
|
|
5903
|
-
return;
|
|
5904
|
-
}
|
|
5905
|
-
if (messageId(id)) bind(id);
|
|
5906
|
-
emit({ event: frame.event, data, ...frame.id !== void 0 ? { id: frame.id } : {} });
|
|
5907
|
-
if (frame.event === "arbi.message_queued") acknowledgement = payload;
|
|
5908
|
-
const patch = {};
|
|
5909
|
-
if (frame.event === "arbi.user_message" && !state.conversationId && typeof payload?.conversation_ext_id === "string")
|
|
5910
|
-
patch.conversationId = payload.conversation_ext_id;
|
|
5911
|
-
if (raw) {
|
|
5912
|
-
patch.rawResponse = raw;
|
|
5913
|
-
if (typeof raw.status === "string") patch.responseStatus = raw.status;
|
|
5914
|
-
if (Array.isArray(raw.output))
|
|
5915
|
-
patch.output = raw.output.filter((item2) => !!object(item2));
|
|
5916
|
-
const metadata = object(raw.metadata);
|
|
5917
|
-
const conversation = text(metadata?.conversation_ext_id) ?? text(metadata?.conversation_id) ?? text(raw.conversation_id);
|
|
5918
|
-
if (conversation && (!state.conversationId || state.conversationId === conversation))
|
|
5919
|
-
patch.conversationId = conversation;
|
|
5920
|
-
if (typeof metadata?.content === "string") patch.displayText = metadata.content;
|
|
5921
|
-
}
|
|
5922
|
-
const item = object(payload?.item);
|
|
5923
|
-
if ((frame.event === "response.output_item.added" || frame.event === "response.output_item.done") && item) {
|
|
5924
|
-
const output = [...state.output];
|
|
5925
|
-
const index = output.findIndex((existing) => existing.id === item.id);
|
|
5926
|
-
if (index >= 0 && item.id) output[index] = item;
|
|
5927
|
-
else
|
|
5928
|
-
output.splice(
|
|
5929
|
-
typeof payload?.output_index === "number" ? payload.output_index : output.length,
|
|
5930
|
-
0,
|
|
5931
|
-
item
|
|
5627
|
+
const user = await request("/v1/user/me", true);
|
|
5628
|
+
if (!user.ok) {
|
|
5629
|
+
add(
|
|
5630
|
+
"authentication",
|
|
5631
|
+
"error",
|
|
5632
|
+
`Session check returned HTTP ${user.status}.`,
|
|
5633
|
+
user.status === 401 ? "Sign in explicitly to renew the session." : "Check deployment access and account permissions."
|
|
5932
5634
|
);
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5635
|
+
add("workspace", "skipped", "Workspace access was not checked.");
|
|
5636
|
+
add("permissions", "skipped", "Permissions were not checked.");
|
|
5637
|
+
} else {
|
|
5638
|
+
const profile = await user.json();
|
|
5639
|
+
authenticated = true;
|
|
5640
|
+
add("authentication", "ok", "The server accepts the current session.");
|
|
5641
|
+
if (!options.workspaceId) {
|
|
5642
|
+
add(
|
|
5643
|
+
"workspace",
|
|
5644
|
+
"warning",
|
|
5645
|
+
"No current workspace is selected.",
|
|
5646
|
+
"Choose a workspace explicitly before reading documents or starting work."
|
|
5647
|
+
);
|
|
5648
|
+
add("permissions", "skipped", "Select a workspace to check membership.");
|
|
5649
|
+
} else {
|
|
5650
|
+
const response = await request("/v1/user/workspaces", true);
|
|
5651
|
+
if (!response.ok) {
|
|
5652
|
+
add(
|
|
5653
|
+
"workspace",
|
|
5654
|
+
"error",
|
|
5655
|
+
`Workspace membership check returned HTTP ${response.status}.`,
|
|
5656
|
+
"Check current account access; diagnosis does not switch workspaces or grant access."
|
|
5657
|
+
);
|
|
5658
|
+
add("permissions", "skipped", "Membership could not be verified.");
|
|
5659
|
+
} else {
|
|
5660
|
+
const workspaces = await response.json();
|
|
5661
|
+
const workspace = Array.isArray(workspaces) ? workspaces.find((w2) => w2.external_id === options.workspaceId) : void 0;
|
|
5662
|
+
if (!workspace) {
|
|
5663
|
+
add(
|
|
5664
|
+
"workspace",
|
|
5665
|
+
"error",
|
|
5666
|
+
"The selected workspace is not in this account\u2019s workspace list.",
|
|
5667
|
+
"Choose an accessible workspace explicitly. Project visibility does not imply workspace access."
|
|
5668
|
+
);
|
|
5669
|
+
add("permissions", "skipped", "Workspace permissions could not be verified.");
|
|
5670
|
+
} else {
|
|
5671
|
+
add(
|
|
5672
|
+
"workspace",
|
|
5673
|
+
"ok",
|
|
5674
|
+
"The selected workspace appears in the account\u2019s workspace list."
|
|
5675
|
+
);
|
|
5676
|
+
const member = workspace.users?.find(
|
|
5677
|
+
(entry) => entry.user?.external_id === profile.external_id
|
|
5678
|
+
);
|
|
5679
|
+
const role = ["owner", "collaborator", "guest"].includes(member?.role) ? member.role : null;
|
|
5680
|
+
add(
|
|
5681
|
+
"permissions",
|
|
5682
|
+
role ? "ok" : "warning",
|
|
5683
|
+
role ? `Workspace membership role: ${workspaceRoleLabel(role)} (${role}).` : "No direct membership role was reported.",
|
|
5684
|
+
"This is a membership check, not proof of a live workspace key or authorization for an agent task. Temporary grants, expiry and execution permissions remain enforced by the API."
|
|
5685
|
+
);
|
|
5686
|
+
}
|
|
5687
|
+
}
|
|
5971
5688
|
}
|
|
5972
|
-
current[key] = content;
|
|
5973
5689
|
}
|
|
5974
|
-
|
|
5975
|
-
|
|
5690
|
+
} catch {
|
|
5691
|
+
add(
|
|
5692
|
+
authenticated ? "workspace" : "authentication",
|
|
5693
|
+
"error",
|
|
5694
|
+
authenticated ? "The workspace membership check could not finish." : "The session check could not finish.",
|
|
5695
|
+
"Check connectivity and browser network policy. No login, workspace switch or grant was attempted."
|
|
5696
|
+
);
|
|
5697
|
+
if (authenticated)
|
|
5698
|
+
add("permissions", "skipped", "Workspace membership could not be verified.");
|
|
5976
5699
|
}
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
5700
|
+
}
|
|
5701
|
+
return { ok: checks.every((c2) => c2.status === "ok"), checks };
|
|
5702
|
+
}
|
|
5703
|
+
|
|
5704
|
+
// src/operations/responses.ts
|
|
5705
|
+
var responses_exports = {};
|
|
5706
|
+
__export(responses_exports, {
|
|
5707
|
+
extractResponseText: () => extractResponseText,
|
|
5708
|
+
getResponse: () => getResponse,
|
|
5709
|
+
submitBackgroundQuery: () => submitBackgroundQuery
|
|
5710
|
+
});
|
|
5711
|
+
async function submitBackgroundQuery(options) {
|
|
5712
|
+
const {
|
|
5713
|
+
workspaceId,
|
|
5714
|
+
question,
|
|
5715
|
+
docIds,
|
|
5716
|
+
previousResponseId,
|
|
5717
|
+
model,
|
|
5718
|
+
text: text2,
|
|
5719
|
+
task,
|
|
5720
|
+
conversationId,
|
|
5721
|
+
mentions,
|
|
5722
|
+
activeArtifactExtId,
|
|
5723
|
+
fullContext = true,
|
|
5724
|
+
...auth
|
|
5725
|
+
} = options;
|
|
5726
|
+
const tools = {};
|
|
5727
|
+
if (docIds.length > 0) {
|
|
5728
|
+
tools.retrieval_chunk = {
|
|
5729
|
+
name: "retrieval_chunk",
|
|
5730
|
+
description: "retrieval chunk",
|
|
5731
|
+
tool_args: { doc_ext_ids: docIds },
|
|
5732
|
+
tool_responses: {}
|
|
5733
|
+
};
|
|
5734
|
+
if (fullContext)
|
|
5735
|
+
tools.retrieval_full_context = {
|
|
5736
|
+
name: "retrieval_full_context",
|
|
5737
|
+
description: "retrieval full context",
|
|
5738
|
+
tool_args: { doc_ext_ids: docIds },
|
|
5739
|
+
tool_responses: {}
|
|
5740
|
+
};
|
|
5741
|
+
}
|
|
5742
|
+
const body = {
|
|
5743
|
+
input: question,
|
|
5744
|
+
workspace_ext_id: workspaceId,
|
|
5745
|
+
stream: false,
|
|
5746
|
+
background: true,
|
|
5747
|
+
store: true,
|
|
5748
|
+
tools,
|
|
5749
|
+
...task !== void 0 ? { task } : {},
|
|
5750
|
+
...conversationId ? { conversation_ext_id: conversationId } : {},
|
|
5751
|
+
...mentions !== void 0 ? { mentions } : {},
|
|
5752
|
+
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
5753
|
+
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
5754
|
+
...model ? { model } : {},
|
|
5755
|
+
...text2 ? { text: text2 } : {}
|
|
5756
|
+
};
|
|
5757
|
+
const res = await authenticatedFetch({
|
|
5758
|
+
...auth,
|
|
5759
|
+
path: "/v1/responses",
|
|
5760
|
+
method: "POST",
|
|
5761
|
+
body: JSON.stringify(body),
|
|
5762
|
+
headers: { "Content-Type": "application/json" }
|
|
5763
|
+
});
|
|
5764
|
+
return await res.json();
|
|
5765
|
+
}
|
|
5766
|
+
async function getResponse(auth, responseId) {
|
|
5767
|
+
const res = await authenticatedFetch({
|
|
5768
|
+
...auth,
|
|
5769
|
+
path: `/v1/responses/${responseId}`,
|
|
5770
|
+
method: "GET"
|
|
5771
|
+
});
|
|
5772
|
+
return await res.json();
|
|
5773
|
+
}
|
|
5774
|
+
function extractResponseText(response) {
|
|
5775
|
+
const parts = [];
|
|
5776
|
+
for (const msg of Array.isArray(response.output) ? response.output : []) {
|
|
5777
|
+
if (msg.type !== "message" || !Array.isArray(msg.content)) continue;
|
|
5778
|
+
for (const item of msg.content) {
|
|
5779
|
+
if (item?.type === "output_text" && typeof item.text === "string") parts.push(item.text);
|
|
6000
5780
|
}
|
|
5781
|
+
}
|
|
5782
|
+
return parts.join("");
|
|
5783
|
+
}
|
|
5784
|
+
|
|
5785
|
+
// src/responses-resource.ts
|
|
5786
|
+
function withOutputText(response, requestId) {
|
|
5787
|
+
return {
|
|
5788
|
+
...response,
|
|
5789
|
+
output_text: extractResponseText(response),
|
|
5790
|
+
...requestId ? { _request_id: requestId } : {}
|
|
6001
5791
|
};
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
5792
|
+
}
|
|
5793
|
+
var ResponseStream = class {
|
|
5794
|
+
constructor(handle) {
|
|
5795
|
+
this.handle = handle;
|
|
5796
|
+
}
|
|
5797
|
+
handle;
|
|
5798
|
+
async *[Symbol.asyncIterator]() {
|
|
6008
5799
|
try {
|
|
6009
|
-
|
|
6010
|
-
const
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
capacityAvailable = resolve2;
|
|
6016
|
-
});
|
|
6017
|
-
}
|
|
6018
|
-
if (done) break;
|
|
6019
|
-
}
|
|
6020
|
-
if (!finished) {
|
|
6021
|
-
if (!bound && acknowledgement) {
|
|
6022
|
-
const value = { status: "acknowledged", responseId: null };
|
|
6023
|
-
resolveStart({
|
|
6024
|
-
kind: "acknowledged",
|
|
6025
|
-
acknowledgement: immutable(acknowledgement),
|
|
6026
|
-
outcome: immutable(value)
|
|
6027
|
-
});
|
|
6028
|
-
finish(value);
|
|
6029
|
-
} else {
|
|
6030
|
-
if (!bound)
|
|
6031
|
-
rejectStart(
|
|
6032
|
-
new ArbiApiError(
|
|
6033
|
-
"Stream ended before response identity was established.",
|
|
6034
|
-
void 0,
|
|
6035
|
-
void 0,
|
|
6036
|
-
{ code: "MISSING_RESPONSE_ID" }
|
|
6037
|
-
)
|
|
6038
|
-
);
|
|
6039
|
-
finish({
|
|
6040
|
-
status: "disconnected",
|
|
6041
|
-
responseId: bound ? state.id : null,
|
|
6042
|
-
reason: "connection_closed"
|
|
6043
|
-
});
|
|
6044
|
-
}
|
|
5800
|
+
for await (const frame of this.handle.events()) {
|
|
5801
|
+
const data = frame.data && typeof frame.data === "object" && !Array.isArray(frame.data) ? frame.data : { data: frame.data };
|
|
5802
|
+
yield {
|
|
5803
|
+
...data,
|
|
5804
|
+
type: typeof data.type === "string" ? data.type : frame.event
|
|
5805
|
+
};
|
|
6045
5806
|
}
|
|
6046
|
-
|
|
6047
|
-
if (
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
5807
|
+
const outcome = await this.handle.outcome;
|
|
5808
|
+
if (outcome.status === "disconnected")
|
|
5809
|
+
throw outcome.error ?? new ArbiTransportError(new Error("The response stream disconnected."), this.handle.id);
|
|
5810
|
+
} finally {
|
|
5811
|
+
this.handle.detach();
|
|
5812
|
+
}
|
|
5813
|
+
}
|
|
5814
|
+
};
|
|
5815
|
+
|
|
5816
|
+
// src/structured-output.ts
|
|
5817
|
+
var ArbiStructuredOutputError = class extends ArbiError {
|
|
5818
|
+
constructor(message, response, options) {
|
|
5819
|
+
const id = response && typeof response === "object" && "id" in response && typeof response.id === "string" ? response.id : void 0;
|
|
5820
|
+
super(message, { responseId: id, ...options });
|
|
5821
|
+
this.response = response;
|
|
5822
|
+
this.name = "ArbiStructuredOutputError";
|
|
5823
|
+
}
|
|
5824
|
+
response;
|
|
5825
|
+
};
|
|
5826
|
+
function localReferences(value) {
|
|
5827
|
+
if (Array.isArray(value)) {
|
|
5828
|
+
value.forEach(localReferences);
|
|
5829
|
+
return;
|
|
5830
|
+
}
|
|
5831
|
+
if (!value || typeof value !== "object") return;
|
|
5832
|
+
for (const [key, child] of Object.entries(value)) {
|
|
5833
|
+
if ((key === "$ref" || key === "$dynamicRef") && (typeof child !== "string" || !child.startsWith("#")))
|
|
5834
|
+
throw new Error("Only local schema references are supported.");
|
|
5835
|
+
if (!["enum", "const", "default", "examples"].includes(key)) localReferences(child);
|
|
5836
|
+
}
|
|
5837
|
+
}
|
|
5838
|
+
async function createStructuredParser(format) {
|
|
5839
|
+
let validate;
|
|
5840
|
+
let Constructor;
|
|
5841
|
+
try {
|
|
5842
|
+
Constructor = (await import('ajv/dist/2020.js')).default;
|
|
5843
|
+
} catch (cause) {
|
|
5844
|
+
throw new ArbiStructuredOutputError(
|
|
5845
|
+
"The JSON Schema validator could not be loaded.",
|
|
5846
|
+
void 0,
|
|
5847
|
+
{ code: "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE", cause }
|
|
5848
|
+
);
|
|
5849
|
+
}
|
|
5850
|
+
try {
|
|
5851
|
+
if (format.type !== "json_schema" || typeof format.name !== "string" || !/^[a-zA-Z0-9_-]{1,64}$/.test(format.name) || !format.schema || typeof format.schema !== "object" || Array.isArray(format.schema))
|
|
5852
|
+
throw new Error("Invalid structured output format.");
|
|
5853
|
+
if (format.schema.$schema !== void 0 && format.schema.$schema !== "https://json-schema.org/draft/2020-12/schema")
|
|
5854
|
+
throw new Error("Expected JSON Schema draft 2020-12.");
|
|
5855
|
+
localReferences(format.schema);
|
|
5856
|
+
validate = new Constructor({
|
|
5857
|
+
strict: false,
|
|
5858
|
+
logger: false,
|
|
5859
|
+
validateFormats: false,
|
|
5860
|
+
strictNumbers: true,
|
|
5861
|
+
addUsedSchema: false
|
|
5862
|
+
}).compile(format.schema);
|
|
5863
|
+
} catch (cause) {
|
|
5864
|
+
const unavailable = cause instanceof EvalError;
|
|
5865
|
+
throw new ArbiStructuredOutputError(
|
|
5866
|
+
unavailable ? "This runtime cannot compile JSON Schema validators." : "Invalid or unsupported output schema.",
|
|
5867
|
+
void 0,
|
|
5868
|
+
{
|
|
5869
|
+
code: unavailable ? "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE" : "STRUCTURED_OUTPUT_SCHEMA_INVALID",
|
|
5870
|
+
cause
|
|
6056
5871
|
}
|
|
6057
|
-
|
|
6058
|
-
|
|
5872
|
+
);
|
|
5873
|
+
}
|
|
5874
|
+
return (response, options = {}) => {
|
|
5875
|
+
const fail = (code, message, cause) => {
|
|
5876
|
+
throw new ArbiStructuredOutputError(message, response, { ...options, code, cause });
|
|
5877
|
+
};
|
|
5878
|
+
if (!response || typeof response !== "object")
|
|
5879
|
+
fail("RESPONSE_INVALID_ENVELOPE", "Expected a Responses JSON object.");
|
|
5880
|
+
if (response.status === "incomplete")
|
|
5881
|
+
fail("RESPONSE_INCOMPLETE", "The response is incomplete; no validated data is available.");
|
|
5882
|
+
if (response.status === "cancelled")
|
|
5883
|
+
fail("RESPONSE_CANCELLED", "The response was cancelled; no validated data is available.");
|
|
5884
|
+
if (response.status === "failed")
|
|
5885
|
+
fail(
|
|
5886
|
+
typeof response.error?.code === "string" ? response.error.code : "RESPONSE_FAILED",
|
|
5887
|
+
typeof response.error?.message === "string" ? response.error.message : "The response failed."
|
|
5888
|
+
);
|
|
5889
|
+
if (response.status !== "completed")
|
|
5890
|
+
fail(
|
|
5891
|
+
"RESPONSE_NOT_COMPLETED",
|
|
5892
|
+
"Wait for a completed response before parsing structured output."
|
|
5893
|
+
);
|
|
5894
|
+
const messages = Array.isArray(response.output) ? response.output.filter(
|
|
5895
|
+
(item) => item && typeof item === "object" && item.type === "message" && item.role === "assistant"
|
|
5896
|
+
) : [];
|
|
5897
|
+
if (messages.some(
|
|
5898
|
+
(message) => !Array.isArray(message.content) || message.content.some((part) => !part || typeof part !== "object")
|
|
5899
|
+
))
|
|
5900
|
+
fail("RESPONSE_INVALID_ENVELOPE", "Invalid assistant output content.");
|
|
5901
|
+
if (messages.some((message) => message.content.some((part) => part.type === "refusal")))
|
|
5902
|
+
fail("RESPONSE_REFUSED", "The model refused this response.");
|
|
5903
|
+
const answers = messages.map(
|
|
5904
|
+
(message) => message.content.filter((part) => part.type === "output_text" && typeof part.text === "string").map((part) => part.text).join("")
|
|
5905
|
+
).filter((answer) => answer.length > 0);
|
|
5906
|
+
if (answers.length !== 1)
|
|
5907
|
+
fail(
|
|
5908
|
+
"STRUCTURED_OUTPUT_AMBIGUOUS",
|
|
5909
|
+
"Expected one final assistant output message; narrative and answer text are not joined."
|
|
5910
|
+
);
|
|
5911
|
+
let data;
|
|
5912
|
+
try {
|
|
5913
|
+
data = JSON.parse(answers[0]);
|
|
5914
|
+
} catch (cause) {
|
|
5915
|
+
fail("STRUCTURED_OUTPUT_INVALID_JSON", "The response is not valid JSON.", cause);
|
|
6059
5916
|
}
|
|
6060
|
-
|
|
6061
|
-
|
|
5917
|
+
if (!validate(data))
|
|
5918
|
+
fail("STRUCTURED_OUTPUT_INVALID", "The response did not match the requested JSON schema.");
|
|
5919
|
+
return { data, response };
|
|
5920
|
+
};
|
|
6062
5921
|
}
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
var documents_exports = {};
|
|
6066
|
-
__export(documents_exports, {
|
|
6067
|
-
MAX_PAGES: () => MAX_PAGES,
|
|
6068
|
-
SUPPORTED_EXTENSIONS: () => SUPPORTED_EXTENSIONS,
|
|
6069
|
-
deleteDocuments: () => deleteDocuments,
|
|
6070
|
-
downloadDocument: () => downloadDocument,
|
|
6071
|
-
finaliseTranslation: () => finaliseTranslation,
|
|
6072
|
-
getDocuments: () => getDocuments,
|
|
6073
|
-
getParsedContent: () => getParsedContent,
|
|
6074
|
-
getThumbnails: () => getThumbnails,
|
|
6075
|
-
listAll: () => listAll,
|
|
6076
|
-
listDocuments: () => listDocuments,
|
|
6077
|
-
listPaginated: () => listPaginated,
|
|
6078
|
-
listVersions: () => listVersions,
|
|
6079
|
-
mimeFromName: () => mimeFromName,
|
|
6080
|
-
presignedPut: () => presignedPut,
|
|
6081
|
-
sanitizeFolderPath: () => sanitizeFolderPath,
|
|
6082
|
-
similarDocuments: () => similarDocuments,
|
|
6083
|
-
updateDocuments: () => updateDocuments,
|
|
6084
|
-
uploadDocuments: () => uploadDocuments,
|
|
6085
|
-
uploadDocumentsDirect: () => uploadDocumentsDirect,
|
|
6086
|
-
uploadFile: () => uploadFile,
|
|
6087
|
-
uploadFiles: () => uploadFiles,
|
|
6088
|
-
uploadUrl: () => uploadUrl
|
|
6089
|
-
});
|
|
6090
|
-
var MAX_PAGES = 400;
|
|
6091
|
-
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
6092
|
-
".pdf",
|
|
6093
|
-
".txt",
|
|
6094
|
-
".md",
|
|
6095
|
-
".html",
|
|
6096
|
-
".htm",
|
|
6097
|
-
".doc",
|
|
6098
|
-
".docx",
|
|
6099
|
-
".rtf",
|
|
6100
|
-
".ppt",
|
|
6101
|
-
".pptx",
|
|
6102
|
-
".xls",
|
|
6103
|
-
".xlsx",
|
|
6104
|
-
".jpg",
|
|
6105
|
-
".jpeg",
|
|
6106
|
-
".png",
|
|
6107
|
-
".gif",
|
|
6108
|
-
".bmp",
|
|
6109
|
-
".tiff",
|
|
6110
|
-
".tif",
|
|
6111
|
-
".webp",
|
|
6112
|
-
// Video (store only, no parsing)
|
|
6113
|
-
".mp4",
|
|
6114
|
-
".mpeg",
|
|
6115
|
-
".mpg",
|
|
6116
|
-
".webm",
|
|
6117
|
-
".mov",
|
|
6118
|
-
".avi",
|
|
6119
|
-
".mkv",
|
|
6120
|
-
// Audio (store only, no parsing)
|
|
6121
|
-
".mp3",
|
|
6122
|
-
".wav",
|
|
6123
|
-
".m4a",
|
|
6124
|
-
".aac",
|
|
6125
|
-
".ogg",
|
|
6126
|
-
".flac",
|
|
6127
|
-
// Email formats (parsed for content)
|
|
6128
|
-
".eml",
|
|
6129
|
-
".msg",
|
|
6130
|
-
".mbox",
|
|
6131
|
-
".pst",
|
|
6132
|
-
".ost"
|
|
6133
|
-
]);
|
|
6134
|
-
function sanitizeFolderPath(folderPath) {
|
|
6135
|
-
return folderPath.replace(/[\x00-\x1f\x7f]/g, "").replace(/\\/g, "/").replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "").trim();
|
|
5922
|
+
async function parseStructuredResponse(response, format) {
|
|
5923
|
+
return (await createStructuredParser(format))(response);
|
|
6136
5924
|
}
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
);
|
|
6147
|
-
if (docs.some((doc) => doc.workspace_ext_id !== workspaceExtId)) {
|
|
6148
|
-
throw new ArbiError(`This server cannot list workspace ${workspaceExtId} without opening it`);
|
|
5925
|
+
|
|
5926
|
+
// src/response-handle.ts
|
|
5927
|
+
var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
5928
|
+
var text = (value) => typeof value === "string" ? value : void 0;
|
|
5929
|
+
var messageId = (value) => typeof value === "string" && /^msg-[\w-]+$/.test(value);
|
|
5930
|
+
function immutable(value) {
|
|
5931
|
+
if (value && typeof value === "object" && !(value instanceof Error) && !Object.isFrozen(value)) {
|
|
5932
|
+
Object.freeze(value);
|
|
5933
|
+
for (const child of Object.values(value)) immutable(child);
|
|
6149
5934
|
}
|
|
6150
|
-
return
|
|
5935
|
+
return value;
|
|
6151
5936
|
}
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
5937
|
+
function reportObserverError(error) {
|
|
5938
|
+
queueMicrotask(() => {
|
|
5939
|
+
throw error;
|
|
5940
|
+
});
|
|
5941
|
+
}
|
|
5942
|
+
var ResponseEventDecoder = class {
|
|
5943
|
+
buffer = "";
|
|
5944
|
+
event = "";
|
|
5945
|
+
data = [];
|
|
5946
|
+
id;
|
|
5947
|
+
push(chunk2, final = false) {
|
|
5948
|
+
this.buffer += chunk2;
|
|
5949
|
+
const frames = [];
|
|
5950
|
+
const dispatch = () => {
|
|
5951
|
+
if (this.data.length)
|
|
5952
|
+
frames.push({
|
|
5953
|
+
event: this.event || "message",
|
|
5954
|
+
data: this.data.join("\n"),
|
|
5955
|
+
...this.id !== void 0 ? { id: this.id } : {}
|
|
5956
|
+
});
|
|
5957
|
+
this.event = "";
|
|
5958
|
+
this.data = [];
|
|
5959
|
+
this.id = void 0;
|
|
6167
5960
|
};
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
5961
|
+
const line = (value) => {
|
|
5962
|
+
if (!value) {
|
|
5963
|
+
dispatch();
|
|
5964
|
+
return;
|
|
5965
|
+
}
|
|
5966
|
+
if (value.startsWith(":")) return;
|
|
5967
|
+
const colon = value.indexOf(":");
|
|
5968
|
+
const field = colon < 0 ? value : value.slice(0, colon);
|
|
5969
|
+
let content = colon < 0 ? "" : value.slice(colon + 1);
|
|
5970
|
+
if (content.startsWith(" ")) content = content.slice(1);
|
|
5971
|
+
if (field === "event") this.event = content;
|
|
5972
|
+
if (field === "data") this.data.push(content);
|
|
5973
|
+
if (field === "id" && !content.includes("\0")) this.id = content;
|
|
5974
|
+
};
|
|
5975
|
+
while (true) {
|
|
5976
|
+
const index = this.buffer.search(/[\r\n]/);
|
|
5977
|
+
if (index < 0 || !final && index === this.buffer.length - 1 && this.buffer[index] === "\r")
|
|
5978
|
+
break;
|
|
5979
|
+
const width = this.buffer[index] === "\r" && this.buffer[index + 1] === "\n" ? 2 : 1;
|
|
5980
|
+
line(this.buffer.slice(0, index));
|
|
5981
|
+
this.buffer = this.buffer.slice(index + width);
|
|
6176
5982
|
}
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
5983
|
+
if (final) {
|
|
5984
|
+
if (this.buffer) line(this.buffer);
|
|
5985
|
+
this.buffer = "";
|
|
5986
|
+
dispatch();
|
|
6180
5987
|
}
|
|
6181
|
-
return
|
|
6182
|
-
}
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
5988
|
+
return frames;
|
|
5989
|
+
}
|
|
5990
|
+
};
|
|
5991
|
+
function consumeResponse(response, controller, cancel, options = {}) {
|
|
5992
|
+
if (!response.body)
|
|
5993
|
+
return Promise.reject(
|
|
5994
|
+
new ArbiApiError("Response has no stream body.", void 0, response.status, {
|
|
5995
|
+
code: "MISSING_RESPONSE_BODY"
|
|
5996
|
+
})
|
|
5997
|
+
);
|
|
5998
|
+
const reader = response.body.getReader();
|
|
5999
|
+
let resolveStart;
|
|
6000
|
+
let rejectStart;
|
|
6001
|
+
const start = new Promise((resolve2, reject) => {
|
|
6002
|
+
resolveStart = resolve2;
|
|
6003
|
+
rejectStart = reject;
|
|
6004
|
+
});
|
|
6005
|
+
let resolveOutcome;
|
|
6006
|
+
const outcome = new Promise((resolve2) => {
|
|
6007
|
+
resolveOutcome = resolve2;
|
|
6008
|
+
});
|
|
6009
|
+
let state = immutable({
|
|
6010
|
+
id: options.id ?? "",
|
|
6011
|
+
conversationId: null,
|
|
6012
|
+
connection: "connecting",
|
|
6013
|
+
responseStatus: null,
|
|
6014
|
+
output: [],
|
|
6015
|
+
displayText: ""
|
|
6016
|
+
});
|
|
6017
|
+
let bound = false;
|
|
6018
|
+
let finished = false;
|
|
6019
|
+
let acknowledgement;
|
|
6020
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
6189
6021
|
const queue = [];
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6022
|
+
let capacityAvailable;
|
|
6023
|
+
const releaseCapacity = () => {
|
|
6024
|
+
capacityAvailable?.();
|
|
6025
|
+
capacityAvailable = void 0;
|
|
6026
|
+
};
|
|
6027
|
+
let claimed = false;
|
|
6028
|
+
let iteratorClosed = false;
|
|
6029
|
+
let iteratorError;
|
|
6030
|
+
let pending;
|
|
6031
|
+
const emit = (event) => {
|
|
6032
|
+
if (!claimed && !options.bufferEvents || iteratorClosed) return;
|
|
6033
|
+
if (pending) {
|
|
6034
|
+
pending.resolve({ value: immutable(event), done: false });
|
|
6035
|
+
pending = void 0;
|
|
6036
|
+
} else if (queue.length < 256) queue.push(immutable(event));
|
|
6037
|
+
else {
|
|
6038
|
+
iteratorError = new ArbiError("Raw response event consumer fell behind.", {
|
|
6039
|
+
code: "RESPONSE_EVENT_OVERFLOW"
|
|
6195
6040
|
});
|
|
6196
|
-
queue.
|
|
6197
|
-
|
|
6198
|
-
issued++;
|
|
6041
|
+
queue.length = 0;
|
|
6042
|
+
iteratorClosed = true;
|
|
6199
6043
|
}
|
|
6200
6044
|
};
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
if (isShort) done = true;
|
|
6208
|
-
tryEnqueue();
|
|
6209
|
-
if (page.length > 0) {
|
|
6210
|
-
yield page;
|
|
6211
|
-
pagesYielded++;
|
|
6212
|
-
}
|
|
6213
|
-
if (isShort) return;
|
|
6214
|
-
if (pagesYielded >= MAX_PAGES) break;
|
|
6215
|
-
}
|
|
6216
|
-
if (!signal?.aborted && !done && pagesYielded >= MAX_PAGES) {
|
|
6217
|
-
console.warn(
|
|
6218
|
-
`[arbi-sdk] listPaginated hit MAX_PAGES (${MAX_PAGES}) \u2014 stopped. Workspace may have more than ${MAX_PAGES * pageSize} documents.`
|
|
6219
|
-
);
|
|
6220
|
-
}
|
|
6221
|
-
}
|
|
6222
|
-
async function listAll(arbi, options = {}) {
|
|
6223
|
-
const all = [];
|
|
6224
|
-
const seen = /* @__PURE__ */ new Set();
|
|
6225
|
-
for await (const page of listPaginated(arbi, options)) {
|
|
6226
|
-
for (const doc of page) {
|
|
6227
|
-
const id = doc.external_id;
|
|
6228
|
-
if (id && !seen.has(id)) {
|
|
6229
|
-
seen.add(id);
|
|
6230
|
-
all.push(doc);
|
|
6045
|
+
const notify = () => {
|
|
6046
|
+
for (const listener of [...listeners]) {
|
|
6047
|
+
try {
|
|
6048
|
+
listener(state);
|
|
6049
|
+
} catch (error) {
|
|
6050
|
+
reportObserverError(error);
|
|
6231
6051
|
}
|
|
6232
6052
|
}
|
|
6233
|
-
}
|
|
6234
|
-
|
|
6235
|
-
}
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
async function finaliseTranslation(arbi, docId) {
|
|
6251
|
-
return requireData(
|
|
6252
|
-
await arbi.fetch.POST("/v1/document/{document_ext_id}/finalise-translation", {
|
|
6253
|
-
params: { path: { document_ext_id: docId } }
|
|
6254
|
-
}),
|
|
6255
|
-
"Failed to finalise the translation"
|
|
6256
|
-
);
|
|
6257
|
-
}
|
|
6258
|
-
async function deleteDocuments(arbi, externalIds) {
|
|
6259
|
-
requireOk(
|
|
6260
|
-
await arbi.fetch.DELETE("/v1/document/", { body: { external_ids: externalIds } }),
|
|
6261
|
-
"Failed to delete documents"
|
|
6262
|
-
);
|
|
6263
|
-
}
|
|
6264
|
-
async function updateDocuments(arbi, documents) {
|
|
6265
|
-
return requireData(
|
|
6266
|
-
await arbi.fetch.PATCH("/v1/document/", { body: { documents } }),
|
|
6267
|
-
"Failed to update documents"
|
|
6268
|
-
);
|
|
6269
|
-
}
|
|
6270
|
-
async function uploadUrl(arbi, urls, options) {
|
|
6271
|
-
return requireUploadData(
|
|
6272
|
-
await arbi.fetch.POST("/v1/document/upload-url", {
|
|
6273
|
-
params: {
|
|
6274
|
-
query: {
|
|
6275
|
-
urls,
|
|
6276
|
-
shared: options.shared ?? false,
|
|
6277
|
-
workspace_ext_id: options.workspaceExtId,
|
|
6278
|
-
...options.configExtId ? { config_ext_id: options.configExtId } : {}
|
|
6279
|
-
}
|
|
6280
|
-
}
|
|
6281
|
-
}),
|
|
6282
|
-
"Failed to upload from URLs"
|
|
6283
|
-
);
|
|
6284
|
-
}
|
|
6285
|
-
var UPLOAD_WORKSPACE_CONFLICT_MESSAGES = {
|
|
6286
|
-
workspace_mismatch: "These files were prepared for another workspace, so they were not saved. Upload them again.",
|
|
6287
|
-
workspace_key_required: "The workspace couldn't be unlocked for this upload, so the files were not saved."
|
|
6288
|
-
};
|
|
6289
|
-
function requireUploadData(result, message) {
|
|
6290
|
-
return requireWorkspaceData(result, message, UPLOAD_WORKSPACE_CONFLICT_MESSAGES);
|
|
6291
|
-
}
|
|
6292
|
-
async function uploadDocuments(arbi, files, options = {}) {
|
|
6293
|
-
const query2 = {};
|
|
6294
|
-
if (options.shared !== void 0) query2.shared = options.shared;
|
|
6295
|
-
if (options.folder) query2.folder = sanitizeFolderPath(options.folder);
|
|
6296
|
-
if (options.configExtId) query2.config_ext_id = options.configExtId;
|
|
6297
|
-
if (options.wpType) query2.wp_type = options.wpType;
|
|
6298
|
-
if (options.versionOf) query2.version_of = options.versionOf;
|
|
6299
|
-
if (options.tagExtId) query2.tag_ext_id = options.tagExtId;
|
|
6300
|
-
if (options.workspaceExtId) query2.workspace_ext_id = options.workspaceExtId;
|
|
6301
|
-
if (options.derivedFrom) {
|
|
6302
|
-
query2.derived_from = options.derivedFrom.docId;
|
|
6303
|
-
query2.derived_role = options.derivedFrom.role;
|
|
6304
|
-
}
|
|
6305
|
-
const result = await arbi.fetch.POST("/v1/document/upload", {
|
|
6306
|
-
params: { query: query2 },
|
|
6307
|
-
...options.onProgress ? { fetch: progressFetch(options.onProgress, arbi.http) } : {},
|
|
6308
|
-
// The schema types the files as strings; they go as multipart parts.
|
|
6309
|
-
body: { files },
|
|
6310
|
-
bodySerializer: () => {
|
|
6311
|
-
const form = new FormData();
|
|
6312
|
-
for (const file of files) form.append("files", file);
|
|
6313
|
-
return form;
|
|
6053
|
+
};
|
|
6054
|
+
const update = (patch) => {
|
|
6055
|
+
state = immutable({ ...state, ...patch });
|
|
6056
|
+
notify();
|
|
6057
|
+
};
|
|
6058
|
+
const finish = (value, detached = false) => {
|
|
6059
|
+
if (finished) return;
|
|
6060
|
+
finished = true;
|
|
6061
|
+
releaseCapacity();
|
|
6062
|
+
controller.signal.removeEventListener("abort", abort);
|
|
6063
|
+
options.cleanup?.();
|
|
6064
|
+
update({ connection: detached ? "detached" : "closed", outcome: immutable(value) });
|
|
6065
|
+
listeners.clear();
|
|
6066
|
+
resolveOutcome(state.outcome);
|
|
6067
|
+
if (pending) {
|
|
6068
|
+
pending.resolve({ value: void 0, done: true });
|
|
6069
|
+
pending = void 0;
|
|
6314
6070
|
}
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
}
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6071
|
+
void reader.cancel().catch(() => {
|
|
6072
|
+
});
|
|
6073
|
+
};
|
|
6074
|
+
const abort = () => {
|
|
6075
|
+
if (!bound) rejectStart(new DOMException("The operation was aborted.", "AbortError"));
|
|
6076
|
+
finish({ status: "disconnected", responseId: bound ? state.id : null, reason: "aborted" }, true);
|
|
6077
|
+
queue.length = 0;
|
|
6078
|
+
};
|
|
6079
|
+
const handle = {
|
|
6080
|
+
get id() {
|
|
6081
|
+
return state.id;
|
|
6082
|
+
},
|
|
6083
|
+
snapshot: () => state,
|
|
6084
|
+
subscribe(listener) {
|
|
6085
|
+
if (!finished) listeners.add(listener);
|
|
6086
|
+
try {
|
|
6087
|
+
listener(state);
|
|
6088
|
+
} catch (error) {
|
|
6089
|
+
reportObserverError(error);
|
|
6090
|
+
}
|
|
6091
|
+
return () => {
|
|
6092
|
+
listeners.delete(listener);
|
|
6093
|
+
};
|
|
6094
|
+
},
|
|
6095
|
+
outcome,
|
|
6096
|
+
detach: () => {
|
|
6097
|
+
if (!finished) controller.abort();
|
|
6098
|
+
},
|
|
6099
|
+
cancel: () => cancel(state.id),
|
|
6100
|
+
events() {
|
|
6101
|
+
if (claimed)
|
|
6102
|
+
throw new ArbiError("A response handle supports one raw event iterator.", {
|
|
6103
|
+
code: "RESPONSE_EVENTS_ALREADY_CLAIMED"
|
|
6104
|
+
});
|
|
6105
|
+
claimed = true;
|
|
6106
|
+
const close = () => {
|
|
6107
|
+
iteratorClosed = true;
|
|
6108
|
+
queue.length = 0;
|
|
6109
|
+
releaseCapacity();
|
|
6110
|
+
if (pending) {
|
|
6111
|
+
pending.resolve({ value: void 0, done: true });
|
|
6112
|
+
pending = void 0;
|
|
6113
|
+
}
|
|
6114
|
+
};
|
|
6115
|
+
return {
|
|
6116
|
+
[Symbol.asyncIterator]() {
|
|
6117
|
+
return this;
|
|
6118
|
+
},
|
|
6119
|
+
next() {
|
|
6120
|
+
if (iteratorError) return Promise.reject(iteratorError);
|
|
6121
|
+
if (queue.length) {
|
|
6122
|
+
const value = queue.shift();
|
|
6123
|
+
releaseCapacity();
|
|
6124
|
+
return Promise.resolve({ value, done: false });
|
|
6125
|
+
}
|
|
6126
|
+
if (finished || iteratorClosed)
|
|
6127
|
+
return Promise.resolve({ value: void 0, done: true });
|
|
6128
|
+
if (pending)
|
|
6129
|
+
return Promise.reject(
|
|
6130
|
+
new ArbiError("Concurrent iterator reads are unsupported.", {
|
|
6131
|
+
code: "RESPONSE_EVENTS_CONCURRENT_READ"
|
|
6132
|
+
})
|
|
6133
|
+
);
|
|
6134
|
+
return new Promise((resolve2, reject) => {
|
|
6135
|
+
pending = { resolve: resolve2, reject };
|
|
6136
|
+
});
|
|
6137
|
+
},
|
|
6138
|
+
async return() {
|
|
6139
|
+
close();
|
|
6140
|
+
return { value: void 0, done: true };
|
|
6141
|
+
},
|
|
6142
|
+
async throw(error) {
|
|
6143
|
+
close();
|
|
6144
|
+
throw error;
|
|
6325
6145
|
}
|
|
6146
|
+
};
|
|
6147
|
+
}
|
|
6148
|
+
};
|
|
6149
|
+
const bind = (id) => {
|
|
6150
|
+
if (bound) return;
|
|
6151
|
+
bound = true;
|
|
6152
|
+
state = immutable({ ...state, id, connection: "streaming" });
|
|
6153
|
+
resolveStart({ kind: "response", handle });
|
|
6154
|
+
};
|
|
6155
|
+
const diagnostic = (code, frame) => emit({ event: "arbi.sdk.protocol_error", data: { code, frame } });
|
|
6156
|
+
const process2 = (frame) => {
|
|
6157
|
+
if (finished) return;
|
|
6158
|
+
let data;
|
|
6159
|
+
if (frame.event === "reasoning") {
|
|
6160
|
+
emit({
|
|
6161
|
+
event: frame.event,
|
|
6162
|
+
data: frame.data,
|
|
6163
|
+
...frame.id !== void 0 ? { id: frame.id } : {}
|
|
6164
|
+
});
|
|
6165
|
+
return;
|
|
6166
|
+
}
|
|
6167
|
+
try {
|
|
6168
|
+
data = JSON.parse(frame.data);
|
|
6169
|
+
} catch {
|
|
6170
|
+
diagnostic("MALFORMED_JSON", frame);
|
|
6171
|
+
return;
|
|
6172
|
+
}
|
|
6173
|
+
const payload = object(data);
|
|
6174
|
+
const raw = object(payload?.response);
|
|
6175
|
+
const id = raw?.id;
|
|
6176
|
+
if (bound && typeof id === "string" && id !== state.id) {
|
|
6177
|
+
diagnostic("CONFLICTING_RESPONSE_ID", frame);
|
|
6178
|
+
return;
|
|
6179
|
+
}
|
|
6180
|
+
if (messageId(id)) bind(id);
|
|
6181
|
+
emit({ event: frame.event, data, ...frame.id !== void 0 ? { id: frame.id } : {} });
|
|
6182
|
+
if (frame.event === "arbi.message_queued") acknowledgement = payload;
|
|
6183
|
+
const patch = {};
|
|
6184
|
+
if (frame.event === "arbi.user_message" && !state.conversationId && typeof payload?.conversation_ext_id === "string")
|
|
6185
|
+
patch.conversationId = payload.conversation_ext_id;
|
|
6186
|
+
if (raw) {
|
|
6187
|
+
patch.rawResponse = raw;
|
|
6188
|
+
if (typeof raw.status === "string") patch.responseStatus = raw.status;
|
|
6189
|
+
if (Array.isArray(raw.output))
|
|
6190
|
+
patch.output = raw.output.filter((item2) => !!object(item2));
|
|
6191
|
+
const metadata = object(raw.metadata);
|
|
6192
|
+
const conversation = text(metadata?.conversation_ext_id) ?? text(metadata?.conversation_id) ?? text(raw.conversation_id);
|
|
6193
|
+
if (conversation && (!state.conversationId || state.conversationId === conversation))
|
|
6194
|
+
patch.conversationId = conversation;
|
|
6195
|
+
if (typeof metadata?.content === "string") patch.displayText = metadata.content;
|
|
6196
|
+
}
|
|
6197
|
+
const item = object(payload?.item);
|
|
6198
|
+
if ((frame.event === "response.output_item.added" || frame.event === "response.output_item.done") && item) {
|
|
6199
|
+
const output = [...state.output];
|
|
6200
|
+
const index = output.findIndex((existing) => existing.id === item.id);
|
|
6201
|
+
if (index >= 0 && item.id) output[index] = item;
|
|
6202
|
+
else
|
|
6203
|
+
output.splice(
|
|
6204
|
+
typeof payload?.output_index === "number" ? payload.output_index : output.length,
|
|
6205
|
+
0,
|
|
6206
|
+
item
|
|
6207
|
+
);
|
|
6208
|
+
patch.output = output;
|
|
6209
|
+
}
|
|
6210
|
+
const itemId = text(payload?.item_id);
|
|
6211
|
+
const delta = text(payload?.delta);
|
|
6212
|
+
if (itemId && [
|
|
6213
|
+
"response.content_part.added",
|
|
6214
|
+
"response.output_text.delta",
|
|
6215
|
+
"response.output_text.done",
|
|
6216
|
+
"response.function_call_arguments.delta",
|
|
6217
|
+
"response.reasoning_summary_text.delta"
|
|
6218
|
+
].includes(frame.event)) {
|
|
6219
|
+
const output = [...patch.output ?? state.output];
|
|
6220
|
+
let index = output.findIndex((existing) => existing.id === itemId);
|
|
6221
|
+
if (index < 0) {
|
|
6222
|
+
index = output.length;
|
|
6223
|
+
output.push({
|
|
6224
|
+
id: itemId,
|
|
6225
|
+
type: frame.event.includes("function_call") ? "function_call" : frame.event.includes("reasoning") ? "reasoning" : "message"
|
|
6226
|
+
});
|
|
6326
6227
|
}
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
const json2 = await res.json();
|
|
6348
|
-
return json2.thumbnails ?? {};
|
|
6349
|
-
}
|
|
6350
|
-
async function uploadFile(auth, fileData, fileName, options) {
|
|
6351
|
-
const formData = new FormData();
|
|
6352
|
-
formData.append("files", fileData, fileName);
|
|
6353
|
-
const params = new URLSearchParams();
|
|
6354
|
-
if (options?.shared !== void 0) params.set("shared", String(options.shared));
|
|
6355
|
-
if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
|
|
6356
|
-
if (options?.configExtId) params.set("config_ext_id", options.configExtId);
|
|
6357
|
-
if (options?.wpType) params.set("wp_type", options.wpType);
|
|
6358
|
-
if (options?.versionOf) params.set("version_of", options.versionOf);
|
|
6359
|
-
if (options?.workspaceExtId) params.set("workspace_ext_id", options.workspaceExtId);
|
|
6360
|
-
if (options?.derivedFrom) {
|
|
6361
|
-
params.set("derived_from", options.derivedFrom.docId);
|
|
6362
|
-
params.set("derived_role", options.derivedFrom.role);
|
|
6363
|
-
}
|
|
6364
|
-
const qs = params.toString();
|
|
6365
|
-
const res = await authenticatedFetch({
|
|
6366
|
-
...auth,
|
|
6367
|
-
path: qs ? `/v1/document/upload?${qs}` : `/v1/document/upload`,
|
|
6368
|
-
method: "POST",
|
|
6369
|
-
body: formData
|
|
6370
|
-
});
|
|
6371
|
-
return res.json();
|
|
6372
|
-
}
|
|
6373
|
-
async function uploadFiles(auth, files, options) {
|
|
6374
|
-
const formData = new FormData();
|
|
6375
|
-
for (const f2 of files) formData.append("files", f2.data, f2.name);
|
|
6376
|
-
const params = new URLSearchParams();
|
|
6377
|
-
if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
|
|
6378
|
-
if (options?.configExtId) params.set("config_ext_id", options.configExtId);
|
|
6379
|
-
if (options?.wpType) params.set("wp_type", options.wpType);
|
|
6380
|
-
if (options?.versionOf) params.set("version_of", options.versionOf);
|
|
6381
|
-
if (options?.derivedFrom) {
|
|
6382
|
-
params.set("derived_from", options.derivedFrom.docId);
|
|
6383
|
-
params.set("derived_role", options.derivedFrom.role);
|
|
6384
|
-
}
|
|
6385
|
-
const qs = params.toString();
|
|
6386
|
-
const res = await authenticatedFetch({
|
|
6387
|
-
...auth,
|
|
6388
|
-
path: qs ? `/v1/document/upload?${qs}` : `/v1/document/upload`,
|
|
6389
|
-
method: "POST",
|
|
6390
|
-
body: formData
|
|
6391
|
-
});
|
|
6392
|
-
return res.json();
|
|
6393
|
-
}
|
|
6394
|
-
async function downloadDocument(auth, docId, version) {
|
|
6395
|
-
return authenticatedFetch({
|
|
6396
|
-
...auth,
|
|
6397
|
-
path: `/v1/document/${docId}/download${version ? `?version=${version}` : ""}`
|
|
6398
|
-
});
|
|
6399
|
-
}
|
|
6400
|
-
function mimeFromName(name) {
|
|
6401
|
-
const dot = name.lastIndexOf(".");
|
|
6402
|
-
const ext = dot === -1 ? "" : name.slice(dot).toLowerCase();
|
|
6403
|
-
switch (ext) {
|
|
6404
|
-
case ".pdf":
|
|
6405
|
-
return "application/pdf";
|
|
6406
|
-
case ".txt":
|
|
6407
|
-
return "text/plain";
|
|
6408
|
-
case ".md":
|
|
6409
|
-
return "text/markdown";
|
|
6410
|
-
case ".html":
|
|
6411
|
-
case ".htm":
|
|
6412
|
-
return "text/html";
|
|
6413
|
-
case ".doc":
|
|
6414
|
-
return "application/msword";
|
|
6415
|
-
case ".docx":
|
|
6416
|
-
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
6417
|
-
case ".xls":
|
|
6418
|
-
return "application/vnd.ms-excel";
|
|
6419
|
-
case ".xlsx":
|
|
6420
|
-
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
6421
|
-
case ".ppt":
|
|
6422
|
-
return "application/vnd.ms-powerpoint";
|
|
6423
|
-
case ".pptx":
|
|
6424
|
-
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
6425
|
-
case ".eml":
|
|
6426
|
-
return "message/rfc822";
|
|
6427
|
-
case ".pst":
|
|
6428
|
-
case ".ost":
|
|
6429
|
-
return "application/vnd.ms-outlook";
|
|
6430
|
-
default:
|
|
6431
|
-
return void 0;
|
|
6432
|
-
}
|
|
6433
|
-
}
|
|
6434
|
-
async function presignedPut(url, body, onProgress, headers) {
|
|
6435
|
-
const XhrGlobal = globalThis.XMLHttpRequest;
|
|
6436
|
-
if (XhrGlobal) {
|
|
6437
|
-
await new Promise((resolve2, reject) => {
|
|
6438
|
-
const xhr = new XhrGlobal();
|
|
6439
|
-
xhr.open("PUT", url);
|
|
6440
|
-
for (const [name, value] of Object.entries(headers ?? {})) {
|
|
6441
|
-
xhr.setRequestHeader(name, value);
|
|
6228
|
+
const current = { ...output[index] };
|
|
6229
|
+
if (frame.event === "response.function_call_arguments.delta")
|
|
6230
|
+
current.arguments = (text(current.arguments) ?? "") + (delta ?? "");
|
|
6231
|
+
else {
|
|
6232
|
+
const key = frame.event.includes("reasoning") ? "summary" : "content";
|
|
6233
|
+
const content = Array.isArray(current[key]) ? [...current[key]] : [];
|
|
6234
|
+
const partIndex = typeof payload?.content_index === "number" ? payload.content_index : typeof payload?.summary_index === "number" ? payload.summary_index : 0;
|
|
6235
|
+
const part = {
|
|
6236
|
+
...object(content[partIndex]) ?? {
|
|
6237
|
+
type: key === "summary" ? "summary_text" : "output_text",
|
|
6238
|
+
text: ""
|
|
6239
|
+
}
|
|
6240
|
+
};
|
|
6241
|
+
if (frame.event === "response.content_part.added")
|
|
6242
|
+
content[partIndex] = object(payload?.part) ?? part;
|
|
6243
|
+
else {
|
|
6244
|
+
part.text = frame.event === "response.output_text.done" ? text(payload?.text) ?? "" : (text(part.text) ?? "") + (delta ?? "");
|
|
6245
|
+
content[partIndex] = part;
|
|
6246
|
+
}
|
|
6247
|
+
current[key] = content;
|
|
6442
6248
|
}
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6249
|
+
output[index] = current;
|
|
6250
|
+
patch.output = output;
|
|
6251
|
+
}
|
|
6252
|
+
if (frame.event === "response.output_text.delta" && delta)
|
|
6253
|
+
patch.displayText = state.displayText + delta;
|
|
6254
|
+
if (frame.event === "response.output_text.done" && typeof payload?.text === "string")
|
|
6255
|
+
patch.displayText = payload.text;
|
|
6256
|
+
update(patch);
|
|
6257
|
+
const terminal = /^response\.(completed|failed|cancelled|incomplete)$/.exec(
|
|
6258
|
+
frame.event
|
|
6259
|
+
)?.[1];
|
|
6260
|
+
if (terminal && bound) {
|
|
6261
|
+
const status = raw?.status;
|
|
6262
|
+
const resolved = status === "completed" || status === "failed" || status === "cancelled" || status === "incomplete" ? status : terminal;
|
|
6263
|
+
const error = resolved === "failed" || raw?.error ? new ArbiApiError(
|
|
6264
|
+
text(object(raw?.error)?.message) ?? "Response failed.",
|
|
6265
|
+
{ response: raw },
|
|
6266
|
+
void 0,
|
|
6267
|
+
{ ...apiErrorMetadata({ response: raw }), responseId: state.id }
|
|
6268
|
+
) : void 0;
|
|
6269
|
+
finish({
|
|
6270
|
+
status: resolved,
|
|
6271
|
+
responseId: state.id,
|
|
6272
|
+
...raw ? { response: raw } : {},
|
|
6273
|
+
...error ? { error } : {}
|
|
6274
|
+
});
|
|
6275
|
+
}
|
|
6276
|
+
};
|
|
6277
|
+
controller.signal.addEventListener("abort", abort, { once: true });
|
|
6278
|
+
if (controller.signal.aborted) abort();
|
|
6279
|
+
else if (options.id) bind(options.id);
|
|
6280
|
+
void (async () => {
|
|
6281
|
+
const decoder = new TextDecoder();
|
|
6282
|
+
const frames = new ResponseEventDecoder();
|
|
6283
|
+
try {
|
|
6284
|
+
while (!finished) {
|
|
6285
|
+
const { value, done } = await reader.read();
|
|
6286
|
+
for (const frame of frames.push(decoder.decode(value, { stream: !done }), done)) {
|
|
6287
|
+
process2(frame);
|
|
6288
|
+
if (options.bufferEvents && bound && !finished && !iteratorClosed && queue.length >= 256)
|
|
6289
|
+
await new Promise((resolve2) => {
|
|
6290
|
+
capacityAvailable = resolve2;
|
|
6291
|
+
});
|
|
6292
|
+
}
|
|
6293
|
+
if (done) break;
|
|
6447
6294
|
}
|
|
6448
|
-
|
|
6449
|
-
if (
|
|
6450
|
-
|
|
6295
|
+
if (!finished) {
|
|
6296
|
+
if (!bound && acknowledgement) {
|
|
6297
|
+
const value = { status: "acknowledged", responseId: null };
|
|
6298
|
+
resolveStart({
|
|
6299
|
+
kind: "acknowledged",
|
|
6300
|
+
acknowledgement: immutable(acknowledgement),
|
|
6301
|
+
outcome: immutable(value)
|
|
6302
|
+
});
|
|
6303
|
+
finish(value);
|
|
6451
6304
|
} else {
|
|
6452
|
-
|
|
6453
|
-
|
|
6305
|
+
if (!bound)
|
|
6306
|
+
rejectStart(
|
|
6307
|
+
new ArbiApiError(
|
|
6308
|
+
"Stream ended before response identity was established.",
|
|
6309
|
+
void 0,
|
|
6310
|
+
void 0,
|
|
6311
|
+
{ code: "MISSING_RESPONSE_ID" }
|
|
6312
|
+
)
|
|
6313
|
+
);
|
|
6314
|
+
finish({
|
|
6315
|
+
status: "disconnected",
|
|
6316
|
+
responseId: bound ? state.id : null,
|
|
6317
|
+
reason: "connection_closed"
|
|
6318
|
+
});
|
|
6454
6319
|
}
|
|
6455
|
-
}
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
}
|
|
6320
|
+
}
|
|
6321
|
+
} catch (cause) {
|
|
6322
|
+
if (!finished) {
|
|
6323
|
+
const error = transportError(cause, bound ? state.id : void 0);
|
|
6324
|
+
if (!bound) rejectStart(error);
|
|
6325
|
+
finish({
|
|
6326
|
+
status: "disconnected",
|
|
6327
|
+
responseId: bound ? state.id : null,
|
|
6328
|
+
reason: error.name === "AbortError" ? "aborted" : "connection_error",
|
|
6329
|
+
...error instanceof ArbiError ? { error } : {}
|
|
6330
|
+
});
|
|
6331
|
+
}
|
|
6332
|
+
} finally {
|
|
6333
|
+
reader.releaseLock();
|
|
6334
|
+
}
|
|
6335
|
+
})();
|
|
6336
|
+
return start;
|
|
6471
6337
|
}
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6338
|
+
|
|
6339
|
+
// src/operations/documents.ts
|
|
6340
|
+
var documents_exports = {};
|
|
6341
|
+
__export(documents_exports, {
|
|
6342
|
+
MAX_PAGES: () => MAX_PAGES,
|
|
6343
|
+
SUPPORTED_EXTENSIONS: () => SUPPORTED_EXTENSIONS,
|
|
6344
|
+
deleteDocuments: () => deleteDocuments,
|
|
6345
|
+
downloadDocument: () => downloadDocument,
|
|
6346
|
+
finaliseTranslation: () => finaliseTranslation,
|
|
6347
|
+
getDocuments: () => getDocuments,
|
|
6348
|
+
getParsedContent: () => getParsedContent,
|
|
6349
|
+
getThumbnails: () => getThumbnails,
|
|
6350
|
+
listAll: () => listAll,
|
|
6351
|
+
listDocuments: () => listDocuments,
|
|
6352
|
+
listPaginated: () => listPaginated,
|
|
6353
|
+
listVersions: () => listVersions,
|
|
6354
|
+
mimeFromName: () => mimeFromName,
|
|
6355
|
+
presignedPut: () => presignedPut,
|
|
6356
|
+
sanitizeFolderPath: () => sanitizeFolderPath,
|
|
6357
|
+
similarDocuments: () => similarDocuments,
|
|
6358
|
+
updateDocuments: () => updateDocuments,
|
|
6359
|
+
uploadDocuments: () => uploadDocuments,
|
|
6360
|
+
uploadDocumentsDirect: () => uploadDocumentsDirect,
|
|
6361
|
+
uploadFile: () => uploadFile,
|
|
6362
|
+
uploadFiles: () => uploadFiles,
|
|
6363
|
+
uploadUrl: () => uploadUrl
|
|
6364
|
+
});
|
|
6365
|
+
var MAX_PAGES = 400;
|
|
6366
|
+
var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
6367
|
+
".pdf",
|
|
6368
|
+
".txt",
|
|
6369
|
+
".md",
|
|
6370
|
+
".html",
|
|
6371
|
+
".htm",
|
|
6372
|
+
".doc",
|
|
6373
|
+
".docx",
|
|
6374
|
+
".rtf",
|
|
6375
|
+
".ppt",
|
|
6376
|
+
".pptx",
|
|
6377
|
+
".xls",
|
|
6378
|
+
".xlsx",
|
|
6379
|
+
".jpg",
|
|
6380
|
+
".jpeg",
|
|
6381
|
+
".png",
|
|
6382
|
+
".gif",
|
|
6383
|
+
".bmp",
|
|
6384
|
+
".tiff",
|
|
6385
|
+
".tif",
|
|
6386
|
+
".webp",
|
|
6387
|
+
// Video (store only, no parsing)
|
|
6388
|
+
".mp4",
|
|
6389
|
+
".mpeg",
|
|
6390
|
+
".mpg",
|
|
6391
|
+
".webm",
|
|
6392
|
+
".mov",
|
|
6393
|
+
".avi",
|
|
6394
|
+
".mkv",
|
|
6395
|
+
// Audio (store only, no parsing)
|
|
6396
|
+
".mp3",
|
|
6397
|
+
".wav",
|
|
6398
|
+
".m4a",
|
|
6399
|
+
".aac",
|
|
6400
|
+
".ogg",
|
|
6401
|
+
".flac",
|
|
6402
|
+
// Email formats (parsed for content)
|
|
6403
|
+
".eml",
|
|
6404
|
+
".msg",
|
|
6405
|
+
".mbox",
|
|
6406
|
+
".pst",
|
|
6407
|
+
".ost"
|
|
6408
|
+
]);
|
|
6409
|
+
function sanitizeFolderPath(folderPath) {
|
|
6410
|
+
return folderPath.replace(/[\x00-\x1f\x7f]/g, "").replace(/\\/g, "/").replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "").trim();
|
|
6411
|
+
}
|
|
6412
|
+
async function listDocuments(arbi, workspaceExtId) {
|
|
6413
|
+
if (!workspaceExtId) {
|
|
6414
|
+
return requireData(await arbi.fetch.GET("/v1/document/list"), "Failed to fetch documents");
|
|
6475
6415
|
}
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
encrypted_file_size: f2.data.length + SECRETBOX_ENVELOPE_OVERHEAD,
|
|
6482
|
-
content_hash: createContentHash(f2.data, workspaceKey),
|
|
6483
|
-
content_type: f2.contentType ?? null
|
|
6484
|
-
}));
|
|
6485
|
-
const initBody = {
|
|
6486
|
-
files: declared,
|
|
6487
|
-
shared: options.shared !== false,
|
|
6488
|
-
config_ext_id: options.configExtId ?? null,
|
|
6489
|
-
// Only sent when set, so a plain upload is accepted by any server version.
|
|
6490
|
-
...options.versionOf ? { version_of: options.versionOf } : {},
|
|
6491
|
-
wp_type: options.wpType ?? null,
|
|
6492
|
-
tag_ext_id: options.tagExtId ?? null,
|
|
6493
|
-
folder: options.folder ? sanitizeFolderPath(options.folder) : null,
|
|
6494
|
-
presign_expires_in: options.presignExpiresIn ?? 3600
|
|
6495
|
-
};
|
|
6496
|
-
const query2 = { workspace_ext_id: options.workspaceExtId };
|
|
6497
|
-
const initResult = requireUploadData(
|
|
6498
|
-
await arbi.fetch.POST("/v1/document/upload-init", { params: { query: query2 }, body: initBody }),
|
|
6499
|
-
"Failed to initialize direct upload"
|
|
6416
|
+
const docs = requireData(
|
|
6417
|
+
await arbi.fetch.GET("/v1/document/list", {
|
|
6418
|
+
params: { query: { workspace_ext_id: workspaceExtId } }
|
|
6419
|
+
}),
|
|
6420
|
+
"Failed to fetch documents"
|
|
6500
6421
|
);
|
|
6501
|
-
|
|
6502
|
-
|
|
6503
|
-
for (const f2 of files) {
|
|
6504
|
-
if (!bytesByName.has(f2.name)) bytesByName.set(f2.name, []);
|
|
6505
|
-
bytesByName.get(f2.name).push(f2.data);
|
|
6422
|
+
if (docs.some((doc) => doc.workspace_ext_id !== workspaceExtId)) {
|
|
6423
|
+
throw new ArbiError(`This server cannot list workspace ${workspaceExtId} without opening it`);
|
|
6506
6424
|
}
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6513
|
-
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6425
|
+
return docs;
|
|
6426
|
+
}
|
|
6427
|
+
async function* listPaginated(arbi, options = {}) {
|
|
6428
|
+
const {
|
|
6429
|
+
pageSize = 5e3,
|
|
6430
|
+
firstPageSize,
|
|
6431
|
+
order = "id_asc",
|
|
6432
|
+
fields,
|
|
6433
|
+
signal,
|
|
6434
|
+
lookahead = 1,
|
|
6435
|
+
workspaceExtId
|
|
6436
|
+
} = options;
|
|
6437
|
+
const fetchPage = async (pageOffset, limit) => {
|
|
6438
|
+
const query2 = {
|
|
6439
|
+
limit,
|
|
6440
|
+
offset: pageOffset,
|
|
6441
|
+
order
|
|
6442
|
+
};
|
|
6443
|
+
if (fields) query2.fields = fields;
|
|
6444
|
+
if (workspaceExtId) query2.workspace_ext_id = workspaceExtId;
|
|
6445
|
+
const { data, error } = await arbi.fetch.GET("/v1/document/list", {
|
|
6446
|
+
params: { query: query2 },
|
|
6447
|
+
signal
|
|
6448
|
+
});
|
|
6449
|
+
if (error) {
|
|
6450
|
+
throw new Error(typeof error === "string" ? error : JSON.stringify(error));
|
|
6521
6451
|
}
|
|
6522
|
-
const
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
throw new Error(`upload-init returned slot for unknown file: ${item.file_name}`);
|
|
6452
|
+
const page = data ?? [];
|
|
6453
|
+
if (workspaceExtId && page.some((doc) => doc.workspace_ext_id !== workspaceExtId)) {
|
|
6454
|
+
throw new ArbiError(`The server returned another workspace's documents for ${workspaceExtId}`);
|
|
6526
6455
|
}
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6456
|
+
return page;
|
|
6457
|
+
};
|
|
6458
|
+
if (signal?.aborted) return;
|
|
6459
|
+
const depth = Math.max(1, Math.min(lookahead, MAX_PAGES));
|
|
6460
|
+
let issued = 0;
|
|
6461
|
+
let pagesYielded = 0;
|
|
6462
|
+
let nextOffsetToIssue = 0;
|
|
6463
|
+
let done = false;
|
|
6464
|
+
const queue = [];
|
|
6465
|
+
const tryEnqueue = () => {
|
|
6466
|
+
while (!done && queue.length < depth && issued < MAX_PAGES) {
|
|
6467
|
+
const limit = issued === 0 && firstPageSize !== void 0 ? firstPageSize : pageSize;
|
|
6468
|
+
const promise = fetchPage(nextOffsetToIssue, limit);
|
|
6469
|
+
promise.catch(() => {
|
|
6539
6470
|
});
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
);
|
|
6471
|
+
queue.push({ limit, promise });
|
|
6472
|
+
nextOffsetToIssue += limit;
|
|
6473
|
+
issued++;
|
|
6544
6474
|
}
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6475
|
+
};
|
|
6476
|
+
tryEnqueue();
|
|
6477
|
+
while (queue.length > 0 && !signal?.aborted) {
|
|
6478
|
+
const { limit, promise } = queue.shift();
|
|
6479
|
+
const page = await promise;
|
|
6480
|
+
if (signal?.aborted) return;
|
|
6481
|
+
const isShort = page.length < limit;
|
|
6482
|
+
if (isShort) done = true;
|
|
6483
|
+
tryEnqueue();
|
|
6484
|
+
if (page.length > 0) {
|
|
6485
|
+
yield page;
|
|
6486
|
+
pagesYielded++;
|
|
6487
|
+
}
|
|
6488
|
+
if (isShort) return;
|
|
6489
|
+
if (pagesYielded >= MAX_PAGES) break;
|
|
6552
6490
|
}
|
|
6553
|
-
if (
|
|
6554
|
-
|
|
6491
|
+
if (!signal?.aborted && !done && pagesYielded >= MAX_PAGES) {
|
|
6492
|
+
console.warn(
|
|
6493
|
+
`[arbi-sdk] listPaginated hit MAX_PAGES (${MAX_PAGES}) \u2014 stopped. Workspace may have more than ${MAX_PAGES * pageSize} documents.`
|
|
6494
|
+
);
|
|
6555
6495
|
}
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6496
|
+
}
|
|
6497
|
+
async function listAll(arbi, options = {}) {
|
|
6498
|
+
const all = [];
|
|
6499
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6500
|
+
for await (const page of listPaginated(arbi, options)) {
|
|
6501
|
+
for (const doc of page) {
|
|
6502
|
+
const id = doc.external_id;
|
|
6503
|
+
if (id && !seen.has(id)) {
|
|
6504
|
+
seen.add(id);
|
|
6505
|
+
all.push(doc);
|
|
6562
6506
|
}
|
|
6563
|
-
}
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
return {
|
|
6567
|
-
doc_ext_ids: commitResult.doc_ext_ids ?? [],
|
|
6568
|
-
version: commitResult.version ?? null,
|
|
6569
|
-
skipped: [...skipped, ...commitResult.skipped ?? []]
|
|
6570
|
-
};
|
|
6507
|
+
}
|
|
6508
|
+
}
|
|
6509
|
+
return all;
|
|
6571
6510
|
}
|
|
6572
|
-
|
|
6573
|
-
// src/operations/signature-requests.ts
|
|
6574
|
-
var signature_requests_exports = {};
|
|
6575
|
-
__export(signature_requests_exports, {
|
|
6576
|
-
assignSuggestions: () => assignSuggestions,
|
|
6577
|
-
createSignatureRequest: () => createSignatureRequest,
|
|
6578
|
-
declineSignatureRequest: () => declineSignatureRequest,
|
|
6579
|
-
getSignatureRequest: () => getSignatureRequest,
|
|
6580
|
-
listDocumentSignatureRequests: () => listDocumentSignatureRequests,
|
|
6581
|
-
listSignatureRequests: () => listSignatureRequests,
|
|
6582
|
-
sendSignatureRequest: () => sendSignatureRequest,
|
|
6583
|
-
suggestSignatureFields: () => suggestSignatureFields,
|
|
6584
|
-
voidSignatureRequest: () => voidSignatureRequest
|
|
6585
|
-
});
|
|
6586
|
-
async function listSignatureRequests(arbi, awaitingMe = false) {
|
|
6511
|
+
async function getDocuments(arbi, externalIds) {
|
|
6587
6512
|
return requireData(
|
|
6588
|
-
await arbi.fetch.GET("/v1/
|
|
6589
|
-
|
|
6590
|
-
}),
|
|
6591
|
-
"Failed to list signature requests"
|
|
6513
|
+
await arbi.fetch.GET("/v1/document/", { params: { query: { external_ids: externalIds } } }),
|
|
6514
|
+
"Failed to fetch documents"
|
|
6592
6515
|
);
|
|
6593
6516
|
}
|
|
6594
|
-
async function
|
|
6517
|
+
async function listVersions(arbi, docId) {
|
|
6595
6518
|
return requireData(
|
|
6596
|
-
await arbi.fetch.GET("/v1/document/{document_ext_id}/
|
|
6519
|
+
await arbi.fetch.GET("/v1/document/{document_ext_id}/versions", {
|
|
6597
6520
|
params: { path: { document_ext_id: docId } }
|
|
6598
6521
|
}),
|
|
6599
|
-
"Failed to
|
|
6600
|
-
);
|
|
6601
|
-
}
|
|
6602
|
-
async function getSignatureRequest(arbi, requestId) {
|
|
6603
|
-
return requireData(
|
|
6604
|
-
await arbi.fetch.GET("/v1/signature-requests/{request_ext_id}", {
|
|
6605
|
-
params: { path: { request_ext_id: requestId } }
|
|
6606
|
-
}),
|
|
6607
|
-
"Failed to fetch the signature request"
|
|
6608
|
-
);
|
|
6609
|
-
}
|
|
6610
|
-
async function suggestSignatureFields(arbi, docId, version) {
|
|
6611
|
-
const data = requireData(
|
|
6612
|
-
await arbi.fetch.GET("/v1/document/{document_ext_id}/signature-fields/suggest", {
|
|
6613
|
-
params: { path: { document_ext_id: docId }, ...version ? { query: { version } } : {} }
|
|
6614
|
-
}),
|
|
6615
|
-
"Failed to find signature blocks"
|
|
6616
|
-
);
|
|
6617
|
-
return data.fields;
|
|
6618
|
-
}
|
|
6619
|
-
function assignSuggestions(suggestions, signers) {
|
|
6620
|
-
const groups = [...new Set(suggestions.filter((s2) => !s2.signer_email).map((s2) => s2.group))];
|
|
6621
|
-
return suggestions.flatMap((s2, i2) => {
|
|
6622
|
-
const signer = s2.signer_email ?? signers[groups.indexOf(s2.group)];
|
|
6623
|
-
if (!signer) return [];
|
|
6624
|
-
const { type, page, x: x2, y: y2, width, height } = s2;
|
|
6625
|
-
return [
|
|
6626
|
-
{ id: `s${i2 + 1}`, type, page, x: x2, y: y2, width, height, signer, required: s2.required ?? true }
|
|
6627
|
-
];
|
|
6628
|
-
});
|
|
6629
|
-
}
|
|
6630
|
-
async function createSignatureRequest(arbi, docId, { fields, version, message, send = true }) {
|
|
6631
|
-
return requireData(
|
|
6632
|
-
await arbi.fetch.POST("/v1/document/{document_ext_id}/signature-requests", {
|
|
6633
|
-
params: { path: { document_ext_id: docId } },
|
|
6634
|
-
body: { fields, send, message: message ?? null, ...version ? { version } : {} }
|
|
6635
|
-
}),
|
|
6636
|
-
"Failed to create the signature request"
|
|
6637
|
-
);
|
|
6638
|
-
}
|
|
6639
|
-
async function sendSignatureRequest(arbi, requestId) {
|
|
6640
|
-
return requireData(
|
|
6641
|
-
await arbi.fetch.POST("/v1/signature-requests/{request_ext_id}/send", {
|
|
6642
|
-
params: { path: { request_ext_id: requestId } }
|
|
6643
|
-
}),
|
|
6644
|
-
"Failed to send the signature request"
|
|
6645
|
-
);
|
|
6646
|
-
}
|
|
6647
|
-
async function voidSignatureRequest(arbi, requestId) {
|
|
6648
|
-
return requireData(
|
|
6649
|
-
await arbi.fetch.POST("/v1/signature-requests/{request_ext_id}/void", {
|
|
6650
|
-
params: { path: { request_ext_id: requestId } }
|
|
6651
|
-
}),
|
|
6652
|
-
"Failed to void the signature request"
|
|
6522
|
+
"Failed to fetch document versions"
|
|
6653
6523
|
);
|
|
6654
6524
|
}
|
|
6655
|
-
async function
|
|
6525
|
+
async function finaliseTranslation(arbi, docId) {
|
|
6656
6526
|
return requireData(
|
|
6657
|
-
await arbi.fetch.POST("/v1/
|
|
6658
|
-
params: { path: {
|
|
6659
|
-
body: { reason: reason ?? null }
|
|
6660
|
-
}),
|
|
6661
|
-
"Failed to decline the signature request"
|
|
6662
|
-
);
|
|
6663
|
-
}
|
|
6664
|
-
|
|
6665
|
-
// src/operations/house-template.ts
|
|
6666
|
-
var house_template_exports = {};
|
|
6667
|
-
__export(house_template_exports, {
|
|
6668
|
-
getDeploymentHouseTemplate: () => getDeploymentHouseTemplate,
|
|
6669
|
-
isDeploymentAdmin: () => isDeploymentAdmin,
|
|
6670
|
-
listHouseTemplateCandidates: () => listHouseTemplateCandidates,
|
|
6671
|
-
setDeploymentHouseTemplate: () => setDeploymentHouseTemplate,
|
|
6672
|
-
setWorkspaceHouseTemplate: () => setWorkspaceHouseTemplate,
|
|
6673
|
-
supportsHouseTemplates: () => supportsHouseTemplates,
|
|
6674
|
-
workspaceHouseTemplateId: () => workspaceHouseTemplateId
|
|
6675
|
-
});
|
|
6676
|
-
function supportsHouseTemplates(workspace) {
|
|
6677
|
-
return !!workspace && "house_template_ext_id" in workspace;
|
|
6678
|
-
}
|
|
6679
|
-
function workspaceHouseTemplateId(workspace) {
|
|
6680
|
-
return workspace?.house_template_ext_id ?? null;
|
|
6681
|
-
}
|
|
6682
|
-
function isDeploymentAdmin(user) {
|
|
6683
|
-
return user?.is_deployment_admin === true;
|
|
6684
|
-
}
|
|
6685
|
-
function filenameOf(response) {
|
|
6686
|
-
const header = response.headers.get("Content-Disposition") ?? "";
|
|
6687
|
-
const star = /filename\*=UTF-8''([^;]+)/i.exec(header);
|
|
6688
|
-
if (star) return decodeURIComponent(star[1]);
|
|
6689
|
-
return /filename="?([^";]+)"?/i.exec(header)?.[1];
|
|
6690
|
-
}
|
|
6691
|
-
async function getDeploymentHouseTemplate(arbi) {
|
|
6692
|
-
const { data, error, response } = await arbi.fetch.GET("/v1/deployment/house-template", {
|
|
6693
|
-
parseAs: "arrayBuffer"
|
|
6694
|
-
});
|
|
6695
|
-
const status = response.status;
|
|
6696
|
-
if (status === 204 || status === 404) return null;
|
|
6697
|
-
if (error || !data)
|
|
6698
|
-
throw new ArbiApiError("Could not read the deployment house template", error, status);
|
|
6699
|
-
return {
|
|
6700
|
-
bytes: new Uint8Array(data),
|
|
6701
|
-
name: filenameOf(response) ?? "House template.dotx"
|
|
6702
|
-
};
|
|
6703
|
-
}
|
|
6704
|
-
async function setDeploymentHouseTemplate(arbi, file) {
|
|
6705
|
-
if (!file) {
|
|
6706
|
-
requireOk(
|
|
6707
|
-
await arbi.fetch.DELETE("/v1/deployment/house-template"),
|
|
6708
|
-
"Could not clear the deployment house template"
|
|
6709
|
-
);
|
|
6710
|
-
return;
|
|
6711
|
-
}
|
|
6712
|
-
const form = new FormData();
|
|
6713
|
-
form.append("file", file);
|
|
6714
|
-
requireOk(
|
|
6715
|
-
await arbi.fetch.PUT("/v1/deployment/house-template", {
|
|
6716
|
-
// The schema types the multipart file as a string; the FormData is sent as is.
|
|
6717
|
-
body: form,
|
|
6718
|
-
bodySerializer: () => form
|
|
6527
|
+
await arbi.fetch.POST("/v1/document/{document_ext_id}/finalise-translation", {
|
|
6528
|
+
params: { path: { document_ext_id: docId } }
|
|
6719
6529
|
}),
|
|
6720
|
-
"
|
|
6721
|
-
);
|
|
6722
|
-
}
|
|
6723
|
-
async function setWorkspaceHouseTemplate(arbi, documentId) {
|
|
6724
|
-
requireData(
|
|
6725
|
-
await arbi.fetch.PATCH("/v1/workspace/", { body: { house_template_ext_id: documentId } }),
|
|
6726
|
-
"Could not set the house template"
|
|
6727
|
-
);
|
|
6728
|
-
}
|
|
6729
|
-
async function listHouseTemplateCandidates(arbi) {
|
|
6730
|
-
return requireData(
|
|
6731
|
-
await arbi.fetch.GET("/v1/workspace/house-template/candidates"),
|
|
6732
|
-
"Could not list the documents that can be the house template"
|
|
6733
|
-
);
|
|
6734
|
-
}
|
|
6735
|
-
|
|
6736
|
-
// src/operations/model-connections.ts
|
|
6737
|
-
var model_connections_exports = {};
|
|
6738
|
-
__export(model_connections_exports, {
|
|
6739
|
-
directUsage: () => directUsage,
|
|
6740
|
-
listConnections: () => listConnections,
|
|
6741
|
-
removeConnection: () => removeConnection,
|
|
6742
|
-
savePersonalConnection: () => savePersonalConnection,
|
|
6743
|
-
sealPersonalApiKey: () => sealPersonalApiKey,
|
|
6744
|
-
unlockModelConnections: () => unlockModelConnections
|
|
6745
|
-
});
|
|
6746
|
-
var FAILED = "Could not update model connections";
|
|
6747
|
-
async function listConnections(arbi) {
|
|
6748
|
-
return requireData(await arbi.fetch.GET("/v1/model-connections"), FAILED);
|
|
6749
|
-
}
|
|
6750
|
-
async function directUsage(arbi) {
|
|
6751
|
-
return requireData(
|
|
6752
|
-
await arbi.fetch.GET("/v1/model-connections/usage"),
|
|
6753
|
-
FAILED
|
|
6530
|
+
"Failed to finalise the translation"
|
|
6754
6531
|
);
|
|
6755
6532
|
}
|
|
6756
|
-
async function
|
|
6757
|
-
const result = id ? await arbi.fetch.PUT("/v1/model-connections/personal/{connection_id}", {
|
|
6758
|
-
params: { path: { connection_id: id } },
|
|
6759
|
-
body
|
|
6760
|
-
}) : await arbi.fetch.POST("/v1/model-connections/personal", { body });
|
|
6761
|
-
return requireData(result, FAILED);
|
|
6762
|
-
}
|
|
6763
|
-
async function removeConnection(arbi, id) {
|
|
6533
|
+
async function deleteDocuments(arbi, externalIds) {
|
|
6764
6534
|
requireOk(
|
|
6765
|
-
await arbi.fetch.DELETE("/v1/
|
|
6766
|
-
|
|
6767
|
-
}),
|
|
6768
|
-
FAILED
|
|
6535
|
+
await arbi.fetch.DELETE("/v1/document/", { body: { external_ids: externalIds } }),
|
|
6536
|
+
"Failed to delete documents"
|
|
6769
6537
|
);
|
|
6770
6538
|
}
|
|
6771
|
-
async function
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
return sealedBoxEncrypt(bytes, pair.publicKey);
|
|
6777
|
-
} finally {
|
|
6778
|
-
bytes.fill(0);
|
|
6779
|
-
pair.secretKey.fill(0);
|
|
6780
|
-
}
|
|
6539
|
+
async function updateDocuments(arbi, documents) {
|
|
6540
|
+
return requireData(
|
|
6541
|
+
await arbi.fetch.PATCH("/v1/document/", { body: { documents } }),
|
|
6542
|
+
"Failed to update documents"
|
|
6543
|
+
);
|
|
6781
6544
|
}
|
|
6782
|
-
async function
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
const bytes = sealedBoxDecrypt(row.sealed_api_key, pair.secretKey);
|
|
6793
|
-
try {
|
|
6794
|
-
requireOk(
|
|
6795
|
-
await arbi.fetch.POST("/v1/model-connections/session-key", {
|
|
6796
|
-
body: {
|
|
6797
|
-
connection_id: row.id,
|
|
6798
|
-
sealed_api_key: sealedBoxEncrypt(bytes, keys.serverSessionKey)
|
|
6799
|
-
}
|
|
6800
|
-
}),
|
|
6801
|
-
FAILED
|
|
6802
|
-
);
|
|
6803
|
-
} finally {
|
|
6804
|
-
bytes.fill(0);
|
|
6545
|
+
async function uploadUrl(arbi, urls, options) {
|
|
6546
|
+
return requireUploadData(
|
|
6547
|
+
await arbi.fetch.POST("/v1/document/upload-url", {
|
|
6548
|
+
params: {
|
|
6549
|
+
query: {
|
|
6550
|
+
urls,
|
|
6551
|
+
shared: options.shared ?? false,
|
|
6552
|
+
workspace_ext_id: options.workspaceExtId,
|
|
6553
|
+
...options.configExtId ? { config_ext_id: options.configExtId } : {}
|
|
6554
|
+
}
|
|
6805
6555
|
}
|
|
6806
|
-
}
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
}
|
|
6556
|
+
}),
|
|
6557
|
+
"Failed to upload from URLs"
|
|
6558
|
+
);
|
|
6810
6559
|
}
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
__export(secure_mail_exports, {
|
|
6815
|
-
claimSecureMail: () => claimSecureMail,
|
|
6816
|
-
prepareSecureMail: () => prepareSecureMail,
|
|
6817
|
-
secureMime: () => secureMime
|
|
6818
|
-
});
|
|
6819
|
-
var MAX_MESSAGE_BYTES = 25 * 1024 * 1024;
|
|
6820
|
-
var utf8 = new TextEncoder();
|
|
6821
|
-
var encodedWord = (value) => `=?UTF-8?B?${bytesToBase64(utf8.encode(value))}?=`;
|
|
6822
|
-
var folded = (value) => value.match(/.{1,76}/g)?.join("\r\n") ?? "";
|
|
6823
|
-
var safeHeader = (value) => {
|
|
6824
|
-
if (/[\r\n\0]/.test(value)) throw new Error("Email headers cannot contain newlines");
|
|
6825
|
-
return value;
|
|
6560
|
+
var UPLOAD_WORKSPACE_CONFLICT_MESSAGES = {
|
|
6561
|
+
workspace_mismatch: "These files were prepared for another workspace, so they were not saved. Upload them again.",
|
|
6562
|
+
workspace_key_required: "The workspace couldn't be unlocked for this upload, so the files were not saved."
|
|
6826
6563
|
};
|
|
6827
|
-
function
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
const
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
return `--${boundary}\r
|
|
6866
|
-
Content-Type: ${safeHeader(a2.content_type || "application/octet-stream")}\r
|
|
6867
|
-
Content-Disposition: attachment; filename*=UTF-8''${name}\r
|
|
6868
|
-
Content-Transfer-Encoding: base64\r
|
|
6869
|
-
\r
|
|
6870
|
-
${folded(a2.content_base64)}`;
|
|
6564
|
+
function requireUploadData(result, message) {
|
|
6565
|
+
return requireWorkspaceData(result, message, UPLOAD_WORKSPACE_CONFLICT_MESSAGES);
|
|
6566
|
+
}
|
|
6567
|
+
async function uploadDocuments(arbi, files, options = {}) {
|
|
6568
|
+
const query2 = {};
|
|
6569
|
+
if (options.shared !== void 0) query2.shared = options.shared;
|
|
6570
|
+
if (options.folder) query2.folder = sanitizeFolderPath(options.folder);
|
|
6571
|
+
if (options.configExtId) query2.config_ext_id = options.configExtId;
|
|
6572
|
+
if (options.wpType) query2.wp_type = options.wpType;
|
|
6573
|
+
if (options.versionOf) query2.version_of = options.versionOf;
|
|
6574
|
+
if (options.tagExtId) query2.tag_ext_id = options.tagExtId;
|
|
6575
|
+
if (options.workspaceExtId) query2.workspace_ext_id = options.workspaceExtId;
|
|
6576
|
+
if (options.derivedFrom) {
|
|
6577
|
+
query2.derived_from = options.derivedFrom.docId;
|
|
6578
|
+
query2.derived_role = options.derivedFrom.role;
|
|
6579
|
+
}
|
|
6580
|
+
const result = await arbi.fetch.POST("/v1/document/upload", {
|
|
6581
|
+
params: { query: query2 },
|
|
6582
|
+
...options.onProgress ? { fetch: progressFetch(options.onProgress, arbi.http) } : {},
|
|
6583
|
+
// The schema types the files as strings; they go as multipart parts.
|
|
6584
|
+
body: { files },
|
|
6585
|
+
bodySerializer: () => {
|
|
6586
|
+
const form = new FormData();
|
|
6587
|
+
for (const file of files) form.append("files", file);
|
|
6588
|
+
return form;
|
|
6589
|
+
}
|
|
6590
|
+
});
|
|
6591
|
+
return requireUploadData(result, "Failed to upload documents");
|
|
6592
|
+
}
|
|
6593
|
+
async function similarDocuments(arbi, options = {}) {
|
|
6594
|
+
return requireData(
|
|
6595
|
+
await arbi.fetch.GET("/v1/document/similar", {
|
|
6596
|
+
params: {
|
|
6597
|
+
query: {
|
|
6598
|
+
...options.threshold !== void 0 ? { threshold: options.threshold } : {},
|
|
6599
|
+
...options.docId ? { doc_ext_id: options.docId } : {}
|
|
6600
|
+
}
|
|
6601
|
+
}
|
|
6871
6602
|
}),
|
|
6872
|
-
|
|
6873
|
-
|
|
6874
|
-
];
|
|
6875
|
-
return utf8.encode(headers.join("\r\n") + "\r\n\r\n" + parts.join("\r\n"));
|
|
6603
|
+
"Failed to fetch similar documents"
|
|
6604
|
+
);
|
|
6876
6605
|
}
|
|
6877
|
-
async function
|
|
6878
|
-
const
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6606
|
+
async function getParsedContent(auth, docId, stage, version) {
|
|
6607
|
+
const res = await authenticatedFetch({
|
|
6608
|
+
...auth,
|
|
6609
|
+
path: `/v1/document/${docId}/parsed-${stage}${version ? `?version=${version}` : ""}`
|
|
6610
|
+
});
|
|
6611
|
+
return res.json();
|
|
6612
|
+
}
|
|
6613
|
+
async function getThumbnails(auth, docIds) {
|
|
6614
|
+
if (docIds.length === 0) return {};
|
|
6615
|
+
const res = await authenticatedFetch({
|
|
6616
|
+
...auth,
|
|
6617
|
+
path: `/v1/document/thumbnails`,
|
|
6618
|
+
method: "POST",
|
|
6619
|
+
headers: { "Content-Type": "application/json" },
|
|
6620
|
+
body: JSON.stringify({ document_ext_ids: docIds })
|
|
6621
|
+
});
|
|
6622
|
+
const json2 = await res.json();
|
|
6623
|
+
return json2.thumbnails ?? {};
|
|
6624
|
+
}
|
|
6625
|
+
async function uploadFile(auth, fileData, fileName, options) {
|
|
6626
|
+
const formData = new FormData();
|
|
6627
|
+
formData.append("files", fileData, fileName);
|
|
6628
|
+
const params = new URLSearchParams();
|
|
6629
|
+
if (options?.shared !== void 0) params.set("shared", String(options.shared));
|
|
6630
|
+
if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
|
|
6631
|
+
if (options?.configExtId) params.set("config_ext_id", options.configExtId);
|
|
6632
|
+
if (options?.wpType) params.set("wp_type", options.wpType);
|
|
6633
|
+
if (options?.versionOf) params.set("version_of", options.versionOf);
|
|
6634
|
+
if (options?.workspaceExtId) params.set("workspace_ext_id", options.workspaceExtId);
|
|
6635
|
+
if (options?.derivedFrom) {
|
|
6636
|
+
params.set("derived_from", options.derivedFrom.docId);
|
|
6637
|
+
params.set("derived_role", options.derivedFrom.role);
|
|
6638
|
+
}
|
|
6639
|
+
const qs = params.toString();
|
|
6640
|
+
const res = await authenticatedFetch({
|
|
6641
|
+
...auth,
|
|
6642
|
+
path: qs ? `/v1/document/upload?${qs}` : `/v1/document/upload`,
|
|
6643
|
+
method: "POST",
|
|
6644
|
+
body: formData
|
|
6645
|
+
});
|
|
6646
|
+
return res.json();
|
|
6647
|
+
}
|
|
6648
|
+
async function uploadFiles(auth, files, options) {
|
|
6649
|
+
const formData = new FormData();
|
|
6650
|
+
for (const f2 of files) formData.append("files", f2.data, f2.name);
|
|
6651
|
+
const params = new URLSearchParams();
|
|
6652
|
+
if (options?.folder) params.set("folder", sanitizeFolderPath(options.folder));
|
|
6653
|
+
if (options?.configExtId) params.set("config_ext_id", options.configExtId);
|
|
6654
|
+
if (options?.wpType) params.set("wp_type", options.wpType);
|
|
6655
|
+
if (options?.versionOf) params.set("version_of", options.versionOf);
|
|
6656
|
+
if (options?.derivedFrom) {
|
|
6657
|
+
params.set("derived_from", options.derivedFrom.docId);
|
|
6658
|
+
params.set("derived_role", options.derivedFrom.role);
|
|
6919
6659
|
}
|
|
6660
|
+
const qs = params.toString();
|
|
6661
|
+
const res = await authenticatedFetch({
|
|
6662
|
+
...auth,
|
|
6663
|
+
path: qs ? `/v1/document/upload?${qs}` : `/v1/document/upload`,
|
|
6664
|
+
method: "POST",
|
|
6665
|
+
body: formData
|
|
6666
|
+
});
|
|
6667
|
+
return res.json();
|
|
6920
6668
|
}
|
|
6921
|
-
async function
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6669
|
+
async function downloadDocument(auth, docId, version) {
|
|
6670
|
+
return authenticatedFetch({
|
|
6671
|
+
...auth,
|
|
6672
|
+
path: `/v1/document/${docId}/download${version ? `?version=${version}` : ""}`
|
|
6673
|
+
});
|
|
6674
|
+
}
|
|
6675
|
+
function mimeFromName(name) {
|
|
6676
|
+
const dot = name.lastIndexOf(".");
|
|
6677
|
+
const ext = dot === -1 ? "" : name.slice(dot).toLowerCase();
|
|
6678
|
+
switch (ext) {
|
|
6679
|
+
case ".pdf":
|
|
6680
|
+
return "application/pdf";
|
|
6681
|
+
case ".txt":
|
|
6682
|
+
return "text/plain";
|
|
6683
|
+
case ".md":
|
|
6684
|
+
return "text/markdown";
|
|
6685
|
+
case ".html":
|
|
6686
|
+
case ".htm":
|
|
6687
|
+
return "text/html";
|
|
6688
|
+
case ".doc":
|
|
6689
|
+
return "application/msword";
|
|
6690
|
+
case ".docx":
|
|
6691
|
+
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
6692
|
+
case ".xls":
|
|
6693
|
+
return "application/vnd.ms-excel";
|
|
6694
|
+
case ".xlsx":
|
|
6695
|
+
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
6696
|
+
case ".ppt":
|
|
6697
|
+
return "application/vnd.ms-powerpoint";
|
|
6698
|
+
case ".pptx":
|
|
6699
|
+
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
6700
|
+
case ".eml":
|
|
6701
|
+
return "message/rfc822";
|
|
6702
|
+
case ".pst":
|
|
6703
|
+
case ".ost":
|
|
6704
|
+
return "application/vnd.ms-outlook";
|
|
6705
|
+
default:
|
|
6706
|
+
return void 0;
|
|
6933
6707
|
}
|
|
6934
6708
|
}
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
}
|
|
6967
|
-
|
|
6968
|
-
|
|
6709
|
+
async function presignedPut(url, body, onProgress, headers) {
|
|
6710
|
+
const XhrGlobal = globalThis.XMLHttpRequest;
|
|
6711
|
+
if (XhrGlobal) {
|
|
6712
|
+
await new Promise((resolve2, reject) => {
|
|
6713
|
+
const xhr = new XhrGlobal();
|
|
6714
|
+
xhr.open("PUT", url);
|
|
6715
|
+
for (const [name, value] of Object.entries(headers ?? {})) {
|
|
6716
|
+
xhr.setRequestHeader(name, value);
|
|
6717
|
+
}
|
|
6718
|
+
if (onProgress) {
|
|
6719
|
+
xhr.upload.addEventListener("progress", (e) => {
|
|
6720
|
+
if (e.lengthComputable) onProgress(e.loaded, e.total);
|
|
6721
|
+
});
|
|
6722
|
+
}
|
|
6723
|
+
xhr.addEventListener("load", () => {
|
|
6724
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
6725
|
+
resolve2();
|
|
6726
|
+
} else {
|
|
6727
|
+
const snippet = (xhr.responseText || "").slice(0, 200);
|
|
6728
|
+
reject(new Error(`Presigned PUT failed: ${xhr.status} ${snippet}`));
|
|
6729
|
+
}
|
|
6730
|
+
});
|
|
6731
|
+
xhr.addEventListener("error", () => reject(new Error("Presigned PUT network error")));
|
|
6732
|
+
xhr.addEventListener("abort", () => reject(new Error("Presigned PUT aborted")));
|
|
6733
|
+
xhr.send(body);
|
|
6734
|
+
});
|
|
6735
|
+
return;
|
|
6736
|
+
}
|
|
6737
|
+
const putRes = await fetch(url, {
|
|
6738
|
+
method: "PUT",
|
|
6739
|
+
body,
|
|
6740
|
+
...headers ? { headers } : {}
|
|
6741
|
+
});
|
|
6742
|
+
if (!putRes.ok) {
|
|
6743
|
+
const snippet = await putRes.text().catch(() => "");
|
|
6744
|
+
throw new Error(`Presigned PUT failed: ${putRes.status} ${snippet.slice(0, 200)}`);
|
|
6745
|
+
}
|
|
6969
6746
|
}
|
|
6970
|
-
async function
|
|
6971
|
-
|
|
6972
|
-
|
|
6747
|
+
async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
|
|
6748
|
+
if (!options?.workspaceExtId) {
|
|
6749
|
+
throw new ArbiError("uploadDocumentsDirect needs options.workspaceExtId (the key's workspace)");
|
|
6750
|
+
}
|
|
6751
|
+
if (files.length === 0) return { doc_ext_ids: [], skipped: [] };
|
|
6752
|
+
const SECRETBOX_ENVELOPE_OVERHEAD = 40;
|
|
6753
|
+
const declared = files.map((f2) => ({
|
|
6754
|
+
file_name: f2.name,
|
|
6755
|
+
file_size: f2.data.length,
|
|
6756
|
+
encrypted_file_size: f2.data.length + SECRETBOX_ENVELOPE_OVERHEAD,
|
|
6757
|
+
content_hash: createContentHash(f2.data, workspaceKey),
|
|
6758
|
+
content_type: f2.contentType ?? null
|
|
6759
|
+
}));
|
|
6760
|
+
const initBody = {
|
|
6761
|
+
files: declared,
|
|
6762
|
+
shared: options.shared !== false,
|
|
6763
|
+
config_ext_id: options.configExtId ?? null,
|
|
6764
|
+
// Only sent when set, so a plain upload is accepted by any server version.
|
|
6765
|
+
...options.versionOf ? { version_of: options.versionOf } : {},
|
|
6766
|
+
wp_type: options.wpType ?? null,
|
|
6767
|
+
tag_ext_id: options.tagExtId ?? null,
|
|
6768
|
+
folder: options.folder ? sanitizeFolderPath(options.folder) : null,
|
|
6769
|
+
presign_expires_in: options.presignExpiresIn ?? 3600
|
|
6770
|
+
};
|
|
6771
|
+
const query2 = { workspace_ext_id: options.workspaceExtId };
|
|
6772
|
+
const initResult = requireUploadData(
|
|
6773
|
+
await arbi.fetch.POST("/v1/document/upload-init", { params: { query: query2 }, body: initBody }),
|
|
6774
|
+
"Failed to initialize direct upload"
|
|
6775
|
+
);
|
|
6776
|
+
const items = initResult.items ?? [];
|
|
6777
|
+
const bytesByName = /* @__PURE__ */ new Map();
|
|
6778
|
+
for (const f2 of files) {
|
|
6779
|
+
if (!bytesByName.has(f2.name)) bytesByName.set(f2.name, []);
|
|
6780
|
+
bytesByName.get(f2.name).push(f2.data);
|
|
6781
|
+
}
|
|
6782
|
+
const skipped = [];
|
|
6783
|
+
const toCommit = [];
|
|
6784
|
+
const indexByName = /* @__PURE__ */ new Map();
|
|
6785
|
+
files.forEach((f2, i2) => {
|
|
6786
|
+
if (!indexByName.has(f2.name)) indexByName.set(f2.name, []);
|
|
6787
|
+
indexByName.get(f2.name).push(i2);
|
|
6788
|
+
});
|
|
6789
|
+
for (const item of items) {
|
|
6790
|
+
if (item.status !== "uploading" || !item.upload_url || !item.doc_ext_id) {
|
|
6791
|
+
skipped.push({
|
|
6792
|
+
file_name: item.file_name,
|
|
6793
|
+
reason: item.reason || item.status
|
|
6794
|
+
});
|
|
6795
|
+
continue;
|
|
6796
|
+
}
|
|
6797
|
+
const queue = bytesByName.get(item.file_name);
|
|
6798
|
+
const idxQueue = indexByName.get(item.file_name);
|
|
6799
|
+
if (!queue || queue.length === 0 || !idxQueue || idxQueue.length === 0) {
|
|
6800
|
+
throw new Error(`upload-init returned slot for unknown file: ${item.file_name}`);
|
|
6801
|
+
}
|
|
6802
|
+
const raw = queue.shift();
|
|
6803
|
+
const fileIndex = idxQueue.shift();
|
|
6804
|
+
const ciphertext = encryptFile(raw, workspaceKey);
|
|
6805
|
+
const total = ciphertext.length;
|
|
6806
|
+
try {
|
|
6807
|
+
await presignedPut(item.upload_url, ciphertext, (loaded, putTotal) => {
|
|
6808
|
+
options.onBytesProgress?.({
|
|
6809
|
+
fileIndex,
|
|
6810
|
+
fileName: item.file_name,
|
|
6811
|
+
loaded,
|
|
6812
|
+
total: putTotal
|
|
6813
|
+
});
|
|
6814
|
+
});
|
|
6815
|
+
} catch (err) {
|
|
6816
|
+
throw new Error(
|
|
6817
|
+
`Presigned PUT for ${item.doc_ext_id} failed: ${err instanceof Error ? err.message : String(err)}`
|
|
6818
|
+
);
|
|
6819
|
+
}
|
|
6820
|
+
options.onBytesProgress?.({
|
|
6821
|
+
fileIndex,
|
|
6822
|
+
fileName: item.file_name,
|
|
6823
|
+
loaded: total,
|
|
6824
|
+
total
|
|
6825
|
+
});
|
|
6826
|
+
toCommit.push(item.doc_ext_id);
|
|
6827
|
+
}
|
|
6828
|
+
if (toCommit.length === 0) {
|
|
6829
|
+
return { doc_ext_ids: [], skipped };
|
|
6830
|
+
}
|
|
6831
|
+
const commitResult = requireUploadData(
|
|
6832
|
+
await arbi.fetch.POST("/v1/document/upload-commit", {
|
|
6833
|
+
params: { query: query2 },
|
|
6973
6834
|
body: {
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
is_public: isPublic,
|
|
6977
|
-
workspace_key: encryptedWorkspaceKey,
|
|
6978
|
-
project_ext_id: projectExtId
|
|
6835
|
+
doc_ext_ids: toCommit,
|
|
6836
|
+
tag_ext_id: options.tagExtId ?? null
|
|
6979
6837
|
}
|
|
6980
6838
|
}),
|
|
6981
|
-
"Failed to
|
|
6839
|
+
"Failed to commit direct upload"
|
|
6982
6840
|
);
|
|
6841
|
+
return {
|
|
6842
|
+
doc_ext_ids: commitResult.doc_ext_ids ?? [],
|
|
6843
|
+
version: commitResult.version ?? null,
|
|
6844
|
+
skipped: [...skipped, ...commitResult.skipped ?? []]
|
|
6845
|
+
};
|
|
6983
6846
|
}
|
|
6984
|
-
|
|
6847
|
+
|
|
6848
|
+
// src/operations/signature-requests.ts
|
|
6849
|
+
var signature_requests_exports = {};
|
|
6850
|
+
__export(signature_requests_exports, {
|
|
6851
|
+
assignSuggestions: () => assignSuggestions,
|
|
6852
|
+
createSignatureRequest: () => createSignatureRequest,
|
|
6853
|
+
declineSignatureRequest: () => declineSignatureRequest,
|
|
6854
|
+
getSignatureRequest: () => getSignatureRequest,
|
|
6855
|
+
listDocumentSignatureRequests: () => listDocumentSignatureRequests,
|
|
6856
|
+
listSignatureRequests: () => listSignatureRequests,
|
|
6857
|
+
sendSignatureRequest: () => sendSignatureRequest,
|
|
6858
|
+
suggestSignatureFields: () => suggestSignatureFields,
|
|
6859
|
+
voidSignatureRequest: () => voidSignatureRequest
|
|
6860
|
+
});
|
|
6861
|
+
async function listSignatureRequests(arbi, awaitingMe = false) {
|
|
6985
6862
|
return requireData(
|
|
6986
|
-
await arbi.fetch.
|
|
6987
|
-
params: {
|
|
6988
|
-
body: { project_ext_id: projectExtId }
|
|
6863
|
+
await arbi.fetch.GET("/v1/signature-requests", {
|
|
6864
|
+
params: { query: { awaiting_me: awaitingMe } }
|
|
6989
6865
|
}),
|
|
6990
|
-
"Failed to
|
|
6866
|
+
"Failed to list signature requests"
|
|
6991
6867
|
);
|
|
6992
6868
|
}
|
|
6993
|
-
async function
|
|
6869
|
+
async function listDocumentSignatureRequests(arbi, docId) {
|
|
6994
6870
|
return requireData(
|
|
6995
|
-
await arbi.fetch.GET("/v1/
|
|
6996
|
-
params: { path: {
|
|
6871
|
+
await arbi.fetch.GET("/v1/document/{document_ext_id}/signature-requests", {
|
|
6872
|
+
params: { path: { document_ext_id: docId } }
|
|
6997
6873
|
}),
|
|
6998
|
-
"
|
|
6874
|
+
"Failed to list the document\u2019s signature requests"
|
|
6999
6875
|
);
|
|
7000
6876
|
}
|
|
7001
|
-
async function
|
|
6877
|
+
async function getSignatureRequest(arbi, requestId) {
|
|
7002
6878
|
return requireData(
|
|
7003
|
-
await arbi.fetch.
|
|
7004
|
-
params: { path: {
|
|
6879
|
+
await arbi.fetch.GET("/v1/signature-requests/{request_ext_id}", {
|
|
6880
|
+
params: { path: { request_ext_id: requestId } }
|
|
7005
6881
|
}),
|
|
7006
|
-
"
|
|
6882
|
+
"Failed to fetch the signature request"
|
|
7007
6883
|
);
|
|
7008
6884
|
}
|
|
7009
|
-
async function
|
|
7010
|
-
|
|
7011
|
-
await arbi.fetch.
|
|
7012
|
-
params: { path: {
|
|
6885
|
+
async function suggestSignatureFields(arbi, docId, version) {
|
|
6886
|
+
const data = requireData(
|
|
6887
|
+
await arbi.fetch.GET("/v1/document/{document_ext_id}/signature-fields/suggest", {
|
|
6888
|
+
params: { path: { document_ext_id: docId }, ...version ? { query: { version } } : {} }
|
|
7013
6889
|
}),
|
|
7014
|
-
"
|
|
6890
|
+
"Failed to find signature blocks"
|
|
7015
6891
|
);
|
|
6892
|
+
return data.fields;
|
|
7016
6893
|
}
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
6894
|
+
function assignSuggestions(suggestions, signers) {
|
|
6895
|
+
const groups = [...new Set(suggestions.filter((s2) => !s2.signer_email).map((s2) => s2.group))];
|
|
6896
|
+
return suggestions.flatMap((s2, i2) => {
|
|
6897
|
+
const signer = s2.signer_email ?? signers[groups.indexOf(s2.group)];
|
|
6898
|
+
if (!signer) return [];
|
|
6899
|
+
const { type, page, x: x2, y: y2, width, height } = s2;
|
|
6900
|
+
return [
|
|
6901
|
+
{ id: `s${i2 + 1}`, type, page, x: x2, y: y2, width, height, signer, required: s2.required ?? true }
|
|
6902
|
+
];
|
|
6903
|
+
});
|
|
7024
6904
|
}
|
|
7025
|
-
async function
|
|
6905
|
+
async function createSignatureRequest(arbi, docId, { fields, version, message, send = true }) {
|
|
7026
6906
|
return requireData(
|
|
7027
|
-
await arbi.fetch.
|
|
7028
|
-
|
|
6907
|
+
await arbi.fetch.POST("/v1/document/{document_ext_id}/signature-requests", {
|
|
6908
|
+
params: { path: { document_ext_id: docId } },
|
|
6909
|
+
body: { fields, send, message: message ?? null, ...version ? { version } : {} }
|
|
6910
|
+
}),
|
|
6911
|
+
"Failed to create the signature request"
|
|
7029
6912
|
);
|
|
7030
6913
|
}
|
|
7031
|
-
async function
|
|
7032
|
-
return requireData(await arbi.fetch.GET("/v1/workspace/users"), "Failed to fetch workspace users");
|
|
7033
|
-
}
|
|
7034
|
-
var EXTERNAL_ACCESS_SECONDS = 86400;
|
|
7035
|
-
function addWorkspaceMembersBody(request) {
|
|
7036
|
-
return {
|
|
7037
|
-
...request,
|
|
7038
|
-
access_duration_seconds: request.access_duration_seconds ?? EXTERNAL_ACCESS_SECONDS
|
|
7039
|
-
};
|
|
7040
|
-
}
|
|
7041
|
-
async function addWorkspaceMembers(arbi, request) {
|
|
6914
|
+
async function sendSignatureRequest(arbi, requestId) {
|
|
7042
6915
|
return requireData(
|
|
7043
|
-
await arbi.fetch.POST("/v1/
|
|
7044
|
-
|
|
6916
|
+
await arbi.fetch.POST("/v1/signature-requests/{request_ext_id}/send", {
|
|
6917
|
+
params: { path: { request_ext_id: requestId } }
|
|
6918
|
+
}),
|
|
6919
|
+
"Failed to send the signature request"
|
|
7045
6920
|
);
|
|
7046
6921
|
}
|
|
7047
|
-
async function
|
|
7048
|
-
const invite = confirmInvite ? { confirm_invite: true } : {};
|
|
6922
|
+
async function voidSignatureRequest(arbi, requestId) {
|
|
7049
6923
|
return requireData(
|
|
7050
|
-
await arbi.fetch.POST("/v1/
|
|
7051
|
-
|
|
7052
|
-
target ? {
|
|
7053
|
-
emails,
|
|
7054
|
-
role,
|
|
7055
|
-
workspace_ext_id: target.workspaceExtId,
|
|
7056
|
-
workspace_key: target.workspaceKey,
|
|
7057
|
-
...invite
|
|
7058
|
-
} : { emails, role, ...invite }
|
|
7059
|
-
)
|
|
6924
|
+
await arbi.fetch.POST("/v1/signature-requests/{request_ext_id}/void", {
|
|
6925
|
+
params: { path: { request_ext_id: requestId } }
|
|
7060
6926
|
}),
|
|
7061
|
-
"Failed to
|
|
6927
|
+
"Failed to void the signature request"
|
|
7062
6928
|
);
|
|
7063
6929
|
}
|
|
7064
|
-
async function
|
|
6930
|
+
async function declineSignatureRequest(arbi, requestId, reason) {
|
|
7065
6931
|
return requireData(
|
|
7066
|
-
await arbi.fetch.POST("/v1/
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
role: params.role ?? "collaborator",
|
|
7070
|
-
workspace_ext_id: params.workspaceExtId,
|
|
7071
|
-
workspace_key: params.workspaceKey,
|
|
7072
|
-
session_pubkey_b64: params.sessionPubkeyB64
|
|
7073
|
-
})
|
|
6932
|
+
await arbi.fetch.POST("/v1/signature-requests/{request_ext_id}/decline", {
|
|
6933
|
+
params: { path: { request_ext_id: requestId } },
|
|
6934
|
+
body: { reason: reason ?? null }
|
|
7074
6935
|
}),
|
|
7075
|
-
"Failed to
|
|
6936
|
+
"Failed to decline the signature request"
|
|
7076
6937
|
);
|
|
7077
6938
|
}
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
)
|
|
6939
|
+
|
|
6940
|
+
// src/operations/house-template.ts
|
|
6941
|
+
var house_template_exports = {};
|
|
6942
|
+
__export(house_template_exports, {
|
|
6943
|
+
getDeploymentHouseTemplate: () => getDeploymentHouseTemplate,
|
|
6944
|
+
isDeploymentAdmin: () => isDeploymentAdmin,
|
|
6945
|
+
listHouseTemplateCandidates: () => listHouseTemplateCandidates,
|
|
6946
|
+
setDeploymentHouseTemplate: () => setDeploymentHouseTemplate,
|
|
6947
|
+
setWorkspaceHouseTemplate: () => setWorkspaceHouseTemplate,
|
|
6948
|
+
supportsHouseTemplates: () => supportsHouseTemplates,
|
|
6949
|
+
workspaceHouseTemplateId: () => workspaceHouseTemplateId
|
|
6950
|
+
});
|
|
6951
|
+
function supportsHouseTemplates(workspace) {
|
|
6952
|
+
return !!workspace && "house_template_ext_id" in workspace;
|
|
7088
6953
|
}
|
|
7089
|
-
|
|
7090
|
-
return
|
|
7091
|
-
await arbi.fetch.PATCH("/v1/workspace/users", {
|
|
7092
|
-
body: { user_ext_ids: userIds, role }
|
|
7093
|
-
}),
|
|
7094
|
-
"Failed to update roles"
|
|
7095
|
-
);
|
|
6954
|
+
function workspaceHouseTemplateId(workspace) {
|
|
6955
|
+
return workspace?.house_template_ext_id ?? null;
|
|
7096
6956
|
}
|
|
7097
|
-
|
|
7098
|
-
return
|
|
7099
|
-
await arbi.fetch.POST("/v1/workspace/copy", {
|
|
7100
|
-
body: {
|
|
7101
|
-
target_workspace_ext_id: targetWorkspaceId,
|
|
7102
|
-
target_workspace_key: targetWorkspaceKey,
|
|
7103
|
-
items: docIds
|
|
7104
|
-
}
|
|
7105
|
-
}),
|
|
7106
|
-
"Failed to copy documents"
|
|
7107
|
-
);
|
|
6957
|
+
function isDeploymentAdmin(user) {
|
|
6958
|
+
return user?.is_deployment_admin === true;
|
|
7108
6959
|
}
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
query: { cursor: options.cursor ?? void 0, limit: options.limit }
|
|
7115
|
-
}
|
|
7116
|
-
}),
|
|
7117
|
-
"Failed to fetch workspace activity"
|
|
7118
|
-
);
|
|
6960
|
+
function filenameOf(response) {
|
|
6961
|
+
const header = response.headers.get("Content-Disposition") ?? "";
|
|
6962
|
+
const star = /filename\*=UTF-8''([^;]+)/i.exec(header);
|
|
6963
|
+
if (star) return decodeURIComponent(star[1]);
|
|
6964
|
+
return /filename="?([^";]+)"?/i.exec(header)?.[1];
|
|
7119
6965
|
}
|
|
7120
|
-
async function
|
|
6966
|
+
async function getDeploymentHouseTemplate(arbi) {
|
|
6967
|
+
const { data, error, response } = await arbi.fetch.GET("/v1/deployment/house-template", {
|
|
6968
|
+
parseAs: "arrayBuffer"
|
|
6969
|
+
});
|
|
6970
|
+
const status = response.status;
|
|
6971
|
+
if (status === 204 || status === 404) return null;
|
|
6972
|
+
if (error || !data)
|
|
6973
|
+
throw new ArbiApiError("Could not read the deployment house template", error, status);
|
|
6974
|
+
return {
|
|
6975
|
+
bytes: new Uint8Array(data),
|
|
6976
|
+
name: filenameOf(response) ?? "House template.dotx"
|
|
6977
|
+
};
|
|
6978
|
+
}
|
|
6979
|
+
async function setDeploymentHouseTemplate(arbi, file) {
|
|
6980
|
+
if (!file) {
|
|
6981
|
+
requireOk(
|
|
6982
|
+
await arbi.fetch.DELETE("/v1/deployment/house-template"),
|
|
6983
|
+
"Could not clear the deployment house template"
|
|
6984
|
+
);
|
|
6985
|
+
return;
|
|
6986
|
+
}
|
|
6987
|
+
const form = new FormData();
|
|
6988
|
+
form.append("file", file);
|
|
7121
6989
|
requireOk(
|
|
7122
|
-
await arbi.fetch.
|
|
7123
|
-
|
|
7124
|
-
body:
|
|
6990
|
+
await arbi.fetch.PUT("/v1/deployment/house-template", {
|
|
6991
|
+
// The schema types the multipart file as a string; the FormData is sent as is.
|
|
6992
|
+
body: form,
|
|
6993
|
+
bodySerializer: () => form
|
|
7125
6994
|
}),
|
|
7126
|
-
"
|
|
6995
|
+
"Could not set the deployment house template"
|
|
7127
6996
|
);
|
|
7128
6997
|
}
|
|
7129
|
-
async function
|
|
7130
|
-
|
|
7131
|
-
await arbi.fetch.
|
|
7132
|
-
"
|
|
6998
|
+
async function setWorkspaceHouseTemplate(arbi, documentId) {
|
|
6999
|
+
requireData(
|
|
7000
|
+
await arbi.fetch.PATCH("/v1/workspace/", { body: { house_template_ext_id: documentId } }),
|
|
7001
|
+
"Could not set the house template"
|
|
7133
7002
|
);
|
|
7134
7003
|
}
|
|
7135
|
-
async function
|
|
7004
|
+
async function listHouseTemplateCandidates(arbi) {
|
|
7136
7005
|
return requireData(
|
|
7137
|
-
await arbi.fetch.
|
|
7138
|
-
|
|
7139
|
-
scope: params.scope,
|
|
7140
|
-
mode: params.mode,
|
|
7141
|
-
target_workspace_ext_id: params.targetWorkspaceId,
|
|
7142
|
-
target_workspace_key: params.targetWorkspaceKey,
|
|
7143
|
-
on_conflict: params.onConflict ?? "skip"
|
|
7144
|
-
}
|
|
7145
|
-
}),
|
|
7146
|
-
"Failed to start the transfer"
|
|
7006
|
+
await arbi.fetch.GET("/v1/workspace/house-template/candidates"),
|
|
7007
|
+
"Could not list the documents that can be the house template"
|
|
7147
7008
|
);
|
|
7148
7009
|
}
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
)
|
|
7010
|
+
|
|
7011
|
+
// src/operations/model-connections.ts
|
|
7012
|
+
var model_connections_exports = {};
|
|
7013
|
+
__export(model_connections_exports, {
|
|
7014
|
+
directUsage: () => directUsage,
|
|
7015
|
+
listConnections: () => listConnections,
|
|
7016
|
+
removeConnection: () => removeConnection,
|
|
7017
|
+
savePersonalConnection: () => savePersonalConnection,
|
|
7018
|
+
sealPersonalApiKey: () => sealPersonalApiKey,
|
|
7019
|
+
unlockModelConnections: () => unlockModelConnections
|
|
7020
|
+
});
|
|
7021
|
+
var FAILED = "Could not update model connections";
|
|
7022
|
+
async function listConnections(arbi) {
|
|
7023
|
+
return requireData(await arbi.fetch.GET("/v1/model-connections"), FAILED);
|
|
7157
7024
|
}
|
|
7158
|
-
async function
|
|
7025
|
+
async function directUsage(arbi) {
|
|
7159
7026
|
return requireData(
|
|
7160
|
-
await arbi.fetch.
|
|
7161
|
-
|
|
7162
|
-
}),
|
|
7163
|
-
"Failed to cancel the transfer"
|
|
7027
|
+
await arbi.fetch.GET("/v1/model-connections/usage"),
|
|
7028
|
+
FAILED
|
|
7164
7029
|
);
|
|
7165
7030
|
}
|
|
7166
|
-
async function
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7031
|
+
async function savePersonalConnection(arbi, body, id) {
|
|
7032
|
+
const result = id ? await arbi.fetch.PUT("/v1/model-connections/personal/{connection_id}", {
|
|
7033
|
+
params: { path: { connection_id: id } },
|
|
7034
|
+
body
|
|
7035
|
+
}) : await arbi.fetch.POST("/v1/model-connections/personal", { body });
|
|
7036
|
+
return requireData(result, FAILED);
|
|
7037
|
+
}
|
|
7038
|
+
async function removeConnection(arbi, id) {
|
|
7039
|
+
requireOk(
|
|
7040
|
+
await arbi.fetch.DELETE("/v1/model-connections/{connection_id}", {
|
|
7041
|
+
params: { path: { connection_id: id } }
|
|
7170
7042
|
}),
|
|
7171
|
-
|
|
7043
|
+
FAILED
|
|
7172
7044
|
);
|
|
7173
7045
|
}
|
|
7174
|
-
async function
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7046
|
+
async function sealPersonalApiKey(apiKey, signingPrivateKey) {
|
|
7047
|
+
await initSodium();
|
|
7048
|
+
const pair = encryptionKeypairFromSigningKey(signingPrivateKey);
|
|
7049
|
+
const bytes = new TextEncoder().encode(apiKey);
|
|
7050
|
+
try {
|
|
7051
|
+
return sealedBoxEncrypt(bytes, pair.publicKey);
|
|
7052
|
+
} finally {
|
|
7053
|
+
bytes.fill(0);
|
|
7054
|
+
pair.secretKey.fill(0);
|
|
7055
|
+
}
|
|
7179
7056
|
}
|
|
7180
|
-
async function
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7057
|
+
async function unlockModelConnections(arbi, keys, onlyId) {
|
|
7058
|
+
await initSodium();
|
|
7059
|
+
const pair = encryptionKeypairFromSigningKey(keys.signingPrivateKey);
|
|
7060
|
+
try {
|
|
7061
|
+
const rows = requireData(
|
|
7062
|
+
await arbi.fetch.GET("/v1/model-connections/sealed-keys"),
|
|
7063
|
+
FAILED
|
|
7064
|
+
);
|
|
7065
|
+
for (const row of rows) {
|
|
7066
|
+
if (onlyId && onlyId !== row.id || !row.sealed_api_key || !row.enabled) continue;
|
|
7067
|
+
const bytes = sealedBoxDecrypt(row.sealed_api_key, pair.secretKey);
|
|
7068
|
+
try {
|
|
7069
|
+
requireOk(
|
|
7070
|
+
await arbi.fetch.POST("/v1/model-connections/session-key", {
|
|
7071
|
+
body: {
|
|
7072
|
+
connection_id: row.id,
|
|
7073
|
+
sealed_api_key: sealedBoxEncrypt(bytes, keys.serverSessionKey)
|
|
7074
|
+
}
|
|
7075
|
+
}),
|
|
7076
|
+
FAILED
|
|
7077
|
+
);
|
|
7078
|
+
} finally {
|
|
7079
|
+
bytes.fill(0);
|
|
7080
|
+
}
|
|
7081
|
+
}
|
|
7082
|
+
} finally {
|
|
7083
|
+
pair.secretKey.fill(0);
|
|
7084
|
+
}
|
|
7185
7085
|
}
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7086
|
+
|
|
7087
|
+
// src/operations/secure-mail.ts
|
|
7088
|
+
var secure_mail_exports = {};
|
|
7089
|
+
__export(secure_mail_exports, {
|
|
7090
|
+
claimSecureMail: () => claimSecureMail,
|
|
7091
|
+
prepareSecureMail: () => prepareSecureMail,
|
|
7092
|
+
secureMime: () => secureMime
|
|
7093
|
+
});
|
|
7094
|
+
var MAX_MESSAGE_BYTES = 25 * 1024 * 1024;
|
|
7095
|
+
var utf8 = new TextEncoder();
|
|
7096
|
+
var encodedWord = (value) => `=?UTF-8?B?${bytesToBase64(utf8.encode(value))}?=`;
|
|
7097
|
+
var folded = (value) => value.match(/.{1,76}/g)?.join("\r\n") ?? "";
|
|
7098
|
+
var safeHeader = (value) => {
|
|
7099
|
+
if (/[\r\n\0]/.test(value)) throw new Error("Email headers cannot contain newlines");
|
|
7100
|
+
return value;
|
|
7101
|
+
};
|
|
7102
|
+
function secureMime(compose, sender) {
|
|
7103
|
+
const address = (r2) => `${r2.name ? encodedWord(safeHeader(r2.name)) + " " : ""}<${safeHeader(r2.email)}>`;
|
|
7104
|
+
const boundary = "arbi-" + crypto.randomUUID();
|
|
7105
|
+
const headers = [
|
|
7106
|
+
`From: ${address({ email: sender.email, name: sender.display_name })}`,
|
|
7107
|
+
...compose.to.length ? [`To: ${compose.to.map(address).join(", ")}`] : [],
|
|
7108
|
+
...compose.cc.length ? [`Cc: ${compose.cc.map(address).join(", ")}`] : [],
|
|
7109
|
+
`Subject: ${encodedWord(safeHeader(compose.subject))}`,
|
|
7110
|
+
`Date: ${(/* @__PURE__ */ new Date()).toUTCString()}`,
|
|
7111
|
+
`Message-ID: <${crypto.randomUUID()}@${sender.email.split("@")[1]}>`,
|
|
7112
|
+
...compose.in_reply_to ? [`In-Reply-To: ${safeHeader(compose.in_reply_to)}`] : [],
|
|
7113
|
+
...compose.references?.length ? [`References: ${compose.references.map(safeHeader).join(" ")}`] : [],
|
|
7114
|
+
"MIME-Version: 1.0",
|
|
7115
|
+
"X-ARBI-Secure-Delivery: 1",
|
|
7116
|
+
`Content-Type: multipart/mixed; boundary="${boundary}"`
|
|
7117
|
+
];
|
|
7118
|
+
const alternative = "alternative-" + crypto.randomUUID();
|
|
7119
|
+
const plainPart = `Content-Type: text/plain; charset="utf-8"\r
|
|
7120
|
+
Content-Transfer-Encoding: base64\r
|
|
7121
|
+
\r
|
|
7122
|
+
${folded(bytesToBase64(utf8.encode(compose.text)))}`;
|
|
7123
|
+
const bodyPart = compose.html ? `Content-Type: multipart/alternative; boundary="${alternative}"\r
|
|
7124
|
+
\r
|
|
7125
|
+
--${alternative}\r
|
|
7126
|
+
${plainPart}\r
|
|
7127
|
+
--${alternative}\r
|
|
7128
|
+
Content-Type: text/html; charset="utf-8"\r
|
|
7129
|
+
Content-Transfer-Encoding: base64\r
|
|
7130
|
+
\r
|
|
7131
|
+
${folded(bytesToBase64(utf8.encode(compose.html)))}\r
|
|
7132
|
+
--${alternative}--\r
|
|
7133
|
+
` : plainPart;
|
|
7134
|
+
const parts = [
|
|
7135
|
+
`--${boundary}\r
|
|
7136
|
+
${bodyPart}`,
|
|
7137
|
+
...compose.attachments.map((a2) => {
|
|
7138
|
+
if (!a2.content_base64) throw new Error("Attachment content is missing");
|
|
7139
|
+
const name = encodeURIComponent(safeHeader(a2.name)).replace(/'/g, "%27");
|
|
7140
|
+
return `--${boundary}\r
|
|
7141
|
+
Content-Type: ${safeHeader(a2.content_type || "application/octet-stream")}\r
|
|
7142
|
+
Content-Disposition: attachment; filename*=UTF-8''${name}\r
|
|
7143
|
+
Content-Transfer-Encoding: base64\r
|
|
7144
|
+
\r
|
|
7145
|
+
${folded(a2.content_base64)}`;
|
|
7190
7146
|
}),
|
|
7191
|
-
|
|
7192
|
-
|
|
7147
|
+
`--${boundary}--\r
|
|
7148
|
+
`
|
|
7149
|
+
];
|
|
7150
|
+
return utf8.encode(headers.join("\r\n") + "\r\n\r\n" + parts.join("\r\n"));
|
|
7151
|
+
}
|
|
7152
|
+
async function prepareSecureMail(compose, sender, { requestId, senderPublicKey, frontendOrigin }) {
|
|
7153
|
+
const raw = secureMime(compose, sender);
|
|
7154
|
+
try {
|
|
7155
|
+
if (raw.length > MAX_MESSAGE_BYTES) throw new Error("Email exceeds the message size limit");
|
|
7156
|
+
const metadata = {
|
|
7157
|
+
secure_delivery: true,
|
|
7158
|
+
id: "",
|
|
7159
|
+
subject: compose.subject,
|
|
7160
|
+
sender: [{ email: sender.email, name: sender.display_name }],
|
|
7161
|
+
to: compose.to,
|
|
7162
|
+
cc: compose.cc,
|
|
7163
|
+
bcc: [],
|
|
7164
|
+
received_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7165
|
+
preview: compose.text.slice(0, 220),
|
|
7166
|
+
unread: false,
|
|
7167
|
+
text: "",
|
|
7168
|
+
references: compose.references ?? [],
|
|
7169
|
+
attachments: compose.attachments.map((a2, i2) => ({
|
|
7170
|
+
...a2,
|
|
7171
|
+
id: String(i2),
|
|
7172
|
+
content_base64: null
|
|
7173
|
+
}))
|
|
7174
|
+
};
|
|
7175
|
+
const recipients = [
|
|
7176
|
+
...new Set([...compose.to, ...compose.cc, ...compose.bcc].map((r2) => r2.email.toLowerCase()))
|
|
7177
|
+
];
|
|
7178
|
+
const sealed = await sealSecureMail(raw, metadata, senderPublicKey);
|
|
7179
|
+
return {
|
|
7180
|
+
request_id: requestId,
|
|
7181
|
+
draft_id: compose.draft_id,
|
|
7182
|
+
recipients: recipients.map((email) => ({
|
|
7183
|
+
id: crypto.randomUUID(),
|
|
7184
|
+
email,
|
|
7185
|
+
fragment_key: sealed.fragment_key
|
|
7186
|
+
})),
|
|
7187
|
+
ciphertext: sealed.ciphertext,
|
|
7188
|
+
metadata_ciphertext: sealed.metadata_ciphertext,
|
|
7189
|
+
sender_wrapped_key: sealed.sender_wrapped_key,
|
|
7190
|
+
frontend_origin: frontendOrigin
|
|
7191
|
+
};
|
|
7192
|
+
} finally {
|
|
7193
|
+
raw.fill(0);
|
|
7194
|
+
}
|
|
7195
|
+
}
|
|
7196
|
+
async function claimSecureMail(mail, id, fragmentKey, recipientPublicKey) {
|
|
7197
|
+
const key = decodeSecureMailKey(fragmentKey);
|
|
7198
|
+
try {
|
|
7199
|
+
const path5 = `/secure/${encodeURIComponent(id)}`;
|
|
7200
|
+
const response = await mail(path5);
|
|
7201
|
+
const { raw } = await openSecureMail(await response.json(), key);
|
|
7202
|
+
raw.fill(0);
|
|
7203
|
+
const claim = await secureMailClaim(key, recipientPublicKey);
|
|
7204
|
+
const claimed = await mail(`${path5}/claim`, { method: "POST", body: JSON.stringify(claim) });
|
|
7205
|
+
return await claimed.json();
|
|
7206
|
+
} finally {
|
|
7207
|
+
key.fill(0);
|
|
7208
|
+
}
|
|
7193
7209
|
}
|
|
7194
7210
|
|
|
7195
7211
|
// src/operations/conversations.ts
|
|
@@ -10645,6 +10661,10 @@ __export(mail_exports, {
|
|
|
10645
10661
|
claimNativeAlias: () => claimNativeAlias,
|
|
10646
10662
|
createMailFetch: () => createMailFetch,
|
|
10647
10663
|
downloadAttachment: () => downloadAttachment,
|
|
10664
|
+
fileConversation: () => fileConversation,
|
|
10665
|
+
fileMessage: () => fileMessage,
|
|
10666
|
+
fileWaitingNativeMail: () => fileWaitingNativeMail,
|
|
10667
|
+
getFilingState: () => getFilingState,
|
|
10648
10668
|
getMailPolicy: () => getMailPolicy,
|
|
10649
10669
|
getMessage: () => getMessage2,
|
|
10650
10670
|
getNativeThreadSecret: () => getNativeThreadSecret,
|
|
@@ -10653,9 +10673,12 @@ __export(mail_exports, {
|
|
|
10653
10673
|
listFolders: () => listFolders,
|
|
10654
10674
|
listMailAccounts: () => listMailAccounts,
|
|
10655
10675
|
listMessages: () => listMessages,
|
|
10676
|
+
listNativeFiling: () => listNativeFiling,
|
|
10656
10677
|
openDraftEditor: () => openDraftEditor,
|
|
10657
10678
|
saveDraft: () => saveDraft,
|
|
10658
10679
|
sendMessage: () => sendMessage,
|
|
10680
|
+
setNativeFiling: () => setNativeFiling,
|
|
10681
|
+
stopFilingConversation: () => stopFilingConversation,
|
|
10659
10682
|
submitNativeThreadKeys: () => submitNativeThreadKeys,
|
|
10660
10683
|
unlockMailCredentials: () => unlockMailCredentials,
|
|
10661
10684
|
unlockNativeMail: () => unlockNativeMail,
|
|
@@ -10721,6 +10744,86 @@ async function submitNativeThreadKeys(mail, keys) {
|
|
|
10721
10744
|
);
|
|
10722
10745
|
return updated;
|
|
10723
10746
|
}
|
|
10747
|
+
function fileMessage(mail, messageId2, workspaceExtId, accountId = NATIVE_ACCOUNT) {
|
|
10748
|
+
return json(
|
|
10749
|
+
mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId2)}/file`, {
|
|
10750
|
+
method: "POST",
|
|
10751
|
+
body: JSON.stringify({ workspace_ext_id: workspaceExtId })
|
|
10752
|
+
})
|
|
10753
|
+
);
|
|
10754
|
+
}
|
|
10755
|
+
function fileConversation(mail, input) {
|
|
10756
|
+
return json(
|
|
10757
|
+
mail(`${accountPath(input.accountId ?? NATIVE_ACCOUNT)}/conversations/file`, {
|
|
10758
|
+
method: "POST",
|
|
10759
|
+
body: JSON.stringify({
|
|
10760
|
+
workspace_ext_id: input.workspaceExtId,
|
|
10761
|
+
thread_id: input.threadId,
|
|
10762
|
+
message_ids: input.messageIds
|
|
10763
|
+
})
|
|
10764
|
+
})
|
|
10765
|
+
);
|
|
10766
|
+
}
|
|
10767
|
+
async function stopFilingConversation(mail, ruleId, threadId) {
|
|
10768
|
+
const params = new URLSearchParams({ thread_id: threadId });
|
|
10769
|
+
await mail(`/filing/${encodeURIComponent(ruleId)}/threads?${params}`, { method: "DELETE" });
|
|
10770
|
+
}
|
|
10771
|
+
function listNativeFiling(mail) {
|
|
10772
|
+
return json(mail("/native/filing"));
|
|
10773
|
+
}
|
|
10774
|
+
function setNativeFiling(mail, input) {
|
|
10775
|
+
return json(
|
|
10776
|
+
mail("/native/filing", {
|
|
10777
|
+
method: "PUT",
|
|
10778
|
+
body: JSON.stringify({
|
|
10779
|
+
workspace_ext_id: input.workspaceExtId,
|
|
10780
|
+
folders: input.folders,
|
|
10781
|
+
backfill_window: input.backfillWindow ?? 90
|
|
10782
|
+
})
|
|
10783
|
+
})
|
|
10784
|
+
);
|
|
10785
|
+
}
|
|
10786
|
+
async function fileWaitingNativeMail(mail, keys, workspaceExtId) {
|
|
10787
|
+
const params = new URLSearchParams({ workspace_ext_id: workspaceExtId });
|
|
10788
|
+
const waiting = await json(mail(`/native/filing/waiting?${params}`));
|
|
10789
|
+
if (!Object.keys(waiting.keys).length) return { filed: 0, waiting: 0, failed: 0 };
|
|
10790
|
+
await bridgeItemKeys(mail, keys, waiting.keys);
|
|
10791
|
+
return json(
|
|
10792
|
+
mail("/native/filing/run", {
|
|
10793
|
+
method: "POST",
|
|
10794
|
+
body: JSON.stringify({ workspace_ext_id: workspaceExtId })
|
|
10795
|
+
})
|
|
10796
|
+
);
|
|
10797
|
+
}
|
|
10798
|
+
async function bridgeItemKeys(mail, keys, wrapped) {
|
|
10799
|
+
await initSodium();
|
|
10800
|
+
const secretKey = encryptionKeypairFromSigningKey(keys.signingPrivateKey).secretKey;
|
|
10801
|
+
try {
|
|
10802
|
+
const sealed = {};
|
|
10803
|
+
for (const [id, value] of Object.entries(wrapped)) {
|
|
10804
|
+
const key = sealedBoxDecrypt(value, secretKey);
|
|
10805
|
+
try {
|
|
10806
|
+
sealed[id] = await sealKeyForSession(key, keys.serverSessionKey);
|
|
10807
|
+
} finally {
|
|
10808
|
+
key.fill(0);
|
|
10809
|
+
}
|
|
10810
|
+
}
|
|
10811
|
+
await mail("/native/session-keys", { method: "POST", body: JSON.stringify({ keys: sealed }) });
|
|
10812
|
+
} finally {
|
|
10813
|
+
secretKey.fill(0);
|
|
10814
|
+
}
|
|
10815
|
+
}
|
|
10816
|
+
function getFilingState(mail, input) {
|
|
10817
|
+
return json(
|
|
10818
|
+
mail(`${accountPath(input.accountId ?? NATIVE_ACCOUNT)}/filing`, {
|
|
10819
|
+
method: "POST",
|
|
10820
|
+
body: JSON.stringify({
|
|
10821
|
+
message_ids: input.messageIds ?? [],
|
|
10822
|
+
thread_ids: input.threadIds ?? []
|
|
10823
|
+
})
|
|
10824
|
+
})
|
|
10825
|
+
);
|
|
10826
|
+
}
|
|
10724
10827
|
function getMessage2(mail, messageId2, accountId = NATIVE_ACCOUNT) {
|
|
10725
10828
|
return json(mail(`${accountPath(accountId)}/messages/${encodeURIComponent(messageId2)}`));
|
|
10726
10829
|
}
|
|
@@ -10746,33 +10849,13 @@ function sendMessage(mail, message, accountId = NATIVE_ACCOUNT) {
|
|
|
10746
10849
|
);
|
|
10747
10850
|
}
|
|
10748
10851
|
async function unlockNativeMail(mail, keys) {
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
);
|
|
10757
|
-
const sealed = {};
|
|
10758
|
-
for (const [id, wrapped] of Object.entries(page.keys)) {
|
|
10759
|
-
const key = sealedBoxDecrypt(wrapped, secretKey);
|
|
10760
|
-
try {
|
|
10761
|
-
sealed[id] = await sealKeyForSession(key, keys.serverSessionKey);
|
|
10762
|
-
} finally {
|
|
10763
|
-
key.fill(0);
|
|
10764
|
-
}
|
|
10765
|
-
}
|
|
10766
|
-
if (Object.keys(sealed).length) {
|
|
10767
|
-
await mail("/native/session-keys", {
|
|
10768
|
-
method: "POST",
|
|
10769
|
-
body: JSON.stringify({ keys: sealed })
|
|
10770
|
-
});
|
|
10771
|
-
}
|
|
10772
|
-
cursor = page.next_cursor;
|
|
10773
|
-
}
|
|
10774
|
-
} finally {
|
|
10775
|
-
secretKey.fill(0);
|
|
10852
|
+
let cursor = 0;
|
|
10853
|
+
while (cursor !== null) {
|
|
10854
|
+
const page = await json(
|
|
10855
|
+
mail(`/native/keys?cursor=${cursor}`)
|
|
10856
|
+
);
|
|
10857
|
+
if (Object.keys(page.keys).length) await bridgeItemKeys(mail, keys, page.keys);
|
|
10858
|
+
cursor = page.next_cursor;
|
|
10776
10859
|
}
|
|
10777
10860
|
}
|
|
10778
10861
|
async function unlockMailCredentials(mail, accountId, keys) {
|
|
@@ -11428,7 +11511,7 @@ var CODE_TEXT = {
|
|
|
11428
11511
|
host_only: "Only the host can do that.",
|
|
11429
11512
|
// transcription
|
|
11430
11513
|
transcription_off: "Transcription is off.",
|
|
11431
|
-
speaker_mismatch: "Only the speaker (or
|
|
11514
|
+
speaker_mismatch: "Only the speaker can store this line (or another member, when the speaker is read only).",
|
|
11432
11515
|
// recording
|
|
11433
11516
|
storage_quota_exceeded: "The storage quota is full: recording stopped.",
|
|
11434
11517
|
already_recording: "The call is already being recorded.",
|
|
@@ -12772,7 +12855,10 @@ var Arbi = class {
|
|
|
12772
12855
|
listUsers: () => listWorkspaceUsers(this.requireClient()),
|
|
12773
12856
|
/** One page of a workspace's activity feed, newest first (see `getWorkspaceActivity`). */
|
|
12774
12857
|
activity: (workspaceId, options) => getWorkspaceActivity(this.requireClient(), workspaceId, options),
|
|
12775
|
-
/**
|
|
12858
|
+
/**
|
|
12859
|
+
* Add users to the open workspace; `confirmInvite` also invites emails not on ARBI yet. `role`
|
|
12860
|
+
* defaults to `collaborator`; `guest` makes a read-only member (shown as "Read only").
|
|
12861
|
+
*/
|
|
12776
12862
|
addUsers: (emails, role, options) => addWorkspaceUsers(
|
|
12777
12863
|
this.requireClient(),
|
|
12778
12864
|
emails,
|
|
@@ -12815,6 +12901,7 @@ var Arbi = class {
|
|
|
12815
12901
|
userIds,
|
|
12816
12902
|
await this.targetWorkspace(options?.workspaceId)
|
|
12817
12903
|
),
|
|
12904
|
+
/** Change members' role; `guest` is read-only (shown as "Read only"). */
|
|
12818
12905
|
setUserRole: (userIds, role) => setUserRole(this.requireClient(), userIds, role),
|
|
12819
12906
|
/**
|
|
12820
12907
|
* Ask another user to grant you workspace access. Builds the E2E-encrypted
|
|
@@ -13140,6 +13227,19 @@ var Arbi = class {
|
|
|
13140
13227
|
}
|
|
13141
13228
|
await unlockMailCredentials(this.mail.fetch, account.id, await this.nativeMailKeys());
|
|
13142
13229
|
},
|
|
13230
|
+
/**
|
|
13231
|
+
* File the ARBI mail waiting for a workspace (it arrived while the user was away) with this
|
|
13232
|
+
* session: the waiting messages' keys are bridged, then the server files them with the
|
|
13233
|
+
* workspace's key, deposited first without switching to it (see `fileWaitingNativeMail`).
|
|
13234
|
+
*/
|
|
13235
|
+
fileWaiting: async (workspaceExtId) => {
|
|
13236
|
+
await this.workspaces.open(workspaceExtId);
|
|
13237
|
+
return fileWaitingNativeMail(
|
|
13238
|
+
this.mail.fetch,
|
|
13239
|
+
await this.nativeMailKeys(),
|
|
13240
|
+
workspaceExtId
|
|
13241
|
+
);
|
|
13242
|
+
},
|
|
13143
13243
|
/**
|
|
13144
13244
|
* Open a native draft's body in the Word editor, unlocking its room for this session with the
|
|
13145
13245
|
* user's key when the server asks (see `openDraftEditor`).
|