coding-tool-x 3.8.8 → 3.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/web/assets/{AgentsDrawer-DRQuwi0m.js → AgentsDrawer-Cj5CJ4d9.js} +1 -1
- package/dist/web/assets/{Analytics-Cf5KwEdj.js → Analytics-1doS-8uC.js} +1 -1
- package/dist/web/assets/{AssetPathField-DyniM0pF.js → AssetPathField-C9TOPl7o.js} +1 -1
- package/dist/web/assets/{ChatHistoryDrawer-CrfS0KYV.js → ChatHistoryDrawer-BTmQ1aQr.js} +1 -1
- package/dist/web/assets/{CollapseItem-ClMsJuUu.js → CollapseItem-CwqJk3bE.js} +1 -1
- package/dist/web/assets/{CommandsDrawer-CzHelf56.js → CommandsDrawer-CaZWDI_G.js} +1 -1
- package/dist/web/assets/{ConfigExportDrawer-BEZ8wTby.js → ConfigExportDrawer-C3vSZEsS.js} +1 -1
- package/dist/web/assets/ConfigTemplates-gyERg9iC.js +1 -0
- package/dist/web/assets/{ConfigTemplatesDrawer-BqM32Im7.js → ConfigTemplatesDrawer-B17RqFi4.js} +1 -1
- package/dist/web/assets/{ConfigTemplatesPanel-lTdutC8H.js → ConfigTemplatesPanel-DKIC_FqG.js} +1 -1
- package/dist/web/assets/{FavoritesDrawer-DDyWUBJR.js → FavoritesDrawer-DaziQmBp.js} +1 -1
- package/dist/web/assets/{GatewayConvertDrawer-Rigtt_5J.js → GatewayConvertDrawer-OMgWUUSc.js} +1 -1
- package/dist/web/assets/{Home-tCSKmSHV.js → Home-DOSUTfrE.js} +1 -1
- package/dist/web/assets/{MarkdownEditor-BMMUufSc.js → MarkdownEditor-9TTwTS-U.js} +1 -1
- package/dist/web/assets/{McpDrawer-CmE-d7VW.js → McpDrawer-I8rl8lGH.js} +1 -1
- package/dist/web/assets/{McpFormDrawer-ByvS18od.js → McpFormDrawer-DEP3C7ut.js} +1 -1
- package/dist/web/assets/{PluginManager-C4kJlpVX.js → PluginManager-BuRcWuBj.js} +1 -1
- package/dist/web/assets/{PluginsDrawer-05R4k15x.js → PluginsDrawer-_zZENaQn.js} +1 -1
- package/dist/web/assets/{PluginsPanel-BCoEs7Og.js → PluginsPanel-Bs5qZ-TK.js} +1 -1
- package/dist/web/assets/ProjectList-BSxuL2td.js +1 -0
- package/dist/web/assets/ProjectList-VbIYSHbH.css +1 -0
- package/dist/web/assets/{PromptsDrawer-DnwBf_oW.js → PromptsDrawer-CoZ-ZtsY.js} +1 -1
- package/dist/web/assets/{RecentSessionsDrawer-B7d-38wH.js → RecentSessionsDrawer-B_17aJBG.js} +1 -1
- package/dist/web/assets/{SessionCard-BUgjHQwX.js → SessionCard-BL_x0d3t.js} +1 -1
- package/dist/web/assets/SessionList-DhRYZ6vl.js +1 -0
- package/dist/web/assets/{SettingsDrawer-BITzjQLl.js → SettingsDrawer-fYb0DU7X.js} +1 -1
- package/dist/web/assets/{SkillManager-D9jkNuRM.js → SkillManager-S698Hns8.js} +1 -1
- package/dist/web/assets/{SkillsDrawer-0Z4IefxC.js → SkillsDrawer-Ms4lPCow.js} +1 -1
- package/dist/web/assets/{SkillsPanel-BKIVOj7n.js → SkillsPanel-rqnqAOGL.js} +1 -1
- package/dist/web/assets/{SpeedTestDrawer-Bx1bYf5i.js → SpeedTestDrawer-Bbn38SfV.js} +1 -1
- package/dist/web/assets/{Upload-CzC4rGI4.js → Upload-CdyVHxCI.js} +1 -1
- package/dist/web/assets/{WorkspaceDrawer-eujtWpoq.js → WorkspaceDrawer-L7HJRc6u.js} +1 -1
- package/dist/web/assets/{WorkspaceManager-CQ-8Ej68.js → WorkspaceManager-DsoNg2z8.js} +1 -1
- package/dist/web/assets/{WorkspacePanel-Cql5qE2R.js → WorkspacePanel-Be8PVZah.js} +1 -1
- package/dist/web/assets/headers-B5JWGn3v.js +1 -0
- package/dist/web/assets/{index-Cnbe696C.css → index-3Lp6z8TQ.css} +1 -1
- package/dist/web/assets/index-BKlAWTH-.js +2 -0
- package/dist/web/assets/{sessions-DqlbocLJ.js → sessions-CC0j-KH_.js} +1 -1
- package/dist/web/assets/{useResponsiveDrawer-DZd5rNk5.js → useResponsiveDrawer-V_onl9NV.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/src/commands/daemon.js +27 -4
- package/src/platforms/channel-auth-registry.js +36 -6
- package/src/platforms/channel-auth-service.js +12 -2
- package/src/platforms/drivers/omp/prompts.js +58 -2
- package/src/platforms/drivers/omp/proxy-implementation.js +25 -1
- package/src/platforms/drivers/opencode/channels-implementation.js +25 -22
- package/src/platforms/drivers/opencode/channels.js +6 -1
- package/src/platforms/manifests/omp.json +2 -1
- package/src/platforms/manifests/opencode.json +28 -0
- package/src/platforms/native-oauth-adapters.js +318 -18
- package/src/platforms/oauth-credentials-service.js +344 -13
- package/src/server/index.js +35 -1
- package/dist/web/assets/ConfigTemplates-Crg3xWe5.js +0 -1
- package/dist/web/assets/ProjectList-BJt1OIaI.js +0 -1
- package/dist/web/assets/ProjectList-DG3yu8xZ.css +0 -1
- package/dist/web/assets/SessionList-B-bXZRFk.js +0 -1
- package/dist/web/assets/headers-BqDmkMjy.js +0 -1
- package/dist/web/assets/index-Cmmwj3Fx.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as e,o as a,st as l}from"./vue-vendor-BqZbbXHA.js";import{a as t,n}from"./client-UDwXBP9i.js";import{i as s,t as r}from"./platforms-BmzzwnSw.js";import{a as u,d as o,i,m as v,n as c,r as f,u as m}from"./sessions-D4yQtfKb.js";import{n as
|
|
1
|
+
import{b as e,o as a,st as l}from"./vue-vendor-BqZbbXHA.js";import{a as t,n}from"./client-UDwXBP9i.js";import{i as s,t as r}from"./platforms-BmzzwnSw.js";import{a as u,d as o,i,m as v,n as c,r as f,u as m}from"./sessions-D4yQtfKb.js";import{n as h,t as p}from"./session-visibility-BAmxh3cK.js";async function g(e="claude",a={}){if(!s(e))return r(e,a);const l=t(e),u={};return null!=a.page&&(u.page=a.page),null!=a.limit&&(u.limit=a.limit),(a.q||a.search)&&(u.q=a.q||a.search),a.fresh&&(u.fresh="1"),(await n.get(`${l}/projects`,{params:u})).data}var d=new Map,y=new Map,j=new Map,w=new Map,$=[1500,3500,7e3,12e3],M=[2500,5e3,1e4,15e3],S=new Map,A=new Map,I=20;function P(e,a){return`${e}:${a}`}function k({page:e=1,limit:a=20,query:l=""}={}){return`:page=${e}:limit=${a}:query=${l||""}`}function B(e,a={}){const l=`${e}${k(a)}`,t=d.get(l);return t?Date.now()-t.timestamp>2e4?(d.delete(l),null):t.payload:null}function q(e,a,l={}){d.set(`${e}${k(l)}`,{timestamp:Date.now(),payload:a})}function b(e,a,l={}){const t=`${P(e,a)}${k(l)}`,n=y.get(t);return n?Date.now()-n.timestamp>2e4?(y.delete(t),null):n.payload:null}function E(e,a,l,t={}){y.set(`${P(e,a)}${k(t)}`,{timestamp:Date.now(),payload:l})}function z(e,a){a?Array.from(y.keys()).filter(l=>l.startsWith(`${P(e,a)}:`)).forEach(e=>y.delete(e)):Array.from(y.keys()).filter(a=>a.startsWith(`${e}:`)).forEach(e=>y.delete(e))}function W(e,a){const l=e.get(a);l&&(clearTimeout(l),e.delete(a))}function D(e,a,l){W(e,l),a.delete(l)}function O(e,a,l,t,n,s,r){W(e,l);const u=a.get(l)||Date.now();a.set(l,u);const o=185e3-(Date.now()-u);if(o<=0)return a.delete(l),void r?.();const i=Math.min(t[Math.min(n,t.length-1)],o),v=setTimeout(()=>{e.delete(l),s()},i);e.set(l,v)}var R=a("sessions",()=>{const a=l([]),s=l(null),r=l(null),y=l(null),W=l(null),R=l({page:1,limit:I,total:0,hasMore:!1}),C=l({page:1,limit:I,total:0,hasMore:!1}),F=l([]),T=l({}),U=l(0),x=l(!1),G=l(null),H=l("claude"),J=new Map,K=new Map;let L=0;const N=e(()=>F.value.map(e=>({...e,alias:T.value[e.sessionId]||null}))),Q=e(()=>Boolean(y.value?.refreshing)),V=e(()=>Boolean(W.value?.refreshing)),X=e(()=>Boolean(y.value?.fallback||y.value?.stale)),Y=e(()=>Boolean(W.value?.fallback||W.value?.stale)),Z=e(()=>Boolean(y.value?.refreshing&&0===a.value.length)),_=e(()=>Boolean(W.value?.refreshing&&0===F.value.length));function ee(){s.value&&E(H.value,s.value,{sessions:F.value,aliases:T.value,totalSize:U.value,projectInfo:r.value,meta:W.value,pagination:C.value},C.value)}function ae(e){D(j,S,e)}function le(e){if(!e)return;const a=`${e}:`;Array.from(J.keys()).filter(e=>e.startsWith(a)).forEach(e=>J.delete(e)),Array.from(K.keys()).filter(e=>e.startsWith(a)).forEach(e=>K.delete(e))}function te(e=H.value){ae(e),le(e)}function ne(e,a){D(w,A,P(e,a))}async function se({page:e=1,limit:l=20,query:t="",force:n=!1,silent:r=!1,pollAttempt:u=0,fresh:o=!1}={}){r||(x.value=!0),G.value=null;try{const i=H.value,v={page:e,limit:l,query:t},c=!n&&!o,f=`${i}${k(v)}`;if(!n&&!o){const t=B(i,v);if(t&&!t.meta?.refreshing)return K.set(f,++L),J.delete(f),a.value=p(t.projects),s.value=a.value.some(e=>e.name===t.currentProject)?t.currentProject:a.value[0]?.name||null,y.value=t.meta||null,R.value=t.pagination||{page:e,limit:l,total:a.value.length,hasMore:!1},void(r||(x.value=!1))}let m,h=J.get(f),d=h?K.get(f):null;if(!c||!h||!d){d=++L,K.set(f,d);const a={fresh:n||o};1!==e&&(a.page=e),l!==I&&(a.limit=l),t&&(a.q=t),h=g(i,a),J.set(f,h)}try{m=await h}finally{J.get(f)===h&&J.delete(f)}if(H.value!==i||K.get(f)!==d)return;const w=p(m.projects),M=0===w.length&&a.value.length>0&&1===e&&!t&&(!0===m.meta?.refreshing||!0===m.meta?.stale||!0===m.meta?.fallback||Boolean(m.meta?.error)),A=w.length>0||0===a.value.length||!M;y.value=m.meta||null,m.meta?.error&&(G.value=m.meta.error),A&&(R.value=m.pagination||{page:e,limit:l,total:w.length,hasMore:!1},a.value=w,s.value=w.some(e=>e.name===m.currentProject)?m.currentProject:w[0]?.name||null,!0!==m.meta?.fallback&&(z(i),q(i,{projects:w,currentProject:s.value,meta:m.meta||null,pagination:R.value},v))),m.meta?.refreshing?function(e,a=0){O(j,S,e,$,a,()=>{H.value===e&&se({force:!0,silent:!0,pollAttempt:a+1}).catch(()=>{})},()=>{H.value===e&&(y.value={...y.value||{},refreshing:!1,stale:!0,error:y.value?.error||"项目列表生成超时,请重试"},G.value=y.value.error)})}(i,u):ae(i)}catch(i){G.value=i.message}finally{r||(x.value=!1)}}async function re(e,{page:a=1,limit:l=20,query:t="",force:n=!1,silent:u=!1,pollAttempt:o=0,fresh:i=!1}={}){u||(x.value=!0),G.value=null;try{const v=H.value,c={page:a,limit:l,query:t};if(s.value===e||b(v,e,c)||(F.value=[],T.value={},U.value=0,r.value=null,W.value=null),!n){const t=b(v,e,c);if(t)return F.value=h(t.sessions,e),T.value=t.aliases||{},U.value=t.totalSize||0,s.value=e,r.value=t.projectInfo||null,W.value=t.meta||null,C.value=t.pagination||{page:a,limit:l,total:F.value.length,hasMore:!1},void(u||(x.value=!1))}s.value=e;const f={fresh:i};1!==a&&(f.page=a),l!==I&&(f.limit=l),t&&(f.q=t);const p=await m(e,v,f);if(H.value!==v||s.value!==e)return;const g=h(p.sessions,e),d=g.length>0||0===F.value.length||!0!==p.meta?.refreshing;W.value=p.meta||null,C.value=p.pagination||{page:a,limit:l,total:g.length,hasMore:!1},p.meta?.error&&(G.value=p.meta.error),s.value=e,d&&(F.value=g,T.value=p.aliases||{},U.value=p.totalSize||0,r.value=p.projectInfo||null,!0!==p.meta?.fallback&&E(v,e,{sessions:g,aliases:p.aliases||{},totalSize:p.totalSize||0,projectInfo:p.projectInfo||null,meta:p.meta||null,pagination:C.value},c)),p.meta?.refreshing?function(e,a,l=0){const t=P(e,a);O(w,A,t,M,l,()=>{H.value===e&&s.value===a&&re(a,{force:!0,silent:!0,pollAttempt:l+1}).catch(()=>{})},()=>{H.value===e&&s.value===a&&(W.value={...W.value||{},refreshing:!1,stale:!0,error:W.value?.error||"会话列表生成超时,请重试"},G.value=W.value.error)})}(v,e,o):ne(v,e)}catch(v){G.value=v.message}finally{u||(x.value=!1)}}return{projects:a,currentProject:s,currentProjectInfo:r,projectsMeta:y,sessionsMeta:W,projectsPagination:R,sessionsPagination:C,sessions:F,aliases:T,totalSize:U,loading:x,error:G,currentChannel:H,sessionsWithAlias:N,projectsRefreshing:Q,sessionsRefreshing:V,projectsUsingFallback:X,sessionsUsingFallback:Y,projectsPending:Z,sessionsPending:_,setChannel:function(e){if(!e||H.value===e)return;const l=H.value;te(l),Array.from(w.keys()).filter(e=>e.startsWith(`${l}:`)).forEach(e=>D(w,A,e)),le(e),H.value=e,a.value=[],s.value=null,y.value=null,R.value={page:1,limit:I,total:0,hasMore:!1},F.value=[],T.value={},U.value=0,r.value=null,W.value=null,C.value={page:1,limit:I,total:0,hasMore:!1},G.value=null;const t=B(e);t&&(a.value=p(t.projects),s.value=a.value.some(e=>e.name===t.currentProject)?t.currentProject:a.value[0]?.name||null,y.value=t.meta||null,R.value=t.pagination||R.value)},fetchProjects:se,fetchSessions:re,retryProjects:async function(){return ae(H.value),se({force:!0,fresh:Boolean(y.value?.error)})},retrySessions:async function(e=s.value){if(e)return ne(H.value,e),re(e,{page:C.value.page,limit:C.value.limit,force:!0,fresh:Boolean(W.value?.error)})},pauseProjectRefresh:te,setAlias:async function(e,a){try{await v(e,a),T.value[e]=a}catch(l){throw G.value=l.message,l}},deleteAlias:async function(e){try{await c(e),delete T.value[e]}catch(a){throw G.value=a.message,a}},deleteSession:async function(e){try{await f(s.value,e,H.value),F.value=F.value.filter(a=>a.sessionId!==e),T.value[e]&&delete T.value[e],ee()}catch(a){throw G.value=a.message,a}},deleteSessions:async function(e=[]){const a=Array.from(new Set((e||[]).filter(Boolean)));if(0===a.length)return{deletedSessionIds:[],failed:[]};let l=[],t=[];try{const e=await i(s.value,a,H.value);l=Array.isArray(e?.deletedSessionIds)?e.deletedSessionIds:[],t=Array.isArray(e?.failed)?e.failed.map(e=>({sessionId:e.sessionId,error:new Error(e.error||"删除失败")})):[]}catch(n){throw G.value=n.message,n}if(l.length>0){const e=new Set(l);F.value=F.value.filter(a=>!e.has(a.sessionId)),Object.keys(T.value).forEach(a=>{e.has(a)&&delete T.value[a]}),ee()}return t.length>0&&0===l.length&&(G.value=t[0].error.message),{deletedSessionIds:l,failed:t}},forkSession:async function(e,a={}){try{const l=await u(s.value,e,H.value,a);return await re(s.value,{page:C.value.page,limit:C.value.limit,force:!0,fresh:!0}),l.newSessionId}catch(l){throw G.value=l.message,l}},saveProjectOrder:async function(e){try{await async function(e,a="claude"){const l=t(a);return(await n.post(`${l}/projects/order`,{order:e})).data}(e,H.value);const l=e.map(e=>a.value.find(a=>a.name===e)).filter(Boolean),r=a.value.filter(a=>!e.includes(a.name));a.value=[...l,...r],q(H.value,{projects:a.value,currentProject:s.value,meta:y.value,pagination:R.value},R.value)}catch(l){throw G.value=l.message,l}},saveSessionOrder:async function(e){try{await o(s.value,e,H.value);const a=e.map(e=>F.value.find(a=>a.sessionId===e)).filter(Boolean),l=F.value.filter(a=>!e.includes(a.sessionId));F.value=[...a,...l],E(H.value,s.value,{sessions:F.value,aliases:T.value,totalSize:U.value,projectInfo:r.value,meta:W.value,pagination:C.value},C.value)}catch(a){throw G.value=a.message,a}},deleteProject:async function(e){try{await async function(e,a="claude"){const l=t(a);return(await n.delete(`${l}/projects/${e}`)).data}(e,H.value),a.value=a.value.filter(a=>a.name!==e),s.value===e&&(s.value=null),l=H.value,Array.from(d.keys()).filter(e=>e.startsWith(`${l}:`)).forEach(e=>d.delete(e)),z(H.value,e)}catch(r){throw G.value=r.message,r}var l}}});export{g as n,R as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{F as e,I as t,It as n,Jt as r,N as o,Nt as i,Qt as a,Rt as s,Tt as l,Ut as d,Wt as c,Zt as u,gn as h,gt as m,hn as v,ht as b,jt as f,kt as p,qt as g,vn as w,w as y,y as z,yn as $,zt as x}from"./_plugin-vue_export-helper-BeLZJZij.js";import{A as S,F as k,G as C,H as E,M as B,N as F,Q as M,V as R,Z as H,b as O,dt as A,f as T,l as W,st as D,tt as N,z as P}from"./vue-vendor-BqZbbXHA.js";import{n as U,t as j}from"./use-lock-html-scroll-DXIqmUW4.js";import{J as L}from"./index-Cmmwj3Fx.js";var I=S({name:"NDrawerContent",inheritAttrs:!1,props:{blockScroll:Boolean,show:{type:Boolean,default:void 0},displayDirective:{type:String,required:!0},placement:{type:String,required:!0},contentClass:String,contentStyle:[Object,String],nativeScrollbar:{type:Boolean,required:!0},scrollbarProps:Object,trapFocus:{type:Boolean,default:!0},autoFocus:{type:Boolean,default:!0},showMask:{type:[Boolean,String],required:!0},maxWidth:Number,maxHeight:Number,minWidth:Number,minHeight:Number,resizable:Boolean,onClickoutside:Function,onAfterLeave:Function,onAfterEnter:Function,onEsc:Function},setup(e){const n=D(!!e.show),o=D(null),i=F(r);let a=0,s="",l=null;const u=D(!1),h=D(!1),v=O(()=>"top"===e.placement||"bottom"===e.placement),{mergedClsPrefixRef:b,mergedRtlRef:f}=m(e),p=t("Drawer",f,b),w=S,{doUpdateHeight:y,doUpdateWidth:z}=i;function $(t){var n,r;if(h.value)if(v.value){let r=(null===(n=o.value)||void 0===n?void 0:n.offsetHeight)||0;const i=a-t.clientY;r+="bottom"===e.placement?i:-i,r=(t=>{const{maxHeight:n}=e;if(n&&t>n)return n;const{minHeight:r}=e;return r&&t<r?r:t})(r),y(r),a=t.clientY}else{let n=(null===(r=o.value)||void 0===r?void 0:r.offsetWidth)||0;const i=a-t.clientX;n+="right"===e.placement?i:-i,n=(t=>{const{maxWidth:n}=e;if(n&&t>n)return n;const{minWidth:r}=e;return r&&t<r?r:t})(n),z(n),a=t.clientX}}function S(){h.value&&(a=0,h.value=!1,document.body.style.cursor=s,document.body.removeEventListener("mousemove",$),document.body.removeEventListener("mouseup",S),document.body.removeEventListener("mouseleave",w))}M(()=>{e.show&&(n.value=!0)}),H(()=>e.show,e=>{e||S()}),P(()=>{S()});const k=O(()=>{const{show:t}=e,n=[[T,t]];return e.showMask||n.push([x,e.onClickoutside,void 0,{capture:!0}]),n});return j(O(()=>e.blockScroll&&n.value)),C(g,o),C(d,null),C(c,null),{bodyRef:o,rtlEnabled:p,mergedClsPrefix:i.mergedClsPrefixRef,isMounted:i.isMountedRef,mergedTheme:i.mergedThemeRef,displayed:n,transitionName:O(()=>({right:"slide-in-from-right-transition",left:"slide-in-from-left-transition",top:"slide-in-from-top-transition",bottom:"slide-in-from-bottom-transition"}[e.placement])),handleAfterLeave:function(){var t;n.value=!1,null===(t=e.onAfterLeave)||void 0===t||t.call(e)},bodyDirectives:k,handleMousedownResizeTrigger:e=>{h.value=!0,a=v.value?e.clientY:e.clientX,s=document.body.style.cursor,document.body.style.cursor=v.value?"ns-resize":"ew-resize",document.body.addEventListener("mousemove",$),document.body.addEventListener("mouseleave",w),document.body.addEventListener("mouseup",S)},handleMouseenterResizeTrigger:()=>{null!==l&&(window.clearTimeout(l),l=null),h.value?u.value=!0:l=window.setTimeout(()=>{u.value=!0},300)},handleMouseleaveResizeTrigger:()=>{null!==l&&(window.clearTimeout(l),l=null),u.value=!1},isDragging:h,isHoverOnResizeTrigger:u}},render(){const{$slots:e,mergedClsPrefix:t}=this;return"show"===this.displayDirective||this.displayed||this.show?N(B("div",{role:"none"},B(i,{disabled:!this.showMask||!this.trapFocus,active:this.show,autoFocus:this.autoFocus,onEsc:this.onEsc},{default:()=>B(W,{name:this.transitionName,appear:this.isMounted,onAfterEnter:this.onAfterEnter,onAfterLeave:this.handleAfterLeave},{default:()=>N(B("div",k(this.$attrs,{role:"dialog",ref:"bodyRef","aria-modal":"true",class:[`${t}-drawer`,this.rtlEnabled&&`${t}-drawer--rtl`,`${t}-drawer--${this.placement}-placement`,this.isDragging&&`${t}-drawer--unselectable`,this.nativeScrollbar&&`${t}-drawer--native-scrollbar`]}),[this.resizable?B("div",{class:[`${t}-drawer__resize-trigger`,(this.isDragging||this.isHoverOnResizeTrigger)&&`${t}-drawer__resize-trigger--hover`],onMouseenter:this.handleMouseenterResizeTrigger,onMouseleave:this.handleMouseleaveResizeTrigger,onMousedown:this.handleMousedownResizeTrigger}):null,this.nativeScrollbar?B("div",{class:[`${t}-drawer-content-wrapper`,this.contentClass],style:this.contentStyle,role:"none"},e):B(z,Object.assign({},this.scrollbarProps,{contentStyle:this.contentStyle,contentClass:[`${t}-drawer-content-wrapper`,this.contentClass],theme:this.mergedTheme.peers.Scrollbar,themeOverrides:this.mergedTheme.peerOverrides.Scrollbar}),e)]),this.bodyDirectives)})})),[[T,"if"===this.displayDirective||this.displayed||this.show]]):null}}),{cubicBezierEaseIn:X,cubicBezierEaseOut:Y}=e;var{cubicBezierEaseIn:_,cubicBezierEaseOut:q}=e;var{cubicBezierEaseIn:V,cubicBezierEaseOut:J}=e;var{cubicBezierEaseIn:Q,cubicBezierEaseOut:Z}=e;var G=v([h("drawer","\n word-break: break-word;\n line-height: var(--n-line-height);\n position: absolute;\n pointer-events: all;\n box-shadow: var(--n-box-shadow);\n transition:\n background-color .3s var(--n-bezier),\n color .3s var(--n-bezier);\n background-color: var(--n-color);\n color: var(--n-text-color);\n box-sizing: border-box;\n ",[function({duration:e="0.3s",leaveDuration:t="0.2s",name:n="slide-in-from-right"}={}){return[v(`&.${n}-transition-leave-active`,{transition:`transform ${t} ${V}`}),v(`&.${n}-transition-enter-active`,{transition:`transform ${e} ${J}`}),v(`&.${n}-transition-enter-to`,{transform:"translateX(0)"}),v(`&.${n}-transition-enter-from`,{transform:"translateX(100%)"}),v(`&.${n}-transition-leave-from`,{transform:"translateX(0)"}),v(`&.${n}-transition-leave-to`,{transform:"translateX(100%)"})]}(),function({duration:e="0.3s",leaveDuration:t="0.2s",name:n="slide-in-from-left"}={}){return[v(`&.${n}-transition-leave-active`,{transition:`transform ${t} ${_}`}),v(`&.${n}-transition-enter-active`,{transition:`transform ${e} ${q}`}),v(`&.${n}-transition-enter-to`,{transform:"translateX(0)"}),v(`&.${n}-transition-enter-from`,{transform:"translateX(-100%)"}),v(`&.${n}-transition-leave-from`,{transform:"translateX(0)"}),v(`&.${n}-transition-leave-to`,{transform:"translateX(-100%)"})]}(),function({duration:e="0.3s",leaveDuration:t="0.2s",name:n="slide-in-from-top"}={}){return[v(`&.${n}-transition-leave-active`,{transition:`transform ${t} ${Q}`}),v(`&.${n}-transition-enter-active`,{transition:`transform ${e} ${Z}`}),v(`&.${n}-transition-enter-to`,{transform:"translateY(0)"}),v(`&.${n}-transition-enter-from`,{transform:"translateY(-100%)"}),v(`&.${n}-transition-leave-from`,{transform:"translateY(0)"}),v(`&.${n}-transition-leave-to`,{transform:"translateY(-100%)"})]}(),function({duration:e="0.3s",leaveDuration:t="0.2s",name:n="slide-in-from-bottom"}={}){return[v(`&.${n}-transition-leave-active`,{transition:`transform ${t} ${X}`}),v(`&.${n}-transition-enter-active`,{transition:`transform ${e} ${Y}`}),v(`&.${n}-transition-enter-to`,{transform:"translateY(0)"}),v(`&.${n}-transition-enter-from`,{transform:"translateY(100%)"}),v(`&.${n}-transition-leave-from`,{transform:"translateY(0)"}),v(`&.${n}-transition-leave-to`,{transform:"translateY(100%)"})]}(),$("unselectable","\n user-select: none; \n -webkit-user-select: none;\n "),$("native-scrollbar",[h("drawer-content-wrapper","\n overflow: auto;\n height: 100%;\n ")]),w("resize-trigger","\n position: absolute;\n background-color: #0000;\n transition: background-color .3s var(--n-bezier);\n ",[$("hover","\n background-color: var(--n-resize-trigger-color-hover);\n ")]),h("drawer-content-wrapper","\n box-sizing: border-box;\n "),h("drawer-content","\n height: 100%;\n display: flex;\n flex-direction: column;\n ",[$("native-scrollbar",[h("drawer-body-content-wrapper","\n height: 100%;\n overflow: auto;\n ")]),h("drawer-body","\n flex: 1 0 0;\n overflow: hidden;\n "),h("drawer-body-content-wrapper","\n box-sizing: border-box;\n padding: var(--n-body-padding);\n "),h("drawer-header","\n font-weight: var(--n-title-font-weight);\n line-height: 1;\n font-size: var(--n-title-font-size);\n color: var(--n-title-text-color);\n padding: var(--n-header-padding);\n transition: border .3s var(--n-bezier);\n border-bottom: 1px solid var(--n-divider-color);\n border-bottom: var(--n-header-border-bottom);\n display: flex;\n justify-content: space-between;\n align-items: center;\n ",[w("main","\n flex: 1;\n "),w("close","\n margin-left: 6px;\n transition:\n background-color .3s var(--n-bezier),\n color .3s var(--n-bezier);\n ")]),h("drawer-footer","\n display: flex;\n justify-content: flex-end;\n border-top: var(--n-footer-border-top);\n transition: border .3s var(--n-bezier);\n padding: var(--n-footer-padding);\n ")]),$("right-placement","\n top: 0;\n bottom: 0;\n right: 0;\n border-top-left-radius: var(--n-border-radius);\n border-bottom-left-radius: var(--n-border-radius);\n ",[w("resize-trigger","\n width: 3px;\n height: 100%;\n top: 0;\n left: 0;\n transform: translateX(-1.5px);\n cursor: ew-resize;\n ")]),$("left-placement","\n top: 0;\n bottom: 0;\n left: 0;\n border-top-right-radius: var(--n-border-radius);\n border-bottom-right-radius: var(--n-border-radius);\n ",[w("resize-trigger","\n width: 3px;\n height: 100%;\n top: 0;\n right: 0;\n transform: translateX(1.5px);\n cursor: ew-resize;\n ")]),$("top-placement","\n top: 0;\n left: 0;\n right: 0;\n border-bottom-left-radius: var(--n-border-radius);\n border-bottom-right-radius: var(--n-border-radius);\n ",[w("resize-trigger","\n width: 100%;\n height: 3px;\n bottom: 0;\n left: 0;\n transform: translateY(1.5px);\n cursor: ns-resize;\n ")]),$("bottom-placement","\n left: 0;\n bottom: 0;\n right: 0;\n border-top-left-radius: var(--n-border-radius);\n border-top-right-radius: var(--n-border-radius);\n ",[w("resize-trigger","\n width: 100%;\n height: 3px;\n top: 0;\n left: 0;\n transform: translateY(-1.5px);\n cursor: ns-resize;\n ")])]),v("body",[v(">",[h("drawer-container","\n position: fixed;\n ")])]),h("drawer-container","\n position: relative;\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n pointer-events: none;\n ",[v("> *","\n pointer-events: all;\n ")]),h("drawer-mask","\n background-color: rgba(0, 0, 0, .3);\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n ",[$("invisible","\n background-color: rgba(0, 0, 0, 0)\n "),y({enterDuration:"0.2s",leaveDuration:"0.2s",enterCubicBezier:"var(--n-bezier-in)",leaveCubicBezier:"var(--n-bezier-out)"})])]),K=S({name:"Drawer",inheritAttrs:!1,props:Object.assign(Object.assign({},o.props),{show:Boolean,width:[Number,String],height:[Number,String],placement:{type:String,default:"right"},maskClosable:{type:Boolean,default:!0},showMask:{type:[Boolean,String],default:!0},to:[String,Object],displayDirective:{type:String,default:"if"},nativeScrollbar:{type:Boolean,default:!0},zIndex:Number,onMaskClick:Function,scrollbarProps:Object,contentClass:String,contentStyle:[Object,String],trapFocus:{type:Boolean,default:!0},onEsc:Function,autoFocus:{type:Boolean,default:!0},closeOnEsc:{type:Boolean,default:!0},blockScroll:{type:Boolean,default:!0},maxWidth:Number,maxHeight:Number,minWidth:Number,minHeight:Number,resizable:Boolean,defaultWidth:{type:[Number,String],default:251},defaultHeight:{type:[Number,String],default:251},onUpdateWidth:[Function,Array],onUpdateHeight:[Function,Array],"onUpdate:width":[Function,Array],"onUpdate:height":[Function,Array],"onUpdate:show":[Function,Array],onUpdateShow:[Function,Array],onAfterEnter:Function,onAfterLeave:Function,drawerStyle:[String,Object],drawerClass:String,target:null,onShow:Function,onHide:Function}),setup(e){const{mergedClsPrefixRef:t,namespaceRef:n,inlineThemeDisabled:i}=m(e),s=u(),d=o("Drawer","-drawer",G,L,e,t),c=D(e.defaultWidth),h=D(e.defaultHeight),v=a(A(e,"width"),c),g=a(A(e,"height"),h),w=O(()=>{const{placement:t}=e;return"top"===t||"bottom"===t?"":f(v.value)}),y=O(()=>{const{placement:t}=e;return"left"===t||"right"===t?"":f(g.value)}),z=O(()=>[{width:w.value,height:y.value},e.drawerStyle||""]);function $(t){const{onMaskClick:n,maskClosable:r}=e;r&&S(!1),n&&n(t)}const x=U();function S(t){const{onHide:n,onUpdateShow:r,"onUpdate:show":o}=e;r&&l(r,t),o&&l(o,t),n&&!t&&l(n,t)}C(r,{isMountedRef:s,mergedThemeRef:d,mergedClsPrefixRef:t,doUpdateShow:S,doUpdateHeight:t=>{const{onUpdateHeight:n,"onUpdate:width":r}=e;n&&l(n,t),r&&l(r,t),h.value=t},doUpdateWidth:t=>{const{onUpdateWidth:n,"onUpdate:width":r}=e;n&&l(n,t),r&&l(r,t),c.value=t}});const k=O(()=>{const{common:{cubicBezierEaseInOut:e,cubicBezierEaseIn:t,cubicBezierEaseOut:n},self:{color:r,textColor:o,boxShadow:i,lineHeight:a,headerPadding:s,footerPadding:l,borderRadius:c,bodyPadding:u,titleFontSize:h,titleTextColor:m,titleFontWeight:v,headerBorderBottom:b,footerBorderTop:f,closeIconColor:p,closeIconColorHover:g,closeIconColorPressed:w,closeColorHover:y,closeColorPressed:z,closeIconSize:$,closeSize:x,closeBorderRadius:S,resizableTriggerColorHover:k}}=d.value;return{"--n-line-height":a,"--n-color":r,"--n-border-radius":c,"--n-text-color":o,"--n-box-shadow":i,"--n-bezier":e,"--n-bezier-out":n,"--n-bezier-in":t,"--n-header-padding":s,"--n-body-padding":u,"--n-footer-padding":l,"--n-title-text-color":m,"--n-title-font-size":h,"--n-title-font-weight":v,"--n-header-border-bottom":b,"--n-footer-border-top":f,"--n-close-icon-color":p,"--n-close-icon-color-hover":g,"--n-close-icon-color-pressed":w,"--n-close-size":x,"--n-close-color-hover":y,"--n-close-color-pressed":z,"--n-close-icon-size":$,"--n-close-border-radius":S,"--n-resize-trigger-color-hover":k}}),E=i?b("drawer",void 0,k,e):void 0;return{mergedClsPrefix:t,namespace:n,mergedBodyStyle:z,handleOutsideClick:function(e){$(e)},handleMaskClick:$,handleEsc:function(t){var n;null===(n=e.onEsc)||void 0===n||n.call(e),e.show&&e.closeOnEsc&&p(t)&&(x.value||S(!1))},mergedTheme:d,cssVars:i?void 0:k,themeClass:null==E?void 0:E.themeClass,onRender:null==E?void 0:E.onRender,isMounted:s}},render(){const{mergedClsPrefix:e}=this;return B(n,{to:this.to,show:this.show},{default:()=>{var t;return null===(t=this.onRender)||void 0===t||t.call(this),N(B("div",{class:[`${e}-drawer-container`,this.namespace,this.themeClass],style:this.cssVars,role:"none"},this.showMask?B(W,{name:"fade-in-transition",appear:this.isMounted},{default:()=>this.show?B("div",{"aria-hidden":!0,class:[`${e}-drawer-mask`,"transparent"===this.showMask&&`${e}-drawer-mask--invisible`],onClick:this.handleMaskClick}):null}):null,B(I,Object.assign({},this.$attrs,{class:[this.drawerClass,this.$attrs.class],style:[this.mergedBodyStyle,this.$attrs.style],blockScroll:this.blockScroll,contentStyle:this.contentStyle,contentClass:this.contentClass,placement:this.placement,scrollbarProps:this.scrollbarProps,show:this.show,displayDirective:this.displayDirective,nativeScrollbar:this.nativeScrollbar,onAfterEnter:this.onAfterEnter,onAfterLeave:this.onAfterLeave,trapFocus:this.trapFocus,autoFocus:this.autoFocus,resizable:this.resizable,maxHeight:this.maxHeight,minHeight:this.minHeight,maxWidth:this.maxWidth,minWidth:this.minWidth,showMask:this.showMask,onEsc:this.handleEsc,onClickoutside:this.handleOutsideClick}),this.$slots)),[[s,{zIndex:this.zIndex,enabled:this.show}]])}})}});function ee(e=520,t=null){const n=D("undefined"!=typeof window?window.innerWidth:1200),r=()=>{n.value=window.innerWidth};R(()=>{window.addEventListener("resize",r)}),E(()=>{window.removeEventListener("resize",r)});const o=O(()=>n.value<640),i=O(()=>n.value>=640&&n.value<1024);return{drawerWidth:O(()=>{if(n.value<640)return"100%";if(n.value<768)return Math.min(.95*n.value,e);if(n.value<1024){const r=t||e;return Math.min(.85*n.value,r)}return e}),isMobile:o,isTablet:i,windowWidth:n}}export{K as n,ee as t};
|
|
1
|
+
import{F as e,I as t,It as n,Jt as r,N as o,Nt as i,Qt as a,Rt as s,Tt as l,Ut as d,Wt as c,Zt as u,gn as h,gt as m,hn as v,ht as b,jt as f,kt as p,qt as g,vn as w,w as y,y as z,yn as $,zt as x}from"./_plugin-vue_export-helper-BeLZJZij.js";import{A as S,F as k,G as C,H as E,M as B,N as F,Q as M,V as R,Z as H,b as O,dt as A,f as T,l as W,st as D,tt as N,z as P}from"./vue-vendor-BqZbbXHA.js";import{n as U,t as j}from"./use-lock-html-scroll-DXIqmUW4.js";import{J as L}from"./index-BKlAWTH-.js";var I=S({name:"NDrawerContent",inheritAttrs:!1,props:{blockScroll:Boolean,show:{type:Boolean,default:void 0},displayDirective:{type:String,required:!0},placement:{type:String,required:!0},contentClass:String,contentStyle:[Object,String],nativeScrollbar:{type:Boolean,required:!0},scrollbarProps:Object,trapFocus:{type:Boolean,default:!0},autoFocus:{type:Boolean,default:!0},showMask:{type:[Boolean,String],required:!0},maxWidth:Number,maxHeight:Number,minWidth:Number,minHeight:Number,resizable:Boolean,onClickoutside:Function,onAfterLeave:Function,onAfterEnter:Function,onEsc:Function},setup(e){const n=D(!!e.show),o=D(null),i=F(r);let a=0,s="",l=null;const u=D(!1),h=D(!1),v=O(()=>"top"===e.placement||"bottom"===e.placement),{mergedClsPrefixRef:b,mergedRtlRef:f}=m(e),p=t("Drawer",f,b),w=S,{doUpdateHeight:y,doUpdateWidth:z}=i;function $(t){var n,r;if(h.value)if(v.value){let r=(null===(n=o.value)||void 0===n?void 0:n.offsetHeight)||0;const i=a-t.clientY;r+="bottom"===e.placement?i:-i,r=(t=>{const{maxHeight:n}=e;if(n&&t>n)return n;const{minHeight:r}=e;return r&&t<r?r:t})(r),y(r),a=t.clientY}else{let n=(null===(r=o.value)||void 0===r?void 0:r.offsetWidth)||0;const i=a-t.clientX;n+="right"===e.placement?i:-i,n=(t=>{const{maxWidth:n}=e;if(n&&t>n)return n;const{minWidth:r}=e;return r&&t<r?r:t})(n),z(n),a=t.clientX}}function S(){h.value&&(a=0,h.value=!1,document.body.style.cursor=s,document.body.removeEventListener("mousemove",$),document.body.removeEventListener("mouseup",S),document.body.removeEventListener("mouseleave",w))}M(()=>{e.show&&(n.value=!0)}),H(()=>e.show,e=>{e||S()}),P(()=>{S()});const k=O(()=>{const{show:t}=e,n=[[T,t]];return e.showMask||n.push([x,e.onClickoutside,void 0,{capture:!0}]),n});return j(O(()=>e.blockScroll&&n.value)),C(g,o),C(d,null),C(c,null),{bodyRef:o,rtlEnabled:p,mergedClsPrefix:i.mergedClsPrefixRef,isMounted:i.isMountedRef,mergedTheme:i.mergedThemeRef,displayed:n,transitionName:O(()=>({right:"slide-in-from-right-transition",left:"slide-in-from-left-transition",top:"slide-in-from-top-transition",bottom:"slide-in-from-bottom-transition"}[e.placement])),handleAfterLeave:function(){var t;n.value=!1,null===(t=e.onAfterLeave)||void 0===t||t.call(e)},bodyDirectives:k,handleMousedownResizeTrigger:e=>{h.value=!0,a=v.value?e.clientY:e.clientX,s=document.body.style.cursor,document.body.style.cursor=v.value?"ns-resize":"ew-resize",document.body.addEventListener("mousemove",$),document.body.addEventListener("mouseleave",w),document.body.addEventListener("mouseup",S)},handleMouseenterResizeTrigger:()=>{null!==l&&(window.clearTimeout(l),l=null),h.value?u.value=!0:l=window.setTimeout(()=>{u.value=!0},300)},handleMouseleaveResizeTrigger:()=>{null!==l&&(window.clearTimeout(l),l=null),u.value=!1},isDragging:h,isHoverOnResizeTrigger:u}},render(){const{$slots:e,mergedClsPrefix:t}=this;return"show"===this.displayDirective||this.displayed||this.show?N(B("div",{role:"none"},B(i,{disabled:!this.showMask||!this.trapFocus,active:this.show,autoFocus:this.autoFocus,onEsc:this.onEsc},{default:()=>B(W,{name:this.transitionName,appear:this.isMounted,onAfterEnter:this.onAfterEnter,onAfterLeave:this.handleAfterLeave},{default:()=>N(B("div",k(this.$attrs,{role:"dialog",ref:"bodyRef","aria-modal":"true",class:[`${t}-drawer`,this.rtlEnabled&&`${t}-drawer--rtl`,`${t}-drawer--${this.placement}-placement`,this.isDragging&&`${t}-drawer--unselectable`,this.nativeScrollbar&&`${t}-drawer--native-scrollbar`]}),[this.resizable?B("div",{class:[`${t}-drawer__resize-trigger`,(this.isDragging||this.isHoverOnResizeTrigger)&&`${t}-drawer__resize-trigger--hover`],onMouseenter:this.handleMouseenterResizeTrigger,onMouseleave:this.handleMouseleaveResizeTrigger,onMousedown:this.handleMousedownResizeTrigger}):null,this.nativeScrollbar?B("div",{class:[`${t}-drawer-content-wrapper`,this.contentClass],style:this.contentStyle,role:"none"},e):B(z,Object.assign({},this.scrollbarProps,{contentStyle:this.contentStyle,contentClass:[`${t}-drawer-content-wrapper`,this.contentClass],theme:this.mergedTheme.peers.Scrollbar,themeOverrides:this.mergedTheme.peerOverrides.Scrollbar}),e)]),this.bodyDirectives)})})),[[T,"if"===this.displayDirective||this.displayed||this.show]]):null}}),{cubicBezierEaseIn:X,cubicBezierEaseOut:Y}=e;var{cubicBezierEaseIn:_,cubicBezierEaseOut:q}=e;var{cubicBezierEaseIn:V,cubicBezierEaseOut:J}=e;var{cubicBezierEaseIn:Q,cubicBezierEaseOut:Z}=e;var G=v([h("drawer","\n word-break: break-word;\n line-height: var(--n-line-height);\n position: absolute;\n pointer-events: all;\n box-shadow: var(--n-box-shadow);\n transition:\n background-color .3s var(--n-bezier),\n color .3s var(--n-bezier);\n background-color: var(--n-color);\n color: var(--n-text-color);\n box-sizing: border-box;\n ",[function({duration:e="0.3s",leaveDuration:t="0.2s",name:n="slide-in-from-right"}={}){return[v(`&.${n}-transition-leave-active`,{transition:`transform ${t} ${V}`}),v(`&.${n}-transition-enter-active`,{transition:`transform ${e} ${J}`}),v(`&.${n}-transition-enter-to`,{transform:"translateX(0)"}),v(`&.${n}-transition-enter-from`,{transform:"translateX(100%)"}),v(`&.${n}-transition-leave-from`,{transform:"translateX(0)"}),v(`&.${n}-transition-leave-to`,{transform:"translateX(100%)"})]}(),function({duration:e="0.3s",leaveDuration:t="0.2s",name:n="slide-in-from-left"}={}){return[v(`&.${n}-transition-leave-active`,{transition:`transform ${t} ${_}`}),v(`&.${n}-transition-enter-active`,{transition:`transform ${e} ${q}`}),v(`&.${n}-transition-enter-to`,{transform:"translateX(0)"}),v(`&.${n}-transition-enter-from`,{transform:"translateX(-100%)"}),v(`&.${n}-transition-leave-from`,{transform:"translateX(0)"}),v(`&.${n}-transition-leave-to`,{transform:"translateX(-100%)"})]}(),function({duration:e="0.3s",leaveDuration:t="0.2s",name:n="slide-in-from-top"}={}){return[v(`&.${n}-transition-leave-active`,{transition:`transform ${t} ${Q}`}),v(`&.${n}-transition-enter-active`,{transition:`transform ${e} ${Z}`}),v(`&.${n}-transition-enter-to`,{transform:"translateY(0)"}),v(`&.${n}-transition-enter-from`,{transform:"translateY(-100%)"}),v(`&.${n}-transition-leave-from`,{transform:"translateY(0)"}),v(`&.${n}-transition-leave-to`,{transform:"translateY(-100%)"})]}(),function({duration:e="0.3s",leaveDuration:t="0.2s",name:n="slide-in-from-bottom"}={}){return[v(`&.${n}-transition-leave-active`,{transition:`transform ${t} ${X}`}),v(`&.${n}-transition-enter-active`,{transition:`transform ${e} ${Y}`}),v(`&.${n}-transition-enter-to`,{transform:"translateY(0)"}),v(`&.${n}-transition-enter-from`,{transform:"translateY(100%)"}),v(`&.${n}-transition-leave-from`,{transform:"translateY(0)"}),v(`&.${n}-transition-leave-to`,{transform:"translateY(100%)"})]}(),$("unselectable","\n user-select: none; \n -webkit-user-select: none;\n "),$("native-scrollbar",[h("drawer-content-wrapper","\n overflow: auto;\n height: 100%;\n ")]),w("resize-trigger","\n position: absolute;\n background-color: #0000;\n transition: background-color .3s var(--n-bezier);\n ",[$("hover","\n background-color: var(--n-resize-trigger-color-hover);\n ")]),h("drawer-content-wrapper","\n box-sizing: border-box;\n "),h("drawer-content","\n height: 100%;\n display: flex;\n flex-direction: column;\n ",[$("native-scrollbar",[h("drawer-body-content-wrapper","\n height: 100%;\n overflow: auto;\n ")]),h("drawer-body","\n flex: 1 0 0;\n overflow: hidden;\n "),h("drawer-body-content-wrapper","\n box-sizing: border-box;\n padding: var(--n-body-padding);\n "),h("drawer-header","\n font-weight: var(--n-title-font-weight);\n line-height: 1;\n font-size: var(--n-title-font-size);\n color: var(--n-title-text-color);\n padding: var(--n-header-padding);\n transition: border .3s var(--n-bezier);\n border-bottom: 1px solid var(--n-divider-color);\n border-bottom: var(--n-header-border-bottom);\n display: flex;\n justify-content: space-between;\n align-items: center;\n ",[w("main","\n flex: 1;\n "),w("close","\n margin-left: 6px;\n transition:\n background-color .3s var(--n-bezier),\n color .3s var(--n-bezier);\n ")]),h("drawer-footer","\n display: flex;\n justify-content: flex-end;\n border-top: var(--n-footer-border-top);\n transition: border .3s var(--n-bezier);\n padding: var(--n-footer-padding);\n ")]),$("right-placement","\n top: 0;\n bottom: 0;\n right: 0;\n border-top-left-radius: var(--n-border-radius);\n border-bottom-left-radius: var(--n-border-radius);\n ",[w("resize-trigger","\n width: 3px;\n height: 100%;\n top: 0;\n left: 0;\n transform: translateX(-1.5px);\n cursor: ew-resize;\n ")]),$("left-placement","\n top: 0;\n bottom: 0;\n left: 0;\n border-top-right-radius: var(--n-border-radius);\n border-bottom-right-radius: var(--n-border-radius);\n ",[w("resize-trigger","\n width: 3px;\n height: 100%;\n top: 0;\n right: 0;\n transform: translateX(1.5px);\n cursor: ew-resize;\n ")]),$("top-placement","\n top: 0;\n left: 0;\n right: 0;\n border-bottom-left-radius: var(--n-border-radius);\n border-bottom-right-radius: var(--n-border-radius);\n ",[w("resize-trigger","\n width: 100%;\n height: 3px;\n bottom: 0;\n left: 0;\n transform: translateY(1.5px);\n cursor: ns-resize;\n ")]),$("bottom-placement","\n left: 0;\n bottom: 0;\n right: 0;\n border-top-left-radius: var(--n-border-radius);\n border-top-right-radius: var(--n-border-radius);\n ",[w("resize-trigger","\n width: 100%;\n height: 3px;\n top: 0;\n left: 0;\n transform: translateY(-1.5px);\n cursor: ns-resize;\n ")])]),v("body",[v(">",[h("drawer-container","\n position: fixed;\n ")])]),h("drawer-container","\n position: relative;\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n pointer-events: none;\n ",[v("> *","\n pointer-events: all;\n ")]),h("drawer-mask","\n background-color: rgba(0, 0, 0, .3);\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n ",[$("invisible","\n background-color: rgba(0, 0, 0, 0)\n "),y({enterDuration:"0.2s",leaveDuration:"0.2s",enterCubicBezier:"var(--n-bezier-in)",leaveCubicBezier:"var(--n-bezier-out)"})])]),K=S({name:"Drawer",inheritAttrs:!1,props:Object.assign(Object.assign({},o.props),{show:Boolean,width:[Number,String],height:[Number,String],placement:{type:String,default:"right"},maskClosable:{type:Boolean,default:!0},showMask:{type:[Boolean,String],default:!0},to:[String,Object],displayDirective:{type:String,default:"if"},nativeScrollbar:{type:Boolean,default:!0},zIndex:Number,onMaskClick:Function,scrollbarProps:Object,contentClass:String,contentStyle:[Object,String],trapFocus:{type:Boolean,default:!0},onEsc:Function,autoFocus:{type:Boolean,default:!0},closeOnEsc:{type:Boolean,default:!0},blockScroll:{type:Boolean,default:!0},maxWidth:Number,maxHeight:Number,minWidth:Number,minHeight:Number,resizable:Boolean,defaultWidth:{type:[Number,String],default:251},defaultHeight:{type:[Number,String],default:251},onUpdateWidth:[Function,Array],onUpdateHeight:[Function,Array],"onUpdate:width":[Function,Array],"onUpdate:height":[Function,Array],"onUpdate:show":[Function,Array],onUpdateShow:[Function,Array],onAfterEnter:Function,onAfterLeave:Function,drawerStyle:[String,Object],drawerClass:String,target:null,onShow:Function,onHide:Function}),setup(e){const{mergedClsPrefixRef:t,namespaceRef:n,inlineThemeDisabled:i}=m(e),s=u(),d=o("Drawer","-drawer",G,L,e,t),c=D(e.defaultWidth),h=D(e.defaultHeight),v=a(A(e,"width"),c),g=a(A(e,"height"),h),w=O(()=>{const{placement:t}=e;return"top"===t||"bottom"===t?"":f(v.value)}),y=O(()=>{const{placement:t}=e;return"left"===t||"right"===t?"":f(g.value)}),z=O(()=>[{width:w.value,height:y.value},e.drawerStyle||""]);function $(t){const{onMaskClick:n,maskClosable:r}=e;r&&S(!1),n&&n(t)}const x=U();function S(t){const{onHide:n,onUpdateShow:r,"onUpdate:show":o}=e;r&&l(r,t),o&&l(o,t),n&&!t&&l(n,t)}C(r,{isMountedRef:s,mergedThemeRef:d,mergedClsPrefixRef:t,doUpdateShow:S,doUpdateHeight:t=>{const{onUpdateHeight:n,"onUpdate:width":r}=e;n&&l(n,t),r&&l(r,t),h.value=t},doUpdateWidth:t=>{const{onUpdateWidth:n,"onUpdate:width":r}=e;n&&l(n,t),r&&l(r,t),c.value=t}});const k=O(()=>{const{common:{cubicBezierEaseInOut:e,cubicBezierEaseIn:t,cubicBezierEaseOut:n},self:{color:r,textColor:o,boxShadow:i,lineHeight:a,headerPadding:s,footerPadding:l,borderRadius:c,bodyPadding:u,titleFontSize:h,titleTextColor:m,titleFontWeight:v,headerBorderBottom:b,footerBorderTop:f,closeIconColor:p,closeIconColorHover:g,closeIconColorPressed:w,closeColorHover:y,closeColorPressed:z,closeIconSize:$,closeSize:x,closeBorderRadius:S,resizableTriggerColorHover:k}}=d.value;return{"--n-line-height":a,"--n-color":r,"--n-border-radius":c,"--n-text-color":o,"--n-box-shadow":i,"--n-bezier":e,"--n-bezier-out":n,"--n-bezier-in":t,"--n-header-padding":s,"--n-body-padding":u,"--n-footer-padding":l,"--n-title-text-color":m,"--n-title-font-size":h,"--n-title-font-weight":v,"--n-header-border-bottom":b,"--n-footer-border-top":f,"--n-close-icon-color":p,"--n-close-icon-color-hover":g,"--n-close-icon-color-pressed":w,"--n-close-size":x,"--n-close-color-hover":y,"--n-close-color-pressed":z,"--n-close-icon-size":$,"--n-close-border-radius":S,"--n-resize-trigger-color-hover":k}}),E=i?b("drawer",void 0,k,e):void 0;return{mergedClsPrefix:t,namespace:n,mergedBodyStyle:z,handleOutsideClick:function(e){$(e)},handleMaskClick:$,handleEsc:function(t){var n;null===(n=e.onEsc)||void 0===n||n.call(e),e.show&&e.closeOnEsc&&p(t)&&(x.value||S(!1))},mergedTheme:d,cssVars:i?void 0:k,themeClass:null==E?void 0:E.themeClass,onRender:null==E?void 0:E.onRender,isMounted:s}},render(){const{mergedClsPrefix:e}=this;return B(n,{to:this.to,show:this.show},{default:()=>{var t;return null===(t=this.onRender)||void 0===t||t.call(this),N(B("div",{class:[`${e}-drawer-container`,this.namespace,this.themeClass],style:this.cssVars,role:"none"},this.showMask?B(W,{name:"fade-in-transition",appear:this.isMounted},{default:()=>this.show?B("div",{"aria-hidden":!0,class:[`${e}-drawer-mask`,"transparent"===this.showMask&&`${e}-drawer-mask--invisible`],onClick:this.handleMaskClick}):null}):null,B(I,Object.assign({},this.$attrs,{class:[this.drawerClass,this.$attrs.class],style:[this.mergedBodyStyle,this.$attrs.style],blockScroll:this.blockScroll,contentStyle:this.contentStyle,contentClass:this.contentClass,placement:this.placement,scrollbarProps:this.scrollbarProps,show:this.show,displayDirective:this.displayDirective,nativeScrollbar:this.nativeScrollbar,onAfterEnter:this.onAfterEnter,onAfterLeave:this.onAfterLeave,trapFocus:this.trapFocus,autoFocus:this.autoFocus,resizable:this.resizable,maxHeight:this.maxHeight,minHeight:this.minHeight,maxWidth:this.maxWidth,minWidth:this.minWidth,showMask:this.showMask,onEsc:this.handleEsc,onClickoutside:this.handleOutsideClick}),this.$slots)),[[s,{zIndex:this.zIndex,enabled:this.show}]])}})}});function ee(e=520,t=null){const n=D("undefined"!=typeof window?window.innerWidth:1200),r=()=>{n.value=window.innerWidth};R(()=>{window.addEventListener("resize",r)}),E(()=>{window.removeEventListener("resize",r)});const o=O(()=>n.value<640),i=O(()=>n.value>=640&&n.value<1024);return{drawerWidth:O(()=>{if(n.value<640)return"100%";if(n.value<768)return Math.min(.95*n.value,e);if(n.value<1024){const r=t||e;return Math.min(.85*n.value,r)}return e}),isMobile:o,isTablet:i,windowWidth:n}}export{K as n,ee as t};
|
package/dist/web/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" href="/favicon.ico">
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
7
|
<title>coding-tool-x · AI 编程工作台</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-BKlAWTH-.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/vue-vendor-BqZbbXHA.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/_plugin-vue_export-helper-BeLZJZij.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/vendors-D0c_0KLP.js">
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/assets/use-message-DqCwefG6.js">
|
|
17
17
|
<link rel="modulepreload" crossorigin href="/assets/use-lock-html-scroll-DXIqmUW4.js">
|
|
18
18
|
<link rel="modulepreload" crossorigin href="/assets/light-0eavxNvt.js">
|
|
19
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
19
|
+
<link rel="stylesheet" crossorigin href="/assets/index-3Lp6z8TQ.css">
|
|
20
20
|
</head>
|
|
21
21
|
<body>
|
|
22
22
|
<div id="app"></div>
|
package/package.json
CHANGED
package/src/commands/daemon.js
CHANGED
|
@@ -15,6 +15,17 @@ const { hasHostFlag } = require('../utils/cli-flags');
|
|
|
15
15
|
const { getPlatformRegistry, getPlatformRuntime } = require('../platforms/runtime');
|
|
16
16
|
const PM2_APP_NAME = 'cc-tool';
|
|
17
17
|
const STARTUP_LOG_FILE = 'cc-tool-out.log';
|
|
18
|
+
const PM2_RUNTIME_ENV_KEYS = [
|
|
19
|
+
'HOME',
|
|
20
|
+
'USERPROFILE',
|
|
21
|
+
'PATH',
|
|
22
|
+
'CODEX_HOME',
|
|
23
|
+
'OMP_COMMAND',
|
|
24
|
+
'OMP_CONFIG_DIR',
|
|
25
|
+
'OMP_PROFILE',
|
|
26
|
+
'PI_CODING_AGENT_DIR',
|
|
27
|
+
'OMP_CODING_AGENT_DIR'
|
|
28
|
+
];
|
|
18
29
|
const CURRENT_PM2_FORK_PATH = resolveCurrentPm2ForkPath();
|
|
19
30
|
|
|
20
31
|
function resolveCurrentPm2ForkPath() {
|
|
@@ -475,6 +486,21 @@ function buildStartOptions(port, enableHost, enableHttps) {
|
|
|
475
486
|
pmArgs.push('--https');
|
|
476
487
|
}
|
|
477
488
|
|
|
489
|
+
const env = {
|
|
490
|
+
NODE_ENV: 'production',
|
|
491
|
+
CC_TOOL_PORT: port
|
|
492
|
+
};
|
|
493
|
+
PM2_RUNTIME_ENV_KEYS.forEach((key) => {
|
|
494
|
+
if (key === 'CODEX_HOME'
|
|
495
|
+
|| key.startsWith('OMP_')
|
|
496
|
+
|| key.endsWith('_CODING_AGENT_DIR')) {
|
|
497
|
+
// Explicitly pass empty native path/profile overrides too, so PM2 cannot resurrect stale state.
|
|
498
|
+
env[key] = process.env[key] || '';
|
|
499
|
+
} else if (process.env[key]) {
|
|
500
|
+
env[key] = process.env[key];
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
|
|
478
504
|
return {
|
|
479
505
|
name: PM2_APP_NAME,
|
|
480
506
|
script: path.join(__dirname, '../index.js'),
|
|
@@ -484,10 +510,7 @@ function buildStartOptions(port, enableHost, enableHttps) {
|
|
|
484
510
|
autorestart: true,
|
|
485
511
|
kill_timeout: 5000,
|
|
486
512
|
max_memory_restart: '500M',
|
|
487
|
-
env
|
|
488
|
-
NODE_ENV: 'production',
|
|
489
|
-
CC_TOOL_PORT: port
|
|
490
|
-
},
|
|
513
|
+
env,
|
|
491
514
|
output: path.join(PATHS.logs, STARTUP_LOG_FILE),
|
|
492
515
|
error: path.join(PATHS.logs, STARTUP_LOG_FILE),
|
|
493
516
|
merge_logs: true,
|
|
@@ -58,10 +58,32 @@ function scanNative(adapter) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function scanOmp() {
|
|
61
|
-
const snapshot = getOmpAuthProviderSnapshot({ forceRefresh: true, accountCheck: true });
|
|
61
|
+
const snapshot = getOmpAuthProviderSnapshot({ forceRefresh: true, accountCheck: true }) || {};
|
|
62
62
|
const hasAccounts = (snapshot.providers || []).some(provider => (
|
|
63
63
|
provider.loggedIn === true && Array.isArray(provider.accounts) && provider.accounts.length > 0
|
|
64
64
|
));
|
|
65
|
+
if (!hasAccounts) {
|
|
66
|
+
const native = readAllNativeOAuth('omp') || [];
|
|
67
|
+
let synced = null;
|
|
68
|
+
if (native.length) {
|
|
69
|
+
try {
|
|
70
|
+
synced = oauthStore.syncLocalCredential('omp');
|
|
71
|
+
} catch {
|
|
72
|
+
synced = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const credentials = synced?.credentials || [];
|
|
76
|
+
const candidates = native.map((metadata, index) => nativeCandidate('omp', metadata, credentials[index]));
|
|
77
|
+
return {
|
|
78
|
+
candidates,
|
|
79
|
+
nativeState: {
|
|
80
|
+
available: snapshot.available === true || candidates.length > 0,
|
|
81
|
+
providers: snapshot.providers || [],
|
|
82
|
+
checkedAt: snapshot.checkedAt
|
|
83
|
+
},
|
|
84
|
+
warnings: candidates.length ? [] : [snapshot.reason || 'omp: unavailable: no logged-in local provider']
|
|
85
|
+
};
|
|
86
|
+
}
|
|
65
87
|
let synced = null;
|
|
66
88
|
if (hasAccounts) {
|
|
67
89
|
try {
|
|
@@ -81,13 +103,14 @@ function scanOmp() {
|
|
|
81
103
|
const credential = credentials.find(item => (
|
|
82
104
|
item.providerId === provider.id
|
|
83
105
|
&& (item.accountId === String(accountId || '') || item.accountEmail === String(accountEmail || ''))
|
|
84
|
-
))
|
|
106
|
+
)) || credentials
|
|
107
|
+
.filter(item => item.providerId === provider.id)[Number(accountId) - 1] || null;
|
|
85
108
|
const ref = safeRef({
|
|
86
109
|
credentialId: credential?.id,
|
|
87
110
|
providerId: provider.id,
|
|
88
|
-
accountId,
|
|
89
|
-
identityKey,
|
|
90
|
-
accountEmail
|
|
111
|
+
accountId: credential?.accountId || accountId,
|
|
112
|
+
identityKey: credential?.identityKey || identityKey,
|
|
113
|
+
accountEmail: credential?.accountEmail || accountEmail
|
|
91
114
|
});
|
|
92
115
|
if (!ref.accountId && !ref.identityKey && (provider.accounts || []).length > 1) continue;
|
|
93
116
|
candidates.push({
|
|
@@ -132,8 +155,15 @@ const adapters = Object.freeze({
|
|
|
132
155
|
},
|
|
133
156
|
omp: {
|
|
134
157
|
scan: scanOmp,
|
|
135
|
-
|
|
158
|
+
usage: (ref) => oauthStore.fetchCredentialUsage('omp', ref.credentialId),
|
|
159
|
+
quota: (ref) => oauthStore.fetchCredentialUsage('omp', ref.credentialId),
|
|
136
160
|
channelServicePath: './drivers/omp/channels-implementation'
|
|
161
|
+
},
|
|
162
|
+
opencode: {
|
|
163
|
+
scan: () => scanNative('opencode'),
|
|
164
|
+
usage: (ref) => oauthStore.fetchCredentialUsage('opencode', ref.credentialId),
|
|
165
|
+
quota: (ref) => oauthStore.fetchCredentialUsage('opencode', ref.credentialId),
|
|
166
|
+
channelServicePath: './drivers/opencode/channels-implementation'
|
|
137
167
|
}
|
|
138
168
|
});
|
|
139
169
|
|
|
@@ -37,11 +37,21 @@ function resolveChannelAuthRef(adapter, channel) {
|
|
|
37
37
|
const matched = candidates.find(candidate => matchChannel(channel, candidate));
|
|
38
38
|
if (matched) return safeRef(matched.authRef);
|
|
39
39
|
|
|
40
|
+
// A channel may retain an old account ID after the local OAuth store rotates
|
|
41
|
+
// credentials. When there is exactly one account for the same provider, it
|
|
42
|
+
// is safe to rebind the stale reference for quota lookup.
|
|
43
|
+
const soleCandidate = candidates.length === 1 ? candidates[0] : null;
|
|
44
|
+
const soleRef = safeRef(soleCandidate?.authRef);
|
|
45
|
+
const providerId = current.providerId || String(channel?.oauthProviderId || '').trim();
|
|
46
|
+
if (soleCandidate && providerId && soleRef.providerId === providerId) {
|
|
47
|
+
return soleRef;
|
|
48
|
+
}
|
|
49
|
+
|
|
40
50
|
// A channel created before OAuth credentials were synced can have no stable
|
|
41
51
|
// reference. Only auto-select when the local scan found exactly one account.
|
|
42
52
|
if (!current.credentialId && !current.providerId && !current.accountId
|
|
43
|
-
&& !current.identityKey && !current.accountEmail &&
|
|
44
|
-
return
|
|
53
|
+
&& !current.identityKey && !current.accountEmail && soleCandidate) {
|
|
54
|
+
return soleRef;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
57
|
return current;
|
|
@@ -1,9 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { ok, failed } = require('../../../shared/driver-result');
|
|
6
|
+
const { getOmpPaths } = require('./config');
|
|
7
|
+
|
|
8
|
+
const MANAGED_PROMPT_NAMESPACE = 'coding-tool-x';
|
|
9
|
+
const MANAGED_PROMPT_FILE = 'prompt.md';
|
|
10
|
+
|
|
11
|
+
function resolvePromptsDir(context = {}) {
|
|
12
|
+
const native = context.pathContext?.native || {};
|
|
13
|
+
return native.prompts
|
|
14
|
+
|| context.paths?.prompts
|
|
15
|
+
|| getOmpPaths(process.env, { resolveRuntime: false }).prompts;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function stripFrontmatter(content) {
|
|
19
|
+
return String(content || '').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n(?:\r?\n)?/, '');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function buildTemplateContent(content) {
|
|
23
|
+
return `---\ndescription: "coding-tool-x prompt"\n---\n\n${content}`;
|
|
24
|
+
}
|
|
4
25
|
|
|
5
26
|
function createDriver(context = {}) {
|
|
6
|
-
|
|
27
|
+
const promptsDir = resolvePromptsDir(context);
|
|
28
|
+
const managedDir = path.join(promptsDir, MANAGED_PROMPT_NAMESPACE);
|
|
29
|
+
const promptPath = path.join(managedDir, MANAGED_PROMPT_FILE);
|
|
30
|
+
|
|
31
|
+
const invoke = (operation, args) => {
|
|
32
|
+
try {
|
|
33
|
+
if (operation === 'read') {
|
|
34
|
+
return ok('omp', 'prompts', operation,
|
|
35
|
+
fs.existsSync(promptPath) ? stripFrontmatter(fs.readFileSync(promptPath, 'utf8')) : '');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (operation === 'write') {
|
|
39
|
+
const [content] = args;
|
|
40
|
+
if (typeof content !== 'string') throw new Error('提示词内容必须是字符串');
|
|
41
|
+
fs.mkdirSync(managedDir, { recursive: true });
|
|
42
|
+
fs.writeFileSync(promptPath, buildTemplateContent(content), 'utf8');
|
|
43
|
+
return ok('omp', 'prompts', operation, content);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (fs.existsSync(managedDir)) {
|
|
47
|
+
fs.rmSync(managedDir, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
return ok('omp', 'prompts', operation, true);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return failed('omp', 'prompts', operation, error);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
platform: 'omp',
|
|
57
|
+
capability: 'prompts',
|
|
58
|
+
path: managedDir,
|
|
59
|
+
read: (...args) => invoke('read', args),
|
|
60
|
+
write: (...args) => invoke('write', args),
|
|
61
|
+
remove: (...args) => invoke('remove', args)
|
|
62
|
+
};
|
|
7
63
|
}
|
|
8
64
|
|
|
9
65
|
module.exports = { createDriver };
|
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
const { createOmpGateway } = require('./gateway');
|
|
16
16
|
const { prepareManagedOmpChannels } = require('./gateway-routing');
|
|
17
17
|
const { probeOmpAuthGateways } = require('./auth-gateway-client');
|
|
18
|
+
const { restoreStoredOmpOAuthCredentials } = require('../../oauth-credentials-service');
|
|
18
19
|
|
|
19
20
|
let currentPort = null;
|
|
20
21
|
let lastSyncResult = null;
|
|
@@ -33,11 +34,24 @@ function withLifecycleLock(operation) {
|
|
|
33
34
|
|
|
34
35
|
async function startOmpProxyServerUnlocked(options = {}) {
|
|
35
36
|
if (gateway.status().listening) {
|
|
37
|
+
const oauthRestore = restoreStoredOmpOAuthCredentials(getEnabledChannels());
|
|
38
|
+
if (oauthRestore.warnings.length > 0) {
|
|
39
|
+
lastSyncResult = {
|
|
40
|
+
...(lastSyncResult || {}),
|
|
41
|
+
warnings: [
|
|
42
|
+
...(lastSyncResult?.warnings || []),
|
|
43
|
+
...oauthRestore.warnings
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
}
|
|
36
47
|
return {
|
|
37
48
|
success: true,
|
|
38
49
|
port: gateway.status().port,
|
|
39
50
|
sync: lastSyncResult,
|
|
40
|
-
warnings:
|
|
51
|
+
warnings: [
|
|
52
|
+
...(lastSyncResult?.warnings || []),
|
|
53
|
+
...(oauthRestore.warnings || [])
|
|
54
|
+
]
|
|
41
55
|
};
|
|
42
56
|
}
|
|
43
57
|
const preserveStartTime = options.preserveStartTime || false;
|
|
@@ -56,6 +70,7 @@ async function startOmpProxyServerUnlocked(options = {}) {
|
|
|
56
70
|
});
|
|
57
71
|
currentPort = gatewayStatus.port;
|
|
58
72
|
try {
|
|
73
|
+
const oauthRestore = restoreStoredOmpOAuthCredentials(channels);
|
|
59
74
|
const oauthSupport = await probeOmpAuthGateways(channels);
|
|
60
75
|
const descriptor = {
|
|
61
76
|
...gateway.descriptor(),
|
|
@@ -71,10 +86,19 @@ async function startOmpProxyServerUnlocked(options = {}) {
|
|
|
71
86
|
lastSyncResult = {
|
|
72
87
|
...lastSyncResult,
|
|
73
88
|
warnings: [
|
|
89
|
+
...(oauthRestore.warnings || []),
|
|
74
90
|
...(lastSyncResult?.warnings || []),
|
|
75
91
|
...oauthSupport.warnings
|
|
76
92
|
]
|
|
77
93
|
};
|
|
94
|
+
} else if (oauthRestore.warnings.length > 0) {
|
|
95
|
+
lastSyncResult = {
|
|
96
|
+
...lastSyncResult,
|
|
97
|
+
warnings: [
|
|
98
|
+
...(oauthRestore.warnings || []),
|
|
99
|
+
...(lastSyncResult?.warnings || [])
|
|
100
|
+
]
|
|
101
|
+
};
|
|
78
102
|
}
|
|
79
103
|
} catch (error) {
|
|
80
104
|
if (wasEnabled) {
|
|
@@ -68,6 +68,10 @@ function normalizeChannelName(value) {
|
|
|
68
68
|
.replace(/\s+/g, ' ');
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
function normalizeAuthMode(value) {
|
|
72
|
+
return ['api_key', 'oauth', 'none'].includes(value) ? value : 'api_key';
|
|
73
|
+
}
|
|
74
|
+
|
|
71
75
|
// 获取渠道存储文件路径
|
|
72
76
|
function getChannelsFilePath() {
|
|
73
77
|
const channelsDir = path.dirname(configuredState.channels);
|
|
@@ -98,24 +102,7 @@ function loadChannels() {
|
|
|
98
102
|
const data = JSON.parse(content);
|
|
99
103
|
// 确保渠道有必要字段(兼容旧数据)
|
|
100
104
|
if (data.channels) {
|
|
101
|
-
data.channels = data.channels.map(ch =>
|
|
102
|
-
const normalized = {
|
|
103
|
-
...ch,
|
|
104
|
-
enabled: ch.enabled !== false,
|
|
105
|
-
weight: ch.weight || 1,
|
|
106
|
-
maxConcurrency: ch.maxConcurrency || null,
|
|
107
|
-
balanceToken: ch.balanceToken || '',
|
|
108
|
-
balanceUserId: ch.balanceUserId || null,
|
|
109
|
-
modelRedirects: ch.modelRedirects || [],
|
|
110
|
-
speedTestModel: ch.speedTestModel || null,
|
|
111
|
-
wireApi: ch.wireApi || 'openai', // OpenCode 默认使用 OpenAI 兼容格式
|
|
112
|
-
gatewaySourceType: normalizeGatewaySourceType(ch.gatewaySourceType, 'codex'),
|
|
113
|
-
allowedModels: ch.allowedModels || []
|
|
114
|
-
};
|
|
115
|
-
normalized.providerKey = ch.providerKey || deriveProviderKey(normalized);
|
|
116
|
-
normalized.websiteUrl = resolveChannelWebsiteUrl('opencode', normalized);
|
|
117
|
-
return normalized;
|
|
118
|
-
});
|
|
105
|
+
data.channels = data.channels.map(ch => normalizeOpenCodeChannel(ch));
|
|
119
106
|
}
|
|
120
107
|
return data;
|
|
121
108
|
} catch (err) {
|
|
@@ -191,12 +178,18 @@ function getChannels() {
|
|
|
191
178
|
function createChannel(name, baseUrl, apiKey, extraConfig = {}) {
|
|
192
179
|
const data = loadChannels();
|
|
193
180
|
const isProxyRunning = getOpenCodeProxyRunning();
|
|
181
|
+
const authMode = normalizeAuthMode(extraConfig.authMode);
|
|
194
182
|
|
|
195
183
|
const newChannel = {
|
|
196
184
|
id: crypto.randomUUID(),
|
|
197
185
|
name,
|
|
198
|
-
baseUrl,
|
|
199
|
-
apiKey,
|
|
186
|
+
baseUrl: authMode === 'oauth' || authMode === 'none' ? '' : baseUrl,
|
|
187
|
+
apiKey: authMode === 'oauth' || authMode === 'none' ? '' : apiKey,
|
|
188
|
+
authMode,
|
|
189
|
+
authRef: authMode === 'oauth' ? (extraConfig.authRef || {}) : undefined,
|
|
190
|
+
authSource: authMode === 'oauth' ? (extraConfig.authSource || 'synced-local') : undefined,
|
|
191
|
+
authStatus: authMode === 'oauth' ? (extraConfig.authStatus || 'available') : undefined,
|
|
192
|
+
oauthProviderId: authMode === 'oauth' ? (extraConfig.oauthProviderId || extraConfig.providerKey || '') : '',
|
|
200
193
|
wireApi: extraConfig.wireApi || 'openai',
|
|
201
194
|
enabled: extraConfig.enabled !== false,
|
|
202
195
|
weight: extraConfig.weight || 1,
|
|
@@ -248,7 +241,7 @@ function updateChannel(channelId, updates) {
|
|
|
248
241
|
|
|
249
242
|
const oldChannel = data.channels[index];
|
|
250
243
|
|
|
251
|
-
const merged = {
|
|
244
|
+
const merged = normalizeOpenCodeChannel({
|
|
252
245
|
...oldChannel,
|
|
253
246
|
...updates,
|
|
254
247
|
id: channelId,
|
|
@@ -264,7 +257,7 @@ function updateChannel(channelId, updates) {
|
|
|
264
257
|
'codex'
|
|
265
258
|
),
|
|
266
259
|
updatedAt: Date.now()
|
|
267
|
-
};
|
|
260
|
+
});
|
|
268
261
|
merged.providerKey = updates.providerKey || oldChannel.providerKey || deriveProviderKey(merged);
|
|
269
262
|
merged.websiteUrl = resolveChannelWebsiteUrl('opencode', merged);
|
|
270
263
|
data.channels[index] = merged;
|
|
@@ -524,6 +517,7 @@ function findOpenCodeExistingByProvider(channels = [], providerId = '', baseUrl
|
|
|
524
517
|
}
|
|
525
518
|
|
|
526
519
|
function normalizeOpenCodeChannel(channel = {}) {
|
|
520
|
+
const authMode = normalizeAuthMode(channel.authMode);
|
|
527
521
|
const normalized = {
|
|
528
522
|
...channel,
|
|
529
523
|
enabled: channel.enabled !== false,
|
|
@@ -537,6 +531,15 @@ function normalizeOpenCodeChannel(channel = {}) {
|
|
|
537
531
|
gatewaySourceType: normalizeGatewaySourceType(channel.gatewaySourceType, 'codex'),
|
|
538
532
|
allowedModels: Array.isArray(channel.allowedModels) ? channel.allowedModels : []
|
|
539
533
|
};
|
|
534
|
+
normalized.authMode = authMode;
|
|
535
|
+
normalized.authRef = authMode === 'oauth' ? (channel.authRef || {}) : undefined;
|
|
536
|
+
normalized.authSource = authMode === 'oauth' ? (channel.authSource || 'synced-local') : undefined;
|
|
537
|
+
normalized.authStatus = authMode === 'oauth' ? (channel.authStatus || 'available') : undefined;
|
|
538
|
+
normalized.oauthProviderId = authMode === 'oauth' ? (channel.oauthProviderId || channel.providerKey || '') : '';
|
|
539
|
+
if (authMode === 'oauth' || authMode === 'none') {
|
|
540
|
+
normalized.baseUrl = '';
|
|
541
|
+
normalized.apiKey = '';
|
|
542
|
+
}
|
|
540
543
|
normalized.providerKey = normalized.providerKey || deriveProviderKey(normalized);
|
|
541
544
|
normalized.websiteUrl = resolveChannelWebsiteUrl('opencode', normalized);
|
|
542
545
|
return normalized;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const { createChannelDriver } = require('../../../shared/channel-driver');
|
|
4
4
|
|
|
5
5
|
function createDriver(context = {}) {
|
|
6
|
-
|
|
6
|
+
const driver = createChannelDriver({
|
|
7
7
|
...context,
|
|
8
8
|
platform: 'opencode',
|
|
9
9
|
servicePath: './opencode/channels-implementation',
|
|
@@ -35,6 +35,11 @@ function createDriver(context = {}) {
|
|
|
35
35
|
},
|
|
36
36
|
dashboardChannelShape: 'array'
|
|
37
37
|
});
|
|
38
|
+
const auth = require('../../channel-auth-service');
|
|
39
|
+
driver.getAuth = context => auth.getChannelAuth('opencode', { channelId: context?.params?.channelId || context?.query?.channelId || '' });
|
|
40
|
+
driver.syncLocalAuth = context => auth.syncLocalChannelAuth('opencode', { channelId: context?.body?.channelId || context?.params?.channelId || context?.query?.channelId || '' });
|
|
41
|
+
driver.getAuthQuota = context => auth.fetchChannelAuthQuota('opencode', context?.params?.channelId, { refresh: context?.query?.refresh === 'true' });
|
|
42
|
+
return driver;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
module.exports = { createDriver };
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"defaultEnabled": true,
|
|
10
10
|
"sortOrder": 30,
|
|
11
11
|
"modelConfig": { "catalogKey": "codex" },
|
|
12
|
+
"auth": {
|
|
13
|
+
"modes": ["api_key", "oauth", "none"],
|
|
14
|
+
"oauth": { "adapter": "opencode", "policy": "single-enabled", "quota": "codex" }
|
|
15
|
+
},
|
|
12
16
|
"helpLabel": "OpenCode",
|
|
13
17
|
"terminalColor": "yellow",
|
|
14
18
|
"cliSelectable": true,
|
|
@@ -257,6 +261,30 @@
|
|
|
257
261
|
"request": "default",
|
|
258
262
|
"response": "default"
|
|
259
263
|
},
|
|
264
|
+
{
|
|
265
|
+
"method": "GET",
|
|
266
|
+
"path": "/channels/auth",
|
|
267
|
+
"capability": "channels",
|
|
268
|
+
"operation": "getAuth",
|
|
269
|
+
"request": "default",
|
|
270
|
+
"response": "default"
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"method": "POST",
|
|
274
|
+
"path": "/channels/auth/sync-local",
|
|
275
|
+
"capability": "channels",
|
|
276
|
+
"operation": "syncLocalAuth",
|
|
277
|
+
"request": "default",
|
|
278
|
+
"response": "default"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
"method": "GET",
|
|
282
|
+
"path": "/channels/:channelId/auth/quota",
|
|
283
|
+
"capability": "channels",
|
|
284
|
+
"operation": "getAuthQuota",
|
|
285
|
+
"request": "default",
|
|
286
|
+
"response": "default"
|
|
287
|
+
},
|
|
260
288
|
{
|
|
261
289
|
"method": "POST",
|
|
262
290
|
"path": "/channels/sync-current",
|