@narumitw/pi-btw 0.49.5 → 0.49.6
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/package.json +8 -5
- package/src/btw.ts +14 -1
- package/src/side-thread.ts +4 -34
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ pi -e npm:@narumitw/pi-btw
|
|
|
34
34
|
Try this package locally from the repository root:
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
pi -e ./
|
|
37
|
+
pi -e ./packages/pi-btw
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## 🚀 Usage
|
|
@@ -154,7 +154,7 @@ Normal assistant messages become part of the main Pi conversation and can distra
|
|
|
154
154
|
## 🗂️ Package layout
|
|
155
155
|
|
|
156
156
|
```txt
|
|
157
|
-
|
|
157
|
+
packages/pi-btw/
|
|
158
158
|
├── src/
|
|
159
159
|
│ ├── index.ts
|
|
160
160
|
│ ├── btw.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-btw",
|
|
3
|
-
"version": "0.49.
|
|
3
|
+
"version": "0.49.6",
|
|
4
4
|
"description": "Pi extension that adds a /btw side-question command.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
"./src/index.ts"
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
|
+
"piExtension": {
|
|
26
|
+
"lifecycle": "stable"
|
|
27
|
+
},
|
|
25
28
|
"scripts": {
|
|
26
29
|
"check": "biome check . && npm run typecheck",
|
|
27
30
|
"format": "biome check --write .",
|
|
@@ -29,15 +32,15 @@
|
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
34
|
"@biomejs/biome": "2.5.7",
|
|
32
|
-
"@earendil-works/pi-ai": "0.
|
|
33
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
34
|
-
"@earendil-works/pi-tui": "0.
|
|
35
|
+
"@earendil-works/pi-ai": "0.84.0",
|
|
36
|
+
"@earendil-works/pi-coding-agent": "0.84.0",
|
|
37
|
+
"@earendil-works/pi-tui": "0.84.0",
|
|
35
38
|
"typescript": "7.0.2"
|
|
36
39
|
},
|
|
37
40
|
"repository": {
|
|
38
41
|
"type": "git",
|
|
39
42
|
"url": "https://github.com/narumiruna/pi-extensions",
|
|
40
|
-
"directory": "
|
|
43
|
+
"directory": "packages/pi-btw"
|
|
41
44
|
},
|
|
42
45
|
"dependencies": {
|
|
43
46
|
"@narumitw/pi-tui-kit": "^0.49.1"
|
package/src/btw.ts
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
import {
|
|
41
41
|
BTW_THINKING_LEVELS,
|
|
42
42
|
type BtwThinkingLevel,
|
|
43
|
+
type CompleteSimpleFunction,
|
|
43
44
|
completeSideThreadTurn,
|
|
44
45
|
createSideThread,
|
|
45
46
|
type SideQuestionAuth,
|
|
@@ -66,7 +67,6 @@ export {
|
|
|
66
67
|
type BtwThinkingLevel,
|
|
67
68
|
buildUserPrompt,
|
|
68
69
|
completeSideQuestion,
|
|
69
|
-
loadCompleteSimple,
|
|
70
70
|
} from "./side-thread.js";
|
|
71
71
|
export { sanitizeSingleLine } from "./text.js";
|
|
72
72
|
|
|
@@ -82,6 +82,18 @@ type BtwModelRegistry = Pick<
|
|
|
82
82
|
"find" | "getApiKeyAndHeaders"
|
|
83
83
|
>;
|
|
84
84
|
|
|
85
|
+
type BtwProviderRegistry = Pick<ExtensionCommandContext["modelRegistry"], "getProvider">;
|
|
86
|
+
|
|
87
|
+
export function createModelRegistryCompleteSimple(
|
|
88
|
+
modelRegistry: BtwProviderRegistry,
|
|
89
|
+
): CompleteSimpleFunction {
|
|
90
|
+
return async (model, context, options) => {
|
|
91
|
+
const provider = modelRegistry.getProvider(model.provider);
|
|
92
|
+
if (!provider) throw new Error(`No provider registered for model provider: ${model.provider}`);
|
|
93
|
+
return provider.streamSimple(model, context, options).result();
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
85
97
|
interface ResolveBtwModelOptions {
|
|
86
98
|
settings: BtwSettings;
|
|
87
99
|
currentModel: Model<Api> | undefined;
|
|
@@ -777,6 +789,7 @@ async function askThreadQuestion(
|
|
|
777
789
|
thinkingLevel,
|
|
778
790
|
auth: selected.auth,
|
|
779
791
|
signal: view.signal,
|
|
792
|
+
completeSimple: createModelRegistryCompleteSimple(ctx.modelRegistry),
|
|
780
793
|
}).then((result) => {
|
|
781
794
|
if (settled) return;
|
|
782
795
|
settled = true;
|
package/src/side-thread.ts
CHANGED
|
@@ -33,36 +33,6 @@ export type CompleteSimpleFunction = <TApi extends Api>(
|
|
|
33
33
|
options?: SimpleStreamOptions,
|
|
34
34
|
) => Promise<AssistantMessage>;
|
|
35
35
|
|
|
36
|
-
type ModuleImporter = (moduleId: string) => Promise<unknown>;
|
|
37
|
-
|
|
38
|
-
function hasCompleteSimple(value: unknown): value is { completeSimple: CompleteSimpleFunction } {
|
|
39
|
-
return (
|
|
40
|
-
typeof value === "object" &&
|
|
41
|
-
value !== null &&
|
|
42
|
-
typeof Reflect.get(value, "completeSimple") === "function"
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function loadCompleteSimple(
|
|
47
|
-
importModule: ModuleImporter = (moduleId) => import(moduleId),
|
|
48
|
-
): Promise<CompleteSimpleFunction> {
|
|
49
|
-
let importError: unknown;
|
|
50
|
-
for (const moduleId of ["@earendil-works/pi-ai/compat", "@earendil-works/pi-ai"]) {
|
|
51
|
-
try {
|
|
52
|
-
const module = await importModule(moduleId);
|
|
53
|
-
if (hasCompleteSimple(module)) return module.completeSimple;
|
|
54
|
-
} catch (error: unknown) {
|
|
55
|
-
importError = error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
throw new Error("@earendil-works/pi-ai does not export completeSimple", {
|
|
60
|
-
cause: importError,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const defaultCompleteSimple = await loadCompleteSimple();
|
|
65
|
-
|
|
66
36
|
export type SideThreadTurn =
|
|
67
37
|
| {
|
|
68
38
|
kind: "answered";
|
|
@@ -115,7 +85,7 @@ export interface CompleteSideThreadTurnOptions {
|
|
|
115
85
|
thinkingLevel: BtwThinkingLevel;
|
|
116
86
|
auth: SideQuestionAuth;
|
|
117
87
|
signal?: AbortSignal;
|
|
118
|
-
completeSimple
|
|
88
|
+
completeSimple: CompleteSimpleFunction;
|
|
119
89
|
}
|
|
120
90
|
|
|
121
91
|
export type CompleteSideThreadTurnResult =
|
|
@@ -130,7 +100,7 @@ export async function completeSideThreadTurn({
|
|
|
130
100
|
thinkingLevel,
|
|
131
101
|
auth,
|
|
132
102
|
signal,
|
|
133
|
-
completeSimple
|
|
103
|
+
completeSimple,
|
|
134
104
|
}: CompleteSideThreadTurnOptions): Promise<CompleteSideThreadTurnResult> {
|
|
135
105
|
if (signal?.aborted) return { kind: "aborted" };
|
|
136
106
|
let response: AssistantMessage;
|
|
@@ -162,7 +132,7 @@ export interface CompleteSideQuestionOptions {
|
|
|
162
132
|
thinkingLevel: BtwThinkingLevel;
|
|
163
133
|
auth: SideQuestionAuth;
|
|
164
134
|
signal?: AbortSignal;
|
|
165
|
-
completeSimple
|
|
135
|
+
completeSimple: CompleteSimpleFunction;
|
|
166
136
|
}
|
|
167
137
|
|
|
168
138
|
export async function completeSideQuestion({
|
|
@@ -172,7 +142,7 @@ export async function completeSideQuestion({
|
|
|
172
142
|
thinkingLevel,
|
|
173
143
|
auth,
|
|
174
144
|
signal,
|
|
175
|
-
completeSimple
|
|
145
|
+
completeSimple,
|
|
176
146
|
}: CompleteSideQuestionOptions): Promise<AssistantMessage> {
|
|
177
147
|
return completeSimple(
|
|
178
148
|
model,
|