var e=`/api`,t=`velamq_console_token`,n=2e4,r=class extends Error{constructor(e=`AI 助手响应尾部暂时卡住，已保留当前已生成内容，你可以继续追问或选择下一步。`){super(e),this.name=`AssistantStreamStalledError`}};function i(){return typeof localStorage>`u`?null:localStorage.getItem(t)}function a(e){localStorage.setItem(t,e)}function o(){localStorage.removeItem(t)}async function s(t,n=`GET`,r){let a={"Content-Type":`application/json`},s=i();s&&(a.Authorization=`Bearer ${s}`);let c={method:n,headers:a};r!==void 0&&(c.body=JSON.stringify(r));let l=await fetch(e+t,c);if(l.status===401){o(),typeof window<`u`&&window.location.pathname!==`/login`&&window.location.assign(`/login`);let e=await l.text();throw Error(e||`Unauthorized`)}if(l.status===204)return null;if(!l.ok){let e=await l.text();throw Error(e||l.statusText)}let u=await l.text();return u?JSON.parse(u):null}function c(e){if(!e)return null;let t=e.match(/filename\*=UTF-8''([^;]+)/i);if(t)try{return decodeURIComponent(t[1])}catch{return t[1]}let n=e.match(/filename="?([^";]+)"?/i);return n?n[1]:null}async function l(t,n=`GET`,r){let a={},s=i();s&&(a.Authorization=`Bearer ${s}`),r!==void 0&&(a[`Content-Type`]=`application/json`);let l={method:n,headers:a};r!==void 0&&(l.body=JSON.stringify(r));let u=await fetch(e+t,l);if(u.status===401){o(),typeof window<`u`&&window.location.pathname!==`/login`&&window.location.assign(`/login`);let e=await u.text();throw Error(e||`Unauthorized`)}if(!u.ok){let e=await u.text();throw Error(e||u.statusText)}return{blob:await u.blob(),filename:c(u.headers.get(`content-disposition`))}}function u(e){let t=e.split(/\r?\n/),n=`message`,r=[];for(let e of t)if(e){if(e.startsWith(`event:`)){n=e.slice(6).trim();continue}e.startsWith(`data:`)&&r.push(e.slice(5).trim())}if(r.length===0)return null;let i=JSON.parse(r.join(`
`));return n===`meta`||n===`preview`||n===`done`||n===`error`?{event:n,data:i}:null}function d(e){let t=e.split(/\r?\n/),n=`message`,r=[];for(let e of t)if(e){if(e.startsWith(`event:`)){n=e.slice(6).trim();continue}e.startsWith(`data:`)&&r.push(e.slice(5).trim())}return r.length===0?null:{event:n,data:JSON.parse(r.join(`
`))}}var f={getDashboardOverview:()=>s(`/dashboard/overview`),getAssistantConfig:e=>s(`/assistant/config${e?.refreshStatus?`?refresh=true`:``}`),updateAssistantConfig:e=>s(`/assistant/config`,`PUT`,e),listAssistantModels:e=>s(`/assistant/models`,`POST`,e),listAssistantConversations:()=>s(`/assistant/conversations`),getAssistantConversation:e=>s(`/assistant/conversations/${encodeURIComponent(e)}`),deleteAssistantConversation:e=>s(`/assistant/conversations/${encodeURIComponent(e)}`,`DELETE`),saveAssistantConversationMessage:(e,t)=>s(`/assistant/conversations/${encodeURIComponent(e)}/messages`,`POST`,t),chatAssistant:e=>s(`/assistant/chat`,`POST`,e),streamAssistantChat:async(t,a)=>{let s={"Content-Type":`application/json`},c=i();c&&(s.Authorization=`Bearer ${c}`);let l=await fetch(`${e}/assistant/chat/stream`,{method:`POST`,headers:s,body:JSON.stringify(t)});if(l.status===401){o(),typeof window<`u`&&window.location.pathname!==`/login`&&window.location.assign(`/login`);let e=await l.text();throw Error(e||`Unauthorized`)}if(!l.ok){let e=await l.text();throw Error(e||l.statusText)}if(!l.body)throw Error(`Assistant stream is not available`);let d=l.body.getReader(),f=new TextDecoder,p=``,m=!1,h=!1,g=e=>{let t=u(e);if(t){if(t.event===`meta`){a.onMeta?.(t.data);return}if(t.event===`preview`){h=!0,a.onPreview?.(t.data);return}if(t.event===`done`){m=!0,a.onDone?.(t.data);return}throw m=!0,Error(t.data.message||`Assistant stream failed`)}},_=async()=>!h||m?d.read():new Promise((e,t)=>{let i=setTimeout(()=>{d.cancel().catch(()=>void 0),t(new r)},n);d.read().then(t=>{clearTimeout(i),e(t)},e=>{clearTimeout(i),t(e)})});outer:for(;;){let{value:e,done:t}=await _();if(t)break;p+=f.decode(e,{stream:!0});let n=p.indexOf(`

`);for(;n>=0;){let e=p.slice(0,n);if(p=p.slice(n+2),g(e),m){d.cancel().catch(()=>void 0);break outer}n=p.indexOf(`

`)}}let v=f.decode();if(v&&(p+=v),p.trim()&&g(p),!m)throw Error(`AI 助手流式响应在完成前中断，请重试`)},streamTrafficTap:async(t,n,r)=>{let a=new URLSearchParams;a.set(`client_id`,t.client_id),a.set(`directions`,`both`),a.set(`packet_filter`,`all`),t.duration_secs!=null&&a.set(`duration_secs`,String(t.duration_secs)),t.max_frame_bytes!=null&&a.set(`max_frame_bytes`,String(t.max_frame_bytes)),t.max_total_bytes!=null&&a.set(`max_total_bytes`,String(t.max_total_bytes)),t.connection_id!=null&&t.connection_id>0&&a.set(`connection_id`,String(t.connection_id));let s={},c=i();c&&(s.Authorization=`Bearer ${c}`);let l=await fetch(`${e}/traffic-taps/stream?${a.toString()}`,{method:`GET`,headers:s,signal:r});if(l.status===401){o(),typeof window<`u`&&window.location.pathname!==`/login`&&window.location.assign(`/login`);let e=await l.text();throw Error(e||`Unauthorized`)}if(!l.ok){let e=await l.text();throw Error(e||l.statusText)}if(!l.body)throw Error(`Traffic tap stream is not available`);let u=l.body.getReader(),f=new TextDecoder,p=``,m=!1;try{for(;;){let{value:e,done:t}=await u.read();if(t)break;p+=f.decode(e,{stream:!0});let r=p.indexOf(`

`);for(;r>=0;){let e=p.slice(0,r);p=p.slice(r+2);let t=d(e);if(t){if(t.event===`meta`)n.onMeta?.(t.data);else if(t.event===`status`)n.onStatus?.(t.data);else if(t.event===`frame`)n.onFrame?.(t.data);else if(t.event===`summary`)n.onSummary?.(t.data);else if(t.event===`done`)m=!0,n.onDone?.();else if(t.event===`error`){let e=t.data;throw Error(e.message||`Traffic tap failed`)}}r=p.indexOf(`

`)}}m||n.onDone?.()}catch(e){throw e.name===`AbortError`||n.onError?.(e instanceof Error?e:Error(String(e))),e}finally{u.releaseLock()}},applyAssistantDraft:e=>s(`/assistant/apply`,`POST`,e),getStats:()=>s(`/stats`),getLicense:()=>s(`/license`),importLicense:e=>s(`/license`,`POST`,e),getSystemStats:()=>s(`/system`),getClusterMetrics:()=>s(`/cluster/metrics`),getClusterStorageRaft:()=>s(`/cluster/storage-raft`),getClusterShards:()=>s(`/cluster/shards`),listRetainedMessages:e=>{let t=new URLSearchParams;e?.limit!=null&&t.set(`limit`,String(e.limit)),e?.offset!=null&&t.set(`offset`,String(e.offset)),e?.cursor!=null&&e.cursor.trim()!==``&&t.set(`cursor`,e.cursor.trim()),e?.q!=null&&e.q.trim()!==``&&t.set(`q`,e.q.trim());let n=t.toString();return s(`/data-management/retained${n?`?${n}`:``}`)},deleteRetainedMessage:e=>s(`/data-management/retained/${encodeURIComponent(e)}`,`DELETE`),getRetainedPayload:e=>s(`/data-management/retained/${encodeURIComponent(e)}`),listSessionData:e=>{let t=new URLSearchParams;e?.limit!=null&&t.set(`limit`,String(e.limit)),e?.offset!=null&&t.set(`offset`,String(e.offset)),e?.cursor!=null&&e.cursor.trim()!==``&&t.set(`cursor`,e.cursor.trim()),e?.q!=null&&e.q.trim()!==``&&t.set(`q`,e.q.trim());let n=t.toString();return s(`/data-management/sessions${n?`?${n}`:``}`)},deleteSessionData:e=>s(`/data-management/sessions/${encodeURIComponent(e)}`,`DELETE`),listDelayedMessages:e=>{let t=new URLSearchParams;e?.limit!=null&&t.set(`limit`,String(e.limit)),e?.offset!=null&&t.set(`offset`,String(e.offset)),e?.cursor!=null&&e.cursor.trim()!==``&&t.set(`cursor`,e.cursor.trim()),e?.q!=null&&e.q.trim()!==``&&t.set(`q`,e.q.trim());let n=t.toString();return s(`/data-management/delayed${n?`?${n}`:``}`)},deleteDelayedMessage:e=>s(`/data-management/delayed/${encodeURIComponent(e)}`,`DELETE`),getDelayedPayload:e=>s(`/data-management/delayed/${encodeURIComponent(e)}`),getStorageStatus:()=>s(`/data-management/storage/status`),createStorageBackup:e=>s(`/data-management/storage/backup`,`POST`,e??{}),createStorageSnapshot:e=>s(`/data-management/storage/snapshot`,`POST`,e??{}),getMetricsHistory:e=>{let t=new URLSearchParams;e?.since_ms!=null&&t.set(`since_ms`,String(e.since_ms)),e?.until_ms!=null&&t.set(`until_ms`,String(e.until_ms)),e?.limit!=null&&t.set(`limit`,String(e.limit));let n=t.toString();return s(`/metrics/history${n?`?${n}`:``}`)},getClusterConnections:e=>{let t=new URLSearchParams;e?.page!=null&&t.set(`page`,String(e.page)),e?.per_page!=null&&t.set(`per_page`,String(e.per_page)),e?.client_id!=null&&e.client_id.trim()!==``&&t.set(`client_id`,e.client_id.trim()),e?.snapshot_id!=null&&e.snapshot_id.trim()!==``&&t.set(`snapshot_id`,e.snapshot_id.trim());let n=t.toString();return s(`/cluster/connections${n?`?${n}`:``}`)},disconnectClusterConnection:e=>s(`/cluster/connections/disconnect`,`POST`,e),getConnectionMonitor:e=>{let t=new URLSearchParams;return t.set(`connection_id`,String(e.connection_id)),s(`/cluster/connections/monitor?${t.toString()}`)},listDataSources:()=>s(`/datasources`),addDataSource:e=>s(`/datasources`,`POST`,e),updateDataSource:(e,t)=>s(`/datasources/${encodeURIComponent(e)}`,`PUT`,t),removeDataSource:e=>s(`/datasources/${encodeURIComponent(e)}`,`DELETE`),listRules:()=>s(`/rules`),addRule:e=>s(`/rules`,`POST`,e),updateRule:(e,t)=>s(`/rules/${encodeURIComponent(e)}`,`PUT`,t),removeRule:e=>s(`/rules/${encodeURIComponent(e)}`,`DELETE`),getRuleMonitor:e=>s(`/rules/${encodeURIComponent(e)}/monitor`),dryRunRule:e=>s(`/rules/dry-run`,`POST`,e),listRuleOutbox:e=>{let t=new URLSearchParams;e?.status&&t.set(`status`,e.status),e?.rule_id&&t.set(`rule_id`,e.rule_id),e?.action_id&&t.set(`action_id`,e.action_id),e?.limit!=null&&t.set(`limit`,String(e.limit));let n=t.toString();return s(`/rule-outbox${n?`?${n}`:``}`)},retryRuleOutbox:e=>s(`/rule-outbox/${encodeURIComponent(e)}/retry`,`POST`),retryRuleOutboxBatch:e=>s(`/rule-outbox/retry`,`POST`,e),deleteRuleOutbox:e=>s(`/rule-outbox/${encodeURIComponent(e)}`,`DELETE`),listFunctions:()=>s(`/functions`),upsertFunction:e=>s(`/functions`,`POST`,e),deleteFunction:e=>s(`/functions/${encodeURIComponent(e)}`,`DELETE`),enableFunction:e=>s(`/functions/${encodeURIComponent(e)}/enable`,`POST`),disableFunction:e=>s(`/functions/${encodeURIComponent(e)}/disable`,`POST`),testFunction:e=>s(`/functions/test`,`POST`,e),listAclPolicies:()=>s(`/acl`),listAclRules:e=>{let t=new URLSearchParams;e?.page!=null&&t.set(`page`,String(e.page)),e?.per_page!=null&&t.set(`per_page`,String(e.per_page)),e?.acl_type&&t.set(`acl_type`,e.acl_type),e?.topic&&t.set(`topic`,e.topic);let n=t.toString();return s(`/acl/rules${n?`?${n}`:``}`)},addAclRule:e=>s(`/acl/rules`,`POST`,e),updateAclRule:(e,t)=>s(`/acl/rules/${encodeURIComponent(e)}`,`PUT`,t),removeAclRule:e=>s(`/acl/rules/${encodeURIComponent(e)}`,`DELETE`),addAclPolicy:e=>s(`/acl`,`POST`,e),updateAclPolicy:(e,t)=>s(`/acl/${e}`,`PUT`,t),removeAclPolicy:e=>s(`/acl/${e}`,`DELETE`),listAuthProviders:()=>s(`/auth`),addAuthProvider:e=>s(`/auth`,`POST`,e),updateAuthProvider:(e,t)=>s(`/auth/${e}`,`PUT`,t),removeAuthProvider:e=>s(`/auth/${e}`,`DELETE`),listCommandTypes:()=>s(`/commands/types`),listCommands:()=>s(`/commands`),addCommand:e=>s(`/commands`,`POST`,e),updateCommand:(e,t)=>s(`/commands/${encodeURIComponent(e)}`,`PUT`,t),updateCommandStatus:(e,t)=>s(`/commands/${encodeURIComponent(e)}/status`,`PUT`,{status:t}),removeCommand:e=>s(`/commands/${encodeURIComponent(e)}`,`DELETE`),listEndpoints:()=>s(`/endpoints`),replaceEndpoints:e=>s(`/endpoints`,`PUT`,e),listServerCertificates:()=>s(`/certificates/servers`),createSelfSignedServerCertificate:e=>s(`/certificates/servers/self-signed`,`POST`,e),uploadServerCertificate:e=>s(`/certificates/servers/upload`,`POST`,e),deleteServerCertificate:e=>s(`/certificates/servers/${encodeURIComponent(e)}`,`DELETE`),downloadServerCertificate:e=>s(`/certificates/servers/${encodeURIComponent(e)}/download`),downloadServerCertificateArchive:e=>l(`/certificates/servers/${encodeURIComponent(e)}/download/archive`),listClientCertificates:e=>{let t=new URLSearchParams;e&&t.set(`server_certificate_id`,e);let n=t.toString();return s(`/certificates/clients${n?`?${n}`:``}`)},issueClientCertificate:(e,t)=>s(`/certificates/servers/${encodeURIComponent(e)}/clients`,`POST`,t),downloadClientCertificate:e=>s(`/certificates/clients/${encodeURIComponent(e)}/download`),downloadClientCertificateArchive:e=>l(`/certificates/clients/${encodeURIComponent(e)}/download/archive`),getClusterInfo:()=>s(`/cluster`),getConsoleConfig:()=>s(`/console/config`),getMe:()=>s(`/console/me`),logout:()=>s(`/console/logout`,`POST`),login:async(t,n)=>{let r=await fetch(`${e}/console/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({username:t,password:n})});if(!r.ok){let e=await r.text();throw Error(e||r.statusText)}return r.json()},bootstrap:async(t,n)=>{let r=await fetch(`${e}/console/bootstrap`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({username:t,password:n})});if(!r.ok){let e=await r.text();throw Error(e||r.statusText)}return r.json()},listConsoleUsers:()=>s(`/console/users`),createConsoleUser:e=>s(`/console/users`,`POST`,e),updateConsoleUser:(e,t)=>s(`/console/users/${encodeURIComponent(e)}`,`PUT`,t),deleteConsoleUser:e=>s(`/console/users/${encodeURIComponent(e)}`,`DELETE`),listAuditLogs:e=>{let t=new URLSearchParams;e?.limit!=null&&t.set(`limit`,String(e.limit)),e?.offset!=null&&t.set(`offset`,String(e.offset));let n=t.toString();return s(`/console/audit${n?`?${n}`:``}`)}};export{a,i,f as n,o as r,r as t};