@node-llm/core 1.4.3 → 1.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.
Files changed (83) hide show
  1. package/README.md +65 -2
  2. package/dist/chat/Chat.d.ts +51 -0
  3. package/dist/chat/Chat.d.ts.map +1 -1
  4. package/dist/chat/Chat.js +189 -55
  5. package/dist/chat/ChatOptions.d.ts +11 -2
  6. package/dist/chat/ChatOptions.d.ts.map +1 -1
  7. package/dist/chat/ChatResponse.d.ts +7 -1
  8. package/dist/chat/ChatResponse.d.ts.map +1 -1
  9. package/dist/chat/ChatResponse.js +9 -1
  10. package/dist/chat/ChatStream.d.ts +15 -1
  11. package/dist/chat/ChatStream.d.ts.map +1 -1
  12. package/dist/chat/ChatStream.js +122 -36
  13. package/dist/chat/Role.d.ts +1 -1
  14. package/dist/chat/Role.d.ts.map +1 -1
  15. package/dist/config.d.ts +11 -0
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +7 -1
  18. package/dist/constants.d.ts +11 -0
  19. package/dist/constants.d.ts.map +1 -1
  20. package/dist/constants.js +12 -0
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -0
  24. package/dist/llm.d.ts +4 -0
  25. package/dist/llm.d.ts.map +1 -1
  26. package/dist/llm.js +10 -0
  27. package/dist/providers/Provider.d.ts +6 -0
  28. package/dist/providers/Provider.d.ts.map +1 -1
  29. package/dist/providers/anthropic/AnthropicProvider.d.ts +1 -0
  30. package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
  31. package/dist/providers/anthropic/AnthropicProvider.js +1 -0
  32. package/dist/providers/anthropic/Chat.d.ts.map +1 -1
  33. package/dist/providers/anthropic/Chat.js +4 -3
  34. package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
  35. package/dist/providers/anthropic/Streaming.js +3 -2
  36. package/dist/providers/anthropic/Utils.js +2 -2
  37. package/dist/providers/deepseek/Chat.d.ts.map +1 -1
  38. package/dist/providers/deepseek/Chat.js +8 -5
  39. package/dist/providers/deepseek/DeepSeekProvider.d.ts +1 -0
  40. package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -1
  41. package/dist/providers/deepseek/DeepSeekProvider.js +1 -0
  42. package/dist/providers/deepseek/Streaming.d.ts.map +1 -1
  43. package/dist/providers/deepseek/Streaming.js +7 -4
  44. package/dist/providers/gemini/Chat.d.ts.map +1 -1
  45. package/dist/providers/gemini/Chat.js +4 -3
  46. package/dist/providers/gemini/ChatUtils.js +5 -5
  47. package/dist/providers/gemini/GeminiProvider.d.ts +1 -0
  48. package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
  49. package/dist/providers/gemini/GeminiProvider.js +1 -0
  50. package/dist/providers/gemini/Streaming.d.ts.map +1 -1
  51. package/dist/providers/gemini/Streaming.js +3 -2
  52. package/dist/providers/ollama/OllamaProvider.d.ts.map +1 -1
  53. package/dist/providers/ollama/OllamaProvider.js +1 -0
  54. package/dist/providers/openai/Capabilities.d.ts +1 -0
  55. package/dist/providers/openai/Capabilities.d.ts.map +1 -1
  56. package/dist/providers/openai/Capabilities.js +3 -0
  57. package/dist/providers/openai/Chat.d.ts +4 -2
  58. package/dist/providers/openai/Chat.d.ts.map +1 -1
  59. package/dist/providers/openai/Chat.js +16 -7
  60. package/dist/providers/openai/Embedding.d.ts.map +1 -1
  61. package/dist/providers/openai/Embedding.js +3 -2
  62. package/dist/providers/openai/Image.d.ts.map +1 -1
  63. package/dist/providers/openai/Image.js +3 -2
  64. package/dist/providers/openai/Moderation.d.ts.map +1 -1
  65. package/dist/providers/openai/Moderation.js +3 -2
  66. package/dist/providers/openai/OpenAIProvider.d.ts +1 -0
  67. package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
  68. package/dist/providers/openai/OpenAIProvider.js +3 -2
  69. package/dist/providers/openai/Streaming.d.ts +4 -2
  70. package/dist/providers/openai/Streaming.d.ts.map +1 -1
  71. package/dist/providers/openai/Streaming.js +15 -6
  72. package/dist/providers/openai/Transcription.d.ts.map +1 -1
  73. package/dist/providers/openai/Transcription.js +5 -4
  74. package/dist/providers/openrouter/OpenRouterProvider.d.ts +1 -0
  75. package/dist/providers/openrouter/OpenRouterProvider.d.ts.map +1 -1
  76. package/dist/providers/openrouter/OpenRouterProvider.js +1 -0
  77. package/dist/providers/utils.d.ts +8 -0
  78. package/dist/providers/utils.d.ts.map +1 -0
  79. package/dist/providers/utils.js +16 -0
  80. package/dist/utils/fetch.d.ts +12 -0
  81. package/dist/utils/fetch.d.ts.map +1 -0
  82. package/dist/utils/fetch.js +34 -0
  83. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  export function formatSystemPrompt(messages) {
2
2
  let systemPrompt;
3
3
  for (const msg of messages) {
4
- if (msg.role === "system") {
4
+ if (msg.role === "system" || msg.role === "developer") {
5
5
  if (typeof msg.content === "string") {
6
6
  systemPrompt = msg.content;
7
7
  }
@@ -21,7 +21,7 @@ export function formatSystemPrompt(messages) {
21
21
  export function formatMessages(requestMessages) {
22
22
  const messages = [];
23
23
  for (const msg of requestMessages) {
24
- if (msg.role === "system")
24
+ if (msg.role === "system" || msg.role === "developer")
25
25
  continue;
26
26
  const formatted = formatSingleMessage(msg);
27
27
  const lastMsg = messages[messages.length - 1];
@@ -1 +1 @@
1
- {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAsBlE,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAyF3D"}
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAwBlE,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CA2F3D"}
@@ -1,5 +1,7 @@
1
1
  import { ModelRegistry } from "../../models/ModelRegistry.js";
2
2
  import { logger } from "../../utils/logger.js";
3
+ import { mapSystemMessages } from "../utils.js";
4
+ import { fetchWithTimeout } from "../../utils/fetch.js";
3
5
  export class DeepSeekChat {
4
6
  baseUrl;
5
7
  apiKey;
@@ -8,10 +10,11 @@ export class DeepSeekChat {
8
10
  this.apiKey = apiKey;
9
11
  }
10
12
  async execute(request) {
11
- const { model, messages, tools, max_tokens, response_format, headers, ...rest } = request;
13
+ const { model, messages, tools, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
14
+ const mappedMessages = mapSystemMessages(messages, false);
12
15
  const body = {
13
16
  model,
14
- messages,
17
+ messages: mappedMessages,
15
18
  ...rest
16
19
  };
17
20
  if (max_tokens)
@@ -31,7 +34,7 @@ export class DeepSeekChat {
31
34
  const schemaString = JSON.stringify(schema.schema, null, 2);
32
35
  const instruction = `\n\nIMPORTANT: You must output strictly valid JSON conforming to the following schema:\n${schemaString}\n\nOutput only the JSON object.`;
33
36
  // Find system message or append to last user message
34
- const systemMessage = body.messages.find((m) => m.role === "system");
37
+ const systemMessage = body.messages.find((m) => m.role === "system" || m.role === "developer");
35
38
  if (systemMessage) {
36
39
  systemMessage.content += instruction;
37
40
  }
@@ -49,7 +52,7 @@ export class DeepSeekChat {
49
52
  }
50
53
  const url = `${this.baseUrl}/chat/completions`;
51
54
  logger.logRequest("DeepSeek", "POST", url, body);
52
- const response = await fetch(url, {
55
+ const response = await fetchWithTimeout(url, {
53
56
  method: "POST",
54
57
  headers: {
55
58
  "Authorization": `Bearer ${this.apiKey}`,
@@ -57,7 +60,7 @@ export class DeepSeekChat {
57
60
  ...request.headers,
58
61
  },
59
62
  body: JSON.stringify(body),
60
- });
63
+ }, requestTimeout);
61
64
  if (!response.ok) {
62
65
  const errorText = await response.text();
63
66
  throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
@@ -19,6 +19,7 @@ export declare class DeepSeekProvider extends BaseProvider implements Provider {
19
19
  supportsTranscription: (model: string) => boolean;
20
20
  supportsModeration: (model: string) => boolean;
21
21
  supportsReasoning: (model: string) => boolean;
22
+ supportsDeveloperRole: (_model: string) => boolean;
22
23
  getContextWindow: (model: string) => number | null;
23
24
  };
24
25
  constructor(options: DeepSeekProviderOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"DeepSeekProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/DeepSeekProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMlD,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,gBAAiB,SAAQ,YAAa,YAAW,QAAQ;IAkBxD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAjBpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAExC,YAAY;gCACO,MAAM;+BACP,MAAM;0CACK,MAAM;oCACZ,MAAM;yCACD,MAAM;uCACR,M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D,OAAO,IAAI,MAAM;IAIjB,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAOxC,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAKzC"}
@@ -18,6 +18,7 @@ export class DeepSeekProvider extends BaseProvider {
18
18
  supportsTranscription: (model) => Capabilities.supportsTranscription(model),
19
19
  supportsModeration: (model) => Capabilities.supportsModeration(model),
20
20
  supportsReasoning: (model) => Capabilities.supportsReasoning(model),
21
+ supportsDeveloperRole: (_model) => false,
21
22
  getContextWindow: (model) => Capabilities.getContextWindow(model),
22
23
  };
23
24
  constructor(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIxD,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CA+J7B"}
1
+ {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMxD,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CAiK7B"}
@@ -1,5 +1,7 @@
1
1
  import { APIError } from "../../errors/index.js";
2
2
  import { logger } from "../../utils/logger.js";
3
+ import { mapSystemMessages } from "../utils.js";
4
+ import { fetchWithTimeout } from "../../utils/fetch.js";
3
5
  export class DeepSeekStreaming {
4
6
  baseUrl;
5
7
  apiKey;
@@ -9,10 +11,11 @@ export class DeepSeekStreaming {
9
11
  }
10
12
  async *execute(request, controller) {
11
13
  const abortController = controller || new AbortController();
12
- const { model, messages, tools, max_tokens, response_format, headers, ...rest } = request;
14
+ const { model, messages, tools, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
15
+ const mappedMessages = mapSystemMessages(messages, false);
13
16
  const body = {
14
17
  model,
15
- messages,
18
+ messages: mappedMessages,
16
19
  stream: true,
17
20
  ...rest
18
21
  };
@@ -28,7 +31,7 @@ export class DeepSeekStreaming {
28
31
  try {
29
32
  const url = `${this.baseUrl}/chat/completions`;
30
33
  logger.logRequest("DeepSeek", "POST", url, body);
31
- const response = await fetch(url, {
34
+ const response = await fetchWithTimeout(url, {
32
35
  method: "POST",
33
36
  headers: {
34
37
  "Authorization": `Bearer ${this.apiKey}`,
@@ -37,7 +40,7 @@ export class DeepSeekStreaming {
37
40
  },
38
41
  body: JSON.stringify(body),
39
42
  signal: abortController.signal,
40
- });
43
+ }, requestTimeout);
41
44
  if (!response.ok) {
42
45
  const errorText = await response.text();
43
46
  throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
@@ -1 +1 @@
1
- {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAQlE,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA4F1D,OAAO,CAAC,cAAc;CAwBvB"}
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AASlE,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA4F1D,OAAO,CAAC,cAAc;CAwBvB"}
@@ -3,6 +3,7 @@ import { handleGeminiError } from "./Errors.js";
3
3
  import { GeminiChatUtils } from "./ChatUtils.js";
4
4
  import { ModelRegistry } from "../../models/ModelRegistry.js";
5
5
  import { logger } from "../../utils/logger.js";
6
+ import { fetchWithTimeout } from "../../utils/fetch.js";
6
7
  export class GeminiChat {
7
8
  baseUrl;
8
9
  apiKey;
@@ -27,7 +28,7 @@ export class GeminiChat {
27
28
  generationConfig.responseSchema = this.sanitizeSchema(request.response_format.json_schema.schema);
28
29
  }
29
30
  }
30
- const { model: _model, messages: _messages, tools: _tools, temperature: _temp, max_tokens: _max, response_format: _format, headers: _headers, ...rest } = request;
31
+ const { model: _model, messages: _messages, tools: _tools, temperature: _temp, max_tokens: _max, response_format: _format, headers: _headers, requestTimeout, ...rest } = request;
31
32
  const payload = {
32
33
  contents,
33
34
  generationConfig: {
@@ -51,13 +52,13 @@ export class GeminiChat {
51
52
  ];
52
53
  }
53
54
  logger.logRequest("Gemini", "POST", url, payload);
54
- const response = await fetch(url, {
55
+ const response = await fetchWithTimeout(url, {
55
56
  method: "POST",
56
57
  headers: {
57
58
  "Content-Type": "application/json",
58
59
  },
59
60
  body: JSON.stringify(payload),
60
- });
61
+ }, requestTimeout);
61
62
  if (!response.ok) {
62
63
  await handleGeminiError(response, request.model);
63
64
  }
@@ -4,9 +4,9 @@ export class GeminiChatUtils {
4
4
  const contents = [];
5
5
  const systemInstructionParts = [];
6
6
  for (const msg of messages) {
7
- if (msg.role === "system") {
8
- if (typeof msg.content === "string") {
9
- systemInstructionParts.push({ text: msg.content });
7
+ if (msg.role === "system" || msg.role === "developer") {
8
+ if (msg.content) {
9
+ systemInstructionParts.push({ text: String(msg.content) });
10
10
  }
11
11
  }
12
12
  else if (msg.role === "user" || msg.role === "assistant" || msg.role === "tool") {
@@ -22,8 +22,8 @@ export class GeminiChatUtils {
22
22
  }
23
23
  else {
24
24
  const role = msg.role === "assistant" ? "model" : "user";
25
- if (typeof msg.content === "string" && msg.content) {
26
- parts.push({ text: msg.content });
25
+ if (msg.content && (typeof msg.content === "string" || msg.content instanceof String)) {
26
+ parts.push({ text: String(msg.content) });
27
27
  }
28
28
  else if (Array.isArray(msg.content)) {
29
29
  for (const part of msg.content) {
@@ -22,6 +22,7 @@ export declare class GeminiProvider extends BaseProvider implements Provider {
22
22
  supportsTranscription: (model: string) => boolean;
23
23
  supportsModeration: (model: string) => boolean;
24
24
  supportsReasoning: (_model: string) => boolean;
25
+ supportsDeveloperRole: (_model: string) => boolean;
25
26
  getContextWindow: (model: string) => number | null;
26
27
  };
27
28
  constructor(options: GeminiProviderOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"GeminiProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/GeminiProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,E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AC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAIlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpD,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI5D,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAKhF"}
@@ -24,6 +24,7 @@ export class GeminiProvider extends BaseProvider {
24
24
  supportsTranscription: (model) => Capabilities.supportsTranscription(model),
25
25
  supportsModeration: (model) => Capabilities.supportsModeration(model),
26
26
  supportsReasoning: (_model) => false,
27
+ supportsDeveloperRole: (_model) => true,
27
28
  getContextWindow: (model) => Capabilities.getContextWindow(model),
28
29
  };
29
30
  constructor(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOxD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;IAyI5B,OAAO,CAAC,cAAc;CAwBvB"}
1
+ {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;IAyI5B,OAAO,CAAC,cAAc;CAwBvB"}
@@ -2,6 +2,7 @@ import { Capabilities } from "./Capabilities.js";
2
2
  import { handleGeminiError } from "./Errors.js";
3
3
  import { GeminiChatUtils } from "./ChatUtils.js";
4
4
  import { logger } from "../../utils/logger.js";
5
+ import { fetchWithTimeout } from "../../utils/fetch.js";
5
6
  export class GeminiStreaming {
6
7
  baseUrl;
7
8
  apiKey;
@@ -49,14 +50,14 @@ export class GeminiStreaming {
49
50
  const toolCalls = [];
50
51
  try {
51
52
  logger.logRequest("Gemini", "POST", url, payload);
52
- const response = await fetch(url, {
53
+ const response = await fetchWithTimeout(url, {
53
54
  method: "POST",
54
55
  headers: {
55
56
  "Content-Type": "application/json",
56
57
  },
57
58
  body: JSON.stringify(payload),
58
59
  signal: abortController.signal,
59
- });
60
+ }, request.requestTimeout);
60
61
  if (!response.ok) {
61
62
  await handleGeminiError(response, request.model);
62
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OllamaProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/ollama/OllamaProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAM7D,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,cAAe,SAAQ,cAAc;gBACpC,OAAO,GAAE,qBAA0B;IAwB/C,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;CAGvD"}
1
+ {"version":3,"file":"OllamaProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/ollama/OllamaProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAM7D,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,cAAe,SAAQ,cAAc;gBACpC,OAAO,GAAE,qBAA0B;IAyB/C,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;CAGvD"}
@@ -22,6 +22,7 @@ export class OllamaProvider extends OpenAIProvider {
22
22
  supportsTranscription: (modelId) => OllamaCapabilities.supportsTranscription(modelId),
23
23
  supportsModeration: (modelId) => OllamaCapabilities.supportsModeration(modelId),
24
24
  supportsReasoning: (modelId) => OllamaCapabilities.supportsReasoning(modelId),
25
+ supportsDeveloperRole: (_modelId) => false,
25
26
  getContextWindow: (modelId) => OllamaCapabilities.getContextWindow(modelId),
26
27
  };
27
28
  }
@@ -10,6 +10,7 @@ export declare class Capabilities {
10
10
  static supportsTranscription(modelId: string): boolean;
11
11
  static supportsModeration(modelId: string): boolean;
12
12
  static supportsReasoning(modelId: string): boolean;
13
+ static supportsDeveloperRole(modelId: string): boolean;
13
14
  static getModelType(modelId: string): "embeddings" | "audio" | "moderation" | "image" | "chat" | "audio_transcription" | "audio_speech";
14
15
  static getModalities(modelId: string): {
15
16
  input: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Capabilities.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAUvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,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,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI;IAMxG,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAOjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;CAcxC"}
@@ -73,6 +73,9 @@ export class Capabilities {
73
73
  return true;
74
74
  return /o\d|gpt-5/.test(modelId);
75
75
  }
76
+ static supportsDeveloperRole(modelId) {
77
+ return /gpt-4o|o1|o3/.test(modelId);
78
+ }
76
79
  static getModelType(modelId) {
77
80
  if (this.supportsEmbeddings(modelId))
78
81
  return "embeddings";
@@ -1,8 +1,10 @@
1
1
  import { ChatRequest, ChatResponse } from "../Provider.js";
2
+ import { OpenAIProvider } from "./OpenAIProvider.js";
2
3
  export declare class OpenAIChat {
3
- private readonly baseUrl;
4
+ private readonly providerOrUrl;
4
5
  private readonly apiKey;
5
- constructor(baseUrl: string, apiKey: string);
6
+ private readonly baseUrl;
7
+ constructor(providerOrUrl: OpenAIProvider | string, apiKey: string);
6
8
  execute(request: ChatRequest): Promise<ChatResponse>;
7
9
  }
8
10
  //# sourceMappingURL=Chat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAQlE,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAuD3D"}
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AASlE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,UAAU;IAGT,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAF5F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,aAAa,EAAE,cAAc,GAAG,MAAM,EAAmB,MAAM,EAAE,MAAM;IAI9F,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAgE3D"}
@@ -3,19 +3,28 @@ import { handleOpenAIError } from "./Errors.js";
3
3
  import { ModelRegistry } from "../../models/ModelRegistry.js";
4
4
  import { buildUrl } from "./utils.js";
5
5
  import { logger } from "../../utils/logger.js";
6
+ import { fetchWithTimeout } from "../../utils/fetch.js";
7
+ import { mapSystemMessages } from "../utils.js";
6
8
  export class OpenAIChat {
7
- baseUrl;
9
+ providerOrUrl;
8
10
  apiKey;
9
- constructor(baseUrl, apiKey) {
10
- this.baseUrl = baseUrl;
11
+ baseUrl;
12
+ constructor(providerOrUrl, apiKey) {
13
+ this.providerOrUrl = providerOrUrl;
11
14
  this.apiKey = apiKey;
15
+ this.baseUrl = typeof providerOrUrl === "string" ? providerOrUrl : providerOrUrl.apiBase();
12
16
  }
13
17
  async execute(request) {
14
18
  const temperature = Capabilities.normalizeTemperature(request.temperature, request.model);
15
- const { model, messages, tools, temperature: _, max_tokens, response_format, headers, ...rest } = request;
19
+ const isMainOpenAI = this.baseUrl.includes("api.openai.com");
20
+ const supportsDeveloperRole = isMainOpenAI && (typeof this.providerOrUrl === "string"
21
+ ? Capabilities.supportsDeveloperRole(request.model)
22
+ : this.providerOrUrl.capabilities?.supportsDeveloperRole(request.model));
23
+ const { model, messages, tools, temperature: _, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
24
+ const mappedMessages = mapSystemMessages(messages, !!supportsDeveloperRole);
16
25
  const body = {
17
26
  model,
18
- messages,
27
+ messages: mappedMessages,
19
28
  ...rest
20
29
  };
21
30
  if (temperature !== undefined && temperature !== null)
@@ -28,7 +37,7 @@ export class OpenAIChat {
28
37
  body.response_format = response_format;
29
38
  const url = buildUrl(this.baseUrl, '/chat/completions');
30
39
  logger.logRequest("OpenAI", "POST", url, body);
31
- const response = await fetch(url, {
40
+ const response = await fetchWithTimeout(url, {
32
41
  method: "POST",
33
42
  headers: {
34
43
  "Authorization": `Bearer ${this.apiKey}`,
@@ -36,7 +45,7 @@ export class OpenAIChat {
36
45
  ...request.headers,
37
46
  },
38
47
  body: JSON.stringify(body),
39
- });
48
+ }, request.requestTimeout);
40
49
  if (!response.ok) {
41
50
  await handleOpenAIError(response, request.model);
42
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Embedding.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAOrE,qBAAa,eAAe;IAExB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAClC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAGnC,SAAS,CAAC,eAAe,IAAI,MAAM;IAInC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMtC,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA+CrE"}
1
+ {"version":3,"file":"Embedding.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAQrE,qBAAa,eAAe;IAExB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAClC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAGnC,SAAS,CAAC,eAAe,IAAI,MAAM;IAInC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMtC,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA+CrE"}
@@ -3,6 +3,7 @@ import { Capabilities } from "./Capabilities.js";
3
3
  import { DEFAULT_MODELS } from "../../constants.js";
4
4
  import { buildUrl } from "./utils.js";
5
5
  import { logger } from "../../utils/logger.js";
6
+ import { fetchWithTimeout } from "../../utils/fetch.js";
6
7
  export class OpenAIEmbedding {
7
8
  baseUrl;
8
9
  apiKey;
@@ -33,14 +34,14 @@ export class OpenAIEmbedding {
33
34
  }
34
35
  const url = buildUrl(this.baseUrl, '/embeddings');
35
36
  logger.logRequest("OpenAI", "POST", url, body);
36
- const response = await fetch(url, {
37
+ const response = await fetchWithTimeout(url, {
37
38
  method: "POST",
38
39
  headers: {
39
40
  "Authorization": `Bearer ${this.apiKey}`,
40
41
  "Content-Type": "application/json",
41
42
  },
42
43
  body: JSON.stringify(body),
43
- });
44
+ }, request.requestTimeout);
44
45
  if (!response.ok) {
45
46
  await handleOpenAIError(response, request.model || DEFAULT_MODELS.EMBEDDING);
46
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK7D,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAuC7D"}
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM7D,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAuC7D"}
@@ -1,6 +1,7 @@
1
1
  import { handleOpenAIError } from "./Errors.js";
2
2
  import { buildUrl } from "./utils.js";
3
3
  import { logger } from "../../utils/logger.js";
4
+ import { fetchWithTimeout } from "../../utils/fetch.js";
4
5
  export class OpenAIImage {
5
6
  baseUrl;
6
7
  apiKey;
@@ -18,14 +19,14 @@ export class OpenAIImage {
18
19
  };
19
20
  const url = buildUrl(this.baseUrl, '/images/generations');
20
21
  logger.logRequest("OpenAI", "POST", url, body);
21
- const response = await fetch(url, {
22
+ const response = await fetchWithTimeout(url, {
22
23
  method: "POST",
23
24
  headers: {
24
25
  "Authorization": `Bearer ${this.apiKey}`,
25
26
  "Content-Type": "application/json",
26
27
  },
27
28
  body: JSON.stringify(body),
28
- });
29
+ }, request.requestTimeout);
29
30
  if (!response.ok) {
30
31
  await handleOpenAIError(response, request.model);
31
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Moderation.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Moderation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAMvE,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA0BvE"}
1
+ {"version":3,"file":"Moderation.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Moderation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAOvE,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA0BvE"}
@@ -2,6 +2,7 @@ import { handleOpenAIError } from "./Errors.js";
2
2
  import { DEFAULT_MODELS } from "../../constants.js";
3
3
  import { buildUrl } from "./utils.js";
4
4
  import { logger } from "../../utils/logger.js";
5
+ import { fetchWithTimeout } from "../../utils/fetch.js";
5
6
  export class OpenAIModeration {
6
7
  baseUrl;
7
8
  apiKey;
@@ -16,14 +17,14 @@ export class OpenAIModeration {
16
17
  };
17
18
  const url = buildUrl(this.baseUrl, '/moderations');
18
19
  logger.logRequest("OpenAI", "POST", url, body);
19
- const response = await fetch(url, {
20
+ const response = await fetchWithTimeout(url, {
20
21
  method: "POST",
21
22
  headers: {
22
23
  "Authorization": `Bearer ${this.apiKey}`,
23
24
  "Content-Type": "application/json",
24
25
  },
25
26
  body: JSON.stringify(body),
26
- });
27
+ }, request.requestTimeout);
27
28
  if (!response.ok) {
28
29
  await handleOpenAIError(response, request.model || DEFAULT_MODELS.MODERATION);
29
30
  }
@@ -31,6 +31,7 @@ export declare class OpenAIProvider extends BaseProvider implements Provider {
31
31
  supportsTranscription: (model: string) => boolean;
32
32
  supportsModeration: (model: string) => boolean;
33
33
  supportsReasoning: (model: string) => boolean;
34
+ supportsDeveloperRole: (modelId: string) => boolean;
34
35
  getContextWindow: (model: string) => number | null;
35
36
  };
36
37
  constructor(options: OpenAIProviderOptions);
@@ -1 +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AIhB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAIlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpD,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAIzE,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIjE,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGnE"}
@@ -26,14 +26,15 @@ export class OpenAIProvider extends BaseProvider {
26
26
  supportsTranscription: (model) => Capabilities.supportsTranscription(model),
27
27
  supportsModeration: (model) => Capabilities.supportsModeration(model),
28
28
  supportsReasoning: (model) => Capabilities.supportsReasoning(model),
29
+ supportsDeveloperRole: (modelId) => this.baseUrl.includes("api.openai.com") && Capabilities.supportsDeveloperRole(modelId),
29
30
  getContextWindow: (model) => Capabilities.getContextWindow(model) || null,
30
31
  };
31
32
  constructor(options) {
32
33
  super();
33
34
  this.options = options;
34
35
  this.baseUrl = options.baseUrl ?? "https://api.openai.com/v1";
35
- this.chatHandler = new OpenAIChat(this.baseUrl, options.apiKey);
36
- this.streamingHandler = new OpenAIStreaming(this.baseUrl, options.apiKey);
36
+ this.chatHandler = new OpenAIChat(this, options.apiKey);
37
+ this.streamingHandler = new OpenAIStreaming(this, options.apiKey);
37
38
  this.modelsHandler = new OpenAIModels(this.baseUrl, options.apiKey);
38
39
  this.imageHandler = new OpenAIImage(this.baseUrl, options.apiKey);
39
40
  this.transcriptionHandler = new OpenAITranscription(this.baseUrl, options.apiKey);
@@ -1,8 +1,10 @@
1
1
  import { ChatRequest, ChatChunk } from "../Provider.js";
2
+ import { OpenAIProvider } from "./OpenAIProvider.js";
2
3
  export declare class OpenAIStreaming {
3
- private readonly baseUrl;
4
+ private readonly providerOrUrl;
4
5
  private readonly apiKey;
5
- constructor(baseUrl: string, apiKey: string);
6
+ private readonly baseUrl;
7
+ constructor(providerOrUrl: OpenAIProvider | string, apiKey: string);
6
8
  execute(request: ChatRequest, controller?: AbortController): AsyncGenerator<ChatChunk>;
7
9
  }
8
10
  //# sourceMappingURL=Streaming.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOxD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CAqK7B"}
1
+ {"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAF5F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,aAAa,EAAE,cAAc,GAAG,MAAM,EAAmB,MAAM,EAAE,MAAM;IAI7F,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CA8K7B"}
@@ -3,19 +3,28 @@ import { handleOpenAIError } from "./Errors.js";
3
3
  import { buildUrl } from "./utils.js";
4
4
  import { APIError } from "../../errors/index.js";
5
5
  import { logger } from "../../utils/logger.js";
6
+ import { fetchWithTimeout } from "../../utils/fetch.js";
7
+ import { mapSystemMessages } from "../utils.js";
6
8
  export class OpenAIStreaming {
7
- baseUrl;
9
+ providerOrUrl;
8
10
  apiKey;
9
- constructor(baseUrl, apiKey) {
10
- this.baseUrl = baseUrl;
11
+ baseUrl;
12
+ constructor(providerOrUrl, apiKey) {
13
+ this.providerOrUrl = providerOrUrl;
11
14
  this.apiKey = apiKey;
15
+ this.baseUrl = typeof providerOrUrl === "string" ? providerOrUrl : providerOrUrl.apiBase();
12
16
  }
13
17
  async *execute(request, controller) {
14
18
  const abortController = controller || new AbortController();
15
19
  const temperature = Capabilities.normalizeTemperature(request.temperature, request.model);
20
+ const isMainOpenAI = this.baseUrl.includes("api.openai.com");
21
+ const supportsDeveloperRole = isMainOpenAI && (typeof this.providerOrUrl === "string"
22
+ ? Capabilities.supportsDeveloperRole(request.model)
23
+ : this.providerOrUrl.capabilities?.supportsDeveloperRole(request.model));
24
+ const mappedMessages = mapSystemMessages(request.messages, !!supportsDeveloperRole);
16
25
  const body = {
17
26
  model: request.model,
18
- messages: request.messages,
27
+ messages: mappedMessages,
19
28
  stream: true,
20
29
  };
21
30
  if (temperature !== undefined && temperature !== null) {
@@ -36,7 +45,7 @@ export class OpenAIStreaming {
36
45
  try {
37
46
  const url = buildUrl(this.baseUrl, '/chat/completions');
38
47
  logger.logRequest("OpenAI", "POST", url, body);
39
- const response = await fetch(url, {
48
+ const response = await fetchWithTimeout(url, {
40
49
  method: "POST",
41
50
  headers: {
42
51
  "Authorization": `Bearer ${this.apiKey}`,
@@ -45,7 +54,7 @@ export class OpenAIStreaming {
45
54
  },
46
55
  body: JSON.stringify(body),
47
56
  signal: abortController.signal,
48
- });
57
+ }, request.requestTimeout);
49
58
  if (!response.ok) {
50
59
  await handleOpenAIError(response, request.model);
51
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAO7E,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAU9D,oBAAoB;YAgDpB,iBAAiB;CA4HhC"}
1
+ {"version":3,"file":"Transcription.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAQ7E,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAU9D,oBAAoB;YAgDpB,iBAAiB;CA4HhC"}