@aigne/core 1.74.0-beta → 1.74.0-beta.2

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.
@@ -109,8 +109,8 @@ declare const imageModelInputSchema: z.ZodObject<{
109
109
  mimeType?: string | undefined;
110
110
  filename?: string | undefined;
111
111
  })[] | undefined;
112
- n?: number | undefined;
113
112
  outputFileType?: "local" | "url" | "file" | undefined;
113
+ n?: number | undefined;
114
114
  modelOptions?: Record<string, unknown> | undefined;
115
115
  }, {
116
116
  prompt: string;
@@ -130,8 +130,8 @@ declare const imageModelInputSchema: z.ZodObject<{
130
130
  mimeType?: string | undefined;
131
131
  filename?: string | undefined;
132
132
  })[] | undefined;
133
- n?: number | undefined;
134
133
  outputFileType?: "local" | "url" | "file" | undefined;
134
+ n?: number | undefined;
135
135
  modelOptions?: Record<string, unknown> | undefined;
136
136
  }>;
137
137
  interface ImageModelOutput extends Message {
@@ -109,8 +109,8 @@ declare const imageModelInputSchema: z$1.ZodObject<{
109
109
  mimeType?: string | undefined;
110
110
  filename?: string | undefined;
111
111
  })[] | undefined;
112
- n?: number | undefined;
113
112
  outputFileType?: "local" | "url" | "file" | undefined;
113
+ n?: number | undefined;
114
114
  modelOptions?: Record<string, unknown> | undefined;
115
115
  }, {
116
116
  prompt: string;
@@ -130,8 +130,8 @@ declare const imageModelInputSchema: z$1.ZodObject<{
130
130
  mimeType?: string | undefined;
131
131
  filename?: string | undefined;
132
132
  })[] | undefined;
133
- n?: number | undefined;
134
133
  outputFileType?: "local" | "url" | "file" | undefined;
134
+ n?: number | undefined;
135
135
  modelOptions?: Record<string, unknown> | undefined;
136
136
  }>;
137
137
  interface ImageModelOutput extends Message {
@@ -214,6 +214,7 @@ var AIGNE = class AIGNE {
214
214
  * Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.
215
215
  */
216
216
  initProcessExitHandler() {
217
+ if (typeof process === "undefined") return;
217
218
  const originalExit = process.exit;
218
219
  process.exit = (...args) => {
219
220
  this.shutdown().finally(() => originalExit(...args));
@@ -213,6 +213,7 @@ var AIGNE = class AIGNE {
213
213
  * Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.
214
214
  */
215
215
  initProcessExitHandler() {
216
+ if (typeof process === "undefined") return;
216
217
  const originalExit = process.exit;
217
218
  process.exit = (...args) => {
218
219
  this.shutdown().finally(() => originalExit(...args));
@@ -1 +1 @@
1
- {"version":3,"file":"aigne.mjs","names":["z"],"sources":["../../src/aigne/aigne.ts"],"sourcesContent":["import { AIGNEObserver } from \"@aigne/observability-api\";\nimport { z } from \"zod\";\nimport type { Agent, AgentResponse, AgentResponseStream, Message } from \"../agents/agent.js\";\nimport type { ChatModel } from \"../agents/chat-model.js\";\nimport type { ImageModel } from \"../agents/image-model.js\";\nimport type { UserAgent } from \"../agents/user-agent.js\";\nimport { type LoadOptions, load } from \"../loader/index.js\";\nimport { checkArguments, createAccessorArray } from \"../utils/type-utils.js\";\nimport { AIGNEContext, type Context, type InvokeOptions, type UserContext } from \"./context.js\";\nimport {\n type MessagePayload,\n MessageQueue,\n type MessageQueueListener,\n type Unsubscribe,\n} from \"./message-queue.js\";\nimport type { AIGNECLIAgents, AIGNEMetadata } from \"./type.js\";\nimport type { ContextLimits } from \"./usage.js\";\n\n/**\n * Options for the AIGNE class.\n */\nexport interface AIGNEOptions {\n /**\n * Optional root directory for this AIGNE instance.\n * This is used to resolve relative paths for agents and skills.\n */\n rootDir?: string;\n\n /**\n * The name of the AIGNE instance.\n */\n name?: string;\n\n /**\n * The description of the AIGNE instance.\n */\n description?: string;\n\n /**\n * Global model to use for all agents not specifying a model.\n */\n model?: ChatModel;\n\n /**\n * Optional image model to use for image processing tasks.\n */\n imageModel?: ImageModel;\n\n /**\n * Skills to use for the AIGNE instance.\n */\n skills?: Agent[];\n\n /**\n * Agents to use for the AIGNE instance.\n */\n agents?: Agent[];\n\n mcpServer?: {\n agents?: Agent[];\n };\n\n cli?: AIGNECLIAgents;\n\n /**\n * Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.\n */\n limits?: ContextLimits;\n\n /**\n * Observer for the AIGNE instance.\n */\n observer?: AIGNEObserver;\n\n metadata?: AIGNEMetadata;\n}\n\n/**\n * AIGNE is a class that orchestrates multiple agents to build complex AI applications.\n * It serves as the central coordination point for agent interactions, message passing, and execution flow.\n *\n * @example\n * Here's a simple example of how to use AIGNE:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-simple}\n *\n * @example\n * Here's an example of how to use AIGNE with streaming response:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}\n */\nexport class AIGNE<U extends UserContext = UserContext> {\n /**\n * Loads an AIGNE instance from a directory containing an aigne.yaml file and agent definitions.\n * This static method provides a convenient way to initialize an AIGNE system from configuration files.\n *\n * @param path - Path to the directory containing the aigne.yaml file.\n * @param options - Options to override the loaded configuration.\n * @returns A fully initialized AIGNE instance with configured agents and skills.\n */\n static async load(\n path: string,\n options: Omit<AIGNEOptions, keyof LoadOptions> & LoadOptions = {},\n ): Promise<AIGNE> {\n const { agents = [], skills = [], model, imageModel, ...aigne } = await load(path, options);\n return new AIGNE({\n ...aigne,\n ...options,\n model,\n imageModel,\n agents: agents.concat(options?.agents ?? []),\n skills: skills.concat(options?.skills ?? []),\n metadata: options?.metadata,\n });\n }\n\n /**\n * Creates a new AIGNE instance with the specified options.\n *\n * @param options - Configuration options for the AIGNE instance including name, description, model, and agents.\n */\n constructor(options?: AIGNEOptions) {\n if (options) checkArguments(\"AIGNE\", aigneOptionsSchema, options);\n\n this.rootDir = options?.rootDir;\n this.name = options?.name;\n this.description = options?.description;\n this.model = options?.model;\n this.imageModel = options?.imageModel;\n this.limits = options?.limits;\n this.observer =\n process.env.AIGNE_OBSERVABILITY_DISABLED === \"true\"\n ? undefined\n : (options?.observer ?? new AIGNEObserver());\n if (options?.skills?.length) this.skills.push(...options.skills);\n if (options?.agents?.length) this.addAgent(...options.agents);\n if (options?.mcpServer?.agents?.length) this.mcpServer.agents.push(...options.mcpServer.agents);\n this.cli = options?.cli ?? {};\n\n this.observer?.serve();\n this.initProcessExitHandler();\n this.metadata = options?.metadata ?? {};\n }\n\n /**\n * Optional root directory for this AIGNE instance.\n */\n rootDir?: string;\n\n /**\n * Optional name identifier for this AIGNE instance.\n */\n name?: string;\n\n /**\n * Optional description of this AIGNE instance's purpose or functionality.\n */\n description?: string;\n\n /**\n * Global model to use for all agents that don't specify their own model.\n */\n model?: ChatModel;\n\n /**\n * Optional image model to use for image processing tasks.\n */\n imageModel?: ImageModel;\n\n /**\n * Usage limits applied to this AIGNE instance's execution.\n */\n limits?: ContextLimits;\n\n /**\n * Message queue for handling inter-agent communication.\n *\n * @hidden\n */\n readonly messageQueue = new MessageQueue();\n\n /**\n * Collection of all context IDs created by this AIGNE instance.\n */\n readonly contextIds = new Set<string>();\n\n /**\n * Collection of skill agents available to this AIGNE instance.\n * Provides indexed access by skill name.\n */\n readonly skills = createAccessorArray<Agent>([], (arr, name) => arr.find((i) => i.name === name));\n\n /**\n * Collection of primary agents managed by this AIGNE instance.\n * Provides indexed access by agent name.\n */\n readonly agents = createAccessorArray<Agent>([], (arr, name) => arr.find((i) => i.name === name));\n\n readonly mcpServer = {\n agents: createAccessorArray<Agent>([], (arr, name) => arr.find((i) => i.name === name)),\n };\n\n readonly cli: AIGNECLIAgents = {};\n\n /**\n * Observer for the AIGNE instance.\n */\n readonly observer?: AIGNEObserver;\n\n /**\n * Metadata for the AIGNE instance.\n */\n readonly metadata: AIGNEMetadata = {};\n\n /**\n * Adds one or more agents to this AIGNE instance.\n * Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.\n *\n * @param agents - One or more Agent instances to add to this AIGNE.\n */\n addAgent(...agents: Agent[]) {\n checkArguments(\"AIGNE.addAgent\", aigneAddAgentArgsSchema, agents);\n\n for (const agent of agents) {\n this.agents.push(agent);\n\n agent.attach(this);\n }\n }\n\n /**\n * Creates a new execution context for this AIGNE instance.\n * Contexts isolate state for different flows or conversations.\n *\n * @returns A new AIGNEContext instance bound to this AIGNE.\n */\n newContext(options?: Partial<Pick<Context, \"userContext\" | \"memories\">>) {\n const context = new AIGNEContext(this);\n\n if (options?.userContext) context.userContext = options.userContext;\n if (options?.memories) context.memories = options.memories;\n\n return context;\n }\n\n /**\n * Creates a user agent for consistent interactions with a specified agent.\n * This method allows you to create a wrapper around an agent for repeated invocations.\n *\n * @param agent - Target agent to be wrapped for consistent invocation\n * @returns A user agent instance that provides a convenient interface for interacting with the target agent\n *\n * @example\n * Here's an example of how to create a user agent and invoke it consistently:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-user-agent}\n */\n invoke<I extends Message, O extends Message>(agent: Agent<I, O>): UserAgent<I, O>;\n\n /**\n * Invokes an agent with a message and returns both the output and the active agent.\n * This overload is useful when you need to track which agent was ultimately responsible for generating the response.\n *\n * @param agent - Target agent to invoke\n * @param message - Input message to send to the agent\n * @param options.returnActiveAgent - Must be true to return the final active agent\n * @param options.streaming - Must be false to return a response stream\n * @returns A promise resolving to a tuple containing the agent's response and the final active agent\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message: I & Message,\n options: InvokeOptions<U> & { returnActiveAgent: true; streaming?: false },\n ): Promise<[O, Agent]>;\n\n /**\n * Invokes an agent with a message and returns both a stream of the response and the active agent.\n * This overload is useful when you need streaming responses while also tracking which agent provided them.\n *\n * @param agent - Target agent to invoke\n * @param message - Input message to send to the agent\n * @param options.returnActiveAgent - Must be true to return the final active agent\n * @param options.streaming - Must be true to return a response stream\n * @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message: I & Message,\n options: InvokeOptions<U> & { returnActiveAgent: true; streaming: true },\n ): Promise<[AgentResponseStream<O>, Promise<Agent>]>;\n\n /**\n * Invokes an agent with a message and returns just the output.\n * This is the standard way to invoke an agent when you only need the response.\n *\n * @param agent - Target agent to invoke\n * @param message - Input message to send to the agent\n * @param options - Optional configuration parameters for the invocation\n * @returns A promise resolving to the agent's complete response\n *\n * @example\n * Here's a simple example of how to invoke an agent:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-simple}\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message: I & Message,\n options?: InvokeOptions<U> & { returnActiveAgent?: false; streaming?: false },\n ): Promise<O>;\n\n /**\n * Invokes an agent with a message and returns a stream of the response.\n * This allows processing the response incrementally as it's being generated.\n *\n * @param agent - Target agent to invoke\n * @param message - Input message to send to the agent\n * @param options - Configuration with streaming enabled to receive incremental response chunks\n * @returns A promise resolving to a stream of the agent's response that can be consumed incrementally\n *\n * @example\n * Here's an example of how to invoke an agent with streaming response:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message: I & Message,\n options: InvokeOptions<U> & { returnActiveAgent?: false; streaming: true },\n ): Promise<AgentResponseStream<O>>;\n\n /**\n * General implementation signature that handles all overload cases.\n * This unified signature supports all the different invocation patterns defined by the overloads.\n *\n * @param agent - Target agent to invoke or wrap\n * @param message - Optional input message to send to the agent\n * @param options - Optional configuration parameters for the invocation\n * @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response\n * with optional active agent information based on the provided options\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message?: I & Message,\n options?: InvokeOptions<U>,\n ): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;\n\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message?: I & Message,\n options?: InvokeOptions<U>,\n ): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]> {\n this.observer?.serve();\n const context = new AIGNEContext(this);\n return context.invoke(agent, message, { ...options, newContext: false });\n }\n\n /**\n * Publishes a message to the message queue for inter-agent communication.\n * This method broadcasts a message to all subscribers of the specified topic(s).\n * It creates a new context internally and delegates to the context's publish method.\n *\n * @param topic - The topic or array of topics to publish the message to\n * @param payload - The message payload to be delivered to subscribers\n * @param options - Optional configuration parameters for the publish operation\n *\n * @example\n * Here's an example of how to publish a message:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}\n */\n publish(\n topic: string | string[],\n payload: Omit<MessagePayload, \"context\"> | Message,\n options?: InvokeOptions<U>,\n ) {\n this.observer?.serve();\n return new AIGNEContext(this).publish(topic, payload, options);\n }\n\n /**\n * Subscribes to receive the next message on a specific topic.\n * This overload returns a Promise that resolves with the next message published to the topic.\n * It's useful for one-time message handling or when using async/await patterns.\n *\n * @param topic - The topic to subscribe to\n * @returns A Promise that resolves with the next message payload published to the specified topic\n *\n * @example\n * Here's an example of how to subscribe to a topic and receive the next message:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}\n */\n subscribe(topic: string | string[], listener?: undefined): Promise<MessagePayload>;\n\n /**\n * Subscribes to messages on a specific topic with a listener callback.\n * This overload registers a listener function that will be called for each message published to the topic.\n * It's useful for continuous message handling or event-driven architectures.\n *\n * @param topic - The topic to subscribe to\n * @param listener - Callback function that will be invoked when messages arrive on the specified topic\n * @returns An Unsubscribe function that can be called to cancel the subscription\n *\n * @example\n * Here's an example of how to subscribe to a topic with a listener:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-subscribe-topic}\n */\n subscribe(topic: string | string[], listener: MessageQueueListener): Unsubscribe;\n\n /**\n * Generic subscribe signature that handles both Promise and listener patterns.\n * This is the implementation signature that supports both overloaded behaviors.\n *\n * @param topic - The topic to subscribe to\n * @param listener - Optional callback function\n * @returns Either a Promise for the next message or an Unsubscribe function\n */\n subscribe(\n topic: string | string[],\n listener?: MessageQueueListener,\n ): Unsubscribe | Promise<MessagePayload>;\n subscribe(\n topic: string | string[],\n listener?: MessageQueueListener,\n ): Unsubscribe | Promise<MessagePayload> {\n return this.messageQueue.subscribe(topic, listener);\n }\n\n /**\n * Unsubscribes a listener from a specific topic in the message queue.\n * This method stops a previously registered listener from receiving further messages.\n * It should be called when message processing is complete or when the component is no longer interested\n * in messages published to the specified topic.\n *\n * @param topic - The topic to unsubscribe from\n * @param listener - The listener function that was previously subscribed to the topic\n *\n * @example\n * {@includeCode ../../test/aigne/aigne.test.ts#example-subscribe-topic}\n */\n unsubscribe(topic: string | string[], listener: MessageQueueListener) {\n this.messageQueue.unsubscribe(topic, listener);\n }\n\n /**\n * Gracefully shuts down the AIGNE instance and all its agents and skills.\n * This ensures proper cleanup of resources before termination.\n *\n * @returns A promise that resolves when shutdown is complete.\n *\n * @example\n * Here's an example of shutdown an AIGNE instance:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-shutdown}\n */\n async shutdown() {\n // Close observer first to flush any pending traces\n await this.observer?.close(Array.from(this.contextIds));\n\n for (const tool of this.skills) {\n await tool.shutdown();\n }\n for (const agent of this.agents) {\n await agent.shutdown();\n }\n }\n\n /**\n * Asynchronous dispose method for the AIGNE instance.\n *\n * @example\n * Here's an example of using async dispose:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-shutdown-using}\n */\n async [Symbol.asyncDispose]() {\n await this.shutdown();\n }\n\n /**\n * Initializes handlers for process exit events to ensure clean shutdown.\n * This registers handlers for SIGINT/SIGTERM to properly terminate all agents.\n * Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.\n */\n private initProcessExitHandler() {\n const originalExit = process.exit;\n\n // @ts-ignore\n process.exit = (...args) => {\n this.shutdown().finally(() => originalExit(...args));\n };\n\n const shutdownAndExit = () => this.shutdown().finally(() => originalExit(0));\n process.on(\"SIGINT\", shutdownAndExit);\n }\n}\n\nconst aigneOptionsSchema = z.object({\n model: z.custom<ChatModel>().optional(),\n imageModel: z.custom<ImageModel>().optional(),\n skills: z.array(z.custom<Agent>()).optional(),\n agents: z.array(z.custom<Agent>()).optional(),\n observer: z.custom<AIGNEObserver>().optional(),\n});\n\nconst aigneAddAgentArgsSchema = z.array(z.custom<Agent>());\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyFA,IAAa,QAAb,MAAa,MAA2C;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AAO,OAAO,gBAAgB;AAC5B,QAAM,KAAK,UAAU;;;;;;;CAQvB,AAAQ,yBAAyB;EAC/B,MAAM,eAAe,QAAQ;AAG7B,UAAQ,QAAQ,GAAG,SAAS;AAC1B,QAAK,UAAU,CAAC,cAAc,aAAa,GAAG,KAAK,CAAC;;EAGtD,MAAM,wBAAwB,KAAK,UAAU,CAAC,cAAc,aAAa,EAAE,CAAC;AAC5E,UAAQ,GAAG,UAAU,gBAAgB;;;AAIzC,MAAM,qBAAqBA,IAAE,OAAO;CAClC,OAAOA,IAAE,QAAmB,CAAC,UAAU;CACvC,YAAYA,IAAE,QAAoB,CAAC,UAAU;CAC7C,QAAQA,IAAE,MAAMA,IAAE,QAAe,CAAC,CAAC,UAAU;CAC7C,QAAQA,IAAE,MAAMA,IAAE,QAAe,CAAC,CAAC,UAAU;CAC7C,UAAUA,IAAE,QAAuB,CAAC,UAAU;CAC/C,CAAC;AAEF,MAAM,0BAA0BA,IAAE,MAAMA,IAAE,QAAe,CAAC"}
1
+ {"version":3,"file":"aigne.mjs","names":["z"],"sources":["../../src/aigne/aigne.ts"],"sourcesContent":["import { AIGNEObserver } from \"@aigne/observability-api\";\nimport { z } from \"zod\";\nimport type { Agent, AgentResponse, AgentResponseStream, Message } from \"../agents/agent.js\";\nimport type { ChatModel } from \"../agents/chat-model.js\";\nimport type { ImageModel } from \"../agents/image-model.js\";\nimport type { UserAgent } from \"../agents/user-agent.js\";\nimport { type LoadOptions, load } from \"../loader/index.js\";\nimport { checkArguments, createAccessorArray } from \"../utils/type-utils.js\";\nimport { AIGNEContext, type Context, type InvokeOptions, type UserContext } from \"./context.js\";\nimport {\n type MessagePayload,\n MessageQueue,\n type MessageQueueListener,\n type Unsubscribe,\n} from \"./message-queue.js\";\nimport type { AIGNECLIAgents, AIGNEMetadata } from \"./type.js\";\nimport type { ContextLimits } from \"./usage.js\";\n\n/**\n * Options for the AIGNE class.\n */\nexport interface AIGNEOptions {\n /**\n * Optional root directory for this AIGNE instance.\n * This is used to resolve relative paths for agents and skills.\n */\n rootDir?: string;\n\n /**\n * The name of the AIGNE instance.\n */\n name?: string;\n\n /**\n * The description of the AIGNE instance.\n */\n description?: string;\n\n /**\n * Global model to use for all agents not specifying a model.\n */\n model?: ChatModel;\n\n /**\n * Optional image model to use for image processing tasks.\n */\n imageModel?: ImageModel;\n\n /**\n * Skills to use for the AIGNE instance.\n */\n skills?: Agent[];\n\n /**\n * Agents to use for the AIGNE instance.\n */\n agents?: Agent[];\n\n mcpServer?: {\n agents?: Agent[];\n };\n\n cli?: AIGNECLIAgents;\n\n /**\n * Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.\n */\n limits?: ContextLimits;\n\n /**\n * Observer for the AIGNE instance.\n */\n observer?: AIGNEObserver;\n\n metadata?: AIGNEMetadata;\n}\n\n/**\n * AIGNE is a class that orchestrates multiple agents to build complex AI applications.\n * It serves as the central coordination point for agent interactions, message passing, and execution flow.\n *\n * @example\n * Here's a simple example of how to use AIGNE:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-simple}\n *\n * @example\n * Here's an example of how to use AIGNE with streaming response:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}\n */\nexport class AIGNE<U extends UserContext = UserContext> {\n /**\n * Loads an AIGNE instance from a directory containing an aigne.yaml file and agent definitions.\n * This static method provides a convenient way to initialize an AIGNE system from configuration files.\n *\n * @param path - Path to the directory containing the aigne.yaml file.\n * @param options - Options to override the loaded configuration.\n * @returns A fully initialized AIGNE instance with configured agents and skills.\n */\n static async load(\n path: string,\n options: Omit<AIGNEOptions, keyof LoadOptions> & LoadOptions = {},\n ): Promise<AIGNE> {\n const { agents = [], skills = [], model, imageModel, ...aigne } = await load(path, options);\n return new AIGNE({\n ...aigne,\n ...options,\n model,\n imageModel,\n agents: agents.concat(options?.agents ?? []),\n skills: skills.concat(options?.skills ?? []),\n metadata: options?.metadata,\n });\n }\n\n /**\n * Creates a new AIGNE instance with the specified options.\n *\n * @param options - Configuration options for the AIGNE instance including name, description, model, and agents.\n */\n constructor(options?: AIGNEOptions) {\n if (options) checkArguments(\"AIGNE\", aigneOptionsSchema, options);\n\n this.rootDir = options?.rootDir;\n this.name = options?.name;\n this.description = options?.description;\n this.model = options?.model;\n this.imageModel = options?.imageModel;\n this.limits = options?.limits;\n this.observer =\n process.env.AIGNE_OBSERVABILITY_DISABLED === \"true\"\n ? undefined\n : (options?.observer ?? new AIGNEObserver());\n if (options?.skills?.length) this.skills.push(...options.skills);\n if (options?.agents?.length) this.addAgent(...options.agents);\n if (options?.mcpServer?.agents?.length) this.mcpServer.agents.push(...options.mcpServer.agents);\n this.cli = options?.cli ?? {};\n\n this.observer?.serve();\n this.initProcessExitHandler();\n this.metadata = options?.metadata ?? {};\n }\n\n /**\n * Optional root directory for this AIGNE instance.\n */\n rootDir?: string;\n\n /**\n * Optional name identifier for this AIGNE instance.\n */\n name?: string;\n\n /**\n * Optional description of this AIGNE instance's purpose or functionality.\n */\n description?: string;\n\n /**\n * Global model to use for all agents that don't specify their own model.\n */\n model?: ChatModel;\n\n /**\n * Optional image model to use for image processing tasks.\n */\n imageModel?: ImageModel;\n\n /**\n * Usage limits applied to this AIGNE instance's execution.\n */\n limits?: ContextLimits;\n\n /**\n * Message queue for handling inter-agent communication.\n *\n * @hidden\n */\n readonly messageQueue = new MessageQueue();\n\n /**\n * Collection of all context IDs created by this AIGNE instance.\n */\n readonly contextIds = new Set<string>();\n\n /**\n * Collection of skill agents available to this AIGNE instance.\n * Provides indexed access by skill name.\n */\n readonly skills = createAccessorArray<Agent>([], (arr, name) => arr.find((i) => i.name === name));\n\n /**\n * Collection of primary agents managed by this AIGNE instance.\n * Provides indexed access by agent name.\n */\n readonly agents = createAccessorArray<Agent>([], (arr, name) => arr.find((i) => i.name === name));\n\n readonly mcpServer = {\n agents: createAccessorArray<Agent>([], (arr, name) => arr.find((i) => i.name === name)),\n };\n\n readonly cli: AIGNECLIAgents = {};\n\n /**\n * Observer for the AIGNE instance.\n */\n readonly observer?: AIGNEObserver;\n\n /**\n * Metadata for the AIGNE instance.\n */\n readonly metadata: AIGNEMetadata = {};\n\n /**\n * Adds one or more agents to this AIGNE instance.\n * Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.\n *\n * @param agents - One or more Agent instances to add to this AIGNE.\n */\n addAgent(...agents: Agent[]) {\n checkArguments(\"AIGNE.addAgent\", aigneAddAgentArgsSchema, agents);\n\n for (const agent of agents) {\n this.agents.push(agent);\n\n agent.attach(this);\n }\n }\n\n /**\n * Creates a new execution context for this AIGNE instance.\n * Contexts isolate state for different flows or conversations.\n *\n * @returns A new AIGNEContext instance bound to this AIGNE.\n */\n newContext(options?: Partial<Pick<Context, \"userContext\" | \"memories\">>) {\n const context = new AIGNEContext(this);\n\n if (options?.userContext) context.userContext = options.userContext;\n if (options?.memories) context.memories = options.memories;\n\n return context;\n }\n\n /**\n * Creates a user agent for consistent interactions with a specified agent.\n * This method allows you to create a wrapper around an agent for repeated invocations.\n *\n * @param agent - Target agent to be wrapped for consistent invocation\n * @returns A user agent instance that provides a convenient interface for interacting with the target agent\n *\n * @example\n * Here's an example of how to create a user agent and invoke it consistently:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-user-agent}\n */\n invoke<I extends Message, O extends Message>(agent: Agent<I, O>): UserAgent<I, O>;\n\n /**\n * Invokes an agent with a message and returns both the output and the active agent.\n * This overload is useful when you need to track which agent was ultimately responsible for generating the response.\n *\n * @param agent - Target agent to invoke\n * @param message - Input message to send to the agent\n * @param options.returnActiveAgent - Must be true to return the final active agent\n * @param options.streaming - Must be false to return a response stream\n * @returns A promise resolving to a tuple containing the agent's response and the final active agent\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message: I & Message,\n options: InvokeOptions<U> & { returnActiveAgent: true; streaming?: false },\n ): Promise<[O, Agent]>;\n\n /**\n * Invokes an agent with a message and returns both a stream of the response and the active agent.\n * This overload is useful when you need streaming responses while also tracking which agent provided them.\n *\n * @param agent - Target agent to invoke\n * @param message - Input message to send to the agent\n * @param options.returnActiveAgent - Must be true to return the final active agent\n * @param options.streaming - Must be true to return a response stream\n * @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message: I & Message,\n options: InvokeOptions<U> & { returnActiveAgent: true; streaming: true },\n ): Promise<[AgentResponseStream<O>, Promise<Agent>]>;\n\n /**\n * Invokes an agent with a message and returns just the output.\n * This is the standard way to invoke an agent when you only need the response.\n *\n * @param agent - Target agent to invoke\n * @param message - Input message to send to the agent\n * @param options - Optional configuration parameters for the invocation\n * @returns A promise resolving to the agent's complete response\n *\n * @example\n * Here's a simple example of how to invoke an agent:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-simple}\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message: I & Message,\n options?: InvokeOptions<U> & { returnActiveAgent?: false; streaming?: false },\n ): Promise<O>;\n\n /**\n * Invokes an agent with a message and returns a stream of the response.\n * This allows processing the response incrementally as it's being generated.\n *\n * @param agent - Target agent to invoke\n * @param message - Input message to send to the agent\n * @param options - Configuration with streaming enabled to receive incremental response chunks\n * @returns A promise resolving to a stream of the agent's response that can be consumed incrementally\n *\n * @example\n * Here's an example of how to invoke an agent with streaming response:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message: I & Message,\n options: InvokeOptions<U> & { returnActiveAgent?: false; streaming: true },\n ): Promise<AgentResponseStream<O>>;\n\n /**\n * General implementation signature that handles all overload cases.\n * This unified signature supports all the different invocation patterns defined by the overloads.\n *\n * @param agent - Target agent to invoke or wrap\n * @param message - Optional input message to send to the agent\n * @param options - Optional configuration parameters for the invocation\n * @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response\n * with optional active agent information based on the provided options\n */\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message?: I & Message,\n options?: InvokeOptions<U>,\n ): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;\n\n invoke<I extends Message, O extends Message>(\n agent: Agent<I, O>,\n message?: I & Message,\n options?: InvokeOptions<U>,\n ): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]> {\n this.observer?.serve();\n const context = new AIGNEContext(this);\n return context.invoke(agent, message, { ...options, newContext: false });\n }\n\n /**\n * Publishes a message to the message queue for inter-agent communication.\n * This method broadcasts a message to all subscribers of the specified topic(s).\n * It creates a new context internally and delegates to the context's publish method.\n *\n * @param topic - The topic or array of topics to publish the message to\n * @param payload - The message payload to be delivered to subscribers\n * @param options - Optional configuration parameters for the publish operation\n *\n * @example\n * Here's an example of how to publish a message:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}\n */\n publish(\n topic: string | string[],\n payload: Omit<MessagePayload, \"context\"> | Message,\n options?: InvokeOptions<U>,\n ) {\n this.observer?.serve();\n return new AIGNEContext(this).publish(topic, payload, options);\n }\n\n /**\n * Subscribes to receive the next message on a specific topic.\n * This overload returns a Promise that resolves with the next message published to the topic.\n * It's useful for one-time message handling or when using async/await patterns.\n *\n * @param topic - The topic to subscribe to\n * @returns A Promise that resolves with the next message payload published to the specified topic\n *\n * @example\n * Here's an example of how to subscribe to a topic and receive the next message:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-publish-message}\n */\n subscribe(topic: string | string[], listener?: undefined): Promise<MessagePayload>;\n\n /**\n * Subscribes to messages on a specific topic with a listener callback.\n * This overload registers a listener function that will be called for each message published to the topic.\n * It's useful for continuous message handling or event-driven architectures.\n *\n * @param topic - The topic to subscribe to\n * @param listener - Callback function that will be invoked when messages arrive on the specified topic\n * @returns An Unsubscribe function that can be called to cancel the subscription\n *\n * @example\n * Here's an example of how to subscribe to a topic with a listener:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-subscribe-topic}\n */\n subscribe(topic: string | string[], listener: MessageQueueListener): Unsubscribe;\n\n /**\n * Generic subscribe signature that handles both Promise and listener patterns.\n * This is the implementation signature that supports both overloaded behaviors.\n *\n * @param topic - The topic to subscribe to\n * @param listener - Optional callback function\n * @returns Either a Promise for the next message or an Unsubscribe function\n */\n subscribe(\n topic: string | string[],\n listener?: MessageQueueListener,\n ): Unsubscribe | Promise<MessagePayload>;\n subscribe(\n topic: string | string[],\n listener?: MessageQueueListener,\n ): Unsubscribe | Promise<MessagePayload> {\n return this.messageQueue.subscribe(topic, listener);\n }\n\n /**\n * Unsubscribes a listener from a specific topic in the message queue.\n * This method stops a previously registered listener from receiving further messages.\n * It should be called when message processing is complete or when the component is no longer interested\n * in messages published to the specified topic.\n *\n * @param topic - The topic to unsubscribe from\n * @param listener - The listener function that was previously subscribed to the topic\n *\n * @example\n * {@includeCode ../../test/aigne/aigne.test.ts#example-subscribe-topic}\n */\n unsubscribe(topic: string | string[], listener: MessageQueueListener) {\n this.messageQueue.unsubscribe(topic, listener);\n }\n\n /**\n * Gracefully shuts down the AIGNE instance and all its agents and skills.\n * This ensures proper cleanup of resources before termination.\n *\n * @returns A promise that resolves when shutdown is complete.\n *\n * @example\n * Here's an example of shutdown an AIGNE instance:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-shutdown}\n */\n async shutdown() {\n // Close observer first to flush any pending traces\n await this.observer?.close(Array.from(this.contextIds));\n\n for (const tool of this.skills) {\n await tool.shutdown();\n }\n for (const agent of this.agents) {\n await agent.shutdown();\n }\n }\n\n /**\n * Asynchronous dispose method for the AIGNE instance.\n *\n * @example\n * Here's an example of using async dispose:\n * {@includeCode ../../test/aigne/aigne.test.ts#example-shutdown-using}\n */\n async [Symbol.asyncDispose]() {\n await this.shutdown();\n }\n\n /**\n * Initializes handlers for process exit events to ensure clean shutdown.\n * This registers handlers for SIGINT/SIGTERM to properly terminate all agents.\n * Note: 'exit' event cannot run async code, so we handle cleanup in signal handlers.\n */\n private initProcessExitHandler() {\n if (typeof process === \"undefined\") return;\n\n const originalExit = process.exit;\n\n // @ts-ignore\n process.exit = (...args) => {\n this.shutdown().finally(() => originalExit(...args));\n };\n\n const shutdownAndExit = () => this.shutdown().finally(() => originalExit(0));\n process.on(\"SIGINT\", shutdownAndExit);\n }\n}\n\nconst aigneOptionsSchema = z.object({\n model: z.custom<ChatModel>().optional(),\n imageModel: z.custom<ImageModel>().optional(),\n skills: z.array(z.custom<Agent>()).optional(),\n agents: z.array(z.custom<Agent>()).optional(),\n observer: z.custom<AIGNEObserver>().optional(),\n});\n\nconst aigneAddAgentArgsSchema = z.array(z.custom<Agent>());\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyFA,IAAa,QAAb,MAAa,MAA2C;;;;;;;;;CAStD,aAAa,KACX,MACA,UAA+D,EAAE,EACjD;EAChB,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,YAAY,GAAG,UAAU,MAAM,KAAK,MAAM,QAAQ;AAC3F,SAAO,IAAI,MAAM;GACf,GAAG;GACH,GAAG;GACH;GACA;GACA,QAAQ,OAAO,OAAO,SAAS,UAAU,EAAE,CAAC;GAC5C,QAAQ,OAAO,OAAO,SAAS,UAAU,EAAE,CAAC;GAC5C,UAAU,SAAS;GACpB,CAAC;;;;;;;CAQJ,YAAY,SAAwB;AAClC,MAAI,QAAS,gBAAe,SAAS,oBAAoB,QAAQ;AAEjE,OAAK,UAAU,SAAS;AACxB,OAAK,OAAO,SAAS;AACrB,OAAK,cAAc,SAAS;AAC5B,OAAK,QAAQ,SAAS;AACtB,OAAK,aAAa,SAAS;AAC3B,OAAK,SAAS,SAAS;AACvB,OAAK,WACH,QAAQ,IAAI,iCAAiC,SACzC,SACC,SAAS,YAAY,IAAI,eAAe;AAC/C,MAAI,SAAS,QAAQ,OAAQ,MAAK,OAAO,KAAK,GAAG,QAAQ,OAAO;AAChE,MAAI,SAAS,QAAQ,OAAQ,MAAK,SAAS,GAAG,QAAQ,OAAO;AAC7D,MAAI,SAAS,WAAW,QAAQ,OAAQ,MAAK,UAAU,OAAO,KAAK,G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,QAAQ,OAAO,SAAS,QAAQ;;CA4ChE,UACE,OACA,UACuC;AACvC,SAAO,KAAK,aAAa,UAAU,OAAO,SAAS;;;;;;;;;;;;;;CAerD,YAAY,OAA0B,UAAgC;AACpE,OAAK,aAAa,YAAY,OAAO,SAAS;;;;;;;;;;;;CAahD,MAAM,WAAW;AAEf,QAAM,KAAK,UAAU,MAAM,MAAM,KAAK,KAAK,WAAW,CAAC;AAEvD,OAAK,MAAM,QAAQ,KAAK,OACtB,OAAM,KAAK,UAAU;AAEvB,OAAK,MAAM,SAAS,KAAK,OACvB,OAAM,MAAM,UAAU;;;;;;;;;CAW1B,OAAO,OAAO,gBAAgB;AAC5B,QAAM,KAAK,UAAU;;;;;;;CAQvB,AAAQ,yBAAyB;AAC/B,MAAI,OAAO,YAAY,YAAa;EAEpC,MAAM,eAAe,QAAQ;AAG7B,UAAQ,QAAQ,GAAG,SAAS;AAC1B,QAAK,UAAU,CAAC,cAAc,aAAa,GAAG,KAAK,CAAC;;EAGtD,MAAM,wBAAwB,KAAK,UAAU,CAAC,cAAc,aAAa,EAAE,CAAC;AAC5E,UAAQ,GAAG,UAAU,gBAAgB;;;AAIzC,MAAM,qBAAqBA,IAAE,OAAO;CAClC,OAAOA,IAAE,QAAmB,CAAC,UAAU;CACvC,YAAYA,IAAE,QAAoB,CAAC,UAAU;CAC7C,QAAQA,IAAE,MAAMA,IAAE,QAAe,CAAC,CAAC,UAAU;CAC7C,QAAQA,IAAE,MAAMA,IAAE,QAAe,CAAC,CAAC,UAAU;CAC7C,UAAUA,IAAE,QAAuB,CAAC,UAAU;CAC/C,CAAC;AAEF,MAAM,0BAA0BA,IAAE,MAAMA,IAAE,QAAe,CAAC"}
@@ -3,7 +3,7 @@ import { LoadOptions } from "./index.cjs";
3
3
  import { AgentSchema } from "./agent-yaml.cjs";
4
4
 
5
5
  //#region src/loader/agent-js.d.ts
6
- declare function loadAgentFromJsFile(path: string, options: LoadOptions): Promise<Agent<any, any> | AgentSchema>;
6
+ declare function loadAgentFromJsFile(path: string, options: LoadOptions): Promise<AgentSchema | Agent<any, any>>;
7
7
  //#endregion
8
8
  export { loadAgentFromJsFile };
9
9
  //# sourceMappingURL=agent-js.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-js.d.cts","names":[],"sources":["../../src/loader/agent-js.ts"],"mappings":";;;;;iBASsB,mBAAA,CAAA,IAAA,UAAA,OAAA,EAA2C,WAAA,GAAW,OAAA,CAAA,KAAA,aAAA,WAAA"}
1
+ {"version":3,"file":"agent-js.d.cts","names":[],"sources":["../../src/loader/agent-js.ts"],"mappings":";;;;;iBASsB,mBAAA,CAAA,IAAA,UAAA,OAAA,EAA2C,WAAA,GAAW,OAAA,CAAA,WAAA,GAAA,KAAA"}
@@ -141,6 +141,8 @@ declare const aigneFileSchema: z.ZodObject<{
141
141
  chat?: string | undefined;
142
142
  } | undefined>;
143
143
  }, "strip", z.ZodTypeAny, {
144
+ name?: string | undefined;
145
+ description?: string | undefined;
144
146
  model?: z.objectInputType<{
145
147
  model: ZodType<string | {
146
148
  $get: string;
@@ -173,8 +175,6 @@ declare const aigneFileSchema: z.ZodObject<{
173
175
  $get: string;
174
176
  } | undefined>;
175
177
  }, z.ZodTypeAny, "passthrough"> | undefined;
176
- name?: string | undefined;
177
- description?: string | undefined;
178
178
  imageModel?: z.objectInputType<{
179
179
  model: ZodType<string | {
180
180
  $get: string;
@@ -193,6 +193,8 @@ declare const aigneFileSchema: z.ZodObject<{
193
193
  chat?: string | undefined;
194
194
  } | undefined;
195
195
  }, {
196
+ name?: string | undefined;
197
+ description?: string | undefined;
196
198
  model?: z.objectInputType<{
197
199
  model: ZodType<string | {
198
200
  $get: string;
@@ -225,8 +227,6 @@ declare const aigneFileSchema: z.ZodObject<{
225
227
  $get: string;
226
228
  } | undefined>;
227
229
  }, z.ZodTypeAny, "passthrough"> | undefined;
228
- name?: string | undefined;
229
- description?: string | undefined;
230
230
  imageModel?: z.objectInputType<{
231
231
  model: ZodType<string | {
232
232
  $get: string;
@@ -141,6 +141,8 @@ declare const aigneFileSchema: z$1.ZodObject<{
141
141
  chat?: string | undefined;
142
142
  } | undefined>;
143
143
  }, "strip", z$1.ZodTypeAny, {
144
+ name?: string | undefined;
145
+ description?: string | undefined;
144
146
  model?: z$1.objectInputType<{
145
147
  model: ZodType<string | {
146
148
  $get: string;
@@ -173,8 +175,6 @@ declare const aigneFileSchema: z$1.ZodObject<{
173
175
  $get: string;
174
176
  } | undefined>;
175
177
  }, z$1.ZodTypeAny, "passthrough"> | undefined;
176
- name?: string | undefined;
177
- description?: string | undefined;
178
178
  imageModel?: z$1.objectInputType<{
179
179
  model: ZodType<string | {
180
180
  $get: string;
@@ -193,6 +193,8 @@ declare const aigneFileSchema: z$1.ZodObject<{
193
193
  chat?: string | undefined;
194
194
  } | undefined;
195
195
  }, {
196
+ name?: string | undefined;
197
+ description?: string | undefined;
196
198
  model?: z$1.objectInputType<{
197
199
  model: ZodType<string | {
198
200
  $get: string;
@@ -225,8 +227,6 @@ declare const aigneFileSchema: z$1.ZodObject<{
225
227
  $get: string;
226
228
  } | undefined>;
227
229
  }, z$1.ZodTypeAny, "passthrough"> | undefined;
228
- name?: string | undefined;
229
- description?: string | undefined;
230
230
  imageModel?: z$1.objectInputType<{
231
231
  model: ZodType<string | {
232
232
  $get: string;
@@ -5,7 +5,7 @@ front_matter = require_rolldown_runtime.__toESM(front_matter);
5
5
 
6
6
  //#region src/prompt/skills/afs/agent-skill/skill-loader.ts
7
7
  function parseSkill(content, path) {
8
- const meta = front_matter.default.default(content);
8
+ const meta = (0, front_matter.default)(content);
9
9
  return {
10
10
  path,
11
11
  name: meta.attributes.name,
@@ -3,7 +3,7 @@ import fm from "front-matter";
3
3
 
4
4
  //#region src/prompt/skills/afs/agent-skill/skill-loader.ts
5
5
  function parseSkill(content, path) {
6
- const meta = fm.default(content);
6
+ const meta = fm(content);
7
7
  return {
8
8
  path,
9
9
  name: meta.attributes.name,
@@ -1 +1 @@
1
- {"version":3,"file":"skill-loader.mjs","names":[],"sources":["../../../../../src/prompt/skills/afs/agent-skill/skill-loader.ts"],"sourcesContent":["import type { AFS, AFSEntry } from \"@aigne/afs\";\nimport fm from \"front-matter\";\nimport { AgentSkill } from \"./agent-skill.js\";\n\nexport interface Skill {\n path: string;\n name: string;\n description: string;\n content: string;\n}\n\nfunction parseSkill(content: string, path: string): Skill {\n const meta = fm.default<{ name: string; description: string }>(content);\n\n return {\n path,\n name: meta.attributes.name as string,\n description: meta.attributes.description as string,\n content: meta.body,\n };\n}\n\nexport async function discoverSkillsFromAFS(afs: AFS): Promise<Skill[]> {\n const modules = await afs.listModules();\n const filtered = modules.filter(({ module: m }) => m.agentSkills === true);\n if (!filtered.length) return [];\n\n const skills: Skill[] = [];\n for (const module of filtered) {\n const data: AFSEntry[] = (\n await afs\n .list(module.path, {\n pattern: \"**/SKILL.md\",\n maxDepth: 10,\n })\n .catch(() => ({ data: [] }))\n ).data;\n\n for (const entry of data) {\n const { data: file } = await afs.read(entry.path);\n if (typeof file?.content !== \"string\") continue;\n\n const dirname = entry.path.split(\"/\").slice(0, -1).join(\"/\");\n\n const skill = parseSkill(file.content, dirname);\n skills.push(skill);\n }\n }\n\n return skills;\n}\n\nexport async function loadAgentSkillFromAFS({\n afs,\n}: {\n afs: AFS;\n}): Promise<AgentSkill | undefined> {\n const skills = await discoverSkillsFromAFS(afs);\n if (!skills.length) return;\n\n return new AgentSkill({\n agentSkills: skills,\n });\n}\n"],"mappings":";;;;AAWA,SAAS,WAAW,SAAiB,MAAqB;CACxD,MAAM,OAAO,GAAG,QAA+C,QAAQ;AAEvE,QAAO;EACL;EACA,MAAM,KAAK,WAAW;EACtB,aAAa,KAAK,WAAW;EAC7B,SAAS,KAAK;EACf;;AAGH,eAAsB,sBAAsB,KAA4B;CAEtE,MAAM,YADU,MAAM,IAAI,aAAa,EACd,QAAQ,EAAE,QAAQ,QAAQ,EAAE,gBAAgB,KAAK;AAC1E,KAAI,CAAC,SAAS,OAAQ,QAAO,EAAE;CAE/B,MAAM,SAAkB,EAAE;AAC1B,MAAK,MAAM,UAAU,UAAU;EAC7B,MAAM,QACJ,MAAM,IACH,KAAK,OAAO,MAAM;GACjB,SAAS;GACT,UAAU;GACX,CAAC,CACD,aAAa,EAAE,MAAM,EAAE,EAAE,EAAE,EAC9B;AAEF,OAAK,MAAM,SAAS,MAAM;GACxB,MAAM,EAAE,MAAM,SAAS,MAAM,IAAI,KAAK,MAAM,KAAK;AACjD,OAAI,OAAO,MAAM,YAAY,SAAU;GAEvC,MAAM,UAAU,MAAM,KAAK,MAAM,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,IAAI;GAE5D,MAAM,QAAQ,WAAW,KAAK,SAAS,QAAQ;AAC/C,UAAO,KAAK,MAAM;;;AAItB,QAAO;;AAGT,eAAsB,sBAAsB,EAC1C,OAGkC;CAClC,MAAM,SAAS,MAAM,sBAAsB,IAAI;AAC/C,KAAI,CAAC,OAAO,OAAQ;AAEpB,QAAO,IAAI,WAAW,EACpB,aAAa,QACd,CAAC"}
1
+ {"version":3,"file":"skill-loader.mjs","names":[],"sources":["../../../../../src/prompt/skills/afs/agent-skill/skill-loader.ts"],"sourcesContent":["import type { AFS, AFSEntry } from \"@aigne/afs\";\nimport fm from \"front-matter\";\nimport { AgentSkill } from \"./agent-skill.js\";\n\nexport interface Skill {\n path: string;\n name: string;\n description: string;\n content: string;\n}\n\nfunction parseSkill(content: string, path: string): Skill {\n const meta = fm<{ name: string; description: string }>(content);\n\n return {\n path,\n name: meta.attributes.name as string,\n description: meta.attributes.description as string,\n content: meta.body,\n };\n}\n\nexport async function discoverSkillsFromAFS(afs: AFS): Promise<Skill[]> {\n const modules = await afs.listModules();\n const filtered = modules.filter(({ module: m }) => m.agentSkills === true);\n if (!filtered.length) return [];\n\n const skills: Skill[] = [];\n for (const module of filtered) {\n const data: AFSEntry[] = (\n await afs\n .list(module.path, {\n pattern: \"**/SKILL.md\",\n maxDepth: 10,\n })\n .catch(() => ({ data: [] }))\n ).data;\n\n for (const entry of data) {\n const { data: file } = await afs.read(entry.path);\n if (typeof file?.content !== \"string\") continue;\n\n const dirname = entry.path.split(\"/\").slice(0, -1).join(\"/\");\n\n const skill = parseSkill(file.content, dirname);\n skills.push(skill);\n }\n }\n\n return skills;\n}\n\nexport async function loadAgentSkillFromAFS({\n afs,\n}: {\n afs: AFS;\n}): Promise<AgentSkill | undefined> {\n const skills = await discoverSkillsFromAFS(afs);\n if (!skills.length) return;\n\n return new AgentSkill({\n agentSkills: skills,\n });\n}\n"],"mappings":";;;;AAWA,SAAS,WAAW,SAAiB,MAAqB;CACxD,MAAM,OAAO,GAA0C,QAAQ;AAE/D,QAAO;EACL;EACA,MAAM,KAAK,WAAW;EACtB,aAAa,KAAK,WAAW;EAC7B,SAAS,KAAK;EACf;;AAGH,eAAsB,sBAAsB,KAA4B;CAEtE,MAAM,YADU,MAAM,IAAI,aAAa,EACd,QAAQ,EAAE,QAAQ,QAAQ,EAAE,gBAAgB,KAAK;AAC1E,KAAI,CAAC,SAAS,OAAQ,QAAO,EAAE;CAE/B,MAAM,SAAkB,EAAE;AAC1B,MAAK,MAAM,UAAU,UAAU;EAC7B,MAAM,QACJ,MAAM,IACH,KAAK,OAAO,MAAM;GACjB,SAAS;GACT,UAAU;GACX,CAAC,CACD,aAAa,EAAE,MAAM,EAAE,EAAE,EAAE,EAC9B;AAEF,OAAK,MAAM,SAAS,MAAM;GACxB,MAAM,EAAE,MAAM,SAAS,MAAM,IAAI,KAAK,MAAM,KAAK;AACjD,OAAI,OAAO,MAAM,YAAY,SAAU;GAEvC,MAAM,UAAU,MAAM,KAAK,MAAM,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,IAAI;GAE5D,MAAM,QAAQ,WAAW,KAAK,SAAS,QAAQ;AAC/C,UAAO,KAAK,MAAM;;;AAItB,QAAO;;AAGT,eAAsB,sBAAsB,EAC1C,OAGkC;CAClC,MAAM,SAAS,MAAM,sBAAsB,IAAI;AAC/C,KAAI,CAAC,OAAO,OAAQ;AAEpB,QAAO,IAAI,WAAW,EACpB,aAAa,QACd,CAAC"}
@@ -44,7 +44,7 @@ declare class AgentMessageTemplate extends ChatMessageTemplate {
44
44
  static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): AgentMessageTemplate;
45
45
  constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
46
46
  format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
47
- role: "agent" | "user" | "system" | "tool";
47
+ role: "system" | "user" | "agent" | "tool";
48
48
  name: string | undefined;
49
49
  content: ChatModelInputMessageContent | undefined;
50
50
  toolCalls: ChatModelOutputToolCall[] | undefined;
@@ -56,7 +56,7 @@ declare class ToolMessageTemplate extends ChatMessageTemplate {
56
56
  static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): ToolMessageTemplate;
57
57
  constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
58
58
  format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
59
- role: "agent" | "user" | "system" | "tool";
59
+ role: "system" | "user" | "agent" | "tool";
60
60
  name: string | undefined;
61
61
  content: ChatModelInputMessageContent | undefined;
62
62
  toolCallId: string;
@@ -85,16 +85,16 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
85
85
  ttl?: "5m" | "1h" | undefined;
86
86
  }>>;
87
87
  }, "strip", z.ZodTypeAny, {
88
- content: string;
89
88
  role: "system";
89
+ content: string;
90
90
  name?: string | undefined;
91
91
  cacheControl?: {
92
92
  type: "ephemeral";
93
93
  ttl?: "5m" | "1h" | undefined;
94
94
  } | undefined;
95
95
  }, {
96
- content: string;
97
96
  role: "system";
97
+ content: string;
98
98
  name?: string | undefined;
99
99
  cacheControl?: {
100
100
  type: "ephemeral";
@@ -115,16 +115,16 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
115
115
  ttl?: "5m" | "1h" | undefined;
116
116
  }>>;
117
117
  }, "strip", z.ZodTypeAny, {
118
- content: string;
119
118
  role: "user";
119
+ content: string;
120
120
  name?: string | undefined;
121
121
  cacheControl?: {
122
122
  type: "ephemeral";
123
123
  ttl?: "5m" | "1h" | undefined;
124
124
  } | undefined;
125
125
  }, {
126
- content: string;
127
126
  role: "user";
127
+ content: string;
128
128
  name?: string | undefined;
129
129
  cacheControl?: {
130
130
  type: "ephemeral";
@@ -174,8 +174,8 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
174
174
  }>>;
175
175
  }, "strip", z.ZodTypeAny, {
176
176
  role: "agent";
177
- content?: string | undefined;
178
177
  name?: string | undefined;
178
+ content?: string | undefined;
179
179
  cacheControl?: {
180
180
  type: "ephemeral";
181
181
  ttl?: "5m" | "1h" | undefined;
@@ -190,8 +190,8 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
190
190
  }[] | undefined;
191
191
  }, {
192
192
  role: "agent";
193
- content?: string | undefined;
194
193
  name?: string | undefined;
194
+ content?: string | undefined;
195
195
  cacheControl?: {
196
196
  type: "ephemeral";
197
197
  ttl?: "5m" | "1h" | undefined;
@@ -220,8 +220,8 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
220
220
  ttl?: "5m" | "1h" | undefined;
221
221
  }>>;
222
222
  }, "strip", z.ZodTypeAny, {
223
- content: string;
224
223
  role: "tool";
224
+ content: string;
225
225
  toolCallId: string;
226
226
  name?: string | undefined;
227
227
  cacheControl?: {
@@ -229,8 +229,8 @@ declare const chatMessageSchema: z.ZodUnion<[z.ZodObject<{
229
229
  ttl?: "5m" | "1h" | undefined;
230
230
  } | undefined;
231
231
  }, {
232
- content: string | Record<string, unknown>;
233
232
  role: "tool";
233
+ content: string | Record<string, unknown>;
234
234
  toolCallId: string;
235
235
  name?: string | undefined;
236
236
  cacheControl?: {
@@ -44,7 +44,7 @@ declare class AgentMessageTemplate extends ChatMessageTemplate {
44
44
  static from(template?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[], name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): AgentMessageTemplate;
45
45
  constructor(content?: ChatModelInputMessage["content"], toolCalls?: ChatModelOutputToolCall[] | undefined, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
46
46
  format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
47
- role: "agent" | "user" | "system" | "tool";
47
+ role: "system" | "user" | "agent" | "tool";
48
48
  name: string | undefined;
49
49
  content: ChatModelInputMessageContent | undefined;
50
50
  toolCalls: ChatModelOutputToolCall[] | undefined;
@@ -56,7 +56,7 @@ declare class ToolMessageTemplate extends ChatMessageTemplate {
56
56
  static from(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]): ToolMessageTemplate;
57
57
  constructor(content: object | string, toolCallId: string, name?: string, options?: FormatOptions, cacheControl?: ChatModelInputMessage["cacheControl"]);
58
58
  format(_variables?: Record<string, unknown>, _options?: FormatOptions): Promise<{
59
- role: "agent" | "user" | "system" | "tool";
59
+ role: "system" | "user" | "agent" | "tool";
60
60
  name: string | undefined;
61
61
  content: ChatModelInputMessageContent | undefined;
62
62
  toolCallId: string;
@@ -85,16 +85,16 @@ declare const chatMessageSchema: z$1.ZodUnion<[z$1.ZodObject<{
85
85
  ttl?: "5m" | "1h" | undefined;
86
86
  }>>;
87
87
  }, "strip", z$1.ZodTypeAny, {
88
- content: string;
89
88
  role: "system";
89
+ content: string;
90
90
  name?: string | undefined;
91
91
  cacheControl?: {
92
92
  type: "ephemeral";
93
93
  ttl?: "5m" | "1h" | undefined;
94
94
  } | undefined;
95
95
  }, {
96
- content: string;
97
96
  role: "system";
97
+ content: string;
98
98
  name?: string | undefined;
99
99
  cacheControl?: {
100
100
  type: "ephemeral";
@@ -115,16 +115,16 @@ declare const chatMessageSchema: z$1.ZodUnion<[z$1.ZodObject<{
115
115
  ttl?: "5m" | "1h" | undefined;
116
116
  }>>;
117
117
  }, "strip", z$1.ZodTypeAny, {
118
- content: string;
119
118
  role: "user";
119
+ content: string;
120
120
  name?: string | undefined;
121
121
  cacheControl?: {
122
122
  type: "ephemeral";
123
123
  ttl?: "5m" | "1h" | undefined;
124
124
  } | undefined;
125
125
  }, {
126
- content: string;
127
126
  role: "user";
127
+ content: string;
128
128
  name?: string | undefined;
129
129
  cacheControl?: {
130
130
  type: "ephemeral";
@@ -174,8 +174,8 @@ declare const chatMessageSchema: z$1.ZodUnion<[z$1.ZodObject<{
174
174
  }>>;
175
175
  }, "strip", z$1.ZodTypeAny, {
176
176
  role: "agent";
177
- content?: string | undefined;
178
177
  name?: string | undefined;
178
+ content?: string | undefined;
179
179
  cacheControl?: {
180
180
  type: "ephemeral";
181
181
  ttl?: "5m" | "1h" | undefined;
@@ -190,8 +190,8 @@ declare const chatMessageSchema: z$1.ZodUnion<[z$1.ZodObject<{
190
190
  }[] | undefined;
191
191
  }, {
192
192
  role: "agent";
193
- content?: string | undefined;
194
193
  name?: string | undefined;
194
+ content?: string | undefined;
195
195
  cacheControl?: {
196
196
  type: "ephemeral";
197
197
  ttl?: "5m" | "1h" | undefined;
@@ -220,8 +220,8 @@ declare const chatMessageSchema: z$1.ZodUnion<[z$1.ZodObject<{
220
220
  ttl?: "5m" | "1h" | undefined;
221
221
  }>>;
222
222
  }, "strip", z$1.ZodTypeAny, {
223
- content: string;
224
223
  role: "tool";
224
+ content: string;
225
225
  toolCallId: string;
226
226
  name?: string | undefined;
227
227
  cacheControl?: {
@@ -229,8 +229,8 @@ declare const chatMessageSchema: z$1.ZodUnion<[z$1.ZodObject<{
229
229
  ttl?: "5m" | "1h" | undefined;
230
230
  } | undefined;
231
231
  }, {
232
- content: string | Record<string, unknown>;
233
232
  role: "tool";
233
+ content: string | Record<string, unknown>;
234
234
  toolCallId: string;
235
235
  name?: string | undefined;
236
236
  cacheControl?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.74.0-beta",
3
+ "version": "1.74.0-beta.2",
4
4
  "description": "The functional core of agentic AI",
5
5
  "license": "Elastic-2.0",
6
6
  "publishConfig": {
@@ -175,8 +175,8 @@
175
175
  "zod": "^3.25.67",
176
176
  "zod-from-json-schema": "^0.0.5",
177
177
  "zod-to-json-schema": "^3.24.6",
178
- "@aigne/afs-history": "^1.74.0-beta",
179
- "@aigne/utils": "^1.74.0-beta"
178
+ "@aigne/utils": "^1.74.0-beta.2",
179
+ "@aigne/afs-history": "^1.74.0-beta.2"
180
180
  },
181
181
  "devDependencies": {
182
182
  "@types/bun": "^1.3.6",