@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/dist/react.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/react.ts
|
|
4
|
+
import {
|
|
5
|
+
queryOptions,
|
|
6
|
+
useMutation,
|
|
7
|
+
useQuery,
|
|
8
|
+
useQueryClient
|
|
9
|
+
} from "@tanstack/react-query";
|
|
10
|
+
|
|
11
|
+
// src/client.ts
|
|
12
|
+
var ActionClientError = class extends Error {
|
|
13
|
+
actionName;
|
|
14
|
+
statusCode;
|
|
15
|
+
errorCode;
|
|
16
|
+
committed;
|
|
17
|
+
details;
|
|
18
|
+
userMessage;
|
|
19
|
+
constructor(params) {
|
|
20
|
+
super(`Action ${params.actionName} failed: ${params.message}`);
|
|
21
|
+
this.name = "ActionClientError";
|
|
22
|
+
this.actionName = params.actionName;
|
|
23
|
+
this.statusCode = params.statusCode;
|
|
24
|
+
this.errorCode = params.errorCode ?? "action_failed";
|
|
25
|
+
this.committed = params.committed ?? false;
|
|
26
|
+
this.details = params.details;
|
|
27
|
+
this.userMessage = params.userMessage;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function actionErrorMessage(error) {
|
|
31
|
+
if (error instanceof ActionClientError) {
|
|
32
|
+
if (error.statusCode >= 500) return void 0;
|
|
33
|
+
return error.userMessage;
|
|
34
|
+
}
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
function buildActionQueryKey(actionName, input, scope) {
|
|
38
|
+
return scope ? ["agent-native-action", scope, actionName, input ?? {}] : ["agent-native-action", actionName, input ?? {}];
|
|
39
|
+
}
|
|
40
|
+
function createActionClient(options = {}) {
|
|
41
|
+
const baseUrl = (options.baseUrl ?? "/api/agent-native/actions").replace(
|
|
42
|
+
/\/+$/,
|
|
43
|
+
""
|
|
44
|
+
);
|
|
45
|
+
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
46
|
+
return {
|
|
47
|
+
baseUrl,
|
|
48
|
+
scope: options.scope,
|
|
49
|
+
queryKey: (name, input, extraScope) => buildActionQueryKey(name, input, extraScope ?? options.scope),
|
|
50
|
+
call: async (name, input, callOptions = {}) => {
|
|
51
|
+
const method = callOptions.method ?? options.methods?.[name] ?? "POST";
|
|
52
|
+
const resolvedBaseHeaders = typeof options.headers === "function" ? await options.headers() : options.headers;
|
|
53
|
+
const headers = new Headers(resolvedBaseHeaders);
|
|
54
|
+
if (callOptions.headers) {
|
|
55
|
+
new Headers(callOptions.headers).forEach((value, key) => {
|
|
56
|
+
headers.set(key, value);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (callOptions.approvalToken) {
|
|
60
|
+
headers.set("X-Action-Approval", callOptions.approvalToken);
|
|
61
|
+
}
|
|
62
|
+
let url = `${baseUrl}/${encodeURIComponent(name)}`;
|
|
63
|
+
let body;
|
|
64
|
+
if (method === "GET") {
|
|
65
|
+
if (input !== void 0 && Object.keys(input).length > 0) {
|
|
66
|
+
const qs = new URLSearchParams({
|
|
67
|
+
input: JSON.stringify(input)
|
|
68
|
+
});
|
|
69
|
+
url = `${url}?${qs.toString()}`;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
headers.set("Content-Type", "application/json");
|
|
73
|
+
body = JSON.stringify(input ?? {});
|
|
74
|
+
}
|
|
75
|
+
const response = await fetchImpl(url, {
|
|
76
|
+
method,
|
|
77
|
+
headers,
|
|
78
|
+
credentials: options.credentials ?? "same-origin",
|
|
79
|
+
...callOptions.signal ? { signal: callOptions.signal } : {},
|
|
80
|
+
...body !== void 0 ? { body } : {}
|
|
81
|
+
});
|
|
82
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
83
|
+
const isJson = contentType.includes("application/json");
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
let errorPayload = null;
|
|
86
|
+
try {
|
|
87
|
+
errorPayload = isJson ? await response.json() : await response.text();
|
|
88
|
+
} catch {
|
|
89
|
+
errorPayload = null;
|
|
90
|
+
}
|
|
91
|
+
const record = errorPayload && typeof errorPayload === "object" ? errorPayload : null;
|
|
92
|
+
const message = typeof record?.["error"] === "string" ? record["error"] : `HTTP ${response.status}`;
|
|
93
|
+
const errorCode = typeof record?.["errorCode"] === "string" ? record["errorCode"] : "action_failed";
|
|
94
|
+
const committed = record?.["committed"] === true;
|
|
95
|
+
const details = record?.["details"] && typeof record["details"] === "object" && !Array.isArray(record["details"]) ? record["details"] : void 0;
|
|
96
|
+
throw new ActionClientError({
|
|
97
|
+
actionName: name,
|
|
98
|
+
message,
|
|
99
|
+
statusCode: response.status,
|
|
100
|
+
errorCode,
|
|
101
|
+
committed,
|
|
102
|
+
...details ? { details } : {},
|
|
103
|
+
...response.status < 500 && typeof record?.["error"] === "string" ? { userMessage: record["error"] } : {}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (response.status === 204) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
const payload = isJson ? await response.json() : await response.text();
|
|
110
|
+
return payload;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/react.ts
|
|
116
|
+
function createActionHooks(options = {}) {
|
|
117
|
+
const client = createActionClient(options);
|
|
118
|
+
function actionQueryOptions2(name, input, hookOptions = {}) {
|
|
119
|
+
const { queryKeyScope, method = "GET", headers, ...rest } = hookOptions;
|
|
120
|
+
const key = client.queryKey(name, input, queryKeyScope);
|
|
121
|
+
return queryOptions({
|
|
122
|
+
queryKey: key,
|
|
123
|
+
queryFn: ({ signal }) => client.call(name, input, {
|
|
124
|
+
method,
|
|
125
|
+
signal,
|
|
126
|
+
...headers ? { headers } : {}
|
|
127
|
+
}),
|
|
128
|
+
...rest
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function useActionQuery2(name, input, hookOptions = {}) {
|
|
132
|
+
return useQuery(actionQueryOptions2(name, input, hookOptions));
|
|
133
|
+
}
|
|
134
|
+
function useActionMutation2(name, hookOptions = {}) {
|
|
135
|
+
const queryClient = useQueryClient();
|
|
136
|
+
const {
|
|
137
|
+
invalidate,
|
|
138
|
+
method = "POST",
|
|
139
|
+
headers,
|
|
140
|
+
approvalToken,
|
|
141
|
+
onSuccess,
|
|
142
|
+
...rest
|
|
143
|
+
} = hookOptions;
|
|
144
|
+
return useMutation({
|
|
145
|
+
mutationFn: (input) => client.call(name, input, {
|
|
146
|
+
method,
|
|
147
|
+
...headers ? { headers } : {},
|
|
148
|
+
...approvalToken !== void 0 ? { approvalToken } : {}
|
|
149
|
+
}),
|
|
150
|
+
onSuccess: async (data, variables, onMutateResult, context) => {
|
|
151
|
+
if (invalidate !== false) {
|
|
152
|
+
if (Array.isArray(invalidate) && invalidate.length > 0) {
|
|
153
|
+
await Promise.all(
|
|
154
|
+
invalidate.map(
|
|
155
|
+
(targetName) => queryClient.invalidateQueries({
|
|
156
|
+
queryKey: client.scope ? ["agent-native-action", client.scope, targetName] : ["agent-native-action", targetName]
|
|
157
|
+
})
|
|
158
|
+
)
|
|
159
|
+
);
|
|
160
|
+
} else {
|
|
161
|
+
await queryClient.invalidateQueries({
|
|
162
|
+
queryKey: client.scope ? ["agent-native-action", client.scope] : ["agent-native-action"]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
await onSuccess?.(data, variables, onMutateResult, context);
|
|
167
|
+
},
|
|
168
|
+
...rest
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
client,
|
|
173
|
+
callAction: client.call,
|
|
174
|
+
actionQueryOptions: actionQueryOptions2,
|
|
175
|
+
useActionQuery: useActionQuery2,
|
|
176
|
+
useActionMutation: useActionMutation2,
|
|
177
|
+
actionErrorMessage
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
var defaultReactHooks = createActionHooks();
|
|
181
|
+
var callAction = defaultReactHooks.callAction;
|
|
182
|
+
var actionQueryOptions = defaultReactHooks.actionQueryOptions;
|
|
183
|
+
var useActionQuery = defaultReactHooks.useActionQuery;
|
|
184
|
+
var useActionMutation = defaultReactHooks.useActionMutation;
|
|
185
|
+
export {
|
|
186
|
+
ActionClientError,
|
|
187
|
+
actionErrorMessage,
|
|
188
|
+
actionQueryOptions,
|
|
189
|
+
callAction,
|
|
190
|
+
createActionHooks,
|
|
191
|
+
useActionMutation,
|
|
192
|
+
useActionQuery
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts","../src/client.ts"],"sourcesContent":["import {\n queryOptions,\n useMutation,\n useQuery,\n useQueryClient,\n type UseMutationOptions,\n type UseMutationResult,\n type UseQueryOptions,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\n\nimport {\n ActionClientError,\n actionErrorMessage,\n createActionClient,\n type ActionCallOptions,\n type ActionClient,\n type ActionClientOptions,\n type ActionInputOf,\n type ActionNameOf,\n type ActionOutputOf,\n} from \"./client.js\";\n\nexport { ActionClientError, actionErrorMessage };\nexport type { ActionCallOptions, ActionClient, ActionClientOptions };\n\nexport interface ActionQueryHookOptions<TData> extends Omit<\n UseQueryOptions<TData, ActionClientError, TData, readonly unknown[]>,\n \"queryKey\" | \"queryFn\"\n> {\n /** Partition the local query cache by viewer/tenant without sending it to the server. */\n queryKeyScope?: string;\n /** Override HTTP method (defaults to GET for queries). */\n method?: \"GET\" | \"POST\";\n headers?: HeadersInit;\n}\n\nexport interface ActionMutationHookOptions<\n TData,\n TInput,\n TNames extends string,\n> extends Omit<\n UseMutationOptions<TData, ActionClientError, TInput>,\n \"mutationFn\"\n> {\n /**\n * Targeted list of query action names to invalidate on success.\n * Defaults to invalidating all active `agent-native-action` queries in this client scope.\n */\n invalidate?: readonly TNames[] | false;\n method?: \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n headers?: HeadersInit;\n approvalToken?: string;\n}\n\nexport function createActionHooks<TRegistry = unknown>(\n options: ActionClientOptions = {},\n) {\n const client = createActionClient<TRegistry>(options);\n\n function actionQueryOptions<TName extends ActionNameOf<TRegistry>>(\n name: TName,\n input?: ActionInputOf<TRegistry, TName>,\n hookOptions: ActionQueryHookOptions<ActionOutputOf<TRegistry, TName>> = {},\n ) {\n const { queryKeyScope, method = \"GET\", headers, ...rest } = hookOptions;\n const key = client.queryKey(name, input, queryKeyScope);\n return queryOptions<\n ActionOutputOf<TRegistry, TName>,\n ActionClientError,\n ActionOutputOf<TRegistry, TName>,\n readonly unknown[]\n >({\n queryKey: key,\n queryFn: ({ signal }) =>\n client.call(name, input, {\n method,\n signal,\n ...(headers ? { headers } : {}),\n }),\n ...rest,\n });\n }\n\n function useActionQuery<TName extends ActionNameOf<TRegistry>>(\n name: TName,\n input?: ActionInputOf<TRegistry, TName>,\n hookOptions: ActionQueryHookOptions<ActionOutputOf<TRegistry, TName>> = {},\n ): UseQueryResult<ActionOutputOf<TRegistry, TName>, ActionClientError> {\n return useQuery(actionQueryOptions(name, input, hookOptions));\n }\n\n function useActionMutation<TName extends ActionNameOf<TRegistry>>(\n name: TName,\n hookOptions: ActionMutationHookOptions<\n ActionOutputOf<TRegistry, TName>,\n ActionInputOf<TRegistry, TName>,\n ActionNameOf<TRegistry>\n > = {},\n ): UseMutationResult<\n ActionOutputOf<TRegistry, TName>,\n ActionClientError,\n ActionInputOf<TRegistry, TName>\n > {\n const queryClient = useQueryClient();\n const {\n invalidate,\n method = \"POST\",\n headers,\n approvalToken,\n onSuccess,\n ...rest\n } = hookOptions;\n\n return useMutation<\n ActionOutputOf<TRegistry, TName>,\n ActionClientError,\n ActionInputOf<TRegistry, TName>\n >({\n mutationFn: (input) =>\n client.call(name, input, {\n method,\n ...(headers ? { headers } : {}),\n ...(approvalToken !== undefined ? { approvalToken } : {}),\n }),\n onSuccess: async (data, variables, onMutateResult, context) => {\n if (invalidate !== false) {\n if (Array.isArray(invalidate) && invalidate.length > 0) {\n await Promise.all(\n invalidate.map((targetName) =>\n queryClient.invalidateQueries({\n queryKey: client.scope\n ? [\"agent-native-action\", client.scope, targetName]\n : [\"agent-native-action\", targetName],\n }),\n ),\n );\n } else {\n await queryClient.invalidateQueries({\n queryKey: client.scope\n ? [\"agent-native-action\", client.scope]\n : [\"agent-native-action\"],\n });\n }\n }\n await onSuccess?.(data, variables, onMutateResult, context);\n },\n ...rest,\n });\n }\n\n return {\n client,\n callAction: client.call,\n actionQueryOptions,\n useActionQuery,\n useActionMutation,\n actionErrorMessage,\n };\n}\n\nconst defaultReactHooks = createActionHooks();\n\nexport const callAction = defaultReactHooks.callAction;\nexport const actionQueryOptions = defaultReactHooks.actionQueryOptions;\nexport const useActionQuery = defaultReactHooks.useActionQuery;\nexport const useActionMutation = defaultReactHooks.useActionMutation;\n","import type { ActionsRegistry } from \"./registry.js\";\nimport type {\n ActionHttpMethod,\n ActionMap,\n InferActionInputFromDef,\n InferActionReturn,\n} from \"./types.js\";\n\n/**\n * Optional module augmentation hook populated by `.generated/action-types.d.ts`.\n * Prefer passing `createActionClient<AppActions>()` / `createActionHooks<AppActions>()`\n * when a single TypeScript program contains multiple independent action registries.\n */\nexport interface ActionTypeRegistry {\n actions: Record<string, { input: unknown; output: unknown }>;\n}\n\nexport type ActionNameOf<TRegistry> =\n TRegistry extends ActionsRegistry<never, infer TActions>\n ? Extract<keyof TActions, string>\n : keyof ActionTypeRegistry[\"actions\"] extends never\n ? string\n : Extract<keyof ActionTypeRegistry[\"actions\"], string>;\n\nexport type ActionInputOf<TRegistry, TName extends string> =\n TRegistry extends ActionsRegistry<never, infer TActions>\n ? TName extends keyof TActions\n ? InferActionInputFromDef<TActions[TName]>\n : Record<string, unknown>\n : TName extends keyof ActionTypeRegistry[\"actions\"]\n ? ActionTypeRegistry[\"actions\"][TName][\"input\"]\n : Record<string, unknown>;\n\nexport type ActionOutputOf<TRegistry, TName extends string> =\n TRegistry extends ActionsRegistry<never, infer TActions>\n ? TName extends keyof TActions\n ? InferActionReturn<TActions[TName]>\n : unknown\n : TName extends keyof ActionTypeRegistry[\"actions\"]\n ? ActionTypeRegistry[\"actions\"][TName][\"output\"]\n : unknown;\n\nexport class ActionClientError extends Error {\n readonly actionName: string;\n readonly statusCode: number;\n readonly errorCode: string;\n readonly committed: boolean;\n readonly details: Record<string, unknown> | undefined;\n readonly userMessage: string | undefined;\n\n constructor(params: {\n actionName: string;\n message: string;\n statusCode: number;\n errorCode?: string;\n committed?: boolean;\n details?: Record<string, unknown>;\n userMessage?: string;\n }) {\n super(`Action ${params.actionName} failed: ${params.message}`);\n this.name = \"ActionClientError\";\n this.actionName = params.actionName;\n this.statusCode = params.statusCode;\n this.errorCode = params.errorCode ?? \"action_failed\";\n this.committed = params.committed ?? false;\n this.details = params.details;\n this.userMessage = params.userMessage;\n }\n}\n\n/**\n * Extract the clean, caller-facing error message from an `ActionClientError`\n * without the `Action <name> failed:` console prefix. Returns `undefined` for\n * network drops or unexpected 5xx failures so the UI renders its own fallback copy.\n */\nexport function actionErrorMessage(error: unknown): string | undefined {\n if (error instanceof ActionClientError) {\n if (error.statusCode >= 500) return undefined;\n return error.userMessage;\n }\n return undefined;\n}\n\nexport interface ActionClientOptions {\n /** Base URL for HTTP action calls. Defaults to `\"/api/agent-native/actions\"`. */\n baseUrl?: string;\n /** Custom Fetch implementation (e.g. SvelteKit `event.fetch`, Nuxt `useRequestFetch()`). */\n fetch?: typeof globalThis.fetch;\n /** Static or async headers attached to every request (e.g. Bearer token). */\n headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);\n /** Fetch credentials mode. Defaults to `\"same-origin\"`. */\n credentials?: RequestCredentials;\n /** Optional map of action names to HTTP methods (defaults to POST; GET used when specified). */\n methods?: Record<string, ActionHttpMethod>;\n /** Optional namespace scoping generated query keys (e.g. tenant or signed-in user id). */\n scope?: string;\n}\n\nexport interface ActionCallOptions {\n method?: ActionHttpMethod;\n signal?: AbortSignal;\n headers?: HeadersInit;\n approvalToken?: string;\n}\n\nexport function buildActionQueryKey(\n actionName: string,\n input?: unknown,\n scope?: string,\n): readonly unknown[] {\n return scope\n ? ([\"agent-native-action\", scope, actionName, input ?? {}] as const)\n : ([\"agent-native-action\", actionName, input ?? {}] as const);\n}\n\nexport interface ActionClient<TRegistry = unknown> {\n readonly baseUrl: string;\n readonly scope: string | undefined;\n call: <TName extends ActionNameOf<TRegistry>>(\n name: TName,\n input?: ActionInputOf<TRegistry, TName>,\n options?: ActionCallOptions,\n ) => Promise<ActionOutputOf<TRegistry, TName>>;\n queryKey: <TName extends ActionNameOf<TRegistry>>(\n name: TName,\n input?: ActionInputOf<TRegistry, TName>,\n extraScope?: string,\n ) => readonly unknown[];\n}\n\nexport function createActionClient<\n TRegistry = ActionsRegistry<never, ActionMap<never>>,\n>(options: ActionClientOptions = {}): ActionClient<TRegistry> {\n const baseUrl = (options.baseUrl ?? \"/api/agent-native/actions\").replace(\n /\\/+$/,\n \"\",\n );\n const fetchImpl = options.fetch ?? globalThis.fetch;\n\n return {\n baseUrl,\n scope: options.scope,\n queryKey: (name, input, extraScope) =>\n buildActionQueryKey(name, input, extraScope ?? options.scope),\n call: async (name, input, callOptions = {}) => {\n const method: ActionHttpMethod =\n callOptions.method ?? options.methods?.[name] ?? \"POST\";\n\n const resolvedBaseHeaders =\n typeof options.headers === \"function\"\n ? await options.headers()\n : options.headers;\n\n const headers = new Headers(resolvedBaseHeaders);\n if (callOptions.headers) {\n new Headers(callOptions.headers).forEach((value, key) => {\n headers.set(key, value);\n });\n }\n if (callOptions.approvalToken) {\n headers.set(\"X-Action-Approval\", callOptions.approvalToken);\n }\n\n let url = `${baseUrl}/${encodeURIComponent(name)}`;\n let body: string | undefined;\n\n if (method === \"GET\") {\n if (input !== undefined && Object.keys(input as object).length > 0) {\n const qs = new URLSearchParams({\n input: JSON.stringify(input),\n });\n url = `${url}?${qs.toString()}`;\n }\n } else {\n headers.set(\"Content-Type\", \"application/json\");\n body = JSON.stringify(input ?? {});\n }\n\n const response = await fetchImpl(url, {\n method,\n headers,\n credentials: options.credentials ?? \"same-origin\",\n ...(callOptions.signal ? { signal: callOptions.signal } : {}),\n ...(body !== undefined ? { body } : {}),\n });\n\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n const isJson = contentType.includes(\"application/json\");\n\n if (!response.ok) {\n let errorPayload: unknown = null;\n try {\n errorPayload = isJson ? await response.json() : await response.text();\n } catch {\n // coercion-ok: error response body may be empty or malformed; HTTP status error is always thrown below\n errorPayload = null;\n }\n const record =\n errorPayload && typeof errorPayload === \"object\"\n ? (errorPayload as Record<string, unknown>)\n : null;\n const message =\n typeof record?.[\"error\"] === \"string\"\n ? record[\"error\"]\n : `HTTP ${response.status}`;\n const errorCode =\n typeof record?.[\"errorCode\"] === \"string\"\n ? record[\"errorCode\"]\n : \"action_failed\";\n const committed = record?.[\"committed\"] === true;\n const details =\n record?.[\"details\"] &&\n typeof record[\"details\"] === \"object\" &&\n !Array.isArray(record[\"details\"])\n ? (record[\"details\"] as Record<string, unknown>)\n : undefined;\n\n throw new ActionClientError({\n actionName: name,\n message,\n statusCode: response.status,\n errorCode,\n committed,\n ...(details ? { details } : {}),\n ...(response.status < 500 && typeof record?.[\"error\"] === \"string\"\n ? { userMessage: record[\"error\"] }\n : {}),\n });\n }\n\n if (response.status === 204) {\n return undefined as ActionOutputOf<TRegistry, typeof name>;\n }\n const payload: unknown = isJson\n ? await response.json()\n : await response.text();\n return payload as ActionOutputOf<TRegistry, typeof name>;\n },\n };\n}\n"],"mappings":";;;AAAA;AAAA,EACE;AAAA,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M,iBAAiB,kBAAkB;AACzC,IAAM,oBAAoB,kBAAkB;","names":["actionQueryOptions","useActionQuery","useActionMutation"]}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
|
|
3
|
+
type ActionCaller = "http" | "mcp" | "cli" | "server" | "agent";
|
|
4
|
+
type ActionHttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
5
|
+
type ActionHttpConfig = false | {
|
|
6
|
+
method?: ActionHttpMethod;
|
|
7
|
+
path?: string;
|
|
8
|
+
};
|
|
9
|
+
type JsonSchemaObject = Record<string, unknown>;
|
|
10
|
+
interface ActionContextInput {
|
|
11
|
+
/** Which surface invoked this action. */
|
|
12
|
+
caller: ActionCaller;
|
|
13
|
+
/** Alias for `caller` for ergonomic destructuring. */
|
|
14
|
+
source: ActionCaller;
|
|
15
|
+
/** Name of the action being invoked, if resolved. */
|
|
16
|
+
actionName?: string;
|
|
17
|
+
/** Incoming Web Standard Request when called via HTTP or Streamable HTTP MCP. */
|
|
18
|
+
request?: Request;
|
|
19
|
+
/** Canonical Headers view available across HTTP, MCP, RSC, and server adapters. */
|
|
20
|
+
headers: Headers;
|
|
21
|
+
/** AbortSignal tied to the incoming request or caller cancellation. */
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
/** Runtime environment variables (defaults to process.env in Node). */
|
|
24
|
+
env: Record<string, string | undefined>;
|
|
25
|
+
/** Optional host-specific event, bindings (e.g. Cloudflare Workers env), or framework context. */
|
|
26
|
+
platform?: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface DefaultActionContext {
|
|
29
|
+
caller: ActionCaller;
|
|
30
|
+
source: ActionCaller;
|
|
31
|
+
headers: Headers;
|
|
32
|
+
request?: Request;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
actionName?: string;
|
|
35
|
+
}
|
|
36
|
+
interface ActionApprovalRequest<TInput = unknown, TCtx = unknown> {
|
|
37
|
+
actionName: string;
|
|
38
|
+
input: TInput;
|
|
39
|
+
ctx: TCtx;
|
|
40
|
+
caller: ActionCaller;
|
|
41
|
+
approvalToken?: string;
|
|
42
|
+
}
|
|
43
|
+
type ActionApprovalVerifier<TCtx = unknown> = (request: ActionApprovalRequest<unknown, TCtx>) => boolean | Promise<boolean>;
|
|
44
|
+
interface ActionDefinition<TSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined, TOutputSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined, TReturn = unknown, TCtx = DefaultActionContext> {
|
|
45
|
+
/** Concise one-line description shown to agents, MCP clients, and CLI `--help`. */
|
|
46
|
+
description: string;
|
|
47
|
+
/** Optional human-readable title for MCP / UI listings. */
|
|
48
|
+
title?: string;
|
|
49
|
+
/** Standard Schema validator (Zod, Valibot, ArkType, etc.) for action inputs. */
|
|
50
|
+
schema?: TSchema;
|
|
51
|
+
/** Optional Standard Schema validator for action outputs. */
|
|
52
|
+
outputSchema?: TOutputSchema;
|
|
53
|
+
/** Explicit JSON Schema override for MCP/AI SDK tools when a Standard Schema lacks JSON Schema conversion. */
|
|
54
|
+
toolSchema?: JsonSchemaObject;
|
|
55
|
+
/** HTTP exposure and verb. Omit for POST; set `{ method: "GET" }` for queries; `false` disables HTTP. */
|
|
56
|
+
http?: ActionHttpConfig;
|
|
57
|
+
/** Marks the action as read-only (maps to MCP `readOnlyHint` and query eligibility). */
|
|
58
|
+
readOnly?: boolean;
|
|
59
|
+
/** Marks the action as destructive (maps to MCP `destructiveHint`). */
|
|
60
|
+
destructive?: boolean;
|
|
61
|
+
/** Marks the action as genuinely idempotent across repeated identical calls (maps to MCP `idempotentHint`). */
|
|
62
|
+
retrySafe?: boolean;
|
|
63
|
+
/** Set `false` to exclude from MCP listings and calls (still callable from UI/HTTP/CLI). */
|
|
64
|
+
mcpTool?: boolean;
|
|
65
|
+
/** Set `false` to exclude from AI SDK tool exports and MCP (UI/HTTP/CLI only). */
|
|
66
|
+
agentTool?: boolean;
|
|
67
|
+
/** Publish `outputSchema` to MCP clients when supported (defaults to true when `outputSchema` is provided). */
|
|
68
|
+
mcpOutputSchema?: boolean;
|
|
69
|
+
/** Gate who may call this action. Runs after input validation and before `needsApproval` / `run`. */
|
|
70
|
+
authorize?(input: InferActionOutput<TSchema>, ctx: TCtx): boolean | Promise<boolean>;
|
|
71
|
+
/** Require an approved execution grant before `run` executes. */
|
|
72
|
+
needsApproval?: boolean | {
|
|
73
|
+
(input: InferActionOutput<TSchema>, ctx: TCtx): boolean | Promise<boolean>;
|
|
74
|
+
};
|
|
75
|
+
/** Core implementation receiving validated input and resolved context. */
|
|
76
|
+
run(input: InferActionOutput<TSchema>, ctx: TCtx): Promise<TReturn> | TReturn;
|
|
77
|
+
}
|
|
78
|
+
type InferActionInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : Record<string, never>;
|
|
79
|
+
type InferActionOutput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : Record<string, never>;
|
|
80
|
+
type InferActionReturn<TAction> = TAction extends {
|
|
81
|
+
outputSchema?: infer TOutSchema;
|
|
82
|
+
run(input: never, ctx: never): infer TReturn;
|
|
83
|
+
} ? TOutSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TOutSchema> : Awaited<TReturn> : unknown;
|
|
84
|
+
type InferActionInputFromDef<TAction> = TAction extends {
|
|
85
|
+
schema?: infer TSchema;
|
|
86
|
+
} ? TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : Record<string, never> : Record<string, unknown>;
|
|
87
|
+
interface DefinedAction<TSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined, TOutputSchema extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined, TReturn = unknown, TCtx = DefaultActionContext> extends ActionDefinition<TSchema, TOutputSchema, TReturn, TCtx> {
|
|
88
|
+
readonly __agentNativeAction: true;
|
|
89
|
+
}
|
|
90
|
+
interface ActionMapEntry<TCtx = DefaultActionContext> {
|
|
91
|
+
description: string;
|
|
92
|
+
title?: string | undefined;
|
|
93
|
+
schema?: StandardSchemaV1 | undefined;
|
|
94
|
+
outputSchema?: StandardSchemaV1 | undefined;
|
|
95
|
+
toolSchema?: JsonSchemaObject | undefined;
|
|
96
|
+
http?: ActionHttpConfig | undefined;
|
|
97
|
+
readOnly?: boolean | undefined;
|
|
98
|
+
destructive?: boolean | undefined;
|
|
99
|
+
retrySafe?: boolean | undefined;
|
|
100
|
+
mcpTool?: boolean | undefined;
|
|
101
|
+
agentTool?: boolean | undefined;
|
|
102
|
+
mcpOutputSchema?: boolean | undefined;
|
|
103
|
+
authorize?(input: never, ctx: TCtx): boolean | Promise<boolean>;
|
|
104
|
+
needsApproval?: boolean | ((input: never, ctx: TCtx) => boolean | Promise<boolean>) | undefined;
|
|
105
|
+
run(input: never, ctx: TCtx): Promise<unknown> | unknown;
|
|
106
|
+
}
|
|
107
|
+
type AnyDefinedAction<TCtx = never> = ActionMapEntry<TCtx>;
|
|
108
|
+
type ActionMap<TCtx = DefaultActionContext> = Record<string, ActionMapEntry<TCtx>>;
|
|
109
|
+
interface ActionMiddlewareParams<TCtx = unknown> {
|
|
110
|
+
name: string;
|
|
111
|
+
input: unknown;
|
|
112
|
+
ctx: TCtx;
|
|
113
|
+
caller: ActionCaller;
|
|
114
|
+
next: () => Promise<unknown>;
|
|
115
|
+
}
|
|
116
|
+
type ActionMiddleware<TCtx = unknown> = (params: ActionMiddlewareParams<TCtx>) => Promise<unknown>;
|
|
117
|
+
interface ActionAfterMutateInfo<TCtx = unknown> {
|
|
118
|
+
name: string;
|
|
119
|
+
input: unknown;
|
|
120
|
+
result: unknown;
|
|
121
|
+
ctx: TCtx;
|
|
122
|
+
caller: ActionCaller;
|
|
123
|
+
}
|
|
124
|
+
interface ActionErrorInfo<TCtx = unknown> {
|
|
125
|
+
name: string;
|
|
126
|
+
caller: ActionCaller;
|
|
127
|
+
ctx?: TCtx;
|
|
128
|
+
committed: boolean;
|
|
129
|
+
}
|
|
130
|
+
interface ActionMetadataSummary {
|
|
131
|
+
name: string;
|
|
132
|
+
title?: string;
|
|
133
|
+
description: string;
|
|
134
|
+
httpMethod: ActionHttpMethod | null;
|
|
135
|
+
httpPath: string | null;
|
|
136
|
+
readOnly: boolean;
|
|
137
|
+
destructive: boolean;
|
|
138
|
+
retrySafe: boolean;
|
|
139
|
+
mcpExposed: boolean;
|
|
140
|
+
agentExposed: boolean;
|
|
141
|
+
hasInputSchema: boolean;
|
|
142
|
+
hasOutputSchema: boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface ActionHttpHandlerOptions {
|
|
146
|
+
/** Mount prefix stripped before resolving action names. Defaults to `"/api/agent-native/actions"`. */
|
|
147
|
+
basePath?: string;
|
|
148
|
+
/** Enforce same-origin check on cookie-authenticated mutations. Defaults to `true`. */
|
|
149
|
+
csrfProtection?: boolean;
|
|
150
|
+
/** Optional CORS configuration for cross-origin browser clients. */
|
|
151
|
+
cors?: boolean | {
|
|
152
|
+
origin: string | readonly string[] | ((origin: string) => boolean);
|
|
153
|
+
credentials?: boolean;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
interface McpHandlerOptions {
|
|
157
|
+
/** MCP server name announced during initialize. */
|
|
158
|
+
name?: string;
|
|
159
|
+
/** MCP server version announced during initialize. */
|
|
160
|
+
version?: string;
|
|
161
|
+
/** Server instructions shown to MCP hosts. */
|
|
162
|
+
instructions?: string;
|
|
163
|
+
/** Explicit allowlist of action names exposed over MCP. */
|
|
164
|
+
include?: readonly string[];
|
|
165
|
+
/** Action names excluded from MCP. */
|
|
166
|
+
exclude?: readonly string[];
|
|
167
|
+
/** Optional gate run before handling an incoming HTTP MCP request. Return false to reject with 401. */
|
|
168
|
+
authenticate?: (request: Request) => boolean | Promise<boolean>;
|
|
169
|
+
}
|
|
170
|
+
interface CombinedHandlerOptions {
|
|
171
|
+
/** Base path for the combined catch-all handler. Defaults to `"/api/agent-native"`. */
|
|
172
|
+
basePath?: string;
|
|
173
|
+
/** Enable or configure Streamable HTTP MCP at `<basePath>/mcp`. Defaults to `true`. */
|
|
174
|
+
mcp?: boolean | McpHandlerOptions;
|
|
175
|
+
/** HTTP RPC handler options (CORS, CSRF). */
|
|
176
|
+
http?: Omit<ActionHttpHandlerOptions, "basePath">;
|
|
177
|
+
}
|
|
178
|
+
interface CreateActionsOptions<TActions extends ActionMap<TCtx>, TCtx = DefaultActionContext> {
|
|
179
|
+
actions: TActions & ActionMap<TCtx>;
|
|
180
|
+
/** Resolve the typed context passed as the 2nd argument to `authorize`, `needsApproval`, and `run`. */
|
|
181
|
+
createContext?: (input: ActionContextInput) => TCtx | Promise<TCtx>;
|
|
182
|
+
/** Middleware wrapping every action invocation across HTTP, MCP, CLI, server, and AI SDKs. */
|
|
183
|
+
middleware?: readonly ActionMiddleware<NoInfer<TCtx>>[];
|
|
184
|
+
/** Host verifier for `needsApproval` grants (e.g. signed token or DB approval lookup). */
|
|
185
|
+
verifyApproval?: ActionApprovalVerifier<NoInfer<TCtx>>;
|
|
186
|
+
/** Runs after a non-read-only action's `run()` and `outputSchema` succeed. */
|
|
187
|
+
onAfterMutate?: (info: ActionAfterMutateInfo<NoInfer<TCtx>>) => void | Promise<void>;
|
|
188
|
+
/** Structured error observer for logging / Sentry / OpenTelemetry. */
|
|
189
|
+
onError?: (error: unknown, info: ActionErrorInfo<NoInfer<TCtx>>) => void;
|
|
190
|
+
/** Default options for `actions.handler` and `actions.mcpHandler`. */
|
|
191
|
+
http?: ActionHttpHandlerOptions;
|
|
192
|
+
mcp?: McpHandlerOptions;
|
|
193
|
+
}
|
|
194
|
+
interface ActionsRegistry<TCtx, TActions extends ActionMap<TCtx>> {
|
|
195
|
+
readonly actions: TActions;
|
|
196
|
+
readonly __contextType?: TCtx;
|
|
197
|
+
/** List all registered action names. */
|
|
198
|
+
list: () => Array<Extract<keyof TActions, string>>;
|
|
199
|
+
/** Return static metadata for every registered action (safe for diagnostics / client method maps). */
|
|
200
|
+
describe: () => ActionMetadataSummary[];
|
|
201
|
+
/** Build a `{ [actionName]: "GET" | "POST" | ... }` map for typed clients. */
|
|
202
|
+
httpMethodMap: () => Record<string, ActionHttpMethod>;
|
|
203
|
+
/** Resolve an incoming relative HTTP path to an action name and method. */
|
|
204
|
+
resolveHttpAction: (relativePath: string) => {
|
|
205
|
+
name: Extract<keyof TActions, string>;
|
|
206
|
+
method: ActionHttpMethod;
|
|
207
|
+
} | null;
|
|
208
|
+
/**
|
|
209
|
+
* Call a registered action directly with full schema validation, `authorize`,
|
|
210
|
+
* `needsApproval`, middleware, and `outputSchema` enforcement.
|
|
211
|
+
*/
|
|
212
|
+
call: <TName extends Extract<keyof TActions, string>>(name: TName, input: InferActionInputFromDef<TActions[TName]>, options?: {
|
|
213
|
+
ctx?: TCtx;
|
|
214
|
+
caller?: ActionCaller;
|
|
215
|
+
request?: Request;
|
|
216
|
+
headers?: HeadersInit;
|
|
217
|
+
signal?: AbortSignal;
|
|
218
|
+
platform?: unknown;
|
|
219
|
+
approvalToken?: string;
|
|
220
|
+
approved?: boolean;
|
|
221
|
+
}) => Promise<InferActionReturn<TActions[TName]>>;
|
|
222
|
+
/** Internal / adapter entry point using an incoming Web Standard Request to build context. */
|
|
223
|
+
invokeFromRequest: (name: string, rawInput: unknown, options: {
|
|
224
|
+
caller: ActionCaller;
|
|
225
|
+
request: Request;
|
|
226
|
+
platform?: unknown;
|
|
227
|
+
approvalToken?: string;
|
|
228
|
+
}) => Promise<unknown>;
|
|
229
|
+
/** Internal / CLI / stdio MCP entry point using local env to build context. */
|
|
230
|
+
invokeFromCliOrStdio: (name: string, rawInput: unknown, options: {
|
|
231
|
+
caller: ActionCaller;
|
|
232
|
+
approved?: boolean;
|
|
233
|
+
approvalToken?: string;
|
|
234
|
+
}) => Promise<unknown>;
|
|
235
|
+
/** Internal / AI SDK entry point with an explicit pre-resolved context. */
|
|
236
|
+
invokeWithContext: (name: string, rawInput: unknown, ctx: TCtx, options: {
|
|
237
|
+
caller: ActionCaller;
|
|
238
|
+
approvalToken?: string;
|
|
239
|
+
approved?: boolean;
|
|
240
|
+
}) => Promise<unknown>;
|
|
241
|
+
/** Web Fetch handler for HTTP action RPC only (`/actions/:name`). */
|
|
242
|
+
fetchHandler: (request: Request, override?: {
|
|
243
|
+
actionPath?: string;
|
|
244
|
+
platform?: unknown;
|
|
245
|
+
}) => Promise<Response>;
|
|
246
|
+
/** Web Fetch handler for Streamable HTTP MCP only (`/mcp`). */
|
|
247
|
+
mcpHandler: (request: Request, override?: {
|
|
248
|
+
platform?: unknown;
|
|
249
|
+
}) => Promise<Response>;
|
|
250
|
+
/** Single catch-all Web Fetch handler routing `/actions/*` and `/mcp` under one prefix. */
|
|
251
|
+
handler: (request: Request, override?: {
|
|
252
|
+
pathSegments?: readonly string[];
|
|
253
|
+
platform?: unknown;
|
|
254
|
+
}) => Promise<Response>;
|
|
255
|
+
/** Build a customized catch-all Web Fetch handler (e.g. custom `basePath` or MCP config). */
|
|
256
|
+
createHandler: (options?: CombinedHandlerOptions) => (request: Request, override?: {
|
|
257
|
+
pathSegments?: readonly string[];
|
|
258
|
+
platform?: unknown;
|
|
259
|
+
}) => Promise<Response>;
|
|
260
|
+
}
|
|
261
|
+
declare function createActions<TCtx = DefaultActionContext, TActions extends ActionMap<TCtx> = ActionMap<TCtx>>(options: CreateActionsOptions<TActions, TCtx>): ActionsRegistry<TCtx, TActions>;
|
|
262
|
+
|
|
263
|
+
export { type ActionMapEntry as A, type CombinedHandlerOptions as C, type DefinedAction as D, type InferActionInput as I, type JsonSchemaObject as J, type McpHandlerOptions as M, type ActionCaller as a, type ActionApprovalVerifier as b, type ActionMiddleware as c, type ActionAfterMutateInfo as d, type ActionErrorInfo as e, type ActionDefinition as f, type DefaultActionContext as g, type ActionHttpMethod as h, type ActionMap as i, type ActionsRegistry as j, type ActionHttpHandlerOptions as k, type ActionApprovalRequest as l, type ActionContextInput as m, type ActionHttpConfig as n, type ActionMetadataSummary as o, type ActionMiddlewareParams as p, type AnyDefinedAction as q, type CreateActionsOptions as r, type InferActionInputFromDef as s, type InferActionOutput as t, type InferActionReturn as u, createActions as v };
|
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Resource } from 'solid-js';
|
|
2
|
+
import { A as ActionClientError, a as ActionCallOptions, b as ActionClientOptions, c as ActionClient, d as ActionNameOf, e as ActionInputOf, f as ActionOutputOf, g as actionErrorMessage } from './client-C87WZhlZ.js';
|
|
3
|
+
import '@standard-schema/spec';
|
|
4
|
+
|
|
5
|
+
interface SolidMutationResult<TData, TInput> {
|
|
6
|
+
readonly pending: boolean;
|
|
7
|
+
readonly error: ActionClientError | null;
|
|
8
|
+
readonly data: TData | undefined;
|
|
9
|
+
mutate: (input: TInput) => Promise<TData | undefined>;
|
|
10
|
+
mutateAsync: (input: TInput) => Promise<TData>;
|
|
11
|
+
reset: () => void;
|
|
12
|
+
}
|
|
13
|
+
interface SolidMutationOptions<TData, TInput, TNames extends string> {
|
|
14
|
+
invalidate?: readonly TNames[] | false;
|
|
15
|
+
method?: "POST" | "PUT" | "PATCH" | "DELETE";
|
|
16
|
+
headers?: HeadersInit;
|
|
17
|
+
approvalToken?: string;
|
|
18
|
+
onSuccess?: (data: TData, input: TInput) => void | Promise<void>;
|
|
19
|
+
onError?: (error: ActionClientError, input: TInput) => void;
|
|
20
|
+
}
|
|
21
|
+
declare function createSolidActionHooks<TRegistry = unknown>(options?: ActionClientOptions): {
|
|
22
|
+
client: ActionClient<TRegistry>;
|
|
23
|
+
callAction: <TName extends ActionNameOf<TRegistry>>(name: TName, input?: ActionInputOf<TRegistry, TName> | undefined, options?: ActionCallOptions) => Promise<ActionOutputOf<TRegistry, TName>>;
|
|
24
|
+
createActionQuery: <TName extends ActionNameOf<TRegistry>>(name: TName, input?: ActionInputOf<TRegistry, TName> | (() => ActionInputOf<TRegistry, TName> | false | null | undefined), queryOpts?: {
|
|
25
|
+
method?: "GET" | "POST";
|
|
26
|
+
headers?: HeadersInit;
|
|
27
|
+
}) => Resource<ActionOutputOf<TRegistry, TName> | undefined>;
|
|
28
|
+
createActionMutation: <TName extends ActionNameOf<TRegistry>>(name: TName, mutationOpts?: SolidMutationOptions<ActionOutputOf<TRegistry, TName>, ActionInputOf<TRegistry, TName>, ActionNameOf<TRegistry>>) => SolidMutationResult<ActionOutputOf<TRegistry, TName>, ActionInputOf<TRegistry, TName>>;
|
|
29
|
+
invalidateActions: (targets?: readonly string[] | false) => void;
|
|
30
|
+
actionErrorMessage: typeof actionErrorMessage;
|
|
31
|
+
};
|
|
32
|
+
declare const callAction: <TName extends string>(name: TName, input?: (TName extends string ? unknown : Record<string, unknown>) | undefined, options?: ActionCallOptions) => Promise<TName extends string ? unknown : unknown>;
|
|
33
|
+
declare const createActionQuery: <TName extends string>(name: TName, input?: (TName extends string ? unknown : Record<string, unknown>) | (() => false | (TName extends string ? unknown : Record<string, unknown>) | null | undefined) | undefined, queryOpts?: {
|
|
34
|
+
method?: "GET" | "POST";
|
|
35
|
+
headers?: HeadersInit;
|
|
36
|
+
}) => Resource<(TName extends string ? unknown : unknown) | undefined>;
|
|
37
|
+
declare const createActionMutation: <TName extends string>(name: TName, mutationOpts?: SolidMutationOptions<TName extends string ? unknown : unknown, TName extends string ? unknown : Record<string, unknown>, string>) => SolidMutationResult<TName extends string ? unknown : unknown, TName extends string ? unknown : Record<string, unknown>>;
|
|
38
|
+
|
|
39
|
+
export { ActionCallOptions, ActionClient, ActionClientError, ActionClientOptions, type SolidMutationOptions, type SolidMutationResult, actionErrorMessage, callAction, createActionMutation, createActionQuery, createSolidActionHooks };
|