beddel 0.2.1 → 0.2.3
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 +20 -0
- package/README.md +132 -21
- 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 +143 -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 +150 -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 +58 -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 +66 -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 +42 -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 +95 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +76 -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 +48 -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 +35 -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/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 +8 -0
- package/dist/agents/rag/rag.handler.d.ts.map +1 -0
- package/dist/agents/rag/rag.handler.js +101 -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 +47 -0
- package/dist/agents/rag/rag.types.d.ts.map +1 -0
- package/dist/agents/rag/rag.types.js +6 -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} +25 -1
- package/dist/agents/registry/agentRegistry.d.ts.map +1 -0
- package/dist/agents/{agentRegistry.js → registry/agentRegistry.js} +154 -4
- 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 +83 -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 +40 -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 +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/dist/runtime/declarativeAgentRuntime.d.ts +14 -49
- package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -1
- package/dist/runtime/declarativeAgentRuntime.js +248 -355
- package/dist/runtime/declarativeAgentRuntime.js.map +1 -1
- package/dist/runtime/index.d.ts +12 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +33 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/workflowExecutor.d.ts +30 -0
- package/dist/runtime/workflowExecutor.d.ts.map +1 -0
- package/dist/runtime/workflowExecutor.js +70 -0
- package/dist/runtime/workflowExecutor.js.map +1 -0
- package/dist/server/api/graphql.d.ts +1 -1
- package/dist/server/api/graphql.d.ts.map +1 -1
- package/dist/server/api/graphql.js +104 -62
- 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 +50 -0
- package/dist/shared/types/agent.types.d.ts.map +1 -0
- package/dist/shared/types/agent.types.js +7 -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 +48 -12
- package/src/agents/chat/chat.handler.ts +209 -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 +150 -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 +72 -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 +82 -0
- package/src/agents/image/image.schema.ts +28 -0
- package/src/agents/image/image.types.ts +45 -0
- package/src/agents/image/image.yaml +86 -0
- package/src/agents/image/index.ts +19 -0
- package/src/agents/index.ts +59 -0
- package/src/agents/joker/index.ts +19 -0
- package/src/agents/joker/joker.handler.ts +60 -0
- package/src/agents/joker/joker.schema.ts +15 -0
- package/src/agents/joker/joker.types.ts +37 -0
- package/src/agents/joker/joker.yaml +47 -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 +119 -0
- package/src/agents/rag/rag.schema.ts +26 -0
- package/src/agents/rag/rag.types.ts +51 -0
- package/src/agents/rag/rag.yaml +89 -0
- package/src/agents/{agentRegistry.ts → registry/agentRegistry.ts} +161 -5
- package/src/agents/registry/index.ts +6 -0
- package/src/agents/translator/index.ts +19 -0
- package/src/agents/translator/translator.handler.ts +99 -0
- package/src/agents/translator/translator.schema.ts +30 -0
- package/src/agents/translator/translator.types.ts +42 -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 +48 -5
- package/src/runtime/declarativeAgentRuntime.ts +367 -489
- package/src/runtime/index.ts +31 -0
- package/src/runtime/workflowExecutor.ts +94 -0
- package/src/server/api/graphql.ts +109 -74
- package/src/server/index.ts +2 -2
- package/src/shared/index.ts +7 -0
- package/src/shared/types/agent.types.ts +80 -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,82 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Image Agent Handler - Server-only execution logic
|
|
5
|
+
* Generates images using Gemini Flash with curated styles
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { experimental_generateImage } from 'ai';
|
|
9
|
+
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
10
|
+
import type { ExecutionContext } from '../../types/executionContext';
|
|
11
|
+
import type { ImageHandlerParams, ImageHandlerResult } from './image.types';
|
|
12
|
+
|
|
13
|
+
const GEMINI_IMAGE_MODEL = 'imagen-4.0-fast-generate-001';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Execute image generation using Gemini
|
|
17
|
+
*/
|
|
18
|
+
export async function executeImageHandler(
|
|
19
|
+
params: ImageHandlerParams,
|
|
20
|
+
props: Record<string, string>,
|
|
21
|
+
context: ExecutionContext
|
|
22
|
+
): Promise<ImageHandlerResult> {
|
|
23
|
+
const apiKey = props?.gemini_api_key?.trim();
|
|
24
|
+
if (!apiKey) {
|
|
25
|
+
throw new Error('Missing required prop: gemini_api_key');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const description = params.description?.trim();
|
|
29
|
+
const style = params.style?.trim();
|
|
30
|
+
const resolution = params.resolution?.trim();
|
|
31
|
+
|
|
32
|
+
if (!description) {
|
|
33
|
+
throw new Error('Missing required image input: description');
|
|
34
|
+
}
|
|
35
|
+
if (!style) {
|
|
36
|
+
throw new Error('Missing required image input: style');
|
|
37
|
+
}
|
|
38
|
+
if (!resolution || !/^\d+x\d+$/.test(resolution)) {
|
|
39
|
+
throw new Error('Missing required image input: resolution (format: WIDTHxHEIGHT)');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const promptTemplate = params.promptTemplate?.trim() ||
|
|
43
|
+
'Create a detailed image in {{style}} style focusing on: {{description}}';
|
|
44
|
+
|
|
45
|
+
const prompt = promptTemplate
|
|
46
|
+
.replace(/{{description}}/g, description)
|
|
47
|
+
.replace(/{{style}}/g, style)
|
|
48
|
+
.trim();
|
|
49
|
+
|
|
50
|
+
const google = createGoogleGenerativeAI({ apiKey });
|
|
51
|
+
const model = google.image(GEMINI_IMAGE_MODEL);
|
|
52
|
+
const startTime = Date.now();
|
|
53
|
+
|
|
54
|
+
context.log(`[Image] Generating image with style=${style}, resolution=${resolution}`);
|
|
55
|
+
|
|
56
|
+
const result = await experimental_generateImage({
|
|
57
|
+
model,
|
|
58
|
+
prompt,
|
|
59
|
+
size: resolution as `${number}x${number}`,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const image = result.image;
|
|
63
|
+
if (!image?.base64 || !image.mediaType) {
|
|
64
|
+
throw new Error('Gemini Flash image helper returned an invalid file');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const normalizedBase64 = image.base64.replace(/\s+/g, '');
|
|
68
|
+
const imageUrl = `data:${image.mediaType};base64,${normalizedBase64}`;
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
image_url: imageUrl,
|
|
72
|
+
image_base64: normalizedBase64,
|
|
73
|
+
media_type: image.mediaType,
|
|
74
|
+
prompt_used: prompt,
|
|
75
|
+
metadata: {
|
|
76
|
+
model_used: GEMINI_IMAGE_MODEL,
|
|
77
|
+
processing_time: Date.now() - startTime,
|
|
78
|
+
style,
|
|
79
|
+
resolution,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Agent Schema - Zod validation schemas
|
|
3
|
+
* Safe for both client and server
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
export const ImageInputSchema = z.object({
|
|
9
|
+
description: z.string().min(5).max(500),
|
|
10
|
+
style: z.enum(['watercolor', 'neon', 'sketch']),
|
|
11
|
+
resolution: z.string().regex(/^[0-9]{3,4}x[0-9]{3,4}$/),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const ImageOutputSchema = z.object({
|
|
15
|
+
image_url: z.string(),
|
|
16
|
+
image_base64: z.string().optional(),
|
|
17
|
+
media_type: z.string().optional(),
|
|
18
|
+
prompt_used: z.string(),
|
|
19
|
+
metadata: z.object({
|
|
20
|
+
model_used: z.string(),
|
|
21
|
+
processing_time: z.number(),
|
|
22
|
+
style: z.string(),
|
|
23
|
+
resolution: z.string(),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export type ImageInput = z.infer<typeof ImageInputSchema>;
|
|
28
|
+
export type ImageOutput = z.infer<typeof ImageOutputSchema>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Agent Types - Shared between client and server
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Supported image styles
|
|
7
|
+
*/
|
|
8
|
+
export type ImageStyle = 'watercolor' | 'neon' | 'sketch' | string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for image generation
|
|
12
|
+
*/
|
|
13
|
+
export interface ImageHandlerParams {
|
|
14
|
+
description: string;
|
|
15
|
+
style: ImageStyle;
|
|
16
|
+
resolution: string;
|
|
17
|
+
promptTemplate?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Result from image generation
|
|
22
|
+
*/
|
|
23
|
+
export interface ImageHandlerResult {
|
|
24
|
+
image_url: string;
|
|
25
|
+
image_base64: string;
|
|
26
|
+
media_type: string;
|
|
27
|
+
prompt_used: string;
|
|
28
|
+
metadata: {
|
|
29
|
+
model_used: string;
|
|
30
|
+
processing_time: number;
|
|
31
|
+
style: string;
|
|
32
|
+
resolution: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Image agent metadata
|
|
38
|
+
*/
|
|
39
|
+
export interface ImageMetadata {
|
|
40
|
+
id: 'image';
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
category: 'creative';
|
|
44
|
+
route: '/agents/image';
|
|
45
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Image Generator Agent - Declarative Genkit workflow
|
|
2
|
+
# Route: /agents/image
|
|
3
|
+
# Method: image.generate
|
|
4
|
+
|
|
5
|
+
agent:
|
|
6
|
+
id: image
|
|
7
|
+
version: 1.0.0
|
|
8
|
+
protocol: beddel-declarative-protocol/v2.0
|
|
9
|
+
|
|
10
|
+
metadata:
|
|
11
|
+
name: "Image Generator Agent"
|
|
12
|
+
description: "Generates images using Gemini Flash with curated styles"
|
|
13
|
+
category: "creative"
|
|
14
|
+
route: "/agents/image"
|
|
15
|
+
|
|
16
|
+
schema:
|
|
17
|
+
input:
|
|
18
|
+
type: "object"
|
|
19
|
+
properties:
|
|
20
|
+
description:
|
|
21
|
+
type: "string"
|
|
22
|
+
minLength: 5
|
|
23
|
+
maxLength: 500
|
|
24
|
+
description: "Detailed textual description of the scene"
|
|
25
|
+
style:
|
|
26
|
+
type: "string"
|
|
27
|
+
enum: ["watercolor", "neon", "sketch"]
|
|
28
|
+
description: "Desired visual style"
|
|
29
|
+
resolution:
|
|
30
|
+
type: "string"
|
|
31
|
+
pattern: "^[0-9]{3,4}x[0-9]{3,4}$"
|
|
32
|
+
description: "Resolution in WIDTHxHEIGHT format (e.g., 1024x1024)"
|
|
33
|
+
required: ["description", "style", "resolution"]
|
|
34
|
+
|
|
35
|
+
output:
|
|
36
|
+
type: "object"
|
|
37
|
+
properties:
|
|
38
|
+
image_url:
|
|
39
|
+
type: "string"
|
|
40
|
+
image_base64:
|
|
41
|
+
type: "string"
|
|
42
|
+
media_type:
|
|
43
|
+
type: "string"
|
|
44
|
+
prompt_used:
|
|
45
|
+
type: "string"
|
|
46
|
+
metadata:
|
|
47
|
+
type: "object"
|
|
48
|
+
properties:
|
|
49
|
+
model_used:
|
|
50
|
+
type: "string"
|
|
51
|
+
processing_time:
|
|
52
|
+
type: "number"
|
|
53
|
+
style:
|
|
54
|
+
type: "string"
|
|
55
|
+
resolution:
|
|
56
|
+
type: "string"
|
|
57
|
+
required: ["model_used", "processing_time", "style", "resolution"]
|
|
58
|
+
required: ["image_url", "prompt_used", "metadata"]
|
|
59
|
+
|
|
60
|
+
logic:
|
|
61
|
+
workflow:
|
|
62
|
+
- name: "generate-image"
|
|
63
|
+
type: "genkit-image"
|
|
64
|
+
action:
|
|
65
|
+
type: "image"
|
|
66
|
+
result: "imageResult"
|
|
67
|
+
promptTemplate: "Create an image in {{style}} style focusing on: {{description}}"
|
|
68
|
+
|
|
69
|
+
- name: "deliver-image"
|
|
70
|
+
type: "output-generator"
|
|
71
|
+
action:
|
|
72
|
+
type: "generate"
|
|
73
|
+
output:
|
|
74
|
+
image_url: "$imageResult.image_url"
|
|
75
|
+
image_base64: "$imageResult.image_base64"
|
|
76
|
+
media_type: "$imageResult.media_type"
|
|
77
|
+
prompt_used: "$imageResult.prompt_used"
|
|
78
|
+
metadata: "$imageResult.metadata"
|
|
79
|
+
|
|
80
|
+
output:
|
|
81
|
+
schema:
|
|
82
|
+
image_url: "$imageResult.image_url"
|
|
83
|
+
image_base64: "$imageResult.image_base64"
|
|
84
|
+
media_type: "$imageResult.media_type"
|
|
85
|
+
prompt_used: "$imageResult.prompt_used"
|
|
86
|
+
metadata: "$imageResult.metadata"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Agent - Public exports (client-safe)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Schema exports (client-safe)
|
|
6
|
+
export { ImageInputSchema, ImageOutputSchema } from './image.schema';
|
|
7
|
+
export type { ImageInput, ImageOutput } from './image.schema';
|
|
8
|
+
|
|
9
|
+
// Type exports (client-safe)
|
|
10
|
+
export type { ImageStyle, ImageHandlerParams, ImageHandlerResult, ImageMetadata } from './image.types';
|
|
11
|
+
|
|
12
|
+
// Metadata (client-safe)
|
|
13
|
+
export const imageMetadata = {
|
|
14
|
+
id: 'image',
|
|
15
|
+
name: 'Image Generator Agent',
|
|
16
|
+
description: 'Generates images using Gemini Flash with curated styles',
|
|
17
|
+
category: 'creative',
|
|
18
|
+
route: '/agents/image',
|
|
19
|
+
} as const;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents Module - Public exports
|
|
3
|
+
*
|
|
4
|
+
* This module provides the agent registry and agent metadata.
|
|
5
|
+
* Handler implementations are server-only and should be imported directly
|
|
6
|
+
* from their respective agent folders when needed.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Registry exports
|
|
10
|
+
export { AgentRegistry, agentRegistry } from './registry';
|
|
11
|
+
export type { AgentRegistration } from './registry';
|
|
12
|
+
|
|
13
|
+
// Agent metadata exports (client-safe)
|
|
14
|
+
export { jokerMetadata } from './joker';
|
|
15
|
+
export { translatorMetadata } from './translator';
|
|
16
|
+
export { imageMetadata } from './image';
|
|
17
|
+
export { mcpToolMetadata } from './mcp-tool';
|
|
18
|
+
export { geminiVectorizeMetadata } from './gemini-vectorize';
|
|
19
|
+
export { chromadbMetadata } from './chromadb';
|
|
20
|
+
export { gitmcpMetadata } from './gitmcp';
|
|
21
|
+
export { ragMetadata } from './rag';
|
|
22
|
+
export { chatMetadata } from './chat';
|
|
23
|
+
|
|
24
|
+
// Schema exports (client-safe)
|
|
25
|
+
export { JokerInputSchema, JokerOutputSchema } from './joker';
|
|
26
|
+
export { TranslatorInputSchema, TranslatorOutputSchema } from './translator';
|
|
27
|
+
export { ImageInputSchema, ImageOutputSchema } from './image';
|
|
28
|
+
export { McpToolInputSchema, McpToolOutputSchema } from './mcp-tool';
|
|
29
|
+
export { GeminiVectorizeInputSchema, GeminiVectorizeOutputSchema } from './gemini-vectorize';
|
|
30
|
+
export { ChromaDBInputSchema, ChromaDBOutputSchema } from './chromadb';
|
|
31
|
+
export { GitMcpInputSchema, GitMcpOutputSchema } from './gitmcp';
|
|
32
|
+
export { RagInputSchema, RagOutputSchema } from './rag';
|
|
33
|
+
export { ChatInputSchema, ChatOutputSchema } from './chat';
|
|
34
|
+
|
|
35
|
+
// Type exports (client-safe)
|
|
36
|
+
export type { JokerInput, JokerOutput, JokeHandlerParams, JokeHandlerResult } from './joker';
|
|
37
|
+
export type { TranslatorInput, TranslatorOutput, TranslationHandlerParams, TranslationHandlerResult } from './translator';
|
|
38
|
+
export type { ImageInput, ImageOutput, ImageStyle, ImageHandlerParams, ImageHandlerResult } from './image';
|
|
39
|
+
export type { McpToolInput, McpToolOutput, McpToolHandlerParams, McpToolHandlerResult } from './mcp-tool';
|
|
40
|
+
export type { GeminiVectorizeInput, GeminiVectorizeOutput, VectorizeHandlerParams, VectorizeHandlerResult } from './gemini-vectorize';
|
|
41
|
+
export type { ChromaDBInput, ChromaDBOutput, ChromaDBHandlerParams, ChromaDBHandlerResult, ChromaDBSearchResult } from './chromadb';
|
|
42
|
+
export type { GitMcpInput, GitMcpOutput, GitMcpHandlerParams, GitMcpHandlerResult } from './gitmcp';
|
|
43
|
+
export type { RagInput, RagOutput, RagHandlerParams, RagHandlerResult, ConversationMessage } from './rag';
|
|
44
|
+
export type { ChatInput, ChatOutput, ChatHandlerParams, ChatHandlerResult } from './chat';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* All agent metadata for UI display
|
|
48
|
+
*/
|
|
49
|
+
export const allAgentMetadata = [
|
|
50
|
+
{ id: 'joker', name: 'Joker Agent', description: 'Tells jokes using Gemini Flash', category: 'utility', route: '/agents/joker' },
|
|
51
|
+
{ id: 'translator', name: 'Translator Agent', description: 'Translates text between languages using Gemini Flash via Genkit', category: 'translation', route: '/agents/translator' },
|
|
52
|
+
{ id: 'image', name: 'Image Generator Agent', description: 'Generates images using Gemini Flash with curated styles', category: 'creative', route: '/agents/image' },
|
|
53
|
+
{ id: 'mcp-tool', name: 'MCP Tool Agent', description: 'Generic agent for calling MCP server tools via SSE transport', category: 'integration', route: '/agents/mcp-tool' },
|
|
54
|
+
{ id: 'gemini-vectorize', name: 'Gemini Vectorize Agent', description: "Generates text embeddings using Google's Gemini text-embedding-004 model", category: 'ai-service', route: '/agents/gemini-vectorize' },
|
|
55
|
+
{ id: 'chromadb', name: 'ChromaDB Agent', description: 'Vector storage and retrieval using ChromaDB. Supports local and cloud deployments.', category: 'database', route: '/agents/chromadb' },
|
|
56
|
+
{ id: 'gitmcp', name: 'GitMCP Documentation Agent', description: 'Fetches and chunks GitHub repository documentation via gitmcp.io MCP servers', category: 'integration', route: '/agents/gitmcp' },
|
|
57
|
+
{ id: 'rag', name: 'RAG Intelligence Agent', description: 'Generates natural language answers based on provided context using Gemini', category: 'intelligence', route: '/agents/rag' },
|
|
58
|
+
{ id: 'chat', name: 'Q&A Context Chat Agent', description: 'Orchestrates RAG pipeline: vectorization, storage, retrieval and answer generation', category: 'chat', route: '/agents/chat' },
|
|
59
|
+
] as const;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joker Agent - Public exports (client-safe)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Schema exports (client-safe)
|
|
6
|
+
export { JokerInputSchema, JokerOutputSchema } from './joker.schema';
|
|
7
|
+
export type { JokerInput, JokerOutput } from './joker.schema';
|
|
8
|
+
|
|
9
|
+
// Type exports (client-safe)
|
|
10
|
+
export type { JokeHandlerParams, JokeHandlerResult, JokerMetadata } from './joker.types';
|
|
11
|
+
|
|
12
|
+
// Metadata (client-safe)
|
|
13
|
+
export const jokerMetadata = {
|
|
14
|
+
id: 'joker',
|
|
15
|
+
name: 'Joker Agent',
|
|
16
|
+
description: 'Tells jokes using Gemini Flash',
|
|
17
|
+
category: 'utility',
|
|
18
|
+
route: '/agents/joker',
|
|
19
|
+
} as const;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Joker Agent Handler - Server-only execution logic
|
|
5
|
+
* Generates jokes using Gemini Flash
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { generateText } from 'ai';
|
|
9
|
+
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
10
|
+
import type { ExecutionContext } from '../../types/executionContext';
|
|
11
|
+
import type { JokeHandlerParams, JokeHandlerResult } from './joker.types';
|
|
12
|
+
|
|
13
|
+
const GEMINI_MODEL = 'models/gemini-2.5-flash';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Execute joke generation using Gemini Flash
|
|
17
|
+
*/
|
|
18
|
+
export async function executeJokeHandler(
|
|
19
|
+
params: JokeHandlerParams,
|
|
20
|
+
props: Record<string, string>,
|
|
21
|
+
context: ExecutionContext
|
|
22
|
+
): Promise<JokeHandlerResult> {
|
|
23
|
+
const apiKey = props?.gemini_api_key?.trim();
|
|
24
|
+
if (!apiKey) {
|
|
25
|
+
throw new Error('Missing required prop: gemini_api_key');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const prompt = params.prompt?.trim() || 'Tell a short and original joke that works for any audience.';
|
|
29
|
+
const temperature = params.temperature ?? 0.8;
|
|
30
|
+
const maxTokens = params.maxTokens;
|
|
31
|
+
|
|
32
|
+
const google = createGoogleGenerativeAI({ apiKey });
|
|
33
|
+
const model = google(GEMINI_MODEL);
|
|
34
|
+
const startTime = Date.now();
|
|
35
|
+
|
|
36
|
+
context.log(`[Joker] Generating joke with temperature=${temperature}`);
|
|
37
|
+
|
|
38
|
+
const { text } = await generateText({
|
|
39
|
+
model,
|
|
40
|
+
prompt,
|
|
41
|
+
temperature,
|
|
42
|
+
...(maxTokens && { maxOutputTokens: maxTokens }),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const finalText = text?.trim() || '';
|
|
46
|
+
if (!finalText) {
|
|
47
|
+
throw new Error('Gemini returned empty response');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
text: finalText,
|
|
52
|
+
metadata: {
|
|
53
|
+
model_used: GEMINI_MODEL,
|
|
54
|
+
processing_time: Date.now() - startTime,
|
|
55
|
+
temperature,
|
|
56
|
+
max_tokens: maxTokens ?? null,
|
|
57
|
+
prompt_used: prompt,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joker Agent Schema - Zod validation schemas
|
|
3
|
+
* Safe for both client and server
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
export const JokerInputSchema = z.object({}).optional();
|
|
9
|
+
|
|
10
|
+
export const JokerOutputSchema = z.object({
|
|
11
|
+
response: z.string(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type JokerInput = z.infer<typeof JokerInputSchema>;
|
|
15
|
+
export type JokerOutput = z.infer<typeof JokerOutputSchema>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joker Agent Types - Shared between client and server
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parameters for joke generation
|
|
7
|
+
*/
|
|
8
|
+
export interface JokeHandlerParams {
|
|
9
|
+
prompt?: string;
|
|
10
|
+
temperature?: number;
|
|
11
|
+
maxTokens?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Result from joke generation
|
|
16
|
+
*/
|
|
17
|
+
export interface JokeHandlerResult {
|
|
18
|
+
text: string;
|
|
19
|
+
metadata: {
|
|
20
|
+
model_used: string;
|
|
21
|
+
processing_time: number;
|
|
22
|
+
temperature: number;
|
|
23
|
+
max_tokens: number | null;
|
|
24
|
+
prompt_used: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Joker agent metadata
|
|
30
|
+
*/
|
|
31
|
+
export interface JokerMetadata {
|
|
32
|
+
id: 'joker';
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
category: 'utility';
|
|
36
|
+
route: '/agents/joker';
|
|
37
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Joker Agent - Simple Response Agent for Beddel Runtime
|
|
2
|
+
# Route: /agents/joker
|
|
3
|
+
# Method: joker.execute
|
|
4
|
+
|
|
5
|
+
agent:
|
|
6
|
+
id: joker
|
|
7
|
+
version: 1.0.0
|
|
8
|
+
protocol: beddel-declarative-protocol/v2.0
|
|
9
|
+
|
|
10
|
+
metadata:
|
|
11
|
+
name: "Joker Agent"
|
|
12
|
+
description: "Tells jokes using Gemini Flash"
|
|
13
|
+
category: "utility"
|
|
14
|
+
route: "/agents/joker"
|
|
15
|
+
|
|
16
|
+
schema:
|
|
17
|
+
input:
|
|
18
|
+
type: "object"
|
|
19
|
+
properties: {}
|
|
20
|
+
required: []
|
|
21
|
+
|
|
22
|
+
output:
|
|
23
|
+
type: "object"
|
|
24
|
+
properties:
|
|
25
|
+
response:
|
|
26
|
+
type: "string"
|
|
27
|
+
required: ["response"]
|
|
28
|
+
|
|
29
|
+
logic:
|
|
30
|
+
workflow:
|
|
31
|
+
- name: "generate-joke"
|
|
32
|
+
type: "genkit-joke"
|
|
33
|
+
action:
|
|
34
|
+
type: "joke"
|
|
35
|
+
prompt: "Tell a short and original joke that works for any audience."
|
|
36
|
+
result: "jokerResult"
|
|
37
|
+
|
|
38
|
+
- name: "deliver-response"
|
|
39
|
+
type: "output-generator"
|
|
40
|
+
action:
|
|
41
|
+
type: "generate"
|
|
42
|
+
output:
|
|
43
|
+
response: "$jokerResult.text"
|
|
44
|
+
|
|
45
|
+
output:
|
|
46
|
+
schema:
|
|
47
|
+
response: "$jokerResult.text"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Agent - Public exports (client-safe)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Schema exports (client-safe)
|
|
6
|
+
export { McpToolInputSchema, McpToolOutputSchema } from './mcp-tool.schema';
|
|
7
|
+
export type { McpToolInput, McpToolOutput } from './mcp-tool.schema';
|
|
8
|
+
|
|
9
|
+
// Type exports (client-safe)
|
|
10
|
+
export type { McpToolHandlerParams, McpToolHandlerResult, McpToolMetadata } from './mcp-tool.types';
|
|
11
|
+
|
|
12
|
+
// Metadata (client-safe)
|
|
13
|
+
export const mcpToolMetadata = {
|
|
14
|
+
id: 'mcp-tool',
|
|
15
|
+
name: 'MCP Tool Agent',
|
|
16
|
+
description: 'Generic agent for calling MCP server tools via SSE transport',
|
|
17
|
+
category: 'integration',
|
|
18
|
+
route: '/agents/mcp-tool',
|
|
19
|
+
} as const;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MCP Tool Agent Handler - Server-only execution logic
|
|
5
|
+
* Generic agent for calling MCP server tools via SSE transport
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExecutionContext } from '../../types/executionContext';
|
|
9
|
+
import type { McpToolHandlerParams, McpToolHandlerResult } from './mcp-tool.types';
|
|
10
|
+
|
|
11
|
+
// MCP imports (lazy loaded to avoid issues if not installed)
|
|
12
|
+
let mcpClient: any = null;
|
|
13
|
+
let mcpSSETransport: any = null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Execute MCP tool invocation
|
|
17
|
+
*/
|
|
18
|
+
export async function executeMcpToolHandler(
|
|
19
|
+
params: McpToolHandlerParams,
|
|
20
|
+
_props: Record<string, string>,
|
|
21
|
+
context: ExecutionContext
|
|
22
|
+
): Promise<McpToolHandlerResult> {
|
|
23
|
+
const serverUrl = params.server_url;
|
|
24
|
+
const toolName = params.tool_name;
|
|
25
|
+
const toolArguments = params.tool_arguments || {};
|
|
26
|
+
|
|
27
|
+
if (!serverUrl) {
|
|
28
|
+
throw new Error('Missing required MCP input: server_url');
|
|
29
|
+
}
|
|
30
|
+
if (!toolName) {
|
|
31
|
+
throw new Error('Missing required MCP input: tool_name');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
context.log(`[MCP Tool] Connecting to ${serverUrl}...`);
|
|
35
|
+
context.log(`[MCP Tool] Tool: ${toolName}`);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// Lazy load MCP SDK
|
|
39
|
+
if (!mcpClient) {
|
|
40
|
+
const { Client } = await import('@modelcontextprotocol/sdk/client/index.js');
|
|
41
|
+
const { SSEClientTransport } = await import('@modelcontextprotocol/sdk/client/sse.js');
|
|
42
|
+
mcpClient = Client;
|
|
43
|
+
mcpSSETransport = SSEClientTransport;
|
|
44
|
+
|
|
45
|
+
// Setup EventSource for Node.js
|
|
46
|
+
const eventsourceModule = await import('eventsource');
|
|
47
|
+
const EventSourceClass = eventsourceModule.default || eventsourceModule;
|
|
48
|
+
if (!(global as any).EventSource) {
|
|
49
|
+
(global as any).EventSource = EventSourceClass;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const transport = new mcpSSETransport(new URL(serverUrl));
|
|
54
|
+
const client = new mcpClient(
|
|
55
|
+
{ name: 'beddel-mcp-client', version: '1.0.0' },
|
|
56
|
+
{ capabilities: {} }
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
await client.connect(transport);
|
|
60
|
+
context.log('[MCP Tool] Connected!');
|
|
61
|
+
|
|
62
|
+
// List available tools
|
|
63
|
+
const tools = await client.listTools();
|
|
64
|
+
const availableToolNames = tools.tools.map((t: any) => t.name);
|
|
65
|
+
context.log(`[MCP Tool] Available tools: ${availableToolNames.join(', ')}`);
|
|
66
|
+
|
|
67
|
+
// Handle list_tools special case
|
|
68
|
+
if (toolName === 'list_tools') {
|
|
69
|
+
await client.close();
|
|
70
|
+
return {
|
|
71
|
+
success: true,
|
|
72
|
+
data: JSON.stringify(tools.tools),
|
|
73
|
+
tool_names: availableToolNames,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Validate tool exists
|
|
78
|
+
if (!availableToolNames.includes(toolName)) {
|
|
79
|
+
await client.close();
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
error: `Tool '${toolName}' not found. Available tools: ${availableToolNames.join(', ')}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Call the tool with timeout
|
|
87
|
+
const timeoutPromise = new Promise((_, reject) =>
|
|
88
|
+
setTimeout(() => reject(new Error('MCP Tool Timeout (30s)')), 30000)
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const callPromise = client.callTool({
|
|
92
|
+
name: toolName,
|
|
93
|
+
arguments: toolArguments,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const callResult: any = await Promise.race([callPromise, timeoutPromise]);
|
|
97
|
+
await client.close();
|
|
98
|
+
|
|
99
|
+
// Parse result content
|
|
100
|
+
const textContent = callResult.content
|
|
101
|
+
.filter((c: any) => c.type === 'text')
|
|
102
|
+
.map((c: any) => c.text)
|
|
103
|
+
.join('\n') || 'No text content returned';
|
|
104
|
+
|
|
105
|
+
return { success: true, data: textContent };
|
|
106
|
+
|
|
107
|
+
} catch (error: unknown) {
|
|
108
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
109
|
+
context.log(`[MCP Tool] Error: ${message}`);
|
|
110
|
+
return { success: false, error: message };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Agent Schema - Zod validation schemas
|
|
3
|
+
* Safe for both client and server
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
export const McpToolInputSchema = z.object({
|
|
9
|
+
server_url: z.string().url(),
|
|
10
|
+
tool_name: z.string().min(1),
|
|
11
|
+
tool_arguments: z.record(z.string(), z.unknown()).optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const McpToolOutputSchema = z.object({
|
|
15
|
+
success: z.boolean(),
|
|
16
|
+
data: z.string().optional(),
|
|
17
|
+
tool_names: z.array(z.string()).optional(),
|
|
18
|
+
error: z.string().optional(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type McpToolInput = z.infer<typeof McpToolInputSchema>;
|
|
22
|
+
export type McpToolOutput = z.infer<typeof McpToolOutputSchema>;
|