Skip to content
Merged
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
14 changes: 14 additions & 0 deletions LLM.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,20 @@ from the page's origin and `useClient` posts the credential calls there. hanzo.a
and hanzo.market (`src/choose.tsx`, `src/menu.tsx`) are the two callers; the bar's
own menu (Header.tsx) and the Accounts section keep their markup.

## Dev on Hanzo Desktop: This computer, and a site to redesign

`dev.tsx` hands @hanzo/build's Dev what only the desktop window has, as `Host.local` and `Host.site`; a browser
page gets neither (`isTauri()` is false), and Dev offers the cloud workspace and the org's machines only.

- `lib/local-fs.ts` `desktopLocal()`: the folders the window opened, its folder dialog, and a run of the `dev` agent
in one folder (`local_workspace_run_dev`).
- `lib/local-site.ts` `desktopSite()` (hanzo-inc/app issue 312): opening a site from the computer's own connection and
saving a copy of it into a folder for the agent (`local_site_capture`: the page, its words, its stylesheets, a picture
when a paired browser can take one), naming a new folder under Documents/Hanzo (`local_site_folder`), serving the
folder's `redesign/` live with reload on every file change (`local_preview_start`, `local_preview_stop`) and showing
it in Chrome (`local_preview_open`, which opens only a preview the window is serving). What the desktop refuses (a
private-network address, a site that will not answer) comes back in plain words and is shown as it comes.

## Build and ship

The repository is a pnpm workspace of the packages it publishes, each under
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hanzo/app",
"version": "0.3.112",
"version": "0.3.113",
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
"type": "module",
"main": "./dist/index.js",
Expand Down Expand Up @@ -59,7 +59,7 @@
"peerDependencies": {
"@hanzo/ai": ">=0.7.0",
"@hanzo/appearance": ">=0.2.15",
"@hanzo/build": ">=0.2.136",
"@hanzo/build": ">=0.2.138",
"@hanzo/composer": ">=0.2.0",
"@hanzo/design": ">=0.5.39",
"@hanzo/event": ">=0.3.63",
Expand Down
6 changes: 5 additions & 1 deletion pkg/app/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { app, place, settings, visit } from './lib/host'
import { link } from './lib/tags'
import { payUrl, topUp } from './lib/pay'
import { desktopLocal } from './lib/local-fs'
import { desktopSite } from './lib/local-site'

/** Where the builder links out: every one of them an address of this site. */
const LINKS: Host['links'] = {
Expand Down Expand Up @@ -102,6 +103,8 @@ export function useDevHost(): Host {
const signedIn = Boolean(accessToken || bearer() || u)
// Hanzo Desktop's folders, so Dev offers This computer (hanzo-inc/app issues 309 and 310); none in a browser.
const local = useMemo(() => desktopLocal(), [])
// The same window opens a site, saves a copy for the agent and serves its redesign live (hanzo-inc/app issue 312).
const site = useMemo(() => desktopSite(), [])

return useMemo<Host>(
() => ({
Expand Down Expand Up @@ -155,7 +158,8 @@ export function useDevHost(): Host {
signIn: () => enter(),
signOut: () => void logout(),
...(local ? { local } : {}),
...(site ? { site } : {}),
}),
[scoped, memberships, look.pref.theme, look.set, signedIn, name, email, avatar, here, router, logout, local],
[scoped, memberships, look.pref.theme, look.set, signedIn, name, email, avatar, here, router, logout, local, site],
)
}
64 changes: 64 additions & 0 deletions pkg/app/src/lib/local-site.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { afterEach, describe, expect, it, vi } from 'vitest'

import { desktopSite } from './local-site'

/** A window with Hanzo Desktop's IPC (`invoke`), as the desktop's webview has. */
function desktop(invoke: (cmd: string, args?: Record<string, unknown>) => Promise<unknown>) {
;(globalThis as Record<string, unknown>).window = { __TAURI_INTERNALS__: { invoke } }
}

afterEach(() => {
delete (globalThis as Record<string, unknown>).window
})

describe('Redesigning a site on Hanzo Desktop (hanzo-inc/app issue 312)', () => {
it('is nothing in a browser page, which cannot open a site for the agent', () => {
;(globalThis as Record<string, unknown>).window = {}
expect(desktopSite()).toBeNull()
})

it('names the folder, saves the site into it, serves its redesign and shows it, each through the desktop’s own command', async () => {
const invoke = vi.fn(async (cmd: string) => {
switch (cmd) {
case 'local_site_folder':
return { name: 'acme-redesign', path: '/Users/me/Documents/Hanzo/acme-redesign' }
case 'local_site_capture':
return { title: 'Acme', url: 'https://acme.test/', files: ['page.html', 'text.md'], screenshot: false }
case 'local_preview_start':
return { url: 'http://127.0.0.1:9933/', port: 9933 }
default:
return null
}
})
desktop(invoke)
const site = desktopSite()!
await expect(site.folder('acme-redesign')).resolves.toEqual({ name: 'acme-redesign', path: '/Users/me/Documents/Hanzo/acme-redesign' })
await expect(site.capture('https://acme.test', '/Users/me/Documents/Hanzo/acme-redesign')).resolves.toEqual({
title: 'Acme',
url: 'https://acme.test/',
files: ['page.html', 'text.md'],
screenshot: false,
})
await expect(site.preview('/Users/me/Documents/Hanzo/acme-redesign')).resolves.toEqual({ url: 'http://127.0.0.1:9933/' })
await site.show('http://127.0.0.1:9933/')
await site.stop('/Users/me/Documents/Hanzo/acme-redesign')
expect(invoke.mock.calls).toEqual([
['local_site_folder', { name: 'acme-redesign' }],
['local_site_capture', { url: 'https://acme.test', dir: '/Users/me/Documents/Hanzo/acme-redesign' }],
['local_preview_start', { dir: '/Users/me/Documents/Hanzo/acme-redesign' }],
['local_preview_open', { url: 'http://127.0.0.1:9933/' }],
['local_preview_stop', { dir: '/Users/me/Documents/Hanzo/acme-redesign' }],
])
})

it('says what the desktop refused in its own words, whether it rejects with text or an Error', async () => {
desktop(async () => {
throw 'The site took too long to answer.'
})
await expect(desktopSite()!.capture('https://slow.test', '/x')).rejects.toThrow('The site took too long to answer.')
desktop(async () => {
throw new Error('That preview is not running any more.')
})
await expect(desktopSite()!.show('http://127.0.0.1:1/')).rejects.toThrow('That preview is not running any more.')
})
})
71 changes: 71 additions & 0 deletions pkg/app/src/lib/local-site.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Redesigning a site on Hanzo Desktop (hanzo-inc/app issue 312, hanzoai/desktop issue 15).
*
* `desktopSite()` is @hanzo/build's `Site` (`Host.site`) over the desktop's own commands: the window opens the
* site from the computer's connection and saves a copy into a folder (`local_site_capture`), serves the folder's
* `redesign/` live on this computer (`local_preview_start`) and shows it in Chrome (`local_preview_open`). A browser
* page has no such commands, so it gets none and Dev offers nothing of it. The agent runs through `desktopLocal()`.
*
* What the desktop refuses it says in plain words (an address on a private network, a site that will not answer), and
* those words are what a person reads: they are passed up as the error's own message.
*/
import type { Site } from '@hanzo/build'

import { isTauri } from './local-fs'

/** Invoke a desktop command; a refusal is its plain words, as an Error. */
async function command<T>(name: string, args?: Record<string, unknown>): Promise<T> {
const win = window as unknown as { __TAURI_INTERNALS__?: { invoke: (cmd: string, args?: Record<string, unknown>) => Promise<T> } }
const invoke = win.__TAURI_INTERNALS__?.invoke
if (!invoke) throw new Error('Hanzo Desktop is not running.')
try {
return await invoke(name, args)
} catch (e) {
throw e instanceof Error ? e : new Error(typeof e === 'string' ? e : 'Hanzo Desktop could not do that.')
}
}

/** What `local_site_folder` answers: the folder's name and path. */
interface SiteFolder {
name: string
path: string
}

/** What `local_site_capture` answers. */
interface SiteSaved {
title: string
url: string
files: string[]
screenshot: boolean
}

/** What `local_preview_start` answers. */
interface Live {
url: string
port: number
}

/** Hanzo Desktop's way of redesigning a site, or null outside its window. */
export function desktopSite(): Site | null {
if (!isTauri()) return null
return {
folder: async (name) => {
const made = await command<SiteFolder>('local_site_folder', { name })
return { path: made.path, name: made.name }
},
capture: async (url, folder) => {
const saved = await command<SiteSaved>('local_site_capture', { url, dir: folder })
return { title: saved.title, url: saved.url, files: saved.files, screenshot: saved.screenshot }
},
preview: async (folder) => {
const live = await command<Live>('local_preview_start', { dir: folder })
return { url: live.url }
},
stop: async (folder) => {
await command<null>('local_preview_stop', { dir: folder })
},
show: async (url) => {
await command<null>('local_preview_open', { url })
},
}
}
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ minimumReleaseAge: 0
catalog:
'@hanzo/ai': 0.7.0
'@hanzo/appearance': 0.2.15
'@hanzo/build': 0.2.136
'@hanzo/build': 0.2.138
'@hanzo/composer': 0.2.0
'@hanzo/design': 0.5.39
'@hanzo/event': 0.3.67
Expand Down
Loading