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,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Slack Integration
|
|
4
|
+
*
|
|
5
|
+
* Provides Slack bot adapters for building AI-powered Slack bots.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.SlackBot = void 0;
|
|
42
|
+
exports.createSlackBot = createSlackBot;
|
|
43
|
+
exports.verifySlackSignature = verifySlackSignature;
|
|
44
|
+
exports.parseSlackMessage = parseSlackMessage;
|
|
45
|
+
/**
|
|
46
|
+
* Create a Slack bot adapter.
|
|
47
|
+
*
|
|
48
|
+
* @example Basic usage
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { createSlackBot } from 'praisonai/integrations/slack';
|
|
51
|
+
* import { Agent } from 'praisonai';
|
|
52
|
+
*
|
|
53
|
+
* const agent = new Agent({ instructions: 'You are a helpful Slack bot' });
|
|
54
|
+
*
|
|
55
|
+
* const bot = createSlackBot({
|
|
56
|
+
* botToken: process.env.SLACK_BOT_TOKEN!,
|
|
57
|
+
* signingSecret: process.env.SLACK_SIGNING_SECRET!
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* bot.onMessage(async (message) => {
|
|
61
|
+
* const response = await agent.chat(message.text);
|
|
62
|
+
* return { text: response, threadTs: message.ts };
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Start webhook server
|
|
66
|
+
* bot.listen(3000);
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example With Socket Mode
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const bot = createSlackBot({
|
|
72
|
+
* botToken: process.env.SLACK_BOT_TOKEN!,
|
|
73
|
+
* appToken: process.env.SLACK_APP_TOKEN!,
|
|
74
|
+
* socketMode: true
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* bot.onMessage(async (message) => {
|
|
78
|
+
* return { text: 'Hello!' };
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* await bot.start();
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function createSlackBot(config) {
|
|
85
|
+
return new SlackBot(config);
|
|
86
|
+
}
|
|
87
|
+
class SlackBot {
|
|
88
|
+
constructor(config) {
|
|
89
|
+
this.boltApp = null;
|
|
90
|
+
this.config = config;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Set the message handler.
|
|
94
|
+
*/
|
|
95
|
+
onMessage(handler) {
|
|
96
|
+
this.messageHandler = handler;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Set the app mention handler.
|
|
101
|
+
*/
|
|
102
|
+
onAppMention(handler) {
|
|
103
|
+
this.mentionHandler = handler;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set the reaction handler.
|
|
108
|
+
*/
|
|
109
|
+
onReactionAdded(handler) {
|
|
110
|
+
this.reactionHandler = handler;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Initialize the Bolt app (lazy load).
|
|
115
|
+
*/
|
|
116
|
+
async initBolt() {
|
|
117
|
+
if (this.boltApp)
|
|
118
|
+
return this.boltApp;
|
|
119
|
+
try {
|
|
120
|
+
// @ts-ignore - Optional dependency
|
|
121
|
+
const { App } = await Promise.resolve().then(() => __importStar(require('@slack/bolt')));
|
|
122
|
+
this.boltApp = new App({
|
|
123
|
+
token: this.config.botToken,
|
|
124
|
+
signingSecret: this.config.signingSecret,
|
|
125
|
+
appToken: this.config.appToken,
|
|
126
|
+
socketMode: this.config.socketMode,
|
|
127
|
+
});
|
|
128
|
+
// Register message handler
|
|
129
|
+
if (this.messageHandler) {
|
|
130
|
+
this.boltApp.message(async ({ message, say }) => {
|
|
131
|
+
// Skip bot messages
|
|
132
|
+
if (message.bot_id)
|
|
133
|
+
return;
|
|
134
|
+
const slackMessage = {
|
|
135
|
+
channel: message.channel,
|
|
136
|
+
user: message.user,
|
|
137
|
+
text: message.text || '',
|
|
138
|
+
threadTs: message.thread_ts,
|
|
139
|
+
ts: message.ts,
|
|
140
|
+
};
|
|
141
|
+
const response = await this.messageHandler(slackMessage);
|
|
142
|
+
if (response) {
|
|
143
|
+
await say({
|
|
144
|
+
text: response.text,
|
|
145
|
+
blocks: response.blocks,
|
|
146
|
+
thread_ts: response.threadTs || message.ts,
|
|
147
|
+
unfurl_links: response.unfurlLinks,
|
|
148
|
+
unfurl_media: response.unfurlMedia,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Register app mention handler
|
|
154
|
+
if (this.mentionHandler) {
|
|
155
|
+
this.boltApp.event('app_mention', async ({ event, say }) => {
|
|
156
|
+
const slackMessage = {
|
|
157
|
+
channel: event.channel,
|
|
158
|
+
user: event.user,
|
|
159
|
+
text: event.text || '',
|
|
160
|
+
threadTs: event.thread_ts,
|
|
161
|
+
ts: event.ts,
|
|
162
|
+
};
|
|
163
|
+
const response = await this.mentionHandler(slackMessage);
|
|
164
|
+
if (response) {
|
|
165
|
+
await say({
|
|
166
|
+
text: response.text,
|
|
167
|
+
blocks: response.blocks,
|
|
168
|
+
thread_ts: response.threadTs || event.ts,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
// Register reaction handler
|
|
174
|
+
if (this.reactionHandler) {
|
|
175
|
+
this.boltApp.event('reaction_added', async ({ event }) => {
|
|
176
|
+
await this.reactionHandler(event);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return this.boltApp;
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
throw new Error(`Failed to initialize Slack Bolt: ${error.message}. ` +
|
|
183
|
+
'Install with: npm install @slack/bolt');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Start the bot (Socket Mode).
|
|
188
|
+
*/
|
|
189
|
+
async start() {
|
|
190
|
+
const app = await this.initBolt();
|
|
191
|
+
await app.start();
|
|
192
|
+
console.log('⚡️ Slack bot is running in Socket Mode');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Start webhook server.
|
|
196
|
+
*/
|
|
197
|
+
async listen(port = 3000) {
|
|
198
|
+
const app = await this.initBolt();
|
|
199
|
+
await app.start(port);
|
|
200
|
+
console.log(`⚡️ Slack bot is running on port ${port}`);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Stop the bot.
|
|
204
|
+
*/
|
|
205
|
+
async stop() {
|
|
206
|
+
if (this.boltApp) {
|
|
207
|
+
await this.boltApp.stop();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Send a message to a channel.
|
|
212
|
+
*/
|
|
213
|
+
async sendMessage(channel, text, options) {
|
|
214
|
+
const app = await this.initBolt();
|
|
215
|
+
await app.client.chat.postMessage({
|
|
216
|
+
token: this.config.botToken,
|
|
217
|
+
channel,
|
|
218
|
+
text,
|
|
219
|
+
blocks: options?.blocks,
|
|
220
|
+
thread_ts: options?.threadTs,
|
|
221
|
+
unfurl_links: options?.unfurlLinks,
|
|
222
|
+
unfurl_media: options?.unfurlMedia,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get an Express middleware for webhook handling.
|
|
227
|
+
*/
|
|
228
|
+
getExpressMiddleware() {
|
|
229
|
+
return async (req, res, next) => {
|
|
230
|
+
const app = await this.initBolt();
|
|
231
|
+
return app.receiver.app(req, res, next);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.SlackBot = SlackBot;
|
|
236
|
+
/**
|
|
237
|
+
* Verify Slack request signature.
|
|
238
|
+
*/
|
|
239
|
+
function verifySlackSignature(signingSecret, signature, timestamp, body) {
|
|
240
|
+
const crypto = require('crypto');
|
|
241
|
+
const baseString = `v0:${timestamp}:${body}`;
|
|
242
|
+
const hmac = crypto.createHmac('sha256', signingSecret);
|
|
243
|
+
hmac.update(baseString);
|
|
244
|
+
const computedSignature = `v0=${hmac.digest('hex')}`;
|
|
245
|
+
return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(computedSignature));
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Parse Slack message text to extract mentions and links.
|
|
249
|
+
*/
|
|
250
|
+
function parseSlackMessage(text) {
|
|
251
|
+
const mentions = [];
|
|
252
|
+
const links = [];
|
|
253
|
+
// Extract user mentions <@U123456>
|
|
254
|
+
const mentionRegex = /<@([A-Z0-9]+)>/g;
|
|
255
|
+
let match;
|
|
256
|
+
while ((match = mentionRegex.exec(text)) !== null) {
|
|
257
|
+
mentions.push(match[1]);
|
|
258
|
+
}
|
|
259
|
+
// Extract links <http://...|label>
|
|
260
|
+
const linkRegex = /<(https?:\/\/[^|>]+)(?:\|[^>]+)?>/g;
|
|
261
|
+
while ((match = linkRegex.exec(text)) !== null) {
|
|
262
|
+
links.push(match[1]);
|
|
263
|
+
}
|
|
264
|
+
// Clean text (remove mentions and format links)
|
|
265
|
+
const cleanText = text
|
|
266
|
+
.replace(/<@[A-Z0-9]+>/g, '')
|
|
267
|
+
.replace(/<(https?:\/\/[^|>]+)(?:\|([^>]+))?>/g, '$2 ($1)')
|
|
268
|
+
.trim();
|
|
269
|
+
return { mentions, links, cleanText };
|
|
270
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Vector Store - Abstract class for vector database integrations
|
|
3
|
+
* Matches mastra's MastraVector pattern
|
|
4
|
+
*/
|
|
5
|
+
export interface VectorDocument {
|
|
6
|
+
id: string;
|
|
7
|
+
vector: number[];
|
|
8
|
+
metadata?: Record<string, any>;
|
|
9
|
+
content?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface QueryResult {
|
|
12
|
+
id: string;
|
|
13
|
+
score: number;
|
|
14
|
+
metadata?: Record<string, any>;
|
|
15
|
+
content?: string;
|
|
16
|
+
vector?: number[];
|
|
17
|
+
}
|
|
18
|
+
export interface IndexStats {
|
|
19
|
+
dimension: number;
|
|
20
|
+
count: number;
|
|
21
|
+
metric: 'cosine' | 'euclidean' | 'dotProduct';
|
|
22
|
+
}
|
|
23
|
+
export interface CreateIndexParams {
|
|
24
|
+
indexName: string;
|
|
25
|
+
dimension: number;
|
|
26
|
+
metric?: 'cosine' | 'euclidean' | 'dotProduct';
|
|
27
|
+
}
|
|
28
|
+
export interface UpsertParams {
|
|
29
|
+
indexName: string;
|
|
30
|
+
vectors: VectorDocument[];
|
|
31
|
+
}
|
|
32
|
+
export interface QueryParams {
|
|
33
|
+
indexName: string;
|
|
34
|
+
vector: number[];
|
|
35
|
+
topK?: number;
|
|
36
|
+
filter?: Record<string, any>;
|
|
37
|
+
includeMetadata?: boolean;
|
|
38
|
+
includeVectors?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface DeleteParams {
|
|
41
|
+
indexName: string;
|
|
42
|
+
ids?: string[];
|
|
43
|
+
filter?: Record<string, any>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Abstract base class for vector store implementations
|
|
47
|
+
*/
|
|
48
|
+
export declare abstract class BaseVectorStore {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly name: string;
|
|
51
|
+
constructor(config: {
|
|
52
|
+
id: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* Create a new index
|
|
57
|
+
*/
|
|
58
|
+
abstract createIndex(params: CreateIndexParams): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* List all indexes
|
|
61
|
+
*/
|
|
62
|
+
abstract listIndexes(): Promise<string[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Get index statistics
|
|
65
|
+
*/
|
|
66
|
+
abstract describeIndex(indexName: string): Promise<IndexStats>;
|
|
67
|
+
/**
|
|
68
|
+
* Delete an index
|
|
69
|
+
*/
|
|
70
|
+
abstract deleteIndex(indexName: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Upsert vectors into an index
|
|
73
|
+
*/
|
|
74
|
+
abstract upsert(params: UpsertParams): Promise<string[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Query vectors by similarity
|
|
77
|
+
*/
|
|
78
|
+
abstract query(params: QueryParams): Promise<QueryResult[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Delete vectors by ID or filter
|
|
81
|
+
*/
|
|
82
|
+
abstract delete(params: DeleteParams): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Update vector metadata
|
|
85
|
+
*/
|
|
86
|
+
abstract update(indexName: string, id: string, metadata: Record<string, any>): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* In-memory vector store for testing and development
|
|
90
|
+
*/
|
|
91
|
+
export declare class MemoryVectorStore extends BaseVectorStore {
|
|
92
|
+
private indexes;
|
|
93
|
+
constructor(config?: {
|
|
94
|
+
id: string;
|
|
95
|
+
});
|
|
96
|
+
createIndex(params: CreateIndexParams): Promise<void>;
|
|
97
|
+
listIndexes(): Promise<string[]>;
|
|
98
|
+
describeIndex(indexName: string): Promise<IndexStats>;
|
|
99
|
+
deleteIndex(indexName: string): Promise<void>;
|
|
100
|
+
upsert(params: UpsertParams): Promise<string[]>;
|
|
101
|
+
query(params: QueryParams): Promise<QueryResult[]>;
|
|
102
|
+
delete(params: DeleteParams): Promise<void>;
|
|
103
|
+
update(indexName: string, id: string, metadata: Record<string, any>): Promise<void>;
|
|
104
|
+
private calculateSimilarity;
|
|
105
|
+
private cosineSimilarity;
|
|
106
|
+
private euclideanDistance;
|
|
107
|
+
private dotProduct;
|
|
108
|
+
private matchesFilter;
|
|
109
|
+
}
|
|
110
|
+
export declare function createMemoryVectorStore(id?: string): MemoryVectorStore;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base Vector Store - Abstract class for vector database integrations
|
|
4
|
+
* Matches mastra's MastraVector pattern
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.MemoryVectorStore = exports.BaseVectorStore = void 0;
|
|
8
|
+
exports.createMemoryVectorStore = createMemoryVectorStore;
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base class for vector store implementations
|
|
11
|
+
*/
|
|
12
|
+
class BaseVectorStore {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.id = config.id;
|
|
15
|
+
this.name = config.name || 'VectorStore';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.BaseVectorStore = BaseVectorStore;
|
|
19
|
+
/**
|
|
20
|
+
* In-memory vector store for testing and development
|
|
21
|
+
*/
|
|
22
|
+
class MemoryVectorStore extends BaseVectorStore {
|
|
23
|
+
constructor(config = { id: 'memory' }) {
|
|
24
|
+
super({ ...config, name: 'MemoryVectorStore' });
|
|
25
|
+
this.indexes = new Map();
|
|
26
|
+
}
|
|
27
|
+
async createIndex(params) {
|
|
28
|
+
if (this.indexes.has(params.indexName)) {
|
|
29
|
+
return; // Index already exists
|
|
30
|
+
}
|
|
31
|
+
this.indexes.set(params.indexName, {
|
|
32
|
+
dimension: params.dimension,
|
|
33
|
+
metric: params.metric || 'cosine',
|
|
34
|
+
vectors: new Map()
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async listIndexes() {
|
|
38
|
+
return Array.from(this.indexes.keys());
|
|
39
|
+
}
|
|
40
|
+
async describeIndex(indexName) {
|
|
41
|
+
const index = this.indexes.get(indexName);
|
|
42
|
+
if (!index) {
|
|
43
|
+
throw new Error(`Index ${indexName} not found`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
dimension: index.dimension,
|
|
47
|
+
count: index.vectors.size,
|
|
48
|
+
metric: index.metric
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async deleteIndex(indexName) {
|
|
52
|
+
this.indexes.delete(indexName);
|
|
53
|
+
}
|
|
54
|
+
async upsert(params) {
|
|
55
|
+
const index = this.indexes.get(params.indexName);
|
|
56
|
+
if (!index) {
|
|
57
|
+
throw new Error(`Index ${params.indexName} not found`);
|
|
58
|
+
}
|
|
59
|
+
const ids = [];
|
|
60
|
+
for (const doc of params.vectors) {
|
|
61
|
+
index.vectors.set(doc.id, doc);
|
|
62
|
+
ids.push(doc.id);
|
|
63
|
+
}
|
|
64
|
+
return ids;
|
|
65
|
+
}
|
|
66
|
+
async query(params) {
|
|
67
|
+
const index = this.indexes.get(params.indexName);
|
|
68
|
+
if (!index) {
|
|
69
|
+
throw new Error(`Index ${params.indexName} not found`);
|
|
70
|
+
}
|
|
71
|
+
const results = [];
|
|
72
|
+
for (const [id, doc] of index.vectors) {
|
|
73
|
+
// Apply filter if provided
|
|
74
|
+
if (params.filter && !this.matchesFilter(doc.metadata || {}, params.filter)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const score = this.calculateSimilarity(params.vector, doc.vector, index.metric);
|
|
78
|
+
results.push({
|
|
79
|
+
id,
|
|
80
|
+
score,
|
|
81
|
+
metadata: params.includeMetadata ? doc.metadata : undefined,
|
|
82
|
+
content: doc.content,
|
|
83
|
+
vector: params.includeVectors ? doc.vector : undefined
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Sort by score descending and limit
|
|
87
|
+
results.sort((a, b) => b.score - a.score);
|
|
88
|
+
return results.slice(0, params.topK || 10);
|
|
89
|
+
}
|
|
90
|
+
async delete(params) {
|
|
91
|
+
const index = this.indexes.get(params.indexName);
|
|
92
|
+
if (!index) {
|
|
93
|
+
throw new Error(`Index ${params.indexName} not found`);
|
|
94
|
+
}
|
|
95
|
+
if (params.ids) {
|
|
96
|
+
for (const id of params.ids) {
|
|
97
|
+
index.vectors.delete(id);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (params.filter) {
|
|
101
|
+
for (const [id, doc] of index.vectors) {
|
|
102
|
+
if (this.matchesFilter(doc.metadata || {}, params.filter)) {
|
|
103
|
+
index.vectors.delete(id);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async update(indexName, id, metadata) {
|
|
109
|
+
const index = this.indexes.get(indexName);
|
|
110
|
+
if (!index) {
|
|
111
|
+
throw new Error(`Index ${indexName} not found`);
|
|
112
|
+
}
|
|
113
|
+
const doc = index.vectors.get(id);
|
|
114
|
+
if (doc) {
|
|
115
|
+
doc.metadata = { ...doc.metadata, ...metadata };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
calculateSimilarity(a, b, metric) {
|
|
119
|
+
if (a.length !== b.length) {
|
|
120
|
+
throw new Error('Vector dimensions must match');
|
|
121
|
+
}
|
|
122
|
+
switch (metric) {
|
|
123
|
+
case 'cosine':
|
|
124
|
+
return this.cosineSimilarity(a, b);
|
|
125
|
+
case 'euclidean':
|
|
126
|
+
return 1 / (1 + this.euclideanDistance(a, b));
|
|
127
|
+
case 'dotProduct':
|
|
128
|
+
return this.dotProduct(a, b);
|
|
129
|
+
default:
|
|
130
|
+
return this.cosineSimilarity(a, b);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
cosineSimilarity(a, b) {
|
|
134
|
+
const dot = this.dotProduct(a, b);
|
|
135
|
+
const normA = Math.sqrt(a.reduce((sum, x) => sum + x * x, 0));
|
|
136
|
+
const normB = Math.sqrt(b.reduce((sum, x) => sum + x * x, 0));
|
|
137
|
+
return dot / (normA * normB);
|
|
138
|
+
}
|
|
139
|
+
euclideanDistance(a, b) {
|
|
140
|
+
return Math.sqrt(a.reduce((sum, x, i) => sum + Math.pow(x - b[i], 2), 0));
|
|
141
|
+
}
|
|
142
|
+
dotProduct(a, b) {
|
|
143
|
+
return a.reduce((sum, x, i) => sum + x * b[i], 0);
|
|
144
|
+
}
|
|
145
|
+
matchesFilter(metadata, filter) {
|
|
146
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
147
|
+
if (metadata[key] !== value) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.MemoryVectorStore = MemoryVectorStore;
|
|
155
|
+
// Factory function
|
|
156
|
+
function createMemoryVectorStore(id) {
|
|
157
|
+
return new MemoryVectorStore({ id: id || 'memory' });
|
|
158
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chroma Vector Store Integration
|
|
3
|
+
*/
|
|
4
|
+
import { BaseVectorStore, CreateIndexParams, UpsertParams, QueryParams, DeleteParams, QueryResult, IndexStats } from './base';
|
|
5
|
+
export interface ChromaConfig {
|
|
6
|
+
host?: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
path?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class ChromaVectorStore extends BaseVectorStore {
|
|
11
|
+
private baseUrl;
|
|
12
|
+
constructor(config?: ChromaConfig & {
|
|
13
|
+
id?: string;
|
|
14
|
+
});
|
|
15
|
+
private request;
|
|
16
|
+
createIndex(params: CreateIndexParams): Promise<void>;
|
|
17
|
+
listIndexes(): Promise<string[]>;
|
|
18
|
+
describeIndex(indexName: string): Promise<IndexStats>;
|
|
19
|
+
deleteIndex(indexName: string): Promise<void>;
|
|
20
|
+
upsert(params: UpsertParams): Promise<string[]>;
|
|
21
|
+
query(params: QueryParams): Promise<QueryResult[]>;
|
|
22
|
+
delete(params: DeleteParams): Promise<void>;
|
|
23
|
+
update(indexName: string, id: string, metadata: Record<string, any>): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createChromaStore(config?: ChromaConfig): ChromaVectorStore;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Chroma Vector Store Integration
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ChromaVectorStore = void 0;
|
|
7
|
+
exports.createChromaStore = createChromaStore;
|
|
8
|
+
const base_1 = require("./base");
|
|
9
|
+
class ChromaVectorStore extends base_1.BaseVectorStore {
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
super({ id: config.id || 'chroma', name: 'ChromaVectorStore' });
|
|
12
|
+
const host = config.host || 'localhost';
|
|
13
|
+
const port = config.port || 8000;
|
|
14
|
+
this.baseUrl = config.path || `http://${host}:${port}`;
|
|
15
|
+
}
|
|
16
|
+
async request(path, options = {}) {
|
|
17
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
18
|
+
...options,
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
...options.headers
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
const error = await response.text();
|
|
26
|
+
throw new Error(`Chroma API error: ${response.status} - ${error}`);
|
|
27
|
+
}
|
|
28
|
+
const text = await response.text();
|
|
29
|
+
return text ? JSON.parse(text) : {};
|
|
30
|
+
}
|
|
31
|
+
async createIndex(params) {
|
|
32
|
+
const metadataMap = {
|
|
33
|
+
cosine: 'cosine',
|
|
34
|
+
euclidean: 'l2',
|
|
35
|
+
dotProduct: 'ip'
|
|
36
|
+
};
|
|
37
|
+
await this.request('/api/v1/collections', {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
body: JSON.stringify({
|
|
40
|
+
name: params.indexName,
|
|
41
|
+
metadata: {
|
|
42
|
+
'hnsw:space': metadataMap[params.metric || 'cosine'],
|
|
43
|
+
dimension: params.dimension
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async listIndexes() {
|
|
49
|
+
const response = await this.request('/api/v1/collections');
|
|
50
|
+
return (response || []).map((c) => c.name);
|
|
51
|
+
}
|
|
52
|
+
async describeIndex(indexName) {
|
|
53
|
+
const response = await this.request(`/api/v1/collections/${indexName}`);
|
|
54
|
+
const spaceMap = {
|
|
55
|
+
'cosine': 'cosine',
|
|
56
|
+
'l2': 'euclidean',
|
|
57
|
+
'ip': 'dotProduct'
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
dimension: response.metadata?.dimension || 0,
|
|
61
|
+
count: response.count || 0,
|
|
62
|
+
metric: spaceMap[response.metadata?.['hnsw:space']] || 'cosine'
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async deleteIndex(indexName) {
|
|
66
|
+
await this.request(`/api/v1/collections/${indexName}`, { method: 'DELETE' });
|
|
67
|
+
}
|
|
68
|
+
async upsert(params) {
|
|
69
|
+
const ids = params.vectors.map(v => v.id);
|
|
70
|
+
const embeddings = params.vectors.map(v => v.vector);
|
|
71
|
+
const metadatas = params.vectors.map(v => v.metadata || {});
|
|
72
|
+
const documents = params.vectors.map(v => v.content || '');
|
|
73
|
+
await this.request(`/api/v1/collections/${params.indexName}/upsert`, {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
ids,
|
|
77
|
+
embeddings,
|
|
78
|
+
metadatas,
|
|
79
|
+
documents
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
return ids;
|
|
83
|
+
}
|
|
84
|
+
async query(params) {
|
|
85
|
+
let where = undefined;
|
|
86
|
+
if (params.filter) {
|
|
87
|
+
where = params.filter;
|
|
88
|
+
}
|
|
89
|
+
const response = await this.request(`/api/v1/collections/${params.indexName}/query`, {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
body: JSON.stringify({
|
|
92
|
+
query_embeddings: [params.vector],
|
|
93
|
+
n_results: params.topK || 10,
|
|
94
|
+
where,
|
|
95
|
+
include: [
|
|
96
|
+
'documents',
|
|
97
|
+
'metadatas',
|
|
98
|
+
'distances',
|
|
99
|
+
...(params.includeVectors ? ['embeddings'] : [])
|
|
100
|
+
]
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
const ids = response.ids?.[0] || [];
|
|
104
|
+
const distances = response.distances?.[0] || [];
|
|
105
|
+
const metadatas = response.metadatas?.[0] || [];
|
|
106
|
+
const documents = response.documents?.[0] || [];
|
|
107
|
+
const embeddings = response.embeddings?.[0] || [];
|
|
108
|
+
return ids.map((id, i) => ({
|
|
109
|
+
id,
|
|
110
|
+
score: 1 - (distances[i] || 0), // Convert distance to similarity
|
|
111
|
+
metadata: metadatas[i],
|
|
112
|
+
content: documents[i],
|
|
113
|
+
vector: embeddings[i]
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
async delete(params) {
|
|
117
|
+
if (params.ids) {
|
|
118
|
+
await this.request(`/api/v1/collections/${params.indexName}/delete`, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
body: JSON.stringify({ ids: params.ids })
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else if (params.filter) {
|
|
124
|
+
await this.request(`/api/v1/collections/${params.indexName}/delete`, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
body: JSON.stringify({ where: params.filter })
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async update(indexName, id, metadata) {
|
|
131
|
+
await this.request(`/api/v1/collections/${indexName}/update`, {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
body: JSON.stringify({
|
|
134
|
+
ids: [id],
|
|
135
|
+
metadatas: [metadata]
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.ChromaVectorStore = ChromaVectorStore;
|
|
141
|
+
function createChromaStore(config) {
|
|
142
|
+
return new ChromaVectorStore(config);
|
|
143
|
+
}
|