@pixelbyte-software/pixcode 1.34.0 → 1.35.0

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 (155) hide show
  1. package/dist/api-docs.html +162 -9
  2. package/dist/assets/index-B8w57E1r.css +32 -0
  3. package/dist/assets/index-Djuh0wHV.js +854 -0
  4. package/dist/favicon.svg +8 -8
  5. package/dist/icons/icon-128x128.svg +9 -9
  6. package/dist/icons/icon-144x144.svg +9 -9
  7. package/dist/icons/icon-152x152.svg +9 -9
  8. package/dist/icons/icon-192x192.svg +9 -9
  9. package/dist/icons/icon-384x384.svg +9 -9
  10. package/dist/icons/icon-512x512.svg +9 -9
  11. package/dist/icons/icon-72x72.svg +9 -9
  12. package/dist/icons/icon-96x96.svg +9 -9
  13. package/dist/icons/icon-template.svg +9 -9
  14. package/dist/index.html +2 -2
  15. package/dist/logo.svg +12 -12
  16. package/dist/openapi.yaml +383 -1
  17. package/dist-server/server/claude-sdk.js +38 -7
  18. package/dist-server/server/claude-sdk.js.map +1 -1
  19. package/dist-server/server/cli.js +12 -17
  20. package/dist-server/server/cli.js.map +1 -1
  21. package/dist-server/server/daemon-manager.js +98 -51
  22. package/dist-server/server/daemon-manager.js.map +1 -1
  23. package/dist-server/server/database/json-store.js +8 -5
  24. package/dist-server/server/database/json-store.js.map +1 -1
  25. package/dist-server/server/index.js +31 -10
  26. package/dist-server/server/index.js.map +1 -1
  27. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js +45 -19
  28. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js.map +1 -1
  29. package/dist-server/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js.map +1 -1
  30. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js +1 -0
  31. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js.map +1 -1
  32. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js +202 -0
  33. package/dist-server/server/modules/orchestration/a2a/adapters/codex.adapter.js.map +1 -0
  34. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js +205 -0
  35. package/dist-server/server/modules/orchestration/a2a/adapters/cursor.adapter.js.map +1 -0
  36. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js +205 -0
  37. package/dist-server/server/modules/orchestration/a2a/adapters/gemini.adapter.js.map +1 -0
  38. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js +205 -0
  39. package/dist-server/server/modules/orchestration/a2a/adapters/opencode.adapter.js.map +1 -0
  40. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js +205 -0
  41. package/dist-server/server/modules/orchestration/a2a/adapters/qwen.adapter.js.map +1 -0
  42. package/dist-server/server/modules/orchestration/a2a/routes.js +298 -34
  43. package/dist-server/server/modules/orchestration/a2a/routes.js.map +1 -1
  44. package/dist-server/server/modules/orchestration/a2a/task-store.js +144 -0
  45. package/dist-server/server/modules/orchestration/a2a/task-store.js.map +1 -0
  46. package/dist-server/server/modules/orchestration/a2a/validator.js +16 -0
  47. package/dist-server/server/modules/orchestration/a2a/validator.js.map +1 -1
  48. package/dist-server/server/modules/orchestration/index.js +14 -0
  49. package/dist-server/server/modules/orchestration/index.js.map +1 -1
  50. package/dist-server/server/modules/orchestration/preview/port-watcher.js +90 -0
  51. package/dist-server/server/modules/orchestration/preview/port-watcher.js.map +1 -0
  52. package/dist-server/server/modules/orchestration/preview/preview-proxy.js +58 -0
  53. package/dist-server/server/modules/orchestration/preview/preview-proxy.js.map +1 -0
  54. package/dist-server/server/modules/orchestration/preview/types.js +2 -0
  55. package/dist-server/server/modules/orchestration/preview/types.js.map +1 -0
  56. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js +37 -0
  57. package/dist-server/server/modules/orchestration/tasks/orchestration-task-store.js.map +1 -0
  58. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js +68 -0
  59. package/dist-server/server/modules/orchestration/tasks/orchestration-task.routes.js.map +1 -0
  60. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js +128 -0
  61. package/dist-server/server/modules/orchestration/tasks/orchestration-task.service.js.map +1 -0
  62. package/dist-server/server/modules/orchestration/tasks/orchestration-task.types.js +2 -0
  63. package/dist-server/server/modules/orchestration/tasks/orchestration-task.types.js.map +1 -0
  64. package/dist-server/server/modules/orchestration/workflows/built-in-workflows.js +126 -0
  65. package/dist-server/server/modules/orchestration/workflows/built-in-workflows.js.map +1 -0
  66. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js +1047 -0
  67. package/dist-server/server/modules/orchestration/workflows/workflow-runner.js.map +1 -0
  68. package/dist-server/server/modules/orchestration/workflows/workflow-store.js +76 -0
  69. package/dist-server/server/modules/orchestration/workflows/workflow-store.js.map +1 -0
  70. package/dist-server/server/modules/orchestration/workflows/workflow.routes.js +151 -0
  71. package/dist-server/server/modules/orchestration/workflows/workflow.routes.js.map +1 -0
  72. package/dist-server/server/modules/orchestration/workflows/workflow.types.js +2 -0
  73. package/dist-server/server/modules/orchestration/workflows/workflow.types.js.map +1 -0
  74. package/dist-server/server/modules/orchestration/workflows/workspace-target.js +98 -0
  75. package/dist-server/server/modules/orchestration/workflows/workspace-target.js.map +1 -0
  76. package/dist-server/server/modules/orchestration/workspace/docker-workspace.js +122 -0
  77. package/dist-server/server/modules/orchestration/workspace/docker-workspace.js.map +1 -0
  78. package/dist-server/server/modules/orchestration/workspace/path-safety.js +48 -0
  79. package/dist-server/server/modules/orchestration/workspace/path-safety.js.map +1 -0
  80. package/dist-server/server/modules/orchestration/workspace/types.js +11 -0
  81. package/dist-server/server/modules/orchestration/workspace/types.js.map +1 -0
  82. package/dist-server/server/modules/orchestration/workspace/workspace-manager.js +80 -0
  83. package/dist-server/server/modules/orchestration/workspace/workspace-manager.js.map +1 -0
  84. package/dist-server/server/modules/orchestration/workspace/worktree-workspace.js +96 -0
  85. package/dist-server/server/modules/orchestration/workspace/worktree-workspace.js.map +1 -0
  86. package/dist-server/server/modules/providers/index.js +3 -0
  87. package/dist-server/server/modules/providers/index.js.map +1 -0
  88. package/dist-server/server/openai-codex.js +35 -4
  89. package/dist-server/server/openai-codex.js.map +1 -1
  90. package/dist-server/server/routes/taskmaster.js +106 -89
  91. package/dist-server/server/routes/taskmaster.js.map +1 -1
  92. package/package.json +3 -1
  93. package/scripts/smoke/a2a-roundtrip.mjs +167 -98
  94. package/scripts/smoke/orchestration-api.mjs +172 -0
  95. package/scripts/smoke/orchestration-live-run.mjs +176 -0
  96. package/server/claude-sdk.js +48 -7
  97. package/server/cli.js +12 -17
  98. package/server/daemon-manager.js +90 -51
  99. package/server/database/db.js +794 -794
  100. package/server/database/json-store.js +8 -5
  101. package/server/index.js +40 -9
  102. package/server/modules/orchestration/a2a/adapter-registry.ts +108 -58
  103. package/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.ts +55 -49
  104. package/server/modules/orchestration/a2a/adapters/claude-code.adapter.ts +284 -283
  105. package/server/modules/orchestration/a2a/adapters/codex.adapter.ts +244 -0
  106. package/server/modules/orchestration/a2a/adapters/cursor.adapter.ts +249 -0
  107. package/server/modules/orchestration/a2a/adapters/gemini.adapter.ts +248 -0
  108. package/server/modules/orchestration/a2a/adapters/opencode.adapter.ts +248 -0
  109. package/server/modules/orchestration/a2a/adapters/qwen.adapter.ts +248 -0
  110. package/server/modules/orchestration/a2a/agent-card.ts +55 -55
  111. package/server/modules/orchestration/a2a/auth.middleware.ts +29 -29
  112. package/server/modules/orchestration/a2a/bus.ts +46 -46
  113. package/server/modules/orchestration/a2a/routes.ts +577 -264
  114. package/server/modules/orchestration/a2a/task-store.ts +178 -0
  115. package/server/modules/orchestration/a2a/types.ts +125 -111
  116. package/server/modules/orchestration/a2a/validator.ts +113 -90
  117. package/server/modules/orchestration/index.ts +66 -26
  118. package/server/modules/orchestration/preview/port-watcher.ts +112 -0
  119. package/server/modules/orchestration/preview/preview-proxy.ts +60 -0
  120. package/server/modules/orchestration/preview/types.ts +19 -0
  121. package/server/modules/orchestration/tasks/orchestration-task-store.ts +45 -0
  122. package/server/modules/orchestration/tasks/orchestration-task.routes.ts +73 -0
  123. package/server/modules/orchestration/tasks/orchestration-task.service.ts +145 -0
  124. package/server/modules/orchestration/tasks/orchestration-task.types.ts +29 -0
  125. package/server/modules/orchestration/workflows/built-in-workflows.ts +127 -0
  126. package/server/modules/orchestration/workflows/workflow-runner.ts +1206 -0
  127. package/server/modules/orchestration/workflows/workflow-store.ts +97 -0
  128. package/server/modules/orchestration/workflows/workflow.routes.ts +169 -0
  129. package/server/modules/orchestration/workflows/workflow.types.ts +70 -0
  130. package/server/modules/orchestration/workflows/workspace-target.ts +120 -0
  131. package/server/modules/orchestration/workspace/docker-workspace.ts +135 -0
  132. package/server/modules/orchestration/workspace/path-safety.ts +55 -0
  133. package/server/modules/orchestration/workspace/types.ts +52 -0
  134. package/server/modules/orchestration/workspace/workspace-manager.ts +97 -0
  135. package/server/modules/orchestration/workspace/worktree-workspace.ts +125 -0
  136. package/server/modules/providers/index.ts +2 -0
  137. package/server/modules/providers/list/opencode/opencode-auth.provider.ts +130 -130
  138. package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +126 -126
  139. package/server/modules/providers/list/opencode/opencode.provider.ts +29 -29
  140. package/server/modules/providers/list/qwen/qwen-auth.provider.ts +145 -145
  141. package/server/modules/providers/list/qwen/qwen-mcp.provider.ts +114 -114
  142. package/server/modules/providers/list/qwen/qwen.provider.ts +21 -21
  143. package/server/modules/providers/shared/provider-configs.ts +142 -142
  144. package/server/openai-codex.js +40 -4
  145. package/server/qwen-code-cli.js +395 -395
  146. package/server/qwen-response-handler.js +73 -73
  147. package/server/routes/qwen.js +27 -27
  148. package/server/routes/taskmaster.js +116 -91
  149. package/server/services/external-access.js +171 -171
  150. package/server/services/provider-models.js +381 -381
  151. package/server/services/telegram/telegram-http-client.js +130 -130
  152. package/server/services/vapid-keys.js +36 -36
  153. package/server/utils/port-access.js +209 -209
  154. package/dist/assets/index-B1ghfb4w.css +0 -32
  155. package/dist/assets/index-BvClqlMf.js +0 -852
@@ -0,0 +1,178 @@
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,111 +1,125 @@
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
- | 'data';
51
-
52
- // Note: Artifact and AuthScheme use `type` discriminator (matches A2A
53
- // v0.2 wire format). Part and BusEvent use `kind` per the same spec.
54
- export interface Artifact {
55
- artifactId: string;
56
- type: ArtifactType;
57
- parts: Part[];
58
- metadata?: Record<string, unknown>;
59
- }
60
-
61
- export interface TaskError {
62
- code: string;
63
- message: string;
64
- details?: Record<string, unknown>;
65
- }
66
-
67
- export interface Task {
68
- id: string;
69
- contextId?: string;
70
- state: TaskState;
71
- history: Message[];
72
- artifacts: Artifact[];
73
- error?: TaskError;
74
- metadata?: Record<string, unknown>;
75
- createdAt: number;
76
- updatedAt: number;
77
- }
78
-
79
- export interface AgentSkill {
80
- id: string;
81
- description: string;
82
- examples?: string[];
83
- }
84
-
85
- export type AuthScheme =
86
- | { type: 'none' }
87
- | { type: 'bearer' }
88
- | { type: 'mtls' };
89
-
90
- export interface AgentCard {
91
- name: string;
92
- description: string;
93
- url: string;
94
- version: string;
95
- capabilities: string[];
96
- skills: AgentSkill[];
97
- authentication: AuthScheme;
98
- }
99
-
100
- export interface SubmitTaskInput {
101
- message: Message;
102
- contextId?: string;
103
- metadata?: Record<string, unknown>;
104
- /** Adapter id, "auto", or "skill:<id>". Resolved by the adapter registry. */
105
- adapterId: string;
106
- }
107
-
108
- export type BusEvent =
109
- | { kind: 'task-state'; taskId: string; state: TaskState; error?: TaskError }
110
- | { kind: 'message'; taskId: string; message: Message }
111
- | { kind: 'artifact'; taskId: string; artifact: Artifact };
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
+ | 'data';
51
+
52
+ // Note: Artifact and AuthScheme use `type` discriminator (matches A2A
53
+ // v0.2 wire format). Part and BusEvent use `kind` per the same spec.
54
+ export interface Artifact {
55
+ artifactId: string;
56
+ type: ArtifactType;
57
+ parts: Part[];
58
+ metadata?: Record<string, unknown>;
59
+ }
60
+
61
+ export interface TaskError {
62
+ code: string;
63
+ message: string;
64
+ details?: Record<string, unknown>;
65
+ }
66
+
67
+ export interface Task {
68
+ id: string;
69
+ contextId?: string;
70
+ state: TaskState;
71
+ history: Message[];
72
+ artifacts: Artifact[];
73
+ error?: TaskError;
74
+ metadata?: Record<string, unknown>;
75
+ createdAt: number;
76
+ updatedAt: number;
77
+ }
78
+
79
+ export interface TaskSummary {
80
+ id: string;
81
+ contextId?: string;
82
+ state: TaskState;
83
+ adapterId?: string;
84
+ adapterSelector?: string;
85
+ error?: TaskError;
86
+ createdAt: number;
87
+ updatedAt: number;
88
+ messageCount: number;
89
+ artifactCount: number;
90
+ lastMessage?: Message;
91
+ }
92
+
93
+ export interface AgentSkill {
94
+ id: string;
95
+ description: string;
96
+ examples?: string[];
97
+ }
98
+
99
+ export type AuthScheme =
100
+ | { type: 'none' }
101
+ | { type: 'bearer' }
102
+ | { type: 'mtls' };
103
+
104
+ export interface AgentCard {
105
+ name: string;
106
+ description: string;
107
+ url: string;
108
+ version: string;
109
+ capabilities: string[];
110
+ skills: AgentSkill[];
111
+ authentication: AuthScheme;
112
+ }
113
+
114
+ export interface SubmitTaskInput {
115
+ message: Message;
116
+ contextId?: string;
117
+ metadata?: Record<string, unknown>;
118
+ /** Adapter id, "auto", or "skill:<id>". Resolved by the adapter registry. */
119
+ adapterId: string;
120
+ }
121
+
122
+ export type BusEvent =
123
+ | { kind: 'task-state'; taskId: string; state: TaskState; error?: TaskError }
124
+ | { kind: 'message'; taskId: string; message: Message }
125
+ | { kind: 'artifact'; taskId: string; artifact: Artifact };
@@ -1,90 +1,113 @@
1
- // server/modules/orchestration/a2a/validator.ts
2
- // Hand-written validators for incoming A2A payloads.
3
- // We deliberately avoid adding a new dep (zod, ajv) for the
4
- // foundation; a follow-on plan can swap to a schema lib if needed.
5
- //
6
- // All path strings use JSONPath-style "$" as the document root so
7
- // callers can map errors to wire-payload locations consistently.
8
-
9
- import type { AgentCard, DataPart, FilePart, Message, Part, SubmitTaskInput, TextPart } from '@/modules/orchestration/a2a/types.js';
10
-
11
- export class A2AValidationError extends Error {
12
- constructor(message: string, public readonly path: string) {
13
- super(`${path}: ${message}`);
14
- this.name = 'A2AValidationError';
15
- }
16
- }
17
-
18
- function assertNonEmptyString(value: unknown, path: string): asserts value is string {
19
- if (typeof value !== 'string' || value.length === 0) {
20
- throw new A2AValidationError('expected non-empty string', path);
21
- }
22
- }
23
-
24
- function assertPart(value: unknown, path: string): asserts value is Part {
25
- if (!value || typeof value !== 'object') {
26
- throw new A2AValidationError('expected object', path);
27
- }
28
- const part = value as { kind?: unknown };
29
- if (part.kind === 'text') {
30
- assertNonEmptyString((part as Partial<TextPart>).text, `${path}.text`);
31
- return;
32
- }
33
- if (part.kind === 'file') {
34
- assertNonEmptyString((part as Partial<FilePart>).name, `${path}.name`);
35
- return;
36
- }
37
- if (part.kind === 'data') {
38
- const data = (part as Partial<DataPart>).data;
39
- if (!data || typeof data !== 'object' || Array.isArray(data)) {
40
- throw new A2AValidationError('data must be a plain object', `${path}.data`);
41
- }
42
- return;
43
- }
44
- throw new A2AValidationError('part.kind must be text|file|data', `${path}.kind`);
45
- }
46
-
47
- export function assertMessage(value: unknown, path = '$'): asserts value is Message {
48
- if (!value || typeof value !== 'object') {
49
- throw new A2AValidationError('expected object', path);
50
- }
51
- const m = value as { messageId?: unknown; role?: unknown; parts?: unknown };
52
- assertNonEmptyString(m.messageId, `${path}.messageId`);
53
- if (m.role !== 'user' && m.role !== 'agent') {
54
- throw new A2AValidationError('role must be user|agent', `${path}.role`);
55
- }
56
- if (!Array.isArray(m.parts) || m.parts.length === 0) {
57
- throw new A2AValidationError('parts must be non-empty array', `${path}.parts`);
58
- }
59
- m.parts.forEach((p, i) => assertPart(p, `${path}.parts[${i}]`));
60
- }
61
-
62
- export function assertSubmitTaskInput(value: unknown): asserts value is SubmitTaskInput {
63
- if (!value || typeof value !== 'object') {
64
- throw new A2AValidationError('expected object', '$');
65
- }
66
- const v = value as { message?: unknown; adapterId?: unknown };
67
- assertMessage(v.message, '$.message');
68
- assertNonEmptyString(v.adapterId, '$.adapterId');
69
- }
70
-
71
- export function assertAgentCard(value: unknown): asserts value is AgentCard {
72
- if (!value || typeof value !== 'object') {
73
- throw new A2AValidationError('expected object', '$');
74
- }
75
- const card = value as Partial<AgentCard>;
76
- assertNonEmptyString(card.name, '$.name');
77
- assertNonEmptyString(card.description, '$.description');
78
- assertNonEmptyString(card.url, '$.url');
79
- assertNonEmptyString(card.version, '$.version');
80
- if (!Array.isArray(card.capabilities)) {
81
- throw new A2AValidationError('capabilities must be array', '$.capabilities');
82
- }
83
- if (!Array.isArray(card.skills)) {
84
- throw new A2AValidationError('skills must be array', '$.skills');
85
- }
86
- card.skills.forEach((s, i) => {
87
- assertNonEmptyString(s.id, `$.skills[${i}].id`);
88
- assertNonEmptyString(s.description, `$.skills[${i}].description`);
89
- });
90
- }
1
+ // server/modules/orchestration/a2a/validator.ts
2
+ // Hand-written validators for incoming A2A payloads.
3
+ // We deliberately avoid adding a new dep (zod, ajv) for the
4
+ // foundation; a follow-on plan can swap to a schema lib if needed.
5
+ //
6
+ // All path strings use JSONPath-style "$" as the document root so
7
+ // callers can map errors to wire-payload locations consistently.
8
+
9
+ import type { AgentCard, DataPart, FilePart, Message, Part, SubmitTaskInput, TextPart } from '@/modules/orchestration/a2a/types.js';
10
+
11
+ export class A2AValidationError extends Error {
12
+ constructor(message: string, public readonly path: string) {
13
+ super(`${path}: ${message}`);
14
+ this.name = 'A2AValidationError';
15
+ }
16
+ }
17
+
18
+ function assertNonEmptyString(value: unknown, path: string): asserts value is string {
19
+ if (typeof value !== 'string' || value.length === 0) {
20
+ throw new A2AValidationError('expected non-empty string', path);
21
+ }
22
+ }
23
+
24
+ function assertOptionalNonEmptyString(value: unknown, path: string): void {
25
+ if (value === undefined) {
26
+ return;
27
+ }
28
+ assertNonEmptyString(value, path);
29
+ }
30
+
31
+ function assertPlainObject(value: unknown, path: string): void {
32
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
33
+ throw new A2AValidationError('expected plain object', path);
34
+ }
35
+ }
36
+
37
+ function assertPart(value: unknown, path: string): asserts value is Part {
38
+ if (!value || typeof value !== 'object') {
39
+ throw new A2AValidationError('expected object', path);
40
+ }
41
+ const part = value as { kind?: unknown };
42
+ if (part.kind === 'text') {
43
+ assertNonEmptyString((part as Partial<TextPart>).text, `${path}.text`);
44
+ return;
45
+ }
46
+ if (part.kind === 'file') {
47
+ assertNonEmptyString((part as Partial<FilePart>).name, `${path}.name`);
48
+ return;
49
+ }
50
+ if (part.kind === 'data') {
51
+ const data = (part as Partial<DataPart>).data;
52
+ if (!data || typeof data !== 'object' || Array.isArray(data)) {
53
+ throw new A2AValidationError('data must be a plain object', `${path}.data`);
54
+ }
55
+ return;
56
+ }
57
+ throw new A2AValidationError('part.kind must be text|file|data', `${path}.kind`);
58
+ }
59
+
60
+ export function assertMessage(value: unknown, path = '$'): asserts value is Message {
61
+ if (!value || typeof value !== 'object') {
62
+ throw new A2AValidationError('expected object', path);
63
+ }
64
+ const m = value as { messageId?: unknown; role?: unknown; parts?: unknown; taskId?: unknown };
65
+ assertNonEmptyString(m.messageId, `${path}.messageId`);
66
+ if (m.role !== 'user' && m.role !== 'agent') {
67
+ throw new A2AValidationError('role must be user|agent', `${path}.role`);
68
+ }
69
+ if (!Array.isArray(m.parts) || m.parts.length === 0) {
70
+ throw new A2AValidationError('parts must be non-empty array', `${path}.parts`);
71
+ }
72
+ assertOptionalNonEmptyString(m.taskId, `${path}.taskId`);
73
+ m.parts.forEach((p, i) => assertPart(p, `${path}.parts[${i}]`));
74
+ }
75
+
76
+ export function assertSubmitTaskInput(value: unknown): asserts value is SubmitTaskInput {
77
+ if (!value || typeof value !== 'object') {
78
+ throw new A2AValidationError('expected object', '$');
79
+ }
80
+ const v = value as {
81
+ message?: unknown;
82
+ adapterId?: unknown;
83
+ contextId?: unknown;
84
+ metadata?: unknown;
85
+ };
86
+ assertMessage(v.message, '$.message');
87
+ assertNonEmptyString(v.adapterId, '$.adapterId');
88
+ assertOptionalNonEmptyString(v.contextId, '$.contextId');
89
+ if (v.metadata !== undefined) {
90
+ assertPlainObject(v.metadata, '$.metadata');
91
+ }
92
+ }
93
+
94
+ export function assertAgentCard(value: unknown): asserts value is AgentCard {
95
+ if (!value || typeof value !== 'object') {
96
+ throw new A2AValidationError('expected object', '$');
97
+ }
98
+ const card = value as Partial<AgentCard>;
99
+ assertNonEmptyString(card.name, '$.name');
100
+ assertNonEmptyString(card.description, '$.description');
101
+ assertNonEmptyString(card.url, '$.url');
102
+ assertNonEmptyString(card.version, '$.version');
103
+ if (!Array.isArray(card.capabilities)) {
104
+ throw new A2AValidationError('capabilities must be array', '$.capabilities');
105
+ }
106
+ if (!Array.isArray(card.skills)) {
107
+ throw new A2AValidationError('skills must be array', '$.skills');
108
+ }
109
+ card.skills.forEach((s, i) => {
110
+ assertNonEmptyString(s.id, `$.skills[${i}].id`);
111
+ assertNonEmptyString(s.description, `$.skills[${i}].description`);
112
+ });
113
+ }