@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,233 @@
1
+ import { envelopeExtrasValid, ENVELOPE_EXTRA_FIELDS, GenesisError } from './errors.js';
2
+ export const mindsAgentOperations = ['minds_agentInsertEpisodicMemory', 'minds_agentGetEpisodicMemory', 'minds_agentSearchMemory'];
3
+ /** Agent Mind creation: an approved agent-create token with DPoP, default-off at the gateway (MINDS_AGENT_CREATE_ENABLED). */
4
+ export const mindsAgentCreateOperations = ['minds_agentCreateMind', 'minds_agentGetCreateOperation'];
5
+ export const isMindsAgentCreateOperation = (id) => mindsAgentCreateOperations.includes(id);
6
+ export const isMindsAgentOperation = (id) => mindsAgentOperations.includes(id) || isMindsAgentCreateOperation(id);
7
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
8
+ const UUID4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
9
+ const GROUP = /^agp_[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
10
+ const EVENT_TYPES = ['Conversation', 'Command', 'Query', 'Document', 'Error', 'Success', 'Learning', 'Decision', 'Action', 'Context', 'Knowledge'];
11
+ /** Safe metadata from a failed agent-memory call; never contains credentials or proof bytes. */
12
+ export class MindsAgentError extends GenesisError {
13
+ dpopNonce;
14
+ constructor(init) {
15
+ super(init);
16
+ this.dpopNonce = init.dpopNonce;
17
+ }
18
+ }
19
+ const row = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
20
+ const exact = (value, required, optional = []) => required.every(key => Object.hasOwn(value, key))
21
+ && Object.keys(value).every(key => required.includes(key) || optional.includes(key));
22
+ const bytes = (value) => new TextEncoder().encode(value).length;
23
+ const text = (value, max) => typeof value === 'string' && value.length > 0 && bytes(value) <= max
24
+ && !/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(value);
25
+ const date = (value) => text(value, 128) && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(value) && Number.isFinite(Date.parse(value));
26
+ const eventType = (value) => typeof value === 'string' && EVENT_TYPES.includes(value);
27
+ function validEvent(value) {
28
+ if (!row(value) || !exact(value, ['id', 'content', 'timestamp'], ['event_type', 'summary', 'tags']))
29
+ return false;
30
+ return text(value.id, 36) && UUID4.test(value.id) && text(value.content, 16_000) && !!value.content.trim() && date(value.timestamp)
31
+ && (value.event_type === undefined || eventType(value.event_type))
32
+ && (value.summary == null || typeof value.summary === 'string' && bytes(value.summary) <= 2_000)
33
+ && (value.tags === undefined || Array.isArray(value.tags) && value.tags.length <= 16 && value.tags.every(tag => text(tag, 80)));
34
+ }
35
+ // Stored events have additional normalized metadata. Validate the producer's
36
+ // stable required fields without reducing its returned event to the input DTO.
37
+ function validStoredEvent(value) {
38
+ return row(value) && text(value.id, 36) && UUID.test(value.id) && text(value.content, 1_000_000)
39
+ && date(value.timestamp) && eventType(value.event_type) && Array.isArray(value.tags) && value.tags.every(tag => typeof tag === 'string');
40
+ }
41
+ function validCreation(value) {
42
+ if (!row(value) || !exact(value, ['schemaVersion', 'approvalId', 'approvalVersion', 'operationId', 'spec']) || value.schemaVersion !== 1
43
+ || typeof value.approvalId !== 'string' || !UUID4.test(value.approvalId) || typeof value.operationId !== 'string' || !UUID4.test(value.operationId)
44
+ || !Number.isSafeInteger(value.approvalVersion) || Number(value.approvalVersion) < 1)
45
+ return false;
46
+ const spec = value.spec, capacity = row(spec) ? spec.capacity : undefined;
47
+ return row(spec) && row(capacity) && exact(spec, ['name', 'region', 'plan', 'capacity', 'services'])
48
+ && exact(capacity, ['profile_id', 'cpus', 'memory_mb', 'volume_size_gb']) && typeof spec.name === 'string' && spec.name.trim() === spec.name
49
+ && [...spec.name].length <= 80 && (spec.name === 'Sandbox' || spec.name.startsWith('Sandbox ')) && !/[\u0000-\u001f\u007f-\u009f]/.test(spec.name)
50
+ && spec.region === 'us-central1-a' && spec.plan === 'free' && capacity.profile_id === 'F1' && capacity.cpus === 1 && capacity.memory_mb === 512
51
+ && capacity.volume_size_gb === 1 && JSON.stringify(spec.services) === '["kv","memory"]';
52
+ }
53
+ /** A single agent request: no human context selection, credential exchange or automatic retry. */
54
+ export async function mindsAgentTransport(options) {
55
+ const { operationId: id, input } = options;
56
+ const create = id === 'minds_agentCreateMind', status = id === 'minds_agentGetCreateOperation', creation = create || status;
57
+ const write = id === 'minds_agentInsertEpisodicMemory' || create, read = id === 'minds_agentGetEpisodicMemory' || status;
58
+ let dispatched = false;
59
+ const fail = (status, type, details = {}) => new MindsAgentError({
60
+ status, type, operationId: id, code: details.code, requestId: details.requestId, dpopNonce: details.dpopNonce,
61
+ message: creation ? (details.code === 'SERVICE_UNAVAILABLE' ? 'Agent Mind creation is not enabled on this gateway (MINDS_AGENT_CREATE_ENABLED).'
62
+ : 'Agent Mind creation was not confirmed. Read the operation status with the same operationId before an explicit retry.')
63
+ : 'Agent memory request was not confirmed. Inspect the error before an explicit retry.',
64
+ ...(details.unknown || write && dispatched && (status === 0 || status >= 500 || type === 'invalid_response' && status >= 200 && status < 300)
65
+ ? { body: { outcome: 'unknown' } } : {}),
66
+ });
67
+ if (creation && (options.routing !== 'gateway' || !exact(input, status ? ['operation_id'] : ['body'])
68
+ || (status ? typeof input.operation_id !== 'string' || !UUID4.test(input.operation_id) : !validCreation(input.body))
69
+ || !options.headers || !Object.keys(options.headers).some(name => name.toLowerCase() === 'dpop')))
70
+ throw fail(0, 'invalid_request');
71
+ const fields = read ? ['mind', 'storage_id'] : ['mind', 'body'];
72
+ if (!creation && (options.routing !== 'gateway' || !isMindsAgentOperation(id) || !exact(input, fields, ['group'])
73
+ || typeof input.mind !== 'string' || !UUID.test(input.mind)
74
+ || input.group !== undefined && (typeof input.group !== 'string' || !GROUP.test(input.group))
75
+ || read && (typeof input.storage_id !== 'string' || !UUID.test(input.storage_id))))
76
+ throw fail(0, 'invalid_request');
77
+ if (!creation && !read && (!row(input.body) || (write ? !exact(input.body, ['event']) || !validEvent(input.body.event)
78
+ : !exact(input.body, ['text'], ['limit']) || !text(input.body.text, 1_000) || !input.body.text.trim()
79
+ || input.body.limit !== undefined && (!Number.isInteger(input.body.limit) || Number(input.body.limit) < 1 || Number(input.body.limit) > 100))))
80
+ throw fail(0, 'invalid_request');
81
+ const headerEntries = Object.entries(options.headers ?? {});
82
+ if (headerEntries.length > 1 || headerEntries.some(([name, value]) => name.toLowerCase() !== 'dpop' || !text(value, 16_384) || /[^\x21-\x7e]|,/.test(value)))
83
+ throw fail(0, 'invalid_request');
84
+ const body = read ? undefined : JSON.stringify(input.body);
85
+ if (body !== undefined && bytes(body) > 65_536)
86
+ throw fail(0, 'invalid_request');
87
+ const controller = new AbortController(), cancel = () => controller.abort(options.signal?.reason);
88
+ options.signal?.addEventListener('abort', cancel, { once: true });
89
+ if (options.signal?.aborted)
90
+ cancel();
91
+ const timer = setTimeout(() => controller.abort(), 35_000);
92
+ async function bounded(work) {
93
+ controller.signal.throwIfAborted();
94
+ let abort = () => { };
95
+ const cancelled = new Promise((_, reject) => {
96
+ abort = () => reject(fail(0, 'transport_error'));
97
+ controller.signal.addEventListener('abort', abort, { once: true });
98
+ });
99
+ try {
100
+ controller.signal.throwIfAborted();
101
+ let pending;
102
+ try {
103
+ pending = work();
104
+ }
105
+ catch (error) {
106
+ pending = Promise.reject(error);
107
+ }
108
+ return await Promise.race([cancelled, pending]);
109
+ }
110
+ finally {
111
+ controller.signal.removeEventListener('abort', abort);
112
+ }
113
+ }
114
+ try {
115
+ const credential = await bounded(options.credential);
116
+ controller.signal.throwIfAborted();
117
+ if (!text(credential, 16_384) || /[^\x21-\x7e]|,/.test(credential))
118
+ throw fail(401, 'unauthenticated');
119
+ const response = await bounded(() => {
120
+ dispatched = true;
121
+ return options.fetch(options.url, { method: read ? 'GET' : 'POST', redirect: 'error', cache: 'no-store', signal: controller.signal,
122
+ headers: { authorization: `Bearer ${credential}`, accept: 'application/json', ...(body === undefined ? {} : { 'content-type': 'application/json' }),
123
+ ...(headerEntries.length ? { dpop: headerEntries[0][1] } : {}), ...(create ? { 'idempotency-key': input.body.operationId } : {}) }, ...(body === undefined ? {} : { body }) }).then(response => {
124
+ if (controller.signal.aborted) {
125
+ void response.body?.cancel().catch(() => { });
126
+ throw fail(0, 'transport_error');
127
+ }
128
+ return response;
129
+ });
130
+ });
131
+ const reader = response.body?.getReader();
132
+ if (!reader)
133
+ throw fail(response.status, 'invalid_response');
134
+ const chunks = [];
135
+ let size = 0;
136
+ const stop = () => { void reader.cancel().catch(() => { }); };
137
+ controller.signal.addEventListener('abort', stop, { once: true });
138
+ try {
139
+ for (;;) {
140
+ const next = await bounded(() => reader.read());
141
+ if (next.done)
142
+ break;
143
+ size += next.value.length;
144
+ if (size > 2 * 1024 * 1024)
145
+ throw fail(response.status, 'invalid_response');
146
+ chunks.push(next.value);
147
+ }
148
+ }
149
+ finally {
150
+ controller.signal.removeEventListener('abort', stop);
151
+ stop();
152
+ try {
153
+ reader.releaseLock();
154
+ }
155
+ catch { /* cancellation owns pending read */ }
156
+ }
157
+ const data = new Uint8Array(size);
158
+ let offset = 0;
159
+ for (const chunk of chunks) {
160
+ data.set(chunk, offset);
161
+ offset += chunk.length;
162
+ }
163
+ let value;
164
+ try {
165
+ value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(data));
166
+ }
167
+ catch {
168
+ throw fail(response.status, 'invalid_response');
169
+ }
170
+ if (!response.ok) {
171
+ if (!row(value) || !exact(value, ['error']) || !row(value.error) || !exact(value.error, ['code', 'request_id'], ['outcome', ...ENVELOPE_EXTRA_FIELDS]) || !envelopeExtrasValid(value.error)
172
+ || !text(value.error.code, 128) || !/^[A-Z][A-Z0-9_]*$/.test(value.error.code)
173
+ || !text(value.error.request_id, 256) || /[^\x21-\x7e]/.test(value.error.request_id)
174
+ || value.error.outcome !== undefined && value.error.outcome !== 'unknown') {
175
+ // Controller refusals pass through the agent-create route verbatim; keep the status, never invent a code.
176
+ if (creation)
177
+ throw fail(response.status, 'minds_agent_error', { unknown: create && response.status >= 500 });
178
+ throw fail(response.status, 'invalid_response');
179
+ }
180
+ const nonce = response.headers.get('dpop-nonce');
181
+ if (value.error.code === 'DPOP_NONCE_REQUIRED' && (response.status !== 401 || !nonce || !/^[A-Za-z0-9_-]{1,512}$/.test(nonce)))
182
+ throw fail(response.status, 'invalid_response');
183
+ throw fail(response.status, 'minds_agent_error', { code: value.error.code, requestId: value.error.request_id,
184
+ ...(value.error.code === 'DPOP_NONCE_REQUIRED' ? { dpopNonce: nonce } : {}), unknown: write && value.error.outcome === 'unknown' });
185
+ }
186
+ if (creation) {
187
+ if (response.status !== (create ? 202 : 200) || !row(value) || typeof value.mind_id !== 'string' || !UUID.test(value.mind_id) || typeof value.status !== 'string')
188
+ throw fail(response.status, 'invalid_response');
189
+ return Response.json(value, { status: response.status, headers: { 'cache-control': 'private, no-store' } });
190
+ }
191
+ if (response.status !== 200 || (write ? !row(value) || !exact(value, ['id']) || !text(value.id, 36) || !UUID.test(value.id)
192
+ : read ? !row(value) || !exact(value, ['item']) || value.item !== null && !validStoredEvent(value.item)
193
+ : !Array.isArray(value) || value.length > Number(input.body.limit ?? 20) || !value.every(validStoredEvent)))
194
+ throw fail(response.status, 'invalid_response');
195
+ return Response.json(value, { status: 200, headers: { 'cache-control': 'private, no-store' } });
196
+ }
197
+ catch (error) {
198
+ if (error instanceof MindsAgentError)
199
+ throw error;
200
+ throw fail(0, 'transport_error');
201
+ }
202
+ finally {
203
+ clearTimeout(timer);
204
+ controller.abort();
205
+ options.signal?.removeEventListener('abort', cancel);
206
+ }
207
+ }
208
+ export function mindsAgentModule(client) {
209
+ const validOptions = (value) => row(value) && exact(value, [], ['group', 'dpopProof', 'signal']);
210
+ const init = (options) => {
211
+ if (!validOptions(options))
212
+ throw new MindsAgentError({ status: 0, type: 'invalid_request', message: 'Unknown agent memory option.' });
213
+ return { signal: options.signal, ...(options.dpopProof === undefined ? {} : { headers: { dpop: options.dpopProof } }) };
214
+ };
215
+ const query = (mind, options) => ({ mind, ...(options.group === undefined ? {} : { group: options.group }) });
216
+ const proof = (options) => {
217
+ if (!row(options) || !exact(options, ['dpopProof'], ['signal']) || typeof options.dpopProof !== 'string')
218
+ throw new MindsAgentError({ status: 0, type: 'invalid_request', message: 'Agent Mind creation requires an explicit DPoP proof.' });
219
+ return { signal: options.signal, headers: { dpop: options.dpopProof } };
220
+ };
221
+ return {
222
+ /** Free/F1 Sandbox only; the fixed spec is the only shape the gateway admits. */
223
+ create: (input, options) => client.request('minds_agentCreateMind', { body: { schemaVersion: 1,
224
+ approvalId: input.approvalId, approvalVersion: input.approvalVersion, operationId: input.operationId,
225
+ spec: { name: input.name, region: 'us-central1-a', plan: 'free', capacity: { profile_id: 'F1', cpus: 1, memory_mb: 512, volume_size_gb: 1 }, services: ['kv', 'memory'] } } }, proof(options)),
226
+ createStatus: (operation_id, options) => client.request('minds_agentGetCreateOperation', { operation_id }, proof(options)),
227
+ memory: {
228
+ insert: (mind, event, options = {}) => client.request('minds_agentInsertEpisodicMemory', { ...query(mind, options), body: { event } }, init(options)),
229
+ get: (mind, storage_id, options = {}) => client.request('minds_agentGetEpisodicMemory', { ...query(mind, options), storage_id }, init(options)),
230
+ search: (mind, text, limit = 20, options = {}) => client.request('minds_agentSearchMemory', { ...query(mind, options), body: { text, limit } }, init(options)),
231
+ }
232
+ };
233
+ }