@aigne/core 1.18.0 → 1.18.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
@@ -5,6 +5,20 @@
5
5
 
6
6
  * add user context support ([#131](https://github.com/AIGNE-io/aigne-framework/issues/131)) ([4dd9d20](https://github.com/AIGNE-io/aigne-framework/commit/4dd9d20953f6ac33933723db56efd9b44bafeb02))
7
7
 
8
+ ## [1.18.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.18.0...core-v1.18.1) (2025-05-30)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * respect DEBUG env for logger ([#142](https://github.com/AIGNE-io/aigne-framework/issues/142)) ([f84738a](https://github.com/AIGNE-io/aigne-framework/commit/f84738acb382d9fb4f47253fcf91c92c02200053))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * The following workspace dependencies were updated
19
+ * dependencies
20
+ * @aigne/platform-helpers bumped to 0.1.1
21
+
8
22
  ## [1.18.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.17.0...core-v1.18.0) (2025-05-29)
9
23
 
10
24
 
@@ -1,10 +1,10 @@
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
1
2
  import { ZodObject, type ZodType } from "zod";
2
3
  import type { Context, UserContext } from "../aigne/context.js";
3
4
  import type { MessagePayload } from "../aigne/message-queue.js";
4
5
  import type { Memory, MemoryAgent } from "../memory/memory.js";
5
6
  import type { MemoryRecorderInput } from "../memory/recorder.js";
6
7
  import type { MemoryRetrieverInput } from "../memory/retriever.js";
7
- import { nodejs } from "../utils/nodejs.js";
8
8
  import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils.js";
9
9
  import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
10
10
  import { type TransferAgentOutput } from "./types.js";
@@ -40,10 +40,10 @@ exports.FunctionAgent = exports.Agent = exports.agentOptionsSchema = void 0;
40
40
  exports.isEmptyChunk = isEmptyChunk;
41
41
  exports.textDelta = textDelta;
42
42
  exports.jsonDelta = jsonDelta;
43
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
43
44
  const zod_1 = require("zod");
44
45
  const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
45
46
  const logger_js_1 = require("../utils/logger.js");
46
- const nodejs_js_1 = require("../utils/nodejs.js");
47
47
  const stream_utils_js_1 = require("../utils/stream-utils.js");
48
48
  const type_utils_js_1 = require("../utils/type-utils.js");
49
49
  const types_js_1 = require("./types.js");
@@ -557,7 +557,7 @@ class Agent {
557
557
  *
558
558
  * @returns Agent name
559
559
  */
560
- [nodejs_js_1.nodejs.customInspect]() {
560
+ [index_js_1.nodejs.customInspect]() {
561
561
  return this.name;
562
562
  }
563
563
  /**
@@ -5,7 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MCPResource = exports.MCPPrompt = exports.MCPTool = exports.MCPBase = exports.MCPAgent = void 0;
7
7
  const stdio_client_transport_js_1 = require("@aigne/platform-helpers/mcp/stdio-client-transport.js");
8
- const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
8
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
9
+ const index_js_2 = require("@modelcontextprotocol/sdk/client/index.js");
9
10
  const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
10
11
  const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
11
12
  const uriTemplate_js_1 = require("@modelcontextprotocol/sdk/shared/uriTemplate.js");
@@ -13,7 +14,6 @@ const p_retry_1 = __importDefault(require("p-retry"));
13
14
  const zod_1 = require("zod");
14
15
  const logger_js_1 = require("../utils/logger.js");
15
16
  const mcp_utils_js_1 = require("../utils/mcp-utils.js");
16
- const nodejs_js_1 = require("../utils/nodejs.js");
17
17
  const type_utils_js_1 = require("../utils/type-utils.js");
18
18
  const agent_js_1 = require("./agent.js");
19
19
  const MCP_AGENT_CLIENT_NAME = "AIGNE/MCPAgent";
@@ -23,7 +23,7 @@ const DEFAULT_TIMEOUT = () => zod_1.z.coerce
23
23
  .number()
24
24
  .int()
25
25
  .min(0)
26
- .safeParse(nodejs_js_1.nodejs.env.MCP_TIMEOUT || nodejs_js_1.nodejs.env.TIMEOUT).data || 60e3;
26
+ .safeParse(index_js_1.nodejs.env.MCP_TIMEOUT || index_js_1.nodejs.env.TIMEOUT).data || 60e3;
27
27
  function isSSEServerParameters(options) {
28
28
  return "url" in options && typeof options.url === "string";
29
29
  }
@@ -203,7 +203,7 @@ class MCPAgent extends agent_js_1.Agent {
203
203
  }
204
204
  }
205
205
  exports.MCPAgent = MCPAgent;
206
- class ClientWithReconnect extends index_js_1.Client {
206
+ class ClientWithReconnect extends index_js_2.Client {
207
207
  reconnectOptions;
208
208
  constructor(info, options, reconnectOptions) {
209
209
  super(info, options);
@@ -294,7 +294,7 @@ function getMCPServerName(client) {
294
294
  }
295
295
  const mcpAgentOptionsSchema = zod_1.z.union([
296
296
  zod_1.z.object({
297
- client: zod_1.z.instanceof(index_js_1.Client),
297
+ client: zod_1.z.instanceof(index_js_2.Client),
298
298
  prompts: zod_1.z.array(zod_1.z.instanceof(MCPPrompt)).optional(),
299
299
  resources: zod_1.z.array(zod_1.z.instanceof(MCPResource)).optional(),
300
300
  }),
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadAgentFromYamlFile = loadAgentFromYamlFile;
4
4
  const json_schema_to_zod_1 = require("@aigne/json-schema-to-zod");
5
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
5
6
  const yaml_1 = require("yaml");
6
7
  const zod_1 = require("zod");
7
8
  const ai_agent_js_1 = require("../agents/ai-agent.js");
8
9
  const camelize_js_1 = require("../utils/camelize.js");
9
- const nodejs_js_1 = require("../utils/nodejs.js");
10
10
  const type_utils_js_1 = require("../utils/type-utils.js");
11
11
  const schema_js_1 = require("./schema.js");
12
12
  const agentFileSchema = zod_1.z.discriminatedUnion("type", [
@@ -70,7 +70,7 @@ const agentFileSchema = zod_1.z.discriminatedUnion("type", [
70
70
  }),
71
71
  ]);
72
72
  async function loadAgentFromYamlFile(path) {
73
- const raw = await (0, type_utils_js_1.tryOrThrow)(() => nodejs_js_1.nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
73
+ const raw = await (0, type_utils_js_1.tryOrThrow)(() => index_js_1.nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
74
74
  const json = await (0, type_utils_js_1.tryOrThrow)(() => (0, yaml_1.parse)(raw), (error) => new Error(`Failed to parse agent definition from ${path}: ${error.message}`));
75
75
  const agent = (0, type_utils_js_1.tryOrThrow)(() => (0, camelize_js_1.customCamelize)(agentFileSchema.parse({
76
76
  ...json,
@@ -4,22 +4,22 @@ exports.load = load;
4
4
  exports.loadAgent = loadAgent;
5
5
  exports.loadModel = loadModel;
6
6
  exports.loadAIGNEFile = loadAIGNEFile;
7
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
7
8
  const yaml_1 = require("yaml");
8
9
  const zod_1 = require("zod");
9
10
  const agent_js_1 = require("../agents/agent.js");
10
11
  const ai_agent_js_1 = require("../agents/ai-agent.js");
11
12
  const mcp_agent_js_1 = require("../agents/mcp-agent.js");
12
- const nodejs_js_1 = require("../utils/nodejs.js");
13
13
  const type_utils_js_1 = require("../utils/type-utils.js");
14
14
  const agent_js_js_1 = require("./agent-js.js");
15
15
  const agent_yaml_js_1 = require("./agent-yaml.js");
16
16
  const AIGNE_FILE_NAME = ["aigne.yaml", "aigne.yml"];
17
17
  async function load(options) {
18
18
  const aigneFilePath = await getAIGNEFilePath(options.path);
19
- const rootDir = nodejs_js_1.nodejs.path.dirname(aigneFilePath);
19
+ const rootDir = index_js_1.nodejs.path.dirname(aigneFilePath);
20
20
  const aigne = await loadAIGNEFile(aigneFilePath);
21
- const agents = await Promise.all((aigne.agents ?? []).map((filename) => loadAgent(nodejs_js_1.nodejs.path.join(rootDir, filename))));
22
- const skills = await Promise.all((aigne.skills ?? []).map((filename) => loadAgent(nodejs_js_1.nodejs.path.join(rootDir, filename))));
21
+ const agents = await Promise.all((aigne.agents ?? []).map((filename) => loadAgent(index_js_1.nodejs.path.join(rootDir, filename))));
22
+ const skills = await Promise.all((aigne.skills ?? []).map((filename) => loadAgent(index_js_1.nodejs.path.join(rootDir, filename))));
23
23
  return {
24
24
  ...aigne,
25
25
  model: await loadModel(options.models, aigne.chat_model),
@@ -28,11 +28,11 @@ async function load(options) {
28
28
  };
29
29
  }
30
30
  async function loadAgent(path, options) {
31
- if (nodejs_js_1.nodejs.path.extname(path) === ".js") {
31
+ if (index_js_1.nodejs.path.extname(path) === ".js") {
32
32
  const agent = await (0, agent_js_js_1.loadAgentFromJsFile)(path);
33
33
  return agent_js_1.FunctionAgent.from(agent);
34
34
  }
35
- if (nodejs_js_1.nodejs.path.extname(path) === ".yaml" || nodejs_js_1.nodejs.path.extname(path) === ".yml") {
35
+ if (index_js_1.nodejs.path.extname(path) === ".yaml" || index_js_1.nodejs.path.extname(path) === ".yml") {
36
36
  const agent = await (0, agent_yaml_js_1.loadAgentFromYamlFile)(path);
37
37
  if (agent.type === "ai") {
38
38
  return ai_agent_js_1.AIAgent.from({
@@ -41,7 +41,7 @@ async function loadAgent(path, options) {
41
41
  ? undefined
42
42
  : await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {}),
43
43
  skills: agent.skills &&
44
- (await Promise.all(agent.skills.map((filename) => loadAgent(nodejs_js_1.nodejs.path.join(nodejs_js_1.nodejs.path.dirname(path), filename))))),
44
+ (await Promise.all(agent.skills.map((filename) => loadAgent(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), filename))))),
45
45
  });
46
46
  }
47
47
  if (agent.type === "mcp") {
@@ -69,7 +69,7 @@ async function loadMemory(memories, provider, options) {
69
69
  throw new Error(`Unsupported memory: ${provider}`);
70
70
  return new M(options);
71
71
  }
72
- const { MODEL_PROVIDER, MODEL_NAME } = nodejs_js_1.nodejs.env;
72
+ const { MODEL_PROVIDER, MODEL_NAME } = index_js_1.nodejs.env;
73
73
  const DEFAULT_MODEL_PROVIDER = "openai";
74
74
  async function loadModel(models, model, modelOptions) {
75
75
  const params = {
@@ -107,17 +107,17 @@ const aigneFileSchema = zod_1.z.object({
107
107
  skills: zod_1.z.array(zod_1.z.string()).nullish(),
108
108
  });
109
109
  async function loadAIGNEFile(path) {
110
- const raw = await (0, type_utils_js_1.tryOrThrow)(() => nodejs_js_1.nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load aigne.yaml from ${path}: ${error.message}`));
110
+ const raw = await (0, type_utils_js_1.tryOrThrow)(() => index_js_1.nodejs.fs.readFile(path, "utf8"), (error) => new Error(`Failed to load aigne.yaml from ${path}: ${error.message}`));
111
111
  const json = await (0, type_utils_js_1.tryOrThrow)(() => (0, yaml_1.parse)(raw), (error) => new Error(`Failed to parse aigne.yaml from ${path}: ${error.message}`));
112
112
  const agent = (0, type_utils_js_1.tryOrThrow)(() => aigneFileSchema.parse({ ...json, skills: json.skills ?? json.tools }), (error) => new Error(`Failed to validate aigne.yaml from ${path}: ${error.message}`));
113
113
  return agent;
114
114
  }
115
115
  async function getAIGNEFilePath(path) {
116
- const s = await nodejs_js_1.nodejs.fs.stat(path);
116
+ const s = await index_js_1.nodejs.fs.stat(path);
117
117
  if (s.isDirectory()) {
118
118
  for (const file of AIGNE_FILE_NAME) {
119
- const filePath = nodejs_js_1.nodejs.path.join(path, file);
120
- if ((await nodejs_js_1.nodejs.fs.stat(filePath)).isFile())
119
+ const filePath = index_js_1.nodejs.path.join(path, file);
120
+ if ((await index_js_1.nodejs.fs.stat(filePath)).isFile())
121
121
  return filePath;
122
122
  }
123
123
  }
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PromptBuilder = exports.MESSAGE_KEY = void 0;
4
4
  exports.createMessage = createMessage;
5
5
  exports.getMessage = getMessage;
6
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
6
7
  const yaml_1 = require("yaml");
7
8
  const zod_1 = require("zod");
8
9
  const agent_js_1 = require("../agents/agent.js");
9
10
  const json_schema_js_1 = require("../utils/json-schema.js");
10
- const nodejs_js_1 = require("../utils/nodejs.js");
11
11
  const type_utils_js_1 = require("../utils/type-utils.js");
12
12
  const memory_message_template_js_1 = require("./prompts/memory-message-template.js");
13
13
  const template_js_1 = require("./template.js");
@@ -36,7 +36,7 @@ class PromptBuilder {
36
36
  throw new Error(`Invalid instructions ${instructions}`);
37
37
  }
38
38
  static async fromFile(path) {
39
- const text = await nodejs_js_1.nodejs.fs.readFile(path, "utf-8");
39
+ const text = await index_js_1.nodejs.fs.readFile(path, "utf-8");
40
40
  return PromptBuilder.from(text);
41
41
  }
42
42
  static fromMCPPromptResult(result) {
@@ -4,7 +4,12 @@ export declare enum LogLevel {
4
4
  INFO = "info",
5
5
  DEBUG = "debug"
6
6
  }
7
+ export declare function getLevelFromEnv(ns: string): LogLevel | undefined;
7
8
  export declare class Logger {
9
+ options: {
10
+ level: LogLevel;
11
+ ns: string;
12
+ };
8
13
  constructor(options: {
9
14
  level: LogLevel;
10
15
  ns: string;
@@ -4,8 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.logger = exports.Logger = exports.LogLevel = void 0;
7
+ exports.getLevelFromEnv = getLevelFromEnv;
8
+ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
7
9
  const debug_1 = __importDefault(require("debug"));
8
- const nodejs_js_1 = require("./nodejs.js");
9
10
  var LogLevel;
10
11
  (function (LogLevel) {
11
12
  LogLevel["ERROR"] = "error";
@@ -14,22 +15,31 @@ var LogLevel;
14
15
  LogLevel["DEBUG"] = "debug";
15
16
  })(LogLevel || (exports.LogLevel = LogLevel = {}));
16
17
  const levels = Object.values(LogLevel);
18
+ function getLevelFromEnv(ns) {
19
+ for (const level of levels.toReversed()) {
20
+ if (debug_1.default.enabled(`${ns}:${level}`)) {
21
+ return level;
22
+ }
23
+ }
24
+ }
17
25
  class Logger {
26
+ options;
18
27
  constructor(options) {
19
- this.level = options.level;
20
- this.debugLogger = (0, debug_1.default)(`${options.ns}:debug`);
21
- this.infoLogger = (0, debug_1.default)(`${options.ns}:info`);
22
- this.warnLogger = (0, debug_1.default)(`${options.ns}:warn`);
23
- this.errorLogger = (0, debug_1.default)(`${options.ns}:error`);
28
+ this.options = options;
29
+ this.debugLogger = (0, debug_1.default)(`${options.ns}:${LogLevel.DEBUG}`);
30
+ this.infoLogger = (0, debug_1.default)(`${options.ns}:${LogLevel.INFO}`);
31
+ this.warnLogger = (0, debug_1.default)(`${options.ns}:${LogLevel.WARN}`);
32
+ this.errorLogger = (0, debug_1.default)(`${options.ns}:${LogLevel.ERROR}`);
33
+ this.level = getLevelFromEnv(options.ns) || options.level;
24
34
  for (const logger of [this.debugLogger, this.infoLogger, this.warnLogger]) {
25
35
  // @ts-ignore
26
- logger.useColors = nodejs_js_1.nodejs.isStdoutATTY;
36
+ logger.useColors = index_js_1.nodejs.isStdoutATTY;
27
37
  logger.enabled = true;
28
38
  logger.log = (...args) => this.logMessage(...args);
29
39
  }
30
40
  this.errorLogger.log = (...args) => this.logError(...args);
31
41
  // @ts-ignore
32
- this.errorLogger.useColors = nodejs_js_1.nodejs.isStderrATTY;
42
+ this.errorLogger.useColors = index_js_1.nodejs.isStderrATTY;
33
43
  this.errorLogger.enabled = true;
34
44
  }
35
45
  level;
@@ -1,10 +1,10 @@
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
1
2
  import { ZodObject, type ZodType } from "zod";
2
3
  import type { Context, UserContext } from "../aigne/context.js";
3
4
  import type { MessagePayload } from "../aigne/message-queue.js";
4
5
  import type { Memory, MemoryAgent } from "../memory/memory.js";
5
6
  import type { MemoryRecorderInput } from "../memory/recorder.js";
6
7
  import type { MemoryRetrieverInput } from "../memory/retriever.js";
7
- import { nodejs } from "../utils/nodejs.js";
8
8
  import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils.js";
9
9
  import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
10
10
  import { type TransferAgentOutput } from "./types.js";
@@ -4,7 +4,12 @@ export declare enum LogLevel {
4
4
  INFO = "info",
5
5
  DEBUG = "debug"
6
6
  }
7
+ export declare function getLevelFromEnv(ns: string): LogLevel | undefined;
7
8
  export declare class Logger {
9
+ options: {
10
+ level: LogLevel;
11
+ ns: string;
12
+ };
8
13
  constructor(options: {
9
14
  level: LogLevel;
10
15
  ns: string;
@@ -1,10 +1,10 @@
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
1
2
  import { ZodObject, type ZodType } from "zod";
2
3
  import type { Context, UserContext } from "../aigne/context.js";
3
4
  import type { MessagePayload } from "../aigne/message-queue.js";
4
5
  import type { Memory, MemoryAgent } from "../memory/memory.js";
5
6
  import type { MemoryRecorderInput } from "../memory/recorder.js";
6
7
  import type { MemoryRetrieverInput } from "../memory/retriever.js";
7
- import { nodejs } from "../utils/nodejs.js";
8
8
  import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils.js";
9
9
  import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
10
10
  import { type TransferAgentOutput } from "./types.js";
@@ -1,7 +1,7 @@
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
1
2
  import { ZodObject, z } from "zod";
2
3
  import { createMessage, getMessage } from "../prompt/prompt-builder.js";
3
4
  import { logger } from "../utils/logger.js";
4
- import { nodejs } from "../utils/nodejs.js";
5
5
  import { agentResponseStreamToObject, asyncGeneratorToReadableStream, isAsyncGenerator, objectToAgentResponseStream, onAgentResponseStreamEnd, } from "../utils/stream-utils.js";
6
6
  import { checkArguments, createAccessorArray, isEmpty, orArrayToArray, } from "../utils/type-utils.js";
7
7
  import { replaceTransferAgentToName, transferToAgentOutput, } from "./types.js";
@@ -1,4 +1,5 @@
1
1
  import { createStdioClientTransport } from "@aigne/platform-helpers/mcp/stdio-client-transport.js";
2
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
3
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
3
4
  import { SSEClientTransport, } from "@modelcontextprotocol/sdk/client/sse.js";
4
5
  import { StreamableHTTPClientTransport, } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
@@ -7,7 +8,6 @@ import pRetry from "p-retry";
7
8
  import { z } from "zod";
8
9
  import { logger } from "../utils/logger.js";
9
10
  import { promptFromMCPPrompt, resourceFromMCPResource, toolFromMCPTool, } from "../utils/mcp-utils.js";
10
- import { nodejs } from "../utils/nodejs.js";
11
11
  import { checkArguments, createAccessorArray } from "../utils/type-utils.js";
12
12
  import { Agent } from "./agent.js";
13
13
  const MCP_AGENT_CLIENT_NAME = "AIGNE/MCPAgent";
@@ -1,9 +1,9 @@
1
1
  import { jsonSchemaToZod } from "@aigne/json-schema-to-zod";
2
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
2
3
  import { parse } from "yaml";
3
4
  import { z } from "zod";
4
5
  import { AIAgentToolChoice } from "../agents/ai-agent.js";
5
6
  import { customCamelize } from "../utils/camelize.js";
6
- import { nodejs } from "../utils/nodejs.js";
7
7
  import { tryOrThrow } from "../utils/type-utils.js";
8
8
  import { inputOutputSchema } from "./schema.js";
9
9
  const agentFileSchema = z.discriminatedUnion("type", [
@@ -1,9 +1,9 @@
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
1
2
  import { parse } from "yaml";
2
3
  import { z } from "zod";
3
4
  import { FunctionAgent } from "../agents/agent.js";
4
5
  import { AIAgent } from "../agents/ai-agent.js";
5
6
  import { MCPAgent } from "../agents/mcp-agent.js";
6
- import { nodejs } from "../utils/nodejs.js";
7
7
  import { tryOrThrow } from "../utils/type-utils.js";
8
8
  import { loadAgentFromJsFile } from "./agent-js.js";
9
9
  import { loadAgentFromYamlFile } from "./agent-yaml.js";
@@ -1,8 +1,8 @@
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
1
2
  import { stringify } from "yaml";
2
3
  import { ZodObject } from "zod";
3
4
  import { Agent } from "../agents/agent.js";
4
5
  import { outputSchemaToResponseFormatSchema } from "../utils/json-schema.js";
5
- import { nodejs } from "../utils/nodejs.js";
6
6
  import { isNil, unique } from "../utils/type-utils.js";
7
7
  import { MEMORY_MESSAGE_TEMPLATE } from "./prompts/memory-message-template.js";
8
8
  import { AgentMessageTemplate, ChatMessagesTemplate, PromptTemplate, SystemMessageTemplate, UserMessageTemplate, } from "./template.js";
@@ -4,7 +4,12 @@ export declare enum LogLevel {
4
4
  INFO = "info",
5
5
  DEBUG = "debug"
6
6
  }
7
+ export declare function getLevelFromEnv(ns: string): LogLevel | undefined;
7
8
  export declare class Logger {
9
+ options: {
10
+ level: LogLevel;
11
+ ns: string;
12
+ };
8
13
  constructor(options: {
9
14
  level: LogLevel;
10
15
  ns: string;
@@ -1,5 +1,5 @@
1
+ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
1
2
  import debug from "debug";
2
- import { nodejs } from "./nodejs.js";
3
3
  export var LogLevel;
4
4
  (function (LogLevel) {
5
5
  LogLevel["ERROR"] = "error";
@@ -8,13 +8,22 @@ export var LogLevel;
8
8
  LogLevel["DEBUG"] = "debug";
9
9
  })(LogLevel || (LogLevel = {}));
10
10
  const levels = Object.values(LogLevel);
11
+ export function getLevelFromEnv(ns) {
12
+ for (const level of levels.toReversed()) {
13
+ if (debug.enabled(`${ns}:${level}`)) {
14
+ return level;
15
+ }
16
+ }
17
+ }
11
18
  export class Logger {
19
+ options;
12
20
  constructor(options) {
13
- this.level = options.level;
14
- this.debugLogger = debug(`${options.ns}:debug`);
15
- this.infoLogger = debug(`${options.ns}:info`);
16
- this.warnLogger = debug(`${options.ns}:warn`);
17
- this.errorLogger = debug(`${options.ns}:error`);
21
+ this.options = options;
22
+ this.debugLogger = debug(`${options.ns}:${LogLevel.DEBUG}`);
23
+ this.infoLogger = debug(`${options.ns}:${LogLevel.INFO}`);
24
+ this.warnLogger = debug(`${options.ns}:${LogLevel.WARN}`);
25
+ this.errorLogger = debug(`${options.ns}:${LogLevel.ERROR}`);
26
+ this.level = getLevelFromEnv(options.ns) || options.level;
18
27
  for (const logger of [this.debugLogger, this.infoLogger, this.warnLogger]) {
19
28
  // @ts-ignore
20
29
  logger.useColors = nodejs.isStdoutATTY;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.18.0",
3
+ "version": "1.18.1",
4
4
  "description": "AIGNE core library for building AI-powered applications",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -81,7 +81,7 @@
81
81
  "yaml": "^2.7.1",
82
82
  "zod": "^3.24.4",
83
83
  "zod-to-json-schema": "^3.24.5",
84
- "@aigne/platform-helpers": "^0.1.0"
84
+ "@aigne/platform-helpers": "^0.1.1"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@types/bun": "^1.2.12",
@@ -1,8 +0,0 @@
1
- export declare const nodejs: {
2
- customInspect: any;
3
- isStdoutATTY: boolean;
4
- isStderrATTY: boolean;
5
- env: NodeJS.ProcessEnv;
6
- readonly fs: typeof import("node:fs/promises");
7
- readonly path: typeof import("node:path");
8
- };
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nodejs = void 0;
4
- exports.nodejs = {
5
- customInspect: isNodejsEnvironment() ? require("node:util").inspect.custom : Symbol("inspect"),
6
- isStdoutATTY: isNodejsEnvironment() && process.stdout?.isTTY,
7
- isStderrATTY: isNodejsEnvironment() && process.stderr?.isTTY,
8
- env: isNodejsEnvironment() ? process.env : {},
9
- get fs() {
10
- ensureNodejsEnvironment();
11
- return require("node:fs/promises");
12
- },
13
- get path() {
14
- ensureNodejsEnvironment();
15
- return require("node:path");
16
- },
17
- };
18
- function isNodejsEnvironment() {
19
- return typeof process !== "undefined";
20
- }
21
- function ensureNodejsEnvironment() {
22
- if (!isNodejsEnvironment())
23
- throw new Error("This code must run in a Node.js environment.");
24
- }
@@ -1,8 +0,0 @@
1
- export declare const nodejs: {
2
- customInspect: any;
3
- isStdoutATTY: boolean;
4
- isStderrATTY: boolean;
5
- env: NodeJS.ProcessEnv;
6
- readonly fs: typeof import("node:fs/promises");
7
- readonly path: typeof import("node:path");
8
- };
@@ -1,8 +0,0 @@
1
- export declare const nodejs: {
2
- customInspect: any;
3
- isStdoutATTY: boolean;
4
- isStderrATTY: boolean;
5
- env: NodeJS.ProcessEnv;
6
- readonly fs: typeof import("node:fs/promises");
7
- readonly path: typeof import("node:path");
8
- };
@@ -1,21 +0,0 @@
1
- export const nodejs = {
2
- customInspect: isNodejsEnvironment() ? require("node:util").inspect.custom : Symbol("inspect"),
3
- isStdoutATTY: isNodejsEnvironment() && process.stdout?.isTTY,
4
- isStderrATTY: isNodejsEnvironment() && process.stderr?.isTTY,
5
- env: isNodejsEnvironment() ? process.env : {},
6
- get fs() {
7
- ensureNodejsEnvironment();
8
- return require("node:fs/promises");
9
- },
10
- get path() {
11
- ensureNodejsEnvironment();
12
- return require("node:path");
13
- },
14
- };
15
- function isNodejsEnvironment() {
16
- return typeof process !== "undefined";
17
- }
18
- function ensureNodejsEnvironment() {
19
- if (!isNodejsEnvironment())
20
- throw new Error("This code must run in a Node.js environment.");
21
- }