Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
130 changes: 72 additions & 58 deletions apps/mobile/app/assistant/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {
} from "../../src/assistant/new-chat-action";
import { RenameDialog } from "../../src/assistant/rename-dialog";
import { useThreadRunning } from "../../src/assistant/runs";
import {
ThreadSearchBox,
ThreadSearchResults,
useThreadSearch,
} from "../../src/assistant/thread-search";
import {
ActionButton,
EmptyState,
Expand Down Expand Up @@ -97,6 +102,7 @@ export default function AssistantThreadsScreen() {
const palette = usePalette();
const plain = usePlainBackground();
const threads = useAssistantThreads();
const search = useThreadSearch();
const ready = useAssistantReady();
const rename = useRenameThread();
const remove = useDeleteThread();
Expand Down Expand Up @@ -137,67 +143,75 @@ export default function AssistantThreadsScreen() {
}}
/>
<AssistantGate>
<FlatList
data={threads.data ?? []}
contentContainerStyle={{ paddingBottom: NEW_CHAT_CLEARANCE }}
keyExtractor={(thread) => thread.id}
contentInsetAdjustmentBehavior="automatic"
refreshControl={
<RefreshControl
refreshing={pull.refreshing}
onRefresh={pull.onRefresh}
colors={[String(palette.primary)]}
progressBackgroundColor={String(palette.surfaceContainerHigh)}
tintColor={palette.primary}
/>
}
ListHeaderComponent={
error ? (
<View style={{ padding: SPACE.l }}>
<ErrorBanner message={error} />
</View>
) : null
}
ListEmptyComponent={
threads.isPending ? (
<View style={{ paddingTop: SPACE.l }}>
<Inset>
<Skeleton height={56} />
<Skeleton height={56} />
<Skeleton height={56} />
</Inset>
</View>
) : threads.error ? (
<ErrorState
error={threads.error}
onRetry={() => void threads.refetch()}
<ThreadSearchBox search={search} />
{search.active ? (
<ThreadSearchResults query={search.query} />
) : (
<FlatList
data={threads.data ?? []}
contentContainerStyle={{ paddingBottom: NEW_CHAT_CLEARANCE }}
keyExtractor={(thread) => thread.id}
contentInsetAdjustmentBehavior="automatic"
refreshControl={
<RefreshControl
refreshing={pull.refreshing}
onRefresh={pull.onRefresh}
colors={[String(palette.primary)]}
progressBackgroundColor={String(palette.surfaceContainerHigh)}
tintColor={palette.primary}
/>
) : (
<EmptyState
icon="assistant"
title="No conversations yet"
message="Ask about your tracked time, or ask the assistant to log more of it. It shows you every change first."
action={
<ActionButton label="Start a conversation" onPress={start} />
}
ListHeaderComponent={
error ? (
<View style={{ padding: SPACE.l }}>
<ErrorBanner message={error} />
</View>
) : null
}
ListEmptyComponent={
threads.isPending ? (
<View style={{ paddingTop: SPACE.l }}>
<Inset>
<Skeleton height={56} />
<Skeleton height={56} />
<Skeleton height={56} />
</Inset>
</View>
) : threads.error ? (
<ErrorState
error={threads.error}
onRetry={() => void threads.refetch()}
/>
) : (
<EmptyState
icon="assistant"
title="No conversations yet"
message="Ask about your tracked time, or ask the assistant to log more of it. It shows you every change first."
action={
<ActionButton
label="Start a conversation"
onPress={start}
/>
}
/>
)
}
renderItem={({ item }) => (
<ThreadRow
thread={item}
now={now}
onOpen={() =>
router.push({
pathname: "/assistant/[id]",
params: { id: item.id },
})
}
onRename={() => setRenaming(item)}
onDelete={() => confirmDelete(item)}
/>
)
}
renderItem={({ item }) => (
<ThreadRow
thread={item}
now={now}
onOpen={() =>
router.push({
pathname: "/assistant/[id]",
params: { id: item.id },
})
}
onRename={() => setRenaming(item)}
onDelete={() => confirmDelete(item)}
/>
)}
/>
)}
/>
)}
</AssistantGate>
{/* No new chat while the gate above says why the assistant
cannot answer. */}
Expand Down
38 changes: 38 additions & 0 deletions apps/mobile/app/assistant/shared/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Stack, useLocalSearchParams } from "expo-router";

import { useWorkspace } from "../../../src/api/queries";
import { AssistantGate } from "../../../src/assistant/gate";
import { SharedChat } from "../../../src/assistant/shared-chat";
import { otherWorkspace } from "../../../src/assistant/shared-target";
import { EmptyState } from "../../../src/ui/components";

/** A chat that its owner shared with the workspace. Read only. */
function SharedChatOrMismatch({ id }: { id: string }) {
const { org, server } = useLocalSearchParams<{
org?: string;
server?: string;
}>();
const w = useWorkspace();
const other = otherWorkspace({ org, server }, w);
if (!other) return <SharedChat id={id} />;
return (
<EmptyState
icon="error"
tone="error"
title="This chat is in another workspace."
message={`Switch to ${other.org} on ${other.server}, then open the link again.`}
/>
);
}

export default function SharedConversationScreen() {
const { id } = useLocalSearchParams<{ id: string }>();
return (
<>
<Stack.Screen options={{ title: "Shared chat" }} />
<AssistantGate>
<SharedChatOrMismatch id={id ?? ""} />
</AssistantGate>
</>
);
}
4 changes: 2 additions & 2 deletions apps/mobile/app/workspace/assistant.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Redirect } from "expo-router";

/** The assistant's settings are a part of the workspace integrations, as on
* the web. This route stays for a link that points here. */
/** The assistant's settings are a part of the workspace integrations in the
* app. This route stays for a link that points here. */
export default function AssistantSettingsScreen() {
return <Redirect href="/workspace/integrations" />;
}
61 changes: 61 additions & 0 deletions apps/mobile/src/api/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,64 @@ export const useUpdateAssistantSettings = () =>

export const useDisconnectAssistant = () =>
useSettingsChange<void>((w) => w.client.disconnectAssistant(w.slug));

/** Undo one write from its trace row. A write can change anything the
* workspace shows, so the whole workspace is stale after it. */
export const useUndoWrite = () => {
const w = useWorkspace();
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, messageId }: { id: string; messageId: string }) =>
w.client.undoAssistantWrite(w.slug, id, messageId),
onSuccess: () => queryClient.invalidateQueries({ queryKey: scope(w) }),
});
};

/** Take back the last question. Answers with its text, to send again. */
export const useRewindThread = () => {
const w = useWorkspace();
const queryClient = useQueryClient();
return useMutation({
mutationFn: (id: string) => w.client.rewindAssistantThread(w.slug, id),
onSuccess: (_, id) =>
queryClient.invalidateQueries({ queryKey: threadKey(w, id) }),
});
};

/** The person's threads whose title or text match `q`. Off below two
* characters, as the server refuses them. */
export const useSearchThreads = (q: string) => {
const w = useWorkspace();
return useQuery({
queryKey: [...assistantKey(w), "search", q],
queryFn: () => w.client.searchAssistantThreads(w.slug, { q }),
enabled: q.length >= 2,
});
};

/** One thread that its owner shared. Read only. */
export const useSharedThread = (id: string) => {
const w = useWorkspace();
return useQuery({
queryKey: [...assistantKey(w), "shared", id],
queryFn: () => w.client.getSharedAssistantThread(w.slug, id),
retry: false,
});
};

/** Share a thread with the workspace, or stop sharing it. */
export const useSetThreadShared = () => {
const w = useWorkspace();
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, shared }: { id: string; shared: boolean }) =>
shared
? w.client.shareAssistantThread(w.slug, id)
: w.client.unshareAssistantThread(w.slug, id),
onSuccess: (_, { id }) =>
Promise.all([
queryClient.invalidateQueries({ queryKey: threadsKey(w) }),
queryClient.invalidateQueries({ queryKey: threadKey(w, id) }),
]),
});
};
Loading
Loading