@intentrax/sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +185 -0
- package/README.md +148 -0
- package/cli/intentrax.mjs +2412 -0
- package/examples/adapters/claude-code.md +27 -0
- package/examples/adapters/cursor.md +27 -0
- package/examples/adapters/langchain.md +27 -0
- package/examples/adapters/langgraph.md +28 -0
- package/examples/adapters/mcp.md +27 -0
- package/examples/adapters/vercel-ai-sdk.md +28 -0
- package/examples/agent-gateway-admission.md +72 -0
- package/examples/one-command-init.md +94 -0
- package/http.d.ts +392 -0
- package/http.js +667 -0
- package/http.ts +667 -0
- package/index.d.ts +235 -0
- package/index.js +626 -0
- package/index.ts +626 -0
- package/package.json +63 -0
package/http.js
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AGENT_ADMISSION_ENDPOINT,
|
|
3
|
+
API_VERSION,
|
|
4
|
+
INTENT_EXECUTE_ENDPOINT,
|
|
5
|
+
PROOF_EXPORT_ENDPOINT_PREFIX,
|
|
6
|
+
SDK_INPUT_ERROR_CODE,
|
|
7
|
+
SDK_VERSION,
|
|
8
|
+
buildAgentGatewayAdmissionEnvelope,
|
|
9
|
+
buildIntentExecuteEnvelope,
|
|
10
|
+
buildProofExportEnvelope,
|
|
11
|
+
buildProofInclusionEnvelope,
|
|
12
|
+
buildProofReadEnvelope,
|
|
13
|
+
buildProofReplayEnvelope,
|
|
14
|
+
buildReceiptVerificationEnvelope,
|
|
15
|
+
buildVerifierHandoffEnvelope,
|
|
16
|
+
buildVerificationEnvelope,
|
|
17
|
+
canonicalJson,
|
|
18
|
+
} from "./index.js";
|
|
19
|
+
|
|
20
|
+
export function buildVerificationHttpRequest(request, options) {
|
|
21
|
+
const invalidOptions = [];
|
|
22
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
23
|
+
invalidOptions.push("base_url");
|
|
24
|
+
}
|
|
25
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
26
|
+
invalidOptions.push("api_key");
|
|
27
|
+
}
|
|
28
|
+
if (invalidOptions.length > 0) {
|
|
29
|
+
return {
|
|
30
|
+
status: "FAIL",
|
|
31
|
+
error: {
|
|
32
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
33
|
+
error_type: "public_sdk_input_error",
|
|
34
|
+
message: "Verification HTTP options are missing or malformed.",
|
|
35
|
+
invalid_fields: invalidOptions.sort(),
|
|
36
|
+
retriable: false,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const envelope = buildVerificationEnvelope(request);
|
|
41
|
+
if (envelope.status !== "PASS") {
|
|
42
|
+
return envelope;
|
|
43
|
+
}
|
|
44
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
45
|
+
const path = request.request_path.startsWith("/") ? request.request_path : "/" + request.request_path;
|
|
46
|
+
return {
|
|
47
|
+
status: "PASS",
|
|
48
|
+
output: {
|
|
49
|
+
method: request.request_method,
|
|
50
|
+
url: baseUrl + path,
|
|
51
|
+
headers: {
|
|
52
|
+
"content-type": "application/json",
|
|
53
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
54
|
+
"X-Intentrax-Idempotency-Key": envelope.output.idempotency_key,
|
|
55
|
+
"intentrax-api-version": API_VERSION,
|
|
56
|
+
"intentrax-request-hash": envelope.output.request_hash,
|
|
57
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
58
|
+
},
|
|
59
|
+
body: canonicalJson(request),
|
|
60
|
+
envelope: envelope.output,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function verifyProofHttp(request, transport, options) {
|
|
66
|
+
if (typeof transport !== "function") {
|
|
67
|
+
return {
|
|
68
|
+
status: "FAIL",
|
|
69
|
+
error: {
|
|
70
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
71
|
+
error_type: "public_sdk_input_error",
|
|
72
|
+
message: "HTTP transport function is required.",
|
|
73
|
+
invalid_fields: ["transport"],
|
|
74
|
+
retriable: false,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const httpRequest = buildVerificationHttpRequest(request, options);
|
|
79
|
+
if (httpRequest.status !== "PASS") {
|
|
80
|
+
return httpRequest;
|
|
81
|
+
}
|
|
82
|
+
const response = await transport(httpRequest.output);
|
|
83
|
+
return {
|
|
84
|
+
status: "PASS",
|
|
85
|
+
output: {
|
|
86
|
+
request: httpRequest.output,
|
|
87
|
+
response,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function buildReceiptVerificationHttpRequest(request, options) {
|
|
93
|
+
const invalidOptions = [];
|
|
94
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
95
|
+
invalidOptions.push("base_url");
|
|
96
|
+
}
|
|
97
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
98
|
+
invalidOptions.push("api_key");
|
|
99
|
+
}
|
|
100
|
+
if (invalidOptions.length > 0) {
|
|
101
|
+
return {
|
|
102
|
+
status: "FAIL",
|
|
103
|
+
error: {
|
|
104
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
105
|
+
error_type: "public_sdk_input_error",
|
|
106
|
+
message: "Receipt verification HTTP options are missing or malformed.",
|
|
107
|
+
invalid_fields: invalidOptions.sort(),
|
|
108
|
+
retriable: false,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const envelope = buildReceiptVerificationEnvelope(request);
|
|
113
|
+
if (envelope.status !== "PASS") {
|
|
114
|
+
return envelope;
|
|
115
|
+
}
|
|
116
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
117
|
+
return {
|
|
118
|
+
status: "PASS",
|
|
119
|
+
output: {
|
|
120
|
+
method: "POST",
|
|
121
|
+
url: baseUrl + envelope.output.endpoint,
|
|
122
|
+
headers: {
|
|
123
|
+
"content-type": "application/json",
|
|
124
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
125
|
+
"X-Intentrax-Idempotency-Key": envelope.output.idempotency_key,
|
|
126
|
+
"intentrax-api-version": API_VERSION,
|
|
127
|
+
"intentrax-request-hash": envelope.output.request_hash,
|
|
128
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
129
|
+
},
|
|
130
|
+
body: canonicalJson(request),
|
|
131
|
+
envelope: envelope.output,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function verifyReceiptHttp(request, transport, options) {
|
|
137
|
+
if (typeof transport !== "function") {
|
|
138
|
+
return {
|
|
139
|
+
status: "FAIL",
|
|
140
|
+
error: {
|
|
141
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
142
|
+
error_type: "public_sdk_input_error",
|
|
143
|
+
message: "HTTP transport function is required.",
|
|
144
|
+
invalid_fields: ["transport"],
|
|
145
|
+
retriable: false,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const httpRequest = buildReceiptVerificationHttpRequest(request, options);
|
|
150
|
+
if (httpRequest.status !== "PASS") {
|
|
151
|
+
return httpRequest;
|
|
152
|
+
}
|
|
153
|
+
const response = await transport(httpRequest.output);
|
|
154
|
+
return {
|
|
155
|
+
status: "PASS",
|
|
156
|
+
output: {
|
|
157
|
+
request: httpRequest.output,
|
|
158
|
+
response,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function buildProofExportHttpRequest(request, options) {
|
|
164
|
+
const invalidOptions = [];
|
|
165
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
166
|
+
invalidOptions.push("base_url");
|
|
167
|
+
}
|
|
168
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
169
|
+
invalidOptions.push("api_key");
|
|
170
|
+
}
|
|
171
|
+
if (invalidOptions.length > 0) {
|
|
172
|
+
return {
|
|
173
|
+
status: "FAIL",
|
|
174
|
+
error: {
|
|
175
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
176
|
+
error_type: "public_sdk_input_error",
|
|
177
|
+
message: "Proof export HTTP options are missing or malformed.",
|
|
178
|
+
invalid_fields: invalidOptions.sort(),
|
|
179
|
+
retriable: false,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const envelope = buildProofExportEnvelope(request);
|
|
184
|
+
if (envelope.status !== "PASS") {
|
|
185
|
+
return envelope;
|
|
186
|
+
}
|
|
187
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
188
|
+
const accept = envelope.output.format === "pdf" ? "application/pdf" : "application/json";
|
|
189
|
+
return {
|
|
190
|
+
status: "PASS",
|
|
191
|
+
output: {
|
|
192
|
+
method: "GET",
|
|
193
|
+
url: `${baseUrl}${envelope.output.endpoint}?format=${encodeURIComponent(envelope.output.format)}`,
|
|
194
|
+
headers: {
|
|
195
|
+
accept,
|
|
196
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
197
|
+
"intentrax-api-version": API_VERSION,
|
|
198
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
199
|
+
},
|
|
200
|
+
body: "",
|
|
201
|
+
envelope: envelope.output,
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export async function exportProofHttp(request, transport, options) {
|
|
207
|
+
if (typeof transport !== "function") {
|
|
208
|
+
return {
|
|
209
|
+
status: "FAIL",
|
|
210
|
+
error: {
|
|
211
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
212
|
+
error_type: "public_sdk_input_error",
|
|
213
|
+
message: "HTTP transport function is required.",
|
|
214
|
+
invalid_fields: ["transport"],
|
|
215
|
+
retriable: false,
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const httpRequest = buildProofExportHttpRequest(request, options);
|
|
220
|
+
if (httpRequest.status !== "PASS") {
|
|
221
|
+
return httpRequest;
|
|
222
|
+
}
|
|
223
|
+
const response = await transport(httpRequest.output);
|
|
224
|
+
return {
|
|
225
|
+
status: "PASS",
|
|
226
|
+
output: {
|
|
227
|
+
request: httpRequest.output,
|
|
228
|
+
response,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function buildProofReadHttpRequest(request, options) {
|
|
234
|
+
const invalidOptions = [];
|
|
235
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
236
|
+
invalidOptions.push("base_url");
|
|
237
|
+
}
|
|
238
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
239
|
+
invalidOptions.push("api_key");
|
|
240
|
+
}
|
|
241
|
+
if (invalidOptions.length > 0) {
|
|
242
|
+
return {
|
|
243
|
+
status: "FAIL",
|
|
244
|
+
error: {
|
|
245
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
246
|
+
error_type: "public_sdk_input_error",
|
|
247
|
+
message: "Proof read HTTP options are missing or malformed.",
|
|
248
|
+
invalid_fields: invalidOptions.sort(),
|
|
249
|
+
retriable: false,
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const envelope = buildProofReadEnvelope(request);
|
|
254
|
+
if (envelope.status !== "PASS") {
|
|
255
|
+
return envelope;
|
|
256
|
+
}
|
|
257
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
258
|
+
return {
|
|
259
|
+
status: "PASS",
|
|
260
|
+
output: {
|
|
261
|
+
method: "GET",
|
|
262
|
+
url: baseUrl + envelope.output.endpoint,
|
|
263
|
+
headers: {
|
|
264
|
+
accept: "application/json",
|
|
265
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
266
|
+
"intentrax-api-version": API_VERSION,
|
|
267
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
268
|
+
},
|
|
269
|
+
body: "",
|
|
270
|
+
envelope: envelope.output,
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export async function readProofHttp(request, transport, options) {
|
|
276
|
+
if (typeof transport !== "function") {
|
|
277
|
+
return {
|
|
278
|
+
status: "FAIL",
|
|
279
|
+
error: {
|
|
280
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
281
|
+
error_type: "public_sdk_input_error",
|
|
282
|
+
message: "HTTP transport function is required.",
|
|
283
|
+
invalid_fields: ["transport"],
|
|
284
|
+
retriable: false,
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const httpRequest = buildProofReadHttpRequest(request, options);
|
|
289
|
+
if (httpRequest.status !== "PASS") {
|
|
290
|
+
return httpRequest;
|
|
291
|
+
}
|
|
292
|
+
const response = await transport(httpRequest.output);
|
|
293
|
+
return {
|
|
294
|
+
status: "PASS",
|
|
295
|
+
output: {
|
|
296
|
+
request: httpRequest.output,
|
|
297
|
+
response,
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function buildProofReplayHttpRequest(request, options) {
|
|
303
|
+
const invalidOptions = [];
|
|
304
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
305
|
+
invalidOptions.push("base_url");
|
|
306
|
+
}
|
|
307
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
308
|
+
invalidOptions.push("api_key");
|
|
309
|
+
}
|
|
310
|
+
if (invalidOptions.length > 0) {
|
|
311
|
+
return {
|
|
312
|
+
status: "FAIL",
|
|
313
|
+
error: {
|
|
314
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
315
|
+
error_type: "public_sdk_input_error",
|
|
316
|
+
message: "Proof replay HTTP options are missing or malformed.",
|
|
317
|
+
invalid_fields: invalidOptions.sort(),
|
|
318
|
+
retriable: false,
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
const envelope = buildProofReplayEnvelope(request);
|
|
323
|
+
if (envelope.status !== "PASS") {
|
|
324
|
+
return envelope;
|
|
325
|
+
}
|
|
326
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
327
|
+
return {
|
|
328
|
+
status: "PASS",
|
|
329
|
+
output: {
|
|
330
|
+
method: "POST",
|
|
331
|
+
url: baseUrl + envelope.output.endpoint,
|
|
332
|
+
headers: {
|
|
333
|
+
"content-type": "application/json",
|
|
334
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
335
|
+
"intentrax-api-version": API_VERSION,
|
|
336
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
337
|
+
},
|
|
338
|
+
body: canonicalJson(request),
|
|
339
|
+
envelope: envelope.output,
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export async function replayProofHttp(request, transport, options) {
|
|
345
|
+
if (typeof transport !== "function") {
|
|
346
|
+
return {
|
|
347
|
+
status: "FAIL",
|
|
348
|
+
error: {
|
|
349
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
350
|
+
error_type: "public_sdk_input_error",
|
|
351
|
+
message: "HTTP transport function is required.",
|
|
352
|
+
invalid_fields: ["transport"],
|
|
353
|
+
retriable: false,
|
|
354
|
+
},
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
const httpRequest = buildProofReplayHttpRequest(request, options);
|
|
358
|
+
if (httpRequest.status !== "PASS") {
|
|
359
|
+
return httpRequest;
|
|
360
|
+
}
|
|
361
|
+
const response = await transport(httpRequest.output);
|
|
362
|
+
return {
|
|
363
|
+
status: "PASS",
|
|
364
|
+
output: {
|
|
365
|
+
request: httpRequest.output,
|
|
366
|
+
response,
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function buildProofInclusionHttpRequest(request, options) {
|
|
372
|
+
const invalidOptions = [];
|
|
373
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
374
|
+
invalidOptions.push("base_url");
|
|
375
|
+
}
|
|
376
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
377
|
+
invalidOptions.push("api_key");
|
|
378
|
+
}
|
|
379
|
+
if (invalidOptions.length > 0) {
|
|
380
|
+
return {
|
|
381
|
+
status: "FAIL",
|
|
382
|
+
error: {
|
|
383
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
384
|
+
error_type: "public_sdk_input_error",
|
|
385
|
+
message: "Proof inclusion HTTP options are missing or malformed.",
|
|
386
|
+
invalid_fields: invalidOptions.sort(),
|
|
387
|
+
retriable: false,
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
const envelope = buildProofInclusionEnvelope(request);
|
|
392
|
+
if (envelope.status !== "PASS") {
|
|
393
|
+
return envelope;
|
|
394
|
+
}
|
|
395
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
396
|
+
return {
|
|
397
|
+
status: "PASS",
|
|
398
|
+
output: {
|
|
399
|
+
method: "GET",
|
|
400
|
+
url: baseUrl + envelope.output.endpoint,
|
|
401
|
+
headers: {
|
|
402
|
+
accept: "application/json",
|
|
403
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
404
|
+
"intentrax-api-version": API_VERSION,
|
|
405
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
406
|
+
},
|
|
407
|
+
body: "",
|
|
408
|
+
envelope: envelope.output,
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export async function getProofInclusionHttp(request, transport, options) {
|
|
414
|
+
if (typeof transport !== "function") {
|
|
415
|
+
return {
|
|
416
|
+
status: "FAIL",
|
|
417
|
+
error: {
|
|
418
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
419
|
+
error_type: "public_sdk_input_error",
|
|
420
|
+
message: "HTTP transport function is required.",
|
|
421
|
+
invalid_fields: ["transport"],
|
|
422
|
+
retriable: false,
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
const httpRequest = buildProofInclusionHttpRequest(request, options);
|
|
427
|
+
if (httpRequest.status !== "PASS") {
|
|
428
|
+
return httpRequest;
|
|
429
|
+
}
|
|
430
|
+
const response = await transport(httpRequest.output);
|
|
431
|
+
return {
|
|
432
|
+
status: "PASS",
|
|
433
|
+
output: {
|
|
434
|
+
request: httpRequest.output,
|
|
435
|
+
response,
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export function buildVerifierHandoffHttpRequest(request, options) {
|
|
441
|
+
const invalidOptions = [];
|
|
442
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
443
|
+
invalidOptions.push("base_url");
|
|
444
|
+
}
|
|
445
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
446
|
+
invalidOptions.push("api_key");
|
|
447
|
+
}
|
|
448
|
+
if (invalidOptions.length > 0) {
|
|
449
|
+
return {
|
|
450
|
+
status: "FAIL",
|
|
451
|
+
error: {
|
|
452
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
453
|
+
error_type: "public_sdk_input_error",
|
|
454
|
+
message: "Verifier handoff HTTP options are missing or malformed.",
|
|
455
|
+
invalid_fields: invalidOptions.sort(),
|
|
456
|
+
retriable: false,
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
const envelope = buildVerifierHandoffEnvelope(request);
|
|
461
|
+
if (envelope.status !== "PASS") {
|
|
462
|
+
return envelope;
|
|
463
|
+
}
|
|
464
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
465
|
+
return {
|
|
466
|
+
status: "PASS",
|
|
467
|
+
output: {
|
|
468
|
+
method: "GET",
|
|
469
|
+
url: baseUrl + envelope.output.endpoint,
|
|
470
|
+
headers: {
|
|
471
|
+
accept: "application/json",
|
|
472
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
473
|
+
"intentrax-api-version": API_VERSION,
|
|
474
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
475
|
+
},
|
|
476
|
+
body: "",
|
|
477
|
+
envelope: envelope.output,
|
|
478
|
+
},
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export async function getVerifierHandoffHttp(request, transport, options) {
|
|
483
|
+
if (typeof transport !== "function") {
|
|
484
|
+
return {
|
|
485
|
+
status: "FAIL",
|
|
486
|
+
error: {
|
|
487
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
488
|
+
error_type: "public_sdk_input_error",
|
|
489
|
+
message: "HTTP transport function is required.",
|
|
490
|
+
invalid_fields: ["transport"],
|
|
491
|
+
retriable: false,
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
const httpRequest = buildVerifierHandoffHttpRequest(request, options);
|
|
496
|
+
if (httpRequest.status !== "PASS") {
|
|
497
|
+
return httpRequest;
|
|
498
|
+
}
|
|
499
|
+
const response = await transport(httpRequest.output);
|
|
500
|
+
return {
|
|
501
|
+
status: "PASS",
|
|
502
|
+
output: {
|
|
503
|
+
request: httpRequest.output,
|
|
504
|
+
response,
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export function buildAgentGatewayAdmissionHttpRequest(request, options) {
|
|
510
|
+
const invalidOptions = [];
|
|
511
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
512
|
+
invalidOptions.push("base_url");
|
|
513
|
+
}
|
|
514
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
515
|
+
invalidOptions.push("api_key");
|
|
516
|
+
}
|
|
517
|
+
if (invalidOptions.length > 0) {
|
|
518
|
+
return {
|
|
519
|
+
status: "FAIL",
|
|
520
|
+
error: {
|
|
521
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
522
|
+
error_type: "public_sdk_input_error",
|
|
523
|
+
message: "Agent Gateway HTTP options are missing or malformed.",
|
|
524
|
+
invalid_fields: invalidOptions.sort(),
|
|
525
|
+
retriable: false,
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
const envelope = buildAgentGatewayAdmissionEnvelope(request);
|
|
530
|
+
if (envelope.status !== "PASS") {
|
|
531
|
+
return envelope;
|
|
532
|
+
}
|
|
533
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
534
|
+
return {
|
|
535
|
+
status: "PASS",
|
|
536
|
+
output: {
|
|
537
|
+
method: "POST",
|
|
538
|
+
url: baseUrl + AGENT_ADMISSION_ENDPOINT,
|
|
539
|
+
headers: {
|
|
540
|
+
"content-type": "application/json",
|
|
541
|
+
"X-Intentrax-Tenant-ID": request.tenant_id,
|
|
542
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
543
|
+
"X-Intentrax-Idempotency-Key": request.idempotency_key_hash,
|
|
544
|
+
"intentrax-api-version": API_VERSION,
|
|
545
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
546
|
+
},
|
|
547
|
+
body: canonicalJson(request),
|
|
548
|
+
envelope: envelope.output,
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export async function admitAgentGatewayHttp(request, transport, options) {
|
|
554
|
+
if (typeof transport !== "function") {
|
|
555
|
+
return {
|
|
556
|
+
status: "FAIL",
|
|
557
|
+
error: {
|
|
558
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
559
|
+
error_type: "public_sdk_input_error",
|
|
560
|
+
message: "HTTP transport function is required.",
|
|
561
|
+
invalid_fields: ["transport"],
|
|
562
|
+
retriable: false,
|
|
563
|
+
},
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
const httpRequest = buildAgentGatewayAdmissionHttpRequest(request, options);
|
|
567
|
+
if (httpRequest.status !== "PASS") {
|
|
568
|
+
return httpRequest;
|
|
569
|
+
}
|
|
570
|
+
const response = await transport(httpRequest.output);
|
|
571
|
+
return {
|
|
572
|
+
status: "PASS",
|
|
573
|
+
output: {
|
|
574
|
+
request: httpRequest.output,
|
|
575
|
+
response,
|
|
576
|
+
},
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// buildIntentExecuteHttpRequest builds the POST for the fail-closed live
|
|
581
|
+
// execution lane. It is a thin envelope + transport builder: the body is the
|
|
582
|
+
// caller-supplied request canonicalized, and there is NO idempotency header
|
|
583
|
+
// (the engine derives RequestHash from the body; the caller's idempotency_key
|
|
584
|
+
// is an opaque body field). The lane returns HTTP 423 until the engine's
|
|
585
|
+
// LiveExecutionEnabled flag is set and HTTP 403 until the tenant is allowlisted;
|
|
586
|
+
// this builder does not assert that the lane is live.
|
|
587
|
+
export function buildIntentExecuteHttpRequest(request, options) {
|
|
588
|
+
const invalidOptions = [];
|
|
589
|
+
if (!options || typeof options.base_url !== "string" || options.base_url.length === 0) {
|
|
590
|
+
invalidOptions.push("base_url");
|
|
591
|
+
}
|
|
592
|
+
if (!options || typeof options.api_key !== "string" || options.api_key.length === 0) {
|
|
593
|
+
invalidOptions.push("api_key");
|
|
594
|
+
}
|
|
595
|
+
if (invalidOptions.length > 0) {
|
|
596
|
+
return {
|
|
597
|
+
status: "FAIL",
|
|
598
|
+
error: {
|
|
599
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
600
|
+
error_type: "public_sdk_input_error",
|
|
601
|
+
message: "Intent execute HTTP options are missing or malformed.",
|
|
602
|
+
invalid_fields: invalidOptions.sort(),
|
|
603
|
+
retriable: false,
|
|
604
|
+
},
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
const envelope = buildIntentExecuteEnvelope(request);
|
|
608
|
+
if (envelope.status !== "PASS") {
|
|
609
|
+
return envelope;
|
|
610
|
+
}
|
|
611
|
+
const baseUrl = options.base_url.replace(/\/+$/, "");
|
|
612
|
+
return {
|
|
613
|
+
status: "PASS",
|
|
614
|
+
output: {
|
|
615
|
+
method: "POST",
|
|
616
|
+
url: baseUrl + INTENT_EXECUTE_ENDPOINT,
|
|
617
|
+
headers: {
|
|
618
|
+
"content-type": "application/json",
|
|
619
|
+
"X-Intentrax-Tenant-ID": request.tenant_id,
|
|
620
|
+
"X-Intentrax-Api-Key": options.api_key,
|
|
621
|
+
"intentrax-api-version": API_VERSION,
|
|
622
|
+
"intentrax-sdk-version": SDK_VERSION,
|
|
623
|
+
},
|
|
624
|
+
body: canonicalJson(request),
|
|
625
|
+
envelope: envelope.output,
|
|
626
|
+
},
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// executeIntentHttp builds the request and awaits the caller-supplied
|
|
631
|
+
// transport. The engine response is returned VERBATIM under output.response:
|
|
632
|
+
// receipt_id, request_hash, registry_proof_id, response_hash, status, and
|
|
633
|
+
// vee_recorded are the engine's to produce and are never synthesized here.
|
|
634
|
+
export async function executeIntentHttp(request, transport, options) {
|
|
635
|
+
if (typeof transport !== "function") {
|
|
636
|
+
return {
|
|
637
|
+
status: "FAIL",
|
|
638
|
+
error: {
|
|
639
|
+
error_code: SDK_INPUT_ERROR_CODE,
|
|
640
|
+
error_type: "public_sdk_input_error",
|
|
641
|
+
message: "HTTP transport function is required.",
|
|
642
|
+
invalid_fields: ["transport"],
|
|
643
|
+
retriable: false,
|
|
644
|
+
},
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
const httpRequest = buildIntentExecuteHttpRequest(request, options);
|
|
648
|
+
if (httpRequest.status !== "PASS") {
|
|
649
|
+
return httpRequest;
|
|
650
|
+
}
|
|
651
|
+
const response = await transport(httpRequest.output);
|
|
652
|
+
return {
|
|
653
|
+
status: "PASS",
|
|
654
|
+
output: {
|
|
655
|
+
request: httpRequest.output,
|
|
656
|
+
response,
|
|
657
|
+
},
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// verifyUrlForProof is a pure string concatenation helper: given a base URL and
|
|
662
|
+
// a proof_id returned by the engine, it composes the read-only proof read URL.
|
|
663
|
+
// It computes no truth and performs no I/O.
|
|
664
|
+
export function verifyUrlForProof(base, proof_id) {
|
|
665
|
+
const baseUrl = String(base).replace(/\/+$/, "");
|
|
666
|
+
return `${baseUrl}${PROOF_EXPORT_ENDPOINT_PREFIX}/${proof_id}`;
|
|
667
|
+
}
|