@onesi/genesis 0.0.1-stage → 0.2.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 (113) hide show
  1. package/README.md +29 -0
  2. package/dist/auto.d.ts +1010 -0
  3. package/dist/auto.js +125 -0
  4. package/dist/beacons.d.ts +145 -0
  5. package/dist/beacons.js +148 -0
  6. package/dist/blinds-owner-enrollment.d.ts +280 -0
  7. package/dist/blinds-owner-enrollment.js +169 -0
  8. package/dist/client.d.ts +52 -0
  9. package/dist/client.js +384 -0
  10. package/dist/context.d.ts +50 -0
  11. package/dist/context.js +153 -0
  12. package/dist/dials.d.ts +299 -0
  13. package/dist/dials.js +100 -0
  14. package/dist/errors.d.ts +35 -0
  15. package/dist/errors.js +66 -0
  16. package/dist/flares.d.ts +202 -0
  17. package/dist/flares.js +61 -0
  18. package/dist/fleets.d.ts +218 -0
  19. package/dist/fleets.js +189 -0
  20. package/dist/flocks.d.ts +439 -0
  21. package/dist/flocks.js +98 -0
  22. package/dist/foundry-billing.d.ts +97 -0
  23. package/dist/foundry-billing.js +107 -0
  24. package/dist/foundry.d.ts +424 -0
  25. package/dist/foundry.js +133 -0
  26. package/dist/garden.d.ts +754 -0
  27. package/dist/garden.js +76 -0
  28. package/dist/gateway.d.ts +365 -0
  29. package/dist/gateway.js +82 -0
  30. package/dist/gears.d.ts +226 -0
  31. package/dist/gears.js +42 -0
  32. package/dist/generated/operations.d.ts +4 -0
  33. package/dist/generated/operations.js +65134 -0
  34. package/dist/generated/schema.d.ts +87658 -0
  35. package/dist/generated/schema.js +1 -0
  36. package/dist/genesis.d.ts +9574 -0
  37. package/dist/genesis.js +271 -0
  38. package/dist/genesis.openapi.json +128522 -0
  39. package/dist/henry.d.ts +369 -0
  40. package/dist/henry.js +268 -0
  41. package/dist/hives-cells.d.ts +127 -0
  42. package/dist/hives-cells.js +151 -0
  43. package/dist/hives-environment.d.ts +37 -0
  44. package/dist/hives-environment.js +80 -0
  45. package/dist/hives-functions.d.ts +36 -0
  46. package/dist/hives-functions.js +185 -0
  47. package/dist/hives-marketplace.d.ts +128 -0
  48. package/dist/hives-marketplace.js +187 -0
  49. package/dist/hives-node.d.ts +9 -0
  50. package/dist/hives-node.js +155 -0
  51. package/dist/hives-operations.d.ts +451 -0
  52. package/dist/hives-operations.js +43 -0
  53. package/dist/hives-platform.d.ts +149 -0
  54. package/dist/hives-platform.js +183 -0
  55. package/dist/hives-queue-consumer.d.ts +56 -0
  56. package/dist/hives-queue-consumer.js +95 -0
  57. package/dist/hives-queue-funding.d.ts +28 -0
  58. package/dist/hives-queue-funding.js +81 -0
  59. package/dist/hives-queues.d.ts +137 -0
  60. package/dist/hives-queues.js +143 -0
  61. package/dist/hives-resources-transport.d.ts +23 -0
  62. package/dist/hives-resources-transport.js +204 -0
  63. package/dist/hives-response.d.ts +2 -0
  64. package/dist/hives-response.js +32 -0
  65. package/dist/hives-runtimes.d.ts +34 -0
  66. package/dist/hives-runtimes.js +32 -0
  67. package/dist/hives-sse.d.ts +24 -0
  68. package/dist/hives-sse.js +111 -0
  69. package/dist/hives-topics.d.ts +51 -0
  70. package/dist/hives-topics.js +79 -0
  71. package/dist/hives-upload.d.ts +9 -0
  72. package/dist/hives-upload.js +23 -0
  73. package/dist/hives-volumes.d.ts +64 -0
  74. package/dist/hives-volumes.js +117 -0
  75. package/dist/iam-directory.d.ts +8 -0
  76. package/dist/iam-directory.js +23 -0
  77. package/dist/iam.d.ts +391 -0
  78. package/dist/iam.js +92 -0
  79. package/dist/idempotency.d.ts +7 -0
  80. package/dist/idempotency.js +39 -0
  81. package/dist/index.d.ts +47 -0
  82. package/dist/index.js +37 -0
  83. package/dist/instances.d.ts +200 -0
  84. package/dist/instances.js +43 -0
  85. package/dist/lanes.d.ts +267 -0
  86. package/dist/lanes.js +41 -0
  87. package/dist/minds-agent.d.ts +88 -0
  88. package/dist/minds-agent.js +233 -0
  89. package/dist/minds-engine.d.ts +394 -0
  90. package/dist/minds-engine.js +555 -0
  91. package/dist/minds-owner.d.ts +110 -0
  92. package/dist/minds-owner.js +226 -0
  93. package/dist/minds.d.ts +377 -0
  94. package/dist/minds.js +228 -0
  95. package/dist/orgs.d.ts +405 -0
  96. package/dist/orgs.js +63 -0
  97. package/dist/relays-enrollment.d.ts +33 -0
  98. package/dist/relays-enrollment.js +115 -0
  99. package/dist/runner-grant.d.ts +10 -0
  100. package/dist/runner-grant.js +133 -0
  101. package/dist/runner.d.ts +72 -0
  102. package/dist/runner.js +117 -0
  103. package/dist/scopes.d.ts +310 -0
  104. package/dist/scopes.js +40 -0
  105. package/dist/taps.d.ts +118 -0
  106. package/dist/taps.js +45 -0
  107. package/dist/traces.d.ts +574 -0
  108. package/dist/traces.js +97 -0
  109. package/dist/types.d.ts +98 -0
  110. package/dist/types.js +1 -0
  111. package/dist/urls.d.ts +6 -0
  112. package/dist/urls.js +31 -0
  113. package/package.json +49 -1
@@ -0,0 +1,377 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import type { OperationInput, OperationOutput } from './types.js';
3
+ export declare const mindsOperations: readonly ["minds_listMinds", "minds_getMind", "minds_getUsage", "minds_createMind", "minds_resumeMind", "minds_stopMind", "minds_deleteMind", "minds_resizeMind", "minds_insertEpisodicMemory", "minds_getEpisodicMemory", "minds_updateEpisodicMemory", "minds_searchMemory", "minds_createWebhookDelivery", "minds_getWebhookDelivery"];
4
+ /** Engine service groups a create may choose (the controller's CREATE_SERVICES); kv and memory always run. */
5
+ export declare const mindsServices: readonly ["kv", "memory", "graph", "analytics", "ml", "inference", "vector", "snn", "continual", "associative-memory", "cognitive", "cognitive-cycle", "mcp"];
6
+ export type MindsService = typeof mindsServices[number];
7
+ export declare const isMindsOperation: (id: string) => boolean;
8
+ export type MindsEventInput = OperationInput<'minds_insertEpisodicMemory'>['body']['event'];
9
+ export type MindsUsage = OperationOutput<'minds_getUsage'>;
10
+ export type MindsWebhookDelivery = OperationInput<'minds_createWebhookDelivery'>['body'];
11
+ export type MindsWebhookDeliveryReceipt = OperationOutput<'minds_getWebhookDelivery'>;
12
+ export interface MindsRequestOptions {
13
+ signal?: AbortSignal;
14
+ }
15
+ export type MindsWakeReason = 'manual' | 'scheduled_job' | 'webhook' | 'memory_consolidation' | 'activity';
16
+ export interface MindsResumeOptions extends MindsRequestOptions {
17
+ idempotencyKey: string;
18
+ wakeReason?: MindsWakeReason;
19
+ }
20
+ export interface MindsStopOptions extends MindsRequestOptions {
21
+ idempotencyKey: string;
22
+ }
23
+ export type MindsDeleteOptions = MindsStopOptions;
24
+ export type MindsResizeOptions = MindsStopOptions;
25
+ export interface MindsCreateOptions extends MindsRequestOptions {
26
+ idempotencyKey: string;
27
+ contextSha256: string;
28
+ plan?: 'free' | 'pro';
29
+ profileId?: 'F1' | 'D1' | 'D2';
30
+ services?: MindsService[];
31
+ }
32
+ /** One dispatch only. Creation retains its operation key; episodic insertion returns a storage UUID distinct from event.id. */
33
+ export declare function mindsTransport(options: {
34
+ operationId: string;
35
+ input: Record<string, unknown>;
36
+ headers?: Record<string, string>;
37
+ routing: string;
38
+ url: string;
39
+ credential: () => Promise<string | undefined>;
40
+ fetch: typeof fetch;
41
+ signal?: AbortSignal;
42
+ }): Promise<Response>;
43
+ export declare function mindsModule(client: GenesisClient): {
44
+ agent: {
45
+ create: (input: import("./minds-agent.js").MindsAgentCreateInput, options: import("./minds-agent.js").MindsAgentCreateOptions) => Promise<{
46
+ mind_id: string;
47
+ status: string;
48
+ } & {
49
+ [key: string]: unknown;
50
+ }>;
51
+ createStatus: (operation_id: string, options: import("./minds-agent.js").MindsAgentCreateOptions) => Promise<{
52
+ mind_id: string;
53
+ status: string;
54
+ } & {
55
+ [key: string]: unknown;
56
+ }>;
57
+ memory: {
58
+ insert: (mind: string, event: import("./minds-agent.js").MindsAgentEventInput, options?: import("./minds-agent.js").MindsAgentOptions) => Promise<{
59
+ id: string;
60
+ }>;
61
+ get: (mind: string, storage_id: string, options?: import("./minds-agent.js").MindsAgentOptions) => Promise<{
62
+ item: import("./index.js").components["schemas"]["Minds.EpisodicEvent"] | null;
63
+ }>;
64
+ search: (mind: string, text: string, limit?: number, options?: import("./minds-agent.js").MindsAgentOptions) => Promise<({
65
+ id: string;
66
+ content: string;
67
+ timestamp: string;
68
+ event_type: "Conversation" | "Command" | "Query" | "Document" | "Error" | "Success" | "Learning" | "Decision" | "Action" | "Context" | "Knowledge";
69
+ summary?: string | null;
70
+ tags: string[];
71
+ } & {
72
+ [key: string]: unknown;
73
+ })[]>;
74
+ };
75
+ };
76
+ list: (query?: OperationInput<"minds_listMinds">, options?: MindsRequestOptions) => Promise<{
77
+ schema_version: "minds.controller.v1";
78
+ items: import("./index.js").components["schemas"]["Minds.Mind"][];
79
+ next_cursor: string | null;
80
+ context_sha256: string;
81
+ }>;
82
+ get: (mind_id: string, options?: MindsRequestOptions) => Promise<{
83
+ schema_version: "minds.controller.v1";
84
+ mind_id: string;
85
+ organization_id: string;
86
+ project_id: string;
87
+ name: string;
88
+ region: string;
89
+ plan: "free" | "pro";
90
+ capacity: import("./index.js").components["schemas"]["Minds.Capacity"];
91
+ observed_capacity: import("./index.js").components["schemas"]["Minds.Capacity"] | null;
92
+ services: string[];
93
+ volume_id: string;
94
+ base_url: string;
95
+ desired_state: "running" | "stopped" | "deleted";
96
+ observed_state: "pending" | "running" | "stopped" | "deleted" | "failed" | "uncertain";
97
+ desired_generation: number;
98
+ observed_generation: number;
99
+ status: "ready" | "provisioning" | "stopped" | "deleted" | "failed" | "uncertain";
100
+ capacity_applied: boolean;
101
+ operation_id: string | null;
102
+ error_code: string | null;
103
+ created_at: string;
104
+ updated_at: string;
105
+ } & {
106
+ [key: string]: unknown;
107
+ }>;
108
+ usage: (window: OperationInput<"minds_getUsage">, options?: MindsRequestOptions) => Promise<{
109
+ schema_version: "minds.controller.v1";
110
+ organization_id: string;
111
+ project_id: string;
112
+ from: string;
113
+ to: string;
114
+ measured_at: string;
115
+ basis: "host_confirmed_intervals";
116
+ minds: import("./index.js").components["schemas"]["Minds.UsageMind"][];
117
+ }>;
118
+ create: (name: string, options: MindsCreateOptions) => Promise<{
119
+ schema_version: "minds.controller.v1";
120
+ mind_id: string;
121
+ organization_id: string;
122
+ project_id: string;
123
+ name: string;
124
+ region: string;
125
+ plan: "free" | "pro";
126
+ capacity: import("./index.js").components["schemas"]["Minds.Capacity"];
127
+ observed_capacity: import("./index.js").components["schemas"]["Minds.Capacity"] | null;
128
+ services: string[];
129
+ volume_id: string;
130
+ base_url: string;
131
+ desired_state: "running" | "stopped" | "deleted";
132
+ observed_state: "pending" | "running" | "stopped" | "deleted" | "failed" | "uncertain";
133
+ desired_generation: number;
134
+ observed_generation: number;
135
+ status: "ready" | "provisioning" | "stopped" | "deleted" | "failed" | "uncertain";
136
+ capacity_applied: boolean;
137
+ operation_id: string | null;
138
+ error_code: string | null;
139
+ created_at: string;
140
+ updated_at: string;
141
+ } & {
142
+ [key: string]: unknown;
143
+ }>;
144
+ resume: (mind_id: string, expected_generation: number, options: MindsResumeOptions) => Promise<{
145
+ schema_version: "minds.controller.v1";
146
+ mind_id: string;
147
+ organization_id: string;
148
+ project_id: string;
149
+ name: string;
150
+ region: string;
151
+ plan: "free" | "pro";
152
+ capacity: import("./index.js").components["schemas"]["Minds.Capacity"];
153
+ observed_capacity: import("./index.js").components["schemas"]["Minds.Capacity"] | null;
154
+ services: string[];
155
+ volume_id: string;
156
+ base_url: string;
157
+ desired_state: "running" | "stopped" | "deleted";
158
+ observed_state: "pending" | "running" | "stopped" | "deleted" | "failed" | "uncertain";
159
+ desired_generation: number;
160
+ observed_generation: number;
161
+ status: "ready" | "provisioning" | "stopped" | "deleted" | "failed" | "uncertain";
162
+ capacity_applied: boolean;
163
+ operation_id: string | null;
164
+ error_code: string | null;
165
+ created_at: string;
166
+ updated_at: string;
167
+ } & {
168
+ [key: string]: unknown;
169
+ }>;
170
+ stop: (mind_id: string, expected_generation: number, options: MindsStopOptions) => Promise<{
171
+ schema_version: "minds.controller.v1";
172
+ mind_id: string;
173
+ organization_id: string;
174
+ project_id: string;
175
+ name: string;
176
+ region: string;
177
+ plan: "free" | "pro";
178
+ capacity: import("./index.js").components["schemas"]["Minds.Capacity"];
179
+ observed_capacity: import("./index.js").components["schemas"]["Minds.Capacity"] | null;
180
+ services: string[];
181
+ volume_id: string;
182
+ base_url: string;
183
+ desired_state: "running" | "stopped" | "deleted";
184
+ observed_state: "pending" | "running" | "stopped" | "deleted" | "failed" | "uncertain";
185
+ desired_generation: number;
186
+ observed_generation: number;
187
+ status: "ready" | "provisioning" | "stopped" | "deleted" | "failed" | "uncertain";
188
+ capacity_applied: boolean;
189
+ operation_id: string | null;
190
+ error_code: string | null;
191
+ created_at: string;
192
+ updated_at: string;
193
+ } & {
194
+ [key: string]: unknown;
195
+ }>;
196
+ /** Deletes the Mind (controller lifecycle delete): human delete permission, or an org API key with minds:write. */
197
+ delete: (mind_id: string, expected_generation: number, options: MindsDeleteOptions) => Promise<{
198
+ schema_version: "minds.controller.v1";
199
+ mind_id: string;
200
+ organization_id: string;
201
+ project_id: string;
202
+ name: string;
203
+ region: string;
204
+ plan: "free" | "pro";
205
+ capacity: import("./index.js").components["schemas"]["Minds.Capacity"];
206
+ observed_capacity: import("./index.js").components["schemas"]["Minds.Capacity"] | null;
207
+ services: string[];
208
+ volume_id: string;
209
+ base_url: string;
210
+ desired_state: "running" | "stopped" | "deleted";
211
+ observed_state: "pending" | "running" | "stopped" | "deleted" | "failed" | "uncertain";
212
+ desired_generation: number;
213
+ observed_generation: number;
214
+ status: "ready" | "provisioning" | "stopped" | "deleted" | "failed" | "uncertain";
215
+ capacity_applied: boolean;
216
+ operation_id: string | null;
217
+ error_code: string | null;
218
+ created_at: string;
219
+ updated_at: string;
220
+ } & {
221
+ [key: string]: unknown;
222
+ }>;
223
+ /** Resizes to an existing Pro profile (F1/D1/D2): human manage permission, or an org API key with minds:manage. */
224
+ resize: (mind_id: string, expected_generation: number, profile_id: "F1" | "D1" | "D2", options: MindsResizeOptions) => Promise<{
225
+ schema_version: "minds.controller.v1";
226
+ mind_id: string;
227
+ organization_id: string;
228
+ project_id: string;
229
+ name: string;
230
+ region: string;
231
+ plan: "free" | "pro";
232
+ capacity: import("./index.js").components["schemas"]["Minds.Capacity"];
233
+ observed_capacity: import("./index.js").components["schemas"]["Minds.Capacity"] | null;
234
+ services: string[];
235
+ volume_id: string;
236
+ base_url: string;
237
+ desired_state: "running" | "stopped" | "deleted";
238
+ observed_state: "pending" | "running" | "stopped" | "deleted" | "failed" | "uncertain";
239
+ desired_generation: number;
240
+ observed_generation: number;
241
+ status: "ready" | "provisioning" | "stopped" | "deleted" | "failed" | "uncertain";
242
+ capacity_applied: boolean;
243
+ operation_id: string | null;
244
+ error_code: string | null;
245
+ created_at: string;
246
+ updated_at: string;
247
+ } & {
248
+ [key: string]: unknown;
249
+ }>;
250
+ webhookDeliveries: {
251
+ create: (mind_id: string, delivery: MindsWebhookDelivery, options?: MindsRequestOptions) => Promise<{
252
+ schema_version: "minds.webhook-delivery.v1";
253
+ delivery_id: string;
254
+ mind_id: string;
255
+ organization_id: string;
256
+ project_id: string;
257
+ issuer_principal_id: string;
258
+ event_reference: string;
259
+ event_sha256: string;
260
+ received_at: string;
261
+ outcome: "wake_queued" | "activity_recorded" | "ignored";
262
+ reason: "deleted" | "user_stopped" | "operation_in_flight" | "not_ready" | null;
263
+ operation_id: string | null;
264
+ generation: number;
265
+ wake_reason: "webhook";
266
+ }>;
267
+ get: (mind_id: string, delivery_id: string, options?: MindsRequestOptions) => Promise<{
268
+ schema_version: "minds.webhook-delivery.v1";
269
+ delivery_id: string;
270
+ mind_id: string;
271
+ organization_id: string;
272
+ project_id: string;
273
+ issuer_principal_id: string;
274
+ event_reference: string;
275
+ event_sha256: string;
276
+ received_at: string;
277
+ outcome: "wake_queued" | "activity_recorded" | "ignored";
278
+ reason: "deleted" | "user_stopped" | "operation_in_flight" | "not_ready" | null;
279
+ operation_id: string | null;
280
+ generation: number;
281
+ wake_reason: "webhook";
282
+ }>;
283
+ };
284
+ memory: {
285
+ insert: (mind: string, event: MindsEventInput, options?: MindsRequestOptions) => Promise<{
286
+ id: string;
287
+ }>;
288
+ get: (mind: string, storage_id: string, options?: MindsRequestOptions) => Promise<{
289
+ item: import("./index.js").components["schemas"]["Minds.EpisodicEvent"] | null;
290
+ }>;
291
+ update: (mind: string, storage_id: string, body: {
292
+ event_id: string;
293
+ content: string;
294
+ }, options?: MindsRequestOptions) => Promise<{
295
+ ok: true;
296
+ }>;
297
+ search: (mind: string, text: string, limit?: number, options?: MindsRequestOptions) => Promise<({
298
+ id: string;
299
+ content: string;
300
+ timestamp: string;
301
+ event_type: "Conversation" | "Command" | "Query" | "Document" | "Error" | "Success" | "Learning" | "Decision" | "Action" | "Context" | "Knowledge";
302
+ summary?: string | null;
303
+ tags: string[];
304
+ } & {
305
+ [key: string]: unknown;
306
+ })[]>;
307
+ };
308
+ groups: {
309
+ list: (options?: import("./minds-owner.js").MindsOwnerOptions) => Promise<{
310
+ groups: import("./index.js").components["schemas"]["Minds.OwnerAgentGroup"][];
311
+ }>;
312
+ create: (body: {
313
+ operationId: string;
314
+ name: string;
315
+ }, options?: import("./minds-owner.js").MindsOwnerOptions) => Promise<{
316
+ id: string;
317
+ organizationId: string;
318
+ ownerId: string;
319
+ organizationGeneration: number;
320
+ name: string;
321
+ version: number;
322
+ revokedAt: number | null;
323
+ }>;
324
+ members: {
325
+ list: (group_id: string, options?: import("./minds-owner.js").MindsOwnerOptions) => Promise<{
326
+ members: import("./index.js").components["schemas"]["Minds.OwnerAgentGroupMember"][];
327
+ }>;
328
+ add: (group_id: string, body: import("./minds-owner.js").MindsOwnerVersion & {
329
+ agentId: string;
330
+ }, options?: import("./minds-owner.js").MindsOwnerOptions) => Promise<{
331
+ groupId: string;
332
+ agentId: string;
333
+ agentDid: string;
334
+ agentCreatedAt: number;
335
+ version: number;
336
+ revokedAt: number | null;
337
+ }>;
338
+ remove: (group_id: string, agent_id: string, body: import("./minds-owner.js").MindsOwnerVersion, options?: import("./minds-owner.js").MindsOwnerOptions) => Promise<{
339
+ groupId: string;
340
+ agentId: string;
341
+ agentDid: string;
342
+ agentCreatedAt: number;
343
+ version: number;
344
+ revokedAt: number | null;
345
+ }>;
346
+ };
347
+ };
348
+ attachments: {
349
+ list: (mind_id: string, options?: import("./minds-owner.js").MindsOwnerOptions) => Promise<{
350
+ attachments: import("./index.js").components["schemas"]["Minds.MindAttachment"][];
351
+ }>;
352
+ attach: (mind_id: string, body: import("./minds-owner.js").MindsAttachInput, options?: import("./minds-owner.js").MindsOwnerOptions) => Promise<{
353
+ id: string;
354
+ version: number;
355
+ organizationId: string;
356
+ projectId: string;
357
+ mindId: string;
358
+ subject: import("./index.js").components["schemas"]["Minds.MindAttachmentSubject"];
359
+ permissions: ["minds.agent_data.read"] | ["minds.agent_data.read", "minds.agent_data.write"];
360
+ sharedNamespace: string | null;
361
+ expiresAt: number;
362
+ revokedAt: number | null;
363
+ }>;
364
+ detach: (mind_id: string, attachment_id: string, body: import("./minds-owner.js").MindsOwnerVersion, options?: import("./minds-owner.js").MindsOwnerOptions) => Promise<{
365
+ id: string;
366
+ version: number;
367
+ organizationId: string;
368
+ projectId: string;
369
+ mindId: string;
370
+ subject: import("./index.js").components["schemas"]["Minds.MindAttachmentSubject"];
371
+ permissions: ["minds.agent_data.read"] | ["minds.agent_data.read", "minds.agent_data.write"];
372
+ sharedNamespace: string | null;
373
+ expiresAt: number;
374
+ revokedAt: number | null;
375
+ }>;
376
+ };
377
+ };
package/dist/minds.js ADDED
@@ -0,0 +1,228 @@
1
+ import { GenesisError } from './errors.js';
2
+ import { mindsAgentModule } from './minds-agent.js';
3
+ import { mindsOwnerModule } from './minds-owner.js';
4
+ export const mindsOperations = ['minds_listMinds', 'minds_getMind', 'minds_getUsage', 'minds_createMind', 'minds_resumeMind', 'minds_stopMind', 'minds_deleteMind', 'minds_resizeMind', 'minds_insertEpisodicMemory', 'minds_getEpisodicMemory', 'minds_updateEpisodicMemory', 'minds_searchMemory', 'minds_createWebhookDelivery', 'minds_getWebhookDelivery'];
5
+ /** Engine service groups a create may choose (the controller's CREATE_SERVICES); kv and memory always run. */
6
+ export const mindsServices = ['kv', 'memory', 'graph', 'analytics', 'ml', 'inference', 'vector', 'snn', 'continual', 'associative-memory', 'cognitive', 'cognitive-cycle', 'mcp'];
7
+ export const isMindsOperation = (id) => mindsOperations.includes(id);
8
+ const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
9
+ const uuid4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
10
+ const lifecycle = ['minds_resumeMind', 'minds_stopMind', 'minds_deleteMind', 'minds_resizeMind'];
11
+ const writes = new Set(['minds_createMind', 'minds_resumeMind', 'minds_stopMind', 'minds_deleteMind', 'minds_resizeMind', 'minds_insertEpisodicMemory', 'minds_updateEpisodicMemory', 'minds_createWebhookDelivery']);
12
+ const nilUuid = '00000000-0000-0000-0000-000000000000';
13
+ // Match the native gateway's RFC3339/calendar and nanosecond window bounds.
14
+ function usageInstant(value) {
15
+ if (typeof value !== 'string' || value.length > 40)
16
+ return undefined;
17
+ const match = /^(\d{4})-(\d\d)-(\d\d)[Tt](\d\d):(\d\d):(\d\d)(?:\.(\d{1,9}))?([Zz]|([+-])(\d\d):(\d\d))$/.exec(value);
18
+ if (!match)
19
+ return undefined;
20
+ const [, year, month, day, hour, minute, second, fraction, zone, sign, offsetHour, offsetMinute] = match;
21
+ const [y, mo, d, h, mi, s] = [year, month, day, hour, minute, second].map(Number);
22
+ if (mo < 1 || mo > 12 || d < 1 || d > 31 || h > 23 || mi > 59 || s > 59
23
+ || (zone.toUpperCase() !== 'Z' && (Number(offsetHour) > 23 || Number(offsetMinute) > 59)))
24
+ return undefined;
25
+ const parsed = new Date(0);
26
+ parsed.setUTCFullYear(y, mo - 1, d);
27
+ parsed.setUTCHours(h, mi, s, 0);
28
+ if (parsed.getUTCFullYear() !== y || parsed.getUTCMonth() !== mo - 1 || parsed.getUTCDate() !== d)
29
+ return undefined;
30
+ const offset = zone.toUpperCase() === 'Z' ? 0 : (Number(offsetHour) * 60 + Number(offsetMinute)) * (sign === '+' ? 1 : -1);
31
+ return BigInt(parsed.getTime() - offset * 60_000) * 1000000n + BigInt((fraction ?? '').padEnd(9, '0'));
32
+ }
33
+ /** One dispatch only. Creation retains its operation key; episodic insertion returns a storage UUID distinct from event.id. */
34
+ export async function mindsTransport(options) {
35
+ const id = options.operationId, input = options.input, write = writes.has(id);
36
+ let dispatchAttempted = false;
37
+ const error = (status, type, code, unknownOutcome = false) => new GenesisError({ status, type, code, operationId: id,
38
+ message: status === 403 ? code === 'HUMAN_SANDBOX_SELECTION_REQUIRED'
39
+ ? 'HUMAN_SANDBOX_SELECTION_REQUIRED: Minds accepts an original human One account session with a Console Sandbox selection, or organization API keys with a selected (bound) context; M2M tokens are refused.'
40
+ : code === 'SCOPE_MISSING' ? 'SCOPE_MISSING: this organization API key lacks the Minds scope the operation needs (minds:read, minds:write or minds:manage; minds:manage does not imply read).'
41
+ : 'Minds requires an admitted original human One account session with a Console Sandbox selection, or an organization API key with the operation\'s Minds scope.'
42
+ : write ? 'Minds write was not confirmed. Preserve the lifecycle/create key or delivery_id, or reconcile memory, before an explicit retry.' : 'Minds request was not confirmed.',
43
+ ...(write && (unknownOutcome || dispatchAttempted && (status === 0 || status >= 500 || type === 'invalid_response')) ? { body: { outcome: 'unknown' } } : {}) });
44
+ const fields = id === 'minds_getUsage' ? ['from', 'to'] : id === 'minds_listMinds' ? ['after', 'limit'] : id === 'minds_getMind' ? ['mind_id'] : id === 'minds_updateEpisodicMemory' ? ['mind', 'storage_id', 'body'] : ['minds_resumeMind', 'minds_stopMind', 'minds_resizeMind'].includes(id) ? ['mind_id', 'body']
45
+ : id === 'minds_deleteMind' ? ['mind_id', 'expected_generation']
46
+ : id === 'minds_createMind' ? ['body'] : id === 'minds_getEpisodicMemory' ? ['mind', 'storage_id'] : id === 'minds_createWebhookDelivery' ? ['mind_id', 'body']
47
+ : id === 'minds_getWebhookDelivery' ? ['mind_id', 'delivery_id'] : ['mind', 'body'];
48
+ if (options.routing !== 'gateway' || !isMindsOperation(id) || Object.keys(input).some(key => !fields.includes(key)))
49
+ throw error(0, 'invalid_request');
50
+ if (id === 'minds_getUsage') {
51
+ const from = usageInstant(input.from), to = usageInstant(input.to);
52
+ if (from === undefined || to === undefined || to <= from || to - from > 93n * 86400n * 1000000000n)
53
+ throw error(0, 'invalid_request');
54
+ }
55
+ for (const key of ['mind', 'mind_id', 'storage_id', 'after', 'delivery_id'])
56
+ if (input[key] !== undefined && (typeof input[key] !== 'string' || !uuid.test(input[key])))
57
+ throw error(0, 'invalid_request');
58
+ if (id === 'minds_updateEpisodicMemory') {
59
+ const body = input.body;
60
+ if (typeof input.mind !== 'string' || input.mind.length !== 36 || typeof input.storage_id !== 'string' || input.storage_id.length !== 36
61
+ || !body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).sort().join() !== 'content,event_id'
62
+ || typeof body.event_id !== 'string' || body.event_id.length !== 36 || !uuid.test(body.event_id)
63
+ || typeof body.content !== 'string' || !body.content.trim() || body.content.length > 16_000)
64
+ throw error(0, 'invalid_request');
65
+ }
66
+ if (id === 'minds_createWebhookDelivery' || id === 'minds_getWebhookDelivery') {
67
+ const body = input.body;
68
+ if (input.mind_id === nilUuid || input.delivery_id === nilUuid || (id === 'minds_getWebhookDelivery' ? typeof input.delivery_id !== 'string'
69
+ : !body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).sort().join() !== 'delivery_id,event_reference,event_sha256'
70
+ || typeof body.delivery_id !== 'string' || !uuid.test(body.delivery_id) || body.delivery_id === nilUuid
71
+ || typeof body.event_reference !== 'string' || body.event_reference.length > 200 || !/^[A-Za-z0-9_.:/-]+$/.test(body.event_reference)
72
+ || typeof body.event_sha256 !== 'string' || !/^[0-9a-f]{64}$/.test(body.event_sha256)))
73
+ throw error(0, 'invalid_request');
74
+ }
75
+ if (id === 'minds_createMind') {
76
+ const body = input.body;
77
+ if (!uuid4.test(options.headers?.['idempotency-key'] ?? '') || !/^[a-f0-9]{64}$/.test(options.headers?.['x-genesis-minds-creation-context'] ?? '')
78
+ || !body || typeof body !== 'object' || Array.isArray(body) || typeof body.name !== 'string'
79
+ || Object.keys(body).some(key => !['name', 'plan', 'profile_id', 'services'].includes(key))
80
+ || (body.services !== undefined && (!Array.isArray(body.services) || new Set(body.services).size !== body.services.length
81
+ || body.services.some(service => !mindsServices.includes(service))))
82
+ || (body.plan !== undefined && body.plan !== 'free' && body.plan !== 'pro')
83
+ || (body.profile_id !== undefined && (typeof body.profile_id !== 'string' || !['F1', 'D1', 'D2'].includes(body.profile_id) || (body.plan !== 'pro' && body.profile_id !== 'F1'))))
84
+ throw error(0, 'invalid_request');
85
+ }
86
+ if (id === 'minds_resumeMind' || id === 'minds_stopMind') {
87
+ const body = input.body;
88
+ if (!uuid4.test(options.headers?.['idempotency-key'] ?? '') || !body || typeof body !== 'object' || Array.isArray(body)
89
+ || Object.keys(body).some(key => !(id === 'minds_resumeMind' ? ['expected_generation', 'wake_reason'] : ['expected_generation']).includes(key))
90
+ || (body.wake_reason !== undefined && (typeof body.wake_reason !== 'string' || !['manual', 'scheduled_job', 'webhook', 'memory_consolidation', 'activity'].includes(body.wake_reason)))
91
+ || !Number.isSafeInteger(body.expected_generation) || body.expected_generation < 1
92
+ || body.expected_generation >= Number.MAX_SAFE_INTEGER)
93
+ throw error(0, 'invalid_request');
94
+ }
95
+ if (id === 'minds_deleteMind' || id === 'minds_resizeMind') {
96
+ const body = input.body, generation = id === 'minds_deleteMind' ? input.expected_generation : body?.expected_generation;
97
+ if (!uuid4.test(options.headers?.['idempotency-key'] ?? '') || !Number.isSafeInteger(generation) || generation < 1 || generation >= Number.MAX_SAFE_INTEGER
98
+ || (id === 'minds_resizeMind' && (!body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).sort().join() !== 'expected_generation,profile_id'
99
+ || !['F1', 'D1', 'D2'].includes(body.profile_id))))
100
+ throw error(0, 'invalid_request');
101
+ }
102
+ const controller = new AbortController(), cancel = () => controller.abort(options.signal?.reason);
103
+ options.signal?.addEventListener('abort', cancel, { once: true });
104
+ if (options.signal?.aborted)
105
+ cancel();
106
+ const timer = setTimeout(() => controller.abort(), 35_000);
107
+ async function bounded(work) {
108
+ controller.signal.throwIfAborted();
109
+ let abort = () => { };
110
+ try {
111
+ return await Promise.race([work(), new Promise((_, reject) => { abort = () => reject(error(0, 'transport_error')); controller.signal.addEventListener('abort', abort, { once: true }); })]);
112
+ }
113
+ finally {
114
+ controller.signal.removeEventListener('abort', abort);
115
+ }
116
+ }
117
+ try {
118
+ const credential = await bounded(options.credential);
119
+ controller.signal.throwIfAborted();
120
+ if (!credential)
121
+ throw error(401, 'unauthenticated');
122
+ const body = Object.hasOwn(input, 'body') ? JSON.stringify(input.body) : undefined;
123
+ if (body !== undefined && new TextEncoder().encode(body).length > 65_536)
124
+ throw error(0, 'invalid_request');
125
+ const response = await bounded(() => {
126
+ dispatchAttempted = true;
127
+ return options.fetch(options.url, { method: id === 'minds_updateEpisodicMemory' ? 'PUT' : id === 'minds_deleteMind' ? 'DELETE' : ['minds_listMinds', 'minds_getMind', 'minds_getUsage', 'minds_getEpisodicMemory', 'minds_getWebhookDelivery'].includes(id) ? 'GET' : 'POST',
128
+ headers: { authorization: `Bearer ${credential}`, accept: 'application/json', ...(body === undefined ? {} : { 'content-type': 'application/json' }),
129
+ ...(lifecycle.includes(id) ? { 'idempotency-key': options.headers['idempotency-key'] } : {}),
130
+ ...(id === 'minds_createMind' ? { 'idempotency-key': options.headers['idempotency-key'], 'x-genesis-minds-creation-context': options.headers['x-genesis-minds-creation-context'] } : {}) },
131
+ ...(body === undefined ? {} : { body }), signal: controller.signal, redirect: 'error', cache: 'no-store' }).then(result => {
132
+ if (controller.signal.aborted) {
133
+ void result.body?.cancel().catch(() => { });
134
+ throw error(0, 'transport_error');
135
+ }
136
+ return result;
137
+ });
138
+ });
139
+ const reader = response.body?.getReader();
140
+ if (!reader)
141
+ throw error(response.status, 'invalid_response');
142
+ const chunks = [];
143
+ let size = 0;
144
+ const stop = () => { void reader.cancel().catch(() => { }); };
145
+ controller.signal.addEventListener('abort', stop, { once: true });
146
+ try {
147
+ for (;;) {
148
+ const next = await bounded(() => reader.read());
149
+ if (next.done)
150
+ break;
151
+ size += next.value.length;
152
+ if (size > 2 * 1024 * 1024)
153
+ throw error(response.status, 'invalid_response');
154
+ chunks.push(next.value);
155
+ }
156
+ }
157
+ finally {
158
+ controller.signal.removeEventListener('abort', stop);
159
+ stop();
160
+ try {
161
+ reader.releaseLock();
162
+ }
163
+ catch { /* cancellation owns a pending read */ }
164
+ }
165
+ const bytes = new Uint8Array(size);
166
+ let offset = 0;
167
+ for (const chunk of chunks) {
168
+ bytes.set(chunk, offset);
169
+ offset += chunk.length;
170
+ }
171
+ let value;
172
+ try {
173
+ value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
174
+ }
175
+ catch {
176
+ throw error(response.status, 'invalid_response');
177
+ }
178
+ if (!response.ok) {
179
+ const row = value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
180
+ const detail = row && Object.hasOwn(row, 'error') && row.error && typeof row.error === 'object' && !Array.isArray(row.error)
181
+ ? row.error : undefined;
182
+ const code = detail && Object.hasOwn(detail, 'code') && typeof detail.code === 'string' ? detail.code : undefined;
183
+ const unknownOutcome = lifecycle.includes(id) && response.status === 401 && code === 'SELECTION_EXPIRED'
184
+ && detail !== undefined && Object.hasOwn(detail, 'outcome') && detail.outcome === 'unknown';
185
+ throw error(response.status, 'minds_error', code, unknownOutcome || id === 'minds_createWebhookDelivery' && detail?.outcome === 'unknown');
186
+ }
187
+ if (['minds_createMind', ...lifecycle, 'minds_createWebhookDelivery'].includes(id) && response.status !== 202)
188
+ throw error(response.status, 'invalid_response');
189
+ return Response.json(value, { status: response.status, headers: { 'cache-control': 'no-store' } });
190
+ }
191
+ catch (cause) {
192
+ if (cause instanceof GenesisError)
193
+ throw cause;
194
+ throw error(0, 'transport_error');
195
+ }
196
+ finally {
197
+ clearTimeout(timer);
198
+ controller.abort();
199
+ options.signal?.removeEventListener('abort', cancel);
200
+ }
201
+ }
202
+ export function mindsModule(client) {
203
+ return {
204
+ ...mindsOwnerModule(client),
205
+ agent: mindsAgentModule(client),
206
+ list: (query = {}, options = {}) => client.request('minds_listMinds', query, options),
207
+ get: (mind_id, options = {}) => client.request('minds_getMind', { mind_id }, options),
208
+ usage: (window, options = {}) => client.request('minds_getUsage', window, options),
209
+ create: (name, options) => client.request('minds_createMind', { body: { name, ...(options.plan === undefined ? {} : { plan: options.plan }), ...(options.profileId === undefined ? {} : { profile_id: options.profileId }), ...(options.services === undefined ? {} : { services: options.services }) } }, { signal: options.signal,
210
+ headers: { 'idempotency-key': options.idempotencyKey, 'x-genesis-minds-creation-context': options.contextSha256 } }),
211
+ resume: (mind_id, expected_generation, options) => client.request('minds_resumeMind', { mind_id, body: { expected_generation, ...(options.wakeReason === undefined ? {} : { wake_reason: options.wakeReason }) } }, { signal: options.signal, headers: { 'idempotency-key': options.idempotencyKey } }),
212
+ stop: (mind_id, expected_generation, options) => client.request('minds_stopMind', { mind_id, body: { expected_generation } }, { signal: options.signal, headers: { 'idempotency-key': options.idempotencyKey } }),
213
+ /** Deletes the Mind (controller lifecycle delete): human delete permission, or an org API key with minds:write. */
214
+ delete: (mind_id, expected_generation, options) => client.request('minds_deleteMind', { mind_id, expected_generation }, { signal: options.signal, headers: { 'idempotency-key': options.idempotencyKey } }),
215
+ /** Resizes to an existing Pro profile (F1/D1/D2): human manage permission, or an org API key with minds:manage. */
216
+ resize: (mind_id, expected_generation, profile_id, options) => client.request('minds_resizeMind', { mind_id, body: { expected_generation, profile_id } }, { signal: options.signal, headers: { 'idempotency-key': options.idempotencyKey } }),
217
+ webhookDeliveries: {
218
+ create: (mind_id, delivery, options = {}) => client.request('minds_createWebhookDelivery', { mind_id, body: delivery }, options),
219
+ get: (mind_id, delivery_id, options = {}) => client.request('minds_getWebhookDelivery', { mind_id, delivery_id }, options),
220
+ },
221
+ memory: {
222
+ insert: (mind, event, options = {}) => client.request('minds_insertEpisodicMemory', { mind, body: { event } }, options),
223
+ get: (mind, storage_id, options = {}) => client.request('minds_getEpisodicMemory', { mind, storage_id }, options),
224
+ update: (mind, storage_id, body, options = {}) => client.request('minds_updateEpisodicMemory', { mind, storage_id, body }, options),
225
+ search: (mind, text, limit = 20, options = {}) => client.request('minds_searchMemory', { mind, body: { text, limit } }, options),
226
+ },
227
+ };
228
+ }