@steerable/agent-shell-web 0.8.5 → 0.9.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-shell-web",
3
- "version": "0.8.5",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "Steerable framework — product-neutral renderer SPA source for @steerable/agent-shell (React + Vite). Consumed by product web entry points via the `@/` alias (anchored at this package's src/) and the createProductViteConfig factory. Published as a source package (src/), plus the compiled vite.base config factory (vite.base.js + .d.ts) for Node-side config loading.",
6
6
  "license": "Apache-2.0",
@@ -45,8 +45,8 @@
45
45
  "react-router-dom": "^6.30.0",
46
46
  "rehype-raw": "^7.0.0",
47
47
  "remark-gfm": "^4.0.1",
48
- "@steerable/agent-protocol": "0.8.5",
49
- "@steerable/agent-ui": "0.8.5"
48
+ "@steerable/agent-protocol": "0.9.0",
49
+ "@steerable/agent-ui": "0.9.0"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@tailwindcss/vite": "^4.3.0",
@@ -59,7 +59,7 @@
59
59
  "typescript": "^5.8.3",
60
60
  "vite": "^5.4.21",
61
61
  "vitest": "^3.2.4",
62
- "@steerable/pack-sdk": "0.8.5"
62
+ "@steerable/pack-sdk": "0.9.0"
63
63
  },
64
64
  "scripts": {
65
65
  "gen": "echo agent-shell-web",
package/src/brand.ts CHANGED
@@ -31,6 +31,12 @@ export const BRAND_TITLE: string =
31
31
  export const BRAND_HOME_HINT: string =
32
32
  import.meta.env.VITE_BRAND_HOME_HINT ?? 'Type a message to start a new chat.';
33
33
 
34
+ /**
35
+ * 首启是否先显示模型配置页。中性 shell 为 true;产品注入自己的品牌后
36
+ * 缺省为 false,产品自带首启流程或已预置模型时保持原样。
37
+ */
38
+ export const BRAND_FIRST_RUN: boolean = import.meta.env.VITE_BRAND_FIRST_RUN === 'true';
39
+
34
40
  /** shell 默认方形标,用于侧栏和 favicon。包只注册一枚 logo 时与字标相同。 */
35
41
  let brandMarkUrl: string = shellMarkUrl;
36
42
 
@@ -7,29 +7,18 @@
7
7
  * names out of the headline. The message itself belongs in the details
8
8
  * disclosure, which is for whoever reads it: the user reporting a problem and
9
9
  * the person on support.
10
+ *
11
+ * The vocabulary and the metadata reader live in `@steerable/agent-protocol` so
12
+ * the command line classifies a failure exactly as this card does.
10
13
  */
11
14
 
15
+ import { readTurnFailureDetail, readTurnFailureKind, type TurnFailureDetail, type TurnFailureKind } from '@steerable/agent-protocol';
12
16
  import { t } from '@/i18n';
13
17
 
14
- export type FailureKind =
15
- | 'transport'
16
- | 'rate_limit'
17
- | 'server'
18
- | 'auth'
19
- | 'invalid_request'
20
- | 'context_overflow'
21
- | 'unknown';
18
+ export type FailureKind = TurnFailureKind;
19
+ export type { TurnFailureDetail };
22
20
 
23
- /** The provider classifications the backend can send. */
24
- const KINDS: readonly FailureKind[] = [
25
- 'transport',
26
- 'rate_limit',
27
- 'server',
28
- 'auth',
29
- 'invalid_request',
30
- 'context_overflow',
31
- 'unknown',
32
- ];
21
+ export { readTurnFailureDetail, readTurnFailureKind };
33
22
 
34
23
  /** One action a failed turn can offer. */
35
24
  export type FailureAction =
@@ -38,16 +27,6 @@ export type FailureAction =
38
27
  | { kind: 'open-model-settings' }
39
28
  | { kind: 'new-chat' };
40
29
 
41
- /** Structured failure detail persisted with the turn (`messageMetadata.failure`). */
42
- export interface TurnFailureDetail {
43
- kind: FailureKind;
44
- /** Proxy the failing request used, credentials already stripped. */
45
- proxy?: string;
46
- /** Provider attempts spent on the request, including the last. */
47
- attempts?: number;
48
- statusCode?: number;
49
- }
50
-
51
30
  /** Everything the card renders, derived from one failure. */
52
31
  export interface FailurePresentation {
53
32
  title: string;
@@ -67,11 +46,7 @@ export interface FailurePresentation {
67
46
  * the generic card with the raw message, which is still actionable when the
68
47
  * only remedy is reporting it.
69
48
  */
70
- export function readFailureKind(value: unknown): FailureKind | undefined {
71
- return typeof value === 'string' && (KINDS as readonly string[]).includes(value)
72
- ? (value as FailureKind)
73
- : undefined;
74
- }
49
+ export const readFailureKind = readTurnFailureKind;
75
50
 
76
51
  /**
77
52
  * Copy and actions for one failure.
@@ -161,25 +136,4 @@ export function failurePresentation(
161
136
  }
162
137
 
163
138
  /** Reads the persisted failure block, dropping fields of the wrong type. */
164
- export function readFailureDetail(value: unknown): TurnFailureDetail | undefined {
165
- if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;
166
- const record = value as Record<string, unknown>;
167
- const kind = readFailureKind(record.errorKind);
168
- if (!kind) return undefined;
169
- const proxy =
170
- typeof record.proxy === 'string' && record.proxy ? record.proxy : undefined;
171
- const attempts =
172
- typeof record.attempts === 'number' && Number.isFinite(record.attempts)
173
- ? record.attempts
174
- : undefined;
175
- const statusCode =
176
- typeof record.statusCode === 'number' && Number.isFinite(record.statusCode)
177
- ? record.statusCode
178
- : undefined;
179
- return {
180
- kind,
181
- ...(proxy ? { proxy } : {}),
182
- ...(attempts !== undefined ? { attempts } : {}),
183
- ...(statusCode !== undefined ? { statusCode } : {}),
184
- };
185
- }
139
+ export const readFailureDetail = readTurnFailureDetail;
@@ -871,6 +871,30 @@ export async function getLlmAccount(refresh = false) {
871
871
  });
872
872
  }
873
873
 
874
+ /** Why a turn can or cannot start: the credential source the host resolved. */
875
+ export interface LlmCredentialStatus {
876
+ ok: boolean;
877
+ source: 'config' | 'env' | 'not_required' | 'missing';
878
+ envName?: string;
879
+ envNames: string[];
880
+ provider: string;
881
+ vendorId: string | null;
882
+ model: string;
883
+ }
884
+
885
+ /**
886
+ * Reads the host's credential verdict.
887
+ *
888
+ * The first-run page uses it instead of inspecting settings itself, so the web
889
+ * shell and the command line agree on what "configured" means.
890
+ */
891
+ export async function getLlmCredential() {
892
+ return bridge().localBackend.request<LlmCredentialStatus>({
893
+ method: 'GET',
894
+ path: '/api/v2/llm/credential',
895
+ });
896
+ }
897
+
874
898
  export async function getLlmSettings() {
875
899
  return bridge().localBackend.request<LlmSettings>({
876
900
  method: 'GET',
package/src/main.tsx CHANGED
@@ -6,8 +6,9 @@ import { I18nProvider, configureI18n, getLocale, notifyHostLocale } from './i18n
6
6
  import { AgentLayout } from './layouts/AgentLayout';
7
7
  import { AgentPage } from './pages/AgentPage';
8
8
  import { SettingsPage } from './pages/SettingsPage';
9
+ import { SetupPage } from './pages/SetupPage';
9
10
  import { getPackRoutes } from './packs/registry';
10
- import { getBrandMarkUrl, BRAND_NAME } from './brand';
11
+ import { BRAND_FIRST_RUN, getBrandMarkUrl, BRAND_NAME } from './brand';
11
12
  import { getAppShellGate } from './auth/gate';
12
13
  import { installHostPaste } from './lib/host-paste';
13
14
  import './styles/index.css';
@@ -52,7 +53,9 @@ function renderApplication(root: Root): void {
52
53
  {
53
54
  element: <AgentLayout />,
54
55
  children: [
55
- { index: true, element: <AgentPage /> },
56
+ // The framework's own shell has no credential yet, so its first
57
+ // screen configures one. A product brand keeps its own first run.
58
+ { index: true, element: BRAND_FIRST_RUN ? <SetupPage /> : <AgentPage /> },
56
59
  { path: 'agent', element: <AgentPage /> },
57
60
  { path: 'agent/:chatId', element: <AgentPage /> },
58
61
  { path: 'settings', element: <SettingsPage /> },
@@ -0,0 +1,95 @@
1
+ /**
2
+ * First-run setup: connect a model before the chat, on the framework's own
3
+ * shell only.
4
+ *
5
+ * The panel is the same component the settings screen uses, so a key entered
6
+ * here is saved and verified exactly as it would be there; this page only adds
7
+ * the surrounding copy and the step out of the way. Products that ship their
8
+ * own brand never see it (see `BRAND_FIRST_RUN`).
9
+ */
10
+ import { useEffect, useRef, useState } from 'react';
11
+ import { useNavigate } from 'react-router-dom';
12
+
13
+ import { BRAND_NAME } from '@/brand';
14
+ import { LlmSettingsPanel, type LlmSettingsPanelHandle } from '@/components/settings/LlmSettingsPanel';
15
+ import { t } from '@/i18n';
16
+ import { getLlmCredential } from '@/lib/local-api';
17
+
18
+ /** What the first-run page should render for a credential answer. */
19
+ export type SetupDecision = 'chat' | 'form';
20
+
21
+ /**
22
+ * Decides between the chat and the setup form.
23
+ *
24
+ * A failed read is treated as "go to the chat": refusing to show the app
25
+ * because one endpoint failed would be worse than letting the turn report its
26
+ * own failure, which is already a designed path.
27
+ *
28
+ * @param status Credential status, or null when it could not be read.
29
+ * @returns Which screen to show.
30
+ */
31
+ export function setupDecision(status: { ok: boolean } | null): SetupDecision {
32
+ if (!status) return 'chat';
33
+ return status.ok ? 'chat' : 'form';
34
+ }
35
+
36
+ /** Reads the credential once; renders nothing while the answer is unknown. */
37
+ export function SetupPage() {
38
+ const navigate = useNavigate();
39
+ const [state, setState] = useState<'checking' | 'needed' | 'ready'>('checking');
40
+ const panel = useRef<LlmSettingsPanelHandle>(null);
41
+
42
+ useEffect(() => {
43
+ let cancelled = false;
44
+ void getLlmCredential()
45
+ .then((status) => {
46
+ if (cancelled) return;
47
+ setState(setupDecision(status) === 'chat' ? 'ready' : 'needed');
48
+ })
49
+ .catch(() => {
50
+ // A failed read is not proof that a credential is missing; let the
51
+ // chat page show its own failure card instead of trapping the user.
52
+ if (!cancelled) setState('ready');
53
+ });
54
+ return () => {
55
+ cancelled = true;
56
+ };
57
+ }, []);
58
+
59
+ useEffect(() => {
60
+ if (state === 'ready') navigate('/', { replace: true });
61
+ }, [navigate, state]);
62
+
63
+ if (state === 'checking') return null;
64
+
65
+ return (
66
+ <div className="flex h-full w-full items-start justify-center overflow-auto bg-agent-canvas px-6 py-10">
67
+ <div className="w-full max-w-xl">
68
+ <h1 className="text-lg font-semibold text-agent-foreground">
69
+ {t('Connect a model to get started')}
70
+ </h1>
71
+ <p className="mt-2 text-xs text-agent-muted-foreground">
72
+ {t('{name} needs a model service to work. The key stays on this computer.', { name: BRAND_NAME })}
73
+ </p>
74
+ <div className="mt-6">
75
+ <LlmSettingsPanel
76
+ ref={panel}
77
+ showFooterSave
78
+ onSaved={() => {
79
+ void getLlmCredential().then((status) => {
80
+ if (setupDecision(status) === 'chat') navigate('/', { replace: true });
81
+ });
82
+ }}
83
+ />
84
+ </div>
85
+ <button
86
+ type="button"
87
+ className="mt-4 text-xs text-agent-muted-foreground underline underline-offset-2 hover:text-agent-foreground"
88
+ onClick={() => navigate('/', { replace: true })}
89
+ >
90
+ {t('Set up later')}
91
+ </button>
92
+ </div>
93
+ </div>
94
+ );
95
+ }
package/src/vite-env.d.ts CHANGED
@@ -7,6 +7,7 @@ interface ImportMetaEnv {
7
7
  readonly VITE_BRAND_TAGLINE?: string;
8
8
  /** 新对话落地页副文案。空字符串表示不显示。 */
9
9
  readonly VITE_BRAND_HOME_HINT?: string;
10
+ readonly VITE_BRAND_FIRST_RUN?: string;
10
11
  readonly VITE_DEFAULT_AGENT_ID?: string;
11
12
  readonly VITE_HOST_TOOLS?: string;
12
13
  readonly VITE_APPROVAL?: string;
package/vite.base.js CHANGED
@@ -54,6 +54,8 @@ export function createProductViteConfig(options) {
54
54
  'import.meta.env.VITE_BRAND_TAGLINE': JSON.stringify(brand?.tagline ?? 'A local desktop AI partner'),
55
55
  'import.meta.env.VITE_BRAND_HOME_HINT': JSON.stringify(brand?.homeHint ?? 'Type a message to start a new chat.'),
56
56
  'import.meta.env.VITE_DEFAULT_AGENT_ID': JSON.stringify(brand?.defaultAgentId ?? 'local-assistant'),
57
+ // 首启配置页:只有中性 shell 打开;产品声明了自己的品牌即缺省关闭。
58
+ 'import.meta.env.VITE_BRAND_FIRST_RUN': JSON.stringify(brand?.firstRunSetup === true ? 'true' : 'false'),
57
59
  // 宿主工具族 / 安全询问:与 node 侧 setProductConfig 读同一份 product.json。
58
60
  'import.meta.env.VITE_HOST_TOOLS': JSON.stringify(JSON.stringify(product.hostTools ?? {})),
59
61
  'import.meta.env.VITE_APPROVAL': JSON.stringify(product.approval ?? 'host'),