@jterrazz/intelligence 2.0.0 → 3.0.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.
- package/README.md +56 -268
- package/dist/index.cjs +656 -2017
- package/dist/index.d.ts +5 -15
- package/dist/index.js +5 -33
- package/dist/index.js.map +1 -1
- package/dist/middleware/__tests__/logging.middleware.test.js +390 -0
- package/dist/middleware/__tests__/logging.middleware.test.js.map +1 -0
- package/dist/middleware/logging.middleware.d.ts +21 -0
- package/dist/middleware/logging.middleware.js +296 -0
- package/dist/middleware/logging.middleware.js.map +1 -0
- package/dist/parsing/__tests__/create-schema-prompt.test.js +53 -0
- package/dist/parsing/__tests__/create-schema-prompt.test.js.map +1 -0
- package/dist/parsing/__tests__/parse-object.test.d.ts +1 -0
- package/dist/parsing/__tests__/parse-object.test.js +193 -0
- package/dist/parsing/__tests__/parse-object.test.js.map +1 -0
- package/dist/parsing/__tests__/parse-text.test.d.ts +1 -0
- package/dist/parsing/__tests__/parse-text.test.js +159 -0
- package/dist/parsing/__tests__/parse-text.test.js.map +1 -0
- package/dist/parsing/create-schema-prompt.d.ts +28 -0
- package/dist/parsing/create-schema-prompt.js +42 -0
- package/dist/parsing/create-schema-prompt.js.map +1 -0
- package/dist/parsing/parse-object.d.ts +33 -0
- package/dist/parsing/parse-object.js +360 -0
- package/dist/parsing/parse-object.js.map +1 -0
- package/dist/parsing/parse-text.d.ts +14 -0
- package/dist/parsing/parse-text.js +80 -0
- package/dist/parsing/parse-text.js.map +1 -0
- package/dist/providers/openrouter.provider.d.ts +36 -0
- package/dist/providers/openrouter.provider.js +58 -0
- package/dist/providers/openrouter.provider.js.map +1 -0
- package/package.json +14 -15
- package/dist/adapters/agents/chat-agent.adapter.d.ts +0 -27
- package/dist/adapters/agents/chat-agent.adapter.js +0 -356
- package/dist/adapters/agents/chat-agent.adapter.js.map +0 -1
- package/dist/adapters/agents/resilient-agent.adapter.d.ts +0 -20
- package/dist/adapters/agents/resilient-agent.adapter.js +0 -263
- package/dist/adapters/agents/resilient-agent.adapter.js.map +0 -1
- package/dist/adapters/agents/tool-agent.adapter.d.ts +0 -30
- package/dist/adapters/agents/tool-agent.adapter.js +0 -400
- package/dist/adapters/agents/tool-agent.adapter.js.map +0 -1
- package/dist/adapters/models/openrouter-model.adapter.d.ts +0 -23
- package/dist/adapters/models/openrouter-model.adapter.js +0 -148
- package/dist/adapters/models/openrouter-model.adapter.js.map +0 -1
- package/dist/adapters/prompts/__tests__/__snapshots__/presets.test.ts.snap +0 -120
- package/dist/adapters/prompts/__tests__/presets.test.js +0 -31
- package/dist/adapters/prompts/__tests__/presets.test.js.map +0 -1
- package/dist/adapters/prompts/library/categories/domain.d.ts +0 -11
- package/dist/adapters/prompts/library/categories/domain.js +0 -12
- package/dist/adapters/prompts/library/categories/domain.js.map +0 -1
- package/dist/adapters/prompts/library/categories/format.d.ts +0 -10
- package/dist/adapters/prompts/library/categories/format.js +0 -11
- package/dist/adapters/prompts/library/categories/format.js.map +0 -1
- package/dist/adapters/prompts/library/categories/foundations.d.ts +0 -12
- package/dist/adapters/prompts/library/categories/foundations.js +0 -13
- package/dist/adapters/prompts/library/categories/foundations.js.map +0 -1
- package/dist/adapters/prompts/library/categories/language.d.ts +0 -11
- package/dist/adapters/prompts/library/categories/language.js +0 -12
- package/dist/adapters/prompts/library/categories/language.js.map +0 -1
- package/dist/adapters/prompts/library/categories/persona.d.ts +0 -13
- package/dist/adapters/prompts/library/categories/persona.js +0 -14
- package/dist/adapters/prompts/library/categories/persona.js.map +0 -1
- package/dist/adapters/prompts/library/categories/response.d.ts +0 -9
- package/dist/adapters/prompts/library/categories/response.js +0 -10
- package/dist/adapters/prompts/library/categories/response.js.map +0 -1
- package/dist/adapters/prompts/library/categories/tone.d.ts +0 -9
- package/dist/adapters/prompts/library/categories/tone.js +0 -10
- package/dist/adapters/prompts/library/categories/tone.js.map +0 -1
- package/dist/adapters/prompts/library/categories/verbosity.d.ts +0 -8
- package/dist/adapters/prompts/library/categories/verbosity.js +0 -9
- package/dist/adapters/prompts/library/categories/verbosity.js.map +0 -1
- package/dist/adapters/prompts/library/index.d.ts +0 -68
- package/dist/adapters/prompts/library/index.js +0 -26
- package/dist/adapters/prompts/library/index.js.map +0 -1
- package/dist/adapters/prompts/library/presets.d.ts +0 -17
- package/dist/adapters/prompts/library/presets.js +0 -45
- package/dist/adapters/prompts/library/presets.js.map +0 -1
- package/dist/adapters/prompts/system-prompt.adapter.d.ts +0 -9
- package/dist/adapters/prompts/system-prompt.adapter.js +0 -57
- package/dist/adapters/prompts/system-prompt.adapter.js.map +0 -1
- package/dist/adapters/prompts/user-prompt.adapter.d.ts +0 -9
- package/dist/adapters/prompts/user-prompt.adapter.js +0 -57
- package/dist/adapters/prompts/user-prompt.adapter.js.map +0 -1
- package/dist/adapters/providers/openrouter-provider.adapter.d.ts +0 -34
- package/dist/adapters/providers/openrouter-provider.adapter.js +0 -57
- package/dist/adapters/providers/openrouter-provider.adapter.js.map +0 -1
- package/dist/adapters/tools/safe-tool.adapter.d.ts +0 -27
- package/dist/adapters/tools/safe-tool.adapter.js +0 -283
- package/dist/adapters/tools/safe-tool.adapter.js.map +0 -1
- package/dist/adapters/utils/__tests__/structured-response-parser.test.js +0 -289
- package/dist/adapters/utils/__tests__/structured-response-parser.test.js.map +0 -1
- package/dist/adapters/utils/structured-response-parser-error.d.ts +0 -8
- package/dist/adapters/utils/structured-response-parser-error.js +0 -136
- package/dist/adapters/utils/structured-response-parser-error.js.map +0 -1
- package/dist/adapters/utils/structured-response-parser.d.ts +0 -60
- package/dist/adapters/utils/structured-response-parser.js +0 -347
- package/dist/adapters/utils/structured-response-parser.js.map +0 -1
- package/dist/ports/agent.port.d.ts +0 -17
- package/dist/ports/agent.port.js +0 -7
- package/dist/ports/agent.port.js.map +0 -1
- package/dist/ports/model.port.d.ts +0 -37
- package/dist/ports/model.port.js +0 -5
- package/dist/ports/model.port.js.map +0 -1
- package/dist/ports/prompt.port.d.ts +0 -9
- package/dist/ports/prompt.port.js +0 -5
- package/dist/ports/prompt.port.js.map +0 -1
- package/dist/ports/provider.port.d.ts +0 -13
- package/dist/ports/provider.port.js +0 -5
- package/dist/ports/provider.port.js.map +0 -1
- package/dist/ports/tool.port.d.ts +0 -11
- package/dist/ports/tool.port.js +0 -5
- package/dist/ports/tool.port.js.map +0 -1
- /package/dist/{adapters/prompts/__tests__/presets.test.d.ts → middleware/__tests__/logging.middleware.test.d.ts} +0 -0
- /package/dist/{adapters/utils/__tests__/structured-response-parser.test.d.ts → parsing/__tests__/create-schema-prompt.test.d.ts} +0 -0
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jterrazz/test';
|
|
2
|
-
import { z } from 'zod/v4';
|
|
3
|
-
import { StructuredResponseParser } from '../structured-response-parser.js';
|
|
4
|
-
import { StructuredResponseParserError } from '../structured-response-parser-error.js';
|
|
5
|
-
// Test data
|
|
6
|
-
var testSchema = z.object({
|
|
7
|
-
content: z.string(),
|
|
8
|
-
tags: z.array(z.string()),
|
|
9
|
-
title: z.string()
|
|
10
|
-
});
|
|
11
|
-
var validJson = {
|
|
12
|
-
content: 'Test content',
|
|
13
|
-
tags: [
|
|
14
|
-
'test',
|
|
15
|
-
'ai'
|
|
16
|
-
],
|
|
17
|
-
title: 'Test Article'
|
|
18
|
-
};
|
|
19
|
-
var validJsonString = JSON.stringify(validJson);
|
|
20
|
-
describe('StructuredResponseParser', function() {
|
|
21
|
-
describe('parse', function() {
|
|
22
|
-
it('should parse valid JSON object', function() {
|
|
23
|
-
// Given - a valid JSON object string and parser
|
|
24
|
-
var text = validJsonString;
|
|
25
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
26
|
-
// When - parsing the string
|
|
27
|
-
var result = parser.parse(text);
|
|
28
|
-
// Then - it should return the parsed object
|
|
29
|
-
expect(result).toEqual(validJson);
|
|
30
|
-
});
|
|
31
|
-
it('should parse JSON object with surrounding text', function() {
|
|
32
|
-
// Given - a JSON object string with surrounding text and parser
|
|
33
|
-
var text = "Here's the article: ".concat(validJsonString, " - end of article");
|
|
34
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
35
|
-
// When - parsing the string
|
|
36
|
-
var result = parser.parse(text);
|
|
37
|
-
// Then - it should return the parsed object
|
|
38
|
-
expect(result).toEqual(validJson);
|
|
39
|
-
});
|
|
40
|
-
it('should parse array response', function() {
|
|
41
|
-
// Given - a JSON array string and array parser
|
|
42
|
-
var arraySchema = z.array(z.string());
|
|
43
|
-
var text = '["test", "ai", "content"]';
|
|
44
|
-
var parser = new StructuredResponseParser(arraySchema);
|
|
45
|
-
// When - parsing the string
|
|
46
|
-
var result = parser.parse(text);
|
|
47
|
-
// Then - it should return the parsed array
|
|
48
|
-
expect(result).toEqual([
|
|
49
|
-
'test',
|
|
50
|
-
'ai',
|
|
51
|
-
'content'
|
|
52
|
-
]);
|
|
53
|
-
});
|
|
54
|
-
it('should parse primitive string value', function() {
|
|
55
|
-
// Given - a JSON string value and string parser
|
|
56
|
-
var text = '"test string"';
|
|
57
|
-
var parser = new StructuredResponseParser(z.string());
|
|
58
|
-
// When - parsing the string
|
|
59
|
-
var result = parser.parse(text);
|
|
60
|
-
// Then - it should return the parsed string
|
|
61
|
-
expect(result).toBe('test string');
|
|
62
|
-
});
|
|
63
|
-
it('should parse primitive number value', function() {
|
|
64
|
-
// Given - a JSON number value and number parser
|
|
65
|
-
var text = '42';
|
|
66
|
-
var parser = new StructuredResponseParser(z.number());
|
|
67
|
-
// When - parsing the string
|
|
68
|
-
var result = parser.parse(text);
|
|
69
|
-
// Then - it should return the parsed number
|
|
70
|
-
expect(result).toBe(42);
|
|
71
|
-
});
|
|
72
|
-
it('should parse primitive boolean value', function() {
|
|
73
|
-
// Given - a JSON boolean value and boolean parser
|
|
74
|
-
var text = 'true';
|
|
75
|
-
var parser = new StructuredResponseParser(z["boolean"]());
|
|
76
|
-
// When - parsing the string
|
|
77
|
-
var result = parser.parse(text);
|
|
78
|
-
// Then - it should return the parsed boolean
|
|
79
|
-
expect(result).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
it('should parse primitive null value', function() {
|
|
82
|
-
// Given - a JSON null value and null parser
|
|
83
|
-
var text = 'null';
|
|
84
|
-
var parser = new StructuredResponseParser(z["null"]());
|
|
85
|
-
// When - parsing the string
|
|
86
|
-
var result = parser.parse(text);
|
|
87
|
-
// Then - it should return the parsed null
|
|
88
|
-
expect(result).toBeNull();
|
|
89
|
-
});
|
|
90
|
-
it('should throw ResponseParsingError when JSON is invalid', function() {
|
|
91
|
-
// Given - an invalid JSON string and parser
|
|
92
|
-
var text = '{invalid json}';
|
|
93
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
94
|
-
// When/Then - parsing the string should throw a ResponseParsingError
|
|
95
|
-
expect(function() {
|
|
96
|
-
return parser.parse(text);
|
|
97
|
-
}).toThrow(StructuredResponseParserError);
|
|
98
|
-
});
|
|
99
|
-
it('should throw ResponseParsingError when schema validation fails', function() {
|
|
100
|
-
// Given - an invalid JSON object and parser
|
|
101
|
-
var invalidJson = {
|
|
102
|
-
// Should be string
|
|
103
|
-
content: 'Test content',
|
|
104
|
-
tags: [
|
|
105
|
-
'test',
|
|
106
|
-
'ai'
|
|
107
|
-
],
|
|
108
|
-
title: 123
|
|
109
|
-
};
|
|
110
|
-
var text = JSON.stringify(invalidJson);
|
|
111
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
112
|
-
// When/Then - parsing the string should throw a ResponseParsingError
|
|
113
|
-
expect(function() {
|
|
114
|
-
return parser.parse(text);
|
|
115
|
-
}).toThrow(StructuredResponseParserError);
|
|
116
|
-
});
|
|
117
|
-
it('should throw ResponseParsingError when no object found in text', function() {
|
|
118
|
-
// Given - a text without a JSON object and parser
|
|
119
|
-
var text = 'No JSON object here';
|
|
120
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
121
|
-
// When/Then - parsing the string should throw a ResponseParsingError
|
|
122
|
-
expect(function() {
|
|
123
|
-
return parser.parse(text);
|
|
124
|
-
}).toThrow(StructuredResponseParserError);
|
|
125
|
-
});
|
|
126
|
-
it('should throw ResponseParsingError when no array found in text', function() {
|
|
127
|
-
// Given - a text without a JSON array and array parser
|
|
128
|
-
var text = 'No array here';
|
|
129
|
-
var arraySchema = z.array(z.string());
|
|
130
|
-
var parser = new StructuredResponseParser(arraySchema);
|
|
131
|
-
// When/Then - parsing the string should throw a ResponseParsingError
|
|
132
|
-
expect(function() {
|
|
133
|
-
return parser.parse(text);
|
|
134
|
-
}).toThrow(StructuredResponseParserError);
|
|
135
|
-
});
|
|
136
|
-
it('should throw ResponseParsingError for unsupported schema type', function() {
|
|
137
|
-
// Given - a text with an unsupported schema type and parser
|
|
138
|
-
var text = 'test';
|
|
139
|
-
var unsupportedSchema = z.union([
|
|
140
|
-
z.string(),
|
|
141
|
-
z.number()
|
|
142
|
-
]);
|
|
143
|
-
var parser = new StructuredResponseParser(unsupportedSchema);
|
|
144
|
-
// When/Then - parsing the string should throw a ResponseParsingError
|
|
145
|
-
expect(function() {
|
|
146
|
-
return parser.parse(text);
|
|
147
|
-
}).toThrow(StructuredResponseParserError);
|
|
148
|
-
});
|
|
149
|
-
it('should include original text in error when parsing fails', function() {
|
|
150
|
-
// Given - an invalid JSON string and parser
|
|
151
|
-
var text = '{invalid json}';
|
|
152
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
153
|
-
// When - parsing the string
|
|
154
|
-
try {
|
|
155
|
-
parser.parse(text);
|
|
156
|
-
throw new Error('Should have thrown an error');
|
|
157
|
-
} catch (error) {
|
|
158
|
-
// Then - the error should include the original text
|
|
159
|
-
expect(error).toBeInstanceOf(StructuredResponseParserError);
|
|
160
|
-
expect(error.text).toBe(text);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
it('should handle text with newlines in JSON object', function() {
|
|
164
|
-
// Given - a JSON object with newlines and parser
|
|
165
|
-
var textWithNewlines = '{\n "content": "Test\ncontent\nwith\nnewlines",\n "tags": ["test", "ai"],\n "title": "Test\nArticle"\n }';
|
|
166
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
167
|
-
// When - parsing the string
|
|
168
|
-
var result = parser.parse(textWithNewlines);
|
|
169
|
-
// Then - it should return the parsed object
|
|
170
|
-
expect(result).toEqual({
|
|
171
|
-
content: 'Test content with newlines',
|
|
172
|
-
tags: [
|
|
173
|
-
'test',
|
|
174
|
-
'ai'
|
|
175
|
-
],
|
|
176
|
-
title: 'Test Article'
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
it('should handle text with newlines in surrounding text', function() {
|
|
180
|
-
// Given - a text with newlines around the JSON object and parser
|
|
181
|
-
var textWithNewlines = "Here's the\narticle:\n".concat(validJsonString, "\n- end of\narticle");
|
|
182
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
183
|
-
// When - parsing the string
|
|
184
|
-
var result = parser.parse(textWithNewlines);
|
|
185
|
-
// Then - it should return the parsed object
|
|
186
|
-
expect(result).toEqual(validJson);
|
|
187
|
-
});
|
|
188
|
-
it('should handle text with multiple consecutive newlines and spaces', function() {
|
|
189
|
-
// Given - a text with multiple consecutive newlines and spaces and parser
|
|
190
|
-
var textWithNewlines = "Here's the\n\n article: \n\n".concat(validJsonString, "\n\n");
|
|
191
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
192
|
-
// When - parsing the string
|
|
193
|
-
var result = parser.parse(textWithNewlines);
|
|
194
|
-
// Then - it should return the parsed object
|
|
195
|
-
expect(result).toEqual(validJson);
|
|
196
|
-
});
|
|
197
|
-
it('should handle escaped characters in JSON', function() {
|
|
198
|
-
// Given - a JSON string with escaped characters and parser
|
|
199
|
-
var text = '{"content": "Test\\ncontent\\twith\\r\\nescapes", "tags": ["test\\u0020ai", "escaped\\"quotes\\""], "title": "Test\\\\Article"}';
|
|
200
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
201
|
-
// When - parsing the string
|
|
202
|
-
var result = parser.parse(text);
|
|
203
|
-
// Then - it should return the parsed object
|
|
204
|
-
expect(result).toEqual({
|
|
205
|
-
content: 'Test\ncontent\twith\r\nescapes',
|
|
206
|
-
tags: [
|
|
207
|
-
'test ai',
|
|
208
|
-
'escaped"quotes"'
|
|
209
|
-
],
|
|
210
|
-
title: 'Test\\Article'
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
it('should handle escaped characters in markdown code blocks', function() {
|
|
214
|
-
// Given - a markdown code block with escaped characters and parser
|
|
215
|
-
var text = '```json\n{"content": "Test\\nContent", "tags": ["test\\u0020ai"], "title": "Test\\\\Title"}\n```';
|
|
216
|
-
var parser = new StructuredResponseParser(testSchema);
|
|
217
|
-
// When - parsing the string
|
|
218
|
-
var result = parser.parse(text);
|
|
219
|
-
// Then - it should return the parsed object
|
|
220
|
-
expect(result).toEqual({
|
|
221
|
-
content: 'Test\nContent',
|
|
222
|
-
tags: [
|
|
223
|
-
'test ai'
|
|
224
|
-
],
|
|
225
|
-
title: 'Test\\Title'
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
it('should handle escaped characters in markdown code blocks', function() {
|
|
229
|
-
// Given - a markdown code block with escaped characters and array parser
|
|
230
|
-
var text = '```json\n [\n{"content": "Test\\nContent", "tags": ["test\\u0020ai"], "title": "Test\\\\Title"}\n]\n```';
|
|
231
|
-
var arraySchema = z.array(testSchema);
|
|
232
|
-
var parser = new StructuredResponseParser(arraySchema);
|
|
233
|
-
// When - parsing the string
|
|
234
|
-
var result = parser.parse(text);
|
|
235
|
-
// Then - it should return the parsed array
|
|
236
|
-
expect(result).toEqual([
|
|
237
|
-
{
|
|
238
|
-
content: 'Test\nContent',
|
|
239
|
-
tags: [
|
|
240
|
-
'test ai'
|
|
241
|
-
],
|
|
242
|
-
title: 'Test\\Title'
|
|
243
|
-
}
|
|
244
|
-
]);
|
|
245
|
-
});
|
|
246
|
-
it('should parse complex NBA trade analysis JSON with escaped quotes', function() {
|
|
247
|
-
// Given - a complex JSON object with nested structures and escaped quotes in markdown
|
|
248
|
-
var complexSchema = z.object({
|
|
249
|
-
category: z.string(),
|
|
250
|
-
countries: z.array(z.string()),
|
|
251
|
-
perspectives: z.array(z.object({
|
|
252
|
-
holisticDigest: z.string(),
|
|
253
|
-
tags: z.object({
|
|
254
|
-
discourse_type: z.string(),
|
|
255
|
-
stance: z.string()
|
|
256
|
-
})
|
|
257
|
-
})),
|
|
258
|
-
synopsis: z.string()
|
|
259
|
-
});
|
|
260
|
-
var text = '```json\n{\n "category": "sports",\n "countries": [\n "us"\n ],\n "perspectives": [\n {\n "holisticDigest": "The NBA offseason has seen a massive blockbuster trade as the Phoenix Suns have sent Kevin Durant to the Houston Rockets. The Rockets are acquiring Durant in exchange for Jalen Green, Dillon Brooks, the No. 10 pick in the 2025 NBA draft, and five second-round picks. This move significantly boosts the Rockets\' championship aspirations, positioning them as immediate contenders in the Western Conference alongside established teams. Durant, a future Hall of Famer, is expected to provide elite scoring and shot creation, addressing the Rockets\' previous offensive struggles in the half-court, particularly in the playoffs. Durant\'s decision to list Houston as a preferred destination suggests a potential long-term commitment, with an extension likely upon the opening of the new league year. For the Suns, this trade represents a pivot towards rebuilding, allowing them to acquire young talent and draft assets after their "Big 3" experiment failed to yield a championship. The Suns\' return is viewed by some analysts as lacking compared to Durant\'s caliber, but it does provide them with a reset and a chance to retool around Devin Booker and the draft picks. The specifics of the deal, including Dillon Brooks\' contract and the distribution of second-round picks, have also been highlighted as key elements enabling the trade to go through. The Rockets\' odds to win the NBA title have shortened considerably following the acquisition.",\n "tags": {\n "discourse_type": "mainstream",\n "stance": "neutral"\n }\n }\n ],\n "synopsis": "This collection of articles reports on a major NBA trade where the Phoenix Suns have sent veteran superstar Kevin Durant to the Houston Rockets. The Rockets have acquired Durant in exchange for a package that includes young players Jalen Green and Dillon Brooks, as well as the No. 10 pick in the 2025 NBA draft and five second-round picks. The trade is seen as a significant move that immediately elevates the Rockets into championship contention in the Western Conference. For the Suns, the deal signals a shift towards rebuilding, acquiring young assets and draft capital after their pursuit of a championship with Durant did not come to fruition. Analysis within the articles discusses the potential impact of Durant on the Rockets\' offense and their championship odds, as well as the Suns\' strategy in moving forward after this blockbuster deal. The player himself was reportedly informed of the trade while on stage at an event, offering a brief, somewhat non-committal reaction to the news."\n}\n```';
|
|
261
|
-
var parser = new StructuredResponseParser(complexSchema);
|
|
262
|
-
// When - parsing the string
|
|
263
|
-
var result = parser.parse(text);
|
|
264
|
-
// Then - it should return the parsed object with escaped quotes properly handled
|
|
265
|
-
expect(result).toEqual({
|
|
266
|
-
category: 'sports',
|
|
267
|
-
countries: [
|
|
268
|
-
'us'
|
|
269
|
-
],
|
|
270
|
-
perspectives: [
|
|
271
|
-
{
|
|
272
|
-
holisticDigest: expect.stringContaining('The NBA offseason has seen a massive blockbuster trade'),
|
|
273
|
-
tags: {
|
|
274
|
-
discourse_type: 'mainstream',
|
|
275
|
-
stance: 'neutral'
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
],
|
|
279
|
-
synopsis: expect.stringContaining('This collection of articles reports on a major NBA trade')
|
|
280
|
-
});
|
|
281
|
-
// Additional verification for escaped quotes handling
|
|
282
|
-
expect(result.perspectives[0].holisticDigest).toContain('"Big 3" experiment');
|
|
283
|
-
expect(result.perspectives[0].holisticDigest).toContain("Rockets' championship aspirations");
|
|
284
|
-
expect(result.perspectives[0].holisticDigest).toContain("Durant's decision");
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
//# sourceMappingURL=structured-response-parser.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/adapters/utils/__tests__/structured-response-parser.test.ts"],"sourcesContent":["import { describe, expect, it } from '@jterrazz/test';\nimport { z } from 'zod/v4';\n\nimport { StructuredResponseParser } from '../structured-response-parser.js';\nimport { StructuredResponseParserError } from '../structured-response-parser-error.js';\n\n// Test data\nconst testSchema = z.object({\n content: z.string(),\n tags: z.array(z.string()),\n title: z.string(),\n});\n\nconst validJson = {\n content: 'Test content',\n tags: ['test', 'ai'],\n title: 'Test Article',\n};\n\nconst validJsonString = JSON.stringify(validJson);\n\ndescribe('StructuredResponseParser', () => {\n describe('parse', () => {\n it('should parse valid JSON object', () => {\n // Given - a valid JSON object string and parser\n const text = validJsonString;\n const parser = new StructuredResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should parse JSON object with surrounding text', () => {\n // Given - a JSON object string with surrounding text and parser\n const text = `Here's the article: ${validJsonString} - end of article`;\n const parser = new StructuredResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should parse array response', () => {\n // Given - a JSON array string and array parser\n const arraySchema = z.array(z.string());\n const text = '[\"test\", \"ai\", \"content\"]';\n const parser = new StructuredResponseParser(arraySchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed array\n expect(result).toEqual(['test', 'ai', 'content']);\n });\n\n it('should parse primitive string value', () => {\n // Given - a JSON string value and string parser\n const text = '\"test string\"';\n const parser = new StructuredResponseParser(z.string());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed string\n expect(result).toBe('test string');\n });\n\n it('should parse primitive number value', () => {\n // Given - a JSON number value and number parser\n const text = '42';\n const parser = new StructuredResponseParser(z.number());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed number\n expect(result).toBe(42);\n });\n\n it('should parse primitive boolean value', () => {\n // Given - a JSON boolean value and boolean parser\n const text = 'true';\n const parser = new StructuredResponseParser(z.boolean());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed boolean\n expect(result).toBe(true);\n });\n\n it('should parse primitive null value', () => {\n // Given - a JSON null value and null parser\n const text = 'null';\n const parser = new StructuredResponseParser(z.null());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed null\n expect(result).toBeNull();\n });\n\n it('should throw ResponseParsingError when JSON is invalid', () => {\n // Given - an invalid JSON string and parser\n const text = '{invalid json}';\n const parser = new StructuredResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(StructuredResponseParserError);\n });\n\n it('should throw ResponseParsingError when schema validation fails', () => {\n // Given - an invalid JSON object and parser\n const invalidJson = {\n // Should be string\n content: 'Test content',\n tags: ['test', 'ai'],\n title: 123,\n };\n const text = JSON.stringify(invalidJson);\n const parser = new StructuredResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(StructuredResponseParserError);\n });\n\n it('should throw ResponseParsingError when no object found in text', () => {\n // Given - a text without a JSON object and parser\n const text = 'No JSON object here';\n const parser = new StructuredResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(StructuredResponseParserError);\n });\n\n it('should throw ResponseParsingError when no array found in text', () => {\n // Given - a text without a JSON array and array parser\n const text = 'No array here';\n const arraySchema = z.array(z.string());\n const parser = new StructuredResponseParser(arraySchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(StructuredResponseParserError);\n });\n\n it('should throw ResponseParsingError for unsupported schema type', () => {\n // Given - a text with an unsupported schema type and parser\n const text = 'test';\n const unsupportedSchema = z.union([z.string(), z.number()]);\n const parser = new StructuredResponseParser(unsupportedSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(StructuredResponseParserError);\n });\n\n it('should include original text in error when parsing fails', () => {\n // Given - an invalid JSON string and parser\n const text = '{invalid json}';\n const parser = new StructuredResponseParser(testSchema);\n\n // When - parsing the string\n try {\n parser.parse(text);\n throw new Error('Should have thrown an error');\n } catch (error) {\n // Then - the error should include the original text\n expect(error).toBeInstanceOf(StructuredResponseParserError);\n expect((error as StructuredResponseParserError).text).toBe(text);\n }\n });\n\n it('should handle text with newlines in JSON object', () => {\n // Given - a JSON object with newlines and parser\n const textWithNewlines = `{\n \"content\": \"Test\\ncontent\\nwith\\nnewlines\",\n \"tags\": [\"test\", \"ai\"],\n \"title\": \"Test\\nArticle\"\n }`;\n const parser = new StructuredResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test content with newlines',\n tags: ['test', 'ai'],\n title: 'Test Article',\n });\n });\n\n it('should handle text with newlines in surrounding text', () => {\n // Given - a text with newlines around the JSON object and parser\n const textWithNewlines = `Here's the\\narticle:\\n${validJsonString}\\n- end of\\narticle`;\n const parser = new StructuredResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should handle text with multiple consecutive newlines and spaces', () => {\n // Given - a text with multiple consecutive newlines and spaces and parser\n const textWithNewlines = `Here's the\\n\\n article: \\n\\n${validJsonString}\\n\\n`;\n const parser = new StructuredResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should handle escaped characters in JSON', () => {\n // Given - a JSON string with escaped characters and parser\n const text =\n '{\"content\": \"Test\\\\ncontent\\\\twith\\\\r\\\\nescapes\", \"tags\": [\"test\\\\u0020ai\", \"escaped\\\\\"quotes\\\\\"\"], \"title\": \"Test\\\\\\\\Article\"}';\n const parser = new StructuredResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test\\ncontent\\twith\\r\\nescapes',\n tags: ['test ai', 'escaped\"quotes\"'],\n title: 'Test\\\\Article',\n });\n });\n\n it('should handle escaped characters in markdown code blocks', () => {\n // Given - a markdown code block with escaped characters and parser\n const text =\n '```json\\n{\"content\": \"Test\\\\nContent\", \"tags\": [\"test\\\\u0020ai\"], \"title\": \"Test\\\\\\\\Title\"}\\n```';\n const parser = new StructuredResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test\\nContent',\n tags: ['test ai'],\n title: 'Test\\\\Title',\n });\n });\n\n it('should handle escaped characters in markdown code blocks', () => {\n // Given - a markdown code block with escaped characters and array parser\n const text =\n '```json\\n [\\n{\"content\": \"Test\\\\nContent\", \"tags\": [\"test\\\\u0020ai\"], \"title\": \"Test\\\\\\\\Title\"}\\n]\\n```';\n const arraySchema = z.array(testSchema);\n const parser = new StructuredResponseParser(arraySchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed array\n expect(result).toEqual([\n {\n content: 'Test\\nContent',\n tags: ['test ai'],\n title: 'Test\\\\Title',\n },\n ]);\n });\n\n it('should parse complex NBA trade analysis JSON with escaped quotes', () => {\n // Given - a complex JSON object with nested structures and escaped quotes in markdown\n const complexSchema = z.object({\n category: z.string(),\n countries: z.array(z.string()),\n perspectives: z.array(\n z.object({\n holisticDigest: z.string(),\n tags: z.object({\n discourse_type: z.string(),\n stance: z.string(),\n }),\n }),\n ),\n synopsis: z.string(),\n });\n\n const text =\n '```json\\n{\\n \"category\": \"sports\",\\n \"countries\": [\\n \"us\"\\n ],\\n \"perspectives\": [\\n {\\n \"holisticDigest\": \"The NBA offseason has seen a massive blockbuster trade as the Phoenix Suns have sent Kevin Durant to the Houston Rockets. The Rockets are acquiring Durant in exchange for Jalen Green, Dillon Brooks, the No. 10 pick in the 2025 NBA draft, and five second-round picks. This move significantly boosts the Rockets\\' championship aspirations, positioning them as immediate contenders in the Western Conference alongside established teams. Durant, a future Hall of Famer, is expected to provide elite scoring and shot creation, addressing the Rockets\\' previous offensive struggles in the half-court, particularly in the playoffs. Durant\\'s decision to list Houston as a preferred destination suggests a potential long-term commitment, with an extension likely upon the opening of the new league year. For the Suns, this trade represents a pivot towards rebuilding, allowing them to acquire young talent and draft assets after their \"Big 3\" experiment failed to yield a championship. The Suns\\' return is viewed by some analysts as lacking compared to Durant\\'s caliber, but it does provide them with a reset and a chance to retool around Devin Booker and the draft picks. The specifics of the deal, including Dillon Brooks\\' contract and the distribution of second-round picks, have also been highlighted as key elements enabling the trade to go through. The Rockets\\' odds to win the NBA title have shortened considerably following the acquisition.\",\\n \"tags\": {\\n \"discourse_type\": \"mainstream\",\\n \"stance\": \"neutral\"\\n }\\n }\\n ],\\n \"synopsis\": \"This collection of articles reports on a major NBA trade where the Phoenix Suns have sent veteran superstar Kevin Durant to the Houston Rockets. The Rockets have acquired Durant in exchange for a package that includes young players Jalen Green and Dillon Brooks, as well as the No. 10 pick in the 2025 NBA draft and five second-round picks. The trade is seen as a significant move that immediately elevates the Rockets into championship contention in the Western Conference. For the Suns, the deal signals a shift towards rebuilding, acquiring young assets and draft capital after their pursuit of a championship with Durant did not come to fruition. Analysis within the articles discusses the potential impact of Durant on the Rockets\\' offense and their championship odds, as well as the Suns\\' strategy in moving forward after this blockbuster deal. The player himself was reportedly informed of the trade while on stage at an event, offering a brief, somewhat non-committal reaction to the news.\"\\n}\\n```';\n\n const parser = new StructuredResponseParser(complexSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object with escaped quotes properly handled\n expect(result).toEqual({\n category: 'sports',\n countries: ['us'],\n perspectives: [\n {\n holisticDigest: expect.stringContaining(\n 'The NBA offseason has seen a massive blockbuster trade',\n ),\n tags: {\n discourse_type: 'mainstream',\n stance: 'neutral',\n },\n },\n ],\n synopsis: expect.stringContaining(\n 'This collection of articles reports on a major NBA trade',\n ),\n });\n\n // Additional verification for escaped quotes handling\n expect(result.perspectives[0].holisticDigest).toContain('\"Big 3\" experiment');\n expect(result.perspectives[0].holisticDigest).toContain(\n \"Rockets' championship aspirations\",\n );\n expect(result.perspectives[0].holisticDigest).toContain(\"Durant's decision\");\n });\n });\n});\n"],"names":["describe","expect","it","z","StructuredResponseParser","StructuredResponseParserError","testSchema","object","content","string","tags","array","title","validJson","validJsonString","JSON","stringify","text","parser","result","parse","toEqual","arraySchema","toBe","number","boolean","null","toBeNull","toThrow","invalidJson","unsupportedSchema","union","Error","error","toBeInstanceOf","textWithNewlines","complexSchema","category","countries","perspectives","holisticDigest","discourse_type","stance","synopsis","stringContaining","toContain"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,iBAAiB;AACtD,SAASC,CAAC,QAAQ,SAAS;AAE3B,SAASC,wBAAwB,QAAQ,mCAAmC;AAC5E,SAASC,6BAA6B,QAAQ,yCAAyC;AAEvF,YAAY;AACZ,IAAMC,aAAaH,EAAEI,MAAM,CAAC;IACxBC,SAASL,EAAEM,MAAM;IACjBC,MAAMP,EAAEQ,KAAK,CAACR,EAAEM,MAAM;IACtBG,OAAOT,EAAEM,MAAM;AACnB;AAEA,IAAMI,YAAY;IACdL,SAAS;IACTE,MAAM;QAAC;QAAQ;KAAK;IACpBE,OAAO;AACX;AAEA,IAAME,kBAAkBC,KAAKC,SAAS,CAACH;AAEvCb,SAAS,4BAA4B;IACjCA,SAAS,SAAS;QACdE,GAAG,kCAAkC;YACjC,gDAAgD;YAChD,IAAMe,OAAOH;YACb,IAAMI,SAAS,IAAId,yBAAyBE;YAE5C,4BAA4B;YAC5B,IAAMa,SAASD,OAAOE,KAAK,CAACH;YAE5B,4CAA4C;YAC5ChB,OAAOkB,QAAQE,OAAO,CAACR;QAC3B;QAEAX,GAAG,kDAAkD;YACjD,gEAAgE;YAChE,IAAMe,OAAO,AAAC,uBAAsC,OAAhBH,iBAAgB;YACpD,IAAMI,SAAS,IAAId,yBAAyBE;YAE5C,4BAA4B;YAC5B,IAAMa,SAASD,OAAOE,KAAK,CAACH;YAE5B,4CAA4C;YAC5ChB,OAAOkB,QAAQE,OAAO,CAACR;QAC3B;QAEAX,GAAG,+BAA+B;YAC9B,+CAA+C;YAC/C,IAAMoB,cAAcnB,EAAEQ,KAAK,CAACR,EAAEM,MAAM;YACpC,IAAM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;gBACDC,UAAU1C,OAAO2C,gBAAgB,CAC7B;YAER;YAEA,sDAAsD;YACtD3C,OAAOkB,OAAOoB,YAAY,CAAC,EAAE,CAACC,cAAc,EAAEK,SAAS,CAAC;YACxD5C,OAAOkB,OAAOoB,YAAY,CAAC,EAAE,CAACC,cAAc,EAAEK,SAAS,CACnD;YAEJ5C,OAAOkB,OAAOoB,YAAY,CAAC,EAAE,CAACC,cAAc,EAAEK,SAAS,CAAC;QAC5D;IACJ;AACJ"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom error for structured response parsing failures
|
|
3
|
-
*/
|
|
4
|
-
export declare class StructuredResponseParserError extends Error {
|
|
5
|
-
readonly cause?: unknown | undefined;
|
|
6
|
-
readonly text?: string | undefined;
|
|
7
|
-
constructor(message: string, cause?: unknown | undefined, text?: string | undefined);
|
|
8
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom error for structured response parsing failures
|
|
3
|
-
*/ function _assert_this_initialized(self) {
|
|
4
|
-
if (self === void 0) {
|
|
5
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
6
|
-
}
|
|
7
|
-
return self;
|
|
8
|
-
}
|
|
9
|
-
function _call_super(_this, derived, args) {
|
|
10
|
-
derived = _get_prototype_of(derived);
|
|
11
|
-
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
12
|
-
}
|
|
13
|
-
function _class_call_check(instance, Constructor) {
|
|
14
|
-
if (!(instance instanceof Constructor)) {
|
|
15
|
-
throw new TypeError("Cannot call a class as a function");
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function _construct(Parent, args, Class) {
|
|
19
|
-
if (_is_native_reflect_construct()) {
|
|
20
|
-
_construct = Reflect.construct;
|
|
21
|
-
} else {
|
|
22
|
-
_construct = function construct(Parent, args, Class) {
|
|
23
|
-
var a = [
|
|
24
|
-
null
|
|
25
|
-
];
|
|
26
|
-
a.push.apply(a, args);
|
|
27
|
-
var Constructor = Function.bind.apply(Parent, a);
|
|
28
|
-
var instance = new Constructor();
|
|
29
|
-
if (Class) _set_prototype_of(instance, Class.prototype);
|
|
30
|
-
return instance;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return _construct.apply(null, arguments);
|
|
34
|
-
}
|
|
35
|
-
function _define_property(obj, key, value) {
|
|
36
|
-
if (key in obj) {
|
|
37
|
-
Object.defineProperty(obj, key, {
|
|
38
|
-
value: value,
|
|
39
|
-
enumerable: true,
|
|
40
|
-
configurable: true,
|
|
41
|
-
writable: true
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
44
|
-
obj[key] = value;
|
|
45
|
-
}
|
|
46
|
-
return obj;
|
|
47
|
-
}
|
|
48
|
-
function _get_prototype_of(o) {
|
|
49
|
-
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
50
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
51
|
-
};
|
|
52
|
-
return _get_prototype_of(o);
|
|
53
|
-
}
|
|
54
|
-
function _inherits(subClass, superClass) {
|
|
55
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
56
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
57
|
-
}
|
|
58
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
59
|
-
constructor: {
|
|
60
|
-
value: subClass,
|
|
61
|
-
writable: true,
|
|
62
|
-
configurable: true
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
if (superClass) _set_prototype_of(subClass, superClass);
|
|
66
|
-
}
|
|
67
|
-
function _is_native_function(fn) {
|
|
68
|
-
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
69
|
-
}
|
|
70
|
-
function _possible_constructor_return(self, call) {
|
|
71
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
72
|
-
return call;
|
|
73
|
-
}
|
|
74
|
-
return _assert_this_initialized(self);
|
|
75
|
-
}
|
|
76
|
-
function _set_prototype_of(o, p) {
|
|
77
|
-
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
78
|
-
o.__proto__ = p;
|
|
79
|
-
return o;
|
|
80
|
-
};
|
|
81
|
-
return _set_prototype_of(o, p);
|
|
82
|
-
}
|
|
83
|
-
function _type_of(obj) {
|
|
84
|
-
"@swc/helpers - typeof";
|
|
85
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
86
|
-
}
|
|
87
|
-
function _wrap_native_super(Class) {
|
|
88
|
-
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
89
|
-
_wrap_native_super = function wrapNativeSuper(Class) {
|
|
90
|
-
if (Class === null || !_is_native_function(Class)) return Class;
|
|
91
|
-
if (typeof Class !== "function") {
|
|
92
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
93
|
-
}
|
|
94
|
-
if (typeof _cache !== "undefined") {
|
|
95
|
-
if (_cache.has(Class)) return _cache.get(Class);
|
|
96
|
-
_cache.set(Class, Wrapper);
|
|
97
|
-
}
|
|
98
|
-
function Wrapper() {
|
|
99
|
-
return _construct(Class, arguments, _get_prototype_of(this).constructor);
|
|
100
|
-
}
|
|
101
|
-
Wrapper.prototype = Object.create(Class.prototype, {
|
|
102
|
-
constructor: {
|
|
103
|
-
value: Wrapper,
|
|
104
|
-
enumerable: false,
|
|
105
|
-
writable: true,
|
|
106
|
-
configurable: true
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
return _set_prototype_of(Wrapper, Class);
|
|
110
|
-
};
|
|
111
|
-
return _wrap_native_super(Class);
|
|
112
|
-
}
|
|
113
|
-
function _is_native_reflect_construct() {
|
|
114
|
-
try {
|
|
115
|
-
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
116
|
-
} catch (_) {}
|
|
117
|
-
return (_is_native_reflect_construct = function() {
|
|
118
|
-
return !!result;
|
|
119
|
-
})();
|
|
120
|
-
}
|
|
121
|
-
export var StructuredResponseParserError = /*#__PURE__*/ function(Error1) {
|
|
122
|
-
"use strict";
|
|
123
|
-
_inherits(StructuredResponseParserError, Error1);
|
|
124
|
-
function StructuredResponseParserError(message, cause, text) {
|
|
125
|
-
_class_call_check(this, StructuredResponseParserError);
|
|
126
|
-
var _this;
|
|
127
|
-
_this = _call_super(this, StructuredResponseParserError, [
|
|
128
|
-
message
|
|
129
|
-
]), _define_property(_this, "cause", void 0), _define_property(_this, "text", void 0), _this.cause = cause, _this.text = text;
|
|
130
|
-
_this.name = 'StructuredResponseParserError';
|
|
131
|
-
return _this;
|
|
132
|
-
}
|
|
133
|
-
return StructuredResponseParserError;
|
|
134
|
-
}(_wrap_native_super(Error));
|
|
135
|
-
|
|
136
|
-
//# sourceMappingURL=structured-response-parser-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/utils/structured-response-parser-error.ts"],"sourcesContent":["/**\n * Custom error for structured response parsing failures\n */\nexport class StructuredResponseParserError extends Error {\n constructor(\n message: string,\n public readonly cause?: unknown,\n public readonly text?: string,\n ) {\n super(message);\n this.name = 'StructuredResponseParserError';\n }\n}\n"],"names":["StructuredResponseParserError","message","cause","text","name","Error"],"mappings":"AAAA;;CAEC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACD,OAAO,IAAA,AAAMA,8CAAN;;cAAMA;aAAAA,8BAELC,OAAe,EACf,AAAgBC,KAAe,EAC/B,AAAgBC,IAAa;gCAJxBH;;gBAML,kBANKA;YAMCC;qGAHUC,QAAAA,aACAC,OAAAA;QAGhB,MAAKC,IAAI,GAAG;;;WAPPJ;qBAAsCK,QASlD"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod/v4';
|
|
2
|
-
/**
|
|
3
|
-
* Parses AI response text into structured data based on Zod schema
|
|
4
|
-
*/
|
|
5
|
-
export declare class StructuredResponseParser<T> {
|
|
6
|
-
private readonly schema;
|
|
7
|
-
constructor(schema: z.ZodSchema<T>);
|
|
8
|
-
/**
|
|
9
|
-
* Parses the AI response text based on the configured schema
|
|
10
|
-
*/
|
|
11
|
-
parse(text: string): T;
|
|
12
|
-
/**
|
|
13
|
-
* Cleans text and finds the largest schema-compatible structure
|
|
14
|
-
*/
|
|
15
|
-
private cleanText;
|
|
16
|
-
/**
|
|
17
|
-
* Converts value to appropriate primitive type based on schema
|
|
18
|
-
*/
|
|
19
|
-
private convertToPrimitive;
|
|
20
|
-
/**
|
|
21
|
-
* Extracts array from text
|
|
22
|
-
*/
|
|
23
|
-
private extractArray;
|
|
24
|
-
/**
|
|
25
|
-
* Extracts and validates JSON content from a code block
|
|
26
|
-
*/
|
|
27
|
-
private extractJsonFromCodeBlock;
|
|
28
|
-
/**
|
|
29
|
-
* Extracts and parses JSON from text based on schema type
|
|
30
|
-
*/
|
|
31
|
-
private extractJsonFromText;
|
|
32
|
-
/**
|
|
33
|
-
* Extracts object from text
|
|
34
|
-
*/
|
|
35
|
-
private extractObject;
|
|
36
|
-
/**
|
|
37
|
-
* Extracts and converts primitive value from text
|
|
38
|
-
*/
|
|
39
|
-
private extractPrimitive;
|
|
40
|
-
/**
|
|
41
|
-
* Finds valid JSON structures in raw text
|
|
42
|
-
*/
|
|
43
|
-
private findJsonStructures;
|
|
44
|
-
/**
|
|
45
|
-
* Returns the largest string from an array of strings
|
|
46
|
-
*/
|
|
47
|
-
private findLargestString;
|
|
48
|
-
/**
|
|
49
|
-
* Repairs common JSON issues using jsonrepair library
|
|
50
|
-
*/
|
|
51
|
-
private repairJson;
|
|
52
|
-
/**
|
|
53
|
-
* Recursively unescapes all string values in a JSON object/array
|
|
54
|
-
*/
|
|
55
|
-
private unescapeJsonValues;
|
|
56
|
-
/**
|
|
57
|
-
* Unescapes common escaped characters in text
|
|
58
|
-
*/
|
|
59
|
-
private unescapeText;
|
|
60
|
-
}
|