@hanzo/build 0.2.117 → 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 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, XHigh,
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. Yours is the org's own — model, instructions, tools, budget — created,
254
- edited (only what changed is sent) and deleted.
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, XHigh and Max name `high` (`level`).
384
+ and High and Max name `high` (`level`).
364
385
 
365
386
  ## Layout
366
387
 
@@ -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: QUICK, max_tokens: tokens, messages: [{ role: 'system', content: system }, { role: 'user', content: user }] }, { signal });
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>;
@@ -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
+ }
@@ -116,6 +116,8 @@ export interface Grants {
116
116
  repos: Grant[];
117
117
  /** Accounts the connection could not read. */
118
118
  unread: string[];
119
+ /** The accounts the organization added (`added`), each listed even before any of its repositories is. */
120
+ added?: string[];
119
121
  }
120
122
  export interface Account {
121
123
  name: string;
@@ -131,7 +133,7 @@ export interface Account {
131
133
  * `imported` is decided by `grants` from the links and the forge.
132
134
  */
133
135
  export declare function grant(raw: unknown): Grant | null;
134
- /** Accounts the grant names, plus any account that could not be read. */
136
+ /** Accounts the grant names, plus any account that could not be read or that the organization added. */
135
137
  export declare function accounts(g: Grants): Account[];
136
138
  /**
137
139
  * Every repository the GitHub connection grants, every page, with whether the
@@ -139,6 +141,15 @@ export declare function accounts(g: Grants): Account[];
139
141
  * state), or a forge repository under its codebase name (GET /v1/git/repos).
140
142
  */
141
143
  export declare function grants(t: Target, signal?: AbortSignal): Promise<Grants>;
144
+ /**
145
+ * The repositories this organization can bring in: `grants`, narrowed to the
146
+ * accounts the organization has added (`installations`, `connected`). The list
147
+ * is the person's own GitHub, which reaches accounts another Hanzo workspace
148
+ * added; the import goes through this organization's own, so it refuses every
149
+ * repository of those. With the organization's accounts unreadable, `grants` as
150
+ * it is: the import still says which it refuses.
151
+ */
152
+ export declare function added(t: Target, signal?: AbortSignal): Promise<Grants>;
142
153
  /** What an import queued: how many, and the name each takes on the forge, by `owner/name`. */
143
154
  export interface Queued {
144
155
  queued: number;
package/lib/api/github.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * POST /v1/provider/github/user/connect {return} → {authorizeUrl}
8
8
  * POST /v1/provider/github/user/complete {grant} → the connection
9
9
  * POST /v1/provider/github/user/disconnect
10
- * GET /v1/provider/github/installations the accounts this org has bound the App on
10
+ * GET /v1/provider/github/installations the accounts this org has bound the App on (`added` narrows to them)
11
11
  * POST /v1/provider/github/issues/backfill {state, repo?} → mirror GitHub issues onto the board
12
12
  *
13
13
  * Paged by an opaque `after` cursor; `next` is the cursor for the page after
@@ -152,7 +152,7 @@ export function grant(raw) {
152
152
  status: '',
153
153
  };
154
154
  }
155
- /** Accounts the grant names, plus any account that could not be read. */
155
+ /** Accounts the grant names, plus any account that could not be read or that the organization added. */
156
156
  export function accounts(g) {
157
157
  const counts = new Map();
158
158
  for (const r of g.repos) {
@@ -162,6 +162,14 @@ export function accounts(g) {
162
162
  }
163
163
  const unread = new Set(g.unread.filter(Boolean));
164
164
  const names = new Set([...counts.keys(), ...unread]);
165
+ // GitHub's logins are case-blind: an added account is named once, as its repositories spell it.
166
+ const seen = new Set([...names].map((n) => n.toLowerCase()));
167
+ for (const n of g.added ?? []) {
168
+ if (!n || seen.has(n.toLowerCase()))
169
+ continue;
170
+ names.add(n);
171
+ seen.add(n.toLowerCase());
172
+ }
165
173
  return [...names]
166
174
  .sort((a, b) => a.localeCompare(b))
167
175
  .map((name) => {
@@ -211,6 +219,23 @@ export async function grants(t, signal) {
211
219
  unread: unread.filter(Boolean),
212
220
  };
213
221
  }
222
+ /**
223
+ * The repositories this organization can bring in: `grants`, narrowed to the
224
+ * accounts the organization has added (`installations`, `connected`). The list
225
+ * is the person's own GitHub, which reaches accounts another Hanzo workspace
226
+ * added; the import goes through this organization's own, so it refuses every
227
+ * repository of those. With the organization's accounts unreadable, `grants` as
228
+ * it is: the import still says which it refuses.
229
+ */
230
+ export async function added(t, signal) {
231
+ const [g, mine] = await Promise.all([grants(t, signal), installations(t).catch(() => null)]);
232
+ if (!mine)
233
+ return g;
234
+ const logins = mine.filter((i) => i.connected).map((i) => i.login);
235
+ const held = new Set(logins.map((l) => l.toLowerCase()));
236
+ const ours = (name) => held.has(name.toLowerCase());
237
+ return { repos: g.repos.filter((r) => ours(r.owner)), unread: g.unread.filter(ours), added: logins };
238
+ }
214
239
  /** Queue a mirror of the named repositories onto the forge. The names are `owner/name`. */
215
240
  export async function bring(t, repos) {
216
241
  const names = repos.map((n) => n.trim()).filter(Boolean);
@@ -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
- /** Clone yourself, or anyone named: a name, who they are, and writing of theirs, pasted or uploaded. */
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, person(name, about, writing, me?.avatar), window.location.href));
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 (_jsxs(Sheet, { title: self ? t('Clone yourself') : t('Create from a person'), open: true, onOpenChange: (o) => !o && onClose(), 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 }) }), _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) => {
245
- void read(e.currentTarget.files);
246
- e.currentTarget.value = '';
247
- } })] }), _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') })] })] }));
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: "chat", 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
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,4 @@
1
+ import { type Agent } from '../api/agents.ts';
2
+ export declare function Drafted({ onMade }: {
3
+ onMade: (a: Agent) => void;
4
+ }): import("react").JSX.Element;