@arbol-ai/maximus 7.3.1 → 8.0.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 +36 -38
- package/bin/maximus.js +4 -0
- package/config/oxfmt.mjs +1 -0
- package/config/oxlint.mjs +10 -0
- package/dist/analytics/analytics.d.ts +21 -9
- package/dist/analytics/analytics.js +19 -5
- package/dist/body.d.ts +1 -1
- package/dist/body.js +2 -2
- package/dist/chunks/agent-skills-Ef65jTf_.js +49 -0
- package/dist/chunks/agent-skills-m7y1EUch.js +3 -0
- package/dist/chunks/{body-6LichrQm.js → body-DOIHwIIl.js} +14 -7
- package/dist/chunks/{correlation-BEkcFFGT.js → correlation-4b23a-a4.js} +8 -5
- package/dist/chunks/define-app-CfVZBt7D.js +336 -0
- package/dist/chunks/errors-WfyKhiyk.js +131 -0
- package/dist/chunks/execution-CfZEx_JP.js +84 -0
- package/dist/chunks/generate-C-9FKW0o.js +197 -0
- package/dist/chunks/handler-DWTGoduQ.js +140 -0
- package/dist/chunks/http-layout-_h7xwgPC.js +128 -0
- package/dist/chunks/http-paths-DMBxwpp6.js +218 -0
- package/dist/chunks/{json-Bu4BLT25.js → json-B14evE6-.js} +21 -5
- package/dist/chunks/names-ncD7A3DV.js +280 -0
- package/dist/chunks/openapi-CV0KmJpS.js +1588 -0
- package/dist/chunks/openapi-file-OjSs9mRv.js +83 -0
- package/dist/chunks/pages-DyC0m8Zb.js +14 -0
- package/dist/chunks/prepare-configured-BmRJLg6J.js +3 -0
- package/dist/chunks/prepare-configured-Cithjf80.js +52 -0
- package/dist/chunks/project-files-C0OX7MQQ.js +130 -0
- package/dist/chunks/query-kind-CWKAXEME.js +40 -0
- package/dist/chunks/record-DQUDTpEA.js +10 -0
- package/dist/chunks/result-CKgZHrnj.js +56 -0
- package/dist/chunks/{runtime-BPnaa-NK.js → runtime-CVVf5hmp.js} +50 -25
- package/dist/chunks/scaffold-DGrcjR3h.js +3 -0
- package/dist/chunks/scaffold-DZD6dfoZ.js +138 -0
- package/dist/chunks/{schemas-CzTvbXb6.js → schemas-p_aRcMC1.js} +30 -14
- package/dist/chunks/server-CCc7fil4.js +410 -0
- package/dist/chunks/src--HZrH1U9.js +568 -0
- package/dist/chunks/standard-failures-CLjxS2ea.js +74 -0
- package/dist/chunks/{telemetry-BTwB68m5.js → telemetry-C3LfZcOB.js} +32 -11
- package/dist/chunks/{types-BWxDd3tY.d.ts → types-BQYB4Ads.d.ts} +998 -337
- package/dist/chunks/{validation-r-sgmsqb.js → validation-fTohBT6R.js} +69 -28
- package/dist/chunks/workers-types-iONp32T4.d.ts +143 -0
- package/dist/chunks/yaml-Dk2L24yQ.js +74 -0
- package/dist/diagnostics.d.ts +6 -4
- package/dist/diagnostics.js +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +2 -125
- package/dist/http-paths.d.ts +1 -1
- package/dist/http-paths.js +1 -197
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -10
- package/dist/internals.d.ts +1 -1
- package/dist/internals.js +5 -3
- package/dist/mcp/index.d.ts +3 -2
- package/dist/mcp/index.js +5 -387
- package/dist/postgres/index.d.ts +25 -8
- package/dist/postgres/index.js +17 -8
- package/dist/project/config.d.ts +139 -0
- package/dist/project/config.js +196 -0
- package/dist/project/index.d.ts +17 -4
- package/dist/project/index.js +44 -9
- package/dist/projection.d.ts +14 -13
- package/dist/projection.js +8 -32
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +2 -2
- package/dist/standard-failures.d.ts +2 -89
- package/dist/standard-failures.js +1 -72
- package/dist/tooling/cli.js +151 -107
- package/dist/tooling/testing.js +2 -2
- package/dist/vite/cloudflare-workers.js +25 -0
- package/dist/vite/index.d.ts +157 -0
- package/dist/vite/index.js +1477 -0
- package/dist/webhooks.d.ts +12 -10
- package/dist/webhooks.js +26 -12
- package/dist/workers/runtime.d.ts +1 -1
- package/dist/workers/runtime.js +1 -1
- package/package.json +30 -22
- package/skills/maximus/SKILL.md +165 -69
- package/skills/maximus/references/deploying.md +73 -0
- package/skills/maximus/references/errors-and-results.md +114 -55
- package/skills/maximus/references/project.md +202 -0
- package/skills/maximus/references/routes-and-tools.md +256 -0
- package/skills/maximus/references/testing.md +137 -50
- package/skills/maximus/references/transports.md +113 -100
- package/skills/maximus/references/writing-code.md +84 -0
- package/templates/mcp/mcp/instructions.md.template +2 -0
- package/templates/mcp/routes/v1/greeting.get.ts.template +12 -0
- package/templates/mcp/tests/mcp.test.ts.template +36 -0
- package/templates/project/.agents/skills/project/SKILL.md.template +21 -12
- package/templates/project/.github/workflows/ci.yml.template +4 -1
- package/templates/project/CLAUDE.md.template +41 -22
- package/templates/project/README.md.template +54 -47
- package/templates/project/middleware/10-response.ts.template +16 -0
- package/templates/project/package.json.template +16 -8
- package/templates/project/pages/index.ts.template +2 -4
- package/templates/project/routes/v1/greeting.get.ts.template +10 -0
- package/templates/project/routes/v1/greeting.post.ts.template +12 -0
- package/templates/project/tests/greeting.test.ts.template +45 -0
- package/templates/project/tsconfig.json.template +8 -5
- package/templates/project/vite.config.ts.template +15 -7
- package/templates/web/app/main.tsx.template +16 -0
- package/templates/web/app/root.tsx.template +17 -0
- package/templates/web/app/routes/index.tsx.template +9 -0
- package/templates/web/index.html.template +12 -0
- package/templates/web/package.json.template +12 -0
- package/templates/web/tsconfig.json.template +7 -0
- package/templates/web/vite.config.ts.template +22 -0
- package/dist/chunks/execution-B-yy4C7N.js +0 -691
- package/dist/chunks/prepare-project-zi106pWF.js +0 -146
- package/dist/chunks/record-DY-lX9w1.js +0 -34
- package/dist/chunks/src-DPSpGNnT.js +0 -1164
- package/dist/client/client.d.ts +0 -129
- package/dist/client/client.js +0 -321
- package/dist/tooling/vite.d.ts +0 -3
- package/dist/tooling/vite.js +0 -44
- package/skills/maximus/references/adding-an-operation.md +0 -179
- package/skills/maximus/references/building-a-service.md +0 -167
- package/skills/maximus/references/migration-from-v2.md +0 -62
- package/skills/maximus/references/migration-to-v5.md +0 -37
- package/skills/maximus/references/publishing-and-verification.md +0 -39
- package/templates/project/cloudflare.config.ts.template +0 -24
- package/templates/project/routes/v1/greeting.ts.template +0 -22
- package/templates/project/src/app.ts.template +0 -2
- package/templates/project/src/application.ts.template +0 -26
- package/templates/project/src/index.ts.template +0 -3
- package/templates/project/src/worker.ts.template +0 -6
- package/templates/service/.agents/skills/project/SKILL.md.template +0 -10
- package/templates/service/.github/workflows/ci.yml.template +0 -21
- package/templates/service/.gitignore.template +0 -9
- package/templates/service/CLAUDE.md.template +0 -5
- package/templates/service/README.md.template +0 -45
- package/templates/service/cloudflare.config.ts.template +0 -30
- package/templates/service/package.json.template +0 -36
- package/templates/service/src/app.ts.template +0 -30
- package/templates/service/src/index.ts.template +0 -13
- package/templates/service/tests/contract.test.ts.template +0 -12
- package/templates/service/tsconfig.json.template +0 -16
- package/templates/service/vite.config.ts.template +0 -13
- package/templates/service/vitest.config.ts.template +0 -10
package/README.md
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
1
|
# @arbol-ai/maximus
|
|
2
2
|
|
|
3
|
-
Maximus
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Maximus builds organization-scoped APIs on Cloudflare Workers that people and AI agents call alike. Each
|
|
4
|
+
route is a file that declares its handler and its contract once, and the same Worker serves it over HTTP
|
|
5
|
+
with an OpenAPI 3.1 document, as an MCP tool when the route names one, and over native RPC to the Workers
|
|
6
|
+
you allow.
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
bun
|
|
9
|
+
bun create maximus my-api
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
async () => ok({ notes: [] })
|
|
37
|
-
)
|
|
38
|
-
.build();
|
|
13
|
+
// routes/v1/notes/[noteId].get.ts
|
|
14
|
+
import { defineHandler, UuidSchema } from '@arbol-ai/maximus';
|
|
15
|
+
|
|
16
|
+
import { NoteSchema } from '#src/notes.ts';
|
|
17
|
+
|
|
18
|
+
/** GET /api/v1/notes/{noteId}, also the MCP tool get_note: one note of the caller's organization. */
|
|
19
|
+
export default defineHandler(
|
|
20
|
+
async ({ input, notes, fail }) => {
|
|
21
|
+
const note = await notes.find(input.noteId);
|
|
22
|
+
if (!note) {
|
|
23
|
+
return fail('NOTE_NOT_FOUND');
|
|
24
|
+
}
|
|
25
|
+
return note;
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
description: 'Read one note of the organization by its id.',
|
|
29
|
+
input: { noteId: UuidSchema },
|
|
30
|
+
output: NoteSchema,
|
|
31
|
+
failures: ['NOTE_NOT_FOUND'],
|
|
32
|
+
mcp: { name: 'get_note' },
|
|
33
|
+
}
|
|
34
|
+
);
|
|
39
35
|
```
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
`maximus`
|
|
46
|
-
|
|
37
|
+
This package is the framework. Its root entry holds routes and operations, TypeBox schemas, tokens and
|
|
38
|
+
scopes, the error catalog and the HTTP handler with its OpenAPI document; each optional capability is an
|
|
39
|
+
entry of its own, such as `@arbol-ai/maximus/mcp`, `/workers` or `/postgres`, and a Worker carries only the
|
|
40
|
+
entries it imports. The package installs the `maximus` command and ships the Maximus skill for coding agents
|
|
41
|
+
in `skills/maximus/`. `maximus()` from `@arbol-ai/maximus/vite` makes `vite.config.ts` a project's one
|
|
42
|
+
configuration.
|
|
47
43
|
|
|
48
44
|
- [Getting started](https://github.com/getarbol/maximus/blob/main/docs/getting-started.md)
|
|
49
45
|
- [Concepts](https://github.com/getarbol/maximus/blob/main/docs/concepts.md)
|
|
50
|
-
- [
|
|
46
|
+
- [Package exports](https://github.com/getarbol/maximus/blob/main/docs/reference/exports.md), every entry
|
|
47
|
+
- [CLI](https://github.com/getarbol/maximus/blob/main/docs/reference/cli.md), the `maximus` command
|
|
48
|
+
- [All documentation](https://github.com/getarbol/maximus/blob/main/docs/README.md)
|
|
51
49
|
|
|
52
50
|
Released under the MIT License.
|
package/bin/maximus.js
ADDED
package/config/oxfmt.mjs
CHANGED
package/config/oxlint.mjs
CHANGED
|
@@ -98,6 +98,16 @@ export default defineConfig({
|
|
|
98
98
|
// Node tooling imports stay explicit, and immutable option defaults stay local.
|
|
99
99
|
'unicorn/import-style': 'off',
|
|
100
100
|
'unicorn/no-object-as-default-parameter': 'off',
|
|
101
|
+
// A route file names its path parameter as its input field: `[taskId].get.ts`.
|
|
102
|
+
'unicorn/filename-case': [
|
|
103
|
+
'error',
|
|
104
|
+
{
|
|
105
|
+
case: 'kebabCase',
|
|
106
|
+
ignore: [
|
|
107
|
+
String.raw`^\[[a-z][A-Za-z0-9]*\](?:\.(?:get|post|put|patch|delete))?(?:\.(?:dev|prod))?\.[cm]?[jt]sx?$`,
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
101
111
|
},
|
|
102
112
|
overrides: [
|
|
103
113
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sn as Observer } from "../chunks/types-BQYB4Ads.js";
|
|
2
2
|
import { Static } from "@sinclair/typebox";
|
|
3
3
|
/** An analytics event: the allowlisted metadata of one operation call, flattened, with an id of its own. */
|
|
4
4
|
export declare const ExecutionEventSchema: import("@sinclair/typebox").TObject<{
|
|
@@ -18,15 +18,27 @@ export declare const ExecutionEventSchema: import("@sinclair/typebox").TObject<{
|
|
|
18
18
|
}>;
|
|
19
19
|
/** An analytics event. */
|
|
20
20
|
export type ExecutionEvent = Static<typeof ExecutionEventSchema>;
|
|
21
|
-
/**
|
|
22
|
-
export interface
|
|
21
|
+
/** What `analytics()` takes: where events go, whether it records, and how events name the actor. */
|
|
22
|
+
export interface AnalyticsOptions<E> {
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Whether events are recorded: a boolean, or a function that decides for each env; on by default. A
|
|
25
|
+
* function that throws turns recording off for that call.
|
|
25
26
|
*/
|
|
26
|
-
record: (event: ExecutionEvent) => Promise<Result<null, Failure>>;
|
|
27
|
-
}
|
|
28
|
-
/** Safe metadata projection; no request or response bodies reach this sink. */
|
|
29
|
-
export declare function analytics<E>(options: {
|
|
30
27
|
enabled?: boolean | ((env: E) => boolean);
|
|
28
|
+
/** Keeps one event in the application's store; an `ok: false` result counts as a delivery failure. */
|
|
31
29
|
record: (env: E, event: ExecutionEvent) => Promise<unknown>;
|
|
32
|
-
|
|
30
|
+
/**
|
|
31
|
+
* How an event names its actor. `pseudonymous`, the default, records the hex SHA-256 of the organization id
|
|
32
|
+
* and the actor id: distinct actors stay countable, and an identity provider that uses email addresses as
|
|
33
|
+
* subjects does not put them in analytics. `id` records the actor id as the token states it.
|
|
34
|
+
*/
|
|
35
|
+
actor?: 'pseudonymous' | 'id';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An observer that records one allowlisted event for each operation call: who called which operation, over
|
|
39
|
+
* which surface, how it ended and how long it took. No input, output, credential or message ever reaches
|
|
40
|
+
* it. `.build()` and `defineErrors` refuse a service name, an operation name or a failure code the event
|
|
41
|
+
* could not carry; an event that still does not match `ExecutionEventSchema` is never recorded: the
|
|
42
|
+
* observer fails, and diagnostics report it.
|
|
43
|
+
*/
|
|
44
|
+
export declare function analytics<E>(options: AnalyticsOptions<E>): Observer<E>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { i as UuidSchema, n as OrganizationIdSchema } from "../chunks/schemas-
|
|
2
|
-
import { a as telemetryEnabled } from "../chunks/telemetry-
|
|
1
|
+
import { i as UuidSchema, n as OrganizationIdSchema } from "../chunks/schemas-p_aRcMC1.js";
|
|
2
|
+
import { a as telemetryEnabled } from "../chunks/telemetry-C3LfZcOB.js";
|
|
3
3
|
import { Type } from "@sinclair/typebox";
|
|
4
|
+
import { Value } from "@sinclair/typebox/value";
|
|
4
5
|
|
|
5
6
|
// src/analytics/analytics.ts
|
|
6
7
|
/**
|
|
@@ -34,16 +35,28 @@ const ExecutionEventSchema = Type.Object({
|
|
|
34
35
|
outcome: Type.Union([Type.Literal("success"), Type.Literal("failure")]),
|
|
35
36
|
errorCode: Type.Union([Type.String({ pattern: "^[A-Z][A-Z0-9_]{0,80}$" }), Type.Null()])
|
|
36
37
|
}, { additionalProperties: false });
|
|
37
|
-
/**
|
|
38
|
+
/** The hex SHA-256 of an actor within its organization. */
|
|
39
|
+
async function pseudonym(organizationId, actorId) {
|
|
40
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${organizationId}:${actorId}`));
|
|
41
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* An observer that records one allowlisted event for each operation call: who called which operation, over
|
|
45
|
+
* which surface, how it ended and how long it took. No input, output, credential or message ever reaches
|
|
46
|
+
* it. `.build()` and `defineErrors` refuse a service name, an operation name or a failure code the event
|
|
47
|
+
* could not carry; an event that still does not match `ExecutionEventSchema` is never recorded: the
|
|
48
|
+
* observer fails, and diagnostics report it.
|
|
49
|
+
*/
|
|
38
50
|
function analytics(options) {
|
|
39
51
|
return { async execution(observation, env) {
|
|
40
52
|
if (!telemetryEnabled(options, env)) return;
|
|
53
|
+
const { organizationId, actorId } = observation.principal;
|
|
41
54
|
const event = {
|
|
42
55
|
id: crypto.randomUUID(),
|
|
43
56
|
service: observation.service,
|
|
44
57
|
operation: observation.operation,
|
|
45
|
-
organizationId
|
|
46
|
-
actorId:
|
|
58
|
+
organizationId,
|
|
59
|
+
actorId: options.actor === "id" ? actorId : await pseudonym(organizationId, actorId),
|
|
47
60
|
actorKind: observation.principal.actorKind,
|
|
48
61
|
requestId: observation.principal.requestId,
|
|
49
62
|
traceId: observation.traceId,
|
|
@@ -53,6 +66,7 @@ function analytics(options) {
|
|
|
53
66
|
outcome: observation.outcome,
|
|
54
67
|
errorCode: observation.errorCode
|
|
55
68
|
};
|
|
69
|
+
if (!Value.Check(ExecutionEventSchema, event)) throw new TypeError("The analytics event does not match ExecutionEventSchema.");
|
|
56
70
|
const result = await options.record(env, event);
|
|
57
71
|
if (result && typeof result === "object" && "ok" in result && result.ok === false) throw new Error("Analytics sink rejected the event.");
|
|
58
72
|
} };
|
package/dist/body.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as readBodyText, d as readJsonResponse, f as retryAfterSeconds, g as readBodyBytes, h as HttpBodyFailureReason, l as isJsonMediaType, m as HttpBodyFailure, p as BodyReadOptions, u as readJsonBody } from "./chunks/types-BQYB4Ads.js";
|
|
2
2
|
export { type BodyReadOptions, type HttpBodyFailure, type HttpBodyFailureReason, isJsonMediaType, readBodyBytes, readBodyText, readJsonBody, readJsonResponse, retryAfterSeconds };
|
package/dist/body.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as readBodyBytes, r as readBodyText } from "./chunks/body-
|
|
2
|
-
import { a as retryAfterSeconds, i as readJsonResponse, r as readJsonBody, t as isJsonMediaType } from "./chunks/json-
|
|
1
|
+
import { n as readBodyBytes, r as readBodyText } from "./chunks/body-DOIHwIIl.js";
|
|
2
|
+
import { a as retryAfterSeconds, i as readJsonResponse, r as readJsonBody, t as isJsonMediaType } from "./chunks/json-B14evE6-.js";
|
|
3
3
|
|
|
4
4
|
export { isJsonMediaType, readBodyBytes, readBodyText, readJsonBody, readJsonResponse, retryAfterSeconds };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { n as checkProjectFolder } from "./project-files-C0OX7MQQ.js";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readlinkSync, symlinkSync } from "node:fs";
|
|
3
|
+
import { join, relative, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
// src/tooling/internal/agent-skills.ts
|
|
6
|
+
/**
|
|
7
|
+
* The Maximus skill where coding agents look for skills: `.agents/skills/maximus`, `.claude/skills/maximus`
|
|
8
|
+
* and `.codex/skills/maximus` link to the copy installed in `node_modules/@arbol-ai/maximus/skills/maximus`,
|
|
9
|
+
* so agents always read the skill of the release the project runs.
|
|
10
|
+
*/
|
|
11
|
+
/** The installed skill, from the project's root. */
|
|
12
|
+
const INSTALLED = "node_modules/@arbol-ai/maximus/skills/maximus";
|
|
13
|
+
/** The folders coding agents read a project's skills from. */
|
|
14
|
+
const HARNESSES = [
|
|
15
|
+
".agents",
|
|
16
|
+
".claude",
|
|
17
|
+
".codex"
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Links the installed Maximus skill into each agent's skills folder of the project at `directory`, and
|
|
21
|
+
* returns the links it created. A link already in place is kept; anything else at a link's path is refused,
|
|
22
|
+
* never replaced, and so is an agent's folder or skills folder that is a symlink. A link may point at nothing
|
|
23
|
+
* until `bun install` installs the package.
|
|
24
|
+
*/
|
|
25
|
+
function linkAgentSkills(directory) {
|
|
26
|
+
const root = resolve(directory);
|
|
27
|
+
const planned = HARNESSES.map((harness) => {
|
|
28
|
+
const folder = join(root, harness, "skills");
|
|
29
|
+
return {
|
|
30
|
+
folder,
|
|
31
|
+
link: join(folder, "maximus"),
|
|
32
|
+
target: relative(folder, join(root, INSTALLED))
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
for (const { folder, link, target } of planned) {
|
|
36
|
+
checkProjectFolder(root, folder);
|
|
37
|
+
const present = lstatSync(link, { throwIfNoEntry: false });
|
|
38
|
+
if (present && !(present.isSymbolicLink() && readlinkSync(link) === target)) throw new TypeError(`${relative(root, link)} exists and is not the Maximus skill link; move it first.`);
|
|
39
|
+
}
|
|
40
|
+
const created = [];
|
|
41
|
+
for (const { folder, link, target } of planned) if (!existsSync(link) && !lstatSync(link, { throwIfNoEntry: false })) {
|
|
42
|
+
mkdirSync(folder, { recursive: true });
|
|
43
|
+
symlinkSync(target, link);
|
|
44
|
+
created.push(relative(root, link));
|
|
45
|
+
}
|
|
46
|
+
return created;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { linkAgentSkills as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/internal/body.ts
|
|
2
|
-
/**
|
|
2
|
+
/** Every reason a bounded read can fail with: the values of a body failure's `data.reason`. */
|
|
3
3
|
const HTTP_BODY_FAILURES = [
|
|
4
4
|
"too_large",
|
|
5
5
|
"invalid_length",
|
|
@@ -9,7 +9,10 @@ const HTTP_BODY_FAILURES = [
|
|
|
9
9
|
"aborted",
|
|
10
10
|
"read_failed"
|
|
11
11
|
];
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The body failure for a reason: `HTTP_BODY_INVALID`, with the reason as its only data and nothing of the
|
|
14
|
+
* body. A reason outside `HTTP_BODY_FAILURES` throws a TypeError.
|
|
15
|
+
*/
|
|
13
16
|
function httpBodyFailure(reason) {
|
|
14
17
|
if (!HTTP_BODY_FAILURES.includes(reason)) throw new TypeError("Invalid HTTP body reason");
|
|
15
18
|
return {
|
|
@@ -20,9 +23,11 @@ function httpBodyFailure(reason) {
|
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
+
* Reads a request's or a response's body as bytes, at most `maxBytes` of them, chunked bodies included, and
|
|
27
|
+
* answers them unchanged, as a signature check needs them; an absent body is no bytes. A `content-length`
|
|
28
|
+
* that is malformed or above the limit is refused before reading. Every expected failure is a result
|
|
29
|
+
* (`too_large`, `invalid_length`, `aborted` or `read_failed`), and a refused body is cancelled without
|
|
30
|
+
* waiting for the other side.
|
|
26
31
|
*/
|
|
27
32
|
async function readBodyBytes(source, options) {
|
|
28
33
|
if (!Number.isSafeInteger(options.maxBytes) || options.maxBytes < 1) throw new RangeError("Invalid body byte limit");
|
|
@@ -60,7 +65,6 @@ async function readBodyBytes(source, options) {
|
|
|
60
65
|
let size = 0;
|
|
61
66
|
try {
|
|
62
67
|
while (true) {
|
|
63
|
-
if (options.signal?.aborted) return fail("aborted");
|
|
64
68
|
const chunk = await reader.read();
|
|
65
69
|
if (options.signal?.aborted) return fail("aborted");
|
|
66
70
|
if (chunk.done) break;
|
|
@@ -85,7 +89,10 @@ async function readBodyBytes(source, options) {
|
|
|
85
89
|
reader.releaseLock();
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Reads a body as `readBodyBytes` does and decodes it as UTF-8. Invalid UTF-8 fails as `invalid_utf8`,
|
|
94
|
+
* unless `fatalUtf8: false` replaces it with U+FFFD, as a provider that signs its decoded text may require.
|
|
95
|
+
*/
|
|
89
96
|
async function readBodyText(source, options) {
|
|
90
97
|
const bytes = await readBodyBytes(source, options);
|
|
91
98
|
if (!bytes.ok) return bytes;
|
|
@@ -7,14 +7,17 @@
|
|
|
7
7
|
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
8
|
/** A Cloudflare ray id, with its optional data center suffix. */
|
|
9
9
|
const RAY_PATTERN = /^[0-9a-f]{16}(?:-[A-Z]{3})?$/;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Whether a value is a request id: a UUID or a Cloudflare ray id. A request id correlates diagnostics; never
|
|
12
|
+
* use one as authority or as a deduplication key.
|
|
13
|
+
*/
|
|
11
14
|
function isRequestId(value) {
|
|
12
15
|
return typeof value === "string" && (UUID_PATTERN.test(value) || RAY_PATTERN.test(value));
|
|
13
16
|
}
|
|
14
17
|
/**
|
|
15
|
-
*
|
|
16
|
-
* Cloudflare edge or a
|
|
17
|
-
*
|
|
18
|
+
* A request id: `trustedEdgeRay` when it is a valid request id, otherwise a random UUID. Pass a ray id only
|
|
19
|
+
* from the Cloudflare edge or from a caller authenticated separately, never an `x-request-id` or `cf-ray`
|
|
20
|
+
* value an untrusted caller sent.
|
|
18
21
|
*/
|
|
19
22
|
function createRequestId(trustedEdgeRay) {
|
|
20
23
|
return isRequestId(trustedEdgeRay) ? trustedEdgeRay : crypto.randomUUID();
|
|
@@ -31,7 +34,7 @@ function parseTraceParent(value) {
|
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* The correlation to persist with durable work: a valid request id and, when it parses, the originating
|
|
34
|
-
* `traceparent`.
|
|
37
|
+
* `traceparent`. A request id that is not one throws a TypeError.
|
|
35
38
|
*/
|
|
36
39
|
function durableCorrelation(requestId, originTraceParent) {
|
|
37
40
|
if (!isRequestId(requestId)) throw new TypeError("Invalid correlation id");
|