crewx 0.8.6-rc.1 → 0.8.6-rc.11

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.
Files changed (118) hide show
  1. package/bin/crewx-lib.js +0 -69
  2. package/bin/crewx.js +68 -44
  3. package/dist/assets/{MarketPage-CoCR1dCg.js → MarketPage-nPJp6K-p.js} +7 -7
  4. package/dist/assets/PromptTab-C0-Nvu_h.js +37 -0
  5. package/dist/assets/arc-BWUu3D_k.js +1 -0
  6. package/dist/assets/architectureDiagram-UYN6MBPD-BhhiZvnJ.js +36 -0
  7. package/dist/assets/blockDiagram-ZHA2E4KO-Hec1jZe4.js +121 -0
  8. package/dist/assets/c4Diagram-6F5ED5ID-Bn_AnYuD.js +10 -0
  9. package/dist/assets/channel-C-oAJs_9.js +1 -0
  10. package/dist/assets/chunk-5HRBRIJM-DCzupWnG.js +1 -0
  11. package/dist/assets/chunk-7U56Z5CX-DzstA0UB.js +220 -0
  12. package/dist/assets/chunk-ASOPGD6M-BJTRNfdw.js +1 -0
  13. package/dist/assets/{chunk-QZHKN3VN-C4dk7jd_.js → chunk-KFBOBJHC-BGQXz2rx.js} +1 -1
  14. package/dist/assets/chunk-T2TOU4HS-B_Hp8GkX.js +164 -0
  15. package/dist/assets/{chunk-4BX2VUAB-BBHyCswj.js → chunk-TMUBEWPD-B-wRJmoa.js} +1 -1
  16. package/dist/assets/classDiagram-LNE6IOMH-CZ8s4mLA.js +1 -0
  17. package/dist/assets/classDiagram-v2-MQ7JQ4JX-CZ8s4mLA.js +1 -0
  18. package/dist/assets/dagre-4EVJKHTY-P6NEeAHP.js +4 -0
  19. package/dist/assets/diagram-QW4FP2JN-D9MgZ4pR.js +24 -0
  20. package/dist/assets/erDiagram-6RL3IURR-B5MeX-n8.js +51 -0
  21. package/dist/assets/flowDiagram-7ASYPVHJ-DJNgDNr-.js +160 -0
  22. package/dist/assets/ganttDiagram-NTVNEXSI-DGQ-2AXN.js +257 -0
  23. package/dist/assets/gitGraph-YCYPL57B-DuelfB2i.js +133 -0
  24. package/dist/assets/gitGraphDiagram-NRZ2UAAF-F1pgJp5v.js +65 -0
  25. package/dist/assets/graph-BlwPajkw.js +1 -0
  26. package/dist/assets/infoDiagram-A4XQUW5V-BpE4Lqpu.js +2 -0
  27. package/dist/assets/journeyDiagram-G5WM74LC-DA2heykh.js +139 -0
  28. package/dist/assets/{kanban-definition-6JOO6SKY-DDkk2pi4.js → kanban-definition-QRCXZQQD-DDrc4ZgF.js} +9 -10
  29. package/dist/assets/layout-Bvwu4dCi.js +1 -0
  30. package/dist/assets/linear-rewU58yp.js +1 -0
  31. package/dist/assets/main-BT5_pdVW.css +10 -0
  32. package/dist/assets/main-Bj-Sews0.js +1064 -0
  33. package/dist/assets/mindmap-definition-GWI6TPTV-bfGwTkWH.js +95 -0
  34. package/dist/assets/pieDiagram-YF2LJOPJ-vXO0jQ-T.js +30 -0
  35. package/dist/assets/{quadrantDiagram-34T5L4WZ-CzpNqHz9.js → quadrantDiagram-OS5C2QUG-BW-IIhOe.js} +4 -4
  36. package/dist/assets/requirementDiagram-MIRIMTAZ-CHSKqwb4.js +52 -0
  37. package/dist/assets/{sankeyDiagram-XADWPNL6-DEdEaxaO.js → sankeyDiagram-Y46BX6SQ-DPtdxF9s.js} +7 -9
  38. package/dist/assets/sequenceDiagram-G6AWOVSC-KG_aawZU.js +122 -0
  39. package/dist/assets/stateDiagram-MAYHULR4-lzW4oM1G.js +1 -0
  40. package/dist/assets/stateDiagram-v2-4JROLMXI-DE-mb-Dw.js +1 -0
  41. package/dist/assets/timeline-definition-U7ZMHBDA-DkuthLq_.js +61 -0
  42. package/dist/assets/xychartDiagram-6QU3TZC5-BlnWNfha.js +7 -0
  43. package/dist/index.html +2 -2
  44. package/dist-server/app.module.js +1 -0
  45. package/dist-server/bootstrap/crewx-server.js +1 -0
  46. package/dist-server/bootstrap/tls.js +108 -27
  47. package/dist-server/common/limits/limits.controller.js +1 -1
  48. package/dist-server/domain/agent/agent.service.js +12 -1
  49. package/dist-server/domain/auth/auth.controller.js +13 -11
  50. package/dist-server/domain/auth/guards/base-auth.guard.js +13 -9
  51. package/dist-server/domain/auth/session-store.js +26 -0
  52. package/dist-server/domain/auth/utils/ip.utils.js +1 -1
  53. package/dist-server/domain/cli/cli.controller.js +48 -0
  54. package/dist-server/domain/cli/cli.service.js +132 -31
  55. package/dist-server/domain/cli/dto/login-cli.dto.js +25 -0
  56. package/dist-server/domain/git/git.service.js +1 -1
  57. package/dist-server/domain/task/task.service.js +38 -5
  58. package/dist-server/domain/usage/usage.service.js +18 -3
  59. package/dist-server/domain/workspace/workspace.service.js +8 -26
  60. package/dist-server/main.js +23 -1
  61. package/dist-server/modules/crewx-pool.service.js +1 -1
  62. package/dist-server/repository/project.repository.js +3 -0
  63. package/dist-server/repository/task.repository.js +0 -1
  64. package/package.json +119 -122
  65. package/packages/cli/dist/bootstrap/crewx-cli.js +1 -0
  66. package/packages/cli/dist/commands/execute.js +1 -0
  67. package/packages/cli/dist/commands/query.js +1 -0
  68. package/packages/cli/dist/commands/slack.js +1 -1
  69. package/packages/cli/dist/main.js +3 -6
  70. package/packages/cli/dist/slack/file-download.js +1 -1
  71. package/packages/cli/package.json +5 -5
  72. package/dist/assets/PromptTab-CX3T_kO-.js +0 -37
  73. package/dist/assets/_baseUniq-DoJ1HHWx.js +0 -1
  74. package/dist/assets/arc-t5HebXb5.js +0 -1
  75. package/dist/assets/architectureDiagram-Q4EWVU46-BrSDq1JQ.js +0 -36
  76. package/dist/assets/blockDiagram-DXYQGD6D-BG0JNT6z.js +0 -132
  77. package/dist/assets/c4Diagram-AHTNJAMY-BOqLqa3J.js +0 -10
  78. package/dist/assets/channel-CEB3zo90.js +0 -1
  79. package/dist/assets/chunk-4TB4RGXK-C5-asTsp.js +0 -206
  80. package/dist/assets/chunk-55IACEB6-0OYgffGZ.js +0 -1
  81. package/dist/assets/chunk-EDXVE4YY-BvS4WeNv.js +0 -1
  82. package/dist/assets/chunk-FMBD7UC4-BUZZ5ZG5.js +0 -15
  83. package/dist/assets/chunk-OYMX7WX6-BD3Ms2oI.js +0 -231
  84. package/dist/assets/chunk-YZCP3GAM-Ce9RY9B4.js +0 -1
  85. package/dist/assets/classDiagram-6PBFFD2Q-aFvMKrtn.js +0 -1
  86. package/dist/assets/classDiagram-v2-HSJHXN6E-aFvMKrtn.js +0 -1
  87. package/dist/assets/clone-C-cMw_b1.js +0 -1
  88. package/dist/assets/cose-bilkent-S5V4N54A-D_EdvpCz.js +0 -1
  89. package/dist/assets/dagre-KV5264BT-CrdKSic2.js +0 -4
  90. package/dist/assets/defaultLocale-DX6XiGOO.js +0 -1
  91. package/dist/assets/diagram-5BDNPKRD-CvKlLSOF.js +0 -10
  92. package/dist/assets/diagram-G4DWMVQ6-C7w3ovOF.js +0 -24
  93. package/dist/assets/diagram-MMDJMWI5-CQB0s4BI.js +0 -43
  94. package/dist/assets/diagram-TYMM5635-DFwxw9PV.js +0 -24
  95. package/dist/assets/erDiagram-SMLLAGMA-D_43jyaU.js +0 -85
  96. package/dist/assets/flowDiagram-DWJPFMVM-B6ETX3HO.js +0 -162
  97. package/dist/assets/ganttDiagram-T4ZO3ILL-DMMgqlrx.js +0 -292
  98. package/dist/assets/gitGraphDiagram-UUTBAWPF-BliZXVbG.js +0 -106
  99. package/dist/assets/graph-BpzhcyLY.js +0 -1
  100. package/dist/assets/infoDiagram-42DDH7IO-CiIf42kM.js +0 -2
  101. package/dist/assets/ishikawaDiagram-UXIWVN3A-D4KNwqjV.js +0 -70
  102. package/dist/assets/journeyDiagram-VCZTEJTY-D5KyHoNR.js +0 -139
  103. package/dist/assets/layout-DR2RX63p.js +0 -1
  104. package/dist/assets/linear-DhaHLG7O.js +0 -1
  105. package/dist/assets/main-Cg4sg9yR.css +0 -10
  106. package/dist/assets/main-CxlpSzil.js +0 -1172
  107. package/dist/assets/min-Bg9B8ATt.js +0 -1
  108. package/dist/assets/mindmap-definition-QFDTVHPH-CMFaK3VU.js +0 -96
  109. package/dist/assets/pieDiagram-DEJITSTG-D4px3qAh.js +0 -30
  110. package/dist/assets/requirementDiagram-MS252O5E-BjbJXwco.js +0 -84
  111. package/dist/assets/sequenceDiagram-FGHM5R23-BOdpoApq.js +0 -157
  112. package/dist/assets/stateDiagram-FHFEXIEX-BdG-qjkB.js +0 -1
  113. package/dist/assets/stateDiagram-v2-QKLJ7IA2-DFwoxvPZ.js +0 -1
  114. package/dist/assets/timeline-definition-GMOUNBTQ-C9gA4zUg.js +0 -120
  115. package/dist/assets/vennDiagram-DHZGUBPP-DPC4_X3Z.js +0 -34
  116. package/dist/assets/wardley-RL74JXVD-zu57xGLd.js +0 -162
  117. package/dist/assets/wardleyDiagram-NUSXRM2D-CIcOsOyi.js +0 -20
  118. package/dist/assets/xychartDiagram-5P7HB3ND-yn2jMJNf.js +0 -7
package/bin/crewx-lib.js CHANGED
@@ -7,75 +7,6 @@ import { join } from 'path';
7
7
  import { CLI_SUBCOMMANDS } from './cli-commands.js';
8
8
  import { buildHintMessage } from './launcher-flags.js';
9
9
 
10
- /**
11
- * Parse serve-related flags: --port, --token, --token-file, --no-open.
12
- * Strict mode: unknown --xxx tokens → { error } instead of silent absorption.
13
- *
14
- * @param {string[]} args
15
- * @returns {{ port?: number, token?: string, tokenFile?: string, noOpen: boolean } | { error: string }}
16
- */
17
- export function parseServeFlags(args) {
18
- let port = undefined;
19
- let token = undefined;
20
- let tokenFile = undefined;
21
- let noOpen = false;
22
-
23
- const consumed = new Set();
24
-
25
- for (let i = 0; i < args.length; i++) {
26
- const arg = args[i];
27
-
28
- if (arg === '--port') {
29
- const val = Number(args[i + 1]);
30
- if (!val || val < 1 || val > 65535) {
31
- return { error: 'Invalid port number. Use 1-65535.' };
32
- }
33
- port = val;
34
- consumed.add(i);
35
- consumed.add(i + 1);
36
- i++;
37
- } else if (arg?.startsWith('--port=')) {
38
- const val = Number(arg.slice('--port='.length));
39
- if (!val || val < 1 || val > 65535) {
40
- return { error: 'Invalid port number. Use 1-65535.' };
41
- }
42
- port = val;
43
- consumed.add(i);
44
- } else if (arg === '--token') {
45
- token = args[i + 1];
46
- consumed.add(i);
47
- consumed.add(i + 1);
48
- i++;
49
- } else if (arg?.startsWith('--token=')) {
50
- token = arg.slice('--token='.length);
51
- consumed.add(i);
52
- } else if (arg === '--token-file') {
53
- tokenFile = args[i + 1];
54
- consumed.add(i);
55
- consumed.add(i + 1);
56
- i++;
57
- } else if (arg?.startsWith('--token-file=')) {
58
- tokenFile = arg.slice('--token-file='.length);
59
- consumed.add(i);
60
- } else if (arg === '--no-open') {
61
- noOpen = true;
62
- consumed.add(i);
63
- } else if (arg === '--help' || arg === '-h') {
64
- return { help: true };
65
- }
66
- }
67
-
68
- // Strict: reject unconsumed --xxx flags
69
- for (let i = 0; i < args.length; i++) {
70
- if (consumed.has(i)) continue;
71
- const arg = args[i];
72
- if (arg?.startsWith('--')) {
73
- return { error: `Unknown option for "crewx serve": ${arg}` };
74
- }
75
- }
76
-
77
- return { port, token, tokenFile, noOpen };
78
- }
79
10
 
80
11
  /**
81
12
  * Parse --port option from extra CLI args.
package/bin/crewx.js CHANGED
@@ -7,6 +7,8 @@
7
7
  * crewx serve [--port N] → Web server (explicit)
8
8
  * [--token T] → MCP bearer token (⚠️ prefer --token-file in shared shells)
9
9
  * [--token-file PATH] → Read token from file
10
+ * [--https] → Enable HTTPS with auto-generated certificate
11
+ * [--trust] → Install CA to system trust store (requires --https)
10
12
  * [--no-open] → Do not open browser
11
13
  * crewx electron [--overlay] → Electron desktop or overlay window
12
14
  * crewx --version → CLI version output
@@ -19,7 +21,8 @@ import { fileURLToPath } from 'url';
19
21
  import { dirname, join } from 'path';
20
22
  import { homedir } from 'os';
21
23
  import { createRequire } from 'module';
22
- import { setupSignalForwarding, resolveRoute, parseServeFlags, ensureCrewxDirs } from './crewx-lib.js';
24
+ import { defineCommand, runCommand, renderUsage } from 'citty';
25
+ import { setupSignalForwarding, resolveRoute, ensureCrewxDirs } from './crewx-lib.js';
23
26
 
24
27
  const __filename = fileURLToPath(import.meta.url);
25
28
  const __dirname = dirname(__filename);
@@ -68,52 +71,21 @@ function launchElectron(entryFile, routeArgs = []) {
68
71
  }
69
72
 
70
73
  /**
71
- * Launch the web server with parsed serve flags.
74
+ * Launch the web server with the given options.
72
75
  * Token injection: --token → MCP_BEARER_TOKEN env; --token-file → read + inject.
73
76
  */
74
- function launchWeb(serveArgs = [], { openBrowser = false } = {}) {
75
- // Ensure ~/.crewx/ directory and tasks schema before spawning the NestJS server.
76
- // Schema owner = CLI; launcher is the enforcement point so the server can assume DB exists.
77
- const require = createRequire(import.meta.url);
78
- const cliSchemaPath = join(__dirname, '..', 'packages', 'cli', 'dist', 'schema', 'tasks.js');
79
- const { ensureTasksSchema } = require(cliSchemaPath);
80
- const dbDir = join(homedir(), '.crewx');
81
- const BetterSqlite3 = require('better-sqlite3');
82
- const db = new BetterSqlite3(join(dbDir, 'crewx.db'));
83
- ensureTasksSchema(db);
84
- db.close();
85
-
77
+ function launchWeb({ port, token, tokenFile, open: openFlag, https, trust } = {}) {
86
78
  const serverScript = join(__dirname, '..', 'server.js');
87
79
 
88
- const flagsResult = parseServeFlags(serveArgs);
89
- if (flagsResult.help) {
90
- process.stdout.write(
91
- 'Usage: crewx serve [options]\n' +
92
- '\n' +
93
- 'Options:\n' +
94
- ' --port <N> Port to listen on (default: auto)\n' +
95
- ' --token <T> MCP bearer token\n' +
96
- ' --token-file <path> Read token from file\n' +
97
- ' --no-open Do not open browser automatically\n' +
98
- ' --help, -h Show this help\n',
99
- );
100
- process.exit(0);
80
+ const env = { ...process.env, NODE_ENV: 'production' };
81
+
82
+ if (https) {
83
+ env.CREWX_HTTPS = 'true';
101
84
  }
102
- if (flagsResult.error) {
103
- console.error(`❌ ${flagsResult.error}`);
104
- if (flagsResult.error.startsWith('Unknown option')) {
105
- process.stderr.write(
106
- ' Did you mean: crewx serve --port <N>\n' +
107
- ' Run `crewx serve --help` for usage.\n',
108
- );
109
- }
110
- process.exit(flagsResult.error.startsWith('Unknown option') ? 2 : 1);
85
+ if (trust) {
86
+ env.CREWX_TRUST_CA = 'true';
111
87
  }
112
88
 
113
- const { port, token, tokenFile, noOpen } = flagsResult;
114
-
115
- const env = { ...process.env, NODE_ENV: 'production' }; // Force production — prevents users from bypassing FREE limits via env
116
-
117
89
  if (port) {
118
90
  env.PORT = String(port);
119
91
  }
@@ -144,7 +116,15 @@ function launchWeb(serveArgs = [], { openBrowser = false } = {}) {
144
116
  env.NODE_EXTRA_CA_CERTS = certPath;
145
117
  }
146
118
 
147
- if (openBrowser && !noOpen) {
119
+ if (https) {
120
+ console.log('🔒 HTTPS enabled with SowonLabs CA');
121
+ if (!trust) {
122
+ console.log('⚠️ Browser may show a certificate warning.');
123
+ console.log(' To remove warning: npx crewx serve --https --trust');
124
+ }
125
+ }
126
+
127
+ if (openFlag) {
148
128
  env.CREWX_OPEN_BROWSER = '1';
149
129
  }
150
130
 
@@ -162,6 +142,51 @@ function launchWeb(serveArgs = [], { openBrowser = false } = {}) {
162
142
  });
163
143
  }
164
144
 
145
+ const serveCommand = defineCommand({
146
+ meta: { name: 'serve', description: 'Launch CrewX web server' },
147
+ args: {
148
+ port: { type: 'string', description: 'Port to listen on' },
149
+ token: { type: 'string', description: 'MCP bearer token' },
150
+ 'token-file': { type: 'string', description: 'Read token from file' },
151
+ https: { type: 'boolean', description: 'Enable HTTPS with auto-generated certificate' },
152
+ trust: { type: 'boolean', description: 'Install CA to system trust store (requires --https)' },
153
+ open: { type: 'boolean', description: 'Auto-open browser', default: true },
154
+ help: { type: 'boolean', alias: 'h', description: 'Show this help' },
155
+ },
156
+ async run({ args }) {
157
+ if (args.help) {
158
+ const usage = await renderUsage(serveCommand);
159
+ process.stdout.write(usage + '\n');
160
+ process.exit(0);
161
+ }
162
+ const knownArgs = new Set(['_', 'port', 'token', 'token-file', 'tokenFile', 'https', 'trust', 'open', 'help', 'h']);
163
+ for (const key of Object.keys(args)) {
164
+ if (!knownArgs.has(key)) {
165
+ console.error(`❌ Unknown option for "crewx serve": --${key}`);
166
+ console.error(' Run `crewx serve --help` for usage.');
167
+ process.exit(2);
168
+ }
169
+ }
170
+ if (args.trust && !args.https) {
171
+ console.error('❌ --trust requires --https');
172
+ process.exit(1);
173
+ }
174
+ const port = args.port ? Number(args.port) : undefined;
175
+ if (args.port && (!port || port < 1 || port > 65535)) {
176
+ console.error('❌ Invalid port number. Use 1-65535.');
177
+ process.exit(1);
178
+ }
179
+ launchWeb({
180
+ port,
181
+ token: args.token,
182
+ tokenFile: args['token-file'],
183
+ open: args.open,
184
+ https: args.https,
185
+ trust: args.trust,
186
+ });
187
+ },
188
+ });
189
+
165
190
  function forwardToCli(cliArgs) {
166
191
  const serverScript = join(__dirname, '..', 'server.js');
167
192
  const child = spawn(process.execPath, [serverScript, 'cli', ...cliArgs], {
@@ -185,8 +210,7 @@ const args = process.argv.slice(2);
185
210
  const { route, routeArgs, error } = resolveRoute(args);
186
211
 
187
212
  if (route === 'serve') {
188
- // Explicit web server launch
189
- launchWeb(routeArgs, { openBrowser: false });
213
+ runCommand(serveCommand, { rawArgs: routeArgs });
190
214
  } else if (route === 'electron') {
191
215
  // Electron: desktop (default) or overlay (--overlay flag)
192
216
  const isOverlay = routeArgs.includes('--overlay');
@@ -213,7 +237,7 @@ if (route === 'serve') {
213
237
  forwardToCli(routeArgs);
214
238
  } else if (route === 'web-default') {
215
239
  // No arguments → web dashboard + browser auto-open
216
- launchWeb(routeArgs, { openBrowser: true });
240
+ runCommand(serveCommand, { rawArgs: ['--open', ...routeArgs] });
217
241
  } else if (route === 'error') {
218
242
  // Unknown command or option
219
243
  console.error(`❌ ${error}`);
@@ -1,4 +1,4 @@
1
- import{aO as v,aP as we,aQ as b,aR as k,aS as Se,aT as u,aU as e,aV as ae,aW as se,aX as K,aY as N,aZ as re,a_ as Ie,a$ as le,b0 as U,b1 as ze,b2 as Re,b3 as ie,b4 as Ce,b5 as Me}from"./main-CxlpSzil.js";/**
1
+ import{aB as v,aC as we,aD as b,aE as k,aF as Se,aG as u,aH as e,aI as ae,aJ as se,aK as Y,aL as N,aM as re,aN as Ie,aO as le,aP as O,aQ as ze,aR as Ce,aS as ie,aT as Re,aU as Me}from"./main-Bj-Sews0.js";/**
2
2
  * @license lucide-react v0.563.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,29 +8,29 @@ import{aO as v,aP as we,aQ as b,aR as k,aS as Se,aT as u,aU as e,aV as ae,aW as
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const Ae=[["path",{d:"M12 6v6h4",key:"135r8i"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Te=v("clock-3",Ae);/**
11
+ */const Ae=[["path",{d:"M12 6v6h4",key:"135r8i"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Le=v("clock-3",Ae);/**
12
12
  * @license lucide-react v0.563.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const Le=[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]],de=v("layout-template",Le);/**
16
+ */const Te=[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]],de=v("layout-template",Te);/**
17
17
  * @license lucide-react v0.563.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const $e=[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]],oe=v("puzzle",$e);/**
21
+ */const Ee=[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]],oe=v("puzzle",Ee);/**
22
22
  * @license lucide-react v0.563.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const Ee=[["path",{d:"M12 3v18",key:"108xh3"}],["path",{d:"m19 8 3 8a5 5 0 0 1-6 0zV7",key:"zcdpyk"}],["path",{d:"M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1",key:"1yorad"}],["path",{d:"m5 8 3 8a5 5 0 0 1-6 0zV7",key:"eua70x"}],["path",{d:"M7 21h10",key:"1b0cd5"}]],_e=v("scale",Ee);/**
26
+ */const $e=[["path",{d:"M12 3v18",key:"108xh3"}],["path",{d:"m19 8 3 8a5 5 0 0 1-6 0zV7",key:"zcdpyk"}],["path",{d:"M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1",key:"1yorad"}],["path",{d:"m5 8 3 8a5 5 0 0 1-6 0zV7",key:"eua70x"}],["path",{d:"M7 21h10",key:"1b0cd5"}]],_e=v("scale",$e);/**
27
27
  * @license lucide-react v0.563.0 - ISC
28
28
  *
29
29
  * This source code is licensed under the ISC license.
30
30
  * See the LICENSE file in the root directory of this source tree.
31
- */const Ve=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],Fe=v("settings-2",Ve);/**
31
+ */const Fe=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],Ve=v("settings-2",Fe);/**
32
32
  * @license lucide-react v0.563.0 - ISC
33
33
  *
34
34
  * This source code is licensed under the ISC license.
35
35
  * See the LICENSE file in the root directory of this source tree.
36
- */const Pe=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],Oe=v("star",Pe);function I(t){return t instanceof Error?t.message:String(t)}function Ue(t){return[...t].sort((a,s)=>a.isInstalled!==s.isInstalled?a.isInstalled?-1:1:(a.displayName||a.name).localeCompare(s.displayName||s.name))}function Be(t=[],a=[]){return Array.from(new Set([...t,...a]))}function He(t,a){var s;return t?{...t,...a,displayName:a.displayName||t.displayName||a.name,description:a.description||t.description,author:a.author||t.author,version:a.version||t.version,tags:Be(t.tags,a.tags),type:a.type||t.type,isVerified:t.isVerified||a.isVerified,isInstalled:t.isInstalled||a.isInstalled,registryId:a.registryId??t.registryId,registryName:a.registryName??t.registryName,installSource:a.installSource??t.installSource,authors:(s=a.authors)!=null&&s.length?a.authors:t.authors,updatedAt:a.updatedAt??t.updatedAt,stars:a.stars??t.stars,license:a.license??t.license,installCount:a.installCount??t.installCount}:a}function L(t){const a=new Map;for(const s of t){const r=a.get(s.name);a.set(s.name,He(r,s))}return Ue(Array.from(a.values()))}function Qe(t,a){return t.map(s=>({...s,registryId:s.registryId??a.id,registryName:s.registryName??a.name,isVerified:s.isVerified||a.isVerified}))}function qe(t){return t.find(a=>a.isDefault)??t.find(a=>a.isVerified)??t[0]??null}function We(t,a){return L([...t,...a])}function O(t,a){var s;return a&&t.some(r=>r.name===a)?a:((s=t[0])==null?void 0:s.name)??null}const Ze=we((t,a)=>({initialized:!1,loading:!1,loadingOfficial:!1,loadingInstalled:!1,savingRegistry:!1,deletingRegistryId:null,mutatingSkillName:null,error:null,registries:[],officialRegistryId:null,allSkills:[],activeFilter:"all",searchQuery:"",selectedSkillName:null,setActiveFilter:s=>t({activeFilter:s}),setSearchQuery:s=>t({searchQuery:s}),setSelectedSkill:s=>t({selectedSkillName:s}),initialize:async()=>{const s=a().selectedSkillName;t({loading:!0,loadingOfficial:!0,loadingInstalled:!0,error:null});try{const n=(await b.getSkillRegistries()).registries,o=qe(n),[d,m]=await Promise.all([o?b.getRegistrySkills(o.id):Promise.resolve({skills:[]}),b.getInstalledSkills()]),y=o?Qe(d.skills,o):[],c=L(m.skills.filter(f=>!f.source||f.source==="local")),h=We(y,c);t({initialized:!0,loading:!1,loadingOfficial:!1,loadingInstalled:!1,registries:n,officialRegistryId:(o==null?void 0:o.id)??null,allSkills:h,selectedSkillName:O(h,s)})}catch(r){throw t({loading:!1,loadingOfficial:!1,loadingInstalled:!1,error:I(r)}),r}},refresh:async()=>{await a().initialize()},addRegistry:async s=>{const r=s.trim();if(!r){const n=new Error("Registry URL is required");throw t({error:n.message}),n}t({savingRegistry:!0,error:null});try{await b.addSkillRegistry(r),await a().initialize(),t({savingRegistry:!1})}catch(n){throw t({savingRegistry:!1,error:I(n)}),n}},deleteRegistry:async s=>{t({deletingRegistryId:s,error:null});try{await b.deleteSkillRegistry(s),await a().initialize(),t({deletingRegistryId:null})}catch(r){throw t({deletingRegistryId:null,error:I(r)}),r}},installSkill:async(s,r)=>{t({mutatingSkillName:r,error:null});try{await b.installSkill(s,r),t(n=>{const o=n.registries.find(m=>m.id===s),d=L(n.allSkills.map(m=>m.name===r?{...m,isInstalled:!0,registryId:m.registryId??s,registryName:m.registryName??(o==null?void 0:o.name)}:m));return{allSkills:d,mutatingSkillName:null,selectedSkillName:O(d,n.selectedSkillName??r)}})}catch(n){throw t({mutatingSkillName:null,error:I(n)}),n}},uninstallSkill:async s=>{t({mutatingSkillName:s,error:null});try{await b.uninstallSkill(s),t(r=>{const n=L(r.allSkills.map(o=>o.name===s?{...o,isInstalled:!1}:o));return{allSkills:n,mutatingSkillName:null,selectedSkillName:O(n,r.selectedSkillName)}})}catch(r){throw t({mutatingSkillName:null,error:I(r)}),r}},clearError:()=>t({error:null})}));function ce(t,a){if(!t)return"—";const s=new Date(t);return Number.isNaN(s.getTime())?"—":new Intl.DateTimeFormat(a,{year:"numeric",month:"short",day:"numeric"}).format(s)}function Xe(t,a){if(!t)return null;const s=new Date(t);if(Number.isNaN(s.getTime()))return null;const r=s.getTime()-Date.now(),n=[{unit:"year",ms:1e3*60*60*24*365},{unit:"month",ms:1e3*60*60*24*30},{unit:"week",ms:1e3*60*60*24*7},{unit:"day",ms:1e3*60*60*24},{unit:"hour",ms:1e3*60*60},{unit:"minute",ms:1e3*60}],o=new Intl.RelativeTimeFormat(a,{numeric:"auto"});for(const d of n)if(Math.abs(r)>=d.ms||d.unit==="minute")return o.format(Math.round(r/d.ms),d.unit);return null}function ee(t,a){return typeof t!="number"?"—":new Intl.NumberFormat(a,{notation:"compact",compactDisplay:"short",maximumFractionDigits:1}).format(t)}function B(t){switch(t==null?void 0:t.toLowerCase()){case"template":return"template";case"agent":return"agent";default:return"skill"}}function me({type:t}){const{t:a}=k(),s=B(t),r={skill:"bg-violet-50 text-violet-700",template:"bg-amber-50 text-amber-700",agent:"bg-emerald-50 text-emerald-700"},n={skill:oe,template:de,agent:re},o={skill:a("market.types.skill"),template:a("market.types.template"),agent:a("market.types.agent")},d=n[s];return e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${r[s]}`,children:[e.jsx(d,{size:12}),o[s]]})}function Ye({url:t,error:a,submitting:s,onChange:r,onClose:n,onSubmit:o}){const{t:d}=k(),m=y=>{y.preventDefault(),o()};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{role:"dialog","aria-modal":"true",className:"w-full max-w-xl overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl",children:[e.jsxs("div",{className:"border-b border-gray-200 px-6 py-5",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:d("market.addRegistryModal.title")}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:d("market.addRegistryModal.description")})]}),e.jsxs("form",{onSubmit:m,children:[e.jsxs("div",{className:"space-y-4 px-6 py-5",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"registry-url",className:"mb-2 block text-sm font-medium text-gray-700",children:d("market.addRegistryModal.urlLabel")}),e.jsx("input",{id:"registry-url",type:"url",value:t,onChange:y=>r(y.target.value),placeholder:d("market.addRegistryModal.urlPlaceholder"),className:"w-full rounded-lg border border-gray-300 px-4 py-3 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500",autoFocus:!0})]}),e.jsx("div",{className:"rounded-xl border border-blue-200 bg-blue-50 px-4 py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-white text-blue-600",children:e.jsx(Ce,{size:18})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-blue-900",children:d("market.addRegistryModal.compatibilityTitle")}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-blue-800",children:d("market.addRegistryModal.compatibilityDescription")})]})]})}),a&&e.jsxs("div",{className:"flex items-start gap-3 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-red-700",children:[e.jsx(se,{size:18,className:"mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm",children:a})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-gray-200 px-6 py-4",children:[e.jsx("button",{type:"button",onClick:n,disabled:s,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:d("market.actions.cancel")}),e.jsxs("button",{type:"submit",disabled:s,className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600 disabled:cursor-not-allowed disabled:opacity-50",children:[s?e.jsx(N,{size:16,className:"animate-spin"}):e.jsx(U,{size:16}),d("market.actions.addRegistry")]})]})]})]})})}function Ge({registry:t,deleting:a,onDelete:s}){const{t:r,i18n:n}=k();return e.jsxs("article",{className:"flex flex-col gap-4 rounded-xl border border-gray-200 bg-white p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("div",{className:`flex h-11 w-11 shrink-0 items-center justify-center rounded-xl ${t.isVerified?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-500"}`,children:e.jsx(ie,{size:20})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"truncate text-base font-semibold text-gray-900",children:t.name}),e.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${t.isDefault?"bg-amber-50 text-amber-700":"bg-gray-100 text-gray-600"}`,children:t.isDefault?r("market.registryCard.defaultBadge"):r("market.registryCard.customBadge")})]}),e.jsxs("a",{href:t.url,target:"_blank",rel:"noreferrer",className:"mt-2 inline-flex break-all text-sm text-blue-600 hover:text-blue-700",children:[e.jsx("span",{children:t.url}),e.jsx(Me,{size:14,className:"ml-1 mt-0.5 shrink-0"})]})]})]}),e.jsxs("button",{type:"button",onClick:()=>s(t.id),disabled:t.isDefault||a,className:`inline-flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors ${t.isDefault?"cursor-not-allowed bg-gray-100 text-gray-400":"bg-red-50 text-red-600 hover:bg-red-100 disabled:cursor-not-allowed disabled:opacity-50"}`,children:[a?e.jsx(N,{size:15,className:"animate-spin"}):e.jsx(le,{size:15}),t.isDefault?r("market.registryCard.lockedAction"):r("market.actions.deleteRegistry")]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:r("market.registryCard.skillCount")}),e.jsx("p",{className:"mt-1 text-lg font-semibold text-gray-900",children:t.skillCount})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:r("market.registryCard.addedAt")}),e.jsx("p",{className:"mt-1 text-sm font-medium text-gray-900",children:ce(t.addedAt,n.language)})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:t.isDefault?r("market.registryCard.defaultHint"):r("market.registryCard.customHint")})]})}function Je({registries:t,loading:a,deletingRegistryId:s,onAdd:r,onClose:n,onDelete:o}){const{t:d}=k();return e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{role:"dialog","aria-modal":"true",className:"flex max-h-[85vh] w-full max-w-4xl flex-col overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-gray-200 px-6 py-5",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:d("market.registryModal.title")}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:d("market.registryModal.description")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:r,className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[e.jsx(U,{size:16}),d("market.actions.addRegistry")]}),e.jsx("button",{type:"button",onClick:n,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:d("market.actions.close")})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5",children:a?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(N,{size:22,className:"animate-spin text-gray-400"})}):t.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-gray-300 px-6 py-16 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:e.jsx(ie,{size:20})}),e.jsx("h3",{className:"mt-4 text-base font-semibold text-gray-900",children:d("market.empty.registryTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:d("market.empty.registryDescription")})]}):e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:t.map(m=>e.jsx(Ge,{registry:m,deleting:s===m.id,onDelete:o},m.id))})})]})})}function te({skill:t,selected:a,onSelect:s}){const{t:r,i18n:n}=k(),o=Xe(t.updatedAt,n.language),d=B(t.type),m={skill:oe,template:de,agent:re},y={skill:t.isInstalled?"bg-blue-100 text-blue-600":"bg-gray-100 text-gray-500",template:"bg-amber-100 text-amber-700",agent:"bg-emerald-100 text-emerald-700"},c=m[d];return e.jsx("button",{type:"button",onClick:()=>s(t.name),className:`w-full rounded-xl border p-3 text-left transition-colors ${a?"border-blue-200 bg-blue-50 shadow-sm":"border-transparent bg-white hover:border-gray-200 hover:bg-gray-50"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl ${y[d]}`,children:e.jsx(c,{size:18})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:t.displayName||t.name}),t.isVerified&&e.jsx(ne,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}),e.jsx(me,{type:t.type})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-gray-500",children:t.description||r("market.card.noDescription")}),e.jsxs("p",{className:"mt-2 text-[11px] text-gray-400",children:[t.registryName||t.author||r("market.card.unknownAuthor"),o?` · ${r("market.list.updatedLabel",{time:o})}`:""]})]}),t.isInstalled&&e.jsx("span",{className:"shrink-0 rounded-full bg-green-100 px-2 py-0.5 text-[10px] font-medium text-green-700",children:r("market.badges.installed")})]})})}function T({icon:t,label:a,value:s}){return e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-gray-50 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsx("span",{className:"text-gray-400",children:t}),e.jsx("span",{children:a})]}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-gray-900",children:s})]})}function Ke({skill:t,markdownBody:a,descriptionLoading:s,descriptionError:r,busy:n,canInstall:o,onInstall:d,onUninstall:m,onRefresh:y}){const{t:c,i18n:h}=k(),f=typeof(t==null?void 0:t.installCount)=="number";return t?e.jsxs("section",{className:"flex h-full min-h-[520px] flex-col rounded-2xl border border-gray-200 bg-white p-6 shadow-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4 border-b border-gray-200 pb-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"text-2xl font-semibold text-gray-900",children:t.displayName||t.name}),e.jsxs("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-600",children:["v",t.version]}),e.jsx(me,{type:t.type}),t.isVerified&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-50 px-2.5 py-1 text-xs font-medium text-blue-700",children:[e.jsx(ne,{size:13}),c("market.badges.verified")]})]}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t.registryName||t.author||c("market.card.unknownAuthor")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.isInstalled?e.jsxs("button",{type:"button",onClick:()=>m(t.name),disabled:n,className:"inline-flex items-center gap-2 rounded-lg bg-red-50 px-4 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-100 disabled:cursor-not-allowed disabled:opacity-50",children:[n?e.jsx(N,{size:16,className:"animate-spin"}):e.jsx(le,{size:16}),c("market.actions.uninstall")]}):e.jsxs("button",{type:"button",onClick:()=>d(t),disabled:n||!o,className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600 disabled:cursor-not-allowed disabled:opacity-50",children:[n?e.jsx(N,{size:16,className:"animate-spin"}):e.jsx(U,{size:16}),c("market.actions.install")]}),e.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:[e.jsx(ae,{size:16}),c("market.actions.checkUpdates")]})]})]}),e.jsxs("div",{className:"space-y-6 py-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:c("market.detail.description")}),e.jsx("div",{className:"mt-2",children:s?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx(N,{size:16,className:"animate-spin"}),e.jsx("span",{children:c("market.detail.loadingBody")})]}):t.isInstalled?a!=null&&a.trim()?e.jsx(ze,{content:a,className:"text-sm"}):e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"mb-3 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:r}),e.jsx("p",{className:"whitespace-pre-wrap text-sm leading-6 text-gray-600",children:t.description||c("market.card.noDescription")})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm leading-6 text-gray-600",children:t.description||c("market.card.noDescription")}),e.jsx("div",{className:"rounded-xl border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-800",children:c("market.detail.installToViewBody")})]})})]}),t.tags.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:c("market.detail.tags")}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:t.tags.map(p=>e.jsxs("span",{className:"rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1 text-xs text-gray-600",children:["#",p]},p))})]}),t.authors&&t.authors.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:c("market.detail.developers")}),e.jsx("div",{className:"mt-3 space-y-3",children:t.authors.map(p=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:p.avatarUrl,alt:`@${p.login}`,className:"h-8 w-8 rounded-full border border-gray-200 object-cover"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-sm font-medium text-gray-900",children:p.name||p.login}),e.jsxs("div",{className:"text-xs text-gray-500",children:["@",p.login]})]}),typeof p.contributions=="number"&&e.jsx("div",{className:"text-xs text-gray-400",children:c("market.detail.contributions",{count:p.contributions})})]},`${t.name}-${p.login}`))})]})]}),e.jsxs("div",{className:`mt-auto grid gap-3 border-t border-gray-200 pt-6 sm:grid-cols-2 ${f?"xl:grid-cols-4":"xl:grid-cols-3"}`,children:[e.jsx(T,{icon:e.jsx(Oe,{size:14}),label:c("market.detail.stats.stars"),value:ee(t.stars,h.language)}),f&&e.jsx(T,{icon:e.jsx(Re,{size:14}),label:c("market.detail.stats.installs"),value:ee(t.installCount,h.language)}),e.jsx(T,{icon:e.jsx(_e,{size:14}),label:c("market.detail.stats.license"),value:t.license||c("market.detail.unavailable")}),e.jsx(T,{icon:e.jsx(Te,{size:14}),label:c("market.detail.stats.updatedAt"),value:ce(t.updatedAt,h.language)})]})]}):e.jsx("div",{className:"flex h-full min-h-[520px] items-center justify-center rounded-2xl border border-gray-200 bg-white p-8 shadow-sm",children:e.jsxs("div",{className:"max-w-sm text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:e.jsx(Ie,{size:20})}),e.jsx("h3",{className:"mt-4 text-base font-semibold text-gray-900",children:c("market.detail.emptyTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:c("market.detail.emptyDescription")})]})})}function tt(){const{t}=k(),{setPageHeader:a}=Se(),[s,r]=u.useState(!1),[n,o]=u.useState(!1),[d,m]=u.useState(""),[y,c]=u.useState(null),[h,f]=u.useState({}),[p,$]=u.useState(null),[xe,z]=u.useState(null),{initialized:H,loading:R,savingRegistry:ue,deletingRegistryId:ge,mutatingSkillName:pe,error:Q,registries:ye,officialRegistryId:E,allSkills:w,activeFilter:S,searchQuery:_,selectedSkillName:C,setActiveFilter:he,setSearchQuery:fe,setSelectedSkill:M,initialize:q,refresh:D,addRegistry:W,deleteRegistry:Z,installSkill:X,uninstallSkill:Y,clearError:A}=Ze();u.useEffect(()=>{H||q().catch(()=>{})},[H,q]);const G=u.useMemo(()=>w.filter(l=>l.isInstalled).length,[w]),j=u.useMemo(()=>{const l=_.trim().toLowerCase();return w.filter(x=>S==="installed"&&!x.isInstalled||S!=="all"&&S!=="installed"&&B(x.type)!==S?!1:l?[x.displayName,x.name,x.description,x.author,x.registryName,...x.tags].filter(g=>!!g).some(g=>g.toLowerCase().includes(l)):!0)},[S,w,_]),i=u.useMemo(()=>j.find(l=>l.name===C)??j[0]??null,[j,C]),V=i?h[i.name]:void 0;u.useEffect(()=>{const l=(i==null?void 0:i.name)??null;l!==C&&M(l)},[i,C,M]),u.useEffect(()=>{if(!(i!=null&&i.isInstalled)){z(null),$(g=>g===(i==null?void 0:i.name)?null:g);return}if(V!==void 0){z(null);return}let l=!1;const x=i.name;return $(x),z(null),b.getInstalledSkillDetail(x).then(g=>{l||f(ke=>({...ke,[x]:g.body??""}))}).catch(g=>{l||z(g instanceof Error?g.message:t("market.errors.detailLoad"))}).finally(()=>{l||$(g=>g===x?null:g)}),()=>{l=!0}},[i==null?void 0:i.isInstalled,i==null?void 0:i.name,V,t]);const F=u.useCallback(l=>{l&&f(x=>{if(!(l in x))return x;const g={...x};return delete g[l],g})},[]);u.useEffect(()=>{a({title:t("market.title"),subtitle:t("market.subtitle.summary",{total:w.length,installed:G}),actions:e.jsxs("button",{type:"button",onClick:()=>{A(),F((i==null?void 0:i.name)??null),D().catch(()=>{})},className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:[e.jsx(ae,{size:16,className:R?"animate-spin":""}),t("market.actions.refresh")]})})},[w.length,A,R,D,F,i==null?void 0:i.name,a,t,G]);const be=u.useCallback(l=>{const x=l.registryId??E;x&&X(x,l.name).catch(()=>{})},[X,E]),je=u.useCallback(l=>{window.confirm(t("market.actions.confirmUninstall",{name:l}))&&Y(l).catch(()=>{})},[t,Y]),Ne=u.useCallback(l=>{Z(l).catch(()=>{})},[Z]),ve=u.useCallback(async()=>{c(null);try{await W(d),m(""),o(!1)}catch(l){c(l instanceof Error?l.message:t("market.errors.addRegistry"))}},[W,d,t]),P=j.filter(l=>l.isInstalled),J=j.filter(l=>!l.isInstalled);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-6",children:[Q&&e.jsxs("div",{className:"flex items-start gap-3 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-red-700",children:[e.jsx(se,{size:18,className:"mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:t("market.errors.bannerTitle")}),e.jsx("p",{className:"mt-1 break-words text-sm",children:Q})]}),e.jsx("button",{type:"button",onClick:()=>{A(),D().catch(()=>{})},className:"shrink-0 rounded-md bg-red-100 px-3 py-1.5 text-xs font-medium text-red-700 transition-colors hover:bg-red-200",children:t("market.actions.retry")})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-2xl border border-gray-200 bg-white p-4 shadow-sm lg:flex-row lg:items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(K,{size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search",value:_,onChange:l=>fe(l.target.value),placeholder:t("market.searchPlaceholder"),className:"w-full rounded-xl border border-gray-300 py-2.5 pl-10 pr-4 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("button",{type:"button",onClick:()=>r(!0),className:"inline-flex items-center justify-center gap-2 rounded-xl border border-gray-200 bg-gray-50 px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100",children:[e.jsx(Fe,{size:16}),t("market.actions.manageSources")]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["all","installed","skill","template","agent"].map(l=>e.jsx("button",{type:"button",onClick:()=>he(l),className:`rounded-full border px-3 py-1.5 text-sm font-medium transition-colors ${S===l?"border-blue-500 bg-blue-500 text-white":"border-gray-200 bg-white text-gray-600 hover:bg-gray-50"}`,children:t(`market.filters.${l}`)},l))}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[360px_minmax(0,1fr)]",children:[e.jsxs("section",{className:"rounded-2xl border border-gray-200 bg-white shadow-sm",children:[e.jsxs("div",{className:"border-b border-gray-200 px-4 py-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900",children:t("market.list.title")}),e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:t("market.list.count",{count:j.length})})]}),e.jsx("div",{className:"max-h-[640px] overflow-y-auto p-3",children:R?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(N,{size:22,className:"animate-spin text-gray-400"})}):j.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-gray-300 px-4 py-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:e.jsx(K,{size:18})}),e.jsx("h3",{className:"mt-3 text-sm font-semibold text-gray-900",children:t("market.empty.filteredTitle")}),e.jsx("p",{className:"mt-2 text-xs leading-5 text-gray-500",children:t("market.empty.filteredDescription")})]}):e.jsxs("div",{className:"space-y-3",children:[P.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"px-1 text-xs font-semibold uppercase tracking-wide text-gray-400",children:t("market.list.installedHeading")}),P.map(l=>e.jsx(te,{skill:l,selected:(i==null?void 0:i.name)===l.name,onSelect:M},l.name))]}),J.length>0&&e.jsxs("div",{className:"space-y-2",children:[P.length>0&&e.jsx("p",{className:"px-1 pt-2 text-xs font-semibold uppercase tracking-wide text-gray-400",children:t("market.list.availableHeading")}),J.map(l=>e.jsx(te,{skill:l,selected:(i==null?void 0:i.name)===l.name,onSelect:M},l.name))]})]})})]}),e.jsx(Ke,{skill:i,markdownBody:V,descriptionLoading:i?p===i.name:!1,descriptionError:xe,busy:i?pe===i.name:!1,canInstall:!!((i==null?void 0:i.registryId)??E),onInstall:be,onUninstall:je,onRefresh:()=>{A(),F((i==null?void 0:i.name)??null),D().catch(()=>{})}})]})]}),s&&e.jsx(Je,{registries:ye,loading:R,deletingRegistryId:ge,onAdd:()=>{c(null),m(""),o(!0)},onClose:()=>r(!1),onDelete:Ne}),n&&e.jsx(Ye,{url:d,error:y,submitting:ue,onChange:m,onClose:()=>{c(null),o(!1)},onSubmit:ve})]})}export{tt as default};
36
+ */const Pe=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],Be=v("star",Pe);function I(t){return t instanceof Error?t.message:String(t)}function Oe(t){return[...t].sort((a,s)=>a.isInstalled!==s.isInstalled?a.isInstalled?-1:1:(a.displayName||a.name).localeCompare(s.displayName||s.name))}function Ue(t=[],a=[]){return Array.from(new Set([...t,...a]))}function He(t,a){var s;return t?{...t,...a,displayName:a.displayName||t.displayName||a.name,description:a.description||t.description,author:a.author||t.author,version:a.version||t.version,tags:Ue(t.tags,a.tags),type:a.type||t.type,isVerified:t.isVerified||a.isVerified,isInstalled:t.isInstalled||a.isInstalled,registryId:a.registryId??t.registryId,registryName:a.registryName??t.registryName,installSource:a.installSource??t.installSource,authors:(s=a.authors)!=null&&s.length?a.authors:t.authors,updatedAt:a.updatedAt??t.updatedAt,stars:a.stars??t.stars,license:a.license??t.license,installCount:a.installCount??t.installCount}:a}function T(t){const a=new Map;for(const s of t){const r=a.get(s.name);a.set(s.name,He(r,s))}return Oe(Array.from(a.values()))}function Qe(t,a){return t.map(s=>({...s,registryId:s.registryId??a.id,registryName:s.registryName??a.name,isVerified:s.isVerified||a.isVerified}))}function qe(t){return t.find(a=>a.isDefault)??t.find(a=>a.isVerified)??t[0]??null}function Ge(t,a){return T([...t,...a])}function B(t,a){var s;return a&&t.some(r=>r.name===a)?a:((s=t[0])==null?void 0:s.name)??null}const Je=we((t,a)=>({initialized:!1,loading:!1,loadingOfficial:!1,loadingInstalled:!1,savingRegistry:!1,deletingRegistryId:null,mutatingSkillName:null,error:null,registries:[],officialRegistryId:null,allSkills:[],activeFilter:"all",searchQuery:"",selectedSkillName:null,setActiveFilter:s=>t({activeFilter:s}),setSearchQuery:s=>t({searchQuery:s}),setSelectedSkill:s=>t({selectedSkillName:s}),initialize:async()=>{const s=a().selectedSkillName;t({loading:!0,loadingOfficial:!0,loadingInstalled:!0,error:null});try{const n=(await b.getSkillRegistries()).registries,o=qe(n),[d,m]=await Promise.all([o?b.getRegistrySkills(o.id):Promise.resolve({skills:[]}),b.getInstalledSkills()]),y=o?Qe(d.skills,o):[],c=T(m.skills.filter(f=>!f.source||f.source==="local")),h=Ge(y,c);t({initialized:!0,loading:!1,loadingOfficial:!1,loadingInstalled:!1,registries:n,officialRegistryId:(o==null?void 0:o.id)??null,allSkills:h,selectedSkillName:B(h,s)})}catch(r){throw t({loading:!1,loadingOfficial:!1,loadingInstalled:!1,error:I(r)}),r}},refresh:async()=>{await a().initialize()},addRegistry:async s=>{const r=s.trim();if(!r){const n=new Error("Registry URL is required");throw t({error:n.message}),n}t({savingRegistry:!0,error:null});try{await b.addSkillRegistry(r),await a().initialize(),t({savingRegistry:!1})}catch(n){throw t({savingRegistry:!1,error:I(n)}),n}},deleteRegistry:async s=>{t({deletingRegistryId:s,error:null});try{await b.deleteSkillRegistry(s),await a().initialize(),t({deletingRegistryId:null})}catch(r){throw t({deletingRegistryId:null,error:I(r)}),r}},installSkill:async(s,r)=>{t({mutatingSkillName:r,error:null});try{await b.installSkill(s,r),t(n=>{const o=n.registries.find(m=>m.id===s),d=T(n.allSkills.map(m=>m.name===r?{...m,isInstalled:!0,registryId:m.registryId??s,registryName:m.registryName??(o==null?void 0:o.name)}:m));return{allSkills:d,mutatingSkillName:null,selectedSkillName:B(d,n.selectedSkillName??r)}})}catch(n){throw t({mutatingSkillName:null,error:I(n)}),n}},uninstallSkill:async s=>{t({mutatingSkillName:s,error:null});try{await b.uninstallSkill(s),t(r=>{const n=T(r.allSkills.map(o=>o.name===s?{...o,isInstalled:!1}:o));return{allSkills:n,mutatingSkillName:null,selectedSkillName:B(n,r.selectedSkillName)}})}catch(r){throw t({mutatingSkillName:null,error:I(r)}),r}},clearError:()=>t({error:null})}));function ce(t,a){if(!t)return"—";const s=new Date(t);return Number.isNaN(s.getTime())?"—":new Intl.DateTimeFormat(a,{year:"numeric",month:"short",day:"numeric"}).format(s)}function Ke(t,a){if(!t)return null;const s=new Date(t);if(Number.isNaN(s.getTime()))return null;const r=s.getTime()-Date.now(),n=[{unit:"year",ms:1e3*60*60*24*365},{unit:"month",ms:1e3*60*60*24*30},{unit:"week",ms:1e3*60*60*24*7},{unit:"day",ms:1e3*60*60*24},{unit:"hour",ms:1e3*60*60},{unit:"minute",ms:1e3*60}],o=new Intl.RelativeTimeFormat(a,{numeric:"auto"});for(const d of n)if(Math.abs(r)>=d.ms||d.unit==="minute")return o.format(Math.round(r/d.ms),d.unit);return null}function ee(t,a){return typeof t!="number"?"—":new Intl.NumberFormat(a,{notation:"compact",compactDisplay:"short",maximumFractionDigits:1}).format(t)}function U(t){switch(t==null?void 0:t.toLowerCase()){case"template":return"template";case"agent":return"agent";default:return"skill"}}function me({type:t}){const{t:a}=k(),s=U(t),r={skill:"bg-violet-50 text-violet-700",template:"bg-amber-50 text-amber-700",agent:"bg-emerald-50 text-emerald-700"},n={skill:oe,template:de,agent:re},o={skill:a("market.types.skill"),template:a("market.types.template"),agent:a("market.types.agent")},d=n[s];return e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-medium ${r[s]}`,children:[e.jsx(d,{size:12}),o[s]]})}function We({url:t,error:a,submitting:s,onChange:r,onClose:n,onSubmit:o}){const{t:d}=k(),m=y=>{y.preventDefault(),o()};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{role:"dialog","aria-modal":"true",className:"w-full max-w-xl overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl",children:[e.jsxs("div",{className:"border-b border-gray-200 px-6 py-5",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:d("market.addRegistryModal.title")}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:d("market.addRegistryModal.description")})]}),e.jsxs("form",{onSubmit:m,children:[e.jsxs("div",{className:"space-y-4 px-6 py-5",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"registry-url",className:"mb-2 block text-sm font-medium text-gray-700",children:d("market.addRegistryModal.urlLabel")}),e.jsx("input",{id:"registry-url",type:"url",value:t,onChange:y=>r(y.target.value),placeholder:d("market.addRegistryModal.urlPlaceholder"),className:"w-full rounded-lg border border-gray-300 px-4 py-3 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500",autoFocus:!0})]}),e.jsx("div",{className:"rounded-xl border border-blue-200 bg-blue-50 px-4 py-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-white text-blue-600",children:e.jsx(Re,{size:18})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-blue-900",children:d("market.addRegistryModal.compatibilityTitle")}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-blue-800",children:d("market.addRegistryModal.compatibilityDescription")})]})]})}),a&&e.jsxs("div",{className:"flex items-start gap-3 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-red-700",children:[e.jsx(se,{size:18,className:"mt-0.5 shrink-0"}),e.jsx("p",{className:"text-sm",children:a})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-gray-200 px-6 py-4",children:[e.jsx("button",{type:"button",onClick:n,disabled:s,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:d("market.actions.cancel")}),e.jsxs("button",{type:"submit",disabled:s,className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600 disabled:cursor-not-allowed disabled:opacity-50",children:[s?e.jsx(N,{size:16,className:"animate-spin"}):e.jsx(O,{size:16}),d("market.actions.addRegistry")]})]})]})]})})}function Ze({registry:t,deleting:a,onDelete:s}){const{t:r,i18n:n}=k();return e.jsxs("article",{className:"flex flex-col gap-4 rounded-xl border border-gray-200 bg-white p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("div",{className:`flex h-11 w-11 shrink-0 items-center justify-center rounded-xl ${t.isVerified?"bg-blue-50 text-blue-600":"bg-gray-100 text-gray-500"}`,children:e.jsx(ie,{size:20})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"truncate text-base font-semibold text-gray-900",children:t.name}),e.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${t.isDefault?"bg-amber-50 text-amber-700":"bg-gray-100 text-gray-600"}`,children:t.isDefault?r("market.registryCard.defaultBadge"):r("market.registryCard.customBadge")})]}),e.jsxs("a",{href:t.url,target:"_blank",rel:"noreferrer",className:"mt-2 inline-flex break-all text-sm text-blue-600 hover:text-blue-700",children:[e.jsx("span",{children:t.url}),e.jsx(Me,{size:14,className:"ml-1 mt-0.5 shrink-0"})]})]})]}),e.jsxs("button",{type:"button",onClick:()=>s(t.id),disabled:t.isDefault||a,className:`inline-flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors ${t.isDefault?"cursor-not-allowed bg-gray-100 text-gray-400":"bg-red-50 text-red-600 hover:bg-red-100 disabled:cursor-not-allowed disabled:opacity-50"}`,children:[a?e.jsx(N,{size:15,className:"animate-spin"}):e.jsx(le,{size:15}),t.isDefault?r("market.registryCard.lockedAction"):r("market.actions.deleteRegistry")]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:r("market.registryCard.skillCount")}),e.jsx("p",{className:"mt-1 text-lg font-semibold text-gray-900",children:t.skillCount})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-4 py-3",children:[e.jsx("p",{className:"text-xs text-gray-500",children:r("market.registryCard.addedAt")}),e.jsx("p",{className:"mt-1 text-sm font-medium text-gray-900",children:ce(t.addedAt,n.language)})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:t.isDefault?r("market.registryCard.defaultHint"):r("market.registryCard.customHint")})]})}function Xe({registries:t,loading:a,deletingRegistryId:s,onAdd:r,onClose:n,onDelete:o}){const{t:d}=k();return e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{role:"dialog","aria-modal":"true",className:"flex max-h-[85vh] w-full max-w-4xl flex-col overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-gray-200 px-6 py-5",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:d("market.registryModal.title")}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:d("market.registryModal.description")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:r,className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:[e.jsx(O,{size:16}),d("market.actions.addRegistry")]}),e.jsx("button",{type:"button",onClick:n,className:"rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:d("market.actions.close")})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5",children:a?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(N,{size:22,className:"animate-spin text-gray-400"})}):t.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-gray-300 px-6 py-16 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:e.jsx(ie,{size:20})}),e.jsx("h3",{className:"mt-4 text-base font-semibold text-gray-900",children:d("market.empty.registryTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:d("market.empty.registryDescription")})]}):e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:t.map(m=>e.jsx(Ze,{registry:m,deleting:s===m.id,onDelete:o},m.id))})})]})})}function te({skill:t,selected:a,onSelect:s}){const{t:r,i18n:n}=k(),o=Ke(t.updatedAt,n.language),d=U(t.type),m={skill:oe,template:de,agent:re},y={skill:t.isInstalled?"bg-blue-100 text-blue-600":"bg-gray-100 text-gray-500",template:"bg-amber-100 text-amber-700",agent:"bg-emerald-100 text-emerald-700"},c=m[d];return e.jsx("button",{type:"button",onClick:()=>s(t.name),className:`w-full rounded-xl border p-3 text-left transition-colors ${a?"border-blue-200 bg-blue-50 shadow-sm":"border-transparent bg-white hover:border-gray-200 hover:bg-gray-50"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl ${y[d]}`,children:e.jsx(c,{size:18})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-gray-900",children:t.displayName||t.name}),t.isVerified&&e.jsx(ne,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}),e.jsx(me,{type:t.type})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-xs text-gray-500",children:t.description||r("market.card.noDescription")}),e.jsxs("p",{className:"mt-2 text-[11px] text-gray-400",children:[t.registryName||t.author||r("market.card.unknownAuthor"),o?` · ${r("market.list.updatedLabel",{time:o})}`:""]})]}),t.isInstalled&&e.jsx("span",{className:"shrink-0 rounded-full bg-green-100 px-2 py-0.5 text-[10px] font-medium text-green-700",children:r("market.badges.installed")})]})})}function L({icon:t,label:a,value:s}){return e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-gray-50 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsx("span",{className:"text-gray-400",children:t}),e.jsx("span",{children:a})]}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-gray-900",children:s})]})}function Ye({skill:t,markdownBody:a,descriptionLoading:s,descriptionError:r,busy:n,canInstall:o,onInstall:d,onUninstall:m,onRefresh:y}){const{t:c,i18n:h}=k(),f=typeof(t==null?void 0:t.installCount)=="number";return t?e.jsxs("section",{className:"flex h-full min-h-[520px] flex-col rounded-2xl border border-gray-200 bg-white p-6 shadow-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4 border-b border-gray-200 pb-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"text-2xl font-semibold text-gray-900",children:t.displayName||t.name}),e.jsxs("span",{className:"rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-600",children:["v",t.version]}),e.jsx(me,{type:t.type}),t.isVerified&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-50 px-2.5 py-1 text-xs font-medium text-blue-700",children:[e.jsx(ne,{size:13}),c("market.badges.verified")]})]}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:t.registryName||t.author||c("market.card.unknownAuthor")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.isInstalled?e.jsxs("button",{type:"button",onClick:()=>m(t.name),disabled:n,className:"inline-flex items-center gap-2 rounded-lg bg-red-50 px-4 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-100 disabled:cursor-not-allowed disabled:opacity-50",children:[n?e.jsx(N,{size:16,className:"animate-spin"}):e.jsx(le,{size:16}),c("market.actions.uninstall")]}):e.jsxs("button",{type:"button",onClick:()=>d(t),disabled:n||!o,className:"inline-flex items-center gap-2 rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600 disabled:cursor-not-allowed disabled:opacity-50",children:[n?e.jsx(N,{size:16,className:"animate-spin"}):e.jsx(O,{size:16}),c("market.actions.install")]}),e.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:[e.jsx(ae,{size:16}),c("market.actions.checkUpdates")]})]})]}),e.jsxs("div",{className:"space-y-6 py-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:c("market.detail.description")}),e.jsx("div",{className:"mt-2",children:s?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx(N,{size:16,className:"animate-spin"}),e.jsx("span",{children:c("market.detail.loadingBody")})]}):t.isInstalled?a!=null&&a.trim()?e.jsx(ze,{content:a,className:"text-sm"}):e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"mb-3 rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800",children:r}),e.jsx("p",{className:"whitespace-pre-wrap text-sm leading-6 text-gray-600",children:t.description||c("market.card.noDescription")})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm leading-6 text-gray-600",children:t.description||c("market.card.noDescription")}),e.jsx("div",{className:"rounded-xl border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-800",children:c("market.detail.installToViewBody")})]})})]}),t.tags.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:c("market.detail.tags")}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:t.tags.map(p=>e.jsxs("span",{className:"rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1 text-xs text-gray-600",children:["#",p]},p))})]}),t.authors&&t.authors.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-900",children:c("market.detail.developers")}),e.jsx("div",{className:"mt-3 space-y-3",children:t.authors.map(p=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("img",{src:p.avatarUrl,alt:`@${p.login}`,className:"h-8 w-8 rounded-full border border-gray-200 object-cover"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-sm font-medium text-gray-900",children:p.name||p.login}),e.jsxs("div",{className:"text-xs text-gray-500",children:["@",p.login]})]}),typeof p.contributions=="number"&&e.jsx("div",{className:"text-xs text-gray-400",children:c("market.detail.contributions",{count:p.contributions})})]},`${t.name}-${p.login}`))})]})]}),e.jsxs("div",{className:`mt-auto grid gap-3 border-t border-gray-200 pt-6 sm:grid-cols-2 ${f?"xl:grid-cols-4":"xl:grid-cols-3"}`,children:[e.jsx(L,{icon:e.jsx(Be,{size:14}),label:c("market.detail.stats.stars"),value:ee(t.stars,h.language)}),f&&e.jsx(L,{icon:e.jsx(Ce,{size:14}),label:c("market.detail.stats.installs"),value:ee(t.installCount,h.language)}),e.jsx(L,{icon:e.jsx(_e,{size:14}),label:c("market.detail.stats.license"),value:t.license||c("market.detail.unavailable")}),e.jsx(L,{icon:e.jsx(Le,{size:14}),label:c("market.detail.stats.updatedAt"),value:ce(t.updatedAt,h.language)})]})]}):e.jsx("div",{className:"flex h-full min-h-[520px] items-center justify-center rounded-2xl border border-gray-200 bg-white p-8 shadow-sm",children:e.jsxs("div",{className:"max-w-sm text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:e.jsx(Ie,{size:20})}),e.jsx("h3",{className:"mt-4 text-base font-semibold text-gray-900",children:c("market.detail.emptyTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-500",children:c("market.detail.emptyDescription")})]})})}function tt(){const{t}=k(),{setPageHeader:a}=Se(),[s,r]=u.useState(!1),[n,o]=u.useState(!1),[d,m]=u.useState(""),[y,c]=u.useState(null),[h,f]=u.useState({}),[p,E]=u.useState(null),[xe,z]=u.useState(null),{initialized:H,loading:C,savingRegistry:ue,deletingRegistryId:ge,mutatingSkillName:pe,error:Q,registries:ye,officialRegistryId:$,allSkills:w,activeFilter:S,searchQuery:_,selectedSkillName:R,setActiveFilter:he,setSearchQuery:fe,setSelectedSkill:M,initialize:q,refresh:D,addRegistry:G,deleteRegistry:J,installSkill:K,uninstallSkill:W,clearError:A}=Je();u.useEffect(()=>{H||q().catch(()=>{})},[H,q]);const Z=u.useMemo(()=>w.filter(l=>l.isInstalled).length,[w]),j=u.useMemo(()=>{const l=_.trim().toLowerCase();return w.filter(x=>S==="installed"&&!x.isInstalled||S!=="all"&&S!=="installed"&&U(x.type)!==S?!1:l?[x.displayName,x.name,x.description,x.author,x.registryName,...x.tags].filter(g=>!!g).some(g=>g.toLowerCase().includes(l)):!0)},[S,w,_]),i=u.useMemo(()=>j.find(l=>l.name===R)??j[0]??null,[j,R]),F=i?h[i.name]:void 0;u.useEffect(()=>{const l=(i==null?void 0:i.name)??null;l!==R&&M(l)},[i,R,M]),u.useEffect(()=>{if(!(i!=null&&i.isInstalled)){z(null),E(g=>g===(i==null?void 0:i.name)?null:g);return}if(F!==void 0){z(null);return}let l=!1;const x=i.name;return E(x),z(null),b.getInstalledSkillDetail(x).then(g=>{l||f(ke=>({...ke,[x]:g.body??""}))}).catch(g=>{l||z(g instanceof Error?g.message:t("market.errors.detailLoad"))}).finally(()=>{l||E(g=>g===x?null:g)}),()=>{l=!0}},[i==null?void 0:i.isInstalled,i==null?void 0:i.name,F,t]);const V=u.useCallback(l=>{l&&f(x=>{if(!(l in x))return x;const g={...x};return delete g[l],g})},[]);u.useEffect(()=>{a({title:t("market.title"),subtitle:t("market.subtitle.summary",{total:w.length,installed:Z}),actions:e.jsxs("button",{type:"button",onClick:()=>{A(),V((i==null?void 0:i.name)??null),D().catch(()=>{})},className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:[e.jsx(ae,{size:16,className:C?"animate-spin":""}),t("market.actions.refresh")]})})},[w.length,A,C,D,V,i==null?void 0:i.name,a,t,Z]);const be=u.useCallback(l=>{const x=l.registryId??$;x&&K(x,l.name).catch(()=>{})},[K,$]),je=u.useCallback(l=>{window.confirm(t("market.actions.confirmUninstall",{name:l}))&&W(l).catch(()=>{})},[t,W]),Ne=u.useCallback(l=>{J(l).catch(()=>{})},[J]),ve=u.useCallback(async()=>{c(null);try{await G(d),m(""),o(!1)}catch(l){c(l instanceof Error?l.message:t("market.errors.addRegistry"))}},[G,d,t]),P=j.filter(l=>l.isInstalled),X=j.filter(l=>!l.isInstalled);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-6",children:[Q&&e.jsxs("div",{className:"flex items-start gap-3 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-red-700",children:[e.jsx(se,{size:18,className:"mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:t("market.errors.bannerTitle")}),e.jsx("p",{className:"mt-1 break-words text-sm",children:Q})]}),e.jsx("button",{type:"button",onClick:()=>{A(),D().catch(()=>{})},className:"shrink-0 rounded-md bg-red-100 px-3 py-1.5 text-xs font-medium text-red-700 transition-colors hover:bg-red-200",children:t("market.actions.retry")})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-2xl border border-gray-200 bg-white p-4 shadow-sm lg:flex-row lg:items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Y,{size:16,className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search",value:_,onChange:l=>fe(l.target.value),placeholder:t("market.searchPlaceholder"),className:"w-full rounded-xl border border-gray-300 py-2.5 pl-10 pr-4 text-sm text-gray-900 placeholder:text-gray-400 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("button",{type:"button",onClick:()=>r(!0),className:"inline-flex items-center justify-center gap-2 rounded-xl border border-gray-200 bg-gray-50 px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100",children:[e.jsx(Ve,{size:16}),t("market.actions.manageSources")]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["all","installed","skill","template","agent"].map(l=>e.jsx("button",{type:"button",onClick:()=>he(l),className:`rounded-full border px-3 py-1.5 text-sm font-medium transition-colors ${S===l?"border-blue-500 bg-blue-500 text-white":"border-gray-200 bg-white text-gray-600 hover:bg-gray-50"}`,children:t(`market.filters.${l}`)},l))}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[360px_minmax(0,1fr)]",children:[e.jsxs("section",{className:"rounded-2xl border border-gray-200 bg-white shadow-sm",children:[e.jsxs("div",{className:"border-b border-gray-200 px-4 py-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900",children:t("market.list.title")}),e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:t("market.list.count",{count:j.length})})]}),e.jsx("div",{className:"max-h-[640px] overflow-y-auto p-3",children:C?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(N,{size:22,className:"animate-spin text-gray-400"})}):j.length===0?e.jsxs("div",{className:"rounded-xl border border-dashed border-gray-300 px-4 py-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-10 w-10 items-center justify-center rounded-full bg-gray-100 text-gray-400",children:e.jsx(Y,{size:18})}),e.jsx("h3",{className:"mt-3 text-sm font-semibold text-gray-900",children:t("market.empty.filteredTitle")}),e.jsx("p",{className:"mt-2 text-xs leading-5 text-gray-500",children:t("market.empty.filteredDescription")})]}):e.jsxs("div",{className:"space-y-3",children:[P.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"px-1 text-xs font-semibold uppercase tracking-wide text-gray-400",children:t("market.list.installedHeading")}),P.map(l=>e.jsx(te,{skill:l,selected:(i==null?void 0:i.name)===l.name,onSelect:M},l.name))]}),X.length>0&&e.jsxs("div",{className:"space-y-2",children:[P.length>0&&e.jsx("p",{className:"px-1 pt-2 text-xs font-semibold uppercase tracking-wide text-gray-400",children:t("market.list.availableHeading")}),X.map(l=>e.jsx(te,{skill:l,selected:(i==null?void 0:i.name)===l.name,onSelect:M},l.name))]})]})})]}),e.jsx(Ye,{skill:i,markdownBody:F,descriptionLoading:i?p===i.name:!1,descriptionError:xe,busy:i?pe===i.name:!1,canInstall:!!((i==null?void 0:i.registryId)??$),onInstall:be,onUninstall:je,onRefresh:()=>{A(),V((i==null?void 0:i.name)??null),D().catch(()=>{})}})]})]}),s&&e.jsx(Xe,{registries:ye,loading:C,deletingRegistryId:ge,onAdd:()=>{c(null),m(""),o(!0)},onClose:()=>r(!1),onDelete:Ne}),n&&e.jsx(We,{url:d,error:y,submitting:ue,onChange:m,onClose:()=>{c(null),o(!1)},onSubmit:ve})]})}export{tt as default};
@@ -0,0 +1,37 @@
1
+ import{aB as F,aE as B,aG as u,aH as r,aV as ke,aL as X,aQ as we,aW as je,aD as V,aX as de,aK as ue,aY as K,aS as Ne,aZ as Ce,a_ as Le,a$ as _e,aO as Ee,b0 as pe,b1 as Se,b2 as De,b3 as Me,b4 as Ae,b5 as $e,b6 as Te,b7 as Ie,b8 as Pe,b9 as Re,ba as Be,bb as ze,bc as Oe,bd as qe,be as Ve,bf as Fe,bg as He,bh as Ke,bi as Qe,bj as We,bk as Ue,bl as Xe,bm as Je,bn as Ge,bo as Y}from"./main-Bj-Sews0.js";/**
2
+ * @license lucide-react v0.563.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Ze=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],Ye=F("braces",Ze);/**
7
+ * @license lucide-react v0.563.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const et=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],tt=F("eye",et);/**
12
+ * @license lucide-react v0.563.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const nt=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],rt=F("link-2",nt);/**
17
+ * @license lucide-react v0.563.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const st=[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]],at=F("refresh-ccw",st);function ee(e,s){return(e??"").toLowerCase().includes(s)}function me(e,s){const n=s.trim().toLowerCase();if(!n)return{nodes:e,autoExpanded:new Set};const t=new Set;return{nodes:e.flatMap(l=>{const c=ee(l.name,n)||ee(l.path,n);if(l.type==="file")return c?[l]:[];if(c)return t.add(l.path),[{...l,children:l.children}];const p=me(l.children??[],n);return p.nodes.length>0?(t.add(l.path),p.autoExpanded.forEach(m=>t.add(m)),[{...l,children:p.nodes}]):[]}),autoExpanded:t}}function fe(e){return e instanceof Error?/HTTP (404|405|501|503)\b|Failed to fetch|NetworkError/i.test(e.message):!1}const R={id:"agent_id",name:"에이전트 이름",role:"에이전트 역할",team:"팀",description:"에이전트 설명"};function ot(e){return{id:e.id.trim()||R.id,name:e.name.trim()||R.name,role:e.role.trim()||R.role,team:e.team.trim()||R.team,description:e.description.trim()||R.description}}function it(e,s,n){let t=!1;return e.state.doc.descendants(i=>i.type.name==="documentBlock"&&i.attrs.key===s&&i.attrs.variant===n?(t=!0,!1):!t),t}const he=["[&_h1]:mt-0","[&_h1]:mb-3","[&_h1]:text-2xl","[&_h1]:font-bold","[&_h2]:mt-0","[&_h2]:mb-2","[&_h2]:text-xl","[&_h2]:font-semibold","[&_h3]:mt-0","[&_h3]:mb-2","[&_h3]:text-lg","[&_h3]:font-semibold","[&_p]:my-2","[&_p]:leading-7","[&_ul]:my-2","[&_ol]:my-2","[&_ul]:list-disc","[&_ol]:list-decimal","[&_ul]:pl-6","[&_ol]:pl-6","[&_li]:my-1","[&_blockquote]:my-3","[&_blockquote]:border-l-4","[&_blockquote]:border-gray-300","[&_blockquote]:pl-4","[&_blockquote]:text-gray-600","[&_blockquote]:italic","[&_blockquote_p]:my-0","[&_a]:text-blue-600","[&_a]:underline","[&_hr]:my-4","[&_hr]:border-gray-300","[&_code]:rounded","[&_code]:bg-gray-100","[&_code]:px-1.5","[&_code]:py-0.5","[&_code]:font-mono","[&_code]:text-[13px]","[&_pre]:my-3","[&_pre]:overflow-x-auto","[&_pre]:rounded-lg","[&_pre]:bg-gray-900","[&_pre]:p-4","[&_pre]:text-sm","[&_pre]:text-gray-100","[&_pre_code]:bg-transparent","[&_pre_code]:p-0","[&_pre_code]:text-inherit"].join(" "),lt=["min-h-[420px]","rounded-xl","border","border-gray-200","bg-white","px-4","py-3","text-sm","text-gray-900","shadow-sm","focus:outline-none","prose","prose-sm","max-w-none",he,"[&_.is-editor-empty:first-child::before]:pointer-events-none","[&_.is-editor-empty:first-child::before]:float-left","[&_.is-editor-empty:first-child::before]:h-0","[&_.is-editor-empty:first-child::before]:text-gray-400","[&_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]"].join(" ");function ct({open:e,request:s,onClose:n}){const{t}=B(),i=u.useRef(null),l=u.useRef(s),[c,p]=u.useState(""),[m,x]=u.useState(!1),[o,y]=u.useState(null),[b,k]=u.useState(!1),w=t("agent.prompt.preview.error");l.current=s;const h=async()=>{var g;if((g=i.current)==null||g.abort(),!l.current.template.trim()){p(""),y(null),k(!1),x(!1);return}const d=new AbortController;i.current=d,x(!0),y(null),k(!1);try{const v=await V.previewPrompt(l.current,{signal:d.signal});if(d.signal.aborted)return;p(v.rendered),y(null),k(!1)}catch(v){if(d.signal.aborted)return;if(fe(v)){p(""),y(null),k(!0);return}p(""),k(!1),y(v instanceof Error?v.message:w)}finally{i.current===d&&(i.current=null),x(!1)}};return u.useEffect(()=>{var d;if(!e){(d=i.current)==null||d.abort();return}h()},[e]),u.useEffect(()=>{if(!e)return;const d=g=>{g.key==="Escape"&&(g.preventDefault(),n())};return window.addEventListener("keydown",d),()=>{window.removeEventListener("keydown",d)}},[n,e]),u.useEffect(()=>()=>{var d;(d=i.current)==null||d.abort()},[]),e?r.jsx("div",{"data-testid":"preview-modal-backdrop",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:n,children:r.jsxs("div",{role:"dialog","aria-modal":"true","data-testid":"preview-modal",onClick:d=>d.stopPropagation(),className:"flex max-h-[85vh] w-full max-w-4xl flex-col overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl",children:[r.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-gray-200 px-6 py-5",children:[r.jsx("div",{children:r.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:t("agent.prompt.preview.title")})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("button",{type:"button",onClick:()=>{h()},disabled:m,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:[r.jsx(at,{size:14,className:m?"animate-spin":""}),t("agent.prompt.preview.refresh")]}),r.jsxs("button",{type:"button",onClick:n,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200",children:[r.jsx(ke,{size:14}),t("common.close")]})]})]}),r.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5",children:s.template.trim()?m?r.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[r.jsx(X,{size:16,className:"animate-spin"}),r.jsx("span",{children:t("agent.prompt.preview.loading")})]}):b?r.jsx("div",{className:"text-sm text-gray-500",children:t("agent.prompt.preview.unavailable")}):o?r.jsxs("div",{className:"space-y-2",children:[r.jsx("div",{className:"text-sm font-medium text-red-600",children:t("agent.prompt.preview.error")}),r.jsx("div",{className:"text-sm text-red-500",children:o})]}):r.jsx(we,{content:c,className:he}):r.jsx("div",{className:"text-sm text-gray-500",children:t("agent.prompt.preview.empty")})}),r.jsxs("div",{className:"flex justify-end gap-2 border-t border-gray-200 px-6 py-4",children:[r.jsxs("button",{type:"button",onClick:()=>{var d;return void((d=navigator.clipboard)==null?void 0:d.writeText(c))},disabled:!c,className:"inline-flex items-center gap-2 rounded-lg bg-gray-100 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50",children:[r.jsx(je,{size:14}),t("agent.prompt.preview.copy")]}),r.jsx("button",{type:"button",onClick:n,className:"rounded-lg bg-blue-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-600",children:t("common.close")})]})]})}):null}function dt({trigger:e,items:s,searchable:n=!1,searchPlaceholder:t,emptyLabel:i}){const l=u.useRef(null),c=u.useRef(null),[p,m]=u.useState(!1),[x,o]=u.useState(""),[y,b]=u.useState(0),k=u.useMemo(()=>{const d=x.trim().toLowerCase();return d?s.filter(g=>g.label.toLowerCase().includes(d)?!0:g.actions.some(v=>v.label.toLowerCase().includes(d))):s},[s,x]),w=u.useMemo(()=>k.flatMap(d=>d.actions.map(g=>({itemLabel:d.label,actionLabel:g.label,onClick:g.onClick}))),[k]);u.useEffect(()=>{var d;if(!p){o(""),b(0);return}n&&((d=c.current)==null||d.focus())},[p,n]),u.useEffect(()=>{y<w.length||b(Math.max(w.length-1,0))},[w.length,y]),u.useEffect(()=>{if(!p)return;const d=v=>{var _;(_=l.current)!=null&&_.contains(v.target)||m(!1)},g=v=>{var _;if(v.key==="Escape"){v.preventDefault(),m(!1);return}if(w.length!==0){if(v.key==="ArrowDown"){v.preventDefault(),b(M=>(M+1)%w.length);return}if(v.key==="ArrowUp"){v.preventDefault(),b(M=>(M-1+w.length)%w.length);return}v.key==="Enter"&&(v.preventDefault(),(_=w[y])==null||_.onClick(),m(!1))}};return window.addEventListener("mousedown",d),window.addEventListener("keydown",g),()=>{window.removeEventListener("mousedown",d),window.removeEventListener("keydown",g)}},[w,y,p]);let h=-1;return r.jsxs("div",{ref:l,className:"relative",children:[r.jsxs("button",{type:"button",onMouseDown:d=>d.preventDefault(),onClick:()=>m(d=>!d),className:"inline-flex items-center gap-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 transition hover:border-gray-300 hover:bg-gray-100",children:[r.jsx("span",{children:e}),r.jsx(de,{size:14})]}),p?r.jsxs("div",{className:"absolute left-0 top-[calc(100%+0.5rem)] z-20 w-72 rounded-xl border border-gray-200 bg-white p-2 shadow-lg",children:[n?r.jsxs("label",{className:"mb-2 flex items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-xs text-gray-500",children:[r.jsx(ue,{size:14}),r.jsx("input",{ref:c,value:x,onChange:d=>{o(d.target.value),b(0)},className:"w-full bg-transparent text-sm text-gray-700 outline-none","aria-label":t,placeholder:t})]}):null,r.jsx("div",{className:"max-h-80 space-y-1 overflow-y-auto",children:k.length===0?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:i??""}):k.map(d=>r.jsxs("div",{className:"rounded-lg border border-gray-100 px-3 py-2",children:[r.jsx("div",{className:"text-sm font-medium text-gray-900",children:d.label}),d.actions.length>0?r.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:d.actions.map(g=>{h+=1;const v=h===y;return r.jsx("button",{type:"button",onMouseDown:_=>_.preventDefault(),onClick:()=>{g.onClick(),m(!1)},className:`rounded-md px-2.5 py-1 text-xs font-medium transition ${v?"bg-blue-500 text-white":"border border-gray-200 bg-white text-gray-700 hover:border-gray-300 hover:bg-gray-100"}`,children:g.label},`${d.label}-${g.label}`)})}):r.jsx("div",{className:"mt-1 text-xs text-gray-500",children:i??d.label})]},d.label))})]}):null]})}function te(e){return e.replace(/\\/g,"/").replace(/^\.?\//,"")}function ne(e,s){return(e??"").toLowerCase().includes(s)}function ut({documents:e,documentsLoading:s,documentsError:n,documentsUnavailable:t,onInsertDocument:i,onRefetchDocuments:l}){const{t:c}=B(),p=u.useRef(null),m=u.useRef(null),[x,o]=u.useState(!1),[y,b]=u.useState(""),[k,w]=u.useState([]),[h,d]=u.useState(!1),[g,v]=u.useState(null),[_,M]=u.useState(new Set),[a,j]=u.useState(!1),[C,D]=u.useState(null);u.useEffect(()=>{var N;if(!x||((N=m.current)==null||N.focus(),k.length>0||h))return;let f=!1;return(async()=>{d(!0),v(null);try{const S=await V.getDocTree();f||w(S)}catch(S){f||v(S instanceof Error?S.message:c("agent.prompt.documentPicker.treeError"))}finally{f||d(!1)}})(),()=>{f=!0}},[x,k.length]),u.useEffect(()=>{x||(b(f=>f&&""),M(f=>f.size>0?new Set:f))},[x]),u.useEffect(()=>{if(!x)return;const f=N=>{var S;(S=p.current)!=null&&S.contains(N.target)||o(!1)},L=N=>{N.key==="Escape"&&(N.preventDefault(),o(!1))};return window.addEventListener("mousedown",f),window.addEventListener("keydown",L),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",L)}},[x]);const E=y.trim().toLowerCase(),$=u.useMemo(()=>e.filter(f=>f.type==="inline"),[e]),z=u.useMemo(()=>{const f=e.filter(L=>L.type==="file"&&L.path);return L=>{const N=te(L),S=f.find(ve=>te(ve.path??"")===N);return S==null?void 0:S.key}},[e]),T=u.useMemo(()=>E?$.filter(f=>ne(f.key,E)||ne(f.summary,E)):$,[$,E]),P=u.useMemo(()=>me(k,E),[E,k]),be=u.useMemo(()=>{if(!E)return _;const f=new Set(_);return P.autoExpanded.forEach(L=>f.add(L)),f},[_,P.autoExpanded,E]),H=f=>{i(f,"content"),o(!1)},ye=async f=>{D(null);const L=z(f);if(L){H(L);return}try{j(!0);const N=await V.registerDocument({path:f});H(N.key),l==null||l()}catch(N){D(N instanceof Error?N.message:c("agent.prompt.documentPicker.registerError"))}finally{j(!1)}},G=s||n||t||T.length>0,Z=h||g||P.nodes.length>0;return r.jsxs("div",{ref:p,className:"relative",children:[r.jsxs("button",{type:"button",onMouseDown:f=>f.preventDefault(),onClick:()=>o(f=>!f),className:"inline-flex items-center gap-1 rounded-md border border-gray-200 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 transition hover:border-gray-300 hover:bg-gray-100","aria-label":c("agent.prompt.documentInsert"),children:[r.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[r.jsx(K,{className:"h-4 w-4"}),r.jsx("span",{children:c("agent.prompt.documentInsert")})]}),r.jsx(de,{size:14})]}),x?r.jsxs("div",{className:"absolute left-0 top-[calc(100%+0.5rem)] z-20 w-80 rounded-xl border border-gray-200 bg-white p-2 shadow-lg","data-testid":"document-picker-popover",children:[r.jsxs("label",{className:"mb-2 flex items-center gap-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-xs text-gray-500",children:[r.jsx(ue,{size:14}),r.jsx("input",{ref:m,value:y,onChange:f=>b(f.target.value),className:"w-full bg-transparent text-sm text-gray-700 outline-none","aria-label":c("agent.prompt.documentPicker.searchPlaceholder"),placeholder:c("agent.prompt.documentPicker.searchPlaceholder")})]}),r.jsxs("div",{className:"max-h-96 space-y-3 overflow-y-auto",children:[G?r.jsxs("section",{children:[r.jsxs("div",{className:"mb-1 flex items-center gap-2 px-2 py-1 text-xs font-semibold uppercase tracking-wide text-gray-400",children:[r.jsx(Ne,{className:"h-3.5 w-3.5"}),r.jsx("span",{children:c("agent.prompt.documentPicker.inlineSection")})]}),s?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentInsertLoading")}):n?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-red-500",children:n}):t?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentInsertUnavailable")}):T.length===0?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentPicker.noInlineResults")}):r.jsx("div",{className:"space-y-1",children:T.map(f=>r.jsxs("button",{type:"button",onMouseDown:L=>L.preventDefault(),onClick:()=>H(f.key),className:"flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-gray-700 transition hover:bg-gray-100",children:[r.jsx(K,{className:"h-4 w-4 shrink-0 text-gray-400"}),r.jsx("span",{className:"truncate",children:f.key})]},f.key))})]}):null,Z?r.jsxs("section",{children:[r.jsxs("div",{className:"mb-1 flex items-center gap-2 px-2 py-1 text-xs font-semibold uppercase tracking-wide text-gray-400",children:[r.jsx(K,{className:"h-3.5 w-3.5"}),r.jsx("span",{children:c("agent.prompt.documentPicker.docsSection")})]}),h?r.jsxs("div",{className:"flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-gray-500",children:[r.jsx(X,{className:"h-4 w-4 animate-spin"}),r.jsx("span",{children:c("agent.prompt.documentPicker.treeLoading")})]}):g?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-red-500",children:g}):P.nodes.length===0?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentPicker.noTreeResults")}):r.jsxs(r.Fragment,{children:[r.jsx(Ce,{nodes:P.nodes,expandedFolders:be,onToggle:f=>M(L=>{const N=new Set(L);return N.has(f)?N.delete(f):N.add(f),N}),onSelect:f=>{a||ye(f)},selectedPath:null,isFileDisabled:()=>a,renderFileSuffix:f=>z(f.path)?r.jsx(rt,{className:"h-3.5 w-3.5 shrink-0 text-blue-500","aria-label":c("agent.prompt.documentPicker.linked")}):a?r.jsx(X,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-gray-400"}):null}),C?r.jsx("div",{className:"mt-1 rounded-lg px-3 py-2 text-sm text-red-500",role:"alert",children:C}):null]})]}):null,!G&&!Z?r.jsx("div",{className:"rounded-lg px-3 py-2 text-sm text-gray-500",children:c("agent.prompt.documentInsertEmpty")}):null]})]}):null]})}function pt({deleteNode:e,extension:s,node:n,updateAttributes:t}){const{t:i}=B(),l=u.useRef(null),[c,p]=u.useState(!1),m=String(n.attrs.key??""),x=String(n.attrs.variant??"content"),o=s.options.getVariantLabel;u.useEffect(()=>{if(!c)return;const b=w=>{var h;(h=l.current)!=null&&h.contains(w.target)||p(!1)},k=w=>{w.key==="Escape"&&(w.preventDefault(),p(!1))};return window.addEventListener("mousedown",b),window.addEventListener("keydown",k),()=>{window.removeEventListener("mousedown",b),window.removeEventListener("keydown",k)}},[c]);const y=[{value:"content",label:o("content")},{value:"toc",label:o("toc")}];return r.jsxs(Le,{as:"span",ref:l,className:"relative inline-flex","data-testid":"document-block-node",children:[r.jsx("button",{type:"button","data-testid":"document-block-trigger",onMouseDown:b=>b.preventDefault(),onClick:()=>p(b=>!b),className:"inline-flex items-center rounded-lg border border-amber-200 bg-amber-50 px-2 py-0.5 text-xs font-medium text-amber-700",children:`📄 ${m} · ${o(x)}`}),c?r.jsxs("span",{className:"absolute left-0 top-[calc(100%+0.375rem)] z-20 min-w-32 rounded-lg border border-gray-200 bg-white p-1 shadow-lg","data-testid":"document-block-popover",children:[y.map(b=>{const k=b.value===x;return r.jsxs("button",{type:"button","data-testid":`document-block-option-${b.value}`,onMouseDown:w=>w.preventDefault(),onClick:()=>{t({variant:b.value}),p(!1)},className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-gray-700 transition hover:bg-gray-100",children:[r.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center",children:k?r.jsx(_e,{className:"h-4 w-4 text-blue-500"}):null}),r.jsx("span",{children:b.label})]},b.value)}),r.jsx("div",{className:"my-1 border-t border-gray-100"}),r.jsxs("button",{type:"button","data-testid":"document-block-delete",onMouseDown:b=>b.preventDefault(),onClick:()=>{e(),p(!1)},className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-red-600 transition hover:bg-red-50",children:[r.jsx(Ee,{className:"h-4 w-4"}),r.jsx("span",{children:i("agent.prompt.documentChip.delete")})]})]}):null]})}const mt=pe.create({name:"documentBlock",addOptions(){return{getVariantLabel:e=>String(e)}},inline:!0,group:"inline",atom:!0,draggable:!0,selectable:!0,addAttributes(){return{key:{default:""},variant:{default:"content"}}},parseHTML(){return[{tag:"span[data-doc-block]"}]},renderHTML({HTMLAttributes:e,node:s}){const n=String(s.attrs.key??""),t=String(s.attrs.variant??"content"),i=this.options.getVariantLabel(t);return["span",De(e,{"data-doc-block":"true","data-key":n,"data-variant":t,"data-testid":"document-block",class:"inline-flex items-center rounded-lg border border-amber-200 bg-amber-50 px-2 py-0.5 text-xs font-medium text-amber-700"}),`📄 ${n} · ${i}`]},addNodeView(){return Se(pt)}}),ft=Me.extend({name:"variableMention",addAttributes(){return{variable:{default:"",parseHTML:e=>e.getAttribute("data-variable")??"",renderHTML:e=>({"data-variable":e.variable})}}},renderText({node:e}){return`{{${String(e.attrs.variable??"")}}}`},renderHTML({node:e,HTMLAttributes:s}){return["span",{...s,class:"inline-flex items-center rounded-full bg-blue-500 px-2 py-0.5 text-xs font-semibold text-white","data-testid":"variable-chip"},String(e.attrs.variable??"")]}}),ge=["agent.id","agent.name","agent.role","agent.team","agent.description"],re=["bold","italic","strike","code"],se={bold:{open:"**",close:"**"},italic:{open:"*",close:"*"},strike:{open:"~~",close:"~~"},code:{open:"`",close:"`"}};function ht(e){return ge.includes(e)}function xe(e,s){return s&&s.length>0?{type:"text",text:e,marks:s}:{type:"text",text:e}}function Q(e,s,n){if(!s)return;const t=e[e.length-1],i=JSON.stringify(n??[]),l=JSON.stringify((t==null?void 0:t.marks)??[]);if((t==null?void 0:t.type)==="text"&&i===l){t.text=`${t.text??""}${s}`;return}e.push(xe(s,n))}function O(e,...s){return e.map(n=>{if(n.type!=="text")return n;const t=new Set((n.marks??[]).map(l=>l.type)),i=s.filter(l=>!t.has(l)).map(l=>({type:l}));return{...n,marks:[...n.marks??[],...i]}})}function gt(e){const s=e.match(/^\{\{(agent\.(?:id|name|role|team|description))\}\}$/);return!s||!ht(s[1])?null:{type:"variableMention",attrs:{variable:s[1]}}}function J(e){const s=e.match(/^\{\{\{documents\.([^.\s}]+)\.(content|toc)\}\}\}$/);return s?{type:"documentBlock",attrs:{key:s[1],variant:s[2]}}:null}function xt(e,s){const n=e[s].match(/^<document\b[^>]*>\s*(\{\{\{documents\.([^.\s}]+)\.(content|toc)\}\}\})\s*<\/document>\s*$/);if(n){const m=J(n[1]);if(m)return{node:{type:"paragraph",content:[m]},nextIndex:s+1}}if(!/^<document\b[^>]*>\s*$/.test(e[s]??""))return null;let t=s+1;for(;t<e.length&&(e[t]??"").trim()==="";)t+=1;const l=(e[t]??"").trim();for(t+=1;t<e.length&&(e[t]??"").trim()==="";)t+=1;if((e[t]??"").trim()!=="</document>")return null;const p=J(l);return p?{node:{type:"paragraph",content:[p]},nextIndex:t+1}:null}function W(e,s,n,t){return e.startsWith(s,t)?e.indexOf(n,t+s.length):-1}function bt(e,s){const n=[e.indexOf("{{{documents.",s),e.indexOf("{{agent.",s),e.indexOf("**",s),e.indexOf("~~",s),e.indexOf("`",s),e.indexOf("*",s)].filter(t=>t>=0);return n.length>0?Math.min(...n):-1}function A(e,s=!1){const n=[];let t=0;for(;t<e.length;){const i=W(e,"***","***",t);if(i>t){const o=e.slice(t+3,i);n.push(...O(A(o,s),"bold","italic")),t=i+3;continue}if(!s&&e.startsWith("{{{documents.",t)){const o=e.indexOf("}}}",t);if(o>t){const y=e.slice(t,o+3),b=J(y);if(b){n.push(b),t=o+3;continue}}}if(!s&&e.startsWith("{{agent.",t)){const o=e.indexOf("}}",t);if(o>t){const y=e.slice(t,o+2),b=gt(y);if(b){n.push(b),t=o+2;continue}}}const l=W(e,"**","**",t);if(l>t){const o=e.slice(t+2,l);n.push(...O(A(o,s),"bold")),t=l+2;continue}const c=W(e,"~~","~~",t);if(c>t){const o=e.slice(t+2,c);n.push(...O(A(o,s),"strike")),t=c+2;continue}const p=e[t]==="*"&&!e.startsWith("**",t)?e.indexOf("*",t+1):-1;if(p>t){const o=e.slice(t+1,p);n.push(...O(A(o,s),"italic")),t=p+1;continue}if(e[t]==="`"){const o=e.indexOf("`",t+1);if(o>t){Q(n,e.slice(t+1,o),[{type:"code"}]),t=o+1;continue}}const m=bt(e,t),x=m>=0?m:e.length;if(x===t){Q(n,e[t]),t+=1;continue}Q(n,e.slice(t,x)),t=x}return n}function yt(e){const s=e.split(`
22
+ `),n=[];return s.forEach((t,i)=>{n.push(...A(t)),i<s.length-1&&n.push({type:"hardBreak"})}),{type:"paragraph",content:n}}function ae(e,s){const n=s?"orderedList":"bulletList",t=s?/^\d+\.\s+/:/^[-*]\s+/;return{type:n,content:e.map(i=>({type:"listItem",content:[{type:"paragraph",content:A(i.replace(t,""))}]}))}}function vt(e){return/^#{1,3}\s+/.test(e)||/^```/.test(e)||/^---+$/.test(e)||/^[-*]\s+/.test(e)||/^\d+\.\s+/.test(e)}function kt(e){const s=new Set((e??[]).map(n=>n.type).filter(n=>re.includes(n)));return re.filter(n=>s.has(n))}function wt(e,s){let n=0;for(;n<e.length&&n<s.length&&e[n]===s[n];)n+=1;return n}function oe(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").trim()}function jt(e,s,n){var t,i,l,c;if(e.type==="hardBreak")return`
23
+ `;if(e.type==="variableMention"){const p=String(((t=e.attrs)==null?void 0:t.variable)??"");return s==="preview"?`**{{${p}}}**`:`{{${p}}}`}if(e.type==="documentBlock"){const p=String(((i=e.attrs)==null?void 0:i.key)??""),m=String(((l=e.attrs)==null?void 0:l.variant)??"content"),x=`{{{documents.${p}.${m}}}}`,o=((c=n==null?void 0:n.getDocumentMeta)==null?void 0:c.call(n,p))??{name:p},y=[`name="${oe(o.name)}"`];return o.path&&y.push(`path="${oe(o.path)}"`),y.push(`type="${m}"`),`<document ${y.join(" ")}>
24
+
25
+ ${x}
26
+
27
+ </document>`}return I(e.content,s,n)}function I(e,s,n){let t="",i=[];const l=c=>{const p=wt(i,c);for(let m=i.length-1;m>=p;m-=1)t+=se[i[m]].close;for(let m=p;m<c.length;m+=1)t+=se[c[m]].open;i=c};for(const c of e??[]){if(c.type==="text"){l(kt(c.marks)),t+=c.text??"";continue}l([]),t+=jt(c,s,n)}return l([]),t}function U(e){const s=e.replace(/\r\n?/g,`
28
+ `);if(!s.trim())return{type:"doc",content:[]};const n=s.split(`
29
+ `),t=[];let i=0;for(;i<n.length;){const l=n[i];if(!l.trim()){i+=1;continue}const c=xt(n,i);if(c){t.push(c.node),i=c.nextIndex;continue}const p=l.match(/^```(\S+)?\s*$/);if(p){const o=p[1]??null,y=[];for(i+=1;i<n.length&&!/^```/.test(n[i]);)y.push(n[i]),i+=1;i<n.length&&(i+=1),t.push({type:"codeBlock",attrs:o?{language:o}:{},content:[xe(y.join(`
30
+ `))]});continue}const m=l.match(/^(#{1,3})\s+(.*)$/);if(m){t.push({type:"heading",attrs:{level:m[1].length},content:A(m[2])}),i+=1;continue}if(/^---+$/.test(l)){t.push({type:"horizontalRule"}),i+=1;continue}if(/^[-*]\s+/.test(l)){const o=[];for(;i<n.length&&/^[-*]\s+/.test(n[i]);)o.push(n[i]),i+=1;t.push(ae(o,!1));continue}if(/^\d+\.\s+/.test(l)){const o=[];for(;i<n.length&&/^\d+\.\s+/.test(n[i]);)o.push(n[i]),i+=1;t.push(ae(o,!0));continue}const x=[l];for(i+=1;i<n.length&&n[i].trim()&&!vt(n[i]);)x.push(n[i]),i+=1;t.push(yt(x.join(`
31
+ `)))}return{type:"doc",content:t}}function Nt(e,s,n){var t,i,l,c;switch(e.type){case"heading":{const p=Number(((t=e.attrs)==null?void 0:t.level)??1);return`${"#".repeat(Math.max(1,Math.min(3,p)))} ${I(e.content,s,n)}`}case"bulletList":return(e.content??[]).map(p=>{var m,x;return`- ${I((x=(m=p.content)==null?void 0:m[0])==null?void 0:x.content,s,n)}`}).join(`
32
+ `);case"orderedList":return(e.content??[]).map((p,m)=>{var x,o;return`${m+1}. ${I((o=(x=p.content)==null?void 0:x[0])==null?void 0:o.content,s,n)}`}).join(`
33
+ `);case"codeBlock":{const p=typeof((i=e.attrs)==null?void 0:i.language)=="string"?e.attrs.language:"",m=((c=(l=e.content)==null?void 0:l[0])==null?void 0:c.text)??"";return`\`\`\`${p}
34
+ ${m}
35
+ \`\`\``}case"horizontalRule":return"---";case"paragraph":return I(e.content,s,n);default:return I(e.content,s,n)}}function ie(e,s){return(e.content??[]).map(n=>Nt(n,"hbs",s)).join(`
36
+
37
+ `)}function Ct(e){return/\{\{agent\.(?:id|name|role|team|description)\}\}|\{\{\{documents\.[^.\s}]+\.(?:content|toc)\}\}\}|<document\b[^>]*>/.test(e)}function Lt(e,s){return{type:"documentBlock",attrs:{key:e,variant:s}}}function le(e){return{type:"variableMention",attrs:{variable:e}}}function q(e){return!e.isActive("codeBlock")&&!e.isActive("code")}function ce(e,s,n){return q(e)?it(e,s,n)?!1:(e.chain().focus().insertContent(Lt(s,n)).run(),!0):(e.chain().focus().insertContent(`{{{documents.${s}.${n}}}}`).run(),!0)}const _t=u.forwardRef(function({value:s,onChange:n,documents:t,documentsLoading:i,documentsError:l,documentsUnavailable:c,onPreview:p,onRefetchDocuments:m},x){const{t:o}=B(),y=u.useRef(null),b=u.useMemo(()=>({content:o("agent.prompt.variantContent"),toc:o("agent.prompt.variantToc")}),[o]),k=u.useMemo(()=>a=>{var C;const j=t.find(D=>D.key===a);if((j==null?void 0:j.type)==="file"&&j.path){const D=j.path.split("/").filter(Boolean);return{name:D[D.length-1]??a,path:j.path}}return{name:((C=j==null?void 0:j.summary)==null?void 0:C.trim())||a}},[t]),w=u.useMemo(()=>[{key:"headings",buttons:[{key:"h1",label:o("agent.prompt.toolbar.h1"),icon:Ae,shortcut:"Cmd+Alt+1",action:a=>{a.chain().focus().toggleHeading({level:1}).run()},isActive:a=>a.isActive("heading",{level:1})},{key:"h2",label:o("agent.prompt.toolbar.h2"),icon:$e,shortcut:"Cmd+Alt+2",action:a=>{a.chain().focus().toggleHeading({level:2}).run()},isActive:a=>a.isActive("heading",{level:2})},{key:"h3",label:o("agent.prompt.toolbar.h3"),icon:Te,shortcut:"Cmd+Alt+3",action:a=>{a.chain().focus().toggleHeading({level:3}).run()},isActive:a=>a.isActive("heading",{level:3})}]},{key:"text",buttons:[{key:"bold",label:o("agent.prompt.toolbar.bold"),icon:Ie,shortcut:"Cmd+B",action:a=>{a.chain().focus().toggleBold().run()},isActive:a=>a.isActive("bold")},{key:"italic",label:o("agent.prompt.toolbar.italic"),icon:Pe,shortcut:"Cmd+I",action:a=>{a.chain().focus().toggleItalic().run()},isActive:a=>a.isActive("italic")},{key:"strike",label:o("agent.prompt.toolbar.strike"),icon:Re,shortcut:"Cmd+Shift+S",action:a=>{a.chain().focus().toggleStrike().run()},isActive:a=>a.isActive("strike")}]},{key:"lists",buttons:[{key:"bulletList",label:o("agent.prompt.toolbar.bulletList"),icon:Be,shortcut:"Cmd+Shift+8",action:a=>{a.chain().focus().toggleBulletList().run()},isActive:a=>a.isActive("bulletList")},{key:"orderedList",label:o("agent.prompt.toolbar.orderedList"),icon:ze,shortcut:"Cmd+Shift+7",action:a=>{a.chain().focus().toggleOrderedList().run()},isActive:a=>a.isActive("orderedList")},{key:"blockquote",label:o("agent.prompt.toolbar.blockquote"),icon:Oe,shortcut:"Cmd+Shift+B",action:a=>{a.chain().focus().toggleBlockquote().run()},isActive:a=>a.isActive("blockquote")}]},{key:"code",buttons:[{key:"code",label:o("agent.prompt.toolbar.code"),icon:qe,shortcut:"Cmd+E",action:a=>{a.chain().focus().toggleCode().run()},isActive:a=>a.isActive("code")},{key:"codeBlock",label:o("agent.prompt.toolbar.codeBlock"),icon:Ve,shortcut:"Cmd+Alt+C",action:a=>{a.chain().focus().toggleCodeBlock().run()},isActive:a=>a.isActive("codeBlock")},{key:"horizontalRule",label:o("agent.prompt.toolbar.horizontalRule"),icon:Fe,shortcut:"Cmd+Alt+-",action:a=>{a.chain().focus().setHorizontalRule().run()}}]},{key:"history",buttons:[{key:"undo",label:o("agent.prompt.toolbar.undo"),icon:He,shortcut:"Cmd+Z",action:a=>{a.chain().focus().undo().run()},isDisabled:a=>!a.can().chain().focus().undo().run()},{key:"redo",label:o("agent.prompt.toolbar.redo"),icon:Ke,shortcut:"Cmd+Shift+Z",action:a=>{a.chain().focus().redo().run()},isDisabled:a=>!a.can().chain().focus().redo().run()}]}],[o]),h=Qe({immediatelyRender:!1,extensions:[We.configure({heading:{levels:[1,2,3]}}),Ue.configure({placeholder:o("agent.prompt.placeholder")}),ft.configure({HTMLAttributes:{class:"inline-flex items-center rounded-full bg-blue-500 px-2 py-0.5 text-xs font-semibold text-white"}}),mt.configure({getVariantLabel:a=>a==="toc"?b.toc:b.content}),pe.create({name:"fallbackInline",inline:!0,group:"inline"})],content:U(s),editorProps:{attributes:{class:lt,"data-testid":"prompt-editor-content","aria-label":o("agent.prompt.editorLabel"),role:"textbox"}},onUpdate({editor:a}){const j=ie(a.getJSON(),{getDocumentMeta:k});y.current=j,n(j)}}),d=Xe({editor:h,selector:({editor:a})=>a?{active:{h1:a.isActive("heading",{level:1}),h2:a.isActive("heading",{level:2}),h3:a.isActive("heading",{level:3}),bold:a.isActive("bold"),italic:a.isActive("italic"),strike:a.isActive("strike"),bulletList:a.isActive("bulletList"),orderedList:a.isActive("orderedList"),blockquote:a.isActive("blockquote"),code:a.isActive("code"),codeBlock:a.isActive("codeBlock")},disabled:{undo:!a.can().chain().focus().undo().run(),redo:!a.can().chain().focus().redo().run()}}:{active:{},disabled:{}}}),g=u.useMemo(()=>ge.map(a=>({label:a,actions:[{label:o("agent.prompt.toolbar.insert"),onClick:()=>{if(h){if(q(h)){h.chain().focus().insertContent(le(a)).run();return}h.chain().focus().insertContent(`{{${a}}}`).run()}}}]})),[h,o]);u.useEffect(()=>{if(!h)return;const a=ie(h.getJSON(),{getDocumentMeta:k});s===a||s===y.current||(h.commands.setContent(U(s)),y.current=s)},[h,k,s]),u.useImperativeHandle(x,()=>({insertVariable(a){if(h){if(q(h)){h.chain().focus().insertContent(le(a)).run();return}h.chain().focus().insertContent(`{{${a}}}`).run()}},insertDocumentBlock(a,j){return h?ce(h,a,j):!1},selectAll(){h==null||h.chain().focus().selectAll().run()}}),[h]);const v=a=>{if(!h||!q(h))return;const j=a.clipboardData.getData("text/plain");if(!j||!Ct(j))return;a.preventDefault();const C=U(j);h.chain().focus().insertContent(C.content??[]).run()},_=a=>`${a.label} (${a.shortcut})`,M=(a,j)=>h?ce(h,a,j):!1;return r.jsxs("section",{className:"rounded-xl border border-gray-200 bg-gray-50 p-4 shadow-sm",children:[r.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2 rounded-xl border border-gray-200 bg-white p-2 shadow-sm",children:[w.map((a,j)=>r.jsxs("div",{className:"flex items-center gap-1",children:[j>0?r.jsx("div",{className:"mx-1 h-6 border-l border-gray-300","aria-hidden":"true"}):null,a.buttons.map(C=>{var T;const D=_(C),E=(d==null?void 0:d.active[C.key])??!1,$=h?(((T=C.isDisabled)==null?void 0:T.call(C,h))??!1)||((d==null?void 0:d.disabled[C.key])??!1):!0,z=C.icon;return r.jsx("button",{type:"button",title:D,"aria-label":D,"data-testid":`prompt-toolbar-${C.key}`,disabled:$,onClick:()=>h&&C.action(h),className:`flex h-8 w-8 items-center justify-center rounded-md transition-colors ${E?"bg-gray-200 text-gray-900":"text-gray-600 hover:bg-gray-100 hover:text-gray-900"} ${$?"cursor-not-allowed opacity-40":""}`,children:r.jsx(z,{className:"h-4 w-4"})},C.key)})]},a.key)),r.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:[r.jsx("div",{className:"mx-1 h-6 border-l border-gray-300","aria-hidden":"true"}),r.jsx(dt,{trigger:r.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[r.jsx(Ye,{className:"h-4 w-4"}),r.jsx("span",{children:o("agent.prompt.toolbar.variable")})]}),items:g,emptyLabel:o("agent.prompt.toolbar.empty")}),r.jsx(ut,{documents:t,documentsLoading:i,documentsError:l,documentsUnavailable:c,onInsertDocument:M,onRefetchDocuments:m}),r.jsx("button",{type:"button",title:`${o("agent.prompt.preview.button")} (Cmd+P)`,"aria-label":`${o("agent.prompt.preview.button")} (Cmd+P)`,"data-testid":"prompt-toolbar-preview",onClick:p,className:"flex h-8 w-8 items-center justify-center rounded-md text-gray-600 transition-colors hover:bg-gray-100 hover:text-gray-900",children:r.jsx(tt,{className:"h-4 w-4"})})]})]}),r.jsx("div",{"data-testid":"prompt-editor",onPaste:v,children:r.jsx(Je,{editor:h})})]})});function St({previewAgentId:e=null}){const{t:s}=B(),n=Ge(g=>g.currentWorkspaceId),t=Y(g=>g.form),i=Y(g=>g.setField),[l,c]=u.useState([]),[p,m]=u.useState(!0),[x,o]=u.useState(null),[y,b]=u.useState(!1),[k,w]=u.useState(!1),h=u.useMemo(()=>{const g=ot(t);return{template:t.prompt,...e?{agentId:e}:{},context:{agent:g}}},[t,e]),d=u.useCallback(async()=>{m(!0),o(null),b(!1);try{const g=await V.getDocuments();c(g.documents)}catch(g){if(fe(g)){c([]),b(!0);return}o(g instanceof Error?g.message:s("agent.prompt.documentInsertError"))}finally{m(!1)}},[s]);return u.useEffect(()=>{d()},[n,d]),u.useEffect(()=>{const g=v=>{!(v.metaKey||v.ctrlKey)||v.key.toLowerCase()!=="p"||(v.preventDefault(),w(!0))};return window.addEventListener("keydown",g),()=>{window.removeEventListener("keydown",g)}},[]),r.jsxs("div",{className:"space-y-5",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-base font-semibold text-gray-900",children:s("agent.section.promptTitle")}),r.jsx("p",{className:"mt-1 text-sm text-gray-500",children:s("agent.section.promptDescription")})]}),r.jsx("div",{className:"grid grid-cols-1 gap-5",children:r.jsx(_t,{value:t.prompt,onChange:g=>i("prompt",g),documents:l,documentsLoading:p,documentsError:x,documentsUnavailable:y,onPreview:()=>w(!0),onRefetchDocuments:()=>void d()})}),r.jsx(ct,{open:k,request:h,onClose:()=>w(!1)})]})}export{St as default};
@@ -0,0 +1 @@
1
+ import{$ as ln,a0 as an,a1 as y,a2 as tn,a3 as G,a4 as q,a5 as _,a6 as un,a7 as rn,a8 as K,a9 as o,aa as z,ab as sn,ac as on,ad as fn}from"./main-Bj-Sews0.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,B,a){var O=I-l,i=D-h,n=B-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function V(l,h,I,D,v,A,B){var a=l-I,O=h-D,i=(B?A:-A)/K(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,C=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*K(fn(0,T*T*R-P*P)),$=(P*g-m*S)/R,j=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=$-C,e=j-t,r=w-C,F=p-t;return x*x+e*e>r*r+F*F&&($=w,j=p),{cx:$,cy:j,x01:-n,y01:-d,x11:$*(v/T-1),y11:j*(v/T-1)}}function hn(){var l=cn,h=yn,I=z(0),D=null,v=gn,A=dn,B=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-an,c=A.apply(this,arguments)-an,C=un(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(C>tn-y)a.moveTo(s*G(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*G(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=C,S=C,$=B.apply(this,arguments)/2,j=$>y&&(D?+D.apply(this,arguments):K(u*u+s*s)),w=_(un(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if(j>y){var F=sn(j/u*q($)),L=sn(j/s*q($));(P-=F*2)>y?(F*=t?1:-1,R+=F,T-=F):(P=0,R=T=(f+c)/2),(S-=L*2)>y?(L*=t?1:-1,m+=L,g-=L):(S=0,m=g=(f+c)/2)}var H=s*G(m),J=s*q(m),M=u*G(T),N=u*q(T);if(w>y){var Q=s*G(g),U=s*q(g),W=u*G(R),X=u*q(R),E;if(C<rn)if(E=pn(H,J,W,X,Q,U,M,N)){var Y=H-E[0],Z=J-E[1],b=Q-E[0],k=U-E[1],nn=1/q(on((Y*b+Z*k)/(K(Y*Y+Z*Z)*K(b*b+k*k)))/2),en=K(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=V(W,X,H,J,s,x,t),r=V(Q,U,M,N,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(H,J),a.arc(0,0,s,m,g,!t)):a.moveTo(H,J),!(u>y)||!(P>y)?a.lineTo(M,N):p>y?(e=V(M,N,Q,U,u,-p,t),r=V(H,J,W,X,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-rn/2;return[G(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:z(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:z(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:z(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:z(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:z(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:z(+n),i):A},i.padAngle=function(n){return arguments.length?(B=typeof n=="function"?n:z(+n),i):B},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};