@pydantic/logfire-agent-sandboxes 0.1.1 → 0.2.1

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
@@ -4,7 +4,7 @@ Run Python that your AI agents write in isolated, remote [Pydantic Monty](https:
4
4
  hosted by [Pydantic Logfire](https://pydantic.dev/logfire), from Node.js.
5
5
 
6
6
  ```bash
7
- npm install @pydantic/logfire-agent-sandboxes @pydantic/monty@^1.4.0
7
+ npm install @pydantic/logfire-agent-sandboxes @pydantic/monty@^1.5.0
8
8
  ```
9
9
 
10
10
  Create a Logfire project API key with the **Run code in this project's agent sandboxes** permission
@@ -18,8 +18,8 @@ await using session = await pool.checkout()
18
18
  console.log(await session.feedRun('sum([20, 21, 1])')) // 42
19
19
  ```
20
20
 
21
- `agentSandboxes()` resolves to a `MontyWebsocket` pool from `@pydantic/monty`, set up with your API key, region URL,
22
- and the trace context active at each checkout. It accepts every `MontyWebsocket` option, plus `apiKey` and `url`.
21
+ `agentSandboxes()` resolves to a `MontyRemote` pool from `@pydantic/monty`, set up with your API key, region URL,
22
+ and the trace context active at each checkout. It accepts every `MontyRemote` option, plus `apiKey` and `url`.
23
23
 
24
24
  See the [Agent Sandboxes docs](https://github.com/pydantic/logfire-js/blob/main/docs/agent-sandboxes.md) for host
25
25
  functions, sessions, snapshots, and options.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@opentelemetry/api"),t=require("@pydantic/monty"),n=require("logfire");function r(e){let t=new URL(e);return t.protocol===`https:`?t.protocol=`wss:`:t.protocol===`http:`&&(t.protocol=`ws:`),t.pathname=`${t.pathname.replace(/\/+$/u,``)}/monty-ws/`,t.toString()}async function i(i={}){let{apiKey:a,connectHeaders:o,url:s,...c}=i,l=[a,process.env.LOGFIRE_API_KEY].find(e=>e!==void 0&&e!==``);if(l===void 0)throw Error("Agent sandboxes require a Logfire API key with the `project:execute_agent_sandboxes` scope. Set the LOGFIRE_API_KEY environment variable or pass `apiKey` to `agentSandboxes()`.");let u=s??r((0,n.resolveBaseUrl)(process.env,void 0,l)),d=async()=>{let t={};return e.propagation.inject(e.context.active(),t),t.authorization=`Bearer ${l}`,o===void 0?t:{...t,...await o()}};return t.MontyWebsocket.create(u,{...c,connectHeaders:d})}exports.agentSandboxes=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@opentelemetry/api"),t=require("@pydantic/monty"),n=require("logfire");function r(e){return e.replace(/\/+$/u,``)}async function i(i={}){let{apiKey:o,connectHeaders:s,metadata:c,url:l,...u}=i,d=[o,process.env.LOGFIRE_API_KEY].find(e=>e!==void 0&&e!==``);if(d===void 0)throw Error("Agent sandboxes require a Logfire API key with the `project:execute_agent_sandboxes` scope. Set the LOGFIRE_API_KEY environment variable or pass `apiKey` to `agentSandboxes()`.");if(c!==void 0&&s!==void 0)throw TypeError(`pass metadata, not connectHeaders as well`);let f=c??s,p=l??r((0,n.resolveBaseUrl)(process.env,void 0,d)),m=async()=>{let t={};e.propagation.inject(e.context.active(),t),t.authorization=`Bearer ${d}`;let n=a(t);return f===void 0?n:{...n,...a(await f())}};return t.MontyRemote.create(p,{...u,metadata:m})}function a(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e.toLowerCase(),t]))}exports.agentSandboxes=i;
package/dist/index.d.cts CHANGED
@@ -1,13 +1,13 @@
1
- import { MontyWebsocket, MontyWebsocketOptions } from "@pydantic/monty";
1
+ import { MontyRemote, MontyRemoteOptions } from "@pydantic/monty";
2
2
  //#region src/index.d.ts
3
- export interface AgentSandboxesOptions extends MontyWebsocketOptions {
3
+ export interface AgentSandboxesOptions extends MontyRemoteOptions {
4
4
  /**
5
5
  * A Logfire API key with the `project:execute_agent_sandboxes` scope.
6
6
  * Defaults to the `LOGFIRE_API_KEY` environment variable.
7
7
  */
8
8
  apiKey?: string;
9
9
  /**
10
- * The WebSocket URL of the sandboxes server.
10
+ * The `https://` or `http://` URL of the sandboxes server, with no path.
11
11
  * Defaults to the Logfire region the API key belongs to, or `LOGFIRE_BASE_URL` when set.
12
12
  */
13
13
  url?: string;
@@ -15,7 +15,7 @@ export interface AgentSandboxesOptions extends MontyWebsocketOptions {
15
15
  /**
16
16
  * Connects to Logfire Agent Sandboxes, remote Pydantic Monty workers hosted by Logfire.
17
17
  *
18
- * Resolves to a `MontyWebsocket` pool from `@pydantic/monty`; check out sessions from it:
18
+ * Resolves to a `MontyRemote` pool from `@pydantic/monty`; check out sessions from it:
19
19
  *
20
20
  * ```ts
21
21
  * await using pool = await agentSandboxes()
@@ -27,7 +27,8 @@ export interface AgentSandboxesOptions extends MontyWebsocketOptions {
27
27
  * with each checkout, so the spans Logfire records for the session join the caller's trace.
28
28
  *
29
29
  * Omitted pool options use the defaults of the installed `@pydantic/monty` version.
30
- * `connectHeaders` results are merged over the Logfire `Authorization` header and win on conflicts.
30
+ * `metadata` results (or those of `connectHeaders`, its deprecated former name) are merged over
31
+ * the Logfire `authorization` metadata and win on conflicts. Names match case-insensitively.
31
32
  */
32
- export declare function agentSandboxes(options?: AgentSandboxesOptions): Promise<MontyWebsocket>;
33
+ export declare function agentSandboxes(options?: AgentSandboxesOptions): Promise<MontyRemote>;
33
34
  //#endregion
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { MontyWebsocket, MontyWebsocketOptions } from "@pydantic/monty";
1
+ import { MontyRemote, MontyRemoteOptions } from "@pydantic/monty";
2
2
  //#region src/index.d.ts
3
- export interface AgentSandboxesOptions extends MontyWebsocketOptions {
3
+ export interface AgentSandboxesOptions extends MontyRemoteOptions {
4
4
  /**
5
5
  * A Logfire API key with the `project:execute_agent_sandboxes` scope.
6
6
  * Defaults to the `LOGFIRE_API_KEY` environment variable.
7
7
  */
8
8
  apiKey?: string;
9
9
  /**
10
- * The WebSocket URL of the sandboxes server.
10
+ * The `https://` or `http://` URL of the sandboxes server, with no path.
11
11
  * Defaults to the Logfire region the API key belongs to, or `LOGFIRE_BASE_URL` when set.
12
12
  */
13
13
  url?: string;
@@ -15,7 +15,7 @@ export interface AgentSandboxesOptions extends MontyWebsocketOptions {
15
15
  /**
16
16
  * Connects to Logfire Agent Sandboxes, remote Pydantic Monty workers hosted by Logfire.
17
17
  *
18
- * Resolves to a `MontyWebsocket` pool from `@pydantic/monty`; check out sessions from it:
18
+ * Resolves to a `MontyRemote` pool from `@pydantic/monty`; check out sessions from it:
19
19
  *
20
20
  * ```ts
21
21
  * await using pool = await agentSandboxes()
@@ -27,7 +27,8 @@ export interface AgentSandboxesOptions extends MontyWebsocketOptions {
27
27
  * with each checkout, so the spans Logfire records for the session join the caller's trace.
28
28
  *
29
29
  * Omitted pool options use the defaults of the installed `@pydantic/monty` version.
30
- * `connectHeaders` results are merged over the Logfire `Authorization` header and win on conflicts.
30
+ * `metadata` results (or those of `connectHeaders`, its deprecated former name) are merged over
31
+ * the Logfire `authorization` metadata and win on conflicts. Names match case-insensitively.
31
32
  */
32
- export declare function agentSandboxes(options?: AgentSandboxesOptions): Promise<MontyWebsocket>;
33
+ export declare function agentSandboxes(options?: AgentSandboxesOptions): Promise<MontyRemote>;
33
34
  //#endregion
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{context as e,propagation as t}from"@opentelemetry/api";import{MontyWebsocket as n}from"@pydantic/monty";import{resolveBaseUrl as r}from"logfire";function i(e){let t=new URL(e);return t.protocol===`https:`?t.protocol=`wss:`:t.protocol===`http:`&&(t.protocol=`ws:`),t.pathname=`${t.pathname.replace(/\/+$/u,``)}/monty-ws/`,t.toString()}async function a(a={}){let{apiKey:o,connectHeaders:s,url:c,...l}=a,u=[o,process.env.LOGFIRE_API_KEY].find(e=>e!==void 0&&e!==``);if(u===void 0)throw Error("Agent sandboxes require a Logfire API key with the `project:execute_agent_sandboxes` scope. Set the LOGFIRE_API_KEY environment variable or pass `apiKey` to `agentSandboxes()`.");let d=c??i(r(process.env,void 0,u)),f=async()=>{let n={};return t.inject(e.active(),n),n.authorization=`Bearer ${u}`,s===void 0?n:{...n,...await s()}};return n.create(d,{...l,connectHeaders:f})}export{a as agentSandboxes};
1
+ import{context as e,propagation as t}from"@opentelemetry/api";import{MontyRemote as n}from"@pydantic/monty";import{resolveBaseUrl as r}from"logfire";function i(e){return e.replace(/\/+$/u,``)}async function a(a={}){let{apiKey:s,connectHeaders:c,metadata:l,url:u,...d}=a,f=[s,process.env.LOGFIRE_API_KEY].find(e=>e!==void 0&&e!==``);if(f===void 0)throw Error("Agent sandboxes require a Logfire API key with the `project:execute_agent_sandboxes` scope. Set the LOGFIRE_API_KEY environment variable or pass `apiKey` to `agentSandboxes()`.");if(l!==void 0&&c!==void 0)throw TypeError(`pass metadata, not connectHeaders as well`);let p=l??c,m=u??i(r(process.env,void 0,f)),h=async()=>{let n={};t.inject(e.active(),n),n.authorization=`Bearer ${f}`;let r=o(n);return p===void 0?r:{...r,...o(await p())}};return n.create(m,{...d,metadata:h})}function o(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e.toLowerCase(),t]))}export{a as agentSandboxes};
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  "agents",
24
24
  "python"
25
25
  ],
26
- "version": "0.1.1",
26
+ "version": "0.2.1",
27
27
  "type": "module",
28
28
  "main": "./dist/index.cjs",
29
29
  "module": "./dist/index.js",
@@ -41,17 +41,18 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "logfire": "0.25.1"
44
+ "logfire": "0.26.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@opentelemetry/api": ">=1.9.1 <1.10.0",
48
- "@pydantic/monty": "^1.4.0"
48
+ "@pydantic/monty": "^1.5.0"
49
49
  },
50
50
  "devDependencies": {
51
+ "@grpc/grpc-js": "^1.14.5",
51
52
  "@opentelemetry/api": ">=1.9.1 <1.10.0",
52
53
  "@opentelemetry/context-async-hooks": "^2.8.0",
53
54
  "@opentelemetry/core": "^2.8.0",
54
- "@pydantic/monty": "^1.4.0",
55
+ "@pydantic/monty": "^1.5.0",
55
56
  "@types/node": "^22.5.1",
56
57
  "vitest": "5.0.1"
57
58
  },