@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,267 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import type { OperationInput as In } from './types.js';
3
+ /** Lanes agent context, Sandbox only. Every POST, including the read POSTs (retrieve, snapshots,
4
+ * cache lookup, tenant export), needs a stable idempotency key; a changed payload under it is 409. */
5
+ export declare function lanesModule(client: GenesisClient): {
6
+ records: {
7
+ get: (recordId: string) => Promise<{
8
+ id?: string;
9
+ scope?: Record<string, never>;
10
+ subject?: string;
11
+ contentRef?: string;
12
+ summary?: string;
13
+ visibility?: import("./index.js").components["schemas"]["Lanes.Visibility"];
14
+ labels?: string[];
15
+ }>;
16
+ write: (body: {
17
+ subject: string;
18
+ contentRef: string;
19
+ summary: string;
20
+ visibility: import("./index.js").components["schemas"]["Lanes.Visibility"];
21
+ labels: string[];
22
+ proposedDataClass?: string;
23
+ }, idempotencyKey: string) => Promise<{
24
+ id?: string;
25
+ scope?: Record<string, never>;
26
+ subject?: string;
27
+ contentRef?: string;
28
+ summary?: string;
29
+ visibility?: import("./index.js").components["schemas"]["Lanes.Visibility"];
30
+ labels?: string[];
31
+ }>;
32
+ snapshot: (body: {
33
+ exportedBy: string;
34
+ }, idempotencyKey: string) => Promise<{
35
+ scope?: Record<string, never>;
36
+ exportedBy?: string;
37
+ evidenceRef?: string;
38
+ } & {
39
+ [key: string]: unknown;
40
+ }>;
41
+ restore: (body: {
42
+ scope?: Record<string, never>;
43
+ exportedBy?: string;
44
+ evidenceRef?: string;
45
+ } & {
46
+ [key: string]: unknown;
47
+ }, idempotencyKey: string) => Promise<unknown>;
48
+ };
49
+ retrieve: (body: {
50
+ agentId: string;
51
+ taskId: string;
52
+ query: string;
53
+ allowRawContext: boolean;
54
+ tokenBudget: number;
55
+ } | {
56
+ subject: {
57
+ agentId: string;
58
+ runId?: string;
59
+ sessionId?: string;
60
+ userId?: string;
61
+ };
62
+ query: string;
63
+ allowRawContext?: boolean;
64
+ tokenBudget?: number;
65
+ maxResults?: number;
66
+ }, idempotencyKey: string) => Promise<{
67
+ frame?: import("./index.js").components["schemas"]["Lanes.Frame"];
68
+ route?: import("./index.js").components["schemas"]["Lanes.Route"];
69
+ }>;
70
+ frames: {
71
+ create: (body: {
72
+ agentId: string;
73
+ taskId: string;
74
+ query: string;
75
+ allowRawContext: boolean;
76
+ tokenBudget: number;
77
+ }, idempotencyKey: string) => Promise<{
78
+ frame?: import("./index.js").components["schemas"]["Lanes.Frame"];
79
+ route?: import("./index.js").components["schemas"]["Lanes.Route"];
80
+ }>;
81
+ };
82
+ answer: (body: {
83
+ agentId: string;
84
+ taskId: string;
85
+ query: string;
86
+ allowRawContext: boolean;
87
+ tokenBudget: number;
88
+ }, idempotencyKey: string) => Promise<{
89
+ frame?: import("./index.js").components["schemas"]["Lanes.Frame"];
90
+ routeDecision?: Record<string, never>;
91
+ route?: import("./index.js").components["schemas"]["Lanes.Route"];
92
+ cache?: Record<string, never>;
93
+ answer?: unknown;
94
+ policyDecisionIds?: string[];
95
+ }>;
96
+ ledger: {
97
+ frame: (frameId: string) => Promise<{
98
+ sequence?: number;
99
+ frameId?: string;
100
+ kind?: string;
101
+ detail?: unknown;
102
+ }[]>;
103
+ snapshot: (body: {
104
+ exportedBy: string;
105
+ }, idempotencyKey: string) => Promise<{
106
+ scope?: Record<string, never>;
107
+ exportedBy?: string;
108
+ evidenceRef?: string;
109
+ } & {
110
+ [key: string]: unknown;
111
+ }>;
112
+ restore: (body: {
113
+ scope?: Record<string, never>;
114
+ exportedBy?: string;
115
+ evidenceRef?: string;
116
+ } & {
117
+ [key: string]: unknown;
118
+ }, idempotencyKey: string) => Promise<unknown>;
119
+ };
120
+ cache: {
121
+ lookup: (body: {
122
+ cacheKey: string;
123
+ cacheClass: string;
124
+ requestedBy: string;
125
+ }, idempotencyKey: string) => Promise<{
126
+ cacheKey?: string;
127
+ cacheClass?: string;
128
+ status?: string;
129
+ hit?: import("./index.js").components["schemas"]["Lanes.CacheArtifact"] | null;
130
+ policyDecisionIds?: string[];
131
+ }>;
132
+ write: (body: {
133
+ cacheKey: string;
134
+ cacheClass: string;
135
+ valueRef: string;
136
+ summary: string;
137
+ labels: string[];
138
+ sourceRecordIds: string[];
139
+ writtenBy: string;
140
+ }, idempotencyKey: string) => Promise<{
141
+ id?: string;
142
+ scope?: Record<string, never>;
143
+ cacheKey?: string;
144
+ cacheClass?: string;
145
+ valueRef?: string;
146
+ summary?: string;
147
+ labels?: string[];
148
+ sourceRecordIds?: string[];
149
+ status?: string;
150
+ evidenceRef?: string;
151
+ policyDecisionIds?: string[];
152
+ }>;
153
+ snapshot: (body: {
154
+ exportedBy: string;
155
+ }, idempotencyKey: string) => Promise<{
156
+ scope?: Record<string, never>;
157
+ exportedBy?: string;
158
+ evidenceRef?: string;
159
+ } & {
160
+ [key: string]: unknown;
161
+ }>;
162
+ restore: (body: {
163
+ scope?: Record<string, never>;
164
+ exportedBy?: string;
165
+ evidenceRef?: string;
166
+ } & {
167
+ [key: string]: unknown;
168
+ }, idempotencyKey: string) => Promise<unknown>;
169
+ };
170
+ recovery: {
171
+ restore: (body: {
172
+ [key: string]: unknown;
173
+ }, idempotencyKey: string) => Promise<{
174
+ scope?: Record<string, never>;
175
+ contextRecordsRestored?: number;
176
+ cacheArtifactsRestored?: number;
177
+ framesRestored?: number;
178
+ ledgerEntriesRestored?: number;
179
+ stageOrder?: string[];
180
+ } & {
181
+ [key: string]: unknown;
182
+ }>;
183
+ };
184
+ tenant: {
185
+ export: (body: {
186
+ requestedBy: string;
187
+ includeLedger: boolean;
188
+ includeOperationalRecords: boolean;
189
+ }, idempotencyKey: string) => Promise<{
190
+ [key: string]: unknown;
191
+ }>;
192
+ delete: (body: {
193
+ requestedBy: string;
194
+ reason: string;
195
+ legalHold: boolean;
196
+ }, idempotencyKey: string) => Promise<{
197
+ [key: string]: unknown;
198
+ }>;
199
+ };
200
+ policy: {
201
+ evaluate: (body: {
202
+ actorId: string;
203
+ action: string;
204
+ dataClass: string;
205
+ allowRawContext: boolean;
206
+ modelClass: string;
207
+ }, idempotencyKey: string) => Promise<{
208
+ decisionId?: string;
209
+ allowed?: boolean;
210
+ decision?: "allow" | "deny";
211
+ reason?: string;
212
+ requiresRedaction?: boolean;
213
+ auditLevel?: string;
214
+ reasons?: string[];
215
+ denialReasons?: string[];
216
+ explanation?: Record<string, never>;
217
+ }>;
218
+ };
219
+ foundryRoutes: {
220
+ enforce: (body: {
221
+ routeAlias: string;
222
+ modelClass: string;
223
+ dataUseTerms: string[];
224
+ tokenBudget: number;
225
+ inputTokens: number;
226
+ }, idempotencyKey: string) => Promise<{
227
+ allowed?: boolean;
228
+ routeAlias?: string;
229
+ modelClass?: string;
230
+ inputTokens?: number;
231
+ maxInputTokens?: number;
232
+ reasons?: string[];
233
+ }>;
234
+ };
235
+ promotions: {
236
+ list: () => Promise<{
237
+ [key: string]: unknown;
238
+ }[]>;
239
+ propose: (body: {
240
+ sourceRecordId: string;
241
+ proposedBy: string;
242
+ sanitizedContentRef?: string;
243
+ sanitizedSummary?: string;
244
+ labels?: string[];
245
+ }, idempotencyKey: string) => Promise<{
246
+ [key: string]: unknown;
247
+ }>;
248
+ review: (promotionId: string, body: In<"lanes_reviewPromotion">["body"], idempotencyKey: string) => Promise<{
249
+ [key: string]: unknown;
250
+ }>;
251
+ };
252
+ operations: {
253
+ records: () => Promise<{
254
+ meterRecords?: Record<string, never>[];
255
+ auditRecords?: Record<string, never>[];
256
+ evidenceRecords?: Record<string, never>[];
257
+ probeEvents?: Record<string, never>[];
258
+ }>;
259
+ get: (operationId: string) => Promise<{
260
+ operationId?: string;
261
+ state?: string;
262
+ responseStatus?: number;
263
+ } & {
264
+ [key: string]: unknown;
265
+ }>;
266
+ };
267
+ };
package/dist/lanes.js ADDED
@@ -0,0 +1,41 @@
1
+ import { idempotencyHeaders } from './idempotency.js';
2
+ /** Lanes agent context, Sandbox only. Every POST, including the read POSTs (retrieve, snapshots,
3
+ * cache lookup, tenant export), needs a stable idempotency key; a changed payload under it is 409. */
4
+ export function lanesModule(client) {
5
+ const post = (id) => async (body, idempotencyKey) => client.request(id, { body }, { headers: idempotencyHeaders(id, idempotencyKey) });
6
+ return {
7
+ records: {
8
+ get: (recordId) => client.request('lanes_getRecord', { recordId }),
9
+ write: post('lanes_writeRecord'),
10
+ snapshot: post('lanes_snapshotRecords'),
11
+ restore: post('lanes_restoreRecords'),
12
+ },
13
+ retrieve: post('lanes_retrieve'),
14
+ frames: { create: post('lanes_createFrame') },
15
+ answer: post('lanes_answer'),
16
+ ledger: {
17
+ frame: (frameId) => client.request('lanes_getLedgerFrame', { frameId }),
18
+ snapshot: post('lanes_snapshotLedger'),
19
+ restore: post('lanes_restoreLedger'),
20
+ },
21
+ cache: {
22
+ lookup: post('lanes_cacheLookup'),
23
+ write: post('lanes_cacheWrite'),
24
+ snapshot: post('lanes_snapshotCache'),
25
+ restore: post('lanes_restoreCache'),
26
+ },
27
+ recovery: { restore: post('lanes_recoveryRestore') },
28
+ tenant: { export: post('lanes_exportTenant'), delete: post('lanes_deleteTenant') },
29
+ policy: { evaluate: post('lanes_evaluatePolicy') },
30
+ foundryRoutes: { enforce: post('lanes_enforceFoundryRoute') },
31
+ promotions: {
32
+ list: () => client.request('lanes_listPromotionCandidates'),
33
+ propose: post('lanes_proposePromotion'),
34
+ review: async (promotionId, body, idempotencyKey) => client.request('lanes_reviewPromotion', { promotionId, body }, { headers: idempotencyHeaders('lanes_reviewPromotion', idempotencyKey) }),
35
+ },
36
+ operations: {
37
+ records: () => client.request('lanes_listOperationalRecords'),
38
+ get: (operationId) => client.request('lanes_getOperation', { operationId }),
39
+ },
40
+ };
41
+ }
@@ -0,0 +1,60 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import { GenesisError } from './errors.js';
3
+ export declare const mindsAgentOperations: readonly ["minds_agentInsertEpisodicMemory", "minds_agentGetEpisodicMemory", "minds_agentSearchMemory"];
4
+ export declare const isMindsAgentOperation: (id: string) => boolean;
5
+ declare const EVENT_TYPES: readonly ["Conversation", "Command", "Query", "Document", "Error", "Success", "Learning", "Decision", "Action", "Context", "Knowledge"];
6
+ type Row = Record<string, unknown>;
7
+ export interface MindsAgentEventInput {
8
+ id: string;
9
+ content: string;
10
+ timestamp: string;
11
+ event_type?: typeof EVENT_TYPES[number];
12
+ summary?: string | null;
13
+ tags?: string[];
14
+ }
15
+ export interface MindsAgentOptions {
16
+ /** Omit for the agent's private namespace; group authority is checked by the controller. */
17
+ group?: string;
18
+ /** Fresh caller-signed proof for the controller capability method and canonical URL. Never generated or retried by the SDK. */
19
+ dpopProof?: string;
20
+ signal?: AbortSignal;
21
+ }
22
+ /** Safe metadata from a failed agent-memory call; never contains credentials or proof bytes. */
23
+ export declare class MindsAgentError extends GenesisError {
24
+ readonly dpopNonce?: string;
25
+ constructor(init: ConstructorParameters<typeof GenesisError>[0] & {
26
+ dpopNonce?: string;
27
+ });
28
+ }
29
+ /** A single agent request: no human context selection, credential exchange or automatic retry. */
30
+ export declare function mindsAgentTransport(options: {
31
+ operationId: string;
32
+ input: Row;
33
+ headers?: Record<string, string>;
34
+ routing: string;
35
+ url: string;
36
+ credential: () => Promise<string | undefined>;
37
+ fetch: typeof fetch;
38
+ signal?: AbortSignal;
39
+ }): Promise<Response>;
40
+ export declare function mindsAgentModule(client: GenesisClient): {
41
+ memory: {
42
+ insert: (mind: string, event: MindsAgentEventInput, options?: MindsAgentOptions) => Promise<{
43
+ id: string;
44
+ }>;
45
+ get: (mind: string, storage_id: string, options?: MindsAgentOptions) => Promise<{
46
+ item: import("./index.js").components["schemas"]["Minds.EpisodicEvent"] | null;
47
+ }>;
48
+ search: (mind: string, text: string, limit?: number, options?: MindsAgentOptions) => Promise<({
49
+ id: string;
50
+ content: string;
51
+ timestamp: string;
52
+ event_type: "Conversation" | "Command" | "Query" | "Document" | "Error" | "Success" | "Learning" | "Decision" | "Action" | "Context" | "Knowledge";
53
+ summary?: string | null;
54
+ tags: string[];
55
+ } & {
56
+ [key: string]: unknown;
57
+ })[]>;
58
+ };
59
+ };
60
+ export {};
@@ -0,0 +1,190 @@
1
+ import { envelopeExtrasValid, ENVELOPE_EXTRA_FIELDS, GenesisError } from './errors.js';
2
+ export const mindsAgentOperations = ['minds_agentInsertEpisodicMemory', 'minds_agentGetEpisodicMemory', 'minds_agentSearchMemory'];
3
+ export const isMindsAgentOperation = (id) => mindsAgentOperations.includes(id);
4
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
5
+ const UUID4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
6
+ const GROUP = /^agp_[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
7
+ const EVENT_TYPES = ['Conversation', 'Command', 'Query', 'Document', 'Error', 'Success', 'Learning', 'Decision', 'Action', 'Context', 'Knowledge'];
8
+ /** Safe metadata from a failed agent-memory call; never contains credentials or proof bytes. */
9
+ export class MindsAgentError extends GenesisError {
10
+ dpopNonce;
11
+ constructor(init) {
12
+ super(init);
13
+ this.dpopNonce = init.dpopNonce;
14
+ }
15
+ }
16
+ const row = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
17
+ const exact = (value, required, optional = []) => required.every(key => Object.hasOwn(value, key))
18
+ && Object.keys(value).every(key => required.includes(key) || optional.includes(key));
19
+ const bytes = (value) => new TextEncoder().encode(value).length;
20
+ const text = (value, max) => typeof value === 'string' && value.length > 0 && bytes(value) <= max
21
+ && !/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(value);
22
+ 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));
23
+ const eventType = (value) => typeof value === 'string' && EVENT_TYPES.includes(value);
24
+ function validEvent(value) {
25
+ if (!row(value) || !exact(value, ['id', 'content', 'timestamp'], ['event_type', 'summary', 'tags']))
26
+ return false;
27
+ return text(value.id, 36) && UUID4.test(value.id) && text(value.content, 16_000) && !!value.content.trim() && date(value.timestamp)
28
+ && (value.event_type === undefined || eventType(value.event_type))
29
+ && (value.summary == null || typeof value.summary === 'string' && bytes(value.summary) <= 2_000)
30
+ && (value.tags === undefined || Array.isArray(value.tags) && value.tags.length <= 16 && value.tags.every(tag => text(tag, 80)));
31
+ }
32
+ // Stored events have additional normalized metadata. Validate the producer's
33
+ // stable required fields without reducing its returned event to the input DTO.
34
+ function validStoredEvent(value) {
35
+ return row(value) && text(value.id, 36) && UUID.test(value.id) && text(value.content, 1_000_000)
36
+ && date(value.timestamp) && eventType(value.event_type) && Array.isArray(value.tags) && value.tags.every(tag => typeof tag === 'string');
37
+ }
38
+ /** A single agent request: no human context selection, credential exchange or automatic retry. */
39
+ export async function mindsAgentTransport(options) {
40
+ const { operationId: id, input } = options;
41
+ const write = id === 'minds_agentInsertEpisodicMemory', read = id === 'minds_agentGetEpisodicMemory';
42
+ let dispatched = false;
43
+ const fail = (status, type, details = {}) => new MindsAgentError({
44
+ status, type, operationId: id, code: details.code, requestId: details.requestId, dpopNonce: details.dpopNonce,
45
+ message: 'Agent memory request was not confirmed. Inspect the error before an explicit retry.',
46
+ ...(details.unknown || write && dispatched && (status === 0 || status >= 500 || type === 'invalid_response' && status >= 200 && status < 300)
47
+ ? { body: { outcome: 'unknown' } } : {}),
48
+ });
49
+ const fields = read ? ['mind', 'storage_id'] : ['mind', 'body'];
50
+ if (options.routing !== 'gateway' || !isMindsAgentOperation(id) || !exact(input, fields, ['group'])
51
+ || typeof input.mind !== 'string' || !UUID.test(input.mind)
52
+ || input.group !== undefined && (typeof input.group !== 'string' || !GROUP.test(input.group))
53
+ || read && (typeof input.storage_id !== 'string' || !UUID.test(input.storage_id)))
54
+ throw fail(0, 'invalid_request');
55
+ if (!read && (!row(input.body) || (write ? !exact(input.body, ['event']) || !validEvent(input.body.event)
56
+ : !exact(input.body, ['text'], ['limit']) || !text(input.body.text, 1_000) || !input.body.text.trim()
57
+ || input.body.limit !== undefined && (!Number.isInteger(input.body.limit) || Number(input.body.limit) < 1 || Number(input.body.limit) > 100))))
58
+ throw fail(0, 'invalid_request');
59
+ const headerEntries = Object.entries(options.headers ?? {});
60
+ if (headerEntries.length > 1 || headerEntries.some(([name, value]) => name.toLowerCase() !== 'dpop' || !text(value, 16_384) || /[^\x21-\x7e]|,/.test(value)))
61
+ throw fail(0, 'invalid_request');
62
+ const body = read ? undefined : JSON.stringify(input.body);
63
+ if (body !== undefined && bytes(body) > 65_536)
64
+ throw fail(0, 'invalid_request');
65
+ const controller = new AbortController(), cancel = () => controller.abort(options.signal?.reason);
66
+ options.signal?.addEventListener('abort', cancel, { once: true });
67
+ if (options.signal?.aborted)
68
+ cancel();
69
+ const timer = setTimeout(() => controller.abort(), 35_000);
70
+ async function bounded(work) {
71
+ controller.signal.throwIfAborted();
72
+ let abort = () => { };
73
+ const cancelled = new Promise((_, reject) => {
74
+ abort = () => reject(fail(0, 'transport_error'));
75
+ controller.signal.addEventListener('abort', abort, { once: true });
76
+ });
77
+ try {
78
+ controller.signal.throwIfAborted();
79
+ let pending;
80
+ try {
81
+ pending = work();
82
+ }
83
+ catch (error) {
84
+ pending = Promise.reject(error);
85
+ }
86
+ return await Promise.race([cancelled, pending]);
87
+ }
88
+ finally {
89
+ controller.signal.removeEventListener('abort', abort);
90
+ }
91
+ }
92
+ try {
93
+ const credential = await bounded(options.credential);
94
+ controller.signal.throwIfAborted();
95
+ if (!text(credential, 16_384) || /[^\x21-\x7e]|,/.test(credential))
96
+ throw fail(401, 'unauthenticated');
97
+ const response = await bounded(() => {
98
+ dispatched = true;
99
+ return options.fetch(options.url, { method: read ? 'GET' : 'POST', redirect: 'error', cache: 'no-store', signal: controller.signal,
100
+ headers: { authorization: `Bearer ${credential}`, accept: 'application/json', ...(body === undefined ? {} : { 'content-type': 'application/json' }),
101
+ ...(headerEntries.length ? { dpop: headerEntries[0][1] } : {}) }, ...(body === undefined ? {} : { body }) }).then(response => {
102
+ if (controller.signal.aborted) {
103
+ void response.body?.cancel().catch(() => { });
104
+ throw fail(0, 'transport_error');
105
+ }
106
+ return response;
107
+ });
108
+ });
109
+ const reader = response.body?.getReader();
110
+ if (!reader)
111
+ throw fail(response.status, 'invalid_response');
112
+ const chunks = [];
113
+ let size = 0;
114
+ const stop = () => { void reader.cancel().catch(() => { }); };
115
+ controller.signal.addEventListener('abort', stop, { once: true });
116
+ try {
117
+ for (;;) {
118
+ const next = await bounded(() => reader.read());
119
+ if (next.done)
120
+ break;
121
+ size += next.value.length;
122
+ if (size > 2 * 1024 * 1024)
123
+ throw fail(response.status, 'invalid_response');
124
+ chunks.push(next.value);
125
+ }
126
+ }
127
+ finally {
128
+ controller.signal.removeEventListener('abort', stop);
129
+ stop();
130
+ try {
131
+ reader.releaseLock();
132
+ }
133
+ catch { /* cancellation owns pending read */ }
134
+ }
135
+ const data = new Uint8Array(size);
136
+ let offset = 0;
137
+ for (const chunk of chunks) {
138
+ data.set(chunk, offset);
139
+ offset += chunk.length;
140
+ }
141
+ let value;
142
+ try {
143
+ value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(data));
144
+ }
145
+ catch {
146
+ throw fail(response.status, 'invalid_response');
147
+ }
148
+ if (!response.ok) {
149
+ if (!row(value) || !exact(value, ['error']) || !row(value.error) || !exact(value.error, ['code', 'request_id'], ['outcome', ...ENVELOPE_EXTRA_FIELDS]) || !envelopeExtrasValid(value.error)
150
+ || !text(value.error.code, 128) || !/^[A-Z][A-Z0-9_]*$/.test(value.error.code)
151
+ || !text(value.error.request_id, 256) || /[^\x21-\x7e]/.test(value.error.request_id)
152
+ || value.error.outcome !== undefined && value.error.outcome !== 'unknown')
153
+ throw fail(response.status, 'invalid_response');
154
+ const nonce = response.headers.get('dpop-nonce');
155
+ if (value.error.code === 'DPOP_NONCE_REQUIRED' && (response.status !== 401 || !nonce || !/^[A-Za-z0-9_-]{1,512}$/.test(nonce)))
156
+ throw fail(response.status, 'invalid_response');
157
+ throw fail(response.status, 'minds_agent_error', { code: value.error.code, requestId: value.error.request_id,
158
+ ...(value.error.code === 'DPOP_NONCE_REQUIRED' ? { dpopNonce: nonce } : {}), unknown: write && value.error.outcome === 'unknown' });
159
+ }
160
+ if (response.status !== 200 || (write ? !row(value) || !exact(value, ['id']) || !text(value.id, 36) || !UUID.test(value.id)
161
+ : read ? !row(value) || !exact(value, ['item']) || value.item !== null && !validStoredEvent(value.item)
162
+ : !Array.isArray(value) || value.length > Number(input.body.limit ?? 20) || !value.every(validStoredEvent)))
163
+ throw fail(response.status, 'invalid_response');
164
+ return Response.json(value, { status: 200, headers: { 'cache-control': 'private, no-store' } });
165
+ }
166
+ catch (error) {
167
+ if (error instanceof MindsAgentError)
168
+ throw error;
169
+ throw fail(0, 'transport_error');
170
+ }
171
+ finally {
172
+ clearTimeout(timer);
173
+ controller.abort();
174
+ options.signal?.removeEventListener('abort', cancel);
175
+ }
176
+ }
177
+ export function mindsAgentModule(client) {
178
+ const validOptions = (value) => row(value) && exact(value, [], ['group', 'dpopProof', 'signal']);
179
+ const init = (options) => {
180
+ if (!validOptions(options))
181
+ throw new MindsAgentError({ status: 0, type: 'invalid_request', message: 'Unknown agent memory option.' });
182
+ return { signal: options.signal, ...(options.dpopProof === undefined ? {} : { headers: { dpop: options.dpopProof } }) };
183
+ };
184
+ const query = (mind, options) => ({ mind, ...(options.group === undefined ? {} : { group: options.group }) });
185
+ return { memory: {
186
+ insert: (mind, event, options = {}) => client.request('minds_agentInsertEpisodicMemory', { ...query(mind, options), body: { event } }, init(options)),
187
+ get: (mind, storage_id, options = {}) => client.request('minds_agentGetEpisodicMemory', { ...query(mind, options), storage_id }, init(options)),
188
+ search: (mind, text, limit = 20, options = {}) => client.request('minds_agentSearchMemory', { ...query(mind, options), body: { text, limit } }, init(options)),
189
+ } };
190
+ }
@@ -0,0 +1,110 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import { GenesisError } from './errors.js';
3
+ export declare const mindsOwnerOperations: readonly ["minds_listAgentGroups", "minds_createAgentGroup", "minds_listAgentGroupMembers", "minds_addAgentGroupMember", "minds_removeAgentGroupMember", "minds_listMindAttachments", "minds_attachMind", "minds_detachMind"];
4
+ type OwnerOperation = typeof mindsOwnerOperations[number];
5
+ export declare const isMindsOwnerOperation: (id: string) => id is OwnerOperation;
6
+ export interface MindsOwnerOptions {
7
+ signal?: AbortSignal;
8
+ }
9
+ export interface MindsOwnerVersion {
10
+ operationId: string;
11
+ expectedVersion: number;
12
+ }
13
+ export type MindsAttachmentSubject = {
14
+ kind: 'agent';
15
+ agentId: string;
16
+ } | {
17
+ kind: 'group';
18
+ groupId: string;
19
+ };
20
+ export interface MindsAttachInput extends MindsOwnerVersion {
21
+ subject: MindsAttachmentSubject;
22
+ permissions: ['minds.agent_data.read'] | ['minds.agent_data.read', 'minds.agent_data.write'];
23
+ expiresAt: number;
24
+ }
25
+ export declare class MindsOwnerError extends GenesisError {
26
+ }
27
+ type Row = Record<string, unknown>;
28
+ /** Original-human owner operations. No context selection, token substitution or automatic retry. */
29
+ export declare function mindsOwnerTransport(options: {
30
+ operationId: string;
31
+ input: Row;
32
+ headers?: Record<string, string>;
33
+ routing: string;
34
+ url: string;
35
+ credential: () => Promise<string | undefined>;
36
+ fetch: typeof fetch;
37
+ signal?: AbortSignal;
38
+ }): Promise<Response>;
39
+ export declare function mindsOwnerModule(client: GenesisClient): {
40
+ groups: {
41
+ list: (options?: MindsOwnerOptions) => Promise<{
42
+ groups: import("./index.js").components["schemas"]["Minds.OwnerAgentGroup"][];
43
+ }>;
44
+ create: (body: {
45
+ operationId: string;
46
+ name: string;
47
+ }, options?: MindsOwnerOptions) => Promise<{
48
+ id: string;
49
+ organizationId: string;
50
+ ownerId: string;
51
+ organizationGeneration: number;
52
+ name: string;
53
+ version: number;
54
+ revokedAt: number | null;
55
+ }>;
56
+ members: {
57
+ list: (group_id: string, options?: MindsOwnerOptions) => Promise<{
58
+ members: import("./index.js").components["schemas"]["Minds.OwnerAgentGroupMember"][];
59
+ }>;
60
+ add: (group_id: string, body: MindsOwnerVersion & {
61
+ agentId: string;
62
+ }, options?: MindsOwnerOptions) => Promise<{
63
+ groupId: string;
64
+ agentId: string;
65
+ agentDid: string;
66
+ agentCreatedAt: number;
67
+ version: number;
68
+ revokedAt: number | null;
69
+ }>;
70
+ remove: (group_id: string, agent_id: string, body: MindsOwnerVersion, options?: MindsOwnerOptions) => Promise<{
71
+ groupId: string;
72
+ agentId: string;
73
+ agentDid: string;
74
+ agentCreatedAt: number;
75
+ version: number;
76
+ revokedAt: number | null;
77
+ }>;
78
+ };
79
+ };
80
+ attachments: {
81
+ list: (mind_id: string, options?: MindsOwnerOptions) => Promise<{
82
+ attachments: import("./index.js").components["schemas"]["Minds.MindAttachment"][];
83
+ }>;
84
+ attach: (mind_id: string, body: MindsAttachInput, options?: MindsOwnerOptions) => Promise<{
85
+ id: string;
86
+ version: number;
87
+ organizationId: string;
88
+ projectId: string;
89
+ mindId: string;
90
+ subject: import("./index.js").components["schemas"]["Minds.MindAttachmentSubject"];
91
+ permissions: ["minds.agent_data.read"] | ["minds.agent_data.read", "minds.agent_data.write"];
92
+ sharedNamespace: string | null;
93
+ expiresAt: number;
94
+ revokedAt: number | null;
95
+ }>;
96
+ detach: (mind_id: string, attachment_id: string, body: MindsOwnerVersion, options?: MindsOwnerOptions) => Promise<{
97
+ id: string;
98
+ version: number;
99
+ organizationId: string;
100
+ projectId: string;
101
+ mindId: string;
102
+ subject: import("./index.js").components["schemas"]["Minds.MindAttachmentSubject"];
103
+ permissions: ["minds.agent_data.read"] | ["minds.agent_data.read", "minds.agent_data.write"];
104
+ sharedNamespace: string | null;
105
+ expiresAt: number;
106
+ revokedAt: number | null;
107
+ }>;
108
+ };
109
+ };
110
+ export {};