@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/contract.js
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
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
|
+
// src/schema.ts
|
|
100
|
+
function isPlainRecord(value) {
|
|
101
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
102
|
+
}
|
|
103
|
+
function formatIssuePath(path) {
|
|
104
|
+
if (!path || path.length === 0) return "";
|
|
105
|
+
return path.map(
|
|
106
|
+
(segment) => typeof segment === "object" && "key" in segment ? String(segment.key) : String(segment)
|
|
107
|
+
).join(".");
|
|
108
|
+
}
|
|
109
|
+
async function validateInputSchema(schema, rawInput, actionName) {
|
|
110
|
+
const result = await schema["~standard"].validate(rawInput);
|
|
111
|
+
if (result.issues) {
|
|
112
|
+
const formatted = result.issues.map((issue) => {
|
|
113
|
+
const pathStr = formatIssuePath(issue.path);
|
|
114
|
+
return pathStr ? `${pathStr}: ${issue.message}` : issue.message;
|
|
115
|
+
});
|
|
116
|
+
throw new ActionError(
|
|
117
|
+
`Invalid input for "${actionName}": ${formatted.join("; ")}`,
|
|
118
|
+
{
|
|
119
|
+
statusCode: 400,
|
|
120
|
+
errorCode: "invalid_input",
|
|
121
|
+
details: {
|
|
122
|
+
issues: result.issues.map((issue) => ({
|
|
123
|
+
path: formatIssuePath(issue.path),
|
|
124
|
+
message: issue.message
|
|
125
|
+
}))
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return result.value;
|
|
131
|
+
}
|
|
132
|
+
async function validateOutputSchema(schema, rawOutput, actionName) {
|
|
133
|
+
const result = await schema["~standard"].validate(rawOutput);
|
|
134
|
+
if (result.issues) {
|
|
135
|
+
const formatted = result.issues.map((issue) => {
|
|
136
|
+
const pathStr = formatIssuePath(issue.path);
|
|
137
|
+
return pathStr ? `${pathStr}: ${issue.message}` : issue.message;
|
|
138
|
+
});
|
|
139
|
+
throw new ActionPostCommitError(
|
|
140
|
+
`Action "${actionName}" returned output that violated outputSchema: ${formatted.join("; ")}`,
|
|
141
|
+
void 0,
|
|
142
|
+
{
|
|
143
|
+
issues: result.issues.map((issue) => ({
|
|
144
|
+
path: formatIssuePath(issue.path),
|
|
145
|
+
message: issue.message
|
|
146
|
+
}))
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return result.value;
|
|
151
|
+
}
|
|
152
|
+
function schemaToJsonSchema(schema, mode, explicitOverride) {
|
|
153
|
+
if (mode === "input" && explicitOverride) {
|
|
154
|
+
return structuredClone(explicitOverride);
|
|
155
|
+
}
|
|
156
|
+
if (!schema) {
|
|
157
|
+
return mode === "input" ? { type: "object", properties: {}, additionalProperties: false } : null;
|
|
158
|
+
}
|
|
159
|
+
const standard = schema["~standard"];
|
|
160
|
+
const converter = mode === "input" ? standard.jsonSchema?.input : standard.jsonSchema?.output;
|
|
161
|
+
if (typeof converter !== "function") {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const converted = converter({ target: "draft-2020-12" });
|
|
165
|
+
if (!isPlainRecord(converted)) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
const copy = structuredClone(converted);
|
|
169
|
+
delete copy["$schema"];
|
|
170
|
+
return copy;
|
|
171
|
+
}
|
|
172
|
+
function normalizeLlmToolInput(rawInput, jsonSchema) {
|
|
173
|
+
if (!isPlainRecord(rawInput) || !jsonSchema) {
|
|
174
|
+
return rawInput;
|
|
175
|
+
}
|
|
176
|
+
const properties = isPlainRecord(jsonSchema["properties"]) ? jsonSchema["properties"] : null;
|
|
177
|
+
if (!properties) {
|
|
178
|
+
return rawInput;
|
|
179
|
+
}
|
|
180
|
+
const required = new Set(
|
|
181
|
+
Array.isArray(jsonSchema["required"]) ? jsonSchema["required"].filter(
|
|
182
|
+
(item) => typeof item === "string"
|
|
183
|
+
) : []
|
|
184
|
+
);
|
|
185
|
+
const out = {};
|
|
186
|
+
for (const [key, value] of Object.entries(rawInput)) {
|
|
187
|
+
const fieldSchema = isPlainRecord(properties[key]) ? properties[key] : null;
|
|
188
|
+
if (!fieldSchema) {
|
|
189
|
+
out[key] = value;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const fieldType = fieldSchema["type"];
|
|
193
|
+
const allowsNull = fieldType === "null" || Array.isArray(fieldType) && fieldType.includes("null") || Array.isArray(fieldSchema["anyOf"]) && fieldSchema["anyOf"].some(
|
|
194
|
+
(branch) => isPlainRecord(branch) && branch["type"] === "null"
|
|
195
|
+
);
|
|
196
|
+
if (value === null && !required.has(key) && !allowsNull) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (typeof value === "string" && (fieldType === "object" || fieldType === "array")) {
|
|
200
|
+
const trimmed = value.trim();
|
|
201
|
+
if (fieldType === "object" && trimmed.startsWith("{") && trimmed.endsWith("}") || fieldType === "array" && trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
202
|
+
try {
|
|
203
|
+
const parsed = JSON.parse(trimmed);
|
|
204
|
+
out[key] = fieldType === "object" ? normalizeLlmToolInput(parsed, fieldSchema) : parsed;
|
|
205
|
+
continue;
|
|
206
|
+
} catch {
|
|
207
|
+
out[key] = value;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (isPlainRecord(value) && fieldType === "object") {
|
|
213
|
+
out[key] = normalizeLlmToolInput(value, fieldSchema);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
out[key] = value;
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/action.ts
|
|
222
|
+
function defineAction(definition) {
|
|
223
|
+
return {
|
|
224
|
+
...definition,
|
|
225
|
+
__agentNativeAction: true
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function createActionBuilder() {
|
|
229
|
+
return function defineTypedAction(definition) {
|
|
230
|
+
return {
|
|
231
|
+
...definition,
|
|
232
|
+
__agentNativeAction: true
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function isDefinedAction(value) {
|
|
237
|
+
return typeof value === "object" && value !== null && "__agentNativeAction" in value && value.__agentNativeAction === true && typeof value.run === "function";
|
|
238
|
+
}
|
|
239
|
+
function resolveActionHttpMethod(action) {
|
|
240
|
+
if (action.http === false) return null;
|
|
241
|
+
if (action.http && action.http.method) return action.http.method;
|
|
242
|
+
return "POST";
|
|
243
|
+
}
|
|
244
|
+
function resolveActionHttpPath(name, action) {
|
|
245
|
+
if (action.http === false) return null;
|
|
246
|
+
if (action.http && action.http.path) {
|
|
247
|
+
return action.http.path.replace(/^\/+/, "");
|
|
248
|
+
}
|
|
249
|
+
return name;
|
|
250
|
+
}
|
|
251
|
+
function isActionReadOnly(action) {
|
|
252
|
+
if (typeof action.readOnly === "boolean") return action.readOnly;
|
|
253
|
+
return resolveActionHttpMethod(action) === "GET";
|
|
254
|
+
}
|
|
255
|
+
async function executeAction(options) {
|
|
256
|
+
const {
|
|
257
|
+
name,
|
|
258
|
+
action,
|
|
259
|
+
ctx,
|
|
260
|
+
caller,
|
|
261
|
+
approvalToken,
|
|
262
|
+
approved,
|
|
263
|
+
verifyApproval,
|
|
264
|
+
middleware = [],
|
|
265
|
+
onAfterMutate,
|
|
266
|
+
onError
|
|
267
|
+
} = options;
|
|
268
|
+
let committed = false;
|
|
269
|
+
try {
|
|
270
|
+
let candidateInput = options.rawInput;
|
|
271
|
+
if (caller === "mcp" || caller === "agent") {
|
|
272
|
+
const jsonSchema = schemaToJsonSchema(
|
|
273
|
+
action.schema,
|
|
274
|
+
"input",
|
|
275
|
+
action.toolSchema
|
|
276
|
+
);
|
|
277
|
+
candidateInput = normalizeLlmToolInput(candidateInput, jsonSchema);
|
|
278
|
+
}
|
|
279
|
+
const inputToValidate = candidateInput ?? {};
|
|
280
|
+
const validatedInput = action.schema ? await validateInputSchema(action.schema, inputToValidate, name) : inputToValidate;
|
|
281
|
+
if (action.authorize) {
|
|
282
|
+
const allowed = await action.authorize(validatedInput, ctx);
|
|
283
|
+
if (!allowed) {
|
|
284
|
+
throw new ActionError(`Not authorized to run action "${name}".`, {
|
|
285
|
+
statusCode: 403,
|
|
286
|
+
errorCode: "forbidden"
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (action.needsApproval !== void 0) {
|
|
291
|
+
const required = typeof action.needsApproval === "function" ? await action.needsApproval(validatedInput, ctx) : Boolean(action.needsApproval);
|
|
292
|
+
if (required) {
|
|
293
|
+
let isApproved = false;
|
|
294
|
+
if (verifyApproval) {
|
|
295
|
+
isApproved = Boolean(
|
|
296
|
+
await verifyApproval({
|
|
297
|
+
actionName: name,
|
|
298
|
+
input: validatedInput,
|
|
299
|
+
ctx,
|
|
300
|
+
caller,
|
|
301
|
+
...approvalToken !== void 0 ? { approvalToken } : {}
|
|
302
|
+
})
|
|
303
|
+
);
|
|
304
|
+
} else if (approved === true) {
|
|
305
|
+
isApproved = true;
|
|
306
|
+
}
|
|
307
|
+
if (!isApproved) {
|
|
308
|
+
throw new ActionError(
|
|
309
|
+
`Action "${name}" requires explicit human approval before executing.`,
|
|
310
|
+
{
|
|
311
|
+
statusCode: 403,
|
|
312
|
+
errorCode: "approval_required",
|
|
313
|
+
details: {
|
|
314
|
+
action: name,
|
|
315
|
+
input: validatedInput
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const runCore = async () => action.run(validatedInput, ctx);
|
|
323
|
+
const dispatch = middleware.reduceRight(
|
|
324
|
+
(next, mw) => () => mw({ name, input: validatedInput, ctx, caller, next }),
|
|
325
|
+
runCore
|
|
326
|
+
);
|
|
327
|
+
const rawResult = await dispatch();
|
|
328
|
+
committed = true;
|
|
329
|
+
const validatedResult = action.outputSchema ? await validateOutputSchema(action.outputSchema, rawResult, name) : rawResult;
|
|
330
|
+
if (onAfterMutate && !isActionReadOnly(action)) {
|
|
331
|
+
try {
|
|
332
|
+
await onAfterMutate({
|
|
333
|
+
name,
|
|
334
|
+
input: validatedInput,
|
|
335
|
+
result: validatedResult,
|
|
336
|
+
ctx,
|
|
337
|
+
caller
|
|
338
|
+
});
|
|
339
|
+
} catch (hookError) {
|
|
340
|
+
throw new ActionPostCommitError(
|
|
341
|
+
`Action "${name}" succeeded, but post-mutation hook failed.`,
|
|
342
|
+
hookError
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return validatedResult;
|
|
347
|
+
} catch (error) {
|
|
348
|
+
onError?.(error, { name, caller, ctx, committed });
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
export {
|
|
353
|
+
ActionError,
|
|
354
|
+
ActionPostCommitError,
|
|
355
|
+
createActionBuilder,
|
|
356
|
+
defineAction,
|
|
357
|
+
defineActionErrors,
|
|
358
|
+
executeAction,
|
|
359
|
+
fail,
|
|
360
|
+
isActionError,
|
|
361
|
+
isActionPostCommitError,
|
|
362
|
+
isActionReadOnly,
|
|
363
|
+
isDefinedAction,
|
|
364
|
+
normalizeLlmToolInput,
|
|
365
|
+
resolveActionHttpMethod,
|
|
366
|
+
resolveActionHttpPath,
|
|
367
|
+
schemaToJsonSchema,
|
|
368
|
+
serializeActionErrorBody,
|
|
369
|
+
validateInputSchema,
|
|
370
|
+
validateOutputSchema
|
|
371
|
+
};
|
|
372
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/schema.ts","../src/action.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","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nimport { ActionError, ActionPostCommitError } from \"./errors.js\";\nimport type { JsonSchemaObject } from \"./types.js\";\n\ninterface StandardJsonSchemaCapability {\n jsonSchema?: {\n input?: (options: { target: string }) => unknown;\n output?: (options: { target: string }) => unknown;\n };\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction formatIssuePath(\n path: ReadonlyArray<PropertyKey | StandardSchemaV1.PathSegment> | undefined,\n): string {\n if (!path || path.length === 0) return \"\";\n return path\n .map((segment) =>\n typeof segment === \"object\" && \"key\" in segment\n ? String(segment.key)\n : String(segment),\n )\n .join(\".\");\n}\n\nexport async function validateInputSchema<TSchema extends StandardSchemaV1>(\n schema: TSchema,\n rawInput: unknown,\n actionName: string,\n): Promise<StandardSchemaV1.InferOutput<TSchema>> {\n const result = await schema[\"~standard\"].validate(rawInput);\n if (result.issues) {\n const formatted = result.issues.map((issue) => {\n const pathStr = formatIssuePath(issue.path);\n return pathStr ? `${pathStr}: ${issue.message}` : issue.message;\n });\n throw new ActionError(\n `Invalid input for \"${actionName}\": ${formatted.join(\"; \")}`,\n {\n statusCode: 400,\n errorCode: \"invalid_input\",\n details: {\n issues: result.issues.map((issue) => ({\n path: formatIssuePath(issue.path),\n message: issue.message,\n })),\n },\n },\n );\n }\n return result.value;\n}\n\nexport async function validateOutputSchema<TSchema extends StandardSchemaV1>(\n schema: TSchema,\n rawOutput: unknown,\n actionName: string,\n): Promise<StandardSchemaV1.InferOutput<TSchema>> {\n const result = await schema[\"~standard\"].validate(rawOutput);\n if (result.issues) {\n const formatted = result.issues.map((issue) => {\n const pathStr = formatIssuePath(issue.path);\n return pathStr ? `${pathStr}: ${issue.message}` : issue.message;\n });\n throw new ActionPostCommitError(\n `Action \"${actionName}\" returned output that violated outputSchema: ${formatted.join(\"; \")}`,\n undefined,\n {\n issues: result.issues.map((issue) => ({\n path: formatIssuePath(issue.path),\n message: issue.message,\n })),\n },\n );\n }\n return result.value;\n}\n\nexport function schemaToJsonSchema(\n schema: StandardSchemaV1 | undefined,\n mode: \"input\" | \"output\",\n explicitOverride?: JsonSchemaObject,\n): JsonSchemaObject | null {\n if (mode === \"input\" && explicitOverride) {\n return structuredClone(explicitOverride);\n }\n if (!schema) {\n return mode === \"input\"\n ? { type: \"object\", properties: {}, additionalProperties: false }\n : null;\n }\n\n const standard = schema[\"~standard\"] as StandardSchemaV1.Props &\n StandardJsonSchemaCapability;\n const converter =\n mode === \"input\" ? standard.jsonSchema?.input : standard.jsonSchema?.output;\n\n if (typeof converter !== \"function\") {\n return null;\n }\n\n const converted = converter({ target: \"draft-2020-12\" });\n if (!isPlainRecord(converted)) {\n return null;\n }\n const copy = structuredClone(converted);\n delete copy[\"$schema\"];\n return copy;\n}\n\n/**\n * Normalize common LLM strict-mode quirks where optional fields are sent as\n * `null` or stringified JSON objects/arrays when the JSON Schema does not\n * expect those types.\n */\nexport function normalizeLlmToolInput(\n rawInput: unknown,\n jsonSchema: JsonSchemaObject | null,\n): unknown {\n if (!isPlainRecord(rawInput) || !jsonSchema) {\n return rawInput;\n }\n const properties = isPlainRecord(jsonSchema[\"properties\"])\n ? jsonSchema[\"properties\"]\n : null;\n if (!properties) {\n return rawInput;\n }\n const required = new Set(\n Array.isArray(jsonSchema[\"required\"])\n ? jsonSchema[\"required\"].filter(\n (item): item is string => typeof item === \"string\",\n )\n : [],\n );\n\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rawInput)) {\n const fieldSchema = isPlainRecord(properties[key]) ? properties[key] : null;\n if (!fieldSchema) {\n out[key] = value;\n continue;\n }\n\n const fieldType = fieldSchema[\"type\"];\n const allowsNull =\n fieldType === \"null\" ||\n (Array.isArray(fieldType) && fieldType.includes(\"null\")) ||\n (Array.isArray(fieldSchema[\"anyOf\"]) &&\n fieldSchema[\"anyOf\"].some(\n (branch) => isPlainRecord(branch) && branch[\"type\"] === \"null\",\n ));\n\n if (value === null && !required.has(key) && !allowsNull) {\n continue;\n }\n\n if (\n typeof value === \"string\" &&\n (fieldType === \"object\" || fieldType === \"array\")\n ) {\n const trimmed = value.trim();\n if (\n (fieldType === \"object\" &&\n trimmed.startsWith(\"{\") &&\n trimmed.endsWith(\"}\")) ||\n (fieldType === \"array\" &&\n trimmed.startsWith(\"[\") &&\n trimmed.endsWith(\"]\"))\n ) {\n try {\n const parsed: unknown = JSON.parse(trimmed);\n out[key] =\n fieldType === \"object\"\n ? normalizeLlmToolInput(parsed, fieldSchema)\n : parsed;\n continue;\n } catch {\n out[key] = value;\n continue;\n }\n }\n }\n\n if (isPlainRecord(value) && fieldType === \"object\") {\n out[key] = normalizeLlmToolInput(value, fieldSchema);\n continue;\n }\n\n out[key] = value;\n }\n return out;\n}\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nimport { ActionError, ActionPostCommitError } from \"./errors.js\";\nimport {\n normalizeLlmToolInput,\n schemaToJsonSchema,\n validateInputSchema,\n validateOutputSchema,\n} from \"./schema.js\";\nimport type {\n ActionAfterMutateInfo,\n ActionApprovalVerifier,\n ActionCaller,\n ActionDefinition,\n ActionErrorInfo,\n ActionHttpMethod,\n ActionMapEntry,\n ActionMiddleware,\n DefaultActionContext,\n DefinedAction,\n} from \"./types.js\";\n\nexport function defineAction<\n TSchema extends StandardSchemaV1 | undefined = undefined,\n TOutputSchema extends StandardSchemaV1 | undefined = undefined,\n TReturn = unknown,\n TCtx = DefaultActionContext,\n>(\n definition: ActionDefinition<TSchema, TOutputSchema, TReturn, TCtx>,\n): DefinedAction<TSchema, TOutputSchema, TReturn, TCtx> {\n return {\n ...definition,\n __agentNativeAction: true,\n };\n}\n\n/**\n * Create an app-local `defineAction` helper pre-bound to your app's context type\n * (e.g. `{ user: SessionUser | null; orgId: string | null }`), so `ctx` is\n * strongly typed inside every `actions/*.ts` file.\n */\nexport function createActionBuilder<TCtx>() {\n return function defineTypedAction<\n TSchema extends StandardSchemaV1 | undefined = undefined,\n TOutputSchema extends StandardSchemaV1 | undefined = undefined,\n TReturn = unknown,\n >(\n definition: ActionDefinition<TSchema, TOutputSchema, TReturn, TCtx>,\n ): DefinedAction<TSchema, TOutputSchema, TReturn, TCtx> {\n return {\n ...definition,\n __agentNativeAction: true,\n };\n };\n}\n\nexport function isDefinedAction(value: unknown): value is DefinedAction {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"__agentNativeAction\" in value &&\n (value as { __agentNativeAction?: unknown }).__agentNativeAction === true &&\n typeof (value as { run?: unknown }).run === \"function\"\n );\n}\n\nexport function resolveActionHttpMethod(\n action: Pick<ActionMapEntry<never>, \"http\">,\n): ActionHttpMethod | null {\n if (action.http === false) return null;\n if (action.http && action.http.method) return action.http.method;\n return \"POST\";\n}\n\nexport function resolveActionHttpPath(\n name: string,\n action: Pick<ActionMapEntry<never>, \"http\">,\n): string | null {\n if (action.http === false) return null;\n if (action.http && action.http.path) {\n return action.http.path.replace(/^\\/+/, \"\");\n }\n return name;\n}\n\nexport function isActionReadOnly(\n action: Pick<ActionMapEntry<never>, \"readOnly\" | \"http\">,\n): boolean {\n if (typeof action.readOnly === \"boolean\") return action.readOnly;\n return resolveActionHttpMethod(action) === \"GET\";\n}\n\nexport interface ExecuteActionOptions<TCtx> {\n name: string;\n action: ActionMapEntry<TCtx>;\n rawInput: unknown;\n ctx: TCtx;\n caller: ActionCaller;\n approvalToken?: string;\n approved?: boolean;\n verifyApproval?: ActionApprovalVerifier<TCtx>;\n middleware?: readonly ActionMiddleware<TCtx>[];\n onAfterMutate?: (info: ActionAfterMutateInfo<TCtx>) => void | Promise<void>;\n onError?: (error: unknown, info: ActionErrorInfo<TCtx>) => void;\n}\n\n/**\n * Single checked execution pipeline shared by HTTP, direct `.call()`, CLI,\n * MCP, and AI SDK tools:\n *\n * 1. Normalize LLM input quirks (for `mcp` and `agent` callers only)\n * 2. Validate input once through Standard Schema\n * 3. Run `authorize(input, ctx)` -> 403 `forbidden` before approval or `run`\n * 4. Evaluate `needsApproval(input, ctx)` -> 403 `approval_required` unless verified\n * 5. Run middleware chain + `run(input, ctx)`\n * 6. Validate `outputSchema` and fire `onAfterMutate` (failures raise `ActionPostCommitError`)\n */\nexport async function executeAction<TCtx>(\n options: ExecuteActionOptions<TCtx>,\n): Promise<unknown> {\n const {\n name,\n action,\n ctx,\n caller,\n approvalToken,\n approved,\n verifyApproval,\n middleware = [],\n onAfterMutate,\n onError,\n } = options;\n\n let committed = false;\n\n try {\n let candidateInput = options.rawInput;\n if (caller === \"mcp\" || caller === \"agent\") {\n const jsonSchema = schemaToJsonSchema(\n action.schema,\n \"input\",\n action.toolSchema,\n );\n candidateInput = normalizeLlmToolInput(candidateInput, jsonSchema);\n }\n\n const inputToValidate = candidateInput ?? {};\n const validatedInput = action.schema\n ? await validateInputSchema(action.schema, inputToValidate, name)\n : inputToValidate;\n\n if (action.authorize) {\n const allowed = await action.authorize(validatedInput as never, ctx);\n if (!allowed) {\n throw new ActionError(`Not authorized to run action \"${name}\".`, {\n statusCode: 403,\n errorCode: \"forbidden\",\n });\n }\n }\n\n if (action.needsApproval !== undefined) {\n const required =\n typeof action.needsApproval === \"function\"\n ? await action.needsApproval(validatedInput as never, ctx)\n : Boolean(action.needsApproval);\n\n if (required) {\n let isApproved = false;\n if (verifyApproval) {\n isApproved = Boolean(\n await verifyApproval({\n actionName: name,\n input: validatedInput,\n ctx,\n caller,\n ...(approvalToken !== undefined ? { approvalToken } : {}),\n }),\n );\n } else if (approved === true) {\n isApproved = true;\n }\n\n if (!isApproved) {\n throw new ActionError(\n `Action \"${name}\" requires explicit human approval before executing.`,\n {\n statusCode: 403,\n errorCode: \"approval_required\",\n details: {\n action: name,\n input: validatedInput,\n },\n },\n );\n }\n }\n }\n\n const runCore = async (): Promise<unknown> =>\n action.run(validatedInput as never, ctx);\n\n const dispatch = middleware.reduceRight<() => Promise<unknown>>(\n (next, mw) => () =>\n mw({ name, input: validatedInput, ctx, caller, next }),\n runCore,\n );\n\n const rawResult = await dispatch();\n committed = true;\n\n const validatedResult = action.outputSchema\n ? await validateOutputSchema(action.outputSchema, rawResult, name)\n : rawResult;\n\n if (onAfterMutate && !isActionReadOnly(action)) {\n try {\n await onAfterMutate({\n name,\n input: validatedInput,\n result: validatedResult,\n ctx,\n caller,\n });\n } catch (hookError) {\n throw new ActionPostCommitError(\n `Action \"${name}\" succeeded, but post-mutation hook failed.`,\n hookError,\n );\n }\n }\n\n return validatedResult;\n } catch (error) {\n onError?.(error, { name, caller, ctx, committed });\n throw error;\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,SAAK,aAAa,QAAQ,cAAc,QAAQ,UAAU;AAC1D,SAAK,YAAY,QAAQ,aAAa;AACtC,SAAK,UAAU,QAAQ;AACvB,SAAK,YAAY,QAAQ,aAAa;AAAA,EACxC;AACF;AAOO,IAAM,wBAAN,cAAoC,YAAY;AAAA,EACrD,CAAU,uBAAuB,IAAI;AAAA,EACnB;AAAA,EAElB,YACE,SACA,OACA,SACA;AACA,UAAM,SAAS;AAAA,MACb,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,WAAW;AAAA,MACX,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC/B,CAAC;A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