@arbidocs/sdk 0.5.60 → 0.5.62
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/README.md +158 -15
- package/dist/{browser-BuRU9RVU.d.cts → browser-DHvxPDoF.d.cts} +217 -4
- package/dist/{browser-GyBIGRNQ.d.ts → browser-DpDuiKeo.d.ts} +217 -4
- package/dist/browser.cjs +616 -127
- 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 +605 -129
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +601 -127
- 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 +592 -129
- package/dist/index.js.map +1 -1
- package/examples/background-response.mjs +18 -0
- package/examples/node-response.mjs +6 -36
- package/examples/response-handle.mjs +36 -0
- package/examples/responses-contract.json +97 -0
- package/examples/session.mjs +10 -0
- package/examples/stream-response.mjs +11 -0
- package/examples/structured-extraction.mjs +20 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs2, { readFileSync } from 'fs';
|
|
2
2
|
import path3, { dirname, resolve } from 'path';
|
|
3
3
|
import os2 from 'os';
|
|
4
|
-
import { createArbiClient, base64ToBytes, unwrapWorkspaceKey, sealKeyForSession, buildWebSocketUrl, createAuthMessage, parseServerMessage, isMessageType, createContentHash, encryptFile, initSodium, encryptionKeypairFromSigningKey, sealedBoxDecrypt, bytesToBase64, encryptWithChatKey, decryptWithChatKey, decryptFile, deriveDirectChatKey, openSealedChatKey, generateChatKey, sealChatKey, sealCallKey, encryptMessage, decodeSecureMailKey, openSecureMail, secureMailClaim, createSessionManager, authRequestError, changePassword, openCallKeyOf, decryptCallTitle, generateCallKey, encryptCallTitle, sealCallKeyForPeers, openSealedCallKey, readSessionClaims
|
|
4
|
+
import { createArbiClient, base64ToBytes, unwrapWorkspaceKey, sealKeyForSession, buildWebSocketUrl, createAuthMessage, parseServerMessage, isMessageType, createContentHash, encryptFile, initSodium, encryptionKeypairFromSigningKey, sealedBoxDecrypt, bytesToBase64, encryptWithChatKey, decryptWithChatKey, decryptFile, deriveDirectChatKey, openSealedChatKey, generateChatKey, sealChatKey, sealCallKey, encryptMessage, decodeSecureMailKey, openSecureMail, secureMailClaim, createSessionManager, authRequestError, isAbortError, changePassword, openCallKeyOf, decryptCallTitle, generateCallKey, encryptCallTitle, sealCallKeyForPeers, openSealedCallKey, readSessionClaims } from '@arbidocs/client';
|
|
5
5
|
import { execSync, spawn } from 'child_process';
|
|
6
6
|
import { createHash } from 'crypto';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
@@ -3517,6 +3517,22 @@ var ArbiWorkspaceChangedError = class extends ArbiError {
|
|
|
3517
3517
|
}
|
|
3518
3518
|
workspaceId;
|
|
3519
3519
|
};
|
|
3520
|
+
var ArbiWorkspaceUnavailableError = class extends ArbiError {
|
|
3521
|
+
constructor(workspaceId, cause, message = `Workspace ${workspaceId} can't be opened in this session, so nothing was sent`) {
|
|
3522
|
+
super(message, { code: "WORKSPACE_UNAVAILABLE", cause });
|
|
3523
|
+
this.workspaceId = workspaceId;
|
|
3524
|
+
this.name = "ArbiWorkspaceUnavailableError";
|
|
3525
|
+
}
|
|
3526
|
+
workspaceId;
|
|
3527
|
+
};
|
|
3528
|
+
function workspaceConflictOf(error) {
|
|
3529
|
+
const body = error instanceof ArbiApiError ? error.apiError : error instanceof Error ? void 0 : error;
|
|
3530
|
+
const detail = errorRecord(errorRecord(body)?.detail);
|
|
3531
|
+
const code = detail?.code;
|
|
3532
|
+
const workspaceId = detail?.workspace_ext_id;
|
|
3533
|
+
if (code !== "workspace_key_required" && code !== "workspace_mismatch") return null;
|
|
3534
|
+
return typeof workspaceId === "string" && workspaceId ? { code, workspaceId } : null;
|
|
3535
|
+
}
|
|
3520
3536
|
function detailText(detail) {
|
|
3521
3537
|
if (typeof detail === "string") return detail || void 0;
|
|
3522
3538
|
if (Array.isArray(detail)) {
|
|
@@ -5156,6 +5172,228 @@ function buildChunkLookup(tools) {
|
|
|
5156
5172
|
return lookup;
|
|
5157
5173
|
}
|
|
5158
5174
|
|
|
5175
|
+
// src/operations/responses.ts
|
|
5176
|
+
var responses_exports = {};
|
|
5177
|
+
__export(responses_exports, {
|
|
5178
|
+
extractResponseText: () => extractResponseText,
|
|
5179
|
+
getResponse: () => getResponse,
|
|
5180
|
+
submitBackgroundQuery: () => submitBackgroundQuery
|
|
5181
|
+
});
|
|
5182
|
+
async function submitBackgroundQuery(options) {
|
|
5183
|
+
const {
|
|
5184
|
+
workspaceId,
|
|
5185
|
+
question,
|
|
5186
|
+
docIds,
|
|
5187
|
+
previousResponseId,
|
|
5188
|
+
model,
|
|
5189
|
+
text: text2,
|
|
5190
|
+
task,
|
|
5191
|
+
conversationId,
|
|
5192
|
+
mentions,
|
|
5193
|
+
activeArtifactExtId,
|
|
5194
|
+
fullContext = true,
|
|
5195
|
+
...auth
|
|
5196
|
+
} = options;
|
|
5197
|
+
const tools = {};
|
|
5198
|
+
if (docIds.length > 0) {
|
|
5199
|
+
tools.retrieval_chunk = {
|
|
5200
|
+
name: "retrieval_chunk",
|
|
5201
|
+
description: "retrieval chunk",
|
|
5202
|
+
tool_args: { doc_ext_ids: docIds },
|
|
5203
|
+
tool_responses: {}
|
|
5204
|
+
};
|
|
5205
|
+
if (fullContext)
|
|
5206
|
+
tools.retrieval_full_context = {
|
|
5207
|
+
name: "retrieval_full_context",
|
|
5208
|
+
description: "retrieval full context",
|
|
5209
|
+
tool_args: { doc_ext_ids: docIds },
|
|
5210
|
+
tool_responses: {}
|
|
5211
|
+
};
|
|
5212
|
+
}
|
|
5213
|
+
const body = {
|
|
5214
|
+
input: question,
|
|
5215
|
+
workspace_ext_id: workspaceId,
|
|
5216
|
+
stream: false,
|
|
5217
|
+
background: true,
|
|
5218
|
+
store: true,
|
|
5219
|
+
tools,
|
|
5220
|
+
...task !== void 0 ? { task } : {},
|
|
5221
|
+
...conversationId ? { conversation_ext_id: conversationId } : {},
|
|
5222
|
+
...mentions !== void 0 ? { mentions } : {},
|
|
5223
|
+
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
5224
|
+
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
5225
|
+
...model ? { model } : {},
|
|
5226
|
+
...text2 ? { text: text2 } : {}
|
|
5227
|
+
};
|
|
5228
|
+
const res = await authenticatedFetch({
|
|
5229
|
+
...auth,
|
|
5230
|
+
path: "/v1/responses",
|
|
5231
|
+
method: "POST",
|
|
5232
|
+
body: JSON.stringify(body),
|
|
5233
|
+
headers: { "Content-Type": "application/json" }
|
|
5234
|
+
});
|
|
5235
|
+
return await res.json();
|
|
5236
|
+
}
|
|
5237
|
+
async function getResponse(auth, responseId) {
|
|
5238
|
+
const res = await authenticatedFetch({
|
|
5239
|
+
...auth,
|
|
5240
|
+
path: `/v1/responses/${responseId}`,
|
|
5241
|
+
method: "GET"
|
|
5242
|
+
});
|
|
5243
|
+
return await res.json();
|
|
5244
|
+
}
|
|
5245
|
+
function extractResponseText(response) {
|
|
5246
|
+
const parts = [];
|
|
5247
|
+
for (const msg of Array.isArray(response.output) ? response.output : []) {
|
|
5248
|
+
if (msg.type !== "message" || !Array.isArray(msg.content)) continue;
|
|
5249
|
+
for (const item of msg.content) {
|
|
5250
|
+
if (item?.type === "output_text" && typeof item.text === "string") parts.push(item.text);
|
|
5251
|
+
}
|
|
5252
|
+
}
|
|
5253
|
+
return parts.join("");
|
|
5254
|
+
}
|
|
5255
|
+
|
|
5256
|
+
// src/responses-resource.ts
|
|
5257
|
+
function withOutputText(response, requestId) {
|
|
5258
|
+
return {
|
|
5259
|
+
...response,
|
|
5260
|
+
output_text: extractResponseText(response),
|
|
5261
|
+
...requestId ? { _request_id: requestId } : {}
|
|
5262
|
+
};
|
|
5263
|
+
}
|
|
5264
|
+
var ResponseStream = class {
|
|
5265
|
+
constructor(handle) {
|
|
5266
|
+
this.handle = handle;
|
|
5267
|
+
}
|
|
5268
|
+
handle;
|
|
5269
|
+
async *[Symbol.asyncIterator]() {
|
|
5270
|
+
try {
|
|
5271
|
+
for await (const frame of this.handle.events()) {
|
|
5272
|
+
const data = frame.data && typeof frame.data === "object" && !Array.isArray(frame.data) ? frame.data : { data: frame.data };
|
|
5273
|
+
yield {
|
|
5274
|
+
...data,
|
|
5275
|
+
type: typeof data.type === "string" ? data.type : frame.event
|
|
5276
|
+
};
|
|
5277
|
+
}
|
|
5278
|
+
const outcome = await this.handle.outcome;
|
|
5279
|
+
if (outcome.status === "disconnected")
|
|
5280
|
+
throw outcome.error ?? new ArbiTransportError(new Error("The response stream disconnected."), this.handle.id);
|
|
5281
|
+
} finally {
|
|
5282
|
+
this.handle.detach();
|
|
5283
|
+
}
|
|
5284
|
+
}
|
|
5285
|
+
};
|
|
5286
|
+
|
|
5287
|
+
// src/structured-output.ts
|
|
5288
|
+
var ArbiStructuredOutputError = class extends ArbiError {
|
|
5289
|
+
constructor(message, response, options) {
|
|
5290
|
+
const id = response && typeof response === "object" && "id" in response && typeof response.id === "string" ? response.id : void 0;
|
|
5291
|
+
super(message, { responseId: id, ...options });
|
|
5292
|
+
this.response = response;
|
|
5293
|
+
this.name = "ArbiStructuredOutputError";
|
|
5294
|
+
}
|
|
5295
|
+
response;
|
|
5296
|
+
};
|
|
5297
|
+
function localReferences(value) {
|
|
5298
|
+
if (Array.isArray(value)) {
|
|
5299
|
+
value.forEach(localReferences);
|
|
5300
|
+
return;
|
|
5301
|
+
}
|
|
5302
|
+
if (!value || typeof value !== "object") return;
|
|
5303
|
+
for (const [key, child] of Object.entries(value)) {
|
|
5304
|
+
if ((key === "$ref" || key === "$dynamicRef") && (typeof child !== "string" || !child.startsWith("#")))
|
|
5305
|
+
throw new Error("Only local schema references are supported.");
|
|
5306
|
+
if (!["enum", "const", "default", "examples"].includes(key)) localReferences(child);
|
|
5307
|
+
}
|
|
5308
|
+
}
|
|
5309
|
+
async function createStructuredParser(format) {
|
|
5310
|
+
let validate;
|
|
5311
|
+
let Constructor;
|
|
5312
|
+
try {
|
|
5313
|
+
Constructor = (await import('ajv/dist/2020.js')).default;
|
|
5314
|
+
} catch (cause) {
|
|
5315
|
+
throw new ArbiStructuredOutputError(
|
|
5316
|
+
"The JSON Schema validator could not be loaded.",
|
|
5317
|
+
void 0,
|
|
5318
|
+
{ code: "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE", cause }
|
|
5319
|
+
);
|
|
5320
|
+
}
|
|
5321
|
+
try {
|
|
5322
|
+
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))
|
|
5323
|
+
throw new Error("Invalid structured output format.");
|
|
5324
|
+
if (format.schema.$schema !== void 0 && format.schema.$schema !== "https://json-schema.org/draft/2020-12/schema")
|
|
5325
|
+
throw new Error("Expected JSON Schema draft 2020-12.");
|
|
5326
|
+
localReferences(format.schema);
|
|
5327
|
+
validate = new Constructor({
|
|
5328
|
+
strict: false,
|
|
5329
|
+
logger: false,
|
|
5330
|
+
validateFormats: false,
|
|
5331
|
+
strictNumbers: true,
|
|
5332
|
+
addUsedSchema: false
|
|
5333
|
+
}).compile(format.schema);
|
|
5334
|
+
} catch (cause) {
|
|
5335
|
+
const unavailable = cause instanceof EvalError;
|
|
5336
|
+
throw new ArbiStructuredOutputError(
|
|
5337
|
+
unavailable ? "This runtime cannot compile JSON Schema validators." : "Invalid or unsupported output schema.",
|
|
5338
|
+
void 0,
|
|
5339
|
+
{
|
|
5340
|
+
code: unavailable ? "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE" : "STRUCTURED_OUTPUT_SCHEMA_INVALID",
|
|
5341
|
+
cause
|
|
5342
|
+
}
|
|
5343
|
+
);
|
|
5344
|
+
}
|
|
5345
|
+
return (response, options = {}) => {
|
|
5346
|
+
const fail = (code, message, cause) => {
|
|
5347
|
+
throw new ArbiStructuredOutputError(message, response, { ...options, code, cause });
|
|
5348
|
+
};
|
|
5349
|
+
if (!response || typeof response !== "object")
|
|
5350
|
+
fail("RESPONSE_INVALID_ENVELOPE", "Expected a Responses JSON object.");
|
|
5351
|
+
if (response.status === "incomplete")
|
|
5352
|
+
fail("RESPONSE_INCOMPLETE", "The response is incomplete; no validated data is available.");
|
|
5353
|
+
if (response.status === "cancelled")
|
|
5354
|
+
fail("RESPONSE_CANCELLED", "The response was cancelled; no validated data is available.");
|
|
5355
|
+
if (response.status === "failed")
|
|
5356
|
+
fail(
|
|
5357
|
+
typeof response.error?.code === "string" ? response.error.code : "RESPONSE_FAILED",
|
|
5358
|
+
typeof response.error?.message === "string" ? response.error.message : "The response failed."
|
|
5359
|
+
);
|
|
5360
|
+
if (response.status !== "completed")
|
|
5361
|
+
fail(
|
|
5362
|
+
"RESPONSE_NOT_COMPLETED",
|
|
5363
|
+
"Wait for a completed response before parsing structured output."
|
|
5364
|
+
);
|
|
5365
|
+
const messages = Array.isArray(response.output) ? response.output.filter(
|
|
5366
|
+
(item) => item && typeof item === "object" && item.type === "message" && item.role === "assistant"
|
|
5367
|
+
) : [];
|
|
5368
|
+
if (messages.some(
|
|
5369
|
+
(message) => !Array.isArray(message.content) || message.content.some((part) => !part || typeof part !== "object")
|
|
5370
|
+
))
|
|
5371
|
+
fail("RESPONSE_INVALID_ENVELOPE", "Invalid assistant output content.");
|
|
5372
|
+
if (messages.some((message) => message.content.some((part) => part.type === "refusal")))
|
|
5373
|
+
fail("RESPONSE_REFUSED", "The model refused this response.");
|
|
5374
|
+
const answers = messages.map(
|
|
5375
|
+
(message) => message.content.filter((part) => part.type === "output_text" && typeof part.text === "string").map((part) => part.text).join("")
|
|
5376
|
+
).filter((answer) => answer.length > 0);
|
|
5377
|
+
if (answers.length !== 1)
|
|
5378
|
+
fail(
|
|
5379
|
+
"STRUCTURED_OUTPUT_AMBIGUOUS",
|
|
5380
|
+
"Expected one final assistant output message; narrative and answer text are not joined."
|
|
5381
|
+
);
|
|
5382
|
+
let data;
|
|
5383
|
+
try {
|
|
5384
|
+
data = JSON.parse(answers[0]);
|
|
5385
|
+
} catch (cause) {
|
|
5386
|
+
fail("STRUCTURED_OUTPUT_INVALID_JSON", "The response is not valid JSON.", cause);
|
|
5387
|
+
}
|
|
5388
|
+
if (!validate(data))
|
|
5389
|
+
fail("STRUCTURED_OUTPUT_INVALID", "The response did not match the requested JSON schema.");
|
|
5390
|
+
return { data, response };
|
|
5391
|
+
};
|
|
5392
|
+
}
|
|
5393
|
+
async function parseStructuredResponse(response, format) {
|
|
5394
|
+
return (await createStructuredParser(format))(response);
|
|
5395
|
+
}
|
|
5396
|
+
|
|
5159
5397
|
// src/response-handle.ts
|
|
5160
5398
|
var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
5161
5399
|
var text = (value) => typeof value === "string" ? value : void 0;
|
|
@@ -5252,12 +5490,17 @@ function consumeResponse(response, controller, cancel, options = {}) {
|
|
|
5252
5490
|
let acknowledgement;
|
|
5253
5491
|
const listeners = /* @__PURE__ */ new Set();
|
|
5254
5492
|
const queue = [];
|
|
5493
|
+
let capacityAvailable;
|
|
5494
|
+
const releaseCapacity = () => {
|
|
5495
|
+
capacityAvailable?.();
|
|
5496
|
+
capacityAvailable = void 0;
|
|
5497
|
+
};
|
|
5255
5498
|
let claimed = false;
|
|
5256
5499
|
let iteratorClosed = false;
|
|
5257
5500
|
let iteratorError;
|
|
5258
5501
|
let pending;
|
|
5259
5502
|
const emit = (event) => {
|
|
5260
|
-
if (!claimed || iteratorClosed) return;
|
|
5503
|
+
if (!claimed && !options.bufferEvents || iteratorClosed) return;
|
|
5261
5504
|
if (pending) {
|
|
5262
5505
|
pending.resolve({ value: immutable(event), done: false });
|
|
5263
5506
|
pending = void 0;
|
|
@@ -5286,6 +5529,7 @@ function consumeResponse(response, controller, cancel, options = {}) {
|
|
|
5286
5529
|
const finish = (value, detached = false) => {
|
|
5287
5530
|
if (finished) return;
|
|
5288
5531
|
finished = true;
|
|
5532
|
+
releaseCapacity();
|
|
5289
5533
|
controller.signal.removeEventListener("abort", abort);
|
|
5290
5534
|
options.cleanup?.();
|
|
5291
5535
|
update({ connection: detached ? "detached" : "closed", outcome: immutable(value) });
|
|
@@ -5333,6 +5577,7 @@ function consumeResponse(response, controller, cancel, options = {}) {
|
|
|
5333
5577
|
const close = () => {
|
|
5334
5578
|
iteratorClosed = true;
|
|
5335
5579
|
queue.length = 0;
|
|
5580
|
+
releaseCapacity();
|
|
5336
5581
|
if (pending) {
|
|
5337
5582
|
pending.resolve({ value: void 0, done: true });
|
|
5338
5583
|
pending = void 0;
|
|
@@ -5344,7 +5589,11 @@ function consumeResponse(response, controller, cancel, options = {}) {
|
|
|
5344
5589
|
},
|
|
5345
5590
|
next() {
|
|
5346
5591
|
if (iteratorError) return Promise.reject(iteratorError);
|
|
5347
|
-
if (queue.length)
|
|
5592
|
+
if (queue.length) {
|
|
5593
|
+
const value = queue.shift();
|
|
5594
|
+
releaseCapacity();
|
|
5595
|
+
return Promise.resolve({ value, done: false });
|
|
5596
|
+
}
|
|
5348
5597
|
if (finished || iteratorClosed)
|
|
5349
5598
|
return Promise.resolve({ value: void 0, done: true });
|
|
5350
5599
|
if (pending)
|
|
@@ -5505,8 +5754,13 @@ function consumeResponse(response, controller, cancel, options = {}) {
|
|
|
5505
5754
|
try {
|
|
5506
5755
|
while (!finished) {
|
|
5507
5756
|
const { value, done } = await reader.read();
|
|
5508
|
-
for (const frame of frames.push(decoder.decode(value, { stream: !done }), done))
|
|
5757
|
+
for (const frame of frames.push(decoder.decode(value, { stream: !done }), done)) {
|
|
5509
5758
|
process2(frame);
|
|
5759
|
+
if (options.bufferEvents && bound && !finished && !iteratorClosed && queue.length >= 256)
|
|
5760
|
+
await new Promise((resolve2) => {
|
|
5761
|
+
capacityAvailable = resolve2;
|
|
5762
|
+
});
|
|
5763
|
+
}
|
|
5510
5764
|
if (done) break;
|
|
5511
5765
|
}
|
|
5512
5766
|
if (!finished) {
|
|
@@ -5970,9 +6224,12 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
|
|
|
5970
6224
|
folder: options?.folder ? sanitizeFolderPath(options.folder) : null,
|
|
5971
6225
|
presign_expires_in: options?.presignExpiresIn ?? 3600
|
|
5972
6226
|
};
|
|
5973
|
-
const
|
|
5974
|
-
|
|
5975
|
-
|
|
6227
|
+
const guarded = options?.inWorkspace ?? ((send) => send());
|
|
6228
|
+
const initResult = await guarded(
|
|
6229
|
+
async () => requireData(
|
|
6230
|
+
await arbi.fetch.POST("/v1/document/upload-init", { body: initBody }),
|
|
6231
|
+
"Failed to initialize direct upload"
|
|
6232
|
+
)
|
|
5976
6233
|
);
|
|
5977
6234
|
const items = initResult.items ?? [];
|
|
5978
6235
|
const bytesByName = /* @__PURE__ */ new Map();
|
|
@@ -6029,14 +6286,16 @@ async function uploadDocumentsDirect(arbi, workspaceKey, files, options) {
|
|
|
6029
6286
|
if (toCommit.length === 0) {
|
|
6030
6287
|
return { doc_ext_ids: [], skipped };
|
|
6031
6288
|
}
|
|
6032
|
-
const commitResult =
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6289
|
+
const commitResult = await guarded(
|
|
6290
|
+
async () => requireData(
|
|
6291
|
+
await arbi.fetch.POST("/v1/document/upload-commit", {
|
|
6292
|
+
body: {
|
|
6293
|
+
doc_ext_ids: toCommit,
|
|
6294
|
+
tag_ext_id: options?.tagExtId ?? null
|
|
6295
|
+
}
|
|
6296
|
+
}),
|
|
6297
|
+
"Failed to commit direct upload"
|
|
6298
|
+
)
|
|
6040
6299
|
);
|
|
6041
6300
|
return {
|
|
6042
6301
|
doc_ext_ids: commitResult.doc_ext_ids ?? [],
|
|
@@ -6554,6 +6813,7 @@ __export(assistant_exports, {
|
|
|
6554
6813
|
AssistantTurnRefused: () => AssistantTurnRefused,
|
|
6555
6814
|
MAX_RETRIEVE_DOC_IDS: () => MAX_RETRIEVE_DOC_IDS,
|
|
6556
6815
|
SESSION_EXPIRED_MESSAGE: () => SESSION_EXPIRED_MESSAGE,
|
|
6816
|
+
WORKSPACE_CONFLICT_MESSAGES: () => WORKSPACE_CONFLICT_MESSAGES,
|
|
6557
6817
|
cancelRun: () => cancelRun,
|
|
6558
6818
|
filterSkills: () => filterSkills,
|
|
6559
6819
|
interject: () => interject,
|
|
@@ -6656,6 +6916,7 @@ function buildTurnRequest(request) {
|
|
|
6656
6916
|
...request.previousResponseId ? { previous_response_id: request.previousResponseId } : {},
|
|
6657
6917
|
...request.conversationId ? { conversation_ext_id: request.conversationId } : {},
|
|
6658
6918
|
...request.model && !pa2 ? { model: request.model } : {},
|
|
6919
|
+
...request.text ? { text: request.text } : {},
|
|
6659
6920
|
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
6660
6921
|
...request.bindDocumentId && !request.previousResponseId && !pa2 ? { bound_document_ext_id: request.bindDocumentId } : {},
|
|
6661
6922
|
...request.mentions && request.mentions.length > 0 ? { mentions: request.mentions } : {},
|
|
@@ -6786,11 +7047,29 @@ function quotaFromStreamError(error) {
|
|
|
6786
7047
|
if (!Number.isFinite(spend) || !Number.isFinite(budget)) return null;
|
|
6787
7048
|
return { spend, budget, projectExtId: match.groups.project ?? null };
|
|
6788
7049
|
}
|
|
7050
|
+
var WORKSPACE_CONFLICT_MESSAGES = {
|
|
7051
|
+
workspace_mismatch: "This conversation belongs to another workspace, so the reply was not sent. Open that workspace to continue it.",
|
|
7052
|
+
workspace_key_required: "This chat's workspace isn't open in this session, so the message was not sent. Open the workspace and try again."
|
|
7053
|
+
};
|
|
6789
7054
|
async function refusal(response) {
|
|
6790
7055
|
const { status } = response;
|
|
6791
7056
|
const parsed = await apiErrorFromResponse(response, `HTTP error! status: ${status}`);
|
|
6792
7057
|
const detail = parsed.apiError?.detail;
|
|
6793
7058
|
const quota = status === 402 ? quotaExceededFrom(detail) : null;
|
|
7059
|
+
const conflict = status === 409 ? workspaceConflictOf(parsed.apiError) : null;
|
|
7060
|
+
if (conflict) {
|
|
7061
|
+
return new AssistantTurnRefused(
|
|
7062
|
+
WORKSPACE_CONFLICT_MESSAGES[conflict.code],
|
|
7063
|
+
status,
|
|
7064
|
+
null,
|
|
7065
|
+
parsed.apiError,
|
|
7066
|
+
{
|
|
7067
|
+
code: conflict.code,
|
|
7068
|
+
requestId: parsed.requestId,
|
|
7069
|
+
responseId: parsed.responseId
|
|
7070
|
+
}
|
|
7071
|
+
);
|
|
7072
|
+
}
|
|
6794
7073
|
const fallback = status === 409 ? "This message has failed. Please retry from the previous message." : status === 503 ? "The selected LLM is not responding. Please retry again in a minute or select another model." : status === 402 ? "This project's AI usage for this month is used up." : parsed.message;
|
|
6795
7074
|
return new AssistantTurnRefused(
|
|
6796
7075
|
quota?.message || parsed.detail || fallback,
|
|
@@ -6929,86 +7208,6 @@ async function cancelRun(auth, responseId) {
|
|
|
6929
7208
|
});
|
|
6930
7209
|
}
|
|
6931
7210
|
|
|
6932
|
-
// src/operations/responses.ts
|
|
6933
|
-
var responses_exports = {};
|
|
6934
|
-
__export(responses_exports, {
|
|
6935
|
-
extractResponseText: () => extractResponseText,
|
|
6936
|
-
getResponse: () => getResponse,
|
|
6937
|
-
submitBackgroundQuery: () => submitBackgroundQuery
|
|
6938
|
-
});
|
|
6939
|
-
async function submitBackgroundQuery(options) {
|
|
6940
|
-
const {
|
|
6941
|
-
workspaceId,
|
|
6942
|
-
question,
|
|
6943
|
-
docIds,
|
|
6944
|
-
previousResponseId,
|
|
6945
|
-
model,
|
|
6946
|
-
task,
|
|
6947
|
-
conversationId,
|
|
6948
|
-
mentions,
|
|
6949
|
-
activeArtifactExtId,
|
|
6950
|
-
fullContext = true,
|
|
6951
|
-
...auth
|
|
6952
|
-
} = options;
|
|
6953
|
-
const tools = {};
|
|
6954
|
-
if (docIds.length > 0) {
|
|
6955
|
-
tools.retrieval_chunk = {
|
|
6956
|
-
name: "retrieval_chunk",
|
|
6957
|
-
description: "retrieval chunk",
|
|
6958
|
-
tool_args: { doc_ext_ids: docIds },
|
|
6959
|
-
tool_responses: {}
|
|
6960
|
-
};
|
|
6961
|
-
if (fullContext)
|
|
6962
|
-
tools.retrieval_full_context = {
|
|
6963
|
-
name: "retrieval_full_context",
|
|
6964
|
-
description: "retrieval full context",
|
|
6965
|
-
tool_args: { doc_ext_ids: docIds },
|
|
6966
|
-
tool_responses: {}
|
|
6967
|
-
};
|
|
6968
|
-
}
|
|
6969
|
-
const body = {
|
|
6970
|
-
input: question,
|
|
6971
|
-
workspace_ext_id: workspaceId,
|
|
6972
|
-
stream: false,
|
|
6973
|
-
background: true,
|
|
6974
|
-
store: true,
|
|
6975
|
-
tools,
|
|
6976
|
-
...task !== void 0 ? { task } : {},
|
|
6977
|
-
...conversationId ? { conversation_ext_id: conversationId } : {},
|
|
6978
|
-
...mentions !== void 0 ? { mentions } : {},
|
|
6979
|
-
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
6980
|
-
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
6981
|
-
...model ? { model } : {}
|
|
6982
|
-
};
|
|
6983
|
-
const res = await authenticatedFetch({
|
|
6984
|
-
...auth,
|
|
6985
|
-
path: "/v1/responses",
|
|
6986
|
-
method: "POST",
|
|
6987
|
-
body: JSON.stringify(body),
|
|
6988
|
-
headers: { "Content-Type": "application/json" }
|
|
6989
|
-
});
|
|
6990
|
-
return await res.json();
|
|
6991
|
-
}
|
|
6992
|
-
async function getResponse(auth, responseId) {
|
|
6993
|
-
const res = await authenticatedFetch({
|
|
6994
|
-
...auth,
|
|
6995
|
-
path: `/v1/responses/${responseId}`,
|
|
6996
|
-
method: "GET"
|
|
6997
|
-
});
|
|
6998
|
-
return await res.json();
|
|
6999
|
-
}
|
|
7000
|
-
function extractResponseText(response) {
|
|
7001
|
-
const parts = [];
|
|
7002
|
-
for (const msg of response.output) {
|
|
7003
|
-
for (const item of msg.content) {
|
|
7004
|
-
if ("type" in item && item.type === "output_text" && "text" in item) {
|
|
7005
|
-
parts.push(item.text);
|
|
7006
|
-
}
|
|
7007
|
-
}
|
|
7008
|
-
}
|
|
7009
|
-
return parts.join("");
|
|
7010
|
-
}
|
|
7011
|
-
|
|
7012
7211
|
// src/operations/tags.ts
|
|
7013
7212
|
var tags_exports = {};
|
|
7014
7213
|
__export(tags_exports, {
|
|
@@ -11445,11 +11644,57 @@ var Arbi = class {
|
|
|
11445
11644
|
* Make a workspace usable for requests that name it, WITHOUT changing the current workspace (on
|
|
11446
11645
|
* the server or here): its key, sealed to this server session, is deposited with `/prime-key`
|
|
11447
11646
|
* (the client's `workspaceKeys.prime`: once per server session). The current workspace is open.
|
|
11647
|
+
* A workspace the user holds no key for (a public one, or a temporary grant whose key the server
|
|
11648
|
+
* session already holds) has nothing to deposit: the server answers for it as it is.
|
|
11448
11649
|
*/
|
|
11449
|
-
openWorkspace(workspaceId) {
|
|
11450
|
-
if (workspaceId === this.currentWorkspaceId) return
|
|
11650
|
+
async openWorkspace(workspaceId) {
|
|
11651
|
+
if (workspaceId === this.currentWorkspaceId) return;
|
|
11451
11652
|
this.requireLogin();
|
|
11452
|
-
|
|
11653
|
+
const keys = this.requireClient().workspaceKeys;
|
|
11654
|
+
const { wrappedKey } = await keys.wrappedKey(workspaceId).catch(keyLookupFailed);
|
|
11655
|
+
if (!wrappedKey) return;
|
|
11656
|
+
return keys.prime(workspaceId);
|
|
11657
|
+
}
|
|
11658
|
+
/**
|
|
11659
|
+
* {@link openWorkspace} (or, with `force`, deposit the key again even for the current workspace:
|
|
11660
|
+
* the server said it lacks it), failing with {@link ArbiWorkspaceUnavailableError} when the key
|
|
11661
|
+
* cannot be deposited. Then nothing is sent, so nothing can land in another workspace.
|
|
11662
|
+
*/
|
|
11663
|
+
async primeOrFail(workspaceId, options = {}) {
|
|
11664
|
+
try {
|
|
11665
|
+
if (options.force) {
|
|
11666
|
+
this.requireLogin();
|
|
11667
|
+
await this.requireClient().workspaceKeys.prime(workspaceId, { force: true });
|
|
11668
|
+
} else await this.openWorkspace(workspaceId);
|
|
11669
|
+
} catch (error) {
|
|
11670
|
+
if (isAbortError(error) || error instanceof ArbiSessionExpiredError) throw error;
|
|
11671
|
+
throw new ArbiWorkspaceUnavailableError(workspaceId, error);
|
|
11672
|
+
}
|
|
11673
|
+
}
|
|
11674
|
+
/**
|
|
11675
|
+
* Open a chat turn's stream in `workspaceId` (captured by the caller when the turn started): the
|
|
11676
|
+
* workspace is opened for this session first if it is not the current one, and the body names
|
|
11677
|
+
* it, so a switch meanwhile cannot move the turn. A follow-up refused with 409
|
|
11678
|
+
* `workspace_mismatch` (its thread is in another workspace: nothing was written) is sent once
|
|
11679
|
+
* more in the thread's workspace, which is where the server stores a follow-up anyway.
|
|
11680
|
+
* `onWorkspace` hears the workspace the turn was accepted in.
|
|
11681
|
+
*/
|
|
11682
|
+
async openTurn(request, workspaceId, open, onWorkspace) {
|
|
11683
|
+
let target = workspaceId;
|
|
11684
|
+
for (let attempt = 0; ; attempt++) {
|
|
11685
|
+
await this.primeOrFail(target);
|
|
11686
|
+
const body = buildTurnRequest({ ...request, workspaceId: target });
|
|
11687
|
+
try {
|
|
11688
|
+
const response = await this.recovering(() => open(body));
|
|
11689
|
+
onWorkspace?.(target);
|
|
11690
|
+
return response;
|
|
11691
|
+
} catch (error) {
|
|
11692
|
+
const conflict = workspaceConflictOf(error);
|
|
11693
|
+
const retryInThread = attempt === 0 && !!request.previousResponseId && conflict?.code === "workspace_mismatch" && conflict.workspaceId !== target;
|
|
11694
|
+
if (!retryInThread) throw error;
|
|
11695
|
+
target = conflict.workspaceId;
|
|
11696
|
+
}
|
|
11697
|
+
}
|
|
11453
11698
|
}
|
|
11454
11699
|
/**
|
|
11455
11700
|
* Create a tag in `workspaceId`, named on the request: a switch while it is sent cannot move it to the workspace
|
|
@@ -11606,6 +11851,11 @@ var Arbi = class {
|
|
|
11606
11851
|
try {
|
|
11607
11852
|
return await run();
|
|
11608
11853
|
} catch (error) {
|
|
11854
|
+
const conflict = workspaceConflictOf(error);
|
|
11855
|
+
if (conflict?.code === "workspace_key_required") {
|
|
11856
|
+
await this.primeOrFail(conflict.workspaceId, { force: true });
|
|
11857
|
+
return run();
|
|
11858
|
+
}
|
|
11609
11859
|
const message = error instanceof Error ? error.message : "";
|
|
11610
11860
|
const noWorkspace = /no active workspace/i.test(message);
|
|
11611
11861
|
const unauthorised = /\b401\b|token has expired/i.test(message);
|
|
@@ -12113,6 +12363,23 @@ var Arbi = class {
|
|
|
12113
12363
|
});
|
|
12114
12364
|
});
|
|
12115
12365
|
},
|
|
12366
|
+
/**
|
|
12367
|
+
* Upload files straight to storage, encrypted here with `workspaceKey` (`uploadDocumentsDirect`),
|
|
12368
|
+
* into `workspaceId`, which must be the workspace open NOW. `upload-init` and `upload-commit`
|
|
12369
|
+
* name no workspace yet (they act on the session's open one), so each runs under
|
|
12370
|
+
* `readInWorkspace`: it is not sent, or its answer not kept, unless `workspaceId` is open when
|
|
12371
|
+
* it is sent and still when it returns. A switch refuses the upload
|
|
12372
|
+
* (`ArbiWorkspaceChangedError`) instead of storing files encrypted with one workspace's key in
|
|
12373
|
+
* another. For any other workspace use `upload` with `workspaceExtId`, which names it.
|
|
12374
|
+
*/
|
|
12375
|
+
uploadDirect: (workspaceId, workspaceKey, files, options) => {
|
|
12376
|
+
if (this.currentWorkspaceId !== workspaceId)
|
|
12377
|
+
return Promise.reject(new ArbiWorkspaceChangedError(workspaceId, "uploading to"));
|
|
12378
|
+
return uploadDocumentsDirect(this.requireClient(), workspaceKey, files, {
|
|
12379
|
+
...options,
|
|
12380
|
+
inWorkspace: (send) => this.readInWorkspace(workspaceId, send)
|
|
12381
|
+
});
|
|
12382
|
+
},
|
|
12116
12383
|
/** Download a document's original file — its current version, or `version`. */
|
|
12117
12384
|
download: (docId, version) => this.recovering(() => downloadDocument(this.getAuthHeaders(), docId, version)),
|
|
12118
12385
|
getParsedContent: (docId, stage, version) => this.recovering(
|
|
@@ -12168,8 +12435,13 @@ var Arbi = class {
|
|
|
12168
12435
|
const first = await runConversation(client, conversationId);
|
|
12169
12436
|
if (!first.pending_auth_request_id) return first;
|
|
12170
12437
|
const pending = await getPendingAuth(client, conversationId);
|
|
12438
|
+
if (!pending.workspace_ext_id)
|
|
12439
|
+
throw new ArbiError(
|
|
12440
|
+
"The run is waiting for access, but the server did not say to which workspace",
|
|
12441
|
+
{ code: "PENDING_AUTH_WITHOUT_WORKSPACE" }
|
|
12442
|
+
);
|
|
12171
12443
|
await this.workspaces.grantTemporaryAccess({
|
|
12172
|
-
workspaceId: pending.workspace_ext_id
|
|
12444
|
+
workspaceId: pending.workspace_ext_id,
|
|
12173
12445
|
emails: [pending.agent_email],
|
|
12174
12446
|
sessionPubkeyB64: pending.session_pubkey
|
|
12175
12447
|
});
|
|
@@ -12262,7 +12534,7 @@ var Arbi = class {
|
|
|
12262
12534
|
});
|
|
12263
12535
|
}
|
|
12264
12536
|
};
|
|
12265
|
-
async openResponseHandle(open, options, id) {
|
|
12537
|
+
async openResponseHandle(open, options, id, bufferEvents = false) {
|
|
12266
12538
|
const controller = new AbortController();
|
|
12267
12539
|
const abort = () => controller.abort();
|
|
12268
12540
|
options.signal?.addEventListener("abort", abort, { once: true });
|
|
@@ -12274,7 +12546,7 @@ var Arbi = class {
|
|
|
12274
12546
|
response,
|
|
12275
12547
|
controller,
|
|
12276
12548
|
(responseId) => this.assistant.cancel(responseId),
|
|
12277
|
-
{ id, cleanup }
|
|
12549
|
+
{ id, cleanup, bufferEvents }
|
|
12278
12550
|
);
|
|
12279
12551
|
} catch (error) {
|
|
12280
12552
|
cleanup();
|
|
@@ -12282,16 +12554,143 @@ var Arbi = class {
|
|
|
12282
12554
|
throw error;
|
|
12283
12555
|
}
|
|
12284
12556
|
}
|
|
12557
|
+
/** Canonical Responses-shaped requests; existing assistant convenience helpers remain supported. */
|
|
12558
|
+
responses = {
|
|
12559
|
+
create: async (request, options = {}) => {
|
|
12560
|
+
if (request.stream) {
|
|
12561
|
+
if (request.background)
|
|
12562
|
+
throw new ArbiError(
|
|
12563
|
+
"Streaming background creation is not supported yet. Create in background mode, then attach to the returned response.",
|
|
12564
|
+
{ code: "RESPONSES_UNSUPPORTED_OPTION" }
|
|
12565
|
+
);
|
|
12566
|
+
const body2 = {
|
|
12567
|
+
...request,
|
|
12568
|
+
workspace_ext_id: request.workspace_ext_id ?? this.requireWorkspace(),
|
|
12569
|
+
stream: true,
|
|
12570
|
+
background: false,
|
|
12571
|
+
store: request.store ?? true
|
|
12572
|
+
};
|
|
12573
|
+
const started = await this.openResponseHandle(
|
|
12574
|
+
(signal) => openTurnStream(this.getAuthHeaders(), body2, signal),
|
|
12575
|
+
options,
|
|
12576
|
+
void 0,
|
|
12577
|
+
true
|
|
12578
|
+
);
|
|
12579
|
+
if (started.kind !== "response")
|
|
12580
|
+
throw new ArbiError("The control command was acknowledged without creating a response.", {
|
|
12581
|
+
code: "RESPONSE_CONTROL_ACKNOWLEDGED",
|
|
12582
|
+
cause: started.acknowledgement
|
|
12583
|
+
});
|
|
12584
|
+
return new ResponseStream(started.handle);
|
|
12585
|
+
}
|
|
12586
|
+
const requestBody = {
|
|
12587
|
+
...request,
|
|
12588
|
+
workspace_ext_id: request.workspace_ext_id ?? this.requireWorkspace(),
|
|
12589
|
+
stream: false,
|
|
12590
|
+
background: request.background ?? false,
|
|
12591
|
+
store: request.store ?? true
|
|
12592
|
+
};
|
|
12593
|
+
const response = await this.recovering(
|
|
12594
|
+
() => openTurnStream(this.getAuthHeaders(), requestBody, options.signal)
|
|
12595
|
+
);
|
|
12596
|
+
let body;
|
|
12597
|
+
try {
|
|
12598
|
+
body = await response.text();
|
|
12599
|
+
} catch (cause) {
|
|
12600
|
+
throw transportError(cause);
|
|
12601
|
+
}
|
|
12602
|
+
try {
|
|
12603
|
+
return withOutputText(
|
|
12604
|
+
JSON.parse(body),
|
|
12605
|
+
response.headers.get("x-request-id") ?? void 0
|
|
12606
|
+
);
|
|
12607
|
+
} catch (cause) {
|
|
12608
|
+
throw new ArbiError("Expected a Responses JSON object.", {
|
|
12609
|
+
code: "RESPONSE_INVALID_ENVELOPE",
|
|
12610
|
+
cause,
|
|
12611
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
12612
|
+
});
|
|
12613
|
+
}
|
|
12614
|
+
},
|
|
12615
|
+
parse: async (request, options = {}) => {
|
|
12616
|
+
if (request.stream || request.background)
|
|
12617
|
+
throw new ArbiError(
|
|
12618
|
+
"Parse a synchronous response, or validate a completed stored response separately.",
|
|
12619
|
+
{ code: "RESPONSES_UNSUPPORTED_OPTION" }
|
|
12620
|
+
);
|
|
12621
|
+
const workspaceId = request.workspace_ext_id ?? this.requireWorkspace();
|
|
12622
|
+
const parse = await createStructuredParser(request.text.format);
|
|
12623
|
+
const response = await this.responses.create(
|
|
12624
|
+
{ ...request, workspace_ext_id: workspaceId, stream: false, background: false },
|
|
12625
|
+
options
|
|
12626
|
+
);
|
|
12627
|
+
return {
|
|
12628
|
+
...response,
|
|
12629
|
+
output_parsed: parse(response, { requestId: response._request_id }).data
|
|
12630
|
+
};
|
|
12631
|
+
},
|
|
12632
|
+
stream: (request, options = {}) => this.openResponseHandle(
|
|
12633
|
+
(signal) => openTurnStream(
|
|
12634
|
+
this.getAuthHeaders(),
|
|
12635
|
+
{
|
|
12636
|
+
...request,
|
|
12637
|
+
workspace_ext_id: request.workspace_ext_id ?? this.requireWorkspace(),
|
|
12638
|
+
stream: true,
|
|
12639
|
+
background: false,
|
|
12640
|
+
store: request.store ?? true
|
|
12641
|
+
},
|
|
12642
|
+
signal
|
|
12643
|
+
),
|
|
12644
|
+
options
|
|
12645
|
+
),
|
|
12646
|
+
retrieve: async (id) => withOutputText(await this.assistant.getResponse(id)),
|
|
12647
|
+
cancel: (id) => this.assistant.cancel(id),
|
|
12648
|
+
attach: (id, options = {}) => this.assistant.attachResponse(id, options)
|
|
12649
|
+
};
|
|
12285
12650
|
// ── Assistant ─────────────────────────────────────────────────────────
|
|
12286
12651
|
assistant = {
|
|
12652
|
+
/** Create one synchronous Responses result and return validated JSON alongside the raw response. */
|
|
12653
|
+
parseResponse: async (request, options = {}) => {
|
|
12654
|
+
const parse = await createStructuredParser(request.text.format);
|
|
12655
|
+
const body = {
|
|
12656
|
+
...buildTurnRequest({
|
|
12657
|
+
...request,
|
|
12658
|
+
workspaceId: request.workspaceId ?? this.requireWorkspace()
|
|
12659
|
+
}),
|
|
12660
|
+
stream: false,
|
|
12661
|
+
background: false
|
|
12662
|
+
};
|
|
12663
|
+
const response = await this.recovering(
|
|
12664
|
+
() => openTurnStream(this.getAuthHeaders(), body, options.signal)
|
|
12665
|
+
);
|
|
12666
|
+
let rawText;
|
|
12667
|
+
try {
|
|
12668
|
+
rawText = await response.text();
|
|
12669
|
+
} catch (cause) {
|
|
12670
|
+
throw transportError(cause);
|
|
12671
|
+
}
|
|
12672
|
+
let raw;
|
|
12673
|
+
try {
|
|
12674
|
+
raw = JSON.parse(rawText);
|
|
12675
|
+
} catch (cause) {
|
|
12676
|
+
throw new ArbiStructuredOutputError("Expected a Responses JSON object.", rawText, {
|
|
12677
|
+
code: "RESPONSE_INVALID_ENVELOPE",
|
|
12678
|
+
cause,
|
|
12679
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
12680
|
+
});
|
|
12681
|
+
}
|
|
12682
|
+
return parse(raw, { requestId: response.headers.get("x-request-id") ?? void 0 });
|
|
12683
|
+
},
|
|
12287
12684
|
/** Start one response with a composable observer; existing ask callbacks remain unchanged. */
|
|
12288
12685
|
startResponse: async (request, options = {}) => {
|
|
12289
|
-
const
|
|
12290
|
-
...request,
|
|
12291
|
-
workspaceId: request.workspaceId ?? this.requireWorkspace()
|
|
12292
|
-
});
|
|
12686
|
+
const workspaceId = request.workspaceId ?? this.requireWorkspace();
|
|
12293
12687
|
return this.openResponseHandle(
|
|
12294
|
-
(signal) =>
|
|
12688
|
+
(signal) => this.openTurn(
|
|
12689
|
+
request,
|
|
12690
|
+
workspaceId,
|
|
12691
|
+
(body) => openTurnStream(this.getAuthHeaders(), body, signal),
|
|
12692
|
+
options.onWorkspace
|
|
12693
|
+
),
|
|
12295
12694
|
options
|
|
12296
12695
|
);
|
|
12297
12696
|
},
|
|
@@ -12319,22 +12718,29 @@ var Arbi = class {
|
|
|
12319
12718
|
* with it; an abort just rejects.
|
|
12320
12719
|
*/
|
|
12321
12720
|
ask: async (request, handlers = {}) => {
|
|
12322
|
-
const { signal, onError, onQuotaExceeded, ...callbacks } = handlers;
|
|
12323
|
-
const
|
|
12324
|
-
...request,
|
|
12325
|
-
workspaceId: request.workspaceId ?? this.requireWorkspace()
|
|
12326
|
-
});
|
|
12721
|
+
const { signal, onError, onQuotaExceeded, onWorkspace, ...callbacks } = handlers;
|
|
12722
|
+
const workspaceId = request.workspaceId ?? this.requireWorkspace();
|
|
12327
12723
|
const refuse = (message, error = new Error(message)) => {
|
|
12328
12724
|
onError?.(message);
|
|
12329
12725
|
throw error;
|
|
12330
12726
|
};
|
|
12331
12727
|
let response;
|
|
12332
12728
|
try {
|
|
12333
|
-
response = await this.
|
|
12334
|
-
|
|
12729
|
+
response = await this.openTurn(
|
|
12730
|
+
request,
|
|
12731
|
+
workspaceId,
|
|
12732
|
+
(body) => openTurnStream(this.getAuthHeaders(), body, signal),
|
|
12733
|
+
onWorkspace
|
|
12335
12734
|
);
|
|
12336
12735
|
} catch (error) {
|
|
12337
12736
|
if (isAbort(error)) throw error;
|
|
12737
|
+
if (error instanceof ArbiWorkspaceUnavailableError) {
|
|
12738
|
+
callbacks.onErrorDetails?.(error);
|
|
12739
|
+
return refuse(
|
|
12740
|
+
"This chat's workspace can't be opened in this session, so the message was not sent.",
|
|
12741
|
+
error
|
|
12742
|
+
);
|
|
12743
|
+
}
|
|
12338
12744
|
if (error instanceof AssistantTurnRefused) {
|
|
12339
12745
|
if (error.quota) onQuotaExceeded?.(error.quota);
|
|
12340
12746
|
callbacks.onErrorDetails?.(error);
|
|
@@ -12392,14 +12798,16 @@ var Arbi = class {
|
|
|
12392
12798
|
transcribe: (audio) => transcribe(this.requireClient(), audio),
|
|
12393
12799
|
/** Start a durable background turn; task options make its thread a work item. */
|
|
12394
12800
|
submit: (question, options) => {
|
|
12395
|
-
const workspaceId = this.requireWorkspace();
|
|
12396
|
-
return this.
|
|
12397
|
-
() =>
|
|
12398
|
-
|
|
12399
|
-
|
|
12400
|
-
|
|
12401
|
-
|
|
12402
|
-
|
|
12801
|
+
const workspaceId = options.workspaceId ?? this.requireWorkspace();
|
|
12802
|
+
return this.primeOrFail(workspaceId).then(
|
|
12803
|
+
() => this.recovering(
|
|
12804
|
+
() => submitBackgroundQuery({
|
|
12805
|
+
...this.getAuthHeaders(),
|
|
12806
|
+
...options,
|
|
12807
|
+
workspaceId,
|
|
12808
|
+
question
|
|
12809
|
+
})
|
|
12810
|
+
)
|
|
12403
12811
|
);
|
|
12404
12812
|
},
|
|
12405
12813
|
/** Read the status of a background turn. */
|
|
@@ -12420,13 +12828,19 @@ var Arbi = class {
|
|
|
12420
12828
|
* Search documents without LLM generation (retrieval only). No `docIds` searches the whole
|
|
12421
12829
|
* workspace; `searchChunks(result)` ranks the passages found.
|
|
12422
12830
|
*/
|
|
12423
|
-
retrieve: (query2, docIds, options) =>
|
|
12424
|
-
|
|
12425
|
-
workspaceId
|
|
12426
|
-
|
|
12427
|
-
|
|
12428
|
-
|
|
12429
|
-
|
|
12831
|
+
retrieve: (query2, docIds, options) => {
|
|
12832
|
+
const { workspaceId: named, ...rest } = options ?? {};
|
|
12833
|
+
const workspaceId = named ?? this.requireWorkspace();
|
|
12834
|
+
return this.primeOrFail(workspaceId).then(
|
|
12835
|
+
() => retrieve({
|
|
12836
|
+
arbi: this.requireClient(),
|
|
12837
|
+
workspaceId,
|
|
12838
|
+
query: query2,
|
|
12839
|
+
docIds,
|
|
12840
|
+
...rest
|
|
12841
|
+
})
|
|
12842
|
+
);
|
|
12843
|
+
}
|
|
12430
12844
|
};
|
|
12431
12845
|
// ── Tags ──────────────────────────────────────────────────────────────
|
|
12432
12846
|
tags = {
|
|
@@ -14921,6 +15335,55 @@ function getRunToAttach(localGeneration, messages) {
|
|
|
14921
15335
|
return getAttachableRunId(messages);
|
|
14922
15336
|
}
|
|
14923
15337
|
|
|
14924
|
-
|
|
15338
|
+
// src/configuration.ts
|
|
15339
|
+
function composeConfiguration(base, ...patches) {
|
|
15340
|
+
const result = structuredClone(base);
|
|
15341
|
+
for (const patch of patches) {
|
|
15342
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
15343
|
+
if (value === void 0) continue;
|
|
15344
|
+
result[key] = value && typeof value === "object" && !Array.isArray(value) ? { ...result[key] ?? {}, ...structuredClone(value) } : structuredClone(value);
|
|
15345
|
+
}
|
|
15346
|
+
}
|
|
15347
|
+
return result;
|
|
15348
|
+
}
|
|
15349
|
+
function instructions(text2) {
|
|
15350
|
+
return { QueryLLM: { SYSTEM_INSTRUCTION: text2 }, Agents: { PERSONA: text2 } };
|
|
15351
|
+
}
|
|
15352
|
+
function capabilities(options) {
|
|
15353
|
+
const flags = {
|
|
15354
|
+
webSearch: "WEB_SEARCH_ENABLED",
|
|
15355
|
+
codeExecution: "RUN_CODE_ENABLED",
|
|
15356
|
+
planning: "PLANNING_ENABLED",
|
|
15357
|
+
deepResearch: "DEEP_RESEARCH_ENABLED",
|
|
15358
|
+
subagents: "SUBAGENTS_ENABLED",
|
|
15359
|
+
humanInput: "HUMAN_IN_THE_LOOP"
|
|
15360
|
+
};
|
|
15361
|
+
const Agents = {};
|
|
15362
|
+
for (const key of Object.keys(flags)) {
|
|
15363
|
+
if (options[key] !== void 0) Agents[flags[key]] = options[key];
|
|
15364
|
+
}
|
|
15365
|
+
return { Agents };
|
|
15366
|
+
}
|
|
15367
|
+
function mcpTools(base, names, mode) {
|
|
15368
|
+
return {
|
|
15369
|
+
Agents: {
|
|
15370
|
+
MCP_TOOLS: [
|
|
15371
|
+
.../* @__PURE__ */ new Set([...mode === "add" ? base.Agents?.MCP_TOOLS ?? [] : [], ...names])
|
|
15372
|
+
]
|
|
15373
|
+
}
|
|
15374
|
+
};
|
|
15375
|
+
}
|
|
15376
|
+
function documentTools(options) {
|
|
15377
|
+
return {
|
|
15378
|
+
...options.search ? { retrieval_chunk: buildRetrievalChunkTool([...options.search]) } : {},
|
|
15379
|
+
...options.fullContext ? { retrieval_full_context: buildRetrievalFullContextTool([...options.fullContext]) } : {},
|
|
15380
|
+
...options.tableOfContents ? { retrieval_toc: buildRetrievalTocTool([...options.tableOfContents]) } : {}
|
|
15381
|
+
};
|
|
15382
|
+
}
|
|
15383
|
+
function composeTools(base, next, mode) {
|
|
15384
|
+
return structuredClone(mode === "add" ? { ...base, ...next } : next);
|
|
15385
|
+
}
|
|
15386
|
+
|
|
15387
|
+
export { ACCOUNT_VENDOR, Arbi, ArbiApiError, ArbiError, ArbiSessionExpiredError, ArbiStructuredOutputError, ArbiTransportError, ArbiWorkspaceChangedError, ArbiWorkspaceSupersededError, ArbiWorkspaceUnavailableError, CallApiError, ClaudeOrchestrator, DEFAULT_AI_USD_PER_GBP, DOC_TERMINAL_STATUSES, DRIVE_SYNC_VENDORS, DuplicateContactError, ENTITY_KINDS, FLAT_TAG_KINDS, FileConfigStore, GOOGLE_VENDORS, IMANAGE_VENDORS, MAILBOX_SYNC_VENDORS, MAX_RETRIEVE_DOC_IDS, MICROSOFT_VENDORS, OpenClawOrchestrator, PRESENCE_KINDS, PROMPT_CONTEXT_CHARS, PlanStepsError, PublicBookingError, ResponseStream, SHAREPOINT_VENDORS, STEP_FIELD_OPTION_TONES, STOP_ID_WAIT_MS, STOP_REPEAT_WINDOW_MS, TAG_KINDS, TAG_NESTING_MAX_DEPTH, WebSocketAuthError, account_exports as account, agentconfig_exports as agentconfig, agents_exports as agents, appendTranscriptionHints, assistant_exports as assistant, authenticatedFetch, bookPublicSlot, buildCitationChunkData, buildDocNameMap, buildDocumentTools, buildFactsContextTool, buildRetrievalChunkTool, buildRetrievalFullContextTool, buildRetrievalTocTool, buildTurnRequest, calendar_exports as calendar, calls_exports as calls, canTagHaveParent, cancelPublicBooking, capabilities, chats_exports as chats, composeConfiguration, composeTools, computeRunStats, connectErrorMessage, connectWebSocket, connectWithReconnect, connectors_exports as connectors, contacts_exports as contacts, continuityPrompt, conversations_exports as conversations, countCitations, createAuthenticatedClient, createDocumentWaiter, createIndexAssigner, databases_exports as databases, defaultKindForFormat, device_flow_exports as deviceFlow, doctags_exports as doctags, documentTools, documents_exports as documents, documents_node_exports as documentsNode, estimateDraftTokens, extractDocumentIdsFromMessages, extractFactIdsFromMessages, extractSubagentLanes, facts_exports as facts, files_exports as files, filterDocumentTags, filterSkills, findLeafForTaskMessage, findMainSiblingLeaf, findReplyTarget, findSubagentRunId, firm_exports as firm, flattenTagTree, formatAgentStepLabel, formatFileSize, formatGbp, formatGbpPerMillionTokens, formatItemLabel, formatStreamSummary, formatTokens, formatUserName, formatWorkspaceChoices, formatWsMessage, generateEncryptedWorkspaceKey, generateNewWorkspaceKey, getAgentStepLabel, getAttachableRunId, getChildTags, getContextRemainingPercent, getContextUsedPercent, getContextUsedTokens, getCurrentStep, getEligibleParentTags, getErrorCode, getErrorMessage, getPublicBookingPage, getRawWorkspaceKey, getRunToAttach, getRunToCancel, getStepDisplay, getStepTool, getSubagentBranchRecord, getTagDescendantIds, health_exports as health, house_template_exports as houseTemplates, hydrateAgentSteps, identityErrorCode, identity_exports as identityVerification, instructions, isAnnotationTag, isConnectorVendorVisible, isDriveSyncVendor, isEntityTag, isFlatKind, isLabelTag, isMailboxSyncVendor, isNearAiUsageBudget, isPresenceTag, isSharePointVendor, isSharedSkill, isTraceItem, listen_exports as listen, mail_exports as mail, mail_node_exports as mailNode, mcpTools, mergeAgentSteps, notifications_exports as notifications, parseSSEEvents, parseSlashCommand, parseSlashTokenInProgress, parseStructuredResponse, performPasswordLogin, performSigningKeyLogin, performSsoDeviceFlowLogin, pickMainThread, profile_exports as profile, progressFetch, projects_exports as projects, quotaExceededFrom, quotaFromStreamError, reduceOutputItem, refusalReason, requireData, requireOk, resolveAuth, resolveCitations, resolveSummary, resolveWorkspace, responses_exports as responses, searchChunks, selectFullContextDocument, selectWorkspace, selectWorkspaceById, sessions_exports as sessions, settings_exports as settings, signature_requests_exports as signatureRequests, sliceToSubagentThread, startDmListener, streamSSE, stripCitationMarkdown, subagentJobLabel, summarizeCitations, tagUseCount, tags_exports as tags, tagsForScope, tagsOfGroup, topLevelAgentSteps, uploadSkill, usdToGbp, work_exports as work, workflow_steps_exports as workflowSteps, workflows_exports as workflows, workspaceConflictOf, workspaces_exports as workspaces, wouldCreateTagCycle };
|
|
14925
15388
|
//# sourceMappingURL=index.js.map
|
|
14926
15389
|
//# sourceMappingURL=index.js.map
|