@pydantic/logfire-agent-sandboxes 0.2.0 → 0.2.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/README.md +15 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,5 +21,20 @@ console.log(await session.feedRun('sum([20, 21, 1])')) // 42
|
|
|
21
21
|
`agentSandboxes()` resolves to a `MontyRemote` pool from `@pydantic/monty`, set up with your API key, region URL,
|
|
22
22
|
and the trace context active at each checkout. It accepts every `MontyRemote` option, plus `apiKey` and `url`.
|
|
23
23
|
|
|
24
|
+
An explicit `url` or `LOGFIRE_BASE_URL` must have no path, query, or fragment. Remove the old `/monty-ws/` path;
|
|
25
|
+
the client selects its gRPC session path itself.
|
|
26
|
+
|
|
27
|
+
The package exports these errors:
|
|
28
|
+
|
|
29
|
+
- `AgentSandboxError`: the base class, also used for SDK configuration errors.
|
|
30
|
+
- `AgentSandboxRefusedError`: a refused checkout, with `statusCode`, `statusMessage`, and `reason` fields, plus
|
|
31
|
+
Logfire hints for project access, API key configuration, and capacity when applicable.
|
|
32
|
+
- `AgentSandboxConnectionError`: any other failure to create the pool or check out a session.
|
|
33
|
+
|
|
34
|
+
Refusal and connection errors preserve the original error as the standard `Error.cause`. For a refusal, the original
|
|
35
|
+
`MontyRefusedError` is on `cause`; its policy string is copied to the outer error's `reason`, not `cause`. Error
|
|
36
|
+
messages start with **Agent Sandboxes**. Errors from operations on an already checked-out session pass through
|
|
37
|
+
unchanged, including user-code errors, `MontyCrashedError`, `MontyDisconnectError`, and `MontyShutdown`.
|
|
38
|
+
|
|
24
39
|
See the [Agent Sandboxes docs](https://github.com/pydantic/logfire-js/blob/main/docs/agent-sandboxes.md) for host
|
|
25
40
|
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");
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@opentelemetry/api"),t=require("@pydantic/monty"),n=require("logfire");var r=class extends Error{constructor(e,t){super(e,t),this.name=`AgentSandboxError`}},i=class extends r{statusCode;statusMessage;reason;constructor(e){let t=`Agent Sandboxes refused the session: ${e.statusMessage??`no server status message`}`,n=o(e);super(n===void 0?t:`${t}\n${n}`,{cause:e}),this.name=`AgentSandboxRefusedError`,this.statusCode=e.statusCode,this.statusMessage=e.statusMessage,this.reason=e.cause}},a=class extends r{constructor(e,t){let n=(t instanceof Error?t.message:String(t)).replace(/^failed to spawn monty worker: /u,``),r=`${e}: `;super(`Agent Sandboxes could not connect to ${e}: ${n.startsWith(r)?n.slice(r.length):n}`,{cause:t}),this.name=`AgentSandboxConnectionError`}};function o(e){return e.statusCode===`UNAUTHENTICATED`||e.statusCode===`PERMISSION_DENIED`?"Use a project API key (not a personal API key) with the `project:execute_agent_sandboxes` scope. Check that the key's region matches the URL and that Agent Sandboxes are enabled for the project.":e.cause===`caller_cap`?"Too many sessions are being opened at once. Lower `maxProcesses` or retry after a delay.":e.cause===`capacity`?`The service is at capacity. Retry after a delay.`:void 0}function s(e){let t=e.replace(/\/+$/u,``);if(!URL.canParse(t)||!/^https?:\/\/[^/\\?#\s]+$/iu.test(t))throw new r("Agent Sandboxes URL must use http://<host> or https://<host> with no path, query or fragment. Remove the old /monty-ws/ path from `url` or LOGFIRE_BASE_URL.");return t}async function c(i={}){let{apiKey:a,connectHeaders:o,metadata:c,url:d,...f}=i,p=[a,process.env.LOGFIRE_API_KEY].find(e=>e!==void 0&&e!==``);if(p===void 0)throw new r("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&&o!==void 0)throw new r("Agent Sandboxes require `metadata`, not `connectHeaders` as well.");let m=c??o,h=s(d??(0,n.resolveBaseUrl)(process.env,void 0,p)),g=async()=>{let t={};e.propagation.inject(e.context.active(),t),t.authorization=`Bearer ${p}`;let n=u(t);return m===void 0?n:{...n,...u(await m())}},_=await t.MontyRemote.create(h,{...f,metadata:g}).catch(e=>{throw l(h,e)}),v=_.checkout.bind(_);return _.checkout=async(...e)=>{try{return await v(...e)}catch(e){throw l(h,e)}},_}function l(e,n){return n instanceof t.MontyRefusedError?new i(n):new a(e,n)}function u(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e.toLowerCase(),t]))}exports.AgentSandboxConnectionError=a,exports.AgentSandboxError=r,exports.AgentSandboxRefusedError=i,exports.agentSandboxes=c;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import { MontyRemote, MontyRemoteOptions } from "@pydantic/monty";
|
|
1
|
+
import { MontyRefusedError, MontyRemote, MontyRemoteOptions } from "@pydantic/monty";
|
|
2
|
+
//#region src/errors.d.ts
|
|
3
|
+
/** Base class for Agent Sandboxes SDK errors. */
|
|
4
|
+
export declare class AgentSandboxError extends Error {
|
|
5
|
+
constructor(message: string, options?: ErrorOptions);
|
|
6
|
+
}
|
|
7
|
+
/** The server refused a checkout; no sandbox code ran. The original refusal is `cause`. */
|
|
8
|
+
export declare class AgentSandboxRefusedError extends AgentSandboxError {
|
|
9
|
+
readonly statusCode: string | null;
|
|
10
|
+
readonly statusMessage: string | null;
|
|
11
|
+
readonly reason: string | null;
|
|
12
|
+
constructor(cause: MontyRefusedError);
|
|
13
|
+
}
|
|
14
|
+
/** A pool could not be created or checked out. The original failure is `cause`. */
|
|
15
|
+
export declare class AgentSandboxConnectionError extends AgentSandboxError {
|
|
16
|
+
constructor(url: string, cause: unknown);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
2
19
|
//#region src/index.d.ts
|
|
3
20
|
export interface AgentSandboxesOptions extends MontyRemoteOptions {
|
|
4
21
|
/**
|
|
@@ -7,7 +24,7 @@ export interface AgentSandboxesOptions extends MontyRemoteOptions {
|
|
|
7
24
|
*/
|
|
8
25
|
apiKey?: string;
|
|
9
26
|
/**
|
|
10
|
-
* The `https://` or `http://` URL of the sandboxes server, with no path.
|
|
27
|
+
* The `https://` or `http://` URL of the sandboxes server, with no path, query, or fragment.
|
|
11
28
|
* Defaults to the Logfire region the API key belongs to, or `LOGFIRE_BASE_URL` when set.
|
|
12
29
|
*/
|
|
13
30
|
url?: string;
|
|
@@ -25,6 +42,10 @@ export interface AgentSandboxesOptions extends MontyRemoteOptions {
|
|
|
25
42
|
*
|
|
26
43
|
* No connection is made until a session is checked out. The current trace context is sent
|
|
27
44
|
* with each checkout, so the spans Logfire records for the session join the caller's trace.
|
|
45
|
+
* Checkout refusals raise `AgentSandboxRefusedError`, and other connection or checkout failures
|
|
46
|
+
* raise `AgentSandboxConnectionError`. Both preserve the original error as `cause`. Refusals add
|
|
47
|
+
* Logfire hints for authentication, permissions, and capacity. Configuration failures raise
|
|
48
|
+
* `AgentSandboxError`. Operations on a checked-out session keep their original error types.
|
|
28
49
|
*
|
|
29
50
|
* Omitted pool options use the defaults of the installed `@pydantic/monty` version.
|
|
30
51
|
* `metadata` results (or those of `connectHeaders`, its deprecated former name) are merged over
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import { MontyRemote, MontyRemoteOptions } from "@pydantic/monty";
|
|
1
|
+
import { MontyRefusedError, MontyRemote, MontyRemoteOptions } from "@pydantic/monty";
|
|
2
|
+
//#region src/errors.d.ts
|
|
3
|
+
/** Base class for Agent Sandboxes SDK errors. */
|
|
4
|
+
export declare class AgentSandboxError extends Error {
|
|
5
|
+
constructor(message: string, options?: ErrorOptions);
|
|
6
|
+
}
|
|
7
|
+
/** The server refused a checkout; no sandbox code ran. The original refusal is `cause`. */
|
|
8
|
+
export declare class AgentSandboxRefusedError extends AgentSandboxError {
|
|
9
|
+
readonly statusCode: string | null;
|
|
10
|
+
readonly statusMessage: string | null;
|
|
11
|
+
readonly reason: string | null;
|
|
12
|
+
constructor(cause: MontyRefusedError);
|
|
13
|
+
}
|
|
14
|
+
/** A pool could not be created or checked out. The original failure is `cause`. */
|
|
15
|
+
export declare class AgentSandboxConnectionError extends AgentSandboxError {
|
|
16
|
+
constructor(url: string, cause: unknown);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
2
19
|
//#region src/index.d.ts
|
|
3
20
|
export interface AgentSandboxesOptions extends MontyRemoteOptions {
|
|
4
21
|
/**
|
|
@@ -7,7 +24,7 @@ export interface AgentSandboxesOptions extends MontyRemoteOptions {
|
|
|
7
24
|
*/
|
|
8
25
|
apiKey?: string;
|
|
9
26
|
/**
|
|
10
|
-
* The `https://` or `http://` URL of the sandboxes server, with no path.
|
|
27
|
+
* The `https://` or `http://` URL of the sandboxes server, with no path, query, or fragment.
|
|
11
28
|
* Defaults to the Logfire region the API key belongs to, or `LOGFIRE_BASE_URL` when set.
|
|
12
29
|
*/
|
|
13
30
|
url?: string;
|
|
@@ -25,6 +42,10 @@ export interface AgentSandboxesOptions extends MontyRemoteOptions {
|
|
|
25
42
|
*
|
|
26
43
|
* No connection is made until a session is checked out. The current trace context is sent
|
|
27
44
|
* with each checkout, so the spans Logfire records for the session join the caller's trace.
|
|
45
|
+
* Checkout refusals raise `AgentSandboxRefusedError`, and other connection or checkout failures
|
|
46
|
+
* raise `AgentSandboxConnectionError`. Both preserve the original error as `cause`. Refusals add
|
|
47
|
+
* Logfire hints for authentication, permissions, and capacity. Configuration failures raise
|
|
48
|
+
* `AgentSandboxError`. Operations on a checked-out session keep their original error types.
|
|
28
49
|
*
|
|
29
50
|
* Omitted pool options use the defaults of the installed `@pydantic/monty` version.
|
|
30
51
|
* `metadata` results (or those of `connectHeaders`, its deprecated former name) are merged over
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{context as e,propagation as t}from"@opentelemetry/api";import{MontyRemote as
|
|
1
|
+
import{context as e,propagation as t}from"@opentelemetry/api";import{MontyRefusedError as n,MontyRemote as r}from"@pydantic/monty";import{resolveBaseUrl as i}from"logfire";var a=class extends Error{constructor(e,t){super(e,t),this.name=`AgentSandboxError`}},o=class extends a{statusCode;statusMessage;reason;constructor(e){let t=`Agent Sandboxes refused the session: ${e.statusMessage??`no server status message`}`,n=c(e);super(n===void 0?t:`${t}\n${n}`,{cause:e}),this.name=`AgentSandboxRefusedError`,this.statusCode=e.statusCode,this.statusMessage=e.statusMessage,this.reason=e.cause}},s=class extends a{constructor(e,t){let n=(t instanceof Error?t.message:String(t)).replace(/^failed to spawn monty worker: /u,``),r=`${e}: `;super(`Agent Sandboxes could not connect to ${e}: ${n.startsWith(r)?n.slice(r.length):n}`,{cause:t}),this.name=`AgentSandboxConnectionError`}};function c(e){return e.statusCode===`UNAUTHENTICATED`||e.statusCode===`PERMISSION_DENIED`?"Use a project API key (not a personal API key) with the `project:execute_agent_sandboxes` scope. Check that the key's region matches the URL and that Agent Sandboxes are enabled for the project.":e.cause===`caller_cap`?"Too many sessions are being opened at once. Lower `maxProcesses` or retry after a delay.":e.cause===`capacity`?`The service is at capacity. Retry after a delay.`:void 0}function l(e){let t=e.replace(/\/+$/u,``);if(!URL.canParse(t)||!/^https?:\/\/[^/\\?#\s]+$/iu.test(t))throw new a("Agent Sandboxes URL must use http://<host> or https://<host> with no path, query or fragment. Remove the old /monty-ws/ path from `url` or LOGFIRE_BASE_URL.");return t}async function u(n={}){let{apiKey:o,connectHeaders:s,metadata:c,url:u,...p}=n,m=[o,process.env.LOGFIRE_API_KEY].find(e=>e!==void 0&&e!==``);if(m===void 0)throw new a("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 new a("Agent Sandboxes require `metadata`, not `connectHeaders` as well.");let h=c??s,g=l(u??i(process.env,void 0,m)),_=async()=>{let n={};t.inject(e.active(),n),n.authorization=`Bearer ${m}`;let r=f(n);return h===void 0?r:{...r,...f(await h())}},v=await r.create(g,{...p,metadata:_}).catch(e=>{throw d(g,e)}),y=v.checkout.bind(v);return v.checkout=async(...e)=>{try{return await y(...e)}catch(e){throw d(g,e)}},v}function d(e,t){return t instanceof n?new o(t):new s(e,t)}function f(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e.toLowerCase(),t]))}export{s as AgentSandboxConnectionError,a as AgentSandboxError,o as AgentSandboxRefusedError,u as agentSandboxes};
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"agents",
|
|
24
24
|
"python"
|
|
25
25
|
],
|
|
26
|
-
"version": "0.2.
|
|
26
|
+
"version": "0.2.2",
|
|
27
27
|
"type": "module",
|
|
28
28
|
"main": "./dist/index.cjs",
|
|
29
29
|
"module": "./dist/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"logfire": "0.
|
|
44
|
+
"logfire": "0.26.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@opentelemetry/api": ">=1.9.1 <1.10.0",
|