@lunora/agent 1.0.0-alpha.150 → 1.0.0-alpha.151
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/channels.d.mts +11 -0
- package/dist/channels.d.ts +11 -0
- package/dist/channels.mjs +1 -1
- package/package.json +5 -5
package/dist/channels.d.mts
CHANGED
|
@@ -18,6 +18,12 @@ declare const verifySlack: (options: {
|
|
|
18
18
|
}) => Promise<boolean>;
|
|
19
19
|
/**
|
|
20
20
|
* Verify a GitHub webhook signature (`x-hub-signature-256` = `sha256=` + HMAC over the body).
|
|
21
|
+
*
|
|
22
|
+
* There is no replay window: GitHub signs the body alone, with no timestamp, so
|
|
23
|
+
* a captured delivery verifies indefinitely. `dispatchAgentChannel` bounds that
|
|
24
|
+
* by keying the run on the SHA-256 of the signed body (see `deliveryId`), so a
|
|
25
|
+
* replay dedupes to the original run — for as long as the Workflow keeps that
|
|
26
|
+
* instance id.
|
|
21
27
|
* @experimental
|
|
22
28
|
*/
|
|
23
29
|
declare const verifyGithub: (options: {
|
|
@@ -28,13 +34,18 @@ declare const verifyGithub: (options: {
|
|
|
28
34
|
/**
|
|
29
35
|
* Verify a Discord interaction signature: Ed25519 over `timestamp + body`,
|
|
30
36
|
* `x-signature-ed25519` (hex) against the application's `publicKey` (hex).
|
|
37
|
+
* The signed `x-signature-timestamp` must be within `tolerance` seconds of
|
|
38
|
+
* `now` in either direction, or a captured interaction would verify forever.
|
|
39
|
+
* `now` is injectable for deterministic tests (defaults to the wall clock).
|
|
31
40
|
* @experimental
|
|
32
41
|
*/
|
|
33
42
|
declare const verifyDiscord: (options: {
|
|
34
43
|
body: string;
|
|
44
|
+
now?: number;
|
|
35
45
|
publicKey: string;
|
|
36
46
|
signature: string | undefined;
|
|
37
47
|
timestamp: string | undefined;
|
|
48
|
+
tolerance?: number;
|
|
38
49
|
}) => Promise<boolean>;
|
|
39
50
|
/**
|
|
40
51
|
* One agent wired into the inbound channel HTTP handler.
|
package/dist/channels.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ declare const verifySlack: (options: {
|
|
|
18
18
|
}) => Promise<boolean>;
|
|
19
19
|
/**
|
|
20
20
|
* Verify a GitHub webhook signature (`x-hub-signature-256` = `sha256=` + HMAC over the body).
|
|
21
|
+
*
|
|
22
|
+
* There is no replay window: GitHub signs the body alone, with no timestamp, so
|
|
23
|
+
* a captured delivery verifies indefinitely. `dispatchAgentChannel` bounds that
|
|
24
|
+
* by keying the run on the SHA-256 of the signed body (see `deliveryId`), so a
|
|
25
|
+
* replay dedupes to the original run — for as long as the Workflow keeps that
|
|
26
|
+
* instance id.
|
|
21
27
|
* @experimental
|
|
22
28
|
*/
|
|
23
29
|
declare const verifyGithub: (options: {
|
|
@@ -28,13 +34,18 @@ declare const verifyGithub: (options: {
|
|
|
28
34
|
/**
|
|
29
35
|
* Verify a Discord interaction signature: Ed25519 over `timestamp + body`,
|
|
30
36
|
* `x-signature-ed25519` (hex) against the application's `publicKey` (hex).
|
|
37
|
+
* The signed `x-signature-timestamp` must be within `tolerance` seconds of
|
|
38
|
+
* `now` in either direction, or a captured interaction would verify forever.
|
|
39
|
+
* `now` is injectable for deterministic tests (defaults to the wall clock).
|
|
31
40
|
* @experimental
|
|
32
41
|
*/
|
|
33
42
|
declare const verifyDiscord: (options: {
|
|
34
43
|
body: string;
|
|
44
|
+
now?: number;
|
|
35
45
|
publicKey: string;
|
|
36
46
|
signature: string | undefined;
|
|
37
47
|
timestamp: string | undefined;
|
|
48
|
+
tolerance?: number;
|
|
38
49
|
}) => Promise<boolean>;
|
|
39
50
|
/**
|
|
40
51
|
* One agent wired into the inbound channel HTTP handler.
|
package/dist/channels.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as
|
|
1
|
+
import{LunoraError as g}from"@lunora/errors";import{isDuplicateInstanceError as E}from"@lunora/workflow";import{h as A,B as R}from"./packem_shared/branch-marker-boZ00zmk.mjs";import{f as k}from"./packem_shared/fnv1a-BNN96GYb.mjs";const m=300,N=/[^0-9a-f]/iu,S=new TextEncoder,u=t=>new Uint8Array(S.encode(t)),l=t=>{if(t.length%2!==0||N.test(t))throw new g("BAD_REQUEST","@lunora/agent: malformed hex signature");const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n+=1)e[n]=Number.parseInt(t.slice(n*2,n*2+2),16);return e},v=async(t,e,n)=>{try{const r=await crypto.subtle.importKey("raw",u(t),{hash:"SHA-256",name:"HMAC"},!1,["verify"]);return await crypto.subtle.verify("HMAC",r,l(n),u(e))}catch{return!1}},b=(t,e,n)=>Number.isFinite(t)&&Math.abs(e-t)<=n,x=async t=>{const{body:e,now:n=Date.now()/1e3,signature:r,signingSecret:a,timestamp:s,tolerance:o=m}=t;return!r||!s||!r.startsWith("v0=")||!b(Number(s),n,o)?!1:v(a,`v0:${s}:${e}`,r.slice(3))},T=async t=>{const{body:e,secret:n,signature:r}=t;return r?.startsWith("sha256=")?v(n,e,r.slice(7)):!1},C=async t=>{const{body:e,now:n=Date.now()/1e3,publicKey:r,signature:a,timestamp:s,tolerance:o=m}=t;if(!a||!s||!b(Number(s),n,o))return!1;try{const c=await crypto.subtle.importKey("raw",l(r),{name:"Ed25519"},!1,["verify"]);return await crypto.subtle.verify({name:"Ed25519"},c,l(a),u(s+e))}catch{return!1}},H=t=>{if(t.has("x-slack-signature"))return"slack";if(t.has("x-hub-signature-256"))return"github";if(t.has("x-signature-ed25519"))return"discord"},I=(t,e)=>{if(typeof t=="function")return t(e);const n=e[t];return typeof n=="string"?n:void 0},_=async(t,e,n,r)=>{switch(t){case"discord":return C({body:r,publicKey:e,signature:n.get("x-signature-ed25519")??void 0,timestamp:n.get("x-signature-timestamp")??void 0});case"github":return T({body:r,secret:e,signature:n.get("x-hub-signature-256")??void 0});case"slack":return x({body:r,signature:n.get("x-slack-signature")??void 0,signingSecret:e,timestamp:n.get("x-slack-request-timestamp")??void 0});default:return!1}},B=(t,e)=>{if(t==="discord")try{if(JSON.parse(e).type===1)return Response.json({type:1})}catch{}},w=()=>new Response(void 0,{status:200}),D=async t=>[...new Uint8Array(await crypto.subtle.digest("SHA-256",u(t)))].map(e=>e.toString(16).padStart(2,"0")).join(""),M=async(t,e)=>{if(t!=="github")try{const n=JSON.parse(e),r=t==="slack"?n.event_id:n.id;if(typeof r=="string"&&r!=="")return r}catch{}return D(e)},U=async(t,e,n,r)=>{if(A(e))throw new g("BAD_REQUEST",`@lunora/agent: inbound channel run params ${R}`);try{await t.create({id:`${n}-${k(r)}`,params:e})}catch(a){if(E(a))return w();throw a}return w()},J=t=>async(e,n)=>{const r=await e.text(),a=H(e.headers);if(a===void 0)return new Response("Unrecognized webhook",{status:400});const s=t.map(i=>({config:i.agent.onInbound,target:i})).filter(i=>i.config?.channel===a),o={channel:a,headers:e.headers,json:()=>JSON.parse(r),rawBody:r};let c=!1;for(const{config:i,target:d}of s){const y=I(i.secret,n);if(y===void 0||!await _(a,y,e.headers,r))continue;c=!0;const p=B(a,r);if(p)return p;const h=await i.map(o);if(!h)continue;const f=n[d.binding];if(!f||typeof f.create!="function")throw new g("INTERNAL",`@lunora/agent: no Workflow binding "${d.binding}" on env for an inbound-channel agent — run codegen/dev so wrangler.jsonc declares it`);return await U(f,h,a,await M(a,r))}return c?new Response(void 0,{status:204}):new Response("Invalid signature",{status:401})};export{J as dispatchAgentChannel,C as verifyDiscord,T as verifyGithub,x as verifySlack};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/agent",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.151",
|
|
4
4
|
"description": "Durable AI agents for Lunora: defineAgent compiles a replay-safe tool-loop onto Cloudflare Workflows, with DO SQLite threads and live message subscriptions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
"access": "public"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@lunora/ai": "1.0.0-alpha.
|
|
88
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
89
|
-
"@lunora/mail": "1.0.0-alpha.
|
|
90
|
-
"@lunora/server": "1.0.0-alpha.
|
|
87
|
+
"@lunora/ai": "1.0.0-alpha.102",
|
|
88
|
+
"@lunora/errors": "1.0.0-alpha.47",
|
|
89
|
+
"@lunora/mail": "1.0.0-alpha.93",
|
|
90
|
+
"@lunora/server": "1.0.0-alpha.158",
|
|
91
91
|
"@lunora/values": "1.0.0-alpha.57",
|
|
92
92
|
"@lunora/workflow": "1.0.0-alpha.68",
|
|
93
93
|
"@modelcontextprotocol/sdk": "^1.30.0",
|