@downcity/type 0.1.202 → 0.1.213

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 (162) hide show
  1. package/README.md +1 -1
  2. package/bin/index.d.ts +7 -3
  3. package/bin/index.d.ts.map +1 -1
  4. package/bin/index.js +4 -1
  5. package/bin/index.js.map +1 -1
  6. package/bin/session.d.ts +12 -0
  7. package/bin/session.d.ts.map +1 -0
  8. package/bin/session.js +3 -0
  9. package/bin/session.js.map +1 -0
  10. package/bin/shell.d.ts +11 -0
  11. package/bin/shell.d.ts.map +1 -0
  12. package/bin/shell.js +3 -0
  13. package/bin/shell.js.map +1 -0
  14. package/bin/types/city/CityRuntime.d.ts +31 -0
  15. package/bin/types/city/CityRuntime.d.ts.map +1 -0
  16. package/bin/types/city/CityRuntime.js +8 -0
  17. package/bin/types/city/CityRuntime.js.map +1 -0
  18. package/bin/types/json/Json.d.ts +32 -0
  19. package/bin/types/json/Json.d.ts.map +1 -0
  20. package/bin/types/json/Json.js +9 -0
  21. package/bin/types/json/Json.js.map +1 -0
  22. package/bin/types/model/ModelClient.d.ts +4 -0
  23. package/bin/types/model/ModelClient.d.ts.map +1 -1
  24. package/bin/types/model/ModelMetadata.d.ts +11 -0
  25. package/bin/types/model/ModelMetadata.d.ts.map +1 -0
  26. package/bin/types/model/ModelMetadata.js +21 -0
  27. package/bin/types/model/ModelMetadata.js.map +1 -0
  28. package/bin/types/model/ModelRequest.d.ts +24 -0
  29. package/bin/types/model/ModelRequest.d.ts.map +1 -0
  30. package/bin/types/model/ModelRequest.js +3 -0
  31. package/bin/types/model/ModelRequest.js.map +1 -0
  32. package/bin/types/model/index.d.ts +2 -0
  33. package/bin/types/model/index.d.ts.map +1 -1
  34. package/bin/types/model/index.js +1 -0
  35. package/bin/types/model/index.js.map +1 -1
  36. package/bin/types/session/SessionAction.d.ts +39 -0
  37. package/bin/types/session/SessionAction.d.ts.map +1 -0
  38. package/bin/types/session/SessionAction.js +8 -0
  39. package/bin/types/session/SessionAction.js.map +1 -0
  40. package/bin/types/session/SessionCompact.d.ts +4 -0
  41. package/bin/types/session/SessionCompact.d.ts.map +1 -0
  42. package/bin/types/session/SessionCompact.js +3 -0
  43. package/bin/types/session/SessionCompact.js.map +1 -0
  44. package/bin/types/session/SessionContent.d.ts +52 -0
  45. package/bin/types/session/SessionContent.d.ts.map +1 -0
  46. package/bin/types/session/SessionContent.js +8 -0
  47. package/bin/types/session/SessionContent.js.map +1 -0
  48. package/bin/types/session/SessionExtension.d.ts +56 -0
  49. package/bin/types/session/SessionExtension.d.ts.map +1 -0
  50. package/bin/types/session/SessionExtension.js +22 -0
  51. package/bin/types/session/SessionExtension.js.map +1 -0
  52. package/bin/types/session/SessionHook.d.ts +120 -0
  53. package/bin/types/session/SessionHook.d.ts.map +1 -0
  54. package/bin/types/session/SessionHook.js +8 -0
  55. package/bin/types/session/SessionHook.js.map +1 -0
  56. package/bin/types/session/SessionInteraction.d.ts +231 -0
  57. package/bin/types/session/SessionInteraction.d.ts.map +1 -0
  58. package/bin/types/session/SessionInteraction.js +15 -0
  59. package/bin/types/session/SessionInteraction.js.map +1 -0
  60. package/bin/types/session/SessionMessage.d.ts +256 -0
  61. package/bin/types/session/SessionMessage.d.ts.map +1 -0
  62. package/bin/types/session/SessionMessage.js +8 -0
  63. package/bin/types/session/SessionMessage.js.map +1 -0
  64. package/bin/types/session/SessionMutation.d.ts +173 -0
  65. package/bin/types/session/SessionMutation.d.ts.map +1 -0
  66. package/bin/types/session/SessionMutation.js +25 -0
  67. package/bin/types/session/SessionMutation.js.map +1 -0
  68. package/bin/types/session/SessionOrigin.d.ts +29 -0
  69. package/bin/types/session/SessionOrigin.d.ts.map +1 -0
  70. package/bin/types/session/SessionOrigin.js +44 -0
  71. package/bin/types/session/SessionOrigin.js.map +1 -0
  72. package/bin/types/session/SessionSystem.d.ts +18 -0
  73. package/bin/types/session/SessionSystem.d.ts.map +1 -0
  74. package/bin/types/session/SessionSystem.js +8 -0
  75. package/bin/types/session/SessionSystem.js.map +1 -0
  76. package/bin/types/session/SessionTurnFileDiff.d.ts +40 -0
  77. package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -0
  78. package/bin/types/session/SessionTurnFileDiff.js +8 -0
  79. package/bin/types/session/SessionTurnFileDiff.js.map +1 -0
  80. package/bin/types/shell/Sandbox.d.ts +111 -0
  81. package/bin/types/shell/Sandbox.d.ts.map +1 -0
  82. package/bin/types/shell/Sandbox.js +10 -0
  83. package/bin/types/shell/Sandbox.js.map +1 -0
  84. package/bin/types/shell/Shell.d.ts +70 -0
  85. package/bin/types/shell/Shell.d.ts.map +1 -0
  86. package/bin/types/shell/Shell.js +9 -0
  87. package/bin/types/shell/Shell.js.map +1 -0
  88. package/bin/types/shell/ShellAction.d.ts +308 -0
  89. package/bin/types/shell/ShellAction.d.ts.map +1 -0
  90. package/bin/types/shell/ShellAction.js +9 -0
  91. package/bin/types/shell/ShellAction.js.map +1 -0
  92. package/bin/types/shell/ShellApproval.d.ts +50 -0
  93. package/bin/types/shell/ShellApproval.d.ts.map +1 -0
  94. package/bin/types/shell/ShellApproval.js +9 -0
  95. package/bin/types/shell/ShellApproval.js.map +1 -0
  96. package/bin/types/shell/ShellCommand.d.ts +15 -0
  97. package/bin/types/shell/ShellCommand.d.ts.map +1 -0
  98. package/bin/types/shell/ShellCommand.js +9 -0
  99. package/bin/types/shell/ShellCommand.js.map +1 -0
  100. package/bin/types/shell/ShellHostContext.d.ts +65 -0
  101. package/bin/types/shell/ShellHostContext.d.ts.map +1 -0
  102. package/bin/types/shell/ShellHostContext.js +9 -0
  103. package/bin/types/shell/ShellHostContext.js.map +1 -0
  104. package/bin/types/shell/ShellRuntime.d.ts +113 -0
  105. package/bin/types/shell/ShellRuntime.d.ts.map +1 -0
  106. package/bin/types/shell/ShellRuntime.js +10 -0
  107. package/bin/types/shell/ShellRuntime.js.map +1 -0
  108. package/bin/types/shell/ShellRuntimeOptions.d.ts +103 -0
  109. package/bin/types/shell/ShellRuntimeOptions.d.ts.map +1 -0
  110. package/bin/types/shell/ShellRuntimeOptions.js +10 -0
  111. package/bin/types/shell/ShellRuntimeOptions.js.map +1 -0
  112. package/bin/types/shell/WorkspaceShell.d.ts +58 -0
  113. package/bin/types/shell/WorkspaceShell.d.ts.map +1 -0
  114. package/bin/types/shell/WorkspaceShell.js +3 -0
  115. package/bin/types/shell/WorkspaceShell.js.map +1 -0
  116. package/bin/types/storage/Storage.d.ts +27 -0
  117. package/bin/types/storage/Storage.d.ts.map +1 -0
  118. package/bin/types/storage/Storage.js +3 -0
  119. package/bin/types/storage/Storage.js.map +1 -0
  120. package/bin/types/tool/RuntimeToolEffect.d.ts +14 -0
  121. package/bin/types/tool/RuntimeToolEffect.d.ts.map +1 -0
  122. package/bin/types/tool/RuntimeToolEffect.js +8 -0
  123. package/bin/types/tool/RuntimeToolEffect.js.map +1 -0
  124. package/bin/types/tool/index.d.ts +1 -0
  125. package/bin/types/tool/index.d.ts.map +1 -1
  126. package/bin/types/workspace/FileSystem.d.ts +56 -0
  127. package/bin/types/workspace/FileSystem.d.ts.map +1 -0
  128. package/bin/types/workspace/FileSystem.js +9 -0
  129. package/bin/types/workspace/FileSystem.js.map +1 -0
  130. package/bin/types/workspace/FileTool.d.ts +182 -0
  131. package/bin/types/workspace/FileTool.d.ts.map +1 -0
  132. package/bin/types/workspace/FileTool.js +10 -0
  133. package/bin/types/workspace/FileTool.js.map +1 -0
  134. package/bin/types/workspace/SearchTool.d.ts +131 -0
  135. package/bin/types/workspace/SearchTool.d.ts.map +1 -0
  136. package/bin/types/workspace/SearchTool.js +10 -0
  137. package/bin/types/workspace/SearchTool.js.map +1 -0
  138. package/bin/types/workspace/WorkspaceEnv.d.ts +16 -0
  139. package/bin/types/workspace/WorkspaceEnv.d.ts.map +1 -0
  140. package/bin/types/workspace/WorkspaceEnv.js +9 -0
  141. package/bin/types/workspace/WorkspaceEnv.js.map +1 -0
  142. package/bin/types/workspace/WorkspaceFileMutation.d.ts +42 -0
  143. package/bin/types/workspace/WorkspaceFileMutation.d.ts.map +1 -0
  144. package/bin/types/workspace/WorkspaceFileMutation.js +16 -0
  145. package/bin/types/workspace/WorkspaceFileMutation.js.map +1 -0
  146. package/bin/types/workspace/WorkspaceRuntime.d.ts +45 -0
  147. package/bin/types/workspace/WorkspaceRuntime.d.ts.map +1 -0
  148. package/bin/types/workspace/WorkspaceRuntime.js +8 -0
  149. package/bin/types/workspace/WorkspaceRuntime.js.map +1 -0
  150. package/bin/types/workspace/WorkspaceToolResult.d.ts +44 -0
  151. package/bin/types/workspace/WorkspaceToolResult.d.ts.map +1 -0
  152. package/bin/types/workspace/WorkspaceToolResult.js +8 -0
  153. package/bin/types/workspace/WorkspaceToolResult.js.map +1 -0
  154. package/bin/types/workspace/WorkspaceTools.d.ts +20 -0
  155. package/bin/types/workspace/WorkspaceTools.d.ts.map +1 -0
  156. package/bin/types/workspace/WorkspaceTools.js +9 -0
  157. package/bin/types/workspace/WorkspaceTools.js.map +1 -0
  158. package/bin/workspace.d.ts +12 -0
  159. package/bin/workspace.d.ts.map +1 -0
  160. package/bin/workspace.js +3 -0
  161. package/bin/workspace.js.map +1 -0
  162. package/package.json +14 -1
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Session Hook 跨包运行协议。
3
+ *
4
+ * Agent 定义 Hook 检查点,City 等组合层提供具体实现。协议放在公共类型包中,
5
+ * 使双方共享稳定边界而不产生 package 反向依赖。
6
+ */
7
+ import type { JsonValue } from "../json/Json.js";
8
+ import type { SessionMessage } from "./SessionMessage.js";
9
+ import type { SessionOrigin } from "./SessionOrigin.js";
10
+ import type { SessionSystemBlock } from "./SessionSystem.js";
11
+ /** Session 向 Hook 暴露的单次执行快照。 */
12
+ export interface SessionHookContext {
13
+ /** 当前 Session 标识;非 Session 调用时为空。 */
14
+ readonly session_id?: string;
15
+ /** 当前 Session 来源;非 Session 调用时为空。 */
16
+ readonly session_origin?: SessionOrigin;
17
+ /** 当前 Turn 标识;非 Turn 调用时为空。 */
18
+ readonly turn_id?: string;
19
+ /** 当前 Workspace 的逻辑根路径。 */
20
+ readonly project_root?: string;
21
+ /** 当前 Step 已提交的 Workspace 环境快照。 */
22
+ readonly workspace_env?: Readonly<Record<string, string>>;
23
+ /** 当前 Step 已提交的 Agent 指令快照。 */
24
+ readonly agent_systems?: readonly string[];
25
+ /** 当前 Turn 的协作式取消信号。 */
26
+ readonly abort_signal?: AbortSignal;
27
+ /** 当前 Tool 或宿主调用的稳定标识。 */
28
+ readonly call_id?: string;
29
+ }
30
+ /** 单个 Session Step 捕获的稳定 Hook 执行作用域。 */
31
+ export interface SessionHookScopeRuntime {
32
+ /** 解析当前作用域中生效的 system blocks。 */
33
+ system_blocks(context?: SessionHookContext): Promise<SessionSystemBlock[]>;
34
+ /** 按注册顺序运行一个可转换值的 Hook。 */
35
+ pipeline<TValue = JsonValue>(point_name: string, value: TValue): Promise<TValue>;
36
+ /** 按注册顺序运行一个只产生副作用的 Hook。 */
37
+ effect<TValue = JsonValue>(point_name: string, value: TValue): Promise<void>;
38
+ /** 幂等释放当前作用域捕获的长期资源。 */
39
+ close(): Promise<void>;
40
+ }
41
+ /** Session 在执行检查点消费的 Hook 集合协议。 */
42
+ export interface SessionHookRuntime {
43
+ /** 解析当前执行视图中生效的 system blocks。 */
44
+ system_blocks(context?: SessionHookContext): Promise<SessionSystemBlock[]>;
45
+ /** 按注册顺序运行一个可转换值的 Hook。 */
46
+ pipeline<TValue = JsonValue>(point_name: string, value: TValue): Promise<TValue>;
47
+ /** 按注册顺序运行一个只产生副作用的 Hook。 */
48
+ effect<TValue = JsonValue>(point_name: string, value: TValue): Promise<void>;
49
+ /** 为下一个 Session Step 捕获稳定 Hook 作用域。 */
50
+ open(): Promise<SessionHookScopeRuntime>;
51
+ }
52
+ /** SessionHooks 与 SessionHookScope 共用的具体处理函数。 */
53
+ export interface SessionHookHandlers {
54
+ /** 解析当前执行视图中生效的 system blocks。 */
55
+ readonly system_blocks?: (context?: SessionHookContext) => Promise<SessionSystemBlock[]>;
56
+ /** 按注册顺序运行一个可转换值的 Hook。 */
57
+ readonly pipeline?: <TValue = JsonValue>(point_name: string, value: TValue) => Promise<TValue>;
58
+ /** 按注册顺序运行一个只产生副作用的 Hook。 */
59
+ readonly effect?: <TValue = JsonValue>(point_name: string, value: TValue) => Promise<void>;
60
+ /** 幂等释放当前 Scope 捕获的长期资源占用。 */
61
+ readonly close?: () => Promise<void>;
62
+ /** 为下一个 Step 捕获一份稳定 Hook 作用域。 */
63
+ readonly open?: () => SessionHookHandlers | Promise<SessionHookHandlers>;
64
+ }
65
+ /** Hook 在当前 Turn 中返回的一条低权限动态参考内容。 */
66
+ export interface SessionHookContextBlock {
67
+ /** 产生当前内容块的 Plugin 稳定名称。 */
68
+ source_plugin: string;
69
+ /** Plugin 内稳定且非空的内容块名称。 */
70
+ name: string;
71
+ /** 需要追加到当前 User 模型消息副本的完整文本。 */
72
+ content: string;
73
+ /** 当前动态内容的信任等级;当前固定为历史参考数据。 */
74
+ trust_level: "reference";
75
+ /** 支撑当前内容的可选稳定逻辑引用。 */
76
+ citations?: string[];
77
+ /** 当前内容块的可选来源版本,用于审计和恢复。 */
78
+ version?: string;
79
+ }
80
+ /** 当前 Turn 中一条 canonical User Message 的只读文本投影。 */
81
+ export interface SessionHookUserMessage {
82
+ /** canonical User Message 的稳定标识。 */
83
+ message_id: string;
84
+ /** 从 canonical 文本 Part 中提取的原始用户文本。 */
85
+ text: string;
86
+ }
87
+ /** `session.system_context` pipeline 的值。 */
88
+ export interface SessionSystemContextHookValue {
89
+ /** 当前 Session 的稳定标识。 */
90
+ session_id: string;
91
+ /** 当前 Turn 的稳定标识;非 Turn system 查询时省略。 */
92
+ turn_id?: string;
93
+ /** Pipeline 当前累计的 Session system blocks。 */
94
+ blocks: SessionSystemBlock[];
95
+ }
96
+ /** `session.turn_context` pipeline 的值。 */
97
+ export interface SessionTurnContextHookValue {
98
+ /** 当前 Session 的稳定标识。 */
99
+ session_id: string;
100
+ /** 当前 Turn 的稳定标识。 */
101
+ turn_id: string;
102
+ /** 当前 Turn 已提交的 canonical User Message 文本投影。 */
103
+ user_messages: SessionHookUserMessage[];
104
+ /** Pipeline 当前累计的低权限动态内容块。 */
105
+ blocks: SessionHookContextBlock[];
106
+ }
107
+ /** 一个 canonical Turn 完成后的稳定状态。 */
108
+ export type SessionCommittedTurnStatus = "completed" | "failed" | "stopped";
109
+ /** `session.turn_committed` effect 的值。 */
110
+ export interface SessionTurnCommittedHookValue {
111
+ /** 当前 Session 的稳定标识。 */
112
+ session_id: string;
113
+ /** 当前 Turn 的稳定标识。 */
114
+ turn_id: string;
115
+ /** 当前 Turn 的最终提交状态。 */
116
+ status: SessionCommittedTurnStatus;
117
+ /** 当前 Turn 已经持久化完成的 canonical Message 快照。 */
118
+ messages: SessionMessage[];
119
+ }
120
+ //# sourceMappingURL=SessionHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionHook.d.ts","sourceRoot":"","sources":["../../../src/types/session/SessionHook.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,gCAAgC;AAChC,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,qCAAqC;IACrC,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC;IACxC,+BAA+B;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,2BAA2B;IAC3B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,mCAAmC;IACnC,QAA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AM,WAAW,6BAA6B;IAC5C,wBAAwB;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAED,0CAA0C;AAC1C,MAAM,WAAW,2BAA2B;IAC1C,wBAAwB;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,aAAa,EAAE,sBAAsB,EAAE,CAAC;IACxC,8BAA8B;IAC9B,MAAM,EAAE,uBAAuB,EAAE,CAAC;CACnC;AAED,kCAAkC;AAClC,MAAM,MAAM,0BAA0B,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE5E,0CAA0C;AAC1C,MAAM,WAAW,6BAA6B;IAC5C,wBAAwB;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,MAAM,EAAE,0BAA0B,CAAC;IACnC,6CAA6C;IAC7C,QAAQ,EAAE,cAAc,EAAE,CAAC;CAC5B"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Session Hook 跨包运行协议。
3
+ *
4
+ * Agent 定义 Hook 检查点,City 等组合层提供具体实现。协议放在公共类型包中,
5
+ * 使双方共享稳定边界而不产生 package 反向依赖。
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=SessionHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionHook.js","sourceRoot":"","sources":["../../../src/types/session/SessionHook.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Session Interaction 通用协议。
3
+ *
4
+ * Interaction 只定义可持久化的生命周期与通用信封;业务类型和 payload
5
+ * 由 Tool、Plugin、Shell 或宿主应用动态定义,前端可以自由选择渲染方式。
6
+ */
7
+ import type { JsonValue } from "../json/Json.js";
8
+ /** Interaction 当前生命周期状态。 */
9
+ export type SessionInteractionStatus = "pending" | "resolved" | "denied" | "expired" | "cancelled" | "failed";
10
+ /** 高风险操作审批请求是否需要用户逐次确认。 */
11
+ export type SessionApprovalMode = "ask" | "always-allow";
12
+ /** Interaction 的执行来源。 */
13
+ export type SessionInteractionSource = {
14
+ /** 来源为 Tool Call。 */
15
+ type: "tool";
16
+ /** 发起 Interaction 的稳定 Tool Call 标识。 */
17
+ tool_call_id?: string;
18
+ /** 发起 Interaction 的工具注册名称。 */
19
+ tool_name?: string;
20
+ } | {
21
+ /** 来源为 Plugin。 */
22
+ type: "plugin";
23
+ /** 发起 Interaction 的 Plugin 名称。 */
24
+ plugin_name: string;
25
+ /** Plugin 关联的 Tool Call 标识。 */
26
+ tool_call_id?: string;
27
+ /** Plugin 关联的 Tool 名称。 */
28
+ tool_name?: string;
29
+ } | {
30
+ /** 来源为 Shell。 */
31
+ type: "shell";
32
+ /** 发起 Interaction 的 Shell Tool Call 标识。 */
33
+ tool_call_id?: string;
34
+ /** 发起 Interaction 的 Shell 工具名称。 */
35
+ tool_name?: string;
36
+ } | {
37
+ /** 来源为不绑定具体 Tool 的 Session 执行过程。 */
38
+ type: "execution";
39
+ /** 可选关联的 Tool Call 标识。 */
40
+ tool_call_id?: string;
41
+ /** 可选关联的 Tool 名称。 */
42
+ tool_name?: string;
43
+ };
44
+ /** Interaction 请求公共字段。 */
45
+ export interface SessionInteractionRequest {
46
+ /** 当前 Interaction 的稳定唯一标识。 */
47
+ interaction_id: string;
48
+ /** 当前 Interaction 所属 Turn 标识。 */
49
+ turn_id: string;
50
+ /** 动态业务类型;核心类型使用 question、approval 等,Plugin 使用命名空间。 */
51
+ type: string;
52
+ /** 当前 Interaction 的执行来源。 */
53
+ source: SessionInteractionSource;
54
+ /** 前端可选展示标题。 */
55
+ title?: string;
56
+ /** 前端可选展示描述。 */
57
+ description?: string;
58
+ /** 业务请求数据,由 type 对应的生产者解释。 */
59
+ payload: JsonValue;
60
+ /** 响应数据的声明式校验结构;不包含可执行 UI 代码。 */
61
+ response_schema?: JsonValue;
62
+ /** 当前 Interaction 创建时间戳,单位为毫秒。 */
63
+ created_at: number;
64
+ /** 当前 Interaction 自动过期时间戳,省略表示不自动过期。 */
65
+ expires_at?: number;
66
+ }
67
+ /** Approval Interaction 的默认 payload 结构。 */
68
+ export interface SessionApprovalPayload {
69
+ /** 当前审批决定对应的操作。 */
70
+ operation: "exec" | "start" | "write" | "tool";
71
+ /** 请求执行的命令或输入文本。 */
72
+ command?: string;
73
+ /** 请求执行时使用的工作目录。 */
74
+ cwd?: string;
75
+ /** 请求高风险操作的明确原因。 */
76
+ reason?: string;
77
+ /** Tool schema 校验通过后的真实调用输入。 */
78
+ validated_input?: JsonValue;
79
+ /** Tool 定义提供的稳定能力说明。 */
80
+ tool_description?: string;
81
+ /** 模型为当前调用给出的可选解释。 */
82
+ model_explanation?: string;
83
+ }
84
+ /** Question 支持的回答形式。 */
85
+ export type SessionInteractionQuestionResponseType = "text" | "single_select" | "multi_select";
86
+ /** Question 选择项。 */
87
+ export interface SessionInteractionOption {
88
+ /** 当前选项在问题内的稳定值。 */
89
+ value: string;
90
+ /** 当前选项向用户展示的标签。 */
91
+ label: string;
92
+ /** 当前选项的可选解释。 */
93
+ description?: string;
94
+ }
95
+ /** 一条等待用户回答的问题。 */
96
+ export interface SessionInteractionQuestion {
97
+ /** 当前问题在 Interaction 内的稳定标识。 */
98
+ question_id: string;
99
+ /** 向用户展示的完整问题文本。 */
100
+ prompt: string;
101
+ /** 当前问题要求的回答形式。 */
102
+ response_type: SessionInteractionQuestionResponseType;
103
+ /** 单选或多选问题允许选择的候选项。 */
104
+ options?: SessionInteractionOption[];
105
+ }
106
+ /** Question Interaction 的默认 payload 结构。 */
107
+ export interface SessionQuestionPayload {
108
+ /** Interaction 包含的一到多条问题。 */
109
+ questions: SessionInteractionQuestion[];
110
+ }
111
+ /** Approval Interaction 的用户响应 payload。 */
112
+ export interface SessionApprovalResponsePayload {
113
+ /** 用户对审批作出的最终决定。 */
114
+ decision: "approved" | "denied";
115
+ /** 拒绝时的可选原因。 */
116
+ reason?: string;
117
+ }
118
+ /** 单条 Question 回答。 */
119
+ export interface SessionInteractionAnswer {
120
+ /** 当前回答对应的问题标识。 */
121
+ question_id: string;
122
+ /** 文本或选择回答值;多选回答使用字符串数组。 */
123
+ value: string | string[];
124
+ }
125
+ /** Question Interaction 的用户响应 payload。 */
126
+ export interface SessionQuestionResponsePayload {
127
+ /** 按 question_id 关联的完整回答集合。 */
128
+ answers: SessionInteractionAnswer[];
129
+ /** 用户随回答提交的可选补充说明。 */
130
+ note?: string;
131
+ }
132
+ /** 用户提交一次 Interaction 响应的通用结构。 */
133
+ export interface SessionInteractionResponse {
134
+ /** 必须与原请求 type 一致。 */
135
+ type: string;
136
+ /** 用户是否允许当前 Interaction 继续。 */
137
+ outcome: "resolved" | "denied";
138
+ /** 业务响应数据,由 type 对应的生产者解释。 */
139
+ payload: JsonValue;
140
+ }
141
+ /** 用户提交一次 Interaction 响应的公开输入。 */
142
+ export interface RespondSessionInteractionInput {
143
+ /** 需要响应的 pending Interaction 标识。 */
144
+ interaction_id: string;
145
+ /** 与原请求 type 一致的结构化响应。 */
146
+ response: SessionInteractionResponse;
147
+ }
148
+ /** Interaction 已成功收到用户响应。 */
149
+ export interface SessionResolvedInteractionResult {
150
+ /** 终态固定为 resolved。 */
151
+ status: "resolved";
152
+ /** 已完成的 Interaction 标识。 */
153
+ interaction_id: string;
154
+ /** 已持久化的结构化用户响应。 */
155
+ response: SessionInteractionResponse;
156
+ }
157
+ /** Interaction 被拒绝。 */
158
+ export interface SessionDeniedInteractionResult {
159
+ /** 终态固定为 denied。 */
160
+ status: "denied";
161
+ /** 被拒绝的 Interaction 标识。 */
162
+ interaction_id: string;
163
+ /** 可选拒绝原因。 */
164
+ reason?: string;
165
+ }
166
+ /** Interaction 因等待超时结束。 */
167
+ export interface SessionExpiredInteractionResult {
168
+ /** 终态固定为 expired。 */
169
+ status: "expired";
170
+ /** 已过期的 Interaction 标识。 */
171
+ interaction_id: string;
172
+ }
173
+ /** Interaction 因 Session 生命周期变化被取消。 */
174
+ export interface SessionCancelledInteractionResult {
175
+ /** 终态固定为 cancelled。 */
176
+ status: "cancelled";
177
+ /** 已取消的 Interaction 标识。 */
178
+ interaction_id: string;
179
+ /** Interaction 被取消的稳定原因。 */
180
+ reason: "turn_stopped" | "session_disposed" | "runtime_interrupted";
181
+ }
182
+ /** Interaction 执行失败。 */
183
+ export interface SessionFailedInteractionResult {
184
+ /** 终态固定为 failed。 */
185
+ status: "failed";
186
+ /** 执行失败的 Interaction 标识。 */
187
+ interaction_id: string;
188
+ /** 稳定失败说明。 */
189
+ error: string;
190
+ }
191
+ /** Interaction 等待方最终收到的领域结果。 */
192
+ export type SessionInteractionResult = SessionResolvedInteractionResult | SessionDeniedInteractionResult | SessionExpiredInteractionResult | SessionCancelledInteractionResult | SessionFailedInteractionResult;
193
+ /** 当前 Session 中一条 pending Interaction 的公开快照。 */
194
+ export interface SessionPendingInteraction {
195
+ /** 已持久化的完整 Interaction 请求。 */
196
+ request: SessionInteractionRequest;
197
+ }
198
+ /** 执行方等待一次 Interaction 的运行时句柄。 */
199
+ export interface SessionInteractionHandle {
200
+ /** 已成功持久化并等待响应的 Interaction 标识。 */
201
+ interaction_id: string;
202
+ /** Interaction 进入终态后兑现的领域结果。 */
203
+ result: Promise<SessionInteractionResult>;
204
+ }
205
+ /** 把 pending Interaction 标记为超时的输入。 */
206
+ export interface SessionExpireInteractionInput {
207
+ /** 目标终态固定为 expired。 */
208
+ status: "expired";
209
+ }
210
+ /** 因 Session 生命周期变化取消 pending Interaction 的输入。 */
211
+ export interface SessionCancelInteractionInput {
212
+ /** 目标终态固定为 cancelled。 */
213
+ status: "cancelled";
214
+ /** Interaction 被取消的稳定生命周期原因。 */
215
+ reason: "turn_stopped" | "session_disposed" | "runtime_interrupted";
216
+ }
217
+ /** 内部关闭 pending Interaction 时允许提交的终态输入。 */
218
+ export type SessionInteractionCloseInput = SessionExpireInteractionInput | SessionCancelInteractionInput;
219
+ /** 执行面请求用户异步参与的最小端口。 */
220
+ export interface SessionInteractionPort {
221
+ /** 创建并持久化一次 Interaction,返回等待终态结果的句柄。 */
222
+ request(request: SessionInteractionRequest): Promise<SessionInteractionHandle>;
223
+ }
224
+ /** 控制面结束 Turn 时使用的 Interaction 生命周期端口。 */
225
+ export interface SessionInteractionLifecycle {
226
+ /** 取消当前 Session 中全部 pending Interaction。 */
227
+ cancel_all(reason: "turn_stopped" | "session_disposed" | "runtime_interrupted"): Promise<void>;
228
+ }
229
+ /** 默认审批响应 schema,供前端生成自由实现的控件。 */
230
+ export declare const SESSION_APPROVAL_RESPONSE_SCHEMA: JsonValue;
231
+ //# sourceMappingURL=SessionInteraction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionInteraction.d.ts","sourceRoot":"","sources":["../../../src/types/session/SessionInteraction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,4BAA4B;AAC5B,MAAM,MAAM,wBAAwB,GAChC,SAAS,GACT,UAAU,GACV,QAAQ,GACR,SAAS,GACT,WAAW,GACX,QAAQ,CAAC;AAEb,2BAA2B;AAC3B,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,cAAc,CAAC;AAEzD,yBAAyB;AACzB,MAAM,MAAM,wBAAwB,GAChC;IACE,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GACD;IACE,kBAAkB;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;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GAChC,8BAA8B,GAC9B,+BAA+B,GAC/B,iCAAiC,GACjC,8BAA8B,CAAC;AAEnC,gDAAgD;AAChD,MAAM,WAAW,yBAAyB;IACxC,8BAA8B;IAC9B,OAAO,EAAE,yBAAyB,CAAC;CACpC;AAED,kCAAkC;AAClC,MAAM,WAAW,wBAAwB;IACvC,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,gCAAgC;IAChC,MAAM,EAAE,OAAO,CAAC,wBAAwB,CAAC,CAAC;CAC3C;AAED,sCAAsC;AACtC,MAAM,WAAW,6BAA6B;IAC5C,uBAAuB;IACvB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,kDAAkD;AAClD,MAAM,WAAW,6BAA6B;IAC5C,yBAAyB;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,gCAAgC;IAChC,MAAM,EAAE,cAAc,GAAG,kBAAkB,GAAG,qBAAqB,CAAC;CACrE;AAED,2CAA2C;AAC3C,MAAM,MAAM,4BAA4B,GACpC,6BAA6B,GAC7B,6BAA6B,CAAC;AAElC,wBAAwB;AACxB,MAAM,WAAW,sBAAsB;IACrC,wCAAwC;IACxC,OAAO,CACL,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,wBAAwB,CAAC,CAAC;CACtC;AAED,0CAA0C;AAC1C,MAAM,WAAW,2BAA2B;IAC1C,4CAA4C;IAC5C,UAAU,CACR,MAAM,EAAE,cAAc,GAAG,kBAAkB,GAAG,qBAAqB,GAClE,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED,kCAAkC;AAClC,eAAO,MAAM,gCAAgC,EAAE,SAM9C,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Session Interaction 通用协议。
3
+ *
4
+ * Interaction 只定义可持久化的生命周期与通用信封;业务类型和 payload
5
+ * 由 Tool、Plugin、Shell 或宿主应用动态定义,前端可以自由选择渲染方式。
6
+ */
7
+ /** 默认审批响应 schema,供前端生成自由实现的控件。 */
8
+ export const SESSION_APPROVAL_RESPONSE_SCHEMA = {
9
+ type: "object",
10
+ required: ["decision"],
11
+ properties: {
12
+ decision: { type: "string", enum: ["approved", "denied"] },
13
+ },
14
+ };
15
+ //# sourceMappingURL=SessionInteraction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionInteraction.js","sourceRoot":"","sources":["../../../src/types/session/SessionInteraction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoRH,kCAAkC;AAClC,MAAM,CAAC,MAAM,gCAAgC,GAAc;IACzD,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,UAAU,CAAC;IACtB,UAAU,EAAE;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE;KAC3D;CACF,CAAC"}
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Session canonical 消息类型。
3
+ *
4
+ * Session 只维护一条由 sequence 排序的双主体消息序列;User 与 Agent 是顶层角色,
5
+ * text、reasoning、tool、interaction、file、data、action、error 都是主体内部 Part。
6
+ */
7
+ import type { JsonObject, JsonValue } from "../json/Json.js";
8
+ import type { SessionContextContent, SessionDataContent, SessionFileContent, SessionTextContent } from "./SessionContent.js";
9
+ import type { SessionInteractionRequest, SessionInteractionResponse, SessionInteractionStatus } from "./SessionInteraction.js";
10
+ /** Message 默认展示范围。 */
11
+ export type SessionMessageVisibility = "visible" | "internal";
12
+ /** 从其他 Session 导入时保留的来源身份。 */
13
+ export interface SessionMessageOrigin {
14
+ /** 来源 Session 标识。 */
15
+ session_id: string;
16
+ /** 来源 Message 标识。 */
17
+ message_id: string;
18
+ /** 来源 turn 标识。 */
19
+ turn_id?: string;
20
+ }
21
+ /** Session Message 公共字段。 */
22
+ export interface SessionMessageBase {
23
+ /** 当前 Message 在 Session 内的稳定唯一标识。 */
24
+ message_id: string;
25
+ /** 当前 Message 所属 Session 标识。 */
26
+ session_id: string;
27
+ /** 当前 Message 所属 turn;独立 action 可以省略。 */
28
+ turn_id?: string;
29
+ /** Message 的线性位置;创建后永远不变。 */
30
+ sequence: number;
31
+ /** Message 版本号;每次对外发布的消息变化后递增。 */
32
+ revision: number;
33
+ /** 当前 Message 是否默认对用户可见。 */
34
+ visibility: SessionMessageVisibility;
35
+ /** Message 首次创建时间戳(ms)。 */
36
+ created_at: number;
37
+ /** Message 最近更新时间戳(ms)。 */
38
+ updated_at: number;
39
+ /** 从其他 Session 导入时的来源信息。 */
40
+ origin?: SessionMessageOrigin;
41
+ }
42
+ /** User 文本 part。 */
43
+ export interface SessionUserTextPart extends SessionTextContent {
44
+ /** User Message 内稳定的 part 标识。 */
45
+ part_id: string;
46
+ /** Part 在当前 User Message 内的不可变线性顺序,从 1 开始。 */
47
+ sequence: number;
48
+ }
49
+ /** User 带语义标签的模型上下文 part。 */
50
+ export interface SessionUserContextPart extends SessionContextContent {
51
+ /** User Message 内稳定的 part 标识。 */
52
+ part_id: string;
53
+ /** Part 在当前 User Message 内的不可变线性顺序,从 1 开始。 */
54
+ sequence: number;
55
+ }
56
+ /** User 文件 part。 */
57
+ export interface SessionUserFilePart extends SessionFileContent {
58
+ /** User Message 内稳定的 part 标识。 */
59
+ part_id: string;
60
+ /** Part 在当前 User Message 内的不可变线性顺序,从 1 开始。 */
61
+ sequence: number;
62
+ }
63
+ /** User 结构化数据 part。 */
64
+ export interface SessionUserDataPart extends SessionDataContent {
65
+ /** User Message 内稳定的 part 标识。 */
66
+ part_id: string;
67
+ /** Part 在当前 User Message 内的不可变线性顺序,从 1 开始。 */
68
+ sequence: number;
69
+ }
70
+ /** User Message part。 */
71
+ export type SessionUserMessagePart = SessionUserTextPart | SessionUserContextPart | SessionUserFilePart | SessionUserDataPart;
72
+ /** User 顶层 Message。 */
73
+ export interface SessionUserMessage extends SessionMessageBase {
74
+ /** Message 主体角色固定为 user。 */
75
+ role: "user";
76
+ /** 用户消息的结构化 parts。 */
77
+ parts: SessionUserMessagePart[];
78
+ }
79
+ /** Agent 普通文本 Part。 */
80
+ export interface SessionAgentTextPart extends SessionTextContent {
81
+ /** Agent Message 内稳定的 Part 标识。 */
82
+ part_id: string;
83
+ /** Assistant Part 在当前 Message 中的不可变线性顺序,从 1 开始。 */
84
+ sequence: number;
85
+ /** 产生当前 Part 的模型 Step;非模型追加内容可以为空。 */
86
+ step_id?: string;
87
+ /** 文本 part 是否已经结束。 */
88
+ state: "streaming" | "done";
89
+ }
90
+ /** Agent 推理文本 Part。 */
91
+ export interface SessionAgentReasoningPart {
92
+ /** Agent Message 内稳定的 Part 标识。 */
93
+ part_id: string;
94
+ /** Assistant Part 在当前 Message 中的不可变线性顺序,从 1 开始。 */
95
+ sequence: number;
96
+ /** 产生当前 Part 的模型 Step;非模型追加内容可以为空。 */
97
+ step_id?: string;
98
+ /** part 类型固定为 reasoning。 */
99
+ type: "reasoning";
100
+ /** 当前已经累计的完整推理文本。 */
101
+ text: string;
102
+ /** 推理 part 是否已经结束。 */
103
+ state: "streaming" | "done";
104
+ /** Provider 用于后续模型上下文续接的可选不透明签名。 */
105
+ reasoning_signature?: string;
106
+ }
107
+ /** Agent 工具 Part。 */
108
+ export interface SessionAgentToolPart {
109
+ /** Agent Message 内稳定的 Part 标识。 */
110
+ part_id: string;
111
+ /** Assistant Part 在当前 Message 中的不可变线性顺序,从 1 开始。 */
112
+ sequence: number;
113
+ /** 产生当前 Part 的模型 Step;非模型追加内容可以为空。 */
114
+ step_id?: string;
115
+ /** part 类型固定为 tool。 */
116
+ type: "tool";
117
+ /** 模型工具调用稳定标识。 */
118
+ tool_call_id: string;
119
+ /** 工具注册名称。 */
120
+ tool_name: string;
121
+ /** 工具当前生命周期状态。 */
122
+ state: "input-streaming" | "ready" | "waiting-user" | "running" | "completed" | "failed";
123
+ /** 流式接收中的参数原文。 */
124
+ input_text?: string;
125
+ /** 收敛后的结构化输入。 */
126
+ input?: JsonValue;
127
+ /** 工具成功输出。 */
128
+ output?: JsonValue;
129
+ /** 工具失败信息。 */
130
+ error?: string;
131
+ /** 工具调用的可选展示标题。 */
132
+ title?: string;
133
+ }
134
+ /** Agent 用户异步交互 Part。 */
135
+ export interface SessionAgentInteractionPart {
136
+ /** Agent Message 内稳定的 Part 标识。 */
137
+ part_id: string;
138
+ /** Assistant Part 在当前 Message 中的不可变线性顺序,从 1 开始。 */
139
+ sequence: number;
140
+ /** 产生当前 Part 的模型 Step;非模型追加内容可以为空。 */
141
+ step_id?: string;
142
+ /** part 类型固定为 interaction。 */
143
+ type: "interaction";
144
+ /** 当前 Interaction 的稳定唯一标识。 */
145
+ interaction_id: string;
146
+ /** 当前 Interaction 的具体业务类型。 */
147
+ interaction_type: string;
148
+ /** 当前 Interaction 的生命周期状态。 */
149
+ status: SessionInteractionStatus;
150
+ /** 已持久化的完整 Interaction 请求。 */
151
+ request: SessionInteractionRequest;
152
+ /** 用户已响应时保存的结构化响应。 */
153
+ response?: SessionInteractionResponse;
154
+ /** Interaction 进入终态的时间戳,单位为毫秒。 */
155
+ resolved_at?: number;
156
+ /** Interaction 被取消时保存的稳定原因。 */
157
+ cancel_reason?: "turn_stopped" | "session_disposed" | "runtime_interrupted";
158
+ }
159
+ /** Agent 文件 Part。 */
160
+ export interface SessionAgentFilePart extends SessionFileContent {
161
+ /** Agent Message 内稳定的 Part 标识。 */
162
+ part_id: string;
163
+ /** Assistant Part 在当前 Message 中的不可变线性顺序,从 1 开始。 */
164
+ sequence: number;
165
+ /** 产生当前 Part 的模型 Step;非模型追加内容可以为空。 */
166
+ step_id?: string;
167
+ }
168
+ /** Agent 结构化数据 Part。 */
169
+ export interface SessionAgentDataPart extends SessionDataContent {
170
+ /** Agent Message 内稳定的 Part 标识。 */
171
+ part_id: string;
172
+ /** Assistant Part 在当前 Message 中的不可变线性顺序,从 1 开始。 */
173
+ sequence: number;
174
+ /** 产生当前 Part 的模型 Step;非模型追加内容可以为空。 */
175
+ step_id?: string;
176
+ }
177
+ /** Agent Action Part。 */
178
+ export interface SessionAgentActionPart {
179
+ /** Agent Message 内稳定的 Part 标识。 */
180
+ part_id: string;
181
+ /** Agent Part 在当前 Message 中的不可变线性顺序,从 1 开始。 */
182
+ sequence: number;
183
+ /** 产生当前 Part 的模型 Step;Session Action 可以为空。 */
184
+ step_id?: string;
185
+ /** Part 类型固定为 action。 */
186
+ type: "action";
187
+ /** 同一 Action 生命周期内稳定复用的业务标识。 */
188
+ action_id: string;
189
+ /** Action 业务类别。 */
190
+ action_type: string;
191
+ /** Action 当前生命周期状态。 */
192
+ state: "running" | "completed" | "failed";
193
+ /** Action 展示标题。 */
194
+ title: string;
195
+ /** Action 展示描述。 */
196
+ description?: string;
197
+ /** Action 附加结构化信息。 */
198
+ data?: JsonObject;
199
+ }
200
+ /** Agent Error Part。 */
201
+ export interface SessionAgentErrorPart {
202
+ /** Agent Message 内稳定的 Part 标识。 */
203
+ part_id: string;
204
+ /** Agent Part 在当前 Message 中的不可变线性顺序,从 1 开始。 */
205
+ sequence: number;
206
+ /** 产生当前 Part 的模型 Step;Session/Turn 错误可以为空。 */
207
+ step_id?: string;
208
+ /** Part 类型固定为 error。 */
209
+ type: "error";
210
+ /** 错误影响范围。 */
211
+ scope: "session" | "turn";
212
+ /** 稳定错误码。 */
213
+ code: string;
214
+ /** 用户可见错误信息。 */
215
+ message: string;
216
+ /** 当前错误是否允许重试恢复。 */
217
+ recoverable: boolean;
218
+ }
219
+ /** Agent Message Part。 */
220
+ export type SessionAgentMessagePart = SessionAgentTextPart | SessionAgentReasoningPart | SessionAgentToolPart | SessionAgentInteractionPart | SessionAgentFilePart | SessionAgentDataPart | SessionAgentActionPart | SessionAgentErrorPart;
221
+ /** Agent 顶层 Message。 */
222
+ export interface SessionAgentMessage extends SessionMessageBase {
223
+ /** Message 主体角色固定为 agent。 */
224
+ role: "agent";
225
+ /** Agent Message 聚合当前仍在写入,还是已经永久收口。 */
226
+ state: "streaming" | "done";
227
+ /** Agent 内按真实产生顺序保存的 Parts。 */
228
+ parts: SessionAgentMessagePart[];
229
+ }
230
+ /** Session 唯一顶层 Message 联合类型。 */
231
+ export type SessionMessage = SessionUserMessage | SessionAgentMessage;
232
+ /** 读取 Session Message snapshot 的分页输入。 */
233
+ export interface ListSessionMessagesInput {
234
+ /** 返回该 Message sequence 之前的一页历史;必须是正整数。 */
235
+ before_sequence?: number;
236
+ /** 单页返回的最大 Message 数量。 */
237
+ limit?: number;
238
+ /** 是否包含 internal Message。 */
239
+ include_internal?: boolean;
240
+ }
241
+ /** Session Message snapshot 分页结果。 */
242
+ export interface SessionMessagePage {
243
+ /** 当前页按 sequence 升序排列的完整 Message。 */
244
+ items: SessionMessage[];
245
+ /** 当前 Session 已分配的真实 Message 总数。 */
246
+ total: number;
247
+ /** 当前结果覆盖的第一条真实 Message sequence。 */
248
+ start_sequence?: number;
249
+ /** 当前结果覆盖的最后一条真实 Message sequence。 */
250
+ end_sequence?: number;
251
+ /** 继续向前读取时作为 before_sequence 传入的边界。 */
252
+ next_before_sequence?: number;
253
+ /** 当前结果之前是否仍有更早 Segment。 */
254
+ has_more: boolean;
255
+ }
256
+ //# sourceMappingURL=SessionMessage.d.ts.map