@bobannomi/client 0.3.0 → 0.3.1
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 +2 -2
- package/dist/index.d.ts +33 -6
- package/dist/index.js +95 -27
- package/dist/index.js.map +2 -2
- package/dist/service.js +95 -27
- package/dist/service.js.map +2 -2
- package/package.json +4 -4
package/dist/service.js
CHANGED
|
@@ -2198,16 +2198,25 @@ function validateSessionId(id2) {
|
|
|
2198
2198
|
}
|
|
2199
2199
|
function parseCreateSessionRequest(value) {
|
|
2200
2200
|
const body = record3(value);
|
|
2201
|
-
fields2(body, ["id", "requestId", "cwd", "projectId", "title", "storage", "configuration", "optionsRevision", "metadata"]);
|
|
2201
|
+
fields2(body, ["id", "requestId", "cwd", "projectId", "workspaceId", "outsideProject", "title", "storage", "configuration", "optionsRevision", "metadata"]);
|
|
2202
2202
|
const cwd = optionalString2(body, "cwd");
|
|
2203
|
+
const workspaceId = optionalString2(body, "workspaceId");
|
|
2204
|
+
const outsideProject = optionalBoolean2(body, "outsideProject");
|
|
2203
2205
|
const id2 = validateSessionId(requiredString2(body, "id"));
|
|
2204
2206
|
const requestId = requiredString2(body, "requestId");
|
|
2205
2207
|
if (cwd !== void 0 && !cwd.trim()) throw new ProtocolValidationError("cwd cannot be empty", "cwd");
|
|
2206
2208
|
if (!requestId.trim()) throw new ProtocolValidationError("requestId cannot be empty", "requestId");
|
|
2207
|
-
|
|
2208
|
-
if (
|
|
2209
|
+
if (workspaceId !== void 0 && !workspaceId.trim()) throw new ProtocolValidationError("workspaceId cannot be empty", "workspaceId");
|
|
2210
|
+
if (outsideProject === false || outsideProject === true && workspaceId !== void 0)
|
|
2211
|
+
throw new ProtocolValidationError("outsideProject must be true and used without workspaceId", "outsideProject");
|
|
2212
|
+
if ((outsideProject === true || workspaceId !== void 0) && (cwd !== void 0 || body.projectId !== void 0))
|
|
2213
|
+
throw new ProtocolValidationError("Supply one session directory choice", outsideProject === true ? "outsideProject" : "workspaceId");
|
|
2214
|
+
const projectId = optionalString2(body, "projectId");
|
|
2215
|
+
if (cwd === void 0 && outsideProject === void 0 && workspaceId === void 0 && !projectId?.trim())
|
|
2216
|
+
throw new ProtocolValidationError("projectId cannot be empty", "projectId");
|
|
2217
|
+
const target = workspaceId !== void 0 ? { workspaceId } : outsideProject === true ? { outsideProject } : cwd !== void 0 ? { cwd, ...projectId === void 0 ? {} : { projectId } } : { projectId };
|
|
2209
2218
|
const result = { id: id2, requestId, ...target };
|
|
2210
|
-
for (const key of ["
|
|
2219
|
+
for (const key of ["title", "optionsRevision"]) if (body[key] !== void 0) result[key] = optionalString2(body, key);
|
|
2211
2220
|
if (body.storage !== void 0) result.storage = optionalEnum2(body, "storage", ["sqlite", "memory"]);
|
|
2212
2221
|
if (body.configuration !== void 0) result.configuration = parseSessionConfiguration2(body.configuration);
|
|
2213
2222
|
if (body.metadata !== void 0) result.metadata = appMetadata(optionalRecord(body, "metadata"));
|
|
@@ -3943,18 +3952,25 @@ async function getDraftComposerOptions(transport, input, options = {}) {
|
|
|
3943
3952
|
}
|
|
3944
3953
|
return result;
|
|
3945
3954
|
}
|
|
3946
|
-
async function create(transport, input, options = {}) {
|
|
3955
|
+
async function create(transport, input, options = {}, prepareModel) {
|
|
3947
3956
|
const body = parseCreateSessionRequest({
|
|
3948
3957
|
...input,
|
|
3949
3958
|
id: input.id ?? createSessionRequestId(),
|
|
3950
3959
|
requestId: input.requestId ?? createSessionRequestId()
|
|
3951
3960
|
});
|
|
3952
|
-
if (body.
|
|
3961
|
+
if (body.workspaceId !== void 0 || body.outsideProject)
|
|
3962
|
+
await requireDaemonFeature(transport, "sessionDirectoryCreation", options.signal);
|
|
3963
|
+
else if (body.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
|
|
3964
|
+
const modelConnection = await prepareModel?.(body.id, body.configuration?.model, options.signal);
|
|
3953
3965
|
const response = await transport.request(
|
|
3954
3966
|
"/sessions",
|
|
3955
3967
|
{
|
|
3956
3968
|
method: "POST",
|
|
3957
3969
|
body,
|
|
3970
|
+
headers: {
|
|
3971
|
+
...body.workspaceId === void 0 ? {} : { "x-bobannomi-workspace-id": body.workspaceId },
|
|
3972
|
+
...modelConnection === void 0 ? {} : { "x-bobannomi-model-connection": modelConnection }
|
|
3973
|
+
},
|
|
3958
3974
|
signal: options.signal
|
|
3959
3975
|
}
|
|
3960
3976
|
);
|
|
@@ -3968,7 +3984,9 @@ async function getConfigurationOptions(transport, input, options = {}) {
|
|
|
3968
3984
|
);
|
|
3969
3985
|
}
|
|
3970
3986
|
async function getCreationResult(transport, input, options = {}) {
|
|
3971
|
-
if (input.original.
|
|
3987
|
+
if (input.original.workspaceId !== void 0 || input.original.outsideProject)
|
|
3988
|
+
await requireDaemonFeature(transport, "sessionDirectoryCreation", options.signal);
|
|
3989
|
+
else if (input.original.cwd === void 0) await requireDaemonFeature(transport, "projectSessionCreation", options.signal);
|
|
3972
3990
|
return transport.request("/sessions/creation-result", {
|
|
3973
3991
|
method: "POST",
|
|
3974
3992
|
body: input,
|
|
@@ -3982,11 +4000,17 @@ async function getConfiguration(transport, sessionId, options = {}) {
|
|
|
3982
4000
|
);
|
|
3983
4001
|
return decodeSessionConfigurationSnapshot(value);
|
|
3984
4002
|
}
|
|
3985
|
-
async function configure(transport, sessionId, input, options = {}) {
|
|
4003
|
+
async function configure(transport, sessionId, input, options = {}, prepareModel) {
|
|
3986
4004
|
const body = parseConfigureSessionRequest(input);
|
|
4005
|
+
const modelConnection = await prepareModel?.(sessionId, body.configuration.model, options.signal);
|
|
3987
4006
|
const response = await transport.requestUnknown(
|
|
3988
4007
|
`/sessions/${encodeURIComponent(sessionId)}/configure`,
|
|
3989
|
-
{
|
|
4008
|
+
{
|
|
4009
|
+
method: "POST",
|
|
4010
|
+
body,
|
|
4011
|
+
signal: options.signal,
|
|
4012
|
+
...modelConnection === void 0 ? {} : { headers: { "x-bobannomi-model-connection": modelConnection } }
|
|
4013
|
+
}
|
|
3990
4014
|
);
|
|
3991
4015
|
return decodeSessionConfigurationReceipt(response, {
|
|
3992
4016
|
sessionId,
|
|
@@ -4896,7 +4920,7 @@ async function interrupt(transport, sessionId, options = {}) {
|
|
|
4896
4920
|
}
|
|
4897
4921
|
|
|
4898
4922
|
// src/resources/session/session-handle.ts
|
|
4899
|
-
function createSessionHandle(transport, syncClient, management, sessionId) {
|
|
4923
|
+
function createSessionHandle(transport, syncClient, management, sessionId, prepareModel) {
|
|
4900
4924
|
function cancelQueuedPrompt2(inputId, input, options) {
|
|
4901
4925
|
return cancelQueuedPrompt(transport, sessionId, inputId, input, options);
|
|
4902
4926
|
}
|
|
@@ -5057,7 +5081,7 @@ function createSessionHandle(transport, syncClient, management, sessionId) {
|
|
|
5057
5081
|
return getConfiguration(transport, sessionId, options);
|
|
5058
5082
|
},
|
|
5059
5083
|
update(input, options = {}) {
|
|
5060
|
-
return configure(transport, sessionId, input, options);
|
|
5084
|
+
return configure(transport, sessionId, input, options, prepareModel);
|
|
5061
5085
|
},
|
|
5062
5086
|
getResult(input, options = {}) {
|
|
5063
5087
|
return getConfigurationResult(transport, sessionId, input, options);
|
|
@@ -5164,17 +5188,19 @@ function createSessionHandle(transport, syncClient, management, sessionId) {
|
|
|
5164
5188
|
|
|
5165
5189
|
// src/resources/session/session-resource.ts
|
|
5166
5190
|
var SessionResource = class {
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
#transport;
|
|
5170
|
-
constructor(transport, events) {
|
|
5191
|
+
constructor(transport, events, prepareModel) {
|
|
5192
|
+
this.prepareModel = prepareModel;
|
|
5171
5193
|
this.#transport = transport;
|
|
5172
5194
|
this.#management = new SessionManagementResource(transport);
|
|
5173
5195
|
this.#events = events ?? new EventResource(transport, new SseTransport(transport));
|
|
5174
5196
|
}
|
|
5197
|
+
prepareModel;
|
|
5198
|
+
#management;
|
|
5199
|
+
#events;
|
|
5200
|
+
#transport;
|
|
5175
5201
|
/** Bind a session ID locally. Operations use this resource's daemon connection when called. */
|
|
5176
5202
|
byId(sessionId) {
|
|
5177
|
-
return createSessionHandle(this.#transport, { sessions: this, events: this.#events }, this.#management, sessionId);
|
|
5203
|
+
return createSessionHandle(this.#transport, { sessions: this, events: this.#events }, this.#management, sessionId, this.prepareModel);
|
|
5178
5204
|
}
|
|
5179
5205
|
/** `GET /sessions/search` - search saved conversation text without opening it. */
|
|
5180
5206
|
async search(options) {
|
|
@@ -5205,7 +5231,7 @@ var SessionResource = class {
|
|
|
5205
5231
|
}
|
|
5206
5232
|
/** `POST /sessions` */
|
|
5207
5233
|
create(input, options = {}) {
|
|
5208
|
-
return create(this.#transport, input, options);
|
|
5234
|
+
return create(this.#transport, input, options, this.prepareModel);
|
|
5209
5235
|
}
|
|
5210
5236
|
getConfigurationOptions(input, options = {}) {
|
|
5211
5237
|
return getConfigurationOptions(this.#transport, input, options);
|
|
@@ -5328,7 +5354,54 @@ var PermissionResource = class {
|
|
|
5328
5354
|
|
|
5329
5355
|
// src/resources/runtime/runtime-resource.ts
|
|
5330
5356
|
function createRuntimeResources(transport, providers) {
|
|
5331
|
-
const catalog = typeof providers === "function" || providers === void 0 ? providers :
|
|
5357
|
+
const catalog = typeof providers === "function" || providers === void 0 ? providers : providers.map(({ connection, ...provider2 }) => ({
|
|
5358
|
+
...structuredClone(provider2),
|
|
5359
|
+
connection: typeof connection === "function" ? connection : structuredClone(connection)
|
|
5360
|
+
}));
|
|
5361
|
+
async function load(source, signal) {
|
|
5362
|
+
signal?.throwIfAborted();
|
|
5363
|
+
const value = await waitForRequest(Promise.resolve().then(() => {
|
|
5364
|
+
signal?.throwIfAborted();
|
|
5365
|
+
return source({ signal });
|
|
5366
|
+
}), signal);
|
|
5367
|
+
signal?.throwIfAborted();
|
|
5368
|
+
return value;
|
|
5369
|
+
}
|
|
5370
|
+
function readCatalog(signal) {
|
|
5371
|
+
signal?.throwIfAborted();
|
|
5372
|
+
return typeof catalog === "function" ? load(catalog, signal) : Promise.resolve(catalog ?? []);
|
|
5373
|
+
}
|
|
5374
|
+
const prepareModel = catalog === void 0 ? void 0 : async (sessionId, selection, signal) => {
|
|
5375
|
+
if (!selection) return;
|
|
5376
|
+
const provider2 = (await readCatalog(signal)).find(({ name }) => name === selection.provider);
|
|
5377
|
+
if (!provider2?.connection) return;
|
|
5378
|
+
if (!provider2.models.some(({ id: id2 }) => id2 === selection.model)) throw new Error("The selected model is not in the supplied provider catalog");
|
|
5379
|
+
await requireDaemonFeature(transport, "sessionModelConnections", signal);
|
|
5380
|
+
const connection = typeof provider2.connection === "function" ? await load(provider2.connection, signal) : provider2.connection;
|
|
5381
|
+
const { ref } = await transport.request("/model-connections", {
|
|
5382
|
+
method: "POST",
|
|
5383
|
+
signal,
|
|
5384
|
+
body: {
|
|
5385
|
+
sessionId,
|
|
5386
|
+
provider: {
|
|
5387
|
+
id: provider2.name,
|
|
5388
|
+
displayName: provider2.displayName,
|
|
5389
|
+
baseUrl: connection.baseUrl,
|
|
5390
|
+
apiKey: connection.apiKey,
|
|
5391
|
+
apiFormat: connection.apiFormat,
|
|
5392
|
+
models: provider2.models.map(({ id: id2, label, contextWindow, outputLimit, inputCapabilities }) => ({
|
|
5393
|
+
id: id2,
|
|
5394
|
+
displayName: label,
|
|
5395
|
+
contextWindow,
|
|
5396
|
+
maxOutputTokens: outputLimit,
|
|
5397
|
+
imageInputSupport: inputCapabilities?.image
|
|
5398
|
+
}))
|
|
5399
|
+
}
|
|
5400
|
+
}
|
|
5401
|
+
});
|
|
5402
|
+
if (typeof ref !== "string" || !ref) throw new Error("Invalid prepared model connection");
|
|
5403
|
+
return ref;
|
|
5404
|
+
};
|
|
5332
5405
|
async function modelProviders(input, options = {}) {
|
|
5333
5406
|
const response = await transport.request("/providers/manage", { ...options, method: "POST", body: input });
|
|
5334
5407
|
if (!validModelProviderConnections(response?.providers)) throw new Error("Invalid model provider response");
|
|
@@ -5341,19 +5414,14 @@ function createRuntimeResources(transport, providers) {
|
|
|
5341
5414
|
return result;
|
|
5342
5415
|
}
|
|
5343
5416
|
return {
|
|
5417
|
+
prepareModel,
|
|
5344
5418
|
models: {
|
|
5345
5419
|
async list({ signal } = {}) {
|
|
5346
5420
|
if (catalog === void 0) {
|
|
5347
5421
|
const response = await transport.request("/models", { signal });
|
|
5348
5422
|
return response.providers;
|
|
5349
5423
|
}
|
|
5350
|
-
signal
|
|
5351
|
-
const providers2 = typeof catalog === "function" ? await waitForRequest(Promise.resolve().then(() => {
|
|
5352
|
-
signal?.throwIfAborted();
|
|
5353
|
-
return catalog({ signal });
|
|
5354
|
-
}), signal) : catalog;
|
|
5355
|
-
signal?.throwIfAborted();
|
|
5356
|
-
return structuredClone([...providers2]);
|
|
5424
|
+
return (await readCatalog(signal)).map(({ name, displayName, models }) => structuredClone({ name, displayName, models }));
|
|
5357
5425
|
}
|
|
5358
5426
|
},
|
|
5359
5427
|
agents: {
|
|
@@ -6256,7 +6324,7 @@ var BobanNomiClient = class {
|
|
|
6256
6324
|
const sse = new SseTransport(transport);
|
|
6257
6325
|
this.protocol = new ProtocolClient(transport);
|
|
6258
6326
|
const providers = options instanceof HttpTransport ? void 0 : options.providers;
|
|
6259
|
-
const { models, modelProviders, agents, skills } = createRuntimeResources(transport, providers);
|
|
6327
|
+
const { models, modelProviders, agents, skills, prepareModel } = createRuntimeResources(transport, providers);
|
|
6260
6328
|
this.models = models;
|
|
6261
6329
|
this.modelProviders = modelProviders;
|
|
6262
6330
|
this.agents = agents;
|
|
@@ -6265,7 +6333,7 @@ var BobanNomiClient = class {
|
|
|
6265
6333
|
this.attachments = new AttachmentResource(transport);
|
|
6266
6334
|
this.permissions = new PermissionResource(transport);
|
|
6267
6335
|
this.events = new EventResource(transport, sse);
|
|
6268
|
-
this.sessions = new SessionResource(transport, this.events);
|
|
6336
|
+
this.sessions = new SessionResource(transport, this.events, prepareModel);
|
|
6269
6337
|
this.plugins = new PluginResource(transport);
|
|
6270
6338
|
this.channels = new ChannelResource(transport);
|
|
6271
6339
|
this.projects = new ProjectResource(transport);
|