@downcity/agent 1.1.79 → 1.1.81

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.
Files changed (173) hide show
  1. package/README.md +1 -1
  2. package/bin/agent/local/Agent.d.ts +8 -121
  3. package/bin/agent/local/Agent.d.ts.map +1 -1
  4. package/bin/agent/local/Agent.js +63 -381
  5. package/bin/agent/local/Agent.js.map +1 -1
  6. package/bin/agent/local/AgentRuntimeFactory.d.ts +2 -2
  7. package/bin/agent/local/AgentRuntimeFactory.d.ts.map +1 -1
  8. package/bin/agent/local/AgentRuntimeFactory.js +2 -23
  9. package/bin/agent/local/AgentRuntimeFactory.js.map +1 -1
  10. package/bin/agent/local/services/AgentAssemblyService.d.ts +112 -0
  11. package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -0
  12. package/bin/agent/local/services/AgentAssemblyService.js +135 -0
  13. package/bin/agent/local/services/AgentAssemblyService.js.map +1 -0
  14. package/bin/agent/local/services/AgentLifecycleService.d.ts +59 -0
  15. package/bin/agent/local/services/AgentLifecycleService.d.ts.map +1 -0
  16. package/bin/agent/local/services/AgentLifecycleService.js +136 -0
  17. package/bin/agent/local/services/AgentLifecycleService.js.map +1 -0
  18. package/bin/agent/local/services/AgentSessionManager.d.ts +106 -0
  19. package/bin/agent/local/services/AgentSessionManager.d.ts.map +1 -0
  20. package/bin/agent/local/services/AgentSessionManager.js +182 -0
  21. package/bin/agent/local/services/AgentSessionManager.js.map +1 -0
  22. package/bin/executor/Executor.d.ts +7 -24
  23. package/bin/executor/Executor.d.ts.map +1 -1
  24. package/bin/executor/Executor.js +73 -361
  25. package/bin/executor/Executor.js.map +1 -1
  26. package/bin/executor/SessionRunScope.d.ts +18 -34
  27. package/bin/executor/SessionRunScope.d.ts.map +1 -1
  28. package/bin/executor/SessionRunScope.js +42 -28
  29. package/bin/executor/SessionRunScope.js.map +1 -1
  30. package/bin/executor/composer/context/LocalSessionContextComposer.d.ts +5 -3
  31. package/bin/executor/composer/context/LocalSessionContextComposer.d.ts.map +1 -1
  32. package/bin/executor/composer/context/LocalSessionContextComposer.js +11 -18
  33. package/bin/executor/composer/context/LocalSessionContextComposer.js.map +1 -1
  34. package/bin/executor/composer/context/SessionContextComposer.d.ts +8 -3
  35. package/bin/executor/composer/context/SessionContextComposer.d.ts.map +1 -1
  36. package/bin/executor/composer/system/SessionSystemComposer.d.ts +2 -1
  37. package/bin/executor/composer/system/SessionSystemComposer.d.ts.map +1 -1
  38. package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts +2 -1
  39. package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts.map +1 -1
  40. package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js +2 -4
  41. package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js.map +1 -1
  42. package/bin/executor/core-engine/CoreEngineRunner.d.ts +62 -0
  43. package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -0
  44. package/bin/executor/core-engine/CoreEngineRunner.js +309 -0
  45. package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -0
  46. package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts +5 -0
  47. package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts.map +1 -1
  48. package/bin/executor/core-engine/CoreEngineUiStreamCollector.js +2 -4
  49. package/bin/executor/core-engine/CoreEngineUiStreamCollector.js.map +1 -1
  50. package/bin/executor/services/ExecutorInflightService.d.ts +39 -0
  51. package/bin/executor/services/ExecutorInflightService.d.ts.map +1 -0
  52. package/bin/executor/services/ExecutorInflightService.js +75 -0
  53. package/bin/executor/services/ExecutorInflightService.js.map +1 -0
  54. package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +103 -0
  55. package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +1 -0
  56. package/bin/executor/services/ExecutorRecoveryPolicy.js +87 -0
  57. package/bin/executor/services/ExecutorRecoveryPolicy.js.map +1 -0
  58. package/bin/executor/tools/plugin/PluginToolBridge.d.ts +19 -0
  59. package/bin/executor/tools/plugin/PluginToolBridge.d.ts.map +1 -0
  60. package/bin/executor/tools/plugin/PluginToolBridge.js +143 -0
  61. package/bin/executor/tools/plugin/PluginToolBridge.js.map +1 -0
  62. package/bin/executor/tools/plugin/PluginToolDefinition.d.ts +32 -0
  63. package/bin/executor/tools/plugin/PluginToolDefinition.d.ts.map +1 -0
  64. package/bin/executor/tools/plugin/PluginToolDefinition.js +27 -0
  65. package/bin/executor/tools/plugin/PluginToolDefinition.js.map +1 -0
  66. package/bin/executor/tools/plugin/PluginToolSchemas.d.ts +14 -0
  67. package/bin/executor/tools/plugin/PluginToolSchemas.d.ts.map +1 -0
  68. package/bin/executor/tools/plugin/PluginToolSchemas.js +19 -0
  69. package/bin/executor/tools/plugin/PluginToolSchemas.js.map +1 -0
  70. package/bin/executor/tools/plugin/types/PluginTool.d.ts +39 -0
  71. package/bin/executor/tools/plugin/types/PluginTool.d.ts.map +1 -0
  72. package/bin/executor/tools/plugin/types/PluginTool.js +9 -0
  73. package/bin/executor/tools/plugin/types/PluginTool.js.map +1 -0
  74. package/bin/executor/tools/shell/ShellToolBridge.js +3 -3
  75. package/bin/executor/tools/shell/ShellToolBridge.js.map +1 -1
  76. package/bin/executor/types/SessionRun.d.ts +18 -0
  77. package/bin/executor/types/SessionRun.d.ts.map +1 -1
  78. package/bin/index.d.ts +10 -1
  79. package/bin/index.d.ts.map +1 -1
  80. package/bin/index.js +3 -0
  81. package/bin/index.js.map +1 -1
  82. package/bin/plugin/core/BasePlugin.d.ts +2 -2
  83. package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
  84. package/bin/plugin/core/BasePlugin.js.map +1 -1
  85. package/bin/plugin/core/ImagePlugin.d.ts +56 -0
  86. package/bin/plugin/core/ImagePlugin.d.ts.map +1 -0
  87. package/bin/plugin/core/ImagePlugin.js +109 -0
  88. package/bin/plugin/core/ImagePlugin.js.map +1 -0
  89. package/bin/session/Session.d.ts +14 -83
  90. package/bin/session/Session.d.ts.map +1 -1
  91. package/bin/session/Session.js +139 -362
  92. package/bin/session/Session.js.map +1 -1
  93. package/bin/session/SessionSystemBuilder.d.ts +2 -1
  94. package/bin/session/SessionSystemBuilder.d.ts.map +1 -1
  95. package/bin/session/SessionSystemBuilder.js +2 -3
  96. package/bin/session/SessionSystemBuilder.js.map +1 -1
  97. package/bin/session/services/SessionStateService.d.ts +132 -0
  98. package/bin/session/services/SessionStateService.d.ts.map +1 -0
  99. package/bin/session/services/SessionStateService.js +242 -0
  100. package/bin/session/services/SessionStateService.js.map +1 -0
  101. package/bin/session/services/SessionTurnService.d.ts +66 -0
  102. package/bin/session/services/SessionTurnService.d.ts.map +1 -0
  103. package/bin/session/services/SessionTurnService.js +137 -0
  104. package/bin/session/services/SessionTurnService.js.map +1 -0
  105. package/bin/session/services/SessionViewService.d.ts +105 -0
  106. package/bin/session/services/SessionViewService.d.ts.map +1 -0
  107. package/bin/session/services/SessionViewService.js +184 -0
  108. package/bin/session/services/SessionViewService.js.map +1 -0
  109. package/bin/types/agent/AgentOptions.d.ts +18 -0
  110. package/bin/types/agent/AgentOptions.d.ts.map +1 -1
  111. package/bin/types/agent/AgentTypes.d.ts +3 -1
  112. package/bin/types/agent/AgentTypes.d.ts.map +1 -1
  113. package/bin/types/agent/SessionTypes.d.ts.map +1 -1
  114. package/bin/types/executor/SessionRunContext.d.ts +66 -0
  115. package/bin/types/executor/SessionRunContext.d.ts.map +1 -0
  116. package/bin/types/executor/SessionRunContext.js +10 -0
  117. package/bin/types/executor/SessionRunContext.js.map +1 -0
  118. package/bin/types/plugin/ImagePlugin.d.ts +94 -0
  119. package/bin/types/plugin/ImagePlugin.d.ts.map +1 -0
  120. package/bin/types/plugin/ImagePlugin.js +10 -0
  121. package/bin/types/plugin/ImagePlugin.js.map +1 -0
  122. package/bin/types/session/SessionComposerOptions.d.ts +90 -0
  123. package/bin/types/session/SessionComposerOptions.d.ts.map +1 -0
  124. package/bin/types/session/SessionComposerOptions.js +10 -0
  125. package/bin/types/session/SessionComposerOptions.js.map +1 -0
  126. package/bin/types/session/SessionLocalState.d.ts +35 -0
  127. package/bin/types/session/SessionLocalState.d.ts.map +1 -0
  128. package/bin/types/session/SessionLocalState.js +10 -0
  129. package/bin/types/session/SessionLocalState.js.map +1 -0
  130. package/bin/types/session/SessionOptions.d.ts +85 -0
  131. package/bin/types/session/SessionOptions.d.ts.map +1 -0
  132. package/bin/types/session/SessionOptions.js +10 -0
  133. package/bin/types/session/SessionOptions.js.map +1 -0
  134. package/package.json +1 -1
  135. package/src/agent/local/Agent.ts +74 -433
  136. package/src/agent/local/AgentRuntimeFactory.ts +4 -25
  137. package/src/agent/local/services/AgentAssemblyService.ts +268 -0
  138. package/src/agent/local/services/AgentLifecycleService.ts +187 -0
  139. package/src/agent/local/services/AgentSessionManager.ts +291 -0
  140. package/src/executor/Executor.ts +103 -441
  141. package/src/executor/README.md +4 -4
  142. package/src/executor/SessionRunScope.ts +47 -71
  143. package/src/executor/composer/context/LocalSessionContextComposer.ts +24 -20
  144. package/src/executor/composer/context/SessionContextComposer.ts +13 -3
  145. package/src/executor/composer/system/SessionSystemComposer.ts +2 -1
  146. package/src/executor/composer/system/default/DefaultSessionSystemComposer.ts +3 -4
  147. package/src/executor/core-engine/CoreEngineRunner.ts +433 -0
  148. package/src/executor/core-engine/CoreEngineUiStreamCollector.ts +7 -5
  149. package/src/executor/services/ExecutorInflightService.ts +101 -0
  150. package/src/executor/services/ExecutorRecoveryPolicy.ts +213 -0
  151. package/src/executor/tools/plugin/PluginToolBridge.ts +161 -0
  152. package/src/executor/tools/plugin/PluginToolDefinition.ts +32 -0
  153. package/src/executor/tools/plugin/PluginToolSchemas.ts +20 -0
  154. package/src/executor/tools/plugin/types/PluginTool.ts +41 -0
  155. package/src/executor/tools/shell/ShellToolBridge.ts +3 -3
  156. package/src/executor/types/SessionRun.ts +20 -0
  157. package/src/index.ts +33 -0
  158. package/src/plugin/core/BasePlugin.ts +2 -2
  159. package/src/plugin/core/ImagePlugin.ts +128 -0
  160. package/src/session/Session.ts +178 -485
  161. package/src/session/SessionSystemBuilder.ts +3 -3
  162. package/src/session/services/SessionStateService.ts +341 -0
  163. package/src/session/services/SessionTurnService.ts +202 -0
  164. package/src/session/services/SessionViewService.ts +301 -0
  165. package/src/types/agent/AgentOptions.ts +25 -0
  166. package/src/types/agent/AgentTypes.ts +10 -0
  167. package/src/types/agent/SessionTypes.ts +1 -0
  168. package/src/types/executor/SessionRunContext.ts +76 -0
  169. package/src/types/plugin/ImagePlugin.ts +103 -0
  170. package/src/types/session/SessionComposerOptions.ts +107 -0
  171. package/src/types/session/SessionLocalState.ts +40 -0
  172. package/src/types/session/SessionOptions.ts +99 -0
  173. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,94 @@
1
+ /**
2
+ * ImagePlugin 类型定义。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里仅定义 agent 对图片能力的最低层协议,不绑定 city 或任意上游 provider。
6
+ * - 图片生成结果使用 AI SDK UIMessage,保证 session 落盘格式与现有消息系统一致。
7
+ * - 字段保持 JSON 可序列化,便于通过 plugin action 与 tool bridge 传递。
8
+ */
9
+ import type { UIMessage } from "ai";
10
+ import type { JsonObject, JsonValue } from "../../types/common/Json.js";
11
+ /**
12
+ * 图片生成文本内容片段。
13
+ */
14
+ export interface ImagePluginTextContent {
15
+ /** 内容类型,固定为文本。 */
16
+ type: "text";
17
+ /** 生图提示词或上下文文本。 */
18
+ text: string;
19
+ }
20
+ /**
21
+ * 图片生成参考图片内容片段。
22
+ */
23
+ export interface ImagePluginFileContent {
24
+ /** 内容类型,固定为图片。 */
25
+ type: "image";
26
+ /** 远程图片 URL。 */
27
+ url?: string;
28
+ /** data URL 图片内容。 */
29
+ data_url?: string;
30
+ /** 图片 MIME 类型,例如 `image/png`。 */
31
+ media_type?: string;
32
+ }
33
+ /**
34
+ * 图片生成多模态内容片段。
35
+ */
36
+ export type ImagePluginContent = ImagePluginTextContent | ImagePluginFileContent;
37
+ /**
38
+ * 图片生成上下文消息。
39
+ */
40
+ export interface ImagePluginMessage {
41
+ /** 消息角色。 */
42
+ role: "system" | "user" | "assistant";
43
+ /** 该消息内的文本与图片内容。 */
44
+ content: ImagePluginContent[];
45
+ }
46
+ /**
47
+ * ImagePlugin 调用输入。
48
+ */
49
+ export interface ImagePluginInput {
50
+ /** 图片模型引用。 */
51
+ model?: string;
52
+ /** 单句快捷提示词。 */
53
+ prompt?: string;
54
+ /** 多轮或多模态图片生成上下文。 */
55
+ messages?: ImagePluginMessage[];
56
+ /** 生成图片数量。 */
57
+ n?: number;
58
+ /** 生成图片数量,兼容部分上游使用的 count 命名。 */
59
+ count?: number;
60
+ /** 图片尺寸,例如 `1024x1024`。 */
61
+ size?: string;
62
+ /** 图片宽高比,例如 `1:1`。 */
63
+ aspect_ratio?: string;
64
+ /** 图片宽高比,兼容部分上游使用的 ratio 命名。 */
65
+ ratio?: string;
66
+ /** 图片质量,例如 `standard`、`hd`、`ultra`、`4k`。 */
67
+ quality?: string;
68
+ /** 随机种子。 */
69
+ seed?: number;
70
+ /** 业务侧任务 ID,用于异步图片任务幂等、追踪和恢复。 */
71
+ client_job_id?: string;
72
+ /** Provider 私有参数,例如 `{ openai: {...}, gemini: {...}, luchi: {...} }`。 */
73
+ provider_options?: JsonObject;
74
+ /** 允许外部 image 函数接收其他 JSON 可序列化参数。 */
75
+ [key: string]: JsonValue | ImagePluginMessage[] | undefined;
76
+ }
77
+ /**
78
+ * ImagePlugin 生成结果。
79
+ */
80
+ export type ImagePluginResult = UIMessage;
81
+ /**
82
+ * ImagePlugin 构造参数。
83
+ */
84
+ export interface ImagePluginOptions {
85
+ /** Plugin 稳定名称,默认 `image`。 */
86
+ name?: string;
87
+ /** Plugin 展示标题,默认 `Image`。 */
88
+ title?: string;
89
+ /** Plugin 用途说明。 */
90
+ description?: string;
91
+ /** 图片生成函数,通常传入 `(input) => city.ai.image(input)`。 */
92
+ image: (input: ImagePluginInput) => Promise<ImagePluginResult> | ImagePluginResult;
93
+ }
94
+ //# sourceMappingURL=ImagePlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImagePlugin.d.ts","sourceRoot":"","sources":["../../../src/types/plugin/ImagePlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,kBAAkB;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,sBAAsB,GACtB,sBAAsB,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,YAAY;IACZ,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACtC,oBAAoB;IACpB,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,cAAc;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAChC,cAAc;IACd,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAC9B,qCAAqC;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,kBAAkB,EAAE,GAAG,SAAS,CAAC;CAC7D;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,KAAK,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAAC;CACpF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * ImagePlugin 类型定义。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里仅定义 agent 对图片能力的最低层协议,不绑定 city 或任意上游 provider。
6
+ * - 图片生成结果使用 AI SDK UIMessage,保证 session 落盘格式与现有消息系统一致。
7
+ * - 字段保持 JSON 可序列化,便于通过 plugin action 与 tool bridge 传递。
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=ImagePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImagePlugin.js","sourceRoot":"","sources":["../../../src/types/plugin/ImagePlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Session Composer 配置类型。
3
+ *
4
+ * 关键点(中文)
5
+ * - Composer 是 session 执行阶段的可替换策略对象。
6
+ * - 调用方可以传入现成实例,也可以传入 factory 为每个 session 创建独立实例。
7
+ * - factory 适合 history/system 等可能绑定 sessionId、historyStore 或 session 元信息的 composer。
8
+ */
9
+ import type { Tool } from "ai";
10
+ import type { SessionCompactionComposer } from "../../executor/composer/compaction/SessionCompactionComposer.js";
11
+ import type { SessionContextComposer } from "../../executor/composer/context/SessionContextComposer.js";
12
+ import type { SessionHistoryComposer } from "../../executor/composer/history/SessionHistoryComposer.js";
13
+ import type { SessionSystemComposer } from "../../executor/composer/system/SessionSystemComposer.js";
14
+ import type { SessionHistoryStore } from "../../executor/store/history/SessionHistoryStore.js";
15
+ import type { AgentSessionSystemBlock } from "../../types/agent/SessionTypes.js";
16
+ /**
17
+ * 单个 session 创建 Composer 时可读取的稳定上下文。
18
+ */
19
+ export interface SessionComposerFactoryContext {
20
+ /**
21
+ * 当前 agent 的稳定标识。
22
+ */
23
+ agentId: string;
24
+ /**
25
+ * 当前 agent 绑定的项目根目录。
26
+ */
27
+ projectRoot: string;
28
+ /**
29
+ * 当前 session 唯一标识。
30
+ */
31
+ sessionId: string;
32
+ /**
33
+ * 当前 session 对应的 history 事实源。
34
+ *
35
+ * 关键点(中文)
36
+ * - history composer 和 compaction composer 通常需要基于它读取或压缩历史。
37
+ * - factory 每次收到的都是当前 session 自己的 store。
38
+ */
39
+ historyStore: SessionHistoryStore;
40
+ /**
41
+ * 当前 agent 默认工具集合读取器。
42
+ */
43
+ getTools: () => Record<string, Tool>;
44
+ /**
45
+ * 读取当前 SDK 调用方传入的 instruction system blocks。
46
+ */
47
+ getInstructionSystemBlocks: () => AgentSessionSystemBlock[];
48
+ /**
49
+ * 读取当前 agent 显式注入的受托管 plugin system blocks。
50
+ */
51
+ getManagedPluginSystemBlocks: () => Promise<AgentSessionSystemBlock[]>;
52
+ /**
53
+ * 读取当前 agent 显式注册 plugin 的 system blocks。
54
+ */
55
+ getPluginSystemBlocks: () => Promise<AgentSessionSystemBlock[]>;
56
+ /**
57
+ * 读取当前 session 首次创建时间(ms)。
58
+ */
59
+ getSessionCreatedAt: () => number;
60
+ /**
61
+ * 读取当前 session 初始化时解析到的系统时区。
62
+ */
63
+ getSessionTimezone: () => string;
64
+ }
65
+ /**
66
+ * 可直接传入 composer 实例,也可传入按 session 创建 composer 的 factory。
67
+ */
68
+ export type SessionComposerInput<TComposer> = TComposer | ((context: SessionComposerFactoryContext) => TComposer);
69
+ /**
70
+ * Session Composer 覆盖项。
71
+ */
72
+ export interface SessionComposerOptions {
73
+ /**
74
+ * 覆盖本轮 system messages 的 composer。
75
+ */
76
+ systemComposer?: SessionComposerInput<SessionSystemComposer>;
77
+ /**
78
+ * 覆盖本轮 history messages 的 composer。
79
+ */
80
+ historyComposer?: SessionComposerInput<SessionHistoryComposer>;
81
+ /**
82
+ * 覆盖本轮 tools、step hooks、fallback assistant message 等运行上下文 composer。
83
+ */
84
+ contextComposer?: SessionComposerInput<SessionContextComposer>;
85
+ /**
86
+ * 覆盖本轮上下文压缩 composer。
87
+ */
88
+ compactionComposer?: SessionComposerInput<SessionCompactionComposer>;
89
+ }
90
+ //# sourceMappingURL=SessionComposerOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionComposerOptions.d.ts","sourceRoot":"","sources":["../../../src/types/session/SessionComposerOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6DAA6D,CAAC;AAC7G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uDAAuD,CAAC;AACpG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uDAAuD,CAAC;AACpG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qDAAqD,CAAC;AACjG,OAAO,KAAK,EAAE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*
4
+ * 关键点(中文)
5
+ * - Composer 是 session 执行阶段的可替换策略对象。
6
+ * - 调用方可以传入现成实例,也可以传入 factory 为每个 session 创建独立实例。
7
+ * - factory 适合 history/system 等可能绑定 sessionId、historyStore 或 session 元信息的 composer。
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=SessionComposerOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionComposerOptions.js","sourceRoot":"","sources":["../../../src/types/session/SessionComposerOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * SessionLocalState:本地 Session 运行态快照。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里承载本地 Session 在内存中的可变运行态。
6
+ * - state / turn / view 三类 service 通过共享该对象协作,避免彼此复制状态。
7
+ * - 这里只保存运行态,不承载行为逻辑。
8
+ */
9
+ import type { AgentSessionConfigSnapshot } from "../../types/agent/AgentTypes.js";
10
+ /**
11
+ * 本地 Session 内存状态。
12
+ */
13
+ export interface SessionLocalState {
14
+ /**
15
+ * 当前 session 配置快照。
16
+ */
17
+ sessionConfig: AgentSessionConfigSnapshot;
18
+ /**
19
+ * 当前 session 创建时间(毫秒时间戳)。
20
+ */
21
+ createdAt: number;
22
+ /**
23
+ * 当前 session 参考时区。
24
+ */
25
+ timezone: string;
26
+ /**
27
+ * initialize() 过程中的并发复用 Promise。
28
+ */
29
+ initializePromise: Promise<void> | null;
30
+ /**
31
+ * ensureReadyForExecution() 过程中的并发复用 Promise。
32
+ */
33
+ ensureConfiguredPromise: Promise<void> | null;
34
+ }
35
+ //# sourceMappingURL=SessionLocalState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionLocalState.d.ts","sourceRoot":"","sources":["../../../src/types/session/SessionLocalState.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,aAAa,EAAE,0BAA0B,CAAC;IAE1C;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,iBAAiB,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAExC;;OAEG;IACH,uBAAuB,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC/C"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * SessionLocalState:本地 Session 运行态快照。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里承载本地 Session 在内存中的可变运行态。
6
+ * - state / turn / view 三类 service 通过共享该对象协作,避免彼此复制状态。
7
+ * - 这里只保存运行态,不承载行为逻辑。
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=SessionLocalState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionLocalState.js","sourceRoot":"","sources":["../../../src/types/session/SessionLocalState.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Session 构造参数类型。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里描述 Agent 创建本地 Session 时传入的稳定上下文。
6
+ * - 默认 Session 和自定义 Session 类都应使用这组参数。
7
+ * - Composer 仍然是 Session 级能力,不向 Agent 的执行策略层泄漏。
8
+ */
9
+ import type { Tool } from "ai";
10
+ import type { AgentSession } from "../../types/agent/SessionActor.js";
11
+ import type { SessionPort } from "../../types/runtime/agent/AgentContext.js";
12
+ import type { AgentSessionSystemBlock } from "../../types/agent/SessionTypes.js";
13
+ import type { SessionComposerOptions } from "../../types/session/SessionComposerOptions.js";
14
+ /**
15
+ * Agent 可管理的本地 Session 实例。
16
+ */
17
+ export interface AgentManagedSession extends AgentSession {
18
+ /**
19
+ * 初始化当前 session。
20
+ */
21
+ initialize(): Promise<this>;
22
+ /**
23
+ * 返回供 plugin/runtime 使用的 session 端口。
24
+ */
25
+ getRuntimePort(): SessionPort;
26
+ /**
27
+ * 返回当前 session 是否正在执行。
28
+ */
29
+ isExecuting(): boolean;
30
+ }
31
+ /**
32
+ * 本地 Session 构造参数。
33
+ */
34
+ export interface SessionOptions {
35
+ /**
36
+ * 当前 agent 稳定标识。
37
+ */
38
+ agentId: string;
39
+ /**
40
+ * 当前项目根目录。
41
+ */
42
+ projectRoot: string;
43
+ /**
44
+ * 当前 sessionId。
45
+ */
46
+ sessionId: string;
47
+ /**
48
+ * 当前 agent 默认工具集合。
49
+ */
50
+ tools: Record<string, Tool>;
51
+ /**
52
+ * 统一日志器。
53
+ */
54
+ logger: {
55
+ /**
56
+ * 记录普通信息。
57
+ */
58
+ info(message: string, details?: Record<string, unknown>): void;
59
+ /**
60
+ * 记录警告信息。
61
+ */
62
+ warn(message: string, details?: Record<string, unknown>): void;
63
+ };
64
+ /**
65
+ * 读取当前 SDK 调用方传入的 instruction system blocks。
66
+ */
67
+ getInstructionSystemBlocks: () => AgentSessionSystemBlock[];
68
+ /**
69
+ * 读取当前 agent 显式注入的受托管 plugin system blocks。
70
+ */
71
+ getManagedPluginSystemBlocks: () => Promise<AgentSessionSystemBlock[]>;
72
+ /**
73
+ * 读取当前 agent 显式注册 plugin 的 system blocks。
74
+ */
75
+ getPluginSystemBlocks: () => Promise<AgentSessionSystemBlock[]>;
76
+ /**
77
+ * 在执行前确保当前 session 已完成宿主侧默认配置。
78
+ */
79
+ ensureConfigured?: (session: AgentManagedSession) => Promise<void>;
80
+ /**
81
+ * 当前 session 的 Composer 覆盖项。
82
+ */
83
+ composers?: SessionComposerOptions;
84
+ }
85
+ //# sourceMappingURL=SessionOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionOptions.d.ts","sourceRoot":"","sources":["../../../src/types/session/SessionOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;A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AAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnE;;OAEG;IACH,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACpC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Session 构造参数类型。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里描述 Agent 创建本地 Session 时传入的稳定上下文。
6
+ * - 默认 Session 和自定义 Session 类都应使用这组参数。
7
+ * - Composer 仍然是 Session 级能力,不向 Agent 的执行策略层泄漏。
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=SessionOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionOptions.js","sourceRoot":"","sources":["../../../src/types/session/SessionOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@downcity/agent",
3
- "version": "1.1.79",
3
+ "version": "1.1.81",
4
4
  "type": "module",
5
5
  "description": "Downcity Agent 运行时 — 单 Agent 执行壳与本机 RPC 能力",
6
6
  "main": "./bin/index.js",