@hanzo/build 0.2.118 → 0.2.119
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 +25 -4
- package/lib/api/agents.d.ts +4 -2
- package/lib/api/agents.js +5 -3
- package/lib/api/chat.d.ts +1 -1
- package/lib/api/chat.js +2 -2
- package/lib/api/draft.d.ts +33 -0
- package/lib/api/draft.js +81 -0
- package/lib/api/gallery.d.ts +32 -0
- package/lib/api/gallery.js +85 -0
- package/lib/customize/agents.js +35 -8
- package/lib/customize/drafted.d.ts +4 -0
- package/lib/customize/drafted.js +79 -0
- package/lib/customize/inventory.d.ts +11 -0
- package/lib/customize/inventory.js +78 -0
- package/lib/customize/ocean.d.ts +41 -0
- package/lib/customize/ocean.js +332 -0
- package/lib/customize/ui.d.ts +9 -2
- package/lib/customize/ui.js +33 -4
- package/lib/host.d.ts +7 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/landing.js +1 -1
- package/lib/library.js +7 -7
- package/lib/make.d.ts +10 -0
- package/lib/make.js +113 -0
- package/lib/marks.d.ts +15 -0
- package/lib/marks.js +18 -0
- package/lib/mind.d.ts +29 -3
- package/lib/mind.js +73 -6
- package/lib/nav.d.ts +1 -1
- package/lib/nav.js +16 -8
- package/lib/route.d.ts +3 -2
- package/lib/route.js +2 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -119,7 +119,7 @@ One of each, shared with Chat (@hanzo/rooms imports them):
|
|
|
119
119
|
|
|
120
120
|
- `useMind` — the model and effort: `GET /v1/models` read once per platform,
|
|
121
121
|
and the choice kept in this browser (`hanzo.mind`, Enso and Auto until
|
|
122
|
-
changed). The composer's row changes it: the effort (Auto, High,
|
|
122
|
+
changed). The composer's row changes it: the effort (Auto, High,
|
|
123
123
|
Max) always, the model chip only where the person turned the model selector
|
|
124
124
|
on (Settings → Appearance, `@hanzo/appearance` `composing`). Settings → Code
|
|
125
125
|
writes the same choice. `@hanzo/build/mind` serves the store alone, without
|
|
@@ -250,8 +250,29 @@ are any member's.
|
|
|
250
250
|
`-2`, `-3`), with its face, model and instructions, and opens its profile;
|
|
251
251
|
nothing is added in bulk. Start from scratch, Clone yourself (the person
|
|
252
252
|
signed in, with writing pasted or uploaded) and Create from a person make one
|
|
253
|
-
too.
|
|
254
|
-
|
|
253
|
+
too. Clone yourself also asks the Big Five: the IPIP 50-item markers or the
|
|
254
|
+
IPIP-NEO-120 with its 30 facets (`customize/ocean.ts`, public domain), one
|
|
255
|
+
statement a screen on a phone, kept in this browser (`hanzo.build.ocean.<email>`)
|
|
256
|
+
as it is answered. The raw 1-5 means, and a line for each domain at either
|
|
257
|
+
end, seed the instructions, shown to edit before the agent is made; the
|
|
258
|
+
answers stay in the browser. Make with AI is one box above them: a name or a
|
|
259
|
+
description, drafted by Enso (`api/draft.ts`) into a name, role, instructions
|
|
260
|
+
and an opening line shown once, editable, with Save; a real historical figure
|
|
261
|
+
gets a public-domain or CC0 portrait from Wikimedia Commons where one is free
|
|
262
|
+
to use, any other agent the emoji the model chose. An agent's model is picked
|
|
263
|
+
from `scope="agent"`: text out, tools and reasoning not ruled out, in groups
|
|
264
|
+
by maker, with what cannot run one in a shut group at the end. Yours is the
|
|
265
|
+
org's own — model, instructions, tools, budget — created, edited (only what
|
|
266
|
+
changed is sent) and deleted.
|
|
267
|
+
|
|
268
|
+
**Marks and models.** `MARKS` (`marks.tsx`) is the one icon for each product and
|
|
269
|
+
place, and for what each starts (the pen in Chat, `</>` in Dev, the terminal in
|
|
270
|
+
Tabs); the rail, the bar, the sidebars, the palette and the pages read it. The
|
|
271
|
+
comparison vendor's models (`owned_by` typesafe, Jev) are in no picker. Another
|
|
272
|
+
maker's models are paid from the prepaid balance on any plan: a host that sets
|
|
273
|
+
`Host.topUp` gets `useMind`/`useFunds` reading `GET /v1/billing/balance`, so on
|
|
274
|
+
Free they are selectable with a balance and say Top up without one, and a top-up
|
|
275
|
+
returns to the page with `?model=`; Hanzo's own models follow the plan.
|
|
255
276
|
|
|
256
277
|
**New.** "What's up next?", and at the foot the composer: where the run runs
|
|
257
278
|
(Cloud is the platform's sandbox with the codebase's environment; the org's
|
|
@@ -360,7 +381,7 @@ picker and open-in-tab; Share and Publish; the console dock under it.
|
|
|
360
381
|
`enso-auto`, never left out — and `issue`, the number a run started from an
|
|
361
382
|
issue closes; the platform honours them where it does and nothing here
|
|
362
383
|
simulates them. A run takes `low`, `medium` or `high`, so Auto names `medium`
|
|
363
|
-
and High
|
|
384
|
+
and High and Max name `high` (`level`).
|
|
364
385
|
|
|
365
386
|
## Layout
|
|
366
387
|
|
package/lib/api/agents.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export interface Draft {
|
|
|
46
46
|
period: Period;
|
|
47
47
|
/** Sent on create only: an https link or a data URL. */
|
|
48
48
|
avatar: string;
|
|
49
|
+
/** Sent on create only, and only when there is no avatar: one emoji. */
|
|
50
|
+
emoji?: string;
|
|
49
51
|
executionMode?: Mode;
|
|
50
52
|
schedule?: string;
|
|
51
53
|
triggers?: Trigger[];
|
|
@@ -128,8 +130,8 @@ export declare const link: (at: string | undefined, base: string) => string;
|
|
|
128
130
|
* and its face linked. The template is not touched.
|
|
129
131
|
*/
|
|
130
132
|
export declare function use(t: Target, c: Cast, base: string, overrides?: Partial<Pick<Draft, 'executionMode' | 'schedule' | 'triggers' | 'model' | 'tools' | 'cap' | 'task' | 'period'>>): Promise<Agent>;
|
|
131
|
-
/** Anyone as a template: their name, who they are, and writing of theirs to take the voice from. */
|
|
132
|
-
export declare function person(name: string, about: string, writing: string, avatar?: string): Cast;
|
|
133
|
+
/** Anyone as a template: their name, who they are, how they think and write (ocean.ts `nature`), and writing of theirs to take the voice from. */
|
|
134
|
+
export declare function person(name: string, about: string, writing: string, avatar?: string, nature?: string): Cast;
|
|
133
135
|
export declare function create(t: Target, d: Draft): Promise<Agent>;
|
|
134
136
|
/** The fields that differ from `was`, and nothing else: an omitted field keeps its value. */
|
|
135
137
|
export declare function changes(was: Agent, d: Draft): Record<string, unknown>;
|
package/lib/api/agents.js
CHANGED
|
@@ -181,10 +181,10 @@ export async function use(t, c, base, overrides) {
|
|
|
181
181
|
...(triggers?.length ? { triggers } : {}),
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
|
-
/** Anyone as a template: their name, who they are, and writing of theirs to take the voice from. */
|
|
185
|
-
export function person(name, about, writing, avatar = '') {
|
|
184
|
+
/** Anyone as a template: their name, who they are, how they think and write (ocean.ts `nature`), and writing of theirs to take the voice from. */
|
|
185
|
+
export function person(name, about, writing, avatar = '', nature = '') {
|
|
186
186
|
const who = name.trim();
|
|
187
|
-
const lines = [`You are ${who}.`, about.trim(), writing.trim() && `Writing by ${who}:\n\n${writing.trim()}`];
|
|
187
|
+
const lines = [`You are ${who}.`, about.trim(), nature, writing.trim() && `Writing by ${who}:\n\n${writing.trim()}`];
|
|
188
188
|
return { name: who, title: who, description: about.trim(), category: phrase('Person'), model: '', instructions: lines.filter(Boolean).join('\n\n'), avatar };
|
|
189
189
|
}
|
|
190
190
|
export async function create(t, d) {
|
|
@@ -204,6 +204,8 @@ export async function create(t, d) {
|
|
|
204
204
|
body.model = d.model;
|
|
205
205
|
if (d.avatar)
|
|
206
206
|
body.avatar = d.avatar;
|
|
207
|
+
else if (d.emoji)
|
|
208
|
+
body.emoji = d.emoji;
|
|
207
209
|
if (d.executionMode)
|
|
208
210
|
body.executionMode = d.executionMode;
|
|
209
211
|
if (d.schedule?.trim())
|
package/lib/api/chat.d.ts
CHANGED
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
import { type Target } from './call.ts';
|
|
8
8
|
/** The quick model a plugin thinks with: planning a search, drafting a template. */
|
|
9
9
|
export declare const QUICK = "enso-flash";
|
|
10
|
-
export declare function ask(t: Target, system: string, user: string, signal?: AbortSignal, tokens?: number): Promise<string>;
|
|
10
|
+
export declare function ask(t: Target, system: string, user: string, signal?: AbortSignal, tokens?: number, model?: string): Promise<string>;
|
|
11
11
|
/** The first JSON object in a model's answer, or null: a model may talk around it. */
|
|
12
12
|
export declare function json(said: string): Record<string, unknown> | null;
|
package/lib/api/chat.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
import { call } from './call.js';
|
|
8
8
|
/** The quick model a plugin thinks with: planning a search, drafting a template. */
|
|
9
9
|
export const QUICK = 'enso-flash';
|
|
10
|
-
export async function ask(t, system, user, signal, tokens = 800) {
|
|
11
|
-
const raw = await call(t, 'POST', '/v1/chat/completions', { model
|
|
10
|
+
export async function ask(t, system, user, signal, tokens = 800, model = QUICK) {
|
|
11
|
+
const raw = await call(t, 'POST', '/v1/chat/completions', { model, max_tokens: tokens, messages: [{ role: 'system', content: system }, { role: 'user', content: user }] }, { signal });
|
|
12
12
|
const said = raw?.choices?.[0]?.message?.content;
|
|
13
13
|
return typeof said === 'string' ? said : '';
|
|
14
14
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Target } from './call.ts';
|
|
2
|
+
/** What the model drafts. */
|
|
3
|
+
export interface Sketch {
|
|
4
|
+
/** One short word the agent is called by. */
|
|
5
|
+
name: string;
|
|
6
|
+
role: string;
|
|
7
|
+
instructions: string;
|
|
8
|
+
/** The first line it says, kept in its instructions. */
|
|
9
|
+
opening: string;
|
|
10
|
+
/** One emoji for a role; '' for a person. */
|
|
11
|
+
emoji: string;
|
|
12
|
+
/** The full name of a real historical person, '' for anyone or anything else. */
|
|
13
|
+
figure: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const SYSTEM: string;
|
|
16
|
+
/** A model's answer as a draft: the fields that are text, or null where it named no one to draft. */
|
|
17
|
+
export declare function parse(said: string): Sketch | null;
|
|
18
|
+
/** The line they typed, drafted. */
|
|
19
|
+
export declare function sketch(t: Target, line: string, signal?: AbortSignal): Promise<Sketch>;
|
|
20
|
+
/** The instructions as saved: what the model wrote, then the first line it says. */
|
|
21
|
+
export declare const saved: (s: Pick<Sketch, 'instructions' | 'opening'>) => string;
|
|
22
|
+
/** A portrait that is free to use, and where it came from. */
|
|
23
|
+
export interface Portrait {
|
|
24
|
+
url: string;
|
|
25
|
+
page: string;
|
|
26
|
+
licence: string;
|
|
27
|
+
}
|
|
28
|
+
/** A licence the portrait may be used under without asking: public domain or CC0. */
|
|
29
|
+
export declare const free: (licence: string) => boolean;
|
|
30
|
+
/** The Commons answer for a search over files, as a portrait that is free to use, or null. */
|
|
31
|
+
export declare function portraitOf(body: unknown): Portrait | null;
|
|
32
|
+
/** A public-domain portrait of a historical figure from Wikimedia Commons, or null; any failure is no portrait. */
|
|
33
|
+
export declare function portrait(name: string, signal?: AbortSignal): Promise<Portrait | null>;
|
package/lib/api/draft.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An agent drafted from one line: a name ("Marie Curie") or a description ("a
|
|
3
|
+
* skeptical CFO", "my grandmother who taught maths"). A Hanzo model, asked with
|
|
4
|
+
* the person's own bearer, writes the draft; nothing is created until they save it.
|
|
5
|
+
*
|
|
6
|
+
* POST /v1/chat/completions Enso, the router every plan grants
|
|
7
|
+
* GET commons.wikimedia.org a public-domain portrait, for a historical figure only
|
|
8
|
+
*/
|
|
9
|
+
import { ask, json } from './chat.js';
|
|
10
|
+
import { ENSO } from './models.js';
|
|
11
|
+
export const SYSTEM = [
|
|
12
|
+
'You draft one agent for a person\'s own team from one line they typed: a name or a description.',
|
|
13
|
+
'Reply with one JSON object and nothing else: {"name","role","instructions","opening","emoji","figure"}.',
|
|
14
|
+
'name: one short word the agent goes by, letters and digits only (Curie, Marie, Cfo).',
|
|
15
|
+
'role: two to four words.',
|
|
16
|
+
'instructions: second person, "You are ...", plain and specific: what you do, how you speak, how you work. For a real historical person, speak in their own voice and from what they wrote and did, and say when a question is past what they could have known.',
|
|
17
|
+
'opening: the one short line you say first.',
|
|
18
|
+
'emoji: one emoji that fits a role; "" for a real person.',
|
|
19
|
+
'figure: the full name of a real historical person who died more than seventy years ago when the line names one; "" otherwise.',
|
|
20
|
+
].join(' ');
|
|
21
|
+
const word = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
22
|
+
/** A model's answer as a draft: the fields that are text, or null where it named no one to draft. */
|
|
23
|
+
export function parse(said) {
|
|
24
|
+
const o = json(said);
|
|
25
|
+
if (!o)
|
|
26
|
+
return null;
|
|
27
|
+
const name = word(o.name).replace(/[^\p{L}\p{N}._-]+/gu, '').slice(0, 40);
|
|
28
|
+
const instructions = word(o.instructions);
|
|
29
|
+
if (!name || !instructions)
|
|
30
|
+
return null;
|
|
31
|
+
return { name, role: word(o.role), instructions, opening: word(o.opening), emoji: word(o.emoji).slice(0, 8), figure: word(o.figure) };
|
|
32
|
+
}
|
|
33
|
+
/** The line they typed, drafted. */
|
|
34
|
+
export async function sketch(t, line, signal) {
|
|
35
|
+
const said = await ask(t, SYSTEM, line.trim(), signal, 1200, ENSO);
|
|
36
|
+
const draft = parse(said);
|
|
37
|
+
if (!draft)
|
|
38
|
+
throw new Error('The draft did not come out. Try again.');
|
|
39
|
+
return draft;
|
|
40
|
+
}
|
|
41
|
+
/** The instructions as saved: what the model wrote, then the first line it says. */
|
|
42
|
+
export const saved = (s) => (s.opening ? `${s.instructions.trim()}\n\nBegin a new conversation with: ${s.opening}` : s.instructions.trim());
|
|
43
|
+
/** A licence the portrait may be used under without asking: public domain or CC0. */
|
|
44
|
+
export const free = (licence) => /^(public domain|pd\b|cc0)/i.test(licence.trim());
|
|
45
|
+
/** The Commons answer for a search over files, as a portrait that is free to use, or null. */
|
|
46
|
+
export function portraitOf(body) {
|
|
47
|
+
const pages = body?.query?.pages;
|
|
48
|
+
if (!pages)
|
|
49
|
+
return null;
|
|
50
|
+
const rows = Object.values(pages);
|
|
51
|
+
for (const r of rows.sort((a, b) => (a.index ?? 0) - (b.index ?? 0))) {
|
|
52
|
+
const info = r.imageinfo?.[0];
|
|
53
|
+
const licence = word(info?.extmetadata?.LicenseShortName?.value);
|
|
54
|
+
const url = word(info?.thumburl) || word(info?.url);
|
|
55
|
+
if (info && url.startsWith('https://') && free(licence))
|
|
56
|
+
return { url, page: word(info.descriptionurl), licence };
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
/** A public-domain portrait of a historical figure from Wikimedia Commons, or null; any failure is no portrait. */
|
|
61
|
+
export async function portrait(name, signal) {
|
|
62
|
+
const q = new URLSearchParams({
|
|
63
|
+
action: 'query',
|
|
64
|
+
format: 'json',
|
|
65
|
+
origin: '*',
|
|
66
|
+
generator: 'search',
|
|
67
|
+
gsrsearch: `${name} portrait`,
|
|
68
|
+
gsrnamespace: '6',
|
|
69
|
+
gsrlimit: '8',
|
|
70
|
+
prop: 'imageinfo',
|
|
71
|
+
iiprop: 'url|extmetadata',
|
|
72
|
+
iiurlwidth: '256',
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
const r = await fetch(`https://commons.wikimedia.org/w/api.php?${q}`, { signal });
|
|
76
|
+
return r.ok ? portraitOf(await r.json()) : null;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const GALLERY = "https://gallery.hanzo.ai/templates.json";
|
|
2
|
+
export declare const KINDS: readonly ['site', 'agent'];
|
|
3
|
+
export type Kind = (typeof KINDS)[number];
|
|
4
|
+
/** Each kind's name, English and marked (`phrase`), drawn through `t`. */
|
|
5
|
+
export declare const KIND: Record<Kind, string>;
|
|
6
|
+
/** Where each kind is made. */
|
|
7
|
+
export type App = 'dev' | 'agents';
|
|
8
|
+
export declare const APP: Record<Kind, App>;
|
|
9
|
+
export interface Template {
|
|
10
|
+
slug: string;
|
|
11
|
+
name: string;
|
|
12
|
+
kind: Kind;
|
|
13
|
+
category: string;
|
|
14
|
+
description: string;
|
|
15
|
+
/** Its capture, an https address, or ''. */
|
|
16
|
+
preview: string;
|
|
17
|
+
/** An agent's instructions and model ('' the deployment's default); '' for a site. */
|
|
18
|
+
instructions: string;
|
|
19
|
+
model: string;
|
|
20
|
+
/** What a search reads, lower case. */
|
|
21
|
+
words: string;
|
|
22
|
+
}
|
|
23
|
+
/** What the screen says when the catalogue cannot be read, whatever the reason. */
|
|
24
|
+
export declare const UNREAD: string;
|
|
25
|
+
/** One row as the gallery serves it, or null for one this Library cannot offer. */
|
|
26
|
+
export declare function template(raw: unknown): Template | null;
|
|
27
|
+
/** The gallery's templates, in its order, each slug once. Any failure is `UNREAD`; an abort stays an abort. */
|
|
28
|
+
export declare function catalogue(init?: {
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}): Promise<Template[]>;
|
|
31
|
+
/** The templates of `kind` ('' every kind) holding every word of `q`. */
|
|
32
|
+
export declare function narrow(list: readonly Template[], kind: Kind | '', q: string): Template[];
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gallery: gallery.hanzo.ai's templates, read live from the one catalogue it
|
|
3
|
+
* publishes (hanzoai/gallery `scripts/gen-templates-json.mjs`).
|
|
4
|
+
*
|
|
5
|
+
* GET https://gallery.hanzo.ai/templates.json {version, templates: [row]}
|
|
6
|
+
*
|
|
7
|
+
* Reference content: no bearer, no org. A row is a starter kit — a repository
|
|
8
|
+
* with a capture of its page — and names no kind, so a row with a repository is
|
|
9
|
+
* a site. A row that names a kind is that kind; one this reader does not know,
|
|
10
|
+
* or one missing what its kind is made from, is left out.
|
|
11
|
+
*
|
|
12
|
+
* A site is made in Dev, as a copy of its repository (projects.ts `fork`); an
|
|
13
|
+
* agent in Customize › Agents, as the org's own (agents.ts `use`).
|
|
14
|
+
*/
|
|
15
|
+
import { phrase } from '@hanzo/i18n';
|
|
16
|
+
import { SLUG } from '../route.js';
|
|
17
|
+
export const GALLERY = 'https://gallery.hanzo.ai/templates.json';
|
|
18
|
+
export const KINDS = ['site', 'agent'];
|
|
19
|
+
/** Each kind's name, English and marked (`phrase`), drawn through `t`. */
|
|
20
|
+
export const KIND = { site: phrase('Site'), agent: phrase('Agent') };
|
|
21
|
+
export const APP = { site: 'dev', agent: 'agents' };
|
|
22
|
+
/** What the screen says when the catalogue cannot be read, whatever the reason. */
|
|
23
|
+
export const UNREAD = phrase('The gallery is not answering right now.');
|
|
24
|
+
const str = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
25
|
+
const obj = (v) => (v && typeof v === 'object' ? v : {});
|
|
26
|
+
const https = (v) => (/^https:\/\/\S+$/.test(str(v)) ? str(v) : '');
|
|
27
|
+
const strs = (v) => (Array.isArray(v) ? v.map(str).filter(Boolean) : []);
|
|
28
|
+
/** One row as the gallery serves it, or null for one this Library cannot offer. */
|
|
29
|
+
export function template(raw) {
|
|
30
|
+
const o = obj(raw);
|
|
31
|
+
const slug = str(o.slug);
|
|
32
|
+
if (!SLUG.test(slug))
|
|
33
|
+
return null;
|
|
34
|
+
// A row names its kind, or is a site by its repository.
|
|
35
|
+
const kind = (str(o.kind) || (https(o.repo) ? 'site' : ''));
|
|
36
|
+
if (!KINDS.includes(kind))
|
|
37
|
+
return null;
|
|
38
|
+
const instructions = kind === 'agent' ? str(o.instructions) : '';
|
|
39
|
+
if (kind === 'agent' && !instructions)
|
|
40
|
+
return null;
|
|
41
|
+
const name = str(o.displayName) || str(o.name) || slug;
|
|
42
|
+
const category = str(o.category);
|
|
43
|
+
const description = str(o.description);
|
|
44
|
+
return {
|
|
45
|
+
slug,
|
|
46
|
+
name,
|
|
47
|
+
kind,
|
|
48
|
+
category,
|
|
49
|
+
description,
|
|
50
|
+
preview: o.hasScreenshot === false ? '' : https(o.screenshotUrl),
|
|
51
|
+
instructions,
|
|
52
|
+
model: kind === 'agent' ? str(o.model) : '',
|
|
53
|
+
words: [name, slug, category, description, str(o.useCase), str(o.framework), ...strs(o.features), ...strs(o.intents)].join(' ').toLowerCase(),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** The gallery's templates, in its order, each slug once. Any failure is `UNREAD`; an abort stays an abort. */
|
|
57
|
+
export async function catalogue(init) {
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
const res = await fetch(GALLERY, { signal: init?.signal, cache: 'no-cache' });
|
|
61
|
+
if (!res.ok)
|
|
62
|
+
throw new Error(String(res.status));
|
|
63
|
+
raw = await res.json();
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
if (init?.signal?.aborted)
|
|
67
|
+
throw e;
|
|
68
|
+
throw new Error(UNREAD);
|
|
69
|
+
}
|
|
70
|
+
const rows = obj(raw).templates;
|
|
71
|
+
if (!Array.isArray(rows))
|
|
72
|
+
throw new Error(UNREAD);
|
|
73
|
+
const out = new Map();
|
|
74
|
+
for (const r of rows) {
|
|
75
|
+
const x = template(r);
|
|
76
|
+
if (x && !out.has(x.slug))
|
|
77
|
+
out.set(x.slug, x);
|
|
78
|
+
}
|
|
79
|
+
return [...out.values()];
|
|
80
|
+
}
|
|
81
|
+
/** The templates of `kind` ('' every kind) holding every word of `q`. */
|
|
82
|
+
export function narrow(list, kind, q) {
|
|
83
|
+
const words = q.toLowerCase().split(/\s+/).filter(Boolean);
|
|
84
|
+
return list.filter((x) => (!kind || x.kind === kind) && words.every((w) => x.words.includes(w)));
|
|
85
|
+
}
|
package/lib/customize/agents.js
CHANGED
|
@@ -30,8 +30,12 @@ import { agents, ALL, CAST_CAP, CAST_TASK, create, draft, EMPTY, one, PERIODS, p
|
|
|
30
30
|
import { models } from '../api/models.js';
|
|
31
31
|
import { tools } from '../api/tools.js';
|
|
32
32
|
import { useHost, useTarget } from '../host.js';
|
|
33
|
+
import { useFunds } from '../mind.js';
|
|
33
34
|
import { path } from '../route.js';
|
|
35
|
+
import { Drafted } from './drafted.js';
|
|
36
|
+
import { Inventory, Traits } from './inventory.js';
|
|
34
37
|
import { useLoad } from './load.js';
|
|
38
|
+
import { keep, kept, nature, score } from './ocean.js';
|
|
35
39
|
import { say } from './say.js';
|
|
36
40
|
import { Add, Choice, Confirm, Empty, Failed, Field, Grid, Line, Mark, matches, mono, Part, Sheet, Soft, Tile, useCount, Visitor } from './ui.js';
|
|
37
41
|
/** How many cards Browse draws at a time. */
|
|
@@ -152,7 +156,7 @@ export function Agents({ view, q, adding, onAdding, onView, onCount, mode = 'age
|
|
|
152
156
|
const all = [...first, ...rest];
|
|
153
157
|
const shown = all.filter((c) => (botsMode || kind === ANY || c.category === kind) && matches(q, c.title, c.name, c.description, c.category, ...(c.after ?? [])));
|
|
154
158
|
const card = (c) => (_jsx(Tile, { title: c.title, detail: [c.description === c.title || c.description === c.category ? '' : c.description, c.after?.length ? t('after {names}', { names: c.after.join(', ') }) : ''].filter(Boolean).join(' · ') || undefined, meta: [botsMode ? t('Bot') : category(c.category, t), c.executionMode === 'long-running' ? t('24/7 · Proactive · Event-driven') : '', c.schedule].filter(Boolean).join(' · '), mark: _jsx(Mark, { name: c.title, size: 40, logo: c.avatar }), onOpen: signed && botsMode ? () => setElecting(c) : undefined, action: signed ? (_jsxs(XStack, { items: "center", gap: "$1.5", children: [botsMode ? (_jsx(XStack, { "$max-sm": { display: 'none' }, children: _jsx(Button, { size: "sm", variant: "ghost", disabled: using !== null, "aria-label": t('Elect {name} to run 24/7', { name: c.title }), onPress: () => setElecting(c), children: t('Configure 24/7') }) })) : null, _jsx(Add, { name: c.title, use: true, added: false, busy: using !== null, onPress: () => void take(c) })] })) : undefined }, `${c.category}/${c.name}/${c.title}`));
|
|
155
|
-
return (_jsxs(YStack, { gap: "$3", children: [signed ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", children: [_jsx(Button, { size: "sm", variant: "outline", onPress: () => onAdding(true), children: t('Start from scratch') }), botsMode ? (allCast.length ? (_jsx(Button, { size: "sm", variant: "outline", onPress: () => setElecting((first[0] ?? allCast[0])), children: t('Elect 24/7 preset') })) : null) : (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", variant: "outline", onPress: () => setMaking('self'), children: t('Clone yourself') }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setMaking('person'), children: t('Create from a person') })] }))] })) : null, !botsMode ? (_jsx(XStack, { overflowX: "auto", overflowY: "hidden", pb: "$1", children: _jsx(Choice, { label: t('Category'), value: kind, options: kinds(first, rest).map((id) => ({ id, label: category(id, t) })), onChange: setKind }) })) : null, _jsx(Line, { children: note }), shown.length ? (_jsx(Grid, { label: botsMode ? t('Bots to start from') : t('Agents to start from'), children: shown.slice(0, more).map(card) })) : figures.loading ? null : q.trim() ? (_jsx(Soft, { children: t(botsMode ? 'No bot matches “{q}”.' : 'No agent matches “{q}”.', { q: q.trim() }) })) : botsMode ? (_jsx(Soft, { children: t('Create a persistent 24/7 bot from scratch or elect any preset.') })) : (_jsx(Soft, { children: t('No agent matches “{q}”.', { q: q.trim() }) })), shown.length > more ? (_jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "ghost", onPress: () => setMore(more + PAGE), children: t('More') }) })) : null, figures.error ? _jsx(Failed, { error: figures.error, onRetry: figures.reload }) : figures.loading ? _jsx(Soft, { children: t('Loading…') }) : null, editor, making ? _jsx(Person, { self: making === 'self', onClose: () => setMaking(null), onMade: opened }) : null, electing ? _jsx(Elect, { preset: electing, all: allCast, onClose: () => setElecting(null), onElected: opened }) : null] }));
|
|
159
|
+
return (_jsxs(YStack, { gap: "$3", children: [signed && !botsMode ? _jsx(Drafted, { onMade: opened }) : null, signed ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", children: [_jsx(Button, { size: "sm", variant: "outline", onPress: () => onAdding(true), children: t('Start from scratch') }), botsMode ? (allCast.length ? (_jsx(Button, { size: "sm", variant: "outline", onPress: () => setElecting((first[0] ?? allCast[0])), children: t('Elect 24/7 preset') })) : null) : (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", variant: "outline", onPress: () => setMaking('self'), children: t('Clone yourself') }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setMaking('person'), children: t('Create from a person') })] }))] })) : null, !botsMode ? (_jsx(XStack, { overflowX: "auto", overflowY: "hidden", pb: "$1", children: _jsx(Choice, { label: t('Category'), value: kind, options: kinds(first, rest).map((id) => ({ id, label: category(id, t) })), onChange: setKind }) })) : null, _jsx(Line, { children: note }), shown.length ? (_jsx(Grid, { label: botsMode ? t('Bots to start from') : t('Agents to start from'), children: shown.slice(0, more).map(card) })) : figures.loading ? null : q.trim() ? (_jsx(Soft, { children: t(botsMode ? 'No bot matches “{q}”.' : 'No agent matches “{q}”.', { q: q.trim() }) })) : botsMode ? (_jsx(Soft, { children: t('Create a persistent 24/7 bot from scratch or elect any preset.') })) : (_jsx(Soft, { children: t('No agent matches “{q}”.', { q: q.trim() }) })), shown.length > more ? (_jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "ghost", onPress: () => setMore(more + PAGE), children: t('More') }) })) : null, figures.error ? _jsx(Failed, { error: figures.error, onRetry: figures.reload }) : figures.loading ? _jsx(Soft, { children: t('Loading…') }) : null, editor, making ? _jsx(Person, { self: making === 'self', onClose: () => setMaking(null), onMade: opened }) : null, electing ? _jsx(Elect, { preset: electing, all: allCast, onClose: () => setElecting(null), onElected: opened }) : null] }));
|
|
156
160
|
}
|
|
157
161
|
if (!signed) {
|
|
158
162
|
return _jsx(Visitor, { children: t(botsMode ? 'Sign in to see your bots.' : 'Sign in to see your agents.') });
|
|
@@ -214,18 +218,36 @@ function Elect({ preset, all, onClose, onElected, }) {
|
|
|
214
218
|
return (_jsx(Button, { size: "sm", variant: active ? 'primary' : 'ghost', onPress: () => selectPreset(c), children: c.title }, `${c.category}/${c.name}`));
|
|
215
219
|
}) }) })) : null, _jsxs(XStack, { items: "center", gap: "$3", p: "$3", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", color: "$ink", children: t('Run autonomously 24/7') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('Stays active continuously (long-running), waking proactively on its schedule and when events fire.') })] }), _jsx(Switch, { checked: autonomous, onCheckedChange: setAutonomous, "aria-label": t('Run autonomously 24/7') })] }), autonomous ? (_jsxs(_Fragment, { children: [_jsx(Field, { label: t('Proactive schedule'), hint: t('Choose how often this agent wakes proactively, or enter any 5-field cron expression.'), children: _jsxs(YStack, { gap: "$2", children: [_jsx(XStack, { gap: "$1.5", flexWrap: "wrap", children: SCHEDULES.map((s) => (_jsx(Button, { size: "sm", variant: schedule.trim() === s.cron ? 'primary' : 'outline', onPress: () => setSchedule(s.cron), children: t(s.label) }, s.cron))) }), _jsx(Input, { value: schedule, onChangeText: setSchedule, placeholder: "*/15 * * * *", "aria-label": t('Proactive schedule') })] }) }), _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$2", color: "$ink", children: t('Event-driven triggers') }), _jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", children: TRIGGERS.map((tr, i) => (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", color: "$ink", children: t(TRIGGER_LABELS[tr].title) }), _jsx(SizableText, { size: "$1", color: "$soft", children: t(TRIGGER_LABELS[tr].detail) })] }), _jsx(Switch, { checked: triggers.includes(tr), onCheckedChange: (v) => toggleTrigger(tr, v), "aria-label": t(TRIGGER_LABELS[tr].title) })] }, tr))) })] })] })) : null, _jsxs(YStack, { gap: "$2", children: [_jsx(SizableText, { size: "$2", color: "$ink", children: t('Budget') }), _jsxs(XStack, { gap: "$3", flexWrap: "wrap", rowGap: "$2", items: "flex-end", children: [_jsxs(YStack, { gap: "$1", width: 140, children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t(EACH[period]) }), _jsx(Input, { value: cap, onChangeText: setCap, placeholder: "10", "aria-label": t('Budget each period'), inputMode: "decimal" })] }), _jsxs(YStack, { gap: "$1", width: 140, children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('One run, USD') }), _jsx(Input, { value: task, onChangeText: setTask, placeholder: "1", "aria-label": t('Budget for one run'), inputMode: "decimal" })] }), _jsx(Choice, { label: t('Period'), value: period, options: PERIODS.map((p) => ({ id: p, label: t(PERIOD[p]) })), onChange: (p) => setPeriod(p) })] })] }), _jsx(Line, { children: note }), _jsxs(XStack, { gap: "$2", items: "center", children: [_jsx(XStack, { flex: 1 }), _jsx(Button, { size: "sm", variant: "ghost", onPress: onClose, children: t('Cancel') }), _jsx(Button, { size: "sm", disabled: working || (autonomous && !schedule.trim()), onPress: () => void save(), children: autonomous ? t('Elect & Run 24/7') : t('Create') })] })] }));
|
|
216
220
|
}
|
|
217
|
-
/**
|
|
221
|
+
/**
|
|
222
|
+
* Clone yourself, or anyone named: a name, who they are, and writing of theirs,
|
|
223
|
+
* pasted or uploaded. Yourself also takes the Big Five questionnaire, kept in
|
|
224
|
+
* this browser as it is answered; its result seeds the instructions, which are
|
|
225
|
+
* shown to edit before the agent is made.
|
|
226
|
+
*/
|
|
218
227
|
function Person({ self, onClose, onMade }) {
|
|
219
228
|
const { t } = useI18n();
|
|
220
229
|
const host = useHost();
|
|
221
230
|
const target = useTarget();
|
|
222
231
|
const me = self ? host.person : null;
|
|
232
|
+
const who = me?.email || me?.name || '';
|
|
223
233
|
const [name, setName] = useState(me?.name ?? '');
|
|
224
234
|
const [about, setAbout] = useState('');
|
|
225
235
|
const [writing, setWriting] = useState('');
|
|
236
|
+
const [answers, setAnswers] = useState(() => kept(who));
|
|
237
|
+
const [taking, setTaking] = useState(false);
|
|
238
|
+
const [edited, setEdited] = useState(null);
|
|
226
239
|
const [working, setWorking] = useState(false);
|
|
227
240
|
const [note, setNote] = useState('');
|
|
228
241
|
const file = useRef(null);
|
|
242
|
+
const sheet = answers[answers.form];
|
|
243
|
+
const answered = sheet.filter(Boolean).length;
|
|
244
|
+
const result = self && answered === sheet.length ? score(answers.form, sheet) : null;
|
|
245
|
+
const cast = person(name, about, writing, me?.avatar, result ? nature(name.trim(), answers.form, result) : '');
|
|
246
|
+
const instructions = edited ?? cast.instructions;
|
|
247
|
+
const answer = (a) => {
|
|
248
|
+
setAnswers(a);
|
|
249
|
+
keep(who, a);
|
|
250
|
+
};
|
|
229
251
|
const read = async (files) => {
|
|
230
252
|
const texts = await Promise.all([...(files ?? [])].map((f) => f.text()));
|
|
231
253
|
setWriting((w) => [w.trim(), ...texts.map((x) => x.trim())].filter(Boolean).join('\n\n'));
|
|
@@ -234,17 +256,20 @@ function Person({ self, onClose, onMade }) {
|
|
|
234
256
|
setWorking(true);
|
|
235
257
|
setNote('');
|
|
236
258
|
try {
|
|
237
|
-
onMade(await use(target,
|
|
259
|
+
onMade(await use(target, { ...cast, instructions }, window.location.href));
|
|
238
260
|
}
|
|
239
261
|
catch (e) {
|
|
240
262
|
setNote(say(e, t));
|
|
241
263
|
setWorking(false);
|
|
242
264
|
}
|
|
243
265
|
};
|
|
244
|
-
return (
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
266
|
+
return (_jsx(Sheet, { title: self ? t('Clone yourself') : t('Create from a person'), open: true, onOpenChange: (o) => !o && onClose(), full: true, children: taking ? (_jsx(Inventory, { answers: answers, onChange: answer, onDone: () => setTaking(false) })) : (_jsxs(_Fragment, { children: [_jsx(Field, { label: t('Name'), children: _jsx(Input, { value: name, onChangeText: setName, "aria-label": t('Name') }) }), _jsx(Field, { label: t('Description'), children: _jsx(Textarea, { value: about, onChangeText: setAbout, "aria-label": t('Description'), rows: 3 }) }), self ? (_jsx(Field, { label: t('Personality'), children: _jsxs(YStack, { gap: "$3", children: [_jsx(Choice, { label: t('Questionnaire'), value: answers.form, options: [
|
|
267
|
+
{ id: 'short', label: t('50 statements') },
|
|
268
|
+
{ id: 'long', label: t('120 statements') },
|
|
269
|
+
], onChange: (form) => answer({ ...answers, form }) }), result ? _jsx(Traits, { form: answers.form, score: result }) : null, _jsx(XStack, { children: _jsx(Button, { size: "sm", variant: result ? 'ghost' : 'outline', onPress: () => setTaking(true), children: result ? t('Change answers') : answered ? t('Resume, {n} of {total}', { n: answered, total: sheet.length }) : t('Start') }) })] }) })) : null, _jsx(Field, { label: t('Writing'), children: _jsx(Textarea, { value: writing, onChangeText: setWriting, "aria-label": t('Writing'), rows: 6 }) }), _jsxs(XStack, { children: [_jsxs(Button, { size: "sm", variant: "ghost", onPress: () => file.current?.click(), children: [_jsx(Upload, { size: 14 }), " ", t('Upload')] }), _jsx("input", { ref: file, type: "file", multiple: true, accept: ".txt,.md,.markdown,.csv,.json,.html,text/*", hidden: true, "aria-label": t('Upload writing'), onChange: (e) => {
|
|
270
|
+
void read(e.currentTarget.files);
|
|
271
|
+
e.currentTarget.value = '';
|
|
272
|
+
} })] }), _jsx(Field, { label: t('Instructions'), children: _jsx(Textarea, { value: instructions, onChangeText: setEdited, "aria-label": t('Instructions'), rows: 8 }) }), _jsx(Line, { children: note }), _jsxs(XStack, { gap: "$2", items: "center", children: [_jsx(XStack, { flex: 1 }), _jsx(Button, { size: "sm", variant: "ghost", onPress: onClose, children: t('Cancel') }), _jsx(Button, { size: "sm", disabled: working || !name.trim(), onPress: () => void save(), children: t('Create') })] })] })) }));
|
|
248
273
|
}
|
|
249
274
|
function reach(a, t) {
|
|
250
275
|
if (a.tools.includes(ALL))
|
|
@@ -278,9 +303,11 @@ export function Profile({ name }) {
|
|
|
278
303
|
/** Write a new agent, or change one; an existing agent is read whole first, for its instructions. */
|
|
279
304
|
function Editor({ agent, defaultBot = false, onClose, onSaved, onDeleted, }) {
|
|
280
305
|
const { t } = useI18n();
|
|
306
|
+
const host = useHost();
|
|
281
307
|
const target = useTarget();
|
|
282
308
|
const full = useLoad(agent ? () => one(target, agent.id || agent.name) : null, null, [target, agent?.id]);
|
|
283
309
|
const catalog = useLoad(() => models(target), [], [target]);
|
|
310
|
+
const funds = useFunds(target, host.topUp);
|
|
284
311
|
const on = useLoad(() => tools(target, { activated: true }), [], [target]);
|
|
285
312
|
const [d, setD] = useState(() => defaultBot
|
|
286
313
|
? { ...EMPTY, executionMode: 'long-running', schedule: '*/15 * * * *', triggers: ['webhook', 'git', 'channel', 'watch'] }
|
|
@@ -322,7 +349,7 @@ function Editor({ agent, defaultBot = false, onClose, onSaved, onDeleted, }) {
|
|
|
322
349
|
}
|
|
323
350
|
};
|
|
324
351
|
const pick = (name, yes) => set({ tools: yes ? [...d.tools, name] : d.tools.filter((n) => n !== name) });
|
|
325
|
-
return (_jsx(Sheet, { title: agent ? agent.name : t(defaultBot ? 'New bot' : 'New agent'), open: true, onOpenChange: (o) => !o && onClose(), width: 680, children: agent && full.error && !full.value ? (_jsx(Failed, { error: full.error, onRetry: full.reload })) : !ready ? (_jsx(Soft, { children: t('Loading the agent…') })) : (_jsxs(_Fragment, { children: [_jsx(Field, { label: t('Name'), hint: agent ? t('An agent keeps its name.') : t('Letters, digits, . _ or -. Other agents call it as agent_<name>.'), children: _jsx(Input, { value: d.name, onChangeText: (v) => set({ name: v }), "aria-label": t('Name'), disabled: Boolean(agent), autoCapitalize: "none" }) }), _jsx(Field, { label: t('Description'), hint: t('The line another agent reads to decide whether to call this one.'), children: _jsx(Input, { value: d.description, onChangeText: (v) => set({ description: v }), placeholder: t('Answers questions about our codebase'), "aria-label": t('Description') }) }), _jsx(Field, { label: t('Model'), children: _jsxs(XStack, { items: "center", gap: "$2", flexWrap: "wrap", children: [_jsx(ModelPicker, { size: "sm", name: t('Model'), placeholder: t('The deployment’s default'), models: catalog.value, scope: "
|
|
352
|
+
return (_jsx(Sheet, { title: agent ? agent.name : t(defaultBot ? 'New bot' : 'New agent'), open: true, onOpenChange: (o) => !o && onClose(), width: 680, children: agent && full.error && !full.value ? (_jsx(Failed, { error: full.error, onRetry: full.reload })) : !ready ? (_jsx(Soft, { children: t('Loading the agent…') })) : (_jsxs(_Fragment, { children: [_jsx(Field, { label: t('Name'), hint: agent ? t('An agent keeps its name.') : t('Letters, digits, . _ or -. Other agents call it as agent_<name>.'), children: _jsx(Input, { value: d.name, onChangeText: (v) => set({ name: v }), "aria-label": t('Name'), disabled: Boolean(agent), autoCapitalize: "none" }) }), _jsx(Field, { label: t('Description'), hint: t('The line another agent reads to decide whether to call this one.'), children: _jsx(Input, { value: d.description, onChangeText: (v) => set({ description: v }), placeholder: t('Answers questions about our codebase'), "aria-label": t('Description') }) }), _jsx(Field, { label: t('Model'), children: _jsxs(XStack, { items: "center", gap: "$2", flexWrap: "wrap", children: [_jsx(ModelPicker, { size: "sm", name: t('Model'), placeholder: t('The deployment’s default'), models: catalog.value, scope: "agent", funded: funds.funded, balance: funds.balance, onTopUp: funds.topUp, value: d.model || undefined, onChange: (id) => set({ model: id }), loading: catalog.loading, error: catalog.error ? say(catalog.error, t) : null }), d.model && !agent ? (_jsx(Button, { size: "sm", variant: "ghost", onPress: () => set({ model: '' }), children: t('Use the default') })) : null] }) }), _jsx(Field, { label: t('Instructions'), hint: t('The system prompt: what the model reads before every run.'), children: _jsx(Textarea, { value: d.instructions, onChangeText: (v) => set({ instructions: v }), placeholder: t('Be terse, and cite the file you read.'), "aria-label": t('Instructions'), rows: 8 }) }), _jsxs(YStack, { gap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$3", children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", color: "$ink", children: t('Tools') }), _jsx(SizableText, { size: "$1", color: "$soft", children: every
|
|
326
353
|
? t('Every tool the fleet’s MCP server serves when it runs.')
|
|
327
354
|
: d.tools.length
|
|
328
355
|
? t('{n} chosen. It can call only these.', { n: d.tools.length })
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Make with AI: one box at the top of Browse. A name ("Marie Curie") or a
|
|
4
|
+
* description ("a skeptical CFO") and a Hanzo model drafts the agent, which is
|
|
5
|
+
* shown once, editable, with Save; saving makes the org's own agent and opens its
|
|
6
|
+
* profile. A real historical figure gets a public-domain portrait from Wikimedia
|
|
7
|
+
* Commons where one is free to use, any other agent the emoji the model chose.
|
|
8
|
+
* Nothing is made before Save.
|
|
9
|
+
*/
|
|
10
|
+
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
11
|
+
import { useI18n } from '@hanzo/i18n/react';
|
|
12
|
+
import { Button, Input, Textarea } from '@hanzo/ui';
|
|
13
|
+
import { useState } from 'react';
|
|
14
|
+
import { agents, CAST_CAP, CAST_TASK, create, EMPTY, free, handle } from '../api/agents.js';
|
|
15
|
+
import { portrait, saved, sketch } from '../api/draft.js';
|
|
16
|
+
import { useTarget } from '../host.js';
|
|
17
|
+
import { say } from './say.js';
|
|
18
|
+
import { Field, Line, Mark, Sheet } from './ui.js';
|
|
19
|
+
/** How long a portrait is waited for before the draft is shown without one. */
|
|
20
|
+
const WAIT = 6000;
|
|
21
|
+
export function Drafted({ onMade }) {
|
|
22
|
+
const { t } = useI18n();
|
|
23
|
+
const target = useTarget();
|
|
24
|
+
const [line, setLine] = useState('');
|
|
25
|
+
const [busy, setBusy] = useState(false);
|
|
26
|
+
const [note, setNote] = useState('');
|
|
27
|
+
const [draft, setDraft] = useState(null);
|
|
28
|
+
const make = async () => {
|
|
29
|
+
if (!line.trim() || busy)
|
|
30
|
+
return;
|
|
31
|
+
setBusy(true);
|
|
32
|
+
setNote('');
|
|
33
|
+
try {
|
|
34
|
+
const s = await sketch(target, line);
|
|
35
|
+
const face = s.figure ? await portrait(s.figure, AbortSignal.timeout(WAIT)) : null;
|
|
36
|
+
setDraft({ s, face });
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
setNote(say(e, t));
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
setBusy(false);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return (_jsxs(YStack, { gap: "$2", children: [_jsxs(XStack, { gap: "$2", items: "center", children: [_jsx(Input, { flex: 1, value: line, onChangeText: setLine, placeholder: t('A name or a description: Marie Curie, a skeptical CFO…'), "aria-label": t('Make with AI'), onSubmitEditing: () => void make() }), _jsx(Button, { size: "sm", disabled: !line.trim() || busy, onPress: () => void make(), children: busy ? t('Drafting…') : t('Make with AI') })] }), _jsx(Line, { children: note }), draft ? _jsx(Review, { draft: draft, onClose: () => setDraft(null), onMade: onMade }) : null] }));
|
|
46
|
+
}
|
|
47
|
+
function Review({ draft, onClose, onMade }) {
|
|
48
|
+
const { t } = useI18n();
|
|
49
|
+
const target = useTarget();
|
|
50
|
+
const [name, setName] = useState(draft.s.name);
|
|
51
|
+
const [role, setRole] = useState(draft.s.role);
|
|
52
|
+
const [instructions, setInstructions] = useState(draft.s.instructions);
|
|
53
|
+
const [opening, setOpening] = useState(draft.s.opening);
|
|
54
|
+
const [working, setWorking] = useState(false);
|
|
55
|
+
const [note, setNote] = useState('');
|
|
56
|
+
const save = async () => {
|
|
57
|
+
setWorking(true);
|
|
58
|
+
setNote('');
|
|
59
|
+
try {
|
|
60
|
+
const have = await agents(target);
|
|
61
|
+
const made = await create(target, {
|
|
62
|
+
...EMPTY,
|
|
63
|
+
name: free(handle(name), have),
|
|
64
|
+
description: role.trim(),
|
|
65
|
+
instructions: saved({ instructions, opening }),
|
|
66
|
+
cap: CAST_CAP,
|
|
67
|
+
task: CAST_TASK,
|
|
68
|
+
avatar: draft.face?.url ?? '',
|
|
69
|
+
emoji: draft.face ? '' : draft.s.emoji,
|
|
70
|
+
});
|
|
71
|
+
onMade(made);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
setNote(say(e, t));
|
|
75
|
+
setWorking(false);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return (_jsxs(Sheet, { title: t('New agent'), open: true, onOpenChange: (o) => !o && onClose(), children: [_jsxs(XStack, { items: "center", gap: "$3", children: [_jsx(Mark, { name: name || draft.s.name, size: 48, logo: draft.face?.url, icon: !draft.face && draft.s.emoji ? _jsx(SizableText, { size: "$8", children: draft.s.emoji }) : undefined }), _jsx(YStack, { flex: 1, minW: 0, children: _jsx(Input, { value: name, onChangeText: setName, "aria-label": t('Name') }) })] }), _jsx(Field, { label: t('Role'), children: _jsx(Input, { value: role, onChangeText: setRole, "aria-label": t('Role') }) }), _jsx(Field, { label: t('Instructions'), children: _jsx(Textarea, { value: instructions, onChangeText: setInstructions, "aria-label": t('Instructions'), rows: 8 }) }), _jsx(Field, { label: t('Opening line'), children: _jsx(Input, { value: opening, onChangeText: setOpening, "aria-label": t('Opening line') }) }), _jsx(Line, { children: note }), _jsxs(XStack, { gap: "$2", items: "center", children: [_jsx(XStack, { flex: 1 }), _jsx(Button, { size: "sm", variant: "ghost", onPress: onClose, children: t('Cancel') }), _jsx(Button, { size: "sm", disabled: working || !name.trim() || !instructions.trim(), onPress: () => void save(), children: t('Save') })] })] }));
|
|
79
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Answers, type Form, type Score } from './ocean.ts';
|
|
2
|
+
export declare function Inventory({ answers, onChange, onDone }: {
|
|
3
|
+
answers: Answers;
|
|
4
|
+
onChange: (a: Answers) => void;
|
|
5
|
+
onDone: () => void;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
/** The five domains as bars of their raw means, 1 to 5, and on the long form each domain's six facets under it. */
|
|
8
|
+
export declare function Traits({ form, score }: {
|
|
9
|
+
form: Form;
|
|
10
|
+
score: Score;
|
|
11
|
+
}): import("react").JSX.Element;
|