@steerable/agent-shell 0.12.6 → 0.12.7
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/local-backend/regenerate-helper.d.ts +18 -0
- package/dist/local-backend/regenerate-helper.js +59 -0
- package/dist/local-backend/router.d.ts +1 -0
- package/dist/local-backend/router.js +339 -250
- package/dist/local-backend/skills/80-tool-usage/SKILL.md +3 -2
- package/dist/server/http-server.js +1 -1
- package/package.json +5 -5
|
@@ -12,7 +12,25 @@ export interface RegenerateMessageLike {
|
|
|
12
12
|
id: string;
|
|
13
13
|
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
14
14
|
content: string;
|
|
15
|
+
messageMetadata?: string | null;
|
|
15
16
|
}
|
|
17
|
+
export type EditUserMessageResolution = {
|
|
18
|
+
ok: true;
|
|
19
|
+
targetMessageId: string;
|
|
20
|
+
userOrdinal: number;
|
|
21
|
+
} | {
|
|
22
|
+
ok: false;
|
|
23
|
+
reason: 'not_found' | 'not_user' | 'not_latest_user';
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the target user message for `POST /api/v2/chats/:id/messages/:messageId/edit`.
|
|
27
|
+
*
|
|
28
|
+
* Accepts `'latest'` to address the most recent non-internal user turn (used by
|
|
29
|
+
* live UI turns whose client message id has not yet been hydrated from SQLite),
|
|
30
|
+
* or an explicit persisted `messageId` (rejected with `not_latest_user` if a
|
|
31
|
+
* newer user turn already follows it).
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveEditUserMessageContext(messagesAsc: RegenerateMessageLike[], targetMessageId: string): EditUserMessageResolution;
|
|
16
34
|
export type RegenerateResolution = {
|
|
17
35
|
ok: true;
|
|
18
36
|
userMessageText: string;
|
|
@@ -8,6 +8,65 @@
|
|
|
8
8
|
* `storage/index.ts` (which can't be unit-tested here: `better-sqlite3` is
|
|
9
9
|
* compiled against Electron's ABI and can't load under plain Node/vitest).
|
|
10
10
|
*/
|
|
11
|
+
function isInternalUserMessage(message) {
|
|
12
|
+
if (message.role !== 'user' || !message.messageMetadata)
|
|
13
|
+
return false;
|
|
14
|
+
try {
|
|
15
|
+
const metadata = JSON.parse(message.messageMetadata);
|
|
16
|
+
return (metadata.internal === true &&
|
|
17
|
+
(metadata.trigger === 'goal' || metadata.trigger === 'loop'));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the target user message for `POST /api/v2/chats/:id/messages/:messageId/edit`.
|
|
25
|
+
*
|
|
26
|
+
* Accepts `'latest'` to address the most recent non-internal user turn (used by
|
|
27
|
+
* live UI turns whose client message id has not yet been hydrated from SQLite),
|
|
28
|
+
* or an explicit persisted `messageId` (rejected with `not_latest_user` if a
|
|
29
|
+
* newer user turn already follows it).
|
|
30
|
+
*/
|
|
31
|
+
export function resolveEditUserMessageContext(messagesAsc, targetMessageId) {
|
|
32
|
+
let latestUserIdx = -1;
|
|
33
|
+
for (let i = messagesAsc.length - 1; i >= 0; i -= 1) {
|
|
34
|
+
if (messagesAsc[i].role === 'user' && !isInternalUserMessage(messagesAsc[i])) {
|
|
35
|
+
latestUserIdx = i;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let targetIdx;
|
|
40
|
+
if (targetMessageId === 'latest') {
|
|
41
|
+
if (latestUserIdx === -1) {
|
|
42
|
+
return { ok: false, reason: 'not_found' };
|
|
43
|
+
}
|
|
44
|
+
targetIdx = latestUserIdx;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
targetIdx = messagesAsc.findIndex((m) => m.id === targetMessageId);
|
|
48
|
+
if (targetIdx === -1) {
|
|
49
|
+
return { ok: false, reason: 'not_found' };
|
|
50
|
+
}
|
|
51
|
+
if (messagesAsc[targetIdx].role !== 'user' || isInternalUserMessage(messagesAsc[targetIdx])) {
|
|
52
|
+
return { ok: false, reason: 'not_user' };
|
|
53
|
+
}
|
|
54
|
+
if (targetIdx !== latestUserIdx) {
|
|
55
|
+
return { ok: false, reason: 'not_latest_user' };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
let userOrdinal = 0;
|
|
59
|
+
for (let i = 0; i < targetIdx; i += 1) {
|
|
60
|
+
if (messagesAsc[i].role === 'user') {
|
|
61
|
+
userOrdinal += 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
ok: true,
|
|
66
|
+
targetMessageId: messagesAsc[targetIdx].id,
|
|
67
|
+
userOrdinal,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
11
70
|
const FALLBACK_TEXT = '请基于上一轮内容重新生成回复。';
|
|
12
71
|
/**
|
|
13
72
|
* @param messagesAsc Full chat history, chronologically ascending (oldest first).
|
|
@@ -102,6 +102,7 @@ export declare class LocalBackendRouter {
|
|
|
102
102
|
/** 4.6a/4.6c:任务面板的路由入口(列表 + 合并/丢弃)。未注入时任务路由 503。 */
|
|
103
103
|
private readonly taskService;
|
|
104
104
|
private takeAskReplay;
|
|
105
|
+
private readonly activeTurnRuns;
|
|
105
106
|
constructor(toolRouter: ToolRouter, options: {
|
|
106
107
|
store: ScopedStore;
|
|
107
108
|
resolveStore?: (principal?: Principal) => ScopedStore;
|
|
@@ -41,7 +41,7 @@ import { generateChatTitle } from './ai-title.js';
|
|
|
41
41
|
import { generateSuggestedReplies } from './ai-suggestions.js';
|
|
42
42
|
import { detectDeferredExecution } from './deferred-detector.js';
|
|
43
43
|
import { formatHistoryForSummary, truncateMiddle, } from './context-compactor.js';
|
|
44
|
-
import { planRegenerateTruncate, resolveRegenerateContext, resolveRegenerateForkOrdinal, } from './regenerate-helper.js';
|
|
44
|
+
import { planRegenerateTruncate, resolveEditUserMessageContext, resolveRegenerateContext, resolveRegenerateForkOrdinal, } from './regenerate-helper.js';
|
|
45
45
|
import { resolveBranchActivation } from './branch-helper.js';
|
|
46
46
|
import { detectInterruptedTurn } from './interrupted-helper.js';
|
|
47
47
|
import { resumableTurn } from './resumable-turn.js';
|
|
@@ -365,6 +365,7 @@ export class LocalBackendRouter {
|
|
|
365
365
|
/** 4.6a/4.6c:任务面板的路由入口(列表 + 合并/丢弃)。未注入时任务路由 503。 */
|
|
366
366
|
taskService;
|
|
367
367
|
takeAskReplay = null;
|
|
368
|
+
activeTurnRuns = new Map();
|
|
368
369
|
constructor(toolRouter, options) {
|
|
369
370
|
this.toolRouter = toolRouter;
|
|
370
371
|
this.defaultStore = options.store;
|
|
@@ -2548,7 +2549,8 @@ export class LocalBackendRouter {
|
|
|
2548
2549
|
const pathname = url.pathname;
|
|
2549
2550
|
const sendMatch = pathname.match(/^\/api\/v2\/chats\/([^/]+)\/(send|run|agent)$/);
|
|
2550
2551
|
const regenerateMatch = pathname.match(/^\/api\/v2\/chats\/([^/]+)\/messages\/([^/]+)\/regenerate$/);
|
|
2551
|
-
|
|
2552
|
+
const editMatch = pathname.match(/^\/api\/v2\/chats\/([^/]+)\/messages\/([^/]+)\/edit$/);
|
|
2553
|
+
if (!sendMatch && !regenerateMatch && !editMatch) {
|
|
2552
2554
|
emit(this.sse('error', { message: `Stream route not found: ${request.method} ${pathname}` }));
|
|
2553
2555
|
return { status: 404 };
|
|
2554
2556
|
}
|
|
@@ -2556,7 +2558,11 @@ export class LocalBackendRouter {
|
|
|
2556
2558
|
emit(this.sse('error', { message: `Stream route not found: ${request.method} ${pathname}` }));
|
|
2557
2559
|
return { status: 404 };
|
|
2558
2560
|
}
|
|
2559
|
-
const chatId = sendMatch
|
|
2561
|
+
const chatId = sendMatch
|
|
2562
|
+
? sendMatch[1]
|
|
2563
|
+
: regenerateMatch
|
|
2564
|
+
? regenerateMatch[1]
|
|
2565
|
+
: editMatch[1];
|
|
2560
2566
|
const payload = this.toRecord(request.body);
|
|
2561
2567
|
let chat = await this.store.getChat(chatId);
|
|
2562
2568
|
if (!chat) {
|
|
@@ -2564,9 +2570,10 @@ export class LocalBackendRouter {
|
|
|
2564
2570
|
// 会话任务反复打开运行,本地会话却可能已经被用户清理、被空会话 prune、
|
|
2565
2571
|
// 或换机重装后不复存在。首次发送时按 URL 里的 id 现场补建,避免 404
|
|
2566
2572
|
// `chat not found` 把一次本该能跑的任务直接打断。
|
|
2567
|
-
// • regenerate 例外——没有历史消息就无从"
|
|
2573
|
+
// • regenerate / edit 例外——没有历史消息就无从"重新生成/编辑",保持 404。
|
|
2568
2574
|
// • 只有真的带了一条用户消息才补建,空 body 不该凭空落一条空会话。
|
|
2569
2575
|
const shouldAutoProvision = !regenerateMatch &&
|
|
2576
|
+
!editMatch &&
|
|
2570
2577
|
payload.resume !== true &&
|
|
2571
2578
|
typeof payload.message === 'string' &&
|
|
2572
2579
|
payload.message.trim().length > 0;
|
|
@@ -2587,267 +2594,349 @@ export class LocalBackendRouter {
|
|
|
2587
2594
|
emit(this.sse('error', { message: 'chat not found' }));
|
|
2588
2595
|
return { status: 404 };
|
|
2589
2596
|
}
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
// regenerate' user turn on top of the old reply". The old bug ignored
|
|
2598
|
-
// the :messageId path param entirely, so regenerating just piled a new
|
|
2599
|
-
// user+assistant pair onto history while the original (possibly bad)
|
|
2600
|
-
// assistant reply stayed in place — the model saw both and had no real
|
|
2601
|
-
// reason to answer differently.
|
|
2602
|
-
//
|
|
2603
|
-
// sidecar 门必须先于任何写操作:rerun 回合只能跑在 sidecar 上
|
|
2604
|
-
// (handleCoreLoopTurn 无 sidecar 直接 503)。若先截断再 503,旧回复
|
|
2605
|
-
// 已删、新回复不会产生、record 也不存在——非破坏性承诺破窗。
|
|
2606
|
-
if (!getSidecarSupervisor()) {
|
|
2607
|
-
emit(this.sse('error', { message: 'coreloop enabled but sidecar is not running' }));
|
|
2608
|
-
return { status: 503 };
|
|
2597
|
+
if (editMatch) {
|
|
2598
|
+
const running = this.activeTurnRuns.get(chatId);
|
|
2599
|
+
if (running) {
|
|
2600
|
+
running.abort.abort();
|
|
2601
|
+
const activeStreamId = getActiveCoreLoopStreamId(chatId);
|
|
2602
|
+
if (activeStreamId) {
|
|
2603
|
+
await getSidecarSupervisor()?.cancelChat(activeStreamId).catch(() => { });
|
|
2609
2604
|
}
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
const priorMessages = (await this.store.listMessages(chatId, 200)).reverse();
|
|
2617
|
-
const resolution = resolveRegenerateContext(priorMessages, targetMessageId);
|
|
2618
|
-
if (!resolution.ok) {
|
|
2619
|
-
emit(this.sse('error', { message: 'regenerate target message not found or not an assistant message' }));
|
|
2620
|
-
return { status: 404 };
|
|
2605
|
+
await running.done;
|
|
2606
|
+
}
|
|
2607
|
+
else {
|
|
2608
|
+
const activeStreamId = getActiveCoreLoopStreamId(chatId);
|
|
2609
|
+
if (activeStreamId) {
|
|
2610
|
+
await getSidecarSupervisor()?.cancelChat(activeStreamId).catch(() => { });
|
|
2621
2611
|
}
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
const turnAbort = new AbortController();
|
|
2615
|
+
if (signal) {
|
|
2616
|
+
if (signal.aborted)
|
|
2617
|
+
turnAbort.abort();
|
|
2618
|
+
else
|
|
2619
|
+
signal.addEventListener('abort', () => turnAbort.abort(), { once: true });
|
|
2620
|
+
}
|
|
2621
|
+
let resolveTurnDone;
|
|
2622
|
+
const turnDone = new Promise((resolve) => {
|
|
2623
|
+
resolveTurnDone = resolve;
|
|
2624
|
+
});
|
|
2625
|
+
const turnEntry = { abort: turnAbort, done: turnDone };
|
|
2626
|
+
this.activeTurnRuns.set(chatId, turnEntry);
|
|
2627
|
+
try {
|
|
2628
|
+
return await this.withChatWriteLock(chatId, emit, async (emit) => {
|
|
2629
|
+
// W7-1: resume=true(仅 send 路由)续跑 durable record 里被中断的 turn,
|
|
2630
|
+
// 不追加新用户消息;与 regenerate / edit 互斥。
|
|
2631
|
+
const isResume = !regenerateMatch && !editMatch && payload.resume === true;
|
|
2632
|
+
let userMessageText;
|
|
2633
|
+
if (editMatch) {
|
|
2634
|
+
const editedText = String(payload.message ?? payload.content ?? '').trim();
|
|
2635
|
+
if (!editedText) {
|
|
2636
|
+
emit(this.sse('error', { message: 'message is required' }));
|
|
2637
|
+
return { status: 400 };
|
|
2638
|
+
}
|
|
2639
|
+
if (!getSidecarSupervisor()) {
|
|
2640
|
+
emit(this.sse('error', { message: 'coreloop enabled but sidecar is not running' }));
|
|
2641
|
+
return { status: 503 };
|
|
2642
|
+
}
|
|
2643
|
+
const rawTargetId = editMatch[2];
|
|
2644
|
+
const priorMessages = (await this.store.listMessages(chatId, 200)).reverse();
|
|
2645
|
+
const resolution = resolveEditUserMessageContext(priorMessages, rawTargetId);
|
|
2646
|
+
if (!resolution.ok) {
|
|
2647
|
+
if (resolution.reason === 'not_found') {
|
|
2648
|
+
emit(this.sse('error', { message: 'edit target message not found' }));
|
|
2649
|
+
return { status: 404 };
|
|
2650
|
+
}
|
|
2651
|
+
if (resolution.reason === 'not_user') {
|
|
2652
|
+
emit(this.sse('error', { message: 'edit target message is not a user message' }));
|
|
2653
|
+
return { status: 400 };
|
|
2654
|
+
}
|
|
2655
|
+
emit(this.sse('error', { message: 'only the most recent user message can be edited' }));
|
|
2656
|
+
return { status: 409 };
|
|
2657
|
+
}
|
|
2658
|
+
userMessageText = editedText;
|
|
2659
|
+
const supervisor = getSidecarSupervisor();
|
|
2660
|
+
const outcome = supervisor
|
|
2661
|
+
? await supervisor.forkSession({
|
|
2662
|
+
recordId: await this.store.getChatRecordId(chatId) ?? chatId,
|
|
2663
|
+
beforeUserIndex: resolution.userOrdinal,
|
|
2664
|
+
newRecordId: `${chatId}:r${Date.now().toString(36)}`,
|
|
2665
|
+
})
|
|
2666
|
+
: null;
|
|
2667
|
+
if (outcome?.ok) {
|
|
2668
|
+
await this.store.setChatRecordId(chatId, outcome.fork.recordId);
|
|
2669
|
+
}
|
|
2670
|
+
const plan = planRegenerateTruncate(outcome);
|
|
2671
|
+
if (!plan.proceed) {
|
|
2672
|
+
emit(this.sse('error', { message: plan.message }));
|
|
2673
|
+
return { status: 409 };
|
|
2674
|
+
}
|
|
2675
|
+
await this.store.deleteMessagesFrom(chatId, resolution.targetMessageId);
|
|
2676
|
+
}
|
|
2677
|
+
else if (regenerateMatch) {
|
|
2678
|
+
// Regenerate = truncate-and-rerun, *not* "append a fresh 'please
|
|
2679
|
+
// regenerate' user turn on top of the old reply". The old bug ignored
|
|
2680
|
+
// the :messageId path param entirely, so regenerating just piled a new
|
|
2681
|
+
// user+assistant pair onto history while the original (possibly bad)
|
|
2682
|
+
// assistant reply stayed in place — the model saw both and had no real
|
|
2683
|
+
// reason to answer differently.
|
|
2684
|
+
//
|
|
2685
|
+
// sidecar 门必须先于任何写操作:rerun 回合只能跑在 sidecar 上
|
|
2686
|
+
// (handleCoreLoopTurn 无 sidecar 直接 503)。若先截断再 503,旧回复
|
|
2687
|
+
// 已删、新回复不会产生、record 也不存在——非破坏性承诺破窗。
|
|
2688
|
+
if (!getSidecarSupervisor()) {
|
|
2689
|
+
emit(this.sse('error', { message: 'coreloop enabled but sidecar is not running' }));
|
|
2690
|
+
return { status: 503 };
|
|
2691
|
+
}
|
|
2692
|
+
const targetMessageId = regenerateMatch[2];
|
|
2693
|
+
// The user turn that prompted the target reply is whatever immediately
|
|
2694
|
+
// precedes it — re-derive its text so buildConversationMessages gets
|
|
2695
|
+
// the *real* request instead of a generic placeholder (matters for
|
|
2696
|
+
// deferred-exec detection, mode preamble, etc., which all key off the
|
|
2697
|
+
// actual ask).
|
|
2698
|
+
const priorMessages = (await this.store.listMessages(chatId, 200)).reverse();
|
|
2699
|
+
const resolution = resolveRegenerateContext(priorMessages, targetMessageId);
|
|
2700
|
+
if (!resolution.ok) {
|
|
2701
|
+
emit(this.sse('error', { message: 'regenerate target message not found or not an assistant message' }));
|
|
2702
|
+
return { status: 404 };
|
|
2703
|
+
}
|
|
2704
|
+
userMessageText = resolution.userMessageText;
|
|
2705
|
+
// W5-2: fork the durable record BEFORE truncating the UI store, so
|
|
2706
|
+
// the old tail survives as a discoverable branch instead of being
|
|
2707
|
+
// destroyed (UI store) / interleaved with the new tail (record).
|
|
2708
|
+
// The fork point is addressed by user-message ordinal: the prompting
|
|
2709
|
+
// user turn is the last user message before the target, i.e. index
|
|
2710
|
+
// (count of user messages before the target) - 1. An ordinal the sidecar
|
|
2711
|
+
// declines to split — no record, or a point inside a branch seed — is the
|
|
2712
|
+
// protocol's documented fallback and truncates; a fork that failed instead
|
|
2713
|
+
// of answering refuses the request (planRegenerateTruncate).
|
|
2714
|
+
const supervisor = getSidecarSupervisor();
|
|
2715
|
+
const outcome = supervisor
|
|
2716
|
+
? await supervisor.forkSession({
|
|
2717
|
+
recordId: await this.store.getChatRecordId(chatId) ?? chatId,
|
|
2718
|
+
beforeUserIndex: resolveRegenerateForkOrdinal(priorMessages, targetMessageId),
|
|
2719
|
+
newRecordId: `${chatId}:r${Date.now().toString(36)}`,
|
|
2720
|
+
})
|
|
2721
|
+
: null;
|
|
2722
|
+
if (outcome?.ok) {
|
|
2723
|
+
await this.store.setChatRecordId(chatId, outcome.fork.recordId);
|
|
2724
|
+
console.log('[local-backend] regenerate: record forked (old tail preserved)', {
|
|
2725
|
+
chatId,
|
|
2726
|
+
branchRecordId: outcome.fork.recordId,
|
|
2727
|
+
label: outcome.fork.label,
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
else if (outcome) {
|
|
2731
|
+
console.log('[local-backend] regenerate: no fork', {
|
|
2732
|
+
chatId,
|
|
2733
|
+
declined: outcome.declined,
|
|
2734
|
+
reason: outcome.reason,
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
const plan = planRegenerateTruncate(outcome);
|
|
2738
|
+
if (!plan.proceed) {
|
|
2739
|
+
emit(this.sse('error', { message: plan.message }));
|
|
2740
|
+
return { status: 409 };
|
|
2741
|
+
}
|
|
2742
|
+
const deleted = await this.store.deleteMessagesFrom(chatId, targetMessageId);
|
|
2743
|
+
console.log('[local-backend] regenerate: truncated history', {
|
|
2643
2744
|
chatId,
|
|
2644
|
-
|
|
2645
|
-
|
|
2745
|
+
targetMessageId,
|
|
2746
|
+
deletedCount: deleted,
|
|
2646
2747
|
});
|
|
2647
2748
|
}
|
|
2648
|
-
else if (
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2749
|
+
else if (isResume) {
|
|
2750
|
+
// 继续上一轮 —— 不追加新用户消息(记录里已有),而是让 sidecar 回放
|
|
2751
|
+
// durable record 的投影作为循环种子。允许续跑的三种终态见
|
|
2752
|
+
// `resumable-turn.ts`:崩溃中断、失败、用户停止。正常完成的回合拒绝,
|
|
2753
|
+
// 否则会给完整对话凭空多接一段回复。
|
|
2754
|
+
const prior = await this.store.listMessages(chatId, 200);
|
|
2755
|
+
const lastAssistant = prior.find((m) => m.role === 'assistant');
|
|
2756
|
+
const reason = resumableTurn({
|
|
2757
|
+
turnActive: (await this.store.getTurnActive(chatId)) !== null,
|
|
2758
|
+
streamActive: getActiveCoreLoopStreamId(chatId) !== undefined,
|
|
2759
|
+
lastMessageRole: prior[0]?.role ?? null,
|
|
2760
|
+
lastAssistantStatus: readCompletionStatus(lastAssistant),
|
|
2653
2761
|
});
|
|
2762
|
+
const lastUser = prior.find(m => m.role === 'user');
|
|
2763
|
+
if (!reason || !lastUser) {
|
|
2764
|
+
emit(this.sse('error', { message: '没有可继续的回复' }));
|
|
2765
|
+
return { status: 409 };
|
|
2766
|
+
}
|
|
2767
|
+
// 触发轮的用户消息仍在库里(崩溃只丢了回复)——取其原文喂给
|
|
2768
|
+
// buildConversationMessages,让 mode preamble / deferred-exec 检测
|
|
2769
|
+
// 仍然基于真实诉求。发给 sidecar 的 messages 为空(见下方调用点)。
|
|
2770
|
+
userMessageText = lastUser.content;
|
|
2771
|
+
// 在原先失败/停止的那条回复上记下「已从这里继续」:界面据此把整张
|
|
2772
|
+
// 失败卡片收成一行历史记录,重启后仍然是这一行,而不是又一次失败。
|
|
2773
|
+
if (lastAssistant && reason !== 'interrupted') {
|
|
2774
|
+
// 记不下来只会让卡片多留一张,不值得让续跑失败——所以吞掉异常,
|
|
2775
|
+
// 但用 try/catch 而不是 `.catch()`:store 实现可以是同步的。
|
|
2776
|
+
try {
|
|
2777
|
+
await this.store.patchMessageMetadata(chatId, lastAssistant.id, {
|
|
2778
|
+
continuedAt: new Date().toISOString(),
|
|
2779
|
+
continuedReason: reason,
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2782
|
+
catch (patchErr) {
|
|
2783
|
+
console.warn('[local-backend] continue: metadata patch failed', patchErr);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
else {
|
|
2788
|
+
userMessageText = String(payload.message || '').trim();
|
|
2654
2789
|
}
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
return { status: 409 };
|
|
2790
|
+
if (!userMessageText) {
|
|
2791
|
+
emit(this.sse('error', { message: 'message is required' }));
|
|
2792
|
+
return { status: 400 };
|
|
2659
2793
|
}
|
|
2660
|
-
const
|
|
2661
|
-
|
|
2794
|
+
const cleanedResult = await this.cleanUserMessage(userMessageText);
|
|
2795
|
+
const cleanUserMessageText = cleanedResult.cleanText;
|
|
2796
|
+
const forcedSkillName = cleanedResult.skillName;
|
|
2797
|
+
const forcedMcpToolToken = cleanedResult.mcpToolToken;
|
|
2798
|
+
// 仅在以下条件全部成立时才在本轮结束后生成 AI 标题:
|
|
2799
|
+
// 1. 当前标题仍是 storage.createChat 默认值「新对话」(用户没自己改过)
|
|
2800
|
+
// 2. 这是非 regenerate 的真实 user turn(regenerate 不应改写标题)
|
|
2801
|
+
// 3. 历史里目前没有任何 assistant 消息——也就是说,本轮即将产生的是第一条助手回复
|
|
2802
|
+
// 这避免在已经聊到一半的对话里突然把标题换掉。listMessages 是 DESC,limit 拉
|
|
2803
|
+
// 大一点确保看到完整历史(200 已经覆盖绝大多数本地会话)。
|
|
2804
|
+
const existingAssistant = (await this.store
|
|
2805
|
+
.listMessages(chatId, 200))
|
|
2806
|
+
.some((m) => m.role === 'assistant');
|
|
2807
|
+
const shouldGenerateTitle = !regenerateMatch &&
|
|
2808
|
+
!isResume &&
|
|
2809
|
+
!existingAssistant &&
|
|
2810
|
+
(chat.title === '新对话' || chat.title.trim() === '');
|
|
2811
|
+
const firstUserMessageForTitle = cleanUserMessageText;
|
|
2812
|
+
console.log('[local-backend] title-gen decision', {
|
|
2662
2813
|
chatId,
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
else if (isResume) {
|
|
2668
|
-
// 继续上一轮 —— 不追加新用户消息(记录里已有),而是让 sidecar 回放
|
|
2669
|
-
// durable record 的投影作为循环种子。允许续跑的三种终态见
|
|
2670
|
-
// `resumable-turn.ts`:崩溃中断、失败、用户停止。正常完成的回合拒绝,
|
|
2671
|
-
// 否则会给完整对话凭空多接一段回复。
|
|
2672
|
-
const prior = await this.store.listMessages(chatId, 200);
|
|
2673
|
-
const lastAssistant = prior.find((m) => m.role === 'assistant');
|
|
2674
|
-
const reason = resumableTurn({
|
|
2675
|
-
turnActive: (await this.store.getTurnActive(chatId)) !== null,
|
|
2676
|
-
streamActive: getActiveCoreLoopStreamId(chatId) !== undefined,
|
|
2677
|
-
lastMessageRole: prior[0]?.role ?? null,
|
|
2678
|
-
lastAssistantStatus: readCompletionStatus(lastAssistant),
|
|
2814
|
+
shouldGenerateTitle,
|
|
2815
|
+
currentTitle: chat.title,
|
|
2816
|
+
isRegenerate: !!regenerateMatch,
|
|
2817
|
+
existingAssistant,
|
|
2679
2818
|
});
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
//
|
|
2687
|
-
//
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2819
|
+
// Regenerate reruns against the (now-truncated) existing history — the
|
|
2820
|
+
// triggering user message is already in it, so unlike `send` we must not
|
|
2821
|
+
// insert another copy or the model would see it twice. Resume (W7-1)
|
|
2822
|
+
// likewise appends nothing: the crashed turn's user message is already
|
|
2823
|
+
// persisted (and already in the durable record).
|
|
2824
|
+
let currentUserMessageId;
|
|
2825
|
+
// 本轮被点名的智能体:菜单点选带来的 id 优先,手打的 `@名字` 从正文
|
|
2826
|
+
// 解析补齐(两者缺一,提及就在后端消失,只剩前端徽章)。
|
|
2827
|
+
const chatAgents = await this.store.listChatAgents();
|
|
2828
|
+
const mentionedAgentIds = resolveMentionedAgentIds(payload, userMessageText, chatAgents);
|
|
2829
|
+
if (!regenerateMatch && !isResume) {
|
|
2830
|
+
const internal = payload.internal === true &&
|
|
2831
|
+
(payload.trigger === 'goal' || payload.trigger === 'loop') &&
|
|
2832
|
+
typeof payload.sourceId === 'string';
|
|
2833
|
+
const userMetadata = {
|
|
2834
|
+
...(mentionedAgentIds.length > 0 ? { mentionedAgentIds } : {}),
|
|
2835
|
+
...(internal
|
|
2836
|
+
? {
|
|
2837
|
+
internal: true,
|
|
2838
|
+
trigger: payload.trigger,
|
|
2839
|
+
sourceId: payload.sourceId,
|
|
2840
|
+
}
|
|
2841
|
+
: {}),
|
|
2842
|
+
};
|
|
2843
|
+
const userMeta = Object.keys(userMetadata).length > 0
|
|
2844
|
+
? JSON.stringify(userMetadata)
|
|
2845
|
+
: null;
|
|
2846
|
+
const userMessage = await this.store.addMessage(chatId, 'user', userMessageText, userMeta);
|
|
2847
|
+
currentUserMessageId = userMessage.id;
|
|
2848
|
+
emit(this.sseData({ type: 'user_message', message: userMessage }));
|
|
2703
2849
|
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
existingAssistant,
|
|
2736
|
-
});
|
|
2737
|
-
// Regenerate reruns against the (now-truncated) existing history — the
|
|
2738
|
-
// triggering user message is already in it, so unlike `send` we must not
|
|
2739
|
-
// insert another copy or the model would see it twice. Resume (W7-1)
|
|
2740
|
-
// likewise appends nothing: the crashed turn's user message is already
|
|
2741
|
-
// persisted (and already in the durable record).
|
|
2742
|
-
let currentUserMessageId;
|
|
2743
|
-
// 本轮被点名的智能体:菜单点选带来的 id 优先,手打的 `@名字` 从正文
|
|
2744
|
-
// 解析补齐(两者缺一,提及就在后端消失,只剩前端徽章)。
|
|
2745
|
-
const chatAgents = await this.store.listChatAgents();
|
|
2746
|
-
const mentionedAgentIds = resolveMentionedAgentIds(payload, userMessageText, chatAgents);
|
|
2747
|
-
if (!regenerateMatch && !isResume) {
|
|
2748
|
-
const internal = payload.internal === true &&
|
|
2749
|
-
(payload.trigger === 'goal' || payload.trigger === 'loop') &&
|
|
2750
|
-
typeof payload.sourceId === 'string';
|
|
2751
|
-
const userMetadata = {
|
|
2752
|
-
...(mentionedAgentIds.length > 0 ? { mentionedAgentIds } : {}),
|
|
2753
|
-
...(internal
|
|
2754
|
-
? {
|
|
2755
|
-
internal: true,
|
|
2756
|
-
trigger: payload.trigger,
|
|
2757
|
-
sourceId: payload.sourceId,
|
|
2850
|
+
// Plan 模式(类 Cursor "先出计划"):仅暴露只读工具给模型,引导它先调研、
|
|
2851
|
+
// 再输出结构化计划,不做任何写操作/执行。其余值一律视为常规 agent 模式。
|
|
2852
|
+
const chatMode = resolveTurnChatMode(payload.mode);
|
|
2853
|
+
// 本轮生效的智能体:人设、技能勾选、工具策略同源。必须先解析——工具
|
|
2854
|
+
// 策略决定工具列表,工具列表又决定技能的触发条件。
|
|
2855
|
+
const turnAgents = await this.resolveTurnAgents(chatId, payload, mentionedAgentIds);
|
|
2856
|
+
// Wave 2 工具分层:模型可见列表只出 direct 层(内置工具 + tool_search
|
|
2857
|
+
// 发现缝);MCP 动态工具全在 deferred 层,经 tool_search 命中即调。
|
|
2858
|
+
// 附带收益:MCP 目录增删不再改动系统提示词里的工具名录,前缀更稳。
|
|
2859
|
+
const turnTools = this.toolRouter
|
|
2860
|
+
.listModelSchemas(turnAgents.capability.toolPolicy)
|
|
2861
|
+
.filter(schema => chatMode !== 'plan' || schema.mode === 'read')
|
|
2862
|
+
.map(schema => toTurnTool(schema));
|
|
2863
|
+
// 用户通过 "/" 显式指定的 MCP 工具:从注册表补齐元信息,available 取决于
|
|
2864
|
+
// 该工具本轮是否真的在 turnTools 里(未启用/未连接/被 plan 模式过滤都算
|
|
2865
|
+
// 不可用——指令模块会据此渲染"强制调用"或"如实告知不可用"两种版本)。
|
|
2866
|
+
let forcedMcpTool;
|
|
2867
|
+
if (forcedMcpToolToken) {
|
|
2868
|
+
const resolved = this.toolRouter.mcpRegistry?.findToolByToken(forcedMcpToolToken) ?? null;
|
|
2869
|
+
const token = resolved?.token ?? forcedMcpToolToken;
|
|
2870
|
+
const tokenParts = token.split('__');
|
|
2871
|
+
// 显式指定的工具属于 deferred 层、不在模型可见列表——本轮直接提升
|
|
2872
|
+
// 进列表(用户点名 = 最强信号),省一轮 tool_search 往返。
|
|
2873
|
+
// 智能体的工具策略不因点名而让步:被拒的工具不提升,forcedMcpTool
|
|
2874
|
+
// 随之落到 available: false 分支(指令模块如实告知不可用)。
|
|
2875
|
+
if (resolved &&
|
|
2876
|
+
!turnTools.some((t) => t.name === token) &&
|
|
2877
|
+
isToolAllowed(turnAgents.capability.toolPolicy, token)) {
|
|
2878
|
+
const schema = this.toolRouter.getSchemaByName(token);
|
|
2879
|
+
if (schema && (chatMode !== 'plan' || schema.mode === 'read')) {
|
|
2880
|
+
turnTools.push(toTurnTool(schema));
|
|
2758
2881
|
}
|
|
2759
|
-
: {}),
|
|
2760
|
-
};
|
|
2761
|
-
const userMeta = Object.keys(userMetadata).length > 0
|
|
2762
|
-
? JSON.stringify(userMetadata)
|
|
2763
|
-
: null;
|
|
2764
|
-
const userMessage = await this.store.addMessage(chatId, 'user', userMessageText, userMeta);
|
|
2765
|
-
currentUserMessageId = userMessage.id;
|
|
2766
|
-
emit(this.sseData({ type: 'user_message', message: userMessage }));
|
|
2767
|
-
}
|
|
2768
|
-
// Plan 模式(类 Cursor "先出计划"):仅暴露只读工具给模型,引导它先调研、
|
|
2769
|
-
// 再输出结构化计划,不做任何写操作/执行。其余值一律视为常规 agent 模式。
|
|
2770
|
-
const chatMode = resolveTurnChatMode(payload.mode);
|
|
2771
|
-
// 本轮生效的智能体:人设、技能勾选、工具策略同源。必须先解析——工具
|
|
2772
|
-
// 策略决定工具列表,工具列表又决定技能的触发条件。
|
|
2773
|
-
const turnAgents = await this.resolveTurnAgents(chatId, payload, mentionedAgentIds);
|
|
2774
|
-
// Wave 2 工具分层:模型可见列表只出 direct 层(内置工具 + tool_search
|
|
2775
|
-
// 发现缝);MCP 动态工具全在 deferred 层,经 tool_search 命中即调。
|
|
2776
|
-
// 附带收益:MCP 目录增删不再改动系统提示词里的工具名录,前缀更稳。
|
|
2777
|
-
const turnTools = this.toolRouter
|
|
2778
|
-
.listModelSchemas(turnAgents.capability.toolPolicy)
|
|
2779
|
-
.filter(schema => chatMode !== 'plan' || schema.mode === 'read')
|
|
2780
|
-
.map(schema => toTurnTool(schema));
|
|
2781
|
-
// 用户通过 "/" 显式指定的 MCP 工具:从注册表补齐元信息,available 取决于
|
|
2782
|
-
// 该工具本轮是否真的在 turnTools 里(未启用/未连接/被 plan 模式过滤都算
|
|
2783
|
-
// 不可用——指令模块会据此渲染"强制调用"或"如实告知不可用"两种版本)。
|
|
2784
|
-
let forcedMcpTool;
|
|
2785
|
-
if (forcedMcpToolToken) {
|
|
2786
|
-
const resolved = this.toolRouter.mcpRegistry?.findToolByToken(forcedMcpToolToken) ?? null;
|
|
2787
|
-
const token = resolved?.token ?? forcedMcpToolToken;
|
|
2788
|
-
const tokenParts = token.split('__');
|
|
2789
|
-
// 显式指定的工具属于 deferred 层、不在模型可见列表——本轮直接提升
|
|
2790
|
-
// 进列表(用户点名 = 最强信号),省一轮 tool_search 往返。
|
|
2791
|
-
// 智能体的工具策略不因点名而让步:被拒的工具不提升,forcedMcpTool
|
|
2792
|
-
// 随之落到 available: false 分支(指令模块如实告知不可用)。
|
|
2793
|
-
if (resolved &&
|
|
2794
|
-
!turnTools.some((t) => t.name === token) &&
|
|
2795
|
-
isToolAllowed(turnAgents.capability.toolPolicy, token)) {
|
|
2796
|
-
const schema = this.toolRouter.getSchemaByName(token);
|
|
2797
|
-
if (schema && (chatMode !== 'plan' || schema.mode === 'read')) {
|
|
2798
|
-
turnTools.push(toTurnTool(schema));
|
|
2799
2882
|
}
|
|
2883
|
+
forcedMcpTool = {
|
|
2884
|
+
token,
|
|
2885
|
+
toolName: resolved?.toolName ?? tokenParts.slice(2).join('__'),
|
|
2886
|
+
serverName: resolved?.serverName ?? '',
|
|
2887
|
+
description: resolved?.description ?? '',
|
|
2888
|
+
available: turnTools.some((t) => t.name === token),
|
|
2889
|
+
};
|
|
2800
2890
|
}
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
emit,
|
|
2843
|
-
signal,
|
|
2844
|
-
shouldGenerateTitle,
|
|
2845
|
-
firstUserMessageForTitle,
|
|
2846
|
-
resume: isResume,
|
|
2847
|
-
subagent: mergeTurnSubagentParam(Object.fromEntries(mentionRoster.map((row) => [row.profileName, row.profile])), Object.fromEntries(ambientRoster.map((row) => [row.profileName, row.profile]))),
|
|
2848
|
-
parentAgentId: turnAgents.parent?.id ?? null,
|
|
2891
|
+
const turnToolNames = turnTools.map((tool) => tool.name);
|
|
2892
|
+
const mentionRoster = await buildMentionDelegateRoster(turnAgents.delegates, turnToolNames);
|
|
2893
|
+
// 常驻可委派名单:其余智能体也进画像,技能/提示里的「交给 X」无需用户
|
|
2894
|
+
// `@` 就能落成一次真实委派。父代理自己不进——它就是本轮的执行者,给它
|
|
2895
|
+
// 一个自己的画像只会诱导无意义的自委派(`@自己` 走提及那条路,仍然可以)。
|
|
2896
|
+
const ambientRoster = await buildAmbientDelegateRoster(chatAgents, turnToolNames, {
|
|
2897
|
+
excludeAgentIds: [
|
|
2898
|
+
...mentionRoster.map((row) => row.agentId),
|
|
2899
|
+
...(turnAgents.parent ? [turnAgents.parent.id] : []),
|
|
2900
|
+
],
|
|
2901
|
+
reservedProfileNames: [
|
|
2902
|
+
...Object.keys(BUILTIN_SUBAGENT_PROFILES),
|
|
2903
|
+
...mentionRoster.map((row) => row.profileName),
|
|
2904
|
+
],
|
|
2905
|
+
});
|
|
2906
|
+
const { systemPrompt, messages, skillContext } = await this.buildConversationMessages(chatId, cleanUserMessageText, payload, turnTools, turnAgents, forcedSkillName, chatMode, forcedMcpTool, currentUserMessageId, { mention: mentionRoster, ambient: ambientRoster });
|
|
2907
|
+
// A4: the sidecar-hosted CoreLoop is the only chat path (the TS loop
|
|
2908
|
+
// was deleted 2026-08-26 after default-on + canary verification). Tools
|
|
2909
|
+
// round-trip back to this process over the reverse channel. If the
|
|
2910
|
+
// sidecar isn't running, handleCoreLoopTurn fails loud with a 503.
|
|
2911
|
+
return this.handleCoreLoopTurn({
|
|
2912
|
+
chatId,
|
|
2913
|
+
systemPrompt,
|
|
2914
|
+
// W7-1: on resume the sidecar replays the durable record's projection
|
|
2915
|
+
// as the loop seed and rejects a non-empty host history — the record
|
|
2916
|
+
// is authoritative, so the freshly built history stays unsent (only
|
|
2917
|
+
// systemPrompt / skillContext ride along).
|
|
2918
|
+
messages: isResume ? [] : messages,
|
|
2919
|
+
skillContext,
|
|
2920
|
+
turnTools,
|
|
2921
|
+
toolPolicy: turnAgents.capability.toolPolicy,
|
|
2922
|
+
chatMode,
|
|
2923
|
+
payload,
|
|
2924
|
+
emit,
|
|
2925
|
+
signal: turnAbort.signal,
|
|
2926
|
+
shouldGenerateTitle,
|
|
2927
|
+
firstUserMessageForTitle,
|
|
2928
|
+
resume: isResume,
|
|
2929
|
+
subagent: mergeTurnSubagentParam(Object.fromEntries(mentionRoster.map((row) => [row.profileName, row.profile])), Object.fromEntries(ambientRoster.map((row) => [row.profileName, row.profile]))),
|
|
2930
|
+
parentAgentId: turnAgents.parent?.id ?? null,
|
|
2931
|
+
});
|
|
2849
2932
|
});
|
|
2850
|
-
}
|
|
2933
|
+
}
|
|
2934
|
+
finally {
|
|
2935
|
+
if (this.activeTurnRuns.get(chatId) === turnEntry) {
|
|
2936
|
+
this.activeTurnRuns.delete(chatId);
|
|
2937
|
+
}
|
|
2938
|
+
resolveTurnDone();
|
|
2939
|
+
}
|
|
2851
2940
|
}
|
|
2852
2941
|
/**
|
|
2853
2942
|
* 后台异步生成 chat 标题。**完全 fire-and-forget**——不阻塞 `[DONE]`,
|
|
@@ -16,10 +16,11 @@ tags: [tool, guide]
|
|
|
16
16
|
|
|
17
17
|
## 多步任务清单(todo_write)
|
|
18
18
|
|
|
19
|
-
需要 3 步以上才能完成的任务(生成多页 PPT、批量改文件、多阶段调研等),**先调 `todo_write`
|
|
19
|
+
需要 3 步以上才能完成的任务(生成多页 PPT、批量改文件、多阶段调研等),**先调 `todo_write` 建任务清单再动手**,并在执行过程中**每完成一步立即更新状态**:
|
|
20
20
|
|
|
21
21
|
- 开始执行某项 → 标 `in_progress`(同时最多一个)
|
|
22
|
-
-
|
|
22
|
+
- **某项刚做完 → 立刻在同一轮(可与下一步业务工具一起批量发出)或紧随下一步调 `todo_write` 将其标为 `completed`,并把下一项标为 `in_progress`**
|
|
23
|
+
- **严禁建完清单后一路沉默执行、直到所有步骤都做完才一次性把全部条目改成 `completed`**——用户依靠清单实时观察每一步进度
|
|
23
24
|
- 清单还有未完成项时,**不要用纯文本汇报进度然后停下**——系统会检测未完成项并要求你继续执行
|
|
24
25
|
- 某项确实不需要做了 → 重写清单把它移除,再收尾
|
|
25
26
|
- 单步请求(回答一个问题、改一处)不用建清单
|
|
@@ -41,7 +41,7 @@ import { getResolvedHostTools } from '../host-tools-runtime.js';
|
|
|
41
41
|
/** 与 router.handleStream 内部的路由正则保持一致——只有这些路径是流式。 */
|
|
42
42
|
const STREAM_PATH_PATTERNS = [
|
|
43
43
|
/^\/api\/v2\/chats\/[^/]+\/(send|run|agent)$/,
|
|
44
|
-
/^\/api\/v2\/chats\/[^/]+\/messages\/[^/]+\/regenerate$/,
|
|
44
|
+
/^\/api\/v2\/chats\/[^/]+\/messages\/[^/]+\/(regenerate|edit)$/,
|
|
45
45
|
];
|
|
46
46
|
/**
|
|
47
47
|
* 请求体上限。会话附件(`/host/attachments/save`)在浏览器模式走 base64,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerable/agent-shell",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.7",
|
|
4
4
|
"description": "Steerable framework — product-neutral Node HostRuntime and headless HTTP server shared by Tauri desktop and browser deployments; scenario packs extend it through @steerable/pack-sdk.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://steerableframework.com/",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"jpeg-js": "^0.4.4",
|
|
54
54
|
"node-pty": "^1.1.0",
|
|
55
55
|
"pngjs": "^7.0.0",
|
|
56
|
-
"@steerable/agent-harness": "0.12.
|
|
57
|
-
"@steerable/agent-
|
|
58
|
-
"@steerable/agent-
|
|
59
|
-
"@steerable/pack-sdk": "0.12.
|
|
56
|
+
"@steerable/agent-harness": "0.12.7",
|
|
57
|
+
"@steerable/agent-runtime": "0.12.7",
|
|
58
|
+
"@steerable/agent-protocol": "0.12.7",
|
|
59
|
+
"@steerable/pack-sdk": "0.12.7"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/better-sqlite3": "^7.6.13",
|