-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: surface GLM-backed Codex and Claude runtimes #1823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Marve10s
wants to merge
7
commits into
pingdotgg:main
Choose a base branch
from
Marve10s:feat/glm-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
676bfb1
feat: add GLM (Z.ai) as a third provider
Marve10s aaeaf5b
fix: address review comments on GlmAdapter
Marve10s 7cf4cc3
feat: surface GLM-backed Codex and Claude runtimes
Marve10s 157756a
fix: derive GLM models from user config
Marve10s bfd92f3
Merge branch 'main' into feat/glm-provider
Marve10s 379408e
Merge upstream/main into GLM provider branch
Marve10s e20c106
Preserve GLM display name in Codex error state
Marve10s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import type { | ||
| ApprovalRequestId, | ||
| ProviderApprovalDecision, | ||
| ProviderRuntimeEvent, | ||
| ProviderSendTurnInput, | ||
| ProviderSession, | ||
| ProviderSessionStartInput, | ||
| ProviderTurnStartResult, | ||
| ProviderUserInputAnswers, | ||
| ThreadId, | ||
| TurnId, | ||
| } from "@t3tools/contracts"; | ||
| import { Effect, Layer, Queue, Stream } from "effect"; | ||
|
|
||
| import type { ProviderAdapterError } from "../Errors.ts"; | ||
| import { GlmAdapter, type GlmAdapterShape } from "../Services/GlmAdapter.ts"; | ||
| import { CodexAdapter } from "../Services/CodexAdapter.ts"; | ||
| import type { | ||
| ProviderAdapterCapabilities, | ||
| ProviderThreadSnapshot, | ||
| } from "../Services/ProviderAdapter.ts"; | ||
| import type { EventNdjsonLogger } from "./EventNdjsonLogger.ts"; | ||
|
|
||
| const PROVIDER = "glm" as const; | ||
|
|
||
| export interface GlmAdapterLiveOptions { | ||
| readonly nativeEventLogger?: EventNdjsonLogger; | ||
| } | ||
|
|
||
| function remapSessionProvider(session: ProviderSession): ProviderSession { | ||
| return { ...session, provider: PROVIDER }; | ||
| } | ||
|
|
||
| export const GlmAdapterLive = Layer.effect( | ||
| GlmAdapter, | ||
| Effect.gen(function* () { | ||
| const codexAdapter = yield* CodexAdapter; | ||
| const glmEventQueue = yield* Queue.unbounded<ProviderRuntimeEvent>(); | ||
| const glmThreadIds = new Set<ThreadId>(); | ||
|
|
||
| const capabilities: ProviderAdapterCapabilities = { | ||
| sessionModelSwitch: "restart-session", | ||
| }; | ||
|
|
||
| const startSession = ( | ||
| input: ProviderSessionStartInput, | ||
| ): Effect.Effect<ProviderSession, ProviderAdapterError> => | ||
| Effect.gen(function* () { | ||
| glmThreadIds.add(input.threadId); | ||
| const session = yield* codexAdapter.startSession({ | ||
| ...input, | ||
| provider: "codex", | ||
| }); | ||
| return remapSessionProvider(session); | ||
| }); | ||
|
|
||
| const sendTurn = ( | ||
| input: ProviderSendTurnInput, | ||
| ): Effect.Effect<ProviderTurnStartResult, ProviderAdapterError> => codexAdapter.sendTurn(input); | ||
|
|
||
| const interruptTurn = ( | ||
| threadId: ThreadId, | ||
| turnId?: TurnId, | ||
| ): Effect.Effect<void, ProviderAdapterError> => codexAdapter.interruptTurn(threadId, turnId); | ||
|
|
||
| const respondToRequest = ( | ||
| threadId: ThreadId, | ||
| requestId: ApprovalRequestId, | ||
| decision: ProviderApprovalDecision, | ||
| ): Effect.Effect<void, ProviderAdapterError> => | ||
| codexAdapter.respondToRequest(threadId, requestId, decision); | ||
|
|
||
| const respondToUserInput = ( | ||
| threadId: ThreadId, | ||
| requestId: ApprovalRequestId, | ||
| answers: ProviderUserInputAnswers, | ||
| ): Effect.Effect<void, ProviderAdapterError> => | ||
| codexAdapter.respondToUserInput(threadId, requestId, answers); | ||
|
|
||
| const stopSession = (threadId: ThreadId): Effect.Effect<void, ProviderAdapterError> => | ||
| Effect.gen(function* () { | ||
| yield* codexAdapter.stopSession(threadId); | ||
| glmThreadIds.delete(threadId); | ||
| }); | ||
|
|
||
| const listSessions = (): Effect.Effect<ReadonlyArray<ProviderSession>> => | ||
| codexAdapter | ||
| .listSessions() | ||
| .pipe( | ||
| Effect.map((sessions) => | ||
| sessions.filter((s) => glmThreadIds.has(s.threadId)).map(remapSessionProvider), | ||
| ), | ||
| ); | ||
|
|
||
| const hasSession = (threadId: ThreadId): Effect.Effect<boolean> => | ||
| glmThreadIds.has(threadId) ? codexAdapter.hasSession(threadId) : Effect.succeed(false); | ||
|
|
||
| const readThread = ( | ||
| threadId: ThreadId, | ||
| ): Effect.Effect<ProviderThreadSnapshot, ProviderAdapterError> => | ||
| codexAdapter.readThread(threadId); | ||
|
|
||
| const rollbackThread = ( | ||
| threadId: ThreadId, | ||
| numTurns: number, | ||
| ): Effect.Effect<ProviderThreadSnapshot, ProviderAdapterError> => | ||
| codexAdapter.rollbackThread(threadId, numTurns); | ||
|
|
||
| const stopAll = (): Effect.Effect<void, ProviderAdapterError> => | ||
| Effect.gen(function* () { | ||
| for (const threadId of glmThreadIds) { | ||
| yield* codexAdapter.stopSession(threadId).pipe(Effect.ignore); | ||
| } | ||
| glmThreadIds.clear(); | ||
| }); | ||
|
|
||
| return { | ||
| provider: PROVIDER, | ||
| capabilities, | ||
| startSession, | ||
| sendTurn, | ||
| interruptTurn, | ||
| respondToRequest, | ||
| respondToUserInput, | ||
| stopSession, | ||
| listSessions, | ||
| hasSession, | ||
| readThread, | ||
| rollbackThread, | ||
| stopAll, | ||
| get streamEvents() { | ||
| return Stream.fromQueue(glmEventQueue); | ||
| }, | ||
| } satisfies GlmAdapterShape; | ||
| }), | ||
| ); | ||
|
|
||
| export function makeGlmAdapterLive(_options?: GlmAdapterLiveOptions) { | ||
| return GlmAdapterLive; | ||
| } | ||
|
macroscopeapp[bot] marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import type { GlmSettings, ModelCapabilities, ServerProviderModel } from "@t3tools/contracts"; | ||
| import { Effect, Equal, Layer, Stream } from "effect"; | ||
|
|
||
| import { | ||
| buildServerProvider, | ||
| providerModelsFromSettings, | ||
| type ProviderProbeResult, | ||
| } from "../providerSnapshot.ts"; | ||
| import { makeManagedServerProvider } from "../makeManagedServerProvider.ts"; | ||
| import { GlmProvider } from "../Services/GlmProvider.ts"; | ||
| import { ServerSettingsService } from "../../serverSettings.ts"; | ||
|
|
||
| const PROVIDER = "glm" as const; | ||
|
|
||
| const DEFAULT_GLM_MODEL_CAPABILITIES: ModelCapabilities = { | ||
| reasoningEffortLevels: [], | ||
| supportsFastMode: false, | ||
| supportsThinkingToggle: false, | ||
| contextWindowOptions: [], | ||
| promptInjectedEffortLevels: [], | ||
| }; | ||
|
|
||
| const BUILT_IN_MODELS: ReadonlyArray<ServerProviderModel> = [ | ||
| { | ||
| slug: "glm-5.1", | ||
| name: "GLM 5.1", | ||
| isCustom: false, | ||
| capabilities: DEFAULT_GLM_MODEL_CAPABILITIES, | ||
| }, | ||
| { | ||
| slug: "glm-5", | ||
| name: "GLM 5", | ||
| isCustom: false, | ||
| capabilities: DEFAULT_GLM_MODEL_CAPABILITIES, | ||
| }, | ||
| { | ||
| slug: "glm-5-turbo", | ||
| name: "GLM 5 Turbo", | ||
| isCustom: false, | ||
| capabilities: DEFAULT_GLM_MODEL_CAPABILITIES, | ||
| }, | ||
| { | ||
| slug: "glm-4.7", | ||
| name: "GLM 4.7", | ||
| isCustom: false, | ||
| capabilities: DEFAULT_GLM_MODEL_CAPABILITIES, | ||
| }, | ||
| { | ||
| slug: "glm-4.6", | ||
| name: "GLM 4.6", | ||
| isCustom: false, | ||
| capabilities: DEFAULT_GLM_MODEL_CAPABILITIES, | ||
| }, | ||
| { | ||
| slug: "glm-4.5", | ||
| name: "GLM 4.5", | ||
| isCustom: false, | ||
| capabilities: DEFAULT_GLM_MODEL_CAPABILITIES, | ||
| }, | ||
| { | ||
| slug: "glm-4.5-air", | ||
| name: "GLM 4.5 Air", | ||
| isCustom: false, | ||
| capabilities: DEFAULT_GLM_MODEL_CAPABILITIES, | ||
| }, | ||
| ]; | ||
|
|
||
| function checkGlmProviderStatus(_glmSettings: GlmSettings): ProviderProbeResult { | ||
| const hasApiKey = Boolean(process.env.GLM_API_KEY); | ||
|
|
||
| if (!hasApiKey) { | ||
| return { | ||
| installed: true, | ||
| version: null, | ||
| status: "error", | ||
| auth: { status: "unauthenticated" }, | ||
| message: "Set the GLM_API_KEY environment variable to authenticate.", | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| installed: true, | ||
| version: null, | ||
| status: "ready", | ||
| auth: { status: "authenticated", type: "apiKey" }, | ||
| }; | ||
| } | ||
|
|
||
| export const GlmProviderLive = Layer.effect( | ||
| GlmProvider, | ||
| Effect.gen(function* () { | ||
| const serverSettings = yield* ServerSettingsService; | ||
|
|
||
| const checkProvider = Effect.gen(function* () { | ||
| const settings = yield* serverSettings.getSettings; | ||
| const glmSettings = settings.providers.glm; | ||
| const probe = checkGlmProviderStatus(glmSettings); | ||
|
|
||
| const models = providerModelsFromSettings( | ||
| BUILT_IN_MODELS, | ||
| PROVIDER, | ||
| glmSettings.customModels, | ||
| DEFAULT_GLM_MODEL_CAPABILITIES, | ||
| ); | ||
|
|
||
| return buildServerProvider({ | ||
| provider: PROVIDER, | ||
| enabled: glmSettings.enabled, | ||
| checkedAt: new Date().toISOString(), | ||
| models, | ||
| probe, | ||
| }); | ||
| }); | ||
|
|
||
| return yield* makeManagedServerProvider<GlmSettings>({ | ||
| getSettings: serverSettings.getSettings.pipe( | ||
| Effect.map((settings) => settings.providers.glm), | ||
| Effect.orDie, | ||
| ), | ||
| streamSettings: serverSettings.streamChanges.pipe( | ||
| Stream.map((settings) => settings.providers.glm), | ||
| ), | ||
| haveSettingsChanged: (previous, next) => !Equal.equals(previous, next), | ||
| checkProvider, | ||
| }); | ||
| }), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.