-
Notifications
You must be signed in to change notification settings - Fork 0
fix(mcp): route t3_thread_start/t3_spawn_subagent by plain model name #6
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,11 @@ import { | |
| type OrchestrationThreadShell, | ||
| } from "@t3tools/contracts"; | ||
| import { buildTemporaryWorktreeBranchName } from "@t3tools/shared/git"; | ||
| import { | ||
| buildProviderOptionSelectionsFromDescriptors, | ||
| pickModelSelectionFromInstances, | ||
| type ProviderModelSource, | ||
| } from "@t3tools/shared/model"; | ||
| import * as Crypto from "effect/Crypto"; | ||
| import * as DateTime from "effect/DateTime"; | ||
| import * as Effect from "effect/Effect"; | ||
|
|
@@ -17,6 +22,7 @@ import * as Schema from "effect/Schema"; | |
| import * as McpInvocationContext from "../../McpInvocationContext.ts"; | ||
| import * as BootstrapTurnStartDispatcher from "../../../orchestration/Services/BootstrapTurnStartDispatcher.ts"; | ||
| import { ProjectionSnapshotQuery } from "../../../orchestration/Services/ProjectionSnapshotQuery.ts"; | ||
| import { ProviderInstanceRegistry } from "../../../provider/Services/ProviderInstanceRegistry.ts"; | ||
| import { GitWorkflowService } from "../../../git/GitWorkflowService.ts"; | ||
| import { | ||
| ThreadStartToolError, | ||
|
|
@@ -63,6 +69,7 @@ export const activeThreadStartRuntimeOf = (): ActiveThreadStartRuntime | null => | |
| const makeActiveThreadStartRuntime = Effect.fn("ThreadToolkit.makeActiveRuntime")(function* () { | ||
| const crypto = yield* Crypto.Crypto; | ||
| const projectionSnapshotQuery = yield* ProjectionSnapshotQuery; | ||
| const providerInstanceRegistry = yield* ProviderInstanceRegistry; | ||
| const gitWorkflow = yield* GitWorkflowService; | ||
| const uuid = () => crypto.randomUUIDv4.pipe(Effect.orDie); | ||
|
|
||
|
|
@@ -179,7 +186,22 @@ const makeActiveThreadStartRuntime = Effect.fn("ThreadToolkit.makeActiveRuntime" | |
| const worktreePath: string | null = | ||
| mode === "existing_worktree" ? (input.worktreePath ?? null) : null; | ||
| const title = input.title ?? truncateTitle(input.prompt); | ||
| const modelSelection = resolveModelSelection(input, sourceThread); | ||
| const providerInstances = yield* providerInstanceRegistry.listInstances; | ||
| const modelSources = yield* Effect.forEach( | ||
| providerInstances.filter((providerInstance) => providerInstance.enabled), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a provider is enabled but currently unavailable, its snapshot can still advertise fallback models (for example Useful? React with 👍 / 👎. |
||
| (providerInstance) => | ||
| Effect.map(providerInstance.snapshot.getSnapshot, (snapshot) => ({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This reads each raw instance snapshot, but the model picker is backed by Useful? React with 👍 / 👎. |
||
| instanceId: providerInstance.instanceId, | ||
| driverKind: providerInstance.driverKind, | ||
| models: snapshot.models.map((providerModel) => ({ | ||
| slug: providerModel.slug, | ||
| defaultOptions: buildProviderOptionSelectionsFromDescriptors( | ||
| providerModel.capabilities?.optionDescriptors, | ||
| ), | ||
| })), | ||
| })), | ||
| ); | ||
| const modelSelection = yield* resolveModelSelection(input, sourceThread, modelSources); | ||
| const runtimeMode = input.runtimeMode ?? sourceThread.runtimeMode; | ||
| const interactionMode = input.interactionMode ?? sourceThread.interactionMode; | ||
| const prepareWorktree = | ||
|
|
@@ -269,7 +291,29 @@ export const ThreadStartRuntimeLive = Layer.effectDiscard( | |
| const resolveModelSelection = ( | ||
| input: ThreadStartToolInput, | ||
| sourceThread: OrchestrationThreadShell, | ||
| ): ModelSelection => input.modelSelection ?? sourceThread.modelSelection; | ||
| modelSources: ReadonlyArray<ProviderModelSource>, | ||
| ): Effect.Effect<ModelSelection, ThreadStartToolError> => { | ||
| // An explicit bare `model` is resolved against the live provider model lists; | ||
| // if the caller named a model no provider serves, fail loudly rather than | ||
| // silently starting the thread on a different (inherited) model. | ||
| if (input.model !== undefined) { | ||
| const resolved = pickModelSelectionFromInstances( | ||
| input.model, | ||
| modelSources, | ||
| sourceThread.modelSelection.instanceId, | ||
| ); | ||
| if (resolved === null) { | ||
| return Effect.fail( | ||
| fail( | ||
| `Model "${input.model}" is not served by any configured provider. Pass a model shown in the model picker, or omit "model" to keep the thread's current model.`, | ||
| ), | ||
| ); | ||
| } | ||
| return Effect.succeed(resolved); | ||
| } | ||
| // Otherwise an explicit modelSelection wins, else inherit the source thread. | ||
| return Effect.succeed(input.modelSelection ?? sourceThread.modelSelection); | ||
| }; | ||
|
|
||
| const startThread = Effect.fn("ThreadToolkit.startThread")(function* (input: ThreadStartToolInput) { | ||
| const invocation = yield* McpInvocationContext.requireMcpCapability("thread-management").pipe( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,3 +206,20 @@ export const PROVIDER_DISPLAY_NAMES: Partial<Record<ProviderDriverKind, string>> | |
| [GROK_DRIVER_KIND]: "Grok", | ||
| [OPENCODE_DRIVER_KIND]: "OpenCode", | ||
| }; | ||
|
|
||
| /** | ||
| * Preference order for inferring a model's official provider/harness from its | ||
| * name (see `inferProviderFromModel`). Native providers come first; aggregator | ||
| * providers that re-list other providers' models (e.g. Cursor exposes Claude | ||
| * models) come last, so a model offered by several providers resolves to its | ||
| * official one — Claude models to `claudeAgent`, not `cursor`. This is an | ||
| * attribute of provider identity, not of model names, so it needs no change | ||
| * when new models ship: those are picked up from the registry maps above. | ||
| */ | ||
| export const PROVIDER_INFERENCE_PRIORITY: ReadonlyArray<ProviderDriverKind> = [ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| CODEX_DRIVER_KIND, | ||
| CLAUDE_DRIVER_KIND, | ||
| GROK_DRIVER_KIND, | ||
| OPENCODE_DRIVER_KIND, | ||
| CURSOR_DRIVER_KIND, | ||
| ]; | ||
Uh oh!
There was an error while loading. Please reload this page.