@arbidocs/sdk 0.5.60 → 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-BuRU9RVU.d.cts → browser-2WIMhFQU.d.cts} +100 -1
- package/dist/{browser-GyBIGRNQ.d.ts → browser-CKSVXWvq.d.ts} +100 -1
- 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/browser.cjs
CHANGED
|
@@ -4610,6 +4610,116 @@ function buildChunkLookup(tools) {
|
|
|
4610
4610
|
return lookup;
|
|
4611
4611
|
}
|
|
4612
4612
|
|
|
4613
|
+
// src/structured-output.ts
|
|
4614
|
+
var ArbiStructuredOutputError = class extends ArbiError {
|
|
4615
|
+
constructor(message, response, options) {
|
|
4616
|
+
const id = response && typeof response === "object" && "id" in response && typeof response.id === "string" ? response.id : void 0;
|
|
4617
|
+
super(message, { responseId: id, ...options });
|
|
4618
|
+
this.response = response;
|
|
4619
|
+
this.name = "ArbiStructuredOutputError";
|
|
4620
|
+
}
|
|
4621
|
+
response;
|
|
4622
|
+
};
|
|
4623
|
+
function localReferences(value) {
|
|
4624
|
+
if (Array.isArray(value)) {
|
|
4625
|
+
value.forEach(localReferences);
|
|
4626
|
+
return;
|
|
4627
|
+
}
|
|
4628
|
+
if (!value || typeof value !== "object") return;
|
|
4629
|
+
for (const [key, child] of Object.entries(value)) {
|
|
4630
|
+
if ((key === "$ref" || key === "$dynamicRef") && (typeof child !== "string" || !child.startsWith("#")))
|
|
4631
|
+
throw new Error("Only local schema references are supported.");
|
|
4632
|
+
if (!["enum", "const", "default", "examples"].includes(key)) localReferences(child);
|
|
4633
|
+
}
|
|
4634
|
+
}
|
|
4635
|
+
async function createStructuredParser(format) {
|
|
4636
|
+
let validate;
|
|
4637
|
+
let Constructor;
|
|
4638
|
+
try {
|
|
4639
|
+
Constructor = (await import('ajv/dist/2020.js')).default;
|
|
4640
|
+
} catch (cause) {
|
|
4641
|
+
throw new ArbiStructuredOutputError(
|
|
4642
|
+
"The JSON Schema validator could not be loaded.",
|
|
4643
|
+
void 0,
|
|
4644
|
+
{ code: "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE", cause }
|
|
4645
|
+
);
|
|
4646
|
+
}
|
|
4647
|
+
try {
|
|
4648
|
+
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))
|
|
4649
|
+
throw new Error("Invalid structured output format.");
|
|
4650
|
+
if (format.schema.$schema !== void 0 && format.schema.$schema !== "https://json-schema.org/draft/2020-12/schema")
|
|
4651
|
+
throw new Error("Expected JSON Schema draft 2020-12.");
|
|
4652
|
+
localReferences(format.schema);
|
|
4653
|
+
validate = new Constructor({
|
|
4654
|
+
strict: false,
|
|
4655
|
+
logger: false,
|
|
4656
|
+
validateFormats: false,
|
|
4657
|
+
strictNumbers: true,
|
|
4658
|
+
addUsedSchema: false
|
|
4659
|
+
}).compile(format.schema);
|
|
4660
|
+
} catch (cause) {
|
|
4661
|
+
const unavailable = cause instanceof EvalError;
|
|
4662
|
+
throw new ArbiStructuredOutputError(
|
|
4663
|
+
unavailable ? "This runtime cannot compile JSON Schema validators." : "Invalid or unsupported output schema.",
|
|
4664
|
+
void 0,
|
|
4665
|
+
{
|
|
4666
|
+
code: unavailable ? "STRUCTURED_OUTPUT_VALIDATOR_UNAVAILABLE" : "STRUCTURED_OUTPUT_SCHEMA_INVALID",
|
|
4667
|
+
cause
|
|
4668
|
+
}
|
|
4669
|
+
);
|
|
4670
|
+
}
|
|
4671
|
+
return (response, options = {}) => {
|
|
4672
|
+
const fail = (code, message, cause) => {
|
|
4673
|
+
throw new ArbiStructuredOutputError(message, response, { ...options, code, cause });
|
|
4674
|
+
};
|
|
4675
|
+
if (!response || typeof response !== "object")
|
|
4676
|
+
fail("RESPONSE_INVALID_ENVELOPE", "Expected a Responses JSON object.");
|
|
4677
|
+
if (response.status === "incomplete")
|
|
4678
|
+
fail("RESPONSE_INCOMPLETE", "The response is incomplete; no validated data is available.");
|
|
4679
|
+
if (response.status === "cancelled")
|
|
4680
|
+
fail("RESPONSE_CANCELLED", "The response was cancelled; no validated data is available.");
|
|
4681
|
+
if (response.status === "failed")
|
|
4682
|
+
fail(
|
|
4683
|
+
typeof response.error?.code === "string" ? response.error.code : "RESPONSE_FAILED",
|
|
4684
|
+
typeof response.error?.message === "string" ? response.error.message : "The response failed."
|
|
4685
|
+
);
|
|
4686
|
+
if (response.status !== "completed")
|
|
4687
|
+
fail(
|
|
4688
|
+
"RESPONSE_NOT_COMPLETED",
|
|
4689
|
+
"Wait for a completed response before parsing structured output."
|
|
4690
|
+
);
|
|
4691
|
+
const messages = Array.isArray(response.output) ? response.output.filter(
|
|
4692
|
+
(item) => item && typeof item === "object" && item.type === "message" && item.role === "assistant"
|
|
4693
|
+
) : [];
|
|
4694
|
+
if (messages.some(
|
|
4695
|
+
(message) => !Array.isArray(message.content) || message.content.some((part) => !part || typeof part !== "object")
|
|
4696
|
+
))
|
|
4697
|
+
fail("RESPONSE_INVALID_ENVELOPE", "Invalid assistant output content.");
|
|
4698
|
+
if (messages.some((message) => message.content.some((part) => part.type === "refusal")))
|
|
4699
|
+
fail("RESPONSE_REFUSED", "The model refused this response.");
|
|
4700
|
+
const answers = messages.map(
|
|
4701
|
+
(message) => message.content.filter((part) => part.type === "output_text" && typeof part.text === "string").map((part) => part.text).join("")
|
|
4702
|
+
).filter((answer) => answer.length > 0);
|
|
4703
|
+
if (answers.length !== 1)
|
|
4704
|
+
fail(
|
|
4705
|
+
"STRUCTURED_OUTPUT_AMBIGUOUS",
|
|
4706
|
+
"Expected one final assistant output message; narrative and answer text are not joined."
|
|
4707
|
+
);
|
|
4708
|
+
let data;
|
|
4709
|
+
try {
|
|
4710
|
+
data = JSON.parse(answers[0]);
|
|
4711
|
+
} catch (cause) {
|
|
4712
|
+
fail("STRUCTURED_OUTPUT_INVALID_JSON", "The response is not valid JSON.", cause);
|
|
4713
|
+
}
|
|
4714
|
+
if (!validate(data))
|
|
4715
|
+
fail("STRUCTURED_OUTPUT_INVALID", "The response did not match the requested JSON schema.");
|
|
4716
|
+
return { data, response };
|
|
4717
|
+
};
|
|
4718
|
+
}
|
|
4719
|
+
async function parseStructuredResponse(response, format) {
|
|
4720
|
+
return (await createStructuredParser(format))(response);
|
|
4721
|
+
}
|
|
4722
|
+
|
|
4613
4723
|
// src/response-handle.ts
|
|
4614
4724
|
var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
4615
4725
|
var text = (value) => typeof value === "string" ? value : void 0;
|
|
@@ -6087,6 +6197,7 @@ function buildTurnRequest(request) {
|
|
|
6087
6197
|
...request.previousResponseId ? { previous_response_id: request.previousResponseId } : {},
|
|
6088
6198
|
...request.conversationId ? { conversation_ext_id: request.conversationId } : {},
|
|
6089
6199
|
...request.model && !pa2 ? { model: request.model } : {},
|
|
6200
|
+
...request.text ? { text: request.text } : {},
|
|
6090
6201
|
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
6091
6202
|
...request.bindDocumentId && !request.previousResponseId && !pa2 ? { bound_document_ext_id: request.bindDocumentId } : {},
|
|
6092
6203
|
...request.mentions && request.mentions.length > 0 ? { mentions: request.mentions } : {},
|
|
@@ -6374,6 +6485,7 @@ async function submitBackgroundQuery(options) {
|
|
|
6374
6485
|
docIds,
|
|
6375
6486
|
previousResponseId,
|
|
6376
6487
|
model,
|
|
6488
|
+
text: text2,
|
|
6377
6489
|
task,
|
|
6378
6490
|
conversationId,
|
|
6379
6491
|
mentions,
|
|
@@ -6409,7 +6521,8 @@ async function submitBackgroundQuery(options) {
|
|
|
6409
6521
|
...mentions !== void 0 ? { mentions } : {},
|
|
6410
6522
|
...activeArtifactExtId ? { active_artifact_ext_id: activeArtifactExtId } : {},
|
|
6411
6523
|
...previousResponseId ? { previous_response_id: previousResponseId } : {},
|
|
6412
|
-
...model ? { model } : {}
|
|
6524
|
+
...model ? { model } : {},
|
|
6525
|
+
...text2 ? { text: text2 } : {}
|
|
6413
6526
|
};
|
|
6414
6527
|
const res = await authenticatedFetch({
|
|
6415
6528
|
...auth,
|
|
@@ -11692,8 +11805,90 @@ var Arbi = class {
|
|
|
11692
11805
|
throw error;
|
|
11693
11806
|
}
|
|
11694
11807
|
}
|
|
11808
|
+
/** Canonical Responses-shaped requests; existing assistant convenience helpers remain supported. */
|
|
11809
|
+
responses = {
|
|
11810
|
+
create: async (request, options = {}) => {
|
|
11811
|
+
const response = await this.recovering(
|
|
11812
|
+
() => openTurnStream(
|
|
11813
|
+
this.getAuthHeaders(),
|
|
11814
|
+
{
|
|
11815
|
+
...request,
|
|
11816
|
+
workspace_ext_id: request.workspace_ext_id ?? this.requireWorkspace(),
|
|
11817
|
+
stream: false,
|
|
11818
|
+
background: request.background ?? false,
|
|
11819
|
+
store: request.store ?? true
|
|
11820
|
+
},
|
|
11821
|
+
options.signal
|
|
11822
|
+
)
|
|
11823
|
+
);
|
|
11824
|
+
let body;
|
|
11825
|
+
try {
|
|
11826
|
+
body = await response.text();
|
|
11827
|
+
} catch (cause) {
|
|
11828
|
+
throw transportError(cause);
|
|
11829
|
+
}
|
|
11830
|
+
try {
|
|
11831
|
+
return JSON.parse(body);
|
|
11832
|
+
} catch (cause) {
|
|
11833
|
+
throw new ArbiError("Expected a Responses JSON object.", {
|
|
11834
|
+
code: "RESPONSE_INVALID_ENVELOPE",
|
|
11835
|
+
cause,
|
|
11836
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
11837
|
+
});
|
|
11838
|
+
}
|
|
11839
|
+
},
|
|
11840
|
+
stream: (request, options = {}) => this.openResponseHandle(
|
|
11841
|
+
(signal) => openTurnStream(
|
|
11842
|
+
this.getAuthHeaders(),
|
|
11843
|
+
{
|
|
11844
|
+
...request,
|
|
11845
|
+
workspace_ext_id: request.workspace_ext_id ?? this.requireWorkspace(),
|
|
11846
|
+
stream: true,
|
|
11847
|
+
background: false,
|
|
11848
|
+
store: request.store ?? true
|
|
11849
|
+
},
|
|
11850
|
+
signal
|
|
11851
|
+
),
|
|
11852
|
+
options
|
|
11853
|
+
),
|
|
11854
|
+
retrieve: (id) => this.assistant.getResponse(id),
|
|
11855
|
+
cancel: (id) => this.assistant.cancel(id),
|
|
11856
|
+
attach: (id, options = {}) => this.assistant.attachResponse(id, options)
|
|
11857
|
+
};
|
|
11695
11858
|
// ── Assistant ─────────────────────────────────────────────────────────
|
|
11696
11859
|
assistant = {
|
|
11860
|
+
/** Create one synchronous Responses result and return validated JSON alongside the raw response. */
|
|
11861
|
+
parseResponse: async (request, options = {}) => {
|
|
11862
|
+
const parse = await createStructuredParser(request.text.format);
|
|
11863
|
+
const body = {
|
|
11864
|
+
...buildTurnRequest({
|
|
11865
|
+
...request,
|
|
11866
|
+
workspaceId: request.workspaceId ?? this.requireWorkspace()
|
|
11867
|
+
}),
|
|
11868
|
+
stream: false,
|
|
11869
|
+
background: false
|
|
11870
|
+
};
|
|
11871
|
+
const response = await this.recovering(
|
|
11872
|
+
() => openTurnStream(this.getAuthHeaders(), body, options.signal)
|
|
11873
|
+
);
|
|
11874
|
+
let rawText;
|
|
11875
|
+
try {
|
|
11876
|
+
rawText = await response.text();
|
|
11877
|
+
} catch (cause) {
|
|
11878
|
+
throw transportError(cause);
|
|
11879
|
+
}
|
|
11880
|
+
let raw;
|
|
11881
|
+
try {
|
|
11882
|
+
raw = JSON.parse(rawText);
|
|
11883
|
+
} catch (cause) {
|
|
11884
|
+
throw new ArbiStructuredOutputError("Expected a Responses JSON object.", rawText, {
|
|
11885
|
+
code: "RESPONSE_INVALID_ENVELOPE",
|
|
11886
|
+
cause,
|
|
11887
|
+
requestId: response.headers.get("x-request-id") ?? void 0
|
|
11888
|
+
});
|
|
11889
|
+
}
|
|
11890
|
+
return parse(raw, { requestId: response.headers.get("x-request-id") ?? void 0 });
|
|
11891
|
+
},
|
|
11697
11892
|
/** Start one response with a composable observer; existing ask callbacks remain unchanged. */
|
|
11698
11893
|
startResponse: async (request, options = {}) => {
|
|
11699
11894
|
const body = buildTurnRequest({
|
|
@@ -13258,10 +13453,60 @@ function getRunToAttach(localGeneration, messages) {
|
|
|
13258
13453
|
return getAttachableRunId(messages);
|
|
13259
13454
|
}
|
|
13260
13455
|
|
|
13456
|
+
// src/configuration.ts
|
|
13457
|
+
function composeConfiguration(base, ...patches) {
|
|
13458
|
+
const result = structuredClone(base);
|
|
13459
|
+
for (const patch of patches) {
|
|
13460
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
13461
|
+
if (value === void 0) continue;
|
|
13462
|
+
result[key] = value && typeof value === "object" && !Array.isArray(value) ? { ...result[key] ?? {}, ...structuredClone(value) } : structuredClone(value);
|
|
13463
|
+
}
|
|
13464
|
+
}
|
|
13465
|
+
return result;
|
|
13466
|
+
}
|
|
13467
|
+
function instructions(text2) {
|
|
13468
|
+
return { QueryLLM: { SYSTEM_INSTRUCTION: text2 }, Agents: { PERSONA: text2 } };
|
|
13469
|
+
}
|
|
13470
|
+
function capabilities(options) {
|
|
13471
|
+
const flags = {
|
|
13472
|
+
webSearch: "WEB_SEARCH_ENABLED",
|
|
13473
|
+
codeExecution: "RUN_CODE_ENABLED",
|
|
13474
|
+
planning: "PLANNING_ENABLED",
|
|
13475
|
+
deepResearch: "DEEP_RESEARCH_ENABLED",
|
|
13476
|
+
subagents: "SUBAGENTS_ENABLED",
|
|
13477
|
+
humanInput: "HUMAN_IN_THE_LOOP"
|
|
13478
|
+
};
|
|
13479
|
+
const Agents = {};
|
|
13480
|
+
for (const key of Object.keys(flags)) {
|
|
13481
|
+
if (options[key] !== void 0) Agents[flags[key]] = options[key];
|
|
13482
|
+
}
|
|
13483
|
+
return { Agents };
|
|
13484
|
+
}
|
|
13485
|
+
function mcpTools(base, names, mode) {
|
|
13486
|
+
return {
|
|
13487
|
+
Agents: {
|
|
13488
|
+
MCP_TOOLS: [
|
|
13489
|
+
.../* @__PURE__ */ new Set([...mode === "add" ? base.Agents?.MCP_TOOLS ?? [] : [], ...names])
|
|
13490
|
+
]
|
|
13491
|
+
}
|
|
13492
|
+
};
|
|
13493
|
+
}
|
|
13494
|
+
function documentTools(options) {
|
|
13495
|
+
return {
|
|
13496
|
+
...options.search ? { retrieval_chunk: buildRetrievalChunkTool([...options.search]) } : {},
|
|
13497
|
+
...options.fullContext ? { retrieval_full_context: buildRetrievalFullContextTool([...options.fullContext]) } : {},
|
|
13498
|
+
...options.tableOfContents ? { retrieval_toc: buildRetrievalTocTool([...options.tableOfContents]) } : {}
|
|
13499
|
+
};
|
|
13500
|
+
}
|
|
13501
|
+
function composeTools(base, next, mode) {
|
|
13502
|
+
return structuredClone(mode === "add" ? { ...base, ...next } : next);
|
|
13503
|
+
}
|
|
13504
|
+
|
|
13261
13505
|
exports.ACCOUNT_VENDOR = ACCOUNT_VENDOR;
|
|
13262
13506
|
exports.Arbi = Arbi;
|
|
13263
13507
|
exports.ArbiApiError = ArbiApiError;
|
|
13264
13508
|
exports.ArbiError = ArbiError;
|
|
13509
|
+
exports.ArbiStructuredOutputError = ArbiStructuredOutputError;
|
|
13265
13510
|
exports.ArbiTransportError = ArbiTransportError;
|
|
13266
13511
|
exports.ArbiWorkspaceChangedError = ArbiWorkspaceChangedError;
|
|
13267
13512
|
exports.ArbiWorkspaceSupersededError = ArbiWorkspaceSupersededError;
|
|
@@ -13303,7 +13548,10 @@ exports.calendar = calendar_exports;
|
|
|
13303
13548
|
exports.calls = calls_exports;
|
|
13304
13549
|
exports.canTagHaveParent = canTagHaveParent;
|
|
13305
13550
|
exports.cancelPublicBooking = cancelPublicBooking;
|
|
13551
|
+
exports.capabilities = capabilities;
|
|
13306
13552
|
exports.chats = chats_exports;
|
|
13553
|
+
exports.composeConfiguration = composeConfiguration;
|
|
13554
|
+
exports.composeTools = composeTools;
|
|
13307
13555
|
exports.computeRunStats = computeRunStats;
|
|
13308
13556
|
exports.connectErrorMessage = connectErrorMessage;
|
|
13309
13557
|
exports.connectWebSocket = connectWebSocket;
|
|
@@ -13318,6 +13566,7 @@ exports.createIndexAssigner = createIndexAssigner;
|
|
|
13318
13566
|
exports.databases = databases_exports;
|
|
13319
13567
|
exports.defaultKindForFormat = defaultKindForFormat;
|
|
13320
13568
|
exports.doctags = doctags_exports;
|
|
13569
|
+
exports.documentTools = documentTools;
|
|
13321
13570
|
exports.documents = documents_exports;
|
|
13322
13571
|
exports.estimateDraftTokens = estimateDraftTokens;
|
|
13323
13572
|
exports.extractDocumentIdsFromMessages = extractDocumentIdsFromMessages;
|
|
@@ -13362,6 +13611,7 @@ exports.houseTemplates = house_template_exports;
|
|
|
13362
13611
|
exports.hydrateAgentSteps = hydrateAgentSteps;
|
|
13363
13612
|
exports.identityErrorCode = identityErrorCode;
|
|
13364
13613
|
exports.identityVerification = identity_exports;
|
|
13614
|
+
exports.instructions = instructions;
|
|
13365
13615
|
exports.isAnnotationTag = isAnnotationTag;
|
|
13366
13616
|
exports.isConnectorVendorVisible = isConnectorVendorVisible;
|
|
13367
13617
|
exports.isDriveSyncVendor = isDriveSyncVendor;
|
|
@@ -13375,11 +13625,13 @@ exports.isSharePointVendor = isSharePointVendor;
|
|
|
13375
13625
|
exports.isSharedSkill = isSharedSkill;
|
|
13376
13626
|
exports.isTraceItem = isTraceItem;
|
|
13377
13627
|
exports.mail = mail_exports;
|
|
13628
|
+
exports.mcpTools = mcpTools;
|
|
13378
13629
|
exports.mergeAgentSteps = mergeAgentSteps;
|
|
13379
13630
|
exports.notifications = notifications_exports;
|
|
13380
13631
|
exports.parseSSEEvents = parseSSEEvents;
|
|
13381
13632
|
exports.parseSlashCommand = parseSlashCommand;
|
|
13382
13633
|
exports.parseSlashTokenInProgress = parseSlashTokenInProgress;
|
|
13634
|
+
exports.parseStructuredResponse = parseStructuredResponse;
|
|
13383
13635
|
exports.performPasswordLogin = performPasswordLogin;
|
|
13384
13636
|
exports.pickMainThread = pickMainThread;
|
|
13385
13637
|
exports.profile = profile_exports;
|