@agent-native/core 0.146.0 → 0.146.2
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 +1 -1
- package/corpus/templates/analytics/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/analytics/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/analytics/actions/compose-dashboard.ts +2 -27
- package/corpus/templates/analytics/actions/get-sql-dashboard.ts +7 -8
- package/corpus/templates/analytics/actions/migrate-first-party-analytics-to-bigquery.ts +18 -2
- package/corpus/templates/analytics/actions/mutate-dashboard.ts +16 -24
- package/corpus/templates/analytics/actions/rename-dashboard.ts +2 -24
- package/corpus/templates/analytics/actions/reorder-dashboard-panels.ts +2 -24
- package/corpus/templates/analytics/actions/restore-dashboard-revision.ts +2 -25
- package/corpus/templates/analytics/actions/update-dashboard.ts +4 -32
- package/corpus/templates/analytics/app/components/layout/CommandPalette.tsx +1 -40
- package/corpus/templates/analytics/changelog/2026-08-07-language-selection-now-lives-in-settings-instead-of-the-comm.md +6 -0
- package/corpus/templates/analytics/netlify.toml +7 -0
- package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +13 -13
- package/corpus/templates/analytics/server/jobs/analytics-bigquery-backfill.ts +4 -2
- package/corpus/templates/analytics/server/lib/canonical-first-party-dashboard-repair.ts +0 -35
- package/corpus/templates/analytics/server/lib/dashboard-catalog.ts +5 -3
- package/corpus/templates/analytics/server/lib/dashboard-collab-sync.ts +77 -0
- package/corpus/templates/analytics/server/lib/demo-dashboards.ts +2 -23
- package/corpus/templates/analytics/server/lib/first-party-metric-catalog.ts +28 -74
- package/corpus/templates/analytics/server/routes/api/dashboard-agent-context.json.get.ts +5 -9
- package/corpus/templates/assets/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/assets/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/brain/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/brain/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/calendar/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/calendar/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/chat/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/chat/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/clips/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/clips/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/clips/app/components/player/video-player.tsx +1 -1
- package/corpus/templates/clips/changelog/2026-08-07-fixed-trimmed-clips-durations-so-the-main-player-display-mat.md +6 -0
- package/corpus/templates/clips/chrome-extension/STORE_DRAFT.md +1 -1
- package/corpus/templates/clips/chrome-extension/public/manifest.json +1 -1
- package/corpus/templates/content/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/content/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/crm/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/crm/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/design/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/design/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/dispatch/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/dispatch/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/dispatch/changelog/2026-08-07-language-selection-now-lives-in-settings-instead-of-the-disp.md +6 -0
- package/corpus/templates/factory/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/factory/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/factory/server/plugins/factory-scheduler-job.ts +59 -22
- package/corpus/templates/forms/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/forms/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/macros/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/macros/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/mail/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/mail/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/plan/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/plan/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/slides/.agents/skills/image-generation-via-a2a/SKILL.md +10 -1
- package/corpus/templates/slides/.agents/skills/slide-images/SKILL.md +10 -3
- package/corpus/templates/slides/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/slides/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/corpus/templates/slides/actions/generate-image-api.ts +123 -0
- package/corpus/templates/slides/actions/import-file.ts +144 -99
- package/corpus/templates/slides/app/components/deck/DeckCard.tsx +10 -2
- package/corpus/templates/slides/app/components/editor/ImageGenPanel.tsx +1 -1
- package/corpus/templates/slides/changelog/2026-08-07-deleting-a-deck-no-longer-freezes-the-slides-browser.md +6 -0
- package/corpus/templates/slides/changelog/2026-08-07-slides-verify-generated-images-are-persisted-on-the-target-s.md +6 -0
- package/corpus/templates/slides/package.json +1 -0
- package/corpus/templates/slides/server/handlers/import/html-converter.ts +9 -0
- package/corpus/templates/slides/server/handlers/import/pdf-fidelity-parser.ts +960 -0
- package/corpus/templates/slides/server/lib/slide-image-insertion.ts +141 -0
- package/corpus/templates/slides/server/plugins/agent-chat.ts +2 -0
- package/corpus/templates/tasks/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/corpus/templates/tasks/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/dist/client/AgentPanel.d.ts +10 -4
- package/dist/client/AgentPanel.js +29 -82
- package/dist/collab/awareness.d.ts +2 -2
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/db/migrations.js +22 -4
- package/dist/deploy/build.d.ts +1 -0
- package/dist/deploy/build.js +27 -22
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/ingestion/pptx.d.ts +1 -0
- package/dist/ingestion/pptx.js +353 -28
- package/dist/notifications/routes.d.ts +2 -2
- package/dist/observability/routes.d.ts +1 -1
- package/dist/progress/routes.d.ts +1 -1
- package/dist/resources/handlers.d.ts +1 -1
- package/dist/secrets/routes.d.ts +6 -6
- package/dist/server/builder-browser.d.ts +34 -0
- package/dist/server/builder-browser.js +179 -0
- package/dist/server/core-routes-plugin.d.ts +5 -0
- package/dist/server/core-routes-plugin.js +24 -8
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/shared/cache-control.d.ts +2 -2
- package/dist/shared/cache-control.js +2 -2
- package/dist/templates/chat/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/dist/templates/chat/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/dist/templates/default/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/dist/templates/default/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/dist/templates/headless/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/dist/templates/headless/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/dist/templates/workspace-core/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/dist/templates/workspace-core/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/dist/vite/client.js +13 -1
- package/docs/content/drop-in-agent.mdx +3 -3
- package/docs/content/getting-started-actions.mdx +1 -2
- package/docs/content/getting-started-pages.mdx +1 -2
- package/docs/content/getting-started.mdx +0 -4
- package/docs/content/what-is-agent-native.mdx +4 -4
- package/package.json +3 -3
- package/src/templates/chat/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/src/templates/chat/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/src/templates/default/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/src/templates/default/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/src/templates/headless/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/src/templates/headless/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/src/templates/workspace-core/.agents/skills/turn-into-app/SKILL.md +4 -0
- package/src/templates/workspace-core/.agents/skills/turn-into-app/references/fresh-project.md +8 -0
- package/docs/content/getting-started-database.mdx +0 -173
|
@@ -26,10 +26,6 @@ Define a typed text analyzer and render its result as a chart in the chat.
|
|
|
26
26
|
|
|
27
27
|
Build a React route that calls the same action outside the transcript.
|
|
28
28
|
|
|
29
|
-
### Persist data in SQL (optional)
|
|
30
|
-
|
|
31
|
-
Add a table and persistence actions when results need to survive conversations.
|
|
32
|
-
|
|
33
29
|
</Steps>
|
|
34
30
|
|
|
35
31
|
## 1. Create a chat app {#create-your-app}
|
|
@@ -79,10 +79,10 @@ Every operation is defined as a typed **action**: a name, a schema, and a `run`
|
|
|
79
79
|
|
|
80
80
|
```mermaid
|
|
81
81
|
graph TD
|
|
82
|
-
UI_IN["
|
|
83
|
-
AG_IN["
|
|
84
|
-
ACTION["
|
|
85
|
-
DB["
|
|
82
|
+
UI_IN["Click a button"]
|
|
83
|
+
AG_IN["Type a message to the agent"]
|
|
84
|
+
ACTION["Same typed action"]
|
|
85
|
+
DB["Shared database"]
|
|
86
86
|
UI_OUT["UI updates instantly"]
|
|
87
87
|
AG_OUT["Agent sees the change"]
|
|
88
88
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-native/core",
|
|
3
|
-
"version": "0.146.
|
|
3
|
+
"version": "0.146.2",
|
|
4
4
|
"description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/agent-native#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -412,8 +412,8 @@
|
|
|
412
412
|
"y-protocols": "^1.0.7",
|
|
413
413
|
"yjs": "^13.6.31",
|
|
414
414
|
"zod": "^4.3.6",
|
|
415
|
-
"@agent-native/
|
|
416
|
-
"@agent-native/
|
|
415
|
+
"@agent-native/recap-cli": "0.5.3",
|
|
416
|
+
"@agent-native/toolkit": "^0.13.5"
|
|
417
417
|
},
|
|
418
418
|
"devDependencies": {
|
|
419
419
|
"@ai-sdk/anthropic": "^3.0.71",
|
|
@@ -27,6 +27,10 @@ The build location depends on the host. Treat this as a hard routing rule:
|
|
|
27
27
|
`resourceIds` when available. This is the Builder handoff.
|
|
28
28
|
- Do not substitute the generic `create_workspace_app` MCP tool in an online
|
|
29
29
|
host. That tool is a local workspace scaffolder, not the Builder handoff.
|
|
30
|
+
- Connect the Agent-Native Dispatch MCP connector only. Dispatch uses the
|
|
31
|
+
authenticated Builder Projects API to reuse or provision the workspace
|
|
32
|
+
project before starting the Builder Cloud Agent; a separate Builder CMS MCP
|
|
33
|
+
connection is not required for this workflow.
|
|
30
34
|
- If `start-workspace-app-creation` is not available or Dispatch is not
|
|
31
35
|
authenticated, stop with the connector setup needed. Do not fall back to a
|
|
32
36
|
local build or claim that the app exists.
|
|
@@ -50,6 +50,14 @@ skills. For a ChatGPT Project or any host that exposes only the MCP connector,
|
|
|
50
50
|
also place the skill instructions or this reference in the Project
|
|
51
51
|
instructions/knowledge files. Then add and authenticate the Dispatch MCP
|
|
52
52
|
connector from the packaged `adapters/chatgpt-mcp/connector.json`.
|
|
53
|
+
This single connector is enough: Dispatch provisions or reuses the Builder
|
|
54
|
+
project through the Builder Projects API, so do not ask the user to add a
|
|
55
|
+
separate Builder CMS MCP for app creation.
|
|
56
|
+
Builder's separate Fusion MCP is available as a custom remote connector at
|
|
57
|
+
`https://mcp.builder.io/mcp/fusion` for direct Builder work. It can run an
|
|
58
|
+
existing project, but it cannot provision the repo-backed Agent-Native
|
|
59
|
+
workspace project, so it is optional and not a replacement for the Dispatch
|
|
60
|
+
handoff in this skill. Do not add Builder's CMS MCP for this workflow.
|
|
53
61
|
|
|
54
62
|
For Claude Web, ChatGPT Web, and their web Projects, the host is an
|
|
55
63
|
orchestrator, not the build environment. After forming the source brief, call
|
|
@@ -27,6 +27,10 @@ The build location depends on the host. Treat this as a hard routing rule:
|
|
|
27
27
|
`resourceIds` when available. This is the Builder handoff.
|
|
28
28
|
- Do not substitute the generic `create_workspace_app` MCP tool in an online
|
|
29
29
|
host. That tool is a local workspace scaffolder, not the Builder handoff.
|
|
30
|
+
- Connect the Agent-Native Dispatch MCP connector only. Dispatch uses the
|
|
31
|
+
authenticated Builder Projects API to reuse or provision the workspace
|
|
32
|
+
project before starting the Builder Cloud Agent; a separate Builder CMS MCP
|
|
33
|
+
connection is not required for this workflow.
|
|
30
34
|
- If `start-workspace-app-creation` is not available or Dispatch is not
|
|
31
35
|
authenticated, stop with the connector setup needed. Do not fall back to a
|
|
32
36
|
local build or claim that the app exists.
|
|
@@ -50,6 +50,14 @@ skills. For a ChatGPT Project or any host that exposes only the MCP connector,
|
|
|
50
50
|
also place the skill instructions or this reference in the Project
|
|
51
51
|
instructions/knowledge files. Then add and authenticate the Dispatch MCP
|
|
52
52
|
connector from the packaged `adapters/chatgpt-mcp/connector.json`.
|
|
53
|
+
This single connector is enough: Dispatch provisions or reuses the Builder
|
|
54
|
+
project through the Builder Projects API, so do not ask the user to add a
|
|
55
|
+
separate Builder CMS MCP for app creation.
|
|
56
|
+
Builder's separate Fusion MCP is available as a custom remote connector at
|
|
57
|
+
`https://mcp.builder.io/mcp/fusion` for direct Builder work. It can run an
|
|
58
|
+
existing project, but it cannot provision the repo-backed Agent-Native
|
|
59
|
+
workspace project, so it is optional and not a replacement for the Dispatch
|
|
60
|
+
handoff in this skill. Do not add Builder's CMS MCP for this workflow.
|
|
53
61
|
|
|
54
62
|
For Claude Web, ChatGPT Web, and their web Projects, the host is an
|
|
55
63
|
orchestrator, not the build environment. After forming the source brief, call
|
|
@@ -27,6 +27,10 @@ The build location depends on the host. Treat this as a hard routing rule:
|
|
|
27
27
|
`resourceIds` when available. This is the Builder handoff.
|
|
28
28
|
- Do not substitute the generic `create_workspace_app` MCP tool in an online
|
|
29
29
|
host. That tool is a local workspace scaffolder, not the Builder handoff.
|
|
30
|
+
- Connect the Agent-Native Dispatch MCP connector only. Dispatch uses the
|
|
31
|
+
authenticated Builder Projects API to reuse or provision the workspace
|
|
32
|
+
project before starting the Builder Cloud Agent; a separate Builder CMS MCP
|
|
33
|
+
connection is not required for this workflow.
|
|
30
34
|
- If `start-workspace-app-creation` is not available or Dispatch is not
|
|
31
35
|
authenticated, stop with the connector setup needed. Do not fall back to a
|
|
32
36
|
local build or claim that the app exists.
|
|
@@ -50,6 +50,14 @@ skills. For a ChatGPT Project or any host that exposes only the MCP connector,
|
|
|
50
50
|
also place the skill instructions or this reference in the Project
|
|
51
51
|
instructions/knowledge files. Then add and authenticate the Dispatch MCP
|
|
52
52
|
connector from the packaged `adapters/chatgpt-mcp/connector.json`.
|
|
53
|
+
This single connector is enough: Dispatch provisions or reuses the Builder
|
|
54
|
+
project through the Builder Projects API, so do not ask the user to add a
|
|
55
|
+
separate Builder CMS MCP for app creation.
|
|
56
|
+
Builder's separate Fusion MCP is available as a custom remote connector at
|
|
57
|
+
`https://mcp.builder.io/mcp/fusion` for direct Builder work. It can run an
|
|
58
|
+
existing project, but it cannot provision the repo-backed Agent-Native
|
|
59
|
+
workspace project, so it is optional and not a replacement for the Dispatch
|
|
60
|
+
handoff in this skill. Do not add Builder's CMS MCP for this workflow.
|
|
53
61
|
|
|
54
62
|
For Claude Web, ChatGPT Web, and their web Projects, the host is an
|
|
55
63
|
orchestrator, not the build environment. After forming the source brief, call
|
|
@@ -27,6 +27,10 @@ The build location depends on the host. Treat this as a hard routing rule:
|
|
|
27
27
|
`resourceIds` when available. This is the Builder handoff.
|
|
28
28
|
- Do not substitute the generic `create_workspace_app` MCP tool in an online
|
|
29
29
|
host. That tool is a local workspace scaffolder, not the Builder handoff.
|
|
30
|
+
- Connect the Agent-Native Dispatch MCP connector only. Dispatch uses the
|
|
31
|
+
authenticated Builder Projects API to reuse or provision the workspace
|
|
32
|
+
project before starting the Builder Cloud Agent; a separate Builder CMS MCP
|
|
33
|
+
connection is not required for this workflow.
|
|
30
34
|
- If `start-workspace-app-creation` is not available or Dispatch is not
|
|
31
35
|
authenticated, stop with the connector setup needed. Do not fall back to a
|
|
32
36
|
local build or claim that the app exists.
|
package/src/templates/workspace-core/.agents/skills/turn-into-app/references/fresh-project.md
CHANGED
|
@@ -50,6 +50,14 @@ skills. For a ChatGPT Project or any host that exposes only the MCP connector,
|
|
|
50
50
|
also place the skill instructions or this reference in the Project
|
|
51
51
|
instructions/knowledge files. Then add and authenticate the Dispatch MCP
|
|
52
52
|
connector from the packaged `adapters/chatgpt-mcp/connector.json`.
|
|
53
|
+
This single connector is enough: Dispatch provisions or reuses the Builder
|
|
54
|
+
project through the Builder Projects API, so do not ask the user to add a
|
|
55
|
+
separate Builder CMS MCP for app creation.
|
|
56
|
+
Builder's separate Fusion MCP is available as a custom remote connector at
|
|
57
|
+
`https://mcp.builder.io/mcp/fusion` for direct Builder work. It can run an
|
|
58
|
+
existing project, but it cannot provision the repo-backed Agent-Native
|
|
59
|
+
workspace project, so it is optional and not a replacement for the Dispatch
|
|
60
|
+
handoff in this skill. Do not add Builder's CMS MCP for this workflow.
|
|
53
61
|
|
|
54
62
|
For Claude Web, ChatGPT Web, and their web Projects, the host is an
|
|
55
63
|
orchestrator, not the build environment. After forming the source brief, call
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Persist Data in SQL"
|
|
3
|
-
description: "Persist action results in SQL when they need to survive conversations."
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Persist Data in SQL
|
|
7
|
-
|
|
8
|
-
This is the optional fourth part of the Getting Started series. In [Add a Page](/docs/getting-started-pages)
|
|
9
|
-
you used `analyze-text` directly from a route. Here you'll add app-owned SQL
|
|
10
|
-
data when results need to survive conversations.
|
|
11
|
-
|
|
12
|
-
## Add a table {#persist-data}
|
|
13
|
-
|
|
14
|
-
Chat already includes the SQL runtime, framework tables, and a local SQLite file
|
|
15
|
-
by default. You do not need to install a database, set `DATABASE_URL`, or add a
|
|
16
|
-
migration for Chat's built-in tables. For a new app-owned table, add these three
|
|
17
|
-
server files:
|
|
18
|
-
|
|
19
|
-
1. `server/plugins/db.ts` creates the table with an additive migration.
|
|
20
|
-
2. `server/db/schema.ts` describes the table for typed queries.
|
|
21
|
-
3. `server/db/index.ts` creates the app's typed database client.
|
|
22
|
-
|
|
23
|
-
Create `server/plugins/db.ts`:
|
|
24
|
-
|
|
25
|
-
```ts filename="server/plugins/db.ts"
|
|
26
|
-
import { runMigrations } from "@agent-native/core/db";
|
|
27
|
-
|
|
28
|
-
export default runMigrations(
|
|
29
|
-
[
|
|
30
|
-
{
|
|
31
|
-
version: 1,
|
|
32
|
-
name: "create-text-analyses",
|
|
33
|
-
sql: `CREATE TABLE IF NOT EXISTS text_analyses (
|
|
34
|
-
id TEXT PRIMARY KEY,
|
|
35
|
-
input TEXT NOT NULL,
|
|
36
|
-
char_count INTEGER NOT NULL,
|
|
37
|
-
word_count INTEGER NOT NULL,
|
|
38
|
-
sentence_count INTEGER NOT NULL,
|
|
39
|
-
paragraph_count INTEGER NOT NULL,
|
|
40
|
-
owner_email TEXT NOT NULL,
|
|
41
|
-
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
42
|
-
)`,
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
{ table: "text_analyses_migrations" },
|
|
46
|
-
);
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Create `server/db/schema.ts`:
|
|
50
|
-
|
|
51
|
-
```ts filename="server/db/schema.ts"
|
|
52
|
-
import { integer, now, table, text } from "@agent-native/core/db/schema";
|
|
53
|
-
|
|
54
|
-
export const textAnalyses = table("text_analyses", {
|
|
55
|
-
id: text("id").primaryKey(),
|
|
56
|
-
input: text("input").notNull(),
|
|
57
|
-
charCount: integer("char_count").notNull(),
|
|
58
|
-
wordCount: integer("word_count").notNull(),
|
|
59
|
-
sentenceCount: integer("sentence_count").notNull(),
|
|
60
|
-
paragraphCount: integer("paragraph_count").notNull(),
|
|
61
|
-
ownerEmail: text("owner_email").notNull(),
|
|
62
|
-
createdAt: text("created_at").notNull().default(now()),
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Create `server/db/index.ts`:
|
|
67
|
-
|
|
68
|
-
```ts filename="server/db/index.ts"
|
|
69
|
-
import { createGetDb } from "@agent-native/core/db";
|
|
70
|
-
import * as schema from "./schema.js";
|
|
71
|
-
|
|
72
|
-
export const getDb = createGetDb(schema);
|
|
73
|
-
export { schema };
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Restart `pnpm dev` once so the migration runs. Keep future migrations additive,
|
|
77
|
-
and give each one a new `version` and `name`.
|
|
78
|
-
|
|
79
|
-
## Add save and list actions
|
|
80
|
-
|
|
81
|
-
Keep `analyze-text` read-only and make saving explicit with a separate action.
|
|
82
|
-
Create `actions/save-text-analysis.ts`:
|
|
83
|
-
|
|
84
|
-
```ts filename="actions/save-text-analysis.ts"
|
|
85
|
-
import { defineAction } from "@agent-native/core/action";
|
|
86
|
-
import { z } from "zod";
|
|
87
|
-
|
|
88
|
-
import { getDb, schema } from "../server/db/index.js";
|
|
89
|
-
|
|
90
|
-
export default defineAction({
|
|
91
|
-
description: "Save a text analysis result to the database.",
|
|
92
|
-
schema: z.object({
|
|
93
|
-
input: z.string().min(1),
|
|
94
|
-
charCount: z.number(),
|
|
95
|
-
wordCount: z.number(),
|
|
96
|
-
sentenceCount: z.number(),
|
|
97
|
-
paragraphCount: z.number(),
|
|
98
|
-
}),
|
|
99
|
-
run: async (
|
|
100
|
-
{ input, charCount, wordCount, sentenceCount, paragraphCount },
|
|
101
|
-
ctx,
|
|
102
|
-
) => {
|
|
103
|
-
const ownerEmail = ctx?.userEmail;
|
|
104
|
-
if (!ownerEmail) throw new Error("Sign in before saving analyses.");
|
|
105
|
-
|
|
106
|
-
const id = crypto.randomUUID();
|
|
107
|
-
await getDb().insert(schema.textAnalyses).values({
|
|
108
|
-
id,
|
|
109
|
-
input,
|
|
110
|
-
charCount,
|
|
111
|
-
wordCount,
|
|
112
|
-
sentenceCount,
|
|
113
|
-
paragraphCount,
|
|
114
|
-
ownerEmail,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
return { id };
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Create `actions/list-text-analyses.ts`:
|
|
123
|
-
|
|
124
|
-
```ts filename="actions/list-text-analyses.ts"
|
|
125
|
-
import { defineAction } from "@agent-native/core/action";
|
|
126
|
-
import { desc, eq } from "drizzle-orm";
|
|
127
|
-
import { z } from "zod";
|
|
128
|
-
|
|
129
|
-
import { getDb, schema } from "../server/db/index.js";
|
|
130
|
-
|
|
131
|
-
export default defineAction({
|
|
132
|
-
description: "List the signed-in user's saved text analyses, newest first.",
|
|
133
|
-
schema: z.object({}),
|
|
134
|
-
http: { method: "GET" },
|
|
135
|
-
readOnly: true,
|
|
136
|
-
run: async (_, ctx) => {
|
|
137
|
-
const ownerEmail = ctx?.userEmail;
|
|
138
|
-
if (!ownerEmail) throw new Error("Sign in before listing analyses.");
|
|
139
|
-
|
|
140
|
-
return getDb()
|
|
141
|
-
.select({
|
|
142
|
-
id: schema.textAnalyses.id,
|
|
143
|
-
input: schema.textAnalyses.input,
|
|
144
|
-
charCount: schema.textAnalyses.charCount,
|
|
145
|
-
wordCount: schema.textAnalyses.wordCount,
|
|
146
|
-
sentenceCount: schema.textAnalyses.sentenceCount,
|
|
147
|
-
paragraphCount: schema.textAnalyses.paragraphCount,
|
|
148
|
-
createdAt: schema.textAnalyses.createdAt,
|
|
149
|
-
})
|
|
150
|
-
.from(schema.textAnalyses)
|
|
151
|
-
.where(eq(schema.textAnalyses.ownerEmail, ownerEmail))
|
|
152
|
-
.orderBy(desc(schema.textAnalyses.createdAt));
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
The actions use the typed Drizzle client for app reads and writes. Raw SQL is
|
|
158
|
-
only needed here for the additive migration. Skip this page until your action
|
|
159
|
-
needs durable domain data.
|
|
160
|
-
|
|
161
|
-
## Try it
|
|
162
|
-
|
|
163
|
-
In chat, ask the agent to do the whole flow:
|
|
164
|
-
|
|
165
|
-
> Run analyze-text on "Hello world", save the result with save-text-analysis, then list my saved text analyses.
|
|
166
|
-
|
|
167
|
-
The saved row is now available to the agent and to any page that reads
|
|
168
|
-
`list-text-analyses`.
|
|
169
|
-
|
|
170
|
-
## Continue
|
|
171
|
-
|
|
172
|
-
You now have durable app data. Continue with [Key Concepts](/docs/key-concepts)
|
|
173
|
-
to learn how actions, SQL, and pages fit together.
|