dsh-plugin-om 0.0.42 → 0.0.44
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/README.md +67 -82
- package/dist/client/OmConfigCard.d.ts +9 -0
- package/dist/client/OmConfigCard.d.ts.map +1 -0
- package/dist/client/definition.d.ts +2 -2
- package/dist/client/definition.d.ts.map +1 -1
- package/dist/client/index.d.ts +4 -7
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/locales.d.ts +42 -1
- package/dist/client/locales.d.ts.map +1 -1
- package/dist/client/om-config-controller.d.ts +77 -0
- package/dist/client/om-config-controller.d.ts.map +1 -0
- package/dist/client.js +338 -31
- package/dist/client.js.map +1 -1
- package/dist/compaction-log.d.ts.map +1 -1
- package/dist/compress-loop.d.ts +1 -1
- package/dist/compress-loop.d.ts.map +1 -1
- package/dist/compress-view.d.ts.map +1 -1
- package/dist/compress.d.ts +1 -39
- package/dist/compress.d.ts.map +1 -1
- package/dist/config.d.ts +40 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +20 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/embedding.d.ts +2 -5
- package/dist/embedding.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +214 -108
- package/dist/logger.d.ts +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/om-event.d.ts.map +1 -1
- package/dist/recall-output.d.ts.map +1 -1
- package/dist/types.d.ts +14 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +55 -22
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
|
+
import { CompactionId } from "@deepseek-ai/dsh-compaction";
|
|
2
|
+
import { BlockAssembler, createToolResultMessage, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
1
3
|
import { scopeOf } from "@deepseek-ai/dsh-scope";
|
|
2
4
|
import { SessionId, SessionSeq } from "@deepseek-ai/dsh-session";
|
|
3
5
|
import { renderPrompt } from "@deepseek-ai/dsh-system-prompt";
|
|
4
|
-
import { BlockAssembler, createToolResultMessage } from "@deepseek-ai/dsh-llm";
|
|
5
6
|
import { SUBAGENT_DESCRIPTOR_VERSION } from "@deepseek-ai/dsh-subagent";
|
|
7
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
6
8
|
import { copyFileSync, existsSync, mkdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
7
9
|
import { homedir } from "node:os";
|
|
8
10
|
import path from "node:path";
|
|
9
11
|
import { fileURLToPath } from "node:url";
|
|
10
12
|
import { z } from "zod";
|
|
11
13
|
import { toJSONSchema } from "zod/v4/core";
|
|
14
|
+
import { AttachmentId } from "@deepseek-ai/dsh-attachment";
|
|
12
15
|
//#region \0rolldown/runtime.js
|
|
13
16
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
14
17
|
//#endregion
|
|
15
18
|
//#region src/constants.ts
|
|
19
|
+
/** 插件标识:日志前缀与历史日志的 source.plugin 取值。 */
|
|
20
|
+
const PLUGIN_LABEL = "dsh-plugin-om";
|
|
16
21
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* COMPACT_CHECKPOINT_PLUGIN / COMPACTION_ABORTED_ERROR / isPluginOwnedSource。
|
|
22
|
+
* 插件自产消息的 producer-owned source kind(format v4 要求消息 source 为生产者自有
|
|
23
|
+
* kind,与宿主 v3→v4 迁移对本插件旧日志的产出一致;types.ts 把它声明进宿主
|
|
24
|
+
* MessageSourceMap,使 UserMessage.source 原生接受该形态)。
|
|
21
25
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const PLUGIN_SOURCE_KIND = "plugin:dsh-plugin-om";
|
|
27
|
+
/** 构造插件自产消息的 source(compactionId 仅替换检查点消息传入)。 */
|
|
28
|
+
function omSource(compactionId) {
|
|
29
|
+
return {
|
|
30
|
+
kind: PLUGIN_SOURCE_KIND,
|
|
31
|
+
...compactionId === void 0 ? {} : { compactionId }
|
|
32
|
+
};
|
|
33
|
+
}
|
|
24
34
|
/** 压缩日志标签名:<history>...</history> 包裹观察/反思日志块。 */
|
|
25
35
|
const HISTORY_TAG = "history";
|
|
26
36
|
/** 压缩日志块开标签的 tip 属性(对 AI 的提醒:本块是历史压缩产物,不要复述)。 */
|
|
@@ -61,10 +71,12 @@ const ASK_USER_QUESTION_TOOL_NAME = "ask_user_question";
|
|
|
61
71
|
const COMPACTION_ABORTED_ERROR = "压缩已中止(signal aborted)";
|
|
62
72
|
/**
|
|
63
73
|
* 判定 user/message 的 source 是否为本插件自产或宿主压缩 checkpoint(压缩日志消息与
|
|
64
|
-
* 宿主压缩替换消息)。这类消息不占完整消息 index
|
|
74
|
+
* 宿主压缩替换消息)。这类消息不占完整消息 index。宿主迁移前的 v3 信封形态
|
|
75
|
+
* (kind 'plugin' + plugin 字段)仅作读取防御保留。
|
|
65
76
|
*/
|
|
66
77
|
function isPluginOwnedSource(source) {
|
|
67
78
|
if (source?.kind === "compact-checkpoint") return true;
|
|
79
|
+
if (source?.kind === "plugin:dsh-plugin-om") return true;
|
|
68
80
|
if (source?.kind !== "plugin") return false;
|
|
69
81
|
return source.plugin === "dsh-plugin-om" || source.plugin === "compact";
|
|
70
82
|
}
|
|
@@ -78,7 +90,7 @@ function isPluginOwnedSource(source) {
|
|
|
78
90
|
function makeLogger(ctx, debug) {
|
|
79
91
|
return {
|
|
80
92
|
step(message) {
|
|
81
|
-
if (debug) ctx.logger.debug(`${PLUGIN_LABEL}: ${message}`);
|
|
93
|
+
if (typeof debug === "function" ? debug() : debug) ctx.logger.debug(`${PLUGIN_LABEL}: ${message}`);
|
|
82
94
|
},
|
|
83
95
|
info(message) {
|
|
84
96
|
ctx.logger.info(`${PLUGIN_LABEL}: ${message}`);
|
|
@@ -232,20 +244,15 @@ function formatCompressionStats(phase, success, stats) {
|
|
|
232
244
|
if (usage !== void 0) lines.push(`usage 合计:${usageLine(usage)}`);
|
|
233
245
|
return lines.join("\n");
|
|
234
246
|
}
|
|
235
|
-
/** 构造插件自产 user 消息(子会话统计消息;
|
|
247
|
+
/** 构造插件自产 user 消息(子会话统计消息;source 为插件自有 kind)。 */
|
|
236
248
|
function makeStatsMessage(text) {
|
|
237
|
-
return {
|
|
238
|
-
id: uuid(),
|
|
239
|
-
role: "user",
|
|
249
|
+
return createUserMessage({
|
|
240
250
|
content: [{
|
|
241
251
|
type: "text",
|
|
242
252
|
text
|
|
243
253
|
}],
|
|
244
|
-
source:
|
|
245
|
-
|
|
246
|
-
plugin: PLUGIN_LABEL
|
|
247
|
-
}
|
|
248
|
-
};
|
|
254
|
+
source: omSource()
|
|
255
|
+
});
|
|
249
256
|
}
|
|
250
257
|
/**
|
|
251
258
|
* 把一次压缩工具循环的完整会话消息组落盘为子会话:ctx.sessions.create 创建子会话
|
|
@@ -7632,6 +7639,10 @@ function renderCompleteMessage(session, cm, pruner) {
|
|
|
7632
7639
|
function newQuietParser$1() {
|
|
7633
7640
|
return new import_lib.DOMParser({ onError: () => {} });
|
|
7634
7641
|
}
|
|
7642
|
+
/** 判定 DOM 节点为元素节点(nodeType 1;text/comment 等节点跳过)。 */
|
|
7643
|
+
function isElement(node) {
|
|
7644
|
+
return node?.nodeType === 1;
|
|
7645
|
+
}
|
|
7635
7646
|
/**
|
|
7636
7647
|
* 提取用户消息条目的文本与注释(文本块拼接为原文;图片/其他块降级为注释文本,
|
|
7637
7648
|
* 渲染时输出为 XML 注释)。无任何内容返回 null(该 index 在视图中不占条目)。
|
|
@@ -7989,9 +8000,8 @@ function parseBlockEntries(blockText, blockSeq) {
|
|
|
7989
8000
|
const entries = [];
|
|
7990
8001
|
const children = root.childNodes;
|
|
7991
8002
|
for (let i = 0; i < children.length; i += 1) {
|
|
7992
|
-
const
|
|
7993
|
-
if (
|
|
7994
|
-
const el = node;
|
|
8003
|
+
const el = children[i];
|
|
8004
|
+
if (!isElement(el)) continue;
|
|
7995
8005
|
const text = el.textContent ?? "";
|
|
7996
8006
|
if (el.nodeName === "user_message") {
|
|
7997
8007
|
const index = intAttr(el, "index");
|
|
@@ -8683,20 +8693,15 @@ function buildCompressionTaskText(phase, start, end) {
|
|
|
8683
8693
|
}
|
|
8684
8694
|
/** 模型输出纯文本(无工具调用)时追加的提醒消息文本。 */
|
|
8685
8695
|
const COMPRESSION_NUDGE_TEXT = "请通过工具执行压缩:用 getHistory 查看区间条目,用 compressHistory 压缩 assistant 条目,完成后调用 completeCompression。不要输出与工具调用无关的文本。";
|
|
8686
|
-
/** 构造插件自产 user 消息(压缩指令/提醒;
|
|
8696
|
+
/** 构造插件自产 user 消息(压缩指令/提醒;source 为插件自有 kind)。 */
|
|
8687
8697
|
function makePluginUserMessage(text) {
|
|
8688
|
-
return {
|
|
8689
|
-
id: uuid(),
|
|
8690
|
-
role: "user",
|
|
8698
|
+
return createUserMessage({
|
|
8691
8699
|
content: [{
|
|
8692
8700
|
type: "text",
|
|
8693
8701
|
text
|
|
8694
8702
|
}],
|
|
8695
|
-
source:
|
|
8696
|
-
|
|
8697
|
-
plugin: PLUGIN_LABEL
|
|
8698
|
-
}
|
|
8699
|
-
};
|
|
8703
|
+
source: omSource()
|
|
8704
|
+
});
|
|
8700
8705
|
}
|
|
8701
8706
|
/** 把工具执行结果封装为 tool-result 消息(回填到压缩会话)。 */
|
|
8702
8707
|
function toolResultOf(call, result) {
|
|
@@ -8892,21 +8897,13 @@ async function runCompressionLoop(ctx, session, options) {
|
|
|
8892
8897
|
//#region src/om-event.ts
|
|
8893
8898
|
/** om 信封 text 前缀:标识该 feedback/record 记录由本插件写入。 */
|
|
8894
8899
|
const OM_EVENT_PREFIX = "om:1:";
|
|
8895
|
-
/** 校验载荷字段与类别匹配(运行时守卫,保证返回类型的诚实性)。 */
|
|
8896
|
-
function isValidPayload(kind, data) {
|
|
8897
|
-
switch (kind) {
|
|
8898
|
-
case "om/warning": return typeof data.problem === "string" && typeof data.message === "string";
|
|
8899
|
-
case "om/observe-pending": return typeof data.triggerMessageIndex === "number" && Number.isSafeInteger(data.triggerMessageIndex);
|
|
8900
|
-
case "om/observe-invalidate": return typeof data.pendingSeq === "number" && Number.isSafeInteger(data.pendingSeq);
|
|
8901
|
-
}
|
|
8902
|
-
}
|
|
8903
8900
|
/**
|
|
8904
8901
|
* 解码一条会话事件为 om 私有事件:仅识别 feedback/record 中带 om 信封前缀的
|
|
8905
8902
|
* text;前缀缺失、JSON 非法、kind 未知或载荷字段缺失时返回 undefined。
|
|
8906
8903
|
*/
|
|
8907
8904
|
function readOmEvent(event) {
|
|
8908
8905
|
if (event === void 0 || event === null || event.type !== "feedback/record") return void 0;
|
|
8909
|
-
const text = event.data
|
|
8906
|
+
const text = event.data.text;
|
|
8910
8907
|
if (typeof text !== "string" || !text.startsWith("om:1:")) return void 0;
|
|
8911
8908
|
let envelope;
|
|
8912
8909
|
try {
|
|
@@ -8916,19 +8913,39 @@ function readOmEvent(event) {
|
|
|
8916
8913
|
}
|
|
8917
8914
|
if (envelope === null || typeof envelope !== "object" || Array.isArray(envelope)) return void 0;
|
|
8918
8915
|
const { kind, ...rest } = envelope;
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8916
|
+
switch (kind) {
|
|
8917
|
+
case "om/warning": {
|
|
8918
|
+
const { problem, message } = rest;
|
|
8919
|
+
if (typeof problem !== "string" || typeof message !== "string") return void 0;
|
|
8920
|
+
return {
|
|
8921
|
+
kind,
|
|
8922
|
+
data: {
|
|
8923
|
+
problem,
|
|
8924
|
+
message
|
|
8925
|
+
},
|
|
8926
|
+
seq: event.seq
|
|
8927
|
+
};
|
|
8928
|
+
}
|
|
8929
|
+
case "om/observe-pending": {
|
|
8930
|
+
const { triggerMessageIndex } = rest;
|
|
8931
|
+
if (typeof triggerMessageIndex !== "number" || !Number.isSafeInteger(triggerMessageIndex)) return void 0;
|
|
8932
|
+
return {
|
|
8933
|
+
kind,
|
|
8934
|
+
data: { triggerMessageIndex },
|
|
8935
|
+
seq: event.seq
|
|
8936
|
+
};
|
|
8937
|
+
}
|
|
8938
|
+
case "om/observe-invalidate": {
|
|
8939
|
+
const { pendingSeq } = rest;
|
|
8940
|
+
if (typeof pendingSeq !== "number" || !Number.isSafeInteger(pendingSeq)) return void 0;
|
|
8941
|
+
return {
|
|
8942
|
+
kind,
|
|
8943
|
+
data: { pendingSeq },
|
|
8944
|
+
seq: event.seq
|
|
8945
|
+
};
|
|
8946
|
+
}
|
|
8947
|
+
default: return;
|
|
8948
|
+
}
|
|
8932
8949
|
}
|
|
8933
8950
|
/** 编码一条 om 私有事件为 feedback/record 的 text 信封。 */
|
|
8934
8951
|
function encodeOmEvent(kind, data) {
|
|
@@ -8995,6 +9012,44 @@ function reportDegrade(session, logger, problem) {
|
|
|
8995
9012
|
}
|
|
8996
9013
|
//#endregion
|
|
8997
9014
|
//#region src/compress.ts
|
|
9015
|
+
/**
|
|
9016
|
+
* 两级自动压缩(观察/反思)与 compaction 生命周期提交。
|
|
9017
|
+
* 导出 estimateTextTokens / isPairBalancedAfter / computeCompressRange / historySection /
|
|
9018
|
+
* findObservePending / reflectPass / observePass / maybeCompress。
|
|
9019
|
+
*
|
|
9020
|
+
* - 摘要生成走工具驱动的压缩循环(compress-loop.ts runCompressionLoop):首条 user
|
|
9021
|
+
* 消息仅含压缩指令与 start/end 区间,模型经 getHistory / compressHistory /
|
|
9022
|
+
* completeCompression 工具完成压缩;最终 <history> 块由插件从视图与替换记录构建,
|
|
9023
|
+
* 全程无需整块校验
|
|
9024
|
+
* - 反思:全部 <history> 块 token 合计 ≥ reflectThresholdTokens 时,把全部块条目作为
|
|
9025
|
+
* 压缩视图重新压缩合并(视图无条目时跳过,如全部为不可解析的历史遗留块)
|
|
9026
|
+
* - 观察(触发 → 待定 → 延迟执行):净压力(上下文压力 − 已压缩块 token 合计 − 系统提示词
|
|
9027
|
+
* token 估算 − 工具定义 token 估算)首次 ≥ observeThresholdTokens 时记录待定标记
|
|
9028
|
+
* (触发点 = 当时的最后一条完整消息 index),本次不压缩;待定后新增完整消息数 ≥
|
|
9029
|
+
* tailMessageCount 时,把压缩边界至触发点的全部消息作为压缩视图替换为新 <history>
|
|
9030
|
+
* 块(旧块保留),等待期间的新消息成为下一轮未压缩尾部(延迟窗口内压力允许
|
|
9031
|
+
* 短暂超阈值);tailMessageCount=0 时触发当轮直接执行(不落待定标记)
|
|
9032
|
+
* - 待定标记以 log-only om 信封事件(借用 feedback/record,kind 为 om/observe-pending /
|
|
9033
|
+
* om/observe-invalidate,见 om-event.ts)持久化在会话日志中(重启后从日志恢复);
|
|
9034
|
+
* 压缩失败保留待定,下个 pre-step 直接重试执行
|
|
9035
|
+
* - 两级在 pre-step 阻塞串行执行(先反思后观察);仅主会话生效;omEnabled=false 关闭
|
|
9036
|
+
* - 压缩目标默认跟随会话路由;compressProvider + compressModel 成对配置时覆盖路由
|
|
9037
|
+
* (成对配置下未路由会话也执行压缩);compressReasoningEffort 配置时压缩前经
|
|
9038
|
+
* ctx.llm.resolveModelInfo 校验目标模型 reasoning.efforts(按 provider+model 缓存),
|
|
9039
|
+
* 未命中 / 无元数据 / 查询失败降级为模型默认并报告 reasoning-effort-unavailable 降级
|
|
9040
|
+
* - 压缩边界:最后一个合法 <history> 块之后的消息视为未压缩,其前不重复压缩
|
|
9041
|
+
* - 压缩循环最终失败(连续无工具调用 / 请求级错误)时 pass 返回失败结果(携带最后一次
|
|
9042
|
+
* 错误),压缩流程向上传播,pre-step 据此拒绝本 step 中断当前 turn;signal 中止标记
|
|
9043
|
+
* aborted(不中断);成功与失败均落盘压缩会话记录子会话(失败时其 id 随结果传播为
|
|
9044
|
+
* 诊断子会话 id)
|
|
9045
|
+
* - 提交走宿主 compaction/* 生命周期事件(start 带 phase → summary → 替换消息 → end),
|
|
9046
|
+
* 失败补 end(error,实际报错 + 诊断子会话 sessionId);替换消息 source 标记插件标识供 UI 认领
|
|
9047
|
+
* - 挂载失败类问题(systemPrompt/tokenMeter 服务异常)始终 console 到外部进程,并追加
|
|
9048
|
+
* log-only om 警告事件(借用 feedback/record,客户端渲染功能降级警告行,每会话同一
|
|
9049
|
+
* 问题至多一次);
|
|
9050
|
+
* 辅助估算的普通运行时报错仅记日志。降级与报错都不阻塞压缩(tokenMeter 压力数据
|
|
9051
|
+
* 缺失时本轮跳过观察)
|
|
9052
|
+
*/
|
|
8998
9053
|
/** 历史文本 token 估算:4 字符 ≈ 1 token(与宿主 dsh-token-meter 启发式一致)。 */
|
|
8999
9054
|
function estimateTextTokens(text) {
|
|
9000
9055
|
return Math.ceil(text.length / 4);
|
|
@@ -9066,8 +9121,7 @@ async function runPassLoop(ctx, session, lifecycle, options, logger, phase) {
|
|
|
9066
9121
|
*/
|
|
9067
9122
|
function historyTextOf(event) {
|
|
9068
9123
|
if (event?.type !== "user/message") return void 0;
|
|
9069
|
-
|
|
9070
|
-
if (!isPluginOwnedSource(source)) return void 0;
|
|
9124
|
+
if (!isPluginOwnedSource(event.data.source)) return void 0;
|
|
9071
9125
|
const text = blocksToText(event.data.content);
|
|
9072
9126
|
const idx = text.indexOf(`<${HISTORY_TAG}`);
|
|
9073
9127
|
if (idx === -1) return void 0;
|
|
@@ -9201,9 +9255,9 @@ function openTurnOf(session) {
|
|
|
9201
9255
|
else if (event.type === "turn/end") turn = null;
|
|
9202
9256
|
return turn;
|
|
9203
9257
|
}
|
|
9204
|
-
/** 生成宿主 compaction 生命周期 id
|
|
9258
|
+
/** 生成宿主 compaction 生命周期 id(经宿主品牌构造函数标注)。 */
|
|
9205
9259
|
function newCompactionId() {
|
|
9206
|
-
return uuid();
|
|
9260
|
+
return CompactionId(uuid());
|
|
9207
9261
|
}
|
|
9208
9262
|
/** 追加 compaction/start(log-only;载荷带 phase 区分观察/反思),返回事件 seq。 */
|
|
9209
9263
|
function appendCompactionStart(session, lifecycle, phase) {
|
|
@@ -9261,19 +9315,13 @@ function appendCompactionEnd(session, lifecycle, error, diagnosticSessionId, dur
|
|
|
9261
9315
|
}
|
|
9262
9316
|
/** 追加 <history> 压缩日志消息(surfaceOp 替换遮蔽区间,source 标记插件自产 + compactionId)。 */
|
|
9263
9317
|
function appendHistoryMessage(session, content, sourceEventSeqs, surfaceOp, compactionId) {
|
|
9264
|
-
const message = {
|
|
9265
|
-
id: uuid(),
|
|
9266
|
-
role: "user",
|
|
9318
|
+
const message = createUserMessage({
|
|
9267
9319
|
content: [{
|
|
9268
9320
|
type: "text",
|
|
9269
9321
|
text: content
|
|
9270
9322
|
}],
|
|
9271
|
-
source:
|
|
9272
|
-
|
|
9273
|
-
plugin: PLUGIN_LABEL,
|
|
9274
|
-
compactionId
|
|
9275
|
-
}
|
|
9276
|
-
};
|
|
9323
|
+
source: omSource(compactionId)
|
|
9324
|
+
});
|
|
9277
9325
|
session.append("user/message", message, {
|
|
9278
9326
|
surfaceOp: {
|
|
9279
9327
|
op: "replace",
|
|
@@ -9783,21 +9831,23 @@ function ensureModelSmallFiles(modelDir, bundledDir = BUNDLED_MODEL_DIR) {
|
|
|
9783
9831
|
}
|
|
9784
9832
|
/** 单批最大文本数(避免单次推理过大)。 */
|
|
9785
9833
|
const BATCH_SIZE = 32;
|
|
9786
|
-
/**
|
|
9787
|
-
|
|
9788
|
-
/**
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
*/
|
|
9834
|
+
/** 各模型目录的单飞加载缓存。 */
|
|
9835
|
+
const pipelines = /* @__PURE__ */ new Map();
|
|
9836
|
+
/** 懒加载 transformers 模块,跨模型目录并发初始化共享同一个导入。 */
|
|
9837
|
+
let transformersPromise;
|
|
9838
|
+
/** 获取模型目录对应的嵌入函数,同目录单飞,失败允许再次加载。 */
|
|
9792
9839
|
function getEmbedder(modelDir = BUNDLED_MODEL_DIR) {
|
|
9793
|
-
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
|
|
9797
|
-
|
|
9798
|
-
|
|
9799
|
-
|
|
9800
|
-
const extractor = await pipeline("feature-extraction",
|
|
9840
|
+
const directory = path.resolve(modelDir);
|
|
9841
|
+
const existing = pipelines.get(directory);
|
|
9842
|
+
if (existing) return existing;
|
|
9843
|
+
const loading = (async () => {
|
|
9844
|
+
ensureModelSmallFiles(directory);
|
|
9845
|
+
if (!transformersPromise) transformersPromise = import("@huggingface/transformers");
|
|
9846
|
+
const { pipeline } = await transformersPromise;
|
|
9847
|
+
const extractor = await pipeline("feature-extraction", directory, {
|
|
9848
|
+
dtype: "q8",
|
|
9849
|
+
local_files_only: true
|
|
9850
|
+
});
|
|
9801
9851
|
return async (texts) => {
|
|
9802
9852
|
const vectors = [];
|
|
9803
9853
|
for (let i = 0; i < texts.length; i += BATCH_SIZE) {
|
|
@@ -9817,7 +9867,11 @@ function getEmbedder(modelDir = BUNDLED_MODEL_DIR) {
|
|
|
9817
9867
|
return vectors;
|
|
9818
9868
|
};
|
|
9819
9869
|
})();
|
|
9820
|
-
|
|
9870
|
+
pipelines.set(directory, loading);
|
|
9871
|
+
loading.catch(() => {
|
|
9872
|
+
if (pipelines.get(directory) === loading) pipelines.delete(directory);
|
|
9873
|
+
});
|
|
9874
|
+
return loading;
|
|
9821
9875
|
}
|
|
9822
9876
|
/** 每个 modelDir 的在途下载任务(单飞:并发查询只发起一次下载)。 */
|
|
9823
9877
|
const inflightDownloads = /* @__PURE__ */ new Map();
|
|
@@ -9862,9 +9916,9 @@ function cosineSimilarity(a, b) {
|
|
|
9862
9916
|
//#endregion
|
|
9863
9917
|
//#region src/config.ts
|
|
9864
9918
|
/**
|
|
9865
|
-
*
|
|
9866
|
-
* 导出 PluginConfig / DEFAULT_CONFIG / resolveConfig
|
|
9867
|
-
*
|
|
9919
|
+
* 插件配置:宿主 Config 严格校验、volatile 引用读取与兼容 YAML 的宽松合并。
|
|
9920
|
+
* 导出 Config / PluginConfig / DEFAULT_CONFIG / currentConfig / resolveConfig;
|
|
9921
|
+
* 旧输入在 resolveConfig 中未知键忽略、非法值回退默认值。
|
|
9868
9922
|
*/
|
|
9869
9923
|
/** 默认配置(冻结对象,resolveConfig 合并的基底;debug 缺省值在解析时按 NODE_ENV 判定)。 */
|
|
9870
9924
|
const DEFAULT_CONFIG = Object.freeze({
|
|
@@ -9883,6 +9937,33 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
9883
9937
|
compressModel: void 0,
|
|
9884
9938
|
compressReasoningEffort: void 0
|
|
9885
9939
|
});
|
|
9940
|
+
/** 宿主保存时严格校验,所有字段均为稳定 volatile 引用,运行时由 Loader 原地提交。 */
|
|
9941
|
+
const Config = Schema.object({
|
|
9942
|
+
observeThresholdTokens: Schema.number().step(1).default(DEFAULT_CONFIG.observeThresholdTokens).volatile(),
|
|
9943
|
+
reflectThresholdTokens: Schema.number().step(1).default(DEFAULT_CONFIG.reflectThresholdTokens).volatile(),
|
|
9944
|
+
compressMaxTokens: Schema.number().step(1).volatile(),
|
|
9945
|
+
rateLimitWaitMs: Schema.number().step(1).default(DEFAULT_CONFIG.rateLimitWaitMs).volatile(),
|
|
9946
|
+
tailMessageCount: Schema.number().step(1).default(DEFAULT_CONFIG.tailMessageCount).volatile(),
|
|
9947
|
+
compressSkipReasoning: Schema.boolean().default(DEFAULT_CONFIG.compressSkipReasoning).volatile(),
|
|
9948
|
+
omEnabled: Schema.boolean().default(DEFAULT_CONFIG.omEnabled).volatile(),
|
|
9949
|
+
debug: Schema.boolean().default(process.env.NODE_ENV !== "production").volatile(),
|
|
9950
|
+
recallEnabled: Schema.boolean().default(DEFAULT_CONFIG.recallEnabled).volatile(),
|
|
9951
|
+
semanticRecallEnabled: Schema.boolean().default(DEFAULT_CONFIG.semanticRecallEnabled).volatile(),
|
|
9952
|
+
modelDir: Schema.string().default(DEFAULT_CONFIG.modelDir).volatile(),
|
|
9953
|
+
compressProvider: Schema.string().volatile(),
|
|
9954
|
+
compressModel: Schema.string().volatile(),
|
|
9955
|
+
compressReasoningEffort: Schema.string().volatile()
|
|
9956
|
+
}).default({});
|
|
9957
|
+
/** 解析宿主 volatile 引用中的当前值,也兼容直接传入的原始配置对象。 */
|
|
9958
|
+
function currentConfig(config) {
|
|
9959
|
+
if (!isRecord(config)) return resolveConfig(config);
|
|
9960
|
+
const values = {};
|
|
9961
|
+
for (const key of Object.keys(DEFAULT_CONFIG)) {
|
|
9962
|
+
const value = config[key];
|
|
9963
|
+
values[key] = isRecord(value) && typeof value.get === "function" ? value.get() : value;
|
|
9964
|
+
}
|
|
9965
|
+
return resolveConfig(values);
|
|
9966
|
+
}
|
|
9886
9967
|
/** 数值键校验参数表:键名 + [是否必须为整数]。 */
|
|
9887
9968
|
const NUMBER_KEYS = [
|
|
9888
9969
|
["observeThresholdTokens", true],
|
|
@@ -9947,6 +10028,13 @@ function parametersFromZod(schema) {
|
|
|
9947
10028
|
}
|
|
9948
10029
|
//#endregion
|
|
9949
10030
|
//#region src/recall-output.ts
|
|
10031
|
+
/**
|
|
10032
|
+
* recall / recall-semantic 共享输出契约:输出值为固定形态 { text, images }。
|
|
10033
|
+
* text 为完整消息的 XML 条目序列(形态见 recall-xml.ts,图片位置以 XML 注释标注),
|
|
10034
|
+
* images 为图片附件元数据(按 attachmentId 引用,不含字节)。
|
|
10035
|
+
* 导出 ImageRefValue / RecallOutputValue / RECALL_OUTPUT_SCHEMA / textOnly / imageNote /
|
|
10036
|
+
* renderRecallOutput。
|
|
10037
|
+
*/
|
|
9950
10038
|
/** 纯文本结果(无图片)的便捷构造。 */
|
|
9951
10039
|
function textOnly(text) {
|
|
9952
10040
|
return {
|
|
@@ -10020,7 +10108,14 @@ function renderRecallOutput(value) {
|
|
|
10020
10108
|
for (const ref of value.images) {
|
|
10021
10109
|
const block = {
|
|
10022
10110
|
type: "image",
|
|
10023
|
-
attachment:
|
|
10111
|
+
attachment: {
|
|
10112
|
+
attachmentId: AttachmentId(ref.attachmentId),
|
|
10113
|
+
mediaType: ref.mediaType,
|
|
10114
|
+
bytes: ref.bytes,
|
|
10115
|
+
width: ref.width,
|
|
10116
|
+
height: ref.height,
|
|
10117
|
+
...ref.name === void 0 ? {} : { name: ref.name }
|
|
10118
|
+
}
|
|
10024
10119
|
};
|
|
10025
10120
|
blocks.push(block);
|
|
10026
10121
|
}
|
|
@@ -10382,16 +10477,6 @@ function buildSemanticRecallTool(options) {
|
|
|
10382
10477
|
}
|
|
10383
10478
|
//#endregion
|
|
10384
10479
|
//#region src/index.ts
|
|
10385
|
-
/**
|
|
10386
|
-
* dsh-plugin-om 入口(tsdown 打包入口):导出 name / inject / apply。
|
|
10387
|
-
* apply 注册 recall / recall-semantic 工具,并接线 agent/pre-step 自动压缩
|
|
10388
|
-
* (先反思后观察,仅主会话生效)。压缩走工具驱动的压缩循环(模型经 getHistory /
|
|
10389
|
-
* compressHistory / completeCompression 工具完成,见 compress-loop.ts);最终失败
|
|
10390
|
-
* (连续无工具调用 / 请求级错误)时拒绝本 step 中断当前 turn(signal 中止除外),
|
|
10391
|
-
* 主会话日志记录失败原因与诊断子会话 sessionId(完整循环会话由 compaction-log.ts
|
|
10392
|
-
* 落盘为子会话)。压缩与检索的实现见 compress.ts / compress-loop.ts /
|
|
10393
|
-
* compaction-log.ts / recall.ts / semantic-recall.ts。
|
|
10394
|
-
*/
|
|
10395
10480
|
/** 插件名(Loader 识别入口的稳定标识)。 */
|
|
10396
10481
|
const name = "dsh-plugin-om";
|
|
10397
10482
|
/** 插件注入的服务依赖(tools/llm/tokenMeter/sessions),由宿主按序注入。 */
|
|
@@ -10403,20 +10488,41 @@ const inject = [
|
|
|
10403
10488
|
];
|
|
10404
10489
|
/** 插件激活入口:解析配置、注册工具、接线 pre-step 自动压缩。 */
|
|
10405
10490
|
function apply(ctx, config) {
|
|
10406
|
-
const resolved =
|
|
10407
|
-
const logger = makeLogger(ctx,
|
|
10491
|
+
const resolved = currentConfig(config);
|
|
10492
|
+
const logger = makeLogger(ctx, () => currentConfig(config).debug);
|
|
10408
10493
|
logger.step(`apply 启动:observeThresholdTokens=${String(resolved.observeThresholdTokens)} reflectThresholdTokens=${String(resolved.reflectThresholdTokens)} compressMaxTokens=${resolved.compressMaxTokens === void 0 ? "未设置" : String(resolved.compressMaxTokens)} tailMessageCount=${String(resolved.tailMessageCount)} omEnabled=${String(resolved.omEnabled)} debug=${String(resolved.debug)} compressProvider=${resolved.compressProvider ?? "跟随会话路由"} compressModel=${resolved.compressModel ?? "跟随会话路由"} compressReasoningEffort=${resolved.compressReasoningEffort ?? "模型默认"}`);
|
|
10409
|
-
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
|
|
10413
|
-
|
|
10414
|
-
|
|
10415
|
-
|
|
10416
|
-
|
|
10417
|
-
|
|
10418
|
-
|
|
10494
|
+
const warnModel = (message) => ctx.logger.warn(`dsh-plugin-om: ${message}`);
|
|
10495
|
+
const logModel = (message) => logger.info(message);
|
|
10496
|
+
let disposeRecall;
|
|
10497
|
+
let disposeSemantic;
|
|
10498
|
+
let modelDir = resolved.modelDir;
|
|
10499
|
+
let semanticEnabled = false;
|
|
10500
|
+
/** 保持实际注册列表与当前配置一致;仅首次启用或更换目录时启动后台预热。 */
|
|
10501
|
+
function syncTools() {
|
|
10502
|
+
const next = currentConfig(config);
|
|
10503
|
+
if (next.recallEnabled && !disposeRecall) disposeRecall = ctx.tools.register(buildRecallTool(() => ctx.get("toolResultPruner")));
|
|
10504
|
+
else if (!next.recallEnabled && disposeRecall) {
|
|
10505
|
+
disposeRecall();
|
|
10506
|
+
disposeRecall = void 0;
|
|
10507
|
+
}
|
|
10508
|
+
if (disposeSemantic && (!next.semanticRecallEnabled || next.modelDir !== modelDir)) {
|
|
10509
|
+
disposeSemantic();
|
|
10510
|
+
disposeSemantic = void 0;
|
|
10511
|
+
}
|
|
10512
|
+
if (next.semanticRecallEnabled && !disposeSemantic) {
|
|
10513
|
+
const directory = next.modelDir;
|
|
10514
|
+
disposeSemantic = ctx.tools.register(buildSemanticRecallTool({
|
|
10515
|
+
getPruner: () => ctx.get("toolResultPruner"),
|
|
10516
|
+
modelStatus: () => ensureModelReady(directory, warnModel, void 0, logModel),
|
|
10517
|
+
embedder: (texts) => getEmbedder(directory).then((embed) => embed(texts))
|
|
10518
|
+
}));
|
|
10519
|
+
}
|
|
10520
|
+
if (next.semanticRecallEnabled && (!semanticEnabled || next.modelDir !== modelDir)) ensureModelReady(next.modelDir, warnModel, void 0, logModel);
|
|
10521
|
+
modelDir = next.modelDir;
|
|
10522
|
+
semanticEnabled = next.semanticRecallEnabled;
|
|
10419
10523
|
}
|
|
10524
|
+
syncTools();
|
|
10525
|
+
ctx.on("loader/volatile-update", () => syncTools());
|
|
10420
10526
|
ctx.on("agent/pre-step", async ({ agent, signal }, next) => {
|
|
10421
10527
|
let outcome = { failed: false };
|
|
10422
10528
|
try {
|
|
@@ -10424,7 +10530,7 @@ function apply(ctx, config) {
|
|
|
10424
10530
|
else if (!isMainSession(agent.session)) logger.step("subagent 会话,跳过压缩(仅主会话生效)");
|
|
10425
10531
|
else {
|
|
10426
10532
|
logger.step(`pre-step 触发压缩(会话 ${agent.session.id})`);
|
|
10427
|
-
outcome = await maybeCompress(ctx, agent,
|
|
10533
|
+
outcome = await maybeCompress(ctx, agent, currentConfig(config), signal);
|
|
10428
10534
|
}
|
|
10429
10535
|
} catch (error) {
|
|
10430
10536
|
logger.warn(`pre-step 处理失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -10438,4 +10544,4 @@ function apply(ctx, config) {
|
|
|
10438
10544
|
});
|
|
10439
10545
|
}
|
|
10440
10546
|
//#endregion
|
|
10441
|
-
export { apply, inject, name };
|
|
10547
|
+
export { Config, apply, inject, name };
|
package/dist/logger.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export type PluginLogger = {
|
|
|
9
9
|
warn(message: string): void;
|
|
10
10
|
};
|
|
11
11
|
/** 构建插件日志门面:统一加 PLUGIN_LABEL 前缀,step 按 debug 开关过滤。 */
|
|
12
|
-
export declare function makeLogger(ctx: Context, debug: boolean): PluginLogger;
|
|
12
|
+
export declare function makeLogger(ctx: Context, debug: boolean | (() => boolean)): PluginLogger;
|
|
13
13
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,6CAA6C;AAC7C,MAAM,MAAM,YAAY,GAAG;IACzB,4BAA4B;IAC5B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,kBAAkB;IAClB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,mBAAmB;IACnB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,sDAAsD;AACtD,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,6CAA6C;AAC7C,MAAM,MAAM,YAAY,GAAG;IACzB,4BAA4B;IAC5B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,kBAAkB;IAClB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,mBAAmB;IACnB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,sDAAsD;AACtD,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,YAAY,CAavF"}
|
package/dist/om-event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"om-event.d.ts","sourceRoot":"","sources":["../src/om-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAExD,kDAAkD;AAClD,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC,6BAA6B;AAC7B,MAAM,MAAM,WAAW;AACrB,4CAA4C;AAC1C,YAAY;AACd,qCAAqC;GACnC,oBAAoB;AACtB,uCAAuC;GACrC,uBAAuB,CAAC;AAE5B,iCAAiC;AACjC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,EAAE;QACZ,qCAAqC;QACrC,OAAO,EAAE,MAAM,CAAC;QAChB,iBAAiB;QACjB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,oBAAoB,EAAE;QACpB,8BAA8B;QAC9B,mBAAmB,EAAE,MAAM,CAAC;KAC7B,CAAC;IACF,uBAAuB,EAAE;QACvB,sCAAsC;QACtC,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,OAAO,GAAG;KACnB,CAAC,IAAI,WAAW,GAAG;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;CACzE,CAAC,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"om-event.d.ts","sourceRoot":"","sources":["../src/om-event.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAExD,kDAAkD;AAClD,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC,6BAA6B;AAC7B,MAAM,MAAM,WAAW;AACrB,4CAA4C;AAC1C,YAAY;AACd,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AC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recall-output.d.ts","sourceRoot":"","sources":["../src/recall-output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"recall-output.d.ts","sourceRoot":"","sources":["../src/recall-output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,wDAAwD;AACxD,MAAM,MAAM,aAAa,GAAG;IAC1B,yCAAyC;IACzC,YAAY,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW;IACX,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,6DAA6D;AAC7D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC;AAEF,uBAAuB;AACvB,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAExD;AAED,qDAAqD;AACrD,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAGpD;AAED,0CAA0C;AAC1C,eAAO,MAAM,oBAAoB,EAAE,cA6BlC,CAAC;AAEF,iDAAiD;AACjD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,EAAE,CAmB3E"}
|
package/dist/types.d.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* 共享类型:宿主类型再导出(type-only,编译期擦除)+ 插件领域类型。
|
|
3
3
|
* 导出官方包宿主类型(Context/Agent/Session 等)、PluginConfig、
|
|
4
4
|
* MessageNode/MessageIndex/CompleteMessage(完整消息索引)与 compaction 载荷扩展。
|
|
5
|
-
* 各 dsh-* 包通过 declare module 增强 Context/Events,使 ctx.tools
|
|
5
|
+
* 各 dsh-* 包通过 declare module 增强 Context/Events,使 ctx.tools 等获得宿主一致类型;
|
|
6
|
+
* 本文件同时向宿主 MessageSourceMap 声明插件自产消息的 producer-owned source
|
|
7
|
+
* ('plugin:dsh-plugin-om',见 constants.ts),使写入的 source 形态原生可类型化。
|
|
6
8
|
*/
|
|
7
9
|
import type { Context, EventOptions, Events } from '@deepseek-ai/cordis';
|
|
8
10
|
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
@@ -14,8 +16,19 @@ import type { SubagentResult, SubagentRun, SubagentStartRequest } from '@deepsee
|
|
|
14
16
|
import type { SystemPrompt } from '@deepseek-ai/dsh-system-prompt';
|
|
15
17
|
import type { TokenMeter } from '@deepseek-ai/dsh-token-meter';
|
|
16
18
|
import type { JsonSchemaNode, ToolDefinition, ToolRunContext } from '@deepseek-ai/dsh-tools';
|
|
19
|
+
import type { OmMessageSource } from './constants.ts';
|
|
17
20
|
/** 插件配置类型(来自 config.ts)。 */
|
|
18
21
|
export type { PluginConfig } from './config.ts';
|
|
22
|
+
declare module '@deepseek-ai/dsh-llm' {
|
|
23
|
+
interface MessageSourceMap {
|
|
24
|
+
/**
|
|
25
|
+
* 插件自产消息的 producer-owned source(与宿主 MessageSourceMap 的官方扩展机制
|
|
26
|
+
* 一致:生产者在自有模块声明自有 kind)。声明后 UserMessage.source 原生接受
|
|
27
|
+
* 插件写入的 source 形态,宿主持久化读路径的 producer-owned 准入随之满足。
|
|
28
|
+
*/
|
|
29
|
+
'plugin:dsh-plugin-om': OmMessageSource;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
19
32
|
declare module '@deepseek-ai/dsh-session/types' {
|
|
20
33
|
interface SessionEventMap {
|
|
21
34
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,OAAO,EACP,UAAU,EACV,WAAW,EACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACnG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,4BAA4B;AAC5B,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,gBAAgB;QACxB;;;;WAIG;QACH,sBAAsB,EAAE,eAAe,CAAC;KACzC;CACF;AAED,OAAO,QAAQ,gCAAgC,CAAC;IAC9C,UAAU,eAAe;QACvB;;;;;;WAMG;QACH,iBAAiB,EA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