@happyvertical/smrt-template-sveltekit 0.60.18 → 0.61.1

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,49 @@
1
+ <script lang="ts">
2
+ import {
3
+ createAssistantHttpTransport,
4
+ } from '@happyvertical/smrt-chat/svelte';
5
+ import { ShellSettingsPage } from '@happyvertical/smrt-svelte/app';
6
+ import {
7
+ ConnectAi,
8
+ createConnectAiClient,
9
+ } from '@happyvertical/smrt-svelte/connect-ai';
10
+ import { OwnerApprovalsSettings } from '@happyvertical/smrt-svelte/settings';
11
+ import { signOut } from '@happyvertical/smrt-template-sveltekit/host/sveltekit-client';
12
+ import { Toggle } from '@happyvertical/smrt-ui/forms';
13
+ import { defineMessages, useI18n } from '@happyvertical/smrt-ui/i18n';
14
+ import { Button } from '@happyvertical/smrt-ui/ui';
15
+ import { invalidateAll } from '$app/navigation';
16
+ import type { PageProps } from './$types';
17
+
18
+ let { data }: PageProps = $props();
19
+ const M = defineMessages({
20
+ 'cookbook.settings.template': 'Start over from a template',
21
+ });
22
+ const { t } = useI18n();
23
+ const client = createConnectAiClient({ endpoint: '/api/connect-ai' });
24
+ let busy = $state(false);
25
+ let message = $state('');
26
+ const transport = createAssistantHttpTransport({ endpoint: '/api/assistant' });
27
+ </script>
28
+
29
+ <svelte:head>
30
+ <title>Settings · My app</title>
31
+ </svelte:head>
32
+
33
+ <!-- Appearance, account, and layout; preferences persist through the shell storageKey. -->
34
+ <ShellSettingsPage onSignOut={signOut}>
35
+ <OwnerApprovalsSettings approvals={data.approvals} {transport} ondecided={invalidateAll} onsettled={invalidateAll} />
36
+ <Button href="/onboarding?restart=1">{t(M['cookbook.settings.template'])}</Button>
37
+ <ConnectAi {client} variant="settings" apiKeyHref="/settings/inference" />
38
+ <Toggle label="Pre-built components" checked={data.prebuilt.enabled} disabled={busy} onchange={async enabled => {
39
+ busy = true;
40
+ message = '';
41
+ try {
42
+ const response = await fetch('/api/cookbook/prebuilt', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ enabled, revision: data.prebuilt.revision }) });
43
+ if (!response.ok) throw new Error('The setting could not be saved.');
44
+ await invalidateAll();
45
+ } catch { message = 'The setting could not be saved. Refresh and try again.'; }
46
+ finally { busy = false; }
47
+ }} />
48
+ {#if message}<p role="alert">{message}</p>{/if}
49
+ </ShellSettingsPage>
@@ -0,0 +1,6 @@
1
+ import { createInferenceSettingsPage } from '@happyvertical/smrt-template-sveltekit/host/settings';
2
+ import { host } from '$lib/server/smrt';
3
+ export const { load, actions } = createInferenceSettingsPage(
4
+ host.inferenceSettings,
5
+ host.workProfiles,
6
+ );
@@ -0,0 +1,14 @@
1
+ <script lang="ts">
2
+ import InferenceSettingsPage from '@happyvertical/smrt-template-sveltekit/host/InferenceSettingsPage.svelte';
3
+ import { defineMessages, useI18n } from '@happyvertical/smrt-ui/i18n';
4
+ import { Button } from '@happyvertical/smrt-ui/ui';
5
+ import { page } from '$app/state';
6
+ import type { PageProps } from './$types';
7
+
8
+ const M = defineMessages({ 'cookbook.onboarding.return': 'Back to setup' });
9
+ const { t } = useI18n();
10
+ let { data }: PageProps = $props();
11
+ </script>
12
+ <InferenceSettingsPage {data} />
13
+
14
+ {#if (data.onboarding && !data.onboarding.completed) || page.url.searchParams.get('returnTo') === 'onboarding'}<Button href="/onboarding">{t(M['cookbook.onboarding.return'])}</Button>{/if}
@@ -0,0 +1,4 @@
1
+ import { sveltekit } from '@sveltejs/kit/vite';
2
+ import { cookbookHostVite } from '@happyvertical/smrt-template-sveltekit/host/generate';
3
+ import { defineConfig, type UserConfig } from 'vite';
4
+ export default defineConfig(async (): Promise<UserConfig> => ({ plugins: [...await sveltekit(), ...await cookbookHostVite()] }));
@@ -0,0 +1,8 @@
1
+ import type { CookbookAppProps } from '@happyvertical/smrt-svelte/cookbook';
2
+ /** One registry shared by CookbookApp's Provider, mounted screens and assistant. */
3
+ export declare function createCookbookAssistant(options?: {
4
+ endpoint?: string;
5
+ label?: string;
6
+ introduction?: NonNullable<CookbookAppProps['assistant']>['introduction'];
7
+ onchange?: () => void | Promise<void>;
8
+ }): NonNullable<CookbookAppProps['assistant']>;
@@ -0,0 +1,66 @@
1
+ /** Browser half of the cookbook host. No SvelteKit globals or server imports. */
2
+ import { reconcileAssistantApprovalView, } from '@happyvertical/smrt-chat/assistant-turn';
3
+ import { createAssistantHttpTransport } from '@happyvertical/smrt-chat/svelte';
4
+ import { OnboardingAssistant } from '@happyvertical/smrt-svelte/onboarding';
5
+ import { createDataSurfaceRegistry } from '@happyvertical/smrt-ui/data-surface';
6
+ /** One registry shared by CookbookApp's Provider, mounted screens and assistant. */
7
+ export function createCookbookAssistant(options = {}) {
8
+ const transport = createAssistantHttpTransport({
9
+ endpoint: options.endpoint ?? '/api/assistant',
10
+ designRuns: true,
11
+ });
12
+ // Observe the existing authorized card polls; historical terminal rows are inert.
13
+ // Retain terminal observations so overlapping/stale requests cannot re-arm them.
14
+ const approvals = new Map();
15
+ const observeApprovals = async (rows, notify = true) => {
16
+ for (const row of rows) {
17
+ const previous = approvals.get(row.id);
18
+ const next = reconcileAssistantApprovalView(previous, row);
19
+ approvals.set(row.id, next);
20
+ if (previous &&
21
+ previous.status !== 'succeeded' &&
22
+ next.status === 'succeeded' &&
23
+ notify)
24
+ await options.onchange?.();
25
+ }
26
+ };
27
+ const refresh = async (work) => {
28
+ const result = await work;
29
+ await options.onchange?.();
30
+ return result;
31
+ };
32
+ return {
33
+ component: OnboardingAssistant,
34
+ toolPresentation: 'generic',
35
+ transport: {
36
+ ...transport,
37
+ sendMessage: (input) => refresh(transport.sendMessage(input)),
38
+ ...(transport.resumeTurn
39
+ ? { resumeTurn: (input) => refresh(transport.resumeTurn(input)) }
40
+ : {}),
41
+ ...(transport.listApprovals
42
+ ? {
43
+ listApprovals: async (threadId) => {
44
+ const rows = await transport.listApprovals(threadId);
45
+ await observeApprovals(rows);
46
+ return rows;
47
+ },
48
+ }
49
+ : {}),
50
+ ...(transport.decideApproval
51
+ ? {
52
+ decideApproval: (id, approve) => refresh((async () => {
53
+ const next = await transport.decideApproval(id, approve);
54
+ // The existing decision refresh covers immediate completion.
55
+ // An approved response still needs its later terminal poll.
56
+ await observeApprovals([next], false);
57
+ return next;
58
+ })()),
59
+ }
60
+ : {}),
61
+ },
62
+ registry: createDataSurfaceRegistry(),
63
+ introduction: options.introduction,
64
+ ...(options.label ? { label: options.label } : {}),
65
+ };
66
+ }
@@ -0,0 +1,72 @@
1
+ import type { CookbookToolDefinition, CookbookToolName, CookbookToolResult } from '@happyvertical/smrt-core/cookbook/tools';
2
+ import { type DesignPassRequest, type DesignPassResult, type DesignRunBudget, type DesignRunProgress, type DesignRunState, type ResolvedWorkProfile } from '@happyvertical/smrt-inference/server';
3
+ import type { DatabaseInterface } from '@happyvertical/sql';
4
+ /** Host callbacks retain the normal authenticated assistant dispatcher and approvals. */
5
+ export interface CookbookDesignRunsOptions {
6
+ db: DatabaseInterface;
7
+ authorize(ownerId: string, tenantId: string | null): Promise<void>;
8
+ authorizeThread?(ownerId: string, tenantId: string | null, threadId: string): Promise<void>;
9
+ currentRevision?(ownerId: string, tenantId: string | null): Promise<number>;
10
+ /** Normal app.describe read; its pinned catalog only classifies work, never authorizes it. */
11
+ describeApp?(ownerId: string, tenantId: string | null): Promise<CookbookToolResult | undefined>;
12
+ executeOperation?(input: {
13
+ ownerId: string;
14
+ tenantId: string | null;
15
+ threadId: string;
16
+ runId: string;
17
+ actionId: string;
18
+ permissions: readonly string[];
19
+ operation: {
20
+ tool: CookbookToolName;
21
+ args: Record<string, unknown>;
22
+ };
23
+ signal: AbortSignal;
24
+ }): Promise<CookbookToolResult>;
25
+ /** Current core-owned structural schemas, resolved under the live owner. */
26
+ listOperations?(ownerId: string, tenantId: string | null): Promise<readonly Pick<CookbookToolDefinition, 'name' | 'inputSchema' | 'description'>[]>;
27
+ executePass(input: {
28
+ ownerId: string;
29
+ tenantId: string | null;
30
+ threadId: string;
31
+ content: string;
32
+ stage: 'profile' | 'propose' | 'revise';
33
+ request: DesignPassRequest;
34
+ profile: ResolvedWorkProfile;
35
+ permissions: readonly string[];
36
+ }): Promise<DesignPassResult>;
37
+ readResource?(ownerId: string, tenantId: string | null, resourceId: string, cursor: string | undefined, maxChars: number): Promise<{
38
+ data: unknown;
39
+ nextCursor?: string;
40
+ }>;
41
+ onProgress?(event: DesignRunProgress): void | Promise<void>;
42
+ }
43
+ /** The actual checked proposal, including a v5 first-pass proposal, owns Apply. */
44
+ export declare function isCookbookDesignFinalCheck(state: Readonly<DesignRunState>): boolean;
45
+ /** Public progress is host-owned; model prose and raw checkpoint notes stay private. */
46
+ export declare function presentCookbookDesignProgress(event: DesignRunProgress, state?: Readonly<DesignRunState>): DesignRunProgress;
47
+ /**
48
+ * Concrete cookbook workflow on inference checkpoints and the existing jobs queue.
49
+ * Construct once per database before starting its TaskRunner. Browser requests only
50
+ * admit jobs; model calls occur exclusively through the registered job target.
51
+ */
52
+ export declare function createCookbookDesignRuns(options: CookbookDesignRunsOptions): {
53
+ dispose: () => void;
54
+ forOwner(ownerId: string, tenantId: string | null): {
55
+ start(input: {
56
+ threadId: string;
57
+ content: string;
58
+ profile: ResolvedWorkProfile;
59
+ resourceIds?: string[];
60
+ /** Captured authenticated permission ceiling; never model supplied. */
61
+ permissions?: readonly string[];
62
+ /** Presence of a raw owner pass override, supplied only by the host. */
63
+ fixedPasses?: boolean;
64
+ }): Promise<DesignRunState>;
65
+ latest(threadId: string): Promise<DesignRunState | null>;
66
+ status(id: string): Promise<DesignRunState>;
67
+ validateAction(id: string, actionId: string, tool: string, args: Record<string, unknown>): Promise<void>;
68
+ stop(id: string): Promise<DesignRunState>;
69
+ resume(id: string, budget?: Partial<DesignRunBudget>): Promise<DesignRunState>;
70
+ resumeAfterApproval(id: string): Promise<DesignRunState>;
71
+ };
72
+ };