@neta-art/cohub-cli 10.22.0 → 10.24.0
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 +18 -5
- package/dist/avatar.d.ts +14 -1
- package/dist/avatar.js +33 -0
- package/dist/board-kernel.js +25 -2
- package/dist/build.json +1 -1
- package/dist/commands/generations.js +2 -1
- package/dist/commands/me.js +35 -2
- package/dist/commands/models.js +23 -2
- package/dist/commands/space-wallet.js +89 -12
- package/dist/commands/spaces.js +67 -16
- package/dist/host/auth.js +20 -8
- package/dist/runtime/native/daemon.js +1 -0
- package/dist/runtime/native/pi-extension.d.ts +1 -0
- package/dist/runtime/native/pi-extension.js +21 -4
- package/dist/runtime/native/pi-link.d.ts +2 -0
- package/dist/runtime/native/pi-link.js +23 -9
- package/dist/session-status.d.ts +6 -2
- package/dist/session-status.js +9 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -256,10 +256,16 @@ cohub -s <spaceId> spaces sessions create "<title>" --json
|
|
|
256
256
|
cohub -s <spaceId> spaces sessions get <sessionId> --json
|
|
257
257
|
cohub -s <spaceId> spaces sessions files <sessionId> --json
|
|
258
258
|
cohub -s <spaceId> spaces sessions rename <sessionId> "<new title>"
|
|
259
|
+
cohub -s <spaceId> spaces sessions archive <sessionId...>
|
|
260
|
+
cohub -s <spaceId> spaces sessions unarchive <sessionId...>
|
|
261
|
+
cohub -s <spaceId> spaces sessions ls --archived # --all includes archived Chats
|
|
259
262
|
```
|
|
260
263
|
|
|
261
264
|
Use `spaces prompt --session <sessionId>` to send to a Chat.
|
|
262
265
|
|
|
266
|
+
Archiving hides a Chat for every member and frees its runtime files after a
|
|
267
|
+
short grace period. Sending a message to an archived Chat restores it.
|
|
268
|
+
|
|
263
269
|
## Space turns
|
|
264
270
|
|
|
265
271
|
List recent turns across all visible Sessions in a Space:
|
|
@@ -300,15 +306,22 @@ cohub -s <spaceId> spaces activity 365 --json
|
|
|
300
306
|
|
|
301
307
|
```bash
|
|
302
308
|
cohub -s <spaceId> spaces wallet balance
|
|
303
|
-
cohub -s <spaceId> spaces wallet
|
|
304
|
-
cohub -s <spaceId> spaces wallet
|
|
309
|
+
cohub -s <spaceId> spaces wallet funding
|
|
310
|
+
cohub -s <spaceId> spaces wallet transfer 50
|
|
311
|
+
cohub -s <spaceId> spaces wallet transfer-status <requestId>
|
|
312
|
+
cohub -s <spaceId> spaces wallet recharge <productKey>
|
|
305
313
|
cohub -s <spaceId> spaces wallet confirm <orderId>
|
|
314
|
+
cohub -s <spaceId> spaces wallet public-funding on
|
|
306
315
|
cohub -s <spaceId> spaces wallet activity --page 1 --json
|
|
307
316
|
```
|
|
308
317
|
|
|
309
|
-
|
|
310
|
-
recharge
|
|
311
|
-
|
|
318
|
+
`transfer` moves purchased personal balance (whole USD) into the wallet;
|
|
319
|
+
`recharge` prints a payment URL for a funding tier. Request IDs are generated
|
|
320
|
+
automatically; when a result is uncertain the CLI prints a retry command with
|
|
321
|
+
`--request-id` that continues the same transfer or order. Viewers of the Space
|
|
322
|
+
can always fund it; with public funding on, anyone signed in can. Funding does
|
|
323
|
+
not grant access, and wallet funds cannot be withdrawn. Transfers require a
|
|
324
|
+
personal session, not an agent execution token.
|
|
312
325
|
|
|
313
326
|
## Boards
|
|
314
327
|
|
package/dist/avatar.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CohubHttpClient, type PublicAssetPurpose } from "@neta-art/cohub";
|
|
2
2
|
type PreparedAvatar = {
|
|
3
3
|
body: Buffer;
|
|
4
4
|
mimeType: "image/webp" | "image/jpeg" | "image/png" | "image/gif";
|
|
@@ -18,6 +18,19 @@ export declare function uploadAvatarAsset(input: {
|
|
|
18
18
|
uploadMethod: "PUT";
|
|
19
19
|
uploadHeaders?: Record<string, string>;
|
|
20
20
|
}>;
|
|
21
|
+
export declare function normalizeLikeStickerFile(path: string): Promise<PreparedAvatar>;
|
|
22
|
+
export declare function uploadLikeStickerAsset(input: {
|
|
23
|
+
client: CohubHttpClient;
|
|
24
|
+
spaceId: string;
|
|
25
|
+
path: string;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
purpose: PublicAssetPurpose;
|
|
28
|
+
objectKey: string;
|
|
29
|
+
publicUrl: string;
|
|
30
|
+
uploadUrl: string;
|
|
31
|
+
uploadMethod: "PUT";
|
|
32
|
+
uploadHeaders?: Record<string, string>;
|
|
33
|
+
}>;
|
|
21
34
|
export declare function normalizeChatImageFile(path: string): Promise<{
|
|
22
35
|
body: Buffer<ArrayBuffer>;
|
|
23
36
|
width: number;
|
package/dist/avatar.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { LIKE_STICKER_MAX_EDGE, LIKE_STICKER_MAX_FILE_BYTES } from "@neta-art/cohub";
|
|
2
3
|
const loadSharp = async () => (await import("sharp")).default;
|
|
3
4
|
const AVATAR_SIZE = 1024;
|
|
4
5
|
const AVATAR_QUALITY = 86;
|
|
@@ -47,6 +48,38 @@ export async function uploadAvatarAsset(input) {
|
|
|
47
48
|
filename: `avatar.${avatar.extension}`,
|
|
48
49
|
});
|
|
49
50
|
}
|
|
51
|
+
export async function normalizeLikeStickerFile(path) {
|
|
52
|
+
const original = await readFile(path);
|
|
53
|
+
const format = detectAvatarFormat(original);
|
|
54
|
+
if (!format)
|
|
55
|
+
throw new Error("Like sticker must be a PNG, GIF, WebP, or JPEG image");
|
|
56
|
+
const sharp = await loadSharp().catch(() => null);
|
|
57
|
+
let prepared = { body: original, ...format };
|
|
58
|
+
if (sharp) {
|
|
59
|
+
const body = await sharp(original, { animated: true })
|
|
60
|
+
.resize(LIKE_STICKER_MAX_EDGE, LIKE_STICKER_MAX_EDGE, { fit: "inside", withoutEnlargement: true })
|
|
61
|
+
.webp({ quality: AVATAR_QUALITY, effort: 5 })
|
|
62
|
+
.toBuffer();
|
|
63
|
+
prepared = { body, mimeType: "image/webp", extension: "webp" };
|
|
64
|
+
}
|
|
65
|
+
else if (format.mimeType === "image/jpeg") {
|
|
66
|
+
throw new Error("Converting a JPEG like sticker needs sharp; use a PNG, GIF, or WebP image");
|
|
67
|
+
}
|
|
68
|
+
if (prepared.body.byteLength > LIKE_STICKER_MAX_FILE_BYTES) {
|
|
69
|
+
throw new Error(`Like sticker must be at most ${LIKE_STICKER_MAX_FILE_BYTES / 1024 / 1024} MiB after resizing`);
|
|
70
|
+
}
|
|
71
|
+
return prepared;
|
|
72
|
+
}
|
|
73
|
+
export async function uploadLikeStickerAsset(input) {
|
|
74
|
+
const sticker = await normalizeLikeStickerFile(input.path);
|
|
75
|
+
return input.client.publicAssets.upload({
|
|
76
|
+
purpose: "space_like_sticker",
|
|
77
|
+
spaceId: input.spaceId,
|
|
78
|
+
file: new Blob([new Uint8Array(sticker.body)], { type: sticker.mimeType }),
|
|
79
|
+
mimeType: sticker.mimeType,
|
|
80
|
+
filename: `like-sticker.${sticker.extension}`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
50
83
|
const CHAT_IMAGE_MAX_EDGE = 1984;
|
|
51
84
|
const CHAT_IMAGE_QUALITY = 86;
|
|
52
85
|
export async function normalizeChatImageFile(path) {
|
package/dist/board-kernel.js
CHANGED
|
@@ -52147,6 +52147,7 @@ function createBoardEditor(options) {
|
|
|
52147
52147
|
const registry = options.registry ?? defaultBoardRegistry;
|
|
52148
52148
|
const channels = createChannels();
|
|
52149
52149
|
const track = options.track ?? (() => {});
|
|
52150
|
+
let collecting = null;
|
|
52150
52151
|
const preferences = options.preferences;
|
|
52151
52152
|
const state = observable({
|
|
52152
52153
|
base: options.document,
|
|
@@ -52256,11 +52257,16 @@ function createBoardEditor(options) {
|
|
|
52256
52257
|
};
|
|
52257
52258
|
ctx.preferencesChanged();
|
|
52258
52259
|
}
|
|
52260
|
+
function note(channel) {
|
|
52261
|
+
track(channel);
|
|
52262
|
+
collecting?.add(channel);
|
|
52263
|
+
}
|
|
52259
52264
|
function read(channel, value) {
|
|
52260
|
-
if (typeof channel === "string")
|
|
52261
|
-
else for (const each of channel)
|
|
52265
|
+
if (typeof channel === "string") note(channel);
|
|
52266
|
+
else for (const each of channel) note(each);
|
|
52262
52267
|
return value();
|
|
52263
52268
|
}
|
|
52269
|
+
const visibleRect = memo(() => [state.camera, state.surfaceSize], (_camera, _surface) => camera.visibleRect());
|
|
52264
52270
|
function tracked(channels, query) {
|
|
52265
52271
|
return (...args) => read(channels, () => query(...args));
|
|
52266
52272
|
}
|
|
@@ -52268,6 +52274,20 @@ function createBoardEditor(options) {
|
|
|
52268
52274
|
registry,
|
|
52269
52275
|
readonly: options.readonly === true,
|
|
52270
52276
|
subscribe: channels.subscribe,
|
|
52277
|
+
collect(read) {
|
|
52278
|
+
const outer = collecting;
|
|
52279
|
+
const seen = /* @__PURE__ */ new Set();
|
|
52280
|
+
collecting = seen;
|
|
52281
|
+
try {
|
|
52282
|
+
return {
|
|
52283
|
+
value: read(),
|
|
52284
|
+
channels: seen
|
|
52285
|
+
};
|
|
52286
|
+
} finally {
|
|
52287
|
+
collecting = outer;
|
|
52288
|
+
if (outer) for (const channel of seen) outer.add(channel);
|
|
52289
|
+
}
|
|
52290
|
+
},
|
|
52271
52291
|
get hasScripts() {
|
|
52272
52292
|
return read("document", () => hasBoardScripts(state.base));
|
|
52273
52293
|
},
|
|
@@ -52322,6 +52342,9 @@ function createBoardEditor(options) {
|
|
|
52322
52342
|
get camera() {
|
|
52323
52343
|
return read("camera", () => state.camera);
|
|
52324
52344
|
},
|
|
52345
|
+
get visibleRect() {
|
|
52346
|
+
return read("camera", visibleRect);
|
|
52347
|
+
},
|
|
52325
52348
|
get cameraPolicy() {
|
|
52326
52349
|
return read("camera", () => state.cameraPolicy);
|
|
52327
52350
|
},
|
package/dist/build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commit":"
|
|
1
|
+
{"commit":"d44f824"}
|
|
@@ -366,7 +366,8 @@ Examples:
|
|
|
366
366
|
if (opts.async) {
|
|
367
367
|
if (jsonRequested(opts))
|
|
368
368
|
return outJson(created);
|
|
369
|
-
|
|
369
|
+
const reserved = created.reservation ? `\n reserved: ${created.reservation.amountUsd} USD` : "";
|
|
370
|
+
return ok(`Generation queued — task ID: ${created.taskRunId}${reserved}\n ${resumeHint(created.taskRunId)}`);
|
|
370
371
|
}
|
|
371
372
|
const spin = spinner();
|
|
372
373
|
let pollCount = 0;
|
package/dist/commands/me.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClient } from "../client.js";
|
|
2
2
|
import { formatLocalDateTime, handleHttp, json as outJson, jsonRequested, table } from "../output.js";
|
|
3
|
-
import { SESSION_STATUS_COLUMN } from "../session-status.js";
|
|
3
|
+
import { SESSION_STATUS_COLUMN, sessionArchiveFilter } from "../session-status.js";
|
|
4
4
|
function parseInteger(value, name, min) {
|
|
5
5
|
const parsed = Number.parseInt(value, 10);
|
|
6
6
|
if (!Number.isSafeInteger(parsed) || parsed < min) {
|
|
@@ -14,9 +14,11 @@ export function registerMe(program) {
|
|
|
14
14
|
meCmd
|
|
15
15
|
.command("sessions")
|
|
16
16
|
.alias("list-sessions")
|
|
17
|
-
.description("List sessions you created across all spaces")
|
|
17
|
+
.description("List sessions you created across all spaces (archived sessions are hidden by default)")
|
|
18
18
|
.option("--limit <n>", "Maximum number of sessions (default 20)")
|
|
19
19
|
.option("--cursor <cursor>", "Pagination cursor from a previous result")
|
|
20
|
+
.option("--archived", "List only archived sessions")
|
|
21
|
+
.option("--all", "Include archived sessions")
|
|
20
22
|
.option("--json", "Output as JSON")
|
|
21
23
|
.action(async (opts) => {
|
|
22
24
|
const client = createClient();
|
|
@@ -24,6 +26,7 @@ export function registerMe(program) {
|
|
|
24
26
|
const result = await client.user.listSessions({
|
|
25
27
|
limit: opts.limit ? parseInteger(opts.limit, "limit", 1) : undefined,
|
|
26
28
|
cursor: opts.cursor ?? null,
|
|
29
|
+
archived: sessionArchiveFilter(opts),
|
|
27
30
|
});
|
|
28
31
|
if (jsonRequested(opts))
|
|
29
32
|
return outJson(result);
|
|
@@ -44,6 +47,36 @@ export function registerMe(program) {
|
|
|
44
47
|
handleHttp(e);
|
|
45
48
|
}
|
|
46
49
|
});
|
|
50
|
+
meCmd
|
|
51
|
+
.command("billing-activity")
|
|
52
|
+
.description("List your personal wallet activity, including generation reserves and refunds")
|
|
53
|
+
.option("--page <n>", "Page number (default 1)")
|
|
54
|
+
.option("--json", "Output as JSON")
|
|
55
|
+
.action(async (opts) => {
|
|
56
|
+
const client = createClient();
|
|
57
|
+
try {
|
|
58
|
+
const { activities } = await client.billing.getBalanceActivities({
|
|
59
|
+
page: opts.page ? parseInteger(opts.page, "page", 1) : undefined,
|
|
60
|
+
});
|
|
61
|
+
if (jsonRequested(opts))
|
|
62
|
+
return outJson(activities);
|
|
63
|
+
if (activities.items.length === 0) {
|
|
64
|
+
console.log(" (empty)");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
table(activities.items, [
|
|
68
|
+
{ key: "title", label: "Activity" },
|
|
69
|
+
{ key: "amountUsd", label: "Amount (USD)" },
|
|
70
|
+
{ key: "operationId", label: "Operation" },
|
|
71
|
+
{ key: "createdAt", label: "Date" },
|
|
72
|
+
]);
|
|
73
|
+
if (activities.pagination.hasMore)
|
|
74
|
+
console.log(` More: --page ${activities.page + 1}`);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
handleHttp(e);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
47
80
|
meCmd
|
|
48
81
|
.command("activity")
|
|
49
82
|
.description("Show your activity across all spaces")
|
package/dist/commands/models.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { filterDiscoverableGenerationModels, filterGenerationDeclarationsByPolicy, getAllowedGenerationModelIds, parseGenerationPolicyFromEnv, } from "@neta-art/cohub";
|
|
2
2
|
import { createClient } from "../client.js";
|
|
3
|
+
import { explicitSpace, failSpaceTarget, resolveSpaceRef } from "../space.js";
|
|
3
4
|
import { table, json as outJson, jsonRequested, error, handleHttp } from "../output.js";
|
|
4
5
|
export function toMultimodalModelSummary(model) {
|
|
5
6
|
return {
|
|
@@ -154,6 +155,21 @@ function printMultimodalModel(model) {
|
|
|
154
155
|
return `${index + 1}. ${title}${prompt ? `"${prompt}"` : example.request.model}`;
|
|
155
156
|
}));
|
|
156
157
|
}
|
|
158
|
+
function formatModelContext(model) {
|
|
159
|
+
const value = model.contextWindow;
|
|
160
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
161
|
+
return "";
|
|
162
|
+
const source = typeof model.contextWindowSource === "string" ? model.contextWindowSource : null;
|
|
163
|
+
const ref = typeof model.contextWindowSourceRef === "string" ? `:${model.contextWindowSourceRef}` : "";
|
|
164
|
+
return source ? `${formatTokenCount(value)} (${source}${ref})` : formatTokenCount(value);
|
|
165
|
+
}
|
|
166
|
+
function formatTokenCount(value) {
|
|
167
|
+
if (value >= 1_000_000)
|
|
168
|
+
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
169
|
+
if (value >= 1_000)
|
|
170
|
+
return `${(value / 1_000).toFixed(1)}k`;
|
|
171
|
+
return String(value);
|
|
172
|
+
}
|
|
157
173
|
export function registerModels(program) {
|
|
158
174
|
const cmd = program
|
|
159
175
|
.command("models")
|
|
@@ -162,6 +178,7 @@ export function registerModels(program) {
|
|
|
162
178
|
|
|
163
179
|
Examples:
|
|
164
180
|
cohub models ls
|
|
181
|
+
cohub models ls --space <spaceId>
|
|
165
182
|
cohub models ls --model-type multimodal
|
|
166
183
|
cohub models ls --model-type multimodal --json
|
|
167
184
|
cohub models show <model>
|
|
@@ -173,7 +190,7 @@ Examples:
|
|
|
173
190
|
.description("List available models")
|
|
174
191
|
.option("--model-type <type>", "Model type: llm | multimodal", "llm")
|
|
175
192
|
.option("--json", "Output as JSON")
|
|
176
|
-
.action(async (opts) => {
|
|
193
|
+
.action(async (opts, command) => {
|
|
177
194
|
const client = createClient();
|
|
178
195
|
try {
|
|
179
196
|
if (opts.modelType === "multimodal") {
|
|
@@ -201,7 +218,9 @@ Examples:
|
|
|
201
218
|
if (opts.modelType && opts.modelType !== "llm") {
|
|
202
219
|
return error("Invalid model type", "Use --model-type llm or --model-type multimodal");
|
|
203
220
|
}
|
|
204
|
-
const
|
|
221
|
+
const spaceRef = explicitSpace(command);
|
|
222
|
+
const spaceId = spaceRef ? await resolveSpaceRef(spaceRef).catch(failSpaceTarget) : undefined;
|
|
223
|
+
const catalog = await client.models.list({ spaceId });
|
|
205
224
|
const visibleCatalog = filterHiddenLlmModels(catalog);
|
|
206
225
|
if (jsonRequested(opts))
|
|
207
226
|
return outJson(visibleCatalog);
|
|
@@ -213,10 +232,12 @@ Examples:
|
|
|
213
232
|
table(entries.map((entry) => ({
|
|
214
233
|
id: entry.id,
|
|
215
234
|
provider: entry.provider,
|
|
235
|
+
context: formatModelContext(entry.model),
|
|
216
236
|
cost: formatLlmModelCost(entry.model),
|
|
217
237
|
})), [
|
|
218
238
|
{ key: "id", label: "ID" },
|
|
219
239
|
{ key: "provider", label: "Provider" },
|
|
240
|
+
{ key: "context", label: "Context" },
|
|
220
241
|
{ key: "cost", label: "Cost" },
|
|
221
242
|
]);
|
|
222
243
|
}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { createClient } from "../client.js";
|
|
2
|
-
import { handleHttp, json as outJson, jsonRequested, table } from "../output.js";
|
|
3
|
+
import { handleHttp, json as outJson, jsonRequested, ok, table, warn } from "../output.js";
|
|
3
4
|
import { resolveSpace } from "../space.js";
|
|
5
|
+
const usd = (value) => `$${value.toFixed(2)}`;
|
|
6
|
+
const uncertain = (cause) => {
|
|
7
|
+
const status = cause.status;
|
|
8
|
+
return !status || status >= 500;
|
|
9
|
+
};
|
|
10
|
+
function retryHint(command, requestId) {
|
|
11
|
+
warn(`Result unknown. Retry with: ${command} --request-id ${requestId}`);
|
|
12
|
+
}
|
|
4
13
|
export function registerSpaceWallet(spaces) {
|
|
5
|
-
const wallet = spaces.command("wallet").description("Space wallet balance,
|
|
14
|
+
const wallet = spaces.command("wallet").description("Space wallet balance, funding, and activity");
|
|
15
|
+
const space = async () => createClient().space(await resolveSpace(spaces)).wallet;
|
|
6
16
|
wallet.command("balance").option("--json", "Output as JSON").action(async (opts) => {
|
|
7
17
|
try {
|
|
8
|
-
const value = await
|
|
18
|
+
const value = await (await space()).get();
|
|
9
19
|
if (jsonRequested(opts))
|
|
10
20
|
return outJson(value);
|
|
11
21
|
table([{ balance: `$${value.balanceUsd.toFixed(8)}`, usable: value.usable }], [{ key: "balance", label: "Balance" }, { key: "usable", label: "Usable" }]);
|
|
@@ -14,12 +24,26 @@ export function registerSpaceWallet(spaces) {
|
|
|
14
24
|
handleHttp(cause);
|
|
15
25
|
}
|
|
16
26
|
});
|
|
17
|
-
wallet.command("
|
|
27
|
+
wallet.command("funding").description("Funding tiers and your transferable balance").option("--json", "Output as JSON").action(async (opts) => {
|
|
18
28
|
try {
|
|
19
|
-
const value = await
|
|
29
|
+
const value = await (await space()).funding();
|
|
20
30
|
if (jsonRequested(opts))
|
|
21
31
|
return outJson(value);
|
|
22
|
-
table(value.
|
|
32
|
+
table(value.tiers.map((tier) => ({ product: tier.productKey, amount: usd(tier.amountUsd), price: usd(tier.priceUsd) })), [{ key: "product", label: "Product" }, { key: "amount", label: "Credits" }, { key: "price", label: "Price" }]);
|
|
33
|
+
console.log(`Public funding: ${value.publicFunding ? "on" : "off"}`);
|
|
34
|
+
if (value.transfer)
|
|
35
|
+
console.log(`Transferable balance: ${usd(value.transfer.allowanceUsd)} (whole dollars, ${usd(value.transfer.minUsd)}–${usd(value.transfer.maxUsd)})`);
|
|
36
|
+
}
|
|
37
|
+
catch (cause) {
|
|
38
|
+
handleHttp(cause);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
wallet.command("public-funding <state>").description("Let anyone signed in fund this wallet (on|off)").action(async (state) => {
|
|
42
|
+
try {
|
|
43
|
+
if (state !== "on" && state !== "off")
|
|
44
|
+
throw new Error("State must be on or off");
|
|
45
|
+
await createClient().space(await resolveSpace(spaces)).profile({ fundingEnabled: state === "on" });
|
|
46
|
+
ok(`Public funding ${state}`);
|
|
23
47
|
}
|
|
24
48
|
catch (cause) {
|
|
25
49
|
handleHttp(cause);
|
|
@@ -30,32 +54,85 @@ export function registerSpaceWallet(spaces) {
|
|
|
30
54
|
const page = Number(opts.page);
|
|
31
55
|
if (!Number.isInteger(page) || page < 1 || page > 10_000)
|
|
32
56
|
throw new Error("Page must be an integer between 1 and 10000");
|
|
33
|
-
const value = await
|
|
57
|
+
const value = await (await space()).activities(page);
|
|
34
58
|
if (jsonRequested(opts))
|
|
35
59
|
return outJson(value);
|
|
36
|
-
table(value.items, [{ key: "
|
|
60
|
+
table(value.items, [{ key: "title", label: "Activity" }, { key: "amountUsd", label: "Amount (USD)" }, { key: "actorUserId", label: "User" }, { key: "createdAt", label: "Date" }]);
|
|
37
61
|
}
|
|
38
62
|
catch (cause) {
|
|
39
63
|
handleHttp(cause);
|
|
40
64
|
}
|
|
41
65
|
});
|
|
42
|
-
wallet.command("
|
|
66
|
+
wallet.command("transfer <amount>").description("Move purchased personal balance into the wallet (whole USD)").option("--request-id <uuid>", "Continue an earlier uncertain transfer").option("--json", "Output as JSON").action(async (amount, opts) => {
|
|
67
|
+
const id = opts.requestId ?? randomUUID();
|
|
68
|
+
let sent = false;
|
|
43
69
|
try {
|
|
44
|
-
const
|
|
70
|
+
const amountUsd = Number(amount);
|
|
71
|
+
if (!Number.isInteger(amountUsd) || amountUsd < 1)
|
|
72
|
+
throw new Error("Amount must be a whole number of USD");
|
|
73
|
+
const api = await space();
|
|
74
|
+
sent = true;
|
|
75
|
+
const value = await api.transfer({ id, amountUsd });
|
|
76
|
+
if (jsonRequested(opts))
|
|
77
|
+
return outJson(value);
|
|
78
|
+
if (value.state === "completed")
|
|
79
|
+
ok(`Added ${usd(value.creditedUsd)} to the Space wallet`);
|
|
80
|
+
else if (value.state === "refunded")
|
|
81
|
+
warn(`Returned ${usd(value.refundedUsd)} to your balance`);
|
|
82
|
+
else
|
|
83
|
+
console.log(`Processing. Check with: cohub spaces wallet transfer-status ${id}`);
|
|
84
|
+
}
|
|
85
|
+
catch (cause) {
|
|
86
|
+
if (sent && uncertain(cause))
|
|
87
|
+
retryHint(`cohub spaces wallet transfer ${amount}`, id);
|
|
88
|
+
handleHttp(cause);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
wallet.command("transfer-status <id>").option("--json", "Output as JSON").action(async (id, opts) => {
|
|
92
|
+
try {
|
|
93
|
+
const value = await (await space()).getTransfer(id);
|
|
94
|
+
if (jsonRequested(opts))
|
|
95
|
+
return outJson(value);
|
|
96
|
+
table([{ state: value.state, amount: usd(value.amountUsd), credited: usd(value.creditedUsd), refunded: usd(value.refundedUsd) }], [{ key: "state", label: "State" }, { key: "amount", label: "Amount" }, { key: "credited", label: "Credited" }, { key: "refunded", label: "Refunded" }]);
|
|
97
|
+
}
|
|
98
|
+
catch (cause) {
|
|
99
|
+
handleHttp(cause);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
wallet.command("recharge <product>").description("Open checkout for a funding tier").option("--request-id <uuid>", "Continue an earlier uncertain checkout").option("--json", "Output as JSON").action(async (productKey, opts) => {
|
|
103
|
+
const id = opts.requestId ?? randomUUID();
|
|
104
|
+
let sent = false;
|
|
105
|
+
try {
|
|
106
|
+
const api = await space();
|
|
107
|
+
sent = true;
|
|
108
|
+
const value = await api.createOrder({ id, productKey });
|
|
45
109
|
if (jsonRequested(opts))
|
|
46
110
|
return outJson(value);
|
|
47
111
|
if (!value.checkout.checkoutUsable || !value.checkout.checkoutUrl)
|
|
48
112
|
throw new Error(value.checkout.message ?? "Checkout is unavailable");
|
|
49
113
|
console.log(value.checkout.checkoutUrl);
|
|
50
|
-
console.log(`
|
|
114
|
+
console.log(`After paying: cohub spaces wallet confirm ${value.orderId}`);
|
|
51
115
|
}
|
|
52
116
|
catch (cause) {
|
|
117
|
+
if (sent && uncertain(cause))
|
|
118
|
+
retryHint(`cohub spaces wallet recharge ${productKey}`, id);
|
|
53
119
|
handleHttp(cause);
|
|
54
120
|
}
|
|
55
121
|
});
|
|
56
122
|
wallet.command("confirm <order>").action(async (orderId) => {
|
|
57
123
|
try {
|
|
58
|
-
outJson(await
|
|
124
|
+
outJson(await (await space()).confirmOrder(orderId));
|
|
125
|
+
}
|
|
126
|
+
catch (cause) {
|
|
127
|
+
handleHttp(cause);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
wallet.command("catalog").option("--json", "Output as JSON").action(async (opts) => {
|
|
131
|
+
try {
|
|
132
|
+
const value = await (await space()).catalog();
|
|
133
|
+
if (jsonRequested(opts))
|
|
134
|
+
return outJson(value);
|
|
135
|
+
table(value.products.map((product) => ({ key: product.key, name: product.name, price: product.pricing.amountUsd })), [{ key: "key", label: "Product" }, { key: "name", label: "Name" }, { key: "price", label: "Price (USD)" }]);
|
|
59
136
|
}
|
|
60
137
|
catch (cause) {
|
|
61
138
|
handleHttp(cause);
|
package/dist/commands/spaces.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { readdir, stat } from "node:fs/promises";
|
|
2
2
|
import { basename, dirname, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { APPROVAL_MODES, harnessSchema, isApprovalMode, isModelThinkingLevel, MODEL_THINKING_LEVELS, readSentTurns, readSessionTurnOrigin, resolveCohubEnvironment } from "@neta-art/cohub";
|
|
4
|
-
import { uploadAvatarAsset, uploadChatImageAsset } from "../avatar.js";
|
|
4
|
+
import { uploadAvatarAsset, uploadChatImageAsset, uploadLikeStickerAsset } from "../avatar.js";
|
|
5
5
|
import { createClient } from "../client.js";
|
|
6
6
|
import { collectOption, readPromptContent } from "../command-input.js";
|
|
7
7
|
import { table, json as outJson, jsonRequested, ok, error, handleHttp, formatEpochMs, truncateText } from "../output.js";
|
|
8
|
-
import { SESSION_STATUS_COLUMN } from "../session-status.js";
|
|
8
|
+
import { SESSION_STATUS_COLUMN, sessionArchiveFilter } from "../session-status.js";
|
|
9
9
|
import { resolveSpace } from "../space.js";
|
|
10
10
|
import { uploadLocalFiles } from "../space-files/upload.js";
|
|
11
11
|
import { registerDecisionCommand } from "./decision.js";
|
|
@@ -202,15 +202,12 @@ async function sendPrompt(command, words, opts) {
|
|
|
202
202
|
if (opts.note) {
|
|
203
203
|
const agentOnly = Object.entries({
|
|
204
204
|
"--delay-ms": opts.delayMs, "--at": opts.at, "--cron": opts.cron, "--model": opts.model, "--provider": opts.provider,
|
|
205
|
-
"--thinking-level": opts.thinkingLevel, "--approval-mode": opts.approvalMode, "--service-tier": opts.serviceTier,
|
|
205
|
+
"--thinking-level": opts.thinkingLevel, "--context-window": opts.contextWindow, "--approval-mode": opts.approvalMode, "--service-tier": opts.serviceTier,
|
|
206
206
|
"--read-only": opts.readOnly, "--steer": opts.steer, "--env": opts.env?.length,
|
|
207
207
|
}).flatMap(([flag, value]) => value ? [flag] : []);
|
|
208
208
|
if (agentOnly.length)
|
|
209
209
|
return error("Conflicting options", `--note cannot be combined with ${agentOnly.join(", ")}`);
|
|
210
210
|
}
|
|
211
|
-
if (opts.reply && (opts.note || scheduleFlags.length)) {
|
|
212
|
-
return error("Conflicting options", "--reply cannot be combined with --note or scheduling");
|
|
213
|
-
}
|
|
214
211
|
const requestedThinkingLevel = opts.thinkingLevel?.trim() || undefined;
|
|
215
212
|
const thinkingLevel = isModelThinkingLevel(requestedThinkingLevel) ? requestedThinkingLevel : undefined;
|
|
216
213
|
if (requestedThinkingLevel && !thinkingLevel) {
|
|
@@ -218,6 +215,7 @@ async function sendPrompt(command, words, opts) {
|
|
|
218
215
|
}
|
|
219
216
|
if (opts.approvalMode !== undefined && !isApprovalMode(opts.approvalMode))
|
|
220
217
|
return error("Invalid approval mode", `Use ${APPROVAL_MODES.join("|")}`);
|
|
218
|
+
const contextWindow = opts.contextWindow !== undefined ? parseInteger(opts.contextWindow, "context-window", { min: 1 }) : undefined;
|
|
221
219
|
const spaceId = await resolveSpace(command, { home: true });
|
|
222
220
|
const client = createClient();
|
|
223
221
|
try {
|
|
@@ -265,6 +263,7 @@ async function sendPrompt(command, words, opts) {
|
|
|
265
263
|
provider: opts.provider,
|
|
266
264
|
harness: opts.harness,
|
|
267
265
|
thinkingLevel,
|
|
266
|
+
...(contextWindow ? { contextWindow } : {}),
|
|
268
267
|
...(isApprovalMode(opts.approvalMode) ? { approvalMode: opts.approvalMode } : {}),
|
|
269
268
|
...(opts.serviceTier ? { serviceTier: opts.serviceTier } : {}),
|
|
270
269
|
accessMode: opts.readOnly ? "read_only" : "full_access",
|
|
@@ -272,14 +271,11 @@ async function sendPrompt(command, words, opts) {
|
|
|
272
271
|
env: parseEnvOptions(opts.env),
|
|
273
272
|
schedule,
|
|
274
273
|
labelRefs: opts.label?.length ? opts.label : undefined,
|
|
275
|
-
...(opts.reply ? { reply: "prompt" } : {}),
|
|
276
274
|
});
|
|
277
275
|
if (jsonRequested(opts))
|
|
278
276
|
return outJson(result);
|
|
279
|
-
if (result.mode === "immediate")
|
|
280
|
-
|
|
281
|
-
return ok(`${label} — sessionId: ${result.session.id}, turnId: ${result.turn.id}`);
|
|
282
|
-
}
|
|
277
|
+
if (result.mode === "immediate")
|
|
278
|
+
return ok(`${opts.note ? "Note recorded" : "Prompt sent"} — sessionId: ${result.session.id}, turnId: ${result.turn.id}`);
|
|
283
279
|
if (result.mode === "repeat")
|
|
284
280
|
return ok(`Prompt scheduled — cronJobId: ${result.cronJobId}, nextRunAt: ${result.nextRunAt}`);
|
|
285
281
|
return ok(`Prompt scheduled — taskRunId: ${result.taskRunId}, scheduledAt: ${result.scheduledAt}`);
|
|
@@ -377,6 +373,7 @@ export function registerPrompt(program) {
|
|
|
377
373
|
.option("-p, --provider <provider>", "Provider name")
|
|
378
374
|
.option("--harness <harness>", `Harness: ${harnessSchema.options.join(", ")}`, "cohub")
|
|
379
375
|
.option("--thinking-level <level>", `Thinking level: ${MODEL_THINKING_LEVELS.join("|")}`)
|
|
376
|
+
.option("--context-window <tokens>", "Context window for this session from this prompt on; capped at the platform value")
|
|
380
377
|
.option("--approval-mode <mode>", `Local Harness approval mode: ${APPROVAL_MODES.join("|")}`)
|
|
381
378
|
.option("--service-tier <tier>", "Local Harness service tier, e.g. priority for Codex Fast")
|
|
382
379
|
.option("--read-only", "Use read-only tools")
|
|
@@ -389,7 +386,6 @@ export function registerPrompt(program) {
|
|
|
389
386
|
.option("--env <key=value>", "Set an environment variable for this turn", collectOption, [])
|
|
390
387
|
.option("--image <path>", "Attach an image", collectOption, [])
|
|
391
388
|
.option("--note", "Record the message without an AI reply")
|
|
392
|
-
.option("--reply", "Send the final reply back to the calling Chat and run its Agent")
|
|
393
389
|
.option("--json", "Output as JSON")
|
|
394
390
|
.action((words, opts) => sendPrompt(program, words, opts));
|
|
395
391
|
program
|
|
@@ -611,7 +607,8 @@ export function registerSpaces(program) {
|
|
|
611
607
|
return outJson(space);
|
|
612
608
|
const usage = space.workspaceUsage;
|
|
613
609
|
const storage = usage ? `${usage.bytes === null ? "-" : formatBytes(usage.bytes)} (${usage.status})` : undefined;
|
|
614
|
-
|
|
610
|
+
const likeSticker = space.publicProfile?.likeSticker?.url;
|
|
611
|
+
table([{ ...space, storage, likeSticker }], [
|
|
615
612
|
{ key: "id", label: "ID" },
|
|
616
613
|
{ key: "name", label: "Name" },
|
|
617
614
|
{ key: "slug", label: "Slug" },
|
|
@@ -619,6 +616,7 @@ export function registerSpaces(program) {
|
|
|
619
616
|
{ key: "status", label: "Status" },
|
|
620
617
|
{ key: "createdAt", label: "Created" },
|
|
621
618
|
...(storage ? [{ key: "storage", label: "Storage" }] : []),
|
|
619
|
+
...(likeSticker ? [{ key: "likeSticker", label: "Like sticker" }] : []),
|
|
622
620
|
]);
|
|
623
621
|
}
|
|
624
622
|
catch (e) {
|
|
@@ -691,6 +689,28 @@ export function registerSpaces(program) {
|
|
|
691
689
|
handleHttp(e);
|
|
692
690
|
}
|
|
693
691
|
});
|
|
692
|
+
// ── spaces like-sticker ──
|
|
693
|
+
spacesCmd
|
|
694
|
+
.command("like-sticker [path]")
|
|
695
|
+
.description("Set the image that replaces the heart on the space's published Apps")
|
|
696
|
+
.option("--clear", "Restore the default heart")
|
|
697
|
+
.option("--json", "Output as JSON")
|
|
698
|
+
.action(async (path, opts) => {
|
|
699
|
+
if (Boolean(path) === Boolean(opts.clear))
|
|
700
|
+
return error("Pass an image path or --clear");
|
|
701
|
+
const spaceId = await resolveSpace(spacesCmd);
|
|
702
|
+
const client = createClient();
|
|
703
|
+
try {
|
|
704
|
+
const asset = path ? await uploadLikeStickerAsset({ client, spaceId, path }) : null;
|
|
705
|
+
const result = await client.space(spaceId).profile({ likeSticker: asset ? { url: asset.publicUrl } : null });
|
|
706
|
+
if (jsonRequested(opts))
|
|
707
|
+
return outJson({ ...result, ...(asset ? { asset } : {}) });
|
|
708
|
+
ok(asset ? "Like sticker updated" : "Like sticker cleared");
|
|
709
|
+
}
|
|
710
|
+
catch (e) {
|
|
711
|
+
handleHttp(e);
|
|
712
|
+
}
|
|
713
|
+
});
|
|
694
714
|
registerSpaceSetup(spacesCmd);
|
|
695
715
|
// ── spaces config ──
|
|
696
716
|
spacesCmd
|
|
@@ -754,6 +774,7 @@ export function registerSpaces(program) {
|
|
|
754
774
|
.option("-m, --model <model>", "Model name")
|
|
755
775
|
.option("-p, --provider <provider>", "Provider name")
|
|
756
776
|
.option("--thinking-level <level>", `Thinking level: ${MODEL_THINKING_LEVELS.join("|")}`)
|
|
777
|
+
.option("--context-window <tokens>", "Context window for this session from this prompt on; capped at the platform value")
|
|
757
778
|
.option("--approval-mode <mode>", `Local Harness approval mode: ${APPROVAL_MODES.join("|")}`)
|
|
758
779
|
.option("--service-tier <tier>", "Local Harness service tier, e.g. priority for Codex Fast")
|
|
759
780
|
.option("--read-only", "Use read-only tools")
|
|
@@ -766,7 +787,6 @@ export function registerSpaces(program) {
|
|
|
766
787
|
.option("--env <key=value>", "Set an environment variable for this turn", collectOption, [])
|
|
767
788
|
.option("--image <path>", "Attach an image", collectOption, [])
|
|
768
789
|
.option("--note", "Record the message without an AI reply")
|
|
769
|
-
.option("--reply", "Send the final reply back to the calling Chat and run its Agent")
|
|
770
790
|
.option("--json", "Output as JSON")
|
|
771
791
|
.action((words, opts) => sendPrompt(spacesCmd, words, opts));
|
|
772
792
|
// ── spaces completion ──
|
|
@@ -1399,13 +1419,15 @@ function registerSessions(spacesCmd) {
|
|
|
1399
1419
|
sessionsCmd
|
|
1400
1420
|
.command("ls")
|
|
1401
1421
|
.alias("list")
|
|
1402
|
-
.description("List sessions")
|
|
1422
|
+
.description("List sessions (archived sessions are hidden by default)")
|
|
1423
|
+
.option("--archived", "List only archived sessions")
|
|
1424
|
+
.option("--all", "Include archived sessions")
|
|
1403
1425
|
.option("--json", "Output as JSON")
|
|
1404
1426
|
.action(async (opts) => {
|
|
1405
1427
|
const spaceId = await resolveSpace(spacesCmd);
|
|
1406
1428
|
const client = createClient();
|
|
1407
1429
|
try {
|
|
1408
|
-
const result = await client.space(spaceId).sessions.list();
|
|
1430
|
+
const result = await client.space(spaceId).sessions.list({ archived: sessionArchiveFilter(opts) });
|
|
1409
1431
|
if (jsonRequested(opts))
|
|
1410
1432
|
return outJson(result);
|
|
1411
1433
|
if (result.sessions.length === 0) {
|
|
@@ -1556,6 +1578,35 @@ function registerSessions(spacesCmd) {
|
|
|
1556
1578
|
handleHttp(e);
|
|
1557
1579
|
}
|
|
1558
1580
|
});
|
|
1581
|
+
for (const archived of [true, false]) {
|
|
1582
|
+
const verb = archived ? "archive" : "unarchive";
|
|
1583
|
+
const done = archived ? "archived" : "restored";
|
|
1584
|
+
sessionsCmd
|
|
1585
|
+
.command(`${verb} <ids...>`)
|
|
1586
|
+
.description(archived
|
|
1587
|
+
? "Archive sessions for every member; a new message restores them"
|
|
1588
|
+
: "Restore archived sessions to the active list")
|
|
1589
|
+
.option("--json", "Output as JSON")
|
|
1590
|
+
.action(async (ids, opts) => {
|
|
1591
|
+
const spaceId = await resolveSpace(spacesCmd);
|
|
1592
|
+
const client = createClient();
|
|
1593
|
+
const sessions = [];
|
|
1594
|
+
for (const id of ids) {
|
|
1595
|
+
try {
|
|
1596
|
+
const session = client.space(spaceId).session(id.trim());
|
|
1597
|
+
sessions.push((await (archived ? session.archive() : session.unarchive())).session);
|
|
1598
|
+
}
|
|
1599
|
+
catch (e) {
|
|
1600
|
+
if (sessions.length > 0)
|
|
1601
|
+
process.stderr.write(`\n ${sessions.length} of ${ids.length} sessions ${done} before ${id}\n`);
|
|
1602
|
+
handleHttp(e);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
if (jsonRequested(opts))
|
|
1606
|
+
return outJson({ sessions });
|
|
1607
|
+
ok(ids.length === 1 ? `Session ${done}` : `${ids.length} sessions ${done}`);
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1559
1610
|
// ── sessions tail ──
|
|
1560
1611
|
sessionsCmd
|
|
1561
1612
|
.command("tail <id>")
|
package/dist/host/auth.js
CHANGED
|
@@ -3,6 +3,7 @@ import { basename, dirname } from "node:path";
|
|
|
3
3
|
import { HOST_SERVICE_SHELL_EVENTS, hostAuthChangedSchema, hostShellOpenSchema } from "@neta-art/cohub/host-bridge";
|
|
4
4
|
import { AuthRequiredError, authSessionPath, pollDeviceCode, readAuthSession, requestDeviceCode, resolveAccessToken, revokeAndClearAuthSession, } from "../auth.js";
|
|
5
5
|
import { clearHomeSpaceCache, jwtClaim } from "../space.js";
|
|
6
|
+
const REOPEN_AFTER_MS = 10_000;
|
|
6
7
|
function snapshot() {
|
|
7
8
|
const session = readAuthSession();
|
|
8
9
|
if (!session)
|
|
@@ -21,6 +22,8 @@ export class HostAuth {
|
|
|
21
22
|
#debounce;
|
|
22
23
|
#rewatch;
|
|
23
24
|
#pending = null;
|
|
25
|
+
#requesting = null;
|
|
26
|
+
#redirectPath;
|
|
24
27
|
constructor(emit, onAccountChanged) {
|
|
25
28
|
this.emit = emit;
|
|
26
29
|
this.onAccountChanged = onAccountChanged;
|
|
@@ -65,22 +68,31 @@ export class HostAuth {
|
|
|
65
68
|
return { authenticated: subject !== null, userUuid: null, subject, email: null };
|
|
66
69
|
}
|
|
67
70
|
async signIn(redirectPath) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
this.#redirectPath = hostAuthChangedSchema.shape.redirectPath.safeParse(redirectPath).data;
|
|
72
|
+
const pending = this.#pending;
|
|
73
|
+
if (pending && pending.expiresAt > Date.now()) {
|
|
74
|
+
if (Date.now() - pending.openedAt >= REOPEN_AFTER_MS)
|
|
75
|
+
this.#openPending(pending);
|
|
72
76
|
return true;
|
|
73
77
|
}
|
|
78
|
+
this.#requesting ??= this.#request().finally(() => { this.#requesting = null; });
|
|
79
|
+
await this.#requesting;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
async #request() {
|
|
74
83
|
const code = await requestDeviceCode();
|
|
75
|
-
const pending = { url: code.verificationUriComplete, expiresAt: code.expiresAt,
|
|
84
|
+
const pending = { url: code.verificationUriComplete, expiresAt: code.expiresAt, openedAt: 0 };
|
|
76
85
|
this.#pending = pending;
|
|
77
|
-
this.#
|
|
86
|
+
this.#openPending(pending);
|
|
78
87
|
void pollDeviceCode(code)
|
|
79
|
-
.then(() => this.#sync({ redirectPath:
|
|
88
|
+
.then(() => this.#sync({ redirectPath: this.#redirectPath, signedIn: true }))
|
|
80
89
|
.catch((error) => process.stderr.write(`Sign-in did not complete: ${error instanceof Error ? error.message : String(error)}\n`))
|
|
81
90
|
.finally(() => { if (this.#pending === pending)
|
|
82
91
|
this.#pending = null; });
|
|
83
|
-
|
|
92
|
+
}
|
|
93
|
+
#openPending(pending) {
|
|
94
|
+
pending.openedAt = Date.now();
|
|
95
|
+
this.#open(pending.url);
|
|
84
96
|
}
|
|
85
97
|
async signOut() {
|
|
86
98
|
await revokeAndClearAuthSession();
|
|
@@ -50,6 +50,7 @@ export class NativeRuntime {
|
|
|
50
50
|
if (link.sessionFile)
|
|
51
51
|
this.ingest.touch(link.sessionFile);
|
|
52
52
|
},
|
|
53
|
+
onDroppedLine: (nativeSessionId, bytes) => options.diagnostics.log("warn", "native.pi_line_dropped", { nativeSessionId, bytes }, { component: "native", harness: "pi" }),
|
|
53
54
|
});
|
|
54
55
|
this.codex = new CodexShared(options.executables.codex || "codex", options.root, Boolean(options.config?.codexShared) && options.harnesses.includes("codex"));
|
|
55
56
|
this.codex.onConnect((channel) => this.observeCodex(channel));
|
|
@@ -31,5 +31,6 @@ type Pi = {
|
|
|
31
31
|
};
|
|
32
32
|
/** Runtime directory shared with the CLI; one socket per bound directory, hashed to stay short. */
|
|
33
33
|
export declare function controlSocketPath(root: string): string;
|
|
34
|
+
export declare function forwardedEvent(name: string, event: unknown): Record<string, unknown>;
|
|
34
35
|
export default function cohub(pi: Pi): void;
|
|
35
36
|
export {};
|
|
@@ -43,8 +43,25 @@ function locateSocket(cwd) {
|
|
|
43
43
|
}
|
|
44
44
|
/** How often a missing or lost Runtime is looked for again. */
|
|
45
45
|
const RECONNECT_MS = 3_000;
|
|
46
|
-
|
|
47
|
-
const
|
|
46
|
+
const MESSAGE_FIELDS = ["message", "assistantMessageEvent"];
|
|
47
|
+
const TOOL_FIELDS = ["toolCallId", "toolName", "args", "result", "partialResult", "isError"];
|
|
48
|
+
/**
|
|
49
|
+
* Streamed events the daemon uses, with the fields it reads; everything else Pi emits stays local.
|
|
50
|
+
* An allowlist, since Pi adds fields across versions, some with the whole context (`turn_end`).
|
|
51
|
+
*/
|
|
52
|
+
const FORWARDED = {
|
|
53
|
+
agent_start: [], agent_end: ["willRetry"], agent_settled: [], turn_start: [], turn_end: ["message", "toolResults"],
|
|
54
|
+
message_start: MESSAGE_FIELDS, message_update: MESSAGE_FIELDS, message_end: MESSAGE_FIELDS,
|
|
55
|
+
tool_execution_start: TOOL_FIELDS, tool_execution_update: TOOL_FIELDS, tool_execution_end: TOOL_FIELDS,
|
|
56
|
+
};
|
|
57
|
+
export function forwardedEvent(name, event) {
|
|
58
|
+
const source = (event ?? {});
|
|
59
|
+
const forwarded = { type: name };
|
|
60
|
+
for (const field of FORWARDED[name] ?? [])
|
|
61
|
+
if (field in source)
|
|
62
|
+
forwarded[field] = source[field];
|
|
63
|
+
return forwarded;
|
|
64
|
+
}
|
|
48
65
|
export default function cohub(pi) {
|
|
49
66
|
// Cohub may load this file explicitly into a Pi it starts; never attach twice.
|
|
50
67
|
const marker = Symbol.for("cohub.pi.control");
|
|
@@ -148,12 +165,12 @@ export default function cohub(pi) {
|
|
|
148
165
|
});
|
|
149
166
|
};
|
|
150
167
|
pi.on("session_start", (_event, ctx) => attach(ctx));
|
|
151
|
-
for (const name of FORWARDED) {
|
|
168
|
+
for (const name of Object.keys(FORWARDED)) {
|
|
152
169
|
pi.on(name, (event, ctx) => {
|
|
153
170
|
context = ctx;
|
|
154
171
|
if (!socket)
|
|
155
172
|
attach(ctx);
|
|
156
|
-
send({ type: "event", sessionId: ctx.sessionManager.getSessionId(), event:
|
|
173
|
+
send({ type: "event", sessionId: ctx.sessionManager.getSessionId(), event: forwardedEvent(name, event) });
|
|
157
174
|
});
|
|
158
175
|
}
|
|
159
176
|
// Pi replaces this instance on /new, /resume, /fork and /reload, and loads the next one only
|
|
@@ -33,6 +33,8 @@ export declare class PiLink {
|
|
|
33
33
|
onEvent?: (session: PiSessionLink, event: Record<string, unknown>) => void;
|
|
34
34
|
onConnect?: (session: PiSessionLink) => void;
|
|
35
35
|
onDisconnect?: (session: PiSessionLink) => void;
|
|
36
|
+
/** A line over the limit was skipped; the connection stays up. */
|
|
37
|
+
onDroppedLine?: (sessionId: string | null, bytes: number) => void;
|
|
36
38
|
});
|
|
37
39
|
get socketPath(): string;
|
|
38
40
|
subscribe(sessionId: string, listener: (event: Record<string, unknown>) => void): () => void;
|
|
@@ -149,9 +149,12 @@ export class PiLink {
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
accept(socket) {
|
|
152
|
-
|
|
152
|
+
/** The line being received; an oversized one is only counted, until its newline arrives. */
|
|
153
|
+
let parts = [];
|
|
154
|
+
let size = 0;
|
|
153
155
|
/** This connection's link; a newer connection for the same session replaces it in the map. */
|
|
154
156
|
let own = null;
|
|
157
|
+
const dropped = (bytes) => this.options.onDroppedLine?.(own?.sessionId ?? null, bytes);
|
|
155
158
|
socket.setNoDelay?.(true);
|
|
156
159
|
socket.on("error", () => socket.destroy());
|
|
157
160
|
socket.on("close", () => {
|
|
@@ -172,14 +175,25 @@ export class PiLink {
|
|
|
172
175
|
this.options.onDisconnect?.(link);
|
|
173
176
|
});
|
|
174
177
|
socket.on("data", (bytes) => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
for (let start = 0;;) {
|
|
179
|
+
const end = bytes.indexOf(0x0a, start);
|
|
180
|
+
const piece = bytes.subarray(start, end < 0 ? bytes.length : end);
|
|
181
|
+
size += piece.length;
|
|
182
|
+
if (size <= MAX_LINE_BYTES)
|
|
183
|
+
parts.push(piece);
|
|
184
|
+
else
|
|
185
|
+
parts = [];
|
|
186
|
+
if (end < 0)
|
|
187
|
+
return;
|
|
188
|
+
start = end + 1;
|
|
189
|
+
const length = size, kept = parts;
|
|
190
|
+
parts = [];
|
|
191
|
+
size = 0;
|
|
192
|
+
if (length > MAX_LINE_BYTES) {
|
|
193
|
+
dropped(length);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const line = Buffer.concat(kept, length).toString("utf8");
|
|
183
197
|
if (!line)
|
|
184
198
|
continue;
|
|
185
199
|
let message;
|
package/dist/session-status.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type { SessionRecord } from "@neta-art/cohub";
|
|
1
|
+
import type { SessionArchiveFilter, SessionRecord } from "@neta-art/cohub";
|
|
2
2
|
import type { Column } from "./output.js";
|
|
3
|
-
type SessionStatusFields = Pick<SessionRecord, "activeTurn" | "lastTurnIssue">;
|
|
3
|
+
type SessionStatusFields = Pick<SessionRecord, "activeTurn" | "lastTurnIssue" | "archivedAt">;
|
|
4
4
|
export declare function sessionStatusText(session: Partial<SessionStatusFields>): string;
|
|
5
5
|
export declare const SESSION_STATUS_COLUMN: Column;
|
|
6
|
+
export declare function sessionArchiveFilter(opts: {
|
|
7
|
+
archived?: boolean;
|
|
8
|
+
all?: boolean;
|
|
9
|
+
}): SessionArchiveFilter | undefined;
|
|
6
10
|
export {};
|
package/dist/session-status.js
CHANGED
|
@@ -2,6 +2,8 @@ export function sessionStatusText(session) {
|
|
|
2
2
|
const turn = session.activeTurn;
|
|
3
3
|
if (turn)
|
|
4
4
|
return turn.status === "abort_requested" ? "stopping" : turn.status;
|
|
5
|
+
if (session.archivedAt)
|
|
6
|
+
return "archived";
|
|
5
7
|
const issue = session.lastTurnIssue;
|
|
6
8
|
if (issue?.status === "failed")
|
|
7
9
|
return "failed";
|
|
@@ -14,3 +16,10 @@ export const SESSION_STATUS_COLUMN = {
|
|
|
14
16
|
label: "Status",
|
|
15
17
|
format: (_value, row) => sessionStatusText(row),
|
|
16
18
|
};
|
|
19
|
+
export function sessionArchiveFilter(opts) {
|
|
20
|
+
if (opts.archived && opts.all) {
|
|
21
|
+
process.stderr.write("\n ✗ Use either --archived or --all\n\n");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
return opts.archived ? "only" : opts.all ? "include" : undefined;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neta-art/cohub-cli",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.24.0",
|
|
4
4
|
"description": "CLI for Cohub — spaces, sessions, and agent collaboration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"NOTICE"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@neta-art/cohub": "13.
|
|
27
|
+
"@neta-art/cohub": "13.15.0",
|
|
28
28
|
"@neta-art/generation": "0.2.15",
|
|
29
29
|
"commander": "^15.0.0",
|
|
30
30
|
"sharp": "^0.35.4",
|