@narumitw/pi-btw 0.11.0 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/btw.ts +42 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@narumitw/pi-btw",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Pi extension that adds a /btw side-question command.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/btw.ts CHANGED
@@ -1,4 +1,45 @@
1
- import { complete, type UserMessage } from "@earendil-works/pi-ai/compat";
1
+ import type {
2
+ Api,
3
+ AssistantMessage,
4
+ Context,
5
+ Model,
6
+ ProviderStreamOptions,
7
+ UserMessage,
8
+ } from "@earendil-works/pi-ai";
9
+ // pi-ai 0.79 exports complete from the root; 0.80 moved it to the compat subpath.
10
+ type CompleteFunction = <TApi extends Api>(
11
+ model: Model<TApi>,
12
+ context: Context,
13
+ options?: ProviderStreamOptions,
14
+ ) => Promise<AssistantMessage>;
15
+
16
+ function hasComplete(value: unknown): value is { complete: CompleteFunction } {
17
+ return (
18
+ typeof value === "object" &&
19
+ value !== null &&
20
+ typeof Reflect.get(value, "complete") === "function"
21
+ );
22
+ }
23
+
24
+ type ModuleImporter = (moduleId: string) => Promise<unknown>;
25
+
26
+ export async function loadComplete(
27
+ importModule: ModuleImporter = (moduleId) => import(moduleId),
28
+ ): Promise<CompleteFunction> {
29
+ let importError: unknown;
30
+ for (const moduleId of ["@earendil-works/pi-ai/compat", "@earendil-works/pi-ai"]) {
31
+ try {
32
+ const module = await importModule(moduleId);
33
+ if (hasComplete(module)) return module.complete;
34
+ } catch (error: unknown) {
35
+ importError = error;
36
+ }
37
+ }
38
+
39
+ throw new Error("@earendil-works/pi-ai does not export complete", { cause: importError });
40
+ }
41
+
42
+ const complete = await loadComplete();
2
43
  import {
3
44
  BorderedLoader,
4
45
  DynamicBorder,