@aventurevc/aventure-cli 0.8.5 → 0.8.7
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/dist/aventure-cli/command-catalog.compact.txt +1 -0
- package/dist/aventure-cli/index.js +1 -1
- package/dist/aventure-cli/unified-operations.json +22 -2
- package/dist/chunks/auth-BkmEH7-r.js +114 -0
- package/dist/chunks/{aventure-cli-B_uADrfi.js → aventure-cli-B-3cBc5U.js} +26 -26
- package/dist/chunks/{index.node-BkDh_eWA.js → index.node-Cae5ADms.js} +1 -1
- package/dist/chunks/oauth-bearer-credential-CMb1HSSN.js +4 -0
- package/dist/chunks/oauth-login-D-tNp610.js +1 -0
- package/dist/chunks/{oauth-login-B_FiHfOz.js → oauth-login-DZHht6I9.js} +5 -5
- package/dist/chunks/openapi-commands-Ddy43sf8.js +1 -0
- package/dist/chunks/text-field-CtBuc7ot.js +1 -0
- package/dist/chunks/{text-response-66NOFpNK.js → text-response-CLqndug9.js} +1 -1
- package/package.json +3 -3
- package/dist/chunks/auth-BOk_4sIm.js +0 -114
- package/dist/chunks/oauth-bearer-credential-DvAios2Z.js +0 -4
- package/dist/chunks/oauth-login-4Tt49dbx.js +0 -1
- package/dist/chunks/openapi-commands-C--b11zL.js +0 -1
- package/dist/chunks/text-field-D9QRpX61.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./auth-BOk_4sIm.js";import{C as t,T as n,_ as r,a as i,b as ee,c as a,d as te,g as o,h as s,k as ne,l as c,o as re,p as ie,u as ae,v as l,w as u,x as d,y as f}from"./person-owner-BqBLyw4S.js";var oe=l({clerkPublishableKey:t().nullish(),oauthClient:e.nullish()}),se=`2025-11-25`,ce=`2025-03-26`,le=[se,`2025-06-18`,`2025-03-26`,`2024-11-05`,`2024-10-07`],ue=`io.modelcontextprotocol/related-task`,p=ae(e=>e!==null&&(typeof e==`object`||typeof e==`function`)),de=u([t(),r().int()]),fe=t();o({ttl:r().optional(),pollInterval:r().optional()});var pe=l({ttl:r().optional()}),me=l({taskId:t()}),m=o({progressToken:de.optional(),[ue]:me.optional()}),h=l({_meta:m.optional()}),g=h.extend({task:pe.optional()}),he=e=>g.safeParse(e).success,_=l({method:t(),params:h.loose().optional()}),v=l({_meta:m.optional()}),y=l({method:t(),params:v.loose().optional()}),b=o({_meta:m.optional()}),x=u([t(),r().int()]),ge=l({jsonrpc:s(`2.0`),id:x,..._.shape}).strict(),_e=e=>ge.safeParse(e).success,ve=l({jsonrpc:s(`2.0`),...y.shape}).strict(),ye=e=>ve.safeParse(e).success,S=l({jsonrpc:s(`2.0`),id:x,result:b}).strict(),be=e=>S.safeParse(e).success,C;(function(e){e[e.ConnectionClosed=-32e3]=`ConnectionClosed`,e[e.RequestTimeout=-32001]=`RequestTimeout`,e[e.ParseError=-32700]=`ParseError`,e[e.InvalidRequest=-32600]=`InvalidRequest`,e[e.MethodNotFound=-32601]=`MethodNotFound`,e[e.InvalidParams=-32602]=`InvalidParams`,e[e.InternalError=-32603]=`InternalError`,e[e.UrlElicitationRequired=-32042]=`UrlElicitationRequired`})(C||={});var w=l({jsonrpc:s(`2.0`),id:x.optional(),error:l({code:r().int(),message:t(),data:n().optional()})}).strict(),xe=e=>w.safeParse(e).success,Se=u([ge,ve,S,w]);u([S,w]);var T=b.strict(),Ce=v.extend({requestId:x.optional(),reason:t().optional()}),E=y.extend({method:s(`notifications/cancelled`),params:Ce}),we=l({src:t(),mimeType:t().optional(),sizes:a(t()).optional(),theme:i([`light`,`dark`]).optional()}),D=l({icons:a(we).optional()}),O=l({name:t(),title:t().optional()}),Te=O.extend({...O.shape,...D.shape,version:t(),websiteUrl:t().optional(),description:t().optional()}),Ee=ie(l({applyDefaults:c().optional()}),d(t(),n())),De=ee(e=>e&&typeof e==`object`&&!Array.isArray(e)&&Object.keys(e).length===0?{form:{}}:e,ie(l({form:Ee.optional(),url:p.optional()}),d(t(),n()).optional())),Oe=o({list:p.optional(),cancel:p.optional(),requests:o({sampling:o({createMessage:p.optional()}).optional(),elicitation:o({create:p.optional()}).optional()}).optional()}),ke=o({list:p.optional(),cancel:p.optional(),requests:o({tools:o({call:p.optional()}).optional()}).optional()}),Ae=l({experimental:d(t(),p).optional(),sampling:l({context:p.optional(),tools:p.optional()}).optional(),elicitation:De.optional(),roots:l({listChanged:c().optional()}).optional(),tasks:Oe.optional(),extensions:d(t(),p).optional()}),je=h.extend({protocolVersion:t(),capabilities:Ae,clientInfo:Te}),k=_.extend({method:s(`initialize`),params:je}),Me=e=>k.safeParse(e).success,Ne=l({experimental:d(t(),p).optional(),logging:p.optional(),completions:p.optional(),prompts:l({listChanged:c().optional()}).optional(),resources:l({subscribe:c().optional(),listChanged:c().optional()}).optional(),tools:l({listChanged:c().optional()}).optional(),tasks:ke.optional(),extensions:d(t(),p).optional()}),Pe=b.extend({protocolVersion:t(),capabilities:Ne,serverInfo:Te,instructions:t().optional()}),Fe=y.extend({method:s(`notifications/initialized`),params:v.optional()}),A=_.extend({method:s(`ping`),params:h.optional()}),Ie=l({progress:r(),total:f(r()),message:f(t())}),Le=l({...v.shape,...Ie.shape,progressToken:de}),j=y.extend({method:s(`notifications/progress`),params:Le}),Re=h.extend({cursor:fe.optional()}),M=_.extend({params:Re.optional()}),N=b.extend({nextCursor:fe.optional()}),ze=i([`working`,`input_required`,`completed`,`failed`,`cancelled`]),P=l({taskId:t(),status:ze,ttl:u([r(),re()]),createdAt:t(),lastUpdatedAt:t(),pollInterval:f(r()),statusMessage:f(t())}),F=b.extend({task:P}),Be=v.merge(P),I=y.extend({method:s(`notifications/tasks/status`),params:Be}),L=_.extend({method:s(`tasks/get`),params:h.extend({taskId:t()})}),R=b.merge(P),z=_.extend({method:s(`tasks/result`),params:h.extend({taskId:t()})});b.loose();var B=M.extend({method:s(`tasks/list`)}),V=N.extend({tasks:a(P)}),H=_.extend({method:s(`tasks/cancel`),params:h.extend({taskId:t()})}),Ve=b.merge(P),He=l({uri:t(),mimeType:f(t()),_meta:d(t(),n()).optional()}),Ue=He.extend({text:t()}),U=t().refine(e=>{try{return atob(e),!0}catch{return!1}},{message:`Invalid Base64 string`}),We=He.extend({blob:U}),W=i([`user`,`assistant`]),G=l({audience:a(W).optional(),priority:r().min(0).max(1).optional(),lastModified:ne({offset:!0}).optional()}),Ge=l({...O.shape,...D.shape,uri:t(),description:f(t()),mimeType:f(t()),size:f(r()),annotations:G.optional(),_meta:f(o({}))}),Ke=l({...O.shape,...D.shape,uriTemplate:t(),description:f(t()),mimeType:f(t()),annotations:G.optional(),_meta:f(o({}))}),qe=M.extend({method:s(`resources/list`)}),Je=N.extend({resources:a(Ge)}),Ye=M.extend({method:s(`resources/templates/list`)}),Xe=N.extend({resourceTemplates:a(Ke)}),K=h.extend({uri:t()}),Ze=K,Qe=_.extend({method:s(`resources/read`),params:Ze}),$e=b.extend({contents:a(u([Ue,We]))}),et=y.extend({method:s(`notifications/resources/list_changed`),params:v.optional()}),tt=K,nt=_.extend({method:s(`resources/subscribe`),params:tt}),rt=K,it=_.extend({method:s(`resources/unsubscribe`),params:rt}),at=v.extend({uri:t()}),ot=y.extend({method:s(`notifications/resources/updated`),params:at}),st=l({name:t(),description:f(t()),required:f(c())}),ct=l({...O.shape,...D.shape,description:f(t()),arguments:f(a(st)),_meta:f(o({}))}),lt=M.extend({method:s(`prompts/list`)}),ut=N.extend({prompts:a(ct)}),dt=h.extend({name:t(),arguments:d(t(),t()).optional()}),ft=_.extend({method:s(`prompts/get`),params:dt}),q=l({type:s(`text`),text:t(),annotations:G.optional(),_meta:d(t(),n()).optional()}),J=l({type:s(`image`),data:U,mimeType:t(),annotations:G.optional(),_meta:d(t(),n()).optional()}),Y=l({type:s(`audio`),data:U,mimeType:t(),annotations:G.optional(),_meta:d(t(),n()).optional()}),pt=l({type:s(`tool_use`),name:t(),id:t(),input:d(t(),n()),_meta:d(t(),n()).optional()}),mt=l({type:s(`resource`),resource:u([Ue,We]),annotations:G.optional(),_meta:d(t(),n()).optional()}),ht=Ge.extend({type:s(`resource_link`)}),X=u([q,J,Y,ht,mt]),gt=l({role:W,content:X}),_t=b.extend({description:t().optional(),messages:a(gt)}),vt=y.extend({method:s(`notifications/prompts/list_changed`),params:v.optional()}),yt=l({title:t().optional(),readOnlyHint:c().optional(),destructiveHint:c().optional(),idempotentHint:c().optional(),openWorldHint:c().optional()}),bt=l({taskSupport:i([`required`,`optional`,`forbidden`]).optional()}),xt=l({...O.shape,...D.shape,description:t().optional(),inputSchema:l({type:s(`object`),properties:d(t(),p).optional(),required:a(t()).optional()}).catchall(n()),outputSchema:l({type:s(`object`),properties:d(t(),p).optional(),required:a(t()).optional()}).catchall(n()).optional(),annotations:yt.optional(),execution:bt.optional(),_meta:d(t(),n()).optional()}),St=M.extend({method:s(`tools/list`)}),Ct=N.extend({tools:a(xt)}),Z=b.extend({content:a(X).default([]),structuredContent:d(t(),n()).optional(),isError:c().optional()});Z.or(b.extend({toolResult:n()}));var wt=g.extend({name:t(),arguments:d(t(),n()).optional()}),Tt=_.extend({method:s(`tools/call`),params:wt}),Et=y.extend({method:s(`notifications/tools/list_changed`),params:v.optional()});l({autoRefresh:c().default(!0),debounceMs:r().int().nonnegative().default(300)});var Q=i([`debug`,`info`,`notice`,`warning`,`error`,`critical`,`alert`,`emergency`]),Dt=h.extend({level:Q}),Ot=_.extend({method:s(`logging/setLevel`),params:Dt}),kt=v.extend({level:Q,logger:t().optional(),data:n()}),At=y.extend({method:s(`notifications/message`),params:kt}),jt=l({name:t().optional()}),Mt=l({hints:a(jt).optional(),costPriority:r().min(0).max(1).optional(),speedPriority:r().min(0).max(1).optional(),intelligencePriority:r().min(0).max(1).optional()}),Nt=l({mode:i([`auto`,`required`,`none`]).optional()}),Pt=l({type:s(`tool_result`),toolUseId:t().describe(`The unique identifier for the corresponding tool call.`),content:a(X).default([]),structuredContent:l({}).loose().optional(),isError:c().optional(),_meta:d(t(),n()).optional()}),Ft=te(`type`,[q,J,Y]),$=te(`type`,[q,J,Y,pt,Pt]),It=l({role:W,content:u([$,a($)]),_meta:d(t(),n()).optional()}),Lt=g.extend({messages:a(It),modelPreferences:Mt.optional(),systemPrompt:t().optional(),includeContext:i([`none`,`thisServer`,`allServers`]).optional(),temperature:r().optional(),maxTokens:r().int(),stopSequences:a(t()).optional(),metadata:p.optional(),tools:a(xt).optional(),toolChoice:Nt.optional()}),Rt=_.extend({method:s(`sampling/createMessage`),params:Lt}),zt=b.extend({model:t(),stopReason:f(i([`endTurn`,`stopSequence`,`maxTokens`]).or(t())),role:W,content:Ft}),Bt=b.extend({model:t(),stopReason:f(i([`endTurn`,`stopSequence`,`maxTokens`,`toolUse`]).or(t())),role:W,content:u([$,a($)])}),Vt=l({type:s(`boolean`),title:t().optional(),description:t().optional(),default:c().optional()}),Ht=l({type:s(`string`),title:t().optional(),description:t().optional(),minLength:r().optional(),maxLength:r().optional(),format:i([`email`,`uri`,`date`,`date-time`]).optional(),default:t().optional()}),Ut=l({type:i([`number`,`integer`]),title:t().optional(),description:t().optional(),minimum:r().optional(),maximum:r().optional(),default:r().optional()}),Wt=l({type:s(`string`),title:t().optional(),description:t().optional(),enum:a(t()),default:t().optional()}),Gt=l({type:s(`string`),title:t().optional(),description:t().optional(),oneOf:a(l({const:t(),title:t()})),default:t().optional()}),Kt=l({type:s(`string`),title:t().optional(),description:t().optional(),enum:a(t()),enumNames:a(t()).optional(),default:t().optional()}),qt=u([Wt,Gt]),Jt=l({type:s(`array`),title:t().optional(),description:t().optional(),minItems:r().optional(),maxItems:r().optional(),items:l({type:s(`string`),enum:a(t())}),default:a(t()).optional()}),Yt=l({type:s(`array`),title:t().optional(),description:t().optional(),minItems:r().optional(),maxItems:r().optional(),items:l({anyOf:a(l({const:t(),title:t()}))}),default:a(t()).optional()}),Xt=u([Jt,Yt]),Zt=u([Kt,qt,Xt]),Qt=u([Zt,Vt,Ht,Ut]),$t=g.extend({mode:s(`form`).optional(),message:t(),requestedSchema:l({type:s(`object`),properties:d(t(),Qt),required:a(t()).optional()})}),en=g.extend({mode:s(`url`),message:t(),elicitationId:t(),url:t().url()}),tn=u([$t,en]),nn=_.extend({method:s(`elicitation/create`),params:tn}),rn=v.extend({elicitationId:t()}),an=y.extend({method:s(`notifications/elicitation/complete`),params:rn}),on=b.extend({action:i([`accept`,`decline`,`cancel`]),content:ee(e=>e===null?void 0:e,d(t(),u([t(),r(),c(),a(t())])).optional())}),sn=l({type:s(`ref/resource`),uri:t()}),cn=l({type:s(`ref/prompt`),name:t()}),ln=h.extend({ref:u([cn,sn]),argument:l({name:t(),value:t()}),context:l({arguments:d(t(),t()).optional()}).optional()}),un=_.extend({method:s(`completion/complete`),params:ln});function dn(e){if(e.params.ref.type!==`ref/prompt`)throw TypeError(`Expected CompleteRequestPrompt, but got ${e.params.ref.type}`)}function fn(e){if(e.params.ref.type!==`ref/resource`)throw TypeError(`Expected CompleteRequestResourceTemplate, but got ${e.params.ref.type}`)}var pn=b.extend({completion:o({values:a(t()).max(100),total:f(r().int()),hasMore:f(c())})}),mn=l({uri:t().startsWith(`file://`),name:t().optional(),_meta:d(t(),n()).optional()}),hn=_.extend({method:s(`roots/list`),params:h.optional()}),gn=b.extend({roots:a(mn)}),_n=y.extend({method:s(`notifications/roots/list_changed`),params:v.optional()});u([A,k,un,Ot,ft,lt,qe,Ye,Qe,nt,it,Tt,St,L,z,B,H]),u([E,j,Fe,_n,I]),u([T,zt,Bt,on,gn,R,V,F]),u([A,Rt,nn,hn,L,z,B,H]),u([E,j,At,ot,et,Et,vt,I,an]),u([T,Pe,pn,_t,ut,Je,Xe,$e,Z,Ct,R,V,F]);var vn=class e extends Error{constructor(e,t,n){super(`MCP error ${e}: ${t}`),this.code=e,this.data=n,this.name=`McpError`}static fromError(t,n,r){if(t===C.UrlElicitationRequired&&r){let e=r;if(e.elicitations)return new yn(e.elicitations,n)}return new e(t,n,r)}},yn=class extends vn{constructor(e,t=`URL elicitation${e.length>1?`s`:``} required`){super(C.UrlElicitationRequired,t,{elicitations:e})}get elicitations(){return this.data?.elicitations??[]}},bn=globalThis.crypto?.webcrypto??globalThis.crypto??import(`node:crypto`).then(e=>e.webcrypto);async function xn(e){return(await bn).getRandomValues(new Uint8Array(e))}async function Sn(e){let t=``;for(;t.length<e;){let n=await xn(e-t.length);for(let e of n)e<198&&(t+=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~`[e%66])}return t}async function Cn(e){return await Sn(e)}async function wn(e){let t=await(await bn).subtle.digest(`SHA-256`,new TextEncoder().encode(e));return btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\//g,`_`).replace(/\+/g,`-`).replace(/=/g,``)}async function Tn(e){if(e||=43,e<43||e>128)throw`Expected a length between 43 and 128. Received ${e}.`;let t=await Cn(e);return{code_verifier:t,code_challenge:await wn(t)}}export{Q as A,fn as B,lt as C,B as D,gn as E,Qe as F,be as G,xe as H,le as I,he as K,Ot as L,A as M,j as N,V as O,ue as P,I as R,se as S,qe as T,ye as U,Me as V,_e as W,L as _,Ve as a,Fe as b,zt as c,ce as d,on as f,z as g,ft as h,H as i,vn as j,St as k,Bt as l,C as m,Tt as n,E as o,T as p,oe as q,Z as r,un as s,Tn as t,F as u,R as v,Ye as w,Se as x,k as y,dn as z};
|
|
1
|
+
import{a as e}from"./auth-BkmEH7-r.js";import{C as t,T as n,_ as r,a as i,b as ee,c as a,d as te,g as o,h as s,k as ne,l as c,o as re,p as ie,u as ae,v as l,w as u,x as d,y as f}from"./person-owner-BqBLyw4S.js";var oe=l({clerkPublishableKey:t().nullish(),oauthClient:e.nullish()}),se=`2025-11-25`,ce=`2025-03-26`,le=[se,`2025-06-18`,`2025-03-26`,`2024-11-05`,`2024-10-07`],ue=`io.modelcontextprotocol/related-task`,p=ae(e=>e!==null&&(typeof e==`object`||typeof e==`function`)),de=u([t(),r().int()]),fe=t();o({ttl:r().optional(),pollInterval:r().optional()});var pe=l({ttl:r().optional()}),me=l({taskId:t()}),m=o({progressToken:de.optional(),[ue]:me.optional()}),h=l({_meta:m.optional()}),g=h.extend({task:pe.optional()}),he=e=>g.safeParse(e).success,_=l({method:t(),params:h.loose().optional()}),v=l({_meta:m.optional()}),y=l({method:t(),params:v.loose().optional()}),b=o({_meta:m.optional()}),x=u([t(),r().int()]),ge=l({jsonrpc:s(`2.0`),id:x,..._.shape}).strict(),_e=e=>ge.safeParse(e).success,ve=l({jsonrpc:s(`2.0`),...y.shape}).strict(),ye=e=>ve.safeParse(e).success,S=l({jsonrpc:s(`2.0`),id:x,result:b}).strict(),be=e=>S.safeParse(e).success,C;(function(e){e[e.ConnectionClosed=-32e3]=`ConnectionClosed`,e[e.RequestTimeout=-32001]=`RequestTimeout`,e[e.ParseError=-32700]=`ParseError`,e[e.InvalidRequest=-32600]=`InvalidRequest`,e[e.MethodNotFound=-32601]=`MethodNotFound`,e[e.InvalidParams=-32602]=`InvalidParams`,e[e.InternalError=-32603]=`InternalError`,e[e.UrlElicitationRequired=-32042]=`UrlElicitationRequired`})(C||={});var w=l({jsonrpc:s(`2.0`),id:x.optional(),error:l({code:r().int(),message:t(),data:n().optional()})}).strict(),xe=e=>w.safeParse(e).success,Se=u([ge,ve,S,w]);u([S,w]);var T=b.strict(),Ce=v.extend({requestId:x.optional(),reason:t().optional()}),E=y.extend({method:s(`notifications/cancelled`),params:Ce}),we=l({src:t(),mimeType:t().optional(),sizes:a(t()).optional(),theme:i([`light`,`dark`]).optional()}),D=l({icons:a(we).optional()}),O=l({name:t(),title:t().optional()}),Te=O.extend({...O.shape,...D.shape,version:t(),websiteUrl:t().optional(),description:t().optional()}),Ee=ie(l({applyDefaults:c().optional()}),d(t(),n())),De=ee(e=>e&&typeof e==`object`&&!Array.isArray(e)&&Object.keys(e).length===0?{form:{}}:e,ie(l({form:Ee.optional(),url:p.optional()}),d(t(),n()).optional())),Oe=o({list:p.optional(),cancel:p.optional(),requests:o({sampling:o({createMessage:p.optional()}).optional(),elicitation:o({create:p.optional()}).optional()}).optional()}),ke=o({list:p.optional(),cancel:p.optional(),requests:o({tools:o({call:p.optional()}).optional()}).optional()}),Ae=l({experimental:d(t(),p).optional(),sampling:l({context:p.optional(),tools:p.optional()}).optional(),elicitation:De.optional(),roots:l({listChanged:c().optional()}).optional(),tasks:Oe.optional(),extensions:d(t(),p).optional()}),je=h.extend({protocolVersion:t(),capabilities:Ae,clientInfo:Te}),k=_.extend({method:s(`initialize`),params:je}),Me=e=>k.safeParse(e).success,Ne=l({experimental:d(t(),p).optional(),logging:p.optional(),completions:p.optional(),prompts:l({listChanged:c().optional()}).optional(),resources:l({subscribe:c().optional(),listChanged:c().optional()}).optional(),tools:l({listChanged:c().optional()}).optional(),tasks:ke.optional(),extensions:d(t(),p).optional()}),Pe=b.extend({protocolVersion:t(),capabilities:Ne,serverInfo:Te,instructions:t().optional()}),Fe=y.extend({method:s(`notifications/initialized`),params:v.optional()}),A=_.extend({method:s(`ping`),params:h.optional()}),Ie=l({progress:r(),total:f(r()),message:f(t())}),Le=l({...v.shape,...Ie.shape,progressToken:de}),j=y.extend({method:s(`notifications/progress`),params:Le}),Re=h.extend({cursor:fe.optional()}),M=_.extend({params:Re.optional()}),N=b.extend({nextCursor:fe.optional()}),ze=i([`working`,`input_required`,`completed`,`failed`,`cancelled`]),P=l({taskId:t(),status:ze,ttl:u([r(),re()]),createdAt:t(),lastUpdatedAt:t(),pollInterval:f(r()),statusMessage:f(t())}),F=b.extend({task:P}),Be=v.merge(P),I=y.extend({method:s(`notifications/tasks/status`),params:Be}),L=_.extend({method:s(`tasks/get`),params:h.extend({taskId:t()})}),R=b.merge(P),z=_.extend({method:s(`tasks/result`),params:h.extend({taskId:t()})});b.loose();var B=M.extend({method:s(`tasks/list`)}),V=N.extend({tasks:a(P)}),H=_.extend({method:s(`tasks/cancel`),params:h.extend({taskId:t()})}),Ve=b.merge(P),He=l({uri:t(),mimeType:f(t()),_meta:d(t(),n()).optional()}),Ue=He.extend({text:t()}),U=t().refine(e=>{try{return atob(e),!0}catch{return!1}},{message:`Invalid Base64 string`}),We=He.extend({blob:U}),W=i([`user`,`assistant`]),G=l({audience:a(W).optional(),priority:r().min(0).max(1).optional(),lastModified:ne({offset:!0}).optional()}),Ge=l({...O.shape,...D.shape,uri:t(),description:f(t()),mimeType:f(t()),size:f(r()),annotations:G.optional(),_meta:f(o({}))}),Ke=l({...O.shape,...D.shape,uriTemplate:t(),description:f(t()),mimeType:f(t()),annotations:G.optional(),_meta:f(o({}))}),qe=M.extend({method:s(`resources/list`)}),Je=N.extend({resources:a(Ge)}),Ye=M.extend({method:s(`resources/templates/list`)}),Xe=N.extend({resourceTemplates:a(Ke)}),K=h.extend({uri:t()}),Ze=K,Qe=_.extend({method:s(`resources/read`),params:Ze}),$e=b.extend({contents:a(u([Ue,We]))}),et=y.extend({method:s(`notifications/resources/list_changed`),params:v.optional()}),tt=K,nt=_.extend({method:s(`resources/subscribe`),params:tt}),rt=K,it=_.extend({method:s(`resources/unsubscribe`),params:rt}),at=v.extend({uri:t()}),ot=y.extend({method:s(`notifications/resources/updated`),params:at}),st=l({name:t(),description:f(t()),required:f(c())}),ct=l({...O.shape,...D.shape,description:f(t()),arguments:f(a(st)),_meta:f(o({}))}),lt=M.extend({method:s(`prompts/list`)}),ut=N.extend({prompts:a(ct)}),dt=h.extend({name:t(),arguments:d(t(),t()).optional()}),ft=_.extend({method:s(`prompts/get`),params:dt}),q=l({type:s(`text`),text:t(),annotations:G.optional(),_meta:d(t(),n()).optional()}),J=l({type:s(`image`),data:U,mimeType:t(),annotations:G.optional(),_meta:d(t(),n()).optional()}),Y=l({type:s(`audio`),data:U,mimeType:t(),annotations:G.optional(),_meta:d(t(),n()).optional()}),pt=l({type:s(`tool_use`),name:t(),id:t(),input:d(t(),n()),_meta:d(t(),n()).optional()}),mt=l({type:s(`resource`),resource:u([Ue,We]),annotations:G.optional(),_meta:d(t(),n()).optional()}),ht=Ge.extend({type:s(`resource_link`)}),X=u([q,J,Y,ht,mt]),gt=l({role:W,content:X}),_t=b.extend({description:t().optional(),messages:a(gt)}),vt=y.extend({method:s(`notifications/prompts/list_changed`),params:v.optional()}),yt=l({title:t().optional(),readOnlyHint:c().optional(),destructiveHint:c().optional(),idempotentHint:c().optional(),openWorldHint:c().optional()}),bt=l({taskSupport:i([`required`,`optional`,`forbidden`]).optional()}),xt=l({...O.shape,...D.shape,description:t().optional(),inputSchema:l({type:s(`object`),properties:d(t(),p).optional(),required:a(t()).optional()}).catchall(n()),outputSchema:l({type:s(`object`),properties:d(t(),p).optional(),required:a(t()).optional()}).catchall(n()).optional(),annotations:yt.optional(),execution:bt.optional(),_meta:d(t(),n()).optional()}),St=M.extend({method:s(`tools/list`)}),Ct=N.extend({tools:a(xt)}),Z=b.extend({content:a(X).default([]),structuredContent:d(t(),n()).optional(),isError:c().optional()});Z.or(b.extend({toolResult:n()}));var wt=g.extend({name:t(),arguments:d(t(),n()).optional()}),Tt=_.extend({method:s(`tools/call`),params:wt}),Et=y.extend({method:s(`notifications/tools/list_changed`),params:v.optional()});l({autoRefresh:c().default(!0),debounceMs:r().int().nonnegative().default(300)});var Q=i([`debug`,`info`,`notice`,`warning`,`error`,`critical`,`alert`,`emergency`]),Dt=h.extend({level:Q}),Ot=_.extend({method:s(`logging/setLevel`),params:Dt}),kt=v.extend({level:Q,logger:t().optional(),data:n()}),At=y.extend({method:s(`notifications/message`),params:kt}),jt=l({name:t().optional()}),Mt=l({hints:a(jt).optional(),costPriority:r().min(0).max(1).optional(),speedPriority:r().min(0).max(1).optional(),intelligencePriority:r().min(0).max(1).optional()}),Nt=l({mode:i([`auto`,`required`,`none`]).optional()}),Pt=l({type:s(`tool_result`),toolUseId:t().describe(`The unique identifier for the corresponding tool call.`),content:a(X).default([]),structuredContent:l({}).loose().optional(),isError:c().optional(),_meta:d(t(),n()).optional()}),Ft=te(`type`,[q,J,Y]),$=te(`type`,[q,J,Y,pt,Pt]),It=l({role:W,content:u([$,a($)]),_meta:d(t(),n()).optional()}),Lt=g.extend({messages:a(It),modelPreferences:Mt.optional(),systemPrompt:t().optional(),includeContext:i([`none`,`thisServer`,`allServers`]).optional(),temperature:r().optional(),maxTokens:r().int(),stopSequences:a(t()).optional(),metadata:p.optional(),tools:a(xt).optional(),toolChoice:Nt.optional()}),Rt=_.extend({method:s(`sampling/createMessage`),params:Lt}),zt=b.extend({model:t(),stopReason:f(i([`endTurn`,`stopSequence`,`maxTokens`]).or(t())),role:W,content:Ft}),Bt=b.extend({model:t(),stopReason:f(i([`endTurn`,`stopSequence`,`maxTokens`,`toolUse`]).or(t())),role:W,content:u([$,a($)])}),Vt=l({type:s(`boolean`),title:t().optional(),description:t().optional(),default:c().optional()}),Ht=l({type:s(`string`),title:t().optional(),description:t().optional(),minLength:r().optional(),maxLength:r().optional(),format:i([`email`,`uri`,`date`,`date-time`]).optional(),default:t().optional()}),Ut=l({type:i([`number`,`integer`]),title:t().optional(),description:t().optional(),minimum:r().optional(),maximum:r().optional(),default:r().optional()}),Wt=l({type:s(`string`),title:t().optional(),description:t().optional(),enum:a(t()),default:t().optional()}),Gt=l({type:s(`string`),title:t().optional(),description:t().optional(),oneOf:a(l({const:t(),title:t()})),default:t().optional()}),Kt=l({type:s(`string`),title:t().optional(),description:t().optional(),enum:a(t()),enumNames:a(t()).optional(),default:t().optional()}),qt=u([Wt,Gt]),Jt=l({type:s(`array`),title:t().optional(),description:t().optional(),minItems:r().optional(),maxItems:r().optional(),items:l({type:s(`string`),enum:a(t())}),default:a(t()).optional()}),Yt=l({type:s(`array`),title:t().optional(),description:t().optional(),minItems:r().optional(),maxItems:r().optional(),items:l({anyOf:a(l({const:t(),title:t()}))}),default:a(t()).optional()}),Xt=u([Jt,Yt]),Zt=u([Kt,qt,Xt]),Qt=u([Zt,Vt,Ht,Ut]),$t=g.extend({mode:s(`form`).optional(),message:t(),requestedSchema:l({type:s(`object`),properties:d(t(),Qt),required:a(t()).optional()})}),en=g.extend({mode:s(`url`),message:t(),elicitationId:t(),url:t().url()}),tn=u([$t,en]),nn=_.extend({method:s(`elicitation/create`),params:tn}),rn=v.extend({elicitationId:t()}),an=y.extend({method:s(`notifications/elicitation/complete`),params:rn}),on=b.extend({action:i([`accept`,`decline`,`cancel`]),content:ee(e=>e===null?void 0:e,d(t(),u([t(),r(),c(),a(t())])).optional())}),sn=l({type:s(`ref/resource`),uri:t()}),cn=l({type:s(`ref/prompt`),name:t()}),ln=h.extend({ref:u([cn,sn]),argument:l({name:t(),value:t()}),context:l({arguments:d(t(),t()).optional()}).optional()}),un=_.extend({method:s(`completion/complete`),params:ln});function dn(e){if(e.params.ref.type!==`ref/prompt`)throw TypeError(`Expected CompleteRequestPrompt, but got ${e.params.ref.type}`)}function fn(e){if(e.params.ref.type!==`ref/resource`)throw TypeError(`Expected CompleteRequestResourceTemplate, but got ${e.params.ref.type}`)}var pn=b.extend({completion:o({values:a(t()).max(100),total:f(r().int()),hasMore:f(c())})}),mn=l({uri:t().startsWith(`file://`),name:t().optional(),_meta:d(t(),n()).optional()}),hn=_.extend({method:s(`roots/list`),params:h.optional()}),gn=b.extend({roots:a(mn)}),_n=y.extend({method:s(`notifications/roots/list_changed`),params:v.optional()});u([A,k,un,Ot,ft,lt,qe,Ye,Qe,nt,it,Tt,St,L,z,B,H]),u([E,j,Fe,_n,I]),u([T,zt,Bt,on,gn,R,V,F]),u([A,Rt,nn,hn,L,z,B,H]),u([E,j,At,ot,et,Et,vt,I,an]),u([T,Pe,pn,_t,ut,Je,Xe,$e,Z,Ct,R,V,F]);var vn=class e extends Error{constructor(e,t,n){super(`MCP error ${e}: ${t}`),this.code=e,this.data=n,this.name=`McpError`}static fromError(t,n,r){if(t===C.UrlElicitationRequired&&r){let e=r;if(e.elicitations)return new yn(e.elicitations,n)}return new e(t,n,r)}},yn=class extends vn{constructor(e,t=`URL elicitation${e.length>1?`s`:``} required`){super(C.UrlElicitationRequired,t,{elicitations:e})}get elicitations(){return this.data?.elicitations??[]}},bn=globalThis.crypto?.webcrypto??globalThis.crypto??import(`node:crypto`).then(e=>e.webcrypto);async function xn(e){return(await bn).getRandomValues(new Uint8Array(e))}async function Sn(e){let t=``;for(;t.length<e;){let n=await xn(e-t.length);for(let e of n)e<198&&(t+=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~`[e%66])}return t}async function Cn(e){return await Sn(e)}async function wn(e){let t=await(await bn).subtle.digest(`SHA-256`,new TextEncoder().encode(e));return btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\//g,`_`).replace(/\+/g,`-`).replace(/=/g,``)}async function Tn(e){if(e||=43,e<43||e>128)throw`Expected a length between 43 and 128. Received ${e}.`;let t=await Cn(e);return{code_verifier:t,code_challenge:await wn(t)}}export{Q as A,fn as B,lt as C,B as D,gn as E,Qe as F,be as G,xe as H,le as I,he as K,Ot as L,A as M,j as N,V as O,ue as P,I as R,se as S,qe as T,ye as U,Me as V,_e as W,L as _,Ve as a,Fe as b,zt as c,ce as d,on as f,z as g,ft as h,H as i,vn as j,St as k,Bt as l,C as m,Tt as n,E as o,T as p,oe as q,Z as r,un as s,Tn as t,F as u,R as v,Ye as w,Se as x,k as y,dn as z};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{F as e,M as t,N as n,R as r,V as i,X as a,Y as o,a as s,d as c,j as l,m as u,nt as d,r as f}from"./auth-BkmEH7-r.js";import{C as p,a as m,c as ee,k as h,v as te}from"./person-owner-BqBLyw4S.js";import{execFile as ne}from"node:child_process";import{dirname as g,join as _}from"node:path";import{chmod as re,mkdir as v,readFile as ie,rename as ae,rm as y,stat as oe,writeFile as se}from"node:fs/promises";import{AsyncLocalStorage as ce}from"node:async_hooks";import{randomUUID as b}from"node:crypto";import{homedir as le,platform as x}from"node:os";import{setTimeout as ue}from"node:timers/promises";function S(e,t=[]){let n=e instanceof Error?e.message:String(e);return u(n,t)}function de(e,t=[]){let n=u(e.title,t),r=u(e.detail?.trim()??``,t);return`${e.status} ${n}${r?` — ${r}`:``}`}function fe(){if(x()===`win32`){let e=process.env.APPDATA??_(le(),`AppData`,`Roaming`);return _(e,`aventure`,`config.json`)}let e=process.env.XDG_CONFIG_HOME??_(le(),`.config`);return _(e,`aventure`,`config.json`)}function pe(){let e=process.env[a.authToken];return typeof e==`string`&&e.length>0?{present:!0,source:`env`}:{present:!1,source:null}}function C(e,t){return typeof e==`object`&&!!e&&`code`in e&&e.code===t}function w(e){let t=e.trim();if(t.length===0)throw Error(`API host must not be blank`);let n=new URL(ge(t)?t:`${_e(t)}://${t}`),r=T(n.hostname);if(n.protocol!==`https:`&&n.protocol!==`http:`||n.username.length>0||n.password.length>0||n.pathname!==`/`&&n.pathname!==``||n.search.length>0||n.hash.length>0)throw Error(`API host must contain only an HTTP(S) host and optional port`);if(n.protocol===`http:`&&!r)throw Error(`stored credentials require HTTPS except for loopback API hosts`);return{host:n.host.toLowerCase(),origin:n.origin,isLoopback:r}}function me(e){return{...e,host:w(e.host).origin}}function he(e){let t=w(e);if(t.isLoopback)return`http://localhost:3000`;if(t.host===`api.aventure.vc`)return`https://aventure.vc`;throw Error(`no first-party browser origin is configured for API host ${t.host}`)}function ge(e){return/^[a-z][a-z\d+.-]*:\/\//iu.test(e)}function _e(e){let t=e.split(`/`,1)[0]?.toLowerCase()??``;try{return T(new URL(`http://${t}`).hostname)?`http`:`https`}catch{return`https`}}function T(e){let t=e.toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`0.0.0.0`||t===`[::1]`}var ve=2;function ye(e,t){return D(e,t).redactedUrl}async function be(e,t,n){let r=D(e,t);return await E(new URL(r.openerUrl),n)}async function E(e,t){let n=t.environment??process.env,r=t.operatingSystem??x(),i=O(t.noBrowser,n,r);if(i!==null)return{state:`skipped`,reason:i};let a=xe(r,e.toString());if(a===null)return{state:`failed`,reason:`unsupported browser-opening platform: ${r}`};try{return await Se(a.command,a.arguments),{state:`opened`,reason:null}}catch{return{state:`failed`,reason:`browser opener failed`}}}function D(e,t){let{id:n,verificationUrl:r,pollSecret:i}=e,a,o;try{a=new URL(r),o=new URL(t)}catch{throw Error(`broker returned an invalid browser verification URL`)}if(o.username.length>0||o.password.length>0||o.pathname!==`/`||o.search.length>0||o.hash.length>0)throw Error(`configured browser origin must contain only an origin`);let s=T(o.hostname);if(o.protocol!==`https:`&&!(o.protocol===`http:`&&s))throw Error(`configured browser origin must use HTTPS except for loopback development`);let c=new URLSearchParams(a.hash.slice(1)),l=[...c.keys()],u=c.getAll(`cliAuthorizationId`),d=c.getAll(`browserSecret`),f=d[0]??``;if(a.origin!==o.origin||a.protocol!==o.protocol||a.username.length>0||a.password.length>0||a.pathname!==`/settings/developer`||a.search.length>0||l.length!==ve||u.length!==1||u[0]!==n||d.length!==1||f.length===0||i.length===0||f===i)throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`);let p;try{p=decodeURIComponent(r)}catch{throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`)}if(r.includes(i)||p.includes(i))throw Error(`broker returned a browser verification URL outside the configured first-party approval flow`);let m=new URL(a);return m.hash=new URLSearchParams({cliAuthorizationId:n,browserSecret:`<redacted>`}).toString(),{openerUrl:r,redactedUrl:m.toString()}}function O(e,t,n){return e?`--no-browser was set`:n===`darwin`&&t.CODEX_SESSION_ID?`macOS Codex browser process boundary`:t.SSH_CONNECTION||t.SSH_CLIENT||t.SSH_TTY?`SSH/headless session detected`:(n===`linux`||n===`freebsd`)&&!t.DISPLAY&&!t.WAYLAND_DISPLAY?`no graphical display detected`:null}function xe(e,t){return e===`darwin`?{command:`open`,arguments:[t]}:e===`win32`?{command:`rundll32.exe`,arguments:[`url.dll,FileProtocolHandler`,t]}:e===`linux`||e===`freebsd`?{command:`xdg-open`,arguments:[t]}:null}function Se(e,t){return new Promise((n,r)=>{ne(e,[...t],{timeout:5e3,windowsHide:!0},e=>e?r(e):n())})}var Ce=100,we=3e4,Te=6e4,k=new ce;function A(){return _(g(fe()),`credentials.json`)}function Ee(e){return`OS keyring is unusable (${e}); the credential will be stored in ${A()} (mode 0600).\n`}async function j(e,t){let n;try{let n=await(await I(e,t)).getPassword()??void 0;if(n!==void 0)return{record:{provider:`keyring`,value:n}}}catch(e){n=F(e)}let r=(await L())[e]?.[t];return{...r===void 0?{}:{record:{provider:`file`,value:r}},...n===void 0?{}:{keyringFailure:n}}}async function M(e,t,n){let r;try{let i=await I(e,t);if(await i.setPassword(n),await i.getPassword()===n)return await z(e,t,void 0),`keyring`;r=`Error: keyring readback did not match`}catch(e){r=F(e,[n])}if(await z(e,t,n),(await L())[e]?.[t]!==n)throw Error(`credential storage did not confirm a durable write (keyring: ${r}; file: readback did not match)`);return`file`}async function N(e,t){try{let n=await I(e,t),r;try{await n.deleteCredential()}catch(e){r=e}let i;try{i=await n.getPassword()??void 0}catch(e){throw Error(`OS keyring removal outcome is unknown (${F(r??e)})`,{cause:e})}if(i!==void 0)throw Error(`OS keyring did not confirm removal (${F(r)})`,r===void 0?void 0:{cause:r})}finally{await z(e,t,void 0)}}async function P(e,t){let n=`${t}:probe:${b()}`,r=`aventure-cli-credential-probe:${b()}`,i;try{let t=await I(e,n);await t.setPassword(r);let a=await(await I(e,n)).getPassword(),o=await t.deleteCredential(),s=await(await I(e,n)).getPassword()??void 0;if(a!==r)i=`Error: probe readback did not match`;else if(!o||s!==void 0)i=`Error: probe cleanup was not confirmed`;else return{provider:`keyring`}}catch(e){i=F(e,[r])}try{await R(async()=>{await z(e,n,r);let t=(await L())[e]?.[n];if(await z(e,n,void 0),t!==r)throw Error(`probe readback did not match`)})}catch(e){throw Error(`credential storage is unavailable (keyring: ${i}; file ${A()}: ${F(e,[r])})`,{cause:e})}return{provider:`file`,keyringFailure:i}}function F(e,t=[]){if(!(e instanceof Error))return`Error`;let n=e.name||`Error`,[r=``]=S(e,t).trim().split(`
|
|
2
|
+
`,1);return r&&r!==n?`${n}: ${r}`:n}async function I(e,t){let n=x(),r=n===`linux`||n===`freebsd`?O(!1,process.env,n):null;if(r!==null)throw Error(`OS keyring unlock prompt is unreachable (${r})`);let{AsyncEntry:i}=await import(`@napi-rs/keyring`);return new i(e,t)}async function L(){let e=A(),t;try{t=await ie(e,`utf8`)}catch(e){if(C(e,`ENOENT`))return{};throw e}let n;try{n=JSON.parse(t)}catch(t){return await De(e,t)}return ke(n)?n:await De(e,void 0)}async function De(e,t){let n=`${e}.corrupt-${new Date().toISOString().replace(/[:.]/gu,`-`)}`;try{await ae(e,n)}catch(t){if(C(t,`ENOENT`))return{};throw Error(`${e} is not a valid credential file and could not be moved aside`,{cause:t})}return i({component:`aventure-cli`,event:`credential_file_quarantined`,message:`${e} is not a valid credential file; moved it to ${n} and continuing with an empty file store`,...t===void 0?{}:{error:t}}),{}}async function R(e){if(k.getStore()===!0)return await e();let t=`${A()}.lock`;await v(g(t),{recursive:!0,mode:448});let n=Date.now()+we,r=b();for(;;){try{await se(t,r,{flag:`wx`,mode:384});break}catch(e){if(!C(e,`EEXIST`))throw e}if(await oe(t).then(e=>Date.now()-e.mtimeMs,()=>0)>Te)await y(t,{force:!0});else if(Date.now()>n)throw Error(`credential store is locked by another CLI process (${t})`);else await ue(Ce)}try{return await k.run(!0,e)}finally{await ie(t,`utf8`).catch(()=>``)===r&&await y(t,{force:!0})}}async function z(e,t,n){await R(async()=>await Oe(e,t,n))}async function Oe(e,t,n){let r=A(),i=await L(),a={...i[e]};if(n===void 0?delete a[t]:a[t]=n,Object.keys(a).length===0?delete i[e]:i[e]=a,Object.keys(i).length===0){await y(r,{force:!0});return}await v(g(r),{recursive:!0,mode:448});let o=`${r}.${b()}.tmp`;await se(o,`${JSON.stringify(i,null,2)}\n`,{mode:384}),await re(o,384),await ae(o,r)}function ke(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.values(e).every(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.values(e).every(e=>typeof e==`string`))}var Ae=te({createdAt:h({offset:!0}),description:p().nullish(),expiresAt:h({offset:!0}).nullish(),id:p().regex(/^ak_[0-9A-Fa-f]{32}$/),lastUsedAt:h({offset:!0}).nullish(),name:p(),revocationReason:p().nullish(),scopes:ee(p()),status:m([`ACTIVE`,`REVOKED`,`EXPIRED`]),subject:p(),updatedAt:h({offset:!0})}),B=`vc.aventure.aventure-cli`,V=`aventure-cli-personal-v1`;async function je(e,t,n){let r=U(e),i=Fe(t,n),a;try{a=await M(B,r,i)}catch(e){throw Error(`${S(e,[i,t.secret])}; broker acknowledgment was withheld. Re-run auth status before retrying.`,{cause:e})}return{host:r,provider:a,activation:n,credential:t}}async function H(e){let t=U(e),n;try{n=await j(B,t)}catch(e){return Pe(S(e))}let{record:r,keyringFailure:i}=n;return r===void 0?i===void 0?{state:`missing`}:{state:`missing`,keyringFailure:i}:{state:`found`,stored:{host:t,provider:r.provider,...Ie(r.value)}}}async function Me(e){let t=await H(e);if(t.state!==`missing`)return t;try{let{keyringFailure:t}=await P(B,U(e));return t===void 0?{state:`missing`}:{state:`missing`,keyringFailure:t}}catch(e){return Pe(S(e))}}async function Ne(e){await N(B,U(e))}function U(e){return w(e).host}function Pe(e){return{state:`unavailable`,summary:e,cause:`storage`}}function Fe(e,t){return`${V}:${t}\n${JSON.stringify(e.apiKey)}\n${e.secret}`}function Ie(e){let t=e.indexOf(`
|
|
3
|
+
`),n=t<0?-1:e.indexOf(`
|
|
4
|
+
`,t+1),r=t<0?e:e.slice(0,t),i=r===`${V}:active`?`active`:`pending`;if(t<0||n<0||r!==`${V}:pending`&&r!==`${V}:active`)throw Error(`OS credential entry has an unsupported format`);let a=e.slice(n+1);if(a.length===0)throw Error(`OS credential entry has an empty secret`);let o;try{o=JSON.parse(e.slice(t+1,n))}catch(e){throw Error(`OS credential entry failed canonical schema validation`,{cause:e})}let s=Ae.safeParse(o);if(!s.success)throw Error(`OS credential entry failed canonical schema validation`,{cause:s.error});return{activation:i,credential:{apiKey:s.data,secret:a}}}async function Le(e){if(Re())return;let t=U(d().host);try{let n=await H(t);if(n.state===`unavailable`){r(ze(`keyring`,Error(n.summary)));return}n.state===`found`&&n.stored.activation===`active`&&!Re()&&(process.env[a.authToken]=n.stored.credential.secret,e?.(`api-key`))}catch(e){i(ze(`parse`,e))}}function Re(){return(process.env[a.authToken]?.trim().length??0)>0}function ze(e,t){return{component:`aventure-cli`,event:`api_key_materialization_unavailable`,message:`saved API key could not be loaded; continuing with environment auth`,fields:{source:e},error:t}}var Be=s.omit({mcpResource:!0}),W=`vc.aventure.aventure-cli.oauth`,Ve=`oauth:`,He=6e4;function Ue(e,t){let n=Z(t);return{client:e,expiresAt:st(ot(n)),tokens:n}}async function We(e,t){let n=q(e),r=tt(n,t),i;try{i=await M(W,X(n),r)}catch(e){throw Error(`OAuth credential could not be stored — ${S(e,[r,...Y(t.tokens)])}`,{cause:e})}return{host:n,provider:i,credential:nt(n,r)}}async function G(e){let t=q(e),n;try{n=await j(W,X(t))}catch(e){return{state:`unavailable`,summary:S(e)}}let{record:r,keyringFailure:i}=n;return r===void 0?i===void 0?{state:`missing`}:{state:`missing`,keyringFailure:i}:{state:`found`,stored:{host:t,provider:r.provider,credential:nt(t,r.value)}}}async function Ge(e){await N(W,X(q(e)))}async function Ke(e){try{return await G(e)}catch(e){return{state:`invalid`,summary:S(e)}}}async function qe(e){let t=await Ke(e);if(t.state!==`missing`)return t;let n=await Je(e);return n.state===`unavailable`?n:n.keyringFailure===void 0?{state:`missing`}:{state:`missing`,keyringFailure:n.keyringFailure}}async function Je(e){let t=q(e);try{return{state:`available`,...await P(W,X(t))}}catch(e){return{state:`unavailable`,summary:S(e)}}}function Ye(e){return K(e.authorizationServer,`authorization server`)}function Xe(e){if(URL.canParse(e.resource)&&new URL(e.resource).protocol===`http:`){let t=w(e.resource);if(t.isLoopback)return new URL(t.origin)}return K(e.resource,`resource`)}function Ze(e){if(e.clientId.trim()!==e.clientId||e.clientId.length===0)throw Error(`OAuth client ID must not be blank`);return e.clientId}function Qe(e){if(e.scope.length===0||e.scope.some(e=>e.trim()!==e||e.length===0)||new Set(e.scope).size!==e.scope.length)throw Error(`OAuth scope must contain unique non-blank values`);return e.scope}function K(e,t,n=!1){let r;try{r=new URL(e)}catch(e){throw Error(`OAuth ${t} is not a valid URL`,{cause:e})}if(r.protocol!==`https:`||r.username.length>0||r.password.length>0||!n&&r.search.length>0||r.hash.length>0)throw Error(`OAuth ${t} must be an HTTPS URL without credentials${n?``:`, query`} or fragment`);return r}function q(e){return w(e).host}function J(e){return new Date(e.expiresAt).getTime()-He<=Date.now()}function $e(e){let t=et(e.tokens.id_token)??et(e.tokens.access_token),n=t?.email;return{subject:t?.sub??null,email:typeof n==`string`?n:null}}function et(e){if(e!==void 0)try{return l(e)}catch{return}}function Y(e){return[e.access_token,e.refresh_token,e.id_token]}function X(e){return`${Ve}${e}`}function tt(e,t){return JSON.stringify({client:rt(e,t.client),expiresAt:ct(t.expiresAt),tokens:Z(t.tokens)})}function nt(e,t){let n;try{n=JSON.parse(t)}catch(e){throw Error(`OS OAuth credential entry failed schema validation`,{cause:e})}if(!ut(n))throw Error(`OS OAuth credential entry failed schema validation`);return{client:rt(e,it(n.client)),expiresAt:ct(n.expiresAt),tokens:Z(at(n.tokens))}}function rt(e,t){if(q(t.resource)!==e)throw Error(`OAuth client resource must match the credential API host`);return t}function it(e){let t=Be.safeParse(e);if(!t.success)throw Error(`OS OAuth credential entry failed canonical client validation`,{cause:t.error});return t.data}function at(e){let t=f.safeParse(e);if(!t.success)throw Error(`OS OAuth credential entry failed OAuth token validation`,{cause:t.error});return t.data}function Z(e){if(!lt(e.access_token)||e.token_type.trim().toLowerCase()!==`bearer`)throw Error(`OAuth token response must contain a bearer access token`);if(e.refresh_token!==void 0&&!lt(e.refresh_token))throw Error(`OAuth token response has an invalid refresh token`);return ot(e),e}function ot(e){let t=e.expires_in;if(typeof t!=`number`||!Number.isSafeInteger(t)||t<=0)throw Error(`OAuth token response must contain a positive expires_in`);return t}function st(e){let t=new Date(Date.now()+e*1e3);if(!Number.isFinite(t.getTime()))throw Error(`OAuth token response has an expiry outside the supported date range`);return t.toISOString()}function ct(e){if(typeof e!=`string`)throw Error(`OS OAuth credential entry has an invalid absolute expiry`);let t=new Date(e);if(!Number.isFinite(t.getTime())||t.toISOString()!==e)throw Error(`OS OAuth credential entry has an invalid absolute expiry`);return e}function lt(e){return e.trim()===e&&e.length>0}function ut(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}async function dt(r,o){if($())return;let s=async(e,t,n,a=!1)=>{if(await Le(o),!$())throw a?t:pt(e,r,t,n);i({component:`aventure-cli`,event:`oauth_credential_bypassed`,message:`OAuth sign-in is unavailable (${e}); using the stored API key.`,...t===void 0?{}:{error:Error(S(t,Q(n)))}})},l=async(e,t,n)=>{let r=await G(e.host).catch(()=>void 0);if(r?.state===`found`&&r.stored.credential.tokens.access_token!==e.credential.tokens.access_token)return await u(r.stored,!1);try{await Ge(e.host)}catch(n){i({component:`aventure-cli`,event:`oauth_credential_retire_failed`,message:`the saved OAuth credential is dead (${t}) but could not be removed`,error:Error(S(n,Q(e)))})}await s(t,n,e)},u=async(r,i)=>{let u=(e,t)=>i?l(r,e,t):s(e,t,r),d=r.credential;if(J(d)){if(d.tokens.refresh_token===void 0)return await u(`the saved OAuth credential has expired`);try{d=await ft(r)}catch(t){return t instanceof n?await u(`Clerk rejected the saved refresh token`,t):await s(`the saved OAuth credential could not be renewed`,t,r,!(t instanceof e))}}let f;try{f=await c(d.tokens.access_token,new URL(d.client.resource))!==null}catch(e){return e instanceof t?await u(`the saved OAuth credential is malformed`,e):await s(`the saved OAuth credential could not be verified`,e,r,!0)}if(!f)return await u(`the saved OAuth credential was rejected`);$()||(process.env[a.authToken]=d.tokens.access_token,o?.(`oauth`))},f;try{f=q(d().host)}catch(e){throw pt(`the API host could not select its OAuth credential`,r,e)}let p;try{p=await G(f)}catch(e){return await s(`the saved OAuth credential is invalid or expired`,e)}if(p.state!==`missing`){if(p.state===`unavailable`)return await s(`the saved OAuth credential could not be read`,Error(p.summary));await u(p.stored,!0)}}async function ft(e){return await R(async()=>{let t=await G(e.host),n=t.state===`found`?t.stored:e;if(!J(n.credential))return n.credential;let{renewOAuthTokens:r}=await import(`./oauth-login-D-tNp610.js`),a=Ue(n.credential.client,await r(n));try{await We(e.host,a)}catch(e){i({component:`aventure-cli`,event:`oauth_credential_store_failed`,message:`renewed OAuth credential could not be stored; this command uses it and the next one falls back to the API key or sign-in`,error:Error(S(e,Y(a.tokens)))})}return a})}function Q(e){return e===void 0?[]:Y(e.credential.tokens)}function $(){return(process.env[a.authToken]?.trim().length??0)>0}function pt(e,t,n,r){let i=n===void 0?``:` — ${S(n,Q(r))}`,a=t??o().bin[0];return Error(`OAuth sign-in is required: ${e}. Run \`${a} auth login\` before retrying.${i}`)}export{me as A,je as C,be as D,E,S as M,de as N,ye as O,H as S,Ee as T,We as _,Ge as a,Ne as b,J as c,$e as d,Xe as f,K as g,Je as h,Ue as i,pe as j,he as k,Ye as l,Y as m,ft as n,Ke as o,Qe as p,q as r,qe as s,dt as t,Ze as u,Le as v,Ae as w,Me as x,U as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e}from"./oauth-login-DZHht6I9.js";export{e as renewOAuthTokens};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`,ye=`urn:ietf:params:oauth:grant-type:device_code`;function V(e){let t=Reflect.get(e,`device_authorization_endpoint`);if(typeof t!=`string`)throw Error(`OAuth authorization-server metadata lacks device_authorization_endpoint`);return _(t,`device authorization endpoint`,!0)}async function be(e,t){let n=await fetch(V(t),{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({client_id:w(e),scope:C(e).join(` `),resource:g(e).toString()})});if(!n.ok)throw Error(`device authorization endpoint answered ${n.status}`);return xe(await H(n,`device authorization`),Date.now())}async function H(e,t){try{return await e.json()}catch(n){throw Error(`${t} endpoint answered ${e.status} without a JSON body`,{cause:n})}}function xe(e,t){if(typeof e!=`object`||!e)throw Error(`device authorization response is not an object`);let n=Reflect.get(e,`device_code`),r=Reflect.get(e,`user_code`),i=Reflect.get(e,`verification_uri_complete`),a=Reflect.get(e,`verification_uri`),o=Reflect.get(e,`expires_in`),s=Reflect.get(e,`interval`);if(typeof n!=`string`||typeof r!=`string`||n.length===0||r.length===0)throw Error(`device authorization response lacks device_code or user_code`);let c=typeof i==`string`&&i.length>0?i:a;if(typeof c!=`string`)throw Error(`device authorization response lacks a verification URI`);if(typeof o!=`number`||o<=0)throw Error(`device authorization response lacks a positive expires_in`);return{deviceCode:n,userCode:r,verificationUri:_(c,`verification URI`,!0),expiresAt:t+o*1e3,intervalMilliseconds:(typeof s==`number`&&s>=0?s:5)*1e3}}async function Se(e,t,n){let r=_(t.token_endpoint,`token endpoint`,!0),i=n.intervalMilliseconds,a=null;for(;Date.now()<n.expiresAt;){await pe(i);let t;try{t=await fetch(r,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({client_id:w(e),grant_type:ye,device_code:n.deviceCode})})}catch(e){a=`the token endpoint was unreachable — ${
|
|
3
|
-
`);let
|
|
4
|
-
`),await K(e,
|
|
1
|
+
import{I as e,M as t,P as n,at as r,d as i,i as a,n as o,nt as s,ot as c,p as l,r as u,s as ee,t as d}from"./auth-BkmEH7-r.js";import{A as te,E as f,M as p,N as ne,T as re,_ as m,c as h,f as g,g as _,h as v,i as ie,l as y,m as b,n as x,o as S,p as C,r as ae,u as w}from"./oauth-bearer-credential-CMb1HSSN.js";import{S as oe,q as se,t as ce}from"./index.node-Cae5ADms.js";import{once as le}from"node:events";import{stderr as T}from"node:process";import{createServer as ue}from"node:http";import{randomBytes as de,timingSafeEqual as fe}from"node:crypto";import{setTimeout as pe}from"node:timers/promises";function me(e){return[`client_secret_basic`,`client_secret_post`,`none`].includes(e)}var E=`code`,D=`S256`;function O(e,t){let n=e.client_secret!==void 0;return`token_endpoint_auth_method`in e&&e.token_endpoint_auth_method&&me(e.token_endpoint_auth_method)&&(t.length===0||t.includes(e.token_endpoint_auth_method))?e.token_endpoint_auth_method:t.length===0?n?`client_secret_basic`:`none`:n&&t.includes(`client_secret_basic`)?`client_secret_basic`:n&&t.includes(`client_secret_post`)?`client_secret_post`:t.includes(`none`)?`none`:n?`client_secret_post`:`none`}function k(e,t,n,r){let{client_id:i,client_secret:a}=t;switch(e){case`client_secret_basic`:A(i,a,n);return;case`client_secret_post`:j(i,a,r);return;case`none`:M(i,r);return;default:throw Error(`Unsupported client authentication method: ${e}`)}}function A(e,t,n){if(!t)throw Error(`client_secret_basic authentication requires a client_secret`);let r=btoa(`${e}:${t}`);n.set(`Authorization`,`Basic ${r}`)}function j(e,t,n){n.set(`client_id`,e),t&&n.set(`client_secret`,t)}function M(e,t){t.set(`client_id`,e)}async function N(t){let r=t instanceof Response?t.status:void 0,i=t instanceof Response?await t.text():t;try{let{error:t,error_description:r,error_uri:a}=d.parse(JSON.parse(i));return new(n[t]||e)(r||``,a)}catch(t){let n=`${r?`HTTP ${r}: `:``}Invalid OAuth error response: ${t}. Raw body: ${i}`;return new e(n)}}async function P(e,t,n=fetch){try{return await n(e,{headers:t})}catch(r){if(r instanceof TypeError)return t?P(e,void 0,n):void 0;throw r}}function F(e){let t=typeof e==`string`?new URL(e):e,n=t.pathname!==`/`,r=[];if(!n)return r.push({url:new URL(`/.well-known/oauth-authorization-server`,t.origin),type:`oauth`}),r.push({url:new URL(`/.well-known/openid-configuration`,t.origin),type:`oidc`}),r;let i=t.pathname;return i.endsWith(`/`)&&(i=i.slice(0,-1)),r.push({url:new URL(`/.well-known/oauth-authorization-server${i}`,t.origin),type:`oauth`}),r.push({url:new URL(`/.well-known/openid-configuration${i}`,t.origin),type:`oidc`}),r.push({url:new URL(`${i}/.well-known/openid-configuration`,t.origin),type:`oidc`}),r}async function I(e,{fetchFn:t=fetch,protocolVersion:n=oe}={}){let r={"MCP-Protocol-Version":n,Accept:`application/json`},i=F(e);for(let{url:e,type:n}of i){let i=await P(e,r,t);if(i){if(!i.ok){if(await i.body?.cancel(),i.status>=400&&i.status<500)continue;throw Error(`HTTP ${i.status} trying to load ${n===`oauth`?`OAuth`:`OpenID provider`} metadata from ${e}`)}return n===`oauth`?o.parse(await i.json()):a.parse(await i.json())}}}async function L(e,{metadata:t,clientInformation:n,redirectUrl:r,scope:i,state:a,resource:o}){let s;if(t){if(s=new URL(t.authorization_endpoint),!t.response_types_supported.includes(E))throw Error(`Incompatible auth server: does not support response type ${E}`);if(t.code_challenge_methods_supported&&!t.code_challenge_methods_supported.includes(D))throw Error(`Incompatible auth server: does not support code challenge method ${D}`)}else s=new URL(`/authorize`,e);let c=await ce(),l=c.code_verifier,u=c.code_challenge;return s.searchParams.set(`response_type`,E),s.searchParams.set(`client_id`,n.client_id),s.searchParams.set(`code_challenge`,u),s.searchParams.set(`code_challenge_method`,D),s.searchParams.set(`redirect_uri`,String(r)),a&&s.searchParams.set(`state`,a),i&&s.searchParams.set(`scope`,i),i?.includes(`offline_access`)&&s.searchParams.append(`prompt`,`consent`),o&&s.searchParams.set(`resource`,o.href),{authorizationUrl:s,codeVerifier:l}}function R(e,t,n){return new URLSearchParams({grant_type:`authorization_code`,code:e,code_verifier:t,redirect_uri:String(n)})}async function z(e,{metadata:t,tokenRequestParams:n,clientInformation:r,addClientAuthentication:i,resource:a,fetchFn:o}){let s=t?.token_endpoint?new URL(t.token_endpoint):new URL(`/token`,e),c=new Headers({"Content-Type":`application/x-www-form-urlencoded`,Accept:`application/json`});a&&n.set(`resource`,a.href),i?await i(c,n,s,t):r&&k(O(r,t?.token_endpoint_auth_methods_supported??[]),r,c,n);let l=await(o??fetch)(s,{method:`POST`,headers:c,body:n});if(!l.ok)throw await N(l);return u.parse(await l.json())}async function he(e,{metadata:t,clientInformation:n,authorizationCode:r,codeVerifier:i,redirectUri:a,resource:o,addClientAuthentication:s,fetchFn:c}){return z(e,{metadata:t,tokenRequestParams:R(r,i,a),clientInformation:n,addClientAuthentication:s,resource:o,fetchFn:c})}async function ge(e,{metadata:t,clientInformation:n,refreshToken:r,resource:i,addClientAuthentication:a,fetchFn:o}){return{refresh_token:r,...await z(e,{metadata:t,tokenRequestParams:new URLSearchParams({grant_type:`refresh_token`,refresh_token:r}),clientInformation:n,addClientAuthentication:a,resource:i,fetchFn:o})}}var _e=5e3,ve=500,B=`Approval poll was interrupted; retrying.
|
|
2
|
+
`,ye=`urn:ietf:params:oauth:grant-type:device_code`;function V(e){let t=Reflect.get(e,`device_authorization_endpoint`);if(typeof t!=`string`)throw Error(`OAuth authorization-server metadata lacks device_authorization_endpoint`);return _(t,`device authorization endpoint`,!0)}async function be(e,t){let n=await fetch(V(t),{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({client_id:w(e),scope:C(e).join(` `),resource:g(e).toString()})});if(!n.ok)throw Error(`device authorization endpoint answered ${n.status}`);return xe(await H(n,`device authorization`),Date.now())}async function H(e,t){try{return await e.json()}catch(n){throw Error(`${t} endpoint answered ${e.status} without a JSON body`,{cause:n})}}function xe(e,t){if(typeof e!=`object`||!e)throw Error(`device authorization response is not an object`);let n=Reflect.get(e,`device_code`),r=Reflect.get(e,`user_code`),i=Reflect.get(e,`verification_uri_complete`),a=Reflect.get(e,`verification_uri`),o=Reflect.get(e,`expires_in`),s=Reflect.get(e,`interval`);if(typeof n!=`string`||typeof r!=`string`||n.length===0||r.length===0)throw Error(`device authorization response lacks device_code or user_code`);let c=typeof i==`string`&&i.length>0?i:a;if(typeof c!=`string`)throw Error(`device authorization response lacks a verification URI`);if(typeof o!=`number`||o<=0)throw Error(`device authorization response lacks a positive expires_in`);return{deviceCode:n,userCode:r,verificationUri:_(c,`verification URI`,!0),expiresAt:t+o*1e3,intervalMilliseconds:(typeof s==`number`&&s>=0?s:5)*1e3}}async function Se(e,t,n){let r=_(t.token_endpoint,`token endpoint`,!0),i=n.intervalMilliseconds,a=null;for(;Date.now()<n.expiresAt;){await pe(i);let t;try{t=await fetch(r,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:new URLSearchParams({client_id:w(e),grant_type:ye,device_code:n.deviceCode})})}catch(e){a=`the token endpoint was unreachable — ${p(e)}`,T.write(B);continue}if(t.status>=ve){await t.body?.cancel(),a=`the token endpoint answered ${t.status}`,T.write(B);continue}a=null;let o=await H(t,`token`);if(t.ok){let e=u.safeParse(o);if(!e.success)throw Error(`token endpoint returned an invalid token response`);return e.data}let s=d.safeParse(o),c=s.success?s.data.error:`HTTP ${t.status}`;if(c!==`authorization_pending`){if(c===`slow_down`){i+=_e;continue}throw Error(c===`access_denied`?`the sign-in was denied in the browser`:c===`expired_token`?`the device code expired before approval`:`token endpoint answered ${c}`)}}throw Error(a===null?`the device code expired before approval`:`the device code expired before approval — last failure: ${a}`)}var Ce=3e5;function we(e){let t;try{t=new URL(e.redirectUri)}catch(e){throw Error(`OAuth callback configuration is not a valid URL`,{cause:e})}if(t.protocol!==`http:`||t.hostname!==`127.0.0.1`||t.port.length>0||t.pathname!==`/callback`||t.username.length>0||t.password.length>0||t.search.length>0||t.hash.length>0)throw Error(`OAuth callback configuration must be http://127.0.0.1/callback without a port, query, or fragment`);return t}async function Te(e,t){let n,r=new Promise(e=>{n=e}),i=ue((r,i)=>{i.setHeader(`Cache-Control`,`no-store`),i.setHeader(`Content-Type`,`text/plain; charset=utf-8`);let a=new URL(r.url??`/`,e);if(r.method!==`GET`||a.pathname!==e.pathname){i.statusCode=404,i.end(`OAuth callback not found.`);return}let o=a.searchParams.getAll(`state`),s=Buffer.from(o[0]??``),c=Buffer.from(t);if(o.length!==1||s.length!==c.length||!fe(s,c)){i.statusCode=400,i.end(`OAuth callback state did not match. Return to the CLI and retry.`);return}if(a.searchParams.has(`error`)){i.statusCode=400,i.end(`OAuth authorization was not completed. Return to the CLI.`),n({state:`failed`,message:`OAuth authorization server returned an error`});return}let l=a.searchParams.getAll(`code`),u=l[0]?.trim();if(l.length!==1||u===void 0||u.length===0){i.statusCode=400,i.end(`OAuth callback did not include an authorization code.`);return}i.statusCode=200,i.end(`OAuth authorization completed. Return to the CLI.`),n({state:`code`,authorizationCode:u})});i.on(`error`,e=>n({state:`failed`,message:`OAuth callback listener failed: ${p(e)}`}));try{let t=le(i,`listening`);i.listen({host:`127.0.0.1`,port:0}),await t;let n=i.address();if(n===null||typeof n==`string`||n.port<=0)throw Error(`OAuth callback listener did not receive an ephemeral loopback port`);let a=new URL(e);return a.port=String(n.port),{redirectUri:a,waitForAuthorizationCode:async()=>{let e;return await Promise.race([r,new Promise(t=>{e=setTimeout(()=>t({state:`timed-out`}),Ce)})]).finally(()=>{e!==void 0&&clearTimeout(e)})},close:async()=>await U(i)}}catch(e){throw i.listening&&await U(i),e}}function U(e){return new Promise((t,n)=>{e.close(e=>e===void 0?t():n(e))})}var W=`the OAuth credential is valid, but the API refused this account (HTTP 403); signing in again will not change that`;async function Ee(e){let n;try{n=ae(s().host)}catch(e){return r(`auth login: invalid API host — ${p(e)}`)}let a=await S(n);if(a.state===`missing`)return G(n,e);if(a.state===`unavailable`)return r(`auth login: ${a.summary}`);if(a.state===`invalid`)return G(n,e,`Saved OAuth credential cannot be read — ${a.summary}`);let{stored:o}=a;if(h(o.credential))return await De(o,e);let l;try{l=await i(o.credential.tokens.access_token,g(o.credential.client))}catch(i){return i instanceof t?G(n,e,`Saved OAuth credential was rejected`):r(`auth login: saved OAuth credential could not be verified — ${p(i,b(o.credential.tokens))}`)}return l===`forbidden`?r(`auth login: ${W}`):l===null?G(n,e,`Saved OAuth credential was rejected`):c(`OAuth CLI access token is already stored and verified.`,$(o))}async function De(e,t){let n=await v(e.host);if(n.state===`unavailable`)return r(`auth login: ${n.summary}`);let{tokens:i}=e.credential;if(i.refresh_token===void 0)return G(e.host,t,`Saved OAuth access token expired`,n);let a;try{a=await x(e)}catch(r){return G(e.host,t,`Saved OAuth credential could not be renewed — ${p(r,b(i))}`,n)}J(n);let o=await Q(e.host,a,`OAuth CLI access token renewed and verified.`);if(!o.ok)return o;let s=await Z(a);return s.state===`failed`?r(`auth login: ${s.summary}`):s.state===`rejected`?G(e.host,t,`Renewed OAuth access token was rejected`,n):o}async function G(e,t,n,i){let a=i??await v(e);if(a.state===`unavailable`)return r(`auth login: ${a.summary}`);J(a),n!==void 0&&T.write(`${n}; continuing to browser sign-in.\n`);let o;try{let e=(await Y()).oauthClient;if(e==null)throw Error(`the API does not advertise an OAuth CLI client`);o=e}catch(e){return r(`auth login: OAuth configuration is unavailable — ${p(e)}`)}let s;try{s=await X(o)}catch(e){return r(`auth login: OAuth authorization-server discovery failed — ${p(e)}`)}if(t.noBrowser)return await K(e,o,s);let c=de(32).toString(`base64url`),l;try{l=await Te(we(o),c);let t=await L(y(o),{metadata:s,clientInformation:{client_id:w(o)},redirectUrl:l.redirectUri,resource:g(o),scope:C(o).join(` `),state:c}),n=await f(t.authorizationUrl,{noBrowser:!1});if(n.state!==`opened`)return await l.close(),l=void 0,T.write(`Browser not opened automatically (${n.reason}).\n`),await K(e,o,s);T.write(`Browser sign-in opened: choose the account, then approve. Waiting for the loopback callback...
|
|
3
|
+
`);let i=await l.waitForAuthorizationCode();if(i.state===`timed-out`)return await l.close(),l=void 0,T.write(`Browser sign-in was not completed; continuing with a device code.
|
|
4
|
+
`),await K(e,o,s);if(i.state===`failed`)return r(`auth login: ${i.message}`);let a;try{a=await he(y(o),{metadata:s,clientInformation:{client_id:w(o)},authorizationCode:i.authorizationCode,codeVerifier:t.codeVerifier,redirectUri:l.redirectUri,resource:g(o)})}catch(e){return r(`auth login: OAuth token exchange failed — ${p(e,[i.authorizationCode,t.codeVerifier])}`)}return await q(e,o,a)}catch(e){return r(`auth login: OAuth browser authorization failed — ${p(e)}`)}finally{await l?.close()}}async function K(e,t,n){let i;try{i=await be(t,n)}catch(e){return r(`auth login: OAuth device authorization request failed — ${p(e)}`)}T.write([`Sign-in URL (works on any device): ${i.verificationUri.toString()}`,`Confirm that the page shows code ${i.userCode} before approving.`,"That page approves with the account already signed in there; to pick an account, run `auth login` on a machine with a browser.",`Waiting for approval...
|
|
5
5
|
`].join(`
|
|
6
|
-
`));let
|
|
6
|
+
`));let a;try{a=await Se(t,n,i)}catch(e){return r(`auth login: OAuth device authorization did not complete — ${p(e,[i.deviceCode])}`)}return await q(e,t,a)}async function q(e,t,n){let i=await ke(t,n);return i.state===`failed`?r(`auth login: ${i.summary}`):i.state===`rejected`?r(`auth login: OAuth access token was rejected and was not stored`):await Q(e,i.credential,`OAuth CLI access token stored and verified.`)}async function Oe(e){let{client:t,tokens:n}=e.credential;if(n.refresh_token===void 0)throw Error(`saved OAuth credential has no refresh token`);let r=await X(t);return await ge(y(t),{metadata:r,clientInformation:{client_id:w(t)},refreshToken:n.refresh_token,resource:g(t)})}function J(e){e.state===`available`&&e.provider===`file`&&T.write(re(e.keyringFailure??`unknown failure`))}async function Y(){let e=await l(te(s()),{method:`GET`,path:ee(`getAuthProviderCatalog`,{}),headers:{}},se);if(!e.ok)throw Error(`provider catalog request failed: ${ne(e.problem)}`);return e.data}async function X(e){let t=await I(y(e));if(t===void 0||t.issuer!==e.authorizationServer)throw Error(`OAuth authorization-server metadata issuer must match its configured server`);if(!t.response_types_supported.includes(`code`)||t.code_challenge_methods_supported?.includes(`S256`)!==!0)throw Error(`OAuth authorization-server metadata must advertise authorization-code and PKCE S256 support`);if(t.grant_types_supported?.includes(`urn:ietf:params:oauth:grant-type:device_code`)!==!0)throw Error(`OAuth authorization-server metadata must advertise the device authorization grant`);return _(t.authorization_endpoint,`authorization endpoint`,!0),V(t),_(t.token_endpoint,`token endpoint`,!0),t}async function ke(e,t){let n;try{n=ie(e,t)}catch(e){return{state:`failed`,summary:`OAuth token response is invalid — ${p(e,b(t))}`}}return await Z(n)}async function Z(e){let n;try{n=await i(e.tokens.access_token,g(e.client))}catch(n){return n instanceof t?{state:`rejected`}:{state:`failed`,summary:`OAuth access token could not be verified — ${p(n,b(e.tokens))}`}}return n===`forbidden`?{state:`failed`,summary:W}:n===null?{state:`rejected`}:{state:`accepted`,credential:e}}async function Q(e,t,n){try{let r=await m(e,t);return c(n,$(r))}catch(e){return r(`auth login: OAuth credential could not be durably stored — ${p(e,b(t.tokens))}`)}}function $(e){return{host:e.host,provider:e.provider,expiresAt:e.credential.expiresAt,client:e.credential.client}}export{Oe as i,Y as n,Ee as r,X as t};
|