@agentorg/cli 0.0.5 → 0.0.6
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 +18 -102
- package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.d.ts +2 -7
- package/dist/node_modules/@agentorg/hub/dist/src/hub-actor.js +4 -144
- package/dist/node_modules/@agentorg/hub/dist/src/index.d.ts +1 -3
- package/dist/node_modules/@agentorg/hub/dist/src/index.js +1 -3
- package/dist/node_modules/@agentorg/hub/dist/src/router.d.ts +6 -57
- package/dist/node_modules/@agentorg/hub/dist/src/router.js +38 -413
- package/dist/node_modules/@agentorg/hub/dist/src/state.d.ts +17 -317
- package/dist/node_modules/@agentorg/hub/dist/src/state.js +42 -536
- package/dist/node_modules/@agentorg/hub/dist/src/validate.d.ts +1 -3
- package/dist/node_modules/@agentorg/hub/dist/src/validate.js +3 -15
- package/dist/node_modules/@agentorg/hub/package.json +0 -3
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.d.ts +132 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.js +105 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.d.ts +42 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-settings.js +53 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/chat.d.ts +15 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/chat.js +14 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/hub.d.ts +16 -286
- package/dist/node_modules/@agentorg/interfaces/dist/src/hub.js +17 -159
- package/dist/node_modules/@agentorg/interfaces/dist/src/index.d.ts +6 -8
- package/dist/node_modules/@agentorg/interfaces/dist/src/index.js +6 -8
- package/dist/node_modules/@agentorg/interfaces/dist/src/kv.d.ts +2 -2
- package/dist/node_modules/@agentorg/interfaces/dist/src/kv.js +2 -2
- package/dist/node_modules/@agentorg/interfaces/dist/src/manager.d.ts +272 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/manager.js +185 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/mcp-provider.d.ts +88 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/mcp-provider.js +78 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/tools.d.ts +39 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/tools.js +43 -0
- package/dist/node_modules/@agentorg/manager/dist/src/index.d.ts +1 -0
- package/dist/node_modules/@agentorg/manager/dist/src/index.js +1 -0
- package/dist/node_modules/@agentorg/manager/dist/src/manager.d.ts +21 -0
- package/dist/node_modules/@agentorg/manager/dist/src/manager.js +528 -0
- package/dist/node_modules/@agentorg/manager/dist/src/skills.d.ts +25 -0
- package/dist/node_modules/@agentorg/manager/dist/src/skills.js +145 -0
- package/dist/node_modules/@agentorg/manager/package.json +30 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/connection.d.ts +33 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/connection.js +290 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/index.d.ts +1 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/index.js +1 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/kinds.d.ts +50 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/kinds.js +69 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/provider.d.ts +22 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/provider.js +167 -0
- package/dist/node_modules/@agentorg/mcp/package.json +31 -0
- package/dist/node_modules/@agentorg/sdk/dist/src/cli.js +3 -23
- package/dist/node_modules/@agentorg/sdk/dist/src/client.d.ts +4 -25
- package/dist/node_modules/@agentorg/sdk/dist/src/client.js +5 -55
- package/dist/node_modules/@agentorg/sdk/dist/src/errors.d.ts +1 -1
- package/dist/node_modules/@agentorg/sdk/dist/src/errors.js +3 -3
- package/dist/node_modules/@agentorg/sdk/dist/src/index.d.ts +2 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/index.js +1 -1
- package/dist/node_modules/@agentorg/sdk/dist/src/interface.d.ts +6 -34
- package/dist/node_modules/@agentorg/sdk/dist/src/interface.js +3 -24
- package/dist/node_modules/@agentorg/sdk/dist/src/module-host.d.ts +8 -17
- package/dist/node_modules/@agentorg/sdk/dist/src/module-host.js +15 -87
- package/dist/node_modules/@agentorg/sdk/dist/src/module.d.ts +10 -76
- package/dist/node_modules/@agentorg/sdk/dist/src/module.js +3 -23
- package/dist/node_modules/@agentorg/sdk/dist/src/person-commands.js +0 -5
- package/dist/node_modules/@agentorg/sdk/dist/src/runtime.d.ts +3 -27
- package/dist/node_modules/@agentorg/sdk/dist/src/runtime.js +5 -100
- package/dist/node_modules/@agentorg/sdk/dist/src/testing.d.ts +7 -8
- package/dist/node_modules/@agentorg/sdk/dist/src/testing.js +12 -24
- package/dist/node_modules/@agentorg/sdk/package.json +4 -37
- package/dist/node_modules/@agentorg/shell/dist/app.css +3435 -739
- package/dist/node_modules/@agentorg/shell/dist/app.js +204 -202
- package/dist/node_modules/@agentorg/shell/package.json +18 -10
- package/dist/node_modules/@agentorg/wire/dist/src/frames.d.ts +2 -3
- package/dist/node_modules/@agentorg/wire/dist/src/frames.js +2 -3
- package/dist/node_modules/@agentorg/wire/dist/src/ops.d.ts +5 -34
- package/dist/node_modules/@agentorg/wire/dist/src/ops.js +2 -17
- package/dist/node_modules/assistant/dist/src/agent.d.ts +62 -0
- package/dist/node_modules/assistant/dist/src/agent.js +226 -0
- package/dist/node_modules/assistant/dist/src/engine.d.ts +23 -0
- package/dist/node_modules/assistant/dist/src/engine.js +88 -0
- package/dist/node_modules/assistant/dist/src/history.d.ts +97 -0
- package/dist/node_modules/assistant/dist/src/history.js +235 -0
- package/dist/node_modules/assistant/dist/src/local-store.d.ts +3 -0
- package/dist/node_modules/assistant/dist/src/local-store.js +58 -0
- package/dist/node_modules/assistant/dist/src/provider.d.ts +21 -0
- package/dist/node_modules/assistant/dist/src/provider.js +231 -0
- package/dist/node_modules/assistant/dist/src/settings.d.ts +17 -0
- package/dist/node_modules/assistant/dist/src/settings.js +43 -0
- package/dist/node_modules/assistant/dist/src/tools.d.ts +74 -0
- package/dist/node_modules/assistant/dist/src/tools.js +123 -0
- package/dist/node_modules/assistant/package.json +29 -0
- package/dist/node_modules/chatgpt/dist/src/account.d.ts +52 -0
- package/dist/node_modules/chatgpt/dist/src/account.js +270 -0
- package/dist/node_modules/chatgpt/dist/src/encoding.d.ts +7 -0
- package/dist/node_modules/chatgpt/dist/src/encoding.js +20 -0
- package/dist/node_modules/chatgpt/dist/src/file-store.d.ts +9 -0
- package/dist/node_modules/chatgpt/dist/src/file-store.js +68 -0
- package/dist/node_modules/chatgpt/dist/src/index.d.ts +1 -0
- package/dist/node_modules/chatgpt/dist/src/index.js +1 -0
- package/dist/node_modules/chatgpt/dist/src/jwt.d.ts +15 -0
- package/dist/node_modules/chatgpt/dist/src/jwt.js +37 -0
- package/dist/node_modules/chatgpt/dist/src/oauth.d.ts +43 -0
- package/dist/node_modules/chatgpt/dist/src/oauth.js +104 -0
- package/dist/node_modules/chatgpt/dist/src/program.d.ts +23 -0
- package/dist/node_modules/chatgpt/dist/src/program.js +41 -0
- package/dist/node_modules/chatgpt/dist/src/responses.d.ts +54 -0
- package/dist/node_modules/chatgpt/dist/src/responses.js +300 -0
- package/dist/node_modules/chatgpt/dist/src/serve.d.ts +65 -0
- package/dist/node_modules/chatgpt/dist/src/serve.js +46 -0
- package/dist/node_modules/chatgpt/package.json +33 -0
- package/dist/src/api.d.ts +5 -34
- package/dist/src/api.js +6 -68
- package/dist/src/cli.js +3 -7
- package/dist/src/gateway.d.ts +6 -7
- package/dist/src/gateway.js +39 -285
- package/dist/src/index.d.ts +4 -5
- package/dist/src/index.js +3 -4
- package/dist/src/notes.d.ts +11 -0
- package/dist/src/notes.js +64 -0
- package/dist/src/oauth.d.ts +16 -0
- package/dist/src/oauth.js +46 -0
- package/dist/src/programs.d.ts +29 -0
- package/dist/src/programs.js +171 -0
- package/package.json +3 -11
- package/dist/bundled/index.json +0 -6
- package/dist/bundled/sha256-0e91cc3d0e9762b81abc2427b5496b20f383abcd6fb97d928a8d50e956b54d1f.agentorg +0 -0
- package/dist/bundled/sha256-1f64ca62a0209d767d6aa6c4feb50b0653d60f10bebbc301f79bd3a37e0153c1.agentorg +0 -0
- package/dist/bundled/sha256-4055f8fddf6b90f3d356543f554b2a9e9a2c4a8827a8774f8f87952dc1692331.agentorg +0 -0
- package/dist/bundled/sha256-e356ea3c1899138a8494baf521556831006f38534fa9e92ae873e7e6956c3a46.agentorg +0 -0
- package/dist/node_modules/@agentorg/hub/dist/src/build.d.ts +0 -17
- package/dist/node_modules/@agentorg/hub/dist/src/build.js +0 -120
- package/dist/node_modules/@agentorg/hub/dist/src/logs.d.ts +0 -33
- package/dist/node_modules/@agentorg/hub/dist/src/logs.js +0 -162
- package/dist/node_modules/@agentorg/hub/dist/src/net.d.ts +0 -41
- package/dist/node_modules/@agentorg/hub/dist/src/net.js +0 -265
- package/dist/node_modules/@agentorg/hub/dist/src/processes.d.ts +0 -78
- package/dist/node_modules/@agentorg/hub/dist/src/processes.js +0 -485
- package/dist/node_modules/@agentorg/hub/dist/src/storage.d.ts +0 -38
- package/dist/node_modules/@agentorg/hub/dist/src/storage.js +0 -194
- package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.d.ts +0 -6
- package/dist/node_modules/@agentorg/interfaces/dist/src/http-egress.js +0 -7
- package/dist/node_modules/@agentorg/interfaces/dist/src/installer.d.ts +0 -191
- package/dist/node_modules/@agentorg/interfaces/dist/src/installer.js +0 -136
- package/dist/node_modules/@agentorg/interfaces/dist/src/layout.d.ts +0 -47
- package/dist/node_modules/@agentorg/interfaces/dist/src/layout.js +0 -52
- package/dist/node_modules/@agentorg/interfaces/dist/src/rules.d.ts +0 -35
- package/dist/node_modules/@agentorg/interfaces/dist/src/rules.js +0 -37
- package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.d.ts +0 -23
- package/dist/node_modules/@agentorg/interfaces/dist/src/storage-admin.js +0 -31
- package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.d.ts +0 -14
- package/dist/node_modules/@agentorg/interfaces/dist/src/ui-shell.js +0 -26
- package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.d.ts +0 -27
- package/dist/node_modules/@agentorg/interfaces/dist/src/ui-view.js +0 -26
- package/dist/node_modules/@agentorg/kit/dist/src/chat.d.ts +0 -37
- package/dist/node_modules/@agentorg/kit/dist/src/chat.js +0 -131
- package/dist/node_modules/@agentorg/kit/dist/src/components.d.ts +0 -94
- package/dist/node_modules/@agentorg/kit/dist/src/components.js +0 -66
- package/dist/node_modules/@agentorg/kit/dist/src/icons.d.ts +0 -17
- package/dist/node_modules/@agentorg/kit/dist/src/icons.js +0 -30
- package/dist/node_modules/@agentorg/kit/dist/src/index.d.ts +0 -6
- package/dist/node_modules/@agentorg/kit/dist/src/index.js +0 -10
- package/dist/node_modules/@agentorg/kit/dist/src/markdown.d.ts +0 -9
- package/dist/node_modules/@agentorg/kit/dist/src/markdown.js +0 -14
- package/dist/node_modules/@agentorg/kit/dist/src/resizable.d.ts +0 -5
- package/dist/node_modules/@agentorg/kit/dist/src/resizable.js +0 -8
- package/dist/node_modules/@agentorg/kit/dist/src/styles.d.ts +0 -11
- package/dist/node_modules/@agentorg/kit/dist/src/styles.js +0 -166
- package/dist/node_modules/@agentorg/kit/package.json +0 -44
- package/dist/node_modules/@agentorg/sdk/dist/frame/runtime.js +0 -753
- package/dist/node_modules/@agentorg/sdk/dist/host/runner.js +0 -21963
- package/dist/node_modules/@agentorg/sdk/dist/src/build.d.ts +0 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/build.js +0 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/client-http.d.ts +0 -24
- package/dist/node_modules/@agentorg/sdk/dist/src/client-http.js +0 -247
- package/dist/node_modules/@agentorg/sdk/dist/src/describe.d.ts +0 -13
- package/dist/node_modules/@agentorg/sdk/dist/src/describe.js +0 -16
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.d.ts +0 -8
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-base.js +0 -64
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.d.ts +0 -1
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-entry.js +0 -35
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.d.ts +0 -57
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-host.js +0 -293
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.d.ts +0 -124
- package/dist/node_modules/@agentorg/sdk/dist/src/frame-protocol.js +0 -16
- package/dist/node_modules/@agentorg/sdk/dist/src/frame.d.ts +0 -25
- package/dist/node_modules/@agentorg/sdk/dist/src/frame.js +0 -248
- package/dist/node_modules/@agentorg/sdk/dist/src/host-main.d.ts +0 -1
- package/dist/node_modules/@agentorg/sdk/dist/src/host-main.js +0 -60
- package/dist/node_modules/@agentorg/sdk/dist/src/host.d.ts +0 -25
- package/dist/node_modules/@agentorg/sdk/dist/src/host.js +0 -92
- package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.d.ts +0 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/manifest-api.js +0 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/manifest.d.ts +0 -56
- package/dist/node_modules/@agentorg/sdk/dist/src/manifest.js +0 -165
- package/dist/node_modules/@agentorg/sdk/dist/src/package.d.ts +0 -60
- package/dist/node_modules/@agentorg/sdk/dist/src/package.js +0 -538
- package/dist/node_modules/@agentorg/sdk/dist/src/tar.d.ts +0 -7
- package/dist/node_modules/@agentorg/sdk/dist/src/tar.js +0 -71
- package/dist/node_modules/@agentorg/shell/dist/agent-bindings.js +0 -59
- package/dist/node_modules/@agentorg/shell/src/agent-bindings.ts +0 -107
- package/dist/src/frames.d.ts +0 -23
- package/dist/src/frames.js +0 -78
- package/dist/src/layout.d.ts +0 -44
- package/dist/src/layout.js +0 -90
- package/dist/src/model.d.ts +0 -54
- package/dist/src/model.js +0 -299
- package/dist/src/rules.d.ts +0 -71
- package/dist/src/rules.js +0 -157
- package/dist/src/transfer.d.ts +0 -30
- package/dist/src/transfer.js +0 -110
|
@@ -2,35 +2,43 @@
|
|
|
2
2
|
"name": "@agentorg/shell",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"private": true,
|
|
5
|
-
"description": "The person's web shell for AgentOrg: their agents,
|
|
5
|
+
"description": "The person's web shell for AgentOrg: their agents, what each is made of, and their settings.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=22.15"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
|
-
"./package.json": "./package.json"
|
|
13
|
-
"./agent-bindings": {
|
|
14
|
-
"types": "./src/agent-bindings.ts",
|
|
15
|
-
"default": "./dist/agent-bindings.js"
|
|
16
|
-
}
|
|
12
|
+
"./package.json": "./package.json"
|
|
17
13
|
},
|
|
18
14
|
"files": [
|
|
19
|
-
"dist"
|
|
20
|
-
"src/agent-bindings.ts"
|
|
15
|
+
"dist"
|
|
21
16
|
],
|
|
22
17
|
"scripts": {
|
|
23
|
-
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json && node scripts/build.js"
|
|
18
|
+
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json && tsc -p tsconfig.test.json && node scripts/build.js",
|
|
19
|
+
"test": "node --experimental-strip-types --no-warnings --test --test-timeout=60000 \"test/**/*.test.ts\""
|
|
24
20
|
},
|
|
25
21
|
"devDependencies": {
|
|
26
22
|
"@agentorg/interfaces": "0.0.0",
|
|
27
|
-
"@agentorg/kit": "0.0.0",
|
|
28
23
|
"@agentorg/sdk": "0.0.0",
|
|
24
|
+
"@playwright/test": "1.64.1",
|
|
25
|
+
"@shadcn/react": "0.3.1",
|
|
26
|
+
"@tailwindcss/cli": "4.3.5",
|
|
29
27
|
"@types/react": "19.3.0",
|
|
30
28
|
"@types/react-dom": "19.3.0",
|
|
29
|
+
"@types/ws": "8.18.2",
|
|
30
|
+
"class-variance-authority": "0.7.1",
|
|
31
|
+
"clsx": "2.1.1",
|
|
31
32
|
"esbuild": "0.28.2",
|
|
33
|
+
"lucide-react": "1.70.0",
|
|
34
|
+
"radix-ui": "1.8.1",
|
|
32
35
|
"react": "19.3.1",
|
|
33
36
|
"react-dom": "19.3.1",
|
|
37
|
+
"streamdown": "2.7.1",
|
|
38
|
+
"tailwind-merge": "3.7.0",
|
|
39
|
+
"tailwindcss": "4.3.5",
|
|
40
|
+
"tw-animate-css": "1.4.0",
|
|
41
|
+
"ws": "8.22.1",
|
|
34
42
|
"zod": "^4.6.7"
|
|
35
43
|
}
|
|
36
44
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The largest JSON frame: 1 MiB.
|
|
1
|
+
/** The largest JSON frame: 1 MiB. */
|
|
2
2
|
export declare const MAX_FRAME: number;
|
|
3
3
|
export declare class FrameError extends Error {
|
|
4
4
|
readonly name = "FrameError";
|
|
@@ -6,8 +6,7 @@ export declare class FrameError extends Error {
|
|
|
6
6
|
/** A frame: a 4-byte big-endian length, then that many bytes of UTF-8 JSON. */
|
|
7
7
|
export declare function encodeFrame(value: unknown): Uint8Array;
|
|
8
8
|
/**
|
|
9
|
-
* Reads frames from a byte stream,
|
|
10
|
-
* with a header frame, and for `open` and `http` the rest is raw bytes.
|
|
9
|
+
* Reads frames from a byte stream, and can hand over what follows them untouched.
|
|
11
10
|
*/
|
|
12
11
|
export declare class FrameReader {
|
|
13
12
|
#private;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ByteQueue } from "./bytes.js";
|
|
2
|
-
/** The largest JSON frame: 1 MiB.
|
|
2
|
+
/** The largest JSON frame: 1 MiB. */
|
|
3
3
|
export const MAX_FRAME = 1024 * 1024;
|
|
4
4
|
export class FrameError extends Error {
|
|
5
5
|
name = "FrameError";
|
|
@@ -16,8 +16,7 @@ export function encodeFrame(value) {
|
|
|
16
16
|
return frame;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Reads frames from a byte stream,
|
|
20
|
-
* with a header frame, and for `open` and `http` the rest is raw bytes.
|
|
19
|
+
* Reads frames from a byte stream, and can hand over what follows them untouched.
|
|
21
20
|
*/
|
|
22
21
|
export class FrameReader {
|
|
23
22
|
#reader;
|
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
* closes the channel too. Without `declares` the Actor keeps what it declared before; with it,
|
|
8
8
|
* `declares` replaces that. The result is `{actorId, bound}`: the Actor's slots bound now. A
|
|
9
9
|
* newer channel for an Actor replaces its older one; with `replace: false` the hello is refused
|
|
10
|
-
* instead (`Refused`, code `connected`) while the Actor has a live channel.
|
|
11
|
-
* made for a package Actor's process, the hello names that Actor and carries no credential (the
|
|
12
|
-
* pipe is the proof) and no `declares` (a package declares through its manifest).
|
|
10
|
+
* instead (`Refused`, code `connected`) while the Actor has a live channel.
|
|
13
11
|
* - `slot`: from the Hub, one of the Actor's slots was bound or unbound after its channel's hello
|
|
14
12
|
* result was taken. The header is the whole message: the Hub closes its side, and the Actor
|
|
15
13
|
* closes its side once it has read it (an open notice counts against its streams). Applied in
|
|
@@ -17,22 +15,16 @@
|
|
|
17
15
|
* they give each slot's state. A `bound: true` for a slot already bound means its provider came
|
|
18
16
|
* back after going away: the slot is usable again, and what was subscribed must be again. A
|
|
19
17
|
* provider going away sends nothing; calls meanwhile are `NotConnected`.
|
|
20
|
-
* - `offer` and `withdraw`: the channel's own Actor offers an export at run time, or withdraws
|
|
21
|
-
* one it offered; one body (`{result: {}}` or `{error}`) answers, then the stream closes.
|
|
22
18
|
* - `call`: the caller sends one `{input}` body and closes its side; the answer is one `{result}`
|
|
23
19
|
* or `{error}` body, then the stream closes.
|
|
24
20
|
* - `subscribe`: `{event}` bodies flow until the subscriber resets the stream, or the provider
|
|
25
21
|
* side closes it (with an `{error}` body first when it was refused).
|
|
26
|
-
* - `open` and `http`: the answering side sends exactly one body first, `{result: {}}` to accept
|
|
27
|
-
* or `{error}` to refuse; after an accept, raw bytes flow both ways, each side closing its own
|
|
28
|
-
* direction, and a reset ends both. The provider answers the Hub, and the Hub forwards that
|
|
29
|
-
* answer. The opener may send bytes before the answer; they wait.
|
|
30
22
|
* Cancelling a reader of a yamux stream resets it.
|
|
31
23
|
*/
|
|
32
24
|
export type Header =
|
|
33
25
|
/**
|
|
34
|
-
* Admits a channel; its first stream.
|
|
35
|
-
*
|
|
26
|
+
* Admits a channel; its first stream. It carries the Actor's credential and may declare (the
|
|
27
|
+
* Hub validates `declares`).
|
|
36
28
|
*/
|
|
37
29
|
{
|
|
38
30
|
op: "hello";
|
|
@@ -49,26 +41,6 @@ export type Header =
|
|
|
49
41
|
slot: string;
|
|
50
42
|
event: string;
|
|
51
43
|
}
|
|
52
|
-
/** Raw bytes in the interface's protocol, after the Hub validates `params`. */
|
|
53
|
-
| {
|
|
54
|
-
op: "open";
|
|
55
|
-
slot: string;
|
|
56
|
-
params: unknown;
|
|
57
|
-
}
|
|
58
|
-
/** HTTP/1.1 bytes. */
|
|
59
|
-
| {
|
|
60
|
-
op: "http";
|
|
61
|
-
slot: string;
|
|
62
|
-
}
|
|
63
|
-
/** Offer an export at run time, as a described interface; it lasts until withdrawn or disconnect. */
|
|
64
|
-
| {
|
|
65
|
-
op: "offer";
|
|
66
|
-
name: string;
|
|
67
|
-
interface: unknown;
|
|
68
|
-
} | {
|
|
69
|
-
op: "withdraw";
|
|
70
|
-
name: string;
|
|
71
|
-
}
|
|
72
44
|
/**
|
|
73
45
|
* From the Hub to an Actor: one of its slots was bound or unbound. A slot made at run time (an
|
|
74
46
|
* export exposed to this Actor) carries `exposed` while bound: the export's described interface
|
|
@@ -81,18 +53,17 @@ export type Header =
|
|
|
81
53
|
exposed?: Exposure;
|
|
82
54
|
}
|
|
83
55
|
/**
|
|
84
|
-
* From the Hub to a provider: the same
|
|
56
|
+
* From the Hub to a provider: the same two, naming its export, who is calling, and through which
|
|
85
57
|
* of the caller's slots (a provider keeping state per consumer keys it by both).
|
|
86
58
|
*/
|
|
87
59
|
| {
|
|
88
60
|
op: "serve";
|
|
89
|
-
kind: "call" | "subscribe"
|
|
61
|
+
kind: "call" | "subscribe";
|
|
90
62
|
export: string;
|
|
91
63
|
caller: string;
|
|
92
64
|
slot: string;
|
|
93
65
|
method?: string;
|
|
94
66
|
event?: string;
|
|
95
|
-
params?: unknown;
|
|
96
67
|
};
|
|
97
68
|
/** A slot made at run time, as the Hub describes it: the export's interface, and whose it is. */
|
|
98
69
|
export interface Exposure {
|
|
@@ -25,18 +25,6 @@ export function parseHeader(value) {
|
|
|
25
25
|
return { op: "call", slot: text(value, "slot"), method: text(value, "method") };
|
|
26
26
|
case "subscribe":
|
|
27
27
|
return { op: "subscribe", slot: text(value, "slot"), event: text(value, "event") };
|
|
28
|
-
case "open":
|
|
29
|
-
if (!("params" in value))
|
|
30
|
-
throw new HeaderError("An open header needs params.");
|
|
31
|
-
return { op: "open", slot: text(value, "slot"), params: value.params };
|
|
32
|
-
case "http":
|
|
33
|
-
return { op: "http", slot: text(value, "slot") };
|
|
34
|
-
case "offer":
|
|
35
|
-
if (!isRecord(value.interface))
|
|
36
|
-
throw new HeaderError("An offer header needs an interface.");
|
|
37
|
-
return { op: "offer", name: text(value, "name"), interface: value.interface };
|
|
38
|
-
case "withdraw":
|
|
39
|
-
return { op: "withdraw", name: text(value, "name") };
|
|
40
28
|
case "slot": {
|
|
41
29
|
if (typeof value.bound !== "boolean")
|
|
42
30
|
throw new HeaderError("A slot header needs bound.");
|
|
@@ -63,10 +51,8 @@ export function parseHeader(value) {
|
|
|
63
51
|
}
|
|
64
52
|
case "serve": {
|
|
65
53
|
const kind = value.kind;
|
|
66
|
-
if (kind !== "call" && kind !== "subscribe"
|
|
67
|
-
throw new HeaderError("A serve header's kind must be call
|
|
68
|
-
if (kind === "open" && !("params" in value))
|
|
69
|
-
throw new HeaderError("An open serve header needs params.");
|
|
54
|
+
if (kind !== "call" && kind !== "subscribe")
|
|
55
|
+
throw new HeaderError("A serve header's kind must be call or subscribe.");
|
|
70
56
|
return {
|
|
71
57
|
op: "serve",
|
|
72
58
|
kind,
|
|
@@ -75,7 +61,6 @@ export function parseHeader(value) {
|
|
|
75
61
|
slot: text(value, "slot"),
|
|
76
62
|
...(kind === "call" ? { method: text(value, "method") } : {}),
|
|
77
63
|
...(kind === "subscribe" ? { event: text(value, "event") } : {}),
|
|
78
|
-
...(kind === "open" ? { params: value.params } : {}),
|
|
79
64
|
};
|
|
80
65
|
}
|
|
81
66
|
default:
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent loop: a turn sends the conversation and the tools to the model, runs each function the
|
|
3
|
+
* model calls through its slot, and sends the results back, until the model answers without
|
|
4
|
+
* calling anything, or the turn has made its 20 calls.
|
|
5
|
+
*/
|
|
6
|
+
import type { ChatMessage, llmSession } from "@agentorg/interfaces";
|
|
7
|
+
import { type Log, type Slot } from "@agentorg/sdk";
|
|
8
|
+
import type { z } from "zod";
|
|
9
|
+
import { type History } from "./history.js";
|
|
10
|
+
import { type Tools } from "./tools.js";
|
|
11
|
+
export declare const MAX_CALLS = 20;
|
|
12
|
+
type Status = {
|
|
13
|
+
state: "idle" | "thinking" | "tool";
|
|
14
|
+
} | {
|
|
15
|
+
state: "error";
|
|
16
|
+
detail: {
|
|
17
|
+
code: string;
|
|
18
|
+
message: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export interface Chat {
|
|
22
|
+
message(message: z.input<typeof ChatMessage>): void;
|
|
23
|
+
delta(id: string, text: string): void;
|
|
24
|
+
status(status: Status): void;
|
|
25
|
+
}
|
|
26
|
+
export declare function createAgent(options: {
|
|
27
|
+
/** Read for each model request: what it's told and what it can call follow what it's bound to. */
|
|
28
|
+
request(): Promise<{
|
|
29
|
+
instructions: string;
|
|
30
|
+
tools: Tools;
|
|
31
|
+
}>;
|
|
32
|
+
model: Slot<typeof llmSession>;
|
|
33
|
+
/** The model chosen for this agent, read for each request; none means the provider's default. */
|
|
34
|
+
chosenModel(): Promise<string | undefined>;
|
|
35
|
+
history: History;
|
|
36
|
+
chat: Chat;
|
|
37
|
+
log: Log;
|
|
38
|
+
}): {
|
|
39
|
+
/** Start a turn with the person's message; its progress arrives as events. */
|
|
40
|
+
send(text: string): Promise<{
|
|
41
|
+
messageId: string;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Run the last turn again, without recording the person's message again. What followed it goes
|
|
45
|
+
* from the record, so the new reply takes its place; what its tools did stays done.
|
|
46
|
+
*/
|
|
47
|
+
retry(): Promise<{
|
|
48
|
+
messageId: string;
|
|
49
|
+
}>;
|
|
50
|
+
/** The status now. */
|
|
51
|
+
state: () => Status;
|
|
52
|
+
/**
|
|
53
|
+
* Stop the turn now: its model request is cancelled, no further call starts, and a new turn
|
|
54
|
+
* may begin at once. A call already running finishes, and its result is kept.
|
|
55
|
+
*/
|
|
56
|
+
cancel(): Promise<void>;
|
|
57
|
+
/** Settles when the latest turn has written all it will. */
|
|
58
|
+
settled: () => Promise<void>;
|
|
59
|
+
/** Streamed text of the model request running now, for the reply it becomes. */
|
|
60
|
+
delta(requestId: string, text: string): void;
|
|
61
|
+
};
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { Refused } from "@agentorg/sdk";
|
|
2
|
+
import { argumentsOf, head, messageOf } from "./history.js";
|
|
3
|
+
import { capped, codeOf, runTool } from "./tools.js";
|
|
4
|
+
export const MAX_CALLS = 20;
|
|
5
|
+
export function createAgent(options) {
|
|
6
|
+
const { model, history, chat, log } = options;
|
|
7
|
+
let turn;
|
|
8
|
+
/** A cancelled turn whose running call hasn't settled: the next turn waits for its records. */
|
|
9
|
+
let draining;
|
|
10
|
+
/** Settles when the latest turn's loop has ended. */
|
|
11
|
+
let ending;
|
|
12
|
+
/** The latest status, for a view that asks. */
|
|
13
|
+
let latest = { state: "idle" };
|
|
14
|
+
const say = (next) => {
|
|
15
|
+
latest = next;
|
|
16
|
+
chat.status(next);
|
|
17
|
+
};
|
|
18
|
+
/** A turn's status, while it is still the turn: a cancelled one has already said idle. */
|
|
19
|
+
const status = (current, next) => {
|
|
20
|
+
if (turn === current)
|
|
21
|
+
say(next);
|
|
22
|
+
};
|
|
23
|
+
/** Run a turn on the record as it stands; its progress arrives as events. */
|
|
24
|
+
const begin = (current) => {
|
|
25
|
+
current.ended = run(current)
|
|
26
|
+
.then(() => status(current, { state: "idle" }), (error) => {
|
|
27
|
+
if (current.cancelled)
|
|
28
|
+
return;
|
|
29
|
+
log.error("A turn failed.", { error: String(error) });
|
|
30
|
+
status(current, { state: "error", detail: codeOf(error) });
|
|
31
|
+
})
|
|
32
|
+
.finally(() => {
|
|
33
|
+
if (turn === current)
|
|
34
|
+
turn = undefined;
|
|
35
|
+
})
|
|
36
|
+
.catch((error) => log.error("A turn's status failed.", { error: String(error) }));
|
|
37
|
+
ending = current.ended;
|
|
38
|
+
};
|
|
39
|
+
const show = (entry) => chat.message(messageOf(entry));
|
|
40
|
+
/** A call starting: shown as running, under the id its record will have when it ends. */
|
|
41
|
+
const running = (call, id) => chat.message({
|
|
42
|
+
id,
|
|
43
|
+
role: "tool",
|
|
44
|
+
text: `${call.name}: running`,
|
|
45
|
+
at: new Date().toISOString(),
|
|
46
|
+
tool: { name: head(call.name, 128), state: "running", input: argumentsOf(call.arguments) },
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* Record a function call with its output, keeping every call paired, as the API needs. Its end
|
|
50
|
+
* is shown even if the record can't be written, so no call is left shown as running.
|
|
51
|
+
*/
|
|
52
|
+
const answered = async (call, result, id) => {
|
|
53
|
+
const entry = {
|
|
54
|
+
role: "tool",
|
|
55
|
+
text: `${call.name}: ${result.ok ? "done" : result.code}`,
|
|
56
|
+
state: result.ok ? "done" : "refused",
|
|
57
|
+
items: [
|
|
58
|
+
call,
|
|
59
|
+
{
|
|
60
|
+
type: "function_call_output",
|
|
61
|
+
callId: call.callId,
|
|
62
|
+
output: capped(result.output),
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
show(await history.append(entry, id));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
chat.message(messageOf({
|
|
71
|
+
...entry,
|
|
72
|
+
id,
|
|
73
|
+
at: new Date().toISOString(),
|
|
74
|
+
items: [{ ...call, arguments: argumentsOf(call.arguments) }, ...entry.items.slice(1)],
|
|
75
|
+
}));
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Note calls that won't run, in one message however many there are. They never ran, so the
|
|
81
|
+
* record leaves them out: what the model is sent next holds only calls with their outputs.
|
|
82
|
+
*/
|
|
83
|
+
const skipped = async (calls, code) => {
|
|
84
|
+
if (calls.length === 0)
|
|
85
|
+
return;
|
|
86
|
+
const text = calls.length === 1 ? `${calls[0]?.name}: ${code}` : `${calls.length} calls: ${code}`;
|
|
87
|
+
show(await history.append({ role: "tool", text, items: [] }));
|
|
88
|
+
};
|
|
89
|
+
async function run(current) {
|
|
90
|
+
let calls = 0;
|
|
91
|
+
for (;;) {
|
|
92
|
+
status(current, { state: "thinking" });
|
|
93
|
+
const { instructions, tools } = await options.request();
|
|
94
|
+
const input = await history.input();
|
|
95
|
+
const chosen = await options.chosenModel();
|
|
96
|
+
if (current.cancelled)
|
|
97
|
+
return;
|
|
98
|
+
const requestId = crypto.randomUUID();
|
|
99
|
+
const replyId = crypto.randomUUID();
|
|
100
|
+
current.requestId = requestId;
|
|
101
|
+
current.replyId = replyId;
|
|
102
|
+
let output;
|
|
103
|
+
try {
|
|
104
|
+
({ output } = await model.call.respond({
|
|
105
|
+
requestId,
|
|
106
|
+
...(chosen ? { model: chosen } : {}),
|
|
107
|
+
instructions,
|
|
108
|
+
input,
|
|
109
|
+
tools: [...tools.values()].map((found) => found.tool),
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
current.requestId = undefined;
|
|
114
|
+
}
|
|
115
|
+
if (current.cancelled)
|
|
116
|
+
return;
|
|
117
|
+
const texts = output.flatMap((item) => (item.type === "message" ? [item.content] : []));
|
|
118
|
+
const called = output.filter((item) => item.type === "function_call");
|
|
119
|
+
if (texts.length > 0 || called.length === 0)
|
|
120
|
+
show(await history.append({
|
|
121
|
+
role: "assistant",
|
|
122
|
+
items: texts.map((content) => ({ type: "message", role: "assistant", content })),
|
|
123
|
+
}, replyId));
|
|
124
|
+
if (called.length === 0)
|
|
125
|
+
return;
|
|
126
|
+
for (const [i, call] of called.entries()) {
|
|
127
|
+
if (current.cancelled || calls >= MAX_CALLS) {
|
|
128
|
+
const rest = called.slice(i);
|
|
129
|
+
await skipped(rest, current.cancelled ? "cancelled" : "limit");
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
calls++;
|
|
133
|
+
status(current, { state: "tool" });
|
|
134
|
+
// A call that has started runs to its end, and its real result is kept: it may have
|
|
135
|
+
// taken effect.
|
|
136
|
+
const id = crypto.randomUUID();
|
|
137
|
+
running(call, id);
|
|
138
|
+
const result = await runTool(tools, call.name, call.arguments);
|
|
139
|
+
await answered(call, result, id);
|
|
140
|
+
}
|
|
141
|
+
if (current.cancelled)
|
|
142
|
+
return;
|
|
143
|
+
if (calls >= MAX_CALLS)
|
|
144
|
+
throw new Refused("limit", `This turn stopped after ${MAX_CALLS} tool calls.`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
/** Start a turn with the person's message; its progress arrives as events. */
|
|
149
|
+
async send(text) {
|
|
150
|
+
if (turn)
|
|
151
|
+
throw new Refused("busy", "A turn is running. Wait for it, or cancel it.");
|
|
152
|
+
const current = { cancelled: false };
|
|
153
|
+
turn = current;
|
|
154
|
+
try {
|
|
155
|
+
// A cancelled turn's last call lands in the record before this message does.
|
|
156
|
+
await draining;
|
|
157
|
+
draining = undefined;
|
|
158
|
+
const entry = await history.append({
|
|
159
|
+
role: "user",
|
|
160
|
+
items: [{ type: "message", role: "user", content: text }],
|
|
161
|
+
});
|
|
162
|
+
show(entry);
|
|
163
|
+
begin(current);
|
|
164
|
+
return { messageId: entry.id };
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (turn === current)
|
|
168
|
+
turn = undefined;
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Run the last turn again, without recording the person's message again. What followed it goes
|
|
174
|
+
* from the record, so the new reply takes its place; what its tools did stays done.
|
|
175
|
+
*/
|
|
176
|
+
async retry() {
|
|
177
|
+
if (turn)
|
|
178
|
+
throw new Refused("busy", "A turn is running. Wait for it, or cancel it.");
|
|
179
|
+
const current = { cancelled: false };
|
|
180
|
+
turn = current;
|
|
181
|
+
try {
|
|
182
|
+
await draining;
|
|
183
|
+
draining = undefined;
|
|
184
|
+
const last = await history.lastUser();
|
|
185
|
+
if (!last)
|
|
186
|
+
throw new Refused("nothing_to_retry", "No message has been sent yet.");
|
|
187
|
+
await history.dropAfter(last.id);
|
|
188
|
+
begin(current);
|
|
189
|
+
return { messageId: last.id };
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (turn === current)
|
|
193
|
+
turn = undefined;
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
/** The status now. */
|
|
198
|
+
state: () => latest,
|
|
199
|
+
/**
|
|
200
|
+
* Stop the turn now: its model request is cancelled, no further call starts, and a new turn
|
|
201
|
+
* may begin at once. A call already running finishes, and its result is kept.
|
|
202
|
+
*/
|
|
203
|
+
async cancel() {
|
|
204
|
+
const current = turn;
|
|
205
|
+
if (!current)
|
|
206
|
+
return;
|
|
207
|
+
current.cancelled = true;
|
|
208
|
+
turn = undefined;
|
|
209
|
+
// In a model call, nothing more is recorded; in a tool call, its result still is.
|
|
210
|
+
if (!current.requestId)
|
|
211
|
+
draining = current.ended;
|
|
212
|
+
say({ state: "idle" });
|
|
213
|
+
if (current.requestId && model.bound)
|
|
214
|
+
await model.call.cancel({ requestId: current.requestId }).catch(() => { });
|
|
215
|
+
},
|
|
216
|
+
/** Settles when the latest turn has written all it will. */
|
|
217
|
+
settled: async () => {
|
|
218
|
+
await ending;
|
|
219
|
+
},
|
|
220
|
+
/** Streamed text of the model request running now, for the reply it becomes. */
|
|
221
|
+
delta(requestId, text) {
|
|
222
|
+
if (turn?.requestId === requestId && turn.replyId)
|
|
223
|
+
chat.delta(turn.replyId, text);
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine: one agent's chat, its loop, and what a request says and offers. Its host says where
|
|
3
|
+
* the record is kept and what the agent is told when no `settings` is bound.
|
|
4
|
+
*/
|
|
5
|
+
import type { agentSettings, chat, kv, llmSession } from "@agentorg/interfaces";
|
|
6
|
+
import { type Context, type Slot } from "@agentorg/sdk";
|
|
7
|
+
type Host = Pick<Context<{
|
|
8
|
+
model: typeof llmSession;
|
|
9
|
+
settings: typeof agentSettings;
|
|
10
|
+
}, {
|
|
11
|
+
chat: typeof chat;
|
|
12
|
+
}>, "slots" | "exports" | "exposed" | "log">;
|
|
13
|
+
export declare function startEngine(ctx: Host, options: {
|
|
14
|
+
store: Slot<typeof kv>["call"];
|
|
15
|
+
/** What the agent is told while no `settings` is bound. */
|
|
16
|
+
instructions(): string;
|
|
17
|
+
}): {
|
|
18
|
+
/** Stop the turn in progress. */
|
|
19
|
+
cancel: () => Promise<void>;
|
|
20
|
+
/** Settles when the latest turn has written all it will. */
|
|
21
|
+
settled: () => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Refused } from "@agentorg/sdk";
|
|
2
|
+
import { createAgent } from "./agent.js";
|
|
3
|
+
import { createHistory } from "./history.js";
|
|
4
|
+
import { instructionsWith, skillTool } from "./settings.js";
|
|
5
|
+
import { listedBy, listsTools, offered } from "./tools.js";
|
|
6
|
+
/** Where the agent keeps the model chosen for it, beside its record in the store. */
|
|
7
|
+
const MODEL_KEY = "settings/model";
|
|
8
|
+
export function startEngine(ctx, options) {
|
|
9
|
+
const { store } = options;
|
|
10
|
+
const history = createHistory(store, ctx.log);
|
|
11
|
+
/** The model chosen for this agent, if any; read for each request. */
|
|
12
|
+
const chosen = async () => {
|
|
13
|
+
const { value } = await store.get({ key: MODEL_KEY });
|
|
14
|
+
return typeof value === "string" ? value : undefined;
|
|
15
|
+
};
|
|
16
|
+
/** What was last reported as left out, so a change is logged once. */
|
|
17
|
+
let reported = "[]";
|
|
18
|
+
const report = (leftOut) => {
|
|
19
|
+
const now = JSON.stringify(leftOut);
|
|
20
|
+
if (now === reported)
|
|
21
|
+
return;
|
|
22
|
+
reported = now;
|
|
23
|
+
if (leftOut.length > 0)
|
|
24
|
+
ctx.log.warn("Not everything is offered to the model.", { leftOut });
|
|
25
|
+
else
|
|
26
|
+
ctx.log.info("Everything is offered to the model again.");
|
|
27
|
+
};
|
|
28
|
+
/** What a request says and offers, read afresh: nothing here outlives the request. */
|
|
29
|
+
const request = async () => {
|
|
30
|
+
const settings = ctx.slots.settings.bound ? await ctx.slots.settings.call.get({}) : undefined;
|
|
31
|
+
const told = settings
|
|
32
|
+
? instructionsWith(settings.instructions, settings.skills)
|
|
33
|
+
: { instructions: options.instructions(), leftOut: [] };
|
|
34
|
+
const own = settings?.skills.length ? [skillTool(ctx.slots.settings)] : [];
|
|
35
|
+
// In the order they came, each asked at once so one slow server delays only itself.
|
|
36
|
+
const exposed = await Promise.all(ctx
|
|
37
|
+
.exposed()
|
|
38
|
+
.filter((slot) => listsTools(slot.described))
|
|
39
|
+
.map((slot) => listedBy(slot.slot, slot)));
|
|
40
|
+
const { tools, leftOut } = offered([...own, ...exposed.flatMap((one) => one.candidates)]);
|
|
41
|
+
report([...told.leftOut, ...exposed.flatMap((one) => one.leftOut), ...leftOut]);
|
|
42
|
+
return { instructions: told.instructions, tools };
|
|
43
|
+
};
|
|
44
|
+
const agent = createAgent({
|
|
45
|
+
request,
|
|
46
|
+
model: ctx.slots.model,
|
|
47
|
+
chosenModel: chosen,
|
|
48
|
+
history,
|
|
49
|
+
chat: {
|
|
50
|
+
message: (message) => ctx.exports.chat.emit("message", message),
|
|
51
|
+
delta: (id, text) => ctx.exports.chat.emit("delta", { id, text }),
|
|
52
|
+
status: (status) => ctx.exports.chat.emit("status", status),
|
|
53
|
+
},
|
|
54
|
+
log: ctx.log,
|
|
55
|
+
});
|
|
56
|
+
ctx.slots.model.on("delta", ({ requestId, text }) => agent.delta(requestId, text));
|
|
57
|
+
ctx.exports.chat.implement({
|
|
58
|
+
send: ({ text }) => agent.send(text),
|
|
59
|
+
history: ({ before, limit }) => history.page(before, limit ?? 50),
|
|
60
|
+
cancel: async () => {
|
|
61
|
+
await agent.cancel();
|
|
62
|
+
return {};
|
|
63
|
+
},
|
|
64
|
+
state: () => agent.state(),
|
|
65
|
+
retry: () => agent.retry(),
|
|
66
|
+
models: async () => {
|
|
67
|
+
const [{ models }, current] = await Promise.all([ctx.slots.model.call.models({}), chosen()]);
|
|
68
|
+
return { models, ...(current ? { current } : {}) };
|
|
69
|
+
},
|
|
70
|
+
setModel: async ({ model }) => {
|
|
71
|
+
if (!model) {
|
|
72
|
+
await store.delete({ key: MODEL_KEY });
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
const { models } = await ctx.slots.model.call.models({});
|
|
76
|
+
if (!models.some((offered) => offered.id === model))
|
|
77
|
+
throw new Refused("unknown", `${model} isn't one of the models offered.`);
|
|
78
|
+
await store.set({ key: MODEL_KEY, value: model });
|
|
79
|
+
return {};
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
/** Stop the turn in progress. */
|
|
84
|
+
cancel: () => agent.cancel(),
|
|
85
|
+
/** Settles when the latest turn has written all it will. */
|
|
86
|
+
settled: () => agent.settled(),
|
|
87
|
+
};
|
|
88
|
+
}
|