@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.
- package/README.md +41 -2
- package/dist/chunk-4X4LYULO.js +108 -0
- package/dist/chunk-4X4LYULO.js.map +1 -0
- package/dist/chunk-D66CG6AI.js +265 -0
- package/dist/chunk-D66CG6AI.js.map +1 -0
- package/dist/chunk-KWA4U6DI.js +273 -0
- package/dist/chunk-KWA4U6DI.js.map +1 -0
- package/dist/chunk-SXOEFWAM.js +147 -0
- package/dist/chunk-SXOEFWAM.js.map +1 -0
- package/dist/cli.js +1765 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-C87WZhlZ.d.ts +223 -0
- package/dist/client.d.ts +70 -0
- package/dist/client.js +110 -0
- package/dist/client.js.map +1 -0
- package/dist/contract.d.ts +251 -0
- package/dist/contract.js +372 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +251 -0
- package/dist/index.js +704 -0
- package/dist/index.js.map +1 -0
- package/dist/next-config.d.ts +16 -0
- package/dist/next-config.js +46 -0
- package/dist/next-config.js.map +1 -0
- package/dist/next-pages.d.ts +12 -0
- package/dist/next-pages.js +13 -0
- package/dist/next-pages.js.map +1 -0
- package/dist/next-server.d.ts +41 -0
- package/dist/next-server.js +96 -0
- package/dist/next-server.js.map +1 -0
- package/dist/next.d.ts +39 -0
- package/dist/next.js +68 -0
- package/dist/next.js.map +1 -0
- package/dist/nuxt.d.ts +17 -0
- package/dist/nuxt.js +22 -0
- package/dist/nuxt.js.map +1 -0
- package/dist/react.d.ts +50 -0
- package/dist/react.js +194 -0
- package/dist/react.js.map +1 -0
- package/dist/registry-CIe_aYoE.d.ts +263 -0
- package/dist/solid.d.ts +39 -0
- package/dist/solid.js +229 -0
- package/dist/solid.js.map +1 -0
- package/dist/svelte-server.d.ts +23 -0
- package/dist/svelte-server.js +33 -0
- package/dist/svelte-server.js.map +1 -0
- package/dist/svelte.d.ts +53 -0
- package/dist/svelte.js +244 -0
- package/dist/svelte.js.map +1 -0
- package/dist/vite.d.ts +30 -0
- package/dist/vite.js +131 -0
- package/dist/vite.js.map +1 -0
- package/dist/vue-server.d.ts +20 -0
- package/dist/vue-server.js +26 -0
- package/dist/vue-server.js.map +1 -0
- package/dist/vue.d.ts +64 -0
- package/dist/vue.js +250 -0
- package/dist/vue.js.map +1 -0
- package/dist/webmcp.d.ts +19 -0
- package/dist/webmcp.js +36 -0
- package/dist/webmcp.js.map +1 -0
- package/package.json +172 -4
- package/skills/agent-native-actions/SKILL.md +76 -0
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @agent-native/actions
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Define your app's operations once with `defineAction()` and call them everywhere — typed UI hooks (React, SolidJS, Vue, Svelte), HTTP endpoints, a built-in CLI, a Streamable HTTP & `stdio` MCP server, and AI SDK tools (Vercel AI SDK, Anthropic SDK, OpenAI SDK).
|
|
4
|
+
|
|
5
|
+
Works incrementally in **any** existing app — Next.js, Vite, SolidJS, Vue, Nuxt, SvelteKit, Hono, Express, Fastify, Cloudflare Workers, or plain Node.js.
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @agent-native/actions init
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Define an action in `actions/create-todo.ts`:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineAction } from "@agent-native/actions";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import { db } from "../lib/db";
|
|
19
|
+
|
|
20
|
+
export default defineAction({
|
|
21
|
+
description: "Create a new todo item",
|
|
22
|
+
schema: z.object({
|
|
23
|
+
title: z.string().describe("What needs to be done"),
|
|
24
|
+
}),
|
|
25
|
+
run: async ({ title }, ctx) => {
|
|
26
|
+
return db.todos.create({ title, userId: ctx.user.id });
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Call it from everywhere:
|
|
32
|
+
|
|
33
|
+
- **UI Hooks:** `useActionMutation("create-todo")` (React, SolidJS, Vue, Svelte 5)
|
|
34
|
+
- **HTTP:** `POST /api/agent-native/actions/create-todo`
|
|
35
|
+
- **CLI:** `pnpm action create-todo --title "Ship docs"`
|
|
36
|
+
- **MCP:** Streamable HTTP at `/api/agent-native/mcp` or `npx @agent-native/actions mcp`
|
|
37
|
+
- **AI SDKs:** `toAiSdkTools()`, `toAnthropicTools()`, `toOpenAiTools()`
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
Full guides, framework integrations, and auth/migration recipes:
|
|
42
|
+
https://agent-native.com/docs/actions-package/?utm_source=npm&utm_medium=referral&utm_content=actions-readme
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var ACTION_ERROR_BRAND = /* @__PURE__ */ Symbol.for("agent-native.actions.ActionError");
|
|
3
|
+
var POST_COMMIT_ERROR_BRAND = /* @__PURE__ */ Symbol.for(
|
|
4
|
+
"agent-native.actions.ActionPostCommitError"
|
|
5
|
+
);
|
|
6
|
+
var ActionError = class extends Error {
|
|
7
|
+
[ACTION_ERROR_BRAND] = true;
|
|
8
|
+
actionContractError = true;
|
|
9
|
+
statusCode;
|
|
10
|
+
errorCode;
|
|
11
|
+
details;
|
|
12
|
+
committed;
|
|
13
|
+
constructor(message, options = {}) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "ActionError";
|
|
16
|
+
this.statusCode = options.statusCode ?? options.status ?? 400;
|
|
17
|
+
this.errorCode = options.errorCode ?? "action_failed";
|
|
18
|
+
this.details = options.details;
|
|
19
|
+
this.committed = options.committed ?? false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var ActionPostCommitError = class extends ActionError {
|
|
23
|
+
[POST_COMMIT_ERROR_BRAND] = true;
|
|
24
|
+
cause;
|
|
25
|
+
constructor(message, cause, details) {
|
|
26
|
+
super(message, {
|
|
27
|
+
statusCode: 500,
|
|
28
|
+
errorCode: "post_commit_error",
|
|
29
|
+
committed: true,
|
|
30
|
+
...details ? { details } : {}
|
|
31
|
+
});
|
|
32
|
+
this.name = "ActionPostCommitError";
|
|
33
|
+
this.cause = cause;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function isActionError(value) {
|
|
37
|
+
if (value instanceof ActionError) return true;
|
|
38
|
+
if (typeof value !== "object" || value === null) return false;
|
|
39
|
+
if (ACTION_ERROR_BRAND in value) return true;
|
|
40
|
+
return value.actionContractError === true && typeof value.errorCode === "string";
|
|
41
|
+
}
|
|
42
|
+
function isActionPostCommitError(value) {
|
|
43
|
+
return value instanceof ActionPostCommitError || typeof value === "object" && value !== null && POST_COMMIT_ERROR_BRAND in value;
|
|
44
|
+
}
|
|
45
|
+
function fail(message, options = {}) {
|
|
46
|
+
throw new ActionError(message, options);
|
|
47
|
+
}
|
|
48
|
+
function defineActionErrors(...codes) {
|
|
49
|
+
const uniqueCodes = Object.freeze([
|
|
50
|
+
...new Set(codes)
|
|
51
|
+
]);
|
|
52
|
+
const allowed = new Set(uniqueCodes);
|
|
53
|
+
const errorSet = {
|
|
54
|
+
codes: uniqueCodes,
|
|
55
|
+
fail(message, code, options = {}) {
|
|
56
|
+
if (!allowed.has(code)) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Unknown action errorCode "${code}". Declared codes: ${uniqueCodes.join(", ")}`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
throw new ActionError(message, { ...options, errorCode: code });
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return Object.freeze(errorSet);
|
|
65
|
+
}
|
|
66
|
+
function serializeActionErrorBody(error) {
|
|
67
|
+
if (isActionPostCommitError(error)) {
|
|
68
|
+
return {
|
|
69
|
+
statusCode: 500,
|
|
70
|
+
body: {
|
|
71
|
+
error: "Action completed but post-execution processing failed.",
|
|
72
|
+
errorCode: error.errorCode,
|
|
73
|
+
committed: true,
|
|
74
|
+
...error.details ? { details: error.details } : {}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (isActionError(error)) {
|
|
79
|
+
const safeMessage = error.statusCode >= 500 ? "Internal action error." : error.message;
|
|
80
|
+
return {
|
|
81
|
+
statusCode: error.statusCode,
|
|
82
|
+
body: {
|
|
83
|
+
error: safeMessage,
|
|
84
|
+
errorCode: error.errorCode,
|
|
85
|
+
...error.committed ? { committed: true } : {},
|
|
86
|
+
...error.statusCode < 500 && error.details ? { details: error.details } : {}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
statusCode: 500,
|
|
92
|
+
body: {
|
|
93
|
+
error: "Internal action error.",
|
|
94
|
+
errorCode: "internal_error"
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
ActionError,
|
|
101
|
+
ActionPostCommitError,
|
|
102
|
+
isActionError,
|
|
103
|
+
isActionPostCommitError,
|
|
104
|
+
fail,
|
|
105
|
+
defineActionErrors,
|
|
106
|
+
serializeActionErrorBody
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=chunk-4X4LYULO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["export interface ActionFailOptions {\n /** HTTP status code (preferred, matches `@agent-native/core`). Defaults to 400. */\n statusCode?: number;\n /** Alias for `statusCode`. */\n status?: number;\n /** Machine-readable error code surfaced to UI callers, MCP clients, and agents. */\n errorCode?: string;\n /** Bounded structured context for callers/agents (ids, field names, limits). */\n details?: Record<string, unknown>;\n}\n\nconst ACTION_ERROR_BRAND = Symbol.for(\"agent-native.actions.ActionError\");\nconst POST_COMMIT_ERROR_BRAND = Symbol.for(\n \"agent-native.actions.ActionPostCommitError\",\n);\n\nexport class ActionError extends Error {\n readonly [ACTION_ERROR_BRAND] = true;\n readonly actionContractError = true;\n readonly statusCode: number;\n readonly errorCode: string;\n readonly details: Record<string, unknown> | undefined;\n readonly committed: boolean;\n\n constructor(\n message: string,\n options: ActionFailOptions & { committed?: boolean } = {},\n ) {\n super(message);\n this.name = \"ActionError\";\n this.statusCode = options.statusCode ?? options.status ?? 400;\n this.errorCode = options.errorCode ?? \"action_failed\";\n this.details = options.details;\n this.committed = options.committed ?? false;\n }\n}\n\n/**\n * Raised when an action's `run()` already completed (so side effects may have\n * committed), but a post-run step such as `outputSchema` validation or\n * `onAfterMutate` failed. Callers must not blindly retry writes on this error.\n */\nexport class ActionPostCommitError extends ActionError {\n readonly [POST_COMMIT_ERROR_BRAND] = true;\n override readonly cause: unknown;\n\n constructor(\n message: string,\n cause?: unknown,\n details?: Record<string, unknown>,\n ) {\n super(message, {\n statusCode: 500,\n errorCode: \"post_commit_error\",\n committed: true,\n ...(details ? { details } : {}),\n });\n this.name = \"ActionPostCommitError\";\n this.cause = cause;\n }\n}\n\nexport function isActionError(value: unknown): value is ActionError {\n if (value instanceof ActionError) return true;\n if (typeof value !== \"object\" || value === null) return false;\n if (ACTION_ERROR_BRAND in value) return true;\n return (\n (value as { actionContractError?: unknown }).actionContractError === true &&\n typeof (value as { errorCode?: unknown }).errorCode === \"string\"\n );\n}\n\nexport function isActionPostCommitError(\n value: unknown,\n): value is ActionPostCommitError {\n return (\n value instanceof ActionPostCommitError ||\n (typeof value === \"object\" &&\n value !== null &&\n POST_COMMIT_ERROR_BRAND in value)\n );\n}\n\n/**\n * Throw a structured, caller-readable error from an action.\n * Compatible with `@agent-native/core`'s `fail()`.\n */\nexport function fail(message: string, options: ActionFailOptions = {}): never {\n throw new ActionError(message, options);\n}\n\nexport interface ActionErrorSet<TCode extends string> {\n readonly codes: readonly TCode[];\n fail: (\n message: string,\n code: TCode,\n options?: Omit<ActionFailOptions, \"errorCode\">,\n ) => never;\n}\n\n/**\n * Declare a closed set of error codes for an action, matching `@agent-native/core`'s\n * `defineActionErrors(\"not_found\", \"already_paid\")`.\n */\nexport function defineActionErrors<\n const TCodes extends readonly [string, ...string[]],\n>(...codes: TCodes): ActionErrorSet<TCodes[number]> {\n const uniqueCodes: readonly TCodes[number][] = Object.freeze([\n ...new Set(codes),\n ]);\n const allowed = new Set<string>(uniqueCodes);\n const errorSet: ActionErrorSet<TCodes[number]> = {\n codes: uniqueCodes,\n fail(message, code, options = {}) {\n if (!allowed.has(code)) {\n throw new Error(\n `Unknown action errorCode \"${code}\". Declared codes: ${uniqueCodes.join(\", \")}`,\n );\n }\n throw new ActionError(message, { ...options, errorCode: code });\n },\n };\n return Object.freeze(errorSet);\n}\n\nexport function serializeActionErrorBody(error: unknown): {\n statusCode: number;\n body: {\n error: string;\n errorCode: string;\n committed?: true;\n details?: Record<string, unknown>;\n };\n} {\n if (isActionPostCommitError(error)) {\n return {\n statusCode: 500,\n body: {\n error: \"Action completed but post-execution processing failed.\",\n errorCode: error.errorCode,\n committed: true,\n ...(error.details ? { details: error.details } : {}),\n },\n };\n }\n if (isActionError(error)) {\n const safeMessage =\n error.statusCode >= 500 ? \"Internal action error.\" : error.message;\n return {\n statusCode: error.statusCode,\n body: {\n error: safeMessage,\n errorCode: error.errorCode,\n ...(error.committed ? { committed: true as const } : {}),\n ...(error.statusCode < 500 && error.details\n ? { details: error.details }\n : {}),\n },\n };\n }\n return {\n statusCode: 500,\n body: {\n error: \"Internal action error.\",\n errorCode: \"internal_error\",\n },\n };\n}\n"],"mappings":";AAWA,IAAM,qBAAqB,uBAAO,IAAI,kCAAkC;AACxE,IAAM,0BAA0B,uBAAO;AAAA,EACrC;AACF;AAEO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,CAAU,kBAAkB,IAAI;AAAA,EACvB,sBAAsB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,SACA,UAAuD,CAAC,GACxD;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ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AE,GAAG,SAAS,WAAW,KAAK,CAAC;AAAA,IAChE;AAAA,EACF;AACA,SAAO,OAAO,OAAO,QAAQ;AAC/B;AAEO,SAAS,yBAAyB,OAQvC;AACA,MAAI,wBAAwB,KAAK,GAAG;AAClC,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,MAAM;AAAA,QACJ,OAAO;AAAA,QACP,WAAW,MAAM;AAAA,QACjB,WAAW;AAAA,QACX,GAAI,MAAM,UAAU,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AACA,MAAI,cAAc,KAAK,GAAG;AACxB,UAAM,cACJ,MAAM,cAAc,MAAM,2BAA2B,MAAM;AAC7D,WAAO;AAAA,MACL,YAAY,MAAM;AAAA,MAClB,MAAM;AAAA,QACJ,OAAO;AAAA,QACP,WAAW,MAAM;AAAA,QACjB,GAAI,MAAM,YAAY,EAAE,WAAW,KAAc,IAAI,CAAC;AAAA,QACtD,GAAI,MAAM,aAAa,OAAO,MAAM,UAChC,EAAE,SAAS,MAAM,QAAQ,IACzB,CAAC;AAAA,MACP;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AAAA,MACJ,OAAO;AAAA,MACP,WAAW;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActionError,
|
|
3
|
+
serializeActionErrorBody
|
|
4
|
+
} from "./chunk-4X4LYULO.js";
|
|
5
|
+
|
|
6
|
+
// src/http.ts
|
|
7
|
+
var DEFAULT_CORS_METHODS = "GET, POST, PUT, PATCH, DELETE, OPTIONS";
|
|
8
|
+
var DEFAULT_CORS_HEADERS = "Content-Type, Authorization, X-Action-Approval, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID";
|
|
9
|
+
function jsonResponse(body, status, extraHeaders) {
|
|
10
|
+
const headers = new Headers({
|
|
11
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
12
|
+
"Cache-Control": "no-store",
|
|
13
|
+
...extraHeaders
|
|
14
|
+
});
|
|
15
|
+
return new Response(JSON.stringify(body), { status, headers });
|
|
16
|
+
}
|
|
17
|
+
function buildCorsHeaders(request, cors) {
|
|
18
|
+
if (!cors) return {};
|
|
19
|
+
const origin = request.headers.get("origin");
|
|
20
|
+
if (!origin) return {};
|
|
21
|
+
let allowOrigin = null;
|
|
22
|
+
if (cors === true) {
|
|
23
|
+
allowOrigin = "*";
|
|
24
|
+
} else if (typeof cors.origin === "string") {
|
|
25
|
+
allowOrigin = cors.origin;
|
|
26
|
+
} else if (Array.isArray(cors.origin)) {
|
|
27
|
+
allowOrigin = cors.origin.includes(origin) ? origin : null;
|
|
28
|
+
} else if (typeof cors.origin === "function") {
|
|
29
|
+
allowOrigin = cors.origin(origin) ? origin : null;
|
|
30
|
+
}
|
|
31
|
+
if (!allowOrigin) return {};
|
|
32
|
+
const headers = {
|
|
33
|
+
"Access-Control-Allow-Origin": allowOrigin,
|
|
34
|
+
"Access-Control-Allow-Methods": DEFAULT_CORS_METHODS,
|
|
35
|
+
"Access-Control-Allow-Headers": DEFAULT_CORS_HEADERS,
|
|
36
|
+
Vary: "Origin"
|
|
37
|
+
};
|
|
38
|
+
if (typeof cors === "object" && cors.credentials && allowOrigin !== "*") {
|
|
39
|
+
headers["Access-Control-Allow-Credentials"] = "true";
|
|
40
|
+
}
|
|
41
|
+
return headers;
|
|
42
|
+
}
|
|
43
|
+
function checkCsrfOrigin(request, csrfProtection) {
|
|
44
|
+
if (!csrfProtection) return null;
|
|
45
|
+
const method = request.method.toUpperCase();
|
|
46
|
+
if (method === "GET" || method === "HEAD" || method === "OPTIONS") {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const hasCookie = Boolean(request.headers.get("cookie"));
|
|
50
|
+
const hasBearer = Boolean(request.headers.get("authorization"));
|
|
51
|
+
if (!hasCookie || hasBearer) return null;
|
|
52
|
+
const origin = request.headers.get("origin");
|
|
53
|
+
if (!origin) return null;
|
|
54
|
+
const requestOrigin = new URL(request.url).origin;
|
|
55
|
+
if (origin !== requestOrigin) {
|
|
56
|
+
return jsonResponse(
|
|
57
|
+
{
|
|
58
|
+
error: "Cross-origin cookie mutation rejected.",
|
|
59
|
+
errorCode: "csrf_origin_mismatch"
|
|
60
|
+
},
|
|
61
|
+
403
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
function parseQueryParams(url) {
|
|
67
|
+
const encodedInput = url.searchParams.get("input");
|
|
68
|
+
if (encodedInput !== null) {
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(encodedInput);
|
|
71
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
72
|
+
return parsed;
|
|
73
|
+
}
|
|
74
|
+
throw new ActionError('Query parameter "input" must be a JSON object.', {
|
|
75
|
+
statusCode: 400,
|
|
76
|
+
errorCode: "invalid_input"
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error instanceof ActionError) throw error;
|
|
80
|
+
throw new ActionError('Query parameter "input" is not valid JSON.', {
|
|
81
|
+
statusCode: 400,
|
|
82
|
+
errorCode: "invalid_input"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const params = {};
|
|
87
|
+
for (const [key, value] of url.searchParams.entries()) {
|
|
88
|
+
const existing = params[key];
|
|
89
|
+
if (existing !== void 0) {
|
|
90
|
+
params[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];
|
|
91
|
+
} else if (value === "true") {
|
|
92
|
+
params[key] = true;
|
|
93
|
+
} else if (value === "false") {
|
|
94
|
+
params[key] = false;
|
|
95
|
+
} else {
|
|
96
|
+
params[key] = value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return params;
|
|
100
|
+
}
|
|
101
|
+
async function readJsonBody(request) {
|
|
102
|
+
const contentLength = request.headers.get("content-length");
|
|
103
|
+
if (contentLength === "0") return {};
|
|
104
|
+
const text = await request.text();
|
|
105
|
+
if (!text.trim()) return {};
|
|
106
|
+
try {
|
|
107
|
+
return JSON.parse(text);
|
|
108
|
+
} catch {
|
|
109
|
+
throw new ActionError("Request body must be valid JSON.", {
|
|
110
|
+
statusCode: 400,
|
|
111
|
+
errorCode: "invalid_json"
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function stripBasePath(pathname, basePath) {
|
|
116
|
+
const normalizedBase = basePath.replace(/\/+$/, "");
|
|
117
|
+
if (!normalizedBase || normalizedBase === "/") {
|
|
118
|
+
return pathname.replace(/^\/+/, "");
|
|
119
|
+
}
|
|
120
|
+
if (pathname === normalizedBase) return "";
|
|
121
|
+
if (pathname.startsWith(`${normalizedBase}/`)) {
|
|
122
|
+
return pathname.slice(normalizedBase.length + 1);
|
|
123
|
+
}
|
|
124
|
+
return pathname.replace(/^\/+/, "");
|
|
125
|
+
}
|
|
126
|
+
function createActionFetchHandler(registry, options = {}) {
|
|
127
|
+
const basePath = options.basePath ?? "/api/agent-native/actions";
|
|
128
|
+
const csrfProtection = options.csrfProtection ?? true;
|
|
129
|
+
return async (request, override) => {
|
|
130
|
+
const corsHeaders = buildCorsHeaders(request, options.cors);
|
|
131
|
+
const method = request.method.toUpperCase();
|
|
132
|
+
if (method === "OPTIONS") {
|
|
133
|
+
return new Response(null, {
|
|
134
|
+
status: 204,
|
|
135
|
+
headers: {
|
|
136
|
+
Allow: DEFAULT_CORS_METHODS,
|
|
137
|
+
...corsHeaders
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const csrfBlock = checkCsrfOrigin(request, csrfProtection);
|
|
142
|
+
if (csrfBlock) return csrfBlock;
|
|
143
|
+
const url = new URL(request.url);
|
|
144
|
+
const relativePath = override?.actionPath !== void 0 ? override.actionPath.replace(/^\/+/, "") : stripBasePath(url.pathname, basePath);
|
|
145
|
+
if (!relativePath) {
|
|
146
|
+
if (method === "GET") {
|
|
147
|
+
return jsonResponse({ actions: registry.describe() }, 200, corsHeaders);
|
|
148
|
+
}
|
|
149
|
+
return jsonResponse(
|
|
150
|
+
{ error: "Action name is required.", errorCode: "not_found" },
|
|
151
|
+
404,
|
|
152
|
+
corsHeaders
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const resolved = registry.resolveHttpAction(relativePath);
|
|
156
|
+
if (!resolved) {
|
|
157
|
+
return jsonResponse(
|
|
158
|
+
{
|
|
159
|
+
error: `Action "${relativePath}" not found.`,
|
|
160
|
+
errorCode: "not_found"
|
|
161
|
+
},
|
|
162
|
+
404,
|
|
163
|
+
corsHeaders
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
const expectedMethod = resolved.method;
|
|
167
|
+
if (method !== expectedMethod && !(expectedMethod === "GET" && method === "POST")) {
|
|
168
|
+
return jsonResponse(
|
|
169
|
+
{
|
|
170
|
+
error: `Action "${resolved.name}" expects ${expectedMethod}, received ${method}.`,
|
|
171
|
+
errorCode: "method_not_allowed"
|
|
172
|
+
},
|
|
173
|
+
405,
|
|
174
|
+
{ Allow: expectedMethod, ...corsHeaders }
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const rawInput = method === "GET" ? parseQueryParams(url) : await readJsonBody(request);
|
|
179
|
+
const approvalToken = request.headers.get("x-action-approval") ?? void 0;
|
|
180
|
+
const result = await registry.invokeFromRequest(resolved.name, rawInput, {
|
|
181
|
+
caller: "http",
|
|
182
|
+
request,
|
|
183
|
+
...approvalToken !== void 0 ? { approvalToken } : {},
|
|
184
|
+
...override?.platform !== void 0 ? { platform: override.platform } : {}
|
|
185
|
+
});
|
|
186
|
+
return jsonResponse(result ?? null, 200, corsHeaders);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
const { statusCode, body } = serializeActionErrorBody(error);
|
|
189
|
+
return jsonResponse(body, statusCode, corsHeaders);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function toNodeHandler(handler) {
|
|
194
|
+
return async (req, res) => {
|
|
195
|
+
const protoHeader = req.headers["x-forwarded-proto"];
|
|
196
|
+
const protocol = typeof protoHeader === "string" ? (protoHeader.split(",")[0] ?? "http").trim() : "http";
|
|
197
|
+
const host = req.headers.host ?? "localhost";
|
|
198
|
+
const reqUrl = req.url ?? "/";
|
|
199
|
+
const fullUrl = new URL(reqUrl, `${protocol}://${host}`).toString();
|
|
200
|
+
const headers = new Headers();
|
|
201
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
202
|
+
if (typeof value === "string") {
|
|
203
|
+
headers.set(key, value);
|
|
204
|
+
} else if (Array.isArray(value)) {
|
|
205
|
+
for (const item of value) headers.append(key, item);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
209
|
+
let body;
|
|
210
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
211
|
+
if (req.body !== void 0) {
|
|
212
|
+
body = typeof req.body === "string" ? req.body : req.body instanceof Uint8Array ? new Uint8Array(req.body) : JSON.stringify(req.body);
|
|
213
|
+
if (!headers.has("content-type")) {
|
|
214
|
+
headers.set("content-type", "application/json");
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
const chunks = [];
|
|
218
|
+
for await (const chunk of req) {
|
|
219
|
+
chunks.push(
|
|
220
|
+
typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk)
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
if (chunks.length > 0) {
|
|
224
|
+
body = new Uint8Array(Buffer.concat(chunks));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const controller = new AbortController();
|
|
229
|
+
req.on("close", () => {
|
|
230
|
+
if (!res.writableEnded) controller.abort();
|
|
231
|
+
});
|
|
232
|
+
const request = new Request(fullUrl, {
|
|
233
|
+
method,
|
|
234
|
+
headers,
|
|
235
|
+
signal: controller.signal,
|
|
236
|
+
...body !== void 0 ? { body } : {}
|
|
237
|
+
});
|
|
238
|
+
const response = await handler(request);
|
|
239
|
+
res.statusCode = response.status;
|
|
240
|
+
response.headers.forEach((value, key) => {
|
|
241
|
+
res.setHeader(key, value);
|
|
242
|
+
});
|
|
243
|
+
if (!response.body) {
|
|
244
|
+
res.end();
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const reader = response.body.getReader();
|
|
248
|
+
try {
|
|
249
|
+
for (let chunk = await reader.read(); !chunk.done; chunk = await reader.read()) {
|
|
250
|
+
if (res.writableEnded) break;
|
|
251
|
+
res.write(chunk.value);
|
|
252
|
+
}
|
|
253
|
+
} finally {
|
|
254
|
+
reader.releaseLock();
|
|
255
|
+
if (!res.writableEnded) res.end();
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export {
|
|
261
|
+
stripBasePath,
|
|
262
|
+
createActionFetchHandler,
|
|
263
|
+
toNodeHandler
|
|
264
|
+
};
|
|
265
|
+
//# sourceMappingURL=chunk-D66CG6AI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/http.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from \"node:http\";\n\nimport { ActionError, serializeActionErrorBody } from \"./errors.js\";\nimport type { ActionHttpHandlerOptions, ActionsRegistry } from \"./registry.js\";\nimport type { ActionHttpMethod, ActionMap } from \"./types.js\";\n\nconst DEFAULT_CORS_METHODS = \"GET, POST, PUT, PATCH, DELETE, OPTIONS\";\nconst DEFAULT_CORS_HEADERS =\n \"Content-Type, Authorization, X-Action-Approval, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID\";\n\nfunction jsonResponse(\n body: unknown,\n status: number,\n extraHeaders?: Record<string, string>,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"application/json; charset=utf-8\",\n \"Cache-Control\": \"no-store\",\n ...extraHeaders,\n });\n return new Response(JSON.stringify(body), { status, headers });\n}\n\nfunction buildCorsHeaders(\n request: Request,\n cors: ActionHttpHandlerOptions[\"cors\"],\n): Record<string, string> {\n if (!cors) return {};\n const origin = request.headers.get(\"origin\");\n if (!origin) return {};\n\n let allowOrigin: string | null = null;\n if (cors === true) {\n allowOrigin = \"*\";\n } else if (typeof cors.origin === \"string\") {\n allowOrigin = cors.origin;\n } else if (Array.isArray(cors.origin)) {\n allowOrigin = cors.origin.includes(origin) ? origin : null;\n } else if (typeof cors.origin === \"function\") {\n allowOrigin = cors.origin(origin) ? origin : null;\n }\n\n if (!allowOrigin) return {};\n const headers: Record<string, string> = {\n \"Access-Control-Allow-Origin\": allowOrigin,\n \"Access-Control-Allow-Methods\": DEFAULT_CORS_METHODS,\n \"Access-Control-Allow-Headers\": DEFAULT_CORS_HEADERS,\n Vary: \"Origin\",\n };\n if (typeof cors === \"object\" && cors.credentials && allowOrigin !== \"*\") {\n headers[\"Access-Control-Allow-Credentials\"] = \"true\";\n }\n return headers;\n}\n\nfunction checkCsrfOrigin(\n request: Request,\n csrfProtection: boolean,\n): Response | null {\n if (!csrfProtection) return null;\n const method = request.method.toUpperCase();\n if (method === \"GET\" || method === \"HEAD\" || method === \"OPTIONS\") {\n return null;\n }\n const hasCookie = Boolean(request.headers.get(\"cookie\"));\n const hasBearer = Boolean(request.headers.get(\"authorization\"));\n if (!hasCookie || hasBearer) return null;\n\n const origin = request.headers.get(\"origin\");\n if (!origin) return null;\n\n const requestOrigin = new URL(request.url).origin;\n if (origin !== requestOrigin) {\n return jsonResponse(\n {\n error: \"Cross-origin cookie mutation rejected.\",\n errorCode: \"csrf_origin_mismatch\",\n },\n 403,\n );\n }\n return null;\n}\n\nfunction parseQueryParams(url: URL): Record<string, unknown> {\n const encodedInput = url.searchParams.get(\"input\");\n if (encodedInput !== null) {\n try {\n const parsed: unknown = JSON.parse(encodedInput);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed as Record<string, unknown>;\n }\n throw new ActionError('Query parameter \"input\" must be a JSON object.', {\n statusCode: 400,\n errorCode: \"invalid_input\",\n });\n } catch (error) {\n if (error instanceof ActionError) throw error;\n throw new ActionError('Query parameter \"input\" is not valid JSON.', {\n statusCode: 400,\n errorCode: \"invalid_input\",\n });\n }\n }\n\n const params: Record<string, unknown> = {};\n for (const [key, value] of url.searchParams.entries()) {\n const existing = params[key];\n if (existing !== undefined) {\n params[key] = Array.isArray(existing)\n ? [...existing, value]\n : [existing, value];\n } else if (value === \"true\") {\n params[key] = true;\n } else if (value === \"false\") {\n params[key] = false;\n } else {\n params[key] = value;\n }\n }\n return params;\n}\n\nasync function readJsonBody(request: Request): Promise<unknown> {\n const contentLength = request.headers.get(\"content-length\");\n if (contentLength === \"0\") return {};\n\n const text = await request.text();\n if (!text.trim()) return {};\n try {\n return JSON.parse(text) as unknown;\n } catch {\n throw new ActionError(\"Request body must be valid JSON.\", {\n statusCode: 400,\n errorCode: \"invalid_json\",\n });\n }\n}\n\nexport function stripBasePath(pathname: string, basePath: string): string {\n const normalizedBase = basePath.replace(/\\/+$/, \"\");\n if (!normalizedBase || normalizedBase === \"/\") {\n return pathname.replace(/^\\/+/, \"\");\n }\n if (pathname === normalizedBase) return \"\";\n if (pathname.startsWith(`${normalizedBase}/`)) {\n return pathname.slice(normalizedBase.length + 1);\n }\n return pathname.replace(/^\\/+/, \"\");\n}\n\nexport function createActionFetchHandler<\n TCtx,\n TActions extends ActionMap<TCtx>,\n>(\n registry: ActionsRegistry<TCtx, TActions>,\n options: ActionHttpHandlerOptions = {},\n): (\n request: Request,\n override?: { actionPath?: string; platform?: unknown },\n) => Promise<Response> {\n const basePath = options.basePath ?? \"/api/agent-native/actions\";\n const csrfProtection = options.csrfProtection ?? true;\n\n return async (request, override) => {\n const corsHeaders = buildCorsHeaders(request, options.cors);\n const method = request.method.toUpperCase();\n\n if (method === \"OPTIONS\") {\n return new Response(null, {\n status: 204,\n headers: {\n Allow: DEFAULT_CORS_METHODS,\n ...corsHeaders,\n },\n });\n }\n\n const csrfBlock = checkCsrfOrigin(request, csrfProtection);\n if (csrfBlock) return csrfBlock;\n\n const url = new URL(request.url);\n const relativePath =\n override?.actionPath !== undefined\n ? override.actionPath.replace(/^\\/+/, \"\")\n : stripBasePath(url.pathname, basePath);\n\n if (!relativePath) {\n if (method === \"GET\") {\n return jsonResponse({ actions: registry.describe() }, 200, corsHeaders);\n }\n return jsonResponse(\n { error: \"Action name is required.\", errorCode: \"not_found\" },\n 404,\n corsHeaders,\n );\n }\n\n const resolved = registry.resolveHttpAction(relativePath);\n if (!resolved) {\n return jsonResponse(\n {\n error: `Action \"${relativePath}\" not found.`,\n errorCode: \"not_found\",\n },\n 404,\n corsHeaders,\n );\n }\n\n const expectedMethod: ActionHttpMethod = resolved.method;\n if (\n method !== expectedMethod &&\n !(expectedMethod === \"GET\" && method === \"POST\")\n ) {\n return jsonResponse(\n {\n error: `Action \"${resolved.name}\" expects ${expectedMethod}, received ${method}.`,\n errorCode: \"method_not_allowed\",\n },\n 405,\n { Allow: expectedMethod, ...corsHeaders },\n );\n }\n\n try {\n const rawInput =\n method === \"GET\" ? parseQueryParams(url) : await readJsonBody(request);\n\n const approvalToken =\n request.headers.get(\"x-action-approval\") ?? undefined;\n\n const result = await registry.invokeFromRequest(resolved.name, rawInput, {\n caller: \"http\",\n request,\n ...(approvalToken !== undefined ? { approvalToken } : {}),\n ...(override?.platform !== undefined\n ? { platform: override.platform }\n : {}),\n });\n\n return jsonResponse(result ?? null, 200, corsHeaders);\n } catch (error) {\n const { statusCode, body } = serializeActionErrorBody(error);\n return jsonResponse(body, statusCode, corsHeaders);\n }\n };\n}\n\nexport type FetchHandler = (\n request: Request,\n override?: { actionPath?: string; platform?: unknown },\n) => Promise<Response>;\n\ntype NodeRequestWithBody = IncomingMessage & {\n body?: unknown;\n originalUrl?: string | undefined;\n};\n\n/**\n * Adapt any Web Standard Fetch handler (`actions.handler`, `actions.fetchHandler`,\n * or `actions.mcpHandler`) to Node's `(req, res)` signature for Express, Fastify,\n * Connect, or `node:http`.\n */\nexport function toNodeHandler(\n handler: FetchHandler,\n): (req: NodeRequestWithBody, res: ServerResponse) => Promise<void> {\n return async (req, res) => {\n const protoHeader = req.headers[\"x-forwarded-proto\"];\n const protocol =\n typeof protoHeader === \"string\"\n ? (protoHeader.split(\",\")[0] ?? \"http\").trim()\n : \"http\";\n const host = req.headers.host ?? \"localhost\";\n const reqUrl = req.url ?? \"/\";\n const fullUrl = new URL(reqUrl, `${protocol}://${host}`).toString();\n\n const headers = new Headers();\n for (const [key, value] of Object.entries(req.headers)) {\n if (typeof value === \"string\") {\n headers.set(key, value);\n } else if (Array.isArray(value)) {\n for (const item of value) headers.append(key, item);\n }\n }\n\n const method = (req.method ?? \"GET\").toUpperCase();\n let body: BodyInit | undefined;\n\n if (method !== \"GET\" && method !== \"HEAD\") {\n if (req.body !== undefined) {\n body =\n typeof req.body === \"string\"\n ? req.body\n : req.body instanceof Uint8Array\n ? new Uint8Array(req.body)\n : JSON.stringify(req.body);\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n } else {\n const chunks: Buffer[] = [];\n for await (const chunk of req) {\n chunks.push(\n typeof chunk === \"string\" ? Buffer.from(chunk) : Buffer.from(chunk),\n );\n }\n if (chunks.length > 0) {\n body = new Uint8Array(Buffer.concat(chunks));\n }\n }\n }\n\n const controller = new AbortController();\n req.on(\"close\", () => {\n if (!res.writableEnded) controller.abort();\n });\n\n const request = new Request(fullUrl, {\n method,\n headers,\n signal: controller.signal,\n ...(body !== undefined ? { body } : {}),\n });\n\n const response = await handler(request);\n res.statusCode = response.status;\n response.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (!response.body) {\n res.end();\n return;\n }\n\n const reader = response.body.getReader();\n try {\n for (\n let chunk = await reader.read();\n !chunk.done;\n chunk = await reader.read()\n ) {\n if (res.writableEnded) break;\n res.write(chunk.value);\n }\n } finally {\n reader.releaseLock();\n if (!res.writable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