@hanzo/app 0.3.97 → 0.3.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Recents.js +12 -5
- package/dist/lib/todo.js +98 -20
- package/dist/rail-open.d.ts +5 -0
- package/dist/rail-open.js +9 -2
- package/package.json +1 -1
package/dist/Recents.js
CHANGED
|
@@ -234,12 +234,14 @@ function Runs({ host, view, keep, onOpen }) {
|
|
|
234
234
|
return true;
|
|
235
235
|
patchMeta(t.id, { title });
|
|
236
236
|
const tok = host.token?.();
|
|
237
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
238
|
+
if (tok)
|
|
239
|
+
headers.Authorization = `Bearer ${tok}`;
|
|
240
|
+
if (host.org)
|
|
241
|
+
headers['X-Org-Id'] = host.org;
|
|
237
242
|
void fetch(`${host.api}/v1/agent/sessions/${encodeURIComponent(t.id)}`, {
|
|
238
243
|
method: 'PATCH',
|
|
239
|
-
headers
|
|
240
|
-
...(tok ? { Authorization: `Bearer ${tok}` } : {}),
|
|
241
|
-
'Content-Type': 'application/json',
|
|
242
|
-
},
|
|
244
|
+
headers,
|
|
243
245
|
body: JSON.stringify({ title }),
|
|
244
246
|
}).catch(() => { });
|
|
245
247
|
return true;
|
|
@@ -247,9 +249,14 @@ function Runs({ host, view, keep, onOpen }) {
|
|
|
247
249
|
remove: async (t) => {
|
|
248
250
|
patchMeta(t.id, { deleted: true });
|
|
249
251
|
const tok = host.token?.();
|
|
252
|
+
const headers = {};
|
|
253
|
+
if (tok)
|
|
254
|
+
headers.Authorization = `Bearer ${tok}`;
|
|
255
|
+
if (host.org)
|
|
256
|
+
headers['X-Org-Id'] = host.org;
|
|
250
257
|
void fetch(`${host.api}/v1/agent/sessions/${encodeURIComponent(t.id)}`, {
|
|
251
258
|
method: 'DELETE',
|
|
252
|
-
headers
|
|
259
|
+
headers,
|
|
253
260
|
}).catch(() => { });
|
|
254
261
|
return true;
|
|
255
262
|
},
|
package/dist/lib/todo.js
CHANGED
|
@@ -15,6 +15,79 @@ export const COLUMNS = [
|
|
|
15
15
|
/** The priorities the store accepts, loudest first. */
|
|
16
16
|
export const PRIORITIES = ['urgent', 'high', 'medium', 'low', 'none'];
|
|
17
17
|
const STORAGE_KEY = 'hanzo_board_cards';
|
|
18
|
+
/**
|
|
19
|
+
* What `/v1/task/*` answers when a caller has no forge seat yet in a
|
|
20
|
+
* platform-made code workspace, or when the org has no forge namespace yet
|
|
21
|
+
* (cloud apps/task/source.go). Opening `/v1/git/workspace` provisions both
|
|
22
|
+
* idempotently; an API-key refusal ("a seat in a code workspace is a person's")
|
|
23
|
+
* does not match and surfaces untouched.
|
|
24
|
+
*/
|
|
25
|
+
const UNSEATED = /no forge identity for this principal yet|no namespace on the forge yet/i;
|
|
26
|
+
const seatedByClient = new WeakMap();
|
|
27
|
+
function isUnseated(err) {
|
|
28
|
+
if (!err || typeof err !== 'object')
|
|
29
|
+
return false;
|
|
30
|
+
const e = err;
|
|
31
|
+
if (e.status !== 403)
|
|
32
|
+
return false;
|
|
33
|
+
const detail = typeof e.body === 'object' && e.body !== null && 'detail' in e.body
|
|
34
|
+
? String(e.body.detail ?? '')
|
|
35
|
+
: typeof e.body === 'string'
|
|
36
|
+
? e.body
|
|
37
|
+
: '';
|
|
38
|
+
const text = `${typeof e.message === 'string' ? e.message : ''} ${detail}`;
|
|
39
|
+
return UNSEATED.test(text);
|
|
40
|
+
}
|
|
41
|
+
function seatWorkspace(client) {
|
|
42
|
+
let pending = seatedByClient.get(client);
|
|
43
|
+
if (!pending) {
|
|
44
|
+
pending = client.http
|
|
45
|
+
.json({
|
|
46
|
+
method: 'POST',
|
|
47
|
+
path: '/v1/git/workspace',
|
|
48
|
+
body: {},
|
|
49
|
+
})
|
|
50
|
+
.catch((e) => {
|
|
51
|
+
seatedByClient.delete(client);
|
|
52
|
+
throw e;
|
|
53
|
+
});
|
|
54
|
+
seatedByClient.set(client, pending);
|
|
55
|
+
}
|
|
56
|
+
return pending;
|
|
57
|
+
}
|
|
58
|
+
/** Runs a `/v1/task/*` request, seating the caller on the forge once if 403 unseated. */
|
|
59
|
+
async function seated(client, run) {
|
|
60
|
+
try {
|
|
61
|
+
return await run();
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
if (!isUnseated(e))
|
|
65
|
+
throw e;
|
|
66
|
+
await seatWorkspace(client);
|
|
67
|
+
return run();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function normalizeBoardKey(key) {
|
|
71
|
+
return key.trim().toLowerCase().replace(/_/g, '-');
|
|
72
|
+
}
|
|
73
|
+
function projectBoardKey(p) {
|
|
74
|
+
const repoUrl = p.repo?.url?.trim();
|
|
75
|
+
if (repoUrl) {
|
|
76
|
+
try {
|
|
77
|
+
const parsed = new URL(repoUrl);
|
|
78
|
+
if (/^git\./i.test(parsed.hostname)) {
|
|
79
|
+
const segs = parsed.pathname.replace(/\/+$/, '').split('/').filter(Boolean);
|
|
80
|
+
const last = segs[segs.length - 1]?.replace(/\.git$/i, '');
|
|
81
|
+
if (last)
|
|
82
|
+
return last;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch { }
|
|
86
|
+
}
|
|
87
|
+
if (p.slug?.trim())
|
|
88
|
+
return p.slug.trim();
|
|
89
|
+
return (p.name || p.id || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
90
|
+
}
|
|
18
91
|
export const DEFAULT_CARDS = [
|
|
19
92
|
{
|
|
20
93
|
id: 'hanzo-1',
|
|
@@ -144,11 +217,11 @@ export async function board(client, params = {}, signal) {
|
|
|
144
217
|
query.label = params.label;
|
|
145
218
|
if (params.scheduled !== undefined)
|
|
146
219
|
query.scheduled = String(params.scheduled);
|
|
147
|
-
const out = await client.http.json({
|
|
220
|
+
const out = await seated(client, () => client.http.json({
|
|
148
221
|
path: '/v1/task/board',
|
|
149
222
|
query,
|
|
150
223
|
signal,
|
|
151
|
-
});
|
|
224
|
+
}));
|
|
152
225
|
const fetched = rows(out);
|
|
153
226
|
// A SUCCESSFUL READ IS THE ANSWER, EMPTY OR NOT. An org whose board holds
|
|
154
227
|
// no cards yet is a fact about the org — the empty state a reader is owed
|
|
@@ -173,15 +246,13 @@ export async function board(client, params = {}, signal) {
|
|
|
173
246
|
export function targetOf(own, shown, keys) {
|
|
174
247
|
return own || (shown && shown !== 'all' ? shown : '') || keys[0] || '';
|
|
175
248
|
}
|
|
176
|
-
/** The boards the server names (
|
|
249
|
+
/** The boards the server names (task's own, then the org's projects), added to `map` when one is given; with a fresh map, no stand-ins. */
|
|
177
250
|
async function served(client, signal, map = new Map()) {
|
|
178
251
|
const [todoPs, devPs] = await Promise.all([
|
|
179
|
-
client.http
|
|
180
|
-
.json({
|
|
252
|
+
seated(client, () => client.http.json({
|
|
181
253
|
path: '/v1/task/projects',
|
|
182
254
|
signal,
|
|
183
|
-
})
|
|
184
|
-
.catch(() => null),
|
|
255
|
+
})).catch(() => null),
|
|
185
256
|
client.http
|
|
186
257
|
.json({
|
|
187
258
|
path: '/v1/project',
|
|
@@ -189,14 +260,23 @@ async function served(client, signal, map = new Map()) {
|
|
|
189
260
|
})
|
|
190
261
|
.catch(() => null),
|
|
191
262
|
]);
|
|
263
|
+
const seen = new Set(Array.from(map.keys(), normalizeBoardKey));
|
|
192
264
|
for (const p of rows(todoPs)) {
|
|
193
|
-
if (p?.key)
|
|
265
|
+
if (!p?.key)
|
|
266
|
+
continue;
|
|
267
|
+
const norm = normalizeBoardKey(p.key);
|
|
268
|
+
if (!map.has(p.key) && !seen.has(norm)) {
|
|
194
269
|
map.set(p.key, { key: p.key, name: p.name || p.key });
|
|
270
|
+
seen.add(norm);
|
|
271
|
+
}
|
|
195
272
|
}
|
|
196
273
|
for (const p of Array.isArray(devPs) ? devPs : []) {
|
|
197
|
-
const k = (p
|
|
198
|
-
|
|
274
|
+
const k = projectBoardKey(p);
|
|
275
|
+
const norm = normalizeBoardKey(k);
|
|
276
|
+
if (k && !map.has(k) && !seen.has(norm)) {
|
|
199
277
|
map.set(k, { key: k, name: p.name || k });
|
|
278
|
+
seen.add(norm);
|
|
279
|
+
}
|
|
200
280
|
}
|
|
201
281
|
return Array.from(map.values());
|
|
202
282
|
}
|
|
@@ -215,10 +295,8 @@ export async function projects(client, signal) {
|
|
|
215
295
|
if (!client)
|
|
216
296
|
return fallback;
|
|
217
297
|
try {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
map.set(f.key, f);
|
|
221
|
-
return await served(client, signal, map);
|
|
298
|
+
const live = await served(client, signal);
|
|
299
|
+
return live.length > 0 ? live : fallback;
|
|
222
300
|
}
|
|
223
301
|
catch {
|
|
224
302
|
return fallback;
|
|
@@ -246,12 +324,12 @@ export async function open(client, key, card, signal) {
|
|
|
246
324
|
};
|
|
247
325
|
if (client) {
|
|
248
326
|
try {
|
|
249
|
-
const created = await client.http.json({
|
|
327
|
+
const created = await seated(client, () => client.http.json({
|
|
250
328
|
method: 'POST',
|
|
251
329
|
path: `/v1/task/projects/${encodeURIComponent(key)}/issues`,
|
|
252
330
|
body: card,
|
|
253
331
|
signal,
|
|
254
|
-
});
|
|
332
|
+
}));
|
|
255
333
|
if (created?.id) {
|
|
256
334
|
saveLocalCards([created, ...current]);
|
|
257
335
|
return created;
|
|
@@ -286,12 +364,12 @@ export async function edit(client, key, num, patch, signal) {
|
|
|
286
364
|
}
|
|
287
365
|
if (client) {
|
|
288
366
|
try {
|
|
289
|
-
const serverUpdated = await client.http.json({
|
|
367
|
+
const serverUpdated = await seated(client, () => client.http.json({
|
|
290
368
|
method: 'PATCH',
|
|
291
369
|
path: `/v1/task/projects/${encodeURIComponent(key)}/issues/${num}`,
|
|
292
370
|
body: patch,
|
|
293
371
|
signal,
|
|
294
|
-
});
|
|
372
|
+
}));
|
|
295
373
|
if (serverUpdated?.id) {
|
|
296
374
|
return serverUpdated;
|
|
297
375
|
}
|
|
@@ -304,12 +382,12 @@ export async function edit(client, key, num, patch, signal) {
|
|
|
304
382
|
export async function claim(client, key, num, signal) {
|
|
305
383
|
if (client) {
|
|
306
384
|
try {
|
|
307
|
-
return await client.http.json({
|
|
385
|
+
return await seated(client, () => client.http.json({
|
|
308
386
|
method: 'POST',
|
|
309
387
|
path: `/v1/task/projects/${encodeURIComponent(key)}/issues/${num}/claim`,
|
|
310
388
|
body: {},
|
|
311
389
|
signal,
|
|
312
|
-
});
|
|
390
|
+
}));
|
|
313
391
|
}
|
|
314
392
|
catch { }
|
|
315
393
|
}
|
package/dist/rail-open.d.ts
CHANGED
|
@@ -5,5 +5,10 @@
|
|
|
5
5
|
* The page is prerendered, so the first pass draws the server's tree (open) and what the reader kept arrives
|
|
6
6
|
* after mount; nothing kept falls back to Hanzo's earlier key `hanzo:sidebar:open`, then the window's width.
|
|
7
7
|
* `away` shuts it for now without keeping that: a pick on a phone is not a choice to keep it shut.
|
|
8
|
+
*
|
|
9
|
+
* The setter reads whether it is open NOW, not when the setter was made. The Shell keeps its toggle from the
|
|
10
|
+
* first render (`useCallback` with no dependencies, for ⌘B), and that render draws the server's tree, open: a
|
|
11
|
+
* setter closed over it answered every toggle with "shut", so on a phone, where the rail starts away, "Open
|
|
12
|
+
* sidebar" could never open it.
|
|
8
13
|
*/
|
|
9
14
|
export declare function useSidebar(): [boolean, (next: boolean | ((open: boolean) => boolean)) => void, () => void];
|
package/dist/rail-open.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { useKept } from './kept.js';
|
|
4
4
|
/**
|
|
5
5
|
* Whether the Shell's sidebar is open, kept under App.tsx's key (`hanzo.build.rail`, true when shut) so the
|
|
@@ -8,6 +8,11 @@ import { useKept } from './kept.js';
|
|
|
8
8
|
* The page is prerendered, so the first pass draws the server's tree (open) and what the reader kept arrives
|
|
9
9
|
* after mount; nothing kept falls back to Hanzo's earlier key `hanzo:sidebar:open`, then the window's width.
|
|
10
10
|
* `away` shuts it for now without keeping that: a pick on a phone is not a choice to keep it shut.
|
|
11
|
+
*
|
|
12
|
+
* The setter reads whether it is open NOW, not when the setter was made. The Shell keeps its toggle from the
|
|
13
|
+
* first render (`useCallback` with no dependencies, for ⌘B), and that render draws the server's tree, open: a
|
|
14
|
+
* setter closed over it answered every toggle with "shut", so on a phone, where the rail starts away, "Open
|
|
15
|
+
* sidebar" could never open it.
|
|
11
16
|
*/
|
|
12
17
|
export function useSidebar() {
|
|
13
18
|
const [shut, setShut] = useKept('hanzo.build.rail', null);
|
|
@@ -26,9 +31,11 @@ export function useSidebar() {
|
|
|
26
31
|
setStarted(true);
|
|
27
32
|
}, []);
|
|
28
33
|
const open = !away && (started ? (shut === null ? first : !shut) : true);
|
|
34
|
+
const now = useRef(open);
|
|
35
|
+
now.current = open;
|
|
29
36
|
const set = (next) => {
|
|
30
37
|
setAway(false);
|
|
31
|
-
setShut(!(typeof next === 'function' ? next(
|
|
38
|
+
setShut(!(typeof next === 'function' ? next(now.current) : next));
|
|
32
39
|
};
|
|
33
40
|
return [open, set, () => setAway(true)];
|
|
34
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.100",
|
|
4
4
|
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|