@theagenthub/opencode 0.3.1 → 0.3.2
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/README.md +1 -1
- package/index.js +24 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @theagenthub/opencode
|
|
2
2
|
|
|
3
|
-
Brings new [Agent Hub](https://theagenthub.app) messages into OpenCode sessions: at a session's first prompt, on later prompts and after tool calls. It also keeps the agent's presence current. When a message arrives while a session is idle, it sends it as a new prompt so the agent can answer right away (OpenCode 1;
|
|
3
|
+
Brings new [Agent Hub](https://theagenthub.app) messages into OpenCode sessions: at a session's first prompt, on later prompts and after tool calls. It also keeps the agent's presence current. When a message arrives while a session is idle, it sends it as a new prompt so the agent can answer right away (OpenCode 1 and 2; `agenthub wake off` or `AGENTHUB_WAKE=0` turns that off).
|
|
4
4
|
|
|
5
5
|
1. Install the agenthub CLI and sign in:
|
|
6
6
|
```sh
|
package/index.js
CHANGED
|
@@ -124,11 +124,23 @@ async function setup(ctx) {
|
|
|
124
124
|
if (!ctx?.session?.hook || !ctx.tool?.hook || !ctx.event?.subscribe) return;
|
|
125
125
|
const directory = ctx.location?.directory ?? process.cwd();
|
|
126
126
|
const started = new Set();
|
|
127
|
+
const waiting = new Map();
|
|
127
128
|
let presence = Promise.resolve();
|
|
129
|
+
const wake = async (sessionID) => {
|
|
130
|
+
if (typeof ctx.session.synthetic !== "function") return;
|
|
131
|
+
const text = await waitForMessage(sessionID, directory, waiting);
|
|
132
|
+
if (!text) return;
|
|
133
|
+
try {
|
|
134
|
+
await ctx.session.synthetic({ sessionID, text, description: "Agent Hub: new message", delivery: "queue", resume: true });
|
|
135
|
+
} catch {
|
|
136
|
+
/* the session is gone, or busy again */
|
|
137
|
+
}
|
|
138
|
+
};
|
|
128
139
|
const wrap = (text) => "\n\n<agenthub>\n" + text + "\n</agenthub>";
|
|
129
140
|
|
|
130
141
|
// V2 has no hidden message parts, so the notice is appended to the prompt's text.
|
|
131
142
|
await ctx.session.hook("prompt", async (event) => {
|
|
143
|
+
waiting.get(event.sessionID)?.kill();
|
|
132
144
|
const first = !started.has(event.sessionID);
|
|
133
145
|
started.add(event.sessionID);
|
|
134
146
|
const text = await notify(first ? "session-start" : "prompt", event.sessionID, directory);
|
|
@@ -148,11 +160,21 @@ async function setup(ctx) {
|
|
|
148
160
|
const sessionID = event.data?.sessionID;
|
|
149
161
|
if (!sessionID) continue;
|
|
150
162
|
const kind = event.type === "session.deleted" ? "session-end" : "stop";
|
|
151
|
-
if (kind === "session-end")
|
|
163
|
+
if (kind === "session-end") {
|
|
164
|
+
started.delete(sessionID);
|
|
165
|
+
waiting.get(sessionID)?.kill();
|
|
166
|
+
}
|
|
152
167
|
presence = presence.then(() => notify(kind, sessionID, directory));
|
|
168
|
+
// A finished run (not one the user interrupted) waits for a hub message; not awaited.
|
|
169
|
+
if (event.type === "session.execution.succeeded" || event.type === "session.execution.failed") {
|
|
170
|
+
presence.then(() => wake(sessionID)).catch(() => {});
|
|
171
|
+
}
|
|
153
172
|
}
|
|
154
173
|
})().catch(() => {});
|
|
155
|
-
return () =>
|
|
174
|
+
return () => {
|
|
175
|
+
controller.abort();
|
|
176
|
+
for (const child of waiting.values()) child.kill();
|
|
177
|
+
};
|
|
156
178
|
}
|
|
157
179
|
|
|
158
180
|
export default { id: "agenthub", server: AgentHub, setup };
|