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,209 @@
1
+ import { AuditEvent } from '@recoder/shared/a2a/schemas';
2
+ import { RecoderAgentPlatform } from '@recoder/shared/a2a';
3
+
4
+ /**
5
+ * @module audit-helpers
6
+ *
7
+ * High-level audit event emitter helpers for common A2A operations.
8
+ *
9
+ * Instead of manually constructing `CreateAuditEventInput` objects for every
10
+ * lifecycle event, adapter code can call these type-safe helper functions
11
+ * which pre-fill the `event_type`, `actor`, `target`, and `severity` fields
12
+ * for the most common scenarios.
13
+ *
14
+ * All helpers return an `AuditEvent` (not a side-effecting "emit"). The
15
+ * caller is responsible for persisting or publishing the event through
16
+ * the audit-log service transport layer.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { emitTaskSubmitted, emitConnectorInvoked } from '@recoder/a2a-sdk/audit-helpers';
21
+ *
22
+ * const evt = emitTaskSubmitted({
23
+ * id: 'evt_01',
24
+ * task_id: 'task_01',
25
+ * workspace_id: 'ws_abc',
26
+ * trace_id: '4bf92f3577b34da6a3ce929d0e0e4736',
27
+ * actor_agent_id: 'agent-pm',
28
+ * actor_platform: 'recoder_pm',
29
+ * });
30
+ * await auditLogService.persist(evt);
31
+ * ```
32
+ */
33
+
34
+ /**
35
+ * Common fields required by all audit event helpers.
36
+ */
37
+ interface AuditEventBase {
38
+ /** Unique event ID. */
39
+ id: string;
40
+ /** Workspace ID. */
41
+ workspace_id: string;
42
+ /** Trace ID for correlation with the originating TaskEnvelope. */
43
+ trace_id: string;
44
+ /** Optional thread ID. */
45
+ thread_id?: string;
46
+ /** Optional parent event ID. */
47
+ parent_event_id?: string;
48
+ /** Optional additional metadata. */
49
+ metadata?: Record<string, unknown>;
50
+ /** Optional tags. */
51
+ tags?: string[];
52
+ /** Override the timestamp (defaults to now). */
53
+ now?: string;
54
+ }
55
+ /**
56
+ * Fields for task-scoped audit events.
57
+ */
58
+ interface TaskAuditEventInput extends AuditEventBase {
59
+ /** The task ID that this event is about. */
60
+ task_id: string;
61
+ /** The actor agent ID. */
62
+ actor_agent_id: string;
63
+ /** The actor's platform. */
64
+ actor_platform: RecoderAgentPlatform;
65
+ /** Optional actor display name. */
66
+ actor_name?: string;
67
+ }
68
+ /**
69
+ * Fields for connector-scoped audit events.
70
+ */
71
+ interface ConnectorAuditEventInput extends AuditEventBase {
72
+ /** The connector ID. */
73
+ connector_id: string;
74
+ /** The connector platform. */
75
+ connector_platform: RecoderAgentPlatform;
76
+ /** Optional task ID. */
77
+ task_id?: string;
78
+ /** Optional connector display name. */
79
+ connector_name?: string;
80
+ }
81
+ /**
82
+ * Emit a `task.submitted` audit event.
83
+ *
84
+ * Call this when a new task envelope is created and submitted to the
85
+ * control plane.
86
+ */
87
+ declare function emitTaskSubmitted(input: TaskAuditEventInput): AuditEvent;
88
+ /**
89
+ * Emit a `task.started` audit event.
90
+ *
91
+ * Call this when a task transitions from `submitted` to `working`.
92
+ */
93
+ declare function emitTaskStarted(input: TaskAuditEventInput): AuditEvent;
94
+ /**
95
+ * Emit a `task.progress` audit event.
96
+ *
97
+ * Call this for intermediate progress updates during task execution.
98
+ */
99
+ declare function emitTaskProgress(input: TaskAuditEventInput & {
100
+ progress_pct?: number;
101
+ }): AuditEvent;
102
+ /**
103
+ * Emit a `task.input_required` audit event.
104
+ *
105
+ * Call this when the assignee agent needs additional input.
106
+ */
107
+ declare function emitTaskInputRequired(input: TaskAuditEventInput): AuditEvent;
108
+ /**
109
+ * Emit a `task.completed` audit event.
110
+ *
111
+ * Call this when a task reaches the `completed` terminal state.
112
+ */
113
+ declare function emitTaskCompleted(input: TaskAuditEventInput & {
114
+ duration_ms?: number;
115
+ }): AuditEvent;
116
+ /**
117
+ * Emit a `task.failed` audit event.
118
+ *
119
+ * Call this when a task reaches the `failed` terminal state.
120
+ */
121
+ declare function emitTaskFailed(input: TaskAuditEventInput & {
122
+ error_code?: string;
123
+ error_message?: string;
124
+ duration_ms?: number;
125
+ }): AuditEvent;
126
+ /**
127
+ * Emit a `task.cancelled` audit event.
128
+ *
129
+ * Call this when a task is explicitly cancelled.
130
+ */
131
+ declare function emitTaskCancelled(input: TaskAuditEventInput & {
132
+ reason?: string;
133
+ }): AuditEvent;
134
+ /**
135
+ * Emit a `connector.attached` audit event.
136
+ *
137
+ * Call this when a connector is attached to an agent for task execution.
138
+ */
139
+ declare function emitConnectorAttached(input: ConnectorAuditEventInput): AuditEvent;
140
+ /**
141
+ * Emit a `connector.health` audit event.
142
+ *
143
+ * Call this when a connector emits a health check or diagnostic event.
144
+ */
145
+ declare function emitConnectorHealth(input: ConnectorAuditEventInput & {
146
+ healthy: boolean;
147
+ latency_ms?: number;
148
+ }): AuditEvent;
149
+ /**
150
+ * Emit a `connector.error` audit event.
151
+ *
152
+ * Call this when a connector encounters an error during task execution.
153
+ */
154
+ declare function emitConnectorError(input: ConnectorAuditEventInput & {
155
+ error_code?: string;
156
+ error_message: string;
157
+ }): AuditEvent;
158
+ /**
159
+ * Input for policy audit events.
160
+ */
161
+ interface PolicyAuditEventInput extends AuditEventBase {
162
+ /** The task ID the policy was checked for. */
163
+ task_id: string;
164
+ /** The agent ID the policy was evaluated against. */
165
+ agent_id: string;
166
+ /** The policy action (e.g. 'file:write', 'bash:exec'). */
167
+ action: string;
168
+ /** The rule that was applied ('auto', 'prompt', 'deny'). */
169
+ rule: string;
170
+ /** Whether the action was approved. */
171
+ approved: boolean;
172
+ /** Human-readable reason for the decision. */
173
+ reason: string;
174
+ /** Duration of the policy check. */
175
+ duration_ms?: number;
176
+ }
177
+ /**
178
+ * Emit a `policy.checked` audit event.
179
+ *
180
+ * Call this after a policy evaluation completes.
181
+ */
182
+ declare function emitPolicyChecked(input: PolicyAuditEventInput): AuditEvent;
183
+ /**
184
+ * Emit a `policy.approved` audit event.
185
+ *
186
+ * Convenience wrapper around `emitPolicyChecked` for approved actions.
187
+ */
188
+ declare function emitPolicyApproved(input: Omit<PolicyAuditEventInput, 'approved'>): AuditEvent;
189
+ /**
190
+ * Emit a `policy.denied` audit event.
191
+ *
192
+ * Convenience wrapper for denied actions.
193
+ */
194
+ declare function emitPolicyDenied(input: Omit<PolicyAuditEventInput, 'approved'>): AuditEvent;
195
+ /**
196
+ * Automatically emit the correct audit event type for a task state
197
+ * transition. This is the preferred method for adapter code that processes
198
+ * state changes and wants to emit a matching audit event without manually
199
+ * switching on the state.
200
+ *
201
+ * @param input - The task audit event input.
202
+ * @param newState - The canonical state the task transitioned to.
203
+ * @returns An `AuditEvent` with the correct event_type for the transition.
204
+ */
205
+ declare function emitAuditForTransition(input: TaskAuditEventInput & {
206
+ duration_ms?: number;
207
+ }, newState: string): AuditEvent;
208
+
209
+ export { type AuditEventBase, type ConnectorAuditEventInput, type PolicyAuditEventInput, type TaskAuditEventInput, emitAuditForTransition, emitConnectorAttached, emitConnectorError, emitConnectorHealth, emitPolicyApproved, emitPolicyChecked, emitPolicyDenied, emitTaskCancelled, emitTaskCompleted, emitTaskFailed, emitTaskInputRequired, emitTaskProgress, emitTaskStarted, emitTaskSubmitted };
@@ -0,0 +1,209 @@
1
+ import { AuditEvent } from '@recoder/shared/a2a/schemas';
2
+ import { RecoderAgentPlatform } from '@recoder/shared/a2a';
3
+
4
+ /**
5
+ * @module audit-helpers
6
+ *
7
+ * High-level audit event emitter helpers for common A2A operations.
8
+ *
9
+ * Instead of manually constructing `CreateAuditEventInput` objects for every
10
+ * lifecycle event, adapter code can call these type-safe helper functions
11
+ * which pre-fill the `event_type`, `actor`, `target`, and `severity` fields
12
+ * for the most common scenarios.
13
+ *
14
+ * All helpers return an `AuditEvent` (not a side-effecting "emit"). The
15
+ * caller is responsible for persisting or publishing the event through
16
+ * the audit-log service transport layer.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { emitTaskSubmitted, emitConnectorInvoked } from '@recoder/a2a-sdk/audit-helpers';
21
+ *
22
+ * const evt = emitTaskSubmitted({
23
+ * id: 'evt_01',
24
+ * task_id: 'task_01',
25
+ * workspace_id: 'ws_abc',
26
+ * trace_id: '4bf92f3577b34da6a3ce929d0e0e4736',
27
+ * actor_agent_id: 'agent-pm',
28
+ * actor_platform: 'recoder_pm',
29
+ * });
30
+ * await auditLogService.persist(evt);
31
+ * ```
32
+ */
33
+
34
+ /**
35
+ * Common fields required by all audit event helpers.
36
+ */
37
+ interface AuditEventBase {
38
+ /** Unique event ID. */
39
+ id: string;
40
+ /** Workspace ID. */
41
+ workspace_id: string;
42
+ /** Trace ID for correlation with the originating TaskEnvelope. */
43
+ trace_id: string;
44
+ /** Optional thread ID. */
45
+ thread_id?: string;
46
+ /** Optional parent event ID. */
47
+ parent_event_id?: string;
48
+ /** Optional additional metadata. */
49
+ metadata?: Record<string, unknown>;
50
+ /** Optional tags. */
51
+ tags?: string[];
52
+ /** Override the timestamp (defaults to now). */
53
+ now?: string;
54
+ }
55
+ /**
56
+ * Fields for task-scoped audit events.
57
+ */
58
+ interface TaskAuditEventInput extends AuditEventBase {
59
+ /** The task ID that this event is about. */
60
+ task_id: string;
61
+ /** The actor agent ID. */
62
+ actor_agent_id: string;
63
+ /** The actor's platform. */
64
+ actor_platform: RecoderAgentPlatform;
65
+ /** Optional actor display name. */
66
+ actor_name?: string;
67
+ }
68
+ /**
69
+ * Fields for connector-scoped audit events.
70
+ */
71
+ interface ConnectorAuditEventInput extends AuditEventBase {
72
+ /** The connector ID. */
73
+ connector_id: string;
74
+ /** The connector platform. */
75
+ connector_platform: RecoderAgentPlatform;
76
+ /** Optional task ID. */
77
+ task_id?: string;
78
+ /** Optional connector display name. */
79
+ connector_name?: string;
80
+ }
81
+ /**
82
+ * Emit a `task.submitted` audit event.
83
+ *
84
+ * Call this when a new task envelope is created and submitted to the
85
+ * control plane.
86
+ */
87
+ declare function emitTaskSubmitted(input: TaskAuditEventInput): AuditEvent;
88
+ /**
89
+ * Emit a `task.started` audit event.
90
+ *
91
+ * Call this when a task transitions from `submitted` to `working`.
92
+ */
93
+ declare function emitTaskStarted(input: TaskAuditEventInput): AuditEvent;
94
+ /**
95
+ * Emit a `task.progress` audit event.
96
+ *
97
+ * Call this for intermediate progress updates during task execution.
98
+ */
99
+ declare function emitTaskProgress(input: TaskAuditEventInput & {
100
+ progress_pct?: number;
101
+ }): AuditEvent;
102
+ /**
103
+ * Emit a `task.input_required` audit event.
104
+ *
105
+ * Call this when the assignee agent needs additional input.
106
+ */
107
+ declare function emitTaskInputRequired(input: TaskAuditEventInput): AuditEvent;
108
+ /**
109
+ * Emit a `task.completed` audit event.
110
+ *
111
+ * Call this when a task reaches the `completed` terminal state.
112
+ */
113
+ declare function emitTaskCompleted(input: TaskAuditEventInput & {
114
+ duration_ms?: number;
115
+ }): AuditEvent;
116
+ /**
117
+ * Emit a `task.failed` audit event.
118
+ *
119
+ * Call this when a task reaches the `failed` terminal state.
120
+ */
121
+ declare function emitTaskFailed(input: TaskAuditEventInput & {
122
+ error_code?: string;
123
+ error_message?: string;
124
+ duration_ms?: number;
125
+ }): AuditEvent;
126
+ /**
127
+ * Emit a `task.cancelled` audit event.
128
+ *
129
+ * Call this when a task is explicitly cancelled.
130
+ */
131
+ declare function emitTaskCancelled(input: TaskAuditEventInput & {
132
+ reason?: string;
133
+ }): AuditEvent;
134
+ /**
135
+ * Emit a `connector.attached` audit event.
136
+ *
137
+ * Call this when a connector is attached to an agent for task execution.
138
+ */
139
+ declare function emitConnectorAttached(input: ConnectorAuditEventInput): AuditEvent;
140
+ /**
141
+ * Emit a `connector.health` audit event.
142
+ *
143
+ * Call this when a connector emits a health check or diagnostic event.
144
+ */
145
+ declare function emitConnectorHealth(input: ConnectorAuditEventInput & {
146
+ healthy: boolean;
147
+ latency_ms?: number;
148
+ }): AuditEvent;
149
+ /**
150
+ * Emit a `connector.error` audit event.
151
+ *
152
+ * Call this when a connector encounters an error during task execution.
153
+ */
154
+ declare function emitConnectorError(input: ConnectorAuditEventInput & {
155
+ error_code?: string;
156
+ error_message: string;
157
+ }): AuditEvent;
158
+ /**
159
+ * Input for policy audit events.
160
+ */
161
+ interface PolicyAuditEventInput extends AuditEventBase {
162
+ /** The task ID the policy was checked for. */
163
+ task_id: string;
164
+ /** The agent ID the policy was evaluated against. */
165
+ agent_id: string;
166
+ /** The policy action (e.g. 'file:write', 'bash:exec'). */
167
+ action: string;
168
+ /** The rule that was applied ('auto', 'prompt', 'deny'). */
169
+ rule: string;
170
+ /** Whether the action was approved. */
171
+ approved: boolean;
172
+ /** Human-readable reason for the decision. */
173
+ reason: string;
174
+ /** Duration of the policy check. */
175
+ duration_ms?: number;
176
+ }
177
+ /**
178
+ * Emit a `policy.checked` audit event.
179
+ *
180
+ * Call this after a policy evaluation completes.
181
+ */
182
+ declare function emitPolicyChecked(input: PolicyAuditEventInput): AuditEvent;
183
+ /**
184
+ * Emit a `policy.approved` audit event.
185
+ *
186
+ * Convenience wrapper around `emitPolicyChecked` for approved actions.
187
+ */
188
+ declare function emitPolicyApproved(input: Omit<PolicyAuditEventInput, 'approved'>): AuditEvent;
189
+ /**
190
+ * Emit a `policy.denied` audit event.
191
+ *
192
+ * Convenience wrapper for denied actions.
193
+ */
194
+ declare function emitPolicyDenied(input: Omit<PolicyAuditEventInput, 'approved'>): AuditEvent;
195
+ /**
196
+ * Automatically emit the correct audit event type for a task state
197
+ * transition. This is the preferred method for adapter code that processes
198
+ * state changes and wants to emit a matching audit event without manually
199
+ * switching on the state.
200
+ *
201
+ * @param input - The task audit event input.
202
+ * @param newState - The canonical state the task transitioned to.
203
+ * @returns An `AuditEvent` with the correct event_type for the transition.
204
+ */
205
+ declare function emitAuditForTransition(input: TaskAuditEventInput & {
206
+ duration_ms?: number;
207
+ }, newState: string): AuditEvent;
208
+
209
+ export { type AuditEventBase, type ConnectorAuditEventInput, type PolicyAuditEventInput, type TaskAuditEventInput, emitAuditForTransition, emitConnectorAttached, emitConnectorError, emitConnectorHealth, emitPolicyApproved, emitPolicyChecked, emitPolicyDenied, emitTaskCancelled, emitTaskCompleted, emitTaskFailed, emitTaskInputRequired, emitTaskProgress, emitTaskStarted, emitTaskSubmitted };