67 lines
10 KiB
Go
67 lines
10 KiB
Go
package main
|
|
|
|
const chatinputCategory = "Chat Input"
|
|
|
|
var chatinputPages = []page{
|
|
{ID: "221", Name: "PromptComposer", ZhName: "提示编辑器", Category: chatinputCategory, Demo: chatinputDemoPromptComposer,
|
|
Keys: "Enter 发送,Shift+Enter 换行;CmdEnterSends 下使用 Command/Ctrl+Enter;组合保护期间 Enter 留给输入法。",
|
|
Code: "var prompt string\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tr := chat.PromptComposer(c, &prompt, chat.PromptComposerOptions{Placeholder: \"Ask the herald\"})\n\tif r.Submitted() {\n\t\tfmt.Println(\"send\", prompt)\n\t\tprompt = \"\"\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "222", Name: "AttachmentChip", ZhName: "附件标签", Category: chatinputCategory, Demo: chatinputDemoAttachmentChip,
|
|
Keys: "Tab 到移除与重试;Enter、Space 激活。",
|
|
Code: "view := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tr := chat.AttachmentChip(c, chat.Attachment{Name: \"guests.csv\", Size: 4096, Uploading: true, Progress: 0.4})\n\tif r.Removed() {\n\t\tfmt.Println(\"cancel the upload\")\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "223", Name: "PasteImagePreview", ZhName: "图片预览", Category: chatinputCategory, Demo: chatinputDemoPasteImagePreview,
|
|
Keys: "Tab 到移除按钮;Enter、Space 移除。",
|
|
Code: "pic := ui.MustParseSVG([]byte(`<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"4\" height=\"3\"/>`))\nimages := []chat.PastedImage{{ID: \"p1\", Source: pic, Name: \"screenshot\"}}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tif id, ok := chat.PasteImagePreview(c, images).Removed(); ok {\n\t\tfmt.Println(\"remove\", id)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "224", Name: "DragDropOverlay", ZhName: "拖放遮罩", Category: chatinputCategory, Demo: chatinputDemoDragDropOverlay,
|
|
Keys: "内容中的操作按其自身键盘规则访问;文件拖入由操作系统驱动。",
|
|
Code: "view := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\timages := func(path string) bool { return strings.HasSuffix(path, \".png\") }\n\tr := chat.DragDropOverlay(c, chat.DragDropOverlayOptions{Accept: images}, func() {\n\t\tui.Text(c, \"Drag images into the chat\")\n\t})\n\tfor _, path := range r.Accepted() {\n\t\tfmt.Println(\"attach\", path)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "225", Name: "VoiceInputButton", ZhName: "语音输入按钮", Category: chatinputCategory, Demo: chatinputDemoVoiceInputButton,
|
|
Keys: "Tab 到按钮;Enter、Space 开始或停止。",
|
|
Code: "var rec chat.VoiceInputOptions\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tif chat.VoiceInputButton(c, rec).Changed() {\n\t\trec = chat.VoiceInputOptions{Recording: !rec.Recording, Started: time.Now()}\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "226", Name: "VoiceWaveform", ZhName: "输入波形", Category: chatinputCategory, Demo: chatinputDemoVoiceWaveform,
|
|
Keys: "展示组件,沿用外层 Tab 顺序。",
|
|
Code: "levels := []float32{0.2, 0.6, 0.9, 0.4, 0.1}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tchat.VoiceWaveform(c, levels, chat.VoiceWaveformOptions{})\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "227", Name: "SlashCommandMenu", ZhName: "斜杠命令菜单", Category: chatinputCategory, Demo: chatinputDemoSlashCommandMenu,
|
|
Keys: "编辑器内 Up/Down 选择,Enter 选中,Tab 补全,Escape 关闭。",
|
|
Code: "var prompt string\ncommands := []chat.SlashCommand{{Name: \"summarize\", Description: \"Summarize the thread\"}}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tcomposer := chat.PromptComposer(c, &prompt, chat.PromptComposerOptions{})\n\tif cmd, ok := chat.SlashCommandMenu(c, composer, &prompt, commands).Chosen(); ok {\n\t\tfmt.Println(\"run\", cmd.Name)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "228", Name: "ContextMentionMenu", ZhName: "上下文提及菜单", Category: chatinputCategory, Demo: chatinputDemoContextMentionMenu,
|
|
Keys: "编辑器内 Up/Down 选择,Enter 或 Tab 附加,Escape 关闭。",
|
|
Code: "var prompt string\nvar found []chat.ContextItem\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tcomposer := chat.PromptComposer(c, &prompt, chat.PromptComposerOptions{})\n\tr := chat.ContextMentionMenu(c, composer, &prompt, found, chat.ContextMentionOptions{})\n\tif r.QueryChanged() {\n\t\tfound = []chat.ContextItem{{ID: \"f1\", Label: r.Query() + \".md\", Kind: chat.ContextFile}}\n\t}\n\tif item, ok := r.Chosen(); ok {\n\t\tfmt.Println(\"attach\", item.ID)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "229", Name: "ContextChips", ZhName: "上下文标签", Category: chatinputCategory, Demo: chatinputDemoContextChips,
|
|
Keys: "Tab 到移除与展开;Enter、Space 激活。",
|
|
Code: "items := []chat.ContextItem{{ID: \"f1\", Label: \"guests.csv\", Kind: chat.ContextFile}}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tif id, ok := chat.ContextChips(c, items, chat.ContextChipsOptions{}).Removed(); ok {\n\t\tfmt.Println(\"detach\", id)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "230", Name: "ModelSelector", ZhName: "模型选择器", Category: chatinputCategory, Demo: chatinputDemoModelSelector,
|
|
Keys: "Tab 到选择器;Up/Down、Home/End 选择,Enter/Space 确认,Escape 关闭。",
|
|
Code: "model := \"herald\"\nmodels := []chat.ModelOption{{ID: \"herald\", Name: \"Herald 2\", Capabilities: []string{\"Vision\"}, ContextTokens: 200000}}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tif chat.ModelSelector(c, &model, models, chat.ModelSelectorOptions{}).Changed() {\n\t\tfmt.Println(\"model\", model)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "231", Name: "ModeSelector", ZhName: "模式选择器", Category: chatinputCategory, Demo: chatinputDemoModeSelector,
|
|
Keys: "Tab 进入模式组;Left/Right 切换模式。",
|
|
Code: "mode := chat.ModeChat\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tif chat.ModeSelector(c, &mode, chat.ModeSelectorOptions{}).Changed() {\n\t\tfmt.Println(\"mode\", mode)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "232", Name: "ToolToggleMenu", ZhName: "工具开关菜单", Category: chatinputCategory, Demo: chatinputDemoToolToggleMenu,
|
|
Keys: "Tab 到菜单按钮;Enter/Space 打开;Tab 到开关与授权;Escape 关闭。",
|
|
Code: "web := true\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\ttools := []chat.ToolItem{{ID: \"web\", Label: \"Web search\", On: &web}}\n\tif id, ok := chat.ToolToggleMenu(c, tools).Changed(); ok {\n\t\tfmt.Println(\"toggled\", id)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "233", Name: "ParameterPanel", ZhName: "参数面板", Category: chatinputCategory, Demo: chatinputDemoParameterPanel,
|
|
Keys: "Tab 到滑块与重置;方向键按 Step 调整,Home/End 到范围端点;Enter/Space 重置。",
|
|
Code: "temperature := 1.0\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tparams := []chat.ModelParam{{Label: \"Temperature\", Value: &temperature, Min: 0, Max: 2, Step: 0.1, Default: 1}}\n\tchat.ParameterPanel(c, params)\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "234", Name: "TokenCounter", ZhName: "Token计数", Category: chatinputCategory, Demo: chatinputDemoTokenCounter,
|
|
Keys: "展示组件,沿用外层 Tab 顺序。",
|
|
Code: "view := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tchat.TokenCounter(c, 1234, 8000)\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "235", Name: "ContextWindowMeter", ZhName: "上下文容量", Category: chatinputCategory, Demo: chatinputDemoContextWindowMeter,
|
|
Keys: "展示组件,沿用外层 Tab 顺序。",
|
|
Code: "segments := []chat.ContextSegment{{Label: \"System\", Tokens: 1200}, {Label: \"History\", Tokens: 58000}}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tchat.ContextWindowMeter(c, segments, 128000, chat.ContextWindowMeterOptions{})\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "236", Name: "SendButton", ZhName: "发送按钮", Category: chatinputCategory, Demo: chatinputDemoSendButton,
|
|
Keys: "Tab 到按钮;Enter、Space 激活;快捷键提示由调用方绑定。",
|
|
Code: "streaming := false\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tr := chat.SendButton(c, chat.SendButtonOptions{Streaming: streaming, Shortcut: \"Enter\"})\n\tif r.Sent() || r.Stopped() {\n\t\tstreaming = r.Sent()\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "237", Name: "CitationBadge", ZhName: "引用编号", Category: chatinputCategory, Demo: chatinputDemoCitationBadge,
|
|
Keys: "Tab 到引用;Enter、Space 定位;悬停或键盘焦点 500 毫秒后预览;Escape 关闭预览。",
|
|
Code: "var cites chat.CitationState\nsrc := chat.Source{Title: \"The Palace of Versailles\", URL: \"https://example.com/versailles\"}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tif chat.CitationBadge(c, 1, src, &cites).Changed() {\n\t\tfmt.Println(\"show source\", cites.Active)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "238", Name: "SourceCard", ZhName: "来源卡片", Category: chatinputCategory, Demo: chatinputDemoSourceCard,
|
|
Keys: "Tab 到卡片;Enter、Space 请求打开。",
|
|
Code: "var cites chat.CitationState\nsrc := chat.Source{Title: \"Hall of Mirrors\", URL: \"https://example.org/hall\", Snippet: \"Seventeen arches.\"}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tif chat.SourceCard(c, 1, src, &cites).Clicked() {\n\t\tfmt.Println(\"open\", src.URL)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "239", Name: "SourcesPanel", ZhName: "来源面板", Category: chatinputCategory, Demo: chatinputDemoSourcesPanel,
|
|
Keys: "Tab 到可见来源;Enter、Space 请求打开;滚轮滚动;Active 变化定位来源。",
|
|
Code: "var cites chat.CitationState\nsources := []chat.Source{{Title: \"Hall of Mirrors\", URL: \"https://example.org/hall\"}}\nview := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tif n, ok := chat.SourcesPanel(c, sources, &cites).Opened(); ok {\n\t\tfmt.Println(\"open\", sources[n-1].URL)\n\t}\n}\nui.Render(view, 400, 300, 1)"},
|
|
{ID: "240", Name: "SearchProgress", ZhName: "搜索进度", Category: chatinputCategory, Demo: chatinputDemoSearchProgress,
|
|
Keys: "Tab 到折叠标题;Enter、Space 展开或收起。",
|
|
Code: "view := func(c *ui.Context) {\n\tcore.Use(c, core.Settings{})\n\tstages := []chat.SearchStage{{Label: \"Searching the web\", Done: true}, {Label: \"Reading sources\"}}\n\tchat.SearchProgress(c, chat.SearchProgressOptions{Query: \"Versailles\", Read: 3, Total: 8, Stages: stages})\n}\nui.Render(view, 400, 300, 1)"},
|
|
}
|