@onesi/genesis 0.1.13 → 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 (69) hide show
  1. package/README.md +1 -1
  2. package/dist/auto.d.ts +1010 -0
  3. package/dist/auto.js +125 -0
  4. package/dist/beacons.d.ts +42 -0
  5. package/dist/beacons.js +71 -0
  6. package/dist/blinds-owner-enrollment.d.ts +109 -0
  7. package/dist/blinds-owner-enrollment.js +21 -2
  8. package/dist/client.d.ts +3 -19947
  9. package/dist/client.js +124 -17
  10. package/dist/errors.js +1 -1
  11. package/dist/flares.d.ts +32 -0
  12. package/dist/flares.js +5 -0
  13. package/dist/fleets.d.ts +32 -0
  14. package/dist/fleets.js +59 -6
  15. package/dist/flocks.d.ts +285 -1
  16. package/dist/flocks.js +59 -0
  17. package/dist/foundry.d.ts +424 -0
  18. package/dist/foundry.js +133 -0
  19. package/dist/garden.d.ts +754 -0
  20. package/dist/garden.js +76 -0
  21. package/dist/gateway.d.ts +365 -0
  22. package/dist/gateway.js +82 -0
  23. package/dist/gears.d.ts +121 -2
  24. package/dist/gears.js +24 -2
  25. package/dist/generated/operations.d.ts +3 -19948
  26. package/dist/generated/operations.js +54590 -13302
  27. package/dist/generated/schema.d.ts +69793 -17548
  28. package/dist/genesis.d.ts +7908 -1260
  29. package/dist/genesis.js +90 -25
  30. package/dist/genesis.openapi.json +109121 -29920
  31. package/dist/henry.d.ts +202 -1
  32. package/dist/henry.js +223 -0
  33. package/dist/hives-environment.d.ts +9 -0
  34. package/dist/hives-environment.js +22 -0
  35. package/dist/hives-node.js +3 -0
  36. package/dist/hives-operations.d.ts +114 -0
  37. package/dist/hives-operations.js +2 -0
  38. package/dist/hives-platform.d.ts +149 -0
  39. package/dist/hives-platform.js +183 -0
  40. package/dist/hives-sse.d.ts +24 -0
  41. package/dist/hives-sse.js +111 -0
  42. package/dist/iam-directory.d.ts +8 -0
  43. package/dist/iam-directory.js +23 -0
  44. package/dist/iam.d.ts +391 -0
  45. package/dist/iam.js +92 -0
  46. package/dist/idempotency.d.ts +3 -0
  47. package/dist/idempotency.js +22 -0
  48. package/dist/index.d.ts +18 -4
  49. package/dist/index.js +16 -4
  50. package/dist/instances.d.ts +177 -2
  51. package/dist/instances.js +37 -5
  52. package/dist/minds-agent.d.ts +28 -0
  53. package/dist/minds-agent.js +53 -10
  54. package/dist/minds-engine.d.ts +394 -0
  55. package/dist/minds-engine.js +555 -0
  56. package/dist/minds.d.ts +109 -1
  57. package/dist/minds.js +49 -14
  58. package/dist/orgs.d.ts +405 -0
  59. package/dist/orgs.js +63 -0
  60. package/dist/runner.d.ts +4 -0
  61. package/dist/runner.js +1 -0
  62. package/dist/scopes.d.ts +310 -0
  63. package/dist/scopes.js +40 -0
  64. package/dist/taps.d.ts +118 -0
  65. package/dist/taps.js +45 -0
  66. package/dist/traces.d.ts +574 -0
  67. package/dist/traces.js +97 -0
  68. package/dist/types.d.ts +12 -1
  69. package/package.json +1 -1
@@ -1,11 +1,63 @@
1
1
  import type { GenesisClient } from './client.js';
2
- /** Read-only instance inventories. Each needs an interactive One account login with a selected
3
- * organization and project; the gateway admits nothing else on these products. */
2
+ import type { OperationInput } from './types.js';
3
+ /** Instance inventory and lifecycle. Each needs a One account login with a selected organization
4
+ * and project, or an org API key whose binding selects them. `create` needs a stable idempotency
5
+ * key (8-128 printable ASCII characters): reuse it to retry and the same instance is returned.
6
+ * `delete` runs the instance's stop action (an optional key makes the stop one replayable
7
+ * operation); Omega's native stop deletes the deployment. Ids are Omega deployment UUIDs. */
4
8
  export declare function rigsModule(client: GenesisClient): {
5
9
  list: () => Promise<{
6
10
  product: "rigs";
7
11
  instances: import("./index.js").components["schemas"]["Rigs.Instance"][];
8
12
  }>;
13
+ get: (id: string) => Promise<{
14
+ product: "rigs";
15
+ instance: import("./index.js").components["schemas"]["Rigs.Instance"];
16
+ }>;
17
+ create: (body: NonNullable<OperationInput<"rigs_createRig">["body"]>, idempotencyKey: string) => Promise<{
18
+ product: "rigs";
19
+ instance: import("./index.js").components["schemas"]["Rigs.Instance"];
20
+ }>;
21
+ delete: (id: string, idempotencyKey?: string) => Promise<{
22
+ ok: true;
23
+ product: "rigs";
24
+ id: string;
25
+ capability: "stop";
26
+ result: {
27
+ ok?: boolean;
28
+ capability?: string;
29
+ status?: string;
30
+ completed?: boolean;
31
+ pending?: boolean;
32
+ bridge?: boolean;
33
+ };
34
+ }>;
35
+ /** `{capability, args}`; the key is required for every capability but `stop`. */
36
+ action: (id: string, body: NonNullable<OperationInput<"rigs_actOnRig">["body"]>, idempotencyKey?: string) => Promise<{
37
+ ok: boolean;
38
+ product: string;
39
+ id: string;
40
+ capability: string;
41
+ result?: {
42
+ [key: string]: unknown;
43
+ } | null;
44
+ } & {
45
+ [key: string]: unknown;
46
+ }>;
47
+ term: (id: string) => Promise<{
48
+ product: string;
49
+ id: string;
50
+ kind?: string;
51
+ credentials: {
52
+ url?: string;
53
+ token?: string;
54
+ expires_in?: number | string;
55
+ } & {
56
+ [key: string]: unknown;
57
+ };
58
+ } & {
59
+ [key: string]: unknown;
60
+ }>;
9
61
  };
10
62
  export declare function panesModule(client: GenesisClient): {
11
63
  list: () => Promise<{
@@ -14,6 +66,61 @@ export declare function panesModule(client: GenesisClient): {
14
66
  } & {
15
67
  [key: string]: unknown;
16
68
  }>;
69
+ get: (id: string) => Promise<{
70
+ product: "panes";
71
+ instance: import("./index.js").components["schemas"]["Panes.Instance"];
72
+ } & {
73
+ [key: string]: unknown;
74
+ }>;
75
+ create: (body: NonNullable<OperationInput<"panes_createPane">["body"]>, idempotencyKey: string) => Promise<{
76
+ product: "panes";
77
+ instance: import("./index.js").components["schemas"]["Panes.Instance"];
78
+ } & {
79
+ [key: string]: unknown;
80
+ }>;
81
+ delete: (id: string, idempotencyKey?: string) => Promise<{
82
+ ok: true;
83
+ product: "panes";
84
+ id: string;
85
+ capability: "stop";
86
+ result?: {
87
+ [key: string]: unknown;
88
+ };
89
+ accepted?: boolean;
90
+ completed?: boolean;
91
+ pending?: boolean;
92
+ status?: string;
93
+ } & {
94
+ [key: string]: unknown;
95
+ }>;
96
+ /** `{capability, args}`; the key is required for every capability but `stop`. */
97
+ action: (id: string, body: NonNullable<OperationInput<"panes_actOnPane">["body"]>, idempotencyKey?: string) => Promise<{
98
+ ok: boolean;
99
+ product: string;
100
+ id: string;
101
+ capability: string;
102
+ result?: {
103
+ [key: string]: unknown;
104
+ } | null;
105
+ } & {
106
+ [key: string]: unknown;
107
+ }>;
108
+ term: (id: string) => Promise<{
109
+ product: string;
110
+ id: string;
111
+ kind?: string;
112
+ credentials: {
113
+ url?: string;
114
+ token?: string;
115
+ expires_in?: number | string;
116
+ } & {
117
+ [key: string]: unknown;
118
+ };
119
+ } & {
120
+ [key: string]: unknown;
121
+ }>;
122
+ /** The screenshot image as a raw Response (PNG or JPEG). */
123
+ screenshot: (id: string, artifactId: string) => Promise<unknown>;
17
124
  };
18
125
  export declare function shellsModule(client: GenesisClient): {
19
126
  list: () => Promise<{
@@ -22,4 +129,72 @@ export declare function shellsModule(client: GenesisClient): {
22
129
  } & {
23
130
  [key: string]: unknown;
24
131
  }>;
132
+ get: (id: string) => Promise<{
133
+ product: "shells";
134
+ instance: import("./index.js").components["schemas"]["Shells.Instance"];
135
+ } & {
136
+ [key: string]: unknown;
137
+ }>;
138
+ create: (body: NonNullable<OperationInput<"shells_createShell">["body"]>, idempotencyKey: string) => Promise<{
139
+ product: "shells";
140
+ instance: import("./index.js").components["schemas"]["Shells.Instance"];
141
+ } & {
142
+ [key: string]: unknown;
143
+ }>;
144
+ delete: (id: string, idempotencyKey?: string) => Promise<{
145
+ ok: true;
146
+ product: "shells";
147
+ id: string;
148
+ capability: "stop";
149
+ result?: {
150
+ [key: string]: unknown;
151
+ };
152
+ cambium?: unknown;
153
+ } & {
154
+ [key: string]: unknown;
155
+ }>;
156
+ /** `{capability, args}`; the key is required for every capability but `stop`. */
157
+ action: (id: string, body: NonNullable<OperationInput<"shells_actOnShell">["body"]>, idempotencyKey?: string) => Promise<{
158
+ ok: boolean;
159
+ product: string;
160
+ id: string;
161
+ capability: string;
162
+ result?: {
163
+ [key: string]: unknown;
164
+ } | null;
165
+ } & {
166
+ [key: string]: unknown;
167
+ }>;
168
+ term: (id: string) => Promise<{
169
+ product: string;
170
+ id: string;
171
+ kind?: string;
172
+ credentials: {
173
+ url?: string;
174
+ token?: string;
175
+ expires_in?: number | string;
176
+ } & {
177
+ [key: string]: unknown;
178
+ };
179
+ } & {
180
+ [key: string]: unknown;
181
+ }>;
182
+ /** One-shot exec; a repeat with the same key and body replays the stored result. */
183
+ exec: (id: string, body: NonNullable<OperationInput<"shells_execShell">["body"]>, idempotencyKey: string) => Promise<{
184
+ ok: true;
185
+ product: "shells";
186
+ id: string;
187
+ result: {
188
+ exitCode: number | null;
189
+ encoding: "base64";
190
+ stdout: string;
191
+ stderr: string;
192
+ truncated: {
193
+ stdout?: boolean;
194
+ stderr?: boolean;
195
+ };
196
+ timedOut: boolean;
197
+ durationMs: number;
198
+ };
199
+ }>;
25
200
  };
package/dist/instances.js CHANGED
@@ -1,11 +1,43 @@
1
- /** Read-only instance inventories. Each needs an interactive One account login with a selected
2
- * organization and project; the gateway admits nothing else on these products. */
1
+ import { idempotencyHeaders } from './idempotency.js';
2
+ /** Instance inventory and lifecycle. Each needs a One account login with a selected organization
3
+ * and project, or an org API key whose binding selects them. `create` needs a stable idempotency
4
+ * key (8-128 printable ASCII characters): reuse it to retry and the same instance is returned.
5
+ * `delete` runs the instance's stop action (an optional key makes the stop one replayable
6
+ * operation); Omega's native stop deletes the deployment. Ids are Omega deployment UUIDs. */
3
7
  export function rigsModule(client) {
4
- return { list: () => client.request('rigs_listRigs') };
8
+ return {
9
+ list: () => client.request('rigs_listRigs'),
10
+ get: (id) => client.request('rigs_getRig', { id }),
11
+ create: (body, idempotencyKey) => client.request('rigs_createRig', { body }, { headers: idempotencyHeaders('rigs_createRig', idempotencyKey) }),
12
+ delete: (id, idempotencyKey) => client.request('rigs_deleteRig', { id }, { headers: idempotencyHeaders('rigs_deleteRig', idempotencyKey) }),
13
+ /** `{capability, args}`; the key is required for every capability but `stop`. */
14
+ action: (id, body, idempotencyKey) => client.request('rigs_actOnRig', { id, body }, { headers: idempotencyHeaders('rigs_actOnRig', idempotencyKey) }),
15
+ term: (id) => client.request('rigs_openRigTerm', { id }),
16
+ };
5
17
  }
6
18
  export function panesModule(client) {
7
- return { list: () => client.request('panes_listPanes') };
19
+ return {
20
+ list: () => client.request('panes_listPanes'),
21
+ get: (id) => client.request('panes_getPane', { id }),
22
+ create: (body, idempotencyKey) => client.request('panes_createPane', { body }, { headers: idempotencyHeaders('panes_createPane', idempotencyKey) }),
23
+ delete: (id, idempotencyKey) => client.request('panes_deletePane', { id }, { headers: idempotencyHeaders('panes_deletePane', idempotencyKey) }),
24
+ /** `{capability, args}`; the key is required for every capability but `stop`. */
25
+ action: (id, body, idempotencyKey) => client.request('panes_actOnPane', { id, body }, { headers: idempotencyHeaders('panes_actOnPane', idempotencyKey) }),
26
+ term: (id) => client.request('panes_openPaneTerm', { id }),
27
+ /** The screenshot image as a raw Response (PNG or JPEG). */
28
+ screenshot: (id, artifactId) => client.request('panes_getPaneScreenshotData', { id, artifactId }),
29
+ };
8
30
  }
9
31
  export function shellsModule(client) {
10
- return { list: () => client.request('shells_listShells') };
32
+ return {
33
+ list: () => client.request('shells_listShells'),
34
+ get: (id) => client.request('shells_getShell', { id }),
35
+ create: (body, idempotencyKey) => client.request('shells_createShell', { body }, { headers: idempotencyHeaders('shells_createShell', idempotencyKey) }),
36
+ delete: (id, idempotencyKey) => client.request('shells_deleteShell', { id }, { headers: idempotencyHeaders('shells_deleteShell', idempotencyKey) }),
37
+ /** `{capability, args}`; the key is required for every capability but `stop`. */
38
+ action: (id, body, idempotencyKey) => client.request('shells_actOnShell', { id, body }, { headers: idempotencyHeaders('shells_actOnShell', idempotencyKey) }),
39
+ term: (id) => client.request('shells_openShellTerm', { id }),
40
+ /** One-shot exec; a repeat with the same key and body replays the stored result. */
41
+ exec: (id, body, idempotencyKey) => client.request('shells_execShell', { id, body }, { headers: idempotencyHeaders('shells_execShell', idempotencyKey) }),
42
+ };
11
43
  }
@@ -1,6 +1,9 @@
1
1
  import type { GenesisClient } from './client.js';
2
2
  import { GenesisError } from './errors.js';
3
3
  export declare const mindsAgentOperations: readonly ["minds_agentInsertEpisodicMemory", "minds_agentGetEpisodicMemory", "minds_agentSearchMemory"];
4
+ /** Agent Mind creation: an approved agent-create token with DPoP, default-off at the gateway (MINDS_AGENT_CREATE_ENABLED). */
5
+ export declare const mindsAgentCreateOperations: readonly ["minds_agentCreateMind", "minds_agentGetCreateOperation"];
6
+ export declare const isMindsAgentCreateOperation: (id: string) => boolean;
4
7
  export declare const isMindsAgentOperation: (id: string) => boolean;
5
8
  declare const EVENT_TYPES: readonly ["Conversation", "Command", "Query", "Document", "Error", "Success", "Learning", "Decision", "Action", "Context", "Knowledge"];
6
9
  type Row = Record<string, unknown>;
@@ -12,6 +15,18 @@ export interface MindsAgentEventInput {
12
15
  summary?: string | null;
13
16
  tags?: string[];
14
17
  }
18
+ export interface MindsAgentCreateInput {
19
+ /** "Sandbox" or "Sandbox <label>", at most 80 characters. */
20
+ name: string;
21
+ approvalId: string;
22
+ approvalVersion: number;
23
+ /** Persisted UUID4 for this creation; also the idempotency key and the status lookup id. */
24
+ operationId: string;
25
+ }
26
+ export interface MindsAgentCreateOptions {
27
+ dpopProof: string;
28
+ signal?: AbortSignal;
29
+ }
15
30
  export interface MindsAgentOptions {
16
31
  /** Omit for the agent's private namespace; group authority is checked by the controller. */
17
32
  group?: string;
@@ -38,6 +53,19 @@ export declare function mindsAgentTransport(options: {
38
53
  signal?: AbortSignal;
39
54
  }): Promise<Response>;
40
55
  export declare function mindsAgentModule(client: GenesisClient): {
56
+ /** Free/F1 Sandbox only; the fixed spec is the only shape the gateway admits. */
57
+ create: (input: MindsAgentCreateInput, options: MindsAgentCreateOptions) => Promise<{
58
+ mind_id: string;
59
+ status: string;
60
+ } & {
61
+ [key: string]: unknown;
62
+ }>;
63
+ createStatus: (operation_id: string, options: MindsAgentCreateOptions) => Promise<{
64
+ mind_id: string;
65
+ status: string;
66
+ } & {
67
+ [key: string]: unknown;
68
+ }>;
41
69
  memory: {
42
70
  insert: (mind: string, event: MindsAgentEventInput, options?: MindsAgentOptions) => Promise<{
43
71
  id: string;
@@ -1,6 +1,9 @@
1
1
  import { envelopeExtrasValid, ENVELOPE_EXTRA_FIELDS, GenesisError } from './errors.js';
2
2
  export const mindsAgentOperations = ['minds_agentInsertEpisodicMemory', 'minds_agentGetEpisodicMemory', 'minds_agentSearchMemory'];
3
- export const isMindsAgentOperation = (id) => mindsAgentOperations.includes(id);
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);
4
7
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
5
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}$/;
6
9
  const GROUP = /^agp_[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
@@ -35,24 +38,43 @@ function validStoredEvent(value) {
35
38
  return row(value) && text(value.id, 36) && UUID.test(value.id) && text(value.content, 1_000_000)
36
39
  && date(value.timestamp) && eventType(value.event_type) && Array.isArray(value.tags) && value.tags.every(tag => typeof tag === 'string');
37
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
+ }
38
53
  /** A single agent request: no human context selection, credential exchange or automatic retry. */
39
54
  export async function mindsAgentTransport(options) {
40
55
  const { operationId: id, input } = options;
41
- const write = id === 'minds_agentInsertEpisodicMemory', read = id === 'minds_agentGetEpisodicMemory';
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;
42
58
  let dispatched = false;
43
59
  const fail = (status, type, details = {}) => new MindsAgentError({
44
60
  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.',
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.',
46
64
  ...(details.unknown || write && dispatched && (status === 0 || status >= 500 || type === 'invalid_response' && status >= 200 && status < 300)
47
65
  ? { body: { outcome: 'unknown' } } : {}),
48
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');
49
71
  const fields = read ? ['mind', 'storage_id'] : ['mind', 'body'];
50
- if (options.routing !== 'gateway' || !isMindsAgentOperation(id) || !exact(input, fields, ['group'])
72
+ if (!creation && (options.routing !== 'gateway' || !isMindsAgentOperation(id) || !exact(input, fields, ['group'])
51
73
  || typeof input.mind !== 'string' || !UUID.test(input.mind)
52
74
  || input.group !== undefined && (typeof input.group !== 'string' || !GROUP.test(input.group))
53
- || read && (typeof input.storage_id !== 'string' || !UUID.test(input.storage_id)))
75
+ || read && (typeof input.storage_id !== 'string' || !UUID.test(input.storage_id))))
54
76
  throw fail(0, 'invalid_request');
55
- if (!read && (!row(input.body) || (write ? !exact(input.body, ['event']) || !validEvent(input.body.event)
77
+ if (!creation && !read && (!row(input.body) || (write ? !exact(input.body, ['event']) || !validEvent(input.body.event)
56
78
  : !exact(input.body, ['text'], ['limit']) || !text(input.body.text, 1_000) || !input.body.text.trim()
57
79
  || input.body.limit !== undefined && (!Number.isInteger(input.body.limit) || Number(input.body.limit) < 1 || Number(input.body.limit) > 100))))
58
80
  throw fail(0, 'invalid_request');
@@ -98,7 +120,7 @@ export async function mindsAgentTransport(options) {
98
120
  dispatched = true;
99
121
  return options.fetch(options.url, { method: read ? 'GET' : 'POST', redirect: 'error', cache: 'no-store', signal: controller.signal,
100
122
  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 => {
123
+ ...(headerEntries.length ? { dpop: headerEntries[0][1] } : {}), ...(create ? { 'idempotency-key': input.body.operationId } : {}) }, ...(body === undefined ? {} : { body }) }).then(response => {
102
124
  if (controller.signal.aborted) {
103
125
  void response.body?.cancel().catch(() => { });
104
126
  throw fail(0, 'transport_error');
@@ -149,14 +171,23 @@ export async function mindsAgentTransport(options) {
149
171
  if (!row(value) || !exact(value, ['error']) || !row(value.error) || !exact(value.error, ['code', 'request_id'], ['outcome', ...ENVELOPE_EXTRA_FIELDS]) || !envelopeExtrasValid(value.error)
150
172
  || !text(value.error.code, 128) || !/^[A-Z][A-Z0-9_]*$/.test(value.error.code)
151
173
  || !text(value.error.request_id, 256) || /[^\x21-\x7e]/.test(value.error.request_id)
152
- || value.error.outcome !== undefined && value.error.outcome !== 'unknown')
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 });
153
178
  throw fail(response.status, 'invalid_response');
179
+ }
154
180
  const nonce = response.headers.get('dpop-nonce');
155
181
  if (value.error.code === 'DPOP_NONCE_REQUIRED' && (response.status !== 401 || !nonce || !/^[A-Za-z0-9_-]{1,512}$/.test(nonce)))
156
182
  throw fail(response.status, 'invalid_response');
157
183
  throw fail(response.status, 'minds_agent_error', { code: value.error.code, requestId: value.error.request_id,
158
184
  ...(value.error.code === 'DPOP_NONCE_REQUIRED' ? { dpopNonce: nonce } : {}), unknown: write && value.error.outcome === 'unknown' });
159
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
+ }
160
191
  if (response.status !== 200 || (write ? !row(value) || !exact(value, ['id']) || !text(value.id, 36) || !UUID.test(value.id)
161
192
  : read ? !row(value) || !exact(value, ['item']) || value.item !== null && !validStoredEvent(value.item)
162
193
  : !Array.isArray(value) || value.length > Number(input.body.limit ?? 20) || !value.every(validStoredEvent)))
@@ -182,9 +213,21 @@ export function mindsAgentModule(client) {
182
213
  return { signal: options.signal, ...(options.dpopProof === undefined ? {} : { headers: { dpop: options.dpopProof } }) };
183
214
  };
184
215
  const query = (mind, options) => ({ mind, ...(options.group === undefined ? {} : { group: options.group }) });
185
- return { memory: {
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: {
186
228
  insert: (mind, event, options = {}) => client.request('minds_agentInsertEpisodicMemory', { ...query(mind, options), body: { event } }, init(options)),
187
229
  get: (mind, storage_id, options = {}) => client.request('minds_agentGetEpisodicMemory', { ...query(mind, options), storage_id }, init(options)),
188
230
  search: (mind, text, limit = 20, options = {}) => client.request('minds_agentSearchMemory', { ...query(mind, options), body: { text, limit } }, init(options)),
189
- } };
231
+ }
232
+ };
190
233
  }