@aigne/core 1.72.0 → 1.74.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/agents/agent.cjs +874 -0
- package/dist/agents/agent.d.cts +967 -0
- package/dist/agents/agent.d.cts.map +1 -0
- package/dist/agents/agent.d.mts +967 -0
- package/dist/agents/agent.d.mts.map +1 -0
- package/dist/agents/agent.mjs +863 -0
- package/dist/agents/agent.mjs.map +1 -0
- package/dist/agents/ai-agent.cjs +524 -0
- package/dist/agents/ai-agent.d.cts +401 -0
- package/dist/agents/ai-agent.d.cts.map +1 -0
- package/dist/agents/ai-agent.d.mts +401 -0
- package/dist/agents/ai-agent.d.mts.map +1 -0
- package/dist/agents/ai-agent.mjs +519 -0
- package/dist/agents/ai-agent.mjs.map +1 -0
- package/dist/agents/chat-model.cjs +397 -0
- package/dist/agents/chat-model.d.cts +674 -0
- package/dist/agents/chat-model.d.cts.map +1 -0
- package/dist/agents/chat-model.d.mts +674 -0
- package/dist/agents/chat-model.d.mts.map +1 -0
- package/dist/agents/chat-model.mjs +391 -0
- package/dist/agents/chat-model.mjs.map +1 -0
- package/dist/agents/guide-rail-agent.cjs +17 -0
- package/dist/agents/guide-rail-agent.d.cts +67 -0
- package/dist/agents/guide-rail-agent.d.cts.map +1 -0
- package/dist/agents/guide-rail-agent.d.mts +67 -0
- package/dist/agents/guide-rail-agent.d.mts.map +1 -0
- package/dist/agents/guide-rail-agent.mjs +17 -0
- package/dist/agents/guide-rail-agent.mjs.map +1 -0
- package/dist/agents/image-agent.cjs +74 -0
- package/dist/agents/image-agent.d.cts +44 -0
- package/dist/agents/image-agent.d.cts.map +1 -0
- package/dist/agents/image-agent.d.mts +44 -0
- package/dist/agents/image-agent.d.mts.map +1 -0
- package/dist/agents/image-agent.mjs +72 -0
- package/dist/agents/image-agent.mjs.map +1 -0
- package/dist/agents/image-model.cjs +83 -0
- package/dist/agents/image-model.d.cts +276 -0
- package/dist/agents/image-model.d.cts.map +1 -0
- package/dist/agents/image-model.d.mts +276 -0
- package/dist/agents/image-model.d.mts.map +1 -0
- package/dist/agents/image-model.mjs +81 -0
- package/dist/agents/image-model.mjs.map +1 -0
- package/dist/agents/mcp-agent.cjs +307 -0
- package/dist/agents/mcp-agent.d.cts +235 -0
- package/dist/agents/mcp-agent.d.cts.map +1 -0
- package/dist/agents/mcp-agent.d.mts +235 -0
- package/dist/agents/mcp-agent.d.mts.map +1 -0
- package/dist/agents/mcp-agent.mjs +303 -0
- package/dist/agents/mcp-agent.mjs.map +1 -0
- package/dist/agents/model.cjs +143 -0
- package/dist/agents/model.d.cts +257 -0
- package/dist/agents/model.d.cts.map +1 -0
- package/dist/agents/model.d.mts +257 -0
- package/dist/agents/model.d.mts.map +1 -0
- package/dist/agents/model.mjs +136 -0
- package/dist/agents/model.mjs.map +1 -0
- package/dist/agents/team-agent.cjs +342 -0
- package/dist/agents/team-agent.d.cts +390 -0
- package/dist/agents/team-agent.d.cts.map +1 -0
- package/dist/agents/team-agent.d.mts +390 -0
- package/dist/agents/team-agent.d.mts.map +1 -0
- package/dist/agents/team-agent.mjs +339 -0
- package/dist/agents/team-agent.mjs.map +1 -0
- package/dist/agents/transform-agent.cjs +77 -0
- package/dist/agents/transform-agent.d.cts +99 -0
- package/dist/agents/transform-agent.d.cts.map +1 -0
- package/dist/agents/transform-agent.d.mts +99 -0
- package/dist/agents/transform-agent.d.mts.map +1 -0
- package/dist/agents/transform-agent.mjs +76 -0
- package/dist/agents/transform-agent.mjs.map +1 -0
- package/dist/agents/types.cjs +30 -0
- package/dist/agents/types.d.cts +34 -0
- package/dist/agents/types.d.cts.map +1 -0
- package/dist/agents/types.d.mts +34 -0
- package/dist/agents/types.d.mts.map +1 -0
- package/dist/agents/types.mjs +25 -0
- package/dist/agents/types.mjs.map +1 -0
- package/dist/agents/user-agent.cjs +87 -0
- package/dist/agents/user-agent.d.cts +32 -0
- package/dist/agents/user-agent.d.cts.map +1 -0
- package/dist/agents/user-agent.d.mts +32 -0
- package/dist/agents/user-agent.d.mts.map +1 -0
- package/dist/agents/user-agent.mjs +88 -0
- package/dist/agents/user-agent.mjs.map +1 -0
- package/dist/agents/video-model.cjs +66 -0
- package/dist/agents/video-model.d.cts +286 -0
- package/dist/agents/video-model.d.cts.map +1 -0
- package/dist/agents/video-model.d.mts +286 -0
- package/dist/agents/video-model.d.mts.map +1 -0
- package/dist/agents/video-model.mjs +64 -0
- package/dist/agents/video-model.mjs.map +1 -0
- package/dist/aigne/aigne.cjs +235 -0
- package/dist/aigne/aigne.d.cts +340 -0
- package/dist/aigne/aigne.d.cts.map +1 -0
- package/dist/aigne/aigne.d.mts +340 -0
- package/dist/aigne/aigne.d.mts.map +1 -0
- package/dist/aigne/aigne.mjs +235 -0
- package/dist/aigne/aigne.mjs.map +1 -0
- package/dist/aigne/context.cjs +377 -0
- package/dist/aigne/context.d.cts +226 -0
- package/dist/aigne/context.d.cts.map +1 -0
- package/dist/aigne/context.d.mts +226 -0
- package/dist/aigne/context.d.mts.map +1 -0
- package/dist/aigne/context.mjs +376 -0
- package/dist/aigne/context.mjs.map +1 -0
- package/dist/aigne/index.cjs +4 -0
- package/dist/aigne/index.d.mts +5 -0
- package/dist/aigne/index.mjs +6 -0
- package/dist/aigne/message-queue.cjs +102 -0
- package/dist/aigne/message-queue.d.cts +52 -0
- package/dist/aigne/message-queue.d.cts.map +1 -0
- package/dist/aigne/message-queue.d.mts +52 -0
- package/dist/aigne/message-queue.d.mts.map +1 -0
- package/dist/aigne/message-queue.mjs +99 -0
- package/dist/aigne/message-queue.mjs.map +1 -0
- package/dist/aigne/type.d.cts +32 -0
- package/dist/aigne/type.d.cts.map +1 -0
- package/dist/aigne/type.d.mts +32 -0
- package/dist/aigne/type.d.mts.map +1 -0
- package/dist/aigne/usage.cjs +29 -0
- package/dist/aigne/usage.d.cts +32 -0
- package/dist/aigne/usage.d.cts.map +1 -0
- package/dist/aigne/usage.d.mts +32 -0
- package/dist/aigne/usage.d.mts.map +1 -0
- package/dist/aigne/usage.mjs +28 -0
- package/dist/aigne/usage.mjs.map +1 -0
- package/dist/index.cjs +142 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.mts +31 -0
- package/dist/index.mjs +31 -0
- package/dist/loader/agent-js.cjs +23 -0
- package/dist/loader/agent-js.d.cts +9 -0
- package/dist/loader/agent-js.d.cts.map +1 -0
- package/dist/loader/agent-js.d.mts +10 -0
- package/dist/loader/agent-js.d.mts.map +1 -0
- package/dist/loader/agent-js.mjs +23 -0
- package/dist/loader/agent-js.mjs.map +1 -0
- package/dist/loader/agent-yaml.cjs +109 -0
- package/dist/loader/agent-yaml.d.cts +87 -0
- package/dist/loader/agent-yaml.d.cts.map +1 -0
- package/dist/loader/agent-yaml.d.mts +87 -0
- package/dist/loader/agent-yaml.d.mts.map +1 -0
- package/dist/loader/agent-yaml.mjs +106 -0
- package/dist/loader/agent-yaml.mjs.map +1 -0
- package/dist/loader/agents.cjs +19 -0
- package/dist/loader/agents.d.cts +9 -0
- package/dist/loader/agents.d.cts.map +1 -0
- package/dist/loader/agents.d.mts +9 -0
- package/dist/loader/agents.d.mts.map +1 -0
- package/dist/loader/agents.mjs +20 -0
- package/dist/loader/agents.mjs.map +1 -0
- package/dist/loader/error.cjs +6 -0
- package/dist/loader/error.d.cts +5 -0
- package/dist/loader/error.d.cts.map +1 -0
- package/dist/loader/error.d.mts +5 -0
- package/dist/loader/error.d.mts.map +1 -0
- package/dist/loader/error.mjs +6 -0
- package/dist/loader/error.mjs.map +1 -0
- package/dist/loader/function-agent.cjs +9 -0
- package/dist/loader/function-agent.d.cts +7 -0
- package/dist/loader/function-agent.d.cts.map +1 -0
- package/dist/loader/function-agent.d.mts +7 -0
- package/dist/loader/function-agent.d.mts.map +1 -0
- package/dist/loader/function-agent.mjs +9 -0
- package/dist/loader/function-agent.mjs.map +1 -0
- package/dist/loader/index.cjs +233 -0
- package/dist/loader/index.d.cts +255 -0
- package/dist/loader/index.d.cts.map +1 -0
- package/dist/loader/index.d.mts +255 -0
- package/dist/loader/index.d.mts.map +1 -0
- package/dist/loader/index.mjs +228 -0
- package/dist/loader/index.mjs.map +1 -0
- package/dist/loader/schema.cjs +135 -0
- package/dist/loader/schema.d.cts +177 -0
- package/dist/loader/schema.d.cts.map +1 -0
- package/dist/loader/schema.d.mts +177 -0
- package/dist/loader/schema.d.mts.map +1 -0
- package/dist/loader/schema.mjs +127 -0
- package/dist/loader/schema.mjs.map +1 -0
- package/dist/memory/index.cjs +3 -0
- package/dist/memory/index.d.mts +3 -0
- package/dist/memory/index.mjs +5 -0
- package/dist/memory/memory.cjs +134 -0
- package/dist/memory/memory.d.cts +103 -0
- package/dist/memory/memory.d.cts.map +1 -0
- package/dist/memory/memory.d.mts +103 -0
- package/dist/memory/memory.d.mts.map +1 -0
- package/dist/memory/memory.mjs +133 -0
- package/dist/memory/memory.mjs.map +1 -0
- package/dist/memory/recorder.cjs +61 -0
- package/dist/memory/recorder.d.cts +98 -0
- package/dist/memory/recorder.d.cts.map +1 -0
- package/dist/memory/recorder.d.mts +98 -0
- package/dist/memory/recorder.d.mts.map +1 -0
- package/dist/memory/recorder.mjs +59 -0
- package/dist/memory/recorder.mjs.map +1 -0
- package/dist/memory/retriever.cjs +60 -0
- package/dist/memory/retriever.d.cts +111 -0
- package/dist/memory/retriever.d.cts.map +1 -0
- package/dist/memory/retriever.d.mts +111 -0
- package/dist/memory/retriever.d.mts.map +1 -0
- package/dist/memory/retriever.mjs +58 -0
- package/dist/memory/retriever.mjs.map +1 -0
- package/dist/prompt/agent-session.cjs +700 -0
- package/dist/prompt/agent-session.d.cts +167 -0
- package/dist/prompt/agent-session.d.cts.map +1 -0
- package/dist/prompt/agent-session.d.mts +167 -0
- package/dist/prompt/agent-session.d.mts.map +1 -0
- package/dist/prompt/agent-session.mjs +700 -0
- package/dist/prompt/agent-session.mjs.map +1 -0
- package/dist/prompt/compact/compactor.cjs +50 -0
- package/dist/prompt/compact/compactor.mjs +50 -0
- package/dist/prompt/compact/compactor.mjs.map +1 -0
- package/dist/prompt/compact/session-memory-extractor.cjs +137 -0
- package/dist/prompt/compact/session-memory-extractor.mjs +137 -0
- package/dist/prompt/compact/session-memory-extractor.mjs.map +1 -0
- package/dist/prompt/compact/types.cjs +59 -0
- package/dist/prompt/compact/types.d.cts +341 -0
- package/dist/prompt/compact/types.d.cts.map +1 -0
- package/dist/prompt/compact/types.d.mts +341 -0
- package/dist/prompt/compact/types.d.mts.map +1 -0
- package/dist/prompt/compact/types.mjs +49 -0
- package/dist/prompt/compact/types.mjs.map +1 -0
- package/dist/prompt/compact/user-memory-extractor.cjs +118 -0
- package/dist/prompt/compact/user-memory-extractor.mjs +118 -0
- package/dist/prompt/compact/user-memory-extractor.mjs.map +1 -0
- package/dist/prompt/context/afs/history.cjs +30 -0
- package/dist/prompt/context/afs/history.mjs +30 -0
- package/dist/prompt/context/afs/history.mjs.map +1 -0
- package/dist/prompt/context/afs/index.cjs +60 -0
- package/dist/prompt/context/afs/index.mjs +61 -0
- package/dist/prompt/context/afs/index.mjs.map +1 -0
- package/dist/prompt/context/index.cjs +18 -0
- package/dist/prompt/context/index.mjs +19 -0
- package/dist/prompt/context/index.mjs.map +1 -0
- package/dist/prompt/filters/index.cjs +22 -0
- package/dist/prompt/filters/index.mjs +21 -0
- package/dist/prompt/filters/index.mjs.map +1 -0
- package/dist/prompt/prompt-builder.cjs +291 -0
- package/dist/prompt/prompt-builder.d.cts +57 -0
- package/dist/prompt/prompt-builder.d.cts.map +1 -0
- package/dist/prompt/prompt-builder.d.mts +57 -0
- package/dist/prompt/prompt-builder.d.mts.map +1 -0
- package/dist/prompt/prompt-builder.mjs +291 -0
- package/dist/prompt/prompt-builder.mjs.map +1 -0
- package/dist/prompt/prompts/afs-builtin-prompt.cjs +12 -0
- package/dist/prompt/prompts/afs-builtin-prompt.mjs +13 -0
- package/dist/prompt/prompts/afs-builtin-prompt.mjs.map +1 -0
- package/dist/prompt/prompts/memory-message-template.cjs +10 -0
- package/dist/prompt/prompts/memory-message-template.mjs +10 -0
- package/dist/prompt/prompts/memory-message-template.mjs.map +1 -0
- package/dist/prompt/prompts/structured-stream-instructions.cjs +30 -0
- package/dist/prompt/prompts/structured-stream-instructions.mjs +30 -0
- package/dist/prompt/prompts/structured-stream-instructions.mjs.map +1 -0
- package/dist/prompt/skills/afs/agent-skill/agent-skill.cjs +66 -0
- package/dist/prompt/skills/afs/agent-skill/agent-skill.mjs +66 -0
- package/dist/prompt/skills/afs/agent-skill/agent-skill.mjs.map +1 -0
- package/dist/prompt/skills/afs/agent-skill/skill-loader.cjs +42 -0
- package/dist/prompt/skills/afs/agent-skill/skill-loader.mjs +41 -0
- package/dist/prompt/skills/afs/agent-skill/skill-loader.mjs.map +1 -0
- package/dist/prompt/skills/afs/base.cjs +9 -0
- package/dist/prompt/skills/afs/base.mjs +10 -0
- package/dist/prompt/skills/afs/base.mjs.map +1 -0
- package/dist/prompt/skills/afs/delete.cjs +50 -0
- package/dist/prompt/skills/afs/delete.mjs +50 -0
- package/dist/prompt/skills/afs/delete.mjs.map +1 -0
- package/dist/prompt/skills/afs/edit.cjs +92 -0
- package/dist/prompt/skills/afs/edit.mjs +92 -0
- package/dist/prompt/skills/afs/edit.mjs.map +1 -0
- package/dist/prompt/skills/afs/exec.cjs +36 -0
- package/dist/prompt/skills/afs/exec.mjs +36 -0
- package/dist/prompt/skills/afs/exec.mjs.map +1 -0
- package/dist/prompt/skills/afs/index.cjs +28 -0
- package/dist/prompt/skills/afs/index.mjs +29 -0
- package/dist/prompt/skills/afs/index.mjs.map +1 -0
- package/dist/prompt/skills/afs/list.cjs +69 -0
- package/dist/prompt/skills/afs/list.mjs +69 -0
- package/dist/prompt/skills/afs/list.mjs.map +1 -0
- package/dist/prompt/skills/afs/read.cjs +86 -0
- package/dist/prompt/skills/afs/read.mjs +86 -0
- package/dist/prompt/skills/afs/read.mjs.map +1 -0
- package/dist/prompt/skills/afs/rename.cjs +53 -0
- package/dist/prompt/skills/afs/rename.mjs +53 -0
- package/dist/prompt/skills/afs/rename.mjs.map +1 -0
- package/dist/prompt/skills/afs/search.cjs +63 -0
- package/dist/prompt/skills/afs/search.mjs +63 -0
- package/dist/prompt/skills/afs/search.mjs.map +1 -0
- package/dist/prompt/skills/afs/write.cjs +51 -0
- package/dist/prompt/skills/afs/write.mjs +51 -0
- package/dist/prompt/skills/afs/write.mjs.map +1 -0
- package/dist/prompt/template.cjs +229 -0
- package/dist/prompt/template.d.cts +247 -0
- package/dist/prompt/template.d.cts.map +1 -0
- package/dist/prompt/template.d.mts +247 -0
- package/dist/prompt/template.d.mts.map +1 -0
- package/dist/prompt/template.mjs +219 -0
- package/dist/prompt/template.mjs.map +1 -0
- package/dist/utils/agent-utils.cjs +49 -0
- package/dist/utils/agent-utils.d.cts +22 -0
- package/dist/utils/agent-utils.d.cts.map +1 -0
- package/dist/utils/agent-utils.d.mts +22 -0
- package/dist/utils/agent-utils.d.mts.map +1 -0
- package/dist/utils/agent-utils.mjs +46 -0
- package/dist/utils/agent-utils.mjs.map +1 -0
- package/dist/utils/camelize.cjs +34 -0
- package/dist/utils/camelize.d.cts +9 -0
- package/dist/utils/camelize.d.cts.map +1 -0
- package/dist/utils/camelize.d.mts +9 -0
- package/dist/utils/camelize.d.mts.map +1 -0
- package/dist/utils/camelize.mjs +33 -0
- package/dist/utils/camelize.mjs.map +1 -0
- package/dist/utils/event-stream.cjs +136 -0
- package/dist/utils/event-stream.d.cts +20 -0
- package/dist/utils/event-stream.d.cts.map +1 -0
- package/dist/utils/event-stream.d.mts +20 -0
- package/dist/utils/event-stream.d.mts.map +1 -0
- package/dist/utils/event-stream.mjs +133 -0
- package/dist/utils/event-stream.mjs.map +1 -0
- package/dist/utils/fetch.cjs +32 -0
- package/dist/utils/fetch.d.cts +8 -0
- package/dist/utils/fetch.d.cts.map +1 -0
- package/dist/utils/fetch.d.mts +8 -0
- package/dist/utils/fetch.d.mts.map +1 -0
- package/dist/utils/fetch.mjs +32 -0
- package/dist/utils/fetch.mjs.map +1 -0
- package/dist/utils/json-schema.cjs +107 -0
- package/dist/utils/json-schema.d.cts +20 -0
- package/dist/utils/json-schema.d.cts.map +1 -0
- package/dist/utils/json-schema.d.mts +20 -0
- package/dist/utils/json-schema.d.mts.map +1 -0
- package/dist/utils/json-schema.mjs +102 -0
- package/dist/utils/json-schema.mjs.map +1 -0
- package/dist/utils/json-utils.cjs +46 -0
- package/dist/utils/json-utils.d.cts +28 -0
- package/dist/utils/json-utils.d.cts.map +1 -0
- package/dist/utils/json-utils.d.mts +28 -0
- package/dist/utils/json-utils.d.mts.map +1 -0
- package/dist/utils/json-utils.mjs +44 -0
- package/dist/utils/json-utils.mjs.map +1 -0
- package/dist/utils/logger.cjs +72 -0
- package/dist/utils/logger.d.cts +41 -0
- package/dist/utils/logger.d.cts.map +1 -0
- package/dist/utils/logger.d.mts +41 -0
- package/dist/utils/logger.d.mts.map +1 -0
- package/dist/utils/logger.mjs +68 -0
- package/dist/utils/logger.mjs.map +1 -0
- package/dist/utils/mcp-utils.cjs +53 -0
- package/dist/utils/mcp-utils.d.cts +10 -0
- package/dist/utils/mcp-utils.d.cts.map +1 -0
- package/dist/utils/mcp-utils.d.mts +10 -0
- package/dist/utils/mcp-utils.d.mts.map +1 -0
- package/dist/utils/mcp-utils.mjs +51 -0
- package/dist/utils/mcp-utils.mjs.map +1 -0
- package/dist/utils/model-utils.cjs +12 -0
- package/dist/utils/model-utils.d.cts +8 -0
- package/dist/utils/model-utils.d.cts.map +1 -0
- package/dist/utils/model-utils.d.mts +8 -0
- package/dist/utils/model-utils.d.mts.map +1 -0
- package/dist/utils/model-utils.mjs +12 -0
- package/dist/utils/model-utils.mjs.map +1 -0
- package/dist/utils/promise.cjs +17 -0
- package/dist/utils/promise.d.cts +10 -0
- package/dist/utils/promise.d.cts.map +1 -0
- package/dist/utils/promise.d.mts +10 -0
- package/dist/utils/promise.d.mts.map +1 -0
- package/dist/utils/promise.mjs +17 -0
- package/dist/utils/promise.mjs.map +1 -0
- package/dist/utils/prompts.cjs +19 -0
- package/dist/utils/prompts.d.cts +6 -0
- package/dist/utils/prompts.d.cts.map +1 -0
- package/dist/utils/prompts.d.mts +6 -0
- package/dist/utils/prompts.d.mts.map +1 -0
- package/dist/utils/prompts.mjs +18 -0
- package/dist/utils/prompts.mjs.map +1 -0
- package/dist/utils/queue.cjs +273 -0
- package/dist/utils/queue.d.cts +60 -0
- package/dist/utils/queue.d.cts.map +1 -0
- package/dist/utils/queue.d.mts +60 -0
- package/dist/utils/queue.d.mts.map +1 -0
- package/dist/utils/queue.mjs +271 -0
- package/dist/utils/queue.mjs.map +1 -0
- package/dist/utils/role-utils.cjs +40 -0
- package/dist/utils/role-utils.d.cts +32 -0
- package/dist/utils/role-utils.d.cts.map +1 -0
- package/dist/utils/role-utils.d.mts +32 -0
- package/dist/utils/role-utils.d.mts.map +1 -0
- package/dist/utils/role-utils.mjs +38 -0
- package/dist/utils/role-utils.mjs.map +1 -0
- package/dist/utils/stream-polyfill.cjs +37 -0
- package/dist/utils/stream-polyfill.d.cts +1 -0
- package/dist/utils/stream-polyfill.d.mts +1 -0
- package/dist/utils/stream-polyfill.mjs +38 -0
- package/dist/utils/stream-polyfill.mjs.map +1 -0
- package/dist/utils/stream-utils.cjs +187 -0
- package/dist/utils/stream-utils.d.cts +30 -0
- package/dist/utils/stream-utils.d.cts.map +1 -0
- package/dist/utils/stream-utils.d.mts +30 -0
- package/dist/utils/stream-utils.d.mts.map +1 -0
- package/dist/utils/stream-utils.mjs +174 -0
- package/dist/utils/stream-utils.mjs.map +1 -0
- package/dist/utils/structured-stream-extractor.cjs +63 -0
- package/dist/utils/structured-stream-extractor.d.cts +23 -0
- package/dist/utils/structured-stream-extractor.d.cts.map +1 -0
- package/dist/utils/structured-stream-extractor.d.mts +23 -0
- package/dist/utils/structured-stream-extractor.d.mts.map +1 -0
- package/dist/utils/structured-stream-extractor.mjs +64 -0
- package/dist/utils/structured-stream-extractor.mjs.map +1 -0
- package/dist/utils/test/agent-response.cjs +16 -0
- package/dist/utils/test/agent-response.d.cts +12 -0
- package/dist/utils/test/agent-response.d.cts.map +1 -0
- package/dist/utils/test/agent-response.d.mts +13 -0
- package/dist/utils/test/agent-response.d.mts.map +1 -0
- package/dist/utils/test/agent-response.mjs +17 -0
- package/dist/utils/test/agent-response.mjs.map +1 -0
- package/dist/utils/test/openai-like-utils.cjs +73 -0
- package/dist/utils/test/openai-like-utils.d.cts +13 -0
- package/dist/utils/test/openai-like-utils.d.cts.map +1 -0
- package/dist/utils/test/openai-like-utils.d.mts +14 -0
- package/dist/utils/test/openai-like-utils.d.mts.map +1 -0
- package/dist/utils/test/openai-like-utils.mjs +68 -0
- package/dist/utils/test/openai-like-utils.mjs.map +1 -0
- package/dist/utils/token-estimator.cjs +57 -0
- package/dist/utils/token-estimator.d.cts +13 -0
- package/dist/utils/token-estimator.d.cts.map +1 -0
- package/dist/utils/token-estimator.d.mts +13 -0
- package/dist/utils/token-estimator.d.mts.map +1 -0
- package/dist/utils/token-estimator.mjs +57 -0
- package/dist/utils/token-estimator.mjs.map +1 -0
- package/dist/utils/type-utils.cjs +159 -0
- package/dist/utils/type-utils.d.cts +32 -0
- package/dist/utils/type-utils.d.cts.map +1 -0
- package/dist/utils/type-utils.d.mts +32 -0
- package/dist/utils/type-utils.d.mts.map +1 -0
- package/dist/utils/type-utils.mjs +141 -0
- package/dist/utils/type-utils.mjs.map +1 -0
- package/dist/utils/typed-event-emitter.cjs +0 -0
- package/dist/utils/typed-event-emitter.d.cts +13 -0
- package/dist/utils/typed-event-emitter.d.cts.map +1 -0
- package/dist/utils/typed-event-emitter.d.mts +13 -0
- package/dist/utils/typed-event-emitter.d.mts.map +1 -0
- package/dist/utils/typed-event-emitter.mjs +1 -0
- package/package.json +143 -62
- package/CHANGELOG.md +0 -2584
- package/lib/cjs/agents/agent.d.ts +0 -961
- package/lib/cjs/agents/agent.js +0 -961
- package/lib/cjs/agents/ai-agent.d.ts +0 -395
- package/lib/cjs/agents/ai-agent.js +0 -572
- package/lib/cjs/agents/chat-model.d.ts +0 -672
- package/lib/cjs/agents/chat-model.js +0 -457
- package/lib/cjs/agents/guide-rail-agent.d.ts +0 -62
- package/lib/cjs/agents/guide-rail-agent.js +0 -14
- package/lib/cjs/agents/image-agent.d.ts +0 -38
- package/lib/cjs/agents/image-agent.js +0 -71
- package/lib/cjs/agents/image-model.d.ts +0 -270
- package/lib/cjs/agents/image-model.js +0 -91
- package/lib/cjs/agents/mcp-agent.d.ts +0 -231
- package/lib/cjs/agents/mcp-agent.js +0 -366
- package/lib/cjs/agents/model.d.ts +0 -252
- package/lib/cjs/agents/model.js +0 -180
- package/lib/cjs/agents/team-agent.d.ts +0 -382
- package/lib/cjs/agents/team-agent.js +0 -386
- package/lib/cjs/agents/transform-agent.d.ts +0 -94
- package/lib/cjs/agents/transform-agent.js +0 -80
- package/lib/cjs/agents/types.d.ts +0 -31
- package/lib/cjs/agents/types.js +0 -40
- package/lib/cjs/agents/user-agent.d.ts +0 -27
- package/lib/cjs/agents/user-agent.js +0 -90
- package/lib/cjs/agents/video-model.d.ts +0 -280
- package/lib/cjs/agents/video-model.js +0 -67
- package/lib/cjs/aigne/aigne.d.ts +0 -335
- package/lib/cjs/aigne/aigne.js +0 -248
- package/lib/cjs/aigne/context.d.ts +0 -220
- package/lib/cjs/aigne/context.js +0 -423
- package/lib/cjs/aigne/index.d.ts +0 -4
- package/lib/cjs/aigne/index.js +0 -20
- package/lib/cjs/aigne/message-queue.d.ts +0 -48
- package/lib/cjs/aigne/message-queue.js +0 -109
- package/lib/cjs/aigne/type.d.ts +0 -26
- package/lib/cjs/aigne/type.js +0 -2
- package/lib/cjs/aigne/usage.d.ts +0 -28
- package/lib/cjs/aigne/usage.js +0 -34
- package/lib/cjs/index.d.ts +0 -21
- package/lib/cjs/index.js +0 -37
- package/lib/cjs/loader/agent-js.d.ts +0 -2
- package/lib/cjs/loader/agent-js.js +0 -21
- package/lib/cjs/loader/agent-yaml.d.ts +0 -78
- package/lib/cjs/loader/agent-yaml.js +0 -120
- package/lib/cjs/loader/agents.d.ts +0 -4
- package/lib/cjs/loader/agents.js +0 -17
- package/lib/cjs/loader/error.d.ts +0 -2
- package/lib/cjs/loader/error.js +0 -6
- package/lib/cjs/loader/function-agent.d.ts +0 -2
- package/lib/cjs/loader/function-agent.js +0 -7
- package/lib/cjs/loader/index.d.ts +0 -247
- package/lib/cjs/loader/index.js +0 -266
- package/lib/cjs/loader/schema.d.ts +0 -167
- package/lib/cjs/loader/schema.js +0 -162
- package/lib/cjs/memory/index.d.ts +0 -3
- package/lib/cjs/memory/index.js +0 -19
- package/lib/cjs/memory/memory.d.ts +0 -93
- package/lib/cjs/memory/memory.js +0 -147
- package/lib/cjs/memory/recorder.d.ts +0 -93
- package/lib/cjs/memory/recorder.js +0 -63
- package/lib/cjs/memory/retriever.d.ts +0 -106
- package/lib/cjs/memory/retriever.js +0 -60
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/prompt/agent-session.d.ts +0 -163
- package/lib/cjs/prompt/agent-session.js +0 -1008
- package/lib/cjs/prompt/compact/compactor.d.ts +0 -7
- package/lib/cjs/prompt/compact/compactor.js +0 -52
- package/lib/cjs/prompt/compact/session-memory-extractor.d.ts +0 -7
- package/lib/cjs/prompt/compact/session-memory-extractor.js +0 -143
- package/lib/cjs/prompt/compact/types.d.ts +0 -336
- package/lib/cjs/prompt/compact/types.js +0 -53
- package/lib/cjs/prompt/compact/user-memory-extractor.d.ts +0 -7
- package/lib/cjs/prompt/compact/user-memory-extractor.js +0 -124
- package/lib/cjs/prompt/context/afs/history.d.ts +0 -9
- package/lib/cjs/prompt/context/afs/history.js +0 -33
- package/lib/cjs/prompt/context/afs/index.d.ts +0 -20
- package/lib/cjs/prompt/context/afs/index.js +0 -54
- package/lib/cjs/prompt/context/index.d.ts +0 -31
- package/lib/cjs/prompt/context/index.js +0 -18
- package/lib/cjs/prompt/filters/index.d.ts +0 -2
- package/lib/cjs/prompt/filters/index.js +0 -51
- package/lib/cjs/prompt/prompt-builder.d.ts +0 -50
- package/lib/cjs/prompt/prompt-builder.js +0 -352
- package/lib/cjs/prompt/prompts/afs-builtin-prompt.d.ts +0 -4
- package/lib/cjs/prompt/prompts/afs-builtin-prompt.js +0 -36
- package/lib/cjs/prompt/prompts/memory-message-template.d.ts +0 -1
- package/lib/cjs/prompt/prompts/memory-message-template.js +0 -8
- package/lib/cjs/prompt/prompts/structured-stream-instructions.d.ts +0 -7
- package/lib/cjs/prompt/prompts/structured-stream-instructions.js +0 -27
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.d.ts +0 -19
- package/lib/cjs/prompt/skills/afs/agent-skill/agent-skill.js +0 -69
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.d.ts +0 -12
- package/lib/cjs/prompt/skills/afs/agent-skill/skill-loader.js +0 -50
- package/lib/cjs/prompt/skills/afs/base.d.ts +0 -4
- package/lib/cjs/prompt/skills/afs/base.js +0 -8
- package/lib/cjs/prompt/skills/afs/delete.d.ts +0 -19
- package/lib/cjs/prompt/skills/afs/delete.js +0 -54
- package/lib/cjs/prompt/skills/afs/edit.d.ts +0 -24
- package/lib/cjs/prompt/skills/afs/edit.js +0 -124
- package/lib/cjs/prompt/skills/afs/exec.d.ts +0 -16
- package/lib/cjs/prompt/skills/afs/exec.js +0 -43
- package/lib/cjs/prompt/skills/afs/index.d.ts +0 -3
- package/lib/cjs/prompt/skills/afs/index.js +0 -26
- package/lib/cjs/prompt/skills/afs/list.d.ts +0 -24
- package/lib/cjs/prompt/skills/afs/list.js +0 -81
- package/lib/cjs/prompt/skills/afs/read.d.ts +0 -28
- package/lib/cjs/prompt/skills/afs/read.js +0 -105
- package/lib/cjs/prompt/skills/afs/rename.d.ts +0 -21
- package/lib/cjs/prompt/skills/afs/rename.js +0 -59
- package/lib/cjs/prompt/skills/afs/search.d.ts +0 -24
- package/lib/cjs/prompt/skills/afs/search.js +0 -71
- package/lib/cjs/prompt/skills/afs/write.d.ts +0 -20
- package/lib/cjs/prompt/skills/afs/write.js +0 -59
- package/lib/cjs/prompt/template.d.ts +0 -243
- package/lib/cjs/prompt/template.js +0 -265
- package/lib/cjs/utils/agent-utils.d.ts +0 -13
- package/lib/cjs/utils/agent-utils.js +0 -60
- package/lib/cjs/utils/camelize.d.ts +0 -7
- package/lib/cjs/utils/camelize.js +0 -38
- package/lib/cjs/utils/event-stream.d.ts +0 -15
- package/lib/cjs/utils/event-stream.js +0 -158
- package/lib/cjs/utils/fetch.d.ts +0 -4
- package/lib/cjs/utils/fetch.js +0 -36
- package/lib/cjs/utils/json-schema.d.ts +0 -15
- package/lib/cjs/utils/json-schema.js +0 -123
- package/lib/cjs/utils/json-utils.d.ts +0 -24
- package/lib/cjs/utils/json-utils.js +0 -48
- package/lib/cjs/utils/logger.d.ts +0 -39
- package/lib/cjs/utils/logger.js +0 -81
- package/lib/cjs/utils/mcp-utils.d.ts +0 -5
- package/lib/cjs/utils/mcp-utils.js +0 -52
- package/lib/cjs/utils/model-utils.d.ts +0 -3
- package/lib/cjs/utils/model-utils.js +0 -10
- package/lib/cjs/utils/promise.d.ts +0 -6
- package/lib/cjs/utils/promise.js +0 -12
- package/lib/cjs/utils/prompts.d.ts +0 -2
- package/lib/cjs/utils/prompts.js +0 -22
- package/lib/cjs/utils/queue.d.ts +0 -57
- package/lib/cjs/utils/queue.js +0 -318
- package/lib/cjs/utils/role-utils.d.ts +0 -31
- package/lib/cjs/utils/role-utils.js +0 -37
- package/lib/cjs/utils/stream-polyfill.d.ts +0 -1
- package/lib/cjs/utils/stream-polyfill.js +0 -38
- package/lib/cjs/utils/stream-utils.d.ts +0 -26
- package/lib/cjs/utils/stream-utils.js +0 -235
- package/lib/cjs/utils/structured-stream-extractor.d.ts +0 -14
- package/lib/cjs/utils/structured-stream-extractor.js +0 -68
- package/lib/cjs/utils/token-estimator.d.ts +0 -9
- package/lib/cjs/utils/token-estimator.js +0 -66
- package/lib/cjs/utils/type-utils.d.ts +0 -31
- package/lib/cjs/utils/type-utils.js +0 -202
- package/lib/cjs/utils/typed-event-emitter.d.ts +0 -10
- package/lib/cjs/utils/typed-event-emitter.js +0 -2
- package/lib/dts/agents/agent.d.ts +0 -961
- package/lib/dts/agents/ai-agent.d.ts +0 -395
- package/lib/dts/agents/chat-model.d.ts +0 -672
- package/lib/dts/agents/guide-rail-agent.d.ts +0 -62
- package/lib/dts/agents/image-agent.d.ts +0 -38
- package/lib/dts/agents/image-model.d.ts +0 -270
- package/lib/dts/agents/mcp-agent.d.ts +0 -231
- package/lib/dts/agents/model.d.ts +0 -252
- package/lib/dts/agents/team-agent.d.ts +0 -382
- package/lib/dts/agents/transform-agent.d.ts +0 -94
- package/lib/dts/agents/types.d.ts +0 -31
- package/lib/dts/agents/user-agent.d.ts +0 -27
- package/lib/dts/agents/video-model.d.ts +0 -280
- package/lib/dts/aigne/aigne.d.ts +0 -335
- package/lib/dts/aigne/context.d.ts +0 -220
- package/lib/dts/aigne/index.d.ts +0 -4
- package/lib/dts/aigne/message-queue.d.ts +0 -48
- package/lib/dts/aigne/type.d.ts +0 -26
- package/lib/dts/aigne/usage.d.ts +0 -28
- package/lib/dts/index.d.ts +0 -21
- package/lib/dts/loader/agent-js.d.ts +0 -2
- package/lib/dts/loader/agent-yaml.d.ts +0 -78
- package/lib/dts/loader/agents.d.ts +0 -4
- package/lib/dts/loader/error.d.ts +0 -2
- package/lib/dts/loader/function-agent.d.ts +0 -2
- package/lib/dts/loader/index.d.ts +0 -247
- package/lib/dts/loader/schema.d.ts +0 -167
- package/lib/dts/memory/index.d.ts +0 -3
- package/lib/dts/memory/memory.d.ts +0 -93
- package/lib/dts/memory/recorder.d.ts +0 -93
- package/lib/dts/memory/retriever.d.ts +0 -106
- package/lib/dts/prompt/agent-session.d.ts +0 -163
- package/lib/dts/prompt/compact/compactor.d.ts +0 -7
- package/lib/dts/prompt/compact/session-memory-extractor.d.ts +0 -7
- package/lib/dts/prompt/compact/types.d.ts +0 -336
- package/lib/dts/prompt/compact/user-memory-extractor.d.ts +0 -7
- package/lib/dts/prompt/context/afs/history.d.ts +0 -9
- package/lib/dts/prompt/context/afs/index.d.ts +0 -20
- package/lib/dts/prompt/context/index.d.ts +0 -31
- package/lib/dts/prompt/filters/index.d.ts +0 -2
- package/lib/dts/prompt/prompt-builder.d.ts +0 -50
- package/lib/dts/prompt/prompts/afs-builtin-prompt.d.ts +0 -4
- package/lib/dts/prompt/prompts/memory-message-template.d.ts +0 -1
- package/lib/dts/prompt/prompts/structured-stream-instructions.d.ts +0 -7
- package/lib/dts/prompt/skills/afs/agent-skill/agent-skill.d.ts +0 -19
- package/lib/dts/prompt/skills/afs/agent-skill/skill-loader.d.ts +0 -12
- package/lib/dts/prompt/skills/afs/base.d.ts +0 -4
- package/lib/dts/prompt/skills/afs/delete.d.ts +0 -19
- package/lib/dts/prompt/skills/afs/edit.d.ts +0 -24
- package/lib/dts/prompt/skills/afs/exec.d.ts +0 -16
- package/lib/dts/prompt/skills/afs/index.d.ts +0 -3
- package/lib/dts/prompt/skills/afs/list.d.ts +0 -24
- package/lib/dts/prompt/skills/afs/read.d.ts +0 -28
- package/lib/dts/prompt/skills/afs/rename.d.ts +0 -21
- package/lib/dts/prompt/skills/afs/search.d.ts +0 -24
- package/lib/dts/prompt/skills/afs/write.d.ts +0 -20
- package/lib/dts/prompt/template.d.ts +0 -243
- package/lib/dts/utils/agent-utils.d.ts +0 -13
- package/lib/dts/utils/camelize.d.ts +0 -7
- package/lib/dts/utils/event-stream.d.ts +0 -15
- package/lib/dts/utils/fetch.d.ts +0 -4
- package/lib/dts/utils/json-schema.d.ts +0 -15
- package/lib/dts/utils/json-utils.d.ts +0 -24
- package/lib/dts/utils/logger.d.ts +0 -39
- package/lib/dts/utils/mcp-utils.d.ts +0 -5
- package/lib/dts/utils/model-utils.d.ts +0 -3
- package/lib/dts/utils/promise.d.ts +0 -6
- package/lib/dts/utils/prompts.d.ts +0 -2
- package/lib/dts/utils/queue.d.ts +0 -57
- package/lib/dts/utils/role-utils.d.ts +0 -31
- package/lib/dts/utils/stream-polyfill.d.ts +0 -1
- package/lib/dts/utils/stream-utils.d.ts +0 -26
- package/lib/dts/utils/structured-stream-extractor.d.ts +0 -14
- package/lib/dts/utils/token-estimator.d.ts +0 -9
- package/lib/dts/utils/type-utils.d.ts +0 -31
- package/lib/dts/utils/typed-event-emitter.d.ts +0 -10
- package/lib/esm/agents/agent.d.ts +0 -961
- package/lib/esm/agents/agent.js +0 -911
- package/lib/esm/agents/ai-agent.d.ts +0 -395
- package/lib/esm/agents/ai-agent.js +0 -535
- package/lib/esm/agents/chat-model.d.ts +0 -672
- package/lib/esm/agents/chat-model.js +0 -419
- package/lib/esm/agents/guide-rail-agent.d.ts +0 -62
- package/lib/esm/agents/guide-rail-agent.js +0 -11
- package/lib/esm/agents/image-agent.d.ts +0 -38
- package/lib/esm/agents/image-agent.js +0 -64
- package/lib/esm/agents/image-model.d.ts +0 -270
- package/lib/esm/agents/image-model.js +0 -87
- package/lib/esm/agents/mcp-agent.d.ts +0 -231
- package/lib/esm/agents/mcp-agent.js +0 -325
- package/lib/esm/agents/model.d.ts +0 -252
- package/lib/esm/agents/model.js +0 -143
- package/lib/esm/agents/team-agent.d.ts +0 -382
- package/lib/esm/agents/team-agent.js +0 -346
- package/lib/esm/agents/transform-agent.d.ts +0 -94
- package/lib/esm/agents/transform-agent.js +0 -73
- package/lib/esm/agents/types.d.ts +0 -31
- package/lib/esm/agents/types.js +0 -30
- package/lib/esm/agents/user-agent.d.ts +0 -27
- package/lib/esm/agents/user-agent.js +0 -86
- package/lib/esm/agents/video-model.d.ts +0 -280
- package/lib/esm/agents/video-model.js +0 -63
- package/lib/esm/aigne/aigne.d.ts +0 -335
- package/lib/esm/aigne/aigne.js +0 -244
- package/lib/esm/aigne/context.d.ts +0 -220
- package/lib/esm/aigne/context.js +0 -416
- package/lib/esm/aigne/index.d.ts +0 -4
- package/lib/esm/aigne/index.js +0 -4
- package/lib/esm/aigne/message-queue.d.ts +0 -48
- package/lib/esm/aigne/message-queue.js +0 -104
- package/lib/esm/aigne/type.d.ts +0 -26
- package/lib/esm/aigne/type.js +0 -1
- package/lib/esm/aigne/usage.d.ts +0 -28
- package/lib/esm/aigne/usage.js +0 -30
- package/lib/esm/index.d.ts +0 -21
- package/lib/esm/index.js +0 -21
- package/lib/esm/loader/agent-js.d.ts +0 -2
- package/lib/esm/loader/agent-js.js +0 -18
- package/lib/esm/loader/agent-yaml.d.ts +0 -78
- package/lib/esm/loader/agent-yaml.js +0 -113
- package/lib/esm/loader/agents.d.ts +0 -4
- package/lib/esm/loader/agents.js +0 -14
- package/lib/esm/loader/error.d.ts +0 -2
- package/lib/esm/loader/error.js +0 -2
- package/lib/esm/loader/function-agent.d.ts +0 -2
- package/lib/esm/loader/function-agent.js +0 -4
- package/lib/esm/loader/index.d.ts +0 -247
- package/lib/esm/loader/index.js +0 -258
- package/lib/esm/loader/schema.d.ts +0 -167
- package/lib/esm/loader/schema.js +0 -153
- package/lib/esm/memory/index.d.ts +0 -3
- package/lib/esm/memory/index.js +0 -3
- package/lib/esm/memory/memory.d.ts +0 -93
- package/lib/esm/memory/memory.js +0 -142
- package/lib/esm/memory/recorder.d.ts +0 -93
- package/lib/esm/memory/recorder.js +0 -59
- package/lib/esm/memory/retriever.d.ts +0 -106
- package/lib/esm/memory/retriever.js +0 -56
- package/lib/esm/package.json +0 -3
- package/lib/esm/prompt/agent-session.d.ts +0 -163
- package/lib/esm/prompt/agent-session.js +0 -968
- package/lib/esm/prompt/compact/compactor.d.ts +0 -7
- package/lib/esm/prompt/compact/compactor.js +0 -48
- package/lib/esm/prompt/compact/session-memory-extractor.d.ts +0 -7
- package/lib/esm/prompt/compact/session-memory-extractor.js +0 -139
- package/lib/esm/prompt/compact/types.d.ts +0 -336
- package/lib/esm/prompt/compact/types.js +0 -50
- package/lib/esm/prompt/compact/user-memory-extractor.d.ts +0 -7
- package/lib/esm/prompt/compact/user-memory-extractor.js +0 -120
- package/lib/esm/prompt/context/afs/history.d.ts +0 -9
- package/lib/esm/prompt/context/afs/history.js +0 -30
- package/lib/esm/prompt/context/afs/index.d.ts +0 -20
- package/lib/esm/prompt/context/afs/index.js +0 -51
- package/lib/esm/prompt/context/index.d.ts +0 -31
- package/lib/esm/prompt/context/index.js +0 -15
- package/lib/esm/prompt/filters/index.d.ts +0 -2
- package/lib/esm/prompt/filters/index.js +0 -15
- package/lib/esm/prompt/prompt-builder.d.ts +0 -50
- package/lib/esm/prompt/prompt-builder.js +0 -348
- package/lib/esm/prompt/prompts/afs-builtin-prompt.d.ts +0 -4
- package/lib/esm/prompt/prompts/afs-builtin-prompt.js +0 -32
- package/lib/esm/prompt/prompts/memory-message-template.d.ts +0 -1
- package/lib/esm/prompt/prompts/memory-message-template.js +0 -5
- package/lib/esm/prompt/prompts/structured-stream-instructions.d.ts +0 -7
- package/lib/esm/prompt/prompts/structured-stream-instructions.js +0 -24
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.d.ts +0 -19
- package/lib/esm/prompt/skills/afs/agent-skill/agent-skill.js +0 -65
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.d.ts +0 -12
- package/lib/esm/prompt/skills/afs/agent-skill/skill-loader.js +0 -43
- package/lib/esm/prompt/skills/afs/base.d.ts +0 -4
- package/lib/esm/prompt/skills/afs/base.js +0 -4
- package/lib/esm/prompt/skills/afs/delete.d.ts +0 -19
- package/lib/esm/prompt/skills/afs/delete.js +0 -50
- package/lib/esm/prompt/skills/afs/edit.d.ts +0 -24
- package/lib/esm/prompt/skills/afs/edit.js +0 -120
- package/lib/esm/prompt/skills/afs/exec.d.ts +0 -16
- package/lib/esm/prompt/skills/afs/exec.js +0 -39
- package/lib/esm/prompt/skills/afs/index.d.ts +0 -3
- package/lib/esm/prompt/skills/afs/index.js +0 -23
- package/lib/esm/prompt/skills/afs/list.d.ts +0 -24
- package/lib/esm/prompt/skills/afs/list.js +0 -77
- package/lib/esm/prompt/skills/afs/read.d.ts +0 -28
- package/lib/esm/prompt/skills/afs/read.js +0 -101
- package/lib/esm/prompt/skills/afs/rename.d.ts +0 -21
- package/lib/esm/prompt/skills/afs/rename.js +0 -55
- package/lib/esm/prompt/skills/afs/search.d.ts +0 -24
- package/lib/esm/prompt/skills/afs/search.js +0 -67
- package/lib/esm/prompt/skills/afs/write.d.ts +0 -20
- package/lib/esm/prompt/skills/afs/write.js +0 -55
- package/lib/esm/prompt/template.d.ts +0 -243
- package/lib/esm/prompt/template.js +0 -249
- package/lib/esm/utils/agent-utils.d.ts +0 -13
- package/lib/esm/utils/agent-utils.js +0 -54
- package/lib/esm/utils/camelize.d.ts +0 -7
- package/lib/esm/utils/camelize.js +0 -34
- package/lib/esm/utils/event-stream.d.ts +0 -15
- package/lib/esm/utils/event-stream.js +0 -151
- package/lib/esm/utils/fetch.d.ts +0 -4
- package/lib/esm/utils/fetch.js +0 -33
- package/lib/esm/utils/json-schema.d.ts +0 -15
- package/lib/esm/utils/json-schema.js +0 -114
- package/lib/esm/utils/json-utils.d.ts +0 -24
- package/lib/esm/utils/json-utils.js +0 -41
- package/lib/esm/utils/logger.d.ts +0 -39
- package/lib/esm/utils/logger.js +0 -73
- package/lib/esm/utils/mcp-utils.d.ts +0 -5
- package/lib/esm/utils/mcp-utils.js +0 -47
- package/lib/esm/utils/model-utils.d.ts +0 -3
- package/lib/esm/utils/model-utils.js +0 -7
- package/lib/esm/utils/promise.d.ts +0 -6
- package/lib/esm/utils/promise.js +0 -9
- package/lib/esm/utils/prompts.d.ts +0 -2
- package/lib/esm/utils/prompts.js +0 -18
- package/lib/esm/utils/queue.d.ts +0 -57
- package/lib/esm/utils/queue.js +0 -315
- package/lib/esm/utils/role-utils.d.ts +0 -31
- package/lib/esm/utils/role-utils.js +0 -33
- package/lib/esm/utils/stream-polyfill.d.ts +0 -1
- package/lib/esm/utils/stream-polyfill.js +0 -37
- package/lib/esm/utils/stream-utils.d.ts +0 -26
- package/lib/esm/utils/stream-utils.js +0 -217
- package/lib/esm/utils/structured-stream-extractor.d.ts +0 -14
- package/lib/esm/utils/structured-stream-extractor.js +0 -64
- package/lib/esm/utils/token-estimator.d.ts +0 -9
- package/lib/esm/utils/token-estimator.js +0 -63
- package/lib/esm/utils/type-utils.d.ts +0 -31
- package/lib/esm/utils/type-utils.js +0 -181
- package/lib/esm/utils/typed-event-emitter.d.ts +0 -10
- package/lib/esm/utils/typed-event-emitter.js +0 -1
|
@@ -0,0 +1,874 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_loader_function_agent = require('../loader/function-agent.cjs');
|
|
3
|
+
const require_utils_agent_utils = require('../utils/agent-utils.cjs');
|
|
4
|
+
const require_utils_logger = require('../utils/logger.cjs');
|
|
5
|
+
const require_utils_type_utils = require('../utils/type-utils.cjs');
|
|
6
|
+
const require_utils_json_schema = require('../utils/json-schema.cjs');
|
|
7
|
+
const require_utils_stream_utils = require('../utils/stream-utils.cjs');
|
|
8
|
+
const require_types = require('./types.cjs');
|
|
9
|
+
let _aigne_afs = require("@aigne/afs");
|
|
10
|
+
let _aigne_utils_nodejs = require("@aigne/utils/nodejs");
|
|
11
|
+
let fast_deep_equal = require("fast-deep-equal");
|
|
12
|
+
fast_deep_equal = require_rolldown_runtime.__toESM(fast_deep_equal);
|
|
13
|
+
let nunjucks = require("nunjucks");
|
|
14
|
+
nunjucks = require_rolldown_runtime.__toESM(nunjucks);
|
|
15
|
+
let ufo = require("ufo");
|
|
16
|
+
let yaml = require("yaml");
|
|
17
|
+
let zod = require("zod");
|
|
18
|
+
let zod_to_json_schema = require("zod-to-json-schema");
|
|
19
|
+
|
|
20
|
+
//#region src/agents/agent.ts
|
|
21
|
+
const DEFAULT_INPUT_ACTION_GET = "$get";
|
|
22
|
+
const DEFAULT_RETRIES = 3;
|
|
23
|
+
const DEFAULT_RETRY_MIN_TIMEOUT = 1e3;
|
|
24
|
+
const DEFAULT_RETRY_FACTOR = 2;
|
|
25
|
+
const hooksSchema = zod.z.object({
|
|
26
|
+
onStart: zod.z.custom().optional(),
|
|
27
|
+
onEnd: zod.z.custom().optional(),
|
|
28
|
+
onSkillStart: zod.z.custom().optional(),
|
|
29
|
+
onSkillEnd: zod.z.custom().optional(),
|
|
30
|
+
onHandoff: zod.z.custom().optional()
|
|
31
|
+
});
|
|
32
|
+
const agentOptionsSchema = zod.z.object({
|
|
33
|
+
subscribeTopic: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).optional(),
|
|
34
|
+
publishTopic: zod.z.union([
|
|
35
|
+
zod.z.string(),
|
|
36
|
+
zod.z.array(zod.z.string()),
|
|
37
|
+
zod.z.custom()
|
|
38
|
+
]).optional(),
|
|
39
|
+
name: zod.z.string().optional(),
|
|
40
|
+
description: zod.z.string().optional(),
|
|
41
|
+
inputSchema: zod.z.custom().optional(),
|
|
42
|
+
defaultInput: zod.z.record(zod.z.any()).optional(),
|
|
43
|
+
outputSchema: zod.z.custom().optional(),
|
|
44
|
+
includeInputInOutput: zod.z.boolean().optional(),
|
|
45
|
+
skills: zod.z.array(zod.z.union([zod.z.custom(), zod.z.custom()])).optional(),
|
|
46
|
+
disableEvents: zod.z.boolean().optional(),
|
|
47
|
+
memory: zod.z.union([zod.z.custom(), zod.z.array(zod.z.custom())]).optional(),
|
|
48
|
+
asyncMemoryRecord: zod.z.boolean().optional(),
|
|
49
|
+
maxRetrieveMemoryCount: zod.z.number().optional(),
|
|
50
|
+
hooks: zod.z.union([zod.z.array(hooksSchema), hooksSchema]).optional(),
|
|
51
|
+
guideRails: zod.z.array(zod.z.custom()).optional(),
|
|
52
|
+
retryOnError: zod.z.union([zod.z.boolean(), zod.z.object({
|
|
53
|
+
retries: zod.z.number().int().min(0),
|
|
54
|
+
minTimeout: zod.z.number().min(0).optional(),
|
|
55
|
+
factor: zod.z.number().min(1).optional(),
|
|
56
|
+
randomize: zod.z.boolean().optional(),
|
|
57
|
+
shouldRetry: zod.z.custom().optional()
|
|
58
|
+
})]).optional()
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Agent is the base class for all agents.
|
|
62
|
+
* It provides a mechanism for defining input/output schemas and implementing processing logic,
|
|
63
|
+
* serving as the foundation of the entire agent system.
|
|
64
|
+
*
|
|
65
|
+
* By extending the Agent class and implementing the process method, you can create custom agents
|
|
66
|
+
* with various capabilities:
|
|
67
|
+
* - Process structured input and output data
|
|
68
|
+
* - Validate data formats using schemas
|
|
69
|
+
* - Communicate between agents through contexts
|
|
70
|
+
* - Support streaming or non-streaming responses
|
|
71
|
+
* - Maintain memory of past interactions
|
|
72
|
+
* - Output in multiple formats (JSON/text)
|
|
73
|
+
* - Forward tasks to other agents
|
|
74
|
+
*
|
|
75
|
+
* @template I The input message type the agent accepts
|
|
76
|
+
* @template O The output message type the agent returns
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* Here's an example of how to create a custom agent:
|
|
80
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-custom-agent}
|
|
81
|
+
*/
|
|
82
|
+
var Agent = class Agent {
|
|
83
|
+
static async load(_options) {
|
|
84
|
+
throw new Error("Not implemented");
|
|
85
|
+
}
|
|
86
|
+
constructor(options = {}) {
|
|
87
|
+
require_utils_type_utils.checkArguments("Agent options", agentOptionsSchema, options);
|
|
88
|
+
const { inputSchema, outputSchema } = options;
|
|
89
|
+
this.name = options.name || this.constructor.name;
|
|
90
|
+
this.alias = options.alias;
|
|
91
|
+
this.description = options.description;
|
|
92
|
+
this.model = options.model;
|
|
93
|
+
this.imageModel = options.imageModel;
|
|
94
|
+
this.taskTitle = options.taskTitle;
|
|
95
|
+
this.taskRenderMode = options.taskRenderMode;
|
|
96
|
+
if (inputSchema) checkAgentInputOutputSchema(inputSchema);
|
|
97
|
+
if (outputSchema) checkAgentInputOutputSchema(outputSchema);
|
|
98
|
+
this._inputSchema = inputSchema;
|
|
99
|
+
this.defaultInput = options.defaultInput;
|
|
100
|
+
this._outputSchema = outputSchema;
|
|
101
|
+
this.includeInputInOutput = options.includeInputInOutput;
|
|
102
|
+
this.subscribeTopic = options.subscribeTopic;
|
|
103
|
+
this.publishTopic = options.publishTopic;
|
|
104
|
+
if (options.skills?.length) this.skills.push(...options.skills.map(functionToAgent));
|
|
105
|
+
this.disableEvents = options.disableEvents;
|
|
106
|
+
if (Array.isArray(options.memory)) this.memories.push(...options.memory);
|
|
107
|
+
else if (options.memory) this.memories.push(options.memory);
|
|
108
|
+
this.afs = !options.afs ? void 0 : options.afs === true ? new _aigne_afs.AFS() : typeof options.afs === "function" ? options.afs(new _aigne_afs.AFS()) : options.afs instanceof _aigne_afs.AFS ? options.afs : new _aigne_afs.AFS(options.afs);
|
|
109
|
+
this.asyncMemoryRecord = options.asyncMemoryRecord;
|
|
110
|
+
this.maxRetrieveMemoryCount = options.maxRetrieveMemoryCount;
|
|
111
|
+
this.hooks = require_utils_type_utils.flat(options.hooks);
|
|
112
|
+
this.retryOnError = options.retryOnError === false ? void 0 : options.retryOnError === true ? { retries: DEFAULT_RETRIES } : options.retryOnError;
|
|
113
|
+
this.guideRails = options.guideRails;
|
|
114
|
+
}
|
|
115
|
+
afs;
|
|
116
|
+
tag;
|
|
117
|
+
/**
|
|
118
|
+
* List of memories this agent can use
|
|
119
|
+
*
|
|
120
|
+
* @deprecated use afs instead
|
|
121
|
+
*/
|
|
122
|
+
memories = [];
|
|
123
|
+
asyncMemoryRecord;
|
|
124
|
+
/**
|
|
125
|
+
* Maximum number of memory items to retrieve
|
|
126
|
+
*/
|
|
127
|
+
maxRetrieveMemoryCount;
|
|
128
|
+
/**
|
|
129
|
+
* Lifecycle hooks for agent processing.
|
|
130
|
+
*
|
|
131
|
+
* Hooks enable tracing, logging, monitoring, and custom behavior
|
|
132
|
+
* without modifying the core agent implementation
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* Here's an example of using hooks:
|
|
136
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-agent-hooks}
|
|
137
|
+
*/
|
|
138
|
+
hooks;
|
|
139
|
+
retryOnError;
|
|
140
|
+
/**
|
|
141
|
+
* List of GuideRail agents applied to this agent
|
|
142
|
+
*
|
|
143
|
+
* GuideRail agents validate, transform, or control the message flow by:
|
|
144
|
+
* - Enforcing rules and safety policies
|
|
145
|
+
* - Validating inputs/outputs against specific criteria
|
|
146
|
+
* - Implementing business logic validations
|
|
147
|
+
* - Monitoring and auditing agent behavior
|
|
148
|
+
*
|
|
149
|
+
* Each GuideRail agent can examine both input and expected output,
|
|
150
|
+
* and has the ability to abort the process with an explanation
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* Here's an example of using GuideRail agents:
|
|
154
|
+
*
|
|
155
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-agent-guide-rails}
|
|
156
|
+
*/
|
|
157
|
+
guideRails;
|
|
158
|
+
/**
|
|
159
|
+
* Name of the agent, used for identification and logging
|
|
160
|
+
*
|
|
161
|
+
* Defaults to the class constructor name if not specified in options
|
|
162
|
+
*/
|
|
163
|
+
name;
|
|
164
|
+
/**
|
|
165
|
+
* Alias for the agent, can be used to refer to the agent by multiple names, especially in AIGNE CLI
|
|
166
|
+
*/
|
|
167
|
+
alias;
|
|
168
|
+
/**
|
|
169
|
+
* Default topic this agent subscribes to
|
|
170
|
+
*
|
|
171
|
+
* Each agent has a default topic in the format "$agent_[agent name]"
|
|
172
|
+
* The agent automatically subscribes to this topic to receive messages
|
|
173
|
+
*
|
|
174
|
+
* @returns The default topic string
|
|
175
|
+
*/
|
|
176
|
+
get topic() {
|
|
177
|
+
return `$agent_${this.name}`;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Description of the agent's purpose and capabilities
|
|
181
|
+
*
|
|
182
|
+
* Useful for documentation and when agents need to understand
|
|
183
|
+
* each other's roles in a multi-agent system
|
|
184
|
+
*/
|
|
185
|
+
description;
|
|
186
|
+
model;
|
|
187
|
+
imageModel;
|
|
188
|
+
taskTitle;
|
|
189
|
+
async renderTaskTitle(input) {
|
|
190
|
+
if (!this.taskTitle) return;
|
|
191
|
+
const s = typeof this.taskTitle === "function" ? await this.taskTitle(input) : this.taskTitle;
|
|
192
|
+
if (!s) return;
|
|
193
|
+
return nunjucks.default.renderString(s, { ...input });
|
|
194
|
+
}
|
|
195
|
+
taskRenderMode;
|
|
196
|
+
_inputSchema;
|
|
197
|
+
defaultInput;
|
|
198
|
+
_outputSchema;
|
|
199
|
+
/**
|
|
200
|
+
* Get the input data schema for this agent
|
|
201
|
+
*
|
|
202
|
+
* Used to validate that input messages conform to required format
|
|
203
|
+
* If no input schema is set, returns an empty object schema by default
|
|
204
|
+
*
|
|
205
|
+
* @returns The Zod type definition for input data
|
|
206
|
+
*/
|
|
207
|
+
get inputSchema() {
|
|
208
|
+
const s = this._inputSchema;
|
|
209
|
+
const schema = typeof s === "function" ? s(this) : s || zod.z.object({});
|
|
210
|
+
checkAgentInputOutputSchema(schema);
|
|
211
|
+
return schema.passthrough();
|
|
212
|
+
}
|
|
213
|
+
get inputKeys() {
|
|
214
|
+
return require_utils_json_schema.getZodObjectKeys(this.inputSchema);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get the output data schema for this agent
|
|
218
|
+
*
|
|
219
|
+
* Used to validate that output messages conform to required format
|
|
220
|
+
* If no output schema is set, returns an empty object schema by default
|
|
221
|
+
*
|
|
222
|
+
* @returns The Zod type definition for output data
|
|
223
|
+
*/
|
|
224
|
+
get outputSchema() {
|
|
225
|
+
const s = this._outputSchema;
|
|
226
|
+
const schema = typeof s === "function" ? s(this) : s || zod.z.object({});
|
|
227
|
+
checkAgentInputOutputSchema(schema);
|
|
228
|
+
return schema.passthrough();
|
|
229
|
+
}
|
|
230
|
+
get outputKeys() {
|
|
231
|
+
return require_utils_json_schema.getZodObjectKeys(this.outputSchema);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Whether to include the original input in the output
|
|
235
|
+
*
|
|
236
|
+
* When true, the agent will merge input fields into the output object
|
|
237
|
+
*/
|
|
238
|
+
includeInputInOutput;
|
|
239
|
+
/**
|
|
240
|
+
* Topics the agent subscribes to for receiving messages
|
|
241
|
+
*
|
|
242
|
+
* Can be a single topic string or an array of topic strings
|
|
243
|
+
*/
|
|
244
|
+
subscribeTopic;
|
|
245
|
+
/**
|
|
246
|
+
* Topics the agent publishes to for sending messages
|
|
247
|
+
*
|
|
248
|
+
* Can be a string, array of strings, or a function that determines
|
|
249
|
+
* topics based on the output
|
|
250
|
+
*/
|
|
251
|
+
publishTopic;
|
|
252
|
+
/**
|
|
253
|
+
* Collection of skills (other agents) this agent can use
|
|
254
|
+
*
|
|
255
|
+
* Skills can be accessed by name or by array index, allowing
|
|
256
|
+
* the agent to delegate tasks to specialized sub-agents
|
|
257
|
+
*/
|
|
258
|
+
skills = require_utils_type_utils.createAccessorArray([], (arr, name) => arr.find((t) => t.name === name));
|
|
259
|
+
/**
|
|
260
|
+
* Whether to disable emitting events for agent actions
|
|
261
|
+
*
|
|
262
|
+
* When true, the agent won't emit events like agentStarted,
|
|
263
|
+
* agentSucceed, or agentFailed
|
|
264
|
+
*/
|
|
265
|
+
disableEvents;
|
|
266
|
+
subscriptions = [];
|
|
267
|
+
/**
|
|
268
|
+
* Attach agent to context:
|
|
269
|
+
* - Subscribe to topics and invoke process method when messages are received
|
|
270
|
+
* - Subscribe to memory topics if memory is enabled
|
|
271
|
+
*
|
|
272
|
+
* Agents can receive messages and respond through the topic subscription system,
|
|
273
|
+
* enabling inter-agent communication.
|
|
274
|
+
*
|
|
275
|
+
* @param context Context to attach to
|
|
276
|
+
*/
|
|
277
|
+
attach(context) {
|
|
278
|
+
for (const memory of this.memories) memory.attach(context);
|
|
279
|
+
this.subscribeToTopics(context);
|
|
280
|
+
}
|
|
281
|
+
subscribeToTopics(context) {
|
|
282
|
+
for (const topic of require_utils_type_utils.flat(this.subscribeTopic).concat(this.topic)) this.subscriptions.push(context.subscribe(topic, (payload) => this.onMessage(payload)));
|
|
283
|
+
}
|
|
284
|
+
async onMessage({ message, context }) {
|
|
285
|
+
try {
|
|
286
|
+
await context.invoke(this, message, { newContext: false });
|
|
287
|
+
} catch (error) {
|
|
288
|
+
context.emit("agentFailed", {
|
|
289
|
+
agent: this,
|
|
290
|
+
error
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Add skills (other agents or functions) to this agent
|
|
296
|
+
*
|
|
297
|
+
* Skills allow agents to reuse functionality from other agents,
|
|
298
|
+
* building more complex behaviors.
|
|
299
|
+
*
|
|
300
|
+
* @param skills List of skills to add, can be Agent instances or functions
|
|
301
|
+
*/
|
|
302
|
+
addSkill(...skills) {
|
|
303
|
+
this.skills.push(...skills.map((skill) => typeof skill === "function" ? functionToAgent(skill) : skill));
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Check if the agent is invokable
|
|
307
|
+
*
|
|
308
|
+
* An agent is invokable if it has implemented the process method
|
|
309
|
+
*/
|
|
310
|
+
get isInvokable() {
|
|
311
|
+
return !!this.process;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Check context status to ensure it hasn't timed out
|
|
315
|
+
*
|
|
316
|
+
* @param options Invocation options containing context
|
|
317
|
+
* @throws Error if the context has timed out
|
|
318
|
+
*/
|
|
319
|
+
checkContextStatus(options) {
|
|
320
|
+
const { status } = options.context;
|
|
321
|
+
if (status === "timeout") throw new Error(`AIGNE for agent ${this.name} has timed out`);
|
|
322
|
+
}
|
|
323
|
+
async newDefaultContext() {
|
|
324
|
+
return Promise.resolve().then(() => require("../aigne/context.cjs")).then((m) => new m.AIGNEContext());
|
|
325
|
+
}
|
|
326
|
+
async retrieveMemories(input, options) {
|
|
327
|
+
const memories = [];
|
|
328
|
+
for (const memory of this.memories) {
|
|
329
|
+
const ms = (await memory.retrieve({
|
|
330
|
+
...input,
|
|
331
|
+
limit: input.limit ?? this.maxRetrieveMemoryCount
|
|
332
|
+
}, options.context)).memories;
|
|
333
|
+
memories.push(...ms);
|
|
334
|
+
}
|
|
335
|
+
return memories;
|
|
336
|
+
}
|
|
337
|
+
async recordMemories(input, options) {
|
|
338
|
+
for (const memory of this.memories) if (memory.autoUpdate) await memory.record(input, options.context);
|
|
339
|
+
}
|
|
340
|
+
async invoke(input, options = {}) {
|
|
341
|
+
const opts = {
|
|
342
|
+
...options,
|
|
343
|
+
context: options.context ?? await this.newDefaultContext()
|
|
344
|
+
};
|
|
345
|
+
input = this.mergeDefaultInput(input);
|
|
346
|
+
require_utils_logger.logger.debug("Invoke agent %s started with input: %O", this.name, input);
|
|
347
|
+
if (!this.disableEvents) opts.context.emit("agentStarted", {
|
|
348
|
+
agent: this,
|
|
349
|
+
input,
|
|
350
|
+
taskTitle: await this.renderTaskTitle(input)
|
|
351
|
+
});
|
|
352
|
+
try {
|
|
353
|
+
const s = await this.callHooks("onStart", { input }, opts);
|
|
354
|
+
if (s?.input) input = s.input;
|
|
355
|
+
if (s?.options) Object.assign(opts, s.options);
|
|
356
|
+
input = require_utils_type_utils.checkArguments(`Agent ${this.name} input`, this.inputSchema, input);
|
|
357
|
+
await this.preprocess(input, opts);
|
|
358
|
+
this.checkContextStatus(opts);
|
|
359
|
+
const response = require_utils_stream_utils.asyncGeneratorToReadableStream(this.processStreamingAndRetry(input, opts));
|
|
360
|
+
return await this.checkResponseByGuideRails(input, options.streaming ? response : await agentProcessResultToObject(response), opts);
|
|
361
|
+
} catch (error) {
|
|
362
|
+
throw (await this.processAgentError(input, error, opts)).error ?? error;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
async *processStreamingAndRetry(input, options) {
|
|
366
|
+
let output = {};
|
|
367
|
+
let attempt = 0;
|
|
368
|
+
for (;;) {
|
|
369
|
+
const resetOutput = Object.fromEntries(Object.entries(output).map(([key]) => [key, null]));
|
|
370
|
+
if (!require_utils_type_utils.isEmpty(resetOutput)) {
|
|
371
|
+
yield { delta: { json: resetOutput } };
|
|
372
|
+
output = {};
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
let response = await this.process(input, options);
|
|
376
|
+
if (response instanceof Agent) response = require_types.transferToAgentOutput(response);
|
|
377
|
+
const stream = response instanceof ReadableStream ? response : require_utils_stream_utils.isAsyncGenerator(response) ? require_utils_stream_utils.asyncGeneratorToReadableStream(response) : require_utils_stream_utils.objectToAgentResponseStream(response);
|
|
378
|
+
const messages = [];
|
|
379
|
+
for await (const chunk of stream) {
|
|
380
|
+
require_utils_stream_utils.mergeAgentResponseChunk(output, chunk);
|
|
381
|
+
yield chunk;
|
|
382
|
+
if (isAgentResponseProgress(chunk) && chunk.progress.event === "message") messages.push(chunk.progress.message);
|
|
383
|
+
}
|
|
384
|
+
let result = await this.processAgentOutput(input, output, {
|
|
385
|
+
...options,
|
|
386
|
+
messages
|
|
387
|
+
});
|
|
388
|
+
if (attempt > 0) result = {
|
|
389
|
+
...result,
|
|
390
|
+
$meta: {
|
|
391
|
+
...result.$meta,
|
|
392
|
+
retries: attempt
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
if (result && !(0, fast_deep_equal.default)(result, output)) yield { delta: { json: result } };
|
|
396
|
+
break;
|
|
397
|
+
} catch (error) {
|
|
398
|
+
if (this.retryOnError?.retries) {
|
|
399
|
+
const { retries, minTimeout = DEFAULT_RETRY_MIN_TIMEOUT, factor = DEFAULT_RETRY_FACTOR, randomize = false, shouldRetry } = this.retryOnError;
|
|
400
|
+
if (attempt < retries && (!shouldRetry || await shouldRetry(error))) {
|
|
401
|
+
attempt++;
|
|
402
|
+
const timeout = minTimeout * factor ** (attempt - 1) * (randomize ? 1 + Math.random() : 1);
|
|
403
|
+
require_utils_logger.logger.warn(`Agent ${this.name} attempt ${attempt} of ${retries} failed with error: ${error}. Retrying in ${timeout}ms...`);
|
|
404
|
+
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const res = await this.processAgentError(input, error, options);
|
|
409
|
+
if (!res.retry) {
|
|
410
|
+
const e = res.error ?? error;
|
|
411
|
+
if (attempt > 0) e.message += ` (after ${attempt + 1} retries)`;
|
|
412
|
+
throw e;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async callHooks(hook, input, options) {
|
|
418
|
+
const { context } = options;
|
|
419
|
+
const result = {};
|
|
420
|
+
const hs = require_utils_type_utils.flat(hook);
|
|
421
|
+
const hooks = require_utils_agent_utils.sortHooks(require_utils_type_utils.flat(options.hooks, options.context.hooks, this.hooks)).flatMap((hooks$1) => hs.map((h) => hooks$1[h])).filter(require_utils_type_utils.isNonNullable);
|
|
422
|
+
for (const h of hooks) {
|
|
423
|
+
if (typeof h === "function") Object.assign(result, await h({
|
|
424
|
+
...input,
|
|
425
|
+
context,
|
|
426
|
+
agent: this
|
|
427
|
+
}));
|
|
428
|
+
else Object.assign(result, await context.invoke(h, {
|
|
429
|
+
...input,
|
|
430
|
+
agent: this
|
|
431
|
+
}));
|
|
432
|
+
if ("retry" in result && result.retry) return result;
|
|
433
|
+
}
|
|
434
|
+
return result;
|
|
435
|
+
}
|
|
436
|
+
mergeDefaultInput(input) {
|
|
437
|
+
input = {
|
|
438
|
+
...Object.fromEntries(Object.entries(this.defaultInput ?? {}).filter(([, v]) => !(typeof v === "object" && DEFAULT_INPUT_ACTION_GET in v))),
|
|
439
|
+
...input
|
|
440
|
+
};
|
|
441
|
+
for (const key of Object.keys(this.defaultInput ?? {})) {
|
|
442
|
+
const v = this.defaultInput?.[key];
|
|
443
|
+
if (v && typeof v === "object" && DEFAULT_INPUT_ACTION_GET in v && typeof v[DEFAULT_INPUT_ACTION_GET] === "string" && require_utils_type_utils.isNil(input[key])) {
|
|
444
|
+
const value = input[v[DEFAULT_INPUT_ACTION_GET]];
|
|
445
|
+
if (!require_utils_type_utils.isNil(value)) Object.assign(input, { [key]: value });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return input;
|
|
449
|
+
}
|
|
450
|
+
async invokeSkill(skill, input, options) {
|
|
451
|
+
await this.callHooks("onSkillStart", {
|
|
452
|
+
skill,
|
|
453
|
+
input
|
|
454
|
+
}, options);
|
|
455
|
+
try {
|
|
456
|
+
const output = await this.invokeChildAgent(skill, input, {
|
|
457
|
+
...options,
|
|
458
|
+
streaming: false
|
|
459
|
+
});
|
|
460
|
+
await this.callHooks("onSkillEnd", {
|
|
461
|
+
skill,
|
|
462
|
+
input,
|
|
463
|
+
output
|
|
464
|
+
}, options);
|
|
465
|
+
return output;
|
|
466
|
+
} catch (error) {
|
|
467
|
+
await this.callHooks("onSkillEnd", {
|
|
468
|
+
skill,
|
|
469
|
+
input,
|
|
470
|
+
error
|
|
471
|
+
}, options);
|
|
472
|
+
throw error;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
invokeChildAgent = ((agent, input, options) => {
|
|
476
|
+
return options.context.invoke(agent, input, {
|
|
477
|
+
...options,
|
|
478
|
+
model: this.model || options.model,
|
|
479
|
+
imageModel: this.imageModel || options.imageModel,
|
|
480
|
+
caller: this
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
/**
|
|
484
|
+
* Process agent output
|
|
485
|
+
*
|
|
486
|
+
* Validates output format, applies post-processing operations, and triggers success events
|
|
487
|
+
*
|
|
488
|
+
* @param input Original input message
|
|
489
|
+
* @param output Raw output produced by the agent
|
|
490
|
+
* @param options Invocation options
|
|
491
|
+
* @returns Final processed output
|
|
492
|
+
*/
|
|
493
|
+
async processAgentOutput(input, output, { messages, ...options }) {
|
|
494
|
+
const { context } = options;
|
|
495
|
+
if (!require_utils_type_utils.isRecord(output)) throw new Error(`expect to return a record type such as {result: ...}, but got (${typeof output}): ${output}`);
|
|
496
|
+
const parsedOutput = require_utils_type_utils.checkArguments(`Agent ${this.name} output`, this.outputSchema, output);
|
|
497
|
+
let finalOutput = this.includeInputInOutput ? {
|
|
498
|
+
...input,
|
|
499
|
+
...parsedOutput
|
|
500
|
+
} : parsedOutput;
|
|
501
|
+
await this.postprocess(input, finalOutput, options);
|
|
502
|
+
require_utils_logger.logger.debug("Invoke agent %s succeed with output: %O", this.name, finalOutput);
|
|
503
|
+
const o = await this.callHooks(["onSuccess", "onEnd"], {
|
|
504
|
+
input,
|
|
505
|
+
output: finalOutput
|
|
506
|
+
}, options);
|
|
507
|
+
if (o?.output) finalOutput = o.output;
|
|
508
|
+
this.afs?.emit("agentSucceed", {
|
|
509
|
+
agentId: this.name,
|
|
510
|
+
userId: context.userContext.userId,
|
|
511
|
+
sessionId: context.userContext.sessionId,
|
|
512
|
+
input,
|
|
513
|
+
output: finalOutput,
|
|
514
|
+
messages
|
|
515
|
+
});
|
|
516
|
+
if (!this.disableEvents) context.emit("agentSucceed", {
|
|
517
|
+
agent: this,
|
|
518
|
+
output: finalOutput
|
|
519
|
+
});
|
|
520
|
+
return finalOutput;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Process errors that occur during agent execution
|
|
524
|
+
*
|
|
525
|
+
* Logs error information, triggers failure events, and re-throws the error
|
|
526
|
+
*
|
|
527
|
+
* @param error Caught error
|
|
528
|
+
* @param options Invocation options
|
|
529
|
+
*/
|
|
530
|
+
async processAgentError(input, error, options) {
|
|
531
|
+
require_utils_logger.logger.error("Invoke agent %s failed with error: %O", this.name, error);
|
|
532
|
+
const res = await this.callHooks(["onError", "onEnd"], {
|
|
533
|
+
input,
|
|
534
|
+
error
|
|
535
|
+
}, options) ?? {};
|
|
536
|
+
if (!res.retry) {
|
|
537
|
+
if (!this.disableEvents) options.context.emit("agentFailed", {
|
|
538
|
+
agent: this,
|
|
539
|
+
error
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
return { ...res };
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Check agent invocation usage to prevent exceeding limits
|
|
546
|
+
*
|
|
547
|
+
* If the context has a maximum invocation limit set, checks if the limit
|
|
548
|
+
* has been exceeded and increments the invocation counter
|
|
549
|
+
*
|
|
550
|
+
* @param options Invocation options containing context and limits
|
|
551
|
+
* @throws Error if maximum invocation limit is exceeded
|
|
552
|
+
*/
|
|
553
|
+
checkAgentInvokesUsage(options) {
|
|
554
|
+
const { limits, usage } = options.context;
|
|
555
|
+
if (limits?.maxAgentInvokes && usage.agentCalls >= limits.maxAgentInvokes) throw new Error(`Exceeded max agent invokes ${usage.agentCalls}/${limits.maxAgentInvokes}`);
|
|
556
|
+
usage.agentCalls++;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Pre-processing operations before handling input
|
|
560
|
+
*
|
|
561
|
+
* Preparatory work done before executing the agent's main processing logic, including:
|
|
562
|
+
* - Checking context status
|
|
563
|
+
* - Verifying invocation limits
|
|
564
|
+
*
|
|
565
|
+
* @param _ Input message (unused)
|
|
566
|
+
* @param options Options for agent invocation
|
|
567
|
+
*/
|
|
568
|
+
async preprocess(_, options) {
|
|
569
|
+
this.checkContextStatus(options);
|
|
570
|
+
this.checkAgentInvokesUsage(options);
|
|
571
|
+
}
|
|
572
|
+
async checkResponseByGuideRails(input, output, options) {
|
|
573
|
+
if (!this.guideRails?.length) return output;
|
|
574
|
+
const result = await output;
|
|
575
|
+
if (result instanceof ReadableStream) return require_utils_stream_utils.onAgentResponseStreamEnd(result, { onResult: async (result$1) => {
|
|
576
|
+
const error$1 = await this.runGuideRails(input, result$1, options);
|
|
577
|
+
if (error$1) return {
|
|
578
|
+
...await this.onGuideRailError(error$1),
|
|
579
|
+
$status: "GuideRailError"
|
|
580
|
+
};
|
|
581
|
+
} });
|
|
582
|
+
const error = await this.runGuideRails(input, result, options);
|
|
583
|
+
if (!error) return output;
|
|
584
|
+
return {
|
|
585
|
+
...await this.onGuideRailError(error),
|
|
586
|
+
$status: "GuideRailError"
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
async runGuideRails(input, output, options) {
|
|
590
|
+
return (await Promise.all((this.guideRails ?? []).map((i) => this.invokeChildAgent(i, {
|
|
591
|
+
input,
|
|
592
|
+
output
|
|
593
|
+
}, {
|
|
594
|
+
...options,
|
|
595
|
+
streaming: false
|
|
596
|
+
})))).find((i) => !!i.abort);
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Handle errors detected by GuideRail agents
|
|
600
|
+
*
|
|
601
|
+
* This method is called when a GuideRail agent aborts the process, providing
|
|
602
|
+
* a way for agents to customize error handling behavior. By default, it simply
|
|
603
|
+
* returns the original error, but subclasses can override this method to:
|
|
604
|
+
* - Transform the error into a more specific response
|
|
605
|
+
* - Apply recovery strategies
|
|
606
|
+
* - Log or report the error in a custom format
|
|
607
|
+
* - Return a fallback output instead of an error
|
|
608
|
+
*
|
|
609
|
+
* @param error The GuideRail agent output containing abort=true and a reason
|
|
610
|
+
* @returns Either the original/modified error or a substitute output object
|
|
611
|
+
* which will be tagged with $status: "GuideRailError"
|
|
612
|
+
*/
|
|
613
|
+
async onGuideRailError(error) {
|
|
614
|
+
return error;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Post-processing operations after handling output
|
|
618
|
+
*
|
|
619
|
+
* Operations performed after the agent produces output, including:
|
|
620
|
+
* - Checking context status
|
|
621
|
+
* - Adding interaction records to memory
|
|
622
|
+
*
|
|
623
|
+
* @param input Input message
|
|
624
|
+
* @param output Output message
|
|
625
|
+
* @param options Options for agent invocation
|
|
626
|
+
*/
|
|
627
|
+
async postprocess(input, output, options) {
|
|
628
|
+
this.checkContextStatus(options);
|
|
629
|
+
this.publishToTopics(output, options);
|
|
630
|
+
const memory = this.recordMemories({ content: [{
|
|
631
|
+
input,
|
|
632
|
+
output: require_types.replaceTransferAgentToName(output),
|
|
633
|
+
source: this.name
|
|
634
|
+
}] }, options).catch((error) => {
|
|
635
|
+
require_utils_logger.logger.error(`Agent ${this.name} failed to record memories:`, error);
|
|
636
|
+
});
|
|
637
|
+
if (!this.asyncMemoryRecord) await memory;
|
|
638
|
+
}
|
|
639
|
+
async publishToTopics(output, options) {
|
|
640
|
+
const publishTopics = typeof this.publishTopic === "function" ? await this.publishTopic(output) : this.publishTopic;
|
|
641
|
+
const role = this.constructor.name === "UserAgent" ? "user" : "agent";
|
|
642
|
+
if (publishTopics?.length) (role === "user" ? options.context.newContext({ reset: true }) : options.context).publish(publishTopics, {
|
|
643
|
+
role,
|
|
644
|
+
source: this.name,
|
|
645
|
+
message: output
|
|
646
|
+
}, { newContext: role !== "user" });
|
|
647
|
+
}
|
|
648
|
+
formatOutput(output) {
|
|
649
|
+
return (0, yaml.stringify)(output);
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Shut down the agent and clean up resources
|
|
653
|
+
*
|
|
654
|
+
* Primarily used to clean up memory and other resources to prevent memory leaks
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* Here's an example of shutting down an agent:
|
|
658
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-agent-shutdown}
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* Here's an example of shutting down an agent by using statement:
|
|
662
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-agent-shutdown-by-using}
|
|
663
|
+
*/
|
|
664
|
+
async shutdown() {
|
|
665
|
+
for (const sub of this.subscriptions) sub();
|
|
666
|
+
this.subscriptions = [];
|
|
667
|
+
for (const m of this.memories) m.shutdown();
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Custom object inspection behavior
|
|
671
|
+
*
|
|
672
|
+
* When using Node.js's util.inspect function to inspect an agent,
|
|
673
|
+
* only the agent's name will be shown, making output more concise
|
|
674
|
+
*
|
|
675
|
+
* @returns Agent name
|
|
676
|
+
*/
|
|
677
|
+
[_aigne_utils_nodejs.nodejs.customInspect]() {
|
|
678
|
+
return this.name;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Async dispose method for shutdown the agent
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* Here's an example of shutting down an agent by using statement:
|
|
685
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-agent-shutdown-by-using}
|
|
686
|
+
*/
|
|
687
|
+
async [Symbol.asyncDispose]() {
|
|
688
|
+
await this.shutdown();
|
|
689
|
+
}
|
|
690
|
+
/** For AFSModule interface **/
|
|
691
|
+
agentToAFSEntry(agent) {
|
|
692
|
+
return {
|
|
693
|
+
id: `/${this.name}/${agent.name}`,
|
|
694
|
+
path: agent === this ? "/" : (0, ufo.joinURL)("/", agent.name),
|
|
695
|
+
summary: agent.description,
|
|
696
|
+
metadata: { execute: agent.isInvokable ? {
|
|
697
|
+
name: agent.name,
|
|
698
|
+
description: agent.description,
|
|
699
|
+
inputSchema: (0, zod_to_json_schema.zodToJsonSchema)(agent.inputSchema),
|
|
700
|
+
outputSchema: (0, zod_to_json_schema.zodToJsonSchema)(agent.outputSchema)
|
|
701
|
+
} : void 0 }
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
findAgentByAFSPath(path) {
|
|
705
|
+
let agent;
|
|
706
|
+
if (path === "/") agent = this;
|
|
707
|
+
else {
|
|
708
|
+
const name = path.split("/")[1];
|
|
709
|
+
agent = this.skills.find((s) => s.name === name);
|
|
710
|
+
}
|
|
711
|
+
return agent;
|
|
712
|
+
}
|
|
713
|
+
async list(_path, _options) {
|
|
714
|
+
return { data: [this, ...this.skills].map((agent) => this.agentToAFSEntry(agent)) };
|
|
715
|
+
}
|
|
716
|
+
async read(path) {
|
|
717
|
+
const agent = this.findAgentByAFSPath(path);
|
|
718
|
+
if (!agent) return { message: `Agent not found at path: ${path}` };
|
|
719
|
+
return { data: this.agentToAFSEntry(agent) };
|
|
720
|
+
}
|
|
721
|
+
async search(path, _query, options) {
|
|
722
|
+
return this.list(path, options);
|
|
723
|
+
}
|
|
724
|
+
async exec(path, args, options) {
|
|
725
|
+
const agent = this.findAgentByAFSPath(path);
|
|
726
|
+
if (!agent) throw new Error(`Agent not found at path: ${path}`);
|
|
727
|
+
return { data: await options.context.invoke(agent, args) };
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* Check if a response chunk is empty
|
|
732
|
+
*
|
|
733
|
+
* @template T Response data type
|
|
734
|
+
* @param chunk The response chunk to check
|
|
735
|
+
* @returns True if the chunk is empty
|
|
736
|
+
*/
|
|
737
|
+
function isEmptyChunk(chunk) {
|
|
738
|
+
return isAgentResponseDelta(chunk) && require_utils_type_utils.isEmpty(chunk.delta.json) && require_utils_type_utils.isEmpty(chunk.delta.text);
|
|
739
|
+
}
|
|
740
|
+
function isAgentResponseDelta(chunk) {
|
|
741
|
+
return "delta" in chunk;
|
|
742
|
+
}
|
|
743
|
+
function isAgentResponseProgress(chunk) {
|
|
744
|
+
return "progress" in chunk;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Creates a text delta for streaming responses
|
|
748
|
+
*
|
|
749
|
+
* This utility function creates an AgentResponseDelta object with only the text part,
|
|
750
|
+
* useful for incrementally building streaming text responses in agents.
|
|
751
|
+
*
|
|
752
|
+
* @template T Agent message type extending Message
|
|
753
|
+
* @param textDelta The text content to include in the delta update
|
|
754
|
+
* @returns An AgentResponseDelta with the text delta wrapped in the expected structure
|
|
755
|
+
*/
|
|
756
|
+
function textDelta(textDelta) {
|
|
757
|
+
return { delta: { text: textDelta } };
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Creates a JSON delta for streaming responses
|
|
761
|
+
*
|
|
762
|
+
* This utility function creates an AgentResponseDelta object with only the JSON part,
|
|
763
|
+
* useful for incrementally building structured data responses in streaming mode.
|
|
764
|
+
*
|
|
765
|
+
* @template T Agent message type extending Message
|
|
766
|
+
* @param jsonDelta The JSON data to include in the delta update
|
|
767
|
+
* @returns An AgentResponseDelta with the JSON delta wrapped in the expected structure
|
|
768
|
+
*/
|
|
769
|
+
function jsonDelta(jsonDelta) {
|
|
770
|
+
return { delta: { json: jsonDelta } };
|
|
771
|
+
}
|
|
772
|
+
async function agentProcessResultToObject(response) {
|
|
773
|
+
return response instanceof ReadableStream ? await require_utils_stream_utils.agentResponseStreamToObject(response) : require_utils_stream_utils.isAsyncGenerator(response) ? await require_utils_stream_utils.agentResponseStreamToObject(response) : response;
|
|
774
|
+
}
|
|
775
|
+
function checkAgentInputOutputSchema(schema) {
|
|
776
|
+
if (typeof schema !== "function" && !require_utils_json_schema.isZodSchema(schema)) throw new Error(`schema must be a zod object or function return a zod object, got: ${typeof schema}`);
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Function agent class, implements agent logic through a function
|
|
780
|
+
*
|
|
781
|
+
* Provides a convenient way to create agents using functions without
|
|
782
|
+
* needing to extend the Agent class
|
|
783
|
+
*
|
|
784
|
+
* @template I Agent input message type
|
|
785
|
+
* @template O Agent output message type
|
|
786
|
+
*
|
|
787
|
+
* @example
|
|
788
|
+
* Here's an example of creating a function agent:
|
|
789
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
|
|
790
|
+
*/
|
|
791
|
+
var FunctionAgent = class FunctionAgent extends Agent {
|
|
792
|
+
tag = "FunctionAgent";
|
|
793
|
+
static schema() {
|
|
794
|
+
return zod.z.object({ process: zod.z.preprocess((v) => typeof v === "string" ? require_loader_function_agent.codeToFunctionAgentFn(v) : v, zod.z.custom()) });
|
|
795
|
+
}
|
|
796
|
+
static async load(options) {
|
|
797
|
+
const valid = await FunctionAgent.schema().parseAsync(options.parsed);
|
|
798
|
+
return new FunctionAgent({
|
|
799
|
+
...options.parsed,
|
|
800
|
+
process: valid.process
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Create a function agent from a function or options
|
|
805
|
+
*
|
|
806
|
+
* Provides a convenient factory method to create an agent directly from a function
|
|
807
|
+
*
|
|
808
|
+
* @param options Function agent options or function
|
|
809
|
+
* @returns New function agent instance
|
|
810
|
+
*
|
|
811
|
+
* @example
|
|
812
|
+
* Here's an example of creating a function agent from a function:
|
|
813
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-function-agent-from-function}
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* Here's an example of creating a function agent without basic agent options:
|
|
817
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
|
|
818
|
+
*
|
|
819
|
+
* @example
|
|
820
|
+
* Here's an example of creating a function agent from a function returning a stream:
|
|
821
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-function-agent-stream}
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* Here's an example of creating a function agent from a function returning an async generator:
|
|
825
|
+
* {@includeCode ../../test/agents/agent.test.ts#example-function-agent-async-generator}
|
|
826
|
+
*/
|
|
827
|
+
static from(options) {
|
|
828
|
+
return typeof options === "function" ? functionToAgent(options) : new FunctionAgent(options);
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Create a function agent instance
|
|
832
|
+
*
|
|
833
|
+
* @param options Function agent configuration options
|
|
834
|
+
*/
|
|
835
|
+
constructor(options) {
|
|
836
|
+
super(options);
|
|
837
|
+
this._process = options.process;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Stores the function used to process agent input and generate output
|
|
841
|
+
*
|
|
842
|
+
* @private
|
|
843
|
+
*/
|
|
844
|
+
_process;
|
|
845
|
+
/**
|
|
846
|
+
* Process input implementation, calls the configured processing function
|
|
847
|
+
*
|
|
848
|
+
* @param input Input message
|
|
849
|
+
* @param options Invocation options
|
|
850
|
+
* @returns Processing result
|
|
851
|
+
*/
|
|
852
|
+
process(input, options) {
|
|
853
|
+
return this._process.apply(this, [input, options]);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
function functionToAgent(agent) {
|
|
857
|
+
if (typeof agent === "function") return FunctionAgent.from({
|
|
858
|
+
name: agent.name,
|
|
859
|
+
process: agent
|
|
860
|
+
});
|
|
861
|
+
return agent;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
//#endregion
|
|
865
|
+
exports.Agent = Agent;
|
|
866
|
+
exports.DEFAULT_INPUT_ACTION_GET = DEFAULT_INPUT_ACTION_GET;
|
|
867
|
+
exports.FunctionAgent = FunctionAgent;
|
|
868
|
+
exports.agentOptionsSchema = agentOptionsSchema;
|
|
869
|
+
exports.agentProcessResultToObject = agentProcessResultToObject;
|
|
870
|
+
exports.isAgentResponseDelta = isAgentResponseDelta;
|
|
871
|
+
exports.isAgentResponseProgress = isAgentResponseProgress;
|
|
872
|
+
exports.isEmptyChunk = isEmptyChunk;
|
|
873
|
+
exports.jsonDelta = jsonDelta;
|
|
874
|
+
exports.textDelta = textDelta;
|