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
4 changes: 4 additions & 0 deletions app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Redirect, Tabs } from "expo-router";
import { Icon } from "../../src/design/components";
import { useReducedMotion } from "../../src/design/motion";
import { C } from "../../src/design/tokens";
import { useApp } from "../../src/state/react";
export default function Layout() {
const { state } = useApp();
const reduced = useReducedMotion();
if (!state.device) return <Redirect href="/pair" />;
return (
<Tabs
screenOptions={{
headerShown: false,
animation: reduced ? "none" : "fade",
tabBarBadgeStyle: { backgroundColor: C.orange, color: C.canvas },
tabBarActiveTintColor: C.orange,
tabBarInactiveTintColor: C.muted,
tabBarStyle: {
Expand Down
23 changes: 16 additions & 7 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import { StatusBar } from "expo-status-bar";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { Text, View } from "react-native";
import { AppProvider } from "../src/state/react";
import { MotionProvider, useReducedMotion } from "../src/design/motion";
function Navigation() {
const reduced = useReducedMotion();
return (
<Stack
screenOptions={{
headerShown: false,
contentStyle: { backgroundColor: "#181817" },
animation: reduced ? "none" : "slide_from_right",
}}
/>
);
}
export default function Layout() {
const [loaded, error] = useFonts({
Inter: require("../assets/fonts/Inter.ttf"),
Expand All @@ -20,13 +33,9 @@ export default function Layout() {
</Text>
)}
<AppProvider>
<Stack
screenOptions={{
headerShown: false,
contentStyle: { backgroundColor: "#181817" },
animation: "none",
}}
/>
<MotionProvider>
<Navigation />
</MotionProvider>
</AppProvider>
</SafeAreaProvider>
);
Expand Down
13 changes: 11 additions & 2 deletions desktop-connector/src/desktop-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ const normalizedPermission = item => ({ ...item, action: item.permission, resour
export function desktopMessage(item) {
const info = item.info, parts = item.parts ?? []
const texts = parts.filter(p => p.type === 'text').map(p => ({id:p.id,type:'text',text:p.text ?? ''}))
const error = info.error?.data?.message ?? info.error?.message
if (error) texts.push({id:info.id + '_error',type:'text',text:`The computer reported: ${error}`})
if (info.role === 'assistant' && info.error) {
const status = Number(info.error.data?.statusCode)
const name = info.error.name
let reason = 'interrupted'
if (name === 'MessageAbortedError') reason = 'stopped'
else if (name === 'ContextOverflowError' || name === 'OutputLengthError' || name === 'MessageOutputLengthError') reason = 'length'
else if (name === 'ProviderAuthError' || status === 401 || status === 403) reason = 'access'
else if (status === 402) reason = 'billing'
else if (status === 429 || status === 529) reason = 'busy'
texts.push({id:info.id + '_error',type:'text',text:'The model did not finish this reply.',replyIssue:reason})
}
return {id:info.id,type:info.role,time:info.time,
...(info.role === 'user' ? {text:texts.map(p=>p.text).join('\n\n')} : {content:[...texts,...parts.filter(p=>p.type==='tool').map(p=>({id:p.id,type:'tool',name:p.tool,state:{...p.state,content:p.state?.output ? [{type:'text',text:p.state.output}] : []}}))]})}
}
Expand Down
12 changes: 11 additions & 1 deletion desktop-connector/test/desktop-api.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import assert from 'node:assert/strict'
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
import { createDesktopAPI } from '../src/desktop-api.mjs'
import { createDesktopAPI, desktopMessage } from '../src/desktop-api.mjs'

for (const created of [undefined, 999, 1000, Date.now() + 3_600_000]) {
test(`recovery fence blocks unknown old delivery across restart, created=${created}`, async t => {
Expand Down Expand Up @@ -204,3 +204,13 @@ test('confirmed mobile selections are consumed and a later Desktop choice wins',
await api.handle('POST','/api/session/ses_one/prompt',{id:'msg_second',prompt:{text:'Run'}})
assert.equal(prompts[0].model.modelID,'mobile_A');assert.equal(prompts[1].model.modelID,'desktop_B');assert.equal(prompts[1].agent,'plan')
})

test('partial replies keep their text and provider failures carry only an authored summary', () => {
const cases = [[402,'billing'],[403,'access'],[429,'busy'],[529,'busy'],[500,'interrupted']]
for (const [statusCode, reason] of cases) {
const reply = desktopMessage({info:{id:'m',role:'assistant',error:{name:'APIError',data:{statusCode,message:'private provider diagnostic'}}},parts:[{type:'text',id:'p',text:'partial reply'}]})
assert.equal(reply.content[0].text, 'partial reply')
assert.equal(reply.content.at(-1).replyIssue, reason)
assert.ok(!JSON.stringify(reply).includes('private provider diagnostic'))
}
})
41 changes: 41 additions & 0 deletions desktop-integration/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,45 @@ def edit(path, old, new):
edit("packages/app/src/components/settings-v2/dialog-settings-v2.tsx", 'import { SettingsMarketplace } from "../settings-marketplace"', 'import { SettingsMarketplace } from "../settings-marketplace"\nimport { SettingsMobile } from "../settings-mobile"')
edit("packages/app/src/components/settings-v2/dialog-settings-v2.tsx", ' <TabsV2.Trigger value="models">', ' <Show when={platform.mobileAccess}>\n <TabsV2.Trigger value="mobile">\n <Icon name="server" />\n {language.t("mobile.title")}\n </TabsV2.Trigger>\n </Show>\n <TabsV2.Trigger value="models">')
edit("packages/app/src/components/settings-v2/dialog-settings-v2.tsx", ' <TabsV2.Content value="models"', ' <Show when={platform.mobileAccess}>\n <TabsV2.Content value="mobile" class="settings-v2-panel">\n <SettingsMobile />\n </TabsV2.Content>\n </Show>\n <TabsV2.Content value="models"')
# Compose the Desktop layouts around the original timeline, request docks and composer.
for name in ("session-control-layout.tsx", "session-control.css"):
shutil.copyfile(ROOT / "desktop-integration" / name, TARGET / "packages/app/src/components" / name)
session = "packages/app/src/pages/session.tsx"
edit(session, 'import { usePlatform } from "@/context/platform"', 'import { usePlatform } from "@/context/platform"\nimport { SessionControlLayout } from "@/components/session-control-layout"')
edit(session, ' const wantsReview = createMemo(', ' const [mobileControl, setMobileControl] = createSignal(false)\n const wantsReview = createMemo(')
edit(session, 'const enabled = wantsReview() && sync().project?.vcs === "git"', 'const enabled = (wantsReview() || mobileControl()) && sync().project?.vcs === "git"')
edit(session, ' const sessionPanelContent = () => (\n <>', """ const sessionPanelContent = () => (
<SessionControlLayout
available={!!platform.mobileAccess && !!params.id && isDesktop()}
sessionKey={sessionKey()}
pending={!!composer.questionRequest() || !!composer.permissionRequest()}
onControlChange={setMobileControl}
changesTitle={reviewMode() === "git" ? language.t("mobile.session.changes") : language.t("session.review.change.other")}
changes={reviewDiffs()}
openFile={(file) => { tabs().setActive("review"); focusReviewDiff(file) }}
openChanges={() => { openReviewPanel(); tabs().setActive("review") }}
composer={(requestHost) => renderComposer(requestHost)}
>""")
edit(session, ' <Show when={(params.id || !newSessionDesign()) && !mobileChanges()}>', """ </SessionControlLayout>
)

const renderComposer = (requestHost?: HTMLElement) => (
<>
<Show when={(params.id || !newSessionDesign()) && !mobileChanges()}>""")
edit(session, ' <SessionComposerRegion\n controller={controller}', ' <SessionComposerRegion\n requestHost={requestHost}\n controller={controller}')
region = "packages/app/src/pages/session/composer/session-composer-region.tsx"
edit(region, 'import { Show, type JSX } from "solid-js"', 'import { Show, type JSX } from "solid-js"\nimport { Portal } from "solid-js/web"')
edit(region, ' controller: SessionComposerRegionController', ' requestHost?: HTMLElement\n controller: SessionComposerRegionController')
region_file = TARGET / region
region_source = region_file.read_text()
if "const requestDocks =" not in region_source:
start = region_source.index(" <Show when={controller.state.questionRequest()}")
end = region_source.index(" <Show when={controller.showComposer()}", start)
docks = region_source[start:end]
region_source = region_source[:start] + """ <Show when={props.requestHost} fallback={requestDocks()}>
{(host) => <Portal mount={host()}>{requestDocks()}</Portal>}
</Show>
""" + region_source[end:]
region_source = region_source.replace(" return (", " const requestDocks = () => (<>\n" + docks + " </>)\n\n return (", 1)
region_file.write_text(region_source)
print("Applied mobile connector, trusted IPC and Mobile devices settings to the pinned Desktop source.")
11 changes: 10 additions & 1 deletion desktop-integration/mobile-english.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const MOBILE_ENGLISH = {
"mobile.session.layout": "Session layout",
"mobile.session.chat": "Chat",
"mobile.session.control": "Desktop Control",
"mobile.session.activity": "Session activity",
"mobile.session.changes": "Working changes",
"mobile.status.off": "Remote access is off.",
"mobile.status.provisioning": "Preparing the secure tunnel. First-time certificate issuance can take a few minutes.",
"mobile.status.connected": "Secure tunnel connected.",
Expand Down Expand Up @@ -32,10 +37,14 @@ export const MOBILE_ENGLISH = {
"mobile.revoke": "Revoke access",
"mobile.revokeConfirm": "Revoke this phone’s access? It will need a new pairing code to reconnect.",
"mobile.scope": "Connects to the local Desktop runtime. WSL workspaces are not available on mobile yet.",
"mobile.error.title": "Mobile connection needs attention",
"mobile.error.check": "Check status",
"mobile.error.storage":
"Mobile-device storage is unavailable. Your existing device data has been kept. Check storage access and try again.",
"mobile.error.connection":
"The secure connection could not be established. Check your internet connection and retry.",
"mobile.error.reconnecting": "OpenTunnel is reconnecting. Keep BharatCode running.",
"mobile.error.action": "This mobile-device action could not be completed. Refresh and try again.",
"mobile.error.clipboard": "The pairing link couldn’t be copied. Scan the QR code with your phone instead.",
"mobile.error.status": "Couldn’t load mobile device status. Check again in a moment.",
"mobile.error.action": "Desktop hasn’t confirmed this action. Check the current device status before trying again.",
} as const
86 changes: 86 additions & 0 deletions desktop-integration/session-control-layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { For, Show, createEffect, createSignal, on, onCleanup, type JSX } from "solid-js"
import { useLanguage } from "@/context/language"
import "./session-control.css"

type ControlProps = {
available: boolean
sessionKey: string
onControlChange?: (open: boolean) => void
changesTitle?: string
pending: boolean
changes: readonly { file?: string; additions?: number; deletions?: number }[]
openFile: (file: string) => void
openChanges: () => void
children: JSX.Element
composer: (requestHost?: HTMLElement) => JSX.Element
}

// The existing request docks render into one stable host in both layouts.
// Moving the rail with CSS preserves typed answers, focus and the transcript.
export function SessionControlLayout(props: ControlProps) {
const language = useLanguage()
const [control, setControl] = createSignal(false)
createEffect(
on(
() => props.sessionKey,
() => setControl(false),
{ defer: true },
),
)
const host = document.createElement("div")
host.className = "bc-request-host"
const active = () => control() && props.available
createEffect(() => props.onControlChange?.(active()))
onCleanup(() => props.onControlChange?.(false))
const open = (file?: string) => {
setControl(false)
if (file) props.openFile(file)
else props.openChanges()
}
return (
<div class="bc-session-shell" data-control={active()} data-available={props.available}>
<Show when={props.available}>
<div class="bc-mode-bar" role="group" aria-label={language.t("mobile.session.layout")}>
<button type="button" aria-pressed={!control()} onClick={() => setControl(false)}>
{language.t("mobile.session.chat")}
</button>
<button type="button" aria-pressed={control()} onClick={() => setControl(true)}>
{language.t("mobile.session.control")}
</button>
</div>
</Show>
<div class="bc-transcript">{props.children}</div>
<aside
class="bc-session-rail"
aria-label={language.t("mobile.session.activity")}
hidden={!active() && !props.pending}
>
<Show when={active()}>
<h3>{language.t("mobile.session.activity")}</h3>
</Show>
{host}
<Show when={active()}>
<div class="bc-changes">
<button type="button" class="bc-review-link" onClick={() => open()}>
{props.changesTitle ?? language.t("mobile.session.changes")} <span aria-hidden="true">›</span>
</button>
<For each={props.changes.filter((change) => !!change.file).slice(0, 5)}>
{(change) => (
<button type="button" onClick={() => open(change.file)} class="bc-file-row">
<span>{change.file}</span>
<Show when={change.additions != null}>
<small class="bc-added">+{change.additions}</small>
</Show>
<Show when={change.deletions != null}>
<small class="bc-removed">−{change.deletions}</small>
</Show>
</button>
)}
</For>
</div>
</Show>
</aside>
<div class="bc-composer">{props.composer(host)}</div>
</div>
)
}
Loading