PageSourceSearch

https://xyc.ai/static/js/async/5107.73a9426840.js

js xyc.ai collected 2026-10-05 14:39:35 UTC 16,961 bytes, 1 lines download raw bytes

1"use strict";(self.rspackChunknewapi_web=self.rspackChunknewapi_web||[]).push([[5107],{74028(e,t,a){a.d(t,{c:()=>r});var s=a(68413);function r(e){let{search:t,navigate:a,pagination:r,globalFilter:n,columnFilters:i=[]}=e,l=r?.pageKey??"page",o=r?.pageSizeKey??"pageSize",d=r?.defaultPage??1,c=r?.defaultPageSize??20,u=n?.key??"filter",m=n?.enabled??!0,x=n?.trim??!0,p=(0,s.useMemo)(()=>{let e=[];for(let a of i){let s=t[a.searchKey],r=a.deserialize??(e=>e);if("string"===a.type){let t=r(s)??"";"string"==typeof t&&""!==t.trim()&&e.push({id:a.columnId,value:t})}else{let t=r(s)??[];Array.isArray(t)&&t.length>0&&e.push({id:a.columnId,value:t})}}return e},[i,t]),[h,g]=(0,s.useState)(p);(0,s.useEffect)(()=>{g(p)},[t]);let f=(0,s.useMemo)(()=>{let e=t[l],a=t[o];return{pageIndex:Math.max(0,("number"==typeof e?e:d)-1),pageSize:"number"==typeof a?a:c}},[t,l,o,d,c]),[y,b]=(0,s.useState)(()=>{if(!m)return;let e=t[u];return"string"==typeof e?e:""}),j=m?e=>{let t="function"==typeof e?e(y??""):e,s=x?t.trim():t;b(s),a({search:e=>({...e,[l]:void 0,[u]:s||void 0})})}:void 0;return{globalFilter:m?y??"":void 0,onGlobalFilterChange:j,columnFilters:h,onColumnFiltersChange:e=>{let t="function"==typeof e?e(h):e;g(t);let s={};for(let e of i){let a=t.find(t=>t.id===e.columnId),r=e.serialize??(e=>e);if("string"===e.type){let t="string"==typeof a?.value?a.value:"";s[e.searchKey]=""!==t.trim()?r(t):void 0}else{let t=Array.isArray(a?.value)?a.value:[];s[e.searchKey]=t.length>0?r(t):void 0}}a({search:e=>({...e,[l]:void 0,...s})})},pagination:f,onPaginationChange:e=>{let t="function"==typeof e?e(f):e,s=t.pageIndex+1,r=t.pageSize;a({search:e=>({...e,[l]:s<=d?void 0:s,[o]:r})})},ensurePageInRange:function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{resetTo:"first"},r=t[l],n="number"==typeof r?r:d;e>0&&n>e&&a({replace:!0,search:t=>({...t,[l]:"last"===s.resetTo?e:void 0})})}}}},18318(e,t,a){a.r(t),a.d(t,{component:()=>R});var s=a(72361),r=a(68413),n=a(53540),i=a(2718),l=a(55581),o=a(3521),d=a(11564),c=a(6702),u=a(20598),m=a(61631),x=a(74028),p=a(46775),h=a(54023),g=a(58254),f=a(67267),y=a(64577);async function b(e){let t=await y.FH.get(`/api/admin/user-audit/sessions/${e}`,{disableDuplicate:!0});if(!t.data.success)throw Error(t.data.message||"Failed to load conversation");return t.data.data}async function j(e){let t=(await y.FH.get("/api/admin/user-audit/export",{params:{username:e?.trim()||void 0},responseType:"blob",disableDuplicate:!0})).data,a=URL.createObjectURL(t),s=document.createElement("a");s.href=a,s.download=`user-audit-${new Date().toISOString().slice(0,10)}.csv`,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(a)}async function v(e){let t=await y.FH.get(`/api/admin/user-audit/api-records/${e}`,{disableDuplicate:!0});if(!t.data.success)throw Error(t.data.message||"Failed to load record");return t.data.data}async function N(e){let t=await y.FH.get("/api/admin/user-audit/combined",{params:{p:e.page,page_size:e.pageSize,username:e.username?.trim()||void 0}});if(!t.data.success)throw Error(t.data.message||"Failed to load audit records");return t.data.data}var w=a(1755);function k(e){return"string"==typeof e?e:Array.isArray(e)?e.map(e=>
1"string"==typeof e?e:"string"==typeof e.text?e.text:"").filter(Boolean).join("\n"):""}var C=a(37936);function S(e){return!Number.isFinite(e)||e<=0?"0 B":e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:e<0x40000000?`${(e/1048576).toFixed(2)} MB`:`${(e/0x40000000).toFixed(2)} GB`}function _(e){return e?C.A.unix(e).format("YYYY-MM-DD HH:mm:ss"):"-"}function A(e){let{label:t,content:a}=e,{t:r}=(0,c.Bd)(),{text:n,clipped:i}=a.length<=1e5?{text:a,clipped:!1}:{text:a.slice(0,1e5),clipped:!0};return(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"mb-1 text-sm font-medium",children:t}),(0,s.jsx)("pre",{className:"bg-muted/40 max-h-[32vh] overflow-auto rounded-md p-3 text-xs whitespace-pre-wrap",children:n||r("(empty)")}),i&&(0,s.jsx)("div",{className:"text-text-tertiary mt-1 text-xs",children:r("Content truncated for display")})]})}function z(e){let t,a,r,{recordId:i,onOpenChange:l}=e,{t:o}=(0,c.Bd)(),{data:d,isLoading:u}=(0,n.I)({queryKey:["api-audit-detail",i],queryFn:()=>v(i),enabled:null!==i});return(0,s.jsx)(w.lG,{open:null!==i,onOpenChange:l,children:(0,s.jsxs)(w.Cf,{className:"flex max-h-[92vh] w-[min(96vw,1200px)] !max-w-[min(96vw,1200px)] flex-col overflow-hidden",children:[(0,s.jsx)(w.c7,{children:(0,s.jsxs)(w.L3,{children:[o("API call detail"),d?.record?` \xb7 ${d.record.model}`:""]})}),u?(0,s.jsx)("div",{className:"flex justify-center py-10",children:(0,s.jsx)(m.krw,{className:"animate-spin"})}):d?(0,s.jsxs)("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto pr-1",children:[(0,s.jsxs)("div",{className:"text-text-secondary grid grid-cols-2 gap-x-4 gap-y-1 text-xs sm:grid-cols-3",children:[(0,s.jsxs)("div",{children:[o("User"),": ",d.record.username]}),(0,s.jsxs)("div",{children:[o("Group"),": ",d.record.group||"-"]}),(0,s.jsxs)("div",{children:["IP: ",d.record.ip]}),(0,s.jsxs)("div",{children:[o("Status"),": ",d.record.status_code]}),(0,s.jsxs)("div",{children:[o("Time"),": ",_(d.record.created_at)]}),(0,s.jsxs)("div",{className:"truncate",children:[o("Request ID"),": ",d.record.request_id]})]}),(0,s.jsx)(A,{label:o("Request"),content:d.request}),(t=function(e){try{let t=JSON.parse(e),a=[];"string"==typeof t.system&&t.system.trim()&&a.push(`system: ${t.system}`);let s=t.messages??t.input;if("string"==typeof s)a.push(`user: ${s}`);else if(Array.isArray(s))for(let e of s){let t="string"==typeof e.role?e.role:"";if(!t)continue;let s=k(e.content);s.trim()&&a.push(`${t}: ${s}`)}return a.join("\n\n")}catch{return""}}(d.request),a=function(e){let t=e.trim();if(!t)return"";if(t.includes("data:")){let e=[];for(let a of t.split("\n")){let t=a.trim();if(!t.startsWith("data:"))continue;let s=t.slice(5).trim();if(s&&"[DONE]"!==s)try{let t=JSON.parse(s),a=t.choices;if(Array.isArray(a)&&a.length>0){let t=a[0].delta;if(t&&"string"==typeof t.content){e.push(t.content);continue}}if("content_block_delta"===t.type){let a=t.delta;if(a?.type==="text_delta"&&"string"==typeof a.text){e.push(a.text);continue}}"response.output_text.delta"===t.type&&"string"==typeof t.delta&&e.push(t.delta)}catch{}}return e.join("")}try{return function(e){let t=e.choices;if(Array.isArray(t)&&t.length>0){let e=t[0].message;if(e){let t=k(e.content);if(t)return t}}if(Array.isArray(e.content)){let t=k(e.content);if(t)return t}if(Array.isArray(e.output)){let t=[];for(let a of e.output)if("message"===a.type){let e=k(a.content);e&&t.push(e)}if(t.length>0)return t.join("\n")}return""}(JSON.parse(t))}catch{return""}}(d.response),r=function(e){try{let t=JSON.parse(e);if(!Array.isArray(t.data))return[];return t.data.map(e=>e.b64_json?`data:image/png;base64,${e.b64_json}`:e.url??"").filter(Boolean)}catch{return[]}}(d.response),(0,s.jsxs)(s.Fragment,{children:[t&&(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"mb-1 text-sm font-medium text-indigo-600 dark:text-indigo-400",children:o("Plain input (filtered)")}),(0,s.jsx)("pre",{className:"max-h-[32vh] overflow-auto rounded-md bg-indigo-500/5 p-3 text-xs whitespace-pre-wrap",children:t})]}),a&&(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"mb-1 text-sm font-medium text-emerald-600 dark:text-emerald-400",children:o("Plain reply (filtered)")}),(0,s.jsx)("pre",{className:"max-h-[32vh] overflow-auto rounded-md bg-emerald-500/5 p-3 text-xs whitespace-pre-wrap",children:a})]}),r.length>0&&(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"mb-1 text-sm font-medium text-emerald-600 dark:text-emerald-400",children:o("Generated images")}),(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:r.map((e,t)=>(0,s.jsx)("img",{src:e,alt:`generated-${t}
1`,className:"border-border max-h-64 rounded-md border object-contain"},t))})]})]})),(0,s.jsx)(A,{label:o("Response"),content:d.response})]}):null]})})}var F=a(63742),E=a(18434);function I(e){let{sessionId:t,onOpenChange:a}=e,{t:i}=(0,c.Bd)(),l=null!==t,{data:o,isLoading:d,isError:x}=(0,n.I)({queryKey:["user-audit-session",t],queryFn:()=>b(t),enabled:l,staleTime:3e4});(0,r.useEffect)(()=>{x&&u.oR.error(i("Failed to load conversation"))},[x,i]);let p=o?.session,h=o?.messages??[];return(0,s.jsx)(w.lG,{open:l,onOpenChange:a,children:(0,s.jsxs)(w.Cf,{className:"flex max-h-[92vh] w-[min(96vw,1200px)] !max-w-[min(96vw,1200px)] flex-col gap-3 overflow-hidden p-0",children:[(0,s.jsxs)(w.c7,{className:"border-border shrink-0 border-b px-5 pt-5 pb-3",children:[(0,s.jsxs)(w.L3,{className:"flex min-w-0 items-center gap-2 pr-8",children:[(0,s.jsx)(m.AJG,{className:"text-primary size-4 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:p?.title||i("Conversation details")})]}),(0,s.jsxs)(w.rr,{className:"flex flex-wrap gap-x-3 gap-y-1 text-xs",children:[(0,s.jsx)("span",{children:p?.username||i("Loading...")}),p?.model&&(0,s.jsx)("span",{children:p.model}),p&&(0,s.jsxs)("span",{children:[S(p.content_bytes)," ·"," ",_(p.update_time)]})]})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 pb-5",children:d?(0,s.jsx)("div",{className:"space-y-4 py-2",children:[1,2,3].map(e=>(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(E.E,{className:"h-4 w-24"}),(0,s.jsx)(E.E,{className:"h-20 w-full"})]},e))}):0===h.length?(0,s.jsx)("div",{className:"text-text-secondary py-12 text-center text-sm",children:i("No messages in this conversation")}):(0,s.jsx)("div",{className:"space-y-3 py-1",children:h.map(e=>{var t;let a=e.text||e.content||"-";return(0,s.jsxs)("article",{className:"border-border/70 bg-background-secondary/35 rounded-lg border px-3 py-2.5",children:[(0,s.jsxs)("div",{className:"mb-2 flex flex-wrap items-center justify-between gap-2",children:[(0,s.jsx)(F.E,{variant:"user"===e.role?"default":"secondary",children:(t=e.role,"user"===t?i("User"):"assistant"===t?i("Assistant"):"system"===t?i("System"):t||i("Unknown"))}),(0,s.jsxs)("span",{className:"text-text-tertiary text-[11px] tabular-nums",children:[_(e.create_time)," ·"," ",S(e.content_bytes)]})]}),(0,s.jsx)("pre",{className:"text-foreground/90 max-h-[28rem] overflow-auto font-sans text-sm leading-relaxed break-words whitespace-pre-wrap",children:a})]},e.id)})})})]})})}let $=(0,i.GY)("/_authenticated/user-audit/"),K={items:[],total:0,page:1,page_size:20,total_bytes:0};function M(e){let{icon:t,label:a,value:r}=e;return(0,s.jsxs)("div",{className:"border-border bg-muted/20 flex min-w-[132px] items-center gap-2 rounded-lg border px-3 py-2",children:[(0,s.jsx)(t,{className:"text-primary size-4 shrink-0"}),(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("div",{className:"text-text-tertiary truncate text-[11px]",children:a}),(0,s.jsx)("div",{className:"text-foreground truncate text-sm font-semibold tabular-nums",children:r})]})]})}function P(e){let{value:t,onChange:a,onSubmit:r,onClear:n,exporting:i,onExport:l,disabledExport:o}=e,{t:d}=(0,c.Bd)();return(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2.5",children:[(0,s.jsxs)("form",{className:"flex min-w-0 flex-1 items-center gap-1.5 sm:max-w-md",onSubmit:e=>{e.preventDefault(),r()},children:[(0,s.jsxs)("div",{className:"relative min-w-0 flex-1",children:[(0,s.jsx)(m.vji,{className:"text-text-tertiary pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2"}),(0,s.jsx)(h.p,{value:t,onChange:e=>a(e.target.value),placeholder:d("Search by username"),"aria-label":d("Search by username"),className:"h-9 pr-8 pl-8"}),t&&(0,s.jsx)("button",{type:"button",onClick:n,className:"text-text-tertiary hover:text-foreground absolute top-1/2 right-2 -translate-y-1/2","aria-label":d("Clear"),title:d("Clear"),children:(0,s.jsx)(m.X,{className:"size-3.5"})})]}),(0,s.jsxs)(p.$,{type:"submit",size:"sm",className:"h-9",children:[(0,s.jsx)(m.vji,{}),d("Search")]})]}),(0,s.jsxs)(p.$,{type:"button",variant:"outline",size:"sm",className:"h-9",onClick:l,disabled:o||i,children:[i?(0,s.jsx)(m.krw,{className:"animate-spin"}):(0,s.jsx)(m.f5X,{}),d(i?"Exporting...":"Export conversations")]})]})}let R=function(){var e;let{t}=(0,c.Bd)(),a=(0,d.Ub)("(max-width: 640px)"),i=$.useSearch(),h=$.useNavigate(),y=i.username??"",[b,v]=(0,r.useState)(y),[w,k]=(0,r.useState)(null),[C,A]=(0,r.useState)(null),[F,E]=(0,r.useState)(!1);(0,r.useEffect)(()=>{v(y)},[y]);let{pagination:R,onPaginationChange:B,ensurePageInRange:U}=(0,x.c)({search:i,navigate:h,pagination:{defaultPage:1,defaultPageSize:a?10:20},globalFilter:{enabled:!1}}),{data:D,isLoading:O,isFetching:q}=(0,n.I)({queryKey:["user-audit-combined",R.pageIndex+1,R.pageSize,y],queryFn:async()=>{try{return await N({page:R.pageIndex+1,pageSize:R.pageSize,username:y})}catch(e){return u.oR.error(e instanceof Error?e.message:t("Failed to load audit records")),K}},placeholderData:e=>e}),T=D??K,G=T.items,H=Math.max(1,Math.ceil(T.total/R.pageSize));(0,r.useEffect)(()=>{U(H)},[U,H]);let L=(0,r.useCallback)(()=>{let e=b.trim();h({search:t=>({...t,page:void 0,username:e||void 0})})},[h,b]),J=(0,r.useCallback)(()=>{v(""),h({search:e=>({...e,page:void 0,username:void 0})})},[h]),Y=(0,r.useCallback)(async()=>{E(!0);try{await j(y),u.oR.success(t("Export completed"))}catch(e){u.oR.error(e instanceof Error?e.message:t("Export failed"))}finally{E(!1)}},[t,y]),W=(0,r.useMemo)(()=>[{id:"kind",accessorKey:"kind",header:t("Type"),meta:{mobileBadge:!0},cell:e=>{let{row:a}=e;return(0,s.jsx)("span",{className:"chat"===a.original.kind?"rounded bg-indigo-500/10 px-1.5 py-0.5 text-xs font-medium text-indigo-600 dark:text-indigo-400":"rounded bg-emerald-500/10 px-1.5 py-0.5 text-xs font-medium text-emerald-600 dark:text-emerald-400",children:"chat"===a.original.kind?t("Chat"):"API"})}},{id:"username",accessorKey:"username",header:t("Username"),cell:e=>{let{row:t}=e;return(0,s.jsxs)("div",{className:"max-w-[190px] min-w-[110px]",children:[(0,s.jsx)("div",{className:"truncate font-medium",children:t.original.username||"-"}),t.original.display_name&&(0,s.jsx)("div",{className:"text-text-tertiary truncate text-xs",children:t.original.display_name})]})}},{id:"title",accessorKey:"title",header:t("Conversation"),meta:{mobileTitle:!0},cell:e=>{let{row:a}=e;return(0,s.jsx)("div",{className:"max-w-[260px] truncate font-medium",children:a.original.title||t("Untitled conversation")})}},{id:"model",accessorKey:"model",header:t("Model"),cell:e=>{let{row:t}=e;return(0,s.jsx)("span",{className:"text-text-secondary max-w-[180px] truncate",children:t.original.model||"-"})}},{id:"info",header:t("Messages"),meta:{label:t("Messages")},cell:e=>{let{row:t}=e;return"chat"===t.original.kind?(0,s.jsx)("span",{className:"tabular-nums",children:t.original.message_count}):(0,s.jsx)("span",{className:t.original.status_code>
1=400?"text-red-600 tabular-nums dark:text-red-400":"text-text-secondary tabular-nums",children:t.original.status_code})}},{id:"content_bytes",accessorKey:"content_bytes",header:t("Size"),meta:{label:t("Size")},cell:e=>{let{row:t}=e;return(0,s.jsx)("span",{className:"text-text-secondary tabular-nums",children:S(t.original.content_bytes)})}},{id:"time",accessorKey:"time",header:t("Updated"),meta:{label:t("Updated")},cell:e=>{let{row:t}=e;return(0,s.jsx)("span",{className:"text-text-secondary text-xs tabular-nums",children:_(t.original.time)})}},{id:"actions",header:"",cell:e=>{let{row:a}=e;return(0,s.jsxs)(p.$,{type:"button",variant:"ghost",size:"sm",onClick:()=>"chat"===a.original.kind?k(Number(a.original.id)):A(Number(a.original.id)),title:t("View conversation"),children:[(0,s.jsx)(m.kU3,{}),(0,s.jsx)("span",{className:"hidden sm:inline",children:t("View")})]})}}],[t]),V=(0,l.N4)({data:G,columns:W,state:{pagination:R},getCoreRowModel:(0,o.HT)(),getPaginationRowModel:(0,o.kW)(),onPaginationChange:B,manualPagination:!0,pageCount:H});return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(f.Ni,{children:[(0,s.jsx)(f.Ni.Title,{children:t("User Information Audit")}),(0,s.jsx)(f.Ni.Description,{children:t("Playground conversations")}),(0,s.jsx)(f.Ni.Content,{children:(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)(P,{value:b,onChange:v,onSubmit:L,onClear:J,exporting:F,onExport:Y,disabledExport:0===T.total}),(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,s.jsx)(M,{icon:m.AJG,label:t("Conversations"),value:String(T.total)}),(0,s.jsx)(M,{icon:m.akk,label:t("Total storage"),value:(e=T.total_bytes,`${(Math.max(0,e)/1048576).toFixed(2)} MB`)}),(0,s.jsx)(M,{icon:m.zWC,label:t("Current filter"),value:y||t("All users")})]}),(0,s.jsx)(g.cx,{table:V,columns:W,isLoading:O,isFetching:q,toolbarProps:null,emptyTitle:t("No conversations found"),emptyDescription:t("No persisted chat records match this filter."),emptyIcon:(0,s.jsx)(m.AJG,{}),tableClassName:"rounded-lg",tableHeaderClassName:"bg-muted/30",mobileProps:{getRowKey:e=>`${e.original.kind}-${e.original.id}`}})]})})]}),(0,s.jsx)(I,{sessionId:w,onOpenChange:e=>{e||k(null)}}),(0,s.jsx)(z,{recordId:C,onOpenChange:e=>{e||A(null)}})]})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.