Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/agent/AgentDependencyComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ export function configureMobileRelayController(
host.cancelCurrentInstruction?.();
}
});
relay.setModelChangeHandler((provider, model) =>
host.providerConfigManager.applyModelChangeRemote(provider, model));
relay.setModelChangeHandler((provider, model, options) => options
? host.providerConfigManager.applyModelChangeRemote(provider, model, options)
: host.providerConfigManager.applyModelChangeRemote(provider, model));
}

const MOBILE_PERMISSION_SAFETY_RANK: Record<MobilePermissionMode, number> = {
Expand Down
24 changes: 24 additions & 0 deletions src/core/agent/ProviderConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,7 @@ export class ProviderConfigManager {
async applyModelChangeRemote(
provider: string,
model: string,
options: { reasoningEffort?: string } = {},
): Promise<{ provider: string; model: string; status: "applied" | "failed"; error?: string }> {
if (!ProviderFactory.isValidProvider(provider, this.runtime.config)) {
return { provider, model, status: "failed", error: `Unknown provider: ${provider}` };
Expand All @@ -4031,6 +4032,7 @@ export class ProviderConfigManager {
try {
const currentModel = this.runtime.options.model ?? "";
await this.applyModelChange(provider, sanitized, currentModel);
if (provider === "autohandai") await this.applyAutohandAIReasoningEffortRemote(sanitized, options.reasoningEffort);
return { provider, model: this.runtime.options.model ?? sanitized, status: "applied" };
} catch (error) {
return {
Expand All @@ -4042,6 +4044,28 @@ export class ProviderConfigManager {
}
}

/**
* The phone's effort for an Autohand AI model (Moa: medium, high, xhigh), applied the way the
* interactive picker stores it. A model without effort levels drops any stored effort; an effort
* the model does not offer is ignored. Effort-only changes apply even when the model is unchanged.
*/
private async applyAutohandAIReasoningEffortRemote(model: string, effort: string | undefined): Promise<void> {
const settings = this.runtime.config.autohandai;
if (!settings) return;
const levels = getProviderModelOptions("autohandai").find((entry) => entry.id === model)?.reasoningEfforts ?? [];
const next = effort && (levels as readonly string[]).includes(effort) ? (effort as ReasoningEffort) : undefined;
if (!levels.length) {
if (settings.reasoningEffort === undefined) return;
delete settings.reasoningEffort;
} else if (!next || next === settings.reasoningEffort) {
return;
} else {
settings.reasoningEffort = next;
}
await saveConfig(this.runtime.config);
this.resetLlmClient("autohandai", model);
}

/**
* Apply a model change and update all relevant state
*/
Expand Down
8 changes: 6 additions & 2 deletions src/mobile/MobileRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ export interface MobileRelayController {

export type MobileModelChangeHandler = (
provider: string,
model: string
model: string,
options?: { reasoningEffort?: string }
) => Promise<MobileModelStatus>;

const MAX_MOBILE_IMAGE_BASE64_LENGTH = 5_000_000;
Expand Down Expand Up @@ -1607,7 +1608,10 @@ async function resolveAction(

let result: MobileModelStatus;
try {
result = await relay.modelChangeHandler(provider, model);
const reasoningEffort = action.payload.reasoningEffort;
result = typeof reasoningEffort === 'string'
? await relay.modelChangeHandler(provider, model, { reasoningEffort })
: await relay.modelChangeHandler(provider, model);
} catch (error) {
result = {
provider,
Expand Down
22 changes: 22 additions & 0 deletions tests/core/agent/ProviderConfigManager.remoteModelChange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ describe('ProviderConfigManager.applyModelChangeRemote', () => {
expect(setActiveProvider).toHaveBeenCalledWith('openrouter');
});

it('applies the phone\'s Moa reasoning effort and drops it for Fantail', async () => {
runtime.config.provider = 'autohandai';
runtime.config.autohandai = { plan: 'cloud', authMode: 'account', accountToken: 'tok', model: 'fantail' };
runtime.options.model = 'fantail';

expect((await manager.applyModelChangeRemote('autohandai', 'moa', { reasoningEffort: 'xhigh' })).status).toBe('applied');
expect(runtime.config.autohandai.model).toBe('moa');
expect(runtime.config.autohandai.reasoningEffort).toBe('xhigh');

// Effort only, same model.
await manager.applyModelChangeRemote('autohandai', 'moa', { reasoningEffort: 'medium' });
expect(runtime.config.autohandai.reasoningEffort).toBe('medium');

// An effort Moa does not offer is ignored.
await manager.applyModelChangeRemote('autohandai', 'moa', { reasoningEffort: 'none' });
expect(runtime.config.autohandai.reasoningEffort).toBe('medium');

await manager.applyModelChangeRemote('autohandai', 'fantail', { reasoningEffort: 'high' });
expect(runtime.config.autohandai.model).toBe('fantail');
expect(runtime.config.autohandai.reasoningEffort).toBeUndefined();
});

it.each([4096, 262144])('refreshes the llama.cpp server limit to %s without waiting before switching', async (limit) => {
const metadata = Promise.withResolvers<number | undefined>();
const nextProvider: LLMProvider = {
Expand Down
46 changes: 46 additions & 0 deletions tests/mobile/MobileRelay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,52 @@ describe('MobileRelay event bridge', () => {
]));
});

it('passes the phone reasoning effort with set_model', async () => {
const published: PublishMobileEventPayload[] = [];
const modelChangeHandler = vi.fn().mockResolvedValue({
provider: 'autohandai',
model: 'moa',
status: 'applied' as const,
});
const actions: MobileAction[] = [{
id: 'set-model-1',
sequence: 1,
actionType: 'set_model',
requestId: 'request-set-model-1',
payload: { provider: 'autohandai', model: 'moa', reasoningEffort: 'xhigh' },
createdAt: new Date().toISOString(),
}];
const client: MobileHandoffClientLike = {
getDeviceId: vi.fn().mockResolvedValue('device-1'),
registerDevice: vi.fn().mockResolvedValue(undefined),
createPairing: vi.fn(),
sendRelayHeartbeat: vi.fn().mockResolvedValue(undefined),
claimWork: vi.fn().mockResolvedValue(null),
publishMobileEvent: vi.fn().mockImplementation(async (_token, payload) => published.push(payload)),
pollMobileActions: vi.fn().mockResolvedValue({ actions, nextCursor: 1 }),
};

const relay = startMobileRelay({
client,
token: 'token',
deviceId: 'device-1',
sessionId: 'session-1',
pairingId: 'pairing-1',
mode: 'steer',
pollIntervalMs: 1_000,
enqueueInstruction: vi.fn(),
});
relay.setModelChangeHandler(modelChangeHandler);

await vi.waitFor(() => expect(modelChangeHandler).toHaveBeenCalledWith('autohandai', 'moa', { reasoningEffort: 'xhigh' }));
expect(published).toEqual(expect.arrayContaining([
expect.objectContaining({
eventType: 'model_status',
payload: { provider: 'autohandai', model: 'moa', status: 'applied' },
}),
]));
});

it('rejects permission-mode actions until the mobile pairing is claimed', async () => {
const published: PublishMobileEventPayload[] = [];
const applyPermissionMode = vi.fn().mockReturnValue(createPermissionModeChange('unrestricted'));
Expand Down
Loading