crewx 0.8.6-rc.4 → 0.8.6-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/crewx-lib.js +0 -77
- package/bin/crewx.js +55 -41
- package/dist/assets/{MarketPage-CoCR1dCg.js → MarketPage-mVKZxAhV.js} +4 -4
- package/dist/assets/{PromptTab-CX3T_kO-.js → PromptTab-CHZVcQ0-.js} +4 -4
- package/dist/assets/{_baseUniq-DoJ1HHWx.js → _baseUniq-Db1u033g.js} +1 -1
- package/dist/assets/arc-DvfI2u44.js +1 -0
- package/dist/assets/architectureDiagram-UYN6MBPD-DLBgy7Pv.js +36 -0
- package/dist/assets/blockDiagram-ZHA2E4KO-BRtXBq3c.js +121 -0
- package/dist/assets/c4Diagram-6F5ED5ID-iHz_3Ous.js +10 -0
- package/dist/assets/channel-B6fPa9rF.js +1 -0
- package/dist/assets/chunk-5HRBRIJM-Dvamw7fs.js +1 -0
- package/dist/assets/chunk-7U56Z5CX-Cu_JH-RY.js +220 -0
- package/dist/assets/chunk-ASOPGD6M-6px_k6Np.js +1 -0
- package/dist/assets/{chunk-QZHKN3VN-C4dk7jd_.js → chunk-KFBOBJHC-DLGOlW0g.js} +1 -1
- package/dist/assets/chunk-T2TOU4HS-D30qMJj9.js +164 -0
- package/dist/assets/{chunk-4BX2VUAB-BBHyCswj.js → chunk-TMUBEWPD-Drcfx8Gk.js} +1 -1
- package/dist/assets/classDiagram-LNE6IOMH-V5r85D9M.js +1 -0
- package/dist/assets/classDiagram-v2-MQ7JQ4JX-V5r85D9M.js +1 -0
- package/dist/assets/clone-DA0G-j1Y.js +1 -0
- package/dist/assets/{dagre-KV5264BT-CrdKSic2.js → dagre-4EVJKHTY-DMUzQU_t.js} +3 -3
- package/dist/assets/diagram-QW4FP2JN-DxehNWAY.js +24 -0
- package/dist/assets/erDiagram-6RL3IURR-snPgs7kz.js +51 -0
- package/dist/assets/flowDiagram-7ASYPVHJ-DKbBapLU.js +160 -0
- package/dist/assets/ganttDiagram-NTVNEXSI-CEcJRPl_.js +257 -0
- package/dist/assets/gitGraph-YCYPL57B-CdEdvjry.js +133 -0
- package/dist/assets/gitGraphDiagram-NRZ2UAAF-DTulb7Ly.js +65 -0
- package/dist/assets/{graph-BpzhcyLY.js → graph-D9ElhIkL.js} +1 -1
- package/dist/assets/infoDiagram-A4XQUW5V-CQfyXyRH.js +2 -0
- package/dist/assets/journeyDiagram-G5WM74LC-CZHCM3j3.js +139 -0
- package/dist/assets/{kanban-definition-6JOO6SKY-DDkk2pi4.js → kanban-definition-QRCXZQQD-Dgpn6JHA.js} +9 -10
- package/dist/assets/{layout-DR2RX63p.js → layout-mj1X2Ybo.js} +1 -1
- package/dist/assets/linear-CsJv5BvN.js +1 -0
- package/dist/assets/main-D83eZdBk.js +1064 -0
- package/dist/assets/main-q38TAmrV.css +10 -0
- package/dist/assets/min-CaqYNmLk.js +1 -0
- package/dist/assets/mindmap-definition-GWI6TPTV-Ddc-wr24.js +95 -0
- package/dist/assets/pieDiagram-YF2LJOPJ-iFWXxfMM.js +30 -0
- package/dist/assets/{quadrantDiagram-34T5L4WZ-CzpNqHz9.js → quadrantDiagram-OS5C2QUG-BfnCmQHo.js} +4 -4
- package/dist/assets/requirementDiagram-MIRIMTAZ-BCwCsU93.js +52 -0
- package/dist/assets/{sankeyDiagram-XADWPNL6-DEdEaxaO.js → sankeyDiagram-Y46BX6SQ-BI0jILV9.js} +7 -9
- package/dist/assets/sequenceDiagram-G6AWOVSC-CVHmaxGU.js +122 -0
- package/dist/assets/stateDiagram-MAYHULR4-9teeMOYD.js +1 -0
- package/dist/assets/stateDiagram-v2-4JROLMXI-zpa2BPhE.js +1 -0
- package/dist/assets/timeline-definition-U7ZMHBDA-DPP6BzEU.js +61 -0
- package/dist/assets/xychartDiagram-6QU3TZC5-D6e0Gp3a.js +7 -0
- package/dist/index.html +2 -2
- package/dist-server/adapters/adapter.service.js +7 -17
- package/dist-server/adapters/http-router.service.js +2 -2
- package/dist-server/app.module.js +1 -0
- package/dist-server/bootstrap/crewx-server.js +2 -1
- package/dist-server/bootstrap/tls.js +2 -2
- package/dist-server/common/cors.js +2 -1
- package/dist-server/common/interceptor/http-logging.interceptor.js +1 -1
- package/dist-server/common/middleware/workspace.middleware.js +7 -17
- package/dist-server/common/workspace-context.store.js +3 -3
- package/dist-server/domain/agent/agent.service.js +13 -2
- package/dist-server/domain/auth/session-store.js +4 -3
- package/dist-server/domain/auth/utils/ip.utils.js +5 -4
- package/dist-server/domain/cli/cli.controller.js +48 -0
- package/dist-server/domain/cli/cli.service.js +139 -38
- package/dist-server/domain/cli/dto/login-cli.dto.js +25 -0
- package/dist-server/domain/fs/fs.service.js +7 -17
- package/dist-server/domain/git/git.service.js +7 -17
- package/dist-server/domain/mcp/crewx-tool.factory.js +2 -1
- package/dist-server/domain/mcp/tool-router.service.js +5 -5
- package/dist-server/domain/skill/skill.service.js +7 -17
- package/dist-server/domain/usage/usage.service.js +7 -17
- package/dist-server/domain/workflow/workflow.service.js +7 -17
- package/dist-server/domain/workspace/workspace.service.js +7 -17
- package/dist-server/main.js +7 -17
- package/dist-server/package.json +3 -0
- package/dist-server/shared/crewx-home.js +9 -18
- package/dist-server/shared/crewx-state.js +10 -19
- package/dist-server/utils/tokenizer.js +2 -1
- package/package.json +120 -119
- package/packages/cli/dist/commands/execute.js +1 -0
- package/packages/cli/dist/commands/query.js +1 -0
- package/packages/cli/dist/commands/slack.js +1 -1
- package/packages/cli/dist/main.js +3 -6
- package/packages/cli/dist/slack/file-download.js +1 -1
- package/packages/cli/package.json +5 -5
- package/dist/assets/arc-t5HebXb5.js +0 -1
- package/dist/assets/architectureDiagram-Q4EWVU46-BrSDq1JQ.js +0 -36
- package/dist/assets/blockDiagram-DXYQGD6D-BG0JNT6z.js +0 -132
- package/dist/assets/c4Diagram-AHTNJAMY-BOqLqa3J.js +0 -10
- package/dist/assets/channel-CEB3zo90.js +0 -1
- package/dist/assets/chunk-4TB4RGXK-C5-asTsp.js +0 -206
- package/dist/assets/chunk-55IACEB6-0OYgffGZ.js +0 -1
- package/dist/assets/chunk-EDXVE4YY-BvS4WeNv.js +0 -1
- package/dist/assets/chunk-FMBD7UC4-BUZZ5ZG5.js +0 -15
- package/dist/assets/chunk-OYMX7WX6-BD3Ms2oI.js +0 -231
- package/dist/assets/chunk-YZCP3GAM-Ce9RY9B4.js +0 -1
- package/dist/assets/classDiagram-6PBFFD2Q-aFvMKrtn.js +0 -1
- package/dist/assets/classDiagram-v2-HSJHXN6E-aFvMKrtn.js +0 -1
- package/dist/assets/clone-C-cMw_b1.js +0 -1
- package/dist/assets/cose-bilkent-S5V4N54A-D_EdvpCz.js +0 -1
- package/dist/assets/defaultLocale-DX6XiGOO.js +0 -1
- package/dist/assets/diagram-5BDNPKRD-CvKlLSOF.js +0 -10
- package/dist/assets/diagram-G4DWMVQ6-C7w3ovOF.js +0 -24
- package/dist/assets/diagram-MMDJMWI5-CQB0s4BI.js +0 -43
- package/dist/assets/diagram-TYMM5635-DFwxw9PV.js +0 -24
- package/dist/assets/erDiagram-SMLLAGMA-D_43jyaU.js +0 -85
- package/dist/assets/flowDiagram-DWJPFMVM-B6ETX3HO.js +0 -162
- package/dist/assets/ganttDiagram-T4ZO3ILL-DMMgqlrx.js +0 -292
- package/dist/assets/gitGraphDiagram-UUTBAWPF-BliZXVbG.js +0 -106
- package/dist/assets/infoDiagram-42DDH7IO-CiIf42kM.js +0 -2
- package/dist/assets/ishikawaDiagram-UXIWVN3A-D4KNwqjV.js +0 -70
- package/dist/assets/journeyDiagram-VCZTEJTY-D5KyHoNR.js +0 -139
- package/dist/assets/linear-DhaHLG7O.js +0 -1
- package/dist/assets/main-Cg4sg9yR.css +0 -10
- package/dist/assets/main-CxlpSzil.js +0 -1172
- package/dist/assets/min-Bg9B8ATt.js +0 -1
- package/dist/assets/mindmap-definition-QFDTVHPH-CMFaK3VU.js +0 -96
- package/dist/assets/pieDiagram-DEJITSTG-D4px3qAh.js +0 -30
- package/dist/assets/requirementDiagram-MS252O5E-BjbJXwco.js +0 -84
- package/dist/assets/sequenceDiagram-FGHM5R23-BOdpoApq.js +0 -157
- package/dist/assets/stateDiagram-FHFEXIEX-BdG-qjkB.js +0 -1
- package/dist/assets/stateDiagram-v2-QKLJ7IA2-DFwoxvPZ.js +0 -1
- package/dist/assets/timeline-definition-GMOUNBTQ-C9gA4zUg.js +0 -120
- package/dist/assets/vennDiagram-DHZGUBPP-DPC4_X3Z.js +0 -34
- package/dist/assets/wardley-RL74JXVD-zu57xGLd.js +0 -162
- package/dist/assets/wardleyDiagram-NUSXRM2D-CIcOsOyi.js +0 -20
- package/dist/assets/xychartDiagram-5P7HB3ND-yn2jMJNf.js +0 -7
package/bin/crewx-lib.js
CHANGED
|
@@ -7,83 +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
|
-
let https = false;
|
|
23
|
-
let trust = false;
|
|
24
|
-
|
|
25
|
-
const consumed = new Set();
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < args.length; i++) {
|
|
28
|
-
const arg = args[i];
|
|
29
|
-
|
|
30
|
-
if (arg === '--port') {
|
|
31
|
-
const val = Number(args[i + 1]);
|
|
32
|
-
if (!val || val < 1 || val > 65535) {
|
|
33
|
-
return { error: 'Invalid port number. Use 1-65535.' };
|
|
34
|
-
}
|
|
35
|
-
port = val;
|
|
36
|
-
consumed.add(i);
|
|
37
|
-
consumed.add(i + 1);
|
|
38
|
-
i++;
|
|
39
|
-
} else if (arg?.startsWith('--port=')) {
|
|
40
|
-
const val = Number(arg.slice('--port='.length));
|
|
41
|
-
if (!val || val < 1 || val > 65535) {
|
|
42
|
-
return { error: 'Invalid port number. Use 1-65535.' };
|
|
43
|
-
}
|
|
44
|
-
port = val;
|
|
45
|
-
consumed.add(i);
|
|
46
|
-
} else if (arg === '--token') {
|
|
47
|
-
token = args[i + 1];
|
|
48
|
-
consumed.add(i);
|
|
49
|
-
consumed.add(i + 1);
|
|
50
|
-
i++;
|
|
51
|
-
} else if (arg?.startsWith('--token=')) {
|
|
52
|
-
token = arg.slice('--token='.length);
|
|
53
|
-
consumed.add(i);
|
|
54
|
-
} else if (arg === '--token-file') {
|
|
55
|
-
tokenFile = args[i + 1];
|
|
56
|
-
consumed.add(i);
|
|
57
|
-
consumed.add(i + 1);
|
|
58
|
-
i++;
|
|
59
|
-
} else if (arg?.startsWith('--token-file=')) {
|
|
60
|
-
tokenFile = arg.slice('--token-file='.length);
|
|
61
|
-
consumed.add(i);
|
|
62
|
-
} else if (arg === '--no-open') {
|
|
63
|
-
noOpen = true;
|
|
64
|
-
consumed.add(i);
|
|
65
|
-
} else if (arg === '--https') {
|
|
66
|
-
https = true;
|
|
67
|
-
consumed.add(i);
|
|
68
|
-
} else if (arg === '--trust') {
|
|
69
|
-
trust = true;
|
|
70
|
-
consumed.add(i);
|
|
71
|
-
} else if (arg === '--help' || arg === '-h') {
|
|
72
|
-
return { help: true };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Strict: reject unconsumed --xxx flags
|
|
77
|
-
for (let i = 0; i < args.length; i++) {
|
|
78
|
-
if (consumed.has(i)) continue;
|
|
79
|
-
const arg = args[i];
|
|
80
|
-
if (arg?.startsWith('--')) {
|
|
81
|
-
return { error: `Unknown option for "crewx serve": ${arg}` };
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return { port, token, tokenFile, noOpen, https, trust };
|
|
86
|
-
}
|
|
87
10
|
|
|
88
11
|
/**
|
|
89
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 {
|
|
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,10 +71,10 @@ function launchElectron(entryFile, routeArgs = []) {
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
|
-
* Launch the web server with
|
|
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(
|
|
77
|
+
function launchWeb({ port, token, tokenFile, open: openFlag, https, trust } = {}) {
|
|
75
78
|
// Ensure ~/.crewx/ directory and tasks schema before spawning the NestJS server.
|
|
76
79
|
// Schema owner = CLI; launcher is the enforcement point so the server can assume DB exists.
|
|
77
80
|
const require = createRequire(import.meta.url);
|
|
@@ -85,45 +88,12 @@ function launchWeb(serveArgs = [], { openBrowser = false } = {}) {
|
|
|
85
88
|
|
|
86
89
|
const serverScript = join(__dirname, '..', 'server.js');
|
|
87
90
|
|
|
88
|
-
const
|
|
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
|
-
' --https Enable HTTPS with auto-generated certificate\n' +
|
|
98
|
-
' --trust Install CA to system trust store (requires --https)\n' +
|
|
99
|
-
' --no-open Do not open browser automatically\n' +
|
|
100
|
-
' --help, -h Show this help\n',
|
|
101
|
-
);
|
|
102
|
-
process.exit(0);
|
|
103
|
-
}
|
|
104
|
-
if (flagsResult.error) {
|
|
105
|
-
console.error(`❌ ${flagsResult.error}`);
|
|
106
|
-
if (flagsResult.error.startsWith('Unknown option')) {
|
|
107
|
-
process.stderr.write(
|
|
108
|
-
' Did you mean: crewx serve --port <N>\n' +
|
|
109
|
-
' Run `crewx serve --help` for usage.\n',
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
process.exit(flagsResult.error.startsWith('Unknown option') ? 2 : 1);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const { port, token, tokenFile, noOpen, https, trust } = flagsResult;
|
|
116
|
-
|
|
117
|
-
const env = { ...process.env, NODE_ENV: 'production' }; // Force production — prevents users from bypassing FREE limits via env
|
|
91
|
+
const env = { ...process.env, NODE_ENV: 'production' };
|
|
118
92
|
|
|
119
93
|
if (https) {
|
|
120
94
|
env.CREWX_HTTPS = 'true';
|
|
121
95
|
}
|
|
122
96
|
if (trust) {
|
|
123
|
-
if (!https) {
|
|
124
|
-
console.error('❌ --trust requires --https');
|
|
125
|
-
process.exit(1);
|
|
126
|
-
}
|
|
127
97
|
env.CREWX_TRUST_CA = 'true';
|
|
128
98
|
}
|
|
129
99
|
|
|
@@ -165,7 +135,7 @@ function launchWeb(serveArgs = [], { openBrowser = false } = {}) {
|
|
|
165
135
|
}
|
|
166
136
|
}
|
|
167
137
|
|
|
168
|
-
if (
|
|
138
|
+
if (openFlag) {
|
|
169
139
|
env.CREWX_OPEN_BROWSER = '1';
|
|
170
140
|
}
|
|
171
141
|
|
|
@@ -183,6 +153,51 @@ function launchWeb(serveArgs = [], { openBrowser = false } = {}) {
|
|
|
183
153
|
});
|
|
184
154
|
}
|
|
185
155
|
|
|
156
|
+
const serveCommand = defineCommand({
|
|
157
|
+
meta: { name: 'serve', description: 'Launch CrewX web server' },
|
|
158
|
+
args: {
|
|
159
|
+
port: { type: 'string', description: 'Port to listen on' },
|
|
160
|
+
token: { type: 'string', description: 'MCP bearer token' },
|
|
161
|
+
'token-file': { type: 'string', description: 'Read token from file' },
|
|
162
|
+
https: { type: 'boolean', description: 'Enable HTTPS with auto-generated certificate' },
|
|
163
|
+
trust: { type: 'boolean', description: 'Install CA to system trust store (requires --https)' },
|
|
164
|
+
open: { type: 'boolean', description: 'Auto-open browser', default: true },
|
|
165
|
+
help: { type: 'boolean', alias: 'h', description: 'Show this help' },
|
|
166
|
+
},
|
|
167
|
+
async run({ args }) {
|
|
168
|
+
if (args.help) {
|
|
169
|
+
const usage = await renderUsage(serveCommand);
|
|
170
|
+
process.stdout.write(usage + '\n');
|
|
171
|
+
process.exit(0);
|
|
172
|
+
}
|
|
173
|
+
const knownArgs = new Set(['_', 'port', 'token', 'token-file', 'tokenFile', 'https', 'trust', 'open', 'help', 'h']);
|
|
174
|
+
for (const key of Object.keys(args)) {
|
|
175
|
+
if (!knownArgs.has(key)) {
|
|
176
|
+
console.error(`❌ Unknown option for "crewx serve": --${key}`);
|
|
177
|
+
console.error(' Run `crewx serve --help` for usage.');
|
|
178
|
+
process.exit(2);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (args.trust && !args.https) {
|
|
182
|
+
console.error('❌ --trust requires --https');
|
|
183
|
+
process.exit(1);
|
|
184
|
+
}
|
|
185
|
+
const port = args.port ? Number(args.port) : undefined;
|
|
186
|
+
if (args.port && (!port || port < 1 || port > 65535)) {
|
|
187
|
+
console.error('❌ Invalid port number. Use 1-65535.');
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
launchWeb({
|
|
191
|
+
port,
|
|
192
|
+
token: args.token,
|
|
193
|
+
tokenFile: args['token-file'],
|
|
194
|
+
open: args.open,
|
|
195
|
+
https: args.https,
|
|
196
|
+
trust: args.trust,
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
|
|
186
201
|
function forwardToCli(cliArgs) {
|
|
187
202
|
const serverScript = join(__dirname, '..', 'server.js');
|
|
188
203
|
const child = spawn(process.execPath, [serverScript, 'cli', ...cliArgs], {
|
|
@@ -206,8 +221,7 @@ const args = process.argv.slice(2);
|
|
|
206
221
|
const { route, routeArgs, error } = resolveRoute(args);
|
|
207
222
|
|
|
208
223
|
if (route === 'serve') {
|
|
209
|
-
|
|
210
|
-
launchWeb(routeArgs, { openBrowser: false });
|
|
224
|
+
runCommand(serveCommand, { rawArgs: routeArgs });
|
|
211
225
|
} else if (route === 'electron') {
|
|
212
226
|
// Electron: desktop (default) or overlay (--overlay flag)
|
|
213
227
|
const isOverlay = routeArgs.includes('--overlay');
|
|
@@ -234,7 +248,7 @@ if (route === 'serve') {
|
|
|
234
248
|
forwardToCli(routeArgs);
|
|
235
249
|
} else if (route === 'web-default') {
|
|
236
250
|
// No arguments → web dashboard + browser auto-open
|
|
237
|
-
|
|
251
|
+
runCommand(serveCommand, { rawArgs: ['--open', ...routeArgs] });
|
|
238
252
|
} else if (route === 'error') {
|
|
239
253
|
// Unknown command or option
|
|
240
254
|
console.error(`❌ ${error}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aJ as v,aK as we,aL as b,aM as k,aN as Se,aO as u,aP as e,aQ as ae,aR as se,aS as G,aT as N,aU as re,aV as Ie,aW as le,aX as U,aY as ze,aZ as Re,a_ as ie,a$ as Ce,b0 as Me}from"./main-D83eZdBk.js";/**
|
|
2
2
|
* @license lucide-react v0.563.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -8,12 +8,12 @@ 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"}]],
|
|
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
|
|
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.
|
|
@@ -33,4 +33,4 @@ 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
|
|
|
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"}]],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 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 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 T([...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=T(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=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: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=T(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 Je(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 Ke({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 Xe({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 Ye({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(Xe,{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=Je(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 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 Ge({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(L,{icon:e.jsx(Oe,{size:14}),label:c("market.detail.stats.stars"),value:ee(t.stars,h.language)}),f&&e.jsx(L,{icon:e.jsx(Re,{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,$]=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:J,uninstallSkill:K,clearError:A}=Ze();u.useEffect(()=>{H||q().catch(()=>{})},[H,q]);const X=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:X}),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,X]);const be=u.useCallback(l=>{const x=l.registryId??E;x&&J(x,l.name).catch(()=>{})},[J,E]),je=u.useCallback(l=>{window.confirm(t("market.actions.confirmUninstall",{name:l}))&&K(l).catch(()=>{})},[t,K]),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),Y=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(G,{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(G,{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))]}),Y.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")}),Y.map(l=>e.jsx(te,{skill:l,selected:(i==null?void 0:i.name)===l.name,onSelect:M},l.name))]})]})})]}),e.jsx(Ge,{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(Ye,{registries:ye,loading:R,deletingRegistryId:ge,onAdd:()=>{c(null),m(""),o(!0)},onClose:()=>r(!1),onDelete:Ne}),n&&e.jsx(Ke,{url:d,error:y,submitting:ue,onChange:m,onClose:()=>{c(null),o(!1)},onSubmit:ve})]})}export{tt as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aJ as V,aM as B,aO as d,aP as r,b1 as ve,aT as J,aY as ke,b2 as we,aL as F,b3 as ce,aS as de,b4 as K,a_ as je,b5 as Ne,b6 as Ce,b7 as Le,aW as _e,b8 as ue,b9 as Se,ba as Ee,bb as De,bc as Me,bd as Ae,be as Te,bf as $e,bg as Ie,bh as Pe,bi as Re,bj as Be,bk as Oe,bl as ze,bm as qe,bn as Fe,bo as Ve,bp as He,bq as Ke,br as We,bs as Ue,bt as Qe,bu as Je,bv as Xe,bw as Y}from"./main-D83eZdBk.js";/**
|
|
2
2
|
* @license lucide-react v0.563.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -18,13 +18,13 @@ import{aO as V,aR as B,aT as d,aU as r,b6 as ve,aY as X,b1 as ke,b7 as we,aQ as
|
|
|
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 rt=[["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"}]],st=V("refresh-ccw",rt);function at(e,s){return(e??"").toLowerCase().includes(s)}function pe(e,s){if(!s)return{nodes:e,autoExpanded:new Set};const n=new Set;return{nodes:e.flatMap(o=>{if(o.type==="file")return at(o.name,s)?[o]:[];const u=pe(o.children??[],s);return u.nodes.length>0?(n.add(o.path),u.autoExpanded.forEach(c=>n.add(c)),[{...o,children:u.nodes}]):[]}),autoExpanded:n}}function me(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(o=>o.type.name==="documentBlock"&&o.attrs.key===s&&o.attrs.variant===n?(t=!0,!1):!t),t}const fe=["[&_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",fe,"[&_.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(),o=d.useRef(null),u=d.useRef(s),[c,p]=d.useState(""),[m,x]=d.useState(!1),[i,y]=d.useState(null),[b,k]=d.useState(!1),w=t("agent.prompt.preview.error");u.current=s;const h=async()=>{var g;if((g=o.current)==null||g.abort(),!u.current.template.trim()){p(""),y(null),k(!1),x(!1);return}const l=new AbortController;o.current=l,x(!0),y(null),k(!1);try{const v=await F.previewPrompt(u.current,{signal:l.signal});if(l.signal.aborted)return;p(v.rendered),y(null),k(!1)}catch(v){if(l.signal.aborted)return;if(me(v)){p(""),y(null),k(!0);return}p(""),k(!1),y(v instanceof Error?v.message:w)}finally{o.current===l&&(o.current=null),x(!1)}};return d.useEffect(()=>{var l;if(!e){(l=o.current)==null||l.abort();return}h()},[e]),d.useEffect(()=>{if(!e)return;const l=g=>{g.key==="Escape"&&(g.preventDefault(),n())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l)}},[n,e]),d.useEffect(()=>()=>{var l;(l=o.current)==null||l.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:l=>l.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(st,{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(ve,{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")}):i?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:i})]}):r.jsx(ke,{content:c,className:fe}):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 l;return void((l=navigator.clipboard)==null?void 0:l.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(we,{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:o}){const u=d.useRef(null),c=d.useRef(null),[p,m]=d.useState(!1),[x,i]=d.useState(""),[y,b]=d.useState(0),k=d.useMemo(()=>{const l=x.trim().toLowerCase();return l?s.filter(g=>g.label.toLowerCase().includes(l)?!0:g.actions.some(v=>v.label.toLowerCase().includes(l))):s},[s,x]),w=d.useMemo(()=>k.flatMap(l=>l.actions.map(g=>({itemLabel:l.label,actionLabel:g.label,onClick:g.onClick}))),[k]);d.useEffect(()=>{var l;if(!p){i(""),b(0);return}n&&((l=c.current)==null||l.focus())},[p,n]),d.useEffect(()=>{y<w.length||b(Math.max(w.length-1,0))},[w.length,y]),d.useEffect(()=>{if(!p)return;const l=v=>{var _;(_=u.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",l),window.addEventListener("keydown",g),()=>{window.removeEventListener("mousedown",l),window.removeEventListener("keydown",g)}},[w,y,p]);let h=-1;return r.jsxs("div",{ref:u,className:"relative",children:[r.jsxs("button",{type:"button",onMouseDown:l=>l.preventDefault(),onClick:()=>m(l=>!l),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(ce,{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(de,{size:14}),r.jsx("input",{ref:c,value:x,onChange:l=>{i(l.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:o??""}):k.map(l=>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:l.label}),l.actions.length>0?r.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:l.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},`${l.label}-${g.label}`)})}):r.jsx("div",{className:"mt-1 text-xs text-gray-500",children:o??l.label})]},l.label))})]}):null]})}function ee(e){return e.replace(/\\/g,"/").replace(/^\.?\//,"")}function te(e,s){return(e??"").toLowerCase().includes(s)}function ut({documents:e,documentsLoading:s,documentsError:n,documentsUnavailable:t,onInsertDocument:o,onRefetchDocuments:u}){const{t:c}=B(),p=d.useRef(null),m=d.useRef(null),[x,i]=d.useState(!1),[y,b]=d.useState(""),[k,w]=d.useState([]),[h,l]=d.useState(!1),[g,v]=d.useState(null),[_,M]=d.useState(new Set),[a,j]=d.useState(!1),[C,D]=d.useState(null);d.useEffect(()=>{var N;if(!x||((N=m.current)==null||N.focus(),k.length>0||h))return;let f=!1;return(async()=>{l(!0),v(null);try{const S=await F.getDocTree();f||w(S)}catch(S){f||v(S instanceof Error?S.message:c("agent.prompt.documentPicker.treeError"))}finally{f||l(!1)}})(),()=>{f=!0}},[x,k.length]),d.useEffect(()=>{x||(b(f=>f&&""),M(f=>f.size>0?new Set:f))},[x]),d.useEffect(()=>{if(!x)return;const f=N=>{var S;(S=p.current)!=null&&S.contains(N.target)||i(!1)},L=N=>{N.key==="Escape"&&(N.preventDefault(),i(!1))};return window.addEventListener("mousedown",f),window.addEventListener("keydown",L),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",L)}},[x]);const E=y.trim().toLowerCase(),$=d.useMemo(()=>e.filter(f=>f.type==="inline"),[e]),z=d.useMemo(()=>{const f=e.filter(L=>L.type==="file"&&L.path);return L=>{const N=ee(L),S=f.find(ye=>ee(ye.path??"")===N);return S==null?void 0:S.key}},[e]),T=d.useMemo(()=>E?$.filter(f=>te(f.key,E)||te(f.summary,E)):$,[$,E]),P=d.useMemo(()=>pe(k,E),[E,k]),xe=d.useMemo(()=>{if(!E)return _;const f=new Set(_);return P.autoExpanded.forEach(L=>f.add(L)),f},[_,P.autoExpanded,E]),H=f=>{o(f,"content"),i(!1)},be=async f=>{D(null);const L=z(f);if(L){H(L);return}try{j(!0);const N=await F.registerDocument({path:f});H(N.key),u==null||u()}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:()=>i(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(ce,{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(de,{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(je,{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(Ne,{nodes:P.nodes,expandedFolders:xe,onToggle:f=>M(L=>{const N=new Set(L);return N.has(f)?N.delete(f):N.add(f),N}),onSelect:f=>{a||be(f)},selectedPath:null,isFileDisabled:()=>a,renderFileSuffix:f=>z(f.path)?r.jsx(nt,{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:o}=B(),u=d.useRef(null),[c,p]=d.useState(!1),m=String(n.attrs.key??""),x=String(n.attrs.variant??"content"),i=s.options.getVariantLabel;d.useEffect(()=>{if(!c)return;const b=w=>{var h;(h=u.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:i("content")},{value:"toc",label:i("toc")}];return r.jsxs(Ce,{as:"span",ref:u,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} · ${i(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(Le,{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(_e,{className:"h-4 w-4"}),r.jsx("span",{children:o("agent.prompt.documentChip.delete")})]})]}):null]})}const mt=ue.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"),o=this.options.getVariantLabel(t);return["span",Se(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} · ${o}`]},addNodeView(){return Ee(pt)}}),ft=De.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??"")]}}),he=["agent.id","agent.name","agent.role","agent.team","agent.description"],ne=["bold","italic","strike","code"],re={bold:{open:"**",close:"**"},italic:{open:"*",close:"*"},strike:{open:"~~",close:"~~"},code:{open:"`",close:"`"}};function ht(e){return he.includes(e)}function ge(e,s){return s&&s.length>0?{type:"text",text:e,marks:s}:{type:"text",text:e}}function U(e,s,n){if(!s)return;const t=e[e.length-1],o=JSON.stringify(n??[]),u=JSON.stringify((t==null?void 0:t.marks)??[]);if((t==null?void 0:t.type)==="text"&&o===u){t.text=`${t.text??""}${s}`;return}e.push(ge(s,n))}function O(e,...s){return e.map(n=>{if(n.type!=="text")return n;const t=new Set((n.marks??[]).map(u=>u.type)),o=s.filter(u=>!t.has(u)).map(u=>({type:u}));return{...n,marks:[...n.marks??[],...o]}})}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 u=(e[t]??"").trim();for(t+=1;t<e.length&&(e[t]??"").trim()==="";)t+=1;if((e[t]??"").trim()!=="</document>")return null;const p=J(u);return p?{node:{type:"paragraph",content:[p]},nextIndex:t+1}:null}function Q(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 o=Q(e,"***","***",t);if(o>t){const i=e.slice(t+3,o);n.push(...O(A(i,s),"bold","italic")),t=o+3;continue}if(!s&&e.startsWith("{{{documents.",t)){const i=e.indexOf("}}}",t);if(i>t){const y=e.slice(t,i+3),b=J(y);if(b){n.push(b),t=i+3;continue}}}if(!s&&e.startsWith("{{agent.",t)){const i=e.indexOf("}}",t);if(i>t){const y=e.slice(t,i+2),b=gt(y);if(b){n.push(b),t=i+2;continue}}}const u=Q(e,"**","**",t);if(u>t){const i=e.slice(t+2,u);n.push(...O(A(i,s),"bold")),t=u+2;continue}const c=Q(e,"~~","~~",t);if(c>t){const i=e.slice(t+2,c);n.push(...O(A(i,s),"strike")),t=c+2;continue}const p=e[t]==="*"&&!e.startsWith("**",t)?e.indexOf("*",t+1):-1;if(p>t){const i=e.slice(t+1,p);n.push(...O(A(i,s),"italic")),t=p+1;continue}if(e[t]==="`"){const i=e.indexOf("`",t+1);if(i>t){U(n,e.slice(t+1,i),[{type:"code"}]),t=i+1;continue}}const m=bt(e,t),x=m>=0?m:e.length;if(x===t){U(n,e[t]),t+=1;continue}U(n,e.slice(t,x)),t=x}return n}function yt(e){const s=e.split(`
|
|
21
|
+
*/const rt=[["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"}]],st=V("refresh-ccw",rt);function at(e,s){return(e??"").toLowerCase().includes(s)}function pe(e,s){if(!s)return{nodes:e,autoExpanded:new Set};const n=new Set;return{nodes:e.flatMap(o=>{if(o.type==="file")return at(o.name,s)?[o]:[];const u=pe(o.children??[],s);return u.nodes.length>0?(n.add(o.path),u.autoExpanded.forEach(c=>n.add(c)),[{...o,children:u.nodes}]):[]}),autoExpanded:n}}function me(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(o=>o.type.name==="documentBlock"&&o.attrs.key===s&&o.attrs.variant===n?(t=!0,!1):!t),t}const fe=["[&_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",fe,"[&_.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(),o=d.useRef(null),u=d.useRef(s),[c,p]=d.useState(""),[m,x]=d.useState(!1),[i,y]=d.useState(null),[b,k]=d.useState(!1),w=t("agent.prompt.preview.error");u.current=s;const h=async()=>{var g;if((g=o.current)==null||g.abort(),!u.current.template.trim()){p(""),y(null),k(!1),x(!1);return}const l=new AbortController;o.current=l,x(!0),y(null),k(!1);try{const v=await F.previewPrompt(u.current,{signal:l.signal});if(l.signal.aborted)return;p(v.rendered),y(null),k(!1)}catch(v){if(l.signal.aborted)return;if(me(v)){p(""),y(null),k(!0);return}p(""),k(!1),y(v instanceof Error?v.message:w)}finally{o.current===l&&(o.current=null),x(!1)}};return d.useEffect(()=>{var l;if(!e){(l=o.current)==null||l.abort();return}h()},[e]),d.useEffect(()=>{if(!e)return;const l=g=>{g.key==="Escape"&&(g.preventDefault(),n())};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l)}},[n,e]),d.useEffect(()=>()=>{var l;(l=o.current)==null||l.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:l=>l.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(st,{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(ve,{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(J,{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")}):i?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:i})]}):r.jsx(ke,{content:c,className:fe}):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 l;return void((l=navigator.clipboard)==null?void 0:l.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(we,{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:o}){const u=d.useRef(null),c=d.useRef(null),[p,m]=d.useState(!1),[x,i]=d.useState(""),[y,b]=d.useState(0),k=d.useMemo(()=>{const l=x.trim().toLowerCase();return l?s.filter(g=>g.label.toLowerCase().includes(l)?!0:g.actions.some(v=>v.label.toLowerCase().includes(l))):s},[s,x]),w=d.useMemo(()=>k.flatMap(l=>l.actions.map(g=>({itemLabel:l.label,actionLabel:g.label,onClick:g.onClick}))),[k]);d.useEffect(()=>{var l;if(!p){i(""),b(0);return}n&&((l=c.current)==null||l.focus())},[p,n]),d.useEffect(()=>{y<w.length||b(Math.max(w.length-1,0))},[w.length,y]),d.useEffect(()=>{if(!p)return;const l=v=>{var _;(_=u.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",l),window.addEventListener("keydown",g),()=>{window.removeEventListener("mousedown",l),window.removeEventListener("keydown",g)}},[w,y,p]);let h=-1;return r.jsxs("div",{ref:u,className:"relative",children:[r.jsxs("button",{type:"button",onMouseDown:l=>l.preventDefault(),onClick:()=>m(l=>!l),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(ce,{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(de,{size:14}),r.jsx("input",{ref:c,value:x,onChange:l=>{i(l.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:o??""}):k.map(l=>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:l.label}),l.actions.length>0?r.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:l.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},`${l.label}-${g.label}`)})}):r.jsx("div",{className:"mt-1 text-xs text-gray-500",children:o??l.label})]},l.label))})]}):null]})}function ee(e){return e.replace(/\\/g,"/").replace(/^\.?\//,"")}function te(e,s){return(e??"").toLowerCase().includes(s)}function ut({documents:e,documentsLoading:s,documentsError:n,documentsUnavailable:t,onInsertDocument:o,onRefetchDocuments:u}){const{t:c}=B(),p=d.useRef(null),m=d.useRef(null),[x,i]=d.useState(!1),[y,b]=d.useState(""),[k,w]=d.useState([]),[h,l]=d.useState(!1),[g,v]=d.useState(null),[_,M]=d.useState(new Set),[a,j]=d.useState(!1),[C,D]=d.useState(null);d.useEffect(()=>{var N;if(!x||((N=m.current)==null||N.focus(),k.length>0||h))return;let f=!1;return(async()=>{l(!0),v(null);try{const E=await F.getDocTree();f||w(E)}catch(E){f||v(E instanceof Error?E.message:c("agent.prompt.documentPicker.treeError"))}finally{f||l(!1)}})(),()=>{f=!0}},[x,k.length]),d.useEffect(()=>{x||(b(f=>f&&""),M(f=>f.size>0?new Set:f))},[x]),d.useEffect(()=>{if(!x)return;const f=N=>{var E;(E=p.current)!=null&&E.contains(N.target)||i(!1)},L=N=>{N.key==="Escape"&&(N.preventDefault(),i(!1))};return window.addEventListener("mousedown",f),window.addEventListener("keydown",L),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",L)}},[x]);const S=y.trim().toLowerCase(),T=d.useMemo(()=>e.filter(f=>f.type==="inline"),[e]),O=d.useMemo(()=>{const f=e.filter(L=>L.type==="file"&&L.path);return L=>{const N=ee(L),E=f.find(ye=>ee(ye.path??"")===N);return E==null?void 0:E.key}},[e]),$=d.useMemo(()=>S?T.filter(f=>te(f.key,S)||te(f.summary,S)):T,[T,S]),P=d.useMemo(()=>pe(k,S),[S,k]),xe=d.useMemo(()=>{if(!S)return _;const f=new Set(_);return P.autoExpanded.forEach(L=>f.add(L)),f},[_,P.autoExpanded,S]),H=f=>{o(f,"content"),i(!1)},be=async f=>{D(null);const L=O(f);if(L){H(L);return}try{j(!0);const N=await F.registerDocument({path:f});H(N.key),u==null||u()}catch(N){D(N instanceof Error?N.message:c("agent.prompt.documentPicker.registerError"))}finally{j(!1)}},G=s||n||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:()=>i(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(ce,{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(de,{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(je,{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")}):$.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:$.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(J,{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(Ne,{nodes:P.nodes,expandedFolders:xe,onToggle:f=>M(L=>{const N=new Set(L);return N.has(f)?N.delete(f):N.add(f),N}),onSelect:f=>{a||be(f)},selectedPath:null,isFileDisabled:()=>a,renderFileSuffix:f=>O(f.path)?r.jsx(nt,{className:"h-3.5 w-3.5 shrink-0 text-blue-500","aria-label":c("agent.prompt.documentPicker.linked")}):a?r.jsx(J,{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:o}=B(),u=d.useRef(null),[c,p]=d.useState(!1),m=String(n.attrs.key??""),x=String(n.attrs.variant??"content"),i=s.options.getVariantLabel;d.useEffect(()=>{if(!c)return;const b=w=>{var h;(h=u.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:i("content")},{value:"toc",label:i("toc")}];return r.jsxs(Ce,{as:"span",ref:u,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} · ${i(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(Le,{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(_e,{className:"h-4 w-4"}),r.jsx("span",{children:o("agent.prompt.documentChip.delete")})]})]}):null]})}const mt=ue.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"),o=this.options.getVariantLabel(t);return["span",Ee(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} · ${o}`]},addNodeView(){return Se(pt)}}),ft=De.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??"")]}}),he=["agent.id","agent.name","agent.role","agent.team","agent.description"],ne=["bold","italic","strike","code"],re={bold:{open:"**",close:"**"},italic:{open:"*",close:"*"},strike:{open:"~~",close:"~~"},code:{open:"`",close:"`"}};function ht(e){return he.includes(e)}function ge(e,s){return s&&s.length>0?{type:"text",text:e,marks:s}:{type:"text",text:e}}function W(e,s,n){if(!s)return;const t=e[e.length-1],o=JSON.stringify(n??[]),u=JSON.stringify((t==null?void 0:t.marks)??[]);if((t==null?void 0:t.type)==="text"&&o===u){t.text=`${t.text??""}${s}`;return}e.push(ge(s,n))}function z(e,...s){return e.map(n=>{if(n.type!=="text")return n;const t=new Set((n.marks??[]).map(u=>u.type)),o=s.filter(u=>!t.has(u)).map(u=>({type:u}));return{...n,marks:[...n.marks??[],...o]}})}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 X(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=X(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 u=(e[t]??"").trim();for(t+=1;t<e.length&&(e[t]??"").trim()==="";)t+=1;if((e[t]??"").trim()!=="</document>")return null;const p=X(u);return p?{node:{type:"paragraph",content:[p]},nextIndex:t+1}:null}function U(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 o=U(e,"***","***",t);if(o>t){const i=e.slice(t+3,o);n.push(...z(A(i,s),"bold","italic")),t=o+3;continue}if(!s&&e.startsWith("{{{documents.",t)){const i=e.indexOf("}}}",t);if(i>t){const y=e.slice(t,i+3),b=X(y);if(b){n.push(b),t=i+3;continue}}}if(!s&&e.startsWith("{{agent.",t)){const i=e.indexOf("}}",t);if(i>t){const y=e.slice(t,i+2),b=gt(y);if(b){n.push(b),t=i+2;continue}}}const u=U(e,"**","**",t);if(u>t){const i=e.slice(t+2,u);n.push(...z(A(i,s),"bold")),t=u+2;continue}const c=U(e,"~~","~~",t);if(c>t){const i=e.slice(t+2,c);n.push(...z(A(i,s),"strike")),t=c+2;continue}const p=e[t]==="*"&&!e.startsWith("**",t)?e.indexOf("*",t+1):-1;if(p>t){const i=e.slice(t+1,p);n.push(...z(A(i,s),"italic")),t=p+1;continue}if(e[t]==="`"){const i=e.indexOf("`",t+1);if(i>t){W(n,e.slice(t+1,i),[{type:"code"}]),t=i+1;continue}}const m=bt(e,t),x=m>=0?m:e.length;if(x===t){W(n,e[t]),t+=1;continue}W(n,e.slice(t,x)),t=x}return n}function yt(e){const s=e.split(`
|
|
22
22
|
`),n=[];return s.forEach((t,o)=>{n.push(...A(t)),o<s.length-1&&n.push({type:"hardBreak"})}),{type:"paragraph",content:n}}function se(e,s){const n=s?"orderedList":"bulletList",t=s?/^\d+\.\s+/:/^[-*]\s+/;return{type:n,content:e.map(o=>({type:"listItem",content:[{type:"paragraph",content:A(o.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=>ne.includes(n)));return ne.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 ae(e){return e.replace(/&/g,"&").replace(/"/g,""").trim()}function jt(e,s,n){var t,o,u,c;if(e.type==="hardBreak")return`
|
|
23
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(((o=e.attrs)==null?void 0:o.key)??""),m=String(((u=e.attrs)==null?void 0:u.variant)??"content"),x=`{{{documents.${p}.${m}}}}`,i=((c=n==null?void 0:n.getDocumentMeta)==null?void 0:c.call(n,p))??{name:p},y=[`name="${ae(i.name)}"`];return i.path&&y.push(`path="${ae(i.path)}"`),y.push(`type="${m}"`),`<document ${y.join(" ")}>
|
|
24
24
|
|
|
25
25
|
${x}
|
|
26
26
|
|
|
27
|
-
</document>`}return I(e.content,s,n)}function I(e,s,n){let t="",o=[];const u=c=>{const p=wt(o,c);for(let m=o.length-1;m>=p;m-=1)t+=re[o[m]].close;for(let m=p;m<c.length;m+=1)t+=re[c[m]].open;o=c};for(const c of e??[]){if(c.type==="text"){u(kt(c.marks)),t+=c.text??"";continue}u([]),t+=jt(c,s,n)}return u([]),t}function
|
|
27
|
+
</document>`}return I(e.content,s,n)}function I(e,s,n){let t="",o=[];const u=c=>{const p=wt(o,c);for(let m=o.length-1;m>=p;m-=1)t+=re[o[m]].close;for(let m=p;m<c.length;m+=1)t+=re[c[m]].open;o=c};for(const c of e??[]){if(c.type==="text"){u(kt(c.marks)),t+=c.text??"";continue}u([]),t+=jt(c,s,n)}return u([]),t}function Q(e){const s=e.replace(/\r\n?/g,`
|
|
28
28
|
`);if(!s.trim())return{type:"doc",content:[]};const n=s.split(`
|
|
29
29
|
`),t=[];let o=0;for(;o<n.length;){const u=n[o];if(!u.trim()){o+=1;continue}const c=xt(n,o);if(c){t.push(c.node),o=c.nextIndex;continue}const p=u.match(/^```(\S+)?\s*$/);if(p){const i=p[1]??null,y=[];for(o+=1;o<n.length&&!/^```/.test(n[o]);)y.push(n[o]),o+=1;o<n.length&&(o+=1),t.push({type:"codeBlock",attrs:i?{language:i}:{},content:[ge(y.join(`
|
|
30
30
|
`))]});continue}const m=u.match(/^(#{1,3})\s+(.*)$/);if(m){t.push({type:"heading",attrs:{level:m[1].length},content:A(m[2])}),o+=1;continue}if(/^---+$/.test(u)){t.push({type:"horizontalRule"}),o+=1;continue}if(/^[-*]\s+/.test(u)){const i=[];for(;o<n.length&&/^[-*]\s+/.test(n[o]);)i.push(n[o]),o+=1;t.push(se(i,!1));continue}if(/^\d+\.\s+/.test(u)){const i=[];for(;o<n.length&&/^\d+\.\s+/.test(n[o]);)i.push(n[o]),o+=1;t.push(se(i,!0));continue}const x=[u];for(o+=1;o<n.length&&n[o].trim()&&!vt(n[o]);)x.push(n[o]),o+=1;t.push(yt(x.join(`
|
|
@@ -34,4 +34,4 @@ ${x}
|
|
|
34
34
|
${m}
|
|
35
35
|
\`\`\``}case"horizontalRule":return"---";case"paragraph":return I(e.content,s,n);default:return I(e.content,s,n)}}function oe(e,s){return(e.content??[]).map(n=>Nt(n,"hbs",s)).join(`
|
|
36
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 ie(e){return{type:"variableMention",attrs:{variable:e}}}function q(e){return!e.isActive("codeBlock")&&!e.isActive("code")}function le(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=d.forwardRef(function({value:s,onChange:n,documents:t,documentsLoading:o,documentsError:u,documentsUnavailable:c,onPreview:p,onRefetchDocuments:m},x){const{t:i}=B(),y=d.useRef(null),b=d.useMemo(()=>({content:i("agent.prompt.variantContent"),toc:i("agent.prompt.variantToc")}),[i]),k=d.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=d.useMemo(()=>[{key:"headings",buttons:[{key:"h1",label:i("agent.prompt.toolbar.h1"),icon:Me,shortcut:"Cmd+Alt+1",action:a=>{a.chain().focus().toggleHeading({level:1}).run()},isActive:a=>a.isActive("heading",{level:1})},{key:"h2",label:i("agent.prompt.toolbar.h2"),icon:Ae,shortcut:"Cmd+Alt+2",action:a=>{a.chain().focus().toggleHeading({level:2}).run()},isActive:a=>a.isActive("heading",{level:2})},{key:"h3",label:i("agent.prompt.toolbar.h3"),icon
|
|
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 ie(e){return{type:"variableMention",attrs:{variable:e}}}function q(e){return!e.isActive("codeBlock")&&!e.isActive("code")}function le(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=d.forwardRef(function({value:s,onChange:n,documents:t,documentsLoading:o,documentsError:u,documentsUnavailable:c,onPreview:p,onRefetchDocuments:m},x){const{t:i}=B(),y=d.useRef(null),b=d.useMemo(()=>({content:i("agent.prompt.variantContent"),toc:i("agent.prompt.variantToc")}),[i]),k=d.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=d.useMemo(()=>[{key:"headings",buttons:[{key:"h1",label:i("agent.prompt.toolbar.h1"),icon:Me,shortcut:"Cmd+Alt+1",action:a=>{a.chain().focus().toggleHeading({level:1}).run()},isActive:a=>a.isActive("heading",{level:1})},{key:"h2",label:i("agent.prompt.toolbar.h2"),icon:Ae,shortcut:"Cmd+Alt+2",action:a=>{a.chain().focus().toggleHeading({level:2}).run()},isActive:a=>a.isActive("heading",{level:2})},{key:"h3",label:i("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:i("agent.prompt.toolbar.bold"),icon:$e,shortcut:"Cmd+B",action:a=>{a.chain().focus().toggleBold().run()},isActive:a=>a.isActive("bold")},{key:"italic",label:i("agent.prompt.toolbar.italic"),icon:Ie,shortcut:"Cmd+I",action:a=>{a.chain().focus().toggleItalic().run()},isActive:a=>a.isActive("italic")},{key:"strike",label:i("agent.prompt.toolbar.strike"),icon:Pe,shortcut:"Cmd+Shift+S",action:a=>{a.chain().focus().toggleStrike().run()},isActive:a=>a.isActive("strike")}]},{key:"lists",buttons:[{key:"bulletList",label:i("agent.prompt.toolbar.bulletList"),icon:Re,shortcut:"Cmd+Shift+8",action:a=>{a.chain().focus().toggleBulletList().run()},isActive:a=>a.isActive("bulletList")},{key:"orderedList",label:i("agent.prompt.toolbar.orderedList"),icon:Be,shortcut:"Cmd+Shift+7",action:a=>{a.chain().focus().toggleOrderedList().run()},isActive:a=>a.isActive("orderedList")},{key:"blockquote",label:i("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:i("agent.prompt.toolbar.code"),icon:ze,shortcut:"Cmd+E",action:a=>{a.chain().focus().toggleCode().run()},isActive:a=>a.isActive("code")},{key:"codeBlock",label:i("agent.prompt.toolbar.codeBlock"),icon:qe,shortcut:"Cmd+Alt+C",action:a=>{a.chain().focus().toggleCodeBlock().run()},isActive:a=>a.isActive("codeBlock")},{key:"horizontalRule",label:i("agent.prompt.toolbar.horizontalRule"),icon:Fe,shortcut:"Cmd+Alt+-",action:a=>{a.chain().focus().setHorizontalRule().run()}}]},{key:"history",buttons:[{key:"undo",label:i("agent.prompt.toolbar.undo"),icon:Ve,shortcut:"Cmd+Z",action:a=>{a.chain().focus().undo().run()},isDisabled:a=>!a.can().chain().focus().undo().run()},{key:"redo",label:i("agent.prompt.toolbar.redo"),icon:He,shortcut:"Cmd+Shift+Z",action:a=>{a.chain().focus().redo().run()},isDisabled:a=>!a.can().chain().focus().redo().run()}]}],[i]),h=Ke({immediatelyRender:!1,extensions:[We.configure({heading:{levels:[1,2,3]}}),Ue.configure({placeholder:i("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}),ue.create({name:"fallbackInline",inline:!0,group:"inline"})],content:Q(s),editorProps:{attributes:{class:lt,"data-testid":"prompt-editor-content","aria-label":i("agent.prompt.editorLabel"),role:"textbox"}},onUpdate({editor:a}){const j=oe(a.getJSON(),{getDocumentMeta:k});y.current=j,n(j)}}),l=Qe({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=d.useMemo(()=>he.map(a=>({label:a,actions:[{label:i("agent.prompt.toolbar.insert"),onClick:()=>{if(h){if(q(h)){h.chain().focus().insertContent(ie(a)).run();return}h.chain().focus().insertContent(`{{${a}}}`).run()}}}]})),[h,i]);d.useEffect(()=>{if(!h)return;const a=oe(h.getJSON(),{getDocumentMeta:k});s===a||s===y.current||(h.commands.setContent(Q(s)),y.current=s)},[h,k,s]),d.useImperativeHandle(x,()=>({insertVariable(a){if(h){if(q(h)){h.chain().focus().insertContent(ie(a)).run();return}h.chain().focus().insertContent(`{{${a}}}`).run()}},insertDocumentBlock(a,j){return h?le(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=Q(j);h.chain().focus().insertContent(C.content??[]).run()},_=a=>`${a.label} (${a.shortcut})`,M=(a,j)=>h?le(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 $;const D=_(C),S=(l==null?void 0:l.active[C.key])??!1,T=h?((($=C.isDisabled)==null?void 0:$.call(C,h))??!1)||((l==null?void 0:l.disabled[C.key])??!1):!0,O=C.icon;return r.jsx("button",{type:"button",title:D,"aria-label":D,"data-testid":`prompt-toolbar-${C.key}`,disabled:T,onClick:()=>h&&C.action(h),className:`flex h-8 w-8 items-center justify-center rounded-md transition-colors ${S?"bg-gray-200 text-gray-900":"text-gray-600 hover:bg-gray-100 hover:text-gray-900"} ${T?"cursor-not-allowed opacity-40":""}`,children:r.jsx(O,{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(Ze,{className:"h-4 w-4"}),r.jsx("span",{children:i("agent.prompt.toolbar.variable")})]}),items:g,emptyLabel:i("agent.prompt.toolbar.empty")}),r.jsx(ut,{documents:t,documentsLoading:o,documentsError:u,documentsUnavailable:c,onInsertDocument:M,onRefetchDocuments:m}),r.jsx("button",{type:"button",title:`${i("agent.prompt.preview.button")} (Cmd+P)`,"aria-label":`${i("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(et,{className:"h-4 w-4"})})]})]}),r.jsx("div",{"data-testid":"prompt-editor",onPaste:v,children:r.jsx(Je,{editor:h})})]})});function Et({previewAgentId:e=null}){const{t:s}=B(),n=Xe(g=>g.currentWorkspaceId),t=Y(g=>g.form),o=Y(g=>g.setField),[u,c]=d.useState([]),[p,m]=d.useState(!0),[x,i]=d.useState(null),[y,b]=d.useState(!1),[k,w]=d.useState(!1),h=d.useMemo(()=>{const g=ot(t);return{template:t.prompt,...e?{agentId:e}:{},context:{agent:g}}},[t,e]),l=d.useCallback(async()=>{m(!0),i(null),b(!1);try{const g=await F.getDocuments();c(g.documents)}catch(g){if(me(g)){c([]),b(!0);return}i(g instanceof Error?g.message:s("agent.prompt.documentInsertError"))}finally{m(!1)}},[s]);return d.useEffect(()=>{l()},[n,l]),d.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=>o("prompt",g),documents:u,documentsLoading:p,documentsError:x,documentsUnavailable:y,onPreview:()=>w(!0),onRefetchDocuments:()=>void l()})}),r.jsx(ct,{open:k,request:h,onClose:()=>w(!1)})]})}export{Et as default};
|