@agenticprimitives/a2a 0.0.0-alpha.5 → 0.0.0-alpha.50
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 +39 -55
- package/README.md +44 -1
- package/bin/a2a-conform.mjs +17 -0
- package/dist/agent.d.ts +203 -7
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +586 -76
- package/dist/agent.js.map +1 -1
- package/dist/auth.d.ts +84 -11
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +94 -20
- 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,152 @@
|
|
|
1
|
+
// WHAT THIS AGENT FETCHES ON SOMEONE ELSE'S WORD — spec 445 W0 (audit 2026-11-10, RUN-16 / RUNB-9).
|
|
2
|
+
//
|
|
3
|
+
// A card URL comes from a planner, a user or a registry record; the endpoint comes from the card. Unchecked, both
|
|
4
|
+
// are requests this host makes wherever another party points it, for as long and as large as the far side likes.
|
|
5
|
+
//
|
|
6
|
+
// THE RULE, at the one place every outbound card/agent call passes:
|
|
7
|
+
// · the URL is public https (`defaultPushUrlPolicy` — the same judgement a push destination gets: no loopback,
|
|
8
|
+
// link-local, private or local-by-construction host, no credentials in the URL);
|
|
9
|
+
// · no redirect is followed (a public address cannot hand the request on to a private one): the call is made with
|
|
10
|
+
// `redirect: 'manual'` (workerd rejects `'error'` with a TypeError — COR-5) and ANY 3xx, `redirected` or
|
|
11
|
+
// `opaqueredirect` answer is refused before its body is read;
|
|
12
|
+
// · the call is bounded in TIME (`AbortSignal.timeout`) and its body in SIZE (read through a counting reader —
|
|
13
|
+
// a `content-length` is the far side's claim, not a bound);
|
|
14
|
+
// · a credential leaves only to the card's OWN origin, unless the card is pinned by digest (then its endpoint is
|
|
15
|
+
// the name's word, not the server's) — `credentialDestinationRefusal`.
|
|
16
|
+
// Spec 445 residual (2026-11-10, RUN-16 — the two parts the W0 pass left open):
|
|
17
|
+
// · A NAME THAT RESOLVES TO A PRIVATE ADDRESS is refused when the deployment supplies `resolveHost` (the same port
|
|
18
|
+
// and the same address judgement push delivery uses — `checkPushUrl`): every address the name resolves to must be
|
|
19
|
+
// public, and a resolver that fails or answers nothing is a refusal. `requireResolution: true` makes the resolver
|
|
20
|
+
// MANDATORY — no resolver ⇒ nothing is fetched. With neither, the literal-host policy is the whole check, stated
|
|
21
|
+
// here and on the option: a host whose network can reach private ranges (not a Worker) must bind `resolveHost`.
|
|
22
|
+
// DNS rebinding between this check and the connection is not closed (a fetch-shaped port cannot pin an address).
|
|
23
|
+
// · A CARD RELIED ON FOR ROUTING OR AUTHORITY must be the agent's word: pinned by digest, or its signature verified
|
|
24
|
+
// by the caller's `verifyCardSignature` port (bound to the key the agent's on-chain record names — this package
|
|
25
|
+
// holds no key and reads no chain). `relyOnCard: true` without either is refused — `cardTrustRefusal`.
|
|
26
|
+
import { checkPushUrl, defaultPushUrlPolicy } from './push-url-policy.js';
|
|
27
|
+
export const OUTBOUND_CARD_MAX_BYTES = 256 * 1024;
|
|
28
|
+
export const OUTBOUND_REPLY_MAX_BYTES = 4 * 1024 * 1024;
|
|
29
|
+
export const OUTBOUND_TIMEOUT_MS = 15_000;
|
|
30
|
+
/** RUN-16 residual — why a card may not be relied on, or null when it may (or the caller does not rely on it).
|
|
31
|
+
* A pinned card is the name's word already; an unpinned one needs a verified signature. A verifier that is
|
|
32
|
+
* supplied is always run, relied on or not: a card that fails its signature is never used. */
|
|
33
|
+
export async function cardTrustRefusal(card, raw, pinned, trust = {}) {
|
|
34
|
+
if (trust.verifyCardSignature) {
|
|
35
|
+
let ok = false;
|
|
36
|
+
try {
|
|
37
|
+
ok = (await trust.verifyCardSignature(card, raw)) === true;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
ok = false;
|
|
41
|
+
}
|
|
42
|
+
return ok ? null : 'its card\'s signature does not verify against the agent\'s bound key — the card is not used';
|
|
43
|
+
}
|
|
44
|
+
if (trust.relyOnCard && !pinned)
|
|
45
|
+
return 'its card is relied on for routing or authority but is neither pinned by digest nor signature-verified — refused';
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** Why this URL may not be fetched — null when it may. */
|
|
49
|
+
export function outboundUrlRefusal(url, policy = defaultPushUrlPolicy) {
|
|
50
|
+
const d = policy(url);
|
|
51
|
+
return d.allow ? null : d.reason.replace(/\bpush URL\b/g, 'URL');
|
|
52
|
+
}
|
|
53
|
+
/** RUN-16 residual — the URL policy, then (with `resolveHost`) every address the host resolves to; with
|
|
54
|
+
* `requireResolution` and no resolver, a host name is refused. Null ⇒ may be fetched. */
|
|
55
|
+
export async function outboundUrlRefusalResolved(url, limits = {}) {
|
|
56
|
+
const literal = outboundUrlRefusal(url, limits.urlPolicy);
|
|
57
|
+
if (literal)
|
|
58
|
+
return literal;
|
|
59
|
+
let host = '';
|
|
60
|
+
try {
|
|
61
|
+
host = new URL(url).hostname;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return 'the URL is not a valid absolute URL';
|
|
65
|
+
}
|
|
66
|
+
const isLiteral = host.startsWith('[') || /^\d{1,3}(\.\d{1,3}){3}$/.test(host);
|
|
67
|
+
if (!limits.resolveHost)
|
|
68
|
+
return limits.requireResolution && !isLiteral ? `the host ${host} is not resolved by this deployment (requireResolution, no resolveHost) — refused` : null;
|
|
69
|
+
const d = await checkPushUrl(url, { ...(limits.urlPolicy ? { policy: limits.urlPolicy } : {}), resolveHost: limits.resolveHost });
|
|
70
|
+
return d.allow ? null : d.reason.replace(/\bpush URL\b/g, 'URL');
|
|
71
|
+
}
|
|
72
|
+
/** Read a body (a response's, or an inbound request's — RUN-18) as text, refusing past `maxBytes`. Counts the bytes
|
|
73
|
+
* actually received. */
|
|
74
|
+
export async function readTextBounded(res, maxBytes) {
|
|
75
|
+
const declared = Number(res.headers?.get?.('content-length') ?? NaN);
|
|
76
|
+
if (Number.isFinite(declared) && declared > maxBytes)
|
|
77
|
+
throw new Error(`the response declares ${declared} bytes, over the ${maxBytes}-byte limit`);
|
|
78
|
+
const reader = res.body?.getReader?.();
|
|
79
|
+
if (!reader) {
|
|
80
|
+
const text = await res.text();
|
|
81
|
+
if (new TextEncoder().encode(text).length > maxBytes)
|
|
82
|
+
throw new Error(`the response is over the ${maxBytes}-byte limit`);
|
|
83
|
+
return text;
|
|
84
|
+
}
|
|
85
|
+
const chunks = [];
|
|
86
|
+
let total = 0;
|
|
87
|
+
for (;;) {
|
|
88
|
+
const { done, value } = await reader.read();
|
|
89
|
+
if (done)
|
|
90
|
+
break;
|
|
91
|
+
total += value.byteLength;
|
|
92
|
+
// Cancel without awaiting: on one branch of a teed stream (a cloned Request/Response) the cancel promise settles
|
|
93
|
+
// only once the OTHER branch is cancelled too, so awaiting it here would hang the refusal.
|
|
94
|
+
if (total > maxBytes) {
|
|
95
|
+
reader.cancel().catch(() => undefined);
|
|
96
|
+
throw new Error(`the response is over the ${maxBytes}-byte limit`);
|
|
97
|
+
}
|
|
98
|
+
chunks.push(value);
|
|
99
|
+
}
|
|
100
|
+
const all = new Uint8Array(total);
|
|
101
|
+
let o = 0;
|
|
102
|
+
for (const c of chunks) {
|
|
103
|
+
all.set(c, o);
|
|
104
|
+
o += c.byteLength;
|
|
105
|
+
}
|
|
106
|
+
return new TextDecoder().decode(all);
|
|
107
|
+
}
|
|
108
|
+
/** One bounded outbound call: URL policy, no redirects, a deadline, a size cap. Throws with the reason in words. */
|
|
109
|
+
export async function fetchTextBounded(fetchImpl, url, init, limits) {
|
|
110
|
+
const refused = await outboundUrlRefusalResolved(url, limits);
|
|
111
|
+
if (refused)
|
|
112
|
+
throw new Error(`${url} is not fetched: ${refused}`);
|
|
113
|
+
const timeoutMs = limits.timeoutMs ?? OUTBOUND_TIMEOUT_MS;
|
|
114
|
+
const ctl = new AbortController();
|
|
115
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
116
|
+
try {
|
|
117
|
+
// `manual`, never `error` (COR-5: workerd throws a TypeError on `redirect: 'error'`, so every outbound call failed on
|
|
118
|
+
// Cloudflare). A redirect is then an ANSWER, refused here — never followed, its body never read.
|
|
119
|
+
const res = await fetchImpl(url, { ...init, redirect: 'manual', signal: ctl.signal });
|
|
120
|
+
if (res.redirected || (res.status >= 300 && res.status < 400) || res.type === 'opaqueredirect') {
|
|
121
|
+
void res.body?.cancel().catch(() => undefined);
|
|
122
|
+
throw new Error(`${url} answered with a redirect (HTTP ${res.status}) — redirect refused; it is not followed`);
|
|
123
|
+
}
|
|
124
|
+
const text = await readTextBounded(res, limits.maxBytes);
|
|
125
|
+
return { res, text };
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
if (ctl.signal.aborted)
|
|
129
|
+
throw new Error(`${url} did not answer within ${timeoutMs} ms`);
|
|
130
|
+
throw e;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** RUNB-9 — may a credential be sent to `endpoint`, which the card at `cardUrl` named? Only when the endpoint is on the
|
|
137
|
+
* card's own origin, or the card was pinned by digest (its content is then the name's word). Null ⇒ yes. */
|
|
138
|
+
export function credentialDestinationRefusal(cardUrl, endpoint, pinned) {
|
|
139
|
+
let cardOrigin;
|
|
140
|
+
let endpointOrigin;
|
|
141
|
+
try {
|
|
142
|
+
cardOrigin = new URL(cardUrl).origin;
|
|
143
|
+
endpointOrigin = new URL(endpoint).origin;
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return 'the card or its endpoint is not a URL';
|
|
147
|
+
}
|
|
148
|
+
if (cardOrigin === endpointOrigin || pinned)
|
|
149
|
+
return null;
|
|
150
|
+
return `its card (served at ${cardOrigin}, not pinned) names an endpoint on another origin (${endpointOrigin}) — a credential is never sent there`;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=outbound-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbound-fetch.js","sourceRoot":"","sources":["../../src/standard/outbound-fetch.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,EAAE;AACF,kHAAkH;AAClH,iHAAiH;AACjH,EAAE;AACF,oEAAoE;AACpE,iHAAiH;AACjH,qFAAqF;AACrF,oHAAoH;AACpH,6GAA6G;AAC7G,kEAAkE;AAClE,iHAAiH;AACjH,gEAAgE;AAChE,mHAAmH;AACnH,2EAA2E;AAC3E,gFAAgF;AAChF,qHAAqH;AACrH,sHAAsH;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I,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,0BAA0B,SAAS,KAAK,CAAC,CAAC;QACxF,MAAM,CAAC,CAAC;IACV,CAAC;YAAS,CAAC;QAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAAC,CAAC;AACpC,CAAC;AAED;6GAC6G;AAC7G,MAAM,UAAU,4BAA4B,CAAC,OAAe,EAAE,QAAgB,EAAE,MAAe;IAC7F,IAAI,UAAkB,CAAC;IAAC,IAAI,cAAsB,CAAC;IACnD,IAAI,CAAC;QAAC,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;QAAC,cAAc,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,uCAAuC,CAAC;IAAC,CAAC;IAClJ,IAAI,UAAU,KAAK,cAAc,IAAI,MAAM;QAAE,OAAO,IAAI,CAAC;IACzD,OAAO,uBAAuB,UAAU,sDAAsD,cAAc,sCAAsC,CAAC;AACrJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The policy's answer. A refusal says why, in words fit for an error message. */
|
|
2
|
+
export type PushUrlDecision = {
|
|
3
|
+
allow: true;
|
|
4
|
+
} | {
|
|
5
|
+
allow: false;
|
|
6
|
+
reason: string;
|
|
7
|
+
};
|
|
8
|
+
/** The port: a synchronous judgement of one URL. `defaultPushUrlPolicy` is the shipped one. */
|
|
9
|
+
export type PushUrlPolicy = (url: string) => PushUrlDecision;
|
|
10
|
+
/** Optional port: the addresses a host name resolves to (A and AAAA), as IP literals. */
|
|
11
|
+
export type PushHostResolver = (host: string) => Promise<string[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Why an IP literal is not a public destination — `null` when it is public, a reason when it is refused, and
|
|
14
|
+
* a reason too when the string is not an IP literal at all (a resolver that answers with something else has
|
|
15
|
+
* not answered). Brackets around an IPv6 literal are accepted.
|
|
16
|
+
*/
|
|
17
|
+
export declare function pushAddressRefusal(address: string): string | null;
|
|
18
|
+
/**
|
|
19
|
+
* THE SHIPPED POLICY (spec 445 §3.5). Pure and synchronous: it judges the URL as written.
|
|
20
|
+
* Allows only an `https:` URL with no credentials whose host is a public IP literal or a name that is not
|
|
21
|
+
* local by construction.
|
|
22
|
+
*/
|
|
23
|
+
export declare function defaultPushUrlPolicy(url: string): PushUrlDecision;
|
|
24
|
+
/**
|
|
25
|
+
* The whole check, as the server runs it when a config is stored AND again before each delivery: the policy
|
|
26
|
+
* first; then, when the deployment can resolve names, EVERY address the host resolves to must be public. A
|
|
27
|
+
* host that resolves to nothing, or a resolver that fails, is a refusal — never "unknown, so allowed".
|
|
28
|
+
* An IP-literal host is already judged by the policy and is not resolved.
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkPushUrl(url: string, ports?: {
|
|
31
|
+
policy?: PushUrlPolicy;
|
|
32
|
+
resolveHost?: PushHostResolver;
|
|
33
|
+
}): Promise<PushUrlDecision>;
|
|
34
|
+
//# sourceMappingURL=push-url-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-url-policy.d.ts","sourceRoot":"","sources":["../../src/standard/push-url-policy.ts"],"names":[],"mappings":"AAiBA,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF,+FAA+F;AAC/F,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,eAAe,CAAC;AAE7D,yFAAyF;AACzF,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAiFnE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOjE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CA0BjE;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE;IAAE,MAAM,CAAC,EAAE,aAAa,CAAC;IAAC,WAAW,CAAC,EAAE,gBAAgB,CAAA;CAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAchJ"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// WHERE A PUSH NOTIFICATION MAY GO — spec 445 §3.5 (audit H-11 / RUN-2).
|
|
2
|
+
//
|
|
3
|
+
// A push config is a URL a caller hands this server and asks it to POST to. Unchecked, that is server-side
|
|
4
|
+
// request forgery: the caller picks the address and the Authorization header, and the server's network
|
|
5
|
+
// position (cloud metadata at 169.254.169.254, a loopback admin port, a private service) does the rest.
|
|
6
|
+
//
|
|
7
|
+
// THE RULE: a push goes to a PUBLIC address over https, and nowhere else. `https:` only; no credentials in
|
|
8
|
+
// the URL; no IP literal in a loopback, link-local, private, CGNAT, unspecified, multicast or reserved range —
|
|
9
|
+
// in any spelling, including an IPv4 address carried inside an IPv6 one; no name that is local by
|
|
10
|
+
// construction (`localhost`, `*.localhost`, `*.local`, `*.internal`).
|
|
11
|
+
//
|
|
12
|
+
// PURE: no I/O, no DNS. A name that RESOLVES to a refused range is a second question, answered by
|
|
13
|
+
// `checkPushUrl` when a deployment supplies a resolver. What neither closes: a name re-resolved to a
|
|
14
|
+
// different address between this check and the connection (DNS rebinding) — that needs the transport to pin
|
|
15
|
+
// the checked address, which a fetch-shaped port cannot say. Redirects are refused at delivery
|
|
16
|
+
// (`redirect: 'manual'`, a 3xx answer is a failed delivery — COR-5), so a public address cannot hand the request on to a private one.
|
|
17
|
+
const refuse = (reason) => ({ allow: false, reason });
|
|
18
|
+
const ALLOW = { allow: true };
|
|
19
|
+
/** Four octets from a strict dotted quad, else null. The URL parser has already normalized the odd
|
|
20
|
+
* spellings (`0x7f.1`, `2130706433`, `017700000001`) to this form for an https URL. */
|
|
21
|
+
function parseIpv4(s) {
|
|
22
|
+
const m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(s);
|
|
23
|
+
if (!m)
|
|
24
|
+
return null;
|
|
25
|
+
const o = [Number(m[1]), Number(m[2]), Number(m[3]), Number(m[4])];
|
|
26
|
+
return o.every((n) => n <= 255) ? o : null;
|
|
27
|
+
}
|
|
28
|
+
/** Eight 16-bit groups from an IPv6 literal (no brackets, zone id dropped), else null. Handles `::` and a
|
|
29
|
+
* dotted IPv4 tail. */
|
|
30
|
+
function parseIpv6(input) {
|
|
31
|
+
let s = input;
|
|
32
|
+
const zone = s.indexOf('%');
|
|
33
|
+
if (zone >= 0)
|
|
34
|
+
s = s.slice(0, zone);
|
|
35
|
+
if (!s.includes(':') || !/^[0-9a-f:.]+$/i.test(s))
|
|
36
|
+
return null;
|
|
37
|
+
const tail = /(^|:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(s);
|
|
38
|
+
if (tail) {
|
|
39
|
+
const v4 = parseIpv4(tail[2]);
|
|
40
|
+
if (!v4)
|
|
41
|
+
return null;
|
|
42
|
+
s = `${s.slice(0, s.length - tail[2].length)}${((v4[0] << 8) | v4[1]).toString(16)}:${((v4[2] << 8) | v4[3]).toString(16)}`;
|
|
43
|
+
}
|
|
44
|
+
if (s.includes('.'))
|
|
45
|
+
return null;
|
|
46
|
+
const halves = s.split('::');
|
|
47
|
+
if (halves.length > 2)
|
|
48
|
+
return null;
|
|
49
|
+
const groups = (part) => {
|
|
50
|
+
if (part === '')
|
|
51
|
+
return [];
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const g of part.split(':')) {
|
|
54
|
+
if (!/^[0-9a-f]{1,4}$/i.test(g))
|
|
55
|
+
return null;
|
|
56
|
+
out.push(parseInt(g, 16));
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
};
|
|
60
|
+
const head = groups(halves[0]);
|
|
61
|
+
const rest = halves.length === 2 ? groups(halves[1]) : [];
|
|
62
|
+
if (!head || !rest)
|
|
63
|
+
return null;
|
|
64
|
+
if (halves.length === 1)
|
|
65
|
+
return head.length === 8 ? head : null;
|
|
66
|
+
const fill = 8 - head.length - rest.length;
|
|
67
|
+
if (fill < 1)
|
|
68
|
+
return null;
|
|
69
|
+
return [...head, ...new Array(fill).fill(0), ...rest];
|
|
70
|
+
}
|
|
71
|
+
/** Why an IPv4 address is not a public destination, or null when it is. */
|
|
72
|
+
function ipv4Refusal(o) {
|
|
73
|
+
const [a, b] = o;
|
|
74
|
+
if (a === 0)
|
|
75
|
+
return 'an unspecified ("this network") address';
|
|
76
|
+
if (a === 127)
|
|
77
|
+
return 'a loopback address';
|
|
78
|
+
if (a === 10)
|
|
79
|
+
return 'a private address (10.0.0.0/8)';
|
|
80
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
81
|
+
return 'a private address (172.16.0.0/12)';
|
|
82
|
+
if (a === 192 && b === 168)
|
|
83
|
+
return 'a private address (192.168.0.0/16)';
|
|
84
|
+
if (a === 169 && b === 254)
|
|
85
|
+
return 'a link-local address (169.254.0.0/16)';
|
|
86
|
+
if (a === 100 && b >= 64 && b <= 127)
|
|
87
|
+
return 'a carrier-grade NAT address (100.64.0.0/10)';
|
|
88
|
+
if (a >= 224)
|
|
89
|
+
return 'a multicast or reserved address';
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
/** Why an IPv6 address is not a public destination, or null when it is. An address that CARRIES an IPv4
|
|
93
|
+
* one (mapped `::ffff:a.b.c.d`, the deprecated compatible `::a.b.c.d`, NAT64 `64:ff9b::/96`, 6to4
|
|
94
|
+
* `2002::/16`) is judged by the IPv4 address it reaches. */
|
|
95
|
+
function ipv6Refusal(g) {
|
|
96
|
+
const zeros = (n) => g.slice(0, n).every((x) => x === 0);
|
|
97
|
+
const embedded = (hi, lo, what) => {
|
|
98
|
+
const r = ipv4Refusal([hi >> 8, hi & 0xff, lo >> 8, lo & 0xff]);
|
|
99
|
+
return r ? `${what} for ${r}` : null;
|
|
100
|
+
};
|
|
101
|
+
if (zeros(8))
|
|
102
|
+
return 'the unspecified address (::)';
|
|
103
|
+
if (zeros(7) && g[7] === 1)
|
|
104
|
+
return 'a loopback address (::1)';
|
|
105
|
+
if (zeros(5) && g[5] === 0xffff)
|
|
106
|
+
return embedded(g[6], g[7], 'an IPv4-mapped IPv6 form');
|
|
107
|
+
if (zeros(6))
|
|
108
|
+
return embedded(g[6], g[7], 'an IPv4-compatible IPv6 form') ?? 'an IPv4-compatible IPv6 address';
|
|
109
|
+
if (g[0] === 0x64 && g[1] === 0xff9b && g.slice(2, 6).every((x) => x === 0))
|
|
110
|
+
return embedded(g[6], g[7], 'a NAT64 form');
|
|
111
|
+
if (g[0] === 0x2002)
|
|
112
|
+
return embedded(g[1], g[2], 'a 6to4 form');
|
|
113
|
+
if ((g[0] & 0xffc0) === 0xfe80)
|
|
114
|
+
return 'a link-local address (fe80::/10)';
|
|
115
|
+
if ((g[0] & 0xffc0) === 0xfec0)
|
|
116
|
+
return 'a site-local address (fec0::/10)';
|
|
117
|
+
if ((g[0] & 0xfe00) === 0xfc00)
|
|
118
|
+
return 'a private address (fc00::/7)';
|
|
119
|
+
if ((g[0] & 0xff00) === 0xff00)
|
|
120
|
+
return 'a multicast address (ff00::/8)';
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Why an IP literal is not a public destination — `null` when it is public, a reason when it is refused, and
|
|
125
|
+
* a reason too when the string is not an IP literal at all (a resolver that answers with something else has
|
|
126
|
+
* not answered). Brackets around an IPv6 literal are accepted.
|
|
127
|
+
*/
|
|
128
|
+
export function pushAddressRefusal(address) {
|
|
129
|
+
const s = address.trim().toLowerCase().replace(/^\[(.*)\]$/, '$1');
|
|
130
|
+
const v4 = parseIpv4(s);
|
|
131
|
+
if (v4)
|
|
132
|
+
return ipv4Refusal(v4);
|
|
133
|
+
const v6 = parseIpv6(s);
|
|
134
|
+
if (v6)
|
|
135
|
+
return ipv6Refusal(v6);
|
|
136
|
+
return 'not an IP address';
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* THE SHIPPED POLICY (spec 445 §3.5). Pure and synchronous: it judges the URL as written.
|
|
140
|
+
* Allows only an `https:` URL with no credentials whose host is a public IP literal or a name that is not
|
|
141
|
+
* local by construction.
|
|
142
|
+
*/
|
|
143
|
+
export function defaultPushUrlPolicy(url) {
|
|
144
|
+
let u;
|
|
145
|
+
try {
|
|
146
|
+
u = new URL(url);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return refuse('the push URL is not a valid absolute URL');
|
|
150
|
+
}
|
|
151
|
+
if (u.protocol !== 'https:')
|
|
152
|
+
return refuse(`a push URL must be https: (got ${u.protocol})`);
|
|
153
|
+
if (u.username || u.password)
|
|
154
|
+
return refuse('a push URL must not carry credentials (user:password@)');
|
|
155
|
+
const host = u.hostname.toLowerCase().replace(/\.$/, '');
|
|
156
|
+
if (!host)
|
|
157
|
+
return refuse('the push URL names no host');
|
|
158
|
+
if (host.startsWith('[') || host.includes(':')) {
|
|
159
|
+
const g = parseIpv6(host.replace(/^\[(.*)\]$/, '$1'));
|
|
160
|
+
if (!g)
|
|
161
|
+
return refuse('the push URL host is not a valid IPv6 address');
|
|
162
|
+
const why = ipv6Refusal(g);
|
|
163
|
+
return why ? refuse(`the push URL host is ${why}`) : ALLOW;
|
|
164
|
+
}
|
|
165
|
+
const v4 = parseIpv4(host);
|
|
166
|
+
if (v4) {
|
|
167
|
+
const why = ipv4Refusal(v4);
|
|
168
|
+
return why ? refuse(`the push URL host is ${why}`) : ALLOW;
|
|
169
|
+
}
|
|
170
|
+
// A host whose last label is a number is an IPv4 address in some spelling (WHATWG "ends in a number").
|
|
171
|
+
// A parser that normalized it was handled above; one that did not must not let it through as a name.
|
|
172
|
+
const last = host.slice(host.lastIndexOf('.') + 1);
|
|
173
|
+
if (/^(\d+|0x[0-9a-f]*)$/.test(last))
|
|
174
|
+
return refuse('the push URL host is a numeric address in a non-canonical form');
|
|
175
|
+
if (host === 'localhost' || host.endsWith('.localhost'))
|
|
176
|
+
return refuse('the push URL host is localhost');
|
|
177
|
+
if (host.endsWith('.local') || host === 'local')
|
|
178
|
+
return refuse('the push URL host is a local (.local) name');
|
|
179
|
+
if (host.endsWith('.internal') || host === 'internal')
|
|
180
|
+
return refuse('the push URL host is an internal (.internal) name');
|
|
181
|
+
return ALLOW;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The whole check, as the server runs it when a config is stored AND again before each delivery: the policy
|
|
185
|
+
* first; then, when the deployment can resolve names, EVERY address the host resolves to must be public. A
|
|
186
|
+
* host that resolves to nothing, or a resolver that fails, is a refusal — never "unknown, so allowed".
|
|
187
|
+
* An IP-literal host is already judged by the policy and is not resolved.
|
|
188
|
+
*/
|
|
189
|
+
export async function checkPushUrl(url, ports = {}) {
|
|
190
|
+
const decision = (ports.policy ?? defaultPushUrlPolicy)(url);
|
|
191
|
+
if (!decision.allow || !ports.resolveHost)
|
|
192
|
+
return decision;
|
|
193
|
+
let host;
|
|
194
|
+
try {
|
|
195
|
+
host = new URL(url).hostname.toLowerCase().replace(/\.$/, '');
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return refuse('the push URL is not a valid absolute URL');
|
|
199
|
+
}
|
|
200
|
+
if (host.startsWith('[') || parseIpv4(host))
|
|
201
|
+
return decision;
|
|
202
|
+
let addresses;
|
|
203
|
+
try {
|
|
204
|
+
addresses = await ports.resolveHost(host);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return refuse(`the push URL host ${host} could not be resolved`);
|
|
208
|
+
}
|
|
209
|
+
if (!Array.isArray(addresses) || addresses.length === 0)
|
|
210
|
+
return refuse(`the push URL host ${host} resolves to no address`);
|
|
211
|
+
for (const a of addresses) {
|
|
212
|
+
const why = pushAddressRefusal(String(a));
|
|
213
|
+
if (why)
|
|
214
|
+
return refuse(`the push URL host ${host} resolves to ${why}`);
|
|
215
|
+
}
|
|
216
|
+
return decision;
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=push-url-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-url-policy.js","sourceRoot":"","sources":["../../src/standard/push-url-policy.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,2GAA2G;AAC3G,uGAAuG;AACvG,wGAAwG;AACxG,EAAE;AACF,2GAA2G;AAC3G,+GAA+G;AAC/G,kGAAkG;AAClG,sEAAsE;AACtE,EAAE;AACF,kGAAkG;AAClG,qGAAqG;AACrG,4GAA4G;AAC5G,+FAA+F;AAC/F,sIAAsI;AAWtI,MAAM,MAAM,GAAG,CAAC,MAAc,EAAmB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AAC/E,MAAM,KAAK,GAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAE/C;wFACwF;AACxF,SAAS,SAAS,CAAC,CAAS;IAC1B,MAAM,CAAC,GAAG,8CAA8C,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjE,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC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B,CAAC,CAAC;IAC3H,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAI,GAAG;YAAE,OAAO,MAAM,CAAC,qBAAqB,IAAI,gBAAgB,GAAG,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { type PushHostResolver, type PushUrlPolicy } from './push-url-policy.js';
|
|
2
|
+
import { type AgentCardV1, type ArtifactV1, type MessageV1, type PartV1, type SendMessageConfigurationV1, type TaskPushNotificationConfigV1, type TaskV1 } from './types.js';
|
|
3
|
+
export interface StandardTaskStore {
|
|
4
|
+
get(id: string): Promise<TaskV1 | null>;
|
|
5
|
+
put(task: TaskV1): Promise<void>;
|
|
6
|
+
/** Every task, newest status first. Filtering is the server's. */
|
|
7
|
+
all(): Promise<TaskV1[]>;
|
|
8
|
+
}
|
|
9
|
+
export interface PushConfigStore {
|
|
10
|
+
put(cfg: TaskPushNotificationConfigV1 & {
|
|
11
|
+
id: string;
|
|
12
|
+
taskId: string;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
get(taskId: string, id: string): Promise<(TaskPushNotificationConfigV1 & {
|
|
15
|
+
id: string;
|
|
16
|
+
taskId: string;
|
|
17
|
+
}) | null>;
|
|
18
|
+
list(taskId: string): Promise<Array<TaskPushNotificationConfigV1 & {
|
|
19
|
+
id: string;
|
|
20
|
+
taskId: string;
|
|
21
|
+
}>>;
|
|
22
|
+
delete(taskId: string, id: string): Promise<boolean>;
|
|
23
|
+
}
|
|
24
|
+
export interface Principal {
|
|
25
|
+
agent: string;
|
|
26
|
+
[k: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
/** What an executor is handed: the message, the task as created, the admitted principal, and the ways it
|
|
29
|
+
* may move the task. Every call records on the task, fans out to subscribers and delivers to push configs. */
|
|
30
|
+
export interface ExecutionContext {
|
|
31
|
+
message: MessageV1;
|
|
32
|
+
task: TaskV1;
|
|
33
|
+
principal: Principal | null;
|
|
34
|
+
/** Spec 390 W2 — the request's headers, read-only, so an executor can carry W3C Trace Context
|
|
35
|
+
* (`traceparent` / `tracestate`) into the run it starts. Correlation only: nothing here admits. */
|
|
36
|
+
headers: Headers;
|
|
37
|
+
/** True while a client is streaming this run (`SendStreamingMessage`). */
|
|
38
|
+
streaming: boolean;
|
|
39
|
+
working(message?: PartV1[] | MessageV1): Promise<void>;
|
|
40
|
+
artifact(artifact: Omit<ArtifactV1, 'artifactId'> & {
|
|
41
|
+
artifactId?: string;
|
|
42
|
+
}, opts?: {
|
|
43
|
+
append?: boolean;
|
|
44
|
+
lastChunk?: boolean;
|
|
45
|
+
}): Promise<ArtifactV1>;
|
|
46
|
+
inputRequired(message?: PartV1[] | MessageV1): Promise<void>;
|
|
47
|
+
authRequired(message?: PartV1[] | MessageV1): Promise<void>;
|
|
48
|
+
complete(message?: PartV1[] | MessageV1): Promise<void>;
|
|
49
|
+
fail(message?: PartV1[] | MessageV1): Promise<void>;
|
|
50
|
+
reject(message?: PartV1[] | MessageV1): Promise<void>;
|
|
51
|
+
/** Reply with a MESSAGE and no task at all — only before any other event. */
|
|
52
|
+
reply(parts: PartV1[] | MessageV1): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export interface StandardExecutor {
|
|
55
|
+
execute(ctx: ExecutionContext): Promise<void>;
|
|
56
|
+
/** Asked to stop a non-terminal task; the server marks it canceled either way. */
|
|
57
|
+
cancel?(task: TaskV1): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export interface StandardServerConfig {
|
|
60
|
+
card: AgentCardV1;
|
|
61
|
+
executor: StandardExecutor;
|
|
62
|
+
tasks?: StandardTaskStore;
|
|
63
|
+
push?: PushConfigStore;
|
|
64
|
+
/** Admission: who is asking. Configured ⇒ a request resolving to nobody is 401 before any method runs.
|
|
65
|
+
* Absent ⇒ anonymous: with `visibility: 'single-tenant'` every task is that caller's; with `canSeeTask`
|
|
66
|
+
* the rule judges a `null` principal (a party rule answers false — an in-Worker anonymous caller sees
|
|
67
|
+
* only what it is party to). */
|
|
68
|
+
principal?: (request: Request) => Promise<Principal | null>;
|
|
69
|
+
/** `Major.Minor` versions served; default ['1.0']. A request naming another is -32009. */
|
|
70
|
+
versions?: string[];
|
|
71
|
+
/**
|
|
72
|
+
* Answer a `SendMessage` WITHOUT creating a task of this server's own (spec 372 S4). Returns the result
|
|
73
|
+
* to reply with, or `null` to let the ordinary path run. This is how a message that carries an extension
|
|
74
|
+
* routing it to another runtime keeps THAT runtime's task id: two ids for one task would make `GetTask`
|
|
75
|
+
* a coin toss.
|
|
76
|
+
*/
|
|
77
|
+
beforeSend?: (params: {
|
|
78
|
+
message: MessageV1;
|
|
79
|
+
configuration?: SendMessageConfigurationV1;
|
|
80
|
+
}, principal: Principal | null) => Promise<{
|
|
81
|
+
task?: TaskV1;
|
|
82
|
+
message?: MessageV1;
|
|
83
|
+
} | null>;
|
|
84
|
+
/** Cancel a task this server did not create. Returns the updated task, or `null` to let the ordinary
|
|
85
|
+
* path run. */
|
|
86
|
+
onCancel?: (task: TaskV1, principal: Principal | null) => Promise<TaskV1 | null>;
|
|
87
|
+
/**
|
|
88
|
+
* May this principal see or act on this task (spec 372 S4)? A deployment that carries other people's tasks
|
|
89
|
+
* MUST bind this: a delegated task has parties, and a `GetTask` from anyone else is answered TaskNotFound,
|
|
90
|
+
* never "forbidden" — telling a stranger that a task exists is itself a disclosure.
|
|
91
|
+
*
|
|
92
|
+
* R917-P-5 (spec 408 §2.5): there is no silent default any more. A server binds this OR declares
|
|
93
|
+
* `visibility: 'single-tenant'` (the in-memory shape the TCK's SUT runs, where every task is the one
|
|
94
|
+
* caller's); constructing one with neither throws. The old "absent ⇒ every task visible" was a fail-open
|
|
95
|
+
* knob nobody had written down.
|
|
96
|
+
*/
|
|
97
|
+
canSeeTask?: (task: TaskV1, principal: Principal | null, op: 'get' | 'cancel' | 'continue' | 'list' | 'push') => Promise<boolean> | boolean;
|
|
98
|
+
/** Spec 408 §2.5 — the explicit single-tenant declaration: every task is visible to every caller because there
|
|
99
|
+
* is only one. Mutually exclusive with `canSeeTask`; a server with more than one principal must not say it. */
|
|
100
|
+
visibility?: 'single-tenant';
|
|
101
|
+
/**
|
|
102
|
+
* Spec 412 — THE PUBLIC LANE: a `SendMessage` a stranger may put to this agent with NO credential at all, answered
|
|
103
|
+
* from what the owner marked public and nothing else. `admits(message)` says which messages qualify (a data part
|
|
104
|
+
* naming a public skill, say); `answer` builds the reply. The reply is a MESSAGE, never a task — a stranger holds no
|
|
105
|
+
* task here, so there is nothing to get, cancel or subscribe to. Every other request resolving to nobody stays 401.
|
|
106
|
+
* A door for records, never authority: what `answer` returns is a disclosure the owner already made.
|
|
107
|
+
*/
|
|
108
|
+
public?: {
|
|
109
|
+
admits: (message: MessageV1) => boolean;
|
|
110
|
+
answer: (message: MessageV1, headers: Headers) => Promise<MessageV1>;
|
|
111
|
+
};
|
|
112
|
+
/** Served by `GetExtendedAgentCard` when `card.capabilities.extendedAgentCard` is true. */
|
|
113
|
+
extendedCard?: AgentCardV1;
|
|
114
|
+
/** Extension methods (an A2A extension may define methods beyond the core set — the delegated-task extension's
|
|
115
|
+
* `GetTaskArtifact`, say). Dispatched by exact name after the core methods; the handler gets the parsed params
|
|
116
|
+
* and the door's principal and returns the JSON-RPC result, or throws an `A2aError`. */
|
|
117
|
+
methods?: Record<string, (params: Record<string, unknown>, principal: Principal | null) => Promise<unknown>>;
|
|
118
|
+
/** Push delivery transport (default: global fetch). */
|
|
119
|
+
fetch?: typeof fetch;
|
|
120
|
+
/**
|
|
121
|
+
* Spec 445 §3.5 (H-11) — where a push may go. Judged when a config is stored (a refusal is InvalidParams)
|
|
122
|
+
* and AGAIN before every delivery, because a stored config is not a checked one: the store is a port and
|
|
123
|
+
* the policy can change. Default `defaultPushUrlPolicy`: https only, no credentials in the URL, no
|
|
124
|
+
* loopback / link-local / private / CGNAT / unspecified address in any spelling, no local name.
|
|
125
|
+
*/
|
|
126
|
+
pushUrlPolicy?: PushUrlPolicy;
|
|
127
|
+
/** Spec 445 §3.5 — a deployment that can resolve DNS says so here; then EVERY address a push host resolves
|
|
128
|
+
* to must be public, at store time and before each delivery. Absent ⇒ names are judged as written. */
|
|
129
|
+
resolveHost?: PushHostResolver;
|
|
130
|
+
/** Spec 445 §3.5 — how long one push delivery may take before it is aborted (default 5000 ms). */
|
|
131
|
+
pushTimeoutMs?: number;
|
|
132
|
+
/** Spec 445 §3.5 — push configs one task may hold (default 4); one more is refused. */
|
|
133
|
+
maxPushConfigsPerTask?: number;
|
|
134
|
+
/** RUN-18 (spec 445 W0) — the largest request body read, in bytes (default 8 MiB). Larger is answered 413 before
|
|
135
|
+
* the principal, the parser or any handler sees it. */
|
|
136
|
+
maxRequestBytes?: number;
|
|
137
|
+
now?: () => number;
|
|
138
|
+
/** How long a subscription to an IDLE non-terminal task stays open (default 60 s). */
|
|
139
|
+
idleSubscriptionMs?: number;
|
|
140
|
+
}
|
|
141
|
+
export interface StandardServer {
|
|
142
|
+
handle(request: Request): Promise<Response>;
|
|
143
|
+
card(): AgentCardV1;
|
|
144
|
+
}
|
|
145
|
+
export declare function createMemoryTaskStore(): StandardTaskStore;
|
|
146
|
+
export declare function createMemoryPushStore(): PushConfigStore;
|
|
147
|
+
/** RUN-18 — the default cap on one request body. */
|
|
148
|
+
export declare const STANDARD_MAX_REQUEST_BYTES: number;
|
|
149
|
+
export declare function createStandardA2aServer(config: StandardServerConfig): StandardServer;
|
|
150
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/standard/server.ts"],"names":[],"mappings":"AAcA,OAAO,EAAsC,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrH,OAAO,EAEL,KAAK,WAA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