@yourgpt/llm-sdk 2.5.0 → 2.5.1-beta.1

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 (62) hide show
  1. package/README.md +19 -1
  2. package/dist/adapters/index.d.mts +4 -4
  3. package/dist/adapters/index.d.ts +4 -4
  4. package/dist/adapters/index.js +293 -23
  5. package/dist/adapters/index.mjs +293 -23
  6. package/dist/base-BYQKp9TW.d.mts +263 -0
  7. package/dist/base-Cxq3ni0t.d.ts +263 -0
  8. package/dist/fallback/index.d.mts +4 -4
  9. package/dist/fallback/index.d.ts +4 -4
  10. package/dist/index.d.mts +61 -8
  11. package/dist/index.d.ts +61 -8
  12. package/dist/index.js +71 -0
  13. package/dist/index.mjs +71 -0
  14. package/dist/providers/anthropic/index.d.mts +3 -3
  15. package/dist/providers/anthropic/index.d.ts +3 -3
  16. package/dist/providers/anthropic/index.js +360 -203
  17. package/dist/providers/anthropic/index.mjs +360 -203
  18. package/dist/providers/azure/index.d.mts +3 -3
  19. package/dist/providers/azure/index.d.ts +3 -3
  20. package/dist/providers/azure/index.js +49 -1
  21. package/dist/providers/azure/index.mjs +49 -1
  22. package/dist/providers/fireworks/index.d.mts +1 -1
  23. package/dist/providers/fireworks/index.d.ts +1 -1
  24. package/dist/providers/fireworks/index.js +56 -0
  25. package/dist/providers/fireworks/index.mjs +56 -0
  26. package/dist/providers/google/index.d.mts +3 -3
  27. package/dist/providers/google/index.d.ts +3 -3
  28. package/dist/providers/google/index.js +303 -207
  29. package/dist/providers/google/index.mjs +303 -207
  30. package/dist/providers/ollama/index.d.mts +4 -4
  31. package/dist/providers/ollama/index.d.ts +4 -4
  32. package/dist/providers/ollama/index.js +10 -2
  33. package/dist/providers/ollama/index.mjs +10 -2
  34. package/dist/providers/openai/index.d.mts +3 -3
  35. package/dist/providers/openai/index.d.ts +3 -3
  36. package/dist/providers/openai/index.js +318 -216
  37. package/dist/providers/openai/index.mjs +318 -216
  38. package/dist/providers/openrouter/index.d.mts +3 -3
  39. package/dist/providers/openrouter/index.d.ts +3 -3
  40. package/dist/providers/openrouter/index.js +308 -206
  41. package/dist/providers/openrouter/index.mjs +308 -206
  42. package/dist/providers/togetherai/index.d.mts +3 -3
  43. package/dist/providers/togetherai/index.d.ts +3 -3
  44. package/dist/providers/togetherai/index.js +308 -206
  45. package/dist/providers/togetherai/index.mjs +308 -206
  46. package/dist/providers/xai/index.d.mts +3 -3
  47. package/dist/providers/xai/index.d.ts +3 -3
  48. package/dist/providers/xai/index.js +307 -210
  49. package/dist/providers/xai/index.mjs +307 -210
  50. package/dist/{types-BctsnC3g.d.ts → types-BvkiJ1dd.d.mts} +2 -1
  51. package/dist/{types-38yolWJn.d.ts → types-ChORafYS.d.ts} +1 -1
  52. package/dist/types-D774b0dg.d.mts +1018 -0
  53. package/dist/types-D774b0dg.d.ts +1018 -0
  54. package/dist/{types-DRqxMIjF.d.mts → types-TMilS-Dz.d.ts} +2 -1
  55. package/dist/{types-D4YfrQJR.d.mts → types-mwMhCwOq.d.mts} +1 -1
  56. package/dist/yourgpt/index.d.mts +1 -1
  57. package/dist/yourgpt/index.d.ts +1 -1
  58. package/package.json +1 -1
  59. package/dist/base-D-U61JaB.d.mts +0 -788
  60. package/dist/base-iGi9Va6Z.d.ts +0 -788
  61. package/dist/types-CR8mi9I0.d.mts +0 -417
  62. package/dist/types-CR8mi9I0.d.ts +0 -417
@@ -1,7 +1,7 @@
1
- import { b as AzureProviderConfig, A as AIProvider } from '../../types-DRqxMIjF.mjs';
2
- import '../../base-D-U61JaB.mjs';
3
- import '../../types-CR8mi9I0.mjs';
1
+ import { b as AzureProviderConfig, A as AIProvider } from '../../types-BvkiJ1dd.mjs';
2
+ import '../../types-D774b0dg.mjs';
4
3
  import 'zod';
4
+ import '../../base-BYQKp9TW.mjs';
5
5
 
6
6
  /**
7
7
  * Azure OpenAI Provider
@@ -1,7 +1,7 @@
1
- import { b as AzureProviderConfig, A as AIProvider } from '../../types-BctsnC3g.js';
2
- import '../../base-iGi9Va6Z.js';
3
- import '../../types-CR8mi9I0.js';
1
+ import { b as AzureProviderConfig, A as AIProvider } from '../../types-TMilS-Dz.js';
2
+ import '../../types-D774b0dg.js';
4
3
  import 'zod';
4
+ import '../../base-Cxq3ni0t.js';
5
5
 
6
6
  /**
7
7
  * Azure OpenAI Provider
@@ -75,6 +75,52 @@ function parameterToJsonSchema(param) {
75
75
  }
76
76
  return schema;
77
77
  }
78
+ function normalizeObjectJsonSchema(schema) {
79
+ if (!schema || typeof schema !== "object") {
80
+ return {
81
+ type: "object",
82
+ properties: {},
83
+ required: [],
84
+ additionalProperties: false
85
+ };
86
+ }
87
+ const normalized = { ...schema };
88
+ const type = normalized.type;
89
+ if (type === "object") {
90
+ const properties = normalized.properties && typeof normalized.properties === "object" && !Array.isArray(normalized.properties) ? normalized.properties : {};
91
+ normalized.properties = Object.fromEntries(
92
+ Object.entries(properties).map(([key, value]) => [
93
+ key,
94
+ normalizeObjectJsonSchema(value)
95
+ ])
96
+ );
97
+ const propertyKeys = Object.keys(properties);
98
+ const required = Array.isArray(normalized.required) ? normalized.required.filter(
99
+ (value) => typeof value === "string"
100
+ ) : [];
101
+ normalized.required = Array.from(/* @__PURE__ */ new Set([...required, ...propertyKeys]));
102
+ if (normalized.additionalProperties === void 0) {
103
+ normalized.additionalProperties = false;
104
+ }
105
+ } else if (type === "array" && normalized.items && typeof normalized.items === "object") {
106
+ normalized.items = normalizeObjectJsonSchema(
107
+ normalized.items
108
+ );
109
+ }
110
+ return normalized;
111
+ }
112
+ function toOpenAIResponseFormat(rf) {
113
+ if (!rf) return void 0;
114
+ if (rf.type === "json_object") return { type: "json_object" };
115
+ return {
116
+ type: "json_schema",
117
+ json_schema: {
118
+ name: rf.json_schema.name,
119
+ schema: normalizeObjectJsonSchema(rf.json_schema.schema),
120
+ strict: rf.json_schema.strict ?? true
121
+ }
122
+ };
123
+ }
78
124
  function formatTools(actions) {
79
125
  return actions.map((action) => ({
80
126
  type: "function",
@@ -256,6 +302,7 @@ var AzureAdapter = class {
256
302
  tools,
257
303
  temperature: request.config?.temperature ?? this.config.temperature,
258
304
  max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
305
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat),
259
306
  stream: true
260
307
  };
261
308
  logProviderPayload("azure", "request payload", payload, request.debug);
@@ -355,7 +402,8 @@ var AzureAdapter = class {
355
402
  messages,
356
403
  tools,
357
404
  temperature: request.config?.temperature ?? this.config.temperature,
358
- max_tokens: request.config?.maxTokens ?? this.config.maxTokens
405
+ max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
406
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat)
359
407
  };
360
408
  logProviderPayload("azure", "request payload", payload, request.debug);
361
409
  const response = await client.chat.completions.create(payload);
@@ -73,6 +73,52 @@ function parameterToJsonSchema(param) {
73
73
  }
74
74
  return schema;
75
75
  }
76
+ function normalizeObjectJsonSchema(schema) {
77
+ if (!schema || typeof schema !== "object") {
78
+ return {
79
+ type: "object",
80
+ properties: {},
81
+ required: [],
82
+ additionalProperties: false
83
+ };
84
+ }
85
+ const normalized = { ...schema };
86
+ const type = normalized.type;
87
+ if (type === "object") {
88
+ const properties = normalized.properties && typeof normalized.properties === "object" && !Array.isArray(normalized.properties) ? normalized.properties : {};
89
+ normalized.properties = Object.fromEntries(
90
+ Object.entries(properties).map(([key, value]) => [
91
+ key,
92
+ normalizeObjectJsonSchema(value)
93
+ ])
94
+ );
95
+ const propertyKeys = Object.keys(properties);
96
+ const required = Array.isArray(normalized.required) ? normalized.required.filter(
97
+ (value) => typeof value === "string"
98
+ ) : [];
99
+ normalized.required = Array.from(/* @__PURE__ */ new Set([...required, ...propertyKeys]));
100
+ if (normalized.additionalProperties === void 0) {
101
+ normalized.additionalProperties = false;
102
+ }
103
+ } else if (type === "array" && normalized.items && typeof normalized.items === "object") {
104
+ normalized.items = normalizeObjectJsonSchema(
105
+ normalized.items
106
+ );
107
+ }
108
+ return normalized;
109
+ }
110
+ function toOpenAIResponseFormat(rf) {
111
+ if (!rf) return void 0;
112
+ if (rf.type === "json_object") return { type: "json_object" };
113
+ return {
114
+ type: "json_schema",
115
+ json_schema: {
116
+ name: rf.json_schema.name,
117
+ schema: normalizeObjectJsonSchema(rf.json_schema.schema),
118
+ strict: rf.json_schema.strict ?? true
119
+ }
120
+ };
121
+ }
76
122
  function formatTools(actions) {
77
123
  return actions.map((action) => ({
78
124
  type: "function",
@@ -254,6 +300,7 @@ var AzureAdapter = class {
254
300
  tools,
255
301
  temperature: request.config?.temperature ?? this.config.temperature,
256
302
  max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
303
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat),
257
304
  stream: true
258
305
  };
259
306
  logProviderPayload("azure", "request payload", payload, request.debug);
@@ -353,7 +400,8 @@ var AzureAdapter = class {
353
400
  messages,
354
401
  tools,
355
402
  temperature: request.config?.temperature ?? this.config.temperature,
356
- max_tokens: request.config?.maxTokens ?? this.config.maxTokens
403
+ max_tokens: request.config?.maxTokens ?? this.config.maxTokens,
404
+ response_format: toOpenAIResponseFormat(request.config?.responseFormat)
357
405
  };
358
406
  logProviderPayload("azure", "request payload", payload, request.debug);
359
407
  const response = await client.chat.completions.create(payload);
@@ -1,4 +1,4 @@
1
- import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
1
+ import { L as LanguageModel } from '../../types-D774b0dg.mjs';
2
2
  import 'zod';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { L as LanguageModel } from '../../types-CR8mi9I0.js';
1
+ import { L as LanguageModel } from '../../types-D774b0dg.js';
2
2
  import 'zod';
3
3
 
4
4
  /**
@@ -1,5 +1,53 @@
1
1
  'use strict';
2
2
 
3
+ // src/adapters/base.ts
4
+ function normalizeObjectJsonSchema(schema) {
5
+ if (!schema || typeof schema !== "object") {
6
+ return {
7
+ type: "object",
8
+ properties: {},
9
+ required: [],
10
+ additionalProperties: false
11
+ };
12
+ }
13
+ const normalized = { ...schema };
14
+ const type = normalized.type;
15
+ if (type === "object") {
16
+ const properties = normalized.properties && typeof normalized.properties === "object" && !Array.isArray(normalized.properties) ? normalized.properties : {};
17
+ normalized.properties = Object.fromEntries(
18
+ Object.entries(properties).map(([key, value]) => [
19
+ key,
20
+ normalizeObjectJsonSchema(value)
21
+ ])
22
+ );
23
+ const propertyKeys = Object.keys(properties);
24
+ const required = Array.isArray(normalized.required) ? normalized.required.filter(
25
+ (value) => typeof value === "string"
26
+ ) : [];
27
+ normalized.required = Array.from(/* @__PURE__ */ new Set([...required, ...propertyKeys]));
28
+ if (normalized.additionalProperties === void 0) {
29
+ normalized.additionalProperties = false;
30
+ }
31
+ } else if (type === "array" && normalized.items && typeof normalized.items === "object") {
32
+ normalized.items = normalizeObjectJsonSchema(
33
+ normalized.items
34
+ );
35
+ }
36
+ return normalized;
37
+ }
38
+ function toOpenAIResponseFormat(rf) {
39
+ if (!rf) return void 0;
40
+ if (rf.type === "json_object") return { type: "json_object" };
41
+ return {
42
+ type: "json_schema",
43
+ json_schema: {
44
+ name: rf.json_schema.name,
45
+ schema: normalizeObjectJsonSchema(rf.json_schema.schema),
46
+ strict: rf.json_schema.strict ?? true
47
+ }
48
+ };
49
+ }
50
+
3
51
  // src/providers/fireworks/provider.ts
4
52
  function fireworks(modelId, options = {}) {
5
53
  const apiKey = options.apiKey ?? process.env.FIREWORKS_API_KEY;
@@ -37,6 +85,10 @@ function fireworks(modelId, options = {}) {
37
85
  if (params.tools) {
38
86
  requestBody.tools = params.tools;
39
87
  }
88
+ const responseFormat = toOpenAIResponseFormat(params.responseFormat);
89
+ if (responseFormat) {
90
+ requestBody.response_format = responseFormat;
91
+ }
40
92
  const response = await client2.chat.completions.create(requestBody);
41
93
  const choice = response.choices[0];
42
94
  const message = choice.message;
@@ -72,6 +124,10 @@ function fireworks(modelId, options = {}) {
72
124
  if (params.tools) {
73
125
  requestBody.tools = params.tools;
74
126
  }
127
+ const responseFormat = toOpenAIResponseFormat(params.responseFormat);
128
+ if (responseFormat) {
129
+ requestBody.response_format = responseFormat;
130
+ }
75
131
  const stream = await client2.chat.completions.create(requestBody);
76
132
  const toolCallMap = /* @__PURE__ */ new Map();
77
133
  let totalPromptTokens = 0;
@@ -1,3 +1,51 @@
1
+ // src/adapters/base.ts
2
+ function normalizeObjectJsonSchema(schema) {
3
+ if (!schema || typeof schema !== "object") {
4
+ return {
5
+ type: "object",
6
+ properties: {},
7
+ required: [],
8
+ additionalProperties: false
9
+ };
10
+ }
11
+ const normalized = { ...schema };
12
+ const type = normalized.type;
13
+ if (type === "object") {
14
+ const properties = normalized.properties && typeof normalized.properties === "object" && !Array.isArray(normalized.properties) ? normalized.properties : {};
15
+ normalized.properties = Object.fromEntries(
16
+ Object.entries(properties).map(([key, value]) => [
17
+ key,
18
+ normalizeObjectJsonSchema(value)
19
+ ])
20
+ );
21
+ const propertyKeys = Object.keys(properties);
22
+ const required = Array.isArray(normalized.required) ? normalized.required.filter(
23
+ (value) => typeof value === "string"
24
+ ) : [];
25
+ normalized.required = Array.from(/* @__PURE__ */ new Set([...required, ...propertyKeys]));
26
+ if (normalized.additionalProperties === void 0) {
27
+ normalized.additionalProperties = false;
28
+ }
29
+ } else if (type === "array" && normalized.items && typeof normalized.items === "object") {
30
+ normalized.items = normalizeObjectJsonSchema(
31
+ normalized.items
32
+ );
33
+ }
34
+ return normalized;
35
+ }
36
+ function toOpenAIResponseFormat(rf) {
37
+ if (!rf) return void 0;
38
+ if (rf.type === "json_object") return { type: "json_object" };
39
+ return {
40
+ type: "json_schema",
41
+ json_schema: {
42
+ name: rf.json_schema.name,
43
+ schema: normalizeObjectJsonSchema(rf.json_schema.schema),
44
+ strict: rf.json_schema.strict ?? true
45
+ }
46
+ };
47
+ }
48
+
1
49
  // src/providers/fireworks/provider.ts
2
50
  function fireworks(modelId, options = {}) {
3
51
  const apiKey = options.apiKey ?? process.env.FIREWORKS_API_KEY;
@@ -35,6 +83,10 @@ function fireworks(modelId, options = {}) {
35
83
  if (params.tools) {
36
84
  requestBody.tools = params.tools;
37
85
  }
86
+ const responseFormat = toOpenAIResponseFormat(params.responseFormat);
87
+ if (responseFormat) {
88
+ requestBody.response_format = responseFormat;
89
+ }
38
90
  const response = await client2.chat.completions.create(requestBody);
39
91
  const choice = response.choices[0];
40
92
  const message = choice.message;
@@ -70,6 +122,10 @@ function fireworks(modelId, options = {}) {
70
122
  if (params.tools) {
71
123
  requestBody.tools = params.tools;
72
124
  }
125
+ const responseFormat = toOpenAIResponseFormat(params.responseFormat);
126
+ if (responseFormat) {
127
+ requestBody.response_format = responseFormat;
128
+ }
73
129
  const stream = await client2.chat.completions.create(requestBody);
74
130
  const toolCallMap = /* @__PURE__ */ new Map();
75
131
  let totalPromptTokens = 0;
@@ -1,7 +1,7 @@
1
- import { L as LanguageModel } from '../../types-CR8mi9I0.mjs';
2
- import { G as GoogleProviderConfig, A as AIProvider } from '../../types-DRqxMIjF.mjs';
1
+ import { L as LanguageModel } from '../../types-D774b0dg.mjs';
2
+ import { G as GoogleProviderConfig, A as AIProvider } from '../../types-BvkiJ1dd.mjs';
3
3
  import 'zod';
4
- import '../../base-D-U61JaB.mjs';
4
+ import '../../base-BYQKp9TW.mjs';
5
5
 
6
6
  /**
7
7
  * Google Provider - OpenAI-Compatible
@@ -1,7 +1,7 @@
1
- import { L as LanguageModel } from '../../types-CR8mi9I0.js';
2
- import { G as GoogleProviderConfig, A as AIProvider } from '../../types-BctsnC3g.js';
1
+ import { L as LanguageModel } from '../../types-D774b0dg.js';
2
+ import { G as GoogleProviderConfig, A as AIProvider } from '../../types-TMilS-Dz.js';
3
3
  import 'zod';
4
- import '../../base-iGi9Va6Z.js';
4
+ import '../../base-Cxq3ni0t.js';
5
5
 
6
6
  /**
7
7
  * Google Provider - OpenAI-Compatible