beddel 0.2.2 → 0.3.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/CHANGELOG.md +50 -0
- package/README.md +117 -14
- package/dist/agents/chat/chat.handler.d.ts +12 -0
- package/dist/agents/chat/chat.handler.d.ts.map +1 -0
- package/dist/agents/chat/chat.handler.js +145 -0
- package/dist/agents/chat/chat.handler.js.map +1 -0
- package/dist/agents/chat/chat.schema.d.ts +38 -0
- package/dist/agents/chat/chat.schema.d.ts.map +1 -0
- package/dist/agents/chat/chat.schema.js +31 -0
- package/dist/agents/chat/chat.schema.js.map +1 -0
- package/dist/agents/chat/chat.types.d.ts +42 -0
- package/dist/agents/chat/chat.types.d.ts.map +1 -0
- package/dist/agents/chat/chat.types.js +6 -0
- package/dist/agents/chat/chat.types.js.map +1 -0
- package/dist/agents/chat/chat.yaml +148 -0
- package/dist/agents/chat/index.d.ts +16 -0
- package/dist/agents/chat/index.d.ts.map +1 -0
- package/dist/agents/chat/index.js +21 -0
- package/dist/agents/chat/index.js.map +1 -0
- package/dist/agents/chromadb/chromadb.handler.d.ts +12 -0
- package/dist/agents/chromadb/chromadb.handler.d.ts.map +1 -0
- package/dist/agents/chromadb/chromadb.handler.js +139 -0
- package/dist/agents/chromadb/chromadb.handler.js.map +1 -0
- package/dist/agents/chromadb/chromadb.schema.d.ts +36 -0
- package/dist/agents/chromadb/chromadb.schema.d.ts.map +1 -0
- package/dist/agents/chromadb/chromadb.schema.js +33 -0
- package/dist/agents/chromadb/chromadb.schema.js.map +1 -0
- package/dist/agents/chromadb/chromadb.types.d.ts +49 -0
- package/dist/agents/chromadb/chromadb.types.d.ts.map +1 -0
- package/dist/agents/chromadb/chromadb.types.js +6 -0
- package/dist/agents/chromadb/chromadb.types.js.map +1 -0
- package/dist/agents/chromadb/chromadb.yaml +128 -0
- package/dist/agents/chromadb/index.d.ts +15 -0
- package/dist/agents/chromadb/index.d.ts.map +1 -0
- package/dist/agents/chromadb/index.js +20 -0
- package/dist/agents/chromadb/index.js.map +1 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.handler.d.ts +8 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.handler.d.ts.map +1 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.handler.js +61 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.handler.js.map +1 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.schema.d.ts +22 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.schema.d.ts.map +1 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.schema.js +20 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.schema.js.map +1 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.types.d.ts +32 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.types.d.ts.map +1 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.types.js +6 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.types.js.map +1 -0
- package/dist/agents/gemini-vectorize/gemini-vectorize.yaml +84 -0
- package/dist/agents/gemini-vectorize/index.d.ts +15 -0
- package/dist/agents/gemini-vectorize/index.d.ts.map +1 -0
- package/dist/agents/gemini-vectorize/index.js +20 -0
- package/dist/agents/gemini-vectorize/index.js.map +1 -0
- package/dist/agents/gitmcp/gitmcp.handler.d.ts +12 -0
- package/dist/agents/gitmcp/gitmcp.handler.d.ts.map +1 -0
- package/dist/agents/gitmcp/gitmcp.handler.js +95 -0
- package/dist/agents/gitmcp/gitmcp.handler.js.map +1 -0
- package/dist/agents/gitmcp/gitmcp.schema.d.ts +17 -0
- package/dist/agents/gitmcp/gitmcp.schema.d.ts.map +1 -0
- package/dist/agents/gitmcp/gitmcp.schema.js +18 -0
- package/dist/agents/gitmcp/gitmcp.schema.js.map +1 -0
- package/dist/agents/gitmcp/gitmcp.types.d.ts +31 -0
- package/dist/agents/gitmcp/gitmcp.types.d.ts.map +1 -0
- package/dist/agents/gitmcp/gitmcp.types.js +6 -0
- package/dist/agents/gitmcp/gitmcp.types.js.map +1 -0
- package/dist/agents/gitmcp/gitmcp.yaml +71 -0
- package/dist/agents/gitmcp/index.d.ts +16 -0
- package/dist/agents/gitmcp/index.d.ts.map +1 -0
- package/dist/agents/gitmcp/index.js +21 -0
- package/dist/agents/gitmcp/index.js.map +1 -0
- package/dist/agents/image/image.handler.d.ts +8 -0
- package/dist/agents/image/image.handler.d.ts.map +1 -0
- package/dist/agents/image/image.handler.js +69 -0
- package/dist/agents/image/image.handler.js.map +1 -0
- package/dist/agents/image/image.schema.d.ts +29 -0
- package/dist/agents/image/image.schema.d.ts.map +1 -0
- package/dist/agents/image/image.schema.js +26 -0
- package/dist/agents/image/image.schema.js.map +1 -0
- package/dist/agents/image/image.types.d.ts +43 -0
- package/dist/agents/image/image.types.d.ts.map +1 -0
- package/dist/agents/image/image.types.js +6 -0
- package/dist/agents/image/image.types.js.map +1 -0
- package/{src/agents/image-agent.yaml → dist/agents/image/image.yaml} +21 -21
- package/dist/agents/image/index.d.ts +14 -0
- package/dist/agents/image/index.d.ts.map +1 -0
- package/dist/agents/image/index.js +19 -0
- package/dist/agents/image/index.js.map +1 -0
- package/dist/agents/index.d.ts +104 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +82 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/joker/index.d.ts +14 -0
- package/dist/agents/joker/index.d.ts.map +1 -0
- package/dist/agents/joker/index.js +19 -0
- package/dist/agents/joker/index.js.map +1 -0
- package/dist/agents/joker/joker.handler.d.ts +8 -0
- package/dist/agents/joker/joker.handler.d.ts.map +1 -0
- package/dist/agents/joker/joker.handler.js +44 -0
- package/dist/agents/joker/joker.handler.js.map +1 -0
- package/dist/agents/joker/joker.schema.d.ts +12 -0
- package/dist/agents/joker/joker.schema.d.ts.map +1 -0
- package/dist/agents/joker/joker.schema.js +13 -0
- package/dist/agents/joker/joker.schema.js.map +1 -0
- package/dist/agents/joker/joker.types.d.ts +36 -0
- package/dist/agents/joker/joker.types.d.ts.map +1 -0
- package/dist/agents/joker/joker.types.js +6 -0
- package/dist/agents/joker/joker.types.js.map +1 -0
- package/{src/agents/joker-agent.yaml → dist/agents/joker/joker.yaml} +4 -4
- package/dist/agents/llm/index.d.ts +15 -0
- package/dist/agents/llm/index.d.ts.map +1 -0
- package/dist/agents/llm/index.js +20 -0
- package/dist/agents/llm/index.js.map +1 -0
- package/dist/agents/llm/llm.handler.d.ts +8 -0
- package/dist/agents/llm/llm.handler.d.ts.map +1 -0
- package/dist/agents/llm/llm.handler.js +64 -0
- package/dist/agents/llm/llm.handler.js.map +1 -0
- package/dist/agents/llm/llm.schema.d.ts +26 -0
- package/dist/agents/llm/llm.schema.d.ts.map +1 -0
- package/dist/agents/llm/llm.schema.js +23 -0
- package/dist/agents/llm/llm.schema.js.map +1 -0
- package/dist/agents/llm/llm.types.d.ts +34 -0
- package/dist/agents/llm/llm.types.d.ts.map +1 -0
- package/dist/agents/llm/llm.types.js +7 -0
- package/dist/agents/llm/llm.types.js.map +1 -0
- package/dist/agents/llm/llm.yaml +87 -0
- package/dist/agents/mcp-tool/index.d.ts +14 -0
- package/dist/agents/mcp-tool/index.d.ts.map +1 -0
- package/dist/agents/mcp-tool/index.js +19 -0
- package/dist/agents/mcp-tool/index.js.map +1 -0
- package/dist/agents/mcp-tool/mcp-tool.handler.d.ts +12 -0
- package/dist/agents/mcp-tool/mcp-tool.handler.d.ts.map +1 -0
- package/dist/agents/mcp-tool/mcp-tool.handler.js +116 -0
- package/dist/agents/mcp-tool/mcp-tool.handler.js.map +1 -0
- package/dist/agents/mcp-tool/mcp-tool.schema.d.ts +19 -0
- package/dist/agents/mcp-tool/mcp-tool.schema.d.ts.map +1 -0
- package/dist/agents/mcp-tool/mcp-tool.schema.js +20 -0
- package/dist/agents/mcp-tool/mcp-tool.schema.js.map +1 -0
- package/dist/agents/mcp-tool/mcp-tool.types.d.ts +31 -0
- package/dist/agents/mcp-tool/mcp-tool.types.d.ts.map +1 -0
- package/dist/agents/mcp-tool/mcp-tool.types.js +6 -0
- package/dist/agents/mcp-tool/mcp-tool.types.js.map +1 -0
- package/dist/agents/mcp-tool/mcp-tool.yaml +71 -0
- package/dist/agents/rag/index.d.ts +15 -0
- package/dist/agents/rag/index.d.ts.map +1 -0
- package/dist/agents/rag/index.js +20 -0
- package/dist/agents/rag/index.js.map +1 -0
- package/dist/agents/rag/rag.handler.d.ts +9 -0
- package/dist/agents/rag/rag.handler.d.ts.map +1 -0
- package/dist/agents/rag/rag.handler.js +78 -0
- package/dist/agents/rag/rag.handler.js.map +1 -0
- package/dist/agents/rag/rag.schema.d.ts +27 -0
- package/dist/agents/rag/rag.schema.d.ts.map +1 -0
- package/dist/agents/rag/rag.schema.js +24 -0
- package/dist/agents/rag/rag.schema.js.map +1 -0
- package/dist/agents/rag/rag.types.d.ts +42 -0
- package/dist/agents/rag/rag.types.d.ts.map +1 -0
- package/dist/agents/rag/rag.types.js +7 -0
- package/dist/agents/rag/rag.types.js.map +1 -0
- package/dist/agents/rag/rag.yaml +89 -0
- package/dist/agents/{agentRegistry.d.ts → registry/agentRegistry.d.ts} +30 -1
- package/dist/agents/registry/agentRegistry.d.ts.map +1 -0
- package/dist/agents/{agentRegistry.js → registry/agentRegistry.js} +187 -5
- package/dist/agents/registry/agentRegistry.js.map +1 -0
- package/dist/agents/registry/index.d.ts +6 -0
- package/dist/agents/registry/index.d.ts.map +1 -0
- package/dist/agents/registry/index.js +10 -0
- package/dist/agents/registry/index.js.map +1 -0
- package/dist/agents/translator/index.d.ts +14 -0
- package/dist/agents/translator/index.d.ts.map +1 -0
- package/dist/agents/translator/index.js +19 -0
- package/dist/agents/translator/index.js.map +1 -0
- package/dist/agents/translator/translator.handler.d.ts +8 -0
- package/dist/agents/translator/translator.handler.d.ts.map +1 -0
- package/dist/agents/translator/translator.handler.js +81 -0
- package/dist/agents/translator/translator.handler.js.map +1 -0
- package/dist/agents/translator/translator.schema.d.ts +27 -0
- package/dist/agents/translator/translator.schema.d.ts.map +1 -0
- package/dist/agents/translator/translator.schema.js +28 -0
- package/dist/agents/translator/translator.schema.js.map +1 -0
- package/dist/agents/translator/translator.types.d.ts +41 -0
- package/dist/agents/translator/translator.types.d.ts.map +1 -0
- package/dist/agents/translator/translator.types.js +6 -0
- package/dist/agents/translator/translator.types.js.map +1 -0
- package/{src/agents/translator-agent.yaml → dist/agents/translator/translator.yaml} +27 -27
- package/dist/client/index.d.ts +89 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +93 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +17 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +7 -0
- package/dist/client/types.js.map +1 -0
- package/dist/firebase/tenantManager.d.ts +34 -2
- package/dist/firebase/tenantManager.d.ts.map +1 -1
- package/dist/firebase/tenantManager.js +67 -1
- package/dist/firebase/tenantManager.js.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -7
- package/dist/index.js.map +1 -1
- package/dist/runtime/declarativeAgentRuntime.d.ts +17 -52
- package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -1
- package/dist/runtime/declarativeAgentRuntime.js +259 -361
- package/dist/runtime/declarativeAgentRuntime.js.map +1 -1
- package/dist/runtime/index.d.ts +14 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +38 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/llmProviderFactory.d.ts +47 -0
- package/dist/runtime/llmProviderFactory.d.ts.map +1 -0
- package/dist/runtime/llmProviderFactory.js +119 -0
- package/dist/runtime/llmProviderFactory.js.map +1 -0
- package/dist/runtime/workflowExecutor.d.ts +31 -0
- package/dist/runtime/workflowExecutor.d.ts.map +1 -0
- package/dist/runtime/workflowExecutor.js +80 -0
- package/dist/runtime/workflowExecutor.js.map +1 -0
- package/dist/server/api/graphql.js +3 -3
- package/dist/server/api/graphql.js.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/shared/index.d.ts +7 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +23 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/types/agent.types.d.ts +63 -0
- package/dist/shared/types/agent.types.d.ts.map +1 -0
- package/dist/shared/types/agent.types.js +18 -0
- package/dist/shared/types/agent.types.js.map +1 -0
- package/dist/shared/types/execution.types.d.ts +42 -0
- package/dist/shared/types/execution.types.d.ts.map +1 -0
- package/dist/shared/types/execution.types.js +7 -0
- package/dist/shared/types/execution.types.js.map +1 -0
- package/dist/shared/types/index.d.ts +7 -0
- package/dist/shared/types/index.d.ts.map +1 -0
- package/dist/shared/types/index.js +23 -0
- package/dist/shared/types/index.js.map +1 -0
- package/dist/shared/types/schema.types.d.ts +52 -0
- package/dist/shared/types/schema.types.d.ts.map +1 -0
- package/dist/shared/types/schema.types.js +7 -0
- package/dist/shared/types/schema.types.js.map +1 -0
- package/dist/shared/utils/index.d.ts +5 -0
- package/dist/shared/utils/index.d.ts.map +1 -0
- package/dist/shared/utils/index.js +21 -0
- package/dist/shared/utils/index.js.map +1 -0
- package/dist/shared/utils/validation.d.ts +42 -0
- package/dist/shared/utils/validation.d.ts.map +1 -0
- package/dist/shared/utils/validation.js +93 -0
- package/dist/shared/utils/validation.js.map +1 -0
- package/dist/tenant/TenantManager.d.ts +152 -0
- package/dist/tenant/TenantManager.d.ts.map +1 -0
- package/dist/tenant/TenantManager.js +392 -0
- package/dist/tenant/TenantManager.js.map +1 -0
- package/dist/tenant/index.d.ts +47 -0
- package/dist/tenant/index.d.ts.map +1 -0
- package/dist/tenant/index.js +74 -0
- package/dist/tenant/index.js.map +1 -0
- package/dist/tenant/interfaces.d.ts +170 -0
- package/dist/tenant/interfaces.d.ts.map +1 -0
- package/dist/tenant/interfaces.js +67 -0
- package/dist/tenant/interfaces.js.map +1 -0
- package/dist/tenant/providerFactory.d.ts +43 -0
- package/dist/tenant/providerFactory.d.ts.map +1 -0
- package/dist/tenant/providerFactory.js +70 -0
- package/dist/tenant/providerFactory.js.map +1 -0
- package/dist/tenant/providerRegistry.d.ts +47 -0
- package/dist/tenant/providerRegistry.d.ts.map +1 -0
- package/dist/tenant/providerRegistry.js +79 -0
- package/dist/tenant/providerRegistry.js.map +1 -0
- package/dist/tenant/providers/FirebaseTenantProvider.d.ts +41 -0
- package/dist/tenant/providers/FirebaseTenantProvider.d.ts.map +1 -0
- package/dist/tenant/providers/FirebaseTenantProvider.js +290 -0
- package/dist/tenant/providers/FirebaseTenantProvider.js.map +1 -0
- package/dist/tenant/providers/InMemoryTenantProvider.d.ts +18 -0
- package/dist/tenant/providers/InMemoryTenantProvider.d.ts.map +1 -0
- package/dist/tenant/providers/InMemoryTenantProvider.js +137 -0
- package/dist/tenant/providers/InMemoryTenantProvider.js.map +1 -0
- package/package.json +46 -10
- package/src/agents/chat/chat.handler.ts +211 -0
- package/src/agents/chat/chat.schema.ts +33 -0
- package/src/agents/chat/chat.types.ts +46 -0
- package/src/agents/chat/chat.yaml +148 -0
- package/src/agents/chat/index.ts +21 -0
- package/src/agents/chromadb/chromadb.handler.ts +130 -0
- package/src/agents/chromadb/chromadb.schema.ts +35 -0
- package/src/agents/chromadb/chromadb.types.ts +52 -0
- package/src/agents/chromadb/chromadb.yaml +128 -0
- package/src/agents/chromadb/index.ts +20 -0
- package/src/agents/gemini-vectorize/gemini-vectorize.handler.ts +75 -0
- package/src/agents/gemini-vectorize/gemini-vectorize.schema.ts +22 -0
- package/src/agents/gemini-vectorize/gemini-vectorize.types.ts +34 -0
- package/src/agents/gemini-vectorize/gemini-vectorize.yaml +84 -0
- package/src/agents/gemini-vectorize/index.ts +20 -0
- package/src/agents/gitmcp/gitmcp.handler.ts +122 -0
- package/src/agents/gitmcp/gitmcp.schema.ts +20 -0
- package/src/agents/gitmcp/gitmcp.types.ts +33 -0
- package/src/agents/gitmcp/gitmcp.yaml +71 -0
- package/src/agents/gitmcp/index.ts +21 -0
- package/src/agents/image/image.handler.ts +86 -0
- package/src/agents/image/image.schema.ts +28 -0
- package/src/agents/image/image.types.ts +46 -0
- package/src/agents/image/image.yaml +86 -0
- package/src/agents/image/index.ts +19 -0
- package/src/agents/index.ts +63 -0
- package/src/agents/joker/index.ts +19 -0
- package/src/agents/joker/joker.handler.ts +55 -0
- package/src/agents/joker/joker.schema.ts +15 -0
- package/src/agents/joker/joker.types.ts +38 -0
- package/src/agents/joker/joker.yaml +47 -0
- package/src/agents/llm/index.ts +20 -0
- package/src/agents/llm/llm.handler.ts +82 -0
- package/src/agents/llm/llm.schema.ts +25 -0
- package/src/agents/llm/llm.types.ts +37 -0
- package/src/agents/llm/llm.yaml +87 -0
- package/src/agents/mcp-tool/index.ts +19 -0
- package/src/agents/mcp-tool/mcp-tool.handler.ts +112 -0
- package/src/agents/mcp-tool/mcp-tool.schema.ts +22 -0
- package/src/agents/mcp-tool/mcp-tool.types.ts +33 -0
- package/src/agents/mcp-tool/mcp-tool.yaml +71 -0
- package/src/agents/rag/index.ts +20 -0
- package/src/agents/rag/rag.handler.ts +95 -0
- package/src/agents/rag/rag.schema.ts +26 -0
- package/src/agents/rag/rag.types.ts +45 -0
- package/src/agents/rag/rag.yaml +89 -0
- package/src/agents/{agentRegistry.ts → registry/agentRegistry.ts} +195 -6
- package/src/agents/registry/index.ts +6 -0
- package/src/agents/translator/index.ts +19 -0
- package/src/agents/translator/translator.handler.ts +97 -0
- package/src/agents/translator/translator.schema.ts +30 -0
- package/src/agents/translator/translator.types.ts +43 -0
- package/src/agents/translator/translator.yaml +80 -0
- package/src/client/index.ts +53 -0
- package/src/client/types.ts +38 -0
- package/src/index.ts +56 -5
- package/src/runtime/declarativeAgentRuntime.ts +378 -495
- package/src/runtime/index.ts +36 -0
- package/src/runtime/llmProviderFactory.ts +145 -0
- package/src/runtime/workflowExecutor.ts +107 -0
- package/src/server/api/graphql.ts +1 -1
- package/src/server/index.ts +2 -2
- package/src/shared/index.ts +7 -0
- package/src/shared/types/agent.types.ts +100 -0
- package/src/shared/types/execution.types.ts +45 -0
- package/src/shared/types/index.ts +7 -0
- package/src/shared/types/schema.types.ts +55 -0
- package/src/shared/utils/index.ts +5 -0
- package/src/shared/utils/validation.ts +100 -0
- package/src/tenant/TenantManager.ts +488 -0
- package/src/tenant/index.ts +101 -0
- package/src/tenant/interfaces.ts +231 -0
- package/src/tenant/providerFactory.ts +75 -0
- package/src/tenant/providerRegistry.ts +86 -0
- package/src/tenant/providers/InMemoryTenantProvider.ts +168 -0
- package/dist/agents/agentRegistry.d.ts.map +0 -1
- package/dist/agents/agentRegistry.js.map +0 -1
- package/src/firebase/tenantManager.ts +0 -443
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Module - Server-only exports
|
|
3
|
+
*
|
|
4
|
+
* This module provides the declarative agent runtime and workflow execution.
|
|
5
|
+
* All exports in this module are server-only.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Main runtime exports
|
|
9
|
+
export { DeclarativeAgentInterpreter, declarativeInterpreter } from './declarativeAgentRuntime';
|
|
10
|
+
export type { YamlAgentDefinition, YamlAgentInterpreterOptions, YamlExecutionResult } from './declarativeAgentRuntime';
|
|
11
|
+
|
|
12
|
+
// Workflow executor exports
|
|
13
|
+
export {
|
|
14
|
+
executeWorkflowStep,
|
|
15
|
+
getAvailableStepTypes,
|
|
16
|
+
isStepTypeSupported,
|
|
17
|
+
// Individual handlers for direct use
|
|
18
|
+
executeJokeHandler,
|
|
19
|
+
executeTranslationHandler,
|
|
20
|
+
executeImageHandler,
|
|
21
|
+
executeMcpToolHandler,
|
|
22
|
+
executeVectorizeHandler,
|
|
23
|
+
executeChromaDBHandler,
|
|
24
|
+
executeGitMcpHandler,
|
|
25
|
+
executeRagHandler,
|
|
26
|
+
executeLlmHandler,
|
|
27
|
+
executeChatHandler,
|
|
28
|
+
} from './workflowExecutor';
|
|
29
|
+
|
|
30
|
+
// LLM Provider Factory exports
|
|
31
|
+
export { LLMProviderFactory, extractProviderConfig } from './llmProviderFactory';
|
|
32
|
+
export type { LLMProviderType, LLMProviderConfig } from './llmProviderFactory';
|
|
33
|
+
|
|
34
|
+
// Schema compiler exports
|
|
35
|
+
export { DeclarativeSchemaCompiler, DeclarativeSchemaValidationError } from './schemaCompiler';
|
|
36
|
+
export type { DeclarativeSchemaPhase } from './schemaCompiler';
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* LLM Provider Factory - Centralized provider creation and configuration
|
|
5
|
+
*
|
|
6
|
+
* Provides a single point of configuration for LLM providers, enabling:
|
|
7
|
+
* - Centralized API key validation
|
|
8
|
+
* - Easy provider switching (Google, OpenAI, Anthropic, etc.)
|
|
9
|
+
* - Retry/fallback logic between providers
|
|
10
|
+
* - Consistent error handling
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
14
|
+
import type { LanguageModel } from 'ai';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Supported LLM provider types
|
|
18
|
+
*/
|
|
19
|
+
export type LLMProviderType = 'google' | 'openai' | 'anthropic';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Provider configuration
|
|
23
|
+
*/
|
|
24
|
+
export interface LLMProviderConfig {
|
|
25
|
+
provider: LLMProviderType;
|
|
26
|
+
apiKey: string;
|
|
27
|
+
model?: string;
|
|
28
|
+
baseURL?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Default models for each provider
|
|
33
|
+
*/
|
|
34
|
+
const DEFAULT_MODELS: Record<LLMProviderType, string> = {
|
|
35
|
+
google: 'models/gemini-2.5-flash',
|
|
36
|
+
openai: 'gpt-4-turbo',
|
|
37
|
+
anthropic: 'claude-3-5-sonnet-20241022',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* LLM Provider Factory
|
|
42
|
+
*
|
|
43
|
+
* Centralizes provider creation and configuration across all agents
|
|
44
|
+
*/
|
|
45
|
+
export class LLMProviderFactory {
|
|
46
|
+
/**
|
|
47
|
+
* Create a language model instance
|
|
48
|
+
*/
|
|
49
|
+
static createLanguageModel(config: LLMProviderConfig): LanguageModel {
|
|
50
|
+
this.validateConfig(config);
|
|
51
|
+
|
|
52
|
+
switch (config.provider) {
|
|
53
|
+
case 'google':
|
|
54
|
+
return this.createGoogleProvider(config);
|
|
55
|
+
case 'openai':
|
|
56
|
+
throw new Error('OpenAI provider not yet implemented');
|
|
57
|
+
case 'anthropic':
|
|
58
|
+
throw new Error('Anthropic provider not yet implemented');
|
|
59
|
+
default:
|
|
60
|
+
throw new Error(`Unsupported provider: ${config.provider}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create Google Generative AI provider
|
|
66
|
+
*/
|
|
67
|
+
private static createGoogleProvider(config: LLMProviderConfig): LanguageModel {
|
|
68
|
+
const google = createGoogleGenerativeAI({
|
|
69
|
+
apiKey: config.apiKey,
|
|
70
|
+
...(config.baseURL && { baseURL: config.baseURL }),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const model = config.model || DEFAULT_MODELS.google;
|
|
74
|
+
return google(model);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Validate provider configuration
|
|
79
|
+
*/
|
|
80
|
+
private static validateConfig(config: LLMProviderConfig): void {
|
|
81
|
+
if (!config.apiKey?.trim()) {
|
|
82
|
+
throw new Error(`Missing API key for provider: ${config.provider}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!config.provider) {
|
|
86
|
+
throw new Error('Provider type is required');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get default model for a provider
|
|
92
|
+
*/
|
|
93
|
+
static getDefaultModel(provider: LLMProviderType): string {
|
|
94
|
+
return DEFAULT_MODELS[provider];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Validate API key format (basic check)
|
|
99
|
+
*/
|
|
100
|
+
static validateApiKey(apiKey: string, provider: LLMProviderType): boolean {
|
|
101
|
+
if (!apiKey?.trim()) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Provider-specific validation can be added here
|
|
106
|
+
switch (provider) {
|
|
107
|
+
case 'google':
|
|
108
|
+
// Google API keys typically start with 'AIza'
|
|
109
|
+
return apiKey.startsWith('AIza') || apiKey.length > 20;
|
|
110
|
+
case 'openai':
|
|
111
|
+
return apiKey.startsWith('sk-');
|
|
112
|
+
case 'anthropic':
|
|
113
|
+
return apiKey.startsWith('sk-ant-');
|
|
114
|
+
default:
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Helper function to extract provider config from props
|
|
122
|
+
*/
|
|
123
|
+
export function extractProviderConfig(
|
|
124
|
+
props: Record<string, string>,
|
|
125
|
+
defaultProvider: LLMProviderType = 'google'
|
|
126
|
+
): LLMProviderConfig {
|
|
127
|
+
const apiKey = props.gemini_api_key || props.openai_api_key || props.anthropic_api_key;
|
|
128
|
+
|
|
129
|
+
if (!apiKey) {
|
|
130
|
+
throw new Error('Missing required prop: API key (gemini_api_key, openai_api_key, or anthropic_api_key)');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Determine provider from key name
|
|
134
|
+
let provider: LLMProviderType = defaultProvider;
|
|
135
|
+
if (props.openai_api_key) provider = 'openai';
|
|
136
|
+
if (props.anthropic_api_key) provider = 'anthropic';
|
|
137
|
+
if (props.gemini_api_key) provider = 'google';
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
provider,
|
|
141
|
+
apiKey: apiKey.trim(),
|
|
142
|
+
model: props.model,
|
|
143
|
+
baseURL: props.base_url,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Workflow Executor - Server-only workflow step execution
|
|
5
|
+
* Delegates to individual agent handlers based on step type
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExecutionContext } from '../types/executionContext';
|
|
9
|
+
import type { WorkflowStepType } from '../shared/types/agent.types';
|
|
10
|
+
import { LEGACY_STEP_TYPE_MAP } from '../shared/types/agent.types';
|
|
11
|
+
|
|
12
|
+
// Import handlers from each agent
|
|
13
|
+
import { executeJokeHandler } from '../agents/joker/joker.handler';
|
|
14
|
+
import { executeTranslationHandler } from '../agents/translator/translator.handler';
|
|
15
|
+
import { executeImageHandler } from '../agents/image/image.handler';
|
|
16
|
+
import { executeMcpToolHandler } from '../agents/mcp-tool/mcp-tool.handler';
|
|
17
|
+
import { executeVectorizeHandler } from '../agents/gemini-vectorize/gemini-vectorize.handler';
|
|
18
|
+
import { executeChromaDBHandler } from '../agents/chromadb/chromadb.handler';
|
|
19
|
+
import { executeGitMcpHandler } from '../agents/gitmcp/gitmcp.handler';
|
|
20
|
+
import { executeRagHandler } from '../agents/rag/rag.handler';
|
|
21
|
+
import { executeLlmHandler } from '../agents/llm/llm.handler';
|
|
22
|
+
import { executeChatHandler } from '../agents/chat/chat.handler';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Handler function type - uses any for params to allow flexible handler signatures
|
|
26
|
+
*/
|
|
27
|
+
type HandlerFunction = (
|
|
28
|
+
params: any,
|
|
29
|
+
props: Record<string, string>,
|
|
30
|
+
context: ExecutionContext
|
|
31
|
+
) => Promise<unknown>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Map of workflow step types to their handlers
|
|
35
|
+
* Preferred step type names only - legacy names resolved via LEGACY_STEP_TYPE_MAP
|
|
36
|
+
*/
|
|
37
|
+
const handlerMap: Record<string, HandlerFunction> = {
|
|
38
|
+
'joke': executeJokeHandler,
|
|
39
|
+
'translation': executeTranslationHandler,
|
|
40
|
+
'image': executeImageHandler,
|
|
41
|
+
'mcp-tool': executeMcpToolHandler,
|
|
42
|
+
'vectorize': executeVectorizeHandler,
|
|
43
|
+
'chromadb': executeChromaDBHandler,
|
|
44
|
+
'gitmcp': executeGitMcpHandler,
|
|
45
|
+
'rag': executeRagHandler,
|
|
46
|
+
'llm': executeLlmHandler,
|
|
47
|
+
'chat': executeChatHandler,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Resolve step type, handling legacy names with deprecation warning
|
|
52
|
+
*/
|
|
53
|
+
function resolveStepType(stepType: string, context: ExecutionContext): string {
|
|
54
|
+
if (stepType in LEGACY_STEP_TYPE_MAP) {
|
|
55
|
+
const preferred = LEGACY_STEP_TYPE_MAP[stepType];
|
|
56
|
+
context.log(
|
|
57
|
+
`[DEPRECATION WARNING] Step type '${stepType}' is deprecated. Use '${preferred}' instead.`
|
|
58
|
+
);
|
|
59
|
+
return preferred;
|
|
60
|
+
}
|
|
61
|
+
return stepType;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Execute a workflow step by delegating to the appropriate handler
|
|
66
|
+
*/
|
|
67
|
+
export async function executeWorkflowStep(
|
|
68
|
+
stepType: WorkflowStepType | string,
|
|
69
|
+
params: Record<string, unknown>,
|
|
70
|
+
props: Record<string, string>,
|
|
71
|
+
context: ExecutionContext
|
|
72
|
+
): Promise<unknown> {
|
|
73
|
+
const resolvedType = resolveStepType(stepType, context);
|
|
74
|
+
const handler = handlerMap[resolvedType];
|
|
75
|
+
if (!handler) {
|
|
76
|
+
throw new Error(`Unknown workflow step type: ${stepType}`);
|
|
77
|
+
}
|
|
78
|
+
return handler(params, props, context);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get all available workflow step types
|
|
83
|
+
*/
|
|
84
|
+
export function getAvailableStepTypes(): string[] {
|
|
85
|
+
return Object.keys(handlerMap);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Check if a step type is supported (including legacy names)
|
|
90
|
+
*/
|
|
91
|
+
export function isStepTypeSupported(stepType: string): boolean {
|
|
92
|
+
return stepType in handlerMap || stepType in LEGACY_STEP_TYPE_MAP;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Export individual handlers for direct use
|
|
96
|
+
export {
|
|
97
|
+
executeJokeHandler,
|
|
98
|
+
executeTranslationHandler,
|
|
99
|
+
executeImageHandler,
|
|
100
|
+
executeMcpToolHandler,
|
|
101
|
+
executeVectorizeHandler,
|
|
102
|
+
executeChromaDBHandler,
|
|
103
|
+
executeGitMcpHandler,
|
|
104
|
+
executeRagHandler,
|
|
105
|
+
executeLlmHandler,
|
|
106
|
+
executeChatHandler,
|
|
107
|
+
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { GraphQLError, GraphQLScalarType, Kind, type ValueNode } from "graphql";
|
|
6
6
|
import { createSchema, createYoga } from "graphql-yoga";
|
|
7
|
-
import { agentRegistry } from "../../agents/
|
|
7
|
+
import { agentRegistry } from "../../agents/registry";
|
|
8
8
|
import {
|
|
9
9
|
getClientByApiKey,
|
|
10
10
|
getEndpointByName,
|
package/src/server/index.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from "./types";
|
|
|
2
2
|
export * from "./errors";
|
|
3
3
|
export * from "./kvStore";
|
|
4
4
|
export * from "./runtimeSecurity";
|
|
5
|
-
export { agentRegistry } from "../agents/
|
|
6
|
-
export type { AgentRegistration } from "../agents/
|
|
5
|
+
export { agentRegistry } from "../agents/registry";
|
|
6
|
+
export type { AgentRegistration } from "../agents/registry";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Agent Types - Safe for client and server
|
|
3
|
+
* These types contain no sensitive data and can be used in both environments
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Agent metadata - safe for client display
|
|
8
|
+
*/
|
|
9
|
+
export interface AgentMetadata {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
category: string;
|
|
14
|
+
route: string;
|
|
15
|
+
tags?: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generic agent response wrapper
|
|
20
|
+
*/
|
|
21
|
+
export interface AgentResponse<T = unknown> {
|
|
22
|
+
success: boolean;
|
|
23
|
+
data?: T;
|
|
24
|
+
error?: string;
|
|
25
|
+
timestamp?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Execution step tracking for workflow visualization
|
|
30
|
+
*/
|
|
31
|
+
export interface ExecutionStep {
|
|
32
|
+
agent: string;
|
|
33
|
+
action: string;
|
|
34
|
+
status: 'running' | 'success' | 'error';
|
|
35
|
+
startTime: number;
|
|
36
|
+
endTime?: number;
|
|
37
|
+
duration?: number;
|
|
38
|
+
input?: Record<string, unknown>;
|
|
39
|
+
output?: Record<string, unknown>;
|
|
40
|
+
error?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
phase?: 'orchestration' | 'vectorization' | 'storage' | 'retrieval' | 'ingestion' | 'generation';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Workflow step types supported by the runtime
|
|
47
|
+
*
|
|
48
|
+
* PREFERRED: Use the English step type names (joke, translation, image, vectorize)
|
|
49
|
+
*
|
|
50
|
+
* DEPRECATED: The following legacy names are supported for backward compatibility
|
|
51
|
+
* but will be removed in a future major version:
|
|
52
|
+
* - genkit-joke → use 'joke'
|
|
53
|
+
* - genkit-translation → use 'translation'
|
|
54
|
+
* - genkit-image → use 'image'
|
|
55
|
+
* - gemini-vectorize → use 'vectorize'
|
|
56
|
+
*/
|
|
57
|
+
export type WorkflowStepType =
|
|
58
|
+
// Preferred step types (use these)
|
|
59
|
+
| 'joke'
|
|
60
|
+
| 'translation'
|
|
61
|
+
| 'image'
|
|
62
|
+
| 'vectorize'
|
|
63
|
+
| 'mcp-tool'
|
|
64
|
+
| 'chromadb'
|
|
65
|
+
| 'gitmcp'
|
|
66
|
+
| 'rag'
|
|
67
|
+
| 'llm'
|
|
68
|
+
| 'chat'
|
|
69
|
+
| 'output-generator'
|
|
70
|
+
| 'builtin-agent'
|
|
71
|
+
| 'custom-action'
|
|
72
|
+
// Legacy step types (deprecated - will be removed in v1.0)
|
|
73
|
+
| 'genkit-joke'
|
|
74
|
+
| 'genkit-translation'
|
|
75
|
+
| 'genkit-image'
|
|
76
|
+
| 'gemini-vectorize';
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Maps legacy step type names to their preferred equivalents
|
|
80
|
+
* @deprecated Use preferred step type names directly
|
|
81
|
+
*/
|
|
82
|
+
export const LEGACY_STEP_TYPE_MAP: Record<string, WorkflowStepType> = {
|
|
83
|
+
'genkit-joke': 'joke',
|
|
84
|
+
'genkit-translation': 'translation',
|
|
85
|
+
'genkit-image': 'image',
|
|
86
|
+
'gemini-vectorize': 'vectorize',
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Agent categories for organization
|
|
91
|
+
*/
|
|
92
|
+
export type AgentCategory =
|
|
93
|
+
| 'utility'
|
|
94
|
+
| 'translation'
|
|
95
|
+
| 'image'
|
|
96
|
+
| 'mcp'
|
|
97
|
+
| 'vectorization'
|
|
98
|
+
| 'storage'
|
|
99
|
+
| 'retrieval'
|
|
100
|
+
| 'orchestration';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution Types - Shared between client and server
|
|
3
|
+
* Used for tracking and displaying execution progress
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Execution result from a workflow step
|
|
8
|
+
*/
|
|
9
|
+
export interface ExecutionResult<T = unknown> {
|
|
10
|
+
success: boolean;
|
|
11
|
+
data?: T;
|
|
12
|
+
error?: string;
|
|
13
|
+
duration?: number;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Workflow execution status
|
|
19
|
+
*/
|
|
20
|
+
export type ExecutionStatus = 'pending' | 'running' | 'success' | 'error' | 'cancelled';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Workflow execution summary
|
|
24
|
+
*/
|
|
25
|
+
export interface ExecutionSummary {
|
|
26
|
+
agentId: string;
|
|
27
|
+
status: ExecutionStatus;
|
|
28
|
+
startTime: number;
|
|
29
|
+
endTime?: number;
|
|
30
|
+
totalDuration?: number;
|
|
31
|
+
stepsCompleted: number;
|
|
32
|
+
totalSteps: number;
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Execution log entry
|
|
38
|
+
*/
|
|
39
|
+
export interface ExecutionLogEntry {
|
|
40
|
+
timestamp: number;
|
|
41
|
+
level: 'info' | 'warn' | 'error' | 'debug';
|
|
42
|
+
message: string;
|
|
43
|
+
step?: string;
|
|
44
|
+
metadata?: Record<string, unknown>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Types - Shared type definitions for agent schemas
|
|
3
|
+
* Used for input/output validation on both client and server
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* JSON Schema-like type definition
|
|
8
|
+
*/
|
|
9
|
+
export interface SchemaProperty {
|
|
10
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
11
|
+
description?: string;
|
|
12
|
+
enum?: string[];
|
|
13
|
+
items?: SchemaProperty;
|
|
14
|
+
properties?: Record<string, SchemaProperty>;
|
|
15
|
+
required?: string[];
|
|
16
|
+
default?: unknown;
|
|
17
|
+
minLength?: number;
|
|
18
|
+
maxLength?: number;
|
|
19
|
+
minimum?: number;
|
|
20
|
+
maximum?: number;
|
|
21
|
+
pattern?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Agent schema definition
|
|
26
|
+
*/
|
|
27
|
+
export interface AgentSchemaDefinition {
|
|
28
|
+
input: {
|
|
29
|
+
type: 'object';
|
|
30
|
+
properties: Record<string, SchemaProperty>;
|
|
31
|
+
required?: string[];
|
|
32
|
+
};
|
|
33
|
+
output: {
|
|
34
|
+
type: 'object';
|
|
35
|
+
properties: Record<string, SchemaProperty>;
|
|
36
|
+
required?: string[];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Validation result
|
|
42
|
+
*/
|
|
43
|
+
export interface ValidationResult {
|
|
44
|
+
valid: boolean;
|
|
45
|
+
errors?: ValidationError[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Validation error detail
|
|
50
|
+
*/
|
|
51
|
+
export interface ValidationError {
|
|
52
|
+
path: string;
|
|
53
|
+
message: string;
|
|
54
|
+
code: string;
|
|
55
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Utilities - Shared validation helpers
|
|
3
|
+
* Safe for use in both client and server environments
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ValidationResult, ValidationError } from '../types/schema.types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Validate that a value is a non-empty string
|
|
10
|
+
*/
|
|
11
|
+
export function isNonEmptyString(value: unknown): value is string {
|
|
12
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Validate that a value is a positive number
|
|
17
|
+
*/
|
|
18
|
+
export function isPositiveNumber(value: unknown): value is number {
|
|
19
|
+
return typeof value === 'number' && value > 0 && !isNaN(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Validate that a value is a valid URL
|
|
24
|
+
*/
|
|
25
|
+
export function isValidUrl(value: unknown): value is string {
|
|
26
|
+
if (typeof value !== 'string') return false;
|
|
27
|
+
try {
|
|
28
|
+
new URL(value);
|
|
29
|
+
return true;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Validate resolution format (e.g., "1024x1024")
|
|
37
|
+
*/
|
|
38
|
+
export function isValidResolution(value: unknown): value is string {
|
|
39
|
+
if (typeof value !== 'string') return false;
|
|
40
|
+
return /^\d+x\d+$/.test(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Validate language code (e.g., "en", "pt", "es")
|
|
45
|
+
*/
|
|
46
|
+
export function isValidLanguageCode(value: unknown): value is string {
|
|
47
|
+
if (typeof value !== 'string') return false;
|
|
48
|
+
return /^[a-z]{2}(-[A-Z]{2})?$/.test(value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Create a validation result with errors
|
|
53
|
+
*/
|
|
54
|
+
export function createValidationResult(errors: ValidationError[]): ValidationResult {
|
|
55
|
+
return {
|
|
56
|
+
valid: errors.length === 0,
|
|
57
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Create a validation error
|
|
63
|
+
*/
|
|
64
|
+
export function createValidationError(
|
|
65
|
+
path: string,
|
|
66
|
+
message: string,
|
|
67
|
+
code: string
|
|
68
|
+
): ValidationError {
|
|
69
|
+
return { path, message, code };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Sanitize string input by trimming whitespace
|
|
74
|
+
*/
|
|
75
|
+
export function sanitizeString(value: unknown): string {
|
|
76
|
+
if (typeof value !== 'string') return '';
|
|
77
|
+
return value.trim();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Validate required fields in an object
|
|
82
|
+
*/
|
|
83
|
+
export function validateRequiredFields(
|
|
84
|
+
obj: Record<string, unknown>,
|
|
85
|
+
requiredFields: string[]
|
|
86
|
+
): ValidationError[] {
|
|
87
|
+
const errors: ValidationError[] = [];
|
|
88
|
+
|
|
89
|
+
for (const field of requiredFields) {
|
|
90
|
+
if (obj[field] === undefined || obj[field] === null) {
|
|
91
|
+
errors.push(createValidationError(
|
|
92
|
+
field,
|
|
93
|
+
`Missing required field: ${field}`,
|
|
94
|
+
'REQUIRED_FIELD_MISSING'
|
|
95
|
+
));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return errors;
|
|
100
|
+
}
|