@negoziator/ai-commit 2.41.0 → 2.42.0
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/{anthropic-Cz8g82uN.mjs → anthropic-BtdmHzxH.mjs} +1 -1
- package/dist/{azure-openai-BQW1dfQd.mjs → azure-openai-BhX9jBX3.mjs} +1 -1
- package/dist/{cli-BIq6m4DC.mjs → cli-Ci9E6K8n.mjs} +2 -2
- package/dist/cli.mjs +1 -1
- package/dist/{custom-BiOgkvpn.mjs → custom-CkAl8jGP.mjs} +1 -1
- package/dist/{ollama-OBZsoRDe.mjs → ollama-BN4LWfT0.mjs} +1 -1
- package/dist/{openai-D_E0o7oL.mjs → openai-DdXQVga0.mjs} +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var y=Object.defineProperty;var u=(f,t)=>y(f,"name",{value:t,configurable:!0});import l from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as A,g as C}from"./prompt-BGI0PV0L.mjs";import{K as a}from"./cli-
|
|
1
|
+
var y=Object.defineProperty;var u=(f,t)=>y(f,"name",{value:t,configurable:!0});import l from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as A,g as C}from"./prompt-BGI0PV0L.mjs";import{K as a}from"./cli-Ci9E6K8n.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const h=class h extends A{get name(){return"anthropic"}validateConfig(){const{apiKey:t}=this.config;if(!t)throw new a("Please set your Anthropic API key via `aicommit config set ANTHROPIC_KEY=<your token>`\nGet your API key from: https://console.anthropic.com/");if(!t.startsWith("sk-ant-"))throw new a('Invalid Anthropic API key: Must start with "sk-ant-"')}async generateCommitMessage(t){try{const i=C(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig),o=[{role:"user",content:t.diff}],e=[];for(let s=0;s<t.completions;s++){const r=(await this.createMessage(i,o)).content[0]?.text;r&&e.push(this.sanitizeMessage(r))}return{messages:this.deduplicateMessages(e)}}catch(i){const o=i;throw o.code==="ENOTFOUND"?new a(`Error connecting to ${o.hostname} (${o.syscall}). Are you connected to the internet?`):o}}async createMessage(t,i){const o={model:this.config.model,max_tokens:this.config.maxCompletionTokens,temperature:this.config.temperature,system:t,messages:i},{response:e,data:n}=await this.httpsPost("api.anthropic.com","/v1/messages",{"x-api-key":this.config.apiKey,"anthropic-version":"2023-06-01"},o);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let s=`Anthropic API Error: ${e.statusCode} - ${e.statusMessage}`;throw n&&(s+=`
|
|
2
2
|
|
|
3
3
|
${n}`),e.statusCode===500&&(s+=`
|
|
4
4
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var l=Object.defineProperty;var f=(u,t)=>l(u,"name",{value:t,configurable:!0});import y from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as C,g as A}from"./prompt-BGI0PV0L.mjs";import{K as a}from"./cli-
|
|
1
|
+
var l=Object.defineProperty;var f=(u,t)=>l(u,"name",{value:t,configurable:!0});import y from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as C,g as A}from"./prompt-BGI0PV0L.mjs";import{K as a}from"./cli-Ci9E6K8n.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const g=class g extends C{get name(){return"azure-openai"}validateConfig(){const{apiKey:t,endpoint:i}=this.config;if(!t)throw new a("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!i)throw new a("Please set your Azure OpenAI endpoint via `aicommit config set AZURE_ENDPOINT=<your endpoint>`")}async generateCommitMessage(t){try{const i=await this.createChatCompletion({model:this.config.model,messages:[{role:"system",content:A(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],temperature:this.config.temperature,top_p:1,frequency_penalty:0,presence_penalty:0,max_tokens:this.config.maxCompletionTokens,n:t.completions});return{messages:this.deduplicateMessages(i.choices.filter(r=>r.message?.content).map(r=>this.sanitizeMessage(r.message.content)))}}catch(i){const e=i;throw e.code==="ENOTFOUND"?new a(`Error connecting to ${e.hostname} (${e.syscall}). Are you connected to the internet?`):e}}async createChatCompletion(t){const e=new URL(this.config.endpoint).hostname,m=`/openai/deployments/${this.config.deploymentName||this.config.model}/chat/completions?api-version=2024-02-01`,{response:n,data:s}=await this.httpsPost(e,m,{"api-key":this.config.apiKey},t);if(!n.statusCode||n.statusCode<200||n.statusCode>299){let o=`Azure OpenAI API Error: ${n.statusCode} - ${n.statusMessage}`;throw s&&(o+=`
|
|
2
2
|
|
|
3
3
|
${s}`),new a(o)}return JSON.parse(s)}async httpsPost(t,i,e,r){return new Promise((m,n)=>{const s=JSON.stringify(r),o=y.request({hostname:t,path:i,method:"POST",headers:{...e,"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)},timeout:this.config.timeout,agent:this.config.proxy?new w.HttpsProxyAgent(this.config.proxy):void 0},p=>{const h=[];p.on("data",d=>h.push(d)),p.on("end",()=>{m({request:o,response:p,data:Buffer.concat(h).toString()})})});o.on("error",n),o.on("timeout",()=>{o.destroy(),n(new a(`Time out error: request took over ${this.config.timeout}ms. Try increasing the \`timeout\` config`))}),o.write(s),o.end()})}sanitizeMessage(t){return t.trim().replace(/[\n\r]/g,"").replace(/(\w)\.$/,"$1")}deduplicateMessages(t){return Array.from(new Set(t))}};f(g,"AzureOpenAIProvider");let c=g;export{c as default};
|
|
@@ -19,7 +19,7 @@ var zc=Object.defineProperty;var o=(e,t)=>zc(e,"name",{value:t,configurable:!0})
|
|
|
19
19
|
`:"")+(n?this.indentText({text:this.render(n),spaces:r}):"")}
|
|
20
20
|
`}table({tableData:t,tableOptions:n,tableBreakpoints:r}){return Yl(t.map(i=>i.map(s=>this.render(s))),r?Jl(r):n)}flagParameter(t){return t===Boolean?"":t===String?"<string>":t===Number?"<number>":Array.isArray(t)?this.flagParameter(t[0]):"<value>"}flagOperator(t){return" "}flagName(t){const{flag:n,flagFormatted:r,aliasesEnabled:i,aliasFormatted:s}=t;let a="";if(s?a+=`${s}, `:i&&(a+=" "),a+=r,"placeholder"in n&&typeof n.placeholder=="string")a+=`${this.flagOperator(t)}${n.placeholder}`;else{const u=this.flagParameter("type"in n?n.type:n);u&&(a+=`${this.flagOperator(t)}${u}`)}return a}flagDefault(t){return JSON.stringify(t)}flagDescription({flag:t}){let n="description"in t?t.description??"":"";if("default"in t){let{default:r}=t;typeof r=="function"&&(r=r()),r&&(n+=` (default: ${this.flagDefault(r)})`)}return n}render(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(n=>this.render(n)).join(`
|
|
21
21
|
`);if("type"in t&&this[t.type]){const n=this[t.type];if(typeof n=="function")return n.call(this,t.data)}throw new Error(`Invalid node type: ${JSON.stringify(t)}`)}},o(We,"_ne"),We);T(Pi,"Renderers");let ad=Pi;const bn=T(e=>e.length>0&&!e.includes(" "),"isValidScriptName"),{stringify:Q}=JSON,ud=/[|\\{}()[\]^$+*?.]/;function Cn(e){const t=[];let n,r;for(const i of e){if(r)throw new Error(`Invalid parameter: Spread parameter ${Q(r)} must be last`);const s=i[0],a=i.at(-1);let u;if(s==="<"&&a===">"&&(u=!0,n))throw new Error(`Invalid parameter: Required parameter ${Q(i)} cannot come after optional parameter ${Q(n)}`);if(s==="["&&a==="]"&&(u=!1,n=i),u===void 0)throw new Error(`Invalid parameter: ${Q(i)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let c=i.slice(1,-1);const d=c.slice(-3)==="...";d&&(r=i,c=c.slice(0,-3));const l=c.match(ud);if(l)throw new Error(`Invalid parameter: ${Q(i)}. Invalid character found ${Q(l[0])}`);t.push({name:c,required:u,spread:d})}return t}o(Cn,"P$1"),T(Cn,"parseParameters");function Sn(e,t,n,r){for(let i=0;i<t.length;i+=1){const{name:s,required:a,spread:u}=t[i],c=nd(s);if(c in e)throw new Error(`Invalid parameter: ${Q(s)} is used more than once.`);const d=u?n.slice(i):n[i];if(u&&(i=t.length),a&&(!d||u&&d.length===0))return console.error(`Error: Missing required parameter ${Q(s)}
|
|
22
|
-
`),r(),process.exit(1);e[c]=d}}o(Sn,"S$1"),T(Sn,"mapParametersToArguments");function Li(e){return e!==!1}o(Li,"se"),T(Li,"helpEnabled");const cd=T(e=>{const t=[];for(const[n,r]of Object.entries(e))if(t.push(n),r&&typeof r=="object"&&"alias"in r){const{alias:i}=r;typeof i=="string"&&i?t.push(i):Array.isArray(i)&&t.push(...i.filter(Boolean))}return t},"getKnownFlagNames"),ld=T((e,t)=>{if(e.length<3||t.length===0)return;const n=td(e,t);return vi(e,n)<=2?n:void 0},"findClosestFlag"),dd=T((e,t)=>{const n=Object.keys(e);if(n.length!==0){for(const r of n){const i=ld(r,t),s=i?` (Did you mean --${i}?)`:"";console.error(`Error: Unknown flag: --${r}.${s}`)}process.exit(1)}},"handleUnknownFlags");function vn(e,t,n,r){const i={...t.flags},s=t.version&&!("version"in i);s&&(i.version={type:Boolean,description:"Show version"});const{help:a}=t,u=Li(a);u&&!("help"in i)&&(i.help={type:Boolean,alias:"h",description:"Show help"});const c=Al(i,r,{ignore:t.ignoreArgv}),d=T(()=>{console.log(t.version)},"showVersion");if(s&&c.flags.version===!0)return d(),process.exit(0);const l=new ad,f=u&&a?.render?a.render:m=>l.render(m),h=T(m=>{const g=id({...t,...m?{help:m}:{},flags:i});console.log(f(g,l))},"showHelp");if(u&&c.flags.help===!0)return h(),process.exit(0);if((t.strictFlags??t.parent?.strictFlags)&&dd(c.unknownFlags,cd(i)),t.parameters){let{parameters:m}=t,g=c._;const F=m.indexOf("--"),w=m.slice(F+1),E=Object.create(null);let y=[];F>-1&&w.length>0&&(m=m.slice(0,F),y=c._["--"],g=g.slice(0,-y.length||void 0)),Sn(E,Cn(m),g,h),F>-1&&w.length>0&&Sn(E,Cn(w),y,h),Object.assign(c._,E)}const D={...c,showVersion:d,showHelp:h},p={command:e,...D};if(typeof n=="function"){const m=n(D);if(m&&"then"in m)return Object.assign(Promise.resolve(m),p)}return p}o(vn,"I$1"),T(vn,"cliBase");function ki(e,t){const n=new Map;for(const r of t){const i=[r.options.name],{alias:s}=r.options;s&&(Array.isArray(s)?i.push(...s):i.push(s));for(const a of i){if(n.has(a))throw new Error(`Duplicate command name found: ${Q(a)}`);n.set(a,r)}}return n.get(e)}o(ki,"ce$1"),T(ki,"getCommand");function Ni(e,t,n=process.argv.slice(2)){if(!e)throw new Error("Options is required");if("name"in e&&(!e.name||!bn(e.name)))throw new Error(`Invalid script name: ${Q(e.name)}`);const r=n[0];if(e.commands&&r&&bn(r)){const i=ki(r,e.commands);if(i)return vn(i.options.name,{...i.options,parent:e},i.callback,n.slice(1))}return vn(void 0,e,t,n)}o(Ni,"fe"),T(Ni,"cli");function $n(e,t){if(!e)throw new Error("Command options are required");const{name:n}=e;if(n===void 0)throw new Error("Command name is required");if(!bn(n))throw new Error(`Invalid command name ${JSON.stringify(n)}. Command names must be one word.`);return{options:e,callback:t}}o($n,"de$1"),T($n,"command");var fd="2.
|
|
22
|
+
`),r(),process.exit(1);e[c]=d}}o(Sn,"S$1"),T(Sn,"mapParametersToArguments");function Li(e){return e!==!1}o(Li,"se"),T(Li,"helpEnabled");const cd=T(e=>{const t=[];for(const[n,r]of Object.entries(e))if(t.push(n),r&&typeof r=="object"&&"alias"in r){const{alias:i}=r;typeof i=="string"&&i?t.push(i):Array.isArray(i)&&t.push(...i.filter(Boolean))}return t},"getKnownFlagNames"),ld=T((e,t)=>{if(e.length<3||t.length===0)return;const n=td(e,t);return vi(e,n)<=2?n:void 0},"findClosestFlag"),dd=T((e,t)=>{const n=Object.keys(e);if(n.length!==0){for(const r of n){const i=ld(r,t),s=i?` (Did you mean --${i}?)`:"";console.error(`Error: Unknown flag: --${r}.${s}`)}process.exit(1)}},"handleUnknownFlags");function vn(e,t,n,r){const i={...t.flags},s=t.version&&!("version"in i);s&&(i.version={type:Boolean,description:"Show version"});const{help:a}=t,u=Li(a);u&&!("help"in i)&&(i.help={type:Boolean,alias:"h",description:"Show help"});const c=Al(i,r,{ignore:t.ignoreArgv}),d=T(()=>{console.log(t.version)},"showVersion");if(s&&c.flags.version===!0)return d(),process.exit(0);const l=new ad,f=u&&a?.render?a.render:m=>l.render(m),h=T(m=>{const g=id({...t,...m?{help:m}:{},flags:i});console.log(f(g,l))},"showHelp");if(u&&c.flags.help===!0)return h(),process.exit(0);if((t.strictFlags??t.parent?.strictFlags)&&dd(c.unknownFlags,cd(i)),t.parameters){let{parameters:m}=t,g=c._;const F=m.indexOf("--"),w=m.slice(F+1),E=Object.create(null);let y=[];F>-1&&w.length>0&&(m=m.slice(0,F),y=c._["--"],g=g.slice(0,-y.length||void 0)),Sn(E,Cn(m),g,h),F>-1&&w.length>0&&Sn(E,Cn(w),y,h),Object.assign(c._,E)}const D={...c,showVersion:d,showHelp:h},p={command:e,...D};if(typeof n=="function"){const m=n(D);if(m&&"then"in m)return Object.assign(Promise.resolve(m),p)}return p}o(vn,"I$1"),T(vn,"cliBase");function ki(e,t){const n=new Map;for(const r of t){const i=[r.options.name],{alias:s}=r.options;s&&(Array.isArray(s)?i.push(...s):i.push(s));for(const a of i){if(n.has(a))throw new Error(`Duplicate command name found: ${Q(a)}`);n.set(a,r)}}return n.get(e)}o(ki,"ce$1"),T(ki,"getCommand");function Ni(e,t,n=process.argv.slice(2)){if(!e)throw new Error("Options is required");if("name"in e&&(!e.name||!bn(e.name)))throw new Error(`Invalid script name: ${Q(e.name)}`);const r=n[0];if(e.commands&&r&&bn(r)){const i=ki(r,e.commands);if(i)return vn(i.options.name,{...i.options,parent:e},i.callback,n.slice(1))}return vn(void 0,e,t,n)}o(Ni,"fe"),T(Ni,"cli");function $n(e,t){if(!e)throw new Error("Command options are required");const{name:n}=e;if(n===void 0)throw new Error("Command name is required");if(!bn(n))throw new Error(`Invalid command name ${JSON.stringify(n)}. Command names must be one word.`);return{options:e,callback:t}}o($n,"de$1"),T($n,"command");var fd="2.42.0",hd="Writes your git commit messages for you with AI",An={version:fd,description:hd};function H(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}o(H,"isPlainObject");const Bn=o((e,t)=>{const n=Ui(pd(e));if(typeof n!="string")throw new TypeError(`${t} must be a string or a file URL: ${n}.`);return n},"safeNormalizeFileUrl"),pd=o(e=>ji(e)?e.toString():e,"normalizeDenoExecPath"),ji=o(e=>typeof e!="string"&&e&&Object.getPrototypeOf(e)===String.prototype,"isDenoExecPath"),Ui=o(e=>e instanceof URL?No(e):e,"normalizeFileUrl"),Wi=o((e,t=[],n={})=>{const r=Bn(e,"First argument"),[i,s]=H(t)?[[],t]:[t,n];if(!Array.isArray(i))throw new TypeError(`Second argument must be either an array of arguments or an options object: ${i}`);if(i.some(c=>typeof c=="object"&&c!==null))throw new TypeError(`Second argument must be an array of strings: ${i}`);const a=i.map(String),u=a.find(c=>c.includes("\0"));if(u!==void 0)throw new TypeError(`Arguments cannot contain null bytes ("\\0"): ${u}`);if(!H(s))throw new TypeError(`Last argument must be an options object: ${s}`);return[r,a,s]},"normalizeParameters"),{toString:Gi}=Object.prototype,Dd=o(e=>Gi.call(e)==="[object ArrayBuffer]","isArrayBuffer"),J=o(e=>Gi.call(e)==="[object Uint8Array]","isUint8Array"),Ve=o(e=>new Uint8Array(e.buffer,e.byteOffset,e.byteLength),"bufferToUint8Array"),md=new TextEncoder,zi=o(e=>md.encode(e),"stringToUint8Array"),gd=new TextDecoder,Vi=o(e=>gd.decode(e),"uint8ArrayToString"),Fd=o((e,t)=>wd(e,t).join(""),"joinToString"),wd=o((e,t)=>{if(t==="utf8"&&e.every(s=>typeof s=="string"))return e;const n=new Uo(t),r=e.map(s=>typeof s=="string"?zi(s):s).map(s=>n.write(s)),i=n.end();return i===""?r:[...r,i]},"uint8ArraysToStrings"),Tn=o(e=>e.length===1&&J(e[0])?e[0]:qi(yd(e)),"joinToUint8Array"),yd=o(e=>e.map(t=>typeof t=="string"?zi(t):t),"stringsToUint8Arrays"),qi=o(e=>{const t=new Uint8Array(Ed(e));let n=0;for(const r of e)t.set(r,n),n+=r.length;return t},"concatUint8Arrays"),Ed=o(e=>{let t=0;for(const n of e)t+=n.length;return t},"getJoinLength"),bd=o(e=>Array.isArray(e)&&Array.isArray(e.raw),"isTemplateString"),Cd=o((e,t)=>{let n=[];for(const[s,a]of e.entries())n=Sd({templates:e,expressions:t,tokens:n,index:s,template:a});if(n.length===0)throw new TypeError("Template script must not be empty");const[r,...i]=n;return[r,i,{}]},"parseTemplates"),Sd=o(({templates:e,expressions:t,tokens:n,index:r,template:i})=>{if(i===void 0)throw new TypeError(`Invalid backslash sequence: ${e.raw[r]}`);const{nextTokens:s,leadingWhitespaces:a,trailingWhitespaces:u}=vd(i,e.raw[r]),c=Yi(n,s,a);if(r===t.length)return c;const d=t[r],l=Array.isArray(d)?d.map(f=>Hi(f)):[Hi(d)];return Yi(c,l,u)},"parseTemplate"),vd=o((e,t)=>{if(t.length===0)return{nextTokens:[],leadingWhitespaces:!1,trailingWhitespaces:!1};const n=[];let r=0;const i=Ki.has(t[0]);for(let a=0,u=0;a<e.length;a+=1,u+=1){const c=t[u];if(Ki.has(c))r!==a&&n.push(e.slice(r,a)),r=a+1;else if(c==="\\"){const d=t[u+1];d===`
|
|
23
23
|
`?(a-=1,u+=1):d==="u"&&t[u+2]==="{"?u=t.indexOf("}",u+3):u+=$d[d]??1}}const s=r===e.length;return s||n.push(e.slice(r)),{nextTokens:n,leadingWhitespaces:i,trailingWhitespaces:s}},"splitByWhitespaces"),Ki=new Set([" "," ","\r",`
|
|
24
24
|
`]),$d={x:3,u:5},Yi=o((e,t,n)=>n||e.length===0||t.length===0?[...e,...t]:[...e.slice(0,-1),`${e.at(-1)}${t[0]}`,...t.slice(1)],"concatTokens"),Hi=o(e=>{const t=typeof e;if(t==="string")return e;if(t==="number")return String(e);if(H(e)&&("stdout"in e||"isMaxBuffer"in e))return Ad(e);throw e instanceof jo||Object.prototype.toString.call(e)==="[object Promise]"?new TypeError("Unexpected subprocess in template expression. Please use ${await subprocess} instead of ${subprocess}."):new TypeError(`Unexpected "${t}" in template expression`)},"parseExpression"),Ad=o(({stdout:e})=>{if(typeof e=="string")return e;if(J(e))return Vi(e);throw e===void 0?new TypeError(`Missing result.stdout in template expression. This is probably due to the previous subprocess' "stdout" option.`):new TypeError(`Unexpected "${typeof e}" stdout in template expression`)},"getSubprocessResult"),ge=o(e=>xn.includes(e),"isStandardStream"),xn=[x.stdin,x.stdout,x.stderr],ee=["stdin","stdout","stderr"],Zi=o(e=>ee[e]??`stdio[${e}]`,"getStreamName"),Bd=o(e=>{const t={...e};for(const n of es)t[n]=Ji(e,n);return t},"normalizeFdSpecificOptions"),Ji=o((e,t)=>{const n=Array.from({length:Td(e)+1}),r=xd(e[t],n,t);return _d(r,t)},"normalizeFdSpecificOption"),Td=o(({stdio:e})=>Array.isArray(e)?Math.max(e.length,ee.length):ee.length,"getStdioLength"),xd=o((e,t,n)=>H(e)?Od(e,t,n):t.fill(e),"normalizeFdSpecificValue"),Od=o((e,t,n)=>{for(const r of Object.keys(e).sort(Id))for(const i of Md(r,n,t))t[i]=e[r];return t},"normalizeOptionObject"),Id=o((e,t)=>Xi(e)<Xi(t)?1:-1,"compareFdName"),Xi=o(e=>e==="stdout"||e==="stderr"?0:e==="all"?2:1,"getFdNameOrder"),Md=o((e,t,n)=>{if(e==="ipc")return[n.length-1];const r=Qi(e);if(r===void 0||r===0)throw new TypeError(`"${t}.${e}" is invalid.
|
|
25
25
|
It must be "${t}.stdout", "${t}.stderr", "${t}.all", "${t}.ipc", or "${t}.fd3", "${t}.fd4" (and so on).`);if(r>=n.length)throw new TypeError(`"${t}.${e}" is invalid: that file descriptor does not exist.
|
|
@@ -119,7 +119,7 @@ ${go}Please open a Bug report with the information above:`),console.error(`${go}
|
|
|
119
119
|
`),diff:r}},"getStagedDiff"),Wg=o(e=>`Detected ${e.length.toLocaleString()} staged file${e.length>1?"s":""}`,"getDetectedMessage");var yo,Bc;function Gg(){if(Bc)return yo;Bc=1;const{hasOwnProperty:e}=Object.prototype,t=o((u,c={})=>{typeof c=="string"&&(c={section:c}),c.align=c.align===!0,c.newline=c.newline===!0,c.sort=c.sort===!0,c.whitespace=c.whitespace===!0||c.align===!0,c.platform=c.platform||typeof process<"u"&&process.platform,c.bracketedArray=c.bracketedArray!==!1;const d=c.platform==="win32"?`\r
|
|
120
120
|
`:`
|
|
121
121
|
`,l=c.whitespace?" = ":"=",f=[],h=c.sort?Object.keys(u).sort():Object.keys(u);let D=0;c.align&&(D=s(h.filter(g=>u[g]===null||Array.isArray(u[g])||typeof u[g]!="object").map(g=>Array.isArray(u[g])?`${g}[]`:g).concat([""]).reduce((g,F)=>s(g).length>=s(F).length?g:F)).length);let p="";const m=c.bracketedArray?"[]":"";for(const g of h){const F=u[g];if(F&&Array.isArray(F))for(const w of F)p+=s(`${g}${m}`).padEnd(D," ")+l+s(w)+d;else F&&typeof F=="object"?f.push(g):p+=s(g).padEnd(D," ")+l+s(F)+d}c.section&&p.length&&(p="["+s(c.section)+"]"+(c.newline?d+d:d)+p);for(const g of f){const F=n(g,".").join("\\."),w=(c.section?c.section+".":"")+F,E=t(u[g],{...c,section:w});p.length&&E.length&&(p+=d),p+=E}return p},"encode");function n(u,c){var d=0,l=0,f=0,h=[];do if(f=u.indexOf(c,d),f!==-1){if(d=f+c.length,f>0&&u[f-1]==="\\")continue;h.push(u.slice(l,f)),l=f+c.length}while(f!==-1);return h.push(u.slice(l)),h}o(n,"splitSections");const r=o((u,c={})=>{c.bracketedArray=c.bracketedArray!==!1;const d=Object.create(null);let l=d,f=null;const h=/^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i,D=u.split(/[\r\n]+/g),p={};for(const g of D){if(!g||g.match(/^\s*[;#]/)||g.match(/^\s*$/))continue;const F=g.match(h);if(!F)continue;if(F[1]!==void 0){if(f=a(F[1]),f==="__proto__"){l=Object.create(null);continue}l=d[f]=d[f]||Object.create(null);continue}const w=a(F[2]);let E;c.bracketedArray?E=w.length>2&&w.slice(-2)==="[]":(p[w]=(p?.[w]||0)+1,E=p[w]>1);const y=E&&w.endsWith("[]")?w.slice(0,-2):w;if(y==="__proto__")continue;const b=F[3]?a(F[4]):!0,v=b==="true"||b==="false"||b==="null"?JSON.parse(b):b;E&&(e.call(l,y)?Array.isArray(l[y])||(l[y]=[l[y]]):l[y]=[]),Array.isArray(l[y])?l[y].push(v):l[y]=v}const m=[];for(const g of Object.keys(d)){if(!e.call(d,g)||typeof d[g]!="object"||Array.isArray(d[g]))continue;const F=n(g,".");l=d;const w=F.pop(),E=w.replace(/\\\./g,".");for(const y of F)y!=="__proto__"&&((!e.call(l,y)||typeof l[y]!="object")&&(l[y]=Object.create(null)),l=l[y]);l===d&&E===w||(l[E]=d[g],m.push(g))}for(const g of m)delete d[g];return d},"decode"),i=o(u=>u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"),"isQuoted"),s=o(u=>typeof u!="string"||u.match(/[=\r\n]/)||u.match(/^\[/)||u.length>1&&i(u)||u!==u.trim()?JSON.stringify(u):u.split(";").join("\\;").split("#").join("\\#"),"safe"),a=o(u=>{if(u=(u||"").trim(),i(u)){u.charAt(0)==="'"&&(u=u.slice(1,-1));try{u=JSON.parse(u)}catch{}}else{let c=!1,d="";for(let l=0,f=u.length;l<f;l++){const h=u.charAt(l);if(c)"\\;#".indexOf(h)!==-1?d+=h:d+="\\"+h,c=!1;else{if(";#".indexOf(h)!==-1)break;h==="\\"?c=!0:d+=h}}return c&&(d+="\\"),d.trim()}return u},"unsafe");return yo={parse:r,decode:r,stringify:t,encode:t,safe:s,unsafe:a},yo}o(Gg,"requireIni");var zg=Gg(),Tc=cs(zg);const an=o(e=>W.lstat(e).then(()=>!0,()=>!1),"fileExists"),Eo=o(async e=>{try{let t;try{t=e||await Fo()}catch(a){if(a instanceof I&&a.message.includes("Git repository"))return;throw a}const n=ce.join(t,".ai-commit.json");if(!await an(n))return;const i=await W.readFile(n,"utf8");return JSON.parse(i)}catch(t){if(t instanceof I)throw t;return}},"getProjectConfig");function Vg(e){const t={},n=e.split(`
|
|
122
|
-
`);for(const r of n){const i=r.trim();if(!i||i.startsWith("#"))continue;const s=i.match(/^([A-Z_][A-Z0-9_]*)\s*=\s*(.*)$/i);if(!s)continue;const[,a,u]=s;let c=u.trim();(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))&&(c=c.slice(1,-1)),t[a]=c}return t}o(Vg,"parseEnvContent");async function xc(e){const{filename:t=".env",directory:n=process.cwd(),override:r=!1}=e||{},i=ce.join(n,t);if(!await an(i))return{};try{const a=await W.readFile(i,"utf8"),u=Vg(a);for(const[c,d]of Object.entries(u))(r||process.env[c]===void 0)&&(process.env[c]=d);return u}catch{return{}}}o(xc,"loadEnvFile");async function qg(){process.env.NODE_ENV==="test"?await xc({filename:".env.local"}):await xc({filename:".env"})}o(qg,"loadEnvironment");const Oc=["openai","anthropic","azure-openai","ollama","custom"],Kg=["","conventional"],{hasOwnProperty:Yg}=Object.prototype,Ic=o((e,t)=>Yg.call(e,t),"hasOwn"),R=o((e,t,n)=>{if(!t)throw new I(`Invalid config property ${e}: ${n}`)},"parseAssert"),un={provider(e){return e?(R("provider",Oc.includes(e),`Must be one of: ${Oc.join(", ")}`),e):"openai"},OPENAI_KEY(e){if(e)return R("OPENAI_KEY",e.startsWith("sk-"),'Must start with "sk-"'),e},ANTHROPIC_KEY(e){if(e)return R("ANTHROPIC_KEY",e.startsWith("sk-ant-"),'Must start with "sk-ant-"'),e},AZURE_OPENAI_KEY(e){return e},AZURE_ENDPOINT(e){if(e)return R("AZURE_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},OLLAMA_ENDPOINT(e){return e?(R("OLLAMA_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e):"http://localhost:11434"},CUSTOM_ENDPOINT(e){if(e)return R("CUSTOM_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},CUSTOM_KEY(e){return e},locale(e){return e?(R("locale",e,"Cannot be empty"),R("locale",/^[a-z-]+$/i.test(e),"Must be a valid locale (letters and dashes/underscores). You can consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes"),e):"en"},generate(e){if(!e)return 1;R("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("generate",t>0,"Must be greater than 0"),R("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?(R("type",Kg.includes(e),"Invalid commit type"),e):""},proxy(e){if(!(!e||e.length===0))return R("proxy",/^https?:\/\//.test(e),"Must be a valid URL"),e},model(e){return!e||e.length===0?"gpt-4o-mini":e},timeout(e){if(!e)return 1e4;R("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("timeout",t>=500,"Must be greater than 500ms"),t},temperature(e){if(!e)return .2;R("temperature",/^(2|\d)(\.\d{1,2})?$/.test(e),"Must be decimal between 0 and 2");const t=Number(e);return R("temperature",t>0,"Must be greater than 0"),R("temperature",t<=2,"Must be less than or equal to 2"),t},"max-length"(e){if(!e)return 50;R("max-length",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("max-length",t>=20,"Must be greater than 20 characters"),t},"max-completion-tokens"(e){if(!e)return 1e4;R("max-completion-tokens",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("max-completion-tokens",t>0,"Must be greater than 0"),t},"auto-confirm"(e){return e?typeof e=="boolean"?e:(R("auto-confirm",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1},"prepend-reference"(e){return e?typeof e=="boolean"?e:(R("prepend-reference",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1}},bo=ce.join(dl.homedir(),".aicommit"),Mc=o(async()=>{if(!await an(bo))return Object.create(null);const t=await W.readFile(bo,"utf8");return Tc.parse(t)},"readConfigFile"),Hg=o(e=>{const t=e.provider;switch(t){case"openai":if(!e.OPENAI_KEY)throw new I("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");break;case"anthropic":if(!e.ANTHROPIC_KEY)throw new I("Please set your Anthropic API key via `aicommit config set ANTHROPIC_KEY=<your token>`\nGet your API key from: https://console.anthropic.com/");break;case"azure-openai":if(!e.AZURE_OPENAI_KEY)throw new I("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!e.AZURE_ENDPOINT)throw new I("Please set your Azure OpenAI endpoint via `aicommit config set AZURE_ENDPOINT=<your endpoint>`");break;case"ollama":break;case"custom":if(!e.CUSTOM_ENDPOINT)throw new I("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`");break;default:throw new I(`Unknown provider: ${t}`)}},"validateProviderConfig"),Co=o(async(e,t)=>{await qg();const n=await Mc(),r=await Eo(),i={};for(const a of Object.keys(un)){const u=un[a];let c=r?.[a]??e?.[a]??process.env[a]??n[a];if(typeof c=="boolean"&&(c=c.toString()),t)try{i[a]=u(c)}catch{}else i[a]=u(c)}const s=i;return t||Hg(s),s},"getConfig"),Zg=o(async e=>{const t=await Mc();for(const[n,r]of e){if(!Ic(un,n))throw new I(`Invalid config property: ${n}`);const i=un[n](r);t[n]=i}await W.writeFile(bo,Tc.stringify(t),"utf8")},"setConfigs"),Rc={openai:o(()=>import("./openai-
|
|
122
|
+
`);for(const r of n){const i=r.trim();if(!i||i.startsWith("#"))continue;const s=i.match(/^([A-Z_][A-Z0-9_]*)\s*=\s*(.*)$/i);if(!s)continue;const[,a,u]=s;let c=u.trim();(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))&&(c=c.slice(1,-1)),t[a]=c}return t}o(Vg,"parseEnvContent");async function xc(e){const{filename:t=".env",directory:n=process.cwd(),override:r=!1}=e||{},i=ce.join(n,t);if(!await an(i))return{};try{const a=await W.readFile(i,"utf8"),u=Vg(a);for(const[c,d]of Object.entries(u))(r||process.env[c]===void 0)&&(process.env[c]=d);return u}catch{return{}}}o(xc,"loadEnvFile");async function qg(){process.env.NODE_ENV==="test"?await xc({filename:".env.local"}):await xc({filename:".env"})}o(qg,"loadEnvironment");const Oc=["openai","anthropic","azure-openai","ollama","custom"],Kg=["","conventional"],{hasOwnProperty:Yg}=Object.prototype,Ic=o((e,t)=>Yg.call(e,t),"hasOwn"),R=o((e,t,n)=>{if(!t)throw new I(`Invalid config property ${e}: ${n}`)},"parseAssert"),un={provider(e){return e?(R("provider",Oc.includes(e),`Must be one of: ${Oc.join(", ")}`),e):"openai"},OPENAI_KEY(e){if(e)return R("OPENAI_KEY",e.startsWith("sk-"),'Must start with "sk-"'),e},ANTHROPIC_KEY(e){if(e)return R("ANTHROPIC_KEY",e.startsWith("sk-ant-"),'Must start with "sk-ant-"'),e},AZURE_OPENAI_KEY(e){return e},AZURE_ENDPOINT(e){if(e)return R("AZURE_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},OLLAMA_ENDPOINT(e){return e?(R("OLLAMA_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e):"http://localhost:11434"},CUSTOM_ENDPOINT(e){if(e)return R("CUSTOM_ENDPOINT",/^https?:\/\//.test(e),"Must be a valid URL"),e},CUSTOM_KEY(e){return e},locale(e){return e?(R("locale",e,"Cannot be empty"),R("locale",/^[a-z-]+$/i.test(e),"Must be a valid locale (letters and dashes/underscores). You can consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes"),e):"en"},generate(e){if(!e)return 1;R("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("generate",t>0,"Must be greater than 0"),R("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?(R("type",Kg.includes(e),"Invalid commit type"),e):""},proxy(e){if(!(!e||e.length===0))return R("proxy",/^https?:\/\//.test(e),"Must be a valid URL"),e},model(e){return!e||e.length===0?"gpt-4o-mini":e},timeout(e){if(!e)return 1e4;R("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("timeout",t>=500,"Must be greater than 500ms"),t},temperature(e){if(!e)return .2;R("temperature",/^(2|\d)(\.\d{1,2})?$/.test(e),"Must be decimal between 0 and 2");const t=Number(e);return R("temperature",t>0,"Must be greater than 0"),R("temperature",t<=2,"Must be less than or equal to 2"),t},"max-length"(e){if(!e)return 50;R("max-length",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("max-length",t>=20,"Must be greater than 20 characters"),t},"max-completion-tokens"(e){if(!e)return 1e4;R("max-completion-tokens",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return R("max-completion-tokens",t>0,"Must be greater than 0"),t},"auto-confirm"(e){return e?typeof e=="boolean"?e:(R("auto-confirm",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1},"prepend-reference"(e){return e?typeof e=="boolean"?e:(R("prepend-reference",/^(?:true|false)$/.test(e),"Must be a boolean"),e==="true"):!1}},bo=ce.join(dl.homedir(),".aicommit"),Mc=o(async()=>{if(!await an(bo))return Object.create(null);const t=await W.readFile(bo,"utf8");return Tc.parse(t)},"readConfigFile"),Hg=o(e=>{const t=e.provider;switch(t){case"openai":if(!e.OPENAI_KEY)throw new I("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");break;case"anthropic":if(!e.ANTHROPIC_KEY)throw new I("Please set your Anthropic API key via `aicommit config set ANTHROPIC_KEY=<your token>`\nGet your API key from: https://console.anthropic.com/");break;case"azure-openai":if(!e.AZURE_OPENAI_KEY)throw new I("Please set your Azure OpenAI API key via `aicommit config set AZURE_OPENAI_KEY=<your token>`");if(!e.AZURE_ENDPOINT)throw new I("Please set your Azure OpenAI endpoint via `aicommit config set AZURE_ENDPOINT=<your endpoint>`");break;case"ollama":break;case"custom":if(!e.CUSTOM_ENDPOINT)throw new I("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`");break;default:throw new I(`Unknown provider: ${t}`)}},"validateProviderConfig"),Co=o(async(e,t)=>{await qg();const n=await Mc(),r=await Eo(),i={};for(const a of Object.keys(un)){const u=un[a];let c=r?.[a]??e?.[a]??process.env[a]??n[a];if(typeof c=="boolean"&&(c=c.toString()),t)try{i[a]=u(c)}catch{}else i[a]=u(c)}const s=i;return t||Hg(s),s},"getConfig"),Zg=o(async e=>{const t=await Mc();for(const[n,r]of e){if(!Ic(un,n))throw new I(`Invalid config property: ${n}`);const i=un[n](r);t[n]=i}await W.writeFile(bo,Tc.stringify(t),"utf8")},"setConfigs"),Rc={openai:o(()=>import("./openai-DdXQVga0.mjs"),"openai"),anthropic:o(()=>import("./anthropic-BtdmHzxH.mjs"),"anthropic"),"azure-openai":o(()=>import("./azure-openai-BhX9jBX3.mjs"),"azure-openai"),ollama:o(()=>import("./ollama-BN4LWfT0.mjs"),"ollama"),custom:o(()=>import("./custom-CkAl8jGP.mjs"),"custom")};async function _c(e,t){const n=Rc[e];if(!n)throw new I(`Unknown provider type: ${e}. Supported providers: ${Object.keys(Rc).join(", ")}`);try{const i=(await n()).default;return new i(t)}catch(r){throw r instanceof I?r:r.code==="ERR_MODULE_NOT_FOUND"?new I(`Provider "${e}" is not yet implemented. Currently supported: openai`):new I(`Failed to initialize provider "${e}": ${r.message}`)}}o(_c,"createProvider");var Jg=o(async(e,t,n,r,i)=>(async()=>{vc(rc(nc(" aicommit "))),await Fo();const s=mo();n&&await je("git",["add","--update"]),s.start("Detecting staged files");const a=await Ac(t);if(!a)throw s.stop("Detecting staged files"),new I("No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.");s.stop(`${Wg(a.files)}:
|
|
123
123
|
${a.files.map(h=>` ${h}`).join(`
|
|
124
124
|
`)}`);const{env:u}=process,c=await Co({OPENAI_KEY:u.OPENAI_KEY||u.OPENAI_API_KEY,proxy:u.https_proxy||u.HTTPS_PROXY||u.http_proxy||u.HTTP_PROXY,generate:e?.toString(),type:r?.toString()}),d=mo();d.start("The AI is analyzing your changes");let l;try{const h={model:c.model,locale:c.locale,maxLength:c["max-length"],type:c.type,timeout:c.timeout,temperature:c.temperature,maxCompletionTokens:c["max-completion-tokens"],proxy:c.proxy};let D;switch(c.provider){case"openai":D={...h,apiKey:c.OPENAI_KEY};break;case"anthropic":D={...h,apiKey:c.ANTHROPIC_KEY};break;case"azure-openai":D={...h,apiKey:c.AZURE_OPENAI_KEY,endpoint:c.AZURE_ENDPOINT};break;case"ollama":D={...h,endpoint:c.OLLAMA_ENDPOINT};break;case"custom":D={...h,endpoint:c.CUSTOM_ENDPOINT,apiKey:c.CUSTOM_KEY};break;default:D={...h,apiKey:c.OPENAI_KEY}}const p=await _c(c.provider,D),m=await Eo();l=(await p.generateCommitMessage({diff:a.diff,completions:c.generate,projectConfig:m})).messages}finally{d.stop("Changes analyzed")}if(l.length===0)throw new I("No commit messages were generated. Try again.");let f;if(l.length===1){[f]=l;let h;if(c["auto-confirm"]?(h=!0,xe(`${ct("\u2714")} Auto confirmed commit message.
|
|
125
125
|
|
package/dist/cli.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import"./cli-
|
|
2
|
+
import"./cli-Ci9E6K8n.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var M=Object.defineProperty;var d=(l,t)=>M(l,"name",{value:t,configurable:!0});import T from"http";import N from"https";import{L as O,g as P}from"./prompt-BGI0PV0L.mjs";import{K as m}from"./cli-
|
|
1
|
+
var M=Object.defineProperty;var d=(l,t)=>M(l,"name",{value:t,configurable:!0});import T from"http";import N from"https";import{L as O,g as P}from"./prompt-BGI0PV0L.mjs";import{K as m}from"./cli-Ci9E6K8n.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";const g=class g extends O{get name(){return"custom"}validateConfig(){const{endpoint:t}=this.config;if(!t)throw new m("Please set your custom endpoint via `aicommit config set CUSTOM_ENDPOINT=<your endpoint>`")}async generateCommitMessage(t){try{const o=[{role:"system",content:P(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],s=[];for(let i=0;i<t.completions;i++){const e=await this.createChatCompletion(o);let n;e.choices&&e.choices[0]?.message?.content?n=e.choices[0].message.content:e.message?.content?n=e.message.content:e.content?n=e.content:typeof e=="string"&&(n=e),n&&s.push(this.sanitizeMessage(n))}return{messages:this.deduplicateMessages(s)}}catch(r){const o=r;throw o.code==="ECONNREFUSED"?new m(`Cannot connect to custom endpoint at ${this.config.endpoint}. Make sure your endpoint is running and accessible.`):o.code==="ENOTFOUND"?new m(`Error connecting to ${o.hostname} (${o.syscall}). Check your CUSTOM_ENDPOINT configuration.`):o}}async createChatCompletion(t){const r={model:this.config.model,messages:t,temperature:this.config.temperature,max_tokens:this.config.maxCompletionTokens},o={...this.config.headers||{}};this.config.apiKey&&(o.Authorization=`Bearer ${this.config.apiKey}`);const{response:s,data:a}=await this.httpPost(this.config.endpoint,"",o,r);if(!s.statusCode||s.statusCode<200||s.statusCode>299){let i=`Custom API Error: ${s.statusCode} - ${s.statusMessage}`;throw a&&(i+=`
|
|
2
2
|
|
|
3
3
|
${a}`),new m(i)}return JSON.parse(a)}async httpPost(t,r,o,s){return new Promise((a,i)=>{const e=new URL(t),n=e.protocol==="https:",y=n?N:T,C=e.pathname+(r||""),f=JSON.stringify(s),c=y.request({hostname:e.hostname,port:e.port||(n?443:80),path:C,method:"POST",headers:{...o,"Content-Type":"application/json","Content-Length":Buffer.byteLength(f)},timeout:this.config.timeout},p=>{const u=[];p.on("data",w=>u.push(w)),p.on("end",()=>{a({request:c,response:p,data:Buffer.concat(u).toString()})})});c.on("error",i),c.on("timeout",()=>{c.destroy(),i(new m(`Time out error: request took over ${this.config.timeout}ms. Try increasing the \`timeout\` config.`))}),c.write(f),c.end()})}sanitizeMessage(t){return t.trim().replace(/[\n\r]/g,"").replace(/(\w)\.$/,"$1")}deduplicateMessages(t){return Array.from(new Set(t))}};d(g,"CustomProvider");let h=g;export{h as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var C=Object.defineProperty;var f=(d,t)=>C(d,"name",{value:t,configurable:!0});import M from"http";import O from"https";import{L as $,g as L}from"./prompt-BGI0PV0L.mjs";import{K as m}from"./cli-
|
|
1
|
+
var C=Object.defineProperty;var f=(d,t)=>C(d,"name",{value:t,configurable:!0});import M from"http";import O from"https";import{L as $,g as L}from"./prompt-BGI0PV0L.mjs";import{K as m}from"./cli-Ci9E6K8n.mjs";import"tty";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";import"os";import"url";const g=class g extends ${get name(){return"ollama"}validateConfig(){const{endpoint:t}=this.config;if(!t)throw new m("Ollama endpoint is not configured. Using default: http://localhost:11434")}async generateCommitMessage(t){try{const e=[{role:"system",content:L(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],o=[];for(let s=0;s<t.completions;s++){const a=(await this.createChatCompletion(e)).message.content;a&&o.push(this.sanitizeMessage(a))}return{messages:this.deduplicateMessages(o)}}catch(r){const e=r;throw e.code==="ECONNREFUSED"?new m(`Cannot connect to Ollama at ${this.config.endpoint}. Make sure Ollama is running. Install from: https://ollama.com`):e.code==="ENOTFOUND"?new m(`Error connecting to ${e.hostname} (${e.syscall}). Check your OLLAMA_ENDPOINT configuration.`):e}}async createChatCompletion(t){const r={model:this.config.model,messages:t,stream:!1,options:{temperature:this.config.temperature,num_predict:this.config.maxCompletionTokens}},{response:e,data:o}=await this.httpPost(this.config.endpoint,"/api/chat",{},r);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let n=`Ollama API Error: ${e.statusCode} - ${e.statusMessage}`;if(o)try{const s=JSON.parse(o);s.error&&(n+=`
|
|
2
2
|
|
|
3
3
|
${s.error}`)}catch{n+=`
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var d=Object.defineProperty;var g=(u,t)=>d(u,"name",{value:t,configurable:!0});import y from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as C,g as A}from"./prompt-BGI0PV0L.mjs";import{K as i}from"./cli-
|
|
1
|
+
var d=Object.defineProperty;var g=(u,t)=>d(u,"name",{value:t,configurable:!0});import y from"https";import{d as w}from"./index-B3_BP8RZ.mjs";import{L as C,g as A}from"./prompt-BGI0PV0L.mjs";import{K as i}from"./cli-Ci9E6K8n.mjs";import"net";import"tls";import"assert";import"tty";import"util";import"os";import"http";import"url";import"node:url";import"node:child_process";import"node:string_decoder";import"node:util";import"node:process";import"node:tty";import"node:path";import"child_process";import"path";import"fs";import"node:timers/promises";import"node:os";import"node:events";import"node:v8";import"node:fs";import"node:stream";import"node:buffer";import"node:stream/promises";import"node:readline";import"fs/promises";const m=class m extends C{get name(){return"openai"}validateConfig(){const{apiKey:t}=this.config;if(!t)throw new i("Please set your OpenAI API key via `aicommit config set OPENAI_KEY=<your token>`");if(!t.startsWith("sk-"))throw new i('Invalid OpenAI API key: Must start with "sk-"')}async generateCommitMessage(t){try{const e=await this.createChatCompletion({model:this.config.model,messages:[{role:"system",content:A(this.config.locale,this.config.maxLength,this.config.type,t.projectConfig)},{role:"user",content:t.diff}],temperature:this.config.temperature,top_p:1,frequency_penalty:0,presence_penalty:0,max_completion_tokens:this.config.maxCompletionTokens,stream:!1,n:t.completions});return{messages:this.deduplicateMessages(e.choices.filter(s=>s.message?.content).map(s=>this.sanitizeMessage(s.message.content)))}}catch(e){const o=e;throw o.code==="ENOTFOUND"?new i(`Error connecting to ${o.hostname} (${o.syscall}). Are you connected to the internet?`):o}}async createChatCompletion(t){const{response:e,data:o}=await this.httpsPost("api.openai.com","/v1/chat/completions",{Authorization:`Bearer ${this.config.apiKey}`},t);if(!e.statusCode||e.statusCode<200||e.statusCode>299){let s=`OpenAI API Error: ${e.statusCode} - ${e.statusMessage}`;throw o&&(s+=`
|
|
2
2
|
|
|
3
3
|
${o}`),e.statusCode===500&&(s+=`
|
|
4
4
|
|