@agentorg/cli 0.0.5 → 0.0.7
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 +23 -104
- package/dist/node_modules/@agentorg/computer/LICENSE +201 -0
- package/dist/node_modules/@agentorg/computer/NOTICE +2 -0
- package/dist/node_modules/@agentorg/computer/dist/THIRD_PARTY_LICENSES.txt +1321 -0
- package/dist/node_modules/@agentorg/computer/dist/sdk.js +24909 -0
- package/dist/node_modules/@agentorg/computer/dist/types/generated/schema.d.ts +860 -0
- package/dist/node_modules/@agentorg/computer/dist/types/sdk.d.ts +242 -0
- package/dist/node_modules/@agentorg/computer/package.json +12 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/index.d.ts +1 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/index.js +1 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/provider.d.ts +24 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/provider.js +482 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/unit.d.ts +19 -0
- package/dist/node_modules/@agentorg/computer-connector/dist/src/unit.js +149 -0
- package/dist/node_modules/@agentorg/computer-connector/package.json +33 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/browser/SKILL.md +31 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/computer/SKILL.md +30 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/files/SKILL.md +28 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/terminal/SKILL.md +39 -0
- package/dist/node_modules/@agentorg/computer-connector/skills/web-research/SKILL.md +29 -0
- 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 +9 -58
- package/dist/node_modules/@agentorg/hub/dist/src/router.js +41 -414
- 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 +19 -17
- package/dist/node_modules/@agentorg/hub/package.json +0 -3
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.d.ts +119 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/agent-provider.js +96 -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 +93 -38
- package/dist/node_modules/@agentorg/interfaces/dist/src/chat.js +71 -22
- package/dist/node_modules/@agentorg/interfaces/dist/src/connection.d.ts +36 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/connection.js +31 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/folders.d.ts +19 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/folders.js +25 -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 +9 -9
- package/dist/node_modules/@agentorg/interfaces/dist/src/index.js +9 -9
- 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/llm-session.d.ts +2 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/llm-session.js +2 -1
- package/dist/node_modules/@agentorg/interfaces/dist/src/manager.d.ts +626 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/manager.js +349 -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/interfaces/dist/src/units.d.ts +460 -0
- package/dist/node_modules/@agentorg/interfaces/dist/src/units.js +204 -0
- package/dist/node_modules/@agentorg/looper/dist/src/index.d.ts +5 -0
- package/dist/node_modules/@agentorg/looper/dist/src/index.js +5 -0
- package/dist/node_modules/@agentorg/looper/dist/src/loop.d.ts +75 -0
- package/dist/node_modules/@agentorg/looper/dist/src/loop.js +332 -0
- package/dist/node_modules/@agentorg/looper/dist/src/looper.d.ts +71 -0
- package/dist/node_modules/@agentorg/looper/dist/src/looper.js +282 -0
- package/dist/node_modules/@agentorg/looper/dist/src/record.d.ts +99 -0
- package/dist/node_modules/@agentorg/looper/dist/src/record.js +278 -0
- package/dist/node_modules/@agentorg/looper/dist/src/tools.d.ts +11 -0
- package/dist/node_modules/@agentorg/looper/dist/src/tools.js +42 -0
- package/dist/node_modules/@agentorg/looper/dist/src/types.d.ts +147 -0
- package/dist/node_modules/@agentorg/looper/dist/src/types.js +32 -0
- package/dist/node_modules/@agentorg/looper/package.json +24 -0
- package/dist/node_modules/@agentorg/manager/dist/src/activity.d.ts +18 -0
- package/dist/node_modules/@agentorg/manager/dist/src/activity.js +65 -0
- package/dist/node_modules/@agentorg/manager/dist/src/control.d.ts +134 -0
- package/dist/node_modules/@agentorg/manager/dist/src/control.js +1115 -0
- package/dist/node_modules/@agentorg/manager/dist/src/form.d.ts +40 -0
- package/dist/node_modules/@agentorg/manager/dist/src/form.js +191 -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 +25 -0
- package/dist/node_modules/@agentorg/manager/dist/src/manager.js +680 -0
- package/dist/node_modules/@agentorg/manager/dist/src/skills.d.ts +27 -0
- package/dist/node_modules/@agentorg/manager/dist/src/skills.js +152 -0
- package/dist/node_modules/@agentorg/manager/dist/src/stack.d.ts +454 -0
- package/dist/node_modules/@agentorg/manager/dist/src/stack.js +917 -0
- package/dist/node_modules/@agentorg/manager/package.json +30 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/connection.d.ts +34 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/connection.js +296 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/index.d.ts +4 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/index.js +4 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/kinds.d.ts +158 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/kinds.js +164 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/provider.d.ts +22 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/provider.js +197 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/public.d.ts +6 -0
- package/dist/node_modules/@agentorg/mcp/dist/src/public.js +72 -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/filled.d.ts +21 -0
- package/dist/node_modules/@agentorg/sdk/dist/src/filled.js +24 -0
- package/dist/node_modules/@agentorg/sdk/dist/src/index.d.ts +3 -2
- package/dist/node_modules/@agentorg/sdk/dist/src/index.js +2 -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 +4624 -739
- package/dist/node_modules/@agentorg/shell/dist/app.js +245 -202
- package/dist/node_modules/@agentorg/shell/package.json +23 -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/chats.d.ts +92 -0
- package/dist/node_modules/assistant/dist/src/chats.js +357 -0
- package/dist/node_modules/assistant/dist/src/engine.d.ts +42 -0
- package/dist/node_modules/assistant/dist/src/engine.js +160 -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 +259 -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 +57 -0
- package/dist/node_modules/assistant/dist/src/tools.js +102 -0
- package/dist/node_modules/assistant/package.json +30 -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 +10 -68
- package/dist/src/cli.js +3 -7
- package/dist/src/folders.d.ts +2 -0
- package/dist/src/folders.js +45 -0
- package/dist/src/gateway.d.ts +13 -8
- package/dist/src/gateway.js +119 -296
- package/dist/src/index.d.ts +4 -5
- package/dist/src/index.js +3 -4
- package/dist/src/live.d.ts +17 -0
- package/dist/src/live.js +109 -0
- 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 +36 -0
- package/dist/src/programs.js +198 -0
- package/dist/src/signin.d.ts +12 -3
- package/dist/src/signin.js +30 -6
- package/package.json +4 -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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine: the looper bound to one agent. Its chats are the looper's threads, its model is the
|
|
3
|
+
* agent's `model` slot, and what a request says and offers is read from what the agent is bound to.
|
|
4
|
+
* Its host says where the records are kept and what the agent is told when no `settings` is bound.
|
|
5
|
+
*/
|
|
6
|
+
import type { agentSettings, chat, kv, llmSession } from "@agentorg/interfaces";
|
|
7
|
+
import { type Context, type Slot } from "@agentorg/sdk";
|
|
8
|
+
type Host = Pick<Context<{
|
|
9
|
+
model: typeof llmSession;
|
|
10
|
+
settings: typeof agentSettings;
|
|
11
|
+
}, {
|
|
12
|
+
chat: typeof chat;
|
|
13
|
+
}>, "slots" | "exports" | "exposed" | "onExposed" | "log">;
|
|
14
|
+
export declare function startEngine(ctx: Host, options: {
|
|
15
|
+
store: Slot<typeof kv>["call"];
|
|
16
|
+
/** What the agent is told while no `settings` is bound. */
|
|
17
|
+
instructions(): string;
|
|
18
|
+
/** Whether it starts stopped, as it was left. */
|
|
19
|
+
stopped?: boolean;
|
|
20
|
+
}): {
|
|
21
|
+
/** The models the agent can use, and the one chosen for it. */
|
|
22
|
+
models(): Promise<{
|
|
23
|
+
models: {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
}[];
|
|
27
|
+
current?: string | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
/** Choose the model for its next requests, kept with it; with none, the provider's default. */
|
|
30
|
+
setModel(model: string | undefined): Promise<void>;
|
|
31
|
+
/** Stop the agent: its turns are cut and none starts until `start`. Its chats stay readable. */
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
start: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Close for good: its turns are cut, and none starts after. They go on in the engine that
|
|
36
|
+
* opens this store next.
|
|
37
|
+
*/
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
/** Settles when every chat's latest turn has written all it will. */
|
|
40
|
+
settled(): Promise<void>;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Refused } from "@agentorg/sdk";
|
|
2
|
+
import { createChats } from "./chats.js";
|
|
3
|
+
import { instructionsWith, skillTool } from "./settings.js";
|
|
4
|
+
import { listedBy, listsTools, offered, relayed } from "./tools.js";
|
|
5
|
+
/** Where the agent keeps the model chosen for it, beside its chats in the store. */
|
|
6
|
+
const MODEL_KEY = "settings/model";
|
|
7
|
+
export function startEngine(ctx, options) {
|
|
8
|
+
const { store } = options;
|
|
9
|
+
/** The model chosen for this agent, if any; read for each request. */
|
|
10
|
+
const chosen = async () => {
|
|
11
|
+
const { value } = await store.get({ key: MODEL_KEY });
|
|
12
|
+
return typeof value === "string" ? value : undefined;
|
|
13
|
+
};
|
|
14
|
+
/** What was last reported as left out, so a change is logged once. */
|
|
15
|
+
let reported = "[]";
|
|
16
|
+
const report = (leftOut) => {
|
|
17
|
+
const now = JSON.stringify(leftOut);
|
|
18
|
+
if (now === reported)
|
|
19
|
+
return;
|
|
20
|
+
reported = now;
|
|
21
|
+
if (leftOut.length > 0)
|
|
22
|
+
ctx.log.warn("Not everything is offered to the model.", { leftOut });
|
|
23
|
+
else
|
|
24
|
+
ctx.log.info("Everything is offered to the model again.");
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* What a request says and offers, and to which model, read afresh: none of it outlives it.
|
|
28
|
+
* `leftOut` is what it couldn't offer, and why.
|
|
29
|
+
*/
|
|
30
|
+
const request = async () => {
|
|
31
|
+
const settings = ctx.slots.settings.bound ? await ctx.slots.settings.call.get({}) : undefined;
|
|
32
|
+
const told = settings
|
|
33
|
+
? instructionsWith(settings.instructions, settings.skills)
|
|
34
|
+
: { instructions: options.instructions(), leftOut: [] };
|
|
35
|
+
const own = settings?.skills.length ? [skillTool(ctx.slots.settings)] : [];
|
|
36
|
+
// In the order they came, each asked at once so one slow server delays only itself.
|
|
37
|
+
const exposed = await Promise.all(ctx
|
|
38
|
+
.exposed()
|
|
39
|
+
.filter((slot) => listsTools(slot.described))
|
|
40
|
+
.map((slot) => listedBy(slot.slot, slot)));
|
|
41
|
+
const fitted = offered([...own, ...exposed.flatMap((one) => one.candidates)]);
|
|
42
|
+
const leftOut = [...told.leftOut, ...exposed.flatMap((one) => one.leftOut), ...fitted.leftOut];
|
|
43
|
+
report(leftOut);
|
|
44
|
+
return { instructions: told.instructions, tools: fitted.tools, model: await chosen(), leftOut };
|
|
45
|
+
};
|
|
46
|
+
/** The model slot as the looper asks it: what it refuses is told with its code. */
|
|
47
|
+
const model = {
|
|
48
|
+
respond: (asked) => relayed(ctx.slots.model.call.respond(asked)),
|
|
49
|
+
// A model that is gone has nothing to stop.
|
|
50
|
+
cancel: async (asked) => (ctx.slots.model.bound ? ctx.slots.model.call.cancel(asked) : {}),
|
|
51
|
+
};
|
|
52
|
+
const chats = createChats({
|
|
53
|
+
store,
|
|
54
|
+
stopped: options.stopped ?? false,
|
|
55
|
+
model,
|
|
56
|
+
request: () => relayed(request()),
|
|
57
|
+
emit: {
|
|
58
|
+
message: (message) => ctx.exports.chat.emit("message", message),
|
|
59
|
+
delta: (delta) => ctx.exports.chat.emit("delta", delta),
|
|
60
|
+
status: (status) => ctx.exports.chat.emit("status", status),
|
|
61
|
+
chat: (entry) => ctx.exports.chat.emit("chat", entry),
|
|
62
|
+
},
|
|
63
|
+
log: ctx.log,
|
|
64
|
+
});
|
|
65
|
+
ctx.slots.model.on("delta", ({ requestId, text }) => chats.delta(requestId, text));
|
|
66
|
+
/**
|
|
67
|
+
* The turns that were cut off when the agent last ran go on once the model is bound, the
|
|
68
|
+
* settings answer, and no tools slot is away. As the agent starts, what it is bound to may not
|
|
69
|
+
* be running yet, so this is looked at again whenever that may have changed: a slot's provider
|
|
70
|
+
* is back, a tools slot is made or gone, or one says its tools changed. A tools slot that stays
|
|
71
|
+
* away holds them back; a message in a chat starts that chat's turn anyway.
|
|
72
|
+
*/
|
|
73
|
+
let wentOn = false;
|
|
74
|
+
/** Each tools slot heard for its tools changing, with how to stop hearing it. */
|
|
75
|
+
const heard = new Map();
|
|
76
|
+
const goOn = async () => {
|
|
77
|
+
for (const slot of ctx.exposed())
|
|
78
|
+
if (listsTools(slot.described) && !heard.has(slot))
|
|
79
|
+
heard.set(slot, slot.on("changed", look));
|
|
80
|
+
if (!ctx.slots.model.bound)
|
|
81
|
+
return;
|
|
82
|
+
// Refused while the settings can't answer, as a turn's own request would be.
|
|
83
|
+
const { leftOut } = await request();
|
|
84
|
+
if (leftOut.some((one) => one.reason === "not_connected"))
|
|
85
|
+
return;
|
|
86
|
+
await chats.resume();
|
|
87
|
+
done();
|
|
88
|
+
};
|
|
89
|
+
/** Nothing more is looked for: the turns have gone on, or the agent is stopped or closing. */
|
|
90
|
+
const done = () => {
|
|
91
|
+
wentOn = true;
|
|
92
|
+
for (const stop of heard.values())
|
|
93
|
+
stop();
|
|
94
|
+
heard.clear();
|
|
95
|
+
};
|
|
96
|
+
/** The look running now, and whether to look once more after it. */
|
|
97
|
+
let looking;
|
|
98
|
+
let again = false;
|
|
99
|
+
const look = () => {
|
|
100
|
+
again = true;
|
|
101
|
+
looking ??= (async () => {
|
|
102
|
+
// A start binds its slots one after another in one go, and one not bound yet reads as one
|
|
103
|
+
// the agent doesn't have: so it looks once they all are.
|
|
104
|
+
await Promise.resolve();
|
|
105
|
+
while (again && !wentOn) {
|
|
106
|
+
again = false;
|
|
107
|
+
await goOn().catch((error) => ctx.log.info("Turns that were cut off aren't looked for yet.", { error: String(error) }));
|
|
108
|
+
}
|
|
109
|
+
looking = undefined;
|
|
110
|
+
})();
|
|
111
|
+
};
|
|
112
|
+
ctx.slots.model.onBind(look);
|
|
113
|
+
ctx.slots.settings.onBind(look);
|
|
114
|
+
ctx.onExposed(look);
|
|
115
|
+
ctx.exports.chat.implement({
|
|
116
|
+
send: (input) => chats.send(input),
|
|
117
|
+
history: (input) => chats.history(input),
|
|
118
|
+
state: () => chats.state(),
|
|
119
|
+
list: (input) => chats.list(input),
|
|
120
|
+
rename: (input) => chats.rename(input),
|
|
121
|
+
archive: (input) => chats.archive(input),
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
/** The models the agent can use, and the one chosen for it. */
|
|
125
|
+
async models() {
|
|
126
|
+
const [{ models }, current] = await Promise.all([ctx.slots.model.call.models({}), chosen()]);
|
|
127
|
+
return { models, ...(current ? { current } : {}) };
|
|
128
|
+
},
|
|
129
|
+
/** Choose the model for its next requests, kept with it; with none, the provider's default. */
|
|
130
|
+
async setModel(model) {
|
|
131
|
+
if (!model) {
|
|
132
|
+
await store.delete({ key: MODEL_KEY });
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const { models } = await ctx.slots.model.call.models({});
|
|
136
|
+
if (!models.some((offered) => offered.id === model))
|
|
137
|
+
throw new Refused("unknown", `${model} isn't one of the models offered.`);
|
|
138
|
+
await store.set({ key: MODEL_KEY, value: model });
|
|
139
|
+
},
|
|
140
|
+
/** Stop the agent: its turns are cut and none starts until `start`. Its chats stay readable. */
|
|
141
|
+
stop() {
|
|
142
|
+
done();
|
|
143
|
+
return chats.stop();
|
|
144
|
+
},
|
|
145
|
+
start: () => chats.start(),
|
|
146
|
+
/**
|
|
147
|
+
* Close for good: its turns are cut, and none starts after. They go on in the engine that
|
|
148
|
+
* opens this store next.
|
|
149
|
+
*/
|
|
150
|
+
close() {
|
|
151
|
+
done();
|
|
152
|
+
return chats.close();
|
|
153
|
+
},
|
|
154
|
+
/** Settles when every chat's latest turn has written all it will. */
|
|
155
|
+
async settled() {
|
|
156
|
+
await looking;
|
|
157
|
+
await chats.settled();
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine's record when it runs as an ordinary program: one small JSON file per key, in the
|
|
3
|
+
* agent's own folder. A new message writes one file, however long the record is, and each write
|
|
4
|
+
* lands whole. It answers as `kv@1` does, so the engine reads it as it reads any store.
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { mkdir, readdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
const missing = (error) => error.code === "ENOENT";
|
|
10
|
+
export function createLocalStore(dir) {
|
|
11
|
+
const keys = join(dir, "kv");
|
|
12
|
+
const scratch = join(dir, "tmp");
|
|
13
|
+
const pathOf = (key) => join(keys, encodeURIComponent(key));
|
|
14
|
+
return {
|
|
15
|
+
async get({ key }) {
|
|
16
|
+
try {
|
|
17
|
+
return { value: JSON.parse(await readFile(pathOf(key), "utf8")) };
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (missing(error))
|
|
21
|
+
return {};
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
async set({ key, value }) {
|
|
26
|
+
await mkdir(keys, { recursive: true, mode: 0o700 });
|
|
27
|
+
await mkdir(scratch, { recursive: true, mode: 0o700 });
|
|
28
|
+
const temporary = join(scratch, randomUUID());
|
|
29
|
+
await writeFile(temporary, JSON.stringify(value), { mode: 0o600, flush: true });
|
|
30
|
+
await rename(temporary, pathOf(key));
|
|
31
|
+
return {};
|
|
32
|
+
},
|
|
33
|
+
async delete({ key }) {
|
|
34
|
+
try {
|
|
35
|
+
await rm(pathOf(key));
|
|
36
|
+
return { deleted: true };
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (missing(error))
|
|
40
|
+
return { deleted: false };
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
async list({ prefix = "", after, limit = 1000 }) {
|
|
45
|
+
const names = await readdir(keys).catch((error) => {
|
|
46
|
+
if (missing(error))
|
|
47
|
+
return [];
|
|
48
|
+
throw error;
|
|
49
|
+
});
|
|
50
|
+
const found = names
|
|
51
|
+
.map(decodeURIComponent)
|
|
52
|
+
.filter((key) => key.startsWith(prefix) && (after === undefined || key > after))
|
|
53
|
+
.sort();
|
|
54
|
+
const page = found.slice(0, limit);
|
|
55
|
+
return { keys: page, next: found.length > limit ? (page.at(-1) ?? null) : null };
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Log } from "@agentorg/sdk";
|
|
2
|
+
export interface AgentProviderOptions {
|
|
3
|
+
hubUrl: string;
|
|
4
|
+
/** The provider's own Actor, bound to `hub.actors@1` at `actors` and to the model at `model`. */
|
|
5
|
+
actorId: string;
|
|
6
|
+
credential: string;
|
|
7
|
+
/** The export its `model` slot is bound to, which each agent it makes is bound to in turn. */
|
|
8
|
+
model: {
|
|
9
|
+
actor: string;
|
|
10
|
+
export: string;
|
|
11
|
+
};
|
|
12
|
+
/** A private folder of the provider's, which holds each agent's credential and record. */
|
|
13
|
+
dir: string;
|
|
14
|
+
log?: Log;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentProvider {
|
|
17
|
+
/** Leave the Hub, every agent with it. They stay, and rejoin at the next start as each was left. */
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** Run the bundled agent provider as an Actor exporting `agent.provider@1` as `provider`. */
|
|
21
|
+
export declare function startAgentProvider(options: AgentProviderOptions): Promise<AgentProvider>;
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bundled agent provider: it offers one creatable, Assistant, and runs each agent in this
|
|
3
|
+
* process as its own Actor on its own channel. A stopped agent stays on its channel, so its chats
|
|
4
|
+
* can be read, and runs no turn until it is started. Each agent's chats and model choice are kept
|
|
5
|
+
* in the provider's private folder.
|
|
6
|
+
*/
|
|
7
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { rm } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { agentProvider, agentSettings, chat, hubActors, llmSession } from "@agentorg/interfaces";
|
|
11
|
+
import { NotConnected, Refused } from "@agentorg/sdk";
|
|
12
|
+
import { connect } from "@agentorg/sdk/client";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { startEngine } from "./engine.js";
|
|
15
|
+
import { createLocalStore } from "./local-store.js";
|
|
16
|
+
const ASSISTANT_INSTRUCTIONS = `You are an assistant in AgentOrg, working for the person who created you.
|
|
17
|
+
You act only through your tools, and your tools are exactly the connections the person gave you. If something needs a connection you don't have, say which.
|
|
18
|
+
Before you promise to do something, check that one of your tools does it. A connection you are given later shows up as new tools at your next turn; until then, don't say you can use it.
|
|
19
|
+
Keep replies short and plain.`;
|
|
20
|
+
const ASSISTANT = {
|
|
21
|
+
id: "assistant",
|
|
22
|
+
title: "Assistant",
|
|
23
|
+
description: "An agent that chats, and acts through the connections you give it.",
|
|
24
|
+
instructions: ASSISTANT_INSTRUCTIONS,
|
|
25
|
+
asks: [],
|
|
26
|
+
};
|
|
27
|
+
/** What is kept of an agent between runs, in the provider's private file. */
|
|
28
|
+
const Stored = z.object({ credential: z.string(), stopped: z.boolean() });
|
|
29
|
+
const FILE = "agents.json";
|
|
30
|
+
const quiet = { info() { }, warn() { }, error() { } };
|
|
31
|
+
/** Run the bundled agent provider as an Actor exporting `agent.provider@1` as `provider`. */
|
|
32
|
+
export async function startAgentProvider(options) {
|
|
33
|
+
const log = options.log ?? quiet;
|
|
34
|
+
const { hubUrl, dir } = options;
|
|
35
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
36
|
+
chmodSync(dir, 0o700);
|
|
37
|
+
const path = join(dir, FILE);
|
|
38
|
+
const folderOf = (agent) => join(dir, "agents", agent);
|
|
39
|
+
/** The file; one that can't be read is set aside, so the agents in it can be recovered by hand. */
|
|
40
|
+
const read = () => {
|
|
41
|
+
let raw;
|
|
42
|
+
try {
|
|
43
|
+
raw = readFileSync(path, "utf8");
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code === "ENOENT")
|
|
47
|
+
return {};
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return z.record(z.string(), Stored).parse(JSON.parse(raw));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
renameSync(path, `${path}.unreadable-${Date.now()}`);
|
|
55
|
+
log.error("The agents file can't be read: it is set aside and starts empty.");
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const stored = read();
|
|
60
|
+
const save = () => {
|
|
61
|
+
writeFileSync(`${path}.tmp`, JSON.stringify(stored), { mode: 0o600, flush: true });
|
|
62
|
+
renameSync(`${path}.tmp`, path);
|
|
63
|
+
};
|
|
64
|
+
const agents = new Map();
|
|
65
|
+
let closing = false;
|
|
66
|
+
const held = (agent) => {
|
|
67
|
+
const found = agents.get(agent);
|
|
68
|
+
if (!found)
|
|
69
|
+
throw new Refused("unknown", `This provider made no agent ${agent}.`);
|
|
70
|
+
return found;
|
|
71
|
+
};
|
|
72
|
+
/** An agent's engine, while it is on its channel: running, or stopped. */
|
|
73
|
+
const engineOf = (agent) => {
|
|
74
|
+
const { channel, engine, detail } = held(agent);
|
|
75
|
+
if (!channel || !engine)
|
|
76
|
+
throw new Refused("unavailable", detail ?? "It isn't running.");
|
|
77
|
+
return engine;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* What an agent's model answered. A model that is away is refused as that, where the bare
|
|
81
|
+
* error would reach the caller as its own slot being away.
|
|
82
|
+
*/
|
|
83
|
+
const ofModel = (asked) => asked.catch((error) => {
|
|
84
|
+
if (error instanceof NotConnected)
|
|
85
|
+
throw new Refused("not_connected", "Its model isn't connected.");
|
|
86
|
+
throw error;
|
|
87
|
+
});
|
|
88
|
+
const inTurn = (agent, work) => {
|
|
89
|
+
const one = held(agent);
|
|
90
|
+
const done = one.queue.then(() => work(one));
|
|
91
|
+
one.queue = done.catch(() => { });
|
|
92
|
+
return done;
|
|
93
|
+
};
|
|
94
|
+
/** Join the Hub as the agent, with its engine running, or stopped if it was left so. */
|
|
95
|
+
const open = async (agent, one) => {
|
|
96
|
+
one.state = "starting";
|
|
97
|
+
delete one.detail;
|
|
98
|
+
const { stopped } = stored[agent];
|
|
99
|
+
let engine;
|
|
100
|
+
try {
|
|
101
|
+
const channel = await connect({
|
|
102
|
+
hubUrl,
|
|
103
|
+
actorId: agent,
|
|
104
|
+
credential: stored[agent].credential,
|
|
105
|
+
slots: { model: llmSession, settings: agentSettings },
|
|
106
|
+
exports: { chat },
|
|
107
|
+
log,
|
|
108
|
+
start(ctx) {
|
|
109
|
+
engine = startEngine(ctx, {
|
|
110
|
+
store: createLocalStore(folderOf(agent)),
|
|
111
|
+
instructions: () => ASSISTANT_INSTRUCTIONS,
|
|
112
|
+
stopped,
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
one.channel = channel;
|
|
117
|
+
one.engine = engine;
|
|
118
|
+
one.state = stopped ? "stopped" : "running";
|
|
119
|
+
void channel.closed.then(() => {
|
|
120
|
+
if (one.channel !== channel)
|
|
121
|
+
return;
|
|
122
|
+
delete one.channel;
|
|
123
|
+
one.state = "down";
|
|
124
|
+
one.detail = "Its connection to the Hub ended.";
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
one.state = "down";
|
|
129
|
+
one.detail = error instanceof Error ? error.message : String(error);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/** Cut its turns, close its channel, and wait until its engine has written all it will. */
|
|
134
|
+
const halt = async (one) => {
|
|
135
|
+
const { channel, engine } = one;
|
|
136
|
+
delete one.channel;
|
|
137
|
+
if (!channel || !engine)
|
|
138
|
+
return;
|
|
139
|
+
await engine.close();
|
|
140
|
+
channel.close();
|
|
141
|
+
await channel.closed;
|
|
142
|
+
await engine.settled();
|
|
143
|
+
};
|
|
144
|
+
await Promise.all(Object.keys(stored).map(async (agent) => {
|
|
145
|
+
const one = { state: "stopped", queue: Promise.resolve() };
|
|
146
|
+
agents.set(agent, one);
|
|
147
|
+
try {
|
|
148
|
+
await open(agent, one);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
log.error(`Agent ${agent} didn't rejoin the Hub: ${String(error)}`);
|
|
152
|
+
// The Hub no longer knows it: its Actor was closed while the provider was away.
|
|
153
|
+
if (error instanceof Refused && error.code === "forbidden") {
|
|
154
|
+
agents.delete(agent);
|
|
155
|
+
delete stored[agent];
|
|
156
|
+
save();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
const haltAll = () => Promise.all([...agents.keys()].map((agent) => inTurn(agent, halt).catch(() => { })));
|
|
161
|
+
const provider = await connect({
|
|
162
|
+
hubUrl,
|
|
163
|
+
actorId: options.actorId,
|
|
164
|
+
credential: options.credential,
|
|
165
|
+
slots: { actors: hubActors, model: llmSession },
|
|
166
|
+
exports: { provider: agentProvider },
|
|
167
|
+
log,
|
|
168
|
+
start(ctx) {
|
|
169
|
+
ctx.exports.provider.implement({
|
|
170
|
+
creatable: async () => ({ creatables: [ASSISTANT] }),
|
|
171
|
+
async create({ creatable, name }) {
|
|
172
|
+
if (creatable !== ASSISTANT.id)
|
|
173
|
+
throw new Refused("unknown", `This provider offers no ${creatable}.`);
|
|
174
|
+
// The provider is bound to the model's export, so it can give the agent that binding.
|
|
175
|
+
const { actorId: agent, credential } = await ctx.slots.actors.call.create({
|
|
176
|
+
name,
|
|
177
|
+
bindings: [
|
|
178
|
+
{ slot: "model", provider: options.model.actor, export: options.model.export },
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
const one = { state: "starting", queue: Promise.resolve() };
|
|
182
|
+
try {
|
|
183
|
+
stored[agent] = { credential: credential, stopped: false };
|
|
184
|
+
await open(agent, one);
|
|
185
|
+
if (closing)
|
|
186
|
+
throw new Refused("unavailable", "This provider is stopping.");
|
|
187
|
+
agents.set(agent, one);
|
|
188
|
+
save();
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
delete stored[agent];
|
|
192
|
+
await halt(one);
|
|
193
|
+
await ctx.slots.actors.call.close({ actorId: agent }).catch(() => { });
|
|
194
|
+
await rm(folderOf(agent), { recursive: true, force: true });
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
return { agent, settings: "settings", chat: "chat" };
|
|
198
|
+
},
|
|
199
|
+
status: async ({ agent }) => {
|
|
200
|
+
const { state, detail } = held(agent);
|
|
201
|
+
return { state, ...(detail ? { detail } : {}) };
|
|
202
|
+
},
|
|
203
|
+
start: ({ agent }) => inTurn(agent, async (one) => {
|
|
204
|
+
if (one.state === "running")
|
|
205
|
+
return {};
|
|
206
|
+
stored[agent].stopped = false;
|
|
207
|
+
save();
|
|
208
|
+
// One whose connection ended joins again; one that is only stopped goes on.
|
|
209
|
+
if (!one.channel || !one.engine)
|
|
210
|
+
await open(agent, one);
|
|
211
|
+
else {
|
|
212
|
+
one.engine.start();
|
|
213
|
+
one.state = "running";
|
|
214
|
+
}
|
|
215
|
+
return {};
|
|
216
|
+
}),
|
|
217
|
+
stop: ({ agent }) => inTurn(agent, async (one) => {
|
|
218
|
+
stored[agent].stopped = true;
|
|
219
|
+
save();
|
|
220
|
+
// One whose connection ended joins again, stopped, so that it can be read.
|
|
221
|
+
if (!one.channel || !one.engine)
|
|
222
|
+
await open(agent, one);
|
|
223
|
+
else {
|
|
224
|
+
await one.engine.stop();
|
|
225
|
+
one.state = "stopped";
|
|
226
|
+
}
|
|
227
|
+
return {};
|
|
228
|
+
}),
|
|
229
|
+
models: ({ agent }) => ofModel(engineOf(agent).models()),
|
|
230
|
+
// In the agent's turn, so a choice never lands after the agent is removed.
|
|
231
|
+
setModel: ({ agent, model }) => inTurn(agent, async () => {
|
|
232
|
+
await ofModel(engineOf(agent).setModel(model));
|
|
233
|
+
return {};
|
|
234
|
+
}),
|
|
235
|
+
remove: ({ agent }) => inTurn(agent, async (one) => {
|
|
236
|
+
await halt(one);
|
|
237
|
+
one.state = "down";
|
|
238
|
+
one.detail = "It is being removed.";
|
|
239
|
+
await ctx.slots.actors.call.close({ actorId: agent });
|
|
240
|
+
agents.delete(agent);
|
|
241
|
+
delete stored[agent];
|
|
242
|
+
save();
|
|
243
|
+
await rm(folderOf(agent), { recursive: true, force: true });
|
|
244
|
+
return {};
|
|
245
|
+
}),
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
}).catch(async (error) => {
|
|
249
|
+
await haltAll();
|
|
250
|
+
throw error;
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
253
|
+
async close() {
|
|
254
|
+
closing = true;
|
|
255
|
+
await haltAll();
|
|
256
|
+
provider.close();
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the `settings` slot adds to a request: the skills exposed to this agent, named in its
|
|
3
|
+
* instructions, and one tool to read them. A skill's text is read only when the model asks for it.
|
|
4
|
+
*/
|
|
5
|
+
import type { agentSettings, SkillEntry } from "@agentorg/interfaces";
|
|
6
|
+
import type { Slot } from "@agentorg/sdk";
|
|
7
|
+
import type { z } from "zod";
|
|
8
|
+
import type { Candidate, LeftOut } from "./tools.js";
|
|
9
|
+
/** The longest instructions a request can carry. */
|
|
10
|
+
export declare const MAX_INSTRUCTIONS = 200000;
|
|
11
|
+
/** The agent's instructions and the skills that fit in them; any that don't are reported. */
|
|
12
|
+
export declare function instructionsWith(instructions: string, skills: z.output<typeof SkillEntry>[]): {
|
|
13
|
+
instructions: string;
|
|
14
|
+
leftOut: LeftOut[];
|
|
15
|
+
};
|
|
16
|
+
/** The one way the model reads a skill: its `SKILL.md`, or a file of its folder by `path`. */
|
|
17
|
+
export declare function skillTool(slot: Slot<typeof agentSettings>): Candidate;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** The longest instructions a request can carry. */
|
|
2
|
+
export const MAX_INSTRUCTIONS = 200_000;
|
|
3
|
+
const SLOT = "settings";
|
|
4
|
+
const HEADING = `## Skills
|
|
5
|
+
A skill is written instructions for a kind of task. When one fits what you're asked, read it with settings__skill and follow it before you start. Pass path to read a file its SKILL.md refers to.`;
|
|
6
|
+
/** The agent's instructions and the skills that fit in them; any that don't are reported. */
|
|
7
|
+
export function instructionsWith(instructions, skills) {
|
|
8
|
+
const leftOut = [];
|
|
9
|
+
if (skills.length === 0)
|
|
10
|
+
return { instructions, leftOut };
|
|
11
|
+
let text = `${instructions}\n\n${HEADING}`;
|
|
12
|
+
for (const { name, description } of skills) {
|
|
13
|
+
const line = `\n- ${name}: ${description}`;
|
|
14
|
+
if (text.length + line.length > MAX_INSTRUCTIONS)
|
|
15
|
+
leftOut.push({ slot: SLOT, tool: name, reason: "limit" });
|
|
16
|
+
else
|
|
17
|
+
text += line;
|
|
18
|
+
}
|
|
19
|
+
return leftOut.length === skills.length
|
|
20
|
+
? { instructions, leftOut }
|
|
21
|
+
: { instructions: text, leftOut };
|
|
22
|
+
}
|
|
23
|
+
/** The one way the model reads a skill: its `SKILL.md`, or a file of its folder by `path`. */
|
|
24
|
+
export function skillTool(slot) {
|
|
25
|
+
return {
|
|
26
|
+
slot: SLOT,
|
|
27
|
+
name: "skill",
|
|
28
|
+
description: "Read a skill: its SKILL.md, or with path a file in its folder.",
|
|
29
|
+
parameters: {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
name: { type: "string", description: "The skill's name, as your instructions list it." },
|
|
33
|
+
path: { type: "string", description: "A file in the skill's folder, relative to it." },
|
|
34
|
+
},
|
|
35
|
+
required: ["name"],
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
},
|
|
38
|
+
run: async (args) => {
|
|
39
|
+
const { text } = await slot.call.skill(args);
|
|
40
|
+
return { output: text, ok: true };
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type Outcome, type Tool } from "@agentorg/looper";
|
|
2
|
+
import { type DescribedInterface } from "@agentorg/sdk";
|
|
3
|
+
import type { z } from "zod";
|
|
4
|
+
/** A tool as its slot gives it, before it has the name a request offers it under. */
|
|
5
|
+
export interface Candidate {
|
|
6
|
+
slot: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
parameters: Record<string, z.core.util.JSONType>;
|
|
10
|
+
run(input: unknown): Promise<Outcome>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Something the model isn't offered, and why: `name` (past 64 characters as a function name),
|
|
14
|
+
* `duplicate` (its function name is already taken), `limit` (past what a request can carry), or,
|
|
15
|
+
* with no `tool`, the code its slot's list failed with.
|
|
16
|
+
*/
|
|
17
|
+
export interface LeftOut {
|
|
18
|
+
slot: string;
|
|
19
|
+
tool?: string;
|
|
20
|
+
reason: string;
|
|
21
|
+
}
|
|
22
|
+
/** What a request can carry: its tools count, and, with the record and instructions, one frame. */
|
|
23
|
+
export declare const MAX_TOOLS = 128;
|
|
24
|
+
export declare const TOOLS_BUDGET: number;
|
|
25
|
+
/** The first `length` UTF-16 units of `text`, never ending inside a surrogate pair. */
|
|
26
|
+
export declare function head(text: string, length: number): string;
|
|
27
|
+
/** The code and message of what a call through a slot threw. */
|
|
28
|
+
export declare function codeOf(error: unknown): {
|
|
29
|
+
code: string;
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A call through a slot, as the looper is told how it went: what the slot refuses is the looper's
|
|
34
|
+
* `Refusal`, with the code to show and the slot's own error as its cause.
|
|
35
|
+
*/
|
|
36
|
+
export declare const relayed: <T>(call: Promise<T>) => Promise<T>;
|
|
37
|
+
/** Whether a slot is a `tools@1`, whose tools are whatever it lists. */
|
|
38
|
+
export declare const listsTools: (described: DescribedInterface) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* What a `tools@1` slot lists now. A slot that can't answer gives no tools and says why, and is
|
|
41
|
+
* asked again at the next request.
|
|
42
|
+
*/
|
|
43
|
+
export declare function listedBy(name: string, slot: {
|
|
44
|
+
readonly call: Readonly<Record<string, (input: unknown) => Promise<unknown>>>;
|
|
45
|
+
}): Promise<{
|
|
46
|
+
candidates: Candidate[];
|
|
47
|
+
leftOut: LeftOut[];
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* The tools one request offers, by function name, and what it can't. A character a function name
|
|
51
|
+
* can't have becomes `_`. Candidates are taken in order, so the first ones given are the ones kept
|
|
52
|
+
* when a request is full; what doesn't fit is reported, never sent.
|
|
53
|
+
*/
|
|
54
|
+
export declare function offered(candidates: Candidate[]): {
|
|
55
|
+
tools: Tool[];
|
|
56
|
+
leftOut: LeftOut[];
|
|
57
|
+
};
|