@hanzo/app 0.3.65 → 0.3.68
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/bots/Bots.d.ts +9 -2
- package/dist/bots/Bots.js +254 -467
- package/dist/bots/Make.d.ts +5 -0
- package/dist/bots/Make.js +60 -0
- package/dist/bots/Panel.d.ts +11 -0
- package/dist/bots/Panel.js +149 -0
- package/dist/bots/Roster.d.ts +11 -0
- package/dist/bots/Roster.js +50 -0
- package/dist/bots/Thread.d.ts +20 -0
- package/dist/bots/Thread.js +148 -0
- package/dist/bots/api.d.ts +27 -102
- package/dist/bots/api.js +26 -65
- package/dist/bots/carry.d.ts +18 -0
- package/dist/bots/carry.js +22 -0
- package/dist/bots/face.js +4 -4
- package/dist/bots/grid.d.ts +10 -0
- package/dist/bots/grid.js +20 -0
- package/dist/bots/ink.d.ts +12 -3
- package/dist/bots/ink.js +21 -22
- package/dist/bots/kit.d.ts +51 -87
- package/dist/bots/kit.js +21 -39
- package/dist/bots/refusal.d.ts +28 -0
- package/dist/bots/refusal.js +62 -0
- package/dist/bots/said.d.ts +34 -0
- package/dist/bots/said.js +43 -0
- package/dist/bots/time.d.ts +16 -0
- package/dist/bots/time.js +86 -0
- package/dist/lib/signout.d.ts +27 -10
- package/dist/lib/signout.js +45 -13
- package/package.json +1 -1
- package/dist/bots/runtime.d.ts +0 -4
- package/dist/bots/runtime.js +0 -388
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The thread as lines: what each recorded run said, stamped where the
|
|
2
|
+
// conversation paused. Pure, so the order a reader sees is tested as data.
|
|
3
|
+
import { BREAK, instant, stamp } from './time.js';
|
|
4
|
+
/** The bot a run's actor names, when another bot asked for it. */
|
|
5
|
+
function asker(run, bots, self) {
|
|
6
|
+
const who = run.actor?.split('/').pop();
|
|
7
|
+
if (!who)
|
|
8
|
+
return undefined;
|
|
9
|
+
return bots.find((b) => b.name !== self && (b.name === who || b.id === who || b.serviceAccountId === who));
|
|
10
|
+
}
|
|
11
|
+
/** The thread as lines: stamps where it paused, each run as the messages it holds. */
|
|
12
|
+
export function lines(runs, bots, self, pending, now, locale, t) {
|
|
13
|
+
const out = [];
|
|
14
|
+
let prev = null;
|
|
15
|
+
const mark = (at, key) => {
|
|
16
|
+
if (prev === null || at - prev > BREAK)
|
|
17
|
+
out.push({ kind: 'stamp', key: `s-${key}`, text: stamp(at, now, locale, t) });
|
|
18
|
+
prev = at;
|
|
19
|
+
};
|
|
20
|
+
for (const r of runs) {
|
|
21
|
+
const at = instant(r.createdAt) ?? now;
|
|
22
|
+
mark(at, r.id);
|
|
23
|
+
// A run another bot asked for opens with that bot's words, marked as its
|
|
24
|
+
// message; any other run's input is yours.
|
|
25
|
+
const from = asker(r, bots, self);
|
|
26
|
+
if (from) {
|
|
27
|
+
out.push({ kind: 'from', key: `f-${r.id}`, bot: from });
|
|
28
|
+
if (r.input)
|
|
29
|
+
out.push({ kind: 'other', key: `i-${r.id}`, text: r.input });
|
|
30
|
+
}
|
|
31
|
+
else if (r.input)
|
|
32
|
+
out.push({ kind: 'mine', key: `i-${r.id}`, text: r.input });
|
|
33
|
+
const said = r.output || r.error;
|
|
34
|
+
if (said)
|
|
35
|
+
out.push({ kind: 'theirs', key: `o-${r.id}`, text: said, failed: !r.output && Boolean(r.error) });
|
|
36
|
+
}
|
|
37
|
+
if (pending) {
|
|
38
|
+
mark(pending.at, 'pending');
|
|
39
|
+
out.push({ kind: 'mine', key: 'pending', text: pending.input });
|
|
40
|
+
out.push({ kind: 'thinking', key: 'thinking' });
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Say } from '@hanzo/i18n';
|
|
2
|
+
/**
|
|
3
|
+
* The stamp a thread centres above a message: "Today 11:23 AM", "Yesterday
|
|
4
|
+
* 12:11 AM", "Mon, Nov 9 4:47 PM", and the year once it is not this one.
|
|
5
|
+
*/
|
|
6
|
+
export declare function stamp(at: number, now: number, locale: string, t?: Say): string;
|
|
7
|
+
/** A message more than this long after the one before it gets its own stamp. */
|
|
8
|
+
export declare const BREAK: number;
|
|
9
|
+
/** An instant from the platform's RFC 3339 string, or null. */
|
|
10
|
+
export declare const instant: (iso: string | undefined) => number | null;
|
|
11
|
+
/**
|
|
12
|
+
* A 5-field cron as a person reads it. The common shapes are said in words —
|
|
13
|
+
* every n minutes, every n hours, daily or on weekdays at a time — and any other
|
|
14
|
+
* shape is shown as the expression itself rather than guessed at.
|
|
15
|
+
*/
|
|
16
|
+
export declare function cron(expr: string, locale: string, t?: Say): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// When things happened, in the words the thread and the panel have room for.
|
|
2
|
+
import { english } from '@hanzo/i18n';
|
|
3
|
+
const DAY = 86_400_000;
|
|
4
|
+
/** Midnight of the day `at` falls on, in the reader's zone. */
|
|
5
|
+
const midnight = (at) => {
|
|
6
|
+
const d = new Date(at);
|
|
7
|
+
d.setHours(0, 0, 0, 0);
|
|
8
|
+
return d.getTime();
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The stamp a thread centres above a message: "Today 11:23 AM", "Yesterday
|
|
12
|
+
* 12:11 AM", "Mon, Nov 9 4:47 PM", and the year once it is not this one.
|
|
13
|
+
*/
|
|
14
|
+
export function stamp(at, now, locale, t = english) {
|
|
15
|
+
const time = new Date(at).toLocaleTimeString(locale, { hour: 'numeric', minute: '2-digit' });
|
|
16
|
+
const days = Math.round((midnight(now) - midnight(at)) / DAY);
|
|
17
|
+
if (days === 0)
|
|
18
|
+
return t('Today {time}', { time });
|
|
19
|
+
if (days === 1)
|
|
20
|
+
return t('Yesterday {time}', { time });
|
|
21
|
+
const sameYear = new Date(at).getFullYear() === new Date(now).getFullYear();
|
|
22
|
+
const date = new Date(at).toLocaleDateString(locale, {
|
|
23
|
+
weekday: 'short',
|
|
24
|
+
month: 'short',
|
|
25
|
+
day: 'numeric',
|
|
26
|
+
...(sameYear ? {} : { year: 'numeric' }),
|
|
27
|
+
});
|
|
28
|
+
return `${date} ${time}`;
|
|
29
|
+
}
|
|
30
|
+
/** A message more than this long after the one before it gets its own stamp. */
|
|
31
|
+
export const BREAK = 30 * 60_000;
|
|
32
|
+
/** An instant from the platform's RFC 3339 string, or null. */
|
|
33
|
+
export const instant = (iso) => {
|
|
34
|
+
if (!iso)
|
|
35
|
+
return null;
|
|
36
|
+
const n = Date.parse(iso);
|
|
37
|
+
return Number.isNaN(n) ? null : n;
|
|
38
|
+
};
|
|
39
|
+
const WEEKDAYS = '1-5';
|
|
40
|
+
/** "9:00 AM" for an hour and minute, in the reader's locale. */
|
|
41
|
+
const clock = (hour, minute, locale) => new Date(2000, 0, 1, hour, minute).toLocaleTimeString(locale, { hour: 'numeric', minute: '2-digit' });
|
|
42
|
+
/** A whole number from a cron field, or null where the field is anything else. */
|
|
43
|
+
const whole = (field) => (/^\d+$/.test(field) ? Number(field) : null);
|
|
44
|
+
/** The step of a `*\/n` field, or null. */
|
|
45
|
+
const step = (field) => {
|
|
46
|
+
const m = /^\*\/(\d+)$/.exec(field);
|
|
47
|
+
return m ? Number(m[1]) : null;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A 5-field cron as a person reads it. The common shapes are said in words —
|
|
51
|
+
* every n minutes, every n hours, daily or on weekdays at a time — and any other
|
|
52
|
+
* shape is shown as the expression itself rather than guessed at.
|
|
53
|
+
*/
|
|
54
|
+
export function cron(expr, locale, t = english) {
|
|
55
|
+
const parts = expr.trim().split(/\s+/);
|
|
56
|
+
if (parts.length !== 5)
|
|
57
|
+
return expr;
|
|
58
|
+
const [minute, hour, dom, month, dow] = parts;
|
|
59
|
+
if (dom !== '*' || month !== '*')
|
|
60
|
+
return expr;
|
|
61
|
+
const weekdays = dow === WEEKDAYS;
|
|
62
|
+
if (dow !== '*' && !weekdays)
|
|
63
|
+
return expr;
|
|
64
|
+
const everyMinutes = step(minute);
|
|
65
|
+
if (everyMinutes !== null && hour === '*') {
|
|
66
|
+
return weekdays
|
|
67
|
+
? t('Every {n} minutes on weekdays', { n: everyMinutes })
|
|
68
|
+
: t('Every {n} minutes', { n: everyMinutes });
|
|
69
|
+
}
|
|
70
|
+
const m = whole(minute);
|
|
71
|
+
if (m === null)
|
|
72
|
+
return expr;
|
|
73
|
+
if (hour === '*')
|
|
74
|
+
return weekdays ? t('Every hour on weekdays') : t('Every hour');
|
|
75
|
+
const everyHours = step(hour);
|
|
76
|
+
if (everyHours !== null) {
|
|
77
|
+
return weekdays
|
|
78
|
+
? t('Every {n} hours on weekdays', { n: everyHours })
|
|
79
|
+
: t('Every {n} hours', { n: everyHours });
|
|
80
|
+
}
|
|
81
|
+
const h = whole(hour);
|
|
82
|
+
if (h === null || h > 23 || m > 59)
|
|
83
|
+
return expr;
|
|
84
|
+
const at = clock(h, m, locale);
|
|
85
|
+
return weekdays ? t('Weekdays at {time}', { time: at }) : t('Every day at {time}', { time: at });
|
|
86
|
+
}
|
package/dist/lib/signout.d.ts
CHANGED
|
@@ -7,25 +7,42 @@ import { IAM } from '@hanzo/iam';
|
|
|
7
7
|
export declare const here: () => boolean;
|
|
8
8
|
/** The IAM client for this page; the token exchange at the callback shares its PKCE store. */
|
|
9
9
|
export declare function useClient(): IAM;
|
|
10
|
-
/**
|
|
10
|
+
/** This site's sign-in after a sign-out, which does not ask IAM for the session just ended. */
|
|
11
11
|
export declare const OUT = "/login?from=logout";
|
|
12
|
+
/**
|
|
13
|
+
* Where a plain sign-out lands: this site's home page. Every host this export is
|
|
14
|
+
* served on (hanzo.ai, hanzo.app, hanzo.bot) has a marketing page there, and a
|
|
15
|
+
* person who signed out is brought back to it rather than to a sign-in form. IAM
|
|
16
|
+
* returns the browser to it when the client registered it (universe
|
|
17
|
+
* iam-provision.yaml); otherwise it lands on hanzo.ai/login.
|
|
18
|
+
*/
|
|
19
|
+
export declare const HOME = "/";
|
|
20
|
+
/**
|
|
21
|
+
* The end-session page a sign-out everywhere leaves through: hanzo.ai's, the
|
|
22
|
+
* origin every Hanzo site signs in on and so the one holding the person's session.
|
|
23
|
+
* IAM ends the session there and walks the issuer's other sign-in origins
|
|
24
|
+
* (hanzo.id, hanzo.market) by the request's own Host, so the page has to be one of
|
|
25
|
+
* them: the configured `serverUrl` (api.hanzo.ai, where the token calls go) is
|
|
26
|
+
* none, and an end-session there ends nothing past it. A brand with an issuer of
|
|
27
|
+
* its own ends on that issuer; a dev server on this machine ends here ('').
|
|
28
|
+
*/
|
|
29
|
+
export declare function endsAt(serverUrl: string, hostname: string): string;
|
|
12
30
|
/**
|
|
13
31
|
* Sign-out on this site: @hanzo/ui/auth's `signOut` — the tokens handed back to
|
|
14
32
|
* IAM's /v1/iam routes, IAM's session here ended, the local session cleared —
|
|
15
|
-
* counted as logout_completed, and then
|
|
16
|
-
* chooser, which signs everyone out and stays on the request it was drawn
|
|
17
|
-
*
|
|
33
|
+
* counted as logout_completed, and then this site's home page (or `to`: the
|
|
34
|
+
* account chooser, which signs everyone out and stays on the request it was drawn
|
|
35
|
+
* for).
|
|
18
36
|
*
|
|
19
37
|
* EVERY HANZO SITE AT ONCE (`everywhere`). hanzo.ai and platform.hanzo.ai sign in
|
|
20
38
|
* from one session, so leaving one of them must leave the other: IAM retires the
|
|
21
39
|
* person's grant to every application of this client's organization along with
|
|
22
40
|
* the session. A third-party app the person signed into keeps its own.
|
|
23
41
|
*
|
|
24
|
-
* AND EVERY SIGN-IN ORIGIN (D3). A plain sign-out ends through
|
|
25
|
-
* end-session page (`
|
|
26
|
-
* and hanzo.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* only (an empty issuer).
|
|
42
|
+
* AND EVERY SIGN-IN ORIGIN (D3). A plain sign-out ends through hanzo.ai's
|
|
43
|
+
* end-session page (`endsAt`, passed to @hanzo/ui 8.31 as `issuer`), which ends
|
|
44
|
+
* the session there and on hanzo.id and hanzo.market too, as well as this
|
|
45
|
+
* origin's. A sign-out with its own `to` is the account chooser's, which must stay
|
|
46
|
+
* on the request in flight, so it ends here only (an empty issuer).
|
|
30
47
|
*/
|
|
31
48
|
export declare function useSignOut(to?: string): () => Promise<void>;
|
package/dist/lib/signout.js
CHANGED
|
@@ -13,7 +13,7 @@ import { IAM } from '@hanzo/iam';
|
|
|
13
13
|
import { useIam } from '@hanzo/iam/react';
|
|
14
14
|
import { useSignOut as useUiSignOut } from '@hanzo/ui/auth';
|
|
15
15
|
import { track } from './tags.js';
|
|
16
|
-
import { answers } from './host.js';
|
|
16
|
+
import { answers, SIGNIN } from './host.js';
|
|
17
17
|
import { where } from '../where.js';
|
|
18
18
|
/**
|
|
19
19
|
* Whether the page in front of us is on an origin that answers IAM itself: one of
|
|
@@ -27,30 +27,62 @@ export function useClient() {
|
|
|
27
27
|
const local = here();
|
|
28
28
|
return useMemo(() => new IAM(local ? { ...config, proxyBaseUrl: window.location.origin } : config), [config, local]);
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
30
|
+
/** This site's sign-in after a sign-out, which does not ask IAM for the session just ended. */
|
|
31
31
|
export const OUT = '/login?from=logout';
|
|
32
|
+
/**
|
|
33
|
+
* Where a plain sign-out lands: this site's home page. Every host this export is
|
|
34
|
+
* served on (hanzo.ai, hanzo.app, hanzo.bot) has a marketing page there, and a
|
|
35
|
+
* person who signed out is brought back to it rather than to a sign-in form. IAM
|
|
36
|
+
* returns the browser to it when the client registered it (universe
|
|
37
|
+
* iam-provision.yaml); otherwise it lands on hanzo.ai/login.
|
|
38
|
+
*/
|
|
39
|
+
export const HOME = '/';
|
|
40
|
+
/** A dev server on this machine, which keeps its sign-out local. */
|
|
41
|
+
const loopback = (hostname) => hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]' || hostname.endsWith('.localhost');
|
|
42
|
+
/**
|
|
43
|
+
* The end-session page a sign-out everywhere leaves through: hanzo.ai's, the
|
|
44
|
+
* origin every Hanzo site signs in on and so the one holding the person's session.
|
|
45
|
+
* IAM ends the session there and walks the issuer's other sign-in origins
|
|
46
|
+
* (hanzo.id, hanzo.market) by the request's own Host, so the page has to be one of
|
|
47
|
+
* them: the configured `serverUrl` (api.hanzo.ai, where the token calls go) is
|
|
48
|
+
* none, and an end-session there ends nothing past it. A brand with an issuer of
|
|
49
|
+
* its own ends on that issuer; a dev server on this machine ends here ('').
|
|
50
|
+
*/
|
|
51
|
+
export function endsAt(serverUrl, hostname) {
|
|
52
|
+
if (loopback(hostname))
|
|
53
|
+
return '';
|
|
54
|
+
try {
|
|
55
|
+
const host = new URL(serverUrl).hostname;
|
|
56
|
+
if (host === 'api.hanzo.ai' || host === 'hanzo.id' || host === 'hanzo.ai')
|
|
57
|
+
return SIGNIN;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
return serverUrl;
|
|
63
|
+
}
|
|
32
64
|
/**
|
|
33
65
|
* Sign-out on this site: @hanzo/ui/auth's `signOut` — the tokens handed back to
|
|
34
66
|
* IAM's /v1/iam routes, IAM's session here ended, the local session cleared —
|
|
35
|
-
* counted as logout_completed, and then
|
|
36
|
-
* chooser, which signs everyone out and stays on the request it was drawn
|
|
37
|
-
*
|
|
67
|
+
* counted as logout_completed, and then this site's home page (or `to`: the
|
|
68
|
+
* account chooser, which signs everyone out and stays on the request it was drawn
|
|
69
|
+
* for).
|
|
38
70
|
*
|
|
39
71
|
* EVERY HANZO SITE AT ONCE (`everywhere`). hanzo.ai and platform.hanzo.ai sign in
|
|
40
72
|
* from one session, so leaving one of them must leave the other: IAM retires the
|
|
41
73
|
* person's grant to every application of this client's organization along with
|
|
42
74
|
* the session. A third-party app the person signed into keeps its own.
|
|
43
75
|
*
|
|
44
|
-
* AND EVERY SIGN-IN ORIGIN (D3). A plain sign-out ends through
|
|
45
|
-
* end-session page (`
|
|
46
|
-
* and hanzo.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* only (an empty issuer).
|
|
76
|
+
* AND EVERY SIGN-IN ORIGIN (D3). A plain sign-out ends through hanzo.ai's
|
|
77
|
+
* end-session page (`endsAt`, passed to @hanzo/ui 8.31 as `issuer`), which ends
|
|
78
|
+
* the session there and on hanzo.id and hanzo.market too, as well as this
|
|
79
|
+
* origin's. A sign-out with its own `to` is the account chooser's, which must stay
|
|
80
|
+
* on the request in flight, so it ends here only (an empty issuer).
|
|
50
81
|
*/
|
|
51
|
-
export function useSignOut(to =
|
|
82
|
+
export function useSignOut(to = HOME) {
|
|
52
83
|
const { config } = useIam();
|
|
53
|
-
const
|
|
84
|
+
const plain = to === HOME || to === OUT;
|
|
85
|
+
const issuer = plain && typeof window !== 'undefined' ? endsAt(config.serverUrl, window.location.hostname) : '';
|
|
54
86
|
const signOut = useUiSignOut({ to, track, everywhere: true, issuer });
|
|
55
87
|
return useCallback(async () => {
|
|
56
88
|
// Google One Tap signs a returning person in on its own (`auto_select`), which
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.68",
|
|
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",
|
package/dist/bots/runtime.d.ts
DELETED