@aigne/core 1.60.1 → 1.60.3
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/CHANGELOG.md +15 -0
- package/lib/cjs/agents/image-model.d.ts +1 -0
- package/lib/cjs/agents/image-model.js +15 -0
- package/lib/cjs/agents/mcp-agent.js +1 -1
- package/lib/cjs/utils/json-schema.js +40 -1
- package/lib/dts/agents/image-model.d.ts +1 -0
- package/lib/esm/agents/image-model.d.ts +1 -0
- package/lib/esm/agents/image-model.js +15 -0
- package/lib/esm/agents/mcp-agent.js +1 -1
- package/lib/esm/utils/json-schema.js +40 -1
- package/package.json +18 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.60.3](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.60.2...core-v1.60.3) (2025-09-18)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **models:** convert local image to base64 for image model ([#517](https://github.com/AIGNE-io/aigne-framework/issues/517)) ([c0bc971](https://github.com/AIGNE-io/aigne-framework/commit/c0bc971087ef6e1caa641a699aed391a24feb40d))
|
|
9
|
+
* **models:** convert local image to base64 for image model ([#517](https://github.com/AIGNE-io/aigne-framework/issues/517)) ([c0bc971](https://github.com/AIGNE-io/aigne-framework/commit/c0bc971087ef6e1caa641a699aed391a24feb40d))
|
|
10
|
+
|
|
11
|
+
## [1.60.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.60.1...core-v1.60.2) (2025-09-11)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **core:** add nullish or nullable support for output schema ([#482](https://github.com/AIGNE-io/aigne-framework/issues/482)) ([bf80c29](https://github.com/AIGNE-io/aigne-framework/commit/bf80c29e10d3fef654c830df8dc7f3b7939fa58d))
|
|
17
|
+
|
|
3
18
|
## [1.60.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.60.0...core-v1.60.1) (2025-09-11)
|
|
4
19
|
|
|
5
20
|
|
|
@@ -15,6 +15,7 @@ export declare abstract class ImageModel<I extends ImageModelInput = ImageModelI
|
|
|
15
15
|
protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
|
|
16
16
|
protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
|
|
17
17
|
abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
18
|
+
protected downloadFile(url: string, timeout?: number): Promise<Response>;
|
|
18
19
|
}
|
|
19
20
|
export interface ImageModelInput extends Message {
|
|
20
21
|
model?: string;
|
|
@@ -34,6 +34,21 @@ class ImageModel extends agent_js_1.Agent {
|
|
|
34
34
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
async downloadFile(url, timeout = 30000) {
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
40
|
+
try {
|
|
41
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
const text = await response.text().catch(() => null);
|
|
44
|
+
throw new Error(`Failed to download content from ${url}, ${response.status} ${response.statusText} ${text}`);
|
|
45
|
+
}
|
|
46
|
+
return response;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
clearTimeout(timeoutId);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
37
52
|
}
|
|
38
53
|
exports.ImageModel = ImageModel;
|
|
39
54
|
exports.imageModelInputSchema = zod_1.z.object({
|
|
@@ -239,7 +239,7 @@ class ClientWithReconnect extends index_js_2.Client {
|
|
|
239
239
|
super(info, options);
|
|
240
240
|
this.reconnectOptions = reconnectOptions;
|
|
241
241
|
}
|
|
242
|
-
shouldReconnect(error) {
|
|
242
|
+
shouldReconnect({ error }) {
|
|
243
243
|
const { transportCreator, shouldReconnect, maxReconnects } = this.reconnectOptions || {};
|
|
244
244
|
if (!transportCreator || maxReconnects === 0)
|
|
245
245
|
return false;
|
|
@@ -6,8 +6,9 @@ exports.ensureZodUnionArray = ensureZodUnionArray;
|
|
|
6
6
|
exports.isZodSchema = isZodSchema;
|
|
7
7
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
8
8
|
const logger_js_1 = require("./logger.js");
|
|
9
|
+
const type_utils_js_1 = require("./type-utils.js");
|
|
9
10
|
function outputSchemaToResponseFormatSchema(agentOutput) {
|
|
10
|
-
return setAdditionPropertiesDeep((0, zod_to_json_schema_1.zodToJsonSchema)(agentOutput), false);
|
|
11
|
+
return convertNullableToOptional(setAdditionPropertiesDeep((0, zod_to_json_schema_1.zodToJsonSchema)(agentOutput), false))[0];
|
|
11
12
|
}
|
|
12
13
|
function setAdditionPropertiesDeep(schema, additionalProperties) {
|
|
13
14
|
if (Array.isArray(schema)) {
|
|
@@ -51,3 +52,41 @@ function isZodSchema(schema) {
|
|
|
51
52
|
return false;
|
|
52
53
|
return typeof schema.parse === "function" && typeof schema.safeParse === "function";
|
|
53
54
|
}
|
|
55
|
+
function convertNullableToOptional(schema) {
|
|
56
|
+
if (!(0, type_utils_js_1.isRecord)(schema))
|
|
57
|
+
return [schema, false];
|
|
58
|
+
if (schema.type === "object" && "properties" in schema && (0, type_utils_js_1.isRecord)(schema.properties)) {
|
|
59
|
+
const optionalProperties = [];
|
|
60
|
+
const properties = Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => {
|
|
61
|
+
const [property, optional] = convertNullableToOptional(value);
|
|
62
|
+
if (optional)
|
|
63
|
+
optionalProperties.push(key);
|
|
64
|
+
return [key, property];
|
|
65
|
+
}));
|
|
66
|
+
const currentRequired = "required" in schema && Array.isArray(schema.required) ? schema.required : [];
|
|
67
|
+
const required = currentRequired.filter((key) => !optionalProperties.includes(key));
|
|
68
|
+
return [{ ...schema, properties, required }, false];
|
|
69
|
+
}
|
|
70
|
+
if (schema.type === "array" && "items" in schema && (0, type_utils_js_1.isRecord)(schema.items)) {
|
|
71
|
+
const [items, _] = convertNullableToOptional(schema.items);
|
|
72
|
+
return [{ ...schema, items }, false];
|
|
73
|
+
}
|
|
74
|
+
if (Array.isArray(schema.type)) {
|
|
75
|
+
if (schema.type.includes("null") && schema.type.length === 2) {
|
|
76
|
+
return [
|
|
77
|
+
{
|
|
78
|
+
...schema,
|
|
79
|
+
type: schema.type.filter((t) => t !== "null")[0],
|
|
80
|
+
},
|
|
81
|
+
true,
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(schema.anyOf)) {
|
|
86
|
+
const anyOf = schema.anyOf.filter((i) => (0, type_utils_js_1.isRecord)(i) && i.type !== "null" && !("not" in i && (0, type_utils_js_1.isEmpty)(i.not)));
|
|
87
|
+
const optional = anyOf.length !== schema.anyOf.length;
|
|
88
|
+
if (anyOf.length === 1)
|
|
89
|
+
return [convertNullableToOptional(anyOf[0])[0], optional];
|
|
90
|
+
}
|
|
91
|
+
return [schema, false];
|
|
92
|
+
}
|
|
@@ -15,6 +15,7 @@ export declare abstract class ImageModel<I extends ImageModelInput = ImageModelI
|
|
|
15
15
|
protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
|
|
16
16
|
protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
|
|
17
17
|
abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
18
|
+
protected downloadFile(url: string, timeout?: number): Promise<Response>;
|
|
18
19
|
}
|
|
19
20
|
export interface ImageModelInput extends Message {
|
|
20
21
|
model?: string;
|
|
@@ -15,6 +15,7 @@ export declare abstract class ImageModel<I extends ImageModelInput = ImageModelI
|
|
|
15
15
|
protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
|
|
16
16
|
protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
|
|
17
17
|
abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
18
|
+
protected downloadFile(url: string, timeout?: number): Promise<Response>;
|
|
18
19
|
}
|
|
19
20
|
export interface ImageModelInput extends Message {
|
|
20
21
|
model?: string;
|
|
@@ -31,6 +31,21 @@ export class ImageModel extends Agent {
|
|
|
31
31
|
options.context.usage.aigneHubCredits += usage.aigneHubCredits;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
async downloadFile(url, timeout = 30000) {
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
const text = await response.text().catch(() => null);
|
|
41
|
+
throw new Error(`Failed to download content from ${url}, ${response.status} ${response.statusText} ${text}`);
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
clearTimeout(timeoutId);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
34
49
|
}
|
|
35
50
|
export const imageModelInputSchema = z.object({
|
|
36
51
|
model: z.string().optional(),
|
|
@@ -202,7 +202,7 @@ class ClientWithReconnect extends Client {
|
|
|
202
202
|
super(info, options);
|
|
203
203
|
this.reconnectOptions = reconnectOptions;
|
|
204
204
|
}
|
|
205
|
-
shouldReconnect(error) {
|
|
205
|
+
shouldReconnect({ error }) {
|
|
206
206
|
const { transportCreator, shouldReconnect, maxReconnects } = this.reconnectOptions || {};
|
|
207
207
|
if (!transportCreator || maxReconnects === 0)
|
|
208
208
|
return false;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
2
|
import { logger } from "./logger.js";
|
|
3
|
+
import { isEmpty, isRecord } from "./type-utils.js";
|
|
3
4
|
export function outputSchemaToResponseFormatSchema(agentOutput) {
|
|
4
|
-
return setAdditionPropertiesDeep(zodToJsonSchema(agentOutput), false);
|
|
5
|
+
return convertNullableToOptional(setAdditionPropertiesDeep(zodToJsonSchema(agentOutput), false))[0];
|
|
5
6
|
}
|
|
6
7
|
function setAdditionPropertiesDeep(schema, additionalProperties) {
|
|
7
8
|
if (Array.isArray(schema)) {
|
|
@@ -45,3 +46,41 @@ export function isZodSchema(schema) {
|
|
|
45
46
|
return false;
|
|
46
47
|
return typeof schema.parse === "function" && typeof schema.safeParse === "function";
|
|
47
48
|
}
|
|
49
|
+
function convertNullableToOptional(schema) {
|
|
50
|
+
if (!isRecord(schema))
|
|
51
|
+
return [schema, false];
|
|
52
|
+
if (schema.type === "object" && "properties" in schema && isRecord(schema.properties)) {
|
|
53
|
+
const optionalProperties = [];
|
|
54
|
+
const properties = Object.fromEntries(Object.entries(schema.properties).map(([key, value]) => {
|
|
55
|
+
const [property, optional] = convertNullableToOptional(value);
|
|
56
|
+
if (optional)
|
|
57
|
+
optionalProperties.push(key);
|
|
58
|
+
return [key, property];
|
|
59
|
+
}));
|
|
60
|
+
const currentRequired = "required" in schema && Array.isArray(schema.required) ? schema.required : [];
|
|
61
|
+
const required = currentRequired.filter((key) => !optionalProperties.includes(key));
|
|
62
|
+
return [{ ...schema, properties, required }, false];
|
|
63
|
+
}
|
|
64
|
+
if (schema.type === "array" && "items" in schema && isRecord(schema.items)) {
|
|
65
|
+
const [items, _] = convertNullableToOptional(schema.items);
|
|
66
|
+
return [{ ...schema, items }, false];
|
|
67
|
+
}
|
|
68
|
+
if (Array.isArray(schema.type)) {
|
|
69
|
+
if (schema.type.includes("null") && schema.type.length === 2) {
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
...schema,
|
|
73
|
+
type: schema.type.filter((t) => t !== "null")[0],
|
|
74
|
+
},
|
|
75
|
+
true,
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (Array.isArray(schema.anyOf)) {
|
|
80
|
+
const anyOf = schema.anyOf.filter((i) => isRecord(i) && i.type !== "null" && !("not" in i && isEmpty(i.not)));
|
|
81
|
+
const optional = anyOf.length !== schema.anyOf.length;
|
|
82
|
+
if (anyOf.length === 1)
|
|
83
|
+
return [convertNullableToOptional(anyOf[0])[0], optional];
|
|
84
|
+
}
|
|
85
|
+
return [schema, false];
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "1.60.
|
|
3
|
+
"version": "1.60.3",
|
|
4
4
|
"description": "The functional core of agentic AI",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -66,48 +66,48 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@aigne/json-schema-to-zod": "^1.3.3",
|
|
69
|
-
"@inquirer/prompts": "^7.8.
|
|
70
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
69
|
+
"@inquirer/prompts": "^7.8.6",
|
|
70
|
+
"@modelcontextprotocol/sdk": "^1.18.0",
|
|
71
71
|
"@opentelemetry/api": "^1.9.0",
|
|
72
|
-
"@opentelemetry/sdk-trace-base": "^2.0
|
|
72
|
+
"@opentelemetry/sdk-trace-base": "^2.1.0",
|
|
73
73
|
"@types/debug": "^4.1.12",
|
|
74
74
|
"ajv": "^8.17.1",
|
|
75
75
|
"camelize-ts": "^3.0.0",
|
|
76
76
|
"content-type": "^1.0.5",
|
|
77
|
-
"debug": "^4.4.
|
|
78
|
-
"eventsource-parser": "^3.0.
|
|
77
|
+
"debug": "^4.4.3",
|
|
78
|
+
"eventsource-parser": "^3.0.6",
|
|
79
79
|
"fast-deep-equal": "^3.1.3",
|
|
80
80
|
"fastq": "^1.19.1",
|
|
81
|
-
"immer": "^10.1.
|
|
82
|
-
"is-network-error": "^1.
|
|
81
|
+
"immer": "^10.1.3",
|
|
82
|
+
"is-network-error": "^1.2.0",
|
|
83
83
|
"jaison": "^2.0.2",
|
|
84
|
-
"jsonata": "^2.0
|
|
85
|
-
"mime": "^4.0
|
|
84
|
+
"jsonata": "^2.1.0",
|
|
85
|
+
"mime": "^4.1.0",
|
|
86
86
|
"nunjucks": "^3.2.4",
|
|
87
|
-
"p-retry": "^
|
|
88
|
-
"raw-body": "^3.0.
|
|
87
|
+
"p-retry": "^7.0.0",
|
|
88
|
+
"raw-body": "^3.0.1",
|
|
89
89
|
"strict-event-emitter": "^0.5.1",
|
|
90
90
|
"ufo": "^1.6.1",
|
|
91
|
-
"uuid": "^
|
|
92
|
-
"yaml": "^2.8.
|
|
91
|
+
"uuid": "^13.0.0",
|
|
92
|
+
"yaml": "^2.8.1",
|
|
93
93
|
"zod": "^3.25.67",
|
|
94
94
|
"zod-to-json-schema": "^3.24.6",
|
|
95
95
|
"@aigne/observability-api": "^0.10.4",
|
|
96
96
|
"@aigne/platform-helpers": "^0.6.2"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
-
"@types/bun": "^1.2.
|
|
99
|
+
"@types/bun": "^1.2.22",
|
|
100
100
|
"@types/compression": "^1.8.1",
|
|
101
101
|
"@types/content-type": "^1.1.9",
|
|
102
102
|
"@types/express": "^5.0.3",
|
|
103
|
-
"@types/node": "^24.
|
|
103
|
+
"@types/node": "^24.5.1",
|
|
104
104
|
"@types/nunjucks": "^3.2.6",
|
|
105
|
-
"compression": "^1.8.
|
|
105
|
+
"compression": "^1.8.1",
|
|
106
106
|
"detect-port": "^2.1.0",
|
|
107
107
|
"express": "^5.1.0",
|
|
108
108
|
"npm-run-all": "^4.1.5",
|
|
109
109
|
"rimraf": "^6.0.1",
|
|
110
|
-
"typescript": "^5.
|
|
110
|
+
"typescript": "^5.9.2"
|
|
111
111
|
},
|
|
112
112
|
"scripts": {
|
|
113
113
|
"lint": "tsc --noEmit",
|