@zauso-ai/capstan-core 0.1.2
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/api.d.ts +19 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +49 -0
- package/dist/api.js.map +1 -0
- package/dist/approval.d.ts +41 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +58 -0
- package/dist/approval.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +17 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +10 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +22 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +25 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +29 -0
- package/dist/middleware.js.map +1 -0
- package/dist/policy.d.ts +22 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +45 -0
- package/dist/policy.js.map +1 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +276 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/verify.d.ts +57 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +837 -0
- package/dist/verify.js.map +1 -0
- package/package.json +45 -0
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { APIDefinition } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define a typed API route handler.
|
|
4
|
+
*
|
|
5
|
+
* The returned definition wraps the original handler so that:
|
|
6
|
+
* 1. Input is validated against the Zod `input` schema (if provided).
|
|
7
|
+
* 2. The handler runs with the validated input.
|
|
8
|
+
* 3. Output is validated against the Zod `output` schema (if provided).
|
|
9
|
+
*
|
|
10
|
+
* The definition object is also stored for introspection by the agent
|
|
11
|
+
* manifest system (see `getAPIRegistry()`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function defineAPI<TInput = unknown, TOutput = unknown>(def: APIDefinition<TInput, TOutput>): APIDefinition<TInput, TOutput>;
|
|
14
|
+
/**
|
|
15
|
+
* Return all API definitions registered via `defineAPI()`.
|
|
16
|
+
* Primarily consumed by `createCapstanApp` when building route metadata.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getAPIRegistry(): ReadonlyArray<APIDefinition>;
|
|
19
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC3D,GAAG,EAAE,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAiChC;AAQD;;;GAGG;AACH,wBAAgB,cAAc,IAAI,aAAa,CAAC,aAAa,CAAC,CAE7D"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define a typed API route handler.
|
|
3
|
+
*
|
|
4
|
+
* The returned definition wraps the original handler so that:
|
|
5
|
+
* 1. Input is validated against the Zod `input` schema (if provided).
|
|
6
|
+
* 2. The handler runs with the validated input.
|
|
7
|
+
* 3. Output is validated against the Zod `output` schema (if provided).
|
|
8
|
+
*
|
|
9
|
+
* The definition object is also stored for introspection by the agent
|
|
10
|
+
* manifest system (see `getAPIRegistry()`).
|
|
11
|
+
*/
|
|
12
|
+
export function defineAPI(def) {
|
|
13
|
+
const wrappedHandler = async (args) => {
|
|
14
|
+
// --- validate input ---------------------------------------------------
|
|
15
|
+
let validatedInput = args.input;
|
|
16
|
+
if (def.input) {
|
|
17
|
+
validatedInput = def.input.parse(args.input);
|
|
18
|
+
}
|
|
19
|
+
// --- run handler ------------------------------------------------------
|
|
20
|
+
const result = await def.handler({
|
|
21
|
+
input: validatedInput,
|
|
22
|
+
ctx: args.ctx,
|
|
23
|
+
});
|
|
24
|
+
// --- validate output --------------------------------------------------
|
|
25
|
+
if (def.output) {
|
|
26
|
+
return def.output.parse(result);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
const wrapped = {
|
|
31
|
+
...def,
|
|
32
|
+
handler: wrappedHandler,
|
|
33
|
+
};
|
|
34
|
+
// Register for introspection.
|
|
35
|
+
apiRegistry.push(wrapped);
|
|
36
|
+
return wrapped;
|
|
37
|
+
}
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
// Internal registry — used by createCapstanApp to build the agent manifest.
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
const apiRegistry = [];
|
|
42
|
+
/**
|
|
43
|
+
* Return all API definitions registered via `defineAPI()`.
|
|
44
|
+
* Primarily consumed by `createCapstanApp` when building route metadata.
|
|
45
|
+
*/
|
|
46
|
+
export function getAPIRegistry() {
|
|
47
|
+
return apiRegistry;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CACvB,GAAmC;IAEnC,MAAM,cAAc,GAAG,KAAK,EAC1B,IAA6B,EACX,EAAE;QACpB,yEAAyE;QACzE,IAAI,cAAc,GAAW,IAAI,CAAC,KAAK,CAAC;QACxC,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;YACd,cAAc,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAW,CAAC;QACzD,CAAC;QAED,yEAAyE;QACzE,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC;YAC/B,KAAK,EAAE,cAAc;YACrB,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAC,CAAC;QAEH,yEAAyE;QACzE,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YACf,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAY,CAAC;QAC7C,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,OAAO,GAAmC;QAC9C,GAAG,GAAG;QACN,OAAO,EAAE,cAAc;KACxB,CAAC;IAEF,8BAA8B;IAC9B,WAAW,CAAC,IAAI,CAAC,OAAwB,CAAC,CAAC;IAE3C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAE9E,MAAM,WAAW,GAAoB,EAAE,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface PendingApproval {
|
|
2
|
+
id: string;
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
input: unknown;
|
|
6
|
+
policy: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
status: "pending" | "approved" | "denied";
|
|
9
|
+
createdAt: string;
|
|
10
|
+
resolvedAt?: string;
|
|
11
|
+
resolvedBy?: string;
|
|
12
|
+
result?: unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a new pending approval and store it. Returns the created approval.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createApproval(opts: {
|
|
18
|
+
method: string;
|
|
19
|
+
path: string;
|
|
20
|
+
input: unknown;
|
|
21
|
+
policy: string;
|
|
22
|
+
reason: string;
|
|
23
|
+
}): PendingApproval;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve a single approval by ID, or undefined if not found.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getApproval(id: string): PendingApproval | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* List all approvals, optionally filtered by status.
|
|
30
|
+
*/
|
|
31
|
+
export declare function listApprovals(status?: "pending" | "approved" | "denied"): PendingApproval[];
|
|
32
|
+
/**
|
|
33
|
+
* Resolve a pending approval as approved or denied.
|
|
34
|
+
* Returns the updated approval, or undefined if not found.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveApproval(id: string, decision: "approved" | "denied", resolvedBy?: string): PendingApproval | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Remove all approvals from the in-memory store.
|
|
39
|
+
*/
|
|
40
|
+
export declare function clearApprovals(): void;
|
|
41
|
+
//# sourceMappingURL=approval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval.d.ts","sourceRoot":"","sources":["../src/approval.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAKD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,eAAe,CAclB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAEnE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,QAAQ,GACzC,eAAe,EAAE,CAInB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,UAAU,GAAG,QAAQ,EAC/B,UAAU,CAAC,EAAE,MAAM,GAClB,eAAe,GAAG,SAAS,CAS7B;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAErC"}
|
package/dist/approval.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
/** In-memory store for pending approvals (dev mode). */
|
|
3
|
+
const approvals = new Map();
|
|
4
|
+
/**
|
|
5
|
+
* Create a new pending approval and store it. Returns the created approval.
|
|
6
|
+
*/
|
|
7
|
+
export function createApproval(opts) {
|
|
8
|
+
const id = randomUUID();
|
|
9
|
+
const approval = {
|
|
10
|
+
id,
|
|
11
|
+
method: opts.method,
|
|
12
|
+
path: opts.path,
|
|
13
|
+
input: opts.input,
|
|
14
|
+
policy: opts.policy,
|
|
15
|
+
reason: opts.reason,
|
|
16
|
+
status: "pending",
|
|
17
|
+
createdAt: new Date().toISOString(),
|
|
18
|
+
};
|
|
19
|
+
approvals.set(id, approval);
|
|
20
|
+
return approval;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Retrieve a single approval by ID, or undefined if not found.
|
|
24
|
+
*/
|
|
25
|
+
export function getApproval(id) {
|
|
26
|
+
return approvals.get(id);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* List all approvals, optionally filtered by status.
|
|
30
|
+
*/
|
|
31
|
+
export function listApprovals(status) {
|
|
32
|
+
const all = Array.from(approvals.values());
|
|
33
|
+
if (status === undefined)
|
|
34
|
+
return all;
|
|
35
|
+
return all.filter((a) => a.status === status);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve a pending approval as approved or denied.
|
|
39
|
+
* Returns the updated approval, or undefined if not found.
|
|
40
|
+
*/
|
|
41
|
+
export function resolveApproval(id, decision, resolvedBy) {
|
|
42
|
+
const approval = approvals.get(id);
|
|
43
|
+
if (!approval)
|
|
44
|
+
return undefined;
|
|
45
|
+
approval.status = decision;
|
|
46
|
+
approval.resolvedAt = new Date().toISOString();
|
|
47
|
+
if (resolvedBy !== undefined) {
|
|
48
|
+
approval.resolvedBy = resolvedBy;
|
|
49
|
+
}
|
|
50
|
+
return approval;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Remove all approvals from the in-memory store.
|
|
54
|
+
*/
|
|
55
|
+
export function clearApprovals() {
|
|
56
|
+
approvals.clear();
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=approval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../src/approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAgBzC,wDAAwD;AACxD,MAAM,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAM9B;IACC,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;IACxB,MAAM,QAAQ,GAAoB;QAChC,EAAE;QACF,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC;IACF,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC5B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,EAAU;IACpC,OAAO,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA0C;IAE1C,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3C,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,GAAG,CAAC;IACrC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,EAAU,EACV,QAA+B,EAC/B,UAAmB;IAEnB,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACnC,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;IAC3B,QAAQ,CAAC,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/C,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IACnC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,SAAS,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CapstanConfig } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define the app-level Capstan configuration.
|
|
4
|
+
*
|
|
5
|
+
* This is a pass-through identity function that provides type-checking and
|
|
6
|
+
* editor auto-complete for the config object. The returned value is the
|
|
7
|
+
* same object that was passed in.
|
|
8
|
+
*/
|
|
9
|
+
export declare function defineConfig(config: CapstanConfig): CapstanConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Read an environment variable, returning an empty string if it is not set.
|
|
12
|
+
*/
|
|
13
|
+
export declare function env(key: string): string;
|
|
14
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAEjE;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define the app-level Capstan configuration.
|
|
3
|
+
*
|
|
4
|
+
* This is a pass-through identity function that provides type-checking and
|
|
5
|
+
* editor auto-complete for the config object. The returned value is the
|
|
6
|
+
* same object that was passed in.
|
|
7
|
+
*/
|
|
8
|
+
export function defineConfig(config) {
|
|
9
|
+
return config;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Read an environment variable, returning an empty string if it is not set.
|
|
13
|
+
*/
|
|
14
|
+
export function env(key) {
|
|
15
|
+
return process.env[key] ?? "";
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAqB;IAChD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,GAAW;IAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context as HonoContext } from "hono";
|
|
2
|
+
import type { CapstanContext } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build a CapstanContext from the raw Hono request context.
|
|
5
|
+
*
|
|
6
|
+
* Auth defaults to anonymous. The real auth layer (@zauso-ai/capstan-auth) replaces
|
|
7
|
+
* the auth object via middleware before any handler runs.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createContext(honoCtx: HonoContext): CapstanContext;
|
|
10
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,EAAsB,cAAc,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAkBlE"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a CapstanContext from the raw Hono request context.
|
|
3
|
+
*
|
|
4
|
+
* Auth defaults to anonymous. The real auth layer (@zauso-ai/capstan-auth) replaces
|
|
5
|
+
* the auth object via middleware before any handler runs.
|
|
6
|
+
*/
|
|
7
|
+
export function createContext(honoCtx) {
|
|
8
|
+
const anonymousAuth = {
|
|
9
|
+
isAuthenticated: false,
|
|
10
|
+
type: "anonymous",
|
|
11
|
+
permissions: [],
|
|
12
|
+
};
|
|
13
|
+
// If middleware has already attached auth info, use it; otherwise anonymous.
|
|
14
|
+
const existingAuth = honoCtx.get("capstanAuth");
|
|
15
|
+
return {
|
|
16
|
+
auth: existingAuth ?? anonymousAuth,
|
|
17
|
+
request: honoCtx.req.raw,
|
|
18
|
+
env: process.env,
|
|
19
|
+
honoCtx,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAAoB;IAChD,MAAM,aAAa,GAAuB;QACxC,eAAe,EAAE,KAAK;QACtB,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,EAAE;KAChB,CAAC;IAEF,6EAA6E;IAC7E,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAEjC,CAAC;IAEd,OAAO;QACL,IAAI,EAAE,YAAY,IAAI,aAAa;QACnC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG;QACxB,GAAG,EAAE,OAAO,CAAC,GAAyC;QACtD,OAAO;KACR,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { defineAPI, getAPIRegistry } from "./api.js";
|
|
2
|
+
export { defineMiddleware } from "./middleware.js";
|
|
3
|
+
export { definePolicy, enforcePolicies } from "./policy.js";
|
|
4
|
+
export { defineConfig, env } from "./config.js";
|
|
5
|
+
export { createCapstanApp } from "./server.js";
|
|
6
|
+
export { createContext } from "./context.js";
|
|
7
|
+
export { createApproval, getApproval, listApprovals, resolveApproval, clearApprovals, } from "./approval.js";
|
|
8
|
+
export type { PendingApproval } from "./approval.js";
|
|
9
|
+
export type { CapstanApp } from "./server.js";
|
|
10
|
+
export type { APIDefinition, APIHandlerInput, CapstanAuthContext, CapstanConfig, CapstanContext, HttpMethod, MiddlewareDefinition, PolicyCheckResult, PolicyDefinition, PolicyEffect, RouteMetadata, } from "./types.js";
|
|
11
|
+
export { verifyCapstanApp, renderRuntimeVerifyText } from "./verify.js";
|
|
12
|
+
export type { VerifyReport, VerifyDiagnostic, VerifyStep } from "./verify.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,WAAW,EACX,aAAa,EACb,eAAe,EACf,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,YAAY,EACV,aAAa,EACb,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACxE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Public API ----------------------------------------------------------------
|
|
2
|
+
export { defineAPI, getAPIRegistry } from "./api.js";
|
|
3
|
+
export { defineMiddleware } from "./middleware.js";
|
|
4
|
+
export { definePolicy, enforcePolicies } from "./policy.js";
|
|
5
|
+
export { defineConfig, env } from "./config.js";
|
|
6
|
+
export { createCapstanApp } from "./server.js";
|
|
7
|
+
export { createContext } from "./context.js";
|
|
8
|
+
export { createApproval, getApproval, listApprovals, resolveApproval, clearApprovals, } from "./approval.js";
|
|
9
|
+
export { verifyCapstanApp, renderRuntimeVerifyText } from "./verify.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAE9E,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,WAAW,EACX,aAAa,EACb,eAAe,EACf,cAAc,GACf,MAAM,eAAe,CAAC;AAoBvB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MiddlewareDefinition } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define a Capstan middleware.
|
|
4
|
+
*
|
|
5
|
+
* Accepts either a full `MiddlewareDefinition` object (with optional `name`)
|
|
6
|
+
* or a bare handler function, which is wrapped into a definition with no name.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const logging = defineMiddleware({
|
|
10
|
+
* name: "logging",
|
|
11
|
+
* handler: async ({ request, ctx, next }) => {
|
|
12
|
+
* console.log(request.method, request.url);
|
|
13
|
+
* return next();
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // shorthand
|
|
18
|
+
* const logging2 = defineMiddleware(async ({ request, ctx, next }) => {
|
|
19
|
+
* console.log(request.method, request.url);
|
|
20
|
+
* return next();
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function defineMiddleware(def: MiddlewareDefinition | MiddlewareDefinition["handler"]): MiddlewareDefinition;
|
|
25
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,oBAAoB,GAAG,oBAAoB,CAAC,SAAS,CAAC,GAC1D,oBAAoB,CAKtB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define a Capstan middleware.
|
|
3
|
+
*
|
|
4
|
+
* Accepts either a full `MiddlewareDefinition` object (with optional `name`)
|
|
5
|
+
* or a bare handler function, which is wrapped into a definition with no name.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const logging = defineMiddleware({
|
|
9
|
+
* name: "logging",
|
|
10
|
+
* handler: async ({ request, ctx, next }) => {
|
|
11
|
+
* console.log(request.method, request.url);
|
|
12
|
+
* return next();
|
|
13
|
+
* },
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // shorthand
|
|
17
|
+
* const logging2 = defineMiddleware(async ({ request, ctx, next }) => {
|
|
18
|
+
* console.log(request.method, request.url);
|
|
19
|
+
* return next();
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function defineMiddleware(def) {
|
|
24
|
+
if (typeof def === "function") {
|
|
25
|
+
return { handler: def };
|
|
26
|
+
}
|
|
27
|
+
return def;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAA2D;IAE3D,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CapstanContext, PolicyCheckResult, PolicyDefinition } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Define a named permission policy.
|
|
4
|
+
*
|
|
5
|
+
* Policies are evaluated at request time by `enforcePolicies()`. Each policy
|
|
6
|
+
* returns an effect (`allow`, `deny`, `approve`, `redact`) and an optional
|
|
7
|
+
* human-readable reason.
|
|
8
|
+
*/
|
|
9
|
+
export declare function definePolicy(def: PolicyDefinition): PolicyDefinition;
|
|
10
|
+
/**
|
|
11
|
+
* Run all provided policies and return the single most-restrictive result.
|
|
12
|
+
*
|
|
13
|
+
* If no policies are provided the default result is `{ effect: "allow" }`.
|
|
14
|
+
*
|
|
15
|
+
* Evaluation order:
|
|
16
|
+
* 1. Every policy in the array is executed (none are short-circuited so that
|
|
17
|
+
* callers can collect all reasons if desired).
|
|
18
|
+
* 2. The result with the highest severity wins.
|
|
19
|
+
* 3. Ties are broken by array order (later policy wins).
|
|
20
|
+
*/
|
|
21
|
+
export declare function enforcePolicies(policies: PolicyDefinition[], ctx: CapstanContext, input?: unknown): Promise<PolicyCheckResult>;
|
|
22
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,gBAAgB,GAAG,gBAAgB,CAEpE;AAYD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,GAAG,EAAE,cAAc,EACnB,KAAK,CAAC,EAAE,OAAO,GACd,OAAO,CAAC,iBAAiB,CAAC,CAqB5B"}
|
package/dist/policy.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define a named permission policy.
|
|
3
|
+
*
|
|
4
|
+
* Policies are evaluated at request time by `enforcePolicies()`. Each policy
|
|
5
|
+
* returns an effect (`allow`, `deny`, `approve`, `redact`) and an optional
|
|
6
|
+
* human-readable reason.
|
|
7
|
+
*/
|
|
8
|
+
export function definePolicy(def) {
|
|
9
|
+
return def;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Severity order for policy effects — higher index is more restrictive.
|
|
13
|
+
*/
|
|
14
|
+
const EFFECT_SEVERITY = {
|
|
15
|
+
allow: 0,
|
|
16
|
+
redact: 1,
|
|
17
|
+
approve: 2,
|
|
18
|
+
deny: 3,
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Run all provided policies and return the single most-restrictive result.
|
|
22
|
+
*
|
|
23
|
+
* If no policies are provided the default result is `{ effect: "allow" }`.
|
|
24
|
+
*
|
|
25
|
+
* Evaluation order:
|
|
26
|
+
* 1. Every policy in the array is executed (none are short-circuited so that
|
|
27
|
+
* callers can collect all reasons if desired).
|
|
28
|
+
* 2. The result with the highest severity wins.
|
|
29
|
+
* 3. Ties are broken by array order (later policy wins).
|
|
30
|
+
*/
|
|
31
|
+
export async function enforcePolicies(policies, ctx, input) {
|
|
32
|
+
if (policies.length === 0) {
|
|
33
|
+
return { effect: "allow" };
|
|
34
|
+
}
|
|
35
|
+
const results = await Promise.all(policies.map((p) => p.check({ ctx, input })));
|
|
36
|
+
let mostRestrictive = { effect: "allow" };
|
|
37
|
+
for (const result of results) {
|
|
38
|
+
if (EFFECT_SEVERITY[result.effect] >=
|
|
39
|
+
EFFECT_SEVERITY[mostRestrictive.effect]) {
|
|
40
|
+
mostRestrictive = result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return mostRestrictive;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAqB;IAChD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,eAAe,GAAiC;IACpD,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;CACR,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,QAA4B,EAC5B,GAAmB,EACnB,KAAe;IAEf,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAC7C,CAAC;IAEF,IAAI,eAAe,GAAsB,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAE7D,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IACE,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC;YAC9B,eAAe,CAAC,eAAe,CAAC,MAAM,CAAC,EACvC,CAAC;YACD,eAAe,GAAG,MAAM,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import type { APIDefinition, CapstanConfig, CapstanContext, HttpMethod, PolicyDefinition, RouteMetadata } from "./types.js";
|
|
3
|
+
/** Hono env binding that carries the CapstanContext through middleware. */
|
|
4
|
+
interface CapstanEnv {
|
|
5
|
+
Variables: {
|
|
6
|
+
capstanCtx: CapstanContext;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface CapstanApp {
|
|
10
|
+
/** The underlying Hono application instance. */
|
|
11
|
+
app: Hono<CapstanEnv>;
|
|
12
|
+
/** All registered route metadata — used by the agent manifest endpoint. */
|
|
13
|
+
routeRegistry: RouteMetadata[];
|
|
14
|
+
/**
|
|
15
|
+
* Register an API definition on the Hono app at the given method + path.
|
|
16
|
+
*
|
|
17
|
+
* This both mounts the HTTP handler and records metadata in `routeRegistry`
|
|
18
|
+
* so the `/.well-known/capstan.json` manifest stays in sync.
|
|
19
|
+
*/
|
|
20
|
+
registerAPI: (method: HttpMethod, path: string, apiDef: APIDefinition, policies?: PolicyDefinition[]) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a fully-wired Capstan application backed by a Hono server.
|
|
24
|
+
*
|
|
25
|
+
* The returned object contains:
|
|
26
|
+
* - `app` -- Hono instance ready to handle requests
|
|
27
|
+
* - `routeRegistry` -- array of route metadata for the agent manifest
|
|
28
|
+
* - `registerAPI()` -- helper to register an API definition as an HTTP route
|
|
29
|
+
*/
|
|
30
|
+
export declare function createCapstanApp(config: CapstanConfig): CapstanApp;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAY5B,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,2EAA2E;AAC3E,UAAU,UAAU;IAClB,SAAS,EAAE;QACT,UAAU,EAAE,cAAc,CAAC;KAC5B,CAAC;CACH;AAED,MAAM,WAAW,UAAU;IACzB,gDAAgD;IAChD,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACtB,2EAA2E;IAC3E,aAAa,EAAE,aAAa,EAAE,CAAC;IAC/B;;;;;OAKG;IACH,WAAW,EAAE,CACX,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,EACrB,QAAQ,CAAC,EAAE,gBAAgB,EAAE,KAC1B,IAAI,CAAC;CACX;AAuBD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU,CAmTlE"}
|