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,139 @@
1
+ import { TaskState } from '@recoder/shared/a2a/schemas';
2
+
3
+ /**
4
+ * @module state-mapping
5
+ *
6
+ * Task state mapping helpers for connector adapters.
7
+ *
8
+ * Each external connector (Codex, Claude Code, etc.) has its own native state
9
+ * vocabulary. This module provides bidirectional mapping functions that
10
+ * translate between connector-specific states and the canonical
11
+ * `TaskState` enum defined in `@recoder/shared/a2a/schemas`.
12
+ *
13
+ * Adapter authors should use these mappers at the boundary where connector
14
+ * events enter (or leave) the Recoder A2A control plane, ensuring that all
15
+ * internal logic operates exclusively on canonical states.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { mapCodexState, mapClaudeState } from '@recoder/a2a-sdk/state-mapping';
20
+ *
21
+ * const canonical = mapCodexState('running'); // => 'working'
22
+ * const claude = mapClaudeState('streaming'); // => 'working'
23
+ * ```
24
+ */
25
+
26
+ /** Supported connector platforms for state mapping. */
27
+ type ConnectorPlatform = 'codex' | 'claude_code';
28
+ /**
29
+ * Native states reported by the OpenAI Codex CLI / API adapter.
30
+ * These are the raw status strings that appear in Codex task events.
31
+ */
32
+ type CodexNativeState = 'queued' | 'running' | 'waiting_for_input' | 'completed' | 'failed' | 'error' | 'cancelled' | 'timeout';
33
+ /**
34
+ * Map a Codex native state string to the canonical `TaskState`.
35
+ *
36
+ * @param nativeState - The raw state string from a Codex event.
37
+ * @returns The canonical `TaskState`, or `undefined` if the state is unknown.
38
+ */
39
+ declare function mapCodexState(nativeState: string): TaskState | undefined;
40
+ /**
41
+ * Map a Codex native state to canonical, throwing if the state is unknown.
42
+ *
43
+ * @param nativeState - The raw state string from a Codex event.
44
+ * @returns The canonical `TaskState`.
45
+ * @throws {Error} If the state cannot be mapped.
46
+ */
47
+ declare function mapCodexStateStrict(nativeState: string): TaskState;
48
+ /**
49
+ * Map a canonical `TaskState` back to the primary Codex native state.
50
+ *
51
+ * @param canonicalState - The canonical task state.
52
+ * @returns The Codex native state string.
53
+ */
54
+ declare function canonicalToCodexState(canonicalState: TaskState): CodexNativeState;
55
+ /**
56
+ * Native states reported by the Claude Code CLI / API adapter.
57
+ * These are the raw status strings that appear in Claude Code events.
58
+ */
59
+ type ClaudeNativeState = 'pending' | 'streaming' | 'processing' | 'waiting_for_approval' | 'waiting_for_input' | 'done' | 'completed' | 'error' | 'failed' | 'aborted' | 'cancelled' | 'timeout';
60
+ /**
61
+ * Map a Claude Code native state string to the canonical `TaskState`.
62
+ *
63
+ * @param nativeState - The raw state string from a Claude Code event.
64
+ * @returns The canonical `TaskState`, or `undefined` if the state is unknown.
65
+ */
66
+ declare function mapClaudeState(nativeState: string): TaskState | undefined;
67
+ /**
68
+ * Map a Claude Code native state to canonical, throwing if the state is unknown.
69
+ *
70
+ * @param nativeState - The raw state string from a Claude Code event.
71
+ * @returns The canonical `TaskState`.
72
+ * @throws {Error} If the state cannot be mapped.
73
+ */
74
+ declare function mapClaudeStateStrict(nativeState: string): TaskState;
75
+ /**
76
+ * Map a canonical `TaskState` back to the primary Claude Code native state.
77
+ *
78
+ * @param canonicalState - The canonical task state.
79
+ * @returns The Claude Code native state string.
80
+ */
81
+ declare function canonicalToClaudeState(canonicalState: TaskState): ClaudeNativeState;
82
+ /**
83
+ * Map a native state from any supported connector to canonical `TaskState`.
84
+ *
85
+ * @param platform - The connector platform identifier.
86
+ * @param nativeState - The raw state string from the connector.
87
+ * @returns The canonical `TaskState`, or `undefined` if unmappable.
88
+ */
89
+ declare function mapConnectorState(platform: ConnectorPlatform, nativeState: string): TaskState | undefined;
90
+ /**
91
+ * Map a native state from any supported connector to canonical `TaskState`,
92
+ * throwing if the mapping fails.
93
+ *
94
+ * @param platform - The connector platform identifier.
95
+ * @param nativeState - The raw state string from the connector.
96
+ * @returns The canonical `TaskState`.
97
+ * @throws {Error} If the platform or state is unknown.
98
+ */
99
+ declare function mapConnectorStateStrict(platform: ConnectorPlatform, nativeState: string): TaskState;
100
+ /**
101
+ * Map a canonical `TaskState` back to the primary native state for a given
102
+ * connector platform.
103
+ *
104
+ * @param platform - The connector platform identifier.
105
+ * @param canonicalState - The canonical task state.
106
+ * @returns The native state string, or `undefined` if the platform is unknown.
107
+ */
108
+ declare function canonicalToConnectorState(platform: ConnectorPlatform, canonicalState: TaskState): string | undefined;
109
+ /**
110
+ * Given the current canonical state and a new native state from a connector,
111
+ * determine whether the implied transition is valid according to the
112
+ * canonical lifecycle rules.
113
+ *
114
+ * This is the main "guard" function that adapters should call before
115
+ * applying a state update from a connector event.
116
+ *
117
+ * @param currentCanonical - The current canonical task state.
118
+ * @param platform - The connector platform identifier.
119
+ * @param newNativeState - The new native state reported by the connector.
120
+ * @returns An object indicating whether the transition is valid, the mapped
121
+ * canonical state, and an error message if invalid.
122
+ */
123
+ declare function checkConnectorTransition(currentCanonical: TaskState, platform: ConnectorPlatform, newNativeState: string): {
124
+ valid: boolean;
125
+ mappedState: TaskState | undefined;
126
+ error?: string;
127
+ };
128
+ /**
129
+ * Check whether a connector-reported native state maps to a terminal
130
+ * canonical state.
131
+ *
132
+ * @param platform - The connector platform identifier.
133
+ * @param nativeState - The native state to check.
134
+ * @returns `true` if the mapped canonical state is terminal; `false` if
135
+ * non-terminal or unmappable.
136
+ */
137
+ declare function isConnectorTerminalState(platform: ConnectorPlatform, nativeState: string): boolean;
138
+
139
+ export { type ClaudeNativeState, type CodexNativeState, type ConnectorPlatform, canonicalToClaudeState, canonicalToCodexState, canonicalToConnectorState, checkConnectorTransition, isConnectorTerminalState, mapClaudeState, mapClaudeStateStrict, mapCodexState, mapCodexStateStrict, mapConnectorState, mapConnectorStateStrict };
@@ -0,0 +1,139 @@
1
+ import { TaskState } from '@recoder/shared/a2a/schemas';
2
+
3
+ /**
4
+ * @module state-mapping
5
+ *
6
+ * Task state mapping helpers for connector adapters.
7
+ *
8
+ * Each external connector (Codex, Claude Code, etc.) has its own native state
9
+ * vocabulary. This module provides bidirectional mapping functions that
10
+ * translate between connector-specific states and the canonical
11
+ * `TaskState` enum defined in `@recoder/shared/a2a/schemas`.
12
+ *
13
+ * Adapter authors should use these mappers at the boundary where connector
14
+ * events enter (or leave) the Recoder A2A control plane, ensuring that all
15
+ * internal logic operates exclusively on canonical states.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { mapCodexState, mapClaudeState } from '@recoder/a2a-sdk/state-mapping';
20
+ *
21
+ * const canonical = mapCodexState('running'); // => 'working'
22
+ * const claude = mapClaudeState('streaming'); // => 'working'
23
+ * ```
24
+ */
25
+
26
+ /** Supported connector platforms for state mapping. */
27
+ type ConnectorPlatform = 'codex' | 'claude_code';
28
+ /**
29
+ * Native states reported by the OpenAI Codex CLI / API adapter.
30
+ * These are the raw status strings that appear in Codex task events.
31
+ */
32
+ type CodexNativeState = 'queued' | 'running' | 'waiting_for_input' | 'completed' | 'failed' | 'error' | 'cancelled' | 'timeout';
33
+ /**
34
+ * Map a Codex native state string to the canonical `TaskState`.
35
+ *
36
+ * @param nativeState - The raw state string from a Codex event.
37
+ * @returns The canonical `TaskState`, or `undefined` if the state is unknown.
38
+ */
39
+ declare function mapCodexState(nativeState: string): TaskState | undefined;
40
+ /**
41
+ * Map a Codex native state to canonical, throwing if the state is unknown.
42
+ *
43
+ * @param nativeState - The raw state string from a Codex event.
44
+ * @returns The canonical `TaskState`.
45
+ * @throws {Error} If the state cannot be mapped.
46
+ */
47
+ declare function mapCodexStateStrict(nativeState: string): TaskState;
48
+ /**
49
+ * Map a canonical `TaskState` back to the primary Codex native state.
50
+ *
51
+ * @param canonicalState - The canonical task state.
52
+ * @returns The Codex native state string.
53
+ */
54
+ declare function canonicalToCodexState(canonicalState: TaskState): CodexNativeState;
55
+ /**
56
+ * Native states reported by the Claude Code CLI / API adapter.
57
+ * These are the raw status strings that appear in Claude Code events.
58
+ */
59
+ type ClaudeNativeState = 'pending' | 'streaming' | 'processing' | 'waiting_for_approval' | 'waiting_for_input' | 'done' | 'completed' | 'error' | 'failed' | 'aborted' | 'cancelled' | 'timeout';
60
+ /**
61
+ * Map a Claude Code native state string to the canonical `TaskState`.
62
+ *
63
+ * @param nativeState - The raw state string from a Claude Code event.
64
+ * @returns The canonical `TaskState`, or `undefined` if the state is unknown.
65
+ */
66
+ declare function mapClaudeState(nativeState: string): TaskState | undefined;
67
+ /**
68
+ * Map a Claude Code native state to canonical, throwing if the state is unknown.
69
+ *
70
+ * @param nativeState - The raw state string from a Claude Code event.
71
+ * @returns The canonical `TaskState`.
72
+ * @throws {Error} If the state cannot be mapped.
73
+ */
74
+ declare function mapClaudeStateStrict(nativeState: string): TaskState;
75
+ /**
76
+ * Map a canonical `TaskState` back to the primary Claude Code native state.
77
+ *
78
+ * @param canonicalState - The canonical task state.
79
+ * @returns The Claude Code native state string.
80
+ */
81
+ declare function canonicalToClaudeState(canonicalState: TaskState): ClaudeNativeState;
82
+ /**
83
+ * Map a native state from any supported connector to canonical `TaskState`.
84
+ *
85
+ * @param platform - The connector platform identifier.
86
+ * @param nativeState - The raw state string from the connector.
87
+ * @returns The canonical `TaskState`, or `undefined` if unmappable.
88
+ */
89
+ declare function mapConnectorState(platform: ConnectorPlatform, nativeState: string): TaskState | undefined;
90
+ /**
91
+ * Map a native state from any supported connector to canonical `TaskState`,
92
+ * throwing if the mapping fails.
93
+ *
94
+ * @param platform - The connector platform identifier.
95
+ * @param nativeState - The raw state string from the connector.
96
+ * @returns The canonical `TaskState`.
97
+ * @throws {Error} If the platform or state is unknown.
98
+ */
99
+ declare function mapConnectorStateStrict(platform: ConnectorPlatform, nativeState: string): TaskState;
100
+ /**
101
+ * Map a canonical `TaskState` back to the primary native state for a given
102
+ * connector platform.
103
+ *
104
+ * @param platform - The connector platform identifier.
105
+ * @param canonicalState - The canonical task state.
106
+ * @returns The native state string, or `undefined` if the platform is unknown.
107
+ */
108
+ declare function canonicalToConnectorState(platform: ConnectorPlatform, canonicalState: TaskState): string | undefined;
109
+ /**
110
+ * Given the current canonical state and a new native state from a connector,
111
+ * determine whether the implied transition is valid according to the
112
+ * canonical lifecycle rules.
113
+ *
114
+ * This is the main "guard" function that adapters should call before
115
+ * applying a state update from a connector event.
116
+ *
117
+ * @param currentCanonical - The current canonical task state.
118
+ * @param platform - The connector platform identifier.
119
+ * @param newNativeState - The new native state reported by the connector.
120
+ * @returns An object indicating whether the transition is valid, the mapped
121
+ * canonical state, and an error message if invalid.
122
+ */
123
+ declare function checkConnectorTransition(currentCanonical: TaskState, platform: ConnectorPlatform, newNativeState: string): {
124
+ valid: boolean;
125
+ mappedState: TaskState | undefined;
126
+ error?: string;
127
+ };
128
+ /**
129
+ * Check whether a connector-reported native state maps to a terminal
130
+ * canonical state.
131
+ *
132
+ * @param platform - The connector platform identifier.
133
+ * @param nativeState - The native state to check.
134
+ * @returns `true` if the mapped canonical state is terminal; `false` if
135
+ * non-terminal or unmappable.
136
+ */
137
+ declare function isConnectorTerminalState(platform: ConnectorPlatform, nativeState: string): boolean;
138
+
139
+ export { type ClaudeNativeState, type CodexNativeState, type ConnectorPlatform, canonicalToClaudeState, canonicalToCodexState, canonicalToConnectorState, checkConnectorTransition, isConnectorTerminalState, mapClaudeState, mapClaudeStateStrict, mapCodexState, mapCodexStateStrict, mapConnectorState, mapConnectorStateStrict };