@aithos/sdk 0.1.0-alpha.21 → 0.1.0-alpha.24

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.
@@ -0,0 +1,279 @@
1
+ import type { AithosAuth } from "./auth.js";
2
+ import { type AithosSdkEndpoints } from "./endpoints.js";
3
+ /** Opt-in scope a mandate must carry to invoke `aithos.web_extract`. */
4
+ export declare const WEB_EXTRACT_SCOPE: "web.extract";
5
+ export interface ExtractArgs {
6
+ /**
7
+ * Mandate ID under which this call should be attributed.
8
+ *
9
+ * - **Owner sessions**: optional. The SDK uses the owner's own DID
10
+ * as a sentinel "self" mandate id — the proxy skips mandate checks
11
+ * when the envelope is owner-signed.
12
+ * - **Delegate sessions**: required. Must reference the imported
13
+ * mandate bundle the SDK signs with; the proxy enforces the
14
+ * `web.extract` scope.
15
+ */
16
+ readonly mandateId?: string;
17
+ /** Absolute http(s) URL to extract. */
18
+ readonly url: string;
19
+ /**
20
+ * Playwright `waitUntil` strategy passed straight through to the
21
+ * server-side navigation. Defaults to `"networkidle"` server-side
22
+ * if omitted.
23
+ */
24
+ readonly waitUntil?: "load" | "domcontentloaded" | "networkidle";
25
+ /** Navigation timeout in ms. Server validates [1000, 60000]. */
26
+ readonly timeoutMs?: number;
27
+ /** Reserved for audit-level deduplication; the proxy currently does not
28
+ * enforce idempotency keys for extractions. */
29
+ readonly idempotencyKey?: string;
30
+ /** Abort signal to cancel the request. */
31
+ readonly signal?: AbortSignal;
32
+ }
33
+ export interface ExtractMeta {
34
+ readonly title: string | null;
35
+ readonly description: string | null;
36
+ readonly lang: string | null;
37
+ readonly charset: string | null;
38
+ readonly viewport: string | null;
39
+ readonly canonical: string | null;
40
+ readonly og: Readonly<Record<string, string>>;
41
+ }
42
+ export interface ExtractHeading {
43
+ readonly level: 1 | 2 | 3 | 4 | 5 | 6;
44
+ readonly text: string;
45
+ readonly id: string | null;
46
+ }
47
+ export interface ExtractSection {
48
+ readonly tag: string;
49
+ readonly role: string | null;
50
+ readonly html: string;
51
+ readonly text_len: number;
52
+ }
53
+ export interface ExtractLink {
54
+ readonly label: string;
55
+ readonly href: string;
56
+ readonly internal: boolean;
57
+ }
58
+ export interface ExtractImage {
59
+ readonly src: string;
60
+ readonly alt: string | null;
61
+ readonly role: string | null;
62
+ }
63
+ export interface ExtractFormField {
64
+ readonly type: string;
65
+ readonly name: string | null;
66
+ readonly required: boolean;
67
+ }
68
+ export interface ExtractForm {
69
+ readonly action: string | null;
70
+ readonly method: string;
71
+ readonly fields: readonly ExtractFormField[];
72
+ }
73
+ export interface ExtractStructure {
74
+ readonly headings: readonly ExtractHeading[];
75
+ readonly sections: readonly ExtractSection[];
76
+ readonly nav_links: readonly ExtractLink[];
77
+ readonly forms: readonly ExtractForm[];
78
+ }
79
+ export interface ExtractContent {
80
+ readonly main_html: string;
81
+ readonly main_text: string;
82
+ readonly images: readonly ExtractImage[];
83
+ readonly links: {
84
+ readonly internal: readonly ExtractLink[];
85
+ readonly external: readonly ExtractLink[];
86
+ };
87
+ }
88
+ export interface ExtractStyles {
89
+ readonly css: string;
90
+ readonly inline_styles_count: number;
91
+ }
92
+ export interface PaletteEntry {
93
+ readonly hex: string;
94
+ readonly weight: number;
95
+ readonly role: "background" | "text" | "accent" | "other";
96
+ }
97
+ export interface ComponentStyle {
98
+ readonly count: number;
99
+ readonly bg: string | null;
100
+ readonly fg: string | null;
101
+ readonly border: string | null;
102
+ readonly radius: string | null;
103
+ readonly padding: string | null;
104
+ readonly font_size: string | null;
105
+ readonly font_weight: string | null;
106
+ }
107
+ export interface VisualSignature {
108
+ readonly colors: {
109
+ readonly palette: readonly PaletteEntry[];
110
+ readonly background: string | null;
111
+ readonly text: string | null;
112
+ readonly primary: string | null;
113
+ readonly link: string | null;
114
+ };
115
+ readonly typography: {
116
+ readonly heading_font: string | null;
117
+ readonly body_font: string | null;
118
+ readonly size_scale: readonly number[];
119
+ readonly base_size_px: number | null;
120
+ readonly base_line_height: number | null;
121
+ };
122
+ readonly radii: {
123
+ readonly button: string | null;
124
+ readonly input: string | null;
125
+ readonly card: string | null;
126
+ };
127
+ readonly spacing: {
128
+ readonly base_unit_px: number | null;
129
+ readonly common_gaps_px: readonly number[];
130
+ };
131
+ readonly layout: {
132
+ readonly max_content_width_px: number | null;
133
+ readonly mode: "flex" | "grid" | "block" | null;
134
+ };
135
+ readonly components: {
136
+ readonly buttons: readonly ComponentStyle[];
137
+ readonly inputs: readonly ComponentStyle[];
138
+ readonly cards: readonly ComponentStyle[];
139
+ };
140
+ }
141
+ export interface ExtractIconDeclaration {
142
+ /** href as written in the HTML (relative or absolute). */
143
+ readonly href: string;
144
+ /** rel value, lowercased: "icon", "apple-touch-icon", "shortcut icon", ... */
145
+ readonly rel: string;
146
+ /** Declared `sizes` attribute, e.g. "180x180" or "any" or null. */
147
+ readonly sizes: string | null;
148
+ /** Declared mime type, e.g. "image/svg+xml" or null. */
149
+ readonly type: string | null;
150
+ }
151
+ /**
152
+ * Logo asset resolved server-side. The Lambda picks the best
153
+ * symbol-only asset available on the page — declared <link rel="icon"|
154
+ * "apple-touch-icon"> declarations + conventional well-known paths
155
+ * (/apple-touch-icon.png, /favicon.svg, /favicon.ico) — in that
156
+ * order of expected quality. Null when nothing resolves.
157
+ *
158
+ * Favicons are symbol-only by construction (no designer ships a
159
+ * wordmark inside a 16-180 px icon), which sidesteps the
160
+ * lockup-vs-symbol problem callers used to handle client-side with
161
+ * a vision model.
162
+ */
163
+ export interface ExtractLogo {
164
+ /** Absolute URL of the asset that was successfully fetched. */
165
+ readonly url: string;
166
+ /** Which source produced the winner. */
167
+ readonly source: "link-icon-svg" | "link-apple-touch-icon" | "link-icon-large" | "link-icon" | "link-shortcut-icon" | "well-known-apple-180" | "well-known-apple" | "well-known-svg" | "well-known-png-large" | "well-known-ico";
168
+ readonly content_type: string;
169
+ readonly size_bytes: number;
170
+ /** Base64-encoded asset bytes (no `data:` prefix). Build a data
171
+ * URI with `data:${content_type};base64,${base64}`. */
172
+ readonly base64: string;
173
+ }
174
+ export interface ExtractData {
175
+ readonly url: string;
176
+ readonly final_url: string;
177
+ readonly fetched_at: string;
178
+ readonly render_ms: number;
179
+ readonly meta: ExtractMeta;
180
+ readonly structure: ExtractStructure;
181
+ readonly content: ExtractContent;
182
+ readonly styles: ExtractStyles;
183
+ readonly visual_signature: VisualSignature;
184
+ /**
185
+ * Best logo asset resolved by the lambda — null when no
186
+ * <link rel="icon"> declaration and no conventional favicon
187
+ * path produced a usable image. Callers should then let the
188
+ * operator upload the logo manually rather than treat this as
189
+ * a fatal error.
190
+ */
191
+ readonly logo: ExtractLogo | null;
192
+ }
193
+ export interface ExtractResult {
194
+ /** Cleaned extraction payload. */
195
+ readonly data: ExtractData;
196
+ /** Microcredits charged for this call (1 on success, 0 on refunded failures). */
197
+ readonly creditsCharged: number;
198
+ /** Wallet balance after the (possibly refunded) debit. */
199
+ readonly walletBalance: number;
200
+ /** Audit log id for traceability. */
201
+ readonly auditId: string;
202
+ }
203
+ export interface FetchAssetArgs {
204
+ /** Absolute http(s) URL of the asset to fetch. */
205
+ readonly url: string;
206
+ /** Mandate id under which this call should be attributed. */
207
+ readonly mandateId?: string;
208
+ /** Abort signal. */
209
+ readonly signal?: AbortSignal;
210
+ }
211
+ export interface FetchAssetResult {
212
+ /** Asset payload. */
213
+ readonly data: {
214
+ /** URL we asked the proxy to fetch. */
215
+ readonly url: string;
216
+ /** URL after the proxy followed any redirects. */
217
+ readonly final_url: string;
218
+ /** Content-Type reported by the upstream server. */
219
+ readonly content_type: string;
220
+ /** Size of the fetched body in bytes. */
221
+ readonly size_bytes: number;
222
+ /** Base64-encoded body (no `data:` prefix). Build a data URI
223
+ * with `data:${content_type};base64,${base64}`. */
224
+ readonly base64: string;
225
+ };
226
+ /** Microcredits charged for this call. */
227
+ readonly creditsCharged: number;
228
+ readonly walletBalance: number;
229
+ readonly auditId: string;
230
+ }
231
+ export interface WebNamespaceDeps {
232
+ readonly auth: AithosAuth;
233
+ readonly appDid: string;
234
+ readonly endpoints: AithosSdkEndpoints;
235
+ readonly fetch: typeof fetch;
236
+ }
237
+ /**
238
+ * `sdk.web` namespace — Aithos's web extraction primitive.
239
+ *
240
+ * Designed so a downstream agent can read the static content of any
241
+ * public page (HTML, purged CSS, computed visual signature) without
242
+ * involving an LLM — saving ~30× over a Bedrock-based extraction in
243
+ * both latency and cost.
244
+ *
245
+ * @throws {AithosSDKError} — same error taxonomy as `sdk.compute`,
246
+ * including `-32071` (insufficient balance with `{required, available}`
247
+ * in `data`) and `-32042` (mandate scope mismatch).
248
+ */
249
+ export declare class WebNamespace {
250
+ #private;
251
+ constructor(deps: WebNamespaceDeps);
252
+ /**
253
+ * Extract a public webpage. Returns the cleaned HTML, purged CSS and
254
+ * a deterministic visual signature (palette, typography, dominant
255
+ * radii, spacing, layout mode, component digests).
256
+ */
257
+ extract(args: ExtractArgs): Promise<ExtractResult>;
258
+ /**
259
+ * Fetch a single asset (image / font / css / json …) server-side,
260
+ * bypassing browser CORS. Returns the bytes as base64 + content-type.
261
+ *
262
+ * Use when `fetch(url, {mode: "cors"})` and `<img crossOrigin>`
263
+ * canvas readback both fail because the asset server doesn't return
264
+ * Access-Control-Allow-Origin headers — typical for production
265
+ * sites' logos hosted on the main domain.
266
+ *
267
+ * For the common "logo of a webpage" case the lambda already
268
+ * resolves and embeds the best symbol-only logo in
269
+ * {@link extract}'s `data.logo` field; you only need fetchAsset
270
+ * when extract's logo doesn't fit, when picking up secondary
271
+ * assets (og:image, hero image, document download), or when
272
+ * fetching an asset on a page you haven't extracted.
273
+ *
274
+ * Costs 1 mc per successful fetch, full refund on failure. Server
275
+ * caps: 15 s timeout, 10 MB body, http/https only.
276
+ */
277
+ fetchAsset(args: FetchAssetArgs): Promise<FetchAssetResult>;
278
+ }
279
+ //# sourceMappingURL=web.d.ts.map
@@ -0,0 +1,186 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright 2026 Mathieu Colla
3
+ // Web namespace — `aithos.web_extract` through the web-extractor proxy.
4
+ //
5
+ // Same JSON-RPC + signed-envelope protocol as the compute namespace, but
6
+ // against a separate Aithos service (`extract.aithos.be`). Pricing is a
7
+ // flat 1 microcredit per successful extraction (refunded on failure).
8
+ //
9
+ // The mandate scope is `web.extract` (exported as {@link WEB_EXTRACT_SCOPE}
10
+ // for owner mint-time use). A delegate that holds only this scope can read
11
+ // pages on the owner's behalf without gaining LLM-spend authority.
12
+ //
13
+ // Signing follows the same owner-vs-delegate logic as the compute namespace
14
+ // (see ComputeNamespace.#resolveSigner). The duplication is bounded — both
15
+ // namespaces' `#signAndPost` helpers can later move into a shared internal
16
+ // once a third primitive arrives.
17
+ import { buildSignedEnvelope, } from "@aithos/protocol-client";
18
+ import { webInvokeUrl, } from "./endpoints.js";
19
+ import { delegateKeyPair, ownerKeyPair, } from "./internal/protocol-client-bridge.js";
20
+ import { AithosSDKError } from "./types.js";
21
+ /** Opt-in scope a mandate must carry to invoke `aithos.web_extract`. */
22
+ export const WEB_EXTRACT_SCOPE = "web.extract";
23
+ /**
24
+ * `sdk.web` namespace — Aithos's web extraction primitive.
25
+ *
26
+ * Designed so a downstream agent can read the static content of any
27
+ * public page (HTML, purged CSS, computed visual signature) without
28
+ * involving an LLM — saving ~30× over a Bedrock-based extraction in
29
+ * both latency and cost.
30
+ *
31
+ * @throws {AithosSDKError} — same error taxonomy as `sdk.compute`,
32
+ * including `-32071` (insufficient balance with `{required, available}`
33
+ * in `data`) and `-32042` (mandate scope mismatch).
34
+ */
35
+ export class WebNamespace {
36
+ #deps;
37
+ constructor(deps) {
38
+ this.#deps = deps;
39
+ }
40
+ /**
41
+ * Extract a public webpage. Returns the cleaned HTML, purged CSS and
42
+ * a deterministic visual signature (palette, typography, dominant
43
+ * radii, spacing, layout mode, component digests).
44
+ */
45
+ async extract(args) {
46
+ const { endpoints, fetch: fetchImpl } = this.#deps;
47
+ const choice = this.#resolveSigner(args.mandateId);
48
+ const url = webInvokeUrl(endpoints);
49
+ const params = {
50
+ app_did: this.#deps.appDid,
51
+ mandate_id: this.#resolveMandateIdForWire(args.mandateId, choice),
52
+ url: args.url,
53
+ };
54
+ if (args.waitUntil !== undefined)
55
+ params.waitUntil = args.waitUntil;
56
+ if (args.timeoutMs !== undefined)
57
+ params.timeoutMs = args.timeoutMs;
58
+ if (args.idempotencyKey !== undefined) {
59
+ params.idempotencyKey = args.idempotencyKey;
60
+ }
61
+ return await this.#signAndPost({
62
+ url,
63
+ method: "aithos.web_extract",
64
+ params,
65
+ choice,
66
+ fetchImpl,
67
+ signal: args.signal,
68
+ });
69
+ }
70
+ /**
71
+ * Fetch a single asset (image / font / css / json …) server-side,
72
+ * bypassing browser CORS. Returns the bytes as base64 + content-type.
73
+ *
74
+ * Use when `fetch(url, {mode: "cors"})` and `<img crossOrigin>`
75
+ * canvas readback both fail because the asset server doesn't return
76
+ * Access-Control-Allow-Origin headers — typical for production
77
+ * sites' logos hosted on the main domain.
78
+ *
79
+ * For the common "logo of a webpage" case the lambda already
80
+ * resolves and embeds the best symbol-only logo in
81
+ * {@link extract}'s `data.logo` field; you only need fetchAsset
82
+ * when extract's logo doesn't fit, when picking up secondary
83
+ * assets (og:image, hero image, document download), or when
84
+ * fetching an asset on a page you haven't extracted.
85
+ *
86
+ * Costs 1 mc per successful fetch, full refund on failure. Server
87
+ * caps: 15 s timeout, 10 MB body, http/https only.
88
+ */
89
+ async fetchAsset(args) {
90
+ const { endpoints, fetch: fetchImpl } = this.#deps;
91
+ const choice = this.#resolveSigner(args.mandateId);
92
+ const url = webInvokeUrl(endpoints);
93
+ const params = {
94
+ app_did: this.#deps.appDid,
95
+ mandate_id: this.#resolveMandateIdForWire(args.mandateId, choice),
96
+ url: args.url,
97
+ };
98
+ return await this.#signAndPost({
99
+ url,
100
+ method: "aithos.web_fetch_asset",
101
+ params,
102
+ choice,
103
+ fetchImpl,
104
+ signal: args.signal,
105
+ });
106
+ }
107
+ /* ----------------------------- internals ----------------------------- */
108
+ #resolveSigner(mandateId) {
109
+ const { auth } = this.#deps;
110
+ const owner = auth._getOwnerSigners();
111
+ const ownerLoaded = owner !== null && !owner.destroyed;
112
+ if (ownerLoaded) {
113
+ const publicKp = ownerKeyPair(owner, "public");
114
+ return {
115
+ kind: "owner",
116
+ iss: owner.did,
117
+ verificationMethod: `${owner.did}#public`,
118
+ signer: publicKp,
119
+ mandate: undefined,
120
+ };
121
+ }
122
+ if (mandateId === undefined || mandateId.length === 0) {
123
+ throw new AithosSDKError("sdk_no_signer", "no owner signed in and no mandateId provided — pass a mandateId for a delegate session, or sign in as an owner first.");
124
+ }
125
+ const actor = auth._getDelegateActor(mandateId);
126
+ if (!actor || actor.destroyed) {
127
+ throw new AithosSDKError("sdk_no_delegate_for_mandate", `no owner signed in and no imported delegate mandate matches '${mandateId}'. Sign in as an owner, or import a delegate bundle for that mandate via auth.importMandate.`);
128
+ }
129
+ const kp = delegateKeyPair(actor);
130
+ return {
131
+ kind: "delegate",
132
+ iss: actor.subjectDid,
133
+ verificationMethod: actor.granteePubkeyMultibase,
134
+ signer: kp,
135
+ mandate: actor.mandate,
136
+ };
137
+ }
138
+ #resolveMandateIdForWire(explicit, choice) {
139
+ if (explicit && explicit.length > 0)
140
+ return explicit;
141
+ if (choice.kind === "delegate")
142
+ return choice.mandate.id;
143
+ return `${choice.iss}#self`;
144
+ }
145
+ async #signAndPost(opts) {
146
+ const { url, method, params, choice, fetchImpl, signal } = opts;
147
+ const envelope = buildSignedEnvelope({
148
+ iss: choice.iss,
149
+ aud: url,
150
+ method,
151
+ verificationMethod: choice.verificationMethod,
152
+ params,
153
+ signer: choice.signer,
154
+ ...(choice.kind === "delegate" ? { mandate: choice.mandate } : {}),
155
+ });
156
+ let res;
157
+ try {
158
+ res = await fetchImpl(url, {
159
+ method: "POST",
160
+ headers: { "content-type": "application/json" },
161
+ body: JSON.stringify({
162
+ jsonrpc: "2.0",
163
+ id: method,
164
+ method,
165
+ params: { ...params, _envelope: envelope },
166
+ }),
167
+ ...(signal ? { signal } : {}),
168
+ });
169
+ }
170
+ catch (e) {
171
+ throw new AithosSDKError("network", e.message);
172
+ }
173
+ if (!res.ok) {
174
+ throw new AithosSDKError("http", `HTTP ${res.status} ${res.statusText}`, { status: res.status });
175
+ }
176
+ const body = (await res.json());
177
+ if (body.error) {
178
+ throw new AithosSDKError(String(body.error.code), body.error.message, body.error.data ? { data: body.error.data } : undefined);
179
+ }
180
+ if (!body.result) {
181
+ throw new AithosSDKError("empty", "empty result from web extractor proxy");
182
+ }
183
+ return body.result;
184
+ }
185
+ }
186
+ //# sourceMappingURL=web.js.map
@@ -187,166 +187,8 @@ describe("compute.invokeBedrock — abort", () => {
187
187
  assert.equal(receivedSignal, ac.signal);
188
188
  });
189
189
  });
190
- /* -------------------------------------------------------------------------- */
191
- /* invokeUrlFetch */
192
- /* -------------------------------------------------------------------------- */
193
- const URL_FETCH_HAPPY_RESULT = {
194
- content: "Tata.com propose un service Y avec une couleur primaire bleu (#1E40AF).",
195
- citations: [
196
- {
197
- url: "https://tata.com",
198
- citedText: "Notre service révolutionne...",
199
- documentTitle: "Tata — Home",
200
- startCharIndex: 0,
201
- endCharIndex: 28,
202
- },
203
- ],
204
- urlsFetched: [
205
- {
206
- url: "https://tata.com",
207
- retrievedAt: "2026-05-12T10:00:00Z",
208
- title: "Tata — Home",
209
- },
210
- ],
211
- stopReason: "end_turn",
212
- usage: { inputTokens: 28_500, outputTokens: 420, webFetchInvocations: 1 },
213
- creditsCharged: 35,
214
- walletBalance: 99_965,
215
- auditId: "audit-url-1",
216
- };
217
- describe("compute.invokeUrlFetch — happy path", () => {
218
- it("posts to ${compute}/v1/invoke with method=aithos.compute_invoke_url_fetch", async () => {
219
- let capturedUrl;
220
- let capturedInit;
221
- const fakeFetch = async (input, init) => {
222
- capturedUrl = typeof input === "string" ? input : input.toString();
223
- capturedInit = init;
224
- return new Response(JSON.stringify({ result: URL_FETCH_HAPPY_RESULT }), {
225
- status: 200,
226
- headers: { "content-type": "application/json" },
227
- });
228
- };
229
- const sdk = await makeSdk(fakeFetch);
230
- const out = await sdk.compute.invokeUrlFetch({
231
- mandateId: "mandate:abc",
232
- prompt: "Voici l'URL https://tata.com — résume.",
233
- });
234
- assert.deepEqual(out, URL_FETCH_HAPPY_RESULT);
235
- assert.equal(capturedUrl, "https://compute.example.test/v1/invoke");
236
- const body = JSON.parse(capturedInit?.body);
237
- assert.equal(body.jsonrpc, "2.0");
238
- assert.equal(body.method, "aithos.compute_invoke_url_fetch");
239
- assert.equal(body.params.app_did, APP_DID);
240
- assert.equal(body.params.mandate_id, "mandate:abc");
241
- // Default model is Haiku 4.5 (cheapest model that supports web_fetch).
242
- assert.equal(body.params.model, "claude-haiku-4-5");
243
- assert.equal(body.params.prompt, "Voici l'URL https://tata.com — résume.");
244
- // Auto-generated idempotency key.
245
- assert.match(body.params.idempotency_key, /^[0-9a-f]{32}$/);
246
- // Envelope is present on the wire.
247
- assert.ok(body.params._envelope, "request must carry a signed envelope");
248
- // Optional params NOT forwarded when not provided.
249
- assert.equal(body.params.system, undefined);
250
- assert.equal(body.params.max_fetches, undefined);
251
- assert.equal(body.params.max_content_tokens, undefined);
252
- assert.equal(body.params.citations, undefined);
253
- assert.equal(body.params.allowed_domains, undefined);
254
- assert.equal(body.params.blocked_domains, undefined);
255
- });
256
- it("forwards all optional knobs: system / maxTokens / maxFetches / maxContentTokens / citations / allowedDomains / idempotencyKey / model", async () => {
257
- let capturedBody;
258
- const fakeFetch = async (_input, init) => {
259
- capturedBody = JSON.parse(init?.body).params;
260
- return new Response(JSON.stringify({ result: URL_FETCH_HAPPY_RESULT }), {
261
- status: 200,
262
- headers: { "content-type": "application/json" },
263
- });
264
- };
265
- const sdk = await makeSdk(fakeFetch);
266
- await sdk.compute.invokeUrlFetch({
267
- mandateId: "mandate:abc",
268
- model: "claude-sonnet-4-6",
269
- prompt: "Analyse https://tata.com",
270
- system: "You are a brand analyst.",
271
- maxTokens: 1024,
272
- temperature: 0.1,
273
- maxFetches: 3,
274
- maxContentTokens: 50_000,
275
- citations: false,
276
- allowedDomains: ["tata.com", "*.tata.com"],
277
- idempotencyKey: "idem-url-1",
278
- });
279
- assert.equal(capturedBody?.model, "claude-sonnet-4-6");
280
- assert.equal(capturedBody?.system, "You are a brand analyst.");
281
- assert.equal(capturedBody?.max_tokens, 1024);
282
- assert.equal(capturedBody?.temperature, 0.1);
283
- assert.equal(capturedBody?.max_fetches, 3);
284
- assert.equal(capturedBody?.max_content_tokens, 50_000);
285
- assert.equal(capturedBody?.citations, false);
286
- assert.deepEqual(capturedBody?.allowed_domains, ["tata.com", "*.tata.com"]);
287
- assert.equal(capturedBody?.idempotency_key, "idem-url-1");
288
- // Empty / undefined arrays must NOT bleed through as `[]` on the wire.
289
- assert.equal(capturedBody?.blocked_domains, undefined);
290
- });
291
- it("omits empty allowedDomains / blockedDomains arrays from the wire payload", async () => {
292
- let capturedBody;
293
- const fakeFetch = async (_input, init) => {
294
- capturedBody = JSON.parse(init?.body).params;
295
- return new Response(JSON.stringify({ result: URL_FETCH_HAPPY_RESULT }), {
296
- status: 200,
297
- headers: { "content-type": "application/json" },
298
- });
299
- };
300
- const sdk = await makeSdk(fakeFetch);
301
- await sdk.compute.invokeUrlFetch({
302
- mandateId: "mandate:abc",
303
- prompt: "Analyse https://tata.com",
304
- allowedDomains: [],
305
- blockedDomains: [],
306
- });
307
- assert.equal(capturedBody?.allowed_domains, undefined);
308
- assert.equal(capturedBody?.blocked_domains, undefined);
309
- });
310
- });
311
- describe("compute.invokeUrlFetch — errors", () => {
312
- it("wraps a JSON-RPC error from the proxy as AithosSDKError with the proxy code", async () => {
313
- const fakeFetch = async () => new Response(JSON.stringify({
314
- error: {
315
- code: -32074,
316
- message: "web_fetch failed: robots.txt disallows /api/* — fetch refused",
317
- data: { detail: "robots_blocked" },
318
- },
319
- }), { status: 200, headers: { "content-type": "application/json" } });
320
- const sdk = await makeSdk(fakeFetch);
321
- await assert.rejects(sdk.compute.invokeUrlFetch({
322
- mandateId: "mandate:abc",
323
- prompt: "Analyse https://tata.com/api/secret",
324
- }), (err) => {
325
- assert.ok(err instanceof AithosSDKError);
326
- assert.equal(err.code, "-32074");
327
- assert.match(err.message, /robots\.txt/);
328
- return true;
329
- });
330
- });
331
- });
332
- describe("compute.invokeUrlFetch — abort", () => {
333
- it("propagates an AbortSignal to fetch", async () => {
334
- let receivedSignal;
335
- const fakeFetch = async (_input, init) => {
336
- receivedSignal = init?.signal;
337
- return new Response(JSON.stringify({ result: URL_FETCH_HAPPY_RESULT }), {
338
- status: 200,
339
- headers: { "content-type": "application/json" },
340
- });
341
- };
342
- const sdk = await makeSdk(fakeFetch);
343
- const ac = new AbortController();
344
- await sdk.compute.invokeUrlFetch({
345
- mandateId: "mandate:abc",
346
- prompt: "Analyse https://tata.com",
347
- signal: ac.signal,
348
- });
349
- assert.equal(receivedSignal, ac.signal);
350
- });
351
- });
190
+ // `compute.invokeUrlFetch` was removed in alpha.24 (BREAKING). The
191
+ // Anthropic API-direct + web_fetch tool path is replaced by the
192
+ // `sdk.web.extract` namespace which routes through the deterministic
193
+ // web-extractor Lambda. No tests here anymore.
352
194
  //# sourceMappingURL=compute.test.js.map
@@ -4,7 +4,7 @@
4
4
  import { strict as assert } from "node:assert";
5
5
  import { describe, it } from "node:test";
6
6
  import { DEFAULT_SDK_ENDPOINTS } from "../src/index.js";
7
- import { computeInvokeUrl, resolveEndpoints, walletTopupCheckoutUrl, } from "../src/endpoints.js";
7
+ import { computeInvokeUrl, resolveEndpoints, walletTopupCheckoutUrl, webInvokeUrl, } from "../src/endpoints.js";
8
8
  describe("resolveEndpoints", () => {
9
9
  it("returns a fresh copy of the defaults when no override is given", () => {
10
10
  const a = resolveEndpoints();
@@ -23,12 +23,14 @@ describe("computeInvokeUrl", () => {
23
23
  assert.equal(computeInvokeUrl({
24
24
  compute: "https://compute.aithos.be",
25
25
  wallet: "https://wallet.aithos.be",
26
+ web: "https://extract.aithos.be",
26
27
  }), "https://compute.aithos.be/v1/invoke");
27
28
  });
28
29
  it("trims a trailing slash on the compute base", () => {
29
30
  assert.equal(computeInvokeUrl({
30
31
  compute: "https://compute.aithos.be/",
31
32
  wallet: "https://wallet.aithos.be",
33
+ web: "https://extract.aithos.be",
32
34
  }), "https://compute.aithos.be/v1/invoke");
33
35
  });
34
36
  });
@@ -37,7 +39,24 @@ describe("walletTopupCheckoutUrl", () => {
37
39
  assert.equal(walletTopupCheckoutUrl({
38
40
  compute: "https://compute.aithos.be",
39
41
  wallet: "https://wallet.aithos.be",
42
+ web: "https://extract.aithos.be",
40
43
  }), "https://wallet.aithos.be/v1/wallet/topup/checkout");
41
44
  });
42
45
  });
46
+ describe("webInvokeUrl", () => {
47
+ it("appends /v1/invoke to the web base", () => {
48
+ assert.equal(webInvokeUrl({
49
+ compute: "https://compute.aithos.be",
50
+ wallet: "https://wallet.aithos.be",
51
+ web: "https://extract.aithos.be",
52
+ }), "https://extract.aithos.be/v1/invoke");
53
+ });
54
+ it("trims a trailing slash on the web base", () => {
55
+ assert.equal(webInvokeUrl({
56
+ compute: "https://compute.aithos.be",
57
+ wallet: "https://wallet.aithos.be",
58
+ web: "https://extract.aithos.be/",
59
+ }), "https://extract.aithos.be/v1/invoke");
60
+ });
61
+ });
43
62
  //# sourceMappingURL=endpoints.test.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=web.test.d.ts.map