@aithos/sdk 0.1.0-alpha.39 → 0.1.0-alpha.40

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.
Files changed (45) hide show
  1. package/dist/src/assets.d.ts +207 -0
  2. package/dist/src/assets.js +533 -0
  3. package/dist/src/index.d.ts +1 -0
  4. package/dist/src/index.js +6 -0
  5. package/dist/src/react/AithosAsset.d.ts +66 -0
  6. package/dist/src/react/AithosAsset.js +67 -0
  7. package/dist/src/react/context.d.ts +29 -0
  8. package/dist/src/react/context.js +31 -0
  9. package/dist/src/react/index.d.ts +28 -0
  10. package/dist/src/react/index.js +30 -0
  11. package/dist/src/react/use-aithos-asset.d.ts +39 -0
  12. package/dist/src/react/use-aithos-asset.js +118 -0
  13. package/package.json +16 -2
  14. package/dist/test/auth-j3.test.d.ts +0 -2
  15. package/dist/test/auth-j3.test.js +0 -391
  16. package/dist/test/auth.test.d.ts +0 -2
  17. package/dist/test/auth.test.js +0 -175
  18. package/dist/test/compute-delegate-path.test.d.ts +0 -2
  19. package/dist/test/compute-delegate-path.test.js +0 -183
  20. package/dist/test/compute.test.d.ts +0 -2
  21. package/dist/test/compute.test.js +0 -194
  22. package/dist/test/endpoints.test.d.ts +0 -2
  23. package/dist/test/endpoints.test.js +0 -62
  24. package/dist/test/envelope.test.d.ts +0 -2
  25. package/dist/test/envelope.test.js +0 -318
  26. package/dist/test/ethos-first-edition.test.d.ts +0 -2
  27. package/dist/test/ethos-first-edition.test.js +0 -248
  28. package/dist/test/ethos.test.d.ts +0 -2
  29. package/dist/test/ethos.test.js +0 -219
  30. package/dist/test/key-store.test.d.ts +0 -2
  31. package/dist/test/key-store.test.js +0 -161
  32. package/dist/test/mandates-compute.test.d.ts +0 -2
  33. package/dist/test/mandates-compute.test.js +0 -256
  34. package/dist/test/mandates.test.d.ts +0 -2
  35. package/dist/test/mandates.test.js +0 -93
  36. package/dist/test/sdk.test.d.ts +0 -2
  37. package/dist/test/sdk.test.js +0 -126
  38. package/dist/test/signer.test.d.ts +0 -2
  39. package/dist/test/signer.test.js +0 -117
  40. package/dist/test/signup-bootstrap.test.d.ts +0 -2
  41. package/dist/test/signup-bootstrap.test.js +0 -311
  42. package/dist/test/wallet.test.d.ts +0 -2
  43. package/dist/test/wallet.test.js +0 -121
  44. package/dist/test/web.test.d.ts +0 -2
  45. package/dist/test/web.test.js +0 -270
@@ -0,0 +1,29 @@
1
+ /**
2
+ * React context for the Aithos assets client.
3
+ *
4
+ * App roots wrap their tree with `<AssetsClientProvider client={sdk.assets}>`
5
+ * once, then child components use `<AithosAsset urn="..." />` (or the
6
+ * `useAithosAsset` hook) without having to thread the client through
7
+ * props.
8
+ */
9
+ import { type ReactNode } from "react";
10
+ import type { AssetsClient } from "../assets.js";
11
+ export interface AssetsClientProviderProps {
12
+ /** The SDK's assets client — typically `sdk.assets`. */
13
+ readonly client: AssetsClient;
14
+ readonly children?: ReactNode;
15
+ }
16
+ /**
17
+ * Provider that exposes an {@link AssetsClient} to descendants.
18
+ *
19
+ * Typical placement: as high in the React tree as the authenticated
20
+ * session lives (e.g. inside the auth boundary).
21
+ */
22
+ export declare function AssetsClientProvider(props: AssetsClientProviderProps): any;
23
+ /**
24
+ * Return the {@link AssetsClient} from the nearest provider, or `null`
25
+ * if no provider is present. Components SHOULD accept an override via
26
+ * an explicit `client` prop and fall back to this hook when omitted.
27
+ */
28
+ export declare function useAssetsClient(): AssetsClient | null;
29
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Copyright 2026 Mathieu Colla
4
+ /**
5
+ * React context for the Aithos assets client.
6
+ *
7
+ * App roots wrap their tree with `<AssetsClientProvider client={sdk.assets}>`
8
+ * once, then child components use `<AithosAsset urn="..." />` (or the
9
+ * `useAithosAsset` hook) without having to thread the client through
10
+ * props.
11
+ */
12
+ import { createContext, useContext } from "react";
13
+ const AssetsClientContext = createContext(null);
14
+ /**
15
+ * Provider that exposes an {@link AssetsClient} to descendants.
16
+ *
17
+ * Typical placement: as high in the React tree as the authenticated
18
+ * session lives (e.g. inside the auth boundary).
19
+ */
20
+ export function AssetsClientProvider(props) {
21
+ return (_jsx(AssetsClientContext.Provider, { value: props.client, children: props.children }));
22
+ }
23
+ /**
24
+ * Return the {@link AssetsClient} from the nearest provider, or `null`
25
+ * if no provider is present. Components SHOULD accept an override via
26
+ * an explicit `client` prop and fall back to this hook when omitted.
27
+ */
28
+ export function useAssetsClient() {
29
+ return useContext(AssetsClientContext);
30
+ }
31
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `@aithos/sdk/react` — React bindings for the Aithos SDK.
3
+ *
4
+ * Drop-in components and hooks for displaying Aithos-hosted assets in
5
+ * React applications. The package's only peer dependency beyond
6
+ * `@aithos/sdk` itself is `react` (^18 || ^19).
7
+ *
8
+ * Quick start:
9
+ *
10
+ * // 1. Wrap your tree once
11
+ * <AssetsClientProvider client={sdk.assets}>
12
+ * <App />
13
+ * </AssetsClientProvider>
14
+ *
15
+ * // 2. Use anywhere
16
+ * <AithosAsset urn={cv.urn} alt="CV" className="w-full" />
17
+ * <AithosAsset urn={video.urn} as="video" controls />
18
+ * <AithosAsset urn={pdf.urn} as="download" filename="cv.pdf">
19
+ * Download my CV
20
+ * </AithosAsset>
21
+ *
22
+ * // 3. Or use the hook directly for custom rendering
23
+ * const { url, bytes, loading, error } = useAithosAsset(urn);
24
+ */
25
+ export { AssetsClientProvider, useAssetsClient, type AssetsClientProviderProps, } from "./context.js";
26
+ export { useAithosAsset, type UseAithosAssetState, type UseAithosAssetOptions, } from "./use-aithos-asset.js";
27
+ export { AithosAsset, type AithosAssetProps, type AithosImageProps, type AithosVideoProps, type AithosAudioProps, type AithosDownloadProps, } from "./AithosAsset.js";
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright 2026 Mathieu Colla
3
+ /**
4
+ * `@aithos/sdk/react` — React bindings for the Aithos SDK.
5
+ *
6
+ * Drop-in components and hooks for displaying Aithos-hosted assets in
7
+ * React applications. The package's only peer dependency beyond
8
+ * `@aithos/sdk` itself is `react` (^18 || ^19).
9
+ *
10
+ * Quick start:
11
+ *
12
+ * // 1. Wrap your tree once
13
+ * <AssetsClientProvider client={sdk.assets}>
14
+ * <App />
15
+ * </AssetsClientProvider>
16
+ *
17
+ * // 2. Use anywhere
18
+ * <AithosAsset urn={cv.urn} alt="CV" className="w-full" />
19
+ * <AithosAsset urn={video.urn} as="video" controls />
20
+ * <AithosAsset urn={pdf.urn} as="download" filename="cv.pdf">
21
+ * Download my CV
22
+ * </AithosAsset>
23
+ *
24
+ * // 3. Or use the hook directly for custom rendering
25
+ * const { url, bytes, loading, error } = useAithosAsset(urn);
26
+ */
27
+ export { AssetsClientProvider, useAssetsClient, } from "./context.js";
28
+ export { useAithosAsset, } from "./use-aithos-asset.js";
29
+ export { AithosAsset, } from "./AithosAsset.js";
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,39 @@
1
+ import type { AssetsClient } from "../assets.js";
2
+ export interface UseAithosAssetState {
3
+ /** A `blob:` URL pointing at the decrypted plaintext. Use in <img src=…> etc. */
4
+ readonly url: string | null;
5
+ /** Raw decrypted bytes. Use when you need the binary itself (e.g. PDF viewer). */
6
+ readonly bytes: Uint8Array | null;
7
+ /** IANA media type — useful for routing rendering. */
8
+ readonly mediaType: string | null;
9
+ /** Plaintext size in bytes. */
10
+ readonly sizeBytes: number | null;
11
+ /** True while the fetch+decrypt is in flight. */
12
+ readonly loading: boolean;
13
+ /** Non-null when the fetch/decrypt failed. */
14
+ readonly error: Error | null;
15
+ }
16
+ export interface UseAithosAssetOptions {
17
+ /** Override the client from context. Useful for tests. */
18
+ readonly client?: AssetsClient | null;
19
+ /**
20
+ * If `true`, the hook keeps the previous blob URL visible while a
21
+ * new URN is being fetched, instead of flashing `null`. Default
22
+ * `false` (more predictable, less visual stutter avoidance).
23
+ */
24
+ readonly keepPreviousOnUrnChange?: boolean;
25
+ }
26
+ /**
27
+ * Fetch + decrypt an Aithos asset and return a stable `blob:` URL.
28
+ *
29
+ * Lifecycle:
30
+ * - On mount or when `urn` changes, runs `client.fetch(urn)`.
31
+ * - On success, creates an object URL from the plaintext bytes.
32
+ * - On unmount or before refetching, revokes the URL to free memory.
33
+ * - Cancels in-flight fetches if the URN changes mid-flight.
34
+ *
35
+ * Throws (via `error`) when no client is available — supply one via
36
+ * `<AssetsClientProvider>` or the `client` option.
37
+ */
38
+ export declare function useAithosAsset(urn: string | null | undefined, options?: UseAithosAssetOptions): UseAithosAssetState;
39
+ //# sourceMappingURL=use-aithos-asset.d.ts.map
@@ -0,0 +1,118 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright 2026 Mathieu Colla
3
+ /**
4
+ * `useAithosAsset(urn)` — React hook that fetches an asset and exposes
5
+ * it as a browser-consumable `blob:` URL, with full lifecycle
6
+ * management (revoke on unmount, race-cancel on URN change, error
7
+ * surfacing).
8
+ *
9
+ * For most UIs the higher-level `<AithosAsset>` component is enough.
10
+ * Reach for this hook directly when you want to feed the bytes or the
11
+ * blob URL to a non-`<img>`/`<video>`/`<audio>` consumer — e.g. an
12
+ * inline CSS `background-image`, a Canvas, a custom PDF viewer.
13
+ */
14
+ import { useEffect, useState } from "react";
15
+ import { useAssetsClient } from "./context.js";
16
+ /**
17
+ * Fetch + decrypt an Aithos asset and return a stable `blob:` URL.
18
+ *
19
+ * Lifecycle:
20
+ * - On mount or when `urn` changes, runs `client.fetch(urn)`.
21
+ * - On success, creates an object URL from the plaintext bytes.
22
+ * - On unmount or before refetching, revokes the URL to free memory.
23
+ * - Cancels in-flight fetches if the URN changes mid-flight.
24
+ *
25
+ * Throws (via `error`) when no client is available — supply one via
26
+ * `<AssetsClientProvider>` or the `client` option.
27
+ */
28
+ export function useAithosAsset(urn, options = {}) {
29
+ const contextClient = useAssetsClient();
30
+ const client = options.client ?? contextClient;
31
+ const [state, setState] = useState({
32
+ url: null,
33
+ bytes: null,
34
+ mediaType: null,
35
+ sizeBytes: null,
36
+ loading: !!urn,
37
+ error: null,
38
+ });
39
+ useEffect(() => {
40
+ if (!urn) {
41
+ setState({
42
+ url: null,
43
+ bytes: null,
44
+ mediaType: null,
45
+ sizeBytes: null,
46
+ loading: false,
47
+ error: null,
48
+ });
49
+ return;
50
+ }
51
+ if (!client) {
52
+ setState({
53
+ url: null,
54
+ bytes: null,
55
+ mediaType: null,
56
+ sizeBytes: null,
57
+ loading: false,
58
+ error: new Error("useAithosAsset: no AssetsClient available — wrap your tree with <AssetsClientProvider> or pass the `client` option"),
59
+ });
60
+ return;
61
+ }
62
+ let cancelled = false;
63
+ let createdUrl = null;
64
+ setState((prev) => options.keepPreviousOnUrnChange
65
+ ? { ...prev, loading: true, error: null }
66
+ : {
67
+ url: null,
68
+ bytes: null,
69
+ mediaType: null,
70
+ sizeBytes: null,
71
+ loading: true,
72
+ error: null,
73
+ });
74
+ (async () => {
75
+ try {
76
+ const result = await client.fetch(urn);
77
+ if (cancelled)
78
+ return;
79
+ // Construct the blob: URL the DOM can consume.
80
+ // The `as BlobPart` cast is needed because @types/node and
81
+ // lib.dom disagree on whether Uint8Array's backing buffer is
82
+ // always ArrayBuffer (vs SharedArrayBuffer). The runtime
83
+ // accepts our Uint8Array unconditionally.
84
+ const blob = new Blob([result.bytes], {
85
+ type: result.mediaType,
86
+ });
87
+ createdUrl = URL.createObjectURL(blob);
88
+ setState({
89
+ url: createdUrl,
90
+ bytes: result.bytes,
91
+ mediaType: result.mediaType,
92
+ sizeBytes: result.sizeBytes,
93
+ loading: false,
94
+ error: null,
95
+ });
96
+ }
97
+ catch (e) {
98
+ if (cancelled)
99
+ return;
100
+ setState({
101
+ url: null,
102
+ bytes: null,
103
+ mediaType: null,
104
+ sizeBytes: null,
105
+ loading: false,
106
+ error: e instanceof Error ? e : new Error(String(e)),
107
+ });
108
+ }
109
+ })();
110
+ return () => {
111
+ cancelled = true;
112
+ if (createdUrl)
113
+ URL.revokeObjectURL(createdUrl);
114
+ };
115
+ }, [urn, client, options.keepPreviousOnUrnChange]);
116
+ return state;
117
+ }
118
+ //# sourceMappingURL=use-aithos-asset.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aithos/sdk",
3
- "version": "0.1.0-alpha.39",
3
+ "version": "0.1.0-alpha.40",
4
4
  "description": "Aithos SDK — high-level TypeScript developer kit for building agentic apps on the Aithos protocol. Wraps @aithos/protocol-client and exposes the Aithos compute proxy and wallet (Stripe top-up) endpoints.",
5
5
  "keywords": [
6
6
  "aithos",
@@ -29,6 +29,10 @@
29
29
  "types": "./dist/src/index.d.ts",
30
30
  "import": "./dist/src/index.js"
31
31
  },
32
+ "./react": {
33
+ "types": "./dist/src/react/index.d.ts",
34
+ "import": "./dist/src/react/index.js"
35
+ },
32
36
  "./package.json": "./package.json"
33
37
  },
34
38
  "main": "./dist/src/index.js",
@@ -52,7 +56,17 @@
52
56
  "node": ">=20"
53
57
  },
54
58
  "peerDependencies": {
55
- "@aithos/protocol-client": ">=0.1.0-alpha.13 <0.2.0"
59
+ "@aithos/protocol-client": ">=0.1.0-alpha.13 <0.2.0",
60
+ "@aithos/assets-crypto": ">=0.1.0-alpha.1 <0.2.0",
61
+ "react": "^18.0.0 || ^19.0.0"
62
+ },
63
+ "peerDependenciesMeta": {
64
+ "@aithos/assets-crypto": {
65
+ "optional": true
66
+ },
67
+ "react": {
68
+ "optional": true
69
+ }
56
70
  },
57
71
  "devDependencies": {
58
72
  "@aithos/protocol-client": "^0.1.0-alpha.13",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=auth-j3.test.d.ts.map