@agentplat/mesh-http 0.3.0-alpha.5
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/LICENSE +202 -0
- package/README.md +55 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +614 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# `@agentplat/mesh-http`
|
|
2
|
+
|
|
3
|
+
Bounded, Fetch-compatible HTTP transport for already signed Agentplat Mesh
|
|
4
|
+
envelopes. Importing or constructing a client/handler starts no server, performs
|
|
5
|
+
no discovery and opens no network connection.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {
|
|
9
|
+
createMeshHttpClient,
|
|
10
|
+
createMeshHttpHandler,
|
|
11
|
+
} from "@agentplat/mesh-http";
|
|
12
|
+
|
|
13
|
+
const handler = createMeshHttpHandler({
|
|
14
|
+
target: {
|
|
15
|
+
tenantId: "tenant-a",
|
|
16
|
+
meshId: "mesh-a",
|
|
17
|
+
peerId: "peer-b",
|
|
18
|
+
instanceId: "peer-b-1",
|
|
19
|
+
},
|
|
20
|
+
authenticate: (request) =>
|
|
21
|
+
request.headers.get("authorization") === process.env.MESH_CHANNEL_TOKEN,
|
|
22
|
+
accept: async (envelope) => {
|
|
23
|
+
const receipt = await durableRepository.receive({ scope, envelope });
|
|
24
|
+
return { accepted: true, duplicate: receipt.duplicate };
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const client = createMeshHttpClient({
|
|
29
|
+
allowedSchemes: ["https:"],
|
|
30
|
+
resolveEndpoint: ({ peerId }) => ({
|
|
31
|
+
url: configuredPeerUrls[peerId],
|
|
32
|
+
headers: { authorization: `Bearer ${channelToken}` },
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await client.deliver({ envelope: signedEnvelope });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The handler strictly parses one protocol-v0 envelope and acknowledges it only
|
|
40
|
+
after the injected acceptor returns success. It does not verify signatures or
|
|
41
|
+
admission; the durable worker must use the normal Mesh inbound boundary before
|
|
42
|
+
state mutation.
|
|
43
|
+
|
|
44
|
+
First receipt and exact duplicate receipt are deliberately indistinguishable to
|
|
45
|
+
the remote sender. Detailed signature, key, replay, Trust, policy and database
|
|
46
|
+
errors must remain in bounded local diagnostics.
|
|
47
|
+
|
|
48
|
+
No CORS headers or `OPTIONS` handling are enabled by default. Browser-facing
|
|
49
|
+
deployments may inject an exact construction-bound `cors` policy with explicit
|
|
50
|
+
HTTP(S) origins, lowercase request headers and a bounded preflight age. Wildcard
|
|
51
|
+
origins and envelope-supplied origins are not accepted.
|
|
52
|
+
|
|
53
|
+
Delivery is at least once. The client performs one attempt, never follows
|
|
54
|
+
redirects, and returns a coarse receipt. Retry scheduling belongs to the
|
|
55
|
+
durable outbox worker, which must retry the exact same signed envelope.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { MeshProtocolOptions, SignedMeshEnvelope } from "@agentplat/mesh-protocol";
|
|
2
|
+
export declare const MESH_HTTP_RECEIPT_SCHEMA_VERSION: 1;
|
|
3
|
+
export declare const DEFAULT_MESH_HTTP_PATH = "/agentplat/mesh/v0/envelopes";
|
|
4
|
+
export interface MeshHttpTarget {
|
|
5
|
+
readonly tenantId: string;
|
|
6
|
+
readonly meshId: string;
|
|
7
|
+
readonly peerId: string;
|
|
8
|
+
}
|
|
9
|
+
export interface MeshHttpEndpoint {
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
12
|
+
}
|
|
13
|
+
export type MeshHttpEndpointResolver = (target: MeshHttpTarget) => MeshHttpEndpoint | Promise<MeshHttpEndpoint>;
|
|
14
|
+
export type MeshHttpDiagnostic = {
|
|
15
|
+
readonly kind: "client.failure";
|
|
16
|
+
readonly code: "aborted" | "endpoint_invalid" | "network_failure" | "response_invalid" | "response_too_large" | "timeout";
|
|
17
|
+
readonly target: MeshHttpTarget;
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: "handler.failure";
|
|
20
|
+
readonly code: "acceptor_failure" | "authentication_failure" | "body_failure" | "scope_rejected";
|
|
21
|
+
readonly messageId?: string;
|
|
22
|
+
};
|
|
23
|
+
export type MeshHttpReceiptDisposition = "accepted" | "permanent_rejection" | "retryable";
|
|
24
|
+
export interface MeshHttpReceipt {
|
|
25
|
+
readonly schemaVersion: typeof MESH_HTTP_RECEIPT_SCHEMA_VERSION;
|
|
26
|
+
readonly disposition: MeshHttpReceiptDisposition;
|
|
27
|
+
readonly messageId?: string;
|
|
28
|
+
readonly retryAfterMs?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface MeshHttpDeliveryResult {
|
|
31
|
+
readonly receipt: MeshHttpReceipt;
|
|
32
|
+
readonly status: number;
|
|
33
|
+
}
|
|
34
|
+
export interface MeshHttpDeliverInput {
|
|
35
|
+
readonly envelope: SignedMeshEnvelope;
|
|
36
|
+
/** Required for topic audiences; must match a direct audience when present. */
|
|
37
|
+
readonly targetPeerId?: string;
|
|
38
|
+
readonly signal?: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
export interface MeshHttpClientOptions {
|
|
41
|
+
readonly resolveEndpoint: MeshHttpEndpointResolver;
|
|
42
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
43
|
+
readonly timeoutMs?: number;
|
|
44
|
+
readonly maximumResponseBytes?: number;
|
|
45
|
+
readonly allowedSchemes?: readonly ("http:" | "https:")[];
|
|
46
|
+
readonly protocolOptions?: MeshProtocolOptions;
|
|
47
|
+
readonly onDiagnostic?: (diagnostic: MeshHttpDiagnostic) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface MeshHttpClient {
|
|
50
|
+
deliver(input: MeshHttpDeliverInput): Promise<MeshHttpDeliveryResult>;
|
|
51
|
+
}
|
|
52
|
+
export interface MeshHttpIngressContext {
|
|
53
|
+
readonly target: MeshHttpTarget & {
|
|
54
|
+
readonly instanceId: string;
|
|
55
|
+
};
|
|
56
|
+
readonly request: Request;
|
|
57
|
+
}
|
|
58
|
+
export type MeshHttpIngressDecision = {
|
|
59
|
+
readonly accepted: true;
|
|
60
|
+
/** Local-only detail. It is deliberately omitted from the HTTP receipt. */
|
|
61
|
+
readonly duplicate?: boolean;
|
|
62
|
+
} | {
|
|
63
|
+
readonly accepted: false;
|
|
64
|
+
readonly disposition: "permanent_rejection" | "retryable";
|
|
65
|
+
readonly retryAfterMs?: number;
|
|
66
|
+
};
|
|
67
|
+
export type MeshHttpChannelAuthenticator = (request: Request, target: MeshHttpIngressContext["target"]) => boolean | Promise<boolean>;
|
|
68
|
+
export interface MeshHttpCorsPolicy {
|
|
69
|
+
readonly allowedOrigins: readonly string[];
|
|
70
|
+
readonly allowedRequestHeaders?: readonly string[];
|
|
71
|
+
readonly maxAgeSeconds?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface MeshHttpHandlerOptions {
|
|
74
|
+
readonly target: MeshHttpIngressContext["target"];
|
|
75
|
+
readonly accept: (envelope: SignedMeshEnvelope, context: MeshHttpIngressContext) => MeshHttpIngressDecision | Promise<MeshHttpIngressDecision>;
|
|
76
|
+
readonly path?: string;
|
|
77
|
+
readonly authenticate?: MeshHttpChannelAuthenticator;
|
|
78
|
+
readonly cors?: MeshHttpCorsPolicy;
|
|
79
|
+
readonly maximumBodyBytes?: number;
|
|
80
|
+
readonly protocolOptions?: MeshProtocolOptions;
|
|
81
|
+
readonly onDiagnostic?: (diagnostic: MeshHttpDiagnostic) => void;
|
|
82
|
+
}
|
|
83
|
+
export type MeshHttpHandler = (request: Request) => Promise<Response>;
|
|
84
|
+
/** Creates an inert client. Delivery performs exactly one bounded HTTP attempt. */
|
|
85
|
+
export declare function createMeshHttpClient(options: MeshHttpClientOptions): MeshHttpClient;
|
|
86
|
+
/** Creates an inert Fetch handler. No server or listener is started. */
|
|
87
|
+
export declare function createMeshHttpHandler(options: MeshHttpHandlerOptions): MeshHttpHandler;
|
|
88
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAElC,eAAO,MAAM,gCAAgC,EAAG,CAAU,CAAC;AAC3D,eAAO,MAAM,sBAAsB,iCAAiC,CAAC;AAErE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD;AAED,MAAM,MAAM,wBAAwB,GAAG,CACrC,MAAM,EAAE,cAAc,KACnB,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAElD,MAAM,MAAM,kBAAkB,GAC1B;IACE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,IAAI,EACT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CAAC,MAAM,EAAE,CACf,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,sBAAsB,KAC5B,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAChE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,4BAA4B,CAAC;IACrD,QAAQ,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,eAAe,CAAC,EAAE,mBAAmB,CAAC;IAC/C,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAClE;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEtE,mFAAmF;AACnF,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CAiJhB;AAED,wEAAwE;AACxE,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CAuIjB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import { DEFAULT_MESH_PROTOCOL_LIMITS, canonicalizeMeshJsonBytes, parseSignedMeshEnvelope, validateSignedMeshEnvelope, } from "@agentplat/mesh-protocol";
|
|
2
|
+
export const MESH_HTTP_RECEIPT_SCHEMA_VERSION = 1;
|
|
3
|
+
export const DEFAULT_MESH_HTTP_PATH = "/agentplat/mesh/v0/envelopes";
|
|
4
|
+
/** Creates an inert client. Delivery performs exactly one bounded HTTP attempt. */
|
|
5
|
+
export function createMeshHttpClient(options) {
|
|
6
|
+
if (!options || typeof options.resolveEndpoint !== "function") {
|
|
7
|
+
throw new TypeError("Mesh HTTP endpoint resolver is required");
|
|
8
|
+
}
|
|
9
|
+
const fetchImplementation = options.fetch ?? globalThis.fetch;
|
|
10
|
+
if (typeof fetchImplementation !== "function") {
|
|
11
|
+
throw new TypeError("Mesh HTTP fetch implementation is required");
|
|
12
|
+
}
|
|
13
|
+
const timeoutMs = positiveInteger(options.timeoutMs ?? 10_000, "timeoutMs", 120_000);
|
|
14
|
+
const maximumResponseBytes = positiveInteger(options.maximumResponseBytes ?? 16_384, "maximumResponseBytes", 1_048_576);
|
|
15
|
+
const allowedSchemes = new Set(options.allowedSchemes ?? ["https:"]);
|
|
16
|
+
if (allowedSchemes.size === 0 ||
|
|
17
|
+
[...allowedSchemes].some((scheme) => scheme !== "http:" && scheme !== "https:")) {
|
|
18
|
+
throw new TypeError("Mesh HTTP allowed schemes are invalid");
|
|
19
|
+
}
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
async deliver(input) {
|
|
22
|
+
const validated = validateSignedMeshEnvelope(input?.envelope, options.protocolOptions);
|
|
23
|
+
if (!validated.ok) {
|
|
24
|
+
throw new TypeError("Mesh HTTP delivery requires a signed envelope");
|
|
25
|
+
}
|
|
26
|
+
const envelope = validated.value;
|
|
27
|
+
const target = targetFor(envelope, input.targetPeerId);
|
|
28
|
+
let endpoint;
|
|
29
|
+
try {
|
|
30
|
+
endpoint = await options.resolveEndpoint(target);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
diagnostic(options, {
|
|
34
|
+
kind: "client.failure",
|
|
35
|
+
code: "endpoint_invalid",
|
|
36
|
+
target,
|
|
37
|
+
});
|
|
38
|
+
return retryableResult(503);
|
|
39
|
+
}
|
|
40
|
+
let url;
|
|
41
|
+
let headers;
|
|
42
|
+
try {
|
|
43
|
+
({ url, headers } = validateEndpoint(endpoint, allowedSchemes));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
diagnostic(options, {
|
|
47
|
+
kind: "client.failure",
|
|
48
|
+
code: "endpoint_invalid",
|
|
49
|
+
target,
|
|
50
|
+
});
|
|
51
|
+
return permanentResult(422);
|
|
52
|
+
}
|
|
53
|
+
const body = canonicalizeMeshJsonBytes(envelope, options.protocolOptions);
|
|
54
|
+
if (!body.ok) {
|
|
55
|
+
throw new TypeError("Mesh HTTP envelope cannot be canonicalized");
|
|
56
|
+
}
|
|
57
|
+
const requestBody = new ArrayBuffer(body.value.byteLength);
|
|
58
|
+
new Uint8Array(requestBody).set(body.value);
|
|
59
|
+
headers.set("content-type", "application/json");
|
|
60
|
+
headers.set("accept", "application/json");
|
|
61
|
+
const timeoutController = new AbortController();
|
|
62
|
+
const timer = setTimeout(() => timeoutController.abort("mesh_http_timeout"), timeoutMs);
|
|
63
|
+
const combined = combineSignals(input.signal, timeoutController.signal);
|
|
64
|
+
try {
|
|
65
|
+
const response = await fetchImplementation(url, {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers,
|
|
68
|
+
body: requestBody,
|
|
69
|
+
redirect: "manual",
|
|
70
|
+
signal: combined.signal,
|
|
71
|
+
});
|
|
72
|
+
if (response.status >= 300 && response.status < 400) {
|
|
73
|
+
diagnostic(options, {
|
|
74
|
+
kind: "client.failure",
|
|
75
|
+
code: "response_invalid",
|
|
76
|
+
target,
|
|
77
|
+
});
|
|
78
|
+
return permanentResult(response.status);
|
|
79
|
+
}
|
|
80
|
+
const parsed = await readReceipt(response, maximumResponseBytes);
|
|
81
|
+
if (!parsed.receipt) {
|
|
82
|
+
diagnostic(options, {
|
|
83
|
+
kind: "client.failure",
|
|
84
|
+
code: parsed.tooLarge ? "response_too_large" : "response_invalid",
|
|
85
|
+
target,
|
|
86
|
+
});
|
|
87
|
+
return response.status >= 500 || response.status === 429
|
|
88
|
+
? retryableResult(response.status)
|
|
89
|
+
: permanentResult(response.status);
|
|
90
|
+
}
|
|
91
|
+
if (parsed.receipt.messageId !== undefined &&
|
|
92
|
+
parsed.receipt.messageId !== envelope.messageId) {
|
|
93
|
+
diagnostic(options, {
|
|
94
|
+
kind: "client.failure",
|
|
95
|
+
code: "response_invalid",
|
|
96
|
+
target,
|
|
97
|
+
});
|
|
98
|
+
return retryableResult(502);
|
|
99
|
+
}
|
|
100
|
+
if (!receiptMatchesStatus(parsed.receipt, response.status)) {
|
|
101
|
+
diagnostic(options, {
|
|
102
|
+
kind: "client.failure",
|
|
103
|
+
code: "response_invalid",
|
|
104
|
+
target,
|
|
105
|
+
});
|
|
106
|
+
return retryableResult(502);
|
|
107
|
+
}
|
|
108
|
+
return Object.freeze({
|
|
109
|
+
receipt: parsed.receipt,
|
|
110
|
+
status: response.status,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
const externalAbort = input.signal?.aborted === true;
|
|
115
|
+
const timeout = timeoutController.signal.aborted && !externalAbort;
|
|
116
|
+
const code = externalAbort
|
|
117
|
+
? "aborted"
|
|
118
|
+
: timeout
|
|
119
|
+
? "timeout"
|
|
120
|
+
: "network_failure";
|
|
121
|
+
diagnostic(options, { kind: "client.failure", code, target });
|
|
122
|
+
return retryableResult(externalAbort ? 499 : timeout ? 504 : 503);
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
combined.cleanup();
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/** Creates an inert Fetch handler. No server or listener is started. */
|
|
132
|
+
export function createMeshHttpHandler(options) {
|
|
133
|
+
if (!options || typeof options.accept !== "function") {
|
|
134
|
+
throw new TypeError("Mesh HTTP durable acceptor is required");
|
|
135
|
+
}
|
|
136
|
+
const target = freezeIngressTarget(options.target);
|
|
137
|
+
const path = exactPath(options.path ?? DEFAULT_MESH_HTTP_PATH);
|
|
138
|
+
const protocolMaximum = options.protocolOptions?.limits?.maximumEnvelopeBytes ??
|
|
139
|
+
DEFAULT_MESH_PROTOCOL_LIMITS.maximumEnvelopeBytes;
|
|
140
|
+
const maximumBodyBytes = positiveInteger(options.maximumBodyBytes ?? protocolMaximum, "maximumBodyBytes", DEFAULT_MESH_PROTOCOL_LIMITS.maximumEnvelopeBytes);
|
|
141
|
+
const cors = normalizeCorsPolicy(options.cors);
|
|
142
|
+
return async (request) => {
|
|
143
|
+
let requestUrl;
|
|
144
|
+
try {
|
|
145
|
+
requestUrl = new URL(request.url);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return receiptResponse(400, "permanent_rejection");
|
|
149
|
+
}
|
|
150
|
+
const origin = request.headers.get("origin");
|
|
151
|
+
const respond = (status, disposition, messageId, retryAfterMs) => applyCors(receiptResponse(status, disposition, messageId, retryAfterMs), origin, cors);
|
|
152
|
+
if (request.method.toUpperCase() === "OPTIONS") {
|
|
153
|
+
if (requestUrl.pathname !== path || requestUrl.search !== "") {
|
|
154
|
+
return respond(405, "permanent_rejection");
|
|
155
|
+
}
|
|
156
|
+
return corsPreflight(request, cors);
|
|
157
|
+
}
|
|
158
|
+
if (request.method.toUpperCase() !== "POST" ||
|
|
159
|
+
requestUrl.pathname !== path ||
|
|
160
|
+
requestUrl.search !== "") {
|
|
161
|
+
return respond(405, "permanent_rejection");
|
|
162
|
+
}
|
|
163
|
+
if (origin !== null && cors && !cors.allowedOrigins.has(origin)) {
|
|
164
|
+
return receiptResponse(403, "permanent_rejection");
|
|
165
|
+
}
|
|
166
|
+
if (options.authenticate) {
|
|
167
|
+
try {
|
|
168
|
+
if (!(await options.authenticate(request, target))) {
|
|
169
|
+
return respond(401, "permanent_rejection");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
diagnostic(options, {
|
|
174
|
+
kind: "handler.failure",
|
|
175
|
+
code: "authentication_failure",
|
|
176
|
+
});
|
|
177
|
+
return respond(401, "permanent_rejection");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const mediaType = request.headers
|
|
181
|
+
.get("content-type")
|
|
182
|
+
?.split(";", 1)[0]
|
|
183
|
+
?.trim()
|
|
184
|
+
.toLowerCase();
|
|
185
|
+
if (mediaType !== "application/json") {
|
|
186
|
+
return respond(415, "permanent_rejection");
|
|
187
|
+
}
|
|
188
|
+
const encoding = request.headers
|
|
189
|
+
.get("content-encoding")
|
|
190
|
+
?.trim()
|
|
191
|
+
.toLowerCase();
|
|
192
|
+
if (encoding && encoding !== "identity") {
|
|
193
|
+
return respond(415, "permanent_rejection");
|
|
194
|
+
}
|
|
195
|
+
const declaredLength = request.headers.get("content-length");
|
|
196
|
+
if (declaredLength !== null &&
|
|
197
|
+
(!/^\d+$/u.test(declaredLength) ||
|
|
198
|
+
Number(declaredLength) > maximumBodyBytes)) {
|
|
199
|
+
return respond(413, "permanent_rejection");
|
|
200
|
+
}
|
|
201
|
+
let bytes;
|
|
202
|
+
try {
|
|
203
|
+
bytes = await readBoundedBody(request, maximumBodyBytes);
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
diagnostic(options, { kind: "handler.failure", code: "body_failure" });
|
|
207
|
+
return respond(413, "permanent_rejection");
|
|
208
|
+
}
|
|
209
|
+
const parsed = parseSignedMeshEnvelope(bytes, options.protocolOptions);
|
|
210
|
+
if (!parsed.ok)
|
|
211
|
+
return respond(400, "permanent_rejection");
|
|
212
|
+
const envelope = parsed.value;
|
|
213
|
+
if (!envelopeTargets(envelope, target)) {
|
|
214
|
+
diagnostic(options, {
|
|
215
|
+
kind: "handler.failure",
|
|
216
|
+
code: "scope_rejected",
|
|
217
|
+
messageId: envelope.messageId,
|
|
218
|
+
});
|
|
219
|
+
return respond(422, "permanent_rejection");
|
|
220
|
+
}
|
|
221
|
+
let decision;
|
|
222
|
+
try {
|
|
223
|
+
decision = await options.accept(envelope, { target, request });
|
|
224
|
+
validateIngressDecision(decision);
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
diagnostic(options, {
|
|
228
|
+
kind: "handler.failure",
|
|
229
|
+
code: "acceptor_failure",
|
|
230
|
+
messageId: envelope.messageId,
|
|
231
|
+
});
|
|
232
|
+
return respond(503, "retryable", envelope.messageId);
|
|
233
|
+
}
|
|
234
|
+
if (decision.accepted) {
|
|
235
|
+
return respond(202, "accepted", envelope.messageId);
|
|
236
|
+
}
|
|
237
|
+
const status = decision.disposition === "retryable"
|
|
238
|
+
? decision.retryAfterMs === undefined
|
|
239
|
+
? 503
|
|
240
|
+
: 429
|
|
241
|
+
: 422;
|
|
242
|
+
return respond(status, decision.disposition, envelope.messageId, decision.retryAfterMs);
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function targetFor(envelope, explicitPeerId) {
|
|
246
|
+
const audiencePeerId = envelope.audience.kind === "peer" ? envelope.audience.peerId : undefined;
|
|
247
|
+
if (explicitPeerId !== undefined &&
|
|
248
|
+
(!validIdentifier(explicitPeerId) ||
|
|
249
|
+
(audiencePeerId !== undefined && explicitPeerId !== audiencePeerId))) {
|
|
250
|
+
throw new TypeError("Mesh HTTP target peer does not match the envelope");
|
|
251
|
+
}
|
|
252
|
+
const peerId = explicitPeerId ?? audiencePeerId;
|
|
253
|
+
if (!peerId) {
|
|
254
|
+
throw new TypeError("Mesh HTTP topic delivery requires targetPeerId");
|
|
255
|
+
}
|
|
256
|
+
return Object.freeze({
|
|
257
|
+
tenantId: envelope.tenantId,
|
|
258
|
+
meshId: envelope.meshId,
|
|
259
|
+
peerId,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function validateEndpoint(endpoint, allowedSchemes) {
|
|
263
|
+
if (!endpoint || typeof endpoint !== "object") {
|
|
264
|
+
throw new TypeError("Mesh HTTP endpoint is required");
|
|
265
|
+
}
|
|
266
|
+
const url = new URL(endpoint.url);
|
|
267
|
+
if (!allowedSchemes.has(url.protocol) ||
|
|
268
|
+
url.username !== "" ||
|
|
269
|
+
url.password !== "" ||
|
|
270
|
+
url.hash !== "") {
|
|
271
|
+
throw new TypeError("Mesh HTTP endpoint URL is not allowed");
|
|
272
|
+
}
|
|
273
|
+
const headers = new Headers();
|
|
274
|
+
for (const [name, value] of Object.entries(endpoint.headers ?? {})) {
|
|
275
|
+
const lower = name.toLowerCase();
|
|
276
|
+
if ([
|
|
277
|
+
"accept",
|
|
278
|
+
"connection",
|
|
279
|
+
"content-length",
|
|
280
|
+
"content-type",
|
|
281
|
+
"host",
|
|
282
|
+
"transfer-encoding",
|
|
283
|
+
].includes(lower) ||
|
|
284
|
+
typeof value !== "string" ||
|
|
285
|
+
value.length > 8_192) {
|
|
286
|
+
throw new TypeError("Mesh HTTP endpoint header is not allowed");
|
|
287
|
+
}
|
|
288
|
+
headers.set(name, value);
|
|
289
|
+
}
|
|
290
|
+
return { url, headers };
|
|
291
|
+
}
|
|
292
|
+
function freezeIngressTarget(target) {
|
|
293
|
+
if (!target || typeof target !== "object") {
|
|
294
|
+
throw new TypeError("Mesh HTTP ingress target is required");
|
|
295
|
+
}
|
|
296
|
+
const fields = ["tenantId", "meshId", "peerId", "instanceId"];
|
|
297
|
+
for (const field of fields) {
|
|
298
|
+
if (!validIdentifier(target[field])) {
|
|
299
|
+
throw new TypeError(`Mesh HTTP ingress ${field} is required`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return Object.freeze({
|
|
303
|
+
tenantId: target.tenantId,
|
|
304
|
+
meshId: target.meshId,
|
|
305
|
+
peerId: target.peerId,
|
|
306
|
+
instanceId: target.instanceId,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
function exactPath(value) {
|
|
310
|
+
if (typeof value !== "string" ||
|
|
311
|
+
!value.startsWith("/") ||
|
|
312
|
+
value.includes("?") ||
|
|
313
|
+
value.includes("#") ||
|
|
314
|
+
value.length > 1_024) {
|
|
315
|
+
throw new TypeError("Mesh HTTP path must be an exact absolute path");
|
|
316
|
+
}
|
|
317
|
+
return value;
|
|
318
|
+
}
|
|
319
|
+
function normalizeCorsPolicy(policy) {
|
|
320
|
+
if (policy === undefined)
|
|
321
|
+
return undefined;
|
|
322
|
+
if (!policy ||
|
|
323
|
+
!Array.isArray(policy.allowedOrigins) ||
|
|
324
|
+
policy.allowedOrigins.length < 1 ||
|
|
325
|
+
policy.allowedOrigins.length > 64) {
|
|
326
|
+
throw new TypeError("Mesh HTTP CORS origins are invalid");
|
|
327
|
+
}
|
|
328
|
+
const allowedOrigins = new Set();
|
|
329
|
+
for (const origin of policy.allowedOrigins) {
|
|
330
|
+
let parsed;
|
|
331
|
+
try {
|
|
332
|
+
parsed = new URL(origin);
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
throw new TypeError("Mesh HTTP CORS origin is invalid");
|
|
336
|
+
}
|
|
337
|
+
if ((parsed.protocol !== "http:" && parsed.protocol !== "https:") ||
|
|
338
|
+
parsed.origin !== origin ||
|
|
339
|
+
parsed.username !== "" ||
|
|
340
|
+
parsed.password !== "" ||
|
|
341
|
+
parsed.pathname !== "/" ||
|
|
342
|
+
parsed.search !== "" ||
|
|
343
|
+
parsed.hash !== "" ||
|
|
344
|
+
allowedOrigins.has(origin)) {
|
|
345
|
+
throw new TypeError("Mesh HTTP CORS origin is invalid");
|
|
346
|
+
}
|
|
347
|
+
allowedOrigins.add(origin);
|
|
348
|
+
}
|
|
349
|
+
const requestHeaders = policy.allowedRequestHeaders ?? [
|
|
350
|
+
"authorization",
|
|
351
|
+
"content-type",
|
|
352
|
+
];
|
|
353
|
+
if (!Array.isArray(requestHeaders) ||
|
|
354
|
+
requestHeaders.length > 32 ||
|
|
355
|
+
requestHeaders.some((header) => typeof header !== "string" ||
|
|
356
|
+
header !== header.toLowerCase() ||
|
|
357
|
+
!/^[!#$%&'*+.^_`|~0-9a-z-]+$/u.test(header))) {
|
|
358
|
+
throw new TypeError("Mesh HTTP CORS request headers are invalid");
|
|
359
|
+
}
|
|
360
|
+
const allowedRequestHeaders = new Set(requestHeaders);
|
|
361
|
+
if (allowedRequestHeaders.size !== requestHeaders.length) {
|
|
362
|
+
throw new TypeError("Mesh HTTP CORS request headers are invalid");
|
|
363
|
+
}
|
|
364
|
+
const maxAgeSeconds = policy.maxAgeSeconds ?? 600;
|
|
365
|
+
if (!Number.isSafeInteger(maxAgeSeconds) ||
|
|
366
|
+
maxAgeSeconds < 0 ||
|
|
367
|
+
maxAgeSeconds > 86_400) {
|
|
368
|
+
throw new RangeError("Mesh HTTP CORS maxAgeSeconds is outside its range");
|
|
369
|
+
}
|
|
370
|
+
return Object.freeze({
|
|
371
|
+
allowedOrigins,
|
|
372
|
+
allowedRequestHeaders,
|
|
373
|
+
maxAgeSeconds,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function corsPreflight(request, policy) {
|
|
377
|
+
if (!policy)
|
|
378
|
+
return receiptResponse(405, "permanent_rejection");
|
|
379
|
+
const origin = request.headers.get("origin");
|
|
380
|
+
const method = request.headers.get("access-control-request-method");
|
|
381
|
+
const requestedHeaders = (request.headers.get("access-control-request-headers") ?? "")
|
|
382
|
+
.split(",")
|
|
383
|
+
.map((header) => header.trim().toLowerCase())
|
|
384
|
+
.filter(Boolean);
|
|
385
|
+
if (origin === null ||
|
|
386
|
+
!policy.allowedOrigins.has(origin) ||
|
|
387
|
+
method?.toUpperCase() !== "POST" ||
|
|
388
|
+
requestedHeaders.some((header) => !policy.allowedRequestHeaders.has(header))) {
|
|
389
|
+
return receiptResponse(403, "permanent_rejection");
|
|
390
|
+
}
|
|
391
|
+
const headers = new Headers({
|
|
392
|
+
"access-control-allow-methods": "POST",
|
|
393
|
+
"access-control-allow-origin": origin,
|
|
394
|
+
"cache-control": "no-store",
|
|
395
|
+
vary: "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
|
|
396
|
+
});
|
|
397
|
+
if (policy.allowedRequestHeaders.size > 0) {
|
|
398
|
+
headers.set("access-control-allow-headers", [...policy.allowedRequestHeaders].join(", "));
|
|
399
|
+
}
|
|
400
|
+
headers.set("access-control-max-age", String(policy.maxAgeSeconds));
|
|
401
|
+
return new Response(null, { status: 204, headers });
|
|
402
|
+
}
|
|
403
|
+
function applyCors(response, origin, policy) {
|
|
404
|
+
if (!origin || !policy?.allowedOrigins.has(origin))
|
|
405
|
+
return response;
|
|
406
|
+
response.headers.set("access-control-allow-origin", origin);
|
|
407
|
+
response.headers.append("vary", "Origin");
|
|
408
|
+
return response;
|
|
409
|
+
}
|
|
410
|
+
function envelopeTargets(envelope, target) {
|
|
411
|
+
return (envelope.tenantId === target.tenantId &&
|
|
412
|
+
envelope.meshId === target.meshId &&
|
|
413
|
+
(envelope.audience.kind !== "peer" ||
|
|
414
|
+
envelope.audience.peerId === target.peerId));
|
|
415
|
+
}
|
|
416
|
+
async function readBoundedBody(request, maximumBytes) {
|
|
417
|
+
return readBoundedStream(request.body, maximumBytes);
|
|
418
|
+
}
|
|
419
|
+
async function readBoundedStream(stream, maximumBytes) {
|
|
420
|
+
if (!stream)
|
|
421
|
+
return new Uint8Array();
|
|
422
|
+
const reader = stream.getReader();
|
|
423
|
+
const chunks = [];
|
|
424
|
+
let length = 0;
|
|
425
|
+
try {
|
|
426
|
+
while (true) {
|
|
427
|
+
const next = await reader.read();
|
|
428
|
+
if (next.done)
|
|
429
|
+
break;
|
|
430
|
+
if (!(next.value instanceof Uint8Array)) {
|
|
431
|
+
await reader.cancel("mesh_http_non_byte_stream").catch(() => undefined);
|
|
432
|
+
throw new TypeError("Mesh HTTP body stream must contain bytes");
|
|
433
|
+
}
|
|
434
|
+
length += next.value.byteLength;
|
|
435
|
+
if (length > maximumBytes) {
|
|
436
|
+
await reader.cancel("mesh_http_body_too_large").catch(() => undefined);
|
|
437
|
+
throw new RangeError("request_too_large");
|
|
438
|
+
}
|
|
439
|
+
chunks.push(next.value);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
finally {
|
|
443
|
+
reader.releaseLock();
|
|
444
|
+
}
|
|
445
|
+
const result = new Uint8Array(length);
|
|
446
|
+
let offset = 0;
|
|
447
|
+
for (const chunk of chunks) {
|
|
448
|
+
result.set(chunk, offset);
|
|
449
|
+
offset += chunk.byteLength;
|
|
450
|
+
}
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
async function readReceipt(response, maximumBytes) {
|
|
454
|
+
const contentType = response.headers
|
|
455
|
+
.get("content-type")
|
|
456
|
+
?.split(";", 1)[0]
|
|
457
|
+
?.trim()
|
|
458
|
+
.toLowerCase();
|
|
459
|
+
if (contentType !== "application/json")
|
|
460
|
+
return {};
|
|
461
|
+
let bytes;
|
|
462
|
+
try {
|
|
463
|
+
bytes = await readBoundedStream(response.body, maximumBytes);
|
|
464
|
+
}
|
|
465
|
+
catch (error) {
|
|
466
|
+
return error instanceof RangeError ? { tooLarge: true } : {};
|
|
467
|
+
}
|
|
468
|
+
let candidate;
|
|
469
|
+
try {
|
|
470
|
+
candidate = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
return {};
|
|
474
|
+
}
|
|
475
|
+
if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
476
|
+
return {};
|
|
477
|
+
}
|
|
478
|
+
const record = candidate;
|
|
479
|
+
const keys = Object.keys(record).sort();
|
|
480
|
+
const allowed = ["disposition", "messageId", "retryAfterMs", "schemaVersion"];
|
|
481
|
+
if (keys.some((key) => !allowed.includes(key)))
|
|
482
|
+
return {};
|
|
483
|
+
if (record.schemaVersion !== MESH_HTTP_RECEIPT_SCHEMA_VERSION ||
|
|
484
|
+
!["accepted", "permanent_rejection", "retryable"].includes(String(record.disposition)) ||
|
|
485
|
+
(record.messageId !== undefined && typeof record.messageId !== "string") ||
|
|
486
|
+
(record.retryAfterMs !== undefined &&
|
|
487
|
+
(!Number.isSafeInteger(record.retryAfterMs) ||
|
|
488
|
+
Number(record.retryAfterMs) < 1 ||
|
|
489
|
+
Number(record.retryAfterMs) > 3_600_000)) ||
|
|
490
|
+
(record.disposition !== "retryable" && record.retryAfterMs !== undefined)) {
|
|
491
|
+
return {};
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
receipt: Object.freeze({
|
|
495
|
+
schemaVersion: MESH_HTTP_RECEIPT_SCHEMA_VERSION,
|
|
496
|
+
disposition: record.disposition,
|
|
497
|
+
...(record.messageId === undefined
|
|
498
|
+
? {}
|
|
499
|
+
: { messageId: record.messageId }),
|
|
500
|
+
...(record.retryAfterMs === undefined
|
|
501
|
+
? {}
|
|
502
|
+
: { retryAfterMs: record.retryAfterMs }),
|
|
503
|
+
}),
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function validateIngressDecision(decision) {
|
|
507
|
+
if (!decision || typeof decision !== "object") {
|
|
508
|
+
throw new TypeError("Mesh HTTP ingress decision is invalid");
|
|
509
|
+
}
|
|
510
|
+
const keys = Object.keys(decision).sort();
|
|
511
|
+
if (decision.accepted === true) {
|
|
512
|
+
if (keys.some((key) => !["accepted", "duplicate"].includes(key)) ||
|
|
513
|
+
(decision.duplicate !== undefined &&
|
|
514
|
+
typeof decision.duplicate !== "boolean")) {
|
|
515
|
+
throw new TypeError("Mesh HTTP ingress decision is invalid");
|
|
516
|
+
}
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (decision.accepted !== false ||
|
|
520
|
+
keys.some((key) => !["accepted", "disposition", "retryAfterMs"].includes(key)) ||
|
|
521
|
+
!["permanent_rejection", "retryable"].includes(decision.disposition) ||
|
|
522
|
+
(decision.retryAfterMs !== undefined &&
|
|
523
|
+
(decision.disposition !== "retryable" ||
|
|
524
|
+
!Number.isSafeInteger(decision.retryAfterMs) ||
|
|
525
|
+
decision.retryAfterMs < 1 ||
|
|
526
|
+
decision.retryAfterMs > 3_600_000))) {
|
|
527
|
+
throw new TypeError("Mesh HTTP ingress decision is invalid");
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function receiptMatchesStatus(receipt, status) {
|
|
531
|
+
if (receipt.disposition === "accepted")
|
|
532
|
+
return status >= 200 && status < 300;
|
|
533
|
+
if (receipt.disposition === "retryable") {
|
|
534
|
+
return status === 429 || status >= 500;
|
|
535
|
+
}
|
|
536
|
+
return status >= 400 && status < 500 && status !== 429;
|
|
537
|
+
}
|
|
538
|
+
function receiptResponse(status, disposition, messageId, retryAfterMs) {
|
|
539
|
+
const receipt = {
|
|
540
|
+
schemaVersion: MESH_HTTP_RECEIPT_SCHEMA_VERSION,
|
|
541
|
+
disposition,
|
|
542
|
+
...(messageId === undefined ? {} : { messageId }),
|
|
543
|
+
...(retryAfterMs === undefined ? {} : { retryAfterMs }),
|
|
544
|
+
};
|
|
545
|
+
const headers = new Headers({
|
|
546
|
+
"cache-control": "no-store",
|
|
547
|
+
"content-type": "application/json",
|
|
548
|
+
});
|
|
549
|
+
if (retryAfterMs !== undefined) {
|
|
550
|
+
headers.set("retry-after", String(Math.max(1, Math.ceil(retryAfterMs / 1_000))));
|
|
551
|
+
}
|
|
552
|
+
return new Response(JSON.stringify(receipt), { status, headers });
|
|
553
|
+
}
|
|
554
|
+
function retryableResult(status) {
|
|
555
|
+
return Object.freeze({
|
|
556
|
+
status,
|
|
557
|
+
receipt: Object.freeze({
|
|
558
|
+
schemaVersion: MESH_HTTP_RECEIPT_SCHEMA_VERSION,
|
|
559
|
+
disposition: "retryable",
|
|
560
|
+
}),
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
function permanentResult(status) {
|
|
564
|
+
return Object.freeze({
|
|
565
|
+
status,
|
|
566
|
+
receipt: Object.freeze({
|
|
567
|
+
schemaVersion: MESH_HTTP_RECEIPT_SCHEMA_VERSION,
|
|
568
|
+
disposition: "permanent_rejection",
|
|
569
|
+
}),
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
function combineSignals(external, timeout) {
|
|
573
|
+
if (!external)
|
|
574
|
+
return { signal: timeout, cleanup() { } };
|
|
575
|
+
const controller = new AbortController();
|
|
576
|
+
const abortFromExternal = () => controller.abort(external.reason);
|
|
577
|
+
const abortFromTimeout = () => controller.abort(timeout.reason);
|
|
578
|
+
if (external.aborted)
|
|
579
|
+
abortFromExternal();
|
|
580
|
+
else
|
|
581
|
+
external.addEventListener("abort", abortFromExternal, { once: true });
|
|
582
|
+
if (timeout.aborted)
|
|
583
|
+
abortFromTimeout();
|
|
584
|
+
else
|
|
585
|
+
timeout.addEventListener("abort", abortFromTimeout, { once: true });
|
|
586
|
+
return {
|
|
587
|
+
signal: controller.signal,
|
|
588
|
+
cleanup() {
|
|
589
|
+
external.removeEventListener("abort", abortFromExternal);
|
|
590
|
+
timeout.removeEventListener("abort", abortFromTimeout);
|
|
591
|
+
},
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
function diagnostic(options, value) {
|
|
595
|
+
try {
|
|
596
|
+
options.onDiagnostic?.(Object.freeze(value));
|
|
597
|
+
}
|
|
598
|
+
catch {
|
|
599
|
+
// Diagnostics never change a transport decision.
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function positiveInteger(value, name, maximum) {
|
|
603
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
|
|
604
|
+
throw new RangeError(`Mesh HTTP ${name} is outside its supported range`);
|
|
605
|
+
}
|
|
606
|
+
return value;
|
|
607
|
+
}
|
|
608
|
+
function validIdentifier(value) {
|
|
609
|
+
return (typeof value === "string" &&
|
|
610
|
+
value.length > 0 &&
|
|
611
|
+
new TextEncoder().encode(value).byteLength <= 256 &&
|
|
612
|
+
/^[A-Za-z0-9][A-Za-z0-9._:@-]*$/u.test(value));
|
|
613
|
+
}
|
|
614
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC;AAMlC,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAU,CAAC;AAC3D,MAAM,CAAC,MAAM,sBAAsB,GAAG,8BAA8B,CAAC;AAuHrE,mFAAmF;AACnF,MAAM,UAAU,oBAAoB,CAClC,OAA8B;IAE9B,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,eAAe,KAAK,UAAU,EAAE,CAA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AACJ,CAAC;AAED,SAAS,UAAU,CACjB,OAA6E,EAC7E,KAAyB;IAEzB,IAAI,CAAC;QACH,OAAO,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,iDAAiD;IACnD,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,KAAa,EAAE,IAAY,EAAE,OAAe;IACnE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;QACjE,MAAM,IAAI,UAAU,CAAC,aAAa,IAAI,iCAAiC,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,MAAM,GAAG,CAAC;QAChB,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,IAAI,GAAG;QACjD,iCAAiC,CAAC,IAAI,CAAC,KAAK,CAAC,CAC9C,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentplat/mesh-http",
|
|
3
|
+
"version": "0.3.0-alpha.5",
|
|
4
|
+
"description": "Bounded Fetch-compatible HTTP transport for signed Agentplat Mesh envelopes.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@agentplat/mesh-protocol": "^0.3.0-alpha.5"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20.19.3"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/Agentplat/agentplat.git",
|
|
32
|
+
"directory": "packages/mesh-http"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p tsconfig.json",
|
|
36
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
37
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
|
|
38
|
+
}
|
|
39
|
+
}
|