@downcity/plugins 1.0.60 → 1.0.64
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/bin/BuiltinPlugins.d.ts +15 -0
- package/bin/BuiltinPlugins.d.ts.map +1 -1
- package/bin/BuiltinPlugins.js +7 -1
- package/bin/BuiltinPlugins.js.map +1 -1
- package/bin/index.d.ts +6 -0
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +3 -0
- package/bin/index.js.map +1 -1
- package/bin/memory/Action.d.ts +15 -10
- package/bin/memory/Action.d.ts.map +1 -1
- package/bin/memory/Action.js +233 -16
- package/bin/memory/Action.js.map +1 -1
- package/bin/memory/MemoryPlugin.d.ts +10 -4
- package/bin/memory/MemoryPlugin.d.ts.map +1 -1
- package/bin/memory/MemoryPlugin.js +79 -37
- package/bin/memory/MemoryPlugin.js.map +1 -1
- package/bin/memory/runtime/Search.d.ts +1 -1
- package/bin/memory/runtime/Search.d.ts.map +1 -1
- package/bin/memory/runtime/Search.js +11 -7
- package/bin/memory/runtime/Search.js.map +1 -1
- package/bin/memory/runtime/Store.d.ts +8 -23
- package/bin/memory/runtime/Store.d.ts.map +1 -1
- package/bin/memory/runtime/Store.js +28 -43
- package/bin/memory/runtime/Store.js.map +1 -1
- package/bin/memory/runtime/SystemProvider.d.ts +4 -8
- package/bin/memory/runtime/SystemProvider.d.ts.map +1 -1
- package/bin/memory/runtime/SystemProvider.js +55 -62
- package/bin/memory/runtime/SystemProvider.js.map +1 -1
- package/bin/memory/runtime/Writer.d.ts +48 -10
- package/bin/memory/runtime/Writer.d.ts.map +1 -1
- package/bin/memory/runtime/Writer.js +197 -60
- package/bin/memory/runtime/Writer.js.map +1 -1
- package/bin/memory/types/Memory.d.ts +222 -33
- package/bin/memory/types/Memory.d.ts.map +1 -1
- package/bin/memory/types/Memory.js +4 -3
- package/bin/memory/types/Memory.js.map +1 -1
- package/bin/shell/ShellPlugin.d.ts +2 -1
- package/bin/shell/ShellPlugin.d.ts.map +1 -1
- package/bin/shell/ShellPlugin.js +41 -4
- package/bin/shell/ShellPlugin.js.map +1 -1
- package/bin/shell/ShellRuntimeTypes.d.ts +57 -3
- package/bin/shell/ShellRuntimeTypes.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntime.d.ts +21 -0
- package/bin/shell/runtime/ShellActionRuntime.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntime.js +142 -6
- package/bin/shell/runtime/ShellActionRuntime.js.map +1 -1
- package/bin/shell/runtime/ShellActionRuntimeSupport.d.ts +14 -5
- package/bin/shell/runtime/ShellActionRuntimeSupport.d.ts.map +1 -1
- package/bin/shell/runtime/ShellActionRuntimeSupport.js +61 -22
- package/bin/shell/runtime/ShellActionRuntimeSupport.js.map +1 -1
- package/bin/shell/runtime/ShellApprovalRuntime.d.ts +57 -0
- package/bin/shell/runtime/ShellApprovalRuntime.d.ts.map +1 -0
- package/bin/shell/runtime/ShellApprovalRuntime.js +182 -0
- package/bin/shell/runtime/ShellApprovalRuntime.js.map +1 -0
- package/bin/shell/runtime/ShellProcessEvents.js +3 -3
- package/bin/shell/runtime/ShellProcessEvents.js.map +1 -1
- package/bin/shell/types/ShellPluginOptions.d.ts +103 -0
- package/bin/shell/types/ShellPluginOptions.d.ts.map +1 -0
- package/bin/shell/types/ShellPluginOptions.js +10 -0
- package/bin/shell/types/ShellPluginOptions.js.map +1 -0
- package/bin/task/Scheduler.d.ts +8 -0
- package/bin/task/Scheduler.d.ts.map +1 -1
- package/bin/task/Scheduler.js +7 -9
- package/bin/task/Scheduler.js.map +1 -1
- package/bin/task/TaskPlugin.d.ts +18 -1
- package/bin/task/TaskPlugin.d.ts.map +1 -1
- package/bin/task/TaskPlugin.js +23 -1
- package/bin/task/TaskPlugin.js.map +1 -1
- package/bin/task/types/TaskPluginOptions.d.ts +22 -0
- package/bin/task/types/TaskPluginOptions.d.ts.map +1 -0
- package/bin/task/types/TaskPluginOptions.js +9 -0
- package/bin/task/types/TaskPluginOptions.js.map +1 -0
- package/package.json +2 -2
- package/scripts/unrestricted-sandbox-approval.test.mjs +156 -0
- package/src/BuiltinPlugins.ts +27 -1
- package/src/index.ts +35 -0
- package/src/memory/Action.ts +292 -25
- package/src/memory/MemoryPlugin.ts +82 -40
- package/src/memory/runtime/Search.ts +16 -9
- package/src/memory/runtime/Store.ts +52 -49
- package/src/memory/runtime/SystemProvider.ts +55 -69
- package/src/memory/runtime/Writer.ts +262 -81
- package/src/memory/types/Memory.ts +296 -35
- package/src/shell/ShellPlugin.ts +44 -3
- package/src/shell/ShellRuntimeTypes.ts +61 -3
- package/src/shell/runtime/ShellActionRuntime.ts +182 -9
- package/src/shell/runtime/ShellActionRuntimeSupport.ts +112 -21
- package/src/shell/runtime/ShellApprovalRuntime.ts +236 -0
- package/src/shell/runtime/ShellProcessEvents.ts +3 -3
- package/src/shell/types/ShellPluginOptions.ts +122 -0
- package/src/task/Scheduler.ts +15 -9
- package/src/task/TaskPlugin.ts +27 -1
- package/src/task/types/TaskPluginOptions.ts +22 -0
- package/bin/memory/runtime/Flush.d.ts +0 -15
- package/bin/memory/runtime/Flush.d.ts.map +0 -1
- package/bin/memory/runtime/Flush.js +0 -63
- package/bin/memory/runtime/Flush.js.map +0 -1
- package/src/memory/runtime/Flush.ts +0 -83
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Flush(手动刷写)。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 首版使用确定性规则,不依赖额外模型调用。
|
|
6
|
-
* - 仅提取最近消息的可读文本并落盘到 daily 记忆。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { UIDataTypes, UIMessagePart, UITools } from "ai";
|
|
10
|
-
import { isTextUIPart } from "ai";
|
|
11
|
-
import type { AgentContext } from "@downcity/agent/internal/types/runtime/agent/AgentContext.js";
|
|
12
|
-
import type {
|
|
13
|
-
MemoryFlushPayload,
|
|
14
|
-
MemoryFlushResponse,
|
|
15
|
-
} from "@/memory/types/Memory.js";
|
|
16
|
-
import type { MemoryRuntimeState } from "./Store.js";
|
|
17
|
-
import { storeMemory } from "./Writer.js";
|
|
18
|
-
|
|
19
|
-
type AnyUiMessagePart = UIMessagePart<UIDataTypes, UITools>;
|
|
20
|
-
|
|
21
|
-
function toUiParts(message: { parts?: AnyUiMessagePart[] } | null | undefined): AnyUiMessagePart[] {
|
|
22
|
-
return Array.isArray(message?.parts) ? message.parts : [];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function extractReadableLine(message: {
|
|
26
|
-
role?: string;
|
|
27
|
-
parts?: AnyUiMessagePart[];
|
|
28
|
-
}): string {
|
|
29
|
-
const role = String(message.role || "").toLowerCase() === "user" ? "User" : "Assistant";
|
|
30
|
-
const text = toUiParts(message)
|
|
31
|
-
.filter(isTextUIPart)
|
|
32
|
-
.map((part) => String(part.text || "").trim())
|
|
33
|
-
.filter(Boolean)
|
|
34
|
-
.join("\n")
|
|
35
|
-
.trim();
|
|
36
|
-
if (!text) {
|
|
37
|
-
return "";
|
|
38
|
-
}
|
|
39
|
-
return `${role}: ${text}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 把当前会话最近消息刷写到 daily 记忆。
|
|
44
|
-
*/
|
|
45
|
-
export async function flushMemory(
|
|
46
|
-
context: AgentContext,
|
|
47
|
-
state: MemoryRuntimeState,
|
|
48
|
-
payload: MemoryFlushPayload,
|
|
49
|
-
): Promise<MemoryFlushResponse> {
|
|
50
|
-
const sessionId = String(payload.sessionId || "").trim();
|
|
51
|
-
if (!sessionId) {
|
|
52
|
-
throw new Error("sessionId is required");
|
|
53
|
-
}
|
|
54
|
-
const maxMessages = Number.isFinite(payload.maxMessages)
|
|
55
|
-
? Math.max(1, Math.floor(payload.maxMessages as number))
|
|
56
|
-
: 30;
|
|
57
|
-
const historyStore = context.session.get(sessionId).getHistoryStore();
|
|
58
|
-
const total = await historyStore.size();
|
|
59
|
-
const start = Math.max(0, total - maxMessages);
|
|
60
|
-
const messages = await historyStore.slice(start, total);
|
|
61
|
-
const lines = messages
|
|
62
|
-
.map((msg) => extractReadableLine(msg))
|
|
63
|
-
.filter((line) => line.length > 0);
|
|
64
|
-
const summary =
|
|
65
|
-
lines.length > 0
|
|
66
|
-
? lines.join("\n\n")
|
|
67
|
-
: "本次 flush 未找到可写入的用户/助手文本内容。";
|
|
68
|
-
const content = [
|
|
69
|
-
`Flush Session: ${sessionId}`,
|
|
70
|
-
`Window: ${start}-${Math.max(start, total - 1)}`,
|
|
71
|
-
"",
|
|
72
|
-
summary,
|
|
73
|
-
].join("\n");
|
|
74
|
-
const saved = await storeMemory(context, state, {
|
|
75
|
-
content,
|
|
76
|
-
target: "daily",
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
path: saved.path,
|
|
80
|
-
messageCount: lines.length,
|
|
81
|
-
writtenChars: saved.writtenChars,
|
|
82
|
-
};
|
|
83
|
-
}
|