@onesi/genesis 0.2.4 → 0.2.5
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/client.d.ts +10 -0
- package/dist/client.js +20 -1
- package/dist/fleets.d.ts +4 -1
- package/dist/fleets.js +10 -2
- package/dist/generated/operations.js +177 -150
- package/dist/generated/schema.d.ts +153 -131
- package/dist/genesis.d.ts +15 -5
- package/dist/genesis.js +2 -0
- package/dist/genesis.openapi.json +182 -154
- package/dist/hives-project.d.ts +18 -0
- package/dist/hives-project.js +51 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/urls.js +36 -14
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -41,6 +41,16 @@ export declare class GenesisClient {
|
|
|
41
41
|
constructor(opts?: GenesisOptions);
|
|
42
42
|
static operations: Readonly<Record<OperationId, OperationMeta>>;
|
|
43
43
|
static services: import("./types.js").ServiceMeta[];
|
|
44
|
+
/** This client's one read of the selected context's Hives binding (cleared on failure). */
|
|
45
|
+
private hivesBinding?;
|
|
46
|
+
/**
|
|
47
|
+
* The Hives project id (prj_…) for a Hives project argument. A prj_… id is returned unchanged. Omitted, or the
|
|
48
|
+
* Genesis pr_… id of the selected context's project, it resolves to the Hives project bound to that selection
|
|
49
|
+
* (`hives_get_context_project`, read at most once per client); otherwise a GenesisError says how to find the prj_… id.
|
|
50
|
+
*/
|
|
51
|
+
hivesProjectId(project_id?: string, init?: {
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}): Promise<string>;
|
|
44
54
|
/** Resolve the credential: explicit apiKey > token > env GENESIS_API_KEY > GENESIS_TOKEN > provider. */
|
|
45
55
|
credential(): Promise<string | undefined>;
|
|
46
56
|
/** Build the URL for an operation (exposed for tests and `--dry-run`). */
|
package/dist/client.js
CHANGED
|
@@ -12,6 +12,7 @@ import { requireSecureUrl, redactUserinfo, stripUserinfo } from './urls.js';
|
|
|
12
12
|
import { iamDirectoryFailure, isIamDirectoryOperation } from './iam-directory.js';
|
|
13
13
|
import { validateHivesInvocation, hivesFunctionResponseHeaders, hivesFunctionMetadata, hivesOperationError } from './hives-functions.js';
|
|
14
14
|
import { validateHivesEnvironment, validateHivesEnvironmentNames, hivesEnvironmentSetNames, hivesEnvironmentMetadata, hivesEnvironmentReveal } from './hives-environment.js';
|
|
15
|
+
import { hivesProjectIdRefusal, isGenesisProjectId, isHivesProjectOperation, resolveHivesProjectId } from './hives-project.js';
|
|
15
16
|
import { RUNNER_SELF_GRANT_OPERATION, snapshotRunnerSelfGrant, runnerGrantResponse, runnerGrantTransportError } from './runner-grant.js';
|
|
16
17
|
/** The Genesis API gateway. `https://console.life.one/api` remains an alias for the same gateway. */
|
|
17
18
|
export const DEFAULT_BASE_URL = 'https://os.one.ml/api';
|
|
@@ -75,6 +76,21 @@ export class GenesisClient {
|
|
|
75
76
|
}
|
|
76
77
|
static operations = operationTable;
|
|
77
78
|
static services = services;
|
|
79
|
+
/** This client's one read of the selected context's Hives binding (cleared on failure). */
|
|
80
|
+
hivesBinding;
|
|
81
|
+
/**
|
|
82
|
+
* The Hives project id (prj_…) for a Hives project argument. A prj_… id is returned unchanged. Omitted, or the
|
|
83
|
+
* Genesis pr_… id of the selected context's project, it resolves to the Hives project bound to that selection
|
|
84
|
+
* (`hives_get_context_project`, read at most once per client); otherwise a GenesisError says how to find the prj_… id.
|
|
85
|
+
*/
|
|
86
|
+
async hivesProjectId(project_id, init = {}) {
|
|
87
|
+
return resolveHivesProjectId(project_id, () => {
|
|
88
|
+
const read = this.hivesBinding ??= this.request('hives_get_context_project', {}, { signal: init.signal });
|
|
89
|
+
read.catch(() => { if (this.hivesBinding === read)
|
|
90
|
+
this.hivesBinding = undefined; });
|
|
91
|
+
return read;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
78
94
|
/** Resolve the credential: explicit apiKey > token > env GENESIS_API_KEY > GENESIS_TOKEN > provider. */
|
|
79
95
|
async credential() {
|
|
80
96
|
return this.opts.apiKey ?? this.opts.token ?? env.GENESIS_API_KEY ?? env.GENESIS_TOKEN ?? (await this.opts.credentials?.());
|
|
@@ -184,6 +200,9 @@ export class GenesisClient {
|
|
|
184
200
|
}
|
|
185
201
|
/** Raw Response. Completed Hives guest responses retain their actual status, including non-2xx. */
|
|
186
202
|
async raw(operationId, input = {}, init = {}) {
|
|
203
|
+
// A Genesis pr_… id where Hives wants its own prj_… id would only be a remote 404: refuse it before any request.
|
|
204
|
+
if (isGenesisProjectId(input.project_id) && isHivesProjectOperation(operationTable[operationId]))
|
|
205
|
+
throw hivesProjectIdRefusal(input.project_id, operationId);
|
|
187
206
|
if (!isIamDirectoryOperation(operationId))
|
|
188
207
|
return this.dispatch(operationId, input, init);
|
|
189
208
|
// The gateway binds the organization context itself. A refusal is only explained here; the client never changes a session or its context.
|
|
@@ -226,7 +245,7 @@ export class GenesisClient {
|
|
|
226
245
|
const url = this.url(operationId, input);
|
|
227
246
|
const headers = {
|
|
228
247
|
accept: 'application/json',
|
|
229
|
-
'user-agent': this.opts.userAgent ?? '@onesi/genesis/0.2.
|
|
248
|
+
'user-agent': this.opts.userAgent ?? '@onesi/genesis/0.2.5',
|
|
230
249
|
...this.opts.headers, ...init.headers,
|
|
231
250
|
};
|
|
232
251
|
if (op.service === 'blinds' && !['GET', 'HEAD', 'OPTIONS'].includes(op.method))
|
package/dist/fleets.d.ts
CHANGED
|
@@ -141,7 +141,10 @@ export declare function fleetsModule(client: GenesisClient): {
|
|
|
141
141
|
model: string;
|
|
142
142
|
updated_at?: number;
|
|
143
143
|
}>;
|
|
144
|
-
|
|
144
|
+
/** `model` (optional) must be a model Foundry lists for the key; omit it for the Fleets default. */
|
|
145
|
+
set: (api_key: string, options?: {
|
|
146
|
+
model?: string;
|
|
147
|
+
}) => Promise<{
|
|
145
148
|
connected: boolean;
|
|
146
149
|
model: string;
|
|
147
150
|
updated_at?: number;
|
package/dist/fleets.js
CHANGED
|
@@ -26,6 +26,11 @@ function validateKey(apiKey) {
|
|
|
26
26
|
throw invalid('fleets_setConnection', 'Foundry key must contain 1–4096 UTF-8 bytes without CR, LF or NUL.');
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
function validateModel(model) {
|
|
30
|
+
if (typeof model !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/.test(model)) {
|
|
31
|
+
throw invalid('fleets_setConnection', 'Model must be a Foundry model id of 1–128 characters (letters, digits, . _ : / -).');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
29
34
|
const instanceId = (value, operation) => {
|
|
30
35
|
if (typeof value !== 'string' || !/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)) {
|
|
31
36
|
throw invalid(operation, 'Invalid Fleets instance ID.');
|
|
@@ -160,9 +165,12 @@ export function fleetsModule(client) {
|
|
|
160
165
|
},
|
|
161
166
|
connection: {
|
|
162
167
|
get: () => client.request('fleets_getConnection', {}),
|
|
163
|
-
|
|
168
|
+
/** `model` (optional) must be a model Foundry lists for the key; omit it for the Fleets default. */
|
|
169
|
+
set: async (api_key, options = {}) => {
|
|
164
170
|
validateKey(api_key);
|
|
165
|
-
|
|
171
|
+
if (options.model !== undefined)
|
|
172
|
+
validateModel(options.model);
|
|
173
|
+
return client.request('fleets_setConnection', { body: { api_key, ...(options.model !== undefined ? { model: options.model } : {}) } });
|
|
166
174
|
},
|
|
167
175
|
delete: () => client.request('fleets_deleteConnection', {}),
|
|
168
176
|
},
|