@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/builder.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import { Agent as CoreAgent, AgentBuilder as CoreAgentBuilder } from "@nylorun/core/define";
2
2
  import type { AgentOptions, ToolSchemaSource } from "@nylorun/core/define";
3
- import { type SkillsOptions } from "./skills/index.js";
4
3
  /**
5
- * The agent builder with the capabilities that read files: `.skills()` and `.plugin()`.
4
+ * The agent builder with the methods that read files: `.skills()` and `.plugin()`.
6
5
  * `@nylorun/agents/define` exports the portable builder from core, without them.
7
6
  */
8
7
  export declare class AgentBuilder<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined, Id extends string = string> extends CoreAgentBuilder<Info, Schema, Id> {
9
8
  /** Load an Agent Skills folder. */
10
- skills(directory: string, options?: SkillsOptions): this;
9
+ skills(directory: string): this;
11
10
  /** Attach an Agent Plugin package. */
12
11
  plugin(directory: string): this;
13
12
  output<S extends ToolSchemaSource>(schema: S): AgentBuilder<Info, S, Id>;
package/dist/builder.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import { Agent as CoreAgent, AgentBuilder as CoreAgentBuilder, } from "@nylorun/core/define";
2
- import { skills } from "./skills/index.js";
2
+ import { skills } from "./skills/skills.js";
3
3
  import { plugin } from "./plugins/plugin.js";
4
4
  /**
5
- * The agent builder with the capabilities that read files: `.skills()` and `.plugin()`.
5
+ * The agent builder with the methods that read files: `.skills()` and `.plugin()`.
6
6
  * `@nylorun/agents/define` exports the portable builder from core, without them.
7
7
  */
8
8
  export class AgentBuilder extends CoreAgentBuilder {
9
9
  /** Load an Agent Skills folder. */
10
- skills(directory, options) {
11
- return this.capability(skills(directory, options));
10
+ skills(directory) {
11
+ return this.withPart(skills(directory), "skills()");
12
12
  }
13
13
  /** Attach an Agent Plugin package. */
14
14
  plugin(directory) {
15
- return this.capability(plugin(directory));
15
+ return this.withPart(plugin(directory), "plugin()");
16
16
  }
17
17
  output(schema) {
18
18
  return super.output(schema);
@@ -0,0 +1,387 @@
1
+ /**
2
+ * Environments (protocol 11, D55, D56): `client.environments`. An Environment is one sandbox
3
+ * (kind `virtual`, `pod` or `none`) made from an environment manifest's version or from inline
4
+ * fields, and one vault of secrets for its shell, MCP servers and HTTP tools. It never changes
5
+ * what it runs after it is made (protocol 14, D63): a new version reaches an agent through a new
6
+ * Environment. It has its own id and outlives the sessions that name it; whether it serves one
7
+ * session, one person or a project is the app's choice, made here:
8
+ *
9
+ * - `environments.forSession(...)`: one Environment for one session. It creates the
10
+ * Environment, opens the session on it, and `release()` deletes the Environment (and its
11
+ * vault) when the session is done.
12
+ * - `environments.put(id, { manifest: "analyst-box" })` (or inline fields): one Environment per
13
+ * person or per project, by a deterministic id (`users/alice/web`); get-or-create in one call.
14
+ * Write its secrets with `environments.secrets.put(id, name, { value })` and open sessions on
15
+ * it with `createSession({ environment: id })`.
16
+ * - `environments.manifests.save(manifest)`: save an environment manifest's next version, like
17
+ * `saveAgent`; `plan(manifest)` answers what a save would do and saves nothing.
18
+ *
19
+ * Ids may hold `/`; they are sent percent-encoded as one path segment. Secret values are
20
+ * write-only: no call reads one back.
21
+ *
22
+ * Disk versions (Host feature `environment-disk-versions`): `snapshot(id)` keeps a version of
23
+ * the Environment's disk between turns, `restore(id, version)` puts one back, and
24
+ * `put(id, { from: { environment, version } })` creates a new Environment from another's version.
25
+ *
26
+ * `fork(id, { id: next })` is how an Environment gets a new manifest version (Q15): a new
27
+ * Environment made from it, with the source's disk and secrets; `planFork` answers what it would do.
28
+ */
29
+ import { ENVIRONMENT_MANIFEST_SCHEMA_VERSION, type DeleteEnvironmentManifestResponse, type EnvironmentManifest, type EnvironmentManifestPlan, type EnvironmentManifestVersions, type EnvironmentForkPlan, type EnvironmentManifestView, type ForkEnvironmentRequest, type SaveEnvironmentManifestResponse, type DeleteEnvironmentResponse, type EnvironmentEvent, type EnvironmentEventType, type EnvironmentRestore, type EnvironmentSecretView, type EnvironmentSnapshot, type EnvironmentVersions, type EnvironmentView, type PutEnvironmentRequest, type PutEnvironmentSecretRequest } from "@nylorun/core/contracts";
30
+ import { type Transport } from "./http.js";
31
+ import type { CreateSessionOptions, SessionClient } from "./session-client.js";
32
+ /**
33
+ * What an Environment is made from: an environment manifest (`manifest: "name"` or `"name@n"`)
34
+ * or the inline fields, and its labels, owner guard and `from`.
35
+ */
36
+ export type EnvironmentInput = Omit<PutEnvironmentRequest, "requestId">;
37
+ /**
38
+ * One secret of an Environment's vault, as written: typed, or only its value (`{ value }`, or
39
+ * `{ headers }` for a `headers` secret) when what the Environment runs declares its slot (D64).
40
+ */
41
+ export type EnvironmentSecretInput = PutEnvironmentSecretRequest | {
42
+ readonly value: string;
43
+ } | {
44
+ readonly headers: Readonly<Record<string, string>>;
45
+ };
46
+ /** An environment manifest as authored: `manifestSchemaVersion` may be left out. */
47
+ export type EnvironmentManifestInput = Omit<EnvironmentManifest, "manifestSchemaVersion"> & {
48
+ readonly manifestSchemaVersion?: typeof ENVIRONMENT_MANIFEST_SCHEMA_VERSION;
49
+ /** For editors; dropped here, as the CLI drops it. */
50
+ readonly $schema?: string;
51
+ };
52
+ /**
53
+ * An environment manifest (protocol 14, D63): checked now against the schema the Runtime
54
+ * enforces, with `manifestSchemaVersion` filled in and `$schema` dropped. Save it with
55
+ * `client.environments.manifests.save()`, or make an Environment from it inline.
56
+ */
57
+ export declare function environmentManifest(input: EnvironmentManifestInput): EnvironmentManifest;
58
+ /** A session opened on an Environment of its own (`environments.forSession`). */
59
+ export interface SessionEnvironmentHandle {
60
+ readonly session: SessionClient;
61
+ readonly environment: EnvironmentView;
62
+ /** Deletes the Environment, its vault and its files; call it when the session is done. */
63
+ release(options?: {
64
+ signal?: AbortSignal;
65
+ }): Promise<DeleteEnvironmentResponse>;
66
+ }
67
+ export interface ForSessionOptions {
68
+ /** The session to open, as `createSession` takes it, without `environment`. */
69
+ readonly session: Omit<CreateSessionOptions, "environment">;
70
+ /**
71
+ * What the Environment is made from (a `manifest` or inline fields) and its labels. Default: a
72
+ * virtual one within the Tenant's defaults.
73
+ */
74
+ readonly recipe?: EnvironmentInput;
75
+ /** Secrets to write before the session opens, by name. */
76
+ readonly secrets?: Readonly<Record<string, EnvironmentSecretInput>>;
77
+ /** The Environment's id. Default: `sessions/<session id>`. */
78
+ readonly environmentId?: string;
79
+ readonly signal?: AbortSignal;
80
+ }
81
+ /** An Environment's secrets: `client.environments.secrets`. */
82
+ export declare class EnvironmentSecretsClient {
83
+ private readonly transport;
84
+ private readonly path;
85
+ constructor(transport: Transport, path: (environmentId: string) => string);
86
+ /**
87
+ * Creates or replaces secret `name` (`PUT /v1/environments/{id}/secrets/{name}`): for
88
+ * `environment_secret` and `environment_variable` the name is the variable's. A second
89
+ * credential for a host or a URL is a 409 `credential_conflict`. When what the Environment
90
+ * runs declares the secret's slot (D64), send only `{ value }` (or `{ headers }`); a name it
91
+ * does not declare is `409 secret_not_in_manifest`.
92
+ */
93
+ put(environmentId: string, name: string, secret: EnvironmentSecretInput, options?: {
94
+ signal?: AbortSignal;
95
+ }): Promise<EnvironmentSecretView>;
96
+ /** The secrets' names, types and bindings; never a value. */
97
+ list(environmentId: string, options?: {
98
+ signal?: AbortSignal;
99
+ }): Promise<EnvironmentSecretView[]>;
100
+ get(environmentId: string, name: string, options?: {
101
+ signal?: AbortSignal;
102
+ }): Promise<EnvironmentSecretView>;
103
+ delete(environmentId: string, name: string, options?: {
104
+ signal?: AbortSignal;
105
+ }): Promise<{
106
+ id: string;
107
+ }>;
108
+ }
109
+ /**
110
+ * Environment manifests (protocol 14, D63): `client.environments.manifests`. A save writes the
111
+ * manifest's next version, or answers the latest unchanged, and changes no Environment: an
112
+ * Environment keeps the version it was made from.
113
+ */
114
+ /** The bytes of files by hash, by `sha256:<hex>` (`environmentFiles(...).bytes`). */
115
+ export type EnvironmentFileBytes = Readonly<Record<string, Uint8Array>>;
116
+ /**
117
+ * A manifest `files` entry by content hash (Q6): `contents` (each file's path under `path` and
118
+ * its bytes or text) hashed, as `entry` for the manifest and `bytes` for `manifests.save`'s
119
+ * `files`, which uploads them. Each file holds at most 10 MiB.
120
+ */
121
+ export declare function environmentFiles(path: string, contents: Readonly<Record<string, Uint8Array | string>>): Promise<{
122
+ entry: {
123
+ path: string;
124
+ files: Record<string, string>;
125
+ };
126
+ bytes: Record<string, Uint8Array>;
127
+ }>;
128
+ export declare class EnvironmentManifestsClient {
129
+ private readonly transport;
130
+ constructor(transport: Transport);
131
+ private path;
132
+ private send;
133
+ /**
134
+ * Saves `manifest` (`PUT /v1/environment-manifests/{name}`). `ifMatch`: the version you read
135
+ * (`0` for none yet); a save over a newer one is `412 manifest_changed`. `files`: the bytes of
136
+ * its files by hash (`environmentFiles(...).bytes`), uploaded first when the Runtime lacks them.
137
+ */
138
+ save(manifest: EnvironmentManifestInput, options?: {
139
+ ifMatch?: number;
140
+ files?: EnvironmentFileBytes;
141
+ signal?: AbortSignal;
142
+ }): Promise<SaveEnvironmentManifestResponse>;
143
+ /** What saving `manifest` would do (`?dryRun=true`): changes, errors, warnings, and the Environments behind. */
144
+ plan(manifest: EnvironmentManifestInput, options?: {
145
+ ifMatch?: number;
146
+ files?: EnvironmentFileBytes;
147
+ signal?: AbortSignal;
148
+ }): Promise<EnvironmentManifestPlan>;
149
+ /** The latest version of manifest `name`, or version `version`. */
150
+ get(name: string, options?: {
151
+ version?: number;
152
+ signal?: AbortSignal;
153
+ }): Promise<EnvironmentManifestView>;
154
+ /** Each manifest's latest version. */
155
+ list(options?: {
156
+ signal?: AbortSignal;
157
+ }): Promise<EnvironmentManifestView[]>;
158
+ /** Every version of manifest `name`, newest first. */
159
+ versions(name: string, options?: {
160
+ signal?: AbortSignal;
161
+ }): Promise<EnvironmentManifestVersions>;
162
+ /** Deletes every version; refused while an Environment was made from one (`409 manifest_in_use`). */
163
+ delete(name: string, options?: {
164
+ signal?: AbortSignal;
165
+ }): Promise<DeleteEnvironmentManifestResponse>;
166
+ }
167
+ export declare class EnvironmentsClient {
168
+ private readonly transport;
169
+ /** `AgentsClient.createSession`, bound. */
170
+ private readonly createSession;
171
+ constructor(transport: Transport,
172
+ /** `AgentsClient.createSession`, bound. */
173
+ createSession: (options: CreateSessionOptions) => Promise<SessionClient>);
174
+ private path;
175
+ /** The Environment's secrets. */
176
+ get secrets(): EnvironmentSecretsClient;
177
+ /** Environment manifests (protocol 14, D63): named, versioned definitions of a kind of Environment. */
178
+ get manifests(): EnvironmentManifestsClient;
179
+ /**
180
+ * Creates the Environment and its vault, or finds the one with this id
181
+ * (`PUT /v1/environments/{id}`), from an environment manifest (`{ manifest: "name" }` takes
182
+ * the latest version, `"name@n"` version n) or from inline fields. It never changes what it
183
+ * runs after that (protocol 14): on an existing one, labels replace and `ownerUserId` sets or
184
+ * clears the owner guard, fields that match are accepted, and anything else is
185
+ * `409 environment_immutable`.
186
+ */
187
+ put(environmentId: string, recipe?: EnvironmentInput, options?: {
188
+ signal?: AbortSignal;
189
+ }): Promise<EnvironmentView>;
190
+ get(environmentId: string, options?: {
191
+ signal?: AbortSignal;
192
+ }): Promise<EnvironmentView>;
193
+ /** The Environments with every label in `labels` that this client reaches. */
194
+ list(options?: {
195
+ labels?: Readonly<Record<string, string>>;
196
+ signal?: AbortSignal;
197
+ }): Promise<EnvironmentView[]>;
198
+ page(options?: {
199
+ labels?: Readonly<Record<string, string>>;
200
+ limit?: number;
201
+ cursor?: string;
202
+ signal?: AbortSignal;
203
+ }): Promise<{
204
+ environments: {
205
+ id: string;
206
+ kind: "none" | "pod" | "virtual";
207
+ labels: Record<string, string>;
208
+ manifest: {
209
+ image?: string | undefined;
210
+ resources?: {
211
+ cpus: number;
212
+ memory: string;
213
+ } | undefined;
214
+ storage?: string | undefined;
215
+ network?: {
216
+ allowedHosts: string[];
217
+ } | undefined;
218
+ harness: string;
219
+ lifecycle: {
220
+ idle?: string | undefined;
221
+ deleteAfter?: string | undefined;
222
+ };
223
+ setup?: {
224
+ command: string;
225
+ cwd?: string | undefined;
226
+ timeout?: string | undefined;
227
+ }[] | undefined;
228
+ files?: ({
229
+ artifactId: string;
230
+ version: number;
231
+ path: string;
232
+ } | {
233
+ path: string;
234
+ files: Record<string, string>;
235
+ })[] | undefined;
236
+ secrets?: Record<string, {
237
+ required?: boolean | undefined;
238
+ description?: string | undefined;
239
+ type: "environment_secret";
240
+ allowedHosts: string[];
241
+ inject?: {
242
+ header: string;
243
+ format: string;
244
+ } | undefined;
245
+ } | {
246
+ required?: boolean | undefined;
247
+ description?: string | undefined;
248
+ type: "environment_variable";
249
+ } | {
250
+ via?: string | undefined;
251
+ identity?: {
252
+ header: string;
253
+ } | undefined;
254
+ required?: boolean | undefined;
255
+ description?: string | undefined;
256
+ type: "bearer";
257
+ url: string;
258
+ } | {
259
+ via?: string | undefined;
260
+ identity?: {
261
+ header: string;
262
+ } | undefined;
263
+ required?: boolean | undefined;
264
+ description?: string | undefined;
265
+ type: "headers";
266
+ url: string;
267
+ }> | undefined;
268
+ };
269
+ manifestName?: string | undefined;
270
+ manifestVersion?: number | undefined;
271
+ manifestHash?: string | undefined;
272
+ forkedFrom?: {
273
+ environment: string;
274
+ disk: number | null;
275
+ } | undefined;
276
+ slots?: {
277
+ name: string;
278
+ type: string;
279
+ required: boolean;
280
+ set: boolean;
281
+ }[] | undefined;
282
+ version: number;
283
+ appliedVersion: number;
284
+ ownerUserId: string | null;
285
+ state: string;
286
+ pod?: {
287
+ desired: "deleted" | "running" | "suspended";
288
+ observed: "creating" | "deleting" | "failed" | "lost" | "running" | "suspended";
289
+ volumeGeneration: number;
290
+ hostEpoch: number;
291
+ reason?: string | undefined;
292
+ imageDigest?: string | undefined;
293
+ } | undefined;
294
+ lastUsedAt: string;
295
+ disk?: {
296
+ latestVersion: number | null;
297
+ operation?: {
298
+ kind: "restore" | "seed" | "snapshot";
299
+ version?: number | undefined;
300
+ startedAt: string;
301
+ } | undefined;
302
+ } | undefined;
303
+ sessions: {
304
+ id: string;
305
+ activeTurnId: string | null;
306
+ }[];
307
+ createdAt: string;
308
+ updatedAt: string;
309
+ }[];
310
+ nextCursor: string | null;
311
+ }>;
312
+ /** Stops a pod Environment: its volume is kept, and the next turn starts it again. */
313
+ stop(environmentId: string, options?: {
314
+ signal?: AbortSignal;
315
+ }): Promise<EnvironmentView>;
316
+ /** Resets a pod Environment: a new pod on a new, empty volume, with its recipe applied. */
317
+ reset(environmentId: string, options?: {
318
+ signal?: AbortSignal;
319
+ }): Promise<EnvironmentView>;
320
+ /**
321
+ * Keeps a version of the Environment's disk (`POST /v1/environments/{id}/snapshot`), between
322
+ * turns; `unchanged` when the disk is as the latest version has it.
323
+ */
324
+ snapshot(environmentId: string, options?: {
325
+ signal?: AbortSignal;
326
+ }): Promise<EnvironmentSnapshot>;
327
+ /**
328
+ * Puts disk version `version` back: at once for a virtual Environment (`done`), on a new volume
329
+ * seeded before the next turn for a pod (`pending`).
330
+ */
331
+ restore(environmentId: string, version: number | "latest", options?: {
332
+ signal?: AbortSignal;
333
+ }): Promise<EnvironmentRestore>;
334
+ /**
335
+ * Forks the Environment into a new one, `options.id` (Q15): how an Environment gets a new
336
+ * manifest version, since none ever changes what it runs. It is made from `options.manifest`
337
+ * (default the source's manifest at its latest version), its disk starts from `options.disk`
338
+ * (`latest`, the default, snapshots first; a version; or `empty`) and the secrets the new
339
+ * manifest declares are copied (`options.secrets: "none"` copies none). The source keeps what
340
+ * it runs, its disk and its sessions. Answers the new Environment and the plan it ran.
341
+ */
342
+ fork(environmentId: string, options: Omit<ForkEnvironmentRequest, "requestId" | "dryRun"> & {
343
+ signal?: AbortSignal;
344
+ }): Promise<{
345
+ environment: EnvironmentView;
346
+ plan: EnvironmentForkPlan;
347
+ }>;
348
+ /** What `fork` would do (the disk, the secrets copied and left behind, the changes), making nothing. */
349
+ planFork(environmentId: string, options: Omit<ForkEnvironmentRequest, "requestId" | "dryRun"> & {
350
+ signal?: AbortSignal;
351
+ }): Promise<EnvironmentForkPlan>;
352
+ /** The Environment's disk versions, newest first. */
353
+ versions(environmentId: string, options?: {
354
+ signal?: AbortSignal;
355
+ }): Promise<EnvironmentVersions>;
356
+ /** Deletes disk version `version`; `deleted` is false when there was none. */
357
+ deleteVersion(environmentId: string, version: number, options?: {
358
+ signal?: AbortSignal;
359
+ }): Promise<{
360
+ environmentId: string;
361
+ version: number;
362
+ deleted: boolean;
363
+ }>;
364
+ /** Deletes the Environment, its vault and its files; `deleted` is false when there was none. */
365
+ delete(environmentId: string, options?: {
366
+ signal?: AbortSignal;
367
+ }): Promise<DeleteEnvironmentResponse>;
368
+ /**
369
+ * The Environment's events, from `from` on: its lifecycle, and `environment.egress` for every
370
+ * connection its sandbox opens (with the turns that were running). `types` keeps only those
371
+ * types; `since` and `until` keep events recorded in that window (ISO times or `Date`s).
372
+ */
373
+ events(environmentId: string, options?: {
374
+ from?: number;
375
+ types?: readonly EnvironmentEventType[];
376
+ since?: string | Date;
377
+ until?: string | Date;
378
+ signal?: AbortSignal;
379
+ }): Promise<EnvironmentEvent[]>;
380
+ /**
381
+ * One Environment for one session: creates the Environment (`sessions/<session id>` unless
382
+ * `environmentId` names another), writes `secrets`, opens the session on it, and returns both
383
+ * with `release()`, which deletes the Environment. If the session cannot be opened, the
384
+ * Environment is deleted again.
385
+ */
386
+ forSession(options: ForSessionOptions): Promise<SessionEnvironmentHandle>;
387
+ }