@blade-hq/agent-client 2610.0.0-beta.28 → 2610.0.0-beta.29
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 +34 -0
- package/dist/blade-client.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +51 -1
- package/dist/index.js.map +1 -1
- package/dist/resources/computers.d.ts +63 -0
- package/package.json +1 -1
- package/public-api.md +60 -1
package/README.md
CHANGED
|
@@ -289,6 +289,40 @@ const body = { model: defaultServiceModel, messages, stream: true }
|
|
|
289
289
|
没问题,直接交给浏览器就指向用户自己的机器了。默认形态是后端透传(密钥本来也不该进浏览器),
|
|
290
290
|
浏览器直连只适合这个地址对浏览器同样可达的场景。
|
|
291
291
|
|
|
292
|
+
### 远程电脑:client.computers
|
|
293
|
+
|
|
294
|
+
一个会话除了自己的运行时,还可以操作用户接入的其他电脑(`blade daemon connect` 接进来的机器)。
|
|
295
|
+
**默认一台都不能用**,要先为这次会话启动它。
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
const { computers } = await client.computers.list(sessionId)
|
|
299
|
+
// SessionComputerList → { computers: SessionComputer[] }
|
|
300
|
+
// SessionComputer: { id, label, os, arch, home, workspace, allowed_paths,
|
|
301
|
+
// online, enabled, is_primary, last_seen_at, ... }
|
|
302
|
+
|
|
303
|
+
await client.computers.setEnabled(sessionId, computer.id, true) // 启动
|
|
304
|
+
await client.computers.setEnabled(sessionId, computer.id, false) // 停用
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
`online` 和 `enabled` 是**两件独立的事**:前者指那台电脑此刻连着后端,后者指这次会话已经启动了它。
|
|
308
|
+
离线的电脑也能先启动,等它连上就直接可用。`online` 由服务端读心跳时间判定,不做实时探测,
|
|
309
|
+
所以电脑离线时列表照样返回它——你拿得到「它离线了」这个结论。
|
|
310
|
+
|
|
311
|
+
`is_primary` 表示这次会话本身就跑在这台电脑上。这种电脑恒为可用,也不能停用——
|
|
312
|
+
那是会话自己的工作目录所在。
|
|
313
|
+
|
|
314
|
+
做电脑选择器时用这几个纯函数,别自己重算状态:
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
import { canToggleComputer, computerState, sortComputers } from "@blade-hq/agent-client"
|
|
318
|
+
|
|
319
|
+
sortComputers(computers) // 可用的在前,其次在线的,最后按名字
|
|
320
|
+
computerState(computer) // ComputerState: "primary" | "enabled" | "offline" | "idle"
|
|
321
|
+
canToggleComputer(computer) // 主运行时返回 false
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
`ComputersResource` 是 `client.computers` 的类型。
|
|
325
|
+
|
|
292
326
|
## AgentSession
|
|
293
327
|
|
|
294
328
|
一个会话的实时状态机。**状态归属实例**:同一页面建多个会话互不干扰。
|
package/dist/blade-client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type LoginOptions, type LoginResult, type TokenStorageMode } from "./au
|
|
|
2
2
|
import { type BladeFetchInit, type HttpMethod } from "./rest";
|
|
3
3
|
import { AuthResource } from "./resources/auth";
|
|
4
4
|
import { HeadlessResource } from "./resources/headless";
|
|
5
|
+
import { ComputersResource } from "./resources/computers";
|
|
5
6
|
import { ModelsResource } from "./resources/models";
|
|
6
7
|
import { SessionsResource } from "./resources/sessions";
|
|
7
8
|
import { SessionHub } from "./session/hub";
|
|
@@ -33,6 +34,7 @@ export declare class BladeClient {
|
|
|
33
34
|
readonly options: BladeClientOptions;
|
|
34
35
|
readonly auth: AuthResource;
|
|
35
36
|
readonly headless: HeadlessResource;
|
|
37
|
+
readonly computers: ComputersResource;
|
|
36
38
|
readonly models: ModelsResource;
|
|
37
39
|
readonly sessions: SessionsResource;
|
|
38
40
|
/** 实时会话中枢:client.sessions.connect() 内部使用,一般不直接访问。 */
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ export type { CommandEnvelope, InboundAction, InboundEnvelope } from "./commands
|
|
|
20
20
|
export { isCommandEnvelope, isInboundEnvelope } from "./commands/protocol";
|
|
21
21
|
export type { AuthResource, ExchangeCodeParams, ExchangeCodeResult, ProvidersResponse, UserInfo, } from "./resources/auth";
|
|
22
22
|
export type { HeadlessResource } from "./resources/headless";
|
|
23
|
+
export { ComputersResource } from "./resources/computers";
|
|
24
|
+
export { canToggleComputer, computerState, sortComputers, } from "./resources/computers";
|
|
25
|
+
export type { ComputerState, SessionComputer, SessionComputerList, } from "./resources/computers";
|
|
23
26
|
export { ModelsResource } from "./resources/models";
|
|
24
27
|
export type { ModelCatalog, ModelOption } from "./resources/models";
|
|
25
28
|
export type { SessionsResource } from "./resources/sessions";
|
package/dist/index.js
CHANGED
|
@@ -424,6 +424,50 @@ function ensureSocketConnected(socket, timeoutMs, detail) {
|
|
|
424
424
|
});
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
+
// src/resources/computers.ts
|
|
428
|
+
function computerState(computer) {
|
|
429
|
+
if (computer.is_primary) return "primary";
|
|
430
|
+
if (computer.enabled) return "enabled";
|
|
431
|
+
return computer.online ? "idle" : "offline";
|
|
432
|
+
}
|
|
433
|
+
function canToggleComputer(computer) {
|
|
434
|
+
return !computer.is_primary;
|
|
435
|
+
}
|
|
436
|
+
function sortComputers(computers) {
|
|
437
|
+
return [...computers].sort((a, b) => {
|
|
438
|
+
if (a.enabled !== b.enabled) return a.enabled ? -1 : 1;
|
|
439
|
+
if (a.online !== b.online) return a.online ? -1 : 1;
|
|
440
|
+
return a.label.localeCompare(b.label);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
var ComputersResource = class {
|
|
444
|
+
constructor(client) {
|
|
445
|
+
this.client = client;
|
|
446
|
+
}
|
|
447
|
+
client;
|
|
448
|
+
/**
|
|
449
|
+
* 列出当前用户的全部电脑,带上"在不在线"和"这次会话能不能用"。
|
|
450
|
+
* 服务端只查库,电脑离线时同样返回,所以拿得到"它离线了"这个结论。
|
|
451
|
+
*/
|
|
452
|
+
list(sessionId) {
|
|
453
|
+
return this.client.json(
|
|
454
|
+
"GET",
|
|
455
|
+
`/api/sessions/${encodeURIComponent(sessionId)}/computers`
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* 启动或停止一台电脑。只改这次会话的可用范围,不会碰远程机器,
|
|
460
|
+
* 电脑离线时同样能登记,等它上线就直接可用。
|
|
461
|
+
*/
|
|
462
|
+
setEnabled(sessionId, computer, enabled) {
|
|
463
|
+
return this.client.json(
|
|
464
|
+
"PUT",
|
|
465
|
+
`/api/sessions/${encodeURIComponent(sessionId)}/computers/${encodeURIComponent(computer)}/enabled`,
|
|
466
|
+
{ enabled }
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
427
471
|
// src/resources/models.ts
|
|
428
472
|
var ModelsResource = class {
|
|
429
473
|
constructor(client) {
|
|
@@ -4701,7 +4745,7 @@ function resolveAuthToken(options) {
|
|
|
4701
4745
|
|
|
4702
4746
|
// src/version.ts
|
|
4703
4747
|
var SDK_NAME = "agent-client";
|
|
4704
|
-
var SDK_VERSION = true ? "2610.0.0-beta.
|
|
4748
|
+
var SDK_VERSION = true ? "2610.0.0-beta.29" : "1.1.1";
|
|
4705
4749
|
|
|
4706
4750
|
// src/socket.ts
|
|
4707
4751
|
function withSdkIdentity(auth) {
|
|
@@ -4729,6 +4773,7 @@ var BladeClient = class {
|
|
|
4729
4773
|
options;
|
|
4730
4774
|
auth;
|
|
4731
4775
|
headless;
|
|
4776
|
+
computers;
|
|
4732
4777
|
models;
|
|
4733
4778
|
sessions;
|
|
4734
4779
|
/** 实时会话中枢:client.sessions.connect() 内部使用,一般不直接访问。 */
|
|
@@ -4740,6 +4785,7 @@ var BladeClient = class {
|
|
|
4740
4785
|
};
|
|
4741
4786
|
this.auth = new AuthResource(this);
|
|
4742
4787
|
this.headless = new HeadlessResource(this);
|
|
4788
|
+
this.computers = new ComputersResource(this);
|
|
4743
4789
|
this.models = new ModelsResource(this);
|
|
4744
4790
|
this.sessions = new SessionsResource(this);
|
|
4745
4791
|
this.hub = new SessionHub(this);
|
|
@@ -5280,6 +5326,7 @@ export {
|
|
|
5280
5326
|
BladeApiError,
|
|
5281
5327
|
BladeClient,
|
|
5282
5328
|
ClientProjectionBuilder,
|
|
5329
|
+
ComputersResource,
|
|
5283
5330
|
DEFAULT_REPLAY_SPEED,
|
|
5284
5331
|
EMPTY_PLATFORM_ENDPOINTS,
|
|
5285
5332
|
LayoutType,
|
|
@@ -5294,6 +5341,8 @@ export {
|
|
|
5294
5341
|
TaskStatus,
|
|
5295
5342
|
acceptedPostChatFollowupCompletesLatestRun,
|
|
5296
5343
|
buildMessageContent,
|
|
5344
|
+
canToggleComputer,
|
|
5345
|
+
computerState,
|
|
5297
5346
|
connectEmbedded,
|
|
5298
5347
|
contentPreview,
|
|
5299
5348
|
contextProjectionData,
|
|
@@ -5313,6 +5362,7 @@ export {
|
|
|
5313
5362
|
normalizeMessageContent,
|
|
5314
5363
|
reconcileOptimisticUserTurns,
|
|
5315
5364
|
resolveServiceUrl,
|
|
5365
|
+
sortComputers,
|
|
5316
5366
|
toReplaySnapshot,
|
|
5317
5367
|
transformSlashCommand
|
|
5318
5368
|
};
|