@onesi/genesis 0.1.13 → 0.2.1
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.
- package/README.md +1 -1
- package/dist/auto.d.ts +1010 -0
- package/dist/auto.js +125 -0
- package/dist/beacons.d.ts +42 -0
- package/dist/beacons.js +71 -0
- package/dist/blinds-owner-enrollment.d.ts +121 -0
- package/dist/blinds-owner-enrollment.js +23 -2
- package/dist/boxes.d.ts +1074 -0
- package/dist/boxes.js +338 -0
- package/dist/client.d.ts +3 -19947
- package/dist/client.js +127 -18
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +38 -3
- package/dist/flares.d.ts +32 -0
- package/dist/flares.js +5 -0
- package/dist/fleets.d.ts +32 -0
- package/dist/fleets.js +59 -6
- package/dist/flocks.d.ts +334 -1
- package/dist/flocks.js +85 -0
- package/dist/foundry.d.ts +429 -0
- package/dist/foundry.js +135 -0
- package/dist/garden.d.ts +754 -0
- package/dist/garden.js +76 -0
- package/dist/gateway.d.ts +365 -0
- package/dist/gateway.js +82 -0
- package/dist/gears.d.ts +121 -2
- package/dist/gears.js +24 -2
- package/dist/generated/operations.d.ts +3 -19948
- package/dist/generated/operations.js +64214 -13423
- package/dist/generated/schema.d.ts +85708 -17364
- package/dist/genesis.d.ts +9041 -1250
- package/dist/genesis.js +92 -25
- package/dist/genesis.openapi.json +133172 -31267
- package/dist/henry.d.ts +202 -1
- package/dist/henry.js +223 -0
- package/dist/hives-cells.d.ts +8 -3
- package/dist/hives-cells.js +17 -4
- package/dist/hives-environment.d.ts +9 -0
- package/dist/hives-environment.js +22 -0
- package/dist/hives-node.js +4 -1
- package/dist/hives-operations.d.ts +121 -3
- package/dist/hives-operations.js +2 -0
- package/dist/hives-platform.d.ts +149 -0
- package/dist/hives-platform.js +183 -0
- package/dist/hives-resources-transport.d.ts +7 -1
- package/dist/hives-resources-transport.js +10 -2
- package/dist/hives-sse.d.ts +24 -0
- package/dist/hives-sse.js +111 -0
- package/dist/hives-topics.d.ts +4 -3
- package/dist/hives-topics.js +9 -4
- package/dist/iam-directory.d.ts +8 -0
- package/dist/iam-directory.js +23 -0
- package/dist/iam.d.ts +397 -0
- package/dist/iam.js +92 -0
- package/dist/idempotency.d.ts +3 -0
- package/dist/idempotency.js +27 -0
- package/dist/index.d.ts +22 -6
- package/dist/index.js +19 -5
- package/dist/instances.d.ts +177 -2
- package/dist/instances.js +37 -5
- package/dist/minds-agent.d.ts +28 -0
- package/dist/minds-agent.js +53 -10
- package/dist/minds-engine.d.ts +394 -0
- package/dist/minds-engine.js +555 -0
- package/dist/minds.d.ts +109 -1
- package/dist/minds.js +49 -14
- package/dist/orgs.d.ts +405 -0
- package/dist/orgs.js +63 -0
- package/dist/redact.d.ts +37 -0
- package/dist/redact.js +330 -0
- package/dist/runner.d.ts +4 -0
- package/dist/runner.js +1 -0
- package/dist/scopes.d.ts +316 -0
- package/dist/scopes.js +40 -0
- package/dist/taps.d.ts +118 -0
- package/dist/taps.js +45 -0
- package/dist/traces.d.ts +574 -0
- package/dist/traces.js +97 -0
- package/dist/types.d.ts +12 -1
- package/package.json +1 -1
|
@@ -17,6 +17,18 @@ export function validateHivesEnvironment(input) {
|
|
|
17
17
|
throw new Error('Environment input exceeds 2 MiB. Split it into smaller batches.');
|
|
18
18
|
return result;
|
|
19
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
|
+
}
|
|
20
32
|
function record(value) {
|
|
21
33
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
22
34
|
throw new Error('Hives returned invalid environment metadata.');
|
|
@@ -56,3 +68,13 @@ export function hivesEnvironmentReveal(value, key) {
|
|
|
56
68
|
throw new Error('Hives returned invalid environment reveal data.');
|
|
57
69
|
return { name: data.name, value: data.value };
|
|
58
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
|
+
}
|
package/dist/hives-node.js
CHANGED
|
@@ -12,10 +12,13 @@ export async function closeHivesNodeTransport() {
|
|
|
12
12
|
await current?.destroy();
|
|
13
13
|
}
|
|
14
14
|
export function hivesOperationBudget(id) {
|
|
15
|
-
if (['hives_list_buckets', 'hives_create_bucket', 'hives_get_bucket', 'hives_delete_bucket', 'hives_list_objects', 'hives_upload_object', 'hives_upload_object_by_key', 'hives_delete_object', 'hives_delete_object_by_key', 'hives_download_object_by_key', 'hives_get_cors_config', 'hives_set_cors_config', 'hives_generate_presigned_url', 'hives_reconcile'].includes(id))
|
|
15
|
+
if (['hives_list_buckets', 'hives_create_bucket', 'hives_get_bucket', 'hives_delete_bucket', 'hives_list_objects', 'hives_upload_object', 'hives_upload_object_by_key', 'hives_upload_object_named_download', 'hives_delete_object', 'hives_delete_object_by_key', 'hives_delete_object_named_download', 'hives_download_object_by_key', 'hives_get_cors_config', 'hives_set_cors_config', 'hives_generate_presigned_url', 'hives_reconcile'].includes(id))
|
|
16
16
|
return 100_000;
|
|
17
17
|
if (id === 'hives_cancel_deployment' || id === 'hives_delete_deployment' || id === 'hives_stop_deployment')
|
|
18
18
|
return 330_000;
|
|
19
|
+
// A live SSE subscription is bounded by its caller's window or --follow limit (at most 300 s).
|
|
20
|
+
if (id === 'hives_stream_logs' || id === 'hives_stream_deployment_logs')
|
|
21
|
+
return 330_000;
|
|
19
22
|
if (['hives_create_deployment', 'hives_upload_deployment', 'hives_invoke_deployment', 'hives_invoke_function', 'hives_invoke_function_async'].includes(id))
|
|
20
23
|
return 40_000;
|
|
21
24
|
if (['hives_create_function', 'hives_update_function', 'hives_delete_function'].includes(id))
|
|
@@ -29,15 +29,19 @@ export declare function hivesOperations(client: GenesisClient): {
|
|
|
29
29
|
continuation_token?: string;
|
|
30
30
|
max_keys?: number;
|
|
31
31
|
}, options?: import("./hives-resources-transport.js").HivesResourceOptions): Promise<import("./hives-cells.js").HivesObjectList>;
|
|
32
|
-
put(project: string, id: string, key: string, bytes: Blob | ArrayBuffer | ArrayBufferView, options?: import("./hives-resources-transport.js").
|
|
32
|
+
put(project: string, id: string, key: string, bytes: Blob | ArrayBuffer | ArrayBufferView, options?: import("./hives-resources-transport.js").HivesFundedWriteOptions & {
|
|
33
33
|
content_type?: string;
|
|
34
34
|
}): Promise<import("./hives-cells.js").HivesObjectAcknowledgement>;
|
|
35
35
|
remove: (project: string, id: string, key: string, options?: import("./hives-resources-transport.js").HivesResourceOptions) => Promise<void>;
|
|
36
36
|
download: (project: string, id: string, key: string, options?: import("./hives-resources-transport.js").HivesResourceOptions) => Promise<Response>;
|
|
37
|
-
putFlat(project: string, id: string, key: string, bytes: Blob | ArrayBuffer | ArrayBufferView, options?: import("./hives-resources-transport.js").
|
|
37
|
+
putFlat(project: string, id: string, key: string, bytes: Blob | ArrayBuffer | ArrayBufferView, options?: import("./hives-resources-transport.js").HivesFundedWriteOptions & {
|
|
38
38
|
content_type?: string;
|
|
39
39
|
}): Promise<import("./hives-cells.js").HivesObjectAcknowledgement>;
|
|
40
40
|
removeFlat: (project: string, id: string, key: string, options?: import("./hives-resources-transport.js").HivesResourceOptions) => Promise<void>;
|
|
41
|
+
putDownload(project: string, id: string, bytes: Blob | ArrayBuffer | ArrayBufferView, options?: import("./hives-resources-transport.js").HivesFundedWriteOptions & {
|
|
42
|
+
content_type?: string;
|
|
43
|
+
}): Promise<import("./hives-cells.js").HivesObjectAcknowledgement>;
|
|
44
|
+
removeDownload: (project: string, id: string, options?: import("./hives-resources-transport.js").HivesResourceOptions) => Promise<void>;
|
|
41
45
|
};
|
|
42
46
|
presign(project: string, id: string, body: import("./hives-cells.js").HivesPresign, options?: import("./hives-resources-transport.js").HivesResourceOptions): Promise<import("./hives-cells.js").HivesPresignedUrl>;
|
|
43
47
|
};
|
|
@@ -125,7 +129,7 @@ export declare function hivesOperations(client: GenesisClient): {
|
|
|
125
129
|
deleted: true;
|
|
126
130
|
}>;
|
|
127
131
|
};
|
|
128
|
-
publish(project: string, id: string, body: import("./hives-topics.js").HivesTopicPublish, options?: import("./hives-resources-transport.js").
|
|
132
|
+
publish(project: string, id: string, body: import("./hives-topics.js").HivesTopicPublish, options?: import("./hives-resources-transport.js").HivesFundedWriteOptions): Promise<import("./hives-topics.js").HivesTopicPublication>;
|
|
129
133
|
};
|
|
130
134
|
runtimes: {
|
|
131
135
|
list: (options?: import("./hives-resources-transport.js").HivesResourceOptions) => Promise<{
|
|
@@ -334,4 +338,118 @@ export declare function hivesOperations(client: GenesisClient): {
|
|
|
334
338
|
updated_at: string;
|
|
335
339
|
}>;
|
|
336
340
|
};
|
|
341
|
+
logs: {
|
|
342
|
+
query: (project_id: string, q?: Omit<In<"hives_query_logs">, "project_id">) => Promise<{
|
|
343
|
+
logs: import("./index.js").components["schemas"]["Hives.LogEntry"][];
|
|
344
|
+
pagination: import("./index.js").components["schemas"]["Hives.PaginationMeta"];
|
|
345
|
+
time_range: import("./index.js").components["schemas"]["Hives.TimeRange"];
|
|
346
|
+
}>;
|
|
347
|
+
stream: (project_id: string, q?: import("./hives-platform.js").HivesLogStreamQuery, init?: {
|
|
348
|
+
signal?: AbortSignal;
|
|
349
|
+
}) => AsyncGenerator<import("./hives-platform.js").HivesLogStreamEvent, void, any>;
|
|
350
|
+
window: (project_id: string, q?: import("./hives-platform.js").HivesLogStreamQuery, options?: import("./hives-platform.js").HivesLogWindowOptions) => Promise<import("./hives-platform.js").HivesLogWindow>;
|
|
351
|
+
};
|
|
352
|
+
domains: {
|
|
353
|
+
list: (project_id: string, q?: Omit<In<"hives_list_domains">, "project_id">) => Promise<{
|
|
354
|
+
data: {
|
|
355
|
+
created_at: string;
|
|
356
|
+
dns_status: string;
|
|
357
|
+
domain: string;
|
|
358
|
+
domain_type: import("./index.js").components["schemas"]["Hives.DomainType"];
|
|
359
|
+
id: string;
|
|
360
|
+
ssl_expires_at?: string | null;
|
|
361
|
+
ssl_status: string;
|
|
362
|
+
verification_record?: null | import("./index.js").components["schemas"]["Hives.VerificationRecord"];
|
|
363
|
+
}[];
|
|
364
|
+
pagination: import("./index.js").components["schemas"]["Hives.PaginationMeta"];
|
|
365
|
+
}>;
|
|
366
|
+
add: (project_id: string, body: In<"hives_add_domain">["body"]) => Promise<{
|
|
367
|
+
created_at: string;
|
|
368
|
+
dns_status: string;
|
|
369
|
+
domain: string;
|
|
370
|
+
domain_type: import("./index.js").components["schemas"]["Hives.DomainType"];
|
|
371
|
+
id: string;
|
|
372
|
+
ssl_expires_at?: string | null;
|
|
373
|
+
ssl_status: string;
|
|
374
|
+
verification_record?: null | import("./index.js").components["schemas"]["Hives.VerificationRecord"];
|
|
375
|
+
}>;
|
|
376
|
+
verify: (project_id: string, domain_id: string) => Promise<{
|
|
377
|
+
checked_at: string;
|
|
378
|
+
dns_status: string;
|
|
379
|
+
error?: string | null;
|
|
380
|
+
verified: boolean;
|
|
381
|
+
}>;
|
|
382
|
+
provisionSsl: (project_id: string, domain_id: string) => Promise<{
|
|
383
|
+
error?: string | null;
|
|
384
|
+
expires_at?: string | null;
|
|
385
|
+
ssl_status: string;
|
|
386
|
+
started: boolean;
|
|
387
|
+
}>;
|
|
388
|
+
};
|
|
389
|
+
auth: {
|
|
390
|
+
me: () => Promise<{
|
|
391
|
+
avatar?: string | null;
|
|
392
|
+
createdAt: string;
|
|
393
|
+
email: string;
|
|
394
|
+
id: string;
|
|
395
|
+
name: string;
|
|
396
|
+
organizationId?: string | null;
|
|
397
|
+
role: string;
|
|
398
|
+
}>;
|
|
399
|
+
};
|
|
400
|
+
fleets: {
|
|
401
|
+
list: () => Promise<{
|
|
402
|
+
fleets: import("./index.js").components["schemas"]["Hives.FleetStatusView"][];
|
|
403
|
+
}>;
|
|
404
|
+
deploy: (body: In<"hives_deploy_fleet">["body"]) => Promise<{
|
|
405
|
+
fleetId: string;
|
|
406
|
+
gatewayEndpoint?: string | null;
|
|
407
|
+
totalInstances: number;
|
|
408
|
+
}>;
|
|
409
|
+
status: (fleet_id: string) => Promise<{
|
|
410
|
+
fleetId: string;
|
|
411
|
+
gateway?: null | import("./index.js").components["schemas"]["Hives.GatewaySummary"];
|
|
412
|
+
healthyInstances: number;
|
|
413
|
+
name: string;
|
|
414
|
+
protocols: import("./index.js").components["schemas"]["Hives.ProtocolStatusView"][];
|
|
415
|
+
state: string;
|
|
416
|
+
totalInstances: number;
|
|
417
|
+
}>;
|
|
418
|
+
teardown: (fleet_id: string) => Promise<void>;
|
|
419
|
+
};
|
|
420
|
+
remote: {
|
|
421
|
+
sessions: {
|
|
422
|
+
list: (project_id: string, q?: Omit<In<"hives_list_remote_sessions">, "project_id">) => Promise<Record<string, never>>;
|
|
423
|
+
close: (project_id: string, session_id: string) => Promise<Record<string, never>>;
|
|
424
|
+
};
|
|
425
|
+
ssh: (project_id: string, body: In<"hives_create_ssh_session">["body"]) => Promise<{
|
|
426
|
+
expires_at: string;
|
|
427
|
+
fingerprint: string;
|
|
428
|
+
host: string;
|
|
429
|
+
port: number;
|
|
430
|
+
session_id: string;
|
|
431
|
+
username: string;
|
|
432
|
+
}>;
|
|
433
|
+
terminal: (project_id: string, body: In<"hives_create_terminal_session">["body"]) => Promise<{
|
|
434
|
+
expires_at: string;
|
|
435
|
+
session_id: string;
|
|
436
|
+
token: string;
|
|
437
|
+
websocket_url: string;
|
|
438
|
+
}>;
|
|
439
|
+
debug: (project_id: string, body: In<"hives_create_debug_session">["body"]) => Promise<{
|
|
440
|
+
debug_url: string;
|
|
441
|
+
expires_at: string;
|
|
442
|
+
protocol: string;
|
|
443
|
+
session_id: string;
|
|
444
|
+
token: string;
|
|
445
|
+
}>;
|
|
446
|
+
sftp: {
|
|
447
|
+
list: (project_id: string, target_id: string, q?: {
|
|
448
|
+
path?: string;
|
|
449
|
+
}) => Promise<Record<string, never>>;
|
|
450
|
+
read: (project_id: string, target_id: string, path: string) => Promise<Record<string, never>>;
|
|
451
|
+
write: (project_id: string, target_id: string, body: In<"hives_sftp_write">["body"]) => Promise<Record<string, never>>;
|
|
452
|
+
delete: (project_id: string, target_id: string, body: In<"hives_sftp_delete">["body"]) => Promise<Record<string, never>>;
|
|
453
|
+
};
|
|
454
|
+
};
|
|
337
455
|
};
|
package/dist/hives-operations.js
CHANGED
|
@@ -2,9 +2,11 @@ import { hivesTopics } from './hives-topics.js';
|
|
|
2
2
|
import { hivesCells } from './hives-cells.js';
|
|
3
3
|
import { hivesQueues } from './hives-queues.js';
|
|
4
4
|
import { hivesRuntimes } from './hives-runtimes.js';
|
|
5
|
+
import { hivesPlatform } from './hives-platform.js';
|
|
5
6
|
/** The original Hives scheduler, settings and measured activity use the same gateway and identity. */
|
|
6
7
|
export function hivesOperations(client) {
|
|
7
8
|
return {
|
|
9
|
+
...hivesPlatform(client),
|
|
8
10
|
cells: hivesCells(client),
|
|
9
11
|
queues: hivesQueues(client),
|
|
10
12
|
topics: hivesTopics(client),
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { GenesisClient } from './client.js';
|
|
2
|
+
import type { OperationInput as In } from './types.js';
|
|
3
|
+
/** One Server-Sent Event from `GET /v1/hives/projects/{project_id}/logs/stream`. `data` is parsed JSON when it is JSON. */
|
|
4
|
+
export interface HivesLogStreamEvent {
|
|
5
|
+
event: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
data: unknown;
|
|
8
|
+
}
|
|
9
|
+
export type HivesLogStreamQuery = Omit<In<'hives_stream_logs'>, 'project_id'>;
|
|
10
|
+
export interface HivesLogWindowOptions {
|
|
11
|
+
/** Stop after this many events (1–10000, default 100). */
|
|
12
|
+
maxEvents?: number;
|
|
13
|
+
/** Stop after this many seconds (1–300, default 10). */
|
|
14
|
+
seconds?: number;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
export interface HivesLogWindow {
|
|
18
|
+
events: HivesLogStreamEvent[];
|
|
19
|
+
ended: 'max_events' | 'time' | 'closed';
|
|
20
|
+
}
|
|
21
|
+
/** Pull-based SSE reader. `cancel()` closes the connection even while a read is pending. */
|
|
22
|
+
export declare function hivesSseReader(response: Response): {
|
|
23
|
+
next(): Promise<HivesLogStreamEvent | undefined>;
|
|
24
|
+
cancel(): Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
/** Yield SSE events until the caller stops iterating, the signal aborts or the server closes the stream. */
|
|
27
|
+
export declare function hivesSseEvents(response: Response): AsyncGenerator<HivesLogStreamEvent>;
|
|
28
|
+
/**
|
|
29
|
+
* Hives platform reads and actions the gateway already routes: project logs (query and live SSE), custom domains,
|
|
30
|
+
* the Hives identity, Hives fleets and remote sessions/SFTP.
|
|
31
|
+
*/
|
|
32
|
+
export declare function hivesPlatform(client: GenesisClient): {
|
|
33
|
+
logs: {
|
|
34
|
+
query: (project_id: string, q?: Omit<In<"hives_query_logs">, "project_id">) => Promise<{
|
|
35
|
+
logs: import("./index.js").components["schemas"]["Hives.LogEntry"][];
|
|
36
|
+
pagination: import("./index.js").components["schemas"]["Hives.PaginationMeta"];
|
|
37
|
+
time_range: import("./index.js").components["schemas"]["Hives.TimeRange"];
|
|
38
|
+
}>;
|
|
39
|
+
/** Live SSE events. Iterate and `break` (or abort the signal) to close the connection; it never ends on its own. */
|
|
40
|
+
stream: (project_id: string, q?: HivesLogStreamQuery, init?: {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}) => AsyncGenerator<HivesLogStreamEvent, void, any>;
|
|
43
|
+
/** A bounded window of the live stream: the first `maxEvents` events or `seconds` of stream, whichever comes first. */
|
|
44
|
+
window: (project_id: string, q?: HivesLogStreamQuery, options?: HivesLogWindowOptions) => Promise<HivesLogWindow>;
|
|
45
|
+
};
|
|
46
|
+
domains: {
|
|
47
|
+
list: (project_id: string, q?: Omit<In<"hives_list_domains">, "project_id">) => Promise<{
|
|
48
|
+
data: {
|
|
49
|
+
created_at: string;
|
|
50
|
+
dns_status: string;
|
|
51
|
+
domain: string;
|
|
52
|
+
domain_type: import("./index.js").components["schemas"]["Hives.DomainType"];
|
|
53
|
+
id: string;
|
|
54
|
+
ssl_expires_at?: string | null;
|
|
55
|
+
ssl_status: string;
|
|
56
|
+
verification_record?: null | import("./index.js").components["schemas"]["Hives.VerificationRecord"];
|
|
57
|
+
}[];
|
|
58
|
+
pagination: import("./index.js").components["schemas"]["Hives.PaginationMeta"];
|
|
59
|
+
}>;
|
|
60
|
+
add: (project_id: string, body: In<"hives_add_domain">["body"]) => Promise<{
|
|
61
|
+
created_at: string;
|
|
62
|
+
dns_status: string;
|
|
63
|
+
domain: string;
|
|
64
|
+
domain_type: import("./index.js").components["schemas"]["Hives.DomainType"];
|
|
65
|
+
id: string;
|
|
66
|
+
ssl_expires_at?: string | null;
|
|
67
|
+
ssl_status: string;
|
|
68
|
+
verification_record?: null | import("./index.js").components["schemas"]["Hives.VerificationRecord"];
|
|
69
|
+
}>;
|
|
70
|
+
verify: (project_id: string, domain_id: string) => Promise<{
|
|
71
|
+
checked_at: string;
|
|
72
|
+
dns_status: string;
|
|
73
|
+
error?: string | null;
|
|
74
|
+
verified: boolean;
|
|
75
|
+
}>;
|
|
76
|
+
provisionSsl: (project_id: string, domain_id: string) => Promise<{
|
|
77
|
+
error?: string | null;
|
|
78
|
+
expires_at?: string | null;
|
|
79
|
+
ssl_status: string;
|
|
80
|
+
started: boolean;
|
|
81
|
+
}>;
|
|
82
|
+
};
|
|
83
|
+
auth: {
|
|
84
|
+
me: () => Promise<{
|
|
85
|
+
avatar?: string | null;
|
|
86
|
+
createdAt: string;
|
|
87
|
+
email: string;
|
|
88
|
+
id: string;
|
|
89
|
+
name: string;
|
|
90
|
+
organizationId?: string | null;
|
|
91
|
+
role: string;
|
|
92
|
+
}>;
|
|
93
|
+
};
|
|
94
|
+
fleets: {
|
|
95
|
+
list: () => Promise<{
|
|
96
|
+
fleets: import("./index.js").components["schemas"]["Hives.FleetStatusView"][];
|
|
97
|
+
}>;
|
|
98
|
+
deploy: (body: In<"hives_deploy_fleet">["body"]) => Promise<{
|
|
99
|
+
fleetId: string;
|
|
100
|
+
gatewayEndpoint?: string | null;
|
|
101
|
+
totalInstances: number;
|
|
102
|
+
}>;
|
|
103
|
+
status: (fleet_id: string) => Promise<{
|
|
104
|
+
fleetId: string;
|
|
105
|
+
gateway?: null | import("./index.js").components["schemas"]["Hives.GatewaySummary"];
|
|
106
|
+
healthyInstances: number;
|
|
107
|
+
name: string;
|
|
108
|
+
protocols: import("./index.js").components["schemas"]["Hives.ProtocolStatusView"][];
|
|
109
|
+
state: string;
|
|
110
|
+
totalInstances: number;
|
|
111
|
+
}>;
|
|
112
|
+
teardown: (fleet_id: string) => Promise<void>;
|
|
113
|
+
};
|
|
114
|
+
remote: {
|
|
115
|
+
sessions: {
|
|
116
|
+
list: (project_id: string, q?: Omit<In<"hives_list_remote_sessions">, "project_id">) => Promise<Record<string, never>>;
|
|
117
|
+
close: (project_id: string, session_id: string) => Promise<Record<string, never>>;
|
|
118
|
+
};
|
|
119
|
+
ssh: (project_id: string, body: In<"hives_create_ssh_session">["body"]) => Promise<{
|
|
120
|
+
expires_at: string;
|
|
121
|
+
fingerprint: string;
|
|
122
|
+
host: string;
|
|
123
|
+
port: number;
|
|
124
|
+
session_id: string;
|
|
125
|
+
username: string;
|
|
126
|
+
}>;
|
|
127
|
+
terminal: (project_id: string, body: In<"hives_create_terminal_session">["body"]) => Promise<{
|
|
128
|
+
expires_at: string;
|
|
129
|
+
session_id: string;
|
|
130
|
+
token: string;
|
|
131
|
+
websocket_url: string;
|
|
132
|
+
}>;
|
|
133
|
+
debug: (project_id: string, body: In<"hives_create_debug_session">["body"]) => Promise<{
|
|
134
|
+
debug_url: string;
|
|
135
|
+
expires_at: string;
|
|
136
|
+
protocol: string;
|
|
137
|
+
session_id: string;
|
|
138
|
+
token: string;
|
|
139
|
+
}>;
|
|
140
|
+
sftp: {
|
|
141
|
+
list: (project_id: string, target_id: string, q?: {
|
|
142
|
+
path?: string;
|
|
143
|
+
}) => Promise<Record<string, never>>;
|
|
144
|
+
read: (project_id: string, target_id: string, path: string) => Promise<Record<string, never>>;
|
|
145
|
+
write: (project_id: string, target_id: string, body: In<"hives_sftp_write">["body"]) => Promise<Record<string, never>>;
|
|
146
|
+
delete: (project_id: string, target_id: string, body: In<"hives_sftp_delete">["body"]) => Promise<Record<string, never>>;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { GenesisError } from './errors.js';
|
|
2
|
+
const bounded = (value, fallback, max, name) => {
|
|
3
|
+
if (value === undefined)
|
|
4
|
+
return fallback;
|
|
5
|
+
if (!Number.isInteger(value) || value < 1 || value > max) {
|
|
6
|
+
throw new GenesisError({ status: 0, type: 'invalid_request', operationId: 'hives_stream_logs', message: `${name} must be an integer from 1 to ${max}.` });
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
function parseEvent(lines) {
|
|
11
|
+
let event = 'message';
|
|
12
|
+
let id;
|
|
13
|
+
const data = [];
|
|
14
|
+
for (const line of lines) {
|
|
15
|
+
if (!line || line.startsWith(':'))
|
|
16
|
+
continue; // SSE comments carry keepalives only.
|
|
17
|
+
const colon = line.indexOf(':');
|
|
18
|
+
const field = colon < 0 ? line : line.slice(0, colon);
|
|
19
|
+
let value = colon < 0 ? '' : line.slice(colon + 1);
|
|
20
|
+
if (value.startsWith(' '))
|
|
21
|
+
value = value.slice(1);
|
|
22
|
+
if (field === 'event')
|
|
23
|
+
event = value;
|
|
24
|
+
else if (field === 'id')
|
|
25
|
+
id = value;
|
|
26
|
+
else if (field === 'data')
|
|
27
|
+
data.push(value);
|
|
28
|
+
}
|
|
29
|
+
if (!data.length)
|
|
30
|
+
return undefined;
|
|
31
|
+
const text = data.join('\n');
|
|
32
|
+
let parsed = text;
|
|
33
|
+
try {
|
|
34
|
+
parsed = JSON.parse(text);
|
|
35
|
+
}
|
|
36
|
+
catch { /* non-JSON data such as heartbeat "ping" stays text */ }
|
|
37
|
+
return { event, ...(id === undefined ? {} : { id }), data: parsed };
|
|
38
|
+
}
|
|
39
|
+
/** Pull-based SSE reader. `cancel()` closes the connection even while a read is pending. */
|
|
40
|
+
export function hivesSseReader(response) {
|
|
41
|
+
const reader = response.body?.getReader();
|
|
42
|
+
const decoder = new TextDecoder();
|
|
43
|
+
let buffer = '';
|
|
44
|
+
let lines = [];
|
|
45
|
+
let finished = !reader;
|
|
46
|
+
const take = () => {
|
|
47
|
+
let index;
|
|
48
|
+
while ((index = buffer.search(/\r\n|\r|\n/)) >= 0) {
|
|
49
|
+
const line = buffer.slice(0, index);
|
|
50
|
+
buffer = buffer.slice(index + (buffer.startsWith('\r\n', index) ? 2 : 1));
|
|
51
|
+
if (line !== '') {
|
|
52
|
+
lines.push(line);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const event = parseEvent(lines);
|
|
56
|
+
lines = [];
|
|
57
|
+
if (event)
|
|
58
|
+
return event;
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
async next() {
|
|
64
|
+
for (;;) {
|
|
65
|
+
const ready = take();
|
|
66
|
+
if (ready)
|
|
67
|
+
return ready;
|
|
68
|
+
if (finished) {
|
|
69
|
+
const tail = parseEvent(buffer ? [...lines, buffer] : lines);
|
|
70
|
+
buffer = '';
|
|
71
|
+
lines = [];
|
|
72
|
+
return tail;
|
|
73
|
+
}
|
|
74
|
+
const { done, value } = await reader.read();
|
|
75
|
+
if (done)
|
|
76
|
+
finished = true;
|
|
77
|
+
else
|
|
78
|
+
buffer += decoder.decode(value, { stream: true });
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
async cancel() { finished = true; await reader?.cancel().catch(() => { }); },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** Yield SSE events until the caller stops iterating, the signal aborts or the server closes the stream. */
|
|
85
|
+
export async function* hivesSseEvents(response) {
|
|
86
|
+
const sse = hivesSseReader(response);
|
|
87
|
+
try {
|
|
88
|
+
for (let event = await sse.next(); event; event = await sse.next())
|
|
89
|
+
yield event;
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
await sse.cancel();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Hives platform reads and actions the gateway already routes: project logs (query and live SSE), custom domains,
|
|
97
|
+
* the Hives identity, Hives fleets and remote sessions/SFTP.
|
|
98
|
+
*/
|
|
99
|
+
export function hivesPlatform(client) {
|
|
100
|
+
const open = async (project_id, q = {}, init = {}) => {
|
|
101
|
+
const res = await client.raw('hives_stream_logs', { ...q, project_id }, { signal: init.signal, headers: { accept: 'text/event-stream' } });
|
|
102
|
+
if (!(res.headers.get('content-type') ?? '').toLowerCase().startsWith('text/event-stream')) {
|
|
103
|
+
void res.body?.cancel().catch(() => { });
|
|
104
|
+
throw new GenesisError({ status: res.status, type: 'invalid_response', operationId: 'hives_stream_logs', message: 'Hives did not return a Server-Sent Events stream.',
|
|
105
|
+
requestId: res.headers.get('x-request-id') ?? undefined });
|
|
106
|
+
}
|
|
107
|
+
return res;
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
logs: {
|
|
111
|
+
query: (project_id, q = {}) => client.request('hives_query_logs', { ...q, project_id }),
|
|
112
|
+
/** Live SSE events. Iterate and `break` (or abort the signal) to close the connection; it never ends on its own. */
|
|
113
|
+
stream: async function* (project_id, q = {}, init = {}) {
|
|
114
|
+
yield* hivesSseEvents(await open(project_id, q, init));
|
|
115
|
+
},
|
|
116
|
+
/** A bounded window of the live stream: the first `maxEvents` events or `seconds` of stream, whichever comes first. */
|
|
117
|
+
window: async (project_id, q = {}, options = {}) => {
|
|
118
|
+
const maxEvents = bounded(options.maxEvents, 100, 10_000, 'maxEvents');
|
|
119
|
+
const seconds = bounded(options.seconds, 10, 300, 'seconds');
|
|
120
|
+
const events = [];
|
|
121
|
+
// The window starts before the request, so a server that withholds headers cannot outlast it.
|
|
122
|
+
const deadline = new AbortController();
|
|
123
|
+
let timer;
|
|
124
|
+
const elapsed = new Promise((resolve) => { timer = setTimeout(() => { resolve('time'); deadline.abort(); }, seconds * 1000); });
|
|
125
|
+
const signal = options.signal ? AbortSignal.any([options.signal, deadline.signal]) : deadline.signal;
|
|
126
|
+
let sse;
|
|
127
|
+
try {
|
|
128
|
+
const response = await Promise.race([open(project_id, q, { signal }), elapsed]);
|
|
129
|
+
if (response === 'time')
|
|
130
|
+
return { events, ended: 'time' };
|
|
131
|
+
sse = hivesSseReader(response);
|
|
132
|
+
for (;;) {
|
|
133
|
+
const next = await Promise.race([sse.next(), elapsed]);
|
|
134
|
+
if (next === 'time')
|
|
135
|
+
return { events, ended: 'time' };
|
|
136
|
+
if (!next)
|
|
137
|
+
return { events, ended: 'closed' };
|
|
138
|
+
events.push(next);
|
|
139
|
+
if (events.length >= maxEvents)
|
|
140
|
+
return { events, ended: 'max_events' };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (deadline.signal.aborted && !options.signal?.aborted)
|
|
145
|
+
return { events, ended: 'time' };
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
await sse?.cancel();
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
domains: {
|
|
155
|
+
list: (project_id, q = {}) => client.request('hives_list_domains', { ...q, project_id }),
|
|
156
|
+
add: (project_id, body) => client.request('hives_add_domain', { project_id, body }),
|
|
157
|
+
verify: (project_id, domain_id) => client.request('hives_verify_domain', { project_id, domain_id }),
|
|
158
|
+
provisionSsl: (project_id, domain_id) => client.request('hives_provision_ssl', { project_id, domain_id }),
|
|
159
|
+
},
|
|
160
|
+
auth: { me: () => client.request('hives_me') },
|
|
161
|
+
fleets: {
|
|
162
|
+
list: () => client.request('hives_list_fleets'),
|
|
163
|
+
deploy: (body) => client.request('hives_deploy_fleet', { body }),
|
|
164
|
+
status: (fleet_id) => client.request('hives_get_fleet_status', { fleet_id }),
|
|
165
|
+
teardown: (fleet_id) => client.request('hives_teardown_fleet', { fleet_id }),
|
|
166
|
+
},
|
|
167
|
+
remote: {
|
|
168
|
+
sessions: {
|
|
169
|
+
list: (project_id, q = {}) => client.request('hives_list_remote_sessions', { ...q, project_id }),
|
|
170
|
+
close: (project_id, session_id) => client.request('hives_close_remote_session', { project_id, session_id }),
|
|
171
|
+
},
|
|
172
|
+
ssh: (project_id, body) => client.request('hives_create_ssh_session', { project_id, body }),
|
|
173
|
+
terminal: (project_id, body) => client.request('hives_create_terminal_session', { project_id, body }),
|
|
174
|
+
debug: (project_id, body) => client.request('hives_create_debug_session', { project_id, body }),
|
|
175
|
+
sftp: {
|
|
176
|
+
list: (project_id, target_id, q = {}) => client.request('hives_sftp_list', { ...q, project_id, target_id }),
|
|
177
|
+
read: (project_id, target_id, path) => client.request('hives_sftp_read', { project_id, target_id, path }),
|
|
178
|
+
write: (project_id, target_id, body) => client.request('hives_sftp_write', { project_id, target_id, body }),
|
|
179
|
+
delete: (project_id, target_id, body) => client.request('hives_sftp_delete', { project_id, target_id, body }),
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -6,12 +6,18 @@ export declare const HIVES_RESOURCE_JSON_BYTES: number;
|
|
|
6
6
|
export interface HivesResourceOptions {
|
|
7
7
|
signal?: AbortSignal;
|
|
8
8
|
}
|
|
9
|
+
/** Funded Hives writes (topic publish, Cells object writes): Hives refuses them without one Idempotency-Key. */
|
|
10
|
+
export interface HivesFundedWriteOptions extends HivesResourceOptions {
|
|
11
|
+
idempotencyKey?: string;
|
|
12
|
+
}
|
|
13
|
+
/** The caller's key, or a fresh one when none is given. Reuse a key only to replay the same write, never to act twice. */
|
|
14
|
+
export declare function hivesFundedWriteHeaders(options?: HivesFundedWriteOptions, id?: string): Record<string, string>;
|
|
9
15
|
export declare function hivesResourceId(value: string): string;
|
|
10
16
|
export declare function resourceError(status: number, id?: string): GenesisError;
|
|
11
17
|
/** A non-2xx Hives resource reply as a GenesisError with the gateway's code, request id and required scope (bounded read, body discarded). */
|
|
12
18
|
export declare function resourceErrorFromResponse(response: Response, id?: string): Promise<GenesisError>;
|
|
13
19
|
export declare const isHivesResourceOperation: (id: string) => boolean;
|
|
14
|
-
export declare const isHivesObjectUpload: (id: string) => id is "hives_upload_object_by_key" | "hives_upload_object";
|
|
20
|
+
export declare const isHivesObjectUpload: (id: string) => id is "hives_upload_object_by_key" | "hives_upload_object_named_download" | "hives_upload_object";
|
|
15
21
|
/** Shared-client hook proposal: snapshot only the two real raw Cells upload operations. */
|
|
16
22
|
export declare function hivesObjectBody(value: unknown): Promise<ArrayBuffer>;
|
|
17
23
|
export declare function hivesContentType(value?: string): string;
|
|
@@ -2,6 +2,14 @@ import { GenesisError } from './errors.js';
|
|
|
2
2
|
export const HIVES_OBJECT_BYTES = 10 * 1024 * 1024;
|
|
3
3
|
export const HIVES_QUEUE_BYTES = 256 * 1024;
|
|
4
4
|
export const HIVES_RESOURCE_JSON_BYTES = 2 * 1024 * 1024;
|
|
5
|
+
/** The caller's key, or a fresh one when none is given. Reuse a key only to replay the same write, never to act twice. */
|
|
6
|
+
export function hivesFundedWriteHeaders(options = {}, id) {
|
|
7
|
+
const key = options.idempotencyKey ?? globalThis.crypto.randomUUID();
|
|
8
|
+
// Hives' bound (operation_funding.rs key()): one value of 1-128 printable ASCII bytes.
|
|
9
|
+
if (typeof key !== 'string' || !/^[ -~]{1,128}$/.test(key))
|
|
10
|
+
throw resourceError(0, id);
|
|
11
|
+
return { 'idempotency-key': key };
|
|
12
|
+
}
|
|
5
13
|
export function hivesResourceId(value) {
|
|
6
14
|
if (typeof value !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(value))
|
|
7
15
|
throw resourceError(0);
|
|
@@ -50,8 +58,8 @@ export async function resourceErrorFromResponse(response, id) {
|
|
|
50
58
|
code: fields.code, requestId: fields.requestId,
|
|
51
59
|
body: fields.code || fields.requiredScope ? { error: { code: fields.code, request_id: fields.requestId, required_scope: fields.requiredScope } } : undefined });
|
|
52
60
|
}
|
|
53
|
-
export const isHivesResourceOperation = (id) => /^(?:hives_marketplace_(?:categories|featured|installed|get_installation|uninstall|reconcile|list_packages|publish|get_package|install|update|list_versions)|hives_(?:get|configure|remove)_native_queue_consumer|hives_.*_native_queue|hives_.*_native_topic|hives_(?:(?:list_volumes|create_volume|get_volume|delete_volume|mount_volume|unmount_volume)|list_buckets|create_bucket|get_bucket|delete_bucket|list_objects|upload_object(?:_by_key)?|delete_object(?:_by_key)?|download_object_by_key|get_cors_config|set_cors_config|generate_presigned_url|reconcile|list_runtimes|get_runtime|select_runtime|list_project_runtimes))$/.test(id);
|
|
54
|
-
export const isHivesObjectUpload = (id) => id === 'hives_upload_object_by_key' || id === 'hives_upload_object';
|
|
61
|
+
export const isHivesResourceOperation = (id) => /^(?:hives_marketplace_(?:categories|featured|installed|get_installation|uninstall|reconcile|list_packages|publish|get_package|install|update|list_versions)|hives_(?:get|configure|remove)_native_queue_consumer|hives_.*_native_queue|hives_.*_native_topic|hives_(?:(?:list_volumes|create_volume|get_volume|delete_volume|mount_volume|unmount_volume)|list_buckets|create_bucket|get_bucket|delete_bucket|list_objects|upload_object(?:_by_key|_named_download)?|delete_object(?:_by_key|_named_download)?|download_object_by_key|get_cors_config|set_cors_config|generate_presigned_url|reconcile|list_runtimes|get_runtime|select_runtime|list_project_runtimes))$/.test(id);
|
|
62
|
+
export const isHivesObjectUpload = (id) => id === 'hives_upload_object_by_key' || id === 'hives_upload_object' || id === 'hives_upload_object_named_download';
|
|
55
63
|
/** Shared-client hook proposal: snapshot only the two real raw Cells upload operations. */
|
|
56
64
|
export async function hivesObjectBody(value) {
|
|
57
65
|
let bytes;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** One Server-Sent Event. `data` is parsed JSON when it is JSON, otherwise the raw text. */
|
|
2
|
+
export interface HivesSseEvent {
|
|
3
|
+
event: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
data: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface HivesSseWindowOptions {
|
|
8
|
+
/** Stop after this many events (1-1000, default 100). */
|
|
9
|
+
maxEvents?: number;
|
|
10
|
+
/** Stop after this many seconds (1-15, default 10). The CLI and MCP Hives node transport allows a body 20 s, so a window stays below it. */
|
|
11
|
+
seconds?: number;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
/** A bounded read of an endless stream; `ended` says which bound closed it. */
|
|
15
|
+
export interface HivesSseWindow {
|
|
16
|
+
events: HivesSseEvent[];
|
|
17
|
+
ended: 'max_events' | 'time' | 'closed' | 'aborted';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read one bounded window of a Server-Sent Events response (for example
|
|
21
|
+
* `await genesis.raw('hives_stream_deployment_logs', {...})`) and close the connection.
|
|
22
|
+
* Never buffers the whole body: an SSE stream does not end on its own.
|
|
23
|
+
*/
|
|
24
|
+
export declare function hivesSseWindow(response: Response, options?: HivesSseWindowOptions): Promise<HivesSseWindow>;
|