@theokit/sdk 4.9.1 → 4.10.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.
@@ -1185,6 +1185,32 @@ interface MemoryProvider {
1185
1185
  */
1186
1186
  type ApiMode = "chat_completions" | "anthropic_messages" | "responses_api" | "bedrock" | "bedrock_anthropic";
1187
1187
  type AuthType = "api_key" | "oauth_device_code" | "oauth_external" | "aws_sdk" | "aws_bearer" | "gcp_oauth" | "none";
1188
+ /**
1189
+ * M41 (agent-builder provider framework) — the context a provider's `transform` receives per request. An
1190
+ * object from day one so it can grow without breaking (M42 adds the resolved `credential`).
1191
+ *
1192
+ * @public
1193
+ */
1194
+ interface ProviderTransformContext {
1195
+ /** The bearer the router resolved for this request (env var, injected key, or an oauth access token). */
1196
+ apiKey: string;
1197
+ }
1198
+ /**
1199
+ * M41 — the one OPTIONAL behavior seam on a provider profile. It lets a provider own its per-request auth:
1200
+ * `fetch` is the universal seam (a provider that returns its own fetch fully controls headers + refresh, for
1201
+ * every transport that accepts a fetch); `headers` is a convenience merged over `extraHeaders` on transports
1202
+ * that carry them (responses_api). This is the CONTRACT-shape adaptation of OpenCode's provider `auth.loader`
1203
+ * (MIT © 2025 opencode — `packages/core/src/plugin/provider/*.ts`), retargeted to theokit's transport model.
1204
+ * Closes the gap where a `ProviderProfile` could only declare STATIC headers.
1205
+ *
1206
+ * @public
1207
+ */
1208
+ interface ProviderTransform {
1209
+ /** Dynamic per-request headers, merged OVER the profile's static `extraHeaders`. */
1210
+ headers?(ctx: ProviderTransformContext): Record<string, string>;
1211
+ /** A fetch to use for this provider's requests (refresh-aware / fully provider-controlled). */
1212
+ fetch?(ctx: ProviderTransformContext): typeof fetch;
1213
+ }
1188
1214
  interface ProviderProfile {
1189
1215
  name: string;
1190
1216
  apiMode: ApiMode;
@@ -1200,6 +1226,11 @@ interface ProviderProfile {
1200
1226
  fallbackModels: ReadonlyArray<string>;
1201
1227
  extraHeaders?: Record<string, string>;
1202
1228
  bodyOverrides?: Record<string, unknown>;
1229
+ /**
1230
+ * M41 — the optional per-request behavior seam (dynamic headers + refresh-aware fetch). Absent ⇒ the profile
1231
+ * is pure data and takes the static path byte-for-byte. See {@link ProviderTransform}.
1232
+ */
1233
+ transform?: ProviderTransform;
1203
1234
  /**
1204
1235
  * Opt-in leaked-dialect safe-parse (theokit#58 follow-up). When `true`, a chat_completions finish
1205
1236
  * with ZERO native `tool_calls` has its assistant content scanned for the Hermes
@@ -1185,6 +1185,32 @@ interface MemoryProvider {
1185
1185
  */
1186
1186
  type ApiMode = "chat_completions" | "anthropic_messages" | "responses_api" | "bedrock" | "bedrock_anthropic";
1187
1187
  type AuthType = "api_key" | "oauth_device_code" | "oauth_external" | "aws_sdk" | "aws_bearer" | "gcp_oauth" | "none";
1188
+ /**
1189
+ * M41 (agent-builder provider framework) — the context a provider's `transform` receives per request. An
1190
+ * object from day one so it can grow without breaking (M42 adds the resolved `credential`).
1191
+ *
1192
+ * @public
1193
+ */
1194
+ interface ProviderTransformContext {
1195
+ /** The bearer the router resolved for this request (env var, injected key, or an oauth access token). */
1196
+ apiKey: string;
1197
+ }
1198
+ /**
1199
+ * M41 — the one OPTIONAL behavior seam on a provider profile. It lets a provider own its per-request auth:
1200
+ * `fetch` is the universal seam (a provider that returns its own fetch fully controls headers + refresh, for
1201
+ * every transport that accepts a fetch); `headers` is a convenience merged over `extraHeaders` on transports
1202
+ * that carry them (responses_api). This is the CONTRACT-shape adaptation of OpenCode's provider `auth.loader`
1203
+ * (MIT © 2025 opencode — `packages/core/src/plugin/provider/*.ts`), retargeted to theokit's transport model.
1204
+ * Closes the gap where a `ProviderProfile` could only declare STATIC headers.
1205
+ *
1206
+ * @public
1207
+ */
1208
+ interface ProviderTransform {
1209
+ /** Dynamic per-request headers, merged OVER the profile's static `extraHeaders`. */
1210
+ headers?(ctx: ProviderTransformContext): Record<string, string>;
1211
+ /** A fetch to use for this provider's requests (refresh-aware / fully provider-controlled). */
1212
+ fetch?(ctx: ProviderTransformContext): typeof fetch;
1213
+ }
1188
1214
  interface ProviderProfile {
1189
1215
  name: string;
1190
1216
  apiMode: ApiMode;
@@ -1200,6 +1226,11 @@ interface ProviderProfile {
1200
1226
  fallbackModels: ReadonlyArray<string>;
1201
1227
  extraHeaders?: Record<string, string>;
1202
1228
  bodyOverrides?: Record<string, unknown>;
1229
+ /**
1230
+ * M41 — the optional per-request behavior seam (dynamic headers + refresh-aware fetch). Absent ⇒ the profile
1231
+ * is pure data and takes the static path byte-for-byte. See {@link ProviderTransform}.
1232
+ */
1233
+ transform?: ProviderTransform;
1203
1234
  /**
1204
1235
  * Opt-in leaked-dialect safe-parse (theokit#58 follow-up). When `true`, a chat_completions finish
1205
1236
  * with ZERO native `tool_calls` has its assistant content scanned for the Hermes
package/dist/cron.cjs CHANGED
@@ -13685,6 +13685,9 @@ function resolveApiKey2(envVars) {
13685
13685
  return void 0;
13686
13686
  }
13687
13687
  function selectTransport(profile, apiKey) {
13688
+ const transformCtx = { apiKey };
13689
+ const transformFetch = profile.transform?.fetch?.(transformCtx);
13690
+ const transformHeaders = profile.transform?.headers?.(transformCtx);
13688
13691
  if (profile.apiMode === "chat_completions") {
13689
13692
  if (profile.name === "ollama") {
13690
13693
  const ollamaBase = process.env.OLLAMA_HOST ?? profile.baseUrl;
@@ -13701,6 +13704,7 @@ function selectTransport(profile, apiKey) {
13701
13704
  }
13702
13705
  const envOverride = resolveBaseUrlEnvOverride(profile.name);
13703
13706
  if (envOverride !== void 0) opts.baseUrl = envOverride;
13707
+ if (transformFetch !== void 0) opts.fetch = transformFetch;
13704
13708
  return new OpenAIClient(opts);
13705
13709
  }
13706
13710
  if (profile.apiMode === "anthropic_messages") {
@@ -13717,10 +13721,12 @@ function selectTransport(profile, apiKey) {
13717
13721
  return new BedrockAnthropicClient(realKey !== void 0 ? { apiKey: realKey } : {});
13718
13722
  }
13719
13723
  if (profile.apiMode === "responses_api") {
13724
+ const mergedHeaders = profile.extraHeaders !== void 0 || transformHeaders !== void 0 ? { ...profile.extraHeaders, ...transformHeaders } : void 0;
13720
13725
  return new ResponsesApiClient({
13721
13726
  apiKey,
13722
13727
  ...profile.baseUrl !== void 0 ? { baseUrl: profile.baseUrl } : {},
13723
- ...profile.extraHeaders !== void 0 ? { extraHeaders: profile.extraHeaders } : {},
13728
+ ...mergedHeaders !== void 0 ? { extraHeaders: mergedHeaders } : {},
13729
+ ...transformFetch !== void 0 ? { fetch: transformFetch } : {},
13724
13730
  providerName: profile.name
13725
13731
  });
13726
13732
  }