@hypersocial/decks-cli 0.9.16 → 0.9.18
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 +38 -0
- package/package.json +1 -1
- package/skills/hyperdecks/SKILL.md +2 -1
- package/src/avatar-import.mjs +271 -0
- package/src/commands.mjs +10 -2
- package/src/runtime.mjs +24 -1
package/README.md
CHANGED
|
@@ -111,8 +111,46 @@ deck new <slug> "<title>" --narrated [--dir <path>]
|
|
|
111
111
|
check <slug|deck-dir> [--forbid "<phrase>,<phrase>"] [--max-duration <s>] [--json]
|
|
112
112
|
play <slug|deck-dir> [--voice <v>] [--slug <slug>] [--port <n>] [--no-open] [--json]
|
|
113
113
|
release <slug|deck-dir> [--to "<name>" [--email <e>]]... [--qa] [--no-notify] [--title t] [--voice v]
|
|
114
|
+
|
|
115
|
+
avatar import <head.glb> --metadata <file.json> [--thumbnail <png>] [--pack <packId>] [--expect-account <ownerId>] [--json]
|
|
114
116
|
```
|
|
115
117
|
|
|
118
|
+
### Importing a private avatar head (for tools)
|
|
119
|
+
|
|
120
|
+
`avatar import` puts a baked, owner-private Minimoji head (bake v17–18,
|
|
121
|
+
`privateFormat: 1`) into the signed-in account, or into one of its own private
|
|
122
|
+
packs that has no grants. Tools such as Minimoji's character creator shell out
|
|
123
|
+
to it rather than reading Hyperdecks credentials.
|
|
124
|
+
|
|
125
|
+
- The metadata file may hold only `name`, `provenance` (both required),
|
|
126
|
+
`limitations`, `stockVoice` (`stock:<name>`), `sha256` and `packId`.
|
|
127
|
+
`sha256` is filled from the file when absent; `--pack` must agree with
|
|
128
|
+
`packId`.
|
|
129
|
+
- Every check runs before anything is uploaded: the GLB, thumbnail (a PNG up to
|
|
130
|
+
1 MiB, 2048 px a side) and metadata locally, then `--expect-account` (an
|
|
131
|
+
account id or email), avatars being switched on, and the pack. A refusal
|
|
132
|
+
exits 2; a failure during or after the upload exits 1.
|
|
133
|
+
- `--json` prints the stored values, read back after the upload, so re-importing
|
|
134
|
+
the same head and name reports `reused: true` with the stored voice:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{ "ok": true, "owner": { "id": "…", "email": "…" }, "avatarId": "…", "packId": null,
|
|
138
|
+
"sha256": "…", "bakeVersion": 17, "stockVoice": "stock:brian", "created": true,
|
|
139
|
+
"reused": false, "visibility": "private", "defaultChanged": false }
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
With a pack, the upload also asks the server to re-check that the pack is
|
|
143
|
+
private and ungranted (`requirePrivate`): a pack shared or published after the
|
|
144
|
+
CLI's own check is refused by the server (`pack_not_private` / `pack_has_grants`,
|
|
145
|
+
exit 1 rather than the CLI's own exit 2 for the same codes before upload, nothing
|
|
146
|
+
stored). A server that cannot run the check, or stores the head without
|
|
147
|
+
confirming it, is `private_not_enforced` (exit 1); in the second case the
|
|
148
|
+
output carries the stored `avatarId`, to remove if the pack is shared.
|
|
149
|
+
|
|
150
|
+
Errors print `{ "ok": false, "error": "…", "code": "account_mismatch" }`. The
|
|
151
|
+
output never holds a token or an avatar URL, and the default presenter is
|
|
152
|
+
never changed.
|
|
153
|
+
|
|
116
154
|
## Narrated decks
|
|
117
155
|
|
|
118
156
|
`deck new --narrated` scaffolds `decks/<slug>/` (`index.html` with eight slides for
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: hyperdecks
|
|
3
3
|
description: Use when asked to make, narrate, check or ship a deck ("make me a narrated deck", "turn this into a deck and send it"), or when working with Hypersocial Decks, Hyperdecks CLI, production deck analytics, recipient share links, deck activity, MCP deck tools, or real-world/customer-facing deck checks. Prefer production for real activity and analytics; use development only for local implementation/testing when explicitly requested.
|
|
4
4
|
metadata:
|
|
5
|
-
version: "0.9.
|
|
5
|
+
version: "0.9.18"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Hyperdecks
|
|
@@ -85,6 +85,7 @@ for an import, a code): hand it to them, word for word, and wait.
|
|
|
85
85
|
| Make one the default (the person named it) | `hyperdecks avatar default <name>` | `set_default_avatar` |
|
|
86
86
|
| Remove one (confirm first) | `hyperdecks avatar remove <name>` | `remove_avatar` |
|
|
87
87
|
| One deck's own presenter | `hyperdecks deck avatar <slug> <name\|none\|default>` | `set_deck_avatar` |
|
|
88
|
+
| A tool imports a baked private head (owner-only; see the CLI README) | `hyperdecks avatar import <head.glb> --metadata <file.json> [--pack <id>] [--expect-account <id>] --json` | — (CLI only) |
|
|
88
89
|
|
|
89
90
|
## Target Selection
|
|
90
91
|
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// hyperdecks avatar import <head.glb> --metadata <file.json> [--thumbnail <png>]
|
|
2
|
+
// [--pack <packId>] [--expect-account <ownerId|email>] [--json]
|
|
3
|
+
//
|
|
4
|
+
// Puts an owner-private baked Minimoji head into the signed-in account (or one
|
|
5
|
+
// of its private, ungranted packs) through the deployment's
|
|
6
|
+
// POST /avatars/private-bakes route (convex/lib/avatars/privateBakeHttp.ts),
|
|
7
|
+
// so another tool (Minimoji's character creator) shells out to this command
|
|
8
|
+
// instead of reading our credentials or importing our source.
|
|
9
|
+
//
|
|
10
|
+
// Everything that can be refused is refused before a byte is uploaded, and
|
|
11
|
+
// those refusals exit 2; a failure during or after the upload exits 1. The
|
|
12
|
+
// server stays authoritative: the checks here mirror its cheap ones
|
|
13
|
+
// (convex/lib/avatars/privateBake.ts) so a bad file fails fast and offline.
|
|
14
|
+
//
|
|
15
|
+
// --json prints exactly one object on stdout:
|
|
16
|
+
// { ok: true, owner: { id, email }, avatarId, packId, sha256, bakeVersion,
|
|
17
|
+
// stockVoice, created, reused, visibility: "private", defaultChanged: false }
|
|
18
|
+
// { ok: false, error, code[, avatarId] } (avatarId: stored, but not confirmed)
|
|
19
|
+
// With a pack, the upload carries requirePrivate: the server refuses a pack
|
|
20
|
+
// that became shared or public (pack_not_private / pack_has_grants, exit 1) and
|
|
21
|
+
// acknowledges the check. An old server that refuses the key (nothing stored)
|
|
22
|
+
// or a stored upload without the acknowledgment (the output carries its
|
|
23
|
+
// avatarId: remove it if the pack is shared) is private_not_enforced (exit 1).
|
|
24
|
+
// The values come from the stored avatar read back after the upload, so a
|
|
25
|
+
// re-import of the same head reports what is stored, not what was sent. No
|
|
26
|
+
// token, avatar URL or view token is ever printed.
|
|
27
|
+
import { createHash } from "node:crypto";
|
|
28
|
+
import { readFileSync, statSync } from "node:fs";
|
|
29
|
+
import { makeFunctionReference } from "convex/server";
|
|
30
|
+
import { client as defaultClient, routeAuth as defaultRouteAuth } from "./runtime.mjs";
|
|
31
|
+
|
|
32
|
+
export const MAX_BAKE_BYTES = 8 * 1024 * 1024;
|
|
33
|
+
export const MAX_THUMBNAIL_BYTES = 1024 * 1024;
|
|
34
|
+
const MIN_BAKE_VERSION = 17, MAX_BAKE_VERSION = 18;
|
|
35
|
+
const ALLOWED_EXTENSIONS = new Set(["KHR_materials_sheen", "KHR_materials_clearcoat", "KHR_materials_unlit", "KHR_materials_ior", "KHR_materials_specular", "KHR_materials_emissive_strength"]);
|
|
36
|
+
const METADATA_KEYS = ["name", "sha256", "provenance", "limitations", "stockVoice", "packId"];
|
|
37
|
+
const UPLOAD_TIMEOUT_MS = 120_000;
|
|
38
|
+
export const IMPORT_USAGE = "usage: avatar import <head.glb> --metadata <file.json> [--thumbnail <png>] [--pack <packId>] [--expect-account <ownerId>] [--json]";
|
|
39
|
+
|
|
40
|
+
const fn = {
|
|
41
|
+
whoami: makeFunctionReference("decks:whoami"),
|
|
42
|
+
listAvatars: makeFunctionReference("avatars:listAvatars"),
|
|
43
|
+
packGet: makeFunctionReference("avatarPacks:get"),
|
|
44
|
+
packGrants: makeFunctionReference("avatarPacks:grants"),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// A refusal (exit 2, nothing uploaded) or a failure (exit 1), with a stable
|
|
48
|
+
// code. A failure after the server may have stored the head carries its
|
|
49
|
+
// avatarId when known; re-running is safe, since the route dedups.
|
|
50
|
+
export class ImportError extends Error {
|
|
51
|
+
constructor(code, message, exitCode = 2, avatarId = undefined) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.code = code;
|
|
54
|
+
this.exitCode = exitCode;
|
|
55
|
+
if (avatarId) this.avatarId = avatarId;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const refuse = (code, message) => { throw new ImportError(code, message, 2); };
|
|
59
|
+
const failed = (code, message, avatarId) => { throw new ImportError(code, message, 1, avatarId); };
|
|
60
|
+
const RERUN = "the head may be stored; re-run the same command to confirm (a re-import reuses it)";
|
|
61
|
+
|
|
62
|
+
const option = (opts, key) => {
|
|
63
|
+
if (!Object.hasOwn(opts, key)) return undefined;
|
|
64
|
+
const value = opts[key];
|
|
65
|
+
if (typeof value !== "string" || !value.trim()) refuse("bad_usage", `--${key} requires a value`);
|
|
66
|
+
return value.trim();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function readLocal(path, label, max, code) {
|
|
70
|
+
let stat;
|
|
71
|
+
try { stat = statSync(path); } catch (e) { refuse("bad_usage", `${label} cannot be read: ${path} (${e?.code ?? "error"})`); }
|
|
72
|
+
if (!stat.isFile()) refuse("bad_usage", `${label} is not a file: ${path}`);
|
|
73
|
+
if (stat.size > max) refuse(code, `${label} is ${stat.size} bytes; the limit is ${max}`);
|
|
74
|
+
try { return readFileSync(path); } catch (e) { refuse("bad_usage", `${label} cannot be read: ${path} (${e?.code ?? "error"})`); }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The cheap half of validatePrivateBake: the container, the JSON's shape and
|
|
78
|
+
// the Mini rig header. Geometry budgets and accessor bounds stay server-side.
|
|
79
|
+
export function checkBake(buffer) {
|
|
80
|
+
const bad = (message) => refuse("invalid_glb", message);
|
|
81
|
+
if (buffer.byteLength > MAX_BAKE_BYTES) refuse("glb_too_large", `GLB is ${buffer.byteLength} bytes; the limit is 8 MiB`);
|
|
82
|
+
if (buffer.byteLength < 28) bad("GLB must be 28 bytes to 8 MiB");
|
|
83
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
84
|
+
if (view.getUint32(0, true) !== 0x46546c67 || view.getUint32(4, true) !== 2 || view.getUint32(8, true) !== buffer.byteLength) bad("invalid GLB header");
|
|
85
|
+
const jsonLength = view.getUint32(12, true), binHeader = 20 + jsonLength;
|
|
86
|
+
if (jsonLength > 1024 * 1024 || jsonLength % 4 || binHeader + 8 > buffer.byteLength || view.getUint32(16, true) !== 0x4e4f534a) bad("invalid GLB JSON chunk");
|
|
87
|
+
const binLength = view.getUint32(binHeader, true);
|
|
88
|
+
if (view.getUint32(binHeader + 4, true) !== 0x004e4942 || binLength % 4 || binHeader + 8 + binLength !== buffer.byteLength) bad("expected one embedded GLB binary chunk");
|
|
89
|
+
let doc;
|
|
90
|
+
try { doc = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(buffer.subarray(20, binHeader))); } catch { bad("GLB JSON chunk does not parse"); }
|
|
91
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc)) bad("GLB JSON must be an object");
|
|
92
|
+
const inspect = (x, depth = 0) => {
|
|
93
|
+
if (depth > 24) bad("GLB JSON is too deeply nested");
|
|
94
|
+
if (Array.isArray(x)) { for (const value of x) inspect(value, depth + 1); return; }
|
|
95
|
+
if (!x || typeof x !== "object") return;
|
|
96
|
+
for (const [key, value] of Object.entries(x)) {
|
|
97
|
+
if (["uri", "url", "__proto__", "constructor", "prototype"].includes(key)) bad("external resources and executable metadata are not allowed");
|
|
98
|
+
if (/texture$/i.test(key)) bad("textures are not supported in private head bakes");
|
|
99
|
+
if (key === "extensions" && value && typeof value === "object") for (const extension of Object.keys(value)) if (!ALLOWED_EXTENSIONS.has(extension)) bad(`unsupported GLB extension ${extension}`);
|
|
100
|
+
inspect(value, depth + 1);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
inspect(doc);
|
|
104
|
+
if (doc.asset?.version !== "2.0" || doc.images?.length || doc.textures?.length || doc.animations?.length || doc.skins?.length) bad("expected a texture-free static Mini head rig");
|
|
105
|
+
for (const extension of [...(doc.extensionsUsed ?? []), ...(doc.extensionsRequired ?? [])]) if (!ALLOWED_EXTENSIONS.has(extension)) bad(`unsupported GLB extension ${extension}`);
|
|
106
|
+
const nodes = Array.isArray(doc.nodes) ? doc.nodes : [];
|
|
107
|
+
const roots = nodes.filter((node) => node?.name === "minimoji"), heads = nodes.filter((node) => node?.name === "head");
|
|
108
|
+
if (roots.length !== 1 || heads.length !== 1) bad("expected unique minimoji and head nodes");
|
|
109
|
+
const meta = roots[0].extras?.minimoji;
|
|
110
|
+
if (!meta || typeof meta !== "object") bad("the minimoji node carries no rig metadata");
|
|
111
|
+
if (!Number.isInteger(meta.v) || meta.v < MIN_BAKE_VERSION || meta.v > MAX_BAKE_VERSION) bad(`unsupported Mini bake version ${meta.v} (expected ${MIN_BAKE_VERSION}-${MAX_BAKE_VERSION})`);
|
|
112
|
+
if (meta.privateFormat !== 1 || meta.character != null || meta.avatar != null) bad("not a private-format head (privateFormat must be 1, with no character or avatar)");
|
|
113
|
+
for (const key of ["u", "H", "W"]) if (typeof meta[key] !== "number" || !Number.isFinite(meta[key]) || meta[key] <= 0) bad(`invalid rig ${key}`);
|
|
114
|
+
return { bakeVersion: meta.v, sha256: createHash("sha256").update(buffer).digest("hex") };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// The server's validateThumbnail: a PNG up to 1 MiB and 2048 px per side.
|
|
118
|
+
export function checkThumbnail(buffer) {
|
|
119
|
+
const v = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
120
|
+
const signature = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
121
|
+
if (buffer.byteLength < 33 || buffer.byteLength > MAX_THUMBNAIL_BYTES || signature.some((value, i) => buffer[i] !== value) || v.getUint32(8) !== 13 || v.getUint32(12) !== 0x49484452 || !v.getUint32(16) || !v.getUint32(20) || v.getUint32(16) > 2048 || v.getUint32(20) > 2048) refuse("invalid_thumbnail", "thumbnail must be a PNG up to 1 MiB and 2048 pixels per side");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// The server's parseImportMetadata, plus what the CLI fills in: sha256 (from
|
|
125
|
+
// the file) and limitations (none) when absent, and --pack as the pack.
|
|
126
|
+
export function buildMetadata(raw, { sha256, pack }) {
|
|
127
|
+
const bad = (message) => refuse("invalid_metadata", message);
|
|
128
|
+
let m;
|
|
129
|
+
try { m = JSON.parse(raw); } catch { bad("metadata is not valid JSON"); }
|
|
130
|
+
if (!m || typeof m !== "object" || Array.isArray(m)) bad("metadata must be a JSON object");
|
|
131
|
+
const unknown = Object.keys(m).filter((key) => !METADATA_KEYS.includes(key));
|
|
132
|
+
if (unknown.length) bad(`unsupported metadata field ${unknown.join(", ")} (allowed: ${METADATA_KEYS.join(", ")}; owner, visibility and default are server-controlled)`);
|
|
133
|
+
if (typeof m.name !== "string" || !m.name.trim() || m.name.length > 80) bad("name is required (up to 80 characters)");
|
|
134
|
+
if (typeof m.provenance !== "string" || !m.provenance.trim() || m.provenance.length > 300) bad("provenance is required (up to 300 characters)");
|
|
135
|
+
if (m.limitations !== undefined && (!Array.isArray(m.limitations) || m.limitations.length > 20 || m.limitations.some((x) => typeof x !== "string" || x.length > 400))) bad("limitations must be up to 20 short strings");
|
|
136
|
+
if (m.stockVoice !== undefined && (typeof m.stockVoice !== "string" || !/^stock:[a-z0-9-]{1,40}$/.test(m.stockVoice))) bad("stockVoice must be a stock voice reference (stock:<name>)");
|
|
137
|
+
if (m.packId !== undefined && (typeof m.packId !== "string" || !/^[a-z0-9]{16,64}$/.test(m.packId))) bad("invalid packId");
|
|
138
|
+
if (m.sha256 !== undefined && (typeof m.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(m.sha256))) bad("sha256 must be 64 lowercase hex characters");
|
|
139
|
+
if (m.sha256 !== undefined && m.sha256 !== sha256) refuse("sha256_mismatch", `metadata sha256 ${m.sha256} does not match the GLB (${sha256})`);
|
|
140
|
+
if (pack && m.packId !== undefined && m.packId !== pack) refuse("pack_conflict", `--pack ${pack} conflicts with metadata packId ${m.packId}`);
|
|
141
|
+
const packId = pack ?? m.packId;
|
|
142
|
+
if (packId !== undefined && !/^[a-z0-9]{16,64}$/.test(packId)) refuse("bad_usage", "invalid --pack id");
|
|
143
|
+
// Into a pack, the server re-checks private + ungranted in the same write
|
|
144
|
+
// (requirePrivate), so a pack shared after checkPack below is still refused.
|
|
145
|
+
const out = { name: m.name, sha256, provenance: m.provenance, limitations: m.limitations ?? [], ...(m.stockVoice ? { stockVoice: m.stockVoice } : {}), ...(packId ? { packId, requirePrivate: true } : {}) };
|
|
146
|
+
if (JSON.stringify(out).length > 8192) bad("metadata is too large");
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// No credential at all is "not signed in"; a dropped connection or a 5xx is
|
|
151
|
+
// "server unreachable" (retry), never an account or pack verdict; a refused
|
|
152
|
+
// token exchange is "auth failed" (log in again).
|
|
153
|
+
const UNREACHABLE = /fetch failed|ECONN|ETIMEDOUT|ENOTFOUND|EAI_AGAIN|socket|network|did not respond|could not reach|timed? ?out|\b5\d\d\b/i;
|
|
154
|
+
const signInCode = (e) => {
|
|
155
|
+
const text = String(e?.message ?? e);
|
|
156
|
+
if (/not authenticated/i.test(text)) return "not_signed_in";
|
|
157
|
+
if (/HSDECKS_CONVEX_SITE_URL|needs --convex/.test(text)) return "bad_config";
|
|
158
|
+
return UNREACHABLE.test(text) ? "server_unreachable" : "auth_failed";
|
|
159
|
+
};
|
|
160
|
+
const unreachable = (e, what) => refuse("server_unreachable", `could not ${what}; nothing was uploaded (${errorText(e)})`);
|
|
161
|
+
const errorText = (e) => String(typeof e?.data === "string" ? e.data : e?.message ?? e).replace(/\s+/g, " ").slice(0, 300);
|
|
162
|
+
|
|
163
|
+
// An owner-only import never lands in a pack anyone else can see.
|
|
164
|
+
async function checkPack(c, packId) {
|
|
165
|
+
let pack;
|
|
166
|
+
try { pack = await c.query(fn.packGet, { packId }); } catch (e) { if (UNREACHABLE.test(String(e?.message ?? e))) unreachable(e, `check pack ${packId}`); refuse("pack_not_found", `pack ${packId} not found (${errorText(e)})`); }
|
|
167
|
+
if (!pack) refuse("pack_not_found", `pack ${packId} not found or unavailable to your account`);
|
|
168
|
+
if (pack.access !== "owner") refuse("pack_not_owned", `pack ${packId} belongs to another account`);
|
|
169
|
+
if (pack.visibility !== "private") refuse("pack_not_private", `pack ${packId} is ${pack.visibility}; an owner-only import goes only into a private pack`);
|
|
170
|
+
let grants;
|
|
171
|
+
try { grants = await c.query(fn.packGrants, { packId }); } catch (e) { refuse(UNREACHABLE.test(String(e?.message ?? e)) ? "server_unreachable" : "pack_check_failed", `could not read the grants of pack ${packId}; nothing was uploaded (${errorText(e)})`); }
|
|
172
|
+
if (!Array.isArray(grants) || grants.length) refuse("pack_has_grants", `pack ${packId} is shared with ${grants?.length ?? "some"} grant(s); an owner-only import goes only into an ungranted pack`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export async function avatarImport(file, opts = {}, { client = defaultClient, routeAuth = defaultRouteAuth, fetchImpl = fetch } = {}) {
|
|
176
|
+
if (!file || typeof file !== "string" || file.startsWith("--")) refuse("bad_usage", IMPORT_USAGE);
|
|
177
|
+
const metadataPath = option(opts, "metadata");
|
|
178
|
+
if (!metadataPath) refuse("bad_usage", `--metadata is required. ${IMPORT_USAGE}`);
|
|
179
|
+
const thumbnailPath = option(opts, "thumbnail"), pack = option(opts, "pack"), expect = option(opts, "expect-account");
|
|
180
|
+
|
|
181
|
+
// 1. Local checks: offline, before any sign-in.
|
|
182
|
+
const head = readLocal(file, "GLB", MAX_BAKE_BYTES, "glb_too_large");
|
|
183
|
+
const bake = checkBake(head);
|
|
184
|
+
let thumbnail = null;
|
|
185
|
+
if (thumbnailPath) { thumbnail = readLocal(thumbnailPath, "thumbnail", MAX_THUMBNAIL_BYTES, "invalid_thumbnail"); checkThumbnail(thumbnail); }
|
|
186
|
+
let rawMetadata;
|
|
187
|
+
try { rawMetadata = readFileSync(metadataPath, "utf8"); } catch { refuse("bad_usage", `metadata file not found: ${metadataPath}`); }
|
|
188
|
+
if (rawMetadata.length > 64 * 1024) refuse("invalid_metadata", "metadata is too large");
|
|
189
|
+
const metadata = buildMetadata(rawMetadata, { sha256: bake.sha256, pack });
|
|
190
|
+
|
|
191
|
+
// 2. The account: who this would land under, and whether avatars are on.
|
|
192
|
+
let c, who;
|
|
193
|
+
try { c = await client(opts); who = await c.query(fn.whoami, {}); } catch (e) { refuse(signInCode(e), errorText(e)); }
|
|
194
|
+
if (!who?.subject) refuse("not_signed_in", "not signed in; run `hyperdecks login`");
|
|
195
|
+
const owner = { id: who.subject, email: who.email ?? null };
|
|
196
|
+
if (expect && expect !== owner.id && expect.toLowerCase() !== String(owner.email ?? "").toLowerCase()) refuse("account_mismatch", `signed in as ${owner.id}${owner.email ? ` (${owner.email})` : ""}, not ${expect}; nothing was uploaded`);
|
|
197
|
+
let before;
|
|
198
|
+
try { before = await c.query(fn.listAvatars, {}); } catch (e) { unreachable(e, "read your avatars"); }
|
|
199
|
+
if (before?.enabled === false) refuse("avatars_disabled", "avatars are not switched on for this account (AVATARS_ENABLED)");
|
|
200
|
+
|
|
201
|
+
// 3. The destination.
|
|
202
|
+
if (metadata.packId) await checkPack(c, metadata.packId);
|
|
203
|
+
|
|
204
|
+
// 4. The upload, with the CLI's own sign-in.
|
|
205
|
+
let auth;
|
|
206
|
+
try { auth = await routeAuth(opts); } catch (e) { refuse(signInCode(e), errorText(e)); }
|
|
207
|
+
const form = new FormData();
|
|
208
|
+
form.set("metadata", JSON.stringify(metadata));
|
|
209
|
+
form.set("head", new Blob([head], { type: "model/gltf-binary" }), "head.glb");
|
|
210
|
+
if (thumbnail) form.set("thumbnail", new Blob([thumbnail], { type: "image/png" }), "thumbnail.png");
|
|
211
|
+
let res;
|
|
212
|
+
try {
|
|
213
|
+
res = await fetchImpl(`${auth.siteUrl}/avatars/private-bakes`, { method: "POST", headers: { authorization: `Bearer ${auth.token}` }, body: form, signal: AbortSignal.timeout(UPLOAD_TIMEOUT_MS) });
|
|
214
|
+
} catch (e) {
|
|
215
|
+
// The body may have reached the server before the connection dropped.
|
|
216
|
+
failed("upload_uncertain", `${e?.name === "TimeoutError" ? `upload exceeded ${UPLOAD_TIMEOUT_MS / 1000}s` : `upload interrupted: ${errorText(e)}`}; ${RERUN}`);
|
|
217
|
+
}
|
|
218
|
+
let body = null;
|
|
219
|
+
try { body = await res.json(); } catch { /* reported below by status */ }
|
|
220
|
+
if (!res.ok) {
|
|
221
|
+
const message = typeof body?.error === "string" ? body.error.slice(0, 300) : `HTTP ${res.status}`;
|
|
222
|
+
if (res.status === 401) failed("auth_failed", `the server did not accept the sign-in: ${message}`);
|
|
223
|
+
if (res.status === 403) failed("avatars_disabled", message);
|
|
224
|
+
if (res.status >= 500) failed("server_error", `the server failed (HTTP ${res.status}); ${RERUN}`);
|
|
225
|
+
if (body?.code === "pack_not_private" || body?.code === "pack_has_grants") failed(body.code, `the server refused the pack: ${message.replace(/^pack_\w+:\s*/, "")}; nothing was stored`);
|
|
226
|
+
// A server older than requirePrivate refuses the key: fail closed, and say why.
|
|
227
|
+
if (metadata.requirePrivate && /unsupported metadata field/.test(message)) failed("private_not_enforced", `this server cannot enforce a private pack (${message}); nothing was stored`);
|
|
228
|
+
failed("upload_rejected", `the server refused the head: ${message}`);
|
|
229
|
+
}
|
|
230
|
+
if (typeof body?.id !== "string" || typeof body.created !== "boolean") failed("stored_unverified", `the server accepted the upload (HTTP ${res.status}) but its reply could not be read; ${RERUN}`);
|
|
231
|
+
if (metadata.requirePrivate && body.requirePrivate !== true) failed("private_not_enforced", `stored as ${body.id}, but the server did not confirm pack ${metadata.packId} was private and ungranted; check the pack and remove the avatar if it is shared`, body.id);
|
|
232
|
+
|
|
233
|
+
// 5. Read back what is stored: on a dedup, the stored digest and voice win.
|
|
234
|
+
let after;
|
|
235
|
+
try { after = await c.query(fn.listAvatars, {}); } catch (e) { failed("stored_unverified", `stored as ${body.id}, but reading it back failed (${errorText(e)}); ${RERUN}`, body.id); }
|
|
236
|
+
const row = after?.avatars?.find((a) => a.id === body.id);
|
|
237
|
+
const stored = row?.head?.bakedHead;
|
|
238
|
+
if (!row || !stored) failed("stored_unverified", `stored as ${body.id}, but it is missing from your avatars; ${RERUN}`, body.id);
|
|
239
|
+
return {
|
|
240
|
+
ok: true,
|
|
241
|
+
owner,
|
|
242
|
+
avatarId: body.id,
|
|
243
|
+
packId: row.packId ?? null,
|
|
244
|
+
sha256: stored.sha256,
|
|
245
|
+
bakeVersion: stored.bakeVersion ?? stored.version,
|
|
246
|
+
stockVoice: row.stockVoice ?? null,
|
|
247
|
+
created: body.created,
|
|
248
|
+
reused: !body.created,
|
|
249
|
+
visibility: "private",
|
|
250
|
+
defaultChanged: false,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// The command: prints the JSON (or a line for a person) and maps errors to the
|
|
255
|
+
// stable { ok:false, error, code } shape with exit 2 (refused) or 1 (failed).
|
|
256
|
+
export async function avatarImportCommand(pos = [], opts = {}, { log = console.log, deps } = {}) {
|
|
257
|
+
try {
|
|
258
|
+
if (pos.length > 1) refuse("bad_usage", IMPORT_USAGE);
|
|
259
|
+
const out = await avatarImport(pos[0], opts, deps);
|
|
260
|
+
if (opts.json) log(JSON.stringify(out, null, 2));
|
|
261
|
+
else log(`✓ ${out.reused ? "Already imported" : "Imported"} privately as ${out.avatarId}${out.packId ? ` in pack ${out.packId}` : ""} (bake v${out.bakeVersion}${out.stockVoice ? `, suggested voice ${out.stockVoice}` : ""}). Your default presenter is unchanged.`);
|
|
262
|
+
return out;
|
|
263
|
+
} catch (e) {
|
|
264
|
+
const error = e instanceof ImportError ? e : new ImportError("failed", errorText(e), 1);
|
|
265
|
+
if (opts.json) {
|
|
266
|
+
log(JSON.stringify({ ok: false, error: error.message, code: error.code, ...(error.avatarId ? { avatarId: error.avatarId } : {}) }, null, 2));
|
|
267
|
+
error.reported = true;
|
|
268
|
+
}
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}
|
package/src/commands.mjs
CHANGED
|
@@ -632,6 +632,11 @@ commands:
|
|
|
632
632
|
avatar pack [list|create|get|add|grant|grants|revoke|publish|unpublish|invitations|claim|catalog]
|
|
633
633
|
owner-managed packs; create <name> --private-only permanently prevents publication
|
|
634
634
|
avatar team [list|create|members|add|remove] owner-managed account groups for pack grants
|
|
635
|
+
avatar import <head.glb> --metadata <file.json> [--thumbnail <png>] [--pack <packId>] [--expect-account <ownerId>] [--json]
|
|
636
|
+
upload a baked private Minimoji head to your account (or one of your private, ungranted
|
|
637
|
+
packs); checked locally and against the account first (refusals exit 2, nothing uploaded).
|
|
638
|
+
--json: { ok, owner, avatarId, packId, sha256, bakeVersion, stockVoice, created, reused,
|
|
639
|
+
visibility, defaultChanged } as stored; errors { ok:false, error, code }
|
|
635
640
|
avatar [--json] your avatars (who presents decks in your voice) and the default
|
|
636
641
|
avatar new [--species <s>] pick a species, then an avatar (s shuffles); --json or an agent gets a pick link
|
|
637
642
|
avatar from-photo [file] [--save-to-minimoji]
|
|
@@ -1065,6 +1070,7 @@ function commandTable(pos, rest, opts) {
|
|
|
1065
1070
|
},
|
|
1066
1071
|
"avatar pack": async () => (await import("./avatar-packs.mjs")).avatarPacksCommand(rest, opts),
|
|
1067
1072
|
"avatar team": async () => (await import("./avatar-packs.mjs")).avatarTeamsCommand(rest, opts),
|
|
1073
|
+
"avatar import": async () => (await import("./avatar-import.mjs")).avatarImportCommand(rest, opts),
|
|
1068
1074
|
"avatar new": async () => {
|
|
1069
1075
|
const { avatarNew } = await import("./avatar.mjs");
|
|
1070
1076
|
const { askLine } = await import("./init.mjs");
|
|
@@ -1274,8 +1280,10 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
1274
1280
|
await handler();
|
|
1275
1281
|
return 0;
|
|
1276
1282
|
} catch (e) {
|
|
1277
|
-
|
|
1278
|
-
|
|
1283
|
+
// A command that already printed its own error (avatar import --json)
|
|
1284
|
+
// says so, and may name its exit code (2: refused before any change).
|
|
1285
|
+
if (!e?.reported) console.error("Error:", ops.errorText(e));
|
|
1286
|
+
return Number.isInteger(e?.exitCode) && e.exitCode > 0 ? e.exitCode : 1;
|
|
1279
1287
|
}
|
|
1280
1288
|
}
|
|
1281
1289
|
|
package/src/runtime.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { ConvexHttpClient } from "convex/browser";
|
|
|
9
9
|
import { makeFunctionReference } from "convex/server";
|
|
10
10
|
import { recordSkillInstall } from "./skillFreshness.mjs";
|
|
11
11
|
|
|
12
|
-
export const VERSION = "0.9.
|
|
12
|
+
export const VERSION = "0.9.18";
|
|
13
13
|
|
|
14
14
|
// Sent on the CLI's calls to our routes and to Convex, so the server can see
|
|
15
15
|
// which CLI versions are still out there (not used to refuse anything).
|
|
@@ -428,6 +428,29 @@ export async function client(opts = {}) {
|
|
|
428
428
|
return c;
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
+
// For the deployment's own HTTP routes (<deployment>.convex.site): the CLI's
|
|
432
|
+
// broker JWT and the site origin, so a route is called with the same sign-in
|
|
433
|
+
// as every other command. The token is for an Authorization header only; never
|
|
434
|
+
// print it. On the dev target HSDECKS_CONVEX_SITE_URL overrides the origin (a
|
|
435
|
+
// self-hosted or local backend whose site is not the cloud URL's sibling); prod
|
|
436
|
+
// ignores it, so a leftover variable never sends a prod token elsewhere.
|
|
437
|
+
export function siteUrlFor(convexUrl, { dev = false } = {}) {
|
|
438
|
+
const override = dev ? process.env.HSDECKS_CONVEX_SITE_URL?.trim() : "";
|
|
439
|
+
if (override) return normalizeBase(override);
|
|
440
|
+
const url = new URL(convexUrl);
|
|
441
|
+
if (url.hostname.endsWith(".convex.cloud")) url.hostname = url.hostname.replace(/\.convex\.cloud$/, ".convex.site");
|
|
442
|
+
else if (["127.0.0.1", "localhost"].includes(url.hostname) && url.port) url.port = String(Number(url.port) + 1);
|
|
443
|
+
else throw new Error(`cannot tell the HTTP site of ${convexUrl}; set HSDECKS_CONVEX_SITE_URL`);
|
|
444
|
+
return normalizeBase(url.toString());
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export async function routeAuth(opts = {}) {
|
|
448
|
+
const t = target(opts);
|
|
449
|
+
const refreshToken = resolveRefreshToken(t, opts);
|
|
450
|
+
if (!refreshToken) throw new Error(`not authenticated for ${t.name} - run \`hyperdecks login${t.name === "dev" ? " --dev" : ""}\``);
|
|
451
|
+
return { siteUrl: siteUrlFor(t.convexUrl, { dev: t.name === "dev" }), token: await jwtFor(t.brokerBase, refreshToken) };
|
|
452
|
+
}
|
|
453
|
+
|
|
431
454
|
export function openBrowser(url) {
|
|
432
455
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
433
456
|
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|