@arbol-ai/maximus 8.0.1 → 8.4.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/dist/analytics/analytics.d.ts +16 -16
- package/dist/analytics/analytics.js +4 -4
- package/dist/body.d.ts +2 -2
- package/dist/body.js +2 -2
- package/dist/capture/index.d.ts +37 -0
- package/dist/capture/index.js +181 -0
- package/dist/chunks/{define-app-x7uY70_1.js → define-app-CQpWqqqE.js} +44 -14
- package/dist/chunks/delay-BsKQP_lF.js +12 -0
- package/dist/chunks/{json-B14evE6-.js → destination-DIkn8W6K.js} +65 -1
- package/dist/chunks/digest-C51F1bhA.js +12 -0
- package/dist/chunks/{errors-C5w9WY1l.js → errors-BoutSmiy.js} +2 -3
- package/dist/chunks/execution-Bpq6s4nA.js +265 -0
- package/dist/chunks/{generate-C-9FKW0o.js → generate-Dg88LzLU.js} +1 -1
- package/dist/chunks/{handler-iebR-urt.js → handler-DSpyrWc-.js} +6 -2
- package/dist/chunks/{http-layout-DS8DnPyu.js → http-layout-BcYH4I2w.js} +1 -1
- package/dist/chunks/{http-paths-DMBxwpp6.js → http-paths-D043DkJv.js} +50 -81
- package/dist/chunks/http-routes-B6tCsnxB.js +29 -0
- package/dist/chunks/{openapi-CeolxIqa.js → openapi-D2rds7vy.js} +32 -130
- package/dist/chunks/{openapi-file-Bz9FRaE6.js → openapi-file-BK8zET5U.js} +24 -6
- package/dist/chunks/{pages-iZTvFs5a.js → pages-B7ysoFAM.js} +1 -1
- package/dist/chunks/result-CF4OzG9O.js +29 -0
- package/dist/chunks/{runtime-D94vx21X.js → runtime-CGtS2rOb.js} +165 -11
- package/dist/chunks/schemas-_UJcx_uY.js +813 -0
- package/dist/chunks/{server-Bzf1Q1_4.js → server-CVhTLNj2.js} +38 -101
- package/dist/chunks/{src-CPrJpbOM.js → src-D67OfW9B.js} +94 -27
- package/dist/chunks/tasks-C873C3le.js +100 -0
- package/dist/chunks/tasks-DYdY-dBI.js +267 -0
- package/dist/chunks/{telemetry-C3LfZcOB.js → telemetry-BtxJh69Q.js} +4 -4
- package/dist/chunks/{types-DTIuIEJ-.d.ts → types-BfGa2aJT.d.ts} +537 -124
- package/dist/chunks/validation-CpzAxj2_.js +201 -0
- package/dist/chunks/{workers-types-BRk_Xa_5.d.ts → workers-types-Cxf-5cH7.d.ts} +6 -1
- package/dist/diagnostics.d.ts +1 -1
- package/dist/diagnostics.js +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -11
- package/dist/internals.d.ts +2 -2
- package/dist/internals.js +6 -6
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/tasks.d.ts +33 -0
- package/dist/mcp/tasks.js +3 -0
- package/dist/project/config.d.ts +2 -2
- package/dist/project/config.js +3 -2
- package/dist/project/index.d.ts +2 -2
- package/dist/project/index.js +3 -3
- package/dist/schemas.d.ts +2 -2
- package/dist/schemas.js +3 -3
- package/dist/standard-failures.d.ts +1 -1
- package/dist/tooling/cli.js +2 -2
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +15 -9
- package/dist/webhooks.d.ts +13 -2
- package/dist/webhooks.js +38 -1
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +15 -3
- package/skills/maximus/SKILL.md +14 -4
- package/skills/maximus/references/project.md +4 -0
- package/skills/maximus/references/routes-and-tools.md +11 -1
- package/templates/project/CLAUDE.md.template +3 -3
- package/templates/project/README.md.template +1 -0
- package/templates/project/tsconfig.json.template +1 -0
- package/dist/chunks/execution-rOiLo8VG.js +0 -84
- package/dist/chunks/result-CKgZHrnj.js +0 -56
- package/dist/chunks/schemas-p_aRcMC1.js +0 -227
- package/dist/chunks/validation-fTohBT6R.js +0 -420
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { f as Value } from "./validation-CpzAxj2_.js";
|
|
2
|
+
import { t as STANDARD_FAILURES } from "./standard-failures-Lh4mSfwG.js";
|
|
3
|
+
import { O as literalUnion, i as UuidSchema } from "./schemas-_UJcx_uY.js";
|
|
4
|
+
import { i as standardErrors, t as FailureSchema } from "./errors-BoutSmiy.js";
|
|
5
|
+
import { r as ok, t as err } from "./result-CF4OzG9O.js";
|
|
6
|
+
import { Type } from "typebox";
|
|
7
|
+
|
|
8
|
+
// src/scopes.ts
|
|
9
|
+
/** `<namespace>:<resource>:<action>`, or deeper, in lowercase kebab-case segments. */
|
|
10
|
+
const SCOPE_NAME = /^[a-z][a-z0-9-]*(?::[a-z][a-z0-9-]*){2,}$/;
|
|
11
|
+
/** Whether `scope` is a well-formed scope of the service whose namespace is `namespace`. */
|
|
12
|
+
function isNamespacedScope(scope, namespace) {
|
|
13
|
+
return scope.startsWith(`${namespace}:`) && SCOPE_NAME.test(scope);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether granted scopes admit a requirement: any one of the required scopes, or all of them with `all`.
|
|
17
|
+
* An empty requirement admits nobody.
|
|
18
|
+
*/
|
|
19
|
+
function matchesScopes(required, granted, match = "any") {
|
|
20
|
+
if (!required.length) return false;
|
|
21
|
+
const has = (scope) => granted.includes(scope);
|
|
22
|
+
return match === "all" ? required.every(has) : match === "any" && required.some(has);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/manifest.ts
|
|
26
|
+
/** Whether an operation belongs in public contracts: the OpenAPI document and the discovery metadata. */
|
|
27
|
+
function isPublicOperation(declaration) {
|
|
28
|
+
return declaration.visibility !== "internal";
|
|
29
|
+
}
|
|
30
|
+
/** The scopes of an operation as a list. */
|
|
31
|
+
function operationScopes(declaration) {
|
|
32
|
+
return typeof declaration.scope === "string" ? [declaration.scope] : declaration.scope;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether granted scopes admit an operation: any one of its scopes, or every one under `scopeMatch: 'all'`.
|
|
36
|
+
* HTTP admission, MCP listing and calls, and execution share it.
|
|
37
|
+
*/
|
|
38
|
+
function operationMatchesScopes(declaration, granted) {
|
|
39
|
+
return matchesScopes(operationScopes(declaration), granted, declaration.scopeMatch);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Declares one operation on its own, keeping its literal types. The builder's `.operation()` is the usual way
|
|
43
|
+
* to declare one. As there, `execute` receives the decoded input, `StaticDecode<typeof input>`.
|
|
44
|
+
*/
|
|
45
|
+
function operation(definition) {
|
|
46
|
+
return definition;
|
|
47
|
+
}
|
|
48
|
+
/** Where an operation is served, for a refusal that names it: its HTTP route, else its MCP tool. */
|
|
49
|
+
function servedAs(declared) {
|
|
50
|
+
if (declared?.http) return `${declared.http.method} ${declared.http.path}`;
|
|
51
|
+
return declared?.mcp && `the tool ${declared.mcp.name}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Merges groups of operations into one, never overwriting: a name two groups declare throws a TypeError,
|
|
55
|
+
* `Duplicate operation: <name>`, which names the route or tool of each when both have one.
|
|
56
|
+
*/
|
|
57
|
+
function composeOperations(...groups) {
|
|
58
|
+
const result = {};
|
|
59
|
+
for (const group of groups) for (const [name, op] of Object.entries(group)) {
|
|
60
|
+
if (Object.hasOwn(result, name)) {
|
|
61
|
+
const first = servedAs(result[name]);
|
|
62
|
+
const second = servedAs(op);
|
|
63
|
+
throw new TypeError(first && second ? `Duplicate operation: ${name} names both ${first} and ${second}; give one of them its own operationId.` : `Duplicate operation: ${name}`);
|
|
64
|
+
}
|
|
65
|
+
Object.defineProperty(result, name, {
|
|
66
|
+
value: op,
|
|
67
|
+
enumerable: true
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
/** The failure codes every operation may answer without declaring them. */
|
|
73
|
+
const STANDARD_CODES = new Set(Object.values(STANDARD_FAILURES).map(({ code }) => code));
|
|
74
|
+
/**
|
|
75
|
+
* The standard failures only routing and admission answer, before an operation runs: an unknown path or
|
|
76
|
+
* method, and a missing or refused token. An operation's context, middleware or handler never answers them.
|
|
77
|
+
*/
|
|
78
|
+
const ADMISSION_CODES = /* @__PURE__ */ new Set([
|
|
79
|
+
STANDARD_FAILURES.notFound.code,
|
|
80
|
+
STANDARD_FAILURES.methodNotAllowed.code,
|
|
81
|
+
STANDARD_FAILURES.unauthorized.code
|
|
82
|
+
]);
|
|
83
|
+
/**
|
|
84
|
+
* The standard failures of reading a request body: admission answers them for a JSON body, and a byte body's
|
|
85
|
+
* `read()` for the operation that reads one.
|
|
86
|
+
*/
|
|
87
|
+
const BODY_CODES = /* @__PURE__ */ new Set([STANDARD_FAILURES.tooLarge.code, STANDARD_FAILURES.unsupportedMedia.code]);
|
|
88
|
+
/** Default request body limit when neither the operation nor the application sets one. */
|
|
89
|
+
const DEFAULT_MAX_BODY_BYTES = 32768;
|
|
90
|
+
/** Default output limit when neither the operation nor the application sets one. */
|
|
91
|
+
const DEFAULT_MAX_OUTPUT_BYTES = 262144;
|
|
92
|
+
/** Largest body limit an application or operation may declare: the body is buffered in memory. */
|
|
93
|
+
const MAX_BODY_BYTES_CEILING = 16777216;
|
|
94
|
+
/** The request body limit an operation is held to: its own, else the application's, else the default. */
|
|
95
|
+
function operationBodyLimit(application, declaration) {
|
|
96
|
+
return declaration.maxBodyBytes ?? application.maxBodyBytes ?? 32768;
|
|
97
|
+
}
|
|
98
|
+
/** The output limit an operation is held to: its own, else the application's, else the default. */
|
|
99
|
+
function operationOutputLimit(application, declaration) {
|
|
100
|
+
return declaration.maxOutputBytes ?? application.maxOutputBytes ?? 262144;
|
|
101
|
+
}
|
|
102
|
+
/** Whether an operation's MCP tool reaches outside the service: it does unless it declares otherwise. */
|
|
103
|
+
function mcpOpenWorld(tool) {
|
|
104
|
+
return tool.openWorld ?? true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/tasks.ts
|
|
108
|
+
/**
|
|
109
|
+
* Tasks for the operations that declare `task`: a call that outlasts a short wait answers a task, as MCP Tasks
|
|
110
|
+
* (`io.modelcontextprotocol/tasks`) and RFC 7240's `Prefer: respond-async` define it, and the work goes on in
|
|
111
|
+
* the application's task store, the `MAXIMUS_TASKS` Durable Object binding (`createWorker`'s `tasks`), one
|
|
112
|
+
* object per task. Without that binding every call runs as before. A task belongs to the caller that started
|
|
113
|
+
* it, runs at most once and is kept for its `ttlMs`: an hour, unless its operation declares another.
|
|
114
|
+
*/
|
|
115
|
+
/** How long a call waits for its task to finish before it answers the task instead. */
|
|
116
|
+
const TASK_WAIT_MS = 1e3;
|
|
117
|
+
/** How long a task and its result are kept after the call, unless its operation declares `task: { ttlMs }`. */
|
|
118
|
+
const TASK_TTL_MS = 36e5;
|
|
119
|
+
/** The longest an operation may keep its tasks: a day. */
|
|
120
|
+
const MAX_TASK_TTL_MS = 864e5;
|
|
121
|
+
/** How often a client should ask for a task that is still working. */
|
|
122
|
+
const TASK_POLL_MS = 2e3;
|
|
123
|
+
/** The group of the task operations, which the framework adds and so describes itself. */
|
|
124
|
+
const TASK_GROUP = "Operation tasks";
|
|
125
|
+
/** What the documents say about that group, unless the service's own `groups` describes it. */
|
|
126
|
+
const TASK_GROUP_DESCRIPTION = "The tasks of operations that answer before they finish: read one you started, or cancel one that has not started running.";
|
|
127
|
+
/** How long an operation keeps its tasks: its `task.ttlMs`, or an hour. */
|
|
128
|
+
function taskTtl(operation) {
|
|
129
|
+
return typeof operation?.task === "object" ? operation.task.ttlMs : TASK_TTL_MS;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The caller's tasks in the store `env` binds as `MAXIMUS_TASKS`, or none without it. Each task has its own
|
|
133
|
+
* object, named by its id, so no task waits for another; an id this application never issues names none.
|
|
134
|
+
*/
|
|
135
|
+
function taskAccess(application, env, principal, authority) {
|
|
136
|
+
const binding = env?.MAXIMUS_TASKS;
|
|
137
|
+
if (!binding) return;
|
|
138
|
+
const prefix = `${application.namespace}.`;
|
|
139
|
+
const store = (taskId) => binding.get(binding.idFromName(taskId));
|
|
140
|
+
/** Whether the id is one this application issues: its namespace, a dot and a UUID. */
|
|
141
|
+
const issued = (taskId) => taskId.startsWith(prefix) && Value.Check(UuidSchema, taskId.slice(prefix.length));
|
|
142
|
+
const kept = authority && {
|
|
143
|
+
surface: authority.surface,
|
|
144
|
+
scopes: authority.scopes,
|
|
145
|
+
client: authority.client
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
start: (operation, input) => {
|
|
149
|
+
const now = Date.now();
|
|
150
|
+
const taskId = `${prefix}${crypto.randomUUID()}`;
|
|
151
|
+
const task = {
|
|
152
|
+
taskId,
|
|
153
|
+
operation,
|
|
154
|
+
principal,
|
|
155
|
+
status: "working",
|
|
156
|
+
started: false
|
|
157
|
+
};
|
|
158
|
+
return store(taskId).run({
|
|
159
|
+
...task,
|
|
160
|
+
...kept ? { authority: kept } : {},
|
|
161
|
+
createdAt: now,
|
|
162
|
+
lastUpdatedAt: now,
|
|
163
|
+
ttlMs: taskTtl(application.operations[operation])
|
|
164
|
+
}, input, TASK_WAIT_MS);
|
|
165
|
+
},
|
|
166
|
+
get: (taskId) => issued(taskId) ? store(taskId).get(taskId, principal) : Promise.resolve(void 0),
|
|
167
|
+
cancel: (taskId) => issued(taskId) ? store(taskId).cancel(taskId, principal) : Promise.resolve(void 0)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/** A task as REST answers it: its state, then the operation's value or failure once it has one. */
|
|
171
|
+
const TaskSchema = Type.Object({
|
|
172
|
+
taskId: Type.String(),
|
|
173
|
+
status: literalUnion([
|
|
174
|
+
"working",
|
|
175
|
+
"completed",
|
|
176
|
+
"failed",
|
|
177
|
+
"cancelled"
|
|
178
|
+
]),
|
|
179
|
+
createdAt: Type.String({ format: "date-time" }),
|
|
180
|
+
lastUpdatedAt: Type.String({ format: "date-time" }),
|
|
181
|
+
ttlMs: Type.Integer(),
|
|
182
|
+
pollIntervalMs: Type.Integer(),
|
|
183
|
+
result: Type.Optional(Type.Unknown({ description: "The operation's value, once completed." })),
|
|
184
|
+
error: Type.Optional(Type.With(FailureSchema, { description: "The operation's failure, once failed." }))
|
|
185
|
+
}, {
|
|
186
|
+
$id: "OperationTask",
|
|
187
|
+
additionalProperties: false,
|
|
188
|
+
description: "A call that goes on after it was answered."
|
|
189
|
+
});
|
|
190
|
+
/** A task as REST answers it. */
|
|
191
|
+
function taskView(task) {
|
|
192
|
+
return {
|
|
193
|
+
taskId: task.taskId,
|
|
194
|
+
status: task.status,
|
|
195
|
+
createdAt: new Date(task.createdAt).toISOString(),
|
|
196
|
+
lastUpdatedAt: new Date(task.lastUpdatedAt).toISOString(),
|
|
197
|
+
ttlMs: task.ttlMs,
|
|
198
|
+
pollIntervalMs: TASK_POLL_MS,
|
|
199
|
+
...task.result?.ok === true ? { result: task.result.value } : {},
|
|
200
|
+
...task.result?.ok === false ? { error: task.result.error } : {}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* `getOperationTask`, `GET /v1/operation-tasks/{taskId}`, which reads a task the caller started, and
|
|
205
|
+
* `cancelOperationTask`, `POST /v1/operation-tasks/{taskId}/cancel`, which cancels one that has not started
|
|
206
|
+
* running: names and paths no resource of a service uses. Either admits any scope of the task operations;
|
|
207
|
+
* someone else's task, or an unknown or expired one, is `INVALID_INPUT` at `/taskId`, their only failure
|
|
208
|
+
* besides admission's.
|
|
209
|
+
*/
|
|
210
|
+
function taskOperations(scope, application) {
|
|
211
|
+
const answer = (method) => async ({ env, principal }, { taskId }) => {
|
|
212
|
+
const task = await taskAccess(application, env, principal)?.[method](taskId);
|
|
213
|
+
return task ? ok(taskView(task)) : err(standardErrors.invalidInput.create({ issues: [{
|
|
214
|
+
path: "/taskId",
|
|
215
|
+
message: "must name a task you started"
|
|
216
|
+
}] }));
|
|
217
|
+
};
|
|
218
|
+
const shared = {
|
|
219
|
+
scope,
|
|
220
|
+
group: TASK_GROUP,
|
|
221
|
+
failures: [],
|
|
222
|
+
input: Type.Object({ taskId: Type.String({
|
|
223
|
+
minLength: 1,
|
|
224
|
+
maxLength: 200
|
|
225
|
+
}) }, { additionalProperties: false }),
|
|
226
|
+
output: TaskSchema,
|
|
227
|
+
pipeline: {
|
|
228
|
+
context: (invocation) => Promise.resolve(ok(invocation)),
|
|
229
|
+
middleware: []
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
getOperationTask: {
|
|
234
|
+
...shared,
|
|
235
|
+
title: "Read a task",
|
|
236
|
+
description: "Read a task you started: whether it still works, then the operation's value or failure.",
|
|
237
|
+
effect: "read",
|
|
238
|
+
http: {
|
|
239
|
+
method: "GET",
|
|
240
|
+
path: "/v1/operation-tasks/{taskId}"
|
|
241
|
+
},
|
|
242
|
+
execute: answer("get")
|
|
243
|
+
},
|
|
244
|
+
cancelOperationTask: {
|
|
245
|
+
...shared,
|
|
246
|
+
title: "Cancel a task",
|
|
247
|
+
description: "Cancel a task you started that has not started running; one that has runs to its end.",
|
|
248
|
+
effect: "write",
|
|
249
|
+
http: {
|
|
250
|
+
method: "POST",
|
|
251
|
+
path: "/v1/operation-tasks/{taskId}/cancel"
|
|
252
|
+
},
|
|
253
|
+
execute: answer("cancel")
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/** The application's operations and, when one of them declares `task`, the task operations. */
|
|
258
|
+
function withTaskOperations(operations, namespace) {
|
|
259
|
+
const [first, ...rest] = new Set(Object.values(operations).flatMap((op) => op.task ? operationScopes(op) : []));
|
|
260
|
+
if (first === void 0) return operations;
|
|
261
|
+
return composeOperations(operations, taskOperations([first, ...rest], {
|
|
262
|
+
namespace,
|
|
263
|
+
operations
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export { matchesScopes as S, operationBodyLimit as _, taskAccess as a, operationScopes as b, ADMISSION_CODES as c, MAX_BODY_BYTES_CEILING as d, STANDARD_CODES as f, operation as g, mcpOpenWorld as h, TASK_POLL_MS as i, BODY_CODES as l, isPublicOperation as m, TASK_GROUP as n, taskView as o, composeOperations as p, TASK_GROUP_DESCRIPTION as r, withTaskOperations as s, MAX_TASK_TTL_MS as t, DEFAULT_MAX_BODY_BYTES as u, operationMatchesScopes as v, isNamespacedScope as x, operationOutputLimit as y };
|
|
@@ -95,9 +95,9 @@ function createDiagnostics(errorNames = []) {
|
|
|
95
95
|
* Telemetry: invocation-local diagnostics kept in AsyncLocalStorage, safe native log events, and observers
|
|
96
96
|
* that receive execution and admission observations as background work.
|
|
97
97
|
*/
|
|
98
|
-
/** Microseconds
|
|
99
|
-
function elapsedMicros(started) {
|
|
100
|
-
return Math.max(0, Math.round((
|
|
98
|
+
/** Microseconds from `started` to `until` or now, each a `performance.now()` reading. */
|
|
99
|
+
function elapsedMicros(started, until = performance.now()) {
|
|
100
|
+
return Math.max(0, Math.round((until - started) * 1e3));
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Hands one event to one observer as background work: a failed delivery is logged with its request id
|
|
@@ -236,4 +236,4 @@ function recordExecution(manifest, env, background, invocation) {
|
|
|
236
236
|
for (const observer of manifest.telemetry?.observers ?? []) if (observer.execution) deliver(background, event.principal.requestId, () => observer.execution?.(event, env));
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
export {
|
|
239
|
+
export { recordExecution as a, withDiagnostics as c, recordAdmission as i, withTelemetry as l, diagnosticsEnabled as n, reportUnexpected as o, elapsedMicros as r, telemetryEnabled as s, activeTraceId as t, createDiagnostics as u };
|