@byok-sdk/keys 0.4.3 → 0.5.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { ByokKeysError, BYOK_KEYS_ERROR_CODES } from './errors';
2
2
  export type { ByokKeysErrorCode } from './errors';
3
+ export { PiModelConfigSchema, PI_THINKING_LEVELS } from './pi-model-config';
4
+ export type { PiModelConfig } from './pi-model-config';
3
5
  export { MODEL_PROVIDER_ADAPTERS, MODEL_PROVIDER_KINDS, PROVIDER_AUTH_MODES, PROVIDER_MODEL_CAPABILITIES, ModelProviderProfileSchema, ProviderModelCapabilitySchema, ProviderProfileRefSchema, parseModelProviderProfile, exactProviderProfileBinding, assertExactProviderProfileBinding, } from './provider-profile';
4
6
  export type { ModelProviderAdapter, ModelProviderKind, ModelProviderProfile, ModelProviderProfileInput, ExactProviderProfileBinding, ProviderAuthMode, ProviderModelCapability, ProviderProfileRef, } from './provider-profile';
5
7
  export { MODEL_PROVIDER_VENDORS, MODEL_PROVIDER_VENDOR_IDS, modelProviderVendor, } from './provider-catalog';
package/dist/index.js CHANGED
@@ -56,6 +56,54 @@ var BYOK_KEYS_ERROR_CODES = {
56
56
  SECRET_NAMESPACE_INVALID: "SECRET_NAMESPACE_INVALID",
57
57
  SECRET_VALUE_INVALID: "SECRET_VALUE_INVALID"
58
58
  };
59
+ var PI_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
60
+ var effort = z.string().min(1).max(64).regex(/^[a-zA-Z0-9_-]+$/u).nullable();
61
+ var PiModelConfigSchema = z.object({
62
+ contextWindow: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
63
+ maxTokens: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
64
+ reasoning: z.boolean(),
65
+ thinkingLevel: z.enum(PI_THINKING_LEVELS),
66
+ thinkingLevelMap: z.object({
67
+ off: effort,
68
+ minimal: effort,
69
+ low: effort,
70
+ medium: effort,
71
+ high: effort,
72
+ xhigh: effort,
73
+ max: effort
74
+ }).strict(),
75
+ compat: z.object({
76
+ supportsStore: z.boolean().optional(),
77
+ supportsDeveloperRole: z.boolean().optional(),
78
+ supportsReasoningEffort: z.boolean().optional(),
79
+ supportsUsageInStreaming: z.boolean().optional(),
80
+ maxTokensField: z.enum(["max_completion_tokens", "max_tokens"]).optional(),
81
+ thinkingFormat: z.enum([
82
+ "openai",
83
+ "openrouter",
84
+ "deepseek",
85
+ "together",
86
+ "baseten",
87
+ "zai",
88
+ "qwen",
89
+ "chat-template",
90
+ "qwen-chat-template",
91
+ "string-thinking",
92
+ "ant-ling"
93
+ ]).optional(),
94
+ zaiToolStream: z.boolean().optional()
95
+ }).strict()
96
+ }).strict().superRefine((config, ctx) => {
97
+ if (config.maxTokens > config.contextWindow) {
98
+ ctx.addIssue({ code: "custom", path: ["maxTokens"], message: "Pi maximum output cannot exceed its context window" });
99
+ }
100
+ if (config.reasoning && config.thinkingLevelMap[config.thinkingLevel] === null) {
101
+ ctx.addIssue({ code: "custom", path: ["thinkingLevel"], message: "Pi thinking level is not supported by the declared model" });
102
+ }
103
+ if (!config.reasoning && config.thinkingLevel !== "off") {
104
+ ctx.addIssue({ code: "custom", path: ["thinkingLevel"], message: "Non-reasoning Pi models require thinking off" });
105
+ }
106
+ });
59
107
 
60
108
  // src/provider-catalog.ts
61
109
  function openAiCompatible(display_name, base_url, api_key_env) {
@@ -239,6 +287,8 @@ var ModelProviderProfileSchema = z.object({
239
287
  enabled: z.boolean(),
240
288
  kind: z.literal("model"),
241
289
  model: boundedString("model", 160),
290
+ // Direct transports do not use Pi; Pi admission requires this explicit configuration.
291
+ pi_model: PiModelConfigSchema.optional(),
242
292
  profile_ref: ProviderProfileRefSchema,
243
293
  provider_kind: z.enum(MODEL_PROVIDER_KINDS),
244
294
  updated_at: isoTimestamp("updated_at")
@@ -297,6 +347,7 @@ function exactProviderProfileBinding(profileInput, requiredCapabilities = profil
297
347
  capabilities: normalizedCapabilities,
298
348
  kind: profile.kind,
299
349
  model: profile.model,
350
+ ...profile.pi_model === void 0 ? {} : { pi_model: profile.pi_model },
300
351
  profile_ref: profile.profile_ref,
301
352
  provider_kind: profile.provider_kind
302
353
  });
@@ -1423,6 +1474,7 @@ CREATE TABLE IF NOT EXISTS provider_profile (
1423
1474
  base_url TEXT NOT NULL,
1424
1475
  auth_mode TEXT NOT NULL CHECK (auth_mode IN (${sqlList(PROVIDER_AUTH_MODES)})),
1425
1476
  model TEXT NOT NULL,
1477
+ pi_model TEXT,
1426
1478
  capabilities TEXT NOT NULL,
1427
1479
  enabled INTEGER NOT NULL CHECK (enabled IN (0, 1)),
1428
1480
  created_at TEXT NOT NULL,
@@ -1441,7 +1493,7 @@ function assertProviderProfileSchemaIsCurrent(database, path2) {
1441
1493
  if (normalizeTableDdl(stored) === normalizeTableDdl(SCHEMA)) return;
1442
1494
  throw new ByokKeysError(
1443
1495
  "PROVIDER_STORE_SCHEMA_STALE",
1444
- `Provider profile store at ${path2} was created by a different @byok-sdk/keys schema; recreate the store file to continue`
1496
+ `Provider profile store at ${path2} was created by a different @byok-sdk/keys schema; preserve this store and explicitly provision a separate current-schema store before continuing`
1445
1497
  );
1446
1498
  }
1447
1499
  var ENABLED_INDEX = `
@@ -1523,8 +1575,8 @@ var SqliteProviderProfileStore = class {
1523
1575
  this.#database.prepare(
1524
1576
  `INSERT INTO provider_profile (
1525
1577
  profile_ref, provider_kind, kind, adapter, display_name, base_url,
1526
- auth_mode, model, capabilities, enabled, created_at, updated_at
1527
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1578
+ auth_mode, model, pi_model, capabilities, enabled, created_at, updated_at
1579
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1528
1580
  ON CONFLICT(profile_ref) DO UPDATE SET
1529
1581
  provider_kind = excluded.provider_kind,
1530
1582
  adapter = excluded.adapter,
@@ -1532,6 +1584,7 @@ var SqliteProviderProfileStore = class {
1532
1584
  base_url = excluded.base_url,
1533
1585
  auth_mode = excluded.auth_mode,
1534
1586
  model = excluded.model,
1587
+ pi_model = excluded.pi_model,
1535
1588
  capabilities = excluded.capabilities,
1536
1589
  enabled = excluded.enabled,
1537
1590
  updated_at = excluded.updated_at`
@@ -1544,6 +1597,7 @@ var SqliteProviderProfileStore = class {
1544
1597
  validated.base_url,
1545
1598
  validated.auth_mode,
1546
1599
  validated.model,
1600
+ validated.pi_model === void 0 ? null : JSON.stringify(validated.pi_model),
1547
1601
  JSON.stringify(validated.capabilities),
1548
1602
  validated.enabled ? 1 : 0,
1549
1603
  validated.created_at,
@@ -1582,6 +1636,7 @@ function parseRow(row) {
1582
1636
  }
1583
1637
  return parseModelProviderProfile({
1584
1638
  ...row,
1639
+ pi_model: row.pi_model === null ? void 0 : JSON.parse(row.pi_model),
1585
1640
  capabilities,
1586
1641
  enabled: row.enabled === 1
1587
1642
  });
@@ -1717,6 +1772,7 @@ function encodeRegistry(profiles) {
1717
1772
  enabled: profile.enabled,
1718
1773
  kind: profile.kind,
1719
1774
  model: profile.model,
1775
+ ...profile.pi_model === void 0 ? {} : { pi_model: profile.pi_model },
1720
1776
  profile_ref: profile.profile_ref,
1721
1777
  provider_kind: profile.provider_kind,
1722
1778
  updated_at: profile.updated_at
@@ -1756,7 +1812,10 @@ function decodeRegistryRecord(record, tenant) {
1756
1812
  let profiles;
1757
1813
  try {
1758
1814
  profiles = raw.profiles.map((candidate) => {
1759
- if (!isPlainRecord(candidate) || !hasExactKeys(candidate, PROFILE_KEYS)) {
1815
+ if (!isPlainRecord(candidate) || !hasExactKeys(
1816
+ candidate,
1817
+ Object.hasOwn(candidate, "pi_model") ? [...PROFILE_KEYS, "pi_model"] : PROFILE_KEYS
1818
+ )) {
1760
1819
  throw invalidTruth("Provider profile TruthStore body contains an unknown profile field");
1761
1820
  }
1762
1821
  return parseModelProviderProfile(candidate);
@@ -1944,6 +2003,7 @@ var ProviderRegistry = class {
1944
2003
  display_name: profile.display_name,
1945
2004
  enabled: profile.enabled,
1946
2005
  model: profile.model,
2006
+ ...profile.pi_model === void 0 ? {} : { pi_model: profile.pi_model },
1947
2007
  profile_ref: profile.profile_ref,
1948
2008
  profile_revision: binding.profileRevision,
1949
2009
  profile_hash: binding.profileHash,
@@ -1955,13 +2015,12 @@ var ProviderRegistry = class {
1955
2015
  };
1956
2016
  }
1957
2017
  };
1958
-
1959
- // src/pi-provider-projection.ts
1960
2018
  var PI_PROJECTED_KEY_ENV = "PI_PROVIDER_API_KEY";
1961
2019
  function piProjectionProviderId(profileRef) {
1962
2020
  return `byok-sdk-${profileRef}`;
1963
2021
  }
1964
2022
  function buildPiProviderProjection(profile) {
2023
+ const { thinkingLevel: _, ...modelSettings } = requirePiModelConfig(profile);
1965
2024
  const projectedProviderId = piProjectionProviderId(profile.profile_ref);
1966
2025
  return {
1967
2026
  providers: {
@@ -1972,6 +2031,7 @@ function buildPiProviderProjection(profile) {
1972
2031
  ...profile.auth_mode === "bearer" ? { authHeader: true } : {},
1973
2032
  models: [
1974
2033
  {
2034
+ ...modelSettings,
1975
2035
  id: profile.model,
1976
2036
  name: profile.display_name,
1977
2037
  input: [
@@ -1984,7 +2044,11 @@ function buildPiProviderProjection(profile) {
1984
2044
  }
1985
2045
  };
1986
2046
  }
2047
+ function requirePiModelConfig(profile) {
2048
+ if (profile.pi_model === void 0) throw new Error("Pi execution requires explicit pi_model configuration");
2049
+ return PiModelConfigSchema.parse(profile.pi_model);
2050
+ }
1987
2051
 
1988
- export { AnthropicMessagesClient, BYOK_KEYS_ERROR_CODES, ByokKeysError, DEFAULT_KEYCHAIN_SECRET_STORAGE_PREFIX, DEFAULT_SECRET_ENVELOPE_PREFIX, DEFAULT_SECRET_SERVICE_PREFIX, EnvelopeScopedSecretStore, InMemoryProviderProfileStore, InMemorySecretStore, MODEL_PROVIDER_ADAPTERS, MODEL_PROVIDER_KINDS, MODEL_PROVIDER_VENDORS, MODEL_PROVIDER_VENDOR_IDS, MacOsKeychainSecretStore, ModelProviderProfileSchema, OpenAiCompatibleChatClient, PI_PROJECTED_KEY_ENV, PROVIDER_AUTH_MODES, PROVIDER_MODEL_CAPABILITIES, PROVIDER_PROFILE_TRUTH_RECORD_KEY, PROVIDER_RESPONSE_MAX_BYTES, PROVIDER_TIMEOUT_MS, ProviderModelCapabilitySchema, ProviderProfileRefSchema, ProviderRegistry, SECRET_NAMESPACE_PATTERN, SECRET_NAME_PATTERN, SqliteProviderProfileStore, TruthStoreProviderProfileStore, WindowsCredentialManagerSecretStore, anthropicMessageText, assertExactProviderProfileBinding, assertLiveModelResponse, assertSecretName, assertSecretNamespace, assertSharedSecretValue, buildPiProviderProjection, chatCompletionText, classifyModelProviderHttpError, decodeStrictBase64Utf8, exactProviderProfileBinding, fetchWithProviderGuards, isLoopbackHost, isLoopbackProviderUrl, isPrivateNetworkLiteral, isSqliteAvailable, loadSqliteModule, modelApiUrl, modelMessageText, modelProviderSecretName, modelProviderVendor, normalizeProviderUrl, objectValue, openSqliteDatabase, parseBoundedJsonResponse, parseModelProviderProfile, providerHeaders, readModelProviderResponse, requiredProviderSecret, runCommand, scopeSecretStore, secretScopeId, secureSqliteFilePermissions };
2052
+ export { AnthropicMessagesClient, BYOK_KEYS_ERROR_CODES, ByokKeysError, DEFAULT_KEYCHAIN_SECRET_STORAGE_PREFIX, DEFAULT_SECRET_ENVELOPE_PREFIX, DEFAULT_SECRET_SERVICE_PREFIX, EnvelopeScopedSecretStore, InMemoryProviderProfileStore, InMemorySecretStore, MODEL_PROVIDER_ADAPTERS, MODEL_PROVIDER_KINDS, MODEL_PROVIDER_VENDORS, MODEL_PROVIDER_VENDOR_IDS, MacOsKeychainSecretStore, ModelProviderProfileSchema, OpenAiCompatibleChatClient, PI_PROJECTED_KEY_ENV, PI_THINKING_LEVELS, PROVIDER_AUTH_MODES, PROVIDER_MODEL_CAPABILITIES, PROVIDER_PROFILE_TRUTH_RECORD_KEY, PROVIDER_RESPONSE_MAX_BYTES, PROVIDER_TIMEOUT_MS, PiModelConfigSchema, ProviderModelCapabilitySchema, ProviderProfileRefSchema, ProviderRegistry, SECRET_NAMESPACE_PATTERN, SECRET_NAME_PATTERN, SqliteProviderProfileStore, TruthStoreProviderProfileStore, WindowsCredentialManagerSecretStore, anthropicMessageText, assertExactProviderProfileBinding, assertLiveModelResponse, assertSecretName, assertSecretNamespace, assertSharedSecretValue, buildPiProviderProjection, chatCompletionText, classifyModelProviderHttpError, decodeStrictBase64Utf8, exactProviderProfileBinding, fetchWithProviderGuards, isLoopbackHost, isLoopbackProviderUrl, isPrivateNetworkLiteral, isSqliteAvailable, loadSqliteModule, modelApiUrl, modelMessageText, modelProviderSecretName, modelProviderVendor, normalizeProviderUrl, objectValue, openSqliteDatabase, parseBoundedJsonResponse, parseModelProviderProfile, providerHeaders, readModelProviderResponse, requiredProviderSecret, runCommand, scopeSecretStore, secretScopeId, secureSqliteFilePermissions };
1989
2053
  //# sourceMappingURL=index.js.map
1990
2054
  //# sourceMappingURL=index.js.map