@bobannomi/client 0.8.0 → 0.8.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 +18 -2
- package/dist/index.d.ts +282 -120
- package/dist/index.js +141 -24
- package/dist/index.js.map +3 -3
- package/dist/service.js +149 -32
- package/dist/service.js.map +3 -3
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
// ../plugin-contracts/src/manifest/desktop.ts
|
|
2
|
+
var DESKTOP_COMPOSER_PLACEMENTS = [
|
|
3
|
+
"composer.above",
|
|
4
|
+
"composer.toolbar.left",
|
|
5
|
+
"composer.toolbar.right"
|
|
6
|
+
];
|
|
7
|
+
var DESKTOP_PLACEMENTS = [
|
|
8
|
+
"start.visual",
|
|
9
|
+
"shell.floating",
|
|
10
|
+
"appearance.theme",
|
|
11
|
+
"shell.brand",
|
|
12
|
+
"conversation.view",
|
|
13
|
+
"tools.panel",
|
|
14
|
+
"conversation.header.actions",
|
|
15
|
+
...DESKTOP_COMPOSER_PLACEMENTS,
|
|
16
|
+
"settings.extension",
|
|
17
|
+
"main.page"
|
|
18
|
+
];
|
|
19
|
+
|
|
1
20
|
// ../domain-contracts/src/sessions/records.ts
|
|
2
21
|
var SESSION_EVENT_SCHEMA_VERSION = 1;
|
|
3
22
|
var SESSION_EVENT_SCHEMA_VERSIONS = {
|
|
@@ -1528,7 +1547,7 @@ function parseAttachmentUploadRequest(value) {
|
|
|
1528
1547
|
}
|
|
1529
1548
|
|
|
1530
1549
|
// ../protocol/src/runtime/capabilities.ts
|
|
1531
|
-
var CURRENT_PROTOCOL_VERSION =
|
|
1550
|
+
var CURRENT_PROTOCOL_VERSION = 1;
|
|
1532
1551
|
var PROTOCOL_VERSION_HEADER = "x-bobannomi-protocol-version";
|
|
1533
1552
|
function parseServerCapabilities(value) {
|
|
1534
1553
|
if (!isRecord2(value))
|
|
@@ -2910,10 +2929,7 @@ async function create(transport, input, options = {}, prepareModel) {
|
|
|
2910
2929
|
{
|
|
2911
2930
|
method: "POST",
|
|
2912
2931
|
body,
|
|
2913
|
-
headers: {
|
|
2914
|
-
...body.workspaceId === void 0 ? {} : { "x-bobannomi-workspace-id": body.workspaceId },
|
|
2915
|
-
...modelConnection === void 0 ? {} : { "x-bobannomi-model-connection": modelConnection }
|
|
2916
|
-
},
|
|
2932
|
+
...modelConnection === void 0 ? {} : { headers: { "x-bobannomi-model-connection": modelConnection } },
|
|
2917
2933
|
signal: options.signal
|
|
2918
2934
|
}
|
|
2919
2935
|
);
|
|
@@ -3669,10 +3685,9 @@ async function waitForRun(client, options) {
|
|
|
3669
3685
|
const bucket = update.state.buckets[options.sessionId];
|
|
3670
3686
|
const run = bucket?.runs[options.runId];
|
|
3671
3687
|
if (!run || run.status === "pending" || run.status === "running") continue;
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
};
|
|
3688
|
+
const messages = getVisibleSessionMessages(bucket).filter((item) => item.message.runId === options.runId);
|
|
3689
|
+
const text3 = messages.filter(({ message }) => message.role === "assistant").flatMap(({ parts }) => parts.filter((part) => part.type === "text").map((part) => part.text ?? "")).join("");
|
|
3690
|
+
return { run, messages, text: text3 };
|
|
3676
3691
|
}
|
|
3677
3692
|
options.signal?.throwIfAborted();
|
|
3678
3693
|
throw new Error(`Run ${options.runId} observation ended before a terminal state was available`);
|
|
@@ -3933,8 +3948,8 @@ async function interrupt(transport, sessionId, options = {}) {
|
|
|
3933
3948
|
);
|
|
3934
3949
|
}
|
|
3935
3950
|
|
|
3936
|
-
// src/resources/session/session
|
|
3937
|
-
function
|
|
3951
|
+
// src/resources/session/session.ts
|
|
3952
|
+
function bindSession(transport, syncClient, management, sessionId, prepareModel) {
|
|
3938
3953
|
function cancelQueuedPrompt2(inputId, input, options) {
|
|
3939
3954
|
return cancelQueuedPrompt(transport, sessionId, inputId, input, options);
|
|
3940
3955
|
}
|
|
@@ -3983,7 +3998,12 @@ function createSessionHandle(transport, syncClient, management, sessionId, prepa
|
|
|
3983
3998
|
return decodeAgentSessionStateSnapshot(response);
|
|
3984
3999
|
},
|
|
3985
4000
|
/** `POST /sessions/:id/prompts` — 提交用户输入并触发/排队一次 run。 */
|
|
3986
|
-
prompt(input, options
|
|
4001
|
+
async prompt(input, options) {
|
|
4002
|
+
if (input.text !== void 0) {
|
|
4003
|
+
const { text: text3, ...fields3 } = input;
|
|
4004
|
+
if (fields3.items !== void 0) throw new TypeError("Pass either text or items to session.prompt()");
|
|
4005
|
+
return admitPrompt(transport, sessionId, { ...fields3, items: [{ type: "text", text: text3 }] }, options);
|
|
4006
|
+
}
|
|
3987
4007
|
return admitPrompt(transport, sessionId, input, options);
|
|
3988
4008
|
},
|
|
3989
4009
|
/** `POST /sessions/:id/interrupt` — 中断当前/排队中的 run。 */
|
|
@@ -4216,7 +4236,7 @@ var SessionResource = class {
|
|
|
4216
4236
|
/** Bind a session ID locally. Operations use this resource's daemon connection when called. */
|
|
4217
4237
|
byId(sessionId) {
|
|
4218
4238
|
if (typeof sessionId !== "string" || sessionId.length === 0) throw new TypeError("sessionId is required");
|
|
4219
|
-
return
|
|
4239
|
+
return bindSession(this.#transport, { sessions: this, events: this.#events }, this.#management, sessionId, this.prepareModel);
|
|
4220
4240
|
}
|
|
4221
4241
|
/** `GET /sessions/search` - search saved conversation text without opening it. */
|
|
4222
4242
|
async search(options) {
|
|
@@ -4245,9 +4265,10 @@ var SessionResource = class {
|
|
|
4245
4265
|
getDraftComposerOptions(input, options = {}) {
|
|
4246
4266
|
return getDraftComposerOptions(this.#transport, input, options);
|
|
4247
4267
|
}
|
|
4248
|
-
/**
|
|
4249
|
-
create(input, options = {}) {
|
|
4250
|
-
|
|
4268
|
+
/** Create a session and bind its operations to this connection. */
|
|
4269
|
+
async create(input, options = {}) {
|
|
4270
|
+
const record5 = await create(this.#transport, input, options, this.prepareModel);
|
|
4271
|
+
return { ...this.byId(record5.id), record: record5 };
|
|
4251
4272
|
}
|
|
4252
4273
|
getConfigurationOptions(input, options = {}) {
|
|
4253
4274
|
return getConfigurationOptions(this.#transport, input, options);
|
|
@@ -4263,7 +4284,7 @@ var AttachmentResource = class {
|
|
|
4263
4284
|
this.transport = transport;
|
|
4264
4285
|
}
|
|
4265
4286
|
transport;
|
|
4266
|
-
/**
|
|
4287
|
+
/** Inspect and maintain attachment storage for the current daemon. */
|
|
4267
4288
|
storage = {
|
|
4268
4289
|
scan: (options) => this.transport.request("/attachments/storage", options),
|
|
4269
4290
|
repair: (options) => this.transport.request("/attachments/storage/actions", { ...options, method: "POST", body: { action: "repair-safe" } }),
|
|
@@ -4278,19 +4299,24 @@ var AttachmentResource = class {
|
|
|
4278
4299
|
method: "POST",
|
|
4279
4300
|
headers: headers2,
|
|
4280
4301
|
body: input.body,
|
|
4302
|
+
query: { sessionId: input.sessionId },
|
|
4281
4303
|
signal: input.signal
|
|
4282
4304
|
});
|
|
4283
4305
|
return parseAttachmentAssetRecord(await response.json());
|
|
4284
4306
|
}
|
|
4285
4307
|
async getUpload(input) {
|
|
4286
|
-
const response = await this.transport.requestResponse("/attachments/uploads", {
|
|
4308
|
+
const response = await this.transport.requestResponse("/attachments/uploads", {
|
|
4309
|
+
headers: uploadIdentityHeaders(input),
|
|
4310
|
+
query: { sessionId: input.sessionId },
|
|
4311
|
+
signal: input.signal
|
|
4312
|
+
});
|
|
4287
4313
|
const value = await response.json();
|
|
4288
4314
|
return value === null ? null : parseAttachmentAssetRecord(value);
|
|
4289
4315
|
}
|
|
4290
4316
|
async get(id2, options = {}) {
|
|
4291
4317
|
const value = await this.transport.request(
|
|
4292
4318
|
`/attachments/${encodeURIComponent(id2)}`,
|
|
4293
|
-
{ signal: options.signal }
|
|
4319
|
+
{ query: { sessionId: options.sessionId }, signal: options.signal }
|
|
4294
4320
|
);
|
|
4295
4321
|
return parseAttachmentAssetRecord(value);
|
|
4296
4322
|
}
|
|
@@ -4301,13 +4327,13 @@ var AttachmentResource = class {
|
|
|
4301
4327
|
if (range) headers2.range = range;
|
|
4302
4328
|
return await this.transport.requestResponse(
|
|
4303
4329
|
`/attachments/${encodeURIComponent(id2)}/content`,
|
|
4304
|
-
{ method: "GET", headers: headers2, signal: options.signal }
|
|
4330
|
+
{ method: "GET", headers: headers2, query: { sessionId: options.sessionId }, signal: options.signal }
|
|
4305
4331
|
);
|
|
4306
4332
|
}
|
|
4307
|
-
async delete(id2, options
|
|
4333
|
+
async delete(id2, options) {
|
|
4308
4334
|
const value = await this.transport.request(
|
|
4309
4335
|
`/attachments/${encodeURIComponent(id2)}`,
|
|
4310
|
-
{ method: "DELETE", signal: options.signal }
|
|
4336
|
+
{ method: "DELETE", query: { sessionId: options.sessionId, draftId: options.draftId }, signal: options.signal }
|
|
4311
4337
|
);
|
|
4312
4338
|
return parseAttachmentAssetRecord(value);
|
|
4313
4339
|
}
|
|
@@ -4547,6 +4573,7 @@ function matchingOperation(receipt2, operationId) {
|
|
|
4547
4573
|
}
|
|
4548
4574
|
|
|
4549
4575
|
// src/resources/plugins/plugin-resource.ts
|
|
4576
|
+
var archiveUploads = "/plugins/archive/uploads";
|
|
4550
4577
|
var PluginResource = class {
|
|
4551
4578
|
constructor(transport) {
|
|
4552
4579
|
this.transport = transport;
|
|
@@ -4592,6 +4619,37 @@ var PluginResource = class {
|
|
|
4592
4619
|
installArchive(input, options) {
|
|
4593
4620
|
return this.transport.request("/plugins/archive/install", { ...options, method: "POST", body: input });
|
|
4594
4621
|
}
|
|
4622
|
+
/** Preview a client-selected archive by uploading its bytes to the daemon. */
|
|
4623
|
+
async uploadArchive(input, options) {
|
|
4624
|
+
const format = input.fileName.toLowerCase().match(/\.(zip|tar|tar\.gz|tgz)$/)?.[1];
|
|
4625
|
+
if (!format) throw new Error("Plugin archive must be ZIP, TAR, TAR.GZ or TGZ");
|
|
4626
|
+
const response = await this.transport.requestResponse(archiveUploads, {
|
|
4627
|
+
...options,
|
|
4628
|
+
method: "POST",
|
|
4629
|
+
body: input.archive,
|
|
4630
|
+
query: { cwd: input.cwd, format },
|
|
4631
|
+
headers: { "content-type": "application/octet-stream" }
|
|
4632
|
+
});
|
|
4633
|
+
const preview = await response.json();
|
|
4634
|
+
if (!preview?.candidateId || !/^[a-f0-9]{64}$/.test(preview.archiveDigest)) {
|
|
4635
|
+
throw new ProtocolDataError("Plugin archive preview is missing its candidate ID or SHA-256 digest");
|
|
4636
|
+
}
|
|
4637
|
+
return preview;
|
|
4638
|
+
}
|
|
4639
|
+
/** Release an uploaded archive preview. Unclaimed previews also expire. */
|
|
4640
|
+
cancelUploadedArchive(candidateId, options) {
|
|
4641
|
+
return this.transport.request(`${archiveUploads}/${encodeURIComponent(candidateId)}`, { ...options, method: "DELETE" });
|
|
4642
|
+
}
|
|
4643
|
+
/** Save the operation ID before submitting. Recover an uncertain result with getArchiveInstallOperation. */
|
|
4644
|
+
async installUploadedArchive(input, options) {
|
|
4645
|
+
const receipt2 = await this.transport.request(`${archiveUploads}/install`, { ...options, method: "POST", body: input });
|
|
4646
|
+
return matchingArchiveReceipt(receipt2, input.operationId);
|
|
4647
|
+
}
|
|
4648
|
+
/** Read the result of the original upload install without submitting it again. */
|
|
4649
|
+
async getArchiveInstallOperation(operationId, options) {
|
|
4650
|
+
const receipt2 = await this.transport.request(`${archiveUploads}/operations/${encodeURIComponent(operationId)}`, options);
|
|
4651
|
+
return matchingArchiveReceipt(receipt2, operationId);
|
|
4652
|
+
}
|
|
4595
4653
|
/** Read the digest and required permissions for a Git source. */
|
|
4596
4654
|
previewGit(input, options) {
|
|
4597
4655
|
return this.transport.request("/plugins/git/preview", { ...options, method: "POST", body: input });
|
|
@@ -4607,6 +4665,10 @@ var PluginResource = class {
|
|
|
4607
4665
|
return this.transport.request("/plugins/reload", { ...options, method: "POST", body: input });
|
|
4608
4666
|
}
|
|
4609
4667
|
};
|
|
4668
|
+
function matchingArchiveReceipt(receipt2, operationId) {
|
|
4669
|
+
if (receipt2?.operationId !== operationId) throw new ProtocolDataError("Plugin archive receipt does not match original operation", "operationId");
|
|
4670
|
+
return receipt2;
|
|
4671
|
+
}
|
|
4610
4672
|
|
|
4611
4673
|
// src/resources/channels/channel-resource.ts
|
|
4612
4674
|
var ChannelResource = class {
|
|
@@ -4673,6 +4735,14 @@ var ProjectResource = class {
|
|
|
4673
4735
|
this.transport = transport;
|
|
4674
4736
|
}
|
|
4675
4737
|
transport;
|
|
4738
|
+
/** Read the daemon's registered project directories and their current directory identities. */
|
|
4739
|
+
listDirectories(options) {
|
|
4740
|
+
return this.transport.request("/projects/directories", options);
|
|
4741
|
+
}
|
|
4742
|
+
/** Apply the default shell only while the observed project and registered directory still match. */
|
|
4743
|
+
setDirectoryDefaultShell(input, options) {
|
|
4744
|
+
return this.transport.request("/projects/directories/default-shell", { ...options, method: "PATCH", body: input });
|
|
4745
|
+
}
|
|
4676
4746
|
/** `GET /projects` */
|
|
4677
4747
|
async list(options = {}) {
|
|
4678
4748
|
const { signal, ...query } = options;
|
|
@@ -4682,7 +4752,7 @@ var ProjectResource = class {
|
|
|
4682
4752
|
);
|
|
4683
4753
|
return response.projects;
|
|
4684
4754
|
}
|
|
4685
|
-
/** Register or reopen a
|
|
4755
|
+
/** Register or reopen a project on the daemon host, recording the directory identity and last-opened time. */
|
|
4686
4756
|
async register(path2, options) {
|
|
4687
4757
|
return (await this.transport.request("/projects/inspect", {
|
|
4688
4758
|
...options,
|
|
@@ -4715,7 +4785,7 @@ var ProjectResource = class {
|
|
|
4715
4785
|
{ ...options, method: "PATCH", body: { defaultShell } }
|
|
4716
4786
|
)).project;
|
|
4717
4787
|
}
|
|
4718
|
-
/**
|
|
4788
|
+
/** Rebind a project to the current directory at path. Pass the prior project path as expectedPath to reject a stale update. */
|
|
4719
4789
|
async rebind(projectId, path2, options) {
|
|
4720
4790
|
const { expectedPath, signal } = typeof options === "string" ? { expectedPath: options } : options ?? {};
|
|
4721
4791
|
return (await this.transport.request(
|
|
@@ -4764,11 +4834,58 @@ var WorktreeResource = class {
|
|
|
4764
4834
|
};
|
|
4765
4835
|
|
|
4766
4836
|
// src/resources/workspace/git-resource.ts
|
|
4837
|
+
var GitWorkspaceResource = class {
|
|
4838
|
+
constructor(transport, target) {
|
|
4839
|
+
this.transport = transport;
|
|
4840
|
+
this.target = target;
|
|
4841
|
+
}
|
|
4842
|
+
transport;
|
|
4843
|
+
target;
|
|
4844
|
+
status(options) {
|
|
4845
|
+
return this.read("git.status", {}, options);
|
|
4846
|
+
}
|
|
4847
|
+
listBranches(options) {
|
|
4848
|
+
return this.read("git.listBranches", {}, options);
|
|
4849
|
+
}
|
|
4850
|
+
changes(params = {}, options) {
|
|
4851
|
+
return this.read("git.changes", params, options);
|
|
4852
|
+
}
|
|
4853
|
+
diff(params = {}, options) {
|
|
4854
|
+
return this.read("git.diff", params, options);
|
|
4855
|
+
}
|
|
4856
|
+
/** Submit an original branch operation for a registered project. */
|
|
4857
|
+
changeBranch(requestId, original, options) {
|
|
4858
|
+
return this.transport.request("/git/workspace/branch", {
|
|
4859
|
+
...options,
|
|
4860
|
+
method: "POST",
|
|
4861
|
+
body: { target: this.target, requestId, original }
|
|
4862
|
+
});
|
|
4863
|
+
}
|
|
4864
|
+
/** Query the same original body and request ID after an interrupted branch operation. */
|
|
4865
|
+
getBranchOperation(requestId, original, options) {
|
|
4866
|
+
return this.transport.request("/git/workspace/branch-result", {
|
|
4867
|
+
...options,
|
|
4868
|
+
method: "POST",
|
|
4869
|
+
body: { target: this.target, requestId, original }
|
|
4870
|
+
});
|
|
4871
|
+
}
|
|
4872
|
+
read(method, params, options) {
|
|
4873
|
+
return this.transport.request("/git/workspace/read", {
|
|
4874
|
+
...options,
|
|
4875
|
+
method: "POST",
|
|
4876
|
+
body: { target: this.target, method, params }
|
|
4877
|
+
});
|
|
4878
|
+
}
|
|
4879
|
+
};
|
|
4767
4880
|
var GitResource = class {
|
|
4768
4881
|
constructor(transport) {
|
|
4769
4882
|
this.transport = transport;
|
|
4770
4883
|
}
|
|
4771
4884
|
transport;
|
|
4885
|
+
/** Open Git operations for a registered project or an existing session in the current daemon. */
|
|
4886
|
+
workspace(target) {
|
|
4887
|
+
return new GitWorkspaceResource(this.transport, structuredClone(target));
|
|
4888
|
+
}
|
|
4772
4889
|
/** `GET /git/diff?cwd=&full=` */
|
|
4773
4890
|
async getDiff(options) {
|
|
4774
4891
|
const { signal, cwd, full } = options;
|