@gencode/agents 0.0.8 → 0.0.10
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/dist/builtin-provider-C0d7-NZt.js +66 -0
- package/dist/config/index.d.ts +2 -9
- package/dist/config/index.js +1 -9
- package/dist/config-DG3Q1aJ6.js +1 -0
- package/dist/{index-JD6Ye-N5.d.ts → index-BdfpRxFA.d.ts} +7 -8
- package/dist/index.d.ts +1603 -40
- package/dist/index.js +504 -35
- package/dist/provider-registry-rVbsCDN2.js +1 -0
- package/dist/rolldown-runtime-CNxR59P3.js +1 -0
- package/package.json +2 -2
- package/dist/bootstrap/bootstrap-layout.d.ts +0 -23
- package/dist/bootstrap/bootstrap-layout.d.ts.map +0 -1
- package/dist/bootstrap/bootstrap-layout.js +0 -151
- package/dist/bootstrap/bootstrap-layout.js.map +0 -1
- package/dist/bootstrap/bootstrap.d.ts +0 -36
- package/dist/bootstrap/bootstrap.d.ts.map +0 -1
- package/dist/bootstrap/bootstrap.js +0 -136
- package/dist/bootstrap/bootstrap.js.map +0 -1
- package/dist/bootstrap/templates/AGENTS_MD.d.ts +0 -2
- package/dist/bootstrap/templates/AGENTS_MD.d.ts.map +0 -1
- package/dist/bootstrap/templates/AGENTS_MD.js +0 -223
- package/dist/bootstrap/templates/AGENTS_MD.js.map +0 -1
- package/dist/bootstrap/templates/BOOTSTRAP_MD.d.ts +0 -2
- package/dist/bootstrap/templates/BOOTSTRAP_MD.d.ts.map +0 -1
- package/dist/bootstrap/templates/BOOTSTRAP_MD.js +0 -66
- package/dist/bootstrap/templates/BOOTSTRAP_MD.js.map +0 -1
- package/dist/bootstrap/templates/HEARTBEAT_MD.d.ts +0 -2
- package/dist/bootstrap/templates/HEARTBEAT_MD.d.ts.map +0 -1
- package/dist/bootstrap/templates/HEARTBEAT_MD.js +0 -16
- package/dist/bootstrap/templates/HEARTBEAT_MD.js.map +0 -1
- package/dist/bootstrap/templates/IDENTITY_MD.d.ts +0 -2
- package/dist/bootstrap/templates/IDENTITY_MD.d.ts.map +0 -1
- package/dist/bootstrap/templates/IDENTITY_MD.js +0 -31
- package/dist/bootstrap/templates/IDENTITY_MD.js.map +0 -1
- package/dist/bootstrap/templates/SOUL_MD.d.ts +0 -2
- package/dist/bootstrap/templates/SOUL_MD.d.ts.map +0 -1
- package/dist/bootstrap/templates/SOUL_MD.js +0 -47
- package/dist/bootstrap/templates/SOUL_MD.js.map +0 -1
- package/dist/bootstrap/templates/TOOLS_MD.d.ts +0 -2
- package/dist/bootstrap/templates/TOOLS_MD.d.ts.map +0 -1
- package/dist/bootstrap/templates/TOOLS_MD.js +0 -51
- package/dist/bootstrap/templates/TOOLS_MD.js.map +0 -1
- package/dist/bootstrap/templates/USER_MD.d.ts +0 -2
- package/dist/bootstrap/templates/USER_MD.d.ts.map +0 -1
- package/dist/bootstrap/templates/USER_MD.js +0 -27
- package/dist/bootstrap/templates/USER_MD.js.map +0 -1
- package/dist/bootstrap/templates/index.d.ts +0 -3
- package/dist/bootstrap/templates/index.d.ts.map +0 -1
- package/dist/bootstrap/templates/index.js +0 -26
- package/dist/bootstrap/templates/index.js.map +0 -1
- package/dist/commands/compact.d.ts +0 -28
- package/dist/commands/compact.d.ts.map +0 -1
- package/dist/commands/compact.js +0 -57
- package/dist/commands/compact.js.map +0 -1
- package/dist/commands/help.d.ts +0 -3
- package/dist/commands/help.d.ts.map +0 -1
- package/dist/commands/help.js +0 -50
- package/dist/commands/help.js.map +0 -1
- package/dist/commands/index.d.ts +0 -6
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js +0 -32
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/new.d.ts +0 -3
- package/dist/commands/new.d.ts.map +0 -1
- package/dist/commands/new.js +0 -15
- package/dist/commands/new.js.map +0 -1
- package/dist/commands/registry.d.ts +0 -11
- package/dist/commands/registry.d.ts.map +0 -1
- package/dist/commands/registry.js +0 -122
- package/dist/commands/registry.js.map +0 -1
- package/dist/commands/reset.d.ts +0 -3
- package/dist/commands/reset.d.ts.map +0 -1
- package/dist/commands/reset.js +0 -4
- package/dist/commands/reset.js.map +0 -1
- package/dist/commands/skill.d.ts +0 -7
- package/dist/commands/skill.d.ts.map +0 -1
- package/dist/commands/skill.js +0 -23
- package/dist/commands/skill.js.map +0 -1
- package/dist/commands/types.d.ts +0 -57
- package/dist/commands/types.d.ts.map +0 -1
- package/dist/commands/types.js +0 -2
- package/dist/commands/types.js.map +0 -1
- package/dist/config/agents-config.d.ts +0 -85
- package/dist/config/agents-config.d.ts.map +0 -1
- package/dist/config/agents-config.js +0 -257
- package/dist/config/agents-config.js.map +0 -1
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/types.d.ts +0 -87
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -6
- package/dist/config/types.js.map +0 -1
- package/dist/config-DJX-VM7S.js +0 -198
- package/dist/config-DJX-VM7S.js.map +0 -1
- package/dist/history/compaction.d.ts +0 -42
- package/dist/history/compaction.d.ts.map +0 -1
- package/dist/history/compaction.js +0 -135
- package/dist/history/compaction.js.map +0 -1
- package/dist/history/index.d.ts +0 -57
- package/dist/history/index.d.ts.map +0 -1
- package/dist/history/index.js +0 -145
- package/dist/history/index.js.map +0 -1
- package/dist/history/limit.d.ts +0 -13
- package/dist/history/limit.d.ts.map +0 -1
- package/dist/history/limit.js +0 -32
- package/dist/history/limit.js.map +0 -1
- package/dist/history/repair.d.ts +0 -13
- package/dist/history/repair.d.ts.map +0 -1
- package/dist/history/repair.js +0 -25
- package/dist/history/repair.js.map +0 -1
- package/dist/history/token-estimate.d.ts +0 -22
- package/dist/history/token-estimate.d.ts.map +0 -1
- package/dist/history/token-estimate.js +0 -38
- package/dist/history/token-estimate.js.map +0 -1
- package/dist/index-JD6Ye-N5.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/llm/client.d.ts +0 -53
- package/dist/llm/client.d.ts.map +0 -1
- package/dist/llm/client.js +0 -214
- package/dist/llm/client.js.map +0 -1
- package/dist/llm/openai-completions-compat.d.ts +0 -23
- package/dist/llm/openai-completions-compat.d.ts.map +0 -1
- package/dist/llm/openai-completions-compat.js +0 -602
- package/dist/llm/openai-completions-compat.js.map +0 -1
- package/dist/llm/openai-stream-error.d.ts +0 -11
- package/dist/llm/openai-stream-error.d.ts.map +0 -1
- package/dist/llm/openai-stream-error.js +0 -77
- package/dist/llm/openai-stream-error.js.map +0 -1
- package/dist/loop-detection/session-state.d.ts +0 -5
- package/dist/loop-detection/session-state.d.ts.map +0 -1
- package/dist/loop-detection/session-state.js +0 -16
- package/dist/loop-detection/session-state.js.map +0 -1
- package/dist/loop-detection/tool-loop-detection.d.ts +0 -122
- package/dist/loop-detection/tool-loop-detection.d.ts.map +0 -1
- package/dist/loop-detection/tool-loop-detection.js +0 -516
- package/dist/loop-detection/tool-loop-detection.js.map +0 -1
- package/dist/manager-qXa-NP0p.js +0 -1651
- package/dist/manager-qXa-NP0p.js.map +0 -1
- package/dist/memory/builtin-provider.d.ts +0 -5
- package/dist/memory/builtin-provider.d.ts.map +0 -1
- package/dist/memory/builtin-provider.js +0 -42
- package/dist/memory/builtin-provider.js.map +0 -1
- package/dist/memory/config.d.ts +0 -50
- package/dist/memory/config.d.ts.map +0 -1
- package/dist/memory/config.js +0 -46
- package/dist/memory/config.js.map +0 -1
- package/dist/memory/embedding-registry.d.ts +0 -37
- package/dist/memory/embedding-registry.d.ts.map +0 -1
- package/dist/memory/embedding-registry.js +0 -56
- package/dist/memory/embedding-registry.js.map +0 -1
- package/dist/memory/embeddings.d.ts +0 -11
- package/dist/memory/embeddings.d.ts.map +0 -1
- package/dist/memory/embeddings.js +0 -40
- package/dist/memory/embeddings.js.map +0 -1
- package/dist/memory/fs-utils.d.ts +0 -12
- package/dist/memory/fs-utils.d.ts.map +0 -1
- package/dist/memory/fs-utils.js +0 -24
- package/dist/memory/fs-utils.js.map +0 -1
- package/dist/memory/hybrid.d.ts +0 -43
- package/dist/memory/hybrid.d.ts.map +0 -1
- package/dist/memory/hybrid.js +0 -80
- package/dist/memory/hybrid.js.map +0 -1
- package/dist/memory/internal.d.ts +0 -28
- package/dist/memory/internal.d.ts.map +0 -1
- package/dist/memory/internal.js +0 -270
- package/dist/memory/internal.js.map +0 -1
- package/dist/memory/manager-search.d.ts +0 -61
- package/dist/memory/manager-search.d.ts.map +0 -1
- package/dist/memory/manager-search.js +0 -106
- package/dist/memory/manager-search.js.map +0 -1
- package/dist/memory/manager.d.ts +0 -126
- package/dist/memory/manager.d.ts.map +0 -1
- package/dist/memory/manager.js +0 -1006
- package/dist/memory/manager.js.map +0 -1
- package/dist/memory/memory-schema.d.ts +0 -11
- package/dist/memory/memory-schema.d.ts.map +0 -1
- package/dist/memory/memory-schema.js +0 -78
- package/dist/memory/memory-schema.js.map +0 -1
- package/dist/memory/memory.d.ts +0 -46
- package/dist/memory/memory.d.ts.map +0 -1
- package/dist/memory/memory.js +0 -127
- package/dist/memory/memory.js.map +0 -1
- package/dist/memory/mmr.d.ts +0 -22
- package/dist/memory/mmr.d.ts.map +0 -1
- package/dist/memory/mmr.js +0 -112
- package/dist/memory/mmr.js.map +0 -1
- package/dist/memory/provider-registry.d.ts +0 -29
- package/dist/memory/provider-registry.d.ts.map +0 -1
- package/dist/memory/provider-registry.js +0 -58
- package/dist/memory/provider-registry.js.map +0 -1
- package/dist/memory/provider.d.ts +0 -40
- package/dist/memory/provider.d.ts.map +0 -1
- package/dist/memory/provider.js +0 -2
- package/dist/memory/provider.js.map +0 -1
- package/dist/memory/session-files.d.ts +0 -13
- package/dist/memory/session-files.d.ts.map +0 -1
- package/dist/memory/session-files.js +0 -116
- package/dist/memory/session-files.js.map +0 -1
- package/dist/memory/sqlite-vec.d.ts +0 -10
- package/dist/memory/sqlite-vec.d.ts.map +0 -1
- package/dist/memory/sqlite-vec.js +0 -20
- package/dist/memory/sqlite-vec.js.map +0 -1
- package/dist/memory/sqlite.d.ts +0 -2
- package/dist/memory/sqlite.d.ts.map +0 -1
- package/dist/memory/sqlite.js +0 -12
- package/dist/memory/sqlite.js.map +0 -1
- package/dist/memory/temporal-decay.d.ts +0 -26
- package/dist/memory/temporal-decay.d.ts.map +0 -1
- package/dist/memory/temporal-decay.js +0 -119
- package/dist/memory/temporal-decay.js.map +0 -1
- package/dist/memory/watch-bridge.d.ts +0 -20
- package/dist/memory/watch-bridge.d.ts.map +0 -1
- package/dist/memory/watch-bridge.js +0 -128
- package/dist/memory/watch-bridge.js.map +0 -1
- package/dist/message.d.ts +0 -11
- package/dist/message.d.ts.map +0 -1
- package/dist/message.js +0 -46
- package/dist/message.js.map +0 -1
- package/dist/plugins/boundary-file-read.d.ts +0 -13
- package/dist/plugins/boundary-file-read.d.ts.map +0 -1
- package/dist/plugins/boundary-file-read.js +0 -31
- package/dist/plugins/boundary-file-read.js.map +0 -1
- package/dist/plugins/config-state.d.ts +0 -35
- package/dist/plugins/config-state.d.ts.map +0 -1
- package/dist/plugins/config-state.js +0 -97
- package/dist/plugins/config-state.js.map +0 -1
- package/dist/plugins/discovery.d.ts +0 -21
- package/dist/plugins/discovery.d.ts.map +0 -1
- package/dist/plugins/discovery.js +0 -425
- package/dist/plugins/discovery.js.map +0 -1
- package/dist/plugins/hooks.d.ts +0 -133
- package/dist/plugins/hooks.d.ts.map +0 -1
- package/dist/plugins/hooks.js +0 -19
- package/dist/plugins/hooks.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -20
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -11
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -60
- package/dist/plugins/loader.d.ts.map +0 -1
- package/dist/plugins/loader.js +0 -224
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/manager.d.ts +0 -20
- package/dist/plugins/manager.d.ts.map +0 -1
- package/dist/plugins/manager.js +0 -33
- package/dist/plugins/manager.js.map +0 -1
- package/dist/plugins/manifest-registry.d.ts +0 -15
- package/dist/plugins/manifest-registry.d.ts.map +0 -1
- package/dist/plugins/manifest-registry.js +0 -37
- package/dist/plugins/manifest-registry.js.map +0 -1
- package/dist/plugins/manifest.d.ts +0 -6
- package/dist/plugins/manifest.d.ts.map +0 -1
- package/dist/plugins/manifest.js +0 -80
- package/dist/plugins/manifest.js.map +0 -1
- package/dist/plugins/path-safety.d.ts +0 -6
- package/dist/plugins/path-safety.d.ts.map +0 -1
- package/dist/plugins/path-safety.js +0 -32
- package/dist/plugins/path-safety.js.map +0 -1
- package/dist/plugins/runtime-context.d.ts +0 -12
- package/dist/plugins/runtime-context.d.ts.map +0 -1
- package/dist/plugins/runtime-context.js +0 -2
- package/dist/plugins/runtime-context.js.map +0 -1
- package/dist/plugins/runtime.d.ts +0 -20
- package/dist/plugins/runtime.d.ts.map +0 -1
- package/dist/plugins/runtime.js +0 -33
- package/dist/plugins/runtime.js.map +0 -1
- package/dist/plugins/schema-validator.d.ts +0 -17
- package/dist/plugins/schema-validator.d.ts.map +0 -1
- package/dist/plugins/schema-validator.js +0 -26
- package/dist/plugins/schema-validator.js.map +0 -1
- package/dist/plugins/tool-hooks.d.ts +0 -4
- package/dist/plugins/tool-hooks.d.ts.map +0 -1
- package/dist/plugins/tool-hooks.js +0 -63
- package/dist/plugins/tool-hooks.js.map +0 -1
- package/dist/plugins/tools.d.ts +0 -20
- package/dist/plugins/tools.d.ts.map +0 -1
- package/dist/plugins/tools.js +0 -42
- package/dist/plugins/tools.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -61
- package/dist/plugins/types.d.ts.map +0 -1
- package/dist/plugins/types.js +0 -2
- package/dist/plugins/types.js.map +0 -1
- package/dist/plugins/utils.d.ts +0 -4
- package/dist/plugins/utils.d.ts.map +0 -1
- package/dist/plugins/utils.js +0 -22
- package/dist/plugins/utils.js.map +0 -1
- package/dist/runner/agent-runtime.d.ts +0 -62
- package/dist/runner/agent-runtime.d.ts.map +0 -1
- package/dist/runner/agent-runtime.js +0 -179
- package/dist/runner/agent-runtime.js.map +0 -1
- package/dist/runner/announce-loop.d.ts +0 -41
- package/dist/runner/announce-loop.d.ts.map +0 -1
- package/dist/runner/announce-loop.js +0 -94
- package/dist/runner/announce-loop.js.map +0 -1
- package/dist/runner/event-dispatcher.d.ts +0 -12
- package/dist/runner/event-dispatcher.d.ts.map +0 -1
- package/dist/runner/event-dispatcher.js +0 -18
- package/dist/runner/event-dispatcher.js.map +0 -1
- package/dist/runner/finalizer.d.ts +0 -30
- package/dist/runner/finalizer.d.ts.map +0 -1
- package/dist/runner/finalizer.js +0 -75
- package/dist/runner/finalizer.js.map +0 -1
- package/dist/runner/invocation-resolver.d.ts +0 -67
- package/dist/runner/invocation-resolver.d.ts.map +0 -1
- package/dist/runner/invocation-resolver.js +0 -224
- package/dist/runner/invocation-resolver.js.map +0 -1
- package/dist/runner/plugin-context.d.ts +0 -18
- package/dist/runner/plugin-context.d.ts.map +0 -1
- package/dist/runner/plugin-context.js +0 -26
- package/dist/runner/plugin-context.js.map +0 -1
- package/dist/runner/run-context.d.ts +0 -38
- package/dist/runner/run-context.d.ts.map +0 -1
- package/dist/runner/run-context.js +0 -159
- package/dist/runner/run-context.js.map +0 -1
- package/dist/runner/runner-session.d.ts +0 -34
- package/dist/runner/runner-session.d.ts.map +0 -1
- package/dist/runner/runner-session.js +0 -61
- package/dist/runner/runner-session.js.map +0 -1
- package/dist/runner/runner.d.ts +0 -13
- package/dist/runner/runner.d.ts.map +0 -1
- package/dist/runner/runner.js +0 -234
- package/dist/runner/runner.js.map +0 -1
- package/dist/runner/runtime.d.ts +0 -7
- package/dist/runner/runtime.d.ts.map +0 -1
- package/dist/runner/runtime.js +0 -21
- package/dist/runner/runtime.js.map +0 -1
- package/dist/runner/session-lifecycle.d.ts +0 -31
- package/dist/runner/session-lifecycle.d.ts.map +0 -1
- package/dist/runner/session-lifecycle.js +0 -38
- package/dist/runner/session-lifecycle.js.map +0 -1
- package/dist/runner/skill-usage.d.ts +0 -29
- package/dist/runner/skill-usage.d.ts.map +0 -1
- package/dist/runner/skill-usage.js +0 -65
- package/dist/runner/skill-usage.js.map +0 -1
- package/dist/runner/title.d.ts +0 -3
- package/dist/runner/title.d.ts.map +0 -1
- package/dist/runner/title.js +0 -6
- package/dist/runner/title.js.map +0 -1
- package/dist/runner/turn-executor.d.ts +0 -51
- package/dist/runner/turn-executor.d.ts.map +0 -1
- package/dist/runner/turn-executor.js +0 -294
- package/dist/runner/turn-executor.js.map +0 -1
- package/dist/security/command-dangerous-rules.d.ts +0 -4
- package/dist/security/command-dangerous-rules.d.ts.map +0 -1
- package/dist/security/command-dangerous-rules.js +0 -26
- package/dist/security/command-dangerous-rules.js.map +0 -1
- package/dist/security/command-parser.d.ts +0 -3
- package/dist/security/command-parser.d.ts.map +0 -1
- package/dist/security/command-parser.js +0 -191
- package/dist/security/command-parser.js.map +0 -1
- package/dist/security/command-path-guard.d.ts +0 -10
- package/dist/security/command-path-guard.d.ts.map +0 -1
- package/dist/security/command-path-guard.js +0 -126
- package/dist/security/command-path-guard.js.map +0 -1
- package/dist/security/command-policy-config.d.ts +0 -5
- package/dist/security/command-policy-config.d.ts.map +0 -1
- package/dist/security/command-policy-config.js +0 -212
- package/dist/security/command-policy-config.js.map +0 -1
- package/dist/security/command-policy-engine.d.ts +0 -8
- package/dist/security/command-policy-engine.d.ts.map +0 -1
- package/dist/security/command-policy-engine.js +0 -122
- package/dist/security/command-policy-engine.js.map +0 -1
- package/dist/security/command-policy-types.d.ts +0 -67
- package/dist/security/command-policy-types.d.ts.map +0 -1
- package/dist/security/command-policy-types.js +0 -2
- package/dist/security/command-policy-types.js.map +0 -1
- package/dist/security/command-safe-bins.d.ts +0 -4
- package/dist/security/command-safe-bins.d.ts.map +0 -1
- package/dist/security/command-safe-bins.js +0 -84
- package/dist/security/command-safe-bins.js.map +0 -1
- package/dist/security/command-trusted-executables.d.ts +0 -6
- package/dist/security/command-trusted-executables.d.ts.map +0 -1
- package/dist/security/command-trusted-executables.js +0 -57
- package/dist/security/command-trusted-executables.js.map +0 -1
- package/dist/session/session.d.ts +0 -45
- package/dist/session/session.d.ts.map +0 -1
- package/dist/session/session.js +0 -167
- package/dist/session/session.js.map +0 -1
- package/dist/skills/skills.d.ts +0 -23
- package/dist/skills/skills.d.ts.map +0 -1
- package/dist/skills/skills.js +0 -109
- package/dist/skills/skills.js.map +0 -1
- package/dist/subagent/registry-persist.d.ts +0 -31
- package/dist/subagent/registry-persist.d.ts.map +0 -1
- package/dist/subagent/registry-persist.js +0 -115
- package/dist/subagent/registry-persist.js.map +0 -1
- package/dist/subagent/registry.d.ts +0 -52
- package/dist/subagent/registry.d.ts.map +0 -1
- package/dist/subagent/registry.js +0 -122
- package/dist/subagent/registry.js.map +0 -1
- package/dist/subagent/types.d.ts +0 -20
- package/dist/subagent/types.d.ts.map +0 -1
- package/dist/subagent/types.js +0 -2
- package/dist/subagent/types.js.map +0 -1
- package/dist/system-prompt/builder.d.ts +0 -50
- package/dist/system-prompt/builder.d.ts.map +0 -1
- package/dist/system-prompt/builder.js +0 -335
- package/dist/system-prompt/builder.js.map +0 -1
- package/dist/tools/apply-patch.d.ts +0 -15
- package/dist/tools/apply-patch.d.ts.map +0 -1
- package/dist/tools/apply-patch.js +0 -425
- package/dist/tools/apply-patch.js.map +0 -1
- package/dist/tools/bash.d.ts +0 -11
- package/dist/tools/bash.d.ts.map +0 -1
- package/dist/tools/bash.js +0 -13
- package/dist/tools/bash.js.map +0 -1
- package/dist/tools/cron.d.ts +0 -30
- package/dist/tools/cron.d.ts.map +0 -1
- package/dist/tools/cron.js +0 -57
- package/dist/tools/cron.js.map +0 -1
- package/dist/tools/exec.d.ts +0 -18
- package/dist/tools/exec.d.ts.map +0 -1
- package/dist/tools/exec.js +0 -144
- package/dist/tools/exec.js.map +0 -1
- package/dist/tools/files.d.ts +0 -37
- package/dist/tools/files.d.ts.map +0 -1
- package/dist/tools/files.js +0 -191
- package/dist/tools/files.js.map +0 -1
- package/dist/tools/image.d.ts +0 -14
- package/dist/tools/image.d.ts.map +0 -1
- package/dist/tools/image.js +0 -26
- package/dist/tools/image.js.map +0 -1
- package/dist/tools/index.d.ts +0 -35
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -53
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/memory.d.ts +0 -41
- package/dist/tools/memory.d.ts.map +0 -1
- package/dist/tools/memory.js +0 -114
- package/dist/tools/memory.js.map +0 -1
- package/dist/tools/process-registry.d.ts +0 -47
- package/dist/tools/process-registry.d.ts.map +0 -1
- package/dist/tools/process-registry.js +0 -262
- package/dist/tools/process-registry.js.map +0 -1
- package/dist/tools/process.d.ts +0 -17
- package/dist/tools/process.d.ts.map +0 -1
- package/dist/tools/process.js +0 -114
- package/dist/tools/process.js.map +0 -1
- package/dist/tools/subagent-spawn.d.ts +0 -44
- package/dist/tools/subagent-spawn.d.ts.map +0 -1
- package/dist/tools/subagent-spawn.js +0 -100
- package/dist/tools/subagent-spawn.js.map +0 -1
- package/dist/tools/subagents.d.ts +0 -30
- package/dist/tools/subagents.d.ts.map +0 -1
- package/dist/tools/subagents.js +0 -101
- package/dist/tools/subagents.js.map +0 -1
- package/dist/types.d.ts +0 -153
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
package/dist/config/types.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent configuration types for AIMax multi-agent support.
|
|
3
|
-
* Compatible with the .aimax/agents.json config file.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Single agent configuration.
|
|
7
|
-
* Each agent can have its own model, skills, identity, and subagent settings.
|
|
8
|
-
*/
|
|
9
|
-
export type AgentConfig = {
|
|
10
|
-
/** Unique agent identifier */
|
|
11
|
-
id: string;
|
|
12
|
-
/** Whether this is the default agent */
|
|
13
|
-
default?: boolean;
|
|
14
|
-
/** Display name (overrides identity.name) */
|
|
15
|
-
name?: string;
|
|
16
|
-
/** Model configuration (string or object with primary/fallbacks) */
|
|
17
|
-
model?: string | AgentModelConfig;
|
|
18
|
-
/** Skills allowlist (omit = all skills; empty = none) */
|
|
19
|
-
skills?: string[];
|
|
20
|
-
/** Identity configuration for display/persona */
|
|
21
|
-
identity?: {
|
|
22
|
-
name?: string;
|
|
23
|
-
theme?: string;
|
|
24
|
-
emoji?: string;
|
|
25
|
-
avatar?: string;
|
|
26
|
-
};
|
|
27
|
-
/** Subagent configuration for this agent */
|
|
28
|
-
subagents?: {
|
|
29
|
-
/** Allow spawning subagents under other agent ids. Use "*" to allow any. */
|
|
30
|
-
allowAgents?: string[];
|
|
31
|
-
/** Per-agent default model for spawned subagents (string or {primary,fallbacks}). */
|
|
32
|
-
model?: string | AgentModelConfig;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Model configuration with primary and optional fallbacks.
|
|
37
|
-
*/
|
|
38
|
-
export type AgentModelConfig = {
|
|
39
|
-
primary: string;
|
|
40
|
-
fallbacks?: string[];
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Routing binding configuration.
|
|
44
|
-
* Maps channel/account/peer to a specific agent.
|
|
45
|
-
*/
|
|
46
|
-
export type AgentBinding = {
|
|
47
|
-
/** Target agent ID for this binding */
|
|
48
|
-
agentId: string;
|
|
49
|
-
/** Optional comment/description */
|
|
50
|
-
comment?: string;
|
|
51
|
-
/** Match conditions for this binding */
|
|
52
|
-
match: {
|
|
53
|
-
/** Channel type: H5 | WEB | KLPA | CRON | EIP_ASSISTANT */
|
|
54
|
-
channel: "H5" | "WEB" | "KLPA" | "CRON" | "EIP_ASSISTANT";
|
|
55
|
-
/** Account ID (optional, for multi-account routing) */
|
|
56
|
-
accountId?: string;
|
|
57
|
-
/** User ID (optional, for user-specific routing) */
|
|
58
|
-
userId?: string;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Root agents configuration structure.
|
|
63
|
-
* Stored in .aimax/agents.json
|
|
64
|
-
*/
|
|
65
|
-
export type AgentsConfig = {
|
|
66
|
-
/** List of configured agents */
|
|
67
|
-
agents: AgentConfig[];
|
|
68
|
-
/** Routing bindings (channel -> agent mapping) */
|
|
69
|
-
bindings?: AgentBinding[];
|
|
70
|
-
/** Default configuration (optional) */
|
|
71
|
-
defaults?: {
|
|
72
|
-
model?: string | AgentModelConfig;
|
|
73
|
-
/**
|
|
74
|
-
* Maximum number of recent user turns to keep in context.
|
|
75
|
-
* 0 or undefined means no limit.
|
|
76
|
-
*/
|
|
77
|
-
historyLimit?: number;
|
|
78
|
-
/** LLM-based history compaction settings */
|
|
79
|
-
compaction?: {
|
|
80
|
-
/** Whether to enable automatic LLM summarisation; defaults to true */
|
|
81
|
-
enabled?: boolean;
|
|
82
|
-
/** Fraction of context window that triggers compaction; defaults to 0.6 */
|
|
83
|
-
thresholdRatio?: number;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,8BAA8B;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,wCAAwC;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAClC,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,iDAAiD;IACjD,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;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DELETED
package/dist/config/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/config-DJX-VM7S.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
//#region src/config/agents-config.ts
|
|
5
|
-
/**
|
|
6
|
-
* Agent configuration management for Pingclaw.
|
|
7
|
-
* Handles loading/saving agents.json from .pingclaw directory.
|
|
8
|
-
*/
|
|
9
|
-
const AGENTS_CONFIG_FILE = "agents.json";
|
|
10
|
-
/**
|
|
11
|
-
* Resolves the .pingclaw directory path within a data directory.
|
|
12
|
-
*/
|
|
13
|
-
function pingclawDir(dataDir) {
|
|
14
|
-
return path.join(dataDir, ".pingclaw");
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Resolves the agents configuration file path.
|
|
18
|
-
*/
|
|
19
|
-
function resolveAgentsConfigPath(dataDir) {
|
|
20
|
-
return path.join(pingclawDir(dataDir), AGENTS_CONFIG_FILE);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Resolves the agent-specific directory path.
|
|
24
|
-
*/
|
|
25
|
-
function resolveAgentDir(dataDir, agentId) {
|
|
26
|
-
return path.join(pingclawDir(dataDir), "agents", agentId);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Loads the agents configuration from disk.
|
|
30
|
-
* Returns a default config if the file doesn't exist.
|
|
31
|
-
*/
|
|
32
|
-
async function loadAgentsConfig(dataDir) {
|
|
33
|
-
const configPath = resolveAgentsConfigPath(dataDir);
|
|
34
|
-
try {
|
|
35
|
-
const content = await fs.readFile(configPath, "utf-8");
|
|
36
|
-
const parsed = JSON.parse(content);
|
|
37
|
-
if (!parsed || typeof parsed !== "object") throw new Error("Invalid agents config: not an object");
|
|
38
|
-
if (!Array.isArray(parsed.agents)) parsed.agents = [];
|
|
39
|
-
if (!Array.isArray(parsed.bindings)) parsed.bindings = [];
|
|
40
|
-
return parsed;
|
|
41
|
-
} catch (err) {
|
|
42
|
-
if (err.code === "ENOENT") return { agents: [{
|
|
43
|
-
id: "main",
|
|
44
|
-
default: true
|
|
45
|
-
}] };
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Saves the agents configuration to disk.
|
|
51
|
-
*/
|
|
52
|
-
async function saveAgentsConfig(dataDir, config) {
|
|
53
|
-
const configPath = resolveAgentsConfigPath(dataDir);
|
|
54
|
-
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
55
|
-
await fs.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Lists all valid agent configurations.
|
|
59
|
-
*/
|
|
60
|
-
function listAgents(config) {
|
|
61
|
-
if (!Array.isArray(config.agents)) return [];
|
|
62
|
-
return config.agents.filter((a) => a && typeof a === "object" && typeof a.id === "string");
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Gets the default agent ID.
|
|
66
|
-
* Returns the first agent marked as default, or "main" if none found.
|
|
67
|
-
*/
|
|
68
|
-
function resolveDefaultAgentId(config) {
|
|
69
|
-
return listAgents(config).find((a) => a.default === true)?.id ?? "main";
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Normalizes an agent ID (lowercase, trimmed).
|
|
73
|
-
*/
|
|
74
|
-
function normalizeAgentId(id) {
|
|
75
|
-
if (!id) return "main";
|
|
76
|
-
return id.trim().toLowerCase();
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Gets an agent configuration by ID.
|
|
80
|
-
*/
|
|
81
|
-
function getAgentConfig(config, agentId) {
|
|
82
|
-
const normalizedId = normalizeAgentId(agentId);
|
|
83
|
-
return listAgents(config).find((a) => normalizeAgentId(a.id) === normalizedId);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Lists all routing bindings.
|
|
87
|
-
*/
|
|
88
|
-
function listBindings(config) {
|
|
89
|
-
if (!Array.isArray(config.bindings)) return [];
|
|
90
|
-
return config.bindings.filter((b) => b && typeof b === "object" && typeof b.agentId === "string");
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Resolves the agent ID for a given channel/account/user combination.
|
|
94
|
-
* Returns the agent ID from the first matching binding, or the default agent ID.
|
|
95
|
-
*/
|
|
96
|
-
function resolveAgentIdByBinding(config, channel, accountId, userId) {
|
|
97
|
-
for (const binding of listBindings(config)) {
|
|
98
|
-
const match = binding.match;
|
|
99
|
-
if (!match) continue;
|
|
100
|
-
if (match.channel !== channel) continue;
|
|
101
|
-
if (match.accountId && match.accountId !== accountId) continue;
|
|
102
|
-
if (match.userId && match.userId !== userId) continue;
|
|
103
|
-
return binding.agentId;
|
|
104
|
-
}
|
|
105
|
-
return resolveDefaultAgentId(config);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Resolves the model string from an AgentModelConfig or plain string.
|
|
109
|
-
*/
|
|
110
|
-
function resolveModelString(model) {
|
|
111
|
-
if (!model) return void 0;
|
|
112
|
-
if (typeof model === "string") return model;
|
|
113
|
-
return model.primary;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Resolves the model fallbacks from an AgentModelConfig.
|
|
117
|
-
*/
|
|
118
|
-
function resolveModelFallbacks(model) {
|
|
119
|
-
if (!model || typeof model === "string") return void 0;
|
|
120
|
-
return model.fallbacks;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Adds a new agent to the configuration.
|
|
124
|
-
* Returns false if an agent with the same ID already exists.
|
|
125
|
-
*/
|
|
126
|
-
async function addAgent(dataDir, agent) {
|
|
127
|
-
const config = await loadAgentsConfig(dataDir);
|
|
128
|
-
if (getAgentConfig(config, normalizeAgentId(agent.id))) return false;
|
|
129
|
-
config.agents = config.agents ?? [];
|
|
130
|
-
config.agents.push(agent);
|
|
131
|
-
await saveAgentsConfig(dataDir, config);
|
|
132
|
-
const agentDir = resolveAgentDir(dataDir, agent.id);
|
|
133
|
-
await fs.mkdir(agentDir, { recursive: true });
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Removes an agent from the configuration.
|
|
138
|
-
* Returns false if the agent doesn't exist or is the default agent.
|
|
139
|
-
*/
|
|
140
|
-
async function removeAgent(dataDir, agentId) {
|
|
141
|
-
const config = await loadAgentsConfig(dataDir);
|
|
142
|
-
const normalizedId = normalizeAgentId(agentId);
|
|
143
|
-
const index = config.agents?.findIndex((a) => a && normalizeAgentId(a.id) === normalizedId);
|
|
144
|
-
if (index === void 0 || index < 0) return false;
|
|
145
|
-
if (config.agents?.[index]?.default === true) return false;
|
|
146
|
-
config.agents?.splice(index, 1);
|
|
147
|
-
config.bindings = config.bindings?.filter((b) => normalizeAgentId(b.agentId) !== normalizedId);
|
|
148
|
-
await saveAgentsConfig(dataDir, config);
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Adds a routing binding to the configuration.
|
|
153
|
-
*/
|
|
154
|
-
async function addBinding(dataDir, binding) {
|
|
155
|
-
const config = await loadAgentsConfig(dataDir);
|
|
156
|
-
config.bindings = config.bindings ?? [];
|
|
157
|
-
config.bindings.push(binding);
|
|
158
|
-
await saveAgentsConfig(dataDir, config);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Removes routing bindings matching the given criteria.
|
|
162
|
-
* If channel is "*", removes all bindings for the agent.
|
|
163
|
-
*/
|
|
164
|
-
async function removeBindings(dataDir, agentId, channel, accountId) {
|
|
165
|
-
const config = await loadAgentsConfig(dataDir);
|
|
166
|
-
const normalizedAgentId = normalizeAgentId(agentId);
|
|
167
|
-
const originalLength = config.bindings?.length ?? 0;
|
|
168
|
-
if (channel === "*") config.bindings = config.bindings?.filter((b) => normalizeAgentId(b.agentId) !== normalizedAgentId);
|
|
169
|
-
else config.bindings = config.bindings?.filter((b) => {
|
|
170
|
-
if (normalizeAgentId(b.agentId) !== normalizedAgentId) return true;
|
|
171
|
-
if (channel && b.match?.channel !== channel) return true;
|
|
172
|
-
if (accountId && b.match?.accountId !== accountId) return true;
|
|
173
|
-
return false;
|
|
174
|
-
});
|
|
175
|
-
const removed = originalLength - (config.bindings?.length ?? 0);
|
|
176
|
-
if (removed > 0) await saveAgentsConfig(dataDir, config);
|
|
177
|
-
return removed;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Updates an agent's identity configuration.
|
|
181
|
-
*/
|
|
182
|
-
async function updateAgentIdentity(dataDir, agentId, identity) {
|
|
183
|
-
const config = await loadAgentsConfig(dataDir);
|
|
184
|
-
const agent = getAgentConfig(config, agentId);
|
|
185
|
-
if (!agent) return false;
|
|
186
|
-
const updatedIdentity = { ...agent.identity ?? {} };
|
|
187
|
-
if (identity.name !== void 0) updatedIdentity.name = identity.name;
|
|
188
|
-
if (identity.theme !== void 0) updatedIdentity.theme = identity.theme;
|
|
189
|
-
if (identity.emoji !== void 0) updatedIdentity.emoji = identity.emoji;
|
|
190
|
-
if (identity.avatar !== void 0) updatedIdentity.avatar = identity.avatar;
|
|
191
|
-
agent.identity = updatedIdentity;
|
|
192
|
-
await saveAgentsConfig(dataDir, config);
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
//#endregion
|
|
197
|
-
export { saveAgentsConfig as _, listBindings as a, pingclawDir as c, resolveAgentDir as d, resolveAgentIdByBinding as f, resolveModelString as g, resolveModelFallbacks as h, listAgents as i, removeAgent as l, resolveDefaultAgentId as m, addBinding as n, loadAgentsConfig as o, resolveAgentsConfigPath as p, getAgentConfig as r, normalizeAgentId as s, addAgent as t, removeBindings as u, updateAgentIdentity as v };
|
|
198
|
-
//# sourceMappingURL=config-DJX-VM7S.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-DJX-VM7S.js","names":[],"sources":["../src/config/agents-config.ts"],"sourcesContent":["/**\n * Agent configuration management for Pingclaw.\n * Handles loading/saving agents.json from .pingclaw directory.\n */\n\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { AgentsConfig, AgentConfig, AgentBinding, AgentModelConfig } from \"./types.js\";\n\nexport const AGENTS_CONFIG_FILE = \"agents.json\";\n\n/**\n * Resolves the .pingclaw directory path within a data directory.\n */\nexport function pingclawDir(dataDir: string): string {\n return path.join(dataDir, \".pingclaw\");\n}\n\n/**\n * Resolves the agents configuration file path.\n */\nexport function resolveAgentsConfigPath(dataDir: string): string {\n return path.join(pingclawDir(dataDir), AGENTS_CONFIG_FILE);\n}\n\n/**\n * Resolves the agent-specific directory path.\n */\nexport function resolveAgentDir(dataDir: string, agentId: string): string {\n return path.join(pingclawDir(dataDir), \"agents\", agentId);\n}\n\n/**\n * Loads the agents configuration from disk.\n * Returns a default config if the file doesn't exist.\n */\nexport async function loadAgentsConfig(dataDir: string): Promise<AgentsConfig> {\n const configPath = resolveAgentsConfigPath(dataDir);\n try {\n const content = await fs.readFile(configPath, \"utf-8\");\n const parsed = JSON.parse(content);\n // Validate and normalize the config\n if (!parsed || typeof parsed !== \"object\") {\n throw new Error(\"Invalid agents config: not an object\");\n }\n if (!Array.isArray(parsed.agents)) {\n parsed.agents = [];\n }\n if (!Array.isArray(parsed.bindings)) {\n parsed.bindings = [];\n }\n return parsed as AgentsConfig;\n } catch (err) {\n const code = (err as { code?: string }).code;\n if (code === \"ENOENT\") {\n // Return default config for new installations\n return { agents: [{ id: \"main\", default: true }] };\n }\n throw err;\n }\n}\n\n/**\n * Saves the agents configuration to disk.\n */\nexport async function saveAgentsConfig(\n dataDir: string,\n config: AgentsConfig,\n): Promise<void> {\n const configPath = resolveAgentsConfigPath(dataDir);\n await fs.mkdir(path.dirname(configPath), { recursive: true });\n await fs.writeFile(configPath, JSON.stringify(config, null, 2), \"utf-8\");\n}\n\n/**\n * Lists all valid agent configurations.\n */\nexport function listAgents(config: AgentsConfig): AgentConfig[] {\n if (!Array.isArray(config.agents)) {\n return [];\n }\n return config.agents.filter((a): a is AgentConfig =>\n a && typeof a === \"object\" && typeof a.id === \"string\"\n );\n}\n\n/**\n * Gets the default agent ID.\n * Returns the first agent marked as default, or \"main\" if none found.\n */\nexport function resolveDefaultAgentId(config: AgentsConfig): string {\n const agents = listAgents(config);\n const defaultAgent = agents.find(a => a.default === true);\n return defaultAgent?.id ?? \"main\";\n}\n\n/**\n * Normalizes an agent ID (lowercase, trimmed).\n */\nexport function normalizeAgentId(id: string | undefined): string {\n if (!id) return \"main\";\n return id.trim().toLowerCase();\n}\n\n/**\n * Gets an agent configuration by ID.\n */\nexport function getAgentConfig(\n config: AgentsConfig,\n agentId: string,\n): AgentConfig | undefined {\n const normalizedId = normalizeAgentId(agentId);\n return listAgents(config).find(a => normalizeAgentId(a.id) === normalizedId);\n}\n\n/**\n * Lists all routing bindings.\n */\nexport function listBindings(config: AgentsConfig): AgentBinding[] {\n if (!Array.isArray(config.bindings)) {\n return [];\n }\n return config.bindings.filter((b): b is AgentBinding =>\n b && typeof b === \"object\" && typeof b.agentId === \"string\"\n );\n}\n\n/**\n * Resolves the agent ID for a given channel/account/user combination.\n * Returns the agent ID from the first matching binding, or the default agent ID.\n */\nexport function resolveAgentIdByBinding(\n config: AgentsConfig,\n channel: string,\n accountId?: string,\n userId?: string,\n): string {\n for (const binding of listBindings(config)) {\n const match = binding.match;\n if (!match) continue;\n\n // Match channel\n if (match.channel !== channel) continue;\n\n // Match account if specified\n if (match.accountId && match.accountId !== accountId) continue;\n\n // Match user if specified\n if (match.userId && match.userId !== userId) continue;\n\n return binding.agentId;\n }\n\n // No matching binding, use default agent\n return resolveDefaultAgentId(config);\n}\n\n/**\n * Resolves the model string from an AgentModelConfig or plain string.\n */\nexport function resolveModelString(\n model: string | AgentModelConfig | undefined,\n): string | undefined {\n if (!model) return undefined;\n if (typeof model === \"string\") return model;\n return model.primary;\n}\n\n/**\n * Resolves the model fallbacks from an AgentModelConfig.\n */\nexport function resolveModelFallbacks(\n model: string | AgentModelConfig | undefined,\n): string[] | undefined {\n if (!model || typeof model === \"string\") return undefined;\n return model.fallbacks;\n}\n\n/**\n * Adds a new agent to the configuration.\n * Returns false if an agent with the same ID already exists.\n */\nexport async function addAgent(\n dataDir: string,\n agent: AgentConfig,\n): Promise<boolean> {\n const config = await loadAgentsConfig(dataDir);\n const normalizedId = normalizeAgentId(agent.id);\n\n // Check for existing agent\n if (getAgentConfig(config, normalizedId)) {\n return false;\n }\n\n config.agents = config.agents ?? [];\n config.agents.push(agent);\n await saveAgentsConfig(dataDir, config);\n\n // Create agent directory\n const agentDir = resolveAgentDir(dataDir, agent.id);\n await fs.mkdir(agentDir, { recursive: true });\n\n return true;\n}\n\n/**\n * Removes an agent from the configuration.\n * Returns false if the agent doesn't exist or is the default agent.\n */\nexport async function removeAgent(\n dataDir: string,\n agentId: string,\n): Promise<boolean> {\n const config = await loadAgentsConfig(dataDir);\n const normalizedId = normalizeAgentId(agentId);\n\n const index = config.agents?.findIndex(\n a => a && normalizeAgentId(a.id) === normalizedId\n );\n\n if (index === undefined || index < 0) {\n return false;\n }\n\n // Don't allow removing the default agent\n if (config.agents?.[index]?.default === true) {\n return false;\n }\n\n config.agents?.splice(index, 1);\n\n // Remove associated bindings\n config.bindings = config.bindings?.filter(\n b => normalizeAgentId(b.agentId) !== normalizedId\n );\n\n await saveAgentsConfig(dataDir, config);\n return true;\n}\n\n/**\n * Adds a routing binding to the configuration.\n */\nexport async function addBinding(\n dataDir: string,\n binding: AgentBinding,\n): Promise<void> {\n const config = await loadAgentsConfig(dataDir);\n config.bindings = config.bindings ?? [];\n config.bindings.push(binding);\n await saveAgentsConfig(dataDir, config);\n}\n\n/**\n * Removes routing bindings matching the given criteria.\n * If channel is \"*\", removes all bindings for the agent.\n */\nexport async function removeBindings(\n dataDir: string,\n agentId: string,\n channel?: string,\n accountId?: string,\n): Promise<number> {\n const config = await loadAgentsConfig(dataDir);\n const normalizedAgentId = normalizeAgentId(agentId);\n\n const originalLength = config.bindings?.length ?? 0;\n\n if (channel === \"*\") {\n // Remove all bindings for this agent\n config.bindings = config.bindings?.filter(\n b => normalizeAgentId(b.agentId) !== normalizedAgentId\n );\n } else {\n // Remove matching bindings\n config.bindings = config.bindings?.filter(b => {\n if (normalizeAgentId(b.agentId) !== normalizedAgentId) return true;\n if (channel && b.match?.channel !== channel) return true;\n if (accountId && b.match?.accountId !== accountId) return true;\n return false;\n });\n }\n\n const removed = originalLength - (config.bindings?.length ?? 0);\n if (removed > 0) {\n await saveAgentsConfig(dataDir, config);\n }\n\n return removed;\n}\n\n/**\n * Updates an agent's identity configuration.\n */\nexport async function updateAgentIdentity(\n dataDir: string,\n agentId: string,\n identity: Partial<NonNullable<AgentConfig[\"identity\"]>>,\n): Promise<boolean> {\n const config = await loadAgentsConfig(dataDir);\n const agent = getAgentConfig(config, agentId);\n\n if (!agent) {\n return false;\n }\n\n // Initialize identity if not present\n const currentIdentity = agent.identity ?? {};\n const updatedIdentity: NonNullable<AgentConfig[\"identity\"]> = {\n ...currentIdentity,\n };\n\n // Type-safe property updates\n if (identity.name !== undefined) {\n updatedIdentity.name = identity.name;\n }\n if (identity.theme !== undefined) {\n updatedIdentity.theme = identity.theme;\n }\n if (identity.emoji !== undefined) {\n updatedIdentity.emoji = identity.emoji;\n }\n if (identity.avatar !== undefined) {\n updatedIdentity.avatar = identity.avatar;\n }\n\n agent.identity = updatedIdentity;\n\n await saveAgentsConfig(dataDir, config);\n return true;\n}\n"],"mappings":";;;;;;;;AASA,MAAa,qBAAqB;;;;AAKlC,SAAgB,YAAY,SAAyB;AACnD,QAAO,KAAK,KAAK,SAAS,YAAY;;;;;AAMxC,SAAgB,wBAAwB,SAAyB;AAC/D,QAAO,KAAK,KAAK,YAAY,QAAQ,EAAE,mBAAmB;;;;;AAM5D,SAAgB,gBAAgB,SAAiB,SAAyB;AACxE,Q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E7C,KAAI,CAAC,MACH,QAAO;CAKT,MAAM,kBAAwD,EAC5D,GAFsB,MAAM,YAAY,EAAE,EAG3C;AAGD,KAAI,SAAS,SAAS,OACpB,iBAAgB,OAAO,SAAS;AAElC,KAAI,SAAS,UAAU,OACrB,iBAAgB,QAAQ,SAAS;AAEnC,KAAI,SAAS,UAAU,OACrB,iBAAgB,QAAQ,SAAS;AAEnC,KAAI,SAAS,WAAW,OACtB,iBAAgB,SAAS,SAAS;AAGpC,OAAM,WAAW;AAEjB,OAAM,iBAAiB,SAAS,OAAO;AACvC,QAAO"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { MessageEntry } from "../types.js";
|
|
2
|
-
import type { PluginHookAgentContext, PluginHookRegistry } from "../plugins/hooks.js";
|
|
3
|
-
/** Ratio of context window that triggers compaction when history exceeds it */
|
|
4
|
-
export declare const DEFAULT_COMPACTION_THRESHOLD_RATIO = 0.6;
|
|
5
|
-
export type SummariseParams = {
|
|
6
|
-
entries: MessageEntry[];
|
|
7
|
-
llm: {
|
|
8
|
-
baseUrl: string;
|
|
9
|
-
apiKey: string;
|
|
10
|
-
model: string;
|
|
11
|
-
};
|
|
12
|
-
previousSummary?: string;
|
|
13
|
-
instructions?: string;
|
|
14
|
-
signal?: AbortSignal;
|
|
15
|
-
hooks?: PluginHookRegistry;
|
|
16
|
-
hookCtx?: PluginHookAgentContext;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Call the LLM to produce a summary of the provided entries.
|
|
20
|
-
* If `previousSummary` is given, the LLM is asked to incorporate it so the
|
|
21
|
-
* new summary builds on prior compaction rounds.
|
|
22
|
-
*/
|
|
23
|
-
export declare function generateSummary(params: SummariseParams): Promise<string>;
|
|
24
|
-
/**
|
|
25
|
-
* Return true when the total estimated token count of `entries` exceeds the
|
|
26
|
-
* compaction threshold fraction of `contextWindowTokens`.
|
|
27
|
-
*/
|
|
28
|
-
export declare function shouldCompact(params: {
|
|
29
|
-
entries: MessageEntry[];
|
|
30
|
-
contextWindowTokens: number;
|
|
31
|
-
thresholdRatio?: number;
|
|
32
|
-
}): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Partition `entries` into two slices:
|
|
35
|
-
* - `toKeep`: the most-recent entries that fit within the keep budget
|
|
36
|
-
* - `toSummarise`: the older entries that will be summarised
|
|
37
|
-
*/
|
|
38
|
-
export declare function splitForCompaction(entries: MessageEntry[], contextWindowTokens: number): {
|
|
39
|
-
toKeep: MessageEntry[];
|
|
40
|
-
toSummarise: MessageEntry[];
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=compaction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../src/history/compaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEtF,+EAA+E;AAC/E,eAAO,MAAM,kCAAkC,MAAM,CAAC;AAsBtD,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,GAAG,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAwC9E;AA+CD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAKV;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,YAAY,EAAE,EACvB,mBAAmB,EAAE,MAAM,GAC1B;IAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IAAC,WAAW,EAAE,YAAY,EAAE,CAAA;CAAE,CAgBzD"}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { estimateEntryTokens, estimateEntriesTokens } from "./token-estimate.js";
|
|
2
|
-
import { createLlmClient } from "../llm/client.js";
|
|
3
|
-
/** Ratio of context window that triggers compaction when history exceeds it */
|
|
4
|
-
export const DEFAULT_COMPACTION_THRESHOLD_RATIO = 0.6;
|
|
5
|
-
/**
|
|
6
|
-
* Ratio of context window reserved for the message slice kept after compaction.
|
|
7
|
-
* The older portion (beyond this budget) is summarised.
|
|
8
|
-
*/
|
|
9
|
-
const KEEP_BUDGET_RATIO = 0.35;
|
|
10
|
-
const SUMMARIZATION_PROMPT = [
|
|
11
|
-
"You are a conversation history summariser. Compress the conversation below into a concise summary.",
|
|
12
|
-
"",
|
|
13
|
-
"MUST PRESERVE:",
|
|
14
|
-
"- Active tasks and their current status (including batch progress e.g. '5/17 items done')",
|
|
15
|
-
"- The last thing the user requested and what was being done about it",
|
|
16
|
-
"- Decisions made and their rationale",
|
|
17
|
-
"- TODOs, open questions, and constraints",
|
|
18
|
-
"- All opaque identifiers exactly as written: UUIDs, hashes, file paths, URLs, IPs, ports (never shorten or reconstruct them)",
|
|
19
|
-
"",
|
|
20
|
-
"Prioritise recent context over older history.",
|
|
21
|
-
"Output only the summary text — no preamble, no headings.",
|
|
22
|
-
].join("\n");
|
|
23
|
-
/**
|
|
24
|
-
* Call the LLM to produce a summary of the provided entries.
|
|
25
|
-
* If `previousSummary` is given, the LLM is asked to incorporate it so the
|
|
26
|
-
* new summary builds on prior compaction rounds.
|
|
27
|
-
*/
|
|
28
|
-
export async function generateSummary(params) {
|
|
29
|
-
const { entries, llm, previousSummary, instructions, signal, hooks, hookCtx } = params;
|
|
30
|
-
const userContent = buildSummarisationUserMessage(entries, previousSummary, instructions);
|
|
31
|
-
const MAX_ATTEMPTS = 3;
|
|
32
|
-
let lastError;
|
|
33
|
-
const client = createLlmClient({
|
|
34
|
-
baseUrl: llm.baseUrl,
|
|
35
|
-
apiKey: llm.apiKey,
|
|
36
|
-
defaultModel: llm.model,
|
|
37
|
-
hooks,
|
|
38
|
-
hookCtx,
|
|
39
|
-
});
|
|
40
|
-
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
41
|
-
try {
|
|
42
|
-
const result = await client.chat({
|
|
43
|
-
system: SUMMARIZATION_PROMPT,
|
|
44
|
-
user: userContent,
|
|
45
|
-
temperature: 0,
|
|
46
|
-
maxTokens: 2048,
|
|
47
|
-
signal,
|
|
48
|
-
});
|
|
49
|
-
const text = result.text.trim();
|
|
50
|
-
if (!text) {
|
|
51
|
-
throw new Error("LLM summarisation returned empty content");
|
|
52
|
-
}
|
|
53
|
-
return text;
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
if (err instanceof Error && err.name === "AbortError")
|
|
57
|
-
throw err;
|
|
58
|
-
lastError = err;
|
|
59
|
-
if (attempt < MAX_ATTEMPTS) {
|
|
60
|
-
// Simple backoff: 500ms, 1000ms between retries
|
|
61
|
-
await sleep(500 * attempt);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
throw lastError;
|
|
66
|
-
}
|
|
67
|
-
function sleep(ms) {
|
|
68
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
69
|
-
}
|
|
70
|
-
function buildSummarisationUserMessage(entries, previousSummary, instructions) {
|
|
71
|
-
const parts = [];
|
|
72
|
-
if (instructions?.trim()) {
|
|
73
|
-
parts.push(`[Extra instructions]\n${instructions.trim()}\n`);
|
|
74
|
-
}
|
|
75
|
-
if (previousSummary?.trim()) {
|
|
76
|
-
parts.push(`[Prior summary]\n${previousSummary.trim()}\n`);
|
|
77
|
-
parts.push("[Conversation to incorporate]");
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
parts.push("[Conversation to summarise]");
|
|
81
|
-
}
|
|
82
|
-
for (const entry of entries) {
|
|
83
|
-
if (entry.role === "user") {
|
|
84
|
-
parts.push(`User: ${entry.content}`);
|
|
85
|
-
}
|
|
86
|
-
else if (entry.role === "assistant") {
|
|
87
|
-
const toolLine = entry.toolCalls && entry.toolCalls.length > 0
|
|
88
|
-
? ` [called tools: ${entry.toolCalls.map((t) => t.name).join(", ")}]`
|
|
89
|
-
: "";
|
|
90
|
-
parts.push(`Assistant:${toolLine} ${entry.content}`.trimEnd());
|
|
91
|
-
}
|
|
92
|
-
else if (entry.role === "tool_result") {
|
|
93
|
-
const status = entry.isError ? "error" : "ok";
|
|
94
|
-
// Truncate very long tool outputs to avoid blowing the summarisation context
|
|
95
|
-
const truncated = entry.content.length > 2000
|
|
96
|
-
? `${entry.content.slice(0, 2000)}… [truncated]`
|
|
97
|
-
: entry.content;
|
|
98
|
-
parts.push(`Tool(${entry.toolName})[${status}]: ${truncated}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return parts.join("\n");
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Return true when the total estimated token count of `entries` exceeds the
|
|
105
|
-
* compaction threshold fraction of `contextWindowTokens`.
|
|
106
|
-
*/
|
|
107
|
-
export function shouldCompact(params) {
|
|
108
|
-
const { entries, contextWindowTokens, thresholdRatio = DEFAULT_COMPACTION_THRESHOLD_RATIO } = params;
|
|
109
|
-
if (entries.length === 0)
|
|
110
|
-
return false;
|
|
111
|
-
const threshold = Math.floor(contextWindowTokens * thresholdRatio);
|
|
112
|
-
return estimateEntriesTokens(entries) > threshold;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Partition `entries` into two slices:
|
|
116
|
-
* - `toKeep`: the most-recent entries that fit within the keep budget
|
|
117
|
-
* - `toSummarise`: the older entries that will be summarised
|
|
118
|
-
*/
|
|
119
|
-
export function splitForCompaction(entries, contextWindowTokens) {
|
|
120
|
-
const keepBudget = Math.floor(contextWindowTokens * KEEP_BUDGET_RATIO);
|
|
121
|
-
let accumulated = 0;
|
|
122
|
-
let keepFrom = entries.length; // default: summarise everything
|
|
123
|
-
for (let i = entries.length - 1; i >= 0; i--) {
|
|
124
|
-
const t = estimateEntryTokens(entries[i]);
|
|
125
|
-
if (accumulated + t > keepBudget)
|
|
126
|
-
break;
|
|
127
|
-
accumulated += t;
|
|
128
|
-
keepFrom = i;
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
toKeep: entries.slice(keepFrom),
|
|
132
|
-
toSummarise: entries.slice(0, keepFrom),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
//# sourceMappingURL=compaction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compaction.js","sourceRoot":"","sources":["../../src/history/compaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kCAAkC,GAAG,GAAG,CAAC;AAEtD;;;GAGG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,oBAAoB,GAAG;IAC3B,oGAAoG;IACpG,EAAE;IACF,gBAAgB;IAChB,2FAA2F;IAC3F,sEAAsE;IACtE,sCAAsC;IACtC,0CAA0C;IAC1C,8HAA8H;IAC9H,EAAE;IACF,+CAA+C;IAC/C,0DAA0D;CAC3D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAYb;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAu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O,CAAC,MAAM,CAAC,CAAC,gCAAgC;IAE/D,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,WAAW,GAAG,CAAC,GAAG,UAAU;YAAE,MAAM;QACxC,WAAW,IAAI,CAAC,CAAC;QACjB,QAAQ,GAAG,CAAC,CAAC;IACf,CAAC;IAED,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC/B,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC;KACxC,CAAC;AACJ,CAAC"}
|
package/dist/history/index.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
|
2
|
-
import type { TranscriptEntry, MessageEntry, CompactionEntry } from "../types.js";
|
|
3
|
-
import type { PluginHookAgentContext, PluginHookRegistry } from "../plugins/hooks.js";
|
|
4
|
-
export type ManageHistoryParams = {
|
|
5
|
-
/** Full transcript entries including any prior compaction records */
|
|
6
|
-
entries: TranscriptEntry[];
|
|
7
|
-
modelInfo: {
|
|
8
|
-
model: string;
|
|
9
|
-
api: string;
|
|
10
|
-
};
|
|
11
|
-
contextWindowTokens: number;
|
|
12
|
-
llm: {
|
|
13
|
-
baseUrl: string;
|
|
14
|
-
apiKey: string;
|
|
15
|
-
model: string;
|
|
16
|
-
};
|
|
17
|
-
/** Max user turns to keep; 0/undefined = no limit */
|
|
18
|
-
historyLimit?: number;
|
|
19
|
-
/** Set to false to skip LLM-based compaction; defaults to true */
|
|
20
|
-
compactionEnabled?: boolean;
|
|
21
|
-
/** Fraction of context window that triggers compaction; defaults to 0.6 */
|
|
22
|
-
thresholdRatio?: number;
|
|
23
|
-
signal?: AbortSignal;
|
|
24
|
-
hooks?: PluginHookRegistry;
|
|
25
|
-
hookCtx?: PluginHookAgentContext;
|
|
26
|
-
};
|
|
27
|
-
export type HistoryManagementResult = {
|
|
28
|
-
/** Messages ready to pass to agent.replaceMessages() */
|
|
29
|
-
messages: AgentMessage[];
|
|
30
|
-
/** Summary text to inject into the system prompt (from existing or new compaction) */
|
|
31
|
-
priorSummary: string | undefined;
|
|
32
|
-
/** New compaction record to append to the transcript (undefined if no compaction ran) */
|
|
33
|
-
compactionEntry: CompactionEntry | undefined;
|
|
34
|
-
stats: {
|
|
35
|
-
originalCount: number;
|
|
36
|
-
keptCount: number;
|
|
37
|
-
estimatedTokens: number;
|
|
38
|
-
compacted: boolean;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Manage conversation history before each agent run:
|
|
43
|
-
* 1. Extract message entries that follow the last compaction record.
|
|
44
|
-
* 2. Apply the turn limit (drop oldest user turns beyond `historyLimit`).
|
|
45
|
-
* 3. Repair orphaned tool_result entries created by truncation.
|
|
46
|
-
* 4. If token count exceeds the threshold, generate an LLM summary and
|
|
47
|
-
* return a compaction record to persist.
|
|
48
|
-
*/
|
|
49
|
-
export declare function manageHistory(params: ManageHistoryParams): Promise<HistoryManagementResult>;
|
|
50
|
-
/**
|
|
51
|
-
* Convert MessageEntry[] to AgentMessage[] for use with agent.replaceMessages().
|
|
52
|
-
*/
|
|
53
|
-
export declare function entriesToMessages(entries: MessageEntry[], modelInfo: {
|
|
54
|
-
model: string;
|
|
55
|
-
api: string;
|
|
56
|
-
}): AgentMessage[];
|
|
57
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/history/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAIZ,e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