@negoziator/ai-commit 2.33.8 → 2.34.1

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.
@@ -0,0 +1,5 @@
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-D37UKWt_.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
+
3
+ ${n}`),e.statusCode===500&&(s+=`
4
+
5
+ Check the API status: https://status.anthropic.com`),new a(s)}return JSON.parse(n)}async httpsPost(t,i,o,e){return new Promise((n,s)=>{const m=JSON.stringify(e),r=l.request({hostname:t,path:i,method:"POST",headers:{...o,"Content-Type":"application/json","Content-Length":Buffer.byteLength(m)},timeout:this.config.timeout,agent:this.config.proxy?new w.HttpsProxyAgent(this.config.proxy):void 0},p=>{const g=[];p.on("data",d=>g.push(d)),p.on("end",()=>{n({request:r,response:p,data:Buffer.concat(g).toString()})})});r.on("error",s),r.on("timeout",()=>{r.destroy(),s(new a(`Time out error: request took over ${this.config.timeout}ms. Try increasing the \`timeout\` config, or checking the Anthropic API status https://status.anthropic.com`))}),r.write(m),r.end()})}sanitizeMessage(t){return t.trim().replace(/[\n\r]/g,"").replace(/(\w)\.$/,"$1")}deduplicateMessages(t){return Array.from(new Set(t))}};u(h,"AnthropicProvider");let c=h;export{c as default};
@@ -0,0 +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-D37UKWt_.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
+
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};