@flue/sdk 0.3.6 → 0.3.7

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
@@ -289,6 +289,34 @@ await session.prompt('Review the latest changes.'); // uses reviewer
289
289
  await session.task('Research related issues.', { role: 'researcher' }); // uses researcher
290
290
  ```
291
291
 
292
+ ### Provider Settings
293
+
294
+ Use `providers` when model traffic needs provider-specific runtime settings,
295
+ such as an enterprise API gateway, provider-compatible proxy, custom endpoint,
296
+ or gateway-specific credentials. This is common for managed credentials, audit
297
+ logging, traffic routing, or self-hosted OpenAI-compatible providers.
298
+
299
+ Configure these settings in `init()` instead of mutating global model state. They
300
+ are runtime-scoped to that agent and apply to every model it resolves, including
301
+ agent defaults, role-level models, per-call model selections, tasks, and context
302
+ compaction.
303
+
304
+ ```ts
305
+ const agent = await init({
306
+ model: 'anthropic/claude-sonnet-4-6',
307
+ providers: {
308
+ anthropic: {
309
+ baseUrl: env.ANTHROPIC_BASE_URL,
310
+ headers: {
311
+ 'X-Custom-Auth': env.GATEWAY_KEY,
312
+ },
313
+ // Use this when the proxy expects a synthetic or gateway-specific key.
314
+ apiKey: 'dummy',
315
+ },
316
+ },
317
+ });
318
+ ```
319
+
292
320
  ### Custom Virtual Sandboxes
293
321
 
294
322
  For most agents, use the built-in virtual sandbox or `sandbox: 'local'`. If you need to customize just-bash directly, pass a Bash factory. The factory must return a fresh Bash-like runtime each time; share the filesystem object in the closure to persist files across sessions and prompts.
package/dist/client.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as TaskOptions, C as SessionEnv, D as ShellResult, E as ShellOptions, M as ToolParameters, S as SessionData, T as SessionStore, _ as FlueSessions, a as BashLike, d as FileStat, f as FlueAgent, g as FlueSession, h as FlueEventCallback, i as BashFactory, j as ToolDef, k as SkillOptions, l as Command, m as FlueEvent, p as FlueContext, r as AgentInit, t as AgentConfig, v as PromptOptions, w as SessionOptions, x as SandboxFactory, y as PromptResponse } from "./types-CItTrBsU.mjs";
2
- import { i as connectMcpServer, n as McpServerOptions, r as McpTransport, t as McpServerConnection } from "./mcp-EZy-Vb5M.mjs";
1
+ import { A as ShellResult, D as SessionOptions, E as SessionEnv, F as ToolParameters, M as SkillOptions, N as TaskOptions, O as SessionStore, P as ToolDef, S as ProvidersConfig, T as SessionData, _ as FlueSessions, a as BashLike, b as PromptResponse, d as FileStat, f as FlueAgent, g as FlueSession, h as FlueEventCallback, i as BashFactory, k as ShellOptions, l as Command, m as FlueEvent, p as FlueContext, r as AgentInit, t as AgentConfig, v as ModelConfig, w as SandboxFactory, x as ProviderSettings, y as PromptOptions } from "./types-CKcp6T-y.mjs";
2
+ import { i as connectMcpServer, n as McpServerOptions, r as McpTransport, t as McpServerConnection } from "./mcp-CKMPhMDe.mjs";
3
3
  import { Type } from "@mariozechner/pi-ai";
4
4
 
5
5
  //#region src/client.d.ts
@@ -23,4 +23,4 @@ interface FlueContextInternal extends FlueContext {
23
23
  }
24
24
  declare function createFlueContext(config: FlueContextConfig): FlueContextInternal;
25
25
  //#endregion
26
- export { type AgentInit, type BashFactory, type BashLike, type Command, type FileStat, type FlueAgent, type FlueContext, FlueContextConfig, FlueContextInternal, type FlueEvent, type FlueEventCallback, type FlueSession, type FlueSessions, type McpServerConnection, type McpServerOptions, type McpTransport, type PromptOptions, type PromptResponse, type SandboxFactory, type SessionData, type SessionEnv, type SessionOptions, type SessionStore, type ShellOptions, type ShellResult, type SkillOptions, type TaskOptions, type ToolDef, type ToolParameters, Type, connectMcpServer, createFlueContext };
26
+ export { type AgentInit, type BashFactory, type BashLike, type Command, type FileStat, type FlueAgent, type FlueContext, FlueContextConfig, FlueContextInternal, type FlueEvent, type FlueEventCallback, type FlueSession, type FlueSessions, type McpServerConnection, type McpServerOptions, type McpTransport, type ModelConfig, type PromptOptions, type PromptResponse, type ProviderSettings, type ProvidersConfig, type SandboxFactory, type SessionData, type SessionEnv, type SessionOptions, type SessionStore, type ShellOptions, type ShellResult, type SkillOptions, type TaskOptions, type ToolDef, type ToolParameters, Type, connectMcpServer, createFlueContext };
package/dist/client.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { r as discoverSessionContext } from "./agent-BTB0809P.mjs";
2
- import { a as assertRoleExists } from "./session-BaaSQTWS.mjs";
2
+ import { a as assertRoleExists } from "./session-CNOAfV45.mjs";
3
3
  import { bashFactoryToSessionEnv, createCwdSessionEnv } from "./sandbox.mjs";
4
- import { n as AgentClient, t as connectMcpServer } from "./mcp-DTFRe9vh.mjs";
4
+ import { n as AgentClient, t as connectMcpServer } from "./mcp-B13ZPduG.mjs";
5
5
  import { Type } from "@mariozechner/pi-ai";
6
6
 
7
7
  //#region src/client.ts
@@ -19,24 +19,28 @@ function createFlueContext(config) {
19
19
  return config.env;
20
20
  },
21
21
  async init(options) {
22
- const id = options?.id ?? config.id;
22
+ if (!options || !("model" in options)) throw new Error("[flue] init() requires a model. Pass { model: \"provider/model-id\" } or { model: false }.");
23
+ if (options.model !== false && typeof options.model !== "string") throw new Error("[flue] init({ model }) must be a model string or false.");
24
+ const id = options.id ?? config.id;
23
25
  if (initializedAgentIds.has(id)) throw new Error(`[flue] init() has already been called for agent "${id}" in this request.`);
24
26
  initializedAgentIds.add(id);
25
27
  try {
26
- assertRoleExists(config.agentConfig.roles, options?.role);
27
- const sandbox = options?.sandbox;
28
- const baseEnv = await resolveSessionEnv(id, sandbox, config, options?.cwd);
29
- const env = options?.cwd ? createCwdSessionEnv(baseEnv, options.cwd) : baseEnv;
30
- const store = options?.persist ?? config.defaultStore;
28
+ assertRoleExists(config.agentConfig.roles, options.role);
29
+ const sandbox = options.sandbox;
30
+ const baseEnv = await resolveSessionEnv(id, sandbox, config, options.cwd);
31
+ const env = options.cwd ? createCwdSessionEnv(baseEnv, options.cwd) : baseEnv;
32
+ const store = options.persist ?? config.defaultStore;
31
33
  const localContext = await discoverSessionContext(env);
32
- const agentModel = options?.model && config.agentConfig.resolveModel ? config.agentConfig.resolveModel(options.model) : config.agentConfig.model;
34
+ const providers = mergeProvidersConfig(config.agentConfig.providers, options.providers);
35
+ const agentModel = config.agentConfig.resolveModel(options.model, providers);
33
36
  return new AgentClient(id, {
34
37
  ...config.agentConfig,
35
38
  systemPrompt: localContext.systemPrompt,
36
39
  skills: localContext.skills,
37
40
  model: agentModel,
38
- role: options?.role ?? config.agentConfig.role
39
- }, env, store, currentEventCallback, options?.commands, options?.tools);
41
+ role: options.role ?? config.agentConfig.role,
42
+ providers
43
+ }, env, store, currentEventCallback, options.commands, options.tools);
40
44
  } catch (error) {
41
45
  initializedAgentIds.delete(id);
42
46
  throw error;
@@ -73,6 +77,23 @@ async function resolveSessionEnv(id, sandbox, config, cwd) {
73
77
  });
74
78
  throw new Error("[flue] Invalid sandbox option passed to init().");
75
79
  }
80
+ function mergeProvidersConfig(base, settings) {
81
+ if (!base) return settings;
82
+ if (!settings) return base;
83
+ const merged = { ...base };
84
+ for (const [provider, config] of Object.entries(settings)) {
85
+ const previous = merged[provider];
86
+ merged[provider] = {
87
+ ...previous,
88
+ ...config,
89
+ headers: previous?.headers || config.headers ? {
90
+ ...previous?.headers ?? {},
91
+ ...config.headers ?? {}
92
+ } : void 0
93
+ };
94
+ }
95
+ return merged;
96
+ }
76
97
 
77
98
  //#endregion
78
99
  export { Type, connectMcpServer, createFlueContext };
@@ -1,5 +1,5 @@
1
- import { C as SessionEnv, T as SessionStore, l as Command } from "../types-CItTrBsU.mjs";
2
- import { t as CommandExecutor } from "../command-helpers-CXzopT_-.mjs";
1
+ import { E as SessionEnv, O as SessionStore, l as Command } from "../types-CKcp6T-y.mjs";
2
+ import { t as CommandExecutor } from "../command-helpers-5DpOaRIB.mjs";
3
3
 
4
4
  //#region src/cloudflare/virtual-sandbox.d.ts
5
5
  interface VirtualSandboxOptions {
@@ -1,5 +1,5 @@
1
1
  import "../agent-BTB0809P.mjs";
2
- import "../session-BaaSQTWS.mjs";
2
+ import "../session-CNOAfV45.mjs";
3
3
  import { createSandboxSessionEnv } from "../sandbox.mjs";
4
4
  import { t as normalizeExecutor } from "../command-helpers-hTZKWK13.mjs";
5
5
  import { Workspace, WorkspaceFileSystem } from "@cloudflare/shell";
@@ -1,4 +1,4 @@
1
- import { D as ShellResult } from "./types-CItTrBsU.mjs";
1
+ import { A as ShellResult } from "./types-CKcp6T-y.mjs";
2
2
 
3
3
  //#region src/command-helpers.d.ts
4
4
  /**
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as TaskOptions, C as SessionEnv, D as ShellResult, E as ShellOptions, M as ToolParameters, O as Skill, S as SessionData, T as SessionStore, _ as FlueSessions, a as BashLike, b as Role, c as BuildPlugin, d as FileStat, f as FlueAgent, g as FlueSession, h as FlueEventCallback, i as BashFactory, j as ToolDef, k as SkillOptions, l as Command, m as FlueEvent, n as AgentInfo, o as BuildContext, p as FlueContext, r as AgentInit, s as BuildOptions, t as AgentConfig, u as CommandDef, v as PromptOptions, w as SessionOptions, x as SandboxFactory, y as PromptResponse } from "./types-CItTrBsU.mjs";
1
+ import { A as ShellResult, C as Role, D as SessionOptions, E as SessionEnv, F as ToolParameters, M as SkillOptions, N as TaskOptions, O as SessionStore, P as ToolDef, T as SessionData, _ as FlueSessions, a as BashLike, b as PromptResponse, c as BuildPlugin, d as FileStat, f as FlueAgent, g as FlueSession, h as FlueEventCallback, i as BashFactory, j as Skill, k as ShellOptions, l as Command, m as FlueEvent, n as AgentInfo, o as BuildContext, p as FlueContext, r as AgentInit, s as BuildOptions, t as AgentConfig, u as CommandDef, v as ModelConfig, w as SandboxFactory, y as PromptOptions } from "./types-CKcp6T-y.mjs";
2
2
  import { AgentTool, AgentToolResult } from "@mariozechner/pi-agent-core";
3
3
 
4
4
  //#region src/build.d.ts
@@ -113,4 +113,4 @@ interface CreateToolsOptions {
113
113
  }
114
114
  declare function createTools(env: SessionEnv, options?: CreateToolsOptions): AgentTool<any>[];
115
115
  //#endregion
116
- export { type AgentConfig, type AgentInfo, type AgentInit, BUILTIN_TOOL_NAMES, type BashFactory, type BashLike, type BuildContext, type BuildOptions, type BuildPlugin, type Command, type CommandDef, DEFAULT_DEV_PORT, type DevOptions, type FileStat, type FlueAgent, type FlueContext, type FlueEvent, type FlueEventCallback, type FlueSession, type FlueSessions, type PromptOptions, type PromptResponse, type Role, type SandboxFactory, type SessionData, type SessionEnv, type SessionOptions, type SessionStore, type ShellOptions, type ShellResult, type Skill, type SkillOptions, type TaskOptions, type ToolDef, type ToolParameters, build, createTools, dev, parseEnvFiles, resolveEnvFiles, resolveWorkspaceFromCwd };
116
+ export { type AgentConfig, type AgentInfo, type AgentInit, BUILTIN_TOOL_NAMES, type BashFactory, type BashLike, type BuildContext, type BuildOptions, type BuildPlugin, type Command, type CommandDef, DEFAULT_DEV_PORT, type DevOptions, type FileStat, type FlueAgent, type FlueContext, type FlueEvent, type FlueEventCallback, type FlueSession, type FlueSessions, type ModelConfig, type PromptOptions, type PromptResponse, type Role, type SandboxFactory, type SessionData, type SessionEnv, type SessionOptions, type SessionStore, type ShellOptions, type ShellResult, type Skill, type SkillOptions, type TaskOptions, type ToolDef, type ToolParameters, build, createTools, dev, parseEnvFiles, resolveEnvFiles, resolveWorkspaceFromCwd };
package/dist/index.mjs CHANGED
@@ -439,13 +439,6 @@ const manifest = ${manifest};
439
439
  // dispatcher (which would otherwise return text/plain "Invalid request").
440
440
  const webhookAgentNames = new Set(${JSON.stringify(webhookAgents.map((a) => a.name))});
441
441
 
442
- // ─── Infrastructure ─────────────────────────────────────────────────────────
443
-
444
- // No build-time model default. The user sets model at runtime via
445
- // \`init({ model: "provider/model-id" })\` for an agent default, or via
446
- // \`{ model: "provider/model-id" }\` on any individual prompt/skill/task call.
447
- const model = undefined;
448
-
449
442
  // ─── Sandbox Environments ───────────────────────────────────────────────────
450
443
 
451
444
  /**
@@ -549,7 +542,7 @@ function createContextForRequest(id, payload, doInstance) {
549
542
  payload,
550
543
  env: doInstance?.env ?? {},
551
544
  agentConfig: {
552
- systemPrompt, skills, roles, model, resolveModel,
545
+ systemPrompt, skills, roles, model: undefined, resolveModel,
553
546
  },
554
547
  createDefaultEnv,
555
548
  createLocalEnv,
@@ -909,13 +902,6 @@ const manifest = ${JSON.stringify({ agents: agents.map((a) => ({
909
902
  triggers: a.triggers
910
903
  })) }, null, 2)};
911
904
 
912
- // ─── Infrastructure ─────────────────────────────────────────────────────────
913
-
914
- // No build-time model default. The user sets model at runtime via
915
- // \`init({ model: "provider/model-id" })\` for an agent default, or via
916
- // \`{ model: "provider/model-id" }\` on any individual prompt/skill/task call.
917
- const model = undefined;
918
-
919
905
  // ─── Sandbox Environments ───────────────────────────────────────────────────
920
906
 
921
907
  /**
@@ -955,7 +941,7 @@ function createContextForRequest(id, payload) {
955
941
  payload,
956
942
  env: process.env,
957
943
  agentConfig: {
958
- systemPrompt, skills, roles, model, resolveModel,
944
+ systemPrompt, skills, roles, model: undefined, resolveModel,
959
945
  },
960
946
  createDefaultEnv,
961
947
  createLocalEnv,
@@ -1,5 +1,5 @@
1
- import { S as SessionData, T as SessionStore } from "./types-CItTrBsU.mjs";
2
- import "./mcp-EZy-Vb5M.mjs";
1
+ import { O as SessionStore, S as ProvidersConfig, T as SessionData, v as ModelConfig } from "./types-CKcp6T-y.mjs";
2
+ import "./mcp-CKMPhMDe.mjs";
3
3
  import { FlueContextConfig, FlueContextInternal, createFlueContext } from "./client.mjs";
4
4
  import { bashFactoryToSessionEnv } from "./sandbox.mjs";
5
5
  import { getModel } from "@mariozechner/pi-ai";
@@ -285,6 +285,6 @@ declare function validateAgentRequest(opts: ValidateAgentRequestOptions): void;
285
285
  * transitive deps. Centralizing the resolver here keeps `_entry.ts`
286
286
  * dependency-free apart from `@flue/sdk/*`.
287
287
  */
288
- declare function resolveModel(modelString: string): ReturnType<typeof getModel>;
288
+ declare function resolveModel(model: ModelConfig | undefined, providers?: ProvidersConfig): ReturnType<typeof getModel> | undefined;
289
289
  //#endregion
290
290
  export { AgentNotFoundError, type FlueContextConfig, type FlueContextInternal, InMemorySessionStore, InvalidRequestError, MethodNotAllowedError, RouteNotFoundError, bashFactoryToSessionEnv, createFlueContext, parseJsonBody, resolveModel, toHttpResponse, toSseData, validateAgentRequest };
package/dist/internal.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./agent-BTB0809P.mjs";
2
- import { t as InMemorySessionStore } from "./session-BaaSQTWS.mjs";
2
+ import { t as InMemorySessionStore } from "./session-CNOAfV45.mjs";
3
3
  import { bashFactoryToSessionEnv } from "./sandbox.mjs";
4
- import "./mcp-DTFRe9vh.mjs";
4
+ import "./mcp-B13ZPduG.mjs";
5
5
  import { createFlueContext } from "./client.mjs";
6
6
  import { getModel } from "@mariozechner/pi-ai";
7
7
 
@@ -441,14 +441,30 @@ function validateAgentRequest(opts) {
441
441
  * transitive deps. Centralizing the resolver here keeps `_entry.ts`
442
442
  * dependency-free apart from `@flue/sdk/*`.
443
443
  */
444
- function resolveModel(modelString) {
444
+ function resolveModel(model, providers) {
445
+ if (model === false || model === void 0) return void 0;
446
+ const modelString = model;
445
447
  const slash = modelString.indexOf("/");
446
448
  if (slash === -1) throw new Error(`[flue] Invalid model "${modelString}". Use the "provider/model-id" format (e.g. "anthropic/claude-haiku-4-5").`);
447
449
  const provider = modelString.slice(0, slash);
448
450
  const modelId = modelString.slice(slash + 1);
449
451
  const resolved = getModel(provider, modelId);
450
452
  if (!resolved) throw new Error(`[flue] Unknown model "${modelString}". Provider "${provider}" / model id "${modelId}" is not registered with @mariozechner/pi-ai.`);
451
- return resolved;
453
+ return applyProviderSettings(resolved, providers?.[provider]);
454
+ }
455
+ function applyProviderSettings(model, providerSettings) {
456
+ if (!providerSettings) return model;
457
+ const hasBaseUrl = providerSettings.baseUrl !== void 0;
458
+ const hasHeaders = providerSettings.headers !== void 0;
459
+ if (!hasBaseUrl && !hasHeaders) return model;
460
+ return {
461
+ ...model,
462
+ baseUrl: providerSettings.baseUrl ?? model.baseUrl,
463
+ headers: hasHeaders ? {
464
+ ...model.headers ?? {},
465
+ ...providerSettings.headers
466
+ } : model.headers
467
+ };
452
468
  }
453
469
 
454
470
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { r as discoverSessionContext } from "./agent-BTB0809P.mjs";
2
- import { a as assertRoleExists, n as Session, o as createScopedEnv, r as deleteSessionTree, s as mergeCommands } from "./session-BaaSQTWS.mjs";
2
+ import { a as assertRoleExists, n as Session, o as createScopedEnv, r as deleteSessionTree, s as mergeCommands } from "./session-CNOAfV45.mjs";
3
3
  import { createCwdSessionEnv } from "./sandbox.mjs";
4
4
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
5
5
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
@@ -1,4 +1,4 @@
1
- import { j as ToolDef } from "./types-CItTrBsU.mjs";
1
+ import { P as ToolDef } from "./types-CKcp6T-y.mjs";
2
2
 
3
3
  //#region src/mcp.d.ts
4
4
  type McpTransport = 'streamable-http' | 'sse';
@@ -1,5 +1,5 @@
1
- import { l as Command } from "../types-CItTrBsU.mjs";
2
- import { t as CommandExecutor } from "../command-helpers-CXzopT_-.mjs";
1
+ import { l as Command } from "../types-CKcp6T-y.mjs";
2
+ import { t as CommandExecutor } from "../command-helpers-5DpOaRIB.mjs";
3
3
  import { execFile } from "node:child_process";
4
4
 
5
5
  //#region src/node/define-command.d.ts
@@ -1,4 +1,4 @@
1
- import { C as SessionEnv, D as ShellResult, d as FileStat, i as BashFactory, u as CommandDef, x as SandboxFactory } from "./types-CItTrBsU.mjs";
1
+ import { A as ShellResult, E as SessionEnv, d as FileStat, i as BashFactory, u as CommandDef, w as SandboxFactory } from "./types-CKcp6T-y.mjs";
2
2
 
3
3
  //#region src/sandbox.d.ts
4
4
  declare function createCwdSessionEnv(parentEnv: SessionEnv, cwd: string): SessionEnv;
package/dist/sandbox.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./agent-BTB0809P.mjs";
2
- import { i as normalizePath, o as createScopedEnv } from "./session-BaaSQTWS.mjs";
2
+ import { i as normalizePath, o as createScopedEnv } from "./session-CNOAfV45.mjs";
3
3
 
4
4
  //#region src/sandbox.ts
5
5
  function createCwdSessionEnv(parentEnv, cwd) {
@@ -740,6 +740,7 @@ var Session = class {
740
740
  tools,
741
741
  messages: previousMessages
742
742
  },
743
+ getApiKey: (provider) => this.getProviderApiKey(provider),
743
744
  toolExecution: "parallel"
744
745
  });
745
746
  this.eventCallback = options.onAgentEvent;
@@ -891,8 +892,8 @@ var Session = class {
891
892
  resolveModelForCall(promptModel, roleName, callSite) {
892
893
  let model = this.config.model;
893
894
  const roleModel = resolveRoleModel(this.config.roles, roleName);
894
- if (roleModel && this.config.resolveModel) model = this.config.resolveModel(roleModel);
895
- if (promptModel && this.config.resolveModel) model = this.config.resolveModel(promptModel);
895
+ if (roleModel) model = this.config.resolveModel(roleModel, this.config.providers);
896
+ if (promptModel) model = this.config.resolveModel(promptModel, this.config.providers);
896
897
  return this.requireModel(model, callSite);
897
898
  }
898
899
  /**
@@ -902,7 +903,10 @@ var Session = class {
902
903
  */
903
904
  requireModel(model, callSite) {
904
905
  if (model) return model;
905
- throw new Error(`[flue] No model configured for ${callSite}. Pass \`{ model: "provider/model-id" }\` to \`init()\` for an agent-wide default, or to this prompt()/skill() call for a one-off override.`);
906
+ throw new Error(`[flue] No model configured for ${callSite}. Pass \`{ model: "provider/model-id" }\` to this call or configure a role model.`);
907
+ }
908
+ getProviderApiKey(provider) {
909
+ return this.config.providers?.[provider]?.apiKey;
906
910
  }
907
911
  buildSystemPrompt(roleName) {
908
912
  const parts = [this.config.systemPrompt];
@@ -1193,7 +1197,7 @@ var Session = class {
1193
1197
  reason,
1194
1198
  estimatedTokens
1195
1199
  });
1196
- const result = await compact(preparation, model, void 0, this.compactionAbortController.signal);
1200
+ const result = await compact(preparation, model, this.getProviderApiKey(model.provider), this.compactionAbortController.signal);
1197
1201
  if (this.compactionAbortController.signal.aborted) return;
1198
1202
  this.history.appendCompaction({
1199
1203
  summary: result.summary,
@@ -102,6 +102,25 @@ interface CompactionConfig {
102
102
  /** Recent tokens to preserve (not summarized). Default: 20000 */
103
103
  keepRecentTokens?: number;
104
104
  }
105
+ interface ProviderSettings {
106
+ /**
107
+ * Provider endpoint used by built-in models. Useful for API gateways,
108
+ * LiteLLM-style proxies, or enterprise-managed provider endpoints.
109
+ */
110
+ baseUrl?: string;
111
+ /**
112
+ * Headers merged into the resolved model's provider-level headers. Values
113
+ * here override headers already defined by the built-in model.
114
+ */
115
+ headers?: Record<string, string>;
116
+ /**
117
+ * API key returned to the underlying agent runtime for this provider.
118
+ * Useful when the gateway requires a dummy key or when credentials should
119
+ * come from the agent's runtime env instead of process-global env vars.
120
+ */
121
+ apiKey?: string;
122
+ }
123
+ type ProvidersConfig = Record<string, ProviderSettings>;
105
124
  interface AgentConfig {
106
125
  /** Discovered at runtime from AGENTS.md + .agents/skills/ in the session's cwd. */
107
126
  systemPrompt: string;
@@ -109,17 +128,20 @@ interface AgentConfig {
109
128
  skills: Record<string, Skill>;
110
129
  roles: Record<string, Role>;
111
130
  /**
112
- * Agent-wide default model. Undefined by default — the user must set it via
113
- * `init({ model: "provider/model-id" })` or pass `{ model }` at each prompt/
114
- * skill/task call site. Calls with no model resolved throw clearly at runtime.
131
+ * Agent-wide default model. Undefined when the user explicitly passes
132
+ * `init({ model: false })`, so each model-using call must resolve one from a
133
+ * role or call-site override.
115
134
  */
116
135
  model: Model<any> | undefined;
117
136
  /** Agent-wide default role. Per-session and per-call roles override this. */
118
137
  role?: string;
119
- /** Resolve a "provider/modelId" string to a Model instance. Throws on invalid input. */
120
- resolveModel?: (modelString: string) => Model<any>;
138
+ /** Provider runtime settings applied when resolving models. */
139
+ providers?: ProvidersConfig;
140
+ /** Resolve model config to a Model instance. Throws on invalid model strings. */
141
+ resolveModel: (model: ModelConfig | undefined, providers?: ProvidersConfig) => Model<any> | undefined;
121
142
  compaction?: CompactionConfig;
122
143
  }
144
+ type ModelConfig = string | false;
123
145
  /**
124
146
  * Request context passed to agent handler functions. Pass type parameters
125
147
  * to type `payload` and `env` (e.g. the `Env` interface generated by
@@ -131,9 +153,9 @@ interface FlueContext<TPayload = any, TEnv = Record<string, any>> {
131
153
  /** Platform env bindings (process.env on Node, Worker env on Cloudflare). */
132
154
  readonly env: TEnv;
133
155
  /** Initialize an agent runtime with sandbox + persistence. */
134
- init(options?: AgentInit): Promise<FlueAgent>;
156
+ init(options: AgentInit): Promise<FlueAgent>;
135
157
  }
136
- /** All fields are optional omitting gives platform defaults (empty sandbox, platform store, build-time model). */
158
+ /** Agent runtime options. A default model is required unless explicitly disabled with `model: false`. */
137
159
  interface AgentInit {
138
160
  /** Agent/sandbox scope id. Defaults to the route/context id. */
139
161
  id?: string;
@@ -149,16 +171,37 @@ interface AgentInit {
149
171
  /** Defaults to platform store (in-memory on Node, DO SQLite on Cloudflare). */
150
172
  persist?: SessionStore;
151
173
  /**
152
- * Override the default model for this agent. Applies to all prompt() and skill()
153
- * calls unless overridden at the call site.
174
+ * Default model for this agent. Applies to all prompt(), skill(), and task()
175
+ * calls unless overridden by a role or at the call site. Pass `false` to require every
176
+ * model-using call to resolve a model from a role or call-site override.
154
177
  *
155
178
  * Format: `'provider/modelId'` (e.g. `'anthropic/claude-opus-4-20250514'`).
156
179
  *
157
- * Precedence (highest wins): per-call `model` > role `model` > agent `model` > build-time default.
180
+ * Precedence (highest wins): per-call `model` > role `model` > agent `model`.
158
181
  */
159
- model?: string;
182
+ model: ModelConfig;
160
183
  /** Agent-wide default role. Overridden by session-level or per-call roles. */
161
184
  role?: string;
185
+ /**
186
+ * Provider runtime settings for every model used by this agent, including
187
+ * role-level and per-call model selections.
188
+ *
189
+ * Example:
190
+ *
191
+ * ```ts
192
+ * await init({
193
+ * model: 'anthropic/claude-sonnet-4-6',
194
+ * providers: {
195
+ * anthropic: {
196
+ * baseUrl: env.ANTHROPIC_BASE_URL,
197
+ * headers: { 'X-Custom-Auth': env.GATEWAY_KEY },
198
+ * apiKey: 'dummy',
199
+ * },
200
+ * },
201
+ * });
202
+ * ```
203
+ */
204
+ providers?: ProvidersConfig;
162
205
  /**
163
206
  * Agent-wide tools. Every prompt(), skill(), and task() call can use these.
164
207
  * Per-call tools are added on top and must not reuse the same names.
@@ -463,4 +506,4 @@ interface BuildOptions {
463
506
  plugin?: BuildPlugin;
464
507
  }
465
508
  //#endregion
466
- export { TaskOptions as A, SessionEnv as C, ShellResult as D, ShellOptions as E, ToolParameters as M, Skill as O, SessionData as S, SessionStore as T, FlueSessions as _, BashLike as a, Role as b, BuildPlugin as c, FileStat as d, FlueAgent as f, FlueSession as g, FlueEventCallback as h, BashFactory as i, ToolDef as j, SkillOptions as k, Command as l, FlueEvent as m, AgentInfo as n, BuildContext as o, FlueContext as p, AgentInit as r, BuildOptions as s, AgentConfig as t, CommandDef as u, PromptOptions as v, SessionOptions as w, SandboxFactory as x, PromptResponse as y };
509
+ export { ShellResult as A, Role as C, SessionOptions as D, SessionEnv as E, ToolParameters as F, SkillOptions as M, TaskOptions as N, SessionStore as O, ToolDef as P, ProvidersConfig as S, SessionData as T, FlueSessions as _, BashLike as a, PromptResponse as b, BuildPlugin as c, FileStat as d, FlueAgent as f, FlueSession as g, FlueEventCallback as h, BashFactory as i, Skill as j, ShellOptions as k, Command as l, FlueEvent as m, AgentInfo as n, BuildContext as o, FlueContext as p, AgentInit as r, BuildOptions as s, AgentConfig as t, CommandDef as u, ModelConfig as v, SandboxFactory as w, ProviderSettings as x, PromptOptions as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flue/sdk",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {