@hanzo/app 0.3.53 → 0.3.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Home.js CHANGED
@@ -30,6 +30,8 @@ import { useAi } from './lib/ai.js';
30
30
  import { useHydrated } from './lib/hydrated.js';
31
31
  import { useOpen } from './open.js';
32
32
  import { plainly, say } from './failure.js';
33
+ import { failed } from './failed.js';
34
+ import { watch } from './watch.js';
33
35
  import { Directory } from './Directory.js';
34
36
  import { Bar } from './progress.js';
35
37
  import { Card, Go, INK, Quiet, Row, SOFT, CHOSEN } from './card.js';
@@ -249,7 +251,7 @@ function Chats() {
249
251
  */
250
252
  function Next({ onConnect }) {
251
253
  const { t } = useI18n();
252
- const { sessions } = useSessions({ limit: 100 });
254
+ const { sessions, error: unread, reload } = useSessions({ limit: 100 });
253
255
  const { agents } = useAgents();
254
256
  const { held } = useProjects();
255
257
  const { held: connected } = useApps();
@@ -258,18 +260,25 @@ function Next({ onConnect }) {
258
260
  const running = useMemo(() => safeSessions.filter((s) => s && s.status === 'running'), [safeSessions]);
259
261
  const rows = useMemo(() => {
260
262
  const out = [];
261
- const failed = safeSessions.filter((s) => s && s.status === 'error').length;
262
- if (failed)
263
- out.push({ key: 'failed', say: t('{n} failed', { n: failed }), href: '/work' });
263
+ // The past 7 days' failures, a tree counted once (./failed): counting every
264
+ // error in the last 100 runs kept old failures on the card indefinitely. The
265
+ // row opens the newest of them on the Work board (./watch), not the board
266
+ // alone. A read that failed is not "nothing failed": it says so, and
267
+ // pressing the row reads the runs again.
268
+ const failing = failed(safeSessions);
269
+ if (unread)
270
+ out.push({ key: 'failed', say: say(unread, t('your runs'), 'read', t), press: reload });
271
+ else if (failing.length)
272
+ out.push({ key: 'failed', say: t('{n} failed in the past 7 days', { n: failing.length }), href: watch(failing[0].id) });
264
273
  if (safeAgents.length === 0)
265
274
  out.push({ key: 'agent', say: t('Hire your first agent'), href: '/work' });
266
275
  if (held?.length === 0)
267
276
  out.push({ key: 'ship', say: t('Ship your first project'), href: dev() });
268
277
  if (connected && Array.isArray(connected) && !connected.some((a) => a?.connected))
269
- out.push({ key: 'connect', say: t('Connect an app'), press: true });
278
+ out.push({ key: 'connect', say: t('Connect an app'), press: onConnect });
270
279
  return out;
271
- }, [safeSessions, safeAgents, held, connected, t]);
272
- return (_jsxs(Card, { kind: "next", icon: _jsx(Bot, { size: 14, "aria-hidden": true }), title: t('Next'), children: [running.length ? (_jsx(YStack, { gap: "$2", children: running.slice(0, 2).map((s) => (_jsxs(YStack, { gap: "$1", children: [_jsx(Row, { href: "/work", children: s.title || s.agent || t('Run') }), _jsx(Bar, { run: s, label: false })] }, s.id))) })) : null, rows.length === 0 && running.length === 0 ? (_jsx(Quiet, { children: t('Nothing needs you.') })) : (_jsx(YStack, { gap: "$1", children: rows.slice(0, 3).map((r) => (_jsx(Row, { href: r.href, onPress: r.press ? onConnect : undefined, children: r.say }, r.key))) }))] }));
280
+ }, [safeSessions, unread, reload, safeAgents, held, connected, onConnect, t]);
281
+ return (_jsxs(Card, { kind: "next", icon: _jsx(Bot, { size: 14, "aria-hidden": true }), title: t('Next'), children: [running.length ? (_jsx(YStack, { gap: "$2", children: running.slice(0, 2).map((s) => (_jsxs(YStack, { gap: "$1", children: [_jsx(Row, { href: "/work", children: s.title || s.agent || t('Run') }), _jsx(Bar, { run: s, label: false })] }, s.id))) })) : null, rows.length === 0 && running.length === 0 ? (_jsx(Quiet, { children: t('Nothing needs you.') })) : (_jsx(YStack, { gap: "$1", children: rows.slice(0, 3).map((r) => (_jsx(Row, { href: r.href, onPress: r.press, children: r.say }, r.key))) }))] }));
273
282
  }
274
283
  /**
275
284
  * The apps the org has connected.
package/dist/Shell.js CHANGED
@@ -74,6 +74,7 @@ const HOME_INDICATOR = "env(safe-area-inset-bottom)";
74
74
  import { invite } from "./lib/home.js";
75
75
  import { reach } from "./lib/reach.js";
76
76
  import { say } from "./failure.js";
77
+ import { half } from "./half.js";
77
78
  import { Face } from "./cast.js";
78
79
  import { useStarred, titleOf } from "./stars.js";
79
80
  import { channelName } from "./network.js";
@@ -814,8 +815,13 @@ function Bots({ show, owner, filter = "", onPick, navigate, }) {
814
815
  folk = [...folk].sort((a, b) => (a.displayName || a.name).localeCompare(b.displayName || b.name));
815
816
  }
816
817
  const empty = folk.length + shown.length === 0;
817
- const waiting = agentsLoading || peopleLoading;
818
- const broke = agentsWrong ?? peopleWrong;
818
+ // Each half answers for its own read. IAM refuses the people read to a member
819
+ // who is not an org admin, so reporting either read's failure put "cannot open
820
+ // this org's roster" over agents that had loaded (half.ts).
821
+ const { loading: waiting, error: broke } = half(show, {
822
+ agents: { loading: agentsLoading, error: agentsWrong },
823
+ people: { loading: peopleLoading, error: peopleWrong },
824
+ });
819
825
  const pick = async (file) => {
820
826
  if (!file)
821
827
  return;
package/dist/Talk.js CHANGED
@@ -51,7 +51,7 @@ const mention = (draft, name) => `${draft && !/\s$/.test(draft) ? `${draft} ` :
51
51
  export function Talk({ channel }) {
52
52
  const { t, dir, locale } = useI18n();
53
53
  const { messages, failed, send } = useMessages(channel.id, channel.space);
54
- const { members, wrong } = useRoster();
54
+ const { members, wrong } = useRoster(channel.space);
55
55
  const me = useMe();
56
56
  const { aside, showAside } = useOpen();
57
57
  const [draft, setDraft] = useState('');
package/dist/Work.js CHANGED
@@ -15,6 +15,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
15
15
  import { useCallback, useEffect, useMemo, useState } from 'react';
16
16
  import { useAi, useSession, useSessions } from '@hanzo/ai/react';
17
17
  import { useOpen } from './open.js';
18
+ import { asked, KEY } from './watch.js';
18
19
  import { AgentBoard, ChannelHeader, Pane, ProgressBlock, Steer, steps, } from '@hanzo/ui/agents';
19
20
  import { Text, XStack, YStack } from '@hanzo/ui';
20
21
  import { useIam } from '@hanzo/iam/react';
@@ -88,6 +89,20 @@ function Watching({ idle }) {
88
89
  // and the list is re-read when the id changes so the new row is there to open.
89
90
  const { session: open, openSession: setOpen } = useOpen();
90
91
  const [trees, setTrees] = useState({});
92
+ // A run the address names opens on arrival: Home's "{n} failed" sends
93
+ // /work?session=<id> (./watch). The param is then dropped, the way Chat drops
94
+ // `?thread=`, so the address is the board's own again and a reload does not
95
+ // reopen a run the reader has moved on from.
96
+ useEffect(() => {
97
+ const url = new URL(window.location.href);
98
+ if (!url.searchParams.has(KEY))
99
+ return;
100
+ const id = asked(url.search);
101
+ url.searchParams.delete(KEY);
102
+ window.history.replaceState(null, '', `${url.pathname}${url.search}${url.hash}`);
103
+ if (id)
104
+ setOpen(id);
105
+ }, [setOpen]);
91
106
  useEffect(() => {
92
107
  if (open)
93
108
  reload();
@@ -0,0 +1,12 @@
1
+ import type { Session } from '@hanzo/ai';
2
+ /** How long a failure stays on the card: the Recents menu's "Past 7 days". */
3
+ export declare const FRESH: number;
4
+ /**
5
+ * The failed runs worth the card, newest first.
6
+ *
7
+ * Only a tree's root counts: a sub-run that failed under a root is the root's
8
+ * business, and a root that failed is one failure however many of its sub-runs
9
+ * failed with it. A run with no time on it is left out, since nothing says it
10
+ * is recent.
11
+ */
12
+ export declare function failed(sessions: readonly (Session | null | undefined)[], now?: number): Session[];
package/dist/failed.js ADDED
@@ -0,0 +1,28 @@
1
+ // The runs Home's Next card says failed: the ones that are still news. No React,
2
+ // so a spec reads it as it is.
3
+ //
4
+ // The card counted every run marked `error` among the org's last 100, with no
5
+ // window and a fan-out's sub-runs each counted on their own, so a failure stayed
6
+ // on the card ("14 failed", hanzo-inc/app issue 202) until a hundred newer runs pushed
7
+ // it off the page, however long ago it happened. A failure is news for the same
8
+ // 7 days the Recents menu calls "Past 7 days", and a tree is one run.
9
+ /** How long a failure stays on the card: the Recents menu's "Past 7 days". */
10
+ export const FRESH = 7 * 86_400_000;
11
+ /** When a run stopped: its end, else its last activity, else its start. */
12
+ const when = (s) => Date.parse(s.endedAt || s.updatedAt || s.createdAt || '');
13
+ /** The top of a tree: no parent, and the root it names, if any, is itself. */
14
+ const top = (s) => !s.parentSessionId && (!s.rootSessionId || s.rootSessionId === s.id);
15
+ /**
16
+ * The failed runs worth the card, newest first.
17
+ *
18
+ * Only a tree's root counts: a sub-run that failed under a root is the root's
19
+ * business, and a root that failed is one failure however many of its sub-runs
20
+ * failed with it. A run with no time on it is left out, since nothing says it
21
+ * is recent.
22
+ */
23
+ export function failed(sessions, now = Date.now()) {
24
+ return sessions
25
+ .filter((s) => !!s && s.status === 'error' && top(s))
26
+ .filter((s) => now - when(s) <= FRESH)
27
+ .sort((a, b) => when(b) - when(a));
28
+ }
package/dist/half.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type Half = 'agents' | 'people';
2
+ /** One read's state, as `useAgents` and `usePeople` answer it. */
3
+ export interface Read {
4
+ loading: boolean;
5
+ error: Error | null;
6
+ }
7
+ /** The read the half `show` draws: the only one whose wait and failure it reports. */
8
+ export declare const half: (show: Half, reads: Record<Half, Read>) => Read;
package/dist/half.js ADDED
@@ -0,0 +1,14 @@
1
+ // Which read a half of the sidebar's roster answers for.
2
+ //
3
+ // The sidebar draws the roster as two halves, the org's people and its agents,
4
+ // from two reads that fail apart: the agents from `/v1/agents`, the people from
5
+ // IAM's SCIM directory. IAM lists an org's people to an org admin only (403
6
+ // "listing users requires org-admin"), so for an ordinary member the people read
7
+ // fails every time while the agents read answers.
8
+ //
9
+ // hanzo.bot/bots draws the agents half alone. It used to report whichever read
10
+ // had failed, so every member who is not an org admin read "This account cannot
11
+ // open this org's roster." over agents that had loaded (hanzo-inc/app issue 199).
12
+ // A half reports its own read and no other: its own wait, its own failure.
13
+ /** The read the half `show` draws: the only one whose wait and failure it reports. */
14
+ export const half = (show, reads) => reads[show];
@@ -0,0 +1,35 @@
1
+ /** The space roster's route. */
2
+ export declare const MEMBERS = "/v1/team/members";
3
+ /** One row of a space roster, as cloud answers it. */
4
+ export interface TeamMember {
5
+ /** The account uuid: a message's author, a channel member, a `<@id>` mention. */
6
+ id: string;
7
+ name: string;
8
+ /** One of the org's agents rather than a person. */
9
+ bot: boolean;
10
+ /** A blob id, readable at `/v1/team/files/{space}/avatar` with the reader's
11
+ * credential. Not a picture a `src` can draw, so it is not carried. */
12
+ avatar?: string;
13
+ role?: string;
14
+ /** False for a retired agent, which stays so its past messages keep an author. */
15
+ active?: boolean;
16
+ presence?: string;
17
+ personRef?: string;
18
+ }
19
+ /** One member of the org: a person, or an agent standing in the channels. */
20
+ export interface Member {
21
+ /** The account a message names as its author. */
22
+ id: string;
23
+ name: string;
24
+ /** A saved picture, as a data URI. Absent where the source has none to draw. */
25
+ avatar?: string;
26
+ agent: boolean;
27
+ }
28
+ /**
29
+ * The members a roster answer names, in the order it gives (people, then
30
+ * agents). A row with no account names no author, so it is not a member; a row
31
+ * with no name is called by its account.
32
+ */
33
+ export declare const membersOf: (body: {
34
+ members?: TeamMember[] | null;
35
+ } | null | undefined) => Member[];
@@ -0,0 +1,22 @@
1
+ // Who a channel can name: the space roster, read once.
2
+ //
3
+ // `GET /v1/team/members?space=<space>` (hanzo-inc/cloud apps/team/members.go)
4
+ // answers the space's people and the org's agents in one list, each by the
5
+ // account uuid a message names as its author, and asks only that the reader be
6
+ // a member of the space.
7
+ //
8
+ // It replaced two reads joined with Promise.all, and both failed a signed-in
9
+ // reader (hanzo-inc/app issue 199):
10
+ // - `/v1/team/bots`, which cloud retired for `/v1/bot/members`, answers 404,
11
+ // so the pair failed for everyone.
12
+ // - `/v1/iam/users?owner=<org>` is listed to an org admin only, so a member
13
+ // read 403 even before that.
14
+ // A channel's Roster said "Could not read this org's roster." either way.
15
+ /** The space roster's route. */
16
+ export const MEMBERS = '/v1/team/members';
17
+ /**
18
+ * The members a roster answer names, in the order it gives (people, then
19
+ * agents). A row with no account names no author, so it is not a member; a row
20
+ * with no name is called by its account.
21
+ */
22
+ export const membersOf = (body) => (body?.members ?? []).flatMap((one) => (one?.id ? [{ id: one.id, name: one.name || one.id, agent: Boolean(one.bot) }] : []));
package/dist/roster.d.ts CHANGED
@@ -1,20 +1,13 @@
1
- /** One member of the org: a person, or an agent standing in the channels. */
2
- export interface Member {
3
- /** The account a message names as its author. */
4
- id: string;
5
- name: string;
6
- /** A saved picture, as a data URI. People only; an agent wears initials. */
7
- avatar?: string;
8
- agent: boolean;
9
- }
1
+ import { type Member } from './members.js';
2
+ export type { Member } from './members.js';
10
3
  /**
11
- * The org's members, or null while unknown.
4
+ * The members of the space a channel stands in, or null while unknown.
12
5
  *
13
- * Needs a session and an org: both reads are org-scoped and answer 403 without
14
- * one. A service account carries no id and can author nothing, so it is not a
15
- * member here.
6
+ * Needs a session and the space: the roster is read per space and answers only
7
+ * a member of it. A service account carries no id and can author nothing, so it
8
+ * is not a member here.
16
9
  */
17
- export declare function useRoster(): {
10
+ export declare function useRoster(space: string | undefined): {
18
11
  members: Member[] | null;
19
12
  wrong: unknown;
20
13
  };
package/dist/roster.js CHANGED
@@ -1,49 +1,37 @@
1
1
  'use client';
2
- // Who is in the org, by account — the ONE place an author becomes a name.
2
+ // Who is in a space, by account — the ONE place an author becomes a name.
3
3
  //
4
4
  // A message carries the team account that wrote it and nothing else: for a
5
5
  // person that is their IAM user id (the OIDC `sub`, which team's account id
6
- // equals), for an agent the user id the platform minted for it and publishes on
7
- // `/v1/team/bots`. Two reads, one list, so the transcript, the roster column and
8
- // the mention chips cannot disagree about what to call anybody.
6
+ // equals), for an agent the account team derives from its id. The space roster
7
+ // answers both in one list (members.ts), so the transcript, the roster column
8
+ // and the mention chips cannot disagree about what to call anybody.
9
9
  import { useEffect, useState } from 'react';
10
- import { useIam, useOrganizations } from '@hanzo/iam/react';
10
+ import { useIam } from '@hanzo/iam/react';
11
11
  import { useAi } from './lib/ai.js';
12
+ import { MEMBERS, membersOf } from './members.js';
12
13
  /**
13
- * The org's members, or null while unknown.
14
+ * The members of the space a channel stands in, or null while unknown.
14
15
  *
15
- * Needs a session and an org: both reads are org-scoped and answer 403 without
16
- * one. A service account carries no id and can author nothing, so it is not a
17
- * member here.
16
+ * Needs a session and the space: the roster is read per space and answers only
17
+ * a member of it. A service account carries no id and can author nothing, so it
18
+ * is not a member here.
18
19
  */
19
- export function useRoster() {
20
+ export function useRoster(space) {
20
21
  const { client } = useAi();
21
22
  const { isAuthenticated } = useIam();
22
- const { currentOrgId } = useOrganizations();
23
23
  const [members, setMembers] = useState(null);
24
24
  const [wrong, setWrong] = useState(null);
25
25
  useEffect(() => {
26
- if (!client || !isAuthenticated || !currentOrgId)
26
+ if (!client || !isAuthenticated || !space)
27
27
  return;
28
28
  let live = true;
29
29
  const stop = new AbortController();
30
- const { signal } = stop;
31
- Promise.all([
32
- client.http.json({ path: '/v1/iam/users', query: { owner: currentOrgId }, signal }),
33
- client.http.json({
34
- path: '/v1/team/bots',
35
- signal,
36
- }),
37
- ])
38
- .then(([people, bots]) => {
39
- if (!live)
40
- return;
41
- setMembers([
42
- ...(people.users ?? []).flatMap((one) => one.id
43
- ? [{ id: one.id, name: one.displayName || one.name, avatar: one.avatar || undefined, agent: false }]
44
- : []),
45
- ...(bots.bots ?? []).map((one) => ({ id: one.userId, name: one.name, agent: true })),
46
- ]);
30
+ client.http
31
+ .json({ path: MEMBERS, query: { space }, signal: stop.signal })
32
+ .then((body) => {
33
+ if (live)
34
+ setMembers(membersOf(body));
47
35
  })
48
36
  .catch((e) => {
49
37
  if (live)
@@ -53,7 +41,7 @@ export function useRoster() {
53
41
  live = false;
54
42
  stop.abort();
55
43
  };
56
- }, [client, isAuthenticated, currentOrgId]);
44
+ }, [client, isAuthenticated, space]);
57
45
  return { members, wrong };
58
46
  }
59
47
  /** The member an author id names, or undefined for one the roster lacks. */
@@ -0,0 +1,6 @@
1
+ /** The query key Work reads a run from. */
2
+ export declare const KEY = "session";
3
+ /** The Work board, opened on one run; the board alone for anything that is not an id. */
4
+ export declare const watch: (id: string) => string;
5
+ /** The run an address asks Work to open, or null when it names none. */
6
+ export declare function asked(search: string): string | null;
package/dist/watch.js ADDED
@@ -0,0 +1,20 @@
1
+ // One run on the Work board, as an address: where a line about a run sends the
2
+ // reader. No React, so a spec reads it as it is.
3
+ //
4
+ // Home's Next card says "{n} failed in the past 7 days". Linked to /work alone,
5
+ // it left the reader on a board of up to a hundred runs, old failures among
6
+ // them, to find the ones it meant (hanzo-inc/app issue 202). The address names
7
+ // the newest failure instead, and Work opens it on arrival, where its steps say
8
+ // what went wrong and Steer acts on it. What writes the address and what reads
9
+ // it live here together, so the two cannot drift apart.
10
+ /** The query key Work reads a run from. */
11
+ export const KEY = 'session';
12
+ /** An id-shaped token ("sess_" + 32 hex today), and nothing that could be a path. */
13
+ const ID = /^[A-Za-z0-9_-]{1,128}$/;
14
+ /** The Work board, opened on one run; the board alone for anything that is not an id. */
15
+ export const watch = (id) => (ID.test(id) ? `/work?${new URLSearchParams({ [KEY]: id })}` : '/work');
16
+ /** The run an address asks Work to open, or null when it names none. */
17
+ export function asked(search) {
18
+ const id = new URLSearchParams(search).get(KEY)?.trim();
19
+ return id && ID.test(id) ? id : null;
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/app",
3
- "version": "0.3.53",
3
+ "version": "0.3.54",
4
4
  "description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",