@happyvertical/smrt-svelte 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.
- package/AGENTS.md +6 -0
- package/agents/components.md +15 -0
- package/agents/connect-ai.md +180 -0
- package/agents/cookbook-shell.md +173 -6
- package/agents/import-export.md +10 -0
- package/agents/screens.md +233 -12
- package/agents/settings.md +84 -0
- package/agents/testing.md +6 -0
- package/agents/workspace.md +64 -1
- package/dist/components/app/AppShell.svelte +220 -7
- package/dist/components/app/AppShell.svelte.d.ts +49 -3
- package/dist/components/app/AppShell.svelte.d.ts.map +1 -1
- package/dist/components/app/OwnerSetupForm.svelte +5 -3
- package/dist/components/app/OwnerSetupForm.svelte.d.ts.map +1 -1
- package/dist/components/app/PhoneTabBar.svelte +28 -1
- package/dist/components/app/PhoneTabBar.svelte.d.ts +10 -0
- package/dist/components/app/PhoneTabBar.svelte.d.ts.map +1 -1
- package/dist/components/app/ShellAccountMenu.svelte +46 -0
- package/dist/components/app/ShellAccountMenu.svelte.d.ts +13 -0
- package/dist/components/app/ShellAccountMenu.svelte.d.ts.map +1 -0
- package/dist/components/app/ShellSettingsPage.svelte +119 -4
- package/dist/components/app/ShellSettingsPage.svelte.d.ts +18 -0
- package/dist/components/app/ShellSettingsPage.svelte.d.ts.map +1 -1
- package/dist/components/app/index.d.ts +3 -2
- package/dist/components/app/index.d.ts.map +1 -1
- package/dist/components/app/index.js +1 -1
- package/dist/components/app/owner-setup-types.d.ts +1 -0
- package/dist/components/app/owner-setup-types.d.ts.map +1 -1
- package/dist/components/app/settings-menu-item.d.ts +8 -0
- package/dist/components/app/settings-menu-item.d.ts.map +1 -0
- package/dist/components/app/settings-menu-item.js +1 -0
- package/dist/components/app/slot-item.d.ts +53 -0
- package/dist/components/app/slot-item.d.ts.map +1 -1
- package/dist/components/audit/RecordHistory.svelte +30 -22
- package/dist/components/audit/RecordHistory.svelte.d.ts +31 -10
- package/dist/components/audit/RecordHistory.svelte.d.ts.map +1 -1
- package/dist/components/audit/index.d.ts +1 -1
- package/dist/components/audit/index.d.ts.map +1 -1
- package/dist/components/audit/types.d.ts +12 -6
- package/dist/components/audit/types.d.ts.map +1 -1
- package/dist/components/connect-ai/ConnectAi.svelte +584 -0
- package/dist/components/connect-ai/ConnectAi.svelte.d.ts +23 -0
- package/dist/components/connect-ai/ConnectAi.svelte.d.ts.map +1 -0
- package/dist/components/connect-ai/client.d.ts +68 -0
- package/dist/components/connect-ai/client.d.ts.map +1 -0
- package/dist/components/connect-ai/client.js +121 -0
- package/dist/components/connect-ai/index.d.ts +4 -0
- package/dist/components/connect-ai/index.d.ts.map +1 -0
- package/dist/components/connect-ai/index.js +2 -0
- package/dist/components/connect-ai/server.d.ts +33 -0
- package/dist/components/connect-ai/server.d.ts.map +1 -0
- package/dist/components/connect-ai/server.js +190 -0
- package/dist/components/connect-ai/types.d.ts +48 -0
- package/dist/components/connect-ai/types.d.ts.map +1 -0
- package/dist/components/connect-ai/types.js +1 -0
- package/dist/components/cookbook/CookbookApp.svelte +84 -5
- package/dist/components/cookbook/CookbookApp.svelte.d.ts +1 -1
- package/dist/components/cookbook/CookbookApp.svelte.d.ts.map +1 -1
- package/dist/components/cookbook/app-props.d.ts +65 -0
- package/dist/components/cookbook/app-props.d.ts.map +1 -0
- package/dist/components/cookbook/app-props.js +1 -0
- package/dist/components/cookbook/build.d.ts +3 -0
- package/dist/components/cookbook/build.d.ts.map +1 -1
- package/dist/components/cookbook/build.js +92 -8
- package/dist/components/cookbook/catalog.d.ts +2 -1
- package/dist/components/cookbook/catalog.d.ts.map +1 -1
- package/dist/components/cookbook/catalog.js +5 -2
- package/dist/components/cookbook/context.d.ts +6 -0
- package/dist/components/cookbook/context.d.ts.map +1 -1
- package/dist/components/cookbook/index.d.ts +2 -1
- package/dist/components/cookbook/index.d.ts.map +1 -1
- package/dist/components/cookbook/index.js +1 -1
- package/dist/components/cookbook/registry.d.ts +3 -0
- package/dist/components/cookbook/registry.d.ts.map +1 -1
- package/dist/components/cookbook/registry.js +5 -0
- package/dist/components/cookbook/server.d.ts +1 -0
- package/dist/components/cookbook/server.d.ts.map +1 -1
- package/dist/components/cookbook/surfaces.d.ts +14 -0
- package/dist/components/cookbook/surfaces.d.ts.map +1 -0
- package/dist/components/cookbook/surfaces.js +6 -0
- package/dist/components/cookbook/types.d.ts +0 -28
- package/dist/components/cookbook/types.d.ts.map +1 -1
- package/dist/components/import-export/ImportExport.svelte +21 -2
- package/dist/components/import-export/ImportExport.svelte.d.ts.map +1 -1
- package/dist/components/import-export/fields.d.ts +1 -0
- package/dist/components/import-export/fields.d.ts.map +1 -1
- package/dist/components/import-export/fields.js +8 -3
- package/dist/components/import-export/props.d.ts +5 -1
- package/dist/components/import-export/props.d.ts.map +1 -1
- package/dist/components/onboarding/FirstRunOnboarding.svelte +249 -0
- package/dist/components/onboarding/FirstRunOnboarding.svelte.d.ts +21 -0
- package/dist/components/onboarding/FirstRunOnboarding.svelte.d.ts.map +1 -0
- package/dist/components/onboarding/OnboardingAssistant.svelte +82 -0
- package/dist/components/onboarding/OnboardingAssistant.svelte.d.ts +19 -0
- package/dist/components/onboarding/OnboardingAssistant.svelte.d.ts.map +1 -0
- package/dist/components/onboarding/client.d.ts +7 -0
- package/dist/components/onboarding/client.d.ts.map +1 -0
- package/dist/components/onboarding/client.js +26 -0
- package/dist/components/onboarding/index.d.ts +5 -0
- package/dist/components/onboarding/index.d.ts.map +1 -0
- package/dist/components/onboarding/index.js +3 -0
- package/dist/components/onboarding/types.d.ts +38 -0
- package/dist/components/onboarding/types.d.ts.map +1 -0
- package/dist/components/onboarding/types.js +1 -0
- package/dist/components/overview/recipe-widgets.d.ts +2 -18
- package/dist/components/overview/recipe-widgets.d.ts.map +1 -1
- package/dist/components/overview/recipe-widgets.js +14 -14
- package/dist/components/screens/DetailScreen.svelte +40 -16
- package/dist/components/screens/DetailScreen.svelte.d.ts.map +1 -1
- package/dist/components/screens/EditForm.svelte +83 -18
- package/dist/components/screens/EditForm.svelte.d.ts.map +1 -1
- package/dist/components/screens/ListScreen.svelte +35 -9
- package/dist/components/screens/ListScreen.svelte.d.ts.map +1 -1
- package/dist/components/screens/RecipeScreens.svelte +78 -6
- package/dist/components/screens/RecipeScreens.svelte.d.ts +2 -1
- package/dist/components/screens/RecipeScreens.svelte.d.ts.map +1 -1
- package/dist/components/screens/RecordHeader.svelte +18 -4
- package/dist/components/screens/RecordHeader.svelte.d.ts +2 -1
- package/dist/components/screens/RecordHeader.svelte.d.ts.map +1 -1
- package/dist/components/screens/RecordScreen.svelte +22 -3
- package/dist/components/screens/RecordScreen.svelte.d.ts.map +1 -1
- package/dist/components/screens/ReferencePicker.svelte +103 -0
- package/dist/components/screens/ReferencePicker.svelte.d.ts +12 -0
- package/dist/components/screens/ReferencePicker.svelte.d.ts.map +1 -0
- package/dist/components/screens/fields.d.ts +6 -14
- package/dist/components/screens/fields.d.ts.map +1 -1
- package/dist/components/screens/fields.js +67 -10
- package/dist/components/screens/index.d.ts +3 -1
- package/dist/components/screens/index.d.ts.map +1 -1
- package/dist/components/screens/index.js +2 -0
- package/dist/components/screens/reference-labels.svelte.d.ts +11 -0
- package/dist/components/screens/reference-labels.svelte.d.ts.map +1 -0
- package/dist/components/screens/reference-labels.svelte.js +50 -0
- package/dist/components/screens/references.d.ts +6 -0
- package/dist/components/screens/references.d.ts.map +1 -0
- package/dist/components/screens/references.js +26 -0
- package/dist/components/screens/relations.d.ts +3 -1
- package/dist/components/screens/relations.d.ts.map +1 -1
- package/dist/components/screens/relations.js +4 -3
- package/dist/components/screens/roles.d.ts.map +1 -1
- package/dist/components/screens/roles.js +3 -2
- package/dist/components/screens/source.d.ts +37 -0
- package/dist/components/screens/source.d.ts.map +1 -0
- package/dist/components/screens/source.js +96 -0
- package/dist/components/screens/types.d.ts +63 -2
- package/dist/components/screens/types.d.ts.map +1 -1
- package/dist/components/screens/values.d.ts.map +1 -1
- package/dist/components/screens/values.js +5 -0
- package/dist/components/settings/OwnerApprovalsSettings.svelte +169 -0
- package/dist/components/settings/OwnerApprovalsSettings.svelte.d.ts +13 -0
- package/dist/components/settings/OwnerApprovalsSettings.svelte.d.ts.map +1 -0
- package/dist/components/settings/PrebuiltComponentsSettings.svelte +83 -0
- package/dist/components/settings/PrebuiltComponentsSettings.svelte.d.ts +14 -0
- package/dist/components/settings/PrebuiltComponentsSettings.svelte.d.ts.map +1 -0
- package/dist/components/settings/WorkProfileSettings.svelte +250 -0
- package/dist/components/settings/WorkProfileSettings.svelte.d.ts +22 -0
- package/dist/components/settings/WorkProfileSettings.svelte.d.ts.map +1 -0
- package/dist/components/settings/index.d.ts +3 -0
- package/dist/components/settings/index.d.ts.map +1 -1
- package/dist/components/settings/index.js +3 -0
- package/dist/components/workspace/admin-shell/AdminShell.svelte +186 -18
- package/dist/components/workspace/admin-shell/AdminShell.svelte.d.ts +26 -1
- package/dist/components/workspace/admin-shell/AdminShell.svelte.d.ts.map +1 -1
- package/dist/components/workspace/admin-shell/ShellSettingsPanel.svelte +18 -3
- package/dist/components/workspace/admin-shell/ShellSettingsPanel.svelte.d.ts +6 -0
- package/dist/components/workspace/admin-shell/ShellSettingsPanel.svelte.d.ts.map +1 -1
- package/dist/components/workspace/admin-shell/WorkspaceAccountMenu.svelte +89 -5
- package/dist/components/workspace/admin-shell/WorkspaceAccountMenu.svelte.d.ts +7 -1
- package/dist/components/workspace/admin-shell/WorkspaceAccountMenu.svelte.d.ts.map +1 -1
- package/dist/components/workspace/admin-shell/layout.d.ts +4 -0
- package/dist/components/workspace/admin-shell/layout.d.ts.map +1 -1
- package/dist/components/workspace/admin-shell/layout.js +17 -4
- package/dist/components/workspace/admin-shell/settings-delta.d.ts.map +1 -1
- package/dist/components/workspace/admin-shell/settings-delta.js +4 -3
- package/dist/components/workspace/admin-shell/settings-sections.d.ts +10 -0
- package/dist/components/workspace/admin-shell/settings-sections.d.ts.map +1 -0
- package/dist/components/workspace/admin-shell/settings-sections.js +16 -0
- package/dist/components/workspace/admin-shell/settings.d.ts +7 -0
- package/dist/components/workspace/admin-shell/settings.d.ts.map +1 -1
- package/dist/components/workspace/admin-shell/settings.js +26 -0
- package/dist/components/workspace/admin-shell/shell-icons.d.ts +4 -0
- package/dist/components/workspace/admin-shell/shell-icons.d.ts.map +1 -1
- package/dist/components/workspace/admin-shell/shell-icons.js +4 -0
- package/dist/components/workspace/admin-shell/state.svelte.d.ts +13 -5
- package/dist/components/workspace/admin-shell/state.svelte.d.ts.map +1 -1
- package/dist/components/workspace/admin-shell/state.svelte.js +37 -2
- package/dist/components/workspace/admin-shell/types.d.ts +32 -1
- package/dist/components/workspace/admin-shell/types.d.ts.map +1 -1
- package/dist/components/workspace/index.d.ts +3 -2
- package/dist/components/workspace/index.d.ts.map +1 -1
- package/dist/components/workspace/index.js +2 -1
- package/dist/i18n/server.d.ts +2 -0
- package/dist/i18n/server.d.ts.map +1 -1
- package/dist/i18n/server.js +2 -0
- package/dist/i18n/strings.connect-ai.d.ts +57 -0
- package/dist/i18n/strings.connect-ai.d.ts.map +1 -0
- package/dist/i18n/strings.connect-ai.js +57 -0
- package/dist/i18n/strings.onboarding.d.ts +51 -0
- package/dist/i18n/strings.onboarding.d.ts.map +1 -0
- package/dist/i18n/strings.onboarding.js +51 -0
- package/dist/i18n/strings.screens.d.ts +12 -0
- package/dist/i18n/strings.screens.d.ts.map +1 -1
- package/dist/i18n/strings.screens.js +13 -1
- package/dist/i18n/strings.settings.d.ts +2 -0
- package/dist/i18n/strings.settings.d.ts.map +1 -1
- package/dist/i18n/strings.settings.js +2 -0
- package/dist/i18n/strings.workspace.d.ts +14 -0
- package/dist/i18n/strings.workspace.d.ts.map +1 -1
- package/dist/i18n/strings.workspace.js +15 -1
- package/dist/smrt-knowledge.okf.md +21 -10
- package/package.json +46 -17
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** Same-origin JSON transport for mountConnectAiRoutes. It never exposes server error text. */
|
|
2
|
+
export function createConnectAiClient(options) {
|
|
3
|
+
if (!/^\/(?!\/)[^?#]*$/.test(options.endpoint))
|
|
4
|
+
throw new Error('Connect AI requires a same-origin route path.');
|
|
5
|
+
const doFetch = options.fetch ?? fetch;
|
|
6
|
+
const call = async (body, signal) => {
|
|
7
|
+
const response = await doFetch(options.endpoint, {
|
|
8
|
+
method: body ? 'POST' : 'GET',
|
|
9
|
+
credentials: 'same-origin',
|
|
10
|
+
cache: 'no-store',
|
|
11
|
+
signal,
|
|
12
|
+
...(body
|
|
13
|
+
? {
|
|
14
|
+
headers: { 'content-type': 'application/json' },
|
|
15
|
+
body: JSON.stringify(body),
|
|
16
|
+
}
|
|
17
|
+
: {}),
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
const detail = await response.json().catch(() => null);
|
|
21
|
+
throw Object.assign(new Error('Connect AI request failed.'), detail?.code === 'chatgpt_cancel_unavailable'
|
|
22
|
+
? { code: 'chatgpt_cancel_unavailable' }
|
|
23
|
+
: {});
|
|
24
|
+
}
|
|
25
|
+
return response.json();
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
state: (signal) => call(undefined, signal),
|
|
29
|
+
connect: async (tool, signal) => {
|
|
30
|
+
await call({ action: 'connect', tool }, signal);
|
|
31
|
+
},
|
|
32
|
+
choose: async (engine, signal) => {
|
|
33
|
+
await call({ action: 'select', engine }, signal);
|
|
34
|
+
},
|
|
35
|
+
startChatGPT: (signal) => call({ action: 'chatgpt-start' }, signal),
|
|
36
|
+
cancelChatGPT: async (signal) => {
|
|
37
|
+
await call({ action: 'chatgpt-cancel' }, signal);
|
|
38
|
+
},
|
|
39
|
+
signOutChatGPT: async (signal) => {
|
|
40
|
+
await call({ action: 'chatgpt-sign-out' }, signal);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Whether the engine in effect can answer right now. */
|
|
45
|
+
export function engineReady(info) {
|
|
46
|
+
if (info.engine === 'api')
|
|
47
|
+
return info.apiReady;
|
|
48
|
+
if (info.engine === 'chatgpt')
|
|
49
|
+
return info.chatgpt?.signedIn === true;
|
|
50
|
+
const tool = info.tools.find((t) => t.tool === info.engine);
|
|
51
|
+
return !!tool?.installed && tool.signedIn === true && tool.ready === true;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The API-key line under the tools: "in-use" only when the API engine is the
|
|
55
|
+
* one in effect AND a key resolves; "available" when a key resolves but
|
|
56
|
+
* another engine is chosen (or the chosen one is not working); "none" when
|
|
57
|
+
* nothing works yet. Covers every engine: with `chatgpt` chosen and signed in,
|
|
58
|
+
* the API key is "available", never "in use".
|
|
59
|
+
*/
|
|
60
|
+
export function apiRow(info) {
|
|
61
|
+
if (!info.apiReady)
|
|
62
|
+
return 'none';
|
|
63
|
+
return info.engine === 'api' ? 'in-use' : 'available';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* CLI rows before and after the recommended ChatGPT option, in either host.
|
|
67
|
+
* The legacy `advanced` DTO field now supplies the visible Codex alternative.
|
|
68
|
+
*/
|
|
69
|
+
export function visibleTools(info, variant) {
|
|
70
|
+
if (variant === 'settings')
|
|
71
|
+
return {
|
|
72
|
+
main: info.tools.filter((t) => t.tool !== 'codex'),
|
|
73
|
+
advanced: info.tools.filter((t) => t.tool === 'codex'),
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
main: info.tools.filter((t) => t.tool !== 'codex'),
|
|
77
|
+
advanced: info.tools.filter((t) => t.tool === 'codex'),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** The one button the ChatGPT row gets, and its words. */
|
|
81
|
+
export function chatgptAction(info) {
|
|
82
|
+
const chatgpt = info.chatgpt;
|
|
83
|
+
if (chatgpt?.signedIn)
|
|
84
|
+
return info.engine === 'chatgpt'
|
|
85
|
+
? { kind: 'in-use', label: 'In use' }
|
|
86
|
+
: { kind: 'use', label: 'Use ChatGPT' };
|
|
87
|
+
if (chatgpt?.signingIn)
|
|
88
|
+
return { kind: 'waiting', label: 'Waiting for sign-in…' };
|
|
89
|
+
return { kind: 'sign-in', label: 'Sign in with ChatGPT' };
|
|
90
|
+
}
|
|
91
|
+
/** The line under the ChatGPT row's name. */
|
|
92
|
+
export function chatgptDescription(info) {
|
|
93
|
+
const chatgpt = info.chatgpt;
|
|
94
|
+
if (chatgpt?.signedIn)
|
|
95
|
+
return `Signed in${chatgpt.account ? ` as ${chatgpt.account.label}` : ''}.`;
|
|
96
|
+
if (chatgpt?.signingIn)
|
|
97
|
+
return 'Finish signing in in your browser.';
|
|
98
|
+
if (chatgpt?.error?.message)
|
|
99
|
+
return chatgpt.error.message;
|
|
100
|
+
return 'Use your own ChatGPT plan. A preview for open source apps.';
|
|
101
|
+
}
|
|
102
|
+
/** The one button a tool gets, and its words. */
|
|
103
|
+
export function toolAction(tool, info) {
|
|
104
|
+
if (!tool.installed)
|
|
105
|
+
return { kind: 'install', label: 'How to install' };
|
|
106
|
+
if (tool.signedIn === null || (tool.signedIn === true && tool.ready !== true))
|
|
107
|
+
return { kind: 'retry', label: 'Check again' };
|
|
108
|
+
if (tool.signedIn === false)
|
|
109
|
+
return tool.login === 'running'
|
|
110
|
+
? { kind: 'waiting', label: 'Waiting for sign-in…' }
|
|
111
|
+
: {
|
|
112
|
+
kind: 'sign-in',
|
|
113
|
+
label: `Sign in with ${tool.label ?? (tool.tool === 'codex' ? 'Codex' : 'Claude Code')}`,
|
|
114
|
+
};
|
|
115
|
+
return info.engine === tool.tool
|
|
116
|
+
? { kind: 'in-use', label: 'In use' }
|
|
117
|
+
: {
|
|
118
|
+
kind: 'use',
|
|
119
|
+
label: `Use ${tool.label ?? (tool.tool === 'codex' ? 'Codex' : 'Claude Code')}`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as ConnectAi } from './ConnectAi.svelte';
|
|
2
|
+
export { apiRow, chatgptAction, chatgptDescription, createConnectAiClient, engineReady, toolAction, visibleTools, } from './client.js';
|
|
3
|
+
export type { ConnectAiClient, ConnectAiState } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/connect-ai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,MAAM,EACN,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,WAAW,EACX,UAAU,EACV,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Server-only, framework-neutral mounts over inference's status and vendor sign-in APIs. */
|
|
2
|
+
import { type ChatGPTPlanConnection, type createAgentCliService, type InferenceEngineId, type InferenceEngineStatus } from '@happyvertical/smrt-inference/server';
|
|
3
|
+
/** Authenticated bindings: the host must verify owner, tenant and settings authority first. */
|
|
4
|
+
export interface ConnectAiServerBinding {
|
|
5
|
+
engine(): Promise<InferenceEngineId | null>;
|
|
6
|
+
select(engine: InferenceEngineId): Promise<void>;
|
|
7
|
+
cli: Pick<ReturnType<typeof createAgentCliService>, 'cliStatus' | 'agentLogin'>;
|
|
8
|
+
chatgpt: Pick<ChatGPTPlanConnection, 'status' | 'start' | 'signOut'> & Partial<Pick<ChatGPTPlanConnection, 'cancel'>>;
|
|
9
|
+
/** Resolve the current user's API binding through inference. Never return a key. */
|
|
10
|
+
apiStatus(): Promise<InferenceEngineStatus>;
|
|
11
|
+
}
|
|
12
|
+
/** Fetch-style request event, structurally compatible with SvelteKit. */
|
|
13
|
+
export interface ConnectAiRequestEvent {
|
|
14
|
+
request: Request;
|
|
15
|
+
url: URL;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Mount GET status and POST actions at one host-owned route. authorize is required
|
|
19
|
+
* and runs on EVERY request, including polls. No process-wide user bindings are cached.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mountConnectAiRoutes<E extends ConnectAiRequestEvent>(options: {
|
|
22
|
+
authorize(event: E): Promise<ConnectAiServerBinding | null>;
|
|
23
|
+
/** Desktop hosts may open the validated URL. Otherwise return a new-tab link. */
|
|
24
|
+
openBrowser?(url: string): Promise<boolean>;
|
|
25
|
+
/** Compatibility for hosts that let an API engine remain selected without a key. */
|
|
26
|
+
allowUnconfiguredApiSelection?: boolean;
|
|
27
|
+
/** Include inference's non-secret remote revocation confirmation for existing host routes. */
|
|
28
|
+
includeSignOutConfirmation?: boolean;
|
|
29
|
+
}): {
|
|
30
|
+
GET(event: E): Promise<Response>;
|
|
31
|
+
POST(event: E): Promise<Response>;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/components/connect-ai/server.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAI3B,MAAM,sCAAsC,CAAC;AAG9C,+FAA+F;AAC/F,MAAM,WAAW,sBAAsB;IACrC,MAAM,IAAI,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,GAAG,EAAE,IAAI,CACP,UAAU,CAAC,OAAO,qBAAqB,CAAC,EACxC,WAAW,GAAG,YAAY,CAC3B,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC,GAClE,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjD,oFAAoF;IACpF,SAAS,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC7C;AAED,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,GAAG,CAAC;CACV;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,qBAAqB,EAAE,OAAO,EAAE;IAC7E,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CAAC;IAC5D,iFAAiF;IACjF,WAAW,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,oFAAoF;IACpF,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,8FAA8F;IAC9F,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC;eAyDoB,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;gBAWpB,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC;EAsH1C"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/** Server-only, framework-neutral mounts over inference's status and vendor sign-in APIs. */
|
|
2
|
+
import { AGENT_TOOL_INFO, AGENT_TOOLS, inferenceEngineStatus, isAgentTool, isChatGPTAuthorizationUrl, } from '@happyvertical/smrt-inference/server';
|
|
3
|
+
/**
|
|
4
|
+
* Mount GET status and POST actions at one host-owned route. authorize is required
|
|
5
|
+
* and runs on EVERY request, including polls. No process-wide user bindings are cached.
|
|
6
|
+
*/
|
|
7
|
+
export function mountConnectAiRoutes(options) {
|
|
8
|
+
const json = (body, status = 200) => new Response(JSON.stringify(body), {
|
|
9
|
+
status,
|
|
10
|
+
headers: {
|
|
11
|
+
'content-type': 'application/json',
|
|
12
|
+
'cache-control': 'no-store',
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const error = (status, code) => json({ code }, status);
|
|
16
|
+
const known = (value) => value === 'api' || value === 'chatgpt' || isAgentTool(value);
|
|
17
|
+
const state = async (binding) => {
|
|
18
|
+
const [engine, tools, chatgpt, api] = await Promise.all([
|
|
19
|
+
binding.engine(),
|
|
20
|
+
Promise.all(AGENT_TOOLS.map(async (tool) => {
|
|
21
|
+
const found = await binding.cli.cliStatus(tool, { fresh: true });
|
|
22
|
+
return {
|
|
23
|
+
tool,
|
|
24
|
+
installUrl: AGENT_TOOL_INFO[tool].installUrl,
|
|
25
|
+
installed: found.installed,
|
|
26
|
+
signedIn: found.signedIn,
|
|
27
|
+
...(found.ready !== undefined ? { ready: found.ready } : {}),
|
|
28
|
+
...(found.startError ? { startError: found.startError } : {}),
|
|
29
|
+
login: binding.cli.agentLogin().snapshot(tool).state,
|
|
30
|
+
};
|
|
31
|
+
})),
|
|
32
|
+
binding.chatgpt.status(),
|
|
33
|
+
binding.apiStatus(),
|
|
34
|
+
]);
|
|
35
|
+
const status = engine && known(engine)
|
|
36
|
+
? await inferenceEngineStatus(engine, {
|
|
37
|
+
cliStatus: async (tool) => tools.find((found) => found.tool === tool),
|
|
38
|
+
chatgpt: { status: async () => chatgpt },
|
|
39
|
+
apiStatus: async () => api,
|
|
40
|
+
})
|
|
41
|
+
: undefined;
|
|
42
|
+
// Explicit projection: never spread host settings, account details or SDK errors.
|
|
43
|
+
return {
|
|
44
|
+
engine: known(engine) ? engine : null,
|
|
45
|
+
configured: status?.configured === true,
|
|
46
|
+
tools,
|
|
47
|
+
chatgpt: {
|
|
48
|
+
signedIn: chatgpt.signedIn,
|
|
49
|
+
signingIn: chatgpt.signingIn,
|
|
50
|
+
...(chatgpt.error ? { error: { code: chatgpt.error.code } } : {}),
|
|
51
|
+
},
|
|
52
|
+
apiReady: api.configured,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
async GET(event) {
|
|
57
|
+
if (event.request.method !== 'GET')
|
|
58
|
+
return error(405, 'method_not_allowed');
|
|
59
|
+
try {
|
|
60
|
+
const binding = await options.authorize(event);
|
|
61
|
+
if (!binding)
|
|
62
|
+
return error(403, 'not_allowed');
|
|
63
|
+
return json(await state(binding));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return error(503, 'connect_ai_unavailable');
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
async POST(event) {
|
|
70
|
+
if (event.request.method !== 'POST')
|
|
71
|
+
return error(405, 'method_not_allowed');
|
|
72
|
+
if (event.request.headers.get('origin') !== event.url.origin ||
|
|
73
|
+
new URL(event.request.url).origin !== event.url.origin)
|
|
74
|
+
return error(403, 'invalid_origin');
|
|
75
|
+
if (event.request.headers
|
|
76
|
+
.get('content-type')
|
|
77
|
+
?.split(';')[0]
|
|
78
|
+
.trim()
|
|
79
|
+
.toLowerCase() !== 'application/json')
|
|
80
|
+
return error(415, 'invalid_content_type');
|
|
81
|
+
try {
|
|
82
|
+
const binding = await options.authorize(event);
|
|
83
|
+
if (!binding)
|
|
84
|
+
return error(403, 'not_allowed');
|
|
85
|
+
const reader = event.request.body?.getReader();
|
|
86
|
+
if (!reader)
|
|
87
|
+
return error(400, 'invalid_request');
|
|
88
|
+
let bytes = new Uint8Array(0);
|
|
89
|
+
try {
|
|
90
|
+
while (true) {
|
|
91
|
+
const part = await reader.read();
|
|
92
|
+
if (part.done)
|
|
93
|
+
break;
|
|
94
|
+
if (bytes.length + part.value.length > 1024) {
|
|
95
|
+
await reader.cancel();
|
|
96
|
+
return error(413, 'request_too_large');
|
|
97
|
+
}
|
|
98
|
+
const next = new Uint8Array(bytes.length + part.value.length);
|
|
99
|
+
next.set(bytes);
|
|
100
|
+
next.set(part.value, bytes.length);
|
|
101
|
+
bytes = next;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
reader.releaseLock();
|
|
106
|
+
}
|
|
107
|
+
let body;
|
|
108
|
+
try {
|
|
109
|
+
const parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
110
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
111
|
+
return error(400, 'invalid_request');
|
|
112
|
+
body = parsed;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return error(400, 'invalid_request');
|
|
116
|
+
}
|
|
117
|
+
if (body.action === 'select') {
|
|
118
|
+
if (!known(body.engine))
|
|
119
|
+
return error(400, 'unknown_engine');
|
|
120
|
+
const ready = await inferenceEngineStatus(body.engine, {
|
|
121
|
+
cliStatus: (tool) => binding.cli.cliStatus(tool, { fresh: true }),
|
|
122
|
+
chatgpt: binding.chatgpt,
|
|
123
|
+
apiStatus: () => binding.apiStatus(),
|
|
124
|
+
});
|
|
125
|
+
if (!ready.configured &&
|
|
126
|
+
!(body.engine === 'api' && options.allowUnconfiguredApiSelection))
|
|
127
|
+
return error(409, 'engine_not_ready');
|
|
128
|
+
await binding.select(body.engine);
|
|
129
|
+
return json({ ok: true });
|
|
130
|
+
}
|
|
131
|
+
if (body.action === 'connect') {
|
|
132
|
+
if (!isAgentTool(body.tool))
|
|
133
|
+
return error(400, 'unknown_tool');
|
|
134
|
+
const found = await binding.cli.cliStatus(body.tool, { fresh: true });
|
|
135
|
+
if (!found.installed)
|
|
136
|
+
return error(409, 'cli_missing');
|
|
137
|
+
if (found.signedIn === null)
|
|
138
|
+
return error(502, 'cli_no_answer');
|
|
139
|
+
if (found.signedIn && found.ready !== true)
|
|
140
|
+
return error(409, 'engine_not_ready');
|
|
141
|
+
if (found.signedIn) {
|
|
142
|
+
await binding.select(body.tool);
|
|
143
|
+
return json({ ok: true });
|
|
144
|
+
}
|
|
145
|
+
const result = await binding.cli.agentLogin().start(body.tool);
|
|
146
|
+
return json({ result });
|
|
147
|
+
}
|
|
148
|
+
if (body.action === 'chatgpt-start') {
|
|
149
|
+
const before = await binding.chatgpt.status();
|
|
150
|
+
if (before.signedIn && !before.signingIn)
|
|
151
|
+
return json({ signedIn: true });
|
|
152
|
+
const { authorizationUrl } = await binding.chatgpt.start();
|
|
153
|
+
if (!isChatGPTAuthorizationUrl(authorizationUrl))
|
|
154
|
+
return error(502, 'invalid_authorization_url');
|
|
155
|
+
const opened = before.signingIn
|
|
156
|
+
? false
|
|
157
|
+
: ((await options.openBrowser?.(authorizationUrl)) ?? false);
|
|
158
|
+
return json(opened ? { opened } : { opened, authorizationUrl });
|
|
159
|
+
}
|
|
160
|
+
if (body.action === 'chatgpt-cancel') {
|
|
161
|
+
if (!binding.chatgpt.cancel)
|
|
162
|
+
return error(409, 'chatgpt_cancel_unavailable');
|
|
163
|
+
try {
|
|
164
|
+
await binding.chatgpt.cancel();
|
|
165
|
+
}
|
|
166
|
+
catch (cause) {
|
|
167
|
+
if (cause?.code ===
|
|
168
|
+
'chatgpt_cancel_unavailable')
|
|
169
|
+
return error(409, 'chatgpt_cancel_unavailable');
|
|
170
|
+
throw cause;
|
|
171
|
+
}
|
|
172
|
+
return json({ ok: true });
|
|
173
|
+
}
|
|
174
|
+
if (body.action === 'chatgpt-sign-out') {
|
|
175
|
+
const out = await binding.chatgpt.signOut();
|
|
176
|
+
return json({
|
|
177
|
+
ok: true,
|
|
178
|
+
...(options.includeSignOutConfirmation
|
|
179
|
+
? { remoteRevocationConfirmed: out.remoteRevocationConfirmed }
|
|
180
|
+
: {}),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return error(400, 'unknown_action');
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return error(503, 'connect_ai_unavailable');
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AgentCliStatus, AgentTool, ChatGPTPlanStatus, InferenceEngineId, LoginSnapshot } from '@happyvertical/smrt-inference/server';
|
|
2
|
+
/** Key-free status DTO from the authenticated Connect AI route. */
|
|
3
|
+
export interface ConnectAiState {
|
|
4
|
+
engine: InferenceEngineId | null;
|
|
5
|
+
configured: boolean;
|
|
6
|
+
tools: Array<Pick<AgentCliStatus, 'tool' | 'installed' | 'signedIn' | 'installUrl' | 'ready' | 'startError'> & {
|
|
7
|
+
login: LoginSnapshot['state'];
|
|
8
|
+
label?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
}>;
|
|
11
|
+
chatgpt: Pick<ChatGPTPlanStatus, 'signedIn' | 'signingIn'> & {
|
|
12
|
+
error?: {
|
|
13
|
+
code: NonNullable<ChatGPTPlanStatus['error']>['code'];
|
|
14
|
+
message?: string;
|
|
15
|
+
};
|
|
16
|
+
account?: {
|
|
17
|
+
label: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
apiReady: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Browser transport; keys and credentials are handled by inference settings, never this API. */
|
|
23
|
+
export interface ConnectAiClient {
|
|
24
|
+
state(signal?: AbortSignal): Promise<ConnectAiState>;
|
|
25
|
+
connect(tool: AgentTool, signal?: AbortSignal): Promise<void>;
|
|
26
|
+
/** Optional compact-host result contract, including a CLI removed between status and click. */
|
|
27
|
+
connectOutcome?(tool: AgentTool, signal?: AbortSignal): Promise<{
|
|
28
|
+
result: 'ready' | 'login_started' | 'login_running' | 'missing';
|
|
29
|
+
}>;
|
|
30
|
+
/** Compact hosts may project their own fixed, key-free transport errors. */
|
|
31
|
+
errorMessage?(error: unknown): string;
|
|
32
|
+
choose(engine: InferenceEngineId, signal?: AbortSignal): Promise<void>;
|
|
33
|
+
startChatGPT(signal?: AbortSignal): Promise<{
|
|
34
|
+
authorizationUrl?: string;
|
|
35
|
+
}>;
|
|
36
|
+
cancelChatGPT?(signal?: AbortSignal): Promise<void>;
|
|
37
|
+
signOutChatGPT(signal?: AbortSignal): Promise<void>;
|
|
38
|
+
/** Optional host-owned ChatGPT model preference; no credentials. */
|
|
39
|
+
modelState?(signal?: AbortSignal): Promise<{
|
|
40
|
+
model: string | null;
|
|
41
|
+
models?: {
|
|
42
|
+
id: string;
|
|
43
|
+
label: string;
|
|
44
|
+
}[];
|
|
45
|
+
}>;
|
|
46
|
+
chooseModel?(model: string | null, signal?: AbortSignal): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/connect-ai/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACd,MAAM,sCAAsC,CAAC;AAE9C,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,KAAK,CACV,IAAI,CACF,cAAc,EACd,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,GAAG,OAAO,GAAG,YAAY,CAC1E,GAAG;QACF,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;QAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CACF,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,WAAW,CAAC,GAAG;QAC3D,KAAK,CAAC,EAAE;YACN,IAAI,EAAE,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YACtD,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,OAAO,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;KAC7B,CAAC;IACF,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,iGAAiG;AACjG,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACrD,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,+FAA+F;IAC/F,cAAc,CAAC,CACb,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC;QACT,MAAM,EAAE,OAAO,GAAG,eAAe,GAAG,eAAe,GAAG,SAAS,CAAC;KACjE,CAAC,CAAC;IACH,4EAA4E;IAC5E,YAAY,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACtC,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,YAAY,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3E,aAAa,CAAC,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,oEAAoE;IACpE,UAAU,CAAC,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;QACzC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,MAAM,CAAC,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;KAC1C,CAAC,CAAC;IACH,WAAW,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
* `buildCookbookShell`, keeps layout and overview edits in memory, and hands
|
|
10
10
|
* each edit to `oncookbookchange` for the host to persist.
|
|
11
11
|
*/
|
|
12
|
+
import { resolveCookbookFieldPolicy } from '@happyvertical/smrt-fields/policy';
|
|
13
|
+
import { useI18n } from '@happyvertical/smrt-ui/i18n';
|
|
12
14
|
import { createRawSnippet, mount, unmount, untrack } from 'svelte';
|
|
15
|
+
import { M } from '../../i18n/strings.workspace.js';
|
|
13
16
|
import AppShell from '../app/AppShell.svelte';
|
|
14
17
|
import type { ShellSlotItem } from '../app/slot-item.js';
|
|
15
18
|
import { parseRecipeExportRef } from '../overview/recipe-widgets.js';
|
|
@@ -23,18 +26,24 @@ import {
|
|
|
23
26
|
isShellLayoutEmpty,
|
|
24
27
|
type ShellLayout,
|
|
25
28
|
} from '../workspace/admin-shell/layout.js';
|
|
29
|
+
import type { CookbookAppProps } from './app-props.js';
|
|
26
30
|
import { applyCookbookTheme } from './brand-theme.js';
|
|
27
|
-
import { buildCookbookShell,
|
|
31
|
+
import { buildCookbookShell, cookbookScreenDefinition } from './build.js';
|
|
28
32
|
import { type CookbookContext, setCookbookContext } from './context.js';
|
|
29
|
-
import {
|
|
30
|
-
|
|
33
|
+
import {
|
|
34
|
+
createCookbookRegistry,
|
|
35
|
+
resolveInstalledRecipeExport,
|
|
36
|
+
} from './registry.js';
|
|
31
37
|
|
|
32
38
|
let {
|
|
33
39
|
cookbook,
|
|
34
40
|
catalog,
|
|
41
|
+
fieldPolicies,
|
|
42
|
+
assistant,
|
|
43
|
+
embed = false,
|
|
35
44
|
loaders,
|
|
36
45
|
widgetContext,
|
|
37
|
-
resolveExport,
|
|
46
|
+
resolveExport: suppliedResolveExport,
|
|
38
47
|
oncookbookchange,
|
|
39
48
|
recipeOrder,
|
|
40
49
|
entryPath,
|
|
@@ -44,8 +53,24 @@ let {
|
|
|
44
53
|
navMode = 'sections-with-items',
|
|
45
54
|
slotItems = [],
|
|
46
55
|
children,
|
|
56
|
+
panel,
|
|
57
|
+
panelEnabled,
|
|
58
|
+
panelToggle,
|
|
59
|
+
panelLabel,
|
|
47
60
|
...shellProps
|
|
48
61
|
}: CookbookAppProps = $props();
|
|
62
|
+
const { t } = useI18n();
|
|
63
|
+
const assistantLabel = $derived(
|
|
64
|
+
assistant?.label ?? t(M['ui.cookbook.assistant']),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const resolveExport = $derived(
|
|
68
|
+
suppliedResolveExport ??
|
|
69
|
+
((specifier: string, exportName: string) =>
|
|
70
|
+
resolveInstalledRecipeExport(specifier, exportName, {
|
|
71
|
+
recipes: cookbook.recipes,
|
|
72
|
+
})),
|
|
73
|
+
);
|
|
49
74
|
|
|
50
75
|
const shell = $derived(
|
|
51
76
|
buildCookbookShell({
|
|
@@ -140,6 +165,8 @@ $effect(() => {
|
|
|
140
165
|
void (async () => {
|
|
141
166
|
const items: ShellSlotItem[] = [];
|
|
142
167
|
for (const widget of widgets) {
|
|
168
|
+
// This recipe needs authenticated transport/registry bindings supplied by the host panel.
|
|
169
|
+
if (widget.recipeId === 'chat.assistant') continue;
|
|
143
170
|
const ref = parseRecipeExportRef(widget.export);
|
|
144
171
|
if (!ref) continue;
|
|
145
172
|
try {
|
|
@@ -187,13 +214,28 @@ const models = $derived.by(() => {
|
|
|
187
214
|
seen.add(entry.model.id);
|
|
188
215
|
choices.push({
|
|
189
216
|
value: entry.model.id,
|
|
190
|
-
label:
|
|
217
|
+
label: entry.label,
|
|
191
218
|
});
|
|
192
219
|
}
|
|
193
220
|
return choices;
|
|
194
221
|
});
|
|
195
222
|
|
|
196
223
|
setCookbookContext({
|
|
224
|
+
get resolveExport() {
|
|
225
|
+
return resolveExport;
|
|
226
|
+
},
|
|
227
|
+
fieldPolicy(definition) {
|
|
228
|
+
return (
|
|
229
|
+
fieldPolicies?.[definition.objectRef] ??
|
|
230
|
+
resolveCookbookFieldPolicy(definition, cookbook)
|
|
231
|
+
);
|
|
232
|
+
},
|
|
233
|
+
get fieldPolicies() {
|
|
234
|
+
return fieldPolicies;
|
|
235
|
+
},
|
|
236
|
+
screenDefinition(definition, entryId) {
|
|
237
|
+
return cookbookScreenDefinition(shell, definition, entryId);
|
|
238
|
+
},
|
|
197
239
|
get shell() {
|
|
198
240
|
return shell;
|
|
199
241
|
},
|
|
@@ -220,6 +262,17 @@ setCookbookContext({
|
|
|
220
262
|
|
|
221
263
|
<AppShell
|
|
222
264
|
{...shellProps}
|
|
265
|
+
panel={assistant && !embed ? assistantPanel : panel}
|
|
266
|
+
panelEnabled={assistant ? !embed : panelEnabled}
|
|
267
|
+
panelToggle={assistant ? (embed ? false : { label: assistantLabel }) : panelToggle}
|
|
268
|
+
panelLabel={assistant ? assistantLabel : panelLabel}
|
|
269
|
+
webmcp={assistant && shellProps.webmcp !== false ? {
|
|
270
|
+
...(typeof shellProps.webmcp === 'object' ? shellProps.webmcp : {}),
|
|
271
|
+
ui: {
|
|
272
|
+
...(typeof shellProps.webmcp === 'object' && typeof shellProps.webmcp.ui === 'object' ? shellProps.webmcp.ui : {}),
|
|
273
|
+
dataSurfaceRegistry: assistant.registry,
|
|
274
|
+
},
|
|
275
|
+
} : shellProps.webmcp}
|
|
223
276
|
title={shell.title}
|
|
224
277
|
{navMode}
|
|
225
278
|
navGroups={shell.navGroups}
|
|
@@ -238,3 +291,29 @@ setCookbookContext({
|
|
|
238
291
|
>
|
|
239
292
|
{@render children()}
|
|
240
293
|
</AppShell>
|
|
294
|
+
|
|
295
|
+
{#snippet assistantPanel({ open }: { open: boolean })}
|
|
296
|
+
{#if assistant && !embed}
|
|
297
|
+
{@const Dock = assistant.component}
|
|
298
|
+
<section class="smrt-cookbook-app__cookbook-assistant" aria-label={assistantLabel} hidden={!open}>
|
|
299
|
+
<Dock transport={assistant.transport} registry={assistant.registry} contextMode="server" visible={open} messageFormat="markdown" toolPresentation={assistant.toolPresentation} introduction={assistant.introduction} />
|
|
300
|
+
</section>
|
|
301
|
+
{/if}
|
|
302
|
+
{/snippet}
|
|
303
|
+
|
|
304
|
+
<style>
|
|
305
|
+
@layer smrt.reset, smrt.structure, smrt.theme;
|
|
306
|
+
|
|
307
|
+
@layer smrt.structure {
|
|
308
|
+
.smrt-cookbook-app__cookbook-assistant {
|
|
309
|
+
height: 100%;
|
|
310
|
+
min-height: 0;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
@layer smrt.theme {
|
|
315
|
+
.smrt-cookbook-app__cookbook-assistant {
|
|
316
|
+
color: var(--smrt-color-on-surface);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
</style>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CookbookAppProps } from './
|
|
1
|
+
import type { CookbookAppProps } from './app-props.js';
|
|
2
2
|
declare const CookbookApp: import("svelte").Component<CookbookAppProps, {}, "">;
|
|
3
3
|
type CookbookApp = ReturnType<typeof CookbookApp>;
|
|
4
4
|
export default CookbookApp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CookbookApp.svelte.d.ts","sourceRoot":"","sources":["../../../src/components/cookbook/CookbookApp.svelte.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CookbookApp.svelte.d.ts","sourceRoot":"","sources":["../../../src/components/cookbook/CookbookApp.svelte.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAsRvD,QAAA,MAAM,WAAW,sDAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Shell-dependent props, kept outside the plain cookbook data contract. */
|
|
2
|
+
import type { AssistantTransport } from '@happyvertical/smrt-chat/svelte';
|
|
3
|
+
import type { Cookbook } from '@happyvertical/smrt-types';
|
|
4
|
+
import type { DataSurfaceRegistry } from '@happyvertical/smrt-ui/data-surface';
|
|
5
|
+
import type { Component, ComponentProps } from 'svelte';
|
|
6
|
+
import type AppShell from '../app/AppShell.svelte';
|
|
7
|
+
import type { RecipeExportResolver } from '../overview/recipe-widgets.js';
|
|
8
|
+
import type { ScreenPolicy } from '../screens/types.js';
|
|
9
|
+
import type { BuildCookbookShellOptions, CookbookCatalog, CookbookLoaders } from './types.js';
|
|
10
|
+
/** Props of `CookbookApp`; anything else is passed to `AppShell` unchanged. */
|
|
11
|
+
export interface CookbookAppProps extends Omit<ComponentProps<typeof AppShell>, 'navGroups' | 'nav' | 'navMode' | 'layout' | 'onlayoutchange' | 'preset' | 'colorScheme' | 'borderRadius' | 'density' | 'contrast' | 'sectionHref' | 'title' | 'children'>, Pick<BuildCookbookShellOptions, 'recipeOrder' | 'entryPath' | 'sectionPath' | 'href' | 'title'> {
|
|
12
|
+
cookbook: Cookbook;
|
|
13
|
+
catalog: CookbookCatalog;
|
|
14
|
+
/** Shared host composition supplies the dock, transport and surface registry. */
|
|
15
|
+
assistant?: {
|
|
16
|
+
component: Component<{
|
|
17
|
+
transport: AssistantTransport;
|
|
18
|
+
registry: DataSurfaceRegistry;
|
|
19
|
+
contextMode?: 'data-surfaces' | 'server';
|
|
20
|
+
visible?: boolean;
|
|
21
|
+
messageFormat?: 'text' | 'markdown';
|
|
22
|
+
toolPresentation?: 'generic';
|
|
23
|
+
introduction?: {
|
|
24
|
+
lists: string[];
|
|
25
|
+
actions: string[];
|
|
26
|
+
configured: boolean;
|
|
27
|
+
};
|
|
28
|
+
}>;
|
|
29
|
+
transport: AssistantTransport;
|
|
30
|
+
registry: DataSurfaceRegistry;
|
|
31
|
+
label?: string;
|
|
32
|
+
/** Host-owned person-facing tool copy; raw provider history stays private. */
|
|
33
|
+
toolPresentation?: 'generic';
|
|
34
|
+
introduction?: {
|
|
35
|
+
lists: string[];
|
|
36
|
+
actions: string[];
|
|
37
|
+
configured: boolean;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/** Embedded/plugin hosts keep their content and navigation without in-app chat. */
|
|
41
|
+
embed?: boolean;
|
|
42
|
+
/** Resolved once by the owning policy engine at the server boundary. */
|
|
43
|
+
fieldPolicies?: Readonly<Record<string, ScreenPolicy>>;
|
|
44
|
+
/** Expanded section entries are the default; use `sections` for headings only. */
|
|
45
|
+
navMode?: 'sections' | 'sections-with-items';
|
|
46
|
+
/**
|
|
47
|
+
* Data loaders for the `metric`, `records` and `chart` widgets. With
|
|
48
|
+
* `metric` and `records`, section pages also show a record count and the
|
|
49
|
+
* latest records of the section's lead model. `shortcuts` composes with the
|
|
50
|
+
* registry's own entries (see {@link CookbookShortcutsLoader}).
|
|
51
|
+
*/
|
|
52
|
+
loaders?: CookbookLoaders;
|
|
53
|
+
/** Host capabilities handed to widget loaders that run in the browser. */
|
|
54
|
+
widgetContext?: () => Record<string, unknown>;
|
|
55
|
+
/**
|
|
56
|
+
* Turns a recipe export reference (`'@acme/shop/svelte#SalesTotal'`) into
|
|
57
|
+
* the export: a static map of dynamic imports in a bundled app. Without it,
|
|
58
|
+
* recipe `widget` and `shell-widget` surfaces are ignored.
|
|
59
|
+
*/
|
|
60
|
+
resolveExport?: RecipeExportResolver;
|
|
61
|
+
/** Called with the cookbook after a layout or overview edit. */
|
|
62
|
+
oncookbookchange?: (cookbook: Cookbook) => void;
|
|
63
|
+
children: import('svelte').Snippet;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=app-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-props.d.ts","sourceRoot":"","sources":["../../../src/components/cookbook/app-props.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,QAAQ,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,yBAAyB,EACzB,eAAe,EACf,eAAe,EAEhB,MAAM,YAAY,CAAC;AAEpB,+EAA+E;AAC/E,MAAM,WAAW,gBACf,SAAQ,IAAI,CACR,cAAc,CAAC,OAAO,QAAQ,CAAC,EAC7B,WAAW,GACX,KAAK,GACL,SAAS,GACT,QAAQ,GACR,gBAAgB,GAChB,QAAQ,GACR,aAAa,GACb,cAAc,GACd,SAAS,GACT,UAAU,GACV,aAAa,GACb,OAAO,GACP,UAAU,CACb,EACD,IAAI,CACF,yBAAyB,EACzB,aAAa,GAAG,WAAW,GAAG,aAAa,GAAG,MAAM,GAAG,OAAO,CAC/D;IACH,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,eAAe,CAAC;IACzB,iFAAiF;IACjF,SAAS,CAAC,EAAE;QACV,SAAS,EAAE,SAAS,CAAC;YACnB,SAAS,EAAE,kBAAkB,CAAC;YAC9B,QAAQ,EAAE,mBAAmB,CAAC;YAC9B,WAAW,CAAC,EAAE,eAAe,GAAG,QAAQ,CAAC;YACzC,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB,aAAa,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;YACpC,gBAAgB,CAAC,EAAE,SAAS,CAAC;YAC7B,YAAY,CAAC,EAAE;gBACb,KAAK,EAAE,MAAM,EAAE,CAAC;gBAChB,OAAO,EAAE,MAAM,EAAE,CAAC;gBAClB,UAAU,EAAE,OAAO,CAAC;aACrB,CAAC;SACH,CAAC,CAAC;QACH,SAAS,EAAE,kBAAkB,CAAC;QAC9B,QAAQ,EAAE,mBAAmB,CAAC;QAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,8EAA8E;QAC9E,gBAAgB,CAAC,EAAE,SAAS,CAAC;QAC7B,YAAY,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,EAAE,CAAC;YAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YAAC,UAAU,EAAE,OAAO,CAAA;SAAE,CAAC;KAC5E,CAAC;IACF,mFAAmF;IACnF,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,wEAAwE;IACxE,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IACvD,kFAAkF;IAClF,OAAO,CAAC,EAAE,UAAU,GAAG,qBAAqB,CAAC;IAC7C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C;;;;OAIG;IACH,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAChD,QAAQ,EAAE,OAAO,QAAQ,EAAE,OAAO,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|