opencode-codex-memory 0.9.9 → 0.9.10
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 +2 -2
- package/dist/src/v2/model-readiness.d.ts +8 -0
- package/dist/src/v2/model-readiness.js +43 -0
- package/dist/src/v2/shim.js +14 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
|
|
|
35
35
|
{
|
|
36
36
|
"$schema": "https://opencode.ai/config.json",
|
|
37
37
|
"plugins": [
|
|
38
|
-
{ "package": "opencode-codex-memory@0.9.
|
|
38
|
+
{ "package": "opencode-codex-memory@0.9.10" }
|
|
39
39
|
]
|
|
40
40
|
}
|
|
41
41
|
```
|
|
@@ -45,7 +45,7 @@ to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
|
|
|
45
45
|
```json
|
|
46
46
|
{
|
|
47
47
|
"$schema": "https://opencode.ai/config.json",
|
|
48
|
-
"plugin": ["opencode-codex-memory@0.9.
|
|
48
|
+
"plugin": ["opencode-codex-memory@0.9.10"]
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type ModelRef = {
|
|
2
|
+
providerID: string;
|
|
3
|
+
id: string;
|
|
4
|
+
};
|
|
5
|
+
/** Only retry host selection failures: these occur before any inference. */
|
|
6
|
+
export declare function isModelSelectionUnavailable(error: unknown, model?: ModelRef): boolean;
|
|
7
|
+
export declare function retryModelSelection<T>(request: () => Promise<T>, model?: ModelRef, signal?: AbortSignal, delays?: readonly number[]): Promise<T>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
+
import { recordDiagnostic } from "../diagnostics.js";
|
|
3
|
+
// Startup provider registrations can lag service health. Bound the wait rather
|
|
4
|
+
// than silently changing models or indefinitely hiding a configuration error.
|
|
5
|
+
const RETRY_DELAYS_MS = [250, 500, 1_000, 2_000, 4_000, 8_000, 15_000, 15_000];
|
|
6
|
+
/** Only retry host selection failures: these occur before any inference. */
|
|
7
|
+
export function isModelSelectionUnavailable(error, model) {
|
|
8
|
+
const message = model
|
|
9
|
+
? `Model unavailable: ${model.providerID}/${model.id}`
|
|
10
|
+
: "No model specified and no supported model is available";
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
for (let current = error; current && !seen.has(current); current = current.cause ?? current.error) {
|
|
13
|
+
seen.add(current);
|
|
14
|
+
const tag = current._tag ?? current.name;
|
|
15
|
+
if (["InvalidRequestError", "Generate.ModelSelectionError"].includes(tag) && current.message === message)
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
export async function retryModelSelection(request, model, signal, delays = RETRY_DELAYS_MS) {
|
|
21
|
+
const label = model ? `${model.providerID}/${model.id}` : "host default model";
|
|
22
|
+
for (let attempt = 0;; attempt++) {
|
|
23
|
+
signal?.throwIfAborted();
|
|
24
|
+
try {
|
|
25
|
+
const result = await request();
|
|
26
|
+
if (attempt > 0)
|
|
27
|
+
recordDiagnostic("info", "model-readiness", `${label} available after ${attempt} startup retry(s)`);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (signal?.aborted || !isModelSelectionUnavailable(error, model))
|
|
32
|
+
throw error;
|
|
33
|
+
const delay = delays[attempt];
|
|
34
|
+
if (delay === undefined) {
|
|
35
|
+
recordDiagnostic("error", "model-readiness", `${label} still unavailable after ${attempt} startup retry(s)`);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
if (attempt === 0)
|
|
39
|
+
recordDiagnostic("warn", "model-readiness", `${label} not registered yet; waiting for model startup`);
|
|
40
|
+
await sleep(delay, undefined, signal ? { signal } : undefined);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/dist/src/v2/shim.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { memoryRoot } from "../paths.js";
|
|
2
2
|
import { consolidationPermissions } from "./agents.js";
|
|
3
|
+
import { retryModelSelection } from "./model-readiness.js";
|
|
3
4
|
import { invalidateOwnService, lastServiceFailure, ownServiceClient, serviceRequest } from "./service.js";
|
|
4
5
|
let v2ctx = null;
|
|
5
6
|
let discoveryStatus = null;
|
|
@@ -396,13 +397,23 @@ async function v2promptWithWait(sessionID, body, signal) {
|
|
|
396
397
|
throw new Error("sub-agent prompt cancelled");
|
|
397
398
|
const publicClient = await ownServiceClient();
|
|
398
399
|
if (typeof publicClient?.generate?.text === "function") {
|
|
399
|
-
const gen = await
|
|
400
|
+
const gen = und(await retryModelSelection(async () => {
|
|
401
|
+
const result = await serviceRequest(publicClient, () => publicClient.generate.text(payload, signal ? { signal } : undefined));
|
|
402
|
+
if (result?.error)
|
|
403
|
+
throw result.error;
|
|
404
|
+
return result;
|
|
405
|
+
}, payload.model, signal));
|
|
400
406
|
const outText = typeof gen?.text === "string" ? gen.text : JSON.stringify(gen);
|
|
401
407
|
return { data: { parts: [{ type: "text", text: outText }] } };
|
|
402
408
|
}
|
|
403
409
|
// ctx.generate.text ignores request-option signals. Race AbortSignal.
|
|
404
|
-
const
|
|
405
|
-
|
|
410
|
+
const gen = und(await retryModelSelection(async () => {
|
|
411
|
+
const genP = c.generate.text(payload);
|
|
412
|
+
const result = signal ? await raceAbort(genP, signal) : await genP;
|
|
413
|
+
if (result?.error)
|
|
414
|
+
throw result.error;
|
|
415
|
+
return result;
|
|
416
|
+
}, payload.model, signal));
|
|
406
417
|
const outText = typeof gen?.text === "string" ? gen.text : JSON.stringify(gen);
|
|
407
418
|
return { data: { parts: [{ type: "text", text: outText }] } };
|
|
408
419
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-codex-memory",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.10",
|
|
4
4
|
"description": "Persistent memory plugin for opencode — ports codex's two-phase memory system (extraction → consolidation → injection → citation feedback)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|