@happyvertical/ai 0.89.7 → 0.89.8

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,747 +0,0 @@
1
- import { n as AI_PROVIDER_TYPES } from "./types-sSecpd_N.js";
2
- import { t as createRateLimitedAI } from "./rate-limit-C2oPwLGI.js";
3
- import { a as normalizeBaseAIOptions, i as createObservedAI } from "./safety-ClfpyKEN.js";
4
- import { ApiError, ValidationError, loadEnvConfig } from "@happyvertical/utils";
5
- import OpenAI from "openai";
6
- //#region \0rolldown/runtime.js
7
- var __defProp = Object.defineProperty;
8
- var __exportAll = (all, no_symbols) => {
9
- let target = {};
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
14
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
15
- return target;
16
- };
17
- //#endregion
18
- //#region src/shared/client.ts
19
- /**
20
- * Type guard to check if options are for OpenAI client
21
- *
22
- * @param options - Options to check
23
- * @returns True if options are valid for OpenAI client
24
- */
25
- function isOpenAIClientOptions(options) {
26
- return options.type === "openai" && "apiKey" in options && !!options.apiKey;
27
- }
28
- /**
29
- * Type guard to check if value is an AI client instance
30
- *
31
- * @param value - Value to check
32
- * @returns True if value is an AI client instance
33
- */
34
- function isAIClientInstance(value) {
35
- return value instanceof AIClient;
36
- }
37
- /**
38
- * Base class for AI clients
39
- * Provides a common interface for different AI service providers
40
- */
41
- var AIClient = class {
42
- /**
43
- * Configuration options for this client
44
- */
45
- options;
46
- /**
47
- * Creates a new AIClient
48
- *
49
- * @param options - Client configuration options
50
- */
51
- constructor(options) {
52
- this.options = options;
53
- }
54
- /**
55
- * Sends a message to the AI
56
- * Base implementation returns a placeholder response
57
- *
58
- * @param text - Message text
59
- * @param options - Message options
60
- * @returns Promise resolving to a placeholder response
61
- */
62
- async message(_text, _options = { role: "user" }) {
63
- return "not a real ai message, this is the base class!";
64
- }
65
- /**
66
- * Factory method to create appropriate AI client based on options
67
- *
68
- * @param options - Client configuration options
69
- * @returns Promise resolving to an initialized AI client
70
- * @throws Error if client type is invalid
71
- */
72
- static async create(options) {
73
- if (isAIClientInstance(options)) return options;
74
- const clientOptions = options;
75
- if (isOpenAIClientOptions(clientOptions)) return OpenAIClient.create(clientOptions);
76
- const providedType = clientOptions.type;
77
- if (providedType && providedType !== "openai") {
78
- const { getAI } = await Promise.resolve().then(() => factory_exports);
79
- return await getAI(clientOptions);
80
- }
81
- if (providedType === "openai") throw new ValidationError("OpenAI API key is required but missing or empty", {
82
- supportedTypes: [...AI_PROVIDER_TYPES],
83
- providedType,
84
- hint: "Set OPENAI_API_KEY environment variable or pass apiKey in options"
85
- });
86
- throw new ValidationError("Invalid client type specified", {
87
- supportedTypes: [...AI_PROVIDER_TYPES],
88
- providedType
89
- });
90
- }
91
- /**
92
- * Gets a text completion from the AI
93
- * In base class, delegates to message method
94
- *
95
- * @param text - Input text for completion
96
- * @param options - Completion options
97
- * @returns Promise resolving to the completion result
98
- */
99
- textCompletion(text, options = { role: "user" }) {
100
- return this.message(text, options);
101
- }
102
- };
103
- /**
104
- * Creates an OpenAI client instance
105
- *
106
- * @param options - OpenAI configuration options
107
- * @returns Promise resolving to an OpenAI client
108
- */
109
- async function getOpenAI(options) {
110
- return new OpenAI({
111
- apiKey: options.apiKey,
112
- baseURL: options.baseUrl
113
- });
114
- }
115
- /**
116
- * Client implementation for the OpenAI API
117
- */
118
- var OpenAIClient = class OpenAIClient extends AIClient {
119
- /**
120
- * OpenAI client instance
121
- */
122
- openai;
123
- /**
124
- * Configuration options for this client
125
- */
126
- options;
127
- /**
128
- * Creates a new OpenAIClient
129
- *
130
- * @param options - OpenAI client configuration options
131
- */
132
- constructor(options) {
133
- super(options);
134
- this.options = options;
135
- }
136
- /**
137
- * Sends a message to OpenAI
138
- *
139
- * @param text - Message text
140
- * @param options - Message options
141
- * @returns Promise resolving to the OpenAI response
142
- */
143
- async message(text, options = { role: "user" }) {
144
- return await this.textCompletion(text, options);
145
- }
146
- /**
147
- * Factory method to create and initialize an OpenAIClient
148
- *
149
- * @param options - OpenAI client configuration options
150
- * @returns Promise resolving to an initialized OpenAIClient
151
- */
152
- static async create(options) {
153
- const client = new OpenAIClient(options);
154
- await client.initialize();
155
- return client;
156
- }
157
- /**
158
- * Initializes the OpenAI client
159
- */
160
- async initialize() {
161
- this.openai = new OpenAI({
162
- apiKey: this.options.apiKey,
163
- baseURL: this.options.baseUrl
164
- });
165
- }
166
- /**
167
- * Sends a text completion request to the OpenAI API
168
- *
169
- * @param message - The message to send
170
- * @param options - Configuration options for the completion request
171
- * @returns Promise resolving to the completion text
172
- * @throws Error if the OpenAI API response is invalid
173
- */
174
- async textCompletion(message, options = {}) {
175
- const { model = "gpt-4o", role = "user", history = [], name: _name, frequencyPenalty = 0, logitBias, logprobs = false, topLogprobs, maxTokens, n = 1, presencePenalty = 0, responseFormat, seed, stop, stream: _stream = false, temperature = 1, topProbability: topP = 1, tools, toolChoice, user, onProgress } = options;
176
- const messages = [...history, {
177
- role,
178
- content: message
179
- }];
180
- if (onProgress) {
181
- const stream = await this.openai.chat.completions.create({
182
- model,
183
- messages,
184
- stream: true,
185
- frequency_penalty: frequencyPenalty,
186
- logit_bias: logitBias,
187
- logprobs,
188
- top_logprobs: topLogprobs,
189
- max_tokens: maxTokens,
190
- n,
191
- presence_penalty: presencePenalty,
192
- response_format: responseFormat,
193
- seed,
194
- stop,
195
- temperature,
196
- top_p: topP,
197
- tools,
198
- tool_choice: toolChoice,
199
- user
200
- });
201
- let fullContent = "";
202
- for await (const chunk of stream) {
203
- const content = chunk.choices[0]?.delta?.content || "";
204
- fullContent += content;
205
- onProgress(content);
206
- }
207
- return fullContent;
208
- }
209
- const response = await this.openai.chat.completions.create({
210
- model,
211
- messages,
212
- frequency_penalty: frequencyPenalty,
213
- logit_bias: logitBias,
214
- logprobs,
215
- top_logprobs: topLogprobs,
216
- max_tokens: maxTokens,
217
- n,
218
- presence_penalty: presencePenalty,
219
- response_format: responseFormat,
220
- seed,
221
- stop,
222
- stream: false,
223
- temperature,
224
- top_p: topP,
225
- tools,
226
- tool_choice: toolChoice,
227
- user
228
- });
229
- const choice = response.choices[0];
230
- if (!choice || !choice.message || !choice.message.content) throw new ApiError("Invalid response from OpenAI API: Missing content", {
231
- model,
232
- responseId: response.id,
233
- choices: response.choices?.length || 0,
234
- hasChoice: !!choice,
235
- hasMessage: !!choice?.message,
236
- hasContent: !!choice?.message?.content
237
- });
238
- return choice.message.content;
239
- }
240
- };
241
- /**
242
- * Factory function to create and initialize an appropriate AI client
243
- * Delegates to the modern getAI() factory for all provider types
244
- *
245
- * @param options - Client configuration options
246
- * @returns Promise resolving to an initialized AI client
247
- * @throws Error if client type is invalid
248
- */
249
- async function getAIClient(options) {
250
- const { getAI } = await Promise.resolve().then(() => factory_exports);
251
- return await getAI(options);
252
- }
253
- //#endregion
254
- //#region src/shared/factory.ts
255
- /**
256
- * Universal factory functions for creating AI provider instances
257
- * Works in both browser and Node.js environments
258
- */
259
- var factory_exports = /* @__PURE__ */ __exportAll({
260
- getAI: () => getAI,
261
- getAIAuto: () => getAIAuto
262
- });
263
- /**
264
- * Type guards for provider options
265
- */
266
- /**
267
- * Checks if the options are for OpenAI provider
268
- * @param options - The AI provider options to check
269
- * @returns True if options are for OpenAI provider (including default case)
270
- */
271
- function isOpenAIOptions(options) {
272
- return !options.type || options.type === "openai";
273
- }
274
- /**
275
- * Checks if the options are for LiteLLM provider
276
- * @param options - The AI provider options to check
277
- * @returns True if options are for LiteLLM provider
278
- */
279
- function isLiteLLMOptions(options) {
280
- return options.type === "litellm";
281
- }
282
- /**
283
- * Checks if the options are for Bifrost provider
284
- * @param options - The AI provider options to check
285
- * @returns True if options are for Bifrost provider
286
- */
287
- function isBifrostOptions(options) {
288
- return options.type === "bifrost";
289
- }
290
- /**
291
- * Checks if the options are for Ollama provider
292
- * @param options - The AI provider options to check
293
- * @returns True if options are for Ollama provider
294
- */
295
- function isOllamaOptions(options) {
296
- return options.type === "ollama";
297
- }
298
- /**
299
- * Checks if the options are for Google Gemini provider
300
- * @param options - The AI provider options to check
301
- * @returns True if options are for Gemini provider
302
- */
303
- function isGeminiOptions(options) {
304
- return options.type === "gemini";
305
- }
306
- /**
307
- * Checks if the options are for Anthropic Claude provider
308
- * @param options - The AI provider options to check
309
- * @returns True if options are for Anthropic provider
310
- */
311
- function isAnthropicOptions(options) {
312
- return options.type === "anthropic";
313
- }
314
- /**
315
- * Checks if the options are for Hugging Face provider
316
- * @param options - The AI provider options to check
317
- * @returns True if options are for Hugging Face provider
318
- */
319
- function isHuggingFaceOptions(options) {
320
- return options.type === "huggingface";
321
- }
322
- /**
323
- * Checks if the options are for AWS Bedrock provider
324
- * @param options - The AI provider options to check
325
- * @returns True if options are for Bedrock provider
326
- */
327
- function isBedrockOptions(options) {
328
- return options.type === "bedrock";
329
- }
330
- /**
331
- * Checks if the options are for Claude CLI provider
332
- * @param options - The AI provider options to check
333
- * @returns True if options are for Claude CLI provider
334
- */
335
- function isClaudeCliOptions(options) {
336
- return options.type === "claude-cli";
337
- }
338
- /**
339
- * Checks if the options are for Qwen3-TTS provider
340
- * @param options - The AI provider options to check
341
- * @returns True if options are for Qwen3-TTS provider
342
- */
343
- function isQwen3TTSOptions(options) {
344
- return options.type === "qwen3-tts";
345
- }
346
- /**
347
- * Checks if the options are for the OpenAI-compatible video-generation provider
348
- * @param options - The AI provider options to check
349
- * @returns True if options are for the openai-compat-video provider
350
- */
351
- function isOpenAICompatVideoOptions(options) {
352
- return options.type === "openai-compat-video";
353
- }
354
- /**
355
- * Checks if the options are for the BytePlus ModelArk (Seedance) provider
356
- * @param options - The AI provider options to check
357
- * @returns True if options are for the byteplus-modelark provider
358
- */
359
- function isByteplusModelArkOptions(options) {
360
- return options.type === "byteplus-modelark";
361
- }
362
- /** Checks if options select Seevio's native Seedance task API. */
363
- function isSeevioOptions(options) {
364
- return options.type === "seevio";
365
- }
366
- /**
367
- * Creates an AI provider instance based on the provided options.
368
- * Universal version that works in both browser and Node.js environments.
369
- *
370
- * Supports environment variable configuration using the pattern:
371
- * - HAVE_AI_PROVIDER → provider type (string)
372
- * - HAVE_AI_MODEL → defaultModel (string)
373
- * - HAVE_AI_TIMEOUT → timeout (number)
374
- * - HAVE_AI_MAX_RETRIES → maxRetries (number)
375
- * - HAVE_AI_API_KEY → apiKey (string) - fallback if provider-specific key not set
376
- * - HAVE_AI_BASE_URL → baseUrl (string)
377
- *
378
- * User-provided options always take precedence over environment variables.
379
- *
380
- * Accepts both GetAIOptions (provider-specific options with literal types)
381
- * and AIClientOptions (legacy interface with generic string type) for
382
- * backward compatibility with existing code.
383
- *
384
- * @param options - Configuration options for the AI provider. Can be GetAIOptions or AIClientOptions.
385
- * @returns Promise resolving to an AI provider instance that implements the AIInterface
386
- * @throws {ValidationError} When the provider type is unsupported or invalid
387
- *
388
- * @example
389
- * ```typescript
390
- * // Create OpenAI client with explicit options
391
- * const openai = await getAI({
392
- * type: 'openai',
393
- * apiKey: process.env.OPENAI_API_KEY!,
394
- * defaultModel: 'gpt-4o'
395
- * });
396
- *
397
- * // Or use environment variables (HAVE_AI_PROVIDER=openai, HAVE_AI_API_KEY=sk-...)
398
- * const client = await getAI({});
399
- *
400
- * // Create Anthropic client
401
- * const anthropic = await getAI({
402
- * type: 'anthropic',
403
- * apiKey: process.env.ANTHROPIC_API_KEY!,
404
- * defaultModel: 'claude-3-5-sonnet-20241022'
405
- * });
406
- *
407
- * // Works with AIClientOptions (legacy interface)
408
- * const clientOptions: AIClientOptions = { type: 'openai', apiKey: '...' };
409
- * const legacy = await getAI(clientOptions);
410
- * ```
411
- */
412
- async function getAI(options = {}) {
413
- options = loadEnvConfig(options, {
414
- packageName: "ai",
415
- schema: {
416
- provider: "string",
417
- type: "string",
418
- model: "string",
419
- defaultModel: "string",
420
- timeout: "number",
421
- maxRetries: "number",
422
- apiKey: "string",
423
- baseUrl: "string",
424
- adminApiKey: "string",
425
- adminBaseUrl: "string",
426
- adminUrl: "string",
427
- adminUser: "string",
428
- adminUsername: "string",
429
- adminPassword: "string"
430
- }
431
- });
432
- if ("provider" in options && !options.type) options.type = options.provider;
433
- if ("model" in options && !options.defaultModel) options.defaultModel = options.model;
434
- options = normalizeBaseAIOptions(options);
435
- let client;
436
- if (isOpenAIOptions(options)) {
437
- const { OpenAIProvider } = await import("./openai-BuwvBruA.js");
438
- client = new OpenAIProvider(options);
439
- } else if (isLiteLLMOptions(options)) {
440
- const { LiteLLMProvider } = await import("./litellm-nOCNI7Vd.js");
441
- client = new LiteLLMProvider(options);
442
- } else if (isBifrostOptions(options)) {
443
- const { BifrostProvider } = await import("./bifrost-DvYZ3LNf.js");
444
- client = new BifrostProvider(options);
445
- } else if (isOllamaOptions(options)) {
446
- const { OllamaProvider } = await import("./ollama-BrB6bjnz.js");
447
- client = new OllamaProvider(options);
448
- } else if (isGeminiOptions(options)) {
449
- const { GeminiProvider } = await import("./gemini-GQdugon1.js");
450
- client = new GeminiProvider(options);
451
- } else if (isAnthropicOptions(options)) {
452
- const { AnthropicProvider } = await import("./anthropic-ByuqC5mC.js");
453
- client = new AnthropicProvider(options);
454
- } else if (isHuggingFaceOptions(options)) {
455
- const { HuggingFaceProvider } = await import("./huggingface-DxPspM6Q.js");
456
- client = new HuggingFaceProvider(options);
457
- } else if (isBedrockOptions(options)) {
458
- const { BedrockProvider } = await import("./bedrock-BeVCmkrS.js");
459
- client = new BedrockProvider(options);
460
- } else if (isClaudeCliOptions(options)) {
461
- const { ClaudeCliProvider } = await import("./claude-cli-BH_C62dV.js");
462
- client = new ClaudeCliProvider(options);
463
- } else if (isQwen3TTSOptions(options)) {
464
- const { Qwen3TTSProvider } = await import("./qwen-tts-CAh1upii.js");
465
- client = new Qwen3TTSProvider(options);
466
- } else if (isOpenAICompatVideoOptions(options)) {
467
- const { OpenAICompatVideoProvider } = await import("./openai-compat-video-DNE1Yvp6.js");
468
- client = new OpenAICompatVideoProvider(options);
469
- } else if (isByteplusModelArkOptions(options)) {
470
- const { ByteplusModelArkProvider } = await import("./byteplus-modelark-DaF0U4n1.js");
471
- client = new ByteplusModelArkProvider(options);
472
- } else if (isSeevioOptions(options)) {
473
- const { SeevioProvider } = await import("./seevio-Bbu_hTUF.js");
474
- client = new SeevioProvider(options);
475
- } else throw new ValidationError("Unsupported AI provider type", {
476
- supportedTypes: [...AI_PROVIDER_TYPES],
477
- providedType: options.type
478
- });
479
- return createObservedAI(createRateLimitedAI(client, options), options);
480
- }
481
- /**
482
- * Browser-compatible auto-detection of AI provider based on available credentials.
483
- * Does not rely on process.env, making it suitable for browser environments.
484
- *
485
- * @param options - Configuration options that may contain provider-specific credentials
486
- * @returns Promise resolving to an AI provider instance based on detected credentials
487
- * @throws {ValidationError} When no provider can be detected from the provided options
488
- *
489
- * @example
490
- * ```typescript
491
- * // Auto-detect OpenAI from apiKey
492
- * const client1 = await getAIAuto({
493
- * apiKey: 'sk-...', // Detected as OpenAI
494
- * defaultModel: 'gpt-4o'
495
- * });
496
- *
497
- * // Auto-detect Hugging Face from apiToken
498
- * const client2 = await getAIAuto({
499
- * apiToken: 'hf_...', // Detected as Hugging Face
500
- * model: 'microsoft/DialoGPT-medium'
501
- * });
502
- *
503
- * // Auto-detect AWS Bedrock from region and credentials
504
- * const client3 = await getAIAuto({
505
- * region: 'us-east-1',
506
- * credentials: {
507
- * accessKeyId: 'AKIA...',
508
- * secretAccessKey: 'xxx'
509
- * }
510
- * });
511
- * ```
512
- */
513
- async function getAIAuto(options) {
514
- const baseUrl = String(options.baseUrl || "");
515
- const hasKeepAliveOption = "keepAlive" in options && options.keepAlive !== void 0;
516
- if (/((?:localhost|127\.0\.0\.1)(?::11434)?(?:\/(?:api|v1))?|ollama(?:\.com)?(?:\/(?:api|v1))?)\/?$/i.test(baseUrl) || hasKeepAliveOption) return getAI({
517
- ...options,
518
- type: "ollama"
519
- });
520
- if (options.apiKey && !options.type) return getAI({
521
- ...options,
522
- type: "openai"
523
- });
524
- if (options.apiToken) return getAI({
525
- ...options,
526
- type: "huggingface"
527
- });
528
- if (options.region && options.credentials) return getAI({
529
- ...options,
530
- type: "bedrock"
531
- });
532
- if (options.projectId || options.anthropicVersion) {
533
- if (options.anthropicVersion) return getAI({
534
- ...options,
535
- type: "anthropic"
536
- });
537
- if (options.projectId) return getAI({
538
- ...options,
539
- type: "gemini"
540
- });
541
- }
542
- throw new ValidationError("Could not auto-detect AI provider from options", {
543
- hint: "Please specify a \"type\" field in options or provide provider-specific credentials",
544
- supportedTypes: [...AI_PROVIDER_TYPES],
545
- providedOptions: Object.keys(options)
546
- });
547
- }
548
- //#endregion
549
- //#region src/shared/message.ts
550
- /**
551
- * Represents a message in an AI conversation
552
- */
553
- var AIMessage = class AIMessage {
554
- /**
555
- * Original options used to create this message
556
- */
557
- options;
558
- /**
559
- * Name of the message sender
560
- */
561
- name;
562
- /**
563
- * Content of the message
564
- */
565
- content;
566
- /**
567
- * Role of the message sender in the conversation
568
- */
569
- role;
570
- /**
571
- * Creates a new AI message
572
- *
573
- * @param options - Message configuration
574
- * @param options.role - Role of the message sender
575
- * @param options.content - Content of the message
576
- * @param options.name - Name of the message sender
577
- */
578
- constructor(options) {
579
- this.options = options;
580
- this.role = options.role;
581
- this.content = options.content;
582
- this.name = options.name;
583
- }
584
- /**
585
- * Factory method to create a new AI message
586
- *
587
- * @param options - Message configuration
588
- * @param options.thread - Thread this message belongs to
589
- * @param options.role - Role of the message sender
590
- * @param options.content - Content of the message
591
- * @param options.name - Name of the message sender
592
- * @returns Promise resolving to a new AIMessage instance
593
- */
594
- static async create(options) {
595
- return new AIMessage(options);
596
- }
597
- };
598
- //#endregion
599
- //#region src/shared/thread.ts
600
- /**
601
- * Represents a conversation thread with an AI model
602
- * Manages messages, references, and conversation state
603
- */
604
- var AIThread = class AIThread {
605
- /**
606
- * AI client instance for this thread
607
- */
608
- ai;
609
- /**
610
- * Options used to configure this thread
611
- */
612
- options;
613
- /**
614
- * Messages in this conversation thread
615
- */
616
- messages = [];
617
- /**
618
- * Reference materials to include in the conversation context
619
- */
620
- references = {};
621
- /**
622
- * Creates a new AI thread
623
- *
624
- * @param options - Thread configuration options
625
- */
626
- constructor(options) {
627
- this.options = options;
628
- }
629
- /**
630
- * Factory method to create and initialize a new AI thread
631
- *
632
- * @param options - Thread configuration options
633
- * @returns Promise resolving to an initialized AIThread
634
- */
635
- static async create(options) {
636
- const thread = new AIThread(options);
637
- await thread.initialize();
638
- return thread;
639
- }
640
- /**
641
- * Initializes the AI client for this thread
642
- */
643
- async initialize() {
644
- this.ai = await AIClient.create(this.options.ai);
645
- }
646
- /**
647
- * Adds a system message to the conversation
648
- *
649
- * @param prompt - System message content
650
- * @returns Promise resolving to the created AIMessage
651
- */
652
- async addSystem(prompt) {
653
- const message = await AIMessage.create({
654
- thread: this,
655
- role: "system",
656
- name: "system",
657
- content: prompt
658
- });
659
- this.messages.push(message);
660
- return message;
661
- }
662
- /**
663
- * Adds a message to the conversation
664
- *
665
- * @param options - Message options
666
- * @param options.role - Role of the message sender
667
- * @param options.name - Optional name of the message sender
668
- * @param options.content - Content of the message
669
- * @returns Promise resolving to the created AIMessage
670
- */
671
- async add(options) {
672
- const message = await AIMessage.create({
673
- thread: this,
674
- role: options.role,
675
- name: options.name || options.role,
676
- content: options.content
677
- });
678
- this.messages.push(message);
679
- return message;
680
- }
681
- /**
682
- * Gets all messages in this thread
683
- *
684
- * @returns Array of AIMessage objects
685
- */
686
- get() {
687
- return this.messages;
688
- }
689
- /**
690
- * Adds a reference to be included in the conversation context
691
- *
692
- * @param name - Name of the reference
693
- * @param body - Content of the reference
694
- */
695
- addReference(name, body) {
696
- this.references[name] = body;
697
- }
698
- /**
699
- * Assembles the conversation history for sending to the AI
700
- * Properly orders system message, references, and conversation messages
701
- *
702
- * @returns Array of message parameters formatted for the OpenAI API
703
- */
704
- assembleHistory() {
705
- const history = [];
706
- const systemMessage = this.messages.find((m) => m.role === "system");
707
- if (systemMessage) history.push({
708
- role: systemMessage.role,
709
- content: systemMessage.content
710
- });
711
- for (const name in this.references) history.push({
712
- role: "user",
713
- content: `Reference - ${name}:\n${this.references[name]}`
714
- });
715
- this.messages.filter((m) => m.role !== "system").forEach((message) => {
716
- history.push({
717
- role: message.role,
718
- content: message.content
719
- });
720
- });
721
- return history;
722
- }
723
- /**
724
- * Sends a prompt to the AI and gets a response
725
- *
726
- * @param prompt - Prompt message to send
727
- * @param options - Options for the AI response
728
- * @param options.responseFormat - Format for the AI to respond with
729
- * @returns Promise resolving to the AI response
730
- */
731
- async do(prompt, options = { responseFormat: "text" }) {
732
- const { responseFormat } = options;
733
- const history = this.assembleHistory();
734
- return await this.ai.textCompletion(prompt, {
735
- history,
736
- responseFormat: { type: responseFormat === "json" ? "json_object" : "text" }
737
- });
738
- }
739
- };
740
- //#endregion
741
- //#region src/index.ts
742
- /** @internal */
743
- var PACKAGE_VERSION_INITIALIZED = true;
744
- //#endregion
745
- export { getAI as a, OpenAIClient as c, factory_exports as i, getAIClient as l, AIThread as n, getAIAuto as o, AIMessage as r, AIClient as s, PACKAGE_VERSION_INITIALIZED as t, getOpenAI as u };
746
-
747
- //# sourceMappingURL=src-B091S0I4.js.map