spora 0.2.17 → 0.2.18

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.
Files changed (28) hide show
  1. package/dist/{chunk-DHT5ORFX.js → chunk-BPGPE2B5.js} +2 -2
  2. package/dist/{chunk-GBOY5OQ6.js → chunk-KRVHRSYY.js} +2 -2
  3. package/dist/{chunk-PQAAEOB7.js → chunk-ZFD5JT4K.js} +4 -65
  4. package/dist/chunk-ZFD5JT4K.js.map +1 -0
  5. package/dist/cli.js +24 -24
  6. package/dist/{client-OCIEKWMN.js → client-T7JWM2MW.js} +65 -132
  7. package/dist/client-T7JWM2MW.js.map +1 -0
  8. package/dist/{colony-4G3JMXXW.js → colony-DODTWT55.js} +2 -2
  9. package/dist/{decision-engine-TEYVBE7F.js → decision-engine-LX24GFKR.js} +4 -5
  10. package/dist/{heartbeat-5TQ5BVHQ.js → heartbeat-ZI4HMZ4W.js} +4 -4
  11. package/dist/{init-XLNIBVHD.js → init-WOV5OZ6B.js} +3 -3
  12. package/dist/mcp-server.js +19 -19
  13. package/dist/{queue-YEVE53NQ.js → queue-3B7JOVOW.js} +2 -2
  14. package/dist/web-chat/logo.png +0 -0
  15. package/dist/{web-chat-QHJUEMBU.js → web-chat-AU2ZT3J7.js} +5 -5
  16. package/dist/{x-client-YE6QFHEN.js → x-client-RE4RFQ7T.js} +2 -2
  17. package/package.json +1 -1
  18. package/dist/chunk-PQAAEOB7.js.map +0 -1
  19. package/dist/client-OCIEKWMN.js.map +0 -1
  20. /package/dist/{chunk-DHT5ORFX.js.map → chunk-BPGPE2B5.js.map} +0 -0
  21. /package/dist/{chunk-GBOY5OQ6.js.map → chunk-KRVHRSYY.js.map} +0 -0
  22. /package/dist/{colony-4G3JMXXW.js.map → colony-DODTWT55.js.map} +0 -0
  23. /package/dist/{decision-engine-TEYVBE7F.js.map → decision-engine-LX24GFKR.js.map} +0 -0
  24. /package/dist/{heartbeat-5TQ5BVHQ.js.map → heartbeat-ZI4HMZ4W.js.map} +0 -0
  25. /package/dist/{init-XLNIBVHD.js.map → init-WOV5OZ6B.js.map} +0 -0
  26. /package/dist/{queue-YEVE53NQ.js.map → queue-3B7JOVOW.js.map} +0 -0
  27. /package/dist/{web-chat-QHJUEMBU.js.map → web-chat-AU2ZT3J7.js.map} +0 -0
  28. /package/dist/{x-client-YE6QFHEN.js.map → x-client-RE4RFQ7T.js.map} +0 -0
@@ -11,7 +11,7 @@ async function getXClient() {
11
11
  if (clientInstance) return clientInstance;
12
12
  const config = loadConfig();
13
13
  if (config.xMethod === "api") {
14
- const { XApiClient } = await import("./client-OCIEKWMN.js");
14
+ const { XApiClient } = await import("./client-T7JWM2MW.js");
15
15
  clientInstance = new XApiClient();
16
16
  logger.info("X client initialized: API mode");
17
17
  } else {
@@ -29,4 +29,4 @@ export {
29
29
  getXClient,
30
30
  resetXClient
31
31
  };
32
- //# sourceMappingURL=chunk-DHT5ORFX.js.map
32
+ //# sourceMappingURL=chunk-BPGPE2B5.js.map
@@ -67,7 +67,7 @@ async function flushQueue() {
67
67
  const now = /* @__PURE__ */ new Date();
68
68
  let posted = 0;
69
69
  let failed = 0;
70
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
70
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
71
71
  const client = await getXClient();
72
72
  for (const entry of queue.entries) {
73
73
  if (entry.status !== "pending") continue;
@@ -121,4 +121,4 @@ export {
121
121
  flushQueue,
122
122
  showQueue
123
123
  };
124
- //# sourceMappingURL=chunk-GBOY5OQ6.js.map
124
+ //# sourceMappingURL=chunk-KRVHRSYY.js.map
@@ -1,12 +1,9 @@
1
1
  import {
2
2
  getXClient
3
- } from "./chunk-DHT5ORFX.js";
3
+ } from "./chunk-BPGPE2B5.js";
4
4
  import {
5
5
  addToQueue
6
- } from "./chunk-GBOY5OQ6.js";
7
- import {
8
- rateLimiter
9
- } from "./chunk-C3INKEY6.js";
6
+ } from "./chunk-KRVHRSYY.js";
10
7
  import {
11
8
  loadIdentity,
12
9
  saveIdentity
@@ -15,8 +12,7 @@ import {
15
12
  logger
16
13
  } from "./chunk-KELPENM3.js";
17
14
  import {
18
- addLearning,
19
- logInteraction
15
+ addLearning
20
16
  } from "./chunk-EBO4F5NU.js";
21
17
 
22
18
  // src/runtime/decision-engine.ts
@@ -52,22 +48,9 @@ async function executeAction(action) {
52
48
  if (action.content.length > 280) {
53
49
  return { action: type, success: false, error: `Tweet too long: ${action.content.length} chars (max 280)` };
54
50
  }
55
- if (!rateLimiter.canPost()) {
56
- return { action: type, success: false, error: "No credits remaining this month" };
57
- }
58
51
  const client = await getXClient();
59
52
  const result = await client.postTweet(action.content);
60
53
  if (result.success) {
61
- rateLimiter.consume(1);
62
- logInteraction({
63
- id: `int-${Date.now()}`,
64
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
65
- type: "post",
66
- tweetId: result.tweetId,
67
- content: action.content,
68
- creditsUsed: 1,
69
- success: true
70
- });
71
54
  logger.info(`Posted: "${action.content.slice(0, 50)}..."`);
72
55
  }
73
56
  return { action: type, success: result.success, detail: result.tweetId, error: result.error };
@@ -76,23 +59,9 @@ async function executeAction(action) {
76
59
  if (!action.tweetId || !action.content) {
77
60
  return { action: type, success: false, error: "Missing tweetId or content" };
78
61
  }
79
- if (!rateLimiter.canPost()) {
80
- return { action: type, success: false, error: "No credits remaining" };
81
- }
82
62
  const client = await getXClient();
83
63
  const result = await client.replyToTweet(action.tweetId, action.content);
84
64
  if (result.success) {
85
- rateLimiter.consume(1);
86
- logInteraction({
87
- id: `int-${Date.now()}`,
88
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
89
- type: "reply",
90
- tweetId: result.tweetId,
91
- inReplyTo: action.tweetId,
92
- content: action.content,
93
- creditsUsed: 1,
94
- success: true
95
- });
96
65
  logger.info(`Replied to ${action.tweetId}: "${action.content.slice(0, 50)}..."`);
97
66
  }
98
67
  return { action: type, success: result.success, detail: result.tweetId, error: result.error };
@@ -101,48 +70,18 @@ async function executeAction(action) {
101
70
  if (!action.tweetId) return { action: type, success: false, error: "Missing tweetId" };
102
71
  const client = await getXClient();
103
72
  const result = await client.likeTweet(action.tweetId);
104
- if (result.success) {
105
- logInteraction({
106
- id: `int-${Date.now()}`,
107
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
108
- type: "like",
109
- tweetId: action.tweetId,
110
- creditsUsed: 0,
111
- success: true
112
- });
113
- }
114
73
  return { action: type, success: result.success, error: result.error };
115
74
  }
116
75
  case "retweet": {
117
76
  if (!action.tweetId) return { action: type, success: false, error: "Missing tweetId" };
118
77
  const client = await getXClient();
119
78
  const result = await client.retweet(action.tweetId);
120
- if (result.success) {
121
- logInteraction({
122
- id: `int-${Date.now()}`,
123
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
124
- type: "retweet",
125
- tweetId: action.tweetId,
126
- creditsUsed: 0,
127
- success: true
128
- });
129
- }
130
79
  return { action: type, success: result.success, error: result.error };
131
80
  }
132
81
  case "follow": {
133
82
  if (!action.handle) return { action: type, success: false, error: "Missing handle" };
134
83
  const client = await getXClient();
135
84
  const result = await client.followUser(action.handle);
136
- if (result.success) {
137
- logInteraction({
138
- id: `int-${Date.now()}`,
139
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
140
- type: "follow",
141
- targetHandle: action.handle,
142
- creditsUsed: 0,
143
- success: true
144
- });
145
- }
146
85
  return { action: type, success: result.success, error: result.error };
147
86
  }
148
87
  case "schedule": {
@@ -198,4 +137,4 @@ export {
198
137
  executeAction,
199
138
  executeActions
200
139
  };
201
- //# sourceMappingURL=chunk-PQAAEOB7.js.map
140
+ //# sourceMappingURL=chunk-ZFD5JT4K.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/decision-engine.ts"],"sourcesContent":["import { logger } from \"../utils/logger.js\";\nimport { getXClient } from \"../x-client/index.js\";\nimport { logInteraction, 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 scheduledFor?: 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 // Extract JSON array from the response (may be wrapped in markdown code blocks)\n const jsonMatch = llmResponse.match(/\\[[\\s\\S]*?\\]/);\n if (!jsonMatch) {\n // Try to parse as a single action object\n const objMatch = llmResponse.match(/\\{[\\s\\S]*?\\}/);\n if (objMatch) {\n try {\n return [JSON.parse(objMatch[0]) as AgentAction];\n } catch {\n logger.warn(\"Could not parse LLM response as action object\");\n return [];\n }\n }\n logger.warn(\"No JSON found in LLM response\");\n return [];\n }\n\n try {\n const actions = JSON.parse(jsonMatch[0]) as AgentAction[];\n return Array.isArray(actions) ? actions : [actions];\n } catch {\n logger.warn(\"Failed to parse actions JSON from LLM response\");\n return [];\n }\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) {\n logger.info(`Posted: \"${action.content.slice(0, 50)}...\"`);\n }\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\n const client = await getXClient();\n const result = await client.replyToTweet(action.tweetId, action.content);\n if (result.success) {\n logger.info(`Replied to ${action.tweetId}: \"${action.content.slice(0, 50)}...\"`);\n }\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, action.scheduledFor);\n const time = new Date(entry.scheduledFor).toLocaleTimeString(\"en-US\", { hour: \"numeric\", minute: \"2-digit\" });\n logger.info(`Scheduled: \"${action.content.slice(0, 50)}...\" for ${time}`);\n return { action: type, success: true, detail: `Queued for ${time}` };\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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AE,QAAQ,MAAM,SAAS,MAAM,QAAQ,OAAO,UAAU,OAAO,UAAU;AAAA,MAClF;AAAA,MAEA;AACE,eAAO,KAAK,mBAAmB,IAAI,EAAE;AACrC,eAAO,EAAE,QAAQ,MAAM,SAAS,OAAO,OAAO,mBAAmB,IAAI,GAAG;AAAA,IAC5E;AAAA,EACF,SAAS,OAAO;AACd,UAAM,MAAO,MAAgB;AAC7B,WAAO,MAAM,UAAU,IAAI,YAAY,GAAG,EAAE;AAC5C,WAAO,EAAE,QAAQ,MAAM,SAAS,OAAO,OAAO,IAAI;AAAA,EACpD;AACF;AAEA,eAAsB,eAAe,SAAiD;AACpF,QAAM,UAA0B,CAAC;AACjC,aAAW,UAAU,SAAS;AAC5B,UAAM,SAAS,MAAM,cAAc,MAAM;AACzC,YAAQ,KAAK,MAAM;AAEnB,UAAM,IAAI,QAAQ,CAAC,MAAM,WAAW,GAAG,MAAO,KAAK,OAAO,IAAI,GAAI,CAAC;AAAA,EACrE;AACA,SAAO;AACT;","names":[]}
package/dist/cli.js CHANGED
@@ -123,7 +123,7 @@ program.command("init").description("Set up X account credentials for your Spore
123
123
  console.log(chalk.cyan(BANNER));
124
124
  console.log(chalk.bold("Welcome to Spora."));
125
125
  console.log(chalk.gray("The global town square for AI agents.\n"));
126
- const { runInit } = await import("./init-XLNIBVHD.js");
126
+ const { runInit } = await import("./init-WOV5OZ6B.js");
127
127
  await runInit(opts.token);
128
128
  });
129
129
  program.command("serve").description("Start the Spora MCP server (stdio)").action(async () => {
@@ -135,7 +135,7 @@ program.command("chat").description("Open web-based chat interface with your Spo
135
135
  console.log(chalk.red("\u2717 No identity found. Run `spora create` first."));
136
136
  process.exit(1);
137
137
  }
138
- const { startWebChat } = await import("./web-chat-QHJUEMBU.js");
138
+ const { startWebChat } = await import("./web-chat-AU2ZT3J7.js");
139
139
  await startWebChat();
140
140
  });
141
141
  program.command("tui").description("Start terminal-based chat interface (TUI)").action(async () => {
@@ -278,7 +278,7 @@ program.command("journal").description("Add a reflection to the evolution journa
278
278
  });
279
279
  program.command("post").description("Post a tweet").argument("<content>", "Tweet content (max 280 chars)").action(async (content) => {
280
280
  try {
281
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
281
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
282
282
  const client = await getXClient();
283
283
  const result = await client.postTweet(content);
284
284
  console.log(JSON.stringify(result, null, 2));
@@ -289,7 +289,7 @@ program.command("post").description("Post a tweet").argument("<content>", "Tweet
289
289
  });
290
290
  program.command("reply").description("Reply to a tweet").argument("<tweetId>", "Tweet ID to reply to").argument("<content>", "Reply content").action(async (tweetId, content) => {
291
291
  try {
292
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
292
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
293
293
  const client = await getXClient();
294
294
  const result = await client.replyToTweet(tweetId, content);
295
295
  console.log(JSON.stringify(result, null, 2));
@@ -300,7 +300,7 @@ program.command("reply").description("Reply to a tweet").argument("<tweetId>", "
300
300
  });
301
301
  program.command("like").description("Like a tweet").argument("<tweetId>", "Tweet ID").action(async (tweetId) => {
302
302
  try {
303
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
303
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
304
304
  const client = await getXClient();
305
305
  const result = await client.likeTweet(tweetId);
306
306
  console.log(JSON.stringify(result, null, 2));
@@ -311,7 +311,7 @@ program.command("like").description("Like a tweet").argument("<tweetId>", "Tweet
311
311
  });
312
312
  program.command("retweet").description("Retweet a tweet").argument("<tweetId>", "Tweet ID").action(async (tweetId) => {
313
313
  try {
314
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
314
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
315
315
  const client = await getXClient();
316
316
  const result = await client.retweet(tweetId);
317
317
  console.log(JSON.stringify(result, null, 2));
@@ -322,7 +322,7 @@ program.command("retweet").description("Retweet a tweet").argument("<tweetId>",
322
322
  });
323
323
  program.command("follow").description("Follow a user").argument("<handle>", "User handle or ID").action(async (handle) => {
324
324
  try {
325
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
325
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
326
326
  const client = await getXClient();
327
327
  const result = await client.followUser(handle);
328
328
  console.log(JSON.stringify(result, null, 2));
@@ -333,7 +333,7 @@ program.command("follow").description("Follow a user").argument("<handle>", "Use
333
333
  });
334
334
  program.command("unfollow").description("Unfollow a user").argument("<handle>", "User handle or ID").action(async (handle) => {
335
335
  try {
336
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
336
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
337
337
  const client = await getXClient();
338
338
  const result = await client.unfollowUser(handle);
339
339
  console.log(JSON.stringify(result, null, 2));
@@ -344,7 +344,7 @@ program.command("unfollow").description("Unfollow a user").argument("<handle>",
344
344
  });
345
345
  program.command("timeline").description("Read home timeline").option("-c, --count <n>", "Number of tweets", "20").action(async (opts) => {
346
346
  try {
347
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
347
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
348
348
  const client = await getXClient();
349
349
  const result = await client.getTimeline({ count: parseInt(opts.count) });
350
350
  console.log(JSON.stringify(result, null, 2));
@@ -355,7 +355,7 @@ program.command("timeline").description("Read home timeline").option("-c, --coun
355
355
  });
356
356
  program.command("mentions").description("Read mentions").option("-c, --count <n>", "Number of mentions", "20").action(async (opts) => {
357
357
  try {
358
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
358
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
359
359
  const client = await getXClient();
360
360
  const result = await client.getMentions({ count: parseInt(opts.count) });
361
361
  console.log(JSON.stringify(result, null, 2));
@@ -366,7 +366,7 @@ program.command("mentions").description("Read mentions").option("-c, --count <n>
366
366
  });
367
367
  program.command("search").description("Search for tweets").argument("<query>", "Search query").option("-c, --count <n>", "Number of results", "20").action(async (query, opts) => {
368
368
  try {
369
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
369
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
370
370
  const client = await getXClient();
371
371
  const result = await client.searchTweets(query, { count: parseInt(opts.count) });
372
372
  console.log(JSON.stringify(result, null, 2));
@@ -377,7 +377,7 @@ program.command("search").description("Search for tweets").argument("<query>", "
377
377
  });
378
378
  program.command("profile").description("Get a user's X profile").argument("<handle>", "X handle (without @)").action(async (handle) => {
379
379
  try {
380
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
380
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
381
381
  const client = await getXClient();
382
382
  const result = await client.getProfile(handle);
383
383
  console.log(JSON.stringify(result, null, 2));
@@ -443,7 +443,7 @@ program.command("note").description("Add a relationship note about someone").arg
443
443
  });
444
444
  program.command("schedule").description("Queue a post for later").argument("<content>", "Tweet content").option("--at <datetime>", "ISO datetime to post at").action(async (content, opts) => {
445
445
  try {
446
- const { addToQueue } = await import("./queue-YEVE53NQ.js");
446
+ const { addToQueue } = await import("./queue-3B7JOVOW.js");
447
447
  const entry = addToQueue(content, opts.at);
448
448
  console.log(JSON.stringify({ success: true, id: entry.id, scheduledFor: entry.scheduledFor }));
449
449
  } catch (error) {
@@ -453,7 +453,7 @@ program.command("schedule").description("Queue a post for later").argument("<con
453
453
  });
454
454
  program.command("flush").description("Post all queued items whose time has come").action(async () => {
455
455
  try {
456
- const { flushQueue } = await import("./queue-YEVE53NQ.js");
456
+ const { flushQueue } = await import("./queue-3B7JOVOW.js");
457
457
  const results = await flushQueue();
458
458
  console.log(JSON.stringify(results, null, 2));
459
459
  } catch (error) {
@@ -462,13 +462,13 @@ program.command("flush").description("Post all queued items whose time has come"
462
462
  }
463
463
  });
464
464
  program.command("queue").description("Show scheduled posts").action(async () => {
465
- const { showQueue } = await import("./queue-YEVE53NQ.js");
465
+ const { showQueue } = await import("./queue-3B7JOVOW.js");
466
466
  showQueue();
467
467
  });
468
468
  var colony = program.command("colony").description("Colony commands");
469
469
  colony.command("checkin").description("Check into The Colony \u2014 sync memory, discover Spores").option("-m, --message <msg>", "Optional message to post").action(async (opts) => {
470
470
  try {
471
- const { colonyCheckin } = await import("./colony-4G3JMXXW.js");
471
+ const { colonyCheckin } = await import("./colony-DODTWT55.js");
472
472
  const result = await colonyCheckin(opts.message);
473
473
  console.log(JSON.stringify(result, null, 2));
474
474
  } catch (error) {
@@ -487,7 +487,7 @@ colony.command("memory").description("Read the Colony's shared memory").action(a
487
487
  });
488
488
  colony.command("plans").description("Get all active Colony plans").action(async () => {
489
489
  try {
490
- const { getActivePlans } = await import("./colony-4G3JMXXW.js");
490
+ const { getActivePlans } = await import("./colony-DODTWT55.js");
491
491
  const plans = getActivePlans();
492
492
  console.log(plans.length > 0 ? JSON.stringify(plans, null, 2) : JSON.stringify({ message: "No active plans. Propose one!" }));
493
493
  } catch (error) {
@@ -497,7 +497,7 @@ colony.command("plans").description("Get all active Colony plans").action(async
497
497
  });
498
498
  colony.command("propose").description("Propose a coordinated plan").argument("<description>", "What's the plan?").action(async (description) => {
499
499
  try {
500
- const { proposePlan } = await import("./colony-4G3JMXXW.js");
500
+ const { proposePlan } = await import("./colony-DODTWT55.js");
501
501
  const result = await proposePlan(description);
502
502
  console.log(JSON.stringify(result, null, 2));
503
503
  } catch (error) {
@@ -507,7 +507,7 @@ colony.command("propose").description("Propose a coordinated plan").argument("<d
507
507
  });
508
508
  colony.command("join").description("Join an active plan").argument("<planId>", "Plan ID").action(async (planId) => {
509
509
  try {
510
- const { joinPlan } = await import("./colony-4G3JMXXW.js");
510
+ const { joinPlan } = await import("./colony-DODTWT55.js");
511
511
  const result = await joinPlan(planId);
512
512
  console.log(JSON.stringify(result, null, 2));
513
513
  } catch (error) {
@@ -517,7 +517,7 @@ colony.command("join").description("Join an active plan").argument("<planId>", "
517
517
  });
518
518
  colony.command("post-status").description("Post a status update to the Colony").argument("<status>", "Your status").action(async (status) => {
519
519
  try {
520
- const { postStatus } = await import("./colony-4G3JMXXW.js");
520
+ const { postStatus } = await import("./colony-DODTWT55.js");
521
521
  const result = await postStatus(status);
522
522
  console.log(JSON.stringify(result, null, 2));
523
523
  } catch (error) {
@@ -527,7 +527,7 @@ colony.command("post-status").description("Post a status update to the Colony").
527
527
  });
528
528
  colony.command("activity").description("Get today's Colony activity").action(async () => {
529
529
  try {
530
- const { getTodaysActivity } = await import("./colony-4G3JMXXW.js");
530
+ const { getTodaysActivity } = await import("./colony-DODTWT55.js");
531
531
  const activity = getTodaysActivity();
532
532
  console.log(activity.length > 0 ? JSON.stringify(activity, null, 2) : JSON.stringify({ message: "No Colony activity today yet." }));
533
533
  } catch (error) {
@@ -557,11 +557,11 @@ program.command("start").description("Start the autonomous Spora agent").option(
557
557
  }
558
558
  console.log(chalk.cyan(BANNER));
559
559
  console.log(chalk.bold("Starting Spora agent...\n"));
560
- const { startHeartbeatLoop } = await import("./heartbeat-5TQ5BVHQ.js");
560
+ const { startHeartbeatLoop } = await import("./heartbeat-ZI4HMZ4W.js");
561
561
  await startHeartbeatLoop();
562
562
  });
563
563
  program.command("stop").description("Stop the running Spora agent").action(async () => {
564
- const { getRunningPid, requestStop } = await import("./heartbeat-5TQ5BVHQ.js");
564
+ const { getRunningPid, requestStop } = await import("./heartbeat-ZI4HMZ4W.js");
565
565
  const pid = getRunningPid();
566
566
  if (!pid) {
567
567
  console.log(JSON.stringify({ message: "Spora agent is not running." }));
@@ -599,7 +599,7 @@ program.command("set-llm-key").description("Set your Anthropic API key for the a
599
599
  console.log(JSON.stringify({ success: true, message: "LLM API key saved." }));
600
600
  });
601
601
  program.command("agent-status").description("Check if the Spora agent is running").action(async () => {
602
- const { getRunningPid } = await import("./heartbeat-5TQ5BVHQ.js");
602
+ const { getRunningPid } = await import("./heartbeat-ZI4HMZ4W.js");
603
603
  const pid = getRunningPid();
604
604
  const { hasLLMKey } = await import("./llm-WLEJLNEA.js");
605
605
  console.log(JSON.stringify({
@@ -18,55 +18,33 @@ import {
18
18
  import "./chunk-53YLFYJF.js";
19
19
 
20
20
  // src/x-client/api/client.ts
21
- var BASE_URL = "https://api.twitter.com/2";
21
+ import { TwitterApi } from "twitter-api-v2";
22
22
  var XApiClient = class {
23
- bearerToken;
24
- accessToken;
25
- accessTokenSecret;
26
- apiKey;
27
- apiSecret;
23
+ client;
28
24
  userId = null;
29
25
  constructor() {
30
26
  const creds = loadCredentials();
31
27
  if (creds.method !== "api") {
32
28
  throw new Error("API client requires API credentials. Current method: browser");
33
29
  }
34
- this.bearerToken = creds.bearerToken;
35
- this.accessToken = creds.accessToken;
36
- this.accessTokenSecret = creds.accessTokenSecret;
37
- this.apiKey = creds.apiKey;
38
- this.apiSecret = creds.apiSecret;
39
- }
40
- async request(endpoint, options = {}) {
41
- const { method = "GET", body, useOAuth = false } = options;
42
- const url = `${BASE_URL}${endpoint}`;
43
- const headers = {
44
- "Content-Type": "application/json"
45
- };
46
- if (useOAuth) {
47
- headers["Authorization"] = `Bearer ${this.bearerToken}`;
48
- } else {
49
- headers["Authorization"] = `Bearer ${this.bearerToken}`;
50
- }
51
- const response = await fetch(url, {
52
- method,
53
- headers,
54
- body: body ? JSON.stringify(body) : void 0
30
+ this.client = new TwitterApi({
31
+ appKey: creds.apiKey,
32
+ appSecret: creds.apiSecret,
33
+ accessToken: creds.accessToken,
34
+ accessSecret: creds.accessTokenSecret
55
35
  });
56
- if (!response.ok) {
57
- const errorBody = await response.text();
58
- throw new Error(`X API error ${response.status}: ${errorBody}`);
59
- }
60
- return response.json();
61
36
  }
62
37
  async getUserId() {
63
38
  if (this.userId) return this.userId;
64
39
  const handle = this.getHandle();
65
- const result = await this.request(
66
- `/users/by/username/${handle}`
67
- );
68
- this.userId = result.data.id;
69
- return this.userId;
40
+ try {
41
+ const user = await this.client.v2.userByUsername(handle);
42
+ this.userId = user.data.id;
43
+ return this.userId;
44
+ } catch (error) {
45
+ logger.error("Failed to get user ID", error);
46
+ throw error;
47
+ }
70
48
  }
71
49
  getHandle() {
72
50
  if (identityExists()) {
@@ -81,11 +59,7 @@ var XApiClient = class {
81
59
  return { success: false, error: "Monthly post limit reached" };
82
60
  }
83
61
  try {
84
- const result = await this.request("/tweets", {
85
- method: "POST",
86
- body: { text: content },
87
- useOAuth: true
88
- });
62
+ const result = await this.client.v2.tweet(content);
89
63
  rateLimiter.consume();
90
64
  logInteraction({
91
65
  id: `int-${Date.now()}`,
@@ -107,14 +81,7 @@ var XApiClient = class {
107
81
  return { success: false, error: "Monthly post limit reached" };
108
82
  }
109
83
  try {
110
- const result = await this.request("/tweets", {
111
- method: "POST",
112
- body: {
113
- text: content,
114
- reply: { in_reply_to_tweet_id: tweetId }
115
- },
116
- useOAuth: true
117
- });
84
+ const result = await this.client.v2.reply(content, tweetId);
118
85
  rateLimiter.consume();
119
86
  logInteraction({
120
87
  id: `int-${Date.now()}`,
@@ -134,10 +101,7 @@ var XApiClient = class {
134
101
  }
135
102
  async deleteTweet(tweetId) {
136
103
  try {
137
- await this.request(`/tweets/${tweetId}`, {
138
- method: "DELETE",
139
- useOAuth: true
140
- });
104
+ await this.client.v2.deleteTweet(tweetId);
141
105
  return { success: true, tweetId };
142
106
  } catch (error) {
143
107
  return { success: false, error: error.message };
@@ -147,11 +111,7 @@ var XApiClient = class {
147
111
  rateLimiter.requireBasicTier("Like");
148
112
  try {
149
113
  const userId = await this.getUserId();
150
- await this.request(`/users/${userId}/likes`, {
151
- method: "POST",
152
- body: { tweet_id: tweetId },
153
- useOAuth: true
154
- });
114
+ await this.client.v2.like(userId, tweetId);
155
115
  logInteraction({
156
116
  id: `int-${Date.now()}`,
157
117
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -169,10 +129,7 @@ var XApiClient = class {
169
129
  rateLimiter.requireBasicTier("Unlike");
170
130
  try {
171
131
  const userId = await this.getUserId();
172
- await this.request(`/users/${userId}/likes/${tweetId}`, {
173
- method: "DELETE",
174
- useOAuth: true
175
- });
132
+ await this.client.v2.unlike(userId, tweetId);
176
133
  return { success: true, tweetId };
177
134
  } catch (error) {
178
135
  return { success: false, error: error.message };
@@ -182,11 +139,7 @@ var XApiClient = class {
182
139
  rateLimiter.requireBasicTier("Retweet");
183
140
  try {
184
141
  const userId = await this.getUserId();
185
- await this.request(`/users/${userId}/retweets`, {
186
- method: "POST",
187
- body: { tweet_id: tweetId },
188
- useOAuth: true
189
- });
142
+ await this.client.v2.retweet(userId, tweetId);
190
143
  logInteraction({
191
144
  id: `int-${Date.now()}`,
192
145
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -204,10 +157,7 @@ var XApiClient = class {
204
157
  rateLimiter.requireBasicTier("Unretweet");
205
158
  try {
206
159
  const userId = await this.getUserId();
207
- await this.request(`/users/${userId}/retweets/${tweetId}`, {
208
- method: "DELETE",
209
- useOAuth: true
210
- });
160
+ await this.client.v2.unretweet(userId, tweetId);
211
161
  return { success: true, tweetId };
212
162
  } catch (error) {
213
163
  return { success: false, error: error.message };
@@ -217,11 +167,7 @@ var XApiClient = class {
217
167
  rateLimiter.requireBasicTier("Follow");
218
168
  try {
219
169
  const myId = await this.getUserId();
220
- await this.request(`/users/${myId}/following`, {
221
- method: "POST",
222
- body: { target_user_id: userId },
223
- useOAuth: true
224
- });
170
+ await this.client.v2.follow(myId, userId);
225
171
  logInteraction({
226
172
  id: `int-${Date.now()}`,
227
173
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -239,10 +185,7 @@ var XApiClient = class {
239
185
  rateLimiter.requireBasicTier("Unfollow");
240
186
  try {
241
187
  const myId = await this.getUserId();
242
- await this.request(`/users/${myId}/following/${userId}`, {
243
- method: "DELETE",
244
- useOAuth: true
245
- });
188
+ await this.client.v2.unfollow(myId, userId);
246
189
  return { success: true };
247
190
  } catch (error) {
248
191
  return { success: false, error: error.message };
@@ -252,27 +195,24 @@ var XApiClient = class {
252
195
  rateLimiter.requireBasicTier("Read timeline");
253
196
  try {
254
197
  const userId = await this.getUserId();
255
- const params = new URLSearchParams({
256
- max_results: String(options?.count ?? 20),
257
- "tweet.fields": "created_at,public_metrics,in_reply_to_user_id",
258
- expansions: "author_id",
259
- "user.fields": "username"
198
+ const result = await this.client.v2.homeTimeline({
199
+ max_results: options?.count ?? 20,
200
+ "tweet.fields": ["created_at", "public_metrics", "in_reply_to_user_id"],
201
+ expansions: ["author_id"],
202
+ "user.fields": ["username"],
203
+ ...options?.sinceId ? { since_id: options.sinceId } : {}
260
204
  });
261
- if (options?.sinceId) params.set("since_id", options.sinceId);
262
- const result = await this.request(
263
- `/users/${userId}/timelines/reverse_chronological?${params}`
264
- );
265
- if (!result.data) return [];
205
+ if (!result.data?.data) return [];
266
206
  const userMap = /* @__PURE__ */ new Map();
267
207
  for (const user of result.includes?.users ?? []) {
268
208
  userMap.set(user.id, user.username);
269
209
  }
270
- return result.data.map((tweet) => ({
210
+ return result.data.data.map((tweet) => ({
271
211
  id: tweet.id,
272
212
  text: tweet.text,
273
- authorId: tweet.author_id,
274
- authorHandle: userMap.get(tweet.author_id) ?? "unknown",
275
- createdAt: tweet.created_at,
213
+ authorId: tweet.author_id ?? "unknown",
214
+ authorHandle: userMap.get(tweet.author_id ?? "") ?? "unknown",
215
+ createdAt: tweet.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
276
216
  likeCount: tweet.public_metrics?.like_count,
277
217
  retweetCount: tweet.public_metrics?.retweet_count,
278
218
  replyCount: tweet.public_metrics?.reply_count
@@ -286,27 +226,24 @@ var XApiClient = class {
286
226
  rateLimiter.requireBasicTier("Read mentions");
287
227
  try {
288
228
  const userId = await this.getUserId();
289
- const params = new URLSearchParams({
290
- max_results: String(options?.count ?? 20),
291
- "tweet.fields": "created_at,public_metrics",
292
- expansions: "author_id",
293
- "user.fields": "username"
229
+ const result = await this.client.v2.userMentionTimeline(userId, {
230
+ max_results: options?.count ?? 20,
231
+ "tweet.fields": ["created_at", "public_metrics"],
232
+ expansions: ["author_id"],
233
+ "user.fields": ["username"],
234
+ ...options?.sinceId ? { since_id: options.sinceId } : {}
294
235
  });
295
- if (options?.sinceId) params.set("since_id", options.sinceId);
296
- const result = await this.request(
297
- `/users/${userId}/mentions?${params}`
298
- );
299
- if (!result.data) return [];
236
+ if (!result.data?.data) return [];
300
237
  const userMap = /* @__PURE__ */ new Map();
301
238
  for (const user of result.includes?.users ?? []) {
302
239
  userMap.set(user.id, user.username);
303
240
  }
304
- return result.data.map((tweet) => ({
241
+ return result.data.data.map((tweet) => ({
305
242
  id: tweet.id,
306
243
  text: tweet.text,
307
- authorId: tweet.author_id,
308
- authorHandle: userMap.get(tweet.author_id) ?? "unknown",
309
- createdAt: tweet.created_at,
244
+ authorId: tweet.author_id ?? "unknown",
245
+ authorHandle: userMap.get(tweet.author_id ?? "") ?? "unknown",
246
+ createdAt: tweet.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
310
247
  likeCount: tweet.public_metrics?.like_count,
311
248
  retweetCount: tweet.public_metrics?.retweet_count,
312
249
  replyCount: tweet.public_metrics?.reply_count
@@ -319,27 +256,23 @@ var XApiClient = class {
319
256
  async searchTweets(query, options) {
320
257
  rateLimiter.requireBasicTier("Search tweets");
321
258
  try {
322
- const params = new URLSearchParams({
323
- query,
324
- max_results: String(options?.count ?? 20),
325
- "tweet.fields": "created_at,public_metrics",
326
- expansions: "author_id",
327
- "user.fields": "username"
259
+ const result = await this.client.v2.search(query, {
260
+ max_results: options?.count ?? 20,
261
+ "tweet.fields": ["created_at", "public_metrics"],
262
+ expansions: ["author_id"],
263
+ "user.fields": ["username"]
328
264
  });
329
- const result = await this.request(
330
- `/tweets/search/recent?${params}`
331
- );
332
- if (!result.data) return [];
265
+ if (!result.data?.data) return [];
333
266
  const userMap = /* @__PURE__ */ new Map();
334
267
  for (const user of result.includes?.users ?? []) {
335
268
  userMap.set(user.id, user.username);
336
269
  }
337
- return result.data.map((tweet) => ({
270
+ return result.data.data.map((tweet) => ({
338
271
  id: tweet.id,
339
272
  text: tweet.text,
340
- authorId: tweet.author_id,
341
- authorHandle: userMap.get(tweet.author_id) ?? "unknown",
342
- createdAt: tweet.created_at,
273
+ authorId: tweet.author_id ?? "unknown",
274
+ authorHandle: userMap.get(tweet.author_id ?? "") ?? "unknown",
275
+ createdAt: tweet.created_at ?? (/* @__PURE__ */ new Date()).toISOString(),
343
276
  likeCount: tweet.public_metrics?.like_count,
344
277
  retweetCount: tweet.public_metrics?.retweet_count,
345
278
  replyCount: tweet.public_metrics?.reply_count
@@ -351,18 +284,18 @@ var XApiClient = class {
351
284
  }
352
285
  async getProfile(handle) {
353
286
  rateLimiter.requireBasicTier("Get profile");
354
- const result = await this.request(
355
- `/users/by/username/${handle}?user.fields=description,public_metrics,verified,profile_image_url`
356
- );
287
+ const result = await this.client.v2.userByUsername(handle, {
288
+ "user.fields": ["description", "public_metrics", "verified", "profile_image_url"]
289
+ });
357
290
  return {
358
291
  id: result.data.id,
359
292
  handle: result.data.username,
360
293
  name: result.data.name,
361
- bio: result.data.description,
362
- followersCount: result.data.public_metrics.followers_count,
363
- followingCount: result.data.public_metrics.following_count,
364
- tweetCount: result.data.public_metrics.tweet_count,
365
- verified: result.data.verified,
294
+ bio: result.data.description ?? "",
295
+ followersCount: result.data.public_metrics?.followers_count ?? 0,
296
+ followingCount: result.data.public_metrics?.following_count ?? 0,
297
+ tweetCount: result.data.public_metrics?.tweet_count ?? 0,
298
+ verified: result.data.verified ?? false,
366
299
  profileImageUrl: result.data.profile_image_url
367
300
  };
368
301
  }
@@ -370,4 +303,4 @@ var XApiClient = class {
370
303
  export {
371
304
  XApiClient
372
305
  };
373
- //# sourceMappingURL=client-OCIEKWMN.js.map
306
+ //# sourceMappingURL=client-T7JWM2MW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/x-client/api/client.ts"],"sourcesContent":["import { TwitterApi } from \"twitter-api-v2\";\nimport { loadCredentials } from \"../../utils/crypto.js\";\nimport { loadConfig } from \"../../utils/config.js\";\nimport { loadIdentity, identityExists } from \"../../identity/index.js\";\nimport { logInteraction } from \"../../memory/index.js\";\nimport { rateLimiter } from \"../rate-limiter.js\";\nimport { logger } from \"../../utils/logger.js\";\nimport type {\n XClientInterface,\n Tweet,\n UserProfile,\n PostResult,\n TimelineOptions,\n SearchOptions,\n} from \"../types.js\";\n\nexport class XApiClient implements XClientInterface {\n private client: TwitterApi;\n private userId: string | null = null;\n\n constructor() {\n const creds = loadCredentials();\n if (creds.method !== \"api\") {\n throw new Error(\"API client requires API credentials. Current method: browser\");\n }\n\n // Use OAuth 1.0a User Context for all endpoints\n this.client = new TwitterApi({\n appKey: creds.apiKey!,\n appSecret: creds.apiSecret!,\n accessToken: creds.accessToken!,\n accessSecret: creds.accessTokenSecret!,\n });\n }\n\n private async getUserId(): Promise<string> {\n if (this.userId) return this.userId;\n const handle = this.getHandle();\n try {\n const user = await this.client.v2.userByUsername(handle);\n this.userId = user.data.id;\n return this.userId;\n } catch (error) {\n logger.error(\"Failed to get user ID\", error);\n throw error;\n }\n }\n\n private getHandle(): string {\n if (identityExists()) {\n return loadIdentity().handle;\n }\n const creds = loadCredentials();\n if (creds.username) return creds.username;\n throw new Error(\"No handle found. Create a Spore identity first.\");\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 result = await this.client.v2.tweet(content);\n\n rateLimiter.consume();\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"post\",\n tweetId: result.data.id,\n content,\n creditsUsed: 1,\n success: true,\n });\n\n return { success: true, tweetId: result.data.id };\n } catch (error) {\n logger.error(\"Failed to post tweet\", error);\n return { success: false, error: (error as Error).message };\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 result = await this.client.v2.reply(content, tweetId);\n\n rateLimiter.consume();\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"reply\",\n tweetId: result.data.id,\n inReplyTo: tweetId,\n content,\n creditsUsed: 1,\n success: true,\n });\n\n return { success: true, tweetId: result.data.id };\n } catch (error) {\n logger.error(\"Failed to reply\", error);\n return { success: false, error: (error as Error).message };\n }\n }\n\n async deleteTweet(tweetId: string): Promise<PostResult> {\n try {\n await this.client.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 rateLimiter.requireBasicTier(\"Like\");\n try {\n const userId = await this.getUserId();\n await this.client.v2.like(userId, 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 rateLimiter.requireBasicTier(\"Unlike\");\n try {\n const userId = await this.getUserId();\n await this.client.v2.unlike(userId, 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 rateLimiter.requireBasicTier(\"Retweet\");\n try {\n const userId = await this.getUserId();\n await this.client.v2.retweet(userId, 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 rateLimiter.requireBasicTier(\"Unretweet\");\n try {\n const userId = await this.getUserId();\n await this.client.v2.unretweet(userId, tweetId);\n return { success: true, tweetId };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async followUser(userId: string): Promise<PostResult> {\n rateLimiter.requireBasicTier(\"Follow\");\n try {\n const myId = await this.getUserId();\n await this.client.v2.follow(myId, userId);\n\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"follow\",\n targetUserId: userId,\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(userId: string): Promise<PostResult> {\n rateLimiter.requireBasicTier(\"Unfollow\");\n try {\n const myId = await this.getUserId();\n await this.client.v2.unfollow(myId, userId);\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 rateLimiter.requireBasicTier(\"Read timeline\");\n try {\n const userId = await this.getUserId();\n const result = await this.client.v2.homeTimeline({\n max_results: options?.count ?? 20,\n \"tweet.fields\": [\"created_at\", \"public_metrics\", \"in_reply_to_user_id\"],\n expansions: [\"author_id\"],\n \"user.fields\": [\"username\"],\n ...(options?.sinceId ? { since_id: options.sinceId } : {}),\n });\n\n if (!result.data?.data) return [];\n\n const userMap = new Map<string, string>();\n for (const user of result.includes?.users ?? []) {\n userMap.set(user.id, user.username);\n }\n\n return result.data.data.map((tweet) => ({\n id: tweet.id,\n text: tweet.text,\n authorId: tweet.author_id ?? \"unknown\",\n authorHandle: userMap.get(tweet.author_id ?? \"\") ?? \"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 }));\n } catch (error) {\n logger.error(\"Failed to read timeline\", error);\n return [];\n }\n }\n\n async getMentions(options?: TimelineOptions): Promise<Tweet[]> {\n rateLimiter.requireBasicTier(\"Read mentions\");\n try {\n const userId = await this.getUserId();\n const result = await this.client.v2.userMentionTimeline(userId, {\n max_results: options?.count ?? 20,\n \"tweet.fields\": [\"created_at\", \"public_metrics\"],\n expansions: [\"author_id\"],\n \"user.fields\": [\"username\"],\n ...(options?.sinceId ? { since_id: options.sinceId } : {}),\n });\n\n if (!result.data?.data) return [];\n\n const userMap = new Map<string, string>();\n for (const user of result.includes?.users ?? []) {\n userMap.set(user.id, user.username);\n }\n\n return result.data.data.map((tweet) => ({\n id: tweet.id,\n text: tweet.text,\n authorId: tweet.author_id ?? \"unknown\",\n authorHandle: userMap.get(tweet.author_id ?? \"\") ?? \"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 }));\n } catch (error) {\n logger.error(\"Failed to read mentions\", error);\n return [];\n }\n }\n\n async searchTweets(query: string, options?: SearchOptions): Promise<Tweet[]> {\n rateLimiter.requireBasicTier(\"Search tweets\");\n try {\n const result = await this.client.v2.search(query, {\n max_results: options?.count ?? 20,\n \"tweet.fields\": [\"created_at\", \"public_metrics\"],\n expansions: [\"author_id\"],\n \"user.fields\": [\"username\"],\n });\n\n if (!result.data?.data) return [];\n\n const userMap = new Map<string, string>();\n for (const user of result.includes?.users ?? []) {\n userMap.set(user.id, user.username);\n }\n\n return result.data.data.map((tweet) => ({\n id: tweet.id,\n text: tweet.text,\n authorId: tweet.author_id ?? \"unknown\",\n authorHandle: userMap.get(tweet.author_id ?? \"\") ?? \"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 }));\n } catch (error) {\n logger.error(\"Failed to search tweets\", error);\n return [];\n }\n }\n\n async getProfile(handle: string): Promise<UserProfile> {\n rateLimiter.requireBasicTier(\"Get profile\");\n const result = await this.client.v2.userByUsername(handle, {\n \"user.fields\": [\"description\", \"public_metrics\", \"verified\", \"profile_image_url\"],\n });\n\n return {\n id: result.data.id,\n handle: result.data.username,\n name: result.data.name,\n bio: result.data.description ?? \"\",\n followersCount: result.data.public_metrics?.followers_count ?? 0,\n followingCount: result.data.public_metrics?.following_count ?? 0,\n tweetCount: result.data.public_metrics?.tweet_count ?? 0,\n verified: result.data.ver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AAM,eAAc,oBAAI,KAAK,GAAE,YAAY;AAAA,QACtD,WAAW,MAAM,gBAAgB;AAAA,QACjC,cAAc,MAAM,gBAAgB;AAAA,QACpC,YAAY,MAAM,gBAAgB;AAAA,MACpC,EAAE;AAAA,IACJ,SAAS,OAAO;AACd,aAAO,MAAM,2BAA2B,KAAK;AAC7C,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,QAAsC;AACrD,gBAAY,iBAAiB,aAAa;AAC1C,UAAM,SAAS,MAAM,KAAK,OAAO,GAAG,eAAe,QAAQ;AAAA,MACzD,eAAe,CAAC,eAAe,kBAAkB,YAAY,mBAAmB;AAAA,IAClF,CAAC;AAED,WAAO;AAAA,MACL,IAAI,OAAO,KAAK;AAAA,MAChB,QAAQ,OAAO,KAAK;AAAA,MACpB,MAAM,OAAO,KAAK;AAAA,MAClB,KAAK,OAAO,KAAK,eAAe;AAAA,MAChC,gBAAgB,OAAO,KAAK,gBAAgB,mBAAmB;AAAA,MAC/D,gBAAgB,OAAO,KAAK,gBAAgB,mBAAmB;AAAA,MAC/D,YAAY,OAAO,KAAK,gBAAgB,eAAe;AAAA,MACvD,UAAU,OAAO,KAAK,YAAY;AAAA,MAClC,iBAAiB,OAAO,KAAK;AAAA,IAC/B;AAAA,EACF;AACF;","names":[]}
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-AHXZIGQE.js";
11
11
  import {
12
12
  getXClient
13
- } from "./chunk-DHT5ORFX.js";
13
+ } from "./chunk-BPGPE2B5.js";
14
14
  import "./chunk-RCJQI7FR.js";
15
15
  import {
16
16
  loadIdentity
@@ -226,4 +226,4 @@ export {
226
226
  postStatus,
227
227
  proposePlan
228
228
  };
229
- //# sourceMappingURL=colony-4G3JMXXW.js.map
229
+ //# sourceMappingURL=colony-DODTWT55.js.map
@@ -2,10 +2,9 @@ import {
2
2
  executeAction,
3
3
  executeActions,
4
4
  parseActions
5
- } from "./chunk-PQAAEOB7.js";
6
- import "./chunk-DHT5ORFX.js";
7
- import "./chunk-GBOY5OQ6.js";
8
- import "./chunk-C3INKEY6.js";
5
+ } from "./chunk-ZFD5JT4K.js";
6
+ import "./chunk-BPGPE2B5.js";
7
+ import "./chunk-KRVHRSYY.js";
9
8
  import "./chunk-RCJQI7FR.js";
10
9
  import "./chunk-AIEXQCQS.js";
11
10
  import "./chunk-KELPENM3.js";
@@ -16,4 +15,4 @@ export {
16
15
  executeActions,
17
16
  parseActions
18
17
  };
19
- //# sourceMappingURL=decision-engine-TEYVBE7F.js.map
18
+ //# sourceMappingURL=decision-engine-LX24GFKR.js.map
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  executeActions,
3
3
  parseActions
4
- } from "./chunk-PQAAEOB7.js";
4
+ } from "./chunk-ZFD5JT4K.js";
5
5
  import {
6
6
  getXClient
7
- } from "./chunk-DHT5ORFX.js";
7
+ } from "./chunk-BPGPE2B5.js";
8
8
  import {
9
9
  flushQueue
10
- } from "./chunk-GBOY5OQ6.js";
10
+ } from "./chunk-KRVHRSYY.js";
11
11
  import {
12
12
  buildHeartbeatUserMessage,
13
13
  buildSystemPrompt
@@ -175,4 +175,4 @@ export {
175
175
  requestStop,
176
176
  startHeartbeatLoop
177
177
  };
178
- //# sourceMappingURL=heartbeat-5TQ5BVHQ.js.map
178
+ //# sourceMappingURL=heartbeat-ZI4HMZ4W.js.map
@@ -203,7 +203,7 @@ async function loginFlow() {
203
203
  console.log(chalk.green("\u2713 Logged in!\n"));
204
204
  console.log(chalk.gray("Opening chat interface...\n"));
205
205
  try {
206
- const { startWebChat } = await import("./web-chat-QHJUEMBU.js");
206
+ const { startWebChat } = await import("./web-chat-AU2ZT3J7.js");
207
207
  await startWebChat();
208
208
  } catch (error) {
209
209
  console.log(chalk.yellow(`Could not start chat interface: ${error.message}
@@ -275,7 +275,7 @@ async function showDoneAndOpenChat() {
275
275
  console.log(chalk.bold.cyan("\u2501\u2501\u2501 Your Spore is Ready! \u2501\u2501\u2501\n"));
276
276
  console.log(chalk.gray("Opening chat interface...\n"));
277
277
  try {
278
- const { startWebChat } = await import("./web-chat-QHJUEMBU.js");
278
+ const { startWebChat } = await import("./web-chat-AU2ZT3J7.js");
279
279
  await startWebChat();
280
280
  } catch (error) {
281
281
  console.log(chalk.yellow(`Could not start chat interface: ${error.message}
@@ -400,4 +400,4 @@ async function runInit(token) {
400
400
  export {
401
401
  runInit
402
402
  };
403
- //# sourceMappingURL=init-XLNIBVHD.js.map
403
+ //# sourceMappingURL=init-WOV5OZ6B.js.map
@@ -388,7 +388,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
388
388
  },
389
389
  async ({ content }) => {
390
390
  try {
391
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
391
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
392
392
  const client = await getXClient();
393
393
  const result = await client.postTweet(content);
394
394
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -406,7 +406,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
406
406
  },
407
407
  async ({ tweetId, content }) => {
408
408
  try {
409
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
409
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
410
410
  const client = await getXClient();
411
411
  const result = await client.replyToTweet(tweetId, content);
412
412
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -421,7 +421,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
421
421
  { tweetId: z.string().describe("The ID of the tweet to like") },
422
422
  async ({ tweetId }) => {
423
423
  try {
424
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
424
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
425
425
  const client = await getXClient();
426
426
  const result = await client.likeTweet(tweetId);
427
427
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -436,7 +436,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
436
436
  { tweetId: z.string().describe("The ID of the tweet to retweet") },
437
437
  async ({ tweetId }) => {
438
438
  try {
439
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
439
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
440
440
  const client = await getXClient();
441
441
  const result = await client.retweet(tweetId);
442
442
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -451,7 +451,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
451
451
  { userId: z.string().describe("The user ID to follow") },
452
452
  async ({ userId }) => {
453
453
  try {
454
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
454
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
455
455
  const client = await getXClient();
456
456
  const result = await client.followUser(userId);
457
457
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -466,7 +466,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
466
466
  { userId: z.string().describe("The user ID to unfollow") },
467
467
  async ({ userId }) => {
468
468
  try {
469
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
469
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
470
470
  const client = await getXClient();
471
471
  const result = await client.unfollowUser(userId);
472
472
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -481,7 +481,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
481
481
  { count: z.number().optional().describe("Number of tweets to fetch (default 20)") },
482
482
  async ({ count }) => {
483
483
  try {
484
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
484
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
485
485
  const client = await getXClient();
486
486
  const result = await client.getTimeline({ count: count ?? 20 });
487
487
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -496,7 +496,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
496
496
  { count: z.number().optional().describe("Number of mentions to fetch (default 20)") },
497
497
  async ({ count }) => {
498
498
  try {
499
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
499
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
500
500
  const client = await getXClient();
501
501
  const result = await client.getMentions({ count: count ?? 20 });
502
502
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -514,7 +514,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
514
514
  },
515
515
  async ({ query, count }) => {
516
516
  try {
517
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
517
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
518
518
  const client = await getXClient();
519
519
  const result = await client.searchTweets(query, { count: count ?? 20 });
520
520
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -529,7 +529,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
529
529
  { handle: z.string().describe("X handle (without @)") },
530
530
  async ({ handle }) => {
531
531
  try {
532
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
532
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
533
533
  const client = await getXClient();
534
534
  const result = await client.getProfile(handle);
535
535
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
@@ -547,7 +547,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
547
547
  },
548
548
  async ({ content, scheduledFor }) => {
549
549
  try {
550
- const { addToQueue } = await import("./queue-YEVE53NQ.js");
550
+ const { addToQueue } = await import("./queue-3B7JOVOW.js");
551
551
  const entry = addToQueue(content, scheduledFor);
552
552
  return {
553
553
  content: [
@@ -565,7 +565,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
565
565
  {},
566
566
  async () => {
567
567
  try {
568
- const { flushQueue } = await import("./queue-YEVE53NQ.js");
568
+ const { flushQueue } = await import("./queue-3B7JOVOW.js");
569
569
  const results = await flushQueue();
570
570
  return {
571
571
  content: [
@@ -586,7 +586,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
586
586
  { message: z.string().optional().describe("Optional message to post to the Colony community") },
587
587
  async ({ message }) => {
588
588
  try {
589
- const { colonyCheckin } = await import("./colony-4G3JMXXW.js");
589
+ const { colonyCheckin } = await import("./colony-DODTWT55.js");
590
590
  const result = await colonyCheckin(message);
591
591
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
592
592
  } catch (error) {
@@ -600,7 +600,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
600
600
  {},
601
601
  async () => {
602
602
  try {
603
- const { getColonyMemory } = await import("./colony-4G3JMXXW.js");
603
+ const { getColonyMemory } = await import("./colony-DODTWT55.js");
604
604
  const memory = getColonyMemory();
605
605
  return { content: [{ type: "text", text: JSON.stringify(memory, null, 2) }] };
606
606
  } catch (error) {
@@ -614,7 +614,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
614
614
  {},
615
615
  async () => {
616
616
  try {
617
- const { getActivePlans } = await import("./colony-4G3JMXXW.js");
617
+ const { getActivePlans } = await import("./colony-DODTWT55.js");
618
618
  const plans = getActivePlans();
619
619
  return {
620
620
  content: [
@@ -637,7 +637,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
637
637
  },
638
638
  async ({ description }) => {
639
639
  try {
640
- const { proposePlan } = await import("./colony-4G3JMXXW.js");
640
+ const { proposePlan } = await import("./colony-DODTWT55.js");
641
641
  const result = await proposePlan(description);
642
642
  if (result.success) {
643
643
  return {
@@ -660,7 +660,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
660
660
  },
661
661
  async ({ planId }) => {
662
662
  try {
663
- const { joinPlan } = await import("./colony-4G3JMXXW.js");
663
+ const { joinPlan } = await import("./colony-DODTWT55.js");
664
664
  const result = await joinPlan(planId);
665
665
  if (result.success) {
666
666
  return { content: [{ type: "text", text: "Joined the plan! Go execute it." }] };
@@ -679,7 +679,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
679
679
  },
680
680
  async ({ status }) => {
681
681
  try {
682
- const { postStatus } = await import("./colony-4G3JMXXW.js");
682
+ const { postStatus } = await import("./colony-DODTWT55.js");
683
683
  const result = await postStatus(status);
684
684
  if (result.success) {
685
685
  return { content: [{ type: "text", text: "Status posted to the Colony." }] };
@@ -696,7 +696,7 @@ Identity saved. Your Spore is alive. Use spora_get_identity to read the full doc
696
696
  {},
697
697
  async () => {
698
698
  try {
699
- const { getTodaysActivity } = await import("./colony-4G3JMXXW.js");
699
+ const { getTodaysActivity } = await import("./colony-DODTWT55.js");
700
700
  const activity = getTodaysActivity();
701
701
  return {
702
702
  content: [
@@ -2,7 +2,7 @@ import {
2
2
  addToQueue,
3
3
  flushQueue,
4
4
  showQueue
5
- } from "./chunk-GBOY5OQ6.js";
5
+ } from "./chunk-KRVHRSYY.js";
6
6
  import "./chunk-RCJQI7FR.js";
7
7
  import "./chunk-KELPENM3.js";
8
8
  import "./chunk-53YLFYJF.js";
@@ -11,4 +11,4 @@ export {
11
11
  flushQueue,
12
12
  showQueue
13
13
  };
14
- //# sourceMappingURL=queue-YEVE53NQ.js.map
14
+ //# sourceMappingURL=queue-3B7JOVOW.js.map
Binary file
@@ -202,7 +202,7 @@ async function extractAndSaveLearnings(responseText) {
202
202
  return responseText.replace(/<<LEARN:\s*.+?>>/g, "").trim();
203
203
  }
204
204
  async function extractAndExecuteActions(responseText) {
205
- const { parseActions, executeActions } = await import("./decision-engine-TEYVBE7F.js");
205
+ const { parseActions, executeActions } = await import("./decision-engine-LX24GFKR.js");
206
206
  const jsonBlockPattern = /```json\s*([\s\S]*?)```/g;
207
207
  const blocks = [...responseText.matchAll(jsonBlockPattern)];
208
208
  const results = [];
@@ -356,11 +356,11 @@ async function startNarratedHeartbeat(server) {
356
356
  }
357
357
  }
358
358
  async function runNarratedHeartbeat(server, maxActions, intervalMs) {
359
- const { getXClient } = await import("./x-client-YE6QFHEN.js");
359
+ const { getXClient } = await import("./x-client-RE4RFQ7T.js");
360
360
  const { buildSystemPrompt, buildNarratedHeartbeatMessage } = await import("./prompt-builder-MLO55Q4I.js");
361
361
  const { generateResponse } = await import("./llm-WLEJLNEA.js");
362
- const { parseActions, executeActions } = await import("./decision-engine-TEYVBE7F.js");
363
- const { flushQueue } = await import("./queue-YEVE53NQ.js");
362
+ const { parseActions, executeActions } = await import("./decision-engine-LX24GFKR.js");
363
+ const { flushQueue } = await import("./queue-3B7JOVOW.js");
364
364
  try {
365
365
  const flushed = await flushQueue();
366
366
  if (flushed.posted > 0) {
@@ -448,4 +448,4 @@ export {
448
448
  openBrowser,
449
449
  startWebChat
450
450
  };
451
- //# sourceMappingURL=web-chat-QHJUEMBU.js.map
451
+ //# sourceMappingURL=web-chat-AU2ZT3J7.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getXClient,
3
3
  resetXClient
4
- } from "./chunk-DHT5ORFX.js";
4
+ } from "./chunk-BPGPE2B5.js";
5
5
  import "./chunk-RCJQI7FR.js";
6
6
  import "./chunk-KELPENM3.js";
7
7
  import "./chunk-53YLFYJF.js";
@@ -9,4 +9,4 @@ export {
9
9
  getXClient,
10
10
  resetXClient
11
11
  };
12
- //# sourceMappingURL=x-client-YE6QFHEN.js.map
12
+ //# sourceMappingURL=x-client-RE4RFQ7T.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spora",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "AI agents (Spores) that autonomously manage X/Twitter accounts",
5
5
  "type": "module",
6
6
  "author": "Spora",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/runtime/decision-engine.ts"],"sourcesContent":["import { logger } from \"../utils/logger.js\";\nimport { getXClient } from \"../x-client/index.js\";\nimport { logInteraction, addLearning } from \"../memory/index.js\";\nimport { loadIdentity, saveIdentity } from \"../identity/index.js\";\nimport { addToQueue } from \"../scheduler/queue.js\";\nimport { rateLimiter } from \"../x-client/rate-limiter.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 scheduledFor?: 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 // Extract JSON array from the response (may be wrapped in markdown code blocks)\n const jsonMatch = llmResponse.match(/\\[[\\s\\S]*?\\]/);\n if (!jsonMatch) {\n // Try to parse as a single action object\n const objMatch = llmResponse.match(/\\{[\\s\\S]*?\\}/);\n if (objMatch) {\n try {\n return [JSON.parse(objMatch[0]) as AgentAction];\n } catch {\n logger.warn(\"Could not parse LLM response as action object\");\n return [];\n }\n }\n logger.warn(\"No JSON found in LLM response\");\n return [];\n }\n\n try {\n const actions = JSON.parse(jsonMatch[0]) as AgentAction[];\n return Array.isArray(actions) ? actions : [actions];\n } catch {\n logger.warn(\"Failed to parse actions JSON from LLM response\");\n return [];\n }\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 if (!rateLimiter.canPost()) {\n return { action: type, success: false, error: \"No credits remaining this month\" };\n }\n\n const client = await getXClient();\n const result = await client.postTweet(action.content);\n if (result.success) {\n rateLimiter.consume(1);\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"post\",\n tweetId: result.tweetId,\n content: action.content,\n creditsUsed: 1,\n success: true,\n });\n logger.info(`Posted: \"${action.content.slice(0, 50)}...\"`);\n }\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 if (!rateLimiter.canPost()) {\n return { action: type, success: false, error: \"No credits remaining\" };\n }\n\n const client = await getXClient();\n const result = await client.replyToTweet(action.tweetId, action.content);\n if (result.success) {\n rateLimiter.consume(1);\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"reply\",\n tweetId: result.tweetId,\n inReplyTo: action.tweetId,\n content: action.content,\n creditsUsed: 1,\n success: true,\n });\n logger.info(`Replied to ${action.tweetId}: \"${action.content.slice(0, 50)}...\"`);\n }\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 if (result.success) {\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"like\",\n tweetId: action.tweetId,\n creditsUsed: 0,\n success: true,\n });\n }\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 if (result.success) {\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"retweet\",\n tweetId: action.tweetId,\n creditsUsed: 0,\n success: true,\n });\n }\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 if (result.success) {\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"follow\",\n targetHandle: action.handle,\n creditsUsed: 0,\n success: true,\n });\n }\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, action.scheduledFor);\n const time = new Date(entry.scheduledFor).toLocaleTimeString(\"en-US\", { hour: \"numeric\", minute: \"2-digit\" });\n logger.info(`Scheduled: \"${action.content.slice(0, 50)}...\" for ${time}`);\n return { action: type, success: true, detail: `Queued for ${time}` };\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyBO,SAAS,aAAa,aAAoC;AAE/D,QAAM,YAAY,YAAY,MAAM,cAAc;AAClD,MAAI,CAAC,WAAW;AAEd,UAAM,WAAW,YAAY,MAAM,cAAc;AACjD,QAAI,UAAU;AACZ,UAAI;AACF,eAAO,CAAC,KAAK,MAAM,SAAS,CAAC,CAAC,CAAgB;AAAA,MAChD,QAAQ;AACN,eAAO,KAAK,+CAA+C;AAC3D,eAAO,CAAC;AAAA,MACV;AAAA,IACF;AACA,WAAO,KAAK,+BAA+B;AAC3C,WAAO,CAAC;AAAA,EACV;AAEA,MAAI;AACF,UAAM,UAAU,KAAK,MAAM,UAAU,CAAC,CAAC;AACvC,WAAO,MAAM,QAAQ,OAAO,IAAI,UAAU,CAAC,OAAO;AAAA,EACpD,QAAQ;AACN,WAAO,KAAK,g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AW,UAAU,SAAS;AAC5B,UAAM,SAAS,MAAM,cAAc,MAAM;AACzC,YAAQ,KAAK,MAAM;AAEnB,UAAM,IAAI,QAAQ,CAAC,MAAM,WAAW,GAAG,MAAO,KAAK,OAAO,IAAI,GAAI,CAAC;AAAA,EACrE;AACA,SAAO;AACT;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/x-client/api/client.ts"],"sourcesContent":["import { loadCredentials } from \"../../utils/crypto.js\";\nimport { loadConfig } from \"../../utils/config.js\";\nimport { loadIdentity, identityExists } from \"../../identity/index.js\";\nimport { logInteraction } from \"../../memory/index.js\";\nimport { rateLimiter } from \"../rate-limiter.js\";\nimport { logger } from \"../../utils/logger.js\";\nimport type {\n XClientInterface,\n Tweet,\n UserProfile,\n PostResult,\n TimelineOptions,\n SearchOptions,\n} from \"../types.js\";\n\nconst BASE_URL = \"https://api.twitter.com/2\";\n\nexport class XApiClient implements XClientInterface {\n private bearerToken: string;\n private accessToken: string;\n private accessTokenSecret: string;\n private apiKey: string;\n private apiSecret: string;\n private userId: string | null = null;\n\n constructor() {\n const creds = loadCredentials();\n if (creds.method !== \"api\") {\n throw new Error(\"API client requires API credentials. Current method: browser\");\n }\n this.bearerToken = creds.bearerToken!;\n this.accessToken = creds.accessToken!;\n this.accessTokenSecret = creds.accessTokenSecret!;\n this.apiKey = creds.apiKey!;\n this.apiSecret = creds.apiSecret!;\n }\n\n private async request(\n endpoint: string,\n options: {\n method?: string;\n body?: unknown;\n useOAuth?: boolean;\n } = {}\n ): Promise<unknown> {\n const { method = \"GET\", body, useOAuth = false } = options;\n const url = `${BASE_URL}${endpoint}`;\n\n const headers: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n };\n\n if (useOAuth) {\n // For user-context endpoints, use OAuth 1.0a\n // In production, this would use proper OAuth 1.0a signing\n // For now, we use Bearer token for app-only endpoints\n // and will implement OAuth 1.0a signing for user endpoints\n headers[\"Authorization\"] = `Bearer ${this.bearerToken}`;\n } else {\n headers[\"Authorization\"] = `Bearer ${this.bearerToken}`;\n }\n\n const response = await fetch(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n const errorBody = await response.text();\n throw new Error(`X API error ${response.status}: ${errorBody}`);\n }\n\n return response.json();\n }\n\n private async getUserId(): Promise<string> {\n if (this.userId) return this.userId;\n const handle = this.getHandle();\n const result = (await this.request(\n `/users/by/username/${handle}`\n )) as { data: { id: string } };\n this.userId = result.data.id;\n return this.userId;\n }\n\n private getHandle(): string {\n if (identityExists()) {\n return loadIdentity().handle;\n }\n // Fallback to credentials username before identity is created\n const creds = loadCredentials();\n if (creds.username) return creds.username;\n throw new Error(\"No handle found. Create a Spore identity first.\");\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 result = (await this.request(\"/tweets\", {\n method: \"POST\",\n body: { text: content },\n useOAuth: true,\n })) as { data: { id: string } };\n\n rateLimiter.consume();\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"post\",\n tweetId: result.data.id,\n content,\n creditsUsed: 1,\n success: true,\n });\n\n return { success: true, tweetId: result.data.id };\n } catch (error) {\n logger.error(\"Failed to post tweet\", error);\n return { success: false, error: (error as Error).message };\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 result = (await this.request(\"/tweets\", {\n method: \"POST\",\n body: {\n text: content,\n reply: { in_reply_to_tweet_id: tweetId },\n },\n useOAuth: true,\n })) as { data: { id: string } };\n\n rateLimiter.consume();\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"reply\",\n tweetId: result.data.id,\n inReplyTo: tweetId,\n content,\n creditsUsed: 1,\n success: true,\n });\n\n return { success: true, tweetId: result.data.id };\n } catch (error) {\n logger.error(\"Failed to reply\", error);\n return { success: false, error: (error as Error).message };\n }\n }\n\n async deleteTweet(tweetId: string): Promise<PostResult> {\n try {\n await this.request(`/tweets/${tweetId}`, {\n method: \"DELETE\",\n useOAuth: true,\n });\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 rateLimiter.requireBasicTier(\"Like\");\n try {\n const userId = await this.getUserId();\n await this.request(`/users/${userId}/likes`, {\n method: \"POST\",\n body: { tweet_id: tweetId },\n useOAuth: true,\n });\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 rateLimiter.requireBasicTier(\"Unlike\");\n try {\n const userId = await this.getUserId();\n await this.request(`/users/${userId}/likes/${tweetId}`, {\n method: \"DELETE\",\n useOAuth: true,\n });\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 rateLimiter.requireBasicTier(\"Retweet\");\n try {\n const userId = await this.getUserId();\n await this.request(`/users/${userId}/retweets`, {\n method: \"POST\",\n body: { tweet_id: tweetId },\n useOAuth: true,\n });\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 rateLimiter.requireBasicTier(\"Unretweet\");\n try {\n const userId = await this.getUserId();\n await this.request(`/users/${userId}/retweets/${tweetId}`, {\n method: \"DELETE\",\n useOAuth: true,\n });\n return { success: true, tweetId };\n } catch (error) {\n return { success: false, error: (error as Error).message };\n }\n }\n\n async followUser(userId: string): Promise<PostResult> {\n rateLimiter.requireBasicTier(\"Follow\");\n try {\n const myId = await this.getUserId();\n await this.request(`/users/${myId}/following`, {\n method: \"POST\",\n body: { target_user_id: userId },\n useOAuth: true,\n });\n\n logInteraction({\n id: `int-${Date.now()}`,\n timestamp: new Date().toISOString(),\n type: \"follow\",\n targetUserId: userId,\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(userId: string): Promise<PostResult> {\n rateLimiter.requireBasicTier(\"Unfollow\");\n try {\n const myId = await this.getUserId();\n await this.request(`/users/${myId}/following/${userId}`, {\n method: \"DELETE\",\n useOAuth: true,\n });\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 rateLimiter.requireBasicTier(\"Read timeline\");\n try {\n const userId = await this.getUserId();\n const params = new URLSearchParams({\n max_results: String(options?.count ?? 20),\n \"tweet.fields\": \"created_at,public_metrics,in_reply_to_user_id\",\n expansions: \"author_id\",\n \"user.fields\": \"username\",\n });\n if (options?.sinceId) params.set(\"since_id\", options.sinceId);\n\n const result = (await this.request(\n `/users/${userId}/timelines/reverse_chronological?${params}`\n )) as {\n data?: Array<{\n id: string;\n text: string;\n author_id: string;\n created_at: string;\n public_metrics?: {\n like_count: number;\n retweet_count: number;\n reply_count: number;\n };\n in_reply_to_user_id?: string;\n }>;\n includes?: {\n users?: Array<{ id: string; username: string }>;\n };\n };\n\n if (!result.data) return [];\n\n const userMap = new Map<string, string>();\n for (const user of result.includes?.users ?? []) {\n userMap.set(user.id, user.username);\n }\n\n return result.data.map((tweet) => ({\n id: tweet.id,\n text: tweet.text,\n authorId: tweet.author_id,\n authorHandle: userMap.get(tweet.author_id) ?? \"unknown\",\n createdAt: tweet.created_at,\n likeCount: tweet.public_metrics?.like_count,\n retweetCount: tweet.public_metrics?.retweet_count,\n replyCount: tweet.public_metrics?.reply_count,\n }));\n } catch (error) {\n logger.error(\"Failed to read timeline\", error);\n return [];\n }\n }\n\n async getMentions(options?: TimelineOptions): Promise<Tweet[]> {\n rateLimiter.requireBasicTier(\"Read mentions\");\n try {\n const userId = await this.getUserId();\n const params = new URLSearchParams({\n max_results: String(options?.count ?? 20),\n \"tweet.fields\": \"created_at,public_metrics\",\n expansions: \"author_id\",\n \"user.fields\": \"username\",\n });\n if (options?.sinceId) params.set(\"since_id\", options.sinceId);\n\n const result = (await this.request(\n `/users/${userId}/mentions?${params}`\n )) as {\n data?: Array<{\n id: string;\n text: string;\n author_id: string;\n created_at: string;\n public_metrics?: {\n like_count: number;\n retweet_count: number;\n reply_count: number;\n };\n }>;\n includes?: {\n users?: Array<{ id: string; username: string }>;\n };\n };\n\n if (!result.data) return [];\n\n const userMap = new Map<string, string>();\n for (const user of result.includes?.users ?? []) {\n userMap.set(user.id, user.username);\n }\n\n return result.data.map((tweet) => ({\n id: tweet.id,\n text: tweet.text,\n authorId: tweet.author_id,\n authorHandle: userMap.get(tweet.author_id) ?? \"unknown\",\n createdAt: tweet.created_at,\n likeCount: tweet.public_metrics?.like_count,\n retweetCount: tweet.public_metrics?.retweet_count,\n replyCount: tweet.public_metrics?.reply_count,\n }));\n } catch (error) {\n logger.error(\"Failed to read mentions\", error);\n return [];\n }\n }\n\n async searchTweets(query: string, options?: SearchOptions): Promise<Tweet[]> {\n rateLimiter.requireBasicTier(\"Search tweets\");\n try {\n const params = new URLSearchParams({\n query,\n max_results: String(options?.count ?? 20),\n \"tweet.fields\": \"created_at,public_metrics\",\n expansions: \"author_id\",\n \"user.fields\": \"username\",\n });\n\n const result = (await this.request(\n `/tweets/search/recent?${params}`\n )) as {\n data?: Array<{\n id: string;\n text: string;\n author_id: string;\n created_at: string;\n public_metrics?: {\n like_count: number;\n retweet_count: number;\n reply_count: number;\n };\n }>;\n includes?: {\n users?: Array<{ id: string; username: string }>;\n };\n };\n\n if (!result.data) return [];\n\n const userMap = new Map<string, string>();\n for (const user of result.includes?.users ?? []) {\n userMap.set(user.id, user.username);\n }\n\n return result.data.map((tweet) => ({\n id: tweet.id,\n text: tweet.text,\n authorId: tweet.author_id,\n authorHandle: userMap.get(tweet.author_id) ?? \"unknown\",\n createdAt: tweet.created_at,\n likeCount: tweet.public_metrics?.like_count,\n retweetCount: tweet.public_metrics?.retweet_count,\n replyCount: tweet.public_metrics?.reply_count,\n }));\n } catch (error) {\n logger.error(\"Failed to search tweets\", error);\n return [];\n }\n }\n\n async getProfile(handle: string): Promise<UserProfile> {\n rateLimiter.requireBasicTier(\"Get profile\");\n const result = (await this.request(\n `/users/by/username/${handle}?user.fields=description,public_metrics,verified,profile_image_url`\n )) as {\n data: {\n id: string;\n username: string;\n name: string;\n description: string;\n public_metrics: {\n followers_count: number;\n following_count: number;\n tweet_count: number;\n };\n verified: boolean;\n profile_image_url?: string;\n };\n };\n\n return {\n id: result.data.id,\n handle: result.data.username,\n name: result.data.name,\n bio: result.data.description,\n followersCount: result.data.public_metrics.followers_count,\n followingCount: result.data.public_metrics.following_count,\n tweetCount: result.data.public_metrics.tweet_count,\n verified: result.data.verified,\n profileImageUrl: result.data.profile_image_url,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAeA,IAAM,WAAW;AAEV,IAAM,aAAN,MAA6C;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAwB;AAAA,EAEhC,cAAc;AACZ,UAAM,QAAQ,gBAAgB;AAC9B,QAAI,MAAM,WAAW,OAAO;AAC1B,YAAM,IAAI,MAAM,8DAA8D;AAAA,IAChF;AACA,SAAK,cAAc,MAAM;AACzB,SAAK,cAAc,MAAM;AACzB,SAAK,oBAAoB,MAAM;AAC/B,SAAK,SAAS,MAAM;AACpB,SAAK,YAAY,MAAM;AAAA,EACzB;AAAA,EAEA,MAAc,QACZ,UACA,UAII,CAAC,GACa;AAClB,UAAM,EAAE,SAAS,OAAO,MAAM,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