k2-im 0.2.0 → 0.2.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.
@@ -1 +1 @@
1
- function t(t,r,n){const e=t.trim(),o=/^0+$/.test(e);if(!/^\d+$/.test(e)||!n&&o)throw new Error(`机器人指令 ${r} 必须是${n?"非负":"正"}整数`);return BigInt(e)}function r(t){const r=[];let n=t;for(;n>0x7fn;)r.push(Number(0x7fn&n|0x80n)),n>>=7n;return r.push(Number(n)),r}function n(t,n){const e=[...(new TextEncoder).encode(n)];return[t<<3|2,...r(BigInt(e.length)),...e]}function e(e){const o=t(e.menuId,"menuId",!0),f=e.robotId.trim(),u=t(e.userId,"userId",!1);if(""===f)throw new Error("机器人指令 robotId 不能为空");const i=[8,...r(o),...n(2,f),24,...r(u)];return Uint8Array.from(i)}function o(t,r){let n=0n,e=0n,o=r;for(;o<t.length&&e<=63n;){const r=t[o];if(o+=1,n|=BigInt(127&r)<<e,!(128&r))return{value:n,offset:o};e+=7n}throw new Error("机器人固定回复 protobuf 截断")}function f(t,r,n){if(0===n)return o(t,r).offset;if(1===n)return r+8;if(5===n)return r+4;if(2===n){const n=o(t,r),e=Number(n.value);if(!Number.isSafeInteger(e)||e<0||n.offset+e>t.length)throw new Error("机器人固定回复 protobuf 截断");return n.offset+e}throw new Error(`机器人固定回复 protobuf 字段类型不支持:${n}`)}function u(t){let r=0n,n=0n,e="",u=0,i=0n,s=new Uint8Array,c=0;for(;c<t.length;){const a=o(t,c),m=Number(a.value>>3n),b=Number(7n&a.value);if(c=a.offset,0===b&&(1===m||2===m||4===m||5===m)){const e=o(t,c);c=e.offset,1===m?r=e.value:2===m?n=e.value:4===m?u=Number(e.value):i=e.value;continue}if(2===b&&(3===m||6===m)){const r=o(t,c),n=Number(r.value);if(!Number.isSafeInteger(n)||n<0||r.offset+n>t.length)throw new Error("机器人固定回复 protobuf 截断");const f=t.subarray(r.offset,r.offset+n);3===m?e=(new TextDecoder).decode(f):s=Uint8Array.from(f),c=r.offset+n;continue}const l=f(t,c,b);if(l>t.length)throw new Error("机器人固定回复 protobuf 截断");c=l}return{toId:r.toString(),fromId:n.toString(),msgId:e,msgType:u,msgTime:i,content:s}}async function i(t,r){return u(await t.postProtobuf({path:"/robotRouter/fixed_chat_msg",body:e(r)}))}export{u as decodeFixedChatMsgResponse,e as encodeFixedChatMsgRequest,i as requestRobotMenuReply};
1
+ function t(t,r,n){const e=t.trim(),o=/^0+$/.test(e);if(!/^\d+$/.test(e)||!n&&o)throw new Error(`机器人指令 ${r} 必须是${n?"非负":"正"}整数`);return BigInt(e)}function r(t){const r=[];let n=t;for(;n>0x7Fn;)r.push(Number(0x7Fn&n|0x80n)),n>>=7n;return r.push(Number(n)),r}function n(t,n){const e=[...(new TextEncoder).encode(n)];return[t<<3|2,...r(BigInt(e.length)),...e]}function e(e){const o=t(e.menuId,"menuId",!0),f=e.robotId.trim(),u=t(e.userId,"userId",!1);if(""===f)throw new Error("机器人指令 robotId 不能为空");const i=[8,...r(o),...n(2,f),24,...r(u)];return Uint8Array.from(i)}function o(t,r){let n=0n,e=0n,o=r;for(;o<t.length&&e<=63n;){const r=t[o];if(o+=1,n|=BigInt(127&r)<<e,!(128&r))return{value:n,offset:o};e+=7n}throw new Error("机器人固定回复 protobuf 截断")}function f(t,r,n){if(0===n)return o(t,r).offset;if(1===n)return r+8;if(5===n)return r+4;if(2===n){const n=o(t,r),e=Number(n.value);if(!Number.isSafeInteger(e)||e<0||n.offset+e>t.length)throw new Error("机器人固定回复 protobuf 截断");return n.offset+e}throw new Error(`机器人固定回复 protobuf 字段类型不支持:${n}`)}function u(t){let r=0n,n=0n,e="",u=0,i=0n,s=new Uint8Array,c=0;for(;c<t.length;){const a=o(t,c),m=Number(a.value>>3n),b=Number(7n&a.value);if(c=a.offset,0===b&&(1===m||2===m||4===m||5===m)){const e=o(t,c);c=e.offset,1===m?r=e.value:2===m?n=e.value:4===m?u=Number(e.value):i=e.value;continue}if(2===b&&(3===m||6===m)){const r=o(t,c),n=Number(r.value);if(!Number.isSafeInteger(n)||n<0||r.offset+n>t.length)throw new Error("机器人固定回复 protobuf 截断");const f=t.subarray(r.offset,r.offset+n);3===m?e=(new TextDecoder).decode(f):s=Uint8Array.from(f),c=r.offset+n;continue}const l=f(t,c,b);if(l>t.length)throw new Error("机器人固定回复 protobuf 截断");c=l}return{toId:r.toString(),fromId:n.toString(),msgId:e,msgType:u,msgTime:i,content:s}}async function i(t,r){return u(await t.postProtobuf({path:"/robotRouter/fixed_chat_msg",body:e(r)}))}export{u as decodeFixedChatMsgResponse,e as encodeFixedChatMsgRequest,i as requestRobotMenuReply};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "k2-im",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "publishConfig": {