@bobannomi/client 0.3.1 → 0.6.0
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 +5 -3
- package/dist/index.d.ts +18 -43
- package/dist/index.js +34 -118
- package/dist/index.js.map +3 -3
- package/dist/service.js +46 -6
- package/dist/service.js.map +2 -2
- package/package.json +2 -2
package/dist/service.js
CHANGED
|
@@ -2072,9 +2072,6 @@ var PLUGIN_APP_DATA_LIMITS = Object.freeze({ maxArgsBytes: 64 * 1024 * 1024, jso
|
|
|
2072
2072
|
// ../domain-contracts/src/plugin-apps/limits.ts
|
|
2073
2073
|
var PLUGIN_APP_INPUT_LIMITS = Object.freeze({ handoffBytes: 32 * 1024, messageCharacters: 4096, maxComposerContexts: 8 });
|
|
2074
2074
|
|
|
2075
|
-
// ../domain-contracts/src/plugin-apps/history.ts
|
|
2076
|
-
var PLUGIN_UI_LIMITS = { dataBytes: 256 * 1024, actionArgsBytes: 64 * 1024 };
|
|
2077
|
-
|
|
2078
2075
|
// ../protocol/src/serialization/json.ts
|
|
2079
2076
|
function isUuid(value) {
|
|
2080
2077
|
return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(
|
|
@@ -3519,14 +3516,22 @@ var ProtocolClient = class {
|
|
|
3519
3516
|
|
|
3520
3517
|
// src/transport/http-transport.ts
|
|
3521
3518
|
var BobanNomiApiError = class extends Error {
|
|
3522
|
-
constructor(message, status, body) {
|
|
3519
|
+
constructor(message, status, body, traceId) {
|
|
3523
3520
|
super(message);
|
|
3524
3521
|
this.status = status;
|
|
3525
3522
|
this.body = body;
|
|
3523
|
+
this.traceId = traceId;
|
|
3526
3524
|
this.name = "BobanNomiApiError";
|
|
3525
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return;
|
|
3526
|
+
const { code, error } = body;
|
|
3527
|
+
const machineCode = [code, error].find(
|
|
3528
|
+
(value) => typeof value === "string" && /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/.test(value)
|
|
3529
|
+
);
|
|
3530
|
+
if (machineCode !== void 0) this.code = machineCode;
|
|
3527
3531
|
}
|
|
3528
3532
|
status;
|
|
3529
3533
|
body;
|
|
3534
|
+
traceId;
|
|
3530
3535
|
};
|
|
3531
3536
|
function responseField(value, field) {
|
|
3532
3537
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -3603,14 +3608,20 @@ function assertPositiveSafeInteger(value, field) {
|
|
|
3603
3608
|
}
|
|
3604
3609
|
}
|
|
3605
3610
|
async function throwResponseError(response) {
|
|
3611
|
+
const traceHeader = response.headers.get("x-bobannomi-trace-id");
|
|
3612
|
+
const traceId = traceHeader && /^[A-Za-z0-9._:-]{1,128}$/.test(traceHeader) ? traceHeader : void 0;
|
|
3606
3613
|
const text3 = await response.text().catch(() => "");
|
|
3607
3614
|
let body = text3;
|
|
3608
3615
|
try {
|
|
3609
3616
|
body = JSON.parse(text3);
|
|
3610
3617
|
} catch {
|
|
3611
3618
|
}
|
|
3612
|
-
|
|
3613
|
-
|
|
3619
|
+
let message = `BobanNomi API request failed with ${response.status}`;
|
|
3620
|
+
if (body && typeof body === "object") {
|
|
3621
|
+
if ("message" in body && typeof body.message === "string") message = body.message;
|
|
3622
|
+
else if ("error" in body && typeof body.error === "string") message = body.error;
|
|
3623
|
+
}
|
|
3624
|
+
throw new BobanNomiApiError(message, response.status, body, traceId);
|
|
3614
3625
|
}
|
|
3615
3626
|
var HttpTransport = class {
|
|
3616
3627
|
protocolHandshake;
|
|
@@ -4131,6 +4142,18 @@ function getVisibleSessionMessages(bucket) {
|
|
|
4131
4142
|
({ message, parts }) => parts.length > 0 || message.role !== "assistant"
|
|
4132
4143
|
);
|
|
4133
4144
|
}
|
|
4145
|
+
function selectSessionInputs(bucket) {
|
|
4146
|
+
if (!bucket) return [];
|
|
4147
|
+
return [...bucket.inputs].sort((a, b) => a.seq - b.seq);
|
|
4148
|
+
}
|
|
4149
|
+
function selectSessionRuns(bucket) {
|
|
4150
|
+
if (!bucket) return [];
|
|
4151
|
+
return Object.values(bucket.runs);
|
|
4152
|
+
}
|
|
4153
|
+
function selectSessionPermissions(bucket) {
|
|
4154
|
+
if (!bucket) return [];
|
|
4155
|
+
return Object.values(bucket.permissions);
|
|
4156
|
+
}
|
|
4134
4157
|
|
|
4135
4158
|
// src/state/reducer.ts
|
|
4136
4159
|
var UnsupportedSessionEventSchemaVersionError = class extends Error {
|
|
@@ -4616,6 +4639,7 @@ async function* runEventSync(client, options, initialState = createClientState()
|
|
|
4616
4639
|
if (error instanceof UnsupportedSessionEventSchemaVersionError) throw error;
|
|
4617
4640
|
if (isAbortError(error) || signal?.aborted) return;
|
|
4618
4641
|
if (options.shouldRetry?.(error) === false) throw error;
|
|
4642
|
+
if (error && typeof error === "object" && "code" in error && error.code === "connection_revoked") throw error;
|
|
4619
4643
|
if (error instanceof BobanNomiApiError && error.status >= 400 && error.status < 500 && ![408, 425, 429].includes(error.status)) throw error;
|
|
4620
4644
|
}
|
|
4621
4645
|
if (signal?.aborted) return;
|
|
@@ -4647,6 +4671,20 @@ function isAbortError(error) {
|
|
|
4647
4671
|
return Boolean(error && typeof error === "object" && "name" in error && error.name === "AbortError");
|
|
4648
4672
|
}
|
|
4649
4673
|
|
|
4674
|
+
// src/state/session-observation.ts
|
|
4675
|
+
async function* observeSession(client, options) {
|
|
4676
|
+
for await (const { source, state } of syncEvents(client, options)) {
|
|
4677
|
+
const bucket = state.buckets[options.sessionId];
|
|
4678
|
+
yield {
|
|
4679
|
+
source,
|
|
4680
|
+
messages: getVisibleSessionMessages(bucket),
|
|
4681
|
+
inputs: selectSessionInputs(bucket),
|
|
4682
|
+
runs: selectSessionRuns(bucket),
|
|
4683
|
+
permissions: selectSessionPermissions(bucket)
|
|
4684
|
+
};
|
|
4685
|
+
}
|
|
4686
|
+
}
|
|
4687
|
+
|
|
4650
4688
|
// src/state/wait-for-run.ts
|
|
4651
4689
|
async function waitForRun(client, options) {
|
|
4652
4690
|
options.signal?.throwIfAborted();
|
|
@@ -4932,6 +4970,7 @@ function createSessionHandle(transport, syncClient, management, sessionId, prepa
|
|
|
4932
4970
|
}
|
|
4933
4971
|
return {
|
|
4934
4972
|
id: sessionId,
|
|
4973
|
+
observe: (options) => observeSession(syncClient, { ...options, sessionId }),
|
|
4935
4974
|
waitForRun: (runId, options) => waitForRun(syncClient, { sessionId, runId, signal: options?.signal }),
|
|
4936
4975
|
async updateAppMetadata(metadata, options) {
|
|
4937
4976
|
const body = parseUpdateSessionRequest({ metadata: { app: metadata } });
|
|
@@ -5200,6 +5239,7 @@ var SessionResource = class {
|
|
|
5200
5239
|
#transport;
|
|
5201
5240
|
/** Bind a session ID locally. Operations use this resource's daemon connection when called. */
|
|
5202
5241
|
byId(sessionId) {
|
|
5242
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) throw new TypeError("sessionId is required");
|
|
5203
5243
|
return createSessionHandle(this.#transport, { sessions: this, events: this.#events }, this.#management, sessionId, this.prepareModel);
|
|
5204
5244
|
}
|
|
5205
5245
|
/** `GET /sessions/search` - search saved conversation text without opening it. */
|