Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { msg, T, useGT, useLocale, useMessages, Var } from "gt-react-native";
import { managedCapabilityDenial } from "@t3tools/client-runtime/contract-labels";
import {
runtimeModeChoicesForSupportedModes,
withManagedRuntimeModeLimits,
} from "../threads/thread-settings-options";
import * as Dialog from "../../components/ui/Dialog";
import { useAtomValue } from "@effect/atom-react";
import {
Expand All @@ -11,6 +15,9 @@ import { readEnvironmentScope } from "../../state/session";
import type {
EnvironmentId,
ProjectId,
RuntimeMode,
ManagedPolicySummary,
ProviderInteractionMode,
ScheduledTask,
ScheduledTaskThreadMode,
ScheduledTaskUpsertInput,
Expand Down Expand Up @@ -439,6 +446,97 @@ function PickerRow(props: {
);
}

function TaskRuntimeRow({
draft,
provider,
managedPolicy,
setDraft,
}: {
readonly draft: Draft;
readonly provider: { readonly supportedRuntimeModes?: ReadonlyArray<RuntimeMode> } | null;
readonly managedPolicy: ManagedPolicySummary | undefined;
readonly setDraft: (update: (current: Draft) => Draft) => void;
}) {
const gt = useGT();
const m = useMessages();
const providerChoices = runtimeModeChoicesForSupportedModes(provider?.supportedRuntimeModes);
// Modes above an administrator's ceiling stay listed, disabled with the reason.
const choices = withManagedRuntimeModeLimits(providerChoices, [managedPolicy], m);
const runtimeMode = taskRuntimeMode(draft.runtimeMode, providerChoices, managedPolicy);
const selected = choices.find((choice) => choice.mode === runtimeMode);
return (
<SelectRow
label={gt("Permissions")}
value={selected ? m(selected.label) : gt("Choose permissions")}
actions={choices.map((choice) => ({
id: choice.mode,
title: m(choice.label),
subtitle: choice.disabledReason ?? m(choice.description),
state: choice.mode === runtimeMode ? ("on" as const) : undefined,
attributes: { disabled: choice.disabledReason !== undefined },
}))}
onSelect={(id) => {
const choice = choices.find((candidate) => candidate.mode === id);
if (choice && choice.disabledReason === undefined)
setDraft((current) => ({ ...current, runtimeMode: choice.mode }));
}}
/>
);
}

/** The mode an unbound task runs in: the provider's nearest mode, lowered to any managed ceiling. */
function taskRuntimeMode(
mode: RuntimeMode,
providerChoices: ReadonlyArray<{ readonly mode: RuntimeMode }>,
managedPolicy: ManagedPolicySummary | undefined,
) {
const modes = providerChoices.map((choice) => choice.mode);
const supported = modes.includes(mode) ? mode : (modes[0] ?? mode);
return clampManagedRuntimeMode(managedPolicy, supported, modes) ?? supported;
}

function TaskInteractionRow({
draft,
planModeAvailable,
disabled,
setDraft,
}: {
readonly draft: Draft;
readonly planModeAvailable: boolean;
readonly disabled: boolean;
readonly setDraft: (update: (current: Draft) => Draft) => void;
}) {
const gt = useGT();
return (
<View className="min-h-14 flex-row items-center gap-3 border-t border-border-subtle px-4 py-3">
<View className="min-w-0 flex-1">
<Text textRole="body" className="text-foreground">
{gt("Mode", { $context: "interaction mode, build or plan" })}
</Text>
<Text className="text-sm text-foreground-muted">
{planModeAvailable
? gt("Plan drafts a proposal before acting.")
: gt("Plan is unavailable for this provider.")}
</Text>
</View>
<SegmentedControl
variant="card"
// Segments share the track's width, so without one the control collapses beside the text.
className="w-48 shrink-0"
options={[
{ value: "default", label: gt("Build", { $context: "interaction mode" }) },
{ value: "plan", label: gt("Plan", { $context: "interaction mode" }) },
]}
selected={planModeAvailable ? draft.interactionMode : "default"}
onSelect={(mode: ProviderInteractionMode) => {
if (!disabled && planModeAvailable)
setDraft((current) => ({ ...current, interactionMode: mode }));
}}
/>
</View>
);
}

export function SettingsScheduledTasksRouteScreen() {
const gt = useGT();
const [now, setNow] = useState(Date.now);
Expand Down Expand Up @@ -805,6 +903,12 @@ function TaskForm({
config?.environment.capabilities.oneTimeSchedules === true ||
draft.task?.schedule.type === "once";
const offersThreadModes = config?.environment.capabilities.scheduledTaskThreadModes === true;
const providerForDraft =
config?.providers.find(
(provider) => provider.instanceId === draft.modelSelection?.instanceId,
) ?? null;
const planModeAvailable = providerForDraft?.showInteractionModeToggle !== false;
const boundToThread = draft.threadId !== null;
const save = async () => {
const current = readEditor();
if (!current || current.environmentId !== environmentId) return;
Expand Down Expand Up @@ -901,10 +1005,15 @@ function TaskForm({
baseRef: worktreeBaseRef,
startFromOrigin: draft.startFromOrigin,
},
// Tasks have no mode picker; a mode above the administrator's ceiling is refused.
runtimeMode:
clampManagedRuntimeMode(config?.managedPolicy, draft.runtimeMode) ?? draft.runtimeMode,
interactionMode: draft.task?.interactionMode ?? "default",
// A bound run uses its thread's modes, so the stored ones are kept as they are.
runtimeMode: boundToThread
? draft.runtimeMode
: taskRuntimeMode(
draft.runtimeMode,
runtimeModeChoicesForSupportedModes(providerForDraft?.supportedRuntimeModes),
config?.managedPolicy,
),
interactionMode: boundToThread || planModeAvailable ? draft.interactionMode : "default",
creationSource: draft.task?.creationSource ?? "mobile",
};
submissionPending.current = true;
Expand Down Expand Up @@ -1088,6 +1197,27 @@ function TaskForm({
) : null}
</SettingsSection>

{boundToThread ? (
<Text className="px-1 text-sm text-foreground-muted">
{gt("Runs use the destination thread's workspace, permissions, and mode.")}
</Text>
) : (
<SettingsSection>
<TaskRuntimeRow
draft={draft}
provider={providerForDraft}
managedPolicy={config?.managedPolicy}
setDraft={setDraft}
/>
<TaskInteractionRow
draft={draft}
planModeAvailable={planModeAvailable}
disabled={saving || dictationPending || environmentUnavailable}
setDraft={setDraft}
/>
</SettingsSection>
)}

<SettingsSection title={gt("Workspace")}>
<SelectRow
label={gt("Run in")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,20 @@ describe("new scheduled task link", () => {
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)).toBeNull();
});

it("keeps unsaved changes until the editor's removal guard discards them", () => {
startScheduledTaskEditor(editing);
const edited = { ...editing, draft: { ...editing.draft, prompt: "unsaved" } };
updateScheduledTaskEditor(edited, null);

takeScheduledTaskNewLink(newTaskLink);
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current).toBe(edited);

discardScheduledTaskEditor();
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)).toBeNull();
});
it.each([{ prompt: "unsaved" }, { interactionMode: "plan" as const }])(
"keeps unsaved %j changes until the editor's removal guard discards them",
(patch) => {
startScheduledTaskEditor(editing);
const edited = { ...editing, draft: { ...editing.draft, ...patch } };
updateScheduledTaskEditor(edited, null);

takeScheduledTaskNewLink(newTaskLink);
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current).toBe(edited);

discardScheduledTaskEditor();
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)).toBeNull();
},
);

it("keeps an unchanged task while its save is still pending", () => {
startScheduledTaskEditor(editing);
Expand Down
5 changes: 5 additions & 0 deletions apps/mobile/src/features/settings/scheduledTaskDraft.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isWebhookDedupeTemplate, scheduledTaskThreadMode } from "@t3tools/contracts";
import type {
ModelSelection,
ProviderInteractionMode,
ServerConfig,
ProjectId,
RuntimeMode,
Expand Down Expand Up @@ -214,6 +215,7 @@ export type ScheduledTaskDraft = {
readonly enabled: boolean;
readonly startFromOrigin: boolean;
readonly runtimeMode: RuntimeMode;
readonly interactionMode: ProviderInteractionMode;
};

function draftSignature(draft: ScheduledTaskDraft): string {
Expand Down Expand Up @@ -244,6 +246,7 @@ function draftSignature(draft: ScheduledTaskDraft): string {
draft.enabled,
draft.startFromOrigin,
draft.runtimeMode,
draft.interactionMode,
]);
}

Expand Down Expand Up @@ -306,6 +309,7 @@ export function createDraft(
enabled: true,
startFromOrigin: true,
runtimeMode: "full-access",
interactionMode: "default",
};
}

Expand All @@ -332,5 +336,6 @@ export function editDraft(task: ScheduledTask): ScheduledTaskDraft {
? (task.workspaceStrategy.startFromOrigin ?? false)
: true,
runtimeMode: task.runtimeMode,
interactionMode: task.interactionMode,
};
}
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5731,6 +5731,14 @@
"eb1fd384ad5919dd": "Interne Notiz",
"b45f0b467e9406d0": "Dem Kunden antworten",
"15e5597f8f93ce12": "{start} bis {end}",
"4aa91c06e3cc23d3": "Berechtigungen",
"b0fe16124082337a": "Berechtigungen wählen",
"8a3707795c8cbd54": "Modus",
"3345dbc93147b56c": "Plan erstellt einen Vorschlag, bevor gehandelt wird.",
"ac5d2d6d0215d5fc": "Plan ist für diesen Anbieter nicht verfügbar.",
"cb66aa6471c80179": "Umsetzen",
"a15816b54dc2fd14": "Plan",
"cbcf2f92931a93fd": "Läufe verwenden den Arbeitsbereich, die Berechtigungen und den Modus des Ziel-Threads.",
"872bf68b2e05f055": "{count, plural, one {{count} angesehene Datei ausgeblendet} other {{count} angesehene Dateien ausgeblendet}}",
"f538b8016f5ca2f3": "Angesehene Dateien ausblenden",
"be348514e8486295": "Noch keine nicht angesehenen Dateien geladen",
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5733,6 +5733,14 @@
"eb1fd384ad5919dd": "Internal note",
"b45f0b467e9406d0": "Reply to customer",
"15e5597f8f93ce12": "{start} to {end}",
"4aa91c06e3cc23d3": "Permissions",
"b0fe16124082337a": "Choose permissions",
"8a3707795c8cbd54": "Mode",
"3345dbc93147b56c": "Plan drafts a proposal before acting.",
"ac5d2d6d0215d5fc": "Plan is unavailable for this provider.",
"cb66aa6471c80179": "Build",
"a15816b54dc2fd14": "Plan",
"cbcf2f92931a93fd": "Runs use the destination thread's workspace, permissions, and mode.",
"872bf68b2e05f055": "{count, plural, one {{count} viewed file hidden} other {{count} viewed files hidden}}",
"f538b8016f5ca2f3": "Hide viewed files",
"be348514e8486295": "No unviewed files loaded yet",
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -5725,6 +5725,14 @@
"eb1fd384ad5919dd": "Nota interna",
"b45f0b467e9406d0": "Responder al cliente",
"15e5597f8f93ce12": "{start} a {end}",
"4aa91c06e3cc23d3": "Permisos",
"b0fe16124082337a": "Elegir permisos",
"8a3707795c8cbd54": "Modo",
"3345dbc93147b56c": "Plan redacta una propuesta antes de actuar.",
"ac5d2d6d0215d5fc": "Plan no está disponible para este proveedor.",
"cb66aa6471c80179": "Construir",
"a15816b54dc2fd14": "Plan",
"cbcf2f92931a93fd": "Las ejecuciones usan el espacio de trabajo, los permisos y el modo del hilo de destino.",
"872bf68b2e05f055": "{count, plural, one {{count} archivo visto oculto} other {{count} archivos vistos ocultos}}",
"f538b8016f5ca2f3": "Ocultar archivos vistos",
"be348514e8486295": "Aún no se han cargado archivos sin ver",
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -5725,6 +5725,14 @@
"eb1fd384ad5919dd": "Note interne",
"b45f0b467e9406d0": "Répondre au client",
"15e5597f8f93ce12": "{start} à {end}",
"4aa91c06e3cc23d3": "Autorisations",
"b0fe16124082337a": "Choisir les autorisations",
"8a3707795c8cbd54": "Mode",
"3345dbc93147b56c": "Plan rédige une proposition avant d'agir.",
"ac5d2d6d0215d5fc": "Plan n'est pas disponible pour ce fournisseur.",
"cb66aa6471c80179": "Construire",
"a15816b54dc2fd14": "Plan",
"cbcf2f92931a93fd": "Les exécutions utilisent l'espace de travail, les autorisations et le mode du fil de destination.",
"872bf68b2e05f055": "{count, plural, one {{count} fichier consulté masqué} other {{count} fichiers consultés masqués}}",
"f538b8016f5ca2f3": "Masquer les fichiers consultés",
"be348514e8486295": "Aucun fichier non consulté chargé pour l’instant",
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -5702,6 +5702,14 @@
"eb1fd384ad5919dd": "内部メモ",
"b45f0b467e9406d0": "顧客に返信",
"15e5597f8f93ce12": "{start}〜{end}",
"4aa91c06e3cc23d3": "権限",
"b0fe16124082337a": "権限を選択",
"8a3707795c8cbd54": "モード",
"3345dbc93147b56c": "プランは実行前に提案を作成します。",
"ac5d2d6d0215d5fc": "このプロバイダーではプランを使用できません。",
"cb66aa6471c80179": "ビルド",
"a15816b54dc2fd14": "プラン",
"cbcf2f92931a93fd": "実行には宛先スレッドのワークスペース、権限、モードが使われます。",
"872bf68b2e05f055": "{count, plural, other {{count} 個の確認済みファイルを非表示}}",
"f538b8016f5ca2f3": "確認済みファイルを非表示",
"be348514e8486295": "未確認のファイルはまだ読み込まれていません",
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -5709,6 +5709,14 @@
"eb1fd384ad5919dd": "내부 메모",
"b45f0b467e9406d0": "고객에게 답변",
"15e5597f8f93ce12": "{start}~{end}",
"4aa91c06e3cc23d3": "권한",
"b0fe16124082337a": "권한 선택",
"8a3707795c8cbd54": "모드",
"3345dbc93147b56c": "계획은 실행하기 전에 제안을 작성합니다.",
"ac5d2d6d0215d5fc": "이 공급자에서는 계획을 사용할 수 없습니다.",
"cb66aa6471c80179": "빌드",
"a15816b54dc2fd14": "계획",
"cbcf2f92931a93fd": "실행은 대상 스레드의 작업 공간, 권한, 모드를 사용합니다.",
"872bf68b2e05f055": "{count, plural, other {확인한 파일 {count}개 숨겨짐}}",
"f538b8016f5ca2f3": "확인한 파일 숨기기",
"be348514e8486295": "아직 불러온 미확인 파일이 없습니다",
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -5740,5 +5740,13 @@
"bd2cfcb7be24cd38": "Przejrzane pliki są ukryte w tym przeglądzie.",
"6ae1484aa5bd2bc8": "Pokaż przejrzane pliki",
"15db3431c35d4927": "{count, plural, one {Ukryto {count} przejrzany} few {Ukryto {count} przejrzane} many {Ukryto {count} przejrzanych} other {Ukryto {count} przejrzanego}}",
"4aa91c06e3cc23d3": "Uprawnienia",
"b0fe16124082337a": "Wybierz uprawnienia",
"8a3707795c8cbd54": "Tryb",
"3345dbc93147b56c": "Planowanie przygotowuje propozycję przed działaniem.",
"ac5d2d6d0215d5fc": "Planowanie jest niedostępne dla tego dostawcy.",
"cb66aa6471c80179": "Budowanie",
"a15816b54dc2fd14": "Planowanie",
"cbcf2f92931a93fd": "Uruchomienia korzystają z obszaru roboczego, uprawnień i trybu wątku docelowego.",
"2461bdd8e58e0a72": "Środowisk T3 Connect nie można tutaj zmienić nazwy."
}
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -5725,6 +5725,14 @@
"eb1fd384ad5919dd": "Nota interna",
"b45f0b467e9406d0": "Responder ao cliente",
"15e5597f8f93ce12": "{start} a {end}",
"4aa91c06e3cc23d3": "Permissões",
"b0fe16124082337a": "Escolher permissões",
"8a3707795c8cbd54": "Modo",
"3345dbc93147b56c": "Plano elabora uma proposta antes de agir.",
"ac5d2d6d0215d5fc": "Plano não está disponível para este provedor.",
"cb66aa6471c80179": "Construir",
"a15816b54dc2fd14": "Plano",
"cbcf2f92931a93fd": "As execuções usam o espaço de trabalho, as permissões e o modo da thread de destino.",
"872bf68b2e05f055": "{count, plural, one {{count} arquivo visto oculto} other {{count} arquivos vistos ocultos}}",
"f538b8016f5ca2f3": "Ocultar arquivos vistos",
"be348514e8486295": "Nenhum arquivo não visto carregado ainda",
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -5805,6 +5805,14 @@
"eb1fd384ad5919dd": "Внутренняя заметка",
"b45f0b467e9406d0": "Ответить клиенту",
"15e5597f8f93ce12": "{start}–{end}",
"4aa91c06e3cc23d3": "Разрешения",
"b0fe16124082337a": "Выберите разрешения",
"8a3707795c8cbd54": "Режим",
"3345dbc93147b56c": "План сначала составляет предложение, а затем действует.",
"ac5d2d6d0215d5fc": "План недоступен для этого провайдера.",
"cb66aa6471c80179": "Сборка",
"a15816b54dc2fd14": "План",
"cbcf2f92931a93fd": "Запуски используют рабочее пространство, разрешения и режим целевого треда.",
"872bf68b2e05f055": "{count, plural, one {{count} просмотренный файл скрыт} few {{count} просмотренных файла скрыто} many {{count} просмотренных файлов скрыто} other {{count} просмотренного файла скрыто}}",
"f538b8016f5ca2f3": "Скрыть просмотренные файлы",
"be348514e8486295": "Непросмотренные файлы ещё не загружены",
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -5731,6 +5731,14 @@
"eb1fd384ad5919dd": "Intern anteckning",
"b45f0b467e9406d0": "Svara kunden",
"15e5597f8f93ce12": "{start} till {end}",
"4aa91c06e3cc23d3": "Behörigheter",
"b0fe16124082337a": "Välj behörigheter",
"8a3707795c8cbd54": "Läge",
"3345dbc93147b56c": "Plan skriver ett förslag innan något görs.",
"ac5d2d6d0215d5fc": "Plan är inte tillgängligt för den här leverantören.",
"cb66aa6471c80179": "Bygg",
"a15816b54dc2fd14": "Plan",
"cbcf2f92931a93fd": "Körningar använder måltrådens arbetsyta, behörigheter och läge.",
"872bf68b2e05f055": "{count, plural, one {{count} visad fil dold} other {{count} visade filer dolda}}",
"f538b8016f5ca2f3": "Dölj visade filer",
"be348514e8486295": "Inga ovisade filer har lästs in än",
Expand Down
Loading
Loading