@winspan/claude-forge 8.33.5 → 8.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/agents/definition.d.ts +3 -0
  2. package/dist/agents/definition.d.ts.map +1 -1
  3. package/dist/agents/definition.js +3 -0
  4. package/dist/agents/definition.js.map +1 -1
  5. package/dist/agents/official-agents.d.ts.map +1 -1
  6. package/dist/agents/official-agents.js +6 -3
  7. package/dist/agents/official-agents.js.map +1 -1
  8. package/dist/agents/registry.d.ts +17 -1
  9. package/dist/agents/registry.d.ts.map +1 -1
  10. package/dist/agents/registry.js +106 -7
  11. package/dist/agents/registry.js.map +1 -1
  12. package/dist/cli/commands/executions.d.ts +3 -0
  13. package/dist/cli/commands/executions.d.ts.map +1 -0
  14. package/dist/cli/commands/executions.js +109 -0
  15. package/dist/cli/commands/executions.js.map +1 -0
  16. package/dist/cli/commands/skills.d.ts.map +1 -1
  17. package/dist/cli/commands/skills.js +83 -20
  18. package/dist/cli/commands/skills.js.map +1 -1
  19. package/dist/cli/index.js +2 -0
  20. package/dist/cli/index.js.map +1 -1
  21. package/dist/core/storage/rows.d.ts +14 -0
  22. package/dist/core/storage/rows.d.ts.map +1 -1
  23. package/dist/core/storage/schema.sql +26 -0
  24. package/dist/core/storage/sqlite.d.ts +11 -2
  25. package/dist/core/storage/sqlite.d.ts.map +1 -1
  26. package/dist/core/storage/sqlite.js +32 -0
  27. package/dist/core/storage/sqlite.js.map +1 -1
  28. package/dist/daemon/handlers/stop.d.ts +5 -1
  29. package/dist/daemon/handlers/stop.d.ts.map +1 -1
  30. package/dist/daemon/handlers/stop.js +27 -1
  31. package/dist/daemon/handlers/stop.js.map +1 -1
  32. package/dist/daemon/handlers/user-prompt.d.ts +3 -1
  33. package/dist/daemon/handlers/user-prompt.d.ts.map +1 -1
  34. package/dist/daemon/handlers/user-prompt.js +37 -4
  35. package/dist/daemon/handlers/user-prompt.js.map +1 -1
  36. package/dist/daemon/index.d.ts.map +1 -1
  37. package/dist/daemon/index.js +10 -4
  38. package/dist/daemon/index.js.map +1 -1
  39. package/dist/daemon/routing-observer.d.ts.map +1 -1
  40. package/dist/daemon/routing-observer.js +24 -1
  41. package/dist/daemon/routing-observer.js.map +1 -1
  42. package/dist/intelligence/execution-doc-builder.d.ts +61 -0
  43. package/dist/intelligence/execution-doc-builder.d.ts.map +1 -0
  44. package/dist/intelligence/execution-doc-builder.js +601 -0
  45. package/dist/intelligence/execution-doc-builder.js.map +1 -0
  46. package/dist/skills/invocation-guard.d.ts +45 -0
  47. package/dist/skills/invocation-guard.d.ts.map +1 -0
  48. package/dist/skills/invocation-guard.js +82 -0
  49. package/dist/skills/invocation-guard.js.map +1 -0
  50. package/dist/skills/registry.d.ts +22 -0
  51. package/dist/skills/registry.d.ts.map +1 -1
  52. package/dist/skills/registry.js +30 -2
  53. package/dist/skills/registry.js.map +1 -1
  54. package/dist/skills/tools/skill-invoke.d.ts +36 -0
  55. package/dist/skills/tools/skill-invoke.d.ts.map +1 -0
  56. package/dist/skills/tools/skill-invoke.js +82 -0
  57. package/dist/skills/tools/skill-invoke.js.map +1 -0
  58. package/dist/skills/tools/skill-list.d.ts +26 -0
  59. package/dist/skills/tools/skill-list.d.ts.map +1 -0
  60. package/dist/skills/tools/skill-list.js +35 -0
  61. package/dist/skills/tools/skill-list.js.map +1 -0
  62. package/dist/web/routes/execution-trace.d.ts.map +1 -1
  63. package/dist/web/routes/execution-trace.js +16 -0
  64. package/dist/web/routes/execution-trace.js.map +1 -1
  65. package/dist/web/routes/skill-stats.d.ts +12 -0
  66. package/dist/web/routes/skill-stats.d.ts.map +1 -0
  67. package/dist/web/routes/skill-stats.js +72 -0
  68. package/dist/web/routes/skill-stats.js.map +1 -0
  69. package/dist/web/static/assets/{AIConfig-BbwRuWzm.js → AIConfig-DiUFET_Q.js} +2 -2
  70. package/dist/web/static/assets/{AIConfig-BbwRuWzm.js.map → AIConfig-DiUFET_Q.js.map} +1 -1
  71. package/dist/web/static/assets/{Agents-FyKzsN-g.js → Agents-bNNGbQnL.js} +2 -2
  72. package/dist/web/static/assets/{Agents-FyKzsN-g.js.map → Agents-bNNGbQnL.js.map} +1 -1
  73. package/dist/web/static/assets/{Events-C2OCOKAD.js → Events-DQHP6Uaq.js} +2 -2
  74. package/dist/web/static/assets/{Events-C2OCOKAD.js.map → Events-DQHP6Uaq.js.map} +1 -1
  75. package/dist/web/static/assets/ExecutionTrace-Co8ARdg-.js +3 -0
  76. package/dist/web/static/assets/ExecutionTrace-Co8ARdg-.js.map +1 -0
  77. package/dist/web/static/assets/{Methodologies-DwYLXc8o.js → Methodologies-CXNrDXwG.js} +2 -2
  78. package/dist/web/static/assets/{Methodologies-DwYLXc8o.js.map → Methodologies-CXNrDXwG.js.map} +1 -1
  79. package/dist/web/static/assets/{Sessions-CFpFk-5I.js → Sessions-ZQSCgXyy.js} +2 -2
  80. package/dist/web/static/assets/{Sessions-CFpFk-5I.js.map → Sessions-ZQSCgXyy.js.map} +1 -1
  81. package/dist/web/static/assets/{Skills-BkbegTV1.js → Skills-C5-5zOSH.js} +2 -2
  82. package/dist/web/static/assets/{Skills-BkbegTV1.js.map → Skills-C5-5zOSH.js.map} +1 -1
  83. package/dist/web/static/assets/{index-CIRlno4E.js → index-DJK5beK6.js} +3 -3
  84. package/dist/web/static/assets/{index-CIRlno4E.js.map → index-DJK5beK6.js.map} +1 -1
  85. package/dist/web/static/assets/index-phpuytMI.css +1 -0
  86. package/dist/web/static/index.html +2 -2
  87. package/package.json +1 -1
  88. package/dist/web/static/assets/ExecutionTrace-BsWSpu2v.js +0 -3
  89. package/dist/web/static/assets/ExecutionTrace-BsWSpu2v.js.map +0 -1
  90. package/dist/web/static/assets/index-N1EByy_h.css +0 -1
@@ -0,0 +1,72 @@
1
+ /**
2
+ * /api/skill-stats/* — Skill usage statistics and analytics
3
+ *
4
+ * Provides data for the Skill Statistics dashboard:
5
+ * - /api/skill-stats/distribution — routing type distribution (agent/skill/none)
6
+ * - /api/skill-stats/frequency — skill usage frequency
7
+ * - /api/skill-stats/trend — skill usage rate trend over time
8
+ */
9
+ export function registerSkillStatsRoutes(app, ctx) {
10
+ const { storage } = ctx;
11
+ // Routing type distribution (for pie chart)
12
+ app.get('/api/skill-stats/distribution', (req, res) => {
13
+ const windowHours = parseInt(req.query.window || '168'); // default 7d
14
+ const since = Date.now() - windowHours * 3600 * 1000;
15
+ const events = storage.queryRoutingEvents({ since_ts: since, limit: 10000 });
16
+ const distribution = {
17
+ agent: 0,
18
+ skill: 0,
19
+ none: 0,
20
+ };
21
+ for (const e of events) {
22
+ const type = e.routed_to_type || 'none';
23
+ distribution[type] = (distribution[type] || 0) + 1;
24
+ }
25
+ const result = Object.entries(distribution).map(([type, count]) => ({
26
+ type,
27
+ count,
28
+ }));
29
+ res.json({ windowHours, distribution: result });
30
+ });
31
+ // Skill usage frequency (for bar chart)
32
+ app.get('/api/skill-stats/frequency', (req, res) => {
33
+ const windowHours = parseInt(req.query.window || '168');
34
+ const since = Date.now() - windowHours * 3600 * 1000;
35
+ const events = storage.queryRoutingEvents({ since_ts: since, limit: 10000 });
36
+ const frequency = new Map();
37
+ for (const e of events) {
38
+ if (e.routed_to_type === 'skill' && e.routed_to_name) {
39
+ frequency.set(e.routed_to_name, (frequency.get(e.routed_to_name) || 0) + 1);
40
+ }
41
+ }
42
+ const result = Array.from(frequency.entries())
43
+ .map(([name, count]) => ({ name, count }))
44
+ .sort((a, b) => b.count - a.count);
45
+ res.json({ windowHours, frequency: result });
46
+ });
47
+ // Skill usage rate trend over time (for line chart)
48
+ app.get('/api/skill-stats/trend', (req, res) => {
49
+ const windowHours = parseInt(req.query.window || '168');
50
+ const since = Date.now() - windowHours * 3600 * 1000;
51
+ const events = storage.queryRoutingEvents({ since_ts: since, limit: 10000 });
52
+ // Group by day
53
+ const dailyStats = new Map();
54
+ for (const e of events) {
55
+ const day = new Date(e.ts).toISOString().split('T')[0];
56
+ const stats = dailyStats.get(day) || { total: 0, skill: 0 };
57
+ stats.total++;
58
+ if (e.routed_to_type === 'skill') {
59
+ stats.skill++;
60
+ }
61
+ dailyStats.set(day, stats);
62
+ }
63
+ const result = Array.from(dailyStats.entries())
64
+ .map(([day, stats]) => ({
65
+ day,
66
+ skillRate: stats.total > 0 ? Math.round((stats.skill / stats.total) * 100) : 0,
67
+ }))
68
+ .sort((a, b) => a.day.localeCompare(b.day));
69
+ res.json({ windowHours, trend: result });
70
+ });
71
+ }
72
+ //# sourceMappingURL=skill-stats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-stats.js","sourceRoot":"","sources":["../../../src/web/routes/skill-stats.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAgB,EAAE,GAAiB;IAC1E,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAExB,4CAA4C;IAC5C,GAAG,CAAC,GAAG,CAAC,+BAA+B,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACpD,MAAM,WAAW,GAAG,QAAQ,CAAE,GAAG,CAAC,KAAK,CAAC,MAAiB,IAAI,KAAK,CAAC,CAAC,CAAC,aAAa;QAClF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,WAAW,GAAG,IAAI,GAAG,IAAI,CAAC;QACrD,MAAM,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAE7E,MAAM,YAAY,GAA2B;YAC3C,KAAK,EAAE,CAAC;YACR,KAAK,EAAE,CAAC;YACR,IAAI,EAAE,CAAC;SACR,CAAC;QAEF,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,CAAC,CAAC,cAAc,IAAI,MAAM,CAAC;YACxC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI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AG,EAAE,KAAK,CAAC,CAAC;QAC7B,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;aAC5C,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACtB,GAAG;YACH,SAAS,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/E,CAAC,CAAC;aACF,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAE9C,GAAG,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,2 +1,2 @@
1
- import{r as m,j as e}from"./react-vendor-CSp-GLFF.js";import{b as w,u as p,c as y}from"./query-C99w429o.js";import{u as N}from"./index-CIRlno4E.js";import{a as f}from"./auth-Bnf8ZcqN.js";import{C as k,E as _,v as C,e as P,d as S,p as E,Z as A,u as F}from"./lucide-BanPULT1.js";import"./react-router-I-HqunH7.js";import"./vendor-CMMjVdZs.js";import"./syntax-highlighter-44FakypI.js";async function I(){const a=await fetch("/api/config/ai");if(!a.ok)throw new Error("Failed to fetch config");return a.json()}async function K(a,r){const i=new URLSearchParams;a&&i.set("api_key",a),r&&i.set("base_url",r);const o=await fetch(`/api/ai/models?${i.toString()}`);return o.ok?(await o.json()).data||[]:[]}async function T(a){if(!(await f("/api/config/ai",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})).ok)throw new Error("Failed to save config")}async function q(a){const r=await f("/api/ai/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),i=await r.json().catch(()=>({}));if(!r.ok)throw new Error(i.error||"Test failed");return i}function J(){const a=w(),r=N(),{data:i,isLoading:o}=p({queryKey:["ai-config"],queryFn:I}),[t,n]=m.useState({api_key:"",base_url:"",model:""}),[u,b]=m.useState(!1),[d,h]=m.useState(null);m.useEffect(()=>{i&&n(i)},[i]);const{data:l,refetch:j,isFetching:g}=p({queryKey:["ai-models",t.api_key,t.base_url],queryFn:()=>K(t.api_key,t.base_url),enabled:!!t.api_key&&!!t.base_url}),x=y({mutationFn:T,onSuccess:()=>{r.success("AI 配置已保存"),a.invalidateQueries({queryKey:["ai-config"]})},onError:s=>r.error(`保存失败: ${s.message}`)}),c=y({mutationFn:q,onSuccess:s=>{const v=(s==null?void 0:s.model)||t.model;h({ok:!0,message:`连接成功!模型: ${v}`}),r.success("API 连接测试通过")},onError:s=>{h({ok:!1,message:s.message}),r.error("API 连接测试失败")}});return o?e.jsx("div",{className:"bg-white rounded-lg shadow p-6",children:"加载中..."}):e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-6",children:"AI 配置"}),e.jsxs("div",{className:"bg-white rounded-lg shadow p-6 max-w-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx(k,{className:"h-5 w-5 text-indigo-600"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Anthropic API 配置"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:u?"text":"password",value:t.api_key||"",onChange:s=>n({...t,api_key:s.target.value}),placeholder:"sk-...",className:"w-full px-3 py-2 pr-10 border border-gray-300 rounded-md text-sm font-mono"}),e.jsx("button",{type:"button",onClick:()=>b(!u),className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:u?e.jsx(_,{className:"h-4 w-4"}):e.jsx(C,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Base URL"}),e.jsx("input",{type:"text",value:t.base_url||"",onChange:s=>n({...t,base_url:s.target.value}),placeholder:"https://api.anthropic.com",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"主模型 (Distill / QualityGate)"}),e.jsx("button",{type:"button",onClick:()=>j(),disabled:!t.api_key||!t.base_url||g,className:"text-xs text-indigo-600 hover:text-indigo-700 disabled:text-gray-400",children:g?"加载中...":"🔄 刷新模型列表"})]}),l&&l.length>0?e.jsxs("select",{value:t.model||"",onChange:s=>n({...t,model:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm bg-white",children:[e.jsx("option",{value:"",children:"-- 选择模型 --"}),l.map(s=>e.jsxs("option",{value:s.id,children:[s.id," ",s.owned_by&&`(${s.owned_by})`]},s.id))]}):e.jsx("input",{type:"text",value:t.model||"",onChange:s=>n({...t,model:s.target.value}),placeholder:"claude-sonnet-4-6",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:l&&l.length>0?`发现 ${l.length} 个可用模型`:"填入 API Key 和 Base URL 后可自动发现模型"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"分类器模型(可选,便宜+快的模型)"}),l&&l.length>0?e.jsxs("select",{value:t.classifier_model||"",onChange:s=>n({...t,classifier_model:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm bg-white",children:[e.jsx("option",{value:"",children:"-- 不指定 (使用主模型) --"}),l.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}):e.jsx("input",{type:"text",value:t.classifier_model||"",onChange:s=>n({...t,classifier_model:s.target.value}),placeholder:"claude-haiku-4-5-20251001",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"分类器超时 (ms)"}),e.jsx("input",{type:"number",value:t.classifier_timeout||1e4,onChange:s=>n({...t,classifier_timeout:parseInt(s.target.value)}),className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),d&&e.jsxs("div",{className:`flex items-start gap-2 p-3 rounded text-sm ${d.ok?"bg-green-50 text-green-800":"bg-red-50 text-red-800"}`,children:[d.ok?e.jsx(P,{className:"h-4 w-4 flex-shrink-0 mt-0.5"}):e.jsx(S,{className:"h-4 w-4 flex-shrink-0 mt-0.5"}),e.jsx("div",{className:"flex-1 break-all",children:d.message})]}),e.jsx("div",{className:"flex items-center justify-end pt-4 border-t",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>c.mutate({api_key:t.api_key,base_url:t.base_url,model:t.model}),disabled:c.isPending||!t.api_key||!t.model,className:"inline-flex items-center gap-2 px-4 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-md hover:bg-gray-200 disabled:bg-gray-50 disabled:text-gray-400",children:[c.isPending?e.jsx(E,{className:"h-4 w-4 animate-spin"}):e.jsx(A,{className:"h-4 w-4"}),c.isPending?"测试中...":"测试连接"]}),e.jsxs("button",{onClick:()=>x.mutate(t),disabled:x.isPending,className:"inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700 disabled:bg-gray-400",children:[e.jsx(F,{className:"h-4 w-4"}),x.isPending?"保存中...":"保存配置"]})]})})]})]})]})}export{J as default};
2
- //# sourceMappingURL=AIConfig-BbwRuWzm.js.map
1
+ import{r as m,j as e}from"./react-vendor-CSp-GLFF.js";import{b as w,u as p,c as y}from"./query-C99w429o.js";import{u as N}from"./index-DJK5beK6.js";import{a as f}from"./auth-Bnf8ZcqN.js";import{C as k,E as _,v as C,e as P,d as S,p as E,Z as A,u as F}from"./lucide-BanPULT1.js";import"./react-router-I-HqunH7.js";import"./vendor-CMMjVdZs.js";import"./syntax-highlighter-44FakypI.js";async function I(){const a=await fetch("/api/config/ai");if(!a.ok)throw new Error("Failed to fetch config");return a.json()}async function K(a,r){const i=new URLSearchParams;a&&i.set("api_key",a),r&&i.set("base_url",r);const o=await fetch(`/api/ai/models?${i.toString()}`);return o.ok?(await o.json()).data||[]:[]}async function T(a){if(!(await f("/api/config/ai",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})).ok)throw new Error("Failed to save config")}async function q(a){const r=await f("/api/ai/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),i=await r.json().catch(()=>({}));if(!r.ok)throw new Error(i.error||"Test failed");return i}function J(){const a=w(),r=N(),{data:i,isLoading:o}=p({queryKey:["ai-config"],queryFn:I}),[t,n]=m.useState({api_key:"",base_url:"",model:""}),[u,b]=m.useState(!1),[d,h]=m.useState(null);m.useEffect(()=>{i&&n(i)},[i]);const{data:l,refetch:j,isFetching:g}=p({queryKey:["ai-models",t.api_key,t.base_url],queryFn:()=>K(t.api_key,t.base_url),enabled:!!t.api_key&&!!t.base_url}),x=y({mutationFn:T,onSuccess:()=>{r.success("AI 配置已保存"),a.invalidateQueries({queryKey:["ai-config"]})},onError:s=>r.error(`保存失败: ${s.message}`)}),c=y({mutationFn:q,onSuccess:s=>{const v=(s==null?void 0:s.model)||t.model;h({ok:!0,message:`连接成功!模型: ${v}`}),r.success("API 连接测试通过")},onError:s=>{h({ok:!1,message:s.message}),r.error("API 连接测试失败")}});return o?e.jsx("div",{className:"bg-white rounded-lg shadow p-6",children:"加载中..."}):e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-6",children:"AI 配置"}),e.jsxs("div",{className:"bg-white rounded-lg shadow p-6 max-w-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6",children:[e.jsx(k,{className:"h-5 w-5 text-indigo-600"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Anthropic API 配置"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:u?"text":"password",value:t.api_key||"",onChange:s=>n({...t,api_key:s.target.value}),placeholder:"sk-...",className:"w-full px-3 py-2 pr-10 border border-gray-300 rounded-md text-sm font-mono"}),e.jsx("button",{type:"button",onClick:()=>b(!u),className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",children:u?e.jsx(_,{className:"h-4 w-4"}):e.jsx(C,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Base URL"}),e.jsx("input",{type:"text",value:t.base_url||"",onChange:s=>n({...t,base_url:s.target.value}),placeholder:"https://api.anthropic.com",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"主模型 (Distill / QualityGate)"}),e.jsx("button",{type:"button",onClick:()=>j(),disabled:!t.api_key||!t.base_url||g,className:"text-xs text-indigo-600 hover:text-indigo-700 disabled:text-gray-400",children:g?"加载中...":"🔄 刷新模型列表"})]}),l&&l.length>0?e.jsxs("select",{value:t.model||"",onChange:s=>n({...t,model:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm bg-white",children:[e.jsx("option",{value:"",children:"-- 选择模型 --"}),l.map(s=>e.jsxs("option",{value:s.id,children:[s.id," ",s.owned_by&&`(${s.owned_by})`]},s.id))]}):e.jsx("input",{type:"text",value:t.model||"",onChange:s=>n({...t,model:s.target.value}),placeholder:"claude-sonnet-4-6",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:l&&l.length>0?`发现 ${l.length} 个可用模型`:"填入 API Key 和 Base URL 后可自动发现模型"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"分类器模型(可选,便宜+快的模型)"}),l&&l.length>0?e.jsxs("select",{value:t.classifier_model||"",onChange:s=>n({...t,classifier_model:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm bg-white",children:[e.jsx("option",{value:"",children:"-- 不指定 (使用主模型) --"}),l.map(s=>e.jsx("option",{value:s.id,children:s.id},s.id))]}):e.jsx("input",{type:"text",value:t.classifier_model||"",onChange:s=>n({...t,classifier_model:s.target.value}),placeholder:"claude-haiku-4-5-20251001",className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"分类器超时 (ms)"}),e.jsx("input",{type:"number",value:t.classifier_timeout||1e4,onChange:s=>n({...t,classifier_timeout:parseInt(s.target.value)}),className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm"})]}),d&&e.jsxs("div",{className:`flex items-start gap-2 p-3 rounded text-sm ${d.ok?"bg-green-50 text-green-800":"bg-red-50 text-red-800"}`,children:[d.ok?e.jsx(P,{className:"h-4 w-4 flex-shrink-0 mt-0.5"}):e.jsx(S,{className:"h-4 w-4 flex-shrink-0 mt-0.5"}),e.jsx("div",{className:"flex-1 break-all",children:d.message})]}),e.jsx("div",{className:"flex items-center justify-end pt-4 border-t",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>c.mutate({api_key:t.api_key,base_url:t.base_url,model:t.model}),disabled:c.isPending||!t.api_key||!t.model,className:"inline-flex items-center gap-2 px-4 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-md hover:bg-gray-200 disabled:bg-gray-50 disabled:text-gray-400",children:[c.isPending?e.jsx(E,{className:"h-4 w-4 animate-spin"}):e.jsx(A,{className:"h-4 w-4"}),c.isPending?"测试中...":"测试连接"]}),e.jsxs("button",{onClick:()=>x.mutate(t),disabled:x.isPending,className:"inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700 disabled:bg-gray-400",children:[e.jsx(F,{className:"h-4 w-4"}),x.isPending?"保存中...":"保存配置"]})]})})]})]})]})}export{J as default};
2
+ //# sourceMappingURL=AIConfig-DiUFET_Q.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AIConfig-BbwRuWzm.js","sources":["../../src/pages/AIConfig.tsx"],"sourcesContent":["import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'\nimport { useState, useEffect } from 'react'\nimport { Save, Eye, EyeOff, Cpu, Zap, CheckCircle, XCircle, Loader2 } from 'lucide-react'\nimport { useToast } from '../components/Toast'\nimport { authFetch } from '../utils/auth'\n\ninterface AIConfig {\n api_key: string\n base_url: string\n model: string\n provider?: string\n classifier_model?: string\n classifier_timeout?: number\n}\n\ninterface ModelOption {\n id: string\n owned_by?: string\n}\n\nasync function fetchConfig(): Promise<AIConfig> {\n const res = await fetch('/api/config/ai')\n if (!res.ok) throw new Error('Failed to fetch config')\n return res.json()\n}\n\nasync function fetchModels(api_key?: string, base_url?: string): Promise<ModelOption[]> {\n const params = new URLSearchParams()\n if (api_key) params.set('api_key', api_key)\n if (base_url) params.set('base_url', base_url)\n const res = await fetch(`/api/ai/models?${params.toString()}`)\n if (!res.ok) return []\n const data = await res.json()\n return data.data || []\n}\n\nasync function saveConfig(config: AIConfig): Promise<void> {\n const res = await authFetch('/api/config/ai', {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(config),\n })\n if (!res.ok) throw new Error('Failed to save config')\n}\n\nasync function testConnection(config: { api_key: string; base_url: string; model: string }): Promise<any> {\n const res = await authFetch('/api/ai/test', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(config),\n })\n const data = await res.json().catch(() => ({}))\n if (!res.ok) throw new Error(data.error || 'Test failed')\n return data\n}\n\nexport default function AIConfig() {\n const queryClient = useQueryClient()\n const toast = useToast()\n const { data: config, isLoading } = useQuery({\n queryKey: ['ai-config'],\n queryFn: fetchConfig,\n })\n\n const [form, setForm] = useState<AIConfig>({\n api_key: '',\n base_url: '',\n model: '',\n })\n const [showKey, setShowKey] = useState(false)\n const [testResult, setTestResult] = useState<{ ok: boolean; message: string } | null>(null)\n\n useEffect(() => {\n if (config) setForm(config)\n }, [config])\n\n const { data: models, refetch: refetchModels, isFetching: loadingModels } = useQuery({\n queryKey: ['ai-models', form.api_key, form.base_url],\n queryFn: () => fetchModels(form.api_key, form.base_url),\n enabled: !!form.api_key && !!form.base_url,\n })\n\n const saveMutation = useMutation({\n mutationFn: saveConfig,\n onSuccess: () => {\n toast.success('AI 配置已保存')\n queryClient.invalidateQueries({ queryKey: ['ai-config'] })\n },\n onError: (e: Error) => toast.error(`保存失败: ${e.message}`),\n })\n\n const testMutation = useMutation({\n mutationFn: testConnection,\n onSuccess: (data) => {\n const modelName = data?.model || form.model\n setTestResult({ ok: true, message: `连接成功!模型: ${modelName}` })\n toast.success('API 连接测试通过')\n },\n onError: (err: Error) => {\n setTestResult({ ok: false, message: err.message })\n toast.error('API 连接测试失败')\n },\n })\n\n if (isLoading) {\n return <div className=\"bg-white rounded-lg shadow p-6\">加载中...</div>\n }\n\n return (\n <div>\n <h1 className=\"text-2xl font-bold text-gray-900 mb-6\">AI 配置</h1>\n\n <div className=\"bg-white rounded-lg shadow p-6 max-w-2xl\">\n <div className=\"flex items-center gap-2 mb-6\">\n <Cpu className=\"h-5 w-5 text-indigo-600\" />\n <h3 className=\"text-lg font-semibold text-gray-900\">Anthropic API 配置</h3>\n </div>\n\n <div className=\"space-y-4\">\n <div>\n <label className=\"block text-sm font-medium text-gray-700 mb-1\">API Key</label>\n <div className=\"relative\">\n <input\n type={showKey ? 'text' : 'password'}\n value={form.api_key || ''}\n onChange={(e) => setForm({ ...form, api_key: e.target.value })}\n placeholder=\"sk-...\"\n className=\"w-full px-3 py-2 pr-10 border border-gray-300 rounded-md text-sm font-mono\"\n />\n <button\n type=\"button\"\n onClick={() => setShowKey(!showKey)}\n className=\"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600\"\n >\n {showKey ? <EyeOff className=\"h-4 w-4\" /> : <Eye className=\"h-4 w-4\" />}\n </button>\n </div>\n </div>\n\n <div>\n <label className=\"block text-sm font-medium text-gray-700 mb-1\">Base URL</label>\n <input\n type=\"text\"\n value={form.base_url || ''}\n onChange={(e) => setForm({ ...form, base_url: e.target.value })}\n placeholder=\"https://api.anthropic.com\"\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm\"\n />\n </div>\n\n <div>\n <div className=\"flex items-center justify-between mb-1\">\n <label className=\"block text-sm font-medium text-gray-700\">主模型 (Distill / QualityGate)</label>\n <button\n type=\"button\"\n onClick={() => refetchModels()}\n disabled={!form.api_key || !form.base_url || loadingModels}\n className=\"text-xs text-indigo-600 hover:text-indigo-700 disabled:text-gray-400\"\n >\n {loadingModels ? '加载中...' : '🔄 刷新模型列表'}\n </button>\n </div>\n {models && models.length > 0 ? (\n <select\n value={form.model || ''}\n onChange={(e) => setForm({ ...form, model: e.target.value })}\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm bg-white\"\n >\n <option value=\"\">-- 选择模型 --</option>\n {models.map((m) => (\n <option key={m.id} value={m.id}>\n {m.id} {m.owned_by && `(${m.owned_by})`}\n </option>\n ))}\n </select>\n ) : (\n <input\n type=\"text\"\n value={form.model || ''}\n onChange={(e) => setForm({ ...form, model: e.target.value })}\n placeholder=\"claude-sonnet-4-6\"\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm\"\n />\n )}\n <p className=\"text-xs text-gray-500 mt-1\">\n {models && models.length > 0\n ? `发现 ${models.length} 个可用模型`\n : '填入 API Key 和 Base URL 后可自动发现模型'}\n </p>\n </div>\n\n <div>\n <label className=\"block text-sm font-medium text-gray-700 mb-1\">分类器模型(可选,便宜+快的模型)</label>\n {models && models.length > 0 ? (\n <select\n value={form.classifier_model || ''}\n onChange={(e) => setForm({ ...form, classifier_model: e.target.value })}\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm bg-white\"\n >\n <option value=\"\">-- 不指定 (使用主模型) --</option>\n {models.map((m) => (\n <option key={m.id} value={m.id}>{m.id}</option>\n ))}\n </select>\n ) : (\n <input\n type=\"text\"\n value={form.classifier_model || ''}\n onChange={(e) => setForm({ ...form, classifier_model: e.target.value })}\n placeholder=\"claude-haiku-4-5-20251001\"\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm\"\n />\n )}\n </div>\n\n <div>\n <label className=\"block text-sm font-medium text-gray-700 mb-1\">分类器超时 (ms)</label>\n <input\n type=\"number\"\n value={form.classifier_timeout || 10000}\n onChange={(e) => setForm({ ...form, classifier_timeout: parseInt(e.target.value) })}\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm\"\n />\n </div>\n\n {/* Test result */}\n {testResult && (\n <div className={`flex items-start gap-2 p-3 rounded text-sm ${\n testResult.ok ? 'bg-green-50 text-green-800' : 'bg-red-50 text-red-800'\n }`}>\n {testResult.ok ? (\n <CheckCircle className=\"h-4 w-4 flex-shrink-0 mt-0.5\" />\n ) : (\n <XCircle className=\"h-4 w-4 flex-shrink-0 mt-0.5\" />\n )}\n <div className=\"flex-1 break-all\">{testResult.message}</div>\n </div>\n )}\n\n <div className=\"flex items-center justify-end pt-4 border-t\">\n <div className=\"flex items-center gap-2\">\n <button\n onClick={() => testMutation.mutate({ api_key: form.api_key, base_url: form.base_url, model: form.model })}\n disabled={testMutation.isPending || !form.api_key || !form.model}\n className=\"inline-flex items-center gap-2 px-4 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-md hover:bg-gray-200 disabled:bg-gray-50 disabled:text-gray-400\"\n >\n {testMutation.isPending ? (\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n ) : (\n <Zap className=\"h-4 w-4\" />\n )}\n {testMutation.isPending ? '测试中...' : '测试连接'}\n </button>\n <button\n onClick={() => saveMutation.mutate(form)}\n disabled={saveMutation.isPending}\n className=\"inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700 disabled:bg-gray-400\"\n >\n <Save className=\"h-4 w-4\" />\n {saveMutation.isPending ? '保存中...' : '保存配置'}\n </button>\n </div>\n </div>\n </div>\n </div>\n </div>\n )\n}\n"],"names":["fetchConfig","res","fetchModels","api_key","base_url","params","saveConfig","config","authFetch","testConnection","data","AIConfig","queryClient","useQueryClient","toast","useToast","isLoading","useQuery","form","setForm","useState","showKey","setShowKey","testResult","setTestResult","useEffect","models","refetchModels","loadingModels","saveMutation","useMutation","e","testMutation","modelName","err","jsx","jsxs","Cpu","EyeOff","Eye","m","CheckCircle","XCircle","Loader2","Zap","Save"],"mappings":"8XAoBA,eAAeA,GAAiC,CAC9C,MAAMC,EAAM,MAAM,MAAM,gBAAgB,EACxC,GAAI,CAACA,EAAI,GAAI,MAAM,IAAI,MAAM,wBAAwB,EACrD,OAAOA,EAAI,KAAA,CACb,CAEA,eAAeC,EAAYC,EAAkBC,EAA2C,CACtF,MAAMC,EAAS,IAAI,gBACfF,GAASE,EAAO,IAAI,UAAWF,CAAO,EACtCC,GAAUC,EAAO,IAAI,WAAYD,CAAQ,EAC7C,MAAMH,EAAM,MAAM,MAAM,kBAAkBI,EAAO,SAAA,CAAU,EAAE,EAC7D,OAAKJ,EAAI,IACI,MAAMA,EAAI,KAAA,GACX,MAAQ,CAAA,EAFA,CAAA,CAGtB,CAEA,eAAeK,EAAWC,EAAiC,CAMzD,GAAI,EALQ,MAAMC,EAAU,iBAAkB,CAC5C,OAAQ,MACR,QAAS,CAAE,eAAgB,kBAAA,EAC3B,KAAM,KAAK,UAAUD,CAAM,CAAA,CAC5B,GACQ,GAAI,MAAM,I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AC,MAAA,CAAI,UAAU,mBAAoB,WAAW,OAAA,CAAQ,CAAA,EACxD,QAGD,MAAA,CAAI,UAAU,8CACb,SAAAC,EAAAA,KAAC,MAAA,CAAI,UAAU,0BACb,SAAA,CAAAA,EAAAA,KAAC,SAAA,CACC,QAAS,IAAMJ,EAAa,OAAO,CAAE,QAASd,EAAK,QAAS,SAAUA,EAAK,SAAU,MAAOA,EAAK,MAAO,EACxG,SAAUc,EAAa,WAAa,CAACd,EAAK,SAAW,CAACA,EAAK,MAC3D,UAAU,iKAET,SAAA,CAAAc,EAAa,gBACXW,EAAA,CAAQ,UAAU,uBAAuB,EAE1CR,EAAAA,IAACS,EAAA,CAAI,UAAU,SAAA,CAAU,EAE1BZ,EAAa,UAAY,SAAW,MAAA,CAAA,CAAA,EAEvCI,EAAAA,KAAC,SAAA,CACC,QAAS,IAAMP,EAAa,OAAOX,CAAI,EACvC,SAAUW,EAAa,UACvB,UAAU,4IAEV,SAAA,CAAAM,EAAAA,IAACU,EAAA,CAAK,UAAU,SAAA,CAAU,EACzBhB,EAAa,UAAY,SAAW,MAAA,CAAA,CAAA,CACvC,CAAA,CACF,CAAA,CACF,CAAA,CAAA,CACF,CAAA,CAAA,CACF,CAAA,EACF,CAEJ"}
1
+ {"version":3,"file":"AIConfig-DiUFET_Q.js","sources":["../../src/pages/AIConfig.tsx"],"sourcesContent":["import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'\nimport { useState, useEffect } from 'react'\nimport { Save, Eye, EyeOff, Cpu, Zap, CheckCircle, XCircle, Loader2 } from 'lucide-react'\nimport { useToast } from '../components/Toast'\nimport { authFetch } from '../utils/auth'\n\ninterface AIConfig {\n api_key: string\n base_url: string\n model: string\n provider?: string\n classifier_model?: string\n classifier_timeout?: number\n}\n\ninterface ModelOption {\n id: string\n owned_by?: string\n}\n\nasync function fetchConfig(): Promise<AIConfig> {\n const res = await fetch('/api/config/ai')\n if (!res.ok) throw new Error('Failed to fetch config')\n return res.json()\n}\n\nasync function fetchModels(api_key?: string, base_url?: string): Promise<ModelOption[]> {\n const params = new URLSearchParams()\n if (api_key) params.set('api_key', api_key)\n if (base_url) params.set('base_url', base_url)\n const res = await fetch(`/api/ai/models?${params.toString()}`)\n if (!res.ok) return []\n const data = await res.json()\n return data.data || []\n}\n\nasync function saveConfig(config: AIConfig): Promise<void> {\n const res = await authFetch('/api/config/ai', {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(config),\n })\n if (!res.ok) throw new Error('Failed to save config')\n}\n\nasync function testConnection(config: { api_key: string; base_url: string; model: string }): Promise<any> {\n const res = await authFetch('/api/ai/test', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(config),\n })\n const data = await res.json().catch(() => ({}))\n if (!res.ok) throw new Error(data.error || 'Test failed')\n return data\n}\n\nexport default function AIConfig() {\n const queryClient = useQueryClient()\n const toast = useToast()\n const { data: config, isLoading } = useQuery({\n queryKey: ['ai-config'],\n queryFn: fetchConfig,\n })\n\n const [form, setForm] = useState<AIConfig>({\n api_key: '',\n base_url: '',\n model: '',\n })\n const [showKey, setShowKey] = useState(false)\n const [testResult, setTestResult] = useState<{ ok: boolean; message: string } | null>(null)\n\n useEffect(() => {\n if (config) setForm(config)\n }, [config])\n\n const { data: models, refetch: refetchModels, isFetching: loadingModels } = useQuery({\n queryKey: ['ai-models', form.api_key, form.base_url],\n queryFn: () => fetchModels(form.api_key, form.base_url),\n enabled: !!form.api_key && !!form.base_url,\n })\n\n const saveMutation = useMutation({\n mutationFn: saveConfig,\n onSuccess: () => {\n toast.success('AI 配置已保存')\n queryClient.invalidateQueries({ queryKey: ['ai-config'] })\n },\n onError: (e: Error) => toast.error(`保存失败: ${e.message}`),\n })\n\n const testMutation = useMutation({\n mutationFn: testConnection,\n onSuccess: (data) => {\n const modelName = data?.model || form.model\n setTestResult({ ok: true, message: `连接成功!模型: ${modelName}` })\n toast.success('API 连接测试通过')\n },\n onError: (err: Error) => {\n setTestResult({ ok: false, message: err.message })\n toast.error('API 连接测试失败')\n },\n })\n\n if (isLoading) {\n return <div className=\"bg-white rounded-lg shadow p-6\">加载中...</div>\n }\n\n return (\n <div>\n <h1 className=\"text-2xl font-bold text-gray-900 mb-6\">AI 配置</h1>\n\n <div className=\"bg-white rounded-lg shadow p-6 max-w-2xl\">\n <div className=\"flex items-center gap-2 mb-6\">\n <Cpu className=\"h-5 w-5 text-indigo-600\" />\n <h3 className=\"text-lg font-semibold text-gray-900\">Anthropic API 配置</h3>\n </div>\n\n <div className=\"space-y-4\">\n <div>\n <label className=\"block text-sm font-medium text-gray-700 mb-1\">API Key</label>\n <div className=\"relative\">\n <input\n type={showKey ? 'text' : 'password'}\n value={form.api_key || ''}\n onChange={(e) => setForm({ ...form, api_key: e.target.value })}\n placeholder=\"sk-...\"\n className=\"w-full px-3 py-2 pr-10 border border-gray-300 rounded-md text-sm font-mono\"\n />\n <button\n type=\"button\"\n onClick={() => setShowKey(!showKey)}\n className=\"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600\"\n >\n {showKey ? <EyeOff className=\"h-4 w-4\" /> : <Eye className=\"h-4 w-4\" />}\n </button>\n </div>\n </div>\n\n <div>\n <label className=\"block text-sm font-medium text-gray-700 mb-1\">Base URL</label>\n <input\n type=\"text\"\n value={form.base_url || ''}\n onChange={(e) => setForm({ ...form, base_url: e.target.value })}\n placeholder=\"https://api.anthropic.com\"\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm\"\n />\n </div>\n\n <div>\n <div className=\"flex items-center justify-between mb-1\">\n <label className=\"block text-sm font-medium text-gray-700\">主模型 (Distill / QualityGate)</label>\n <button\n type=\"button\"\n onClick={() => refetchModels()}\n disabled={!form.api_key || !form.base_url || loadingModels}\n className=\"text-xs text-indigo-600 hover:text-indigo-700 disabled:text-gray-400\"\n >\n {loadingModels ? '加载中...' : '🔄 刷新模型列表'}\n </button>\n </div>\n {models && models.length > 0 ? (\n <select\n value={form.model || ''}\n onChange={(e) => setForm({ ...form, model: e.target.value })}\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm bg-white\"\n >\n <option value=\"\">-- 选择模型 --</option>\n {models.map((m) => (\n <option key={m.id} value={m.id}>\n {m.id} {m.owned_by && `(${m.owned_by})`}\n </option>\n ))}\n </select>\n ) : (\n <input\n type=\"text\"\n value={form.model || ''}\n onChange={(e) => setForm({ ...form, model: e.target.value })}\n placeholder=\"claude-sonnet-4-6\"\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm\"\n />\n )}\n <p className=\"text-xs text-gray-500 mt-1\">\n {models && models.length > 0\n ? `发现 ${models.length} 个可用模型`\n : '填入 API Key 和 Base URL 后可自动发现模型'}\n </p>\n </div>\n\n <div>\n <label className=\"block text-sm font-medium text-gray-700 mb-1\">分类器模型(可选,便宜+快的模型)</label>\n {models && models.length > 0 ? (\n <select\n value={form.classifier_model || ''}\n onChange={(e) => setForm({ ...form, classifier_model: e.target.value })}\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm bg-white\"\n >\n <option value=\"\">-- 不指定 (使用主模型) --</option>\n {models.map((m) => (\n <option key={m.id} value={m.id}>{m.id}</option>\n ))}\n </select>\n ) : (\n <input\n type=\"text\"\n value={form.classifier_model || ''}\n onChange={(e) => setForm({ ...form, classifier_model: e.target.value })}\n placeholder=\"claude-haiku-4-5-20251001\"\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm\"\n />\n )}\n </div>\n\n <div>\n <label className=\"block text-sm font-medium text-gray-700 mb-1\">分类器超时 (ms)</label>\n <input\n type=\"number\"\n value={form.classifier_timeout || 10000}\n onChange={(e) => setForm({ ...form, classifier_timeout: parseInt(e.target.value) })}\n className=\"w-full px-3 py-2 border border-gray-300 rounded-md text-sm\"\n />\n </div>\n\n {/* Test result */}\n {testResult && (\n <div className={`flex items-start gap-2 p-3 rounded text-sm ${\n testResult.ok ? 'bg-green-50 text-green-800' : 'bg-red-50 text-red-800'\n }`}>\n {testResult.ok ? (\n <CheckCircle className=\"h-4 w-4 flex-shrink-0 mt-0.5\" />\n ) : (\n <XCircle className=\"h-4 w-4 flex-shrink-0 mt-0.5\" />\n )}\n <div className=\"flex-1 break-all\">{testResult.message}</div>\n </div>\n )}\n\n <div className=\"flex items-center justify-end pt-4 border-t\">\n <div className=\"flex items-center gap-2\">\n <button\n onClick={() => testMutation.mutate({ api_key: form.api_key, base_url: form.base_url, model: form.model })}\n disabled={testMutation.isPending || !form.api_key || !form.model}\n className=\"inline-flex items-center gap-2 px-4 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-md hover:bg-gray-200 disabled:bg-gray-50 disabled:text-gray-400\"\n >\n {testMutation.isPending ? (\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n ) : (\n <Zap className=\"h-4 w-4\" />\n )}\n {testMutation.isPending ? '测试中...' : '测试连接'}\n </button>\n <button\n onClick={() => saveMutation.mutate(form)}\n disabled={saveMutation.isPending}\n className=\"inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-sm font-medium rounded-md hover:bg-indigo-700 disabled:bg-gray-400\"\n >\n <Save className=\"h-4 w-4\" />\n {saveMutation.isPending ? '保存中...' : '保存配置'}\n </button>\n </div>\n </div>\n </div>\n </div>\n </div>\n )\n}\n"],"names":["fetchConfig","res","fetchModels","api_key","base_url","params","saveConfig","config","authFetch","testConnection","data","AIConfig","queryClient","useQueryClient","toast","useToast","isLoading","useQuery","form","setForm","useState","showKey","setShowKey","testResult","setTestResult","useEffect","models","refetchModels","loadingModels","saveMutation","useMutation","e","testMutation","modelName","err","jsx","jsxs","Cpu","EyeOff","Eye","m","CheckCircle","XCircle","Loader2","Zap","Save"],"mappings":"8XAoBA,eAAeA,GAAiC,CAC9C,MAAMC,EAAM,MAAM,MAAM,gBAAgB,EACxC,GAAI,CAACA,EAAI,GAAI,MAAM,IAAI,MAAM,wBAAwB,EACrD,OAAOA,EAAI,KAAA,CACb,CAEA,eAAeC,EAAYC,EAAkBC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@@
1
- import{r as d,j as e}from"./react-vendor-CSp-GLFF.js";import{b as N,u as p,c as v}from"./query-C99w429o.js";import{D as w}from"./Drawer-DOUcx6m1.js";import{M as b}from"./MarkdownRenderer-CCIz1MOz.js";import{u as A}from"./index-CIRlno4E.js";import{a as C}from"./auth-Bnf8ZcqN.js";import{B as j,s as k,t as E,X as F,u as q}from"./lucide-BanPULT1.js";import"./vendor-CMMjVdZs.js";import"./syntax-highlighter-44FakypI.js";import"./react-router-I-HqunH7.js";async function S(){const n=await fetch("/api/agents");if(!n.ok)throw new Error("Failed to fetch agents");const a=await n.json();return Array.isArray(a)?a:[...a.official||[],...a.user||[]]}async function K(n){const a=await fetch(`/api/agents/${n}`);if(!a.ok)throw new Error("Failed to fetch");return a.json()}async function M(n,a){if(!(await C(`/api/agents/${n}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:a})})).ok)throw new Error("Failed to save")}function U(){const n=N(),a=A(),{data:r,isLoading:y}=p({queryKey:["agents"],queryFn:S}),[l,m]=d.useState(null),[g,o]=d.useState(!1),[h,x]=d.useState(""),{data:t}=p({queryKey:["agent-detail",l],queryFn:()=>K(l),enabled:!!l});d.useEffect(()=>{t!=null&&t.content&&x(t.content),o(!1)},[t]);const c=v({mutationFn:s=>M(s.name,s.content),onSuccess:()=>{a.success("Agent 已保存"),o(!1),n.invalidateQueries({queryKey:["agent-detail",l]}),n.invalidateQueries({queryKey:["agents"]})},onError:s=>a.error(`保存失败: ${s.message}`)}),u=s=>s?typeof s=="string"?s.split(",").map(i=>i.trim()):s:[];return y?e.jsx("div",{className:"bg-white rounded-lg shadow p-6",children:"加载中..."}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Agent 管理"}),e.jsxs("div",{className:"text-sm text-gray-500",children:["共 ",(r==null?void 0:r.length)||0," 个 Agent"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:r==null?void 0:r.map(s=>{const i=u(s.tools);return e.jsxs("div",{className:"bg-white rounded-lg shadow p-5 hover:shadow-md transition-shadow cursor-pointer",onClick:()=>m(s.name),children:[e.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-indigo-100 flex items-center justify-center flex-shrink-0",children:e.jsx(j,{className:"h-5 w-5 text-indigo-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold text-gray-900 truncate",children:s.name}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 line-clamp-2",children:s.description||"(无描述)"})]})]}),i.length>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-100",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500 mb-2",children:[e.jsx(k,{className:"h-3 w-3"}),"可用工具 (",i.length,")"]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[i.slice(0,5).map(f=>e.jsx("span",{className:"px-2 py-0.5 text-xs bg-gray-100 text-gray-700 rounded",children:f},f)),i.length>5&&e.jsxs("span",{className:"text-xs text-gray-400",children:["+",i.length-5]})]})]})]},s.name)})}),e.jsx(w,{open:l!==null,onClose:()=>{m(null),o(!1)},title:`Agent: ${l}`,width:"w-[800px]",children:t&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(j,{className:"h-5 w-5 text-indigo-600"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:t.name}),t.version&&e.jsxs("span",{className:"text-xs text-gray-500",children:["v",t.version]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"描述"}),e.jsx("div",{className:"text-sm text-gray-800",children:t.description})]}),t.tools&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"可用工具"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:u(t.tools).map(s=>e.jsx("span",{className:"px-2 py-0.5 text-xs bg-gray-100 text-gray-700 rounded",children:s},s))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"text-xs text-gray-500",children:"完整内容 (Markdown)"}),e.jsx("div",{className:"flex items-center gap-2",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>{o(!1),x(t.content||"")},className:"inline-flex items-center gap-1 text-xs text-gray-600 hover:text-gray-700",children:[e.jsx(F,{className:"h-3 w-3"}),"取消"]}),e.jsxs("button",{onClick:()=>c.mutate({name:t.name,content:h}),disabled:c.isPending,className:"inline-flex items-center gap-1 text-xs bg-indigo-600 text-white px-2 py-1 rounded hover:bg-indigo-700 disabled:bg-gray-400",children:[e.jsx(q,{className:"h-3 w-3"}),c.isPending?"保存中...":"保存"]})]}):e.jsxs("button",{onClick:()=>o(!0),className:"inline-flex items-center gap-1 text-xs text-indigo-600 hover:text-indigo-700",children:[e.jsx(E,{className:"h-3 w-3"}),"编辑"]})})]}),g?e.jsx("textarea",{value:h,onChange:s=>x(s.target.value),className:"w-full font-mono text-xs bg-gray-50 rounded p-3 border border-gray-300 focus:border-indigo-500 focus:outline-none",rows:20}):e.jsx("div",{className:"bg-white rounded p-3 border border-gray-200 max-h-[500px] overflow-y-auto",children:e.jsx(b,{content:t.content||""})}),c.isError&&e.jsxs("div",{className:"text-xs text-red-600 mt-1",children:["保存失败:",c.error.message]})]})]})})]})}export{U as default};
2
- //# sourceMappingURL=Agents-FyKzsN-g.js.map
1
+ import{r as d,j as e}from"./react-vendor-CSp-GLFF.js";import{b as N,u as p,c as v}from"./query-C99w429o.js";import{D as w}from"./Drawer-DOUcx6m1.js";import{M as b}from"./MarkdownRenderer-CCIz1MOz.js";import{u as A}from"./index-DJK5beK6.js";import{a as C}from"./auth-Bnf8ZcqN.js";import{B as j,s as k,t as E,X as F,u as q}from"./lucide-BanPULT1.js";import"./vendor-CMMjVdZs.js";import"./syntax-highlighter-44FakypI.js";import"./react-router-I-HqunH7.js";async function S(){const n=await fetch("/api/agents");if(!n.ok)throw new Error("Failed to fetch agents");const a=await n.json();return Array.isArray(a)?a:[...a.official||[],...a.user||[]]}async function K(n){const a=await fetch(`/api/agents/${n}`);if(!a.ok)throw new Error("Failed to fetch");return a.json()}async function M(n,a){if(!(await C(`/api/agents/${n}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:a})})).ok)throw new Error("Failed to save")}function U(){const n=N(),a=A(),{data:r,isLoading:y}=p({queryKey:["agents"],queryFn:S}),[l,m]=d.useState(null),[g,o]=d.useState(!1),[h,x]=d.useState(""),{data:t}=p({queryKey:["agent-detail",l],queryFn:()=>K(l),enabled:!!l});d.useEffect(()=>{t!=null&&t.content&&x(t.content),o(!1)},[t]);const c=v({mutationFn:s=>M(s.name,s.content),onSuccess:()=>{a.success("Agent 已保存"),o(!1),n.invalidateQueries({queryKey:["agent-detail",l]}),n.invalidateQueries({queryKey:["agents"]})},onError:s=>a.error(`保存失败: ${s.message}`)}),u=s=>s?typeof s=="string"?s.split(",").map(i=>i.trim()):s:[];return y?e.jsx("div",{className:"bg-white rounded-lg shadow p-6",children:"加载中..."}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Agent 管理"}),e.jsxs("div",{className:"text-sm text-gray-500",children:["共 ",(r==null?void 0:r.length)||0," 个 Agent"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:r==null?void 0:r.map(s=>{const i=u(s.tools);return e.jsxs("div",{className:"bg-white rounded-lg shadow p-5 hover:shadow-md transition-shadow cursor-pointer",onClick:()=>m(s.name),children:[e.jsxs("div",{className:"flex items-start gap-3 mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-indigo-100 flex items-center justify-center flex-shrink-0",children:e.jsx(j,{className:"h-5 w-5 text-indigo-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold text-gray-900 truncate",children:s.name}),e.jsx("p",{className:"text-xs text-gray-500 mt-1 line-clamp-2",children:s.description||"(无描述)"})]})]}),i.length>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-100",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-gray-500 mb-2",children:[e.jsx(k,{className:"h-3 w-3"}),"可用工具 (",i.length,")"]}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[i.slice(0,5).map(f=>e.jsx("span",{className:"px-2 py-0.5 text-xs bg-gray-100 text-gray-700 rounded",children:f},f)),i.length>5&&e.jsxs("span",{className:"text-xs text-gray-400",children:["+",i.length-5]})]})]})]},s.name)})}),e.jsx(w,{open:l!==null,onClose:()=>{m(null),o(!1)},title:`Agent: ${l}`,width:"w-[800px]",children:t&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(j,{className:"h-5 w-5 text-indigo-600"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:t.name}),t.version&&e.jsxs("span",{className:"text-xs text-gray-500",children:["v",t.version]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"描述"}),e.jsx("div",{className:"text-sm text-gray-800",children:t.description})]}),t.tools&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"可用工具"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:u(t.tools).map(s=>e.jsx("span",{className:"px-2 py-0.5 text-xs bg-gray-100 text-gray-700 rounded",children:s},s))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"text-xs text-gray-500",children:"完整内容 (Markdown)"}),e.jsx("div",{className:"flex items-center gap-2",children:g?e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>{o(!1),x(t.content||"")},className:"inline-flex items-center gap-1 text-xs text-gray-600 hover:text-gray-700",children:[e.jsx(F,{className:"h-3 w-3"}),"取消"]}),e.jsxs("button",{onClick:()=>c.mutate({name:t.name,content:h}),disabled:c.isPending,className:"inline-flex items-center gap-1 text-xs bg-indigo-600 text-white px-2 py-1 rounded hover:bg-indigo-700 disabled:bg-gray-400",children:[e.jsx(q,{className:"h-3 w-3"}),c.isPending?"保存中...":"保存"]})]}):e.jsxs("button",{onClick:()=>o(!0),className:"inline-flex items-center gap-1 text-xs text-indigo-600 hover:text-indigo-700",children:[e.jsx(E,{className:"h-3 w-3"}),"编辑"]})})]}),g?e.jsx("textarea",{value:h,onChange:s=>x(s.target.value),className:"w-full font-mono text-xs bg-gray-50 rounded p-3 border border-gray-300 focus:border-indigo-500 focus:outline-none",rows:20}):e.jsx("div",{className:"bg-white rounded p-3 border border-gray-200 max-h-[500px] overflow-y-auto",children:e.jsx(b,{content:t.content||""})}),c.isError&&e.jsxs("div",{className:"text-xs text-red-600 mt-1",children:["保存失败:",c.error.message]})]})]})})]})}export{U as default};
2
+ //# sourceMappingURL=Agents-bNNGbQnL.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Agents-FyKzsN-g.js","sources":["../../src/pages/Agents.tsx"],"sourcesContent":["import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'\nimport { useState, useEffect } from 'react'\nimport { Bot, FileCode, Edit2, Save, X } from 'lucide-react'\nimport Drawer from '../components/Drawer'\nimport MarkdownRenderer from '../components/MarkdownRenderer'\nimport { useToast } from '../components/Toast'\nimport { authFetch } from '../utils/auth'\n\ninterface Agent {\n name: string\n description: string\n tools?: string | string[]\n content?: string\n version?: string\n category?: string\n source?: string\n}\n\ninterface AgentsResponse {\n official?: Agent[]\n user?: Agent[]\n}\n\nasync function fetchAgents(): Promise<Agent[]> {\n const res = await fetch('/api/agents')\n if (!res.ok) throw new Error('Failed to fetch agents')\n const data: AgentsResponse | Agent[] = await res.json()\n // API 可能返回 { official: [...], user: [...] } 或直接返回数组\n if (Array.isArray(data)) return data\n return [...(data.official || []), ...(data.user || [])]\n}\n\nasync function fetchAgentDetail(name: string): Promise<Agent> {\n const res = await fetch(`/api/agents/${name}`)\n if (!res.ok) throw new Error('Failed to fetch')\n return res.json()\n}\n\nasync function saveAgent(name: string, content: string): Promise<void> {\n const res = await authFetch(`/api/agents/${name}`, {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ content }),\n })\n if (!res.ok) throw new Error('Failed to save')\n}\n\nexport default function Agents() {\n const queryClient = useQueryClient()\n const toast = useToast()\n const { data: agents, isLoading } = useQuery({\n queryKey: ['agents'],\n queryFn: fetchAgents,\n })\n\n const [selectedAgent, setSelectedAgent] = useState<string | null>(null)\n const [editing, setEditing] = useState(false)\n const [editContent, setEditContent] = useState('')\n\n const { data: detail } = useQuery({\n queryKey: ['agent-detail', selectedAgent],\n queryFn: () => fetchAgentDetail(selectedAgent!),\n enabled: !!selectedAgent,\n })\n\n useEffect(() => {\n if (detail?.content) setEditContent(detail.content)\n setEditing(false)\n }, [detail])\n\n const mutation = useMutation({\n mutationFn: (vars: { name: string; content: string }) => saveAgent(vars.name, vars.content),\n onSuccess: () => {\n toast.success('Agent 已保存')\n setEditing(false)\n queryClient.invalidateQueries({ queryKey: ['agent-detail', selectedAgent] })\n queryClient.invalidateQueries({ queryKey: ['agents'] })\n },\n onError: (e: Error) => toast.error(`保存失败: ${e.message}`),\n })\n\n const renderTools = (tools?: string | string[]) => {\n if (!tools) return []\n if (typeof tools === 'string') return tools.split(',').map(t => t.trim())\n return tools\n }\n\n if (isLoading) {\n return <div className=\"bg-white rounded-lg shadow p-6\">加载中...</div>\n }\n\n return (\n <div>\n <div className=\"flex items-center justify-between mb-6\">\n <h1 className=\"text-2xl font-bold text-gray-900\">Agent 管理</h1>\n <div className=\"text-sm text-gray-500\">共 {agents?.length || 0} 个 Agent</div>\n </div>\n\n <div className=\"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4\">\n {agents?.map((agent) => {\n const tools = renderTools(agent.tools)\n return (\n <div\n key={agent.name}\n className=\"bg-white rounded-lg shadow p-5 hover:shadow-md transition-shadow cursor-pointer\"\n onClick={() => setSelectedAgent(agent.name)}\n >\n <div className=\"flex items-start gap-3 mb-3\">\n <div className=\"w-10 h-10 rounded-lg bg-indigo-100 flex items-center justify-center flex-shrink-0\">\n <Bot className=\"h-5 w-5 text-indigo-600\" />\n </div>\n <div className=\"flex-1 min-w-0\">\n <h3 className=\"font-semibold text-gray-900 truncate\">{agent.name}</h3>\n <p className=\"text-xs text-gray-500 mt-1 line-clamp-2\">\n {agent.description || '(无描述)'}\n </p>\n </div>\n </div>\n\n {tools.length > 0 && (\n <div className=\"mt-3 pt-3 border-t border-gray-100\">\n <div className=\"flex items-center gap-1 text-xs text-gray-500 mb-2\">\n <FileCode className=\"h-3 w-3\" />可用工具 ({tools.length})\n </div>\n <div className=\"flex flex-wrap gap-1\">\n {tools.slice(0, 5).map((tool) => (\n <span key={tool} className=\"px-2 py-0.5 text-xs bg-gray-100 text-gray-700 rounded\">\n {tool}\n </span>\n ))}\n {tools.length > 5 && (\n <span className=\"text-xs text-gray-400\">+{tools.length - 5}</span>\n )}\n </div>\n </div>\n )}\n </div>\n )\n })}\n </div>\n\n {/* Agent Detail Drawer */}\n <Drawer\n open={selectedAgent !== null}\n onClose={() => { setSelectedAgent(null); setEditing(false) }}\n title={`Agent: ${selectedAgent}`}\n width=\"w-[800px]\"\n >\n {detail && (\n <div className=\"space-y-4\">\n <div className=\"flex items-center gap-2 mb-2\">\n <Bot className=\"h-5 w-5 text-indigo-600\" />\n <h3 className=\"text-lg font-semibold text-gray-900\">{detail.name}</h3>\n {detail.version && (\n <span className=\"text-xs text-gray-500\">v{detail.version}</span>\n )}\n </div>\n\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">描述</div>\n <div className=\"text-sm text-gray-800\">{detail.description}</div>\n </div>\n\n {detail.tools && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">可用工具</div>\n <div className=\"flex flex-wrap gap-1\">\n {renderTools(detail.tools).map(tool => (\n <span key={tool} className=\"px-2 py-0.5 text-xs bg-gray-100 text-gray-700 rounded\">\n {tool}\n </span>\n ))}\n </div>\n </div>\n )}\n\n <div>\n <div className=\"flex items-center justify-between mb-2\">\n <div className=\"text-xs text-gray-500\">完整内容 (Markdown)</div>\n <div className=\"flex items-center gap-2\">\n {!editing ? (\n <button\n onClick={() => setEditing(true)}\n className=\"inline-flex items-center gap-1 text-xs text-indigo-600 hover:text-indigo-700\"\n >\n <Edit2 className=\"h-3 w-3\" />编辑\n </button>\n ) : (\n <>\n <button\n onClick={() => { setEditing(false); setEditContent(detail.content || '') }}\n className=\"inline-flex items-center gap-1 text-xs text-gray-600 hover:text-gray-700\"\n >\n <X className=\"h-3 w-3\" />取消\n </button>\n <button\n onClick={() => mutation.mutate({ name: detail.name, content: editContent })}\n disabled={mutation.isPending}\n className=\"inline-flex items-center gap-1 text-xs bg-indigo-600 text-white px-2 py-1 rounded hover:bg-indigo-700 disabled:bg-gray-400\"\n >\n <Save className=\"h-3 w-3\" />\n {mutation.isPending ? '保存中...' : '保存'}\n </button>\n </>\n )}\n </div>\n </div>\n {editing ? (\n <textarea\n value={editContent}\n onChange={(e) => setEditContent(e.target.value)}\n className=\"w-full font-mono text-xs bg-gray-50 rounded p-3 border border-gray-300 focus:border-indigo-500 focus:outline-none\"\n rows={20}\n />\n ) : (\n <div className=\"bg-white rounded p-3 border border-gray-200 max-h-[500px] overflow-y-auto\">\n <MarkdownRenderer content={detail.content || ''} />\n </div>\n )}\n {mutation.isError && (\n <div className=\"text-xs text-red-600 mt-1\">保存失败:{(mutation.error as Error).message}</div>\n )}\n </div>\n </div>\n )}\n </Drawer>\n </div>\n )\n}\n"],"names":["fetchAgents","res","data","fetchAgentDetail","name","saveAgent","content","authFetch","Agents","queryClient","useQueryClient","toast","useToast","agents","isLoading","useQuery","selectedAgent","setSelectedAgent","useState","editing","setEditing","editContent","setEditContent","detail","useEffect","mutation","useMutation","vars","e","renderTools","tools","t","jsx","jsxs","agent","Bot","FileCode","tool","Drawer","Fragment","X","Save","Edit2","MarkdownRenderer"],"mappings":"qcAuBA,eAAeA,GAAgC,CAC7C,MAAMC,EAAM,MAAM,MAAM,aAAa,EACrC,GAAI,CAACA,EAAI,GAAI,MAAM,IAAI,MAAM,wBAAwB,EACrD,MAAMC,EAAiC,MAAMD,EAAI,KAAA,EAEjD,OAAI,MAAM,QAAQC,CAAI,EAAUA,EACzB,CAAC,GAAIA,EAAK,UAAY,CAAA,EAAK,GAAIA,EAAK,MAAQ,EAAG,CACxD,CAEA,eAAeC,EAAiBC,EAA8B,CAC5D,MAAMH,EAAM,MAAM,MAAM,eAAeG,CAAI,EAAE,EAC7C,GAAI,CAACH,EAAI,GAAI,MAAM,IAAI,MAAM,iBAAiB,EAC9C,OAAOA,EAAI,KAAA,CACb,CAEA,eAAeI,EAAUD,EAAcE,EAAgC,CAMrE,GAAI,EALQ,MAAMC,EAAU,eAAeH,CAAI,GAAI,CACjD,OAAQ,MACR,QAAS,CAAE,eAAgB,kBAAA,EAC3B,KAAM,KAAK,UAAU,CAAE,QAAAE,EAAS,CAAA,CACjC,GACQ,GAAI,MAAM,IAAI,MAAM,gBAAgB,CAC/C,CAEA,SAAwBE,GAAS,CAC/B,MAAMC,EAAcC,EAAA,EACdC,EAAQC,EAAA,EACR,CAAE,KAAMC,EAAQ,UAAAC,CAAA,EAAcC,EAAS,CAC3C,SAAU,CAAC,QAAQ,EACnB,QAASf,CAAA,CACV,EAEK,CAACgB,EAAeC,CAAgB,EAAIC,EAAAA,SAAwB,IAAI,EAChE,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAS,EAAK,EACtC,CAACG,EAAaC,CAAc,EAAIJ,EAAAA,SAAS,EAAE,EAE3C,CAAE,KAAMK,CAAA,EAAWR,EAAS,CAChC,SAAU,CAAC,eAAgBC,CAAa,EACxC,QAAS,IAAMb,EAAiBa,CAAc,EAC9C,QAAS,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C,QAAS,IAAMb,EAAW,EAAI,EAC9B,UAAU,+EAEV,SAAA,CAAAY,EAAAA,IAACU,EAAA,CAAM,UAAU,SAAA,CAAU,EAAE,IAAA,CAAA,CAAA,CAkB/B,CAEJ,CAAA,EACF,EACCvB,EACCa,EAAAA,IAAC,WAAA,CACC,MAAOX,EACP,SAAWO,GAAMN,EAAeM,EAAE,OAAO,KAAK,EAC9C,UAAU,oHACV,KAAM,EAAA,CAAA,EAGRI,EAAAA,IAAC,MAAA,CAAI,UAAU,4EACb,SAAAA,EAAAA,IAACW,EAAA,CAAiB,QAASpB,EAAO,SAAW,EAAA,CAAI,CAAA,CACnD,EAEDE,EAAS,SACRQ,OAAC,MAAA,CAAI,UAAU,4BAA4B,SAAA,CAAA,QAAOR,EAAS,MAAgB,OAAA,CAAA,CAAQ,CAAA,CAAA,CAEvF,CAAA,CAAA,CACF,CAAA,CAAA,CAEJ,EACF,CAEJ"}
1
+ {"version":3,"file":"Agents-bNNGbQnL.js","sources":["../../src/pages/Agents.tsx"],"sourcesContent":["import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'\nimport { useState, useEffect } from 'react'\nimport { Bot, FileCode, Edit2, Save, X } from 'lucide-react'\nimport Drawer from '../components/Drawer'\nimport MarkdownRenderer from '../components/MarkdownRenderer'\nimport { useToast } from '../components/Toast'\nimport { authFetch } from '../utils/auth'\n\ninterface Agent {\n name: string\n description: string\n tools?: string | string[]\n content?: string\n version?: string\n category?: string\n source?: string\n}\n\ninterface AgentsResponse {\n official?: Agent[]\n user?: Agent[]\n}\n\nasync function fetchAgents(): Promise<Agent[]> {\n const res = await fetch('/api/agents')\n if (!res.ok) throw new Error('Failed to fetch agents')\n const data: AgentsResponse | Agent[] = await res.json()\n // API 可能返回 { official: [...], user: [...] } 或直接返回数组\n if (Array.isArray(data)) return data\n return [...(data.official || []), ...(data.user || [])]\n}\n\nasync function fetchAgentDetail(name: string): Promise<Agent> {\n const res = await fetch(`/api/agents/${name}`)\n if (!res.ok) throw new Error('Failed to fetch')\n return res.json()\n}\n\nasync function saveAgent(name: string, content: string): Promise<void> {\n const res = await authFetch(`/api/agents/${name}`, {\n method: 'PUT',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ content }),\n })\n if (!res.ok) throw new Error('Failed to save')\n}\n\nexport default function Agents() {\n const queryClient = useQueryClient()\n const toast = useToast()\n const { data: agents, isLoading } = useQuery({\n queryKey: ['agents'],\n queryFn: fetchAgents,\n })\n\n const [selectedAgent, setSelectedAgent] = useState<string | null>(null)\n const [editing, setEditing] = useState(false)\n const [editContent, setEditContent] = useState('')\n\n const { data: detail } = useQuery({\n queryKey: ['agent-detail', selectedAgent],\n queryFn: () => fetchAgentDetail(selectedAgent!),\n enabled: !!selectedAgent,\n })\n\n useEffect(() => {\n if (detail?.content) setEditContent(detail.content)\n setEditing(false)\n }, [detail])\n\n const mutation = useMutation({\n mutationFn: (vars: { name: string; content: string }) => saveAgent(vars.name, vars.content),\n onSuccess: () => {\n toast.success('Agent 已保存')\n setEditing(false)\n queryClient.invalidateQueries({ queryKey: ['agent-detail', selectedAgent] })\n queryClient.invalidateQueries({ queryKey: ['agents'] })\n },\n onError: (e: Error) => toast.error(`保存失败: ${e.message}`),\n })\n\n const renderTools = (tools?: string | string[]) => {\n if (!tools) return []\n if (typeof tools === 'string') return tools.split(',').map(t => t.trim())\n return tools\n }\n\n if (isLoading) {\n return <div className=\"bg-white rounded-lg shadow p-6\">加载中...</div>\n }\n\n return (\n <div>\n <div className=\"flex items-center justify-between mb-6\">\n <h1 className=\"text-2xl font-bold text-gray-900\">Agent 管理</h1>\n <div className=\"text-sm text-gray-500\">共 {agents?.length || 0} 个 Agent</div>\n </div>\n\n <div className=\"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4\">\n {agents?.map((agent) => {\n const tools = renderTools(agent.tools)\n return (\n <div\n key={agent.name}\n className=\"bg-white rounded-lg shadow p-5 hover:shadow-md transition-shadow cursor-pointer\"\n onClick={() => setSelectedAgent(agent.name)}\n >\n <div className=\"flex items-start gap-3 mb-3\">\n <div className=\"w-10 h-10 rounded-lg bg-indigo-100 flex items-center justify-center flex-shrink-0\">\n <Bot className=\"h-5 w-5 text-indigo-600\" />\n </div>\n <div className=\"flex-1 min-w-0\">\n <h3 className=\"font-semibold text-gray-900 truncate\">{agent.name}</h3>\n <p className=\"text-xs text-gray-500 mt-1 line-clamp-2\">\n {agent.description || '(无描述)'}\n </p>\n </div>\n </div>\n\n {tools.length > 0 && (\n <div className=\"mt-3 pt-3 border-t border-gray-100\">\n <div className=\"flex items-center gap-1 text-xs text-gray-500 mb-2\">\n <FileCode className=\"h-3 w-3\" />可用工具 ({tools.length})\n </div>\n <div className=\"flex flex-wrap gap-1\">\n {tools.slice(0, 5).map((tool) => (\n <span key={tool} className=\"px-2 py-0.5 text-xs bg-gray-100 text-gray-700 rounded\">\n {tool}\n </span>\n ))}\n {tools.length > 5 && (\n <span className=\"text-xs text-gray-400\">+{tools.length - 5}</span>\n )}\n </div>\n </div>\n )}\n </div>\n )\n })}\n </div>\n\n {/* Agent Detail Drawer */}\n <Drawer\n open={selectedAgent !== null}\n onClose={() => { setSelectedAgent(null); setEditing(false) }}\n title={`Agent: ${selectedAgent}`}\n width=\"w-[800px]\"\n >\n {detail && (\n <div className=\"space-y-4\">\n <div className=\"flex items-center gap-2 mb-2\">\n <Bot className=\"h-5 w-5 text-indigo-600\" />\n <h3 className=\"text-lg font-semibold text-gray-900\">{detail.name}</h3>\n {detail.version && (\n <span className=\"text-xs text-gray-500\">v{detail.version}</span>\n )}\n </div>\n\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">描述</div>\n <div className=\"text-sm text-gray-800\">{detail.description}</div>\n </div>\n\n {detail.tools && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">可用工具</div>\n <div className=\"flex flex-wrap gap-1\">\n {renderTools(detail.tools).map(tool => (\n <span key={tool} className=\"px-2 py-0.5 text-xs bg-gray-100 text-gray-700 rounded\">\n {tool}\n </span>\n ))}\n </div>\n </div>\n )}\n\n <div>\n <div className=\"flex items-center justify-between mb-2\">\n <div className=\"text-xs text-gray-500\">完整内容 (Markdown)</div>\n <div className=\"flex items-center gap-2\">\n {!editing ? (\n <button\n onClick={() => setEditing(true)}\n className=\"inline-flex items-center gap-1 text-xs text-indigo-600 hover:text-indigo-700\"\n >\n <Edit2 className=\"h-3 w-3\" />编辑\n </button>\n ) : (\n <>\n <button\n onClick={() => { setEditing(false); setEditContent(detail.content || '') }}\n className=\"inline-flex items-center gap-1 text-xs text-gray-600 hover:text-gray-700\"\n >\n <X className=\"h-3 w-3\" />取消\n </button>\n <button\n onClick={() => mutation.mutate({ name: detail.name, content: editContent })}\n disabled={mutation.isPending}\n className=\"inline-flex items-center gap-1 text-xs bg-indigo-600 text-white px-2 py-1 rounded hover:bg-indigo-700 disabled:bg-gray-400\"\n >\n <Save className=\"h-3 w-3\" />\n {mutation.isPending ? '保存中...' : '保存'}\n </button>\n </>\n )}\n </div>\n </div>\n {editing ? (\n <textarea\n value={editContent}\n onChange={(e) => setEditContent(e.target.value)}\n className=\"w-full font-mono text-xs bg-gray-50 rounded p-3 border border-gray-300 focus:border-indigo-500 focus:outline-none\"\n rows={20}\n />\n ) : (\n <div className=\"bg-white rounded p-3 border border-gray-200 max-h-[500px] overflow-y-auto\">\n <MarkdownRenderer content={detail.content || ''} />\n </div>\n )}\n {mutation.isError && (\n <div className=\"text-xs text-red-600 mt-1\">保存失败:{(mutation.error as Error).message}</div>\n )}\n </div>\n </div>\n )}\n </Drawer>\n </div>\n )\n}\n"],"names":["fetchAgents","res","data","fetchAgentDetail","name","saveAgent","content","authFetch","Agents","queryClient","useQueryClient","toast","useToast","agents","isLoading","useQuery","selectedAgent","setSelectedAgent","useState","editing","setEditing","editContent","setEditContent","detail","useEffect","mutation","useMutation","vars","e","renderTools","tools","t","jsx","jsxs","agent","Bot","FileCode","tool","Drawer","Fragment","X","Save","Edit2","MarkdownRenderer"],"mappings":"qcAuB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,CAAA,CAAA,CAkB/B,CAEJ,CAAA,EACF,EACCvB,EACCa,EAAAA,IAAC,WAAA,CACC,MAAOX,EACP,SAAWO,GAAMN,EAAeM,EAAE,OAAO,KAAK,EAC9C,UAAU,oHACV,KAAM,EAAA,CAAA,EAGRI,EAAAA,IAAC,MAAA,CAAI,UAAU,4EACb,SAAAA,EAAAA,IAACW,EAAA,CAAiB,QAASpB,EAAO,SAAW,EAAA,CAAI,CAAA,CACnD,EAEDE,EAAS,SACRQ,OAAC,MAAA,CAAI,UAAU,4BAA4B,SAAA,CAAA,QAAOR,EAAS,MAAgB,OAAA,CAAA,CAAQ,CAAA,CAAA,CAEvF,CAAA,CAAA,CACF,CAAA,CAAA,CAEJ,EACF,CAEJ"}
@@ -1,2 +1,2 @@
1
- import{r as n,j as e}from"./react-vendor-CSp-GLFF.js";import{u as N}from"./query-C99w429o.js";import{d as u}from"./vendor-CMMjVdZs.js";import{D as w}from"./Drawer-DOUcx6m1.js";import{C as g}from"./CodeBlock--H53gk46.js";import{S as _,g as k,d as S,a as C}from"./export-CbQTOt71.js";import{u as E}from"./index-CIRlno4E.js";import{k as P,D as U,A as T}from"./lucide-BanPULT1.js";import{f as y}from"./date-fns-CZ_bHujz.js";import"./syntax-highlighter-44FakypI.js";import"./react-router-I-HqunH7.js";async function D(i){const c=`/api/events?limit=500${i?`&hook_type=${i}`:""}`,r=await fetch(c);if(!r.ok)throw new Error("Failed to fetch events");return r.json()}const H=["","UserPromptSubmit","PreToolUse","PostToolUse","Stop","Notification"];function B(){const[i,c]=n.useState(""),[r,j]=n.useState(""),[s,p]=n.useState(null),[v,m]=n.useState(!1),f=E(),{data:x,isLoading:b}=N({queryKey:["events",i],queryFn:()=>D(i),refetchInterval:5e3}),o=n.useMemo(()=>{if(!x)return[];if(!r.trim())return x;const t=r.toLowerCase();return x.filter(l=>{var d,a;return((d=l.tool_name)==null?void 0:d.toLowerCase().includes(t))||((a=l.user_prompt)==null?void 0:a.toLowerCase().includes(t))||l.session_id.toLowerCase().includes(t)||JSON.stringify(l.tool_input||"").toLowerCase().includes(t)})},[x,r]),h=t=>{const l=k();if(t==="json")S(`events-${l}.json`,o);else{const d=o.map(a=>({event_id:a.event_id,session_id:a.session_id,timestamp:a.timestamp,hook_type:a.hook_type,tool_name:a.tool_name||"",user_prompt:a.user_prompt||"",tool_input:a.tool_input?JSON.stringify(a.tool_input).slice(0,500):""}));C(`events-${l}.csv`,d)}f.success(`已导出 ${o.length} 条事件`),m(!1)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"事件"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(_,{value:r,onChange:j,placeholder:"搜索提示/工具/session...",className:"w-64"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(P,{className:"h-4 w-4 text-gray-500"}),e.jsx("select",{value:i,onChange:t=>c(t.target.value),className:"text-sm border border-gray-300 rounded-md px-2 py-1.5 bg-white",children:H.map(t=>e.jsx("option",{value:t,children:t||"全部类型"},t))})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>m(t=>!t),disabled:o.length===0,className:"inline-flex items-center gap-1 px-3 py-1.5 text-sm bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50",children:[e.jsx(U,{className:"h-4 w-4"}),"导出"]}),v&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>m(!1)}),e.jsxs("div",{className:"absolute right-0 mt-1 bg-white border border-gray-200 rounded-md shadow-lg z-20",children:[e.jsx("button",{onClick:()=>h("json"),className:"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50",children:"导出为 JSON"}),e.jsx("button",{onClick:()=>h("csv"),className:"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50",children:"导出为 CSV"})]})]})]})]})]}),e.jsxs("div",{className:"text-sm text-gray-500 mb-3",children:["显示 ",o.length," 条 ",r&&"(已过滤)"]}),e.jsx("div",{className:"bg-white rounded-lg shadow overflow-hidden",children:b?e.jsx("div",{className:"p-6 text-gray-600",children:"加载中..."}):e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"时间"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"类型"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"工具"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"详情"})]})}),e.jsxs("tbody",{className:"bg-white divide-y divide-gray-200",children:[o.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 cursor-pointer",onClick:()=>p(t),children:[e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-xs font-mono text-gray-500",children:t.timestamp?y(new Date(t.timestamp),"HH:mm:ss"):"-"}),e.jsx("td",{className:"px-4 py-2 whitespace-nowrap",children:e.jsx("span",{className:u("px-2 py-0.5 text-xs font-medium rounded",t.hook_type==="UserPromptSubmit"&&"bg-purple-100 text-purple-700",t.hook_type==="PreToolUse"&&"bg-blue-100 text-blue-700",t.hook_type==="PostToolUse"&&"bg-green-100 text-green-700",t.hook_type==="Stop"&&"bg-gray-100 text-gray-700",t.hook_type==="Notification"&&"bg-yellow-100 text-yellow-700"),children:t.hook_type})}),e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-sm text-gray-700",children:t.tool_name||"-"}),e.jsx("td",{className:"px-4 py-2 max-w-xl",children:e.jsx("p",{className:"text-xs text-gray-600 truncate",children:t.user_prompt||(t.tool_input?JSON.stringify(t.tool_input).slice(0,100):"-")})})]},t.event_id)),o.length===0&&e.jsx("tr",{children:e.jsxs("td",{colSpan:4,className:"px-4 py-12 text-center text-gray-500",children:[e.jsx(T,{className:"h-12 w-12 text-gray-300 mx-auto mb-2"}),r?"无匹配结果":"暂无事件"]})})]})]})}),e.jsx(w,{open:s!==null,onClose:()=>p(null),title:"事件详情",children:s&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"事件 ID"}),e.jsx("div",{className:"text-sm font-mono text-gray-900",children:s.event_id})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"类型"}),e.jsx("span",{className:u("px-2 py-1 text-xs font-medium rounded",s.hook_type==="UserPromptSubmit"&&"bg-purple-100 text-purple-700",s.hook_type==="PreToolUse"&&"bg-blue-100 text-blue-700",s.hook_type==="PostToolUse"&&"bg-green-100 text-green-700"),children:s.hook_type})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"时间"}),e.jsx("div",{className:"text-sm text-gray-900",children:s.timestamp?y(new Date(s.timestamp),"yyyy-MM-dd HH:mm:ss"):"-"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Session"}),e.jsx("div",{className:"text-sm font-mono text-gray-700",children:s.session_id})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"项目路径"}),e.jsx("div",{className:"text-sm font-mono text-gray-700 break-all",children:s.project_path})]}),s.tool_name&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"工具"}),e.jsx("div",{className:"text-sm text-gray-900",children:s.tool_name})]}),s.user_prompt&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"用户提示"}),e.jsx("div",{className:"bg-purple-50 rounded p-3 text-sm text-gray-800 whitespace-pre-wrap",children:s.user_prompt})]}),s.tool_input&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"工具输入"}),e.jsx(g,{data:s.tool_input,language:"json",maxHeight:"300px"})]}),s.tool_output&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"工具输出"}),e.jsx(g,{data:s.tool_output,language:typeof s.tool_output=="string"?"text":"json",maxHeight:"400px"})]})]})})]})}export{B as default};
2
- //# sourceMappingURL=Events-C2OCOKAD.js.map
1
+ import{r as n,j as e}from"./react-vendor-CSp-GLFF.js";import{u as N}from"./query-C99w429o.js";import{d as u}from"./vendor-CMMjVdZs.js";import{D as w}from"./Drawer-DOUcx6m1.js";import{C as g}from"./CodeBlock--H53gk46.js";import{S as _,g as k,d as S,a as C}from"./export-CbQTOt71.js";import{u as E}from"./index-DJK5beK6.js";import{k as P,D as U,A as T}from"./lucide-BanPULT1.js";import{f as y}from"./date-fns-CZ_bHujz.js";import"./syntax-highlighter-44FakypI.js";import"./react-router-I-HqunH7.js";async function D(i){const c=`/api/events?limit=500${i?`&hook_type=${i}`:""}`,r=await fetch(c);if(!r.ok)throw new Error("Failed to fetch events");return r.json()}const H=["","UserPromptSubmit","PreToolUse","PostToolUse","Stop","Notification"];function B(){const[i,c]=n.useState(""),[r,j]=n.useState(""),[s,p]=n.useState(null),[v,m]=n.useState(!1),f=E(),{data:x,isLoading:b}=N({queryKey:["events",i],queryFn:()=>D(i),refetchInterval:5e3}),o=n.useMemo(()=>{if(!x)return[];if(!r.trim())return x;const t=r.toLowerCase();return x.filter(l=>{var d,a;return((d=l.tool_name)==null?void 0:d.toLowerCase().includes(t))||((a=l.user_prompt)==null?void 0:a.toLowerCase().includes(t))||l.session_id.toLowerCase().includes(t)||JSON.stringify(l.tool_input||"").toLowerCase().includes(t)})},[x,r]),h=t=>{const l=k();if(t==="json")S(`events-${l}.json`,o);else{const d=o.map(a=>({event_id:a.event_id,session_id:a.session_id,timestamp:a.timestamp,hook_type:a.hook_type,tool_name:a.tool_name||"",user_prompt:a.user_prompt||"",tool_input:a.tool_input?JSON.stringify(a.tool_input).slice(0,500):""}));C(`events-${l}.csv`,d)}f.success(`已导出 ${o.length} 条事件`),m(!1)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"事件"}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(_,{value:r,onChange:j,placeholder:"搜索提示/工具/session...",className:"w-64"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(P,{className:"h-4 w-4 text-gray-500"}),e.jsx("select",{value:i,onChange:t=>c(t.target.value),className:"text-sm border border-gray-300 rounded-md px-2 py-1.5 bg-white",children:H.map(t=>e.jsx("option",{value:t,children:t||"全部类型"},t))})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>m(t=>!t),disabled:o.length===0,className:"inline-flex items-center gap-1 px-3 py-1.5 text-sm bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50",children:[e.jsx(U,{className:"h-4 w-4"}),"导出"]}),v&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>m(!1)}),e.jsxs("div",{className:"absolute right-0 mt-1 bg-white border border-gray-200 rounded-md shadow-lg z-20",children:[e.jsx("button",{onClick:()=>h("json"),className:"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50",children:"导出为 JSON"}),e.jsx("button",{onClick:()=>h("csv"),className:"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50",children:"导出为 CSV"})]})]})]})]})]}),e.jsxs("div",{className:"text-sm text-gray-500 mb-3",children:["显示 ",o.length," 条 ",r&&"(已过滤)"]}),e.jsx("div",{className:"bg-white rounded-lg shadow overflow-hidden",children:b?e.jsx("div",{className:"p-6 text-gray-600",children:"加载中..."}):e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"时间"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"类型"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"工具"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"详情"})]})}),e.jsxs("tbody",{className:"bg-white divide-y divide-gray-200",children:[o.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50 cursor-pointer",onClick:()=>p(t),children:[e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-xs font-mono text-gray-500",children:t.timestamp?y(new Date(t.timestamp),"HH:mm:ss"):"-"}),e.jsx("td",{className:"px-4 py-2 whitespace-nowrap",children:e.jsx("span",{className:u("px-2 py-0.5 text-xs font-medium rounded",t.hook_type==="UserPromptSubmit"&&"bg-purple-100 text-purple-700",t.hook_type==="PreToolUse"&&"bg-blue-100 text-blue-700",t.hook_type==="PostToolUse"&&"bg-green-100 text-green-700",t.hook_type==="Stop"&&"bg-gray-100 text-gray-700",t.hook_type==="Notification"&&"bg-yellow-100 text-yellow-700"),children:t.hook_type})}),e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-sm text-gray-700",children:t.tool_name||"-"}),e.jsx("td",{className:"px-4 py-2 max-w-xl",children:e.jsx("p",{className:"text-xs text-gray-600 truncate",children:t.user_prompt||(t.tool_input?JSON.stringify(t.tool_input).slice(0,100):"-")})})]},t.event_id)),o.length===0&&e.jsx("tr",{children:e.jsxs("td",{colSpan:4,className:"px-4 py-12 text-center text-gray-500",children:[e.jsx(T,{className:"h-12 w-12 text-gray-300 mx-auto mb-2"}),r?"无匹配结果":"暂无事件"]})})]})]})}),e.jsx(w,{open:s!==null,onClose:()=>p(null),title:"事件详情",children:s&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"事件 ID"}),e.jsx("div",{className:"text-sm font-mono text-gray-900",children:s.event_id})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"类型"}),e.jsx("span",{className:u("px-2 py-1 text-xs font-medium rounded",s.hook_type==="UserPromptSubmit"&&"bg-purple-100 text-purple-700",s.hook_type==="PreToolUse"&&"bg-blue-100 text-blue-700",s.hook_type==="PostToolUse"&&"bg-green-100 text-green-700"),children:s.hook_type})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"时间"}),e.jsx("div",{className:"text-sm text-gray-900",children:s.timestamp?y(new Date(s.timestamp),"yyyy-MM-dd HH:mm:ss"):"-"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Session"}),e.jsx("div",{className:"text-sm font-mono text-gray-700",children:s.session_id})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"项目路径"}),e.jsx("div",{className:"text-sm font-mono text-gray-700 break-all",children:s.project_path})]}),s.tool_name&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"工具"}),e.jsx("div",{className:"text-sm text-gray-900",children:s.tool_name})]}),s.user_prompt&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"用户提示"}),e.jsx("div",{className:"bg-purple-50 rounded p-3 text-sm text-gray-800 whitespace-pre-wrap",children:s.user_prompt})]}),s.tool_input&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"工具输入"}),e.jsx(g,{data:s.tool_input,language:"json",maxHeight:"300px"})]}),s.tool_output&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"工具输出"}),e.jsx(g,{data:s.tool_output,language:typeof s.tool_output=="string"?"text":"json",maxHeight:"400px"})]})]})})]})}export{B as default};
2
+ //# sourceMappingURL=Events-DQHP6Uaq.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Events-C2OCOKAD.js","sources":["../../src/pages/Events.tsx"],"sourcesContent":["import { useQuery } from '@tanstack/react-query'\nimport { useState, useMemo } from 'react'\nimport { format } from 'date-fns'\nimport { Activity, Filter, Download } from 'lucide-react'\nimport clsx from 'clsx'\nimport Drawer from '../components/Drawer'\nimport CodeBlock from '../components/CodeBlock'\nimport SearchInput from '../components/SearchInput'\nimport { downloadJSON, downloadCSV, getTimestamp } from '../utils/export'\nimport { useToast } from '../components/Toast'\n\ninterface Event {\n event_id: string\n session_id: string\n project_path: string\n timestamp: string\n hook_type: string\n tool_name?: string\n tool_input?: any\n tool_output?: any\n user_prompt?: string\n ai_response?: string\n}\n\nasync function fetchEvents(hookType?: string): Promise<Event[]> {\n const url = `/api/events?limit=500${hookType ? `&hook_type=${hookType}` : ''}`\n const res = await fetch(url)\n if (!res.ok) throw new Error('Failed to fetch events')\n return res.json()\n}\n\nconst hookTypes = ['', 'UserPromptSubmit', 'PreToolUse', 'PostToolUse', 'Stop', 'Notification']\n\nexport default function Events() {\n const [filter, setFilter] = useState('')\n const [search, setSearch] = useState('')\n const [selectedEvent, setSelectedEvent] = useState<Event | null>(null)\n const [showExportMenu, setShowExportMenu] = useState(false)\n const toast = useToast()\n\n const { data: events, isLoading } = useQuery({\n queryKey: ['events', filter],\n queryFn: () => fetchEvents(filter),\n refetchInterval: 5000,\n })\n\n // 客户端搜索过滤\n const filteredEvents = useMemo(() => {\n if (!events) return []\n if (!search.trim()) return events\n const q = search.toLowerCase()\n return events.filter(e =>\n e.tool_name?.toLowerCase().includes(q) ||\n e.user_prompt?.toLowerCase().includes(q) ||\n e.session_id.toLowerCase().includes(q) ||\n JSON.stringify(e.tool_input || '').toLowerCase().includes(q)\n )\n }, [events, search])\n\n const handleExport = (exportFormat: 'json' | 'csv') => {\n const ts = getTimestamp()\n if (exportFormat === 'json') {\n downloadJSON(`events-${ts}.json`, filteredEvents)\n } else {\n // CSV 导出扁平化\n const flat = filteredEvents.map(e => ({\n event_id: e.event_id,\n session_id: e.session_id,\n timestamp: e.timestamp,\n hook_type: e.hook_type,\n tool_name: e.tool_name || '',\n user_prompt: e.user_prompt || '',\n tool_input: e.tool_input ? JSON.stringify(e.tool_input).slice(0, 500) : '',\n }))\n downloadCSV(`events-${ts}.csv`, flat)\n }\n toast.success(`已导出 ${filteredEvents.length} 条事件`)\n setShowExportMenu(false)\n }\n\n return (\n <div>\n <div className=\"flex items-center justify-between mb-4 flex-wrap gap-3\">\n <h1 className=\"text-2xl font-bold text-gray-900\">事件</h1>\n <div className=\"flex items-center gap-2 flex-wrap\">\n <SearchInput\n value={search}\n onChange={setSearch}\n placeholder=\"搜索提示/工具/session...\"\n className=\"w-64\"\n />\n <div className=\"flex items-center gap-1\">\n <Filter className=\"h-4 w-4 text-gray-500\" />\n <select\n value={filter}\n onChange={(e) => setFilter(e.target.value)}\n className=\"text-sm border border-gray-300 rounded-md px-2 py-1.5 bg-white\"\n >\n {hookTypes.map((t) => (\n <option key={t} value={t}>{t || '全部类型'}</option>\n ))}\n </select>\n </div>\n <div className=\"relative\">\n <button\n onClick={() => setShowExportMenu(v => !v)}\n disabled={filteredEvents.length === 0}\n className=\"inline-flex items-center gap-1 px-3 py-1.5 text-sm bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50\"\n >\n <Download className=\"h-4 w-4\" />\n 导出\n </button>\n {showExportMenu && (\n <>\n <div className=\"fixed inset-0 z-10\" onClick={() => setShowExportMenu(false)} />\n <div className=\"absolute right-0 mt-1 bg-white border border-gray-200 rounded-md shadow-lg z-20\">\n <button\n onClick={() => handleExport('json')}\n className=\"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50\"\n >\n 导出为 JSON\n </button>\n <button\n onClick={() => handleExport('csv')}\n className=\"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50\"\n >\n 导出为 CSV\n </button>\n </div>\n </>\n )}\n </div>\n </div>\n </div>\n\n <div className=\"text-sm text-gray-500 mb-3\">\n 显示 {filteredEvents.length} 条 {search && `(已过滤)`}\n </div>\n\n <div className=\"bg-white rounded-lg shadow overflow-hidden\">\n {isLoading ? (\n <div className=\"p-6 text-gray-600\">加载中...</div>\n ) : (\n <table className=\"min-w-full divide-y divide-gray-200\">\n <thead className=\"bg-gray-50\">\n <tr>\n <th className=\"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase\">时间</th>\n <th className=\"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase\">类型</th>\n <th className=\"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase\">工具</th>\n <th className=\"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase\">详情</th>\n </tr>\n </thead>\n <tbody className=\"bg-white divide-y divide-gray-200\">\n {filteredEvents.map((e) => (\n <tr\n key={e.event_id}\n className=\"hover:bg-gray-50 cursor-pointer\"\n onClick={() => setSelectedEvent(e)}\n >\n <td className=\"px-4 py-2 whitespace-nowrap text-xs font-mono text-gray-500\">\n {e.timestamp ? format(new Date(e.timestamp), 'HH:mm:ss') : '-'}\n </td>\n <td className=\"px-4 py-2 whitespace-nowrap\">\n <span className={clsx(\n 'px-2 py-0.5 text-xs font-medium rounded',\n e.hook_type === 'UserPromptSubmit' && 'bg-purple-100 text-purple-700',\n e.hook_type === 'PreToolUse' && 'bg-blue-100 text-blue-700',\n e.hook_type === 'PostToolUse' && 'bg-green-100 text-green-700',\n e.hook_type === 'Stop' && 'bg-gray-100 text-gray-700',\n e.hook_type === 'Notification' && 'bg-yellow-100 text-yellow-700'\n )}>\n {e.hook_type}\n </span>\n </td>\n <td className=\"px-4 py-2 whitespace-nowrap text-sm text-gray-700\">\n {e.tool_name || '-'}\n </td>\n <td className=\"px-4 py-2 max-w-xl\">\n <p className=\"text-xs text-gray-600 truncate\">\n {e.user_prompt || (e.tool_input ? JSON.stringify(e.tool_input).slice(0, 100) : '-')}\n </p>\n </td>\n </tr>\n ))}\n {filteredEvents.length === 0 && (\n <tr>\n <td colSpan={4} className=\"px-4 py-12 text-center text-gray-500\">\n <Activity className=\"h-12 w-12 text-gray-300 mx-auto mb-2\" />\n {search ? '无匹配结果' : '暂无事件'}\n </td>\n </tr>\n )}\n </tbody>\n </table>\n )}\n </div>\n\n {/* Event Detail Drawer */}\n <Drawer\n open={selectedEvent !== null}\n onClose={() => setSelectedEvent(null)}\n title=\"事件详情\"\n >\n {selectedEvent && (\n <div className=\"space-y-4\">\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">事件 ID</div>\n <div className=\"text-sm font-mono text-gray-900\">{selectedEvent.event_id}</div>\n </div>\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">类型</div>\n <span className={clsx(\n 'px-2 py-1 text-xs font-medium rounded',\n selectedEvent.hook_type === 'UserPromptSubmit' && 'bg-purple-100 text-purple-700',\n selectedEvent.hook_type === 'PreToolUse' && 'bg-blue-100 text-blue-700',\n selectedEvent.hook_type === 'PostToolUse' && 'bg-green-100 text-green-700',\n )}>\n {selectedEvent.hook_type}\n </span>\n </div>\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">时间</div>\n <div className=\"text-sm text-gray-900\">\n {selectedEvent.timestamp ? format(new Date(selectedEvent.timestamp), 'yyyy-MM-dd HH:mm:ss') : '-'}\n </div>\n </div>\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">Session</div>\n <div className=\"text-sm font-mono text-gray-700\">{selectedEvent.session_id}</div>\n </div>\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">项目路径</div>\n <div className=\"text-sm font-mono text-gray-700 break-all\">{selectedEvent.project_path}</div>\n </div>\n {selectedEvent.tool_name && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">工具</div>\n <div className=\"text-sm text-gray-900\">{selectedEvent.tool_name}</div>\n </div>\n )}\n {selectedEvent.user_prompt && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">用户提示</div>\n <div className=\"bg-purple-50 rounded p-3 text-sm text-gray-800 whitespace-pre-wrap\">\n {selectedEvent.user_prompt}\n </div>\n </div>\n )}\n {selectedEvent.tool_input && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">工具输入</div>\n <CodeBlock data={selectedEvent.tool_input} language=\"json\" maxHeight=\"300px\" />\n </div>\n )}\n {selectedEvent.tool_output && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">工具输出</div>\n <CodeBlock\n data={selectedEvent.tool_output}\n language={typeof selectedEvent.tool_output === 'string' ? 'text' : 'json'}\n maxHeight=\"400px\"\n />\n </div>\n )}\n </div>\n )}\n </Drawer>\n </div>\n )\n}\n"],"names":["fetchEvents","hookType","url","res","hookTypes","Events","filter","setFilter","useState","search","setSearch","selectedEvent","setSelectedEvent","showExportMenu","setShowExportMenu","toast","useToast","events","isLoading","useQuery","filteredEvents","useMemo","q","e","_a","_b","handleExport","exportFormat","ts","getTimestamp","downloadJSON","flat","downloadCSV","jsxs","jsx","SearchInput","Filter","v","Download","Fragment","format","clsx","Activity","Drawer","CodeBlock"],"mappings":"gfAwBA,eAAeA,EAAYC,EAAqC,CAC9D,MAAMC,EAAM,wBAAwBD,EAAW,cAAcA,CAAQ,GAAK,EAAE,GACtEE,EAAM,MAAM,MAAMD,CAAG,EAC3B,GAAI,CAACC,EAAI,GAAI,MAAM,IAAI,MAAM,wBAAwB,EACrD,OAAOA,EAAI,KAAA,CACb,CAEA,MAAMC,EAAY,CAAC,GAAI,mBAAoB,aAAc,cAAe,OAAQ,cAAc,EAE9F,SAAwBC,GAAS,CAC/B,KAAM,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAAS,EAAE,EACjC,CAACC,EAAQC,CAAS,EAAIF,EAAAA,SAAS,EAAE,EACjC,CAACG,EAAeC,CAAgB,EAAIJ,EAAAA,SAAuB,IAAI,EAC/D,CAACK,EAAgBC,CAAiB,EAAIN,EAAAA,SAAS,EAAK,EACpDO,EAAQC,EAAA,EAER,CAAE,KAAMC,EAAQ,UAAAC,CAAA,EAAcC,EAAS,CAC3C,SAAU,CAAC,SAAUb,CAAM,EAC3B,QAAS,IAAMN,EAAYM,CAAM,EACjC,gBAAiB,GAAA,CAClB,EAGKc,EAAiBC,EAAAA,QAAQ,IAAM,CACnC,GAAI,CAACJ,EAAQ,MAAO,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EAAc,WACbsB,EAAAA,KAAC,MAAA,CACC,SAAA,CAAAC,EAAAA,IAAC,MAAA,CAAI,UAAU,6BAA6B,SAAA,KAAE,EAC9CA,EAAAA,IAAC,MAAA,CAAI,UAAU,wBAAyB,WAAc,SAAA,CAAU,CAAA,EAClE,EAEDvB,EAAc,aACbsB,EAAAA,KAAC,MAAA,CACC,SAAA,CAAAC,EAAAA,IAAC,MAAA,CAAI,UAAU,6BAA6B,SAAA,OAAI,EAChDA,EAAAA,IAAC,MAAA,CAAI,UAAU,qEACZ,WAAc,WAAA,CACjB,CAAA,EACF,EAEDvB,EAAc,YACbsB,EAAAA,KAAC,MAAA,CACC,SAAA,CAAAC,EAAAA,IAAC,MAAA,CAAI,UAAU,6BAA6B,SAAA,OAAI,EAChDA,MAACU,GAAU,KAAMjC,EAAc,WAAY,SAAS,OAAO,UAAU,OAAA,CAAQ,CAAA,EAC/E,EAEDA,EAAc,aACbsB,EAAAA,KAAC,MAAA,CACC,SAAA,CAAAC,EAAAA,IAAC,MAAA,CAAI,UAAU,6BAA6B,SAAA,OAAI,EAChDA,EAAAA,IAACU,EAAA,CACC,KAAMjC,EAAc,YACpB,SAAU,OAAOA,EAAc,aAAgB,SAAW,OAAS,OACnE,UAAU,OAAA,CAAA,CACZ,CAAA,CACF,CAAA,CAAA,CAEJ,CAAA,CAAA,CAEJ,EACF,CAEJ"}
1
+ {"version":3,"file":"Events-DQHP6Uaq.js","sources":["../../src/pages/Events.tsx"],"sourcesContent":["import { useQuery } from '@tanstack/react-query'\nimport { useState, useMemo } from 'react'\nimport { format } from 'date-fns'\nimport { Activity, Filter, Download } from 'lucide-react'\nimport clsx from 'clsx'\nimport Drawer from '../components/Drawer'\nimport CodeBlock from '../components/CodeBlock'\nimport SearchInput from '../components/SearchInput'\nimport { downloadJSON, downloadCSV, getTimestamp } from '../utils/export'\nimport { useToast } from '../components/Toast'\n\ninterface Event {\n event_id: string\n session_id: string\n project_path: string\n timestamp: string\n hook_type: string\n tool_name?: string\n tool_input?: any\n tool_output?: any\n user_prompt?: string\n ai_response?: string\n}\n\nasync function fetchEvents(hookType?: string): Promise<Event[]> {\n const url = `/api/events?limit=500${hookType ? `&hook_type=${hookType}` : ''}`\n const res = await fetch(url)\n if (!res.ok) throw new Error('Failed to fetch events')\n return res.json()\n}\n\nconst hookTypes = ['', 'UserPromptSubmit', 'PreToolUse', 'PostToolUse', 'Stop', 'Notification']\n\nexport default function Events() {\n const [filter, setFilter] = useState('')\n const [search, setSearch] = useState('')\n const [selectedEvent, setSelectedEvent] = useState<Event | null>(null)\n const [showExportMenu, setShowExportMenu] = useState(false)\n const toast = useToast()\n\n const { data: events, isLoading } = useQuery({\n queryKey: ['events', filter],\n queryFn: () => fetchEvents(filter),\n refetchInterval: 5000,\n })\n\n // 客户端搜索过滤\n const filteredEvents = useMemo(() => {\n if (!events) return []\n if (!search.trim()) return events\n const q = search.toLowerCase()\n return events.filter(e =>\n e.tool_name?.toLowerCase().includes(q) ||\n e.user_prompt?.toLowerCase().includes(q) ||\n e.session_id.toLowerCase().includes(q) ||\n JSON.stringify(e.tool_input || '').toLowerCase().includes(q)\n )\n }, [events, search])\n\n const handleExport = (exportFormat: 'json' | 'csv') => {\n const ts = getTimestamp()\n if (exportFormat === 'json') {\n downloadJSON(`events-${ts}.json`, filteredEvents)\n } else {\n // CSV 导出扁平化\n const flat = filteredEvents.map(e => ({\n event_id: e.event_id,\n session_id: e.session_id,\n timestamp: e.timestamp,\n hook_type: e.hook_type,\n tool_name: e.tool_name || '',\n user_prompt: e.user_prompt || '',\n tool_input: e.tool_input ? JSON.stringify(e.tool_input).slice(0, 500) : '',\n }))\n downloadCSV(`events-${ts}.csv`, flat)\n }\n toast.success(`已导出 ${filteredEvents.length} 条事件`)\n setShowExportMenu(false)\n }\n\n return (\n <div>\n <div className=\"flex items-center justify-between mb-4 flex-wrap gap-3\">\n <h1 className=\"text-2xl font-bold text-gray-900\">事件</h1>\n <div className=\"flex items-center gap-2 flex-wrap\">\n <SearchInput\n value={search}\n onChange={setSearch}\n placeholder=\"搜索提示/工具/session...\"\n className=\"w-64\"\n />\n <div className=\"flex items-center gap-1\">\n <Filter className=\"h-4 w-4 text-gray-500\" />\n <select\n value={filter}\n onChange={(e) => setFilter(e.target.value)}\n className=\"text-sm border border-gray-300 rounded-md px-2 py-1.5 bg-white\"\n >\n {hookTypes.map((t) => (\n <option key={t} value={t}>{t || '全部类型'}</option>\n ))}\n </select>\n </div>\n <div className=\"relative\">\n <button\n onClick={() => setShowExportMenu(v => !v)}\n disabled={filteredEvents.length === 0}\n className=\"inline-flex items-center gap-1 px-3 py-1.5 text-sm bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50\"\n >\n <Download className=\"h-4 w-4\" />\n 导出\n </button>\n {showExportMenu && (\n <>\n <div className=\"fixed inset-0 z-10\" onClick={() => setShowExportMenu(false)} />\n <div className=\"absolute right-0 mt-1 bg-white border border-gray-200 rounded-md shadow-lg z-20\">\n <button\n onClick={() => handleExport('json')}\n className=\"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50\"\n >\n 导出为 JSON\n </button>\n <button\n onClick={() => handleExport('csv')}\n className=\"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50\"\n >\n 导出为 CSV\n </button>\n </div>\n </>\n )}\n </div>\n </div>\n </div>\n\n <div className=\"text-sm text-gray-500 mb-3\">\n 显示 {filteredEvents.length} 条 {search && `(已过滤)`}\n </div>\n\n <div className=\"bg-white rounded-lg shadow overflow-hidden\">\n {isLoading ? (\n <div className=\"p-6 text-gray-600\">加载中...</div>\n ) : (\n <table className=\"min-w-full divide-y divide-gray-200\">\n <thead className=\"bg-gray-50\">\n <tr>\n <th className=\"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase\">时间</th>\n <th className=\"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase\">类型</th>\n <th className=\"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase\">工具</th>\n <th className=\"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase\">详情</th>\n </tr>\n </thead>\n <tbody className=\"bg-white divide-y divide-gray-200\">\n {filteredEvents.map((e) => (\n <tr\n key={e.event_id}\n className=\"hover:bg-gray-50 cursor-pointer\"\n onClick={() => setSelectedEvent(e)}\n >\n <td className=\"px-4 py-2 whitespace-nowrap text-xs font-mono text-gray-500\">\n {e.timestamp ? format(new Date(e.timestamp), 'HH:mm:ss') : '-'}\n </td>\n <td className=\"px-4 py-2 whitespace-nowrap\">\n <span className={clsx(\n 'px-2 py-0.5 text-xs font-medium rounded',\n e.hook_type === 'UserPromptSubmit' && 'bg-purple-100 text-purple-700',\n e.hook_type === 'PreToolUse' && 'bg-blue-100 text-blue-700',\n e.hook_type === 'PostToolUse' && 'bg-green-100 text-green-700',\n e.hook_type === 'Stop' && 'bg-gray-100 text-gray-700',\n e.hook_type === 'Notification' && 'bg-yellow-100 text-yellow-700'\n )}>\n {e.hook_type}\n </span>\n </td>\n <td className=\"px-4 py-2 whitespace-nowrap text-sm text-gray-700\">\n {e.tool_name || '-'}\n </td>\n <td className=\"px-4 py-2 max-w-xl\">\n <p className=\"text-xs text-gray-600 truncate\">\n {e.user_prompt || (e.tool_input ? JSON.stringify(e.tool_input).slice(0, 100) : '-')}\n </p>\n </td>\n </tr>\n ))}\n {filteredEvents.length === 0 && (\n <tr>\n <td colSpan={4} className=\"px-4 py-12 text-center text-gray-500\">\n <Activity className=\"h-12 w-12 text-gray-300 mx-auto mb-2\" />\n {search ? '无匹配结果' : '暂无事件'}\n </td>\n </tr>\n )}\n </tbody>\n </table>\n )}\n </div>\n\n {/* Event Detail Drawer */}\n <Drawer\n open={selectedEvent !== null}\n onClose={() => setSelectedEvent(null)}\n title=\"事件详情\"\n >\n {selectedEvent && (\n <div className=\"space-y-4\">\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">事件 ID</div>\n <div className=\"text-sm font-mono text-gray-900\">{selectedEvent.event_id}</div>\n </div>\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">类型</div>\n <span className={clsx(\n 'px-2 py-1 text-xs font-medium rounded',\n selectedEvent.hook_type === 'UserPromptSubmit' && 'bg-purple-100 text-purple-700',\n selectedEvent.hook_type === 'PreToolUse' && 'bg-blue-100 text-blue-700',\n selectedEvent.hook_type === 'PostToolUse' && 'bg-green-100 text-green-700',\n )}>\n {selectedEvent.hook_type}\n </span>\n </div>\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">时间</div>\n <div className=\"text-sm text-gray-900\">\n {selectedEvent.timestamp ? format(new Date(selectedEvent.timestamp), 'yyyy-MM-dd HH:mm:ss') : '-'}\n </div>\n </div>\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">Session</div>\n <div className=\"text-sm font-mono text-gray-700\">{selectedEvent.session_id}</div>\n </div>\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">项目路径</div>\n <div className=\"text-sm font-mono text-gray-700 break-all\">{selectedEvent.project_path}</div>\n </div>\n {selectedEvent.tool_name && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">工具</div>\n <div className=\"text-sm text-gray-900\">{selectedEvent.tool_name}</div>\n </div>\n )}\n {selectedEvent.user_prompt && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">用户提示</div>\n <div className=\"bg-purple-50 rounded p-3 text-sm text-gray-800 whitespace-pre-wrap\">\n {selectedEvent.user_prompt}\n </div>\n </div>\n )}\n {selectedEvent.tool_input && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">工具输入</div>\n <CodeBlock data={selectedEvent.tool_input} language=\"json\" maxHeight=\"300px\" />\n </div>\n )}\n {selectedEvent.tool_output && (\n <div>\n <div className=\"text-xs text-gray-500 mb-1\">工具输出</div>\n <CodeBlock\n data={selectedEvent.tool_output}\n language={typeof selectedEvent.tool_output === 'string' ? 'text' : 'json'}\n maxHeight=\"400px\"\n />\n </div>\n )}\n </div>\n )}\n </Drawer>\n </div>\n )\n}\n"],"names":["fetchEvents","hookType","url","res","hookTypes","Events","filter","setFilter","useState","search","setSearch","selectedEvent","setSelectedEvent","showExportMenu","setShowExportMenu","toast","useToast","events","isLoading","useQuery","filteredEvents","useMemo","q","e","_a","_b","handleExport","exportFormat","ts","getTimestamp","downloadJSON","flat","downloadCSV","jsxs","jsx","SearchInput","Filter","v","Download","Fragment","format","clsx","Activity","Drawer","CodeBlock"],"mappings":"gfAwBA,eAAeA,EAAYC,EAAqC,CAC9D,MAAMC,EAAM,wBAAwBD,EAAW,cAAcA,CAAQ,GAAK,EAAE,GACtEE,EAAM,MAAM,MAAMD,CAAG,EAC3B,GAAI,CAACC,EAAI,GAAI,MAAM,IAAI,MAAM,wBAAwB,EACrD,OAAOA,EAAI,KAAA,CACb,CAEA,MAAMC,EAAY,CAAC,GAAI,mBAAoB,aAAc,cAAe,OAAQ,cAAc,EAE9F,SAAwBC,GAAS,CAC/B,KAAM,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAAS,EAAE,EACjC,CAACC,EAAQC,CAAS,EAAIF,EAAAA,SAAS,EAAE,EACjC,CAACG,EAAeC,CAAgB,EAAIJ,EAAAA,SAAuB,IAAI,EAC/D,CAACK,EAAgBC,CAAiB,EAAIN,EAAAA,SAAS,EAAK,EACpDO,EAAQC,EAAA,EAER,CAAE,KAAMC,EAAQ,UAAAC,CAAA,EAAcC,EAAS,CAC3C,SAAU,CAAC,SAAUb,CAAM,EAC3B,QAAS,IAAMN,EAAYM,CAAM,EACjC,gBAAiB,GAAA,CAClB,EAGKc,EAAiBC,EAAAA,QAAQ,IAAM,CACnC,GAAI,CAACJ,EAAQ,MAAO,CAAA,EACpB,GAAI,CAACR,EAAO,KAAA,EAAQ,OAAOQ,EAC3B,MAAMK,EAAIb,EAAO,YAAA,EACjB,OAAOQ,EAAO,OAAOM,GAAA,SACnB,QAAAC,EAAAD,EAAE,YAAF,YAAAC,EAAa,cAAc,SAASF,OACpCG,EAAAF,EAAE,cAAF,YAAAE,EAAe,cAAc,SAASH,KACtCC,EAAE,WAAW,YAAA,EAAc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CAAI,UAAU,6BAA6B,SAAA,OAAI,EAChDA,EAAAA,IAAC,MAAA,CAAI,UAAU,qEACZ,WAAc,WAAA,CACjB,CAAA,EACF,EAEDvB,EAAc,YACbsB,EAAAA,KAAC,MAAA,CACC,SAAA,CAAAC,EAAAA,IAAC,MAAA,CAAI,UAAU,6BAA6B,SAAA,OAAI,EAChDA,MAACU,GAAU,KAAMjC,EAAc,WAAY,SAAS,OAAO,UAAU,OAAA,CAAQ,CAAA,EAC/E,EAEDA,EAAc,aACbsB,EAAAA,KAAC,MAAA,CACC,SAAA,CAAAC,EAAAA,IAAC,MAAA,CAAI,UAAU,6BAA6B,SAAA,OAAI,EAChDA,EAAAA,IAACU,EAAA,CACC,KAAMjC,EAAc,YACpB,SAAU,OAAOA,EAAc,aAAgB,SAAW,OAAS,OACnE,UAAU,OAAA,CAAA,CACZ,CAAA,CACF,CAAA,CAAA,CAEJ,CAAA,CAAA,CAEJ,EACF,CAEJ"}
@@ -0,0 +1,3 @@
1
+ import{r as y,j as e}from"./react-vendor-CSp-GLFF.js";import{b as A,u as T}from"./query-C99w429o.js";import{d as E}from"./vendor-CMMjVdZs.js";import{D}from"./Drawer-DOUcx6m1.js";import{C as b}from"./CodeBlock--H53gk46.js";import{S as L,g as O,d as J,a as $}from"./export-CbQTOt71.js";import{u as q}from"./index-DJK5beK6.js";import{W,l as B,D as R,A as G}from"./lucide-BanPULT1.js";import{f as H}from"./date-fns-CZ_bHujz.js";import"./syntax-highlighter-44FakypI.js";import"./react-router-I-HqunH7.js";async function V(a){let l="/api/routing/events?limit=200";a==="obeyed"?l+="&obeyed=1":a==="refused"?l+="&obeyed=0":a==="unknown"&&(l+="&obeyed=null");const d=await fetch(l);if(!d.ok)throw new Error("Failed to fetch");return d.json()}const K=[{value:"",label:"全部"},{value:"obeyed",label:"✓ 遵守"},{value:"refused",label:"✗ 违抗"},{value:"unknown",label:"? 未判定"}],F={obeyed:{label:"✓ 遵守",className:"bg-green-100 text-green-800 border border-green-200",title:"调用了推荐的 agent"},disobeyed:{label:"✗ 违抗",className:"bg-red-100 text-red-800 border border-red-200",title:"使用了其他工具而非推荐 agent"},investigation_only:{label:"◎ 仅侦察",className:"bg-orange-100 text-orange-800 border border-orange-200",title:"只做了代码调查(Read/Grep/Glob),未调用推荐 agent"},timeout:{label:"⏱ 超时",className:"bg-gray-100 text-gray-700 border border-gray-200",title:"30 秒内未检测到任何工具调用"},no_action:{label:"— 纯对话",className:"bg-gray-100 text-gray-600 border border-gray-200",title:"未使用任何工具(纯文字回答)"},not_applicable:{label:"· 未适用",className:"bg-gray-50 text-gray-500 border border-gray-200",title:"此消息未触发 agent 推荐,不涉及遵守判定"}};function M({verdict:a}){const l=F[a]??F.not_applicable;return e.jsx("span",{className:E("inline-flex items-center px-2 py-0.5 rounded text-xs whitespace-nowrap",l.className),title:l.title,children:l.label})}function P({events:a,routingTimestamp:l}){const[d,v]=y.useState(new Set),[t,w]=y.useState(!0),u=a.filter(s=>s.hook_type==="PostToolUse"&&s.tool_name),N=new Set(["Read","Grep","Glob"]),r=u.filter(s=>s.tool_name&&N.has(s.tool_name)),i=u.filter(s=>s.tool_name&&!N.has(s.tool_name)),m=s=>N.has(s)?"🔍":["Edit","Write","MultiEdit"].includes(s)?"✏️":s==="Bash"?"⚙️":["Agent","Task"].includes(s)?"🤖":"📦",j=s=>{v(x=>{const h=new Set(x);return h.has(s)?h.delete(s):h.add(s),h})},f=s=>{if(!s)return null;try{return JSON.parse(s)}catch{return null}};return e.jsxs("div",{className:"space-y-3",children:[r.length>0&&e.jsxs("div",{className:"border border-gray-200 rounded-lg p-3",children:[e.jsxs("button",{onClick:()=>w(!t),className:"flex items-center gap-2 text-sm text-gray-700 hover:text-gray-900 w-full",children:[e.jsxs("span",{children:["🔍 侦察 × ",r.length," 次"]}),e.jsx("span",{className:"text-xs text-gray-500",children:t?"(展开)":"(收起)"})]}),!t&&e.jsx("div",{className:"mt-2 space-y-2 pl-4 border-l-2 border-gray-200",children:r.map(s=>{const x=((new Date(s.timestamp).getTime()-l)/1e3).toFixed(1),h=f(s.tool_input),c=f(s.tool_output),g=d.has(s.event_id),S=c==null?void 0:c.error;return e.jsxs("div",{className:"text-xs",children:[e.jsxs("button",{onClick:()=>j(s.event_id),className:"flex items-center gap-2 hover:bg-gray-50 p-1 rounded w-full text-left",children:[e.jsxs("span",{className:"text-gray-400 font-mono",children:[x,"s"]}),e.jsx("span",{children:m(s.tool_name)}),e.jsx("span",{className:"font-medium",children:s.tool_name}),S?e.jsx("span",{className:"text-red-600",children:"✗"}):e.jsx("span",{className:"text-green-600",children:"•"})]}),g&&e.jsxs("div",{className:"mt-1 ml-4 space-y-1",children:[h&&e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-500 mb-0.5",children:"Input:"}),e.jsx(b,{data:h,language:"json",maxHeight:"150px"})]}),c&&e.jsxs("div",{children:[e.jsx("div",{className:"text-gray-500 mb-0.5",children:"Output:"}),e.jsx(b,{data:c,language:"json",maxHeight:"150px"})]})]})]},s.event_id)})})]}),e.jsx("div",{className:"space-y-2 pl-4 border-l-2 border-indigo-200",children:i.map(s=>{const x=((new Date(s.timestamp).getTime()-l)/1e3).toFixed(1),h=f(s.tool_input),c=f(s.tool_output),g=d.has(s.event_id),S=c==null?void 0:c.error;return e.jsxs("div",{className:"text-sm",children:[e.jsxs("button",{onClick:()=>j(s.event_id),className:"flex items-center gap-2 hover:bg-gray-50 p-2 rounded w-full text-left",children:[e.jsxs("span",{className:"text-gray-400 font-mono text-xs",children:[x,"s"]}),e.jsx("span",{children:m(s.tool_name)}),e.jsx("span",{className:"font-medium",children:s.tool_name}),S?e.jsx("span",{className:"text-red-600",children:"✗"}):e.jsx("span",{className:"text-green-600",children:"•"})]}),g&&e.jsxs("div",{className:"mt-2 ml-8 space-y-2",children:[h&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Input:"}),e.jsx(b,{data:h,language:"json",maxHeight:"200px"})]}),c&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Output:"}),e.jsx(b,{data:c,language:"json",maxHeight:"200px"})]})]})]},s.event_id)})}),u.length===0&&e.jsx("div",{className:"text-center text-gray-500 text-sm py-8",children:"此次执行未产生工具调用记录"})]})}function Q({events:a}){const[l,d]=y.useState(new Set),v=new Set(["Edit","Write","MultiEdit","Bash"]),t=a.filter(r=>r.hook_type==="PostToolUse"&&r.tool_name&&v.has(r.tool_name)),w=r=>{d(i=>{const m=new Set(i);return m.has(r)?m.delete(r):m.add(r),m})},u=r=>{if(!r)return null;try{return JSON.parse(r)}catch{return null}},N=r=>r?r.split(`
2
+ `).length:0;return e.jsxs("div",{className:"space-y-3",children:[t.map(r=>{const i=u(r.tool_input),m=u(r.tool_output),j=l.has(r.event_id);if(r.tool_name==="Bash"){const f=(i==null?void 0:i.command)||"",s=(m==null?void 0:m.stdout)||"",x=(m==null?void 0:m.stderr)||"";return e.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>w(r.event_id),className:"w-full px-4 py-3 bg-gray-50 hover:bg-gray-100 text-left flex items-center gap-2",children:[e.jsx("span",{children:"⚙️"}),e.jsxs("span",{className:"font-mono text-sm flex-1 truncate",children:["$ ",f]}),e.jsx("span",{className:"text-xs text-gray-500",children:j?"收起":"展开"})]}),j&&e.jsxs("div",{className:"p-4 space-y-2",children:[s&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"stdout:"}),e.jsx(b,{data:s,language:"bash",maxHeight:"300px"})]}),x&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"stderr:"}),e.jsx(b,{data:x,language:"bash",maxHeight:"300px"})]})]})]},r.event_id)}if(["Edit","Write","MultiEdit"].includes(r.tool_name)){const f=(i==null?void 0:i.file_path)||"(unknown)",s=(i==null?void 0:i.old_string)||"",x=(i==null?void 0:i.new_string)||(i==null?void 0:i.content)||"",h=r.tool_name==="Write"||!s,c=N(x),g=N(s);return e.jsxs("div",{className:"border border-gray-200 rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>w(r.event_id),className:"w-full px-4 py-3 bg-gray-50 hover:bg-gray-100 text-left flex items-center gap-2",children:[e.jsx("span",{children:"📄"}),e.jsx("span",{className:"font-mono text-sm flex-1 truncate",children:f}),e.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-blue-100 text-blue-700",children:h?"+新增":"~修改"}),!h&&e.jsxs("span",{className:"text-xs text-gray-500",children:["+",c,"/-",g]}),e.jsx("span",{className:"text-xs text-gray-500",children:j?"收起":"展开"})]}),j&&e.jsxs("div",{className:"p-4 space-y-2",children:[s&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Before:"}),e.jsx(b,{data:s,language:"typescript",maxHeight:"200px"})]}),x&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:h?"Content:":"After:"}),e.jsx(b,{data:x,language:"typescript",maxHeight:"200px"})]})]})]},r.event_id)}return null}),t.length===0&&e.jsx("div",{className:"text-center text-gray-500 text-sm py-8",children:"此次执行未产生文件改动"})]})}async function U(a){const l=await fetch(`/api/execution-trace/${a}`);if(!l.ok)throw new Error("Failed to fetch execution detail");return l.json()}function C({invocation:a}){const l=a.success?"✓":"✗",d=a.success?"text-green-600":"text-red-600";return e.jsxs("div",{className:"border border-gray-200 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:d,children:l}),e.jsx("span",{className:"font-medium",children:a.skill_id}),e.jsxs("span",{className:"text-xs text-gray-500",children:["深度 ",a.depth," · ",new Date(a.timestamp).toLocaleTimeString()]})]}),a.agent_id&&e.jsxs("div",{className:"mt-1 text-xs text-gray-500",children:[e.jsx("span",{className:"font-medium",children:"调用方 Agent:"})," ",a.agent_id]}),a.reason&&e.jsxs("div",{className:"mt-1 text-xs text-gray-600",children:[e.jsx("span",{className:"font-medium",children:"理由:"})," ",a.reason]}),a.error&&e.jsxs("div",{className:"mt-1 text-xs text-red-600",children:[e.jsx("span",{className:"font-medium",children:"错误:"})," ",a.error]})]})}function z({invocations:a}){if(!a||a.length===0)return e.jsx("div",{className:"text-gray-500 text-sm py-8 text-center",children:"此次执行未调用任何 Skill"});const l=a.filter(t=>t.invocation_type==="static"),d=a.filter(t=>t.invocation_type==="dynamic"),v=a.filter(t=>t.invocation_type==="slash_command");return e.jsxs("div",{className:"space-y-4",children:[l.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-700 mb-2",children:["静态依赖 Skill (",l.length,")"]}),e.jsx("div",{className:"space-y-2",children:l.map(t=>e.jsx(C,{invocation:t},t.id))})]}),d.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-700 mb-2",children:["动态调用 Skill (",d.length,")"]}),e.jsx("div",{className:"space-y-2",children:d.map(t=>e.jsx(C,{invocation:t},t.id))})]}),v.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-gray-700 mb-2",children:["Slash Command Skill (",v.length,")"]}),e.jsx("div",{className:"space-y-2",children:v.map(t=>e.jsx(C,{invocation:t},t.id))})]})]})}function ie(){const[a,l]=y.useState(""),[d,v]=y.useState(""),[t,w]=y.useState(null),[u,N]=y.useState("basic"),[r,i]=y.useState(!1),[m,j]=y.useState(!1),f=q(),s=A();y.useEffect(()=>{const n=new EventSource("/api/execution-trace/stream");return n.onopen=()=>i(!0),n.onerror=()=>i(!1),n.onmessage=o=>{try{JSON.parse(o.data).type==="execution-status"&&s.invalidateQueries({queryKey:["routing-events"]})}catch{}},()=>{n.close(),i(!1)}},[s]);const{data:x,isLoading:h}=T({queryKey:["routing-events",a],queryFn:()=>V(a),refetchInterval:1e4}),{data:c}=T({queryKey:["execution-detail",t==null?void 0:t.id],queryFn:()=>U(t.id),enabled:t!==null}),g=y.useMemo(()=>{if(!x)return[];if(!d.trim())return x;const n=d.toLowerCase();return x.filter(o=>{var _,p,k;return((_=o.prompt)==null?void 0:_.toLowerCase().includes(n))||((p=o.routed_to_name)==null?void 0:p.toLowerCase().includes(n))||((k=o.first_tool_name)==null?void 0:k.toLowerCase().includes(n))})},[x,d]),S=n=>{const o=O();if(n==="json")J(`routing-events-${o}.json`,g);else{const _=g.map(p=>{let k={};try{k=JSON.parse(p.intent_json||"{}")}catch{}return{id:p.id,ts:p.ts?H(p.ts,"yyyy-MM-dd HH:mm:ss"):"",prompt:p.prompt,taskType:k.taskType||"",complexity:k.complexity||"",routed_to:p.routed_to_name||"",obeyed:p.obeyed===1?"yes":p.obeyed===0?"no":"",first_tool:p.first_tool_name||"",duration_ms:p.total_execution_ms||"",refusal_reason:p.refusal_reason||""}});$(`routing-events-${o}.csv`,_)}f.success(`已导出 ${g.length} 条追踪记录`),j(!1)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"执行追踪"}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:r?e.jsxs(e.Fragment,{children:[e.jsx(W,{className:"h-3 w-3 text-green-500"}),e.jsx("span",{className:"text-xs text-green-600",children:"实时流已连接"})]}):e.jsxs(e.Fragment,{children:[e.jsx(B,{className:"h-3 w-3 text-gray-400"}),e.jsx("span",{className:"text-xs text-gray-500",children:"实时流未连接"})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(L,{value:d,onChange:v,placeholder:"搜索 prompt / agent / tool...",className:"w-56"}),e.jsx("div",{className:"flex items-center gap-1",children:K.map(n=>e.jsx("button",{onClick:()=>l(n.value),className:E("px-2.5 py-1.5 text-xs rounded-md",a===n.value?"bg-indigo-100 text-indigo-700":"bg-white text-gray-600 border border-gray-300 hover:bg-gray-50"),children:n.label},n.value))}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>j(n=>!n),disabled:g.length===0,className:"inline-flex items-center gap-1 px-3 py-1.5 text-sm bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50",children:[e.jsx(R,{className:"h-4 w-4"}),"导出"]}),m&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>j(!1)}),e.jsxs("div",{className:"absolute right-0 mt-1 bg-white border border-gray-200 rounded-md shadow-lg z-20",children:[e.jsx("button",{onClick:()=>S("json"),className:"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50",children:"导出为 JSON"}),e.jsx("button",{onClick:()=>S("csv"),className:"block w-full text-left px-4 py-2 text-sm hover:bg-gray-50",children:"导出为 CSV"})]})]})]})]})]}),e.jsxs("div",{className:"text-sm text-gray-500 mb-3",children:["显示 ",g.length," 条 ",d&&"(已过滤)"]}),e.jsx("div",{className:"bg-white rounded-lg shadow overflow-hidden",children:h?e.jsx("div",{className:"p-6",children:"加载中..."}):e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"时间"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"提示"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"路由到"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"遵守"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"首工具"}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase",children:"耗时"})]})}),e.jsxs("tbody",{className:"bg-white divide-y divide-gray-200",children:[g.map(n=>{let o={};try{o=JSON.parse(n.intent_json||"{}")}catch{}return e.jsxs("tr",{className:"hover:bg-gray-50 cursor-pointer",onClick:()=>w(n),children:[e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-xs font-mono text-gray-500",children:H(n.ts,"MM-dd HH:mm:ss")}),e.jsxs("td",{className:"px-4 py-2 max-w-xs",children:[e.jsx("p",{className:"text-xs text-gray-700 truncate",title:n.prompt,children:n.prompt}),e.jsxs("p",{className:"text-xs text-gray-400 mt-0.5",children:[o.taskType," / ",o.complexity]})]}),e.jsx("td",{className:"px-4 py-2 whitespace-nowrap",children:n.routed_to_name?e.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-indigo-100 text-indigo-700 rounded",children:n.routed_to_name}):e.jsx("span",{className:"text-xs text-gray-400",children:"未路由"})}),e.jsx("td",{className:"px-4 py-2 whitespace-nowrap",children:e.jsx(M,{verdict:n.verdict})}),e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-xs text-gray-700",children:n.first_tool_name||"-"}),e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-xs font-mono text-gray-500",children:n.total_execution_ms?`${(n.total_execution_ms/1e3).toFixed(1)}s`:"-"})]},n.id)}),g.length===0&&e.jsx("tr",{children:e.jsxs("td",{colSpan:6,className:"px-4 py-12 text-center text-gray-500",children:[e.jsx(G,{className:"h-12 w-12 text-gray-300 mx-auto mb-2"}),d?"无匹配结果":"暂无追踪记录"]})})]})]})}),e.jsx(D,{open:t!==null,onClose:()=>{w(null),N("basic")},title:"Agent 执行详情",children:t&&c&&(()=>{let n={};try{n=JSON.parse(t.intent_json||"{}")}catch{}return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-2 border-b border-gray-200 pb-2",children:["basic","timeline","artifacts","skills"].map(o=>{var _;return e.jsxs("button",{onClick:()=>N(o),className:E("px-3 py-1.5 text-sm rounded-md transition-colors",u===o?"bg-indigo-100 text-indigo-700 font-medium":"text-gray-600 hover:bg-gray-100"),children:[o==="basic"&&"基本",o==="timeline"&&"过程",o==="artifacts"&&"产物",o==="skills"&&`Skill 调用 (${((_=c==null?void 0:c.skillInvocations)==null?void 0:_.length)||0})`]},o)})}),u==="basic"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"用户提示"}),e.jsx("div",{className:"bg-purple-50 rounded p-3 text-sm text-gray-800 whitespace-pre-wrap",children:t.prompt})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"路由结果"}),e.jsx("div",{className:"text-sm font-medium",children:t.routed_to_name||"未路由"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"遵守状态"}),e.jsx("div",{children:e.jsx(M,{verdict:t.verdict})})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"意图分类"}),e.jsx(b,{data:n,language:"json",maxHeight:"200px"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"首工具"}),e.jsx("div",{className:"font-mono",children:t.first_tool_name||"-"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"分类耗时"}),e.jsxs("div",{className:"font-mono",children:[t.classification_ms,"ms"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"总执行时间"}),e.jsx("div",{className:"font-mono",children:t.total_execution_ms?`${(t.total_execution_ms/1e3).toFixed(2)}s`:"-"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"完成原因"}),e.jsx("div",{children:t.completion_reason||"-"})]})]}),t.refusal_reason&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"违抗原因"}),e.jsx("div",{className:"bg-red-50 rounded p-3 text-sm text-red-700",children:t.refusal_reason})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500 mb-1",children:"Session"}),e.jsx("div",{className:"text-xs font-mono text-gray-700",children:t.session_id})]})]}),u==="timeline"&&e.jsx(P,{events:c.events,routingTimestamp:t.ts}),u==="artifacts"&&e.jsx(Q,{events:c.events}),u==="skills"&&e.jsx(z,{invocations:c.skillInvocations||[]})]})})()})]})}export{ie as default};
3
+ //# sourceMappingURL=ExecutionTrace-Co8ARdg-.js.map