@onesi/genesis 0.0.0-stage → 0.1.13

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 (87) hide show
  1. package/README.md +28 -2
  2. package/dist/beacons.d.ts +103 -0
  3. package/dist/beacons.js +77 -0
  4. package/dist/blinds-owner-enrollment.d.ts +171 -0
  5. package/dist/blinds-owner-enrollment.js +150 -0
  6. package/dist/client.d.ts +19996 -0
  7. package/dist/client.js +277 -0
  8. package/dist/context.d.ts +50 -0
  9. package/dist/context.js +153 -0
  10. package/dist/dials.d.ts +299 -0
  11. package/dist/dials.js +100 -0
  12. package/dist/errors.d.ts +35 -0
  13. package/dist/errors.js +66 -0
  14. package/dist/flares.d.ts +170 -0
  15. package/dist/flares.js +56 -0
  16. package/dist/fleets.d.ts +186 -0
  17. package/dist/fleets.js +136 -0
  18. package/dist/flocks.d.ts +155 -0
  19. package/dist/flocks.js +39 -0
  20. package/dist/foundry-billing.d.ts +97 -0
  21. package/dist/foundry-billing.js +107 -0
  22. package/dist/gears.d.ts +107 -0
  23. package/dist/gears.js +20 -0
  24. package/dist/generated/operations.d.ts +19949 -0
  25. package/dist/generated/operations.js +23846 -0
  26. package/dist/generated/schema.d.ts +35413 -0
  27. package/dist/generated/schema.js +1 -0
  28. package/dist/genesis.d.ts +2926 -0
  29. package/dist/genesis.js +206 -0
  30. package/dist/genesis.openapi.json +49321 -0
  31. package/dist/henry.d.ts +168 -0
  32. package/dist/henry.js +45 -0
  33. package/dist/hives-cells.d.ts +127 -0
  34. package/dist/hives-cells.js +151 -0
  35. package/dist/hives-environment.d.ts +28 -0
  36. package/dist/hives-environment.js +58 -0
  37. package/dist/hives-functions.d.ts +36 -0
  38. package/dist/hives-functions.js +185 -0
  39. package/dist/hives-marketplace.d.ts +128 -0
  40. package/dist/hives-marketplace.js +187 -0
  41. package/dist/hives-node.d.ts +9 -0
  42. package/dist/hives-node.js +152 -0
  43. package/dist/hives-operations.d.ts +337 -0
  44. package/dist/hives-operations.js +41 -0
  45. package/dist/hives-queue-consumer.d.ts +56 -0
  46. package/dist/hives-queue-consumer.js +95 -0
  47. package/dist/hives-queue-funding.d.ts +28 -0
  48. package/dist/hives-queue-funding.js +81 -0
  49. package/dist/hives-queues.d.ts +137 -0
  50. package/dist/hives-queues.js +143 -0
  51. package/dist/hives-resources-transport.d.ts +23 -0
  52. package/dist/hives-resources-transport.js +204 -0
  53. package/dist/hives-response.d.ts +2 -0
  54. package/dist/hives-response.js +32 -0
  55. package/dist/hives-runtimes.d.ts +34 -0
  56. package/dist/hives-runtimes.js +32 -0
  57. package/dist/hives-topics.d.ts +51 -0
  58. package/dist/hives-topics.js +79 -0
  59. package/dist/hives-upload.d.ts +9 -0
  60. package/dist/hives-upload.js +23 -0
  61. package/dist/hives-volumes.d.ts +64 -0
  62. package/dist/hives-volumes.js +117 -0
  63. package/dist/idempotency.d.ts +4 -0
  64. package/dist/idempotency.js +17 -0
  65. package/dist/index.d.ts +33 -0
  66. package/dist/index.js +25 -0
  67. package/dist/instances.d.ts +25 -0
  68. package/dist/instances.js +11 -0
  69. package/dist/lanes.d.ts +267 -0
  70. package/dist/lanes.js +41 -0
  71. package/dist/minds-agent.d.ts +60 -0
  72. package/dist/minds-agent.js +190 -0
  73. package/dist/minds-owner.d.ts +110 -0
  74. package/dist/minds-owner.js +226 -0
  75. package/dist/minds.d.ts +269 -0
  76. package/dist/minds.js +193 -0
  77. package/dist/relays-enrollment.d.ts +33 -0
  78. package/dist/relays-enrollment.js +115 -0
  79. package/dist/runner-grant.d.ts +10 -0
  80. package/dist/runner-grant.js +133 -0
  81. package/dist/runner.d.ts +68 -0
  82. package/dist/runner.js +116 -0
  83. package/dist/types.d.ts +87 -0
  84. package/dist/types.js +1 -0
  85. package/dist/urls.d.ts +6 -0
  86. package/dist/urls.js +31 -0
  87. package/package.json +46 -3
@@ -0,0 +1,299 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import type { OperationInput } from './types.js';
3
+ import type { components } from './generated/schema.js';
4
+ export type DialsScope = components['schemas']['Dials.Scope'];
5
+ export type DialsCallControl = components['schemas']['Dials.CallControl'];
6
+ /** The public call contract requires customer-selected behavior for every caller. */
7
+ export type DialsOutboundCall = components['schemas']['Dials.OutboundCall'];
8
+ export type DialsOutboundCallReceipt = components['schemas']['Dials.OutboundCallReceipt'];
9
+ export type DialsRecoveredOutboundCallReceipt = components['schemas']['Dials.RecoveredOutboundCallReceipt'];
10
+ export type DialsEmergencyAddress = components['schemas']['Dials.RegisterEmergencyAddress'];
11
+ export type DialsCallListItem = components['schemas']['Dials.CallListItem'];
12
+ export type DialsCallDispatchState = components['schemas']['Dials.CallDispatchState'];
13
+ export type DialsMessage = components['schemas']['Dials.MessageEvent'];
14
+ export type DialsMessageTemplate = components['schemas']['Dials.MessageTemplate'];
15
+ export type DialsMessagingBrand = components['schemas']['Dials.MessagingBrand'];
16
+ export type DialsMessagingCampaign = components['schemas']['Dials.MessagingCampaign'];
17
+ export type DialsWorkflowDocument = components['schemas']['Dials.WorkflowDocument'];
18
+ export type DialsRoutingAction = components['schemas']['Dials.RoutingAction'];
19
+ export type DialsRoutingRule = components['schemas']['Dials.RoutingRule'];
20
+ export type DialsRoutingRuleReceipt = components['schemas']['Dials.RoutingRuleReceipt'];
21
+ /** Scope is selection only; the Dials backend verifies its org against signed identity. */
22
+ export declare function dialsModule(client: GenesisClient): {
23
+ routing: {
24
+ list: (scope: DialsScope) => Promise<{
25
+ ok: true;
26
+ scope: components["schemas"]["Dials.Scope"];
27
+ rules: components["schemas"]["Dials.RoutingRule"][];
28
+ }>;
29
+ create: (body: OperationInput<"dials_createRoutingRule">["body"]) => Promise<{
30
+ ok: true;
31
+ rule: components["schemas"]["Dials.RoutingRule"];
32
+ auditId: string;
33
+ idempotentReplay: boolean;
34
+ }>;
35
+ disable: (ruleId: string, body: OperationInput<"dials_disableRoutingRule">["body"]) => Promise<{
36
+ ok: true;
37
+ rule: components["schemas"]["Dials.RoutingRule"];
38
+ auditId: string | null;
39
+ idempotentReplay: boolean;
40
+ }>;
41
+ };
42
+ people: {
43
+ list: (scope: DialsScope) => Promise<{
44
+ ok: boolean;
45
+ humans: components["schemas"]["Dials.HumanProfile"][];
46
+ }>;
47
+ create: (body: OperationInput<"dials_createHumanProfile">["body"]) => Promise<{
48
+ ok: boolean;
49
+ human: components["schemas"]["Dials.HumanProfile"];
50
+ auditId: string;
51
+ usageEventId: string;
52
+ next: string;
53
+ }>;
54
+ };
55
+ agents: {
56
+ list: (scope: DialsScope) => Promise<{
57
+ ok: boolean;
58
+ agents: components["schemas"]["Dials.AgentProfile"][];
59
+ }>;
60
+ create: (body: OperationInput<"dials_createAgent">["body"]) => Promise<{
61
+ ok: boolean;
62
+ agent: components["schemas"]["Dials.AgentProfile"];
63
+ auditId: string;
64
+ usageEventId: string;
65
+ next: string;
66
+ }>;
67
+ };
68
+ voice: {
69
+ list: (scope: DialsScope) => Promise<{
70
+ ok: boolean;
71
+ voiceProfiles: components["schemas"]["Dials.VoiceProfile"][];
72
+ }>;
73
+ create: (body: OperationInput<"dials_createVoiceProfile">["body"]) => Promise<{
74
+ ok: boolean;
75
+ voiceProfile: components["schemas"]["Dials.VoiceProfile"];
76
+ auditId: string;
77
+ usageEventId: string;
78
+ next: string;
79
+ }>;
80
+ };
81
+ messages: {
82
+ list: (scope: DialsScope) => Promise<{
83
+ ok: boolean;
84
+ messages: components["schemas"]["Dials.MessageEvent"][];
85
+ }>;
86
+ send: (body: OperationInput<"dials_createOutboundMessage">["body"]) => Promise<{
87
+ ok: boolean;
88
+ message: components["schemas"]["Dials.MessageEvent"];
89
+ auditId: string;
90
+ usageEventId: string;
91
+ next: string;
92
+ idempotentReplay: boolean;
93
+ }>;
94
+ templates: {
95
+ list: (scope: DialsScope) => Promise<{
96
+ ok: boolean;
97
+ templates: components["schemas"]["Dials.MessageTemplate"][];
98
+ }>;
99
+ create: (body: OperationInput<"dials_createMessageTemplate">["body"]) => Promise<{
100
+ ok: boolean;
101
+ template: components["schemas"]["Dials.MessageTemplate"];
102
+ auditId: string;
103
+ usageEventId: string;
104
+ next: string;
105
+ }>;
106
+ };
107
+ brands: {
108
+ list: (scope: DialsScope) => Promise<{
109
+ ok: boolean;
110
+ brands: components["schemas"]["Dials.MessagingBrand"][];
111
+ }>;
112
+ create: (body: OperationInput<"dials_createMessagingBrand">["body"]) => Promise<{
113
+ ok: boolean;
114
+ brand: components["schemas"]["Dials.MessagingBrand"];
115
+ auditId: string;
116
+ next: string;
117
+ }>;
118
+ };
119
+ campaigns: {
120
+ list: (scope: DialsScope) => Promise<{
121
+ ok: boolean;
122
+ campaigns: components["schemas"]["Dials.MessagingCampaign"][];
123
+ }>;
124
+ create: (body: OperationInput<"dials_createMessagingCampaign">["body"]) => Promise<{
125
+ ok: boolean;
126
+ campaign: components["schemas"]["Dials.MessagingCampaign"];
127
+ auditId: string;
128
+ next: string;
129
+ }>;
130
+ assignNumber: (campaignId: string, body: OperationInput<"dials_assignCampaignNumber">["body"]) => Promise<{
131
+ ok: boolean;
132
+ campaignId: string;
133
+ phoneNumberId: string;
134
+ auditId: string;
135
+ next: string;
136
+ }>;
137
+ };
138
+ };
139
+ workflows: {
140
+ list: (scope: DialsScope) => Promise<{
141
+ ok: boolean;
142
+ workflows: components["schemas"]["Dials.WorkflowDocument"][];
143
+ }>;
144
+ deploy: (body: OperationInput<"dials_deployWorkflow">["body"]) => Promise<{
145
+ ok: boolean;
146
+ workflow: components["schemas"]["Dials.WorkflowDocument"];
147
+ auditId: string;
148
+ usageEventId: string;
149
+ next: string;
150
+ route: components["schemas"]["Dials.RoutingRule"];
151
+ }>;
152
+ };
153
+ overview: {
154
+ summary: (scope: DialsScope) => Promise<{
155
+ ok: boolean;
156
+ scope: components["schemas"]["Dials.Scope"];
157
+ calls: {
158
+ total: number;
159
+ queued: number;
160
+ active: number;
161
+ completed: number;
162
+ failed: number;
163
+ };
164
+ dispatch: {
165
+ total: number;
166
+ pending: number;
167
+ claimed: number;
168
+ dispatched: number;
169
+ failed: number;
170
+ };
171
+ people: {
172
+ deployed: number;
173
+ };
174
+ agents: {
175
+ deployed: number;
176
+ };
177
+ routes: {
178
+ deployed: number;
179
+ };
180
+ numbers: {
181
+ deployed: number;
182
+ };
183
+ voice: {
184
+ deployed: number;
185
+ };
186
+ messages: {
187
+ total: number;
188
+ queued: number;
189
+ delivered: number;
190
+ failed: number;
191
+ };
192
+ usage: {
193
+ total: number;
194
+ quantity: number;
195
+ lastMetric: string | null;
196
+ lastResourceId: string | null;
197
+ };
198
+ }>;
199
+ operatingSurface: (scope: DialsScope) => Promise<{
200
+ ok: boolean;
201
+ scope: components["schemas"]["Dials.Scope"];
202
+ summary: components["schemas"]["Dials.ConsoleSummary"];
203
+ surfaces: components["schemas"]["Dials.OperatingSurfaceCard"][];
204
+ } & {
205
+ [key: string]: unknown;
206
+ }>;
207
+ };
208
+ numbers: {
209
+ reconciliations: (scope: DialsScope) => Promise<{
210
+ ok: boolean;
211
+ reconciliations: components["schemas"]["Dials.InventoryReconciliation"][];
212
+ }>;
213
+ drift: (scope: DialsScope) => Promise<{
214
+ ok: boolean;
215
+ drift: components["schemas"]["Dials.InventoryDrift"][];
216
+ }>;
217
+ updateCallerName: (body: OperationInput<"dials_updateNumberCallerName">["body"]) => Promise<{
218
+ ok: boolean;
219
+ number: components["schemas"]["Dials.Number"];
220
+ auditId: string;
221
+ next: string;
222
+ }>;
223
+ reconcile: (body: OperationInput<"dials_reconcileNumberInventory">["body"]) => Promise<{
224
+ ok: boolean;
225
+ reconciliations: components["schemas"]["Dials.InventoryReconciliation"][];
226
+ drift: components["schemas"]["Dials.InventoryDrift"][];
227
+ orphanCount: number;
228
+ auditId: string;
229
+ next: string;
230
+ }>;
231
+ list: (scope: DialsScope) => Promise<{
232
+ ok: boolean;
233
+ numbers: components["schemas"]["Dials.Number"][];
234
+ }>;
235
+ search: (scope: DialsScope, query?: Omit<OperationInput<"dials_searchNumbers">, keyof DialsScope>) => Promise<{
236
+ ok: boolean;
237
+ numbers: components["schemas"]["Dials.AvailableNumber"][];
238
+ }>;
239
+ provision: (body: OperationInput<"dials_provisionNumber">["body"]) => Promise<{
240
+ [key: string]: unknown;
241
+ }>;
242
+ assign: (body: OperationInput<"dials_assignNumber">["body"]) => Promise<{
243
+ [key: string]: unknown;
244
+ }>;
245
+ delete: (input: OperationInput<"dials_deleteNumber">) => Promise<{
246
+ ok: boolean;
247
+ number: components["schemas"]["Dials.Number"];
248
+ auditId: string;
249
+ usageEventId: string;
250
+ next: string;
251
+ }>;
252
+ release: (body: OperationInput<"dials_releaseNumber">["body"]) => Promise<{
253
+ [key: string]: unknown;
254
+ }>;
255
+ registerEmergencyAddress: (body: DialsEmergencyAddress) => Promise<{
256
+ ok: boolean;
257
+ number: components["schemas"]["Dials.Number"];
258
+ address: components["schemas"]["Dials.EmergencyAddress"];
259
+ auditId: string;
260
+ next: string;
261
+ }>;
262
+ };
263
+ calls: {
264
+ list: (scope: DialsScope) => Promise<{
265
+ ok: boolean;
266
+ calls: components["schemas"]["Dials.CallListItem"][];
267
+ }>;
268
+ validate: (body: DialsOutboundCall) => Promise<{
269
+ [key: string]: unknown;
270
+ }>;
271
+ create: (body: DialsOutboundCall) => Promise<{
272
+ ok: boolean;
273
+ call: components["schemas"]["Dials.CallSession"];
274
+ auditId: string;
275
+ dispatchJobId: string;
276
+ usageEventId: string;
277
+ next: string;
278
+ idempotentReplay: boolean;
279
+ } & {
280
+ [key: string]: unknown;
281
+ }>;
282
+ recover: (body: DialsOutboundCall) => Promise<{
283
+ ok: boolean;
284
+ call: components["schemas"]["Dials.CallSession"];
285
+ auditId: string;
286
+ dispatchJobId: string;
287
+ usageEventId: string;
288
+ next: string;
289
+ idempotentReplay: boolean;
290
+ } & {
291
+ [key: string]: unknown;
292
+ } & {
293
+ idempotentReplay: true;
294
+ }>;
295
+ };
296
+ };
297
+ export type DialsEmergencyAddressFeedback = components['schemas']['Dials.EmergencyAddressFeedback'];
298
+ /** Read bounded, typed advisory feedback from the existing Genesis error. Never auto-apply it. */
299
+ export declare function dialsEmergencyAddressFeedback(error: unknown): DialsEmergencyAddressFeedback | undefined;
package/dist/dials.js ADDED
@@ -0,0 +1,100 @@
1
+ import { errorToken, GenesisError } from './errors.js';
2
+ /** Scope is selection only; the Dials backend verifies its org against signed identity. */
3
+ export function dialsModule(client) {
4
+ return {
5
+ routing: {
6
+ list: (scope) => client.request('dials_listRoutingRules', scope),
7
+ create: (body) => client.request('dials_createRoutingRule', { body }),
8
+ disable: (ruleId, body) => client.request('dials_disableRoutingRule', { rule_id: ruleId, body }),
9
+ },
10
+ people: {
11
+ list: (scope) => client.request('dials_listHumanProfiles', scope),
12
+ create: (body) => client.request('dials_createHumanProfile', { body }),
13
+ },
14
+ agents: {
15
+ list: (scope) => client.request('dials_listAgents', scope),
16
+ create: (body) => client.request('dials_createAgent', { body }),
17
+ },
18
+ voice: {
19
+ list: (scope) => client.request('dials_listVoiceProfiles', scope),
20
+ create: (body) => client.request('dials_createVoiceProfile', { body }),
21
+ },
22
+ messages: {
23
+ list: (scope) => client.request('dials_listMessages', scope),
24
+ send: (body) => client.request('dials_createOutboundMessage', { body }),
25
+ templates: {
26
+ list: (scope) => client.request('dials_listMessageTemplates', scope),
27
+ create: (body) => client.request('dials_createMessageTemplate', { body }),
28
+ },
29
+ brands: {
30
+ list: (scope) => client.request('dials_listMessagingBrands', scope),
31
+ create: (body) => client.request('dials_createMessagingBrand', { body }),
32
+ },
33
+ campaigns: {
34
+ list: (scope) => client.request('dials_listMessagingCampaigns', scope),
35
+ create: (body) => client.request('dials_createMessagingCampaign', { body }),
36
+ assignNumber: (campaignId, body) => client.request('dials_assignCampaignNumber', { campaign_id: campaignId, body }),
37
+ },
38
+ },
39
+ workflows: {
40
+ list: (scope) => client.request('dials_listWorkflows', scope),
41
+ deploy: (body) => client.request('dials_deployWorkflow', { body }),
42
+ },
43
+ overview: {
44
+ summary: (scope) => client.request('dials_getConsoleSummary', scope),
45
+ operatingSurface: (scope) => client.request('dials_getOperatingSurface', scope),
46
+ },
47
+ numbers: {
48
+ reconciliations: (scope) => client.request('dials_listNumberReconciliations', scope),
49
+ drift: (scope) => client.request('dials_listNumberDrift', scope),
50
+ updateCallerName: (body) => client.request('dials_updateNumberCallerName', { body }),
51
+ reconcile: (body) => client.request('dials_reconcileNumberInventory', { body }),
52
+ list: (scope) => client.request('dials_listNumbers', scope),
53
+ search: (scope, query = {}) => client.request('dials_searchNumbers', { ...query, ...scope }),
54
+ provision: (body) => client.request('dials_provisionNumber', { body }),
55
+ assign: (body) => client.request('dials_assignNumber', { body }),
56
+ delete: (input) => client.request('dials_deleteNumber', input),
57
+ release: (body) => client.request('dials_releaseNumber', { body }),
58
+ registerEmergencyAddress: (body) => client.request('dials_registerEmergencyAddress', { body }),
59
+ },
60
+ calls: {
61
+ list: (scope) => client.request('dials_listCalls', scope),
62
+ validate: (body) => client.request('dials_validateOutboundCall', { body }),
63
+ create: (body) => client.request('dials_createOutboundCall', { body }),
64
+ recover: (body) => client.request('dials_recoverOutboundCall', { body }),
65
+ },
66
+ };
67
+ }
68
+ const fields = { streetNumber: 'Review the street number.', streetName: 'Review the street name.', addressLine2: 'Review the suite or unit type and number.', city: 'Review the city.', region: 'Review the state.', postalCode: 'Review the postal code.', country: 'Review the country.', address: 'The carrier could not validate this address. Review the address and any suggestions.' };
69
+ const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
70
+ const addressText = (value, max) => typeof value === 'string' && value.length > 0 && value.length <= max && /^[\p{L}\p{N} .,'#/-]+$/u.test(value) && !/(bearer|basic |sk_|api_key|authorization|secret|token=)/i.test(value);
71
+ /** Read bounded, typed advisory feedback from the existing Genesis error. Never auto-apply it. */
72
+ export function dialsEmergencyAddressFeedback(error) {
73
+ if (!(error instanceof GenesisError) || error.status !== 422 || error.operationId !== 'dials_registerEmergencyAddress')
74
+ return;
75
+ const body = error.body;
76
+ // The gateway sends the envelope (error.code CARRIER_REJECTED) with the advisory fields beside it; older bodies use the string form.
77
+ if (!object(body) || errorToken(body) !== 'carrier_rejected' || body.automaticCorrection !== false || !Array.isArray(body.fieldErrors) || !body.fieldErrors.length || body.fieldErrors.length > 8 || !Array.isArray(body.candidates) || body.candidates.length > 5)
78
+ return;
79
+ const fieldErrors = [];
80
+ for (const value of body.fieldErrors) {
81
+ if (!object(value) || typeof value.field !== 'string' || !Object.hasOwn(fields, value.field) || !['required', 'invalid', 'not_found', 'ambiguous', 'not_validated'].includes(String(value.code)))
82
+ return;
83
+ const field = value.field;
84
+ fieldErrors.push({ field, code: value.code, message: fields[field] });
85
+ }
86
+ const candidates = [];
87
+ for (const value of body.candidates) {
88
+ if (!object(value) || !addressText(value.streetNumber, 32) || !addressText(value.streetName, 128) || !addressText(value.city, 80) || typeof value.region !== 'string' || !/^[A-Za-z]{2}$/.test(value.region) || typeof value.postalCode !== 'string' || !/^\d{5}(?:-\d{4})?$/.test(value.postalCode))
89
+ return;
90
+ const extra = {};
91
+ if (value.addressType !== undefined || value.addressNumber !== undefined) {
92
+ if (!['Apartment', 'Basement', 'Building', 'Department', 'Floor', 'Office', 'Penthouse', 'Suite', 'Trailer', 'Unit'].includes(String(value.addressType)) || !addressText(value.addressNumber, 32))
93
+ return;
94
+ extra.addressType = value.addressType;
95
+ extra.addressNumber = value.addressNumber;
96
+ }
97
+ candidates.push({ streetNumber: value.streetNumber, streetName: value.streetName, city: value.city, region: value.region, postalCode: value.postalCode, ...extra });
98
+ }
99
+ return { automaticCorrection: false, fieldErrors, candidates };
100
+ }
@@ -0,0 +1,35 @@
1
+ /** Normalized error for every Genesis service (gateway `{error:{type,message}}`, IAM `{error,error_description}`, Relays `{error}`, Foundry/OpenAI shape). */
2
+ export declare class GenesisError extends Error {
3
+ readonly status: number;
4
+ readonly type: string;
5
+ readonly code?: string;
6
+ readonly requestId?: string;
7
+ readonly operationId?: string;
8
+ readonly body: unknown;
9
+ constructor(init: {
10
+ status: number;
11
+ type: string;
12
+ message: string;
13
+ code?: string;
14
+ requestId?: string;
15
+ operationId?: string;
16
+ body?: unknown;
17
+ });
18
+ static fromResponse(res: Response, operationId?: string): Promise<GenesisError>;
19
+ }
20
+ /** The gateway catalog fields of an error, for JSON output: `code`, `required_scope` and `docs_url` when the gateway sent them. */
21
+ export declare function errorCatalog(e: GenesisError): {
22
+ code?: string;
23
+ required_scope?: string;
24
+ docs_url?: string;
25
+ };
26
+ /**
27
+ * The refusal code of an error body in either form: the one Genesis envelope (`error.code`) or a
28
+ * legacy string (`{"error":"carrier_rejected"}`), lower-cased so `CARRIER_REJECTED` and `carrier_rejected` match.
29
+ */
30
+ export declare function errorToken(body: unknown): string | undefined;
31
+ /** An error body's dispatch outcome, from `error.outcome` (envelope) or the top level (legacy). */
32
+ export declare function errorOutcome(body: unknown): string | undefined;
33
+ /** Optional fields the gateway adds to an envelope; each must be a bounded string when present. */
34
+ export declare const ENVELOPE_EXTRA_FIELDS: readonly string[];
35
+ export declare const envelopeExtrasValid: (error: Record<string, unknown>) => boolean;
package/dist/errors.js ADDED
@@ -0,0 +1,66 @@
1
+ /** Normalized error for every Genesis service (gateway `{error:{type,message}}`, IAM `{error,error_description}`, Relays `{error}`, Foundry/OpenAI shape). */
2
+ export class GenesisError extends Error {
3
+ status;
4
+ type;
5
+ code;
6
+ requestId;
7
+ operationId;
8
+ body;
9
+ constructor(init) {
10
+ super(init.message);
11
+ this.name = 'GenesisError';
12
+ Object.assign(this, init);
13
+ this.status = init.status;
14
+ this.type = init.type;
15
+ this.body = init.body;
16
+ }
17
+ static async fromResponse(res, operationId) {
18
+ const text = await res.text().catch(() => '');
19
+ let body = text;
20
+ try {
21
+ body = text ? JSON.parse(text) : undefined;
22
+ }
23
+ catch { /* keep text */ }
24
+ const e = body?.error;
25
+ // An OAuth-style token (`{"error":"forbidden"}`) is the type; any other string is a message, and type stays a stable token.
26
+ const type = typeof e === 'object' && e ? (e.type ?? e.code ?? 'error')
27
+ : typeof e === 'string' && /^[a-z][a-z0-9_]{0,63}$/.test(e) ? e : statusType(res.status);
28
+ const message = (typeof e === 'object' && e?.message) || body?.error_description || body?.message ||
29
+ (typeof e === 'string' && e) || (typeof body === 'string' && body) || `${res.status} ${res.statusText}`;
30
+ return new GenesisError({
31
+ status: res.status, type, message, code: typeof e === 'object' ? e?.code : undefined,
32
+ requestId: res.headers.get('x-request-id') ?? (typeof e === 'object' ? e?.request_id : undefined) ?? body?.request_id,
33
+ operationId, body,
34
+ });
35
+ }
36
+ }
37
+ const statusType = (s) => s === 401 ? 'unauthorized' : s === 403 ? 'forbidden' : s === 404 ? 'not_found' : s === 429 ? 'rate_limited' : s >= 500 ? 'upstream_error' : 'error';
38
+ /** The gateway catalog fields of an error, for JSON output: `code`, `required_scope` and `docs_url` when the gateway sent them. */
39
+ export function errorCatalog(e) {
40
+ const body = e.body && typeof e.body === 'object' ? e.body.error : undefined;
41
+ const field = (k) => { const v = body && typeof body === 'object' ? body[k] : undefined; return typeof v === 'string' ? v : undefined; };
42
+ const scope = field('required_scope'), docs = field('docs_url');
43
+ return { ...(typeof e.code === 'string' && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/.test(e.code) ? { code: e.code } : {}), ...(scope ? { required_scope: scope } : {}),
44
+ ...(docs && /^https:\/\/[a-z0-9.-]+\/[^\s]{0,256}$/i.test(docs) ? { docs_url: docs } : {}) };
45
+ }
46
+ const row = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
47
+ /**
48
+ * The refusal code of an error body in either form: the one Genesis envelope (`error.code`) or a
49
+ * legacy string (`{"error":"carrier_rejected"}`), lower-cased so `CARRIER_REJECTED` and `carrier_rejected` match.
50
+ */
51
+ export function errorToken(body) {
52
+ if (!row(body))
53
+ return undefined;
54
+ const value = typeof body.error === 'string' ? body.error : row(body.error) && typeof body.error.code === 'string' ? body.error.code : undefined;
55
+ return value && /^[A-Za-z][A-Za-z0-9_.:-]{0,127}$/.test(value) ? value.toLowerCase() : undefined;
56
+ }
57
+ /** An error body's dispatch outcome, from `error.outcome` (envelope) or the top level (legacy). */
58
+ export function errorOutcome(body) {
59
+ if (!row(body))
60
+ return undefined;
61
+ const nested = row(body.error) && typeof body.error.outcome === 'string' ? body.error.outcome : undefined;
62
+ return nested ?? (typeof body.outcome === 'string' ? body.outcome : undefined);
63
+ }
64
+ /** Optional fields the gateway adds to an envelope; each must be a bounded string when present. */
65
+ export const ENVELOPE_EXTRA_FIELDS = ['type', 'message', 'docs_url', 'layer', 'reason', 'required_scope'];
66
+ export const envelopeExtrasValid = (error) => ENVELOPE_EXTRA_FIELDS.every(name => error[name] === undefined || typeof error[name] === 'string' && error[name].length <= 2048);
@@ -0,0 +1,170 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import type { OperationInput as In } from './types.js';
3
+ /** Flares v2 (Sandbox): flares, conversations, commitments, presence, trust and choreography.
4
+ * Every mutation needs one stable idempotency key; reuse it to replay instead of acting twice. */
5
+ export declare function flaresModule(client: GenesisClient): {
6
+ list: (q?: In<"flares_listFlares">) => Promise<({
7
+ id?: string;
8
+ status?: string;
9
+ flareType?: string;
10
+ recipientId?: string;
11
+ recipientType?: string;
12
+ priority?: string;
13
+ channels?: string[];
14
+ createdAt?: string;
15
+ updatedAt?: string;
16
+ deliveryReceipts?: {
17
+ [key: string]: unknown;
18
+ };
19
+ } & {
20
+ [key: string]: unknown;
21
+ })[]>;
22
+ get: (id: string) => Promise<{
23
+ id?: string;
24
+ status?: string;
25
+ flareType?: string;
26
+ recipientId?: string;
27
+ recipientType?: string;
28
+ priority?: string;
29
+ channels?: string[];
30
+ createdAt?: string;
31
+ updatedAt?: string;
32
+ deliveryReceipts?: {
33
+ [key: string]: unknown;
34
+ };
35
+ } & {
36
+ [key: string]: unknown;
37
+ }>;
38
+ send: (body: In<"flares_sendFlare">["body"], key: string) => Promise<{
39
+ id?: string;
40
+ status?: string;
41
+ }>;
42
+ sendBatch: (body: In<"flares_sendFlareBatch">["body"], key: string) => Promise<{
43
+ results?: import("./index.js").components["schemas"]["Flares.SendFlareResponse"][];
44
+ }>;
45
+ acknowledge: (id: string, body: In<"flares_acknowledgeFlare">["body"], key: string) => Promise<{
46
+ [key: string]: unknown;
47
+ }>;
48
+ act: (id: string, body: In<"flares_actOnFlare">["body"], key: string) => Promise<{
49
+ [key: string]: unknown;
50
+ }>;
51
+ conversations: {
52
+ list: () => Promise<{
53
+ [key: string]: unknown;
54
+ }[]>;
55
+ get: (id: string) => Promise<{
56
+ [key: string]: unknown;
57
+ }>;
58
+ create: (body: In<"flares_createConversation">["body"], key: string) => Promise<{
59
+ [key: string]: unknown;
60
+ }>;
61
+ send: (id: string, body: In<"flares_sendConversationMessage">["body"], key: string) => Promise<{
62
+ [key: string]: unknown;
63
+ }>;
64
+ close: (id: string, key: string) => Promise<{
65
+ [key: string]: unknown;
66
+ }>;
67
+ };
68
+ commitments: {
69
+ list: () => Promise<{
70
+ [key: string]: unknown;
71
+ }[]>;
72
+ get: (id: string) => Promise<{
73
+ [key: string]: unknown;
74
+ }>;
75
+ create: (body: In<"flares_createCommitment">["body"], key: string) => Promise<{
76
+ [key: string]: unknown;
77
+ }>;
78
+ accept: (id: string, key: string) => Promise<{
79
+ [key: string]: unknown;
80
+ }>;
81
+ start: (id: string, key: string) => Promise<{
82
+ [key: string]: unknown;
83
+ }>;
84
+ progress: (id: string, body: In<"flares_reportCommitmentProgress">["body"], key: string) => Promise<{
85
+ [key: string]: unknown;
86
+ }>;
87
+ fulfill: (id: string, body: In<"flares_fulfillCommitment">["body"], key: string) => Promise<{
88
+ [key: string]: unknown;
89
+ }>;
90
+ fail: (id: string, body: In<"flares_failCommitment">["body"], key: string) => Promise<{
91
+ [key: string]: unknown;
92
+ }>;
93
+ };
94
+ presence: {
95
+ heartbeat: (body: In<"flares_presenceHeartbeat">["body"], key: string) => Promise<{
96
+ did?: string;
97
+ status?: string;
98
+ sessionId?: string;
99
+ sessionCount?: number;
100
+ lastSeenAt?: string;
101
+ } & {
102
+ [key: string]: unknown;
103
+ }>;
104
+ get: (did: string) => Promise<{
105
+ did?: string;
106
+ status?: string;
107
+ sessionId?: string;
108
+ sessionCount?: number;
109
+ lastSeenAt?: string;
110
+ } & {
111
+ [key: string]: unknown;
112
+ }>;
113
+ };
114
+ trust: {
115
+ score: (did: string) => Promise<{
116
+ did?: string;
117
+ score?: number;
118
+ confidence?: number;
119
+ dataPoints?: number;
120
+ computedAt?: string;
121
+ expiresAt?: string;
122
+ trustLevel?: string;
123
+ endorsementCount?: number;
124
+ } & {
125
+ [key: string]: unknown;
126
+ }>;
127
+ check: (body: In<"flares_checkTrust">["body"], key: string) => Promise<{
128
+ [key: string]: unknown;
129
+ }>;
130
+ endorsements: (did: string) => Promise<{
131
+ [key: string]: unknown;
132
+ }[]>;
133
+ endorse: (body: In<"flares_createEndorsement">["body"], key: string) => Promise<{
134
+ [key: string]: unknown;
135
+ }>;
136
+ revoke: (id: string, key: string) => Promise<{
137
+ [key: string]: unknown;
138
+ }>;
139
+ };
140
+ choreography: {
141
+ workflows: {
142
+ list: () => Promise<{
143
+ [key: string]: unknown;
144
+ }[]>;
145
+ create: (body: In<"flares_createChoreographyWorkflow">["body"], key: string) => Promise<{
146
+ [key: string]: unknown;
147
+ }>;
148
+ start: (workflow_id: string, key: string) => Promise<{
149
+ [key: string]: unknown;
150
+ }>;
151
+ };
152
+ executions: {
153
+ list: () => Promise<{
154
+ [key: string]: unknown;
155
+ }[]>;
156
+ get: (execution_id: string) => Promise<{
157
+ [key: string]: unknown;
158
+ }>;
159
+ completeStep: (execution_id: string, step_id: string, body: In<"flares_completeChoreographyStep">["body"], key: string) => Promise<{
160
+ [key: string]: unknown;
161
+ }>;
162
+ failStep: (execution_id: string, step_id: string, body: In<"flares_failChoreographyStep">["body"], key: string) => Promise<{
163
+ [key: string]: unknown;
164
+ }>;
165
+ cancel: (execution_id: string, key: string) => Promise<{
166
+ [key: string]: unknown;
167
+ }>;
168
+ };
169
+ };
170
+ };