@pixelbyte-software/pixcode 1.54.11 → 1.55.1

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 (165) hide show
  1. package/dist/assets/{index-Bcqs_1vc.js → index-B-ySsQqi.js} +147 -147
  2. package/dist/assets/index-CWO38aJI.css +32 -0
  3. package/dist/index.html +2 -2
  4. package/dist-server/server/claude-sdk.js +1 -1
  5. package/dist-server/server/claude-sdk.js.map +1 -1
  6. package/dist-server/server/index.js +6 -11
  7. package/dist-server/server/index.js.map +1 -1
  8. package/dist-server/server/modules/security/permission-policy.js.map +1 -0
  9. package/dist-server/server/services/control-room.js +9 -1
  10. package/dist-server/server/services/control-room.js.map +1 -1
  11. package/dist-server/server/services/public-api-manifest.js +5 -5
  12. package/dist-server/server/services/public-api-manifest.js.map +1 -1
  13. package/dist-server/server/services/telegram/control-center.js +10 -10
  14. package/dist-server/server/services/telegram/control-center.js.map +1 -1
  15. package/dist-server/server/services/telegram/telegram-gateway.js +2 -2
  16. package/dist-server/server/services/telegram/telegram-gateway.js.map +1 -1
  17. package/dist-server/server/services/telegram/translations.js +5 -5
  18. package/dist-server/server/services/telegram/translations.js.map +1 -1
  19. package/package.json +1 -1
  20. package/server/claude-sdk.js +1 -1
  21. package/server/index.js +6 -23
  22. package/server/services/control-room.js +10 -1
  23. package/server/services/public-api-manifest.js +5 -5
  24. package/server/services/telegram/control-center.js +10 -10
  25. package/server/services/telegram/telegram-gateway.js +2 -2
  26. package/server/services/telegram/translations.js +5 -5
  27. package/dist/assets/index-Dz1luE0u.css +0 -32
  28. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js +0 -73
  29. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js.map +0 -1
  30. package/dist-server/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js +0 -17
  31. package/dist-server/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js.map +0 -1
  32. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js +0 -236
  33. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js.map +0 -1
  34. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js +0 -202
  35. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js.map +0 -1
  36. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js +0 -205
  37. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js.map +0 -1
  38. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js +0 -205
  39. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js.map +0 -1
  40. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.js +0 -84
  41. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.js.map +0 -1
  42. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.test.js +0 -43
  43. package/dist-server/server/modules/orchestration/a2a/adapters/json-event.adapter.test.js.map +0 -1
  44. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js +0 -205
  45. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js.map +0 -1
  46. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js +0 -205
  47. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js.map +0 -1
  48. package/dist-server/server/modules/orchestration/a2a/agent-card.js +0 -50
  49. package/dist-server/server/modules/orchestration/a2a/agent-card.js.map +0 -1
  50. package/dist-server/server/modules/orchestration/a2a/auth.middleware.js +0 -25
  51. package/dist-server/server/modules/orchestration/a2a/auth.middleware.js.map +0 -1
  52. package/dist-server/server/modules/orchestration/a2a/bus.js +0 -34
  53. package/dist-server/server/modules/orchestration/a2a/bus.js.map +0 -1
  54. package/dist-server/server/modules/orchestration/a2a/routes.js +0 -502
  55. package/dist-server/server/modules/orchestration/a2a/routes.js.map +0 -1
  56. package/dist-server/server/modules/orchestration/a2a/task-dispatcher.js +0 -295
  57. package/dist-server/server/modules/orchestration/a2a/task-dispatcher.js.map +0 -1
  58. package/dist-server/server/modules/orchestration/a2a/task-store.js +0 -144
  59. package/dist-server/server/modules/orchestration/a2a/task-store.js.map +0 -1
  60. package/dist-server/server/modules/orchestration/a2a/types.js +0 -6
  61. package/dist-server/server/modules/orchestration/a2a/types.js.map +0 -1
  62. package/dist-server/server/modules/orchestration/a2a/validator.js +0 -101
  63. package/dist-server/server/modules/orchestration/a2a/validator.js.map +0 -1
  64. package/dist-server/server/modules/orchestration/index.js +0 -27
  65. package/dist-server/server/modules/orchestration/index.js.map +0 -1
  66. package/dist-server/server/modules/orchestration/preview/port-watcher.js +0 -90
  67. package/dist-server/server/modules/orchestration/preview/port-watcher.js.map +0 -1
  68. package/dist-server/server/modules/orchestration/preview/preview-proxy.js +0 -58
  69. package/dist-server/server/modules/orchestration/preview/preview-proxy.js.map +0 -1
  70. package/dist-server/server/modules/orchestration/preview/types.js +0 -2
  71. package/dist-server/server/modules/orchestration/preview/types.js.map +0 -1
  72. package/dist-server/server/modules/orchestration/security/permission-policy.js.map +0 -1
  73. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js +0 -34
  74. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js.map +0 -1
  75. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js +0 -70
  76. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js.map +0 -1
  77. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js +0 -181
  78. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js.map +0 -1
  79. package/dist-server/server/modules/orchestration/tasks/orchestration-task.types.js +0 -2
  80. package/dist-server/server/modules/orchestration/tasks/orchestration-task.types.js.map +0 -1
  81. package/dist-server/server/modules/orchestration/tasks/task-run-graph.js +0 -100
  82. package/dist-server/server/modules/orchestration/tasks/task-run-graph.js.map +0 -1
  83. package/dist-server/server/modules/orchestration/workflows/approval-queue.js +0 -72
  84. package/dist-server/server/modules/orchestration/workflows/approval-queue.js.map +0 -1
  85. package/dist-server/server/modules/orchestration/workflows/built-in-workflows.js +0 -126
  86. package/dist-server/server/modules/orchestration/workflows/built-in-workflows.js.map +0 -1
  87. package/dist-server/server/modules/orchestration/workflows/context-packet.js +0 -89
  88. package/dist-server/server/modules/orchestration/workflows/context-packet.js.map +0 -1
  89. package/dist-server/server/modules/orchestration/workflows/handoff-artifact.js +0 -123
  90. package/dist-server/server/modules/orchestration/workflows/handoff-artifact.js.map +0 -1
  91. package/dist-server/server/modules/orchestration/workflows/workflow-fallback-policy.js +0 -114
  92. package/dist-server/server/modules/orchestration/workflows/workflow-fallback-policy.js.map +0 -1
  93. package/dist-server/server/modules/orchestration/workflows/workflow-replay.js +0 -177
  94. package/dist-server/server/modules/orchestration/workflows/workflow-replay.js.map +0 -1
  95. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js +0 -1718
  96. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js.map +0 -1
  97. package/dist-server/server/modules/orchestration/workflows/workflow-store.js +0 -76
  98. package/dist-server/server/modules/orchestration/workflows/workflow-store.js.map +0 -1
  99. package/dist-server/server/modules/orchestration/workflows/workflow-templates.js +0 -242
  100. package/dist-server/server/modules/orchestration/workflows/workflow-templates.js.map +0 -1
  101. package/dist-server/server/modules/orchestration/workflows/workflow-trace.js +0 -388
  102. package/dist-server/server/modules/orchestration/workflows/workflow-trace.js.map +0 -1
  103. package/dist-server/server/modules/orchestration/workflows/workflow.routes.js +0 -508
  104. package/dist-server/server/modules/orchestration/workflows/workflow.routes.js.map +0 -1
  105. package/dist-server/server/modules/orchestration/workflows/workflow.types.js +0 -2
  106. package/dist-server/server/modules/orchestration/workflows/workflow.types.js.map +0 -1
  107. package/dist-server/server/modules/orchestration/workflows/workspace-target.js +0 -100
  108. package/dist-server/server/modules/orchestration/workflows/workspace-target.js.map +0 -1
  109. package/dist-server/server/modules/orchestration/workspace/docker-workspace.js +0 -123
  110. package/dist-server/server/modules/orchestration/workspace/docker-workspace.js.map +0 -1
  111. package/dist-server/server/modules/orchestration/workspace/path-safety.js +0 -48
  112. package/dist-server/server/modules/orchestration/workspace/path-safety.js.map +0 -1
  113. package/dist-server/server/modules/orchestration/workspace/types.js +0 -11
  114. package/dist-server/server/modules/orchestration/workspace/types.js.map +0 -1
  115. package/dist-server/server/modules/orchestration/workspace/workspace-manager.js +0 -84
  116. package/dist-server/server/modules/orchestration/workspace/workspace-manager.js.map +0 -1
  117. package/dist-server/server/modules/orchestration/workspace/worktree-workspace.js +0 -97
  118. package/dist-server/server/modules/orchestration/workspace/worktree-workspace.js.map +0 -1
  119. package/server/modules/orchestration/a2a/adapter-registry.ts +0 -108
  120. package/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.ts +0 -63
  121. package/server/modules/orchestration/a2a/adapters/claude-code.adapter.ts +0 -286
  122. package/server/modules/orchestration/a2a/adapters/codex.adapter.ts +0 -244
  123. package/server/modules/orchestration/a2a/adapters/cursor.adapter.ts +0 -249
  124. package/server/modules/orchestration/a2a/adapters/gemini.adapter.ts +0 -248
  125. package/server/modules/orchestration/a2a/adapters/json-event.adapter.test.ts +0 -60
  126. package/server/modules/orchestration/a2a/adapters/json-event.adapter.ts +0 -101
  127. package/server/modules/orchestration/a2a/adapters/opencode.adapter.ts +0 -248
  128. package/server/modules/orchestration/a2a/adapters/qwen.adapter.ts +0 -248
  129. package/server/modules/orchestration/a2a/agent-card.ts +0 -55
  130. package/server/modules/orchestration/a2a/auth.middleware.ts +0 -29
  131. package/server/modules/orchestration/a2a/bus.ts +0 -46
  132. package/server/modules/orchestration/a2a/routes.ts +0 -586
  133. package/server/modules/orchestration/a2a/task-dispatcher.ts +0 -345
  134. package/server/modules/orchestration/a2a/task-store.ts +0 -178
  135. package/server/modules/orchestration/a2a/types.ts +0 -126
  136. package/server/modules/orchestration/a2a/validator.ts +0 -113
  137. package/server/modules/orchestration/index.ts +0 -99
  138. package/server/modules/orchestration/preview/port-watcher.ts +0 -112
  139. package/server/modules/orchestration/preview/preview-proxy.ts +0 -60
  140. package/server/modules/orchestration/preview/types.ts +0 -19
  141. package/server/modules/orchestration/tasks/orchestration-task-store.ts +0 -41
  142. package/server/modules/orchestration/tasks/orchestration-task.routes.ts +0 -81
  143. package/server/modules/orchestration/tasks/orchestration-task.service.ts +0 -201
  144. package/server/modules/orchestration/tasks/orchestration-task.types.ts +0 -40
  145. package/server/modules/orchestration/tasks/task-run-graph.ts +0 -155
  146. package/server/modules/orchestration/workflows/approval-queue.ts +0 -106
  147. package/server/modules/orchestration/workflows/built-in-workflows.ts +0 -127
  148. package/server/modules/orchestration/workflows/context-packet.ts +0 -186
  149. package/server/modules/orchestration/workflows/handoff-artifact.ts +0 -175
  150. package/server/modules/orchestration/workflows/workflow-fallback-policy.ts +0 -161
  151. package/server/modules/orchestration/workflows/workflow-replay.ts +0 -254
  152. package/server/modules/orchestration/workflows/workflow-runner.ts +0 -2062
  153. package/server/modules/orchestration/workflows/workflow-store.ts +0 -97
  154. package/server/modules/orchestration/workflows/workflow-templates.ts +0 -272
  155. package/server/modules/orchestration/workflows/workflow-trace.ts +0 -424
  156. package/server/modules/orchestration/workflows/workflow.routes.ts +0 -586
  157. package/server/modules/orchestration/workflows/workflow.types.ts +0 -111
  158. package/server/modules/orchestration/workflows/workspace-target.ts +0 -122
  159. package/server/modules/orchestration/workspace/docker-workspace.ts +0 -136
  160. package/server/modules/orchestration/workspace/path-safety.ts +0 -55
  161. package/server/modules/orchestration/workspace/types.ts +0 -52
  162. package/server/modules/orchestration/workspace/workspace-manager.ts +0 -102
  163. package/server/modules/orchestration/workspace/worktree-workspace.ts +0 -126
  164. /package/dist-server/server/modules/{orchestration/security → security}/permission-policy.js +0 -0
  165. /package/server/modules/{orchestration/security → security}/permission-policy.ts +0 -0
@@ -1,345 +0,0 @@
1
- import crypto from 'node:crypto';
2
-
3
- import { adapterRegistry } from '@/modules/orchestration/a2a/adapter-registry.js';
4
- import { a2aBus } from '@/modules/orchestration/a2a/bus.js';
5
- import { a2aTaskStore } from '@/modules/orchestration/a2a/task-store.js';
6
- import type {
7
- BusEvent,
8
- Message,
9
- SubmitTaskInput,
10
- Task,
11
- TaskState,
12
- } from '@/modules/orchestration/a2a/types.js';
13
- import type { TaskHandle } from '@/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js';
14
- import { portWatcher } from '@/modules/orchestration/preview/port-watcher.js';
15
- import type { PreviewArtifactData } from '@/modules/orchestration/preview/types.js';
16
- import {
17
- type PermissionPolicy,
18
- type PermissionPolicyContext,
19
- } from '@/modules/orchestration/security/permission-policy.js';
20
- import { workspaceManager } from '@/modules/orchestration/workspace/workspace-manager.js';
21
- import type {
22
- WorkspaceHandle,
23
- WorkspaceKind,
24
- WorkspaceMetadata,
25
- } from '@/modules/orchestration/workspace/types.js';
26
- import { WorkspaceError } from '@/modules/orchestration/workspace/types.js';
27
-
28
- type RoutingHints = {
29
- preferredAdapterId?: string;
30
- preferredProvider?: string;
31
- preferredSkillId?: string;
32
- };
33
-
34
- const TERMINAL: TaskState[] = ['completed', 'canceled', 'failed'];
35
- const MAX_TASKS = 1000;
36
- const activeWorkspaces = new Map<string, WorkspaceHandle>();
37
- const activeHandles = new Map<string, TaskHandle>();
38
- const previewStops = new Map<string, () => void>();
39
- const taskUnsubs = new Map<string, () => void>();
40
- const finalizingTasks = new Set<string>();
41
-
42
- function newId(prefix: string): string {
43
- return `${prefix}_${crypto.randomBytes(8).toString('hex')}`;
44
- }
45
-
46
- function isTerminalTaskState(state: TaskState): boolean {
47
- return TERMINAL.includes(state);
48
- }
49
-
50
- function readRoutingHints(value: unknown): RoutingHints {
51
- if (!value || typeof value !== 'object') {
52
- return {};
53
- }
54
-
55
- const source = value as Record<string, unknown>;
56
- return {
57
- preferredAdapterId:
58
- typeof source.preferredAdapterId === 'string' ? source.preferredAdapterId : undefined,
59
- preferredProvider:
60
- typeof source.preferredProvider === 'string' ? source.preferredProvider : undefined,
61
- preferredSkillId:
62
- typeof source.preferredSkillId === 'string' ? source.preferredSkillId : undefined,
63
- };
64
- }
65
-
66
- function readString(value: unknown): string | undefined {
67
- return typeof value === 'string' && value.trim() ? value : undefined;
68
- }
69
-
70
- function readBoolean(value: unknown): boolean | undefined {
71
- return typeof value === 'boolean' ? value : undefined;
72
- }
73
-
74
- function readObject(value: unknown): Record<string, unknown> | undefined {
75
- return value && typeof value === 'object' ? value as Record<string, unknown> : undefined;
76
- }
77
-
78
- function readWorkspaceKind(value: unknown): WorkspaceKind | undefined {
79
- return value === 'host' || value === 'worktree' || value === 'docker' ? value : undefined;
80
- }
81
-
82
- function workspaceMetadata(workspace: WorkspaceHandle, keepAfterCompletion?: boolean): WorkspaceMetadata {
83
- return {
84
- id: workspace.id,
85
- kind: workspace.kind,
86
- path: workspace.path,
87
- baseRef: workspace.baseRef,
88
- branchName: workspace.branchName,
89
- keepAfterCompletion,
90
- };
91
- }
92
-
93
- function evictOldestTerminalTask(): boolean {
94
- for (const [taskId, task] of a2aTaskStore.entries()) {
95
- if (!isTerminalTaskState(task.state)) continue;
96
- const unsub = taskUnsubs.get(taskId);
97
- if (unsub) {
98
- unsub();
99
- taskUnsubs.delete(taskId);
100
- }
101
- a2aTaskStore.delete(taskId);
102
- return true;
103
- }
104
- return false;
105
- }
106
-
107
- async function finalizeTerminalTask(task: Task): Promise<void> {
108
- if (finalizingTasks.has(task.id)) return;
109
- finalizingTasks.add(task.id);
110
-
111
- const stopPreview = previewStops.get(task.id);
112
- if (stopPreview) {
113
- stopPreview();
114
- previewStops.delete(task.id);
115
- }
116
-
117
- const workspace = activeWorkspaces.get(task.id);
118
- try {
119
- if (workspace) {
120
- const diff = await workspace.diff();
121
- if (diff.trim()) {
122
- a2aBus.publish({
123
- kind: 'artifact',
124
- taskId: task.id,
125
- artifact: {
126
- artifactId: newId('art'),
127
- type: 'file-diff',
128
- parts: [{ kind: 'text', text: diff }],
129
- metadata: {
130
- source: 'workspace-diff',
131
- workspaceId: workspace.id,
132
- workspaceKind: workspace.kind,
133
- baseRef: workspace.baseRef,
134
- },
135
- },
136
- });
137
- }
138
-
139
- const keepAfterCompletion = task.metadata?.workspace &&
140
- typeof task.metadata.workspace === 'object' &&
141
- readBoolean((task.metadata.workspace as Record<string, unknown>).keepAfterCompletion);
142
- if (workspace.kind !== 'host' && keepAfterCompletion !== true) {
143
- await workspace.destroy();
144
- }
145
- }
146
- } catch (error) {
147
- const message = error instanceof Error ? error.message : String(error);
148
- task.metadata = {
149
- ...task.metadata,
150
- workspaceFinalizationError: message,
151
- };
152
- task.updatedAt = Date.now();
153
- a2aTaskStore.set(task);
154
- } finally {
155
- activeWorkspaces.delete(task.id);
156
- activeHandles.delete(task.id);
157
- const unsub = taskUnsubs.get(task.id);
158
- if (unsub) {
159
- unsub();
160
- taskUnsubs.delete(task.id);
161
- }
162
- finalizingTasks.delete(task.id);
163
- }
164
- }
165
-
166
- function attachBusToTask(task: Task): void {
167
- if (taskUnsubs.has(task.id)) return;
168
-
169
- const unsubscribe = a2aBus.subscribe(task.id, (event: BusEvent) => {
170
- if (event.kind === 'task-state') {
171
- task.state = event.state;
172
- if (event.error) task.error = event.error;
173
- task.updatedAt = Date.now();
174
- a2aTaskStore.set(task);
175
- if (isTerminalTaskState(event.state)) {
176
- void finalizeTerminalTask(task);
177
- }
178
- } else if (event.kind === 'message') {
179
- task.history.push(event.message);
180
- task.updatedAt = Date.now();
181
- a2aTaskStore.set(task);
182
- } else if (event.kind === 'artifact') {
183
- task.artifacts.push(event.artifact);
184
- task.updatedAt = Date.now();
185
- a2aTaskStore.set(task);
186
- }
187
- });
188
- taskUnsubs.set(task.id, unsubscribe);
189
- }
190
-
191
- export function getA2ATask(taskId: string): Task | undefined {
192
- return a2aTaskStore.get(taskId);
193
- }
194
-
195
- export function listA2AAgentCards() {
196
- return adapterRegistry.agentCards();
197
- }
198
-
199
- export async function submitA2ATask(input: SubmitTaskInput): Promise<Task> {
200
- const metadata = input.metadata as Record<string, unknown> | undefined;
201
- const routing = readRoutingHints(metadata?.routing);
202
- const adapter = adapterRegistry.resolve(input.adapterId, routing);
203
- if (!adapter) {
204
- throw new Error(`ADAPTER_NOT_FOUND: ${input.adapterId}`);
205
- }
206
-
207
- if (a2aTaskStore.size >= MAX_TASKS && !evictOldestTerminalTask()) {
208
- throw new Error(`TASK_LIMIT: task store at capacity (${MAX_TASKS})`);
209
- }
210
-
211
- const userMessage: Message = input.message;
212
- const task: Task = {
213
- id: newId('task'),
214
- contextId: input.contextId,
215
- state: 'submitted',
216
- history: [{ ...userMessage, taskId: '' }],
217
- artifacts: [],
218
- metadata: {
219
- ...metadata,
220
- adapterId: adapter.id,
221
- adapterSelector: input.adapterId,
222
- },
223
- createdAt: Date.now(),
224
- updatedAt: Date.now(),
225
- };
226
- task.history[0] = { ...userMessage, taskId: task.id };
227
- a2aTaskStore.set(task);
228
- attachBusToTask(task);
229
-
230
- const workspaceOptions = (metadata?.workspace && typeof metadata.workspace === 'object'
231
- ? metadata.workspace
232
- : {}) as Record<string, unknown>;
233
- let workspace: WorkspaceHandle;
234
- try {
235
- workspace = await workspaceManager.create({
236
- taskId: task.id,
237
- projectPath: readString(workspaceOptions.projectPath) ?? process.cwd(),
238
- kind: readWorkspaceKind(workspaceOptions.kind) ?? readWorkspaceKind(metadata?.isolation),
239
- baseRef: readString(workspaceOptions.baseRef) ?? readString(metadata?.baseRef) ?? 'HEAD',
240
- keepAfterCompletion: readBoolean(workspaceOptions.keepAfterCompletion),
241
- metadata: workspaceOptions,
242
- });
243
- } catch (err) {
244
- const workspaceError = err instanceof WorkspaceError ? err : undefined;
245
- a2aBus.publish({
246
- kind: 'task-state',
247
- taskId: task.id,
248
- state: 'failed',
249
- error: {
250
- code: workspaceError?.code ?? 'WORKSPACE_CREATE_FAILED',
251
- message: err instanceof Error ? err.message : String(err),
252
- details: workspaceError?.details,
253
- },
254
- });
255
- return a2aTaskStore.get(task.id) ?? task;
256
- }
257
-
258
- activeWorkspaces.set(task.id, workspace);
259
- task.metadata = {
260
- ...task.metadata,
261
- workspace: workspaceMetadata(workspace, readBoolean(workspaceOptions.keepAfterCompletion)),
262
- };
263
- task.updatedAt = Date.now();
264
- a2aTaskStore.set(task);
265
-
266
- previewStops.set(
267
- task.id,
268
- portWatcher.watch({
269
- taskId: task.id,
270
- workspace,
271
- onPort: (event) => {
272
- const data: PreviewArtifactData = {
273
- url: event.url,
274
- proxiedUrl: `/preview/${event.port}/`,
275
- port: event.port,
276
- host: event.host,
277
- processName: event.processName,
278
- confidence: event.confidence,
279
- };
280
- a2aBus.publish({
281
- kind: 'artifact',
282
- taskId: task.id,
283
- artifact: {
284
- artifactId: newId('art'),
285
- type: 'preview-url',
286
- parts: [{ kind: 'data', data: { ...data } }],
287
- metadata: {
288
- source: 'port-watcher',
289
- workspaceId: workspace.id,
290
- },
291
- },
292
- });
293
- },
294
- }),
295
- );
296
-
297
- try {
298
- const handle = await adapter.submitTask(task, {
299
- cwd: workspace.path,
300
- workspace,
301
- model: readString(metadata?.model),
302
- permissionMode: readString(metadata?.permissionMode),
303
- permissionPolicy: readObject(metadata?.permissionPolicy) as PermissionPolicy | undefined,
304
- permissionPolicyContext: readObject(metadata?.permissionPolicyContext) as PermissionPolicyContext | undefined,
305
- toolsSettings: readObject(metadata?.toolsSettings),
306
- });
307
- activeHandles.set(task.id, handle);
308
- handle.finished.finally(() => {
309
- activeHandles.delete(task.id);
310
- }).catch(() => undefined);
311
- } catch (err) {
312
- a2aBus.publish({
313
- kind: 'task-state',
314
- taskId: task.id,
315
- state: 'failed',
316
- error: {
317
- code: 'ADAPTER_SUBMIT_FAILED',
318
- message: err instanceof Error ? err.message : String(err),
319
- },
320
- });
321
- }
322
-
323
- return a2aTaskStore.get(task.id) ?? task;
324
- }
325
-
326
- export async function cancelA2ATask(taskId: string, adapterId?: string): Promise<Task | undefined> {
327
- const task = a2aTaskStore.get(taskId);
328
- if (!task) return undefined;
329
-
330
- const handle = activeHandles.get(taskId);
331
- if (handle) {
332
- await handle.cancel();
333
- return a2aTaskStore.get(taskId) ?? task;
334
- }
335
-
336
- const resolvedAdapterId = adapterId ?? readString(task.metadata?.adapterId);
337
- const adapter = resolvedAdapterId ? adapterRegistry.resolve(resolvedAdapterId) : undefined;
338
- if (adapter) {
339
- await adapter.cancelTask(task.id);
340
- return a2aTaskStore.get(task.id) ?? task;
341
- }
342
-
343
- a2aBus.publish({ kind: 'task-state', taskId: task.id, state: 'canceled' });
344
- return a2aTaskStore.get(task.id) ?? task;
345
- }
@@ -1,178 +0,0 @@
1
- // server/modules/orchestration/a2a/task-store.ts
2
- // A2A task persistence backed by shared JsonStore for atomic writes and corruption recovery.
3
- // Exposes a Map-compatible surface (get/set/delete/size/entries/values) so routes.ts
4
- // can treat the store as a typed Map while still benefiting from durable JSON storage.
5
-
6
- import os from 'os';
7
- import path from 'path';
8
-
9
- import { JsonStore } from '@/database/json-store.js';
10
- import type { Message, Task, TaskState, TaskSummary } from '@/modules/orchestration/a2a/types.js';
11
-
12
- const filePath = path.join(os.homedir(), '.pixcode', 'a2a-tasks.json');
13
-
14
- export interface A2ATaskStoreOptions {
15
- terminalTaskTtlMs?: number;
16
- }
17
-
18
- export interface ListOptions {
19
- state?: TaskState;
20
- contextId?: string;
21
- adapterId?: string;
22
- limit?: number;
23
- }
24
-
25
- export class A2ATaskStore {
26
- private store: JsonStore;
27
-
28
- constructor(_options?: A2ATaskStoreOptions) {
29
- this.store = new JsonStore(filePath, { a2a_tasks: [] });
30
- }
31
-
32
- // ── Map-compatible API ─────────────────────────────────────────────────────
33
-
34
- get(id: string): Task | undefined {
35
- return this.store.findWhere('a2a_tasks', (t: Task) => t.id === id) ?? undefined;
36
- }
37
-
38
- set(task: Task): void {
39
- const existing = this.get(task.id);
40
- if (existing) {
41
- this.store.updateWhere('a2a_tasks', (t: Task) => t.id === task.id, task);
42
- } else {
43
- this.store.insert('a2a_tasks', task, { autoId: false });
44
- }
45
- }
46
-
47
- delete(id: string): void {
48
- this.store.deleteWhere('a2a_tasks', (t: Task) => t.id === id);
49
- }
50
-
51
- get size(): number {
52
- return (this.store.filterWhere('a2a_tasks', () => true) as Task[]).length;
53
- }
54
-
55
- *entries(): IterableIterator<[string, Task]> {
56
- const tasks = this.store.filterWhere('a2a_tasks', () => true) as Task[];
57
- for (const task of tasks) {
58
- yield [task.id, task];
59
- }
60
- }
61
-
62
- *values(): IterableIterator<Task> {
63
- const tasks = this.store.filterWhere('a2a_tasks', () => true) as Task[];
64
- for (const task of tasks) {
65
- yield task;
66
- }
67
- }
68
-
69
- // ── Query helpers ──────────────────────────────────────────────────────────
70
-
71
- list(options: ListOptions = {}): Task[] {
72
- const { state, contextId, adapterId, limit = 50 } = options;
73
- let tasks = this.store.filterWhere('a2a_tasks', (t: Task) => {
74
- if (state && t.state !== state) return false;
75
- if (contextId && t.contextId !== contextId) return false;
76
- if (adapterId && (t.metadata?.adapterId as string | undefined) !== adapterId) return false;
77
- return true;
78
- }) as Task[];
79
- if (limit > 0) tasks = tasks.slice(0, limit);
80
- return tasks;
81
- }
82
-
83
- summarize(task: Task): TaskSummary {
84
- return {
85
- id: task.id,
86
- contextId: task.contextId,
87
- state: task.state,
88
- adapterId: task.metadata?.adapterId as string | undefined,
89
- adapterSelector: task.metadata?.adapterSelector as string | undefined,
90
- error: task.error,
91
- createdAt: task.createdAt,
92
- updatedAt: task.updatedAt,
93
- messageCount: task.history?.length ?? 0,
94
- artifactCount: task.artifacts?.length ?? 0,
95
- lastMessage: task.history?.at(-1),
96
- };
97
- }
98
-
99
- // ── Legacy named methods (kept for any future internal callers) ────────────
100
-
101
- getTask(id: string): Task | undefined {
102
- return this.get(id);
103
- }
104
-
105
- getTaskByIndex(index: number): Task | undefined {
106
- const tasks = this.store.filterWhere('a2a_tasks', () => true) as Task[];
107
- return tasks[index] ?? undefined;
108
- }
109
-
110
- getTasks(): Task[] {
111
- return this.store.filterWhere('a2a_tasks', () => true) as Task[];
112
- }
113
-
114
- createTask(task: Task): void {
115
- this.store.insert('a2a_tasks', task, { autoId: false });
116
- }
117
-
118
- updateTask(id: string, updates: Partial<Task>): void {
119
- const existing = this.get(id);
120
- if (!existing) return;
121
- const updated = { ...existing, ...updates, id: existing.id };
122
- this.store.updateWhere('a2a_tasks', (t: Task) => t.id === id, updated);
123
- }
124
-
125
- updateTaskState(id: string, state: TaskState): void {
126
- this.updateTask(id, { status: { state } } as Partial<Task>);
127
- }
128
-
129
- deleteTask(id: string): void {
130
- this.delete(id);
131
- }
132
-
133
- appendHistory(id: string, entry: { state: TaskState; timestamp: string }): void {
134
- const task = this.get(id);
135
- if (!task) return;
136
- const history = [...(task.history ?? []), entry as unknown as Message];
137
- this.updateTask(id, { history } as Partial<Task>);
138
- }
139
-
140
- addArtifact(id: string, artifact: NonNullable<Task['artifacts']>[number]): void {
141
- const task = this.get(id);
142
- if (!task) return;
143
- const artifacts = [...(task.artifacts ?? []), artifact];
144
- this.updateTask(id, { artifacts } as Partial<Task>);
145
- }
146
-
147
- addMessage(id: string, message: Message): void {
148
- const task = this.get(id);
149
- if (!task) return;
150
- const history = [...(task.history ?? []), message];
151
- this.updateTask(id, { history } as Partial<Task>);
152
- }
153
-
154
- updateMessage(id: string, messageId: string, updates: Partial<Message>): void {
155
- const task = this.get(id);
156
- if (!task?.history) return;
157
- const history = task.history.map((m) =>
158
- m.messageId === messageId ? { ...m, ...updates } : m,
159
- );
160
- this.updateTask(id, { history } as Partial<Task>);
161
- }
162
-
163
- getMessage(id: string, messageId: string): Message | undefined {
164
- const task = this.get(id);
165
- return task?.history?.find((m) => m.messageId === messageId);
166
- }
167
-
168
- getMessages(id: string): Message[] {
169
- const task = this.get(id);
170
- return task?.history ?? [];
171
- }
172
-
173
- clearMessages(id: string): void {
174
- this.updateTask(id, { history: [] } as Partial<Task>);
175
- }
176
- }
177
-
178
- export const a2aTaskStore = new A2ATaskStore();
@@ -1,126 +0,0 @@
1
- // server/modules/orchestration/a2a/types.ts
2
- // A2A protocol v0.2 types — minimal surface used by pixcode.
3
- // See https://a2a-protocol.org for the full spec; this file
4
- // keeps only what the orchestrator actually exchanges.
5
-
6
- export type TaskState =
7
- | 'submitted'
8
- | 'working'
9
- | 'input-required'
10
- | 'completed'
11
- | 'canceled'
12
- | 'failed';
13
-
14
- export type Role = 'user' | 'agent';
15
-
16
- export type PartKind = 'text' | 'file' | 'data';
17
-
18
- export interface TextPart {
19
- kind: 'text';
20
- text: string;
21
- }
22
-
23
- export interface FilePart {
24
- kind: 'file';
25
- name: string;
26
- mimeType?: string;
27
- bytesBase64?: string;
28
- uri?: string;
29
- }
30
-
31
- export interface DataPart {
32
- kind: 'data';
33
- data: Record<string, unknown>;
34
- }
35
-
36
- export type Part = TextPart | FilePart | DataPart;
37
-
38
- export interface Message {
39
- messageId: string;
40
- role: Role;
41
- parts: Part[];
42
- /** Required for task-scoped messages. Omit only for broadcast/standalone messages. */
43
- taskId?: string;
44
- }
45
-
46
- export type ArtifactType =
47
- | 'file-diff'
48
- | 'command-output'
49
- | 'preview-url'
50
- | 'handoff-artifact'
51
- | 'data';
52
-
53
- // Note: Artifact and AuthScheme use `type` discriminator (matches A2A
54
- // v0.2 wire format). Part and BusEvent use `kind` per the same spec.
55
- export interface Artifact {
56
- artifactId: string;
57
- type: ArtifactType;
58
- parts: Part[];
59
- metadata?: Record<string, unknown>;
60
- }
61
-
62
- export interface TaskError {
63
- code: string;
64
- message: string;
65
- details?: Record<string, unknown>;
66
- }
67
-
68
- export interface Task {
69
- id: string;
70
- contextId?: string;
71
- state: TaskState;
72
- history: Message[];
73
- artifacts: Artifact[];
74
- error?: TaskError;
75
- metadata?: Record<string, unknown>;
76
- createdAt: number;
77
- updatedAt: number;
78
- }
79
-
80
- export interface TaskSummary {
81
- id: string;
82
- contextId?: string;
83
- state: TaskState;
84
- adapterId?: string;
85
- adapterSelector?: string;
86
- error?: TaskError;
87
- createdAt: number;
88
- updatedAt: number;
89
- messageCount: number;
90
- artifactCount: number;
91
- lastMessage?: Message;
92
- }
93
-
94
- export interface AgentSkill {
95
- id: string;
96
- description: string;
97
- examples?: string[];
98
- }
99
-
100
- export type AuthScheme =
101
- | { type: 'none' }
102
- | { type: 'bearer' }
103
- | { type: 'mtls' };
104
-
105
- export interface AgentCard {
106
- name: string;
107
- description: string;
108
- url: string;
109
- version: string;
110
- capabilities: string[];
111
- skills: AgentSkill[];
112
- authentication: AuthScheme;
113
- }
114
-
115
- export interface SubmitTaskInput {
116
- message: Message;
117
- contextId?: string;
118
- metadata?: Record<string, unknown>;
119
- /** Adapter id, "auto", or "skill:<id>". Resolved by the adapter registry. */
120
- adapterId: string;
121
- }
122
-
123
- export type BusEvent =
124
- | { kind: 'task-state'; taskId: string; state: TaskState; error?: TaskError }
125
- | { kind: 'message'; taskId: string; message: Message }
126
- | { kind: 'artifact'; taskId: string; artifact: Artifact };