@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,127 @@
1
+ import type { GenesisClient } from './client.js';
2
+ import { type HivesResourceOptions } from './hives-resources-transport.js';
3
+ export interface HivesCorsRule {
4
+ allowed_origins: string[];
5
+ allowed_methods: string[];
6
+ allowed_headers: string[];
7
+ exposed_headers: string[];
8
+ max_age_secs: number;
9
+ }
10
+ export interface HivesBucket {
11
+ id: string;
12
+ tenant_id: string;
13
+ project_id: string;
14
+ name: string;
15
+ region: string;
16
+ visibility: string;
17
+ status: string;
18
+ object_count: number | null;
19
+ size_bytes: number | null;
20
+ statistics_scope: 'unmeasured_provider_inventory' | 'retained_legacy_metadata';
21
+ created_at: string;
22
+ provider_binding: {
23
+ provider: 'gcs';
24
+ region: string;
25
+ state: string;
26
+ requires_reconciliation: boolean;
27
+ } | null;
28
+ operation_state: string | null;
29
+ }
30
+ export interface HivesObject {
31
+ key: string;
32
+ bucket_id: string;
33
+ size_bytes: number;
34
+ etag: string;
35
+ last_modified: string;
36
+ generation: string;
37
+ content_type: string | null;
38
+ metadata: Record<string, string> | null;
39
+ metadata_scope: string;
40
+ }
41
+ export interface HivesObjectAcknowledgement {
42
+ bucket_id: string;
43
+ key: string;
44
+ size_bytes: number;
45
+ etag: string;
46
+ generation: string;
47
+ content_type: string | null;
48
+ }
49
+ export interface HivesObjectList {
50
+ objects: HivesObject[];
51
+ common_prefixes: string[];
52
+ is_truncated: boolean;
53
+ next_continuation_token: string | null;
54
+ total: number | null;
55
+ }
56
+ export interface HivesBucketList {
57
+ data: HivesBucket[];
58
+ pagination: {
59
+ page: number;
60
+ per_page: number;
61
+ total: number;
62
+ total_pages: number;
63
+ has_next: boolean;
64
+ has_prev: boolean;
65
+ };
66
+ }
67
+ export interface HivesCreateBucket {
68
+ name: string;
69
+ region?: 'us-central1';
70
+ visibility?: 'private' | 'publicread';
71
+ cors_rules?: HivesCorsRule[];
72
+ }
73
+ export interface HivesPresign {
74
+ key: string;
75
+ method?: 'GET' | 'PUT';
76
+ expires_in_secs?: number;
77
+ content_type?: string;
78
+ content_length?: number;
79
+ }
80
+ export interface HivesPresignedUrl {
81
+ url: string;
82
+ expires_at: string;
83
+ method: 'GET' | 'PUT';
84
+ required_headers?: Record<string, string>;
85
+ }
86
+ export declare function hivesObjectKey(key: string): string;
87
+ export declare function hivesCells(client: GenesisClient): {
88
+ list(project: string, query?: {
89
+ page?: number;
90
+ per_page?: number;
91
+ }, options?: HivesResourceOptions): Promise<HivesBucketList>;
92
+ get(project: string, id: string, options?: HivesResourceOptions): Promise<HivesBucket>;
93
+ /** A pending provider_binding is an uncertain outcome, never a completed-create claim. */
94
+ create(project: string, body: HivesCreateBucket, options?: HivesResourceOptions): Promise<HivesBucket>;
95
+ remove(project: string, id: string, options?: HivesResourceOptions): Promise<{
96
+ id: string;
97
+ success: boolean;
98
+ message: string;
99
+ }>;
100
+ reconcile(project: string, id: string, options?: HivesResourceOptions): Promise<{
101
+ bucket: HivesBucket;
102
+ outcome: string;
103
+ }>;
104
+ cors: {
105
+ get: (project: string, id: string, options?: HivesResourceOptions) => Promise<HivesCorsRule[]>;
106
+ set: (project: string, id: string, rules: HivesCorsRule[], options?: HivesResourceOptions) => Promise<HivesCorsRule[]>;
107
+ };
108
+ objects: {
109
+ list(project: string, id: string, query?: {
110
+ prefix?: string;
111
+ delimiter?: string;
112
+ continuation_token?: string;
113
+ max_keys?: number;
114
+ }, options?: HivesResourceOptions): Promise<HivesObjectList>;
115
+ put(project: string, id: string, key: string, bytes: Blob | ArrayBuffer | ArrayBufferView, options?: HivesResourceOptions & {
116
+ content_type?: string;
117
+ }): Promise<HivesObjectAcknowledgement>;
118
+ remove: (project: string, id: string, key: string, options?: HivesResourceOptions) => Promise<void>;
119
+ download: (project: string, id: string, key: string, options?: HivesResourceOptions) => Promise<Response>;
120
+ /** Existing flat-key path compatibility; nested keys use canonical collection methods above. */
121
+ putFlat(project: string, id: string, key: string, bytes: Blob | ArrayBuffer | ArrayBufferView, options?: HivesResourceOptions & {
122
+ content_type?: string;
123
+ }): Promise<HivesObjectAcknowledgement>;
124
+ removeFlat: (project: string, id: string, key: string, options?: HivesResourceOptions) => Promise<void>;
125
+ };
126
+ presign(project: string, id: string, body: HivesPresign, options?: HivesResourceOptions): Promise<HivesPresignedUrl>;
127
+ };
@@ -0,0 +1,151 @@
1
+ import { HIVES_OBJECT_BYTES, hivesResourceCall, hivesResourceId, hivesObjectBody, hivesContentType, resourceError } from './hives-resources-transport.js';
2
+ export function hivesObjectKey(key) {
3
+ const bytes = new TextEncoder().encode(key);
4
+ if (typeof key !== 'string' || !key || bytes.length > 1024 || new TextDecoder('utf-8', { fatal: true }).decode(bytes) !== key
5
+ || key.startsWith('/') || key.endsWith('/') || /[\u0000-\u001f\u007f-\u009f\\]/.test(key) || key.split('/').some(p => !p || p === '.' || p === '..'))
6
+ throw resourceError(0);
7
+ let binary = '';
8
+ for (const byte of bytes)
9
+ binary += String.fromCharCode(byte);
10
+ return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
11
+ }
12
+ function cors(rules) {
13
+ if (!Array.isArray(rules) || rules.length > 100)
14
+ throw resourceError(0);
15
+ return rules.map(rule => {
16
+ if (!rule || typeof rule !== 'object' || Object.keys(rule).some(k => !['allowed_origins', 'allowed_methods', 'allowed_headers', 'exposed_headers', 'max_age_secs'].includes(k))
17
+ || !Array.isArray(rule.allowed_origins) || !rule.allowed_origins.length || rule.allowed_origins.length > 100
18
+ || !Array.isArray(rule.allowed_methods) || !rule.allowed_methods.length || rule.allowed_methods.length > 6
19
+ || !Array.isArray(rule.allowed_headers) || rule.allowed_headers.length !== 1 || rule.allowed_headers[0] !== '*'
20
+ || !Array.isArray(rule.exposed_headers) || rule.exposed_headers.length > 100
21
+ || !Number.isInteger(rule.max_age_secs) || rule.max_age_secs < 0 || rule.max_age_secs > 86400)
22
+ throw resourceError(0);
23
+ for (const origin of rule.allowed_origins) {
24
+ if (origin === '*')
25
+ continue;
26
+ if (typeof origin !== 'string')
27
+ throw resourceError(0);
28
+ let url;
29
+ try {
30
+ url = new URL(origin);
31
+ }
32
+ catch {
33
+ throw resourceError(0);
34
+ }
35
+ if (!['http:', 'https:'].includes(url.protocol) || !url.hostname || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
36
+ throw resourceError(0);
37
+ }
38
+ if (rule.allowed_methods.some(m => !['GET', 'HEAD', 'PUT', 'POST', 'DELETE'].includes(m))
39
+ || rule.exposed_headers.some(h => typeof h !== 'string' || h.length > 256 || !/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(h)))
40
+ throw resourceError(0);
41
+ return { allowed_origins: [...rule.allowed_origins], allowed_methods: [...rule.allowed_methods], allowed_headers: ['*'], exposed_headers: [...rule.exposed_headers], max_age_secs: rule.max_age_secs };
42
+ });
43
+ }
44
+ function bucket(value, project, id) {
45
+ if (!value || typeof value !== 'object' || value.project_id !== project || typeof value.id !== 'string' || id !== undefined && value.id !== id
46
+ || !['unmeasured_provider_inventory', 'retained_legacy_metadata'].includes(value.statistics_scope)
47
+ || [value.object_count, value.size_bytes].some(v => v !== null && (!Number.isSafeInteger(v) || v < 0))
48
+ || (value.statistics_scope === 'unmeasured_provider_inventory' && (value.object_count !== null || value.size_bytes !== null)))
49
+ throw resourceError(0);
50
+ if (value.statistics_scope === 'unmeasured_provider_inventory' && !value.provider_binding)
51
+ throw resourceError(0);
52
+ if (value.provider_binding !== null && (!value.provider_binding || value.provider_binding.provider !== 'gcs' || typeof value.provider_binding.state !== 'string' || typeof value.provider_binding.requires_reconciliation !== 'boolean'))
53
+ throw resourceError(0);
54
+ return Object.fromEntries(['id', 'tenant_id', 'project_id', 'name', 'region', 'visibility', 'status', 'object_count', 'size_bytes', 'statistics_scope', 'created_at', 'provider_binding', 'operation_state'].map(k => [k, value[k]]));
55
+ }
56
+ function object(value, id) {
57
+ if (!value || value.bucket_id !== id || typeof value.key !== 'string' || !Number.isSafeInteger(value.size_bytes) || value.size_bytes < 0 || typeof value.generation !== 'string')
58
+ throw resourceError(0);
59
+ hivesObjectKey(value.key);
60
+ return Object.fromEntries(['key', 'bucket_id', 'size_bytes', 'etag', 'last_modified', 'generation', 'content_type', 'metadata', 'metadata_scope'].map(k => [k, value[k]]));
61
+ }
62
+ function acknowledgement(value, key, id, size) {
63
+ if (!value || value.bucket_id !== id || value.key !== key || value.size_bytes !== size || !Number.isSafeInteger(value.size_bytes) || value.size_bytes < 0 || typeof value.etag !== 'string' || typeof value.generation !== 'string' || value.content_type !== null && typeof value.content_type !== 'string')
64
+ throw resourceError(0);
65
+ return { key: value.key, bucket_id: value.bucket_id, size_bytes: value.size_bytes, etag: value.etag, generation: value.generation, content_type: value.content_type };
66
+ }
67
+ export function hivesCells(client) {
68
+ const ids = (project_id, bucket_id) => ({ project_id: hivesResourceId(project_id), ...(bucket_id === undefined ? {} : { bucket_id: hivesResourceId(bucket_id) }) });
69
+ const call = (id, input, options, mode = 'json', limit = 2 * 1024 * 1024) => hivesResourceCall(client, id, input, options, mode, limit, 100_000);
70
+ return {
71
+ async list(project, query = {}, options) {
72
+ if (Object.keys(query).some(k => !['page', 'per_page'].includes(k)) || query.page !== undefined && (!Number.isInteger(query.page) || query.page < 1 || query.page > 10000) || query.per_page !== undefined && (!Number.isInteger(query.per_page) || query.per_page < 1 || query.per_page > 100))
73
+ throw resourceError(0);
74
+ const result = await call('hives_list_buckets', { ...query, ...ids(project) }, options);
75
+ if (!result || !Array.isArray(result.data) || !result.pagination)
76
+ throw resourceError(0);
77
+ return { ...result, data: result.data.map(row => bucket(row, project)) };
78
+ },
79
+ async get(project, id, options) { return bucket(await call('hives_get_bucket', ids(project, id), options), project, id); },
80
+ /** A pending provider_binding is an uncertain outcome, never a completed-create claim. */
81
+ async create(project, body, options) {
82
+ if (!body || typeof body.name !== 'string' || !/^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/.test(body.name) || body.region !== undefined && body.region !== 'us-central1'
83
+ || body.visibility !== undefined && !['private', 'publicread'].includes(body.visibility) || Object.keys(body).some(k => !['name', 'region', 'visibility', 'cors_rules'].includes(k)))
84
+ throw resourceError(0);
85
+ const checked = { ...body, ...(body.cors_rules === undefined ? {} : { cors_rules: cors(body.cors_rules) }) };
86
+ return bucket(await call('hives_create_bucket', { ...ids(project), body: checked }, options), project);
87
+ },
88
+ async remove(project, id, options) {
89
+ const result = await call('hives_delete_bucket', ids(project, id), options);
90
+ if (!result || result.id !== id || result.success !== true)
91
+ throw resourceError(0);
92
+ return result;
93
+ },
94
+ async reconcile(project, id, options) {
95
+ const result = await call('hives_reconcile', ids(project, id), options);
96
+ if (!result || typeof result.outcome !== 'string' || result.bucket?.id !== id)
97
+ throw resourceError(0);
98
+ return { ...result, bucket: bucket(result.bucket, project) };
99
+ },
100
+ cors: {
101
+ get: async (project, id, options) => cors(await call('hives_get_cors_config', ids(project, id), options)),
102
+ set: async (project, id, rules, options) => cors(await call('hives_set_cors_config', { ...ids(project, id), body: { rules: cors(rules) } }, options)),
103
+ },
104
+ objects: {
105
+ async list(project, id, query = {}, options) {
106
+ if (query.max_keys !== undefined && (!Number.isInteger(query.max_keys) || query.max_keys < 1 || query.max_keys > 1000))
107
+ throw resourceError(0);
108
+ const result = await call('hives_list_objects', { ...query, ...ids(project, id) }, options);
109
+ if (!result || !Array.isArray(result.objects) || !Array.isArray(result.common_prefixes) || typeof result.is_truncated !== 'boolean' || result.total !== null)
110
+ throw resourceError(0);
111
+ return { ...result, objects: result.objects.map(row => object(row, id)) };
112
+ },
113
+ async put(project, id, key, bytes, options = {}) {
114
+ const body = await hivesObjectBody(bytes);
115
+ const content_type = hivesContentType(options.content_type);
116
+ return acknowledgement(await call('hives_upload_object_by_key', { ...ids(project, id), key_base64url: hivesObjectKey(key), body, content_type }, options), key, id, body.byteLength);
117
+ },
118
+ remove: (project, id, key, options) => call('hives_delete_object_by_key', { ...ids(project, id), key_base64url: hivesObjectKey(key) }, options, 'empty'),
119
+ download: (project, id, key, options) => call('hives_download_object_by_key', { ...ids(project, id), key_base64url: hivesObjectKey(key) }, options, 'binary', HIVES_OBJECT_BYTES),
120
+ /** Existing flat-key path compatibility; nested keys use canonical collection methods above. */
121
+ async putFlat(project, id, key, bytes, options = {}) {
122
+ hivesObjectKey(key);
123
+ if (!/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/.test(key))
124
+ throw resourceError(0);
125
+ const body = await hivesObjectBody(bytes);
126
+ return acknowledgement(await call('hives_upload_object', { ...ids(project, id), key, body, content_type: hivesContentType(options.content_type) }, options), key, id, body.byteLength);
127
+ },
128
+ removeFlat: (project, id, key, options) => { hivesObjectKey(key); if (!/^[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*$/.test(key))
129
+ throw resourceError(0); return call('hives_delete_object', { ...ids(project, id), key }, options, 'empty'); },
130
+ },
131
+ async presign(project, id, body, options) {
132
+ hivesObjectKey(body.key);
133
+ const method = body.method ?? 'GET';
134
+ if (!['GET', 'PUT'].includes(method) || body.expires_in_secs !== undefined && (!Number.isInteger(body.expires_in_secs) || body.expires_in_secs < 60 || body.expires_in_secs > 900)
135
+ || method === 'PUT' && (body.content_length === undefined || !Number.isInteger(body.content_length) || body.content_length < 0 || body.content_length > HIVES_OBJECT_BYTES))
136
+ throw resourceError(0);
137
+ if (body.content_type !== undefined)
138
+ hivesContentType(body.content_type);
139
+ const result = await call('hives_generate_presigned_url', { ...ids(project, id), body }, options);
140
+ if (!result || typeof result.url !== 'string' || result.method !== method || typeof result.expires_at !== 'string')
141
+ throw resourceError(0);
142
+ const url = new URL(result.url);
143
+ if (url.protocol !== 'https:' || url.hostname !== 'storage.googleapis.com' || url.username || url.password || url.hash)
144
+ throw resourceError(0);
145
+ const headers = result.required_headers;
146
+ if (headers !== undefined && (!headers || typeof headers !== 'object' || Array.isArray(headers) || Object.entries(headers).some(([k, v]) => !['content-type', 'content-length', 'x-goog-if-generation-match'].includes(k.toLowerCase()) || typeof v !== 'string' || /[\u0000-\u001f\u007f]/.test(v))))
147
+ throw resourceError(0);
148
+ return { url: result.url, expires_at: result.expires_at, method: result.method, ...(headers ? { required_headers: { ...headers } } : {}) };
149
+ },
150
+ };
151
+ }
@@ -0,0 +1,37 @@
1
+ /** Environment metadata never carries stored values. Reveals are explicit. */
2
+ export declare function validateHivesEnvironment(input: unknown): Record<string, string>;
3
+ /** Names for DELETE /env: 1–100 distinct valid environment names. */
4
+ export declare function validateHivesEnvironmentNames(input: unknown): string[];
5
+ export declare function hivesEnvironmentMetadata(value: unknown, project: unknown, updated: boolean): {
6
+ project_id: string;
7
+ updated: {
8
+ name: string;
9
+ }[];
10
+ data?: undefined;
11
+ pagination?: undefined;
12
+ } | {
13
+ project_id: string;
14
+ data: {
15
+ name: string;
16
+ }[];
17
+ pagination: {
18
+ page: unknown;
19
+ per_page: unknown;
20
+ total: unknown;
21
+ total_pages: unknown;
22
+ has_next: boolean;
23
+ has_prev: boolean;
24
+ };
25
+ updated?: undefined;
26
+ };
27
+ export declare function hivesEnvironmentReveal(value: unknown, key: unknown): {
28
+ name: string;
29
+ value: string;
30
+ };
31
+ /** PUT /env answers the whole decrypted map. Keep only the submitted names it confirms; never a value. */
32
+ export declare function hivesEnvironmentSetNames(value: unknown, project: unknown, submitted: unknown): {
33
+ project_id: string;
34
+ updated: {
35
+ name: string;
36
+ }[];
37
+ };
@@ -0,0 +1,80 @@
1
+ /** Environment metadata never carries stored values. Reveals are explicit. */
2
+ export function validateHivesEnvironment(input) {
3
+ if (!input || typeof input !== 'object' || Array.isArray(input))
4
+ throw new Error('Environment input must be a flat JSON map of names to string values.');
5
+ const entries = Object.entries(input);
6
+ if (entries.length < 1 || entries.length > 100)
7
+ throw new Error('Environment updates require 1–100 names.');
8
+ const result = Object.create(null);
9
+ for (const [name, value] of entries) {
10
+ if (name.length > 255 || !/^[A-Za-z][A-Za-z0-9_]*$/.test(name))
11
+ throw new Error('Environment names must start with a letter and contain only letters, numbers and underscores (up to 255 characters).');
12
+ if (typeof value !== 'string' || new TextEncoder().encode(value).length > 65536)
13
+ throw new Error('Environment values must be strings of at most 65,536 UTF-8 bytes. Empty values are allowed.');
14
+ result[name] = value;
15
+ }
16
+ if (new TextEncoder().encode(JSON.stringify(result)).length > 2 * 1024 * 1024)
17
+ throw new Error('Environment input exceeds 2 MiB. Split it into smaller batches.');
18
+ return result;
19
+ }
20
+ /** Names for DELETE /env: 1–100 distinct valid environment names. */
21
+ export function validateHivesEnvironmentNames(input) {
22
+ if (!Array.isArray(input) || input.length < 1 || input.length > 100)
23
+ throw new Error('Environment deletion requires a JSON array of 1–100 names.');
24
+ for (const name of input) {
25
+ if (typeof name !== 'string' || name.length > 255 || !/^[A-Za-z][A-Za-z0-9_]*$/.test(name))
26
+ throw new Error('Environment names must start with a letter and contain only letters, numbers and underscores (up to 255 characters).');
27
+ }
28
+ if (new Set(input).size !== input.length)
29
+ throw new Error('Environment deletion names must be distinct.');
30
+ return [...input];
31
+ }
32
+ function record(value) {
33
+ if (!value || typeof value !== 'object' || Array.isArray(value))
34
+ throw new Error('Hives returned invalid environment metadata.');
35
+ return value;
36
+ }
37
+ function names(value) {
38
+ if (!Array.isArray(value))
39
+ throw new Error('Hives returned invalid environment metadata.');
40
+ return value.map((value) => {
41
+ const row = record(value);
42
+ if (typeof row.name !== 'string')
43
+ throw new Error('Hives returned invalid environment metadata.');
44
+ return { name: row.name };
45
+ });
46
+ }
47
+ export function hivesEnvironmentMetadata(value, project, updated) {
48
+ const data = record(value);
49
+ if (typeof project !== 'string' || data.project_id !== project)
50
+ throw new Error('Hives returned environment metadata for a different project.');
51
+ if (updated)
52
+ return { project_id: project, updated: names(data.updated) };
53
+ const pagination = record(data.pagination);
54
+ for (const key of ['page', 'per_page', 'total', 'total_pages']) {
55
+ if (!Number.isSafeInteger(pagination[key]) || pagination[key] < (key === 'page' || key === 'per_page' ? 1 : 0))
56
+ throw new Error('Hives returned invalid environment pagination.');
57
+ }
58
+ if (typeof pagination.has_next !== 'boolean' || typeof pagination.has_prev !== 'boolean')
59
+ throw new Error('Hives returned invalid environment pagination.');
60
+ return { project_id: project, data: names(data.data), pagination: {
61
+ page: pagination.page, per_page: pagination.per_page, total: pagination.total, total_pages: pagination.total_pages,
62
+ has_next: pagination.has_next, has_prev: pagination.has_prev,
63
+ } };
64
+ }
65
+ export function hivesEnvironmentReveal(value, key) {
66
+ const data = record(value);
67
+ if (typeof key !== 'string' || data.name !== key || typeof data.value !== 'string' || new TextEncoder().encode(data.value).length > 65536)
68
+ throw new Error('Hives returned invalid environment reveal data.');
69
+ return { name: data.name, value: data.value };
70
+ }
71
+ /** PUT /env answers the whole decrypted map. Keep only the submitted names it confirms; never a value. */
72
+ export function hivesEnvironmentSetNames(value, project, submitted) {
73
+ const data = record(value);
74
+ if (typeof project !== 'string' || !submitted || typeof submitted !== 'object')
75
+ throw new Error('Hives returned invalid environment data.');
76
+ const updated = Object.keys(submitted);
77
+ if (updated.some((name) => typeof data[name] !== 'string'))
78
+ throw new Error('Hives did not confirm every submitted environment name. Read the names before retrying.');
79
+ return { project_id: project, updated: updated.map((name) => ({ name })) };
80
+ }
@@ -0,0 +1,36 @@
1
+ import { GenesisError } from './errors.js';
2
+ /** The service separately bounds its serialized guest stdin envelope at 10 MiB. */
3
+ export declare const MAX_FUNCTION_BODY_BYTES: number;
4
+ export declare const MAX_FUNCTION_JSON_BYTES: number;
5
+ export interface HivesInvokeRequest {
6
+ method?: string;
7
+ path?: string;
8
+ headers?: Record<string, string>;
9
+ body?: unknown;
10
+ body_base64?: string;
11
+ }
12
+ export interface HivesInvokeOptions {
13
+ signal?: AbortSignal;
14
+ idempotencyKey?: string;
15
+ }
16
+ export interface HivesOperationStatus {
17
+ operation_id: string;
18
+ state: 'prepared' | 'reserve_unknown' | 'reserved' | 'dispatch_unknown' | 'dispatch_authorized' | 'dispatched' | 'settle_unknown' | 'settled' | 'release_pending' | 'released';
19
+ code: string;
20
+ funding_source: 'sandbox_allowance' | 'stripe_test_metered' | null;
21
+ reservation_id: string | null;
22
+ retry_execution: false;
23
+ }
24
+ export declare function hivesInvokeHeaders(options: HivesInvokeOptions): Record<string, string>;
25
+ export declare function hivesOperationStatus(value: unknown, expected: string): HivesOperationStatus;
26
+ export declare class HivesOperationError extends GenesisError {
27
+ readonly operation: HivesOperationStatus;
28
+ constructor(status: number, operation: HivesOperationStatus);
29
+ }
30
+ /** Read only the small platform receipt; never retain reflected guest request data. */
31
+ export declare function hivesOperationError(response: Response): Promise<HivesOperationError | undefined>;
32
+ export declare function validateHivesInvocation(input: unknown): asserts input is HivesInvokeRequest;
33
+ /** Safe display/transport headers; customer headers never establish identity. */
34
+ export declare function hivesFunctionResponseHeaders(headers: Headers): Headers;
35
+ /** Metadata contracts cannot accidentally expose an upstream env/ciphertext field. */
36
+ export declare function hivesFunctionMetadata(input: unknown, project: unknown, expectedId?: unknown): Record<string, unknown>;
@@ -0,0 +1,185 @@
1
+ import { GenesisError } from './errors.js';
2
+ /** The service separately bounds its serialized guest stdin envelope at 10 MiB. */
3
+ export const MAX_FUNCTION_BODY_BYTES = 10 * 1024 * 1024;
4
+ export const MAX_FUNCTION_JSON_BYTES = 16 * 1024 * 1024;
5
+ const executionId = /^exec_[a-f0-9]{32}$/;
6
+ export function hivesInvokeHeaders(options) {
7
+ if (options.idempotencyKey === undefined)
8
+ return {};
9
+ if (!/^[A-Za-z0-9_.:@-]{1,128}$/.test(options.idempotencyKey))
10
+ throw new Error('Use one persisted Hives idempotency key of 1–128 identifier characters.');
11
+ return { 'idempotency-key': options.idempotencyKey };
12
+ }
13
+ export function hivesOperationStatus(value, expected) {
14
+ const row = value;
15
+ const keys = ['operation_id', 'state', 'code', 'funding_source', 'reservation_id', 'retry_execution'];
16
+ if (!executionId.test(expected) || !row || typeof row !== 'object' || Array.isArray(row)
17
+ || Object.keys(row).length !== keys.length || keys.some(key => !Object.hasOwn(row, key))
18
+ || row.operation_id !== expected || row.retry_execution !== false
19
+ || !['prepared', 'reserve_unknown', 'reserved', 'dispatch_unknown', 'dispatch_authorized', 'dispatched', 'settle_unknown', 'settled', 'release_pending', 'released'].includes(row.state)
20
+ || typeof row.code !== 'string' || !/^[a-z_]{1,80}$/.test(row.code)
21
+ || row.funding_source !== null && row.funding_source !== 'sandbox_allowance' && row.funding_source !== 'stripe_test_metered'
22
+ || row.reservation_id !== null && !/^gfr_[A-Za-z0-9_.:@-]{1,124}$/.test(row.reservation_id)) {
23
+ throw new Error('Hives returned invalid or mismatched operation status. Keep the original idempotency key.');
24
+ }
25
+ return row;
26
+ }
27
+ export class HivesOperationError extends GenesisError {
28
+ operation;
29
+ constructor(status, operation) {
30
+ super({ status, type: 'hives_operation_unresolved', message: 'Read the original Hives operation status. Do not invoke with a new idempotency key.', body: operation });
31
+ this.operation = operation;
32
+ }
33
+ }
34
+ /** Read only the small platform receipt; never retain reflected guest request data. */
35
+ export async function hivesOperationError(response) {
36
+ const expected = response.headers.get('x-hives-operation-id');
37
+ if (!expected || !executionId.test(expected) || !response.body)
38
+ return undefined;
39
+ const reader = response.body.getReader();
40
+ const chunks = [];
41
+ let size = 0;
42
+ try {
43
+ for (;;) {
44
+ const { value, done } = await reader.read();
45
+ if (done)
46
+ break;
47
+ size += value.length;
48
+ if (size > 2048) {
49
+ await reader.cancel();
50
+ return undefined;
51
+ }
52
+ chunks.push(value);
53
+ }
54
+ const bytes = new Uint8Array(size);
55
+ let offset = 0;
56
+ for (const chunk of chunks) {
57
+ bytes.set(chunk, offset);
58
+ offset += chunk.length;
59
+ }
60
+ return new HivesOperationError(response.status, hivesOperationStatus(JSON.parse(new TextDecoder().decode(bytes)), expected));
61
+ }
62
+ catch {
63
+ return undefined;
64
+ }
65
+ finally {
66
+ reader.releaseLock();
67
+ }
68
+ }
69
+ const reservedHeaders = new Set(['host', 'connection', 'content-length', 'transfer-encoding', 'keep-alive',
70
+ 'proxy-authenticate', 'proxy-authorization', 'te', 'trailer', 'upgrade', 'set-cookie', 'clear-site-data',
71
+ 'authorization', 'cookie', 'forwarded', 'origin', 'referer', 'x-org-id', 'x-workspace-id', 'x-project-id',
72
+ 'x-admin-token', 'x-tenant-id', 'x-cold-start']);
73
+ const platformHeader = (name) => /^x-(?:auth|genesis|life|l1fe|hives|forwarded|execution)-/.test(name);
74
+ const bytes = (value) => new TextEncoder().encode(value).length;
75
+ const fail = () => { throw new Error('Invalid function request. Check method, path, headers, exclusive body encoding and size limits.'); };
76
+ export function validateHivesInvocation(input) {
77
+ if (!input || typeof input !== 'object' || Array.isArray(input))
78
+ fail();
79
+ const r = input;
80
+ if (Object.keys(r).some((k) => !['method', 'path', 'headers', 'body', 'body_base64'].includes(k)))
81
+ fail();
82
+ if (r.method !== undefined && (typeof r.method !== 'string' || bytes(r.method) > 64 || !/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(r.method)))
83
+ fail();
84
+ if (r.path !== undefined && (typeof r.path !== 'string' || !r.path.startsWith('/') || r.path.startsWith('//') || r.path.includes('#') || bytes(r.path) > 8192 || /[\s\u0000-\u001f\u007f]/.test(r.path)))
85
+ fail();
86
+ let headerBytes = 0;
87
+ if (r.headers !== undefined) {
88
+ if (!r.headers || typeof r.headers !== 'object' || Array.isArray(r.headers) || Object.keys(r.headers).length > 128)
89
+ fail();
90
+ for (const [key, value] of Object.entries(r.headers)) {
91
+ if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(key) || typeof value !== 'string' || /[\u0000-\u0008\u000a-\u001f\u007f]/.test(value)
92
+ || reservedHeaders.has(key.toLowerCase()) || platformHeader(key.toLowerCase()))
93
+ fail();
94
+ headerBytes += bytes(key) + bytes(value);
95
+ if (headerBytes > 64 * 1024)
96
+ fail();
97
+ }
98
+ }
99
+ let size = 0;
100
+ if (r.body_base64 !== undefined) {
101
+ const value = r.body_base64;
102
+ if (r.body != null || typeof value !== 'string' || value.length > Math.ceil(MAX_FUNCTION_BODY_BYTES / 3) * 4
103
+ || value.length % 4 || !/^[A-Za-z0-9+/]*={0,2}$/.test(value))
104
+ fail();
105
+ try {
106
+ const bytes = atob(value);
107
+ if (btoa(bytes) !== value)
108
+ fail();
109
+ size = bytes.length;
110
+ }
111
+ catch {
112
+ fail();
113
+ }
114
+ }
115
+ else if (r.body != null) {
116
+ let value;
117
+ try {
118
+ value = typeof r.body === 'string' ? r.body : JSON.stringify(r.body);
119
+ }
120
+ catch {
121
+ fail();
122
+ }
123
+ if (value === undefined)
124
+ fail();
125
+ size = new TextEncoder().encode(value).length;
126
+ }
127
+ let serialized;
128
+ try {
129
+ serialized = JSON.stringify(r);
130
+ }
131
+ catch {
132
+ fail();
133
+ }
134
+ if (size + headerBytes > MAX_FUNCTION_BODY_BYTES || !serialized || new TextEncoder().encode(serialized).length > MAX_FUNCTION_JSON_BYTES)
135
+ fail();
136
+ }
137
+ /** Safe display/transport headers; customer headers never establish identity. */
138
+ export function hivesFunctionResponseHeaders(headers) {
139
+ const blocked = new Set(['connection', 'keep-alive', 'transfer-encoding', 'upgrade', 'proxy-authenticate', 'proxy-authorization',
140
+ 'te', 'trailer', 'content-length', 'content-encoding', 'set-cookie', 'clear-site-data', 'authorization', 'cookie', 'forwarded', 'host', 'x-org-id', 'x-workspace-id', 'x-project-id', 'x-admin-token', 'x-tenant-id', 'x-hives-guest-status']);
141
+ for (const value of (headers.get('connection') ?? '').split(','))
142
+ blocked.add(value.trim().toLowerCase());
143
+ const safe = new Headers();
144
+ headers.forEach((value, name) => {
145
+ if (!blocked.has(name) && (!platformHeader(name) || ['x-execution-id', 'x-execution-duration-ms'].includes(name)))
146
+ safe.set(name, value);
147
+ });
148
+ const operation = headers.get('x-hives-operation-id');
149
+ if (operation && executionId.test(operation) && operation === headers.get('x-execution-id'))
150
+ safe.set('x-hives-operation-id', operation);
151
+ const observation = headers.get('x-execution-observation-v1');
152
+ if (observation && validObservation(observation))
153
+ safe.set('x-execution-observation-v1', observation);
154
+ safe.set('cache-control', 'no-store');
155
+ return safe;
156
+ }
157
+ function validObservation(encoded) {
158
+ if (encoded.length > 2048 || !/^[A-Za-z0-9_-]+$/.test(encoded))
159
+ return false;
160
+ try {
161
+ const value = JSON.parse(atob(encoded.replace(/-/g, '+').replace(/_/g, '/')));
162
+ const numbers = ['reserved_memory_bytes', 'reserved_cpu_millis', 'admission_wait_us'];
163
+ const nullable = ['executor_poll_cpu_ns', 'exported_linear_memory_bytes'];
164
+ const keys = [...numbers, ...nullable, 'version', 'cpu_scope', 'complete_execution_cpu', 'peak_linear_memory_bytes', 'execution_resident_memory_bytes'];
165
+ return value && typeof value === 'object' && Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key))
166
+ && value.version === 1 && value.cpu_scope === 'executor_thread_polls' && value.complete_execution_cpu === false
167
+ && value.peak_linear_memory_bytes === null && value.execution_resident_memory_bytes === null
168
+ && numbers.every(key => Number.isSafeInteger(value[key]) && value[key] >= 0)
169
+ && nullable.every(key => value[key] === null || Number.isSafeInteger(value[key]) && value[key] >= 0);
170
+ }
171
+ catch {
172
+ return false;
173
+ }
174
+ }
175
+ /** Metadata contracts cannot accidentally expose an upstream env/ciphertext field. */
176
+ export function hivesFunctionMetadata(input, project, expectedId) {
177
+ if (!input || typeof input !== 'object' || input.project_id !== project) {
178
+ throw new Error('Hives returned invalid or wrong-project function metadata.');
179
+ }
180
+ const row = input;
181
+ if (expectedId !== undefined && row.id !== expectedId)
182
+ throw new Error('Hives returned mismatched function metadata.');
183
+ return Object.fromEntries(['id', 'tenant_id', 'project_id', 'name', 'description', 'handler', 'route', 'memory_mb', 'timeout_ms',
184
+ 'status', 'invocations', 'avg_duration_ms', 'created_at', 'updated_at'].map((key) => [key, row[key]]));
185
+ }