modelfusion 0.47.0 → 0.47.2

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 (100) hide show
  1. package/README.md +37 -36
  2. package/core/structure/Schema.d.ts +5 -5
  3. package/core/structure/UncheckedSchema.cjs +2 -2
  4. package/core/structure/UncheckedSchema.d.ts +2 -2
  5. package/core/structure/UncheckedSchema.js +2 -2
  6. package/core/structure/ZodSchema.cjs +2 -5
  7. package/core/structure/ZodSchema.d.ts +2 -2
  8. package/core/structure/ZodSchema.js +2 -5
  9. package/event-source/readEventSource.cjs +5 -8
  10. package/event-source/readEventSource.d.ts +1 -1
  11. package/event-source/readEventSource.js +5 -5
  12. package/event-source/readEventSourceStream.cjs +3 -6
  13. package/event-source/readEventSourceStream.js +3 -3
  14. package/guard/fixStructure.cjs +50 -0
  15. package/guard/fixStructure.d.ts +50 -0
  16. package/guard/fixStructure.js +50 -0
  17. package/guard/guard.d.ts +1 -1
  18. package/model-function/generate-structure/fixJson.test.cjs +183 -181
  19. package/model-function/generate-structure/fixJson.test.js +181 -182
  20. package/model-function/generate-structure/generateStructure.cjs +1 -1
  21. package/model-function/generate-structure/generateStructure.js +1 -1
  22. package/model-function/generate-structure/generateStructureOrText.cjs +1 -1
  23. package/model-function/generate-structure/generateStructureOrText.js +1 -1
  24. package/model-function/generate-structure/streamStructure.cjs +3 -8
  25. package/model-function/generate-structure/streamStructure.js +3 -5
  26. package/model-provider/anthropic/AnthropicError.cjs +7 -14
  27. package/model-provider/anthropic/AnthropicError.js +7 -11
  28. package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +2 -15
  29. package/model-provider/anthropic/AnthropicTextGenerationModel.js +2 -12
  30. package/model-provider/automatic1111/Automatic1111Error.cjs +2 -5
  31. package/model-provider/automatic1111/Automatic1111Error.d.ts +1 -1
  32. package/model-provider/automatic1111/Automatic1111Error.js +2 -2
  33. package/model-provider/cohere/CohereError.cjs +2 -5
  34. package/model-provider/cohere/CohereError.js +2 -2
  35. package/model-provider/cohere/CohereTextEmbeddingModel.cjs +8 -11
  36. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +1 -1
  37. package/model-provider/cohere/CohereTextEmbeddingModel.js +1 -1
  38. package/model-provider/cohere/CohereTextGenerationModel.cjs +22 -21
  39. package/model-provider/cohere/CohereTextGenerationModel.js +22 -18
  40. package/model-provider/cohere/CohereTokenizer.cjs +12 -15
  41. package/model-provider/cohere/CohereTokenizer.d.ts +1 -1
  42. package/model-provider/cohere/CohereTokenizer.js +1 -1
  43. package/model-provider/huggingface/HuggingFaceError.cjs +7 -31
  44. package/model-provider/huggingface/HuggingFaceError.js +7 -28
  45. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.cjs +3 -6
  46. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.d.ts +1 -1
  47. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.js +1 -1
  48. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +2 -5
  49. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +1 -1
  50. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +1 -1
  51. package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +3 -6
  52. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +1 -1
  53. package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +1 -1
  54. package/model-provider/llamacpp/LlamaCppError.cjs +7 -30
  55. package/model-provider/llamacpp/LlamaCppError.js +7 -27
  56. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +3 -6
  57. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +1 -1
  58. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +1 -1
  59. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +53 -66
  60. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +1 -1
  61. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +3 -13
  62. package/model-provider/llamacpp/LlamaCppTokenizer.cjs +3 -6
  63. package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +1 -1
  64. package/model-provider/llamacpp/LlamaCppTokenizer.js +1 -1
  65. package/model-provider/openai/OpenAIError.cjs +2 -5
  66. package/model-provider/openai/OpenAIError.js +2 -2
  67. package/model-provider/openai/OpenAITextEmbeddingModel.cjs +11 -14
  68. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +1 -1
  69. package/model-provider/openai/OpenAITextEmbeddingModel.js +1 -1
  70. package/model-provider/openai/OpenAITextGenerationModel.cjs +26 -39
  71. package/model-provider/openai/OpenAITextGenerationModel.d.ts +1 -1
  72. package/model-provider/openai/OpenAITextGenerationModel.js +3 -13
  73. package/model-provider/openai/OpenAITranscriptionModel.cjs +20 -23
  74. package/model-provider/openai/OpenAITranscriptionModel.d.ts +1 -1
  75. package/model-provider/openai/OpenAITranscriptionModel.js +1 -1
  76. package/model-provider/openai/chat/OpenAIChatModel.cjs +21 -21
  77. package/model-provider/openai/chat/OpenAIChatModel.d.ts +1 -1
  78. package/model-provider/openai/chat/OpenAIChatModel.js +2 -2
  79. package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +2 -6
  80. package/model-provider/openai/chat/OpenAIChatStreamIterable.js +2 -3
  81. package/model-provider/stability/StabilityError.cjs +2 -5
  82. package/model-provider/stability/StabilityError.js +2 -2
  83. package/package.json +4 -4
  84. package/util/JSONParseError.cjs +33 -0
  85. package/util/JSONParseError.d.ts +9 -0
  86. package/util/JSONParseError.js +29 -0
  87. package/util/index.cjs +2 -0
  88. package/util/index.d.ts +2 -0
  89. package/util/index.js +2 -0
  90. package/util/isDeepEqualData.cjs +53 -0
  91. package/util/isDeepEqualData.d.ts +8 -0
  92. package/util/isDeepEqualData.js +49 -0
  93. package/util/isDeepEqualData.test.cjs +108 -0
  94. package/util/isDeepEqualData.test.d.ts +1 -0
  95. package/util/isDeepEqualData.test.js +103 -0
  96. package/util/parseJSON.cjs +67 -0
  97. package/util/parseJSON.d.ts +18 -0
  98. package/util/parseJSON.js +58 -0
  99. package/vector-index/memory/MemoryVectorIndex.cjs +7 -10
  100. package/vector-index/memory/MemoryVectorIndex.js +3 -3
@@ -1,184 +1,183 @@
1
- import { expect, test, describe } from "vitest";
2
- import { fixJson } from "./fixJson";
3
- describe("fixJson", () => {
4
- test("should handle empty input", () => {
5
- expect(fixJson("")).toBe("");
6
- });
7
- describe("literals", () => {
8
- test("should handle incomplete null", () => {
9
- expect(fixJson("nul")).toBe("null");
10
- });
11
- test("should handle incomplete true", () => {
12
- expect(fixJson("t")).toBe("true");
13
- });
14
- test("should handle incomplete false", () => {
15
- expect(fixJson("fals")).toBe("false");
16
- });
17
- });
18
- describe("number", () => {
19
- test("should handle incomplete numbers", () => {
20
- expect(fixJson("12.")).toBe("12");
21
- });
22
- test("should handle numbers with dot", () => {
23
- expect(fixJson("12.2")).toBe("12.2");
24
- });
25
- test("should handle negative numbers", () => {
26
- expect(fixJson("-12")).toBe("-12");
27
- });
28
- test("should handle incomplete negative numbers", () => {
29
- expect(fixJson("-")).toBe("");
30
- });
31
- test("should handle e-notation numbers", () => {
32
- expect(fixJson("2.5e")).toBe("2.5");
33
- expect(fixJson("2.5e-")).toBe("2.5");
34
- expect(fixJson("2.5e3")).toBe("2.5e3");
35
- expect(fixJson("-2.5e3")).toBe("-2.5e3");
36
- });
37
- test("should handle uppercase e-notation numbers", () => {
38
- expect(fixJson("2.5E")).toBe("2.5");
39
- expect(fixJson("2.5E-")).toBe("2.5");
40
- expect(fixJson("2.5E3")).toBe("2.5E3");
41
- expect(fixJson("-2.5E3")).toBe("-2.5E3");
42
- });
43
- test("should handle incomplete numbers", () => {
44
- expect(fixJson("12.e")).toBe("12");
45
- expect(fixJson("12.34e")).toBe("12.34");
46
- expect(fixJson("5e")).toBe("5");
47
- });
48
- });
49
- describe("string", () => {
50
- test("should handle incomplete strings", () => {
51
- expect(fixJson('"abc')).toBe('"abc"');
52
- });
53
- test("should handle escape sequences", () => {
54
- expect(fixJson('"value with \\"quoted\\" text and \\\\ escape')).toBe('"value with \\"quoted\\" text and \\\\ escape"');
55
- });
56
- test("should handle incomplete escape sequences", () => {
57
- expect(fixJson('"value with \\')).toBe('"value with "');
58
- });
59
- test("should handle unicode characters", () => {
60
- expect(fixJson('"value with unicode \u003C"')).toBe('"value with unicode \u003C"');
61
- });
62
- });
63
- describe("array", () => {
64
- test("should handle incomplete array", () => {
65
- expect(fixJson("[")).toBe("[]");
66
- });
67
- test("should handle closing bracket after number in array", () => {
68
- expect(fixJson("[[1], [2")).toBe("[[1], [2]]");
69
- });
70
- test("should handle closing bracket after string in array", () => {
71
- expect(fixJson(`[["1"], ["2`)).toBe(`[["1"], ["2"]]`);
72
- });
73
- test("should handle closing bracket after literal in array", () => {
74
- expect(fixJson("[[false], [nu")).toBe("[[false], [null]]");
75
- });
76
- test("should handle closing bracket after array in array", () => {
77
- expect(fixJson("[[[]], [[]")).toBe("[[[]], [[]]]");
78
- });
79
- test("should handle closing bracket after object in array", () => {
80
- expect(fixJson("[[{}], [{")).toBe("[[{}], [{}]]");
81
- });
82
- test("should handle trailing comma", () => {
83
- expect(fixJson("[1, ")).toBe("[1]");
84
- });
85
- test("should handle closing array", () => {
86
- expect(fixJson("[[], 123")).toBe("[[], 123]");
87
- });
88
- });
89
- describe("object", () => {
90
- test("should handle keys without values", () => {
91
- expect(fixJson('{"key":')).toBe("{}");
92
- });
93
- test("should handle closing brace after number in object", () => {
94
- expect(fixJson('{"a": {"b": 1}, "c": {"d": 2')).toBe('{"a": {"b": 1}, "c": {"d": 2}}');
95
- });
96
- test("should handle closing brace after string in object", () => {
97
- expect(fixJson('{"a": {"b": "1"}, "c": {"d": 2')).toBe('{"a": {"b": "1"}, "c": {"d": 2}}');
98
- });
99
- test("should handle closing brace after literal in object", () => {
100
- expect(fixJson('{"a": {"b": false}, "c": {"d": 2')).toBe('{"a": {"b": false}, "c": {"d": 2}}');
101
- });
102
- test("should handle closing brace after array in object", () => {
103
- expect(fixJson('{"a": {"b": []}, "c": {"d": 2')).toBe('{"a": {"b": []}, "c": {"d": 2}}');
104
- });
105
- test("should handle closing brace after object in object", () => {
106
- expect(fixJson('{"a": {"b": {}}, "c": {"d": 2')).toBe('{"a": {"b": {}}, "c": {"d": 2}}');
107
- });
108
- test("should handle partial keys (first key)", () => {
109
- expect(fixJson('{"ke')).toBe("{}");
110
- });
111
- test("should handle partial keys (second key)", () => {
112
- expect(fixJson('{"k1": 1, "k2')).toBe('{"k1": 1}');
113
- });
114
- test("should handle partial keys with colon (second key)", () => {
115
- expect(fixJson('{"k1": 1, "k2":')).toBe('{"k1": 1}');
116
- });
117
- test("should handle trailing whitespaces", () => {
118
- expect(fixJson('{"key": "value" ')).toBe('{"key": "value"}');
119
- });
120
- });
121
- describe("nesting", () => {
122
- test("should handle nested arrays with numbers", () => {
123
- expect(fixJson("[1, [2, 3, [")).toBe("[1, [2, 3, []]]");
124
- });
125
- test("should handle nested arrays with literals", () => {
126
- expect(fixJson("[false, [true, [")).toBe("[false, [true, []]]");
127
- });
128
- test("should handle nested objects", () => {
129
- expect(fixJson('{"key": {"subKey":')).toBe('{"key": {}}');
130
- });
131
- test("should handle nested objects with numbers", () => {
132
- expect(fixJson('{"key": 123, "key2": {"subKey":')).toBe('{"key": 123, "key2": {}}');
133
- });
134
- test("should handle nested objects with literals", () => {
135
- expect(fixJson('{"key": null, "key2": {"subKey":')).toBe('{"key": null, "key2": {}}');
136
- });
137
- test("should handle arrays within objects", () => {
138
- expect(fixJson('{"key": [1, 2, {')).toBe('{"key": [1, 2, {}]}');
139
- });
140
- test("should handle objects within arrays", () => {
141
- expect(fixJson('[1, 2, {"key": "value",')).toBe('[1, 2, {"key": "value"}]');
142
- });
143
- test("should handle nested arrays and objects", () => {
144
- expect(fixJson('{"a": {"b": ["c", {"d": "e",')).toBe('{"a": {"b": ["c", {"d": "e"}]}}');
145
- });
146
- test("should handle deeply nested structures", () => {
147
- expect(fixJson('{"a": {"b": {"c": {"d":')).toBe('{"a": {"b": {"c": {}}}}');
148
- });
149
- test("should handle potential nested arrays or objects", () => {
150
- expect(fixJson('{"a": 1, "b": [')).toBe('{"a": 1, "b": []}');
151
- expect(fixJson('{"a": 1, "b": {')).toBe('{"a": 1, "b": {}}');
152
- expect(fixJson('{"a": 1, "b": "')).toBe('{"a": 1, "b": ""}');
153
- });
154
- });
155
- describe("regression", () => {
156
- test("should handle complex nesting 1", () => {
157
- expect(fixJson([
158
- "{",
159
- ' "a": [',
160
- " {",
161
- ' "a1": "v1",',
162
- ' "a2": "v2",',
163
- ` "a3": "v3"`,
164
- " }",
165
- " ],",
166
- ' "b": [',
167
- " {",
168
- ' "b1": "n',
169
- ].join("\n"))).toBe([
170
- "{",
171
- ' "a": [',
172
- " {",
173
- ' "a1": "v1",',
174
- ' "a2": "v2",',
175
- ` "a3": "v3"`,
176
- " }",
177
- " ],",
178
- ' "b": [',
179
- " {",
180
- ' "b1": "n"}]}',
181
- ].join("\n"));
182
- });
1
+ import assert from "node:assert";
2
+ import { test, describe } from "vitest";
3
+ import { fixJson } from "./fixJson.js";
4
+ test("should handle empty input", () => {
5
+ assert.strictEqual(fixJson(""), "");
6
+ });
7
+ describe("literals", () => {
8
+ test("should handle incomplete null", () => {
9
+ assert.strictEqual(fixJson("nul"), "null");
10
+ });
11
+ test("should handle incomplete true", () => {
12
+ assert.strictEqual(fixJson("t"), "true");
13
+ });
14
+ test("should handle incomplete false", () => {
15
+ assert.strictEqual(fixJson("fals"), "false");
16
+ });
17
+ });
18
+ describe("number", () => {
19
+ test("should handle incomplete numbers", () => {
20
+ assert.strictEqual(fixJson("12."), "12");
21
+ });
22
+ test("should handle numbers with dot", () => {
23
+ assert.strictEqual(fixJson("12.2"), "12.2");
24
+ });
25
+ test("should handle negative numbers", () => {
26
+ assert.strictEqual(fixJson("-12"), "-12");
27
+ });
28
+ test("should handle incomplete negative numbers", () => {
29
+ assert.strictEqual(fixJson("-"), "");
30
+ });
31
+ test("should handle e-notation numbers", () => {
32
+ assert.strictEqual(fixJson("2.5e"), "2.5");
33
+ assert.strictEqual(fixJson("2.5e-"), "2.5");
34
+ assert.strictEqual(fixJson("2.5e3"), "2.5e3");
35
+ assert.strictEqual(fixJson("-2.5e3"), "-2.5e3");
36
+ });
37
+ test("should handle uppercase e-notation numbers", () => {
38
+ assert.strictEqual(fixJson("2.5E"), "2.5");
39
+ assert.strictEqual(fixJson("2.5E-"), "2.5");
40
+ assert.strictEqual(fixJson("2.5E3"), "2.5E3");
41
+ assert.strictEqual(fixJson("-2.5E3"), "-2.5E3");
42
+ });
43
+ test("should handle incomplete numbers", () => {
44
+ assert.strictEqual(fixJson("12.e"), "12");
45
+ assert.strictEqual(fixJson("12.34e"), "12.34");
46
+ assert.strictEqual(fixJson("5e"), "5");
47
+ });
48
+ });
49
+ describe("string", () => {
50
+ test("should handle incomplete strings", () => {
51
+ assert.strictEqual(fixJson('"abc'), '"abc"');
52
+ });
53
+ test("should handle escape sequences", () => {
54
+ assert.strictEqual(fixJson('"value with \\"quoted\\" text and \\\\ escape'), '"value with \\"quoted\\" text and \\\\ escape"');
55
+ });
56
+ test("should handle incomplete escape sequences", () => {
57
+ assert.strictEqual(fixJson('"value with \\'), '"value with "');
58
+ });
59
+ test("should handle unicode characters", () => {
60
+ assert.strictEqual(fixJson('"value with unicode \u003C"'), '"value with unicode \u003C"');
61
+ });
62
+ });
63
+ describe("array", () => {
64
+ test("should handle incomplete array", () => {
65
+ assert.strictEqual(fixJson("["), "[]");
66
+ });
67
+ test("should handle closing bracket after number in array", () => {
68
+ assert.strictEqual(fixJson("[[1], [2"), "[[1], [2]]");
69
+ });
70
+ test("should handle closing bracket after string in array", () => {
71
+ assert.strictEqual(fixJson(`[["1"], ["2`), `[["1"], ["2"]]`);
72
+ });
73
+ test("should handle closing bracket after literal in array", () => {
74
+ assert.strictEqual(fixJson("[[false], [nu"), "[[false], [null]]");
75
+ });
76
+ test("should handle closing bracket after array in array", () => {
77
+ assert.strictEqual(fixJson("[[[]], [[]"), "[[[]], [[]]]");
78
+ });
79
+ test("should handle closing bracket after object in array", () => {
80
+ assert.strictEqual(fixJson("[[{}], [{"), "[[{}], [{}]]");
81
+ });
82
+ test("should handle trailing comma", () => {
83
+ assert.strictEqual(fixJson("[1, "), "[1]");
84
+ });
85
+ test("should handle closing array", () => {
86
+ assert.strictEqual(fixJson("[[], 123"), "[[], 123]");
87
+ });
88
+ });
89
+ describe("object", () => {
90
+ test("should handle keys without values", () => {
91
+ assert.strictEqual(fixJson('{"key":'), "{}");
92
+ });
93
+ test("should handle closing brace after number in object", () => {
94
+ assert.strictEqual(fixJson('{"a": {"b": 1}, "c": {"d": 2'), '{"a": {"b": 1}, "c": {"d": 2}}');
95
+ });
96
+ test("should handle closing brace after string in object", () => {
97
+ assert.strictEqual(fixJson('{"a": {"b": "1"}, "c": {"d": 2'), '{"a": {"b": "1"}, "c": {"d": 2}}');
98
+ });
99
+ test("should handle closing brace after literal in object", () => {
100
+ assert.strictEqual(fixJson('{"a": {"b": false}, "c": {"d": 2'), '{"a": {"b": false}, "c": {"d": 2}}');
101
+ });
102
+ test("should handle closing brace after array in object", () => {
103
+ assert.strictEqual(fixJson('{"a": {"b": []}, "c": {"d": 2'), '{"a": {"b": []}, "c": {"d": 2}}');
104
+ });
105
+ test("should handle closing brace after object in object", () => {
106
+ assert.strictEqual(fixJson('{"a": {"b": {}}, "c": {"d": 2'), '{"a": {"b": {}}, "c": {"d": 2}}');
107
+ });
108
+ test("should handle partial keys (first key)", () => {
109
+ assert.strictEqual(fixJson('{"ke'), "{}");
110
+ });
111
+ test("should handle partial keys (second key)", () => {
112
+ assert.strictEqual(fixJson('{"k1": 1, "k2'), '{"k1": 1}');
113
+ });
114
+ test("should handle partial keys with colon (second key)", () => {
115
+ assert.strictEqual(fixJson('{"k1": 1, "k2":'), '{"k1": 1}');
116
+ });
117
+ test("should handle trailing whitespaces", () => {
118
+ assert.strictEqual(fixJson('{"key": "value" '), '{"key": "value"}');
119
+ });
120
+ });
121
+ describe("nesting", () => {
122
+ test("should handle nested arrays with numbers", () => {
123
+ assert.strictEqual(fixJson("[1, [2, 3, ["), "[1, [2, 3, []]]");
124
+ });
125
+ test("should handle nested arrays with literals", () => {
126
+ assert.strictEqual(fixJson("[false, [true, ["), "[false, [true, []]]");
127
+ });
128
+ test("should handle nested objects", () => {
129
+ assert.strictEqual(fixJson('{"key": {"subKey":'), '{"key": {}}');
130
+ });
131
+ test("should handle nested objects with numbers", () => {
132
+ assert.strictEqual(fixJson('{"key": 123, "key2": {"subKey":'), '{"key": 123, "key2": {}}');
133
+ });
134
+ test("should handle nested objects with literals", () => {
135
+ assert.strictEqual(fixJson('{"key": null, "key2": {"subKey":'), '{"key": null, "key2": {}}');
136
+ });
137
+ test("should handle arrays within objects", () => {
138
+ assert.strictEqual(fixJson('{"key": [1, 2, {'), '{"key": [1, 2, {}]}');
139
+ });
140
+ test("should handle objects within arrays", () => {
141
+ assert.strictEqual(fixJson('[1, 2, {"key": "value",'), '[1, 2, {"key": "value"}]');
142
+ });
143
+ test("should handle nested arrays and objects", () => {
144
+ assert.strictEqual(fixJson('{"a": {"b": ["c", {"d": "e",'), '{"a": {"b": ["c", {"d": "e"}]}}');
145
+ });
146
+ test("should handle deeply nested structures", () => {
147
+ assert.strictEqual(fixJson('{"a": {"b": {"c": {"d":'), '{"a": {"b": {"c": {}}}}');
148
+ });
149
+ test("should handle potential nested arrays or objects", () => {
150
+ assert.strictEqual(fixJson('{"a": 1, "b": ['), '{"a": 1, "b": []}');
151
+ assert.strictEqual(fixJson('{"a": 1, "b": {'), '{"a": 1, "b": {}}');
152
+ assert.strictEqual(fixJson('{"a": 1, "b": "'), '{"a": 1, "b": ""}');
153
+ });
154
+ });
155
+ describe("regression", () => {
156
+ test("should handle complex nesting 1", () => {
157
+ assert.strictEqual(fixJson([
158
+ "{",
159
+ ' "a": [',
160
+ " {",
161
+ ' "a1": "v1",',
162
+ ' "a2": "v2",',
163
+ ` "a3": "v3"`,
164
+ " }",
165
+ " ],",
166
+ ' "b": [',
167
+ " {",
168
+ ' "b1": "n',
169
+ ].join("\n")), [
170
+ "{",
171
+ ' "a": [',
172
+ " {",
173
+ ' "a1": "v1",',
174
+ ' "a2": "v2",',
175
+ ` "a3": "v3"`,
176
+ " }",
177
+ " ],",
178
+ ' "b": [',
179
+ " {",
180
+ ' "b1": "n"}]}',
181
+ ].join("\n"));
183
182
  });
184
183
  });
@@ -26,7 +26,7 @@ function generateStructure(model, structureDefinition, prompt, options) {
26
26
  cause: parseResult.error,
27
27
  });
28
28
  }
29
- const value = parseResult.value;
29
+ const value = parseResult.data;
30
30
  return {
31
31
  response: result.response,
32
32
  extractedValue: value,
@@ -23,7 +23,7 @@ export function generateStructure(model, structureDefinition, prompt, options) {
23
23
  cause: parseResult.error,
24
24
  });
25
25
  }
26
- const value = parseResult.value;
26
+ const value = parseResult.data;
27
27
  return {
28
28
  response: result.response,
29
29
  extractedValue: value,
@@ -43,7 +43,7 @@ function generateStructureOrText(model, structureDefinitions, prompt, options) {
43
43
  response: result.response,
44
44
  extractedValue: {
45
45
  structure: structure,
46
- value: parseResult.value,
46
+ value: parseResult.data,
47
47
  text: text, // text is string | null, which is part of the response for schema values
48
48
  },
49
49
  usage: result.usage,
@@ -40,7 +40,7 @@ export function generateStructureOrText(model, structureDefinitions, prompt, opt
40
40
  response: result.response,
41
41
  extractedValue: {
42
42
  structure: structure,
43
- value: parseResult.value,
43
+ value: parseResult.data,
44
44
  text: text, // text is string | null, which is part of the response for schema values
45
45
  },
46
46
  usage: result.usage,
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.streamStructure = void 0;
7
- const deep_equal_1 = __importDefault(require("deep-equal"));
8
4
  const nanoid_1 = require("nanoid");
9
5
  const FunctionEventSource_js_1 = require("../../core/FunctionEventSource.cjs");
10
6
  const GlobalFunctionLogging_js_1 = require("../../core/GlobalFunctionLogging.cjs");
@@ -13,6 +9,7 @@ const AbortError_js_1 = require("../../core/api/AbortError.cjs");
13
9
  const getFunctionCallLogger_js_1 = require("../../core/getFunctionCallLogger.cjs");
14
10
  const getRun_js_1 = require("../../core/getRun.cjs");
15
11
  const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
12
+ const isDeepEqualData_js_1 = require("../../util/isDeepEqualData.cjs");
16
13
  const runSafe_js_1 = require("../../util/runSafe.cjs");
17
14
  const AsyncIterableResultPromise_js_1 = require("../AsyncIterableResultPromise.cjs");
18
15
  function streamStructure(model, structureDefinition, prompt, options) {
@@ -91,9 +88,7 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
91
88
  const latestFullDelta = event.fullDelta;
92
89
  const latestStructure = event.valueDelta;
93
90
  // only send a new part into the stream when the partial structure has changed:
94
- if (!(0, deep_equal_1.default)(lastStructure, latestStructure, {
95
- strict: true,
96
- })) {
91
+ if (!(0, isDeepEqualData_js_1.isDeepEqualData)(lastStructure, latestStructure)) {
97
92
  lastFullDelta = latestFullDelta;
98
93
  lastStructure = latestStructure;
99
94
  yield {
@@ -111,7 +106,7 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
111
106
  }
112
107
  yield {
113
108
  isComplete: true,
114
- value: parseResult.value,
109
+ value: parseResult.data,
115
110
  };
116
111
  const finishMetadata = {
117
112
  eventType: "finished",
@@ -1,4 +1,3 @@
1
- import deepEqual from "deep-equal";
2
1
  import { nanoid as createId } from "nanoid";
3
2
  import { FunctionEventSource } from "../../core/FunctionEventSource.js";
4
3
  import { getGlobalFunctionLogging } from "../../core/GlobalFunctionLogging.js";
@@ -7,6 +6,7 @@ import { AbortError } from "../../core/api/AbortError.js";
7
6
  import { getFunctionCallLogger } from "../../core/getFunctionCallLogger.js";
8
7
  import { getRun } from "../../core/getRun.js";
9
8
  import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
9
+ import { isDeepEqualData } from "../../util/isDeepEqualData.js";
10
10
  import { runSafe } from "../../util/runSafe.js";
11
11
  import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
12
12
  export function streamStructure(model, structureDefinition, prompt, options) {
@@ -84,9 +84,7 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
84
84
  const latestFullDelta = event.fullDelta;
85
85
  const latestStructure = event.valueDelta;
86
86
  // only send a new part into the stream when the partial structure has changed:
87
- if (!deepEqual(lastStructure, latestStructure, {
88
- strict: true,
89
- })) {
87
+ if (!isDeepEqualData(lastStructure, latestStructure)) {
90
88
  lastFullDelta = latestFullDelta;
91
89
  lastStructure = latestStructure;
92
90
  yield {
@@ -104,7 +102,7 @@ async function doStreamStructure(model, structureDefinition, prompt, options) {
104
102
  }
105
103
  yield {
106
104
  isComplete: true,
107
- value: parseResult.value,
105
+ value: parseResult.data,
108
106
  };
109
107
  const finishMetadata = {
110
108
  eventType: "finished",
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.failedAnthropicCallResponseHandler = exports.AnthropicError = exports.anthropicErrorDataSchema = void 0;
7
- const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
8
4
  const zod_1 = require("zod");
9
5
  const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
6
+ const parseJSON_js_1 = require("../../util/parseJSON.cjs");
10
7
  exports.anthropicErrorDataSchema = zod_1.z.object({
11
8
  error: zod_1.z.object({
12
9
  type: zod_1.z.string(),
@@ -26,14 +23,10 @@ class AnthropicError extends ApiCallError_js_1.ApiCallError {
26
23
  }
27
24
  }
28
25
  exports.AnthropicError = AnthropicError;
29
- const failedAnthropicCallResponseHandler = async ({ response, url, requestBodyValues }) => {
30
- const responseBody = await response.text();
31
- const parsedError = exports.anthropicErrorDataSchema.parse(secure_json_parse_1.default.parse(responseBody));
32
- return new AnthropicError({
33
- url,
34
- requestBodyValues,
35
- statusCode: response.status,
36
- data: parsedError,
37
- });
38
- };
26
+ const failedAnthropicCallResponseHandler = async ({ response, url, requestBodyValues }) => new AnthropicError({
27
+ url,
28
+ requestBodyValues,
29
+ statusCode: response.status,
30
+ data: (0, parseJSON_js_1.parseJsonWithZod)(await response.text(), exports.anthropicErrorDataSchema),
31
+ });
39
32
  exports.failedAnthropicCallResponseHandler = failedAnthropicCallResponseHandler;
@@ -1,6 +1,6 @@
1
- import SecureJSON from "secure-json-parse";
2
1
  import { z } from "zod";
3
2
  import { ApiCallError } from "../../core/api/ApiCallError.js";
3
+ import { parseJsonWithZod } from "../../util/parseJSON.js";
4
4
  export const anthropicErrorDataSchema = z.object({
5
5
  error: z.object({
6
6
  type: z.string(),
@@ -19,13 +19,9 @@ export class AnthropicError extends ApiCallError {
19
19
  this.data = data;
20
20
  }
21
21
  }
22
- export const failedAnthropicCallResponseHandler = async ({ response, url, requestBodyValues }) => {
23
- const responseBody = await response.text();
24
- const parsedError = anthropicErrorDataSchema.parse(SecureJSON.parse(responseBody));
25
- return new AnthropicError({
26
- url,
27
- requestBodyValues,
28
- statusCode: response.status,
29
- data: parsedError,
30
- });
31
- };
22
+ export const failedAnthropicCallResponseHandler = async ({ response, url, requestBodyValues }) => new AnthropicError({
23
+ url,
24
+ requestBodyValues,
25
+ statusCode: response.status,
26
+ data: parseJsonWithZod(await response.text(), anthropicErrorDataSchema),
27
+ });
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.AnthropicTextGenerationResponseFormat = exports.AnthropicTextGenerationModel = exports.ANTHROPIC_TEXT_GENERATION_MODELS = void 0;
7
- const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
8
4
  const zod_1 = require("zod");
9
5
  const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
10
6
  const postToApi_js_1 = require("../../core/api/postToApi.cjs");
@@ -12,6 +8,7 @@ const AsyncQueue_js_1 = require("../../event-source/AsyncQueue.cjs");
12
8
  const parseEventSourceStream_js_1 = require("../../event-source/parseEventSourceStream.cjs");
13
9
  const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
14
10
  const PromptFormatTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptFormatTextStreamingModel.cjs");
11
+ const parseJSON_js_1 = require("../../util/parseJSON.cjs");
15
12
  const AnthropicApiConfiguration_js_1 = require("./AnthropicApiConfiguration.cjs");
16
13
  const AnthropicError_js_1 = require("./AnthropicError.cjs");
17
14
  const AnthropicPromptFormat_js_1 = require("./AnthropicPromptFormat.cjs");
@@ -183,17 +180,7 @@ async function createAnthropicFullDeltaIterableQueue(stream) {
183
180
  continue;
184
181
  }
185
182
  const data = event.data;
186
- const json = secure_json_parse_1.default.parse(data);
187
- const parseResult = anthropicTextStreamingResponseSchema.safeParse(json);
188
- if (!parseResult.success) {
189
- queue.push({
190
- type: "error",
191
- error: parseResult.error,
192
- });
193
- queue.close();
194
- return;
195
- }
196
- const eventData = parseResult.data;
183
+ const eventData = (0, parseJSON_js_1.parseJsonWithZod)(data, anthropicTextStreamingResponseSchema);
197
184
  content += eventData.completion;
198
185
  queue.push({
199
186
  type: "delta",
@@ -1,4 +1,3 @@
1
- import SecureJSON from "secure-json-parse";
2
1
  import { z } from "zod";
3
2
  import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
4
3
  import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
@@ -6,6 +5,7 @@ import { AsyncQueue } from "../../event-source/AsyncQueue.js";
6
5
  import { parseEventSourceStream } from "../../event-source/parseEventSourceStream.js";
7
6
  import { AbstractModel } from "../../model-function/AbstractModel.js";
8
7
  import { PromptFormatTextStreamingModel } from "../../model-function/generate-text/PromptFormatTextStreamingModel.js";
8
+ import { parseJsonWithZod } from "../../util/parseJSON.js";
9
9
  import { AnthropicApiConfiguration } from "./AnthropicApiConfiguration.js";
10
10
  import { failedAnthropicCallResponseHandler } from "./AnthropicError.js";
11
11
  import { mapChatPromptToAnthropicFormat, mapInstructionPromptToAnthropicFormat, } from "./AnthropicPromptFormat.js";
@@ -176,17 +176,7 @@ async function createAnthropicFullDeltaIterableQueue(stream) {
176
176
  continue;
177
177
  }
178
178
  const data = event.data;
179
- const json = SecureJSON.parse(data);
180
- const parseResult = anthropicTextStreamingResponseSchema.safeParse(json);
181
- if (!parseResult.success) {
182
- queue.push({
183
- type: "error",
184
- error: parseResult.error,
185
- });
186
- queue.close();
187
- return;
188
- }
189
- const eventData = parseResult.data;
179
+ const eventData = parseJsonWithZod(data, anthropicTextStreamingResponseSchema);
190
180
  content += eventData.completion;
191
181
  queue.push({
192
182
  type: "delta",