@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 CHANGED
@@ -3,7 +3,7 @@
3
3
  The TypeScript SDK for OneOS. One typed client for every Genesis service, through the Genesis API at `https://os.one.ml/api`.
4
4
 
5
5
  ```sh
6
- npm install @onesi/genesis@0.2.4
6
+ npm install @onesi/genesis@0.2.5
7
7
  ```
8
8
 
9
9
  ```ts
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.4',
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
- set: (api_key: string) => Promise<{
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
- set: async (api_key) => {
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
- return client.request('fleets_setConnection', { body: { api_key } });
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
  },