@nylorun/agents 0.19.1-beta → 0.21.0-beta

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/dist/sandboxes.js DELETED
@@ -1,109 +0,0 @@
1
- /**
2
- * Sandboxes as a resource (Host feature `sandboxes`): `client.sandboxes`. A sandbox has its own
3
- * id and outlives the sessions attached to it; whether it serves one session, one person or a
4
- * project is the app's choice, made here:
5
- *
6
- * - `sandboxes.forSession(...)`: one sandbox for one session. It creates the sandbox, opens the
7
- * session attached to it, and `release()` deletes the sandbox when the session is done. It
8
- * replaces sharing through another session (`sandbox: { session }`, `sandboxOwnerId`).
9
- * - `sandboxes.ensure(id, spec)`: one sandbox per person or per project, by a deterministic id
10
- * (`user-42`, `team-a/proj-42`); get-or-create in one call. Attach sessions to it with
11
- * `createSession({ sandbox: { id } })`.
12
- *
13
- * Ids may hold `/`; they are sent percent-encoded as one path segment.
14
- */
15
- import { SandboxPageSchema, isSandboxId, } from "@nylorun/core/contracts";
16
- import { id, segment } from "./http.js";
17
- const FEATURE = "sandboxes";
18
- export class SandboxesClient {
19
- transport;
20
- createSession;
21
- constructor(transport,
22
- /** `AgentsClient.createSession`, bound. */
23
- createSession) {
24
- this.transport = transport;
25
- this.createSession = createSession;
26
- }
27
- path(sandboxId) {
28
- if (!isSandboxId(sandboxId))
29
- throw new TypeError(`${sandboxId} is not a sandbox id: up to 200 characters, /-separated segments of letters, digits, '.', '_' and '-'`);
30
- return `/v1/sandboxes/${segment(sandboxId)}`;
31
- }
32
- /**
33
- * Creates the sandbox, or finds the one with this id (`PUT /v1/sandboxes/{id}`). Its spec is
34
- * fixed once it exists: a different one is a 409. Labels, when given, replace its labels.
35
- */
36
- async ensure(sandboxId, spec = {}, options = {}) {
37
- const path = this.path(sandboxId);
38
- await this.transport.requireFeature(FEATURE, options.signal);
39
- return this.transport.json(path, "PUT", { requestId: id(), ...spec }, options.signal);
40
- }
41
- async get(sandboxId, options = {}) {
42
- const path = this.path(sandboxId);
43
- await this.transport.requireFeature(FEATURE, options.signal);
44
- return this.transport.json(path, "GET", undefined, options.signal);
45
- }
46
- /** The sandboxes with every label in `labels` that this client reaches. */
47
- async list(options = {}) {
48
- await this.transport.requireFeature(FEATURE, options.signal);
49
- const query = new URLSearchParams();
50
- for (const [key, value] of Object.entries(options.labels ?? {}))
51
- query.append("label", `${key}=${value}`);
52
- const search = query.toString();
53
- const reply = await this.transport.json(`/v1/sandboxes${search ? `?${search}` : ""}`, "GET", undefined, options.signal);
54
- return reply.sandboxes;
55
- }
56
- async page(options = {}) {
57
- await this.transport.requireFeature("session-reads", options.signal);
58
- const query = new URLSearchParams({ limit: String(options.limit ?? 50) });
59
- if (options.cursor !== undefined)
60
- query.set("cursor", options.cursor);
61
- for (const [key, value] of Object.entries(options.labels ?? {}))
62
- query.append("label", `${key}=${value}`);
63
- return SandboxPageSchema.parse(await this.transport.json(`/v1/sandboxes?${query}`, "GET", undefined, options.signal));
64
- }
65
- /** Deletes the sandbox and its files; `deleted` is false when there was none. */
66
- async delete(sandboxId, options = {}) {
67
- const path = this.path(sandboxId);
68
- await this.transport.requireFeature(FEATURE, options.signal);
69
- return this.transport.json(path, "DELETE", undefined, options.signal);
70
- }
71
- /** The sandbox's lifecycle events, from `from` on. */
72
- async events(sandboxId, options = {}) {
73
- const path = this.path(sandboxId);
74
- await this.transport.requireFeature(FEATURE, options.signal);
75
- const reply = await this.transport.json(`${path}/events${options.from === undefined ? "" : `?from=${options.from}`}`, "GET", undefined, options.signal);
76
- return reply.events;
77
- }
78
- /**
79
- * One sandbox for one session: creates the sandbox (`sessions/<session id>` unless
80
- * `sandboxId` names another), opens the session attached to it, and returns both with
81
- * `release()`, which deletes the sandbox. If the session cannot be opened, the sandbox is
82
- * deleted again.
83
- */
84
- async forSession(options) {
85
- const sessionId = options.session.id ?? id();
86
- const sandboxId = options.sandboxId ??
87
- (isSandboxId(`sessions/${sessionId}`) ? `sessions/${sessionId}` : `sessions/${id()}`);
88
- const sandbox = await this.ensure(sandboxId, options.spec ?? {}, {
89
- ...(options.signal ? { signal: options.signal } : {}),
90
- });
91
- let session;
92
- try {
93
- session = await this.createSession({
94
- ...options.session,
95
- id: sessionId,
96
- sandbox: { id: sandboxId },
97
- });
98
- }
99
- catch (error) {
100
- await this.delete(sandboxId).catch(() => undefined);
101
- throw error;
102
- }
103
- return {
104
- session,
105
- sandbox,
106
- release: (release = {}) => this.delete(sandboxId, release),
107
- };
108
- }
109
- }
@@ -1,5 +0,0 @@
1
- export declare const SKILLS_USAGE = "The following skills provide specialized instructions. When a task matches a skill description, call load_skill with that name before proceeding.";
2
- export declare function formatSkillCatalog(skills: readonly {
3
- name: string;
4
- description: string;
5
- }[]): string;
@@ -1,14 +0,0 @@
1
- export const SKILLS_USAGE = "The following skills provide specialized instructions. When a task matches a skill description, call load_skill with that name before proceeding.";
2
- export function formatSkillCatalog(skills) {
3
- const entries = skills
4
- .map((skill) => ` <skill>\n <name>${escapeXml(skill.name)}</name>\n <description>${escapeXml(skill.description)}</description>\n </skill>`)
5
- .join("\n");
6
- return `<available_skills>\n${entries}\n</available_skills>`;
7
- }
8
- function escapeXml(value) {
9
- return value
10
- .replaceAll("&", "&amp;")
11
- .replaceAll("<", "&lt;")
12
- .replaceAll(">", "&gt;")
13
- .replaceAll('"', "&quot;");
14
- }