@jam-nodes/nodes 0.2.3 → 0.2.5
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/ai/analyze-posts.d.ts +4 -2
- package/dist/ai/analyze-posts.d.ts.map +1 -1
- package/dist/ai/analyze-posts.js +48 -44
- package/dist/ai/analyze-posts.js.map +1 -1
- package/dist/ai/draft-emails.d.ts +4 -2
- package/dist/ai/draft-emails.d.ts.map +1 -1
- package/dist/ai/draft-emails.js +57 -42
- package/dist/ai/draft-emails.js.map +1 -1
- package/dist/ai/keyword-generator.d.ts +1 -1
- package/dist/ai/keyword-generator.d.ts.map +1 -1
- package/dist/ai/keyword-generator.js +45 -20
- package/dist/ai/keyword-generator.js.map +1 -1
- package/dist/examples/bread.d.ts +24 -0
- package/dist/examples/bread.d.ts.map +1 -0
- package/dist/examples/bread.js +33 -0
- package/dist/examples/bread.js.map +1 -0
- package/dist/examples/index.d.ts +3 -0
- package/dist/examples/index.d.ts.map +1 -1
- package/dist/examples/index.js +2 -0
- package/dist/examples/index.js.map +1 -1
- package/dist/index.d.ts +38 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/integrations/apollo/search-contacts.d.ts +8 -8
- package/dist/integrations/apollo/search-contacts.d.ts.map +1 -1
- package/dist/integrations/apollo/search-contacts.js +110 -26
- package/dist/integrations/apollo/search-contacts.js.map +1 -1
- package/dist/integrations/dataforseo/keyword-research.d.ts +1 -1
- package/dist/integrations/dataforseo/keyword-research.d.ts.map +1 -1
- package/dist/integrations/dataforseo/keyword-research.js +59 -9
- package/dist/integrations/dataforseo/keyword-research.js.map +1 -1
- package/dist/integrations/dataforseo/seo-audit.d.ts +1 -1
- package/dist/integrations/dataforseo/seo-audit.d.ts.map +1 -1
- package/dist/integrations/dataforseo/seo-audit.js +52 -23
- package/dist/integrations/dataforseo/seo-audit.js.map +1 -1
- package/dist/integrations/openai/sora-video.d.ts +1 -1
- package/dist/integrations/openai/sora-video.d.ts.map +1 -1
- package/dist/integrations/openai/sora-video.js +82 -7
- package/dist/integrations/openai/sora-video.js.map +1 -1
- package/dist/integrations/social/linkedin-monitor.d.ts +1 -1
- package/dist/integrations/social/linkedin-monitor.d.ts.map +1 -1
- package/dist/integrations/social/linkedin-monitor.js +69 -35
- package/dist/integrations/social/linkedin-monitor.js.map +1 -1
- package/dist/integrations/social/reddit-monitor.d.ts.map +1 -1
- package/dist/integrations/social/reddit-monitor.js +5 -12
- package/dist/integrations/social/reddit-monitor.js.map +1 -1
- package/dist/integrations/social/twitter-monitor.d.ts +20 -3
- package/dist/integrations/social/twitter-monitor.d.ts.map +1 -1
- package/dist/integrations/social/twitter-monitor.js +44 -28
- package/dist/integrations/social/twitter-monitor.js.map +1 -1
- package/dist/transform/index.d.ts +3 -0
- package/dist/transform/index.d.ts.map +1 -1
- package/dist/transform/index.js +2 -0
- package/dist/transform/index.js.map +1 -1
- package/dist/transform/sort.d.ts +37 -0
- package/dist/transform/sort.d.ts.map +1 -0
- package/dist/transform/sort.js +68 -0
- package/dist/transform/sort.js.map +1 -0
- package/dist/utils/http.d.ts +60 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +126 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -5,8 +5,10 @@ export { SocialAiAnalyzeInputSchema, SocialAiAnalyzeOutputSchema, type SocialAiA
|
|
|
5
5
|
* Uses Claude to analyze social media posts for relevance, sentiment,
|
|
6
6
|
* complaint detection, and urgency. Batches posts to stay within context limits.
|
|
7
7
|
*
|
|
8
|
-
* Requires `context.
|
|
9
|
-
*
|
|
8
|
+
* Requires `context.credentials.anthropic.apiKey` to be provided.
|
|
9
|
+
*
|
|
10
|
+
* Note: This node analyzes posts but does NOT store results.
|
|
11
|
+
* Storage is the responsibility of the host application.
|
|
10
12
|
*
|
|
11
13
|
* @example
|
|
12
14
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze-posts.d.ts","sourceRoot":"","sources":["../../src/ai/analyze-posts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"analyze-posts.d.ts","sourceRoot":"","sources":["../../src/ai/analyze-posts.ts"],"names":[],"mappings":"AAoFA,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsI9B,CAAC"}
|
package/dist/ai/analyze-posts.js
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
import { defineNode } from '@jam-nodes/core';
|
|
2
|
+
import { fetchWithRetry } from '../utils/http.js';
|
|
2
3
|
import { SocialAiAnalyzeInputSchema, SocialAiAnalyzeOutputSchema, } from '../schemas/ai.js';
|
|
3
4
|
import { buildAnalysisPrompt, normalizeSentiment, normalizeUrgency, MIN_RELEVANCE_SCORE, ANALYSIS_BATCH_SIZE, } from '../prompts/analyze-posts.js';
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// Constants
|
|
7
|
+
// =============================================================================
|
|
8
|
+
const ANTHROPIC_API_BASE = 'https://api.anthropic.com/v1';
|
|
9
|
+
const ANTHROPIC_VERSION = '2023-06-01';
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// API Functions
|
|
12
|
+
// =============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Generate text using Anthropic Claude API
|
|
15
|
+
*/
|
|
16
|
+
async function generateText(apiKey, prompt, options = {}) {
|
|
17
|
+
const { model = 'claude-sonnet-4-20250514', maxTokens = 4000 } = options;
|
|
18
|
+
const response = await fetchWithRetry(`${ANTHROPIC_API_BASE}/messages`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
'x-api-key': apiKey,
|
|
23
|
+
'anthropic-version': ANTHROPIC_VERSION,
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
model,
|
|
27
|
+
max_tokens: maxTokens,
|
|
28
|
+
messages: [
|
|
29
|
+
{
|
|
30
|
+
role: 'user',
|
|
31
|
+
content: prompt,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
}),
|
|
35
|
+
}, { maxRetries: 3, backoffMs: 1000, timeoutMs: 120000 });
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const errorText = await response.text();
|
|
38
|
+
throw new Error(`Anthropic API error: ${response.status} - ${errorText}`);
|
|
39
|
+
}
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
return data.content[0]?.text || '';
|
|
42
|
+
}
|
|
4
43
|
// Re-export schemas and types for convenience
|
|
5
44
|
export { SocialAiAnalyzeInputSchema, SocialAiAnalyzeOutputSchema, } from '../schemas/ai.js';
|
|
6
45
|
/**
|
|
@@ -9,8 +48,10 @@ export { SocialAiAnalyzeInputSchema, SocialAiAnalyzeOutputSchema, } from '../sch
|
|
|
9
48
|
* Uses Claude to analyze social media posts for relevance, sentiment,
|
|
10
49
|
* complaint detection, and urgency. Batches posts to stay within context limits.
|
|
11
50
|
*
|
|
12
|
-
* Requires `context.
|
|
13
|
-
*
|
|
51
|
+
* Requires `context.credentials.anthropic.apiKey` to be provided.
|
|
52
|
+
*
|
|
53
|
+
* Note: This node analyzes posts but does NOT store results.
|
|
54
|
+
* Storage is the responsibility of the host application.
|
|
14
55
|
*
|
|
15
56
|
* @example
|
|
16
57
|
* ```typescript
|
|
@@ -36,11 +77,12 @@ export const socialAiAnalyzeNode = defineNode({
|
|
|
36
77
|
},
|
|
37
78
|
executor: async (input, context) => {
|
|
38
79
|
try {
|
|
39
|
-
//
|
|
40
|
-
|
|
80
|
+
// Check for API key
|
|
81
|
+
const apiKey = context.credentials?.anthropic?.apiKey;
|
|
82
|
+
if (!apiKey) {
|
|
41
83
|
return {
|
|
42
84
|
success: false,
|
|
43
|
-
error: 'Anthropic
|
|
85
|
+
error: 'Anthropic API key not configured. Please provide context.credentials.anthropic.apiKey.',
|
|
44
86
|
};
|
|
45
87
|
}
|
|
46
88
|
// Combine posts from all platforms
|
|
@@ -69,8 +111,7 @@ export const socialAiAnalyzeNode = defineNode({
|
|
|
69
111
|
for (let i = 0; i < allPosts.length; i += ANALYSIS_BATCH_SIZE) {
|
|
70
112
|
const batch = allPosts.slice(i, i + ANALYSIS_BATCH_SIZE);
|
|
71
113
|
const prompt = buildAnalysisPrompt(input.topic, input.userIntent, batch);
|
|
72
|
-
const responseText = await
|
|
73
|
-
prompt,
|
|
114
|
+
const responseText = await generateText(apiKey, prompt, {
|
|
74
115
|
model: 'claude-sonnet-4-20250514',
|
|
75
116
|
maxTokens: 4000,
|
|
76
117
|
});
|
|
@@ -111,43 +152,6 @@ export const socialAiAnalyzeNode = defineNode({
|
|
|
111
152
|
? Math.round(allAnalyzedPosts.reduce((sum, p) => sum + p.relevanceScore, 0) /
|
|
112
153
|
allAnalyzedPosts.length)
|
|
113
154
|
: 0;
|
|
114
|
-
// Store analyzed posts if service available
|
|
115
|
-
if (context.services?.analyzedPosts && input.monitoringConfigId && allAnalyzedPosts.length > 0) {
|
|
116
|
-
await context.services.analyzedPosts.storePosts({
|
|
117
|
-
monitoringConfigId: input.monitoringConfigId,
|
|
118
|
-
posts: allAnalyzedPosts.map(post => ({
|
|
119
|
-
platform: post.platform,
|
|
120
|
-
externalId: post.id,
|
|
121
|
-
url: post.url,
|
|
122
|
-
text: post.text,
|
|
123
|
-
authorName: post.authorName,
|
|
124
|
-
authorHandle: post.authorHandle,
|
|
125
|
-
authorUrl: post.authorUrl,
|
|
126
|
-
authorFollowers: post.authorFollowers,
|
|
127
|
-
engagement: post.engagement,
|
|
128
|
-
relevanceScore: post.relevanceScore,
|
|
129
|
-
sentiment: post.sentiment,
|
|
130
|
-
isComplaint: post.isComplaint,
|
|
131
|
-
urgencyLevel: post.urgencyLevel,
|
|
132
|
-
aiSummary: post.aiSummary,
|
|
133
|
-
matchedKeywords: post.matchedKeywords,
|
|
134
|
-
postedAt: new Date(post.postedAt),
|
|
135
|
-
})),
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
// Optional: send notification if service available
|
|
139
|
-
if (context.services?.notifications && allAnalyzedPosts.length > 0) {
|
|
140
|
-
await context.services.notifications.send({
|
|
141
|
-
userId: context.userId,
|
|
142
|
-
title: 'Social Posts Analyzed',
|
|
143
|
-
message: `Analyzed ${allAnalyzedPosts.length} posts (${highPriorityPosts.length} high priority)`,
|
|
144
|
-
data: {
|
|
145
|
-
totalAnalyzed: allAnalyzedPosts.length,
|
|
146
|
-
highPriority: highPriorityPosts.length,
|
|
147
|
-
complaints: complaints.length,
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
155
|
return {
|
|
152
156
|
success: true,
|
|
153
157
|
output: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyze-posts.js","sourceRoot":"","sources":["../../src/ai/analyze-posts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,GAG5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AAErC,8CAA8C;AAC9C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GAAG,CAAC;gBACzB,CAAC,CAAC,IAAI,CAAC,KAAK,CACR,gBAAgB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC;oBAC5D,gBAAgB,CAAC,MAAM,CAC1B;gBACH,CAAC,CAAC,CAAC,CAAC;YAER,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,aAAa,EAAE,gBAAgB;oBAC/B,iBAAiB;oBACjB,UAAU;oBACV,aAAa,EAAE,gBAAgB,CAAC,MAAM;oBACtC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM;oBAC3C,cAAc,EAAE,UAAU,CAAC,MAAM;oBACjC,gBAAgB;iBACjB;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAyB;aAC1E,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -3,8 +3,10 @@ export { DraftEmailsInputSchema, DraftEmailsOutputSchema, DraftEmailInfoSchema,
|
|
|
3
3
|
* Draft Emails Node
|
|
4
4
|
*
|
|
5
5
|
* Uses Claude to generate personalized email drafts for each contact.
|
|
6
|
-
* Requires `context.
|
|
7
|
-
*
|
|
6
|
+
* Requires `context.credentials.anthropic.apiKey` to be provided.
|
|
7
|
+
*
|
|
8
|
+
* Note: This node generates email content but does NOT store drafts.
|
|
9
|
+
* Storage is the responsibility of the host application.
|
|
8
10
|
*
|
|
9
11
|
* @example
|
|
10
12
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-emails.d.ts","sourceRoot":"","sources":["../../src/ai/draft-emails.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"draft-emails.d.ts","sourceRoot":"","sources":["../../src/ai/draft-emails.ts"],"names":[],"mappings":"AAmFA,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,OAAO,GACb,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsG1B,CAAC"}
|
package/dist/ai/draft-emails.js
CHANGED
|
@@ -1,14 +1,55 @@
|
|
|
1
1
|
import { defineNode } from '@jam-nodes/core';
|
|
2
|
+
import { fetchWithRetry, sleep } from '../utils/http.js';
|
|
2
3
|
import { DraftEmailsInputSchema, DraftEmailsOutputSchema, } from '../schemas/ai.js';
|
|
3
4
|
import { buildEmailPrompt, buildSubjectPrompt, cleanEmailBody, cleanSubjectLine, } from '../prompts/draft-emails.js';
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// Constants
|
|
7
|
+
// =============================================================================
|
|
8
|
+
const ANTHROPIC_API_BASE = 'https://api.anthropic.com/v1';
|
|
9
|
+
const ANTHROPIC_VERSION = '2023-06-01';
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// API Functions
|
|
12
|
+
// =============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Generate text using Anthropic Claude API
|
|
15
|
+
*/
|
|
16
|
+
async function generateText(apiKey, prompt, options = {}) {
|
|
17
|
+
const { model = 'claude-sonnet-4-20250514', maxTokens = 1000 } = options;
|
|
18
|
+
const response = await fetchWithRetry(`${ANTHROPIC_API_BASE}/messages`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
'x-api-key': apiKey,
|
|
23
|
+
'anthropic-version': ANTHROPIC_VERSION,
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
model,
|
|
27
|
+
max_tokens: maxTokens,
|
|
28
|
+
messages: [
|
|
29
|
+
{
|
|
30
|
+
role: 'user',
|
|
31
|
+
content: prompt,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
}),
|
|
35
|
+
}, { maxRetries: 3, backoffMs: 1000, timeoutMs: 60000 });
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const errorText = await response.text();
|
|
38
|
+
throw new Error(`Anthropic API error: ${response.status} - ${errorText}`);
|
|
39
|
+
}
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
return data.content[0]?.text || '';
|
|
42
|
+
}
|
|
4
43
|
// Re-export schemas for convenience
|
|
5
44
|
export { DraftEmailsInputSchema, DraftEmailsOutputSchema, DraftEmailInfoSchema, ContactSchema, } from '../schemas/ai.js';
|
|
6
45
|
/**
|
|
7
46
|
* Draft Emails Node
|
|
8
47
|
*
|
|
9
48
|
* Uses Claude to generate personalized email drafts for each contact.
|
|
10
|
-
* Requires `context.
|
|
11
|
-
*
|
|
49
|
+
* Requires `context.credentials.anthropic.apiKey` to be provided.
|
|
50
|
+
*
|
|
51
|
+
* Note: This node generates email content but does NOT store drafts.
|
|
52
|
+
* Storage is the responsibility of the host application.
|
|
12
53
|
*
|
|
13
54
|
* @example
|
|
14
55
|
* ```typescript
|
|
@@ -32,24 +73,12 @@ export const draftEmailsNode = defineNode({
|
|
|
32
73
|
},
|
|
33
74
|
executor: async (input, context) => {
|
|
34
75
|
try {
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
success: false,
|
|
39
|
-
error: 'Anthropic service not configured. Please provide context.services.anthropic.',
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// Require email drafts service
|
|
43
|
-
if (!context.services?.emailDrafts) {
|
|
76
|
+
// Check for API key
|
|
77
|
+
const apiKey = context.credentials?.anthropic?.apiKey;
|
|
78
|
+
if (!apiKey) {
|
|
44
79
|
return {
|
|
45
80
|
success: false,
|
|
46
|
-
error: '
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (!context.campaignId) {
|
|
50
|
-
return {
|
|
51
|
-
success: false,
|
|
52
|
-
error: 'Campaign ID is required in execution context',
|
|
81
|
+
error: 'Anthropic API key not configured. Please provide context.credentials.anthropic.apiKey.',
|
|
53
82
|
};
|
|
54
83
|
}
|
|
55
84
|
// Get sender name from workflow variables
|
|
@@ -57,11 +86,11 @@ export const draftEmailsNode = defineNode({
|
|
|
57
86
|
if (!senderName) {
|
|
58
87
|
return {
|
|
59
88
|
success: false,
|
|
60
|
-
error: 'Please set
|
|
89
|
+
error: 'Please set senderName in context.variables before creating email campaigns.',
|
|
61
90
|
};
|
|
62
91
|
}
|
|
63
92
|
const emails = [];
|
|
64
|
-
// Generate
|
|
93
|
+
// Generate drafts for each contact
|
|
65
94
|
for (const contact of input.contacts) {
|
|
66
95
|
if (!contact.email) {
|
|
67
96
|
continue;
|
|
@@ -69,8 +98,7 @@ export const draftEmailsNode = defineNode({
|
|
|
69
98
|
try {
|
|
70
99
|
// Generate personalized email body using prompt helper
|
|
71
100
|
const emailPrompt = buildEmailPrompt(contact, input.productDescription, senderName, input.emailTemplate);
|
|
72
|
-
const rawBody = await
|
|
73
|
-
prompt: emailPrompt,
|
|
101
|
+
const rawBody = await generateText(apiKey, emailPrompt, {
|
|
74
102
|
model: 'claude-sonnet-4-20250514',
|
|
75
103
|
maxTokens: 250,
|
|
76
104
|
});
|
|
@@ -78,37 +106,24 @@ export const draftEmailsNode = defineNode({
|
|
|
78
106
|
const emailBody = cleanEmailBody(rawBody);
|
|
79
107
|
// Generate subject line
|
|
80
108
|
const subjectPrompt = buildSubjectPrompt(contact, emailBody);
|
|
81
|
-
const rawSubject = await
|
|
82
|
-
prompt: subjectPrompt,
|
|
109
|
+
const rawSubject = await generateText(apiKey, subjectPrompt, {
|
|
83
110
|
model: 'claude-sonnet-4-20250514',
|
|
84
111
|
maxTokens: 50,
|
|
85
112
|
});
|
|
86
113
|
// Clean up subject
|
|
87
114
|
const emailSubject = cleanSubjectLine(rawSubject);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
campaignId: context.campaignId,
|
|
91
|
-
userId: context.userId,
|
|
115
|
+
emails.push({
|
|
116
|
+
id: `draft-${contact.id}-${Date.now()}`,
|
|
92
117
|
toEmail: contact.email,
|
|
93
118
|
toName: contact.name,
|
|
94
|
-
toCompany: contact.company
|
|
95
|
-
toTitle: contact.title
|
|
119
|
+
toCompany: contact.company || '',
|
|
120
|
+
toTitle: contact.title || '',
|
|
96
121
|
subject: emailSubject,
|
|
97
122
|
body: emailBody,
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
emails.push({
|
|
101
|
-
id: savedEmail.id,
|
|
102
|
-
toEmail: savedEmail.toEmail,
|
|
103
|
-
toName: savedEmail.toName || '',
|
|
104
|
-
toCompany: savedEmail.toCompany || '',
|
|
105
|
-
toTitle: savedEmail.toTitle || '',
|
|
106
|
-
subject: savedEmail.subject,
|
|
107
|
-
body: savedEmail.body,
|
|
108
|
-
status: savedEmail.status,
|
|
123
|
+
status: 'draft',
|
|
109
124
|
});
|
|
110
125
|
// Small delay between API calls to avoid rate limiting
|
|
111
|
-
await
|
|
126
|
+
await sleep(200);
|
|
112
127
|
}
|
|
113
128
|
catch {
|
|
114
129
|
// Continue with other contacts even if one fails
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-emails.js","sourceRoot":"","sources":["../../src/ai/draft-emails.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GAGxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AAEpC,oCAAoC;AACpC,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,GAKd,MA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B,CAAC,CAAC;oBAEH,uDAAuD;oBACvD,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;gBAAC,MAAM,CAAC;oBACP,iDAAiD;gBACnD,CAAC;YACH,CAAC;YAED,MAAM,MAAM,GAAsB;gBAChC,MAAM;gBACN,YAAY,EAAE,MAAM,CAAC,MAAM;aAC5B,CAAC;YAEF,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM;aACP,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB;aACzE,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -6,7 +6,7 @@ export { SocialKeywordGeneratorInputSchema, SocialKeywordGeneratorOutputSchema,
|
|
|
6
6
|
* natural language topic description. Outputs ready-to-use search queries
|
|
7
7
|
* for Twitter, Reddit, and LinkedIn.
|
|
8
8
|
*
|
|
9
|
-
* Requires `context.
|
|
9
|
+
* Requires `context.credentials.anthropic.apiKey` to be provided.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyword-generator.d.ts","sourceRoot":"","sources":["../../src/ai/keyword-generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyword-generator.d.ts","sourceRoot":"","sources":["../../src/ai/keyword-generator.ts"],"names":[],"mappings":"AA6EA,OAAO,EACL,iCAAiC,EACjC,kCAAkC,EAClC,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;EAoGrC,CAAC"}
|
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
import { defineNode } from '@jam-nodes/core';
|
|
2
|
+
import { fetchWithRetry } from '../utils/http.js';
|
|
2
3
|
import { SocialKeywordGeneratorInputSchema, SocialKeywordGeneratorOutputSchema, } from '../schemas/ai.js';
|
|
3
4
|
import { buildKeywordPrompt } from '../prompts/keyword-generator.js';
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// Constants
|
|
7
|
+
// =============================================================================
|
|
8
|
+
const ANTHROPIC_API_BASE = 'https://api.anthropic.com/v1';
|
|
9
|
+
const ANTHROPIC_VERSION = '2023-06-01';
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// API Functions
|
|
12
|
+
// =============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Generate text using Anthropic Claude API
|
|
15
|
+
*/
|
|
16
|
+
async function generateText(apiKey, prompt, options = {}) {
|
|
17
|
+
const { model = 'claude-sonnet-4-20250514', maxTokens = 2000 } = options;
|
|
18
|
+
const response = await fetchWithRetry(`${ANTHROPIC_API_BASE}/messages`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
'x-api-key': apiKey,
|
|
23
|
+
'anthropic-version': ANTHROPIC_VERSION,
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
model,
|
|
27
|
+
max_tokens: maxTokens,
|
|
28
|
+
messages: [
|
|
29
|
+
{
|
|
30
|
+
role: 'user',
|
|
31
|
+
content: prompt,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
}),
|
|
35
|
+
}, { maxRetries: 3, backoffMs: 1000, timeoutMs: 60000 });
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const errorText = await response.text();
|
|
38
|
+
throw new Error(`Anthropic API error: ${response.status} - ${errorText}`);
|
|
39
|
+
}
|
|
40
|
+
const data = await response.json();
|
|
41
|
+
return data.content[0]?.text || '';
|
|
42
|
+
}
|
|
4
43
|
// Re-export schemas for convenience
|
|
5
44
|
export { SocialKeywordGeneratorInputSchema, SocialKeywordGeneratorOutputSchema, } from '../schemas/ai.js';
|
|
6
45
|
/**
|
|
@@ -10,7 +49,7 @@ export { SocialKeywordGeneratorInputSchema, SocialKeywordGeneratorOutputSchema,
|
|
|
10
49
|
* natural language topic description. Outputs ready-to-use search queries
|
|
11
50
|
* for Twitter, Reddit, and LinkedIn.
|
|
12
51
|
*
|
|
13
|
-
* Requires `context.
|
|
52
|
+
* Requires `context.credentials.anthropic.apiKey` to be provided.
|
|
14
53
|
*
|
|
15
54
|
* @example
|
|
16
55
|
* ```typescript
|
|
@@ -33,18 +72,18 @@ export const socialKeywordGeneratorNode = defineNode({
|
|
|
33
72
|
},
|
|
34
73
|
executor: async (input, context) => {
|
|
35
74
|
try {
|
|
36
|
-
//
|
|
37
|
-
|
|
75
|
+
// Check for API key
|
|
76
|
+
const apiKey = context.credentials?.anthropic?.apiKey;
|
|
77
|
+
if (!apiKey) {
|
|
38
78
|
return {
|
|
39
79
|
success: false,
|
|
40
|
-
error: 'Anthropic
|
|
80
|
+
error: 'Anthropic API key not configured. Please provide context.credentials.anthropic.apiKey.',
|
|
41
81
|
};
|
|
42
82
|
}
|
|
43
83
|
// Build prompt using helper
|
|
44
84
|
const prompt = buildKeywordPrompt(input.topic, input.userKeywords);
|
|
45
85
|
// Call Claude to generate keywords
|
|
46
|
-
const responseText = await
|
|
47
|
-
prompt,
|
|
86
|
+
const responseText = await generateText(apiKey, prompt, {
|
|
48
87
|
model: 'claude-sonnet-4-20250514',
|
|
49
88
|
maxTokens: 2000,
|
|
50
89
|
});
|
|
@@ -94,20 +133,6 @@ export const socialKeywordGeneratorNode = defineNode({
|
|
|
94
133
|
},
|
|
95
134
|
allKeywords,
|
|
96
135
|
};
|
|
97
|
-
// Optional: send notification if service available
|
|
98
|
-
if (context.services?.notifications) {
|
|
99
|
-
await context.services.notifications.send({
|
|
100
|
-
userId: context.userId,
|
|
101
|
-
title: 'Keywords Generated',
|
|
102
|
-
message: `Generated ${allKeywords.length} keywords for "${input.topic}"`,
|
|
103
|
-
data: {
|
|
104
|
-
totalKeywords: allKeywords.length,
|
|
105
|
-
twitterKeywords: mergedTwitterKeywords.length,
|
|
106
|
-
redditKeywords: mergedRedditKeywords.length,
|
|
107
|
-
linkedinKeywords: mergedLinkedInKeywords.length,
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
136
|
return {
|
|
112
137
|
success: true,
|
|
113
138
|
output,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyword-generator.js","sourceRoot":"","sources":["../../src/ai/keyword-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,iCAAiC,EACjC,kCAAkC,GAEnC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,oCAAoC;AACpC,OAAO,EACL,iCAAiC,EACjC,kCAAkC,GAGnC,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAC;IACnD,IAAI,EAAE,0BAA0B;IAChC,IAAI,EAAE,0BAA0B;IAChC,WAAW,EAAE,2EAA2E;IACxF,QAAQ,EAAE,QAAQ;IAClB,WAAW,EAAE,iCAAiC;IAC9C,YAAY,EAAE,kCAAkC;IAChD,iBAAiB,EAAE,EAAE;IACrB,YAAY,EAAE;QACZ,aAAa,EAAE,IAAI;KACpB;IAED,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACjC,IAAI,CAAC;YACH,
|
|
1
|
+
{"version":3,"file":"keyword-generator.js","sourceRoot":"","sources":["../../src/ai/keyword-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kB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Aa,EAAE,MAAM,CAAC,QAAQ,CAAC,aAAa;iBAC7C;gBACD,WAAW;aACZ,CAAC;YAEF,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM;aACP,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B;aAC9E,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for bread node
|
|
4
|
+
*/
|
|
5
|
+
export declare const BreadInputSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
|
6
|
+
export type BreadInput = z.infer<typeof BreadInputSchema>;
|
|
7
|
+
/**
|
|
8
|
+
* Output schema for bread node
|
|
9
|
+
*/
|
|
10
|
+
export declare const BreadOutputSchema: z.ZodObject<{
|
|
11
|
+
message: z.ZodString;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
message: string;
|
|
14
|
+
}, {
|
|
15
|
+
message: string;
|
|
16
|
+
}>;
|
|
17
|
+
export type BreadOutput = z.infer<typeof BreadOutputSchema>;
|
|
18
|
+
/**
|
|
19
|
+
* Bread node - always outputs "bread"
|
|
20
|
+
*/
|
|
21
|
+
export declare const breadNode: import("@jam-nodes/core").NodeDefinition<{}, {
|
|
22
|
+
message: string;
|
|
23
|
+
}>;
|
|
24
|
+
//# sourceMappingURL=bread.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bread.d.ts","sourceRoot":"","sources":["../../src/examples/bread.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,eAAO,MAAM,gBAAgB,gDAAe,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;EAE5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,SAAS;;EAgBpB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineNode } from '@jam-nodes/core';
|
|
3
|
+
/**
|
|
4
|
+
* Input schema for bread node
|
|
5
|
+
*/
|
|
6
|
+
export const BreadInputSchema = z.object({});
|
|
7
|
+
/**
|
|
8
|
+
* Output schema for bread node
|
|
9
|
+
*/
|
|
10
|
+
export const BreadOutputSchema = z.object({
|
|
11
|
+
message: z.string(),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Bread node - always outputs "bread"
|
|
15
|
+
*/
|
|
16
|
+
export const breadNode = defineNode({
|
|
17
|
+
type: 'bread',
|
|
18
|
+
name: 'Bread',
|
|
19
|
+
description: 'Always outputs the string "bread"',
|
|
20
|
+
category: 'action', // or 'example' if that was a category, but 'action' fits best from core types
|
|
21
|
+
inputSchema: BreadInputSchema,
|
|
22
|
+
outputSchema: BreadOutputSchema,
|
|
23
|
+
estimatedDuration: 0,
|
|
24
|
+
executor: async () => {
|
|
25
|
+
return {
|
|
26
|
+
success: true,
|
|
27
|
+
output: {
|
|
28
|
+
message: 'bread',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=bread.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bread.js","sourceRoot":"","sources":["../../src/examples/bread.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAI7C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,CAAC;AAIH;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC;IAClC,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,mCAAmC;IAChD,QAAQ,EAAE,QAAQ,EAAE,8EAA8E;IAClG,WAAW,EAAE,gBAAgB;IAC7B,YAAY,EAAE,iBAAiB;IAC/B,iBAAiB,EAAE,CAAC;IACpB,QAAQ,EAAE,KAAK,IAAI,EAAE;QACnB,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE;gBACN,OAAO,EAAE,OAAO;aACjB;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/dist/examples/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { httpRequestNode } from './http-request.js';
|
|
2
2
|
export type { HttpRequestInput, HttpRequestOutput, HttpMethod } from './http-request.js';
|
|
3
3
|
export { HttpRequestInputSchema, HttpRequestOutputSchema, HttpMethodSchema, } from './http-request.js';
|
|
4
|
+
export { breadNode } from './bread.js';
|
|
5
|
+
export type { BreadInput, BreadOutput } from './bread.js';
|
|
6
|
+
export { BreadInputSchema, BreadOutputSchema } from './bread.js';
|
|
4
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/examples/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { httpRequestNode } from './http-request.js';
|
|
2
2
|
export { HttpRequestInputSchema, HttpRequestOutputSchema, HttpMethodSchema, } from './http-request.js';
|
|
3
|
+
export { breadNode } from './bread.js';
|
|
4
|
+
export { BreadInputSchema, BreadOutputSchema } from './bread.js';
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
|