@hcmai/sdk 0.15.8 → 0.15.10
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/dist/index.d.ts +235 -4
- package/dist/index.js +250 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ function attachRetry(client, onRefresh) {
|
|
|
32
32
|
const status = error.response?.status;
|
|
33
33
|
const cfg = error.config;
|
|
34
34
|
if (!cfg) throw error;
|
|
35
|
+
if (cfg.__skipRetry) throw error;
|
|
35
36
|
if (status === 401 && !cfg.__retried && !cfg.__skipAuthRetry) {
|
|
36
37
|
cfg.__retried = true;
|
|
37
38
|
try {
|
|
@@ -79,6 +80,7 @@ var CliErrorCode = /* @__PURE__ */ ((CliErrorCode2) => {
|
|
|
79
80
|
CliErrorCode2["WS_HANDSHAKE_REJECTED"] = "WS_HANDSHAKE_REJECTED";
|
|
80
81
|
CliErrorCode2["SCOPE_FORBIDDEN"] = "SCOPE_FORBIDDEN";
|
|
81
82
|
CliErrorCode2["BUSINESS_RULE_VIOLATION"] = "BUSINESS_RULE_VIOLATION";
|
|
83
|
+
CliErrorCode2["STREAM_FAILED_NO_SERVER_CODE"] = "STREAM_FAILED_NO_SERVER_CODE";
|
|
82
84
|
CliErrorCode2["MODEL_NOT_FOUND"] = "MODEL_NOT_FOUND";
|
|
83
85
|
CliErrorCode2["ACTION_NOT_FOUND"] = "ACTION_NOT_FOUND";
|
|
84
86
|
CliErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
|
|
@@ -114,6 +116,9 @@ var CODE_TO_EXIT = {
|
|
|
114
116
|
["WS_HANDSHAKE_REJECTED" /* WS_HANDSHAKE_REJECTED */]: 2 /* AUTH_ERROR */,
|
|
115
117
|
["SCOPE_FORBIDDEN" /* SCOPE_FORBIDDEN */]: 2 /* AUTH_ERROR */,
|
|
116
118
|
["BUSINESS_RULE_VIOLATION" /* BUSINESS_RULE_VIOLATION */]: 3 /* BUSINESS_ERROR */,
|
|
119
|
+
// 退出码仍是 3:脚本与 P0 runner 按 3 判「这一轮没跑成」,这一刀只换**码**不换档位。
|
|
120
|
+
// 换的是码承载的信息——从「后端说了业务规则不通过」变成「后端什么都没说到我这儿」。
|
|
121
|
+
["STREAM_FAILED_NO_SERVER_CODE" /* STREAM_FAILED_NO_SERVER_CODE */]: 3 /* BUSINESS_ERROR */,
|
|
117
122
|
["MODEL_NOT_FOUND" /* MODEL_NOT_FOUND */]: 3 /* BUSINESS_ERROR */,
|
|
118
123
|
["ACTION_NOT_FOUND" /* ACTION_NOT_FOUND */]: 3 /* BUSINESS_ERROR */,
|
|
119
124
|
["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: 3 /* BUSINESS_ERROR */,
|
|
@@ -258,6 +263,17 @@ function formatCause(cause) {
|
|
|
258
263
|
}
|
|
259
264
|
|
|
260
265
|
// src/meta/describe.ts
|
|
266
|
+
var HCM_FIELD_RAW_KEYS = [
|
|
267
|
+
"key",
|
|
268
|
+
"name",
|
|
269
|
+
"type",
|
|
270
|
+
"isRequired",
|
|
271
|
+
"description",
|
|
272
|
+
"enums",
|
|
273
|
+
"object",
|
|
274
|
+
"objectLabel",
|
|
275
|
+
"isI18n"
|
|
276
|
+
];
|
|
261
277
|
function normalizeActionParams(action3) {
|
|
262
278
|
if (action3.parameters) return action3.parameters;
|
|
263
279
|
if (action3.params) return action3.params;
|
|
@@ -280,7 +296,9 @@ async function describe(http, model, _opts = {}) {
|
|
|
280
296
|
type: f.type ?? "unknown",
|
|
281
297
|
required: f.isRequired,
|
|
282
298
|
description: f.description,
|
|
283
|
-
|
|
299
|
+
// 只在真有值时出这一位,口径同下面的 object / i18n:绝大多数字段没有值域,
|
|
300
|
+
// 无条件出一个 `enums: undefined` 会让 --output json 每个字段都多一行噪声。
|
|
301
|
+
...f.enums?.length ? { enums: f.enums } : {},
|
|
284
302
|
// 只在有值时出这两位:没有关联目标的普通字段不该多两行 `object: undefined` 噪声
|
|
285
303
|
...f.object ? { object: f.object } : {},
|
|
286
304
|
...f.objectLabel ? { objectLabel: f.objectLabel } : {},
|
|
@@ -1403,7 +1421,8 @@ async function query(http, model, dsl) {
|
|
|
1403
1421
|
const page = dsl.offset ? Math.floor(dsl.offset / size) : 0;
|
|
1404
1422
|
body.page = page;
|
|
1405
1423
|
body.size = size;
|
|
1406
|
-
const
|
|
1424
|
+
const url = `/api/models/${model}/list/dsl`;
|
|
1425
|
+
const resp = dsl.plugin ? await http.post(url, body, { params: { plugin: dsl.plugin } }) : await http.post(url, body);
|
|
1407
1426
|
return {
|
|
1408
1427
|
rows: resp.data.content ?? [],
|
|
1409
1428
|
total: resp.data.totalElements
|
|
@@ -2877,12 +2896,17 @@ function classifyMessage(parsed) {
|
|
|
2877
2896
|
return "connection";
|
|
2878
2897
|
}
|
|
2879
2898
|
var HANDSHAKE_TOKEN_QUERY_PARAM = "token";
|
|
2899
|
+
var HANDSHAKE_CONVERSATION_QUERY_PARAM = "conversationId";
|
|
2880
2900
|
var HANDSHAKE_AUTH_ERROR_HEADER = "x-websocket-auth-error";
|
|
2901
|
+
var CONTROL_BUFFER_LIMIT = 16;
|
|
2881
2902
|
var HANDSHAKE_BODY_CAP = 4096;
|
|
2882
2903
|
var HANDSHAKE_BODY_WAIT_MS = 2e3;
|
|
2883
|
-
function buildHandshakeUrl(endpoint, token) {
|
|
2904
|
+
function buildHandshakeUrl(endpoint, token, conversationId) {
|
|
2884
2905
|
const url = new URL(endpoint);
|
|
2885
2906
|
url.searchParams.set(HANDSHAKE_TOKEN_QUERY_PARAM, token);
|
|
2907
|
+
if (conversationId && conversationId.trim()) {
|
|
2908
|
+
url.searchParams.set(HANDSHAKE_CONVERSATION_QUERY_PARAM, conversationId.trim());
|
|
2909
|
+
}
|
|
2886
2910
|
return url.toString();
|
|
2887
2911
|
}
|
|
2888
2912
|
function conversationWebSocketEndpoint(endpoint) {
|
|
@@ -2891,8 +2915,8 @@ function conversationWebSocketEndpoint(endpoint) {
|
|
|
2891
2915
|
url.pathname = url.pathname.replace(/\/$/, "") + "/ws/conversation";
|
|
2892
2916
|
return url.toString();
|
|
2893
2917
|
}
|
|
2894
|
-
function createHandshakeSocket(endpoint, token, handshakeTimeout) {
|
|
2895
|
-
return new WebSocket(buildHandshakeUrl(endpoint, token), {
|
|
2918
|
+
function createHandshakeSocket(endpoint, token, handshakeTimeout, conversationId) {
|
|
2919
|
+
return new WebSocket(buildHandshakeUrl(endpoint, token, conversationId), {
|
|
2896
2920
|
headers: { Authorization: `Bearer ${token}` },
|
|
2897
2921
|
...handshakeTimeout === void 0 ? {} : { handshakeTimeout }
|
|
2898
2922
|
});
|
|
@@ -2982,6 +3006,16 @@ var WsClient = class {
|
|
|
2982
3006
|
disconnectHandlers = /* @__PURE__ */ new Set();
|
|
2983
3007
|
/** 由 close()/ensureConnected 主动关闭 → 不广播 disconnect(非异常断连)。 */
|
|
2984
3008
|
intentionalClose = false;
|
|
3009
|
+
/**
|
|
3010
|
+
* issue #257:零订阅者时到达的控制帧。
|
|
3011
|
+
*
|
|
3012
|
+
* 后端 `redeliverPending` 的重投帧跟 `auth_success` 挨着发,而 CLI 挂上 onControl
|
|
3013
|
+
* 要晚好几个网络往返(timeline 回放、附件上传)。`dispatchControl` 的循环在零订阅者时
|
|
3014
|
+
* 一次都不转 —— 帧静默消失,与「后端根本没发」完全同形。攒着,等第一个订阅者来取。
|
|
3015
|
+
*/
|
|
3016
|
+
controlBuffer = [];
|
|
3017
|
+
/** 缓冲区溢出丢掉的帧数。丢可以,静默丢不行——调用方要分得清「没发」与「我扔了」。 */
|
|
3018
|
+
droppedControl = 0;
|
|
2985
3019
|
/**
|
|
2986
3020
|
* 订阅「流进行中 socket 异常断连」(后端重启 / 网络闪断)。主动 close() 不触发。
|
|
2987
3021
|
* iterator 订阅它 → 断连时 finish()(incomplete 终态),杜绝 await consume 永久挂死。
|
|
@@ -3010,7 +3044,8 @@ var WsClient = class {
|
|
|
3010
3044
|
message: "no access token; run `hcm login`"
|
|
3011
3045
|
});
|
|
3012
3046
|
}
|
|
3013
|
-
this.
|
|
3047
|
+
this.controlBuffer = [];
|
|
3048
|
+
this.ws = createHandshakeSocket(this.opts.endpoint, tok, void 0, this.opts.conversationId);
|
|
3014
3049
|
return new Promise((resolve6, reject2) => {
|
|
3015
3050
|
const settle = (fn) => {
|
|
3016
3051
|
off();
|
|
@@ -3131,10 +3166,22 @@ var WsClient = class {
|
|
|
3131
3166
|
onControl(fn) {
|
|
3132
3167
|
const h = { kind: "control", fn };
|
|
3133
3168
|
this.handlers.push(h);
|
|
3169
|
+
if (this.controlBuffer.length) {
|
|
3170
|
+
const pending2 = this.controlBuffer;
|
|
3171
|
+
this.controlBuffer = [];
|
|
3172
|
+
for (const ev of pending2) fn(ev);
|
|
3173
|
+
}
|
|
3134
3174
|
return () => {
|
|
3135
3175
|
this.handlers = this.handlers.filter((x) => x !== h);
|
|
3136
3176
|
};
|
|
3137
3177
|
}
|
|
3178
|
+
/**
|
|
3179
|
+
* 建连窗口里被缓冲区挤掉的控制帧数(填空必自陈)。
|
|
3180
|
+
* 非 0 意味着这条连接错过了那么多张确认卡 / 追问,调用方该据此提示用户去列一次未决暂停。
|
|
3181
|
+
*/
|
|
3182
|
+
droppedControlFrames() {
|
|
3183
|
+
return this.droppedControl;
|
|
3184
|
+
}
|
|
3138
3185
|
isReady() {
|
|
3139
3186
|
return this.ready;
|
|
3140
3187
|
}
|
|
@@ -3206,7 +3253,18 @@ var WsClient = class {
|
|
|
3206
3253
|
for (const h of this.handlers) if (h.kind === "connection") h.fn(msg);
|
|
3207
3254
|
}
|
|
3208
3255
|
dispatchControl(ev) {
|
|
3209
|
-
|
|
3256
|
+
const subscribers = this.handlers.filter(
|
|
3257
|
+
(h) => h.kind === "control"
|
|
3258
|
+
);
|
|
3259
|
+
if (!subscribers.length) {
|
|
3260
|
+
this.controlBuffer.push(ev);
|
|
3261
|
+
while (this.controlBuffer.length > CONTROL_BUFFER_LIMIT) {
|
|
3262
|
+
this.controlBuffer.shift();
|
|
3263
|
+
this.droppedControl++;
|
|
3264
|
+
}
|
|
3265
|
+
return;
|
|
3266
|
+
}
|
|
3267
|
+
for (const h of subscribers) h.fn(ev);
|
|
3210
3268
|
}
|
|
3211
3269
|
};
|
|
3212
3270
|
|
|
@@ -3255,6 +3313,7 @@ function buildSteer(content, conversationId) {
|
|
|
3255
3313
|
}
|
|
3256
3314
|
|
|
3257
3315
|
// src/chat/stream-iterator.ts
|
|
3316
|
+
var SERVER_ERROR_GRACE_MS = 300;
|
|
3258
3317
|
async function sendMessageAndStream(ws, prompt, opts = {}) {
|
|
3259
3318
|
const conversationId = opts.conversationId ?? randomUUID2();
|
|
3260
3319
|
const commandId = randomUUID2();
|
|
@@ -3277,6 +3336,16 @@ async function sendMessageAndStream(ws, prompt, opts = {}) {
|
|
|
3277
3336
|
offDisconnect?.();
|
|
3278
3337
|
};
|
|
3279
3338
|
const offDisconnect = ws.onDisconnect?.(() => finish());
|
|
3339
|
+
let lastServerError = null;
|
|
3340
|
+
let serverErrorWaiters = [];
|
|
3341
|
+
ws.onConnection?.((msg) => {
|
|
3342
|
+
const m = msg;
|
|
3343
|
+
if (!m || m.type !== "error") return;
|
|
3344
|
+
lastServerError = { code: m.code, message: m.message };
|
|
3345
|
+
const waiting = serverErrorWaiters;
|
|
3346
|
+
serverErrorWaiters = [];
|
|
3347
|
+
for (const w of waiting) w(lastServerError);
|
|
3348
|
+
});
|
|
3280
3349
|
const off = ws.onEvent((ev) => {
|
|
3281
3350
|
if (done) return;
|
|
3282
3351
|
if (ev.requestId !== commandId) return;
|
|
@@ -3367,7 +3436,27 @@ async function sendMessageAndStream(ws, prompt, opts = {}) {
|
|
|
3367
3436
|
if (ev.conversationId === conversationId) fn(ev);
|
|
3368
3437
|
});
|
|
3369
3438
|
const sendCommand = (command) => ws.send(command);
|
|
3370
|
-
|
|
3439
|
+
const serverError = (graceMs = SERVER_ERROR_GRACE_MS) => {
|
|
3440
|
+
if (lastServerError) return Promise.resolve(lastServerError);
|
|
3441
|
+
if (graceMs <= 0) return Promise.resolve(null);
|
|
3442
|
+
return new Promise((resolve6) => {
|
|
3443
|
+
let settled = false;
|
|
3444
|
+
const onFrame = (f) => {
|
|
3445
|
+
if (settled) return;
|
|
3446
|
+
settled = true;
|
|
3447
|
+
clearTimeout(timer);
|
|
3448
|
+
resolve6(f);
|
|
3449
|
+
};
|
|
3450
|
+
const timer = setTimeout(() => {
|
|
3451
|
+
if (settled) return;
|
|
3452
|
+
settled = true;
|
|
3453
|
+
serverErrorWaiters = serverErrorWaiters.filter((w) => w !== onFrame);
|
|
3454
|
+
resolve6(null);
|
|
3455
|
+
}, graceMs);
|
|
3456
|
+
serverErrorWaiters.push(onFrame);
|
|
3457
|
+
});
|
|
3458
|
+
};
|
|
3459
|
+
return { conversationId, commandId, events, cancel, onControl, sendCommand, serverError };
|
|
3371
3460
|
}
|
|
3372
3461
|
|
|
3373
3462
|
// src/chat/delegation-constants.ts
|
|
@@ -3831,6 +3920,126 @@ async function fetchRecentConversations(http, limit = 10) {
|
|
|
3831
3920
|
return { rows: result.rows, total: result.total };
|
|
3832
3921
|
}
|
|
3833
3922
|
|
|
3923
|
+
// src/chat/interactions.ts
|
|
3924
|
+
var RESPOND_TIMEOUT_MS = 18e4;
|
|
3925
|
+
async function listPendingInteractions(http, agentId, conversationId) {
|
|
3926
|
+
const resp = await http.get(
|
|
3927
|
+
`/api/agents/${agentId}/conversations/${conversationId}/interactions`,
|
|
3928
|
+
{ params: { status: "pending" } }
|
|
3929
|
+
);
|
|
3930
|
+
const body = resp.data?.data ?? resp.data;
|
|
3931
|
+
const rows = Array.isArray(body?.interactions) ? body.interactions : [];
|
|
3932
|
+
return rows;
|
|
3933
|
+
}
|
|
3934
|
+
var RESPOND_NEXT_STEP = {
|
|
3935
|
+
// TOOL_EXECUTION_FAILED:这条路上它表达的是「确认已过期或不存在」(见 handleWriteConfirm 的 catch)
|
|
3936
|
+
"5006": "\u8BE5\u6682\u505C\u5DF2\u8FC7\u671F\uFF08\u9ED8\u8BA4 5 \u5206\u949F\uFF09\u6216\u5DF2\u88AB\u5904\u7406\uFF1A\u7528 `hcm interactions list --conversation <\u4F1A\u8BDD>` \u91CD\u65B0\u770B\u4E00\u773C\u8FD8\u5269\u54EA\u4E9B\uFF1B\u90FD\u6CA1\u6709\u4E86\u5C31\u91CD\u53D1\u539F\u59CB\u6307\u4EE4",
|
|
3937
|
+
"5004": "\u65E0\u6743\u56DE\u5E94\u6B64\u6682\u505C\uFF1A\u5B83\u5C5E\u4E8E\u522B\u7684\u7528\u6237\u6216\u522B\u7684\u4F1A\u8BDD\uFF1B\u786E\u8BA4 --conversation \u4E0E\u767B\u5F55\u8EAB\u4EFD\u5BF9\u5F97\u4E0A\uFF08hcm identity list\uFF09",
|
|
3938
|
+
"5011": "\u8FD9\u4E2A\u4F1A\u8BDD\u8FD8\u6709\u522B\u7684\u672A\u51B3\u6682\u505C\u6321\u7740\uFF1A\u5148 `hcm interactions list --conversation <\u4F1A\u8BDD>` \u9010\u6761\u5904\u7406\u5B8C",
|
|
3939
|
+
"9001": "\u540E\u7AEF\u5904\u7406\u786E\u8BA4\u65F6\u5185\u90E8\u51FA\u9519\uFF1A\u628A traceId \u4E00\u8D77\u62A5\u7ED9\u7814\u53D1\uFF1B\u91CD\u8BD5\u524D\u5148 list \u4E00\u6B21\u786E\u8BA4\u8FD9\u6761\u8FD8\u5728"
|
|
3940
|
+
};
|
|
3941
|
+
async function respondToInteraction(ws, opts) {
|
|
3942
|
+
const { conversationId, interactionId, decision } = opts;
|
|
3943
|
+
const timeoutMs = opts.timeoutMs ?? RESPOND_TIMEOUT_MS;
|
|
3944
|
+
return new Promise((resolve6, reject2) => {
|
|
3945
|
+
let settled = false;
|
|
3946
|
+
const finish = (fn) => {
|
|
3947
|
+
if (settled) return;
|
|
3948
|
+
settled = true;
|
|
3949
|
+
clearTimeout(timer);
|
|
3950
|
+
offControl();
|
|
3951
|
+
offConnection();
|
|
3952
|
+
offDisconnect();
|
|
3953
|
+
fn();
|
|
3954
|
+
};
|
|
3955
|
+
const offControl = ws.onControl((ev) => {
|
|
3956
|
+
if (ev.type !== "control.interaction.resolved") return;
|
|
3957
|
+
const p = ev.payload;
|
|
3958
|
+
if (p.interactionId !== interactionId) return;
|
|
3959
|
+
if (p.phase === "RESUMED") {
|
|
3960
|
+
opts.onAccepted?.();
|
|
3961
|
+
return;
|
|
3962
|
+
}
|
|
3963
|
+
if (p.phase !== "TERMINAL") return;
|
|
3964
|
+
finish(
|
|
3965
|
+
() => resolve6({
|
|
3966
|
+
interactionId,
|
|
3967
|
+
type: p.type ?? null,
|
|
3968
|
+
decision: p.decision ?? null,
|
|
3969
|
+
status: p.status ?? null,
|
|
3970
|
+
text: p.text ?? null,
|
|
3971
|
+
originAgentPath: p.originAgentPath ?? null
|
|
3972
|
+
})
|
|
3973
|
+
);
|
|
3974
|
+
});
|
|
3975
|
+
const offConnection = ws.onConnection((msg) => {
|
|
3976
|
+
const m = msg;
|
|
3977
|
+
if (m?.type !== "error") return;
|
|
3978
|
+
const serverCode = m.code === void 0 || m.code === null ? void 0 : String(m.code);
|
|
3979
|
+
finish(
|
|
3980
|
+
() => reject2(
|
|
3981
|
+
new CliError({
|
|
3982
|
+
code: "BUSINESS_RULE_VIOLATION" /* BUSINESS_RULE_VIOLATION */,
|
|
3983
|
+
message: m.message || `\u56DE\u5E94\u6682\u505C\u88AB\u62D2\uFF08\u670D\u52A1\u7AEF\u7801 ${serverCode ?? "\u672A\u7ED9"}\uFF09`,
|
|
3984
|
+
traceId: m.traceId,
|
|
3985
|
+
context: {
|
|
3986
|
+
interactionId,
|
|
3987
|
+
...serverCode ? { responseCode: serverCode } : {},
|
|
3988
|
+
...m.reason && m.reason !== "null" ? { details: m.reason } : {},
|
|
3989
|
+
nextStep: serverCode && RESPOND_NEXT_STEP[serverCode] || "\u7528 `hcm interactions list --conversation <\u4F1A\u8BDD>` \u770B\u8FD9\u6761\u8FD8\u5728\u4E0D\u5728\uFF1B\u5728\u5C31\u91CD\u8BD5\uFF0C\u4E0D\u5728\u8BF4\u660E\u5B83\u5DF2\u8FC7\u671F\u6216\u5DF2\u88AB\u5904\u7406"
|
|
3990
|
+
}
|
|
3991
|
+
})
|
|
3992
|
+
)
|
|
3993
|
+
);
|
|
3994
|
+
});
|
|
3995
|
+
const offDisconnect = ws.onDisconnect(
|
|
3996
|
+
() => finish(
|
|
3997
|
+
() => reject2(
|
|
3998
|
+
new CliError({
|
|
3999
|
+
code: "NETWORK_ERROR" /* NETWORK_ERROR */,
|
|
4000
|
+
message: `\u7B49\u5F85\u6682\u505C\u7EC8\u6001\u65F6\u8FDE\u63A5\u65AD\u5F00: interactionId=${interactionId}`,
|
|
4001
|
+
context: {
|
|
4002
|
+
interactionId,
|
|
4003
|
+
// 决定可能已经落库了——续跑是同步跑的,断的只是回程。不能让用户当成「没发生」。
|
|
4004
|
+
nextStep: "\u51B3\u5B9A\u53EF\u80FD\u5DF2\u88AB\u53D7\u7406\uFF1A\u5148 `hcm interactions list --conversation <\u4F1A\u8BDD>` \u770B\u5B83\u8FD8\u5728\u4E0D\u5728\uFF0C\u4E0D\u5728\u5C31\u522B\u91CD\u53D1"
|
|
4005
|
+
}
|
|
4006
|
+
})
|
|
4007
|
+
)
|
|
4008
|
+
)
|
|
4009
|
+
);
|
|
4010
|
+
const timer = setTimeout(() => {
|
|
4011
|
+
finish(
|
|
4012
|
+
() => reject2(
|
|
4013
|
+
new CliError({
|
|
4014
|
+
code: "TIMEOUT" /* TIMEOUT */,
|
|
4015
|
+
message: `\u7B49\u5F85\u6682\u505C\u7EC8\u6001\u8D85\u65F6\uFF08${timeoutMs}ms\uFF09: interactionId=${interactionId}`,
|
|
4016
|
+
context: {
|
|
4017
|
+
interactionId,
|
|
4018
|
+
// 只收到 RESUMED 就超时是常态(续跑是一次完整 LLM 轮次),别说成「失败」。
|
|
4019
|
+
nextStep: "\u7EED\u8DD1\u53EF\u80FD\u8FD8\u5728\u8FDB\u884C\uFF1A\u7528 `--timeout` \u7ED9\u66F4\u957F\u65F6\u95F4\uFF0C\u6216 `hcm interactions list --conversation <\u4F1A\u8BDD>` \u786E\u8BA4\u5B83\u5DF2\u7ECF\u4E0D\u5728\u672A\u51B3\u6E05\u5355\u91CC\uFF08\u4E0D\u5728 = \u5DF2\u5904\u7406\u5B8C\uFF09"
|
|
4020
|
+
}
|
|
4021
|
+
})
|
|
4022
|
+
)
|
|
4023
|
+
);
|
|
4024
|
+
}, timeoutMs);
|
|
4025
|
+
try {
|
|
4026
|
+
ws.send(commandFor(decision, interactionId, conversationId));
|
|
4027
|
+
} catch (e) {
|
|
4028
|
+
finish(() => reject2(e));
|
|
4029
|
+
}
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
function commandFor(decision, interactionId, conversationId) {
|
|
4033
|
+
switch (decision.kind) {
|
|
4034
|
+
case "confirm":
|
|
4035
|
+
return buildConfirm(interactionId, conversationId);
|
|
4036
|
+
case "reject":
|
|
4037
|
+
return buildReject(interactionId, conversationId, decision.reason);
|
|
4038
|
+
case "answer":
|
|
4039
|
+
return buildAnswer(interactionId, conversationId, decision.answer, decision.choiceIndex);
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4042
|
+
|
|
3834
4043
|
// src/mini/types.ts
|
|
3835
4044
|
var MINI_CONTEXT_FILE = "hcm.context.json";
|
|
3836
4045
|
var MINI_STATE_DIR = ".hcm";
|
|
@@ -6488,6 +6697,31 @@ async function bootstrapTenant(http, bootstrapKey, req) {
|
|
|
6488
6697
|
});
|
|
6489
6698
|
return resp.data?.data ?? resp.data;
|
|
6490
6699
|
}
|
|
6700
|
+
async function resetTenant(http, tenantId) {
|
|
6701
|
+
const { data: envelope2 } = await http.post("/api/models/DataPackage/action/resetTenant", {
|
|
6702
|
+
tenantId,
|
|
6703
|
+
confirmation: `RESET_TENANT:${tenantId}`
|
|
6704
|
+
}, { __skipRetry: true, maxRedirects: 0 });
|
|
6705
|
+
const receipt = envelope2?.data;
|
|
6706
|
+
const text3 = (value) => typeof value === "string" && value.trim().length > 0;
|
|
6707
|
+
const nonPg = receipt?.nonPgSurface;
|
|
6708
|
+
if (!envelope2 || envelope2.error != null || envelope2.success === false || !receipt || Array.isArray(receipt) || receipt.tenantId !== tenantId || !text3(receipt.runId) || receipt.state !== "FACTORY_BASELINE" || receipt.stateScope !== "POSTGRESQL" || !["deletedRows", "touchedTables", "reconciledComponents", "restoredRows"].every((key) => Number.isSafeInteger(receipt[key]) && receipt[key] >= 0) || !["pgVerified", "overallVerified", "journalReconciledMarked"].every((key) => typeof receipt[key] === "boolean") || !nonPg || !text3(nonPg.status) || !text3(nonPg.reason) || !text3(nonPg.nextStep) || !Array.isArray(nonPg.unhandledSurfaces) || !nonPg.unhandledSurfaces.length || !nonPg.unhandledSurfaces.every(text3)) {
|
|
6709
|
+
throw new CliError({
|
|
6710
|
+
code: "PROTOCOL_UNSUPPORTED" /* PROTOCOL_UNSUPPORTED */,
|
|
6711
|
+
message: "\u91CD\u7F6E\u63A5\u53E3\u672A\u8FD4\u56DE\u5B8C\u6574\u4E14\u5339\u914D\u76EE\u6807\u7684\u73B0\u5F79\u56DE\u6267\uFF0C\u7ED3\u679C\u672A\u786E\u8BA4\uFF1B\u672A\u5C06\u7F3A\u503C\u8865\u6210\u96F6\u6216\u6210\u529F\u3002",
|
|
6712
|
+
context: {
|
|
6713
|
+
reasonCode: "TENANT_RESET_RECEIPT_UNKNOWN",
|
|
6714
|
+
// 坐标来自未确认回执,只供追查;保留原值,绝不据此声明成功。
|
|
6715
|
+
details: {
|
|
6716
|
+
...envelope2?.error ? { error: envelope2.error } : {},
|
|
6717
|
+
...receipt !== void 0 ? { unverifiedReceipt: receipt } : {}
|
|
6718
|
+
},
|
|
6719
|
+
nextStep: "\u4E0D\u8981\u76F2\u76EE\u91CD\u8DD1\u91CD\u7F6E\uFF1B\u6838\u67E5\u670D\u52A1\u7AEF\u91CD\u7F6E\u6D41\u6C34\u4E0E\u5F53\u524D\u79DF\u6237\u72B6\u6001\u3002"
|
|
6720
|
+
}
|
|
6721
|
+
});
|
|
6722
|
+
}
|
|
6723
|
+
return receipt;
|
|
6724
|
+
}
|
|
6491
6725
|
|
|
6492
6726
|
// src/meta/tenant-meta.ts
|
|
6493
6727
|
async function listTenantMeta(http, opts = {}) {
|
|
@@ -22152,6 +22386,7 @@ export {
|
|
|
22152
22386
|
CODE_UNBIND_READBACK_UNREADABLE,
|
|
22153
22387
|
CODE_UNBIND_REFUSED,
|
|
22154
22388
|
CODE_WORDS,
|
|
22389
|
+
CONTROL_BUFFER_LIMIT,
|
|
22155
22390
|
CREDENTIAL_STORE_MODES,
|
|
22156
22391
|
CliError,
|
|
22157
22392
|
CliErrorCode,
|
|
@@ -22184,7 +22419,9 @@ export {
|
|
|
22184
22419
|
FORCE_STALE_FLAG_TEXT,
|
|
22185
22420
|
GATE_COMPONENTS,
|
|
22186
22421
|
HANDSHAKE_AUTH_ERROR_HEADER,
|
|
22422
|
+
HANDSHAKE_CONVERSATION_QUERY_PARAM,
|
|
22187
22423
|
HANDSHAKE_TOKEN_QUERY_PARAM,
|
|
22424
|
+
HCM_FIELD_RAW_KEYS,
|
|
22188
22425
|
HCM_LANG_ENV,
|
|
22189
22426
|
HcmClient,
|
|
22190
22427
|
IMPERSONATION_ACTIVE_PATH,
|
|
@@ -22261,6 +22498,7 @@ export {
|
|
|
22261
22498
|
VERDICTS2 as RECONCILE_VERDICTS,
|
|
22262
22499
|
RECOVERY_WORDS,
|
|
22263
22500
|
REQUIRED_SECTIONS,
|
|
22501
|
+
RESPOND_TIMEOUT_MS,
|
|
22264
22502
|
RESTORE_CODES,
|
|
22265
22503
|
RISK_CODES,
|
|
22266
22504
|
RISK_FILE,
|
|
@@ -22275,6 +22513,7 @@ export {
|
|
|
22275
22513
|
RefStore,
|
|
22276
22514
|
RestoreFailed,
|
|
22277
22515
|
SDK_VERSION,
|
|
22516
|
+
SERVER_ERROR_GRACE_MS,
|
|
22278
22517
|
STATUSES,
|
|
22279
22518
|
STEP_NOTHING,
|
|
22280
22519
|
STEP_PROBE,
|
|
@@ -22457,6 +22696,7 @@ export {
|
|
|
22457
22696
|
listEnvs,
|
|
22458
22697
|
listIdentities,
|
|
22459
22698
|
listModels,
|
|
22699
|
+
listPendingInteractions,
|
|
22460
22700
|
listProfiles,
|
|
22461
22701
|
listTenantMeta,
|
|
22462
22702
|
listWorkspaceFiles,
|
|
@@ -22535,6 +22775,7 @@ export {
|
|
|
22535
22775
|
repoIssueUrl,
|
|
22536
22776
|
requestCliAuthorization,
|
|
22537
22777
|
resetSettingItem,
|
|
22778
|
+
resetTenant,
|
|
22538
22779
|
resolveActiveEnv,
|
|
22539
22780
|
resolveActiveIdentity,
|
|
22540
22781
|
resolveActiveProfile,
|
|
@@ -22546,6 +22787,7 @@ export {
|
|
|
22546
22787
|
resolveProjectEnvironment,
|
|
22547
22788
|
resolveRefs,
|
|
22548
22789
|
resolveSkillInstallOrder,
|
|
22790
|
+
respondToInteraction,
|
|
22549
22791
|
riskFromArtifacts,
|
|
22550
22792
|
roundAge,
|
|
22551
22793
|
roundWarning,
|