@muretai/agent-entry 1.5.0 → 1.6.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/muretai-agent-entry.mjs +40 -0
- package/package.json +1 -1
package/muretai-agent-entry.mjs
CHANGED
|
@@ -2239,6 +2239,25 @@ export function canonicalMount(canonUrl, basePath) {
|
|
|
2239
2239
|
* Recognition only ever ADDS identity (env.wba_did, the wbaVisits
|
|
2240
2240
|
* count); it never changes verified, a ledger row, a rate lane or any
|
|
2241
2241
|
* refusal verdict.
|
|
2242
|
+
* observer OPTIONAL `(env) => void` — a WATCHER, called once per message with the
|
|
2243
|
+
* same frozen envelope the responder gets. It exists so that OBSERVING a
|
|
2244
|
+
* visit is not the same edit as ANSWERING one: wanting a counter should
|
|
2245
|
+
* not mean reaching into the code that decides what to say.
|
|
2246
|
+
*
|
|
2247
|
+
* IT CANNOT AFFECT ANYTHING. It is called AFTER the verdict is settled,
|
|
2248
|
+
* its return value is discarded, a thrown error is swallowed, and a
|
|
2249
|
+
* promise is never awaited — so a slow or broken watcher cannot delay,
|
|
2250
|
+
* fail, or change one byte of the signed reply. That is the whole contract
|
|
2251
|
+
* and it is not a formality: this door answers in ONE round trip with no
|
|
2252
|
+
* callback, and a watcher that dialled out on the hot path would make the
|
|
2253
|
+
* visitor's answer depend on somebody else's uptime.
|
|
2254
|
+
*
|
|
2255
|
+
* WHAT NOT TO PUT IN IT. The envelope carries `peer_did`/`owner_did`,
|
|
2256
|
+
* which a visitor handed you to transact with YOU. Forwarding a raw DID to
|
|
2257
|
+
* a third party shares a durable identifier its owner never offered them;
|
|
2258
|
+
* if you need a metric, send a salted, site-scoped digest and keep the DID
|
|
2259
|
+
* in your own store. This module ships no sink and names no vendor — the
|
|
2260
|
+
* slot is here so an adapter can live outside it.
|
|
2242
2261
|
*/
|
|
2243
2262
|
export function createAgentEntry({
|
|
2244
2263
|
seedHex,
|
|
@@ -2258,6 +2277,7 @@ export function createAgentEntry({
|
|
|
2258
2277
|
guest = false,
|
|
2259
2278
|
maxAccounts = 50000,
|
|
2260
2279
|
howToUrl = FIRST_KNOCK_URL,
|
|
2280
|
+
observer = null,
|
|
2261
2281
|
wbaVerifiers = null,
|
|
2262
2282
|
} = {}) {
|
|
2263
2283
|
if (!seedHex) throw new TypeError('createAgentEntry: seedHex is required');
|
|
@@ -2896,7 +2916,27 @@ export function createAgentEntry({
|
|
|
2896
2916
|
wbaDid: wbaIdentify(reqHeaders) }), reqId, msg, from);
|
|
2897
2917
|
}
|
|
2898
2918
|
|
|
2919
|
+
/** Hand the envelope to the watcher, and make sure it can cost nothing.
|
|
2920
|
+
*
|
|
2921
|
+
* Called BEFORE the responder on purpose: observing that a visit HAPPENED must not
|
|
2922
|
+
* depend on the answer succeeding, or the one request worth counting — the one where
|
|
2923
|
+
* the site's own code threw — is the one that goes uncounted.
|
|
2924
|
+
*
|
|
2925
|
+
* Everything here is a refusal to let a watcher matter: the return value is discarded,
|
|
2926
|
+
* a synchronous throw is swallowed, and a returned promise is given a rejection handler
|
|
2927
|
+
* and then DROPPED rather than awaited. That last one is not tidiness — an unhandled
|
|
2928
|
+
* rejection can take a Node process down, so the watcher must not be able to end the
|
|
2929
|
+
* door by failing quietly in the background. */
|
|
2930
|
+
function observe(env) {
|
|
2931
|
+
if (typeof observer !== 'function') return;
|
|
2932
|
+
try {
|
|
2933
|
+
const r = observer(env);
|
|
2934
|
+
if (isThenable(r)) r.then(undefined, () => {});
|
|
2935
|
+
} catch { /* a watcher never changes what this door does */ }
|
|
2936
|
+
}
|
|
2937
|
+
|
|
2899
2938
|
function respond(env, reqId, msg, toDid) {
|
|
2939
|
+
observe(env);
|
|
2900
2940
|
let answer;
|
|
2901
2941
|
try {
|
|
2902
2942
|
answer = responder(env);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muretai/agent-entry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Make your website answer AI agents: an A2A agent endpoint that verifies who is knocking, opens an account for them and replies signed, in one HTTP round trip. Zero dependencies. Pairs with llms.txt and WebMCP.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "muretai-agent-entry.mjs",
|