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,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool Decorator and Registry - Type-safe tool creation and management
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ToolRegistry = exports.FunctionTool = void 0;
|
|
7
|
+
exports.tool = tool;
|
|
8
|
+
exports.getRegistry = getRegistry;
|
|
9
|
+
exports.registerTool = registerTool;
|
|
10
|
+
exports.getTool = getTool;
|
|
11
|
+
/**
|
|
12
|
+
* Tool class - Represents an executable tool
|
|
13
|
+
*/
|
|
14
|
+
class FunctionTool {
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.name = config.name;
|
|
17
|
+
this.description = config.description || `Function ${config.name}`;
|
|
18
|
+
this.parameters = this.normalizeParameters(config.parameters);
|
|
19
|
+
this.category = config.category;
|
|
20
|
+
this.executeFn = config.execute;
|
|
21
|
+
}
|
|
22
|
+
normalizeParameters(params) {
|
|
23
|
+
if (!params) {
|
|
24
|
+
return { type: 'object', properties: {}, required: [] };
|
|
25
|
+
}
|
|
26
|
+
// Check if it's a Zod schema
|
|
27
|
+
if (params && typeof params.parse === 'function' && typeof params._def === 'object') {
|
|
28
|
+
return this.zodToJsonSchema(params);
|
|
29
|
+
}
|
|
30
|
+
// Already a JSON schema
|
|
31
|
+
return params;
|
|
32
|
+
}
|
|
33
|
+
zodToJsonSchema(zodSchema) {
|
|
34
|
+
// Basic Zod to JSON Schema conversion
|
|
35
|
+
// For full support, use zod-to-json-schema package
|
|
36
|
+
const def = zodSchema._def;
|
|
37
|
+
if (def.typeName === 'ZodObject') {
|
|
38
|
+
const properties = {};
|
|
39
|
+
const required = [];
|
|
40
|
+
for (const [key, value] of Object.entries(def.shape())) {
|
|
41
|
+
const fieldDef = value._def;
|
|
42
|
+
properties[key] = this.zodFieldToJsonSchema(fieldDef);
|
|
43
|
+
// Check if field is required (not optional)
|
|
44
|
+
if (fieldDef.typeName !== 'ZodOptional' && fieldDef.typeName !== 'ZodDefault') {
|
|
45
|
+
required.push(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { type: 'object', properties, required };
|
|
49
|
+
}
|
|
50
|
+
return { type: 'object', properties: {}, required: [] };
|
|
51
|
+
}
|
|
52
|
+
zodFieldToJsonSchema(def) {
|
|
53
|
+
const typeName = def.typeName;
|
|
54
|
+
switch (typeName) {
|
|
55
|
+
case 'ZodString':
|
|
56
|
+
return { type: 'string', description: def.description };
|
|
57
|
+
case 'ZodNumber':
|
|
58
|
+
return { type: 'number', description: def.description };
|
|
59
|
+
case 'ZodBoolean':
|
|
60
|
+
return { type: 'boolean', description: def.description };
|
|
61
|
+
case 'ZodArray':
|
|
62
|
+
return { type: 'array', items: this.zodFieldToJsonSchema(def.type._def) };
|
|
63
|
+
case 'ZodEnum':
|
|
64
|
+
return { type: 'string', enum: def.values };
|
|
65
|
+
case 'ZodOptional':
|
|
66
|
+
return this.zodFieldToJsonSchema(def.innerType._def);
|
|
67
|
+
case 'ZodDefault':
|
|
68
|
+
const inner = this.zodFieldToJsonSchema(def.innerType._def);
|
|
69
|
+
inner.default = def.defaultValue();
|
|
70
|
+
return inner;
|
|
71
|
+
default:
|
|
72
|
+
return { type: 'string' };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async execute(params, context) {
|
|
76
|
+
// Validate parameters if we have a schema
|
|
77
|
+
// For now, just execute - validation can be added later
|
|
78
|
+
return this.executeFn(params, context);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the tool definition for LLM
|
|
82
|
+
*/
|
|
83
|
+
getDefinition() {
|
|
84
|
+
return {
|
|
85
|
+
name: this.name,
|
|
86
|
+
description: this.description,
|
|
87
|
+
parameters: this.parameters,
|
|
88
|
+
category: this.category,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get OpenAI-compatible tool format
|
|
93
|
+
*/
|
|
94
|
+
toOpenAITool() {
|
|
95
|
+
return {
|
|
96
|
+
type: 'function',
|
|
97
|
+
function: {
|
|
98
|
+
name: this.name,
|
|
99
|
+
description: this.description,
|
|
100
|
+
parameters: this.parameters,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.FunctionTool = FunctionTool;
|
|
106
|
+
/**
|
|
107
|
+
* Create a tool from a configuration object
|
|
108
|
+
*/
|
|
109
|
+
function tool(config) {
|
|
110
|
+
return new FunctionTool(config);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Tool Registry - Manages tool registration and lookup
|
|
114
|
+
*/
|
|
115
|
+
class ToolRegistry {
|
|
116
|
+
constructor() {
|
|
117
|
+
this.tools = new Map();
|
|
118
|
+
}
|
|
119
|
+
register(tool, options) {
|
|
120
|
+
if (this.tools.has(tool.name) && !options?.overwrite) {
|
|
121
|
+
throw new Error(`Tool '${tool.name}' is already registered. Use { overwrite: true } to replace.`);
|
|
122
|
+
}
|
|
123
|
+
this.tools.set(tool.name, tool);
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
get(name) {
|
|
127
|
+
return this.tools.get(name);
|
|
128
|
+
}
|
|
129
|
+
has(name) {
|
|
130
|
+
return this.tools.has(name);
|
|
131
|
+
}
|
|
132
|
+
list() {
|
|
133
|
+
return Array.from(this.tools.values());
|
|
134
|
+
}
|
|
135
|
+
getByCategory(category) {
|
|
136
|
+
return this.list().filter(t => t.category === category);
|
|
137
|
+
}
|
|
138
|
+
getDefinitions() {
|
|
139
|
+
return this.list().map(t => t.getDefinition());
|
|
140
|
+
}
|
|
141
|
+
toOpenAITools() {
|
|
142
|
+
return this.list().map(t => t.toOpenAITool());
|
|
143
|
+
}
|
|
144
|
+
delete(name) {
|
|
145
|
+
return this.tools.delete(name);
|
|
146
|
+
}
|
|
147
|
+
clear() {
|
|
148
|
+
this.tools.clear();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.ToolRegistry = ToolRegistry;
|
|
152
|
+
// Global registry instance
|
|
153
|
+
let globalRegistry = null;
|
|
154
|
+
function getRegistry() {
|
|
155
|
+
if (!globalRegistry) {
|
|
156
|
+
globalRegistry = new ToolRegistry();
|
|
157
|
+
}
|
|
158
|
+
return globalRegistry;
|
|
159
|
+
}
|
|
160
|
+
function registerTool(tool, options) {
|
|
161
|
+
getRegistry().register(tool, options);
|
|
162
|
+
}
|
|
163
|
+
function getTool(name) {
|
|
164
|
+
return getRegistry().get(name);
|
|
165
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BaseTool, ToolResult, ToolValidationError, validateTool, createTool, type ToolParameters } from './base';
|
|
2
|
+
export * from './decorator';
|
|
3
|
+
export * from './arxivTools';
|
|
4
|
+
export * from './mcpSse';
|
|
5
|
+
export * from './registry';
|
|
6
|
+
export * from './builtins';
|
|
7
|
+
export { tools, registerBuiltinTools } from './tools';
|
|
8
|
+
export type { default as ToolsFacade } from './tools';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.registerBuiltinTools = exports.tools = exports.createTool = exports.validateTool = exports.ToolValidationError = exports.BaseTool = void 0;
|
|
18
|
+
// Export base tool interfaces and classes
|
|
19
|
+
var base_1 = require("./base");
|
|
20
|
+
Object.defineProperty(exports, "BaseTool", { enumerable: true, get: function () { return base_1.BaseTool; } });
|
|
21
|
+
Object.defineProperty(exports, "ToolValidationError", { enumerable: true, get: function () { return base_1.ToolValidationError; } });
|
|
22
|
+
Object.defineProperty(exports, "validateTool", { enumerable: true, get: function () { return base_1.validateTool; } });
|
|
23
|
+
Object.defineProperty(exports, "createTool", { enumerable: true, get: function () { return base_1.createTool; } });
|
|
24
|
+
// Export decorator and registry (legacy)
|
|
25
|
+
__exportStar(require("./decorator"), exports);
|
|
26
|
+
// Export all tool modules
|
|
27
|
+
__exportStar(require("./arxivTools"), exports);
|
|
28
|
+
__exportStar(require("./mcpSse"), exports);
|
|
29
|
+
// Export new registry system
|
|
30
|
+
__exportStar(require("./registry"), exports);
|
|
31
|
+
// Export built-in tools
|
|
32
|
+
__exportStar(require("./builtins"), exports);
|
|
33
|
+
// Export tools facade
|
|
34
|
+
var tools_1 = require("./tools");
|
|
35
|
+
Object.defineProperty(exports, "tools", { enumerable: true, get: function () { return tools_1.tools; } });
|
|
36
|
+
Object.defineProperty(exports, "registerBuiltinTools", { enumerable: true, get: function () { return tools_1.registerBuiltinTools; } });
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import { BaseTool } from './base';
|
|
3
|
+
export interface MCPToolInfo {
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
inputSchema?: any;
|
|
7
|
+
}
|
|
8
|
+
export declare class MCPTool extends BaseTool<any, any> {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
private client;
|
|
12
|
+
private inputSchema;
|
|
13
|
+
constructor(info: MCPToolInfo, client: Client);
|
|
14
|
+
get schemaProperties(): Record<string, any> | undefined;
|
|
15
|
+
run(args?: any): Promise<any>;
|
|
16
|
+
toOpenAITool(): {
|
|
17
|
+
type: string;
|
|
18
|
+
function: {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
parameters: any;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare class MCP implements Iterable<MCPTool> {
|
|
26
|
+
private url;
|
|
27
|
+
private debug;
|
|
28
|
+
tools: MCPTool[];
|
|
29
|
+
private client;
|
|
30
|
+
constructor(url: string, debug?: boolean);
|
|
31
|
+
initialize(): Promise<void>;
|
|
32
|
+
[Symbol.iterator](): Iterator<MCPTool>;
|
|
33
|
+
toOpenAITools(): {
|
|
34
|
+
type: string;
|
|
35
|
+
function: {
|
|
36
|
+
name: string;
|
|
37
|
+
description: string;
|
|
38
|
+
parameters: any;
|
|
39
|
+
};
|
|
40
|
+
}[];
|
|
41
|
+
close(): Promise<void>;
|
|
42
|
+
get isConnected(): boolean;
|
|
43
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP = exports.MCPTool = void 0;
|
|
4
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
5
|
+
const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
class MCPTool extends base_1.BaseTool {
|
|
8
|
+
constructor(info, client) {
|
|
9
|
+
super();
|
|
10
|
+
this.name = info.name;
|
|
11
|
+
this.description = info.description || `Call the ${info.name} tool`;
|
|
12
|
+
this.client = client;
|
|
13
|
+
this.inputSchema = info.inputSchema || { type: 'object', properties: {}, required: [] };
|
|
14
|
+
}
|
|
15
|
+
get schemaProperties() {
|
|
16
|
+
return this.inputSchema?.properties;
|
|
17
|
+
}
|
|
18
|
+
async run(args = {}) {
|
|
19
|
+
try {
|
|
20
|
+
const result = await this.client.callTool({ name: this.name, arguments: args });
|
|
21
|
+
if (result.structuredContent) {
|
|
22
|
+
return result.structuredContent;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(result.content) && result.content.length > 0) {
|
|
25
|
+
const item = result.content[0];
|
|
26
|
+
if (typeof item.text === 'string')
|
|
27
|
+
return item.text;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error(`Failed to execute tool ${this.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
toOpenAITool() {
|
|
36
|
+
return {
|
|
37
|
+
type: 'function',
|
|
38
|
+
function: {
|
|
39
|
+
name: this.name,
|
|
40
|
+
description: this.description,
|
|
41
|
+
parameters: this.inputSchema
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.MCPTool = MCPTool;
|
|
47
|
+
class MCP {
|
|
48
|
+
constructor(url, debug = false) {
|
|
49
|
+
this.url = url;
|
|
50
|
+
this.debug = debug;
|
|
51
|
+
this.tools = [];
|
|
52
|
+
this.client = null;
|
|
53
|
+
if (debug) {
|
|
54
|
+
console.log(`MCP client initialized for URL: ${url}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async initialize() {
|
|
58
|
+
if (this.client) {
|
|
59
|
+
if (this.debug)
|
|
60
|
+
console.log('MCP client already initialized');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
this.client = new index_js_1.Client({ name: 'praisonai-ts-mcp', version: '1.0.0' });
|
|
65
|
+
const transport = new sse_js_1.SSEClientTransport(new URL(this.url));
|
|
66
|
+
await this.client.connect(transport);
|
|
67
|
+
const { tools } = await this.client.listTools();
|
|
68
|
+
this.tools = tools.map((t) => new MCPTool({
|
|
69
|
+
name: t.name,
|
|
70
|
+
description: t.description,
|
|
71
|
+
inputSchema: t.inputSchema
|
|
72
|
+
}, this.client));
|
|
73
|
+
if (this.debug)
|
|
74
|
+
console.log(`Initialized MCP with ${this.tools.length} tools`);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (this.client) {
|
|
78
|
+
await this.client.close().catch(() => { });
|
|
79
|
+
this.client = null;
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`Failed to initialize MCP client: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
[Symbol.iterator]() {
|
|
85
|
+
return this.tools[Symbol.iterator]();
|
|
86
|
+
}
|
|
87
|
+
toOpenAITools() {
|
|
88
|
+
return this.tools.map(t => t.toOpenAITool());
|
|
89
|
+
}
|
|
90
|
+
async close() {
|
|
91
|
+
if (this.client) {
|
|
92
|
+
try {
|
|
93
|
+
await this.client.close();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (this.debug) {
|
|
97
|
+
console.warn('Error closing MCP client:', error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
this.client = null;
|
|
102
|
+
this.tools = [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
get isConnected() {
|
|
107
|
+
return this.client !== null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.MCP = MCP;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI SDK Tools Registry - Main Exports
|
|
3
|
+
*
|
|
4
|
+
* Lazy-loaded exports for the tools registry system.
|
|
5
|
+
*/
|
|
6
|
+
export type { ToolExecutionContext, ToolLimits, RedactionHooks, ToolLogger, ToolCapabilities, InstallHints, ToolMetadata, ToolExecutionResult, PraisonTool, ToolParameterSchema, ToolParameterProperty, ToolMiddleware, ToolHooks, ToolFactory, RegisteredTool, ToolInstallStatus, } from './types';
|
|
7
|
+
export { MissingDependencyError, MissingEnvVarError } from './types';
|
|
8
|
+
export { ToolsRegistry, getToolsRegistry, createToolsRegistry, resetToolsRegistry, } from './registry';
|
|
9
|
+
export { createLoggingMiddleware, createTimeoutMiddleware, createRedactionMiddleware, createRateLimitMiddleware, createRetryMiddleware, createTracingMiddleware, createValidationMiddleware, composeMiddleware, } from './middleware';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI SDK Tools Registry - Main Exports
|
|
4
|
+
*
|
|
5
|
+
* Lazy-loaded exports for the tools registry system.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.composeMiddleware = exports.createValidationMiddleware = exports.createTracingMiddleware = exports.createRetryMiddleware = exports.createRateLimitMiddleware = exports.createRedactionMiddleware = exports.createTimeoutMiddleware = exports.createLoggingMiddleware = exports.resetToolsRegistry = exports.createToolsRegistry = exports.getToolsRegistry = exports.ToolsRegistry = exports.MissingEnvVarError = exports.MissingDependencyError = void 0;
|
|
9
|
+
// Errors
|
|
10
|
+
var types_1 = require("./types");
|
|
11
|
+
Object.defineProperty(exports, "MissingDependencyError", { enumerable: true, get: function () { return types_1.MissingDependencyError; } });
|
|
12
|
+
Object.defineProperty(exports, "MissingEnvVarError", { enumerable: true, get: function () { return types_1.MissingEnvVarError; } });
|
|
13
|
+
// Registry
|
|
14
|
+
var registry_1 = require("./registry");
|
|
15
|
+
Object.defineProperty(exports, "ToolsRegistry", { enumerable: true, get: function () { return registry_1.ToolsRegistry; } });
|
|
16
|
+
Object.defineProperty(exports, "getToolsRegistry", { enumerable: true, get: function () { return registry_1.getToolsRegistry; } });
|
|
17
|
+
Object.defineProperty(exports, "createToolsRegistry", { enumerable: true, get: function () { return registry_1.createToolsRegistry; } });
|
|
18
|
+
Object.defineProperty(exports, "resetToolsRegistry", { enumerable: true, get: function () { return registry_1.resetToolsRegistry; } });
|
|
19
|
+
// Middleware
|
|
20
|
+
var middleware_1 = require("./middleware");
|
|
21
|
+
Object.defineProperty(exports, "createLoggingMiddleware", { enumerable: true, get: function () { return middleware_1.createLoggingMiddleware; } });
|
|
22
|
+
Object.defineProperty(exports, "createTimeoutMiddleware", { enumerable: true, get: function () { return middleware_1.createTimeoutMiddleware; } });
|
|
23
|
+
Object.defineProperty(exports, "createRedactionMiddleware", { enumerable: true, get: function () { return middleware_1.createRedactionMiddleware; } });
|
|
24
|
+
Object.defineProperty(exports, "createRateLimitMiddleware", { enumerable: true, get: function () { return middleware_1.createRateLimitMiddleware; } });
|
|
25
|
+
Object.defineProperty(exports, "createRetryMiddleware", { enumerable: true, get: function () { return middleware_1.createRetryMiddleware; } });
|
|
26
|
+
Object.defineProperty(exports, "createTracingMiddleware", { enumerable: true, get: function () { return middleware_1.createTracingMiddleware; } });
|
|
27
|
+
Object.defineProperty(exports, "createValidationMiddleware", { enumerable: true, get: function () { return middleware_1.createValidationMiddleware; } });
|
|
28
|
+
Object.defineProperty(exports, "composeMiddleware", { enumerable: true, get: function () { return middleware_1.composeMiddleware; } });
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI SDK Tools Registry - Middleware Pipeline
|
|
3
|
+
*
|
|
4
|
+
* Composable middleware for tool execution:
|
|
5
|
+
* - Logging
|
|
6
|
+
* - Tracing
|
|
7
|
+
* - Rate limiting
|
|
8
|
+
* - Redaction
|
|
9
|
+
* - Timeout handling
|
|
10
|
+
*/
|
|
11
|
+
import type { ToolMiddleware, ToolLogger } from './types';
|
|
12
|
+
/**
|
|
13
|
+
* Create a logging middleware
|
|
14
|
+
*/
|
|
15
|
+
export declare function createLoggingMiddleware(logger?: ToolLogger): ToolMiddleware;
|
|
16
|
+
/**
|
|
17
|
+
* Create a timeout middleware
|
|
18
|
+
*/
|
|
19
|
+
export declare function createTimeoutMiddleware(defaultTimeoutMs?: number): ToolMiddleware;
|
|
20
|
+
/**
|
|
21
|
+
* Create a redaction middleware for PII/sensitive data
|
|
22
|
+
*/
|
|
23
|
+
export declare function createRedactionMiddleware(patterns?: RegExp[]): ToolMiddleware;
|
|
24
|
+
/**
|
|
25
|
+
* Create a rate limiting middleware (simple token bucket)
|
|
26
|
+
*/
|
|
27
|
+
export declare function createRateLimitMiddleware(maxRequests?: number, windowMs?: number): ToolMiddleware;
|
|
28
|
+
/**
|
|
29
|
+
* Create a retry middleware with exponential backoff
|
|
30
|
+
*/
|
|
31
|
+
export declare function createRetryMiddleware(maxRetries?: number, baseDelayMs?: number): ToolMiddleware;
|
|
32
|
+
/**
|
|
33
|
+
* Create a tracing middleware that adds trace context
|
|
34
|
+
*/
|
|
35
|
+
export declare function createTracingMiddleware(): ToolMiddleware;
|
|
36
|
+
/**
|
|
37
|
+
* Create a validation middleware that checks input against limits
|
|
38
|
+
*/
|
|
39
|
+
export declare function createValidationMiddleware(): ToolMiddleware;
|
|
40
|
+
/**
|
|
41
|
+
* Compose multiple middleware into a single middleware
|
|
42
|
+
*/
|
|
43
|
+
export declare function composeMiddleware(...middlewares: ToolMiddleware[]): ToolMiddleware;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI SDK Tools Registry - Middleware Pipeline
|
|
4
|
+
*
|
|
5
|
+
* Composable middleware for tool execution:
|
|
6
|
+
* - Logging
|
|
7
|
+
* - Tracing
|
|
8
|
+
* - Rate limiting
|
|
9
|
+
* - Redaction
|
|
10
|
+
* - Timeout handling
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.createLoggingMiddleware = createLoggingMiddleware;
|
|
14
|
+
exports.createTimeoutMiddleware = createTimeoutMiddleware;
|
|
15
|
+
exports.createRedactionMiddleware = createRedactionMiddleware;
|
|
16
|
+
exports.createRateLimitMiddleware = createRateLimitMiddleware;
|
|
17
|
+
exports.createRetryMiddleware = createRetryMiddleware;
|
|
18
|
+
exports.createTracingMiddleware = createTracingMiddleware;
|
|
19
|
+
exports.createValidationMiddleware = createValidationMiddleware;
|
|
20
|
+
exports.composeMiddleware = composeMiddleware;
|
|
21
|
+
/**
|
|
22
|
+
* Create a logging middleware
|
|
23
|
+
*/
|
|
24
|
+
function createLoggingMiddleware(logger) {
|
|
25
|
+
const log = logger || console;
|
|
26
|
+
return async (input, context, next) => {
|
|
27
|
+
const startTime = Date.now();
|
|
28
|
+
const traceId = context.traceId || 'unknown';
|
|
29
|
+
log.debug?.(`[${traceId}] Tool call started`, { input });
|
|
30
|
+
try {
|
|
31
|
+
const result = await next();
|
|
32
|
+
const duration = Date.now() - startTime;
|
|
33
|
+
log.debug?.(`[${traceId}] Tool call completed in ${duration}ms`);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
const duration = Date.now() - startTime;
|
|
38
|
+
log.error?.(`[${traceId}] Tool call failed after ${duration}ms`, error);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a timeout middleware
|
|
45
|
+
*/
|
|
46
|
+
function createTimeoutMiddleware(defaultTimeoutMs = 30000) {
|
|
47
|
+
return async (input, context, next) => {
|
|
48
|
+
const timeoutMs = context.limits?.timeoutMs || defaultTimeoutMs;
|
|
49
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
reject(new Error(`Tool execution timed out after ${timeoutMs}ms`));
|
|
52
|
+
}, timeoutMs);
|
|
53
|
+
});
|
|
54
|
+
return Promise.race([next(), timeoutPromise]);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a redaction middleware for PII/sensitive data
|
|
59
|
+
*/
|
|
60
|
+
function createRedactionMiddleware(patterns) {
|
|
61
|
+
const defaultPatterns = [
|
|
62
|
+
// Email
|
|
63
|
+
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
|
|
64
|
+
// SSN
|
|
65
|
+
/\b\d{3}-\d{2}-\d{4}\b/g,
|
|
66
|
+
// Credit card
|
|
67
|
+
/\b\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}\b/g,
|
|
68
|
+
// Phone (US)
|
|
69
|
+
/\b\d{3}[-.]?\d{3}[-.]?\d{4}\b/g,
|
|
70
|
+
];
|
|
71
|
+
const allPatterns = [...defaultPatterns, ...(patterns || [])];
|
|
72
|
+
const redact = (value) => {
|
|
73
|
+
if (typeof value === 'string') {
|
|
74
|
+
let result = value;
|
|
75
|
+
for (const pattern of allPatterns) {
|
|
76
|
+
result = result.replace(pattern, '[REDACTED]');
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
if (Array.isArray(value)) {
|
|
81
|
+
return value.map(redact);
|
|
82
|
+
}
|
|
83
|
+
if (value && typeof value === 'object') {
|
|
84
|
+
const result = {};
|
|
85
|
+
for (const [k, v] of Object.entries(value)) {
|
|
86
|
+
result[k] = redact(v);
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
};
|
|
92
|
+
return async (input, context, next) => {
|
|
93
|
+
// Redact input if hooks are set
|
|
94
|
+
const redactedInput = context.redaction?.redactInput
|
|
95
|
+
? context.redaction.redactInput(input)
|
|
96
|
+
: redact(input);
|
|
97
|
+
// Execute with redacted input
|
|
98
|
+
const result = await next();
|
|
99
|
+
// Redact output if hooks are set
|
|
100
|
+
const redactedOutput = context.redaction?.redactOutput
|
|
101
|
+
? context.redaction.redactOutput(result)
|
|
102
|
+
: redact(result);
|
|
103
|
+
return redactedOutput;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Create a rate limiting middleware (simple token bucket)
|
|
108
|
+
*/
|
|
109
|
+
function createRateLimitMiddleware(maxRequests = 10, windowMs = 1000) {
|
|
110
|
+
const requests = [];
|
|
111
|
+
return async (input, context, next) => {
|
|
112
|
+
const now = Date.now();
|
|
113
|
+
// Remove old requests outside the window
|
|
114
|
+
while (requests.length > 0 && requests[0] < now - windowMs) {
|
|
115
|
+
requests.shift();
|
|
116
|
+
}
|
|
117
|
+
if (requests.length >= maxRequests) {
|
|
118
|
+
const waitTime = requests[0] + windowMs - now;
|
|
119
|
+
throw new Error(`Rate limit exceeded. Try again in ${waitTime}ms`);
|
|
120
|
+
}
|
|
121
|
+
requests.push(now);
|
|
122
|
+
return next();
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Create a retry middleware with exponential backoff
|
|
127
|
+
*/
|
|
128
|
+
function createRetryMiddleware(maxRetries = 3, baseDelayMs = 1000) {
|
|
129
|
+
return async (input, context, next) => {
|
|
130
|
+
let lastError;
|
|
131
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
132
|
+
try {
|
|
133
|
+
return await next();
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
137
|
+
if (attempt < maxRetries) {
|
|
138
|
+
const delay = baseDelayMs * Math.pow(2, attempt);
|
|
139
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
throw lastError;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create a tracing middleware that adds trace context
|
|
148
|
+
*/
|
|
149
|
+
function createTracingMiddleware() {
|
|
150
|
+
return async (input, context, next) => {
|
|
151
|
+
// Generate trace ID if not present
|
|
152
|
+
if (!context.traceId) {
|
|
153
|
+
context.traceId = generateTraceId();
|
|
154
|
+
}
|
|
155
|
+
// Add span for this tool call
|
|
156
|
+
const spanId = generateSpanId();
|
|
157
|
+
const startTime = Date.now();
|
|
158
|
+
try {
|
|
159
|
+
const result = await next();
|
|
160
|
+
// Log span completion
|
|
161
|
+
if (context.logger) {
|
|
162
|
+
context.logger.debug('Tool span completed', {
|
|
163
|
+
traceId: context.traceId,
|
|
164
|
+
spanId,
|
|
165
|
+
durationMs: Date.now() - startTime,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (context.logger) {
|
|
172
|
+
context.logger.error('Tool span failed', {
|
|
173
|
+
traceId: context.traceId,
|
|
174
|
+
spanId,
|
|
175
|
+
durationMs: Date.now() - startTime,
|
|
176
|
+
error,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Create a validation middleware that checks input against limits
|
|
185
|
+
*/
|
|
186
|
+
function createValidationMiddleware() {
|
|
187
|
+
return async (input, context, next) => {
|
|
188
|
+
const limits = context.limits;
|
|
189
|
+
if (limits?.maxPayloadBytes) {
|
|
190
|
+
const size = JSON.stringify(input).length;
|
|
191
|
+
if (size > limits.maxPayloadBytes) {
|
|
192
|
+
throw new Error(`Input payload size (${size} bytes) exceeds limit (${limits.maxPayloadBytes} bytes)`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return next();
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Compose multiple middleware into a single middleware
|
|
200
|
+
*/
|
|
201
|
+
function composeMiddleware(...middlewares) {
|
|
202
|
+
return async (input, context, next) => {
|
|
203
|
+
let index = 0;
|
|
204
|
+
const composedNext = async () => {
|
|
205
|
+
if (index < middlewares.length) {
|
|
206
|
+
const mw = middlewares[index++];
|
|
207
|
+
return mw(input, context, composedNext);
|
|
208
|
+
}
|
|
209
|
+
return next();
|
|
210
|
+
};
|
|
211
|
+
return composedNext();
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
// Helper functions
|
|
215
|
+
function generateTraceId() {
|
|
216
|
+
return `trace_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 11)}`;
|
|
217
|
+
}
|
|
218
|
+
function generateSpanId() {
|
|
219
|
+
return `span_${Math.random().toString(36).slice(2, 11)}`;
|
|
220
|
+
}
|