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