@agent-native/core 0.79.1 → 0.79.5
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/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +30 -0
- package/corpus/core/docs/content/locales/zh-TW/a2a-protocol.md +392 -0
- package/corpus/core/docs/content/locales/zh-TW/actions.md +583 -0
- package/corpus/core/docs/content/locales/zh-TW/agent-mentions.md +164 -0
- package/corpus/core/docs/content/locales/zh-TW/agent-surfaces.md +397 -0
- package/corpus/core/docs/content/locales/zh-TW/agent-teams.md +171 -0
- package/corpus/core/docs/content/locales/zh-TW/agent-web-surfaces.md +161 -0
- package/corpus/core/docs/content/locales/zh-TW/audit-log.md +111 -0
- package/corpus/core/docs/content/locales/zh-TW/authentication.md +332 -0
- package/corpus/core/docs/content/locales/zh-TW/automations.md +268 -0
- package/corpus/core/docs/content/locales/zh-TW/blueprint-installer.md +83 -0
- package/corpus/core/docs/content/locales/zh-TW/cli-adapters.md +129 -0
- package/corpus/core/docs/content/locales/zh-TW/client.md +398 -0
- package/corpus/core/docs/content/locales/zh-TW/cloneable-saas.md +114 -0
- package/corpus/core/docs/content/locales/zh-TW/code-agents-ui.md +436 -0
- package/corpus/core/docs/content/locales/zh-TW/components.md +368 -0
- package/corpus/core/docs/content/locales/zh-TW/context-awareness.md +373 -0
- package/corpus/core/docs/content/locales/zh-TW/creating-templates.md +411 -0
- package/corpus/core/docs/content/locales/zh-TW/cross-app-sso.md +188 -0
- package/corpus/core/docs/content/locales/zh-TW/database.md +183 -0
- package/corpus/core/docs/content/locales/zh-TW/deployment.md +348 -0
- package/corpus/core/docs/content/locales/zh-TW/dispatch.md +146 -0
- package/corpus/core/docs/content/locales/zh-TW/drop-in-agent.md +260 -0
- package/corpus/core/docs/content/locales/zh-TW/durable-resume.md +65 -0
- package/corpus/core/docs/content/locales/zh-TW/embedding-sdk.md +597 -0
- package/corpus/core/docs/content/locales/zh-TW/evals.md +155 -0
- package/corpus/core/docs/content/locales/zh-TW/extensions.md +360 -0
- package/corpus/core/docs/content/locales/zh-TW/external-agents.md +619 -0
- package/corpus/core/docs/content/locales/zh-TW/faq.md +142 -0
- package/corpus/core/docs/content/locales/zh-TW/file-uploads.md +122 -0
- package/corpus/core/docs/content/locales/zh-TW/frames.md +153 -0
- package/corpus/core/docs/content/locales/zh-TW/getting-started.md +199 -0
- package/corpus/core/docs/content/locales/zh-TW/harness-agents.md +349 -0
- package/corpus/core/docs/content/locales/zh-TW/human-approval.md +86 -0
- package/corpus/core/docs/content/locales/zh-TW/internationalization.md +147 -0
- package/corpus/core/docs/content/locales/zh-TW/key-concepts.md +312 -0
- package/corpus/core/docs/content/locales/zh-TW/local-file-mode.md +433 -0
- package/corpus/core/docs/content/locales/zh-TW/mcp-apps.md +147 -0
- package/corpus/core/docs/content/locales/zh-TW/mcp-clients.md +330 -0
- package/corpus/core/docs/content/locales/zh-TW/mcp-protocol.md +279 -0
- package/corpus/core/docs/content/locales/zh-TW/messaging.md +461 -0
- package/corpus/core/docs/content/locales/zh-TW/migration-workbench.md +33 -0
- package/corpus/core/docs/content/locales/zh-TW/multi-app-workspace.md +312 -0
- package/corpus/core/docs/content/locales/zh-TW/multi-tenancy.md +52 -0
- package/corpus/core/docs/content/locales/zh-TW/native-chat-ui.md +321 -0
- package/corpus/core/docs/content/locales/zh-TW/notifications.md +231 -0
- package/corpus/core/docs/content/locales/zh-TW/observability.md +294 -0
- package/corpus/core/docs/content/locales/zh-TW/observational-memory.md +77 -0
- package/corpus/core/docs/content/locales/zh-TW/onboarding.md +216 -0
- package/corpus/core/docs/content/locales/zh-TW/plan-plugin.md +200 -0
- package/corpus/core/docs/content/locales/zh-TW/pr-visual-recap.md +384 -0
- package/corpus/core/docs/content/locales/zh-TW/processors.md +106 -0
- package/corpus/core/docs/content/locales/zh-TW/progress.md +199 -0
- package/corpus/core/docs/content/locales/zh-TW/pure-agent-apps.md +39 -0
- package/corpus/core/docs/content/locales/zh-TW/real-time-collaboration.md +680 -0
- package/corpus/core/docs/content/locales/zh-TW/recurring-jobs.md +142 -0
- package/corpus/core/docs/content/locales/zh-TW/routing.md +79 -0
- package/corpus/core/docs/content/locales/zh-TW/sandbox-adapters.md +227 -0
- package/corpus/core/docs/content/locales/zh-TW/security.md +330 -0
- package/corpus/core/docs/content/locales/zh-TW/server.md +265 -0
- package/corpus/core/docs/content/locales/zh-TW/sharing.md +219 -0
- package/corpus/core/docs/content/locales/zh-TW/skills-guide.md +281 -0
- package/corpus/core/docs/content/locales/zh-TW/template-analytics.md +259 -0
- package/corpus/core/docs/content/locales/zh-TW/template-assets.md +303 -0
- package/corpus/core/docs/content/locales/zh-TW/template-brain.md +324 -0
- package/corpus/core/docs/content/locales/zh-TW/template-calendar.md +194 -0
- package/corpus/core/docs/content/locales/zh-TW/template-chat.md +129 -0
- package/corpus/core/docs/content/locales/zh-TW/template-clips.md +368 -0
- package/corpus/core/docs/content/locales/zh-TW/template-content.md +402 -0
- package/corpus/core/docs/content/locales/zh-TW/template-design.md +173 -0
- package/corpus/core/docs/content/locales/zh-TW/template-dispatch.md +220 -0
- package/corpus/core/docs/content/locales/zh-TW/template-forms.md +178 -0
- package/corpus/core/docs/content/locales/zh-TW/template-mail.md +239 -0
- package/corpus/core/docs/content/locales/zh-TW/template-plan.md +814 -0
- package/corpus/core/docs/content/locales/zh-TW/template-slides.md +293 -0
- package/corpus/core/docs/content/locales/zh-TW/template-videos.md +222 -0
- package/corpus/core/docs/content/locales/zh-TW/tracking.md +236 -0
- package/corpus/core/docs/content/locales/zh-TW/using-your-agent.md +71 -0
- package/corpus/core/docs/content/locales/zh-TW/voice-input.md +81 -0
- package/corpus/core/docs/content/locales/zh-TW/what-is-agent-native.md +202 -0
- package/corpus/core/docs/content/locales/zh-TW/workspace-connections.md +321 -0
- package/corpus/core/docs/content/locales/zh-TW/workspace-management.md +175 -0
- package/corpus/core/docs/content/locales/zh-TW/workspace.md +323 -0
- package/corpus/core/docs/content/locales/zh-TW/writing-agent-instructions.md +173 -0
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/client/ErrorBoundary.tsx +10 -0
- package/corpus/core/src/client/FeedbackButton.tsx +12 -0
- package/corpus/core/src/client/blocks/library/block-copy.ts +32 -0
- package/corpus/core/src/client/extensions/ExtensionsSidebarSection.tsx +33 -0
- package/corpus/core/src/client/i18n.tsx +5 -0
- package/corpus/core/src/localization/actions/set-localization-preference.ts +2 -1
- package/corpus/core/src/localization/shared.ts +45 -0
- package/corpus/core/src/server/agent-chat-plugin.ts +54 -2
- package/corpus/core/src/server/onboarding-html.ts +99 -0
- package/corpus/core/src/templates/default/app/i18n/index.ts +2 -0
- package/corpus/core/src/templates/default/app/i18n/zh-TW.ts +466 -0
- package/corpus/core/src/templates/default/app/root.tsx +8 -0
- package/corpus/templates/analytics/app/i18n/index.ts +2 -0
- package/corpus/templates/analytics/app/i18n/zh-TW.ts +818 -0
- package/corpus/templates/analytics/app/i18n-data.ts +9 -0
- package/corpus/templates/assets/app/i18n/index.ts +2 -0
- package/corpus/templates/assets/app/i18n/zh-TW.ts +860 -0
- package/corpus/templates/assets/app/i18n-data.ts +3 -0
- package/corpus/templates/brain/app/i18n/index.ts +2 -0
- package/corpus/templates/brain/app/i18n/zh-TW.ts +709 -0
- package/corpus/templates/brain/app/i18n-data.ts +3 -0
- package/corpus/templates/calendar/app/i18n/zh-TW.ts +836 -0
- package/corpus/templates/calendar/app/i18n-data.ts +4 -0
- package/corpus/templates/chat/app/i18n/index.ts +2 -0
- package/corpus/templates/chat/app/i18n/zh-TW.ts +67 -0
- package/corpus/templates/chat/app/i18n-data.ts +3 -0
- package/corpus/templates/clips/app/i18n/index.ts +2 -0
- package/corpus/templates/clips/app/i18n/zh-TW.ts +1280 -0
- package/corpus/templates/content/app/i18n/index.ts +2 -0
- package/corpus/templates/content/app/i18n/zh-TW.ts +906 -0
- package/corpus/templates/content/app/i18n-data.ts +4 -0
- package/corpus/templates/design/app/i18n/index.ts +2 -0
- package/corpus/templates/design/app/i18n/zh-TW.ts +517 -0
- package/corpus/templates/design/app/i18n-data.ts +6 -0
- package/corpus/templates/dispatch/app/i18n/index.ts +2 -0
- package/corpus/templates/dispatch/app/i18n/zh-TW.ts +195 -0
- package/corpus/templates/dispatch/app/i18n-data.ts +3 -0
- package/corpus/templates/forms/app/i18n/index.ts +2 -0
- package/corpus/templates/forms/app/i18n/zh-TW.ts +349 -0
- package/corpus/templates/macros/app/i18n/index.ts +2 -0
- package/corpus/templates/macros/app/i18n/zh-TW.ts +224 -0
- package/corpus/templates/mail/app/i18n/index.ts +2 -0
- package/corpus/templates/mail/app/i18n/zh-TW.ts +562 -0
- package/corpus/templates/mail/app/root.tsx +6 -0
- package/corpus/templates/plan/app/i18n/index.ts +2 -0
- package/corpus/templates/plan/app/i18n/zh-TW.ts +712 -0
- package/corpus/templates/slides/app/i18n/index.ts +2 -0
- package/corpus/templates/slides/app/i18n/zh-TW.ts +531 -0
- package/corpus/templates/videos/app/i18n/index.ts +2 -0
- package/corpus/templates/videos/app/i18n/zh-TW.ts +435 -0
- package/dist/client/ErrorBoundary.d.ts.map +1 -1
- package/dist/client/ErrorBoundary.js +10 -0
- package/dist/client/ErrorBoundary.js.map +1 -1
- package/dist/client/FeedbackButton.d.ts.map +1 -1
- package/dist/client/FeedbackButton.js +12 -0
- package/dist/client/FeedbackButton.js.map +1 -1
- package/dist/client/blocks/library/block-copy.d.ts.map +1 -1
- package/dist/client/blocks/library/block-copy.js +32 -0
- package/dist/client/blocks/library/block-copy.js.map +1 -1
- package/dist/client/extensions/ExtensionsSidebarSection.d.ts.map +1 -1
- package/dist/client/extensions/ExtensionsSidebarSection.js +32 -0
- package/dist/client/extensions/ExtensionsSidebarSection.js.map +1 -1
- package/dist/client/i18n.d.ts.map +1 -1
- package/dist/client/i18n.js +5 -0
- package/dist/client/i18n.js.map +1 -1
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/awareness.d.ts.map +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/localization/actions/set-localization-preference.d.ts.map +1 -1
- package/dist/localization/actions/set-localization-preference.js +2 -2
- package/dist/localization/actions/set-localization-preference.js.map +1 -1
- package/dist/localization/shared.d.ts +1 -1
- package/dist/localization/shared.d.ts.map +1 -1
- package/dist/localization/shared.js +43 -0
- package/dist/localization/shared.js.map +1 -1
- package/dist/resources/handlers.d.ts +2 -2
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +55 -2
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/onboarding-html.d.ts.map +1 -1
- package/dist/server/onboarding-html.js +96 -0
- package/dist/server/onboarding-html.js.map +1 -1
- package/dist/templates/default/app/i18n/index.ts +2 -0
- package/dist/templates/default/app/i18n/zh-TW.ts +466 -0
- package/dist/templates/default/app/root.tsx +8 -0
- package/docs/content/locales/zh-TW/a2a-protocol.md +392 -0
- package/docs/content/locales/zh-TW/actions.md +583 -0
- package/docs/content/locales/zh-TW/agent-mentions.md +164 -0
- package/docs/content/locales/zh-TW/agent-surfaces.md +397 -0
- package/docs/content/locales/zh-TW/agent-teams.md +171 -0
- package/docs/content/locales/zh-TW/agent-web-surfaces.md +161 -0
- package/docs/content/locales/zh-TW/audit-log.md +111 -0
- package/docs/content/locales/zh-TW/authentication.md +332 -0
- package/docs/content/locales/zh-TW/automations.md +268 -0
- package/docs/content/locales/zh-TW/blueprint-installer.md +83 -0
- package/docs/content/locales/zh-TW/cli-adapters.md +129 -0
- package/docs/content/locales/zh-TW/client.md +398 -0
- package/docs/content/locales/zh-TW/cloneable-saas.md +114 -0
- package/docs/content/locales/zh-TW/code-agents-ui.md +436 -0
- package/docs/content/locales/zh-TW/components.md +368 -0
- package/docs/content/locales/zh-TW/context-awareness.md +373 -0
- package/docs/content/locales/zh-TW/creating-templates.md +411 -0
- package/docs/content/locales/zh-TW/cross-app-sso.md +188 -0
- package/docs/content/locales/zh-TW/database.md +183 -0
- package/docs/content/locales/zh-TW/deployment.md +348 -0
- package/docs/content/locales/zh-TW/dispatch.md +146 -0
- package/docs/content/locales/zh-TW/drop-in-agent.md +260 -0
- package/docs/content/locales/zh-TW/durable-resume.md +65 -0
- package/docs/content/locales/zh-TW/embedding-sdk.md +597 -0
- package/docs/content/locales/zh-TW/evals.md +155 -0
- package/docs/content/locales/zh-TW/extensions.md +360 -0
- package/docs/content/locales/zh-TW/external-agents.md +619 -0
- package/docs/content/locales/zh-TW/faq.md +142 -0
- package/docs/content/locales/zh-TW/file-uploads.md +122 -0
- package/docs/content/locales/zh-TW/frames.md +153 -0
- package/docs/content/locales/zh-TW/getting-started.md +199 -0
- package/docs/content/locales/zh-TW/harness-agents.md +349 -0
- package/docs/content/locales/zh-TW/human-approval.md +86 -0
- package/docs/content/locales/zh-TW/internationalization.md +147 -0
- package/docs/content/locales/zh-TW/key-concepts.md +312 -0
- package/docs/content/locales/zh-TW/local-file-mode.md +433 -0
- package/docs/content/locales/zh-TW/mcp-apps.md +147 -0
- package/docs/content/locales/zh-TW/mcp-clients.md +330 -0
- package/docs/content/locales/zh-TW/mcp-protocol.md +279 -0
- package/docs/content/locales/zh-TW/messaging.md +461 -0
- package/docs/content/locales/zh-TW/migration-workbench.md +33 -0
- package/docs/content/locales/zh-TW/multi-app-workspace.md +312 -0
- package/docs/content/locales/zh-TW/multi-tenancy.md +52 -0
- package/docs/content/locales/zh-TW/native-chat-ui.md +321 -0
- package/docs/content/locales/zh-TW/notifications.md +231 -0
- package/docs/content/locales/zh-TW/observability.md +294 -0
- package/docs/content/locales/zh-TW/observational-memory.md +77 -0
- package/docs/content/locales/zh-TW/onboarding.md +216 -0
- package/docs/content/locales/zh-TW/plan-plugin.md +200 -0
- package/docs/content/locales/zh-TW/pr-visual-recap.md +384 -0
- package/docs/content/locales/zh-TW/processors.md +106 -0
- package/docs/content/locales/zh-TW/progress.md +199 -0
- package/docs/content/locales/zh-TW/pure-agent-apps.md +39 -0
- package/docs/content/locales/zh-TW/real-time-collaboration.md +680 -0
- package/docs/content/locales/zh-TW/recurring-jobs.md +142 -0
- package/docs/content/locales/zh-TW/routing.md +79 -0
- package/docs/content/locales/zh-TW/sandbox-adapters.md +227 -0
- package/docs/content/locales/zh-TW/security.md +330 -0
- package/docs/content/locales/zh-TW/server.md +265 -0
- package/docs/content/locales/zh-TW/sharing.md +219 -0
- package/docs/content/locales/zh-TW/skills-guide.md +281 -0
- package/docs/content/locales/zh-TW/template-analytics.md +259 -0
- package/docs/content/locales/zh-TW/template-assets.md +303 -0
- package/docs/content/locales/zh-TW/template-brain.md +324 -0
- package/docs/content/locales/zh-TW/template-calendar.md +194 -0
- package/docs/content/locales/zh-TW/template-chat.md +129 -0
- package/docs/content/locales/zh-TW/template-clips.md +368 -0
- package/docs/content/locales/zh-TW/template-content.md +402 -0
- package/docs/content/locales/zh-TW/template-design.md +173 -0
- package/docs/content/locales/zh-TW/template-dispatch.md +220 -0
- package/docs/content/locales/zh-TW/template-forms.md +178 -0
- package/docs/content/locales/zh-TW/template-mail.md +239 -0
- package/docs/content/locales/zh-TW/template-plan.md +814 -0
- package/docs/content/locales/zh-TW/template-slides.md +293 -0
- package/docs/content/locales/zh-TW/template-videos.md +222 -0
- package/docs/content/locales/zh-TW/tracking.md +236 -0
- package/docs/content/locales/zh-TW/using-your-agent.md +71 -0
- package/docs/content/locales/zh-TW/voice-input.md +81 -0
- package/docs/content/locales/zh-TW/what-is-agent-native.md +202 -0
- package/docs/content/locales/zh-TW/workspace-connections.md +321 -0
- package/docs/content/locales/zh-TW/workspace-management.md +175 -0
- package/docs/content/locales/zh-TW/workspace.md +323 -0
- package/docs/content/locales/zh-TW/writing-agent-instructions.md +173 -0
- package/package.json +1 -1
- package/src/templates/default/app/i18n/index.ts +2 -0
- package/src/templates/default/app/i18n/zh-TW.ts +466 -0
- package/src/templates/default/app/root.tsx +8 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "原生聊天 UI"
|
|
3
|
+
description: "操作聲明的本機聊天渲染器、可重用的 DataTable/DataChart 輸出,以及 BYO 代理執行時應如何連線到 Agent-Native 聊天。"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 原生聊天 UI
|
|
7
|
+
|
|
8
|
+
本機聊天 UI 是第一方代理輸出的應用內渲染路徑。一個
|
|
9
|
+
操作返回結構化JSON,聊天執行時識別顯式小部件
|
|
10
|
+
判別式,`<AssistantChat>`在
|
|
11
|
+
對話。您不會為
|
|
12
|
+
正常的應用聊天。
|
|
13
|
+
|
|
14
|
+
當使用者應該檢查代理所在位置的輸出時,使用本機聊天 UI
|
|
15
|
+
已經講過:查詢結果、回應見解、設定摘要,
|
|
16
|
+
批準/拒絕控制,或應用程式視圖的連結。使用[MCP Apps](/docs/mcp-apps)
|
|
17
|
+
當外部主機(例如 Claude、ChatGPT、Copilot 或 Cursor)應該渲染時
|
|
18
|
+
來自您的應用的內聯路由。
|
|
19
|
+
|
|
20
|
+
```an-diagram title="原生渲染路徑" summary="操作返回 JSON;執行時匹配顯式小部件判別式或 chatUI.renderer; AssistantChat 安裝真實的 React 元件。沒有 iframe,沒有 HTML 執行。"
|
|
21
|
+
{
|
|
22
|
+
"html": "<div class=\"diagram-render\"><div class=\"diagram-node\">Action 執行<br><small class=\"diagram-muted\">返回結構化 JSON</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-panel center\" data-rough><span class=\"diagram-pill accent\">Match</span><small class=\"diagram-muted\">explicit widget · chatUI.renderer</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-box\"><AssistantChat><br><small class=\"diagram-muted\">掛載 React widget</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-card col\"><div class=\"diagram-pill ok\">DataTable</div><div class=\"diagram-pill ok\">DataChart</div><div class=\"diagram-pill ok\">DataInsights</div></div></div>",
|
|
23
|
+
"css": ".diagram-render{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.diagram-render .center{display:flex;flex-direction:column;align-items:center;gap:4px;padding:14px}.diagram-render .col{display:flex;flex-direction:column;gap:6px;padding:12px}.diagram-render .diagram-arrow{font-size:22px;line-height:1}"
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 動作聲明的小部件 {#action-declared-widgets}
|
|
28
|
+
|
|
29
|
+
本機路徑有兩個顯式部分:
|
|
30
|
+
|
|
31
|
+
- `outputSchema` 驗證操作的回應形狀。
|
|
32
|
+
- `chatUI.renderer` 為驗證結果選取原生 React 渲染器。
|
|
33
|
+
|
|
34
|
+
內置資料渲染器使用普通的 JSON 結果和 `widget` 加上
|
|
35
|
+
匹配有效負載:
|
|
36
|
+
|
|
37
|
+
| 小部件 | 所需的有效負載 | 渲染為 |
|
|
38
|
+
| ----------------- | --------------------------- | ----------------------------- |
|
|
39
|
+
| `"data-table"` | `table` | 原生的、可重用的資料表 |
|
|
40
|
+
| `"data-chart"` | `chartSeries` | 原生條形圖、折線圖或面積圖 |
|
|
41
|
+
| `"data-insights"` | `table` 和/或 `chartSeries` | 帶有圖表/表格輸出的組合洞察卡 |
|
|
42
|
+
|
|
43
|
+
伺服器 actions 應從
|
|
44
|
+
`@agent-native/core/data-widgets`;用戶端程式碼可以從
|
|
45
|
+
`@agent-native/core/client/chat` 或 `@agent-native/core/client`。
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { defineAction } from "@agent-native/core/action";
|
|
49
|
+
import { ACTION_CHAT_UI_DATA_INSIGHTS_RENDERER } from "@agent-native/core/action-ui";
|
|
50
|
+
import {
|
|
51
|
+
createDataInsightsWidgetResult,
|
|
52
|
+
dataInsightsWidgetResultSchema,
|
|
53
|
+
} from "@agent-native/core/data-widgets";
|
|
54
|
+
|
|
55
|
+
export default defineAction({
|
|
56
|
+
description: "Analyze form responses.",
|
|
57
|
+
readOnly: true,
|
|
58
|
+
outputSchema: dataInsightsWidgetResultSchema,
|
|
59
|
+
chatUI: {
|
|
60
|
+
renderer: ACTION_CHAT_UI_DATA_INSIGHTS_RENDERER,
|
|
61
|
+
title: "Response insights",
|
|
62
|
+
},
|
|
63
|
+
run: async () =>
|
|
64
|
+
createDataInsightsWidgetResult({
|
|
65
|
+
title: "Response insights",
|
|
66
|
+
display: {
|
|
67
|
+
title: "42 responses",
|
|
68
|
+
description: "Completion rate rose this week.",
|
|
69
|
+
primaryAction: {
|
|
70
|
+
label: "Open response insights",
|
|
71
|
+
href: "/response-insights",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
chartSeries: {
|
|
75
|
+
type: "bar",
|
|
76
|
+
title: "Responses by day",
|
|
77
|
+
xKey: "day",
|
|
78
|
+
series: [{ key: "responses", label: "Responses" }],
|
|
79
|
+
data: [
|
|
80
|
+
{ day: "Mon", responses: 8 },
|
|
81
|
+
{ day: "Tue", responses: 13 },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
table: {
|
|
85
|
+
title: "Top answers",
|
|
86
|
+
columns: [
|
|
87
|
+
{ key: "answer", label: "Answer" },
|
|
88
|
+
{ key: "count", label: "Count", align: "right" },
|
|
89
|
+
],
|
|
90
|
+
rows: [
|
|
91
|
+
{ answer: "Yes", count: 31 },
|
|
92
|
+
{ answer: "No", count: 11 },
|
|
93
|
+
],
|
|
94
|
+
totalRows: 2,
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```an-callout
|
|
101
|
+
{
|
|
102
|
+
"tone": "success",
|
|
103
|
+
"body": "僅當操作聲明 `chatUI`**或**結果攜帶顯式已知的 `widget` 判別式時,渲染器才會接管。它從不形狀推斷任意物件,也從不從工具結果執行 HTML 或 JavaScript - 因此本機小部件不能成為注入向量。"
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
當使用者請求圖表、圖形、表格、趨勢或精簡報告時,應用代理
|
|
108
|
+
應該更喜歡聲明這些本機渲染器之一的操作。決賽
|
|
109
|
+
輔助文本應保持簡短並讓小部件攜帶資料;請勿複製
|
|
110
|
+
除非使用者明確要求輸入文本,否則將相同的行放入 Markdown 表中
|
|
111
|
+
匯出。
|
|
112
|
+
|
|
113
|
+
當不存在域操作但代理已檢索緊湊時,
|
|
114
|
+
真實的資料,它可以通過以下方式調用框架`render-data-widget`操作
|
|
115
|
+
相同的 `data-table`、`data-chart` 或 `data-insights` JSON 形狀。僅此操作
|
|
116
|
+
驗證並渲染小部件;它不是資料來源,不得使用
|
|
117
|
+
發明預留位置指標。
|
|
118
|
+
|
|
119
|
+
## 資料表輸出 {#data-table}
|
|
120
|
+
|
|
121
|
+
`table` 故意簡單化,以便列出、SQL、分析和設定 actions 可以
|
|
122
|
+
重複使用它:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
{
|
|
126
|
+
title?: string;
|
|
127
|
+
columns: Array<{ key: string; label: string; align?: "left" | "right" }>;
|
|
128
|
+
rows: Array<Record<string, unknown>>;
|
|
129
|
+
totalRows?: number;
|
|
130
|
+
sampledRows?: number;
|
|
131
|
+
truncated?: boolean;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
更喜歡穩定的列鍵和 JSON 安全的行值。使用`totalRows`,
|
|
136
|
+
當操作顯示較大切片時為 `sampledRows` 和 `truncated`
|
|
137
|
+
結果集。
|
|
138
|
+
|
|
139
|
+
## 資料圖表輸出 {#data-chart}
|
|
140
|
+
|
|
141
|
+
`chartSeries` 支持座席答案中使用的常見圖表形狀,無需
|
|
142
|
+
要求每個範本提供自己的聊天渲染器:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
{
|
|
146
|
+
type: "bar" | "line" | "area";
|
|
147
|
+
title?: string;
|
|
148
|
+
xKey: string;
|
|
149
|
+
series: Array<{ key: string; label: string; color?: string }>;
|
|
150
|
+
data: Array<Record<string, unknown>>;
|
|
151
|
+
sampled?: boolean;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
保持圖表資料緊湊。對於大型資料集,在操作和連結中聚合
|
|
156
|
+
到包含 `display.primaryAction` 或操作 `link` 元資料的完整應用視圖。
|
|
157
|
+
|
|
158
|
+
## 本機小部件與 MCP 應用程式 {#native-vs-mcp-apps}
|
|
159
|
+
|
|
160
|
+
本機聊天小部件和 MCP 應用程式是互補的:
|
|
161
|
+
|
|
162
|
+
- **本機小部件**用於應用程式自己的聊天執行時。動作結果為
|
|
163
|
+
JSON,框架渲染內置的React小部件。
|
|
164
|
+
- **MCP 應用程式**適用於外部主機。該操作聲明 `mcpApp` 並且通常
|
|
165
|
+
`link`,並且主機在支持時內聯渲染真實的應用程式路由。
|
|
166
|
+
- **深層連結**仍然是通用的後備方案。使用操作 `link` 或
|
|
167
|
+
`display.primaryAction`、CLI 用戶端、較舊的 MCP 主機和純文本紀錄
|
|
168
|
+
讀者可以開啟完整的應用視圖。
|
|
169
|
+
|
|
170
|
+
當本機小部件負載和 MCP 應用元資料都存在時,應用內
|
|
171
|
+
聊天更喜歡本機小部件。外部主機使用 MCP Apps 資源或
|
|
172
|
+
深層連結回退。
|
|
173
|
+
|
|
174
|
+
## 自訂原生渲染器 {#custom-native-renderers}
|
|
175
|
+
|
|
176
|
+
通過精確的渲染器 ID 註冊特定於產品的元件,然後聲明該 ID
|
|
177
|
+
關於行動:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
import { registerActionChatRenderer } from "@agent-native/core/client/chat";
|
|
181
|
+
|
|
182
|
+
registerActionChatRenderer({
|
|
183
|
+
id: "crm.deal-card",
|
|
184
|
+
renderer: "crm.deal-card",
|
|
185
|
+
Component: ({ context }) => <DealCard result={context.resultJson} />,
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
```ts
|
|
190
|
+
export default defineAction({
|
|
191
|
+
description: "Show a deal card.",
|
|
192
|
+
outputSchema: dealCardSchema,
|
|
193
|
+
chatUI: { renderer: "crm.deal-card" },
|
|
194
|
+
run: async () => ({ dealId: "deal_123", amount: 42000 }),
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
將此用於第一方應用程式 UI。在`mcpApp`中保留跨主機iframe UI,並保留
|
|
199
|
+
在聊天中鍵入讀取 actions 而不是原始 SQL 後執行任意查詢。
|
|
200
|
+
|
|
201
|
+
## BYO 代理執行時 {#byo-agent-runtimes}
|
|
202
|
+
|
|
203
|
+
`AgentChatRuntime` 是聊天 shell 的自帶代理合約,並且
|
|
204
|
+
本節是其規範參考。它允許您在其他地方建置代理
|
|
205
|
+
將標準化事件流式傳輸到 Agent-Native 的對話 UI 中,同時保持
|
|
206
|
+
共用作曲家、腳本渲染、工具卡、批準、本機小部件,
|
|
207
|
+
和週圍的應用程式布局。 [Drop-in Agent](/docs/drop-in-agent#custom-chat-ui)
|
|
208
|
+
此處為執行時故事的教程點,以及 [Component API](/docs/components#agent-chat-ui)
|
|
209
|
+
列出每個連線器和適配器及其匯入路徑;合約本身是
|
|
210
|
+
如下所述。
|
|
211
|
+
|
|
212
|
+
```an-diagram title="BYO 執行時保留 Agent-Native 聊天 shell" summary="您的外部代理通過連線器傳輸標準化事件; Agent-Native 保留作曲家、成績單、工具卡、批準和本機小部件。"
|
|
213
|
+
{
|
|
214
|
+
"html": "<div class=\"diagram-byo\"><div class=\"diagram-box\" data-rough>你的代理<br><small class=\"diagram-muted\">OpenAI · Claude · Vercel AI · AG-UI · HTTP</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-panel center\"><span class=\"diagram-pill accent\">connector</span><small class=\"diagram-muted\">標準化 message-* / tool-* 事件</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-card col\"><div class=\"diagram-pill\"><AssistantChat runtime=… /></div><small class=\"diagram-muted\">composer · transcript · tool cards</small><small class=\"diagram-muted\">approvals · native widgets</small></div></div>",
|
|
215
|
+
"css": ".diagram-byo{display:flex;align-items:center;gap:12px;flex-wrap:wrap}.diagram-byo .center{display:flex;flex-direction:column;align-items:center;gap:4px;padding:14px}.diagram-byo .col{display:flex;flex-direction:column;gap:6px;padding:14px}.diagram-byo .diagram-arrow{font-size:22px;line-height:1}"
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
所有連線器均從 `@agent-native/core/client/chat` 匯出(以及根
|
|
220
|
+
`@agent-native/core/client` 條目)。當您的代理使用通用 HTTP 執行時
|
|
221
|
+
可以公開返回 SSE 或 NDJSON 執行時事件的 POST 端點:
|
|
222
|
+
|
|
223
|
+
```tsx
|
|
224
|
+
import {
|
|
225
|
+
AssistantChat,
|
|
226
|
+
createHttpAgentChatRuntime,
|
|
227
|
+
} from "@agent-native/core/client/chat";
|
|
228
|
+
|
|
229
|
+
const runtime = createHttpAgentChatRuntime({
|
|
230
|
+
id: "external:mastra",
|
|
231
|
+
label: "Mastra",
|
|
232
|
+
endpoint: "/api/mastra/chat",
|
|
233
|
+
headers: async () => ({
|
|
234
|
+
Authorization: `Bearer ${await getAgentToken()}`,
|
|
235
|
+
}),
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
export function SupportChat() {
|
|
239
|
+
return <AssistantChat runtime={runtime} threadId="support" />;
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
如果您的端點已傳輸通用代理協議,請使用匹配的
|
|
244
|
+
連線器並跳過編寫自訂對應器:
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
import {
|
|
248
|
+
createAgUiChatRuntime,
|
|
249
|
+
createClaudeAgentChatRuntime,
|
|
250
|
+
createOpenAIAgentsChatRuntime,
|
|
251
|
+
createOpenAIResponsesChatRuntime,
|
|
252
|
+
createVercelAiChatRuntime,
|
|
253
|
+
} from "@agent-native/core/client/chat";
|
|
254
|
+
|
|
255
|
+
const openAiAgentsRuntime = createOpenAIAgentsChatRuntime({
|
|
256
|
+
endpoint: "/api/openai-agents/chat",
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const openAiResponsesRuntime = createOpenAIResponsesChatRuntime({
|
|
260
|
+
endpoint: "/api/openai-responses/chat",
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
const claudeAgentRuntime = createClaudeAgentChatRuntime({
|
|
264
|
+
endpoint: "/api/claude-agent/chat",
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
const vercelAiRuntime = createVercelAiChatRuntime({
|
|
268
|
+
endpoint: "/api/vercel-ai/chat",
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const agUiRuntime = createAgUiChatRuntime({
|
|
272
|
+
endpoint: "/api/ag-ui/chat",
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
端點可以直接傳輸標準化事件形狀:
|
|
277
|
+
|
|
278
|
+
```text
|
|
279
|
+
data: {"type":"message-start","message":{"id":"m1","role":"assistant","content":[]}}
|
|
280
|
+
data: {"type":"message-delta","messageId":"m1","delta":{"type":"text","text":"Hello"}}
|
|
281
|
+
data: {"type":"tool-start","toolCall":{"id":"t1","name":"query","input":{"q":"forms"}}}
|
|
282
|
+
data: {"type":"tool-done","toolCallId":"t1","toolName":"query","status":"completed","resultText":"34 rows"}
|
|
283
|
+
data: {"type":"done","reason":"complete"}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
對於非常簡單的代理,接受 JSON 回應 `{ "text": "..." }` 並且
|
|
287
|
+
轉換為單個助理訊息。對於更丰富的代理,請流式傳輸
|
|
288
|
+
`message-*`, `tool-*`, `approval-request`, `status`, `artifact`, `file`,
|
|
289
|
+
`usage`、`error` 和 `done` 事件。工具結果可以攜帶`mcpApp`或
|
|
290
|
+
`chatUI` 元資料,因此操作聲明的本機小部件仍然會在沒有
|
|
291
|
+
iframe。
|
|
292
|
+
|
|
293
|
+
當您希望內置 Agent-Native 傳輸作為執行時物件時,請使用:
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
import { createAgentNativeChatRuntime } from "@agent-native/core/client/chat";
|
|
297
|
+
|
|
298
|
+
const runtime = createAgentNativeChatRuntime({
|
|
299
|
+
threadId: "forms-chat",
|
|
300
|
+
mode: "act",
|
|
301
|
+
});
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
僅在需要完整時才使用`<AssistantChat createAdapter={...} />`
|
|
305
|
+
assist-ui 適配器控件。當您的產品時單獨使用`PromptComposer`
|
|
306
|
+
擁有整個外部轉錄本並且只想要 Agent-Native 的作曲家
|
|
307
|
+
欄位。
|
|
308
|
+
|
|
309
|
+
OpenAI、AG-UI、Claude Agent SDK 和 Vercel AI SDK 流可以使用標準
|
|
310
|
+
連線器助手。 ACP 保留編碼代理/編輯器互操作性,而不是
|
|
311
|
+
最終使用者的通用應用程式聊天執行時。此處未聲明支持 A2UI;
|
|
312
|
+
如果它成熟,它應該適應這個相同的顯式執行時/小部件契約。
|
|
313
|
+
|
|
314
|
+
## 相關檔案 {#related-docs}
|
|
315
|
+
|
|
316
|
+
- [Actions](/docs/actions) — 定義返回本機小部件資料的操作。
|
|
317
|
+
- [Agent Surfaces](/docs/agent-surfaces) — 決定您是否需要無頭、聊天、邊車或完整應用程式。
|
|
318
|
+
- [Drop-in Agent](/docs/drop-in-agent) — 安裝標準聊天執行時的教程。
|
|
319
|
+
- [Component API](/docs/components) — 用於聊天層、執行時和工具渲染器的每次匯出 API 對應。
|
|
320
|
+
- [MCP Apps](/docs/mcp-apps) — 用於外部 MCP 主機的內聯 UI。
|
|
321
|
+
- [Key Concepts](/docs/key-concepts#protocols) — 協議狀態和定位。
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "通知"
|
|
3
|
+
description: "具有可插入通道的應用內通知 - 收件箱、Webhook 或自訂"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 通知
|
|
7
|
+
|
|
8
|
+
一個功能,多個目的地。從任何伺服器端程式碼(操作、自動化、外掛)調用 `notify()`,事件就會出現在使用者的應用內收件箱中,並分發到每個註冊的頻道。附帶一個響鈴下拉 UI 元件,主機範本將其放入其標頭中。
|
|
9
|
+
|
|
10
|
+
通知是進入應用程式響鈴收件箱的單向警報(加上 Webhook 扇出)。要通過 Slack/電子郵件/Telegram/WhatsApp 與您的代理*交談*,請參閱 [Messaging](/docs/messaging)。
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { notify } from "@agent-native/core/notifications";
|
|
14
|
+
|
|
15
|
+
await notify(
|
|
16
|
+
{ severity: "info", title: "Booking confirmed", body: "Jane at 3pm" },
|
|
17
|
+
{ owner: "steve@builder.io" },
|
|
18
|
+
);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```an-diagram title="一個電話,多個目的地" summary="notify() 始終寫入所有者範圍的收件箱行,並行扇出到每個註冊通道(盡最大努力),然後在事件總線上發出 notification.sent。"
|
|
22
|
+
{
|
|
23
|
+
"html": "<div class=\"diagram-notify\"><div class=\"diagram-node\">notify(input, { owner })<br><small class=\"diagram-muted\">any server code · action, automation, plugin</small></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-panel fan\" data-rough><div class=\"fan-row\"><span class=\"diagram-pill accent\">inbox</span><div class=\"diagram-box\" data-rough>notifications table → bell UI<br><small class=\"diagram-muted\">always on · owner-scoped</small></div></div><div class=\"fan-row\"><span class=\"diagram-pill\">webhook</span><div class=\"diagram-box\" data-rough>POST JSON to NOTIFICATIONS_WEBHOOK_URL<br><small class=\"diagram-muted\">best-effort</small></div></div><div class=\"fan-row\"><span class=\"diagram-pill\">custom</span><div class=\"diagram-box\" data-rough>registerNotificationChannel(...)<br><small class=\"diagram-muted\">best-effort · runs in parallel</small></div></div></div><div class=\"diagram-arrow diagram-muted\" aria-hidden=\"true\">→</div><div class=\"diagram-card\"><span class=\"diagram-pill ok\">notification.sent</span><small class=\"diagram-muted\">event bus · automations can chain</small></div></div>",
|
|
24
|
+
"css": ".diagram-notify{display:flex;align-items:center;gap:14px;flex-wrap:wrap}.diagram-notify .fan{display:flex;flex-direction:column;gap:10px;padding:14px}.diagram-notify .fan-row{display:flex;align-items:center;gap:10px}.diagram-notify .diagram-card{display:flex;flex-direction:column;gap:6px;padding:12px 14px}.diagram-notify .diagram-arrow{font-size:22px;line-height:1}"
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 嚴重性 {#severities}
|
|
29
|
+
|
|
30
|
+
| 嚴重性 | 用於 |
|
|
31
|
+
| ---------- | ------------------------ |
|
|
32
|
+
| `info` | 確認、進度裡程碑、FYI |
|
|
33
|
+
| `warning` | 使用者應該盡快檢視的內容 |
|
|
34
|
+
| `critical` | 需要立即關注 |
|
|
35
|
+
|
|
36
|
+
嚴重性驅動下拉列表中的徽章樣式,並傳遞到渠道,以便它們可以根據緊急情況進行分支。
|
|
37
|
+
|
|
38
|
+
## 內置頻道 {#channels}
|
|
39
|
+
|
|
40
|
+
| 頻道 | 交付 | 需要 |
|
|
41
|
+
| --------- | ----------------------------------- | -------------------------------------------------- |
|
|
42
|
+
| `inbox` | 持久化到`notifications`表;驅動鈴UI | 始終開啟 - 原語的一部分。 |
|
|
43
|
+
| `webhook` | POST JSON 到已設定的 URL | `NOTIFICATIONS_WEBHOOK_URL` 環境變數在啟動時設定。 |
|
|
44
|
+
|
|
45
|
+
Webhook 通道根據所有者的臨時 [secrets](/docs/security) 解析 URL 和 `NOTIFICATIONS_WEBHOOK_AUTH` 中的 `${keys.NAME}` 引用,因此原始值永遠不會進入代理的上下文。強制執行每鍵 URL 允許列表 - 自動化 `web-request` 工具使用相同的規則。
|
|
46
|
+
|
|
47
|
+
```an-diagram title="渠道和嚴重性" summary="收件箱始終開啟; webhook 需要一個環境變數;自訂頻道在啟動時註冊。嚴重性驅動徽章樣式並傳遞到每個渠道。"
|
|
48
|
+
{
|
|
49
|
+
"html": "<div class=\"diagram-channels\"><div class=\"diagram-panel col\" data-rough><strong>Channels</strong><div class=\"diagram-box\" data-rough>inbox<br><small class=\"diagram-muted\">always on — part of the primitive</small></div><div class=\"diagram-box\" data-rough>webhook<br><small class=\"diagram-muted\">needs NOTIFICATIONS_WEBHOOK_URL</small></div><div class=\"diagram-box\" data-rough>custom<br><small class=\"diagram-muted\">registerNotificationChannel()</small></div></div><div class=\"diagram-panel col\" data-rough><strong>嚴重程度決定徽章</strong><div class=\"sev-row\"><span class=\"diagram-pill\">info</span><span class=\"diagram-muted\">確認和 FYI</span></div><div class=\"sev-row\"><span class=\"diagram-pill warn\">warning</span><span class=\"diagram-muted\">look at soon</span></div><div class=\"sev-row\"><span class=\"diagram-pill accent\">critical</span><span class=\"diagram-muted\">needs immediate attention</span></div></div></div>",
|
|
50
|
+
"css": ".diagram-channels{display:flex;gap:16px;flex-wrap:wrap;align-items:flex-start}.diagram-channels .col{display:flex;flex-direction:column;gap:10px;padding:14px;min-width:240px}.diagram-channels .sev-row{display:flex;align-items:center;gap:10px}"
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## API {#api}
|
|
55
|
+
|
|
56
|
+
### `notify(input, meta)` {#notify}
|
|
57
|
+
|
|
58
|
+
發出通知。除非明確排除,否則始終保留在收件箱中;其他註冊通道會盡力並行執行。
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
await notify(
|
|
62
|
+
{
|
|
63
|
+
severity: "critical",
|
|
64
|
+
title: "Database offline",
|
|
65
|
+
body: "Primary dropped connections",
|
|
66
|
+
metadata: { runbookUrl: "https://runbooks/db-offline" },
|
|
67
|
+
channels: ["inbox", "webhook"], // optional allowlist; omit to run all
|
|
68
|
+
},
|
|
69
|
+
{ owner: "ops@company.com" },
|
|
70
|
+
);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`meta.owner` 是必需的 - 限制通知的範圍,以便只有使用者在鈴聲中看到它。
|
|
74
|
+
|
|
75
|
+
### `registerNotificationChannel(channel)` {#register}
|
|
76
|
+
|
|
77
|
+
從任何伺服器外掛註冊自訂通道。
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { registerNotificationChannel } from "@agent-native/core/notifications";
|
|
81
|
+
|
|
82
|
+
registerNotificationChannel({
|
|
83
|
+
name: "slack-ops",
|
|
84
|
+
async deliver(input, meta) {
|
|
85
|
+
await fetch(process.env.OPS_SLACK_WEBHOOK!, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: { "Content-Type": "application/json" },
|
|
88
|
+
body: JSON.stringify({
|
|
89
|
+
text: `*${input.severity.toUpperCase()}* — ${input.title}\n${input.body ?? ""}`,
|
|
90
|
+
owner: meta.owner,
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
頻道名稱是唯一的 - 重新註冊會替換之前的頻道。 `deliver()` 是盡力而為;拋出錯誤會紀錄錯誤,但不會阻止其他通道或收件箱行。
|
|
98
|
+
|
|
99
|
+
### 列出和閱讀 {#read}
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import {
|
|
103
|
+
listNotifications,
|
|
104
|
+
countUnread,
|
|
105
|
+
markNotificationRead,
|
|
106
|
+
markAllNotificationsRead,
|
|
107
|
+
deleteNotification,
|
|
108
|
+
} from "@agent-native/core/notifications";
|
|
109
|
+
|
|
110
|
+
const rows = await listNotifications("steve@builder.io", {
|
|
111
|
+
unreadOnly: true,
|
|
112
|
+
limit: 50,
|
|
113
|
+
});
|
|
114
|
+
const unread = await countUnread("steve@builder.io");
|
|
115
|
+
await markNotificationRead(rows[0].id, "steve@builder.io");
|
|
116
|
+
await markAllNotificationsRead("steve@builder.io");
|
|
117
|
+
await deleteNotification(rows[0].id, "steve@builder.io");
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
每個函數都是所有者範圍的 - 沒有跨使用者讀取,沒有跨使用者寫入。
|
|
121
|
+
|
|
122
|
+
## NotificationChannel 介面 {#channel-interface}
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
interface NotificationChannel {
|
|
126
|
+
name: string;
|
|
127
|
+
deliver(
|
|
128
|
+
input: NotificationInput,
|
|
129
|
+
meta: NotificationMeta,
|
|
130
|
+
): void | Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface NotificationInput {
|
|
134
|
+
severity: "info" | "warning" | "critical";
|
|
135
|
+
title: string;
|
|
136
|
+
body?: string;
|
|
137
|
+
metadata?: Record<string, unknown>;
|
|
138
|
+
channels?: string[];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface NotificationMeta {
|
|
142
|
+
owner: string;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## HTTP API {#http}
|
|
147
|
+
|
|
148
|
+
通過 core-routes 外掛安裝在 `/_agent-native/notifications/*`。所有路由的範圍僅限於經過驗證的工作階段的電子郵件。
|
|
149
|
+
|
|
150
|
+
| 方法 | 路徑 |
|
|
151
|
+
| -------- | --------------------------------------------------- |
|
|
152
|
+
| `GET` | `/_agent-native/notifications?unread=true&limit=50` |
|
|
153
|
+
| `GET` | `/_agent-native/notifications/count` |
|
|
154
|
+
| `POST` | `/_agent-native/notifications/:id/read` |
|
|
155
|
+
| `POST` | `/_agent-native/notifications/read-all` |
|
|
156
|
+
| `DELETE` | `/_agent-native/notifications/:id` |
|
|
157
|
+
|
|
158
|
+
```an-api title="列出通知" summary="The route behind listNotifications() — scoped to the authenticated session's email."
|
|
159
|
+
{
|
|
160
|
+
"method": "GET",
|
|
161
|
+
"path": "/_agent-native/notifications?unread=true&limit=50",
|
|
162
|
+
"summary": "列出目前使用者的最近通知",
|
|
163
|
+
"auth": "Authenticated session; results are scoped to the session's email.",
|
|
164
|
+
"params": [
|
|
165
|
+
{ "name": "unread", "in": "query", "type": "boolean", "required": false, "description": "When true, returns only unread notifications." },
|
|
166
|
+
{ "name": "limit", "in": "query", "type": "number", "required": false, "description": "Max rows to return." }
|
|
167
|
+
],
|
|
168
|
+
"responses": [
|
|
169
|
+
{ "status": "200", "description": "Owner-scoped notification rows, newest first." }
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## UI元件 {#ui}
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
import { NotificationsBell } from "@agent-native/core/client/notifications";
|
|
178
|
+
|
|
179
|
+
export function HeaderBar() {
|
|
180
|
+
return (
|
|
181
|
+
<header className="flex items-center gap-2">
|
|
182
|
+
{/* … */}
|
|
183
|
+
<NotificationsBell browserNotifications />
|
|
184
|
+
</header>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
帶有未讀徽章的響鈴圖標。點選可開啟最近通知的下拉列表。使用 shadcn 語義標記,適應主機範本的淺色/深色主題。
|
|
190
|
+
|
|
191
|
+
傳遞 `browserNotifications` 來為每個新的未讀專案觸發系統 `new Notification(...)` 快顯窗口 - 當使用者的分頁位於後台時很有用。下拉選單會呈現“啟用”提示,直到使用者授予權限;通過通知 `tag` 欄位防止每個 ID 重複。
|
|
192
|
+
|
|
193
|
+
## 代理工具 {#agent-tools}
|
|
194
|
+
|
|
195
|
+
每個範本中都會註冊一個 `manage-notifications` 工具。 `action`參數選取操作:
|
|
196
|
+
|
|
197
|
+
| 行動 | 參數 | 目的 |
|
|
198
|
+
| ------ | ----------------------------------------------------------------------- | ---------------------------------- |
|
|
199
|
+
| `send` | `severity`(必填)、`title`(必填)、`body`、`metadataJson`、`channels` | 向使用者的收件箱和註冊頻道發送通知 |
|
|
200
|
+
| `list` | `unreadOnly`、`limit`(最多 200 個,預設 20 個) | 列出上下文的最近通知 |
|
|
201
|
+
|
|
202
|
+
自動化(請參閱 [Automations](/docs/automations))可以通過其主體中的 `action=send` 調用 `manage-notifications` - 這是將外部事件轉變為使用者可見警報的規範模式。
|
|
203
|
+
|
|
204
|
+
## 事件總線 {#event-bus}
|
|
205
|
+
|
|
206
|
+
每次成功交付都會在 [event bus](/docs/automations#event-bus) 上發出 `notification.sent`:
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
{
|
|
210
|
+
"notificationId": "n-123",
|
|
211
|
+
"severity": "critical",
|
|
212
|
+
"title": "DB offline",
|
|
213
|
+
"body": "Primary dropped connections",
|
|
214
|
+
"deliveredChannels": ["inbox", "webhook"]
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
自動化可以將其串聯起來——例如*“如果觸發重要通知,也會立即尋呼。”*
|
|
219
|
+
|
|
220
|
+
## 它是如何工作的 {#internals}
|
|
221
|
+
|
|
222
|
+
- **所有者範圍** — 每行都有一個 `owner` 列;每個查詢都會對其進行過濾;每個路由都使用經過驗證的工作階段的電子郵件。使用者永遠不會看到彼此的通知。
|
|
223
|
+
- **輪詢整合** - 每個突變都會調用 `recordChange()`,因此使用 [`useDbSync`](/docs/client) 的範本會自動失效,無需任何額外的接線。
|
|
224
|
+
- **盡力扇出** — 捕獲並紀錄通道錯誤;一個失敗的通道不會阻止其他通道或收件箱寫入。
|
|
225
|
+
- **即發即忘** — `notify()` 在收件箱寫入完成後返回;自訂通道在後台執行。
|
|
226
|
+
|
|
227
|
+
## 下一步是什么
|
|
228
|
+
|
|
229
|
+
- [**Automations**](/docs/automations) — `notify()` 最常見的調用者
|
|
230
|
+
- [**Security**](/docs/security) — 為 Webhook 通道提供支持的 `${keys.NAME}` 替代
|
|
231
|
+
- [**Server plugins**](/docs/server) — 啟動時註冊自訂通道
|