spora 0.7.3 → 0.7.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/autonomy-DFPA3OK6.js +20 -0
- package/dist/{chunk-SUZUJGGW.js → chunk-342ZX72W.js} +4 -4
- package/dist/{chunk-HGNMHGAF.js → chunk-5R4AJZHN.js} +4 -4
- package/dist/{chunk-HGNMHGAF.js.map → chunk-5R4AJZHN.js.map} +1 -1
- package/dist/{chunk-Q3YXJ2C6.js → chunk-A2XTKC7B.js} +281 -65
- package/dist/chunk-A2XTKC7B.js.map +1 -0
- package/dist/{chunk-JBYZ7K56.js → chunk-BBXHECZ5.js} +2 -2
- package/dist/{chunk-WN35MRMF.js → chunk-CAWWG3MD.js} +2 -2
- package/dist/chunk-CP6JWCLY.js +171 -0
- package/dist/chunk-CP6JWCLY.js.map +1 -0
- package/dist/{chunk-T7L2L7ZL.js → chunk-D47OFTEK.js} +2 -2
- package/dist/chunk-HXI2EH5C.js +2338 -0
- package/dist/chunk-HXI2EH5C.js.map +1 -0
- package/dist/{chunk-M6YOQVSI.js → chunk-IULO3GRE.js} +4 -4
- package/dist/chunk-IULO3GRE.js.map +1 -0
- package/dist/chunk-OTZNHIXT.js +431 -0
- package/dist/chunk-OTZNHIXT.js.map +1 -0
- package/dist/{chunk-NO3NQN67.js → chunk-QYFNAGNI.js} +2 -2
- package/dist/{chunk-YMGJQRKG.js → chunk-RSNEVBEI.js} +2 -2
- package/dist/{chunk-VZBHRUZS.js → chunk-SXNZVKLJ.js} +2 -2
- package/dist/chunk-SXNZVKLJ.js.map +1 -0
- package/dist/{chunk-7OOGNZBU.js → chunk-ZLSDFYBR.js} +17 -5
- package/dist/chunk-ZLSDFYBR.js.map +1 -0
- package/dist/{chunk-3RYCUGXE.js → chunk-ZWKTKWS6.js} +4 -1
- package/dist/chunk-ZWKTKWS6.js.map +1 -0
- package/dist/cli.js +49 -49
- package/dist/{client-4KGOBIXE.js → client-AR5ZD6S4.js} +48 -16
- package/dist/client-AR5ZD6S4.js.map +1 -0
- package/dist/{colony-IVYR233C.js → colony-UGVYALOS.js} +7 -7
- package/dist/{config-FL4VJVKZ.js → config-MU2ODEO3.js} +3 -3
- package/dist/{crypto-NOXNL4GP.js → crypto-GDG5K3ZH.js} +3 -3
- package/dist/{goals-RBKLMILE.js → goals-QWX3A47Y.js} +3 -3
- package/dist/{heartbeat-CUL2FTFD.js → heartbeat-RAOEIKWC.js} +18 -21
- package/dist/heartbeat-RAOEIKWC.js.map +1 -0
- package/dist/{identity-VDUW4I2K.js → identity-ASHVWIN5.js} +3 -3
- package/dist/{init-2REECUVH.js → init-ETUTFHT6.js} +59 -13
- package/dist/init-ETUTFHT6.js.map +1 -0
- package/dist/{llm-OGOYCWBH.js → llm-IJBRQ7O2.js} +5 -5
- package/dist/mcp-server.js +24 -24
- package/dist/{memory-PNW7SX7A.js → memory-AWKIW2KW.js} +3 -3
- package/dist/{memory-OIAH33G2.js → memory-DTSLVSQG.js} +3 -3
- package/dist/{paths-BYR6MEPR.js → paths-4V5OCB5F.js} +2 -2
- package/dist/prompt-builder-XJHXZCSQ.js +27 -0
- package/dist/queue-QCGNDHH2.js +14 -0
- package/dist/strategy-R2BMRVJ3.js +19 -0
- package/dist/web-chat/chat.html +190 -3
- package/dist/{web-chat-O24HGJVE.js → web-chat-TB3ACPVF.js} +125 -32
- package/dist/web-chat-TB3ACPVF.js.map +1 -0
- package/dist/x-client-S2LUVEKV.js +12 -0
- package/package.json +1 -1
- package/dist/autonomy-6UWPXTPD.js +0 -19
- package/dist/chunk-3RYCUGXE.js.map +0 -1
- package/dist/chunk-4LNMA56H.js +0 -57
- package/dist/chunk-4LNMA56H.js.map +0 -1
- package/dist/chunk-7OOGNZBU.js.map +0 -1
- package/dist/chunk-M6YOQVSI.js.map +0 -1
- package/dist/chunk-P6KZIJYL.js +0 -79
- package/dist/chunk-P6KZIJYL.js.map +0 -1
- package/dist/chunk-Q3YXJ2C6.js.map +0 -1
- package/dist/chunk-VZBHRUZS.js.map +0 -1
- package/dist/chunk-ZBP2ROAZ.js +0 -377
- package/dist/chunk-ZBP2ROAZ.js.map +0 -1
- package/dist/client-4KGOBIXE.js.map +0 -1
- package/dist/heartbeat-CUL2FTFD.js.map +0 -1
- package/dist/init-2REECUVH.js.map +0 -1
- package/dist/prompt-builder-KJKFCGM7.js +0 -25
- package/dist/queue-D3MRKABU.js +0 -14
- package/dist/strategy-Z4JSFHSP.js +0 -12
- package/dist/web-chat-O24HGJVE.js.map +0 -1
- package/dist/x-client-ASXVQ6EV.js +0 -12
- /package/dist/{autonomy-6UWPXTPD.js.map → autonomy-DFPA3OK6.js.map} +0 -0
- /package/dist/{chunk-SUZUJGGW.js.map → chunk-342ZX72W.js.map} +0 -0
- /package/dist/{chunk-JBYZ7K56.js.map → chunk-BBXHECZ5.js.map} +0 -0
- /package/dist/{chunk-WN35MRMF.js.map → chunk-CAWWG3MD.js.map} +0 -0
- /package/dist/{chunk-T7L2L7ZL.js.map → chunk-D47OFTEK.js.map} +0 -0
- /package/dist/{chunk-NO3NQN67.js.map → chunk-QYFNAGNI.js.map} +0 -0
- /package/dist/{chunk-YMGJQRKG.js.map → chunk-RSNEVBEI.js.map} +0 -0
- /package/dist/{colony-IVYR233C.js.map → colony-UGVYALOS.js.map} +0 -0
- /package/dist/{config-FL4VJVKZ.js.map → config-MU2ODEO3.js.map} +0 -0
- /package/dist/{crypto-NOXNL4GP.js.map → crypto-GDG5K3ZH.js.map} +0 -0
- /package/dist/{goals-RBKLMILE.js.map → goals-QWX3A47Y.js.map} +0 -0
- /package/dist/{identity-VDUW4I2K.js.map → identity-ASHVWIN5.js.map} +0 -0
- /package/dist/{llm-OGOYCWBH.js.map → llm-IJBRQ7O2.js.map} +0 -0
- /package/dist/{memory-OIAH33G2.js.map → memory-AWKIW2KW.js.map} +0 -0
- /package/dist/{memory-PNW7SX7A.js.map → memory-DTSLVSQG.js.map} +0 -0
- /package/dist/{paths-BYR6MEPR.js.map → paths-4V5OCB5F.js.map} +0 -0
- /package/dist/{prompt-builder-KJKFCGM7.js.map → prompt-builder-XJHXZCSQ.js.map} +0 -0
- /package/dist/{queue-D3MRKABU.js.map → queue-QCGNDHH2.js.map} +0 -0
- /package/dist/{strategy-Z4JSFHSP.js.map → strategy-R2BMRVJ3.js.map} +0 -0
- /package/dist/{x-client-ASXVQ6EV.js.map → x-client-S2LUVEKV.js.map} +0 -0
package/dist/chunk-ZBP2ROAZ.js
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getXClient
|
|
3
|
-
} from "./chunk-HGNMHGAF.js";
|
|
4
|
-
import {
|
|
5
|
-
addToQueue
|
|
6
|
-
} from "./chunk-7OOGNZBU.js";
|
|
7
|
-
import {
|
|
8
|
-
buildSystemPrompt,
|
|
9
|
-
buildToolDecisionMessage
|
|
10
|
-
} from "./chunk-Q3YXJ2C6.js";
|
|
11
|
-
import {
|
|
12
|
-
loadIdentity,
|
|
13
|
-
saveIdentity
|
|
14
|
-
} from "./chunk-M6YOQVSI.js";
|
|
15
|
-
import {
|
|
16
|
-
generateResponse
|
|
17
|
-
} from "./chunk-SUZUJGGW.js";
|
|
18
|
-
import {
|
|
19
|
-
logger
|
|
20
|
-
} from "./chunk-YMGJQRKG.js";
|
|
21
|
-
import {
|
|
22
|
-
addLearning,
|
|
23
|
-
getRecentInteractions
|
|
24
|
-
} from "./chunk-JBYZ7K56.js";
|
|
25
|
-
|
|
26
|
-
// src/runtime/decision-engine.ts
|
|
27
|
-
function parseActions(llmResponse) {
|
|
28
|
-
const codeBlockMatch = llmResponse.match(/```(?:json)?\s*\n?([\s\S]*?)```/);
|
|
29
|
-
if (codeBlockMatch) {
|
|
30
|
-
const inside = codeBlockMatch[1].trim();
|
|
31
|
-
try {
|
|
32
|
-
const parsed = JSON.parse(inside);
|
|
33
|
-
return Array.isArray(parsed) ? parsed : [parsed];
|
|
34
|
-
} catch {
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
let lastArrayStart = -1;
|
|
38
|
-
let lastArrayEnd = -1;
|
|
39
|
-
let depth = 0;
|
|
40
|
-
for (let i = 0; i < llmResponse.length; i++) {
|
|
41
|
-
if (llmResponse[i] === "[") {
|
|
42
|
-
if (depth === 0) lastArrayStart = i;
|
|
43
|
-
depth++;
|
|
44
|
-
} else if (llmResponse[i] === "]") {
|
|
45
|
-
depth--;
|
|
46
|
-
if (depth === 0) lastArrayEnd = i;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (lastArrayStart >= 0 && lastArrayEnd > lastArrayStart) {
|
|
50
|
-
const arrayStr = llmResponse.slice(lastArrayStart, lastArrayEnd + 1);
|
|
51
|
-
try {
|
|
52
|
-
const parsed = JSON.parse(arrayStr);
|
|
53
|
-
if (Array.isArray(parsed) && parsed.length > 0 && parsed[0].action) {
|
|
54
|
-
return parsed;
|
|
55
|
-
}
|
|
56
|
-
} catch {
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const objMatches = [...llmResponse.matchAll(/\{[^{}]*"action"\s*:\s*"[^"]+"/g)];
|
|
60
|
-
if (objMatches.length > 0) {
|
|
61
|
-
for (let i = objMatches.length - 1; i >= 0; i--) {
|
|
62
|
-
const start = objMatches[i].index;
|
|
63
|
-
let braceDepth = 0;
|
|
64
|
-
let end = -1;
|
|
65
|
-
for (let j = start; j < llmResponse.length; j++) {
|
|
66
|
-
if (llmResponse[j] === "{") braceDepth++;
|
|
67
|
-
else if (llmResponse[j] === "}") {
|
|
68
|
-
braceDepth--;
|
|
69
|
-
if (braceDepth === 0) {
|
|
70
|
-
end = j;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (end > start) {
|
|
76
|
-
try {
|
|
77
|
-
const obj = JSON.parse(llmResponse.slice(start, end + 1));
|
|
78
|
-
if (obj.action) return [obj];
|
|
79
|
-
} catch {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
const parsed = JSON.parse(llmResponse.trim());
|
|
87
|
-
if (Array.isArray(parsed)) return parsed;
|
|
88
|
-
if (parsed.action) return [parsed];
|
|
89
|
-
} catch {
|
|
90
|
-
}
|
|
91
|
-
logger.warn("Failed to parse actions from LLM response");
|
|
92
|
-
if (llmResponse.length < 500) {
|
|
93
|
-
logger.warn(`Response was: ${llmResponse}`);
|
|
94
|
-
} else {
|
|
95
|
-
logger.warn(`Response starts with: ${llmResponse.slice(0, 200)}...`);
|
|
96
|
-
}
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
async function executeAction(action) {
|
|
100
|
-
const { action: type } = action;
|
|
101
|
-
try {
|
|
102
|
-
switch (type) {
|
|
103
|
-
case "post": {
|
|
104
|
-
if (!action.content) return { action: type, success: false, error: "No content provided" };
|
|
105
|
-
if (action.content.length > 280) {
|
|
106
|
-
return { action: type, success: false, error: `Tweet too long: ${action.content.length} chars (max 280)` };
|
|
107
|
-
}
|
|
108
|
-
const client = await getXClient();
|
|
109
|
-
const result = await client.postTweet(action.content);
|
|
110
|
-
if (result.success) logger.info(`Posted: "${action.content.slice(0, 50)}..."`);
|
|
111
|
-
return { action: type, success: result.success, detail: result.tweetId, error: result.error };
|
|
112
|
-
}
|
|
113
|
-
case "reply": {
|
|
114
|
-
if (!action.tweetId || !action.content) {
|
|
115
|
-
return { action: type, success: false, error: "Missing tweetId or content" };
|
|
116
|
-
}
|
|
117
|
-
const client = await getXClient();
|
|
118
|
-
const result = await client.replyToTweet(action.tweetId, action.content);
|
|
119
|
-
if (result.success) logger.info(`Replied to ${action.tweetId}: "${action.content.slice(0, 50)}..."`);
|
|
120
|
-
return { action: type, success: result.success, detail: result.tweetId, error: result.error };
|
|
121
|
-
}
|
|
122
|
-
case "like": {
|
|
123
|
-
if (!action.tweetId) return { action: type, success: false, error: "Missing tweetId" };
|
|
124
|
-
const client = await getXClient();
|
|
125
|
-
const result = await client.likeTweet(action.tweetId);
|
|
126
|
-
return { action: type, success: result.success, error: result.error };
|
|
127
|
-
}
|
|
128
|
-
case "retweet": {
|
|
129
|
-
if (!action.tweetId) return { action: type, success: false, error: "Missing tweetId" };
|
|
130
|
-
const client = await getXClient();
|
|
131
|
-
const result = await client.retweet(action.tweetId);
|
|
132
|
-
return { action: type, success: result.success, error: result.error };
|
|
133
|
-
}
|
|
134
|
-
case "follow": {
|
|
135
|
-
if (!action.handle) return { action: type, success: false, error: "Missing handle" };
|
|
136
|
-
const client = await getXClient();
|
|
137
|
-
const result = await client.followUser(action.handle);
|
|
138
|
-
return { action: type, success: result.success, error: result.error };
|
|
139
|
-
}
|
|
140
|
-
case "schedule": {
|
|
141
|
-
if (!action.content) return { action: type, success: false, error: "No content" };
|
|
142
|
-
const entry = addToQueue(action.content);
|
|
143
|
-
logger.info(`Scheduled: "${action.content.slice(0, 50)}..." for ${entry.scheduledFor}`);
|
|
144
|
-
return { action: type, success: true, detail: `Scheduled for ${entry.scheduledFor}` };
|
|
145
|
-
}
|
|
146
|
-
case "learn": {
|
|
147
|
-
if (!action.content) return { action: type, success: false, error: "No content" };
|
|
148
|
-
addLearning(action.content, "agent", action.tags ?? ["heartbeat"]);
|
|
149
|
-
logger.info(`Learned: "${action.content.slice(0, 50)}..."`);
|
|
150
|
-
return { action: type, success: true };
|
|
151
|
-
}
|
|
152
|
-
case "reflect": {
|
|
153
|
-
if (!action.content) return { action: type, success: false, error: "No content" };
|
|
154
|
-
const identity = loadIdentity();
|
|
155
|
-
identity.evolutionJournal.push({
|
|
156
|
-
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
157
|
-
reflection: action.content
|
|
158
|
-
});
|
|
159
|
-
saveIdentity(identity);
|
|
160
|
-
logger.info(`Reflected: "${action.content.slice(0, 50)}..."`);
|
|
161
|
-
return { action: type, success: true };
|
|
162
|
-
}
|
|
163
|
-
case "skip": {
|
|
164
|
-
logger.info(`Skipping: ${action.reason ?? action.reasoning ?? "no reason given"}`);
|
|
165
|
-
return { action: type, success: true, detail: action.reason ?? action.reasoning };
|
|
166
|
-
}
|
|
167
|
-
default:
|
|
168
|
-
logger.warn(`Unknown action: ${type}`);
|
|
169
|
-
return { action: type, success: false, error: `Unknown action: ${type}` };
|
|
170
|
-
}
|
|
171
|
-
} catch (error) {
|
|
172
|
-
const msg = error.message;
|
|
173
|
-
logger.error(`Action ${type} failed: ${msg}`);
|
|
174
|
-
return { action: type, success: false, error: msg };
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/runtime/policy.ts
|
|
179
|
-
function normalize(text) {
|
|
180
|
-
return text.toLowerCase().replace(/https?:\/\/\S+/g, "").replace(/[@#]\w+/g, "").replace(/[^a-z0-9\s]/g, " ").replace(/\s+/g, " ").trim();
|
|
181
|
-
}
|
|
182
|
-
function tokenSet(text) {
|
|
183
|
-
const tokens = normalize(text).split(" ").filter(Boolean);
|
|
184
|
-
return new Set(tokens);
|
|
185
|
-
}
|
|
186
|
-
function jaccardSimilarity(a, b) {
|
|
187
|
-
const aSet = tokenSet(a);
|
|
188
|
-
const bSet = tokenSet(b);
|
|
189
|
-
if (aSet.size === 0 || bSet.size === 0) return 0;
|
|
190
|
-
let overlap = 0;
|
|
191
|
-
for (const token of aSet) {
|
|
192
|
-
if (bSet.has(token)) overlap += 1;
|
|
193
|
-
}
|
|
194
|
-
const union = aSet.size + bSet.size - overlap;
|
|
195
|
-
return union === 0 ? 0 : overlap / union;
|
|
196
|
-
}
|
|
197
|
-
function firstWords(text, n) {
|
|
198
|
-
return normalize(text).split(" ").filter(Boolean).slice(0, n).join(" ");
|
|
199
|
-
}
|
|
200
|
-
function hasAllCapsEnding(text) {
|
|
201
|
-
const ending = text.split(/[.!?]/).map((s) => s.trim()).filter(Boolean).slice(-1)[0] ?? "";
|
|
202
|
-
const words = ending.split(/\s+/).filter(Boolean);
|
|
203
|
-
if (words.length < 3) return false;
|
|
204
|
-
return words.every((word) => /^[A-Z0-9]+$/.test(word));
|
|
205
|
-
}
|
|
206
|
-
function recentWrittenContent() {
|
|
207
|
-
const recent = getRecentInteractions(40);
|
|
208
|
-
return recent.filter((i) => i.type === "post" || i.type === "reply").map((i) => i.content ?? "").filter((content) => content.length > 0);
|
|
209
|
-
}
|
|
210
|
-
function hasStrongConversationOpportunity(timeline, mentions) {
|
|
211
|
-
if (mentions.length > 0) return true;
|
|
212
|
-
return timeline.some((tweet) => (tweet.replyCount ?? 0) > 0 || tweet.text.includes("?"));
|
|
213
|
-
}
|
|
214
|
-
function wasInteractionAction(action) {
|
|
215
|
-
return ["reply", "like", "retweet", "follow"].includes(action.action);
|
|
216
|
-
}
|
|
217
|
-
function isWritingAction(action) {
|
|
218
|
-
return ["post", "reply", "schedule"].includes(action.action);
|
|
219
|
-
}
|
|
220
|
-
function executedWrittenContent(executedActions) {
|
|
221
|
-
return executedActions.filter((a) => isWritingAction(a) && typeof a.content === "string").map((a) => a.content?.trim() ?? "").filter((content) => content.length > 0);
|
|
222
|
-
}
|
|
223
|
-
function nearExactDuplicate(content, recent) {
|
|
224
|
-
const normalized = normalize(content);
|
|
225
|
-
if (!normalized) return false;
|
|
226
|
-
return recent.some((r) => {
|
|
227
|
-
const candidate = normalize(r);
|
|
228
|
-
if (!candidate) return false;
|
|
229
|
-
if (candidate === normalized) return true;
|
|
230
|
-
return jaccardSimilarity(content, r) >= 0.88;
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
function isDuplicateTarget(action, executedActions) {
|
|
234
|
-
if (!action.tweetId) return false;
|
|
235
|
-
return executedActions.some((a) => a.tweetId === action.tweetId && a.action === action.action);
|
|
236
|
-
}
|
|
237
|
-
function repeatedTemplate(content, recent) {
|
|
238
|
-
const prefix = firstWords(content, 7);
|
|
239
|
-
if (!prefix) return false;
|
|
240
|
-
return recent.some((r) => {
|
|
241
|
-
const sameStart = firstWords(r, 7) === prefix;
|
|
242
|
-
const similar = jaccardSimilarity(content, r) >= 0.62;
|
|
243
|
-
return sameStart || similar;
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
function overusingAllCapsCadence(content, recentEntries) {
|
|
247
|
-
if (!hasAllCapsEnding(content)) return false;
|
|
248
|
-
const recentCaps = recentEntries.filter((i) => i.type === "post" && i.content).slice(0, 8).filter((i) => hasAllCapsEnding(i.content ?? ""));
|
|
249
|
-
return recentCaps.length >= 2;
|
|
250
|
-
}
|
|
251
|
-
function evaluateActionPolicy(context) {
|
|
252
|
-
const { action, step, timeline, mentions, executedActions } = context;
|
|
253
|
-
if (isDuplicateTarget(action, executedActions)) {
|
|
254
|
-
return { allowed: false, reason: `Action ${action.action} already executed for tweet ${action.tweetId} this heartbeat.` };
|
|
255
|
-
}
|
|
256
|
-
if (action.content && isWritingAction(action)) {
|
|
257
|
-
const existingInHeartbeat = executedWrittenContent(executedActions);
|
|
258
|
-
if (nearExactDuplicate(action.content, existingInHeartbeat)) {
|
|
259
|
-
return {
|
|
260
|
-
allowed: false,
|
|
261
|
-
reason: "Rejected duplicate wording in this heartbeat. Write a distinct message before posting/replying again."
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
const hasConversationOpportunity = hasStrongConversationOpportunity(timeline, mentions);
|
|
266
|
-
const interactedAlready = executedActions.some(wasInteractionAction);
|
|
267
|
-
if (action.action === "post" && hasConversationOpportunity && !interactedAlready && step < 2) {
|
|
268
|
-
return {
|
|
269
|
-
allowed: false,
|
|
270
|
-
reason: "Engage first: reply/like/follow when mentions or active conversations are available before posting an original tweet."
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
if (isWritingAction(action) && action.content) {
|
|
274
|
-
const recent = recentWrittenContent();
|
|
275
|
-
if (nearExactDuplicate(action.content, recent)) {
|
|
276
|
-
return {
|
|
277
|
-
allowed: false,
|
|
278
|
-
reason: "Rejected near-duplicate content from recent history. Tailor this message to the specific context."
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
if (repeatedTemplate(action.content, recent)) {
|
|
282
|
-
return {
|
|
283
|
-
allowed: false,
|
|
284
|
-
reason: "Rejected repetitive content pattern. Use a more novel structure or engage directly with timeline context."
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if ((action.action === "post" || action.action === "schedule") && action.content) {
|
|
289
|
-
const recentInteractions = getRecentInteractions(20);
|
|
290
|
-
if (overusingAllCapsCadence(action.content, recentInteractions)) {
|
|
291
|
-
return {
|
|
292
|
-
allowed: false,
|
|
293
|
-
reason: "Rejected repetitive all-caps slogan cadence. Vary style and reduce monologue formatting."
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if ((action.action === "reply" || action.action === "like" || action.action === "retweet") && action.tweetId) {
|
|
298
|
-
const known = new Set([...timeline, ...mentions].map((tweet) => tweet.id));
|
|
299
|
-
if (!known.has(action.tweetId)) {
|
|
300
|
-
return {
|
|
301
|
-
allowed: false,
|
|
302
|
-
reason: `Tweet ${action.tweetId} is not in current observations. Choose a visible timeline/mention tweet for grounded engagement.`
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return { allowed: true };
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// src/runtime/autonomy.ts
|
|
310
|
-
async function runAutonomyCycle(maxActions) {
|
|
311
|
-
const client = await getXClient();
|
|
312
|
-
let timeline = [];
|
|
313
|
-
let mentions = [];
|
|
314
|
-
try {
|
|
315
|
-
timeline = await client.getTimeline({ count: 20 });
|
|
316
|
-
} catch (error) {
|
|
317
|
-
logger.warn(`Timeline read failed: ${error.message}`);
|
|
318
|
-
}
|
|
319
|
-
try {
|
|
320
|
-
mentions = await client.getMentions({ count: 10 });
|
|
321
|
-
} catch (error) {
|
|
322
|
-
logger.warn(`Mentions read failed: ${error.message}`);
|
|
323
|
-
}
|
|
324
|
-
const systemPrompt = buildSystemPrompt();
|
|
325
|
-
const actions = [];
|
|
326
|
-
const results = [];
|
|
327
|
-
const policyFeedback = [];
|
|
328
|
-
getRecentInteractions(20);
|
|
329
|
-
for (let step = 0; step < maxActions; step += 1) {
|
|
330
|
-
const decisionPrompt = buildToolDecisionMessage({
|
|
331
|
-
step,
|
|
332
|
-
maxActions,
|
|
333
|
-
timeline,
|
|
334
|
-
mentions,
|
|
335
|
-
executedActions: actions,
|
|
336
|
-
policyFeedback
|
|
337
|
-
});
|
|
338
|
-
const llmResponse = await generateResponse(systemPrompt, decisionPrompt);
|
|
339
|
-
const parsed = parseActions(llmResponse.content);
|
|
340
|
-
const proposedAction = parsed[0];
|
|
341
|
-
if (!proposedAction) {
|
|
342
|
-
logger.info("Planner returned no actionable tool call.");
|
|
343
|
-
break;
|
|
344
|
-
}
|
|
345
|
-
const policy = evaluateActionPolicy({
|
|
346
|
-
action: proposedAction,
|
|
347
|
-
step,
|
|
348
|
-
timeline,
|
|
349
|
-
mentions,
|
|
350
|
-
executedActions: actions
|
|
351
|
-
});
|
|
352
|
-
if (!policy.allowed) {
|
|
353
|
-
const reason = policy.reason ?? "Policy rejected action";
|
|
354
|
-
policyFeedback.push(reason);
|
|
355
|
-
logger.info(`Policy rejected action ${proposedAction.action}: ${reason}`);
|
|
356
|
-
continue;
|
|
357
|
-
}
|
|
358
|
-
const result = await executeAction(proposedAction);
|
|
359
|
-
actions.push(proposedAction);
|
|
360
|
-
results.push(result);
|
|
361
|
-
if (proposedAction.action === "skip") {
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return {
|
|
366
|
-
timeline,
|
|
367
|
-
mentions,
|
|
368
|
-
actions,
|
|
369
|
-
results,
|
|
370
|
-
policyFeedback
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export {
|
|
375
|
-
runAutonomyCycle
|
|
376
|
-
};
|
|
377
|
-
//# sourceMappingURL=chunk-ZBP2ROAZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime/decision-engine.ts","../src/runtime/policy.ts","../src/runtime/autonomy.ts"],"sourcesContent":["import { logger } from \"../utils/logger.js\";\nimport { getXClient } from \"../x-client/index.js\";\nimport { addLearning } from \"../memory/index.js\";\nimport { loadIdentity, saveIdentity } from \"../identity/index.js\";\nimport { addToQueue } from \"../scheduler/queue.js\";\n\nexport interface AgentAction {\n action: string;\n content?: string;\n tweetId?: string;\n handle?: string;\n tags?: string[];\n reason?: string;\n reasoning?: string;\n}\n\nexport interface ActionResult {\n action: string;\n success: boolean;\n detail?: string;\n error?: string;\n}\n\nexport function parseActions(llmResponse: string): AgentAction[] {\n // Strategy: try multiple extraction approaches, most specific first\n\n // 1. Try markdown code block first (```json ... ``` or ``` ... ```)\n const codeBlockMatch = llmResponse.match(/```(?:json)?\\s*\\n?([\\s\\S]*?)```/);\n if (codeBlockMatch) {\n const inside = codeBlockMatch[1].trim();\n try {\n const parsed = JSON.parse(inside);\n return Array.isArray(parsed) ? parsed : [parsed];\n } catch {\n // Code block content wasn't valid JSON, continue to other strategies\n }\n }\n\n // 2. Find the last JSON array in the response (LLMs often put reasoning before the array)\n // Use a greedy approach to find the outermost array brackets\n let lastArrayStart = -1;\n let lastArrayEnd = -1;\n let depth = 0;\n for (let i = 0; i < llmResponse.length; i++) {\n if (llmResponse[i] === \"[\") {\n if (depth === 0) lastArrayStart = i;\n depth++;\n } else if (llmResponse[i] === \"]\") {\n depth--;\n if (depth === 0) lastArrayEnd = i;\n }\n }\n\n if (lastArrayStart >= 0 && lastArrayEnd > lastArrayStart) {\n const arrayStr = llmResponse.slice(lastArrayStart, lastArrayEnd + 1);\n try {\n const parsed = JSON.parse(arrayStr);\n if (Array.isArray(parsed) && parsed.length > 0 && parsed[0].action) {\n return parsed;\n }\n } catch {\n // Not valid JSON array, try next strategy\n }\n }\n\n // 3. Try to find a single action object (last one in the response)\n const objMatches = [...llmResponse.matchAll(/\\{[^{}]*\"action\"\\s*:\\s*\"[^\"]+\"/g)];\n if (objMatches.length > 0) {\n // Find the full object starting from this match\n for (let i = objMatches.length - 1; i >= 0; i--) {\n const start = objMatches[i].index!;\n let braceDepth = 0;\n let end = -1;\n for (let j = start; j < llmResponse.length; j++) {\n if (llmResponse[j] === \"{\") braceDepth++;\n else if (llmResponse[j] === \"}\") {\n braceDepth--;\n if (braceDepth === 0) { end = j; break; }\n }\n }\n if (end > start) {\n try {\n const obj = JSON.parse(llmResponse.slice(start, end + 1));\n if (obj.action) return [obj as AgentAction];\n } catch {\n continue;\n }\n }\n }\n }\n\n // 4. Last resort: try the whole response as JSON\n try {\n const parsed = JSON.parse(llmResponse.trim());\n if (Array.isArray(parsed)) return parsed;\n if (parsed.action) return [parsed as AgentAction];\n } catch {\n // Not JSON at all\n }\n\n logger.warn(\"Failed to parse actions from LLM response\");\n if (llmResponse.length < 500) {\n logger.warn(`Response was: ${llmResponse}`);\n } else {\n logger.warn(`Response starts with: ${llmResponse.slice(0, 200)}...`);\n }\n return [];\n}\n\nexport async function executeAction(action: AgentAction): Promise<ActionResult> {\n const { action: type } = action;\n\n try {\n switch (type) {\n case \"post\": {\n if (!action.content) return { action: type, success: false, error: \"No content provided\" };\n if (action.content.length > 280) {\n return { action: type, success: false, error: `Tweet too long: ${action.content.length} chars (max 280)` };\n }\n\n const client = await getXClient();\n const result = await client.postTweet(action.content);\n if (result.success) logger.info(`Posted: \"${action.content.slice(0, 50)}...\"`);\n return { action: type, success: result.success, detail: result.tweetId, error: result.error };\n }\n\n case \"reply\": {\n if (!action.tweetId || !action.content) {\n return { action: type, success: false, error: \"Missing tweetId or content\" };\n }\n const client = await getXClient();\n const result = await client.replyToTweet(action.tweetId, action.content);\n if (result.success) logger.info(`Replied to ${action.tweetId}: \"${action.content.slice(0, 50)}...\"`);\n return { action: type, success: result.success, detail: result.tweetId, error: result.error };\n }\n\n case \"like\": {\n if (!action.tweetId) return { action: type, success: false, error: \"Missing tweetId\" };\n const client = await getXClient();\n const result = await client.likeTweet(action.tweetId);\n return { action: type, success: result.success, error: result.error };\n }\n\n case \"retweet\": {\n if (!action.tweetId) return { action: type, success: false, error: \"Missing tweetId\" };\n const client = await getXClient();\n const result = await client.retweet(action.tweetId);\n return { action: type, success: result.success, error: result.error };\n }\n\n case \"follow\": {\n if (!action.handle) return { action: type, success: false, error: \"Missing handle\" };\n const client = await getXClient();\n const result = await client.followUser(action.handle);\n return { action: type, success: result.success, error: result.error };\n }\n\n case \"schedule\": {\n if (!action.content) return { action: type, success: false, error: \"No content\" };\n const entry = addToQueue(action.content);\n logger.info(`Scheduled: \"${action.content.slice(0, 50)}...\" for ${entry.scheduledFor}`);\n return { action: type, success: true, detail: `Scheduled for ${entry.scheduledFor}` };\n }\n\n case \"learn\": {\n if (!action.content) return { action: type, success: false, error: \"No content\" };\n addLearning(action.content, \"agent\", action.tags ?? [\"heartbeat\"]);\n logger.info(`Learned: \"${action.content.slice(0, 50)}...\"`);\n return { action: type, success: true };\n }\n\n case \"reflect\": {\n if (!action.content) return { action: type, success: false, error: \"No content\" };\n const identity = loadIdentity();\n identity.evolutionJournal.push({\n date: new Date().toISOString(),\n reflection: action.content,\n });\n saveIdentity(identity);\n logger.info(`Reflected: \"${action.content.slice(0, 50)}...\"`);\n return { action: type, success: true };\n }\n\n case \"skip\": {\n logger.info(`Skipping: ${action.reason ?? action.reasoning ?? \"no reason given\"}`);\n return { action: type, success: true, detail: action.reason ?? action.reasoning };\n }\n\n default:\n logger.warn(`Unknown action: ${type}`);\n return { action: type, success: false, error: `Unknown action: ${type}` };\n }\n } catch (error) {\n const msg = (error as Error).message;\n logger.error(`Action ${type} failed: ${msg}`);\n return { action: type, success: false, error: msg };\n }\n}\n\nexport async function executeActions(actions: AgentAction[]): Promise<ActionResult[]> {\n const results: ActionResult[] = [];\n for (const action of actions) {\n const result = await executeAction(action);\n results.push(result);\n // Small delay between actions to be human-like\n await new Promise((r) => setTimeout(r, 2000 + Math.random() * 3000));\n }\n return results;\n}\n","import { getRecentInteractions, type InteractionEntry } from \"../memory/index.js\";\nimport type { Tweet } from \"../x-client/types.js\";\nimport type { AgentAction } from \"./decision-engine.js\";\n\nexport interface PolicyContext {\n action: AgentAction;\n step: number;\n timeline: Tweet[];\n mentions: Tweet[];\n executedActions: AgentAction[];\n}\n\nexport interface PolicyDecision {\n allowed: boolean;\n reason?: string;\n}\n\nfunction normalize(text: string): string {\n return text\n .toLowerCase()\n .replace(/https?:\\/\\/\\S+/g, \"\")\n .replace(/[@#]\\w+/g, \"\")\n .replace(/[^a-z0-9\\s]/g, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction tokenSet(text: string): Set<string> {\n const tokens = normalize(text).split(\" \").filter(Boolean);\n return new Set(tokens);\n}\n\nfunction jaccardSimilarity(a: string, b: string): number {\n const aSet = tokenSet(a);\n const bSet = tokenSet(b);\n if (aSet.size === 0 || bSet.size === 0) return 0;\n\n let overlap = 0;\n for (const token of aSet) {\n if (bSet.has(token)) overlap += 1;\n }\n\n const union = aSet.size + bSet.size - overlap;\n return union === 0 ? 0 : overlap / union;\n}\n\nfunction firstWords(text: string, n: number): string {\n return normalize(text).split(\" \").filter(Boolean).slice(0, n).join(\" \");\n}\n\nfunction hasAllCapsEnding(text: string): boolean {\n const ending = text.split(/[.!?]/).map((s) => s.trim()).filter(Boolean).slice(-1)[0] ?? \"\";\n const words = ending.split(/\\s+/).filter(Boolean);\n if (words.length < 3) return false;\n return words.every((word) => /^[A-Z0-9]+$/.test(word));\n}\n\nfunction recentWrittenContent(): string[] {\n const recent = getRecentInteractions(40);\n return recent\n .filter((i) => i.type === \"post\" || i.type === \"reply\")\n .map((i) => i.content ?? \"\")\n .filter((content) => content.length > 0);\n}\n\nfunction hasStrongConversationOpportunity(timeline: Tweet[], mentions: Tweet[]): boolean {\n if (mentions.length > 0) return true;\n return timeline.some((tweet) => (tweet.replyCount ?? 0) > 0 || tweet.text.includes(\"?\"));\n}\n\nfunction wasInteractionAction(action: AgentAction): boolean {\n return [\"reply\", \"like\", \"retweet\", \"follow\"].includes(action.action);\n}\n\nfunction isWritingAction(action: AgentAction): boolean {\n return [\"post\", \"reply\", \"schedule\"].includes(action.action);\n}\n\nfunction executedWrittenContent(executedActions: AgentAction[]): string[] {\n return executedActions\n .filter((a) => isWritingAction(a) && typeof a.content === \"string\")\n .map((a) => a.content?.trim() ?? \"\")\n .filter((content) => content.length > 0);\n}\n\nfunction nearExactDuplicate(content: string, recent: string[]): boolean {\n const normalized = normalize(content);\n if (!normalized) return false;\n\n return recent.some((r) => {\n const candidate = normalize(r);\n if (!candidate) return false;\n if (candidate === normalized) return true;\n return jaccardSimilarity(content, r) >= 0.88;\n });\n}\n\nfunction isDuplicateTarget(action: AgentAction, executedActions: AgentAction[]): boolean {\n if (!action.tweetId) return false;\n return executedActions.some((a) => a.tweetId === action.tweetId && a.action === action.action);\n}\n\nfunction repeatedTemplate(content: string, recent: string[]): boolean {\n const prefix = firstWords(content, 7);\n if (!prefix) return false;\n\n return recent.some((r) => {\n const sameStart = firstWords(r, 7) === prefix;\n const similar = jaccardSimilarity(content, r) >= 0.62;\n return sameStart || similar;\n });\n}\n\nfunction overusingAllCapsCadence(content: string, recentEntries: InteractionEntry[]): boolean {\n if (!hasAllCapsEnding(content)) return false;\n const recentCaps = recentEntries\n .filter((i) => i.type === \"post\" && i.content)\n .slice(0, 8)\n .filter((i) => hasAllCapsEnding(i.content ?? \"\"));\n\n return recentCaps.length >= 2;\n}\n\nexport function evaluateActionPolicy(context: PolicyContext): PolicyDecision {\n const { action, step, timeline, mentions, executedActions } = context;\n\n if (isDuplicateTarget(action, executedActions)) {\n return { allowed: false, reason: `Action ${action.action} already executed for tweet ${action.tweetId} this heartbeat.` };\n }\n\n if (action.content && isWritingAction(action)) {\n const existingInHeartbeat = executedWrittenContent(executedActions);\n if (nearExactDuplicate(action.content, existingInHeartbeat)) {\n return {\n allowed: false,\n reason: \"Rejected duplicate wording in this heartbeat. Write a distinct message before posting/replying again.\",\n };\n }\n }\n\n const hasConversationOpportunity = hasStrongConversationOpportunity(timeline, mentions);\n const interactedAlready = executedActions.some(wasInteractionAction);\n\n if (\n action.action === \"post\" &&\n hasConversationOpportunity &&\n !interactedAlready &&\n step < 2\n ) {\n return {\n allowed: false,\n reason: \"Engage first: reply/like/follow when mentions or active conversations are available before posting an original tweet.\",\n };\n }\n\n if (isWritingAction(action) && action.content) {\n const recent = recentWrittenContent();\n if (nearExactDuplicate(action.content, recent)) {\n return {\n allowed: false,\n reason: \"Rejected near-duplicate content from recent history. Tailor this message to the specific context.\",\n };\n }\n\n if (repeatedTemplate(action.content, recent)) {\n return {\n allowed: false,\n reason: \"Rejected repetitive content pattern. Use a more novel structure or engage directly with timeline context.\",\n };\n }\n }\n\n if ((action.action === \"post\" || action.action === \"schedule\") && action.content) {\n const recentInteractions = getRecentInteractions(20);\n if (overusingAllCapsCadence(action.content, recentInteractions)) {\n return {\n allowed: false,\n reason: \"Rejected repetitive all-caps slogan cadence. Vary style and reduce monologue formatting.\",\n };\n }\n }\n\n if ((action.action === \"reply\" || action.action === \"like\" || action.action === \"retweet\") && action.tweetId) {\n const known = new Set([...timeline, ...mentions].map((tweet) => tweet.id));\n if (!known.has(action.tweetId)) {\n return {\n allowed: false,\n reason: `Tweet ${action.tweetId} is not in current observations. Choose a visible timeline/mention tweet for grounded engagement.`,\n };\n }\n }\n\n return { allowed: true };\n}\n","import { getXClient } from \"../x-client/index.js\";\nimport { logger } from \"../utils/logger.js\";\nimport { getRecentInteractions } from \"../memory/index.js\";\nimport type { Tweet } from \"../x-client/types.js\";\nimport { buildSystemPrompt, buildToolDecisionMessage } from \"./prompt-builder.js\";\nimport { generateResponse } from \"./llm.js\";\nimport { parseActions, executeAction, type AgentAction, type ActionResult } from \"./decision-engine.js\";\nimport { evaluateActionPolicy } from \"./policy.js\";\n\nexport interface AutonomyCycleResult {\n timeline: Tweet[];\n mentions: Tweet[];\n actions: AgentAction[];\n results: ActionResult[];\n policyFeedback: string[];\n}\n\nexport async function runAutonomyCycle(maxActions: number): Promise<AutonomyCycleResult> {\n const client = await getXClient();\n\n let timeline: Tweet[] = [];\n let mentions: Tweet[] = [];\n\n try {\n timeline = await client.getTimeline({ count: 20 });\n } catch (error) {\n logger.warn(`Timeline read failed: ${(error as Error).message}`);\n }\n\n try {\n mentions = await client.getMentions({ count: 10 });\n } catch (error) {\n logger.warn(`Mentions read failed: ${(error as Error).message}`);\n }\n\n const systemPrompt = buildSystemPrompt();\n const actions: AgentAction[] = [];\n const results: ActionResult[] = [];\n const policyFeedback: string[] = [];\n\n // Keep short memory available in context by touching it before planner loop.\n getRecentInteractions(20);\n\n for (let step = 0; step < maxActions; step += 1) {\n const decisionPrompt = buildToolDecisionMessage({\n step,\n maxActions,\n timeline,\n mentions,\n executedActions: actions,\n policyFeedback,\n });\n\n const llmResponse = await generateResponse(systemPrompt, decisionPrompt);\n const parsed = parseActions(llmResponse.content);\n const proposedAction = parsed[0];\n\n if (!proposedAction) {\n logger.info(\"Planner returned no actionable tool call.\");\n break;\n }\n\n const policy = evaluateActionPolicy({\n action: proposedAction,\n step,\n timeline,\n mentions,\n executedActions: actions,\n });\n\n if (!policy.allowed) {\n const reason = policy.reason ?? \"Policy rejected action\";\n policyFeedback.push(reason);\n logger.info(`Policy rejected action ${proposedAction.action}: ${reason}`);\n continue;\n }\n\n const result = await executeAction(proposedAction);\n actions.push(proposedAction);\n results.push(result);\n\n if (proposedAction.action === \"skip\") {\n break;\n }\n }\n\n return {\n timeline,\n mentions,\n actions,\n results,\n policyFeedback,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAuBO,SAAS,aAAa,aAAoC;AAI/D,QAAM,iBAAiB,YAAY,MAAM,iCAAiC;AAC1E,MAAI,gBAAgB;AAClB,UAAM,SAAS,eAAe,CAAC,EAAE,KAAK;AACtC,QAAI;AACF,YAAM,SAAS,KAAK,MAAM,MAAM;AAChC,aAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AAAA,IACjD,QAAQ;AAAA,IAER;AAAA,E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AE;AAExB,WAAS,OAAO,GAAG,OAAO,YAAY,QAAQ,GAAG;AAC/C,UAAM,iBAAiB,yBAAyB;AAAA,MAC9C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,iBAAiB;AAAA,MACjB;AAAA,IACF,CAAC;AAED,UAAM,cAAc,MAAM,iBAAiB,cAAc,cAAc;AACvE,UAAM,SAAS,aAAa,YAAY,OAAO;AAC/C,UAAM,iBAAiB,OAAO,CAAC;AAE/B,QAAI,CAAC,gBAAgB;AACnB,aAAO,KAAK,2CAA2C;AACvD;AAAA,IACF;AAEA,UAAM,SAAS,qBAAqB;AAAA,MAClC,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA,iBAAiB;AAAA,IACnB,CAAC;AAED,QAAI,CAAC,OAAO,SAAS;AACnB,YAAM,SAAS,OAAO,UAAU;AAChC,qBAAe,KAAK,MAAM;AAC1B,aAAO,KAAK,0BAA0B,eAAe,MAAM,KAAK,MAAM,EAAE;AACxE;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,cAAc,cAAc;AACjD,YAAQ,KAAK,cAAc;AAC3B,YAAQ,KAAK,MAAM;AAEnB,QAAI,eAAe,WAAW,QAAQ;AACpC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/x-client/api/client.ts"],"sourcesContent":["import { TwitterApi } from \"twitter-api-v2\";\nimport { loadCredentials } from \"../../utils/crypto.js\";\nimport { logger } from \"../../utils/logger.js\";\nimport { loadIdentity, identityExists } from \"../../identity/index.js\";\nimport { logInteraction } from \"../../memory/index.js\";\nimport { rateLimiter } from \"../rate-limiter.js\";\nimport type {\n XClientInterface,\n Tweet,\n UserProfile,\n PostResult,\n TimelineOptions,\n SearchOptions,\n} from \"../types.js\";\n\ninterface TwitterResponseMeta {\n next_token?: string;\n}\n\ninterface TwitterUser {\n id: string;\n username: string;\n name?: string;\n description?: string;\n verified?: boolean;\n profile_image_url?: string;\n public_metrics?: {\n followers_count?: number;\n following_count?: number;\n tweet_count?: number;\n };\n}\n\ninterface TwitterTweet {\n id: string;\n text: string;\n author_id?: string;\n created_at?: string;\n in_reply_to_user_id?: string;\n public_metrics?: {\n like_count?: number;\n retweet_count?: number;\n reply_count?: number;\n };\n}\n\ninterface TwitterTimelineResponse {\n data?: TwitterTweet[];\n includes?: {\n users?: TwitterUser[];\n };\n meta?: TwitterResponseMeta;\n}\n\n/**\n * Extract useful error details from twitter-api-v2 errors.\n * Their ApiResponseError has .code, .data, .errors properties that JSON.stringify misses.\n */\nfunction extractTwitterError(error: unknown): string {\n if (!error || typeof error !== \"object\") return String(error);\n const e = error as Record<string, unknown>;\n\n // twitter-api-v2 ApiResponseError shape\n if (e.code && e.data) {\n const status = e.code;\n const data = e.data as Record<string, unknown>;\n const errors = (data.errors ?? data.detail ?? data.title ?? data.reason) as unknown;\n return `HTTP ${status}: ${JSON.stringify(errors ?? data)}`;\n }\n\n // Fallback for standard errors\n if (e.message) return e.message as string;\n return String(error);\n}\n\nexport class XApiClient implements XClientInterface {\n private readonly readWrite: TwitterApi;\n private readonly readOnly: TwitterApi;\n private meId: string | null = null;\n private creds: ReturnType<typeof loadCredentials>;\n\n constructor() {\n this.creds = loadCredentials();\n if (this.creds.method !== \"api\") {\n throw new Error(\"Only API credentials are supported.\");\n }\n\n if (!this.creds.apiKey || !this.creds.apiSecret || !this.creds.accessToken || !this.creds.accessTokenSecret) {\n throw new Error(\"Missing X OAuth credentials. Run `spora init` and provide API keys.\");\n }\n\n this.readWrite = new TwitterApi({\n appKey: this.creds.apiKey,\n appSecret: this.creds.apiSecret,\n accessToken: this.creds.accessToken,\n accessSecret: this.creds.accessTokenSecret,\n });\n\n // Use user-context auth for all reads in runtime.\n // Some endpoints we rely on (timeline/mentions) reject OAuth2 app-only auth.\n this.readOnly = this.readWrite;\n }\n\n private toTweet(tweet: TwitterTweet, userMap: Map<string, string>): Tweet {\n const authorId = tweet.author_id ?? \"unknown\";\n return {\n id: tweet.id,\n text: tweet.text,\n authorId,\n authorHandle: userMap.get(authorId) ?? \"unknown\",\n createdAt: tweet.created_at ?? new Date().toISOString(),\n likeCount: tweet.public_metrics?.like_count,\n retweetCount: tweet.public_metrics?.retweet_count,\n replyCount: tweet.public_metrics?.reply_count,\n inReplyToId: tweet.in_reply_to_user_id,\n };\n }\n\n /**\n * 3-strategy approach to resolve the authenticated user's ID.\n * 1. Extract from OAuth access token (format: {userId}-{rest})\n * 2. Use /2/users/me endpoint\n * 3. Fall back to userByUsername lookup\n */\n private async getUserId(): Promise<string> {\n if (this.meId) return this.meId;\n\n // Strategy 1: Extract user ID from OAuth access token (format: {userId}-{rest})\n const accessToken = this.creds.accessToken;\n if (accessToken) {\n const dashIdx = accessToken.indexOf(\"-\");\n if (dashIdx > 0) {\n const candidate = accessToken.substring(0, dashIdx);\n if (/^\\d+$/.test(candidate)) {\n logger.info(`User ID extracted from access token: ${candidate}`);\n this.meId = candidate;\n return this.meId;\n }\n }\n }\n\n // Strategy 2: Use /2/users/me endpoint\n try {\n const me = (await this.readWrite.v2.me({\n \"user.fields\": [\"id\"],\n })) as { data?: { id: string; username?: string } };\n\n if (me.data?.id) {\n logger.info(`User ID from /me endpoint: ${me.data.id}${me.data.username ? ` (@${me.data.username})` : \"\"}`);\n this.meId = me.data.id;\n return this.meId;\n }\n } catch (err) {\n logger.warn(`/me endpoint failed: ${extractTwitterError(err)}`);\n }\n\n // Strategy 3: Fall back to username lookup\n const handle = this.getHandle();\n logger.info(`Trying userByUsername lookup for: ${handle}`);\n const result = await this.readOnly.v2.userByUsername(handle);\n if (!(result as { data?: { id: string } }).data) {\n const errInfo = (result as Record<string, unknown>).errors;\n throw new Error(\n `Could not find user @${handle}. API returned: ${JSON.stringify(errInfo ?? \"no data\")}`\n );\n }\n this.meId = (result as { data: { id: string } }).data.id;\n return this.meId;\n }\n\n private getHandle(): string {\n let handle: string | undefined;\n if (identityExists()) {\n handle = loadIdentity().handle;\n } else {\n handle = this.creds.username;\n }\n if (!handle) throw new Error(\"No handle found. Create a Spore identity first.\");\n // Strip @ prefix — twitter-api-v2 userByUsername expects bare handle\n return handle.replace(/^@/, \"\");\n }\n\n private normalizeHandleOrId(input: string): { isId: boolean; value: string } {\n const cleaned = input.trim().replace(/^@/, \"\");\n const isId = /^\\d+$/.test(cleaned);\n return { isId, value: cleaned };\n }\n\n private async resolveUserId(handleOrId: string): Promise<string> {\n const parsed = this.normalizeHandleOrId(handleOrId);\n if (parsed.isId) return parsed.value;\n\n const user = (await this.readOnly.v2.userByUsername(parsed.value, {\n \"user.fields\": [\"id\", \"username\"],\n })) as { data?: { id: string } };\n\n if (!user.data?.id) {\n throw new Error(`Could not resolve @${parsed.value} to a user ID`);\n }\n\n return user.data.id;\n }\n\n private buildUserMap(users: TwitterUser[] | undefined): Map<string, string> {\n const map = new Map<string, string>();\n for (const user of users ?? []) {\n map.set(user.id, user.username);\n }\n return map;\n }\n\n async postTweet(content: string): Promise<PostResult> {\n if (!rateLimiter.canPost()) {\n return { success: false, error: \"Monthly post limit reached\" };\n }\n\n try {\n const response = (await this.readWrite.v2.tweet(content)) as { data?: { id?: string } };\n const tweetId = response.data?.id;\n\n if (!tweetId) {\n return { success: false, error: \"X API did not return a tweet ID.\" };\n }\n\n rateLimiter.consume(1);\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"post\",\n tweetId,\n content,\n creditsUsed: 1,\n success: true,\n });\n\n return { success: true, tweetId };\n } catch (error) {\n const detail = extractTwitterError(error);\n logger.error(`Failed to post tweet: ${detail}`);\n return { success: false, error: detail };\n }\n }\n\n async replyToTweet(tweetId: string, content: string): Promise<PostResult> {\n if (!rateLimiter.canPost()) {\n return { success: false, error: \"Monthly post limit reached\" };\n }\n\n try {\n const response = (await this.readWrite.v2.reply(content, tweetId)) as {\n data?: { id?: string };\n };\n const createdId = response.data?.id;\n\n if (!createdId) {\n return { success: false, error: \"X API did not return a reply ID.\" };\n }\n\n rateLimiter.consume(1);\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"reply\",\n tweetId: createdId,\n inReplyTo: tweetId,\n content,\n creditsUsed: 1,\n success: true,\n });\n\n return { success: true, tweetId: createdId };\n } catch (error) {\n const detail = extractTwitterError(error);\n logger.error(`Failed to reply: ${detail}`);\n return { success: false, error: detail };\n }\n }\n\n async deleteTweet(tweetId: string): Promise<PostResult> {\n try {\n await this.readWrite.v2.deleteTweet(tweetId);\n return { success: true, tweetId };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async likeTweet(tweetId: string): Promise<PostResult> {\n try {\n rateLimiter.requireBasicTier(\"Like\");\n const meId = await this.getUserId();\n await this.readWrite.v2.like(meId, tweetId);\n\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"like\",\n tweetId,\n creditsUsed: 0,\n success: true,\n });\n\n return { success: true, tweetId };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async unlikeTweet(tweetId: string): Promise<PostResult> {\n try {\n rateLimiter.requireBasicTier(\"Unlike\");\n const meId = await this.getUserId();\n await this.readWrite.v2.unlike(meId, tweetId);\n return { success: true, tweetId };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async retweet(tweetId: string): Promise<PostResult> {\n try {\n rateLimiter.requireBasicTier(\"Retweet\");\n const meId = await this.getUserId();\n await this.readWrite.v2.retweet(meId, tweetId);\n\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"retweet\",\n tweetId,\n creditsUsed: 0,\n success: true,\n });\n\n return { success: true, tweetId };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async unretweet(tweetId: string): Promise<PostResult> {\n try {\n rateLimiter.requireBasicTier(\"Unretweet\");\n const meId = await this.getUserId();\n await this.readWrite.v2.unretweet(meId, tweetId);\n return { success: true, tweetId };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async followUser(handleOrId: string): Promise<PostResult> {\n rateLimiter.requireBasicTier(\"Follow\");\n try {\n const meId = await this.getUserId();\n const targetId = await this.resolveUserId(handleOrId);\n await this.readWrite.v2.follow(meId, targetId);\n\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"follow\",\n targetUserId: targetId,\n targetHandle: handleOrId.replace(/^@/, \"\"),\n creditsUsed: 0,\n success: true,\n });\n\n return { success: true };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async unfollowUser(handleOrId: string): Promise<PostResult> {\n rateLimiter.requireBasicTier(\"Unfollow\");\n try {\n const meId = await this.getUserId();\n const targetId = await this.resolveUserId(handleOrId);\n await this.readWrite.v2.unfollow(meId, targetId);\n return { success: true };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async getTimeline(options?: TimelineOptions): Promise<Tweet[]> {\n try {\n rateLimiter.requireBasicTier(\"Read timeline\");\n const meId = await this.getUserId();\n\n const response = (await this.readOnly.v2.get(\n `users/${meId}/timelines/reverse_chronological`,\n {\n max_results: options?.count ?? 20,\n since_id: options?.sinceId,\n expansions: [\"author_id\"],\n \"tweet.fields\": [\n \"created_at\",\n \"public_metrics\",\n \"in_reply_to_user_id\",\n \"author_id\",\n ],\n \"user.fields\": [\"username\"],\n }\n )) as TwitterTimelineResponse;\n\n if (!response.data?.length) return [];\n\n const users = this.buildUserMap(response.includes?.users);\n return response.data.map((tweet) => this.toTweet(tweet, users));\n } catch (error) {\n const detail = extractTwitterError(error);\n logger.error(`Failed to read timeline: ${detail}`);\n return [];\n }\n }\n\n async getMentions(options?: TimelineOptions): Promise<Tweet[]> {\n try {\n rateLimiter.requireBasicTier(\"Read mentions\");\n const meId = await this.getUserId();\n const response = (await this.readOnly.v2.get(`users/${meId}/mentions`, {\n max_results: options?.count ?? 20,\n since_id: options?.sinceId,\n expansions: [\"author_id\"],\n \"tweet.fields\": [\"created_at\", \"public_metrics\", \"author_id\"],\n \"user.fields\": [\"username\"],\n })) as TwitterTimelineResponse;\n\n if (!response.data?.length) return [];\n\n const users = this.buildUserMap(response.includes?.users);\n return response.data.map((tweet) => this.toTweet(tweet, users));\n } catch (error) {\n const detail = extractTwitterError(error);\n logger.error(`Failed to read mentions: ${detail}`);\n return [];\n }\n }\n\n async getUserTweets(userId: string, options?: TimelineOptions): Promise<Tweet[]> {\n try {\n rateLimiter.requireBasicTier(\"Read user tweets\");\n\n const response = (await this.readOnly.v2.get(`users/${userId}/tweets`, {\n max_results: options?.count ?? 10,\n since_id: options?.sinceId,\n expansions: [\"author_id\"],\n \"tweet.fields\": [\"created_at\", \"public_metrics\", \"author_id\"],\n \"user.fields\": [\"username\"],\n })) as TwitterTimelineResponse;\n\n if (!response.data?.length) return [];\n\n const users = this.buildUserMap(response.includes?.users);\n return response.data.map((tweet) => this.toTweet(tweet, users));\n } catch (error) {\n const detail = extractTwitterError(error);\n logger.error(`Failed to read user tweets for ${userId}: ${detail}`);\n return [];\n }\n }\n\n async searchTweets(query: string, options?: SearchOptions): Promise<Tweet[]> {\n try {\n rateLimiter.requireBasicTier(\"Search tweets\");\n const paginator = await this.readOnly.v2.search(query, {\n max_results: Math.min(options?.count ?? 20, 100),\n expansions: [\"author_id\"],\n \"tweet.fields\": [\"created_at\", \"public_metrics\", \"author_id\"],\n \"user.fields\": [\"username\"],\n });\n\n const tweets: TwitterTweet[] = [];\n const users = new Map<string, string>();\n\n for await (const tweet of paginator) {\n tweets.push(tweet as unknown as TwitterTweet);\n if (tweets.length >= (options?.count ?? 20)) break;\n }\n\n const includeUsers = (paginator as unknown as { includes?: { users?: TwitterUser[] } }).includes?.users;\n for (const user of includeUsers ?? []) {\n users.set(user.id, user.username);\n }\n\n return tweets.map((tweet) => this.toTweet(tweet, users));\n } catch (error) {\n const detail = extractTwitterError(error);\n logger.error(`Failed to search tweets: ${detail}`);\n return [];\n }\n }\n\n async getProfile(handle: string): Promise<UserProfile> {\n rateLimiter.requireBasicTier(\"Get profile\");\n\n const cleanedHandle = handle.trim().replace(/^@/, \"\");\n const response = (await this.readOnly.v2.userByUsername(cleanedHandle, {\n \"user.fields\": [\n \"description\",\n \"public_metrics\",\n \"verified\",\n \"profile_image_url\",\n \"username\",\n \"name\",\n ],\n })) as { data?: TwitterUser };\n\n if (!response.data) {\n throw new Error(`Profile not found for @${cleanedHandle}`);\n }\n\n return {\n id: response.data.id,\n handle: response.data.username,\n name: response.data.name ?? response.data.username,\n bio: response.data.description ?? \"\",\n followersCount: response.data.public_metrics?.followers_count ?? 0,\n followingCount: response.data.public_metrics?.following_count ?? 0,\n tweetCount: response.data.public_metrics?.tweet_count ?? 0,\n verified: response.data.verified ?? false,\n profileImageUrl: response.data.profile_image_url,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AA0D3B,SAAS,oBAAoB,OAAwB;AACnD,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO,OAAO,KAAK;AAC5D,QAAM,IAAI;AAGV,MAAI,EAAE,QAAQ,EAAE,MAAM;AACpB,UAAM,SAAS,EAAE;AACjB,UAAM,OAAO,EAAE;AACf,UAAM,SAAU,KAAK,UAAU,KAAK,UAAU,KAAK,SAAS,KAAK;AACjE,WAAO,QAAQ,MAAM,KAAK,KAAK,UAAU,UAAU,IAAI,CAAC;AAAA,EAC1D;AAGA,MAAI,EAAE,QAAS,QAAO,EAAE;AACxB,SAAO,OAAO,KAAK;AACrB;AAEO,IAAM,aAAN,MAA6C;AAAA,EACjC;AAAA,EACA;AAAA,EACT,OAAsB;AAAA,EACtB;AAAA,EAER,cAAc;AACZ,SAAK,QAAQ,gBAAgB;AAC7B,QAAI,KAAK,MAAM,WAAW,OAAO;AAC/B,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AAEA,QAAI,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,UAAM,WAAY,MAAM,KAAK,SAAS,GAAG,eAAe,eAAe;AAAA,MACrE,eAAe;AAAA,QACb;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,QAAI,CAAC,SAAS,MAAM;AAClB,YAAM,IAAI,MAAM,0BAA0B,aAAa,EAAE;AAAA,IAC3D;AAEA,WAAO;AAAA,MACL,IAAI,SAAS,KAAK;AAAA,MAClB,QAAQ,SAAS,KAAK;AAAA,MACtB,MAAM,SAAS,KAAK,QAAQ,SAAS,KAAK;AAAA,MAC1C,KAAK,SAAS,KAAK,eAAe;AAAA,MAClC,gBAAgB,SAAS,KAAK,gBAAgB,mBAAmB;AAAA,MACjE,gBAAgB,SAAS,KAAK,gBAAgB,mBAAmB;AAAA,MACjE,YAAY,SAAS,KAAK,gBAAgB,eAAe;AAAA,MACzD,UAAU,SAAS,KAAK,YAAY;AAAA,MACpC,iBAAiB,SAAS,KAAK;AAAA,IACjC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime/heartbeat.ts","../src/runtime/telemetry.ts"],"sourcesContent":["import { existsSync, unlinkSync, writeFileSync, readFileSync } from \"node:fs\";\nimport { logger } from \"../utils/logger.js\";\nimport { loadConfig } from \"../utils/config.js\";\nimport { paths } from \"../utils/paths.js\";\nimport { flushQueue } from \"../scheduler/queue.js\";\nimport { runAutonomyCycle } from \"./autonomy.js\";\nimport { writeHeartbeatMetrics } from \"./telemetry.js\";\nimport { buildReflectionPrompt } from \"./prompt-builder.js\";\nimport { generateResponse } from \"./llm.js\";\nimport { addLearning } from \"../memory/index.js\";\nimport { loadStrategy, saveStrategy } from \"../memory/strategy.js\";\nimport { loadIdentity } from \"../identity/index.js\";\n\nlet running = false;\n\nexport function isRunning(): boolean {\n return running;\n}\n\nexport function requestStop(): void {\n writeFileSync(paths.stopSignal, \"stop\");\n logger.info(\"Stop signal sent.\");\n}\n\nfunction shouldStop(): boolean {\n if (existsSync(paths.stopSignal)) {\n unlinkSync(paths.stopSignal);\n return true;\n }\n return false;\n}\n\nfunction writePid(): void {\n writeFileSync(paths.runtimePid, String(process.pid));\n}\n\nfunction clearPid(): void {\n if (existsSync(paths.runtimePid)) {\n unlinkSync(paths.runtimePid);\n }\n}\n\nexport function getRunningPid(): number | null {\n if (!existsSync(paths.runtimePid)) return null;\n const pid = parseInt(readFileSync(paths.runtimePid, \"utf-8\").trim(), 10);\n if (isNaN(pid)) return null;\n\n // Check if process is actually running\n try {\n process.kill(pid, 0);\n return pid;\n } catch {\n // Process not running, clean up stale PID\n clearPid();\n return null;\n }\n}\n\nexport async function startHeartbeatLoop(): Promise<void> {\n // Check if already running\n const existingPid = getRunningPid();\n if (existingPid) {\n throw new Error(`Spora is already running (PID ${existingPid}). Run \\`spora stop\\` first.`);\n }\n\n running = true;\n writePid();\n\n const config = loadConfig();\n const intervalMs = config.runtime?.heartbeatIntervalMs ?? 300_000;\n const maxActions = config.runtime?.actionsPerHeartbeat ?? 3;\n\n logger.info(`Spora agent starting. Heartbeat interval: ${intervalMs / 1000}s, max actions: ${maxActions}`);\n console.log(`\\nSpora agent is running (PID ${process.pid})`);\n console.log(`Heartbeat every ${Math.round(intervalMs / 60_000)} minutes`);\n console.log(`Press Ctrl+C or run \\`spora stop\\` to stop.\\n`);\n\n // Handle graceful shutdown\n const shutdown = () => {\n logger.info(\"Shutting down...\");\n running = false;\n clearPid();\n process.exit(0);\n };\n process.on(\"SIGINT\", shutdown);\n process.on(\"SIGTERM\", shutdown);\n\n // Clean any stale stop signal\n if (existsSync(paths.stopSignal)) {\n unlinkSync(paths.stopSignal);\n }\n\n let heartbeatCount = 0;\n\n while (running) {\n heartbeatCount++;\n logger.info(`=== Heartbeat #${heartbeatCount} ===`);\n\n try {\n await runHeartbeat(maxActions, heartbeatCount);\n } catch (error) {\n logger.error(\"Heartbeat error\", error);\n console.error(`Heartbeat #${heartbeatCount} failed: ${(error as Error).message}`);\n }\n\n // Check for stop signal\n if (shouldStop()) {\n logger.info(\"Stop signal received.\");\n break;\n }\n\n // Sleep with jitter\n const jitter = Math.floor(Math.random() * intervalMs * 0.3);\n const sleepMs = intervalMs + jitter;\n logger.info(`Sleeping ${Math.round(sleepMs / 1000)}s until next heartbeat...`);\n\n // Sleep in chunks so we can check for stop signals\n const chunkMs = 10_000;\n let slept = 0;\n while (slept < sleepMs && running) {\n await new Promise((r) => setTimeout(r, Math.min(chunkMs, sleepMs - slept)));\n slept += chunkMs;\n if (shouldStop()) {\n running = false;\n break;\n }\n }\n }\n\n clearPid();\n logger.info(\"Spora agent stopped.\");\n console.log(\"\\nSpora agent stopped.\");\n}\n\nasync function runHeartbeat(maxActions: number, heartbeatCount: number): Promise<void> {\n // 1. Flush any queued posts\n logger.info(\"Checking queue...\");\n try {\n const flushed = await flushQueue();\n if (flushed.posted > 0) {\n logger.info(`Flushed ${flushed.posted} queued posts.`);\n }\n } catch (error) {\n logger.warn(`Queue flush failed: ${(error as Error).message}`);\n }\n\n // 2. Run planner/executor cycle.\n const cycle = await runAutonomyCycle(maxActions);\n logger.info(`Observed ${cycle.timeline.length} timeline posts and ${cycle.mentions.length} mentions.`);\n\n if (cycle.actions.length === 0) {\n logger.info(\"Planner returned no approved actions.\");\n return;\n }\n\n logger.info(`Executed ${cycle.results.length} action(s).`);\n\n // 3. Log results\n for (const result of cycle.results) {\n if (result.success) {\n logger.info(` [OK] ${result.action}${result.detail ? `: ${result.detail}` : \"\"}`);\n } else {\n logger.warn(` [FAIL] ${result.action}: ${result.error}`);\n }\n }\n\n for (const note of cycle.policyFeedback) {\n logger.info(` [POLICY] ${note}`);\n }\n\n const metrics = writeHeartbeatMetrics({\n timelineCount: cycle.timeline.length,\n mentionsCount: cycle.mentions.length,\n actions: cycle.actions,\n results: cycle.results,\n policyFeedbackCount: cycle.policyFeedback.length,\n });\n logger.info(\n `Metrics: interactionRatio=${metrics.interactionRatio.toFixed(2)}, repeatedFormatRate=${metrics.repeatedFormatRate.toFixed(2)}`\n );\n\n logger.info(`Heartbeat complete. ${cycle.results.filter((r) => r.success).length}/${cycle.results.length} actions succeeded.`);\n\n // Reflection phase — every 3rd heartbeat\n if (heartbeatCount % 3 === 0) {\n try {\n logger.info(\"Running reflection phase...\");\n const reflectionPrompt = buildReflectionPrompt(cycle.results);\n const reflectionResponse = await generateResponse(\n `You are ${loadIdentity().name}. Reflect honestly on your performance.`,\n reflectionPrompt,\n );\n\n const jsonMatch = reflectionResponse.content.match(/\\{[\\s\\S]*\\}/);\n if (jsonMatch) {\n try {\n const reflection = JSON.parse(jsonMatch[0]);\n if (reflection.learning && reflection.learning !== \"null\") {\n addLearning(reflection.learning, \"reflection\", [\"heartbeat\", \"performance\"]);\n logger.info(`Reflection learning: ${reflection.learning}`);\n }\n if (reflection.strategyUpdate && reflection.strategyUpdate !== \"null\") {\n const strategy = loadStrategy();\n strategy.experiments.push({\n description: reflection.strategyUpdate,\n status: \"pending\",\n });\n strategy.lastUpdated = new Date().toISOString();\n saveStrategy(strategy);\n logger.info(`Strategy update: ${reflection.strategyUpdate}`);\n }\n } catch {\n // Couldn't parse reflection JSON\n }\n }\n } catch (err) {\n logger.warn(`Reflection failed: ${(err as Error).message}`);\n }\n }\n}\n","import { appendFileSync } from \"node:fs\";\nimport { paths, ensureDirectories } from \"../utils/paths.js\";\nimport type { AgentAction, ActionResult } from \"./decision-engine.js\";\n\nexport interface HeartbeatMetrics {\n timestamp: string;\n timelineCount: number;\n mentionsCount: number;\n actionCount: number;\n successCount: number;\n postCount: number;\n interactionCount: number;\n interactionRatio: number;\n repeatedFormatRate: number;\n policyRejectionCount: number;\n}\n\nfunction normalize(text: string): string {\n return text.toLowerCase().replace(/[^a-z0-9\\s]/g, \" \").replace(/\\s+/g, \" \").trim();\n}\n\nfunction prefix(text: string, n = 6): string {\n return normalize(text).split(\" \").filter(Boolean).slice(0, n).join(\" \");\n}\n\nfunction repeatedFormatRate(actions: AgentAction[]): number {\n const posts = actions\n .filter((action) => action.action === \"post\" && action.content)\n .map((action) => action.content ?? \"\");\n\n if (posts.length <= 1) return 0;\n\n const seen = new Map<string, number>();\n for (const content of posts) {\n const key = prefix(content);\n seen.set(key, (seen.get(key) ?? 0) + 1);\n }\n\n let repeated = 0;\n for (const count of seen.values()) {\n if (count > 1) repeated += count;\n }\n\n return repeated / posts.length;\n}\n\nexport function writeHeartbeatMetrics(input: {\n timelineCount: number;\n mentionsCount: number;\n actions: AgentAction[];\n results: ActionResult[];\n policyFeedbackCount: number;\n}): HeartbeatMetrics {\n const interactionCount = input.actions.filter((a) => [\"reply\", \"like\", \"retweet\", \"follow\"].includes(a.action)).length;\n const postCount = input.actions.filter((a) => a.action === \"post\").length;\n const successCount = input.results.filter((r) => r.success).length;\n\n const metrics: HeartbeatMetrics = {\n timestamp: new Date().toISOString(),\n timelineCount: input.timelineCount,\n mentionsCount: input.mentionsCount,\n actionCount: input.actions.length,\n successCount,\n postCount,\n interactionCount,\n interactionRatio: input.actions.length > 0 ? interactionCount / input.actions.length : 0,\n repeatedFormatRate: repeatedFormatRate(input.actions),\n policyRejectionCount: input.policyFeedbackCount,\n };\n\n ensureDirectories();\n appendFileSync(paths.runtimeMetrics, JSON.stringify(metrics) + \"\\n\");\n return metrics;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,YAAY,eAAe,oBAAoB;;;ACApE,SAAS,sBAAsB;AAiB/B,SAAS,UAAU,MAAsB;AACvC,SAAO,KAAK,YAAY,EAAE,QAAQ,gBAAgB,GAAG,EAAE,QAAQ,QAAQ,GAAG,EAAE,KAAK;AACnF;AAEA,SAAS,OAAO,MAAc,IAAI,GAAW;AAC3C,SAAO,UAAU,IAAI,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG;AACxE;AAEA,SAAS,mBAAmB,SAAgC;AAC1D,QAAM,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,MAAM,UAAU,CAAC,CAAC;AAC1C,cAAI,WAAW,YAAY,WAAW,aAAa,QAAQ;AACzD,wBAAY,WAAW,UAAU,cAAc,CAAC,aAAa,aAAa,CAAC;AAC3E,mBAAO,KAAK,wBAAwB,WAAW,QAAQ,EAAE;AAAA,UAC3D;AACA,cAAI,WAAW,kBAAkB,WAAW,mBAAmB,QAAQ;AACrE,kBAAM,WAAW,aAAa;AAC9B,qBAAS,YAAY,KAAK;AAAA,cACxB,aAAa,WAAW;AAAA,cACxB,QAAQ;AAAA,YACV,CAAC;AACD,qBAAS,eAAc,oBAAI,KAAK,GAAE,YAAY;AAC9C,yBAAa,QAAQ;AACrB,mBAAO,KAAK,oBAAoB,WAAW,cAAc,EAAE;AAAA,UAC7D;AAAA,QACF,QAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF,SAAS,KAAK;AACZ,aAAO,KAAK,sBAAuB,IAAc,OAAO,EAAE;AAAA,IAC5D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/init.ts","../src/x-client/profile-updater.ts"],"sourcesContent":["import { input, select, password as passwordPrompt } from \"@inquirer/prompts\";\nimport chalk from \"chalk\";\nimport { ensureDirectories } from \"./utils/paths.js\";\nimport { createDefaultConfig, saveConfig } from \"./utils/config.js\";\nimport { saveCredentials } from \"./utils/crypto.js\";\nimport { loadIdentity } from \"./identity/index.js\";\nimport type { Identity } from \"./identity/schema.js\";\nimport { updateXProfile } from \"./x-client/profile-updater.js\";\nimport { setLLMApiKey, type LLMProvider, getDefaultModel } from \"./runtime/llm.js\";\n\n/**\n * Fetch identity from token and save locally\n */\nasync function syncIdentityFromToken(token: string): Promise<void> {\n console.log(chalk.gray(\"Connecting to spora.dev...\\n\"));\n\n const apiUrl = process.env.SPORA_API_URL || \"https://www.spora.social\";\n const response = await fetch(`${apiUrl}/api/v1/connect`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ token }),\n });\n\n if (!response.ok) {\n const errData = await response.json().catch(() => ({} as { error?: string })) as { error?: string };\n throw new Error(errData.error || `Connection failed: ${response.statusText}`);\n }\n\n const data = await response.json() as {\n identity?: Identity;\n media?: { profileImage?: string; bannerImage?: string };\n readme?: string;\n };\n\n if (!data.identity) {\n throw new Error(\"No Spore identity found for this token\");\n }\n\n // Merge media fields\n if (data.media) {\n if (data.media.profileImage) data.identity.profileImage = data.media.profileImage;\n if (data.media.bannerImage) data.identity.bannerImage = data.media.bannerImage;\n }\n\n const { saveIdentity } = await import(\"./identity/index.js\");\n saveIdentity(data.identity);\n\n console.log(chalk.green(`✓ Connected to Spore: ${data.identity.name} (@${data.identity.handle})\\n`));\n\n // Save README if provided\n if (data.readme) {\n const { writeFileSync } = await import(\"node:fs\");\n const { paths } = await import(\"./utils/paths.js\");\n const { join, dirname } = await import(\"node:path\");\n const readmePath = join(dirname(paths.identity), \"IDENTITY.md\");\n writeFileSync(readmePath, data.readme, \"utf-8\");\n console.log(chalk.green(\"✓ Saved identity README\\n\"));\n }\n\n // Save connection token to config\n const { existsSync } = await import(\"node:fs\");\n const { paths } = await import(\"./utils/paths.js\");\n if (existsSync(paths.config)) {\n const { loadConfig, saveConfig } = await import(\"./utils/config.js\");\n const config = loadConfig();\n config.connection = {\n token,\n apiEndpoint: process.env.SPORA_API_URL || \"https://www.spora.social/api/v1\",\n configVersion: config.connection?.configVersion ?? 0,\n };\n saveConfig(config);\n }\n}\n\n/**\n * Login flow: paste token → sync identity → open chat (keys already saved locally)\n */\nasync function loginFlow(): Promise<void> {\n console.log(chalk.bold(\"\\n━━━ Login to Existing Spore ━━━\\n\"));\n console.log(chalk.gray(\"Paste your setup token from spora.dev\"));\n console.log(chalk.gray(\"(It looks like: spora_7e636ac0...)\\n\"));\n\n const token = await input({\n message: \"Setup token:\",\n validate: (val) => val.length > 0 ? true : \"Token is required\",\n });\n\n ensureDirectories();\n\n try {\n await syncIdentityFromToken(token.trim());\n } catch (error) {\n console.log(chalk.red(`\\n✗ ${(error as Error).message}\\n`));\n console.log(chalk.yellow(\"Please check your token and try again.\\n\"));\n process.exit(1);\n }\n\n console.log(chalk.green(\"✓ Logged in!\\n\"));\n console.log(chalk.gray(\"Opening chat interface...\\n\"));\n\n try {\n const { startWebChat } = await import(\"./web-chat/index.js\");\n await startWebChat();\n } catch (error) {\n console.log(chalk.yellow(`Could not start chat interface: ${(error as Error).message}\\n`));\n console.log(chalk.gray(\"You can start it manually with: spora chat\\n\"));\n }\n}\n\ninterface SetupResult {\n llm: {\n provider: LLMProvider;\n model: string;\n };\n}\n\nfunction providerKeyUrl(provider: LLMProvider): string {\n if (provider === \"anthropic\") return \"https://console.anthropic.com/settings/keys\";\n if (provider === \"openai\") return \"https://platform.openai.com/api-keys\";\n return \"https://platform.deepseek.com/api_keys\";\n}\n\n/**\n * Prompt for LLM provider/model + X credentials.\n */\nasync function setupKeys(): Promise<SetupResult> {\n console.log(chalk.bold(\"\\n━━━ LLM Provider Setup ━━━\\n\"));\n\n const provider = await select({\n message: \"Choose your LLM provider:\",\n choices: [\n { name: \"DeepSeek (recommended for low cost)\", value: \"deepseek\" },\n { name: \"Anthropic (Claude)\", value: \"anthropic\" },\n { name: \"OpenAI\", value: \"openai\" },\n ],\n }) as LLMProvider;\n\n const defaultModel = getDefaultModel(provider);\n const model = await input({\n message: `Model name for ${provider} (press enter for ${defaultModel}):`,\n });\n\n console.log(chalk.gray(\"Get your API key at: \") + chalk.cyan(`${providerKeyUrl(provider)}\\n`));\n const llmKey = await passwordPrompt({\n message: `${provider} API Key:`,\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"API key is required\",\n });\n setLLMApiKey(provider, llmKey.trim());\n console.log(chalk.green(`✓ ${provider} API key saved\\n`));\n\n // X credentials\n console.log(chalk.bold(\"\\n━━━ Connect Your X Account ━━━\\n\"));\n console.log(chalk.gray(\"Your Spore needs OAuth 1.0a credentials for full X API access.\"));\n console.log(chalk.gray(\"This gives your agent the power to read timelines, post tweets, reply, like, and follow.\\n\"));\n console.log(chalk.cyan(\"How to get these credentials:\"));\n console.log(chalk.gray(\" 1. Go to: \") + chalk.cyan(\"https://developer.x.com/en/portal/dashboard\"));\n console.log(chalk.gray(\" 2. Create or select your app\"));\n console.log(chalk.gray(\" 3. Go to \\\"Keys and tokens\\\" tab\"));\n console.log(chalk.gray(\" 4. Copy all 4 credentials below\\n\"));\n console.log(chalk.yellow(\"Note: Some endpoints may require paid X API access depending on your tier.\\n\"));\n\n const apiKey = await passwordPrompt({\n message: \"X API Key (Consumer Key):\",\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"API Key is required\",\n });\n\n const apiSecret = await passwordPrompt({\n message: \"X API Secret (Consumer Secret):\",\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"API Secret is required\",\n });\n\n const accessToken = await passwordPrompt({\n message: \"X Access Token:\",\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"Access Token is required\",\n });\n\n const accessTokenSecret = await passwordPrompt({\n message: \"X Access Token Secret:\",\n mask: \"*\",\n validate: (val: string) => val.length > 0 ? true : \"Access Token Secret is required\",\n });\n\n const bearerToken = await input({\n message: \"X Bearer Token (optional, press enter to skip):\",\n });\n\n saveCredentials({\n method: \"api\",\n apiKey,\n apiSecret,\n accessToken,\n accessTokenSecret,\n bearerToken: bearerToken.trim() || undefined,\n });\n console.log(chalk.green(\"✓ X API credentials saved (encrypted)\\n\"));\n\n return {\n llm: {\n provider,\n model: model.trim() || defaultModel,\n },\n };\n}\n\n/**\n * Show completion message and open chat\n */\nasync function showDoneAndOpenChat(): Promise<void> {\n console.log(chalk.green(\"\\n╔═══════════════════════════════════════╗\"));\n console.log(chalk.green.bold(\"║ Setup Complete! ║\"));\n console.log(chalk.green(\"╚═══════════════════════════════════════╝\\n\"));\n\n console.log(chalk.bold.cyan(\"━━━ Your Spore is Ready! ━━━\\n\"));\n console.log(chalk.gray(\"Opening chat interface...\\n\"));\n\n try {\n const { startWebChat } = await import(\"./web-chat/index.js\");\n await startWebChat();\n } catch (error) {\n console.log(chalk.yellow(`Could not start chat interface: ${(error as Error).message}\\n`));\n console.log(chalk.gray(\"You can start it manually with: spora chat\\n\"));\n }\n\n console.log(chalk.bold(\"Quick Start:\\n\"));\n console.log(chalk.cyan(\" spora chat\"));\n console.log(chalk.gray(\" → Talk to your Spore, tell it what to post, how to behave\\n\"));\n console.log(chalk.bold(\"Or start the autonomous agent:\\n\"));\n console.log(chalk.cyan(\" spora start\"));\n console.log(chalk.gray(\" → Your Spore will post and engage autonomously\\n\"));\n console.log(chalk.bold(\"Other commands:\\n\"));\n console.log(chalk.cyan(\" spora create \") + chalk.gray(\"# Create a personality\"));\n console.log(chalk.cyan(\" spora post <text> \") + chalk.gray(\"# Make your Spore post\"));\n console.log(chalk.cyan(\" spora agent-status \") + chalk.gray(\"# Check if agent is running\"));\n console.log(chalk.cyan(\" spora stop \") + chalk.gray(\"# Stop the agent\"));\n console.log(chalk.cyan(\" spora --help \") + chalk.gray(\"# See all commands\\n\"));\n}\n\nexport async function runInit(token?: string): Promise<void> {\n console.log(chalk.bold.cyan(\"\\n╔════════════════════════════════════════╗\"));\n console.log(chalk.bold.cyan(\"║ Welcome to Spora CLI Setup ║\"));\n console.log(chalk.bold.cyan(\"╚════════════════════════════════════════╝\\n\"));\n\n // If token provided via --token flag, this is a new user from the website → full setup\n if (token) {\n ensureDirectories();\n\n console.log(chalk.bold(\"\\n━━━ Connecting Your Spore ━━━\\n\"));\n try {\n await syncIdentityFromToken(token);\n } catch (error) {\n console.log(chalk.red(`\\n✗ ${(error as Error).message}\\n`));\n console.log(chalk.yellow(\"Please check your token and try again.\\n\"));\n process.exit(1);\n }\n\n const setup = await setupKeys();\n\n // Update X profile\n console.log(chalk.bold(\"\\n━━━ Updating Your X Profile ━━━\\n\"));\n console.log(chalk.gray(\"Setting up profile picture, banner, and bio to match your Spore...\\n\"));\n try {\n const identity = loadIdentity();\n const result = await updateXProfile(identity);\n if (result.success) {\n console.log(chalk.green(\"✓ Profile updated successfully!\\n\"));\n if (result.updated.length > 0) {\n console.log(chalk.cyan(\"Updated:\"));\n for (const field of result.updated) {\n console.log(chalk.gray(` • ${field}`));\n }\n console.log();\n }\n }\n if (result.errors.length > 0) {\n console.log(chalk.yellow(\"\\nSome updates failed:\"));\n for (const err of result.errors) {\n console.log(chalk.gray(` • ${err}`));\n }\n console.log();\n }\n } catch (error) {\n console.log(chalk.yellow(`Could not update profile: ${(error as Error).message}\\n`));\n console.log(chalk.gray(\"You can manually update your X profile later.\\n\"));\n }\n\n const config = createDefaultConfig({ xMethod: \"api\", xApiTier: \"basic\" });\n config.llm = setup.llm;\n config.runtime = { heartbeatIntervalMs: 300_000, actionsPerHeartbeat: 4, enabled: true };\n config.connection = {\n token,\n apiEndpoint: process.env.SPORA_API_URL || \"https://www.spora.social/api/v1\",\n configVersion: 0,\n };\n saveConfig(config);\n\n await showDoneAndOpenChat();\n return;\n }\n\n // No token provided — ask what they want to do\n const action = await select({\n message: \"What would you like to do?\",\n choices: [\n { name: \"Create a new Spore\", value: \"new\" },\n { name: \"Login to existing Spore\", value: \"login\" },\n ],\n });\n\n if (action === \"login\") {\n await loginFlow();\n return;\n }\n\n // \"new\" — full new Spore creation (no token, manual setup)\n ensureDirectories();\n\n const setup = await setupKeys();\n\n // Update X profile\n console.log(chalk.bold(\"\\n━━━ Updating Your X Profile ━━━\\n\"));\n console.log(chalk.gray(\"Setting up profile picture, banner, and bio to match your Spore...\\n\"));\n try {\n const identity = loadIdentity();\n const result = await updateXProfile(identity);\n if (result.success) {\n console.log(chalk.green(\"✓ Profile updated successfully!\\n\"));\n if (result.updated.length > 0) {\n console.log(chalk.cyan(\"Updated:\"));\n for (const field of result.updated) {\n console.log(chalk.gray(` • ${field}`));\n }\n console.log();\n }\n }\n if (result.errors.length > 0) {\n console.log(chalk.yellow(\"\\nSome updates failed:\"));\n for (const err of result.errors) {\n console.log(chalk.gray(` • ${err}`));\n }\n console.log();\n }\n } catch (error) {\n console.log(chalk.yellow(`Could not update profile: ${(error as Error).message}\\n`));\n console.log(chalk.gray(\"You can manually update your X profile later.\\n\"));\n }\n\n const config = createDefaultConfig({ xMethod: \"api\", xApiTier: \"basic\" });\n config.llm = setup.llm;\n config.runtime = { heartbeatIntervalMs: 300_000, actionsPerHeartbeat: 4, enabled: true };\n saveConfig(config);\n\n await showDoneAndOpenChat();\n}\n","/**\n * X Profile Updater\n * Updates X profile to match Spore identity (name, bio, profile pic, banner)\n */\n\nimport { TwitterApi } from \"twitter-api-v2\";\nimport sharp from \"sharp\";\nimport type { Identity } from \"../identity/schema.js\";\nimport { loadCredentials } from \"../utils/crypto.js\";\n\ninterface ProfileUpdateResult {\n success: boolean;\n updated: string[];\n errors: string[];\n}\n\n/**\n * Update X profile to match Spore identity\n * Requires OAuth 1.0a credentials\n */\nexport async function updateXProfile(identity: Identity): Promise<ProfileUpdateResult> {\n const result: ProfileUpdateResult = {\n success: false,\n updated: [],\n errors: [],\n };\n\n try {\n const creds = loadCredentials();\n if (creds.method !== \"api\") {\n result.errors.push(\"API credentials required\");\n return result;\n }\n\n // Create Twitter API client with OAuth 1.0a credentials\n const client = new TwitterApi({\n appKey: creds.apiKey!,\n appSecret: creds.apiSecret!,\n accessToken: creds.accessToken!,\n accessSecret: creds.accessTokenSecret!,\n });\n\n // Update profile name and bio (username separately to avoid breaking on failure)\n try {\n console.log(`Updating name to: ${identity.name}`);\n console.log(`Updating bio to: ${identity.bio.substring(0, 60)}...`);\n await client.v1.updateAccountProfile({\n name: identity.name,\n description: identity.bio,\n });\n result.updated.push(\"name\", \"bio\");\n console.log(\"Name and bio updated successfully\");\n } catch (error) {\n console.error(\"Name/bio update error:\", error);\n result.errors.push(`Failed to update name/bio: ${(error as Error).message}`);\n }\n\n // Username changes are intentionally not attempted here.\n // X frequently restricts handle updates, and failed writes can disrupt setup.\n\n // Update profile image if available\n if (identity.profileImage) {\n try {\n console.log(`Downloading profile image from: ${identity.profileImage.substring(0, 60)}...`);\n let imageBuffer = await downloadImage(identity.profileImage);\n console.log(`Downloaded ${(imageBuffer.length / 1024 / 1024).toFixed(2)}MB`);\n\n // Check image dimensions - Twitter requires min 400x400\n const metadata = await sharp(imageBuffer).metadata();\n console.log(`Image dimensions: ${metadata.width}x${metadata.height}`);\n\n if (!metadata.width || !metadata.height || metadata.width < 400 || metadata.height < 400) {\n throw new Error(`Image too small (${metadata.width}x${metadata.height}). Twitter requires minimum 400x400 pixels.`);\n }\n\n // Compress if needed (Twitter profile image limit: 2MB)\n const MAX_PROFILE_SIZE = 2 * 1024 * 1024; // 2MB\n imageBuffer = await compressImageIfNeeded(imageBuffer, MAX_PROFILE_SIZE, \"Profile\");\n\n console.log(`Uploading profile image to X...`);\n await client.v1.updateAccountProfileImage(imageBuffer);\n result.updated.push(\"profile_image\");\n console.log(\"Profile image updated successfully\");\n } catch (error) {\n console.error(\"Profile image error:\", error);\n result.errors.push(`Failed to update profile image: ${(error as Error).message}`);\n }\n } else {\n console.log(\"No profile image URL in identity\");\n }\n\n // Update banner image if available\n if (identity.bannerImage) {\n try {\n console.log(`Downloading banner image from: ${identity.bannerImage.substring(0, 60)}...`);\n let imageBuffer = await downloadImage(identity.bannerImage);\n console.log(`Downloaded ${(imageBuffer.length / 1024 / 1024).toFixed(2)}MB`);\n\n // Compress if needed (Twitter banner limit: 5MB)\n const MAX_BANNER_SIZE = 5 * 1024 * 1024; // 5MB\n imageBuffer = await compressImageIfNeeded(imageBuffer, MAX_BANNER_SIZE, \"Banner\");\n\n console.log(`Uploading banner image to X...`);\n await client.v1.updateAccountProfileBanner(imageBuffer);\n result.updated.push(\"banner_image\");\n console.log(\"Banner image updated successfully\");\n } catch (error) {\n console.error(\"Banner image error:\", error);\n result.errors.push(`Failed to update banner: ${(error as Error).message}`);\n }\n } else {\n console.log(\"No banner image URL in identity\");\n }\n\n result.success = result.updated.length > 0;\n return result;\n } catch (error) {\n result.errors.push((error as Error).message);\n return result;\n }\n}\n\n/**\n * Download image from URL and return as Buffer\n */\nasync function downloadImage(url: string): Promise<Buffer> {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`Failed to download image: ${response.statusText}`);\n }\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n}\n\n/**\n * Compress image if it exceeds size limit by resizing\n * @param buffer Original image buffer\n * @param maxSizeBytes Maximum allowed size in bytes\n * @param type \"profile\" or \"banner\" for logging\n */\nasync function compressImageIfNeeded(\n buffer: Buffer,\n maxSizeBytes: number,\n type: string\n): Promise<Buffer> {\n if (buffer.length <= maxSizeBytes) {\n return buffer;\n }\n\n console.log(\n `${type} image is ${(buffer.length / 1024 / 1024).toFixed(2)}MB, resizing to fit ${(maxSizeBytes / 1024 / 1024).toFixed(0)}MB limit...`\n );\n\n // Calculate scale factor to fit within size limit\n const scaleFactor = Math.sqrt(maxSizeBytes / buffer.length) * 0.85; // 85% of target for safety\n\n // Get current dimensions and calculate new size\n const metadata = await sharp(buffer).metadata();\n const newWidth = Math.floor((metadata.width || 1000) * scaleFactor);\n\n // Resize and convert to JPEG with good quality\n const compressed = await sharp(buffer)\n .resize(newWidth, null, { fit: \"inside\", withoutEnlargement: true })\n .jpeg({ quality: 90, progressive: true })\n .toBuffer();\n\n console.log(\n `Resized ${type} image from ${(buffer.length / 1024 / 1024).toFixed(2)}MB to ${(compressed.length / 1024 / 1024).toFixed(2)}MB`\n );\n\n return compressed;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,OAAO,QAAQ,YAAY,sBAAsB;AAC1D,OAAO,WAAW;;;ACIlB,SAAS,kBAAkB;AAC3B,OAAO,WAAW;AAclB,eAAsB,eAAe,UAAkD;AACrF,QAAM,SAA8B;AAAA,IAClC,SAAS;AAAA,IACT,SAAS,CAAC;AAAA,IACV,QAAQ,CAAC;AAAA,EACX;AAEA,MAAI;AACF,UAAM,QAAQ,gBAAgB;AAC9B,QAAI,MAAM,WAAW,OAAO;AAC1B,aAAO,OAAO,K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ompt
|
|
8
|
-
} from "./chunk-Q3YXJ2C6.js";
|
|
9
|
-
import "./chunk-P6KZIJYL.js";
|
|
10
|
-
import "./chunk-WN35MRMF.js";
|
|
11
|
-
import "./chunk-4LNMA56H.js";
|
|
12
|
-
import "./chunk-M6YOQVSI.js";
|
|
13
|
-
import "./chunk-YMGJQRKG.js";
|
|
14
|
-
import "./chunk-NO3NQN67.js";
|
|
15
|
-
import "./chunk-JBYZ7K56.js";
|
|
16
|
-
import "./chunk-3RYCUGXE.js";
|
|
17
|
-
export {
|
|
18
|
-
buildChatPrompt,
|
|
19
|
-
buildHeartbeatUserMessage,
|
|
20
|
-
buildReflectionPrompt,
|
|
21
|
-
buildSystemPrompt,
|
|
22
|
-
buildToolDecisionMessage,
|
|
23
|
-
buildTrainingChatPrompt
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=prompt-builder-KJKFCGM7.js.map
|