pi-ghost-autocomplete 0.10.0 → 0.11.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 +44 -3
- package/dist/bench-cli.js +1 -1
- package/dist/bench.js +1 -1
- package/dist/config.d.ts +27 -3
- package/dist/ghost-utils.d.ts +19 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +1 -1
- package/dist/providers/pi-model-provider.d.ts +78 -0
- package/dist/replay-cli.js +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-License-Identifier: SSPL-1.0
|
|
3
|
+
* SPDX-FileCopyrightText: 2025 Alessandro Pungitore <alessandro@pungitore.ch>
|
|
4
|
+
*/
|
|
5
|
+
import type { ModelRegistry } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import type { EmptyReason } from "../metrics.js";
|
|
7
|
+
import type { PiModelProviderConfig } from "../config.js";
|
|
8
|
+
import { type GhostProvider, type GhostRequest, type StreamDelta } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Pi-registry backend: complete through the session's own `ModelRegistry`.
|
|
11
|
+
*
|
|
12
|
+
* Unlike {@link CloudProvider} — which can only resolve models from pi-ai's
|
|
13
|
+
* *static builtin* catalog and must hand-resolve auth (skipping registries
|
|
14
|
+
* with a custom `baseUrl`) — this backend delegates both concerns to pi:
|
|
15
|
+
*
|
|
16
|
+
* - **Model resolution** via `registry.find(provider, id)` / first match in
|
|
17
|
+
* `registry.getAvailable()`. Works for dynamic providers (e.g. "radius")
|
|
18
|
+
* and any model registered by other extensions, none of which exist in
|
|
19
|
+
* the static catalog.
|
|
20
|
+
* - **Auth + endpoint** via `registry.complete()`, which resolves
|
|
21
|
+
* request-time auth (models.json keys, stored credentials, OAuth) and the
|
|
22
|
+
* provider's real `baseUrl` exactly as the main agent sees them
|
|
23
|
+
* (`ModelRuntime.prepareRequest`). No ghost API key needed.
|
|
24
|
+
*
|
|
25
|
+
* Available on pi 0.84+; streaming additionally requires 0.99's
|
|
26
|
+
* `registry.stream` (feature-detected, falls back to the pipeline's
|
|
27
|
+
* non-streaming `predict()` path on 0.84).
|
|
28
|
+
*/
|
|
29
|
+
export declare class PiModelProvider implements GhostProvider {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
private readonly registry;
|
|
32
|
+
private readonly config;
|
|
33
|
+
private readonly streamFn;
|
|
34
|
+
private resolved;
|
|
35
|
+
private resolvedSpec;
|
|
36
|
+
private lastEmpty;
|
|
37
|
+
/**
|
|
38
|
+
* Streaming variant — attached in the constructor **only** when the
|
|
39
|
+
* registry exposes `stream()` (pi ≥ 0.99). The request pipeline selects
|
|
40
|
+
* the streaming path whenever `predictStream` is present, so a class
|
|
41
|
+
* method would make every host look streaming-capable and silently starve
|
|
42
|
+
* pi 0.84–0.98 of ghosts instead of falling back to `predict()`.
|
|
43
|
+
*/
|
|
44
|
+
predictStream?: (req: GhostRequest) => AsyncIterable<StreamDelta>;
|
|
45
|
+
constructor(config: PiModelProviderConfig, registry: ModelRegistry);
|
|
46
|
+
get debounceMs(): number;
|
|
47
|
+
consumeLastEmptyReason(): EmptyReason | null;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve `modelSpec` (`"provider/model-id"` or bare `"model-id"`) to a
|
|
50
|
+
* registry model. Successful lookups are cached per spec; failures retry
|
|
51
|
+
* on the next call (the registry may still be loading models.json early
|
|
52
|
+
* in a session, and a failed scan of the model list is cheap).
|
|
53
|
+
*/
|
|
54
|
+
private resolveModel;
|
|
55
|
+
/**
|
|
56
|
+
* One completion through the registry. Auth, headers, and endpoint are
|
|
57
|
+
* resolved by pi at request time; we only supply sampling knobs, the
|
|
58
|
+
* abort signal, and the SEC-3 timeout.
|
|
59
|
+
*/
|
|
60
|
+
predict(req: GhostRequest): Promise<string | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Streaming implementation behind the conditionally-attached
|
|
63
|
+
* {@link predictStream} — only reachable when the registry exposes
|
|
64
|
+
* `stream()` (pi ≥ 0.99; see {@link StreamingRegistry}). Mirrors
|
|
65
|
+
* {@link CloudProvider.predictStream}: sanitize once on the final
|
|
66
|
+
* assembled text, never per delta.
|
|
67
|
+
*/
|
|
68
|
+
private streamPredict;
|
|
69
|
+
/**
|
|
70
|
+
* Preflight for /ghost diagnostics and router chat-leg warnings: resolves
|
|
71
|
+
* the spec and (when the registry supports it) checks that the model's
|
|
72
|
+
* provider has configured auth.
|
|
73
|
+
*/
|
|
74
|
+
preflight(): Promise<{
|
|
75
|
+
ok: boolean;
|
|
76
|
+
message: string;
|
|
77
|
+
}>;
|
|
78
|
+
}
|