@downcity/agent 1.1.86 → 1.1.91

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 (78) hide show
  1. package/bin/config/AgentInitializer.d.ts.map +1 -1
  2. package/bin/config/AgentInitializer.js +2 -1
  3. package/bin/config/AgentInitializer.js.map +1 -1
  4. package/bin/config/Paths.d.ts +8 -0
  5. package/bin/config/Paths.d.ts.map +1 -1
  6. package/bin/config/Paths.js +10 -0
  7. package/bin/config/Paths.js.map +1 -1
  8. package/bin/executor/Executor.d.ts.map +1 -1
  9. package/bin/executor/Executor.js +3 -0
  10. package/bin/executor/Executor.js.map +1 -1
  11. package/bin/executor/messages/AssistantFileResource.d.ts +31 -0
  12. package/bin/executor/messages/AssistantFileResource.d.ts.map +1 -0
  13. package/bin/executor/messages/AssistantFileResource.js +113 -0
  14. package/bin/executor/messages/AssistantFileResource.js.map +1 -0
  15. package/bin/executor/messages/SessionAttachmentMapper.d.ts +8 -0
  16. package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
  17. package/bin/executor/messages/SessionAttachmentMapper.js +54 -0
  18. package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
  19. package/bin/executor/messages/SessionMessageCodec.d.ts.map +1 -1
  20. package/bin/executor/messages/SessionMessageCodec.js +5 -3
  21. package/bin/executor/messages/SessionMessageCodec.js.map +1 -1
  22. package/bin/executor/tools/plugin/PluginToolBridge.d.ts.map +1 -1
  23. package/bin/executor/tools/plugin/PluginToolBridge.js +9 -2
  24. package/bin/executor/tools/plugin/PluginToolBridge.js.map +1 -1
  25. package/bin/index.d.ts +1 -1
  26. package/bin/index.d.ts.map +1 -1
  27. package/bin/index.js.map +1 -1
  28. package/bin/plugin/core/ImagePlugin.d.ts +62 -0
  29. package/bin/plugin/core/ImagePlugin.d.ts.map +1 -1
  30. package/bin/plugin/core/ImagePlugin.js +230 -7
  31. package/bin/plugin/core/ImagePlugin.js.map +1 -1
  32. package/bin/sandbox/LinuxBubblewrapSandbox.d.ts +21 -0
  33. package/bin/sandbox/LinuxBubblewrapSandbox.d.ts.map +1 -0
  34. package/bin/sandbox/LinuxBubblewrapSandbox.js +184 -0
  35. package/bin/sandbox/LinuxBubblewrapSandbox.js.map +1 -0
  36. package/bin/sandbox/SandboxConfigResolver.d.ts +5 -0
  37. package/bin/sandbox/SandboxConfigResolver.d.ts.map +1 -1
  38. package/bin/sandbox/SandboxConfigResolver.js +11 -4
  39. package/bin/sandbox/SandboxConfigResolver.js.map +1 -1
  40. package/bin/sandbox/SandboxRunner.d.ts +1 -1
  41. package/bin/sandbox/SandboxRunner.d.ts.map +1 -1
  42. package/bin/sandbox/SandboxRunner.js +11 -3
  43. package/bin/sandbox/SandboxRunner.js.map +1 -1
  44. package/bin/sandbox/types/SandboxRuntime.d.ts +6 -2
  45. package/bin/sandbox/types/SandboxRuntime.d.ts.map +1 -1
  46. package/bin/session/Session.d.ts.map +1 -1
  47. package/bin/session/Session.js +1 -0
  48. package/bin/session/Session.js.map +1 -1
  49. package/bin/session/services/SessionTurnService.d.ts +5 -0
  50. package/bin/session/services/SessionTurnService.d.ts.map +1 -1
  51. package/bin/session/services/SessionTurnService.js +3 -0
  52. package/bin/session/services/SessionTurnService.js.map +1 -1
  53. package/bin/types/executor/SessionRunContext.d.ts +8 -0
  54. package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
  55. package/bin/types/plugin/ImagePlugin.d.ts +79 -2
  56. package/bin/types/plugin/ImagePlugin.d.ts.map +1 -1
  57. package/package.json +2 -2
  58. package/scripts/assistant-file-resource.test.mjs +91 -0
  59. package/scripts/image-plugin-job.test.mjs +155 -0
  60. package/scripts/linux-bubblewrap-sandbox.test.mjs +142 -0
  61. package/src/config/AgentInitializer.ts +2 -0
  62. package/src/config/Paths.ts +11 -0
  63. package/src/executor/Executor.ts +3 -0
  64. package/src/executor/messages/AssistantFileResource.ts +155 -0
  65. package/src/executor/messages/SessionAttachmentMapper.ts +59 -0
  66. package/src/executor/messages/SessionMessageCodec.ts +9 -3
  67. package/src/executor/tools/plugin/PluginToolBridge.ts +13 -2
  68. package/src/index.ts +4 -0
  69. package/src/plugin/core/ImagePlugin.ts +284 -7
  70. package/src/sandbox/LinuxBubblewrapSandbox.ts +229 -0
  71. package/src/sandbox/SandboxConfigResolver.ts +13 -7
  72. package/src/sandbox/SandboxRunner.ts +11 -3
  73. package/src/sandbox/types/SandboxRuntime.ts +7 -2
  74. package/src/session/Session.ts +1 -0
  75. package/src/session/services/SessionTurnService.ts +8 -0
  76. package/src/types/executor/SessionRunContext.ts +9 -0
  77. package/src/types/plugin/ImagePlugin.ts +79 -2
  78. package/tsconfig.tsbuildinfo +1 -1
@@ -130,6 +130,7 @@ export class Session implements AgentSession {
130
130
  });
131
131
  this.turnService = new SessionTurnService({
132
132
  session_id: this.id,
133
+ project_root: this.projectRoot,
133
134
  executor: this.executor,
134
135
  state_service: this.stateService,
135
136
  event_hub: this.eventHub,
@@ -32,6 +32,11 @@ type SessionTurnServiceOptions = {
32
32
  */
33
33
  session_id: string;
34
34
 
35
+ /**
36
+ * 当前项目根目录。
37
+ */
38
+ project_root: string;
39
+
35
40
  /**
36
41
  * 当前 session 执行器。
37
42
  */
@@ -53,6 +58,7 @@ type SessionTurnServiceOptions = {
53
58
  */
54
59
  export class SessionTurnService {
55
60
  private readonly session_id: string;
61
+ private readonly project_root: string;
56
62
  private readonly executor: Executor;
57
63
  private readonly state_service: SessionStateService;
58
64
  private readonly event_hub: SessionEventHub;
@@ -60,6 +66,7 @@ export class SessionTurnService {
60
66
 
61
67
  constructor(options: SessionTurnServiceOptions) {
62
68
  this.session_id = options.session_id;
69
+ this.project_root = options.project_root;
63
70
  this.executor = options.executor;
64
71
  this.state_service = options.state_service;
65
72
  this.event_hub = options.event_hub;
@@ -134,6 +141,7 @@ export class SessionTurnService {
134
141
  const tool_name_by_call_id = new Map<string, string>();
135
142
  const run_context: SessionRunContext = {
136
143
  sessionId: this.session_id,
144
+ projectRoot: this.project_root,
137
145
  onStepCallback: input.onStepMerge,
138
146
  onAssistantStepCallback: async (step) => {
139
147
  this.publish_event({
@@ -23,6 +23,15 @@ export interface SessionRunContext {
23
23
  */
24
24
  sessionId: string;
25
25
 
26
+ /**
27
+ * 当前执行所属的项目根目录。
28
+ *
29
+ * 关键点(中文)
30
+ * - 用于 tool/plugin 运行期把二进制资源写入项目级 `.downcity/resources`。
31
+ * - 未提供时,底层资源写入逻辑会回退到当前进程工作目录,兼容旧入口。
32
+ */
33
+ projectRoot?: string;
34
+
26
35
  /**
27
36
  * step 边界合并回调。
28
37
  *
@@ -88,6 +88,73 @@ export interface ImagePluginInput {
88
88
  */
89
89
  export type ImagePluginResult = UIMessage;
90
90
 
91
+ /**
92
+ * ImagePlugin 图片任务状态。
93
+ */
94
+ export type ImagePluginJobStatus = "queued" | "running" | "succeeded" | "failed";
95
+
96
+ /**
97
+ * ImagePlugin 图片任务创建结果。
98
+ */
99
+ export interface ImagePluginJobCreateResult {
100
+ /** 图片任务唯一 ID。 */
101
+ job_id: string;
102
+ /** 当前任务状态。 */
103
+ status: ImagePluginJobStatus;
104
+ /** 查询任务状态的路径或 URL。 */
105
+ status_path?: string;
106
+ /** 读取任务结果的路径或 URL。 */
107
+ result_path?: string;
108
+ /** 人类可读状态说明。 */
109
+ message?: string;
110
+ /** 建议下次轮询前等待的毫秒数。 */
111
+ poll_after_ms?: number;
112
+ /** 任务创建时间。 */
113
+ created_at?: string;
114
+ /** 任务更新时间。 */
115
+ updated_at?: string;
116
+ }
117
+
118
+ /**
119
+ * ImagePlugin 图片任务状态查询结果。
120
+ */
121
+ export interface ImagePluginJobStatusResult {
122
+ /** 图片任务唯一 ID。 */
123
+ job_id: string;
124
+ /** 当前任务状态。 */
125
+ status: ImagePluginJobStatus;
126
+ /** 人类可读状态说明。 */
127
+ message?: string;
128
+ /** 失败时的错误信息。 */
129
+ error?: string;
130
+ /** 建议下次轮询前等待的毫秒数。 */
131
+ poll_after_ms?: number;
132
+ /** 任务创建时间。 */
133
+ created_at?: string;
134
+ /** 任务更新时间。 */
135
+ updated_at?: string;
136
+ }
137
+
138
+ /**
139
+ * ImagePlugin 图片任务结果查询结果。
140
+ */
141
+ export interface ImagePluginJobResult {
142
+ /** 图片任务唯一 ID。 */
143
+ job_id: string;
144
+ /** 当前任务状态。 */
145
+ status: ImagePluginJobStatus;
146
+ /** 成功时的图片结果。 */
147
+ result?: ImagePluginResult;
148
+ /** 失败时的错误信息。 */
149
+ error?: string;
150
+ /** 人类可读状态说明。 */
151
+ message?: string;
152
+ /** 任务创建时间。 */
153
+ created_at?: string;
154
+ /** 任务更新时间。 */
155
+ updated_at?: string;
156
+ }
157
+
91
158
  /**
92
159
  * ImagePlugin 构造参数。
93
160
  */
@@ -98,6 +165,16 @@ export interface ImagePluginOptions {
98
165
  title?: string;
99
166
  /** Plugin 用途说明。 */
100
167
  description?: string;
101
- /** 图片生成函数,通常传入 `(input) => city.ai.image(input)`。 */
102
- image: (input: ImagePluginInput) => Promise<ImagePluginResult> | ImagePluginResult;
168
+ /** 可选:图片生成函数;未传 `create/status/result` 时用于本地后台任务兼容。 */
169
+ image?: (input: ImagePluginInput) => Promise<ImagePluginResult> | ImagePluginResult;
170
+ /** 可选:创建图片生成任务,通常传入 `(input) => city.ai.imageJobCreate(input)`。 */
171
+ create?: (input: ImagePluginInput) => Promise<ImagePluginJobCreateResult> | ImagePluginJobCreateResult;
172
+ /** 可选:查询图片生成任务状态,通常传入 `(input) => city.ai.imageJobStatus(input)`。 */
173
+ status?: (input: { job_id: string }) => Promise<ImagePluginJobStatusResult> | ImagePluginJobStatusResult;
174
+ /** 可选:读取图片生成任务结果,通常传入 `(input) => city.ai.imageJobResult(input)`。 */
175
+ result?: (input: { job_id: string }) => Promise<ImagePluginJobResult> | ImagePluginJobResult;
176
+ /** 兼容 `generate` 动作等待任务完成的最长毫秒数。 */
177
+ wait_timeout_ms?: number;
178
+ /** 兼容 `generate` 动作每次轮询间隔毫秒数。 */
179
+ poll_interval_ms?: number;
103
180
  }