@demicodes/provider 0.3.2 → 0.4.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.
@@ -1,4 +1,4 @@
1
- import { d as ProviderCredentialInfo } from "./types-C9tIelAP.mjs";
1
+ import { d as ProviderCredentialInfo } from "./types-DbFB3sp6.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-DbFB3sp6.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-DbFB3sp6.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,39 @@ 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;
286
- /** Prefer browser vs device/CLI when the vendor supports both; best-effort. */
287
- preferBrowser?: boolean;
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>;
288
307
  }
289
308
  /**
290
- * Login invoke result status of the *vendor* process only, not a pool id.
291
- * Demi does not complete OAuth; product should `importDefault` afterwards.
309
+ * Login invoke result. Every login flow runs the vendor's public protocol
310
+ * natively, imports the resulting material into the pool, and returns the
311
+ * pool `credentialId`.
292
312
  */
293
313
  type ProviderCredentialLoginResult = {
294
314
  status: 'completed';
315
+ credentialId: string;
295
316
  } | {
296
317
  status: 'cancelled';
297
318
  } | {
@@ -312,7 +333,7 @@ type ProviderCredentialsCapability = {
312
333
  mode: 'none';
313
334
  } | {
314
335
  mode: 'supported';
315
- /** Can spawn / open vendor login (`beginLogin`). */
336
+ /** Can run the vendor's native login flow (`beginLogin`). */
316
337
  canBeginLogin?: boolean;
317
338
  /** Can import from the vendor default location into the pool. */
318
339
  canImportDefault?: boolean;
@@ -335,8 +356,9 @@ interface ProviderCredentials {
335
356
  */
336
357
  setActive(credentialId: string): Promise<ProviderCredentialActive> | ProviderCredentialActive;
337
358
  /**
338
- * Invoke the vendors own login flow. Does not complete OAuth inside demi
339
- * and does not return a credential id.
359
+ * Run the vendor's public login protocol natively (device code or copy-back
360
+ * OAuth), surfacing user-facing material via `onPending`. On completion the
361
+ * material is imported into the pool and its `credentialId` is returned.
340
362
  */
341
363
  beginLogin?(options?: ProviderCredentialLoginOptions): Promise<ProviderCredentialLoginResult>;
342
364
  /**
@@ -430,4 +452,4 @@ type ModelPolicy = {
430
452
  default?: string;
431
453
  };
432
454
  //#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 };
455
+ 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,7 +1,7 @@
1
1
  {
2
2
  "name": "@demicodes/provider",
3
3
  "description": "Provider contract and shared building blocks for Demi inference adapters.",
4
- "version": "0.3.2",
4
+ "version": "0.4.1",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "exports": {