lark-remote 0.1.12 → 0.2.0
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/CHANGELOG.md +37 -0
- package/README.en.md +2 -6
- package/README.md +3 -7
- package/dist/bridge/final-usage.d.ts +24 -0
- package/dist/bridge/final-usage.js +55 -0
- package/dist/bridge/inbound-media.d.ts +0 -3
- package/dist/bridge/inbound-media.js +0 -1
- package/dist/bridge/index.d.ts +7 -7
- package/dist/bridge/index.js +100 -133
- package/dist/bridge/queue-manager.js +4 -3
- package/dist/card/approval-render.js +39 -94
- package/dist/card/bash-renderer.js +12 -21
- package/dist/card/card-shared.d.ts +14 -5
- package/dist/card/card-shared.js +23 -34
- package/dist/card/run-renderer.d.ts +0 -22
- package/dist/card/run-renderer.js +206 -153
- package/dist/card/run-state.d.ts +29 -1
- package/dist/card/run-state.js +172 -84
- package/dist/card/text-truncate.d.ts +0 -9
- package/dist/card/text-truncate.js +0 -9
- package/dist/card/tool-render.d.ts +4 -1
- package/dist/card/tool-render.js +76 -32
- package/dist/cli.js +2 -2
- package/dist/common/fs.d.ts +14 -0
- package/dist/common/fs.js +57 -3
- package/dist/common/truncate.d.ts +0 -6
- package/dist/common/truncate.js +1 -1
- package/dist/common/ttl-cache.d.ts +24 -0
- package/dist/common/ttl-cache.js +53 -0
- package/dist/config/codex-config.js +14 -11
- package/dist/config/index.d.ts +0 -8
- package/dist/config/index.js +0 -16
- package/dist/config/kimi-config.d.ts +1 -1
- package/dist/config/kimi-config.js +2 -1
- package/dist/config/opencode-config.d.ts +1 -1
- package/dist/config/opencode-config.js +16 -10
- package/dist/config/qr.d.ts +36 -0
- package/dist/config/qr.js +124 -0
- package/dist/config/wizard.js +69 -27
- package/dist/connector/index.d.ts +3 -2
- package/dist/connector/index.js +5 -3
- package/dist/index.js +14 -41
- package/dist/instance-lock.js +7 -0
- package/dist/persistence/atomic-write.d.ts +2 -0
- package/dist/persistence/atomic-write.js +20 -5
- package/dist/persistence/load-json-file.d.ts +1 -2
- package/dist/persistence/load-json-file.js +2 -3
- package/dist/platform/agent-stopper.d.ts +22 -0
- package/dist/platform/agent-stopper.js +19 -0
- package/dist/platform/command.d.ts +11 -0
- package/dist/platform/command.js +107 -0
- package/dist/platform/identity.d.ts +33 -0
- package/dist/platform/identity.js +187 -0
- package/dist/platform/path.d.ts +24 -0
- package/dist/platform/path.js +110 -0
- package/dist/platform/select.d.ts +9 -0
- package/dist/platform/select.js +12 -0
- package/dist/platform/shell.d.ts +51 -0
- package/dist/platform/shell.js +75 -0
- package/dist/platform/spawn.d.ts +41 -0
- package/dist/platform/spawn.js +77 -0
- package/dist/platform/terminator-posix.d.ts +38 -0
- package/dist/platform/terminator-posix.js +103 -0
- package/dist/platform/terminator-win32.d.ts +21 -0
- package/dist/platform/terminator-win32.js +110 -0
- package/dist/platform/terminator.d.ts +44 -0
- package/dist/platform/terminator.js +24 -0
- package/dist/platform/types.d.ts +23 -0
- package/dist/platform/types.js +5 -0
- package/dist/restart.js +4 -2
- package/dist/router/card-helpers.d.ts +33 -6
- package/dist/router/card-helpers.js +67 -11
- package/dist/router/config/common/render.d.ts +1 -1
- package/dist/router/config/common/render.js +1 -1
- package/dist/router/config-diff.d.ts +4 -0
- package/dist/router/config-diff.js +70 -0
- package/dist/router/index.d.ts +73 -6
- package/dist/router/index.js +663 -590
- package/dist/router/utils.d.ts +6 -0
- package/dist/router/utils.js +12 -0
- package/dist/runner/bash/runner.d.ts +9 -2
- package/dist/runner/bash/runner.js +45 -20
- package/dist/runner/claude/session.d.ts +4 -4
- package/dist/runner/claude/session.js +18 -9
- package/dist/runner/codex/app-server/protocol-types.d.ts +35 -1
- package/dist/runner/codex/app-server/runner.d.ts +1 -16
- package/dist/runner/codex/app-server/runner.js +2 -2
- package/dist/runner/codex/app-server/translator.d.ts +18 -0
- package/dist/runner/codex/app-server/translator.js +146 -0
- package/dist/runner/common/acp/base-acp-runner.d.ts +116 -0
- package/dist/runner/common/acp/base-acp-runner.js +248 -0
- package/dist/runner/common/acp/base-translator.d.ts +141 -0
- package/dist/runner/common/acp/base-translator.js +271 -0
- package/dist/runner/common/acp/protocol-helpers.d.ts +70 -0
- package/dist/runner/common/acp/protocol-helpers.js +82 -0
- package/dist/runner/common/connection-based-runner.d.ts +0 -2
- package/dist/runner/common/connection-based-runner.js +1 -1
- package/dist/runner/common/jsonrpc/transport.d.ts +2 -0
- package/dist/runner/common/jsonrpc/transport.js +25 -5
- package/dist/runner/common/process-stopper.d.ts +4 -26
- package/dist/runner/common/process-stopper.js +4 -76
- package/dist/runner/common/runner-utils.d.ts +0 -5
- package/dist/runner/common/runner-utils.js +0 -7
- package/dist/runner/common/spawning-runner.d.ts +42 -132
- package/dist/runner/common/spawning-runner.js +52 -271
- package/dist/runner/common/usage.d.ts +2 -0
- package/dist/runner/common/usage.js +2 -0
- package/dist/runner/dsh/index.d.ts +0 -2
- package/dist/runner/dsh/index.js +0 -2
- package/dist/runner/dsh/runner.d.ts +0 -2
- package/dist/runner/dsh/runner.js +1 -1
- package/dist/runner/index.d.ts +1 -1
- package/dist/runner/kimi/acp/runner.d.ts +63 -53
- package/dist/runner/kimi/acp/runner.js +189 -334
- package/dist/runner/kimi/acp/translator.d.ts +18 -101
- package/dist/runner/kimi/acp/translator.js +61 -255
- package/dist/runner/opencode/acp/runner.d.ts +22 -46
- package/dist/runner/opencode/acp/runner.js +74 -297
- package/dist/runner/opencode/acp/translator.d.ts +28 -104
- package/dist/runner/opencode/acp/translator.js +54 -249
- package/dist/runner/pi/rpc/index.d.ts +0 -2
- package/dist/runner/pi/rpc/index.js +0 -2
- package/dist/runner/pi/rpc/translator.d.ts +3 -0
- package/dist/runner/pi/rpc/translator.js +47 -9
- package/dist/runner/probe.d.ts +8 -11
- package/dist/runner/probe.js +17 -21
- package/dist/runner/registry.d.ts +4 -4
- package/dist/runner/registry.js +4 -4
- package/dist/runner/resolve-agent-choices.js +6 -2
- package/dist/runner/sync-agent-choices.js +1 -1
- package/dist/runner/types.d.ts +38 -1
- package/dist/session/claude/session-index.js +3 -1
- package/dist/session/claude/sessions.js +37 -64
- package/dist/session/codex/rollout-reader.d.ts +10 -14
- package/dist/session/codex/rollout-reader.js +126 -48
- package/dist/session/common/constants.d.ts +7 -0
- package/dist/session/common/constants.js +9 -0
- package/dist/session/common/pagination.d.ts +0 -2
- package/dist/session/common/pagination.js +1 -1
- package/dist/session/common/recency.d.ts +7 -0
- package/dist/session/common/recency.js +10 -0
- package/dist/session/common/two-pass.d.ts +22 -0
- package/dist/session/common/two-pass.js +70 -0
- package/dist/session/common/usage-accumulator.d.ts +14 -0
- package/dist/session/common/usage-accumulator.js +15 -0
- package/dist/session/dsh/sessions.js +15 -11
- package/dist/session/kimi/sessions.d.ts +24 -4
- package/dist/session/kimi/sessions.js +99 -103
- package/dist/session/opencode/sessions.d.ts +2 -14
- package/dist/session/opencode/sessions.js +35 -15
- package/dist/session/pi/sessions.js +64 -95
- package/dist/update/index.d.ts +2 -3
- package/dist/update/index.js +1 -2
- package/dist/update/install.d.ts +2 -1
- package/dist/update/install.js +58 -9
- package/dist/update/version-check.d.ts +5 -0
- package/dist/update/version-check.js +9 -0
- package/package.json +9 -7
- package/dist/update/startup-hint.d.ts +0 -5
- package/dist/update/startup-hint.js +0 -11
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { collapsibleMarkdownPanel } from './collapsible.js';
|
|
8
8
|
import { truncateUtf8, truncateMarkdownTables } from './text-truncate.js';
|
|
9
|
+
import { cardButton } from './card-shared.js';
|
|
9
10
|
/** Unique nonce for card button callbacks (SDK dedup + router validation). */
|
|
10
11
|
function mkNonce() {
|
|
11
12
|
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
@@ -100,23 +101,13 @@ function renderDecisionButtons(approval, expired, runId) {
|
|
|
100
101
|
// 决策按钮逐个作为 body 直接元素返回(CardKit body 纵向堆叠 = 上下排列)。
|
|
101
102
|
// 不能用 column_set width:auto 横排:手机窄屏下多个按钮挤在一行,按钮文字
|
|
102
103
|
// 被截断成省略号,用户无法辨认审批动作。
|
|
103
|
-
return offered.map((d) => ({
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
value: {
|
|
111
|
-
cmd: 'approval.respond',
|
|
112
|
-
decision: d,
|
|
113
|
-
requestId: approval.requestId,
|
|
114
|
-
runId,
|
|
115
|
-
nonce: mkNonce(),
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
}));
|
|
104
|
+
return offered.map((d) => cardButton(BUTTONS[d].label, {
|
|
105
|
+
cmd: 'approval.respond',
|
|
106
|
+
decision: d,
|
|
107
|
+
requestId: approval.requestId,
|
|
108
|
+
runId,
|
|
109
|
+
nonce: mkNonce(),
|
|
110
|
+
}, { type: BUTTONS[d].type }));
|
|
120
111
|
}
|
|
121
112
|
// =============================================================================
|
|
122
113
|
// Tool Approval (non-command tools, e.g. ExitPlanMode)
|
|
@@ -350,28 +341,14 @@ function renderPermissionsApproval(approval, expired, runId) {
|
|
|
350
341
|
tag: 'div',
|
|
351
342
|
text: { tag: 'lark_md', content: `${icon} ${item.label}` },
|
|
352
343
|
});
|
|
353
|
-
elements.push({
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
behaviors: [
|
|
362
|
-
{
|
|
363
|
-
type: 'callback',
|
|
364
|
-
value: {
|
|
365
|
-
cmd: 'approval.toggle',
|
|
366
|
-
requestId: approval.requestId,
|
|
367
|
-
permId: item.id,
|
|
368
|
-
selected: !item.selected,
|
|
369
|
-
runId,
|
|
370
|
-
nonce: mkNonce(),
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
],
|
|
374
|
-
});
|
|
344
|
+
elements.push(cardButton(item.selected ? '取消授予' : '授予', {
|
|
345
|
+
cmd: 'approval.toggle',
|
|
346
|
+
requestId: approval.requestId,
|
|
347
|
+
permId: item.id,
|
|
348
|
+
selected: !item.selected,
|
|
349
|
+
runId,
|
|
350
|
+
nonce: mkNonce(),
|
|
351
|
+
}, { type: item.selected ? 'default' : 'primary', size: 'small' }));
|
|
375
352
|
}
|
|
376
353
|
}
|
|
377
354
|
// Action buttons
|
|
@@ -473,46 +450,26 @@ function renderQuestionApproval(approval, expired, runId) {
|
|
|
473
450
|
}
|
|
474
451
|
// 多选问题:有勾选才给提交按钮(单选在协调器内即时提交)。
|
|
475
452
|
if (q.multiSelect && selected.length > 0) {
|
|
476
|
-
elements.push({
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
value: {
|
|
484
|
-
cmd: 'approval.answerSubmit',
|
|
485
|
-
requestId: approval.requestId,
|
|
486
|
-
questionIndex: i,
|
|
487
|
-
runId,
|
|
488
|
-
nonce: mkNonce(),
|
|
489
|
-
},
|
|
490
|
-
},
|
|
491
|
-
],
|
|
492
|
-
});
|
|
453
|
+
elements.push(cardButton(`✅ 提交答案(已选 ${selected.length} 项)`, {
|
|
454
|
+
cmd: 'approval.answerSubmit',
|
|
455
|
+
requestId: approval.requestId,
|
|
456
|
+
questionIndex: i,
|
|
457
|
+
runId,
|
|
458
|
+
nonce: mkNonce(),
|
|
459
|
+
}, { type: 'primary' }));
|
|
493
460
|
}
|
|
494
461
|
}
|
|
495
462
|
// 提问卡底部统一「跳过回答」:走现有 approval.respond + decision=decline
|
|
496
463
|
// (coordinator 对 question 允许 decline 作为安全兜底),runner 按协议映射
|
|
497
464
|
// 跳过语义(Claude deny / Codex 空 answers / Kimi action decline / Pi cancelled)。
|
|
498
465
|
if (!expired) {
|
|
499
|
-
elements.push({
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
value: {
|
|
507
|
-
cmd: 'approval.respond',
|
|
508
|
-
decision: 'decline',
|
|
509
|
-
requestId: approval.requestId,
|
|
510
|
-
runId,
|
|
511
|
-
nonce: mkNonce(),
|
|
512
|
-
},
|
|
513
|
-
},
|
|
514
|
-
],
|
|
515
|
-
});
|
|
466
|
+
elements.push(cardButton('⏭️ 跳过回答', {
|
|
467
|
+
cmd: 'approval.respond',
|
|
468
|
+
decision: 'decline',
|
|
469
|
+
requestId: approval.requestId,
|
|
470
|
+
runId,
|
|
471
|
+
nonce: mkNonce(),
|
|
472
|
+
}, { type: 'default' }));
|
|
516
473
|
}
|
|
517
474
|
return elements;
|
|
518
475
|
}
|
|
@@ -530,27 +487,15 @@ function renderOptionRow(requestId, questionIndex, option, isSelected, icon, run
|
|
|
530
487
|
width: 'auto',
|
|
531
488
|
vertical_align: 'center',
|
|
532
489
|
elements: [
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
type: 'callback',
|
|
543
|
-
value: {
|
|
544
|
-
cmd: 'approval.answer',
|
|
545
|
-
requestId,
|
|
546
|
-
questionIndex,
|
|
547
|
-
option: option.label,
|
|
548
|
-
runId,
|
|
549
|
-
nonce: mkNonce(),
|
|
550
|
-
},
|
|
551
|
-
},
|
|
552
|
-
],
|
|
553
|
-
},
|
|
490
|
+
// 固定宽度让所有选项行的按钮左对齐(描述长短不影响按钮列)。
|
|
491
|
+
cardButton(isSelected ? '取消选择' : '选择', {
|
|
492
|
+
cmd: 'approval.answer',
|
|
493
|
+
requestId,
|
|
494
|
+
questionIndex,
|
|
495
|
+
option: option.label,
|
|
496
|
+
runId,
|
|
497
|
+
nonce: mkNonce(),
|
|
498
|
+
}, { type: isSelected ? 'default' : 'primary', size: 'small', width: '100px' }),
|
|
554
499
|
],
|
|
555
500
|
},
|
|
556
501
|
{
|
|
@@ -78,16 +78,17 @@ function assembleCard(state, elements) {
|
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
* Build elements
|
|
81
|
+
* Build output/stderr elements shared by normal & degraded paths (W2.3 单源):
|
|
82
|
+
* 除截断预算(OUTPUT_MAX_BYTES / DEGRADED_OUTPUT_BYTES)外逐行同构。
|
|
82
83
|
*/
|
|
83
|
-
function
|
|
84
|
+
function buildOutputElements(state, maxBytes) {
|
|
84
85
|
const { terminal, runId, output, stderr } = state;
|
|
85
86
|
const elements = [buildStatusRow(state)];
|
|
86
87
|
const truncatedOutput = output
|
|
87
|
-
? truncateUtf8(output,
|
|
88
|
+
? truncateUtf8(output, maxBytes, true, '…(输出已截断,共 ' + output.length + ' 字符)')
|
|
88
89
|
: '';
|
|
89
90
|
const truncatedStderr = stderr
|
|
90
|
-
? truncateUtf8(stderr,
|
|
91
|
+
? truncateUtf8(stderr, maxBytes, true, '…(诊断输出已截断,共 ' + stderr.length + ' 字符)')
|
|
91
92
|
: '';
|
|
92
93
|
if (truncatedOutput)
|
|
93
94
|
elements.push(markdownDiv(`\`\`\`\n${truncatedOutput}\n\`\`\``));
|
|
@@ -99,28 +100,18 @@ function buildNormalElements(state) {
|
|
|
99
100
|
elements.push(...buildExitFooter(state));
|
|
100
101
|
return elements;
|
|
101
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Build elements for the normal path: full output/stderr (each ≤ OUTPUT_MAX_BYTES).
|
|
105
|
+
*/
|
|
106
|
+
function buildNormalElements(state) {
|
|
107
|
+
return buildOutputElements(state, OUTPUT_MAX_BYTES);
|
|
108
|
+
}
|
|
102
109
|
/**
|
|
103
110
|
* Build elements for the degraded path: output/stderr truncated to a smaller
|
|
104
111
|
* budget. Preserves command (status row) and exitCode (footer).
|
|
105
112
|
*/
|
|
106
113
|
function buildDegradedElements(state) {
|
|
107
|
-
|
|
108
|
-
const elements = [buildStatusRow(state)];
|
|
109
|
-
const truncatedOutput = output
|
|
110
|
-
? truncateUtf8(output, DEGRADED_OUTPUT_BYTES, true, '…(输出已截断,共 ' + output.length + ' 字符)')
|
|
111
|
-
: '';
|
|
112
|
-
const truncatedStderr = stderr
|
|
113
|
-
? truncateUtf8(stderr, DEGRADED_OUTPUT_BYTES, true, '…(诊断输出已截断,共 ' + stderr.length + ' 字符)')
|
|
114
|
-
: '';
|
|
115
|
-
if (truncatedOutput)
|
|
116
|
-
elements.push(markdownDiv(`\`\`\`\n${truncatedOutput}\n\`\`\``));
|
|
117
|
-
if (truncatedStderr)
|
|
118
|
-
elements.push(markdownDiv(`📋 诊断输出:\n\`\`\`\n${truncatedStderr}\n\`\`\``));
|
|
119
|
-
if (terminal === 'running') {
|
|
120
|
-
elements.push({ tag: 'div', text: { content: '', tag: 'lark_md' } }, stopButton(runId));
|
|
121
|
-
}
|
|
122
|
-
elements.push(...buildExitFooter(state));
|
|
123
|
-
return elements;
|
|
114
|
+
return buildOutputElements(state, DEGRADED_OUTPUT_BYTES);
|
|
124
115
|
}
|
|
125
116
|
/**
|
|
126
117
|
* Build elements for the extreme fallback: no output/stderr body, only
|
|
@@ -7,12 +7,21 @@ import { type AgentKind } from '../runner/index.js';
|
|
|
7
7
|
* wire up the registry (notably unit tests of pure render helpers).
|
|
8
8
|
*/
|
|
9
9
|
export declare function agentDisplayName(kind: string): string;
|
|
10
|
-
export
|
|
11
|
-
interface TerminalLabelOptions {
|
|
12
|
-
prefix?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function terminalToLabel(terminal: string, options?: TerminalLabelOptions): string;
|
|
10
|
+
export declare function terminalToLabel(terminal: string): string;
|
|
15
11
|
export declare function terminalToColor(terminal: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Create a CardKit 2.0 button with a callback behavior. Shared constructor
|
|
14
|
+
* for every callback button in the card module (stop/new-session/compact/
|
|
15
|
+
* approval decisions/question options/…) — previously each render site
|
|
16
|
+
* hand-rolled the `{tag, text, type, behaviors}` object and they had drifted
|
|
17
|
+
* (plain_text tag sometimes present, sometimes omitted).
|
|
18
|
+
*/
|
|
19
|
+
export declare function cardButton(text: string, value: Record<string, unknown>, opts?: {
|
|
20
|
+
type?: 'primary' | 'default' | 'danger';
|
|
21
|
+
size?: 'small' | 'medium' | 'large';
|
|
22
|
+
/** Fixed width, e.g. '100px' (keeps option-row buttons left-aligned). */
|
|
23
|
+
width?: string;
|
|
24
|
+
}): object;
|
|
16
25
|
/**
|
|
17
26
|
* Create a CardKit 2.0 stop button with behaviors callback.
|
|
18
27
|
*/
|
package/dist/card/card-shared.js
CHANGED
|
@@ -25,7 +25,6 @@ export function agentDisplayName(kind) {
|
|
|
25
25
|
return 'Kimi';
|
|
26
26
|
return kind;
|
|
27
27
|
}
|
|
28
|
-
export { truncate } from '../common/truncate.js';
|
|
29
28
|
const TERMINAL_LABELS = {
|
|
30
29
|
done: '已完成',
|
|
31
30
|
error: '出错',
|
|
@@ -34,10 +33,8 @@ const TERMINAL_LABELS = {
|
|
|
34
33
|
running: '运行中',
|
|
35
34
|
finalizing: '完成中',
|
|
36
35
|
};
|
|
37
|
-
export function terminalToLabel(terminal
|
|
38
|
-
|
|
39
|
-
const prefix = options?.prefix ?? '';
|
|
40
|
-
return prefix + label;
|
|
36
|
+
export function terminalToLabel(terminal) {
|
|
37
|
+
return TERMINAL_LABELS[terminal] ?? '运行中';
|
|
41
38
|
}
|
|
42
39
|
export function terminalToColor(terminal) {
|
|
43
40
|
if (terminal === 'done')
|
|
@@ -55,27 +52,34 @@ export function terminalToColor(terminal) {
|
|
|
55
52
|
return 'red';
|
|
56
53
|
}
|
|
57
54
|
/**
|
|
58
|
-
* Create a CardKit 2.0
|
|
55
|
+
* Create a CardKit 2.0 button with a callback behavior. Shared constructor
|
|
56
|
+
* for every callback button in the card module (stop/new-session/compact/
|
|
57
|
+
* approval decisions/question options/…) — previously each render site
|
|
58
|
+
* hand-rolled the `{tag, text, type, behaviors}` object and they had drifted
|
|
59
|
+
* (plain_text tag sometimes present, sometimes omitted).
|
|
59
60
|
*/
|
|
60
|
-
export function
|
|
61
|
+
export function cardButton(text, value, opts = {}) {
|
|
61
62
|
return {
|
|
62
63
|
tag: 'button',
|
|
63
|
-
text: {
|
|
64
|
-
type:
|
|
65
|
-
|
|
64
|
+
text: { tag: 'plain_text', content: text },
|
|
65
|
+
...(opts.type ? { type: opts.type } : {}),
|
|
66
|
+
...(opts.size ? { size: opts.size } : {}),
|
|
67
|
+
...(opts.width ? { width: opts.width } : {}),
|
|
68
|
+
behaviors: [{ type: 'callback', value }],
|
|
66
69
|
};
|
|
67
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a CardKit 2.0 stop button with behaviors callback.
|
|
73
|
+
*/
|
|
74
|
+
export function stopButton(runId) {
|
|
75
|
+
return cardButton('⏹ 停止', { cmd: 'stop', runId }, { type: 'danger' });
|
|
76
|
+
}
|
|
68
77
|
/**
|
|
69
78
|
* Create a CardKit 2.0 "new session" button with behaviors callback.
|
|
70
79
|
* Standardized: ✨ 新会话 + primary type
|
|
71
80
|
*/
|
|
72
81
|
export function newSessionButton() {
|
|
73
|
-
return {
|
|
74
|
-
tag: 'button',
|
|
75
|
-
text: { content: '✨ 新会话' },
|
|
76
|
-
type: 'primary',
|
|
77
|
-
behaviors: [{ type: 'callback', value: { cmd: 'new-session' } }],
|
|
78
|
-
};
|
|
82
|
+
return cardButton('✨ 新会话', { cmd: 'new-session' }, { type: 'primary' });
|
|
79
83
|
}
|
|
80
84
|
/**
|
|
81
85
|
* Create a CardKit 2.0 Compact button for any runCompact-capable runner
|
|
@@ -84,12 +88,7 @@ export function newSessionButton() {
|
|
|
84
88
|
* runId 解析 agentKind,claude 走 stream-json 内建 /compact)。
|
|
85
89
|
*/
|
|
86
90
|
export function compactButton(runId) {
|
|
87
|
-
return {
|
|
88
|
-
tag: 'button',
|
|
89
|
-
text: { content: '🗜 Compact' },
|
|
90
|
-
type: 'primary',
|
|
91
|
-
behaviors: [{ type: 'callback', value: { cmd: 'codex.compact', runId } }],
|
|
92
|
-
};
|
|
91
|
+
return cardButton('🗜 Compact', { cmd: 'codex.compact', runId }, { type: 'primary' });
|
|
93
92
|
}
|
|
94
93
|
/**
|
|
95
94
|
* Create a CardKit 2.0 Compact button for resume cards (auto-resume / `/resume <id>`).
|
|
@@ -100,19 +99,9 @@ export function compactButton(runId) {
|
|
|
100
99
|
* non-default agent.
|
|
101
100
|
*/
|
|
102
101
|
export function resumeCompactButton(sessionId, agent) {
|
|
103
|
-
return {
|
|
104
|
-
tag: 'button',
|
|
105
|
-
text: { content: '🗜 Compact' },
|
|
106
|
-
type: 'primary',
|
|
107
|
-
behaviors: [{ type: 'callback', value: { cmd: 'resume.compact', sessionId, agent } }],
|
|
108
|
-
};
|
|
102
|
+
return cardButton('🗜 Compact', { cmd: 'resume.compact', sessionId, agent }, { type: 'primary' });
|
|
109
103
|
}
|
|
110
104
|
export function resumeUseButton(sessionId, agent) {
|
|
111
|
-
return {
|
|
112
|
-
tag: 'button',
|
|
113
|
-
text: { tag: 'plain_text', content: '🔁 切换到此会话' },
|
|
114
|
-
type: 'primary',
|
|
115
|
-
behaviors: [{ type: 'callback', value: { cmd: 'resume.use', sessionId, agent } }],
|
|
116
|
-
};
|
|
105
|
+
return cardButton('🔁 切换到此会话', { cmd: 'resume.use', sessionId, agent }, { type: 'primary' });
|
|
117
106
|
}
|
|
118
107
|
//# sourceMappingURL=card-shared.js.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { RunState, ToolEntry } from './run-state.js';
|
|
2
2
|
export interface RunCardRenderOptions {
|
|
3
|
-
showThinking?: boolean;
|
|
4
|
-
showToolUse?: boolean;
|
|
5
|
-
showToolResult?: boolean;
|
|
6
3
|
/**
|
|
7
4
|
* Agent kind for the run card header title (e.g. "Claude · 思考中").
|
|
8
5
|
* Defaults to 'claude' when not provided; the bridge passes `config.defaultAgent`.
|
|
@@ -42,25 +39,6 @@ type BlockGroup = {
|
|
|
42
39
|
};
|
|
43
40
|
/** 每个块的截断后内容(thinking/plan/text),测量与渲染共用(P1-2 建议项)。 */
|
|
44
41
|
type GroupContentPrepared = Map<BlockGroup, string>;
|
|
45
|
-
/**
|
|
46
|
-
* 影子测量:精确复刻 normal 路径(buildChronologicalContent + renderRunCard 的
|
|
47
|
-
* 骨架)产物 stringify 后的字节数,避免"先建完整卡再丢弃"的浪费。
|
|
48
|
-
*
|
|
49
|
-
* 第一性原理:估算应当测量"将要渲染的内容",而非近似它。
|
|
50
|
-
* - 骨架(schema/config/header/statusRow/summary/buttons/spacer)用小对象实测
|
|
51
|
-
* (measureJson),不依赖固定常数。
|
|
52
|
-
* - 块内容经与渲染完全相同的变换后精确测量:truncateUtf8 截断 →
|
|
53
|
-
* markdownDiv 的 escapeMarkdown(反斜杠 2×)→ JSON.stringify。因此 CJK
|
|
54
|
-
* (3 字节/字符无转义)与 ASCII 高转义(\n/" 膨胀)双向精确,无需转义因子。
|
|
55
|
-
* - tool 块直接 measureJson(renderTool(...))——与渲染共用同一函数,无复制。
|
|
56
|
-
* - 块结构基于 groupBlocks(与渲染一致,连续 text 合并),保证合并语义一致。
|
|
57
|
-
*
|
|
58
|
-
* 唯一系统性低估:elements 数组元素间逗号/括号 ~n+1 字节(忽略,4KB 裕度内)。
|
|
59
|
-
*
|
|
60
|
-
* 注意:估算只是优化路径选择,不替代最终 stringify 兜底。即使估算说"低于阈值"
|
|
61
|
-
* 走正常路径,renderRunCard 仍会 stringify 确认 ≤28KB;若估算低估,仍 fallback
|
|
62
|
-
* 到 degraded(安全网不丢)。
|
|
63
|
-
*/
|
|
64
42
|
/** 导出供测试断言估算精度(估算 ≈ 实际渲染字节,见 tests/anchor/run-card/run-card.test.ts)。 */
|
|
65
43
|
export declare function estimateCardBytes(state: RunState, options?: RunCardRenderOptions, shared?: {
|
|
66
44
|
groups?: BlockGroup[];
|