Skip to content

Commit 274fdb5

Browse files
Merge remote-tracking branch 'origin/main' into pr-20303
2 parents 4b71f9c + 4af6618 commit 274fdb5

102 files changed

Lines changed: 3265 additions & 388 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/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { presentThreadShell } from "@t3tools/client-runtime/state/models";
22
import * as DateTime from "effect/DateTime";
3+
import * as Schema from "effect/Schema";
34
import { planPinnedMove } from "@t3tools/client-runtime/state/thread-sort";
45
import {
56
createPendingThreadOrder,
@@ -17,6 +18,7 @@ import {
1718
CommandId,
1819
EnvironmentId,
1920
MessageId,
21+
OrchestrationV2ThreadShell,
2022
ProjectId,
2123
ProviderInstanceId,
2224
RunId,
@@ -43,6 +45,7 @@ import {
4345
} from "./threadListV2";
4446

4547
const environmentId = EnvironmentId.make("environment-1");
48+
const decodeThreadShell = Schema.decodeUnknownSync(OrchestrationV2ThreadShell);
4649

4750
function makeThread(
4851
input: Partial<EnvironmentThreadShell> & Pick<EnvironmentThreadShell, "id" | "title">,
@@ -111,6 +114,30 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => {
111114
});
112115

113116
describe("resolveThreadListV2Status", () => {
117+
it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {
118+
const raw = makeRawThreadShell({
119+
status: "running",
120+
activeRunId: RunId.make("run-wait"),
121+
latestRunId: RunId.make("run-wait"),
122+
});
123+
const present = (shell: unknown) => presentThreadShell(environmentId, decodeThreadShell(shell));
124+
125+
expect(resolveThreadListV2Status(present(raw))).toBe("working");
126+
const blocked = present({ ...raw, blockedOnThreadWait: true });
127+
expect(
128+
resolveThreadListV2Status({
129+
...blocked,
130+
hasPendingApprovals: true,
131+
hasPendingUserInput: true,
132+
}),
133+
).toBe("approval");
134+
expect(resolveThreadListV2Status({ ...blocked, hasPendingUserInput: true })).toBe("input");
135+
expect(resolveThreadListV2Status(blocked)).toBe("waiting");
136+
expect(resolveThreadListV2Status(present({ ...raw, blockedOnThreadWait: false }))).toBe(
137+
"working",
138+
);
139+
});
140+
114141
it("distinguishes usage limits from ordinary failures and clears the label after recovery", () => {
115142
const thread = makeThread({
116143
id: ThreadId.make("limited"),

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ export function threadHasUnseenCompletion(
154154
export function resolveThreadListV2Status(
155155
thread: Pick<
156156
EnvironmentThreadShell,
157-
"hasPendingApprovals" | "hasPendingUserInput" | "pendingSubagentRequest" | "runtime"
157+
| "hasPendingApprovals"
158+
| "hasPendingUserInput"
159+
| "pendingSubagentRequest"
160+
| "runtime"
161+
| "blockedOnThreadWait"
158162
>,
159163
): ThreadListV2Status {
160164
if (thread.hasPendingApprovals || thread.pendingSubagentRequest === "approval") {
@@ -163,6 +167,9 @@ export function resolveThreadListV2Status(
163167
if (thread.hasPendingUserInput || thread.pendingSubagentRequest === "user_input") {
164168
return "input";
165169
}
170+
if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {
171+
return "waiting";
172+
}
166173
if (
167174
thread.runtime !== null &&
168175
["preparing", "queued", "starting", "running", "waiting"].includes(thread.runtime.status)

‎apps/mobile/src/state/thread-task-permissions.test.ts‎

Lines changed: 146 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
import { AuthOrchestrationOperateScope, RuntimeRequestId } from "@t3tools/contracts";
1+
import {
2+
AuthOrchestrationOperateScope,
3+
DEFAULT_SERVER_SETTINGS,
4+
MessageId,
5+
ProjectId,
6+
ProviderDriverKind,
7+
ProviderInstanceId,
8+
RunId,
9+
RuntimeRequestId,
10+
TurnItemId,
11+
type ModelSelection,
12+
type OrchestrationV2ThreadProjection,
13+
type ServerConfig,
14+
} from "@t3tools/contracts";
15+
import {
16+
v2Now,
17+
v2Projection,
18+
} from "../../../../packages/client-runtime/src/state/orchestrationV2TestFixtures";
219
import type { DraftComposerImageAttachment } from "../lib/composerImages";
320
import type { PendingThreadRequests } from "@t3tools/client-runtime/state/thread-requests";
421
import { AsyncResult, type Atom } from "effect/reactivity";
@@ -7,7 +24,13 @@ import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
724
const state = vi.hoisted(() => ({
825
grantedEnvironments: new Set<string>(),
926
connectionState: "connected",
10-
draft: { text: "Keep my draft", attachments: [] as DraftComposerImageAttachment[] },
27+
draft: {
28+
text: "Keep my draft",
29+
attachments: [] as DraftComposerImageAttachment[],
30+
modelSelection: undefined as ModelSelection | undefined,
31+
},
32+
serverConfig: null as ServerConfig | null,
33+
projection: null as OrchestrationV2ThreadProjection | null,
1134
pendingRequests: { approvals: [], userInputs: [] } as PendingThreadRequests,
1235
enqueue: vi.fn(async () => undefined),
1336
clearDraft: vi.fn(),
@@ -25,6 +48,7 @@ const state = vi.hoisted(() => ({
2548
thread: {
2649
id: "thread",
2750
environmentId: "secondary",
51+
projectId: "project",
2852
modelSelection: { instanceId: "codex", model: "gpt-5.4" },
2953
runtimeMode: "full-access",
3054
interactionMode: "default",
@@ -70,15 +94,13 @@ vi.mock("./use-thread-selection", () => ({
7094
selectedThreadCreation: null,
7195
selectedEnvironmentRuntime: {
7296
connectionState: state.connectionState,
73-
serverConfig: {
74-
providers: [{ instanceId: "codex", driver: "codex" }],
75-
environment: { capabilities: {} },
76-
},
97+
serverConfig: state.serverConfig,
7798
},
7899
}),
79100
}));
80101
vi.mock("./use-thread-detail", () => ({
81-
useSelectedThreadProjection: () => null,
102+
useSelectedThreadProjection: () =>
103+
state.projection === null ? null : { projection: state.projection },
82104
useSelectedThreadVisibleTurnItems: () => [],
83105
useSelectedThreadPendingRequests: () => state.pendingRequests,
84106
}));
@@ -126,7 +148,7 @@ vi.mock("./use-composer-drafts", async () => {
126148
mergeComposerDraftContent: vi.fn(),
127149
removeComposerDraftAttachment: vi.fn(),
128150
useComposerDraft: () => state.draft,
129-
useComposerDraftSettings: () => ({}),
151+
useComposerDraftSettings: () => state.draft,
130152
questionAttachmentDraftsAtom: () => Atom.make({}),
131153
};
132154
});
@@ -144,7 +166,6 @@ vi.mock("../lib/commandMetadata", () => ({
144166
}),
145167
}));
146168
vi.mock("../lib/copyTextWithHaptic", () => ({ copyTextWithHaptic: vi.fn() }));
147-
vi.mock("../lib/modelOptions", () => ({ isModelSelectionUnavailable: () => false }));
148169
vi.mock("./use-remote-environment-registry", () => ({ setPendingConnectionError: vi.fn() }));
149170

150171
import { useThreadComposerState } from "./use-thread-composer-state";
@@ -153,7 +174,12 @@ import { useSelectedThreadRequests } from "./use-selected-thread-requests";
153174
beforeEach(() => {
154175
state.grantedEnvironments = new Set(["primary"]);
155176
state.connectionState = "connected";
156-
state.draft = { text: "Keep my draft", attachments: [] };
177+
state.draft = { text: "Keep my draft", attachments: [], modelSelection: undefined };
178+
state.projection = null;
179+
state.serverConfig = {
180+
providers: [{ instanceId: "codex", driver: "codex", enabled: true }],
181+
environment: { capabilities: {} },
182+
} as unknown as ServerConfig;
157183
state.pendingRequests = {
158184
approvals: [
159185
{
@@ -260,3 +286,113 @@ describe("mobile task permissions", () => {
260286
});
261287
});
262288
});
289+
290+
describe("mobile handoff preview and submission", () => {
291+
it("follows project enablement and provider availability for the selected destination", async () => {
292+
state.grantedEnvironments.add("secondary");
293+
const instanceId = ProviderInstanceId.make("antigravity");
294+
const projectId = ProjectId.make(state.thread.projectId);
295+
const selection = { instanceId, model: "gemini" };
296+
const provider = {
297+
instanceId,
298+
driver: ProviderDriverKind.make("antigravity"),
299+
enabled: false,
300+
installed: true,
301+
auth: { status: "authenticated" as const },
302+
availability: "available" as "available" | "unavailable",
303+
models: [{ slug: selection.model }],
304+
};
305+
const projectOverride = { enabled: false };
306+
state.serverConfig = {
307+
...state.serverConfig,
308+
providers: [provider],
309+
settings: {
310+
...DEFAULT_SERVER_SETTINGS,
311+
providerInstances: { [instanceId]: { driver: provider.driver, enabled: false } },
312+
projectSettingsOverrides: {
313+
[projectId]: { providerInstances: { [instanceId]: projectOverride } },
314+
},
315+
},
316+
} as unknown as ServerConfig;
317+
state.draft.modelSelection = selection;
318+
const source = v2Projection.thread.modelSelection;
319+
state.projection = {
320+
...v2Projection,
321+
runs: [
322+
{
323+
id: RunId.make("source-run"),
324+
threadId: v2Projection.thread.id,
325+
ordinal: 1,
326+
providerInstanceId: source.instanceId,
327+
modelSelection: source,
328+
providerThreadId: null,
329+
userMessageId: MessageId.make("source-message"),
330+
rootNodeId: null,
331+
activeAttemptId: null,
332+
status: "completed",
333+
requestedAt: v2Now,
334+
startedAt: v2Now,
335+
completedAt: v2Now,
336+
checkpointId: null,
337+
contextHandoffId: null,
338+
},
339+
],
340+
visibleTurnItems: [
341+
{
342+
position: 0,
343+
visibility: "local",
344+
sourceThreadId: v2Projection.thread.id,
345+
sourceItemId: TurnItemId.make("reply"),
346+
item: {
347+
id: TurnItemId.make("reply"),
348+
threadId: v2Projection.thread.id,
349+
runId: RunId.make("source-run"),
350+
nodeId: null,
351+
providerThreadId: null,
352+
providerTurnId: null,
353+
nativeItemRef: null,
354+
parentItemId: null,
355+
ordinal: 1,
356+
type: "assistant_message",
357+
messageId: MessageId.make("reply"),
358+
status: "completed",
359+
title: null,
360+
text: "Task started",
361+
streaming: false,
362+
startedAt: v2Now,
363+
completedAt: v2Now,
364+
updatedAt: v2Now,
365+
},
366+
},
367+
],
368+
};
369+
370+
const disabled = useThreadComposerState();
371+
expect(disabled.pendingHandoff).toBeNull();
372+
expect(await disabled.onSendMessage()).toBeNull();
373+
expect(state.enqueue).not.toHaveBeenCalled();
374+
expect(state.clearDraft).not.toHaveBeenCalled();
375+
376+
projectOverride.enabled = true;
377+
expect(useThreadComposerState().pendingHandoff).toEqual({ from: [source], to: selection });
378+
379+
provider.availability = "unavailable";
380+
const unavailable = useThreadComposerState();
381+
expect(unavailable.pendingHandoff).toBeNull();
382+
expect(await unavailable.onSendMessage()).toBeNull();
383+
expect(state.enqueue).not.toHaveBeenCalled();
384+
expect(state.clearDraft).not.toHaveBeenCalled();
385+
386+
provider.availability = "available";
387+
const available = useThreadComposerState();
388+
expect(available.pendingHandoff).toEqual({ from: [source], to: selection });
389+
expect(await available.onSendMessage()).toBe("message");
390+
expect(state.enqueue).toHaveBeenCalledExactlyOnceWith(
391+
expect.objectContaining({
392+
modelSelection: selection,
393+
text: "Keep my draft",
394+
}),
395+
);
396+
expect(state.clearDraft).toHaveBeenCalledTimes(1);
397+
});
398+
});

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,13 @@ export function useThreadComposerState() {
300300
const selectedThreadQueueCount = selectedThreadQueuedMessages.length;
301301
const selectedThread = selectedThreadShell;
302302
const modelSelection = selectedDraft.modelSelection ?? selectedThread?.modelSelection ?? null;
303+
const serverConfig = selectedEnvironmentRuntime?.serverConfig;
303304
const pendingHandoff = resolvePendingHandoff(
304305
selectedThreadProjection?.projection,
305-
modelSelection,
306-
selectedEnvironmentRuntime?.serverConfig?.providers ?? [],
306+
isModelSelectionUnavailable(serverConfig, modelSelection, selectedThread?.projectId ?? null)
307+
? null
308+
: modelSelection,
309+
serverConfig?.providers ?? [],
307310
);
308311
const runtimeMode = selectedDraft.runtimeMode ?? selectedThread?.runtimeMode ?? null;
309312
const selectedProvider = selectedEnvironmentRuntime?.serverConfig?.providers.find(

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ const emitStaleXAiPromptCompleteBeforeSecondHang =
9090
const emitOverlappingXAiPromptCompleteOutOfOrder =
9191
process.env.T3_ACP_EMIT_OVERLAPPING_XAI_PROMPT_COMPLETE_OUT_OF_ORDER === "1";
9292
const failPrompt = process.env.T3_ACP_FAIL_PROMPT === "1";
93+
const failPromptOrdinal = Number(process.env.T3_ACP_FAIL_PROMPT_ORDINAL);
94+
const compactionPromptOrdinals = new Set(
95+
(process.env.T3_ACP_COMPACTION_PROMPT_ORDINALS ?? "").split(",").map(Number),
96+
);
9397
const failSetConfigOption = process.env.T3_ACP_FAIL_SET_CONFIG_OPTION === "1";
9498
const failSetModeConfigOption = process.env.T3_ACP_FAIL_SET_MODE_CONFIG_OPTION === "1";
9599
const exitOnSetConfigOption = process.env.T3_ACP_EXIT_ON_SET_CONFIG_OPTION === "1";
@@ -1299,7 +1303,20 @@ const program = Effect.gen(function* () {
12991303
yield* Effect.sleep(`${promptDelayMs} millis`);
13001304
}
13011305

1302-
if (failPrompt) {
1306+
if (compactionPromptOrdinals.has(promptCount)) {
1307+
for (const status of ["in_progress", "completed"] as const) {
1308+
yield* agent.client.sessionUpdate({
1309+
sessionId: requestedSessionId,
1310+
update: {
1311+
sessionUpdate: "compaction_update",
1312+
compactionId: `compact-${promptCount}`,
1313+
status,
1314+
},
1315+
});
1316+
}
1317+
}
1318+
1319+
if (failPrompt || promptCount === failPromptOrdinal) {
13031320
return yield* AcpError.AcpRequestError.internalError("Mock prompt failure");
13041321
}
13051322

‎apps/server/src/assets/AssetAccess.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,36 @@ describe("AssetAccess", () => {
816816
}).pipe(Effect.provide(layerTest)),
817817
);
818818

819+
it.effect("serves home-relative draft media files from the home folder", () =>
820+
Effect.gen(function* () {
821+
const fileSystem = yield* FileSystem.FileSystem;
822+
const path = yield* Path.Path;
823+
const root = yield* fileSystem.makeTempDirectoryScoped({
824+
prefix: "t3-asset-draft-root-",
825+
});
826+
const home = yield* fileSystem.makeTempDirectoryScoped({
827+
prefix: "t3-asset-draft-home-",
828+
});
829+
const clipPath = path.join(home, "Downloads", "clip.mp4");
830+
yield* fileSystem.makeDirectory(path.dirname(clipPath), { recursive: true });
831+
yield* fileSystem.writeFileString(clipPath, "video");
832+
const canonicalClipPath = yield* fileSystem.realPath(clipPath);
833+
834+
const result = yield* issueAssetUrl({
835+
resource: { _tag: "draft-workspace-file", cwd: root, path: "~/Downloads/clip.mp4" },
836+
workspaceRoot: root,
837+
}).pipe(Effect.provideService(HostProcess.HomeDirectory, home));
838+
const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
839+
const token = suffix.slice(0, suffix.indexOf("/"));
840+
841+
expect(yield* resolveAsset(token, "clip.mp4")).toMatchObject({
842+
kind: "file",
843+
path: canonicalClipPath,
844+
mimeType: "video/mp4",
845+
});
846+
}).pipe(Effect.provide(layerTest)),
847+
);
848+
819849
it.effect("serves absolute draft media files exactly, wherever they live", () =>
820850
Effect.gen(function* () {
821851
const fileSystem = yield* FileSystem.FileSystem;

‎apps/server/src/assets/AssetAccess.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,12 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
559559
}
560560
case "draft-workspace-file": {
561561
const draftWorkspaceRoot = input.workspaceRoot ?? input.resource.cwd;
562-
if (path.isAbsolute(input.resource.path)) {
562+
const hostPath = input.resource.path.startsWith("~/")
563+
? expandHomePath(input.resource.path, yield* HostProcess.HomeDirectory)
564+
: input.resource.path;
565+
if (path.isAbsolute(hostPath)) {
563566
const finalized = yield* finalizeAbsoluteMediaFileAsset({
564-
requestedPath: input.resource.path,
567+
requestedPath: hostPath,
565568
resource: input.resource,
566569
expiresAt,
567570
});

0 commit comments

Comments
 (0)