@hypersocial/decks-cli 0.9.18 → 0.9.20
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 +1 -1
- package/package.json +1 -1
- package/skills/hyperdecks/SKILL.md +7 -1
- package/skills/hyperdecks/chat.md +3 -1
- package/src/avatar-import.mjs +17 -1
- package/src/commands.mjs +71 -9
- package/src/ops.mjs +30 -2
- package/src/runtime.mjs +3 -2
- package/src/tags.mjs +57 -0
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ avatar import <head.glb> --metadata <file.json> [--thumbnail <png>] [--pack <pac
|
|
|
117
117
|
|
|
118
118
|
### Importing a private avatar head (for tools)
|
|
119
119
|
|
|
120
|
-
`avatar import` puts a baked, owner-private Minimoji head (bake v17–
|
|
120
|
+
`avatar import` puts a baked, owner-private Minimoji head (bake v17–19; mouth anchors from 19,
|
|
121
121
|
`privateFormat: 1`) into the signed-in account, or into one of its own private
|
|
122
122
|
packs that has no grants. Tools such as Minimoji's character creator shell out
|
|
123
123
|
to it rather than reading Hyperdecks credentials.
|
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.20"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Hyperdecks
|
|
@@ -1005,6 +1005,12 @@ rebuild's list on 2026-11-05 produced four.
|
|
|
1005
1005
|
live changes, state the action and target clearly before executing when user
|
|
1006
1006
|
intent is ambiguous.
|
|
1007
1007
|
- Avoid printing full share tokens unless the user needs the exact URL/token.
|
|
1008
|
+
- Tag the decks you make so the owner can find them: `hyperdecks deck tag <slug>
|
|
1009
|
+
add <tag...>` / `tag_deck { slug, add, remove }` (lowercase a-z 0-9 -, 1–32
|
|
1010
|
+
characters, spaces become -, at most 10 a deck; `remove` takes them off).
|
|
1011
|
+
`deck list --tag <tag>` / `list_decks { tag }` lists one tag's decks, and
|
|
1012
|
+
`deck new … --tag <tag,...>` tags at creation. Tags are the owner's own
|
|
1013
|
+
labels: recipients never see them.
|
|
1008
1014
|
- To retire a deck ("archive it", "put it away", a superseded draft), archive it:
|
|
1009
1015
|
`hyperdecks deck archive <slug>` / `archive_deck`. It is reversible
|
|
1010
1016
|
(`deck unarchive` / `unarchive_deck` puts back the status it had) and deletes
|
|
@@ -112,7 +112,9 @@ makes the hello deck; continue from step 5 below.
|
|
|
112
112
|
gates; owners can turn it off with `set_deck_view { slug, aiReadable: false }`.
|
|
113
113
|
`set_share_notify` to mute a link's "opened" alerts;
|
|
114
114
|
`set_recipient_archived` to tidy the activity feed; `credits` for the
|
|
115
|
-
balance. `
|
|
115
|
+
balance. `tag_deck { slug, add, remove }` labels a deck for its owner
|
|
116
|
+
(investors, fizz-fm…; recipients never see tags): tag the decks you make,
|
|
117
|
+
and `list_decks { tag }` lists one tag's decks. `archive_deck` sets a deck aside reversibly (its links pause and
|
|
116
118
|
exports are refused while archived; nothing is deleted; `unarchive_deck` brings it back as it was): use it when
|
|
117
119
|
someone wants a deck archived or out of the way. `remove_deck` permanently
|
|
118
120
|
deletes a deck and breaks every link to it: only when they ask to delete,
|
package/src/avatar-import.mjs
CHANGED
|
@@ -31,7 +31,11 @@ import { client as defaultClient, routeAuth as defaultRouteAuth } from "./runtim
|
|
|
31
31
|
|
|
32
32
|
export const MAX_BAKE_BYTES = 8 * 1024 * 1024;
|
|
33
33
|
export const MAX_THUMBNAIL_BYTES = 1024 * 1024;
|
|
34
|
-
|
|
34
|
+
// Mirrors convex/lib/avatars/privateBake.ts: bakes 17-19, and mouth anchors
|
|
35
|
+
// (checkMouthExtras there) only from bake 19.
|
|
36
|
+
export const MIN_BAKE_VERSION = 17, MAX_BAKE_VERSION = 19, MOUTH_ANCHOR_MIN_VERSION = 19;
|
|
37
|
+
const MOUTH_EXTRAS = new Set(["mouthAnchor", "mouthRigid", "mouthPivot"]);
|
|
38
|
+
const anchorNumbers = (x, length) => Array.isArray(x) && x.length === length && x.every((n) => typeof n === "number" && Number.isFinite(n) && Math.abs(n) <= 1000);
|
|
35
39
|
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
40
|
const METADATA_KEYS = ["name", "sha256", "provenance", "limitations", "stockVoice", "packId"];
|
|
37
41
|
const UPLOAD_TIMEOUT_MS = 120_000;
|
|
@@ -111,6 +115,18 @@ export function checkBake(buffer) {
|
|
|
111
115
|
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
116
|
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
117
|
for (const key of ["u", "H", "W"]) if (typeof meta[key] !== "number" || !Number.isFinite(meta[key]) || meta[key] <= 0) bad(`invalid rig ${key}`);
|
|
118
|
+
// A mouth piece attached to the mouth (a fang, a tusk) carries
|
|
119
|
+
// mouthAnchor: [anchorX, anchorY, deltaRoll], mouthRigid: true and its offset.
|
|
120
|
+
for (const node of nodes) {
|
|
121
|
+
const extras = node?.extras;
|
|
122
|
+
if (!extras || typeof extras !== "object" || Array.isArray(extras)) continue;
|
|
123
|
+
for (const key of Object.keys(extras)) if (/^mouth/i.test(key) && !MOUTH_EXTRAS.has(key)) bad(`unsupported mouth metadata ${key}`);
|
|
124
|
+
if (extras.mouthRigid !== undefined && typeof extras.mouthRigid !== "boolean") bad("invalid mouthRigid");
|
|
125
|
+
if (extras.mouthAnchor === undefined) continue;
|
|
126
|
+
if (meta.v < MOUTH_ANCHOR_MIN_VERSION) bad(`mouth anchors need bake ${MOUTH_ANCHOR_MIN_VERSION}`);
|
|
127
|
+
if (!anchorNumbers(extras.mouthAnchor, 3)) bad("invalid mouth anchor");
|
|
128
|
+
if (extras.mouthRigid !== true || !anchorNumbers(extras.offset, 2)) bad("an anchored mouth piece needs mouthRigid and an offset");
|
|
129
|
+
}
|
|
114
130
|
return { bakeVersion: meta.v, sha256: createHash("sha256").update(buffer).digest("hex") };
|
|
115
131
|
}
|
|
116
132
|
|
package/src/commands.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { fetchVersionInfo, updatePreflight } from "./update.mjs";
|
|
18
18
|
import { refreshSkillCopies } from "./skillFreshness.mjs";
|
|
19
19
|
import * as ops from "./ops.mjs";
|
|
20
|
+
import { MAX_TAGS, normalizeTags } from "./tags.mjs";
|
|
20
21
|
import { exportVideo } from "./export-video.mjs";
|
|
21
22
|
import { presenterLine } from "./presenter.mjs";
|
|
22
23
|
|
|
@@ -62,14 +63,44 @@ async function whoamiCmd(opts) {
|
|
|
62
63
|
console.log(cliLine);
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
// A flag that takes a value but was given none (`--tag` last, or followed by
|
|
67
|
+
// another flag) parses as undefined or as the next flag: refuse it, never
|
|
68
|
+
// read it as "no filter".
|
|
69
|
+
function tagFlag(opts, usage) {
|
|
70
|
+
if (!("tag" in opts)) return undefined;
|
|
71
|
+
const v = opts.tag;
|
|
72
|
+
// Repeated --tag values arrive comma-joined (runtime parse): check each one.
|
|
73
|
+
const parts = typeof v === "string" ? v.split(",") : [];
|
|
74
|
+
if (!parts.length || parts.some((p) => !p.trim() || p === "undefined" || p.startsWith("--"))) throw new Error(`--tag needs a tag name: ${usage}`);
|
|
75
|
+
return v;
|
|
76
|
+
}
|
|
77
|
+
|
|
65
78
|
async function deckList(opts) {
|
|
66
|
-
const
|
|
79
|
+
const tag = tagFlag(opts, "deck list --tag <tag>");
|
|
80
|
+
const rows = await ops.listDecks(opts, { tag });
|
|
67
81
|
if (opts.json) {
|
|
68
82
|
console.log(JSON.stringify(rows, null, 2));
|
|
69
83
|
return;
|
|
70
84
|
}
|
|
71
|
-
for (const d of rows) console.log(`${d.slug}\t${d.status}\t${d.title}`);
|
|
72
|
-
if (!rows.length) console.log("(no decks)");
|
|
85
|
+
for (const d of rows) console.log(`${d.slug}\t${d.status}\t${d.title}${d.tags.length ? `\t#${d.tags.join(" #")}` : ""}`);
|
|
86
|
+
if (!rows.length) console.log(tag ? `(no decks tagged ${tag})` : "(no decks)");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const TAG_USAGE = "usage: deck tag <slug> add|remove <tag...> [--json]";
|
|
90
|
+
|
|
91
|
+
// Add or remove the deck's tags; with neither, print them.
|
|
92
|
+
async function deckTag(pos, opts) {
|
|
93
|
+
const [slug, action, ...names] = pos;
|
|
94
|
+
if (!slug) throw new Error(TAG_USAGE);
|
|
95
|
+
if (action === undefined) {
|
|
96
|
+
const { tags } = await ops.deckTags(opts, slug);
|
|
97
|
+
if (opts.json) return void console.log(JSON.stringify({ slug, tags }, null, 2));
|
|
98
|
+
return void console.log(tags.length ? `${slug}: ${tags.join(", ")}` : `${slug} has no tags`);
|
|
99
|
+
}
|
|
100
|
+
if ((action !== "add" && action !== "remove") || !names.length) throw new Error(TAG_USAGE);
|
|
101
|
+
const out = await ops.tagDeck(opts, slug, action === "add" ? { add: names } : { remove: names });
|
|
102
|
+
if (opts.json) return void console.log(JSON.stringify(out, null, 2));
|
|
103
|
+
console.log(out.tags.length ? `OK tagged ${out.slug}: ${out.tags.join(", ")}` : `OK ${out.slug} has no tags now`);
|
|
73
104
|
}
|
|
74
105
|
|
|
75
106
|
async function deckStats(pos, opts) {
|
|
@@ -490,7 +521,12 @@ commands:
|
|
|
490
521
|
login [--token <pat>] [--broker <url>] [--dev]
|
|
491
522
|
logout [--dev]
|
|
492
523
|
whoami [--json] [--dev]
|
|
493
|
-
deck list|stats|open|link|archive|unarchive|rm|forward|view|transfer|transfers
|
|
524
|
+
deck list|tag|stats|open|link|archive|unarchive|rm|forward|view|transfer|transfers
|
|
525
|
+
deck list [--tag <tag>] [--json]
|
|
526
|
+
your decks; --tag shows only the ones carrying that tag.
|
|
527
|
+
deck tag <slug> [add|remove <tag...>] [--json]
|
|
528
|
+
label a deck for yourself (investors, fizz-fm…): lowercase a-z 0-9 -, 1–32 characters,
|
|
529
|
+
spaces become -, at most 10 a deck. Only you see them; never recipients. No action: print them.
|
|
494
530
|
deck archive <slug> | deck unarchive <slug> [--json]
|
|
495
531
|
set a deck aside, reversibly; nothing is deleted. While archived its share and preview links show
|
|
496
532
|
"no longer active" and exports are refused. unarchive puts back the status it had (live stays
|
|
@@ -515,7 +551,7 @@ commands:
|
|
|
515
551
|
how the deck opens in the player (default: as its HTML says, data-view or slides) and
|
|
516
552
|
whether viewers get the slides/scroll toggle (on by default). Every link, next load; no re-release.
|
|
517
553
|
--ai-readable: whether each link + /md serves the deck as markdown for AI assistants (on by default).
|
|
518
|
-
deck new <slug> "<title>" --narrated [--layouts hero,product,number,closer] [--presenter-style stage|bubble|glass|corner] [--no-brand] [--dir <path>]
|
|
554
|
+
deck new <slug> "<title>" --narrated [--layouts hero,product,number,closer] [--presenter-style stage|bubble|glass|corner] [--no-brand] [--dir <path>] [--tag <tag,...>]
|
|
519
555
|
scaffold decks/<slug>/: index.html (8 slides, or one per layout, player/v1), script.md, evidence.md,
|
|
520
556
|
in your saved brand's colours, fonts and logo (--no-brand: the template's look)
|
|
521
557
|
layouts: hero, cover-frame, cover-split, cover-band, cover-poster, cover-type, number, product, phones, quote,
|
|
@@ -968,15 +1004,40 @@ function commandTable(pos, rest, opts) {
|
|
|
968
1004
|
if (opts.json) console.log(JSON.stringify(out, null, 2));
|
|
969
1005
|
},
|
|
970
1006
|
"deck new": async () => {
|
|
1007
|
+
// --tag: checked before anything is made, applied once the deck is registered.
|
|
1008
|
+
const tagsWanted = "tag" in opts ? normalizeTags(tagFlag(opts, "deck new <slug> \"<title>\" --tag <tag>")) : [];
|
|
1009
|
+
if (tagsWanted.length > MAX_TAGS) throw new Error(`a deck holds at most ${MAX_TAGS} tags`);
|
|
1010
|
+
// A failed tag must not hide the deck that was made: report it beside the
|
|
1011
|
+
// result (tagError) and say how to retry, never as a failed deck new.
|
|
1012
|
+
const tagNew = async (slug) => {
|
|
1013
|
+
if (!tagsWanted.length) return {};
|
|
1014
|
+
try {
|
|
1015
|
+
return { tags: (await ops.tagDeck(opts, slug, { add: tagsWanted })).tags };
|
|
1016
|
+
} catch (e) {
|
|
1017
|
+
const tagError = ops.errorText(e);
|
|
1018
|
+
console.error(`⚠ created ${slug} but tagging failed (${tagError}); run: hyperdecks deck tag ${slug} add ${tagsWanted.join(" ")}`);
|
|
1019
|
+
return { tagError };
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
// After the result is printed: exit non-zero without printing the error twice.
|
|
1023
|
+
const tagFailed = (tagged) => {
|
|
1024
|
+
if (tagged.tagError) throw Object.assign(new Error(tagged.tagError), { reported: true });
|
|
1025
|
+
};
|
|
971
1026
|
if (opts.hosted) {
|
|
972
1027
|
const { hostedNewDeck } = await import("./source.mjs");
|
|
973
1028
|
if (!opts.narrated) throw new Error("the published CLI scaffolds narrated decks only: add --narrated");
|
|
974
|
-
const
|
|
975
|
-
|
|
1029
|
+
const created = await hostedNewDeck(opts, { slug: rest[0], title: rest[1], layouts: opts.layouts, presenterStyle: opts["presenter-style"], brand: !opts["no-brand"] });
|
|
1030
|
+
const tagged = await tagNew(created.slug);
|
|
1031
|
+
const out = { ...created, ...tagged };
|
|
1032
|
+
console.log(opts.json ? JSON.stringify(out, null, 2) : `✓ created hosted deck "${out.slug}" (rev ${out.rev})${tagged.tags ? `, tagged ${tagged.tags.join(", ")}` : ""}\n preview: ${out.previewUrl}\n edit locally: hyperdecks source pull ${out.slug}`);
|
|
1033
|
+
return tagFailed(tagged);
|
|
976
1034
|
}
|
|
977
1035
|
const { deckNew } = await import("./scaffold.mjs");
|
|
978
|
-
const
|
|
979
|
-
|
|
1036
|
+
const created = await deckNew(rest, opts, opts.json ? { log: (line) => console.error(line) } : {});
|
|
1037
|
+
const tagged = await tagNew(created.slug);
|
|
1038
|
+
if (tagged.tags && !opts.json) console.log(`✓ tagged ${created.slug}: ${tagged.tags.join(", ")}`);
|
|
1039
|
+
if (opts.json) console.log(JSON.stringify({ ...created, ...tagged }, null, 2));
|
|
1040
|
+
tagFailed(tagged);
|
|
980
1041
|
},
|
|
981
1042
|
check: async () => {
|
|
982
1043
|
const { check } = await import("./check.mjs");
|
|
@@ -1171,6 +1232,7 @@ function commandTable(pos, rest, opts) {
|
|
|
1171
1232
|
logout: () => logout(opts),
|
|
1172
1233
|
whoami: () => whoamiCmd(opts),
|
|
1173
1234
|
"deck list": () => deckList(opts),
|
|
1235
|
+
"deck tag": () => deckTag(rest, opts),
|
|
1174
1236
|
"deck stats": () => deckStats(rest, opts),
|
|
1175
1237
|
"deck open": () => deckOpen(rest, opts),
|
|
1176
1238
|
"deck link": () => deckLink(rest, opts),
|
package/src/ops.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { SPECIES } from "./species.mjs";
|
|
|
4
4
|
import { COLOR_KEYS, FONT_PAIRINGS, FONT_ROLES, findPairing, googleFontsUrl } from "./brand.mjs";
|
|
5
5
|
import { MAX_IMPORT_FILE_BYTES, draftArgs, extractFile } from "./brandImport.mjs";
|
|
6
6
|
import { api, backupLinkUrl, client, linkBase, target, uploadBytes as runtimeUploadBytes } from "./runtime.mjs";
|
|
7
|
+
import { normalizeTags, TAG_RULE } from "./tags.mjs";
|
|
7
8
|
import {
|
|
8
9
|
bytesFromText,
|
|
9
10
|
isTextAsset,
|
|
@@ -32,12 +33,19 @@ export function ownerLink(opts, slug) {
|
|
|
32
33
|
return { slug, ownerUrl: url, backupUrl: backupLinkUrl(url) };
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
// `tag`: only the decks carrying it (normalized the way tags are stored).
|
|
37
|
+
/** @param {any} [opts] @param {{ all?: boolean, tag?: string }} [filter] */
|
|
38
|
+
export async function listDecks(opts = {}, { all = false, tag } = {}) {
|
|
39
|
+
const wanted = tag == null ? [] : normalizeTags(tag);
|
|
40
|
+
if (tag != null && wanted.length !== 1) throw new Error(wanted.length ? "filter by one tag at a time" : `name a tag to filter by: ${TAG_RULE}`);
|
|
41
|
+
const want = wanted[0] ?? null;
|
|
36
42
|
const rows = await (await client(opts)).query(all ? api.decks.listAll : api.decks.listForViewer, {});
|
|
37
|
-
return rows.map((d) => ({
|
|
43
|
+
return rows.filter((d) => !want || (d.tags ?? []).includes(want)).map((d) => ({
|
|
38
44
|
slug: d.slug,
|
|
39
45
|
title: d.title,
|
|
40
46
|
status: d.status,
|
|
47
|
+
// The owner's own labels (deck tag / tag_deck), sorted.
|
|
48
|
+
tags: d.tags ?? [],
|
|
41
49
|
ownerEmail: d.ownerEmail ?? null,
|
|
42
50
|
hasHtml: !!(d.html || d.htmlStorageId || d.hasHtml),
|
|
43
51
|
// How it opens (null: as its HTML says) and whether viewers may switch.
|
|
@@ -712,6 +720,26 @@ export async function archiveDeck(opts, slug) {
|
|
|
712
720
|
return { slug, status: "archived" };
|
|
713
721
|
}
|
|
714
722
|
|
|
723
|
+
// Tag a deck you own: add and/or remove tags (normalized: lowercase a-z 0-9 -,
|
|
724
|
+
// 1–32 chars, spaces become -; at most 10 a deck). Returns its tags after.
|
|
725
|
+
// A deck's tags, for its owner (or an admin): decks.get answers no one else.
|
|
726
|
+
/** @param {any} opts @param {string} slug */
|
|
727
|
+
export async function deckTags(opts, slug) {
|
|
728
|
+
if (!slug) throw new Error("slug is required");
|
|
729
|
+
const deck = await (await client(opts)).query(api.decks.get, { slug });
|
|
730
|
+
if (!deck) throw new Error(`deck not found: ${slug} (deck list shows your decks)`);
|
|
731
|
+
return { slug, tags: deck.tags ?? [] };
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/** @param {any} opts @param {string} slug @param {{ add?: string[], remove?: string[] }} [change] */
|
|
735
|
+
export async function tagDeck(opts, slug, { add = [], remove = [] } = {}) {
|
|
736
|
+
if (!slug) throw new Error("slug is required");
|
|
737
|
+
const plus = normalizeTags(add);
|
|
738
|
+
const minus = normalizeTags(remove);
|
|
739
|
+
if (!plus.length && !minus.length) throw new Error("name at least one tag to add or remove");
|
|
740
|
+
return (await client(opts)).mutation(api.decks.setTags, { slug, add: plus, remove: minus });
|
|
741
|
+
}
|
|
742
|
+
|
|
715
743
|
// Unarchive: back to the status it had before archiving (draft if unknown).
|
|
716
744
|
export async function unarchiveDeck(opts, slug) {
|
|
717
745
|
if (!slug) throw new Error("slug is required");
|
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.20";
|
|
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).
|
|
@@ -128,6 +128,7 @@ export const api = {
|
|
|
128
128
|
remove: makeFunctionReference("decks:remove"),
|
|
129
129
|
removalPreview: makeFunctionReference("decks:removalPreview"),
|
|
130
130
|
setStatus: makeFunctionReference("decks:setStatus"),
|
|
131
|
+
setTags: makeFunctionReference("decks:setTags"),
|
|
131
132
|
unarchive: makeFunctionReference("decks:unarchive"),
|
|
132
133
|
setAllowForward: makeFunctionReference("decks:setAllowForward"),
|
|
133
134
|
setView: makeFunctionReference("decks:setView"),
|
|
@@ -238,7 +239,7 @@ export function parse(args) {
|
|
|
238
239
|
else {
|
|
239
240
|
const v = args[++i];
|
|
240
241
|
if (k === "to" || (k === "email" && opts.recipients)) addRecipient(opts, k, v);
|
|
241
|
-
if ((k === "agent" || k === "guest") && opts[k]) opts[k] = `${opts[k]},${v}`;
|
|
242
|
+
if ((k === "agent" || k === "guest" || k === "tag") && opts[k]) opts[k] = `${opts[k]},${v}`;
|
|
242
243
|
else opts[k] = v;
|
|
243
244
|
}
|
|
244
245
|
} else {
|
package/src/tags.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Deck tags: the owner's own labels for grouping decks (investors, fizz-fm…).
|
|
2
|
+
// One rule, shared by Convex (decks.setTags), the CLI, both MCP servers and the
|
|
3
|
+
// dashboard, so a tag typed anywhere comes out the same: lowercase a-z, 0-9 and
|
|
4
|
+
// "-", 1–32 characters, spaces (and underscores) become "-". A deck holds at
|
|
5
|
+
// most MAX_TAGS, stored deduped and sorted. Owner-only: tags never reach a
|
|
6
|
+
// viewer, a share page, /md or an export.
|
|
7
|
+
|
|
8
|
+
export const MAX_TAGS = 10;
|
|
9
|
+
export const MAX_TAG_LENGTH = 32;
|
|
10
|
+
export const TAG_RULE = `a tag is 1–${MAX_TAG_LENGTH} characters of a-z, 0-9 and "-"`;
|
|
11
|
+
|
|
12
|
+
// One tag in its stored form, or null when nothing usable is left
|
|
13
|
+
// (" Fizz FM " → "fizz-fm"; "!!!" → null). Too long is an error, not a cut:
|
|
14
|
+
// a silently shortened tag would not match what the caller typed.
|
|
15
|
+
/** @param {unknown} raw @returns {string | null} */
|
|
16
|
+
export function normalizeTag(raw) {
|
|
17
|
+
const tag = String(raw ?? "")
|
|
18
|
+
.trim()
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.replace(/[\s_]+/g, "-")
|
|
21
|
+
.replace(/[^a-z0-9-]/g, "")
|
|
22
|
+
.replace(/-+/g, "-")
|
|
23
|
+
.replace(/^-|-$/g, "");
|
|
24
|
+
if (!tag) return null;
|
|
25
|
+
if (tag.length > MAX_TAG_LENGTH) throw new Error(`tag "${tag.slice(0, 40)}…" is too long: ${TAG_RULE}`);
|
|
26
|
+
return tag;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Several tags (an array, or one comma-separated string) in stored form,
|
|
30
|
+
// deduped, in the order given. An entry with nothing usable is an error.
|
|
31
|
+
/** @param {unknown} list @returns {string[]} */
|
|
32
|
+
export function normalizeTags(list) {
|
|
33
|
+
const items = Array.isArray(list) ? list : String(list ?? "").split(",");
|
|
34
|
+
/** @type {Set<string>} */
|
|
35
|
+
const out = new Set();
|
|
36
|
+
for (const raw of items) {
|
|
37
|
+
for (const part of String(raw ?? "").split(",")) {
|
|
38
|
+
if (!part.trim()) continue;
|
|
39
|
+
const tag = normalizeTag(part);
|
|
40
|
+
if (!tag) throw new Error(`"${part.trim().slice(0, 40)}" is not a tag: ${TAG_RULE}`);
|
|
41
|
+
out.add(tag);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [...out];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// A deck's tags after adding and removing (remove wins over add for the same
|
|
48
|
+
// tag), deduped and sorted. Throws past MAX_TAGS, naming what is there.
|
|
49
|
+
/** @param {readonly string[] | undefined} current @param {{ add?: readonly string[], remove?: readonly string[] }} [change] @returns {string[]} */
|
|
50
|
+
export function applyTags(current, { add = [], remove = [] } = {}) {
|
|
51
|
+
const drop = new Set(normalizeTags(remove));
|
|
52
|
+
const next = [...new Set([...(current ?? []), ...normalizeTags(add)])].filter((t) => !drop.has(t)).sort();
|
|
53
|
+
if (next.length > MAX_TAGS) {
|
|
54
|
+
throw new Error(`a deck holds at most ${MAX_TAGS} tags (this would make ${next.length}: ${next.join(", ")}); remove some first`);
|
|
55
|
+
}
|
|
56
|
+
return next;
|
|
57
|
+
}
|