@agtlantis/core 0.4.1 → 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.
@@ -1,4 +1,4 @@
1
- import { LanguageModelUsage, ToolSet, generateText, streamText, generateObject, FilePart, ImagePart, LanguageModel } from 'ai';
1
+ import { LanguageModelUsage, CallSettings, ToolSet, generateText, streamText, generateObject, FilePart, ImagePart, LanguageModel } from 'ai';
2
2
  import * as zod from 'zod';
3
3
 
4
4
  /**
@@ -142,6 +142,11 @@ interface CostResult {
142
142
  cachedInputCost: number;
143
143
  }
144
144
 
145
+ /**
146
+ * Standard AI SDK generation parameters that can be set as defaults at the Provider level.
147
+ * Per-call parameters override these defaults via simple spread merge.
148
+ */
149
+ type GenerationOptions = Pick<CallSettings, 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed'>;
145
150
  /**
146
151
  * Structural interface matching AI SDK's internal Output<OUTPUT, PARTIAL>.
147
152
  *
@@ -578,6 +583,11 @@ interface Provider {
578
583
  * The actual options type depends on the provider (Google, OpenAI, etc.).
579
584
  */
580
585
  withDefaultOptions(options: Record<string, unknown>): Provider;
586
+ /**
587
+ * Set default generation options (standard AI SDK parameters) for all LLM calls.
588
+ * Per-call parameters override these defaults.
589
+ */
590
+ withDefaultGenerationOptions(options: GenerationOptions): Provider;
581
591
  streamingExecution<TEvent extends {
582
592
  type: string;
583
593
  }>(generator: (session: StreamingSession<TEvent>) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>>>, options?: ExecutionOptions): StreamingExecution<TEvent>;
@@ -630,6 +640,11 @@ interface SimpleSessionOptions {
630
640
  * These will be merged with per-call tools (per-call takes precedence).
631
641
  */
632
642
  defaultTools?: ToolSet;
643
+ /**
644
+ * Default generation options (standard AI SDK parameters) for all LLM calls.
645
+ * Per-call parameters override these defaults via simple spread.
646
+ */
647
+ defaultGenerationOptions?: GenerationOptions;
633
648
  }
634
649
  declare class SimpleSession {
635
650
  private readonly defaultLanguageModel;
@@ -638,6 +653,7 @@ declare class SimpleSession {
638
653
  private readonly providerPricing;
639
654
  private readonly defaultProviderOptions;
640
655
  private readonly defaultTools;
656
+ private readonly defaultGenerationOptions;
641
657
  private readonly _fileManager;
642
658
  private readonly logger;
643
659
  private readonly sessionStartTime;
@@ -700,6 +716,7 @@ interface StreamingSessionOptions {
700
716
  signal?: AbortSignal;
701
717
  defaultProviderOptions?: ProviderOptions;
702
718
  defaultTools?: ToolSet;
719
+ defaultGenerationOptions?: GenerationOptions;
703
720
  }
704
721
  declare class StreamingSession<TEvent extends {
705
722
  type: string;
@@ -1223,6 +1240,7 @@ declare abstract class BaseProvider implements Provider {
1223
1240
  abstract withLogger(logger: Logger): Provider;
1224
1241
  abstract withPricing(pricing: ProviderPricing): Provider;
1225
1242
  abstract withDefaultOptions(options: Record<string, unknown>): Provider;
1243
+ abstract withDefaultGenerationOptions(options: GenerationOptions): Provider;
1226
1244
  streamingExecution<TEvent extends {
1227
1245
  type: string;
1228
1246
  }>(generator: (session: StreamingSession<TEvent>) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>>>, options?: ExecutionOptions): StreamingExecution<TEvent>;
@@ -1233,4 +1251,4 @@ declare abstract class BaseProvider implements Provider {
1233
1251
  simpleExecution<TResult>(fn: (session: SimpleSession) => Promise<TResult>, options?: ExecutionOptions): SimpleExecution<TResult>;
1234
1252
  }
1235
1253
 
1236
- export { isFileSourceBase64 as $, type LLMCallStartEvent as A, BaseProvider as B, type CalculateCostParams as C, type DistributiveOmit as D, type ErrorEvent as E, type FileSource as F, type LLMCallEndEvent as G, type ExecutionStartEvent as H, type ExecutionEmitEvent as I, type ExecutionDoneEvent as J, type ExecutionErrorEvent as K, type Logger as L, type ModelPricing as M, noopLogger as N, createLogger as O, type ProviderType as P, type Provider as Q, type ReservedEventType as R, type StreamingExecution as S, type FileSourcePath as T, type UploadedFile as U, type FileSourceData as V, type FileSourceBase64 as W, type FileSourceUrl as X, isFileSource as Y, isFileSourcePath as Z, isFileSourceData as _, type PricingConfig as a, isFileSourceUrl as a0, type SimpleSessionOptions as a1, createStreamingSession as a2, type StreamingSessionOptions as a3, type CreateStreamingSessionOptions as a4, type StreamingSessionInternal as a5, type OutputSpec as a6, type DefaultOutput as a7, type InferOutputComplete as a8, type GenerateTextResultTyped as a9, type StreamTextResultTyped as aa, type GenerateTextParams as ab, type GenerateObjectParams as ac, type ToolCallSummary as ad, type LLMCallType as ae, type LLMCallRecord as af, type AdditionalCost as ag, SessionSummary as ah, type SessionSummaryJSON as ai, type ExecutionSession as aj, type DoneMetadata as ak, type ProviderPricing as b, type CostResult as c, StreamingSession as d, type SessionStreamGeneratorFn as e, type SessionEvent as f, type StreamingResult as g, type ExtractResult as h, type SimpleExecution as i, SimpleSession as j, type SimpleResult as k, type ExecutionStatus as l, type CompletionEvent as m, type StreamTextParams as n, type FileCache as o, type FileManager as p, type FileManagerOptions as q, type Execution as r, type ExecutionOptions as s, type ExecutionResult as t, type SessionEventInput as u, type EmittableEventInput as v, type EventMetrics as w, type ExecutionMetadata as x, type LogLevel as y, type LLMCallLogType as z };
1254
+ export { isFileSourceData as $, type LLMCallStartEvent as A, BaseProvider as B, type CalculateCostParams as C, type DistributiveOmit as D, type ErrorEvent as E, type FileSource as F, type GenerationOptions as G, type LLMCallEndEvent as H, type ExecutionStartEvent as I, type ExecutionEmitEvent as J, type ExecutionDoneEvent as K, type Logger as L, type ModelPricing as M, type ExecutionErrorEvent as N, noopLogger as O, type ProviderType as P, createLogger as Q, type ReservedEventType as R, type StreamingExecution as S, type Provider as T, type UploadedFile as U, type FileSourcePath as V, type FileSourceData as W, type FileSourceBase64 as X, type FileSourceUrl as Y, isFileSource as Z, isFileSourcePath as _, type PricingConfig as a, isFileSourceBase64 as a0, isFileSourceUrl as a1, type SimpleSessionOptions as a2, createStreamingSession as a3, type StreamingSessionOptions as a4, type CreateStreamingSessionOptions as a5, type StreamingSessionInternal as a6, type OutputSpec as a7, type DefaultOutput as a8, type InferOutputComplete as a9, type GenerateTextResultTyped as aa, type StreamTextResultTyped as ab, type GenerateTextParams as ac, type GenerateObjectParams as ad, type ToolCallSummary as ae, type LLMCallType as af, type LLMCallRecord as ag, type AdditionalCost as ah, SessionSummary as ai, type SessionSummaryJSON as aj, type ExecutionSession as ak, type DoneMetadata as al, type ProviderPricing as b, type CostResult as c, StreamingSession as d, type SessionStreamGeneratorFn as e, type SessionEvent as f, type StreamingResult as g, type ExtractResult as h, type SimpleExecution as i, SimpleSession as j, type SimpleResult as k, type ExecutionStatus as l, type CompletionEvent as m, type StreamTextParams as n, type FileCache as o, type FileManager as p, type FileManagerOptions as q, type Execution as r, type ExecutionOptions as s, type ExecutionResult as t, type SessionEventInput as u, type EmittableEventInput as v, type EventMetrics as w, type ExecutionMetadata as x, type LogLevel as y, type LLMCallLogType as z };
@@ -1,4 +1,4 @@
1
- import { LanguageModelUsage, ToolSet, generateText, streamText, generateObject, FilePart, ImagePart, LanguageModel } from 'ai';
1
+ import { LanguageModelUsage, CallSettings, ToolSet, generateText, streamText, generateObject, FilePart, ImagePart, LanguageModel } from 'ai';
2
2
  import * as zod from 'zod';
3
3
 
4
4
  /**
@@ -142,6 +142,11 @@ interface CostResult {
142
142
  cachedInputCost: number;
143
143
  }
144
144
 
145
+ /**
146
+ * Standard AI SDK generation parameters that can be set as defaults at the Provider level.
147
+ * Per-call parameters override these defaults via simple spread merge.
148
+ */
149
+ type GenerationOptions = Pick<CallSettings, 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed'>;
145
150
  /**
146
151
  * Structural interface matching AI SDK's internal Output<OUTPUT, PARTIAL>.
147
152
  *
@@ -578,6 +583,11 @@ interface Provider {
578
583
  * The actual options type depends on the provider (Google, OpenAI, etc.).
579
584
  */
580
585
  withDefaultOptions(options: Record<string, unknown>): Provider;
586
+ /**
587
+ * Set default generation options (standard AI SDK parameters) for all LLM calls.
588
+ * Per-call parameters override these defaults.
589
+ */
590
+ withDefaultGenerationOptions(options: GenerationOptions): Provider;
581
591
  streamingExecution<TEvent extends {
582
592
  type: string;
583
593
  }>(generator: (session: StreamingSession<TEvent>) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>>>, options?: ExecutionOptions): StreamingExecution<TEvent>;
@@ -630,6 +640,11 @@ interface SimpleSessionOptions {
630
640
  * These will be merged with per-call tools (per-call takes precedence).
631
641
  */
632
642
  defaultTools?: ToolSet;
643
+ /**
644
+ * Default generation options (standard AI SDK parameters) for all LLM calls.
645
+ * Per-call parameters override these defaults via simple spread.
646
+ */
647
+ defaultGenerationOptions?: GenerationOptions;
633
648
  }
634
649
  declare class SimpleSession {
635
650
  private readonly defaultLanguageModel;
@@ -638,6 +653,7 @@ declare class SimpleSession {
638
653
  private readonly providerPricing;
639
654
  private readonly defaultProviderOptions;
640
655
  private readonly defaultTools;
656
+ private readonly defaultGenerationOptions;
641
657
  private readonly _fileManager;
642
658
  private readonly logger;
643
659
  private readonly sessionStartTime;
@@ -700,6 +716,7 @@ interface StreamingSessionOptions {
700
716
  signal?: AbortSignal;
701
717
  defaultProviderOptions?: ProviderOptions;
702
718
  defaultTools?: ToolSet;
719
+ defaultGenerationOptions?: GenerationOptions;
703
720
  }
704
721
  declare class StreamingSession<TEvent extends {
705
722
  type: string;
@@ -1223,6 +1240,7 @@ declare abstract class BaseProvider implements Provider {
1223
1240
  abstract withLogger(logger: Logger): Provider;
1224
1241
  abstract withPricing(pricing: ProviderPricing): Provider;
1225
1242
  abstract withDefaultOptions(options: Record<string, unknown>): Provider;
1243
+ abstract withDefaultGenerationOptions(options: GenerationOptions): Provider;
1226
1244
  streamingExecution<TEvent extends {
1227
1245
  type: string;
1228
1246
  }>(generator: (session: StreamingSession<TEvent>) => AsyncGenerator<SessionEvent<TEvent>, SessionEvent<TEvent> | Promise<SessionEvent<TEvent>>>, options?: ExecutionOptions): StreamingExecution<TEvent>;
@@ -1233,4 +1251,4 @@ declare abstract class BaseProvider implements Provider {
1233
1251
  simpleExecution<TResult>(fn: (session: SimpleSession) => Promise<TResult>, options?: ExecutionOptions): SimpleExecution<TResult>;
1234
1252
  }
1235
1253
 
1236
- export { isFileSourceBase64 as $, type LLMCallStartEvent as A, BaseProvider as B, type CalculateCostParams as C, type DistributiveOmit as D, type ErrorEvent as E, type FileSource as F, type LLMCallEndEvent as G, type ExecutionStartEvent as H, type ExecutionEmitEvent as I, type ExecutionDoneEvent as J, type ExecutionErrorEvent as K, type Logger as L, type ModelPricing as M, noopLogger as N, createLogger as O, type ProviderType as P, type Provider as Q, type ReservedEventType as R, type StreamingExecution as S, type FileSourcePath as T, type UploadedFile as U, type FileSourceData as V, type FileSourceBase64 as W, type FileSourceUrl as X, isFileSource as Y, isFileSourcePath as Z, isFileSourceData as _, type PricingConfig as a, isFileSourceUrl as a0, type SimpleSessionOptions as a1, createStreamingSession as a2, type StreamingSessionOptions as a3, type CreateStreamingSessionOptions as a4, type StreamingSessionInternal as a5, type OutputSpec as a6, type DefaultOutput as a7, type InferOutputComplete as a8, type GenerateTextResultTyped as a9, type StreamTextResultTyped as aa, type GenerateTextParams as ab, type GenerateObjectParams as ac, type ToolCallSummary as ad, type LLMCallType as ae, type LLMCallRecord as af, type AdditionalCost as ag, SessionSummary as ah, type SessionSummaryJSON as ai, type ExecutionSession as aj, type DoneMetadata as ak, type ProviderPricing as b, type CostResult as c, StreamingSession as d, type SessionStreamGeneratorFn as e, type SessionEvent as f, type StreamingResult as g, type ExtractResult as h, type SimpleExecution as i, SimpleSession as j, type SimpleResult as k, type ExecutionStatus as l, type CompletionEvent as m, type StreamTextParams as n, type FileCache as o, type FileManager as p, type FileManagerOptions as q, type Execution as r, type ExecutionOptions as s, type ExecutionResult as t, type SessionEventInput as u, type EmittableEventInput as v, type EventMetrics as w, type ExecutionMetadata as x, type LogLevel as y, type LLMCallLogType as z };
1254
+ export { isFileSourceData as $, type LLMCallStartEvent as A, BaseProvider as B, type CalculateCostParams as C, type DistributiveOmit as D, type ErrorEvent as E, type FileSource as F, type GenerationOptions as G, type LLMCallEndEvent as H, type ExecutionStartEvent as I, type ExecutionEmitEvent as J, type ExecutionDoneEvent as K, type Logger as L, type ModelPricing as M, type ExecutionErrorEvent as N, noopLogger as O, type ProviderType as P, createLogger as Q, type ReservedEventType as R, type StreamingExecution as S, type Provider as T, type UploadedFile as U, type FileSourcePath as V, type FileSourceData as W, type FileSourceBase64 as X, type FileSourceUrl as Y, isFileSource as Z, isFileSourcePath as _, type PricingConfig as a, isFileSourceBase64 as a0, isFileSourceUrl as a1, type SimpleSessionOptions as a2, createStreamingSession as a3, type StreamingSessionOptions as a4, type CreateStreamingSessionOptions as a5, type StreamingSessionInternal as a6, type OutputSpec as a7, type DefaultOutput as a8, type InferOutputComplete as a9, type GenerateTextResultTyped as aa, type StreamTextResultTyped as ab, type GenerateTextParams as ac, type GenerateObjectParams as ad, type ToolCallSummary as ae, type LLMCallType as af, type LLMCallRecord as ag, type AdditionalCost as ah, SessionSummary as ai, type SessionSummaryJSON as aj, type ExecutionSession as ak, type DoneMetadata as al, type ProviderPricing as b, type CostResult as c, StreamingSession as d, type SessionStreamGeneratorFn as e, type SessionEvent as f, type StreamingResult as g, type ExtractResult as h, type SimpleExecution as i, SimpleSession as j, type SimpleResult as k, type ExecutionStatus as l, type CompletionEvent as m, type StreamTextParams as n, type FileCache as o, type FileManager as p, type FileManagerOptions as q, type Execution as r, type ExecutionOptions as s, type ExecutionResult as t, type SessionEventInput as u, type EmittableEventInput as v, type EventMetrics as w, type ExecutionMetadata as x, type LogLevel as y, type LLMCallLogType as z };
package/dist/index.cjs CHANGED
@@ -9,7 +9,6 @@ var yaml = require('yaml');
9
9
  var crypto = require('crypto');
10
10
  var google = require('@ai-sdk/google');
11
11
  var genai = require('@google/genai');
12
- var merge = require('lodash/merge');
13
12
  var openai = require('@ai-sdk/openai');
14
13
 
15
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -36,7 +35,6 @@ var Handlebars__default = /*#__PURE__*/_interopDefault(Handlebars);
36
35
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
37
36
  var path3__namespace = /*#__PURE__*/_interopNamespace(path3);
38
37
  var yaml__namespace = /*#__PURE__*/_interopNamespace(yaml);
39
- var merge__default = /*#__PURE__*/_interopDefault(merge);
40
38
 
41
39
  // src/errors/utils.ts
42
40
  function wrapAsError(error, ErrorClass, options) {
@@ -1405,11 +1403,9 @@ function parsePromptYaml(content, promptId) {
1405
1403
  try {
1406
1404
  parsed = yaml__namespace.parse(content);
1407
1405
  } catch (error) {
1408
- throw new PromptInvalidFormatError(
1409
- promptId,
1410
- `Invalid YAML: ${toErrorMessage(error)}`,
1411
- { cause: toErrorCause(error) }
1412
- );
1406
+ throw new PromptInvalidFormatError(promptId, `Invalid YAML: ${toErrorMessage(error)}`, {
1407
+ cause: toErrorCause(error)
1408
+ });
1413
1409
  }
1414
1410
  if (!parsed || typeof parsed !== "object") {
1415
1411
  throw new PromptInvalidFormatError(promptId, "Expected YAML object");
@@ -1495,17 +1491,17 @@ var FilePromptRepository = class {
1495
1491
  }
1496
1492
  throw new PromptIOError("read", filePath, { cause: toErrorCause(error) });
1497
1493
  }
1498
- const promptContent = this.parseContent(content, id);
1499
- if (promptContent.id !== id || promptContent.version !== version) {
1494
+ const promptTemplate = this.parseContent(content, id);
1495
+ if (promptTemplate.id !== id || promptTemplate.version !== version) {
1500
1496
  throw new PromptInvalidFormatError(
1501
1497
  id,
1502
- `File content mismatch: expected id='${id}' version='${version}', got id='${promptContent.id}' version='${promptContent.version}'`
1498
+ `File content mismatch: expected id='${id}' version='${version}', got id='${promptTemplate.id}' version='${promptTemplate.version}'`
1503
1499
  );
1504
1500
  }
1505
1501
  if (this.cacheEnabled) {
1506
- this.contentCache.set(cacheKey, promptContent);
1502
+ this.contentCache.set(cacheKey, promptTemplate);
1507
1503
  }
1508
- return promptContent;
1504
+ return promptTemplate;
1509
1505
  }
1510
1506
  let files;
1511
1507
  try {
@@ -2011,6 +2007,23 @@ var GoogleFileManager = class {
2011
2007
  }
2012
2008
  };
2013
2009
 
2010
+ // src/utils/deep-merge.ts
2011
+ function isPlainObject(value) {
2012
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2013
+ }
2014
+ function deepMerge(...sources) {
2015
+ const result = {};
2016
+ for (const source of sources) {
2017
+ if (!source) continue;
2018
+ for (const key of Object.keys(source)) {
2019
+ const existing = result[key];
2020
+ const incoming = source[key];
2021
+ result[key] = isPlainObject(existing) && isPlainObject(incoming) ? deepMerge(existing, incoming) : incoming;
2022
+ }
2023
+ }
2024
+ return result;
2025
+ }
2026
+
2014
2027
  // src/session/usage-extractors.ts
2015
2028
  function mergeUsages(usages) {
2016
2029
  if (usages.length === 0) {
@@ -2279,6 +2292,7 @@ var SimpleSession = class {
2279
2292
  providerPricing;
2280
2293
  defaultProviderOptions;
2281
2294
  defaultTools;
2295
+ defaultGenerationOptions;
2282
2296
  _fileManager;
2283
2297
  logger;
2284
2298
  sessionStartTime;
@@ -2293,6 +2307,7 @@ var SimpleSession = class {
2293
2307
  this.providerPricing = options.providerPricing;
2294
2308
  this.defaultProviderOptions = options.defaultProviderOptions;
2295
2309
  this.defaultTools = options.defaultTools;
2310
+ this.defaultGenerationOptions = options.defaultGenerationOptions;
2296
2311
  this._fileManager = options.fileManager;
2297
2312
  this.logger = options.logger ?? noopLogger;
2298
2313
  this.sessionStartTime = options.startTime ?? Date.now();
@@ -2329,7 +2344,7 @@ var SimpleSession = class {
2329
2344
  const { model: requestedModel, providerOptions, tools, ...restParams } = params;
2330
2345
  const languageModel = this.getModel(requestedModel);
2331
2346
  const modelId = this.extractModelId(languageModel);
2332
- const mergedProviderOptions = this.defaultProviderOptions || providerOptions ? merge__default.default({}, this.defaultProviderOptions ?? {}, providerOptions ?? {}) : void 0;
2347
+ const mergedProviderOptions = this.defaultProviderOptions || providerOptions ? deepMerge(this.defaultProviderOptions ?? {}, providerOptions ?? {}) : void 0;
2333
2348
  const mergedTools = this.defaultTools || tools ? { ...this.defaultTools, ...tools } : void 0;
2334
2349
  this.logger.onLLMCallStart?.({
2335
2350
  type: "llm_call_start",
@@ -2340,6 +2355,7 @@ var SimpleSession = class {
2340
2355
  });
2341
2356
  try {
2342
2357
  const result = await ai.generateText({
2358
+ ...this.defaultGenerationOptions,
2343
2359
  ...restParams,
2344
2360
  tools: mergedTools,
2345
2361
  providerOptions: mergedProviderOptions,
@@ -2390,7 +2406,7 @@ var SimpleSession = class {
2390
2406
  const { model: requestedModel, providerOptions, tools, ...restParams } = params;
2391
2407
  const languageModel = this.getModel(requestedModel);
2392
2408
  const modelId = this.extractModelId(languageModel);
2393
- const mergedProviderOptions = this.defaultProviderOptions || providerOptions ? merge__default.default({}, this.defaultProviderOptions ?? {}, providerOptions ?? {}) : void 0;
2409
+ const mergedProviderOptions = this.defaultProviderOptions || providerOptions ? deepMerge(this.defaultProviderOptions ?? {}, providerOptions ?? {}) : void 0;
2394
2410
  const mergedTools = this.defaultTools || tools ? { ...this.defaultTools, ...tools } : void 0;
2395
2411
  this.logger.onLLMCallStart?.({
2396
2412
  type: "llm_call_start",
@@ -2400,6 +2416,7 @@ var SimpleSession = class {
2400
2416
  request: { params: restParams }
2401
2417
  });
2402
2418
  const result = ai.streamText({
2419
+ ...this.defaultGenerationOptions,
2403
2420
  ...restParams,
2404
2421
  tools: mergedTools,
2405
2422
  providerOptions: mergedProviderOptions,
@@ -2567,7 +2584,8 @@ var StreamingSession = class extends SimpleSession {
2567
2584
  startTime: options.startTime,
2568
2585
  signal: options.signal,
2569
2586
  defaultProviderOptions: options.defaultProviderOptions,
2570
- defaultTools: options.defaultTools
2587
+ defaultTools: options.defaultTools,
2588
+ defaultGenerationOptions: options.defaultGenerationOptions
2571
2589
  });
2572
2590
  this.lastEventTime = this._startTime;
2573
2591
  this._logger.onExecutionStart?.({
@@ -2699,59 +2717,21 @@ function createStreamingSession(options) {
2699
2717
 
2700
2718
  // src/provider/google/factory.ts
2701
2719
  var GoogleProvider = class _GoogleProvider extends BaseProvider {
2702
- constructor(apiKey, defaultModelId, logger, safetySettings, pricingConfig, defaultOptions, searchEnabled = false, urlContextEnabled = false, fileCache) {
2720
+ constructor(config) {
2703
2721
  super();
2704
- this.apiKey = apiKey;
2705
- this.defaultModelId = defaultModelId;
2706
- this.logger = logger;
2707
- this.safetySettings = safetySettings;
2708
- this.pricingConfig = pricingConfig;
2709
- this.defaultOptions = defaultOptions;
2710
- this.searchEnabled = searchEnabled;
2711
- this.urlContextEnabled = urlContextEnabled;
2712
- this.fileCache = fileCache;
2713
- this.google = google.createGoogleGenerativeAI({ apiKey });
2722
+ this.config = config;
2723
+ this.google = google.createGoogleGenerativeAI({ apiKey: config.apiKey });
2714
2724
  }
2715
2725
  google;
2716
2726
  withDefaultModel(modelId) {
2717
- return new _GoogleProvider(
2718
- this.apiKey,
2719
- modelId,
2720
- this.logger,
2721
- this.safetySettings,
2722
- this.pricingConfig,
2723
- this.defaultOptions,
2724
- this.searchEnabled,
2725
- this.urlContextEnabled,
2726
- this.fileCache
2727
- );
2727
+ return new _GoogleProvider({ ...this.config, defaultModelId: modelId });
2728
2728
  }
2729
2729
  withLogger(newLogger) {
2730
- return new _GoogleProvider(
2731
- this.apiKey,
2732
- this.defaultModelId,
2733
- newLogger,
2734
- this.safetySettings,
2735
- this.pricingConfig,
2736
- this.defaultOptions,
2737
- this.searchEnabled,
2738
- this.urlContextEnabled,
2739
- this.fileCache
2740
- );
2730
+ return new _GoogleProvider({ ...this.config, logger: newLogger });
2741
2731
  }
2742
2732
  withPricing(pricing) {
2743
2733
  validateProviderPricing(pricing, "google");
2744
- return new _GoogleProvider(
2745
- this.apiKey,
2746
- this.defaultModelId,
2747
- this.logger,
2748
- this.safetySettings,
2749
- pricing,
2750
- this.defaultOptions,
2751
- this.searchEnabled,
2752
- this.urlContextEnabled,
2753
- this.fileCache
2754
- );
2734
+ return new _GoogleProvider({ ...this.config, pricingConfig: pricing });
2755
2735
  }
2756
2736
  /**
2757
2737
  * Set default provider-specific options for all LLM calls.
@@ -2767,17 +2747,10 @@ var GoogleProvider = class _GoogleProvider extends BaseProvider {
2767
2747
  * ```
2768
2748
  */
2769
2749
  withDefaultOptions(options) {
2770
- return new _GoogleProvider(
2771
- this.apiKey,
2772
- this.defaultModelId,
2773
- this.logger,
2774
- this.safetySettings,
2775
- this.pricingConfig,
2776
- options,
2777
- this.searchEnabled,
2778
- this.urlContextEnabled,
2779
- this.fileCache
2780
- );
2750
+ return new _GoogleProvider({ ...this.config, defaultOptions: options });
2751
+ }
2752
+ withDefaultGenerationOptions(options) {
2753
+ return new _GoogleProvider({ ...this.config, defaultGenOptions: options });
2781
2754
  }
2782
2755
  /**
2783
2756
  * Enable Google Search grounding for all LLM calls.
@@ -2791,17 +2764,7 @@ var GoogleProvider = class _GoogleProvider extends BaseProvider {
2791
2764
  * ```
2792
2765
  */
2793
2766
  withSearchEnabled() {
2794
- return new _GoogleProvider(
2795
- this.apiKey,
2796
- this.defaultModelId,
2797
- this.logger,
2798
- this.safetySettings,
2799
- this.pricingConfig,
2800
- this.defaultOptions,
2801
- true,
2802
- this.urlContextEnabled,
2803
- this.fileCache
2804
- );
2767
+ return new _GoogleProvider({ ...this.config, searchEnabled: true });
2805
2768
  }
2806
2769
  /**
2807
2770
  * Enable URL Context grounding for all LLM calls.
@@ -2815,17 +2778,7 @@ var GoogleProvider = class _GoogleProvider extends BaseProvider {
2815
2778
  * ```
2816
2779
  */
2817
2780
  withUrlContextEnabled() {
2818
- return new _GoogleProvider(
2819
- this.apiKey,
2820
- this.defaultModelId,
2821
- this.logger,
2822
- this.safetySettings,
2823
- this.pricingConfig,
2824
- this.defaultOptions,
2825
- this.searchEnabled,
2826
- true,
2827
- this.fileCache
2828
- );
2781
+ return new _GoogleProvider({ ...this.config, urlContextEnabled: true });
2829
2782
  }
2830
2783
  /**
2831
2784
  * Set a file cache for reusing uploaded files across sessions.
@@ -2844,33 +2797,25 @@ var GoogleProvider = class _GoogleProvider extends BaseProvider {
2844
2797
  * ```
2845
2798
  */
2846
2799
  withFileCache(cache) {
2847
- return new _GoogleProvider(
2848
- this.apiKey,
2849
- this.defaultModelId,
2850
- this.logger,
2851
- this.safetySettings,
2852
- this.pricingConfig,
2853
- this.defaultOptions,
2854
- this.searchEnabled,
2855
- this.urlContextEnabled,
2856
- cache ?? new InMemoryFileCache()
2857
- );
2800
+ return new _GoogleProvider({ ...this.config, fileCache: cache ?? new InMemoryFileCache() });
2858
2801
  }
2859
2802
  getSessionConfig() {
2803
+ const { searchEnabled, urlContextEnabled } = this.config;
2860
2804
  const defaultTools = {
2861
- ...this.searchEnabled && { google_search: this.google.tools.googleSearch({}) },
2862
- ...this.urlContextEnabled && { url_context: this.google.tools.urlContext({}) }
2805
+ ...searchEnabled && { google_search: this.google.tools.googleSearch({}) },
2806
+ ...urlContextEnabled && { url_context: this.google.tools.urlContext({}) }
2863
2807
  };
2864
- const hasDefaultTools = this.searchEnabled || this.urlContextEnabled;
2808
+ const hasDefaultTools = searchEnabled || urlContextEnabled;
2865
2809
  return {
2866
- defaultLanguageModel: this.defaultModelId ? this.createModel(this.defaultModelId) : null,
2810
+ defaultLanguageModel: this.config.defaultModelId ? this.createModel(this.config.defaultModelId) : null,
2867
2811
  modelFactory: (modelId) => this.createModel(modelId),
2868
2812
  providerType: "google",
2869
- providerPricing: this.pricingConfig,
2870
- fileManager: new GoogleFileManager(this.apiKey, { cache: this.fileCache }),
2871
- logger: this.logger,
2872
- defaultProviderOptions: this.defaultOptions ? { google: this.defaultOptions } : void 0,
2873
- defaultTools: hasDefaultTools ? defaultTools : void 0
2813
+ providerPricing: this.config.pricingConfig,
2814
+ fileManager: new GoogleFileManager(this.config.apiKey, { cache: this.config.fileCache }),
2815
+ logger: this.config.logger,
2816
+ defaultProviderOptions: this.config.defaultOptions ? { google: this.config.defaultOptions } : void 0,
2817
+ defaultTools: hasDefaultTools ? defaultTools : void 0,
2818
+ defaultGenerationOptions: this.config.defaultGenOptions
2874
2819
  };
2875
2820
  }
2876
2821
  createStreamingSession(signal) {
@@ -2884,75 +2829,42 @@ var GoogleProvider = class _GoogleProvider extends BaseProvider {
2884
2829
  * include the second parameter, but it's supported at runtime.
2885
2830
  */
2886
2831
  createModel(modelId) {
2887
- if (this.safetySettings) {
2888
- return this.google(modelId, { safetySettings: this.safetySettings });
2832
+ if (this.config.safetySettings) {
2833
+ return this.google(modelId, { safetySettings: this.config.safetySettings });
2889
2834
  }
2890
2835
  return this.google(modelId);
2891
2836
  }
2892
2837
  };
2893
2838
  function createGoogleProvider(config) {
2894
- return new GoogleProvider(
2895
- config.apiKey,
2896
- null,
2897
- // No default model - must be set with withDefaultModel()
2898
- noopLogger,
2899
- config.safetySettings
2900
- );
2839
+ return new GoogleProvider({
2840
+ apiKey: config.apiKey,
2841
+ defaultModelId: null,
2842
+ logger: noopLogger,
2843
+ safetySettings: config.safetySettings,
2844
+ searchEnabled: false,
2845
+ urlContextEnabled: false
2846
+ });
2901
2847
  }
2902
2848
  var OpenAIProvider = class _OpenAIProvider extends BaseProvider {
2903
- constructor(apiKey, defaultModelId, logger, baseURL, organization, pricingConfig, defaultOptions, fileCache) {
2849
+ constructor(config) {
2904
2850
  super();
2905
- this.apiKey = apiKey;
2906
- this.defaultModelId = defaultModelId;
2907
- this.logger = logger;
2908
- this.baseURL = baseURL;
2909
- this.organization = organization;
2910
- this.pricingConfig = pricingConfig;
2911
- this.defaultOptions = defaultOptions;
2912
- this.fileCache = fileCache;
2851
+ this.config = config;
2913
2852
  this.openai = openai.createOpenAI({
2914
- apiKey,
2915
- baseURL,
2916
- organization
2853
+ apiKey: config.apiKey,
2854
+ baseURL: config.baseURL,
2855
+ organization: config.organization
2917
2856
  });
2918
2857
  }
2919
2858
  openai;
2920
2859
  withDefaultModel(modelId) {
2921
- return new _OpenAIProvider(
2922
- this.apiKey,
2923
- modelId,
2924
- this.logger,
2925
- this.baseURL,
2926
- this.organization,
2927
- this.pricingConfig,
2928
- this.defaultOptions,
2929
- this.fileCache
2930
- );
2860
+ return new _OpenAIProvider({ ...this.config, defaultModelId: modelId });
2931
2861
  }
2932
2862
  withLogger(newLogger) {
2933
- return new _OpenAIProvider(
2934
- this.apiKey,
2935
- this.defaultModelId,
2936
- newLogger,
2937
- this.baseURL,
2938
- this.organization,
2939
- this.pricingConfig,
2940
- this.defaultOptions,
2941
- this.fileCache
2942
- );
2863
+ return new _OpenAIProvider({ ...this.config, logger: newLogger });
2943
2864
  }
2944
2865
  withPricing(pricing) {
2945
2866
  validateProviderPricing(pricing, "openai");
2946
- return new _OpenAIProvider(
2947
- this.apiKey,
2948
- this.defaultModelId,
2949
- this.logger,
2950
- this.baseURL,
2951
- this.organization,
2952
- pricing,
2953
- this.defaultOptions,
2954
- this.fileCache
2955
- );
2867
+ return new _OpenAIProvider({ ...this.config, pricingConfig: pricing });
2956
2868
  }
2957
2869
  /**
2958
2870
  * Set default provider-specific options for all LLM calls.
@@ -2969,16 +2881,10 @@ var OpenAIProvider = class _OpenAIProvider extends BaseProvider {
2969
2881
  * ```
2970
2882
  */
2971
2883
  withDefaultOptions(options) {
2972
- return new _OpenAIProvider(
2973
- this.apiKey,
2974
- this.defaultModelId,
2975
- this.logger,
2976
- this.baseURL,
2977
- this.organization,
2978
- this.pricingConfig,
2979
- options,
2980
- this.fileCache
2981
- );
2884
+ return new _OpenAIProvider({ ...this.config, defaultOptions: options });
2885
+ }
2886
+ withDefaultGenerationOptions(options) {
2887
+ return new _OpenAIProvider({ ...this.config, defaultGenOptions: options });
2982
2888
  }
2983
2889
  /**
2984
2890
  * Set a file cache for API consistency with GoogleProvider.
@@ -2991,26 +2897,18 @@ var OpenAIProvider = class _OpenAIProvider extends BaseProvider {
2991
2897
  * ```
2992
2898
  */
2993
2899
  withFileCache(cache) {
2994
- return new _OpenAIProvider(
2995
- this.apiKey,
2996
- this.defaultModelId,
2997
- this.logger,
2998
- this.baseURL,
2999
- this.organization,
3000
- this.pricingConfig,
3001
- this.defaultOptions,
3002
- cache
3003
- );
2900
+ return new _OpenAIProvider({ ...this.config, fileCache: cache });
3004
2901
  }
3005
2902
  getSessionConfig() {
3006
2903
  return {
3007
- defaultLanguageModel: this.defaultModelId ? this.openai(this.defaultModelId) : null,
2904
+ defaultLanguageModel: this.config.defaultModelId ? this.openai(this.config.defaultModelId) : null,
3008
2905
  modelFactory: (modelId) => this.openai(modelId),
3009
2906
  providerType: "openai",
3010
- providerPricing: this.pricingConfig,
2907
+ providerPricing: this.config.pricingConfig,
3011
2908
  fileManager: new NoOpFileManager(),
3012
- logger: this.logger,
3013
- defaultProviderOptions: this.defaultOptions ? { openai: this.defaultOptions } : void 0
2909
+ logger: this.config.logger,
2910
+ defaultProviderOptions: this.config.defaultOptions ? { openai: this.config.defaultOptions } : void 0,
2911
+ defaultGenerationOptions: this.config.defaultGenOptions
3014
2912
  };
3015
2913
  }
3016
2914
  createStreamingSession(signal) {
@@ -3021,14 +2919,13 @@ var OpenAIProvider = class _OpenAIProvider extends BaseProvider {
3021
2919
  }
3022
2920
  };
3023
2921
  function createOpenAIProvider(config) {
3024
- return new OpenAIProvider(
3025
- config.apiKey,
3026
- null,
3027
- // No default model - must be set with withDefaultModel()
3028
- noopLogger,
3029
- config.baseURL,
3030
- config.organization
3031
- );
2922
+ return new OpenAIProvider({
2923
+ apiKey: config.apiKey,
2924
+ defaultModelId: null,
2925
+ logger: noopLogger,
2926
+ baseURL: config.baseURL,
2927
+ organization: config.organization
2928
+ });
3032
2929
  }
3033
2930
 
3034
2931
  // src/validation/validation-history.ts