@celljs/ta-extensions 0.0.0-stage → 4.6.1

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/web/index.js ADDED
@@ -0,0 +1,941 @@
1
+ // web-src/extensions-util.ts
2
+ var ExtensionsUtil;
3
+ ((ExtensionsUtil) => {
4
+ function group(packages) {
5
+ const byName = (a, b) => a.name.localeCompare(b.name);
6
+ return {
7
+ mine: packages.filter((pkg) => pkg.origin === "directory").sort(byName),
8
+ installed: packages.filter((pkg) => pkg.origin === "package").sort(byName)
9
+ };
10
+ }
11
+ ExtensionsUtil.group = group;
12
+ function isArchive(fileName) {
13
+ return /\.(tgz|tar\.gz)$/i.test(fileName);
14
+ }
15
+ ExtensionsUtil.isArchive = isArchive;
16
+ function toBase64(bytes) {
17
+ let binary = "";
18
+ for (let at = 0;at < bytes.length; at += 32768) {
19
+ binary += String.fromCharCode(...bytes.subarray(at, at + 32768));
20
+ }
21
+ return btoa(binary);
22
+ }
23
+ ExtensionsUtil.toBase64 = toBase64;
24
+ function fromBase64(data) {
25
+ const binary = atob(data);
26
+ const bytes = new Uint8Array(binary.length);
27
+ for (let i = 0;i < binary.length; i++) {
28
+ bytes[i] = binary.charCodeAt(i);
29
+ }
30
+ return bytes;
31
+ }
32
+ ExtensionsUtil.fromBase64 = fromBase64;
33
+ })(ExtensionsUtil ||= {});
34
+
35
+ // web-src/i18n.ts
36
+ var EN = {
37
+ title: "Extensions",
38
+ heroTitle: "Make an extension in a sentence",
39
+ heroText: "It works as soon as the reply ends, with no restart.",
40
+ placeholder: "Describe the extension, for example: a pomodoro timer beside the conversation",
41
+ makePrompt: "Make an extension: {text}",
42
+ changePrompt: "Change the extension {name} (in {root}): {text}",
43
+ changeTitle: "Change {name}",
44
+ changePlaceholder: "What should it do differently?",
45
+ mine: "Yours",
46
+ mineEmpty: "None yet: say what you want above.",
47
+ installed: "Installed",
48
+ import: "Import",
49
+ export: "Export",
50
+ change: "Change",
51
+ remove: "Remove",
52
+ copySource: "Copy the source",
53
+ copied: "Copied {source}",
54
+ removeTitle: "Remove {name}?",
55
+ removeDetail: "Its pages, cards and commands go with it.",
56
+ removed: "Removed {name}",
57
+ exported: "Exported {file}",
58
+ imported: "Imported {name}; it works now",
59
+ installedOk: "Installed {name}; it works now",
60
+ existsTitle: "{name} is there already. Replace it?",
61
+ existsDetail: "Its files give way to those of the file imported.",
62
+ replace: "Replace",
63
+ project: "This project",
64
+ turnOn: "Turn {name} on",
65
+ turnedOn: "{name} is on",
66
+ turnedOff: "{name} is off",
67
+ shareTitle: "Hand them on",
68
+ shareSteps: ["Export", "Send the .tgz", "They import it"],
69
+ shareMore: "npm and Git sources import too, or just tell Ta.",
70
+ importTitle: "Import an extension",
71
+ dropHere: "Drop a .tgz file here, or",
72
+ chooseFile: "choose a file",
73
+ orSource: "Or install it from npm or Git",
74
+ sourcePlaceholder: "npm:@scope/name or https://github.com/you/repo",
75
+ install: "Install",
76
+ working: "Working…",
77
+ trust: "An extension runs code on this computer: import only those of people you trust.",
78
+ dropToImport: "Drop to import",
79
+ notArchive: "Only a .tgz file of an extension imports.",
80
+ loading: "Loading…",
81
+ kinds: {
82
+ extensions: "Commands",
83
+ web: "On the page",
84
+ skills: "Skills",
85
+ prompts: "Prompts",
86
+ themes: "Themes"
87
+ },
88
+ examples: [
89
+ {
90
+ kind: "card",
91
+ label: "Card",
92
+ example: "Pomodoro",
93
+ text: "a pomodoro timer as a card beside the conversation: 25 minutes of work, 5 of rest, and a notice when each ends"
94
+ },
95
+ {
96
+ kind: "page",
97
+ label: "Page",
98
+ example: "Commits by day",
99
+ text: "a page that shows, by day, the commits and the lines changed of this repository over the last 30 days"
100
+ },
101
+ {
102
+ kind: "command",
103
+ label: "Command",
104
+ example: "/standup",
105
+ text: "a /standup command that sums up what I committed and changed today in this repository, as words for the stand-up"
106
+ },
107
+ { kind: "skill", label: "Skill", example: "Into English", text: 'a skill: when I say "in English", Ta puts its last reply into natural English' }
108
+ ]
109
+ };
110
+ var ZH = {
111
+ title: "扩展",
112
+ heroTitle: "用一句话做一个扩展",
113
+ heroText: "回答结束就生效,不用重启。",
114
+ placeholder: "描述你想要的扩展,例如:在对话旁放一个番茄钟",
115
+ makePrompt: "做一个扩展:{text}",
116
+ changePrompt: "修改扩展 {name}(在 {root}):{text}",
117
+ changeTitle: "修改 {name}",
118
+ changePlaceholder: "想让它有什么不同?",
119
+ mine: "我的扩展",
120
+ mineEmpty: "还没有,在上面说一句就行。",
121
+ installed: "安装的扩展",
122
+ import: "导入",
123
+ export: "导出",
124
+ change: "修改",
125
+ remove: "移除",
126
+ copySource: "复制来源",
127
+ copied: "已复制 {source}",
128
+ removeTitle: "移除扩展 {name}?",
129
+ removeDetail: "它的页面、卡片和命令也会一起移除。",
130
+ removed: "已移除 {name}",
131
+ exported: "已导出 {file}",
132
+ imported: "已导入 {name},已经生效",
133
+ installedOk: "已安装 {name},已经生效",
134
+ existsTitle: "已有扩展 {name},要替换吗?",
135
+ existsDetail: "现有的文件会换成导入的版本。",
136
+ replace: "替换",
137
+ project: "本项目",
138
+ turnOn: "启用 {name}",
139
+ turnedOn: "已启用 {name}",
140
+ turnedOff: "已停用 {name}",
141
+ shareTitle: "分享给别人",
142
+ shareSteps: ["导出", "发送 .tgz 文件", "对方导入"],
143
+ shareMore: "也支持 npm、Git 来源,或者直接对 Ta 说。",
144
+ importTitle: "导入扩展",
145
+ dropHere: "把 .tgz 文件拖到这里,或",
146
+ chooseFile: "选择文件",
147
+ orSource: "或者从 npm、Git 安装",
148
+ sourcePlaceholder: "npm:@scope/name 或 https://github.com/you/repo",
149
+ install: "安装",
150
+ working: "正在处理…",
151
+ trust: "扩展会在这台电脑上运行代码:只导入你信任的人给的扩展。",
152
+ dropToImport: "松开即可导入",
153
+ notArchive: "只能导入扩展的 .tgz 文件。",
154
+ loading: "正在加载…",
155
+ kinds: {
156
+ extensions: "命令",
157
+ web: "界面",
158
+ skills: "技能",
159
+ prompts: "提示模板",
160
+ themes: "主题"
161
+ },
162
+ examples: [
163
+ { kind: "card", label: "卡片", example: "番茄钟", text: "在对话旁放一个番茄钟卡片:专注 25 分钟、休息 5 分钟,每段结束时提醒我" },
164
+ { kind: "page", label: "页面", example: "提交统计", text: "加一个页面,按天显示这个仓库最近 30 天的提交数和改动行数" },
165
+ { kind: "command", label: "命令", example: "/standup", text: "加一个 /standup 命令:总结我今天在这个仓库里的提交和改动,写成站会发言" },
166
+ { kind: "skill", label: "技能", example: "翻成英文", text: "加一个技能,我说“翻成英文”时,把上一条回复翻成地道的英文" }
167
+ ]
168
+ };
169
+ var ExtensionWords;
170
+ ((ExtensionWords) => {
171
+ function of(language) {
172
+ return language === "zh-CN" ? ZH : EN;
173
+ }
174
+ ExtensionWords.of = of;
175
+ function fill(template, values) {
176
+ return template.replace(/\{(\w+)\}/g, (whole, key) => values[key] ?? whole);
177
+ }
178
+ ExtensionWords.fill = fill;
179
+ })(ExtensionWords ||= {});
180
+
181
+ // web-src/actions.ts
182
+ class PackagesStore {
183
+ pi;
184
+ current = {};
185
+ listeners = new Set;
186
+ constructor(pi) {
187
+ this.pi = pi;
188
+ }
189
+ get state() {
190
+ return this.current;
191
+ }
192
+ subscribe(listener) {
193
+ this.listeners.add(listener);
194
+ return () => this.listeners.delete(listener);
195
+ }
196
+ patch(id, change) {
197
+ this.current = { packages: this.current.packages?.map((pkg) => pkg.id === id ? { ...pkg, ...change } : pkg) };
198
+ this.publish();
199
+ }
200
+ async load() {
201
+ try {
202
+ this.current = { packages: await this.pi.packages.listPackages() };
203
+ } catch (error) {
204
+ this.current = { packages: this.current.packages ?? [] };
205
+ this.pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
206
+ }
207
+ this.publish();
208
+ }
209
+ publish() {
210
+ for (const listener of this.listeners) {
211
+ listener();
212
+ }
213
+ }
214
+ }
215
+
216
+ class ExtensionActions {
217
+ pi;
218
+ store;
219
+ constructor(pi, store) {
220
+ this.pi = pi;
221
+ this.store = store;
222
+ }
223
+ get words() {
224
+ return ExtensionWords.of(this.pi.ui.language);
225
+ }
226
+ make(text) {
227
+ return this.converse(ExtensionWords.fill(this.words.makePrompt, { text: text.trim() }));
228
+ }
229
+ async change(pkg) {
230
+ const words = this.words;
231
+ const text = await this.pi.ui.input(ExtensionWords.fill(words.changeTitle, { name: pkg.name }), words.changePlaceholder);
232
+ if (text?.trim()) {
233
+ await this.converse(ExtensionWords.fill(words.changePrompt, { name: pkg.name, root: pkg.root, text: text.trim() }));
234
+ }
235
+ }
236
+ async exportPackage(pkg) {
237
+ await this.guard(async () => {
238
+ const { fileName, data } = await this.pi.callHost("exportPackage", pkg.id);
239
+ const url = URL.createObjectURL(new Blob([ExtensionsUtil.fromBase64(data)], { type: "application/gzip" }));
240
+ const link = document.createElement("a");
241
+ link.href = url;
242
+ link.download = fileName;
243
+ document.body.appendChild(link);
244
+ link.click();
245
+ link.remove();
246
+ setTimeout(() => URL.revokeObjectURL(url), 1e4);
247
+ this.pi.ui.notify(ExtensionWords.fill(this.words.exported, { file: fileName }));
248
+ });
249
+ }
250
+ async remove(pkg) {
251
+ const words = this.words;
252
+ const confirmed = await this.pi.ui.confirm(ExtensionWords.fill(words.removeTitle, { name: pkg.name }), words.removeDetail, {
253
+ confirmLabel: words.remove,
254
+ danger: true
255
+ });
256
+ if (confirmed) {
257
+ await this.guard(async () => {
258
+ await this.pi.packages.removePackage(pkg.id);
259
+ await this.changed();
260
+ this.pi.ui.notify(ExtensionWords.fill(words.removed, { name: pkg.name }));
261
+ });
262
+ }
263
+ }
264
+ async setEnabled(pkg, enabled) {
265
+ this.store.patch(pkg.id, { enabled });
266
+ await this.guard(async () => {
267
+ await this.pi.packages.setPackageEnabled(pkg.id, enabled);
268
+ await this.changed();
269
+ this.pi.ui.notify(ExtensionWords.fill(enabled ? this.words.turnedOn : this.words.turnedOff, { name: pkg.name }));
270
+ });
271
+ }
272
+ async copySource(pkg) {
273
+ await this.guard(async () => {
274
+ await navigator.clipboard.writeText(pkg.source);
275
+ this.pi.ui.notify(ExtensionWords.fill(this.words.copied, { source: pkg.source }));
276
+ });
277
+ }
278
+ async importFile(file) {
279
+ const words = this.words;
280
+ if (!ExtensionsUtil.isArchive(file.name)) {
281
+ this.pi.ui.notify(words.notArchive, "warning");
282
+ return false;
283
+ }
284
+ return this.guard(async () => {
285
+ const data = ExtensionsUtil.toBase64(new Uint8Array(await file.arrayBuffer()));
286
+ let result = await this.pi.callHost("importPackage", data, false);
287
+ if (result.status === "exists") {
288
+ const replace = await this.pi.ui.confirm(ExtensionWords.fill(words.existsTitle, { name: result.name }), words.existsDetail, {
289
+ confirmLabel: words.replace,
290
+ danger: true
291
+ });
292
+ if (!replace) {
293
+ return false;
294
+ }
295
+ result = await this.pi.callHost("importPackage", data, true);
296
+ }
297
+ await this.changed();
298
+ this.pi.ui.notify(ExtensionWords.fill(words.imported, { name: result.name }));
299
+ return true;
300
+ });
301
+ }
302
+ async install(source) {
303
+ const trimmed = source.trim();
304
+ if (!trimmed) {
305
+ return false;
306
+ }
307
+ return this.guard(async () => {
308
+ await this.pi.packages.installPackage(trimmed, "user");
309
+ await this.changed();
310
+ this.pi.ui.notify(ExtensionWords.fill(this.words.installedOk, { name: trimmed }));
311
+ return true;
312
+ });
313
+ }
314
+ async changed() {
315
+ await this.pi.reloadExtensions();
316
+ await this.store.load();
317
+ }
318
+ async converse(text) {
319
+ await this.guard(async () => {
320
+ const { cwd } = await this.pi.server.getServerInfo();
321
+ const { sessionId } = await this.pi.server.openSession({ cwd });
322
+ await this.pi.switchSession(sessionId);
323
+ await this.pi.sendUserMessage(text);
324
+ });
325
+ }
326
+ async guard(action) {
327
+ try {
328
+ return await action();
329
+ } catch (error) {
330
+ this.pi.ui.notify(error instanceof Error ? error.message : String(error), "error");
331
+ await this.store.load();
332
+ return false;
333
+ }
334
+ }
335
+ }
336
+
337
+ // web-src/react.ts
338
+ var React;
339
+ function bind(react) {
340
+ React = react;
341
+ }
342
+
343
+ // web-src/import-dialog.tsx
344
+ function ImportDialog({ pi, actions, onClose }) {
345
+ const words = actions.words;
346
+ const { Dialog, icons } = pi.ui;
347
+ const Upload = icons.Upload ?? icons.Download;
348
+ const input = React.useRef(null);
349
+ const [over, setOver] = React.useState(false);
350
+ const [busy, setBusy] = React.useState(false);
351
+ const [source, setSource] = React.useState("");
352
+ const run = async (action) => {
353
+ setBusy(true);
354
+ try {
355
+ if (await action()) {
356
+ onClose();
357
+ }
358
+ } finally {
359
+ setBusy(false);
360
+ }
361
+ };
362
+ const take = (file) => file && void run(() => actions.importFile(file));
363
+ return /* @__PURE__ */ React.createElement(Dialog, {
364
+ title: words.importTitle,
365
+ onClose
366
+ }, /* @__PURE__ */ React.createElement("div", {
367
+ className: "tax-dialog"
368
+ }, /* @__PURE__ */ React.createElement("section", {
369
+ "aria-label": words.importTitle,
370
+ className: `tax-drop${over ? " tax-over" : ""}`,
371
+ onDragOver: (event) => {
372
+ event.preventDefault();
373
+ setOver(true);
374
+ },
375
+ onDragLeave: () => setOver(false),
376
+ onDrop: (event) => {
377
+ event.preventDefault();
378
+ setOver(false);
379
+ take(event.dataTransfer.files[0]);
380
+ }
381
+ }, Upload && /* @__PURE__ */ React.createElement(Upload, {
382
+ size: 22
383
+ }), /* @__PURE__ */ React.createElement("div", null, busy ? words.working : /* @__PURE__ */ React.createElement(React.Fragment, null, words.dropHere, " ", /* @__PURE__ */ React.createElement("button", {
384
+ type: "button",
385
+ className: "tax-link",
386
+ onClick: () => input.current?.click()
387
+ }, words.chooseFile))), /* @__PURE__ */ React.createElement("input", {
388
+ ref: input,
389
+ type: "file",
390
+ accept: ".tgz,.gz,application/gzip",
391
+ hidden: true,
392
+ onChange: (event) => {
393
+ take(event.target.files?.[0]);
394
+ event.target.value = "";
395
+ }
396
+ })), /* @__PURE__ */ React.createElement("div", {
397
+ className: "tax-or"
398
+ }, words.orSource), /* @__PURE__ */ React.createElement("form", {
399
+ className: "tax-source",
400
+ onSubmit: (event) => {
401
+ event.preventDefault();
402
+ run(() => actions.install(source));
403
+ }
404
+ }, /* @__PURE__ */ React.createElement("input", {
405
+ value: source,
406
+ placeholder: words.sourcePlaceholder,
407
+ spellCheck: false,
408
+ onChange: (event) => setSource(event.target.value)
409
+ }), /* @__PURE__ */ React.createElement("button", {
410
+ type: "submit",
411
+ className: "tax-button",
412
+ disabled: busy || !source.trim()
413
+ }, busy ? words.working : words.install)), /* @__PURE__ */ React.createElement("div", {
414
+ className: "tax-note"
415
+ }, words.trust)));
416
+ }
417
+
418
+ // web-src/pictures.tsx
419
+ var Frame = () => /* @__PURE__ */ React.createElement("rect", {
420
+ className: "tax-pic-frame",
421
+ x: "1",
422
+ y: "1",
423
+ width: "158",
424
+ height: "94",
425
+ rx: "9"
426
+ });
427
+ var Line = ({ x, y, w }) => /* @__PURE__ */ React.createElement("rect", {
428
+ className: "tax-pic-line",
429
+ x,
430
+ y,
431
+ width: w,
432
+ height: "5",
433
+ rx: "2.5"
434
+ });
435
+ function Card() {
436
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Frame, null), /* @__PURE__ */ React.createElement(Line, {
437
+ x: 12,
438
+ y: 16,
439
+ w: 58
440
+ }), /* @__PURE__ */ React.createElement(Line, {
441
+ x: 12,
442
+ y: 27,
443
+ w: 74
444
+ }), /* @__PURE__ */ React.createElement(Line, {
445
+ x: 12,
446
+ y: 38,
447
+ w: 46
448
+ }), /* @__PURE__ */ React.createElement("rect", {
449
+ className: "tax-pic-pane",
450
+ x: "100",
451
+ y: "1",
452
+ width: "59",
453
+ height: "94"
454
+ }), /* @__PURE__ */ React.createElement("rect", {
455
+ className: "tax-pic-accent",
456
+ x: "108",
457
+ y: "14",
458
+ width: "43",
459
+ height: "38",
460
+ rx: "6"
461
+ }), /* @__PURE__ */ React.createElement("circle", {
462
+ className: "tax-pic-mark",
463
+ cx: "129.5",
464
+ cy: "33",
465
+ r: "10"
466
+ }), /* @__PURE__ */ React.createElement("path", {
467
+ className: "tax-pic-hand",
468
+ d: "M129.5 27v6l4 3"
469
+ }), /* @__PURE__ */ React.createElement(Line, {
470
+ x: 108,
471
+ y: 62,
472
+ w: 34
473
+ }), /* @__PURE__ */ React.createElement("rect", {
474
+ className: "tax-pic-box",
475
+ x: "12",
476
+ y: "72",
477
+ width: "78",
478
+ height: "13",
479
+ rx: "6.5"
480
+ }));
481
+ }
482
+ function Page() {
483
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Frame, null), /* @__PURE__ */ React.createElement("rect", {
484
+ className: "tax-pic-pane",
485
+ x: "1",
486
+ y: "1",
487
+ width: "20",
488
+ height: "94"
489
+ }), /* @__PURE__ */ React.createElement("circle", {
490
+ className: "tax-pic-line",
491
+ cx: "11",
492
+ cy: "16",
493
+ r: "3.5"
494
+ }), /* @__PURE__ */ React.createElement("circle", {
495
+ className: "tax-pic-mark",
496
+ cx: "11",
497
+ cy: "30",
498
+ r: "3.5"
499
+ }), /* @__PURE__ */ React.createElement("circle", {
500
+ className: "tax-pic-line",
501
+ cx: "11",
502
+ cy: "44",
503
+ r: "3.5"
504
+ }), /* @__PURE__ */ React.createElement("rect", {
505
+ className: "tax-pic-accent",
506
+ x: "31",
507
+ y: "13",
508
+ width: "118",
509
+ height: "70",
510
+ rx: "6"
511
+ }), [18, 30, 24, 42, 34, 50].map((height, i) => /* @__PURE__ */ React.createElement("rect", {
512
+ key: height,
513
+ className: "tax-pic-mark",
514
+ x: 42 + i * 17,
515
+ y: 73 - height,
516
+ width: "9",
517
+ height,
518
+ rx: "2"
519
+ })));
520
+ }
521
+ function Command() {
522
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Frame, null), /* @__PURE__ */ React.createElement("rect", {
523
+ className: "tax-pic-line",
524
+ x: "70",
525
+ y: "12",
526
+ width: "76",
527
+ height: "14",
528
+ rx: "7"
529
+ }), /* @__PURE__ */ React.createElement(Line, {
530
+ x: 12,
531
+ y: 36,
532
+ w: 84
533
+ }), /* @__PURE__ */ React.createElement(Line, {
534
+ x: 12,
535
+ y: 47,
536
+ w: 60
537
+ }), /* @__PURE__ */ React.createElement("rect", {
538
+ className: "tax-pic-box",
539
+ x: "10",
540
+ y: "64",
541
+ width: "140",
542
+ height: "21",
543
+ rx: "10.5"
544
+ }), /* @__PURE__ */ React.createElement("rect", {
545
+ className: "tax-pic-accent",
546
+ x: "16",
547
+ y: "68.5",
548
+ width: "50",
549
+ height: "12",
550
+ rx: "6"
551
+ }), /* @__PURE__ */ React.createElement("text", {
552
+ className: "tax-pic-text",
553
+ x: "22",
554
+ y: "78"
555
+ }, "/standup"));
556
+ }
557
+ function Skill() {
558
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Frame, null), /* @__PURE__ */ React.createElement("rect", {
559
+ className: "tax-pic-line",
560
+ x: "74",
561
+ y: "12",
562
+ width: "72",
563
+ height: "14",
564
+ rx: "7"
565
+ }), /* @__PURE__ */ React.createElement("rect", {
566
+ className: "tax-pic-accent",
567
+ x: "12",
568
+ y: "34",
569
+ width: "96",
570
+ height: "30",
571
+ rx: "8"
572
+ }), /* @__PURE__ */ React.createElement("rect", {
573
+ className: "tax-pic-mark tax-pic-soft",
574
+ x: "20",
575
+ y: "42",
576
+ width: "58",
577
+ height: "5",
578
+ rx: "2.5"
579
+ }), /* @__PURE__ */ React.createElement("rect", {
580
+ className: "tax-pic-mark tax-pic-soft",
581
+ x: "20",
582
+ y: "51",
583
+ width: "40",
584
+ height: "5",
585
+ rx: "2.5"
586
+ }), /* @__PURE__ */ React.createElement("path", {
587
+ className: "tax-pic-mark",
588
+ d: "M126 34l3.2 8.3 8.3 3.2-8.3 3.2-3.2 8.3-3.2-8.3-8.3-3.2 8.3-3.2z"
589
+ }), /* @__PURE__ */ React.createElement("path", {
590
+ className: "tax-pic-mark tax-pic-soft",
591
+ d: "M141 60l1.6 4 4 1.6-4 1.6-1.6 4-1.6-4-4-1.6 4-1.6z"
592
+ }), /* @__PURE__ */ React.createElement("rect", {
593
+ className: "tax-pic-box",
594
+ x: "12",
595
+ y: "74",
596
+ width: "136",
597
+ height: "12",
598
+ rx: "6"
599
+ }));
600
+ }
601
+ var PICTURES = { card: Card, page: Page, command: Command, skill: Skill };
602
+ function KindPicture({ kind }) {
603
+ const Picture = PICTURES[kind];
604
+ return /* @__PURE__ */ React.createElement("svg", {
605
+ className: "tax-pic",
606
+ viewBox: "0 0 160 96",
607
+ "aria-hidden": "true"
608
+ }, /* @__PURE__ */ React.createElement(Picture, null));
609
+ }
610
+
611
+ // web-src/page.tsx
612
+ function icon(pi, name, fallback = "Square") {
613
+ return pi.ui.icons[name] ?? pi.ui.icons[fallback] ?? (() => null);
614
+ }
615
+ function ExtensionsPage({ context }) {
616
+ const { pi, store, actions, importing } = context;
617
+ const words = actions.words;
618
+ const { packages } = React.useSyncExternalStore((listener) => store.subscribe(listener), () => store.state);
619
+ const dialog = React.useSyncExternalStore((listener) => importing.subscribe(listener), () => importing.shown);
620
+ const [dragging, setDragging] = React.useState(false);
621
+ const [starting, setStarting] = React.useState(false);
622
+ React.useEffect(() => {
623
+ store.load();
624
+ }, [store]);
625
+ const groups = ExtensionsUtil.group(packages ?? []);
626
+ const Composer = pi.ui.Composer;
627
+ const Sparkles = icon(pi, "Sparkles");
628
+ const Upload = icon(pi, "Upload");
629
+ const make = async (text) => {
630
+ setStarting(true);
631
+ try {
632
+ await actions.make(text);
633
+ } finally {
634
+ setStarting(false);
635
+ }
636
+ };
637
+ const files = (event) => Array.from(event.dataTransfer.types).includes("Files");
638
+ return /* @__PURE__ */ React.createElement("section", {
639
+ "aria-label": words.title,
640
+ className: "tax-page",
641
+ onDragOver: (event) => {
642
+ if (files(event) && !dialog) {
643
+ event.preventDefault();
644
+ setDragging(true);
645
+ }
646
+ },
647
+ onDragLeave: (event) => {
648
+ if (event.currentTarget === event.target) {
649
+ setDragging(false);
650
+ }
651
+ },
652
+ onDrop: (event) => {
653
+ if (files(event) && !dialog) {
654
+ event.preventDefault();
655
+ setDragging(false);
656
+ const file = event.dataTransfer.files[0];
657
+ if (file) {
658
+ actions.importFile(file);
659
+ }
660
+ }
661
+ }
662
+ }, /* @__PURE__ */ React.createElement("div", {
663
+ className: "tax-body"
664
+ }, /* @__PURE__ */ React.createElement("section", {
665
+ className: "tax-hero"
666
+ }, /* @__PURE__ */ React.createElement("h1", null, /* @__PURE__ */ React.createElement(Sparkles, {
667
+ size: 20
668
+ }), " ", words.heroTitle), /* @__PURE__ */ React.createElement("p", null, words.heroText), /* @__PURE__ */ React.createElement(Composer, {
669
+ placeholder: words.placeholder,
670
+ onSend: make
671
+ }), /* @__PURE__ */ React.createElement("div", {
672
+ className: "tax-kinds"
673
+ }, words.examples.map((example) => /* @__PURE__ */ React.createElement("button", {
674
+ key: example.kind,
675
+ type: "button",
676
+ className: "tax-kind",
677
+ disabled: starting,
678
+ onClick: () => void make(example.text)
679
+ }, /* @__PURE__ */ React.createElement(KindPicture, {
680
+ kind: example.kind
681
+ }), /* @__PURE__ */ React.createElement("span", {
682
+ className: "tax-kind-label"
683
+ }, /* @__PURE__ */ React.createElement("strong", null, example.label), /* @__PURE__ */ React.createElement("span", null, example.example)))))), /* @__PURE__ */ React.createElement("section", {
684
+ className: "tax-section"
685
+ }, /* @__PURE__ */ React.createElement("div", {
686
+ className: "tax-section-head"
687
+ }, /* @__PURE__ */ React.createElement("h2", null, words.mine, groups.mine.length > 0 && /* @__PURE__ */ React.createElement("span", {
688
+ className: "tax-count"
689
+ }, groups.mine.length)), /* @__PURE__ */ React.createElement("button", {
690
+ type: "button",
691
+ className: "tax-button",
692
+ onClick: () => importing.open()
693
+ }, /* @__PURE__ */ React.createElement(Upload, {
694
+ size: 14
695
+ }), " ", words.import)), packages === undefined ? /* @__PURE__ */ React.createElement("div", {
696
+ className: "tax-empty"
697
+ }, words.loading) : groups.mine.length === 0 ? /* @__PURE__ */ React.createElement("div", {
698
+ className: "tax-empty"
699
+ }, words.mineEmpty) : /* @__PURE__ */ React.createElement("div", {
700
+ className: "tax-list"
701
+ }, groups.mine.map((pkg) => /* @__PURE__ */ React.createElement(PackageRow, {
702
+ key: pkg.id,
703
+ pi,
704
+ actions,
705
+ pkg
706
+ })))), groups.installed.length > 0 && /* @__PURE__ */ React.createElement("section", {
707
+ className: "tax-section"
708
+ }, /* @__PURE__ */ React.createElement("div", {
709
+ className: "tax-section-head"
710
+ }, /* @__PURE__ */ React.createElement("h2", null, words.installed, /* @__PURE__ */ React.createElement("span", {
711
+ className: "tax-count"
712
+ }, groups.installed.length))), /* @__PURE__ */ React.createElement("div", {
713
+ className: "tax-list"
714
+ }, groups.installed.map((pkg) => /* @__PURE__ */ React.createElement(PackageRow, {
715
+ key: pkg.id,
716
+ pi,
717
+ actions,
718
+ pkg
719
+ })))), /* @__PURE__ */ React.createElement("section", {
720
+ className: "tax-section"
721
+ }, /* @__PURE__ */ React.createElement("div", {
722
+ className: "tax-section-head"
723
+ }, /* @__PURE__ */ React.createElement("h2", null, words.shareTitle)), /* @__PURE__ */ React.createElement(ShareSteps, {
724
+ pi,
725
+ actions
726
+ }))), dragging && /* @__PURE__ */ React.createElement("div", {
727
+ className: "tax-drop-overlay"
728
+ }, words.dropToImport), dialog && /* @__PURE__ */ React.createElement(ImportDialog, {
729
+ pi,
730
+ actions,
731
+ onClose: () => importing.close()
732
+ }));
733
+ }
734
+ function ShareSteps({ pi, actions }) {
735
+ const words = actions.words;
736
+ const steps = [icon(pi, "Download"), icon(pi, "FileArchive", "File"), icon(pi, "Upload")];
737
+ const Arrow = icon(pi, "ArrowRight");
738
+ return /* @__PURE__ */ React.createElement("div", {
739
+ className: "tax-share"
740
+ }, /* @__PURE__ */ React.createElement("div", {
741
+ className: "tax-steps"
742
+ }, steps.map((Step, index) => /* @__PURE__ */ React.createElement(React.Fragment, {
743
+ key: words.shareSteps[index]
744
+ }, index > 0 && /* @__PURE__ */ React.createElement("span", {
745
+ className: "tax-step-arrow"
746
+ }, /* @__PURE__ */ React.createElement(Arrow, {
747
+ size: 16
748
+ })), /* @__PURE__ */ React.createElement("div", {
749
+ className: "tax-step"
750
+ }, /* @__PURE__ */ React.createElement("span", {
751
+ className: "tax-step-icon"
752
+ }, /* @__PURE__ */ React.createElement(Step, {
753
+ size: 20
754
+ })), /* @__PURE__ */ React.createElement("span", null, words.shareSteps[index]))))), /* @__PURE__ */ React.createElement("div", {
755
+ className: "tax-note"
756
+ }, words.shareMore));
757
+ }
758
+ function PackageRow({ pi, actions, pkg }) {
759
+ const words = actions.words;
760
+ const mine = pkg.origin === "directory";
761
+ const Icon = icon(pi, mine ? "Puzzle" : "PackageOpen");
762
+ const tags = [...pkg.resources.map((type) => words.kinds[type]), ...pkg.scope === "project" ? [words.project] : []];
763
+ const buttons = mine ? [
764
+ { key: "change", label: words.change, icon: "Pencil", run: () => actions.change(pkg) },
765
+ { key: "export", label: words.export, icon: "Download", run: () => actions.exportPackage(pkg) },
766
+ { key: "remove", label: words.remove, icon: "Trash2", danger: true, run: () => actions.remove(pkg) }
767
+ ] : [
768
+ { key: "copy", label: words.copySource, icon: "Copy", run: () => actions.copySource(pkg) },
769
+ { key: "remove", label: words.remove, icon: "Trash2", danger: true, run: () => actions.remove(pkg) }
770
+ ];
771
+ return /* @__PURE__ */ React.createElement("div", {
772
+ className: `tax-row${pkg.enabled ? "" : " tax-off"}`
773
+ }, /* @__PURE__ */ React.createElement("span", {
774
+ className: "tax-icon"
775
+ }, /* @__PURE__ */ React.createElement(Icon, {
776
+ size: 17
777
+ })), /* @__PURE__ */ React.createElement("div", {
778
+ className: "tax-main"
779
+ }, /* @__PURE__ */ React.createElement("div", {
780
+ className: "tax-name"
781
+ }, /* @__PURE__ */ React.createElement("span", null, pkg.name), pkg.version && /* @__PURE__ */ React.createElement("span", {
782
+ className: "tax-version"
783
+ }, pkg.version), tags.map((tag) => /* @__PURE__ */ React.createElement("span", {
784
+ key: tag,
785
+ className: "tax-tag"
786
+ }, tag))), (pkg.description || !mine) && /* @__PURE__ */ React.createElement("div", {
787
+ className: "tax-description"
788
+ }, pkg.description || pkg.source)), /* @__PURE__ */ React.createElement("div", {
789
+ className: "tax-actions"
790
+ }, buttons.map((button) => {
791
+ const ButtonIcon = icon(pi, button.icon);
792
+ return /* @__PURE__ */ React.createElement("button", {
793
+ key: button.key,
794
+ type: "button",
795
+ className: `tax-action${button.danger ? " tax-danger" : ""}`,
796
+ title: button.label,
797
+ "aria-label": button.label,
798
+ onClick: () => void button.run()
799
+ }, /* @__PURE__ */ React.createElement(ButtonIcon, {
800
+ size: 15
801
+ }));
802
+ })), /* @__PURE__ */ React.createElement("input", {
803
+ type: "checkbox",
804
+ role: "switch",
805
+ className: "tax-switch",
806
+ "aria-label": ExtensionWords.fill(words.turnOn, { name: pkg.name }),
807
+ "aria-checked": pkg.enabled,
808
+ checked: pkg.enabled,
809
+ onChange: (event) => void actions.setEnabled(pkg, event.target.checked)
810
+ }));
811
+ }
812
+
813
+ // web-src/style.ts
814
+ var STYLE = `
815
+ .tax-page { --tax-accent: var(--ta-green); position: relative; height: 100%; overflow: auto; color: var(--ta-text); font-size: 13.5px; }
816
+ .tax-body { display: flex; flex-direction: column; gap: 32px; max-width: 760px; margin: 0 auto; padding: 44px 24px 56px; box-sizing: border-box; }
817
+ .tax-hero { display: flex; flex-direction: column; gap: 10px; }
818
+ .tax-hero h1 { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
819
+ .tax-hero h1 svg { color: var(--tax-accent); }
820
+ .tax-hero > p { margin: 0 0 6px; color: var(--ta-muted); }
821
+ .tax-kinds { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 6px; }
822
+ @media (max-width: 640px) { .tax-kinds { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
823
+ .tax-kind { display: flex; flex-direction: column; gap: 8px; padding: 8px 8px 10px; border: 1px solid var(--ta-border-muted); border-radius: 12px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; transition: border-color 140ms, background 140ms, transform 140ms var(--ta-ease); }
824
+ .tax-kind:hover { border-color: color-mix(in srgb, var(--tax-accent) 55%, var(--ta-border)); background: var(--ta-hover); }
825
+ .tax-kind:hover .tax-pic-accent { fill: color-mix(in srgb, var(--tax-accent) 26%, transparent); }
826
+ .tax-kind:active { transform: scale(.98); }
827
+ .tax-kind:disabled { opacity: .55; cursor: default; }
828
+ .tax-kind-label { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; padding: 0 4px; min-width: 0; }
829
+ .tax-kind-label strong { font-size: 13px; font-weight: 600; }
830
+ .tax-kind-label span { overflow: hidden; color: var(--ta-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
831
+ .tax-pic { display: block; width: 100%; height: auto; border-radius: 8px; }
832
+ .tax-pic-frame { fill: var(--ta-raised); stroke: var(--ta-border-muted); stroke-width: 1; }
833
+ .tax-pic-pane { fill: var(--ta-hover); }
834
+ .tax-pic-line { fill: var(--ta-hover-strong); }
835
+ .tax-pic-box { fill: none; stroke: var(--ta-border); stroke-width: 1; }
836
+ .tax-pic-accent { fill: color-mix(in srgb, var(--tax-accent) 16%, transparent); stroke: color-mix(in srgb, var(--tax-accent) 70%, transparent); stroke-width: 1; transition: fill 140ms; }
837
+ .tax-pic-mark { fill: var(--tax-accent); }
838
+ .tax-pic-soft { opacity: .45; }
839
+ .tax-pic-hand { fill: none; stroke: var(--ta-raised); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
840
+ .tax-pic-text { fill: var(--tax-accent); font-family: var(--ta-mono); font-size: 8px; font-weight: 600; }
841
+ .tax-section { display: flex; flex-direction: column; gap: 8px; }
842
+ .tax-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; }
843
+ .tax-section-head h2 { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--ta-secondary); font-size: 12.5px; font-weight: 600; }
844
+ .tax-count { padding: 0 6px; border-radius: 8px; background: var(--ta-chip); color: var(--ta-muted); font-size: 11px; font-weight: 500; line-height: 16px; }
845
+ .tax-button { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 1px solid var(--ta-border-muted); border-radius: 8px; background: var(--ta-raised); color: var(--ta-text); font: inherit; font-size: 13px; cursor: pointer; transition: background 120ms, border-color 120ms; }
846
+ .tax-button:hover { background: var(--ta-hover); border-color: var(--ta-border); }
847
+ .tax-button:disabled { opacity: .55; cursor: default; }
848
+ .tax-list { border: 1px solid var(--ta-border-muted); border-radius: 12px; overflow: hidden; }
849
+ .tax-row { position: relative; display: flex; align-items: center; gap: 12px; padding: 11px 14px; }
850
+ .tax-row + .tax-row { border-top: 1px solid var(--ta-border-muted); }
851
+ .tax-row:hover { background: var(--ta-hover); }
852
+ .tax-row:hover .tax-icon, .tax-row:hover .tax-tag { background: var(--ta-hover-strong); }
853
+ .tax-icon { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex: none; border-radius: 9px; background: var(--ta-chip); color: var(--tax-accent); transition: color 160ms; }
854
+ .tax-main { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; transition: opacity 160ms; }
855
+ .tax-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; }
856
+ .tax-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
857
+ .tax-version { flex: none; color: var(--ta-muted); font-size: 12px; font-weight: 400; }
858
+ .tax-description { overflow: hidden; color: var(--ta-secondary); font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
859
+ .tax-tag { flex: none; padding: 0 6px; border-radius: 5px; background: var(--ta-chip); color: var(--ta-muted); font-size: 11px; font-weight: 400; line-height: 17px; }
860
+ .tax-off .tax-main { opacity: .5; }
861
+ .tax-off .tax-icon { color: var(--ta-muted); }
862
+ .tax-actions { display: flex; gap: 2px; flex: none; opacity: 0; transition: opacity 120ms; }
863
+ .tax-row:hover .tax-actions, .tax-row:focus-within .tax-actions { opacity: 1; }
864
+ @media (hover: none) { .tax-actions { opacity: 1; } }
865
+ .tax-action { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 7px; background: none; color: var(--ta-muted); cursor: pointer; }
866
+ .tax-action:hover { background: var(--ta-hover-strong); color: var(--ta-text); }
867
+ .tax-action.tax-danger:hover { color: var(--ta-red); }
868
+ .tax-switch { appearance: none; -webkit-appearance: none; position: relative; width: 36px; height: 20px; flex: none; margin: 0 0 0 4px; border-radius: 10px; background: var(--ta-hover-strong); cursor: pointer; transition: background 160ms; }
869
+ .tax-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform 180ms var(--ta-ease); }
870
+ .tax-switch:checked { background: var(--ta-green); }
871
+ .tax-switch:checked::after { transform: translateX(16px); }
872
+ .tax-switch:focus-visible { outline: 2px solid var(--ta-border-focus); outline-offset: 2px; }
873
+ .tax-empty { padding: 16px; border: 1px dashed var(--ta-border-muted); border-radius: 12px; color: var(--ta-muted); text-align: center; }
874
+ .tax-share { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px 16px 16px; border: 1px solid var(--ta-border-muted); border-radius: 12px; }
875
+ .tax-steps { display: flex; align-items: flex-start; justify-content: center; gap: 10px; width: 100%; }
876
+ .tax-step { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 120px; color: var(--ta-secondary); font-size: 12.5px; text-align: center; }
877
+ .tax-step-icon { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; background: color-mix(in srgb, var(--tax-accent) 12%, transparent); color: var(--tax-accent); }
878
+ .tax-step-arrow { display: inline-flex; align-items: center; height: 44px; color: var(--ta-muted); }
879
+ .tax-note { color: var(--ta-muted); font-size: 12.5px; }
880
+ .tax-note code { padding: 1px 5px; border-radius: 4px; background: var(--ta-code); font-family: var(--ta-mono); font-size: 12px; }
881
+ .tax-drop-overlay { position: absolute; inset: 12px; z-index: 5; display: flex; align-items: center; justify-content: center; border: 2px dashed var(--ta-border-focus); border-radius: 16px; background: color-mix(in srgb, var(--ta-main) 85%, transparent); color: var(--ta-text); font-size: 15px; font-weight: 600; pointer-events: none; }
882
+ .tax-dialog { display: flex; flex-direction: column; gap: 14px; min-width: min(440px, 80vw); }
883
+ .tax-drop { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 26px 16px; border: 1.5px dashed var(--ta-border); border-radius: 12px; color: var(--ta-secondary); text-align: center; transition: border-color 120ms, background 120ms; }
884
+ .tax-drop.tax-over { border-color: var(--ta-border-focus); background: var(--ta-hover); }
885
+ .tax-drop svg { color: var(--ta-muted); }
886
+ .tax-link { padding: 0; border: 0; background: none; color: var(--ta-link); font: inherit; cursor: pointer; }
887
+ .tax-link:hover { text-decoration: underline; }
888
+ .tax-or { display: flex; align-items: center; gap: 10px; color: var(--ta-muted); font-size: 12px; }
889
+ .tax-or::before, .tax-or::after { content: ''; flex: 1; height: 1px; background: var(--ta-border-muted); }
890
+ .tax-source { display: flex; gap: 8px; }
891
+ .tax-source input { flex: 1; min-width: 0; height: 34px; padding: 0 11px; border: 1px solid var(--ta-border-field); border-radius: 8px; background: var(--ta-input); color: var(--ta-text); font: inherit; font-size: 13px; outline: none; box-sizing: border-box; }
892
+ .tax-source input:focus { border-color: var(--ta-border-focus); }
893
+ .tax-source .tax-button { height: 34px; }
894
+ `;
895
+ function injectStyle() {
896
+ const style = document.createElement("style");
897
+ style.dataset.taPackage = "ta-extensions";
898
+ style.textContent = STYLE;
899
+ document.head.appendChild(style);
900
+ return () => style.remove();
901
+ }
902
+
903
+ // web-src/index.tsx
904
+ function activate(pi) {
905
+ bind(pi.React);
906
+ const removeStyle = injectStyle();
907
+ const store = new PackagesStore(pi);
908
+ const actions = new ExtensionActions(pi, store);
909
+ const listeners = new Set;
910
+ const importing = {
911
+ shown: false,
912
+ open: () => set(true),
913
+ close: () => set(false),
914
+ subscribe: (listener) => {
915
+ listeners.add(listener);
916
+ return () => listeners.delete(listener);
917
+ }
918
+ };
919
+ function set(shown) {
920
+ importing.shown = shown;
921
+ for (const listener of listeners) {
922
+ listener();
923
+ }
924
+ }
925
+ const context = { pi, store, actions, importing };
926
+ const Puzzle = pi.ui.icons.Puzzle ?? pi.ui.icons.Square;
927
+ pi.registerView("extensions", {
928
+ title: () => ExtensionWords.of(pi.ui.language).title,
929
+ icon: Puzzle,
930
+ render: () => /* @__PURE__ */ React.createElement(ExtensionsPage, {
931
+ context
932
+ }),
933
+ menu: () => [[{ key: "import", label: ExtensionWords.of(pi.ui.language).import, icon: pi.ui.icons.Upload, run: () => importing.open() }]],
934
+ order: 90
935
+ });
936
+ pi.on("agent_end", () => void store.load());
937
+ return removeStyle;
938
+ }
939
+ export {
940
+ activate as default
941
+ };