agentp 0.11.10 → 0.12.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/README.md +14 -7
- package/bin/tgagentp +674 -334
- package/lib/ocmux.js +27 -9
- package/lib/opencode.js +12 -3
- package/package.json +1 -1
package/lib/ocmux.js
CHANGED
|
@@ -233,13 +233,29 @@ function resurrectServer(dir, printLogs) {
|
|
|
233
233
|
const actualName = windowNameByIndex(winIdx);
|
|
234
234
|
if (actualName !== dir) {
|
|
235
235
|
const found = windowByDir(dir);
|
|
236
|
-
if (found
|
|
236
|
+
if (found == null) {
|
|
237
|
+
// No window exists for this directory — old server is already dead, skip kill
|
|
238
|
+
winIdx = null;
|
|
239
|
+
} else {
|
|
240
|
+
winIdx = found;
|
|
241
|
+
}
|
|
237
242
|
}
|
|
238
243
|
if (winIdx != null) {
|
|
239
244
|
_tmux(['select-window', '-t', `${SESSION}:${winIdx}`]);
|
|
240
245
|
_tmux(['send-keys', '-t', `${SESSION}:${winIdx}.0`, 'C-c']);
|
|
241
246
|
sleep(0.3);
|
|
242
|
-
_tmux(['kill-window', '-t', `${SESSION}:${winIdx}`]);
|
|
247
|
+
const killR = _tmux(['kill-window', '-t', `${SESSION}:${winIdx}`]);
|
|
248
|
+
if (killR.status !== 0) {
|
|
249
|
+
throw new Error(`Failed to kill old tmux window ${winIdx}: ${killR.stderr || 'unknown error'}`);
|
|
250
|
+
}
|
|
251
|
+
// Wait for window to actually disappear (up to 2s)
|
|
252
|
+
for (let i = 0; i < 10; i++) {
|
|
253
|
+
if (windowByDir(dir) == null) break;
|
|
254
|
+
sleep(0.2);
|
|
255
|
+
}
|
|
256
|
+
if (windowByDir(dir) != null) {
|
|
257
|
+
throw new Error(`Old tmux window for ${dir} still exists after kill`);
|
|
258
|
+
}
|
|
243
259
|
}
|
|
244
260
|
}
|
|
245
261
|
}
|
|
@@ -260,11 +276,14 @@ function startServer(dir, printLogs) {
|
|
|
260
276
|
ensureSession();
|
|
261
277
|
const lf = logfileFor(dir);
|
|
262
278
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (winIdx
|
|
279
|
+
// Create a new tmux window and capture its index directly from the -P output
|
|
280
|
+
const newWinR = _tmux(['new-window', '-d', '-P', '-F', '#{window_index}', '-t', SESSION, '-n', dir, '-c', dir]);
|
|
281
|
+
if (newWinR.status !== 0) throw new Error(`failed to create tmux window for ${dir}`);
|
|
282
|
+
let winIdx = parseInt(newWinR.stdout.trim(), 10);
|
|
283
|
+
if (isNaN(winIdx)) {
|
|
284
|
+
winIdx = windowByDir(dir);
|
|
285
|
+
if (winIdx == null) throw new Error('could not determine new window index');
|
|
286
|
+
}
|
|
268
287
|
|
|
269
288
|
pinWindowName(winIdx);
|
|
270
289
|
|
|
@@ -283,8 +302,7 @@ function startServer(dir, printLogs) {
|
|
|
283
302
|
}
|
|
284
303
|
|
|
285
304
|
if (!url) {
|
|
286
|
-
|
|
287
|
-
if (wi != null) _tmux(['kill-window', '-t', `${SESSION}:${wi}`]);
|
|
305
|
+
_tmux(['kill-window', '-t', `${SESSION}:${winIdx}`]);
|
|
288
306
|
throw new Error('opencode server did not start within 10 seconds');
|
|
289
307
|
}
|
|
290
308
|
|
package/lib/opencode.js
CHANGED
|
@@ -217,11 +217,17 @@ async function createSession(server, title) {
|
|
|
217
217
|
return JSON.parse(responseBody);
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
// Update a session's properties (e.g. title).
|
|
221
|
-
|
|
220
|
+
// Update a session's properties (e.g. title, agent, model).
|
|
221
|
+
// model can be a string "providerID/modelID" or an object { providerID, modelID }.
|
|
222
|
+
async function updateSession(server, sessionId, title, agent, model) {
|
|
222
223
|
const bodyObj = {};
|
|
223
224
|
if (title != null) bodyObj.title = title;
|
|
224
225
|
if (agent != null) bodyObj.agent = agent;
|
|
226
|
+
if (model != null) {
|
|
227
|
+
bodyObj.model = typeof model === 'string'
|
|
228
|
+
? model
|
|
229
|
+
: { providerID: model.providerID, id: model.modelID || model.id };
|
|
230
|
+
}
|
|
225
231
|
const url = `${server}/session/${encodeURIComponent(sessionId)}`;
|
|
226
232
|
const body = JSON.stringify(bodyObj);
|
|
227
233
|
const { status, body: responseBody } = await makeRequest(buildJsonRequest(url, 'PATCH', body), body);
|
|
@@ -297,10 +303,13 @@ async function listProviders(server) {
|
|
|
297
303
|
}
|
|
298
304
|
|
|
299
305
|
// Send a message asynchronously (non-blocking). Returns 204 No Content.
|
|
300
|
-
|
|
306
|
+
// Optionally specify a model and/or noReply (injects context without AI response).
|
|
307
|
+
async function sendToSessionAsync(server, sessionId, text, agent, model, noReply) {
|
|
301
308
|
const url = `${server}/session/${encodeURIComponent(sessionId)}/prompt_async`;
|
|
302
309
|
const bodyObj = { parts: [{ type: 'text', text }] };
|
|
303
310
|
if (agent) bodyObj.agent = agent;
|
|
311
|
+
if (model) bodyObj.model = typeof model === 'string' ? model : { providerID: model.providerID, modelID: model.modelID };
|
|
312
|
+
if (noReply) bodyObj.noReply = true;
|
|
304
313
|
const body = JSON.stringify(bodyObj);
|
|
305
314
|
const { status } = await makeRequest(buildJsonRequest(url, 'POST', body), body);
|
|
306
315
|
if (status !== 204) throw new Error(`Failed to send async message: ${status}`);
|