@awcp/sdk 0.0.0-dev-202601300724

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 (69) hide show
  1. package/dist/delegator/admission.d.ts +49 -0
  2. package/dist/delegator/admission.d.ts.map +1 -0
  3. package/dist/delegator/admission.js +117 -0
  4. package/dist/delegator/admission.js.map +1 -0
  5. package/dist/delegator/bin/client.d.ts +102 -0
  6. package/dist/delegator/bin/client.d.ts.map +1 -0
  7. package/dist/delegator/bin/client.js +116 -0
  8. package/dist/delegator/bin/client.js.map +1 -0
  9. package/dist/delegator/bin/daemon.d.ts +78 -0
  10. package/dist/delegator/bin/daemon.d.ts.map +1 -0
  11. package/dist/delegator/bin/daemon.js +245 -0
  12. package/dist/delegator/bin/daemon.js.map +1 -0
  13. package/dist/delegator/config.d.ts +168 -0
  14. package/dist/delegator/config.d.ts.map +1 -0
  15. package/dist/delegator/config.js +54 -0
  16. package/dist/delegator/config.js.map +1 -0
  17. package/dist/delegator/executor-client.d.ts +36 -0
  18. package/dist/delegator/executor-client.d.ts.map +1 -0
  19. package/dist/delegator/executor-client.js +77 -0
  20. package/dist/delegator/executor-client.js.map +1 -0
  21. package/dist/delegator/export-view.d.ts +43 -0
  22. package/dist/delegator/export-view.d.ts.map +1 -0
  23. package/dist/delegator/export-view.js +108 -0
  24. package/dist/delegator/export-view.js.map +1 -0
  25. package/dist/delegator/index.d.ts +8 -0
  26. package/dist/delegator/index.d.ts.map +1 -0
  27. package/dist/delegator/index.js +11 -0
  28. package/dist/delegator/index.js.map +1 -0
  29. package/dist/delegator/service.d.ts +120 -0
  30. package/dist/delegator/service.d.ts.map +1 -0
  31. package/dist/delegator/service.js +323 -0
  32. package/dist/delegator/service.js.map +1 -0
  33. package/dist/executor/config.d.ts +126 -0
  34. package/dist/executor/config.d.ts.map +1 -0
  35. package/dist/executor/config.js +38 -0
  36. package/dist/executor/config.js.map +1 -0
  37. package/dist/executor/delegator-client.d.ts +18 -0
  38. package/dist/executor/delegator-client.d.ts.map +1 -0
  39. package/dist/executor/delegator-client.js +37 -0
  40. package/dist/executor/delegator-client.js.map +1 -0
  41. package/dist/executor/index.d.ts +5 -0
  42. package/dist/executor/index.d.ts.map +1 -0
  43. package/dist/executor/index.js +7 -0
  44. package/dist/executor/index.js.map +1 -0
  45. package/dist/executor/policy.d.ts +55 -0
  46. package/dist/executor/policy.d.ts.map +1 -0
  47. package/dist/executor/policy.js +100 -0
  48. package/dist/executor/policy.js.map +1 -0
  49. package/dist/executor/service.d.ts +84 -0
  50. package/dist/executor/service.d.ts.map +1 -0
  51. package/dist/executor/service.js +322 -0
  52. package/dist/executor/service.js.map +1 -0
  53. package/dist/index.d.ts +9 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +28 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/server/express/awcp-delegator-handler.d.ts +67 -0
  58. package/dist/server/express/awcp-delegator-handler.d.ts.map +1 -0
  59. package/dist/server/express/awcp-delegator-handler.js +99 -0
  60. package/dist/server/express/awcp-delegator-handler.js.map +1 -0
  61. package/dist/server/express/awcp-executor-handler.d.ts +47 -0
  62. package/dist/server/express/awcp-executor-handler.d.ts.map +1 -0
  63. package/dist/server/express/awcp-executor-handler.js +104 -0
  64. package/dist/server/express/awcp-executor-handler.js.map +1 -0
  65. package/dist/server/express/index.d.ts +6 -0
  66. package/dist/server/express/index.d.ts.map +1 -0
  67. package/dist/server/express/index.js +8 -0
  68. package/dist/server/express/index.js.map +1 -0
  69. package/package.json +69 -0
@@ -0,0 +1,322 @@
1
+ /**
2
+ * AWCP Executor Service
3
+ *
4
+ * Handles the AWCP delegation protocol on the Executor (Collaborator) side.
5
+ * Integrates with A2A SDK executor for task execution.
6
+ */
7
+ import { randomUUID } from 'node:crypto';
8
+ import { DefaultExecutionEventBus, } from '@a2a-js/sdk/server';
9
+ import { SshfsMountClient } from '@awcp/transport-sshfs';
10
+ import { PROTOCOL_VERSION, ErrorCodes, AwcpError, } from '@awcp/core';
11
+ import { resolveExecutorConfig } from './config.js';
12
+ import { LocalPolicy } from './policy.js';
13
+ import { DelegatorClient } from './delegator-client.js';
14
+ /**
15
+ * AWCP Executor Service
16
+ *
17
+ * Manages the AWCP delegation lifecycle:
18
+ * 1. Receives INVITE from Delegator
19
+ * 2. Sends ACCEPT back
20
+ * 3. Receives START with credentials
21
+ * 4. Mounts workspace via SSHFS
22
+ * 5. Executes task via A2A executor
23
+ * 6. Unmounts and sends DONE/ERROR
24
+ */
25
+ export class ExecutorService {
26
+ executor;
27
+ config;
28
+ policy;
29
+ sshfsClient;
30
+ delegatorClient;
31
+ pendingInvitations = new Map();
32
+ activeDelegations = new Map();
33
+ constructor(options) {
34
+ this.executor = options.executor;
35
+ this.config = resolveExecutorConfig(options.config);
36
+ this.policy = new LocalPolicy({
37
+ mountRoot: this.config.mount.root,
38
+ maxConcurrent: this.config.policy.maxConcurrentDelegations,
39
+ });
40
+ this.sshfsClient = new SshfsMountClient();
41
+ this.delegatorClient = new DelegatorClient();
42
+ }
43
+ /**
44
+ * Handle incoming AWCP message from Delegator
45
+ */
46
+ async handleMessage(message, delegatorUrl) {
47
+ switch (message.type) {
48
+ case 'INVITE':
49
+ return this.handleInvite(message, delegatorUrl);
50
+ case 'START':
51
+ await this.handleStart(message, delegatorUrl);
52
+ return null;
53
+ case 'ERROR':
54
+ await this.handleError(message);
55
+ return null;
56
+ default:
57
+ throw new Error(`Unexpected message type: ${message.type}`);
58
+ }
59
+ }
60
+ /**
61
+ * Handle INVITE message
62
+ */
63
+ async handleInvite(invite, delegatorUrl) {
64
+ const { delegationId } = invite;
65
+ // Check if we can accept more delegations
66
+ if (!this.policy.canAcceptMore()) {
67
+ return this.createErrorMessage(delegationId, ErrorCodes.DECLINED, 'Maximum concurrent delegations reached', 'Try again later when current tasks complete');
68
+ }
69
+ // Check TTL constraints
70
+ const maxTtl = this.config.policy.maxTtlSeconds;
71
+ if (invite.lease.ttlSeconds > maxTtl) {
72
+ return this.createErrorMessage(delegationId, ErrorCodes.DECLINED, `Requested TTL (${invite.lease.ttlSeconds}s) exceeds maximum (${maxTtl}s)`, `Request a shorter TTL (max: ${maxTtl}s)`);
73
+ }
74
+ // Check access mode
75
+ const allowedModes = this.config.policy.allowedAccessModes;
76
+ if (!allowedModes.includes(invite.lease.accessMode)) {
77
+ return this.createErrorMessage(delegationId, ErrorCodes.DECLINED, `Access mode '${invite.lease.accessMode}' not allowed`, `Allowed modes: ${allowedModes.join(', ')}`);
78
+ }
79
+ // Check dependencies
80
+ const depCheck = await this.sshfsClient.checkDependency();
81
+ if (!depCheck.available) {
82
+ return this.createErrorMessage(delegationId, ErrorCodes.DEP_MISSING, 'SSHFS is not available', 'Install sshfs: brew install macfuse && brew install sshfs (macOS) or apt install sshfs (Linux)');
83
+ }
84
+ // Call onInvite hook if provided
85
+ if (this.config.hooks.onInvite) {
86
+ const accepted = await this.config.hooks.onInvite(invite);
87
+ if (!accepted) {
88
+ return this.createErrorMessage(delegationId, ErrorCodes.DECLINED, 'Invitation declined by policy', 'The agent declined this delegation request');
89
+ }
90
+ }
91
+ else if (!this.config.policy.autoAccept) {
92
+ // No hook and not auto-accept - store as pending
93
+ this.pendingInvitations.set(delegationId, {
94
+ invite,
95
+ delegatorUrl,
96
+ receivedAt: new Date(),
97
+ });
98
+ // For now, we'll auto-decline if not auto-accept and no hook
99
+ return this.createErrorMessage(delegationId, ErrorCodes.DECLINED, 'Manual acceptance required but no hook provided', 'Configure autoAccept: true or provide onInvite hook');
100
+ }
101
+ // Allocate mount point
102
+ const mountPoint = this.policy.allocateMountPoint(delegationId);
103
+ // Validate mount point
104
+ const validation = await this.policy.validateMountPoint(mountPoint);
105
+ if (!validation.valid) {
106
+ await this.policy.releaseMountPoint(mountPoint);
107
+ return this.createErrorMessage(delegationId, ErrorCodes.MOUNTPOINT_DENIED, validation.reason ?? 'Mount point validation failed', 'Check mount root configuration');
108
+ }
109
+ // Store pending invitation
110
+ this.pendingInvitations.set(delegationId, {
111
+ invite,
112
+ delegatorUrl,
113
+ receivedAt: new Date(),
114
+ });
115
+ // Build executor constraints
116
+ const executorConstraints = {
117
+ acceptedAccessMode: invite.lease.accessMode,
118
+ maxTtlSeconds: Math.min(invite.lease.ttlSeconds, maxTtl),
119
+ sandboxProfile: this.config.sandbox,
120
+ };
121
+ // Return ACCEPT
122
+ const acceptMessage = {
123
+ version: PROTOCOL_VERSION,
124
+ type: 'ACCEPT',
125
+ delegationId,
126
+ executorMount: { mountPoint },
127
+ executorConstraints,
128
+ };
129
+ return acceptMessage;
130
+ }
131
+ /**
132
+ * Handle START message
133
+ */
134
+ async handleStart(start, delegatorUrl) {
135
+ const { delegationId } = start;
136
+ const pending = this.pendingInvitations.get(delegationId);
137
+ if (!pending) {
138
+ console.warn(`[AWCP] Unknown delegation for START: ${delegationId}`);
139
+ return;
140
+ }
141
+ const mountPoint = this.policy.allocateMountPoint(delegationId);
142
+ this.pendingInvitations.delete(delegationId);
143
+ try {
144
+ // Prepare mount point
145
+ await this.policy.prepareMountPoint(mountPoint);
146
+ // Mount the workspace
147
+ await this.sshfsClient.mount({
148
+ endpoint: start.mount.endpoint,
149
+ exportLocator: start.mount.exportLocator,
150
+ credential: start.mount.credential,
151
+ mountPoint,
152
+ options: start.mount.mountOptions,
153
+ });
154
+ // Track active delegation
155
+ this.activeDelegations.set(delegationId, {
156
+ id: delegationId,
157
+ delegatorUrl,
158
+ mountPoint,
159
+ task: pending.invite.task,
160
+ startedAt: new Date(),
161
+ });
162
+ // Call onTaskStart hook
163
+ this.config.hooks.onTaskStart?.(delegationId, mountPoint);
164
+ // Execute task via A2A executor
165
+ const result = await this.executeViaA2A(mountPoint, pending.invite.task);
166
+ // Unmount
167
+ await this.sshfsClient.unmount(mountPoint);
168
+ // Send DONE
169
+ const doneMessage = {
170
+ version: PROTOCOL_VERSION,
171
+ type: 'DONE',
172
+ delegationId,
173
+ finalSummary: result.summary,
174
+ highlights: result.highlights,
175
+ };
176
+ await this.delegatorClient.send(delegatorUrl, doneMessage);
177
+ // Call onTaskComplete hook
178
+ this.config.hooks.onTaskComplete?.(delegationId, result.summary);
179
+ // Cleanup
180
+ this.activeDelegations.delete(delegationId);
181
+ await this.policy.releaseMountPoint(mountPoint);
182
+ }
183
+ catch (error) {
184
+ // Cleanup on error
185
+ await this.sshfsClient.unmount(mountPoint).catch(() => { });
186
+ this.activeDelegations.delete(delegationId);
187
+ await this.policy.releaseMountPoint(mountPoint);
188
+ // Send ERROR
189
+ const errorMessage = {
190
+ version: PROTOCOL_VERSION,
191
+ type: 'ERROR',
192
+ delegationId,
193
+ code: ErrorCodes.TASK_FAILED,
194
+ message: error instanceof Error ? error.message : String(error),
195
+ hint: 'Check task requirements and try again',
196
+ };
197
+ await this.delegatorClient.send(delegatorUrl, errorMessage).catch(console.error);
198
+ // Call onError hook
199
+ this.config.hooks.onError?.(delegationId, error instanceof Error ? error : new Error(String(error)));
200
+ }
201
+ }
202
+ /**
203
+ * Handle ERROR message from Delegator
204
+ */
205
+ async handleError(error) {
206
+ const { delegationId } = error;
207
+ // Cleanup if we have an active delegation
208
+ const delegation = this.activeDelegations.get(delegationId);
209
+ if (delegation) {
210
+ await this.sshfsClient.unmount(delegation.mountPoint).catch(() => { });
211
+ this.activeDelegations.delete(delegationId);
212
+ await this.policy.releaseMountPoint(delegation.mountPoint);
213
+ }
214
+ // Remove pending invitation if any
215
+ this.pendingInvitations.delete(delegationId);
216
+ // Call onError hook
217
+ this.config.hooks.onError?.(delegationId, new AwcpError(error.code, error.message, error.hint, delegationId));
218
+ }
219
+ /**
220
+ * Cancel a delegation (called by Delegator via /cancel endpoint)
221
+ */
222
+ async cancelDelegation(delegationId) {
223
+ const delegation = this.activeDelegations.get(delegationId);
224
+ if (delegation) {
225
+ await this.sshfsClient.unmount(delegation.mountPoint).catch(() => { });
226
+ this.activeDelegations.delete(delegationId);
227
+ await this.policy.releaseMountPoint(delegation.mountPoint);
228
+ this.config.hooks.onError?.(delegationId, new AwcpError(ErrorCodes.CANCELLED, 'Delegation cancelled by Delegator', undefined, delegationId));
229
+ return;
230
+ }
231
+ if (this.pendingInvitations.has(delegationId)) {
232
+ this.pendingInvitations.delete(delegationId);
233
+ return;
234
+ }
235
+ throw new Error(`Delegation not found: ${delegationId}`);
236
+ }
237
+ /**
238
+ * Execute task via A2A executor
239
+ */
240
+ async executeViaA2A(mountPoint, task) {
241
+ // Create synthetic A2A message with task context
242
+ const message = {
243
+ kind: 'message',
244
+ messageId: randomUUID(),
245
+ role: 'user',
246
+ parts: [
247
+ { kind: 'text', text: task.prompt },
248
+ {
249
+ kind: 'text',
250
+ text: `\n\n[AWCP Context]\nWorking directory: ${mountPoint}\nTask: ${task.description}`,
251
+ },
252
+ ],
253
+ };
254
+ // Create request context
255
+ const taskId = randomUUID();
256
+ const contextId = randomUUID();
257
+ const requestContext = new RequestContextImpl(message, taskId, contextId);
258
+ // Create event bus and collect results
259
+ const eventBus = new DefaultExecutionEventBus();
260
+ const results = [];
261
+ eventBus.on('event', (event) => {
262
+ if (event.kind === 'message') {
263
+ results.push(event);
264
+ }
265
+ });
266
+ // Execute
267
+ await this.executor.execute(requestContext, eventBus);
268
+ // Extract summary from results
269
+ const summary = results
270
+ .flatMap((m) => m.parts)
271
+ .filter((p) => p.kind === 'text')
272
+ .map((p) => p.text)
273
+ .join('\n');
274
+ return {
275
+ summary: summary || 'Task completed',
276
+ };
277
+ }
278
+ /**
279
+ * Get service status
280
+ */
281
+ getStatus() {
282
+ return {
283
+ pendingInvitations: this.pendingInvitations.size,
284
+ activeDelegations: this.activeDelegations.size,
285
+ delegations: Array.from(this.activeDelegations.values()).map((d) => ({
286
+ id: d.id,
287
+ mountPoint: d.mountPoint,
288
+ startedAt: d.startedAt.toISOString(),
289
+ })),
290
+ };
291
+ }
292
+ /**
293
+ * Create an error message
294
+ */
295
+ createErrorMessage(delegationId, code, message, hint) {
296
+ return {
297
+ version: PROTOCOL_VERSION,
298
+ type: 'ERROR',
299
+ delegationId,
300
+ code,
301
+ message,
302
+ hint,
303
+ };
304
+ }
305
+ }
306
+ /**
307
+ * Simple RequestContext implementation
308
+ */
309
+ class RequestContextImpl {
310
+ userMessage;
311
+ taskId;
312
+ contextId;
313
+ task;
314
+ referenceTasks;
315
+ context;
316
+ constructor(userMessage, taskId, contextId) {
317
+ this.userMessage = userMessage;
318
+ this.taskId = taskId;
319
+ this.contextId = contextId;
320
+ }
321
+ }
322
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/executor/service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,wBAAwB,GAGzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EASL,gBAAgB,EAChB,UAAU,EACV,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAoD,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA6CxD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,eAAe;IAClB,QAAQ,CAAgB;IACxB,MAAM,CAAyB;IAC/B,MAAM,CAAc;IACpB,WAAW,CAAmB;IAC9B,eAAe,CAAkB;IACjC,kBAAkB,GAAG,IAAI,GAAG,EAA6B,CAAC;IAC1D,iBAAiB,GAAG,IAAI,GAAG,EAA4B,CAAC;IAEhE,YAAY,OAA+B;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,qBAAqB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC;YAC5B,SAAS,EAAE,IAAI,CAA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AC9C,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACnE,EAAE,EAAE,CAAC,CAAC,EAAE;gBACR,UAAU,EAAE,CAAC,CAAC,UAAU;gBACxB,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE;aACrC,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,kBAAkB,CACxB,YAAoB,EACpB,IAAY,EACZ,OAAe,EACf,IAAa;QAEb,OAAO;YACL,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE,OAAO;YACb,YAAY;YACZ,IAAI;YACJ,OAAO;YACP,IAAI;SACL,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,kBAAkB;IACb,WAAW,CAAU;IACrB,MAAM,CAAS;IACf,SAAS,CAAS;IAClB,IAAI,CAAa;IACjB,cAAc,CAAa;IAC3B,OAAO,CAAa;IAE7B,YAAY,WAAoB,EAAE,MAAc,EAAE,SAAiB;QACjE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @awcp/sdk
3
+ *
4
+ * AWCP SDK - Delegator and Executor implementations
5
+ */
6
+ export { DelegatorService, type DelegatorServiceOptions, type DelegateParams, type DelegatorServiceStatus, type DelegatorConfig, type SshConfig, type DelegationDefaults, type DelegatorHooks, startDelegatorDaemon, DelegatorDaemonClient, type DaemonConfig, type DaemonInstance, type DelegateRequest, type DelegateResponse, type ListDelegationsResponse, AdmissionController, type AdmissionConfig, type AdmissionResult, type WorkspaceStats, ExportViewManager, ExecutorClient, } from './delegator/index.js';
7
+ export { ExecutorService, type ExecutorServiceOptions, type ExecutorServiceStatus, type ExecutorConfig, type MountConfig, type PolicyConstraints, type ExecutorHooks, LocalPolicy, type PolicyConfig, type MountPointValidation, DelegatorClient, } from './executor/index.js';
8
+ export * from '@awcp/core';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAEL,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAE3B,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,cAAc,EAEnB,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,mBAAmB,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,iBAAiB,EACjB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAEL,eAAe,EACf,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAE1B,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAElB,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAM7B,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @awcp/sdk
3
+ *
4
+ * AWCP SDK - Delegator and Executor implementations
5
+ */
6
+ // ============================================
7
+ // Delegator API (for creating delegations)
8
+ // ============================================
9
+ export {
10
+ // Service
11
+ DelegatorService,
12
+ // Daemon mode
13
+ startDelegatorDaemon, DelegatorDaemonClient,
14
+ // Utilities
15
+ AdmissionController, ExportViewManager, ExecutorClient, } from './delegator/index.js';
16
+ // ============================================
17
+ // Executor API (for executing delegations)
18
+ // ============================================
19
+ export {
20
+ // Service
21
+ ExecutorService,
22
+ // Utilities
23
+ LocalPolicy, DelegatorClient, } from './executor/index.js';
24
+ // ============================================
25
+ // Re-export core types for convenience
26
+ // ============================================
27
+ export * from '@awcp/core';
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+CAA+C;AAC/C,2CAA2C;AAC3C,+CAA+C;AAE/C,OAAO;AACL,UAAU;AACV,gBAAgB;AAShB,cAAc;AACd,oBAAoB,EACpB,qBAAqB;AAMrB,YAAY;AACZ,mBAAmB,EAInB,iBAAiB,EACjB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,+CAA+C;AAC/C,2CAA2C;AAC3C,+CAA+C;AAE/C,OAAO;AACL,UAAU;AACV,eAAe;AAQf,YAAY;AACZ,WAAW,EAGX,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAE7B,+CAA+C;AAC/C,uCAAuC;AACvC,+CAA+C;AAE/C,cAAc,YAAY,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * AWCP Delegator Express Handler
3
+ *
4
+ * Express middleware for enabling AWCP Delegator functionality.
5
+ * This handler receives ACCEPT/DONE/ERROR messages from Executor.
6
+ */
7
+ import { Router } from 'express';
8
+ import type { DelegatorConfig } from '../../delegator/config.js';
9
+ import { DelegatorService } from '../../delegator/service.js';
10
+ /**
11
+ * Options for the AWCP Delegator Express handler
12
+ */
13
+ export interface DelegatorHandlerOptions {
14
+ /**
15
+ * AWCP Delegator configuration
16
+ */
17
+ config: DelegatorConfig;
18
+ /**
19
+ * Callback URL where this handler is mounted
20
+ *
21
+ * This URL is sent to Executor in the X-AWCP-Callback-URL header
22
+ * so Executor knows where to send ACCEPT/DONE/ERROR messages.
23
+ *
24
+ * Example: 'http://localhost:3000/awcp'
25
+ */
26
+ callbackUrl: string;
27
+ }
28
+ /**
29
+ * Result of creating the handler
30
+ */
31
+ export interface DelegatorHandlerResult {
32
+ /** Express router to mount */
33
+ router: Router;
34
+ /** Service instance for creating delegations */
35
+ service: DelegatorService;
36
+ }
37
+ /**
38
+ * Create an Express router that handles AWCP Delegator messages
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import express from 'express';
43
+ * import { delegatorHandler } from '@awcp/sdk/server/express';
44
+ *
45
+ * const app = express();
46
+ *
47
+ * const { router, service } = delegatorHandler({
48
+ * config: {
49
+ * export: { baseDir: '/tmp/awcp/exports' },
50
+ * ssh: { host: 'localhost', user: 'myuser' },
51
+ * },
52
+ * callbackUrl: 'http://localhost:3000/awcp',
53
+ * });
54
+ *
55
+ * // Mount the router
56
+ * app.use('/awcp', router);
57
+ *
58
+ * // Use the service to create delegations
59
+ * const delegationId = await service.delegate({
60
+ * executorUrl: 'http://executor-agent:4001/awcp',
61
+ * localDir: '/path/to/project',
62
+ * task: { description: 'Fix bug', prompt: '...' },
63
+ * });
64
+ * ```
65
+ */
66
+ export declare function delegatorHandler(options: DelegatorHandlerOptions): DelegatorHandlerResult;
67
+ //# sourceMappingURL=awcp-delegator-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awcp-delegator-handler.d.ts","sourceRoot":"","sources":["../../../src/server/express/awcp-delegator-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAQ,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,MAAM,EAAE,eAAe,CAAC;IAExB;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,sBAAsB,CAkEzF"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * AWCP Delegator Express Handler
3
+ *
4
+ * Express middleware for enabling AWCP Delegator functionality.
5
+ * This handler receives ACCEPT/DONE/ERROR messages from Executor.
6
+ */
7
+ import { Router, json } from 'express';
8
+ import { DelegatorService } from '../../delegator/service.js';
9
+ /**
10
+ * Create an Express router that handles AWCP Delegator messages
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import express from 'express';
15
+ * import { delegatorHandler } from '@awcp/sdk/server/express';
16
+ *
17
+ * const app = express();
18
+ *
19
+ * const { router, service } = delegatorHandler({
20
+ * config: {
21
+ * export: { baseDir: '/tmp/awcp/exports' },
22
+ * ssh: { host: 'localhost', user: 'myuser' },
23
+ * },
24
+ * callbackUrl: 'http://localhost:3000/awcp',
25
+ * });
26
+ *
27
+ * // Mount the router
28
+ * app.use('/awcp', router);
29
+ *
30
+ * // Use the service to create delegations
31
+ * const delegationId = await service.delegate({
32
+ * executorUrl: 'http://executor-agent:4001/awcp',
33
+ * localDir: '/path/to/project',
34
+ * task: { description: 'Fix bug', prompt: '...' },
35
+ * });
36
+ * ```
37
+ */
38
+ export function delegatorHandler(options) {
39
+ const router = Router();
40
+ const service = new DelegatorService({
41
+ config: options.config,
42
+ callbackUrl: options.callbackUrl,
43
+ });
44
+ // Parse JSON bodies
45
+ router.use(json());
46
+ /**
47
+ * POST / - Receive AWCP messages from Executor
48
+ *
49
+ * Executor sends ACCEPT, DONE, and ERROR messages to this endpoint.
50
+ */
51
+ router.post('/', async (req, res) => {
52
+ try {
53
+ const message = req.body;
54
+ await service.handleMessage(message);
55
+ res.json({ ok: true });
56
+ }
57
+ catch (error) {
58
+ console.error('[AWCP Delegator] Error handling message:', error);
59
+ res.status(500).json({
60
+ error: error instanceof Error ? error.message : 'Internal error',
61
+ });
62
+ }
63
+ });
64
+ /**
65
+ * GET /status - Get service status
66
+ *
67
+ * Returns information about active delegations.
68
+ */
69
+ router.get('/status', (_req, res) => {
70
+ res.json(service.getStatus());
71
+ });
72
+ /**
73
+ * GET /delegation/:id - Get delegation details
74
+ */
75
+ router.get('/delegation/:id', (req, res) => {
76
+ const delegation = service.getDelegation(req.params.id);
77
+ if (!delegation) {
78
+ res.status(404).json({ error: 'Delegation not found' });
79
+ return;
80
+ }
81
+ res.json(delegation);
82
+ });
83
+ /**
84
+ * DELETE /delegation/:id - Cancel a delegation
85
+ */
86
+ router.delete('/delegation/:id', async (req, res) => {
87
+ try {
88
+ await service.cancel(req.params.id);
89
+ res.json({ ok: true });
90
+ }
91
+ catch (error) {
92
+ res.status(400).json({
93
+ error: error instanceof Error ? error.message : 'Failed to cancel',
94
+ });
95
+ }
96
+ });
97
+ return { router, service };
98
+ }
99
+ //# sourceMappingURL=awcp-delegator-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awcp-delegator-handler.js","sourceRoot":"","sources":["../../../src/server/express/awcp-delegator-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAgC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAC/D,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC;QACnC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC,CAAC;IAEH,oBAAoB;IACpB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;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CAAC,MAAM,CAAC,iBAAiB,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QAClD,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACpC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB;aACnE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * AWCP Executor Express Handler
3
+ *
4
+ * Express middleware for enabling AWCP support in an A2A agent (Executor side).
5
+ */
6
+ import { Router } from 'express';
7
+ import type { AgentExecutor } from '@a2a-js/sdk/server';
8
+ import type { ExecutorConfig } from '../../executor/config.js';
9
+ /**
10
+ * Options for the AWCP Executor Express handler
11
+ */
12
+ export interface ExecutorHandlerOptions {
13
+ /**
14
+ * A2A agent executor
15
+ *
16
+ * This is the executor that will be called to execute tasks.
17
+ * It should be the same executor used by the A2A agent.
18
+ */
19
+ executor: AgentExecutor;
20
+ /**
21
+ * AWCP Executor configuration
22
+ */
23
+ config: ExecutorConfig;
24
+ }
25
+ /**
26
+ * Create an Express router that handles AWCP messages (Executor side)
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * import express from 'express';
31
+ * import { executorHandler } from '@awcp/sdk/server/express';
32
+ *
33
+ * const app = express();
34
+ *
35
+ * // ... existing A2A setup ...
36
+ *
37
+ * // Enable AWCP
38
+ * app.use('/awcp', executorHandler({
39
+ * executor: myExecutor,
40
+ * config: {
41
+ * mount: { root: '/tmp/awcp/mounts' },
42
+ * },
43
+ * }));
44
+ * ```
45
+ */
46
+ export declare function executorHandler(options: ExecutorHandlerOptions): Router;
47
+ //# sourceMappingURL=awcp-executor-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awcp-executor-handler.d.ts","sourceRoot":"","sources":["../../../src/server/express/awcp-executor-handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAQ,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,QAAQ,EAAE,aAAa,CAAC;IAExB;;OAEG;IACH,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAgFvE"}