agentfeed 0.1.0 → 0.1.1
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/index.js +5 -0
- package/dist/invoker.d.ts +5 -2
- package/dist/invoker.js +34 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const apiKey = getRequiredEnv("AGENTFEED_API_KEY");
|
|
|
18
18
|
const client = new AgentFeedClient(serverUrl, apiKey);
|
|
19
19
|
let isRunning = false;
|
|
20
20
|
const wakeAttempts = new Map();
|
|
21
|
+
const sessionMap = new Map(); // postId → claude sessionId
|
|
21
22
|
async function main() {
|
|
22
23
|
console.log("AgentFeed Worker starting...");
|
|
23
24
|
// Step 0: Initialize
|
|
@@ -87,7 +88,11 @@ async function handleTriggers(triggers, agent, skillMd) {
|
|
|
87
88
|
apiKey,
|
|
88
89
|
serverUrl,
|
|
89
90
|
recentContext,
|
|
91
|
+
sessionId: sessionMap.get(trigger.postId),
|
|
90
92
|
});
|
|
93
|
+
if (result.sessionId) {
|
|
94
|
+
sessionMap.set(trigger.postId, result.sessionId);
|
|
95
|
+
}
|
|
91
96
|
if (result.exitCode === 0) {
|
|
92
97
|
success = true;
|
|
93
98
|
break;
|
package/dist/invoker.d.ts
CHANGED
|
@@ -6,8 +6,11 @@ interface InvokeOptions {
|
|
|
6
6
|
apiKey: string;
|
|
7
7
|
serverUrl: string;
|
|
8
8
|
recentContext: string;
|
|
9
|
+
sessionId?: string;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
interface InvokeResult {
|
|
11
12
|
exitCode: number;
|
|
12
|
-
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function invokeAgent(options: InvokeOptions): Promise<InvokeResult>;
|
|
13
16
|
export {};
|
package/dist/invoker.js
CHANGED
|
@@ -2,19 +2,30 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
export function invokeAgent(options) {
|
|
3
3
|
return new Promise((resolve, reject) => {
|
|
4
4
|
const prompt = buildPrompt(options);
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"--
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
5
|
+
const isNewSession = !options.sessionId;
|
|
6
|
+
const args = ["-p", prompt, "--append-system-prompt", options.skillMd];
|
|
7
|
+
if (options.sessionId) {
|
|
8
|
+
args.push("--resume", options.sessionId);
|
|
9
|
+
}
|
|
10
|
+
if (isNewSession) {
|
|
11
|
+
args.push("--output-format", "json");
|
|
12
|
+
}
|
|
13
|
+
const env = {
|
|
14
|
+
...process.env,
|
|
15
|
+
AGENTFEED_BASE_URL: `${options.serverUrl}/api`,
|
|
16
|
+
AGENTFEED_API_KEY: options.apiKey,
|
|
17
|
+
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: process.env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE ?? "50",
|
|
18
|
+
};
|
|
19
|
+
const child = spawn("claude", args, {
|
|
20
|
+
env,
|
|
21
|
+
stdio: isNewSession ? ["inherit", "pipe", "inherit"] : "inherit",
|
|
17
22
|
});
|
|
23
|
+
let stdout = "";
|
|
24
|
+
if (isNewSession && child.stdout) {
|
|
25
|
+
child.stdout.on("data", (chunk) => {
|
|
26
|
+
stdout += chunk.toString();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
18
29
|
child.on("error", (err) => {
|
|
19
30
|
if (err.code === "ENOENT") {
|
|
20
31
|
reject(new Error("'claude' command not found. Install Claude Code: https://claude.ai/claude-code"));
|
|
@@ -24,7 +35,17 @@ export function invokeAgent(options) {
|
|
|
24
35
|
}
|
|
25
36
|
});
|
|
26
37
|
child.on("close", (code) => {
|
|
27
|
-
|
|
38
|
+
let sessionId;
|
|
39
|
+
if (isNewSession && stdout) {
|
|
40
|
+
try {
|
|
41
|
+
const parsed = JSON.parse(stdout);
|
|
42
|
+
sessionId = parsed.session_id;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// JSON parse failed, ignore
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
resolve({ exitCode: code ?? 1, sessionId: sessionId ?? options.sessionId });
|
|
28
49
|
});
|
|
29
50
|
});
|
|
30
51
|
}
|