@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,700 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_logger = require('../utils/logger.cjs');
|
|
3
|
+
const require_utils_type_utils = require('../utils/type-utils.cjs');
|
|
4
|
+
const require_utils_token_estimator = require('../utils/token-estimator.cjs');
|
|
5
|
+
const require_types = require('./compact/types.cjs');
|
|
6
|
+
let ufo = require("ufo");
|
|
7
|
+
let yaml = require("yaml");
|
|
8
|
+
let _aigne_uuid = require("@aigne/uuid");
|
|
9
|
+
let _aigne_afs_history = require("@aigne/afs-history");
|
|
10
|
+
|
|
11
|
+
//#region src/prompt/agent-session.ts
|
|
12
|
+
var AgentSession = class {
|
|
13
|
+
sessionId;
|
|
14
|
+
userId;
|
|
15
|
+
agentId;
|
|
16
|
+
afs;
|
|
17
|
+
historyModulePath;
|
|
18
|
+
mode;
|
|
19
|
+
compactConfig;
|
|
20
|
+
sessionMemoryConfig;
|
|
21
|
+
userMemoryConfig;
|
|
22
|
+
runtimeState;
|
|
23
|
+
initialized;
|
|
24
|
+
compactionPromise;
|
|
25
|
+
sessionMemoryUpdatePromise;
|
|
26
|
+
userMemoryUpdatePromise;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.sessionId = options.sessionId;
|
|
29
|
+
this.userId = options.userId;
|
|
30
|
+
this.agentId = options.agentId;
|
|
31
|
+
this.afs = options.afs;
|
|
32
|
+
this.mode = options.mode ?? require_types.DEFAULT_SESSION_MODE;
|
|
33
|
+
this.compactConfig = options.compact ?? {};
|
|
34
|
+
this.sessionMemoryConfig = options.sessionMemory ?? {};
|
|
35
|
+
this.userMemoryConfig = options.userMemory ?? {};
|
|
36
|
+
this.runtimeState = {
|
|
37
|
+
historyEntries: [],
|
|
38
|
+
currentEntry: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if memory extraction is enabled
|
|
43
|
+
* Memory extraction requires mode to be "auto" AND AFS history module to be available
|
|
44
|
+
*/
|
|
45
|
+
get isMemoryEnabled() {
|
|
46
|
+
return this.mode === "auto" && !!this.afs && !!this.historyModulePath;
|
|
47
|
+
}
|
|
48
|
+
async setSystemMessages(...messages) {
|
|
49
|
+
await this.ensureInitialized();
|
|
50
|
+
this.runtimeState.systemMessages = messages;
|
|
51
|
+
}
|
|
52
|
+
async getMessages() {
|
|
53
|
+
await this.ensureInitialized();
|
|
54
|
+
const { systemMessages, userMemory, sessionMemory, historyCompact, historyEntries, currentEntry, currentEntryCompact } = this.runtimeState;
|
|
55
|
+
let currentMessages = [];
|
|
56
|
+
if (currentEntry?.messages?.length) if (currentEntryCompact) {
|
|
57
|
+
const { compressedCount, summary } = currentEntryCompact;
|
|
58
|
+
currentMessages = [{
|
|
59
|
+
role: "user",
|
|
60
|
+
content: `[Earlier messages in this conversation (${compressedCount} messages compressed)]\n${summary}`
|
|
61
|
+
}, ...currentEntry.messages.slice(compressedCount)];
|
|
62
|
+
} else currentMessages = currentEntry.messages;
|
|
63
|
+
const historyMessages = historyEntries.flatMap((entry) => entry.content?.messages ?? []);
|
|
64
|
+
const hasSkillInCurrentMessages = [...historyMessages, ...currentMessages].some((msg) => msg.role === "user" && Array.isArray(msg.content) && msg.content.some((block) => block.type === "text" && block.isAgentSkill === true));
|
|
65
|
+
const lastAgentSkillToInject = currentEntryCompact?.lastAgentSkill ?? historyCompact?.lastAgentSkill;
|
|
66
|
+
return [
|
|
67
|
+
...systemMessages ?? [],
|
|
68
|
+
...userMemory && userMemory.length > 0 ? [this.formatUserMemory(userMemory)] : [],
|
|
69
|
+
...sessionMemory && sessionMemory.length > 0 ? [this.formatSessionMemory(sessionMemory)] : [],
|
|
70
|
+
...historyCompact?.summary ? [{
|
|
71
|
+
role: "system",
|
|
72
|
+
content: `Previous conversation summary:\n${historyCompact.summary}`
|
|
73
|
+
}] : [],
|
|
74
|
+
...lastAgentSkillToInject && !hasSkillInCurrentMessages ? [{
|
|
75
|
+
role: "user",
|
|
76
|
+
content: [{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: lastAgentSkillToInject.content
|
|
79
|
+
}]
|
|
80
|
+
}] : [],
|
|
81
|
+
...historyMessages,
|
|
82
|
+
...currentMessages
|
|
83
|
+
].map((msg) => {
|
|
84
|
+
if (!msg.content || typeof msg.content === "string") return msg;
|
|
85
|
+
const filteredContent = msg.content.filter((c) => !(c.type === "text" && c.isThinking));
|
|
86
|
+
if (filteredContent.length === 0) return null;
|
|
87
|
+
return {
|
|
88
|
+
...msg,
|
|
89
|
+
content: filteredContent
|
|
90
|
+
};
|
|
91
|
+
}).filter(require_utils_type_utils.isNonNullable).map((msg) => this.truncateLargeMessage(msg));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Format user memory facts into a system message
|
|
95
|
+
* Applies token budget limit to ensure memory injection fits within constraints
|
|
96
|
+
*/
|
|
97
|
+
formatUserMemory(memoryEntries) {
|
|
98
|
+
const memoryRatio = this.userMemoryConfig.memoryRatio ?? require_types.DEFAULT_MEMORY_RATIO;
|
|
99
|
+
const maxTokens = Math.floor((this.compactConfig.maxTokens ?? require_types.DEFAULT_MAX_TOKENS) * memoryRatio);
|
|
100
|
+
const header = "[User Memory Facts]";
|
|
101
|
+
let currentTokens = require_utils_token_estimator.estimateTokens(header);
|
|
102
|
+
const facts = [];
|
|
103
|
+
for (const entry of memoryEntries) {
|
|
104
|
+
const fact = entry.content?.fact;
|
|
105
|
+
if (!fact) continue;
|
|
106
|
+
const factTokens = require_utils_token_estimator.estimateTokens(fact);
|
|
107
|
+
if (currentTokens + factTokens > maxTokens) break;
|
|
108
|
+
facts.push(fact);
|
|
109
|
+
currentTokens += factTokens;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
role: "system",
|
|
113
|
+
content: this.formatMemoryTemplate({
|
|
114
|
+
header,
|
|
115
|
+
data: facts
|
|
116
|
+
})
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Format session memory facts into a system message
|
|
121
|
+
* Applies token budget limit to ensure memory injection fits within constraints
|
|
122
|
+
*/
|
|
123
|
+
formatSessionMemory(memoryEntries) {
|
|
124
|
+
const memoryRatio = this.sessionMemoryConfig.memoryRatio ?? require_types.DEFAULT_MEMORY_RATIO;
|
|
125
|
+
const maxTokens = Math.floor((this.compactConfig.maxTokens ?? require_types.DEFAULT_MAX_TOKENS) * memoryRatio);
|
|
126
|
+
const header = "[Session Memory Facts]";
|
|
127
|
+
let currentTokens = require_utils_token_estimator.estimateTokens(header);
|
|
128
|
+
const facts = [];
|
|
129
|
+
for (const entry of memoryEntries) {
|
|
130
|
+
const fact = entry.content?.fact;
|
|
131
|
+
if (!fact) continue;
|
|
132
|
+
const factTokens = require_utils_token_estimator.estimateTokens(fact);
|
|
133
|
+
if (currentTokens + factTokens > maxTokens) break;
|
|
134
|
+
facts.push(fact);
|
|
135
|
+
currentTokens += factTokens;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
role: "system",
|
|
139
|
+
content: this.formatMemoryTemplate({
|
|
140
|
+
header,
|
|
141
|
+
data: facts
|
|
142
|
+
})
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
formatMemoryTemplate({ header, data }) {
|
|
146
|
+
return `\
|
|
147
|
+
${header}
|
|
148
|
+
|
|
149
|
+
\`\`\`yaml
|
|
150
|
+
${(0, yaml.stringify)(data)}
|
|
151
|
+
\`\`\`
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
async startMessage(input, message, options) {
|
|
155
|
+
await this.ensureInitialized();
|
|
156
|
+
if (this.mode !== "disabled") {
|
|
157
|
+
await this.maybeAutoCompact(options);
|
|
158
|
+
if (this.compactionPromise) await this.compactionPromise;
|
|
159
|
+
}
|
|
160
|
+
this.runtimeState.currentEntryCompact = void 0;
|
|
161
|
+
this.runtimeState.currentEntry = {
|
|
162
|
+
input,
|
|
163
|
+
messages: [message]
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
async endMessage(output, message, options) {
|
|
167
|
+
await this.ensureInitialized();
|
|
168
|
+
if (!this.runtimeState.currentEntry?.input || !this.runtimeState.currentEntry.messages?.length) throw new Error("No current entry to end. Call startMessage() first.");
|
|
169
|
+
if (message) this.runtimeState.currentEntry.messages.push(message);
|
|
170
|
+
this.runtimeState.currentEntry.output = output;
|
|
171
|
+
let newEntry;
|
|
172
|
+
if (this.mode !== "disabled" && this.afs && this.historyModulePath) newEntry = (await this.afs.write((0, ufo.joinURL)(this.historyModulePath, "by-session", this.sessionId, "new"), {
|
|
173
|
+
userId: this.userId,
|
|
174
|
+
sessionId: this.sessionId,
|
|
175
|
+
agentId: this.agentId,
|
|
176
|
+
content: this.runtimeState.currentEntry
|
|
177
|
+
})).data;
|
|
178
|
+
else {
|
|
179
|
+
const id = (0, _aigne_uuid.v7)();
|
|
180
|
+
newEntry = {
|
|
181
|
+
id,
|
|
182
|
+
path: `/history/${id}`,
|
|
183
|
+
userId: this.userId,
|
|
184
|
+
sessionId: this.sessionId,
|
|
185
|
+
agentId: this.agentId,
|
|
186
|
+
content: this.runtimeState.currentEntry
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
this.runtimeState.historyEntries.push(newEntry);
|
|
190
|
+
this.runtimeState.currentEntry = null;
|
|
191
|
+
this.runtimeState.currentEntryCompact = void 0;
|
|
192
|
+
if (this.mode !== "disabled") await Promise.all([this.maybeAutoCompact(options), this.maybeAutoUpdateSessionMemory(options)]);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Manually trigger compaction
|
|
196
|
+
*/
|
|
197
|
+
async compact(options) {
|
|
198
|
+
await this.ensureInitialized();
|
|
199
|
+
if (this.compactionPromise) return this.compactionPromise;
|
|
200
|
+
this.compactionPromise = this.doCompact(options).finally(() => {
|
|
201
|
+
this.compactionPromise = void 0;
|
|
202
|
+
});
|
|
203
|
+
if (!(this.compactConfig.async ?? require_types.DEFAULT_COMPACT_ASYNC)) await this.compactionPromise;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Internal method that performs the actual compaction
|
|
207
|
+
*/
|
|
208
|
+
async doCompact(options) {
|
|
209
|
+
const { compactor } = this.compactConfig ?? {};
|
|
210
|
+
if (!compactor) throw new Error("Cannot compact without a compactor agent configured.");
|
|
211
|
+
const historyEntries = this.runtimeState.historyEntries;
|
|
212
|
+
if (historyEntries.length === 0) return;
|
|
213
|
+
const maxTokens = this.maxTokens;
|
|
214
|
+
const keepRecentTokens = this.keepRecentTokens * .5;
|
|
215
|
+
let splitIndex = historyEntries.length;
|
|
216
|
+
let accumulatedTokens = 0;
|
|
217
|
+
for (let i = historyEntries.length - 1; i >= 0; i--) {
|
|
218
|
+
const entry = historyEntries[i];
|
|
219
|
+
if (!entry) continue;
|
|
220
|
+
const entryTokens = this.estimateMessagesTokens(entry.content?.messages ?? []);
|
|
221
|
+
if (accumulatedTokens + entryTokens > keepRecentTokens) {
|
|
222
|
+
splitIndex = i + 1;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
accumulatedTokens += entryTokens;
|
|
226
|
+
splitIndex = i;
|
|
227
|
+
}
|
|
228
|
+
const entriesToCompact = historyEntries.slice(0, splitIndex);
|
|
229
|
+
const entriesToKeep = historyEntries.slice(splitIndex);
|
|
230
|
+
if (entriesToCompact.length === 0) return;
|
|
231
|
+
const latestCompactedEntry = entriesToCompact.at(-1);
|
|
232
|
+
if (!latestCompactedEntry) return;
|
|
233
|
+
const batches = this.splitIntoBatches(entriesToCompact, maxTokens);
|
|
234
|
+
let currentSummary = this.runtimeState.historyCompact?.summary;
|
|
235
|
+
for (const batch of batches) {
|
|
236
|
+
const messages = batch.flatMap((e) => e.content?.messages ?? []).filter(require_utils_type_utils.isNonNullable).map((msg) => this.truncateLargeMessage(msg));
|
|
237
|
+
currentSummary = (await options.context.invoke(compactor, {
|
|
238
|
+
previousSummary: [currentSummary].filter(require_utils_type_utils.isNonNullable),
|
|
239
|
+
messages
|
|
240
|
+
})).summary;
|
|
241
|
+
}
|
|
242
|
+
let lastAgentSkill = this.findLastAgentSkill(entriesToCompact);
|
|
243
|
+
if (!lastAgentSkill && this.runtimeState.historyCompact?.lastAgentSkill) lastAgentSkill = this.runtimeState.historyCompact.lastAgentSkill;
|
|
244
|
+
const historyCompact = {
|
|
245
|
+
summary: currentSummary ?? "",
|
|
246
|
+
lastAgentSkill
|
|
247
|
+
};
|
|
248
|
+
if (this.afs && this.historyModulePath) await this.afs.write((0, ufo.joinURL)(this.historyModulePath, "by-session", this.sessionId, "@metadata/compact/new"), {
|
|
249
|
+
userId: this.userId,
|
|
250
|
+
agentId: this.agentId,
|
|
251
|
+
content: historyCompact,
|
|
252
|
+
metadata: { latestEntryId: latestCompactedEntry.id }
|
|
253
|
+
});
|
|
254
|
+
this.runtimeState.historyCompact = historyCompact;
|
|
255
|
+
this.runtimeState.historyEntries = entriesToKeep;
|
|
256
|
+
}
|
|
257
|
+
async compactCurrentEntry(options) {
|
|
258
|
+
const { compactor } = this.compactConfig ?? {};
|
|
259
|
+
if (!compactor) return;
|
|
260
|
+
const currentEntry = this.runtimeState.currentEntry;
|
|
261
|
+
if (!currentEntry?.messages?.length) return;
|
|
262
|
+
const alreadyCompressedCount = this.runtimeState.currentEntryCompact?.compressedCount ?? 0;
|
|
263
|
+
const uncompressedMessages = currentEntry.messages.slice(alreadyCompressedCount);
|
|
264
|
+
if (uncompressedMessages.length === 0) return;
|
|
265
|
+
const keepTokenBudget = this.keepRecentTokens * .5;
|
|
266
|
+
let splitIndex = uncompressedMessages.length;
|
|
267
|
+
let accumulatedTokens = 0;
|
|
268
|
+
for (let i = uncompressedMessages.length - 1; i >= 0; i--) {
|
|
269
|
+
const msg = uncompressedMessages[i];
|
|
270
|
+
if (!msg) continue;
|
|
271
|
+
const msgTokens = this.estimateMessagesTokens([msg]);
|
|
272
|
+
if (accumulatedTokens + msgTokens > keepTokenBudget) {
|
|
273
|
+
splitIndex = i + 1;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
accumulatedTokens += msgTokens;
|
|
277
|
+
splitIndex = i;
|
|
278
|
+
}
|
|
279
|
+
const keptMessages = uncompressedMessages.slice(splitIndex);
|
|
280
|
+
const requiredToolCallIds = /* @__PURE__ */ new Set();
|
|
281
|
+
for (const msg of keptMessages) if (msg.role === "tool" && msg.toolCallId) requiredToolCallIds.add(msg.toolCallId);
|
|
282
|
+
if (requiredToolCallIds.size > 0) for (let i = splitIndex - 1; i >= 0; i--) {
|
|
283
|
+
const msg = uncompressedMessages[i];
|
|
284
|
+
if (!msg?.toolCalls) continue;
|
|
285
|
+
for (const toolCall of msg.toolCalls) if (requiredToolCallIds.has(toolCall.id)) {
|
|
286
|
+
splitIndex = i;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const messagesToCompact = uncompressedMessages.slice(0, splitIndex).map((msg) => this.truncateLargeMessage(msg));
|
|
291
|
+
if (messagesToCompact.length === 0) return;
|
|
292
|
+
const result = await options.context.invoke(compactor, {
|
|
293
|
+
previousSummary: this.runtimeState.currentEntryCompact?.summary ? [this.runtimeState.currentEntryCompact.summary] : void 0,
|
|
294
|
+
messages: messagesToCompact
|
|
295
|
+
});
|
|
296
|
+
const lastAgentSkill = this.findLastAgentSkillFromMessages(messagesToCompact) ?? this.runtimeState.currentEntryCompact?.lastAgentSkill;
|
|
297
|
+
this.runtimeState.currentEntryCompact = {
|
|
298
|
+
summary: result.summary,
|
|
299
|
+
lastAgentSkill,
|
|
300
|
+
compressedCount: alreadyCompressedCount + messagesToCompact.length
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
async maybeCompactCurrentEntry(options) {
|
|
304
|
+
const currentEntry = this.runtimeState.currentEntry;
|
|
305
|
+
if (!currentEntry?.messages?.length) return;
|
|
306
|
+
const compressedCount = this.runtimeState.currentEntryCompact?.compressedCount ?? 0;
|
|
307
|
+
const uncompressedMessages = currentEntry.messages.slice(compressedCount);
|
|
308
|
+
const threshold = this.keepRecentTokens;
|
|
309
|
+
if (this.estimateMessagesTokens(uncompressedMessages) > threshold) await this.compactCurrentEntry(options);
|
|
310
|
+
}
|
|
311
|
+
async maybeAutoCompact(options) {
|
|
312
|
+
if (this.compactionPromise) await this.compactionPromise;
|
|
313
|
+
if ((this.compactConfig.mode ?? require_types.DEFAULT_COMPACT_MODE) === "disabled") return;
|
|
314
|
+
const { compactor } = this.compactConfig;
|
|
315
|
+
if (!compactor) return;
|
|
316
|
+
const maxTokens = this.maxTokens;
|
|
317
|
+
const messages = await this.getMessages();
|
|
318
|
+
if (this.estimateMessagesTokens(messages) >= maxTokens) await this.compact(options);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Estimate token count for messages
|
|
322
|
+
* Applies singleMessageLimit to each text block individually
|
|
323
|
+
* Non-text tokens (images, tool calls) are always counted in full
|
|
324
|
+
*/
|
|
325
|
+
estimateMessagesTokens(messages, singleMessageLimit = this.singleMessageLimit) {
|
|
326
|
+
let totalTokens = 0;
|
|
327
|
+
for (const msg of messages) {
|
|
328
|
+
if (typeof msg.content === "string") {
|
|
329
|
+
const textTokens = require_utils_token_estimator.estimateTokens(msg.content);
|
|
330
|
+
totalTokens += textTokens > singleMessageLimit ? singleMessageLimit : textTokens;
|
|
331
|
+
} else if (Array.isArray(msg.content)) for (const block of msg.content) if (block.type === "text" && typeof block.text === "string") {
|
|
332
|
+
const textTokens = require_utils_token_estimator.estimateTokens(block.text);
|
|
333
|
+
totalTokens += textTokens > singleMessageLimit ? singleMessageLimit : textTokens;
|
|
334
|
+
} else totalTokens += 1e3;
|
|
335
|
+
if (msg.toolCalls && msg.toolCalls.length > 0) for (const toolCall of msg.toolCalls) {
|
|
336
|
+
totalTokens += require_utils_token_estimator.estimateTokens(toolCall.function.name);
|
|
337
|
+
totalTokens += require_utils_token_estimator.estimateTokens((0, yaml.stringify)(toolCall.function.arguments).replace(/\s+/g, " "));
|
|
338
|
+
totalTokens += 10;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return totalTokens;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Split entries into batches based on token limit
|
|
345
|
+
* Each batch will not exceed the specified maxTokens
|
|
346
|
+
*/
|
|
347
|
+
splitIntoBatches(entries, maxTokens) {
|
|
348
|
+
const batches = [];
|
|
349
|
+
let currentBatch = [];
|
|
350
|
+
let currentTokens = 0;
|
|
351
|
+
for (const entry of entries) {
|
|
352
|
+
const entryTokens = this.estimateMessagesTokens(entry.content?.messages ?? []);
|
|
353
|
+
if (currentTokens + entryTokens > maxTokens && currentBatch.length > 0) {
|
|
354
|
+
batches.push(currentBatch);
|
|
355
|
+
currentBatch = [entry];
|
|
356
|
+
currentTokens = entryTokens;
|
|
357
|
+
} else {
|
|
358
|
+
currentBatch.push(entry);
|
|
359
|
+
currentTokens += entryTokens;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (currentBatch.length > 0) batches.push(currentBatch);
|
|
363
|
+
return batches;
|
|
364
|
+
}
|
|
365
|
+
async appendCurrentMessages(messages, options) {
|
|
366
|
+
await this.ensureInitialized();
|
|
367
|
+
if (!this.runtimeState.currentEntry || !this.runtimeState.currentEntry.messages?.length) throw new Error("No current entry to append messages. Call startMessage() first.");
|
|
368
|
+
this.runtimeState.currentEntry.messages.push(...[messages].flat());
|
|
369
|
+
await this.maybeCompactCurrentEntry(options);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Truncate text content to fit within target token limit
|
|
373
|
+
* @param text The text to truncate
|
|
374
|
+
* @param currentTokens Current token count of the text
|
|
375
|
+
* @param targetTokens Target token count after truncation
|
|
376
|
+
* @returns Truncated text
|
|
377
|
+
*/
|
|
378
|
+
truncateText(text, currentTokens, targetTokens) {
|
|
379
|
+
if (currentTokens <= targetTokens) return text;
|
|
380
|
+
const keepRatio = targetTokens / currentTokens * .9;
|
|
381
|
+
const keepLength = Math.floor(text.length * keepRatio);
|
|
382
|
+
const headLength = Math.floor(keepLength * .7);
|
|
383
|
+
const tailLength = Math.floor(keepLength * .3);
|
|
384
|
+
return text.slice(0, headLength) + `\n\n[... truncated ${currentTokens - targetTokens} tokens ...]\n\n` + text.slice(-tailLength);
|
|
385
|
+
}
|
|
386
|
+
truncateLargeMessage(msg) {
|
|
387
|
+
const singleMessageLimit = this.singleMessageLimit;
|
|
388
|
+
if (typeof msg.content === "string") {
|
|
389
|
+
const tokens = require_utils_token_estimator.estimateTokens(msg.content);
|
|
390
|
+
if (tokens <= singleMessageLimit) return msg;
|
|
391
|
+
const truncated = this.truncateText(msg.content, tokens, singleMessageLimit);
|
|
392
|
+
return {
|
|
393
|
+
...msg,
|
|
394
|
+
content: truncated
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
if (Array.isArray(msg.content)) {
|
|
398
|
+
const truncatedContent = msg.content.map((block) => {
|
|
399
|
+
if (block.type !== "text" || typeof block.text !== "string") return block;
|
|
400
|
+
const blockTokens = require_utils_token_estimator.estimateTokens(block.text);
|
|
401
|
+
if (blockTokens <= singleMessageLimit) return block;
|
|
402
|
+
const truncatedText = this.truncateText(block.text, blockTokens, singleMessageLimit);
|
|
403
|
+
return {
|
|
404
|
+
...block,
|
|
405
|
+
text: truncatedText
|
|
406
|
+
};
|
|
407
|
+
});
|
|
408
|
+
return {
|
|
409
|
+
...msg,
|
|
410
|
+
content: truncatedContent
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
return msg;
|
|
414
|
+
}
|
|
415
|
+
async ensureInitialized() {
|
|
416
|
+
this.initialized ??= this.initialize();
|
|
417
|
+
await this.initialized;
|
|
418
|
+
}
|
|
419
|
+
async initialize() {
|
|
420
|
+
if (this.initialized) return;
|
|
421
|
+
await this.initializeDefaultCompactor();
|
|
422
|
+
await this.initializeDefaultSessionMemoryExtractor();
|
|
423
|
+
await this.initializeDefaultUserMemoryExtractor();
|
|
424
|
+
this.historyModulePath = ((await this.afs?.listModules())?.find((m) => m.module instanceof _aigne_afs_history.AFSHistory))?.path;
|
|
425
|
+
if (this.afs && this.historyModulePath) {
|
|
426
|
+
const [userMemory, sessionMemory, sessionHistory] = await Promise.all([
|
|
427
|
+
this.loadUserMemory(),
|
|
428
|
+
this.loadSessionMemory(),
|
|
429
|
+
this.loadSessionHistory()
|
|
430
|
+
]);
|
|
431
|
+
this.runtimeState.userMemory = userMemory;
|
|
432
|
+
this.runtimeState.sessionMemory = sessionMemory;
|
|
433
|
+
this.runtimeState.historyCompact = sessionHistory.historyCompact;
|
|
434
|
+
this.runtimeState.historyEntries = sessionHistory.historyEntries;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Load session memory facts
|
|
439
|
+
* @returns Array of memory fact entries for the current session
|
|
440
|
+
*/
|
|
441
|
+
async loadSessionMemory() {
|
|
442
|
+
if (!this.afs || !this.historyModulePath) return [];
|
|
443
|
+
if ((this.sessionMemoryConfig.mode ?? require_types.DEFAULT_SESSION_MEMORY_MODE) === "disabled") return [];
|
|
444
|
+
const sessionMemoryPath = (0, ufo.joinURL)(this.historyModulePath, "by-session", this.sessionId, "@metadata/memory");
|
|
445
|
+
const queryLimit = this.sessionMemoryConfig.queryLimit ?? require_types.DEFAULT_MEMORY_QUERY_LIMIT;
|
|
446
|
+
return (await this.afs.list(sessionMemoryPath, {
|
|
447
|
+
filter: {
|
|
448
|
+
userId: this.userId,
|
|
449
|
+
agentId: this.agentId
|
|
450
|
+
},
|
|
451
|
+
orderBy: [["updatedAt", "desc"]],
|
|
452
|
+
limit: queryLimit
|
|
453
|
+
})).data.reverse().filter((entry) => require_utils_type_utils.isNonNullable(entry.content));
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Load user memory facts
|
|
457
|
+
* @returns Array of memory fact entries for the current user
|
|
458
|
+
*/
|
|
459
|
+
async loadUserMemory() {
|
|
460
|
+
if (!this.afs || !this.historyModulePath || !this.userId) return [];
|
|
461
|
+
if ((this.userMemoryConfig.mode ?? require_types.DEFAULT_USER_MEMORY_MODE) === "disabled") return [];
|
|
462
|
+
const userMemoryPath = (0, ufo.joinURL)(this.historyModulePath, "by-user", this.userId, "@metadata/memory");
|
|
463
|
+
const queryLimit = this.userMemoryConfig.queryLimit ?? require_types.DEFAULT_MEMORY_QUERY_LIMIT;
|
|
464
|
+
return (await this.afs.list(userMemoryPath, {
|
|
465
|
+
filter: {
|
|
466
|
+
userId: this.userId,
|
|
467
|
+
agentId: this.agentId
|
|
468
|
+
},
|
|
469
|
+
orderBy: [["updatedAt", "desc"]],
|
|
470
|
+
limit: queryLimit
|
|
471
|
+
})).data.reverse().filter((entry) => require_utils_type_utils.isNonNullable(entry.content));
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Load session history including compact content and history entries
|
|
475
|
+
* @returns Object containing history compact and history entries
|
|
476
|
+
*/
|
|
477
|
+
async loadSessionHistory() {
|
|
478
|
+
if (!this.afs || !this.historyModulePath) return { historyEntries: [] };
|
|
479
|
+
const compactPath = (0, ufo.joinURL)(this.historyModulePath, "by-session", this.sessionId, "@metadata/compact");
|
|
480
|
+
const latestCompact = (await this.afs.list(compactPath, {
|
|
481
|
+
filter: {
|
|
482
|
+
userId: this.userId,
|
|
483
|
+
agentId: this.agentId
|
|
484
|
+
},
|
|
485
|
+
orderBy: [["createdAt", "desc"]],
|
|
486
|
+
limit: 1
|
|
487
|
+
})).data[0];
|
|
488
|
+
return {
|
|
489
|
+
historyCompact: latestCompact?.content,
|
|
490
|
+
historyEntries: (await this.afs.list((0, ufo.joinURL)(this.historyModulePath, "by-session", this.sessionId), {
|
|
491
|
+
filter: {
|
|
492
|
+
userId: this.userId,
|
|
493
|
+
agentId: this.agentId,
|
|
494
|
+
after: latestCompact?.createdAt?.toISOString()
|
|
495
|
+
},
|
|
496
|
+
orderBy: [["createdAt", "desc"]],
|
|
497
|
+
limit: 1e4
|
|
498
|
+
})).data.reverse().filter((entry) => require_utils_type_utils.isNonNullable(entry.content))
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Manually trigger session memory update
|
|
503
|
+
*/
|
|
504
|
+
async updateSessionMemory(options) {
|
|
505
|
+
await this.ensureInitialized();
|
|
506
|
+
this.sessionMemoryUpdatePromise ??= this.doUpdateSessionMemory(options).then(() => {
|
|
507
|
+
this.maybeAutoUpdateUserMemory(options).catch((err) => {
|
|
508
|
+
require_utils_logger.logger.error("User memory update failed:", err);
|
|
509
|
+
});
|
|
510
|
+
}).finally(() => {
|
|
511
|
+
this.sessionMemoryUpdatePromise = void 0;
|
|
512
|
+
});
|
|
513
|
+
return this.sessionMemoryUpdatePromise;
|
|
514
|
+
}
|
|
515
|
+
async maybeAutoUpdateSessionMemory(options) {
|
|
516
|
+
if (!this.isMemoryEnabled) return;
|
|
517
|
+
if ((this.sessionMemoryConfig.mode ?? require_types.DEFAULT_SESSION_MEMORY_MODE) === "disabled") return;
|
|
518
|
+
this.updateSessionMemory(options).catch((err) => {
|
|
519
|
+
require_utils_logger.logger.error("Session memory update failed:", err);
|
|
520
|
+
});
|
|
521
|
+
if (!(this.sessionMemoryConfig.async ?? require_types.DEFAULT_SESSION_MEMORY_ASYNC)) await this.sessionMemoryUpdatePromise;
|
|
522
|
+
}
|
|
523
|
+
async maybeAutoUpdateUserMemory(options) {
|
|
524
|
+
if (!this.isMemoryEnabled || !this.userId) return;
|
|
525
|
+
if ((this.userMemoryConfig.mode ?? require_types.DEFAULT_USER_MEMORY_MODE) === "disabled") return;
|
|
526
|
+
this.updateUserMemory(options).catch((err) => {
|
|
527
|
+
require_utils_logger.logger.error("User memory update failed:", err);
|
|
528
|
+
});
|
|
529
|
+
if (!(this.userMemoryConfig.async ?? require_types.DEFAULT_USER_MEMORY_ASYNC)) await this.userMemoryUpdatePromise;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Internal method that performs the actual session memory update
|
|
533
|
+
*/
|
|
534
|
+
async doUpdateSessionMemory(options) {
|
|
535
|
+
const { extractor } = this.sessionMemoryConfig ?? {};
|
|
536
|
+
if (!extractor) throw new Error("Cannot update session memory without an extractor agent configured.");
|
|
537
|
+
const latestEntryId = this.runtimeState.sessionMemory?.at(-1)?.metadata?.latestEntryId;
|
|
538
|
+
const lastExtractedIndex = latestEntryId ? this.runtimeState.historyEntries.findIndex((e) => e.id === latestEntryId) : -1;
|
|
539
|
+
const unextractedEntries = lastExtractedIndex >= 0 ? this.runtimeState.historyEntries.slice(lastExtractedIndex + 1) : this.runtimeState.historyEntries;
|
|
540
|
+
if (unextractedEntries.length === 0) return;
|
|
541
|
+
const recentMessages = unextractedEntries.flatMap((entry) => entry.content?.messages ?? []).filter(require_utils_type_utils.isNonNullable);
|
|
542
|
+
if (recentMessages.length === 0) return;
|
|
543
|
+
const existingFacts = this.runtimeState.sessionMemory?.map((entry) => entry.content).filter(require_utils_type_utils.isNonNullable) ?? [];
|
|
544
|
+
const existingUserFacts = this.runtimeState.userMemory?.map((entry) => entry.content).filter(require_utils_type_utils.isNonNullable) ?? [];
|
|
545
|
+
const result = await options.context.invoke(extractor, {
|
|
546
|
+
existingUserFacts,
|
|
547
|
+
existingFacts,
|
|
548
|
+
messages: recentMessages
|
|
549
|
+
});
|
|
550
|
+
if (!result.newFacts.length && !result.removeFacts?.length) return;
|
|
551
|
+
const latestExtractedEntry = unextractedEntries.at(-1);
|
|
552
|
+
if (this.afs && this.historyModulePath) {
|
|
553
|
+
if (result.removeFacts?.length && this.runtimeState.sessionMemory) {
|
|
554
|
+
const entriesToRemove = [];
|
|
555
|
+
for (const label of result.removeFacts) {
|
|
556
|
+
const entry = this.runtimeState.sessionMemory.find((e) => e.content?.label === label);
|
|
557
|
+
if (entry) entriesToRemove.push(entry);
|
|
558
|
+
}
|
|
559
|
+
for (const entryToRemove of entriesToRemove) {
|
|
560
|
+
const memoryEntryPath = (0, ufo.joinURL)(this.historyModulePath, "by-session", this.sessionId, "@metadata/memory", entryToRemove.id);
|
|
561
|
+
await this.afs.delete(memoryEntryPath);
|
|
562
|
+
const index = this.runtimeState.sessionMemory.indexOf(entryToRemove);
|
|
563
|
+
if (index !== -1) this.runtimeState.sessionMemory.splice(index, 1);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (result.newFacts.length) {
|
|
567
|
+
const sessionMemoryPath = (0, ufo.joinURL)(this.historyModulePath, "by-session", this.sessionId, "@metadata/memory/new");
|
|
568
|
+
for (const fact of result.newFacts) {
|
|
569
|
+
const newEntry = await this.afs.write(sessionMemoryPath, {
|
|
570
|
+
userId: this.userId,
|
|
571
|
+
sessionId: this.sessionId,
|
|
572
|
+
agentId: this.agentId,
|
|
573
|
+
content: fact,
|
|
574
|
+
metadata: { latestEntryId: latestExtractedEntry?.id }
|
|
575
|
+
});
|
|
576
|
+
this.runtimeState.sessionMemory ??= [];
|
|
577
|
+
this.runtimeState.sessionMemory.push(newEntry.data);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Manually trigger user memory update
|
|
584
|
+
*/
|
|
585
|
+
async updateUserMemory(options) {
|
|
586
|
+
await this.ensureInitialized();
|
|
587
|
+
this.userMemoryUpdatePromise ??= this.doUpdateUserMemory(options).finally(() => {
|
|
588
|
+
this.userMemoryUpdatePromise = void 0;
|
|
589
|
+
});
|
|
590
|
+
return this.userMemoryUpdatePromise;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Internal method that performs the actual user memory extraction
|
|
594
|
+
*/
|
|
595
|
+
async doUpdateUserMemory(options) {
|
|
596
|
+
const { extractor } = this.userMemoryConfig ?? {};
|
|
597
|
+
if (!extractor) throw new Error("Cannot update user memory without an extractor agent configured.");
|
|
598
|
+
const sessionFacts = this.runtimeState.sessionMemory?.map((entry) => entry.content).filter(require_utils_type_utils.isNonNullable) ?? [];
|
|
599
|
+
if (sessionFacts.length === 0) return;
|
|
600
|
+
const existingUserFacts = this.runtimeState.userMemory?.map((entry) => entry.content).filter(require_utils_type_utils.isNonNullable) ?? [];
|
|
601
|
+
const result = await options.context.invoke(extractor, {
|
|
602
|
+
sessionFacts,
|
|
603
|
+
existingUserFacts
|
|
604
|
+
});
|
|
605
|
+
if (!result.newFacts.length && !result.removeFacts?.length) return;
|
|
606
|
+
if (this.afs && this.historyModulePath && this.userId) {
|
|
607
|
+
if (result.removeFacts?.length && this.runtimeState.userMemory) {
|
|
608
|
+
const entriesToRemove = [];
|
|
609
|
+
for (const label of result.removeFacts) {
|
|
610
|
+
const entry = this.runtimeState.userMemory.find((e) => e.content?.label === label);
|
|
611
|
+
if (entry) entriesToRemove.push(entry);
|
|
612
|
+
}
|
|
613
|
+
for (const entryToRemove of entriesToRemove) {
|
|
614
|
+
const memoryEntryPath = (0, ufo.joinURL)(this.historyModulePath, "by-user", this.userId, "@metadata/memory", entryToRemove.id);
|
|
615
|
+
await this.afs.delete(memoryEntryPath);
|
|
616
|
+
const index = this.runtimeState.userMemory.indexOf(entryToRemove);
|
|
617
|
+
if (index !== -1) this.runtimeState.userMemory.splice(index, 1);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
if (result.newFacts.length) {
|
|
621
|
+
const userMemoryPath = (0, ufo.joinURL)(this.historyModulePath, "by-user", this.userId, "@metadata/memory/new");
|
|
622
|
+
for (const fact of result.newFacts) {
|
|
623
|
+
const existingEntry = this.runtimeState.userMemory?.find((e) => e.content?.label === fact.label);
|
|
624
|
+
if (existingEntry) {
|
|
625
|
+
const oldEntryPath = (0, ufo.joinURL)(this.historyModulePath, "by-user", this.userId, "@metadata/memory", existingEntry.id);
|
|
626
|
+
await this.afs.delete(oldEntryPath);
|
|
627
|
+
if (this.runtimeState.userMemory) {
|
|
628
|
+
const index = this.runtimeState.userMemory.indexOf(existingEntry);
|
|
629
|
+
if (index !== -1) this.runtimeState.userMemory.splice(index, 1);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const newEntry = await this.afs.write(userMemoryPath, {
|
|
633
|
+
userId: this.userId,
|
|
634
|
+
agentId: this.agentId,
|
|
635
|
+
content: fact
|
|
636
|
+
});
|
|
637
|
+
this.runtimeState.userMemory ??= [];
|
|
638
|
+
this.runtimeState.userMemory.push(newEntry.data);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Find Agent Skill content from a single message
|
|
645
|
+
* @param msg - Message to search in
|
|
646
|
+
* @returns The skill content text if found, undefined otherwise
|
|
647
|
+
*/
|
|
648
|
+
findSkillContentInMessage(msg) {
|
|
649
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
650
|
+
const skillBlock = msg.content.find((block) => block.type === "text" && block.isAgentSkill === true);
|
|
651
|
+
if (skillBlock && skillBlock.type === "text") return skillBlock.text;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Find the last Agent Skill from a list of messages
|
|
656
|
+
* @param messages - Messages to search through
|
|
657
|
+
* @returns The last Agent Skill found, or undefined if none found
|
|
658
|
+
*/
|
|
659
|
+
findLastAgentSkillFromMessages(messages) {
|
|
660
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
661
|
+
const msg = messages[i];
|
|
662
|
+
if (!msg) continue;
|
|
663
|
+
const skillContent = this.findSkillContentInMessage(msg);
|
|
664
|
+
if (skillContent) return { content: skillContent };
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Find the last Agent Skill from a list of history entries
|
|
669
|
+
* @param entries - History entries to search through
|
|
670
|
+
* @returns The last Agent Skill found, or undefined if none found
|
|
671
|
+
*/
|
|
672
|
+
findLastAgentSkill(entries) {
|
|
673
|
+
const allMessages = entries.flatMap((entry) => entry.content?.messages ?? []);
|
|
674
|
+
return this.findLastAgentSkillFromMessages(allMessages);
|
|
675
|
+
}
|
|
676
|
+
async initializeDefaultCompactor() {
|
|
677
|
+
this.compactConfig.compactor ??= await Promise.resolve().then(() => require("./compact/compactor.cjs")).then((m) => new m.AISessionCompactor());
|
|
678
|
+
}
|
|
679
|
+
async initializeDefaultSessionMemoryExtractor() {
|
|
680
|
+
this.sessionMemoryConfig.extractor ??= await Promise.resolve().then(() => require("./compact/session-memory-extractor.cjs")).then((m) => new m.AISessionMemoryExtractor());
|
|
681
|
+
}
|
|
682
|
+
async initializeDefaultUserMemoryExtractor() {
|
|
683
|
+
this.userMemoryConfig.extractor ??= await Promise.resolve().then(() => require("./compact/user-memory-extractor.cjs")).then((m) => new m.AIUserMemoryExtractor());
|
|
684
|
+
}
|
|
685
|
+
get maxTokens() {
|
|
686
|
+
return this.compactConfig?.maxTokens ?? require_types.DEFAULT_MAX_TOKENS;
|
|
687
|
+
}
|
|
688
|
+
get keepRecentRatio() {
|
|
689
|
+
return this.compactConfig?.keepRecentRatio ?? require_types.DEFAULT_KEEP_RECENT_RATIO;
|
|
690
|
+
}
|
|
691
|
+
get keepRecentTokens() {
|
|
692
|
+
return Math.floor(this.maxTokens * this.keepRecentRatio);
|
|
693
|
+
}
|
|
694
|
+
get singleMessageLimit() {
|
|
695
|
+
return this.keepRecentTokens * .5;
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
//#endregion
|
|
700
|
+
exports.AgentSession = AgentSession;
|