@happyvertical/smrt-template-sveltekit 0.60.17 → 0.61.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.
Files changed (80) hide show
  1. package/AGENTS.md +68 -51
  2. package/README.md +25 -10
  3. package/agents/cookbook-design-runs.md +164 -0
  4. package/agents/cookbook-host.md +724 -0
  5. package/agents/onboarding.md +116 -0
  6. package/agents/plugin-mode.md +152 -0
  7. package/cookbook-template/.pnpmfile.cjs +5 -0
  8. package/cookbook-template/src/hooks.server.ts +3 -0
  9. package/cookbook-template/src/lib/server/cookbook.ts +21 -0
  10. package/cookbook-template/src/lib/server/smrt.ts +11 -0
  11. package/cookbook-template/src/routes/+layout.server.ts +24 -0
  12. package/cookbook-template/src/routes/+layout.svelte +47 -0
  13. package/cookbook-template/src/routes/+page.server.ts +15 -0
  14. package/cookbook-template/src/routes/+page.svelte +12 -0
  15. package/cookbook-template/src/routes/api/_runtime/owner-link/+server.ts +2 -0
  16. package/cookbook-template/src/routes/api/assistant/[...path]/+server.ts +2 -0
  17. package/cookbook-template/src/routes/api/connect-ai/+server.ts +2 -0
  18. package/cookbook-template/src/routes/api/cookbook/prebuilt/+server.ts +3 -0
  19. package/cookbook-template/src/routes/api/cookbook/preferences/+server.ts +45 -0
  20. package/cookbook-template/src/routes/api/onboarding/+server.ts +3 -0
  21. package/cookbook-template/src/routes/m/[pkg]/[model]/[[key]]/+page.server.ts +1 -0
  22. package/cookbook-template/src/routes/m/[pkg]/[model]/[[key]]/+page.svelte +7 -0
  23. package/cookbook-template/src/routes/mcp/+server.ts +2 -0
  24. package/cookbook-template/src/routes/onboarding/+page.server.ts +13 -0
  25. package/cookbook-template/src/routes/onboarding/+page.svelte +28 -0
  26. package/cookbook-template/src/routes/s/[slug]/+page.server.ts +10 -0
  27. package/cookbook-template/src/routes/s/[slug]/+page.svelte +6 -0
  28. package/cookbook-template/src/routes/settings/+page.server.ts +22 -0
  29. package/cookbook-template/src/routes/settings/+page.svelte +49 -0
  30. package/cookbook-template/src/routes/settings/inference/+page.server.ts +6 -0
  31. package/cookbook-template/src/routes/settings/inference/+page.svelte +14 -0
  32. package/cookbook-template/vite.config.ts +4 -0
  33. package/dist/host/client.d.ts +8 -0
  34. package/dist/host/client.js +66 -0
  35. package/dist/host/design-runs.d.ts +72 -0
  36. package/dist/host/design-runs.js +763 -0
  37. package/dist/host/generate.d.ts +49 -0
  38. package/dist/host/generate.js +266 -0
  39. package/dist/host/onboarding.d.ts +26 -0
  40. package/dist/host/onboarding.js +247 -0
  41. package/dist/host/plugin-mode.d.ts +55 -0
  42. package/dist/host/plugin-mode.js +184 -0
  43. package/dist/host/preferences.d.ts +40 -0
  44. package/dist/host/preferences.js +163 -0
  45. package/dist/host/server.d.ts +283 -0
  46. package/dist/host/server.js +2400 -0
  47. package/dist/host/settings.d.ts +57 -0
  48. package/dist/host/settings.js +130 -0
  49. package/dist/host/state.d.ts +26 -0
  50. package/dist/host/state.js +149 -0
  51. package/dist/host/sveltekit-client.d.ts +22 -0
  52. package/dist/host/sveltekit-client.js +53 -0
  53. package/dist/smrt-knowledge.okf.md +105 -0
  54. package/examples/notes/src/routes/notes/+page.svelte +145 -0
  55. package/host/CookbookModelPage.svelte +78 -0
  56. package/host/InferenceSettingsPage.svelte +103 -0
  57. package/mcp-apps-template/package.dependencies.json +2 -2
  58. package/package.json +102 -24
  59. package/template/README.md +24 -11
  60. package/template/package.json +17 -12
  61. package/template/smrt.config.ts +4 -0
  62. package/template/src/hooks.server.ts +5 -0
  63. package/template/src/lib/objects/index.ts +7 -3
  64. package/template/src/lib/server/settings-registry.ts +29 -0
  65. package/template/src/lib/server/settings.ts +91 -0
  66. package/template/src/lib/server/smrt.ts +1 -0
  67. package/template/src/lib/settings-client.ts +1 -0
  68. package/template/src/lib/sign-out.ts +1 -19
  69. package/template/src/params/settingsSection.ts +4 -0
  70. package/template/src/routes/+layout.svelte +1 -2
  71. package/template/src/routes/+page.svelte +20 -128
  72. package/template/src/routes/settings/+page.svelte +16 -3
  73. package/template/src/routes/settings/[section=settingsSection]/+page.svelte +19 -0
  74. package/template/src/routes/settings/inference/+page.server.ts +3 -0
  75. package/template/src/routes/settings/inference/+page.svelte +6 -0
  76. package/template/src/routes/settings/prompts/+page.server.ts +50 -0
  77. package/template/src/routes/settings/prompts/+page.svelte +28 -0
  78. package/template.config.js +17 -12
  79. /package/{template → examples/notes}/src/lib/objects/Note.ts +0 -0
  80. /package/{template/src/routes → examples/notes/src/routes/notes}/+page.server.ts +0 -0
@@ -0,0 +1,184 @@
1
+ /** Local-owner setup composition; credentials remain in the existing runtime store. */
2
+ import { access, mkdir, unlink, writeFile } from 'node:fs/promises';
3
+ import { dirname, join, relative } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ export const PLUGIN_PERMISSION = 'app.plugin';
6
+ export const PLUGIN_CLIENTS = {
7
+ codex: 'Codex',
8
+ 'claude-code': 'Claude Code',
9
+ 'claude-desktop': 'Claude Desktop',
10
+ };
11
+ export function createPluginMode(options) {
12
+ const { runtime } = options;
13
+ const reply = (value, status = 200) => Response.json(value, { status, headers: { 'cache-control': 'no-store' } });
14
+ async function locations(client) {
15
+ const local = await runtime.localRuntime();
16
+ if (!local.mcpTokens)
17
+ throw new Error('Local MCP token store unavailable');
18
+ const directory = join(runtime.applicationStateRoot(), 'plugin-mode');
19
+ return {
20
+ local,
21
+ store: local.mcpTokens,
22
+ directory,
23
+ config: join(directory, `${client}.json`),
24
+ launcher: join(directory, `${client}.mjs`),
25
+ };
26
+ }
27
+ async function launchOptions(client) {
28
+ const paths = await locations(client);
29
+ const packaged = join(options.sourceRoot, '..', 'bridge', 'smrt-mcp-bridge.mjs');
30
+ const bridgePath = await access(packaged).then(() => packaged, () => join(dirname(fileURLToPath(import.meta.resolve('@happyvertical/smrt-app-cli'))), 'bin', 'smrt-mcp-bridge.js'));
31
+ let resourceRoot = dirname(process.execPath);
32
+ while (relative(resourceRoot, bridgePath).startsWith('..'))
33
+ resourceRoot = dirname(resourceRoot);
34
+ return {
35
+ productId: runtime.applicationId(),
36
+ appId: runtime.applicationId(),
37
+ dataDirectory: paths.local.paths.root,
38
+ sourceRoot: options.sourceRoot,
39
+ resourceRoot,
40
+ nodePath: process.execPath,
41
+ bridgePath,
42
+ healthRoute: '/api/_runtime/health',
43
+ envPrefix: 'SMRT_PLUGIN',
44
+ scopes: [PLUGIN_PERMISSION],
45
+ credentialPath: paths.config,
46
+ mcpPath: '/mcp',
47
+ serverName: options.name,
48
+ serverVersion: '1.0.0',
49
+ };
50
+ }
51
+ async function setup(client) {
52
+ const { launcher } = await locations(client);
53
+ const { generateLocalMcpSetup } = await import('@happyvertical/smrt-app-cli');
54
+ return generateLocalMcpSetup({
55
+ name: options.name,
56
+ command: process.execPath,
57
+ args: [launcher],
58
+ });
59
+ }
60
+ async function read(actor) {
61
+ const local = await runtime.localRuntime();
62
+ if (!local.mcpTokens)
63
+ throw new Error('Local MCP token store unavailable');
64
+ const records = await local.mcpTokens.list();
65
+ const { generateLocalMcpSetup } = await import('@happyvertical/smrt-app-cli');
66
+ return {
67
+ tools: await options.tools?.(actor),
68
+ embed: await (await options.state()).embed(actor.tenantId, actor.id),
69
+ connections: await Promise.all(Object.keys(PLUGIN_CLIENTS).map(async (client) => {
70
+ const record = records.find((r) => r.holder === `plugin-mode:${client}` && r.status === 'active') ?? records.find((r) => r.holder === `plugin-mode:${client}`);
71
+ return {
72
+ client,
73
+ name: PLUGIN_CLIENTS[client],
74
+ status: record?.status ?? 'not_connected',
75
+ lastSeen: record?.lastUsedAt ?? null,
76
+ setup: record?.status === 'active' ? await setup(client) : null,
77
+ };
78
+ })),
79
+ chatgpt: generateLocalMcpSetup({
80
+ name: options.name,
81
+ command: process.execPath,
82
+ args: [],
83
+ }).chatgpt,
84
+ };
85
+ }
86
+ async function handle(event) {
87
+ // No proxy headers or bearer can turn a remote request into a local owner.
88
+ let peer;
89
+ try {
90
+ peer = event.getClientAddress();
91
+ }
92
+ catch {
93
+ return reply({ code: 'not_allowed' }, 403);
94
+ }
95
+ if (!['127.0.0.1', '::1', '::ffff:127.0.0.1'].includes(peer) ||
96
+ !['127.0.0.1', 'localhost', '[::1]'].includes(event.url.hostname) ||
97
+ event.request.headers.get('host') !== event.url.host ||
98
+ event.request.headers.has('authorization'))
99
+ return reply({ code: 'not_allowed' }, 403);
100
+ const actor = await options.authorize(event);
101
+ if (!actor)
102
+ return reply({ code: 'not_allowed' }, 403);
103
+ if (event.request.method === 'GET')
104
+ return reply(await read(actor));
105
+ if (event.request.method !== 'POST')
106
+ return reply({ code: 'method_not_allowed' }, 405);
107
+ if (event.request.headers.get('origin') !== event.url.origin)
108
+ return reply({ code: 'invalid_origin' }, 403);
109
+ if (event.request.headers.get('content-type')?.split(';')[0].trim() !==
110
+ 'application/json')
111
+ return reply({ code: 'invalid_request' }, 415);
112
+ const reader = event.request.body?.getReader();
113
+ if (!reader)
114
+ return reply({ code: 'invalid_request' }, 400);
115
+ let body;
116
+ try {
117
+ let raw = '';
118
+ const decoder = new TextDecoder('utf-8', { fatal: true });
119
+ let bytes = 0;
120
+ for (;;) {
121
+ const part = await reader.read();
122
+ if (part.done)
123
+ break;
124
+ bytes += part.value.byteLength;
125
+ if (bytes > 4096) {
126
+ await reader.cancel();
127
+ return reply({ code: 'body_too_large' }, 413);
128
+ }
129
+ raw += decoder.decode(part.value, { stream: true });
130
+ }
131
+ body = JSON.parse(raw + decoder.decode());
132
+ if (!body || Array.isArray(body) || typeof body !== 'object')
133
+ return reply({ code: 'invalid_request' }, 400);
134
+ }
135
+ catch {
136
+ return reply({ code: 'invalid_request' }, 400);
137
+ }
138
+ finally {
139
+ reader.releaseLock();
140
+ }
141
+ if (body.action === 'embed' &&
142
+ typeof body.enabled === 'boolean' &&
143
+ Object.keys(body).length === 2) {
144
+ await (await options.state()).setEmbed(actor.tenantId, actor.id, body.enabled);
145
+ }
146
+ else {
147
+ const client = body.client;
148
+ if (typeof client !== 'string' ||
149
+ !Object.hasOwn(PLUGIN_CLIENTS, client) ||
150
+ Object.keys(body).length !== 2 ||
151
+ (body.action !== 'connect' && body.action !== 'revoke'))
152
+ return reply({ code: 'invalid_request' }, 400);
153
+ const selected = client;
154
+ const paths = await locations(selected);
155
+ const holder = `plugin-mode:${selected}`;
156
+ if (body.action === 'revoke') {
157
+ await paths.store.revokeHolder(holder);
158
+ await unlink(paths.config).catch((e) => {
159
+ if (e.code !== 'ENOENT')
160
+ throw e;
161
+ });
162
+ }
163
+ else {
164
+ const issued = await paths.store.issue({
165
+ scopes: [PLUGIN_PERMISSION],
166
+ holder,
167
+ label: PLUGIN_CLIENTS[selected],
168
+ }, { userId: actor.id, tenantId: actor.tenantId });
169
+ try {
170
+ const { saveCliConfig } = await import('@happyvertical/smrt-app-cli');
171
+ await saveCliConfig({ envPrefix: 'SMRT_PLUGIN', configPath: paths.config }, { serverUrl: event.url.origin, token: issued.token });
172
+ await mkdir(paths.directory, { recursive: true, mode: 0o700 });
173
+ await writeFile(paths.launcher, `import { runLauncher } from ${JSON.stringify(import.meta.resolve('@happyvertical/smrt-desktop/launcher'))};\nprocess.exitCode = await runLauncher(${JSON.stringify(await launchOptions(selected))});\n`, { mode: 0o600 });
174
+ }
175
+ catch {
176
+ await paths.store.revoke(issued.id);
177
+ return reply({ code: 'setup_failed' }, 503);
178
+ }
179
+ }
180
+ }
181
+ return reply(await read(actor));
182
+ }
183
+ return { handle, read };
184
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The cookbook this checkout was built from (`smrt.cookbook.json`, written by
3
+ * `smrt cookbook apply`) and the edits people make to it in the running app.
4
+ *
5
+ * The file is the app's default. Edits to section overviews and to the shell
6
+ * layout are personal preferences: they are stored through smrt-preferences
7
+ * (`_smrt_ui_preferences`, per tenant and user), never written back to the
8
+ * file. `loadCookbook` lays the stored preferences over the file;
9
+ * `saveCookbookEdits` turns the cookbook `CookbookApp` reports after an edit
10
+ * back into the stored preference.
11
+ */
12
+ import type { SmrtSvelteKitRuntime } from '@happyvertical/smrt-app-runtime/sveltekit';
13
+ import { type PreferenceScope } from '@happyvertical/smrt-preferences';
14
+ import type { CookbookAppProps } from '@happyvertical/smrt-svelte/cookbook';
15
+ import { type CookbookAppData, type LoadCookbookAppOptions } from '@happyvertical/smrt-svelte/cookbook/server';
16
+ /** The shell's preference surface id; the layout is stored once per person. */
17
+ export declare const SHELL_SURFACE = "admin";
18
+ export type CookbookScope = PreferenceScope;
19
+ export type CookbookSaveResult = {
20
+ ok: true;
21
+ saved: string[];
22
+ } | {
23
+ ok: false;
24
+ reason: 'not_allowed' | 'conflict' | 'invalid';
25
+ id?: string;
26
+ };
27
+ /** Where the cookbook lives; the project root and `smrt.cookbook.json` by default. */
28
+ export type CookbookSource = Pick<LoadCookbookAppOptions, 'root' | 'file'>;
29
+ /** Persist cookbook shell edits using the existing overview and shell preference kinds. */
30
+ export declare function createCookbookPreferences(options: {
31
+ runtime: Pick<SmrtSvelteKitRuntime, 'databaseConfig'>;
32
+ resolveExport?: CookbookAppProps['resolveExport'];
33
+ app?: () => Promise<CookbookAppData>;
34
+ }): {
35
+ loadCookbook: (options: {
36
+ signedIn: boolean;
37
+ } & CookbookSource) => Promise<CookbookAppData | null>;
38
+ saveCookbookEdits: (edited: unknown, scope?: CookbookScope, source?: CookbookSource) => Promise<CookbookSaveResult>;
39
+ homePath: (app: CookbookAppData) => string;
40
+ };
@@ -0,0 +1,163 @@
1
+ /**
2
+ * The cookbook this checkout was built from (`smrt.cookbook.json`, written by
3
+ * `smrt cookbook apply`) and the edits people make to it in the running app.
4
+ *
5
+ * The file is the app's default. Edits to section overviews and to the shell
6
+ * layout are personal preferences: they are stored through smrt-preferences
7
+ * (`_smrt_ui_preferences`, per tenant and user), never written back to the
8
+ * file. `loadCookbook` lays the stored preferences over the file;
9
+ * `saveCookbookEdits` turns the cookbook `CookbookApp` reports after an edit
10
+ * back into the stored preference.
11
+ */
12
+ import { resolveDatabase } from '@happyvertical/smrt-core';
13
+ import { createOverviewStore, createPreferenceStore, createShellSettingsPreferences, getPreferencePrincipal, PreferenceAccessError, } from '@happyvertical/smrt-preferences';
14
+ import { createCookbookRegistry, resolveInstalledRecipeExport, } from '@happyvertical/smrt-svelte/cookbook';
15
+ import { buildCookbookShell, hasCookbook, loadCookbookApp, } from '@happyvertical/smrt-svelte/cookbook/server';
16
+ import { diffOverview, resolveOverview, } from '@happyvertical/smrt-svelte/overview/server';
17
+ /** The shell's preference surface id; the layout is stored once per person. */
18
+ export const SHELL_SURFACE = 'admin';
19
+ /** Persist cookbook shell edits using the existing overview and shell preference kinds. */
20
+ export function createCookbookPreferences(options) {
21
+ const { runtime, resolveExport } = options;
22
+ const liveApp = options.app;
23
+ const loadApp = (source) => options.app && !source.root && !source.file
24
+ ? options.app()
25
+ : loadCookbookApp(source);
26
+ async function prepare(app) {
27
+ const shell = buildCookbookShell({
28
+ cookbook: app.cookbook,
29
+ catalog: app.catalog,
30
+ });
31
+ const { registry } = await createCookbookRegistry({
32
+ widgets: shell.widgets,
33
+ resolveExport: resolveExport ??
34
+ ((specifier, name) => resolveInstalledRecipeExport(specifier, name, {
35
+ recipes: app.cookbook.recipes,
36
+ tenantId: getPreferencePrincipal()?.tenantId,
37
+ })),
38
+ });
39
+ return { shell, registry };
40
+ }
41
+ /** The page defaults with the cookbook file's own override already applied. */
42
+ function fileDefinition(page, registry) {
43
+ const { document } = resolveOverview(page.definition, page.override, registry);
44
+ return { ...page.definition, defaults: document.widgets };
45
+ }
46
+ async function stores() {
47
+ const config = runtime.databaseConfig();
48
+ if (!config)
49
+ throw new Error('The runtime has no database configured.');
50
+ const db = await resolveDatabase(config);
51
+ const preferences = createPreferenceStore({ db });
52
+ return {
53
+ overviews: createOverviewStore({ db, preferences }),
54
+ shell: createShellSettingsPreferences(preferences),
55
+ };
56
+ }
57
+ /**
58
+ * The project's cookbook with the signed-in person's stored preferences laid
59
+ * over it, or `null` when the project has no cookbook. An invalid cookbook
60
+ * throws (the message lists every problem).
61
+ */
62
+ async function loadCookbook(options) {
63
+ if ((!liveApp || options.root || options.file) &&
64
+ !(await hasCookbook(options.root, options.file)))
65
+ return null;
66
+ const app = await loadApp(options);
67
+ if (!options.signedIn)
68
+ return app;
69
+ try {
70
+ const { shell, registry } = await prepare(app);
71
+ const { overviews, shell: layouts } = await stores();
72
+ const cookbook = { ...app.cookbook };
73
+ const stored = {};
74
+ for (const [id, page] of Object.entries(shell.overviews)) {
75
+ const state = await overviews.load(fileDefinition(page, registry), registry);
76
+ const base = resolveOverview(page.definition, null, registry).document;
77
+ const override = diffOverview(base, state.document);
78
+ if (override)
79
+ stored[id] = override;
80
+ }
81
+ if (Object.keys(stored).length > 0)
82
+ cookbook.overviews = stored;
83
+ else
84
+ delete cookbook.overviews;
85
+ const { delta } = await layouts.read(SHELL_SURFACE);
86
+ if (delta.layout)
87
+ cookbook.layout = delta.layout;
88
+ return { ...app, cookbook };
89
+ }
90
+ catch (error) {
91
+ // A person without preference permissions still gets the file's cookbook.
92
+ if (error instanceof PreferenceAccessError)
93
+ return app;
94
+ throw error;
95
+ }
96
+ }
97
+ function sameJson(a, b) {
98
+ return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
99
+ }
100
+ function isRecord(value) {
101
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
102
+ }
103
+ /**
104
+ * Store the layout and overview edits in `edited`, the cookbook `CookbookApp`
105
+ * reports (untrusted: only its `layout` and `overviews` are read, and each is
106
+ * validated by the preference kind before anything is stored). `scope: 'user'`
107
+ * keeps a personal version; `'tenant'` changes the default everyone starts
108
+ * from and needs `overviews.customize` / `shell.customize`.
109
+ */
110
+ async function saveCookbookEdits(edited, scope = 'user', source = {}) {
111
+ const app = await loadApp(source);
112
+ const { shell, registry } = await prepare(app);
113
+ const { overviews, shell: layouts } = await stores();
114
+ const input = isRecord(edited) ? edited : {};
115
+ const wanted = isRecord(input.overviews) ? input.overviews : {};
116
+ const saved = [];
117
+ for (const [id, page] of Object.entries(shell.overviews)) {
118
+ const definition = fileDefinition(page, registry);
119
+ const state = await overviews.load(definition, registry);
120
+ const desired = resolveOverview(page.definition, wanted[id] ?? null, registry).document;
121
+ if (sameJson(desired, state.document))
122
+ continue;
123
+ // Each tier stores a delta against the tier below it.
124
+ const below = scope === 'tenant' ? state.tenant.base : state.tenant.document;
125
+ const result = await overviews.save(definition, registry, {
126
+ scope,
127
+ override: diffOverview(below, desired),
128
+ revision: scope === 'tenant'
129
+ ? state.tenant.revision
130
+ : (state.user?.revision ?? null),
131
+ });
132
+ if (!result.ok)
133
+ return { ok: false, reason: result.reason, id };
134
+ saved.push(id);
135
+ }
136
+ const current = (await layouts.read(SHELL_SURFACE)).delta.layout;
137
+ const desiredLayout = isRecord(input.layout)
138
+ ? input.layout
139
+ : (app.cookbook.layout ?? null);
140
+ if (!sameJson(desiredLayout, current ?? app.cookbook.layout)) {
141
+ const result = sameJson(desiredLayout, app.cookbook.layout)
142
+ ? await layouts.reset(SHELL_SURFACE, { scope })
143
+ : await layouts.write(SHELL_SURFACE, { layout: desiredLayout }, { scope });
144
+ if (!result.ok)
145
+ return { ok: false, reason: result.reason, id: 'layout' };
146
+ saved.push('layout');
147
+ }
148
+ return { ok: true, saved };
149
+ }
150
+ /** The cookbook's first section page, respecting the owner's section order. */
151
+ function homePath(app) {
152
+ const shell = buildCookbookShell({
153
+ cookbook: app.cookbook,
154
+ catalog: app.catalog,
155
+ });
156
+ // The layout's own order may name custom sections, which are not suggestions.
157
+ const first = app.cookbook.layout?.sectionOrder?.[0] ?? shell.sections[0]?.id;
158
+ return first
159
+ ? shell.sectionPath(first).replace(/(.)\/$/, '$1')
160
+ : '/settings';
161
+ }
162
+ return { loadCookbook, saveCookbookEdits, homePath };
163
+ }
@@ -0,0 +1,283 @@
1
+ /** Documented local SvelteKit composition over the existing runtime and cookbook APIs. */
2
+ import { type SmrtSvelteKitRuntime, type SmrtSvelteKitRuntimeOptions } from '@happyvertical/smrt-app-runtime/sveltekit';
3
+ import { type MountAssistantRoutesOptions } from '@happyvertical/smrt-chat/sveltekit';
4
+ import { type ActivationCoordinator, type ActivationManifest } from '@happyvertical/smrt-core/activation';
5
+ import { type AppModelSnapshot } from '@happyvertical/smrt-core/app-models';
6
+ import { type CookbookToolOptions } from '@happyvertical/smrt-core/cookbook/tools';
7
+ import { type ChatGPTPlanConnection, createAgentCliService, type WorkProfileName } from '@happyvertical/smrt-inference/server';
8
+ import { type WorkProfilePreferences } from '@happyvertical/smrt-preferences';
9
+ import { type CookbookAppData } from '@happyvertical/smrt-svelte/cookbook/server';
10
+ import type { OnboardingState } from '@happyvertical/smrt-svelte/onboarding';
11
+ import type { Cookbook } from '@happyvertical/smrt-types';
12
+ import type { Handle, RequestEvent, ServerLoad } from '@sveltejs/kit';
13
+ import { type PluginModeState } from './plugin-mode.js';
14
+ export interface CookbookHostOptions {
15
+ runtime: SmrtSvelteKitRuntime;
16
+ packageName?: string;
17
+ application?: string;
18
+ activation?: () => ActivationCoordinator;
19
+ root?: string;
20
+ /** Inject a validated installed catalog/document in tests or generated hosts. */
21
+ app?: {
22
+ cookbook: Cookbook;
23
+ catalog: CookbookToolOptions['catalog'];
24
+ };
25
+ title?: string;
26
+ /** Opt-in first-run composition; owner sign-in remains runtime-owned. */
27
+ onboarding?: boolean;
28
+ assistant?: Pick<MountAssistantRoutesOptions, 'ai' | 'systemPrompt' | 'onError'>;
29
+ /** In-process test/host seams; inference still owns vendor discovery and credentials. */
30
+ cli?: ReturnType<typeof createAgentCliService>;
31
+ chatgpt?: ChatGPTPlanConnection;
32
+ }
33
+ /** Normal local runtime, with fixed-graph SQLite activation before owner bootstrap. */
34
+ export declare function createCookbookApplication(options: Omit<CookbookHostOptions, 'runtime' | 'activation' | 'packageName'> & {
35
+ packageName: string;
36
+ lazyActivation: {
37
+ manifest: ActivationManifest;
38
+ loaders: Record<string, () => Promise<unknown>>;
39
+ scope: string;
40
+ alwaysOn?: string[];
41
+ };
42
+ runtimeOptions?: Omit<SmrtSvelteKitRuntimeOptions, 'createSchema' | 'prepareDatabase'>;
43
+ }): {
44
+ runtime: SmrtSvelteKitRuntime;
45
+ handle: Handle;
46
+ init: () => Promise<void>;
47
+ shutdown: () => Promise<void>;
48
+ load: (event: Parameters<(event: {
49
+ readonly locals: unknown;
50
+ }) => import("@happyvertical/smrt-app-runtime/sveltekit").SessionLayoutData>[0]) => Promise<Awaited<ReturnType<(event: {
51
+ readonly locals: unknown;
52
+ }) => import("@happyvertical/smrt-app-runtime/sveltekit").SessionLayoutData>> & {
53
+ assistantToolCatalog: NonNullable<PluginModeState["tools"]>;
54
+ dynamicDefinitions: AppModelSnapshot["webDefinitions"];
55
+ enabledModels: string[];
56
+ cookbookApp: CookbookAppData;
57
+ onboarding: OnboardingState | null;
58
+ assistantIntroduction: {
59
+ lists: string[];
60
+ actions: string[];
61
+ configured: boolean;
62
+ } | undefined;
63
+ embed: boolean;
64
+ }>;
65
+ assistant: {
66
+ handle: (event: Parameters<import("@happyvertical/smrt-chat/sveltekit").AssistantRouteHandler>[0]) => Promise<Response>;
67
+ GET: import("@happyvertical/smrt-chat/sveltekit").AssistantRouteHandler;
68
+ POST: import("@happyvertical/smrt-chat/sveltekit").AssistantRouteHandler;
69
+ };
70
+ connectAi: {
71
+ GET(event: RequestEvent<Record<string, string>, string | null>): Promise<Response>;
72
+ POST(event: RequestEvent<Record<string, string>, string | null>): Promise<Response>;
73
+ };
74
+ pluginMode: (event: RequestEvent) => Promise<Response>;
75
+ inferenceSettings: import("@happyvertical/smrt-inference/server").InferenceSettingsController;
76
+ workProfiles: {
77
+ read(event: RequestEvent): Promise<{
78
+ resolved: {
79
+ unavailable: boolean;
80
+ name: WorkProfileName;
81
+ engine: import("@happyvertical/smrt-inference").InferenceEngineId;
82
+ model?: string;
83
+ effort: import("@happyvertical/smrt-inference").WorkReasoningEffort;
84
+ tier: "best" | "good" | "cheap";
85
+ budgets: import("@happyvertical/smrt-inference").WorkProfileBudgets;
86
+ autoEscalate: boolean;
87
+ previewBeforeApply: boolean;
88
+ modelSelection?: {
89
+ kind: "strongest" | "custom" | "configured" | "fallback";
90
+ requestedModel?: string;
91
+ resolvedModel?: string;
92
+ };
93
+ }[];
94
+ editable: boolean;
95
+ chatgptSignedIn: boolean;
96
+ settings: WorkProfilePreferences;
97
+ revision: string | null;
98
+ issues: import("@happyvertical/smrt-preferences").PreferenceIssue[];
99
+ }>;
100
+ write(event: RequestEvent, payload: {
101
+ settings: WorkProfilePreferences;
102
+ revision: string | null;
103
+ confirmUnprotectedCli?: boolean;
104
+ }): Promise<import("@happyvertical/smrt-preferences").PreferenceSaveResult>;
105
+ reset(event: RequestEvent, revision: string | null): Promise<import("@happyvertical/smrt-preferences").PreferenceResetResult>;
106
+ };
107
+ history(event: RequestEvent): Promise<Response>;
108
+ onboarding(event: RequestEvent): Promise<Response>;
109
+ modelEditor(tenantId: string): Promise<{
110
+ readonly application: string;
111
+ readonly supportsDurableOperations: boolean;
112
+ recover: (context: import("@happyvertical/smrt-core/app-models").AppModelEditContext) => Promise<import("@happyvertical/smrt-core/app-models").AppModelChange | null>;
113
+ readonly database: import("@happyvertical/sql").DatabaseInterface;
114
+ apply: (edit: import("@happyvertical/smrt-core/app-models").AppModelEdit, context: import("@happyvertical/smrt-core/app-models").AppModelEditContext) => Promise<import("@happyvertical/smrt-core/app-models").AppModelEditReceipt>;
115
+ snapshot: () => AppModelSnapshot;
116
+ export: () => string;
117
+ history: () => Promise<import("@happyvertical/smrt-core/app-models").AppModelChange[]>;
118
+ subscribe(listener: (snapshot: AppModelSnapshot) => void): () => void;
119
+ } | undefined>;
120
+ ownerLink: import("@sveltejs/kit").RequestHandler;
121
+ /** Request-scoped: never pass a browser tenant id or retain this across requests. */
122
+ cookbookApp(tenantId: string): Promise<{
123
+ cookbook: {
124
+ recipes: string[];
125
+ features: string[];
126
+ $schema: string;
127
+ version: 1;
128
+ name?: string;
129
+ description?: string;
130
+ specs?: string;
131
+ policies: import("@happyvertical/smrt-types").CookbookPolicyRow[];
132
+ models?: import("@happyvertical/smrt-types").CookbookModels;
133
+ exposure?: Record<string, import("@happyvertical/smrt-types").CookbookExposureSurface[]>;
134
+ layout?: import("@happyvertical/smrt-types").CookbookLayout;
135
+ theme?: import("@happyvertical/smrt-types").CookbookTheme;
136
+ overviews?: Record<string, import("@happyvertical/smrt-types").CookbookOverviewOverride>;
137
+ };
138
+ catalog: {
139
+ models: readonly import("@happyvertical/smrt-core/cookbook/engine").EngineModel[];
140
+ cookbooks?: readonly import("@happyvertical/smrt-core/cookbook/engine").EngineLibraryCookbook[] | undefined;
141
+ placementItems?: readonly string[] | undefined;
142
+ themePresets?: readonly string[] | undefined;
143
+ currencies?: readonly string[] | undefined;
144
+ settingTargets?: import("@happyvertical/smrt-core/cookbook/engine").SettingTargets | undefined;
145
+ recipes: readonly import("@happyvertical/smrt-core/cookbook/tools").CookbookToolRecipe[];
146
+ };
147
+ warnings: never[];
148
+ }>;
149
+ prebuilt(event: RequestEvent): Promise<Response>;
150
+ mcp(event: RequestEvent): Promise<Response>;
151
+ dispose(): void;
152
+ };
153
+ /** One local owner host per process. Construct before runtime.init seeds permissions. */
154
+ export declare function createCookbookHost(options: CookbookHostOptions): {
155
+ runtime: SmrtSvelteKitRuntime;
156
+ handle: Handle;
157
+ init: () => Promise<void>;
158
+ shutdown: () => Promise<void>;
159
+ load: (event: Parameters<(event: {
160
+ readonly locals: unknown;
161
+ }) => import("@happyvertical/smrt-app-runtime/sveltekit").SessionLayoutData>[0]) => Promise<Awaited<ReturnType<(event: {
162
+ readonly locals: unknown;
163
+ }) => import("@happyvertical/smrt-app-runtime/sveltekit").SessionLayoutData>> & {
164
+ assistantToolCatalog: NonNullable<PluginModeState["tools"]>;
165
+ dynamicDefinitions: AppModelSnapshot["webDefinitions"];
166
+ enabledModels: string[];
167
+ cookbookApp: CookbookAppData;
168
+ onboarding: OnboardingState | null;
169
+ assistantIntroduction: {
170
+ lists: string[];
171
+ actions: string[];
172
+ configured: boolean;
173
+ } | undefined;
174
+ embed: boolean;
175
+ }>;
176
+ assistant: {
177
+ handle: (event: Parameters<import("@happyvertical/smrt-chat/sveltekit").AssistantRouteHandler>[0]) => Promise<Response>;
178
+ GET: import("@happyvertical/smrt-chat/sveltekit").AssistantRouteHandler;
179
+ POST: import("@happyvertical/smrt-chat/sveltekit").AssistantRouteHandler;
180
+ };
181
+ connectAi: {
182
+ GET(event: RequestEvent<Record<string, string>, string | null>): Promise<Response>;
183
+ POST(event: RequestEvent<Record<string, string>, string | null>): Promise<Response>;
184
+ };
185
+ pluginMode: (event: RequestEvent) => Promise<Response>;
186
+ inferenceSettings: import("@happyvertical/smrt-inference/server").InferenceSettingsController;
187
+ workProfiles: {
188
+ read(event: RequestEvent): Promise<{
189
+ resolved: {
190
+ unavailable: boolean;
191
+ name: WorkProfileName;
192
+ engine: import("@happyvertical/smrt-inference").InferenceEngineId;
193
+ model?: string;
194
+ effort: import("@happyvertical/smrt-inference").WorkReasoningEffort;
195
+ tier: "best" | "good" | "cheap";
196
+ budgets: import("@happyvertical/smrt-inference").WorkProfileBudgets;
197
+ autoEscalate: boolean;
198
+ previewBeforeApply: boolean;
199
+ modelSelection?: {
200
+ kind: "strongest" | "custom" | "configured" | "fallback";
201
+ requestedModel?: string;
202
+ resolvedModel?: string;
203
+ };
204
+ }[];
205
+ editable: boolean;
206
+ chatgptSignedIn: boolean;
207
+ settings: WorkProfilePreferences;
208
+ revision: string | null;
209
+ issues: import("@happyvertical/smrt-preferences").PreferenceIssue[];
210
+ }>;
211
+ write(event: RequestEvent, payload: {
212
+ settings: WorkProfilePreferences;
213
+ revision: string | null;
214
+ confirmUnprotectedCli?: boolean;
215
+ }): Promise<import("@happyvertical/smrt-preferences").PreferenceSaveResult>;
216
+ reset(event: RequestEvent, revision: string | null): Promise<import("@happyvertical/smrt-preferences").PreferenceResetResult>;
217
+ };
218
+ history(event: RequestEvent): Promise<Response>;
219
+ onboarding(event: RequestEvent): Promise<Response>;
220
+ modelEditor(tenantId: string): Promise<{
221
+ readonly application: string;
222
+ readonly supportsDurableOperations: boolean;
223
+ recover: (context: import("@happyvertical/smrt-core/app-models").AppModelEditContext) => Promise<import("@happyvertical/smrt-core/app-models").AppModelChange | null>;
224
+ readonly database: import("@happyvertical/sql").DatabaseInterface;
225
+ apply: (edit: import("@happyvertical/smrt-core/app-models").AppModelEdit, context: import("@happyvertical/smrt-core/app-models").AppModelEditContext) => Promise<import("@happyvertical/smrt-core/app-models").AppModelEditReceipt>;
226
+ snapshot: () => AppModelSnapshot;
227
+ export: () => string;
228
+ history: () => Promise<import("@happyvertical/smrt-core/app-models").AppModelChange[]>;
229
+ subscribe(listener: (snapshot: AppModelSnapshot) => void): () => void;
230
+ } | undefined>;
231
+ ownerLink: import("@sveltejs/kit").RequestHandler;
232
+ /** Request-scoped: never pass a browser tenant id or retain this across requests. */
233
+ cookbookApp(tenantId: string): Promise<{
234
+ cookbook: {
235
+ recipes: string[];
236
+ features: string[];
237
+ $schema: string;
238
+ version: 1;
239
+ name?: string;
240
+ description?: string;
241
+ specs?: string;
242
+ policies: import("@happyvertical/smrt-types").CookbookPolicyRow[];
243
+ models?: import("@happyvertical/smrt-types").CookbookModels;
244
+ exposure?: Record<string, import("@happyvertical/smrt-types").CookbookExposureSurface[]>;
245
+ layout?: import("@happyvertical/smrt-types").CookbookLayout;
246
+ theme?: import("@happyvertical/smrt-types").CookbookTheme;
247
+ overviews?: Record<string, import("@happyvertical/smrt-types").CookbookOverviewOverride>;
248
+ };
249
+ catalog: {
250
+ models: readonly import("@happyvertical/smrt-core/cookbook/engine").EngineModel[];
251
+ cookbooks?: readonly import("@happyvertical/smrt-core/cookbook/engine").EngineLibraryCookbook[] | undefined;
252
+ placementItems?: readonly string[] | undefined;
253
+ themePresets?: readonly string[] | undefined;
254
+ currencies?: readonly string[] | undefined;
255
+ settingTargets?: import("@happyvertical/smrt-core/cookbook/engine").SettingTargets | undefined;
256
+ recipes: readonly import("@happyvertical/smrt-core/cookbook/tools").CookbookToolRecipe[];
257
+ };
258
+ warnings: never[];
259
+ }>;
260
+ prebuilt(event: RequestEvent): Promise<Response>;
261
+ mcp(event: RequestEvent): Promise<Response>;
262
+ dispose(): void;
263
+ };
264
+ /** Mount the ordinary cookbook model page with the live session gate. */
265
+ export declare function loadCookbookModelPage({ params, parent, locals, url, }: Parameters<ServerLoad>[0]): Promise<{
266
+ recordId: string | null;
267
+ referenceHrefs: {
268
+ [k: string]: string;
269
+ };
270
+ entry: {
271
+ id: string;
272
+ label: string;
273
+ description: string;
274
+ noun: string | null;
275
+ filter: {
276
+ field: string;
277
+ value: string;
278
+ } | null;
279
+ model: string;
280
+ className: string;
281
+ };
282
+ permissions: string[];
283
+ }>;