forked from bubblelabai/BubbleLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-ai-bubble-flow.ts
More file actions
71 lines (62 loc) · 1.93 KB
/
test-ai-bubble-flow.ts
File metadata and controls
71 lines (62 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Test the API with AIAgentBubble
const API_URL = 'http://localhost:3001';
async function testAIBubbleFlow() {
console.log('Testing BubbleFlow with AIAgentBubble...\n');
// 1. Create a BubbleFlow that uses AIAgentBubble
const createResponse = await fetch(`${API_URL}/bubble-flow`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: 'AI Agent Test Flow',
description: 'A flow that uses AIAgentBubble',
code: `
import type { BubbleTriggerEventRegistry } from '@bubblelab/bubble-core';
import { BubbleFlow } from '@bubblelab/bubble-core';
// Import all services
import * as bubbles from '@bubblelab/bubble-core';
export interface Output {
message: string;
}
export class TestBubbleFlow extends BubbleFlow<'webhook/http'> {
constructor() {
super('test-flow', 'A flow that handles webhook events');
}
async handle(
payload: BubbleTriggerEventRegistry['webhook/http']
): Promise<Output> {
const result = await new bubbles.AIAgentBubble({
message: 'Hello, how are you?',
model: {
model: 'google/gemini-2.5-flash',
},
}).action();
return {
message: \`Response from \${payload.path}: \${result.data?.response ?? 'No response'}\`,
};
}
}
`,
eventType: 'webhook/http',
}),
});
const createResult = await createResponse.json();
console.log('Create response:', createResult);
if (!createResponse.ok) {
console.error('Failed to create flow');
return;
}
// 2. Execute the BubbleFlow
const executeResponse = await fetch(
`${API_URL}/execute-bubble-flow/${createResult.id}`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
payload: { path: '/test-ai' },
}),
}
);
const executeResult = await executeResponse.json();
console.log('\nExecute response:', executeResult);
}
testAIBubbleFlow().catch(console.error);