Skip to content

Commit cc6c5ad

Browse files
Merge remote-tracking branch 'origin/main' into t3code/relay-cors-errors
# Conflicts: # infra/relay/src/http/Api.ts
2 parents 93fddb3 + fc4ecc8 commit cc6c5ad

231 files changed

Lines changed: 19759 additions & 1162 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/marketing/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@t3tools/shared": "workspace:*",
15-
"astro": "^7.2.8",
15+
"astro": "^7.3.5",
1616
"sharp": "0.35.4"
1717
},
1818
"devDependencies": {

‎apps/mobile/src/features/files/AttachmentFileScreen.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { FileMarkdownPreview } from "./FileMarkdownPreview";
2424
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
2525
import { SourceFileSurface } from "./SourceFileSurface";
2626
import { WorkspaceFileWebPreview } from "./WorkspaceFileWebPreview";
27+
import { HtmlRenderWebView } from "../threads/HtmlRenderWebView";
2728

2829
/**
2930
* Both the thread stack and the new-task sheet stack register this screen, so a chip in a
@@ -38,6 +39,8 @@ export type AttachmentFileRouteParams = {
3839
readonly sizeBytes: string;
3940
/** Present for a draft attachment, which may still live only on this device. */
4041
readonly draftKey?: string;
42+
/** Present for a page an agent published with `html_render`, which takes the app theme. */
43+
readonly htmlRender?: "1";
4144
};
4245

4346
type AttachmentFileScreenProps = StaticScreenProps<AttachmentFileRouteParams>;
@@ -54,6 +57,7 @@ function AttachmentDocumentBody(props: {
5457
readonly document: ReturnType<typeof useAttachmentDocument>;
5558
readonly name: string;
5659
readonly environmentId: EnvironmentId | null;
60+
readonly htmlRender: boolean;
5761
readonly nativeViewer: "pending" | "open" | "unavailable" | null;
5862
readonly nativeError: string | null;
5963
readonly onOpenNative: () => void;
@@ -141,7 +145,11 @@ function AttachmentDocumentBody(props: {
141145
return <AudioFilePreview key={document.revision} uri={document.uri} onRetry={document.retry} />;
142146
}
143147
if (document.kind === "html") {
144-
return <WorkspaceFileWebPreview uri={document.uri} />;
148+
return props.htmlRender ? (
149+
<HtmlRenderWebView key={document.uri} uri={document.uri} title={props.name} nested={false} />
150+
) : (
151+
<WorkspaceFileWebPreview uri={document.uri} />
152+
);
145153
}
146154
return (
147155
<View className="flex-1 items-center justify-center bg-sheet px-6">
@@ -339,7 +347,7 @@ export function AttachmentFileScreen(props: AttachmentFileScreenProps) {
339347
},
340348
[menuActions],
341349
);
342-
const subtitle = `${draftKey ? "Draft attachment" : "Attachment"} · ${formatAttachmentSize(sizeBytes)}`;
350+
const subtitle = `${draftKey ? "Draft attachment" : "Attachment"}${sizeBytes > 0 ? ` · ${formatAttachmentSize(sizeBytes)}` : ""}`;
343351

344352
return (
345353
<View className="flex-1 bg-sheet">
@@ -405,6 +413,7 @@ export function AttachmentFileScreen(props: AttachmentFileScreenProps) {
405413
document={document}
406414
name={params.name}
407415
environmentId={environmentId}
416+
htmlRender={params.htmlRender === "1"}
408417
nativeViewer={nativeViewer}
409418
nativeError={nativeError}
410419
onOpenNative={() => {

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

Lines changed: 163 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ import type {
44
ScheduledTask,
55
ScheduledTaskUpsertInput,
66
} from "@t3tools/contracts";
7-
import { resolveEnvironmentMachineKind } from "@t3tools/contracts";
7+
import {
8+
MAX_WEBHOOK_DELIVERY_AGE_MINUTES,
9+
resolveEnvironmentMachineKind,
10+
} from "@t3tools/contracts";
811
import type { MenuAction } from "@react-native-menu/menu";
912
import { DateTimePicker } from "@expo/ui/community/datetime-picker";
1013
import {
1114
isAtomCommandInterrupted,
1215
squashAtomCommandFailure,
1316
type AtomCommandResult,
1417
} from "@t3tools/client-runtime/state/runtime";
18+
import {
19+
DEFAULT_WEBHOOK_PROMPT,
20+
parseMaxDeliveryAge,
21+
} from "@t3tools/client-runtime/scheduled-task-webhook";
1522
import {
1623
useCallback,
1724
useEffect,
@@ -37,6 +44,9 @@ import type { ComposerEditorSelection } from "../../components/ComposerEditor";
3744
import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
3845
import { SegmentedControl } from "../../components/SegmentedControl";
3946
import { ThemedSwitch } from "../../components/ThemedSwitch";
47+
import { webhookAddress } from "@t3tools/client-runtime/webhook-address";
48+
import { tryCopyTextWithHaptic } from "../../lib/copyTextWithHaptic";
49+
import { usePreparedConnection } from "../../state/session";
4050
import { buildModelOptions } from "../../lib/modelOptions";
4151
import { NativeStackScreenOptions } from "../../native/StackHeader";
4252
import { useProjects, useEnvironmentServerConfig } from "../../state/entities";
@@ -87,6 +97,7 @@ const DAYS = [
8797
] as const;
8898

8999
function describeSchedule(task: ScheduledTask): string {
100+
if (task.schedule.type === "webhook") return "On webhook";
90101
if (task.schedule.type === "interval") return formatScheduledTaskInterval(task.schedule.everyMs);
91102
const days = task.schedule.weekdays?.length ? repeatLabel(task.schedule.weekdays) : "Every day";
92103
return `${days} at ${formatTime(task.schedule.timeOfDay)}`;
@@ -127,7 +138,7 @@ function FormField(props: {
127138
readonly label: string;
128139
readonly value: string;
129140
readonly onChange: (value: string) => void;
130-
readonly keyboardType?: "decimal-pad";
141+
readonly keyboardType?: "decimal-pad" | "number-pad";
131142
readonly disabled?: boolean;
132143
readonly placeholder?: string;
133144
readonly borderTop?: boolean;
@@ -598,7 +609,24 @@ function TaskForm({
598609
environmentUnavailable
599610
)
600611
return;
601-
const schedule = scheduleFromDraft(draft.schedule);
612+
// Signatures are edited on desktop and web; send the task's current one,
613+
// not the copy taken when this form opened, so a newer edit survives.
614+
const liveTask = tasks.data?.tasks.find((task) => task.id === draft.task?.id);
615+
const schedule = scheduleFromDraft(
616+
draft.schedule.mode === "webhook" && liveTask?.schedule.type === "webhook"
617+
? { ...draft.schedule, signature: liveTask.schedule.signature }
618+
: draft.schedule,
619+
);
620+
if (
621+
draft.schedule.mode === "webhook" &&
622+
parseMaxDeliveryAge(draft.schedule.maxDeliveryAgeMinutes) === undefined
623+
) {
624+
Alert.alert(
625+
"Invalid age limit",
626+
`Enter whole minutes from 1 to ${MAX_WEBHOOK_DELIVERY_AGE_MINUTES}, or leave it blank.`,
627+
);
628+
return;
629+
}
602630
if (
603631
!draft.title.trim() ||
604632
!draft.prompt.trim() ||
@@ -810,12 +838,20 @@ function TaskForm({
810838
<SegmentedControl
811839
options={[
812840
{ value: "fixed_time", label: "At a time" },
813-
{ value: "interval", label: "Every interval" },
841+
{ value: "interval", label: "Interval" },
842+
{ value: "webhook", label: "On webhook" },
814843
]}
815844
selected={draft.schedule.mode}
816845
onSelect={(mode) => {
817846
setTimePickerOpen(false);
818-
setDraft({ ...draft, schedule: { ...draft.schedule, mode } });
847+
setDraft({
848+
...draft,
849+
prompt:
850+
mode === "webhook" && !draft.prompt.trim()
851+
? DEFAULT_WEBHOOK_PROMPT
852+
: draft.prompt,
853+
schedule: { ...draft.schedule, mode },
854+
});
819855
}}
820856
/>
821857
</View>
@@ -889,6 +925,32 @@ function TaskForm({
889925
}}
890926
/>
891927
</>
928+
) : draft.schedule.mode === "webhook" ? (
929+
<>
930+
<WebhookScheduleDetails
931+
environmentId={environmentId}
932+
// The live row, so a rotated URL shows up without reopening the form.
933+
// Once the list has loaded, a missing task is gone; don't keep showing its URL.
934+
task={
935+
tasks.data
936+
? (tasks.data.tasks.find((task) => task.id === draft.task?.id) ?? null)
937+
: draft.task
938+
}
939+
signatureConfigured={draft.schedule.signature !== null}
940+
disabled={saving || environmentUnavailable}
941+
/>
942+
<FormField
943+
label="Skip requests older than (minutes)"
944+
value={draft.schedule.maxDeliveryAgeMinutes}
945+
placeholder="Run every request"
946+
keyboardType="number-pad"
947+
disabled={saving}
948+
borderTop
949+
onChange={(maxDeliveryAgeMinutes) =>
950+
setDraft({ ...draft, schedule: { ...draft.schedule, maxDeliveryAgeMinutes } })
951+
}
952+
/>
953+
</>
892954
) : (
893955
<>
894956
<FormField
@@ -944,6 +1006,100 @@ function TaskForm({
9441006
);
9451007
}
9461008

1009+
function WebhookScheduleDetails({
1010+
environmentId,
1011+
task,
1012+
signatureConfigured,
1013+
disabled,
1014+
}: {
1015+
readonly environmentId: EnvironmentId;
1016+
readonly task: ScheduledTask | null;
1017+
readonly signatureConfigured: boolean;
1018+
readonly disabled: boolean;
1019+
}) {
1020+
const [rotating, setRotating] = useState(false);
1021+
const rotate = useAtomCommand(serverEnvironment.rotateScheduledTaskWebhookToken, {
1022+
label: "scheduled task rotate webhook token",
1023+
reportFailure: false,
1024+
});
1025+
const preparedConnection = usePreparedConnection(environmentId);
1026+
const httpBaseUrl =
1027+
preparedConnection._tag === "Some" ? preparedConnection.value.httpBaseUrl : null;
1028+
const webhook = task?.schedule.type === "webhook" ? task.webhook : undefined;
1029+
// Without T3 Connect, the path is resolved on the address this phone uses.
1030+
const resolved = webhook ? webhookAddress(webhook, httpBaseUrl) : null;
1031+
return (
1032+
<View className="gap-2 border-t border-border-subtle px-4 py-3">
1033+
<Text className="text-sm text-foreground-muted">
1034+
{
1035+
"The prompt can use {{body.a.b}}, {{headers.name}}, {{query.name}}, {{body}} and {{request}}. The filled-in prompt is all the agent sees."
1036+
}
1037+
</Text>
1038+
{task === null || resolved === null ? (
1039+
<Text className="text-sm text-foreground-muted">Save the task to get its webhook URL.</Text>
1040+
) : (
1041+
<>
1042+
<Pressable
1043+
accessibilityRole="button"
1044+
accessibilityLabel="Copy webhook URL"
1045+
accessibilityHint="Copies the URL to the clipboard"
1046+
// A bare path is not something a sender can call, so only full URLs copy.
1047+
disabled={!resolved.copyable}
1048+
onPress={() => void tryCopyTextWithHaptic(resolved.address)}
1049+
className="gap-1 active:opacity-70"
1050+
>
1051+
<Text className="text-lg text-foreground">
1052+
{resolved.copyable ? "Webhook URL" : "Webhook path"}
1053+
</Text>
1054+
<Text className="text-sm text-foreground-muted" numberOfLines={2} selectable>
1055+
{resolved.address}
1056+
</Text>
1057+
</Pressable>
1058+
{resolved.note !== null ? (
1059+
<Text className="text-sm text-foreground-muted">{resolved.note}</Text>
1060+
) : null}
1061+
<Pressable
1062+
accessibilityRole="button"
1063+
accessibilityState={{ disabled: disabled || rotating }}
1064+
disabled={disabled || rotating}
1065+
onPress={() =>
1066+
Alert.alert("Rotate URL?", "The current URL stops working immediately.", [
1067+
{ text: "Cancel", style: "cancel" },
1068+
{
1069+
text: "Rotate",
1070+
style: "destructive",
1071+
onPress: () => {
1072+
setRotating(true);
1073+
void rotate({ environmentId, input: { id: task.id } }).then((result) => {
1074+
setRotating(false);
1075+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
1076+
Alert.alert(
1077+
"Could not rotate URL",
1078+
String(squashAtomCommandFailure(result)),
1079+
);
1080+
}
1081+
});
1082+
},
1083+
},
1084+
])
1085+
}
1086+
className="min-h-11 justify-center active:opacity-70 disabled:opacity-50"
1087+
>
1088+
<Text className="text-base text-danger-foreground">
1089+
{rotating ? "Rotating…" : "Rotate URL"}
1090+
</Text>
1091+
</Pressable>
1092+
</>
1093+
)}
1094+
{signatureConfigured ? (
1095+
<Text className="text-sm text-foreground-muted">
1096+
Signature check configured on desktop/web.
1097+
</Text>
1098+
) : null}
1099+
</View>
1100+
);
1101+
}
1102+
9471103
function EnvironmentTasks({
9481104
environment,
9491105
now,
@@ -1050,7 +1206,8 @@ function EnvironmentTasks({
10501206
actions={[
10511207
{ id: "edit", title: "Edit" },
10521208
{ id: "toggle", title: task.enabled ? "Pause" : "Resume" },
1053-
{ id: "run", title: "Run now" },
1209+
// A webhook task has no request to run without.
1210+
...(task.schedule.type === "webhook" ? [] : [{ id: "run", title: "Run now" }]),
10541211
{ id: "delete", title: "Delete", attributes: { destructive: true } },
10551212
]}
10561213
onPressAction={({ nativeEvent }) => {

‎apps/mobile/src/features/settings/components/BranchNamingSettings.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function BranchNamingSettings(props: {
4848
{props.mode === "static" ? (
4949
<View className="gap-2 px-4 py-3">
5050
<Text className="text-sm text-foreground-muted">
51-
Use t3code or t3code/ for t3code/add-search. Leave empty for no prefix.
51+
Use t3 or t3/ for t3/add-search. Leave empty for no prefix.
5252
</Text>
5353
<AppTextInput
5454
key={props.prefix}

‎apps/mobile/src/features/settings/scheduledTaskDraft.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,43 @@ describe("scheduleDraftForTask", () => {
2828
const schedule = { type: "interval" as const, everyMs: 65_000 };
2929
expect(scheduleFromDraft(scheduleDraftForTask({ schedule }))).toEqual(schedule);
3030
});
31+
32+
it("round-trips a webhook schedule without a signature", () => {
33+
const draft = scheduleDraftForTask({ schedule: { type: "webhook", signature: null } });
34+
expect(draft.mode).toBe("webhook");
35+
expect(scheduleFromDraft(draft)).toEqual({
36+
type: "webhook",
37+
signature: null,
38+
maxDeliveryAgeMinutes: null,
39+
});
40+
});
41+
42+
it("round-trips a webhook max age and treats blank input as no limit", () => {
43+
const draft = scheduleDraftForTask({
44+
schedule: { type: "webhook", signature: null, maxDeliveryAgeMinutes: 45 },
45+
});
46+
expect(draft.maxDeliveryAgeMinutes).toBe("45");
47+
expect(scheduleFromDraft(draft)).toMatchObject({ maxDeliveryAgeMinutes: 45 });
48+
// An invalid limit is an invalid schedule, never a silently removed one.
49+
expect(scheduleFromDraft({ ...draft, maxDeliveryAgeMinutes: "1.5" })).toBeNull();
50+
expect(scheduleFromDraft({ ...draft, maxDeliveryAgeMinutes: "0" })).toBeNull();
51+
expect(scheduleFromDraft({ ...draft, maxDeliveryAgeMinutes: "" })).toMatchObject({
52+
maxDeliveryAgeMinutes: null,
53+
});
54+
});
55+
56+
it("keeps a webhook signature on save without sending a secret", () => {
57+
const signature = {
58+
header: "x-hub-signature-256",
59+
encoding: "hex" as const,
60+
prefix: "sha256=",
61+
};
62+
const saved = scheduleFromDraft(
63+
scheduleDraftForTask({ schedule: { type: "webhook", signature } }),
64+
);
65+
expect(saved).toEqual({ type: "webhook", signature, maxDeliveryAgeMinutes: null });
66+
expect(saved?.type === "webhook" && saved.signature && "secret" in saved.signature).toBe(false);
67+
});
3168
});
3269

3370
describe("hasScheduledTaskDraftChanges", () => {

0 commit comments

Comments
 (0)