@pixelbyte-software/pixcode 1.33.10 → 1.34.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 (75) hide show
  1. package/dist/api-docs.html +395 -395
  2. package/dist/assets/{index-B_dU5AHA.js → index-BvClqlMf.js} +134 -134
  3. package/dist/favicon.svg +8 -8
  4. package/dist/icons/icon-128x128.svg +9 -9
  5. package/dist/icons/icon-144x144.svg +9 -9
  6. package/dist/icons/icon-152x152.svg +9 -9
  7. package/dist/icons/icon-192x192.svg +9 -9
  8. package/dist/icons/icon-384x384.svg +9 -9
  9. package/dist/icons/icon-512x512.svg +9 -9
  10. package/dist/icons/icon-72x72.svg +9 -9
  11. package/dist/icons/icon-96x96.svg +9 -9
  12. package/dist/icons/icon-template.svg +9 -9
  13. package/dist/index.html +1 -1
  14. package/dist/logo.svg +12 -12
  15. package/dist/openapi.yaml +1311 -1311
  16. package/dist-server/server/index.js +4 -0
  17. package/dist-server/server/index.js.map +1 -1
  18. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js +47 -0
  19. package/dist-server/server/modules/orchestration/a2a/adapter-registry.js.map +1 -0
  20. package/dist-server/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js +17 -0
  21. package/dist-server/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js.map +1 -0
  22. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js +233 -0
  23. package/dist-server/server/modules/orchestration/a2a/adapters/claude-code.adapter.js.map +1 -0
  24. package/dist-server/server/modules/orchestration/a2a/agent-card.js +50 -0
  25. package/dist-server/server/modules/orchestration/a2a/agent-card.js.map +1 -0
  26. package/dist-server/server/modules/orchestration/a2a/auth.middleware.js +25 -0
  27. package/dist-server/server/modules/orchestration/a2a/auth.middleware.js.map +1 -0
  28. package/dist-server/server/modules/orchestration/a2a/bus.js +34 -0
  29. package/dist-server/server/modules/orchestration/a2a/bus.js.map +1 -0
  30. package/dist-server/server/modules/orchestration/a2a/routes.js +233 -0
  31. package/dist-server/server/modules/orchestration/a2a/routes.js.map +1 -0
  32. package/dist-server/server/modules/orchestration/a2a/types.js +6 -0
  33. package/dist-server/server/modules/orchestration/a2a/types.js.map +1 -0
  34. package/dist-server/server/modules/orchestration/a2a/validator.js +85 -0
  35. package/dist-server/server/modules/orchestration/a2a/validator.js.map +1 -0
  36. package/dist-server/server/modules/orchestration/index.js +10 -0
  37. package/dist-server/server/modules/orchestration/index.js.map +1 -0
  38. package/dist-server/server/opencode-cli.js +4 -1
  39. package/dist-server/server/opencode-cli.js.map +1 -1
  40. package/package.json +178 -178
  41. package/scripts/smoke/a2a-roundtrip.mjs +98 -0
  42. package/server/database/db.js +794 -794
  43. package/server/database/json-store.js +194 -194
  44. package/server/index.js +9 -0
  45. package/server/modules/orchestration/a2a/adapter-registry.ts +58 -0
  46. package/server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.ts +49 -0
  47. package/server/modules/orchestration/a2a/adapters/claude-code.adapter.ts +283 -0
  48. package/server/modules/orchestration/a2a/agent-card.ts +55 -0
  49. package/server/modules/orchestration/a2a/auth.middleware.ts +29 -0
  50. package/server/modules/orchestration/a2a/bus.ts +46 -0
  51. package/server/modules/orchestration/a2a/routes.ts +264 -0
  52. package/server/modules/orchestration/a2a/types.ts +111 -0
  53. package/server/modules/orchestration/a2a/validator.ts +90 -0
  54. package/server/modules/orchestration/index.ts +26 -0
  55. package/server/modules/providers/list/opencode/opencode-auth.provider.ts +130 -130
  56. package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +126 -126
  57. package/server/modules/providers/list/opencode/opencode-sessions.provider.ts +232 -232
  58. package/server/modules/providers/list/opencode/opencode.provider.ts +29 -29
  59. package/server/modules/providers/list/qwen/qwen-auth.provider.ts +145 -145
  60. package/server/modules/providers/list/qwen/qwen-mcp.provider.ts +114 -114
  61. package/server/modules/providers/list/qwen/qwen-sessions.provider.ts +265 -265
  62. package/server/modules/providers/list/qwen/qwen.provider.ts +21 -21
  63. package/server/modules/providers/shared/provider-configs.ts +142 -142
  64. package/server/opencode-cli.js +4 -1
  65. package/server/opencode-response-handler.js +107 -107
  66. package/server/qwen-code-cli.js +395 -395
  67. package/server/qwen-response-handler.js +73 -73
  68. package/server/routes/qwen.js +27 -27
  69. package/server/services/external-access.js +171 -171
  70. package/server/services/provider-credentials.js +189 -189
  71. package/server/services/provider-models.js +381 -381
  72. package/server/services/telegram/telegram-http-client.js +130 -130
  73. package/server/services/vapid-keys.js +36 -36
  74. package/server/utils/port-access.js +209 -209
  75. package/scripts/rest-sweep.mjs +0 -93
@@ -1,194 +1,194 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- /**
5
- * Minimal JSON-backed store with atomic writes.
6
- *
7
- * Replaces the `better-sqlite3` auth/session/telegram DB from previous
8
- * releases. The backing store is kilobytes, not gigabytes — a SQL engine
9
- * was overkill and the native compile dragged install-time warnings +
10
- * on-disk WAL files that confused users. This impl:
11
- *
12
- * - Loads the entire store into memory on first access (synchronous
13
- * readFileSync) and keeps it cached; all subsequent reads hit the
14
- * in-memory structure.
15
- * - Every write flushes the whole document via write-to-tmp + rename
16
- * so a crash mid-write can never truncate the file; either the
17
- * old file survives or the new one is fully written.
18
- * - All operations are synchronous and rely on Node's single-threaded
19
- * JS execution for concurrency safety. No async queue, no locks.
20
- *
21
- * The schema is a flat object with one array per "table":
22
- * { _version, _sequences: {<table>: nextId}, users: [...], ... }
23
- *
24
- * Callers use helpers like `insert`, `updateWhere`, `findWhere`,
25
- * `deleteWhere` rather than composing queries — this is a key/value map
26
- * with filter helpers, not a SQL engine.
27
- */
28
-
29
- const CURRENT_VERSION = 1;
30
-
31
- // Tables the store manages — empty arrays on a fresh file.
32
- const EMPTY_STORE = () => ({
33
- _version: CURRENT_VERSION,
34
- _sequences: {
35
- users: 0,
36
- api_keys: 0,
37
- user_credentials: 0,
38
- vapid_keys: 0,
39
- push_subscriptions: 0,
40
- },
41
- users: [],
42
- api_keys: [],
43
- user_credentials: [],
44
- user_notification_preferences: [], // each row: { user_id, preferences_json, updated_at }
45
- vapid_keys: [],
46
- push_subscriptions: [],
47
- session_names: [], // each row: { session_id, provider, custom_name, created_at, updated_at }
48
- app_config: [], // each row: { key, value, created_at }
49
- telegram_config: [], // 0 or 1 row: { id=1, bot_token, bot_username, updated_at }
50
- telegram_links: [], // each row: { user_id, chat_id, ... }
51
- });
52
-
53
- export class JsonStore {
54
- constructor(filePath) {
55
- this.filePath = filePath;
56
- this.tmpPath = `${filePath}.tmp`;
57
- this.data = null;
58
- this._ensureLoaded();
59
- }
60
-
61
- _ensureLoaded() {
62
- if (this.data) return;
63
-
64
- // Ensure parent directory exists — matches the old better-sqlite3
65
- // behavior where the directory was created during initialization.
66
- const dir = path.dirname(this.filePath);
67
- if (!fs.existsSync(dir)) {
68
- fs.mkdirSync(dir, { recursive: true });
69
- }
70
-
71
- if (!fs.existsSync(this.filePath)) {
72
- this.data = EMPTY_STORE();
73
- this._flush();
74
- return;
75
- }
76
-
77
- try {
78
- const raw = fs.readFileSync(this.filePath, 'utf8');
79
- const parsed = JSON.parse(raw);
80
- // Fill missing keys from EMPTY_STORE so adding a new "table" in a
81
- // later schema doesn't crash a fresh deploy reading an old file.
82
- this.data = { ...EMPTY_STORE(), ...parsed };
83
- // Ensure each well-known array key is actually an array — defends
84
- // against a hand-edited file that set one to null or an object.
85
- const empty = EMPTY_STORE();
86
- for (const key of Object.keys(empty)) {
87
- if (key === '_version' || key === '_sequences') continue;
88
- if (!Array.isArray(this.data[key])) {
89
- this.data[key] = [];
90
- }
91
- }
92
- this.data._sequences = { ...empty._sequences, ...(parsed._sequences || {}) };
93
- } catch (err) {
94
- // Corrupted file — back up and start fresh. Never hide this; it's
95
- // very likely user-visible (logins will reset).
96
- const backup = `${this.filePath}.corrupt-${Date.now()}`;
97
- console.error(`[JsonStore] Failed to read ${this.filePath}: ${err.message}. Backing up to ${backup}.`);
98
- try { fs.renameSync(this.filePath, backup); } catch { /* noop */ }
99
- this.data = EMPTY_STORE();
100
- this._flush();
101
- }
102
- }
103
-
104
- _flush() {
105
- const serialized = JSON.stringify(this.data, null, 2);
106
- fs.writeFileSync(this.tmpPath, serialized, 'utf8');
107
- fs.renameSync(this.tmpPath, this.filePath);
108
- }
109
-
110
- // ---------- Raw access ----------
111
- get raw() {
112
- this._ensureLoaded();
113
- return this.data;
114
- }
115
-
116
- save() { this._flush(); }
117
-
118
- // ---------- Sequence (AUTOINCREMENT) ----------
119
- nextId(table) {
120
- this._ensureLoaded();
121
- this.data._sequences[table] = (this.data._sequences[table] || 0) + 1;
122
- return this.data._sequences[table];
123
- }
124
-
125
- // ---------- Query helpers ----------
126
- findWhere(table, predicate) {
127
- this._ensureLoaded();
128
- return this.data[table].find(predicate) || null;
129
- }
130
-
131
- filterWhere(table, predicate) {
132
- this._ensureLoaded();
133
- return this.data[table].filter(predicate);
134
- }
135
-
136
- count(table, predicate) {
137
- this._ensureLoaded();
138
- if (!predicate) return this.data[table].length;
139
- return this.data[table].filter(predicate).length;
140
- }
141
-
142
- // ---------- Mutation helpers ----------
143
- insert(table, row, { autoId = true, sequenceKey } = {}) {
144
- this._ensureLoaded();
145
- const finalRow = { ...row };
146
- if (autoId && finalRow.id === undefined) {
147
- finalRow.id = this.nextId(sequenceKey || table);
148
- }
149
- this.data[table].push(finalRow);
150
- this._flush();
151
- return finalRow;
152
- }
153
-
154
- updateWhere(table, predicate, updater) {
155
- this._ensureLoaded();
156
- let changed = 0;
157
- for (const row of this.data[table]) {
158
- if (predicate(row)) {
159
- const patch = typeof updater === 'function' ? updater(row) : updater;
160
- Object.assign(row, patch);
161
- changed += 1;
162
- }
163
- }
164
- if (changed > 0) this._flush();
165
- return changed;
166
- }
167
-
168
- upsertWhere(table, predicate, row) {
169
- this._ensureLoaded();
170
- const existing = this.data[table].find(predicate);
171
- if (existing) {
172
- Object.assign(existing, row);
173
- this._flush();
174
- return existing;
175
- }
176
- return this.insert(table, row);
177
- }
178
-
179
- deleteWhere(table, predicate) {
180
- this._ensureLoaded();
181
- const before = this.data[table].length;
182
- this.data[table] = this.data[table].filter((row) => !predicate(row));
183
- const removed = before - this.data[table].length;
184
- if (removed > 0) this._flush();
185
- return removed;
186
- }
187
- }
188
-
189
- /**
190
- * Helper — ISO timestamp matching the DATETIME format SQLite used to
191
- * write. Stored as a plain ISO string; no one actually parses it beyond
192
- * displaying "last login X hours ago".
193
- */
194
- export const nowIso = () => new Date().toISOString();
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ /**
5
+ * Minimal JSON-backed store with atomic writes.
6
+ *
7
+ * Replaces the `better-sqlite3` auth/session/telegram DB from previous
8
+ * releases. The backing store is kilobytes, not gigabytes — a SQL engine
9
+ * was overkill and the native compile dragged install-time warnings +
10
+ * on-disk WAL files that confused users. This impl:
11
+ *
12
+ * - Loads the entire store into memory on first access (synchronous
13
+ * readFileSync) and keeps it cached; all subsequent reads hit the
14
+ * in-memory structure.
15
+ * - Every write flushes the whole document via write-to-tmp + rename
16
+ * so a crash mid-write can never truncate the file; either the
17
+ * old file survives or the new one is fully written.
18
+ * - All operations are synchronous and rely on Node's single-threaded
19
+ * JS execution for concurrency safety. No async queue, no locks.
20
+ *
21
+ * The schema is a flat object with one array per "table":
22
+ * { _version, _sequences: {<table>: nextId}, users: [...], ... }
23
+ *
24
+ * Callers use helpers like `insert`, `updateWhere`, `findWhere`,
25
+ * `deleteWhere` rather than composing queries — this is a key/value map
26
+ * with filter helpers, not a SQL engine.
27
+ */
28
+
29
+ const CURRENT_VERSION = 1;
30
+
31
+ // Tables the store manages — empty arrays on a fresh file.
32
+ const EMPTY_STORE = () => ({
33
+ _version: CURRENT_VERSION,
34
+ _sequences: {
35
+ users: 0,
36
+ api_keys: 0,
37
+ user_credentials: 0,
38
+ vapid_keys: 0,
39
+ push_subscriptions: 0,
40
+ },
41
+ users: [],
42
+ api_keys: [],
43
+ user_credentials: [],
44
+ user_notification_preferences: [], // each row: { user_id, preferences_json, updated_at }
45
+ vapid_keys: [],
46
+ push_subscriptions: [],
47
+ session_names: [], // each row: { session_id, provider, custom_name, created_at, updated_at }
48
+ app_config: [], // each row: { key, value, created_at }
49
+ telegram_config: [], // 0 or 1 row: { id=1, bot_token, bot_username, updated_at }
50
+ telegram_links: [], // each row: { user_id, chat_id, ... }
51
+ });
52
+
53
+ export class JsonStore {
54
+ constructor(filePath) {
55
+ this.filePath = filePath;
56
+ this.tmpPath = `${filePath}.tmp`;
57
+ this.data = null;
58
+ this._ensureLoaded();
59
+ }
60
+
61
+ _ensureLoaded() {
62
+ if (this.data) return;
63
+
64
+ // Ensure parent directory exists — matches the old better-sqlite3
65
+ // behavior where the directory was created during initialization.
66
+ const dir = path.dirname(this.filePath);
67
+ if (!fs.existsSync(dir)) {
68
+ fs.mkdirSync(dir, { recursive: true });
69
+ }
70
+
71
+ if (!fs.existsSync(this.filePath)) {
72
+ this.data = EMPTY_STORE();
73
+ this._flush();
74
+ return;
75
+ }
76
+
77
+ try {
78
+ const raw = fs.readFileSync(this.filePath, 'utf8');
79
+ const parsed = JSON.parse(raw);
80
+ // Fill missing keys from EMPTY_STORE so adding a new "table" in a
81
+ // later schema doesn't crash a fresh deploy reading an old file.
82
+ this.data = { ...EMPTY_STORE(), ...parsed };
83
+ // Ensure each well-known array key is actually an array — defends
84
+ // against a hand-edited file that set one to null or an object.
85
+ const empty = EMPTY_STORE();
86
+ for (const key of Object.keys(empty)) {
87
+ if (key === '_version' || key === '_sequences') continue;
88
+ if (!Array.isArray(this.data[key])) {
89
+ this.data[key] = [];
90
+ }
91
+ }
92
+ this.data._sequences = { ...empty._sequences, ...(parsed._sequences || {}) };
93
+ } catch (err) {
94
+ // Corrupted file — back up and start fresh. Never hide this; it's
95
+ // very likely user-visible (logins will reset).
96
+ const backup = `${this.filePath}.corrupt-${Date.now()}`;
97
+ console.error(`[JsonStore] Failed to read ${this.filePath}: ${err.message}. Backing up to ${backup}.`);
98
+ try { fs.renameSync(this.filePath, backup); } catch { /* noop */ }
99
+ this.data = EMPTY_STORE();
100
+ this._flush();
101
+ }
102
+ }
103
+
104
+ _flush() {
105
+ const serialized = JSON.stringify(this.data, null, 2);
106
+ fs.writeFileSync(this.tmpPath, serialized, 'utf8');
107
+ fs.renameSync(this.tmpPath, this.filePath);
108
+ }
109
+
110
+ // ---------- Raw access ----------
111
+ get raw() {
112
+ this._ensureLoaded();
113
+ return this.data;
114
+ }
115
+
116
+ save() { this._flush(); }
117
+
118
+ // ---------- Sequence (AUTOINCREMENT) ----------
119
+ nextId(table) {
120
+ this._ensureLoaded();
121
+ this.data._sequences[table] = (this.data._sequences[table] || 0) + 1;
122
+ return this.data._sequences[table];
123
+ }
124
+
125
+ // ---------- Query helpers ----------
126
+ findWhere(table, predicate) {
127
+ this._ensureLoaded();
128
+ return this.data[table].find(predicate) || null;
129
+ }
130
+
131
+ filterWhere(table, predicate) {
132
+ this._ensureLoaded();
133
+ return this.data[table].filter(predicate);
134
+ }
135
+
136
+ count(table, predicate) {
137
+ this._ensureLoaded();
138
+ if (!predicate) return this.data[table].length;
139
+ return this.data[table].filter(predicate).length;
140
+ }
141
+
142
+ // ---------- Mutation helpers ----------
143
+ insert(table, row, { autoId = true, sequenceKey } = {}) {
144
+ this._ensureLoaded();
145
+ const finalRow = { ...row };
146
+ if (autoId && finalRow.id === undefined) {
147
+ finalRow.id = this.nextId(sequenceKey || table);
148
+ }
149
+ this.data[table].push(finalRow);
150
+ this._flush();
151
+ return finalRow;
152
+ }
153
+
154
+ updateWhere(table, predicate, updater) {
155
+ this._ensureLoaded();
156
+ let changed = 0;
157
+ for (const row of this.data[table]) {
158
+ if (predicate(row)) {
159
+ const patch = typeof updater === 'function' ? updater(row) : updater;
160
+ Object.assign(row, patch);
161
+ changed += 1;
162
+ }
163
+ }
164
+ if (changed > 0) this._flush();
165
+ return changed;
166
+ }
167
+
168
+ upsertWhere(table, predicate, row) {
169
+ this._ensureLoaded();
170
+ const existing = this.data[table].find(predicate);
171
+ if (existing) {
172
+ Object.assign(existing, row);
173
+ this._flush();
174
+ return existing;
175
+ }
176
+ return this.insert(table, row);
177
+ }
178
+
179
+ deleteWhere(table, predicate) {
180
+ this._ensureLoaded();
181
+ const before = this.data[table].length;
182
+ this.data[table] = this.data[table].filter((row) => !predicate(row));
183
+ const removed = before - this.data[table].length;
184
+ if (removed > 0) this._flush();
185
+ return removed;
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Helper — ISO timestamp matching the DATETIME format SQLite used to
191
+ * write. Stored as a plain ISO string; no one actually parses it beyond
192
+ * displaying "last login X hours ago".
193
+ */
194
+ export const nowIso = () => new Date().toISOString();
package/server/index.js CHANGED
@@ -71,6 +71,11 @@ import qwenRoutes from './routes/qwen.js';
71
71
  import pluginsRoutes from './routes/plugins.js';
72
72
  import messagesRoutes from './routes/messages.js';
73
73
  import providerRoutes from './modules/providers/provider.routes.js';
74
+ import {
75
+ createA2ARouter,
76
+ adapterRegistry,
77
+ ClaudeCodeA2AAdapter,
78
+ } from './modules/orchestration/index.js';
74
79
  import networkRoutes from './routes/network.js';
75
80
  import telegramRoutes from './routes/telegram.js';
76
81
  import { restoreBotFromConfig } from './services/telegram/bot.js';
@@ -376,6 +381,10 @@ app.use('/api/sessions', authenticateToken, messagesRoutes);
376
381
  // Unified provider MCP routes (protected)
377
382
  app.use('/api/providers', authenticateToken, providerRoutes);
378
383
 
384
+ // A2A protocol router — has its own auth middleware, do NOT wrap with authenticateToken
385
+ adapterRegistry.register(new ClaudeCodeA2AAdapter());
386
+ app.use('/a2a', createA2ARouter());
387
+
379
388
  // Network discovery / QR endpoints (protected)
380
389
  app.use('/api/network', authenticateToken, networkRoutes);
381
390
 
@@ -0,0 +1,58 @@
1
+ // server/modules/orchestration/a2a/adapter-registry.ts
2
+ // In-process registry mapping adapter ids to AbstractA2AAdapter
3
+ // instances. Resolution supports three id forms:
4
+ // - "claude-code" explicit
5
+ // - "skill:<skillId>" first REGISTERED adapter advertising that skill
6
+ // (Map iteration is insertion-ordered per ES spec).
7
+ // - "auto" first registered adapter (placeholder until
8
+ // AI-suggested routing arrives in a later plan)
9
+
10
+ import type { AbstractA2AAdapter } from '@/modules/orchestration/a2a/adapters/abstract-a2a.adapter.js';
11
+ import type { AgentCard } from '@/modules/orchestration/a2a/types.js';
12
+
13
+ class AdapterRegistry {
14
+ // Map iteration order is insertion-ordered (ES spec); auto and skill: resolution depend on this.
15
+ private readonly byId = new Map<string, AbstractA2AAdapter>();
16
+
17
+ register(adapter: AbstractA2AAdapter): void {
18
+ if (this.byId.has(adapter.id)) {
19
+ throw new Error(`A2A adapter already registered: ${adapter.id}`);
20
+ }
21
+ this.byId.set(adapter.id, adapter);
22
+ }
23
+
24
+ get(idOrSelector: string): AbstractA2AAdapter | undefined {
25
+ if (idOrSelector === 'auto') {
26
+ if (this.byId.size > 1) {
27
+ throw new Error(
28
+ 'A2A adapter selector "auto" is not yet implemented for multi-adapter registries. ' +
29
+ 'Pass an explicit adapter id ("claude-code") or a "skill:<id>" selector. ' +
30
+ 'AI-suggested routing will replace this stub in a later plan.',
31
+ );
32
+ }
33
+ const first = this.byId.values().next().value;
34
+ return first ?? undefined;
35
+ }
36
+ if (idOrSelector.startsWith('skill:')) {
37
+ const skill = idOrSelector.slice('skill:'.length);
38
+ for (const adapter of this.byId.values()) {
39
+ if (adapter.agentCard.skills.some((s) => s.id === skill)) {
40
+ return adapter;
41
+ }
42
+ }
43
+ return undefined;
44
+ }
45
+ return this.byId.get(idOrSelector);
46
+ }
47
+
48
+ list(): AbstractA2AAdapter[] {
49
+ return [...this.byId.values()];
50
+ }
51
+
52
+ agentCards(): AgentCard[] {
53
+ return this.list().map((a) => a.agentCard);
54
+ }
55
+ }
56
+
57
+ export const adapterRegistry = new AdapterRegistry();
58
+ export type { AdapterRegistry };
@@ -0,0 +1,49 @@
1
+ // server/modules/orchestration/a2a/adapters/abstract-a2a.adapter.ts
2
+ // Base class every CLI adapter extends. Adapters wrap the
3
+ // existing per-CLI runtime files (claude-sdk.js, openai-codex.js, ...)
4
+ // and translate between A2A messages and the CLI's native I/O.
5
+
6
+ import { a2aBus } from '@/modules/orchestration/a2a/bus.js';
7
+ import type {
8
+ AgentCard,
9
+ Artifact,
10
+ Message,
11
+ Task,
12
+ TaskError,
13
+ TaskState,
14
+ } from '@/modules/orchestration/a2a/types.js';
15
+
16
+ export interface AdapterContext {
17
+ /** Where the adapter executes — for now this is the project cwd; a future
18
+ * plan introduces WorkspaceHandle (worktree / docker). */
19
+ cwd: string;
20
+ /** pixcode permission mode passed through to the underlying CLI. */
21
+ permissionMode?: 'acceptEdits' | 'plan' | 'bypassPermissions' | 'default';
22
+ /** Optional parent task id when this adapter is invoked inside a workflow. */
23
+ parentTaskId?: string;
24
+ }
25
+
26
+ export interface TaskHandle {
27
+ cancel(): Promise<void>;
28
+ finished: Promise<void>;
29
+ }
30
+
31
+ export abstract class AbstractA2AAdapter {
32
+ abstract readonly id: string;
33
+ abstract readonly agentCard: AgentCard;
34
+
35
+ abstract submitTask(task: Task, ctx: AdapterContext): Promise<TaskHandle>;
36
+ abstract cancelTask(taskId: string): Promise<void>;
37
+
38
+ protected emitState(taskId: string, state: TaskState, error?: TaskError): void {
39
+ a2aBus.publish({ kind: 'task-state', taskId, state, error });
40
+ }
41
+
42
+ protected emitMessage(taskId: string, message: Message): void {
43
+ a2aBus.publish({ kind: 'message', taskId, message });
44
+ }
45
+
46
+ protected emitArtifact(taskId: string, artifact: Artifact): void {
47
+ a2aBus.publish({ kind: 'artifact', taskId, artifact });
48
+ }
49
+ }