@dabuliu_wsy/dsh-im 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +197 -3
- package/cordis.patch.yml +4 -0
- package/dist/core/agent-state.d.ts +38 -0
- package/dist/core/agent-state.js +59 -0
- package/dist/core/arbiter-bridge.d.ts +25 -0
- package/dist/core/arbiter-bridge.js +20 -0
- package/dist/core/arbiter.d.ts +29 -0
- package/dist/core/arbiter.js +59 -0
- package/dist/core/avatar-brands.d.ts +23 -0
- package/dist/core/avatar-brands.js +75 -0
- package/dist/core/avatar-presets.d.ts +21 -0
- package/dist/core/avatar-presets.js +38 -0
- package/dist/core/avatar.d.ts +1 -0
- package/dist/core/avatar.js +18 -0
- package/dist/core/blocked.d.ts +12 -0
- package/dist/core/blocked.js +23 -0
- package/dist/core/budget-plan.d.ts +41 -0
- package/dist/core/budget-plan.js +69 -0
- package/dist/core/calibration-samples.d.ts +77 -0
- package/dist/core/calibration-samples.js +168 -0
- package/dist/core/calibrator.d.ts +57 -0
- package/dist/core/calibrator.js +125 -0
- package/dist/core/chapter-tree.d.ts +128 -0
- package/dist/core/chapter-tree.js +400 -0
- package/dist/core/consensus.d.ts +135 -0
- package/dist/core/consensus.js +394 -0
- package/dist/core/context-budget.d.ts +153 -0
- package/dist/core/context-budget.js +183 -0
- package/dist/core/curator.d.ts +28 -0
- package/dist/core/curator.js +190 -0
- package/dist/core/dual-window.d.ts +86 -0
- package/dist/core/dual-window.js +175 -0
- package/dist/core/events.d.ts +110 -0
- package/dist/core/events.js +117 -0
- package/dist/core/facts.d.ts +114 -0
- package/dist/core/facts.js +400 -0
- package/dist/core/fence.d.ts +34 -0
- package/dist/core/fence.js +129 -0
- package/dist/core/floor.d.ts +18 -0
- package/dist/core/floor.js +80 -0
- package/dist/core/ids.d.ts +11 -0
- package/dist/core/ids.js +29 -0
- package/dist/core/im.d.ts +167 -0
- package/dist/core/im.js +1307 -0
- package/dist/core/index.d.ts +33 -0
- package/dist/core/index.js +33 -0
- package/dist/core/log.d.ts +21 -0
- package/dist/core/log.js +63 -0
- package/dist/core/memory-claims.d.ts +67 -0
- package/dist/core/memory-claims.js +164 -0
- package/dist/core/memory-context.d.ts +121 -0
- package/dist/core/memory-context.js +303 -0
- package/dist/core/memory-visibility.d.ts +58 -0
- package/dist/core/memory-visibility.js +36 -0
- package/dist/core/memory.d.ts +12 -0
- package/dist/core/memory.js +73 -0
- package/dist/core/metrics.d.ts +49 -0
- package/dist/core/metrics.js +89 -0
- package/dist/core/multi-hop.d.ts +116 -0
- package/dist/core/multi-hop.js +278 -0
- package/dist/core/persist.d.ts +21 -0
- package/dist/core/persist.js +94 -0
- package/dist/core/proactive.d.ts +54 -0
- package/dist/core/proactive.js +108 -0
- package/dist/core/prompt.d.ts +82 -0
- package/dist/core/prompt.js +164 -0
- package/dist/core/receipt.d.ts +107 -0
- package/dist/core/receipt.js +86 -0
- package/dist/core/retrieval.d.ts +69 -0
- package/dist/core/retrieval.js +260 -0
- package/dist/core/role-state.d.ts +16 -0
- package/dist/core/role-state.js +65 -0
- package/dist/core/runtime.d.ts +137 -0
- package/dist/core/runtime.js +574 -0
- package/dist/core/summary.d.ts +19 -0
- package/dist/core/summary.js +96 -0
- package/dist/core/text.d.ts +10 -0
- package/dist/core/text.js +45 -0
- package/dist/core/time.d.ts +22 -0
- package/dist/core/time.js +84 -0
- package/dist/core/tool-schema.d.ts +12 -0
- package/dist/core/tool-schema.js +92 -0
- package/dist/core/tools.d.ts +137 -0
- package/dist/core/tools.js +348 -0
- package/dist/core/types.d.ts +400 -0
- package/dist/core/types.js +1 -0
- package/dist/core/window.d.ts +6 -0
- package/dist/core/window.js +7 -0
- package/dist/core/workspace-node.d.ts +28 -0
- package/dist/core/workspace-node.js +232 -0
- package/dist/core/workspace.d.ts +9 -0
- package/dist/core/workspace.js +45 -0
- package/dist/host/agent-session.d.ts +279 -0
- package/dist/host/agent-session.js +935 -0
- package/dist/host/attachment-gc.d.ts +37 -0
- package/dist/host/attachment-gc.js +97 -0
- package/dist/host/calibration-samples-store.d.ts +5 -0
- package/dist/host/calibration-samples-store.js +67 -0
- package/dist/host/capabilities.d.ts +45 -0
- package/dist/host/capabilities.js +67 -0
- package/dist/host/derived-store.d.ts +36 -0
- package/dist/host/derived-store.js +199 -0
- package/dist/host/dsh-llm.d.ts +143 -0
- package/dist/host/dsh-llm.js +395 -0
- package/dist/host/event-store.d.ts +47 -0
- package/dist/host/event-store.js +154 -0
- package/dist/host/fs-atomic.d.ts +1 -0
- package/dist/host/fs-atomic.js +26 -0
- package/dist/host/im-api.d.ts +352 -0
- package/dist/host/im-api.js +1137 -0
- package/dist/host/index.d.ts +103 -0
- package/dist/host/index.js +453 -0
- package/dist/host/memory-index.d.ts +65 -0
- package/dist/host/memory-index.js +181 -0
- package/dist/host/metrics-store.d.ts +7 -0
- package/dist/host/metrics-store.js +104 -0
- package/dist/host/models.d.ts +39 -0
- package/dist/host/models.js +67 -0
- package/dist/host/persona-tools.d.ts +57 -0
- package/dist/host/persona-tools.js +226 -0
- package/dist/host/preflight.d.ts +31 -0
- package/dist/host/preflight.js +29 -0
- package/dist/host/receipt-store.d.ts +26 -0
- package/dist/host/receipt-store.js +68 -0
- package/dist/host/run-check.d.ts +51 -0
- package/dist/host/run-check.js +190 -0
- package/dist/host/state-roots.d.ts +50 -0
- package/dist/host/state-roots.js +163 -0
- package/dist/host/tool-cache.d.ts +25 -0
- package/dist/host/tool-cache.js +90 -0
- package/dist/host/tool-call-budget.d.ts +29 -0
- package/dist/host/tool-call-budget.js +38 -0
- package/dsh-plugin.json +25 -0
- package/lib/client.inner.cjs +3346 -0
- package/lib/client.js +3354 -0
- package/package.json +86 -6
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { assertSafeThreadId } from '../core/workspace.js';
|
|
5
|
+
import { appendEvent, isChatEvent, lastSeq, migrateMessages, toEventInput, } from '../core/events.js';
|
|
6
|
+
/** 每群的私有目录:`.dsh-im/groups/<threadId>/` */
|
|
7
|
+
export function groupDir(root, threadId) {
|
|
8
|
+
assertSafeThreadId(threadId);
|
|
9
|
+
return join(root, '.dsh-im', 'groups', threadId);
|
|
10
|
+
}
|
|
11
|
+
export function eventsPath(root, threadId) {
|
|
12
|
+
return join(groupDir(root, threadId), 'events.jsonl');
|
|
13
|
+
}
|
|
14
|
+
export function leasePath(root, threadId) {
|
|
15
|
+
return join(groupDir(root, threadId), 'lease.json');
|
|
16
|
+
}
|
|
17
|
+
/** 读事件日志:坏行跳过(不让一行脏数据炸整个群)。 */
|
|
18
|
+
export async function readEvents(root, threadId) {
|
|
19
|
+
let raw;
|
|
20
|
+
try {
|
|
21
|
+
raw = await readFile(eventsPath(root, threadId), 'utf8');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error.code === 'ENOENT')
|
|
25
|
+
return [];
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
const events = [];
|
|
29
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
30
|
+
const trimmed = line.trim();
|
|
31
|
+
if (!trimmed)
|
|
32
|
+
continue;
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(trimmed);
|
|
35
|
+
if (typeof parsed?.seq === 'number' && typeof parsed?.text === 'string')
|
|
36
|
+
events.push(parsed);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return events.sort((left, right) => left.seq - right.seq);
|
|
43
|
+
}
|
|
44
|
+
/** 追加一条事件并落盘(只追加,不重写历史)。 */
|
|
45
|
+
export async function appendChatEvent(root, threadId, input) {
|
|
46
|
+
const events = await readEvents(root, threadId);
|
|
47
|
+
const event = appendEvent(events, input);
|
|
48
|
+
await mkdir(groupDir(root, threadId), { recursive: true });
|
|
49
|
+
await appendFile(eventsPath(root, threadId), JSON.stringify(event) + '\n', 'utf8');
|
|
50
|
+
return event;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 老 `state.json` 的 messages → 事件日志。幂等:已有事件就不动。
|
|
54
|
+
* @returns 是否真的迁移了,以及当前事件流。
|
|
55
|
+
*/
|
|
56
|
+
export async function migrateThreadEvents(root, threadId, messages) {
|
|
57
|
+
const existing = await readEvents(root, threadId);
|
|
58
|
+
if (existing.length > 0 || messages.length === 0)
|
|
59
|
+
return { migrated: false, events: existing };
|
|
60
|
+
const events = migrateMessages(messages);
|
|
61
|
+
await mkdir(groupDir(root, threadId), { recursive: true });
|
|
62
|
+
await writeFile(eventsPath(root, threadId), events.map((event) => JSON.stringify(event)).join('\n') + '\n', 'utf8');
|
|
63
|
+
return { migrated: true, events };
|
|
64
|
+
}
|
|
65
|
+
/** 文件版租约存储(host 侧;同步实现,文件很小)。 */
|
|
66
|
+
export function createFileLeaseStore(root) {
|
|
67
|
+
const pathOf = (groupId) => leasePath(root, groupId);
|
|
68
|
+
return {
|
|
69
|
+
read(groupId) {
|
|
70
|
+
try {
|
|
71
|
+
const parsed = JSON.parse(readFileSync(pathOf(groupId), 'utf8'));
|
|
72
|
+
if (typeof parsed?.owner === 'string' && typeof parsed?.fencingToken === 'number')
|
|
73
|
+
return parsed;
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
write(record) {
|
|
81
|
+
// 先校验 groupId(groupDir 内断言)再建目录,避免 `../` 在 groups 外留下空目录。
|
|
82
|
+
const dir = groupDir(root, record.groupId);
|
|
83
|
+
mkdirSync(dir, { recursive: true });
|
|
84
|
+
writeFileSync(pathOf(record.groupId), JSON.stringify(record), 'utf8');
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export function lastEventSeq(events) {
|
|
89
|
+
return lastSeq(events);
|
|
90
|
+
}
|
|
91
|
+
/** 每个群已同步进事件日志的消息条数(双写过渡期的游标)。 */
|
|
92
|
+
export function syncPath(root, threadId) {
|
|
93
|
+
return join(groupDir(root, threadId), 'sync.json');
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 把 state.json 里的 messages 增量同步进事件日志(过渡期双写,读仍以 state 为准)。
|
|
97
|
+
*
|
|
98
|
+
* 消息事件按顺序对应;`seqs` 回传每条消息在事件日志里的持久序号,
|
|
99
|
+
* saveState 用它回填 `message.seq`。非消息事件(事实/仲裁)在整份重写时保留。
|
|
100
|
+
*/
|
|
101
|
+
export async function syncThreadEvents(root, threadId, messages) {
|
|
102
|
+
await mkdir(groupDir(root, threadId), { recursive: true });
|
|
103
|
+
let synced = 0;
|
|
104
|
+
try {
|
|
105
|
+
const meta = JSON.parse(await readFile(syncPath(root, threadId), 'utf8'));
|
|
106
|
+
synced = typeof meta.messageCount === 'number' && meta.messageCount >= 0 ? meta.messageCount : 0;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
synced = 0;
|
|
110
|
+
}
|
|
111
|
+
const existing = await readEvents(root, threadId);
|
|
112
|
+
const chatEvents = existing.filter((event) => isChatEvent(event));
|
|
113
|
+
const stale = synced > messages.length;
|
|
114
|
+
const emptyButHasMessages = chatEvents.length === 0 && messages.length > 0;
|
|
115
|
+
if (stale || emptyButHasMessages) {
|
|
116
|
+
const rebuilt = migrateMessages(messages);
|
|
117
|
+
const events = [...rebuilt];
|
|
118
|
+
// 保留推导出来的事实/仲裁事件:重写消息区不能把它们冲掉。
|
|
119
|
+
for (const event of existing) {
|
|
120
|
+
if (isChatEvent(event))
|
|
121
|
+
continue;
|
|
122
|
+
events.push(appendEvent(events, toEventInput(event)));
|
|
123
|
+
}
|
|
124
|
+
const body = events.map((event) => JSON.stringify(event)).join('\n') + (events.length ? '\n' : '');
|
|
125
|
+
await writeFile(eventsPath(root, threadId), body, 'utf8');
|
|
126
|
+
await writeFile(syncPath(root, threadId), JSON.stringify({ messageCount: messages.length }), 'utf8');
|
|
127
|
+
return { appended: 0, rewritten: true, seqs: rebuilt.map((event) => event.seq) };
|
|
128
|
+
}
|
|
129
|
+
const fresh = messages.slice(synced);
|
|
130
|
+
if (fresh.length === 0) {
|
|
131
|
+
const seqs = chatEvents.length === messages.length ? chatEvents.map((event) => event.seq) : [];
|
|
132
|
+
return { appended: 0, rewritten: false, seqs };
|
|
133
|
+
}
|
|
134
|
+
let events = existing;
|
|
135
|
+
const freshEvents = [];
|
|
136
|
+
for (const message of fresh) {
|
|
137
|
+
const event = appendEvent(events, {
|
|
138
|
+
at: message.createdAt,
|
|
139
|
+
kind: message.kind,
|
|
140
|
+
actorName: message.authorName,
|
|
141
|
+
text: message.text,
|
|
142
|
+
producer: 'plugin',
|
|
143
|
+
...(message.kind === 'user' ? { untrusted: true } : {}),
|
|
144
|
+
});
|
|
145
|
+
events = [...events, event];
|
|
146
|
+
freshEvents.push(event);
|
|
147
|
+
}
|
|
148
|
+
await appendFile(eventsPath(root, threadId), freshEvents.map((event) => JSON.stringify(event)).join('\n') + '\n', 'utf8');
|
|
149
|
+
await writeFile(syncPath(root, threadId), JSON.stringify({ messageCount: messages.length }), 'utf8');
|
|
150
|
+
const seqs = chatEvents.length === synced
|
|
151
|
+
? [...chatEvents.map((event) => event.seq), ...freshEvents.map((event) => event.seq)]
|
|
152
|
+
: [];
|
|
153
|
+
return { appended: fresh.length, rewritten: false, seqs };
|
|
154
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeFileAtomic(path: string, data: string): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 原子写:先写同目录临时文件,再 rename 覆盖目标。
|
|
3
|
+
*
|
|
4
|
+
* 为什么必须原子:`state.json` / `known-roots.json` 是整份覆盖写的。
|
|
5
|
+
* 直接 `writeFile` 时,进程崩在写一半、或两个并发写交错,都会留下半截 JSON
|
|
6
|
+
* (读侧要么 parseState 抛错、要么读到空文件 → 面板表现为「数据没了」)。
|
|
7
|
+
* rename 在同一目录内是原子的:读到的一定是旧版本或新版本,不会是中间态。
|
|
8
|
+
*/
|
|
9
|
+
import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { dirname } from 'node:path';
|
|
11
|
+
/** 全进程唯一的临时后缀(pid + 自增),避免两个并发写撞同一个 .tmp 名字。 */
|
|
12
|
+
let seq = 0;
|
|
13
|
+
export async function writeFileAtomic(path, data) {
|
|
14
|
+
await mkdir(dirname(path), { recursive: true });
|
|
15
|
+
seq += 1;
|
|
16
|
+
const tmp = `${path}.tmp-${process.pid}-${seq}`;
|
|
17
|
+
try {
|
|
18
|
+
await writeFile(tmp, data, 'utf8');
|
|
19
|
+
await rename(tmp, path);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
// 临时文件不能留在工作区里(会被误当成数据文件,也污染 .dsh-im 目录)。
|
|
23
|
+
await rm(tmp, { force: true }).catch(() => undefined);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { type ToolGroupCatalog } from '../core/tools.ts';
|
|
2
|
+
import { type LlmService } from './dsh-llm.ts';
|
|
3
|
+
import type { MessageAttachment, ModelContentPart, NativeFrame, TurnStepTrace } from '../core/types.ts';
|
|
4
|
+
import { type NativeBridge } from './agent-session.ts';
|
|
5
|
+
import { type HostCapabilityReport } from './capabilities.ts';
|
|
6
|
+
import type { MemoryContextReceipt } from '../core/memory-context.ts';
|
|
7
|
+
import { type BudgetChangedEvent, type ContextBudgetReceipt } from '../core/context-budget.ts';
|
|
8
|
+
/** DSH 附件存储(ctx.attachments)的最小接口面:我们只用「存文件/存图片」两种。 */
|
|
9
|
+
export interface DshAttachmentStore {
|
|
10
|
+
saveFile?: (input: {
|
|
11
|
+
data: Uint8Array;
|
|
12
|
+
name?: string;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
attachmentId: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
bytes?: number;
|
|
17
|
+
}>;
|
|
18
|
+
saveImages?: (inputs: {
|
|
19
|
+
data: Uint8Array;
|
|
20
|
+
mediaType: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
}[]) => Promise<{
|
|
23
|
+
attachmentId: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
bytes?: number;
|
|
26
|
+
width?: number;
|
|
27
|
+
height?: number;
|
|
28
|
+
mediaType?: string;
|
|
29
|
+
}[]>;
|
|
30
|
+
}
|
|
31
|
+
export interface ImApiDeps {
|
|
32
|
+
projectRoot: () => string;
|
|
33
|
+
/**
|
|
34
|
+
* 宿主 DSH 的 `ctx.llm`。
|
|
35
|
+
*
|
|
36
|
+
* 插件不直连任何网关:模型目录、调用、默认模型都由 DSH 提供,
|
|
37
|
+
* 网关(如果有)是 DSH 自己配置的 provider,插件不感知。
|
|
38
|
+
*/
|
|
39
|
+
llm: () => LlmService | undefined;
|
|
40
|
+
/** 宿主 DSH 的附件存储 `ctx.attachments`(没挂载时图片只存本地、模型看不到内容)。 */
|
|
41
|
+
attachments?: () => DshAttachmentStore | undefined;
|
|
42
|
+
/** M2.1 原生 session(实验开关;未启用时返回 undefined,插件回退 ctx.llm)。 */
|
|
43
|
+
native?: () => NativeBridge | undefined;
|
|
44
|
+
/** 宿主注册的工作区列表:客户端只能在这些根之间切换,防止任意路径读写。 */
|
|
45
|
+
workspaces?: () => {
|
|
46
|
+
path?: string;
|
|
47
|
+
}[];
|
|
48
|
+
/** 宿主 tools 服务探测(能力契约保证不了时原生整体回退)。 */
|
|
49
|
+
hostTools?: () => {
|
|
50
|
+
register?: unknown;
|
|
51
|
+
guard?: unknown;
|
|
52
|
+
restrict?: unknown;
|
|
53
|
+
schemas?: unknown;
|
|
54
|
+
} | undefined;
|
|
55
|
+
/** 动态工具来源组目录(内置 4 能力 + 宿主来源组,面板刷新即发现新装工具)。 */
|
|
56
|
+
toolGroups?: () => ToolGroupCatalog;
|
|
57
|
+
/** 「用过的数据根」记忆文件(默认 ~/.dsh-im/known-roots.json;测试可注入)。 */
|
|
58
|
+
rootsFile?: () => string | undefined;
|
|
59
|
+
}
|
|
60
|
+
export declare function createImApi(deps: ImApiDeps): {
|
|
61
|
+
getState(projectRoot?: string): Promise<import("../core/types.ts").ImState | null>;
|
|
62
|
+
putState(raw: string, projectRoot?: string): Promise<{
|
|
63
|
+
path: string;
|
|
64
|
+
warnings: string[];
|
|
65
|
+
} | {
|
|
66
|
+
warnings?: undefined;
|
|
67
|
+
path: string;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* 数据根发现(只读):当前根 + DSH 注册工作区 + 以前用过的根,各自有没有数据。
|
|
71
|
+
* 面板加载失败时用它列出「哪个根里还有数据」,而不是静默显示空。
|
|
72
|
+
*/
|
|
73
|
+
stateRoots(): Promise<import("./state-roots.ts").StateRootInfo[]>;
|
|
74
|
+
/** 上传一个附件:字节落到本群 attachments/,图片/文件再登记到 DSH 附件存储(给模型用)。 */
|
|
75
|
+
uploadAttachment(body: {
|
|
76
|
+
threadId?: string;
|
|
77
|
+
projectRoot?: string;
|
|
78
|
+
name?: string;
|
|
79
|
+
mediaType?: string;
|
|
80
|
+
data?: Uint8Array;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
attachment: MessageAttachment;
|
|
83
|
+
url: string;
|
|
84
|
+
modelVisible: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
/** 读本群 attachments/ 下的附件字节(给界面预览/下载)。 */
|
|
87
|
+
attachmentFile(body: {
|
|
88
|
+
threadId?: string;
|
|
89
|
+
file?: string;
|
|
90
|
+
projectRoot?: string;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
bytes: Buffer;
|
|
93
|
+
mediaType: string;
|
|
94
|
+
}>;
|
|
95
|
+
/** 附件垃圾回收:默认 dryRun,只报告孤儿;显式 dryRun=false 才删除。 */
|
|
96
|
+
attachmentGc(body: {
|
|
97
|
+
threadId?: string;
|
|
98
|
+
dryRun?: boolean;
|
|
99
|
+
minAgeMs?: number;
|
|
100
|
+
}): Promise<{
|
|
101
|
+
root: string;
|
|
102
|
+
coveredRoots: string[];
|
|
103
|
+
results: ({
|
|
104
|
+
root: string;
|
|
105
|
+
} & import("./attachment-gc.ts").GcResult)[];
|
|
106
|
+
orphanEntries: {
|
|
107
|
+
root: string;
|
|
108
|
+
path: string;
|
|
109
|
+
}[];
|
|
110
|
+
scanned: number;
|
|
111
|
+
referenced: number;
|
|
112
|
+
orphans: string[];
|
|
113
|
+
freed: number;
|
|
114
|
+
wouldFree: number;
|
|
115
|
+
failed: number;
|
|
116
|
+
statFailed: number;
|
|
117
|
+
errored: number;
|
|
118
|
+
noDir: number;
|
|
119
|
+
dryRun: boolean;
|
|
120
|
+
}>;
|
|
121
|
+
models(): Promise<import("./models.ts").ModelOption[]>;
|
|
122
|
+
preflight(body: {
|
|
123
|
+
threadId?: string;
|
|
124
|
+
projectRoot?: string;
|
|
125
|
+
}): Promise<import("./preflight.ts").PreflightResult>;
|
|
126
|
+
complete(body: {
|
|
127
|
+
model?: string;
|
|
128
|
+
provider?: string;
|
|
129
|
+
system?: string;
|
|
130
|
+
user?: string;
|
|
131
|
+
messages?: {
|
|
132
|
+
role: 'user' | 'assistant' | 'system';
|
|
133
|
+
content: string | ModelContentPart[];
|
|
134
|
+
}[];
|
|
135
|
+
toolAllow?: string[];
|
|
136
|
+
projectRoot?: string;
|
|
137
|
+
threadId?: string;
|
|
138
|
+
/** 回执:这条回复对应的角色、窗口事件序号、摘要覆盖边界、事实版本。 */
|
|
139
|
+
personaId?: string;
|
|
140
|
+
windowSeqs?: number[];
|
|
141
|
+
summaryUntil?: number;
|
|
142
|
+
factsVersion?: string;
|
|
143
|
+
/** 角色状态快照 hash + 检索审计(回执变厚,用于回放/审计)。 */
|
|
144
|
+
stateSnapshotHash?: string;
|
|
145
|
+
retrievalQuery?: {
|
|
146
|
+
topicId: number;
|
|
147
|
+
entities: {
|
|
148
|
+
type: string;
|
|
149
|
+
value: string;
|
|
150
|
+
}[];
|
|
151
|
+
replyChainRoots: number[];
|
|
152
|
+
params: {
|
|
153
|
+
retrievalVersion: string;
|
|
154
|
+
topicSegVersion: string;
|
|
155
|
+
weights: Record<string, number>;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
retrievalHitIds?: number[];
|
|
159
|
+
retrievalSelectedIds?: number[];
|
|
160
|
+
indexVersion?: string;
|
|
161
|
+
/** reply(角色发言)/ extract(异步事实抽取)/ curate(共识整理),指标里区分。 */
|
|
162
|
+
purpose?: 'reply' | 'extract' | 'curate';
|
|
163
|
+
/** A-1 群级预算快照 + 变更事件(客户端组装时算好,回执/指标落盘)。 */
|
|
164
|
+
budget?: ContextBudgetReceipt;
|
|
165
|
+
budgetChanged?: BudgetChangedEvent;
|
|
166
|
+
/** 工具执行预算覆盖(缺省时 host 从 state + 成员模型窗口推导;见 resolveTurnBudget)。 */
|
|
167
|
+
memoryBudgetChars?: number;
|
|
168
|
+
budgetChars?: number;
|
|
169
|
+
budgetTier?: string;
|
|
170
|
+
/** Phase 1 句柄协议回执(含冷区章节目录审计)。 */
|
|
171
|
+
memoryContext?: MemoryContextReceipt;
|
|
172
|
+
}): Promise<{
|
|
173
|
+
text: string;
|
|
174
|
+
trace?: TurnStepTrace[] | undefined;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* 用 ctx.llm.stream 复刻一次和原生会话相近的请求,把原始异常(含 cause)原样返回。
|
|
178
|
+
* 不经过 agent 循环的 failure 投影。
|
|
179
|
+
*/
|
|
180
|
+
llmProbe(body: {
|
|
181
|
+
model?: string;
|
|
182
|
+
provider?: string;
|
|
183
|
+
system?: string;
|
|
184
|
+
prompt?: string;
|
|
185
|
+
maxTokens?: number;
|
|
186
|
+
reasoningEffort?: string;
|
|
187
|
+
tools?: unknown[];
|
|
188
|
+
/** 循环独有:系统提示更新方式。失败会话里是 in-history。 */
|
|
189
|
+
systemPromptUpdate?: 'in-history' | 'replace';
|
|
190
|
+
}): Promise<{
|
|
191
|
+
ok: boolean;
|
|
192
|
+
failure: {
|
|
193
|
+
message: string;
|
|
194
|
+
};
|
|
195
|
+
text?: undefined;
|
|
196
|
+
ms?: undefined;
|
|
197
|
+
provider?: undefined;
|
|
198
|
+
model?: undefined;
|
|
199
|
+
} | {
|
|
200
|
+
ok: boolean;
|
|
201
|
+
ms: number;
|
|
202
|
+
provider: string;
|
|
203
|
+
model: string;
|
|
204
|
+
text: string;
|
|
205
|
+
failure?: undefined;
|
|
206
|
+
} | {
|
|
207
|
+
text?: undefined;
|
|
208
|
+
ok: boolean;
|
|
209
|
+
ms: number;
|
|
210
|
+
provider: string | undefined;
|
|
211
|
+
model: string | undefined;
|
|
212
|
+
failure: unknown;
|
|
213
|
+
}>;
|
|
214
|
+
/** M2.1 原生 session 是否可用(客户端据此选择 transport;默认关)。 */
|
|
215
|
+
nativeStatus(): {
|
|
216
|
+
enabled: boolean;
|
|
217
|
+
reason?: string;
|
|
218
|
+
checks?: import("./agent-session.ts").NativeChecks;
|
|
219
|
+
capabilities?: {
|
|
220
|
+
read: boolean;
|
|
221
|
+
search: boolean;
|
|
222
|
+
write: boolean;
|
|
223
|
+
check: boolean;
|
|
224
|
+
};
|
|
225
|
+
hostToolGroups?: number;
|
|
226
|
+
};
|
|
227
|
+
/** 诊断:原生会话当前派生消息(排查空回复用;不含敏感 prompt)。 */
|
|
228
|
+
nativeDebug(): {
|
|
229
|
+
enabled: boolean;
|
|
230
|
+
sessions: unknown[];
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Phase 0 宿主能力探测:tokenizer / usage / embeddings 有没有。
|
|
234
|
+
* 只做形状探测 + 已观察到的 usage 字段;不主动发模型调用(那由 /llm-probe 触发)。
|
|
235
|
+
*/
|
|
236
|
+
capabilities(): HostCapabilityReport;
|
|
237
|
+
/** Phase 1b:当前数据根的 chars/token 校准(面板启动读取,用于把 token 预算换算成字符预算)。 */
|
|
238
|
+
/**
|
|
239
|
+
* L1/L2/L3 观测:校准样本报告 + 影子决策 + 各桶「若启用」预算。
|
|
240
|
+
* `charsPerToken`(客户端预算实际用的)**只在显式 shadow→calibrated 后才返回**,
|
|
241
|
+
* 其余情况返回空对象 + 完整 shadow 报告(零行为变更)。
|
|
242
|
+
*/
|
|
243
|
+
tokenCalibration(projectRoot?: string): Promise<{
|
|
244
|
+
mode: string;
|
|
245
|
+
totals: {
|
|
246
|
+
samples: number;
|
|
247
|
+
valid: number;
|
|
248
|
+
invalid: number;
|
|
249
|
+
};
|
|
250
|
+
buckets: {
|
|
251
|
+
bucket: string;
|
|
252
|
+
samples: number;
|
|
253
|
+
valid: number;
|
|
254
|
+
invalidShare: number;
|
|
255
|
+
prior: number;
|
|
256
|
+
median: number | undefined;
|
|
257
|
+
shadowRatio: number | undefined;
|
|
258
|
+
mode: import("../core/calibrator.ts").CalibrationMode;
|
|
259
|
+
wouldClamp: boolean;
|
|
260
|
+
reasons: string[];
|
|
261
|
+
wouldBeWindowChars: number;
|
|
262
|
+
wouldBeTokens: number;
|
|
263
|
+
}[];
|
|
264
|
+
charsPerToken: Record<string, number>;
|
|
265
|
+
}>;
|
|
266
|
+
/**
|
|
267
|
+
* Phase 0 记忆索引预览:构建/增量更新指定群的派生索引,返回统计(默认**不落盘**)。
|
|
268
|
+
* 只读诊断用;`persist:true` 才写 `.dsh-im/groups/<id>/index.json`。
|
|
269
|
+
*/
|
|
270
|
+
memoryIndex(body: {
|
|
271
|
+
threadId?: string;
|
|
272
|
+
projectRoot?: string;
|
|
273
|
+
persist?: boolean;
|
|
274
|
+
}): Promise<{
|
|
275
|
+
rebuilt: boolean;
|
|
276
|
+
reason: string;
|
|
277
|
+
stats: {
|
|
278
|
+
messages: number;
|
|
279
|
+
topics: number;
|
|
280
|
+
active: number;
|
|
281
|
+
superseded: number;
|
|
282
|
+
raw: number;
|
|
283
|
+
untrusted: number;
|
|
284
|
+
imperative: number;
|
|
285
|
+
};
|
|
286
|
+
cursor: import("./memory-index.ts").MemoryIndexCursor;
|
|
287
|
+
sample: import("./memory-index.ts").MemoryIndexEntry[];
|
|
288
|
+
}>;
|
|
289
|
+
/**
|
|
290
|
+
* 动态工具目录:内置 4 能力 + 宿主来源组(浏览器/MCP server/其他)。
|
|
291
|
+
* 面板每次打开/刷新都重新发现,用户新装的工具无需改代码即可出现在角色编辑器里。
|
|
292
|
+
*/
|
|
293
|
+
toolGroups(): {
|
|
294
|
+
capabilities: {
|
|
295
|
+
id: import("../core/tools.ts").CoreCapability;
|
|
296
|
+
label: string;
|
|
297
|
+
tools: string[];
|
|
298
|
+
}[];
|
|
299
|
+
groups: import("../core/tools.ts").DiscoveredToolGroup[];
|
|
300
|
+
native: boolean;
|
|
301
|
+
};
|
|
302
|
+
nativeComplete(body: {
|
|
303
|
+
sessionKey?: string;
|
|
304
|
+
personaId?: string;
|
|
305
|
+
model?: string;
|
|
306
|
+
provider?: string;
|
|
307
|
+
system?: string;
|
|
308
|
+
prompt?: string;
|
|
309
|
+
messages?: {
|
|
310
|
+
role?: string;
|
|
311
|
+
content?: string;
|
|
312
|
+
}[];
|
|
313
|
+
cwd?: string;
|
|
314
|
+
projectRoot?: string;
|
|
315
|
+
threadId?: string;
|
|
316
|
+
windowSeqs?: number[];
|
|
317
|
+
summaryUntil?: number;
|
|
318
|
+
factsVersion?: string;
|
|
319
|
+
frame?: NativeFrame;
|
|
320
|
+
nativeFrame?: NativeFrame;
|
|
321
|
+
toolAllow?: string[];
|
|
322
|
+
personaName?: string;
|
|
323
|
+
setupMode?: 'all' | 'off' | 'sections' | 'restrict' | 'bcdp' | 'mcp';
|
|
324
|
+
sessionIdOverride?: string;
|
|
325
|
+
maxTokens?: number;
|
|
326
|
+
reasoningEffort?: string;
|
|
327
|
+
/** 单轮工具调用上限(缺省读 DSH_IM_MAX_TOOL_CALLS / 12)。 */
|
|
328
|
+
maxToolCalls?: number;
|
|
329
|
+
/** A-1 群级预算快照 + 变更事件(与 ctx.llm 路径同一份回执口径)。 */
|
|
330
|
+
budget?: ContextBudgetReceipt;
|
|
331
|
+
budgetChanged?: BudgetChangedEvent;
|
|
332
|
+
/** Phase 1 句柄协议回执(含冷区章节目录审计;native 与 ctx.llm 同结构)。 */
|
|
333
|
+
memoryContext?: MemoryContextReceipt;
|
|
334
|
+
}): Promise<{
|
|
335
|
+
text: string;
|
|
336
|
+
trace?: TurnStepTrace[] | undefined;
|
|
337
|
+
toolStats?: import("./agent-session.ts").NativeToolStats | undefined;
|
|
338
|
+
}>;
|
|
339
|
+
writeFile(body: {
|
|
340
|
+
threadId?: string;
|
|
341
|
+
relativePath?: string;
|
|
342
|
+
content?: string;
|
|
343
|
+
projectRoot?: string;
|
|
344
|
+
}): Promise<{
|
|
345
|
+
path: string;
|
|
346
|
+
}>;
|
|
347
|
+
workspace(projectRoot?: string): Promise<{
|
|
348
|
+
path: string;
|
|
349
|
+
}>;
|
|
350
|
+
/** 宿主挂载时预热「用过的数据根」缓存,避免首个请求在缓存空的时候被判 400。 */
|
|
351
|
+
loadKnownRoots: () => Promise<void>;
|
|
352
|
+
};
|