@hanzo/build 0.2.99 → 0.2.110
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/lib/api/agents.d.ts +24 -1
- package/lib/api/agents.js +52 -2
- package/lib/api/coding.d.ts +8 -0
- package/lib/api/coding.js +27 -3
- package/lib/api/library.d.ts +6 -2
- package/lib/api/library.js +50 -6
- package/lib/api/sessions.js +16 -1
- package/lib/api/turn.d.ts +2 -0
- package/lib/api/turn.js +12 -0
- package/lib/carry.js +79 -7
- package/lib/customize/agents.js +73 -5
- package/lib/desk.d.ts +7 -1
- package/lib/desk.js +56 -11
- package/lib/files.js +6 -2
- package/lib/landing.js +38 -34
- package/lib/library.js +36 -8
- package/lib/nav.js +19 -9
- package/lib/panel.js +2 -2
- package/lib/plugins/index.js +1 -1
- package/lib/reply.d.ts +13 -4
- package/lib/reply.js +74 -14
- package/lib/route.d.ts +2 -2
- package/lib/route.js +2 -2
- package/lib/run.js +185 -13
- package/lib/summary.d.ts +11 -1
- package/lib/summary.js +17 -3
- package/lib/transcript.d.ts +12 -1
- package/lib/transcript.js +16 -8
- package/package.json +1 -1
package/lib/api/agents.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { type Target } from './call.ts';
|
|
2
2
|
export type Period = 'day' | 'week' | 'month';
|
|
3
3
|
export declare const PERIODS: readonly Period[];
|
|
4
|
+
export type Mode = 'one-shot' | 'long-running';
|
|
5
|
+
export declare const MODES: readonly Mode[];
|
|
6
|
+
export type Trigger = 'webhook' | 'git' | 'channel' | 'watch';
|
|
7
|
+
export declare const TRIGGERS: readonly Trigger[];
|
|
8
|
+
export declare const SCHEDULES: readonly {
|
|
9
|
+
cron: string;
|
|
10
|
+
label: string;
|
|
11
|
+
}[];
|
|
4
12
|
export interface Agent {
|
|
5
13
|
id: string;
|
|
6
14
|
name: string;
|
|
@@ -19,6 +27,12 @@ export interface Agent {
|
|
|
19
27
|
/** Its picture: an https link or a data URL; '' draws its emoji or initial. */
|
|
20
28
|
avatar: string;
|
|
21
29
|
emoji: string;
|
|
30
|
+
/** How the agent runs: 'long-running' runs autonomously 24/7 on its schedule and triggers. */
|
|
31
|
+
executionMode?: Mode;
|
|
32
|
+
/** 5-field cron schedule for proactive execution (required when executionMode is 'long-running'). */
|
|
33
|
+
schedule?: string;
|
|
34
|
+
/** Event-driven triggers that wake the agent proactively. */
|
|
35
|
+
triggers?: Trigger[];
|
|
22
36
|
}
|
|
23
37
|
export interface Preset {
|
|
24
38
|
id: string;
|
|
@@ -37,6 +51,9 @@ export interface Draft {
|
|
|
37
51
|
period: Period;
|
|
38
52
|
/** Sent on create only: an https link or a data URL. */
|
|
39
53
|
avatar: string;
|
|
54
|
+
executionMode?: Mode;
|
|
55
|
+
schedule?: string;
|
|
56
|
+
triggers?: Trigger[];
|
|
40
57
|
}
|
|
41
58
|
/** An agent's name, as the handler takes it. */
|
|
42
59
|
export declare const NAME: RegExp;
|
|
@@ -87,6 +104,12 @@ export interface Cast {
|
|
|
87
104
|
/** Its face, an address of the host. */
|
|
88
105
|
avatar?: string;
|
|
89
106
|
tools?: string[];
|
|
107
|
+
/** How the preset runs when elected (e.g. 'long-running' for 24/7 autonomous bots). */
|
|
108
|
+
executionMode?: Mode;
|
|
109
|
+
/** Default 5-field cron schedule for proactive execution. */
|
|
110
|
+
schedule?: string;
|
|
111
|
+
/** Default event-driven triggers. */
|
|
112
|
+
triggers?: Trigger[];
|
|
90
113
|
}
|
|
91
114
|
/** What an agent made from a template may spend until its owner says otherwise, in dollars: each month, and one run. */
|
|
92
115
|
export declare const CAST_CAP = "10";
|
|
@@ -107,7 +130,7 @@ export declare const link: (at: string | undefined, base: string) => string;
|
|
|
107
130
|
* free (read now, so it is never one that exists), with its instructions read
|
|
108
131
|
* and its face linked. The template is not touched.
|
|
109
132
|
*/
|
|
110
|
-
export declare function use(t: Target, c: Cast, base: string): Promise<Agent>;
|
|
133
|
+
export declare function use(t: Target, c: Cast, base: string, overrides?: Partial<Pick<Draft, 'executionMode' | 'schedule' | 'triggers' | 'model' | 'tools' | 'cap' | 'task' | 'period'>>): Promise<Agent>;
|
|
111
134
|
/** Anyone as a template: their name, who they are, and writing of theirs to take the voice from. */
|
|
112
135
|
export declare function person(name: string, about: string, writing: string, avatar?: string): Cast;
|
|
113
136
|
export declare function create(t: Target, d: Draft): Promise<Agent>;
|
package/lib/api/agents.js
CHANGED
|
@@ -20,6 +20,16 @@
|
|
|
20
20
|
import { phrase } from '@hanzo/i18n';
|
|
21
21
|
import { call, seg } from './call.js';
|
|
22
22
|
export const PERIODS = ['day', 'week', 'month'];
|
|
23
|
+
export const MODES = ['one-shot', 'long-running'];
|
|
24
|
+
export const TRIGGERS = ['webhook', 'git', 'channel', 'watch'];
|
|
25
|
+
export const SCHEDULES = [
|
|
26
|
+
{ cron: '*/5 * * * *', label: phrase('Every 5 min') },
|
|
27
|
+
{ cron: '*/15 * * * *', label: phrase('Every 15 min') },
|
|
28
|
+
{ cron: '0 * * * *', label: phrase('Hourly') },
|
|
29
|
+
{ cron: '0 9 * * *', label: phrase('Daily 9am') },
|
|
30
|
+
{ cron: '0 9 * * 1-5', label: phrase('Weekdays 9am') },
|
|
31
|
+
{ cron: '0 9 * * 1', label: phrase('Weekly Mon 9am') },
|
|
32
|
+
];
|
|
23
33
|
/** An agent's name, as the handler takes it. */
|
|
24
34
|
export const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
25
35
|
/** The most instructions the handler keeps. */
|
|
@@ -35,6 +45,9 @@ export const dollars = (m) => (m ? String(m / 1_000_000) : '');
|
|
|
35
45
|
export function agent(raw) {
|
|
36
46
|
const o = obj(raw);
|
|
37
47
|
const period = str(o.period);
|
|
48
|
+
const mode = str(o.executionMode || o.execution_mode);
|
|
49
|
+
const schedule = str(o.schedule);
|
|
50
|
+
const triggers = rows(o.triggers).map(str).filter((x) => TRIGGERS.includes(x));
|
|
38
51
|
return {
|
|
39
52
|
id: str(o.id),
|
|
40
53
|
name: str(o.name),
|
|
@@ -50,6 +63,9 @@ export function agent(raw) {
|
|
|
50
63
|
period: PERIODS.includes(period) ? period : '',
|
|
51
64
|
avatar: str(o.avatar),
|
|
52
65
|
emoji: str(o.emoji),
|
|
66
|
+
...(MODES.includes(mode) ? { executionMode: mode } : {}),
|
|
67
|
+
...(schedule ? { schedule } : {}),
|
|
68
|
+
...(triggers.length ? { triggers } : {}),
|
|
53
69
|
};
|
|
54
70
|
}
|
|
55
71
|
/** A draft of an agent as it stands, to edit. */
|
|
@@ -64,6 +80,9 @@ export function draft(a) {
|
|
|
64
80
|
task: dollars(a.task),
|
|
65
81
|
period: a.period || 'month',
|
|
66
82
|
avatar: a.avatar,
|
|
83
|
+
...(a.executionMode ? { executionMode: a.executionMode } : {}),
|
|
84
|
+
...(a.schedule ? { schedule: a.schedule } : {}),
|
|
85
|
+
...(a.triggers?.length ? { triggers: a.triggers } : {}),
|
|
67
86
|
};
|
|
68
87
|
}
|
|
69
88
|
export const EMPTY = { name: '', description: '', model: '', instructions: '', tools: [], cap: '', task: '', period: 'month', avatar: '' };
|
|
@@ -80,6 +99,8 @@ export function refuse(d) {
|
|
|
80
99
|
return phrase('A name is letters, digits, . _ or -, starting with a letter or digit');
|
|
81
100
|
if (new TextEncoder().encode(d.instructions).length > MAX)
|
|
82
101
|
return phrase('Instructions are at most 32 KB');
|
|
102
|
+
if (d.executionMode === 'long-running' && !d.schedule?.trim())
|
|
103
|
+
return phrase('A 24/7 autonomous agent requires a schedule (5-field cron)');
|
|
83
104
|
const cap = micros(d.cap);
|
|
84
105
|
const task = micros(d.task);
|
|
85
106
|
if (!(cap > 0))
|
|
@@ -142,9 +163,26 @@ export const link = (at, base) => {
|
|
|
142
163
|
* free (read now, so it is never one that exists), with its instructions read
|
|
143
164
|
* and its face linked. The template is not touched.
|
|
144
165
|
*/
|
|
145
|
-
export async function use(t, c, base) {
|
|
166
|
+
export async function use(t, c, base, overrides) {
|
|
146
167
|
const [have, instructions] = await Promise.all([agents(t), c.read ? c.read() : c.instructions]);
|
|
147
|
-
|
|
168
|
+
const executionMode = overrides?.executionMode ?? c.executionMode;
|
|
169
|
+
const schedule = overrides?.schedule ?? c.schedule;
|
|
170
|
+
const triggers = overrides?.triggers ?? c.triggers;
|
|
171
|
+
return create(t, {
|
|
172
|
+
...EMPTY,
|
|
173
|
+
name: free(handle(c.name), have),
|
|
174
|
+
description: c.description,
|
|
175
|
+
model: overrides?.model ?? c.model,
|
|
176
|
+
instructions,
|
|
177
|
+
tools: overrides?.tools ?? c.tools ?? [],
|
|
178
|
+
cap: overrides?.cap ?? CAST_CAP,
|
|
179
|
+
task: overrides?.task ?? CAST_TASK,
|
|
180
|
+
period: overrides?.period ?? 'month',
|
|
181
|
+
avatar: link(c.avatar, base),
|
|
182
|
+
...(executionMode ? { executionMode } : {}),
|
|
183
|
+
...(schedule ? { schedule } : {}),
|
|
184
|
+
...(triggers?.length ? { triggers } : {}),
|
|
185
|
+
});
|
|
148
186
|
}
|
|
149
187
|
/** Anyone as a template: their name, who they are, and writing of theirs to take the voice from. */
|
|
150
188
|
export function person(name, about, writing, avatar = '') {
|
|
@@ -169,6 +207,12 @@ export async function create(t, d) {
|
|
|
169
207
|
body.model = d.model;
|
|
170
208
|
if (d.avatar)
|
|
171
209
|
body.avatar = d.avatar;
|
|
210
|
+
if (d.executionMode)
|
|
211
|
+
body.executionMode = d.executionMode;
|
|
212
|
+
if (d.schedule?.trim())
|
|
213
|
+
body.schedule = d.schedule.trim();
|
|
214
|
+
if (d.triggers?.length)
|
|
215
|
+
body.triggers = d.triggers;
|
|
172
216
|
return agent(await call(t, 'POST', '/v1/agent', body));
|
|
173
217
|
}
|
|
174
218
|
/** The fields that differ from `was`, and nothing else: an omitted field keeps its value. */
|
|
@@ -188,6 +232,12 @@ export function changes(was, d) {
|
|
|
188
232
|
out.max_task_micro_usd = micros(d.task);
|
|
189
233
|
if (d.period !== was.period)
|
|
190
234
|
out.period = d.period;
|
|
235
|
+
if ((d.executionMode ?? '') !== (was.executionMode ?? '') && d.executionMode)
|
|
236
|
+
out.executionMode = d.executionMode;
|
|
237
|
+
if ((d.schedule ?? '').trim() !== (was.schedule ?? ''))
|
|
238
|
+
out.schedule = (d.schedule ?? '').trim();
|
|
239
|
+
if ((d.triggers ?? []).join('\n') !== (was.triggers ?? []).join('\n'))
|
|
240
|
+
out.triggers = d.triggers ?? [];
|
|
191
241
|
return out;
|
|
192
242
|
}
|
|
193
243
|
export async function update(t, was, d) {
|
package/lib/api/coding.d.ts
CHANGED
|
@@ -41,6 +41,14 @@ export interface Run {
|
|
|
41
41
|
*/
|
|
42
42
|
export declare function body(ask: Ask): Record<string, string | number | boolean>;
|
|
43
43
|
export declare function start(t: Target, ask: Ask): Promise<Run>;
|
|
44
|
+
/**
|
|
45
|
+
* New words for a sandbox run that is working. The run takes its task on its
|
|
46
|
+
* command line and reads nothing after (apps/coding steer.go), so the platform
|
|
47
|
+
* stops it with its work kept on its branch and starts a follow-up from there
|
|
48
|
+
* with the words; the follow-up's session arrives on this run's own stream as
|
|
49
|
+
* its `followed` status (turn.ts `followed`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function steer(t: Target, session: string, text: string): Promise<void>;
|
|
44
52
|
/** A run a follow-up continues, as its record states it. */
|
|
45
53
|
export interface Earlier {
|
|
46
54
|
id: string;
|
package/lib/api/coding.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Starting a coding run, and what it left.
|
|
3
3
|
*
|
|
4
4
|
* POST /v1/agent/coding → 202 {sessionId, repo, branch, routed, targetId}
|
|
5
|
+
* POST /v1/agent/coding/{session}/steer {text} 202 {ok}
|
|
5
6
|
* GET /v1/agent/coding/{session}/artifacts {session, saved, artifacts}
|
|
6
7
|
* GET /v1/agent/coding/{session}/artifacts/{name} one stored artifact's bytes
|
|
7
8
|
*
|
|
@@ -75,6 +76,19 @@ export async function start(t, ask) {
|
|
|
75
76
|
target: s('targetId'),
|
|
76
77
|
};
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* New words for a sandbox run that is working. The run takes its task on its
|
|
81
|
+
* command line and reads nothing after (apps/coding steer.go), so the platform
|
|
82
|
+
* stops it with its work kept on its branch and starts a follow-up from there
|
|
83
|
+
* with the words; the follow-up's session arrives on this run's own stream as
|
|
84
|
+
* its `followed` status (turn.ts `followed`).
|
|
85
|
+
*/
|
|
86
|
+
export async function steer(t, session, text) {
|
|
87
|
+
const words = text.trim();
|
|
88
|
+
if (!words)
|
|
89
|
+
throw new Refusal(400, phrase('Say something to the run'));
|
|
90
|
+
await call(t, 'POST', `/v1/agent/coding/${seg(session)}/steer`, { text: words });
|
|
91
|
+
}
|
|
78
92
|
/**
|
|
79
93
|
* The earlier run's ask, without the codebase its title leads with (`universe:
|
|
80
94
|
* add the widget`), or the `new project:` the platform titles a run that made its
|
|
@@ -83,7 +97,7 @@ export async function start(t, ask) {
|
|
|
83
97
|
export function headline(title, repo) {
|
|
84
98
|
const name = repo.split('/').filter(Boolean).pop() ?? '';
|
|
85
99
|
const t = title.trim();
|
|
86
|
-
for (const lead of [name, 'new project'])
|
|
100
|
+
for (const lead of [name, 'new project', 'workspace'])
|
|
87
101
|
if (lead && t.startsWith(`${lead}: `))
|
|
88
102
|
return t.slice(lead.length + 2).trim();
|
|
89
103
|
return t;
|
|
@@ -97,11 +111,12 @@ export function headline(title, repo) {
|
|
|
97
111
|
*/
|
|
98
112
|
function from(e) {
|
|
99
113
|
const place = e.environment && e.environment !== 'sandbox' ? e.environment : undefined;
|
|
114
|
+
const base = e.base && !e.base.startsWith('agent/') ? e.base : undefined;
|
|
100
115
|
return {
|
|
101
116
|
repo: e.repo || undefined,
|
|
102
117
|
project: e.project || undefined,
|
|
103
118
|
targetId: place,
|
|
104
|
-
...(!place || e.pushed ? { after: e.id } : { base
|
|
119
|
+
...(!place || e.pushed ? { after: e.id } : { base }),
|
|
105
120
|
};
|
|
106
121
|
}
|
|
107
122
|
const modeOf = (m) => (m === 'plan' || m === 'setup' ? m : 'build');
|
|
@@ -137,7 +152,16 @@ export function approve(e, plan) {
|
|
|
137
152
|
* with none recorded, its title's.
|
|
138
153
|
*/
|
|
139
154
|
export function retry(e, ask) {
|
|
140
|
-
|
|
155
|
+
const place = e.environment && e.environment !== 'sandbox' ? e.environment : undefined;
|
|
156
|
+
const base = e.base && !e.base.startsWith('agent/') ? e.base : undefined;
|
|
157
|
+
return {
|
|
158
|
+
repo: e.repo || undefined,
|
|
159
|
+
project: e.project || undefined,
|
|
160
|
+
targetId: place,
|
|
161
|
+
...(e.pushed ? { after: e.id } : { base }),
|
|
162
|
+
prompt: ask.trim() || headline(e.title, e.repo),
|
|
163
|
+
mode: modeOf(e.mode),
|
|
164
|
+
};
|
|
141
165
|
}
|
|
142
166
|
const KINDS = ['file', 'patch', 'preview', 'pull', 'deploy'];
|
|
143
167
|
/** What a run left, kept after its sandbox is gone. */
|
package/lib/api/library.d.ts
CHANGED
|
@@ -84,20 +84,24 @@ export interface Made {
|
|
|
84
84
|
seconds?: number;
|
|
85
85
|
pages?: number;
|
|
86
86
|
}
|
|
87
|
-
/** The largest thing
|
|
87
|
+
/** The largest thing an inline upload carries; larger files up to `MAX` reserve a signed PUT. */
|
|
88
88
|
export declare const INLINE: number;
|
|
89
|
+
/** The largest thing one upload carries (2 GiB). */
|
|
90
|
+
export declare const MAX: number;
|
|
89
91
|
/** Bytes as base64, in chunks a call stack holds. */
|
|
90
92
|
export declare function base64(bytes: Uint8Array): string;
|
|
91
93
|
/** Keep a file in the Library. */
|
|
92
94
|
export declare function upload(t: Target, file: {
|
|
93
95
|
name: string;
|
|
94
96
|
type: string;
|
|
95
|
-
bytes
|
|
97
|
+
bytes?: Uint8Array;
|
|
98
|
+
blob?: Blob;
|
|
96
99
|
}, made: Made): Promise<Item>;
|
|
97
100
|
export interface Change {
|
|
98
101
|
name?: string;
|
|
99
102
|
shared?: boolean;
|
|
100
103
|
project?: string;
|
|
104
|
+
commit?: boolean;
|
|
101
105
|
}
|
|
102
106
|
export declare function change(t: Target, id: string, c: Change): Promise<Item>;
|
|
103
107
|
export declare function remove(t: Target, id: string): Promise<void>;
|
package/lib/api/library.js
CHANGED
|
@@ -95,8 +95,10 @@ export async function get(t, id) {
|
|
|
95
95
|
throw new Error(phrase('The item came back without an id'));
|
|
96
96
|
return x;
|
|
97
97
|
}
|
|
98
|
-
/** The largest thing
|
|
98
|
+
/** The largest thing an inline upload carries; larger files up to `MAX` reserve a signed PUT. */
|
|
99
99
|
export const INLINE = 10 << 20;
|
|
100
|
+
/** The largest thing one upload carries (2 GiB). */
|
|
101
|
+
export const MAX = 2 * 1024 * 1024 * 1024;
|
|
100
102
|
/** Bytes as base64, in chunks a call stack holds. */
|
|
101
103
|
export function base64(bytes) {
|
|
102
104
|
let s = '';
|
|
@@ -106,14 +108,56 @@ export function base64(bytes) {
|
|
|
106
108
|
}
|
|
107
109
|
/** Keep a file in the Library. */
|
|
108
110
|
export async function upload(t, file, made) {
|
|
109
|
-
|
|
111
|
+
const len = file.blob ? file.blob.size : (file.bytes?.length ?? 0);
|
|
112
|
+
if (!len)
|
|
110
113
|
throw new Sentence(phrase('{name} is empty'), { name: file.name });
|
|
111
|
-
if (
|
|
112
|
-
throw new Sentence(phrase('{name} is larger than
|
|
114
|
+
if (len > MAX)
|
|
115
|
+
throw new Sentence(phrase('{name} is larger than 2 GB'), { name: file.name });
|
|
116
|
+
const mime = file.type || 'application/octet-stream';
|
|
117
|
+
if (len > INLINE) {
|
|
118
|
+
const reserved = obj(await call(t, 'POST', '/v1/library', {
|
|
119
|
+
name: file.name,
|
|
120
|
+
mime,
|
|
121
|
+
bytes: len,
|
|
122
|
+
...made,
|
|
123
|
+
}));
|
|
124
|
+
const id = str(reserved.id);
|
|
125
|
+
const up = obj(reserved.upload);
|
|
126
|
+
const putUrl = signed(up.url);
|
|
127
|
+
if (!id)
|
|
128
|
+
throw new Error(phrase('The item was kept and came back without an id'));
|
|
129
|
+
if (!putUrl) {
|
|
130
|
+
const x = item(reserved);
|
|
131
|
+
if (!x)
|
|
132
|
+
throw new Error(phrase('The item was kept and came back without an id'));
|
|
133
|
+
return x;
|
|
134
|
+
}
|
|
135
|
+
const headers = {};
|
|
136
|
+
if (Array.isArray(up.headers)) {
|
|
137
|
+
for (const h of up.headers) {
|
|
138
|
+
const ho = obj(h);
|
|
139
|
+
const hn = str(ho.name);
|
|
140
|
+
if (hn)
|
|
141
|
+
headers[hn] = str(ho.value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const res = await fetch(putUrl, {
|
|
145
|
+
method: 'PUT',
|
|
146
|
+
headers,
|
|
147
|
+
body: (file.blob ?? file.bytes),
|
|
148
|
+
});
|
|
149
|
+
if (!res.ok)
|
|
150
|
+
throw new Sentence(phrase('{name} was not kept'), { name: file.name });
|
|
151
|
+
const done = item(await call(t, 'PATCH', `/v1/library/${seg(id)}`, { commit: true }));
|
|
152
|
+
if (!done)
|
|
153
|
+
throw new Error(phrase('The item was kept and came back without an id'));
|
|
154
|
+
return done;
|
|
155
|
+
}
|
|
156
|
+
const bytes = file.bytes ?? new Uint8Array(await file.blob.arrayBuffer());
|
|
113
157
|
const x = item(await call(t, 'POST', '/v1/library', {
|
|
114
158
|
name: file.name,
|
|
115
|
-
mime
|
|
116
|
-
data: base64(
|
|
159
|
+
mime,
|
|
160
|
+
data: base64(bytes),
|
|
117
161
|
...made,
|
|
118
162
|
}));
|
|
119
163
|
if (!x)
|
package/lib/api/sessions.js
CHANGED
|
@@ -86,9 +86,24 @@ export async function list(t, q = {}) {
|
|
|
86
86
|
}
|
|
87
87
|
export async function get(t, id) {
|
|
88
88
|
const raw = obj(await call(t, 'GET', `/v1/agent/sessions/${seg(id)}`));
|
|
89
|
+
let recent = (Array.isArray(raw.recentEvents) ? raw.recentEvents : []).map(event);
|
|
90
|
+
// The detail carries the 50 most recent events; when a long run has scrolled
|
|
91
|
+
// past seq 1, read the opening turns so the person's full multi-line ask stays
|
|
92
|
+
// at the head of the transcript and in Try again.
|
|
93
|
+
if (recent.length > 0 && recent[0].seq > 1) {
|
|
94
|
+
try {
|
|
95
|
+
const head = obj(await call(t, 'GET', `/v1/agent/sessions/${seg(id)}/events?limit=2`));
|
|
96
|
+
const first = (Array.isArray(head.events) ? head.events : []).map(event);
|
|
97
|
+
const have = new Set(recent.map((e) => e.seq));
|
|
98
|
+
recent = [...first.filter((e) => e.seq > 0 && !have.has(e.seq)), ...recent].sort((a, b) => a.seq - b.seq);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
/* keep the tail */
|
|
102
|
+
}
|
|
103
|
+
}
|
|
89
104
|
return {
|
|
90
105
|
...session(raw),
|
|
91
|
-
recent
|
|
106
|
+
recent,
|
|
92
107
|
};
|
|
93
108
|
}
|
|
94
109
|
export async function message(t, id, text) {
|
package/lib/api/turn.d.ts
CHANGED
|
@@ -170,3 +170,5 @@ export interface Settled {
|
|
|
170
170
|
* would clone a branch the push has not reached.
|
|
171
171
|
*/
|
|
172
172
|
export declare function settled(events: Pick<Event, 'kind' | 'payload' | 'seq'>[]): Settled;
|
|
173
|
+
/** The session of the run that carried this one on (its `followed` status), or ''. */
|
|
174
|
+
export declare function followed(events: Pick<Event, 'kind' | 'payload' | 'seq'>[]): string;
|
package/lib/api/turn.js
CHANGED
|
@@ -559,3 +559,15 @@ export function settled(events) {
|
|
|
559
559
|
}
|
|
560
560
|
return out;
|
|
561
561
|
}
|
|
562
|
+
/** The session of the run that carried this one on (its `followed` status), or ''. */
|
|
563
|
+
export function followed(events) {
|
|
564
|
+
let next = '';
|
|
565
|
+
for (const e of [...events].sort((a, b) => a.seq - b.seq)) {
|
|
566
|
+
if (e.kind !== 'status')
|
|
567
|
+
continue;
|
|
568
|
+
const b = decode(e.payload);
|
|
569
|
+
if (b && typeof b !== 'string' && str(b.status) === 'followed')
|
|
570
|
+
next = str(b.next);
|
|
571
|
+
}
|
|
572
|
+
return next;
|
|
573
|
+
}
|
package/lib/carry.js
CHANGED
|
@@ -22,7 +22,7 @@ import { BookOpen, ListChecks, Palette, ScrollText } from '@hanzogui/lucide-icon
|
|
|
22
22
|
import { Button, Dialog, DialogContent, DialogDescription, DialogTitle } from '@hanzo/ui';
|
|
23
23
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
24
24
|
import { call, query, unwrap } from './api/call.js';
|
|
25
|
-
import { active, authored, document, nameOf as skillOf } from './api/skills.js';
|
|
25
|
+
import { active, authored, brand as brandSkills, document, nameOf as skillOf } from './api/skills.js';
|
|
26
26
|
import { brand, brands } from './api/studio.js';
|
|
27
27
|
import { useRead } from './data.js';
|
|
28
28
|
import { said as designSaid } from './design.js';
|
|
@@ -48,11 +48,13 @@ async function said(t, skills, memory, mode, design) {
|
|
|
48
48
|
parts.push(designSaid(b));
|
|
49
49
|
}
|
|
50
50
|
if (skills.length) {
|
|
51
|
-
const own = await authored(t).catch(() => []);
|
|
51
|
+
const own = t.token() ? await authored(t).catch(() => []) : [];
|
|
52
52
|
for (const n of skills) {
|
|
53
53
|
const body = own.find((s) => s.name === n)?.content || (await document(t, n).catch(() => ''));
|
|
54
54
|
if (body)
|
|
55
55
|
parts.push(`Use the skill "${n}" where it applies:\n\n${body.slice(0, SKILL_MAX)}`);
|
|
56
|
+
else
|
|
57
|
+
parts.push(`Use the "${n}" skill where it applies.`);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
if (memory) {
|
|
@@ -93,8 +95,76 @@ export function useCarry(t, key, customize, lent, modes = DEV_MODES) {
|
|
|
93
95
|
}), [t]);
|
|
94
96
|
const found = usePlugins(t);
|
|
95
97
|
const signed = Boolean(t.token());
|
|
96
|
-
const list = useRead(
|
|
97
|
-
|
|
98
|
+
const list = useRead(async () => {
|
|
99
|
+
const [act, own, cat] = await Promise.all([
|
|
100
|
+
signed ? active(t).catch(() => []) : Promise.resolve([]),
|
|
101
|
+
signed ? authored(t).catch(() => []) : Promise.resolve([]),
|
|
102
|
+
brandSkills(t).catch(() => ({ skills: [], products: [] })),
|
|
103
|
+
]);
|
|
104
|
+
const localSkills = [];
|
|
105
|
+
try {
|
|
106
|
+
const raw = typeof localStorage !== 'undefined' ? localStorage.getItem('hanzo_enterprise_settings_v1:plugins') : null;
|
|
107
|
+
if (raw) {
|
|
108
|
+
const parsed = JSON.parse(raw);
|
|
109
|
+
if (Array.isArray(parsed?.skillsAndPlugins)) {
|
|
110
|
+
for (const item of parsed.skillsAndPlugins) {
|
|
111
|
+
if (item?.status === 'enabled' && typeof item?.name === 'string') {
|
|
112
|
+
localSkills.push(item.name);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// ignore
|
|
120
|
+
}
|
|
121
|
+
const standard = [
|
|
122
|
+
'code-review',
|
|
123
|
+
'simplify',
|
|
124
|
+
'security-review',
|
|
125
|
+
'bug-finder',
|
|
126
|
+
'test-writer',
|
|
127
|
+
'refactor',
|
|
128
|
+
'frontend-design',
|
|
129
|
+
'api-design',
|
|
130
|
+
'sql-optimizer',
|
|
131
|
+
'ui-port',
|
|
132
|
+
'app-port',
|
|
133
|
+
'hanzo-cloud',
|
|
134
|
+
'hanzo-base',
|
|
135
|
+
'hanzo-code',
|
|
136
|
+
'hanzo-dev',
|
|
137
|
+
'hanzo-cli',
|
|
138
|
+
'hanzo-commerce',
|
|
139
|
+
'hanzo-bot',
|
|
140
|
+
'hanzo-agent',
|
|
141
|
+
'hanzo-security-review',
|
|
142
|
+
'pdf-analysis',
|
|
143
|
+
'xlsx-modeling',
|
|
144
|
+
'pptx-deck-builder',
|
|
145
|
+
'docx-redline',
|
|
146
|
+
'scientific-research',
|
|
147
|
+
'mcp-builder',
|
|
148
|
+
'webapp-testing',
|
|
149
|
+
];
|
|
150
|
+
const seen = new Set();
|
|
151
|
+
const out = [];
|
|
152
|
+
for (const n of [
|
|
153
|
+
...act.map((s) => skillOf(s.name)),
|
|
154
|
+
...own.map((s) => s.name),
|
|
155
|
+
...localSkills,
|
|
156
|
+
...standard,
|
|
157
|
+
...(Array.isArray(cat?.skills) ? cat.skills.map((s) => s.name) : []),
|
|
158
|
+
]) {
|
|
159
|
+
const clean = typeof n === 'string' ? n.trim() : '';
|
|
160
|
+
if (clean && !seen.has(clean)) {
|
|
161
|
+
seen.add(clean);
|
|
162
|
+
out.push(clean);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}, [], [t, signed]);
|
|
167
|
+
const names = list.value;
|
|
98
168
|
const { skills, research, memory, design } = gear.gear;
|
|
99
169
|
const mode = modes.includes(gear.gear.mode) ? gear.gear.mode : 'auto';
|
|
100
170
|
const shelf = {
|
|
@@ -143,10 +213,12 @@ export function useCarry(t, key, customize, lent, modes = DEV_MODES) {
|
|
|
143
213
|
const [text, setText] = useState('');
|
|
144
214
|
const asked = skills.join('\n');
|
|
145
215
|
useEffect(() => {
|
|
146
|
-
if (!signedIn)
|
|
147
|
-
|
|
216
|
+
if (!signedIn && !skills.length) {
|
|
217
|
+
setText(mode === 'plan' ? 'Plan mode: lay out the plan and stop until the person says go.' : '');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
148
220
|
let live = true;
|
|
149
|
-
void said(t, skills, memory, mode, design).then((x) => live && setText(x));
|
|
221
|
+
void said(t, skills, signedIn ? memory : false, mode, signedIn ? design : '').then((x) => live && setText(x));
|
|
150
222
|
return () => {
|
|
151
223
|
live = false;
|
|
152
224
|
};
|