@steerable/agent-shell-web 0.12.4 → 0.12.6

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.
@@ -70,7 +70,13 @@ import {
70
70
  } from "@/lib/pending-first-message";
71
71
  import { readOrchestrationSetting } from "@/lib/orchestration-settings";
72
72
  import { pickDefaultAgentId } from "@/brand";
73
- import { t } from "@/i18n";
73
+ import { isDemoMode } from "@/lib/demo-flag";
74
+ import {
75
+ DEMO_STARTER_PROMPTS_EN,
76
+ DEMO_STARTER_PROMPTS_ZH,
77
+ type DemoStarterPrompt,
78
+ } from "@/lib/demo-playbook";
79
+ import { getLocale, t } from "@/i18n";
74
80
  import {
75
81
  appendAttachmentRefs,
76
82
  collectImageAttachments,
@@ -1751,77 +1757,106 @@ function EmptyChatGate() {
1751
1757
  [ctx],
1752
1758
  );
1753
1759
 
1754
- const handleSubmit = useCallback(async () => {
1755
- if (isCreating) return;
1756
- const rawText = inputValue.trim();
1757
- if (!rawText && files.length === 0) return;
1758
- trackBehavior('composer_send', {
1759
- empty: false,
1760
- home: true,
1761
- mode: mode === 'plan' ? 'plan' : 'agent',
1762
- execPolicy,
1763
- length: rawText.length,
1764
- });
1765
-
1766
- const mentionedAgentIds = mentionReferences
1767
- .filter((ref) => ref.type === "agent")
1768
- .map((ref) => ref.id);
1769
- const referencedChatIds = mentionReferences
1770
- .filter((ref) => ref.type === "chat")
1771
- .map((ref) => ref.id);
1772
- // 文件路径引用与图像元数据在会话建好、附件落盘之后再装配(见下)——
1773
- // 落地页提交时还没有 chatId,不能像旧代码那样直接用 `f.path`(浏览器
1774
- // 模式下它是空串,会把一条空引用写进正文,模型以为收到了文件却读不到)。
1775
- const baseMetadata = {
1776
- ...(mode === "plan" ? { mode: "plan" as const } : {}),
1777
- ...(execPolicy === "full" ? { execPolicy: "full" as const } : {}),
1778
- ...(ctx.selectedAgentId ? { agentId: ctx.selectedAgentId } : {}),
1779
- ...(mentionedAgentIds.length > 0 ? { mentionedAgentIds } : {}),
1780
- ...(referencedChatIds.length > 0 ? { referencedChatIds } : {}),
1781
- ...(modelOverride ? { model: modelOverride } : {}),
1782
- ...(effortOverride ? { reasoningEffort: effortOverride } : {}),
1783
- };
1760
+ const submitPrompt = useCallback(
1761
+ async (rawText: string, overrideMode?: ChatMode) => {
1762
+ if (isCreating) return;
1763
+ const trimmed = rawText.trim();
1764
+ const effectiveMode = overrideMode ?? mode;
1765
+ if (!trimmed && files.length === 0) return;
1766
+ trackBehavior('composer_send', {
1767
+ empty: false,
1768
+ home: true,
1769
+ mode: effectiveMode === 'plan' ? 'plan' : 'agent',
1770
+ execPolicy,
1771
+ length: trimmed.length,
1772
+ });
1784
1773
 
1785
- setIsCreating(true);
1786
- setCreateError(null);
1787
- try {
1788
- const id = await ctx.createChat({
1789
- ...(selectedProjectId && showProjectsChrome ? { projectId: selectedProjectId } : {}),
1774
+ const mentionedAgentIds = mentionReferences
1775
+ .filter((ref) => ref.type === "agent")
1776
+ .map((ref) => ref.id);
1777
+ const referencedChatIds = mentionReferences
1778
+ .filter((ref) => ref.type === "chat")
1779
+ .map((ref) => ref.id);
1780
+ // 文件路径引用与图像元数据在会话建好、附件落盘之后再装配(见下)——
1781
+ // 落地页提交时还没有 chatId,不能像旧代码那样直接用 `f.path`(浏览器
1782
+ // 模式下它是空串,会把一条空引用写进正文,模型以为收到了文件却读不到)。
1783
+ const baseMetadata = {
1784
+ ...(effectiveMode === "plan" ? { mode: "plan" as const } : {}),
1785
+ ...(execPolicy === "full" ? { execPolicy: "full" as const } : {}),
1790
1786
  ...(ctx.selectedAgentId ? { agentId: ctx.selectedAgentId } : {}),
1791
- });
1792
- if (!id) throw new Error(t("Failed to create the chat. Please try again."));
1793
- // 会话已建,把附件落进会话空间(与 LocalChatPanel 同一套语义):
1794
- // 所有文件都写落盘路径引用(agent 用 local_read_file 读回);仅图片
1795
- // 额外进 metadata.images 走多模态,非图片文件不会被图片逻辑吞掉。
1796
- const { files: resolvedFiles, failures } = await saveChatAttachments(id, files);
1797
- if (failures.length > 0) {
1798
- // 落地页一旦跳转就没法让用户重试了,所以这里宁可中止本次发送:
1799
- // 删掉刚建的空会话,保留输入框(含失败文件),把原因显示出来。
1800
- await ctx.deleteChat(id);
1801
- setCreateError(formatAttachmentFailures(failures));
1787
+ ...(mentionedAgentIds.length > 0 ? { mentionedAgentIds } : {}),
1788
+ ...(referencedChatIds.length > 0 ? { referencedChatIds } : {}),
1789
+ ...(modelOverride ? { model: modelOverride } : {}),
1790
+ ...(effortOverride ? { reasoningEffort: effortOverride } : {}),
1791
+ };
1792
+
1793
+ setIsCreating(true);
1794
+ setCreateError(null);
1795
+ try {
1796
+ const id = await ctx.createChat({
1797
+ ...(selectedProjectId && showProjectsChrome ? { projectId: selectedProjectId } : {}),
1798
+ ...(ctx.selectedAgentId ? { agentId: ctx.selectedAgentId } : {}),
1799
+ });
1800
+ if (!id) throw new Error(t("Failed to create the chat. Please try again."));
1801
+ // 会话已建,把附件落进会话空间(与 LocalChatPanel 同一套语义):
1802
+ // 所有文件都写落盘路径引用(agent 用 local_read_file 读回);仅图片
1803
+ // 额外进 metadata.images 走多模态,非图片文件不会被图片逻辑吞掉。
1804
+ const { files: resolvedFiles, failures } = await saveChatAttachments(id, files);
1805
+ if (failures.length > 0) {
1806
+ // 落地页一旦跳转就没法让用户重试了,所以这里宁可中止本次发送:
1807
+ // 删掉刚建的空会话,保留输入框(含失败文件),把原因显示出来。
1808
+ await ctx.deleteChat(id);
1809
+ setCreateError(formatAttachmentFailures(failures));
1810
+ setIsCreating(false);
1811
+ return;
1812
+ }
1813
+
1814
+ const content = appendAttachmentRefs(trimmed, resolvedFiles);
1815
+ const imageAttachments = collectImageAttachments(resolvedFiles);
1816
+ const metadata = {
1817
+ ...baseMetadata,
1818
+ ...(imageAttachments.length > 0 ? { images: imageAttachments } : {}),
1819
+ };
1820
+
1821
+ setPendingFirstMessage({
1822
+ chatId: id,
1823
+ content,
1824
+ metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
1825
+ });
1826
+ navigate(`/agent/${id}`);
1827
+ // 跳转成功后组件即卸载,不用清 isCreating;失败才恢复可交互。
1828
+ } catch (err) {
1829
+ setCreateError(err instanceof Error ? err.message : String(err));
1802
1830
  setIsCreating(false);
1803
- return;
1804
1831
  }
1832
+ },
1833
+ [
1834
+ inputValue,
1835
+ files,
1836
+ mentionReferences,
1837
+ mode,
1838
+ execPolicy,
1839
+ modelOverride,
1840
+ effortOverride,
1841
+ isCreating,
1842
+ selectedProjectId,
1843
+ showProjectsChrome,
1844
+ ctx,
1845
+ navigate,
1846
+ ],
1847
+ );
1805
1848
 
1806
- const content = appendAttachmentRefs(rawText, resolvedFiles);
1807
- const imageAttachments = collectImageAttachments(resolvedFiles);
1808
- const metadata = {
1809
- ...baseMetadata,
1810
- ...(imageAttachments.length > 0 ? { images: imageAttachments } : {}),
1811
- };
1812
-
1813
- setPendingFirstMessage({
1814
- chatId: id,
1815
- content,
1816
- metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
1817
- });
1818
- navigate(`/agent/${id}`);
1819
- // 跳转成功后组件即卸载,不用清 isCreating;失败才恢复可交互。
1820
- } catch (err) {
1821
- setCreateError(err instanceof Error ? err.message : String(err));
1822
- setIsCreating(false);
1823
- }
1824
- }, [inputValue, files, mentionReferences, mode, execPolicy, modelOverride, effortOverride, isCreating, selectedProjectId, ctx, navigate]);
1849
+ const handleSubmit = useCallback(async () => {
1850
+ await submitPrompt(inputValue);
1851
+ }, [submitPrompt, inputValue]);
1852
+
1853
+ const demoStarters: readonly DemoStarterPrompt[] = useMemo(() => {
1854
+ if (!isDemoMode()) return [];
1855
+ const prefersZh =
1856
+ getLocale().startsWith('zh') ||
1857
+ (typeof navigator !== 'undefined' && /^zh/i.test(navigator.language || ''));
1858
+ return prefersZh ? DEMO_STARTER_PROMPTS_ZH : DEMO_STARTER_PROMPTS_EN;
1859
+ }, []);
1825
1860
 
1826
1861
  return (
1827
1862
  <div
@@ -1887,6 +1922,32 @@ function EmptyChatGate() {
1887
1922
  onMentionReferencesChange={setMentionReferences}
1888
1923
  />
1889
1924
  </div>
1925
+ {demoStarters.length > 0 && (
1926
+ <div
1927
+ className="grid w-full grid-cols-1 gap-2 sm:grid-cols-2"
1928
+ data-testid="demo-playbook-starters"
1929
+ >
1930
+ {demoStarters.map((item) => (
1931
+ <button
1932
+ key={item.id}
1933
+ type="button"
1934
+ disabled={isCreating}
1935
+ onClick={() => void submitPrompt(item.prompt, item.mode)}
1936
+ className="group flex flex-col items-start gap-1 rounded-agent-md border border-agent-border bg-agent-canvas px-3 py-2.5 text-left transition-colors hover:border-agent-foreground/40 hover:bg-agent-muted/60 disabled:cursor-not-allowed disabled:opacity-60"
1937
+ >
1938
+ <span className="flex w-full items-center justify-between gap-2 text-xs font-semibold text-agent-foreground">
1939
+ <span>{item.title}</span>
1940
+ <span className="shrink-0 rounded border border-agent-border bg-agent-muted px-1.5 py-0.5 font-mono text-[10px] font-medium text-agent-muted-foreground">
1941
+ {item.tag}
1942
+ </span>
1943
+ </span>
1944
+ <span className="line-clamp-2 text-[11px] leading-relaxed text-agent-muted-foreground">
1945
+ {item.summary}
1946
+ </span>
1947
+ </button>
1948
+ ))}
1949
+ </div>
1950
+ )}
1890
1951
  {isCreating && (
1891
1952
  <p className="text-xs text-agent-muted-foreground">
1892
1953
  {t("Creating chat…")}
package/vite.base.js CHANGED
@@ -72,6 +72,9 @@ export function createProductViteConfig(options) {
72
72
  // shell 渲染层源码(产品入口与包 web 模块都以 `@/` 引用它)。
73
73
  '@': webSrcDir,
74
74
  },
75
+ // 跨仓 `shell:link` 时产品与 shell 各自有独立 node_modules;必须去重
76
+ // React 与 Router,否则 AppShell 的 <Outlet /> 会读到另一份 Context 而白屏。
77
+ dedupe: ['react', 'react-dom', 'react-router-dom'],
75
78
  },
76
79
  // 静态资产(favicon 等中性默认)随 shell web 包分发;产品可在自己的
77
80
  // web root 放 public/ 覆盖(vite 不合并双 publicDir——需要产品级资产