@aigne/core 1.65.0 → 1.65.1-beta.1

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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.65.1-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.65.1-beta...core-v1.65.1-beta.1) (2025-11-04)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * add fetch utility with timeout and enhanced error handling ([#694](https://github.com/AIGNE-io/aigne-framework/issues/694)) ([c2d4076](https://github.com/AIGNE-io/aigne-framework/commit/c2d4076ec590150d2751591a4f723721f78381e9))
9
+
10
+ ## [1.65.1-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.65.0...core-v1.65.1-beta) (2025-11-03)
11
+
12
+
13
+ ### Dependencies
14
+
15
+ * The following workspace dependencies were updated
16
+ * dependencies
17
+ * @aigne/observability-api bumped to 0.11.5-beta
18
+
3
19
  ## [1.65.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.65.0-beta.5...core-v1.65.0) (2025-10-31)
4
20
 
5
21
 
@@ -39,6 +39,7 @@ const uuid_1 = require("@aigne/uuid");
39
39
  const ufo_1 = require("ufo");
40
40
  const zod_1 = require("zod");
41
41
  const schema_js_1 = require("../loader/schema.js");
42
+ const fetch_js_1 = require("../utils/fetch.js");
42
43
  const type_utils_js_1 = require("../utils/type-utils.js");
43
44
  const agent_js_1 = require("./agent.js");
44
45
  class Model extends agent_js_1.Agent {
@@ -100,11 +101,7 @@ class Model extends agent_js_1.Agent {
100
101
  return mime.getType(filename) || undefined;
101
102
  }
102
103
  async downloadFile(url) {
103
- const response = await fetch(url);
104
- if (!response.ok) {
105
- const text = await response.text().catch(() => null);
106
- throw new Error(`Failed to download content from ${url}, ${response.status} ${response.statusText} ${text}`);
107
- }
104
+ const response = await (0, fetch_js_1.fetch)(url);
108
105
  return response;
109
106
  }
110
107
  }
@@ -0,0 +1,4 @@
1
+ export declare function fetch(input: RequestInfo, init?: RequestInit & {
2
+ timeout?: number;
3
+ skipResponseCheck?: boolean;
4
+ }): Promise<Response>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetch = fetch;
4
+ const TIMEOUT = (process.env.TIMEOUT && parseInt(process.env.TIMEOUT, 10)) || 8e3; // default timeout 8 seconds
5
+ async function fetch(input, init) {
6
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
7
+ const timeout = init?.timeout || TIMEOUT;
8
+ const controller = timeout ? new AbortController() : undefined;
9
+ const timeoutId = controller
10
+ ? setTimeout(() => controller.abort(new Error(`Timeout after ${timeout}ms`)), timeout)
11
+ : undefined;
12
+ try {
13
+ const response = await globalThis
14
+ .fetch(input, {
15
+ ...init,
16
+ signal: controller?.signal,
17
+ })
18
+ .catch((error) => {
19
+ throw new Error(`Fetch ${url} error: ${error.message}`);
20
+ });
21
+ // Clear the timeout if the fetch completes successfully
22
+ clearTimeout(timeoutId);
23
+ if (!init?.skipResponseCheck && !response.ok) {
24
+ const text = await response.text().catch(() => "");
25
+ throw new Error(`Fetch ${url} error: ${response.status} ${response.statusText} ${text}`);
26
+ }
27
+ const json = response.json.bind(response);
28
+ response.json = () => json().catch((error) => {
29
+ throw new Error(`Parse JSON from ${url} error: ${error.message}`);
30
+ });
31
+ return response;
32
+ }
33
+ finally {
34
+ clearTimeout(timeoutId);
35
+ }
36
+ }
@@ -0,0 +1,4 @@
1
+ export declare function fetch(input: RequestInfo, init?: RequestInit & {
2
+ timeout?: number;
3
+ skipResponseCheck?: boolean;
4
+ }): Promise<Response>;
@@ -3,6 +3,7 @@ import { v7 } from "@aigne/uuid";
3
3
  import { parseURL } from "ufo";
4
4
  import { z } from "zod";
5
5
  import { optionalize } from "../loader/schema.js";
6
+ import { fetch } from "../utils/fetch.js";
6
7
  import { pick } from "../utils/type-utils.js";
7
8
  import { Agent } from "./agent.js";
8
9
  export class Model extends Agent {
@@ -65,10 +66,6 @@ export class Model extends Agent {
65
66
  }
66
67
  async downloadFile(url) {
67
68
  const response = await fetch(url);
68
- if (!response.ok) {
69
- const text = await response.text().catch(() => null);
70
- throw new Error(`Failed to download content from ${url}, ${response.status} ${response.statusText} ${text}`);
71
- }
72
69
  return response;
73
70
  }
74
71
  }
@@ -0,0 +1,4 @@
1
+ export declare function fetch(input: RequestInfo, init?: RequestInit & {
2
+ timeout?: number;
3
+ skipResponseCheck?: boolean;
4
+ }): Promise<Response>;
@@ -0,0 +1,33 @@
1
+ const TIMEOUT = (process.env.TIMEOUT && parseInt(process.env.TIMEOUT, 10)) || 8e3; // default timeout 8 seconds
2
+ export async function fetch(input, init) {
3
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
4
+ const timeout = init?.timeout || TIMEOUT;
5
+ const controller = timeout ? new AbortController() : undefined;
6
+ const timeoutId = controller
7
+ ? setTimeout(() => controller.abort(new Error(`Timeout after ${timeout}ms`)), timeout)
8
+ : undefined;
9
+ try {
10
+ const response = await globalThis
11
+ .fetch(input, {
12
+ ...init,
13
+ signal: controller?.signal,
14
+ })
15
+ .catch((error) => {
16
+ throw new Error(`Fetch ${url} error: ${error.message}`);
17
+ });
18
+ // Clear the timeout if the fetch completes successfully
19
+ clearTimeout(timeoutId);
20
+ if (!init?.skipResponseCheck && !response.ok) {
21
+ const text = await response.text().catch(() => "");
22
+ throw new Error(`Fetch ${url} error: ${response.status} ${response.statusText} ${text}`);
23
+ }
24
+ const json = response.json.bind(response);
25
+ response.json = () => json().catch((error) => {
26
+ throw new Error(`Parse JSON from ${url} error: ${error.message}`);
27
+ });
28
+ return response;
29
+ }
30
+ finally {
31
+ clearTimeout(timeoutId);
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.65.0",
3
+ "version": "1.65.1-beta.1",
4
4
  "description": "The functional core of agentic AI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -92,8 +92,8 @@
92
92
  "zod-from-json-schema": "^0.0.5",
93
93
  "zod-to-json-schema": "^3.24.6",
94
94
  "@aigne/afs": "^1.1.1",
95
- "@aigne/platform-helpers": "^0.6.3",
96
- "@aigne/observability-api": "^0.11.4"
95
+ "@aigne/observability-api": "^0.11.5-beta",
96
+ "@aigne/platform-helpers": "^0.6.3"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@types/bun": "^1.2.22",