@arbidocs/sdk 0.5.59 → 0.5.61
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 +118 -0
- package/dist/{browser-wtQhRmpE.d.cts → browser-2WIMhFQU.d.cts} +104 -2
- package/dist/{browser-H9ziI77P.d.ts → browser-CKSVXWvq.d.ts} +104 -2
- package/dist/browser.cjs +253 -1
- 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 +246 -2
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +253 -1
- 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 +246 -2
- package/dist/index.js.map +1 -1
- package/examples/background-response.mjs +18 -0
- package/examples/responses-contract.json +97 -0
- package/examples/session.mjs +10 -0
- package/examples/structured-extraction.mjs +20 -0
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -5165,6 +5165,116 @@ function buildChunkLookup(tools) {
|
|
|
5165
5165
|
return lookup;
|
|
5166
5166
|
}
|
|
5167
5167
|
|
|
5168
|
+
// src/structured-output.ts
|
|
5169
|
+
var ArbiStructuredOutputError = class extends ArbiError {
|
|
5170
|
+
constructor(message, response, options) {
|
|
5171
|
+
const id = response && typeof response === "object" && "id" in response && typeof response.id === "string" ? response.id : void 0;
|
|
5172
|
+
super(message, { responseId: id, ...options });
|
|
5173
|
+
this.response = response;
|
|
5174
|
+
this.name = "ArbiStructuredOutputError";
|
|
5175
|
+
}
|
|
5176
|
+
response;
|
|
5177
|
+
};
|
|
5178
|
+
function localReferences(value) {
|
|
5179
|
+
if (Array.isArray(value)) {
|
|
5180
|
+
value.forEach(localReferences);
|
|
5181
|
+
return;
|
|
5182
|
+
}
|
|
5183
|
+
if (!value || typeof value !== "object") return;
|
|
5184
|
+
for (const [key, child] of Object.entries(value)) {
|
|
5185
|
+
if ((key === "$ref" || key === "$dynamicRef") && (typeof child !== "string" || !child.startsWith("#")))
|
|
5186
|
+
throw new Error("Only local schema references are supported.");
|
|
5187
|
+
if (!["enum", "const", "default", "examples"].includes(key)) localReferences(child);
|
|
5188
|
+
}
|
|
5189
|
+
}
|
|
5190
|
+
async function createStructuredParser(format) {
|
|
5191
|
+
let validate;
|
|
5192
|
+
let Constructor;
|
|
5193
|
+
try {
|
|
5194
|
+
Constructor = (await import('ajv/dist/2020.js')).default;
|
|
5195
|
+
} catch (cause) {
|
|
5196
|
+
throw new ArbiStructuredOutputError(
|
|
5197
|
+
"The JSON Schema validator could not be loaded.",
|
|
5198
|
+
void 0,
|
|
5199
|
+
{ code: "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE", cause }
|
|
5200
|
+
);
|
|
5201
|
+
}
|
|
5202
|
+
try {
|
|
5203
|
+
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))
|
|
5204
|
+
throw new Error("Invalid structured output format.");
|
|
5205
|
+
if (format.schema.$schema !== void 0 && format.schema.$schema !== "https://json-schema.org/draft/2020-12/schema")
|
|
5206
|
+
throw new Error("Expected JSON Schema draft 2020-12.");
|
|
5207
|
+
localReferences(format.schema);
|
|
5208
|
+
validate = new Constructor({
|
|
5209
|
+
strict: false,
|
|
5210
|
+
logger: false,
|
|
5211
|
+
validateFormats: false,
|
|
5212
|
+
strictNumbers: true,
|
|
5213
|
+
addUsedSchema: false
|
|
5214
|
+
}).compile(format.schema);
|
|
5215
|
+
} catch (cause) {
|
|
5216
|
+
const unavailable = cause instanceof EvalError;
|
|
5217
|
+
throw new ArbiStructuredOutputError(
|
|
5218
|
+
unavailable ? "This runtime cannot compile JSON Schema validators." : "Invalid or unsupported output schema.",
|
|
5219
|
+
void 0,
|
|
5220
|
+
{
|
|
5221
|
+
code: unavailable ? "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE" : "STRUCTURED_OUTPUT_SCHEMA_INVALID",
|
|
5222
|
+
cause
|
|
5223
|
+
}
|
|
5224
|
+
);
|
|
5225
|
+
}
|
|
5226
|
+
return (response, options = {}) => {
|
|
5227
|
+
const fail = (code, message, cause) => {
|
|
5228
|
+
throw new ArbiStructuredOutputError(message, response, { ...options, code, cause });
|
|
5229
|
+
};
|
|
5230
|
+
if (!response || typeof response !== "object")
|
|
5231
|
+
fail("RESPONSE_INVALID_ENVELOPE", "Expected a Responses JSON object.");
|
|
5232
|
+
if (response.status === "incomplete")
|
|
5233
|
+
fail("RESPONSE_INCOMPLETE", "The response is incomplete; no validated data is available.");
|
|
5234
|
+
if (response.status === "cancelled")
|
|
5235
|
+
fail("RESPONSE_CANCELLED", "The response was cancelled; no validated data is available.");
|
|
5236
|
+
if (response.status === "failed")
|
|
5237
|
+
fail(
|
|
5238
|
+
typeof response.error?.code === "string" ? response.error.code : "RESPONSE_FAILED",
|
|
5239
|
+
typeof response.error?.message === "string" ? response.error.message : "The response failed."
|
|
5240
|
+
);
|
|
5241
|
+
if (response.status !== "completed")
|
|
5242
|
+
fail(
|
|
5243
|
+
"RESPONSE_NOT_COMPLETED",
|
|
5244
|
+
"Wait for a completed response before parsing structured output."
|
|
5245
|
+
);
|
|
5246
|
+
const messages = Array.isArray(response.output) ? response.output.filter(
|
|
5247
|
+
(item) => item && typeof item === "object" && item.type === "message" && item.role === "assistant"
|
|
5248
|
+
) : [];
|
|
5249
|
+
if (messages.some(
|
|
5250
|
+
(message) => !Array.isArray(message.content) || message.content.some((part) => !part || typeof part !== "object")
|
|
5251
|
+
))
|
|
5252
|
+
fail("RESPONSE_INVALID_ENVELOPE", "Invalid assistant output content.");
|
|
5253
|
+
if (messages.some((message) => message.content.some((part) => part.type === "refusal")))
|
|
5254
|
+
fail("RESPONSE_REFUSED", "The model refused this response.");
|
|
5255
|
+
const answers = messages.map(
|
|
5256
|
+
(message) => message.content.filter((part) => part.type === "output_text" && typeof part.text === "string").map((part) => part.text).join("")
|
|
5257
|
+
).filter((answer) => answer.length > 0);
|
|
5258
|
+
if (answers.length !== 1)
|
|
5259
|
+
fail(
|
|
5260
|
+
"STRUCTURED_OUTPUT_AMBIGUOUS",
|
|
5261
|
+
"Expected one final assistant output message; narrative and answer text are not joined."
|
|
5262
|
+
);
|
|
5263
|
+
let data;
|
|
5264
|
+
try {
|
|
5265
|
+
data = JSON.parse(answers[0]);
|
|
5266
|
+
} catch (cause) {
|
|
5267
|
+
fail("STRUCTURED_OUTPUT_INVALID_JSON", "The response is not valid JSON.", cause);
|
|
5268
|
+
}
|
|
5269
|
+
if (!validate(data))
|
|
5270
|
+
fail("STRUCTURED_OUTPUT_INVALID", "The response did not match the requested JSON schema.");
|
|
5271
|
+
return { data, response };
|
|
5272
|
+
};
|
|
5273
|
+
}
|
|
5274
|
+
async function parseStructuredResponse(response, format) {
|
|
5275
|
+
return (await createStructuredParser(format))(response);
|
|
5276
|
+
}
|
|
5277
|
+
|
|
5168
5278
|
// src/response-handle.ts
|
|
5169
5279
|
var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
5170
5280
|
var text = (value) => typeof value === "string" ? value : void 0;
|
|
@@ -6665,6 +6775,7 @@ function buildTurnRequest(request) {
|
|
|
6665
6775
|
...request.previousResponseId ? { previous_response_id: request.previousResponseId } : {},
|
|
6666
6776
|
...request.conversationId ? { conversation_ext_id: request.conversationId } : {},
|
|
6667
6777
|
...request.model && !pa2 ? { model: request.model } : {},
|
|
6778
|
+
...request.text ? { text: request.text } : {},
|
|
6668
6779
|
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
6669
6780
|
...request.bindDocumentId && !request.previousResponseId && !pa2 ? { bound_document_ext_id: request.bindDocumentId } : {},
|
|
6670
6781
|
...request.mentions && request.mentions.length > 0 ? { mentions: request.mentions } : {},
|
|
@@ -6952,6 +7063,7 @@ async function submitBackgroundQuery(options) {
|
|
|
6952
7063
|
docIds,
|
|
6953
7064
|
previousResponseId,
|
|
6954
7065
|
model,
|
|
7066
|
+
text: text2,
|
|
6955
7067
|
task,
|
|
6956
7068
|
conversationId,
|
|
6957
7069
|
mentions,
|
|
@@ -6987,7 +7099,8 @@ async function submitBackgroundQuery(options) {
|
|
|
6987
7099
|
...mentions !== void 0 ? { mentions } : {},
|
|
6988
7100
|
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
6989
7101
|
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
6990
|
-
...model ? { model } : {}
|
|
7102
|
+
...model ? { model } : {},
|
|
7103
|
+
...text2 ? { text: text2 } : {}
|
|
6991
7104
|
};
|
|
6992
7105
|
const res = await authenticatedFetch({
|
|
6993
7106
|
...auth,
|
|
@@ -12291,8 +12404,90 @@ var Arbi = class {
|
|
|
12291
12404
|
throw error;
|
|
12292
12405
|
}
|
|
12293
12406
|
}
|
|
12407
|
+
/** Canonical Responses-shaped requests; existing assistant convenience helpers remain supported. */
|
|
12408
|
+
responses = {
|
|
12409
|
+
create: async (request, options = {}) => {
|
|
12410
|
+
const response = await this.recovering(
|
|
12411
|
+
() => openTurnStream(
|
|
12412
|
+
this.getAuthHeaders(),
|
|
12413
|
+
{
|
|
12414
|
+
...request,
|
|
12415
|
+
workspace_ext_id: request.workspace_ext_id ?? this.requireWorkspace(),
|
|
12416
|
+
stream: false,
|
|
12417
|
+
background: request.background ?? false,
|
|
12418
|
+
store: request.store ?? true
|
|
12419
|
+
},
|
|
12420
|
+
options.signal
|
|
12421
|
+
)
|
|
12422
|
+
);
|
|
12423
|
+
let body;
|
|
12424
|
+
try {
|
|
12425
|
+
body = await response.text();
|
|
12426
|
+
} catch (cause) {
|
|
12427
|
+
throw transportError(cause);
|
|
12428
|
+
}
|
|
12429
|
+
try {
|
|
12430
|
+
return JSON.parse(body);
|
|
12431
|
+
} catch (cause) {
|
|
12432
|
+
throw new ArbiError("Expected a Responses JSON object.", {
|
|
12433
|
+
code: "RESPONSE_INVALID_ENVELOPE",
|
|
12434
|
+
cause,
|
|
12435
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
12436
|
+
});
|
|
12437
|
+
}
|
|
12438
|
+
},
|
|
12439
|
+
stream: (request, options = {}) => this.openResponseHandle(
|
|
12440
|
+
(signal) => openTurnStream(
|
|
12441
|
+
this.getAuthHeaders(),
|
|
12442
|
+
{
|
|
12443
|
+
...request,
|
|
12444
|
+
workspace_ext_id: request.workspace_ext_id ?? this.requireWorkspace(),
|
|
12445
|
+
stream: true,
|
|
12446
|
+
background: false,
|
|
12447
|
+
store: request.store ?? true
|
|
12448
|
+
},
|
|
12449
|
+
signal
|
|
12450
|
+
),
|
|
12451
|
+
options
|
|
12452
|
+
),
|
|
12453
|
+
retrieve: (id) => this.assistant.getResponse(id),
|
|
12454
|
+
cancel: (id) => this.assistant.cancel(id),
|
|
12455
|
+
attach: (id, options = {}) => this.assistant.attachResponse(id, options)
|
|
12456
|
+
};
|
|
12294
12457
|
// ── Assistant ─────────────────────────────────────────────────────────
|
|
12295
12458
|
assistant = {
|
|
12459
|
+
/** Create one synchronous Responses result and return validated JSON alongside the raw response. */
|
|
12460
|
+
parseResponse: async (request, options = {}) => {
|
|
12461
|
+
const parse = await createStructuredParser(request.text.format);
|
|
12462
|
+
const body = {
|
|
12463
|
+
...buildTurnRequest({
|
|
12464
|
+
...request,
|
|
12465
|
+
workspaceId: request.workspaceId ?? this.requireWorkspace()
|
|
12466
|
+
}),
|
|
12467
|
+
stream: false,
|
|
12468
|
+
background: false
|
|
12469
|
+
};
|
|
12470
|
+
const response = await this.recovering(
|
|
12471
|
+
() => openTurnStream(this.getAuthHeaders(), body, options.signal)
|
|
12472
|
+
);
|
|
12473
|
+
let rawText;
|
|
12474
|
+
try {
|
|
12475
|
+
rawText = await response.text();
|
|
12476
|
+
} catch (cause) {
|
|
12477
|
+
throw transportError(cause);
|
|
12478
|
+
}
|
|
12479
|
+
let raw;
|
|
12480
|
+
try {
|
|
12481
|
+
raw = JSON.parse(rawText);
|
|
12482
|
+
} catch (cause) {
|
|
12483
|
+
throw new ArbiStructuredOutputError("Expected a Responses JSON object.", rawText, {
|
|
12484
|
+
code: "RESPONSE_INVALID_ENVELOPE",
|
|
12485
|
+
cause,
|
|
12486
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
12487
|
+
});
|
|
12488
|
+
}
|
|
12489
|
+
return parse(raw, { requestId: response.headers.get("x-request-id") ?? void 0 });
|
|
12490
|
+
},
|
|
12296
12491
|
/** Start one response with a composable observer; existing ask callbacks remain unchanged. */
|
|
12297
12492
|
startResponse: async (request, options = {}) => {
|
|
12298
12493
|
const body = buildTurnRequest({
|
|
@@ -14930,11 +15125,61 @@ function getRunToAttach(localGeneration, messages) {
|
|
|
14930
15125
|
return getAttachableRunId(messages);
|
|
14931
15126
|
}
|
|
14932
15127
|
|
|
15128
|
+
// src/configuration.ts
|
|
15129
|
+
function composeConfiguration(base, ...patches) {
|
|
15130
|
+
const result = structuredClone(base);
|
|
15131
|
+
for (const patch of patches) {
|
|
15132
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
15133
|
+
if (value === void 0) continue;
|
|
15134
|
+
result[key] = value && typeof value === "object" && !Array.isArray(value) ? { ...result[key] ?? {}, ...structuredClone(value) } : structuredClone(value);
|
|
15135
|
+
}
|
|
15136
|
+
}
|
|
15137
|
+
return result;
|
|
15138
|
+
}
|
|
15139
|
+
function instructions(text2) {
|
|
15140
|
+
return { QueryLLM: { SYSTEM_INSTRUCTION: text2 }, Agents: { PERSONA: text2 } };
|
|
15141
|
+
}
|
|
15142
|
+
function capabilities(options) {
|
|
15143
|
+
const flags = {
|
|
15144
|
+
webSearch: "WEB_SEARCH_ENABLED",
|
|
15145
|
+
codeExecution: "RUN_CODE_ENABLED",
|
|
15146
|
+
planning: "PLANNING_ENABLED",
|
|
15147
|
+
deepResearch: "DEEP_RESEARCH_ENABLED",
|
|
15148
|
+
subagents: "SUBAGENTS_ENABLED",
|
|
15149
|
+
humanInput: "HUMAN_IN_THE_LOOP"
|
|
15150
|
+
};
|
|
15151
|
+
const Agents = {};
|
|
15152
|
+
for (const key of Object.keys(flags)) {
|
|
15153
|
+
if (options[key] !== void 0) Agents[flags[key]] = options[key];
|
|
15154
|
+
}
|
|
15155
|
+
return { Agents };
|
|
15156
|
+
}
|
|
15157
|
+
function mcpTools(base, names, mode) {
|
|
15158
|
+
return {
|
|
15159
|
+
Agents: {
|
|
15160
|
+
MCP_TOOLS: [
|
|
15161
|
+
.../* @__PURE__ */ new Set([...mode === "add" ? base.Agents?.MCP_TOOLS ?? [] : [], ...names])
|
|
15162
|
+
]
|
|
15163
|
+
}
|
|
15164
|
+
};
|
|
15165
|
+
}
|
|
15166
|
+
function documentTools(options) {
|
|
15167
|
+
return {
|
|
15168
|
+
...options.search ? { retrieval_chunk: buildRetrievalChunkTool([...options.search]) } : {},
|
|
15169
|
+
...options.fullContext ? { retrieval_full_context: buildRetrievalFullContextTool([...options.fullContext]) } : {},
|
|
15170
|
+
...options.tableOfContents ? { retrieval_toc: buildRetrievalTocTool([...options.tableOfContents]) } : {}
|
|
15171
|
+
};
|
|
15172
|
+
}
|
|
15173
|
+
function composeTools(base, next, mode) {
|
|
15174
|
+
return structuredClone(mode === "add" ? { ...base, ...next } : next);
|
|
15175
|
+
}
|
|
15176
|
+
|
|
14933
15177
|
exports.ACCOUNT_VENDOR = ACCOUNT_VENDOR;
|
|
14934
15178
|
exports.Arbi = Arbi;
|
|
14935
15179
|
exports.ArbiApiError = ArbiApiError;
|
|
14936
15180
|
exports.ArbiError = ArbiError;
|
|
14937
15181
|
exports.ArbiSessionExpiredError = ArbiSessionExpiredError;
|
|
15182
|
+
exports.ArbiStructuredOutputError = ArbiStructuredOutputError;
|
|
14938
15183
|
exports.ArbiTransportError = ArbiTransportError;
|
|
14939
15184
|
exports.ArbiWorkspaceChangedError = ArbiWorkspaceChangedError;
|
|
14940
15185
|
exports.ArbiWorkspaceSupersededError = ArbiWorkspaceSupersededError;
|
|
@@ -14983,7 +15228,10 @@ exports.calendar = calendar_exports;
|
|
|
14983
15228
|
exports.calls = calls_exports;
|
|
14984
15229
|
exports.canTagHaveParent = canTagHaveParent;
|
|
14985
15230
|
exports.cancelPublicBooking = cancelPublicBooking;
|
|
15231
|
+
exports.capabilities = capabilities;
|
|
14986
15232
|
exports.chats = chats_exports;
|
|
15233
|
+
exports.composeConfiguration = composeConfiguration;
|
|
15234
|
+
exports.composeTools = composeTools;
|
|
14987
15235
|
exports.computeRunStats = computeRunStats;
|
|
14988
15236
|
exports.connectErrorMessage = connectErrorMessage;
|
|
14989
15237
|
exports.connectWebSocket = connectWebSocket;
|
|
@@ -15000,6 +15248,7 @@ exports.databases = databases_exports;
|
|
|
15000
15248
|
exports.defaultKindForFormat = defaultKindForFormat;
|
|
15001
15249
|
exports.deviceFlow = device_flow_exports;
|
|
15002
15250
|
exports.doctags = doctags_exports;
|
|
15251
|
+
exports.documentTools = documentTools;
|
|
15003
15252
|
exports.documents = documents_exports;
|
|
15004
15253
|
exports.documentsNode = documents_node_exports;
|
|
15005
15254
|
exports.estimateDraftTokens = estimateDraftTokens;
|
|
@@ -15051,6 +15300,7 @@ exports.houseTemplates = house_template_exports;
|
|
|
15051
15300
|
exports.hydrateAgentSteps = hydrateAgentSteps;
|
|
15052
15301
|
exports.identityErrorCode = identityErrorCode;
|
|
15053
15302
|
exports.identityVerification = identity_exports;
|
|
15303
|
+
exports.instructions = instructions;
|
|
15054
15304
|
exports.isAnnotationTag = isAnnotationTag;
|
|
15055
15305
|
exports.isConnectorVendorVisible = isConnectorVendorVisible;
|
|
15056
15306
|
exports.isDriveSyncVendor = isDriveSyncVendor;
|
|
@@ -15066,11 +15316,13 @@ exports.isTraceItem = isTraceItem;
|
|
|
15066
15316
|
exports.listen = listen_exports;
|
|
15067
15317
|
exports.mail = mail_exports;
|
|
15068
15318
|
exports.mailNode = mail_node_exports;
|
|
15319
|
+
exports.mcpTools = mcpTools;
|
|
15069
15320
|
exports.mergeAgentSteps = mergeAgentSteps;
|
|
15070
15321
|
exports.notifications = notifications_exports;
|
|
15071
15322
|
exports.parseSSEEvents = parseSSEEvents;
|
|
15072
15323
|
exports.parseSlashCommand = parseSlashCommand;
|
|
15073
15324
|
exports.parseSlashTokenInProgress = parseSlashTokenInProgress;
|
|
15325
|
+
exports.parseStructuredResponse = parseStructuredResponse;
|
|
15074
15326
|
exports.performPasswordLogin = performPasswordLogin;
|
|
15075
15327
|
exports.performSigningKeyLogin = performSigningKeyLogin;
|
|
15076
15328
|
exports.performSsoDeviceFlowLogin = performSsoDeviceFlowLogin;
|