@agent-native/actions 0.0.0-stage → 0.1.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.
Files changed (63) hide show
  1. package/README.md +41 -2
  2. package/dist/chunk-4X4LYULO.js +108 -0
  3. package/dist/chunk-4X4LYULO.js.map +1 -0
  4. package/dist/chunk-D66CG6AI.js +265 -0
  5. package/dist/chunk-D66CG6AI.js.map +1 -0
  6. package/dist/chunk-KWA4U6DI.js +273 -0
  7. package/dist/chunk-KWA4U6DI.js.map +1 -0
  8. package/dist/chunk-SXOEFWAM.js +147 -0
  9. package/dist/chunk-SXOEFWAM.js.map +1 -0
  10. package/dist/cli.js +1765 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/client-C87WZhlZ.d.ts +223 -0
  13. package/dist/client.d.ts +70 -0
  14. package/dist/client.js +110 -0
  15. package/dist/client.js.map +1 -0
  16. package/dist/contract.d.ts +251 -0
  17. package/dist/contract.js +372 -0
  18. package/dist/contract.js.map +1 -0
  19. package/dist/index.d.ts +251 -0
  20. package/dist/index.js +704 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/next-config.d.ts +16 -0
  23. package/dist/next-config.js +46 -0
  24. package/dist/next-config.js.map +1 -0
  25. package/dist/next-pages.d.ts +12 -0
  26. package/dist/next-pages.js +13 -0
  27. package/dist/next-pages.js.map +1 -0
  28. package/dist/next-server.d.ts +41 -0
  29. package/dist/next-server.js +96 -0
  30. package/dist/next-server.js.map +1 -0
  31. package/dist/next.d.ts +39 -0
  32. package/dist/next.js +68 -0
  33. package/dist/next.js.map +1 -0
  34. package/dist/nuxt.d.ts +17 -0
  35. package/dist/nuxt.js +22 -0
  36. package/dist/nuxt.js.map +1 -0
  37. package/dist/react.d.ts +50 -0
  38. package/dist/react.js +194 -0
  39. package/dist/react.js.map +1 -0
  40. package/dist/registry-CIe_aYoE.d.ts +263 -0
  41. package/dist/solid.d.ts +39 -0
  42. package/dist/solid.js +229 -0
  43. package/dist/solid.js.map +1 -0
  44. package/dist/svelte-server.d.ts +23 -0
  45. package/dist/svelte-server.js +33 -0
  46. package/dist/svelte-server.js.map +1 -0
  47. package/dist/svelte.d.ts +53 -0
  48. package/dist/svelte.js +244 -0
  49. package/dist/svelte.js.map +1 -0
  50. package/dist/vite.d.ts +30 -0
  51. package/dist/vite.js +131 -0
  52. package/dist/vite.js.map +1 -0
  53. package/dist/vue-server.d.ts +20 -0
  54. package/dist/vue-server.js +26 -0
  55. package/dist/vue-server.js.map +1 -0
  56. package/dist/vue.d.ts +64 -0
  57. package/dist/vue.js +250 -0
  58. package/dist/vue.js.map +1 -0
  59. package/dist/webmcp.d.ts +19 -0
  60. package/dist/webmcp.js +36 -0
  61. package/dist/webmcp.js.map +1 -0
  62. package/package.json +172 -4
  63. package/skills/agent-native-actions/SKILL.md +76 -0
@@ -0,0 +1,19 @@
1
+ import { ActionClient } from './client.js';
2
+ import { o as ActionMetadataSummary } from './registry-CIe_aYoE.js';
3
+ import '@standard-schema/spec';
4
+
5
+ interface RegisterWebMcpOptions {
6
+ /** Explicit allowlist of action names to expose to the browser's `navigator.modelContext`. */
7
+ include: readonly string[];
8
+ /** Optional metadata overrides (otherwise fetched from `<baseUrl>`). */
9
+ metadata?: readonly ActionMetadataSummary[];
10
+ }
11
+ /**
12
+ * Register selected actions with browser-embedded agents via `navigator.modelContext`
13
+ * (WebMCP), executing under the user's live browser session.
14
+ */
15
+ declare function registerWebMcpTools<TRegistry>(client: ActionClient<TRegistry>, options: RegisterWebMcpOptions): Promise<{
16
+ registered: string[];
17
+ }>;
18
+
19
+ export { type RegisterWebMcpOptions, registerWebMcpTools };
package/dist/webmcp.js ADDED
@@ -0,0 +1,36 @@
1
+ // src/webmcp.ts
2
+ async function registerWebMcpTools(client, options) {
3
+ if (typeof navigator === "undefined") {
4
+ return { registered: [] };
5
+ }
6
+ const modelContext = navigator.modelContext;
7
+ if (!modelContext?.registerTool) {
8
+ return { registered: [] };
9
+ }
10
+ let catalog = options.metadata ?? [];
11
+ if (catalog.length === 0) {
12
+ const res = await fetch(client.baseUrl, { credentials: "same-origin" });
13
+ if (res.ok) {
14
+ const json = await res.json();
15
+ catalog = json.actions ?? [];
16
+ }
17
+ }
18
+ const allow = new Set(options.include);
19
+ const registered = [];
20
+ for (const item of catalog) {
21
+ if (!allow.has(item.name) || !item.mcpExposed) continue;
22
+ modelContext.registerTool({
23
+ name: item.name,
24
+ description: item.description,
25
+ execute: async (input) => client.call(item.name, input, {
26
+ method: item.httpMethod ?? "POST"
27
+ })
28
+ });
29
+ registered.push(item.name);
30
+ }
31
+ return { registered };
32
+ }
33
+ export {
34
+ registerWebMcpTools
35
+ };
36
+ //# sourceMappingURL=webmcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/webmcp.ts"],"sourcesContent":["import type { ActionClient } from \"./client.js\";\nimport type { ActionMetadataSummary } from \"./types.js\";\n\ninterface BrowserModelContext {\n registerTool?: (tool: {\n name: string;\n description: string;\n inputSchema?: Record<string, unknown>;\n execute: (input: Record<string, unknown>) => Promise<unknown>;\n }) => void;\n}\n\nexport interface RegisterWebMcpOptions {\n /** Explicit allowlist of action names to expose to the browser's `navigator.modelContext`. */\n include: readonly string[];\n /** Optional metadata overrides (otherwise fetched from `<baseUrl>`). */\n metadata?: readonly ActionMetadataSummary[];\n}\n\n/**\n * Register selected actions with browser-embedded agents via `navigator.modelContext`\n * (WebMCP), executing under the user's live browser session.\n */\nexport async function registerWebMcpTools<TRegistry>(\n client: ActionClient<TRegistry>,\n options: RegisterWebMcpOptions,\n): Promise<{ registered: string[] }> {\n if (typeof navigator === \"undefined\") {\n return { registered: [] };\n }\n const modelContext = (\n navigator as Navigator & { modelContext?: BrowserModelContext }\n ).modelContext;\n if (!modelContext?.registerTool) {\n return { registered: [] };\n }\n\n let catalog: readonly ActionMetadataSummary[] = options.metadata ?? [];\n if (catalog.length === 0) {\n const res = await fetch(client.baseUrl, { credentials: \"same-origin\" });\n if (res.ok) {\n const json = (await res.json()) as { actions?: ActionMetadataSummary[] };\n catalog = json.actions ?? [];\n }\n }\n\n const allow = new Set(options.include);\n const registered: string[] = [];\n\n for (const item of catalog) {\n if (!allow.has(item.name) || !item.mcpExposed) continue;\n modelContext.registerTool({\n name: item.name,\n description: item.description,\n execute: async (input) =>\n client.call(item.name as never, input as never, {\n method: item.httpMethod ?? \"POST\",\n }),\n });\n registered.push(item.name);\n }\n\n return { registered };\n}\n"],"mappings":";AAuBA,eAAsB,oBACpB,QACA,SACmC;AACnC,MAAI,OAAO,cAAc,aAAa;AACpC,WAAO,EAAE,YAAY,CAAC,EAAE;AAAA,EAC1B;AACA,QAAM,eACJ,UACA;AACF,MAAI,CAAC,cAAc,cAAc;AAC/B,WAAO,EAAE,YAAY,CAAC,EAAE;AAAA,EAC1B;AAEA,MAAI,UAA4C,QAAQ,YAAY,CAAC;AACrE,MAAI,QAAQ,WAAW,GAAG;AACxB,UAAM,MAAM,MAAM,MAAM,OAAO,SAAS,EAAE,aAAa,cAAc,CAAC;AACtE,QAAI,IAAI,IAAI;AACV,YAAM,OAAQ,MAAM,IAAI,KAAK;AAC7B,gBAAU,KAAK,WAAW,CAAC;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,IAAI,QAAQ,OAAO;AACrC,QAAM,aAAuB,CAAC;AAE9B,aAAW,QAAQ,SAAS;AAC1B,QAAI,CAAC,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,WAAY;AAC/C,iBAAa,aAAa;AAAA,MACxB,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,SAAS,OAAO,UACd,OAAO,KAAK,KAAK,MAAe,OAAgB;AAAA,QAC9C,QAAQ,KAAK,cAAc;AAAA,MAC7B,CAAC;AAAA,IACL,CAAC;AACD,eAAW,KAAK,KAAK,IAAI;AAAA,EAC3B;AAEA,SAAO,EAAE,WAAW;AACtB;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,174 @@
1
1
  {
2
2
  "name": "@agent-native/actions",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Define app operations once and get typed UI hooks, HTTP endpoints, a CLI, an MCP server, and AI SDK tools in any framework.",
5
+ "keywords": [
6
+ "actions",
7
+ "agent-native",
8
+ "ai-sdk",
9
+ "mcp",
10
+ "nextjs",
11
+ "rpc",
12
+ "solidjs",
13
+ "standard-schema",
14
+ "svelte",
15
+ "vite",
16
+ "vue",
17
+ "zod"
18
+ ],
19
+ "homepage": "https://agent-native.com/docs/actions-package/",
20
+ "bugs": {
21
+ "url": "https://github.com/BuilderIO/agent-native/issues"
22
+ },
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/BuilderIO/agent-native",
27
+ "directory": "packages/actions"
28
+ },
29
+ "bin": {
30
+ "actions": "./dist/cli.js",
31
+ "agent-native-actions": "./dist/cli.js"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "skills",
36
+ "README.md"
37
+ ],
38
+ "type": "module",
39
+ "sideEffects": false,
40
+ "main": "./dist/index.js",
41
+ "types": "./dist/index.d.ts",
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/index.d.ts",
45
+ "default": "./dist/index.js"
46
+ },
47
+ "./contract": {
48
+ "types": "./dist/contract.d.ts",
49
+ "default": "./dist/contract.js"
50
+ },
51
+ "./client": {
52
+ "types": "./dist/client.d.ts",
53
+ "default": "./dist/client.js"
54
+ },
55
+ "./react": {
56
+ "types": "./dist/react.d.ts",
57
+ "default": "./dist/react.js"
58
+ },
59
+ "./solid": {
60
+ "types": "./dist/solid.d.ts",
61
+ "default": "./dist/solid.js"
62
+ },
63
+ "./vue": {
64
+ "types": "./dist/vue.d.ts",
65
+ "default": "./dist/vue.js"
66
+ },
67
+ "./vue/server": {
68
+ "types": "./dist/vue-server.d.ts",
69
+ "default": "./dist/vue-server.js"
70
+ },
71
+ "./nuxt": {
72
+ "types": "./dist/nuxt.d.ts",
73
+ "default": "./dist/nuxt.js"
74
+ },
75
+ "./svelte": {
76
+ "types": "./dist/svelte.d.ts",
77
+ "default": "./dist/svelte.js"
78
+ },
79
+ "./svelte/server": {
80
+ "types": "./dist/svelte-server.d.ts",
81
+ "default": "./dist/svelte-server.js"
82
+ },
83
+ "./next": {
84
+ "types": "./dist/next.d.ts",
85
+ "default": "./dist/next.js"
86
+ },
87
+ "./next/server": {
88
+ "types": "./dist/next-server.d.ts",
89
+ "default": "./dist/next-server.js"
90
+ },
91
+ "./next/config": {
92
+ "types": "./dist/next-config.d.ts",
93
+ "default": "./dist/next-config.js"
94
+ },
95
+ "./next/pages": {
96
+ "types": "./dist/next-pages.d.ts",
97
+ "default": "./dist/next-pages.js"
98
+ },
99
+ "./vite": {
100
+ "types": "./dist/vite.d.ts",
101
+ "default": "./dist/vite.js"
102
+ },
103
+ "./webmcp": {
104
+ "types": "./dist/webmcp.d.ts",
105
+ "default": "./dist/webmcp.js"
106
+ },
107
+ "./cli": "./dist/cli.js"
108
+ },
109
+ "publishConfig": {
110
+ "access": "public",
111
+ "provenance": true
112
+ },
113
+ "scripts": {
114
+ "build": "node -e \"import('node:fs').then((fs)=>fs.rmSync('dist',{recursive:true,force:true}))\" && tsup",
115
+ "dev": "tsup --watch",
116
+ "typecheck": "tsgo --noEmit",
117
+ "test": "vitest run",
118
+ "prepublishOnly": "npm run build"
119
+ },
120
+ "dependencies": {
121
+ "@modelcontextprotocol/server": "2.4.0",
122
+ "@standard-schema/spec": "^1.1.0",
123
+ "jiti": "^2.7.0"
124
+ },
125
+ "devDependencies": {
126
+ "@tanstack/react-query": "^5.101.2",
127
+ "@types/node": "^24.2.1",
128
+ "@types/react": "^19.2.14",
129
+ "react": "catalog:",
130
+ "solid-js": "^1.9.10",
131
+ "tsup": "^8.4.0",
132
+ "typescript": "catalog:",
133
+ "typescript-7": "catalog:",
134
+ "vite": "catalog:",
135
+ "vitest": "catalog:",
136
+ "zod": "catalog:"
137
+ },
138
+ "peerDependencies": {
139
+ "@tanstack/react-query": ">=5",
140
+ "next": ">=14",
141
+ "react": ">=18",
142
+ "solid-js": ">=1.9",
143
+ "svelte": ">=5",
144
+ "vite": ">=5",
145
+ "vue": ">=3.4",
146
+ "zod": ">=3.24"
147
+ },
148
+ "peerDependenciesMeta": {
149
+ "@tanstack/react-query": {
150
+ "optional": true
151
+ },
152
+ "next": {
153
+ "optional": true
154
+ },
155
+ "react": {
156
+ "optional": true
157
+ },
158
+ "solid-js": {
159
+ "optional": true
160
+ },
161
+ "svelte": {
162
+ "optional": true
163
+ },
164
+ "vite": {
165
+ "optional": true
166
+ },
167
+ "vue": {
168
+ "optional": true
169
+ },
170
+ "zod": {
171
+ "optional": true
172
+ }
173
+ }
174
+ }
@@ -0,0 +1,76 @@
1
+ ---
2
+ name: agent-native-actions
3
+ description: Build and maintain backend operations with @agent-native/actions. Use whenever adding a new feature, endpoint, mutation, data fetch, CLI command, or AI tool in this app so UI, HTTP, CLI, MCP, and AI SDKs always share one typed action.
4
+ ---
5
+
6
+ # Agent-Native Actions
7
+
8
+ This repository uses `@agent-native/actions` as the single source of truth for application operations.
9
+
10
+ ## Core Rule: Always Build New Capabilities as Actions
11
+
12
+ When adding any new backend feature, query, mutation, or integration:
13
+
14
+ 1. **Create one file per operation in `actions/<verb-noun>.ts`** (for example `actions/list-deals.ts`, `actions/create-invoice.ts`, `actions/refund-charge.ts`).
15
+ 2. **Do not create parallel ad-hoc `/api/*` REST routes, Next.js Server Actions, tRPC procedures, or standalone database scripts** for normal app operations. Put the operation in `actions/` so your UI hooks, HTTP API, CLI, MCP server, and AI SDK tools automatically stay in parity.
16
+ 3. Reserve custom routes only for streaming responses, binary/file uploads, inbound third-party webhooks, OAuth callbacks, or non-JSON endpoints.
17
+
18
+ ## Defining an Action
19
+
20
+ Use the app's typed `defineAction` helper from `actions/context.ts` if present (otherwise import `defineAction` from `@agent-native/actions`):
21
+
22
+ ```ts
23
+ // actions/list-todos.ts
24
+ import { z } from "zod";
25
+ import { defineAction } from "./context"; // or "@agent-native/actions"
26
+
27
+ export default defineAction({
28
+ description: "List todos for the current user",
29
+ schema: z.object({
30
+ done: z.boolean().optional().describe("Filter by completion status"),
31
+ }),
32
+ http: { method: "GET" },
33
+ readOnly: true,
34
+ authorize: (_input, ctx) => Boolean(ctx.user),
35
+ run: async ({ done }, ctx) => {
36
+ return db.todos.findMany({ where: { userId: ctx.user.id, done } });
37
+ },
38
+ });
39
+ ```
40
+
41
+ ### Action Authoring Checklist
42
+
43
+ - **Filename = action name:** `actions/create-todo.ts` becomes `create-todo`. Subfolders join with hyphens (`actions/billing/refund.ts` -> `billing-refund`). Prefix shared helpers with `_` (`actions/_shared/db.ts`) so they are not registered as actions.
44
+ - **Describe every field:** Always provide a concise one-line `description` and `.describe(...)` on schema fields so the CLI `--help`, MCP clients, and AI agents know how to call the action.
45
+ - **Mark reads explicitly:** Set `http: { method: "GET" }` and `readOnly: true` on read-only queries. Leave mutations on default `POST` (or `PUT` / `DELETE`).
46
+ - **Enforce auth in `authorize(input, ctx)`:** Never trust UI hiding. Check `ctx` (resolved once in `actions/context.ts`) inside `authorize(input, ctx)` so HTTP, CLI, MCP, and AI callers all go through the same check.
47
+ - **Gate sensitive writes with `needsApproval`:** For destructive, irreversible, or high-value mutations (deleting data, issuing refunds, sending external emails), set `needsApproval: true` or `needsApproval: (input, ctx) => ...` and `destructive: true`.
48
+ - **Throw structured errors with `fail()` or `defineActionErrors()`:** Never throw bare strings or swallow errors into fake empty results. Use `fail("Invoice not found", { statusCode: 404, errorCode: "not_found" })`.
49
+ - **Hide internal-only actions from external agents when needed:** Set `mcpTool: false` (or `agentTool: false`) on UI-only or internal admin operations.
50
+
51
+ ## Calling Actions from UI Code
52
+
53
+ Use the typed client hooks for this repo's framework — never hand-write `fetch("/api/...")` calls for actions:
54
+
55
+ - **React / Next.js:** `useActionQuery("list-todos", { done: false })` and `useActionMutation("create-todo")` from `@agent-native/actions/react` (or `@agent-native/actions/next`)
56
+ - **SolidJS:** `createActionQuery` / `createActionMutation` from `@agent-native/actions/solid`
57
+ - **Vue / Nuxt:** `useActionQuery` / `useActionMutation` from `@agent-native/actions/vue`
58
+ - **Svelte 5 / SvelteKit:** `createActionQuery` / `createActionMutation` from `@agent-native/actions/svelte`
59
+ - **Plain TypeScript:** `createActionClient()` from `@agent-native/actions/client`
60
+
61
+ Mutations automatically invalidate related queries so views stay fresh without manual query-key plumbing.
62
+
63
+ ## Regenerating Types & Verifying via CLI
64
+
65
+ After adding or changing actions:
66
+
67
+ 1. Regenerate `.generated/actions.ts` and `.generated/action-types.d.ts` if the dev server is not running:
68
+ ```bash
69
+ npx @agent-native/actions generate
70
+ ```
71
+ 2. Verify discovery and execution through the CLI:
72
+ ```bash
73
+ pnpm action --list
74
+ pnpm action <action-name> --help
75
+ pnpm action <action-name> '{"key":"value"}'
76
+ ```