@ctyun/desktop-agent-sdk 0.0.2 → 0.0.3
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.cjs.js +2 -2
- package/dist/index.esm.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @ctyun/desktop-agent-sdk v0.0.
|
|
2
|
-
"use strict";var e=require("axios"),s=require("node:crypto");const t=e.create({});[t].forEach(e=>{e.interceptors.request.use(e=>(e=>{const s={baseURL:e.baseURL,url:e.url,payload:e.data},t=Object.keys(e.headers).reduce((s,t)=>(s[t]=e.headers[t],s),{});return s.headers=t,console.log(JSON.stringify(s,null,2)),e})(e)),e.interceptors.response.use(e=>(e=>{const s={url:e.config.url,response:e.data};return console.log(JSON.stringify(s,null,2)),e})(e),e=>(e=>{const s={url:err.config.url,response:e.response.data||{}};return console.error(JSON.stringify(s,null,2)),e})(e))});var o={
|
|
1
|
+
/*! @ctyun/desktop-agent-sdk v0.0.3 | (c) 2026-02-26 zhangjiliang | https://desk.ctyun.cn/html/download/ */
|
|
2
|
+
"use strict";var e=require("axios"),s=require("node:crypto");const t=e.create({});[t].forEach(e=>{e.interceptors.request.use(e=>(e=>{const s={baseURL:e.baseURL,url:e.url,payload:e.data},t=Object.keys(e.headers).reduce((s,t)=>(s[t]=e.headers[t],s),{});return s.headers=t,console.log(JSON.stringify(s,null,2)),e})(e)),e.interceptors.response.use(e=>(e=>{const s={url:e.config.url,response:e.data};return console.log(JSON.stringify(s,null,2)),e})(e),e=>(e=>{const s={url:err.config.url,response:e.response.data||{}};return console.error(JSON.stringify(s,null,2)),e})(e))});var o={createSession:function(e,s){return t.post("/api/openApi/cdserv/aiUse/createSession",e,{...s})},sendMessage:function(e,s){return t.post("/api/openApi/cdserv/aiUse/sendMessage",e,{...s})},queryJob:function(e,s){return t.post("/api/openApi/cdserv/aiUse/queryJob",e,{...s})},deleteSession:function(e,s){return t.post("/api/openApi/cdserv/aiUse/deleteSession",e,{...s})}};const r=e=>{const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",o=s.randomBytes(e);let r="";for(let e=0;e<o.length;e++)r+=t[o[e]%62];return r.slice(0,e)},a=e=>{const{path:t,body:o,apiKey:a,apiSecret:n}=e;let i={};const c=t.indexOf("?");-1!==c&&(i=(e=>{if(!e)return{};let s={},t=e.split("&");for(let e=0;e<t.length;e++){let o=t[e].split("=");s[o[0]]=o[1]}return s})(t.slice(c+1)));const d={"x-ctg-ecpc-ak":a,"x-ctg-algorithm":"SHA256","x-ctg-timestamp":(new Date).getTime(),"x-ctg-nonStr":r(8)};o&&(d["x-ctg-reqJson"]=(e=>{const t=s.createHash("md5");return t.update(e),t.digest("hex")})(JSON.stringify(o)));const u=Object.assign({},i,d),p=[],l=Object.keys(u);l.sort(),l.forEach(e=>{p.push(`${e}=${u[e]}`)});const h=p.join("&")+n;return d.sign=(e=>{const t=s.createHash("sha256");return t.update(e),t.digest("hex")})(h),d},n=(e,t)=>{const o=Buffer.alloc(16,0),r=s.createCipheriv("aes-256-cbc",t,o);let a=r.update(e,"utf8","base64");return a+=r.final("base64"),a};var i=Object.freeze({__proto__:null,click_mouse:(e,s,t="left",o="down")=>({action:"ClickMouse",params:{PositionX:e,PositionY:s,Button:t,Press:"down"==o,Release:"up"==o}}),drag_mouse:(e,s,t,o)=>({action:"DragMouse",params:{SourceX:e,SourceY:s,TargetX:t,TargetY:o}}),get_cursor_position:()=>({action:"GetCursorPosition"}),move_mouse:(e,s)=>({action:"MoveMouse",params:{PositionX:e,PositionY:s}}),press_key:e=>({action:"PressKey",params:{Key:e}}),press_mouse:(e,s,t="left")=>({action:"PressMouse",params:{PositionX:e,PositionY:s,Button:t}}),release_mouse:(e,s,t="left")=>({action:"ReleaseMouse",params:{PositionX:e,PositionY:s,Button:t}}),screen_shot:()=>({action:"TakeScreenshot"}),scroll:(e,s,t,o)=>({action:"Scroll",params:{PositionX:e,PositionY:s,Direction:t,Amount:o}}),type_text:e=>({action:"TypeText",params:{Text:e}})});const c=(e,s)=>{const{apiKey:t,apiSecret:o,path:r}=s;return{headers:a({path:r||"",body:e,apiKey:t,apiSecret:o}),body:e}};module.exports=class{constructor(e={}){this.options=Object.assign({serviceURL:"https://desk.ctyun.cn:8816"},e);const{apiKey:s,apiSecret:t,desktopCode:o,serviceURL:r}=this.options;if(!s||!t)throw new Error("apiKey或apiSecret不能为空");if(!r)throw new Error("serviceURL不能为空");if(!o)throw new Error("desktopCode不能为空")}async createSession(){const{apiKey:e,apiSecret:s,desktopCode:t,serviceURL:a}=this.options,d={requestId:r(32),desktopCode:t},{headers:u,body:p}=c(d,{apiKey:e,apiSecret:s}),l=await o.createSession(p,{headers:u,baseURL:a}),h=this.sessionId=l.data.data.sessionId,y=Object.keys(i).reduce((d,u)=>(d[u]=async(...d)=>{if(!this.sessionId)throw new Error("会话已关闭或未创建");const p=i[u](...d),l=r(32),y={requestId:l,desktopCode:t,sessionId:h,message:n(JSON.stringify(p),l)},{headers:m,body:f}=c(y,{apiKey:e,apiSecret:s}),b=await o.sendMessage(f,{headers:m,baseURL:a}),S=()=>{const{jobId:e,jobRollIntervalMs:s=2e3,jobRollTimes:t=10}=b.data.data;return new Promise((o,r)=>{let a=0;const n=e=>{const t=(new Date).getTime(),o=Math.min(3e3,s*Math.pow(1.5,a));return t-e>=o?0:o-(t-e)},i=async()=>{if(a++,!this.sessionId)return r({code:-1,data:null,msg:"会话已关闭"});if(a>t)return r({code:-1,data:null,msg:"已超时"});const s=(new Date).getTime();try{const t=await g(e),r=n(s);if(0==t.data.code){const{resp:e,respFlag:s}=t.data.data;s?o({code:0,data:e,msg:null}):setTimeout(()=>i(),r)}else setTimeout(()=>i(),r)}catch(e){const t=n(s);setTimeout(()=>i(),t)}};setTimeout(()=>i(),s)})};if(0==b.data.code){return await S()}return{code:b.data.code,data:null,msg:"发送失败"}},d),{}),g=async n=>{if(!this.sessionId)throw new Error("会话已关闭或未创建");const i={requestId:r(32),desktopCode:t,sessionId:h,jobId:n},{headers:d,body:u}=c(i,{apiKey:e,apiSecret:s});return(await o.queryJob(u,{headers:d,baseURL:a})).data},m={sessionId:h,close:async()=>{if(!this.sessionId)return;const n={requestId:r(32),desktopCode:t,sessionId:h},{headers:i,body:d}=c(n,{apiKey:e,apiSecret:s}),u=await o.deleteSession(d,{headers:i,baseURL:a});return this.sessionId=null,u.data},computer:y};return m}};
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @ctyun/desktop-agent-sdk v0.0.
|
|
2
|
-
import e from"axios";import s from"node:crypto";const t=e.create({});[t].forEach(e=>{e.interceptors.request.use(e=>(e=>{const s={baseURL:e.baseURL,url:e.url,payload:e.data},t=Object.keys(e.headers).reduce((s,t)=>(s[t]=e.headers[t],s),{});return s.headers=t,console.log(JSON.stringify(s,null,2)),e})(e)),e.interceptors.response.use(e=>(e=>{const s={url:e.config.url,response:e.data};return console.log(JSON.stringify(s,null,2)),e})(e),e=>(e=>{const s={url:err.config.url,response:e.response.data||{}};return console.error(JSON.stringify(s,null,2)),e})(e))});var o={
|
|
1
|
+
/*! @ctyun/desktop-agent-sdk v0.0.3 | (c) 2026-02-26 zhangjiliang | https://desk.ctyun.cn/html/download/ */
|
|
2
|
+
import e from"axios";import s from"node:crypto";const t=e.create({});[t].forEach(e=>{e.interceptors.request.use(e=>(e=>{const s={baseURL:e.baseURL,url:e.url,payload:e.data},t=Object.keys(e.headers).reduce((s,t)=>(s[t]=e.headers[t],s),{});return s.headers=t,console.log(JSON.stringify(s,null,2)),e})(e)),e.interceptors.response.use(e=>(e=>{const s={url:e.config.url,response:e.data};return console.log(JSON.stringify(s,null,2)),e})(e),e=>(e=>{const s={url:err.config.url,response:e.response.data||{}};return console.error(JSON.stringify(s,null,2)),e})(e))});var o={createSession:function(e,s){return t.post("/api/openApi/cdserv/aiUse/createSession",e,{...s})},sendMessage:function(e,s){return t.post("/api/openApi/cdserv/aiUse/sendMessage",e,{...s})},queryJob:function(e,s){return t.post("/api/openApi/cdserv/aiUse/queryJob",e,{...s})},deleteSession:function(e,s){return t.post("/api/openApi/cdserv/aiUse/deleteSession",e,{...s})}};const r=e=>{const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",o=s.randomBytes(e);let r="";for(let e=0;e<o.length;e++)r+=t[o[e]%62];return r.slice(0,e)},a=e=>{const{path:t,body:o,apiKey:a,apiSecret:n}=e;let i={};const c=t.indexOf("?");-1!==c&&(i=(e=>{if(!e)return{};let s={},t=e.split("&");for(let e=0;e<t.length;e++){let o=t[e].split("=");s[o[0]]=o[1]}return s})(t.slice(c+1)));const d={"x-ctg-ecpc-ak":a,"x-ctg-algorithm":"SHA256","x-ctg-timestamp":(new Date).getTime(),"x-ctg-nonStr":r(8)};o&&(d["x-ctg-reqJson"]=(e=>{const t=s.createHash("md5");return t.update(e),t.digest("hex")})(JSON.stringify(o)));const p=Object.assign({},i,d),u=[],l=Object.keys(p);l.sort(),l.forEach(e=>{u.push(`${e}=${p[e]}`)});const h=u.join("&")+n;return d.sign=(e=>{const t=s.createHash("sha256");return t.update(e),t.digest("hex")})(h),d},n=(e,t)=>{const o=Buffer.alloc(16,0),r=s.createCipheriv("aes-256-cbc",t,o);let a=r.update(e,"utf8","base64");return a+=r.final("base64"),a};var i=Object.freeze({__proto__:null,click_mouse:(e,s,t="left",o="down")=>({action:"ClickMouse",params:{PositionX:e,PositionY:s,Button:t,Press:"down"==o,Release:"up"==o}}),drag_mouse:(e,s,t,o)=>({action:"DragMouse",params:{SourceX:e,SourceY:s,TargetX:t,TargetY:o}}),get_cursor_position:()=>({action:"GetCursorPosition"}),move_mouse:(e,s)=>({action:"MoveMouse",params:{PositionX:e,PositionY:s}}),press_key:e=>({action:"PressKey",params:{Key:e}}),press_mouse:(e,s,t="left")=>({action:"PressMouse",params:{PositionX:e,PositionY:s,Button:t}}),release_mouse:(e,s,t="left")=>({action:"ReleaseMouse",params:{PositionX:e,PositionY:s,Button:t}}),screen_shot:()=>({action:"TakeScreenshot"}),scroll:(e,s,t,o)=>({action:"Scroll",params:{PositionX:e,PositionY:s,Direction:t,Amount:o}}),type_text:e=>({action:"TypeText",params:{Text:e}})});const c=(e,s)=>{const{apiKey:t,apiSecret:o,path:r}=s;return{headers:a({path:r||"",body:e,apiKey:t,apiSecret:o}),body:e}};class d{constructor(e={}){this.options=Object.assign({serviceURL:"https://desk.ctyun.cn:8816"},e);const{apiKey:s,apiSecret:t,desktopCode:o,serviceURL:r}=this.options;if(!s||!t)throw new Error("apiKey或apiSecret不能为空");if(!r)throw new Error("serviceURL不能为空");if(!o)throw new Error("desktopCode不能为空")}async createSession(){const{apiKey:e,apiSecret:s,desktopCode:t,serviceURL:a}=this.options,d={requestId:r(32),desktopCode:t},{headers:p,body:u}=c(d,{apiKey:e,apiSecret:s}),l=await o.createSession(u,{headers:p,baseURL:a}),h=this.sessionId=l.data.data.sessionId,y=Object.keys(i).reduce((d,p)=>(d[p]=async(...d)=>{if(!this.sessionId)throw new Error("会话已关闭或未创建");const u=i[p](...d),l=r(32),y={requestId:l,desktopCode:t,sessionId:h,message:n(JSON.stringify(u),l)},{headers:g,body:f}=c(y,{apiKey:e,apiSecret:s}),b=await o.sendMessage(f,{headers:g,baseURL:a}),S=()=>{const{jobId:e,jobRollIntervalMs:s=2e3,jobRollTimes:t=10}=b.data.data;return new Promise((o,r)=>{let a=0;const n=e=>{const t=(new Date).getTime(),o=Math.min(3e3,s*Math.pow(1.5,a));return t-e>=o?0:o-(t-e)},i=async()=>{if(a++,!this.sessionId)return r({code:-1,data:null,msg:"会话已关闭"});if(a>t)return r({code:-1,data:null,msg:"已超时"});const s=(new Date).getTime();try{const t=await m(e),r=n(s);if(0==t.data.code){const{resp:e,respFlag:s}=t.data.data;s?o({code:0,data:e,msg:null}):setTimeout(()=>i(),r)}else setTimeout(()=>i(),r)}catch(e){const t=n(s);setTimeout(()=>i(),t)}};setTimeout(()=>i(),s)})};if(0==b.data.code){return await S()}return{code:b.data.code,data:null,msg:"发送失败"}},d),{}),m=async n=>{if(!this.sessionId)throw new Error("会话已关闭或未创建");const i={requestId:r(32),desktopCode:t,sessionId:h,jobId:n},{headers:d,body:p}=c(i,{apiKey:e,apiSecret:s});return(await o.queryJob(p,{headers:d,baseURL:a})).data},g={sessionId:h,close:async()=>{if(!this.sessionId)return;const n={requestId:r(32),desktopCode:t,sessionId:h},{headers:i,body:d}=c(n,{apiKey:e,apiSecret:s}),p=await o.deleteSession(d,{headers:i,baseURL:a});return this.sessionId=null,p.data},computer:y};return g}}export{d as default};
|