Skip to content

Commit 685b805

Browse files
committed
refactor(mobile): move the mobile half to its own pull request
1 parent 7584e35 commit 685b805

5 files changed

Lines changed: 6 additions & 117 deletions

File tree

‎apps/mobile/src/components/ComposerEditor.tsx‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export function ComposerEditor({
101101
retained.attachments.length,
102102
controller.signal,
103103
retained.context?.records.length ?? 0,
104-
environmentId,
105104
);
106105
if (!result) {
107106
insertComposerDraftText(draftKey, clipboard.text, insertion);
@@ -114,22 +113,10 @@ export function ComposerEditor({
114113
);
115114
return;
116115
}
117-
const warnings = [
118-
...(result.failures.length > 0
119-
? [
120-
"Some attachments could not be copied. Reconnect to the source environment and copy them again.",
121-
]
122-
: []),
123-
...(result.skippedThreads.length > 0
124-
? [
125-
`Threads from another machine weren't pasted: this machine's agent can't read ${result.skippedThreads.map((title) => `"${title}"`).join(", ")}.`,
126-
]
127-
: []),
128-
];
129-
if (warnings.length > 0)
116+
if (result.failures.length > 0)
130117
Alert.alert(
131-
"Some context could not be pasted",
132-
[...warnings, "Those references are marked unavailable."].join("\n\n"),
118+
"Some attachments could not be copied",
119+
"Reconnect to the source environment and copy them again. References without their files are marked unavailable.",
133120
);
134121
} catch (error) {
135122
if (!controller.signal.aborted)

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import { ProviderIcon } from "../../components/ProviderIcon";
6767
import { SymbolView } from "../../components/AppSymbol";
6868
import { AppText as Text } from "../../components/AppText";
6969
import { hasProviderUsageLimits, isUsageLimitsCommand } from "@t3tools/shared/usageLimits";
70-
import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
7170
import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer";
7271
import { ComposerCommandPopover } from "./ComposerCommandPopover";
7372
import { useComposerCommandMenu } from "./use-composer-command-menu";
@@ -1299,22 +1298,6 @@ export function NewTaskDraftScreen(props: {
12991298
Alert.alert("Too much context", contextBlockReason);
13001299
return;
13011300
}
1302-
const strandedThread = threadContextsOutsideEnvironment({
1303-
text: draft.text,
1304-
records: draft.context?.records ?? [],
1305-
environmentId: selectedProject.environmentId,
1306-
})[0];
1307-
if (strandedThread) {
1308-
const owner =
1309-
flow.environments.find(
1310-
(environment) => environment.environmentId === strandedThread.environmentId,
1311-
)?.environmentLabel ?? "its machine";
1312-
Alert.alert(
1313-
"Attached thread is on another machine",
1314-
`This machine's agent can't read "${strandedThread.title}". Remove it, or switch back to ${owner} to send.`,
1315-
);
1316-
return;
1317-
}
13181301

13191302
const editingPendingTask = flow.editingPendingTask;
13201303

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
ThreadId,
2525
} from "@t3tools/contracts";
2626
import { sanitizeNewRefName } from "@t3tools/shared/git";
27-
import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
2827
import { resolveNewThreadEnvMode, resolveProjectSettings } from "@t3tools/shared/projectSettings";
2928
import { parseT3ProjectFile } from "@t3tools/shared/t3ProjectFile";
3029
import * as Arr from "effect/Array";
@@ -1130,16 +1129,6 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
11301129
if ((text.length === 0 && draft.attachments.length === 0) || !draftModelSelection) {
11311130
return null;
11321131
}
1133-
// A thread attached on another machine is unreadable here; the submit path explains why.
1134-
if (
1135-
threadContextsOutsideEnvironment({
1136-
text: draft.text,
1137-
records: draft.context?.records ?? [],
1138-
environmentId: selectedProject.environmentId,
1139-
}).length > 0
1140-
) {
1141-
return null;
1142-
}
11431132
// A saved choice from before the project went no-project must not
11441133
// survive: those threads always run locally in their own folder.
11451134
const workspaceSelection = canChooseWorkspace ? draft.workspaceSelection : undefined;

‎apps/mobile/src/lib/composerContextClipboard.test.ts‎

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2-
import {
3-
COMPOSER_CONTEXT_MAX_RECORDS,
4-
ComposerContextId,
5-
EnvironmentId,
6-
ThreadId,
7-
} from "@t3tools/contracts";
2+
import { ComposerContextId, EnvironmentId } from "@t3tools/contracts";
83
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
94

105
const mocks = vi.hoisted(() => ({
@@ -147,55 +142,6 @@ describe("mobile context clipboard imports", () => {
147142
expect(mocks.download).not.toHaveBeenCalled();
148143
});
149144

150-
const thread = (id: string, environmentId: string) => ({
151-
version: 1 as const,
152-
kind: "thread" as const,
153-
contextId: ComposerContextId.make(id),
154-
label: id,
155-
environmentId: EnvironmentId.make(environmentId),
156-
threadId: ThreadId.make(id),
157-
title: id,
158-
});
159-
160-
it("drops threads owned by another machine than the destination", async () => {
161-
const result = await importComposerContextClipboard(
162-
{
163-
text: "[local](t3-context://v1/thread/local) [foreign](t3-context://v1/thread/foreign)",
164-
fragment: encodeComposerContextFragment({
165-
version: 1,
166-
source: { environmentId: EnvironmentId.make("source") },
167-
records: [thread("local", "destination"), thread("foreign", "source")],
168-
})!,
169-
html: "",
170-
},
171-
0,
172-
new AbortController().signal,
173-
// Only one slot is free: the dropped thread must not count against it.
174-
COMPOSER_CONTEXT_MAX_RECORDS - 1,
175-
EnvironmentId.make("destination"),
176-
);
177-
expect(result?.context.records.map((record) => record.label)).toEqual(["local"]);
178-
expect(result?.skippedThreads).toEqual(["foreign"]);
179-
});
180-
181-
it("keeps threads when the destination machine is unknown", async () => {
182-
const result = await importComposerContextClipboard(
183-
{
184-
text: "[foreign](t3-context://v1/thread/foreign)",
185-
fragment: encodeComposerContextFragment({
186-
version: 1,
187-
source: { environmentId: EnvironmentId.make("source") },
188-
records: [thread("foreign", "source")],
189-
})!,
190-
html: "",
191-
},
192-
0,
193-
new AbortController().signal,
194-
);
195-
expect(result?.context.records.map((record) => record.label)).toEqual(["foreign"]);
196-
expect(result?.skippedThreads).toEqual([]);
197-
});
198-
199145
it("refuses an overflowing context paste before copying files", async () => {
200146
await expect(
201147
importComposerContextClipboard(clipboard, 0, new AbortController().signal, 200),

‎apps/mobile/src/lib/composerContextClipboard.ts‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,14 @@ export async function importComposerContextClipboard(
6666
existingCount: number,
6767
signal: AbortSignal,
6868
existingContextCount = 0,
69-
destinationEnvironmentId?: EnvironmentId,
7069
) {
7170
const fragment =
7271
decodeComposerContextFragment(input.fragment) ?? decodeComposerContextClipboardHtml(input.html);
7372
if (!fragment) return null;
7473
const selected = referencedComposerContext(input.text, { version: 1, records: fragment.records });
75-
// The agent can only read threads on its own server; a pasted foreign one is dropped and its
76-
// reference stays visibly unavailable, like an attachment that failed to copy.
77-
const skippedThreads: string[] = [];
78-
const retained = (selected?.records ?? []).filter((record) => {
79-
if (
80-
record.kind !== "thread" ||
81-
!("threadId" in record) ||
82-
destinationEnvironmentId === undefined ||
83-
record.environmentId === destinationEnvironmentId
84-
)
85-
return true;
86-
skippedThreads.push(record.title);
87-
return false;
88-
});
89-
if (existingContextCount + retained.length > COMPOSER_CONTEXT_MAX_RECORDS)
74+
if (existingContextCount + (selected?.records.length ?? 0) > COMPOSER_CONTEXT_MAX_RECORDS)
9075
throw new Error("Remove some context items from the draft before pasting more.");
91-
const imported = reidentifyComposerContext(input.text, retained, uuidv4);
76+
const imported = reidentifyComposerContext(input.text, selected?.records ?? [], uuidv4);
9277
const attachments: DraftComposerAttachment[] = [];
9378
const records: ComposerContextRecord[] = [];
9479
const failures: string[] = [];
@@ -115,7 +100,6 @@ export async function importComposerContextClipboard(
115100
context: { version: 1 as const, records },
116101
attachments,
117102
failures,
118-
skippedThreads,
119103
};
120104
} catch (error) {
121105
await Promise.all(

0 commit comments

Comments
 (0)