overai 1.4.0
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 +248 -0
- package/dist/agent/context.d.ts +74 -0
- package/dist/agent/context.js +140 -0
- package/dist/agent/enhanced.d.ts +98 -0
- package/dist/agent/enhanced.js +293 -0
- package/dist/agent/handoff.d.ts +82 -0
- package/dist/agent/handoff.js +124 -0
- package/dist/agent/image.d.ts +57 -0
- package/dist/agent/image.js +116 -0
- package/dist/agent/index.d.ts +19 -0
- package/dist/agent/index.js +38 -0
- package/dist/agent/prompt-expander.d.ts +43 -0
- package/dist/agent/prompt-expander.js +99 -0
- package/dist/agent/proxy.d.ts +26 -0
- package/dist/agent/proxy.js +173 -0
- package/dist/agent/query-rewriter.d.ts +41 -0
- package/dist/agent/query-rewriter.js +94 -0
- package/dist/agent/research.d.ts +55 -0
- package/dist/agent/research.js +134 -0
- package/dist/agent/router.d.ts +141 -0
- package/dist/agent/router.js +209 -0
- package/dist/agent/simple.d.ts +289 -0
- package/dist/agent/simple.js +696 -0
- package/dist/agent/types.d.ts +56 -0
- package/dist/agent/types.js +165 -0
- package/dist/ai/agent-loop.d.ts +177 -0
- package/dist/ai/agent-loop.js +313 -0
- package/dist/ai/devtools.d.ts +74 -0
- package/dist/ai/devtools.js +216 -0
- package/dist/ai/embed.d.ts +71 -0
- package/dist/ai/embed.js +154 -0
- package/dist/ai/generate-image.d.ts +66 -0
- package/dist/ai/generate-image.js +138 -0
- package/dist/ai/generate-object.d.ts +132 -0
- package/dist/ai/generate-object.js +206 -0
- package/dist/ai/generate-text.d.ts +201 -0
- package/dist/ai/generate-text.js +253 -0
- package/dist/ai/index.d.ts +27 -0
- package/dist/ai/index.js +140 -0
- package/dist/ai/mcp.d.ts +181 -0
- package/dist/ai/mcp.js +234 -0
- package/dist/ai/middleware.d.ts +110 -0
- package/dist/ai/middleware.js +186 -0
- package/dist/ai/models.d.ts +67 -0
- package/dist/ai/models.js +249 -0
- package/dist/ai/multimodal.d.ts +125 -0
- package/dist/ai/multimodal.js +270 -0
- package/dist/ai/nextjs.d.ts +122 -0
- package/dist/ai/nextjs.js +218 -0
- package/dist/ai/server.d.ts +126 -0
- package/dist/ai/server.js +336 -0
- package/dist/ai/speech.d.ts +135 -0
- package/dist/ai/speech.js +296 -0
- package/dist/ai/telemetry.d.ts +162 -0
- package/dist/ai/telemetry.js +311 -0
- package/dist/ai/tool-approval.d.ts +225 -0
- package/dist/ai/tool-approval.js +407 -0
- package/dist/ai/tools.d.ts +93 -0
- package/dist/ai/tools.js +89 -0
- package/dist/ai/types.d.ts +47 -0
- package/dist/ai/types.js +5 -0
- package/dist/ai/ui-message.d.ts +218 -0
- package/dist/ai/ui-message.js +291 -0
- package/dist/auto/index.d.ts +62 -0
- package/dist/auto/index.js +163 -0
- package/dist/cache/index.d.ts +78 -0
- package/dist/cache/index.js +235 -0
- package/dist/cli/commands/agent.d.ts +30 -0
- package/dist/cli/commands/agent.js +151 -0
- package/dist/cli/commands/agents.d.ts +24 -0
- package/dist/cli/commands/agents.js +166 -0
- package/dist/cli/commands/approval.d.ts +10 -0
- package/dist/cli/commands/approval.js +253 -0
- package/dist/cli/commands/auto.d.ts +12 -0
- package/dist/cli/commands/auto.js +109 -0
- package/dist/cli/commands/autonomy.d.ts +5 -0
- package/dist/cli/commands/autonomy.js +152 -0
- package/dist/cli/commands/benchmark.d.ts +19 -0
- package/dist/cli/commands/benchmark.js +484 -0
- package/dist/cli/commands/cache.d.ts +9 -0
- package/dist/cli/commands/cache.js +143 -0
- package/dist/cli/commands/chat.d.ts +14 -0
- package/dist/cli/commands/chat.js +127 -0
- package/dist/cli/commands/checkpoints.d.ts +5 -0
- package/dist/cli/commands/checkpoints.js +236 -0
- package/dist/cli/commands/context.d.ts +11 -0
- package/dist/cli/commands/context.js +182 -0
- package/dist/cli/commands/cost.d.ts +5 -0
- package/dist/cli/commands/cost.js +146 -0
- package/dist/cli/commands/db.d.ts +9 -0
- package/dist/cli/commands/db.js +149 -0
- package/dist/cli/commands/embed.d.ts +20 -0
- package/dist/cli/commands/embed.js +375 -0
- package/dist/cli/commands/eval.d.ts +17 -0
- package/dist/cli/commands/eval.js +247 -0
- package/dist/cli/commands/external-agents.d.ts +5 -0
- package/dist/cli/commands/external-agents.js +170 -0
- package/dist/cli/commands/fast-context.d.ts +5 -0
- package/dist/cli/commands/fast-context.js +126 -0
- package/dist/cli/commands/flow.d.ts +5 -0
- package/dist/cli/commands/flow.js +141 -0
- package/dist/cli/commands/git.d.ts +5 -0
- package/dist/cli/commands/git.js +178 -0
- package/dist/cli/commands/graph-rag.d.ts +9 -0
- package/dist/cli/commands/graph-rag.js +131 -0
- package/dist/cli/commands/guardrail.d.ts +11 -0
- package/dist/cli/commands/guardrail.js +156 -0
- package/dist/cli/commands/handoff.d.ts +9 -0
- package/dist/cli/commands/handoff.js +133 -0
- package/dist/cli/commands/help.d.ts +8 -0
- package/dist/cli/commands/help.js +139 -0
- package/dist/cli/commands/image.d.ts +13 -0
- package/dist/cli/commands/image.js +192 -0
- package/dist/cli/commands/interactive.d.ts +6 -0
- package/dist/cli/commands/interactive.js +79 -0
- package/dist/cli/commands/jobs.d.ts +5 -0
- package/dist/cli/commands/jobs.js +282 -0
- package/dist/cli/commands/knowledge.d.ts +9 -0
- package/dist/cli/commands/knowledge.js +226 -0
- package/dist/cli/commands/llm.d.ts +21 -0
- package/dist/cli/commands/llm.js +748 -0
- package/dist/cli/commands/mcp.d.ts +9 -0
- package/dist/cli/commands/mcp.js +243 -0
- package/dist/cli/commands/memory.d.ts +10 -0
- package/dist/cli/commands/memory.js +198 -0
- package/dist/cli/commands/n8n.d.ts +5 -0
- package/dist/cli/commands/n8n.js +137 -0
- package/dist/cli/commands/observability.d.ts +16 -0
- package/dist/cli/commands/observability.js +335 -0
- package/dist/cli/commands/planning.d.ts +9 -0
- package/dist/cli/commands/planning.js +167 -0
- package/dist/cli/commands/prompt-expand.d.ts +11 -0
- package/dist/cli/commands/prompt-expand.js +100 -0
- package/dist/cli/commands/providers.d.ts +17 -0
- package/dist/cli/commands/providers.js +386 -0
- package/dist/cli/commands/query-rewrite.d.ts +12 -0
- package/dist/cli/commands/query-rewrite.js +102 -0
- package/dist/cli/commands/repo-map.d.ts +5 -0
- package/dist/cli/commands/repo-map.js +151 -0
- package/dist/cli/commands/reranker.d.ts +10 -0
- package/dist/cli/commands/reranker.js +144 -0
- package/dist/cli/commands/research.d.ts +12 -0
- package/dist/cli/commands/research.js +108 -0
- package/dist/cli/commands/router.d.ts +11 -0
- package/dist/cli/commands/router.js +142 -0
- package/dist/cli/commands/run.d.ts +14 -0
- package/dist/cli/commands/run.js +111 -0
- package/dist/cli/commands/sandbox.d.ts +5 -0
- package/dist/cli/commands/sandbox.js +135 -0
- package/dist/cli/commands/scheduler.d.ts +5 -0
- package/dist/cli/commands/scheduler.js +260 -0
- package/dist/cli/commands/session.d.ts +9 -0
- package/dist/cli/commands/session.js +238 -0
- package/dist/cli/commands/skills.d.ts +9 -0
- package/dist/cli/commands/skills.js +256 -0
- package/dist/cli/commands/telemetry.d.ts +9 -0
- package/dist/cli/commands/telemetry.js +146 -0
- package/dist/cli/commands/tools.d.ts +19 -0
- package/dist/cli/commands/tools.js +576 -0
- package/dist/cli/commands/vector.d.ts +10 -0
- package/dist/cli/commands/vector.js +171 -0
- package/dist/cli/commands/version.d.ts +8 -0
- package/dist/cli/commands/version.js +40 -0
- package/dist/cli/commands/voice.d.ts +10 -0
- package/dist/cli/commands/voice.js +162 -0
- package/dist/cli/commands/workflow.d.ts +13 -0
- package/dist/cli/commands/workflow.js +184 -0
- package/dist/cli/config/index.d.ts +6 -0
- package/dist/cli/config/index.js +22 -0
- package/dist/cli/config/load.d.ts +20 -0
- package/dist/cli/config/load.js +229 -0
- package/dist/cli/config/resolve.d.ts +28 -0
- package/dist/cli/config/resolve.js +70 -0
- package/dist/cli/config/schema.d.ts +15 -0
- package/dist/cli/config/schema.js +65 -0
- package/dist/cli/features/autonomy-mode.d.ts +98 -0
- package/dist/cli/features/autonomy-mode.js +266 -0
- package/dist/cli/features/background-jobs.d.ts +155 -0
- package/dist/cli/features/background-jobs.js +416 -0
- package/dist/cli/features/checkpoints.d.ts +126 -0
- package/dist/cli/features/checkpoints.js +288 -0
- package/dist/cli/features/cost-tracker.d.ts +101 -0
- package/dist/cli/features/cost-tracker.js +212 -0
- package/dist/cli/features/external-agents.d.ts +117 -0
- package/dist/cli/features/external-agents.js +296 -0
- package/dist/cli/features/fast-context.d.ts +126 -0
- package/dist/cli/features/fast-context.js +310 -0
- package/dist/cli/features/flow-display.d.ts +100 -0
- package/dist/cli/features/flow-display.js +254 -0
- package/dist/cli/features/git-integration.d.ts +138 -0
- package/dist/cli/features/git-integration.js +374 -0
- package/dist/cli/features/index.d.ts +17 -0
- package/dist/cli/features/index.js +102 -0
- package/dist/cli/features/interactive-tui.d.ts +114 -0
- package/dist/cli/features/interactive-tui.js +326 -0
- package/dist/cli/features/n8n-integration.d.ts +111 -0
- package/dist/cli/features/n8n-integration.js +299 -0
- package/dist/cli/features/repo-map.d.ts +101 -0
- package/dist/cli/features/repo-map.js +350 -0
- package/dist/cli/features/sandbox-executor.d.ts +89 -0
- package/dist/cli/features/sandbox-executor.js +314 -0
- package/dist/cli/features/scheduler.d.ts +111 -0
- package/dist/cli/features/scheduler.js +298 -0
- package/dist/cli/features/slash-commands.d.ts +77 -0
- package/dist/cli/features/slash-commands.js +316 -0
- package/dist/cli/index.d.ts +24 -0
- package/dist/cli/index.js +214 -0
- package/dist/cli/output/errors.d.ts +23 -0
- package/dist/cli/output/errors.js +36 -0
- package/dist/cli/output/json.d.ts +27 -0
- package/dist/cli/output/json.js +31 -0
- package/dist/cli/output/pretty.d.ts +13 -0
- package/dist/cli/output/pretty.js +31 -0
- package/dist/cli/runtime/env.d.ts +12 -0
- package/dist/cli/runtime/env.js +55 -0
- package/dist/cli/runtime/exit.d.ts +11 -0
- package/dist/cli/runtime/exit.js +49 -0
- package/dist/cli/runtime/index.d.ts +6 -0
- package/dist/cli/runtime/index.js +22 -0
- package/dist/cli/runtime/lazy.d.ts +18 -0
- package/dist/cli/runtime/lazy.js +85 -0
- package/dist/cli/spec/cli-spec.d.ts +87 -0
- package/dist/cli/spec/cli-spec.js +551 -0
- package/dist/cli/spec/index.d.ts +4 -0
- package/dist/cli/spec/index.js +20 -0
- package/dist/db/index.d.ts +6 -0
- package/dist/db/index.js +75 -0
- package/dist/db/types.d.ts +42 -0
- package/dist/db/types.js +2 -0
- package/dist/eval/index.d.ts +61 -0
- package/dist/eval/index.js +157 -0
- package/dist/events/index.d.ts +84 -0
- package/dist/events/index.js +153 -0
- package/dist/guardrails/index.d.ts +82 -0
- package/dist/guardrails/index.js +202 -0
- package/dist/guardrails/llm-guardrail.d.ts +46 -0
- package/dist/guardrails/llm-guardrail.js +112 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +608 -0
- package/dist/integrations/computer-use.d.ts +182 -0
- package/dist/integrations/computer-use.js +356 -0
- package/dist/integrations/index.d.ts +7 -0
- package/dist/integrations/index.js +26 -0
- package/dist/integrations/observability/base.d.ts +123 -0
- package/dist/integrations/observability/base.js +183 -0
- package/dist/integrations/observability/index.d.ts +8 -0
- package/dist/integrations/observability/index.js +29 -0
- package/dist/integrations/observability/langfuse.d.ts +32 -0
- package/dist/integrations/observability/langfuse.js +174 -0
- package/dist/integrations/postgres.d.ts +162 -0
- package/dist/integrations/postgres.js +396 -0
- package/dist/integrations/slack.d.ts +145 -0
- package/dist/integrations/slack.js +270 -0
- package/dist/integrations/vector/base.d.ts +110 -0
- package/dist/integrations/vector/base.js +158 -0
- package/dist/integrations/vector/chroma.d.ts +25 -0
- package/dist/integrations/vector/chroma.js +143 -0
- package/dist/integrations/vector/index.d.ts +14 -0
- package/dist/integrations/vector/index.js +37 -0
- package/dist/integrations/vector/pinecone.d.ts +28 -0
- package/dist/integrations/vector/pinecone.js +172 -0
- package/dist/integrations/vector/qdrant.d.ts +25 -0
- package/dist/integrations/vector/qdrant.js +146 -0
- package/dist/integrations/vector/weaviate.d.ts +30 -0
- package/dist/integrations/vector/weaviate.js +206 -0
- package/dist/integrations/voice/base.d.ts +76 -0
- package/dist/integrations/voice/base.js +168 -0
- package/dist/integrations/voice/index.d.ts +6 -0
- package/dist/integrations/voice/index.js +26 -0
- package/dist/knowledge/chunking.d.ts +55 -0
- package/dist/knowledge/chunking.js +158 -0
- package/dist/knowledge/graph-rag.d.ts +125 -0
- package/dist/knowledge/graph-rag.js +289 -0
- package/dist/knowledge/index.d.ts +24 -0
- package/dist/knowledge/index.js +47 -0
- package/dist/knowledge/knowledge.d.ts +0 -0
- package/dist/knowledge/knowledge.js +1 -0
- package/dist/knowledge/rag.d.ts +80 -0
- package/dist/knowledge/rag.js +147 -0
- package/dist/knowledge/reranker.d.ts +86 -0
- package/dist/knowledge/reranker.js +196 -0
- package/dist/llm/backend-resolver.d.ts +77 -0
- package/dist/llm/backend-resolver.js +242 -0
- package/dist/llm/embeddings.d.ts +66 -0
- package/dist/llm/embeddings.js +294 -0
- package/dist/llm/index.d.ts +29 -0
- package/dist/llm/index.js +33 -0
- package/dist/llm/llm.d.ts +0 -0
- package/dist/llm/llm.js +1 -0
- package/dist/llm/openai.d.ts +39 -0
- package/dist/llm/openai.js +302 -0
- package/dist/llm/providers/ai-sdk/adapter.d.ts +121 -0
- package/dist/llm/providers/ai-sdk/adapter.js +399 -0
- package/dist/llm/providers/ai-sdk/backend.d.ts +49 -0
- package/dist/llm/providers/ai-sdk/backend.js +421 -0
- package/dist/llm/providers/ai-sdk/index.d.ts +69 -0
- package/dist/llm/providers/ai-sdk/index.js +200 -0
- package/dist/llm/providers/ai-sdk/middleware.d.ts +60 -0
- package/dist/llm/providers/ai-sdk/middleware.js +262 -0
- package/dist/llm/providers/ai-sdk/provider-map.d.ts +75 -0
- package/dist/llm/providers/ai-sdk/provider-map.js +258 -0
- package/dist/llm/providers/ai-sdk/types.d.ts +217 -0
- package/dist/llm/providers/ai-sdk/types.js +222 -0
- package/dist/llm/providers/anthropic.d.ts +33 -0
- package/dist/llm/providers/anthropic.js +291 -0
- package/dist/llm/providers/base.d.ts +25 -0
- package/dist/llm/providers/base.js +43 -0
- package/dist/llm/providers/google.d.ts +27 -0
- package/dist/llm/providers/google.js +275 -0
- package/dist/llm/providers/index.d.ts +107 -0
- package/dist/llm/providers/index.js +216 -0
- package/dist/llm/providers/openai.d.ts +18 -0
- package/dist/llm/providers/openai.js +203 -0
- package/dist/llm/providers/registry.d.ts +159 -0
- package/dist/llm/providers/registry.js +279 -0
- package/dist/llm/providers/types.d.ts +94 -0
- package/dist/llm/providers/types.js +5 -0
- package/dist/main.d.ts +0 -0
- package/dist/main.js +1 -0
- package/dist/memory/auto-memory.d.ts +136 -0
- package/dist/memory/auto-memory.js +301 -0
- package/dist/memory/file-memory.d.ts +88 -0
- package/dist/memory/file-memory.js +287 -0
- package/dist/memory/index.d.ts +26 -0
- package/dist/memory/index.js +41 -0
- package/dist/memory/memory.d.ts +92 -0
- package/dist/memory/memory.js +170 -0
- package/dist/observability/adapters/console.d.ts +33 -0
- package/dist/observability/adapters/console.js +71 -0
- package/dist/observability/adapters/external/arize.d.ts +20 -0
- package/dist/observability/adapters/external/arize.js +22 -0
- package/dist/observability/adapters/external/axiom.d.ts +20 -0
- package/dist/observability/adapters/external/axiom.js +22 -0
- package/dist/observability/adapters/external/braintrust.d.ts +20 -0
- package/dist/observability/adapters/external/braintrust.js +22 -0
- package/dist/observability/adapters/external/helicone.d.ts +20 -0
- package/dist/observability/adapters/external/helicone.js +22 -0
- package/dist/observability/adapters/external/laminar.d.ts +20 -0
- package/dist/observability/adapters/external/laminar.js +22 -0
- package/dist/observability/adapters/external/langfuse.d.ts +28 -0
- package/dist/observability/adapters/external/langfuse.js +186 -0
- package/dist/observability/adapters/external/langsmith.d.ts +21 -0
- package/dist/observability/adapters/external/langsmith.js +83 -0
- package/dist/observability/adapters/external/langwatch.d.ts +20 -0
- package/dist/observability/adapters/external/langwatch.js +22 -0
- package/dist/observability/adapters/external/maxim.d.ts +20 -0
- package/dist/observability/adapters/external/maxim.js +22 -0
- package/dist/observability/adapters/external/patronus.d.ts +20 -0
- package/dist/observability/adapters/external/patronus.js +22 -0
- package/dist/observability/adapters/external/scorecard.d.ts +20 -0
- package/dist/observability/adapters/external/scorecard.js +22 -0
- package/dist/observability/adapters/external/signoz.d.ts +20 -0
- package/dist/observability/adapters/external/signoz.js +22 -0
- package/dist/observability/adapters/external/traceloop.d.ts +20 -0
- package/dist/observability/adapters/external/traceloop.js +22 -0
- package/dist/observability/adapters/external/weave.d.ts +20 -0
- package/dist/observability/adapters/external/weave.js +22 -0
- package/dist/observability/adapters/index.d.ts +19 -0
- package/dist/observability/adapters/index.js +289 -0
- package/dist/observability/adapters/memory.d.ts +41 -0
- package/dist/observability/adapters/memory.js +190 -0
- package/dist/observability/adapters/noop.d.ts +25 -0
- package/dist/observability/adapters/noop.js +64 -0
- package/dist/observability/index.d.ts +47 -0
- package/dist/observability/index.js +115 -0
- package/dist/observability/types.d.ts +165 -0
- package/dist/observability/types.js +165 -0
- package/dist/planning/index.d.ts +253 -0
- package/dist/planning/index.js +475 -0
- package/dist/process/index.d.ts +25 -0
- package/dist/process/index.js +37 -0
- package/dist/process/process.d.ts +0 -0
- package/dist/process/process.js +1 -0
- package/dist/session/index.d.ts +111 -0
- package/dist/session/index.js +250 -0
- package/dist/skills/index.d.ts +70 -0
- package/dist/skills/index.js +233 -0
- package/dist/task/index.d.ts +25 -0
- package/dist/task/index.js +32 -0
- package/dist/task/task.d.ts +0 -0
- package/dist/task/task.js +1 -0
- package/dist/telemetry/index.d.ts +175 -0
- package/dist/telemetry/index.js +287 -0
- package/dist/tools/arxivTools.d.ts +32 -0
- package/dist/tools/arxivTools.js +81 -0
- package/dist/tools/base.d.ts +97 -0
- package/dist/tools/base.js +147 -0
- package/dist/tools/builtins/airweave.d.ts +32 -0
- package/dist/tools/builtins/airweave.js +119 -0
- package/dist/tools/builtins/bedrock-agentcore.d.ts +62 -0
- package/dist/tools/builtins/bedrock-agentcore.js +233 -0
- package/dist/tools/builtins/code-execution.d.ts +36 -0
- package/dist/tools/builtins/code-execution.js +136 -0
- package/dist/tools/builtins/code-mode.d.ts +54 -0
- package/dist/tools/builtins/code-mode.js +167 -0
- package/dist/tools/builtins/custom.d.ts +42 -0
- package/dist/tools/builtins/custom.js +195 -0
- package/dist/tools/builtins/exa.d.ts +53 -0
- package/dist/tools/builtins/exa.js +112 -0
- package/dist/tools/builtins/firecrawl.d.ts +56 -0
- package/dist/tools/builtins/firecrawl.js +158 -0
- package/dist/tools/builtins/index.d.ts +45 -0
- package/dist/tools/builtins/index.js +180 -0
- package/dist/tools/builtins/parallel.d.ts +30 -0
- package/dist/tools/builtins/parallel.js +113 -0
- package/dist/tools/builtins/perplexity.d.ts +32 -0
- package/dist/tools/builtins/perplexity.js +113 -0
- package/dist/tools/builtins/superagent.d.ts +66 -0
- package/dist/tools/builtins/superagent.js +187 -0
- package/dist/tools/builtins/tavily.d.ts +99 -0
- package/dist/tools/builtins/tavily.js +285 -0
- package/dist/tools/builtins/valyu.d.ts +65 -0
- package/dist/tools/builtins/valyu.js +193 -0
- package/dist/tools/decorator.d.ts +91 -0
- package/dist/tools/decorator.js +165 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.js +36 -0
- package/dist/tools/mcpSse.d.ts +43 -0
- package/dist/tools/mcpSse.js +110 -0
- package/dist/tools/registry/index.d.ts +9 -0
- package/dist/tools/registry/index.js +28 -0
- package/dist/tools/registry/middleware.d.ts +43 -0
- package/dist/tools/registry/middleware.js +220 -0
- package/dist/tools/registry/registry.d.ts +92 -0
- package/dist/tools/registry/registry.js +280 -0
- package/dist/tools/registry/types.d.ts +217 -0
- package/dist/tools/registry/types.js +49 -0
- package/dist/tools/test.d.ts +0 -0
- package/dist/tools/test.js +1 -0
- package/dist/tools/tools.d.ts +74 -0
- package/dist/tools/tools.js +133 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.js +149 -0
- package/dist/utils/pretty-logger.d.ts +21 -0
- package/dist/utils/pretty-logger.js +248 -0
- package/dist/workflows/index.d.ts +118 -0
- package/dist/workflows/index.js +247 -0
- package/dist/workflows/loop.d.ts +0 -0
- package/dist/workflows/loop.js +1 -0
- package/dist/workflows/yaml-parser.d.ts +48 -0
- package/dist/workflows/yaml-parser.js +304 -0
- package/package.json +119 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* File-based Memory Storage
|
|
4
|
+
* Persistent memory using JSONL files with lockfile support for concurrent access
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.FileMemory = void 0;
|
|
41
|
+
exports.createFileMemory = createFileMemory;
|
|
42
|
+
/**
|
|
43
|
+
* FileMemory - Append-only JSONL storage with compaction
|
|
44
|
+
*/
|
|
45
|
+
class FileMemory {
|
|
46
|
+
constructor(config) {
|
|
47
|
+
this.entries = new Map();
|
|
48
|
+
this.initialized = false;
|
|
49
|
+
this.writeQueue = Promise.resolve();
|
|
50
|
+
this.filePath = config.filePath;
|
|
51
|
+
this.maxEntries = config.maxEntries ?? 10000;
|
|
52
|
+
this.embeddingProvider = config.embeddingProvider;
|
|
53
|
+
this.compactionThreshold = config.compactionThreshold ?? 1000;
|
|
54
|
+
this.autoCompact = config.autoCompact ?? true;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Initialize and load existing entries
|
|
58
|
+
*/
|
|
59
|
+
async initialize() {
|
|
60
|
+
if (this.initialized)
|
|
61
|
+
return;
|
|
62
|
+
try {
|
|
63
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
64
|
+
const content = await fs.readFile(this.filePath, 'utf-8').catch(() => '');
|
|
65
|
+
if (content) {
|
|
66
|
+
const lines = content.trim().split('\n').filter(Boolean);
|
|
67
|
+
let deletedCount = 0;
|
|
68
|
+
for (const line of lines) {
|
|
69
|
+
try {
|
|
70
|
+
const entry = JSON.parse(line);
|
|
71
|
+
if (entry.deleted) {
|
|
72
|
+
this.entries.delete(entry.id);
|
|
73
|
+
deletedCount++;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.entries.set(entry.id, entry);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// Skip malformed lines
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Auto-compact if too many deleted entries
|
|
84
|
+
if (this.autoCompact && deletedCount > this.compactionThreshold) {
|
|
85
|
+
await this.compact();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (error.code !== 'ENOENT') {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
this.initialized = true;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Add a memory entry
|
|
98
|
+
*/
|
|
99
|
+
async add(content, role, metadata) {
|
|
100
|
+
await this.initialize();
|
|
101
|
+
const id = this.generateId();
|
|
102
|
+
const entry = {
|
|
103
|
+
id,
|
|
104
|
+
content,
|
|
105
|
+
role,
|
|
106
|
+
timestamp: Date.now(),
|
|
107
|
+
metadata
|
|
108
|
+
};
|
|
109
|
+
if (this.embeddingProvider) {
|
|
110
|
+
entry.embedding = await this.embeddingProvider.embed(content);
|
|
111
|
+
}
|
|
112
|
+
this.entries.set(id, entry);
|
|
113
|
+
await this.appendEntry(entry);
|
|
114
|
+
this.enforceLimit();
|
|
115
|
+
return entry;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get a memory entry by ID
|
|
119
|
+
*/
|
|
120
|
+
async get(id) {
|
|
121
|
+
await this.initialize();
|
|
122
|
+
const entry = this.entries.get(id);
|
|
123
|
+
return entry && !entry.deleted ? entry : undefined;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get all entries
|
|
127
|
+
*/
|
|
128
|
+
async getAll() {
|
|
129
|
+
await this.initialize();
|
|
130
|
+
return Array.from(this.entries.values())
|
|
131
|
+
.filter(e => !e.deleted)
|
|
132
|
+
.sort((a, b) => a.timestamp - b.timestamp);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get recent entries
|
|
136
|
+
*/
|
|
137
|
+
async getRecent(count) {
|
|
138
|
+
const all = await this.getAll();
|
|
139
|
+
return all.slice(-count);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Search memory by text similarity
|
|
143
|
+
*/
|
|
144
|
+
async search(query, limit = 5) {
|
|
145
|
+
await this.initialize();
|
|
146
|
+
if (!this.embeddingProvider) {
|
|
147
|
+
return this.textSearch(query, limit);
|
|
148
|
+
}
|
|
149
|
+
const queryEmbedding = await this.embeddingProvider.embed(query);
|
|
150
|
+
const results = [];
|
|
151
|
+
for (const entry of this.entries.values()) {
|
|
152
|
+
if (entry.deleted)
|
|
153
|
+
continue;
|
|
154
|
+
if (entry.embedding) {
|
|
155
|
+
const score = this.cosineSimilarity(queryEmbedding, entry.embedding);
|
|
156
|
+
results.push({ entry, score });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return results
|
|
160
|
+
.sort((a, b) => b.score - a.score)
|
|
161
|
+
.slice(0, limit);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Delete a memory entry (soft delete)
|
|
165
|
+
*/
|
|
166
|
+
async delete(id) {
|
|
167
|
+
await this.initialize();
|
|
168
|
+
const entry = this.entries.get(id);
|
|
169
|
+
if (!entry || entry.deleted)
|
|
170
|
+
return false;
|
|
171
|
+
entry.deleted = true;
|
|
172
|
+
await this.appendEntry({ id, deleted: true });
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Clear all memory
|
|
177
|
+
*/
|
|
178
|
+
async clear() {
|
|
179
|
+
await this.initialize();
|
|
180
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
181
|
+
await fs.writeFile(this.filePath, '');
|
|
182
|
+
this.entries.clear();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Compact the file by removing deleted entries
|
|
186
|
+
*/
|
|
187
|
+
async compact() {
|
|
188
|
+
await this.initialize();
|
|
189
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
190
|
+
const activeEntries = Array.from(this.entries.values()).filter(e => !e.deleted);
|
|
191
|
+
const content = activeEntries
|
|
192
|
+
.map(e => JSON.stringify(e))
|
|
193
|
+
.join('\n') + (activeEntries.length ? '\n' : '');
|
|
194
|
+
// Write to temp file first, then rename (atomic)
|
|
195
|
+
const tempPath = `${this.filePath}.tmp`;
|
|
196
|
+
await fs.writeFile(tempPath, content);
|
|
197
|
+
await fs.rename(tempPath, this.filePath);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get memory size
|
|
201
|
+
*/
|
|
202
|
+
get size() {
|
|
203
|
+
return Array.from(this.entries.values()).filter(e => !e.deleted).length;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Export memory to JSON
|
|
207
|
+
*/
|
|
208
|
+
async toJSON() {
|
|
209
|
+
return this.getAll();
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Import memory from JSON
|
|
213
|
+
*/
|
|
214
|
+
async fromJSON(entries) {
|
|
215
|
+
await this.clear();
|
|
216
|
+
for (const entry of entries) {
|
|
217
|
+
this.entries.set(entry.id, entry);
|
|
218
|
+
}
|
|
219
|
+
await this.compact();
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Build context string from recent memory
|
|
223
|
+
*/
|
|
224
|
+
async buildContext(count) {
|
|
225
|
+
const entries = count ? await this.getRecent(count) : await this.getAll();
|
|
226
|
+
return entries
|
|
227
|
+
.map(e => `${e.role}: ${e.content}`)
|
|
228
|
+
.join('\n');
|
|
229
|
+
}
|
|
230
|
+
async appendEntry(entry) {
|
|
231
|
+
// Queue writes to ensure order
|
|
232
|
+
this.writeQueue = this.writeQueue.then(async () => {
|
|
233
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
234
|
+
await fs.appendFile(this.filePath, JSON.stringify(entry) + '\n');
|
|
235
|
+
});
|
|
236
|
+
await this.writeQueue;
|
|
237
|
+
}
|
|
238
|
+
textSearch(query, limit) {
|
|
239
|
+
const queryLower = query.toLowerCase();
|
|
240
|
+
const results = [];
|
|
241
|
+
for (const entry of this.entries.values()) {
|
|
242
|
+
if (entry.deleted)
|
|
243
|
+
continue;
|
|
244
|
+
const contentLower = entry.content.toLowerCase();
|
|
245
|
+
if (contentLower.includes(queryLower)) {
|
|
246
|
+
const score = queryLower.length / contentLower.length;
|
|
247
|
+
results.push({ entry, score: Math.min(score * 10, 1) });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return results
|
|
251
|
+
.sort((a, b) => b.score - a.score)
|
|
252
|
+
.slice(0, limit);
|
|
253
|
+
}
|
|
254
|
+
cosineSimilarity(a, b) {
|
|
255
|
+
if (a.length !== b.length)
|
|
256
|
+
return 0;
|
|
257
|
+
let dotProduct = 0;
|
|
258
|
+
let normA = 0;
|
|
259
|
+
let normB = 0;
|
|
260
|
+
for (let i = 0; i < a.length; i++) {
|
|
261
|
+
dotProduct += a[i] * b[i];
|
|
262
|
+
normA += a[i] * a[i];
|
|
263
|
+
normB += b[i] * b[i];
|
|
264
|
+
}
|
|
265
|
+
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
266
|
+
return denominator === 0 ? 0 : dotProduct / denominator;
|
|
267
|
+
}
|
|
268
|
+
generateId() {
|
|
269
|
+
return `fmem_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
270
|
+
}
|
|
271
|
+
enforceLimit() {
|
|
272
|
+
const active = Array.from(this.entries.values()).filter(e => !e.deleted);
|
|
273
|
+
while (active.length > this.maxEntries) {
|
|
274
|
+
const oldest = active.shift();
|
|
275
|
+
if (oldest) {
|
|
276
|
+
oldest.deleted = true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.FileMemory = FileMemory;
|
|
282
|
+
/**
|
|
283
|
+
* Create a file-based memory instance
|
|
284
|
+
*/
|
|
285
|
+
function createFileMemory(config) {
|
|
286
|
+
return new FileMemory(config);
|
|
287
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface Memory {
|
|
2
|
+
id: string;
|
|
3
|
+
content: any;
|
|
4
|
+
timestamp: Date;
|
|
5
|
+
metadata: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
export interface MemoryStore {
|
|
8
|
+
add(memory: Memory): void;
|
|
9
|
+
get(id: string): Memory | undefined;
|
|
10
|
+
search(query: string): Memory[];
|
|
11
|
+
update(id: string, memory: Partial<Memory>): boolean;
|
|
12
|
+
delete(id: string): boolean;
|
|
13
|
+
clear(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class BaseMemoryStore implements MemoryStore {
|
|
16
|
+
private memories;
|
|
17
|
+
constructor();
|
|
18
|
+
add(memory: Memory): void;
|
|
19
|
+
get(id: string): Memory | undefined;
|
|
20
|
+
search(query: string): Memory[];
|
|
21
|
+
update(id: string, update: Partial<Memory>): boolean;
|
|
22
|
+
delete(id: string): boolean;
|
|
23
|
+
clear(): void;
|
|
24
|
+
}
|
|
25
|
+
export { FileMemory, createFileMemory, type FileMemoryConfig, type FileMemoryEntry } from './file-memory';
|
|
26
|
+
export { AutoMemory, createAutoMemory, createLLMSummarizer, DEFAULT_POLICIES, type AutoMemoryConfig, type AutoMemoryPolicy, type AutoMemoryContext, type VectorStoreAdapter, type KnowledgeBaseAdapter } from './auto-memory';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_POLICIES = exports.createLLMSummarizer = exports.createAutoMemory = exports.AutoMemory = exports.createFileMemory = exports.FileMemory = exports.BaseMemoryStore = void 0;
|
|
4
|
+
class BaseMemoryStore {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.memories = new Map();
|
|
7
|
+
}
|
|
8
|
+
add(memory) {
|
|
9
|
+
this.memories.set(memory.id, memory);
|
|
10
|
+
}
|
|
11
|
+
get(id) {
|
|
12
|
+
return this.memories.get(id);
|
|
13
|
+
}
|
|
14
|
+
search(query) {
|
|
15
|
+
return Array.from(this.memories.values()).filter(m => JSON.stringify(m).toLowerCase().includes(query.toLowerCase()));
|
|
16
|
+
}
|
|
17
|
+
update(id, update) {
|
|
18
|
+
const existing = this.memories.get(id);
|
|
19
|
+
if (!existing)
|
|
20
|
+
return false;
|
|
21
|
+
this.memories.set(id, { ...existing, ...update });
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
delete(id) {
|
|
25
|
+
return this.memories.delete(id);
|
|
26
|
+
}
|
|
27
|
+
clear() {
|
|
28
|
+
this.memories.clear();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.BaseMemoryStore = BaseMemoryStore;
|
|
32
|
+
// Export FileMemory
|
|
33
|
+
var file_memory_1 = require("./file-memory");
|
|
34
|
+
Object.defineProperty(exports, "FileMemory", { enumerable: true, get: function () { return file_memory_1.FileMemory; } });
|
|
35
|
+
Object.defineProperty(exports, "createFileMemory", { enumerable: true, get: function () { return file_memory_1.createFileMemory; } });
|
|
36
|
+
// Export AutoMemory
|
|
37
|
+
var auto_memory_1 = require("./auto-memory");
|
|
38
|
+
Object.defineProperty(exports, "AutoMemory", { enumerable: true, get: function () { return auto_memory_1.AutoMemory; } });
|
|
39
|
+
Object.defineProperty(exports, "createAutoMemory", { enumerable: true, get: function () { return auto_memory_1.createAutoMemory; } });
|
|
40
|
+
Object.defineProperty(exports, "createLLMSummarizer", { enumerable: true, get: function () { return auto_memory_1.createLLMSummarizer; } });
|
|
41
|
+
Object.defineProperty(exports, "DEFAULT_POLICIES", { enumerable: true, get: function () { return auto_memory_1.DEFAULT_POLICIES; } });
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory System - Conversation and context memory management
|
|
3
|
+
*/
|
|
4
|
+
export interface MemoryEntry {
|
|
5
|
+
id: string;
|
|
6
|
+
content: string;
|
|
7
|
+
role: 'user' | 'assistant' | 'system';
|
|
8
|
+
timestamp: number;
|
|
9
|
+
metadata?: Record<string, any>;
|
|
10
|
+
embedding?: number[];
|
|
11
|
+
}
|
|
12
|
+
export interface MemoryConfig {
|
|
13
|
+
maxEntries?: number;
|
|
14
|
+
maxTokens?: number;
|
|
15
|
+
embeddingProvider?: EmbeddingProvider;
|
|
16
|
+
}
|
|
17
|
+
export interface EmbeddingProvider {
|
|
18
|
+
embed(text: string): Promise<number[]>;
|
|
19
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
20
|
+
}
|
|
21
|
+
export interface SearchResult {
|
|
22
|
+
entry: MemoryEntry;
|
|
23
|
+
score: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Memory class for managing conversation history and context
|
|
27
|
+
*/
|
|
28
|
+
export declare class Memory {
|
|
29
|
+
private entries;
|
|
30
|
+
private maxEntries;
|
|
31
|
+
private maxTokens;
|
|
32
|
+
private embeddingProvider?;
|
|
33
|
+
constructor(config?: MemoryConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Add a memory entry
|
|
36
|
+
*/
|
|
37
|
+
add(content: string, role: 'user' | 'assistant' | 'system', metadata?: Record<string, any>): Promise<MemoryEntry>;
|
|
38
|
+
/**
|
|
39
|
+
* Get a memory entry by ID
|
|
40
|
+
*/
|
|
41
|
+
get(id: string): MemoryEntry | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Get all entries
|
|
44
|
+
*/
|
|
45
|
+
getAll(): MemoryEntry[];
|
|
46
|
+
/**
|
|
47
|
+
* Get recent entries
|
|
48
|
+
*/
|
|
49
|
+
getRecent(count: number): MemoryEntry[];
|
|
50
|
+
/**
|
|
51
|
+
* Search memory by text similarity
|
|
52
|
+
*/
|
|
53
|
+
search(query: string, limit?: number): Promise<SearchResult[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Simple text search fallback
|
|
56
|
+
*/
|
|
57
|
+
private textSearch;
|
|
58
|
+
/**
|
|
59
|
+
* Calculate cosine similarity
|
|
60
|
+
*/
|
|
61
|
+
private cosineSimilarity;
|
|
62
|
+
/**
|
|
63
|
+
* Delete a memory entry
|
|
64
|
+
*/
|
|
65
|
+
delete(id: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Clear all memory
|
|
68
|
+
*/
|
|
69
|
+
clear(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Get memory size
|
|
72
|
+
*/
|
|
73
|
+
get size(): number;
|
|
74
|
+
/**
|
|
75
|
+
* Build context string from recent memory
|
|
76
|
+
*/
|
|
77
|
+
buildContext(count?: number): string;
|
|
78
|
+
/**
|
|
79
|
+
* Export memory to JSON
|
|
80
|
+
*/
|
|
81
|
+
toJSON(): MemoryEntry[];
|
|
82
|
+
/**
|
|
83
|
+
* Import memory from JSON
|
|
84
|
+
*/
|
|
85
|
+
fromJSON(entries: MemoryEntry[]): void;
|
|
86
|
+
private generateId;
|
|
87
|
+
private enforceLimit;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a memory instance
|
|
91
|
+
*/
|
|
92
|
+
export declare function createMemory(config?: MemoryConfig): Memory;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Memory System - Conversation and context memory management
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Memory = void 0;
|
|
7
|
+
exports.createMemory = createMemory;
|
|
8
|
+
/**
|
|
9
|
+
* Memory class for managing conversation history and context
|
|
10
|
+
*/
|
|
11
|
+
class Memory {
|
|
12
|
+
constructor(config = {}) {
|
|
13
|
+
this.entries = new Map();
|
|
14
|
+
this.maxEntries = config.maxEntries ?? 1000;
|
|
15
|
+
this.maxTokens = config.maxTokens ?? 100000;
|
|
16
|
+
this.embeddingProvider = config.embeddingProvider;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Add a memory entry
|
|
20
|
+
*/
|
|
21
|
+
async add(content, role, metadata) {
|
|
22
|
+
const id = this.generateId();
|
|
23
|
+
const entry = {
|
|
24
|
+
id,
|
|
25
|
+
content,
|
|
26
|
+
role,
|
|
27
|
+
timestamp: Date.now(),
|
|
28
|
+
metadata
|
|
29
|
+
};
|
|
30
|
+
if (this.embeddingProvider) {
|
|
31
|
+
entry.embedding = await this.embeddingProvider.embed(content);
|
|
32
|
+
}
|
|
33
|
+
this.entries.set(id, entry);
|
|
34
|
+
this.enforceLimit();
|
|
35
|
+
return entry;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get a memory entry by ID
|
|
39
|
+
*/
|
|
40
|
+
get(id) {
|
|
41
|
+
return this.entries.get(id);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get all entries
|
|
45
|
+
*/
|
|
46
|
+
getAll() {
|
|
47
|
+
return Array.from(this.entries.values())
|
|
48
|
+
.sort((a, b) => a.timestamp - b.timestamp);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get recent entries
|
|
52
|
+
*/
|
|
53
|
+
getRecent(count) {
|
|
54
|
+
return this.getAll().slice(-count);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Search memory by text similarity
|
|
58
|
+
*/
|
|
59
|
+
async search(query, limit = 5) {
|
|
60
|
+
if (!this.embeddingProvider) {
|
|
61
|
+
// Fallback to simple text matching
|
|
62
|
+
return this.textSearch(query, limit);
|
|
63
|
+
}
|
|
64
|
+
const queryEmbedding = await this.embeddingProvider.embed(query);
|
|
65
|
+
const results = [];
|
|
66
|
+
for (const entry of this.entries.values()) {
|
|
67
|
+
if (entry.embedding) {
|
|
68
|
+
const score = this.cosineSimilarity(queryEmbedding, entry.embedding);
|
|
69
|
+
results.push({ entry, score });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return results
|
|
73
|
+
.sort((a, b) => b.score - a.score)
|
|
74
|
+
.slice(0, limit);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Simple text search fallback
|
|
78
|
+
*/
|
|
79
|
+
textSearch(query, limit) {
|
|
80
|
+
const queryLower = query.toLowerCase();
|
|
81
|
+
const results = [];
|
|
82
|
+
for (const entry of this.entries.values()) {
|
|
83
|
+
const contentLower = entry.content.toLowerCase();
|
|
84
|
+
if (contentLower.includes(queryLower)) {
|
|
85
|
+
const score = queryLower.length / contentLower.length;
|
|
86
|
+
results.push({ entry, score: Math.min(score * 10, 1) });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return results
|
|
90
|
+
.sort((a, b) => b.score - a.score)
|
|
91
|
+
.slice(0, limit);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Calculate cosine similarity
|
|
95
|
+
*/
|
|
96
|
+
cosineSimilarity(a, b) {
|
|
97
|
+
if (a.length !== b.length)
|
|
98
|
+
return 0;
|
|
99
|
+
let dotProduct = 0;
|
|
100
|
+
let normA = 0;
|
|
101
|
+
let normB = 0;
|
|
102
|
+
for (let i = 0; i < a.length; i++) {
|
|
103
|
+
dotProduct += a[i] * b[i];
|
|
104
|
+
normA += a[i] * a[i];
|
|
105
|
+
normB += b[i] * b[i];
|
|
106
|
+
}
|
|
107
|
+
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
108
|
+
return denominator === 0 ? 0 : dotProduct / denominator;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Delete a memory entry
|
|
112
|
+
*/
|
|
113
|
+
delete(id) {
|
|
114
|
+
return this.entries.delete(id);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Clear all memory
|
|
118
|
+
*/
|
|
119
|
+
clear() {
|
|
120
|
+
this.entries.clear();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get memory size
|
|
124
|
+
*/
|
|
125
|
+
get size() {
|
|
126
|
+
return this.entries.size;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build context string from recent memory
|
|
130
|
+
*/
|
|
131
|
+
buildContext(count) {
|
|
132
|
+
const entries = count ? this.getRecent(count) : this.getAll();
|
|
133
|
+
return entries
|
|
134
|
+
.map(e => `${e.role}: ${e.content}`)
|
|
135
|
+
.join('\n');
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Export memory to JSON
|
|
139
|
+
*/
|
|
140
|
+
toJSON() {
|
|
141
|
+
return this.getAll();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Import memory from JSON
|
|
145
|
+
*/
|
|
146
|
+
fromJSON(entries) {
|
|
147
|
+
this.entries.clear();
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
this.entries.set(entry.id, entry);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
generateId() {
|
|
153
|
+
return `mem_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
154
|
+
}
|
|
155
|
+
enforceLimit() {
|
|
156
|
+
while (this.entries.size > this.maxEntries) {
|
|
157
|
+
const oldest = this.getAll()[0];
|
|
158
|
+
if (oldest) {
|
|
159
|
+
this.entries.delete(oldest.id);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.Memory = Memory;
|
|
165
|
+
/**
|
|
166
|
+
* Create a memory instance
|
|
167
|
+
*/
|
|
168
|
+
function createMemory(config) {
|
|
169
|
+
return new Memory(config);
|
|
170
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console Observability Adapter
|
|
3
|
+
* Logs traces and spans to console for debugging
|
|
4
|
+
*/
|
|
5
|
+
import type { ObservabilityAdapter, TraceContext, SpanContext, SpanKind, SpanStatus, AttributionContext } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Console Observability Adapter
|
|
8
|
+
* Wraps memory adapter and logs all operations to console
|
|
9
|
+
*/
|
|
10
|
+
export declare class ConsoleObservabilityAdapter implements ObservabilityAdapter {
|
|
11
|
+
readonly name = "console";
|
|
12
|
+
readonly isEnabled = true;
|
|
13
|
+
private memory;
|
|
14
|
+
private verbose;
|
|
15
|
+
constructor(options?: {
|
|
16
|
+
verbose?: boolean;
|
|
17
|
+
});
|
|
18
|
+
initialize(): Promise<void>;
|
|
19
|
+
shutdown(): Promise<void>;
|
|
20
|
+
startTrace(name: string, metadata?: Record<string, unknown>, attribution?: AttributionContext): TraceContext;
|
|
21
|
+
endTrace(traceId: string, status?: SpanStatus): void;
|
|
22
|
+
startSpan(traceId: string, name: string, kind: SpanKind, parentId?: string): SpanContext;
|
|
23
|
+
endSpan(spanId: string, status?: SpanStatus, attributes?: Record<string, unknown>): void;
|
|
24
|
+
addEvent(spanId: string, name: string, attributes?: Record<string, unknown>): void;
|
|
25
|
+
recordError(spanId: string, error: Error): void;
|
|
26
|
+
flush(): Promise<void>;
|
|
27
|
+
getTrace(traceId: string): import("../types").TraceData | undefined;
|
|
28
|
+
getAllTraces(): import("../types").TraceData[];
|
|
29
|
+
clear(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function createConsoleAdapter(options?: {
|
|
32
|
+
verbose?: boolean;
|
|
33
|
+
}): ConsoleObservabilityAdapter;
|