agentp 0.9.0 → 0.10.0

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/lib/opencode.js CHANGED
@@ -11,7 +11,7 @@ function getAuthHeaders() {
11
11
  return { 'Authorization': `Basic ${encoded}` };
12
12
  }
13
13
 
14
- function makeRequest(options, data, cancelRef) {
14
+ function makeRequest(options, data, cancelRef, timeoutMs) {
15
15
  return new Promise((resolve, reject) => {
16
16
  const req = http.request(options, (res) => {
17
17
  let body = '';
@@ -24,6 +24,12 @@ function makeRequest(options, data, cancelRef) {
24
24
  }
25
25
  });
26
26
  });
27
+ if (timeoutMs) {
28
+ req.setTimeout(timeoutMs, () => {
29
+ req.destroy();
30
+ reject(new Error('Request timed out'));
31
+ });
32
+ }
27
33
  req.on('error', reject);
28
34
  if (cancelRef) cancelRef.current = req;
29
35
  if (data) req.write(data);
@@ -243,6 +249,27 @@ async function selectSession(server, sessionId) {
243
249
  }
244
250
  }
245
251
 
252
+ // Get a single session by ID, including its message history.
253
+ // Tries GET /session/:id first; falls back to filtering the sessions list.
254
+ async function getSession(server, sessionId) {
255
+ // Try dedicated endpoint first (newer opencode versions)
256
+ try {
257
+ const url = `${server}/session/${encodeURIComponent(sessionId)}`;
258
+ const { status, body } = await makeRequest(buildJsonRequest(url, 'GET'), null, null, 10000);
259
+ if (status === 200) {
260
+ const parsed = JSON.parse(body);
261
+ if (parsed) return parsed;
262
+ }
263
+ } catch {
264
+ // Fall through
265
+ }
266
+ // Fallback: get all sessions and find the one we need
267
+ const sessions = await listSessions(server);
268
+ const match = sessions.find(s => String(s.id) === String(sessionId));
269
+ if (match) return match;
270
+ throw new Error(`Session ${sessionId} not found`);
271
+ }
272
+
246
273
  // List all agents from the OpenCode server.
247
274
  async function listAgents(server) {
248
275
  const url = `${server}/agent`;
@@ -455,6 +482,7 @@ module.exports = {
455
482
  sendText,
456
483
  listenForFinalAnswer,
457
484
  listSessions,
485
+ getSession,
458
486
  createSession,
459
487
  updateSession,
460
488
  selectSession,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentp",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Pipe prompts into a running OpenCode TUI session and stream the final answer",
5
5
  "bin": {
6
6
  "agentp": "bin/agentp",