@sanctum-runtime/adapter-agent-runtime 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 +26 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @sanctum-runtime/adapter-agent-runtime
|
|
2
|
+
|
|
3
|
+
`protectAgent()` and `AgentActions` helpers for the Sanctum runtime SDK.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @sanctum-runtime/sdk @sanctum-runtime/adapter-agent-runtime
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { SanctumRuntime } from '@sanctum-runtime/sdk'
|
|
11
|
+
import { protectAgent, AgentActions } from '@sanctum-runtime/adapter-agent-runtime'
|
|
12
|
+
|
|
13
|
+
const sanctum = new SanctumRuntime({ baseUrl: process.env.SANCTUM_API_URL! })
|
|
14
|
+
|
|
15
|
+
await protectAgent(sanctum, {
|
|
16
|
+
actor: 'my-agent',
|
|
17
|
+
action: AgentActions.SEND_EMAIL,
|
|
18
|
+
context: { to: 'user@example.com' },
|
|
19
|
+
offlineMode: true,
|
|
20
|
+
execute: async () => sendEmail(),
|
|
21
|
+
})
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Requires a running Sanctum API — clone [sanctum-runtime](https://github.com/Matik103/sanctum-runtime) and `npm run dev:runtime`, or point at your hosted API.
|
|
25
|
+
|
|
26
|
+
MIT — see [OPEN_CORE.md](https://github.com/Matik103/sanctum-runtime/blob/main/OPEN_CORE.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as _sanctum_runtime_sdk from '@sanctum-runtime/sdk';
|
|
2
|
+
import { SanctumActionBlockedError, SanctumRuntime, ActionRequest, ActionResult, SanctumVerificationRequiredError } from '@sanctum-runtime/sdk';
|
|
3
|
+
|
|
4
|
+
/** Canonical agent action types (PRD §17 — Category 1). */
|
|
5
|
+
declare const AgentActions: {
|
|
6
|
+
readonly SEND_EMAIL: "send_email";
|
|
7
|
+
readonly DELETE_FILE: "delete_file";
|
|
8
|
+
readonly EXECUTE_TERMINAL: "execute_terminal";
|
|
9
|
+
readonly TRANSFER_FUNDS: "transfer_funds";
|
|
10
|
+
readonly ACCESS_DATABASE: "access_database";
|
|
11
|
+
readonly CREATE_USER: "create_user";
|
|
12
|
+
};
|
|
13
|
+
type AgentAction = (typeof AgentActions)[keyof typeof AgentActions];
|
|
14
|
+
declare const AGENT_ACTIONS: AgentAction[];
|
|
15
|
+
|
|
16
|
+
type AgentRuntimeAdapterOptions = {
|
|
17
|
+
/** Default actor id for verify calls (e.g. workflow or session id). */
|
|
18
|
+
actor?: string;
|
|
19
|
+
offlineMode?: boolean;
|
|
20
|
+
};
|
|
21
|
+
type AgentProtectOptions<T> = {
|
|
22
|
+
action: AgentAction | string;
|
|
23
|
+
context?: Record<string, unknown>;
|
|
24
|
+
actor?: string;
|
|
25
|
+
correlationId?: string;
|
|
26
|
+
offlineMode?: boolean;
|
|
27
|
+
/** Called only when decision is APPROVED. */
|
|
28
|
+
execute: () => Promise<T>;
|
|
29
|
+
};
|
|
30
|
+
/** @deprecated Use SanctumActionBlockedError from @sanctum-runtime/sdk */
|
|
31
|
+
declare class AgentActionBlockedError extends SanctumActionBlockedError {
|
|
32
|
+
}
|
|
33
|
+
/** @deprecated Use SanctumVerificationRequiredError from @sanctum-runtime/sdk */
|
|
34
|
+
declare class AgentVerificationRequiredError extends SanctumVerificationRequiredError {
|
|
35
|
+
}
|
|
36
|
+
/** Normalizes agent-layer calls into Sanctum {@link ActionRequest}. */
|
|
37
|
+
declare class AgentRuntimeAdapter {
|
|
38
|
+
private runtime;
|
|
39
|
+
private defaultActor;
|
|
40
|
+
private defaultOffline;
|
|
41
|
+
constructor(runtime: SanctumRuntime, options?: AgentRuntimeAdapterOptions);
|
|
42
|
+
normalize(input: {
|
|
43
|
+
actor?: string;
|
|
44
|
+
action: AgentAction | string;
|
|
45
|
+
context?: Record<string, unknown>;
|
|
46
|
+
}): ActionRequest;
|
|
47
|
+
verifyAction(input: Parameters<AgentRuntimeAdapter['normalize']>[0], options?: {
|
|
48
|
+
offlineMode?: boolean;
|
|
49
|
+
correlationId?: string;
|
|
50
|
+
}): Promise<ActionResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Intercept → verify → execute. Throws on block or verification required.
|
|
53
|
+
* PRD integration north star: `sanctum.protect(agent)` style flows.
|
|
54
|
+
*/
|
|
55
|
+
protect<T>(options: AgentProtectOptions<T>): Promise<{
|
|
56
|
+
result: ActionResult;
|
|
57
|
+
value: T;
|
|
58
|
+
}>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One-line guard for agent runtimes (PRD §17). */
|
|
62
|
+
declare function protectAgent<T>(runtime: SanctumRuntime, options: AgentProtectOptions<T> & {
|
|
63
|
+
actor?: string;
|
|
64
|
+
}): Promise<{
|
|
65
|
+
result: _sanctum_runtime_sdk.ActionResult;
|
|
66
|
+
value: T;
|
|
67
|
+
}>;
|
|
68
|
+
|
|
69
|
+
export { AGENT_ACTIONS, type AgentAction, AgentActionBlockedError, AgentActions, type AgentProtectOptions, AgentRuntimeAdapter, type AgentRuntimeAdapterOptions, AgentVerificationRequiredError, protectAgent };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// src/actions.ts
|
|
2
|
+
var AgentActions = {
|
|
3
|
+
SEND_EMAIL: "send_email",
|
|
4
|
+
DELETE_FILE: "delete_file",
|
|
5
|
+
EXECUTE_TERMINAL: "execute_terminal",
|
|
6
|
+
TRANSFER_FUNDS: "transfer_funds",
|
|
7
|
+
ACCESS_DATABASE: "access_database",
|
|
8
|
+
CREATE_USER: "create_user"
|
|
9
|
+
};
|
|
10
|
+
var AGENT_ACTIONS = Object.values(AgentActions);
|
|
11
|
+
|
|
12
|
+
// src/adapter.ts
|
|
13
|
+
import { ActionRequestSchema, SanctumActionBlockedError, SanctumVerificationRequiredError } from "@sanctum-runtime/sdk";
|
|
14
|
+
var AgentActionBlockedError = class extends SanctumActionBlockedError {
|
|
15
|
+
};
|
|
16
|
+
var AgentVerificationRequiredError = class extends SanctumVerificationRequiredError {
|
|
17
|
+
};
|
|
18
|
+
var AgentRuntimeAdapter = class {
|
|
19
|
+
constructor(runtime, options = {}) {
|
|
20
|
+
this.runtime = runtime;
|
|
21
|
+
this.defaultActor = options.actor ?? "agent";
|
|
22
|
+
this.defaultOffline = options.offlineMode ?? false;
|
|
23
|
+
}
|
|
24
|
+
runtime;
|
|
25
|
+
defaultActor;
|
|
26
|
+
defaultOffline;
|
|
27
|
+
normalize(input) {
|
|
28
|
+
return ActionRequestSchema.parse({
|
|
29
|
+
actor: input.actor ?? this.defaultActor,
|
|
30
|
+
action: input.action,
|
|
31
|
+
context: input.context ?? {}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
verifyAction(input, options = {}) {
|
|
35
|
+
const request = this.normalize(input);
|
|
36
|
+
return this.runtime.verifyAction(request, {
|
|
37
|
+
offlineMode: options.offlineMode ?? this.defaultOffline,
|
|
38
|
+
correlationId: options.correlationId
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Intercept → verify → execute. Throws on block or verification required.
|
|
43
|
+
* PRD integration north star: `sanctum.protect(agent)` style flows.
|
|
44
|
+
*/
|
|
45
|
+
async protect(options) {
|
|
46
|
+
const result = await this.verifyAction(
|
|
47
|
+
{
|
|
48
|
+
actor: options.actor,
|
|
49
|
+
action: options.action,
|
|
50
|
+
context: options.context
|
|
51
|
+
},
|
|
52
|
+
{ offlineMode: options.offlineMode, correlationId: options.correlationId }
|
|
53
|
+
);
|
|
54
|
+
assertExecutable(result.decision, result);
|
|
55
|
+
const value = await options.execute();
|
|
56
|
+
return { result, value };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function assertExecutable(decision, result) {
|
|
60
|
+
if (decision === "BLOCKED") throw new SanctumActionBlockedError(result);
|
|
61
|
+
if (decision === "REQUIRE_VERIFICATION") throw new SanctumVerificationRequiredError(result);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/index.ts
|
|
65
|
+
function protectAgent(runtime, options) {
|
|
66
|
+
const adapter = new AgentRuntimeAdapter(runtime, { actor: options.actor });
|
|
67
|
+
return adapter.protect(options);
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
AGENT_ACTIONS,
|
|
71
|
+
AgentActionBlockedError,
|
|
72
|
+
AgentActions,
|
|
73
|
+
AgentRuntimeAdapter,
|
|
74
|
+
AgentVerificationRequiredError,
|
|
75
|
+
protectAgent
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/actions.ts","../src/adapter.ts","../src/index.ts"],"sourcesContent":["/** Canonical agent action types (PRD §17 — Category 1). */\nexport const AgentActions = {\n SEND_EMAIL: 'send_email',\n DELETE_FILE: 'delete_file',\n EXECUTE_TERMINAL: 'execute_terminal',\n TRANSFER_FUNDS: 'transfer_funds',\n ACCESS_DATABASE: 'access_database',\n CREATE_USER: 'create_user',\n} as const\n\nexport type AgentAction = (typeof AgentActions)[keyof typeof AgentActions]\n\nexport const AGENT_ACTIONS = Object.values(AgentActions) as AgentAction[]\n","import type { ActionRequest, ActionResult, Decision } from '@sanctum-runtime/sdk'\nimport { ActionRequestSchema, SanctumActionBlockedError, SanctumVerificationRequiredError } from '@sanctum-runtime/sdk'\nimport type { SanctumRuntime } from '@sanctum-runtime/sdk'\nimport type { AgentAction } from './actions.js'\n\nexport type AgentRuntimeAdapterOptions = {\n /** Default actor id for verify calls (e.g. workflow or session id). */\n actor?: string\n offlineMode?: boolean\n}\n\nexport type AgentProtectOptions<T> = {\n action: AgentAction | string\n context?: Record<string, unknown>\n actor?: string\n correlationId?: string\n offlineMode?: boolean\n /** Called only when decision is APPROVED. */\n execute: () => Promise<T>\n}\n\n/** @deprecated Use SanctumActionBlockedError from @sanctum-runtime/sdk */\nexport class AgentActionBlockedError extends SanctumActionBlockedError {}\n\n/** @deprecated Use SanctumVerificationRequiredError from @sanctum-runtime/sdk */\nexport class AgentVerificationRequiredError extends SanctumVerificationRequiredError {}\n\n/** Normalizes agent-layer calls into Sanctum {@link ActionRequest}. */\nexport class AgentRuntimeAdapter {\n private defaultActor: string\n private defaultOffline: boolean\n\n constructor(\n private runtime: SanctumRuntime,\n options: AgentRuntimeAdapterOptions = {},\n ) {\n this.defaultActor = options.actor ?? 'agent'\n this.defaultOffline = options.offlineMode ?? false\n }\n\n normalize(input: {\n actor?: string\n action: AgentAction | string\n context?: Record<string, unknown>\n }): ActionRequest {\n return ActionRequestSchema.parse({\n actor: input.actor ?? this.defaultActor,\n action: input.action,\n context: input.context ?? {},\n })\n }\n\n verifyAction(\n input: Parameters<AgentRuntimeAdapter['normalize']>[0],\n options: { offlineMode?: boolean; correlationId?: string } = {},\n ): Promise<ActionResult> {\n const request = this.normalize(input)\n return this.runtime.verifyAction(request, {\n offlineMode: options.offlineMode ?? this.defaultOffline,\n correlationId: options.correlationId,\n })\n }\n\n /**\n * Intercept → verify → execute. Throws on block or verification required.\n * PRD integration north star: `sanctum.protect(agent)` style flows.\n */\n async protect<T>(options: AgentProtectOptions<T>): Promise<{ result: ActionResult; value: T }> {\n const result = await this.verifyAction(\n {\n actor: options.actor,\n action: options.action,\n context: options.context,\n },\n { offlineMode: options.offlineMode, correlationId: options.correlationId },\n )\n assertExecutable(result.decision, result)\n const value = await options.execute()\n return { result, value }\n }\n}\n\nfunction assertExecutable(decision: Decision, result: ActionResult): void {\n if (decision === 'BLOCKED') throw new SanctumActionBlockedError(result)\n if (decision === 'REQUIRE_VERIFICATION') throw new SanctumVerificationRequiredError(result)\n}\n","export { AgentActions, AGENT_ACTIONS, type AgentAction } from './actions.js'\nexport {\n AgentRuntimeAdapter,\n AgentActionBlockedError,\n AgentVerificationRequiredError,\n type AgentRuntimeAdapterOptions,\n type AgentProtectOptions,\n} from './adapter.js'\n\nimport type { SanctumRuntime } from '@sanctum-runtime/sdk'\nimport { AgentRuntimeAdapter, type AgentProtectOptions } from './adapter.js'\n\n/** One-line guard for agent runtimes (PRD §17). */\nexport function protectAgent<T>(\n runtime: SanctumRuntime,\n options: AgentProtectOptions<T> & { actor?: string },\n): Promise<{ result: import('@sanctum-runtime/sdk').ActionResult; value: T }> {\n const adapter = new AgentRuntimeAdapter(runtime, { actor: options.actor })\n return adapter.protect(options)\n}\n"],"mappings":";AACO,IAAM,eAAe;AAAA,EAC1B,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,aAAa;AACf;AAIO,IAAM,gBAAgB,OAAO,OAAO,YAAY;;;ACXvD,SAAS,qBAAqB,2BAA2B,wCAAwC;AAqB1F,IAAM,0BAAN,cAAsC,0BAA0B;AAAC;AAGjE,IAAM,iCAAN,cAA6C,iCAAiC;AAAC;AAG/E,IAAM,sBAAN,MAA0B;AAAA,EAI/B,YACU,SACR,UAAsC,CAAC,GACvC;AAFQ;AAGR,SAAK,eAAe,QAAQ,SAAS;AACrC,SAAK,iBAAiB,QAAQ,eAAe;AAAA,EAC/C;AAAA,EALU;AAAA,EAJF;AAAA,EACA;AAAA,EAUR,UAAU,OAIQ;AAChB,WAAO,oBAAoB,MAAM;AAAA,MAC/B,OAAO,MAAM,SAAS,KAAK;AAAA,MAC3B,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM,WAAW,CAAC;AAAA,IAC7B,CAAC;AAAA,EACH;AAAA,EAEA,aACE,OACA,UAA6D,CAAC,GACvC;AACvB,UAAM,UAAU,KAAK,UAAU,KAAK;AACpC,WAAO,KAAK,QAAQ,aAAa,SAAS;AAAA,MACxC,aAAa,QAAQ,eAAe,KAAK;AAAA,MACzC,eAAe,QAAQ;AAAA,IACzB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,QAAW,SAA8E;AAC7F,UAAM,SAAS,MAAM,KAAK;AAAA,MACxB;AAAA,QACE,OAAO,QAAQ;AAAA,QACf,QAAQ,QAAQ;AAAA,QAChB,SAAS,QAAQ;AAAA,MACnB;AAAA,MACA,EAAE,aAAa,QAAQ,aAAa,eAAe,QAAQ,cAAc;AAAA,IAC3E;AACA,qBAAiB,OAAO,UAAU,MAAM;AACxC,UAAM,QAAQ,MAAM,QAAQ,QAAQ;AACpC,WAAO,EAAE,QAAQ,MAAM;AAAA,EACzB;AACF;AAEA,SAAS,iBAAiB,UAAoB,QAA4B;AACxE,MAAI,aAAa,UAAW,OAAM,IAAI,0BAA0B,MAAM;AACtE,MAAI,aAAa,uBAAwB,OAAM,IAAI,iCAAiC,MAAM;AAC5F;;;ACxEO,SAAS,aACd,SACA,SAC4E;AAC5E,QAAM,UAAU,IAAI,oBAAoB,SAAS,EAAE,OAAO,QAAQ,MAAM,CAAC;AACzE,SAAO,QAAQ,QAAQ,OAAO;AAChC;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sanctum-runtime/adapter-agent-runtime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Agent adapter — protectAgent() and action helpers for @sanctum-runtime/sdk",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Matik103/sanctum-runtime.git",
|
|
10
|
+
"directory": "packages/adapters/agent-runtime"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Matik103/sanctum-runtime#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Matik103/sanctum-runtime/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"ai",
|
|
18
|
+
"agents",
|
|
19
|
+
"runtime",
|
|
20
|
+
"security",
|
|
21
|
+
"middleware"
|
|
22
|
+
],
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"prepublishOnly": "npm run build"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"registry": "https://registry.npmjs.org"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@sanctum-runtime/sdk": "^0.1.0",
|
|
45
|
+
"zod": "^3.24.2"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"tsup": "^8.5.0",
|
|
49
|
+
"typescript": "^5.8.3"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
}
|
|
54
|
+
}
|