@ory/mastra 0.13.9 → 1.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 +5 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -22
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Ory Agent Security for [Mastra](https://mastra.ai).
|
|
4
4
|
|
|
5
|
-
Authorizes every tool call against Ory Permissions,
|
|
6
|
-
user → agent → sub-agent identity — built on [`@ory/argus`](
|
|
5
|
+
Authorizes every tool call against Ory Permissions, records invocation activity, and propagates
|
|
6
|
+
user → agent → sub-agent identity — built on [`@ory/argus`](https://www.npmjs.com/package/@ory/argus).
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
9
|
npm install @ory/mastra
|
|
@@ -24,9 +24,9 @@ const agent = new Agent({
|
|
|
24
24
|
});
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
`beforeToolCall` authorizes each call; in **enforce** mode
|
|
27
|
+
`beforeToolCall` authorizes each call; in **enforce** mode a
|
|
28
28
|
denied tool is skipped via `{ proceed: false, output }` and the model receives the denial. In
|
|
29
|
-
**observe** mode (default) the tool runs and a `permission.observe_deny`
|
|
29
|
+
**observe** mode (default) the tool runs and a `permission.observe_deny` activity event is recorded.
|
|
30
30
|
`afterToolCall` records `tool.complete`.
|
|
31
31
|
|
|
32
32
|
Alternatively, wrap tool `execute` directly (deny → throw):
|
|
@@ -38,5 +38,4 @@ const tools = withOry({ search, sendEmail });
|
|
|
38
38
|
|
|
39
39
|
This package depends only on `@ory/argus` — not `@mastra/core`; tools and hook contexts are
|
|
40
40
|
duck-typed so any Mastra v1 version works. Credentials come from the shared
|
|
41
|
-
`~/.config/ory-agent-plugins/config.json`.
|
|
42
|
-
[docs/sdk-integrations.md](../../docs/sdk-integrations.md).
|
|
41
|
+
`~/.config/ory-agent-plugins/config.json`.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* - {@link oryAgentHooks} (recommended) — agent tool-call hooks for `new Agent({ hooks })`.
|
|
7
7
|
* `beforeToolCall` authorizes every tool (incl. agent-/workflow-as-tools); a deny returns
|
|
8
|
-
* `{ proceed: false, output }` so Mastra skips the tool. `afterToolCall`
|
|
8
|
+
* `{ proceed: false, output }` so Mastra skips the tool. `afterToolCall` records completion activity.
|
|
9
9
|
* - {@link withOry} — wraps each tool's `execute` directly (deny → throw), for callers who
|
|
10
10
|
* prefer per-tool wrapping or are on a Mastra version without the hooks API.
|
|
11
11
|
*
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* - {@link oryAgentHooks} (recommended) — agent tool-call hooks for `new Agent({ hooks })`.
|
|
8
8
|
* `beforeToolCall` authorizes every tool (incl. agent-/workflow-as-tools); a deny returns
|
|
9
|
-
* `{ proceed: false, output }` so Mastra skips the tool. `afterToolCall`
|
|
9
|
+
* `{ proceed: false, output }` so Mastra skips the tool. `afterToolCall` records completion activity.
|
|
10
10
|
* - {@link withOry} — wraps each tool's `execute` directly (deny → throw), for callers who
|
|
11
11
|
* prefer per-tool wrapping or are on a Mastra version without the hooks API.
|
|
12
12
|
*
|
|
@@ -18,29 +18,16 @@ exports.oryAgentHooks = oryAgentHooks;
|
|
|
18
18
|
exports.withOry = withOry;
|
|
19
19
|
const argus_1 = require("@ory/argus");
|
|
20
20
|
const HARNESS = "mastra";
|
|
21
|
-
function lazySession(client, projectUrl) {
|
|
22
|
-
let sessionPromise;
|
|
23
|
-
// Cache the in-flight promise (not a boolean) so concurrent first calls all
|
|
24
|
-
// await the same session start instead of racing past a still-running gate.
|
|
25
|
-
// Fail-open: a rejection is logged, never rethrown, and clears the cache so
|
|
26
|
-
// a later call can retry.
|
|
27
|
-
return () => {
|
|
28
|
-
sessionPromise ??= (0, argus_1.sessionStart)(client, { harness: HARNESS, projectUrl }).then(() => undefined, (err) => {
|
|
29
|
-
sessionPromise = undefined;
|
|
30
|
-
client.logger.warn("session_start.failed", {
|
|
31
|
-
message: err instanceof Error ? err.message : String(err),
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
return sessionPromise;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
21
|
/**
|
|
38
22
|
* Build the `{ beforeToolCall, afterToolCall }` hooks object for `new Agent({ hooks })`.
|
|
39
23
|
*/
|
|
40
24
|
function oryAgentHooks(options = {}) {
|
|
41
25
|
const client = options.client ?? argus_1.OryAgentClient.fromEnv(HARNESS);
|
|
42
26
|
const canBlock = options.canBlock ?? true;
|
|
43
|
-
const ensureSession =
|
|
27
|
+
const ensureSession = (0, argus_1.createSessionStarter)(client, {
|
|
28
|
+
harness: HARNESS,
|
|
29
|
+
projectUrl: options.projectUrl,
|
|
30
|
+
});
|
|
44
31
|
return {
|
|
45
32
|
beforeToolCall: async (ctx) => {
|
|
46
33
|
await ensureSession();
|
|
@@ -77,7 +64,10 @@ function oryAgentHooks(options = {}) {
|
|
|
77
64
|
function withOry(tools, options = {}) {
|
|
78
65
|
const client = options.client ?? argus_1.OryAgentClient.fromEnv(HARNESS);
|
|
79
66
|
const canBlock = options.canBlock ?? true;
|
|
80
|
-
const ensureSession =
|
|
67
|
+
const ensureSession = (0, argus_1.createSessionStarter)(client, {
|
|
68
|
+
harness: HARNESS,
|
|
69
|
+
projectUrl: options.projectUrl,
|
|
70
|
+
});
|
|
81
71
|
const wrapped = {};
|
|
82
72
|
for (const [key, tool] of Object.entries(tools)) {
|
|
83
73
|
if (!tool || typeof tool.execute !== "function") {
|
|
@@ -103,9 +93,15 @@ function withOry(tools, options = {}) {
|
|
|
103
93
|
namespace: result.namespace,
|
|
104
94
|
});
|
|
105
95
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
try {
|
|
97
|
+
const output = await originalExecute(inputData, context);
|
|
98
|
+
(0, argus_1.complete)(client, { toolName, output });
|
|
99
|
+
return output;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
(0, argus_1.fail)(client, { toolName, input: inputData, error });
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
109
105
|
},
|
|
110
106
|
};
|
|
111
107
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ory/mastra",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Ory Agent Security for Mastra — per-tool authorization,
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Ory Agent Security for Mastra — per-tool authorization, activity auditing, and identity propagation via agent tool-call hooks (or wrapping tool execute). Built on @ory/argus.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
8
8
|
"registry": "https://registry.npmjs.org/",
|
|
9
9
|
"provenance": true
|
|
10
10
|
},
|
|
11
|
+
"reova": {
|
|
12
|
+
"enabled": true,
|
|
13
|
+
"endpoint": "https://telemetry.reo.dev/data"
|
|
14
|
+
},
|
|
11
15
|
"main": "dist/index.js",
|
|
12
16
|
"types": "dist/index.d.ts",
|
|
13
17
|
"exports": {
|
|
@@ -29,8 +33,8 @@
|
|
|
29
33
|
"permissions"
|
|
30
34
|
],
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"@ory/argus": "0.
|
|
36
|
+
"reova": "^0.7.0",
|
|
37
|
+
"@ory/argus": "1.0.0"
|
|
34
38
|
},
|
|
35
39
|
"devDependencies": {
|
|
36
40
|
"typescript": "^6.0.2",
|