@agenticprimitives/a2a 0.0.0-alpha.5 → 0.0.0-alpha.51
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/CLAUDE.md +40 -55
- package/README.md +44 -1
- package/bin/a2a-conform.mjs +17 -0
- package/dist/agent.d.ts +211 -7
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +615 -76
- package/dist/agent.js.map +1 -1
- package/dist/auth.d.ts +108 -11
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +169 -56
- package/dist/auth.js.map +1 -1
- package/dist/authority-extension.d.ts +58 -0
- package/dist/authority-extension.d.ts.map +1 -0
- package/dist/authority-extension.js +70 -0
- package/dist/authority-extension.js.map +1 -0
- package/dist/card-audience.d.ts +87 -0
- package/dist/card-audience.d.ts.map +1 -0
- package/dist/card-audience.js +135 -0
- package/dist/card-audience.js.map +1 -0
- package/dist/client.d.ts +23 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +76 -13
- package/dist/client.js.map +1 -1
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/index.js +10 -2
- package/dist/cloudflare/index.js.map +1 -1
- package/dist/conform/index.d.ts +36 -0
- package/dist/conform/index.d.ts.map +1 -0
- package/dist/conform/index.js +247 -0
- package/dist/conform/index.js.map +1 -0
- package/dist/discovery.d.ts +4 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +6 -2
- package/dist/discovery.js.map +1 -1
- package/dist/engagement.d.ts +37 -0
- package/dist/engagement.d.ts.map +1 -0
- package/dist/engagement.js +83 -0
- package/dist/engagement.js.map +1 -0
- package/dist/grant.d.ts +4 -2
- package/dist/grant.d.ts.map +1 -1
- package/dist/grant.js +21 -13
- package/dist/grant.js.map +1 -1
- package/dist/handoff.d.ts +42 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +28 -0
- package/dist/handoff.js.map +1 -0
- package/dist/index.d.ts +30 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -5
- package/dist/index.js.map +1 -1
- package/dist/payment-gate.d.ts +69 -3
- package/dist/payment-gate.d.ts.map +1 -1
- package/dist/payment-gate.js +36 -5
- package/dist/payment-gate.js.map +1 -1
- package/dist/placeholder.d.ts +5 -0
- package/dist/placeholder.d.ts.map +1 -0
- package/dist/placeholder.js +10 -0
- package/dist/placeholder.js.map +1 -0
- package/dist/run-provenance-extension.d.ts +22 -0
- package/dist/run-provenance-extension.d.ts.map +1 -0
- package/dist/run-provenance-extension.js +23 -0
- package/dist/run-provenance-extension.js.map +1 -0
- package/dist/runtime.d.ts +13 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +62 -16
- package/dist/runtime.js.map +1 -1
- package/dist/session-wire.d.ts +114 -0
- package/dist/session-wire.d.ts.map +1 -0
- package/dist/session-wire.js +292 -0
- package/dist/session-wire.js.map +1 -0
- package/dist/skill-handler.d.ts +21 -1
- package/dist/skill-handler.d.ts.map +1 -1
- package/dist/skill-handler.js.map +1 -1
- package/dist/standard/app-delegation.d.ts +60 -0
- package/dist/standard/app-delegation.d.ts.map +1 -0
- package/dist/standard/app-delegation.js +43 -0
- package/dist/standard/app-delegation.js.map +1 -0
- package/dist/standard/caller.d.ts +115 -0
- package/dist/standard/caller.d.ts.map +1 -0
- package/dist/standard/caller.js +186 -0
- package/dist/standard/caller.js.map +1 -0
- package/dist/standard/client.d.ts +64 -0
- package/dist/standard/client.d.ts.map +1 -0
- package/dist/standard/client.js +109 -0
- package/dist/standard/client.js.map +1 -0
- package/dist/standard/delegated.d.ts +127 -0
- package/dist/standard/delegated.d.ts.map +1 -0
- package/dist/standard/delegated.js +179 -0
- package/dist/standard/delegated.js.map +1 -0
- package/dist/standard/errors.d.ts +31 -0
- package/dist/standard/errors.d.ts.map +1 -0
- package/dist/standard/errors.js +75 -0
- package/dist/standard/errors.js.map +1 -0
- package/dist/standard/from-agent.d.ts +43 -0
- package/dist/standard/from-agent.d.ts.map +1 -0
- package/dist/standard/from-agent.js +149 -0
- package/dist/standard/from-agent.js.map +1 -0
- package/dist/standard/index.d.ts +12 -0
- package/dist/standard/index.d.ts.map +1 -0
- package/dist/standard/index.js +18 -0
- package/dist/standard/index.js.map +1 -0
- package/dist/standard/mount.d.ts +101 -0
- package/dist/standard/mount.d.ts.map +1 -0
- package/dist/standard/mount.js +186 -0
- package/dist/standard/mount.js.map +1 -0
- package/dist/standard/outbound-fetch.d.ts +51 -0
- package/dist/standard/outbound-fetch.d.ts.map +1 -0
- package/dist/standard/outbound-fetch.js +152 -0
- package/dist/standard/outbound-fetch.js.map +1 -0
- package/dist/standard/push-url-policy.d.ts +34 -0
- package/dist/standard/push-url-policy.d.ts.map +1 -0
- package/dist/standard/push-url-policy.js +218 -0
- package/dist/standard/push-url-policy.js.map +1 -0
- package/dist/standard/server.d.ts +150 -0
- package/dist/standard/server.d.ts.map +1 -0
- package/dist/standard/server.js +575 -0
- package/dist/standard/server.js.map +1 -0
- package/dist/standard/types.d.ts +186 -0
- package/dist/standard/types.d.ts.map +1 -0
- package/dist/standard/types.js +14 -0
- package/dist/standard/types.js.map +1 -0
- package/dist/subject-ask.d.ts +142 -0
- package/dist/subject-ask.d.ts.map +1 -0
- package/dist/subject-ask.js +137 -0
- package/dist/subject-ask.js.map +1 -0
- package/dist/subject-hop.d.ts +156 -0
- package/dist/subject-hop.d.ts.map +1 -0
- package/dist/subject-hop.js +276 -0
- package/dist/subject-hop.js.map +1 -0
- package/dist/task-store.d.ts +9 -3
- package/dist/task-store.d.ts.map +1 -1
- package/dist/task-store.js +12 -6
- package/dist/task-store.js.map +1 -1
- package/dist/types.d.ts +27 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wire-verify.d.ts +35 -0
- package/dist/wire-verify.d.ts.map +1 -0
- package/dist/wire-verify.js +55 -0
- package/dist/wire-verify.js.map +1 -0
- package/package.json +35 -12
- package/dist/jsonrpc.d.ts +0 -25
- package/dist/jsonrpc.d.ts.map +0 -1
- package/dist/jsonrpc.js +0 -52
- package/dist/jsonrpc.js.map +0 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** The extension URI. Versioned in the path: a change to what the authority model REQUIRES is a new
|
|
2
|
+
* URI, not a silent redefinition of this one — a peer must be able to detect the difference. */
|
|
3
|
+
export declare const AP_AUTHORITY_EXTENSION_URI = "https://agenticprimitives.org/a2a/authority/v1";
|
|
4
|
+
/** The activation header stock A2A defines for extensions; clients opt in by naming the URI. */
|
|
5
|
+
export declare const A2A_EXTENSIONS_HEADER = "X-A2A-Extensions";
|
|
6
|
+
/**
|
|
7
|
+
* How a caller proves it may invoke a skill. Both forms resolve to the SAME question — "does the
|
|
8
|
+
* principal SA authorize this actor for this selector, right now?" — and neither is a bearer grant.
|
|
9
|
+
*/
|
|
10
|
+
export type ApAuthorityMethod =
|
|
11
|
+
/** A signed, caveated delegation naming the acting agent, verified against the principal SA
|
|
12
|
+
* (ERC-1271 / 6492 / ECDSA / WebAuthn via UniversalSignatureValidator). */
|
|
13
|
+
'delegation'
|
|
14
|
+
/** A Home-issued session wire bound to the person SA — custody-scoped, not a peer grant. */
|
|
15
|
+
| 'session-wire'
|
|
16
|
+
/** A signed mandate: a scoped delegation plus an explicit, signed statement of intent. Used where a
|
|
17
|
+
* human decision must be attributable, not merely permitted. */
|
|
18
|
+
| 'mandate';
|
|
19
|
+
export interface ApAuthorityExtensionParams {
|
|
20
|
+
/** Which proof forms this deployment accepts. Order is not precedence — the server decides. */
|
|
21
|
+
methods: readonly ApAuthorityMethod[];
|
|
22
|
+
/** CAIP-2 chain the principal SA and its delegations live on, so a peer resolves against the right
|
|
23
|
+
* chain rather than guessing from an address. */
|
|
24
|
+
chain: string;
|
|
25
|
+
/** Whether activation is required to call ANY skill. Almost always false: peer-callable skills are
|
|
26
|
+
* the point, and a required extension excludes clients that could otherwise interoperate. */
|
|
27
|
+
required?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface ApAuthorityExtension {
|
|
30
|
+
uri: string;
|
|
31
|
+
required: boolean;
|
|
32
|
+
description: string;
|
|
33
|
+
/** Machine-readable params. A peer MUST be able to act on this without parsing prose. */
|
|
34
|
+
params: {
|
|
35
|
+
methods: readonly ApAuthorityMethod[];
|
|
36
|
+
chain: string;
|
|
37
|
+
/** Stated explicitly so no client infers otherwise from the presence of a bearer envelope. */
|
|
38
|
+
bearerIsEnvelopeOnly: true;
|
|
39
|
+
/** Authority is re-checked at the moment of acting; a prior success is not a durable capability. */
|
|
40
|
+
reEvaluatedPerCall: true;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build the Card's authority extension.
|
|
45
|
+
*
|
|
46
|
+
* `bearerIsEnvelopeOnly` and `reEvaluatedPerCall` are literal `true` in the type, not booleans a
|
|
47
|
+
* deployment can set. They are not configuration — a deployment that wanted to say otherwise would be
|
|
48
|
+
* describing a different system, and the type refuses to let it say so on our Card (ADR-0041).
|
|
49
|
+
*/
|
|
50
|
+
export declare function apAuthorityExtension(params: ApAuthorityExtensionParams): ApAuthorityExtension;
|
|
51
|
+
/** Whether a client activated the extension, per the stock `X-A2A-Extensions` header.
|
|
52
|
+
*
|
|
53
|
+
* NOTE: activation is a CLIENT HINT and nothing more. It reports which extensions the caller
|
|
54
|
+
* understands; it does not authorize, and a server MUST NOT treat activation as a reason to relax any
|
|
55
|
+
* check. A caller that activates nothing still faces the same authority decision — the extension is
|
|
56
|
+
* documentation of the question, not a way to change the answer. */
|
|
57
|
+
export declare function activatesApAuthority(header: string | null | undefined): boolean;
|
|
58
|
+
//# sourceMappingURL=authority-extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authority-extension.d.ts","sourceRoot":"","sources":["../src/authority-extension.ts"],"names":[],"mappings":"AAuBA;iGACiG;AACjG,eAAO,MAAM,0BAA0B,mDAAmD,CAAC;AAE3F,gGAAgG;AAChG,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,iBAAiB;AAC3B;4EAC4E;AAC1E,YAAY;AACd,4FAA4F;GAC1F,cAAc;AAChB;iEACiE;GAC/D,SAAS,CAAC;AAEd,MAAM,WAAW,0BAA0B;IACzC,+FAA+F;IAC/F,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACtC;sDACkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd;kGAC8F;IAC9F,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,MAAM,EAAE;QACN,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAC;QACtC,KAAK,EAAE,MAAM,CAAC;QACd,8FAA8F;QAC9F,oBAAoB,EAAE,IAAI,CAAC;QAC3B,oGAAoG;QACpG,kBAAkB,EAAE,IAAI,CAAC;KAC1B,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAqB7F;AAED;;;;;qEAKqE;AACrE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAM/E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The AP authority extension for the Agent Card (ADR-0059 / spec 341 §2.1).
|
|
2
|
+
//
|
|
3
|
+
// THE PROBLEM IT SOLVES. The Card declares no `securitySchemes` — not a wrong one, none. A peer reading
|
|
4
|
+
// it learns which skills exist and nothing about how to be allowed to call them. Every caller therefore
|
|
5
|
+
// needs out-of-band knowledge, which is the definition of a private RPC surface wearing a protocol's
|
|
6
|
+
// clothes. Declaring the authority model is what makes the difference between a protocol and skill-RPC
|
|
7
|
+
// cosplay, and it is the thing that lets an EXTERNAL agent use the same skills the Home uses — spec
|
|
8
|
+
// 341's actual success test.
|
|
9
|
+
//
|
|
10
|
+
// WHY AN EXTENSION AND NOT A `securityScheme`. Stock A2A's security schemes are OAuth2 / OIDC / API-key
|
|
11
|
+
// / mTLS — all of them bearer-shaped, all of them "the issuer says you may". Declaring one of those
|
|
12
|
+
// would assert something false about this substrate: here the grant is an ERC-4337-SA-bound,
|
|
13
|
+
// signature-verified, on-chain-revocable **delegation**, re-evaluated at the moment of acting, and a
|
|
14
|
+
// bearer token is at most an envelope carrying a reference to it (ADR-0041). Picking the nearest stock
|
|
15
|
+
// scheme to look compliant would invert the exact property that distinguishes this system, so the
|
|
16
|
+
// authority model is declared as a first-class `AgentExtension` instead — the same mechanism this
|
|
17
|
+
// package already ships for x402 pricing.
|
|
18
|
+
//
|
|
19
|
+
// WHAT THIS EXTENSION IS NOT. It is not authority. Advertising it grants nothing, and a caller that
|
|
20
|
+
// activates it is not thereby authorized; it tells a peer WHICH question will be asked of it, never
|
|
21
|
+
// what the answer will be. The decision still happens server-side against the principal SA, at the
|
|
22
|
+
// moment of acting, every time (ADR-0041, ADR-0043).
|
|
23
|
+
/** The extension URI. Versioned in the path: a change to what the authority model REQUIRES is a new
|
|
24
|
+
* URI, not a silent redefinition of this one — a peer must be able to detect the difference. */
|
|
25
|
+
export const AP_AUTHORITY_EXTENSION_URI = 'https://agenticprimitives.org/a2a/authority/v1';
|
|
26
|
+
/** The activation header stock A2A defines for extensions; clients opt in by naming the URI. */
|
|
27
|
+
export const A2A_EXTENSIONS_HEADER = 'X-A2A-Extensions';
|
|
28
|
+
/**
|
|
29
|
+
* Build the Card's authority extension.
|
|
30
|
+
*
|
|
31
|
+
* `bearerIsEnvelopeOnly` and `reEvaluatedPerCall` are literal `true` in the type, not booleans a
|
|
32
|
+
* deployment can set. They are not configuration — a deployment that wanted to say otherwise would be
|
|
33
|
+
* describing a different system, and the type refuses to let it say so on our Card (ADR-0041).
|
|
34
|
+
*/
|
|
35
|
+
export function apAuthorityExtension(params) {
|
|
36
|
+
if (params.methods.length === 0) {
|
|
37
|
+
// An authority extension that accepts nothing is not a lean Card, it is a broken one: it tells a
|
|
38
|
+
// peer to authorize and gives it no way to. Fail loudly at build time (ADR-0013 — empty is an
|
|
39
|
+
// answer, and here it is the wrong one).
|
|
40
|
+
throw new Error('apAuthorityExtension: at least one authority method must be declared');
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
uri: AP_AUTHORITY_EXTENSION_URI,
|
|
44
|
+
required: params.required ?? false,
|
|
45
|
+
description: 'Authorization is an on-chain delegation decision against the principal Smart Agent, verified by ' +
|
|
46
|
+
'signature and re-evaluated at the moment of acting. A bearer token is a transport envelope only ' +
|
|
47
|
+
'and never the grant.',
|
|
48
|
+
params: {
|
|
49
|
+
methods: params.methods,
|
|
50
|
+
chain: params.chain,
|
|
51
|
+
bearerIsEnvelopeOnly: true,
|
|
52
|
+
reEvaluatedPerCall: true,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Whether a client activated the extension, per the stock `X-A2A-Extensions` header.
|
|
57
|
+
*
|
|
58
|
+
* NOTE: activation is a CLIENT HINT and nothing more. It reports which extensions the caller
|
|
59
|
+
* understands; it does not authorize, and a server MUST NOT treat activation as a reason to relax any
|
|
60
|
+
* check. A caller that activates nothing still faces the same authority decision — the extension is
|
|
61
|
+
* documentation of the question, not a way to change the answer. */
|
|
62
|
+
export function activatesApAuthority(header) {
|
|
63
|
+
if (!header)
|
|
64
|
+
return false;
|
|
65
|
+
return header
|
|
66
|
+
.split(',')
|
|
67
|
+
.map((s) => s.trim())
|
|
68
|
+
.includes(AP_AUTHORITY_EXTENSION_URI);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=authority-extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authority-extension.js","sourceRoot":"","sources":["../src/authority-extension.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,wGAAw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,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type VerifiedPeerContextV1 } from '@agenticprimitives/types';
|
|
2
|
+
import type { AgentCardAudience } from './agent.js';
|
|
3
|
+
/** What a requester presents to claim a wider card audience. All fields required to get past `public`. */
|
|
4
|
+
export interface CardAudienceClaim {
|
|
5
|
+
/** Claimed canonical id (CAIP-10) or address. Unverified until the signature checks out. */
|
|
6
|
+
requester?: string;
|
|
7
|
+
/** A nonce issued by THIS host. Single-use. */
|
|
8
|
+
challengeNonce?: string;
|
|
9
|
+
signature?: `0x${string}`;
|
|
10
|
+
issuedAt?: string;
|
|
11
|
+
/** The view being asked for. Never granted on its own — this is a request, not a grant. */
|
|
12
|
+
requestedView?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The body a requester signs. Binds the host and the view so a proof is not portable. */
|
|
15
|
+
export interface CardChallengeBody {
|
|
16
|
+
requester: string;
|
|
17
|
+
challengeNonce: string;
|
|
18
|
+
/** This host's origin — a proof for one agent's card must not work at another's. */
|
|
19
|
+
cardOrigin: string;
|
|
20
|
+
requestedView: 'authenticated' | 'private';
|
|
21
|
+
issuedAt: string;
|
|
22
|
+
}
|
|
23
|
+
/** Injected signature verification — satisfied by a `chain-state` reader wrapper. */
|
|
24
|
+
export type CardSignatureVerifier = (args: {
|
|
25
|
+
requester: string;
|
|
26
|
+
body: CardChallengeBody;
|
|
27
|
+
signature: `0x${string}`;
|
|
28
|
+
}) => Promise<boolean>;
|
|
29
|
+
/** Single-use nonce consumption. Returns false if already spent or unknown to this host. */
|
|
30
|
+
export type CardNonceConsumer = (nonce: string, cardOrigin: string) => Promise<boolean>;
|
|
31
|
+
export interface CardAudienceResolverOptions {
|
|
32
|
+
/** This host's canonical origin. A proof bound to another origin is refused. */
|
|
33
|
+
cardOrigin: string;
|
|
34
|
+
verifySignature: CardSignatureVerifier;
|
|
35
|
+
consumeNonce: CardNonceConsumer;
|
|
36
|
+
now: () => string;
|
|
37
|
+
/** Maximum age of a claim. Default 2 minutes. */
|
|
38
|
+
maxClaimAgeMs?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Decides whether a VERIFIED requester may see the `private` view, and is the only place a private
|
|
41
|
+
* audience can be granted. Omit ⇒ a verified requester reaches `authenticated` and no further.
|
|
42
|
+
*
|
|
43
|
+
* Kept separate from signature verification because they answer different questions: the signature
|
|
44
|
+
* says *who* is asking; this says *what that party is entitled to see*.
|
|
45
|
+
*/
|
|
46
|
+
privateViewPolicy?: (requester: string) => Promise<boolean>;
|
|
47
|
+
/** Local-only diagnostics. Never surfaced to the requester. */
|
|
48
|
+
observe?: (o: {
|
|
49
|
+
granted: AgentCardAudience['audience'];
|
|
50
|
+
reason?: string;
|
|
51
|
+
}) => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* When the TRANSPORT already authenticated the peer (spec 338 W5-b), a separate card challenge is
|
|
55
|
+
* redundant — the connection itself proved who is asking.
|
|
56
|
+
*
|
|
57
|
+
* Accepted ONLY at `strength: 'agent'` (`isAgentAuthenticatedPeer`). Web PKI authenticates a
|
|
58
|
+
* hostname and SPIFFE a workload; neither is a Smart Agent, and treating either as one is exactly
|
|
59
|
+
* the conflation `VerifiedPeerContextV1` exists to prevent.
|
|
60
|
+
*
|
|
61
|
+
* NOTE this does not imply relay resistance: without a channel binding an active relay could be the
|
|
62
|
+
* party on the connection. Hosts that need that guarantee should require a channel-bound peer at the
|
|
63
|
+
* edge rather than loosening anything here.
|
|
64
|
+
*/
|
|
65
|
+
export interface PeerBackedAudienceInput {
|
|
66
|
+
peerContext?: VerifiedPeerContextV1;
|
|
67
|
+
}
|
|
68
|
+
/** The public audience — the floor, and the answer to every failed claim. */
|
|
69
|
+
export declare const PUBLIC_AUDIENCE: AgentCardAudience;
|
|
70
|
+
/**
|
|
71
|
+
* Build the resolver a card route calls to turn a request into an audience.
|
|
72
|
+
*
|
|
73
|
+
* Never throws. Never returns an audience wider than the claim proved.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createCardAudienceResolver(opts: CardAudienceResolverOptions): (claim: CardAudienceClaim, peer?: PeerBackedAudienceInput) => Promise<AgentCardAudience>;
|
|
76
|
+
/**
|
|
77
|
+
* Read a claim from standard request inputs.
|
|
78
|
+
*
|
|
79
|
+
* The signature and nonce come from HEADERS, never the query string: a query parameter lands in
|
|
80
|
+
* access logs, `Referer` headers, and browser history, and a proof that leaks that way is a replay
|
|
81
|
+
* waiting to happen. `view` stays in the query because it is a request, not a secret.
|
|
82
|
+
*/
|
|
83
|
+
export declare function readCardAudienceClaim(input: {
|
|
84
|
+
query: (k: string) => string | undefined;
|
|
85
|
+
header: (k: string) => string | undefined;
|
|
86
|
+
}): CardAudienceClaim;
|
|
87
|
+
//# sourceMappingURL=card-audience.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-audience.d.ts","sourceRoot":"","sources":["../src/card-audience.ts"],"names":[],"mappings":"AAoBA,OAAO,EAA4B,KAAK,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAChG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,0GAA0G;AAC1G,MAAM,WAAW,iBAAiB;IAChC,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,0FAA0F;AAC1F,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,oFAAoF;IACpF,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,eAAe,GAAG,SAAS,CAAC;IAC3C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qFAAqF;AACrF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AAG,SAAS,CAAC;IACzC,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC3C,GAAG,iBAAiB,CAQpB"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Card-audience authentication (spec 338 §8, W4-b).
|
|
2
|
+
//
|
|
3
|
+
// THE HOLE THIS CLOSES: hosts were serving the extended card on a QUERY PARAMETER
|
|
4
|
+
// (`?view=authenticated`). Anyone could type it. The extended card is supposed to reveal fine-grained
|
|
5
|
+
// skills to *verified* callers, so a parameter that anyone can set makes the split decorative.
|
|
6
|
+
//
|
|
7
|
+
// A requester now proves control of its Smart Agent by signing a challenge bound to
|
|
8
|
+
// {requester, nonce, cardOrigin, requestedView, issuedAt}. Verification goes through the injected
|
|
9
|
+
// signature port — the same `UniversalSignatureValidator` surface used everywhere else, so EOA,
|
|
10
|
+
// ERC-1271, ERC-6492 and passkey credentials all work unchanged.
|
|
11
|
+
//
|
|
12
|
+
// ─── DEGRADE, DON'T DENY ────────────────────────────────────────────────────────────────────────
|
|
13
|
+
// Every failure resolves to `{ audience: 'public' }` rather than an error. That is deliberate and it
|
|
14
|
+
// IS the fail-closed choice here: the public card is genuinely public, so the safe fallback is
|
|
15
|
+
// LEAST DISCLOSURE, not a 401. It also means a plain unauthenticated `curl` keeps working, which is
|
|
16
|
+
// the whole point of a well-known card.
|
|
17
|
+
//
|
|
18
|
+
// The rule to hold onto: a failed proof must never widen the audience. It can only ever leave it at
|
|
19
|
+
// `public`.
|
|
20
|
+
import { isAgentAuthenticatedPeer } from '@agenticprimitives/types';
|
|
21
|
+
const DEFAULT_MAX_CLAIM_AGE_MS = 2 * 60 * 1000;
|
|
22
|
+
/** The public audience — the floor, and the answer to every failed claim. */
|
|
23
|
+
export const PUBLIC_AUDIENCE = { audience: 'public' };
|
|
24
|
+
function normalizeView(v) {
|
|
25
|
+
return v === 'authenticated' || v === 'private' ? v : null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build the resolver a card route calls to turn a request into an audience.
|
|
29
|
+
*
|
|
30
|
+
* Never throws. Never returns an audience wider than the claim proved.
|
|
31
|
+
*/
|
|
32
|
+
export function createCardAudienceResolver(opts) {
|
|
33
|
+
return async (claim, peer) => {
|
|
34
|
+
const deny = (reason) => {
|
|
35
|
+
opts.observe?.({ granted: 'public', reason });
|
|
36
|
+
return PUBLIC_AUDIENCE;
|
|
37
|
+
};
|
|
38
|
+
const view = normalizeView(claim.requestedView);
|
|
39
|
+
// No wider view requested — nothing to verify, and nothing to grant.
|
|
40
|
+
if (!view)
|
|
41
|
+
return PUBLIC_AUDIENCE;
|
|
42
|
+
// Transport-authenticated peer: the connection already proved who is asking, so skip the card
|
|
43
|
+
// challenge. Anything below `agent` strength falls through to the normal challenge path — it has
|
|
44
|
+
// NOT identified a Smart Agent.
|
|
45
|
+
if (peer?.peerContext && isAgentAuthenticatedPeer(peer.peerContext)) {
|
|
46
|
+
const requester = peer.peerContext.canonicalAgentId;
|
|
47
|
+
if (view === 'private') {
|
|
48
|
+
let permitted = false;
|
|
49
|
+
try {
|
|
50
|
+
permitted = (await opts.privateViewPolicy?.(requester)) ?? false;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
permitted = false;
|
|
54
|
+
}
|
|
55
|
+
opts.observe?.({ granted: permitted ? 'private' : 'authenticated', reason: 'peer-authenticated' });
|
|
56
|
+
return { audience: permitted ? 'private' : 'authenticated', requester };
|
|
57
|
+
}
|
|
58
|
+
opts.observe?.({ granted: 'authenticated', reason: 'peer-authenticated' });
|
|
59
|
+
return { audience: 'authenticated', requester };
|
|
60
|
+
}
|
|
61
|
+
if (!claim.requester || !claim.challengeNonce || !claim.signature || !claim.issuedAt) {
|
|
62
|
+
// THE CLOSED HOLE: a bare `?view=authenticated` with no proof lands here and gets the public card.
|
|
63
|
+
return deny('incomplete-claim');
|
|
64
|
+
}
|
|
65
|
+
const issuedAt = Date.parse(claim.issuedAt);
|
|
66
|
+
const nowMs = Date.parse(opts.now());
|
|
67
|
+
if (Number.isNaN(issuedAt) || Number.isNaN(nowMs))
|
|
68
|
+
return deny('unparseable-timestamp');
|
|
69
|
+
if (Math.abs(nowMs - issuedAt) > (opts.maxClaimAgeMs ?? DEFAULT_MAX_CLAIM_AGE_MS)) {
|
|
70
|
+
return deny('stale-claim');
|
|
71
|
+
}
|
|
72
|
+
// Nonce BEFORE signature: a replayed claim must not make the host repeat an expensive chain read.
|
|
73
|
+
let fresh = false;
|
|
74
|
+
try {
|
|
75
|
+
fresh = await opts.consumeNonce(claim.challengeNonce, opts.cardOrigin);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
fresh = false;
|
|
79
|
+
}
|
|
80
|
+
if (!fresh)
|
|
81
|
+
return deny('nonce-spent-or-unknown');
|
|
82
|
+
const body = {
|
|
83
|
+
requester: claim.requester,
|
|
84
|
+
challengeNonce: claim.challengeNonce,
|
|
85
|
+
cardOrigin: opts.cardOrigin,
|
|
86
|
+
requestedView: view,
|
|
87
|
+
issuedAt: claim.issuedAt,
|
|
88
|
+
};
|
|
89
|
+
let valid = false;
|
|
90
|
+
try {
|
|
91
|
+
valid = await opts.verifySignature({ requester: claim.requester, body, signature: claim.signature });
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// A verifier that threw did not verify (ADR-0013: no fallback to a weaker check).
|
|
95
|
+
valid = false;
|
|
96
|
+
}
|
|
97
|
+
if (!valid)
|
|
98
|
+
return deny('signature-invalid');
|
|
99
|
+
if (view === 'private') {
|
|
100
|
+
let permitted = false;
|
|
101
|
+
try {
|
|
102
|
+
permitted = (await opts.privateViewPolicy?.(claim.requester)) ?? false;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
permitted = false;
|
|
106
|
+
}
|
|
107
|
+
if (!permitted) {
|
|
108
|
+
// Authenticated but not entitled to the private view — grant the level they DID earn.
|
|
109
|
+
opts.observe?.({ granted: 'authenticated', reason: 'private-not-permitted' });
|
|
110
|
+
return { audience: 'authenticated', requester: claim.requester };
|
|
111
|
+
}
|
|
112
|
+
opts.observe?.({ granted: 'private' });
|
|
113
|
+
return { audience: 'private', requester: claim.requester };
|
|
114
|
+
}
|
|
115
|
+
opts.observe?.({ granted: 'authenticated' });
|
|
116
|
+
return { audience: 'authenticated', requester: claim.requester };
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Read a claim from standard request inputs.
|
|
121
|
+
*
|
|
122
|
+
* The signature and nonce come from HEADERS, never the query string: a query parameter lands in
|
|
123
|
+
* access logs, `Referer` headers, and browser history, and a proof that leaks that way is a replay
|
|
124
|
+
* waiting to happen. `view` stays in the query because it is a request, not a secret.
|
|
125
|
+
*/
|
|
126
|
+
export function readCardAudienceClaim(input) {
|
|
127
|
+
return {
|
|
128
|
+
requestedView: input.query('view'),
|
|
129
|
+
requester: input.header('x-ap-requester'),
|
|
130
|
+
challengeNonce: input.header('x-ap-challenge'),
|
|
131
|
+
signature: input.header('x-ap-signature'),
|
|
132
|
+
issuedAt: input.header('x-ap-issued-at'),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=card-audience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card-audience.js","sourceRoot":"","sources":["../src/card-audience.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,EAAE;AACF,kFAAkF;AAClF,sGAAsG;AACtG,+FAA+F;AAC/F,EAAE;AACF,oFAAoF;AACpF,kGAAkG;AAClG,gGAAgG;AAChG,iEAAiE;AACjE,EAAE;AACF,mGAAmG;AACnG,qGAAqG;AACrG,+FAA+F;AAC/F,oGAAoG;AACpG,wCAAwC;AACxC,EAAE;AACF,oGAAoG;AACpG,YAAY;AAEZ,OAAO,EAAE,wBAAwB,EAA8B,MAAM,0BAA0B,CAAC;AAuEhG,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE/C,6E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C,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;YACvC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;QAC7C,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IACnE,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAGrC;IACC,OAAO;QACL,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;QAClC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC;QACzC,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC;QAC9C,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAA8B;QACtE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC;KACzC,CAAC;AACJ,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Address, Hex } from '@agenticprimitives/types';
|
|
2
2
|
import type { Delegation } from '@agenticprimitives/delegation';
|
|
3
3
|
import type { Task, TaskEvent, A2aMessage } from './types.js';
|
|
4
|
-
import type { JsonRpcRequest, JsonRpcResponse } from './
|
|
4
|
+
import type { ArtifactV1, JsonRpcRequest, JsonRpcResponse, TaskV1 } from './standard/types.js';
|
|
5
5
|
export interface A2aTransport {
|
|
6
|
-
/** POST a JSON-RPC request to `targetAgent`'s
|
|
6
|
+
/** POST a JSON-RPC request to `targetAgent`'s A2A endpoint and return the parsed response. */
|
|
7
7
|
rpc(targetAgent: Address, request: JsonRpcRequest): Promise<JsonRpcResponse>;
|
|
8
|
-
/** Open the
|
|
8
|
+
/** Open the streaming SSE for a task; yields events until terminal. Optional. */
|
|
9
9
|
stream?(targetAgent: Address, taskId: Hex): AsyncIterable<TaskEvent>;
|
|
10
10
|
}
|
|
11
11
|
export declare class A2aWireAdapter {
|
|
@@ -13,7 +13,10 @@ export declare class A2aWireAdapter {
|
|
|
13
13
|
private seq;
|
|
14
14
|
constructor(transport: A2aTransport);
|
|
15
15
|
private id;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Submit an async task. The `message` must already be signed by its sender (see `hashA2aMessage`); its
|
|
18
|
+
* envelope travels in the extension so the receiver re-derives the same digest.
|
|
19
|
+
*/
|
|
17
20
|
submitTask(targetAgent: Address, args: {
|
|
18
21
|
message: A2aMessage;
|
|
19
22
|
delegation: Delegation;
|
|
@@ -27,11 +30,23 @@ export declare class A2aWireAdapter {
|
|
|
27
30
|
taskId: Hex;
|
|
28
31
|
state: Task['state'];
|
|
29
32
|
}>;
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
/** Resubmit a parked (auth-required) task with a fresh grant + a newly signed message. */
|
|
34
|
+
resubmitTask(targetAgent: Address, taskId: Hex, args: {
|
|
35
|
+
message: A2aMessage;
|
|
36
|
+
delegation: Delegation;
|
|
37
|
+
requester: Address;
|
|
38
|
+
input: unknown;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
taskId: Hex;
|
|
41
|
+
state: Task['state'];
|
|
33
42
|
}>;
|
|
34
|
-
|
|
43
|
+
/** Poll a task. The caller is authenticated by the transport's `Authorization` header, not by params. */
|
|
44
|
+
getTask(targetAgent: Address, taskId: Hex): Promise<TaskV1>;
|
|
45
|
+
/** Read an artifact BODY (the delegated-task extension's `GetTaskArtifact`): the projection `getTask` returns
|
|
46
|
+
* carries only a ref and a hash. Authenticated the same way `getTask` is; a non-party reads not-found. */
|
|
47
|
+
getTaskArtifact(targetAgent: Address, taskId: Hex, artifactId: Hex): Promise<ArtifactV1>;
|
|
48
|
+
/** Cancel a task. Authenticated the same way `getTask` is. */
|
|
49
|
+
cancelTask(targetAgent: Address, taskId: Hex): Promise<{
|
|
35
50
|
taskId: Hex;
|
|
36
51
|
state: Task['state'];
|
|
37
52
|
}>;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAa,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG1G,MAAM,WAAW,YAAY;IAC3B,8FAA8F;IAC9F,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7E,iFAAiF;IACjF,MAAM,CAAC,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;CACtE;AA4BD,qBAAa,cAAc;IAEb,OAAO,CAAC,QAAQ,CAAC,SAAS;IADtC,OAAO,CAAC,GAAG,CAAK;gBACa,SAAS,EAAE,YAAY;IAEpD,OAAO,CAAC,EAAE;IAIV;;;OAGG;IACG,UAAU,CACd,WAAW,EAAE,OAAO,EACpB,IAAI,EAAE;QAAE,OAAO,EAAE,UAAU,CAAC;QAAC,UAAU,EAAE,UAAU,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GACtI,OAAO,CAAC;QAAE,MAAM,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IAiCjD,0FAA0F;IACpF,YAAY,CAChB,WAAW,EAAE,OAAO,EACpB,MAAM,EAAE,GAAG,EACX,IAAI,EAAE;QAAE,OAAO,EAAE,UAAU,CAAC;QAAC,UAAU,EAAE,UAAU,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GACxF,OAAO,CAAC;QAAE,MAAM,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IAejD,yGAAyG;IACnG,OAAO,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjE;+GAC2G;IACrG,eAAe,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;IAK9F,8DAA8D;IACxD,UAAU,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC;IAMnG,wGAAwG;IACxG,oBAAoB,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,aAAa,CAAC,SAAS,CAAC;CAIlF"}
|
package/dist/client.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
|
+
import { delegatedInputPart, taskStateFromV1, withDelegatedTask } from './standard/delegated.js';
|
|
2
|
+
/**
|
|
3
|
+
* The grant, JSON-safe. `Delegation.salt` is a bigint in the type and a decimal STRING on the wire, and
|
|
4
|
+
* `JSON.stringify` throws on a bigint — so a caller that holds the typed shape and one that received the
|
|
5
|
+
* wire shape both end up sending the same bytes. (Every sender in the estate already did this by hand.)
|
|
6
|
+
*
|
|
7
|
+
* A bigint is the ONLY thing changed. A grant the caller received as a wire is passed through untouched,
|
|
8
|
+
* field for field — inventing a default `salt` for one that carries none would make "the wire goes out as
|
|
9
|
+
* it came in" false, and that promise is the whole reason a re-minted grant is not required here.
|
|
10
|
+
*/
|
|
11
|
+
function grantToWire(d) {
|
|
12
|
+
const salt = d.salt;
|
|
13
|
+
if (typeof salt !== 'bigint')
|
|
14
|
+
return { ...d };
|
|
15
|
+
return { ...d, salt: salt.toString() };
|
|
16
|
+
}
|
|
1
17
|
function unwrap(res) {
|
|
2
18
|
if ('error' in res)
|
|
3
19
|
throw new Error(`a2a rpc error ${res.error.code}: ${res.error.message}`);
|
|
4
20
|
return res.result;
|
|
5
21
|
}
|
|
22
|
+
/** The 1.0 result of `SendMessage` is a task or a bare message; a delegated task is always a task. */
|
|
23
|
+
function taskOf(result) {
|
|
24
|
+
if (!result?.task)
|
|
25
|
+
throw new Error('a2a: SendMessage returned no task — a delegated task always creates one');
|
|
26
|
+
return result.task;
|
|
27
|
+
}
|
|
6
28
|
export class A2aWireAdapter {
|
|
7
29
|
transport;
|
|
8
30
|
seq = 0;
|
|
@@ -12,31 +34,72 @@ export class A2aWireAdapter {
|
|
|
12
34
|
id() {
|
|
13
35
|
return ++this.seq;
|
|
14
36
|
}
|
|
15
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Submit an async task. The `message` must already be signed by its sender (see `hashA2aMessage`); its
|
|
39
|
+
* envelope travels in the extension so the receiver re-derives the same digest.
|
|
40
|
+
*/
|
|
16
41
|
async submitTask(targetAgent, args) {
|
|
42
|
+
const m = args.message;
|
|
43
|
+
const carried = withDelegatedTask({
|
|
44
|
+
messageId: m.messageId,
|
|
45
|
+
role: 'ROLE_USER',
|
|
46
|
+
parts: [delegatedInputPart(args.input)],
|
|
47
|
+
...(m.threadId ? { contextId: m.threadId } : {}),
|
|
48
|
+
}, {
|
|
49
|
+
delegation: grantToWire(args.delegation),
|
|
50
|
+
requester: args.requester,
|
|
51
|
+
skill: m.skill,
|
|
52
|
+
sender: m.sender,
|
|
53
|
+
bodyHash: m.bodyHash,
|
|
54
|
+
bodyRef: m.bodyRef,
|
|
55
|
+
signature: m.signature,
|
|
56
|
+
createdAt: m.createdAt,
|
|
57
|
+
recipient: m.recipient,
|
|
58
|
+
chainId: m.chainId,
|
|
59
|
+
});
|
|
17
60
|
const res = await this.transport.rpc(targetAgent, {
|
|
18
|
-
jsonrpc: '2.0', id: this.id(), method: '
|
|
19
|
-
params: {
|
|
61
|
+
jsonrpc: '2.0', id: this.id(), method: 'SendMessage',
|
|
62
|
+
params: {
|
|
63
|
+
message: carried,
|
|
64
|
+
...(args.pushConfig ? { configuration: { taskPushNotificationConfig: args.pushConfig } } : {}),
|
|
65
|
+
},
|
|
20
66
|
});
|
|
21
|
-
|
|
67
|
+
const task = taskOf(unwrap(res));
|
|
68
|
+
return { taskId: task.id, state: taskStateFromV1(task.status.state) };
|
|
22
69
|
}
|
|
23
|
-
/**
|
|
24
|
-
async
|
|
25
|
-
const
|
|
26
|
-
|
|
70
|
+
/** Resubmit a parked (auth-required) task with a fresh grant + a newly signed message. */
|
|
71
|
+
async resubmitTask(targetAgent, taskId, args) {
|
|
72
|
+
const m = args.message;
|
|
73
|
+
const carried = withDelegatedTask({ messageId: m.messageId, role: 'ROLE_USER', parts: [delegatedInputPart(args.input)], taskId, ...(m.threadId ? { contextId: m.threadId } : {}) }, {
|
|
74
|
+
delegation: grantToWire(args.delegation), requester: args.requester, skill: m.skill, sender: m.sender,
|
|
75
|
+
bodyHash: m.bodyHash, bodyRef: m.bodyRef,
|
|
76
|
+
signature: m.signature, createdAt: m.createdAt, recipient: m.recipient, chainId: m.chainId, taskId,
|
|
27
77
|
});
|
|
78
|
+
const res = await this.transport.rpc(targetAgent, { jsonrpc: '2.0', id: this.id(), method: 'SendMessage', params: { message: carried } });
|
|
79
|
+
const task = taskOf(unwrap(res));
|
|
80
|
+
return { taskId: task.id, state: taskStateFromV1(task.status.state) };
|
|
81
|
+
}
|
|
82
|
+
/** Poll a task. The caller is authenticated by the transport's `Authorization` header, not by params. */
|
|
83
|
+
async getTask(targetAgent, taskId) {
|
|
84
|
+
const res = await this.transport.rpc(targetAgent, { jsonrpc: '2.0', id: this.id(), method: 'GetTask', params: { id: taskId } });
|
|
28
85
|
return unwrap(res);
|
|
29
86
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
87
|
+
/** Read an artifact BODY (the delegated-task extension's `GetTaskArtifact`): the projection `getTask` returns
|
|
88
|
+
* carries only a ref and a hash. Authenticated the same way `getTask` is; a non-party reads not-found. */
|
|
89
|
+
async getTaskArtifact(targetAgent, taskId, artifactId) {
|
|
90
|
+
const res = await this.transport.rpc(targetAgent, { jsonrpc: '2.0', id: this.id(), method: 'GetTaskArtifact', params: { id: taskId, artifactId } });
|
|
34
91
|
return unwrap(res);
|
|
35
92
|
}
|
|
93
|
+
/** Cancel a task. Authenticated the same way `getTask` is. */
|
|
94
|
+
async cancelTask(targetAgent, taskId) {
|
|
95
|
+
const res = await this.transport.rpc(targetAgent, { jsonrpc: '2.0', id: this.id(), method: 'CancelTask', params: { id: taskId } });
|
|
96
|
+
const task = unwrap(res);
|
|
97
|
+
return { taskId: task.id, state: taskStateFromV1(task.status.state) };
|
|
98
|
+
}
|
|
36
99
|
/** Subscribe to a task's status/artifact events (SSE). Requires a transport that supports streaming. */
|
|
37
100
|
subscribeTaskUpdates(targetAgent, taskId) {
|
|
38
101
|
if (!this.transport.stream)
|
|
39
|
-
throw new Error('transport does not support streaming (
|
|
102
|
+
throw new Error('transport does not support streaming (SubscribeToTask)');
|
|
40
103
|
return this.transport.stream(targetAgent, taskId);
|
|
41
104
|
}
|
|
42
105
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AASjG;;;;;;;;GAQG;AACH,SAAS,WAAW,CAAC,CAAkC;IACrD,MAAM,IAAI,GAAI,CAAwB,CAAC,IAAI,CAAC;IAC5C,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,GAAI,CAA6B,EAAE,CAAC;IAC3E,OAAO,EAAE,GAAI,CAA6B,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;AACtE,CAAC;AAED,SAAS,MAAM,CAAI,GAAoB;IACrC,IAAI,OAAO,IAAI,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC7F,OAAO,GAAG,CAAC,MAAW,CAAC;AACzB,CAAC;AAED,sGAAsG;AACtG,SAAS,MAAM,CAAC,MAA4C;IAC1D,IAAI,CAAC,MAAM,EAAE,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC9G,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED,MAAM,OAAO,cAAc;IAEI;IADrB,GAAG,GAAG,CAAC,CAAC;IAChB,YAA6B,SAAuB;QAAvB,cAAS,GAAT,SAAS,CAAc;IAAG,CAAC;IAEhD,EAAE;QACR,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CACd,WAAoB,EACpB,IAAuI;QAEvI,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,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AAC;QACjC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAS,EAAE,KAAK,EAAE,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC/E,CAAC;IAED,wGAAwG;IACxG,oBAAoB,CAAC,WAAoB,EAAE,MAAW;QACpD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QACtG,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloudflare/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAMlD;;qFAEqF;AACrF,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cloudflare/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAMlD;;qFAEqF;AACrF,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAmCrF;AAED,eAAO,MAAM,6BAA6B,EAAG,IAAa,CAAC"}
|
package/dist/cloudflare/index.js
CHANGED
|
@@ -27,11 +27,19 @@ export function createDurableObjectTaskStore(storage) {
|
|
|
27
27
|
return out;
|
|
28
28
|
},
|
|
29
29
|
async reserveMessageId(messageId) {
|
|
30
|
+
// Two-phase (spec 290 §3). The key's PRESENCE is the durable replay guard: a present key means the id
|
|
31
|
+
// is in-flight OR consumed → replay (deny). Reserve writes the key (in-flight); commit leaves it
|
|
32
|
+
// (permanently consumed); release deletes it so a legitimate retry of the same message may re-reserve.
|
|
33
|
+
// A crash between reserve and commit/release leaves the key present → that exact id can't retry
|
|
34
|
+
// (fail-closed; the sender mints a fresh messageId), which is the safe posture.
|
|
30
35
|
const k = MSG(messageId);
|
|
31
36
|
if ((await storage.get(k)) !== undefined)
|
|
32
|
-
return
|
|
37
|
+
return null;
|
|
33
38
|
await storage.put(k, 1);
|
|
34
|
-
return
|
|
39
|
+
return {
|
|
40
|
+
async commit() { },
|
|
41
|
+
async release() { await storage.delete(k); },
|
|
42
|
+
};
|
|
35
43
|
},
|
|
36
44
|
};
|
|
37
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cloudflare/index.ts"],"names":[],"mappings":"AAUA,MAAM,IAAI,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;AACxD,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;AACtD,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;AAEtD;;qFAEqF;AACrF,MAAM,UAAU,4BAA4B,CAAC,OAA6B;IACxE,OAAO;QACL,KAAK,CAAC,GAAG,CAAC,MAAkB;YAC1B,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;YACpC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzE,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,MAAM,OAAO,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