Skip to content

Commit 0022d08

Browse files
committed
Merge remote-tracking branch 'github/main' into fix/open-in-same-home-service
2 parents e18fb8f + e455200 commit 0022d08

139 files changed

Lines changed: 3824 additions & 1938 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/ipc/DesktopIpcHandlers.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { installNotificationBadge } from "./methods/notificationBadge.ts";
66
import { getClientSettings, setClientSettings } from "./methods/clientSettings.ts";
77
import { getConnectionCatalog, setConnectionCatalog } from "./methods/connectionCatalog.ts";
88
import {
9+
getHostEnvironmentId,
910
getLocalEnvironmentEnabled,
1011
setLocalEnvironmentEnabled,
1112
} from "./methods/localEnvironment.ts";
@@ -101,6 +102,7 @@ export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers"
101102
yield* ipc.handleSync(getLocalEnvironmentBootstraps);
102103
yield* ipc.handleSync(getLocalEnvironmentEnabled);
103104
yield* ipc.handle(setLocalEnvironmentEnabled);
105+
yield* ipc.handle(getHostEnvironmentId);
104106
yield* ipc.handle(getLocalEnvironmentBearerToken);
105107

106108
yield* ipc.handle(getClientSettings);

‎apps/desktop/src/ipc/channels.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const GET_PREFERRED_SYSTEM_LANGUAGES_CHANNEL = "desktop:get-preferred-sys
3939
export const GET_LOCAL_ENVIRONMENT_BOOTSTRAPS_CHANNEL = "desktop:get-local-environment-bootstraps";
4040
export const GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL = "desktop:get-local-environment-enabled";
4141
export const SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL = "desktop:set-local-environment-enabled";
42+
export const GET_HOST_ENVIRONMENT_ID_CHANNEL = "desktop:get-host-environment-id";
4243
export const GET_LOCAL_ENVIRONMENT_BEARER_TOKEN_CHANNEL =
4344
"desktop:get-local-environment-bearer-token";
4445
export const GET_CLIENT_SETTINGS_CHANNEL = "desktop:get-client-settings";

‎apps/desktop/src/ipc/methods/localEnvironment.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { assert, describe, it } from "@effect/vitest";
2+
import * as NodeServices from "@effect/platform-node/NodeServices";
3+
import * as FileSystem from "effect/FileSystem";
4+
import * as Path from "effect/Path";
25
import * as Effect from "effect/Effect";
36
import * as Layer from "effect/Layer";
47

@@ -10,7 +13,11 @@ import * as ElectronApp from "../../electron/ElectronApp.ts";
1013
import * as ElectronTheme from "../../electron/ElectronTheme.ts";
1114
import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
1215
import * as DesktopWindow from "../../window/DesktopWindow.ts";
13-
import { getLocalEnvironmentEnabled, setLocalEnvironmentEnabled } from "./localEnvironment.ts";
16+
import {
17+
getHostEnvironmentId,
18+
getLocalEnvironmentEnabled,
19+
setLocalEnvironmentEnabled,
20+
} from "./localEnvironment.ts";
1421

1522
const layerUnusedLifecycleRuntime = Layer.mergeAll(
1623
DesktopShutdown.layer,
@@ -27,6 +34,26 @@ const layerUnusedLifecycleRuntime = Layer.mergeAll(
2734
);
2835

2936
describe("local environment IPC", () => {
37+
it.effect("reads the shared home identity without creating one", () =>
38+
Effect.gen(function* () {
39+
const fs = yield* FileSystem.FileSystem;
40+
const path = yield* Path.Path;
41+
const stateDir = yield* fs.makeTempDirectoryScoped();
42+
const environment = DesktopEnvironment.DesktopEnvironment.of({
43+
path,
44+
stateDir,
45+
} as DesktopEnvironment.DesktopEnvironment["Service"]);
46+
const read = getHostEnvironmentId
47+
.handler(undefined)
48+
.pipe(Effect.provideService(DesktopEnvironment.DesktopEnvironment, environment));
49+
assert.strictEqual(yield* read, null);
50+
assert.isFalse(yield* fs.exists(path.join(stateDir, "environment-id")));
51+
yield* fs.writeFileString(path.join(stateDir, "environment-id"), " service-id\n");
52+
assert.strictEqual(yield* read, "service-id");
53+
yield* fs.writeFileString(path.join(stateDir, "environment-id"), "\n");
54+
assert.strictEqual(yield* read, null);
55+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
56+
);
3057
it.effect("relaunches only when the setting changes and keeps other settings", () => {
3158
const relaunchReasons: Array<string> = [];
3259
const layer = Layer.mergeAll(

‎apps/desktop/src/ipc/methods/localEnvironment.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as Effect from "effect/Effect";
2+
import * as FileSystem from "effect/FileSystem";
23
import * as Schema from "effect/Schema";
34

5+
import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
46
import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts";
57
import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
68
import * as IpcChannels from "../channels.ts";
@@ -28,3 +30,18 @@ export const setLocalEnvironmentEnabled = makeIpcMethod({
2830
}
2931
}),
3032
});
33+
34+
// A background service sharing this app's T3 home records its environment ID in the same state dir.
35+
export const getHostEnvironmentId = makeIpcMethod({
36+
channel: IpcChannels.GET_HOST_ENVIRONMENT_ID_CHANNEL,
37+
payload: Schema.Void,
38+
result: Schema.NullOr(Schema.String),
39+
handler: Effect.fn("desktop.ipc.localEnvironment.getHostEnvironmentId")(function* () {
40+
const environment = yield* DesktopEnvironment.DesktopEnvironment;
41+
const fileSystem = yield* FileSystem.FileSystem;
42+
const contents = yield* fileSystem
43+
.readFileString(environment.path.join(environment.stateDir, "environment-id"))
44+
.pipe(Effect.orElseSucceed(() => ""));
45+
return contents.trim() || null;
46+
}),
47+
});

‎apps/desktop/src/preload.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ contextBridge.exposeInMainWorld("desktopBridge", {
126126
ipcRenderer.sendSync(IpcChannels.GET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL) !== false,
127127
setLocalEnvironmentEnabled: (enabled) =>
128128
ipcRenderer.invoke(IpcChannels.SET_LOCAL_ENVIRONMENT_ENABLED_CHANNEL, enabled),
129+
getHostEnvironmentId: () => ipcRenderer.invoke(IpcChannels.GET_HOST_ENVIRONMENT_ID_CHANNEL),
129130
getClientSettings: () => ipcRenderer.invoke(IpcChannels.GET_CLIENT_SETTINGS_CHANNEL),
130131
setClientSettings: (settings) =>
131132
ipcRenderer.invoke(IpcChannels.SET_CLIENT_SETTINGS_CHANNEL, settings),

‎apps/mobile/src/features/settings/SettingsProviderAccountsRouteScreen.tsx‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ function ProviderAccount({
149149
const complete = useAtomCommand(serverEnvironment.completeProviderAuth, options);
150150
const cancel = useAtomCommand(serverEnvironment.cancelProviderAuth, options);
151151
const logout = useAtomCommand(serverEnvironment.logoutProviderAuth, options);
152+
const removeMethod = useAtomCommand(serverEnvironment.removeProviderAuthMethod, options);
153+
const canRemoveMethod = useAtomValue(
154+
serverEnvironment.removeProviderAuthMethod.permissionAtom(environmentId),
155+
);
152156
// Matches ListRowLayout: large text stacks the action below instead of squeezing the status.
153157
const stacked = useWindowDimensions().fontScale >= 1.5;
154158
const [pending, setPending] = useState(false);
@@ -260,6 +264,21 @@ function ProviderAccount({
260264
id: `method:${method.id}`,
261265
title: method.name,
262266
}));
267+
const removableMethods = methods.filter((method) => method.canRemove);
268+
const removeActions: MenuAction[] = removableMethods.length
269+
? [
270+
{
271+
id: "remove",
272+
title: "Remove incomplete connection",
273+
attributes: { disabled: disabled || active || !canRemoveMethod },
274+
subactions: removableMethods.map((method) => ({
275+
id: `remove:${method.id}`,
276+
title: method.name,
277+
attributes: { destructive: true, disabled: disabled || active || !canRemoveMethod },
278+
})),
279+
},
280+
]
281+
: [];
263282
function startSignIn(methodId?: string) {
264283
void run(() => start(methodId ? { environmentId, input: { instanceId, methodId } } : target));
265284
}
@@ -283,10 +302,16 @@ function ProviderAccount({
283302
if (id === "signOut") signOut();
284303
// iOS keeps a disabled submenu's children selectable, so sign-in guards here too.
285304
else if (signInDisabled) return;
286-
else if (id.startsWith("method:")) startSignIn(id.slice("method:".length));
305+
else if (id.startsWith("remove:")) {
306+
if (active || !canRemoveMethod) return;
307+
const methodId = id.slice("remove:".length);
308+
if (!removableMethods.some((method) => method.id === methodId)) return;
309+
void run(() => removeMethod({ environmentId, input: { instanceId, methodId } }));
310+
} else if (id.startsWith("method:")) startSignIn(id.slice("method:".length));
287311
else if (id === "change") startSignIn();
288312
}
289313
const accountActions: MenuAction[] = [
314+
...removeActions,
290315
...(canSignIn
291316
? [
292317
{
@@ -357,7 +382,7 @@ function ProviderAccount({
357382
accessibilityRole="button"
358383
accessibilityLabel={`Sign in to ${name}`}
359384
title="Sign in with"
360-
actions={methodActions}
385+
actions={[...methodActions, ...removeActions]}
361386
onPressAction={({ nativeEvent }) => onMenuAction(nativeEvent.event)}
362387
>
363388
<ControlPill variant="primary" label="Sign in" accessibilityLabel={`Sign in to ${name}`} />

‎apps/mobile/src/features/threads/useStartSideChat.ts‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import {
55
squashAtomCommandFailure,
66
type AtomCommandResult,
77
} from "@t3tools/client-runtime/state/runtime";
8-
import { MessageId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
8+
import {
9+
MessageId,
10+
ThreadId,
11+
type ModelSelection,
12+
type RuntimeMode,
13+
type ScopedThreadRef,
14+
} from "@t3tools/contracts";
915

1016
import * as Dialog from "../../components/ui/Dialog";
1117
import { uuidv4 } from "../../lib/uuid";
@@ -17,11 +23,13 @@ import { useOpenLinkedThread } from "./useOpenLinkedThread";
1723

1824
/**
1925
* Forks `source` at its latest stable point into a side chat, sends `prompt` there, and opens
20-
* it like any linked thread. Resolves false when the side chat did not start.
26+
* it like any linked thread. Resolves false when the side chat did not start. `settings` are
27+
* what the parent's composer would send, which its thread gets only on its next send.
2128
*/
2229
export function useStartSideChat() {
2330
const forkSideChat = useAtomCommand(threadEnvironment.forkSideChat, { reportFailure: false });
2431
const deleteThread = useAtomCommand(threadEnvironment.delete, { reportFailure: false });
32+
const setRuntimeMode = useAtomCommand(threadEnvironment.setRuntimeMode, { reportFailure: false });
2533
const startTurn = useAtomCommand(threadEnvironment.startTurn, { reportFailure: false });
2634
const openLinkedThread = useOpenLinkedThread();
2735

@@ -34,7 +42,11 @@ export function useStartSideChat() {
3442
Dialog.alert("Side chat not started", error instanceof Error ? error.message : fallback);
3543
};
3644

37-
return async (source: ScopedThreadRef, prompt: string): Promise<boolean> => {
45+
return async (
46+
source: ScopedThreadRef,
47+
prompt: string,
48+
settings: { readonly runtimeMode: RuntimeMode; readonly modelSelection: ModelSelection },
49+
): Promise<boolean> => {
3850
const targetThreadId = ThreadId.make(uuidv4());
3951
const fork = await forkSideChat({
4052
environmentId: source.environmentId,
@@ -70,6 +82,21 @@ export function useStartSideChat() {
7082
discard();
7183
return false;
7284
}
85+
if (settings.runtimeMode !== sideChat.runtimeMode) {
86+
const mode = await setRuntimeMode({
87+
environmentId: source.environmentId,
88+
input: {
89+
threadId: targetThreadId,
90+
runtimeMode: settings.runtimeMode,
91+
createdAt: new Date().toISOString(),
92+
},
93+
});
94+
if (mode._tag === "Failure") {
95+
alertFailure(mode, "Could not set the side chat's permission mode.");
96+
discard();
97+
return false;
98+
}
99+
}
73100
const turn = await startTurn({
74101
environmentId: source.environmentId,
75102
input: {
@@ -80,8 +107,9 @@ export function useStartSideChat() {
80107
text: prompt,
81108
attachments: [],
82109
},
110+
modelSelection: settings.modelSelection,
83111
titleSeed: deriveThreadTitleSeed({ text: prompt, attachments: [] }),
84-
runtimeMode: sideChat.runtimeMode,
112+
runtimeMode: settings.runtimeMode,
85113
interactionMode: "default",
86114
createdAt: new Date().toISOString(),
87115
},

‎apps/mobile/src/features/usage/UsageLimitsPooled.tsx‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,11 @@ export function UsageLimitsSection({
408408
now,
409409
failedLabels,
410410
selectedEnvironmentIds,
411-
cursorPrompt,
412411
wide = false,
413412
}: {
414413
readonly now: number;
415414
readonly failedLabels: readonly string[];
416415
readonly selectedEnvironmentIds: ReadonlySet<EnvironmentId> | null;
417-
readonly cursorPrompt?: ReactNode;
418416
readonly wide?: boolean;
419417
}) {
420418
const presentations = useAtomValue(environmentPresentations.presentationsWithProvidersAtom);
@@ -426,29 +424,22 @@ export function UsageLimitsSection({
426424
const notices = collectLimitNotices(selected);
427425
const externalLinks = collectExternalUsageLinks(selected);
428426
const colors = useProviderColors();
429-
const cursorPromptAt =
430-
Math.max(
431-
pools.findIndex((pool) => pool.driver === "codex"),
432-
pools.findIndex((pool) => pool.driver === "claudeAgent"),
433-
) + 1;
434427
return (
435428
<View className="gap-6">
436429
{pools.length === 0 &&
437430
notices.length === 0 &&
438431
failedLabels.length === 0 &&
439-
!cursorPrompt &&
440432
externalLinks.length === 0 ? (
441433
<Text className="py-12 text-center text-base text-foreground-muted">
442434
{selected.size === 0
443435
? "Select an environment to see limits."
444436
: "No provider on the selected environments reports subscription limits."}
445437
</Text>
446438
) : null}
447-
{pools.map((pool, index) => {
439+
{pools.map((pool) => {
448440
const windows = displayLimitWindows(pool);
449441
return (
450442
<Fragment key={pool.driver}>
451-
{index === cursorPromptAt ? cursorPrompt : null}
452443
<View className="gap-3">
453444
<View className="flex-row items-center gap-2 px-1">
454445
<ProviderIcon provider={pool.driver} size={18} />
@@ -478,7 +469,6 @@ export function UsageLimitsSection({
478469
</Fragment>
479470
);
480471
})}
481-
{cursorPromptAt === pools.length ? cursorPrompt : null}
482472
{externalLinks.map((link) => (
483473
<View key={link.url} className="gap-3 rounded-xl border border-border-subtle p-4">
484474
<Text className="text-base font-t3-medium text-foreground">{link.label}</Text>

‎apps/mobile/src/features/usage/UsageLimitsSection.tsx‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,16 @@ export function useRefreshLimits(
345345
.filter(([environmentId]) => failedIds.has(environmentId))
346346
.map(([, presentation]) => presentation.entry.target.label);
347347

348-
const refresh = (afterPending: boolean) =>
348+
const refresh = () =>
349349
Promise.all(
350-
connectedIds.map((environmentId) =>
351-
refreshEnvironmentLimits(registry, environmentId, { afterPending }),
352-
),
350+
connectedIds.map((environmentId) => refreshEnvironmentLimits(registry, environmentId)),
353351
);
354352
// Android RefreshControl needs a true-to-false cycle to stop, even with nothing to probe.
355353
const refreshManually = async () => {
356354
if (refreshingRef.current) return;
357355
refreshingRef.current = true;
358356
setRefreshing(true);
359-
await refresh(false).finally(() => {
357+
await refresh().finally(() => {
360358
refreshingRef.current = false;
361359
setRefreshing(false);
362360
});
@@ -366,6 +364,5 @@ export function useRefreshLimits(
366364
refreshing,
367365
failedLabels,
368366
refresh: refreshManually,
369-
refreshAfterEnable: () => refresh(true),
370367
};
371368
}

0 commit comments

Comments
 (0)