@blade-hq/agent-client 2612.0.0-beta.90 → 2612.0.0-beta.91
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 +13 -9
- package/dist/blade-client.d.ts +0 -2
- package/dist/{chunk-5ANV3FWX.js → chunk-W5EOEPAG.js} +28 -46
- package/dist/chunk-W5EOEPAG.js.map +1 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -5
- package/dist/internal.js +1 -5
- package/dist/internal.js.map +1 -1
- package/dist/resources/connectors.d.ts +21 -2
- package/dist/resources/feishu-bots.d.ts +16 -3
- package/dist/session/state.d.ts +7 -0
- package/package.json +1 -1
- package/public-api.md +49 -63
- package/dist/chunk-5ANV3FWX.js.map +0 -1
- package/dist/resources/approvals.d.ts +0 -70
package/README.md
CHANGED
|
@@ -670,6 +670,9 @@ chat.on("error", (e) => console.error(e.message, e.code))
|
|
|
670
670
|
|
|
671
671
|
`error` 的 `message` 是可以直接展示的业务文案;`code` 是服务端给的机器可读原因(如 `owner_timeout` / `route_broken` / `owner_busy`),调用方据此决定要不要提示重试,不要解析 `message`。同一组原因也以 `AgentSessionError.code` 的形式抛出(`send()` 这类只回布尔值的入口从 `error` 事件拿),队列 API 则通过 `QueueOperationResult.code` 给出。
|
|
672
672
|
|
|
673
|
+
`SessionState.preparationError` 表示指定 `requestId` / `runId` 的输入尚未开始执行,例如执行环境容量不足。宿主可展示其中的 `message`,告知用户联系管理员并继续等待;不要把它当作消费回执或执行失败,也不要重发新请求。该状态随持久日志实时更新、重连恢复,并在原执行开始或结束时清除;普通执行错误仍由 `errorMessage` 表达。
|
|
674
|
+
|
|
675
|
+
|
|
673
676
|
完整事件表见 `AgentSessionEvents` 类型定义(含 `modeChange` / `workspaceChanged` / `artifact` / `notification` / `backgroundTask` / `taskListUpdated` / `rewind` / `replayMismatch` 等)。`toolResult.source` 区分实时结果、首次连接回放和断线重连回放;`on()` 返回取消函数,handler 抛异常只告警、不影响会话。
|
|
674
677
|
|
|
675
678
|
分页响应是 `SessionTurnsPage`,其中 `nextBefore: string | null` 是唯一的“还有更早历史”真值。历史页面指令通过独立的 `HistoricalCommand` 日志恢复,不混进展示页。
|
|
@@ -834,10 +837,14 @@ chat.renderers = {
|
|
|
834
837
|
|
|
835
838
|
`getMessage`、`getHistory`、`resolveNames`、`getChatInfo`、`listChatMembers`、`listChatBots` 与 `downloadResource` 都要求原始 `FeishuBotReferenceScope`。`getDocument` 用调用方明确提供的 owner 办公连接及其来源,机器人不能借用本人的文档授权。接口保留 SW 的 `FeishuBotOperationResult<T>`,消息查询的 `data` 是 `FeishuBotPlatformResult<FeishuBotMessagePage>`,其中包含原生 `FeishuBotRawMessage`;名字查询是 `FeishuBotNames`,群成员是 `FeishuBotMember`。请求类型分别为 `FeishuBotScopedRequest`、`FeishuBotMessageRequest`、`FeishuBotHistoryRequest`、`FeishuBotResourceRequest`,不提供任意 URL 或 operation 调用。
|
|
836
839
|
|
|
840
|
+
`FeishuMarkdownOptions` 定义可选 `question: FeishuMessageQuestion`(持久问题 id 和选项 id/label)及 `card_callback_enabled`;回调默认关闭,只在核实当前应用回调配置后开启。`text` 直接传 Markdown,由 SW 共用转换。
|
|
841
|
+
|
|
837
842
|
`sendMessage(id, FeishuBotSendRequest)` 和 `replyMessage(id, FeishuBotReplyRequest)` 要求固定 `idempotency_key`(最多 50 字节)。保存 `FeishuBotReceipt.operation_id`;`unknown` 表示结果未知,应使用 `getReceipt(id, {operation_id, reference_scope})` 查询,不能改编号再发送。文件发送先用 `uploadArtifact(id, blob, filename, requestId)` 暂存,再用 `uploadFile(id, FeishuBotUploadFileRequest)` 或 `uploadImage` 上传平台,最后 `createMessage(id, FeishuBotCreateMessageRequest)`。上传和创建均保留各自原 `request_id`,平台文件标识在回执的 `result.data` 中。
|
|
838
843
|
|
|
839
844
|
`FeishuBotArtifact` 含临时产物的大小、摘要、来源与下载路径。`downloadArtifact(id, artifactId)` 返回鉴权后的 `Response`,BA 在返回字节前验证大小和 SHA256。路径只用于 BA 同源下载,不是可分享 URL,也不是沙盒内路径;宿主须将字节登记到自己的持久附件链路后供沙盒使用。
|
|
840
845
|
|
|
846
|
+
`getMessage`、`getHistory` 和 `getForwardedMessages` 默认以机器人身份读取;明确指定办公连接及原 scope 时可传 `identity:"user"` 读取个人消息。`sendMessage` 支持 `user_id` 私聊指定的同应用 open_id。
|
|
847
|
+
|
|
841
848
|
`getUserInfo` 返回当前机器人可见的 `FeishuBotUser`。`getForwardedMessages` 保留平台消息列表和 `upper_message_id`,由宿主转换库处理合并转发。`getDocumentMetadata` 使用明确指定的办公连接,按 `FeishuDocumentType` 查询 `FeishuDocumentMetadata`;机器人名称直接用连接的 `label`。`getReceipt` 的 `FeishuBotReceiptQuery` 允许三种原身份之一:`operation_id`、文本发送的 `idempotency_key`、文件上传/创建的 `request_id`。HTTP 断连后可用原 key 查回执,无需先取得 operation_id;查询不自动重发。
|
|
842
849
|
|
|
843
850
|
`replyTypedMessage(id, FeishuBotReplyTypedMessageRequest)` 用固定 `request_id` 回复原消息,参数为 `{params:{message_id},data:{msg_type,content},reference_scope,request_id}`,支持图片、文件等与 `createMessage` 相同的消息类型。文件 key 放在 JSON 编码的 `content` 中;响应丢失后仍通过原 `request_id` 查询回执。
|
|
@@ -1102,11 +1109,11 @@ BA 默认提供内置定时任务。应用自行管理定时安排时,可在
|
|
|
1102
1109
|
|
|
1103
1110
|
### 连接器说明书与使用规则
|
|
1104
1111
|
|
|
1105
|
-
`client.connectors.guide(name)`
|
|
1112
|
+
`client.connectors.guide(name)` 读取当前可用连接器的说明书;飞书包内的结构化设置定义为 `ConnectorQuestionnaire`,位于响应的 `questionnaire` 中;可传第二参数 `{signal}` 取消读取。断开后不可读。
|
|
1106
1113
|
|
|
1107
|
-
`client.connectors.rules(name)` 返回 `ConnectorRules`,其中 `groups` 为 `ConnectorRuleGroup[]`;`ConnectorRuleValue` 为 `"allow" | "
|
|
1114
|
+
`client.connectors.rules(name)` 返回 `ConnectorRules`,其中 `groups` 为 `ConnectorRuleGroup[]`;`ConnectorRuleValue` 为 `"allow" | "off"`。使用 `client.connectors.updateRules(name, {send: "off"})` 按组部分更新,返回最新完整视图;恢复默认时提交该组的 `default`。设置按当前用户跨会话保存,不改变服务授权。
|
|
1108
1115
|
|
|
1109
|
-
|
|
1116
|
+
关闭后调用立即被拒绝,本轮搜索缓存允许保留,下一轮执行反映新设置。存量 `ask` 读取为启用,不回写;未保存的删除组默认关闭,其余组默认启用。未知组或无效值会拒绝整个更新。
|
|
1110
1117
|
|
|
1111
1118
|
### 连接器推送设置
|
|
1112
1119
|
|
|
@@ -1115,14 +1122,11 @@ BA 默认提供内置定时任务。应用自行管理定时安排时,可在
|
|
|
1115
1122
|
`client.connectors.setPushSettings(name, {group_digest: "1h"}, {expectedConnectionId})` 部分更新频率;飞书也可独立提交 `{ack_reaction:true}`,省略字段保持原值。`ack_reaction_available` 只读,表示机器人回应表情的能力,false仍可保存偏好。开关只适用于私聊机器人/群@机器人,由网关以机器人身份先回表情,不改用户授权或工具规则。凭据由BA保存,宿主通过BladeClient调用。
|
|
1116
1123
|
|
|
1117
1124
|
|
|
1118
|
-
###
|
|
1119
|
-
|
|
1120
|
-
`client.approvals` 查询持久确认记录,并以卡片的 revision/digest 提交所有者决定。沙盒运行凭证不能批准或登记本人来源。`client.actionOrigins.bind` 是可信应用后端的一次性根快照登记与输入绑定接口:输入携带不可变 trigger ID 的扁平列表,可同时提供 `ActionOrigin` 快照,不含父链或历史。委派、回执和回答复用根 ID,私人读取影响记在根上,material 仅为触发消息的短摘录。`ActionPlace` 的名称仅供展示,匹配与执行始终使用连接、应用和原始 ID。
|
|
1125
|
+
### 输入来源
|
|
1121
1126
|
|
|
1122
|
-
|
|
1127
|
+
沙盒运行凭证不能写入连接器能力开关和推送设置;可信应用后端应先核验本次持久输入确实来自所有者本人。飞书私聊本人身份以当前办公连接提供的 `owner_open_id` 与平台发送人相等为准,字段缺失时按外部输入处理。
|
|
1123
1128
|
|
|
1124
|
-
|
|
1125
|
-
`client.approvals.list(sessionId)` 独立返回全部活跃确认记录和有限近期历史。持续跟踪卡片时,使用 `reconcileApprovals(client.approvals, watched, sessionId)` 补查历史窗口之外的原 ID:`watched` 只传仍需跟踪的记录,例如等待决定或执行的卡片、尚未发布结果回执的动作;结果持久保存后停止跟踪。该函数通过已有的精确查询读取最新 revision,保持当前会话范围,不保存跨账号的全局缓存。共享 `ActionApprovals` 已使用它,宿主无需另写补查循环。
|
|
1129
|
+
`client.actionOrigins.bind` 是可信应用后端的一次性根快照登记与输入绑定接口:输入携带不可变 trigger ID 的扁平列表,可同时提供 `ActionOrigin` 快照,不含父链或历史。委派、回执和回答保留来源,material 仅为触发消息的短摘录。`ActionPlace` 的名称仅供展示。沙盒运行凭证不能登记本人来源。
|
|
1126
1130
|
|
|
1127
1131
|
### 百变包与界面清单
|
|
1128
1132
|
|
package/dist/blade-client.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ApprovalsResource } from "./resources/approvals";
|
|
2
1
|
import { ActionOriginsResource } from "./resources/action-origins";
|
|
3
2
|
import type { ApplicationUserTransport } from "./application-client";
|
|
4
3
|
import { SandboxResource } from "./resources/sandbox";
|
|
@@ -70,7 +69,6 @@ export declare class BladeClient {
|
|
|
70
69
|
readonly sessions: SessionsResource;
|
|
71
70
|
/** 按用户读取的插件目录与图标;没有会话时也能用。 */
|
|
72
71
|
readonly plugins: PluginsResource;
|
|
73
|
-
readonly approvals: ApprovalsResource;
|
|
74
72
|
readonly actionOrigins: ActionOriginsResource;
|
|
75
73
|
readonly connectors: ConnectorsResource;
|
|
76
74
|
readonly feishuBots: FeishuBotsResource;
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
// src/resources/approvals.ts
|
|
2
|
-
var ApprovalsResource = class {
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
client;
|
|
7
|
-
cancelExecution(session, execution) {
|
|
8
|
-
return this.client.json("POST", "/api/action-approvals/cancel-execution", { session, execution });
|
|
9
|
-
}
|
|
10
|
-
list(sessionId) {
|
|
11
|
-
return this.client.json("GET", `/api/action-approvals${sessionId ? `?session_id=${encodeURIComponent(sessionId)}` : ""}`);
|
|
12
|
-
}
|
|
13
|
-
get(id) {
|
|
14
|
-
return this.client.json("GET", `/api/action-approvals/${encodeURIComponent(id)}`);
|
|
15
|
-
}
|
|
16
|
-
decide(id, decision) {
|
|
17
|
-
return this.client.json("POST", `/api/action-approvals/${encodeURIComponent(id)}/decision`, decision);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
async function reconcileApprovals(api, watched, sessionId) {
|
|
21
|
-
const rows = [...await api.list(sessionId)];
|
|
22
|
-
const present = new Set(rows.map((row) => row.id));
|
|
23
|
-
for (const previous of watched) {
|
|
24
|
-
if (present.has(previous.id) || sessionId && previous.call.session !== sessionId) continue;
|
|
25
|
-
const latest = await api.get(previous.id);
|
|
26
|
-
if (sessionId && latest.call.session !== sessionId) continue;
|
|
27
|
-
rows.push(latest.revision >= previous.revision ? latest : previous);
|
|
28
|
-
present.add(previous.id);
|
|
29
|
-
}
|
|
30
|
-
return rows;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
1
|
// src/resources/action-origins.ts
|
|
34
2
|
var ActionOriginsResource = class {
|
|
35
3
|
constructor(client) {
|
|
@@ -300,7 +268,7 @@ var ToolProvider = class {
|
|
|
300
268
|
|
|
301
269
|
// src/version.ts
|
|
302
270
|
var SDK_NAME = "agent-client";
|
|
303
|
-
var SDK_VERSION = true ? "2612.0.0-beta.
|
|
271
|
+
var SDK_VERSION = true ? "2612.0.0-beta.91" : "1.1.1";
|
|
304
272
|
|
|
305
273
|
// src/auth-login.ts
|
|
306
274
|
function isAuthCallbackMessage(value) {
|
|
@@ -1484,7 +1452,7 @@ function acknowledgeTurnEvents(acknowledge) {
|
|
|
1484
1452
|
}
|
|
1485
1453
|
function hasChatRunEvent(events) {
|
|
1486
1454
|
return events.some(
|
|
1487
|
-
(event) => event.type !== "llm:first_token:delivered" && event.type !== "session:post_chat_followup" && event.type !== "loop:tool_bridge" && !event.type.startsWith("compaction:")
|
|
1455
|
+
(event) => event.type !== "llm:first_token:delivered" && event.type !== "chat:preparation" && event.type !== "session:post_chat_followup" && event.type !== "loop:tool_bridge" && !event.type.startsWith("compaction:")
|
|
1488
1456
|
);
|
|
1489
1457
|
}
|
|
1490
1458
|
function acceptedPostChatFollowupCompletesLatestRun(events, updates) {
|
|
@@ -3385,8 +3353,8 @@ var ConnectorsResource = class {
|
|
|
3385
3353
|
updateRules(name, set) {
|
|
3386
3354
|
return this.client.json("PUT", `/api/connectors/${encodeURIComponent(name)}/rules`, { set });
|
|
3387
3355
|
}
|
|
3388
|
-
guide(name,
|
|
3389
|
-
return this.client.jsonFromInit(`/api/connectors/${encodeURIComponent(name)}/guide
|
|
3356
|
+
guide(name, init) {
|
|
3357
|
+
return this.client.jsonFromInit(`/api/connectors/${encodeURIComponent(name)}/guide`, init);
|
|
3390
3358
|
}
|
|
3391
3359
|
/** Stage an explicit attachment in the current user's SW connection. Reuse requestId on retry. */
|
|
3392
3360
|
async uploadFile(name, file, fileName, requestId) {
|
|
@@ -4650,6 +4618,7 @@ function createInitialSessionState(sessionId) {
|
|
|
4650
4618
|
mode: null,
|
|
4651
4619
|
connection: "disconnected",
|
|
4652
4620
|
errorMessage: null,
|
|
4621
|
+
preparationError: null,
|
|
4653
4622
|
lastRun: null,
|
|
4654
4623
|
askAnswers: {},
|
|
4655
4624
|
agentLoops: {},
|
|
@@ -5752,7 +5721,11 @@ var AgentSession = class _AgentSession {
|
|
|
5752
5721
|
if (controller.signal.aborted) throw controller.signal.reason;
|
|
5753
5722
|
if (error instanceof AgentSessionError && (error.code === "access_denied" || error.code === "license_denied")) throw error;
|
|
5754
5723
|
}
|
|
5755
|
-
if (response?.code === "access_denied" || response?.code === "license_denied") {
|
|
5724
|
+
if (response?.code === "access_denied" || response?.code === "license_denied" || response?.code === "model_catalog_unavailable") {
|
|
5725
|
+
if (response.code === "model_catalog_unavailable" && typeof response.message === "string") {
|
|
5726
|
+
const message = response.message;
|
|
5727
|
+
this.update((state) => ({ ...state, errorMessage: message }));
|
|
5728
|
+
}
|
|
5756
5729
|
throw new AgentSessionError(typeof response.message === "string" ? response.message : "\u63D0\u4EA4\u6682\u65F6\u65E0\u6CD5\u7EE7\u7EED\uFF0C\u8BF7\u4FDD\u7559\u539F\u8BF7\u6C42\u3002", response.code);
|
|
5757
5730
|
}
|
|
5758
5731
|
if (response?.status === "decision_required" && isRecord(response.replay_mismatch)) {
|
|
@@ -5769,7 +5742,11 @@ var AgentSession = class _AgentSession {
|
|
|
5769
5742
|
}
|
|
5770
5743
|
const result = parseQueueAck(response, this.sessionId);
|
|
5771
5744
|
if (result.snapshot && !this.disposed) this.update((state) => withQueue(state, result.snapshot));
|
|
5772
|
-
if (response?.status === "conflict" || response?.status === "rejected")
|
|
5745
|
+
if (response?.status === "conflict" || response?.status === "rejected") {
|
|
5746
|
+
const message = result.message ?? "\u8F93\u5165\u672A\u88AB\u63A5\u6536";
|
|
5747
|
+
this.update((state) => ({ ...state, errorMessage: message }));
|
|
5748
|
+
return { requestId, status: "rejected", message, ...result.code ? { code: result.code } : {} };
|
|
5749
|
+
}
|
|
5773
5750
|
const delivery = response?.delivery;
|
|
5774
5751
|
if (isRecord(delivery) && delivery.status === "accepted") return {
|
|
5775
5752
|
requestId,
|
|
@@ -6179,12 +6156,21 @@ var AgentSession = class _AgentSession {
|
|
|
6179
6156
|
if (delivery.reload) {
|
|
6180
6157
|
this.activeReplayPlaybackId = null;
|
|
6181
6158
|
this.projectionBuilder.reset();
|
|
6182
|
-
this.update((state) => ({ ...state, lastRun: null }));
|
|
6159
|
+
this.update((state) => ({ ...state, lastRun: null, preparationError: null }));
|
|
6183
6160
|
this.pendingTurnPatches.clear();
|
|
6184
6161
|
this.epochReloadRequested += 1;
|
|
6185
6162
|
}
|
|
6186
6163
|
const activeCompactionIds = new Set(this.state.turns.filter((turn) => turn.kind === "compaction" && turn.status === "streaming").map((turn) => turn.compaction_id));
|
|
6187
6164
|
for (const event of events) {
|
|
6165
|
+
if (event.type === "chat:preparation") {
|
|
6166
|
+
const issue = event.payload.preparation_error;
|
|
6167
|
+
if (isRecord(issue) && typeof issue.requestId === "string" && typeof issue.runId === "string" && typeof issue.code === "string" && typeof issue.message === "string") {
|
|
6168
|
+
const preparationError = { requestId: issue.requestId, runId: issue.runId, code: issue.code, message: issue.message };
|
|
6169
|
+
this.update((state) => ({ ...state, preparationError }));
|
|
6170
|
+
} else if (this.state.preparationError?.runId === event.payload.run_id) {
|
|
6171
|
+
this.update((state) => ({ ...state, preparationError: null }));
|
|
6172
|
+
}
|
|
6173
|
+
}
|
|
6188
6174
|
if (event.type === "chat:end") this.recordRunResult(event.payload);
|
|
6189
6175
|
const playbackId = typeof event.payload.playback_id === "string" ? event.payload.playback_id : null;
|
|
6190
6176
|
if (event.type === "chat:start") this.activeReplayPlaybackId = null;
|
|
@@ -7440,10 +7426,10 @@ var FeishuBotsResource = class {
|
|
|
7440
7426
|
return this.client.jsonFromInit(`${this.path(id)}/disconnect`, { ...init, method: "POST", body: "{}" });
|
|
7441
7427
|
}
|
|
7442
7428
|
getMessage(id, request, init) {
|
|
7443
|
-
return this.operation(id, "messages_get", { ...request, identity: "bot" }, init);
|
|
7429
|
+
return this.operation(id, "messages_get", { ...request, identity: request.identity ?? "bot" }, init);
|
|
7444
7430
|
}
|
|
7445
7431
|
getHistory(id, request, init) {
|
|
7446
|
-
return this.operation(id, "messages_list", { ...request, identity: "bot" }, init);
|
|
7432
|
+
return this.operation(id, "messages_list", { ...request, identity: request.identity ?? "bot" }, init);
|
|
7447
7433
|
}
|
|
7448
7434
|
getForwardedMessages(id, request, init) {
|
|
7449
7435
|
return this.getMessage(id, request, init);
|
|
@@ -8311,7 +8297,6 @@ var BladeClient = class _BladeClient {
|
|
|
8311
8297
|
sessions;
|
|
8312
8298
|
/** 按用户读取的插件目录与图标;没有会话时也能用。 */
|
|
8313
8299
|
plugins;
|
|
8314
|
-
approvals;
|
|
8315
8300
|
actionOrigins;
|
|
8316
8301
|
connectors;
|
|
8317
8302
|
feishuBots;
|
|
@@ -8343,7 +8328,6 @@ var BladeClient = class _BladeClient {
|
|
|
8343
8328
|
this.capabilities = new CapabilitiesResource(this);
|
|
8344
8329
|
this.sessions = new SessionsResource(this);
|
|
8345
8330
|
this.plugins = new PluginsResource(this);
|
|
8346
|
-
this.approvals = new ApprovalsResource(this);
|
|
8347
8331
|
this.actionOrigins = new ActionOriginsResource(this);
|
|
8348
8332
|
this.connectors = new ConnectorsResource(this);
|
|
8349
8333
|
this.feishuBots = new FeishuBotsResource(this);
|
|
@@ -9484,8 +9468,6 @@ function attachPackPageBridge(options) {
|
|
|
9484
9468
|
}
|
|
9485
9469
|
|
|
9486
9470
|
export {
|
|
9487
|
-
ApprovalsResource,
|
|
9488
|
-
reconcileApprovals,
|
|
9489
9471
|
SandboxResource,
|
|
9490
9472
|
BROWSER_DISABLED_CODE,
|
|
9491
9473
|
BrowserDisabledError,
|
|
@@ -9595,4 +9577,4 @@ export {
|
|
|
9595
9577
|
formatAskUserAnswer,
|
|
9596
9578
|
attachPackPageBridge
|
|
9597
9579
|
};
|
|
9598
|
-
//# sourceMappingURL=chunk-
|
|
9580
|
+
//# sourceMappingURL=chunk-W5EOEPAG.js.map
|