@juicesharp/rpiv-btw 1.20.0 → 2.0.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/btw.ts +3 -7
- package/package.json +2 -1
- package/pi-compat.ts +64 -0
package/btw.ts
CHANGED
|
@@ -9,13 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { readFileSync } from "node:fs";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
|
-
import {
|
|
13
|
-
type AssistantMessage,
|
|
14
|
-
completeSimple,
|
|
15
|
-
type Message,
|
|
16
|
-
type StopReason,
|
|
17
|
-
type UserMessage,
|
|
18
|
-
} from "@earendil-works/pi-ai";
|
|
12
|
+
import type { AssistantMessage, Message, StopReason, UserMessage } from "@earendil-works/pi-ai";
|
|
19
13
|
import {
|
|
20
14
|
convertToLlm,
|
|
21
15
|
type ExtensionAPI,
|
|
@@ -24,6 +18,7 @@ import {
|
|
|
24
18
|
type SessionEntry,
|
|
25
19
|
} from "@earendil-works/pi-coding-agent";
|
|
26
20
|
import { showBtwOverlay } from "./btw-ui.js";
|
|
21
|
+
import { loadCompleteSimple } from "./pi-compat.js";
|
|
27
22
|
|
|
28
23
|
// ---------------------------------------------------------------------------
|
|
29
24
|
// Constants — flat named consts, grouped by concern (advisor pattern, b9428e9)
|
|
@@ -230,6 +225,7 @@ export async function executeBtw(
|
|
|
230
225
|
const systemPrompt = buildSystemPrompt();
|
|
231
226
|
|
|
232
227
|
try {
|
|
228
|
+
const completeSimple = await loadCompleteSimple();
|
|
233
229
|
const response = await completeSimple(
|
|
234
230
|
model,
|
|
235
231
|
{ systemPrompt, messages, tools: [] },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-btw",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Pi extension. The /btw slash command, for putting a one-off side question to the same primary model without polluting the main conversation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"index.ts",
|
|
33
33
|
"btw.ts",
|
|
34
34
|
"btw-ui.ts",
|
|
35
|
+
"pi-compat.ts",
|
|
35
36
|
"prompts/",
|
|
36
37
|
"README.md",
|
|
37
38
|
"LICENSE"
|
package/pi-compat.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-version-tolerant loader for pi-ai's `completeSimple`.
|
|
3
|
+
*
|
|
4
|
+
* Pi >= 0.80.1 moved the global dispatch API (`completeSimple` et al.) to the
|
|
5
|
+
* "@earendil-works/pi-ai/compat" entrypoint; hosts <= 0.79.x export it from
|
|
6
|
+
* the package root and have no /compat entrypoint at all. pi-ai resolves at
|
|
7
|
+
* runtime against the HOST's copy (peerDependency "*"), so neither path can
|
|
8
|
+
* be a static import — try /compat first, fall back to the root entrypoint.
|
|
9
|
+
*
|
|
10
|
+
* The fallback is reserved for RESOLUTION failures (the /compat subpath does
|
|
11
|
+
* not exist on this host); any other /compat error — the entrypoint exists but
|
|
12
|
+
* throws at module init — rethrows so the real failure surfaces at the call
|
|
13
|
+
* site instead of being masked by a root import that may lack the export.
|
|
14
|
+
*
|
|
15
|
+
* /compat is documented as temporary (deleted with pi's ModelManager
|
|
16
|
+
* migration); when that lands, this module is the single place to migrate.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
type CompleteSimpleFn = typeof import("@earendil-works/pi-ai/compat").completeSimple;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Error codes meaning "the /compat entrypoint is not resolvable on this host":
|
|
23
|
+
* - `ERR_PACKAGE_PATH_NOT_EXPORTED` — Node's ESM resolver when the installed
|
|
24
|
+
* pi-ai (<= 0.79.x) resolves but has no "./compat" in its `exports` map —
|
|
25
|
+
* the code an old host actually produces.
|
|
26
|
+
* - `ERR_MODULE_NOT_FOUND` / `MODULE_NOT_FOUND` — Node's / jiti's resolver
|
|
27
|
+
* for an unresolvable module (jiti is what Pi loads `.ts` extensions with).
|
|
28
|
+
* Mirrors rpiv-core's `isModuleNotFound` (plus the subpath-export code) —
|
|
29
|
+
* duplicated because siblings never import each other at runtime.
|
|
30
|
+
*/
|
|
31
|
+
const MODULE_NOT_FOUND_CODES = new Set(["ERR_PACKAGE_PATH_NOT_EXPORTED", "ERR_MODULE_NOT_FOUND", "MODULE_NOT_FOUND"]);
|
|
32
|
+
|
|
33
|
+
/** True for a module-resolution failure. Walks the `cause` chain — ESM loaders
|
|
34
|
+
* and tooling (vitest's mock layer, some bundlers) nest the real code under
|
|
35
|
+
* `.cause`. Bounded against pathological self-referential chains. */
|
|
36
|
+
function isModuleNotFound(err: unknown): boolean {
|
|
37
|
+
for (
|
|
38
|
+
let cur: unknown = err, depth = 0;
|
|
39
|
+
cur != null && depth < 16;
|
|
40
|
+
cur = (cur as { cause?: unknown }).cause, depth++
|
|
41
|
+
) {
|
|
42
|
+
if (typeof cur === "object" && MODULE_NOT_FOUND_CODES.has((cur as { code?: unknown }).code as string)) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function loadCompleteSimple(): Promise<CompleteSimpleFn> {
|
|
50
|
+
let mod: { completeSimple?: CompleteSimpleFn };
|
|
51
|
+
try {
|
|
52
|
+
mod = (await import("@earendil-works/pi-ai/compat")) as { completeSimple?: CompleteSimpleFn };
|
|
53
|
+
} catch (err) {
|
|
54
|
+
if (!isModuleNotFound(err)) throw err; // a real /compat failure must surface, not mask as a fallback
|
|
55
|
+
mod = (await import("@earendil-works/pi-ai")) as { completeSimple?: CompleteSimpleFn };
|
|
56
|
+
}
|
|
57
|
+
const completeSimple = mod.completeSimple;
|
|
58
|
+
if (typeof completeSimple !== "function") {
|
|
59
|
+
throw new Error(
|
|
60
|
+
"pi-ai does not expose completeSimple on /compat or the package root — unsupported host pi-ai version",
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return completeSimple;
|
|
64
|
+
}
|