@soulcraft/sdk 3.3.7 → 3.3.9

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 (46) hide show
  1. package/dist/client/index.d.ts +2 -1
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/index.js +3 -1
  4. package/dist/client/index.js.map +1 -1
  5. package/dist/index.d.ts +3 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/modules/auth/products.d.ts +11 -0
  10. package/dist/modules/auth/products.d.ts.map +1 -1
  11. package/dist/modules/auth/products.js +11 -0
  12. package/dist/modules/auth/products.js.map +1 -1
  13. package/dist/modules/brainy/errors.d.ts +29 -0
  14. package/dist/modules/brainy/errors.d.ts.map +1 -1
  15. package/dist/modules/brainy/errors.js +35 -0
  16. package/dist/modules/brainy/errors.js.map +1 -1
  17. package/dist/namespaces.d.ts +219 -0
  18. package/dist/namespaces.d.ts.map +1 -1
  19. package/dist/read-only.d.ts +56 -0
  20. package/dist/read-only.d.ts.map +1 -0
  21. package/dist/read-only.js +108 -0
  22. package/dist/read-only.js.map +1 -0
  23. package/dist/server/handlers/imagine.d.ts +140 -0
  24. package/dist/server/handlers/imagine.d.ts.map +1 -0
  25. package/dist/server/handlers/imagine.js +310 -0
  26. package/dist/server/handlers/imagine.js.map +1 -0
  27. package/dist/server/handlers/index.d.ts +2 -0
  28. package/dist/server/handlers/index.d.ts.map +1 -1
  29. package/dist/server/handlers/index.js +2 -0
  30. package/dist/server/handlers/index.js.map +1 -1
  31. package/dist/server/index.d.ts +3 -2
  32. package/dist/server/index.d.ts.map +1 -1
  33. package/dist/server/index.js +3 -1
  34. package/dist/server/index.js.map +1 -1
  35. package/dist/server/read-only.d.ts +61 -0
  36. package/dist/server/read-only.d.ts.map +1 -0
  37. package/dist/server/read-only.js +67 -0
  38. package/dist/server/read-only.js.map +1 -0
  39. package/dist/server/ws-handler.d.ts.map +1 -1
  40. package/dist/server/ws-handler.js +5 -0
  41. package/dist/server/ws-handler.js.map +1 -1
  42. package/dist/transports/read-only.d.ts +68 -0
  43. package/dist/transports/read-only.d.ts.map +1 -0
  44. package/dist/transports/read-only.js +101 -0
  45. package/dist/transports/read-only.js.map +1 -0
  46. package/package.json +1 -1
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @module read-only
3
+ * @description Shared read-only enforcement for @soulcraft/sdk.
4
+ *
5
+ * Defines the canonical registry of mutation methods per SDK namespace. Both the
6
+ * client-side {@link ReadOnlyTransport} (blocks before the wire) and the server-side
7
+ * {@link createReadOnlyAuthorize} helper (blocks after the wire) import from this
8
+ * module to guarantee the same methods are blocked on both sides.
9
+ *
10
+ * ## Architecture
11
+ *
12
+ * ```
13
+ * Browser (Workshop) Server (Venue)
14
+ * ┌─────────────────┐ ┌─────────────────┐
15
+ * │ ReadOnlyTransport│ ── wire ──▶│ authorize() │
16
+ * │ blocks before │ │ blocks after │
17
+ * │ callNs() │ │ dispatch() │
18
+ * └────────┬────────┘ └────────┬────────┘
19
+ * │ │
20
+ * └──── both use ────────────────┘
21
+ * isWriteMethod()
22
+ * from @soulcraft/sdk
23
+ * ```
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { isWriteMethod } from '@soulcraft/sdk'
28
+ *
29
+ * isWriteMethod('brainy', 'find') // false (read)
30
+ * isWriteMethod('brainy', 'add') // true (write)
31
+ * isWriteMethod('brainy.vfs', 'readdir') // false (read)
32
+ * isWriteMethod('brainy.vfs', 'writeFile') // true (write)
33
+ * ```
34
+ */
35
+ export { SDKReadOnlyError } from './modules/brainy/errors.js';
36
+ /**
37
+ * Known mutation methods per SDK namespace. Any `callNs(ns, method)` matching
38
+ * an entry here is considered a write operation.
39
+ *
40
+ * Methods not in this registry are considered reads — the default is "allow".
41
+ * This registry is the single source of truth for both client-side
42
+ * {@link ReadOnlyTransport} and server-side {@link createReadOnlyAuthorize}.
43
+ */
44
+ export declare const WRITE_METHODS: Readonly<Record<string, ReadonlySet<string>>>;
45
+ /**
46
+ * Check whether a namespace + method combination is a known write operation.
47
+ *
48
+ * Used by both {@link ReadOnlyTransport} (client) and
49
+ * {@link createReadOnlyAuthorize} (server) to enforce read-only mode.
50
+ *
51
+ * @param ns - The target namespace (e.g. `'brainy'`, `'brainy.vfs'`).
52
+ * @param method - The method name (e.g. `'add'`, `'readdir'`).
53
+ * @returns `true` if the method mutates data, `false` if it's a read or unknown.
54
+ */
55
+ export declare function isWriteMethod(ns: string, method: string): boolean;
56
+ //# sourceMappingURL=read-only.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-only.d.ts","sourceRoot":"","sources":["../src/read-only.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAM7D;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CA2DvE,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEjE"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @module read-only
3
+ * @description Shared read-only enforcement for @soulcraft/sdk.
4
+ *
5
+ * Defines the canonical registry of mutation methods per SDK namespace. Both the
6
+ * client-side {@link ReadOnlyTransport} (blocks before the wire) and the server-side
7
+ * {@link createReadOnlyAuthorize} helper (blocks after the wire) import from this
8
+ * module to guarantee the same methods are blocked on both sides.
9
+ *
10
+ * ## Architecture
11
+ *
12
+ * ```
13
+ * Browser (Workshop) Server (Venue)
14
+ * ┌─────────────────┐ ┌─────────────────┐
15
+ * │ ReadOnlyTransport│ ── wire ──▶│ authorize() │
16
+ * │ blocks before │ │ blocks after │
17
+ * │ callNs() │ │ dispatch() │
18
+ * └────────┬────────┘ └────────┬────────┘
19
+ * │ │
20
+ * └──── both use ────────────────┘
21
+ * isWriteMethod()
22
+ * from @soulcraft/sdk
23
+ * ```
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * import { isWriteMethod } from '@soulcraft/sdk'
28
+ *
29
+ * isWriteMethod('brainy', 'find') // false (read)
30
+ * isWriteMethod('brainy', 'add') // true (write)
31
+ * isWriteMethod('brainy.vfs', 'readdir') // false (read)
32
+ * isWriteMethod('brainy.vfs', 'writeFile') // true (write)
33
+ * ```
34
+ */
35
+ // Re-export the error class for convenience
36
+ export { SDKReadOnlyError } from './modules/brainy/errors.js';
37
+ // ─────────────────────────────────────────────────────────────────────────────
38
+ // Write method registry
39
+ // ─────────────────────────────────────────────────────────────────────────────
40
+ /**
41
+ * Known mutation methods per SDK namespace. Any `callNs(ns, method)` matching
42
+ * an entry here is considered a write operation.
43
+ *
44
+ * Methods not in this registry are considered reads — the default is "allow".
45
+ * This registry is the single source of truth for both client-side
46
+ * {@link ReadOnlyTransport} and server-side {@link createReadOnlyAuthorize}.
47
+ */
48
+ export const WRITE_METHODS = {
49
+ // Brainy core — entity CRUD + relationship mutations
50
+ 'brainy': new Set([
51
+ 'add', 'update', 'remove', 'upsert', 'batch',
52
+ 'relate', 'unrelate', 'flush',
53
+ ]),
54
+ // Brainy VFS — file system mutations
55
+ 'brainy.vfs': new Set([
56
+ 'writeFile', 'deleteFile', 'mkdir', 'rename',
57
+ ]),
58
+ // Brainy versions — commit/revert
59
+ 'brainy.versions': new Set([
60
+ 'commit', 'revert', 'createBranch', 'deleteBranch', 'checkout',
61
+ ]),
62
+ // Graph — node deletion
63
+ 'graph': new Set(['deleteNode']),
64
+ // Collections — CRUD + membership
65
+ 'collections': new Set([
66
+ 'create', 'update', 'delete',
67
+ 'addMember', 'removeMember',
68
+ 'loadSampleData', 'clearSampleData',
69
+ ]),
70
+ // Annotations — CRUD
71
+ 'annotations': new Set(['create', 'update', 'delete']),
72
+ // Import — file ingestion
73
+ 'import': new Set(['uploadFiles', 'importData', 'cancel']),
74
+ // Workspace — mutations (but not reads)
75
+ 'workspace': new Set([
76
+ 'create', 'update', 'delete',
77
+ 'backup', 'restore', 'connectVenue', 'updateSettings',
78
+ ]),
79
+ // Publish — link/deploy mutations
80
+ 'publish': new Set([
81
+ 'createLink', 'deleteLink',
82
+ 'deployToVenue', 'publishToAcademy', 'to',
83
+ ]),
84
+ // Settings — key/config mutations
85
+ 'settings': new Set(['saveApiKey', 'deleteApiKey', 'updateSettings']),
86
+ // Media — upload/delete
87
+ 'media': new Set(['upload', 'delete']),
88
+ // Commerce — transactional mutations
89
+ 'commerce': new Set(['createProduct', 'checkout']),
90
+ // Certification — issuance
91
+ 'certification': new Set(['issue', 'revoke']),
92
+ // Pulse — event tracking (write-only namespace)
93
+ 'pulse': new Set(['track']),
94
+ };
95
+ /**
96
+ * Check whether a namespace + method combination is a known write operation.
97
+ *
98
+ * Used by both {@link ReadOnlyTransport} (client) and
99
+ * {@link createReadOnlyAuthorize} (server) to enforce read-only mode.
100
+ *
101
+ * @param ns - The target namespace (e.g. `'brainy'`, `'brainy.vfs'`).
102
+ * @param method - The method name (e.g. `'add'`, `'readdir'`).
103
+ * @returns `true` if the method mutates data, `false` if it's a read or unknown.
104
+ */
105
+ export function isWriteMethod(ns, method) {
106
+ return WRITE_METHODS[ns]?.has(method) === true;
107
+ }
108
+ //# sourceMappingURL=read-only.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-only.js","sourceRoot":"","sources":["../src/read-only.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,4CAA4C;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAE7D,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkD;IAC1E,qDAAqD;IACrD,QAAQ,EAAE,IAAI,GA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AG,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAEtC,qCAAqC;IACrC,UAAU,EAAE,IAAI,GAAG,CAAC,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAElD,2BAA2B;IAC3B,eAAe,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAE7C,gDAAgD;IAChD,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;CAC5B,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,EAAU,EAAE,MAAc;IACtD,OAAO,aAAa,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;AAChD,CAAC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @module server/handlers/imagine
3
+ * @description Imagine namespace handler — generate, list, search, and manage
4
+ * images via a GPU inference backend.
5
+ *
6
+ * The handler delegates image generation to an injected {@link ImagineBackend}
7
+ * interface and stores results as Brainy noun entities with VFS-backed PNG files.
8
+ * The backend is the Rust ONNX sidecar (imagine-gpu binary) or any HTTP service
9
+ * that implements the generate contract.
10
+ *
11
+ * Storage is fully Brainy-native: each image is a `media` noun entity with prompt
12
+ * metadata (searchable via semantic search) and a VFS file at `/images/{id}.png`.
13
+ *
14
+ * Methods:
15
+ * - `generate` — Generate images and store in Brainy
16
+ * - `generateStream` — Streaming generation with progress events
17
+ * - `list` — List/search user's image gallery
18
+ * - `get` — Get single image metadata
19
+ * - `getBytes` — Get raw PNG bytes
20
+ * - `delete` — Delete image (entity + VFS file)
21
+ * - `getPresets` — Available style and size presets
22
+ * - `health` — GPU backend health check
23
+ */
24
+ import type { NamespaceProvider } from '../namespace-router.js';
25
+ /**
26
+ * @description GPU inference backend interface. Implemented by the Imagine
27
+ * service's `gpu-client.ts` and injected via handler options.
28
+ *
29
+ * Products that host the imagine namespace (i.e. imagine.soulcraft.com itself)
30
+ * provide this backend. Products that *consume* the imagine namespace (Workshop,
31
+ * Venue) call it via the SDK transport — they never see this interface.
32
+ */
33
+ export interface ImagineBackend {
34
+ /**
35
+ * @description Generate a single image from a fully-resolved prompt.
36
+ * @param params - Generation parameters with resolved dimensions.
37
+ * @param userId - The requesting user's ID for tracking.
38
+ * @returns Raw PNG bytes, the seed used, and the resolved dimensions.
39
+ */
40
+ generate(params: {
41
+ prompt: string;
42
+ width: number;
43
+ height: number;
44
+ steps: number;
45
+ guidance: number;
46
+ seed: number;
47
+ }, userId: string): Promise<{
48
+ bytes: ArrayBuffer;
49
+ seed: number;
50
+ width: number;
51
+ height: number;
52
+ }>;
53
+ /**
54
+ * @description Stream generation progress events.
55
+ * @param params - Generation parameters.
56
+ * @param userId - The requesting user's ID.
57
+ * @returns Async iterable of progress/complete/error events.
58
+ */
59
+ generateStream?(params: {
60
+ prompt: string;
61
+ width: number;
62
+ height: number;
63
+ steps: number;
64
+ guidance: number;
65
+ seed: number;
66
+ }, userId: string): AsyncIterable<{
67
+ type: 'progress';
68
+ step: number;
69
+ total: number;
70
+ } | {
71
+ type: 'complete';
72
+ bytes: ArrayBuffer;
73
+ seed: number;
74
+ width: number;
75
+ height: number;
76
+ } | {
77
+ type: 'error';
78
+ message: string;
79
+ }>;
80
+ /**
81
+ * @description Check GPU backend health.
82
+ * @returns Health status object.
83
+ */
84
+ health(): Promise<{
85
+ status: 'ok' | 'unavailable';
86
+ gpu?: string;
87
+ info?: string;
88
+ }>;
89
+ /**
90
+ * @description Get available style presets.
91
+ * @returns Array of style presets.
92
+ */
93
+ getStylePresets(): Array<{
94
+ key: string;
95
+ label: string;
96
+ description: string;
97
+ prefix: string;
98
+ }>;
99
+ /**
100
+ * @description Get available size presets.
101
+ * @returns Array of size presets.
102
+ */
103
+ getSizePresets(): Array<{
104
+ key: string;
105
+ label: string;
106
+ width: number;
107
+ height: number;
108
+ }>;
109
+ }
110
+ /**
111
+ * @description Options for {@link createImagineHandler}.
112
+ */
113
+ export interface ImagineHandlerOptions {
114
+ /** The GPU inference backend implementation. */
115
+ backend: ImagineBackend;
116
+ }
117
+ /**
118
+ * @description Creates the `imagine` namespace handler.
119
+ *
120
+ * The handler uses `ctx.brain` for per-user image storage (Brainy noun entities
121
+ * + VFS files) and delegates GPU inference to the injected {@link ImagineBackend}.
122
+ *
123
+ * @param options - Handler dependencies. If omitted, all methods throw.
124
+ * @returns A {@link NamespaceProvider} implementing {@link ImagineNamespace}.
125
+ *
126
+ * @example Wiring in Imagine's hooks.server.ts
127
+ * ```typescript
128
+ * import { createImagineHandler } from '@soulcraft/sdk/server'
129
+ * import { imagineBackend } from '$lib/server/gpu-client.js'
130
+ *
131
+ * export const routerConfig = {
132
+ * resolveBrain: async (ctx) => getUserBrain(ctx.user.id, ctx.user.email),
133
+ * providers: {
134
+ * imagine: createImagineHandler({ backend: imagineBackend }),
135
+ * },
136
+ * }
137
+ * ```
138
+ */
139
+ export declare function createImagineHandler(options?: ImagineHandlerOptions): NamespaceProvider;
140
+ //# sourceMappingURL=imagine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imagine.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/imagine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,wBAAwB,CAAA;AAM/E;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,QAAQ,CACN,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;QACb,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;QACb,QAAQ,EAAE,MAAM,CAAA;QAChB,IAAI,EAAE,MAAM,CAAA;KACb,EACD,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,KAAK,EAAE,WAAW,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,C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AAM,WAAW,qBAAqB;IACpC,gDAAgD;IAChD,OAAO,EAAE,cAAc,CAAA;CACxB;AAwGD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,iBAAiB,CAqOvF"}
@@ -0,0 +1,310 @@
1
+ /**
2
+ * @module server/handlers/imagine
3
+ * @description Imagine namespace handler — generate, list, search, and manage
4
+ * images via a GPU inference backend.
5
+ *
6
+ * The handler delegates image generation to an injected {@link ImagineBackend}
7
+ * interface and stores results as Brainy noun entities with VFS-backed PNG files.
8
+ * The backend is the Rust ONNX sidecar (imagine-gpu binary) or any HTTP service
9
+ * that implements the generate contract.
10
+ *
11
+ * Storage is fully Brainy-native: each image is a `media` noun entity with prompt
12
+ * metadata (searchable via semantic search) and a VFS file at `/images/{id}.png`.
13
+ *
14
+ * Methods:
15
+ * - `generate` — Generate images and store in Brainy
16
+ * - `generateStream` — Streaming generation with progress events
17
+ * - `list` — List/search user's image gallery
18
+ * - `get` — Get single image metadata
19
+ * - `getBytes` — Get raw PNG bytes
20
+ * - `delete` — Delete image (entity + VFS file)
21
+ * - `getPresets` — Available style and size presets
22
+ * - `health` — GPU backend health check
23
+ */
24
+ // ─────────────────────────────────────────────────────────────────────────────
25
+ // Constants
26
+ // ─────────────────────────────────────────────────────────────────────────────
27
+ /** VFS directory where generated images are stored. */
28
+ const IMAGES_VFS_PATH = '/images';
29
+ // ─────────────────────────────────────────────────────────────────────────────
30
+ // Internal helpers
31
+ // ─────────────────────────────────────────────────────────────────────────────
32
+ /**
33
+ * @description Resolve a style preset key to its prompt prefix.
34
+ * @param key - Style preset key.
35
+ * @param backend - The GPU backend (for preset lookup).
36
+ * @returns The prefix string (empty for "none").
37
+ */
38
+ function resolveStylePrefix(key, backend) {
39
+ const presets = backend.getStylePresets();
40
+ const preset = presets.find((s) => s.key === key);
41
+ return preset?.prefix ?? '';
42
+ }
43
+ /**
44
+ * @description Resolve a size preset key to dimensions.
45
+ * @param key - Size preset key.
46
+ * @param backend - The GPU backend (for preset lookup).
47
+ * @returns Width and height in pixels.
48
+ */
49
+ function resolveDimensions(key, backend) {
50
+ const presets = backend.getSizePresets();
51
+ const preset = presets.find((s) => s.key === key);
52
+ return preset ?? { width: 1024, height: 576 };
53
+ }
54
+ /**
55
+ * @description Extract image metadata from a Brainy Result or Entity.
56
+ * @param r - A result from brain.find() or brain.get().
57
+ * @returns Normalized image metadata.
58
+ */
59
+ function toImageMeta(r) {
60
+ const d = (r.data ?? {});
61
+ return {
62
+ id: r.id,
63
+ prompt: d['prompt'] ?? '',
64
+ style: d['style'] ?? 'none',
65
+ size: d['size'] ?? 'landscape',
66
+ steps: d['steps'] ?? 25,
67
+ guidance: d['guidance'] ?? 7.5,
68
+ seed: d['seed'] ?? 0,
69
+ width: d['width'] ?? 1024,
70
+ height: d['height'] ?? 576,
71
+ elapsed: d['elapsed'] ?? 0,
72
+ createdAt: d['createdAt'] ?? 0,
73
+ filename: `${r.id}.png`,
74
+ };
75
+ }
76
+ /**
77
+ * @description Store a generated image in Brainy (entity + VFS file).
78
+ * @returns The entity ID.
79
+ */
80
+ async function storeImage(brain, imageBytes, meta) {
81
+ const id = await brain.add({
82
+ data: {
83
+ prompt: meta.prompt,
84
+ style: meta.style,
85
+ size: meta.size,
86
+ steps: meta.steps,
87
+ guidance: meta.guidance,
88
+ seed: meta.seed,
89
+ width: meta.width,
90
+ height: meta.height,
91
+ elapsed: meta.elapsed,
92
+ createdAt: Date.now(),
93
+ },
94
+ type: 'media',
95
+ metadata: {
96
+ name: meta.prompt.slice(0, 100),
97
+ mediaType: 'image/png',
98
+ },
99
+ });
100
+ // Write PNG to VFS
101
+ const vfsPath = `${IMAGES_VFS_PATH}/${id}.png`;
102
+ await brain.vfs.mkdir(IMAGES_VFS_PATH, { recursive: true });
103
+ await brain.vfs.writeFile(vfsPath, Buffer.from(imageBytes));
104
+ return id;
105
+ }
106
+ // ─────────────────────────────────────────────────────────────────────────────
107
+ // Handler factory
108
+ // ─────────────────────────────────────────────────────────────────────────────
109
+ /**
110
+ * @description Creates the `imagine` namespace handler.
111
+ *
112
+ * The handler uses `ctx.brain` for per-user image storage (Brainy noun entities
113
+ * + VFS files) and delegates GPU inference to the injected {@link ImagineBackend}.
114
+ *
115
+ * @param options - Handler dependencies. If omitted, all methods throw.
116
+ * @returns A {@link NamespaceProvider} implementing {@link ImagineNamespace}.
117
+ *
118
+ * @example Wiring in Imagine's hooks.server.ts
119
+ * ```typescript
120
+ * import { createImagineHandler } from '@soulcraft/sdk/server'
121
+ * import { imagineBackend } from '$lib/server/gpu-client.js'
122
+ *
123
+ * export const routerConfig = {
124
+ * resolveBrain: async (ctx) => getUserBrain(ctx.user.id, ctx.user.email),
125
+ * providers: {
126
+ * imagine: createImagineHandler({ backend: imagineBackend }),
127
+ * },
128
+ * }
129
+ * ```
130
+ */
131
+ export function createImagineHandler(options) {
132
+ const backend = options?.backend;
133
+ function requireBackend() {
134
+ if (!backend) {
135
+ throw new Error('imagine namespace is not configured — provide an ImagineBackend via providers.imagine. ' +
136
+ 'The imagine backend is hosted by imagine.soulcraft.com.');
137
+ }
138
+ return backend;
139
+ }
140
+ return {
141
+ async generate(params, ctx) {
142
+ const gpu = requireBackend();
143
+ const { brain } = ctx;
144
+ const count = Math.min(Math.max(params.count ?? 1, 1), 4);
145
+ const style = params.style ?? 'none';
146
+ const sizeKey = params.size ?? 'landscape';
147
+ const steps = params.steps ?? 25;
148
+ const guidance = params.guidance ?? 7.5;
149
+ const prefix = resolveStylePrefix(style, gpu);
150
+ const { width, height } = resolveDimensions(sizeKey, gpu);
151
+ const fullPrompt = prefix + params.prompt;
152
+ const images = [];
153
+ for (let i = 0; i < count; i++) {
154
+ const seed = params.seed != null
155
+ ? params.seed + i
156
+ : Math.floor(Math.random() * 2147483647);
157
+ const start = performance.now();
158
+ const result = await gpu.generate({ prompt: fullPrompt, width, height, steps, guidance, seed }, ctx.user.id);
159
+ const elapsed = (performance.now() - start) / 1000;
160
+ const id = await storeImage(brain, result.bytes, {
161
+ prompt: params.prompt,
162
+ style,
163
+ size: sizeKey,
164
+ steps,
165
+ guidance,
166
+ seed: result.seed,
167
+ width: result.width,
168
+ height: result.height,
169
+ elapsed,
170
+ });
171
+ images.push({
172
+ id,
173
+ prompt: params.prompt,
174
+ style,
175
+ size: sizeKey,
176
+ steps,
177
+ guidance,
178
+ seed: result.seed,
179
+ width: result.width,
180
+ height: result.height,
181
+ elapsed,
182
+ createdAt: Date.now(),
183
+ filename: `${id}.png`,
184
+ });
185
+ }
186
+ return images;
187
+ },
188
+ async *generateStream(params, ctx) {
189
+ const gpu = requireBackend();
190
+ const { brain } = ctx;
191
+ const style = params.style ?? 'none';
192
+ const sizeKey = params.size ?? 'landscape';
193
+ const steps = params.steps ?? 25;
194
+ const guidance = params.guidance ?? 7.5;
195
+ const seed = params.seed ?? Math.floor(Math.random() * 2147483647);
196
+ const prefix = resolveStylePrefix(style, gpu);
197
+ const { width, height } = resolveDimensions(sizeKey, gpu);
198
+ const fullPrompt = prefix + params.prompt;
199
+ if (gpu.generateStream) {
200
+ const start = performance.now();
201
+ let resultBytes = null;
202
+ let resultSeed = seed;
203
+ let resultWidth = width;
204
+ let resultHeight = height;
205
+ for await (const event of gpu.generateStream({ prompt: fullPrompt, width, height, steps, guidance, seed }, ctx.user.id)) {
206
+ if (event.type === 'progress') {
207
+ yield { type: 'progress', step: event.step, total: event.total };
208
+ }
209
+ else if (event.type === 'complete') {
210
+ resultBytes = event.bytes;
211
+ resultSeed = event.seed;
212
+ resultWidth = event.width;
213
+ resultHeight = event.height;
214
+ }
215
+ else if (event.type === 'error') {
216
+ yield { type: 'error', message: event.message };
217
+ return;
218
+ }
219
+ }
220
+ if (resultBytes) {
221
+ const elapsed = (performance.now() - start) / 1000;
222
+ const id = await storeImage(brain, resultBytes, {
223
+ prompt: params.prompt, style, size: sizeKey, steps, guidance,
224
+ seed: resultSeed, width: resultWidth, height: resultHeight, elapsed,
225
+ });
226
+ yield {
227
+ type: 'complete',
228
+ images: [{
229
+ id,
230
+ prompt: params.prompt, style, size: sizeKey, steps, guidance,
231
+ seed: resultSeed, width: resultWidth, height: resultHeight,
232
+ elapsed, createdAt: Date.now(), filename: `${id}.png`,
233
+ }],
234
+ };
235
+ }
236
+ }
237
+ else {
238
+ // Fallback: non-streaming generate with simulated progress
239
+ for (let step = 1; step <= steps; step++) {
240
+ yield { type: 'progress', step, total: steps };
241
+ }
242
+ const start = performance.now();
243
+ const result = await gpu.generate({ prompt: fullPrompt, width, height, steps, guidance, seed }, ctx.user.id);
244
+ const elapsed = (performance.now() - start) / 1000;
245
+ const id = await storeImage(brain, result.bytes, {
246
+ prompt: params.prompt, style, size: sizeKey, steps, guidance,
247
+ seed: result.seed, width: result.width, height: result.height, elapsed,
248
+ });
249
+ yield {
250
+ type: 'complete',
251
+ images: [{
252
+ id,
253
+ prompt: params.prompt, style, size: sizeKey, steps, guidance,
254
+ seed: result.seed, width: result.width, height: result.height,
255
+ elapsed, createdAt: Date.now(), filename: `${id}.png`,
256
+ }],
257
+ };
258
+ }
259
+ },
260
+ async list(options, ctx) {
261
+ const { brain } = ctx;
262
+ const limit = options?.limit ?? 50;
263
+ const results = options?.query
264
+ ? await brain.find({ query: options.query, where: { noun: 'media' }, limit })
265
+ : await brain.find({ where: { noun: 'media' }, limit });
266
+ return results.map(toImageMeta);
267
+ },
268
+ async get(imageId, ctx) {
269
+ const entity = await ctx.brain.get(imageId);
270
+ if (!entity)
271
+ return null;
272
+ return toImageMeta(entity);
273
+ },
274
+ async getBytes(imageId, ctx) {
275
+ try {
276
+ const buffer = await ctx.brain.vfs.readFile(`${IMAGES_VFS_PATH}/${imageId}.png`);
277
+ // Return as ArrayBuffer
278
+ if (buffer instanceof ArrayBuffer)
279
+ return buffer;
280
+ if (Buffer.isBuffer(buffer))
281
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
282
+ return null;
283
+ }
284
+ catch {
285
+ return null;
286
+ }
287
+ },
288
+ async delete(imageId, ctx) {
289
+ await ctx.brain.delete(imageId);
290
+ try {
291
+ await ctx.brain.vfs.unlink(`${IMAGES_VFS_PATH}/${imageId}.png`);
292
+ }
293
+ catch {
294
+ // VFS file may already be gone
295
+ }
296
+ },
297
+ async getPresets() {
298
+ const gpu = requireBackend();
299
+ return {
300
+ styles: gpu.getStylePresets().map(({ key, label, description }) => ({ key, label, description })),
301
+ sizes: gpu.getSizePresets(),
302
+ };
303
+ },
304
+ async health() {
305
+ const gpu = requireBackend();
306
+ return gpu.health();
307
+ },
308
+ };
309
+ }
310
+ //# sourceMappingURL=imagine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imagine.js","sourceRoot":"","sources":["../../../src/server/handlers/imagine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAoFH,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,uDAAuD;AACvD,MAAM,eAAe,GAAG,SAAS,CAAA;AAEjC,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,GAAW,EAAE,OAAuB;IAC9D,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,EAAE,CAAA;IACzC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAA;IACjD,OAAO,MAAM,EAAE,MAAM,IAAI,EAAE,CAAA;AAC7B,CAAC;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,GAAW,EAAE,OAAuB;IAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAA;IACxC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAA;IACjD,OAAO,MAAM,IAAI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CAAC;YAAC,MAAM,CAAC;gBACP,+BAA+B;YACjC,CAAC;QACH,CAAC;QAED,KAAK,CAAC,UAAU;YACd,MAAM,GAAG,GAAG,cAAc,EAAE,CAAA;YAC5B,OAAO;gBACL,MAAM,EAAE,GAAG,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;gBACjG,KAAK,EAAE,GAAG,CAAC,cAAc,EAAE;aAC5B,CAAA;QACH,CAAC;QAED,KAAK,CAAC,MAAM;YACV,MAAM,GAAG,GAAG,cAAc,EAAE,CAAA;YAC5B,OAAO,GAAG,CAAC,MAAM,EAAE,CAAA;QACrB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -46,6 +46,8 @@ export type { ExportPipeline, ExportHandlerOptions } from './export.js';
46
46
  export { createFormatsHandler } from './formats.js';
47
47
  export type { FormatConverter, FormatsHandlerOptions } from './formats.js';
48
48
  export { createGraphHandler } from './graph.js';
49
+ export { createImagineHandler } from './imagine.js';
50
+ export type { ImagineBackend, ImagineHandlerOptions } from './imagine.js';
49
51
  export { createImportHandler } from './import.js';
50
52
  export type { ImportPipeline, ImportHandlerOptions } from './import.js';
51
53
  export { createMediaHandler } from './media.js';