@nylorun/agents 0.19.1-beta → 0.20.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/CHANGELOG.md +76 -0
- package/README.md +165 -96
- package/dist/ag-ui/handler.d.ts +4 -4
- package/dist/artifacts.d.ts +14 -1
- package/dist/artifacts.js +28 -0
- package/dist/environments.d.ts +217 -0
- package/dist/environments.js +174 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/reads.d.ts +1 -1
- package/dist/session-client.d.ts +101 -18
- package/dist/session-client.js +36 -16
- package/package.json +4 -4
- package/dist/sandboxes.d.ts +0 -106
- package/dist/sandboxes.js +0 -109
package/dist/artifacts.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Artifacts (protocol 6): `client.artifacts`. A file is uploaded in one streamed request and
|
|
3
|
+
* kept as an artifact with numbered versions; a session's artifacts appear in its history as
|
|
4
|
+
* `artifact.*` events. Download through the Runtime (with Range), or mint a capability link: a
|
|
5
|
+
* short-lived URL that needs no credential, for `<img>` tags and sharing. A message names an
|
|
6
|
+
* artifact in a file part (`session.inputParts`), and the model reads it.
|
|
7
|
+
*
|
|
8
|
+
* Folders (F8.2): at the end of each turn the Runtime exports `/workspace/outputs` of the
|
|
9
|
+
* session's sandbox as a version of its `outputs` folder. Read one as a tree, one file by path,
|
|
10
|
+
* a diff between versions or a zip.
|
|
11
|
+
*
|
|
12
|
+
* Acting for a person (`client.as`, or a trusted issuer's token), only the artifacts of their own sessions.
|
|
13
|
+
*/
|
|
14
|
+
import { ArtifactPageSchema, } from "@nylorun/core/contracts";
|
|
1
15
|
import { segment } from "./http.js";
|
|
2
16
|
function contentTypeOf(body, declared) {
|
|
3
17
|
if (declared)
|
|
@@ -46,6 +60,20 @@ export class ArtifactsClient {
|
|
|
46
60
|
const reply = await this.transport.json(`/v1/artifacts${query}`, "GET", undefined, options.signal);
|
|
47
61
|
return reply.artifacts;
|
|
48
62
|
}
|
|
63
|
+
/** Newest first, with metadata only (Host feature `artifact-reads`). */
|
|
64
|
+
async page(options = {}) {
|
|
65
|
+
await this.transport.requireFeature("artifact-reads", options.signal);
|
|
66
|
+
const query = new URLSearchParams({ limit: String(options.limit ?? 50) });
|
|
67
|
+
if (options.cursor !== undefined)
|
|
68
|
+
query.set("cursor", options.cursor);
|
|
69
|
+
if (options.sessionId !== undefined)
|
|
70
|
+
query.set("sessionId", options.sessionId);
|
|
71
|
+
if (options.kind !== undefined)
|
|
72
|
+
query.set("kind", options.kind);
|
|
73
|
+
for (const [key, value] of Object.entries(options.labels ?? {}))
|
|
74
|
+
query.append("label", `${key}=${value}`);
|
|
75
|
+
return ArtifactPageSchema.parse(await this.transport.json(`/v1/artifacts?${query}`, "GET", undefined, options.signal));
|
|
76
|
+
}
|
|
49
77
|
/** The artifact, with every version. */
|
|
50
78
|
get(artifactId, options = {}) {
|
|
51
79
|
return this.transport.json(`/v1/artifacts/${segment(artifactId)}`, "GET", undefined, options.signal);
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environments (protocol 11, D55, D56): `client.environments`. An Environment is one sandbox
|
|
3
|
+
* (kind `virtual`, `pod` or `none`) with a recipe that can change, and one vault of secrets for
|
|
4
|
+
* its shell, MCP servers and HTTP tools. It has its own id and outlives the sessions that name
|
|
5
|
+
* it; whether it serves one session, one person or a project is the app's choice, made here:
|
|
6
|
+
*
|
|
7
|
+
* - `environments.forSession(...)`: one Environment for one session. It creates the
|
|
8
|
+
* Environment, opens the session on it, and `release()` deletes the Environment (and its
|
|
9
|
+
* vault) when the session is done.
|
|
10
|
+
* - `environments.put(id, recipe)`: one Environment per person or per project, by a
|
|
11
|
+
* deterministic id (`users/alice/web`); get-or-create, or change its recipe, in one call.
|
|
12
|
+
* Write its secrets with `environments.secrets.put(id, name, secret)` and open sessions on it
|
|
13
|
+
* with `createSession({ environment: id })`.
|
|
14
|
+
*
|
|
15
|
+
* Ids may hold `/`; they are sent percent-encoded as one path segment. Secret values are
|
|
16
|
+
* write-only: no call reads one back.
|
|
17
|
+
*
|
|
18
|
+
* Disk versions (Host feature `environment-disk-versions`): `snapshot(id)` keeps a version of
|
|
19
|
+
* the Environment's disk between turns, `restore(id, version)` puts one back, and
|
|
20
|
+
* `put(id, { from: { environment, version } })` creates a new Environment from another's version.
|
|
21
|
+
*/
|
|
22
|
+
import { type DeleteEnvironmentResponse, type EnvironmentEvent, type EnvironmentRestore, type EnvironmentSecretView, type EnvironmentSnapshot, type EnvironmentVersions, type EnvironmentView, type PutEnvironmentRequest, type PutEnvironmentSecretRequest } from "@nylorun/core/contracts";
|
|
23
|
+
import { type Transport } from "./http.js";
|
|
24
|
+
import type { CreateSessionOptions, SessionClient } from "./session-client.js";
|
|
25
|
+
/** What an Environment is made of: its kind, recipe, labels and owner guard. */
|
|
26
|
+
export type EnvironmentRecipeInput = Omit<PutEnvironmentRequest, "requestId">;
|
|
27
|
+
/** One secret of an Environment's vault, as written. */
|
|
28
|
+
export type EnvironmentSecretInput = PutEnvironmentSecretRequest;
|
|
29
|
+
/** A session opened on an Environment of its own (`environments.forSession`). */
|
|
30
|
+
export interface SessionEnvironmentHandle {
|
|
31
|
+
readonly session: SessionClient;
|
|
32
|
+
readonly environment: EnvironmentView;
|
|
33
|
+
/** Deletes the Environment, its vault and its files; call it when the session is done. */
|
|
34
|
+
release(options?: {
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}): Promise<DeleteEnvironmentResponse>;
|
|
37
|
+
}
|
|
38
|
+
export interface ForSessionOptions {
|
|
39
|
+
/** The session to open, as `createSession` takes it, without `environment`. */
|
|
40
|
+
readonly session: Omit<CreateSessionOptions, "environment">;
|
|
41
|
+
/** The Environment's recipe and labels. Default: a virtual one within the Tenant's defaults. */
|
|
42
|
+
readonly recipe?: EnvironmentRecipeInput;
|
|
43
|
+
/** Secrets to write before the session opens, by name. */
|
|
44
|
+
readonly secrets?: Readonly<Record<string, EnvironmentSecretInput>>;
|
|
45
|
+
/** The Environment's id. Default: `sessions/<session id>`. */
|
|
46
|
+
readonly environmentId?: string;
|
|
47
|
+
readonly signal?: AbortSignal;
|
|
48
|
+
}
|
|
49
|
+
/** An Environment's secrets: `client.environments.secrets`. */
|
|
50
|
+
export declare class EnvironmentSecretsClient {
|
|
51
|
+
private readonly transport;
|
|
52
|
+
private readonly path;
|
|
53
|
+
constructor(transport: Transport, path: (environmentId: string) => string);
|
|
54
|
+
/**
|
|
55
|
+
* Creates or replaces secret `name` (`PUT /v1/environments/{id}/secrets/{name}`): for
|
|
56
|
+
* `environment_secret` and `environment_variable` the name is the variable's. A second
|
|
57
|
+
* credential for a host or a URL is a 409 `credential_conflict`.
|
|
58
|
+
*/
|
|
59
|
+
put(environmentId: string, name: string, secret: EnvironmentSecretInput, options?: {
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}): Promise<EnvironmentSecretView>;
|
|
62
|
+
/** The secrets' names, types and bindings; never a value. */
|
|
63
|
+
list(environmentId: string, options?: {
|
|
64
|
+
signal?: AbortSignal;
|
|
65
|
+
}): Promise<EnvironmentSecretView[]>;
|
|
66
|
+
get(environmentId: string, name: string, options?: {
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
}): Promise<EnvironmentSecretView>;
|
|
69
|
+
delete(environmentId: string, name: string, options?: {
|
|
70
|
+
signal?: AbortSignal;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
id: string;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
export declare class EnvironmentsClient {
|
|
76
|
+
private readonly transport;
|
|
77
|
+
/** `AgentsClient.createSession`, bound. */
|
|
78
|
+
private readonly createSession;
|
|
79
|
+
constructor(transport: Transport,
|
|
80
|
+
/** `AgentsClient.createSession`, bound. */
|
|
81
|
+
createSession: (options: CreateSessionOptions) => Promise<SessionClient>);
|
|
82
|
+
private path;
|
|
83
|
+
/** The Environment's secrets. */
|
|
84
|
+
get secrets(): EnvironmentSecretsClient;
|
|
85
|
+
/**
|
|
86
|
+
* Creates the Environment and its vault, or finds the one with this id
|
|
87
|
+
* (`PUT /v1/environments/{id}`). On an existing one, `kind` and `storage` are fixed (a
|
|
88
|
+
* different one is a 409), labels replace, and any other change writes the recipe and bumps
|
|
89
|
+
* its `version`: a pod's image and resources apply when it next starts from stopped.
|
|
90
|
+
*/
|
|
91
|
+
put(environmentId: string, recipe?: EnvironmentRecipeInput, options?: {
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
}): Promise<EnvironmentView>;
|
|
94
|
+
get(environmentId: string, options?: {
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
}): Promise<EnvironmentView>;
|
|
97
|
+
/** The Environments with every label in `labels` that this client reaches. */
|
|
98
|
+
list(options?: {
|
|
99
|
+
labels?: Readonly<Record<string, string>>;
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
}): Promise<EnvironmentView[]>;
|
|
102
|
+
page(options?: {
|
|
103
|
+
labels?: Readonly<Record<string, string>>;
|
|
104
|
+
limit?: number;
|
|
105
|
+
cursor?: string;
|
|
106
|
+
signal?: AbortSignal;
|
|
107
|
+
}): Promise<{
|
|
108
|
+
environments: {
|
|
109
|
+
id: string;
|
|
110
|
+
kind: "none" | "pod" | "virtual";
|
|
111
|
+
labels: Record<string, string>;
|
|
112
|
+
recipe: {
|
|
113
|
+
image?: string | undefined;
|
|
114
|
+
resources?: {
|
|
115
|
+
cpus: number;
|
|
116
|
+
memory: string;
|
|
117
|
+
} | undefined;
|
|
118
|
+
storage?: string | undefined;
|
|
119
|
+
network?: {
|
|
120
|
+
allowedHosts: string[];
|
|
121
|
+
} | undefined;
|
|
122
|
+
harness: string;
|
|
123
|
+
lifecycle: {
|
|
124
|
+
idle?: string | undefined;
|
|
125
|
+
deleteAfter?: string | undefined;
|
|
126
|
+
};
|
|
127
|
+
setup?: {
|
|
128
|
+
command: string;
|
|
129
|
+
cwd?: string | undefined;
|
|
130
|
+
timeout?: string | undefined;
|
|
131
|
+
}[] | undefined;
|
|
132
|
+
files?: {
|
|
133
|
+
artifactId: string;
|
|
134
|
+
version: number;
|
|
135
|
+
path: string;
|
|
136
|
+
}[] | undefined;
|
|
137
|
+
};
|
|
138
|
+
version: number;
|
|
139
|
+
appliedVersion: number;
|
|
140
|
+
ownerUserId: string | null;
|
|
141
|
+
state: string;
|
|
142
|
+
pod?: {
|
|
143
|
+
desired: "deleted" | "running" | "suspended";
|
|
144
|
+
observed: "creating" | "deleting" | "failed" | "lost" | "running" | "suspended";
|
|
145
|
+
volumeGeneration: number;
|
|
146
|
+
hostEpoch: number;
|
|
147
|
+
reason?: string | undefined;
|
|
148
|
+
} | undefined;
|
|
149
|
+
lastUsedAt: string;
|
|
150
|
+
disk?: {
|
|
151
|
+
latestVersion: number | null;
|
|
152
|
+
operation?: {
|
|
153
|
+
kind: "restore" | "seed" | "snapshot";
|
|
154
|
+
version?: number | undefined;
|
|
155
|
+
startedAt: string;
|
|
156
|
+
} | undefined;
|
|
157
|
+
} | undefined;
|
|
158
|
+
sessions: {
|
|
159
|
+
id: string;
|
|
160
|
+
activeTurnId: string | null;
|
|
161
|
+
}[];
|
|
162
|
+
createdAt: string;
|
|
163
|
+
updatedAt: string;
|
|
164
|
+
}[];
|
|
165
|
+
nextCursor: string | null;
|
|
166
|
+
}>;
|
|
167
|
+
/** Stops a pod Environment: its volume is kept, and the next turn starts it again. */
|
|
168
|
+
stop(environmentId: string, options?: {
|
|
169
|
+
signal?: AbortSignal;
|
|
170
|
+
}): Promise<EnvironmentView>;
|
|
171
|
+
/** Resets a pod Environment: a new pod on a new, empty volume, with its recipe applied. */
|
|
172
|
+
reset(environmentId: string, options?: {
|
|
173
|
+
signal?: AbortSignal;
|
|
174
|
+
}): Promise<EnvironmentView>;
|
|
175
|
+
/**
|
|
176
|
+
* Keeps a version of the Environment's disk (`POST /v1/environments/{id}/snapshot`), between
|
|
177
|
+
* turns; `unchanged` when the disk is as the latest version has it.
|
|
178
|
+
*/
|
|
179
|
+
snapshot(environmentId: string, options?: {
|
|
180
|
+
signal?: AbortSignal;
|
|
181
|
+
}): Promise<EnvironmentSnapshot>;
|
|
182
|
+
/**
|
|
183
|
+
* Puts disk version `version` back: at once for a virtual Environment (`done`), on a new volume
|
|
184
|
+
* seeded before the next turn for a pod (`pending`).
|
|
185
|
+
*/
|
|
186
|
+
restore(environmentId: string, version: number | "latest", options?: {
|
|
187
|
+
signal?: AbortSignal;
|
|
188
|
+
}): Promise<EnvironmentRestore>;
|
|
189
|
+
/** The Environment's disk versions, newest first. */
|
|
190
|
+
versions(environmentId: string, options?: {
|
|
191
|
+
signal?: AbortSignal;
|
|
192
|
+
}): Promise<EnvironmentVersions>;
|
|
193
|
+
/** Deletes disk version `version`; `deleted` is false when there was none. */
|
|
194
|
+
deleteVersion(environmentId: string, version: number, options?: {
|
|
195
|
+
signal?: AbortSignal;
|
|
196
|
+
}): Promise<{
|
|
197
|
+
environmentId: string;
|
|
198
|
+
version: number;
|
|
199
|
+
deleted: boolean;
|
|
200
|
+
}>;
|
|
201
|
+
/** Deletes the Environment, its vault and its files; `deleted` is false when there was none. */
|
|
202
|
+
delete(environmentId: string, options?: {
|
|
203
|
+
signal?: AbortSignal;
|
|
204
|
+
}): Promise<DeleteEnvironmentResponse>;
|
|
205
|
+
/** The Environment's lifecycle events, from `from` on. */
|
|
206
|
+
events(environmentId: string, options?: {
|
|
207
|
+
from?: number;
|
|
208
|
+
signal?: AbortSignal;
|
|
209
|
+
}): Promise<EnvironmentEvent[]>;
|
|
210
|
+
/**
|
|
211
|
+
* One Environment for one session: creates the Environment (`sessions/<session id>` unless
|
|
212
|
+
* `environmentId` names another), writes `secrets`, opens the session on it, and returns both
|
|
213
|
+
* with `release()`, which deletes the Environment. If the session cannot be opened, the
|
|
214
|
+
* Environment is deleted again.
|
|
215
|
+
*/
|
|
216
|
+
forSession(options: ForSessionOptions): Promise<SessionEnvironmentHandle>;
|
|
217
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environments (protocol 11, D55, D56): `client.environments`. An Environment is one sandbox
|
|
3
|
+
* (kind `virtual`, `pod` or `none`) with a recipe that can change, and one vault of secrets for
|
|
4
|
+
* its shell, MCP servers and HTTP tools. It has its own id and outlives the sessions that name
|
|
5
|
+
* it; whether it serves one session, one person or a project is the app's choice, made here:
|
|
6
|
+
*
|
|
7
|
+
* - `environments.forSession(...)`: one Environment for one session. It creates the
|
|
8
|
+
* Environment, opens the session on it, and `release()` deletes the Environment (and its
|
|
9
|
+
* vault) when the session is done.
|
|
10
|
+
* - `environments.put(id, recipe)`: one Environment per person or per project, by a
|
|
11
|
+
* deterministic id (`users/alice/web`); get-or-create, or change its recipe, in one call.
|
|
12
|
+
* Write its secrets with `environments.secrets.put(id, name, secret)` and open sessions on it
|
|
13
|
+
* with `createSession({ environment: id })`.
|
|
14
|
+
*
|
|
15
|
+
* Ids may hold `/`; they are sent percent-encoded as one path segment. Secret values are
|
|
16
|
+
* write-only: no call reads one back.
|
|
17
|
+
*
|
|
18
|
+
* Disk versions (Host feature `environment-disk-versions`): `snapshot(id)` keeps a version of
|
|
19
|
+
* the Environment's disk between turns, `restore(id, version)` puts one back, and
|
|
20
|
+
* `put(id, { from: { environment, version } })` creates a new Environment from another's version.
|
|
21
|
+
*/
|
|
22
|
+
import { EnvironmentPageSchema, isEnvironmentId, } from "@nylorun/core/contracts";
|
|
23
|
+
import { id, segment } from "./http.js";
|
|
24
|
+
/** An Environment's secrets: `client.environments.secrets`. */
|
|
25
|
+
export class EnvironmentSecretsClient {
|
|
26
|
+
transport;
|
|
27
|
+
path;
|
|
28
|
+
constructor(transport, path) {
|
|
29
|
+
this.transport = transport;
|
|
30
|
+
this.path = path;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates or replaces secret `name` (`PUT /v1/environments/{id}/secrets/{name}`): for
|
|
34
|
+
* `environment_secret` and `environment_variable` the name is the variable's. A second
|
|
35
|
+
* credential for a host or a URL is a 409 `credential_conflict`.
|
|
36
|
+
*/
|
|
37
|
+
async put(environmentId, name, secret, options = {}) {
|
|
38
|
+
return this.transport.json(`${this.path(environmentId)}/secrets/${segment(name)}`, "PUT", { requestId: id(), ...secret }, options.signal);
|
|
39
|
+
}
|
|
40
|
+
/** The secrets' names, types and bindings; never a value. */
|
|
41
|
+
async list(environmentId, options = {}) {
|
|
42
|
+
const reply = await this.transport.json(`${this.path(environmentId)}/secrets`, "GET", undefined, options.signal);
|
|
43
|
+
return reply.secrets;
|
|
44
|
+
}
|
|
45
|
+
async get(environmentId, name, options = {}) {
|
|
46
|
+
return this.transport.json(`${this.path(environmentId)}/secrets/${segment(name)}`, "GET", undefined, options.signal);
|
|
47
|
+
}
|
|
48
|
+
async delete(environmentId, name, options = {}) {
|
|
49
|
+
return this.transport.json(`${this.path(environmentId)}/secrets/${segment(name)}`, "DELETE", undefined, options.signal);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class EnvironmentsClient {
|
|
53
|
+
transport;
|
|
54
|
+
createSession;
|
|
55
|
+
constructor(transport,
|
|
56
|
+
/** `AgentsClient.createSession`, bound. */
|
|
57
|
+
createSession) {
|
|
58
|
+
this.transport = transport;
|
|
59
|
+
this.createSession = createSession;
|
|
60
|
+
}
|
|
61
|
+
path(environmentId) {
|
|
62
|
+
if (!isEnvironmentId(environmentId))
|
|
63
|
+
throw new TypeError(`${environmentId} is not an Environment id: up to 200 characters, /-separated segments of letters, digits, '.', '_' and '-'`);
|
|
64
|
+
return `/v1/environments/${segment(environmentId)}`;
|
|
65
|
+
}
|
|
66
|
+
/** The Environment's secrets. */
|
|
67
|
+
get secrets() {
|
|
68
|
+
return new EnvironmentSecretsClient(this.transport, (environmentId) => this.path(environmentId));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates the Environment and its vault, or finds the one with this id
|
|
72
|
+
* (`PUT /v1/environments/{id}`). On an existing one, `kind` and `storage` are fixed (a
|
|
73
|
+
* different one is a 409), labels replace, and any other change writes the recipe and bumps
|
|
74
|
+
* its `version`: a pod's image and resources apply when it next starts from stopped.
|
|
75
|
+
*/
|
|
76
|
+
async put(environmentId, recipe = {}, options = {}) {
|
|
77
|
+
return this.transport.json(this.path(environmentId), "PUT", { requestId: id(), ...recipe }, options.signal);
|
|
78
|
+
}
|
|
79
|
+
async get(environmentId, options = {}) {
|
|
80
|
+
return this.transport.json(this.path(environmentId), "GET", undefined, options.signal);
|
|
81
|
+
}
|
|
82
|
+
/** The Environments with every label in `labels` that this client reaches. */
|
|
83
|
+
async list(options = {}) {
|
|
84
|
+
const query = new URLSearchParams();
|
|
85
|
+
for (const [key, value] of Object.entries(options.labels ?? {}))
|
|
86
|
+
query.append("label", `${key}=${value}`);
|
|
87
|
+
const search = query.toString();
|
|
88
|
+
const reply = await this.transport.json(`/v1/environments${search ? `?${search}` : ""}`, "GET", undefined, options.signal);
|
|
89
|
+
return reply.environments;
|
|
90
|
+
}
|
|
91
|
+
async page(options = {}) {
|
|
92
|
+
await this.transport.requireFeature("session-reads", options.signal);
|
|
93
|
+
const query = new URLSearchParams({ limit: String(options.limit ?? 50) });
|
|
94
|
+
if (options.cursor !== undefined)
|
|
95
|
+
query.set("cursor", options.cursor);
|
|
96
|
+
for (const [key, value] of Object.entries(options.labels ?? {}))
|
|
97
|
+
query.append("label", `${key}=${value}`);
|
|
98
|
+
return EnvironmentPageSchema.parse(await this.transport.json(`/v1/environments?${query}`, "GET", undefined, options.signal));
|
|
99
|
+
}
|
|
100
|
+
/** Stops a pod Environment: its volume is kept, and the next turn starts it again. */
|
|
101
|
+
async stop(environmentId, options = {}) {
|
|
102
|
+
return this.transport.json(`${this.path(environmentId)}/stop`, "POST", {}, options.signal);
|
|
103
|
+
}
|
|
104
|
+
/** Resets a pod Environment: a new pod on a new, empty volume, with its recipe applied. */
|
|
105
|
+
async reset(environmentId, options = {}) {
|
|
106
|
+
return this.transport.json(`${this.path(environmentId)}/reset`, "POST", {}, options.signal);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Keeps a version of the Environment's disk (`POST /v1/environments/{id}/snapshot`), between
|
|
110
|
+
* turns; `unchanged` when the disk is as the latest version has it.
|
|
111
|
+
*/
|
|
112
|
+
async snapshot(environmentId, options = {}) {
|
|
113
|
+
await this.transport.requireFeature("environment-disk-versions", options.signal);
|
|
114
|
+
return this.transport.json(`${this.path(environmentId)}/snapshot`, "POST", {}, options.signal);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Puts disk version `version` back: at once for a virtual Environment (`done`), on a new volume
|
|
118
|
+
* seeded before the next turn for a pod (`pending`).
|
|
119
|
+
*/
|
|
120
|
+
async restore(environmentId, version, options = {}) {
|
|
121
|
+
await this.transport.requireFeature("environment-disk-versions", options.signal);
|
|
122
|
+
return this.transport.json(`${this.path(environmentId)}/restore`, "POST", { requestId: id(), version }, options.signal);
|
|
123
|
+
}
|
|
124
|
+
/** The Environment's disk versions, newest first. */
|
|
125
|
+
async versions(environmentId, options = {}) {
|
|
126
|
+
await this.transport.requireFeature("environment-disk-versions", options.signal);
|
|
127
|
+
return this.transport.json(`${this.path(environmentId)}/versions`, "GET", undefined, options.signal);
|
|
128
|
+
}
|
|
129
|
+
/** Deletes disk version `version`; `deleted` is false when there was none. */
|
|
130
|
+
async deleteVersion(environmentId, version, options = {}) {
|
|
131
|
+
return this.transport.json(`${this.path(environmentId)}/versions/${version}`, "DELETE", undefined, options.signal);
|
|
132
|
+
}
|
|
133
|
+
/** Deletes the Environment, its vault and its files; `deleted` is false when there was none. */
|
|
134
|
+
async delete(environmentId, options = {}) {
|
|
135
|
+
return this.transport.json(this.path(environmentId), "DELETE", undefined, options.signal);
|
|
136
|
+
}
|
|
137
|
+
/** The Environment's lifecycle events, from `from` on. */
|
|
138
|
+
async events(environmentId, options = {}) {
|
|
139
|
+
const reply = await this.transport.json(`${this.path(environmentId)}/events${options.from === undefined ? "" : `?from=${options.from}`}`, "GET", undefined, options.signal);
|
|
140
|
+
return reply.events;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* One Environment for one session: creates the Environment (`sessions/<session id>` unless
|
|
144
|
+
* `environmentId` names another), writes `secrets`, opens the session on it, and returns both
|
|
145
|
+
* with `release()`, which deletes the Environment. If the session cannot be opened, the
|
|
146
|
+
* Environment is deleted again.
|
|
147
|
+
*/
|
|
148
|
+
async forSession(options) {
|
|
149
|
+
const sessionId = options.session.id ?? id();
|
|
150
|
+
const environmentId = options.environmentId ??
|
|
151
|
+
(isEnvironmentId(`sessions/${sessionId}`) ? `sessions/${sessionId}` : `sessions/${id()}`);
|
|
152
|
+
const signal = options.signal ? { signal: options.signal } : {};
|
|
153
|
+
const environment = await this.put(environmentId, options.recipe ?? {}, signal);
|
|
154
|
+
let session;
|
|
155
|
+
try {
|
|
156
|
+
for (const [name, secret] of Object.entries(options.secrets ?? {}))
|
|
157
|
+
await this.secrets.put(environmentId, name, secret, signal);
|
|
158
|
+
session = await this.createSession({
|
|
159
|
+
...options.session,
|
|
160
|
+
id: sessionId,
|
|
161
|
+
environment: environmentId,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
await this.delete(environmentId).catch(() => undefined);
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
session,
|
|
170
|
+
environment,
|
|
171
|
+
release: (release = {}) => this.delete(environmentId, release),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ export { Agent, AgentBuilder } from "./builder.js";
|
|
|
6
6
|
export { AgentBuildError, AgentLifecycleError, VerdictSchema, isVerdict, WorkflowBuildError, isBuiltWorkflow, capability, CapabilityBuilder, flow, tool, http, defineSchema, ToolError, } from "@nylorun/core/define";
|
|
7
7
|
export type { FlowAgentBuilder, Flow, Named, LoopOptions, StageOptions, CapabilityIdentity, HttpTarget, } from "@nylorun/core/define";
|
|
8
8
|
export type { AgentOptions, AgentManifest, BuiltAgent, BuiltWorkflow, Verdict, WorkflowBinding, WorkflowManifest, ToolDefinition, ToolExecutionContext, ToolOutcome, JsonValue, JsonObject, } from "@nylorun/core/define";
|
|
9
|
-
export type { SessionPage, SessionListItem, SessionManifestView, HistoryPage, SessionUsageTotals, ModelCall, ModelCallsPage,
|
|
9
|
+
export type { SessionPage, SessionListItem, SessionManifestView, HistoryPage, SessionUsageTotals, ModelCall, ModelCallsPage, EnvironmentPage, ToolCall, ToolCallsPage, LiveEvent, SessionEvent, SessionEventOf, EventType, SessionCommand, SubjectScope, EnvironmentView, EnvironmentEvent, EnvironmentKind, EnvironmentRecipe, EnvironmentSecretView, EnvironmentSnapshot, EnvironmentRestore, EnvironmentVersions, RestoreEnvironmentRequest, MessagePart, ArtifactView, ArtifactKind, ArtifactListItem, ArtifactPage, ArtifactVersionView, ArtifactLink, UploadArtifactResponse, DefinitionFileView, ArtifactTree, ArtifactDiff, FolderEntry, } from "@nylorun/core/contracts";
|
|
10
10
|
export { SUBJECT_SCOPES } from "@nylorun/core/contracts";
|
|
11
11
|
export { AgentsClient, SessionClient, createClient } from "./client.js";
|
|
12
12
|
export { ArtifactsClient } from "./artifacts.js";
|
|
13
13
|
export { FilesClient, definitionFileHash } from "./files.js";
|
|
14
|
-
export type { ArtifactBody, ArtifactLinkWithUrl, UploadArtifactOptions, } from "./artifacts.js";
|
|
15
|
-
export type { ActAsOptions, AgentSource, SessionView, CommandOptions, CreateSessionOptions, SessionSandbox, ForSessionOptions,
|
|
16
|
-
export {
|
|
14
|
+
export type { ArtifactBody, ArtifactPageOptions, ArtifactLinkWithUrl, UploadArtifactOptions, } from "./artifacts.js";
|
|
15
|
+
export type { ActAsOptions, AgentSource, SessionView, CommandOptions, CreateSessionOptions, SessionSandbox, ForSessionOptions, EnvironmentRecipeInput, EnvironmentSecretInput, SessionEnvironmentHandle, } from "./client.js";
|
|
16
|
+
export { EnvironmentsClient, EnvironmentSecretsClient } from "./client.js";
|
|
17
17
|
export { AccessClient } from "./access.js";
|
|
18
18
|
export { resolveConnection, ConnectionError } from "./connection.js";
|
|
19
19
|
export type { ResolvedConnection } from "./connection.js";
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { SUBJECT_SCOPES } from "@nylorun/core/contracts";
|
|
|
8
8
|
export { AgentsClient, SessionClient, createClient } from "./client.js";
|
|
9
9
|
export { ArtifactsClient } from "./artifacts.js";
|
|
10
10
|
export { FilesClient, definitionFileHash } from "./files.js";
|
|
11
|
-
export {
|
|
11
|
+
export { EnvironmentsClient, EnvironmentSecretsClient } from "./client.js";
|
|
12
12
|
export { AccessClient } from "./access.js";
|
|
13
13
|
export { resolveConnection, ConnectionError } from "./connection.js";
|
|
14
14
|
export { RuntimeError, IncompatibleRuntimeError } from "./http.js";
|
package/dist/reads.d.ts
CHANGED
package/dist/session-client.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* which resolves the connection from the environment or the Project link.
|
|
4
4
|
*/
|
|
5
5
|
import type { AgentManifest, BuiltAgent, BuiltWorkflow, JsonValue, SandboxToolName, WorkflowManifest } from "@nylorun/core/define";
|
|
6
|
-
import { type SessionItemsResponse, type SessionSummary, type ListAgentsResponse, type ListPublicAgentsResponse, type SubjectScope, type
|
|
6
|
+
import { type SessionItemsResponse, type SessionSummary, type ListAgentsResponse, type ListPublicAgentsResponse, type SubjectScope, type MessagePart, type SessionCommand } from "@nylorun/core/contracts";
|
|
7
7
|
import { SessionsReadClient } from "./reads.js";
|
|
8
8
|
import { AccessClient } from "./access.js";
|
|
9
|
-
import {
|
|
9
|
+
import { EnvironmentsClient } from "./environments.js";
|
|
10
10
|
import { ArtifactsClient } from "./artifacts.js";
|
|
11
11
|
import { FilesClient } from "./files.js";
|
|
12
12
|
import { Transport, type Destination } from "./http.js";
|
|
@@ -38,16 +38,12 @@ export interface CreateSessionOptions {
|
|
|
38
38
|
ownerUserId: string;
|
|
39
39
|
info?: Record<string, unknown>;
|
|
40
40
|
requestId?: string;
|
|
41
|
-
vaultIds?: readonly string[];
|
|
42
|
-
credentialSelections?: readonly CredentialSelection[];
|
|
43
41
|
/**
|
|
44
|
-
* The
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* shares another session's and is deprecated: use `client.sandboxes.forSession()` or
|
|
48
|
-
* `ensure()` and `{ id }`. Fixed once the session exists.
|
|
42
|
+
* The Environment the session runs in (`client.environments`): its sandbox, and its vault's
|
|
43
|
+
* credentials for the session's shell, MCP servers and HTTP tools. Omit for no sandbox and no
|
|
44
|
+
* credentials. Fixed once the session exists.
|
|
49
45
|
*/
|
|
50
|
-
|
|
46
|
+
environment?: string;
|
|
51
47
|
}
|
|
52
48
|
export interface ActAsOptions {
|
|
53
49
|
/** What the subject may do; the Runtime grants nothing else. Default `["sessions:own"]`. */
|
|
@@ -61,17 +57,18 @@ export declare class AgentsClient {
|
|
|
61
57
|
/**
|
|
62
58
|
* A client that acts for `subject`: every call sends `Nylorun-Subject` and
|
|
63
59
|
* `Nylorun-Scopes`, and the Runtime limits it to the scopes and to the subject's own sessions
|
|
64
|
-
*
|
|
60
|
+
* (Host feature `subject-headers`). For app servers, which authenticate the person
|
|
65
61
|
* themselves and hold the key; nothing is minted, cached or refreshed.
|
|
66
62
|
*/
|
|
67
63
|
as(subject: string, options?: ActAsOptions): AgentsClient;
|
|
68
64
|
/** The public keys that verify the tokens the Tenant signs. */
|
|
69
65
|
get access(): AccessClient;
|
|
70
66
|
/**
|
|
71
|
-
*
|
|
72
|
-
* label, `delete` one, or give a session its own with
|
|
67
|
+
* Environments (protocol 11): `put` one by id (create, find or change), write its `secrets`,
|
|
68
|
+
* `list` them by label, `stop`, `reset` or `delete` one, or give a session its own with
|
|
69
|
+
* `forSession`.
|
|
73
70
|
*/
|
|
74
|
-
get
|
|
71
|
+
get environments(): EnvironmentsClient;
|
|
75
72
|
/** File artifacts: upload, list, download with Range, capability links (protocol 6). */
|
|
76
73
|
get artifacts(): ArtifactsClient;
|
|
77
74
|
/** Definition files: the skill files a definition names, by content hash. */
|
|
@@ -98,7 +95,7 @@ export declare class AgentsClient {
|
|
|
98
95
|
* Registers the agent's definition (`PUT /v1/agents/{id}`), first uploading the skill files
|
|
99
96
|
* it names that the Runtime does not hold. A definition with a tool that runs your code
|
|
100
97
|
* (`tool({ run })`, a flow's tool stage) is refused before anything is sent: the Runtime runs
|
|
101
|
-
*
|
|
98
|
+
* agents from their manifests alone. `implementationVersion` defaults to
|
|
102
99
|
* `NYLORUN_IMPLEMENTATION_VERSION`, else `dev`.
|
|
103
100
|
*/
|
|
104
101
|
saveAgent(agent: AgentSource | BuiltWorkflow, options?: {
|
|
@@ -206,6 +203,7 @@ export declare class SessionClient {
|
|
|
206
203
|
}): Promise<{
|
|
207
204
|
calls: {
|
|
208
205
|
id: string;
|
|
206
|
+
effectId: string;
|
|
209
207
|
sessionId: string;
|
|
210
208
|
turnId: string;
|
|
211
209
|
agentId: string;
|
|
@@ -229,6 +227,87 @@ export declare class SessionClient {
|
|
|
229
227
|
nextCursor: string | null;
|
|
230
228
|
asOf: string;
|
|
231
229
|
}>;
|
|
230
|
+
/**
|
|
231
|
+
* The session's tool calls (R5, Host feature `tool-calls`), in the order they were first sent:
|
|
232
|
+
* each one's tool, input, status and sends. `attempts` above 1: a crash re-sent it.
|
|
233
|
+
*/
|
|
234
|
+
toolCalls(options?: {
|
|
235
|
+
turnId?: string;
|
|
236
|
+
limit?: number;
|
|
237
|
+
cursor?: string;
|
|
238
|
+
signal?: AbortSignal;
|
|
239
|
+
}): Promise<{
|
|
240
|
+
calls: {
|
|
241
|
+
effectId: string;
|
|
242
|
+
turnId: string;
|
|
243
|
+
callId: string | null;
|
|
244
|
+
capabilityId: string | null;
|
|
245
|
+
toolName: string | null;
|
|
246
|
+
kind: "http" | "mcp" | "platform" | "sandbox" | null;
|
|
247
|
+
server: string | null;
|
|
248
|
+
status: "cancelled" | "completed" | "failed" | "held" | "invoking" | "uncertain";
|
|
249
|
+
attempts: number;
|
|
250
|
+
input: unknown;
|
|
251
|
+
error: {
|
|
252
|
+
code: string;
|
|
253
|
+
message: string;
|
|
254
|
+
} | null;
|
|
255
|
+
startedAt: string | null;
|
|
256
|
+
settledAt: string | null;
|
|
257
|
+
durationMs: number | null;
|
|
258
|
+
}[];
|
|
259
|
+
nextCursor: string | null;
|
|
260
|
+
asOf: string;
|
|
261
|
+
}>;
|
|
262
|
+
/**
|
|
263
|
+
* A turn's trace (R7, Host feature `traces`): its spans as OTLP/HTTP JSON (`resourceSpans`), as
|
|
264
|
+
* the Runtime posts them to an OTLP collector. Post it to a collector's `/v1/traces` to backfill
|
|
265
|
+
* one, or read it without one.
|
|
266
|
+
*/
|
|
267
|
+
trace(turnId: string, options?: {
|
|
268
|
+
signal?: AbortSignal;
|
|
269
|
+
}): Promise<{
|
|
270
|
+
[x: string]: unknown;
|
|
271
|
+
resourceSpans: {
|
|
272
|
+
[x: string]: unknown;
|
|
273
|
+
resource: {
|
|
274
|
+
[x: string]: unknown;
|
|
275
|
+
attributes: {
|
|
276
|
+
[x: string]: unknown;
|
|
277
|
+
key: string;
|
|
278
|
+
value: Record<string, unknown>;
|
|
279
|
+
}[];
|
|
280
|
+
};
|
|
281
|
+
scopeSpans: {
|
|
282
|
+
[x: string]: unknown;
|
|
283
|
+
scope: {
|
|
284
|
+
[x: string]: unknown;
|
|
285
|
+
name: string;
|
|
286
|
+
version?: string | undefined;
|
|
287
|
+
};
|
|
288
|
+
spans: {
|
|
289
|
+
[x: string]: unknown;
|
|
290
|
+
traceId: string;
|
|
291
|
+
spanId: string;
|
|
292
|
+
parentSpanId?: string | undefined;
|
|
293
|
+
name: string;
|
|
294
|
+
kind: number;
|
|
295
|
+
startTimeUnixNano: string;
|
|
296
|
+
endTimeUnixNano: string;
|
|
297
|
+
attributes: {
|
|
298
|
+
[x: string]: unknown;
|
|
299
|
+
key: string;
|
|
300
|
+
value: Record<string, unknown>;
|
|
301
|
+
}[];
|
|
302
|
+
status: {
|
|
303
|
+
[x: string]: unknown;
|
|
304
|
+
code: number;
|
|
305
|
+
message?: string | undefined;
|
|
306
|
+
};
|
|
307
|
+
}[];
|
|
308
|
+
}[];
|
|
309
|
+
}[];
|
|
310
|
+
}>;
|
|
232
311
|
/** `agent` narrows to one agent used as a tool: its delegationId or its path. */
|
|
233
312
|
history(options: {
|
|
234
313
|
cursor?: string;
|
|
@@ -261,10 +340,14 @@ export declare class SessionClient {
|
|
|
261
340
|
time: string;
|
|
262
341
|
schemaVersion: number;
|
|
263
342
|
source: {
|
|
264
|
-
kind: "api" | "controller" | "edge" | "egress-gate" | "evidence" | "harness" | "human" | "init" | "loop" | "model-gate" | "operator" | "sandboxes" | "supervisor" | "tool-gate";
|
|
343
|
+
kind: "api" | "client" | "controller" | "core" | "edge" | "egress-gate" | "evidence" | "harness" | "human" | "init" | "loop" | "model-gate" | "operator" | "sandboxes" | "supervisor" | "tool-gate";
|
|
265
344
|
id: string;
|
|
266
345
|
};
|
|
267
346
|
evidence: "asserted" | "attested" | "claimed" | "measured" | "observed";
|
|
347
|
+
principal?: {
|
|
348
|
+
kind: "application" | "core" | "flow-host" | "subject";
|
|
349
|
+
id: string;
|
|
350
|
+
} | undefined;
|
|
268
351
|
trace?: {
|
|
269
352
|
traceId: string;
|
|
270
353
|
spanId: string;
|
|
@@ -286,5 +369,5 @@ export { RuntimeError, IncompatibleRuntimeError } from "./http.js";
|
|
|
286
369
|
export type { Destination, IncompatibleReason } from "./http.js";
|
|
287
370
|
export type { LiveEvent } from "@nylorun/core/contracts";
|
|
288
371
|
export { AccessClient } from "./access.js";
|
|
289
|
-
export {
|
|
290
|
-
export type { ForSessionOptions,
|
|
372
|
+
export { EnvironmentSecretsClient, EnvironmentsClient } from "./environments.js";
|
|
373
|
+
export type { EnvironmentRecipeInput, EnvironmentSecretInput, ForSessionOptions, SessionEnvironmentHandle, } from "./environments.js";
|