@bobannomi/client 0.3.1 → 0.5.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 +15 -2
- package/dist/index.js +23 -0
- package/dist/index.js.map +2 -2
- package/dist/service.js +35 -0
- package/dist/service.js.map +2 -2
- package/package.json +2 -2
package/dist/service.js
CHANGED
|
@@ -3524,6 +3524,12 @@ var BobanNomiApiError = class extends Error {
|
|
|
3524
3524
|
this.status = status;
|
|
3525
3525
|
this.body = body;
|
|
3526
3526
|
this.name = "BobanNomiApiError";
|
|
3527
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return;
|
|
3528
|
+
const { code, error } = body;
|
|
3529
|
+
const machineCode = [code, error].find(
|
|
3530
|
+
(value) => typeof value === "string" && /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/.test(value)
|
|
3531
|
+
);
|
|
3532
|
+
if (machineCode !== void 0) this.code = machineCode;
|
|
3527
3533
|
}
|
|
3528
3534
|
status;
|
|
3529
3535
|
body;
|
|
@@ -4131,6 +4137,18 @@ function getVisibleSessionMessages(bucket) {
|
|
|
4131
4137
|
({ message, parts }) => parts.length > 0 || message.role !== "assistant"
|
|
4132
4138
|
);
|
|
4133
4139
|
}
|
|
4140
|
+
function selectSessionInputs(bucket) {
|
|
4141
|
+
if (!bucket) return [];
|
|
4142
|
+
return [...bucket.inputs].sort((a, b) => a.seq - b.seq);
|
|
4143
|
+
}
|
|
4144
|
+
function selectSessionRuns(bucket) {
|
|
4145
|
+
if (!bucket) return [];
|
|
4146
|
+
return Object.values(bucket.runs);
|
|
4147
|
+
}
|
|
4148
|
+
function selectSessionPermissions(bucket) {
|
|
4149
|
+
if (!bucket) return [];
|
|
4150
|
+
return Object.values(bucket.permissions);
|
|
4151
|
+
}
|
|
4134
4152
|
|
|
4135
4153
|
// src/state/reducer.ts
|
|
4136
4154
|
var UnsupportedSessionEventSchemaVersionError = class extends Error {
|
|
@@ -4616,6 +4634,7 @@ async function* runEventSync(client, options, initialState = createClientState()
|
|
|
4616
4634
|
if (error instanceof UnsupportedSessionEventSchemaVersionError) throw error;
|
|
4617
4635
|
if (isAbortError(error) || signal?.aborted) return;
|
|
4618
4636
|
if (options.shouldRetry?.(error) === false) throw error;
|
|
4637
|
+
if (error && typeof error === "object" && "code" in error && error.code === "connection_revoked") throw error;
|
|
4619
4638
|
if (error instanceof BobanNomiApiError && error.status >= 400 && error.status < 500 && ![408, 425, 429].includes(error.status)) throw error;
|
|
4620
4639
|
}
|
|
4621
4640
|
if (signal?.aborted) return;
|
|
@@ -4647,6 +4666,20 @@ function isAbortError(error) {
|
|
|
4647
4666
|
return Boolean(error && typeof error === "object" && "name" in error && error.name === "AbortError");
|
|
4648
4667
|
}
|
|
4649
4668
|
|
|
4669
|
+
// src/state/session-observation.ts
|
|
4670
|
+
async function* observeSession(client, options) {
|
|
4671
|
+
for await (const { source, state } of syncEvents(client, options)) {
|
|
4672
|
+
const bucket = state.buckets[options.sessionId];
|
|
4673
|
+
yield {
|
|
4674
|
+
source,
|
|
4675
|
+
messages: getVisibleSessionMessages(bucket),
|
|
4676
|
+
inputs: selectSessionInputs(bucket),
|
|
4677
|
+
runs: selectSessionRuns(bucket),
|
|
4678
|
+
permissions: selectSessionPermissions(bucket)
|
|
4679
|
+
};
|
|
4680
|
+
}
|
|
4681
|
+
}
|
|
4682
|
+
|
|
4650
4683
|
// src/state/wait-for-run.ts
|
|
4651
4684
|
async function waitForRun(client, options) {
|
|
4652
4685
|
options.signal?.throwIfAborted();
|
|
@@ -4932,6 +4965,7 @@ function createSessionHandle(transport, syncClient, management, sessionId, prepa
|
|
|
4932
4965
|
}
|
|
4933
4966
|
return {
|
|
4934
4967
|
id: sessionId,
|
|
4968
|
+
observe: (options) => observeSession(syncClient, { ...options, sessionId }),
|
|
4935
4969
|
waitForRun: (runId, options) => waitForRun(syncClient, { sessionId, runId, signal: options?.signal }),
|
|
4936
4970
|
async updateAppMetadata(metadata, options) {
|
|
4937
4971
|
const body = parseUpdateSessionRequest({ metadata: { app: metadata } });
|
|
@@ -5200,6 +5234,7 @@ var SessionResource = class {
|
|
|
5200
5234
|
#transport;
|
|
5201
5235
|
/** Bind a session ID locally. Operations use this resource's daemon connection when called. */
|
|
5202
5236
|
byId(sessionId) {
|
|
5237
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) throw new TypeError("sessionId is required");
|
|
5203
5238
|
return createSessionHandle(this.#transport, { sessions: this, events: this.#events }, this.#management, sessionId, this.prepareModel);
|
|
5204
5239
|
}
|
|
5205
5240
|
/** `GET /sessions/search` - search saved conversation text without opening it. */
|