engine7 7.1.141 → 7.1.142
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/bg-worker.mjs +15 -3
- package/dist/cli.mjs +2758 -242
- package/dist/engine-startup.mjs +3111 -2143
- package/dist/main.mjs +3117 -2149
- package/dist/recall-worker.mjs +14 -2
- package/dist/sqlite-maintenance-worker.mjs +1 -1
- package/dist/topics-worker.mjs +56 -10
- package/dist/travel-activation-database.mjs +1 -1
- package/dist/travel-authority.mjs +1 -1
- package/dist/travel-console.mjs +1 -1
- package/dist/travel-controller.mjs +2 -2
- package/dist/travel-data.mjs +13 -13
- package/dist/travel-gateway.mjs +535 -142
- package/dist/travel-host.mjs +417 -94
- package/dist/travel-initial-baseline.mjs +16 -14
- package/dist/travel-node-data.mjs +3 -7
- package/dist/travel-node.mjs +31 -17
- package/dist/travel-pairing.mjs +536 -142
- package/dist/web-console.mjs +821 -1422
- package/dlls/win32/msvcp140.dll +0 -0
- package/dlls/win32/vcruntime140.dll +0 -0
- package/dlls/win32/vcruntime140_1.dll +0 -0
- package/package.json +5 -3
package/dist/travel-host.mjs
CHANGED
|
@@ -1698,7 +1698,7 @@ function validateTravelChannelConfiguration(channels) {
|
|
|
1698
1698
|
if (!["feishu", "discord", "wechat"].includes(name)) throw new Error("TRAVEL_CHANNEL_NOT_CONTROLLED");
|
|
1699
1699
|
if (value2.mode !== "remote-only") throw new Error("TRAVEL_REMOTE_ONLY_REQUIRED");
|
|
1700
1700
|
const hasPlatformSecret = (block) => block && typeof block === "object" && Object.entries(block).some(([key2, v]) => ["appSecret", "token", "accessToken", "tenantAccessToken", "app_secret", "botToken", "bot_token"].includes(key2) && typeof v === "string" && !!v.trim() || v && typeof v === "object" && hasPlatformSecret(v));
|
|
1701
|
-
if (hasPlatformSecret(value2)
|
|
1701
|
+
if (hasPlatformSecret(value2)) throw new Error("TRAVEL_PLATFORM_SECRET_PRESENT");
|
|
1702
1702
|
let url;
|
|
1703
1703
|
try {
|
|
1704
1704
|
url = new URL(value2.gatewayUrl);
|
|
@@ -15245,6 +15245,10 @@ function rowElements(state2, rowCap) {
|
|
|
15245
15245
|
}
|
|
15246
15246
|
}
|
|
15247
15247
|
flush();
|
|
15248
|
+
if (state2.steerNotes?.length) {
|
|
15249
|
+
for (const s of state2.steerNotes) lines.push(`\u21AA \u63D2\u8BDD\uFF1A${s.length > ARGS_MAX ? s.slice(0, ARGS_MAX - 1) + "\u2026" : s}`);
|
|
15250
|
+
flush();
|
|
15251
|
+
}
|
|
15248
15252
|
const lt = state2.liveThink;
|
|
15249
15253
|
if (lt) {
|
|
15250
15254
|
const sec = Math.max(1, Math.round((Date.now() - lt.start) / 1e3));
|
|
@@ -15255,6 +15259,9 @@ function rowElements(state2, rowCap) {
|
|
|
15255
15259
|
} else if (state2.status === "run") {
|
|
15256
15260
|
els.push({ tag: "div", text: { tag: "lark_md", content: `*${spinnerFrame()} ${state2.verb}\u2026\uFF08${fmtDur(Math.max(1, Math.round((Date.now() - state2.startedAt) / 1e3)))}\uFF09*` } });
|
|
15257
15261
|
}
|
|
15262
|
+
if (state2.stopAction && (state2.status === "run" || state2.status === "wait")) {
|
|
15263
|
+
els.push({ tag: "action", actions: [{ tag: "button", type: "default", text: { tag: "plain_text", content: "\u505C\u6B62" }, value: state2.stopAction }] });
|
|
15264
|
+
}
|
|
15258
15265
|
return { els, dropped };
|
|
15259
15266
|
}
|
|
15260
15267
|
function buildProcessCard(state2, level = 2) {
|
|
@@ -15447,6 +15454,10 @@ function buildProcessCardV2At(state2, level, panelCap) {
|
|
|
15447
15454
|
}
|
|
15448
15455
|
}
|
|
15449
15456
|
flushPlain();
|
|
15457
|
+
if (state2.steerNotes?.length) {
|
|
15458
|
+
for (const s of state2.steerNotes) plain.push(`\u21AA \u63D2\u8BDD\uFF1A${capStr(s, ARGS_MAX)}`);
|
|
15459
|
+
flushPlain();
|
|
15460
|
+
}
|
|
15450
15461
|
const lt = state2.liveThink;
|
|
15451
15462
|
if (lt) {
|
|
15452
15463
|
const sec = Math.max(1, Math.round((Date.now() - lt.start) / 1e3));
|
|
@@ -15457,6 +15468,9 @@ function buildProcessCardV2At(state2, level, panelCap) {
|
|
|
15457
15468
|
} else if (state2.status === "run") {
|
|
15458
15469
|
els.push({ tag: "markdown", content: `*${spinnerFrame()} ${state2.verb}\u2026\uFF08${fmtDur(Math.max(1, Math.round((Date.now() - state2.startedAt) / 1e3)))}\uFF09*` });
|
|
15459
15470
|
}
|
|
15471
|
+
if (state2.stopAction && (state2.status === "run" || state2.status === "wait")) {
|
|
15472
|
+
els.push(buttonRow([{ tag: "button", type: "default", text: { tag: "plain_text", content: "\u505C\u6B62" }, value: state2.stopAction }]));
|
|
15473
|
+
}
|
|
15460
15474
|
const notes = [];
|
|
15461
15475
|
if (state2.usage) notes.push(state2.usage);
|
|
15462
15476
|
if (state2.status === "wait") notes.push("\u70B9\u6309\u94AE\u5BA1\u6279\uFF0C\u4E5F\u53EF\u76F4\u63A5\u6253\u5B57");
|
|
@@ -15568,7 +15582,7 @@ var init_process_card = __esm({
|
|
|
15568
15582
|
this.summarySent = false;
|
|
15569
15583
|
this.terminal = null;
|
|
15570
15584
|
this.patchFailures = 0;
|
|
15571
|
-
this.state = { repoName: this.repoName, prompt, status: "run", rows: [], finalText: "", usage: "", liveThink: null, startedAt: Date.now(), verb: VERBS[Math.floor(Math.random() * VERBS.length)], presentation: this.options.presentation };
|
|
15585
|
+
this.state = { repoName: this.repoName, prompt, status: "run", rows: [], finalText: "", usage: "", liveThink: null, startedAt: Date.now(), verb: VERBS[Math.floor(Math.random() * VERBS.length)], presentation: this.options.presentation, requestId: this.options.requestId };
|
|
15572
15586
|
this.lastPushKey = this.pushKey();
|
|
15573
15587
|
this.messageId = null;
|
|
15574
15588
|
this.channelV = null;
|
|
@@ -15589,7 +15603,10 @@ var init_process_card = __esm({
|
|
|
15589
15603
|
}
|
|
15590
15604
|
/** Mode decisions can start native progress without awaiting any channel I/O. */
|
|
15591
15605
|
start() {
|
|
15592
|
-
if (!this.ended && !this.started && (this.nativeCapable() || this.legacyCapable())) this.beginInBackground();
|
|
15606
|
+
if (!this.ended && !this.started && (this.nativeCapable() || this.legacyCapable() || this.progressCapable())) this.beginInBackground();
|
|
15607
|
+
}
|
|
15608
|
+
progressCapable() {
|
|
15609
|
+
return !!this.adapter.sendProgress && !!this.adapter.updateProgress && !!this.adapter.removeProgress;
|
|
15593
15610
|
}
|
|
15594
15611
|
nativeCapable() {
|
|
15595
15612
|
const ad = this.adapter;
|
|
@@ -15603,10 +15620,16 @@ var init_process_card = __esm({
|
|
|
15603
15620
|
}
|
|
15604
15621
|
ensureStarted() {
|
|
15605
15622
|
const ad = this.adapter;
|
|
15606
|
-
if (this.options.autoStart && !this.started && (this.nativeCapable() || this.legacyCapable() || ad.sendPreview && ad.editPreview)) this.beginInBackground();
|
|
15623
|
+
if (this.options.autoStart && !this.started && (this.nativeCapable() || this.legacyCapable() || this.progressCapable() || ad.sendPreview && ad.editPreview)) this.beginInBackground();
|
|
15607
15624
|
}
|
|
15608
15625
|
async createCard() {
|
|
15609
15626
|
const ad = this.adapter;
|
|
15627
|
+
if (this.progressCapable()) {
|
|
15628
|
+
this.messageId = await ad.sendProgress(this.target, structuredClone(this.state));
|
|
15629
|
+
this.channelV = "progress";
|
|
15630
|
+
this.lastPatchAt = Date.now();
|
|
15631
|
+
return;
|
|
15632
|
+
}
|
|
15610
15633
|
if (!this.nativeCapable() && this.legacyCapable()) return this.createLegacyCard();
|
|
15611
15634
|
if (!this.nativeCapable() && this.options.allowLegacyCard === false) {
|
|
15612
15635
|
if (!ad.sendPreview || !ad.editPreview) throw new Error("\u65E0\u8FC7\u7A0B\u5361\u6216\u53EF\u7F16\u8F91\u6D88\u606F\u80FD\u529B");
|
|
@@ -15653,8 +15676,10 @@ var init_process_card = __esm({
|
|
|
15653
15676
|
}
|
|
15654
15677
|
async removeCard() {
|
|
15655
15678
|
if (this.messageId) {
|
|
15656
|
-
if (
|
|
15657
|
-
|
|
15679
|
+
if (this.channelV === "progress" && this.adapter.removeProgress) {
|
|
15680
|
+
await this.adapter.removeProgress(this.messageId);
|
|
15681
|
+
} else if (!this.adapter.deletePreview) throw new Error("\u65E0\u8FC7\u7A0B\u5361\u6E05\u7406\u80FD\u529B");
|
|
15682
|
+
else await this.adapter.deletePreview({ channelId: this.target, messageId: this.messageId });
|
|
15658
15683
|
}
|
|
15659
15684
|
this.messageId = null;
|
|
15660
15685
|
this.cardKitId = null;
|
|
@@ -15665,7 +15690,7 @@ var init_process_card = __esm({
|
|
|
15665
15690
|
/** Shared heartbeat samples state; the push key suppresses unchanged cards. */
|
|
15666
15691
|
startHeartbeat() {
|
|
15667
15692
|
this.stopHeartbeat();
|
|
15668
|
-
const interval = this.channelV === "cardkit" ? 800 : 2500;
|
|
15693
|
+
const interval = this.channelV === "cardkit" || this.channelV === "progress" ? 800 : 2500;
|
|
15669
15694
|
this.heartbeat = setInterval(() => {
|
|
15670
15695
|
if (this.state.status !== "run" && this.state.status !== "wait") {
|
|
15671
15696
|
this.stopHeartbeat();
|
|
@@ -15679,10 +15704,10 @@ var init_process_card = __esm({
|
|
|
15679
15704
|
if (this.heartbeat) clearInterval(this.heartbeat);
|
|
15680
15705
|
this.heartbeat = null;
|
|
15681
15706
|
}
|
|
15682
|
-
onToolUse(name, input, id2) {
|
|
15707
|
+
onToolUse(name, input, id2, inputFull) {
|
|
15683
15708
|
if (this.ended || this.disposed) return;
|
|
15684
15709
|
this.ensureStarted();
|
|
15685
|
-
this.state.rows.push({ kind: "tool", id: id2, name, args: stripCardUnsafe(typeof input === "string" ? input : toolArgsSummary(name, input)), state: "run", out: "", more: 0 });
|
|
15710
|
+
this.state.rows.push({ kind: "tool", id: id2, name, args: stripCardUnsafe(typeof input === "string" ? input : toolArgsSummary(name, input)), state: "run", out: "", more: 0, ...inputFull ? { inputFull: stripCardUnsafe(inputFull.slice(0, OUTFULL_MAX)) } : {} });
|
|
15686
15711
|
if (this.state.status === "wait") this.state.status = "run";
|
|
15687
15712
|
this.schedulePatch();
|
|
15688
15713
|
}
|
|
@@ -15695,7 +15720,7 @@ var init_process_card = __esm({
|
|
|
15695
15720
|
row = this.state.rows.at(-1);
|
|
15696
15721
|
}
|
|
15697
15722
|
if (!row) return;
|
|
15698
|
-
const retain = match?.visible !== false || this.nativeCapable();
|
|
15723
|
+
const retain = match?.visible !== false || this.nativeCapable() || this.progressCapable();
|
|
15699
15724
|
const lines = (out || "").split("\n").filter((line) => line.trim());
|
|
15700
15725
|
row.state = retain && isError ? "err" : "ok";
|
|
15701
15726
|
row.resultVisible = match?.visible;
|
|
@@ -15829,6 +15854,19 @@ var init_process_card = __esm({
|
|
|
15829
15854
|
}
|
|
15830
15855
|
return false;
|
|
15831
15856
|
}
|
|
15857
|
+
/** 1119 cc-desk steer:忙时插话在卡片上留 ↪ 行(过程可见) */
|
|
15858
|
+
onSteer(text2) {
|
|
15859
|
+
if (this.ended || this.disposed) return;
|
|
15860
|
+
this.ensureStarted();
|
|
15861
|
+
this.state.steerNotes = [...this.state.steerNotes ?? [], stripCardUnsafe(oneLine(text2))].slice(-3);
|
|
15862
|
+
this.schedulePatch();
|
|
15863
|
+
}
|
|
15864
|
+
/** 1119 卡片停止钮:设置/清除停止按钮的 action value(run/wait 态渲染) */
|
|
15865
|
+
setStopAction(value2) {
|
|
15866
|
+
if (this.ended || this.disposed) return;
|
|
15867
|
+
this.state.stopAction = value2 ?? void 0;
|
|
15868
|
+
this.schedulePatch();
|
|
15869
|
+
}
|
|
15832
15870
|
turnEnd(finalText, usage, outcome) {
|
|
15833
15871
|
return this.finish(outcome, finalText, usage);
|
|
15834
15872
|
}
|
|
@@ -15864,7 +15902,7 @@ var init_process_card = __esm({
|
|
|
15864
15902
|
return;
|
|
15865
15903
|
}
|
|
15866
15904
|
if (this.patchTimer) return;
|
|
15867
|
-
const min = this.channelV === "cardkit" ? CARDKIT_UPDATE_INTERVAL_MS : PATCH_MIN_INTERVAL_MS;
|
|
15905
|
+
const min = this.channelV === "cardkit" || this.channelV === "progress" ? CARDKIT_UPDATE_INTERVAL_MS : PATCH_MIN_INTERVAL_MS;
|
|
15868
15906
|
const wait = Math.max(0, min - (Date.now() - this.lastPatchAt));
|
|
15869
15907
|
this.patchTimer = setTimeout(() => {
|
|
15870
15908
|
this.patchTimer = null;
|
|
@@ -15879,7 +15917,7 @@ var init_process_card = __esm({
|
|
|
15879
15917
|
await this.creation?.catch(() => {
|
|
15880
15918
|
});
|
|
15881
15919
|
if (this.disposed || this.ended && !final) return;
|
|
15882
|
-
if (final && this.options.discardEmptyOnDone && this.state.status === "done" && !this.state.earlierSteps && !this.state.rows.some((row) => row.kind !== "think") && (!this.messageId || this.adapter.deletePreview)) {
|
|
15920
|
+
if (final && this.options.discardEmptyOnDone && this.state.status === "done" && !this.state.earlierSteps && !this.state.rows.some((row) => row.kind !== "think") && (!this.messageId || this.adapter.deletePreview || this.adapter.removeProgress)) {
|
|
15883
15921
|
await this.removeCard().catch((error) => console.warn("[process-card] \u7A7A\u56DE\u5408\u6E05\u7406\u5931\u8D25:", error instanceof Error ? error.message : String(error)));
|
|
15884
15922
|
return;
|
|
15885
15923
|
}
|
|
@@ -15902,17 +15940,19 @@ var init_process_card = __esm({
|
|
|
15902
15940
|
return `q${r.rid}:${r.settled}:${JSON.stringify(r.answers)}`;
|
|
15903
15941
|
}).join("|");
|
|
15904
15942
|
const bucket = Math.floor((Date.now() - s.startedAt) / LIVE_BUCKET_MS);
|
|
15905
|
-
return JSON.stringify([s.prompt, s.status, rows, s.earlierSteps || 0, s.finalText.length, s.usage, s.liveThink ? `${s.liveThink.text.length}:${s.liveThink.text.slice(-24)}` : "", bucket]);
|
|
15943
|
+
return JSON.stringify([s.prompt, s.status, rows, s.earlierSteps || 0, s.finalText.length, s.usage, s.liveThink ? `${s.liveThink.text.length}:${s.liveThink.text.slice(-24)}` : "", bucket, s.steerNotes?.join("\n").length ?? 0, s.stopAction ? 1 : 0]);
|
|
15906
15944
|
}
|
|
15907
15945
|
async doPatch(final = false) {
|
|
15908
15946
|
if (this.degraded || !this.messageId && this.channelV !== "cardkit") return false;
|
|
15909
15947
|
const key2 = this.pushKey();
|
|
15910
15948
|
if (key2 === this.lastPushKey) return true;
|
|
15911
15949
|
this.lastPatchAt = Date.now();
|
|
15912
|
-
const card = this.channelV === "patch-v1" ? buildProcessCard(this.state) : buildProcessCardV2(this.state) ?? (this.options.allowLegacyCard !== false ? buildProcessCard(this.state) : null);
|
|
15913
|
-
if (this.channelV !== "preview" && !card) return false;
|
|
15950
|
+
const card = this.channelV === "progress" ? null : this.channelV === "patch-v1" ? buildProcessCard(this.state) : buildProcessCardV2(this.state) ?? (this.options.allowLegacyCard !== false ? buildProcessCard(this.state) : null);
|
|
15951
|
+
if (this.channelV !== "preview" && this.channelV !== "progress" && !card) return false;
|
|
15914
15952
|
try {
|
|
15915
|
-
if (this.channelV === "
|
|
15953
|
+
if (this.channelV === "progress" && this.messageId && this.adapter.updateProgress) {
|
|
15954
|
+
await this.adapter.updateProgress(this.messageId, structuredClone(this.state));
|
|
15955
|
+
} else if (this.channelV === "preview" && this.previewHandle && this.adapter.editPreview) {
|
|
15916
15956
|
await this.adapter.editPreview(this.previewHandle, buildProcessText(this.state), this.repoName, final);
|
|
15917
15957
|
} else if (this.channelV === "cardkit" && this.cardKitId && card) {
|
|
15918
15958
|
this.seq++;
|
|
@@ -15971,6 +16011,12 @@ async function handleCcCardAction(data) {
|
|
|
15971
16011
|
const fv = action?.form_value ?? {};
|
|
15972
16012
|
const v = action?.value;
|
|
15973
16013
|
if (!v || v.cc !== 1) return { toast: { type: "info", content: "\u672A\u77E5\u64CD\u4F5C" } };
|
|
16014
|
+
if (v.kind === "stop" && typeof v.key === "string") {
|
|
16015
|
+
const { ccDriverRouter: ccDriverRouter2 } = await Promise.resolve().then(() => (init_router(), router_exports));
|
|
16016
|
+
const session = ccDriverRouter2.hub?.forChatKey(v.key);
|
|
16017
|
+
const stopped = session ? session.stopAll() : false;
|
|
16018
|
+
return { toast: { type: stopped ? "success" : "info", content: stopped ? "\u5DF2\u505C\u6B62\u5F53\u524D\u4EFB\u52A1" : "\u5F53\u524D\u6CA1\u6709\u5728\u8DD1\u7684\u4EFB\u52A1" } };
|
|
16019
|
+
}
|
|
15974
16020
|
if (v.kind === "perm" && v.rid) {
|
|
15975
16021
|
const p = pendingPerms.get(v.rid);
|
|
15976
16022
|
if (!p) return { toast: { type: "info", content: "\u8BE5\u5BA1\u6279\u5DF2\u5904\u7406\u6216\u5DF2\u5931\u6548" } };
|
|
@@ -16394,6 +16440,9 @@ var init_dep_downloader = __esm({
|
|
|
16394
16440
|
function requestError(message, status = 409) {
|
|
16395
16441
|
return Object.assign(new Error(message), { status });
|
|
16396
16442
|
}
|
|
16443
|
+
function ccUserMsg(text2) {
|
|
16444
|
+
return { type: "user", message: { role: "user", content: text2 }, parent_tool_use_id: null };
|
|
16445
|
+
}
|
|
16397
16446
|
function resultToText(content) {
|
|
16398
16447
|
if (typeof content === "string") return content;
|
|
16399
16448
|
if (Array.isArray(content)) {
|
|
@@ -16418,7 +16467,7 @@ function chunkText(text2, maxChars) {
|
|
|
16418
16467
|
if (rest.trim()) chunks.push(rest);
|
|
16419
16468
|
return chunks;
|
|
16420
16469
|
}
|
|
16421
|
-
var MAX_QUEUE, INTERIM_MIN_INTERVAL_MS, INTERIM_MIN_CHARS, MAX_INTERIM_PER_TURN, INTERIM_SNIPPET_CHARS, FINAL_CHUNK_CHARS, CcDriverSession, CcDriverHub;
|
|
16470
|
+
var MAX_QUEUE, INTERIM_MIN_INTERVAL_MS, INTERIM_MIN_CHARS, MAX_INTERIM_PER_TURN, INTERIM_SNIPPET_CHARS, FINAL_CHUNK_CHARS, SteerFeeder, defaultCcRuntimeLoader, ccRuntimeLoader, CcDriverSession, CcDriverHub;
|
|
16422
16471
|
var init_driver = __esm({
|
|
16423
16472
|
"src/cc-driver/driver.ts"() {
|
|
16424
16473
|
"use strict";
|
|
@@ -16433,6 +16482,53 @@ var init_driver = __esm({
|
|
|
16433
16482
|
MAX_INTERIM_PER_TURN = 4;
|
|
16434
16483
|
INTERIM_SNIPPET_CHARS = 600;
|
|
16435
16484
|
FINAL_CHUNK_CHARS = 1500;
|
|
16485
|
+
SteerFeeder = class {
|
|
16486
|
+
pending = [];
|
|
16487
|
+
waiters = [];
|
|
16488
|
+
ended = false;
|
|
16489
|
+
/** 已 yield 给 CLI 的消息数(含首条) */
|
|
16490
|
+
yieldCount = 0;
|
|
16491
|
+
/** 最近一次 yield 的文本(续 turn 卡片的 prompt 用) */
|
|
16492
|
+
lastYield = "";
|
|
16493
|
+
/** 注入一条;返回 false = 已收口,进不了这个流了 */
|
|
16494
|
+
push(text2) {
|
|
16495
|
+
if (this.ended && this.pending.length === 0) return false;
|
|
16496
|
+
this.pending.push(text2);
|
|
16497
|
+
for (const w of this.waiters.splice(0)) w();
|
|
16498
|
+
return true;
|
|
16499
|
+
}
|
|
16500
|
+
/** 收口:吐完 pending 后生成器结束 */
|
|
16501
|
+
close() {
|
|
16502
|
+
this.ended = true;
|
|
16503
|
+
for (const w of this.waiters.splice(0)) w();
|
|
16504
|
+
}
|
|
16505
|
+
/** 还有没被 turn 消化的输入吗(未 shift 的 pending + 已 yield 未出 result 的) */
|
|
16506
|
+
expectsMoreTurns(turnsSeen) {
|
|
16507
|
+
return this.pending.length > 0 || this.yieldCount > turnsSeen;
|
|
16508
|
+
}
|
|
16509
|
+
/** 即将注入的下一条(1121:续 turn 卡片显示用——显示"接下来要处理的",不是刚答完的旧消息);无 pending 时 undefined */
|
|
16510
|
+
upcoming() {
|
|
16511
|
+
return this.pending[0];
|
|
16512
|
+
}
|
|
16513
|
+
async *stream(first) {
|
|
16514
|
+
this.yieldCount++;
|
|
16515
|
+
this.lastYield = first;
|
|
16516
|
+
yield ccUserMsg(first);
|
|
16517
|
+
while (true) {
|
|
16518
|
+
if (this.pending.length > 0) {
|
|
16519
|
+
const text2 = this.pending.shift();
|
|
16520
|
+
this.yieldCount++;
|
|
16521
|
+
this.lastYield = text2;
|
|
16522
|
+
yield ccUserMsg(text2);
|
|
16523
|
+
continue;
|
|
16524
|
+
}
|
|
16525
|
+
if (this.ended) return;
|
|
16526
|
+
await new Promise((resolve47) => this.waiters.push(resolve47));
|
|
16527
|
+
}
|
|
16528
|
+
}
|
|
16529
|
+
};
|
|
16530
|
+
defaultCcRuntimeLoader = (onProgress) => loadOptionalModule("cc-runtime", onProgress);
|
|
16531
|
+
ccRuntimeLoader = defaultCcRuntimeLoader;
|
|
16436
16532
|
CcDriverSession = class {
|
|
16437
16533
|
constructor(binding, cm, map, predecessor) {
|
|
16438
16534
|
this.predecessor = predecessor;
|
|
@@ -16454,6 +16550,8 @@ var init_driver = __esm({
|
|
|
16454
16550
|
revision = 0;
|
|
16455
16551
|
idleWaiters = [];
|
|
16456
16552
|
abort = null;
|
|
16553
|
+
/** 当前流式 chunk 的 steer 口(仅用户消息路径开;外部 ask/桌面路径为 null) */
|
|
16554
|
+
feeder = null;
|
|
16457
16555
|
sessionId = null;
|
|
16458
16556
|
sendChain = Promise.resolve();
|
|
16459
16557
|
ui = null;
|
|
@@ -16478,11 +16576,16 @@ var init_driver = __esm({
|
|
|
16478
16576
|
this.sessionId = null;
|
|
16479
16577
|
return this.map.clear(this.key) || had;
|
|
16480
16578
|
}
|
|
16481
|
-
/**
|
|
16579
|
+
/** 入站一条消息:流式 chunk 开着 → steer 注入(1119);否则排队(busy 时 FIFO),队列满则提示。 */
|
|
16482
16580
|
enqueue(text2) {
|
|
16483
16581
|
const trimmed = text2.trim();
|
|
16484
16582
|
if (!trimmed || this.closed) return;
|
|
16485
16583
|
if (this.ui?.routeTyped(trimmed)) return;
|
|
16584
|
+
const feeder = this.feeder;
|
|
16585
|
+
if (feeder && feeder.push(trimmed)) {
|
|
16586
|
+
this.ui?.onSteer(trimmed);
|
|
16587
|
+
return;
|
|
16588
|
+
}
|
|
16486
16589
|
if (this.queue.length >= MAX_QUEUE) {
|
|
16487
16590
|
void this.sendText(`[cc-driver] \u961F\u5217\u5DF2\u6EE1\uFF08${MAX_QUEUE} \u6761\uFF09\uFF0C\u8FD9\u6761\u6CA1\u6392\u4E0A\u2014\u2014\u7B49\u5F53\u524D\u4EFB\u52A1\u5B8C\u4E8B\u518D\u53D1\u3002`);
|
|
16488
16591
|
return;
|
|
@@ -16519,9 +16622,22 @@ var init_driver = __esm({
|
|
|
16519
16622
|
this.closed = true;
|
|
16520
16623
|
this.revision++;
|
|
16521
16624
|
for (const job of this.queue.splice(0)) job.reject?.(requestError("CC binding stopped before execution", 503));
|
|
16625
|
+
this.feeder?.close();
|
|
16522
16626
|
this.stop();
|
|
16523
16627
|
}
|
|
16524
|
-
/**
|
|
16628
|
+
/**
|
|
16629
|
+
* 全停(1119 翀哥拍板):中断当前 turn + 清 FIFO(外部 ask 按取消拒)+ 关 steer 口。
|
|
16630
|
+
* abort 杀进程 → CLI 里已排队未消费的插话一并死——所见即所得的「全停」。
|
|
16631
|
+
*/
|
|
16632
|
+
stopAll() {
|
|
16633
|
+
const hadQueued = this.queue.length > 0;
|
|
16634
|
+
for (const job of this.queue.splice(0)) job.reject?.(requestError("CC request cancelled (stop)", 499));
|
|
16635
|
+
this.feeder?.close();
|
|
16636
|
+
const active = this.busy;
|
|
16637
|
+
if (active) this.stop();
|
|
16638
|
+
return active || hadQueued;
|
|
16639
|
+
}
|
|
16640
|
+
/** 中断当前 turn(不清队列)——外部取消场景用;用户面全停走 stopAll() */
|
|
16525
16641
|
stop() {
|
|
16526
16642
|
this.abort?.abort();
|
|
16527
16643
|
}
|
|
@@ -16543,10 +16659,14 @@ var init_driver = __esm({
|
|
|
16543
16659
|
if (job.expectedSessionId !== void 0 && job.expectedSessionId !== this.sessionId) {
|
|
16544
16660
|
throw requestError("CC session changed while this request was queued");
|
|
16545
16661
|
}
|
|
16546
|
-
|
|
16547
|
-
${job.
|
|
16548
|
-
|
|
16549
|
-
|
|
16662
|
+
if (job.source) {
|
|
16663
|
+
const prompt = `[cc_ask from ${job.source.replace(/[\r\n]/g, " ").slice(0, 160)}]
|
|
16664
|
+
${job.prompt}`;
|
|
16665
|
+
const result = await this.runTurn(prompt, job.signal, true);
|
|
16666
|
+
job.resolve?.(result);
|
|
16667
|
+
} else {
|
|
16668
|
+
await this.runStreaming(job);
|
|
16669
|
+
}
|
|
16550
16670
|
} catch (err) {
|
|
16551
16671
|
job.reject?.(err);
|
|
16552
16672
|
console.error(`[cc-driver] turn \u5931\u8D25 key=${this.key}: ${err?.stack || err}`);
|
|
@@ -16580,15 +16700,11 @@ ${job.prompt}` : job.prompt;
|
|
|
16580
16700
|
this.ui = null;
|
|
16581
16701
|
}
|
|
16582
16702
|
}
|
|
16583
|
-
let textSoFar = "";
|
|
16584
|
-
let gotPartial = false;
|
|
16585
|
-
let lastInterimAt = Date.now();
|
|
16586
|
-
let interimCount = 0;
|
|
16587
|
-
let lastSentLen = 0;
|
|
16588
16703
|
let finalText = "";
|
|
16589
16704
|
let isError = false;
|
|
16590
16705
|
let gotResult = false;
|
|
16591
16706
|
let usage = "";
|
|
16707
|
+
const acc = this.makeStreamAccumulator();
|
|
16592
16708
|
try {
|
|
16593
16709
|
const desktops = resumedFrom ? await findDesktopTargets(this.workDir, resumedFrom) : [];
|
|
16594
16710
|
if (desktops.length > 1) throw new Error("Multiple desktop writers claim this CC session; close the duplicate");
|
|
@@ -16604,7 +16720,7 @@ ${job.prompt}` : job.prompt;
|
|
|
16604
16720
|
throw new Error("This CC session is open in another process; use cc-desktop to receive messages there");
|
|
16605
16721
|
}
|
|
16606
16722
|
let ccRuntimeNoticeSent = false;
|
|
16607
|
-
const { query } = await
|
|
16723
|
+
const { query } = await ccRuntimeLoader((label, got, total) => {
|
|
16608
16724
|
if (ccRuntimeNoticeSent) return;
|
|
16609
16725
|
ccRuntimeNoticeSent = true;
|
|
16610
16726
|
const mb = total ? `\u7EA6 ${Math.round(total / 1024 / 1024)}M` : "\u7EA6 350M";
|
|
@@ -16648,43 +16764,7 @@ ${job.prompt}` : job.prompt;
|
|
|
16648
16764
|
if (process.env.CC_DRIVER_DEBUG) console.log(`[cc-driver:dbg] type=${msg2.type} subtype=${msg2.subtype ?? "-"} sid=${msg2.session_id?.slice(0, 8) ?? "-"}`);
|
|
16649
16765
|
const parentToolUseId = msg2.parent_tool_use_id;
|
|
16650
16766
|
if (parentToolUseId) continue;
|
|
16651
|
-
if (msg2.type === "
|
|
16652
|
-
const ev = msg2.event;
|
|
16653
|
-
if (ev.type === "content_block_start" && ev.content_block?.type === "thinking") this.ui?.onThinkingDelta("");
|
|
16654
|
-
else if (ev.type === "content_block_delta" && ev.delta?.type === "thinking_delta" && typeof ev.delta.thinking === "string") this.ui?.onThinkingDelta(ev.delta.thinking);
|
|
16655
|
-
else if (ev.type === "content_block_stop" && this.ui) this.ui.onThinkingEnd();
|
|
16656
|
-
if (ev.type === "content_block_delta" && ev.delta?.type === "text_delta" && typeof ev.delta.text === "string") {
|
|
16657
|
-
gotPartial = true;
|
|
16658
|
-
textSoFar += ev.delta.text;
|
|
16659
|
-
const now2 = Date.now();
|
|
16660
|
-
const newChars = textSoFar.length - lastSentLen;
|
|
16661
|
-
if (!this.ui && now2 - lastInterimAt >= INTERIM_MIN_INTERVAL_MS && newChars >= INTERIM_MIN_CHARS && interimCount < MAX_INTERIM_PER_TURN) {
|
|
16662
|
-
lastInterimAt = now2;
|
|
16663
|
-
lastSentLen = textSoFar.length;
|
|
16664
|
-
interimCount++;
|
|
16665
|
-
const snippet2 = textSoFar.slice(-INTERIM_SNIPPET_CHARS);
|
|
16666
|
-
void this.sendText(`\u2026${snippet2}`);
|
|
16667
|
-
}
|
|
16668
|
-
}
|
|
16669
|
-
} else if (msg2.type === "assistant") {
|
|
16670
|
-
const content = msg2.message.content ?? [];
|
|
16671
|
-
for (const block of content) {
|
|
16672
|
-
if (block.type === "thinking" && block.thinking) this.ui?.onThinking(String(block.thinking));
|
|
16673
|
-
else if (block.type === "tool_use" && block.id) this.ui?.onToolUse(String(block.name), block.input ?? {});
|
|
16674
|
-
}
|
|
16675
|
-
if (!gotPartial) {
|
|
16676
|
-
for (const block of content) {
|
|
16677
|
-
if (block.type === "text" && typeof block.text === "string") textSoFar += block.text;
|
|
16678
|
-
}
|
|
16679
|
-
}
|
|
16680
|
-
} else if (msg2.type === "user") {
|
|
16681
|
-
const content = msg2.message.content;
|
|
16682
|
-
if (Array.isArray(content) && this.ui) {
|
|
16683
|
-
for (const block of content) {
|
|
16684
|
-
if (block.type === "tool_result") this.ui.onToolResult(resultToText(block.content), block.is_error === true);
|
|
16685
|
-
}
|
|
16686
|
-
}
|
|
16687
|
-
} else if (msg2.type === "result") {
|
|
16767
|
+
if (msg2.type === "result") {
|
|
16688
16768
|
const r = msg2;
|
|
16689
16769
|
if (r.session_id) {
|
|
16690
16770
|
turnSessionId = r.session_id;
|
|
@@ -16700,6 +16780,8 @@ ${job.prompt}` : job.prompt;
|
|
|
16700
16780
|
turnSessionId = sid;
|
|
16701
16781
|
if (this.revision === revision) this.sessionId = sid;
|
|
16702
16782
|
}
|
|
16783
|
+
} else {
|
|
16784
|
+
await acc.handle(msg2);
|
|
16703
16785
|
}
|
|
16704
16786
|
}
|
|
16705
16787
|
}
|
|
@@ -16708,22 +16790,22 @@ ${job.prompt}` : job.prompt;
|
|
|
16708
16790
|
this.abort = null;
|
|
16709
16791
|
signal?.removeEventListener("abort", cancel);
|
|
16710
16792
|
}
|
|
16711
|
-
const result = { sessionId: turnSessionId, text: finalText || textSoFar, isError: isError || ac.signal.aborted };
|
|
16793
|
+
const result = { sessionId: turnSessionId, text: finalText || acc.textSoFar, isError: isError || ac.signal.aborted };
|
|
16712
16794
|
if (ac.signal.aborted) {
|
|
16713
16795
|
if (this.ui && this.ui.alive) {
|
|
16714
16796
|
await this.ui.turnEnd("", "", "aborted");
|
|
16715
|
-
await this.sendText("[\u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1]" + (textSoFar ? `
|
|
16797
|
+
await this.sendText("[\u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1]" + (acc.textSoFar ? `
|
|
16716
16798
|
\u5DF2\u4EA7\u51FA\u7684\u90E8\u5206\uFF1A
|
|
16717
|
-
${textSoFar.slice(-FINAL_CHUNK_CHARS)}` : ""));
|
|
16799
|
+
${acc.textSoFar.slice(-FINAL_CHUNK_CHARS)}` : ""));
|
|
16718
16800
|
return { ...result, text: "[\u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1]" };
|
|
16719
16801
|
}
|
|
16720
|
-
await this.sendText("[\u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1]" + (textSoFar ? `
|
|
16802
|
+
await this.sendText("[\u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1]" + (acc.textSoFar ? `
|
|
16721
16803
|
|
|
16722
16804
|
\u5DF2\u4EA7\u51FA\u7684\u90E8\u5206\uFF1A
|
|
16723
|
-
${textSoFar.slice(-FINAL_CHUNK_CHARS)}` : ""));
|
|
16805
|
+
${acc.textSoFar.slice(-FINAL_CHUNK_CHARS)}` : ""));
|
|
16724
16806
|
return { ...result, text: "[\u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1]" };
|
|
16725
16807
|
}
|
|
16726
|
-
const answer = finalText || textSoFar;
|
|
16808
|
+
const answer = finalText || acc.textSoFar;
|
|
16727
16809
|
if (this.ui && this.ui.alive) {
|
|
16728
16810
|
await this.ui.turnEnd("", usage, isError ? "err" : "done");
|
|
16729
16811
|
if (!answer.trim()) {
|
|
@@ -16742,6 +16824,215 @@ ${textSoFar.slice(-FINAL_CHUNK_CHARS)}` : ""));
|
|
|
16742
16824
|
}
|
|
16743
16825
|
return result;
|
|
16744
16826
|
}
|
|
16827
|
+
/**
|
|
16828
|
+
* stream_event / assistant / user 三类消息的共用处理(runTurn 与 runStreaming 共享;
|
|
16829
|
+
* result / system 两个分支各自的循环里处理——流式 chunk 是多 result 语义)。
|
|
16830
|
+
* 返回 per-turn 累积态访问器(reset 在每个 result 后调)。
|
|
16831
|
+
*/
|
|
16832
|
+
makeStreamAccumulator() {
|
|
16833
|
+
let textSoFar = "";
|
|
16834
|
+
let gotPartial = false;
|
|
16835
|
+
let lastInterimAt = Date.now();
|
|
16836
|
+
let interimCount = 0;
|
|
16837
|
+
let lastSentLen = 0;
|
|
16838
|
+
return {
|
|
16839
|
+
reset: () => {
|
|
16840
|
+
textSoFar = "";
|
|
16841
|
+
gotPartial = false;
|
|
16842
|
+
lastInterimAt = Date.now();
|
|
16843
|
+
interimCount = 0;
|
|
16844
|
+
lastSentLen = 0;
|
|
16845
|
+
},
|
|
16846
|
+
handle: async (msg2) => {
|
|
16847
|
+
if (msg2.type === "stream_event") {
|
|
16848
|
+
const ev = msg2.event;
|
|
16849
|
+
if (ev.type === "content_block_start" && ev.content_block?.type === "thinking") this.ui?.onThinkingDelta("");
|
|
16850
|
+
else if (ev.type === "content_block_delta" && ev.delta?.type === "thinking_delta" && typeof ev.delta.thinking === "string") this.ui?.onThinkingDelta(ev.delta.thinking);
|
|
16851
|
+
else if (ev.type === "content_block_stop" && this.ui) this.ui.onThinkingEnd();
|
|
16852
|
+
if (ev.type === "content_block_delta" && ev.delta?.type === "text_delta" && typeof ev.delta.text === "string") {
|
|
16853
|
+
gotPartial = true;
|
|
16854
|
+
textSoFar += ev.delta.text;
|
|
16855
|
+
const now2 = Date.now();
|
|
16856
|
+
const newChars = textSoFar.length - lastSentLen;
|
|
16857
|
+
if (!this.ui && now2 - lastInterimAt >= INTERIM_MIN_INTERVAL_MS && newChars >= INTERIM_MIN_CHARS && interimCount < MAX_INTERIM_PER_TURN) {
|
|
16858
|
+
lastInterimAt = now2;
|
|
16859
|
+
lastSentLen = textSoFar.length;
|
|
16860
|
+
interimCount++;
|
|
16861
|
+
const snippet2 = textSoFar.slice(-INTERIM_SNIPPET_CHARS);
|
|
16862
|
+
void this.sendText(`\u2026${snippet2}`);
|
|
16863
|
+
}
|
|
16864
|
+
}
|
|
16865
|
+
} else if (msg2.type === "assistant") {
|
|
16866
|
+
const content = msg2.message.content ?? [];
|
|
16867
|
+
for (const block of content) {
|
|
16868
|
+
if (block.type === "thinking" && block.thinking) this.ui?.onThinking(String(block.thinking));
|
|
16869
|
+
else if (block.type === "tool_use" && block.id) this.ui?.onToolUse(String(block.name), block.input ?? {});
|
|
16870
|
+
}
|
|
16871
|
+
if (!gotPartial) {
|
|
16872
|
+
for (const block of content) {
|
|
16873
|
+
if (block.type === "text" && typeof block.text === "string") textSoFar += block.text;
|
|
16874
|
+
}
|
|
16875
|
+
}
|
|
16876
|
+
} else if (msg2.type === "user") {
|
|
16877
|
+
const content = msg2.message.content;
|
|
16878
|
+
if (Array.isArray(content) && this.ui) {
|
|
16879
|
+
for (const block of content) {
|
|
16880
|
+
if (block.type === "tool_result") this.ui.onToolResult(resultToText(block.content), block.is_error === true);
|
|
16881
|
+
}
|
|
16882
|
+
}
|
|
16883
|
+
}
|
|
16884
|
+
},
|
|
16885
|
+
get textSoFar() {
|
|
16886
|
+
return textSoFar;
|
|
16887
|
+
}
|
|
16888
|
+
};
|
|
16889
|
+
}
|
|
16890
|
+
/**
|
|
16891
|
+
* 用户消息的流式 chunk(1119 cc-desk steer):一次 query() 的 prompt 是 feeder 生成器,
|
|
16892
|
+
* busy 时 enqueue → feeder.push 注入(模型下一次 API 调用看到),同一进程可出多个
|
|
16893
|
+
* result(每 result 交付一轮答案);全部消化完 → close → 进程退出,空闲零进程不变。
|
|
16894
|
+
* 桌面托管 / 他进程占用 → 退回 runTurn 封闭路径(桌面桥无 steer)。
|
|
16895
|
+
*/
|
|
16896
|
+
async runStreaming(job) {
|
|
16897
|
+
const resumedFrom = this.sessionId;
|
|
16898
|
+
const desktops = resumedFrom ? await findDesktopTargets(this.workDir, resumedFrom) : [];
|
|
16899
|
+
if (desktops.length > 0 || resumedFrom && nativeSessionOwners(resumedFrom).length) {
|
|
16900
|
+
await this.runTurn(job.prompt, job.signal, false);
|
|
16901
|
+
return;
|
|
16902
|
+
}
|
|
16903
|
+
const ac = new AbortController();
|
|
16904
|
+
this.abort = ac;
|
|
16905
|
+
const revision = this.revision;
|
|
16906
|
+
let turnSessionId = resumedFrom;
|
|
16907
|
+
const cancel = () => ac.abort();
|
|
16908
|
+
job.signal?.addEventListener("abort", cancel, { once: true });
|
|
16909
|
+
if (job.signal?.aborted) ac.abort();
|
|
16910
|
+
console.log(`[cc-driver] streaming turn start key=${this.key} resume=${resumedFrom ? resumedFrom.slice(0, 8) : "new"} cwd=${this.workDir}`);
|
|
16911
|
+
if (this.binding.channel === "feishu" && !this.uiTried) {
|
|
16912
|
+
this.uiTried = true;
|
|
16913
|
+
this.ui = await makeFeishuCardUi(this.cm, this.binding);
|
|
16914
|
+
}
|
|
16915
|
+
if (this.ui) {
|
|
16916
|
+
try {
|
|
16917
|
+
await this.ui.turnStart(job.prompt);
|
|
16918
|
+
this.ui.setStopAction({ cc: 1, kind: "stop", key: this.key });
|
|
16919
|
+
} catch (err) {
|
|
16920
|
+
console.warn(`[cc-driver:card] \u5F00\u5361\u5931\u8D25\uFF0C\u672C binding \u56DE\u9000\u7EAF\u6587\u672C\uFF1A${err?.message ?? err}`);
|
|
16921
|
+
this.ui = null;
|
|
16922
|
+
}
|
|
16923
|
+
}
|
|
16924
|
+
const feeder = new SteerFeeder();
|
|
16925
|
+
this.feeder = feeder;
|
|
16926
|
+
const acc = this.makeStreamAccumulator();
|
|
16927
|
+
let turnsSeen = 0;
|
|
16928
|
+
let deliveredAfterAbort = false;
|
|
16929
|
+
try {
|
|
16930
|
+
const { query } = await ccRuntimeLoader();
|
|
16931
|
+
const stream = query({
|
|
16932
|
+
prompt: feeder.stream(job.prompt),
|
|
16933
|
+
options: {
|
|
16934
|
+
abortController: ac,
|
|
16935
|
+
cwd: this.workDir,
|
|
16936
|
+
...this.binding.permissionMode && this.binding.permissionMode !== "auto" ? { permissionMode: this.binding.permissionMode } : {},
|
|
16937
|
+
model: this.binding.model,
|
|
16938
|
+
resume: resumedFrom ?? void 0,
|
|
16939
|
+
includePartialMessages: true,
|
|
16940
|
+
...this.ui ? {
|
|
16941
|
+
canUseTool: async (toolName, input, opts) => {
|
|
16942
|
+
if (!this.ui) return { behavior: "deny", message: "\u5361\u7247\u901A\u9053\u5DF2\u65AD\u5F00\uFF0C\u64CD\u4F5C\u88AB\u62D2\u7EDD\u3002" };
|
|
16943
|
+
if (toolName === "AskUserQuestion") {
|
|
16944
|
+
const questions = normalizeQuestions(input.questions);
|
|
16945
|
+
if (questions.length === 0) return { behavior: "deny", message: "\u95EE\u9898\u683C\u5F0F\u65E0\u6CD5\u6E32\u67D3\uFF0C\u8BF7\u76F4\u63A5\u8BF4\u660E\u65B9\u6848\u7EE7\u7EED\u3002" };
|
|
16946
|
+
const r2 = await this.ui.askUser(questions, opts.signal);
|
|
16947
|
+
if (r2.answers) return { behavior: "allow", updatedInput: { ...input, answers: r2.answers } };
|
|
16948
|
+
return { behavior: "deny", message: r2.message ?? "\u7528\u6237\u6CA1\u6709\u56DE\u7B54\u8FD9\u4E9B\u95EE\u9898\uFF08\u98DE\u4E66\u5361\u7247\u672A\u7B54/\u8D85\u65F6\uFF09\uFF0C\u8BF7\u76F4\u63A5\u8BF4\u660E\u4F60\u7684\u65B9\u6848\u7EE7\u7EED\u3002" };
|
|
16949
|
+
}
|
|
16950
|
+
const r = await this.ui.askPermission(toolName, input, opts.signal, opts.suggestions);
|
|
16951
|
+
if (r.verdict === "deny") return { behavior: "deny", message: r.message ?? "\u7528\u6237\u5728\u98DE\u4E66\u5361\u7247\u4E0A\u62D2\u7EDD\u4E86\u8FD9\u6B21\u64CD\u4F5C\u3002" };
|
|
16952
|
+
return {
|
|
16953
|
+
behavior: "allow",
|
|
16954
|
+
updatedInput: input,
|
|
16955
|
+
...r.verdict === "always" && Array.isArray(opts.suggestions) && opts.suggestions.length > 0 ? { updatedPermissions: opts.suggestions } : {}
|
|
16956
|
+
};
|
|
16957
|
+
}
|
|
16958
|
+
} : {}
|
|
16959
|
+
}
|
|
16960
|
+
});
|
|
16961
|
+
try {
|
|
16962
|
+
for await (const msg2 of stream) {
|
|
16963
|
+
if (process.env.CC_DRIVER_DEBUG) console.log(`[cc-driver:dbg] type=${msg2.type} subtype=${msg2.subtype ?? "-"} sid=${msg2.session_id?.slice(0, 8) ?? "-"}`);
|
|
16964
|
+
const parentToolUseId = msg2.parent_tool_use_id;
|
|
16965
|
+
if (parentToolUseId) continue;
|
|
16966
|
+
if (msg2.type === "result") {
|
|
16967
|
+
const r = msg2;
|
|
16968
|
+
turnsSeen++;
|
|
16969
|
+
if (r.session_id) {
|
|
16970
|
+
turnSessionId = r.session_id;
|
|
16971
|
+
if (this.revision === revision) this.sessionId = r.session_id;
|
|
16972
|
+
}
|
|
16973
|
+
const isError = r.is_error === true;
|
|
16974
|
+
const finalText = typeof r.result === "string" ? r.result : "";
|
|
16975
|
+
const usage = r.usage ? `\u2193 ${fmtTok(r.usage.input_tokens)} \xB7 \u2191 ${fmtTok(r.usage.output_tokens)}` : "";
|
|
16976
|
+
if (turnSessionId && this.revision === revision) this.map.switchTo(this.key, turnSessionId, this.workDir);
|
|
16977
|
+
const more = feeder.expectsMoreTurns(turnsSeen);
|
|
16978
|
+
const answer = finalText || acc.textSoFar;
|
|
16979
|
+
if (ac.signal.aborted) deliveredAfterAbort = true;
|
|
16980
|
+
if (this.ui && this.ui.alive) {
|
|
16981
|
+
await this.ui.turnEnd("", usage, isError ? "err" : "done");
|
|
16982
|
+
}
|
|
16983
|
+
if (!answer.trim()) {
|
|
16984
|
+
await this.sendText(isError ? "[cc-driver] \u4EFB\u52A1\u51FA\u9519\u4E14\u6CA1\u6709\u4EA7\u51FA\u6587\u672C" : "[cc-driver] \u4EFB\u52A1\u7ED3\u675F\uFF08\u65E0\u6587\u672C\u4EA7\u51FA\uFF09");
|
|
16985
|
+
} else {
|
|
16986
|
+
for (const chunk of chunkText(answer, FINAL_CHUNK_CHARS)) await this.sendText(chunk);
|
|
16987
|
+
}
|
|
16988
|
+
acc.reset();
|
|
16989
|
+
if (ac.signal.aborted) break;
|
|
16990
|
+
if (!more) {
|
|
16991
|
+
feeder.close();
|
|
16992
|
+
break;
|
|
16993
|
+
}
|
|
16994
|
+
if (this.ui) {
|
|
16995
|
+
try {
|
|
16996
|
+
await this.ui.turnStart(`\u21AA ${feeder.upcoming() ?? feeder.lastYield}`);
|
|
16997
|
+
this.ui.setStopAction({ cc: 1, kind: "stop", key: this.key });
|
|
16998
|
+
} catch (err) {
|
|
16999
|
+
console.warn(`[cc-driver:card] \u7EED turn \u5F00\u5361\u5931\u8D25\uFF0C\u56DE\u9000\u7EAF\u6587\u672C\uFF1A${err?.message ?? err}`);
|
|
17000
|
+
this.ui = null;
|
|
17001
|
+
}
|
|
17002
|
+
}
|
|
17003
|
+
} else if (msg2.type === "system" && msg2.subtype === "init") {
|
|
17004
|
+
const sid = msg2.session_id;
|
|
17005
|
+
if (sid) {
|
|
17006
|
+
turnSessionId = sid;
|
|
17007
|
+
if (this.revision === revision) this.sessionId = sid;
|
|
17008
|
+
}
|
|
17009
|
+
} else {
|
|
17010
|
+
await acc.handle(msg2);
|
|
17011
|
+
}
|
|
17012
|
+
}
|
|
17013
|
+
} catch (err) {
|
|
17014
|
+
if (!(ac.signal.aborted || !feeder.expectsMoreTurns(turnsSeen))) throw err;
|
|
17015
|
+
}
|
|
17016
|
+
} finally {
|
|
17017
|
+
feeder.close();
|
|
17018
|
+
this.feeder = null;
|
|
17019
|
+
this.abort = null;
|
|
17020
|
+
job.signal?.removeEventListener("abort", cancel);
|
|
17021
|
+
}
|
|
17022
|
+
if (ac.signal.aborted && !deliveredAfterAbort) {
|
|
17023
|
+
if (this.ui && this.ui.alive) {
|
|
17024
|
+
await this.ui.turnEnd("", "", "aborted");
|
|
17025
|
+
await this.sendText("[\u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1]" + (acc.textSoFar ? `
|
|
17026
|
+
\u5DF2\u4EA7\u51FA\u7684\u90E8\u5206\uFF1A
|
|
17027
|
+
${acc.textSoFar.slice(-FINAL_CHUNK_CHARS)}` : ""));
|
|
17028
|
+
} else {
|
|
17029
|
+
await this.sendText("[\u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1]" + (acc.textSoFar ? `
|
|
17030
|
+
|
|
17031
|
+
\u5DF2\u4EA7\u51FA\u7684\u90E8\u5206\uFF1A
|
|
17032
|
+
${acc.textSoFar.slice(-FINAL_CHUNK_CHARS)}` : ""));
|
|
17033
|
+
}
|
|
17034
|
+
}
|
|
17035
|
+
}
|
|
16745
17036
|
/** 串行发送器:wechat 3s 节流在适配器层,这里保证不并发、失败不炸链 */
|
|
16746
17037
|
sendText(text2) {
|
|
16747
17038
|
const task = this.sendChain.then(async () => {
|
|
@@ -16789,6 +17080,12 @@ ${textSoFar.slice(-FINAL_CHUNK_CHARS)}` : ""));
|
|
|
16789
17080
|
forChat(channel, chatId) {
|
|
16790
17081
|
return this.sessions.get(`${channel}:${chatId}`);
|
|
16791
17082
|
}
|
|
17083
|
+
/** 按 bindingKey(channel:chatId)找 session——卡片停止钮回调用(1119) */
|
|
17084
|
+
forChatKey(key2) {
|
|
17085
|
+
const idx = key2.indexOf(":");
|
|
17086
|
+
if (idx <= 0) return void 0;
|
|
17087
|
+
return this.sessions.get(key2);
|
|
17088
|
+
}
|
|
16792
17089
|
/** 全部绑定的工作目录(去重;cc-progress 工具省参推断用) */
|
|
16793
17090
|
get bindingWorkDirs() {
|
|
16794
17091
|
return [...new Set([...this.sessions.values()].map((s) => s.workDir))];
|
|
@@ -20682,7 +20979,7 @@ function assertImageAssetRef(ref) {
|
|
|
20682
20979
|
throw new Error("Invalid or oversized image asset reference");
|
|
20683
20980
|
}
|
|
20684
20981
|
}
|
|
20685
|
-
async function materializeImageMessages(messages, store, signal, maxBase64Bytes = REQUEST_IMAGE_MAX_BASE64_SIZE) {
|
|
20982
|
+
async function materializeImageMessages(messages, store, signal, maxBase64Bytes = REQUEST_IMAGE_MAX_BASE64_SIZE, opts = {}) {
|
|
20686
20983
|
signal?.throwIfAborted();
|
|
20687
20984
|
let total = 0;
|
|
20688
20985
|
for (const message of messages) if (Array.isArray(message.content)) for (const block of message.content) {
|
|
@@ -20707,6 +21004,7 @@ async function materializeImageMessages(messages, store, signal, maxBase64Bytes
|
|
|
20707
21004
|
return { ...message, content: content.length ? content : "[previous image omitted]" };
|
|
20708
21005
|
});
|
|
20709
21006
|
if (total > maxBase64Bytes) throw new Error(`Request image base64 exceeds ${maxBase64Bytes} byte limit`);
|
|
21007
|
+
const { strict = false } = opts;
|
|
20710
21008
|
const cache2 = /* @__PURE__ */ new Map();
|
|
20711
21009
|
const output = [];
|
|
20712
21010
|
for (const message of requestView) {
|
|
@@ -20723,8 +21021,12 @@ async function materializeImageMessages(messages, store, signal, maxBase64Bytes
|
|
|
20723
21021
|
}
|
|
20724
21022
|
if (!store) throw new Error("Image asset store is required to materialize image refs");
|
|
20725
21023
|
const key2 = JSON.stringify([block.image.sha256, block.image.bytes, block.image.mediaType]);
|
|
20726
|
-
if (!cache2.has(key2)) cache2.set(key2, store.materialize(block.image))
|
|
20727
|
-
|
|
21024
|
+
if (!cache2.has(key2)) cache2.set(key2, store.materialize(block.image).catch((error) => {
|
|
21025
|
+
if (strict) throw error;
|
|
21026
|
+
console.warn(`[image-assets] \u5386\u53F2\u56FE\u7247\u4E0D\u53EF\u7528\uFF0C\u964D\u7EA7\u4E3A\u5360\u4F4D\uFF08sha256=${block.image.sha256.slice(0, 12)}\uFF09\uFF1A${error instanceof Error ? error.message : String(error)}`);
|
|
21027
|
+
return null;
|
|
21028
|
+
}));
|
|
21029
|
+
content.push(await cache2.get(key2) ?? { type: "text", text: "[\u56FE\u7247\u6587\u4EF6\u5DF2\u4E0D\u5728\u672C\u673A\uFF0C\u5185\u5BB9\u4E0D\u53EF\u89C1]" });
|
|
20728
21030
|
signal?.throwIfAborted();
|
|
20729
21031
|
}
|
|
20730
21032
|
output.push({ ...message, content });
|
|
@@ -29256,6 +29558,9 @@ var init_registry2 = __esm({
|
|
|
29256
29558
|
}
|
|
29257
29559
|
}
|
|
29258
29560
|
},
|
|
29561
|
+
// 1119:引擎侧 Gmail 读信的 scoped 代理出口(只作用于 GmailClient→gmail.googleapis.com,
|
|
29562
|
+
// broker 不走它)。Mac 直连被墙的机器配本机代理即可;不配=维持直连行为。
|
|
29563
|
+
{ path: "auth.gmailProxy", type: "string", group: "api", label: "Gmail \u51FA\u53E3\u4EE3\u7406", effect: "hot" },
|
|
29259
29564
|
{
|
|
29260
29565
|
path: "tools.email",
|
|
29261
29566
|
type: "json",
|
|
@@ -30605,10 +30910,11 @@ var STATE_EXCLUDED = {
|
|
|
30605
30910
|
var NESTED_EXCLUDED = { ".git": "source control metadata", node_modules: "installed dependencies", __pycache__: "Python bytecode cache" };
|
|
30606
30911
|
var WORKSPACE_DIAGNOSTICS = /* @__PURE__ */ new Set([".system-prompt.txt", ".context-debug.txt"]);
|
|
30607
30912
|
var RUNTIME_CONTROL = /* @__PURE__ */ new Set([".continuity", ".engine.pid", ".bg-worker.pid", ".travel-restored.json", ".travel-enrolled.json", ".travel-active.json"]);
|
|
30608
|
-
var CORE_DIRECTORIES = new Set(`agents auth configs cron mem7 memory runtime session-memory steer tasks teams todos tools .everos .calendar calendar .proactive proactive skills prompts .nudge hooks inner-voice goals plans private scripts state .voice-chat .desktopBuddy body`.split(" "));
|
|
30913
|
+
var CORE_DIRECTORIES = new Set(`agents auth configs cron mem7 memory runtime session-memory steer tasks teams todos tools .everos .calendar calendar .proactive proactive skills prompts topics .nudge hooks inner-voice goals plans private scripts state .voice-chat .desktopBuddy body`.split(" "));
|
|
30609
30914
|
var CORE_OMITTED = new Set(`media images videos audio content content-library docs output outputs dogfood-output backup backups topics-history node_modules .venvs venv .venv asr .cache cache caches tmp temp .playwright-mcp lancedb`.split(" "));
|
|
30610
30915
|
function coreReason(path37) {
|
|
30611
30916
|
const name = path37.split("/").at(-1);
|
|
30917
|
+
if (path37 === "chan7-files" || path37.startsWith("chan7-files/")) return void 0;
|
|
30612
30918
|
if (CORE_OMITTED.has(name) || /(?:\.lance$|(?:^|[-.])bak(?:[-.]|$))/i.test(name)) return "optional attachments, historical copies or rebuildable indexes; outside core travel";
|
|
30613
30919
|
if (/\.(?:mp4|mov|mkv|webm|avi|m4v|mp3|wav|ogg|opus|m4a|aac|flac|png|jpe?g|gif|webp|heic|bmp|tiff?|ico|pdf|docx?|pptx?|xlsx?|zip|gz|tgz|tar|7z|rar|dmg|exe|dll|so|dylib|bin|onnx|safetensors|gguf|vrm|glb|gltf|fbx|ttf|otf|woff2?|pyc|log|out)$/i.test(name) || name === ".DS_Store" || name === "package-lock.json" || name === ".context-debug.txt" || path37 === "mem7/spool/intake.failed.jsonl") return "attachments, installed binaries or diagnostics; outside core travel";
|
|
30614
30920
|
}
|
|
@@ -31462,12 +31768,7 @@ async function runtimeFileEntries(options) {
|
|
|
31462
31768
|
db2.close();
|
|
31463
31769
|
}
|
|
31464
31770
|
}
|
|
31465
|
-
|
|
31466
|
-
for (const entry of inventory.entries) {
|
|
31467
|
-
if (/\.lance(?:\/|$)/i.test(entry.path)) throw new Error("RUNTIME_UNCLASSIFIED_LANCE");
|
|
31468
|
-
if (entry.kind === "sidecar" && immutable.has(entry.source.replace(/-(wal|shm|journal)$/, ""))) throw new Error("RUNTIME_IMMUTABLE_DATABASE_HAS_SIDECAR");
|
|
31469
|
-
}
|
|
31470
|
-
return inventory.entries.filter((entry) => entry.kind === "directory" || entry.kind === "file" || immutable.has(entry.source));
|
|
31771
|
+
return inventory.entries.filter((entry) => entry.kind === "directory" || entry.kind === "file" || immutable.has(entry.source) || entry.kind === "sqlite" && !dynamic.has(entry.source));
|
|
31471
31772
|
};
|
|
31472
31773
|
return await classify();
|
|
31473
31774
|
}
|
|
@@ -31864,18 +32165,22 @@ function frameBytes(row) {
|
|
|
31864
32165
|
if (createHash24("sha256").update(bytes).digest("hex") !== row.digest) throw new Error("SESSION_EVENT_CORRUPT");
|
|
31865
32166
|
return bytes;
|
|
31866
32167
|
}
|
|
31867
|
-
function mapSessionIndex(bytes,
|
|
32168
|
+
function mapSessionIndex(bytes, _db, path37, stateDir, sourceRoot, targetRoot) {
|
|
31868
32169
|
if (basename5(path37) !== "session-index.json") return bytes;
|
|
31869
|
-
|
|
32170
|
+
let index;
|
|
32171
|
+
try {
|
|
32172
|
+
index = JSON.parse(bytes.toString("utf8"));
|
|
32173
|
+
} catch {
|
|
32174
|
+
return bytes;
|
|
32175
|
+
}
|
|
32176
|
+
if (!index || typeof index !== "object" || Array.isArray(index)) return bytes;
|
|
31870
32177
|
const prefixes = [sourceRoot, stateDir].map((root) => root.replace(/\\/g, "/").replace(/\/$/, "") + "/");
|
|
31871
|
-
if (!index || typeof index !== "object" || Array.isArray(index)) throw new Error("SESSION_INDEX_INVALID");
|
|
31872
32178
|
for (const entry of Object.values(index)) {
|
|
31873
|
-
if (!entry || typeof entry.file !== "string")
|
|
32179
|
+
if (!entry || typeof entry.file !== "string") continue;
|
|
31874
32180
|
const old = entry.file.replace(/\\/g, "/"), prefix2 = prefixes.find((value2) => old.startsWith(value2));
|
|
31875
|
-
if (!prefix2)
|
|
32181
|
+
if (!prefix2) continue;
|
|
31876
32182
|
const local = old.slice(prefix2.length);
|
|
31877
32183
|
sessionFilePath(stateDir, join19(stateDir, local));
|
|
31878
|
-
if (!db2.prepare("SELECT 1 FROM session_files WHERE path=? AND state='active'").get(local)) throw new Error("SESSION_INDEX_TARGET_MISSING");
|
|
31879
32184
|
entry.file = join19(targetRoot, local);
|
|
31880
32185
|
}
|
|
31881
32186
|
return Buffer.from(JSON.stringify(index, null, 2));
|
|
@@ -33813,8 +34118,10 @@ async function runInitialBaselineWorker(options, onProgress, assertCurrent) {
|
|
|
33813
34118
|
});
|
|
33814
34119
|
child.once("exit", (code) => {
|
|
33815
34120
|
clearInterval(timer);
|
|
33816
|
-
if (failure2)
|
|
33817
|
-
|
|
34121
|
+
if (failure2) {
|
|
34122
|
+
if (stderr) process.stderr.write("[initial-baseline child stderr] " + stderr.slice(-4e3) + "\n");
|
|
34123
|
+
reject(failure2);
|
|
34124
|
+
} else if (code !== 0) reject(Error("TRAVEL_INITIAL_CAPTURE_FAILED " + stderr.slice(-2e3)));
|
|
33818
34125
|
else done();
|
|
33819
34126
|
});
|
|
33820
34127
|
});
|
|
@@ -33830,7 +34137,9 @@ function publicPairingError(error) {
|
|
|
33830
34137
|
if (message === "INVALID_ARTIFACT_PATH") return "TRAVEL_SOURCE_PATH_INVALID";
|
|
33831
34138
|
if (/^SYMLINK_(REFUSED|CYCLE)(:|$)/.test(message)) return "TRAVEL_SOURCE_LINK_UNAVAILABLE";
|
|
33832
34139
|
if (message.startsWith("INVALID_SQLITE_FILE:")) return "TRAVEL_SOURCE_DATABASE_INVALID";
|
|
33833
|
-
|
|
34140
|
+
if (/^TRAVEL_[A-Z_]+$/.test(message)) return message;
|
|
34141
|
+
process.stderr.write("[pairing] masked-as TRAVEL_PAIRING_REFUSED, original: " + (error?.stack ?? String(error)) + "\n");
|
|
34142
|
+
return "TRAVEL_PAIRING_REFUSED";
|
|
33834
34143
|
}
|
|
33835
34144
|
|
|
33836
34145
|
// src/continuity/node-main.ts
|
|
@@ -34846,7 +35155,11 @@ async function copyTree(from, to, skipControl = false) {
|
|
|
34846
35155
|
const stat3 = await lstat4(from);
|
|
34847
35156
|
if (stat3.isSymbolicLink() || !stat3.isDirectory() && !stat3.isFile()) throw new Error("TRAVEL_ACTIVATION_UNSAFE_PATH");
|
|
34848
35157
|
if (stat3.isFile()) {
|
|
34849
|
-
|
|
35158
|
+
try {
|
|
35159
|
+
await copyNativeFile(from, to, copyFlags, stat3.size);
|
|
35160
|
+
} catch (error) {
|
|
35161
|
+
if (error.code !== "EEXIST") throw error;
|
|
35162
|
+
}
|
|
34850
35163
|
return;
|
|
34851
35164
|
}
|
|
34852
35165
|
await mkdir3(to, { recursive: true, mode: 448 });
|
|
@@ -34903,7 +35216,11 @@ async function activateRuntimeGeneration(options) {
|
|
|
34903
35216
|
await options.authority.assertPermit(runtime.assert("CONTROL"), "CONTROL");
|
|
34904
35217
|
const path37 = join53(destination, options.layout.databases[d.databaseId]), place = locations.get(d.databaseId);
|
|
34905
35218
|
mkdirSync24(dirname21(path37), { recursive: true, mode: 448 });
|
|
34906
|
-
|
|
35219
|
+
try {
|
|
35220
|
+
await copyNativeFile(join53(snapshot, "databases", d.databaseId + ".sqlite"), path37, copyFlags);
|
|
35221
|
+
} catch (error) {
|
|
35222
|
+
if (error.code !== "EEXIST") throw error;
|
|
35223
|
+
}
|
|
34907
35224
|
const binding = { ...identity3, databaseId: d.databaseId, baselineId: profile.baselineId, epoch: profile.epoch };
|
|
34908
35225
|
await runActivationDatabaseWorker(destination, path37, binding, () => {
|
|
34909
35226
|
options.assertStaging?.();
|
|
@@ -41388,6 +41705,12 @@ var TravelGatewayClient = class {
|
|
|
41388
41705
|
async ack(permit, eventId2) {
|
|
41389
41706
|
await this.call("ack", { permit, eventId: eventId2 });
|
|
41390
41707
|
}
|
|
41708
|
+
/** 1121:引擎主动开口——开一个 ENGINE 态事件承载 effect 台账。 */
|
|
41709
|
+
async begin(permit, channel) {
|
|
41710
|
+
const result = await this.call("begin", { permit, channel });
|
|
41711
|
+
if (!result || typeof result.id !== "string" || !/^[a-f0-9]{64}$/.test(result.id)) throw new Error("TRAVEL_GATEWAY_INVALID_RESPONSE");
|
|
41712
|
+
return result;
|
|
41713
|
+
}
|
|
41391
41714
|
async finish(permit, eventId2) {
|
|
41392
41715
|
await this.call("finish", { permit, eventId: eventId2 });
|
|
41393
41716
|
}
|
|
@@ -41832,7 +42155,7 @@ function createTravelNodeSupervisorServer(options) {
|
|
|
41832
42155
|
} catch (error) {
|
|
41833
42156
|
const code = error instanceof Error && nodeSupervisorErrors.has(error.message) ? error.message : "TRAVEL_NODE_REFUSED";
|
|
41834
42157
|
const reason = error instanceof Error ? /^(?:TRAVEL|RECOVERY|RUNTIME|PUBLICATION|REPLICATION|KEY_SERVICE)_[A-Z_]+/.exec(error.message)?.[0] : void 0;
|
|
41835
|
-
if (slot === "operation" || slot === "stop") process.stderr.write("[travel-node] " + (reason ?? code) + "\n");
|
|
42158
|
+
if (slot === "operation" || slot === "stop") process.stderr.write("[travel-node] " + (reason ?? code) + " | original: " + (error?.stack ?? String(error)) + "\n");
|
|
41836
42159
|
reply(code === "TRAVEL_AUTH_DENIED" ? 403 : 409, { error: code });
|
|
41837
42160
|
} finally {
|
|
41838
42161
|
clearTimeout(timer);
|