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
1 change: 1 addition & 0 deletions .github/workflows/17-check-mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'web/mobile/**'
- 'web/packages/**'
- 'web/entrypoint.sh'
- 'web/docker/**'
- 'web/package.json'
Expand Down
382 changes: 382 additions & 0 deletions docs/design/agenta-mobile/plans/2026-07-26-mobile-flows-lite.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hosting/docker-compose/ee/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ services:
command: sh -c 'echo "AGENTA_MOBILE_GATE=$${AGENTA_MOBILE_GATE:-false}" > /app/mobile/.env.development.local && pnpm dev-mobile'
# === STORAGE ============================================== #
volumes:
- ../../../web/packages:/app/packages
- ../../../web/mobile/src:/app/mobile/src
- ../../../web/mobile/public:/app/mobile/public
- nextjs-mobile-cache:/app/mobile/.next/cache
Expand Down
1 change: 1 addition & 0 deletions hosting/docker-compose/oss/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ services:
command: sh -c 'echo "AGENTA_MOBILE_GATE=$${AGENTA_MOBILE_GATE:-false}" > /app/mobile/.env.development.local && pnpm dev-mobile'
# === STORAGE ============================================== #
volumes:
- ../../../web/packages:/app/packages
- ../../../web/mobile/src:/app/mobile/src
- ../../../web/mobile/public:/app/mobile/public
- nextjs-mobile-cache:/app/mobile/.next/cache
Expand Down
3 changes: 3 additions & 0 deletions web/ee/docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ COPY packages/agenta-playground-ui/package.json ./packages/agenta-playground-ui/
COPY packages/agenta-annotation/package.json ./packages/agenta-annotation/
COPY packages/agenta-annotation-ui/package.json ./packages/agenta-annotation-ui/
COPY packages/agenta-sdk/package.json ./packages/agenta-sdk/
COPY packages/agenta-chat/package.json ./packages/agenta-chat/

# `agenta-api-client` runs `tsc` as a `prepare` lifecycle script during install.
# Its source (src/, tsconfig.json) must be present before `pnpm i` runs, so we
Expand Down Expand Up @@ -90,6 +91,8 @@ COPY --chown=agenta:agenta packages/agenta-annotation/src ./packages/agenta-anno
COPY --chown=agenta:agenta packages/agenta-annotation/tsconfig.json ./packages/agenta-annotation/
COPY --chown=agenta:agenta packages/agenta-annotation-ui/src ./packages/agenta-annotation-ui/src
COPY --chown=agenta:agenta packages/agenta-annotation-ui/tsconfig.json ./packages/agenta-annotation-ui/
COPY --chown=agenta:agenta packages/agenta-chat/src ./packages/agenta-chat/src
COPY --chown=agenta:agenta packages/agenta-chat/tsconfig.json ./packages/agenta-chat/

COPY --chown=agenta:agenta ee/src ./ee/src
COPY --chown=agenta:agenta ee/public ./ee/public
Expand Down
28 changes: 25 additions & 3 deletions web/mobile/docker/Dockerfile.gh
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,39 @@ COPY docker/run-turbo-build.sh /usr/local/bin/run-turbo-build.sh

RUN chmod +x /usr/local/bin/run-turbo-build.sh

# Manifests first (change less often than source). @agenta/mobile has no
# workspace package deps in WP1; add packages/*/package.json copies here when
# WP2+ introduces @agenta/* imports.
# Manifests first (change less often than source): the mobile app plus the
# @agenta/* workspace closure it links (chat → entities/playground/shared;
# entities → sdk/api-client/shared/ui) so `pnpm install` resolves the
# workspace: deps.
COPY mobile/package.json ./mobile/package.json
COPY packages/agenta-shared/package.json ./packages/agenta-shared/
COPY packages/agenta-ui/package.json ./packages/agenta-ui/
COPY packages/agenta-entities/package.json ./packages/agenta-entities/
COPY packages/agenta-playground/package.json ./packages/agenta-playground/
COPY packages/agenta-chat/package.json ./packages/agenta-chat/
COPY packages/agenta-sdk/package.json ./packages/agenta-sdk/

# `agenta-api-client` runs `tsc` as a `prepare` lifecycle script during
# install, so its full source must be present before `pnpm install` runs.
COPY packages/agenta-api-client/ ./packages/agenta-api-client/

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm fetch --frozen-lockfile

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --frozen-lockfile --offline

# Shared package config (required by the package tsconfigs), then the
# workspace package sources for the same closure.
COPY packages/tsconfig.base.json ./packages/
COPY packages/css-modules.d.ts ./packages/
COPY packages/agenta-shared/ ./packages/agenta-shared/
COPY packages/agenta-ui/ ./packages/agenta-ui/
COPY packages/agenta-entities/ ./packages/agenta-entities/
COPY packages/agenta-playground/ ./packages/agenta-playground/
COPY packages/agenta-chat/ ./packages/agenta-chat/
COPY packages/agenta-sdk/ ./packages/agenta-sdk/

COPY mobile/ ./mobile/

RUN --mount=type=cache,id=turbo-mobile,target=/app/.turbo \
Expand Down
12 changes: 12 additions & 0 deletions web/mobile/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ const nextConfig: NextConfig = {
// the app itself owns the prefix (assets, links, and routes all under /m).
basePath: "/m",
output: "standalone",
// Workspace packages ship TS source (main: ./src/index.ts) — Next must
// transpile the full dependency closure (chat → entities/playground/shared;
// entities → sdk/api-client/shared/ui). Same mechanism as web/oss.
transpilePackages: [
"@agenta/sdk",
"@agentaai/api-client",
"@agenta/shared",
"@agenta/ui",
"@agenta/entities",
"@agenta/playground",
"@agenta/chat",
],
reactStrictMode: true,
pageExtensions: ["ts", "tsx"],
productionBrowserSourceMaps: true,
Expand Down
12 changes: 11 additions & 1 deletion web/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@
"test:watch": "vitest"
},
"dependencies": {
"@agenta/chat": "workspace:../packages/agenta-chat",
"@agenta/entities": "workspace:../packages/agenta-entities",
"@agenta/sdk": "workspace:../packages/agenta-sdk",
"@agenta/shared": "workspace:../packages/agenta-shared",
"@ai-sdk/react": "3.0.0-beta.153",
"@tanstack/react-query": "^5.90.21",
"ai": "6.0.0-beta.150",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"jotai": "^2.16.1",
"jotai-tanstack-query": "^0.11.0",
"lucide-react": "^0.479.0",
"motion": "^12.0.0",
"next": "15.5.18",
"radix-ui": "^1.6.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tailwind-merge": "^3.3.1"
"tailwind-merge": "^3.3.1",
"zod": "^4.3.6"
},
"devDependencies": {
"@eslint/js": "^9.39.4",
Expand Down
33 changes: 33 additions & 0 deletions web/mobile/src/features/app/AppProviders.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type {PropsWithChildren} from "react"

import {configureAgentaSdk} from "@agenta/sdk/config"
import {QueryClientProvider} from "@tanstack/react-query"
import {Provider, getDefaultStore} from "jotai"
import {useHydrateAtoms} from "jotai/react/utils"
import {queryClientAtom} from "jotai-tanstack-query"

import {getApiUrl} from "@/lib/env"
import {queryClient} from "@/lib/queryClient"

import {ContextSync} from "./ContextSync"

// Module scope, like the desktop _app: __env.js is beforeInteractive, so
// window.__env is already populated when this module first evaluates.
configureAgentaSdk({host: getApiUrl()})

const HydrateAtoms = ({children}: PropsWithChildren) => {
useHydrateAtoms([[queryClientAtom, queryClient]])
return children
}

export const AppProviders = ({children}: PropsWithChildren) => (
<QueryClientProvider client={queryClient}>
{/* default store — @agenta/chat's loadSessionMessages writes through getDefaultStore() */}
<Provider store={getDefaultStore()}>
<HydrateAtoms>
<ContextSync />
{children}
</HydrateAtoms>
</Provider>
</QueryClientProvider>
)
30 changes: 30 additions & 0 deletions web/mobile/src/features/app/ContextSync.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {useEffect} from "react"

import {setProjectIdAtom} from "@agenta/shared/state"
import {useSetAtom} from "jotai"
import {useRouter} from "next/router"

import {writeLastContext} from "@/lib/context"

/** Null-rendering: mirrors route params into the shared state @agenta/entities reads. */
export const ContextSync = () => {
const router = useRouter()
const setProjectId = useSetAtom(setProjectIdAtom)

const {workspace_id, project_id} = router.query
const workspaceId = typeof workspace_id === "string" ? workspace_id : null
const projectId = typeof project_id === "string" ? project_id : null

useEffect(() => {
if (!router.isReady) return
setProjectId(projectId)
}, [router.isReady, projectId, setProjectId])

useEffect(() => {
if (workspaceId && projectId) {
writeLastContext({workspaceId, projectId})
}
}, [workspaceId, projectId])

return null
}
36 changes: 36 additions & 0 deletions web/mobile/src/features/chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {fetchSessionStream} from "@agenta/entities/session"
import {useQuery} from "@tanstack/react-query"
import Link from "next/link"

export const ChatHeader = ({
sessionId,
projectId,
workspaceId,
}: {
sessionId: string
projectId: string
workspaceId: string
}) => {
const query = useQuery({
queryKey: ["mobile", "session-stream", projectId, sessionId],
queryFn: () => fetchSessionStream({sessionId, projectId}),
enabled: Boolean(projectId && sessionId),
staleTime: 30_000,
})
return (
<header className="border-border flex flex-col gap-1 border-b p-4">
<div className="flex items-center gap-2">
<Link
href={`/w/${workspaceId}/p/${projectId}/sessions`}
className="text-muted-foreground shrink-0 text-xs underline underline-offset-4"
>
Back
</Link>
<h1 className="truncate text-sm font-semibold">{query.data?.name ?? "Session"}</h1>
</div>
<p className="text-muted-foreground text-xs">
Read-only on mobile for now — continue this session on desktop.
</p>
</header>
)
}
52 changes: 52 additions & 0 deletions web/mobile/src/features/chat/ChatScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {useMemo} from "react"

import {buildTurnViewModels, createExecutedToolIdentityCache} from "@agenta/chat/model"

import {ChatHeader} from "./ChatHeader"
import {ChatEmpty, ChatLoading} from "./states/ChatStates"
import {TurnRow} from "./TurnRow"
import {useSessionTranscript} from "./useSessionTranscript"

/** Read-only replay screen — mount it with `key={sessionId}` so per-session state resets. */
export const ChatScreen = ({
sessionId,
projectId,
workspaceId,
}: {
sessionId: string
projectId: string
workspaceId: string
}) => {
const {messages, state} = useSessionTranscript(sessionId)
// One identity cache per session mount (the screen is keyed by sessionId).
// eslint-disable-next-line react-hooks/exhaustive-deps
const executedFor = useMemo(() => createExecutedToolIdentityCache(), [sessionId])
const turns = useMemo(
() => buildTurnViewModels(messages, {busy: false, executedFor}),
[messages, executedFor],
)

let body
if (state === "loading") {
body = <ChatLoading />
} else if (state === "empty") {
body = <ChatEmpty />
} else {
body = (
<div className="flex grow flex-col gap-3 p-4">
{turns
.filter((turn) => !turn.hidden)
.map((turn) => (
<TurnRow key={turn.message.id} turn={turn} />
))}
</div>
)
}

return (
<div className="bg-background text-foreground flex min-h-dvh flex-col">
<ChatHeader sessionId={sessionId} projectId={projectId} workspaceId={workspaceId} />
{body}
</div>
)
}
58 changes: 58 additions & 0 deletions web/mobile/src/features/chat/TurnRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {partToolName, rowSummary, type TurnViewModel} from "@agenta/chat/model"

/** One transcript turn: raw aligned text parts, one-line tool summaries, raw error line. */
export const TurnRow = ({turn}: {turn: TurnViewModel}) => (
<div className={`flex ${turn.isUser ? "justify-end" : "justify-start"}`}>
<div
className={`flex max-w-[85%] flex-col gap-1 ${turn.isUser ? "items-end" : "items-start"}`}
>
{turn.items.map((item) => {
if (item.kind === "part") {
if (item.part.type === "text") {
return (
<p key={item.index} className="whitespace-pre-wrap text-xs">
{item.part.text}
</p>
)
}
if (item.part.type === "reasoning") {
return (
<p
key={item.index}
className="text-muted-foreground whitespace-pre-wrap text-xs italic"
>
{item.part.text}
</p>
)
}
return null
}
if (item.kind === "tools") {
return (
<div key={item.index} className="flex flex-col gap-0.5">
{item.parts.map((part, i) => {
const summary = rowSummary(part)
return (
<p
key={part.toolCallId ?? `${item.index}-${i}`}
className="text-muted-foreground text-xs"
>
{partToolName(part)} — {part.state ?? "pending"}
{summary ? ` · ${summary}` : ""}
</p>
)
})}
</div>
)
}
// clientTool never occurs — the predicate defaults to false on mobile.
return null
})}
{turn.status.showError ? (
<p className="text-destructive text-xs">
{turn.status.errorText ?? "Something went wrong."}
</p>
) : null}
</div>
</div>
)
12 changes: 12 additions & 0 deletions web/mobile/src/features/chat/states/ChatStates.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Raw one-liner states for the LITE phase (designed states come with the skin pass).

export const ChatLoading = () => (
<p className="text-muted-foreground grow p-6 text-center text-xs">Loading…</p>
)

/** Also covers history-unavailable — loadSessionMessages resolves null for both. */
export const ChatEmpty = () => (
<p className="text-muted-foreground grow p-6 text-center text-xs">
No messages here — this session has no replayable history.
</p>
)
36 changes: 36 additions & 0 deletions web/mobile/src/features/chat/useSessionTranscript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {useEffect, useState} from "react"

import {loadSessionMessages} from "@agenta/chat/assets"
import type {UIMessage} from "ai"

/**
* Read-only transcript for one session: server record replay via `loadSessionMessages`
* (IndexedDB-restored, revalidation re-delivered through `onRefreshed`). `null` history
* collapses into "empty" — raw text covers both no-messages and history-unavailable.
*/
export const useSessionTranscript = (sessionId: string) => {
const [messages, setMessages] = useState<UIMessage[]>([])
const [state, setState] = useState<"loading" | "ready" | "empty">("loading")
useEffect(() => {
let cancelled = false
let refreshed = false
setState("loading")
setMessages([])
void loadSessionMessages(sessionId, (fresh) => {
// Disk-restore revalidation re-delivery — fresh is non-empty by contract.
if (cancelled) return
refreshed = true
setMessages(fresh)
setState("ready")
}).then((msgs) => {
// A fast revalidation can beat this one-shot resolve; never clobber it.
if (cancelled || refreshed) return
setMessages(msgs ?? [])
setState(msgs && msgs.length > 0 ? "ready" : "empty")
})
return () => {
cancelled = true
}
}, [sessionId])
return {messages, state}
}
Comment on lines +11 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift

Use TanStack Query instead of manual useEffect fetching.

This hook fetches data with useEffect and manual useState tracking. Wrap loadSessionMessages in a useQuery/atomWithQuery call instead, and use the refresh callback to update the query cache (for example through queryClient.setQueryData). This restores native loading/error/retry semantics and keeps the hook consistent with the rest of the codebase.

As per coding guidelines: "Use atomWithQuery with TanStack Query for API data fetching ... Do not use useEffect with manual fetching or introduce SWR+axios for new features."

Source: Coding guidelines


🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Add error handling to the transcript load.

loadSessionMessages(...).then(...) has no .catch(). If the promise rejects, state stays "loading" indefinitely, and the rejection goes unhandled. The user sees an infinite spinner with no retry option on a transient failure.

Add an "error" state and a .catch() handler, and surface a retry action from ChatScreen.

🐛 Proposed fix
-    const [state, setState] = useState<"loading" | "ready" | "empty">("loading")
+    const [state, setState] = useState<"loading" | "ready" | "empty" | "error">("loading")
     useEffect(() => {
         let cancelled = false
         let refreshed = false
         setState("loading")
         setMessages([])
         void loadSessionMessages(sessionId, (fresh) => {
             if (cancelled) return
             refreshed = true
             setMessages(fresh)
             setState("ready")
         }).then((msgs) => {
             if (cancelled || refreshed) return
             setMessages(msgs ?? [])
             setState(msgs && msgs.length > 0 ? "ready" : "empty")
-        })
+        }).catch(() => {
+            if (cancelled || refreshed) return
+            setState("error")
+        })
         return () => {
             cancelled = true
         }
     }, [sessionId])

Loading
Loading