blink 1.1.36 → 1.1.37

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.
@@ -1 +0,0 @@
1
- import"./wrapper-DRdRnzOz.js";import"./auth-B9qq4cSL.js";import{WorkspaceConnect as e,connect as t}from"./connect-CxdtUbca.js";export{e as WorkspaceConnect,t as default};
@@ -1 +0,0 @@
1
- import{loginIfNeeded as e}from"./auth-B9qq4cSL.js";async function t(t){await e(t)}export{t as default};
@@ -1 +0,0 @@
1
- import{deleteAuthToken as e}from"./auth-B9qq4cSL.js";function t(){e(),console.log(`Logged out successfully.`)}export{t as default};
@@ -1,9 +0,0 @@
1
- import{Client as e,Ie as t,M as n,Se as r,Y as i,ge as a,getHost as o,he as s,loginIfNeeded as c,openUrl as l,pD as u,source_default as d,ye as f}from"./auth-B9qq4cSL.js";import{createDevhookID as p,createGithubApp as m,createSlackApp as h,getDevhookID as g,hasDevhook as _}from"./create-github-app-BeSDE8GT.js";import{_usingCtx as v}from"./usingCtx-CCxav2be.js";import{basename as y,join as b}from"node:path";import{access as x,readFile as S,readdir as C,writeFile as w}from"node:fs/promises";import T from"node:util";import E from"node:crypto";async function D(e){try{let t=await(await fetch(`https://slack.com/api/auth.test`,{method:`POST`,headers:{Authorization:`Bearer ${e}`,"Content-Type":`application/json`}})).json();return t.ok?{valid:!0,botName:t.user}:{valid:!1,error:t.error||`Invalid bot token`}}catch(e){return{valid:!1,error:`Failed to verify credentials: ${e}`}}}function O(e,t,n,r){let i=Math.floor(Date.now()/1e3),a=parseInt(t,10);if(Math.abs(i-a)>300)return!1;let o=E.createHmac(`sha256`,e),s=`v0:${t}:${n}`;o.update(s);let c=`v0=${o.digest(`hex`)}`;return E.timingSafeEqual(Buffer.from(c),Buffer.from(r))}const k=e=>{if(!(typeof e==`object`&&e))throw Error(`Unable to make value disposable, it's not an object`);if(Symbol.dispose in e)return e;if(`dispose`in e&&typeof e.dispose==`function`){let t=e;return t[Symbol.dispose]=()=>t.dispose(),t}throw Error(`Unable to make value disposable`)};async function A(e,t,n){let r=``;try{r=await S(e,`utf-8`)}catch{}r=r.replace(/^(SLACK_BOT_TOKEN=.*)/gm,`# $1`).replace(/^(SLACK_SIGNING_SECRET=.*)/gm,`# $1`),r=`${r.trimEnd()}\n`;let i=[];i.push(``),i.push(`# Slack App credentials`),t&&i.push(`SLACK_BOT_TOKEN=${t}`),n&&i.push(`SLACK_SIGNING_SECRET=${n}`),i.push(``),await w(e,r+i.join(`
2
- `),`utf-8`)}async function j(e){let t=await C(e);for(let[e,n]of[[`bun`,`bun.lock`],[`npm`,`package-lock.json`],[`pnpm`,`pnpm-lock.yaml`],[`yarn`,`yarn.lock`]])for(let r of t)if(r.includes(n))return e;return`npm`}async function M(t,m){try{var S=v();let C=m?._deps?.authenticate??c,w=m?._deps?.getHost??o;await C();let E=m?.name||y(t).replace(/[^a-zA-Z0-9]/g,`-`),M=m?.packageManager||await j(t),N=b(t,`.env.local`);try{await x(N)}catch{n.error(`No .env.local file found in this directory. Please run this command from a Blink agent directory.`),r(`Slack app setup cancelled`);return}let P=await s({message:`What should your Slack app be called? This will be the name displayed in Slack. You can change it later.`,placeholder:E,defaultValue:E,validate:e=>{if(!e||e.trim().length===0)return`App name cannot be empty`}});if(u(P))return;let F=_(t)?g(t):p(t),I=`https://${F}.blink.host`;if(!F)throw Error(`Failed to obtain devhook ID`);n.info(`Starting webhook listener...`);let L=``,R=``,z=!1,B=``,V=``,H=!1,U,W=w();if(!W)throw Error("No Blink host configured. Set the BLINK_HOST environment variable or run `blink login <host>`.");let G=m?._deps?.client??new e({baseURL:W}),K=()=>{},q=e=>{},J=new Promise((e,t)=>{K=e,q=t}),ee=G.devhook.listen({id:F,onRequest:async e=>{let t=await e.text(),r;try{r=JSON.parse(t)}catch{return new Response(`Invalid JSON`,{status:400})}if(r.type===`url_verification`)return n.info(`✓ Webhook challenge received`),new Response(JSON.stringify({challenge:r.challenge}),{headers:{"Content-Type":`application/json`}});if(L){let n=e.headers.get(`x-slack-signature`),i=e.headers.get(`x-slack-request-timestamp`);if(!n||!i)return new Response(`Missing signature`,{status:401});if(!O(L,i,t,n))return H=!0,r.event?.type===`message`&&r.event.channel_type===`im`&&!r.event.bot_id&&(U=r.event.channel),new Response(`Invalid signature`,{status:401})}return r.event?.type===`message`&&r.event.channel_type===`im`&&!r.event.bot_id&&(z=!0,B=r.event.channel??``,V=r.event.ts??``),new Response(`OK`)},onConnect:()=>{K()},onDisconnect:()=>{},onError:e=>{q(e)}});S.u(k(ee));let te={display_information:{name:P.toString(),description:`A Blink agent for Slack`,background_color:`#4A154B`},features:{bot_user:{display_name:P.toString(),always_online:!0},app_home:{home_tab_enabled:!1,messages_tab_enabled:!0,messages_tab_read_only_enabled:!1},assistant_view:{assistant_description:`A helpful assistant powered by Blink`}},oauth_config:{scopes:{bot:[`app_mentions:read`,`assistant:write`,`reactions:write`,`reactions:read`,`channels:history`,`chat:write`,`groups:history`,`groups:read`,`files:read`,`im:history`,`im:read`,`im:write`,`mpim:history`,`mpim:read`,`users:read`,`links:read`,`commands`]}},settings:{event_subscriptions:{request_url:I,bot_events:[`app_mention`,`message.channels`,`message.groups`,`message.im`,`reaction_added`,`reaction_removed`,`assistant_thread_started`,`member_joined_channel`]},interactivity:{is_enabled:!0,request_url:I},token_rotation_enabled:!1,org_deploy_enabled:!1,socket_mode_enabled:!1}},Y=h(te);n.info(`Please visit this URL to create your Slack app and return here after finishing:\n\n${d.gray(Y)}\n`);let X=await f({message:`Open this URL in your browser automatically?`,initialValue:!0});if(u(X)){n.warn(`Skipping Slack app setup`);return}X&&await l(Y,`Could not open the browser. Please visit the URL manually.`);let Z=await s({message:`After creating the app, paste the App ID from the "Basic Information" page:`,placeholder:`A01234567AB`,validate:e=>{if(!e||e.trim().length===0)return`App ID is required`}});if(u(Z)){n.warn(`Skipping Slack app setup`);return}if(L=await a({message:`Paste your Signing Secret from the same page:`,validate:e=>{if(!e||e.trim().length===0)return`Signing secret is required`}}),u(L)){n.warn(`Skipping Slack app setup`);return}let Q=!1;for(;!Q;){if(R=await a({message:`Install your app and paste your Bot Token from ${d.cyan(`https://api.slack.com/apps/${Z}/install-on-team`)}`,validate:e=>{if(!e||e.trim().length===0)return`Bot token is required`}}),u(R)){n.warn(`Skipping Slack app setup`);return}let e=i();e.start(`Verifying bot token...`);let t=await D(R);if(t.valid)e.stop(`✓ Bot token verified!`),Q=!0;else{e.stop(`✗ Failed to verify bot token: ${t.error}`);let r=await f({message:`Would you like to try again?`,initialValue:!0});if(u(r)||!r){n.warn(`Skipping Slack app setup`);return}}}await A(N,R,L),n.success(`Credentials saved to .env.local`),await J;let $=i();$.start(`Try sending a DM to the bot on Slack - it's ${d.bold(d.cyan(P))} in the search bar.`);let ne={bun:`bun run dev`,npm:`npm run dev`,pnpm:`pnpm run dev`,yarn:`yarn dev`}[M];for(;!z;){if(H){if($.stop(`✗ Invalid signing secret detected`),U&&R)try{await fetch(`https://slack.com/api/chat.postMessage`,{method:`POST`,headers:{Authorization:`Bearer ${R}`,"Content-Type":`application/json`},body:JSON.stringify({channel:U,text:`⚠️ There seems to be a problem with the signing secret. Please check the CLI for instructions on how to fix it.`})})}catch{}let e=await a({message:`The signing secret appears to be incorrect. Please paste the correct Signing Secret from ${d.cyan(`https://api.slack.com/apps/${Z}/general`)}`,validate:e=>{if(!e||e.trim().length===0)return`Signing secret is required`}});if(u(e)){n.warn(`Skipping Slack app setup`);return}L=e,H=!1,U=void 0,await A(N,void 0,L),$.start(`Please try sending a DM to the bot again on Slack...`)}await new Promise(e=>setTimeout(e,500))}$.stop(d.green(`✓ DM received!`));try{await fetch(`https://slack.com/api/chat.postMessage`,{method:`POST`,headers:{Authorization:`Bearer ${R}`,"Content-Type":`application/json`},body:JSON.stringify({channel:B,thread_ts:V,text:`Congrats, your app is now installed and ready to use! Run \`${ne}\` to use your agent.`})})}catch(e){n.warn(`Could not send message to Slack: ${T.inspect(e)}`)}n.success(`Slack app setup complete!`)}catch(e){S.e=e}finally{S.d()}}async function N(e){e||=process.cwd(),t(`Setting up Slack app`),await M(e),process.exit(0)}async function P(e,t){let n=``;try{n=await S(e,`utf-8`)}catch{}n=n.replace(/^(GITHUB_APP_ID=.*)/gm,`# $1`).replace(/^(GITHUB_CLIENT_ID=.*)/gm,`# $1`).replace(/^(GITHUB_CLIENT_SECRET=.*)/gm,`# $1`).replace(/^(GITHUB_WEBHOOK_SECRET=.*)/gm,`# $1`).replace(/^(GITHUB_PRIVATE_KEY=.*)/gm,`# $1`),n=`${n.trimEnd()}\n`;let r=`
3
- # GitHub App credentials
4
- GITHUB_APP_ID=${t.id}
5
- GITHUB_CLIENT_ID=${t.client_id}
6
- GITHUB_CLIENT_SECRET=${t.client_secret}
7
- GITHUB_WEBHOOK_SECRET=${t.webhook_secret}
8
- GITHUB_PRIVATE_KEY="${btoa(t.pem)}"
9
- `;await w(e,n+r,`utf-8`)}async function F(e,t){let a=t?._deps?.authenticate??c,h=t?._deps?.getHost??o;await a();let v=t?.name||y(e).replace(/[^a-zA-Z0-9]/g,`-`),S=b(e,`.env.local`);try{await x(S)}catch{n.error(`No .env.local file found in this directory. Please run this command from a Blink agent directory.`),r(`GitHub App setup cancelled`);return}let C=await s({message:`What should your GitHub App be called? This will be the name displayed on GitHub. You can change it later.`,placeholder:v,defaultValue:v,validate:e=>{if(!e||e.trim().length===0)return`App name cannot be empty`}});if(u(C))return;let w=await s({message:`Enter a GitHub organization name to create the app under, or leave blank for a personal app:`,placeholder:`Leave blank for personal app`,defaultValue:``});if(u(w))return;let T=w&&w.trim().length>0?w.trim():void 0,E=_(e)?g(e):p(e);if(!E)throw Error(`Failed to obtain devhook ID`);let D=`https://${E}.blink.host`,O=h();if(!O)throw Error(`No Blink host configured.`);let k={name:C.toString(),url:O,description:`A Blink agent for GitHub`,public:!1,hook_attributes:{url:D,active:!0},default_events:[`issues`,`issue_comment`,`pull_request`,`pull_request_review`,`pull_request_review_comment`,`push`],default_permissions:{contents:`write`,issues:`write`,pull_requests:`write`,metadata:`read`}},A,j,M=new Promise((e,t)=>{A=e,j=t}),N=i(),F=await m(k,T,async(e,t)=>{if(e){j(e);return}t&&A(t)});n.info(`Please visit this URL to create your GitHub App and return here after finishing:\n\n${d.gray(F)}\n`);let I=await f({message:`Open this URL in your browser automatically?`,initialValue:!0});if(u(I)){n.warn(`Skipping GitHub App setup`);return}I&&await l(F,`Could not open the browser. Please visit the URL manually.`),N.start(`Waiting for GitHub App creation to complete...`);let L;try{L=await M}catch(e){N.stop(`Failed to create GitHub App: ${e instanceof Error?e.message:String(e)}`);return}N.stop(d.green(`✓ GitHub App "${L.name}" created!`)),await P(S,L),n.success(`Credentials saved to .env.local`),n.info(`\nYour GitHub App is available at: ${d.cyan(L.html_url)}`),n.info(`\nTo install the app on repositories, visit: ${d.cyan(`${L.html_url}/installations/new`)}`),n.success(`GitHub App setup complete!`)}async function I(e){e||=process.cwd(),t(`Setting up GitHub App`),await F(e),process.exit(0)}export{F as setupGithubApp,I as setupGithubAppCommand,M as setupSlackApp,N as setupSlackAppCommand};