@yourgpt/llm-sdk 2.1.10-alpha.0 → 2.5.1-beta.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 (59) hide show
  1. package/dist/adapters/index.d.mts +4 -38
  2. package/dist/adapters/index.d.ts +4 -38
  3. package/dist/adapters/index.js +158 -325
  4. package/dist/adapters/index.mjs +158 -325
  5. package/dist/base-C58Dsr9p.d.ts +259 -0
  6. package/dist/base-tNgbBaSo.d.mts +259 -0
  7. package/dist/fallback/index.d.mts +4 -4
  8. package/dist/fallback/index.d.ts +4 -4
  9. package/dist/index.d.mts +8 -7
  10. package/dist/index.d.ts +8 -7
  11. package/dist/index.js +35 -43
  12. package/dist/index.mjs +35 -43
  13. package/dist/providers/anthropic/index.d.mts +3 -3
  14. package/dist/providers/anthropic/index.d.ts +3 -3
  15. package/dist/providers/anthropic/index.js +271 -212
  16. package/dist/providers/anthropic/index.mjs +271 -212
  17. package/dist/providers/azure/index.d.mts +3 -3
  18. package/dist/providers/azure/index.d.ts +3 -3
  19. package/dist/providers/azure/index.js +49 -1
  20. package/dist/providers/azure/index.mjs +49 -1
  21. package/dist/providers/fireworks/index.d.mts +1 -1
  22. package/dist/providers/fireworks/index.d.ts +1 -1
  23. package/dist/providers/fireworks/index.js +56 -0
  24. package/dist/providers/fireworks/index.mjs +56 -0
  25. package/dist/providers/google/index.d.mts +3 -3
  26. package/dist/providers/google/index.d.ts +3 -3
  27. package/dist/providers/google/index.js +254 -510
  28. package/dist/providers/google/index.mjs +254 -510
  29. package/dist/providers/ollama/index.d.mts +4 -4
  30. package/dist/providers/ollama/index.d.ts +4 -4
  31. package/dist/providers/ollama/index.js +10 -2
  32. package/dist/providers/ollama/index.mjs +10 -2
  33. package/dist/providers/openai/index.d.mts +3 -3
  34. package/dist/providers/openai/index.d.ts +3 -3
  35. package/dist/providers/openai/index.js +269 -529
  36. package/dist/providers/openai/index.mjs +269 -529
  37. package/dist/providers/openrouter/index.d.mts +3 -7
  38. package/dist/providers/openrouter/index.d.ts +3 -7
  39. package/dist/providers/openrouter/index.js +365 -902
  40. package/dist/providers/openrouter/index.mjs +365 -902
  41. package/dist/providers/togetherai/index.d.mts +3 -3
  42. package/dist/providers/togetherai/index.d.ts +3 -3
  43. package/dist/providers/togetherai/index.js +259 -509
  44. package/dist/providers/togetherai/index.mjs +259 -509
  45. package/dist/providers/xai/index.d.mts +3 -3
  46. package/dist/providers/xai/index.d.ts +3 -3
  47. package/dist/providers/xai/index.js +258 -513
  48. package/dist/providers/xai/index.mjs +258 -513
  49. package/dist/{types-BNCmlJMs.d.mts → types-B6dhnguR.d.mts} +1 -1
  50. package/dist/{types-DhktekQ3.d.ts → types-BQ31QIsA.d.ts} +2 -1
  51. package/dist/{types-CMMQ8s2O.d.mts → types-BSSiJW2o.d.mts} +2 -1
  52. package/dist/{base-DN1EfKnE.d.mts → types-BkQCSiIt.d.mts} +388 -214
  53. package/dist/{base-DuUNxtVg.d.ts → types-BkQCSiIt.d.ts} +388 -214
  54. package/dist/{types-Pj-vpmoT.d.ts → types-CCxPmkmK.d.ts} +1 -1
  55. package/dist/yourgpt/index.d.mts +1 -1
  56. package/dist/yourgpt/index.d.ts +1 -1
  57. package/package.json +1 -1
  58. package/dist/types-CMvvDo-E.d.mts +0 -428
  59. package/dist/types-CMvvDo-E.d.ts +0 -428
@@ -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-CMvvDo-E.mjs';
1
+ import { L as LanguageModel } from '../../types-BkQCSiIt.mjs';
2
2
  import 'zod';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { L as LanguageModel } from '../../types-CMvvDo-E.js';
1
+ import { L as LanguageModel } from '../../types-BkQCSiIt.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-CMvvDo-E.mjs';
2
- import { G as GoogleProviderConfig, A as AIProvider } from '../../types-CMMQ8s2O.mjs';
1
+ import { L as LanguageModel } from '../../types-BkQCSiIt.mjs';
2
+ import { G as GoogleProviderConfig, A as AIProvider } from '../../types-BSSiJW2o.mjs';
3
3
  import 'zod';
4
- import '../../base-DN1EfKnE.mjs';
4
+ import '../../base-tNgbBaSo.mjs';
5
5
 
6
6
  /**
7
7
  * Google Provider - OpenAI-Compatible
@@ -1,7 +1,7 @@
1
- import { L as LanguageModel } from '../../types-CMvvDo-E.js';
2
- import { G as GoogleProviderConfig, A as AIProvider } from '../../types-DhktekQ3.js';
1
+ import { L as LanguageModel } from '../../types-BkQCSiIt.js';
2
+ import { G as GoogleProviderConfig, A as AIProvider } from '../../types-BQ31QIsA.js';
3
3
  import 'zod';
4
- import '../../base-DuUNxtVg.js';
4
+ import '../../base-C58Dsr9p.js';
5
5
 
6
6
  /**
7
7
  * Google Provider - OpenAI-Compatible