@jterrazz/intelligence 1.6.1 → 2.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 +199 -83
- package/dist/adapters/agents/{basic-agent.adapter.d.ts → chat-agent.adapter.d.ts} +6 -6
- package/dist/adapters/agents/{basic-agent.adapter.js → chat-agent.adapter.js} +37 -20
- package/dist/adapters/agents/chat-agent.adapter.js.map +1 -0
- package/dist/adapters/agents/{retryable-agent.adapter.d.ts → resilient-agent.adapter.d.ts} +4 -4
- package/dist/adapters/agents/{retryable-agent.adapter.js → resilient-agent.adapter.js} +8 -8
- package/dist/adapters/agents/resilient-agent.adapter.js.map +1 -0
- package/dist/adapters/agents/{autonomous-agent.adapter.d.ts → tool-agent.adapter.d.ts} +6 -6
- package/dist/adapters/agents/{autonomous-agent.adapter.js → tool-agent.adapter.js} +10 -10
- package/dist/adapters/agents/tool-agent.adapter.js.map +1 -0
- package/dist/adapters/models/openrouter-model.adapter.d.ts +17 -32
- package/dist/adapters/models/openrouter-model.adapter.js +84 -25
- package/dist/adapters/models/openrouter-model.adapter.js.map +1 -1
- package/dist/adapters/prompts/__tests__/presets.test.js +4 -4
- package/dist/adapters/prompts/__tests__/presets.test.js.map +1 -1
- package/dist/adapters/prompts/system-prompt.adapter.d.ts +2 -2
- package/dist/adapters/prompts/system-prompt.adapter.js +6 -6
- package/dist/adapters/prompts/system-prompt.adapter.js.map +1 -1
- package/dist/adapters/prompts/user-prompt.adapter.d.ts +2 -2
- package/dist/adapters/prompts/user-prompt.adapter.js +6 -6
- package/dist/adapters/prompts/user-prompt.adapter.js.map +1 -1
- package/dist/adapters/providers/openrouter-provider.adapter.d.ts +34 -0
- package/dist/adapters/providers/openrouter-provider.adapter.js +57 -0
- package/dist/adapters/providers/openrouter-provider.adapter.js.map +1 -0
- package/dist/adapters/tools/safe-tool.adapter.d.ts +2 -2
- package/dist/adapters/tools/safe-tool.adapter.js +6 -6
- package/dist/adapters/tools/safe-tool.adapter.js.map +1 -1
- package/dist/adapters/utils/__tests__/{ai-response-parser.test.js → structured-response-parser.test.js} +30 -30
- package/dist/adapters/utils/__tests__/structured-response-parser.test.js.map +1 -0
- package/dist/adapters/utils/{ai-response-parser-error.d.ts → structured-response-parser-error.d.ts} +2 -2
- package/dist/adapters/utils/{ai-response-parser-error.js → structured-response-parser-error.js} +9 -9
- package/dist/adapters/utils/structured-response-parser-error.js.map +1 -0
- package/dist/adapters/utils/{ai-response-parser.d.ts → structured-response-parser.d.ts} +1 -1
- package/dist/adapters/utils/{ai-response-parser.js → structured-response-parser.js} +13 -13
- package/dist/adapters/utils/structured-response-parser.js.map +1 -0
- package/dist/index.cjs +727 -342
- package/dist/index.d.ts +11 -8
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/dist/ports/model.port.d.ts +30 -3
- package/dist/ports/model.port.js +1 -1
- package/dist/ports/model.port.js.map +1 -1
- package/dist/ports/provider.port.d.ts +13 -0
- package/dist/ports/provider.port.js +5 -0
- package/dist/ports/provider.port.js.map +1 -0
- package/package.json +11 -9
- package/dist/adapters/agents/autonomous-agent.adapter.js.map +0 -1
- package/dist/adapters/agents/basic-agent.adapter.js.map +0 -1
- package/dist/adapters/agents/retryable-agent.adapter.js.map +0 -1
- package/dist/adapters/utils/__tests__/ai-response-parser.test.js.map +0 -1
- package/dist/adapters/utils/ai-response-parser-error.js.map +0 -1
- package/dist/adapters/utils/ai-response-parser.js.map +0 -1
- /package/dist/adapters/utils/__tests__/{ai-response-parser.test.d.ts → structured-response-parser.test.d.ts} +0 -0
|
@@ -159,12 +159,12 @@ function _ts_generator(thisArg, body) {
|
|
|
159
159
|
}
|
|
160
160
|
import { DynamicStructuredTool, DynamicTool } from 'langchain/tools';
|
|
161
161
|
/**
|
|
162
|
-
* Safe tool
|
|
163
|
-
*/ export var
|
|
162
|
+
* Safe tool that provides error handling and logging for LangChain tools
|
|
163
|
+
*/ export var SafeTool = /*#__PURE__*/ function() {
|
|
164
164
|
"use strict";
|
|
165
|
-
function
|
|
165
|
+
function SafeTool(config) {
|
|
166
166
|
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
167
|
-
_class_call_check(this,
|
|
167
|
+
_class_call_check(this, SafeTool);
|
|
168
168
|
_define_property(this, "config", void 0);
|
|
169
169
|
_define_property(this, "options", void 0);
|
|
170
170
|
_define_property(this, "dynamicTool", void 0);
|
|
@@ -267,7 +267,7 @@ import { DynamicStructuredTool, DynamicTool } from 'langchain/tools';
|
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
_create_class(
|
|
270
|
+
_create_class(SafeTool, [
|
|
271
271
|
{
|
|
272
272
|
/**
|
|
273
273
|
* Get the underlying LangChain DynamicTool instance
|
|
@@ -277,7 +277,7 @@ import { DynamicStructuredTool, DynamicTool } from 'langchain/tools';
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
]);
|
|
280
|
-
return
|
|
280
|
+
return SafeTool;
|
|
281
281
|
}();
|
|
282
282
|
|
|
283
283
|
//# sourceMappingURL=safe-tool.adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/tools/safe-tool.adapter.ts"],"sourcesContent":["import type { LoggerPort } from '@jterrazz/logger';\nimport { DynamicStructuredTool, DynamicTool } from 'langchain/tools';\nimport type { z } from 'zod/v4';\n\nimport type { ToolPort } from '../../ports/tool.port.js';\n\nexport interface SafeToolOptions<T> {\n logger?: LoggerPort;\n schema?: z.ZodSchema<T>;\n}\n\nexport type ToolConfig<T = void> = {\n description: string;\n execute: ToolFunction<T>;\n name: string;\n};\n\nexport type ToolFunction<T = void> = T extends void\n ? () => Promise<string>\n : (args: T) => Promise<string>;\n\n/**\n * Safe tool
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/tools/safe-tool.adapter.ts"],"sourcesContent":["import type { LoggerPort } from '@jterrazz/logger';\nimport { DynamicStructuredTool, DynamicTool } from 'langchain/tools';\nimport type { z } from 'zod/v4';\n\nimport type { ToolPort } from '../../ports/tool.port.js';\n\nexport interface SafeToolOptions<T> {\n logger?: LoggerPort;\n schema?: z.ZodSchema<T>;\n}\n\nexport type ToolConfig<T = void> = {\n description: string;\n execute: ToolFunction<T>;\n name: string;\n};\n\nexport type ToolFunction<T = void> = T extends void\n ? () => Promise<string>\n : (args: T) => Promise<string>;\n\n/**\n * Safe tool that provides error handling and logging for LangChain tools\n */\nexport class SafeTool<T = void> implements ToolPort {\n private readonly dynamicTool: DynamicStructuredTool<z.ZodSchema<T>> | DynamicTool;\n\n constructor(\n private readonly config: ToolConfig<T>,\n private readonly options: SafeToolOptions<T> = {},\n ) {\n const { logger, schema } = options;\n\n if (schema) {\n // Use DynamicStructuredTool for parameterized tools\n this.dynamicTool = new DynamicStructuredTool({\n description: config.description,\n func: async (args: T) => {\n try {\n return await (config.execute as ToolFunction<T>)(args);\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n\n logger?.error(`Unexpected error in ${config.name}`, {\n args,\n error: errorMessage,\n toolName: config.name,\n });\n\n return `Tool ${config.name} failed to execute`;\n }\n },\n name: config.name,\n schema: schema,\n });\n } else {\n // Use DynamicTool for simple tools\n this.dynamicTool = new DynamicTool({\n description: config.description,\n func: async () => {\n try {\n return await (config.execute as ToolFunction<void>)();\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n\n logger?.error(`Unexpected error in ${config.name}`, {\n error: errorMessage,\n toolName: config.name,\n });\n\n return `Tool ${config.name} failed to execute`;\n }\n },\n name: config.name,\n });\n }\n }\n\n /**\n * Get the underlying LangChain DynamicTool instance\n */\n getDynamicTool(): DynamicStructuredTool<z.ZodSchema<unknown>> | DynamicTool {\n return this.dynamicTool as DynamicStructuredTool<z.ZodSchema<unknown>> | DynamicTool;\n }\n}\n"],"names":["DynamicStructuredTool","DynamicTool","SafeTool","config","options","dynamicTool","logger","schema","description","func","args","error","errorMessage","execute","Error","message","String","name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O;;;oCAA5B;;wCAAO;;;oCACFF;oCACCC,eAAeD,AAAK,YAALA,OAAiBG,SAAQH,MAAMI,OAAO,GAAGC,OAAOL;oCAErEL,mBAAAA,6BAAAA,OAAQK,KAAK,CAAC,AAAC,uBAAkC,OAAZR,OAAOc,IAAI,GAAI;wCAChDN,OAAOC;wCACPM,UAAUf,OAAOc,IAAI;oCACzB;oCAEA;;wCAAQ,QAAmB,OAAZd,OAAOc,IAAI,EAAC;;;;;;;;oBAEnC;;gBACAA,MAAMd,OAAOc,IAAI;YACrB;QACJ;;kBAnDKf;;YAsDT;;KAEC,GACDiB,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,CAACd,WAAW;YAC3B;;;WA3DSH;IA4DZ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from '@jterrazz/test';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { StructuredResponseParser } from '../structured-response-parser.js';
|
|
4
|
+
import { StructuredResponseParserError } from '../structured-response-parser-error.js';
|
|
5
5
|
// Test data
|
|
6
6
|
var testSchema = z.object({
|
|
7
7
|
content: z.string(),
|
|
@@ -17,12 +17,12 @@ var validJson = {
|
|
|
17
17
|
title: 'Test Article'
|
|
18
18
|
};
|
|
19
19
|
var validJsonString = JSON.stringify(validJson);
|
|
20
|
-
describe('
|
|
20
|
+
describe('StructuredResponseParser', function() {
|
|
21
21
|
describe('parse', function() {
|
|
22
22
|
it('should parse valid JSON object', function() {
|
|
23
23
|
// Given - a valid JSON object string and parser
|
|
24
24
|
var text = validJsonString;
|
|
25
|
-
var parser = new
|
|
25
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
26
26
|
// When - parsing the string
|
|
27
27
|
var result = parser.parse(text);
|
|
28
28
|
// Then - it should return the parsed object
|
|
@@ -31,7 +31,7 @@ describe('AIResponseParser', function() {
|
|
|
31
31
|
it('should parse JSON object with surrounding text', function() {
|
|
32
32
|
// Given - a JSON object string with surrounding text and parser
|
|
33
33
|
var text = "Here's the article: ".concat(validJsonString, " - end of article");
|
|
34
|
-
var parser = new
|
|
34
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
35
35
|
// When - parsing the string
|
|
36
36
|
var result = parser.parse(text);
|
|
37
37
|
// Then - it should return the parsed object
|
|
@@ -41,7 +41,7 @@ describe('AIResponseParser', function() {
|
|
|
41
41
|
// Given - a JSON array string and array parser
|
|
42
42
|
var arraySchema = z.array(z.string());
|
|
43
43
|
var text = '["test", "ai", "content"]';
|
|
44
|
-
var parser = new
|
|
44
|
+
var parser = new StructuredResponseParser(arraySchema);
|
|
45
45
|
// When - parsing the string
|
|
46
46
|
var result = parser.parse(text);
|
|
47
47
|
// Then - it should return the parsed array
|
|
@@ -54,7 +54,7 @@ describe('AIResponseParser', function() {
|
|
|
54
54
|
it('should parse primitive string value', function() {
|
|
55
55
|
// Given - a JSON string value and string parser
|
|
56
56
|
var text = '"test string"';
|
|
57
|
-
var parser = new
|
|
57
|
+
var parser = new StructuredResponseParser(z.string());
|
|
58
58
|
// When - parsing the string
|
|
59
59
|
var result = parser.parse(text);
|
|
60
60
|
// Then - it should return the parsed string
|
|
@@ -63,7 +63,7 @@ describe('AIResponseParser', function() {
|
|
|
63
63
|
it('should parse primitive number value', function() {
|
|
64
64
|
// Given - a JSON number value and number parser
|
|
65
65
|
var text = '42';
|
|
66
|
-
var parser = new
|
|
66
|
+
var parser = new StructuredResponseParser(z.number());
|
|
67
67
|
// When - parsing the string
|
|
68
68
|
var result = parser.parse(text);
|
|
69
69
|
// Then - it should return the parsed number
|
|
@@ -72,7 +72,7 @@ describe('AIResponseParser', function() {
|
|
|
72
72
|
it('should parse primitive boolean value', function() {
|
|
73
73
|
// Given - a JSON boolean value and boolean parser
|
|
74
74
|
var text = 'true';
|
|
75
|
-
var parser = new
|
|
75
|
+
var parser = new StructuredResponseParser(z["boolean"]());
|
|
76
76
|
// When - parsing the string
|
|
77
77
|
var result = parser.parse(text);
|
|
78
78
|
// Then - it should return the parsed boolean
|
|
@@ -81,7 +81,7 @@ describe('AIResponseParser', function() {
|
|
|
81
81
|
it('should parse primitive null value', function() {
|
|
82
82
|
// Given - a JSON null value and null parser
|
|
83
83
|
var text = 'null';
|
|
84
|
-
var parser = new
|
|
84
|
+
var parser = new StructuredResponseParser(z["null"]());
|
|
85
85
|
// When - parsing the string
|
|
86
86
|
var result = parser.parse(text);
|
|
87
87
|
// Then - it should return the parsed null
|
|
@@ -90,11 +90,11 @@ describe('AIResponseParser', function() {
|
|
|
90
90
|
it('should throw ResponseParsingError when JSON is invalid', function() {
|
|
91
91
|
// Given - an invalid JSON string and parser
|
|
92
92
|
var text = '{invalid json}';
|
|
93
|
-
var parser = new
|
|
93
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
94
94
|
// When/Then - parsing the string should throw a ResponseParsingError
|
|
95
95
|
expect(function() {
|
|
96
96
|
return parser.parse(text);
|
|
97
|
-
}).toThrow(
|
|
97
|
+
}).toThrow(StructuredResponseParserError);
|
|
98
98
|
});
|
|
99
99
|
it('should throw ResponseParsingError when schema validation fails', function() {
|
|
100
100
|
// Given - an invalid JSON object and parser
|
|
@@ -108,30 +108,30 @@ describe('AIResponseParser', function() {
|
|
|
108
108
|
title: 123
|
|
109
109
|
};
|
|
110
110
|
var text = JSON.stringify(invalidJson);
|
|
111
|
-
var parser = new
|
|
111
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
112
112
|
// When/Then - parsing the string should throw a ResponseParsingError
|
|
113
113
|
expect(function() {
|
|
114
114
|
return parser.parse(text);
|
|
115
|
-
}).toThrow(
|
|
115
|
+
}).toThrow(StructuredResponseParserError);
|
|
116
116
|
});
|
|
117
117
|
it('should throw ResponseParsingError when no object found in text', function() {
|
|
118
118
|
// Given - a text without a JSON object and parser
|
|
119
119
|
var text = 'No JSON object here';
|
|
120
|
-
var parser = new
|
|
120
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
121
121
|
// When/Then - parsing the string should throw a ResponseParsingError
|
|
122
122
|
expect(function() {
|
|
123
123
|
return parser.parse(text);
|
|
124
|
-
}).toThrow(
|
|
124
|
+
}).toThrow(StructuredResponseParserError);
|
|
125
125
|
});
|
|
126
126
|
it('should throw ResponseParsingError when no array found in text', function() {
|
|
127
127
|
// Given - a text without a JSON array and array parser
|
|
128
128
|
var text = 'No array here';
|
|
129
129
|
var arraySchema = z.array(z.string());
|
|
130
|
-
var parser = new
|
|
130
|
+
var parser = new StructuredResponseParser(arraySchema);
|
|
131
131
|
// When/Then - parsing the string should throw a ResponseParsingError
|
|
132
132
|
expect(function() {
|
|
133
133
|
return parser.parse(text);
|
|
134
|
-
}).toThrow(
|
|
134
|
+
}).toThrow(StructuredResponseParserError);
|
|
135
135
|
});
|
|
136
136
|
it('should throw ResponseParsingError for unsupported schema type', function() {
|
|
137
137
|
// Given - a text with an unsupported schema type and parser
|
|
@@ -140,30 +140,30 @@ describe('AIResponseParser', function() {
|
|
|
140
140
|
z.string(),
|
|
141
141
|
z.number()
|
|
142
142
|
]);
|
|
143
|
-
var parser = new
|
|
143
|
+
var parser = new StructuredResponseParser(unsupportedSchema);
|
|
144
144
|
// When/Then - parsing the string should throw a ResponseParsingError
|
|
145
145
|
expect(function() {
|
|
146
146
|
return parser.parse(text);
|
|
147
|
-
}).toThrow(
|
|
147
|
+
}).toThrow(StructuredResponseParserError);
|
|
148
148
|
});
|
|
149
149
|
it('should include original text in error when parsing fails', function() {
|
|
150
150
|
// Given - an invalid JSON string and parser
|
|
151
151
|
var text = '{invalid json}';
|
|
152
|
-
var parser = new
|
|
152
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
153
153
|
// When - parsing the string
|
|
154
154
|
try {
|
|
155
155
|
parser.parse(text);
|
|
156
156
|
throw new Error('Should have thrown an error');
|
|
157
157
|
} catch (error) {
|
|
158
158
|
// Then - the error should include the original text
|
|
159
|
-
expect(error).toBeInstanceOf(
|
|
159
|
+
expect(error).toBeInstanceOf(StructuredResponseParserError);
|
|
160
160
|
expect(error.text).toBe(text);
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
163
|
it('should handle text with newlines in JSON object', function() {
|
|
164
164
|
// Given - a JSON object with newlines and parser
|
|
165
165
|
var textWithNewlines = '{\n "content": "Test\ncontent\nwith\nnewlines",\n "tags": ["test", "ai"],\n "title": "Test\nArticle"\n }';
|
|
166
|
-
var parser = new
|
|
166
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
167
167
|
// When - parsing the string
|
|
168
168
|
var result = parser.parse(textWithNewlines);
|
|
169
169
|
// Then - it should return the parsed object
|
|
@@ -179,7 +179,7 @@ describe('AIResponseParser', function() {
|
|
|
179
179
|
it('should handle text with newlines in surrounding text', function() {
|
|
180
180
|
// Given - a text with newlines around the JSON object and parser
|
|
181
181
|
var textWithNewlines = "Here's the\narticle:\n".concat(validJsonString, "\n- end of\narticle");
|
|
182
|
-
var parser = new
|
|
182
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
183
183
|
// When - parsing the string
|
|
184
184
|
var result = parser.parse(textWithNewlines);
|
|
185
185
|
// Then - it should return the parsed object
|
|
@@ -188,7 +188,7 @@ describe('AIResponseParser', function() {
|
|
|
188
188
|
it('should handle text with multiple consecutive newlines and spaces', function() {
|
|
189
189
|
// Given - a text with multiple consecutive newlines and spaces and parser
|
|
190
190
|
var textWithNewlines = "Here's the\n\n article: \n\n".concat(validJsonString, "\n\n");
|
|
191
|
-
var parser = new
|
|
191
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
192
192
|
// When - parsing the string
|
|
193
193
|
var result = parser.parse(textWithNewlines);
|
|
194
194
|
// Then - it should return the parsed object
|
|
@@ -197,7 +197,7 @@ describe('AIResponseParser', function() {
|
|
|
197
197
|
it('should handle escaped characters in JSON', function() {
|
|
198
198
|
// Given - a JSON string with escaped characters and parser
|
|
199
199
|
var text = '{"content": "Test\\ncontent\\twith\\r\\nescapes", "tags": ["test\\u0020ai", "escaped\\"quotes\\""], "title": "Test\\\\Article"}';
|
|
200
|
-
var parser = new
|
|
200
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
201
201
|
// When - parsing the string
|
|
202
202
|
var result = parser.parse(text);
|
|
203
203
|
// Then - it should return the parsed object
|
|
@@ -213,7 +213,7 @@ describe('AIResponseParser', function() {
|
|
|
213
213
|
it('should handle escaped characters in markdown code blocks', function() {
|
|
214
214
|
// Given - a markdown code block with escaped characters and parser
|
|
215
215
|
var text = '```json\n{"content": "Test\\nContent", "tags": ["test\\u0020ai"], "title": "Test\\\\Title"}\n```';
|
|
216
|
-
var parser = new
|
|
216
|
+
var parser = new StructuredResponseParser(testSchema);
|
|
217
217
|
// When - parsing the string
|
|
218
218
|
var result = parser.parse(text);
|
|
219
219
|
// Then - it should return the parsed object
|
|
@@ -229,7 +229,7 @@ describe('AIResponseParser', function() {
|
|
|
229
229
|
// Given - a markdown code block with escaped characters and array parser
|
|
230
230
|
var text = '```json\n [\n{"content": "Test\\nContent", "tags": ["test\\u0020ai"], "title": "Test\\\\Title"}\n]\n```';
|
|
231
231
|
var arraySchema = z.array(testSchema);
|
|
232
|
-
var parser = new
|
|
232
|
+
var parser = new StructuredResponseParser(arraySchema);
|
|
233
233
|
// When - parsing the string
|
|
234
234
|
var result = parser.parse(text);
|
|
235
235
|
// Then - it should return the parsed array
|
|
@@ -258,7 +258,7 @@ describe('AIResponseParser', function() {
|
|
|
258
258
|
synopsis: z.string()
|
|
259
259
|
});
|
|
260
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
|
|
261
|
+
var parser = new StructuredResponseParser(complexSchema);
|
|
262
262
|
// When - parsing the string
|
|
263
263
|
var result = parser.parse(text);
|
|
264
264
|
// Then - it should return the parsed object with escaped quotes properly handled
|
|
@@ -286,4 +286,4 @@ describe('AIResponseParser', function() {
|
|
|
286
286
|
});
|
|
287
287
|
});
|
|
288
288
|
|
|
289
|
-
//# sourceMappingURL=
|
|
289
|
+
//# sourceMappingURL=structured-response-parser.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,KA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AC;gBACnBgB,UAAU;gBACVC,WAAW;oBAAC;iBAAK;gBACjBC,cAAc;oBACV;wBACIC,gBAAgBvC,OAAO2C,gBAAgB,CACnC;wBAEJlC,MAAM;4BACF+B,gBAAgB;4BAChBC,QAAQ;wBACZ;oBACJ;iBACH;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"}
|
package/dist/adapters/utils/{ai-response-parser-error.d.ts → structured-response-parser-error.d.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Custom error for
|
|
2
|
+
* Custom error for structured response parsing failures
|
|
3
3
|
*/
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class StructuredResponseParserError extends Error {
|
|
5
5
|
readonly cause?: unknown | undefined;
|
|
6
6
|
readonly text?: string | undefined;
|
|
7
7
|
constructor(message: string, cause?: unknown | undefined, text?: string | undefined);
|
package/dist/adapters/utils/{ai-response-parser-error.js → structured-response-parser-error.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Custom error for
|
|
2
|
+
* Custom error for structured response parsing failures
|
|
3
3
|
*/ function _assert_this_initialized(self) {
|
|
4
4
|
if (self === void 0) {
|
|
5
5
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
@@ -118,19 +118,19 @@ function _is_native_reflect_construct() {
|
|
|
118
118
|
return !!result;
|
|
119
119
|
})();
|
|
120
120
|
}
|
|
121
|
-
export var
|
|
121
|
+
export var StructuredResponseParserError = /*#__PURE__*/ function(Error1) {
|
|
122
122
|
"use strict";
|
|
123
|
-
_inherits(
|
|
124
|
-
function
|
|
125
|
-
_class_call_check(this,
|
|
123
|
+
_inherits(StructuredResponseParserError, Error1);
|
|
124
|
+
function StructuredResponseParserError(message, cause, text) {
|
|
125
|
+
_class_call_check(this, StructuredResponseParserError);
|
|
126
126
|
var _this;
|
|
127
|
-
_this = _call_super(this,
|
|
127
|
+
_this = _call_super(this, StructuredResponseParserError, [
|
|
128
128
|
message
|
|
129
129
|
]), _define_property(_this, "cause", void 0), _define_property(_this, "text", void 0), _this.cause = cause, _this.text = text;
|
|
130
|
-
_this.name = '
|
|
130
|
+
_this.name = 'StructuredResponseParserError';
|
|
131
131
|
return _this;
|
|
132
132
|
}
|
|
133
|
-
return
|
|
133
|
+
return StructuredResponseParserError;
|
|
134
134
|
}(_wrap_native_super(Error));
|
|
135
135
|
|
|
136
|
-
//# sourceMappingURL=
|
|
136
|
+
//# sourceMappingURL=structured-response-parser-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod/v4';
|
|
|
2
2
|
/**
|
|
3
3
|
* Parses AI response text into structured data based on Zod schema
|
|
4
4
|
*/
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class StructuredResponseParser<T> {
|
|
6
6
|
private readonly schema;
|
|
7
7
|
constructor(schema: z.ZodSchema<T>);
|
|
8
8
|
/**
|
|
@@ -89,17 +89,17 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
89
89
|
}
|
|
90
90
|
import { jsonrepair } from 'jsonrepair';
|
|
91
91
|
import { z } from 'zod/v4';
|
|
92
|
-
import {
|
|
92
|
+
import { StructuredResponseParserError } from './structured-response-parser-error.js';
|
|
93
93
|
/**
|
|
94
94
|
* Parses AI response text into structured data based on Zod schema
|
|
95
|
-
*/ export var
|
|
95
|
+
*/ export var StructuredResponseParser = /*#__PURE__*/ function() {
|
|
96
96
|
"use strict";
|
|
97
|
-
function
|
|
98
|
-
_class_call_check(this,
|
|
97
|
+
function StructuredResponseParser(schema) {
|
|
98
|
+
_class_call_check(this, StructuredResponseParser);
|
|
99
99
|
_define_property(this, "schema", void 0);
|
|
100
100
|
this.schema = schema;
|
|
101
101
|
}
|
|
102
|
-
_create_class(
|
|
102
|
+
_create_class(StructuredResponseParser, [
|
|
103
103
|
{
|
|
104
104
|
key: "parse",
|
|
105
105
|
value: /**
|
|
@@ -112,7 +112,7 @@ import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
|
112
112
|
return this.schema.parse(unescapedJson);
|
|
113
113
|
} catch (error) {
|
|
114
114
|
if (_instanceof(error, z.ZodError)) {
|
|
115
|
-
throw new
|
|
115
|
+
throw new StructuredResponseParserError('Failed to validate response against schema', error, text);
|
|
116
116
|
}
|
|
117
117
|
throw error;
|
|
118
118
|
}
|
|
@@ -174,14 +174,14 @@ import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
|
174
174
|
var arrayStart = text.indexOf('[');
|
|
175
175
|
var arrayEnd = text.lastIndexOf(']');
|
|
176
176
|
if (arrayStart === -1 || arrayEnd === -1) {
|
|
177
|
-
throw new
|
|
177
|
+
throw new StructuredResponseParserError('No array found in response', undefined, text);
|
|
178
178
|
}
|
|
179
179
|
try {
|
|
180
180
|
var raw = text.slice(arrayStart, arrayEnd + 1);
|
|
181
181
|
var repaired = this.repairJson(raw);
|
|
182
182
|
return JSON.parse(repaired);
|
|
183
183
|
} catch (error) {
|
|
184
|
-
throw new
|
|
184
|
+
throw new StructuredResponseParserError('Failed to parse array JSON', error, text);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
},
|
|
@@ -214,7 +214,7 @@ import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
|
214
214
|
if (_instanceof(this.schema, z.ZodString) || _instanceof(this.schema, z.ZodNumber) || _instanceof(this.schema, z.ZodBoolean) || _instanceof(this.schema, z.ZodNull)) {
|
|
215
215
|
return this.extractPrimitive(text, this.schema);
|
|
216
216
|
}
|
|
217
|
-
throw new
|
|
217
|
+
throw new StructuredResponseParserError('Unsupported schema type', undefined, text);
|
|
218
218
|
}
|
|
219
219
|
},
|
|
220
220
|
{
|
|
@@ -225,14 +225,14 @@ import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
|
225
225
|
var objectStart = text.indexOf('{');
|
|
226
226
|
var objectEnd = text.lastIndexOf('}');
|
|
227
227
|
if (objectStart === -1 || objectEnd === -1) {
|
|
228
|
-
throw new
|
|
228
|
+
throw new StructuredResponseParserError('No object found in response', undefined, text);
|
|
229
229
|
}
|
|
230
230
|
try {
|
|
231
231
|
var raw = text.slice(objectStart, objectEnd + 1);
|
|
232
232
|
var repaired = this.repairJson(raw);
|
|
233
233
|
return JSON.parse(repaired);
|
|
234
234
|
} catch (error) {
|
|
235
|
-
throw new
|
|
235
|
+
throw new StructuredResponseParserError('Failed to parse object JSON', error, text);
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
},
|
|
@@ -341,7 +341,7 @@ import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
]);
|
|
344
|
-
return
|
|
344
|
+
return StructuredResponseParser;
|
|
345
345
|
}();
|
|
346
346
|
|
|
347
|
-
//# sourceMappingURL=
|
|
347
|
+
//# sourceMappingURL=structured-response-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/utils/structured-response-parser.ts"],"sourcesContent":["import { jsonrepair } from 'jsonrepair';\nimport { z } from 'zod/v4';\n\nimport { StructuredResponseParserError } from './structured-response-parser-error.js';\n\n/**\n * Parses AI response text into structured data based on Zod schema\n */\nexport class StructuredResponseParser<T> {\n constructor(private readonly schema: z.ZodSchema<T>) {}\n\n /**\n * Parses the AI response text based on the configured schema\n */\n public parse(text: string): T {\n try {\n const cleanedText = this.cleanText(text);\n const json = this.extractJsonFromText(cleanedText);\n const unescapedJson = this.unescapeJsonValues(json);\n return this.schema.parse(unescapedJson);\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new StructuredResponseParserError(\n 'Failed to validate response against schema',\n error,\n text,\n );\n }\n throw error;\n }\n }\n\n /**\n * Cleans text and finds the largest schema-compatible structure\n */\n private cleanText(text: string): string {\n // First try to extract from markdown code blocks\n const codeBlocks = text.match(/```(?:json)?\\r?\\n([^`]*?)\\r?\\n```/g);\n if (codeBlocks) {\n // Try each code block and return the largest valid one\n const validBlocks = codeBlocks\n .map((block) => this.extractJsonFromCodeBlock(block))\n .filter((block): block is string => block !== null);\n\n if (validBlocks.length > 0) {\n return this.findLargestString(validBlocks);\n }\n }\n\n // If no valid code blocks, try to find JSON-like structures in the text\n const jsonMatches = this.findJsonStructures(text);\n if (jsonMatches.length > 0) {\n return this.findLargestString(jsonMatches);\n }\n\n // If no JSON structures found, clean and return the original text\n return text.replace(/\\s+/g, ' ').trim();\n }\n\n /**\n * Converts value to appropriate primitive type based on schema\n */\n private convertToPrimitive(value: unknown, schema: z.ZodType): unknown {\n if (schema instanceof z.ZodString) {\n return String(value);\n }\n if (schema instanceof z.ZodNumber) {\n return Number(value);\n }\n if (schema instanceof z.ZodBoolean) {\n return Boolean(value);\n }\n if (schema instanceof z.ZodNull) {\n return null;\n }\n return value;\n }\n\n /**\n * Extracts array from text\n */\n private extractArray(text: string): unknown {\n const arrayStart = text.indexOf('[');\n const arrayEnd = text.lastIndexOf(']');\n if (arrayStart === -1 || arrayEnd === -1) {\n throw new StructuredResponseParserError('No array found in response', undefined, text);\n }\n try {\n const raw = text.slice(arrayStart, arrayEnd + 1);\n const repaired = this.repairJson(raw);\n return JSON.parse(repaired);\n } catch (error) {\n throw new StructuredResponseParserError('Failed to parse array JSON', error, text);\n }\n }\n\n /**\n * Extracts and validates JSON content from a code block\n */\n private extractJsonFromCodeBlock(block: string): null | string {\n const content = block.replace(/```(?:json)?\\r?\\n([^`]*?)\\r?\\n```/, '$1').trim();\n try {\n // Attempt to parse as JSON to validate structure\n JSON.parse(content);\n return content;\n } catch {\n return null;\n }\n }\n\n /**\n * Extracts and parses JSON from text based on schema type\n */\n private extractJsonFromText(text: string): unknown {\n if (this.schema instanceof z.ZodArray) {\n return this.extractArray(text);\n }\n\n if (this.schema instanceof z.ZodObject) {\n return this.extractObject(text);\n }\n\n if (\n this.schema instanceof z.ZodString ||\n this.schema instanceof z.ZodNumber ||\n this.schema instanceof z.ZodBoolean ||\n this.schema instanceof z.ZodNull\n ) {\n return this.extractPrimitive(text, this.schema);\n }\n\n throw new StructuredResponseParserError('Unsupported schema type', undefined, text);\n }\n\n /**\n * Extracts object from text\n */\n private extractObject(text: string): unknown {\n const objectStart = text.indexOf('{');\n const objectEnd = text.lastIndexOf('}');\n if (objectStart === -1 || objectEnd === -1) {\n throw new StructuredResponseParserError('No object found in response', undefined, text);\n }\n try {\n const raw = text.slice(objectStart, objectEnd + 1);\n const repaired = this.repairJson(raw);\n return JSON.parse(repaired);\n } catch (error) {\n throw new StructuredResponseParserError('Failed to parse object JSON', error, text);\n }\n }\n\n /**\n * Extracts and converts primitive value from text\n */\n private extractPrimitive(text: string, schema: z.ZodType): unknown {\n const trimmed = text.trim();\n\n // Try to parse as JSON first in case it's quoted\n try {\n const parsed = JSON.parse(trimmed);\n return this.convertToPrimitive(parsed, schema);\n } catch {\n // If not valid JSON, use the raw string\n return this.convertToPrimitive(trimmed, schema);\n }\n }\n\n /**\n * Finds valid JSON structures in raw text\n */\n private findJsonStructures(text: string): string[] {\n const jsonMatches: string[] = [];\n let depth = 0;\n let start = -1;\n\n for (let i = 0; i < text.length; i++) {\n const char = text[i];\n if (char === '{' || char === '[') {\n if (depth === 0) start = i;\n depth++;\n } else if (char === '}' || char === ']') {\n depth--;\n if (depth === 0 && start !== -1) {\n const potentialJson = text.slice(start, i + 1);\n try {\n JSON.parse(potentialJson);\n jsonMatches.push(potentialJson);\n } catch {\n // Invalid JSON, ignore\n }\n }\n }\n }\n\n return jsonMatches;\n }\n\n /**\n * Returns the largest string from an array of strings\n */\n private findLargestString(strings: string[]): string {\n return strings.reduce(\n (largest, current) => (current.length > largest.length ? current : largest),\n strings[0],\n );\n }\n\n /**\n * Repairs common JSON issues using jsonrepair library\n */\n private repairJson(jsonString: string): string {\n return jsonrepair(jsonString);\n }\n\n /**\n * Recursively unescapes all string values in a JSON object/array\n */\n private unescapeJsonValues(json: unknown): unknown {\n if (typeof json === 'string') {\n return this.unescapeText(json);\n }\n if (Array.isArray(json)) {\n return json.map((item) => this.unescapeJsonValues(item));\n }\n if (typeof json === 'object' && json !== null) {\n return Object.fromEntries(\n Object.entries(json).map(([key, value]) => [key, this.unescapeJsonValues(value)]),\n );\n }\n return json;\n }\n\n /**\n * Unescapes common escaped characters in text\n */\n private unescapeText(text: string): string {\n return text\n .replace(/\\\\\"/g, '\"') // Unescape quotes\n .replace(/\\\\n/g, '\\n') // Unescape newlines\n .replace(/\\\\r/g, '\\r') // Unescape carriage returns\n .replace(/\\\\t/g, '\\t') // Unescape tabs\n .replace(/\\\\\\\\/g, '\\\\') // Unescape backslashes\n .replace(/\\\\u([0-9a-fA-F]{4})/g, (_, code) => String.fromCharCode(parseInt(code, 16))); // Unescape unicode\n }\n}\n"],"names":["jsonrepair","z","StructuredResponseParserError","StructuredResponseParser","schema","parse","text","cleanedText","cleanText","json","extractJsonFromText","unescapedJson","unescapeJsonValues","error","ZodError","codeBlocks","match","validBlocks","map","block","extractJsonFromCodeBlock","filter","length","findLargestString","jsonMatches","findJsonStructures","replace","trim","convertToPrimitive","value","ZodString","String","ZodNumber","Number","ZodBoolean","Boolean","ZodNull","extractArray","arrayStart","indexOf","arrayEnd","lastIndexOf","undefined","raw","slice","repaired","repairJson","JSON","content","ZodArray","ZodObject","extractObject","extractPrimitive","objectStart","objectEnd","trimmed","parsed","depth","start","i","char","potentialJson","push","strings","reduce","largest","current","jsonString","unescapeText","Array","isArray","item","Object","fromEntries","entries","key","_","code","fromCharCode","parseInt"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,UAAU,QAAQ,aAAa;AACxC,SAASC,CAAC,QAAQ,SAAS;AAE3B,SAASC,6BAA6B,QAAQ,wCAAwC;AAEtF;;CAEC,GACD,OAAO,IAAA,AAAMC,yCAAN;;aAAMA,yBACG,AAAiBC,MAAsB;gCAD1CD;;aACoBC,SAAAA;;kBADpBD;;YAMFE,KAAAA;mBAAP,AAHA;;KAEC,GACD,SAAOA,MAAMC,IAAY;gBACrB,IAAI;oBACA,IAAMC,cAAc,IAAI,CAACC,SAAS,CAACF;oBACnC,IAAMG,OAAO,IAAI,CAACC,mBAAmB,CAACH;oBACtC,IAAMI,gBAAgB,IAAI,CAACC,kBAAkB,CAACH;oBAC9C,OAAO,IAAI,CAACL,MAAM,CAACC,KAAK,CAACM;gBAC7B,EAAE,OAAOE,OAAO;oBACZ,IAAIA,AAAK,YAALA,OAAiBZ,EAAEa,QAAQ,GAAE;wBAC7B,MAAM,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