@jterrazz/intelligence 1.6.1 → 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 +69 -165
- package/dist/index.cjs +649 -1625
- package/dist/index.d.ts +5 -12
- package/dist/index.js +5 -12
- 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 +15 -14
- package/dist/adapters/agents/autonomous-agent.adapter.d.ts +0 -30
- package/dist/adapters/agents/autonomous-agent.adapter.js +0 -400
- package/dist/adapters/agents/autonomous-agent.adapter.js.map +0 -1
- package/dist/adapters/agents/basic-agent.adapter.d.ts +0 -27
- package/dist/adapters/agents/basic-agent.adapter.js +0 -339
- package/dist/adapters/agents/basic-agent.adapter.js.map +0 -1
- package/dist/adapters/agents/retryable-agent.adapter.d.ts +0 -20
- package/dist/adapters/agents/retryable-agent.adapter.js +0 -263
- package/dist/adapters/agents/retryable-agent.adapter.js.map +0 -1
- package/dist/adapters/models/openrouter-model.adapter.d.ts +0 -38
- package/dist/adapters/models/openrouter-model.adapter.js +0 -89
- 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/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__/ai-response-parser.test.js +0 -289
- package/dist/adapters/utils/__tests__/ai-response-parser.test.js.map +0 -1
- package/dist/adapters/utils/ai-response-parser-error.d.ts +0 -8
- package/dist/adapters/utils/ai-response-parser-error.js +0 -136
- package/dist/adapters/utils/ai-response-parser-error.js.map +0 -1
- package/dist/adapters/utils/ai-response-parser.d.ts +0 -60
- package/dist/adapters/utils/ai-response-parser.js +0 -347
- package/dist/adapters/utils/ai-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 -10
- 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/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__/ai-response-parser.test.d.ts → parsing/__tests__/create-schema-prompt.test.d.ts} +0 -0
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom error for AI 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 AIResponseParserError = /*#__PURE__*/ function(Error1) {
|
|
122
|
-
"use strict";
|
|
123
|
-
_inherits(AIResponseParserError, Error1);
|
|
124
|
-
function AIResponseParserError(message, cause, text) {
|
|
125
|
-
_class_call_check(this, AIResponseParserError);
|
|
126
|
-
var _this;
|
|
127
|
-
_this = _call_super(this, AIResponseParserError, [
|
|
128
|
-
message
|
|
129
|
-
]), _define_property(_this, "cause", void 0), _define_property(_this, "text", void 0), _this.cause = cause, _this.text = text;
|
|
130
|
-
_this.name = 'AIResponseParserError';
|
|
131
|
-
return _this;
|
|
132
|
-
}
|
|
133
|
-
return AIResponseParserError;
|
|
134
|
-
}(_wrap_native_super(Error));
|
|
135
|
-
|
|
136
|
-
//# sourceMappingURL=ai-response-parser-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/utils/ai-response-parser-error.ts"],"sourcesContent":["/**\n * Custom error for AI response parsing failures\n */\nexport class AIResponseParserError extends Error {\n constructor(\n message: string,\n public readonly cause?: unknown,\n public readonly text?: string,\n ) {\n super(message);\n this.name = 'AIResponseParserError';\n }\n}\n"],"names":["AIResponseParserError","message","cause","text","name","Error"],"mappings":"AAAA;;CAEC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACD,OAAO,IAAA,AAAMA,sCAAN;;cAAMA;aAAAA,sBAELC,OAAe,EACf,AAAgBC,KAAe,EAC/B,AAAgBC,IAAa;gCAJxBH;;gBAML,kBANKA;YAMCC;qGAHUC,QAAAA,aACAC,OAAAA;QAGhB,MAAKC,IAAI,GAAG;;;WAPPJ;qBAA8BK,QAS1C"}
|
|
@@ -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 AIResponseParser<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
|
-
}
|
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
function _array_like_to_array(arr, len) {
|
|
2
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
-
return arr2;
|
|
5
|
-
}
|
|
6
|
-
function _array_with_holes(arr) {
|
|
7
|
-
if (Array.isArray(arr)) return arr;
|
|
8
|
-
}
|
|
9
|
-
function _class_call_check(instance, Constructor) {
|
|
10
|
-
if (!(instance instanceof Constructor)) {
|
|
11
|
-
throw new TypeError("Cannot call a class as a function");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function _defineProperties(target, props) {
|
|
15
|
-
for(var i = 0; i < props.length; i++){
|
|
16
|
-
var descriptor = props[i];
|
|
17
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
18
|
-
descriptor.configurable = true;
|
|
19
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
20
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
24
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
25
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
26
|
-
return Constructor;
|
|
27
|
-
}
|
|
28
|
-
function _define_property(obj, key, value) {
|
|
29
|
-
if (key in obj) {
|
|
30
|
-
Object.defineProperty(obj, key, {
|
|
31
|
-
value: value,
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true
|
|
35
|
-
});
|
|
36
|
-
} else {
|
|
37
|
-
obj[key] = value;
|
|
38
|
-
}
|
|
39
|
-
return obj;
|
|
40
|
-
}
|
|
41
|
-
function _instanceof(left, right) {
|
|
42
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
43
|
-
return !!right[Symbol.hasInstance](left);
|
|
44
|
-
} else {
|
|
45
|
-
return left instanceof right;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function _iterable_to_array_limit(arr, i) {
|
|
49
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
50
|
-
if (_i == null) return;
|
|
51
|
-
var _arr = [];
|
|
52
|
-
var _n = true;
|
|
53
|
-
var _d = false;
|
|
54
|
-
var _s, _e;
|
|
55
|
-
try {
|
|
56
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
57
|
-
_arr.push(_s.value);
|
|
58
|
-
if (i && _arr.length === i) break;
|
|
59
|
-
}
|
|
60
|
-
} catch (err) {
|
|
61
|
-
_d = true;
|
|
62
|
-
_e = err;
|
|
63
|
-
} finally{
|
|
64
|
-
try {
|
|
65
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
66
|
-
} finally{
|
|
67
|
-
if (_d) throw _e;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return _arr;
|
|
71
|
-
}
|
|
72
|
-
function _non_iterable_rest() {
|
|
73
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
74
|
-
}
|
|
75
|
-
function _sliced_to_array(arr, i) {
|
|
76
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
77
|
-
}
|
|
78
|
-
function _type_of(obj) {
|
|
79
|
-
"@swc/helpers - typeof";
|
|
80
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
81
|
-
}
|
|
82
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
83
|
-
if (!o) return;
|
|
84
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
85
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
86
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
87
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
88
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
89
|
-
}
|
|
90
|
-
import { jsonrepair } from 'jsonrepair';
|
|
91
|
-
import { z } from 'zod/v4';
|
|
92
|
-
import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
93
|
-
/**
|
|
94
|
-
* Parses AI response text into structured data based on Zod schema
|
|
95
|
-
*/ export var AIResponseParser = /*#__PURE__*/ function() {
|
|
96
|
-
"use strict";
|
|
97
|
-
function AIResponseParser(schema) {
|
|
98
|
-
_class_call_check(this, AIResponseParser);
|
|
99
|
-
_define_property(this, "schema", void 0);
|
|
100
|
-
this.schema = schema;
|
|
101
|
-
}
|
|
102
|
-
_create_class(AIResponseParser, [
|
|
103
|
-
{
|
|
104
|
-
key: "parse",
|
|
105
|
-
value: /**
|
|
106
|
-
* Parses the AI response text based on the configured schema
|
|
107
|
-
*/ function parse(text) {
|
|
108
|
-
try {
|
|
109
|
-
var cleanedText = this.cleanText(text);
|
|
110
|
-
var json = this.extractJsonFromText(cleanedText);
|
|
111
|
-
var unescapedJson = this.unescapeJsonValues(json);
|
|
112
|
-
return this.schema.parse(unescapedJson);
|
|
113
|
-
} catch (error) {
|
|
114
|
-
if (_instanceof(error, z.ZodError)) {
|
|
115
|
-
throw new AIResponseParserError('Failed to validate response against schema', error, text);
|
|
116
|
-
}
|
|
117
|
-
throw error;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
key: "cleanText",
|
|
123
|
-
value: /**
|
|
124
|
-
* Cleans text and finds the largest schema-compatible structure
|
|
125
|
-
*/ function cleanText(text) {
|
|
126
|
-
var _this = this;
|
|
127
|
-
// First try to extract from markdown code blocks
|
|
128
|
-
var codeBlocks = text.match(/```(?:json)?\r?\n([^`]*?)\r?\n```/g);
|
|
129
|
-
if (codeBlocks) {
|
|
130
|
-
// Try each code block and return the largest valid one
|
|
131
|
-
var validBlocks = codeBlocks.map(function(block) {
|
|
132
|
-
return _this.extractJsonFromCodeBlock(block);
|
|
133
|
-
}).filter(function(block) {
|
|
134
|
-
return block !== null;
|
|
135
|
-
});
|
|
136
|
-
if (validBlocks.length > 0) {
|
|
137
|
-
return this.findLargestString(validBlocks);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// If no valid code blocks, try to find JSON-like structures in the text
|
|
141
|
-
var jsonMatches = this.findJsonStructures(text);
|
|
142
|
-
if (jsonMatches.length > 0) {
|
|
143
|
-
return this.findLargestString(jsonMatches);
|
|
144
|
-
}
|
|
145
|
-
// If no JSON structures found, clean and return the original text
|
|
146
|
-
return text.replace(/\s+/g, ' ').trim();
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
key: "convertToPrimitive",
|
|
151
|
-
value: /**
|
|
152
|
-
* Converts value to appropriate primitive type based on schema
|
|
153
|
-
*/ function convertToPrimitive(value, schema) {
|
|
154
|
-
if (_instanceof(schema, z.ZodString)) {
|
|
155
|
-
return String(value);
|
|
156
|
-
}
|
|
157
|
-
if (_instanceof(schema, z.ZodNumber)) {
|
|
158
|
-
return Number(value);
|
|
159
|
-
}
|
|
160
|
-
if (_instanceof(schema, z.ZodBoolean)) {
|
|
161
|
-
return Boolean(value);
|
|
162
|
-
}
|
|
163
|
-
if (_instanceof(schema, z.ZodNull)) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
return value;
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
key: "extractArray",
|
|
171
|
-
value: /**
|
|
172
|
-
* Extracts array from text
|
|
173
|
-
*/ function extractArray(text) {
|
|
174
|
-
var arrayStart = text.indexOf('[');
|
|
175
|
-
var arrayEnd = text.lastIndexOf(']');
|
|
176
|
-
if (arrayStart === -1 || arrayEnd === -1) {
|
|
177
|
-
throw new AIResponseParserError('No array found in response', undefined, text);
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
var raw = text.slice(arrayStart, arrayEnd + 1);
|
|
181
|
-
var repaired = this.repairJson(raw);
|
|
182
|
-
return JSON.parse(repaired);
|
|
183
|
-
} catch (error) {
|
|
184
|
-
throw new AIResponseParserError('Failed to parse array JSON', error, text);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
key: "extractJsonFromCodeBlock",
|
|
190
|
-
value: /**
|
|
191
|
-
* Extracts and validates JSON content from a code block
|
|
192
|
-
*/ function extractJsonFromCodeBlock(block) {
|
|
193
|
-
var content = block.replace(/```(?:json)?\r?\n([^`]*?)\r?\n```/, '$1').trim();
|
|
194
|
-
try {
|
|
195
|
-
// Attempt to parse as JSON to validate structure
|
|
196
|
-
JSON.parse(content);
|
|
197
|
-
return content;
|
|
198
|
-
} catch (e) {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
key: "extractJsonFromText",
|
|
205
|
-
value: /**
|
|
206
|
-
* Extracts and parses JSON from text based on schema type
|
|
207
|
-
*/ function extractJsonFromText(text) {
|
|
208
|
-
if (_instanceof(this.schema, z.ZodArray)) {
|
|
209
|
-
return this.extractArray(text);
|
|
210
|
-
}
|
|
211
|
-
if (_instanceof(this.schema, z.ZodObject)) {
|
|
212
|
-
return this.extractObject(text);
|
|
213
|
-
}
|
|
214
|
-
if (_instanceof(this.schema, z.ZodString) || _instanceof(this.schema, z.ZodNumber) || _instanceof(this.schema, z.ZodBoolean) || _instanceof(this.schema, z.ZodNull)) {
|
|
215
|
-
return this.extractPrimitive(text, this.schema);
|
|
216
|
-
}
|
|
217
|
-
throw new AIResponseParserError('Unsupported schema type', undefined, text);
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
key: "extractObject",
|
|
222
|
-
value: /**
|
|
223
|
-
* Extracts object from text
|
|
224
|
-
*/ function extractObject(text) {
|
|
225
|
-
var objectStart = text.indexOf('{');
|
|
226
|
-
var objectEnd = text.lastIndexOf('}');
|
|
227
|
-
if (objectStart === -1 || objectEnd === -1) {
|
|
228
|
-
throw new AIResponseParserError('No object found in response', undefined, text);
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
var raw = text.slice(objectStart, objectEnd + 1);
|
|
232
|
-
var repaired = this.repairJson(raw);
|
|
233
|
-
return JSON.parse(repaired);
|
|
234
|
-
} catch (error) {
|
|
235
|
-
throw new AIResponseParserError('Failed to parse object JSON', error, text);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
key: "extractPrimitive",
|
|
241
|
-
value: /**
|
|
242
|
-
* Extracts and converts primitive value from text
|
|
243
|
-
*/ function extractPrimitive(text, schema) {
|
|
244
|
-
var trimmed = text.trim();
|
|
245
|
-
// Try to parse as JSON first in case it's quoted
|
|
246
|
-
try {
|
|
247
|
-
var parsed = JSON.parse(trimmed);
|
|
248
|
-
return this.convertToPrimitive(parsed, schema);
|
|
249
|
-
} catch (e) {
|
|
250
|
-
// If not valid JSON, use the raw string
|
|
251
|
-
return this.convertToPrimitive(trimmed, schema);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
key: "findJsonStructures",
|
|
257
|
-
value: /**
|
|
258
|
-
* Finds valid JSON structures in raw text
|
|
259
|
-
*/ function findJsonStructures(text) {
|
|
260
|
-
var jsonMatches = [];
|
|
261
|
-
var depth = 0;
|
|
262
|
-
var start = -1;
|
|
263
|
-
for(var i = 0; i < text.length; i++){
|
|
264
|
-
var char = text[i];
|
|
265
|
-
if (char === '{' || char === '[') {
|
|
266
|
-
if (depth === 0) start = i;
|
|
267
|
-
depth++;
|
|
268
|
-
} else if (char === '}' || char === ']') {
|
|
269
|
-
depth--;
|
|
270
|
-
if (depth === 0 && start !== -1) {
|
|
271
|
-
var potentialJson = text.slice(start, i + 1);
|
|
272
|
-
try {
|
|
273
|
-
JSON.parse(potentialJson);
|
|
274
|
-
jsonMatches.push(potentialJson);
|
|
275
|
-
} catch (e) {
|
|
276
|
-
// Invalid JSON, ignore
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return jsonMatches;
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
key: "findLargestString",
|
|
286
|
-
value: /**
|
|
287
|
-
* Returns the largest string from an array of strings
|
|
288
|
-
*/ function findLargestString(strings) {
|
|
289
|
-
return strings.reduce(function(largest, current) {
|
|
290
|
-
return current.length > largest.length ? current : largest;
|
|
291
|
-
}, strings[0]);
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
key: "repairJson",
|
|
296
|
-
value: /**
|
|
297
|
-
* Repairs common JSON issues using jsonrepair library
|
|
298
|
-
*/ function repairJson(jsonString) {
|
|
299
|
-
return jsonrepair(jsonString);
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
key: "unescapeJsonValues",
|
|
304
|
-
value: /**
|
|
305
|
-
* Recursively unescapes all string values in a JSON object/array
|
|
306
|
-
*/ function unescapeJsonValues(json) {
|
|
307
|
-
var _this = this;
|
|
308
|
-
if (typeof json === 'string') {
|
|
309
|
-
return this.unescapeText(json);
|
|
310
|
-
}
|
|
311
|
-
if (Array.isArray(json)) {
|
|
312
|
-
return json.map(function(item) {
|
|
313
|
-
return _this.unescapeJsonValues(item);
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
if ((typeof json === "undefined" ? "undefined" : _type_of(json)) === 'object' && json !== null) {
|
|
317
|
-
return Object.fromEntries(Object.entries(json).map(function(param) {
|
|
318
|
-
var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
319
|
-
return [
|
|
320
|
-
key,
|
|
321
|
-
_this.unescapeJsonValues(value)
|
|
322
|
-
];
|
|
323
|
-
}));
|
|
324
|
-
}
|
|
325
|
-
return json;
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
key: "unescapeText",
|
|
330
|
-
value: /**
|
|
331
|
-
* Unescapes common escaped characters in text
|
|
332
|
-
*/ function unescapeText(text) {
|
|
333
|
-
return text.replace(/\\"/g, '"') // Unescape quotes
|
|
334
|
-
.replace(/\\n/g, '\n') // Unescape newlines
|
|
335
|
-
.replace(/\\r/g, '\r') // Unescape carriage returns
|
|
336
|
-
.replace(/\\t/g, '\t') // Unescape tabs
|
|
337
|
-
.replace(/\\\\/g, '\\') // Unescape backslashes
|
|
338
|
-
.replace(/\\u([0-9a-fA-F]{4})/g, function(_, code) {
|
|
339
|
-
return String.fromCharCode(parseInt(code, 16));
|
|
340
|
-
}); // Unescape unicode
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
]);
|
|
344
|
-
return AIResponseParser;
|
|
345
|
-
}();
|
|
346
|
-
|
|
347
|
-
//# sourceMappingURL=ai-response-parser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/utils/ai-response-parser.ts"],"sourcesContent":["import { jsonrepair } from 'jsonrepair';\nimport { z } from 'zod/v4';\n\nimport { AIResponseParserError } from './ai-response-parser-error.js';\n\n/**\n * Parses AI response text into structured data based on Zod schema\n */\nexport class AIResponseParser<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 AIResponseParserError(\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 AIResponseParserError('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 AIResponseParserError('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 AIResponseParserError('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 AIResponseParserError('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 AIResponseParserError('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","AIResponseParserError","AIResponseParser","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,qBAAqB,QAAQ,gCAAgC;AAEtE;;CAEC,GACD,OAAO,IAAA,AAAMC,iCAAN;;aAAMA,iBACG,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,IA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S,GAAG,CAAC;iEAAEyD,iBAAK9C;+BAAW;4BAAC8C;4BAAK,MAAK/D,kBAAkB,CAACiB;yBAAO;;gBAExF;gBACA,OAAOpB;YACX;;;YAKQ2D,KAAAA;mBAAR,AAHA;;KAEC,GACD,SAAQA,aAAa9D,IAAY;gBAC7B,OAAOA,KACFoB,OAAO,CAAC,QAAQ,KAAK,kBAAkB;iBACvCA,OAAO,CAAC,QAAQ,MAAM,oBAAoB;iBAC1CA,OAAO,CAAC,QAAQ,MAAM,4BAA4B;iBAClDA,OAAO,CAAC,QAAQ,MAAM,gBAAgB;iBACtCA,OAAO,CAAC,SAAS,MAAM,uBAAuB;iBAC9CA,OAAO,CAAC,wBAAwB,SAACkD,GAAGC;2BAAS9C,OAAO+C,YAAY,CAACC,SAASF,MAAM;oBAAO,mBAAmB;YACnH;;;WA5OS1E;IA6OZ"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { PromptPort } from './prompt.port.js';
|
|
2
|
-
/**
|
|
3
|
-
* Port for chat agents with generic input and output types
|
|
4
|
-
* @template TInput - The type of input parameters the agent accepts
|
|
5
|
-
* @template TOutput - The type of output the agent returns
|
|
6
|
-
*/
|
|
7
|
-
export interface AgentPort<TInput = PromptPort, TOutput = string> {
|
|
8
|
-
/**
|
|
9
|
-
* A descriptive name for the agent, used for logging and identification.
|
|
10
|
-
*/
|
|
11
|
-
readonly name: string;
|
|
12
|
-
/**
|
|
13
|
-
* Run the agent with optional input and return optional response
|
|
14
|
-
* @param input - The input to process
|
|
15
|
-
*/
|
|
16
|
-
run(input?: TInput): Promise<null | TOutput>;
|
|
17
|
-
}
|
package/dist/ports/agent.port.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ports/agent.port.ts"],"sourcesContent":["import type { PromptPort } from './prompt.port.js';\n\n/**\n * Port for chat agents with generic input and output types\n * @template TInput - The type of input parameters the agent accepts\n * @template TOutput - The type of output the agent returns\n */\nexport interface AgentPort<TInput = PromptPort, TOutput = string> {\n /**\n * A descriptive name for the agent, used for logging and identification.\n */\n readonly name: string;\n\n /**\n * Run the agent with optional input and return optional response\n * @param input - The input to process\n */\n run(input?: TInput): Promise<null | TOutput>;\n}\n"],"names":[],"mappings":"AAEA;;;;CAIC,GACD,WAWC"}
|
package/dist/ports/model.port.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ports/model.port.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\n\n/**\n * Port for models\n */\nexport interface ModelPort {\n /**\n * Get the configured language model instance\n */\n getModel(): BaseLanguageModel;\n}\n"],"names":[],"mappings":"AAEA;;CAEC,GACD,WAKC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ports/prompt.port.ts"],"sourcesContent":["/**\n * Port for prompt generation\n */\nexport interface PromptPort {\n /**\n * Generate the prompt text\n */\n generate(): string;\n}\n"],"names":[],"mappings":"AAAA;;CAEC,GACD,WAKC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { DynamicStructuredTool, DynamicTool } from 'langchain/tools';
|
|
2
|
-
import type { z } from 'zod/v4';
|
|
3
|
-
/**
|
|
4
|
-
* Port for tools
|
|
5
|
-
*/
|
|
6
|
-
export interface ToolPort {
|
|
7
|
-
/**
|
|
8
|
-
* Get the underlying LangChain tool instance
|
|
9
|
-
*/
|
|
10
|
-
getDynamicTool(): DynamicStructuredTool<z.ZodSchema<unknown>> | DynamicTool;
|
|
11
|
-
}
|