pi-ghost-autocomplete 0.4.0 → 0.5.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 +513 -464
- package/dist/bench-cli.js +1 -1
- package/dist/bench.js +1 -1
- package/dist/config.d.ts +42 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/providers/openai-compat-chat-provider.d.ts +31 -0
- package/dist/providers/router.d.ts +59 -0
- package/dist/replay-cli.js +1 -1
- package/package.json +84 -90
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-License-Identifier: SSPL-1.0
|
|
3
|
+
* SPDX-FileCopyrightText: 2025 Alessandro Pungitore <alessandro@pungitore.ch>
|
|
4
|
+
*/
|
|
5
|
+
import type { OpenAICompatChatProviderConfig } from "../config.js";
|
|
6
|
+
import type { PreflightResult } from "./openai-compat-provider.js";
|
|
7
|
+
import type { GhostProvider, GhostRequest } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Chat-register provider for OpenAI-compatible `/chat/completions` backends
|
|
10
|
+
* (e.g. Inception Mercury's conversational model). Sibling of
|
|
11
|
+
* {@link OpenAICompatProvider}, which uses `/fim/completions` for code.
|
|
12
|
+
*
|
|
13
|
+
* This is the natural-language leg of {@link RouterProvider}: instead of
|
|
14
|
+
* completing code, it completes the developer's *message to the AI coding
|
|
15
|
+
* agent*. The persona that frames the model — "continue the developer's
|
|
16
|
+
* request, don't perform the task" — lives in {@link buildPromptMessages}'s
|
|
17
|
+
* system prompt, shared with the cloud/local chat providers so the wording
|
|
18
|
+
* can't drift across backends.
|
|
19
|
+
*/
|
|
20
|
+
export declare class OpenAICompatChatProvider implements GhostProvider {
|
|
21
|
+
private readonly config;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
constructor(config: OpenAICompatChatProviderConfig);
|
|
24
|
+
get debounceMs(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Validate the API key with a minimal chat request. A successful response
|
|
27
|
+
* (even an empty completion) proves auth + connectivity.
|
|
28
|
+
*/
|
|
29
|
+
preflight(): Promise<PreflightResult>;
|
|
30
|
+
predict(req: GhostRequest): Promise<string | null>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-License-Identifier: SSPL-1.0
|
|
3
|
+
* SPDX-FileCopyrightText: 2025 Alessandro Pungitore <alessandro@pungitore.ch>
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Register-routing provider (PRD §M3h). Holds two legs and dispatches each
|
|
7
|
+
* request to the one whose *register* fits the user's intent:
|
|
8
|
+
*
|
|
9
|
+
* - **FIM leg** (code register) — `command`, `path-ref`, and unclassified
|
|
10
|
+
* requests. A code fill-in-the-middle model (Mercury Edit) completes
|
|
11
|
+
* commands, paths, and code-shaped drafts.
|
|
12
|
+
* - **chat leg** (instruction register) — `instruction`, `question`, `prose`.
|
|
13
|
+
* A conversational model completes the developer's *message to the AI coding
|
|
14
|
+
* agent* (their request/instruction), instead of writing the solution. This
|
|
15
|
+
* is the fix for "the autocomplete keeps suggesting solutions": a code-FIM
|
|
16
|
+
* model, fed a natural-language prompt, completes it like code.
|
|
17
|
+
*
|
|
18
|
+
* When `chat` is null the router degrades to FIM-only — byte-for-byte the
|
|
19
|
+
* default behavior before routing existed, so enabling router mode without a
|
|
20
|
+
* reachable chat backend never regresses.
|
|
21
|
+
*/
|
|
22
|
+
import type { PromptIntent } from "../intent.js";
|
|
23
|
+
import type { PreflightResult } from "./openai-compat-provider.js";
|
|
24
|
+
import { type CandidateSet, type GhostProvider, type GhostRequest } from "./types.js";
|
|
25
|
+
/** Pure routing predicate — exported for direct testing. */
|
|
26
|
+
export declare function routeToChat(intent: PromptIntent | undefined): boolean;
|
|
27
|
+
export declare class RouterProvider implements GhostProvider {
|
|
28
|
+
private readonly fim;
|
|
29
|
+
private readonly chat;
|
|
30
|
+
readonly name = "ghost-router";
|
|
31
|
+
constructor(fim: GhostProvider, chat: GhostProvider | null);
|
|
32
|
+
get debounceMs(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Which leg an intent resolves to — `"chat"` only when a chat leg is
|
|
35
|
+
* present AND the intent is natural-language; otherwise `"fim"` (including
|
|
36
|
+
* the chat-absent fallback). Pure; used by the editor to tag metrics with
|
|
37
|
+
* the served register so bench can split FIM-vs-chat quality.
|
|
38
|
+
*/
|
|
39
|
+
legFor(intent: PromptIntent | undefined): "fim" | "chat";
|
|
40
|
+
/** Choose the leg for this request. Chat leg only when present AND the
|
|
41
|
+
* intent is natural-language; otherwise FIM. */
|
|
42
|
+
private leg;
|
|
43
|
+
predict(req: GhostRequest): Promise<string | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Route, then adapt the chosen leg to the multi-candidate surface. The
|
|
46
|
+
* editor calls this (router exposes no `predictStream`, so it takes the
|
|
47
|
+
* `wrapAsMulti` branch). `wrapAsMulti` uses the leg's own `predictMulti`
|
|
48
|
+
* when present (FIM parallel-fire) and otherwise wraps `predict`.
|
|
49
|
+
*/
|
|
50
|
+
predictMulti(req: GhostRequest): Promise<CandidateSet | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Preflight the FIM leg — it carries the primary key/endpoint and is the
|
|
53
|
+
* always-present leg. The chat leg shares the same vendor/key by default;
|
|
54
|
+
* its own failures surface as silently-dropped NL completions (which fall
|
|
55
|
+
* back to nothing rather than a wrong answer), so we don't block startup
|
|
56
|
+
* on it.
|
|
57
|
+
*/
|
|
58
|
+
preflight(): Promise<boolean | PreflightResult>;
|
|
59
|
+
}
|