@hanzo/app 0.2.58 → 0.3.0
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/README.md +8 -8
- package/dist/{Me.d.ts → Account.d.ts} +1 -1
- package/dist/{Me.js → Account.js} +3 -3
- package/dist/App.d.ts +2 -2
- package/dist/App.js +16 -16
- package/dist/{Top.d.ts → Bar.d.ts} +1 -1
- package/dist/{Top.js → Bar.js} +3 -3
- package/dist/Betas.js +1 -1
- package/dist/Board.js +4 -4
- package/dist/Chat.d.ts +4 -4
- package/dist/Chat.js +96 -96
- package/dist/Contacts.js +17 -15
- package/dist/Directory.js +7 -21
- package/dist/Drive.js +6 -6
- package/dist/{Orgs.d.ts → Gate.d.ts} +1 -1
- package/dist/{Orgs.js → Gate.js} +32 -32
- package/dist/{Chrome.d.ts → Header.d.ts} +1 -1
- package/dist/{Chrome.js → Header.js} +1 -1
- package/dist/Home.d.ts +3 -3
- package/dist/Home.js +30 -30
- package/dist/Inbox.js +29 -33
- package/dist/Meet.js +22 -22
- package/dist/Rail.js +6 -6
- package/dist/RightPane.js +2 -2
- package/dist/{Palette.d.ts → Search.d.ts} +1 -1
- package/dist/{Palette.js → Search.js} +1 -1
- package/dist/Settings.d.ts +3 -3
- package/dist/Settings.js +5 -5
- package/dist/SettingsPane.d.ts +2 -2
- package/dist/SettingsPane.js +5 -5
- package/dist/Setup.js +2 -2
- package/dist/Shell.d.ts +22 -31
- package/dist/Shell.js +167 -114
- package/dist/{Column.d.ts → Sidebar.d.ts} +1 -1
- package/dist/{Column.js → Sidebar.js} +5 -5
- package/dist/Support.js +2 -2
- package/dist/Talk.d.ts +3 -3
- package/dist/Talk.js +18 -18
- package/dist/TeamPreview.js +26 -26
- package/dist/TeamStory.js +1 -1
- package/dist/Usage.js +2 -2
- package/dist/Work.js +2 -2
- package/dist/bots/Bots.js +2 -2
- package/dist/bots/Lights.d.ts +1 -1
- package/dist/bots/Lights.js +1 -1
- package/dist/bots/api.d.ts +8 -7
- package/dist/bots/api.js +4 -4
- package/dist/bots/ink.js +3 -3
- package/dist/bots/kit.d.ts +2 -2
- package/dist/bots/kit.js +4 -4
- package/dist/bots/runtime.js +12 -12
- package/dist/cast.d.ts +14 -14
- package/dist/cast.js +12 -12
- package/dist/channels.d.ts +132 -0
- package/dist/{rooms.js → channels.js} +56 -55
- package/dist/conversations.d.ts +8 -8
- package/dist/conversations.js +18 -17
- package/dist/crew.d.ts +1 -1
- package/dist/crew.js +12 -12
- package/dist/dev.js +6 -6
- package/dist/failure.d.ts +2 -2
- package/dist/failure.js +6 -6
- package/dist/ground.d.ts +1 -1
- package/dist/ground.js +1 -1
- package/dist/help.d.ts +1 -1
- package/dist/help.js +2 -2
- package/dist/hint.d.ts +1 -1
- package/dist/hint.js +1 -1
- package/dist/host.d.ts +15 -15
- package/dist/host.js +13 -13
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -4
- package/dist/lib/ai.js +1 -1
- package/dist/lib/api.d.ts +1 -1
- package/dist/lib/api.js +1 -1
- package/dist/lib/destination.d.ts +3 -3
- package/dist/lib/destination.js +3 -3
- package/dist/lib/home.d.ts +2 -2
- package/dist/lib/home.js +2 -2
- package/dist/lib/host.d.ts +17 -16
- package/dist/lib/host.js +19 -18
- package/dist/lib/hostname.d.ts +1 -1
- package/dist/lib/hostname.js +1 -1
- package/dist/lib/list.d.ts +1 -1
- package/dist/lib/list.js +1 -1
- package/dist/lib/models.js +1 -1
- package/dist/lib/org.d.ts +1 -1
- package/dist/lib/org.js +1 -1
- package/dist/lib/orgname.d.ts +1 -1
- package/dist/lib/orgname.js +1 -1
- package/dist/lib/session.d.ts +4 -4
- package/dist/lib/session.js +6 -6
- package/dist/lib/tier.d.ts +4 -4
- package/dist/lib/tier.js +5 -5
- package/dist/lib/tiers.d.ts +1 -1
- package/dist/lib/tiers.js +10 -10
- package/dist/lib/web.d.ts +1 -1
- package/dist/lib/web.js +1 -1
- package/dist/network.d.ts +18 -18
- package/dist/network.js +28 -28
- package/dist/open.d.ts +24 -22
- package/dist/open.js +19 -19
- package/dist/pane.d.ts +6 -6
- package/dist/pane.js +10 -10
- package/dist/roster.d.ts +2 -2
- package/dist/roster.js +1 -1
- package/dist/seek.js +1 -1
- package/dist/slide.d.ts +1 -1
- package/dist/slide.js +1 -1
- package/dist/span.js +1 -1
- package/dist/stars.d.ts +4 -4
- package/dist/stars.js +8 -10
- package/dist/tabs.d.ts +1 -1
- package/dist/tabs.js +1 -1
- package/dist/team.js +1 -1
- package/dist/thread.d.ts +3 -3
- package/dist/thread.js +4 -4
- package/dist/ui.d.ts +1 -1
- package/dist/ui.js +1 -1
- package/dist/where.d.ts +7 -7
- package/dist/where.js +2 -2
- package/dist/workday.d.ts +26 -26
- package/dist/workday.js +187 -187
- package/package.json +3 -3
- package/dist/Room.d.ts +0 -8
- package/dist/Room.js +0 -51
- package/dist/rooms.d.ts +0 -131
- /package/dist/lib/{rooms.json → routes.json} +0 -0
package/dist/bots/runtime.js
CHANGED
|
@@ -11,7 +11,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
11
11
|
// is deterministic, so the same disk comes back after a lease ends
|
|
12
12
|
// its TOOLS `tools[]` — the names this Bot may call, out of the platform's
|
|
13
13
|
// own MCP surface plus whatever the org has registered
|
|
14
|
-
// its
|
|
14
|
+
// its TRANSPORTS the networks it answers on, from /v1/transport/agent
|
|
15
15
|
// its CODE an autonomous run against one of the org's repos
|
|
16
16
|
// its SECRETS the KMS names under `bots/<name>`
|
|
17
17
|
//
|
|
@@ -77,7 +77,7 @@ export function Runtime({ bot }) {
|
|
|
77
77
|
const [activated, setActivated] = useState([]);
|
|
78
78
|
const [published, setPublished] = useState([]);
|
|
79
79
|
const [links, setLinks] = useState([]);
|
|
80
|
-
const [
|
|
80
|
+
const [transports, setTransports] = useState([]);
|
|
81
81
|
const [keys, setKeys] = useState([]);
|
|
82
82
|
const [repos, setRepos] = useState([]);
|
|
83
83
|
const [why, setWhy] = useState({});
|
|
@@ -95,7 +95,7 @@ export function Runtime({ bot }) {
|
|
|
95
95
|
client.tools.activation().then((a) => setActivated(a.enabled ?? [])).catch(() => setActivated([])),
|
|
96
96
|
readTools(client).then(setPublished).catch((e) => blame('served', e, t('the platform’s tools'))),
|
|
97
97
|
readConnectors(client).then(setLinks).catch((e) => blame('link', e, t('your connectors'))),
|
|
98
|
-
client.
|
|
98
|
+
client.transports.list().then(setTransports).catch((e) => blame('transport', e, t('this org’s transports'))),
|
|
99
99
|
readSecrets(client, vault(bot.name)).then(setKeys).catch((e) => blame('key', e, t('this bot’s secrets'))),
|
|
100
100
|
readProjects(client).then(setRepos).catch((e) => blame('repo', e, t('this org’s repos'))),
|
|
101
101
|
]);
|
|
@@ -112,7 +112,7 @@ export function Runtime({ bot }) {
|
|
|
112
112
|
}) }), bot.schedule ? (_jsx(Line, { children: t(bot.executionMode ? 'Wakes on {schedule} ({mode}).' : 'Wakes on {schedule}.', {
|
|
113
113
|
schedule: _jsx(Text, { color: INK, children: bot.schedule }),
|
|
114
114
|
mode: modeName(bot.executionMode, t),
|
|
115
|
-
}) })) : null] }), _jsx(Machine, { bot: bot, machines: machines, why: why.machine }), _jsx(Computer, { bot: bot, box: boxes[0] ?? null, project: project, why: why.box, onChange: survey }), _jsx(Tools, { bot: bot, servers: servers, skills: skills, published: published, activated: activated, why: why.served ?? why.mcp ?? why.skill }), _jsx(
|
|
115
|
+
}) })) : null] }), _jsx(Machine, { bot: bot, machines: machines, why: why.machine }), _jsx(Computer, { bot: bot, box: boxes[0] ?? null, project: project, why: why.box, onChange: survey }), _jsx(Tools, { bot: bot, servers: servers, skills: skills, published: published, activated: activated, why: why.served ?? why.mcp ?? why.skill }), _jsx(Transports, { bot: bot, transports: transports, why: why.transport }), _jsx(Code, { bot: bot, repos: repos, why: why.repo }), _jsx(Secrets, { bot: bot, keys: keys, why: why.key }), _jsx(Held, { links: links, why: why.link })] }));
|
|
116
116
|
}
|
|
117
117
|
/** The machine this Bot runs on. The list is the org's; the binding is the Bot's. */
|
|
118
118
|
function Machine({ bot, machines, why }) {
|
|
@@ -280,13 +280,13 @@ function Tools({ bot, servers, skills, published, activated, why, }) {
|
|
|
280
280
|
}, gap: 6, children: [_jsx(Picker, { ...PICK, value: pick, onChange: (e) => setPick(e.target.value), "aria-label": t('Tool to call'), children: held.map((h) => (_jsx("option", { value: h, children: h }, h))) }), _jsxs(XStack, { gap: 6, children: [_jsx(Input, { ...BOXED, flex: 1, minW: 0, "data-hz": "op", value: op, onChange: (e) => setOp(e.target.value), placeholder: t('Operation'), "aria-label": t('Operation to run') }), _jsx(Text, { ...TAB, type: 'submit', "data-hz": "call", disabled: busy || !op.trim(), children: t(busy ? 'Calling…' : 'Call') })] })] })) : null, ran ? _jsx(Text, { ...OUT, "data-hz": "called", children: ran }) : null, failed ? _jsx(Line, { children: failed }) : null] }));
|
|
281
281
|
}
|
|
282
282
|
/**
|
|
283
|
-
* The
|
|
283
|
+
* The transports this Bot answers on.
|
|
284
284
|
*
|
|
285
|
-
* `/v1/
|
|
285
|
+
* `/v1/transport/agent` binds ONE agent per transport as the org's default
|
|
286
286
|
* answerer, so this is a per-Bot binding and not an account-wide list: pressing
|
|
287
|
-
* Answer here moves that
|
|
287
|
+
* Answer here moves that transport from whichever bot holds it to this one.
|
|
288
288
|
*/
|
|
289
|
-
function
|
|
289
|
+
function Transports({ bot, transports, why }) {
|
|
290
290
|
const { t, locale } = useI18n();
|
|
291
291
|
const { client } = useAi();
|
|
292
292
|
const [bound, setBound] = useState({});
|
|
@@ -294,7 +294,7 @@ function Channels({ bot, rooms, why }) {
|
|
|
294
294
|
const read = useCallback(async () => {
|
|
295
295
|
if (!client)
|
|
296
296
|
return;
|
|
297
|
-
const pairs = await Promise.all(
|
|
297
|
+
const pairs = await Promise.all(transports.map(async (r) => {
|
|
298
298
|
try {
|
|
299
299
|
return [r.id, (await answering(client, r.id)).default ?? ''];
|
|
300
300
|
}
|
|
@@ -303,11 +303,11 @@ function Channels({ bot, rooms, why }) {
|
|
|
303
303
|
}
|
|
304
304
|
}));
|
|
305
305
|
setBound(Object.fromEntries(pairs));
|
|
306
|
-
}, [client,
|
|
306
|
+
}, [client, transports]);
|
|
307
307
|
useEffect(() => {
|
|
308
308
|
void read();
|
|
309
309
|
}, [read]);
|
|
310
|
-
return (_jsxs(Part, { title: t('
|
|
310
|
+
return (_jsxs(Part, { title: t('Transports'), children: [why ? _jsx(Line, { children: why }) : null, transports.length === 0 && !why ? _jsx(Line, { children: t('This org has no transports.') }) : null, transports.map((r) => {
|
|
311
311
|
const mine = bound[r.id] === bot.name;
|
|
312
312
|
return (_jsxs(Row, { children: [_jsx(Text, { fontSize: "$2", color: INK, children: r.id }), _jsxs(XStack, { items: "center", gap: 8, children: [_jsx(Text, { fontSize: "$1", color: FAINT, children: r.connected ? bound[r.id] || t('unbound') : t('not connected') }), _jsx(Text, { ...TAB, opacity: mine ? 0.5 : 1, disabled: mine, onClick: async () => {
|
|
313
313
|
if (!client)
|
|
@@ -318,7 +318,7 @@ function Channels({ bot, rooms, why }) {
|
|
|
318
318
|
await read();
|
|
319
319
|
}
|
|
320
320
|
catch (e) {
|
|
321
|
-
setFailed(say(e, t('this
|
|
321
|
+
setFailed(say(e, t('this transport'), 'save', t));
|
|
322
322
|
}
|
|
323
323
|
}, children: t(mine ? 'Answers' : 'Answer') })] })] }, r.id));
|
|
324
324
|
}), failed ? _jsx(Line, { children: failed }) : null] }));
|
package/dist/cast.d.ts
CHANGED
|
@@ -29,9 +29,9 @@ interface Role {
|
|
|
29
29
|
* voice id, sent to /v1/audio/speech as it is. The first letter is the accent
|
|
30
30
|
* (a American, b British), the second the register (f female, m male).
|
|
31
31
|
*
|
|
32
|
-
* ONE VOICE PER CHARACTER, and never two who would be in the same
|
|
33
|
-
* house part shares the voice of the character whose face it
|
|
34
|
-
* Coder sounds like Dev; no two characters share one.
|
|
32
|
+
* ONE VOICE PER CHARACTER, and never two who would be in the same
|
|
33
|
+
* conversation. A house part shares the voice of the character whose face it
|
|
34
|
+
* wears, so Hanzo Coder sounds like Dev; no two characters share one.
|
|
35
35
|
*
|
|
36
36
|
* CAST, NOT COPIED. These are the speech service's own voices, chosen for fit
|
|
37
37
|
* — a playful reader for the physicist, something low and measured for the
|
|
@@ -50,14 +50,14 @@ export declare const speaksOf: (name: string | undefined) => string | undefined;
|
|
|
50
50
|
/** Names as a sentence lists them: "Feynman", "Feynman & Einstein", "Feynman, Einstein & Vi". */
|
|
51
51
|
export declare const join: (names: string[], t?: Say) => string;
|
|
52
52
|
/**
|
|
53
|
-
* The
|
|
53
|
+
* The conversation's system turn.
|
|
54
54
|
*
|
|
55
55
|
* One person's brief rides as it is, under their name. Several ride together:
|
|
56
|
-
* who is in the
|
|
57
|
-
* nobody is named (Chat.tsx `addressed` draws the same rule) —
|
|
58
|
-
* lets a reader tell them apart — each contribution opens
|
|
59
|
-
* colon — and then each brief under its name. Null for a
|
|
60
|
-
* describe, which is the plain model.
|
|
56
|
+
* who is in the conversation, who answers — the ones the user names, or
|
|
57
|
+
* everyone when nobody is named (Chat.tsx `addressed` draws the same rule) —
|
|
58
|
+
* the one rule that lets a reader tell them apart — each contribution opens
|
|
59
|
+
* with a name and a colon — and then each brief under its name. Null for a
|
|
60
|
+
* conversation with nobody to describe, which is the plain model.
|
|
61
61
|
*/
|
|
62
62
|
export declare function brief(cast: {
|
|
63
63
|
name: string;
|
|
@@ -65,19 +65,19 @@ export declare function brief(cast: {
|
|
|
65
65
|
}[]): string | null;
|
|
66
66
|
/**
|
|
67
67
|
* The line a conversation records to say who is in it. The thread keeps it as a
|
|
68
|
-
* system turn, so reopening the thread anywhere seats the same
|
|
68
|
+
* system turn, so reopening the thread anywhere seats the same cast. Names are
|
|
69
69
|
* the agents' handles, which carry no comma (the agents API's name pattern).
|
|
70
70
|
*/
|
|
71
71
|
export declare const roster: (names: string[]) => string;
|
|
72
72
|
/** The names a recorded roster line holds, or null for a turn that is not one. */
|
|
73
73
|
export declare function rosterOf(content: string): string[] | null;
|
|
74
74
|
/**
|
|
75
|
-
* The system turn a
|
|
76
|
-
* empty
|
|
75
|
+
* The system turn a conversation sends: the roster line, then the brief. Null
|
|
76
|
+
* for an empty conversation, which is the plain model.
|
|
77
77
|
*/
|
|
78
|
-
export declare function
|
|
78
|
+
export declare function castTurn(names: string[], said: string | null): string | null;
|
|
79
79
|
/**
|
|
80
|
-
* A
|
|
80
|
+
* A conversation's reply, split by who said what.
|
|
81
81
|
*
|
|
82
82
|
* A line that opens with a member's name and a colon — plain or bold — starts
|
|
83
83
|
* that member's part; lines before any such line belong to nobody, and a reply
|
package/dist/cast.js
CHANGED
|
@@ -57,14 +57,14 @@ export const speaksOf = (name) => member(name)?.instructions;
|
|
|
57
57
|
/** Names as a sentence lists them: "Feynman", "Feynman & Einstein", "Feynman, Einstein & Vi". */
|
|
58
58
|
export const join = (names, t = english) => names.length < 2 ? (names[0] ?? '') : t('{names} & {last}', { names: names.slice(0, -1).join(', '), last: names[names.length - 1] });
|
|
59
59
|
/**
|
|
60
|
-
* The
|
|
60
|
+
* The conversation's system turn.
|
|
61
61
|
*
|
|
62
62
|
* One person's brief rides as it is, under their name. Several ride together:
|
|
63
|
-
* who is in the
|
|
64
|
-
* nobody is named (Chat.tsx `addressed` draws the same rule) —
|
|
65
|
-
* lets a reader tell them apart — each contribution opens
|
|
66
|
-
* colon — and then each brief under its name. Null for a
|
|
67
|
-
* describe, which is the plain model.
|
|
63
|
+
* who is in the conversation, who answers — the ones the user names, or
|
|
64
|
+
* everyone when nobody is named (Chat.tsx `addressed` draws the same rule) —
|
|
65
|
+
* the one rule that lets a reader tell them apart — each contribution opens
|
|
66
|
+
* with a name and a colon — and then each brief under its name. Null for a
|
|
67
|
+
* conversation with nobody to describe, which is the plain model.
|
|
68
68
|
*/
|
|
69
69
|
export function brief(cast) {
|
|
70
70
|
if (!cast.length || cast.every((one) => !one.says))
|
|
@@ -79,11 +79,11 @@ export function brief(cast) {
|
|
|
79
79
|
...cast.map((one) => `## ${one.name}\n\n${one.says ?? `${one.name} answers as ${one.name}.`}`),
|
|
80
80
|
].join('\n\n');
|
|
81
81
|
}
|
|
82
|
-
/** The first line of a
|
|
82
|
+
/** The first line of a conversation's system turn: who is in it, by name. */
|
|
83
83
|
const ROSTER = 'Agents in this conversation: ';
|
|
84
84
|
/**
|
|
85
85
|
* The line a conversation records to say who is in it. The thread keeps it as a
|
|
86
|
-
* system turn, so reopening the thread anywhere seats the same
|
|
86
|
+
* system turn, so reopening the thread anywhere seats the same cast. Names are
|
|
87
87
|
* the agents' handles, which carry no comma (the agents API's name pattern).
|
|
88
88
|
*/
|
|
89
89
|
export const roster = (names) => `${ROSTER}${names.length ? names.join(', ') : 'none'}`;
|
|
@@ -96,16 +96,16 @@ export function rosterOf(content) {
|
|
|
96
96
|
return names === 'none' ? [] : names.split(',').map((one) => one.trim()).filter(Boolean);
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
|
-
* The system turn a
|
|
100
|
-
* empty
|
|
99
|
+
* The system turn a conversation sends: the roster line, then the brief. Null
|
|
100
|
+
* for an empty conversation, which is the plain model.
|
|
101
101
|
*/
|
|
102
|
-
export function
|
|
102
|
+
export function castTurn(names, said) {
|
|
103
103
|
if (!names.length)
|
|
104
104
|
return null;
|
|
105
105
|
return said ? `${roster(names)}\n\n${said}` : roster(names);
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* A
|
|
108
|
+
* A conversation's reply, split by who said what.
|
|
109
109
|
*
|
|
110
110
|
* A line that opens with a member's name and a colon — plain or bold — starts
|
|
111
111
|
* that member's part; lines before any such line belong to nobody, and a reply
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A channel as Team keeps it: an open one, a direct message, or one bound to
|
|
3
|
+
* work.
|
|
4
|
+
*
|
|
5
|
+
* `direct` is the distinction the sidebar draws — a channel anyone in the org
|
|
6
|
+
* can read against a conversation between two people — so it decides the sigil
|
|
7
|
+
* and the section rather than a guess from the name.
|
|
8
|
+
*
|
|
9
|
+
* `space` is half of a channel's address: two spaces of one org may each hold a
|
|
10
|
+
* #general, so the pair identifies one and the id alone does not. It is also
|
|
11
|
+
* the box a file goes in — `/v1/team/files/{space}` is addressed by space, never
|
|
12
|
+
* by channel. The field is the server's own name for it.
|
|
13
|
+
*/
|
|
14
|
+
export interface Channel {
|
|
15
|
+
id: string;
|
|
16
|
+
space: string;
|
|
17
|
+
name: string;
|
|
18
|
+
topic?: string;
|
|
19
|
+
desc?: string;
|
|
20
|
+
direct: boolean;
|
|
21
|
+
private: boolean;
|
|
22
|
+
visibility?: 'public' | 'org' | 'private';
|
|
23
|
+
orgId?: string;
|
|
24
|
+
archived: boolean;
|
|
25
|
+
members: string[];
|
|
26
|
+
count?: number;
|
|
27
|
+
/**
|
|
28
|
+
* What the channel is FOR — "standing" for one meant to outlive any task,
|
|
29
|
+
* "bound" for one opened for a single piece of work. Absent reads standing.
|
|
30
|
+
* It is intent, not state: whether the channel is open now is `archived`.
|
|
31
|
+
*/
|
|
32
|
+
life?: string;
|
|
33
|
+
/**
|
|
34
|
+
* What the channel is ABOUT, each a "<kind>:<ref>" — "repo:hanzoai/cloud",
|
|
35
|
+
* "issue:1010". References, never copies: the app that owns a project is the
|
|
36
|
+
* one that can resolve it.
|
|
37
|
+
*/
|
|
38
|
+
bindings?: string[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The key the workspace selects a channel by, and puts in the address:
|
|
42
|
+
* `team:<space>/<id>`. Both halves, because a channel id is unique within a
|
|
43
|
+
* space and not across the org. Prefixed rather than hashed, because a key a
|
|
44
|
+
* person can read in a URL is one they can report in a bug.
|
|
45
|
+
*/
|
|
46
|
+
export declare const teamKey: (channel: Pick<Channel, 'space' | 'id'>) => string;
|
|
47
|
+
/** The address a key names, or null for a key that is not a channel's. */
|
|
48
|
+
export declare function fromKey(key: string | null): {
|
|
49
|
+
space: string;
|
|
50
|
+
id: string;
|
|
51
|
+
} | null;
|
|
52
|
+
/** The page a key opens on: Home, carrying it as the `?channel=` that
|
|
53
|
+
* the host's Home reads on arrival. */
|
|
54
|
+
export declare const channelHref: (key: string) => string;
|
|
55
|
+
/** Asks the platform again. The list held stays on screen until it answers. */
|
|
56
|
+
export declare function reloadChannels(): void;
|
|
57
|
+
/**
|
|
58
|
+
* The org's real channels, from Team, and the way to add one.
|
|
59
|
+
*
|
|
60
|
+
* `/v1/team/channels` is the org's own list and answers only a validated
|
|
61
|
+
* principal. An archived channel is not drawn: it is one the org closed, and a
|
|
62
|
+
* sidebar that lists them makes leaving one meaningless.
|
|
63
|
+
*
|
|
64
|
+
* NULL IS UNKNOWN AND IT IS NOT EMPTY. Three states, and the caller owes a
|
|
65
|
+
* sentence for each: `null` while nothing is known, `[]` for an org that
|
|
66
|
+
* genuinely has no channels, and `wrong` for a service that answered no. A list is
|
|
67
|
+
* never fabricated to cover any of them.
|
|
68
|
+
*
|
|
69
|
+
* `open` posts a channel and HOLDS the one the platform answered with: a 201
|
|
70
|
+
* is `{channel}`, the stored channel, so every view carries it from that moment
|
|
71
|
+
* and the reader can step into it without a second read. The server adds nobody
|
|
72
|
+
* to a channel, so the caller names its own members.
|
|
73
|
+
*/
|
|
74
|
+
export declare function useChannels(): {
|
|
75
|
+
channels: Channel[] | null;
|
|
76
|
+
wrong: unknown;
|
|
77
|
+
reload: () => void;
|
|
78
|
+
open: (channel: {
|
|
79
|
+
name: string;
|
|
80
|
+
space?: string;
|
|
81
|
+
members: string[];
|
|
82
|
+
}) => Promise<Channel>;
|
|
83
|
+
};
|
|
84
|
+
/** The channel with that id, or undefined for none open. */
|
|
85
|
+
export declare function channelOf(channels: Channel[] | null, id: string | null): Channel | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* One thing somebody said in a channel.
|
|
88
|
+
*
|
|
89
|
+
* `author` is the team ACCOUNT that wrote it, not a name: what to call somebody
|
|
90
|
+
* is the roster's answer (`roster.ts`), and copying it onto every message is
|
|
91
|
+
* how the two come to disagree. `text` is plain — the platform stores the
|
|
92
|
+
* client's markup and reduces it on the way out, so nothing here parses HTML.
|
|
93
|
+
*/
|
|
94
|
+
export interface Message {
|
|
95
|
+
id: string;
|
|
96
|
+
/** The channel's id. */
|
|
97
|
+
channel: string;
|
|
98
|
+
author: string;
|
|
99
|
+
text: string;
|
|
100
|
+
/** Unix MILLIseconds, which is what the platform stamps. */
|
|
101
|
+
createdOn: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A channel's conversation, and the way to add to it.
|
|
105
|
+
*
|
|
106
|
+
* READ AND WRITE IN ONE HOOK, because they are one question — a pane that can
|
|
107
|
+
* show a channel and not answer in it is a directory — and because the poller
|
|
108
|
+
* and the sender then cannot disagree about what the channel holds.
|
|
109
|
+
*
|
|
110
|
+
* THE CHANNEL IS POLLED, every two seconds while it is open and the tab is
|
|
111
|
+
* showing. The team plane has no push a browser can read but its transactor
|
|
112
|
+
* socket, which is a binary protocol rather than a line; a read costs a few
|
|
113
|
+
* hundred milliseconds and nothing on the server past the space's own
|
|
114
|
+
* messages, so half a request a second per open channel is the honest price of
|
|
115
|
+
* seeing an answer land. Each read carries its own AbortController, and the
|
|
116
|
+
* cleanup aborts the one in flight and stops the clock — on unmount, and when
|
|
117
|
+
* the channel or its space changes.
|
|
118
|
+
*
|
|
119
|
+
* `send` posts and answers the row the platform stored: a 201 is the message,
|
|
120
|
+
* with its id and stamp, so the hook holds it at once and the next poll finds
|
|
121
|
+
* the same id and keeps one. Nothing the platform did not accept is ever held.
|
|
122
|
+
*
|
|
123
|
+
* `space` is half a channel's address (two spaces of one org may each hold a
|
|
124
|
+
* channel with one id), so both calls carry it and a channel with neither reads
|
|
125
|
+
* empty rather than guessing.
|
|
126
|
+
*/
|
|
127
|
+
export declare function useMessages(channel: string | null, space: string | undefined): {
|
|
128
|
+
messages: Message[];
|
|
129
|
+
failed: unknown;
|
|
130
|
+
send: (text: string) => Promise<Message>;
|
|
131
|
+
reload: () => void;
|
|
132
|
+
};
|
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
// The org's
|
|
2
|
+
// The org's channels: the one reader and writer for /v1/team/channels
|
|
3
|
+
// (HIP-0523 §2.1).
|
|
3
4
|
//
|
|
4
|
-
// A
|
|
5
|
+
// A channel is not the sidebar's private business. The rail lists them, /home
|
|
5
6
|
// reads one, and the composer needs the space off it to address anything — so
|
|
6
7
|
// the list, the key, the transcript and the two writes live here, in one shape,
|
|
7
|
-
// and no second module holds another opinion about what a
|
|
8
|
+
// and no second module holds another opinion about what a channel is.
|
|
8
9
|
import { useCallback, useEffect, useState, useSyncExternalStore } from 'react';
|
|
9
10
|
import { useIam } from '@hanzo/iam/react';
|
|
10
11
|
import { useAi } from './lib/ai.js';
|
|
11
12
|
import { where } from './where.js';
|
|
12
13
|
/**
|
|
13
|
-
* The key the workspace selects a
|
|
14
|
-
* `team:<space>/<id>`. Both halves, because a
|
|
15
|
-
* and not across the org. Prefixed rather than hashed, because a key a
|
|
16
|
-
* can read in a URL is one they can report in a bug.
|
|
14
|
+
* The key the workspace selects a channel by, and puts in the address:
|
|
15
|
+
* `team:<space>/<id>`. Both halves, because a channel id is unique within a
|
|
16
|
+
* space and not across the org. Prefixed rather than hashed, because a key a
|
|
17
|
+
* person can read in a URL is one they can report in a bug.
|
|
17
18
|
*/
|
|
18
|
-
export const teamKey = (
|
|
19
|
-
/** The address a key names, or null for a key that is not a
|
|
20
|
-
export function
|
|
19
|
+
export const teamKey = (channel) => `team:${channel.space}/${channel.id}`;
|
|
20
|
+
/** The address a key names, or null for a key that is not a channel's. */
|
|
21
|
+
export function fromKey(key) {
|
|
21
22
|
const found = key?.match(/^team:([^/]+)\/(.+)$/);
|
|
22
23
|
return found ? { space: found[1], id: found[2] } : null;
|
|
23
24
|
}
|
|
24
|
-
/** The page a key opens on: Home, carrying it as the `?
|
|
25
|
-
*
|
|
26
|
-
export const
|
|
25
|
+
/** The page a key opens on: Home, carrying it as the `?channel=` that
|
|
26
|
+
* the host's Home reads on arrival. */
|
|
27
|
+
export const channelHref = (key) => `${where().home}?${new URLSearchParams({ channel: key })}`;
|
|
27
28
|
/** The prerender's answer, and the first one. A stable reference, because
|
|
28
29
|
* React compares snapshots by identity. */
|
|
29
|
-
const UNKNOWN = {
|
|
30
|
+
const UNKNOWN = { channels: null, wrong: null };
|
|
30
31
|
let held = UNKNOWN;
|
|
31
32
|
/** Bumped by `reload`; a read is made once per value. */
|
|
32
33
|
let epoch = 0;
|
|
@@ -44,28 +45,28 @@ function subscribe(one) {
|
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
/** Asks the platform again. The list held stays on screen until it answers. */
|
|
47
|
-
export function
|
|
48
|
+
export function reloadChannels() {
|
|
48
49
|
epoch += 1;
|
|
49
|
-
publish({
|
|
50
|
+
publish({ channels: held.channels, wrong: null });
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
52
|
-
* The org's real
|
|
53
|
+
* The org's real channels, from Team, and the way to add one.
|
|
53
54
|
*
|
|
54
|
-
* `/v1/team/
|
|
55
|
-
* principal. An archived
|
|
55
|
+
* `/v1/team/channels` is the org's own list and answers only a validated
|
|
56
|
+
* principal. An archived channel is not drawn: it is one the org closed, and a
|
|
56
57
|
* sidebar that lists them makes leaving one meaningless.
|
|
57
58
|
*
|
|
58
59
|
* NULL IS UNKNOWN AND IT IS NOT EMPTY. Three states, and the caller owes a
|
|
59
60
|
* sentence for each: `null` while nothing is known, `[]` for an org that
|
|
60
|
-
* genuinely has no
|
|
61
|
+
* genuinely has no channels, and `wrong` for a service that answered no. A list is
|
|
61
62
|
* never fabricated to cover any of them.
|
|
62
63
|
*
|
|
63
|
-
* `open` posts a
|
|
64
|
-
* the stored
|
|
65
|
-
* step into it without a second read. The
|
|
66
|
-
*
|
|
64
|
+
* `open` posts a channel and HOLDS the one the platform answered with: a 201
|
|
65
|
+
* is `{channel}`, the stored channel, so every view carries it from that moment
|
|
66
|
+
* and the reader can step into it without a second read. The server adds nobody
|
|
67
|
+
* to a channel, so the caller names its own members.
|
|
67
68
|
*/
|
|
68
|
-
export function
|
|
69
|
+
export function useChannels() {
|
|
69
70
|
const { client } = useAi();
|
|
70
71
|
const { user } = useIam();
|
|
71
72
|
const now = useSyncExternalStore(subscribe, () => held, () => UNKNOWN);
|
|
@@ -75,65 +76,65 @@ export function useTeamRooms() {
|
|
|
75
76
|
asked = epoch;
|
|
76
77
|
const mine = epoch;
|
|
77
78
|
client.http
|
|
78
|
-
.json({ path: '/v1/team/
|
|
79
|
+
.json({ path: '/v1/team/channels' })
|
|
79
80
|
.then((page) => {
|
|
80
81
|
if (mine === epoch)
|
|
81
|
-
publish({
|
|
82
|
+
publish({ channels: (page.channels ?? []).filter((c) => !c.archived), wrong: null });
|
|
82
83
|
})
|
|
83
84
|
.catch((e) => {
|
|
84
85
|
if (mine === epoch)
|
|
85
|
-
publish({
|
|
86
|
+
publish({ channels: null, wrong: e });
|
|
86
87
|
});
|
|
87
88
|
}, [client, user, now]);
|
|
88
|
-
const open = useCallback(async (
|
|
89
|
+
const open = useCallback(async (channel) => {
|
|
89
90
|
if (!client)
|
|
90
91
|
throw Object.assign(new Error('Sign in to open a channel'), { status: 401 });
|
|
91
|
-
const made = await client.http.json({
|
|
92
|
+
const { channel: made } = await client.http.json({
|
|
92
93
|
method: 'POST',
|
|
93
|
-
path: '/v1/team/
|
|
94
|
-
body:
|
|
94
|
+
path: '/v1/team/channels',
|
|
95
|
+
body: channel,
|
|
95
96
|
});
|
|
96
|
-
publish({
|
|
97
|
+
publish({ channels: [...(held.channels ?? []), made], wrong: null });
|
|
97
98
|
return made;
|
|
98
99
|
}, [client]);
|
|
99
|
-
return {
|
|
100
|
+
return { channels: now.channels, wrong: now.wrong, reload: reloadChannels, open };
|
|
100
101
|
}
|
|
101
|
-
/** The
|
|
102
|
-
export function
|
|
103
|
-
return id &&
|
|
102
|
+
/** The channel with that id, or undefined for none open. */
|
|
103
|
+
export function channelOf(channels, id) {
|
|
104
|
+
return id && channels ? channels.find((c) => c.id === id) : undefined;
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
107
|
* One row per id, in the platform's order — `createdOn`, then `id` — so a row
|
|
107
108
|
* held from a send and the same row read back by the next poll sit in one place.
|
|
108
109
|
*/
|
|
109
110
|
const order = (rows) => [...new Map(rows.map((one) => [one.id, one])).values()].sort((a, b) => a.createdOn - b.createdOn || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
110
|
-
/** How often an open
|
|
111
|
+
/** How often an open channel asks what was said. */
|
|
111
112
|
const PACE = 2000;
|
|
112
113
|
/**
|
|
113
|
-
* A
|
|
114
|
+
* A channel's conversation, and the way to add to it.
|
|
114
115
|
*
|
|
115
116
|
* READ AND WRITE IN ONE HOOK, because they are one question — a pane that can
|
|
116
|
-
* show a
|
|
117
|
-
* the sender then cannot disagree about what the
|
|
117
|
+
* show a channel and not answer in it is a directory — and because the poller
|
|
118
|
+
* and the sender then cannot disagree about what the channel holds.
|
|
118
119
|
*
|
|
119
|
-
* THE
|
|
120
|
+
* THE CHANNEL IS POLLED, every two seconds while it is open and the tab is
|
|
120
121
|
* showing. The team plane has no push a browser can read but its transactor
|
|
121
122
|
* socket, which is a binary protocol rather than a line; a read costs a few
|
|
122
123
|
* hundred milliseconds and nothing on the server past the space's own
|
|
123
|
-
* messages, so half a request a second per open
|
|
124
|
+
* messages, so half a request a second per open channel is the honest price of
|
|
124
125
|
* seeing an answer land. Each read carries its own AbortController, and the
|
|
125
126
|
* cleanup aborts the one in flight and stops the clock — on unmount, and when
|
|
126
|
-
* the
|
|
127
|
+
* the channel or its space changes.
|
|
127
128
|
*
|
|
128
129
|
* `send` posts and answers the row the platform stored: a 201 is the message,
|
|
129
130
|
* with its id and stamp, so the hook holds it at once and the next poll finds
|
|
130
131
|
* the same id and keeps one. Nothing the platform did not accept is ever held.
|
|
131
132
|
*
|
|
132
|
-
* `space` is half a
|
|
133
|
-
* with one id), so both calls carry it and a
|
|
134
|
-
* rather than guessing.
|
|
133
|
+
* `space` is half a channel's address (two spaces of one org may each hold a
|
|
134
|
+
* channel with one id), so both calls carry it and a channel with neither reads
|
|
135
|
+
* empty rather than guessing.
|
|
135
136
|
*/
|
|
136
|
-
export function
|
|
137
|
+
export function useMessages(channel, space) {
|
|
137
138
|
const { client } = useAi();
|
|
138
139
|
const { user } = useIam();
|
|
139
140
|
const [messages, setMessages] = useState(null);
|
|
@@ -141,13 +142,13 @@ export function useRoomMessages(room, space) {
|
|
|
141
142
|
const [read, setRead] = useState(0);
|
|
142
143
|
const again = useCallback(() => setRead((n) => n + 1), []);
|
|
143
144
|
useEffect(() => {
|
|
144
|
-
if (!
|
|
145
|
+
if (!channel) {
|
|
145
146
|
setMessages(null);
|
|
146
147
|
return;
|
|
147
148
|
}
|
|
148
149
|
if (!client || !user || !space)
|
|
149
150
|
return;
|
|
150
|
-
const path = `/v1/team/
|
|
151
|
+
const path = `/v1/team/channels/${encodeURIComponent(channel)}/messages`;
|
|
151
152
|
let stop = null;
|
|
152
153
|
const look = () => {
|
|
153
154
|
stop?.abort();
|
|
@@ -159,7 +160,7 @@ export function useRoomMessages(room, space) {
|
|
|
159
160
|
if (signal.aborted)
|
|
160
161
|
return;
|
|
161
162
|
setFailed(null);
|
|
162
|
-
// An empty
|
|
163
|
+
// An empty channel reads empty: `[]` is the answer, not the absence of one.
|
|
163
164
|
setMessages(order(page.messages ?? []));
|
|
164
165
|
})
|
|
165
166
|
.catch((e) => {
|
|
@@ -176,20 +177,20 @@ export function useRoomMessages(room, space) {
|
|
|
176
177
|
clearInterval(clock);
|
|
177
178
|
stop?.abort();
|
|
178
179
|
};
|
|
179
|
-
}, [client, user,
|
|
180
|
+
}, [client, user, channel, space, read]);
|
|
180
181
|
/** Says it and answers the stored row, or throws with the platform's status. */
|
|
181
182
|
const send = useCallback(async (text) => {
|
|
182
|
-
if (!client || !
|
|
183
|
+
if (!client || !channel || !space) {
|
|
183
184
|
throw Object.assign(new Error('This channel has no address to send to'), { status: 503 });
|
|
184
185
|
}
|
|
185
186
|
const row = await client.http.json({
|
|
186
187
|
method: 'POST',
|
|
187
|
-
path: `/v1/team/
|
|
188
|
+
path: `/v1/team/channels/${encodeURIComponent(channel)}/messages`,
|
|
188
189
|
body: { space, text },
|
|
189
190
|
});
|
|
190
191
|
setMessages((held) => order([...(held ?? []), row]));
|
|
191
192
|
again();
|
|
192
193
|
return row;
|
|
193
|
-
}, [client,
|
|
194
|
+
}, [client, channel, space, again]);
|
|
194
195
|
return { messages, failed, send, reload: again };
|
|
195
196
|
}
|
package/dist/conversations.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useInbox } from '@hanzo/ai/react';
|
|
2
2
|
import type { AiClient, Thread } from '@hanzo/ai';
|
|
3
3
|
import type { Member } from './roster.js';
|
|
4
|
-
/** An
|
|
5
|
-
* it without every caller importing the hook's return type. */
|
|
6
|
-
type Arrival = ReturnType<typeof useInbox>['
|
|
4
|
+
/** An arrived channel, as `@hanzo/ai` groups one. Named so this file can speak
|
|
5
|
+
* of it without every caller importing the hook's return type. */
|
|
6
|
+
type Arrival = ReturnType<typeof useInbox>['channels'][number];
|
|
7
7
|
/** One conversation another network carries. */
|
|
8
8
|
export interface Conversation {
|
|
9
9
|
key: string;
|
|
10
10
|
/** What to call it in a list. */
|
|
11
11
|
title: string;
|
|
12
|
-
/** The
|
|
13
|
-
|
|
12
|
+
/** The transport it arrived on. */
|
|
13
|
+
transport: string;
|
|
14
14
|
/** Unix MILLIseconds of the last thing said. The arrival plane stamps
|
|
15
15
|
* SECONDS, and this is the one place that is reconciled. */
|
|
16
16
|
lastAt: number;
|
|
@@ -18,7 +18,7 @@ export interface Conversation {
|
|
|
18
18
|
preview: string;
|
|
19
19
|
arrival: Arrival;
|
|
20
20
|
}
|
|
21
|
-
/** The key for an arrival. `useInbox` already keys a
|
|
21
|
+
/** The key for an arrival. `useInbox` already keys a channel; this qualifies it. */
|
|
22
22
|
export declare const netKey: (arrival: Arrival) => string;
|
|
23
23
|
/**
|
|
24
24
|
* Every conversation this reader has been sent, newest first.
|
|
@@ -35,11 +35,11 @@ export declare function useConversations(): {
|
|
|
35
35
|
export declare function conversationOf(all: Conversation[], key: string | null): Conversation | null;
|
|
36
36
|
export declare const opening: (members: Member[]) => string;
|
|
37
37
|
/**
|
|
38
|
-
* Writes the
|
|
38
|
+
* Writes the conversation and answers its id.
|
|
39
39
|
*
|
|
40
40
|
* The agents in it go in AHEAD of the opening line as the roster turn
|
|
41
41
|
* (cast.tsx `roster`), which is how a conversation keeps who is in it: /chat
|
|
42
|
-
* seats
|
|
42
|
+
* seats them when the thread opens and reads each agent's brief fresh.
|
|
43
43
|
* One agent, several, people, or a mix: all open by this one call.
|
|
44
44
|
*/
|
|
45
45
|
export declare function start(ai: AiClient, members: Member[]): Promise<string>;
|