GeezerVison is showing github.com — Expose reasoning effort for custom Claude models by IsraelAraujo70 · Pull Request #4194 · pingdotgg/t3code
Expose reasoning effort for custom Claude models
#4194
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.ts
(6)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
fix: alinhar validacao runtime as capabilities dinamicas
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit b7cff3567a0de386c2ddcb4d31cd9d36f8d83ab0
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -30,6 +30,7 @@ import { ProviderDriverError } from "../Errors.ts";
import { makeClaudeAdapter } from "../Layers/ClaudeAdapter.ts";
import {
checkClaudeProviderStatus,
getClaudeModelCapabilities,
makePendingClaudeProvider,
probeClaudeCapabilities,
} from "../Layers/ClaudeProvider.ts";
Expand Down
Expand Up
@@ -141,14 +142,6 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv> = {
continuationGroupKey,
});
const adapterOptions = {
instanceId,
environment: processEnv,
...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),
};
const adapter = yield* makeClaudeAdapter(effectiveConfig, adapterOptions);
const textGeneration = yield* makeClaudeTextGeneration(effectiveConfig, processEnv);
// Per-instance capabilities cache: keyed on binary + resolved HOME so
// account-specific probes never share auth metadata across instances.
const capabilitiesProbeCache = yield* Cache.make({
Expand All
@@ -160,6 +153,23 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv> = {
),
});
const capabilitiesCacheKey = yield* makeClaudeCapabilitiesCacheKey(effectiveConfig, cwd);
const resolveModelCapabilities = (model: string | null | undefined) =>
Cache.get(capabilitiesProbeCache, capabilitiesCacheKey).pipe(
Effect.map((capabilities) => getClaudeModelCapabilities(model, capabilities?.models)),
);
const adapterOptions = {
instanceId,
environment: processEnv,
resolveModelCapabilities,
...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),
};
const adapter = yield* makeClaudeAdapter(effectiveConfig, adapterOptions);
const textGeneration = yield* makeClaudeTextGeneration(
effectiveConfig,
processEnv,
resolveModelCapabilities,
);
const checkProvider = checkClaudeProviderStatus(
effectiveConfig,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,14 +14,15 @@ import type {
import {
ApprovalRequestId,
ClaudeSettings,
type ModelCapabilities,
ProviderDriverKind,
ProviderItemId,
ProviderRuntimeEvent,
type RuntimeMode,
ThreadId,
ProviderInstanceId,
} from "@t3tools/contracts";
import { createModelSelection } from "@t3tools/shared/model";
import { createModelCapabilities, createModelSelection } from "@t3tools/shared/model";
import { assert, describe, it } from "@effect/vitest";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
Expand Down
Expand Up
@@ -156,6 +157,7 @@ function makeHarness(config?: {
readonly baseDir?: string;
readonly claudeConfig?: Partial<ClaudeSettings>;
readonly instanceId?: ProviderInstanceId;
readonly resolveModelCapabilities?: ClaudeAdapterLiveOptions["resolveModelCapabilities"];
}) {
const query = new FakeClaudeQuery();
let createInput:
Expand All
@@ -171,6 +173,9 @@ function makeHarness(config?: {
createInput = input;
return query;
},
...(config?.resolveModelCapabilities
? { resolveModelCapabilities: config.resolveModelCapabilities }
: {}),
...(config?.nativeEventLogger
? {
nativeEventLogger: config.nativeEventLogger,
Expand Down
Expand Up
@@ -205,6 +210,19 @@ function makeHarness(config?: {
};
}
function customEffortCapabilities(...efforts: ReadonlyArray<string>): ModelCapabilities {
return createModelCapabilities({
optionDescriptors: [
{
id: "effort",
label: "Reasoning",
type: "select",
options: efforts.map((effort) => ({ id: effort, label: effort })),
},
],
});
}
function makeDeterministicRandomService(seed = 0x1234_5678): {
nextIntUnsafe: () => number;
nextDoubleUnsafe: () => number;
Expand Down
Expand Up
@@ -439,7 +457,9 @@ describe("ClaudeAdapterLive", () => {
});
it.effect("preserves xhigh effort for custom Claude models", () => {
const harness = makeHarness();
const harness = makeHarness({
resolveModelCapabilities: () => Effect.succeed(customEffortCapabilities("xhigh")),
});
return Effect.gen(function* () {
const adapter = yield* ClaudeAdapter;
yield* adapter.startSession({
Expand All
@@ -461,6 +481,31 @@ describe("ClaudeAdapterLive", () => {
);
});
it.effect("ignores custom Claude effort levels not advertised by the SDK", () => {
const harness = makeHarness({
resolveModelCapabilities: () => Effect.succeed(customEffortCapabilities("low")),
});
return Effect.gen(function* () {
const adapter = yield* ClaudeAdapter;
yield* adapter.startSession({
threadId: THREAD_ID,
provider: ProviderDriverKind.make("claudeAgent"),
modelSelection: createModelSelection(
ProviderInstanceId.make("claudeAgent"),
"gpt-5.6-sol",
[{ id: "effort", value: "xhigh" }],
),
runtimeMode: "full-access",
});
const createInput = harness.getLastCreateQueryInput();
assert.equal(createInput?.options.effort, undefined);
}).pipe(
Effect.provideService(Random.Random, makeDeterministicRandomService()),
Effect.provide(harness.layer),
);
});
it.effect("runs Claude SDK sessions with the configured CLAUDE_CONFIG_DIR", () => {
const harness = makeHarness({ claudeConfig: { homePath: "~/.claude-work" } });
return Effect.gen(function* () {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -27,6 +27,7 @@ import {
type CanonicalRequestType,
type ClaudeSettings,
EventId,
type ModelCapabilities,
type ProviderApprovalDecision,
ProviderDriverKind,
ProviderInstanceId,
Expand Down
Expand Up
@@ -221,6 +222,9 @@ export interface ClaudeAdapterLiveOptions {
}) => ClaudeQueryRuntime;
readonly nativeEventLogPath?: string;
readonly nativeEventLogger?: EventNdjsonLogger;
readonly resolveModelCapabilities?: (
model: string | null | undefined,
) => Effect.Effect<ModelCapabilities>;
}
function isUuid(value: string): boolean {
Expand Down
Expand Up
@@ -1359,6 +1363,9 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
stream: "native",
})
: undefined);
const resolveModelCapabilities =
options?.resolveModelCapabilities ??
((model: string | null | undefined) => Effect.succeed(getClaudeModelCapabilities(model)));
const createQuery =
options?.createQuery ??
Expand Down
Expand Up
@@ -3414,7 +3421,7 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
const extraArgs = parseCliArgs(claudeSettings.launchArgs).flags;
const modelSelection =
input.modelSelection?.instanceId === boundInstanceId ? input.modelSelection : undefined;
const caps = getClaudeModelCapabilities (modelSelection?.model);
const caps = yield* resolveModelCapabilities (modelSelection?.model);
const descriptors = getProviderOptionDescriptors({ caps });
const apiModelId = modelSelection ? resolveClaudeApiModelId(modelSelection) : undefined;
const initialContextWindow = selectedClaudeContextWindow(modelSelection);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -44,22 +44,6 @@ const EMPTY_CLAUDE_MODEL_CAPABILITIES: ModelCapabilities = createModelCapabiliti
optionDescriptors: [],
});
const CUSTOM_CLAUDE_MODEL_CAPABILITIES: ModelCapabilities = createModelCapabilities({
optionDescriptors: [
buildSelectOptionDescriptor({
id: "effort",
label: "Reasoning",
options: [
{ value: "low", label: "Low" },
{ value: "medium", label: "Medium" },
{ value: "high", label: "High" },
{ value: "xhigh", label: "Extra High" },
{ value: "max", label: "Max" },
],
}),
],
});
const CLAUDE_PRESENTATION = {
displayName: "Claude",
showInteractionModeToggle: true,
Expand Down
Expand Up
@@ -399,14 +383,17 @@ function formatClaudeOpus47UpgradeMessage(version: string | null): string {
return `Claude Code ${versionLabel} is too old for Claude Opus 4.7. Upgrade to v${MINIMUM_CLAUDE_OPUS_4_7_VERSION} or newer to access it.`;
}
export function getClaudeModelCapabilities(model: string | null | undefined): ModelCapabilities {
export function getClaudeModelCapabilities(
model: string | null | undefined,
availableModels: ReadonlyArray<ClaudeModelInfo> = [],
): ModelCapabilities {
const slug = model?.trim();
if (!slug) {
return EMPTY_CLAUDE_MODEL_CAPABILITIES;
}
return (
BUILT_IN_MODELS.find((candidate) => candidate.slug === slug)?.capabilities ??
CUSTOM_CLAUDE_MODEL_CAPABILITIES
customClaudeModelCapabilities(indexClaudeModels(availableModels).get(slug))
);
}
Expand Down
Expand Up
@@ -731,12 +718,14 @@ const probeClaudeCapabilities = (
const customModels = [
...new Set(claudeSettings.customModels.map((model) => model.trim())),
].filter((model) => model.length > 0);
const results = await Promise.allSettled(
(customModels.length > 0 ? customModels : [undefined]).map((model) => initialize(model)),
);
const initializations = results.flatMap((result) =>
result.status === "fulfilled" ? [result.value] : [],
);
const initializations = [];
for (const model of customModels.length > 0 ? customModels : [undefined]) {
Comment thread
IsraelAraujo70 marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
try {
initializations.push(await initialize(model));
} catch {
// One invalid custom model must not prevent the remaining probes.
}
}
Comment thread
IsraelAraujo70 marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
if (initializations.length === 0 && customModels.length > 0) {
initializations.push(await initialize());
}
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
import { ClaudeSettings, ProviderInstanceId } from "@t3tools/contracts";
import { ClaudeSettings, type ModelCapabilities, ProviderInstanceId } from "@t3tools/contracts";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import * as Schema from "effect/Schema";
import { createModelSelection } from "@t3tools/shared/model";
import { createModelCapabilities, createModelSelection } from "@t3tools/shared/model";
import { expect } from "vite-plus/test";
import * as ServerConfig from "../config.ts";
Expand Down
Expand Up
@@ -78,6 +78,7 @@ function withFakeClaudeEnv<A, E, R>(
stdinMustContain?: string;
configDirMustBe?: string;
claudeConfig?: Partial<ClaudeSettings>;
modelCapabilities?: ModelCapabilities;
},
effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,
) {
Expand Down
Expand Up
@@ -184,7 +185,12 @@ function withFakeClaudeEnv<A, E, R>(
);
const config = decodeClaudeSettings(input.claudeConfig ?? {});
const textGeneration = yield* makeClaudeTextGeneration(config);
const modelCapabilities = input.modelCapabilities;
const textGeneration = yield* makeClaudeTextGeneration(
config,
undefined,
modelCapabilities ? () => Effect.succeed(modelCapabilities) : undefined,
);
return yield* effectFn(textGeneration);
}).pipe(Effect.scoped);
}
Expand Down
Expand Up
@@ -264,6 +270,16 @@ it.layer(ClaudeTextGenerationTestLayer)("ClaudeTextGeneration", (it) => {
},
}),
argsMustContain: "--model gpt-5.6-sol --effort xhigh",
modelCapabilities: createModelCapabilities({
optionDescriptors: [
{
id: "effort",
label: "Reasoning",
type: "select",
options: [{ id: "xhigh", label: "Extra High" }],
},
],
}),
},
(textGeneration) =>
Effect.gen(function* () {
Expand All
@@ -282,6 +298,44 @@ it.layer(ClaudeTextGenerationTestLayer)("ClaudeTextGeneration", (it) => {
),
);
it.effect("ignores custom Claude effort levels not advertised by the SDK", () =>
withFakeClaudeEnv(
{
output: JSON.stringify({
structured_output: {
title: "Use advertised custom reasoning",
},
}),
argsMustContain: "--model gpt-5.6-sol",
argsMustNotContain: "--effort",
modelCapabilities: createModelCapabilities({
optionDescriptors: [
{
id: "effort",
label: "Reasoning",
type: "select",
options: [{ id: "low", label: "Low" }],
},
],
}),
},
(textGeneration) =>
Effect.gen(function* () {
const generated = yield* textGeneration.generateThreadTitle({
cwd: process.cwd(),
message: "Name this thread.",
modelSelection: createModelSelection(
ProviderInstanceId.make("claudeAgent"),
"gpt-5.6-sol",
[{ id: "effort", value: "xhigh" }],
),
});
expect(generated.title).toBe("Use advertised custom reasoning");
}),
),
);
it.effect("does not default effort for custom Claude models", () =>
withFakeClaudeEnv(
{
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -13,7 +13,11 @@ import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
import { type ClaudeSettings, type ModelSelection } from "@t3tools/contracts";
import {
type ClaudeSettings,
type ModelCapabilities,
type ModelSelection,
} from "@t3tools/contracts";
import { sanitizeBranchFragment, sanitizeFeatureBranchName } from "@t3tools/shared/git";
import { resolveSpawnCommand } from "@t3tools/shared/shell";
Expand Down
Expand Up
@@ -61,6 +65,10 @@ const decodeClaudeOutputEnvelope = Schema.decodeEffect(Schema.fromJsonString(Cla
export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(function* (
claudeSettings: ClaudeSettings,
environment?: NodeJS.ProcessEnv,
resolveModelCapabilities: (
model: string | null | undefined,
) => Effect.Effect<ModelCapabilities> = (model) =>
Effect.succeed(getClaudeModelCapabilities(model)),
) {
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const claudeEnvironment = yield* makeClaudeEnvironment(claudeSettings, environment);
Expand Down
Expand Up
@@ -126,7 +134,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
toJsonSchemaObject(outputSchemaJson),
"Failed to encode structured output schema.",
);
const caps = getClaudeModelCapabilities (modelSelection.model);
const caps = yield* resolveModelCapabilities (modelSelection.model);
const descriptors = getProviderOptionDescriptors({
caps,
selections: modelSelection.options,
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.