@ory/cloudflare-agents 0.14.0 → 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 CHANGED
@@ -3,8 +3,8 @@
3
3
  Ory Agent Security for the [Cloudflare Agents SDK](https://developers.cloudflare.com/agents/).
4
4
 
5
5
  Cloudflare Agents drive tool calls through the Vercel AI SDK (`streamText({ tools })`), so
6
- Ory wraps each tool's `execute` — authorizing every call against Ory Permissions, tracing it,
7
- and propagating user → agent identity — built on [`@ory/argus`](../core).
6
+ Ory wraps each tool's `execute` — authorizing every call against Ory Permissions, recording activity,
7
+ and propagating user → agent identity — built on [`@ory/argus`](https://www.npmjs.com/package/@ory/argus).
8
8
 
9
9
  ```bash
10
10
  npm install @ory/cloudflare-agents
@@ -39,7 +39,6 @@ export class MyAgent extends AIChatAgent<Env> {
39
39
  // One client + wrapped tool set per agent instance — not per message.
40
40
  ory = new OryAgentClient({
41
41
  projectUrl: this.env.ORY_PROJECT_URL,
42
- apiKey: this.env.ORY_AGENT_API_KEY, // static agent credential — no DCR on Workers
43
42
  harness: "cloudflare-agents",
44
43
  });
45
44
  tools = withOry({ getWeather }, { client: this.ory });
@@ -71,13 +70,12 @@ withOry(tools, {
71
70
  });
72
71
  ```
73
72
 
74
- In **enforce** mode (`ORY_PERMISSION_MODE=enforce`) a denied tool throws — the error surfaces
73
+ In **enforce** mode a denied tool throws — the error surfaces
75
74
  to the model and the tool never runs. In **observe** mode (default) the tool runs and a
76
- `permission.observe_deny` span is recorded. Spans are tagged with the `cloudflare-agents`
75
+ `permission.observe_deny` activity event is recorded. Events are tagged with the `cloudflare-agents`
77
76
  integration so the audit trail distinguishes Cloudflare from a plain Vercel app.
78
77
 
79
78
  Depends only on `@ory/argus` (not `ai`/`agents`); tools are duck-typed. The package requires
80
79
  the `nodejs_compat` compatibility flag (the Agents SDK already requires it). On Node (tests,
81
80
  local dev) the default `OryAgentClient.fromEnv("cloudflare-agents")` and the shared config
82
- file still work; on Workers always inject an explicitly constructed client. See
83
- [docs/sdk-integrations.md](../../docs/sdk-integrations.md).
81
+ file still work; on Workers always inject an explicitly constructed client.
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * `AIChatAgent.onChatMessage` you call `streamText({ tools })` with AI-SDK tools (and
6
6
  * `this.mcp.getAITools()` for MCP tools). The interception point is therefore the same:
7
7
  * wrap each tool's `execute`. {@link withOry} authorizes every call against Ory Permissions,
8
- * traces it, and (on the first call) runs the Ory session gates — under the
8
+ * records its activity, and (on the first call) runs the Ory session gates — under the
9
9
  * `cloudflare-agents` harness identity so the audit trail attributes Cloudflare distinctly
10
10
  * from a plain Vercel app.
11
11
  *
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * `AIChatAgent.onChatMessage` you call `streamText({ tools })` with AI-SDK tools (and
7
7
  * `this.mcp.getAITools()` for MCP tools). The interception point is therefore the same:
8
8
  * wrap each tool's `execute`. {@link withOry} authorizes every call against Ory Permissions,
9
- * traces it, and (on the first call) runs the Ory session gates — under the
9
+ * records its activity, and (on the first call) runs the Ory session gates — under the
10
10
  * `cloudflare-agents` harness identity so the audit trail attributes Cloudflare distinctly
11
11
  * from a plain Vercel app.
12
12
  *
@@ -32,23 +32,10 @@ const HARNESS = "cloudflare-agents";
32
32
  function withOry(tools, options = {}) {
33
33
  const client = options.client ?? argus_1.OryAgentClient.fromEnv(HARNESS);
34
34
  const canBlock = options.canBlock ?? true;
35
- let sessionPromise;
36
- // Cache the in-flight promise (not a boolean) so concurrent first calls all
37
- // await the same session start instead of racing past a still-running gate.
38
- // Fail-open: a rejection is logged, never rethrown, and clears the cache so
39
- // a later call can retry.
40
- const ensureSession = () => {
41
- sessionPromise ??= (0, argus_1.sessionStart)(client, {
42
- harness: HARNESS,
43
- projectUrl: options.projectUrl,
44
- }).then(() => undefined, (err) => {
45
- sessionPromise = undefined;
46
- client.logger.warn("session_start.failed", {
47
- message: err instanceof Error ? err.message : String(err),
48
- });
49
- });
50
- return sessionPromise;
51
- };
35
+ const ensureSession = (0, argus_1.createSessionStarter)(client, {
36
+ harness: HARNESS,
37
+ projectUrl: options.projectUrl,
38
+ });
52
39
  const wrapped = {};
53
40
  for (const [name, tool] of Object.entries(tools)) {
54
41
  if (!tool || typeof tool.execute !== "function") {
@@ -75,9 +62,15 @@ function withOry(tools, options = {}) {
75
62
  namespace: result.namespace,
76
63
  });
77
64
  }
78
- const output = await originalExecute(input, callOptions);
79
- (0, argus_1.complete)(client, { toolName: name, output });
80
- return output;
65
+ try {
66
+ const output = await originalExecute(input, callOptions);
67
+ (0, argus_1.complete)(client, { toolName: name, input, output });
68
+ return output;
69
+ }
70
+ catch (error) {
71
+ (0, argus_1.fail)(client, { toolName: name, input, error });
72
+ throw error;
73
+ }
81
74
  },
82
75
  };
83
76
  }
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@ory/cloudflare-agents",
3
- "version": "0.14.0",
4
- "description": "Ory Agent Security for the Cloudflare Agents SDK — per-tool authorization, tracing, and identity propagation by wrapping the AI SDK tools passed to streamText. Built on @ory/argus.",
3
+ "version": "1.0.0",
4
+ "description": "Ory Agent Security for the Cloudflare Agents SDK — per-tool authorization, activity auditing, and identity propagation by wrapping the AI SDK tools passed to streamText. 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": {
@@ -30,8 +34,8 @@
30
34
  "ai"
31
35
  ],
32
36
  "dependencies": {
33
- "reo-census": "^1.2.8",
34
- "@ory/argus": "0.14.0"
37
+ "reova": "^0.7.0",
38
+ "@ory/argus": "1.0.0"
35
39
  },
36
40
  "devDependencies": {
37
41
  "typescript": "^6.0.2",