@demicodes/provider 0.3.1 → 0.4.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.
@@ -1,4 +1,4 @@
1
- import { d as ProviderCredentialInfo } from "./types-C9tIelAP.mjs";
1
+ import { d as ProviderCredentialInfo } from "./types-DO0VKCUa.mjs";
2
2
  //#region src/credentials-pool.d.ts
3
3
  interface CredentialEntryMeta {
4
4
  id: string;
@@ -56,11 +56,5 @@ declare class CredentialPoolError extends Error {
56
56
  readonly code: 'credential_not_found' | 'credential_invalid';
57
57
  constructor(code: 'credential_not_found' | 'credential_invalid', message: string);
58
58
  }
59
- declare function runVendorLoginCommand(command: string, args: string[], options?: {
60
- signal?: AbortSignal;
61
- }): Promise<{
62
- status: 'completed' | 'cancelled' | 'failed' | 'unavailable';
63
- message?: string;
64
- }>;
65
59
  //#endregion
66
- export { CredentialEntryMeta, CredentialPoolError, FileCredentialPool, FileCredentialPoolOptions, credentialIdFromIdentity, newCredentialId, resolveDemiHome, runVendorLoginCommand };
60
+ export { CredentialEntryMeta, CredentialPoolError, FileCredentialPool, FileCredentialPoolOptions, credentialIdFromIdentity, newCredentialId, resolveDemiHome };
@@ -201,62 +201,5 @@ var CredentialPoolError = class extends Error {
201
201
  this.name = "CredentialPoolError";
202
202
  }
203
203
  };
204
- async function runVendorLoginCommand(command, args, options = {}) {
205
- const { spawn } = await import("node:child_process");
206
- return new Promise((resolvePromise) => {
207
- let child;
208
- try {
209
- child = spawn(command, args, {
210
- stdio: "inherit",
211
- env: process.env,
212
- shell: false
213
- });
214
- } catch (error) {
215
- resolvePromise({
216
- status: "unavailable",
217
- message: error instanceof Error ? error.message : String(error)
218
- });
219
- return;
220
- }
221
- const onAbort = () => {
222
- child.kill("SIGTERM");
223
- };
224
- if (options.signal) {
225
- if (options.signal.aborted) {
226
- child.kill("SIGTERM");
227
- resolvePromise({ status: "cancelled" });
228
- return;
229
- }
230
- options.signal.addEventListener("abort", onAbort, { once: true });
231
- }
232
- child.on("error", (error) => {
233
- options.signal?.removeEventListener("abort", onAbort);
234
- const msg = error instanceof Error ? error.message : String(error);
235
- if (errorCode(error) === "ENOENT") {
236
- resolvePromise({
237
- status: "unavailable",
238
- message: `Command not found: ${command}`
239
- });
240
- return;
241
- }
242
- resolvePromise({
243
- status: "failed",
244
- message: msg
245
- });
246
- });
247
- child.on("exit", (code, signal) => {
248
- options.signal?.removeEventListener("abort", onAbort);
249
- if (options.signal?.aborted || signal === "SIGTERM" || signal === "SIGINT") {
250
- resolvePromise({ status: "cancelled" });
251
- return;
252
- }
253
- if (code === 0) resolvePromise({ status: "completed" });
254
- else resolvePromise({
255
- status: "failed",
256
- message: `${command} exited with code ${code ?? "null"}`
257
- });
258
- });
259
- });
260
- }
261
204
  //#endregion
262
- export { CredentialPoolError, FileCredentialPool, credentialIdFromIdentity, newCredentialId, resolveDemiHome, runVendorLoginCommand };
205
+ export { CredentialPoolError, FileCredentialPool, credentialIdFromIdentity, newCredentialId, resolveDemiHome };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ProviderQuotaCapability, B as ProviderQuotaWindow, C as ProviderRuntimeState, D as CreateProviderQuotaOptions, E as ToolDefinition, F as ProviderQuotaProbeResult, G as severityFromUsedPercent, H as clampUsedPercent, I as ProviderQuotaSeverity, K as unixSecondsToIso, L as ProviderQuotaSnapshot, M as ProviderQuotaPlan, N as ProviderQuotaProbeCost, O as EnsureQuotaOptions, P as ProviderQuotaProbeOptions, R as ProviderQuotaSource, S as ProviderRuntimeFactory, T as ProviderServiceTier, U as createProviderQuota, V as ProviderQuotaWindowUnit, W as ensureQuota, _ as ProviderFactoryDefinition, a as ModelPolicy, b as ProviderModelList, c as ProviderAuthState, d as ProviderCredentialInfo, f as ProviderCredentialLoginOptions, g as ProviderEvent, h as ProviderCredentialsCapability, i as InferenceSteer, j as ProviderQuotaObserveInput, k as ProviderQuota, l as ProviderCredentialActive, m as ProviderCredentials, n as InferenceItem, o as Provider, p as ProviderCredentialLoginResult, q as usedPercentFromRatio, r as InferenceRequest, s as ProviderAuth, t as AgentProvider, u as ProviderCredentialAddInput, v as ProviderModel, w as ProviderSelection, x as ProviderRun, y as ProviderModelCost, z as ProviderQuotaUnsupportedError } from "./types-C9tIelAP.mjs";
1
+ import { A as ProviderQuota, B as ProviderQuotaUnsupportedError, C as ProviderRuntimeFactory, D as ToolDefinition, E as ProviderServiceTier, F as ProviderQuotaProbeOptions, G as ensureQuota, H as ProviderQuotaWindowUnit, I as ProviderQuotaProbeResult, J as usedPercentFromRatio, K as severityFromUsedPercent, L as ProviderQuotaSeverity, M as ProviderQuotaObserveInput, N as ProviderQuotaPlan, O as CreateProviderQuotaOptions, P as ProviderQuotaProbeCost, R as ProviderQuotaSnapshot, S as ProviderRun, T as ProviderSelection, U as clampUsedPercent, V as ProviderQuotaWindow, W as createProviderQuota, _ as ProviderEvent, a as ModelPolicy, b as ProviderModelCost, c as ProviderAuthState, d as ProviderCredentialInfo, f as ProviderCredentialLoginOptions, g as ProviderCredentialsCapability, h as ProviderCredentials, i as InferenceSteer, j as ProviderQuotaCapability, k as EnsureQuotaOptions, l as ProviderCredentialActive, m as ProviderCredentialLoginResult, n as InferenceItem, o as Provider, p as ProviderCredentialLoginPending, q as unixSecondsToIso, r as InferenceRequest, s as ProviderAuth, t as AgentProvider, u as ProviderCredentialAddInput, v as ProviderFactoryDefinition, w as ProviderRuntimeState, x as ProviderModelList, y as ProviderModel, z as ProviderQuotaSource } from "./types-DO0VKCUa.mjs";
2
2
  import { FileExtension, ModelSelection, ThinkingCapability, ThinkingConfig, ToolResultContentBlock } from "@demicodes/core";
3
3
  //#region src/content.d.ts
4
4
  /**
@@ -64,4 +64,4 @@ declare function numberHeader(headers: Headers, name: string): number | null;
64
64
  /** Builds a redacted provider `error` event from a failed HTTP response. */
65
65
  declare function httpRequestFailedEvent(response: Response, secret: string | null | undefined, providerLabel: string): Promise<ProviderEvent>;
66
66
  //#endregion
67
- export { AgentProvider, type CreateProviderQuotaOptions, DEFAULT_ATTACHMENT_EXTENSIONS, type EnsureQuotaOptions, InferenceItem, InferenceRequest, InferenceSteer, ModelPolicy, type ModelSelectionFromCatalogOptions, Provider, ProviderAuth, ProviderAuthState, ProviderCredentialActive, ProviderCredentialAddInput, ProviderCredentialInfo, ProviderCredentialLoginOptions, ProviderCredentialLoginResult, ProviderCredentials, ProviderCredentialsCapability, ProviderEvent, ProviderFactoryDefinition, ProviderModel, ProviderModelCost, ProviderModelList, type ProviderQuota, type ProviderQuotaCapability, type ProviderQuotaObserveInput, type ProviderQuotaPlan, type ProviderQuotaProbeCost, type ProviderQuotaProbeOptions, type ProviderQuotaProbeResult, type ProviderQuotaSeverity, type ProviderQuotaSnapshot, type ProviderQuotaSource, ProviderQuotaUnsupportedError, type ProviderQuotaWindow, type ProviderQuotaWindowUnit, ProviderRun, ProviderRuntimeFactory, ProviderRuntimeState, ProviderSelection, ProviderServiceTier, ToolDefinition, applyModelPolicy, authStatusFromKey, clampPromptCacheKey, clampUsedPercent, createProviderQuota, defineProvider, ensureQuota, httpErrorCode, httpRequestFailedEvent, modelSelectionFromCatalog, normalizeErrorCode, numberHeader, providerErrorFromUnknown, providerRuntime, redactCredentialText, redactSecretText, retryAfterMsFromHeader, severityFromUsedPercent, thinkingCapabilitiesFromProviderModel, toolResultContentToText, unixSecondsToIso, usedPercentFromRatio, withProviderId };
67
+ export { AgentProvider, type CreateProviderQuotaOptions, DEFAULT_ATTACHMENT_EXTENSIONS, type EnsureQuotaOptions, InferenceItem, InferenceRequest, InferenceSteer, ModelPolicy, type ModelSelectionFromCatalogOptions, Provider, ProviderAuth, ProviderAuthState, ProviderCredentialActive, ProviderCredentialAddInput, ProviderCredentialInfo, ProviderCredentialLoginOptions, ProviderCredentialLoginPending, ProviderCredentialLoginResult, ProviderCredentials, ProviderCredentialsCapability, ProviderEvent, ProviderFactoryDefinition, ProviderModel, ProviderModelCost, ProviderModelList, type ProviderQuota, type ProviderQuotaCapability, type ProviderQuotaObserveInput, type ProviderQuotaPlan, type ProviderQuotaProbeCost, type ProviderQuotaProbeOptions, type ProviderQuotaProbeResult, type ProviderQuotaSeverity, type ProviderQuotaSnapshot, type ProviderQuotaSource, ProviderQuotaUnsupportedError, type ProviderQuotaWindow, type ProviderQuotaWindowUnit, ProviderRun, ProviderRuntimeFactory, ProviderRuntimeState, ProviderSelection, ProviderServiceTier, ToolDefinition, applyModelPolicy, authStatusFromKey, clampPromptCacheKey, clampUsedPercent, createProviderQuota, defineProvider, ensureQuota, httpErrorCode, httpRequestFailedEvent, modelSelectionFromCatalog, normalizeErrorCode, numberHeader, providerErrorFromUnknown, providerRuntime, redactCredentialText, redactSecretText, retryAfterMsFromHeader, severityFromUsedPercent, thinkingCapabilitiesFromProviderModel, toolResultContentToText, unixSecondsToIso, usedPercentFromRatio, withProviderId };
@@ -1,4 +1,4 @@
1
- import { g as ProviderEvent, i as InferenceSteer, r as InferenceRequest, t as AgentProvider, x as ProviderRun } from "./types-C9tIelAP.mjs";
1
+ import { S as ProviderRun, _ as ProviderEvent, i as InferenceSteer, r as InferenceRequest, t as AgentProvider } from "./types-DO0VKCUa.mjs";
2
2
  //#region src/testing.d.ts
3
3
  /**
4
4
  * Scripted provider for testing. Each "turn" is a list of events to yield.
@@ -280,18 +280,42 @@ interface ProviderCredentialActive {
280
280
  /** Same shape as auth status, for the active credential. */
281
281
  status: ProviderAuthState;
282
282
  }
283
+ /**
284
+ * User-facing material issued mid-flow by a device-code login: the product
285
+ * relays it to the user, who completes login from any browser on any device.
286
+ */
287
+ interface ProviderCredentialLoginPending {
288
+ /** URL the user opens to confirm the login. */
289
+ verificationUrl: string;
290
+ /** One-time code the user enters at the verification URL (device-code flows). */
291
+ userCode?: string | null;
292
+ /** ISO-8601 expiry of the code, when the vendor exposes one. */
293
+ expiresAt?: string | null;
294
+ /**
295
+ * True when the vendor displays a code AFTER approval that the user must
296
+ * bring back; the product collects it via `promptForCode`.
297
+ */
298
+ requiresCodeInput?: boolean;
299
+ }
283
300
  interface ProviderCredentialLoginOptions {
284
- /** Abort the spawned login process. */
301
+ /** Abort the login flow. */
285
302
  signal?: AbortSignal;
303
+ /** Fires once when the flow issues user-facing material (device-code login). */
304
+ onPending?: (pending: ProviderCredentialLoginPending) => void;
305
+ /** Collects the code the user copied back from the vendor page (`requiresCodeInput` flows). */
306
+ promptForCode?: () => Promise<string>;
286
307
  /** Prefer browser vs device/CLI when the vendor supports both; best-effort. */
287
308
  preferBrowser?: boolean;
288
309
  }
289
310
  /**
290
- * Login invoke result status of the *vendor* process only, not a pool id.
291
- * Demi does not complete OAuth; product should `importDefault` afterwards.
311
+ * Login invoke result. Providers with a public device-code protocol (codex)
312
+ * complete the flow natively, import the material into the pool, and return
313
+ * the pool `credentialId`. CLI-spawning providers report vendor process status
314
+ * only; the product should `importDefault` afterwards.
292
315
  */
293
316
  type ProviderCredentialLoginResult = {
294
317
  status: 'completed';
318
+ credentialId?: string;
295
319
  } | {
296
320
  status: 'cancelled';
297
321
  } | {
@@ -430,4 +454,4 @@ type ModelPolicy = {
430
454
  default?: string;
431
455
  };
432
456
  //#endregion
433
- export { ProviderQuotaCapability as A, ProviderQuotaWindow as B, ProviderRuntimeState as C, CreateProviderQuotaOptions as D, ToolDefinition as E, ProviderQuotaProbeResult as F, severityFromUsedPercent as G, clampUsedPercent as H, ProviderQuotaSeverity as I, unixSecondsToIso as K, ProviderQuotaSnapshot as L, ProviderQuotaPlan as M, ProviderQuotaProbeCost as N, EnsureQuotaOptions as O, ProviderQuotaProbeOptions as P, ProviderQuotaSource as R, ProviderRuntimeFactory as S, ProviderServiceTier as T, createProviderQuota as U, ProviderQuotaWindowUnit as V, ensureQuota as W, ProviderFactoryDefinition as _, ModelPolicy as a, ProviderModelList as b, ProviderAuthState as c, ProviderCredentialInfo as d, ProviderCredentialLoginOptions as f, ProviderEvent as g, ProviderCredentialsCapability as h, InferenceSteer as i, ProviderQuotaObserveInput as j, ProviderQuota as k, ProviderCredentialActive as l, ProviderCredentials as m, InferenceItem as n, Provider as o, ProviderCredentialLoginResult as p, usedPercentFromRatio as q, InferenceRequest as r, ProviderAuth as s, AgentProvider as t, ProviderCredentialAddInput as u, ProviderModel as v, ProviderSelection as w, ProviderRun as x, ProviderModelCost as y, ProviderQuotaUnsupportedError as z };
457
+ export { ProviderQuota as A, ProviderQuotaUnsupportedError as B, ProviderRuntimeFactory as C, ToolDefinition as D, ProviderServiceTier as E, ProviderQuotaProbeOptions as F, ensureQuota as G, ProviderQuotaWindowUnit as H, ProviderQuotaProbeResult as I, usedPercentFromRatio as J, severityFromUsedPercent as K, ProviderQuotaSeverity as L, ProviderQuotaObserveInput as M, ProviderQuotaPlan as N, CreateProviderQuotaOptions as O, ProviderQuotaProbeCost as P, ProviderQuotaSnapshot as R, ProviderRun as S, ProviderSelection as T, clampUsedPercent as U, ProviderQuotaWindow as V, createProviderQuota as W, ProviderEvent as _, ModelPolicy as a, ProviderModelCost as b, ProviderAuthState as c, ProviderCredentialInfo as d, ProviderCredentialLoginOptions as f, ProviderCredentialsCapability as g, ProviderCredentials as h, InferenceSteer as i, ProviderQuotaCapability as j, EnsureQuotaOptions as k, ProviderCredentialActive as l, ProviderCredentialLoginResult as m, InferenceItem as n, Provider as o, ProviderCredentialLoginPending as p, unixSecondsToIso as q, InferenceRequest as r, ProviderAuth as s, AgentProvider as t, ProviderCredentialAddInput as u, ProviderFactoryDefinition as v, ProviderRuntimeState as w, ProviderModelList as x, ProviderModel as y, ProviderQuotaSource as z };
package/package.json CHANGED
@@ -1,29 +1,26 @@
1
1
  {
2
2
  "name": "@demicodes/provider",
3
3
  "description": "Provider contract and shared building blocks for Demi inference adapters.",
4
- "version": "0.3.1",
4
+ "version": "0.4.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
- "development": "./src/index.ts",
10
9
  "types": "./dist/index.d.mts",
11
10
  "import": "./dist/index.mjs"
12
11
  },
13
12
  "./testing": {
14
- "development": "./src/testing.ts",
15
13
  "types": "./dist/testing.d.mts",
16
14
  "import": "./dist/testing.mjs"
17
15
  },
18
16
  "./credentials-pool": {
19
- "development": "./src/credentials-pool.ts",
20
17
  "types": "./dist/credentials-pool.d.mts",
21
18
  "import": "./dist/credentials-pool.mjs"
22
19
  }
23
20
  },
24
21
  "dependencies": {
25
- "@demicodes/core": "^0.3.1",
26
- "@demicodes/utils": "^0.3.1"
22
+ "@demicodes/core": "^0.3.2",
23
+ "@demicodes/utils": "^0.3.2"
27
24
  },
28
25
  "license": "Apache-2.0",
29
26
  "main": "./dist/index.mjs",