-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest-local.js
More file actions
116 lines (98 loc) · 3.83 KB
/
test-local.js
File metadata and controls
116 lines (98 loc) · 3.83 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { Lamatic } from "./dist/index.js";
// Configuration - Replace with your actual values
const config = {
endpoint: "your-endpoint-url", // e.g., "https://api.lamatic.ai/graphql"
projectId: "your-project-id",
apiKey: "your-api-key", // or use accessToken instead
// accessToken: "your-access-token" // alternative to apiKey
};
async function testSDK() {
console.log("🚀 Starting Lamatic SDK Local Tests\n");
// Initialize the SDK
let lamatic;
try {
lamatic = new Lamatic(config);
console.log("✅ SDK initialized successfully");
console.log(` Endpoint: ${lamatic.endpoint}`);
console.log(` Project ID: ${lamatic.projectId}`);
console.log(` Auth Method: ${lamatic.apiKey ? 'API Key' : 'Access Token'}\n`);
} catch (error) {
console.error("❌ Failed to initialize SDK:", error.message);
return;
}
// Test 1: Execute Flow
console.log("📋 Test 1: Execute Flow");
try {
const flowId = "your-flow-id";
const payload = {
prompt: "Hello, this is a test message for flow execution"
};
console.log(` Flow ID: ${flowId}`);
console.log(` Payload:`, payload);
const flowResponse = await lamatic.executeFlow(flowId, payload);
console.log("✅ Flow executed successfully:");
console.log(" Response:", JSON.stringify(flowResponse, null, 2));
} catch (error) {
console.error("❌ Flow execution failed:", error.message);
}
console.log("");
// Test 2: Execute Agent
console.log("🤖 Test 2: Execute Agent");
try {
const agentId = "your-agent-id";
const payload = {
query: "Generate a creative tweet about AI and automation"
};
console.log(` Agent ID: ${agentId}`);
console.log(` Payload:`, payload);
const agentResponse = await lamatic.executeAgent(agentId, payload);
console.log("✅ Agent executed successfully:");
console.log(" Response:", JSON.stringify(agentResponse, null, 2));
} catch (error) {
console.error("❌ Agent execution failed:", error.message);
}
console.log("");
// Test 3: Check Status (new function)
console.log("🔍 Test 3: Check Status");
try {
const requestId = "your-request-id";
console.log(` Request ID: ${requestId}`);
console.log(" Using default polling (15s interval, 900s timeout)");
const statusResponse = await lamatic.checkStatus(requestId);
console.log("✅ Status check completed:");
console.log(" Response:", JSON.stringify(statusResponse, null, 2));
} catch (error) {
console.error("❌ Status check failed:", error.message);
}
console.log("");
// Test 4: Check Status with Custom Polling
console.log("⏱️ Test 4: Check Status with Custom Polling");
try {
const requestId = "your-request-id";
const pollInterval = 5; // 5 seconds
const pollTimeout = 60; // 1 minute
console.log(` Request ID: ${requestId}`);
console.log(` Poll Interval: ${pollInterval}s`);
console.log(` Poll Timeout: ${pollTimeout}s`);
const customStatusResponse = await lamatic.checkStatus(requestId, pollInterval, pollTimeout);
console.log("✅ Custom status check completed:");
console.log(" Response:", JSON.stringify(customStatusResponse, null, 2));
} catch (error) {
console.error("❌ Custom status check failed:", error.message);
}
console.log("");
// Test 5: Update Access Token (if using access token auth)
console.log("🔄 Test 5: Update Access Token");
try {
const newToken = "new-access-token";
lamatic.updateAccessToken(newToken);
console.log("✅ Access token updated successfully");
console.log(` New token: ${newToken.substring(0, 10)}...`);
} catch (error) {
console.error("❌ Access token update failed:", error.message);
}
console.log("");
console.log("🏁 All tests completed!");
}
// Run the tests
testSDK().catch(console.error);