@zibby/core 0.5.29 → 0.5.32
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/index.js +86 -86
- package/dist/package.json +1 -1
- package/dist/register-built-in-strategies.js +55 -55
- package/dist/strategies/claude-strategy.js +2 -2
- package/dist/strategies/codex-strategy.js +5 -5
- package/dist/strategies/index.js +54 -54
- package/dist/strategies/utils/usage.js +1 -0
- package/dist/utils/secure-git.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function l(n){if(!n||typeof n!="object")return null;let o=(...p)=>{for(let t of p){if(t==null||t==="")continue;let i=Number(t);if(Number.isFinite(i))return i}return null},u=o(n.input_tokens,n.inputTokens,n.prompt_tokens,n.promptTokens),e=o(n.output_tokens,n.outputTokens,n.completion_tokens,n.completionTokens);return u==null&&e==null?null:{input:u||0,output:e||0}}var s={normalizeUsage:l};export{s as default,l as normalizeUsage};
|
package/dist/utils/secure-git.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as E,readFileSync as _}from"node:fs";import{homedir as
|
|
1
|
+
import{existsSync as E,readFileSync as _}from"node:fs";import{homedir as y}from"node:os";import{join as x}from"node:path";var w=new Map,$={github:"GITHUB_TOKEN",gitlab:"GITLAB_TOKEN",sentry:"SENTRY_AUTH_TOKEN",slack:"SLACK_BOT_TOKEN"};function I(){let t=process.env.ZIBBY_SELF_HOST;return t!=null&&t!==""&&t!=="0"&&t.toLowerCase()!=="false"}function k(){if(process.env.PROJECT_API_TOKEN)return process.env.PROJECT_API_TOKEN;if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let t=x(y(),".zibby","config.json");return E(t)&&JSON.parse(_(t,"utf-8")).sessionToken||null}catch{return null}}function A(){return process.env.ZIBBY_ACCOUNT_API_URL?process.env.ZIBBY_ACCOUNT_API_URL.replace(/\/$/,""):(process.env.ZIBBY_ENV||"prod")==="local"?"http://localhost:3001":process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app"}async function b(t){if(I()){let a=$[t];if(a&&process.env[a])return{token:process.env[a]}}let e=Date.now(),n=w.get(t);if(n&&n.expiresAt>e)return n.data;let r=k();if(!r)throw new Error("No session token. Run `zibby login` first.");let c=`${A()}/integrations/token/${t}`,s=await fetch(c,{method:"GET",headers:{Authorization:`Bearer ${r}`}});if(!s.ok){let a=await s.text().catch(()=>"");throw s.status===404?new Error(`${t} is not connected. Connect it at https://studio.zibby.dev/integrations`):s.status===401||s.status===403?new Error("Session expired. Run `zibby login` to re-authenticate."):new Error(`Failed to resolve ${t} token (${s.status}): ${a}`)}let o=await s.json();if(!o||typeof o!="object")throw new Error(`Invalid response from ${t} token endpoint: expected object, got ${typeof o}`);if(t==="jira"){if(!o.token||typeof o.token!="string")throw new Error(`Invalid jira token response: token is ${typeof o.token}, expected string`);if(!o.cloudId)throw new Error("Invalid jira token response: missing cloudId")}else if(t==="github"&&(!o.token||typeof o.token!="string"))throw new Error(`Invalid github token response: token is ${typeof o.token}, expected string`);let f=((o.expiresInSec||3e3)-120)*1e3;return w.set(t,{data:o,expiresAt:e+f}),o}var K=Object.freeze(["github.com","gitlab.com"]);function m(t){try{return new URL(t).hostname.toLowerCase()}catch{return""}}function d(t){if(typeof t!="string"||t===""||/[\\\x00-\x20\x7f]/.test(t))return"";let e;try{e=new URL(t)}catch{return""}return e.protocol!=="https:"?"":e.hostname.toLowerCase()}function O(t=process.env){let e=t&&(t.GITLAB_URL||t.GITLAB_INSTANCE_URL)||"";return m(e)}function l(t={}){if(t.gitlabHost){let e=String(t.gitlabHost).trim().toLowerCase();return e?e.includes("://")?m(e):e.replace(/:\d+$/,""):""}return O()}function S(t,e={}){let n=d(t);if(!n)return!1;if(n==="github.com"||n==="gitlab.com")return!0;let r=l(e);return!!(r&&n===r)}function v(t,e={}){if(t==="github.com")return"github";if(t==="gitlab.com")return"gitlab";let n=l(e);return n&&t===n?"gitlab":null}function B(t,e,n={}){if(!t||!e)return t;let r=d(t);if(!r)return t;if(r==="github.com")return t.replace(/^https:\/\/(?:[^@/]+@)?github\.com(?=[:/]|$)/i,`https://x-access-token:${e}@github.com`);if(r==="gitlab.com")return t.replace(/^https:\/\/(?:[^@/]+@)?gitlab\.com(?=[:/]|$)/i,`https://oauth2:${e}@gitlab.com`);let c=l(n);if(c&&r===c){let s=c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(`^https:\\/\\/(?:[^@/]+@)?${s}(?=[:/]|$)`,"i");return t.replace(o,`https://oauth2:${e}@${c}`)}return t}function C(t){return t&&String(t).replace(/^(https:\/\/)[^@/]+@/i,"$1")}function N(t,e){let n=t==null?"":String(t);return e&&(n=n.split(e).join("***")),n=n.replace(/(https?:\/\/)(?:x-access-token|oauth2):[^@\s/]+@/gi,"$1"),n=n.replace(/(https?:\/\/)[^@\s/:]+:[^@\s/]+@/gi,"$1"),n}async function P(t,e,n){try{await t("git",["remote","set-url","origin",C(n)],e)}catch(r){console.warn(`\u26A0\uFE0F could not scrub token from origin remote (continuing): ${r?.message||r}`)}}async function G({run:t,repoPath:e,repoUrl:n,branch:r,token:c,resolveToken:s=b,gitlabHost:o}={}){if(typeof t!="function")throw new Error("securePush: `run` (a spawn wrapper resolving {code,stdout,stderr}) is required");if(!r)throw new Error("securePush: `branch` is required");let f=l({gitlabHost:o}),a=d(n),h=S(n,{gitlabHost:f}),u=c||"";if(!u&&h&&typeof s=="function"){let p=v(a,{gitlabHost:f});if(p)try{u=(await s(p))?.token||""}catch{}}else!u&&!h&&console.warn(`\u26A0\uFE0F push target host '${a||"(unparseable)"}' is not a trusted VCS host \u2014 refusing to mint a token`);let g=u&&h,T=g?B(n,u,{gitlabHost:f}):"origin",i=await t("git",["push",T,r],e);if(!i||i.code!==0){let p=N(i&&i.stderr||"",u);throw new Error(`git push failed (exit ${i?i.code:"?"}): ${String(p).slice(-500)}`)}return{code:i.code,stdout:i.stdout,stderr:i.stderr,pushedAuthed:!!g,target:g?"<authed>":"origin"}}export{K as TRUSTED_VCS_HOSTS,B as authedUrl,m as hostnameOf,S as isTrustedVcsHost,v as providerForHost,N as redactGitSecrets,d as safeVcsHostname,P as scrubRemoteToTokenless,G as securePush,O as selfHostGitlabHost,C as tokenlessUrl};
|