Repository navigation
Expand file tree
/
Copy pathkimi_dashclaw_test.js
More file actions
111 lines (93 loc) · 3.1 KB
/
Copy pathkimi_dashclaw_test.js
File metadata and controls
111 lines (93 loc) · 3.1 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
import { DashClaw } from '../sdk/dashclaw.js';
import dotenv from 'dotenv';
dotenv.config();
/**
* Node.js Parity for Kimi/Moonshot Example
* Demonstrates: guard -> createAction -> recordAssumption -> updateOutcome
*
* The `openai` package is loaded lazily inside main() so this file can be
* imported (e.g. for static analysis) without pulling in the SDK.
*/
const claw = new DashClaw({
baseUrl: process.env.DASHCLAW_BASE_URL || 'http://localhost:3000',
apiKey: process.env.DASHCLAW_API_KEY,
agentId: 'moonshot-email-agent',
agentName: 'Moonshot Email Agent',
});
function sendEmail(recipient, subject, body) {
console.log(`Sending email to ${recipient} with subject: ${subject}`);
return { ok: true, recipient, subject };
}
async function main() {
const userPrompt = 'Write a short follow up email to Acme asking for a meeting next week.';
const { default: OpenAI } = await import('openai');
const moonshot = new OpenAI({
apiKey: process.env.MOONSHOT_API_KEY,
baseURL: 'https://api.moonshot.ai/v1',
});
const completion = await moonshot.chat.completions.create({
model: 'kimi-k2-turbo-preview',
messages: [
{
role: 'system',
content: 'You are Kimi, an AI assistant provided by Moonshot AI.'
},
{ role: 'user', content: userPrompt },
],
temperature: 0.6,
});
const draftedEmail = completion.choices[0].message.content;
// 1. Guard check
const { decision } = await claw.guard({
action_type: 'message',
risk_score: 72,
systems_touched: ['email', 'moonshot_api'],
reversible: false,
declared_goal: 'Draft and send outbound follow up email to a prospect',
});
console.log('Guard result:', decision);
if (decision === 'block' || decision === 'require_approval') {
console.log('DashClaw stopped the action:', decision);
return;
}
// 2. Create the action
const { action } = await claw.createAction({
action_type: 'message',
declared_goal: 'Send outbound follow up email to Acme',
reasoning: 'User requested a follow up email generated by Moonshot.',
systems_touched: ['email', 'moonshot_api'],
input_summary: userPrompt,
reversible: false,
risk_score: 72,
confidence: 84,
});
const actionId = action.action_id;
console.log('Action response:', actionId);
// 3. Register Assumption
await claw.recordAssumption({
action_id: actionId,
assumption: 'The recipient is a valid business contact and outreach is authorized.',
basis: 'User initiated the request and provided the business context.',
validated: false,
});
// 4. Update Outcome
try {
const result = sendEmail(
'team@acme.com',
'Quick follow up',
draftedEmail
);
await claw.updateOutcome(actionId, {
status: 'completed',
output_summary: `Email sent successfully to ${result.recipient}`,
});
console.log('Success. Check DashClaw dashboard for the action trace:', actionId);
} catch (e) {
await claw.updateOutcome(actionId, {
status: 'failed',
output_summary: `Email send failed: ${e.message}`,
});
throw e;
}
}
main().catch(console.error);