pi-ghost-autocomplete 0.3.2 → 0.4.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/LICENSE +561 -0
- package/README.md +464 -331
- package/dist/bench-cli.js +1 -123
- package/dist/bench.d.ts +7 -3
- package/dist/bench.js +1 -522
- package/dist/config.d.ts +4 -1
- package/dist/context-aggregator.d.ts +4 -1
- package/dist/cycle-manager.d.ts +2 -21
- package/dist/entropy-stop.d.ts +4 -1
- package/dist/eval-dataset.d.ts +2 -13
- package/dist/fuzzy-matcher.d.ts +4 -1
- package/dist/ghost-editor.d.ts +11 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -289
- package/dist/intent.d.ts +179 -0
- package/dist/metrics.d.ts +4 -1
- package/dist/path-index.d.ts +4 -1
- package/dist/path-matcher.d.ts +4 -1
- package/dist/profile-store.d.ts +4 -1
- package/dist/profile.d.ts +2 -20
- package/dist/providers/cloud-provider.d.ts +4 -1
- package/dist/providers/local-provider.d.ts +4 -1
- package/dist/providers/openai-compat-provider.d.ts +24 -1
- package/dist/providers/race.d.ts +4 -1
- package/dist/providers/types.d.ts +13 -1
- package/dist/recent-paths.d.ts +4 -1
- package/dist/replay-cli.js +1 -166
- package/dist/replay.d.ts +2 -7
- package/package.json +90 -80
- package/dist/bench-cli.d.ts +0 -3
- package/dist/bench-cli.d.ts.map +0 -1
- package/dist/bench-cli.js.map +0 -1
- package/dist/bench.d.ts.map +0 -1
- package/dist/bench.js.map +0 -1
- package/dist/cache.d.ts +0 -124
- package/dist/cache.d.ts.map +0 -1
- package/dist/cache.js +0 -173
- package/dist/cache.js.map +0 -1
- package/dist/candidate-rerank.d.ts +0 -57
- package/dist/candidate-rerank.d.ts.map +0 -1
- package/dist/candidate-rerank.js +0 -78
- package/dist/candidate-rerank.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -317
- package/dist/config.js.map +0 -1
- package/dist/context-aggregator.d.ts.map +0 -1
- package/dist/context-aggregator.js +0 -87
- package/dist/context-aggregator.js.map +0 -1
- package/dist/context-selector.d.ts +0 -128
- package/dist/context-selector.d.ts.map +0 -1
- package/dist/context-selector.js +0 -300
- package/dist/context-selector.js.map +0 -1
- package/dist/cycle-manager.d.ts.map +0 -1
- package/dist/cycle-manager.js +0 -168
- package/dist/cycle-manager.js.map +0 -1
- package/dist/edit-history-ring.d.ts +0 -148
- package/dist/edit-history-ring.d.ts.map +0 -1
- package/dist/edit-history-ring.js +0 -262
- package/dist/edit-history-ring.js.map +0 -1
- package/dist/entropy-stop.d.ts.map +0 -1
- package/dist/entropy-stop.js +0 -141
- package/dist/entropy-stop.js.map +0 -1
- package/dist/eval-dataset.d.ts.map +0 -1
- package/dist/eval-dataset.js +0 -127
- package/dist/eval-dataset.js.map +0 -1
- package/dist/fast-path-engine.d.ts +0 -286
- package/dist/fast-path-engine.d.ts.map +0 -1
- package/dist/fast-path-engine.js +0 -341
- package/dist/fast-path-engine.js.map +0 -1
- package/dist/fuzzy-matcher.d.ts.map +0 -1
- package/dist/fuzzy-matcher.js +0 -162
- package/dist/fuzzy-matcher.js.map +0 -1
- package/dist/ghost-editor.d.ts.map +0 -1
- package/dist/ghost-editor.js +0 -1491
- package/dist/ghost-editor.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keystroke-timer.d.ts +0 -59
- package/dist/keystroke-timer.d.ts.map +0 -1
- package/dist/keystroke-timer.js +0 -94
- package/dist/keystroke-timer.js.map +0 -1
- package/dist/metrics-builder.d.ts +0 -71
- package/dist/metrics-builder.d.ts.map +0 -1
- package/dist/metrics-builder.js +0 -71
- package/dist/metrics-builder.js.map +0 -1
- package/dist/metrics.d.ts.map +0 -1
- package/dist/metrics.js +0 -212
- package/dist/metrics.js.map +0 -1
- package/dist/path-index.d.ts.map +0 -1
- package/dist/path-index.js +0 -148
- package/dist/path-index.js.map +0 -1
- package/dist/path-matcher.d.ts.map +0 -1
- package/dist/path-matcher.js +0 -88
- package/dist/path-matcher.js.map +0 -1
- package/dist/profile-store.d.ts.map +0 -1
- package/dist/profile-store.js +0 -199
- package/dist/profile-store.js.map +0 -1
- package/dist/profile.d.ts.map +0 -1
- package/dist/profile.js +0 -434
- package/dist/profile.js.map +0 -1
- package/dist/providers/cloud-provider.d.ts.map +0 -1
- package/dist/providers/cloud-provider.js +0 -109
- package/dist/providers/cloud-provider.js.map +0 -1
- package/dist/providers/local-provider.d.ts.map +0 -1
- package/dist/providers/local-provider.js +0 -48
- package/dist/providers/local-provider.js.map +0 -1
- package/dist/providers/openai-compat-provider.d.ts.map +0 -1
- package/dist/providers/openai-compat-provider.js +0 -215
- package/dist/providers/openai-compat-provider.js.map +0 -1
- package/dist/providers/openai-completions-runner.d.ts +0 -52
- package/dist/providers/openai-completions-runner.d.ts.map +0 -1
- package/dist/providers/openai-completions-runner.js +0 -141
- package/dist/providers/openai-completions-runner.js.map +0 -1
- package/dist/providers/race.d.ts.map +0 -1
- package/dist/providers/race.js +0 -441
- package/dist/providers/race.js.map +0 -1
- package/dist/providers/truncate.d.ts +0 -7
- package/dist/providers/truncate.d.ts.map +0 -1
- package/dist/providers/truncate.js +0 -57
- package/dist/providers/truncate.js.map +0 -1
- package/dist/providers/types.d.ts.map +0 -1
- package/dist/providers/types.js +0 -60
- package/dist/providers/types.js.map +0 -1
- package/dist/provisional-manager.d.ts +0 -93
- package/dist/provisional-manager.d.ts.map +0 -1
- package/dist/provisional-manager.js +0 -98
- package/dist/provisional-manager.js.map +0 -1
- package/dist/provisional.d.ts +0 -150
- package/dist/provisional.d.ts.map +0 -1
- package/dist/provisional.js +0 -238
- package/dist/provisional.js.map +0 -1
- package/dist/recent-paths.d.ts.map +0 -1
- package/dist/recent-paths.js +0 -114
- package/dist/recent-paths.js.map +0 -1
- package/dist/regret-tracker.d.ts +0 -84
- package/dist/regret-tracker.d.ts.map +0 -1
- package/dist/regret-tracker.js +0 -145
- package/dist/regret-tracker.js.map +0 -1
- package/dist/replay-cli.d.ts +0 -13
- package/dist/replay-cli.d.ts.map +0 -1
- package/dist/replay-cli.js.map +0 -1
- package/dist/replay.d.ts.map +0 -1
- package/dist/replay.js +0 -225
- package/dist/replay.js.map +0 -1
- package/dist/reranker.d.ts +0 -181
- package/dist/reranker.d.ts.map +0 -1
- package/dist/reranker.js +0 -324
- package/dist/reranker.js.map +0 -1
- package/dist/session-trie.d.ts +0 -103
- package/dist/session-trie.d.ts.map +0 -1
- package/dist/session-trie.js +0 -280
- package/dist/session-trie.js.map +0 -1
- package/dist/speculative.d.ts +0 -74
- package/dist/speculative.d.ts.map +0 -1
- package/dist/speculative.js +0 -107
- package/dist/speculative.js.map +0 -1
- package/dist/tool-summarize.d.ts +0 -40
- package/dist/tool-summarize.d.ts.map +0 -1
- package/dist/tool-summarize.js +0 -245
- package/dist/tool-summarize.js.map +0 -1
- package/dist/trie-sanitize.d.ts +0 -22
- package/dist/trie-sanitize.d.ts.map +0 -1
- package/dist/trie-sanitize.js +0 -142
- package/dist/trie-sanitize.js.map +0 -1
- package/dist/versions.d.ts +0 -23
- package/dist/versions.d.ts.map +0 -1
- package/dist/versions.js +0 -31
- package/dist/versions.js.map +0 -1
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { complete, getEnvApiKey, getModels, stream, } from "@earendil-works/pi-ai";
|
|
2
|
-
import { streamWithSanitize } from "./openai-completions-runner.js";
|
|
3
|
-
import { buildPromptMessages, sanitizeCompletion } from "./truncate.js";
|
|
4
|
-
/** SEC-3: absolute upper bound for a single cloud completion call. */
|
|
5
|
-
const REQUEST_TIMEOUT_MS = 10_000;
|
|
6
|
-
export class CloudProvider {
|
|
7
|
-
config;
|
|
8
|
-
name = "ghost-cloud";
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
}
|
|
12
|
-
get debounceMs() {
|
|
13
|
-
return this.config.debounceMs;
|
|
14
|
-
}
|
|
15
|
-
async predict(req) {
|
|
16
|
-
const apiKey = this.config.apiKey ?? getEnvApiKey(this.config.provider);
|
|
17
|
-
if (!apiKey)
|
|
18
|
-
return null;
|
|
19
|
-
const model = resolveModel(this.config.provider, this.config.modelId);
|
|
20
|
-
if (!model)
|
|
21
|
-
return null;
|
|
22
|
-
const { systemPrompt, user } = buildPromptMessages(req, this.config.maxRecentMessages);
|
|
23
|
-
const messages = [{ role: "user", content: user, timestamp: Date.now() }];
|
|
24
|
-
const ctx = { systemPrompt, messages };
|
|
25
|
-
// SEC-3: cap the call at REQUEST_TIMEOUT_MS in addition to the
|
|
26
|
-
// user's keystroke-driven abort.
|
|
27
|
-
const localCtrl = new AbortController();
|
|
28
|
-
const onUserAbort = () => localCtrl.abort();
|
|
29
|
-
if (req.signal.aborted)
|
|
30
|
-
localCtrl.abort();
|
|
31
|
-
else
|
|
32
|
-
req.signal.addEventListener("abort", onUserAbort, { once: true });
|
|
33
|
-
const timeoutHandle = setTimeout(() => localCtrl.abort(), REQUEST_TIMEOUT_MS);
|
|
34
|
-
try {
|
|
35
|
-
const result = await complete(model, ctx, {
|
|
36
|
-
signal: localCtrl.signal,
|
|
37
|
-
temperature: this.config.temperature,
|
|
38
|
-
maxTokens: this.config.maxTokens,
|
|
39
|
-
apiKey,
|
|
40
|
-
});
|
|
41
|
-
if (result.stopReason === "error" || result.stopReason === "aborted")
|
|
42
|
-
return null;
|
|
43
|
-
const text = result.content
|
|
44
|
-
.filter((c) => c.type === "text")
|
|
45
|
-
.map((c) => c.text)
|
|
46
|
-
.join("");
|
|
47
|
-
return sanitizeCompletion(text, req.editorTextBeforeCursor, 200);
|
|
48
|
-
}
|
|
49
|
-
finally {
|
|
50
|
-
clearTimeout(timeoutHandle);
|
|
51
|
-
req.signal.removeEventListener("abort", onUserAbort);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* PRD §M3.5a — stream tokens from the upstream provider via pi-ai's
|
|
56
|
-
* `stream()`. Yields `text_delta` events as `StreamDelta` chunks
|
|
57
|
-
* including a running `cumulative` to spare the editor from tracking
|
|
58
|
-
* concatenation state. `sanitizeCompletion` runs once on the final
|
|
59
|
-
* assembled text after the stream ends — running it per-chunk would
|
|
60
|
-
* truncate mid-token and break ghost rendering.
|
|
61
|
-
*/
|
|
62
|
-
async *predictStream(req) {
|
|
63
|
-
const apiKey = this.config.apiKey ?? getEnvApiKey(this.config.provider);
|
|
64
|
-
if (!apiKey)
|
|
65
|
-
return;
|
|
66
|
-
const model = resolveModel(this.config.provider, this.config.modelId);
|
|
67
|
-
if (!model)
|
|
68
|
-
return;
|
|
69
|
-
const { systemPrompt, user } = buildPromptMessages(req, this.config.maxRecentMessages);
|
|
70
|
-
const messages = [{ role: "user", content: user, timestamp: Date.now() }];
|
|
71
|
-
const ctx = { systemPrompt, messages };
|
|
72
|
-
const localCtrl = new AbortController();
|
|
73
|
-
const onUserAbort = () => localCtrl.abort();
|
|
74
|
-
if (req.signal.aborted)
|
|
75
|
-
localCtrl.abort();
|
|
76
|
-
else
|
|
77
|
-
req.signal.addEventListener("abort", onUserAbort, { once: true });
|
|
78
|
-
const timeoutHandle = setTimeout(() => localCtrl.abort(), REQUEST_TIMEOUT_MS);
|
|
79
|
-
try {
|
|
80
|
-
const events = stream(model, ctx, {
|
|
81
|
-
signal: localCtrl.signal,
|
|
82
|
-
temperature: this.config.temperature,
|
|
83
|
-
maxTokens: this.config.maxTokens,
|
|
84
|
-
apiKey,
|
|
85
|
-
});
|
|
86
|
-
yield* streamWithSanitize(events, req.editorTextBeforeCursor);
|
|
87
|
-
}
|
|
88
|
-
finally {
|
|
89
|
-
clearTimeout(timeoutHandle);
|
|
90
|
-
req.signal.removeEventListener("abort", onUserAbort);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Look up a model by id from pi-ai's registry. Returns null if the provider
|
|
96
|
-
* has no model with that id; the caller drops the prediction silently.
|
|
97
|
-
*
|
|
98
|
-
* Avoids `getModel(provider, id as never)` — the registry's typed lookup
|
|
99
|
-
* requires a literal id and would otherwise need an unsafe cast.
|
|
100
|
-
*/
|
|
101
|
-
function resolveModel(provider, modelId) {
|
|
102
|
-
const models = getModels(provider);
|
|
103
|
-
for (const m of models) {
|
|
104
|
-
if (m.id === modelId)
|
|
105
|
-
return m;
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
//# sourceMappingURL=cloud-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-provider.js","sourceRoot":"","sources":["../../src/providers/cloud-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,MAAM,GAMN,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGxE,sEAAsE;AACtE,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,MAAM,OAAO,aAAa;IAGI;IAFpB,IAAI,GAAG,aAAa,CAAC;IAE9B,YAA6B,MAA2B;QAA3B,WAAM,GAAN,MAAM,CAAqB;IAAG,CAAC;IAE5D,IAAI,UAAU;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAiB;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAEzB,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtE,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,MAAM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,YAAY,CAAC;AAI3E,qBAAa,aAAc,YAAW,aAAa;IAGtC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,QAAQ,CAAC,IAAI,iBAAiB;gBAED,MAAM,EAAE,mBAAmB;IAExD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAEK,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAY7B,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIxD;;;;OAIG;IACH,aAAa,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa,CAAC,WAAW,CAAC;IAI5D,OAAO,CAAC,QAAQ;CAYhB"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { runOpenAICompletion, runOpenAICompletionStream, trimSlash, } from "./openai-completions-runner.js";
|
|
2
|
-
const DEFAULT_CONTEXT_WINDOW = 8192;
|
|
3
|
-
export class LocalProvider {
|
|
4
|
-
config;
|
|
5
|
-
name = "ghost-local";
|
|
6
|
-
constructor(config) {
|
|
7
|
-
this.config = config;
|
|
8
|
-
}
|
|
9
|
-
get debounceMs() {
|
|
10
|
-
return this.config.debounceMs;
|
|
11
|
-
}
|
|
12
|
-
async preflight() {
|
|
13
|
-
try {
|
|
14
|
-
const ctrl = new AbortController();
|
|
15
|
-
const timeout = setTimeout(() => ctrl.abort(), 750);
|
|
16
|
-
const res = await fetch(`${trimSlash(this.config.baseUrl)}/api/tags`, { signal: ctrl.signal });
|
|
17
|
-
clearTimeout(timeout);
|
|
18
|
-
return res.ok;
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async predict(req) {
|
|
25
|
-
return runOpenAICompletion(req, this.callOpts());
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* PRD §M3.5a — Ollama/vLLM streaming via the OpenAI-completions stream
|
|
29
|
-
* endpoint. Same opts as `predict`, just driven by the runner's
|
|
30
|
-
* streaming variant.
|
|
31
|
-
*/
|
|
32
|
-
predictStream(req) {
|
|
33
|
-
return runOpenAICompletionStream(req, this.callOpts());
|
|
34
|
-
}
|
|
35
|
-
callOpts() {
|
|
36
|
-
return {
|
|
37
|
-
baseUrl: `${trimSlash(this.config.baseUrl)}/v1`,
|
|
38
|
-
apiKey: "ollama",
|
|
39
|
-
modelId: this.config.modelId,
|
|
40
|
-
providerTag: "ollama",
|
|
41
|
-
maxTokens: this.config.maxTokens,
|
|
42
|
-
maxRecentMessages: this.config.maxRecentMessages,
|
|
43
|
-
contextWindow: this.config.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
44
|
-
temperature: this.config.temperature,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=local-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local-provider.js","sourceRoot":"","sources":["../../src/providers/local-provider.ts"],"names":[],"mappings":"AACA,OAAO,EACN,mBAAmB,EACnB,yBAAyB,EACzB,SAAS,GACT,MAAM,gCAAgC,CAAC;AAGxC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC,MAAM,OAAO,aAAa;IAGI;IAFpB,IAAI,GAAG,aAAa,CAAC;IAE9B,YAA6B,MAA2B;QAA3B,WAAM,GAAN,MAAM,CAAqB;IAAG,CAAC;IAE5D,IAAI,UAAU;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,SAAS;QACd,IAAI,CAAC;YACJ,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAC;YACnC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC;YACpD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAA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C,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,qBAAa,oBAAqB,YAAW,aAAa;IAG7C,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEO,MAAM,EAAE,0BAA0B;IAI/D,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,eAAe,CAAC;IA+BrC,OAAO,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIxD;;;;;;OAMG;IACG,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAsBnE,OAAO,CAAC,kBAAkB;YAgBZ,OAAO;CAoDrB"}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { sanitizeCompletion } from "./truncate.js";
|
|
2
|
-
const PREFLIGHT_TIMEOUT_MS = 5_000;
|
|
3
|
-
/**
|
|
4
|
-
* Absolute upper bound on a single FIM POST. The user's abort signal still
|
|
5
|
-
* cancels earlier under normal typing; this guards against hung connections
|
|
6
|
-
* when the user isn't typing (no fresh keystroke → no fresh abort). SEC-3.
|
|
7
|
-
*/
|
|
8
|
-
const REQUEST_TIMEOUT_MS = 10_000;
|
|
9
|
-
/**
|
|
10
|
-
* Provider for FIM-completions backends (e.g. Mercury Edit 2 by Inception
|
|
11
|
-
* Labs). Calls `/fim/completions` with `prompt`/`suffix` and returns the
|
|
12
|
-
* raw text completion.
|
|
13
|
-
*
|
|
14
|
-
* A {@link preflight} method validates the API key at startup so the host
|
|
15
|
-
* can surface configuration errors early instead of silently dropping
|
|
16
|
-
* every prediction.
|
|
17
|
-
*/
|
|
18
|
-
export class OpenAICompatProvider {
|
|
19
|
-
config;
|
|
20
|
-
name;
|
|
21
|
-
constructor(config) {
|
|
22
|
-
this.config = config;
|
|
23
|
-
this.name = `ghost-${config.providerName}`;
|
|
24
|
-
}
|
|
25
|
-
get debounceMs() {
|
|
26
|
-
return this.config.debounceMs;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Validate the API key with a minimal FIM request. A successful
|
|
30
|
-
* response (even an empty completion) proves auth + connectivity.
|
|
31
|
-
*/
|
|
32
|
-
async preflight() {
|
|
33
|
-
const apiKey = this.config.apiKey;
|
|
34
|
-
if (!apiKey)
|
|
35
|
-
return { ok: false, message: "no API key configured" };
|
|
36
|
-
const ctrl = new AbortController();
|
|
37
|
-
const timeout = setTimeout(() => ctrl.abort(), PREFLIGHT_TIMEOUT_MS);
|
|
38
|
-
try {
|
|
39
|
-
const res = await fetch(`${trimSlash(this.config.baseUrl)}/fim/completions`, {
|
|
40
|
-
method: "POST",
|
|
41
|
-
headers: {
|
|
42
|
-
"Content-Type": "application/json",
|
|
43
|
-
Authorization: `Bearer ${apiKey}`,
|
|
44
|
-
},
|
|
45
|
-
body: JSON.stringify({
|
|
46
|
-
model: this.config.modelId,
|
|
47
|
-
prompt: " ",
|
|
48
|
-
max_tokens: 1,
|
|
49
|
-
}),
|
|
50
|
-
signal: ctrl.signal,
|
|
51
|
-
});
|
|
52
|
-
clearTimeout(timeout);
|
|
53
|
-
if (res.ok)
|
|
54
|
-
return { ok: true, status: res.status, message: "ok" };
|
|
55
|
-
return { ok: false, status: res.status, message: describeHttpError(res.status) };
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
clearTimeout(timeout);
|
|
59
|
-
const aborted = err?.name === "AbortError";
|
|
60
|
-
if (aborted)
|
|
61
|
-
return { ok: false, message: "endpoint timed out" };
|
|
62
|
-
return { ok: false, message: "endpoint unreachable" };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async predict(req) {
|
|
66
|
-
return this.fireOne(req);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Multi-candidate prediction. Fires `config.parallelN` FIM requests in
|
|
70
|
-
* parallel and dedupes by exact text. PRD §M3b: FIM does not support
|
|
71
|
-
* the `n` parameter, so parallel POSTs are the only n>1 path. Parallel
|
|
72
|
-
* fire is only useful at temperature > 0 — at temp=0 every call returns
|
|
73
|
-
* the same greedy result. We downgrade silently to n=1 in that case.
|
|
74
|
-
*/
|
|
75
|
-
async predictMulti(req) {
|
|
76
|
-
const n = this.effectiveParallelN();
|
|
77
|
-
if (n <= 1) {
|
|
78
|
-
const text = await this.fireOne(req);
|
|
79
|
-
if (!text)
|
|
80
|
-
return null;
|
|
81
|
-
return { candidates: [{ text }] };
|
|
82
|
-
}
|
|
83
|
-
const results = await Promise.all(Array.from({ length: n }, () => this.fireOne(req)));
|
|
84
|
-
const seen = new Set();
|
|
85
|
-
const candidates = [];
|
|
86
|
-
for (const text of results) {
|
|
87
|
-
if (!text)
|
|
88
|
-
continue;
|
|
89
|
-
if (seen.has(text))
|
|
90
|
-
continue;
|
|
91
|
-
seen.add(text);
|
|
92
|
-
candidates.push({ text });
|
|
93
|
-
}
|
|
94
|
-
if (candidates.length === 0)
|
|
95
|
-
return null;
|
|
96
|
-
return { candidates };
|
|
97
|
-
}
|
|
98
|
-
effectiveParallelN() {
|
|
99
|
-
const n = this.config.parallelN;
|
|
100
|
-
// Guard against NaN / non-finite — a corrupted config should never
|
|
101
|
-
// make us hit Array.from({length: NaN}).
|
|
102
|
-
if (!Number.isFinite(n) || n <= 1)
|
|
103
|
-
return 1;
|
|
104
|
-
// At temp=0 parallel-fire produces identical greedy outputs. Cost
|
|
105
|
-
// without value → downgrade. PRD §M3b documents this case.
|
|
106
|
-
//
|
|
107
|
-
// Assumption: at temperature>0 the backend (Mercury Edit FIM) actually
|
|
108
|
-
// samples non-deterministically. If a future backend caches by
|
|
109
|
-
// prompt+temp without sampling jitter, parallel-fire degenerates to
|
|
110
|
-
// the same downgrade scenario. Worth re-testing per-vendor.
|
|
111
|
-
if (this.config.temperature === 0)
|
|
112
|
-
return 1;
|
|
113
|
-
return Math.floor(n);
|
|
114
|
-
}
|
|
115
|
-
async fireOne(req) {
|
|
116
|
-
const apiKey = this.config.apiKey;
|
|
117
|
-
if (!apiKey)
|
|
118
|
-
return null;
|
|
119
|
-
const { prompt, suffix } = buildFIMPrompt(req, this.config.maxRecentMessages);
|
|
120
|
-
// Combine the caller's abort with an absolute timeout. SEC-3:
|
|
121
|
-
// without this, a hung TCP connection could pin resources until
|
|
122
|
-
// the user types again (the only thing that fires `req.signal`).
|
|
123
|
-
const localCtrl = new AbortController();
|
|
124
|
-
const onUserAbort = () => localCtrl.abort();
|
|
125
|
-
if (req.signal.aborted)
|
|
126
|
-
localCtrl.abort();
|
|
127
|
-
else
|
|
128
|
-
req.signal.addEventListener("abort", onUserAbort, { once: true });
|
|
129
|
-
const timeoutHandle = setTimeout(() => localCtrl.abort(), REQUEST_TIMEOUT_MS);
|
|
130
|
-
try {
|
|
131
|
-
const res = await fetch(`${trimSlash(this.config.baseUrl)}/fim/completions`, {
|
|
132
|
-
method: "POST",
|
|
133
|
-
headers: {
|
|
134
|
-
"Content-Type": "application/json",
|
|
135
|
-
Authorization: `Bearer ${apiKey}`,
|
|
136
|
-
},
|
|
137
|
-
body: JSON.stringify({
|
|
138
|
-
model: this.config.modelId,
|
|
139
|
-
prompt,
|
|
140
|
-
suffix,
|
|
141
|
-
max_tokens: this.config.maxTokens,
|
|
142
|
-
temperature: this.config.temperature,
|
|
143
|
-
}),
|
|
144
|
-
signal: localCtrl.signal,
|
|
145
|
-
});
|
|
146
|
-
if (!res.ok)
|
|
147
|
-
return null;
|
|
148
|
-
try {
|
|
149
|
-
const data = (await res.json());
|
|
150
|
-
const text = data.choices?.[0]?.text ?? "";
|
|
151
|
-
return sanitizeCompletion(text, req.editorTextBeforeCursor, 200);
|
|
152
|
-
}
|
|
153
|
-
catch (parseErr) {
|
|
154
|
-
if (parseErr instanceof SyntaxError) {
|
|
155
|
-
console.error(`[OpenAICompatProvider] malformed JSON response (status ${res.status})`);
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
throw parseErr;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
finally {
|
|
165
|
-
clearTimeout(timeoutHandle);
|
|
166
|
-
req.signal.removeEventListener("abort", onUserAbort);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Build the FIM prompt/suffix pair from the ghost request.
|
|
172
|
-
*
|
|
173
|
-
* Recent conversation messages are prepended as comments in the prompt
|
|
174
|
-
* so the model has context about what the user is working on.
|
|
175
|
-
*/
|
|
176
|
-
function buildFIMPrompt(req, maxRecent) {
|
|
177
|
-
const recent = req.recentMessages
|
|
178
|
-
.slice(-maxRecent)
|
|
179
|
-
.map((m) => {
|
|
180
|
-
// PRD §M6a: tool entries render with a distinguishing prefix so
|
|
181
|
-
// the model can tell prior tool output from conversational turns.
|
|
182
|
-
if (m.role === "tool") {
|
|
183
|
-
const label = m.toolName ? `tool ${m.toolName}` : "tool";
|
|
184
|
-
return `# ${label}: ${truncate(m.text, 280)}`;
|
|
185
|
-
}
|
|
186
|
-
return `# ${m.role}: ${truncate(m.text, 280)}`;
|
|
187
|
-
})
|
|
188
|
-
.join("\n");
|
|
189
|
-
const ctx = recent ? `${recent}\n\n` : "";
|
|
190
|
-
// Split the editor text at cursor to form prompt (before) / suffix (after).
|
|
191
|
-
// Ghost autocomplete only fires when cursor is at end, so suffix is empty
|
|
192
|
-
// in the common case — but we handle the general case for correctness.
|
|
193
|
-
const before = req.editorTextBeforeCursor;
|
|
194
|
-
const after = req.editorText.slice(req.editorTextBeforeCursor.length);
|
|
195
|
-
return {
|
|
196
|
-
prompt: `${ctx}${before}`,
|
|
197
|
-
suffix: after,
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
function truncate(s, n) {
|
|
201
|
-
return s.length > n ? `${s.slice(0, n)}…` : s;
|
|
202
|
-
}
|
|
203
|
-
function trimSlash(url) {
|
|
204
|
-
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
205
|
-
}
|
|
206
|
-
function describeHttpError(status) {
|
|
207
|
-
switch (status) {
|
|
208
|
-
case 401: return "invalid API key (401 Unauthorized)";
|
|
209
|
-
case 402: return "API key has no credits — please top up (402 Payment Required)";
|
|
210
|
-
case 403: return "API key not permitted (403 Forbidden)";
|
|
211
|
-
case 429: return "rate limited (429 Too Many Requests)";
|
|
212
|
-
default: return `HTTP ${status}`;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
//# sourceMappingURL=openai-compat-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai-compat-provider.js","sourceRoot":"","sources":["../../src/providers/openai-compat-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAQlC;;;;;;;;GAQG;AACH,MAAM,OAAO,oBAAoB;IAGH;IAFpB,IAAI,CAAS;IAEtB,YAA6B,MAAkC;QAAlC,WAAM,GAAN,MAAM,CAA4B;QAC9D,IAAI,CAAC,IAAI,GAAG,SAAS,MAAM,CAAC,YAAY,EAAE,CAAC;IAC5C,CAAC;IAED,IAAI,UAAU;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,SAAS;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;QAEpE,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CA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C,CAAC,CAAC,CAAC,GAAG,CAAC;AACnD,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACxC,QAAQ,MAAM,EAAE,CAAC;QAChB,KAAK,GAAG,CAAC,CAAC,OAAO,oCAAoC,CAAC;QACtD,KAAK,GAAG,CAAC,CAAC,OAAO,+DAA+D,CAAC;QACjF,KAAK,GAAG,CAAC,CAAC,OAAO,uCAAuC,CAAC;QACzD,KAAK,GAAG,CAAC,CAAC,OAAO,sCAAsC,CAAC;QACxD,OAAO,CAAC,CAAC,OAAO,QAAQ,MAAM,EAAE,CAAC;IAClC,CAAC;AACF,CAAC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { type AssistantMessageEventStream } from "@earendil-works/pi-ai";
|
|
2
|
-
import type { GhostRequest, StreamDelta } from "./types.js";
|
|
3
|
-
export interface OpenAICompletionsCallOpts {
|
|
4
|
-
baseUrl: string;
|
|
5
|
-
apiKey: string;
|
|
6
|
-
modelId: string;
|
|
7
|
-
/**
|
|
8
|
-
* Metadata tag for pi-ai's `Model.provider`. Cosmetic for logs — the
|
|
9
|
-
* actual endpoint is driven by `baseUrl`. Accepts any string; cast to
|
|
10
|
-
* `KnownProvider` at the call site since the field is purely descriptive.
|
|
11
|
-
*/
|
|
12
|
-
providerTag: string;
|
|
13
|
-
maxTokens: number;
|
|
14
|
-
maxRecentMessages: number;
|
|
15
|
-
contextWindow: number;
|
|
16
|
-
temperature: number;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Shared OpenAI-completions request path used by both {@link LocalProvider}
|
|
20
|
-
* and {@link OpenAICompatProvider}. Builds the pi-ai model record, sends one
|
|
21
|
-
* `complete()` call with the user's abort signal, and returns a sanitized
|
|
22
|
-
* completion string (or null when the call aborts/errors/produces nothing
|
|
23
|
-
* usable).
|
|
24
|
-
*
|
|
25
|
-
* Kept as a free function rather than a base class to avoid one-method
|
|
26
|
-
* inheritance.
|
|
27
|
-
*/
|
|
28
|
-
export declare function runOpenAICompletion(req: GhostRequest, opts: OpenAICompletionsCallOpts): Promise<string | null>;
|
|
29
|
-
export declare function trimSlash(url: string): string;
|
|
30
|
-
/**
|
|
31
|
-
* Streaming variant of {@link runOpenAICompletion}. Yields {@link StreamDelta}
|
|
32
|
-
* chunks as pi-ai's `stream()` produces `text_delta` events. Sanitization
|
|
33
|
-
* runs on the running cumulative (not per-delta) — per-delta would clip
|
|
34
|
-
* mid-token and break ghost rendering.
|
|
35
|
-
*
|
|
36
|
-
* Yields nothing on auth/connectivity failure, abort, or when the model
|
|
37
|
-
* record can't be built. The generator's `finally` block clears the
|
|
38
|
-
* SEC-3 timer and detaches the user-abort listener.
|
|
39
|
-
*/
|
|
40
|
-
export declare function runOpenAICompletionStream(req: GhostRequest, opts: OpenAICompletionsCallOpts): AsyncIterable<StreamDelta>;
|
|
41
|
-
/**
|
|
42
|
-
* Iterate a pi-ai `AssistantMessageEventStream`, filtering for non-empty
|
|
43
|
-
* `text_delta` events and emitting them through `sanitizeCompletion` as
|
|
44
|
-
* `StreamDelta` chunks. Sanitization runs on the running cumulative
|
|
45
|
-
* (NOT per-delta) since per-token clipping would break ghost rendering.
|
|
46
|
-
*
|
|
47
|
-
* Shared by `runOpenAICompletionStream` (Local) and CloudProvider's
|
|
48
|
-
* `predictStream` so the two paths can't drift on filter/sanitize
|
|
49
|
-
* semantics.
|
|
50
|
-
*/
|
|
51
|
-
export declare function streamWithSanitize(events: AssistantMessageEventStream, prefix: string): AsyncIterable<StreamDelta>;
|
|
52
|
-
//# sourceMappingURL=openai-completions-runner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai-completions-runner.d.ts","sourceRoot":"","sources":["../../src/providers/openai-completions-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,2BAA2B,EAKhC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAU5D,MAAM,WAAW,yBAAyB;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACxC,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,yBAAyB,GAC7B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA2CxB;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;;;;;GASG;AACH,wBAAuB,yBAAyB,CAC/C,GAAG,EAAE,YAAY,EACjB,IAAI,EAAE,yBAAyB,GAC7B,aAAa,CAAC,WAAW,CAAC,CAoC5B;AAED;;;;;;;;;GASG;AACH,wBAAuB,kBAAkB,CACxC,MAAM,EAAE,2BAA2B,EACnC,MAAM,EAAE,MAAM,GACZ,aAAa,CAAC,WAAW,CAAC,CAa5B"}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { complete, stream, } from "@earendil-works/pi-ai";
|
|
2
|
-
import { buildPromptMessages, sanitizeCompletion } from "./truncate.js";
|
|
3
|
-
/**
|
|
4
|
-
* Absolute upper bound on a single completion call. Backs SEC-3 for the
|
|
5
|
-
* pi-ai-backed paths (CloudProvider, LocalProvider). The user's keystroke
|
|
6
|
-
* abort still cancels earlier; this is the guard for a stationary user
|
|
7
|
-
* facing a hung backend.
|
|
8
|
-
*/
|
|
9
|
-
const REQUEST_TIMEOUT_MS = 10_000;
|
|
10
|
-
/**
|
|
11
|
-
* Shared OpenAI-completions request path used by both {@link LocalProvider}
|
|
12
|
-
* and {@link OpenAICompatProvider}. Builds the pi-ai model record, sends one
|
|
13
|
-
* `complete()` call with the user's abort signal, and returns a sanitized
|
|
14
|
-
* completion string (or null when the call aborts/errors/produces nothing
|
|
15
|
-
* usable).
|
|
16
|
-
*
|
|
17
|
-
* Kept as a free function rather than a base class to avoid one-method
|
|
18
|
-
* inheritance.
|
|
19
|
-
*/
|
|
20
|
-
export async function runOpenAICompletion(req, opts) {
|
|
21
|
-
const model = {
|
|
22
|
-
id: opts.modelId,
|
|
23
|
-
name: opts.modelId,
|
|
24
|
-
api: "openai-completions",
|
|
25
|
-
provider: opts.providerTag,
|
|
26
|
-
baseUrl: trimSlash(opts.baseUrl),
|
|
27
|
-
reasoning: false,
|
|
28
|
-
input: ["text"],
|
|
29
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
30
|
-
contextWindow: opts.contextWindow,
|
|
31
|
-
maxTokens: opts.maxTokens,
|
|
32
|
-
};
|
|
33
|
-
const { systemPrompt, user } = buildPromptMessages(req, opts.maxRecentMessages);
|
|
34
|
-
const messages = [{ role: "user", content: user, timestamp: Date.now() }];
|
|
35
|
-
const ctx = { systemPrompt, messages };
|
|
36
|
-
// Combine the caller's abort with an absolute timeout (SEC-3).
|
|
37
|
-
const localCtrl = new AbortController();
|
|
38
|
-
const onUserAbort = () => localCtrl.abort();
|
|
39
|
-
if (req.signal.aborted)
|
|
40
|
-
localCtrl.abort();
|
|
41
|
-
else
|
|
42
|
-
req.signal.addEventListener("abort", onUserAbort, { once: true });
|
|
43
|
-
const timeoutHandle = setTimeout(() => localCtrl.abort(), REQUEST_TIMEOUT_MS);
|
|
44
|
-
try {
|
|
45
|
-
const result = await complete(model, ctx, {
|
|
46
|
-
signal: localCtrl.signal,
|
|
47
|
-
temperature: opts.temperature,
|
|
48
|
-
maxTokens: opts.maxTokens,
|
|
49
|
-
apiKey: opts.apiKey,
|
|
50
|
-
});
|
|
51
|
-
if (result.stopReason === "error" || result.stopReason === "aborted")
|
|
52
|
-
return null;
|
|
53
|
-
const text = result.content
|
|
54
|
-
.filter((c) => c.type === "text")
|
|
55
|
-
.map((c) => c.text)
|
|
56
|
-
.join("");
|
|
57
|
-
return sanitizeCompletion(text, req.editorTextBeforeCursor, 200);
|
|
58
|
-
}
|
|
59
|
-
finally {
|
|
60
|
-
clearTimeout(timeoutHandle);
|
|
61
|
-
req.signal.removeEventListener("abort", onUserAbort);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export function trimSlash(url) {
|
|
65
|
-
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Streaming variant of {@link runOpenAICompletion}. Yields {@link StreamDelta}
|
|
69
|
-
* chunks as pi-ai's `stream()` produces `text_delta` events. Sanitization
|
|
70
|
-
* runs on the running cumulative (not per-delta) — per-delta would clip
|
|
71
|
-
* mid-token and break ghost rendering.
|
|
72
|
-
*
|
|
73
|
-
* Yields nothing on auth/connectivity failure, abort, or when the model
|
|
74
|
-
* record can't be built. The generator's `finally` block clears the
|
|
75
|
-
* SEC-3 timer and detaches the user-abort listener.
|
|
76
|
-
*/
|
|
77
|
-
export async function* runOpenAICompletionStream(req, opts) {
|
|
78
|
-
const model = {
|
|
79
|
-
id: opts.modelId,
|
|
80
|
-
name: opts.modelId,
|
|
81
|
-
api: "openai-completions",
|
|
82
|
-
provider: opts.providerTag,
|
|
83
|
-
baseUrl: trimSlash(opts.baseUrl),
|
|
84
|
-
reasoning: false,
|
|
85
|
-
input: ["text"],
|
|
86
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
87
|
-
contextWindow: opts.contextWindow,
|
|
88
|
-
maxTokens: opts.maxTokens,
|
|
89
|
-
};
|
|
90
|
-
const { systemPrompt, user } = buildPromptMessages(req, opts.maxRecentMessages);
|
|
91
|
-
const messages = [{ role: "user", content: user, timestamp: Date.now() }];
|
|
92
|
-
const ctx = { systemPrompt, messages };
|
|
93
|
-
const localCtrl = new AbortController();
|
|
94
|
-
const onUserAbort = () => localCtrl.abort();
|
|
95
|
-
if (req.signal.aborted)
|
|
96
|
-
localCtrl.abort();
|
|
97
|
-
else
|
|
98
|
-
req.signal.addEventListener("abort", onUserAbort, { once: true });
|
|
99
|
-
const timeoutHandle = setTimeout(() => localCtrl.abort(), REQUEST_TIMEOUT_MS);
|
|
100
|
-
try {
|
|
101
|
-
const events = stream(model, ctx, {
|
|
102
|
-
signal: localCtrl.signal,
|
|
103
|
-
temperature: opts.temperature,
|
|
104
|
-
maxTokens: opts.maxTokens,
|
|
105
|
-
apiKey: opts.apiKey,
|
|
106
|
-
});
|
|
107
|
-
yield* streamWithSanitize(events, req.editorTextBeforeCursor);
|
|
108
|
-
}
|
|
109
|
-
finally {
|
|
110
|
-
clearTimeout(timeoutHandle);
|
|
111
|
-
req.signal.removeEventListener("abort", onUserAbort);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Iterate a pi-ai `AssistantMessageEventStream`, filtering for non-empty
|
|
116
|
-
* `text_delta` events and emitting them through `sanitizeCompletion` as
|
|
117
|
-
* `StreamDelta` chunks. Sanitization runs on the running cumulative
|
|
118
|
-
* (NOT per-delta) since per-token clipping would break ghost rendering.
|
|
119
|
-
*
|
|
120
|
-
* Shared by `runOpenAICompletionStream` (Local) and CloudProvider's
|
|
121
|
-
* `predictStream` so the two paths can't drift on filter/sanitize
|
|
122
|
-
* semantics.
|
|
123
|
-
*/
|
|
124
|
-
export async function* streamWithSanitize(events, prefix) {
|
|
125
|
-
let raw = "";
|
|
126
|
-
let firstEmitted = false;
|
|
127
|
-
for await (const ev of events) {
|
|
128
|
-
if (ev.type !== "text_delta")
|
|
129
|
-
continue;
|
|
130
|
-
if (!ev.delta)
|
|
131
|
-
continue;
|
|
132
|
-
raw += ev.delta;
|
|
133
|
-
const sanitized = sanitizeCompletion(raw, prefix, 200);
|
|
134
|
-
if (!sanitized)
|
|
135
|
-
continue;
|
|
136
|
-
const firstChunk = !firstEmitted;
|
|
137
|
-
firstEmitted = true;
|
|
138
|
-
yield { delta: ev.delta, cumulative: sanitized, firstChunk };
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
//# sourceMappingURL=openai-completions-runner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai-completions-runner.js","sourceRoot":"","sources":["../../src/providers/openai-completions-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,MAAM,GAMN,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGxE;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAkBlC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,GAAiB,EACjB,IAA+B;IAE/B,MAAM,KAAK,GAAgC;QAC1C,EAAE,EAAE,IAAI,CAAC,OAAO;QAChB,IAAI,EAAE,IAAI,CAAC,OAAO;QAClB,GAAG,EAAE,oBAAoB;QACzB,QAAQ,EAAE,IAAI,CAAC,WAA4B;QAC3C,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;QAChC,SAAS,EAAE,KAAK;QAChB,KAAK,EAAE,CAAC,MAAM,CAAC;QACf,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;QAC1D,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,SAAS,EAAE,IAAI,CAAC,SAAS;KACzB,CAAC;IAEF,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,mBAAmB,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAChF,MAAM,QAAQ,GAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACrF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