feat: add verified desktop ChatGPT subscription connection
This commit is contained in:
+9
-7
@@ -12,6 +12,9 @@ import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
||||
import { type ModelRole } from "../../config.ts";
|
||||
import { DEFAULT_THINKING_ORDER } from "../core/settings.ts";
|
||||
import packageMetadata from "../../package.json" with { type: "json" };
|
||||
import { chatGPTModel } from "./chatgpt-bridge.ts";
|
||||
import { chatGPTStream } from "./chatgpt-stream.ts";
|
||||
import type { ChatGPTDispatchLifecycle } from "./chatgpt-request-cycle.ts";
|
||||
|
||||
/** App identity is immutable and shared by Models and every native Agent.
|
||||
* Agent's default Pi attribution otherwise overrides the Models identity. */
|
||||
@@ -93,9 +96,9 @@ function defaultThinkingLevel(model: Model<Api>): ThinkingLevel {
|
||||
* key is resolved by pi-ai itself from the environment per request (the
|
||||
* keys seam reflects file-saved keys into env), so the engine never
|
||||
* hardcodes OpenRouter's. */
|
||||
export function piEngineForSpec(spec: ResolvedModelSpec): PiEngine {
|
||||
export function piEngineForSpec(spec: ResolvedModelSpec, background: boolean | (() => boolean) = true, lifecycle?: ChatGPTDispatchLifecycle): PiEngine {
|
||||
const models: Models = piModels();
|
||||
const model = models.getModel(spec.provider, spec.id);
|
||||
const model = spec.provider === "chatgpt" ? chatGPTModel(spec.id) : models.getModel(spec.provider, spec.id);
|
||||
if (!model) {
|
||||
throw new Error(`${spec.provider} catalog has no model ${spec.id}`);
|
||||
}
|
||||
@@ -111,11 +114,10 @@ export function piEngineForSpec(spec: ResolvedModelSpec): PiEngine {
|
||||
// bound streamSimple: the agent loop forwards state.thinkingLevel as
|
||||
// `reasoning` (undefined = off on pi-ai's scale); the clamp above keeps
|
||||
// the pin honest even when config or settings drift off the map.
|
||||
streamFn: (requestModel, context, options) =>
|
||||
models.streamSimple(requestModel, context, {
|
||||
...options,
|
||||
reasoning: level === "off" ? undefined : level,
|
||||
}),
|
||||
streamFn: (requestModel, context, options) => {
|
||||
const stream = spec.provider === "chatgpt" ? chatGPTStream(typeof background === "function" ? background : () => background, lifecycle) : models.streamSimple.bind(models);
|
||||
return stream(requestModel, context, { ...options, reasoning: level === "off" ? undefined : level });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user