@kalphq/cli 0.0.0-dev-20260416091527 → 0.0.0-dev-20260420023057
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/dist/add-5NOYFTJV.js +133 -0
- package/dist/add-5NOYFTJV.js.map +1 -0
- package/dist/build-SUIPVJO6.js +80 -0
- package/dist/build-SUIPVJO6.js.map +1 -0
- package/dist/chunk-6LLXGS2P.js +25 -0
- package/dist/chunk-6LLXGS2P.js.map +1 -0
- package/dist/chunk-CJCIZDCF.js +298 -0
- package/dist/chunk-CJCIZDCF.js.map +1 -0
- package/dist/{chunk-GFEVTHUW.js → chunk-HD5FT7T6.js} +98 -65
- package/dist/chunk-HD5FT7T6.js.map +1 -0
- package/dist/{create-XJURMQC4.js → create-RSQEKCI6.js} +6 -5
- package/dist/{create-XJURMQC4.js.map → create-RSQEKCI6.js.map} +1 -1
- package/dist/delete-ZJB2JGAL.js +136 -0
- package/dist/delete-ZJB2JGAL.js.map +1 -0
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/{init-K7EASUMM.js → init-CUBJEWPE.js} +3 -5
- package/dist/init-CUBJEWPE.js.map +1 -0
- package/dist/list-BOE33VSI.js +120 -0
- package/dist/list-BOE33VSI.js.map +1 -0
- package/dist/push-L3BXB6OC.js +79 -0
- package/dist/push-L3BXB6OC.js.map +1 -0
- package/dist/secrets-3SKCSAGD.js +33 -0
- package/dist/secrets-3SKCSAGD.js.map +1 -0
- package/package.json +2 -2
- package/templates/project/meta/manifest-registry.json +1 -0
- package/dist/chunk-GFEVTHUW.js.map +0 -1
- package/dist/init-K7EASUMM.js.map +0 -1
- package/dist/push-YFHHNITO.js +0 -174
- package/dist/push-YFHHNITO.js.map +0 -1
- package/templates/agents/b2b-sales/index.ts +0 -57
- package/templates/agents/b2b-sales/signals/deal-won.ts +0 -31
- package/templates/agents/b2b-sales/signals/hot-lead-alert.ts +0 -29
- package/templates/agents/b2b-sales/steps/qualify-prospect.ts +0 -50
- package/templates/agents/b2b-sales/steps/score-lead.ts +0 -24
- package/templates/agents/b2b-sales/tools/enrich-company.ts +0 -17
- package/templates/agents/b2b-sales/tools/send-slack-notification.ts +0 -26
- package/templates/agents/b2b-sales/webhooks/crm-inbound.ts +0 -27
- package/templates/agents/b2b-sales/webhooks/stripe-payment.ts +0 -27
- package/templates/agents/customer-support/index.ts +0 -60
- package/templates/agents/customer-support/signals/escalation-needed.ts +0 -28
- package/templates/agents/customer-support/signals/ticket-resolved.ts +0 -29
- package/templates/agents/customer-support/steps/classify-ticket.ts +0 -22
- package/templates/agents/customer-support/steps/escalate-ticket.ts +0 -53
- package/templates/agents/customer-support/tools/create-jira-issue.ts +0 -30
- package/templates/agents/customer-support/tools/search-kb.ts +0 -13
- package/templates/agents/customer-support/webhooks/slack-escalation.ts +0 -27
- package/templates/agents/customer-support/webhooks/zendesk-ticket.ts +0 -29
- package/templates/agents/financial-agent/index.ts +0 -50
- package/templates/agents/financial-agent/signals/market-alert.ts +0 -31
- package/templates/agents/financial-agent/signals/portfolio-rebalance.ts +0 -27
- package/templates/agents/financial-agent/steps/analyze-signal.ts +0 -26
- package/templates/agents/financial-agent/steps/rebalance-check.ts +0 -55
- package/templates/agents/financial-agent/tools/fetch-market-data.ts +0 -13
- package/templates/agents/financial-agent/tools/send-email-alert.ts +0 -31
- package/templates/agents/financial-agent/webhooks/exchange-webhook.ts +0 -33
- package/templates/agents/financial-agent/webhooks/tradingview-alert.ts +0 -30
- package/templates/agents/minimal/index.ts +0 -24
- package/templates/agents/minimal/signals/error-alert.ts +0 -26
- package/templates/agents/minimal/signals/task-complete.ts +0 -25
- package/templates/agents/minimal/steps/example-step.ts +0 -13
- package/templates/agents/minimal/steps/transform-data.ts +0 -32
- package/templates/agents/minimal/tools/example-tool.ts +0 -13
- package/templates/agents/minimal/tools/http-request.ts +0 -26
- package/templates/agents/minimal/webhooks/generic-inbound.ts +0 -25
- package/templates/agents/minimal/webhooks/health-check.ts +0 -23
- package/templates/project/agents/.gitkeep +0 -0
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { createStep } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const escalateTicket = createStep({
|
|
5
|
-
id: "escalate_ticket",
|
|
6
|
-
description: "Determines if a ticket should be escalated to human support.",
|
|
7
|
-
input: z.object({
|
|
8
|
-
category: z.string(), // "billing", "technical", "general"
|
|
9
|
-
priority: z.string(), // "low", "medium", "high"
|
|
10
|
-
sentiment: z.string(), // "frustrated", "angry", "neutral", "satisfied"
|
|
11
|
-
previousAttempts: z.number().default(0),
|
|
12
|
-
}),
|
|
13
|
-
output: z.object({
|
|
14
|
-
escalate: z.boolean(),
|
|
15
|
-
reason: z.string(),
|
|
16
|
-
assignTo: z.string(), // "tier1", "tier2", "tier3", "human"
|
|
17
|
-
}),
|
|
18
|
-
async run({ category, priority, sentiment, previousAttempts }) {
|
|
19
|
-
// Auto-escalate frustrated/angry customers with technical issues
|
|
20
|
-
if ((sentiment === "frustrated" || sentiment === "angry") && category === "technical") {
|
|
21
|
-
return {
|
|
22
|
-
escalate: true,
|
|
23
|
-
reason: "Frustrated customer with technical issue",
|
|
24
|
-
assignTo: "tier2",
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Escalate high priority billing issues immediately
|
|
29
|
-
if (priority === "high" && category === "billing") {
|
|
30
|
-
return {
|
|
31
|
-
escalate: true,
|
|
32
|
-
reason: "High priority billing issue",
|
|
33
|
-
assignTo: "tier3",
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Escalate after multiple failed attempts
|
|
38
|
-
if (previousAttempts >= 3) {
|
|
39
|
-
return {
|
|
40
|
-
escalate: true,
|
|
41
|
-
reason: `Multiple failed resolution attempts (${previousAttempts})`,
|
|
42
|
-
assignTo: "human",
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// No escalation needed
|
|
47
|
-
return {
|
|
48
|
-
escalate: false,
|
|
49
|
-
reason: "Within agent capabilities",
|
|
50
|
-
assignTo: "tier1",
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createTool } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const createJiraIssue = createTool({
|
|
5
|
-
id: "create_jira_issue",
|
|
6
|
-
description: "Creates a bug ticket in Jira for technical issues requiring engineering.",
|
|
7
|
-
input: z.object({
|
|
8
|
-
summary: z.string(),
|
|
9
|
-
description: z.string(),
|
|
10
|
-
priority: z.string(), // "Low", "Medium", "High", "Critical"
|
|
11
|
-
component: z.string().optional(),
|
|
12
|
-
reporter: z.string(),
|
|
13
|
-
}),
|
|
14
|
-
async execute({ summary, description, priority, component, reporter }) {
|
|
15
|
-
// In real implementation, call Jira REST API
|
|
16
|
-
// POST /rest/api/2/issue
|
|
17
|
-
|
|
18
|
-
const issueKey = `PROJ-${Math.floor(Math.random() * 10000)}`;
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
created: true,
|
|
22
|
-
issueKey,
|
|
23
|
-
summary,
|
|
24
|
-
priority,
|
|
25
|
-
component: component ?? "General",
|
|
26
|
-
reporter,
|
|
27
|
-
url: `https://jira.example.com/browse/${issueKey}`,
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createTool } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const searchKnowledgeBase = createTool({
|
|
5
|
-
id: "search_kb",
|
|
6
|
-
description: "Searches the product knowledge base for relevant articles.",
|
|
7
|
-
input: z.object({ query: z.string() }),
|
|
8
|
-
async execute({ query }, ctx) {
|
|
9
|
-
ctx.logger.info("Searching KB", { query });
|
|
10
|
-
// Replace with your actual knowledge base search logic
|
|
11
|
-
return { answer: null as string | null, sources: [] as string[] };
|
|
12
|
-
},
|
|
13
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { defineWebhook } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Webhook for Slack /escalate command or button
|
|
6
|
-
*/
|
|
7
|
-
export const slackEscalation = defineWebhook({
|
|
8
|
-
id: "slack_escalation",
|
|
9
|
-
input: z.object({
|
|
10
|
-
userId: z.string(),
|
|
11
|
-
channelId: z.string(),
|
|
12
|
-
ticketId: z.string(),
|
|
13
|
-
reason: z.string(),
|
|
14
|
-
urgency: z.string(), // "low", "medium", "high"
|
|
15
|
-
}),
|
|
16
|
-
async handler({ userId, channelId, ticketId, reason, urgency }) {
|
|
17
|
-
// Process escalation request from Slack
|
|
18
|
-
// In real implementation, notify on-call support
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
acknowledged: true,
|
|
22
|
-
ticketId,
|
|
23
|
-
escalationId: `ESC-${Date.now()}`,
|
|
24
|
-
estimatedResponse: urgency === "high" ? "5 minutes" : "30 minutes",
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { defineWebhook } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Zendesk ticket sync webhook
|
|
6
|
-
*/
|
|
7
|
-
export const zendeskTicket = defineWebhook({
|
|
8
|
-
id: "zendesk_ticket",
|
|
9
|
-
input: z.object({
|
|
10
|
-
ticketId: z.string(),
|
|
11
|
-
status: z.string(), // "new", "open", "pending", "solved", "closed"
|
|
12
|
-
subject: z.string(),
|
|
13
|
-
requesterEmail: z.string(),
|
|
14
|
-
tags: z.array(z.string()),
|
|
15
|
-
customFields: z.record(z.unknown()).optional(),
|
|
16
|
-
}),
|
|
17
|
-
async handler({ ticketId, status, subject, requesterEmail, tags, customFields }) {
|
|
18
|
-
// Sync external Zendesk ticket with internal system
|
|
19
|
-
// In real implementation, update internal ticket store
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
synced: true,
|
|
23
|
-
externalId: ticketId,
|
|
24
|
-
localId: `LOCAL-${ticketId}`,
|
|
25
|
-
status,
|
|
26
|
-
tags,
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { asAgentId, defineAgent } from "@kalphq/sdk";
|
|
2
|
-
import { analyzeSignal } from "./steps/analyze-signal.js";
|
|
3
|
-
import { rebalanceCheck } from "./steps/rebalance-check.js";
|
|
4
|
-
import { fetchMarketData } from "./tools/fetch-market-data.js";
|
|
5
|
-
import { sendEmailAlert } from "./tools/send-email-alert.js";
|
|
6
|
-
import { tradingviewAlert } from "./webhooks/tradingview-alert.js";
|
|
7
|
-
import { exchangeWebhook } from "./webhooks/exchange-webhook.js";
|
|
8
|
-
import { marketAlert } from "./signals/market-alert.js";
|
|
9
|
-
import { portfolioRebalance } from "./signals/portfolio-rebalance.js";
|
|
10
|
-
|
|
11
|
-
export default defineAgent({
|
|
12
|
-
id: asAgentId("__AGENT_NAME__"),
|
|
13
|
-
name: "__AGENT_NAME__",
|
|
14
|
-
description: "Monitors market signals and provides financial analysis.",
|
|
15
|
-
steps: [analyzeSignal, rebalanceCheck],
|
|
16
|
-
tools: [fetchMarketData, sendEmailAlert],
|
|
17
|
-
webhooks: [tradingviewAlert, exchangeWebhook],
|
|
18
|
-
signals: [marketAlert, portfolioRebalance],
|
|
19
|
-
|
|
20
|
-
systemPrompt:
|
|
21
|
-
"You are a financial analysis agent. Interpret market signals, fetch live data, and provide actionable insights.",
|
|
22
|
-
|
|
23
|
-
async onMessage(message, ctx) {
|
|
24
|
-
const market = await ctx.callTool(fetchMarketData, {
|
|
25
|
-
symbol: message.text.trim().toUpperCase(),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const analysis = await ctx.runStep(analyzeSignal, {
|
|
29
|
-
symbol: market.symbol,
|
|
30
|
-
price: market.price,
|
|
31
|
-
change: market.change,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Send alert for significant movements
|
|
35
|
-
if (Math.abs(market.change) > 5) {
|
|
36
|
-
await ctx.callTool(sendEmailAlert, {
|
|
37
|
-
to: "portfolio@example.com",
|
|
38
|
-
subject: `Alert: ${market.symbol} moved ${market.change}%`,
|
|
39
|
-
alertType: "price_movement",
|
|
40
|
-
data: {
|
|
41
|
-
symbol: market.symbol,
|
|
42
|
-
change: market.change,
|
|
43
|
-
price: market.price,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return { text: analysis.summary };
|
|
49
|
-
},
|
|
50
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createSignal } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Signal for unusual market movements
|
|
6
|
-
*/
|
|
7
|
-
export const marketAlert = createSignal({
|
|
8
|
-
id: "market_alert",
|
|
9
|
-
input: z.object({
|
|
10
|
-
symbol: z.string(),
|
|
11
|
-
eventType: z.string(), // "gap_up", "gap_down", "high_volume", "volatility_spike"
|
|
12
|
-
changePercent: z.number(),
|
|
13
|
-
volume: z.number(),
|
|
14
|
-
averageVolume: z.number(),
|
|
15
|
-
}),
|
|
16
|
-
async handler({ symbol, eventType, changePercent, volume, averageVolume }) {
|
|
17
|
-
// Broadcast market alert to portfolio agents
|
|
18
|
-
// In real implementation, trigger risk management
|
|
19
|
-
|
|
20
|
-
const volumeRatio = volume / averageVolume;
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
broadcast: true,
|
|
24
|
-
symbol,
|
|
25
|
-
eventType,
|
|
26
|
-
severity: Math.abs(changePercent) > 5 || volumeRatio > 3 ? "high" : "medium",
|
|
27
|
-
changePercent,
|
|
28
|
-
volumeRatio: Number(volumeRatio.toFixed(2)),
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { createSignal } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Signal to trigger portfolio rebalancing
|
|
6
|
-
*/
|
|
7
|
-
export const portfolioRebalance = createSignal({
|
|
8
|
-
id: "portfolio_rebalance",
|
|
9
|
-
input: z.object({
|
|
10
|
-
portfolioId: z.string(),
|
|
11
|
-
driftPercent: z.number(),
|
|
12
|
-
triggeredBy: z.string(), // "scheduled", "threshold", "manual"
|
|
13
|
-
targetAllocation: z.record(z.number()),
|
|
14
|
-
}),
|
|
15
|
-
async handler({ portfolioId, driftPercent, triggeredBy, targetAllocation }) {
|
|
16
|
-
// Signal portfolio agents to execute rebalancing
|
|
17
|
-
// In real implementation, generate orders for execution
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
acknowledged: true,
|
|
21
|
-
portfolioId,
|
|
22
|
-
priority: driftPercent > 10 ? "urgent" : "normal",
|
|
23
|
-
triggeredBy,
|
|
24
|
-
estimatedTrades: Object.keys(targetAllocation).length,
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createStep } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const analyzeSignal = createStep({
|
|
5
|
-
id: "analyze_signal",
|
|
6
|
-
description: "Analyzes a market signal and produces a summary.",
|
|
7
|
-
input: z.object({
|
|
8
|
-
symbol: z.string(),
|
|
9
|
-
price: z.number(),
|
|
10
|
-
change: z.number(),
|
|
11
|
-
}),
|
|
12
|
-
output: z.object({
|
|
13
|
-
sentiment: z.enum(["bullish", "bearish", "neutral"]),
|
|
14
|
-
summary: z.string(),
|
|
15
|
-
}),
|
|
16
|
-
async run({ symbol, price, change }, ctx) {
|
|
17
|
-
const result = await ctx.ai.generateObject({
|
|
18
|
-
prompt: `Analyze this market signal: ${symbol} at $${price} (${change > 0 ? "+" : ""}${change}%). Give sentiment and a one-line summary.`,
|
|
19
|
-
schema: z.object({
|
|
20
|
-
sentiment: z.enum(["bullish", "bearish", "neutral"]),
|
|
21
|
-
summary: z.string(),
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
return result;
|
|
25
|
-
},
|
|
26
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { createStep } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const rebalanceCheck = createStep({
|
|
5
|
-
id: "rebalance_check",
|
|
6
|
-
description: "Analyzes portfolio and recommends rebalancing actions.",
|
|
7
|
-
input: z.object({
|
|
8
|
-
portfolioValue: z.number(),
|
|
9
|
-
targetAllocation: z.record(z.number()), // { stocks: 60, bonds: 30, cash: 10 }
|
|
10
|
-
currentAllocation: z.record(z.number()),
|
|
11
|
-
riskTolerance: z.string(), // "conservative", "moderate", "aggressive"
|
|
12
|
-
}),
|
|
13
|
-
output: z.object({
|
|
14
|
-
needsRebalance: z.boolean(),
|
|
15
|
-
driftPercent: z.number(),
|
|
16
|
-
recommendations: z.array(z.object({
|
|
17
|
-
asset: z.string(),
|
|
18
|
-
action: z.string(), // "buy", "sell", "hold"
|
|
19
|
-
amount: z.number(),
|
|
20
|
-
})),
|
|
21
|
-
}),
|
|
22
|
-
async run({ portfolioValue, targetAllocation, currentAllocation, riskTolerance }) {
|
|
23
|
-
const recommendations: Array<{ asset: string; action: string; amount: number }> = [];
|
|
24
|
-
let maxDrift = 0;
|
|
25
|
-
|
|
26
|
-
// Calculate drift for each asset
|
|
27
|
-
for (const [asset, targetPct] of Object.entries(targetAllocation)) {
|
|
28
|
-
const currentPct = currentAllocation[asset] ?? 0;
|
|
29
|
-
const drift = Math.abs(currentPct - targetPct);
|
|
30
|
-
maxDrift = Math.max(maxDrift, drift);
|
|
31
|
-
|
|
32
|
-
// Generate recommendation if drift > 5%
|
|
33
|
-
if (drift > 5) {
|
|
34
|
-
const targetValue = portfolioValue * (targetPct / 100);
|
|
35
|
-
const currentValue = portfolioValue * (currentPct / 100);
|
|
36
|
-
const diff = targetValue - currentValue;
|
|
37
|
-
|
|
38
|
-
recommendations.push({
|
|
39
|
-
asset,
|
|
40
|
-
action: diff > 0 ? "buy" : "sell",
|
|
41
|
-
amount: Math.abs(diff),
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Conservative portfolios rebalance at lower drift
|
|
47
|
-
const threshold = riskTolerance === "conservative" ? 3 : riskTolerance === "aggressive" ? 8 : 5;
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
needsRebalance: maxDrift > threshold,
|
|
51
|
-
driftPercent: maxDrift,
|
|
52
|
-
recommendations,
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createTool } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const fetchMarketData = createTool({
|
|
5
|
-
id: "fetch_market_data",
|
|
6
|
-
description: "Fetches real-time market data for a given symbol.",
|
|
7
|
-
input: z.object({ symbol: z.string() }),
|
|
8
|
-
async execute({ symbol }, ctx) {
|
|
9
|
-
ctx.logger.info("Fetching market data", { symbol });
|
|
10
|
-
// Replace with actual market data API call
|
|
11
|
-
return { symbol, price: 0, change: 0, volume: 0 };
|
|
12
|
-
},
|
|
13
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createTool } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const sendEmailAlert = createTool({
|
|
5
|
-
id: "send_email_alert",
|
|
6
|
-
description: "Sends email notifications for significant portfolio events.",
|
|
7
|
-
input: z.object({
|
|
8
|
-
to: z.string(),
|
|
9
|
-
subject: z.string(),
|
|
10
|
-
alertType: z.string(), // "price_movement", "rebalance_needed", "dividend", "risk_alert"
|
|
11
|
-
data: z.record(z.unknown()),
|
|
12
|
-
}),
|
|
13
|
-
async execute({ to, subject, alertType, data }) {
|
|
14
|
-
// In real implementation, integrate with SendGrid, AWS SES, etc.
|
|
15
|
-
|
|
16
|
-
const emailBody = JSON.stringify({
|
|
17
|
-
alertType,
|
|
18
|
-
timestamp: new Date().toISOString(),
|
|
19
|
-
data,
|
|
20
|
-
}, null, 2);
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
sent: true,
|
|
24
|
-
recipient: to,
|
|
25
|
-
subject,
|
|
26
|
-
alertType,
|
|
27
|
-
messageId: `msg_${Date.now()}`,
|
|
28
|
-
preview: emailBody.slice(0, 200),
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { defineWebhook } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Exchange webhook for order execution confirmations
|
|
6
|
-
*/
|
|
7
|
-
export const exchangeWebhook = defineWebhook({
|
|
8
|
-
id: "exchange_webhook",
|
|
9
|
-
input: z.object({
|
|
10
|
-
orderId: z.string(),
|
|
11
|
-
symbol: z.string(),
|
|
12
|
-
side: z.string(), // "buy", "sell"
|
|
13
|
-
status: z.string(), // "filled", "partial", "rejected"
|
|
14
|
-
filledQty: z.number(),
|
|
15
|
-
avgPrice: z.number(),
|
|
16
|
-
commission: z.number(),
|
|
17
|
-
}),
|
|
18
|
-
async handler({ orderId, symbol, side, status, filledQty, avgPrice, commission }) {
|
|
19
|
-
// Process order execution from exchange
|
|
20
|
-
// In real implementation, update portfolio holdings
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
confirmed: true,
|
|
24
|
-
orderId,
|
|
25
|
-
symbol,
|
|
26
|
-
side,
|
|
27
|
-
status,
|
|
28
|
-
totalValue: filledQty * avgPrice,
|
|
29
|
-
commission,
|
|
30
|
-
netProceeds: filledQty * avgPrice - commission,
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { defineWebhook } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* TradingView alert webhook for technical indicator signals
|
|
6
|
-
*/
|
|
7
|
-
export const tradingviewAlert = defineWebhook({
|
|
8
|
-
id: "tradingview_alert",
|
|
9
|
-
input: z.object({
|
|
10
|
-
symbol: z.string(),
|
|
11
|
-
indicator: z.string(), // "RSI", "MACD", "BB", "EMA_CROSS"
|
|
12
|
-
signal: z.string(), // "buy", "sell", "neutral"
|
|
13
|
-
value: z.number(),
|
|
14
|
-
timeframe: z.string(), // "1h", "4h", "1d"
|
|
15
|
-
price: z.number(),
|
|
16
|
-
}),
|
|
17
|
-
async handler({ symbol, indicator, signal, value, timeframe, price }) {
|
|
18
|
-
// Process technical indicator alert from TradingView
|
|
19
|
-
// In real implementation, trigger portfolio rebalancing
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
processed: true,
|
|
23
|
-
symbol,
|
|
24
|
-
indicator,
|
|
25
|
-
signal,
|
|
26
|
-
timestamp: new Date().toISOString(),
|
|
27
|
-
significance: signal === "buy" && value < 30 ? "high" : "medium",
|
|
28
|
-
};
|
|
29
|
-
},
|
|
30
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { asAgentId, defineAgent } from "@kalphq/sdk";
|
|
2
|
-
import { exampleStep } from "./steps/example-step.js";
|
|
3
|
-
import { transformData } from "./steps/transform-data.js";
|
|
4
|
-
import { exampleTool } from "./tools/example-tool.js";
|
|
5
|
-
import { httpRequest } from "./tools/http-request.js";
|
|
6
|
-
import { genericInbound } from "./webhooks/generic-inbound.js";
|
|
7
|
-
import { healthCheck } from "./webhooks/health-check.js";
|
|
8
|
-
import { taskComplete } from "./signals/task-complete.js";
|
|
9
|
-
import { errorAlert } from "./signals/error-alert.js";
|
|
10
|
-
|
|
11
|
-
export default defineAgent({
|
|
12
|
-
id: asAgentId("__AGENT_NAME__"),
|
|
13
|
-
name: "__AGENT_NAME__",
|
|
14
|
-
steps: [exampleStep, transformData],
|
|
15
|
-
tools: [exampleTool, httpRequest],
|
|
16
|
-
webhooks: [genericInbound, healthCheck],
|
|
17
|
-
signals: [taskComplete, errorAlert],
|
|
18
|
-
|
|
19
|
-
async onMessage(message, ctx) {
|
|
20
|
-
const stepped = await ctx.runStep(exampleStep, { message: message.text });
|
|
21
|
-
const tooled = await ctx.callTool(exampleTool, { query: message.text });
|
|
22
|
-
return { text: `${stepped.result} | ${tooled.output}` };
|
|
23
|
-
},
|
|
24
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createSignal } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Signal sent when an error occurs
|
|
6
|
-
*/
|
|
7
|
-
export const errorAlert = createSignal({
|
|
8
|
-
id: "error_alert",
|
|
9
|
-
input: z.object({
|
|
10
|
-
errorId: z.string(),
|
|
11
|
-
message: z.string(),
|
|
12
|
-
severity: z.string(), // "low", "medium", "high", "critical"
|
|
13
|
-
context: z.record(z.unknown()).optional(),
|
|
14
|
-
}),
|
|
15
|
-
async handler({ errorId, message, severity, context }) {
|
|
16
|
-
// Signal error to monitoring system
|
|
17
|
-
// In real implementation, send to error tracking service
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
logged: true,
|
|
21
|
-
errorId,
|
|
22
|
-
severity,
|
|
23
|
-
alertSent: severity === "high" || severity === "critical",
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { createSignal } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Signal sent when a task completes successfully
|
|
6
|
-
*/
|
|
7
|
-
export const taskComplete = createSignal({
|
|
8
|
-
id: "task_complete",
|
|
9
|
-
input: z.object({
|
|
10
|
-
taskId: z.string(),
|
|
11
|
-
result: z.string(),
|
|
12
|
-
duration: z.number(), // seconds
|
|
13
|
-
}),
|
|
14
|
-
async handler({ taskId, result, duration }) {
|
|
15
|
-
// Signal completion to orchestrator
|
|
16
|
-
// In real implementation, update task queue
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
acknowledged: true,
|
|
20
|
-
taskId,
|
|
21
|
-
status: "completed",
|
|
22
|
-
duration,
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createStep } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const exampleStep = createStep({
|
|
5
|
-
id: "example_step",
|
|
6
|
-
description: "A stub step — replace with your own logic.",
|
|
7
|
-
input: z.object({ message: z.string() }),
|
|
8
|
-
output: z.object({ result: z.string() }),
|
|
9
|
-
async run({ message }, ctx) {
|
|
10
|
-
ctx.logger.info("Running example step", { message });
|
|
11
|
-
return { result: `Processed: ${message}` };
|
|
12
|
-
},
|
|
13
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { createStep } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const transformData = createStep({
|
|
5
|
-
id: "transform_data",
|
|
6
|
-
description: "Transforms input data to a standardized format.",
|
|
7
|
-
input: z.object({
|
|
8
|
-
data: z.record(z.unknown()),
|
|
9
|
-
format: z.string(), // "json", "csv", "xml"
|
|
10
|
-
}),
|
|
11
|
-
output: z.object({
|
|
12
|
-
transformed: z.boolean(),
|
|
13
|
-
result: z.record(z.unknown()),
|
|
14
|
-
format: z.string(),
|
|
15
|
-
}),
|
|
16
|
-
async run({ data, format }) {
|
|
17
|
-
// Simple transformation example
|
|
18
|
-
const result: Record<string, unknown> = {};
|
|
19
|
-
|
|
20
|
-
for (const [key, value] of Object.entries(data)) {
|
|
21
|
-
// Normalize keys to snake_case
|
|
22
|
-
const normalizedKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
23
|
-
result[normalizedKey] = value;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
transformed: true,
|
|
28
|
-
result,
|
|
29
|
-
format: format.toLowerCase(),
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { createTool } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const exampleTool = createTool({
|
|
5
|
-
id: "example_tool",
|
|
6
|
-
description: "A stub tool — replace with your own external call.",
|
|
7
|
-
input: z.object({ query: z.string() }),
|
|
8
|
-
async execute({ query }, ctx) {
|
|
9
|
-
ctx.logger.info("Calling example tool", { query });
|
|
10
|
-
// Replace with your actual external API call
|
|
11
|
-
return { output: `Result for: ${query}` };
|
|
12
|
-
},
|
|
13
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createTool } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
export const httpRequest = createTool({
|
|
5
|
-
id: "http_request",
|
|
6
|
-
description: "Generic HTTP client for external API calls.",
|
|
7
|
-
input: z.object({
|
|
8
|
-
url: z.string(),
|
|
9
|
-
method: z.string().default("GET"), // "GET", "POST", "PUT", "DELETE"
|
|
10
|
-
headers: z.record(z.string()).optional(),
|
|
11
|
-
body: z.string().optional(),
|
|
12
|
-
}),
|
|
13
|
-
async execute({ url, method, headers, body }) {
|
|
14
|
-
// In real implementation, use fetch or axios
|
|
15
|
-
// This is a stub showing the pattern
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
statusCode: 200,
|
|
19
|
-
status: "ok",
|
|
20
|
-
url,
|
|
21
|
-
method,
|
|
22
|
-
bodyLength: body?.length ?? 0,
|
|
23
|
-
timestamp: new Date().toISOString(),
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { defineWebhook } from "@kalphq/sdk";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generic inbound webhook example
|
|
6
|
-
*/
|
|
7
|
-
export const genericInbound = defineWebhook({
|
|
8
|
-
id: "generic_inbound",
|
|
9
|
-
input: z.object({
|
|
10
|
-
event: z.string(),
|
|
11
|
-
payload: z.record(z.unknown()),
|
|
12
|
-
timestamp: z.string().optional(),
|
|
13
|
-
}),
|
|
14
|
-
async handler({ event, payload, timestamp }) {
|
|
15
|
-
// Process generic inbound webhook
|
|
16
|
-
// In real implementation, route to appropriate handler
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
received: true,
|
|
20
|
-
event,
|
|
21
|
-
payloadKeys: Object.keys(payload),
|
|
22
|
-
processedAt: new Date().toISOString(),
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
});
|