@aexhq/sdk 0.58.0 → 0.59.0
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 +25 -22
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/resources.d.ts +57 -12
- package/dist/resources.js +124 -17
- package/dist/session.d.ts +31 -31
- package/dist/session.js +178 -56
- package/dist/tools.d.ts +8 -60
- package/dist/tools.js +18 -323
- package/dist/transport.d.ts +2 -3
- package/dist/transport.js +6 -38
- package/package.json +3 -7
- package/dist/internal.d.ts +0 -2
- package/dist/internal.js +0 -1
package/README.md
CHANGED
|
@@ -6,55 +6,58 @@ TypeScript SDK for Aex sessions and tool extensions.
|
|
|
6
6
|
import { Aex } from "@aexhq/sdk";
|
|
7
7
|
import { awsMicrovm } from "@aexhq/env-aws-microvm";
|
|
8
8
|
import { pi } from "@aexhq/loop-pi";
|
|
9
|
-
import {
|
|
9
|
+
import { openai } from "@aexhq/model-openai";
|
|
10
|
+
import { bash, read, task, write } from "@aexhq/tools";
|
|
10
11
|
|
|
11
12
|
const aex = new Aex({ apiKey: process.env.AEX_API_KEY! });
|
|
12
13
|
const workspace = awsMicrovm();
|
|
13
14
|
|
|
14
15
|
const session = await aex.sessions.create({
|
|
15
16
|
model: {
|
|
17
|
+
component: openai(),
|
|
16
18
|
provider: "openai",
|
|
17
19
|
name: "gpt-5.4",
|
|
18
20
|
apiKey: process.env.OPENAI_API_KEY!,
|
|
19
21
|
},
|
|
20
|
-
|
|
22
|
+
agentloop: pi({ instructions: "Work carefully and verify changes." }),
|
|
21
23
|
environments: { workspace },
|
|
22
|
-
tools: [bash(), read(), write()],
|
|
24
|
+
tools: [bash(), read(), write(), task()],
|
|
23
25
|
});
|
|
24
26
|
|
|
25
27
|
console.log(await session.send("Inspect the workspace."));
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
There is no default
|
|
29
|
-
|
|
30
|
-
environment satisfies it; otherwise creation fails with the eligible or missing capabilities.
|
|
30
|
+
There is no default Agentloop, Model, Tool, or Environment. A Tool component that requests the
|
|
31
|
+
Environment capability requires the session's one declared Environment in the MVP.
|
|
31
32
|
|
|
32
|
-
## Tools
|
|
33
|
+
## Application Tools
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
Application callbacks use the same Tool and Environment component ABI while the handler remains in
|
|
36
|
+
your process. Declare one `app()` Environment; Aex registers each selected callback over one
|
|
37
|
+
authenticated, reconnecting connection. Handler source and captured application state are never
|
|
38
|
+
uploaded to Brain.
|
|
35
39
|
|
|
36
40
|
```ts
|
|
37
|
-
import { tool } from "@aexhq/sdk";
|
|
41
|
+
import { Aex, tool } from "@aexhq/sdk";
|
|
42
|
+
import { app } from "@aexhq/env-app";
|
|
38
43
|
import { z } from "zod";
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
const lookupOrder = tool(
|
|
41
46
|
z.object({ orderId: z.string() }),
|
|
42
47
|
async function lookupOrder({ orderId }) {
|
|
43
48
|
return database.lookup(orderId);
|
|
44
49
|
},
|
|
45
50
|
)
|
|
46
51
|
.describe("Look up an order")
|
|
47
|
-
.returns(z.object({ status: z.string() }))
|
|
48
|
-
.needs({ env: ["ORDERS_TOKEN"], network: [{ host: "orders.example.com", port: 443 }] })
|
|
49
|
-
.setup(async function prepareIndex() {
|
|
50
|
-
await database.prepareIndex();
|
|
51
|
-
});
|
|
52
|
-
```
|
|
52
|
+
.returns(z.object({ status: z.string() }));
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
await new Aex({ apiKey: process.env.AEX_API_KEY! }).sessions.create({
|
|
55
|
+
model,
|
|
56
|
+
agentloop,
|
|
57
|
+
environments: { application: app({ id: "orders-ui" }) },
|
|
58
|
+
tools: [lookupOrder],
|
|
59
|
+
});
|
|
60
|
+
```
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Durable objects remain available through `session.storage`, independently of environment lifetime.
|
|
62
|
+
Source callback Tools are routed automatically to the single `app()` Environment. Durable objects
|
|
63
|
+
remain available through `session.storage`, independently of Environment lifetime.
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiError, ApiErrorCode } from "@aexhq/
|
|
1
|
+
import type { ApiError, ApiErrorCode } from "@aexhq/brain/session";
|
|
2
2
|
/** One Aex trusted-output validation failure, expressed as a JSON Pointer. */
|
|
3
3
|
export interface OutputValidationIssue {
|
|
4
4
|
path: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { Sessions } from "./session.js";
|
|
2
2
|
import type { Fetch } from "./transport.js";
|
|
3
|
-
import type { WebSocketFactory } from "@aexhq/
|
|
3
|
+
import type { WebSocketFactory } from "@aexhq/brain";
|
|
4
4
|
export { AbortError, AexError, OutputRefusalError, OutputSchemaError, OutputValidationError, SessionError, } from "./errors.js";
|
|
5
5
|
export type { AexErrorOptions, OutputValidationIssue } from "./errors.js";
|
|
6
6
|
export { Session, Sessions, } from "./session.js";
|
|
7
|
-
export type { CreateSessionOptions, ListSessionsOptions,
|
|
7
|
+
export type { CreateSessionOptions, ListSessionsOptions, ModelSummary, ModelOptions, OutputOptions, RequestOptions, SessionInput, SessionList, SessionSummary, } from "./session.js";
|
|
8
8
|
export { SessionChild, SessionChildren, SessionStorage, } from "./resources.js";
|
|
9
|
-
export type { BinarySource, ChildSummary,
|
|
9
|
+
export type { BinarySource, ChildSummary, IdempotentOperationOptions, OperationOptions, PageOptions, StorageObject, StoragePage, StreamingUploadSource, UploadSource, } from "./resources.js";
|
|
10
10
|
export type { EventOptions } from "./transport.js";
|
|
11
11
|
export { tool } from "./tools.js";
|
|
12
|
-
export type {
|
|
13
|
-
export type { NetworkPolicy, WebSocketFactory } from "@aexhq/
|
|
14
|
-
export type { EnvironmentRef, HandleOf } from "@aexhq/environment";
|
|
12
|
+
export type { Tool, ToolContract, ToolContext, ToolHandler, } from "./tools.js";
|
|
13
|
+
export type { NetworkPolicy, WebSocketFactory } from "@aexhq/brain";
|
|
15
14
|
export interface AexOptions {
|
|
16
15
|
apiKey: string;
|
|
17
16
|
baseUrl?: string;
|
package/dist/resources.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { SessionChildren as BrainChildren } from "@aexhq/
|
|
2
|
-
import type {
|
|
3
|
-
import type { Event, Session as BrainSession } from "@aexhq/
|
|
4
|
-
import type { EnvironmentRef } from "@aexhq/environment";
|
|
1
|
+
import { SessionChildren as BrainChildren, SessionSandbox as BrainSandbox } from "@aexhq/brain";
|
|
2
|
+
import type { SandboxFileEntry as BrainSandboxFileEntry, SandboxStatus as BrainSandboxStatus } from "@aexhq/brain";
|
|
3
|
+
import type { Event, Session as BrainSession } from "@aexhq/brain/session";
|
|
5
4
|
import type { EventOptions } from "./transport.js";
|
|
6
5
|
import { Transport } from "./transport.js";
|
|
7
6
|
export type BinarySource = string | ArrayBuffer | ArrayBufferView | Blob;
|
|
@@ -23,13 +22,57 @@ export interface PageOptions extends OperationOptions {
|
|
|
23
22
|
cursor?: string;
|
|
24
23
|
limit?: number;
|
|
25
24
|
}
|
|
26
|
-
export interface
|
|
25
|
+
export interface SandboxStatus {
|
|
26
|
+
state: BrainSandboxStatus["state"];
|
|
27
|
+
generation?: string;
|
|
28
|
+
reason?: string;
|
|
29
|
+
changedAt?: string;
|
|
30
|
+
expiresAt?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SandboxFile {
|
|
27
33
|
path: string;
|
|
28
|
-
kind:
|
|
34
|
+
kind: BrainSandboxFileEntry["kind"];
|
|
29
35
|
bytes: number;
|
|
30
36
|
sha256?: string;
|
|
31
37
|
modifiedAt: string;
|
|
32
38
|
}
|
|
39
|
+
export interface SandboxFilePage {
|
|
40
|
+
data: SandboxFile[];
|
|
41
|
+
hasMore: boolean;
|
|
42
|
+
nextCursor?: string;
|
|
43
|
+
generation: string;
|
|
44
|
+
}
|
|
45
|
+
export interface SandboxFileOptions extends OperationOptions {
|
|
46
|
+
generation: string;
|
|
47
|
+
}
|
|
48
|
+
export interface SandboxFilePageOptions extends SandboxFileOptions, PageOptions {
|
|
49
|
+
}
|
|
50
|
+
export declare class SandboxFiles {
|
|
51
|
+
#private;
|
|
52
|
+
constructor(inner: BrainSandbox["files"], transport: Transport);
|
|
53
|
+
list(path: string, options: SandboxFilePageOptions): Promise<SandboxFilePage>;
|
|
54
|
+
stat(path: string, options: SandboxFileOptions): Promise<SandboxFile>;
|
|
55
|
+
download(path: string, options: SandboxFileOptions): Promise<Uint8Array>;
|
|
56
|
+
downloadStream(path: string, options: SandboxFileOptions): Promise<ReadableStream<Uint8Array>>;
|
|
57
|
+
upload(path: string, source: UploadSource, options: SandboxFileOptions & {
|
|
58
|
+
overwrite?: boolean;
|
|
59
|
+
}): Promise<SandboxFile>;
|
|
60
|
+
find(input: {
|
|
61
|
+
path: string;
|
|
62
|
+
glob: string;
|
|
63
|
+
}, options: SandboxFilePageOptions): Promise<SandboxFilePage>;
|
|
64
|
+
grep(input: {
|
|
65
|
+
path: string;
|
|
66
|
+
query: string;
|
|
67
|
+
}, options: SandboxFilePageOptions): Promise<SandboxFilePage>;
|
|
68
|
+
}
|
|
69
|
+
export declare class SessionSandbox {
|
|
70
|
+
#private;
|
|
71
|
+
readonly files: SandboxFiles;
|
|
72
|
+
constructor(transport: Transport, sessionId: string);
|
|
73
|
+
status(options?: OperationOptions): Promise<SandboxStatus>;
|
|
74
|
+
create(options?: OperationOptions): Promise<SandboxStatus>;
|
|
75
|
+
}
|
|
33
76
|
export interface StorageObject {
|
|
34
77
|
key: string;
|
|
35
78
|
bytes: number;
|
|
@@ -45,7 +88,7 @@ export interface StoragePage {
|
|
|
45
88
|
}
|
|
46
89
|
export declare class SessionStorage {
|
|
47
90
|
#private;
|
|
48
|
-
constructor(transport: Transport, sessionId: string
|
|
91
|
+
constructor(transport: Transport, sessionId: string);
|
|
49
92
|
list(options?: PageOptions & {
|
|
50
93
|
prefix?: string;
|
|
51
94
|
}): Promise<StoragePage>;
|
|
@@ -57,18 +100,20 @@ export declare class SessionStorage {
|
|
|
57
100
|
overwrite?: boolean;
|
|
58
101
|
}): Promise<StorageObject>;
|
|
59
102
|
delete(key: string, options?: OperationOptions): Promise<void>;
|
|
60
|
-
|
|
103
|
+
copyFromSandbox(input: {
|
|
104
|
+
environment: string;
|
|
61
105
|
key: string;
|
|
62
106
|
path: string;
|
|
63
|
-
|
|
107
|
+
sandboxGeneration: string;
|
|
64
108
|
overwrite?: boolean;
|
|
65
109
|
}, options?: OperationOptions): Promise<StorageObject>;
|
|
66
|
-
|
|
110
|
+
copyToSandbox(input: {
|
|
111
|
+
environment: string;
|
|
67
112
|
key: string;
|
|
68
113
|
path: string;
|
|
69
|
-
|
|
114
|
+
sandboxGeneration: string;
|
|
70
115
|
overwrite?: boolean;
|
|
71
|
-
}, options?: OperationOptions): Promise<
|
|
116
|
+
}, options?: OperationOptions): Promise<SandboxFile>;
|
|
72
117
|
}
|
|
73
118
|
export interface ChildSummary {
|
|
74
119
|
id: string;
|
package/dist/resources.js
CHANGED
|
@@ -1,14 +1,110 @@
|
|
|
1
|
-
import { MAX_INLINE_FILE_BYTES, SessionChildren as BrainChildren, SessionStorage as BrainStorage, } from "@aexhq/
|
|
1
|
+
import { MAX_INLINE_FILE_BYTES, SessionChildren as BrainChildren, SessionSandbox as BrainSandbox, SessionStorage as BrainStorage, } from "@aexhq/brain";
|
|
2
2
|
import { SessionError, abortError } from "./errors.js";
|
|
3
3
|
import { randomIdempotencyKey } from "./json.js";
|
|
4
|
+
export class SandboxFiles {
|
|
5
|
+
#inner;
|
|
6
|
+
#transport;
|
|
7
|
+
constructor(inner, transport) {
|
|
8
|
+
this.#inner = inner;
|
|
9
|
+
this.#transport = transport;
|
|
10
|
+
}
|
|
11
|
+
async list(path, options) {
|
|
12
|
+
const page = await this.#inner.list({
|
|
13
|
+
path,
|
|
14
|
+
generation: options.generation,
|
|
15
|
+
...(options.cursor === undefined ? {} : { cursor: options.cursor }),
|
|
16
|
+
...(options.limit === undefined ? {} : { limit: options.limit }),
|
|
17
|
+
}, request(options));
|
|
18
|
+
return filePage(page);
|
|
19
|
+
}
|
|
20
|
+
async stat(path, options) {
|
|
21
|
+
return file(await this.#inner.stat({ path, generation: options.generation }, request(options)));
|
|
22
|
+
}
|
|
23
|
+
async download(path, options) {
|
|
24
|
+
return collect(await this.downloadStream(path, options));
|
|
25
|
+
}
|
|
26
|
+
async downloadStream(path, options) {
|
|
27
|
+
const entry = await this.#inner.stat({ path, generation: options.generation }, request(options));
|
|
28
|
+
if (entry.bytes <= MAX_INLINE_FILE_BYTES) {
|
|
29
|
+
const result = await this.#inner.readInline({ path, generation: options.generation }, request(options));
|
|
30
|
+
return byteStream(decodeBase64(result.content_base64));
|
|
31
|
+
}
|
|
32
|
+
const ticket = await this.#inner.prepareDownload({ path, generation: options.generation }, request(options));
|
|
33
|
+
return this.#transport.downloadTransferStream(ticket, options.signal, entry.bytes);
|
|
34
|
+
}
|
|
35
|
+
async upload(path, source, options) {
|
|
36
|
+
const base = {
|
|
37
|
+
path,
|
|
38
|
+
generation: options.generation,
|
|
39
|
+
...(options.overwrite === undefined ? {} : { overwrite: options.overwrite }),
|
|
40
|
+
};
|
|
41
|
+
let entry;
|
|
42
|
+
if (isStreamingSource(source)) {
|
|
43
|
+
assertStreamingSource(source);
|
|
44
|
+
entry = source.bytes <= MAX_INLINE_FILE_BYTES
|
|
45
|
+
? await this.#inner.writeInline({ ...base, content_base64: encodeBase64(await collectDeclared(source, options.signal)) }, request(options))
|
|
46
|
+
: await this.#uploadStream(base, source, options);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const content = await bytesOf(source);
|
|
50
|
+
entry = content.byteLength <= MAX_INLINE_FILE_BYTES
|
|
51
|
+
? await this.#inner.writeInline({ ...base, content_base64: encodeBase64(content) }, request(options))
|
|
52
|
+
: await this.#upload(base, content, options);
|
|
53
|
+
}
|
|
54
|
+
return file(entry);
|
|
55
|
+
}
|
|
56
|
+
async #upload(input, content, options) {
|
|
57
|
+
const ticket = await this.#inner.prepareUpload({ ...input, bytes: content.byteLength, sha256: await sha256(content) }, request(options));
|
|
58
|
+
await this.#transport.uploadTransfer(ticket, content, content.byteLength, options.signal);
|
|
59
|
+
// Direct sandbox transfers are intentionally happy-path only. Do not automatically replay an
|
|
60
|
+
// ambiguous import: surface the error so the caller can inspect the generation/path and
|
|
61
|
+
// prepare a fresh transfer. Durable storage completion has separate retry-safe semantics.
|
|
62
|
+
return this.#inner.completeUpload(ticket.transfer_id, request(options));
|
|
63
|
+
}
|
|
64
|
+
async #uploadStream(input, source, options) {
|
|
65
|
+
const ticket = await this.#inner.prepareUpload({ ...input, bytes: source.bytes, sha256: source.sha256 }, request(options));
|
|
66
|
+
await this.#transport.uploadTransfer(ticket, () => source.stream(), source.bytes, options.signal);
|
|
67
|
+
return this.#inner.completeUpload(ticket.transfer_id, request(options));
|
|
68
|
+
}
|
|
69
|
+
async find(input, options) {
|
|
70
|
+
const page = await this.#inner.find({
|
|
71
|
+
...input,
|
|
72
|
+
generation: options.generation,
|
|
73
|
+
...(options.cursor === undefined ? {} : { cursor: options.cursor }),
|
|
74
|
+
...(options.limit === undefined ? {} : { limit: options.limit }),
|
|
75
|
+
}, request(options));
|
|
76
|
+
return filePage(page);
|
|
77
|
+
}
|
|
78
|
+
async grep(input, options) {
|
|
79
|
+
const page = await this.#inner.grep({
|
|
80
|
+
...input,
|
|
81
|
+
generation: options.generation,
|
|
82
|
+
...(options.cursor === undefined ? {} : { cursor: options.cursor }),
|
|
83
|
+
...(options.limit === undefined ? {} : { limit: options.limit }),
|
|
84
|
+
}, request(options));
|
|
85
|
+
return filePage(page);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export class SessionSandbox {
|
|
89
|
+
#inner;
|
|
90
|
+
files;
|
|
91
|
+
constructor(transport, sessionId) {
|
|
92
|
+
this.#inner = new BrainSandbox(transport, sessionId);
|
|
93
|
+
this.files = new SandboxFiles(this.#inner.files, transport);
|
|
94
|
+
}
|
|
95
|
+
async status(options = {}) {
|
|
96
|
+
return sandboxStatus(await this.#inner.status(request(options)));
|
|
97
|
+
}
|
|
98
|
+
async create(options = {}) {
|
|
99
|
+
return sandboxStatus(await this.#inner.create(intrinsicRequest(options)));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
4
102
|
export class SessionStorage {
|
|
5
103
|
#inner;
|
|
6
104
|
#transport;
|
|
7
|
-
|
|
8
|
-
constructor(transport, sessionId, environmentNames = new Map()) {
|
|
105
|
+
constructor(transport, sessionId) {
|
|
9
106
|
this.#inner = new BrainStorage(transport, sessionId);
|
|
10
107
|
this.#transport = transport;
|
|
11
|
-
this.#environmentNames = environmentNames;
|
|
12
108
|
}
|
|
13
109
|
async list(options = {}) {
|
|
14
110
|
const page = await this.#inner.list({
|
|
@@ -62,28 +158,22 @@ export class SessionStorage {
|
|
|
62
158
|
delete(key, options = {}) {
|
|
63
159
|
return this.#inner.delete(key, request(options));
|
|
64
160
|
}
|
|
65
|
-
async
|
|
66
|
-
return storageObject(await this.#inner.copyFromEnvironment(
|
|
161
|
+
async copyFromSandbox(input, options = {}) {
|
|
162
|
+
return storageObject(await this.#inner.copyFromEnvironment(input.environment, {
|
|
67
163
|
key: input.key,
|
|
68
164
|
path: input.path,
|
|
69
|
-
environment_generation: input.
|
|
165
|
+
environment_generation: input.sandboxGeneration,
|
|
70
166
|
...(input.overwrite === undefined ? {} : { overwrite: input.overwrite }),
|
|
71
167
|
}, request(options)));
|
|
72
168
|
}
|
|
73
|
-
async
|
|
74
|
-
return
|
|
169
|
+
async copyToSandbox(input, options = {}) {
|
|
170
|
+
return file(await this.#inner.copyToEnvironment(input.environment, {
|
|
75
171
|
key: input.key,
|
|
76
172
|
path: input.path,
|
|
77
|
-
environment_generation: input.
|
|
173
|
+
environment_generation: input.sandboxGeneration,
|
|
78
174
|
...(input.overwrite === undefined ? {} : { overwrite: input.overwrite }),
|
|
79
175
|
}, request(options)));
|
|
80
176
|
}
|
|
81
|
-
#environmentName(environment) {
|
|
82
|
-
const name = this.#environmentNames.get(environment);
|
|
83
|
-
if (name === undefined)
|
|
84
|
-
throw new TypeError("EnvironmentRef does not belong to this Session");
|
|
85
|
-
return name;
|
|
86
|
-
}
|
|
87
177
|
}
|
|
88
178
|
export class SessionChild {
|
|
89
179
|
#inner;
|
|
@@ -159,7 +249,16 @@ function idempotentRequest(options) {
|
|
|
159
249
|
retry: true,
|
|
160
250
|
};
|
|
161
251
|
}
|
|
162
|
-
function
|
|
252
|
+
function sandboxStatus(value) {
|
|
253
|
+
return {
|
|
254
|
+
state: value.state,
|
|
255
|
+
...(value.generation == null ? {} : { generation: value.generation }),
|
|
256
|
+
...(value.reason == null ? {} : { reason: value.reason }),
|
|
257
|
+
...(value.changed_at_ms == null ? {} : { changedAt: timestamp(value.changed_at_ms) }),
|
|
258
|
+
...(value.expires_at_ms == null ? {} : { expiresAt: timestamp(value.expires_at_ms) }),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function file(value) {
|
|
163
262
|
return {
|
|
164
263
|
path: value.path,
|
|
165
264
|
kind: value.kind,
|
|
@@ -168,6 +267,14 @@ function environmentFile(value) {
|
|
|
168
267
|
modifiedAt: timestamp(value.modified_at_ms),
|
|
169
268
|
};
|
|
170
269
|
}
|
|
270
|
+
function filePage(value) {
|
|
271
|
+
return {
|
|
272
|
+
data: value.data.map(file),
|
|
273
|
+
hasMore: value.has_more,
|
|
274
|
+
...(value.next_cursor === undefined ? {} : { nextCursor: value.next_cursor }),
|
|
275
|
+
generation: value.generation,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
171
278
|
function storageObject(value) {
|
|
172
279
|
return {
|
|
173
280
|
key: value.key,
|
package/dist/session.d.ts
CHANGED
|
@@ -1,42 +1,32 @@
|
|
|
1
|
-
import type { Event,
|
|
2
|
-
import { type
|
|
3
|
-
import type { NetworkPolicy, WebSocketFactory } from "@aexhq/
|
|
1
|
+
import type { Event, Session as BrainSessionData, SessionState } from "@aexhq/brain/session";
|
|
2
|
+
import { type ComponentExtension, type SessionTool as ComponentSessionTool } from "@aexhq/brain";
|
|
3
|
+
import type { NetworkPolicy, WebSocketFactory } from "@aexhq/brain";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
import type { EventOptions } from "./transport.js";
|
|
6
6
|
import { Transport } from "./transport.js";
|
|
7
|
-
import
|
|
8
|
-
import { SessionChildren, SessionStorage } from "./resources.js";
|
|
7
|
+
import { type Tool } from "./tools.js";
|
|
8
|
+
import { SessionChildren, SessionSandbox, SessionStorage } from "./resources.js";
|
|
9
|
+
type SessionData = BrainSessionData & {
|
|
10
|
+
retain_until: string;
|
|
11
|
+
};
|
|
9
12
|
export type SessionInput = string;
|
|
10
13
|
export interface ModelOptions {
|
|
11
|
-
|
|
14
|
+
/** Imported Model component. */
|
|
15
|
+
component: ComponentExtension<"model">;
|
|
16
|
+
provider: string;
|
|
12
17
|
name: string;
|
|
13
18
|
apiKey: string;
|
|
14
19
|
baseUrl?: string;
|
|
15
20
|
maxOutputTokens?: number;
|
|
16
|
-
/** Immutable context capacity used for admission and compaction; Brain never guesses by name. */
|
|
17
|
-
contextWindowTokens?: number;
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
* A built agentloop implementation, as exported by a loop package or produced by
|
|
21
|
-
* `buildLoopBundle` from `@aexhq/agentloop`. Assignment is by import, never by name:
|
|
22
|
-
* the sealed identity is the content digest plus the pinned toolchain.
|
|
23
|
-
*/
|
|
24
|
-
export interface Loop {
|
|
25
|
-
/** The complete deterministic ESM source bundle — the exact bytes sealed and uploaded. */
|
|
26
|
-
source: string;
|
|
27
|
-
/** SHA-256 hex of the UTF-8 source bytes. */
|
|
28
|
-
sha256: string;
|
|
29
|
-
/** The pinned loop-toolchain identity the bundle was built for. */
|
|
30
|
-
toolchain: string;
|
|
31
|
-
}
|
|
32
|
-
export interface CreateSessionOptions<Environments extends EnvironmentMap = EnvironmentMap> {
|
|
22
|
+
export interface CreateSessionOptions {
|
|
33
23
|
model: ModelOptions;
|
|
34
24
|
/** The imported agent loop that drives this session and every child unless spawn overrides it. */
|
|
35
|
-
|
|
25
|
+
agentloop: ComponentExtension<"agentloop">;
|
|
36
26
|
/** Omitted or empty grants no tools. A non-empty list is the exact grant. */
|
|
37
|
-
environments?:
|
|
38
|
-
tools?: readonly
|
|
39
|
-
/** Write-only values for
|
|
27
|
+
environments?: Readonly<Record<string, ComponentExtension<"environment">>>;
|
|
28
|
+
tools?: readonly (Tool | ComponentSessionTool)[];
|
|
29
|
+
/** Write-only values for components that explicitly consume session secrets. */
|
|
40
30
|
secrets?: Record<string, string>;
|
|
41
31
|
/** Maximum direct outbound network authority sealed for managed sandboxes. Omission is deny-all. */
|
|
42
32
|
network?: NetworkPolicy;
|
|
@@ -49,6 +39,8 @@ export interface CreateSessionOptions<Environments extends EnvironmentMap = Envi
|
|
|
49
39
|
maxDescendants?: number;
|
|
50
40
|
};
|
|
51
41
|
metadata?: Record<string, string>;
|
|
42
|
+
/** Finite durable-history deadline. Omit to use the Brain deployment default. */
|
|
43
|
+
retainUntil?: Date | string;
|
|
52
44
|
}
|
|
53
45
|
export interface RequestOptions {
|
|
54
46
|
signal?: AbortSignal;
|
|
@@ -72,7 +64,7 @@ export interface SessionList {
|
|
|
72
64
|
nextCursor?: string;
|
|
73
65
|
}
|
|
74
66
|
export interface ModelSummary {
|
|
75
|
-
provider:
|
|
67
|
+
provider: string;
|
|
76
68
|
name: string;
|
|
77
69
|
baseUrl?: string;
|
|
78
70
|
contextWindowTokens: number;
|
|
@@ -87,6 +79,7 @@ export interface SessionSummary {
|
|
|
87
79
|
model: ModelSummary;
|
|
88
80
|
createdAt: string;
|
|
89
81
|
updatedAt: string;
|
|
82
|
+
retainUntil: string;
|
|
90
83
|
metadata: Readonly<Record<string, string | undefined>>;
|
|
91
84
|
}
|
|
92
85
|
export declare class Sessions {
|
|
@@ -94,16 +87,16 @@ export declare class Sessions {
|
|
|
94
87
|
constructor(transport: Transport, webSocketFactory?: WebSocketFactory);
|
|
95
88
|
/** @internal Called by `Aex.close()`. */
|
|
96
89
|
close(): void;
|
|
97
|
-
create
|
|
90
|
+
create(options: CreateSessionOptions, request?: RequestOptions): Promise<Session>;
|
|
98
91
|
get(id: string, options?: Pick<RequestOptions, "signal">): Promise<Session>;
|
|
99
92
|
list(options?: ListSessionsOptions): Promise<SessionList>;
|
|
100
93
|
}
|
|
101
|
-
export declare class Session
|
|
94
|
+
export declare class Session implements SessionSummary {
|
|
102
95
|
#private;
|
|
96
|
+
readonly sandbox: SessionSandbox;
|
|
103
97
|
readonly storage: SessionStorage;
|
|
104
98
|
readonly children: SessionChildren;
|
|
105
|
-
constructor(transport: Transport, data: SessionData
|
|
106
|
-
environment<Environment extends EnvironmentValue<Environments>>(environment: Environment): HandleOf<Environment>;
|
|
99
|
+
constructor(transport: Transport, data: SessionData);
|
|
107
100
|
get id(): string;
|
|
108
101
|
get state(): SessionState;
|
|
109
102
|
get turnState(): SessionData["turn_state"];
|
|
@@ -113,6 +106,7 @@ export declare class Session<Environments extends EnvironmentMap = EnvironmentMa
|
|
|
113
106
|
get model(): ModelSummary;
|
|
114
107
|
get createdAt(): string;
|
|
115
108
|
get updatedAt(): string;
|
|
109
|
+
get retainUntil(): string;
|
|
116
110
|
get metadata(): Readonly<Record<string, string | undefined>>;
|
|
117
111
|
refresh(options?: Pick<RequestOptions, "signal">): Promise<this>;
|
|
118
112
|
send(input: SessionInput, options?: RequestOptions): Promise<string>;
|
|
@@ -124,9 +118,15 @@ export declare class Session<Environments extends EnvironmentMap = EnvironmentMa
|
|
|
124
118
|
*/
|
|
125
119
|
events(options?: EventOptions): AsyncGenerator<Event>;
|
|
126
120
|
cancel(options?: Pick<RequestOptions, "signal">): Promise<this>;
|
|
121
|
+
suspend(options?: Pick<RequestOptions, "signal">): Promise<this>;
|
|
122
|
+
resume(options?: Pick<RequestOptions, "signal">): Promise<this>;
|
|
123
|
+
setRetention(value: Date | string, options?: Pick<RequestOptions, "signal"> & {
|
|
124
|
+
allowShorten?: boolean;
|
|
125
|
+
}): Promise<this>;
|
|
127
126
|
end(options?: Pick<RequestOptions, "signal">): Promise<this>;
|
|
128
127
|
delete(options?: Pick<RequestOptions, "signal"> & {
|
|
129
128
|
queue?: boolean;
|
|
130
129
|
}): Promise<void>;
|
|
131
130
|
private markIdle;
|
|
132
131
|
}
|
|
132
|
+
export {};
|