recoder-a2a-sdk 1.0.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 (59) hide show
  1. package/dist/audit-helpers.d.mts +209 -0
  2. package/dist/audit-helpers.d.ts +209 -0
  3. package/dist/audit-helpers.js +905 -0
  4. package/dist/audit-helpers.js.map +1 -0
  5. package/dist/audit-helpers.mjs +34 -0
  6. package/dist/audit-helpers.mjs.map +1 -0
  7. package/dist/chunk-7GY5FFBI.mjs +117 -0
  8. package/dist/chunk-7GY5FFBI.mjs.map +1 -0
  9. package/dist/chunk-AGD6G5N6.mjs +141 -0
  10. package/dist/chunk-AGD6G5N6.mjs.map +1 -0
  11. package/dist/chunk-BWCRJDUB.mjs +357 -0
  12. package/dist/chunk-BWCRJDUB.mjs.map +1 -0
  13. package/dist/chunk-DPFH2JIC.mjs +141 -0
  14. package/dist/chunk-DPFH2JIC.mjs.map +1 -0
  15. package/dist/chunk-EP2GHC3R.mjs +116 -0
  16. package/dist/chunk-EP2GHC3R.mjs.map +1 -0
  17. package/dist/chunk-JOZQDX7A.mjs +359 -0
  18. package/dist/chunk-JOZQDX7A.mjs.map +1 -0
  19. package/dist/chunk-MAA7JZ2Q.mjs +142 -0
  20. package/dist/chunk-MAA7JZ2Q.mjs.map +1 -0
  21. package/dist/chunk-QVOOBAUA.mjs +140 -0
  22. package/dist/chunk-QVOOBAUA.mjs.map +1 -0
  23. package/dist/chunk-T5GUBIFZ.mjs +358 -0
  24. package/dist/chunk-T5GUBIFZ.mjs.map +1 -0
  25. package/dist/chunk-WLNW7Y2H.mjs +636 -0
  26. package/dist/chunk-WLNW7Y2H.mjs.map +1 -0
  27. package/dist/chunk-XSELW6DU.mjs +356 -0
  28. package/dist/chunk-XSELW6DU.mjs.map +1 -0
  29. package/dist/envelope-builders.d.mts +189 -0
  30. package/dist/envelope-builders.d.ts +189 -0
  31. package/dist/envelope-builders.js +652 -0
  32. package/dist/envelope-builders.js.map +1 -0
  33. package/dist/envelope-builders.mjs +20 -0
  34. package/dist/envelope-builders.mjs.map +1 -0
  35. package/dist/error-mapping.d.mts +132 -0
  36. package/dist/error-mapping.d.ts +132 -0
  37. package/dist/error-mapping.js +642 -0
  38. package/dist/error-mapping.js.map +1 -0
  39. package/dist/error-mapping.mjs +16 -0
  40. package/dist/error-mapping.mjs.map +1 -0
  41. package/dist/index.d.mts +7 -0
  42. package/dist/index.d.ts +7 -0
  43. package/dist/index.js +1798 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/index.mjs +153 -0
  46. package/dist/index.mjs.map +1 -0
  47. package/dist/state-mapping.d.mts +139 -0
  48. package/dist/state-mapping.d.ts +139 -0
  49. package/dist/state-mapping.js +641 -0
  50. package/dist/state-mapping.js.map +1 -0
  51. package/dist/state-mapping.mjs +28 -0
  52. package/dist/state-mapping.mjs.map +1 -0
  53. package/dist/validation.d.mts +117 -0
  54. package/dist/validation.d.ts +117 -0
  55. package/dist/validation.js +850 -0
  56. package/dist/validation.js.map +1 -0
  57. package/dist/validation.mjs +22 -0
  58. package/dist/validation.mjs.map +1 -0
  59. package/package.json +18 -0
@@ -0,0 +1,189 @@
1
+ import { TaskAgentRef, TaskState, TaskEnvelope, TaskResult, TaskErrorInfo } from '@recoder/shared/a2a/schemas';
2
+ import { RecoderPayload } from '@recoder/shared/a2a';
3
+
4
+ /**
5
+ * @module envelope-builders
6
+ *
7
+ * Convenience factory functions for creating `TaskEnvelope` instances
8
+ * pre-configured for specific connector platforms.
9
+ *
10
+ * These builders reduce boilerplate in adapter code by pre-filling the
11
+ * `connector`, `requester`, and `assignee` fields with sensible defaults
12
+ * for each platform while still allowing full override.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { buildCodexEnvelope, buildClaudeEnvelope } from '@recoder/a2a-sdk/envelope-builders';
17
+ *
18
+ * const codexEnv = buildCodexEnvelope({
19
+ * id: 'task_01',
20
+ * workspace_id: 'ws_abc',
21
+ * thread_id: 'thr_def',
22
+ * trace_id: '4bf92f3577b34da6a3ce929d0e0e4736',
23
+ * requester: { agent_id: 'agent-pm', platform: 'recoder_pm' },
24
+ * payload: { kind: 'text', text: 'Implement auth flow' },
25
+ * });
26
+ * ```
27
+ */
28
+
29
+ /**
30
+ * Minimal input for a connector-specific envelope builder.
31
+ * Fields that can be derived from the connector context are optional.
32
+ */
33
+ interface ConnectorEnvelopeInput {
34
+ /** Unique task ID. */
35
+ id: string;
36
+ /** Workspace ID. */
37
+ workspace_id: string;
38
+ /** Thread ID. */
39
+ thread_id: string;
40
+ /** Trace ID (W3C Trace Context compatible). */
41
+ trace_id: string;
42
+ /** Optional parent span ID. */
43
+ parent_id?: string;
44
+ /** The requester agent reference. */
45
+ requester: TaskAgentRef;
46
+ /** Optional override for the assignee (defaults to the connector agent). */
47
+ assignee?: TaskAgentRef;
48
+ /** The task payload. */
49
+ payload: RecoderPayload | RecoderPayload[];
50
+ /** Optional metadata. */
51
+ metadata?: Record<string, unknown>;
52
+ /** Optional tags. */
53
+ tags?: string[];
54
+ /** Override the initial state (defaults to 'submitted'). */
55
+ initial_state?: TaskState;
56
+ /** Override the creation timestamp. */
57
+ now?: string;
58
+ }
59
+ /**
60
+ * Optional overrides specific to Codex envelopes.
61
+ */
62
+ interface CodexEnvelopeOptions {
63
+ /** Override the Codex connector ID (defaults to 'codex-v1'). */
64
+ connector_id?: string;
65
+ /** Codex model name (stored in connector metadata). */
66
+ model?: string;
67
+ /** Codex API endpoint (stored in connector metadata). */
68
+ endpoint?: string;
69
+ /** Additional connector metadata. */
70
+ connector_metadata?: Record<string, unknown>;
71
+ }
72
+ /**
73
+ * Build a `TaskEnvelope` pre-configured for the Codex connector.
74
+ *
75
+ * Defaults:
76
+ * - `connector.platform`: `'codex'`
77
+ * - `connector.protocol`: `'jsonrpc'`
78
+ * - `connector.connector_id`: `'codex-v1'`
79
+ * - `assignee.platform`: `'codex'`
80
+ *
81
+ * @param input - The core envelope fields.
82
+ * @param options - Optional Codex-specific overrides.
83
+ * @returns A fully populated `TaskEnvelope`.
84
+ */
85
+ declare function buildCodexEnvelope(input: ConnectorEnvelopeInput, options?: CodexEnvelopeOptions): TaskEnvelope;
86
+ /**
87
+ * Optional overrides specific to Claude Code envelopes.
88
+ */
89
+ interface ClaudeEnvelopeOptions {
90
+ /** Override the Claude connector ID (defaults to 'claude-code-v1'). */
91
+ connector_id?: string;
92
+ /** Claude model name (stored in connector metadata). */
93
+ model?: string;
94
+ /** Claude API endpoint (stored in connector metadata). */
95
+ endpoint?: string;
96
+ /** Maximum tokens for the Claude session. */
97
+ max_tokens?: number;
98
+ /** Additional connector metadata. */
99
+ connector_metadata?: Record<string, unknown>;
100
+ }
101
+ /**
102
+ * Build a `TaskEnvelope` pre-configured for the Claude Code connector.
103
+ *
104
+ * Defaults:
105
+ * - `connector.platform`: `'claude_code'`
106
+ * - `connector.protocol`: `'jsonrpc'`
107
+ * - `connector.connector_id`: `'claude-code-v1'`
108
+ * - `assignee.platform`: `'claude_code'`
109
+ *
110
+ * @param input - The core envelope fields.
111
+ * @param options - Optional Claude-specific overrides.
112
+ * @returns A fully populated `TaskEnvelope`.
113
+ */
114
+ declare function buildClaudeEnvelope(input: ConnectorEnvelopeInput, options?: ClaudeEnvelopeOptions): TaskEnvelope;
115
+ /**
116
+ * Apply a result to a completed task envelope.
117
+ *
118
+ * Transitions the envelope to `completed` and attaches the result payload.
119
+ *
120
+ * @param envelope - The current task envelope (must be in a non-terminal state).
121
+ * @param result - The result data.
122
+ * @param options - Optional reason and actor for the transition.
123
+ * @returns The updated envelope with state `completed` and the result attached.
124
+ */
125
+ declare function completeEnvelope(envelope: TaskEnvelope, result: TaskResult, options?: {
126
+ reason?: string;
127
+ triggered_by?: string;
128
+ now?: string;
129
+ }): TaskEnvelope;
130
+ /**
131
+ * Apply an error to a failed task envelope.
132
+ *
133
+ * Transitions the envelope to `failed` and attaches the error info.
134
+ *
135
+ * @param envelope - The current task envelope (must be in a non-terminal state).
136
+ * @param error - The error information.
137
+ * @param options - Optional reason and actor for the transition.
138
+ * @returns The updated envelope with state `failed` and the error attached.
139
+ */
140
+ declare function failEnvelope(envelope: TaskEnvelope, error: TaskErrorInfo, options?: {
141
+ reason?: string;
142
+ triggered_by?: string;
143
+ now?: string;
144
+ }): TaskEnvelope;
145
+ /**
146
+ * Cancel a task envelope.
147
+ *
148
+ * Transitions the envelope to `cancelled`.
149
+ *
150
+ * @param envelope - The current task envelope.
151
+ * @param options - Optional reason and actor for the transition.
152
+ * @returns The updated envelope with state `cancelled`.
153
+ */
154
+ declare function cancelEnvelope(envelope: TaskEnvelope, options?: {
155
+ reason?: string;
156
+ triggered_by?: string;
157
+ now?: string;
158
+ }): TaskEnvelope;
159
+ /**
160
+ * Start working on a task envelope.
161
+ *
162
+ * Transitions the envelope from `submitted` to `working`.
163
+ *
164
+ * @param envelope - The current task envelope (must be in `submitted` state).
165
+ * @param options - Optional reason and actor for the transition.
166
+ * @returns The updated envelope with state `working`.
167
+ */
168
+ declare function startEnvelope(envelope: TaskEnvelope, options?: {
169
+ reason?: string;
170
+ triggered_by?: string;
171
+ now?: string;
172
+ }): TaskEnvelope;
173
+ /**
174
+ * Convert a canonical `A2AError` to the `TaskErrorInfo` shape expected
175
+ * by the `TaskEnvelope.error` field.
176
+ *
177
+ * @param a2aError - The source A2AError.
178
+ * @returns A `TaskErrorInfo` suitable for embedding in an envelope.
179
+ */
180
+ declare function a2aErrorToTaskErrorInfo(a2aError: {
181
+ code: string;
182
+ category: string;
183
+ message: string;
184
+ severity: string;
185
+ retryable: boolean;
186
+ details?: Record<string, unknown>;
187
+ }): TaskErrorInfo;
188
+
189
+ export { type ClaudeEnvelopeOptions, type CodexEnvelopeOptions, type ConnectorEnvelopeInput, a2aErrorToTaskErrorInfo, buildClaudeEnvelope, buildCodexEnvelope, cancelEnvelope, completeEnvelope, failEnvelope, startEnvelope };
@@ -0,0 +1,189 @@
1
+ import { TaskAgentRef, TaskState, TaskEnvelope, TaskResult, TaskErrorInfo } from '@recoder/shared/a2a/schemas';
2
+ import { RecoderPayload } from '@recoder/shared/a2a';
3
+
4
+ /**
5
+ * @module envelope-builders
6
+ *
7
+ * Convenience factory functions for creating `TaskEnvelope` instances
8
+ * pre-configured for specific connector platforms.
9
+ *
10
+ * These builders reduce boilerplate in adapter code by pre-filling the
11
+ * `connector`, `requester`, and `assignee` fields with sensible defaults
12
+ * for each platform while still allowing full override.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { buildCodexEnvelope, buildClaudeEnvelope } from '@recoder/a2a-sdk/envelope-builders';
17
+ *
18
+ * const codexEnv = buildCodexEnvelope({
19
+ * id: 'task_01',
20
+ * workspace_id: 'ws_abc',
21
+ * thread_id: 'thr_def',
22
+ * trace_id: '4bf92f3577b34da6a3ce929d0e0e4736',
23
+ * requester: { agent_id: 'agent-pm', platform: 'recoder_pm' },
24
+ * payload: { kind: 'text', text: 'Implement auth flow' },
25
+ * });
26
+ * ```
27
+ */
28
+
29
+ /**
30
+ * Minimal input for a connector-specific envelope builder.
31
+ * Fields that can be derived from the connector context are optional.
32
+ */
33
+ interface ConnectorEnvelopeInput {
34
+ /** Unique task ID. */
35
+ id: string;
36
+ /** Workspace ID. */
37
+ workspace_id: string;
38
+ /** Thread ID. */
39
+ thread_id: string;
40
+ /** Trace ID (W3C Trace Context compatible). */
41
+ trace_id: string;
42
+ /** Optional parent span ID. */
43
+ parent_id?: string;
44
+ /** The requester agent reference. */
45
+ requester: TaskAgentRef;
46
+ /** Optional override for the assignee (defaults to the connector agent). */
47
+ assignee?: TaskAgentRef;
48
+ /** The task payload. */
49
+ payload: RecoderPayload | RecoderPayload[];
50
+ /** Optional metadata. */
51
+ metadata?: Record<string, unknown>;
52
+ /** Optional tags. */
53
+ tags?: string[];
54
+ /** Override the initial state (defaults to 'submitted'). */
55
+ initial_state?: TaskState;
56
+ /** Override the creation timestamp. */
57
+ now?: string;
58
+ }
59
+ /**
60
+ * Optional overrides specific to Codex envelopes.
61
+ */
62
+ interface CodexEnvelopeOptions {
63
+ /** Override the Codex connector ID (defaults to 'codex-v1'). */
64
+ connector_id?: string;
65
+ /** Codex model name (stored in connector metadata). */
66
+ model?: string;
67
+ /** Codex API endpoint (stored in connector metadata). */
68
+ endpoint?: string;
69
+ /** Additional connector metadata. */
70
+ connector_metadata?: Record<string, unknown>;
71
+ }
72
+ /**
73
+ * Build a `TaskEnvelope` pre-configured for the Codex connector.
74
+ *
75
+ * Defaults:
76
+ * - `connector.platform`: `'codex'`
77
+ * - `connector.protocol`: `'jsonrpc'`
78
+ * - `connector.connector_id`: `'codex-v1'`
79
+ * - `assignee.platform`: `'codex'`
80
+ *
81
+ * @param input - The core envelope fields.
82
+ * @param options - Optional Codex-specific overrides.
83
+ * @returns A fully populated `TaskEnvelope`.
84
+ */
85
+ declare function buildCodexEnvelope(input: ConnectorEnvelopeInput, options?: CodexEnvelopeOptions): TaskEnvelope;
86
+ /**
87
+ * Optional overrides specific to Claude Code envelopes.
88
+ */
89
+ interface ClaudeEnvelopeOptions {
90
+ /** Override the Claude connector ID (defaults to 'claude-code-v1'). */
91
+ connector_id?: string;
92
+ /** Claude model name (stored in connector metadata). */
93
+ model?: string;
94
+ /** Claude API endpoint (stored in connector metadata). */
95
+ endpoint?: string;
96
+ /** Maximum tokens for the Claude session. */
97
+ max_tokens?: number;
98
+ /** Additional connector metadata. */
99
+ connector_metadata?: Record<string, unknown>;
100
+ }
101
+ /**
102
+ * Build a `TaskEnvelope` pre-configured for the Claude Code connector.
103
+ *
104
+ * Defaults:
105
+ * - `connector.platform`: `'claude_code'`
106
+ * - `connector.protocol`: `'jsonrpc'`
107
+ * - `connector.connector_id`: `'claude-code-v1'`
108
+ * - `assignee.platform`: `'claude_code'`
109
+ *
110
+ * @param input - The core envelope fields.
111
+ * @param options - Optional Claude-specific overrides.
112
+ * @returns A fully populated `TaskEnvelope`.
113
+ */
114
+ declare function buildClaudeEnvelope(input: ConnectorEnvelopeInput, options?: ClaudeEnvelopeOptions): TaskEnvelope;
115
+ /**
116
+ * Apply a result to a completed task envelope.
117
+ *
118
+ * Transitions the envelope to `completed` and attaches the result payload.
119
+ *
120
+ * @param envelope - The current task envelope (must be in a non-terminal state).
121
+ * @param result - The result data.
122
+ * @param options - Optional reason and actor for the transition.
123
+ * @returns The updated envelope with state `completed` and the result attached.
124
+ */
125
+ declare function completeEnvelope(envelope: TaskEnvelope, result: TaskResult, options?: {
126
+ reason?: string;
127
+ triggered_by?: string;
128
+ now?: string;
129
+ }): TaskEnvelope;
130
+ /**
131
+ * Apply an error to a failed task envelope.
132
+ *
133
+ * Transitions the envelope to `failed` and attaches the error info.
134
+ *
135
+ * @param envelope - The current task envelope (must be in a non-terminal state).
136
+ * @param error - The error information.
137
+ * @param options - Optional reason and actor for the transition.
138
+ * @returns The updated envelope with state `failed` and the error attached.
139
+ */
140
+ declare function failEnvelope(envelope: TaskEnvelope, error: TaskErrorInfo, options?: {
141
+ reason?: string;
142
+ triggered_by?: string;
143
+ now?: string;
144
+ }): TaskEnvelope;
145
+ /**
146
+ * Cancel a task envelope.
147
+ *
148
+ * Transitions the envelope to `cancelled`.
149
+ *
150
+ * @param envelope - The current task envelope.
151
+ * @param options - Optional reason and actor for the transition.
152
+ * @returns The updated envelope with state `cancelled`.
153
+ */
154
+ declare function cancelEnvelope(envelope: TaskEnvelope, options?: {
155
+ reason?: string;
156
+ triggered_by?: string;
157
+ now?: string;
158
+ }): TaskEnvelope;
159
+ /**
160
+ * Start working on a task envelope.
161
+ *
162
+ * Transitions the envelope from `submitted` to `working`.
163
+ *
164
+ * @param envelope - The current task envelope (must be in `submitted` state).
165
+ * @param options - Optional reason and actor for the transition.
166
+ * @returns The updated envelope with state `working`.
167
+ */
168
+ declare function startEnvelope(envelope: TaskEnvelope, options?: {
169
+ reason?: string;
170
+ triggered_by?: string;
171
+ now?: string;
172
+ }): TaskEnvelope;
173
+ /**
174
+ * Convert a canonical `A2AError` to the `TaskErrorInfo` shape expected
175
+ * by the `TaskEnvelope.error` field.
176
+ *
177
+ * @param a2aError - The source A2AError.
178
+ * @returns A `TaskErrorInfo` suitable for embedding in an envelope.
179
+ */
180
+ declare function a2aErrorToTaskErrorInfo(a2aError: {
181
+ code: string;
182
+ category: string;
183
+ message: string;
184
+ severity: string;
185
+ retryable: boolean;
186
+ details?: Record<string, unknown>;
187
+ }): TaskErrorInfo;
188
+
189
+ export { type ClaudeEnvelopeOptions, type CodexEnvelopeOptions, type ConnectorEnvelopeInput, a2aErrorToTaskErrorInfo, buildClaudeEnvelope, buildCodexEnvelope, cancelEnvelope, completeEnvelope, failEnvelope, startEnvelope };