@clearideas/agent-runtime-cli 0.8.0 → 0.9.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 +26 -1
- package/dist/index.d.ts +8 -48
- package/dist/index.js +211 -361
- package/package.json +8 -12
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Clear Ideas Agent Runtime CLI
|
|
2
2
|
|
|
3
3
|
The `agent-runtime` CLI validates and runs agent manifests, resumes stored
|
|
4
|
-
runs, inspects events,
|
|
4
|
+
runs, inspects events, starts worker processes, and serves manifests over an
|
|
5
|
+
OpenAI-compatible API.
|
|
5
6
|
|
|
6
7
|
Install it in a project and run it with `npx`:
|
|
7
8
|
|
|
@@ -23,8 +24,12 @@ npx agent-runtime inspect run_123 --store ./.agent-runtime
|
|
|
23
24
|
npx agent-runtime events ./.agent-runtime/events.jsonl --run run_123 --tail 20
|
|
24
25
|
npx agent-runtime examples run variables --stream
|
|
25
26
|
npx agent-runtime run ./agent.yaml --store-driver sqlite --store ./.agent-runtime/runs.sqlite
|
|
27
|
+
npx agent-runtime serve ./support-chat.agent.yaml --port 8000
|
|
28
|
+
npx agent-runtime serve --server-config ./agent-runtime.server.yaml
|
|
26
29
|
```
|
|
27
30
|
|
|
31
|
+
Options accept `--name value` or `--name=value`.
|
|
32
|
+
|
|
28
33
|
`--stream` shows model text on stdout and lifecycle progress on stderr. Use
|
|
29
34
|
`--format ndjson` for a machine-readable stream containing event and result
|
|
30
35
|
messages, and `--show-reasoning` to opt into reasoning deltas in the pretty
|
|
@@ -247,3 +252,23 @@ newline-delimited `ready`, `event`, `result`, or `error` messages to stdout.
|
|
|
247
252
|
Child-process and remote execution adapters launch this command. The worker
|
|
248
253
|
uses only host-pinned `--config` and `--runtime-module` files; request-supplied
|
|
249
254
|
paths and inline configuration are rejected by default.
|
|
255
|
+
|
|
256
|
+
## Serve command
|
|
257
|
+
|
|
258
|
+
`agent-runtime serve` exposes agent manifests as models on an
|
|
259
|
+
OpenAI-compatible API (`/v1/models`, `/v1/chat/completions`), so chat front
|
|
260
|
+
ends and OpenAI SDKs can run whole agents:
|
|
261
|
+
|
|
262
|
+
```sh
|
|
263
|
+
export AGENT_RUNTIME_API_KEY="a-key-you-choose"
|
|
264
|
+
npx agent-runtime serve ./support-chat.agent.yaml --config ./runtime.yaml --port 8000
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
With no arguments, it reads `agent-runtime.server.yaml` (or `.yml`, `.json`)
|
|
268
|
+
from the working directory; `--server-config <file>` selects another file.
|
|
269
|
+
Manifests that declare `messages` receive the chat as conversation turns;
|
|
270
|
+
others receive variables mapped with `--input <variable>=<source>`. Serve
|
|
271
|
+
follows the worker's trust rules: webhook steps need an authorizing executor
|
|
272
|
+
from the runtime module, and requests never supply configuration. `--check`
|
|
273
|
+
validates everything and exits. See
|
|
274
|
+
[Serve agents over an OpenAI-compatible API](https://agent-runtime.clearideas.com/serving).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,45 +1,14 @@
|
|
|
1
|
-
import type { AgentManifest, RunResult
|
|
2
|
-
import { type ArtifactStore, type ApprovalAdapter, type ConnectionCredentialProvider, type EventSink, type ModelAdapter, type RunSandboxProvider, type RunStore, type SandboxAdapter, type StepExecutor, type SubRunAdapter, type ContextSummarizerAdapter, type AgentRuntimeMessagesOptions, type ToolAdapter, type WorkspaceProvider } from "@clearideas/agent-runtime-core";
|
|
3
|
-
import type { SandboxProvider } from "@clearideas/agent-runtime-sandbox";
|
|
1
|
+
import type { AgentManifest, RunResult } from "@clearideas/agent-runtime-contracts";
|
|
4
2
|
import { type ExecutionRequest, type WorkerInvocation, type WorkerMessage } from "@clearideas/agent-runtime-execution";
|
|
5
3
|
import { type AgentRuntimeConfig, type ConfiguredMcpToolAdapterOptions, type ModelAuthorizationPolicy, type WorkspaceCompositionOptions } from "@clearideas/agent-runtime-config";
|
|
4
|
+
import { type HostRuntime, type HostRuntimeModule, type ServeOptions } from "@clearideas/agent-runtime-server";
|
|
6
5
|
export interface CliIo {
|
|
7
6
|
stdout: (text: string) => void;
|
|
8
7
|
stderr: (text: string) => void;
|
|
9
8
|
}
|
|
10
9
|
export type CliStoreDriver = "file" | "sqlite";
|
|
11
10
|
/** Adapters a local runtime module may contribute to CLI execution. */
|
|
12
|
-
export
|
|
13
|
-
/** Called once after execution, including failed setup. Own only module-created resources. */
|
|
14
|
-
shutdown?: () => void | Promise<void>;
|
|
15
|
-
runStore?: RunStore;
|
|
16
|
-
artifactStore?: ArtifactStore;
|
|
17
|
-
model?: ModelAdapter;
|
|
18
|
-
tools?: ToolAdapter;
|
|
19
|
-
connectionCredentials?: ConnectionCredentialProvider;
|
|
20
|
-
approvals?: ApprovalAdapter;
|
|
21
|
-
sandbox?: SandboxAdapter;
|
|
22
|
-
subRuns?: SubRunAdapter;
|
|
23
|
-
/** Resolves manifest workspace bindings instead of the configuration's `workspaces` section. */
|
|
24
|
-
workspaces?: WorkspaceProvider;
|
|
25
|
-
/** Opens run sandboxes instead of the configuration's `sandbox` section. */
|
|
26
|
-
runSandbox?: RunSandboxProvider;
|
|
27
|
-
/** Backs `sandbox.driver: host` in the configuration. */
|
|
28
|
-
sandboxProvider?: SandboxProvider;
|
|
29
|
-
eventSinks?: EventSink[];
|
|
30
|
-
stepExecutors?: StepExecutor[];
|
|
31
|
-
/** Host default execution policies; manifests and steps override them. */
|
|
32
|
-
policies?: ExecutionPolicies;
|
|
33
|
-
/** Host execution policies applied last; manifests cannot override them. */
|
|
34
|
-
enforcedPolicies?: ExecutionPolicies;
|
|
35
|
-
/** Observes, changes, or replaces context summarization. */
|
|
36
|
-
summarizer?: ContextSummarizerAdapter;
|
|
37
|
-
/**
|
|
38
|
-
* Conversation message options, merged over the configuration's `messages`
|
|
39
|
-
* section: for example `authorizeArtifact` or a KMS-backed signer.
|
|
40
|
-
*/
|
|
41
|
-
messages?: AgentRuntimeMessagesOptions;
|
|
42
|
-
}
|
|
11
|
+
export type CliRuntime = HostRuntime;
|
|
43
12
|
export interface CliRuntimeContext {
|
|
44
13
|
manifest: AgentManifest;
|
|
45
14
|
runId?: string;
|
|
@@ -50,20 +19,7 @@ export interface CliRuntimeContext {
|
|
|
50
19
|
artifactDirectory?: string;
|
|
51
20
|
}
|
|
52
21
|
export type CliStoreContext = Omit<CliRuntimeContext, "manifest">;
|
|
53
|
-
export
|
|
54
|
-
store?: RunStore;
|
|
55
|
-
artifacts?: ArtifactStore;
|
|
56
|
-
modelAdapter?: ModelAdapter;
|
|
57
|
-
toolAdapter?: ToolAdapter;
|
|
58
|
-
credentialProvider?: ConnectionCredentialProvider;
|
|
59
|
-
approvalAdapter?: ApprovalAdapter;
|
|
60
|
-
sandboxAdapter?: SandboxAdapter;
|
|
61
|
-
subRunAdapter?: SubRunAdapter;
|
|
62
|
-
workspaceProvider?: WorkspaceProvider;
|
|
63
|
-
runSandboxProvider?: RunSandboxProvider;
|
|
64
|
-
eventSink?: EventSink;
|
|
65
|
-
executors?: StepExecutor[];
|
|
66
|
-
}
|
|
22
|
+
export type CliRuntimeModule = HostRuntimeModule;
|
|
67
23
|
export interface PortableWorkerOptions {
|
|
68
24
|
storeDirectory: string;
|
|
69
25
|
storeDriver?: CliStoreDriver;
|
|
@@ -105,6 +61,10 @@ export interface PortableWorkerOptions {
|
|
|
105
61
|
}
|
|
106
62
|
/** Runs one provider-neutral worker invocation in the current process. */
|
|
107
63
|
export declare const executeWorkerInvocation: (invocation: WorkerInvocation, options: PortableWorkerOptions) => Promise<RunResult>;
|
|
64
|
+
/** Parse `agent-runtime serve` arguments into server options. */
|
|
65
|
+
export declare const parseServeArguments: (args: string[]) => ServeOptions & {
|
|
66
|
+
check?: boolean;
|
|
67
|
+
};
|
|
108
68
|
export interface CliRunOptions {
|
|
109
69
|
signal?: AbortSignal;
|
|
110
70
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { fileURLToPath
|
|
4
|
-
import {
|
|
5
|
-
import { executionPoliciesSchema, messagesSignatureSchema, parseAgentVariableOverrides, parseConversationMessages, } from "@clearideas/agent-runtime-contracts";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { messagesSignatureSchema, parseAgentVariableOverrides, parseConversationMessages, } from "@clearideas/agent-runtime-contracts";
|
|
6
5
|
import { AgentRuntime, } from "@clearideas/agent-runtime-core";
|
|
7
6
|
import { EXECUTION_PROTOCOL_VERSION, parseWorkerInvocation, serializeWorkerMessage, } from "@clearideas/agent-runtime-execution";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { PromptMessageHistoryCompactor, PromptStepExecutor, } from "@clearideas/agent-runtime-step-prompt";
|
|
11
|
-
import { ApprovalStepExecutor, CodeStepExecutor, SubRunStepExecutor, WebhookStepExecutor, } from "@clearideas/agent-runtime-step-standard";
|
|
7
|
+
import { discoverMcpConnectionTools, loadAgentRuntimeConfig, parseAgentRuntimeConfig, validateRuntimeConfiguration, } from "@clearideas/agent-runtime-config";
|
|
8
|
+
import { composeHostRuntime, hostRuntimeDependencies, loadHostRunStore, loadHostRuntime, resolveAgentRuntimeConfig, runServe, validateHostRuntime, } from "@clearideas/agent-runtime-server";
|
|
12
9
|
import { FileArtifactStore, FileAgentManifestSource, FileAgentRunManifestSource, FileRunStore, JsonlEventSink, } from "@clearideas/agent-runtime-store-local";
|
|
13
10
|
import { Document as YamlDocument, YAMLMap, isPair, isScalar, parse as parseYamlDocument, } from "yaml";
|
|
14
11
|
const defaultIo = {
|
|
@@ -30,6 +27,9 @@ Usage:
|
|
|
30
27
|
agent-runtime examples show <variables|conditions|loops>
|
|
31
28
|
agent-runtime examples run <variables|conditions|loops> [run options]
|
|
32
29
|
agent-runtime worker [--store <path>] [--store-driver <file|sqlite>] [--config <config.yaml>] [--runtime-module <local-js-file>]
|
|
30
|
+
agent-runtime serve [<manifest>] [--server-config <server.yaml>] [--no-server-config] [--served-model-name <name>] [--config <runtime.yaml>] [--runtime-module <local-js-file>] [--host <host>] [--port <port>] [--api-key-env <VAR>] [--allow-unauthenticated] [--input <variable>=<source>]... [--output <final|step:id|variable:name>] [--stream-mode <auto|live|committed>] [--progress <none|status>] [--store-driver <memory|sqlite>] [--store <path>] [--ledger <memory|sqlite:path>] [--on-unrecognized <unsigned|reject|restart>] [--client-tools <ignore|reject>] [--max-concurrent-runs <count>] [--request-timeout <ms>] [--warmup] [--check]
|
|
31
|
+
|
|
32
|
+
Options accept --name value or --name=value.
|
|
33
33
|
`;
|
|
34
34
|
const packageDirectory = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
35
35
|
const bundledExamplesDirectory = path.join(packageDirectory, "examples");
|
|
@@ -81,33 +81,55 @@ const resolveCliStore = async (parsed) => {
|
|
|
81
81
|
},
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Parse `--name value` and `--name=value` options. Flags take no value;
|
|
86
|
+
* repeatable options may appear more than once.
|
|
87
|
+
*/
|
|
88
|
+
const parseOptions = (args, allowed, flags = new Set(), repeatable = new Set()) => {
|
|
85
89
|
const positional = [];
|
|
86
90
|
const options = new Map();
|
|
91
|
+
const repeated = new Map();
|
|
87
92
|
for (let index = 0; index < args.length; index += 1) {
|
|
88
93
|
const value = args[index];
|
|
89
94
|
if (!value.startsWith("--")) {
|
|
90
95
|
positional.push(value);
|
|
91
96
|
continue;
|
|
92
97
|
}
|
|
93
|
-
const
|
|
98
|
+
const separator = value.indexOf("=");
|
|
99
|
+
const name = value.slice(2, separator < 0 ? undefined : separator);
|
|
100
|
+
const option = `--${name}`;
|
|
94
101
|
if (!allowed.has(name))
|
|
95
|
-
throw new Error(`Unknown option: ${
|
|
102
|
+
throw new Error(`Unknown option: ${option}`);
|
|
96
103
|
if (flags.has(name)) {
|
|
104
|
+
if (separator >= 0)
|
|
105
|
+
throw new Error(`Option ${option} does not take a value.`);
|
|
97
106
|
if (options.has(name))
|
|
98
|
-
throw new Error(`Option ${
|
|
107
|
+
throw new Error(`Option ${option} may only be provided once.`);
|
|
99
108
|
options.set(name, "true");
|
|
100
109
|
continue;
|
|
101
110
|
}
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
111
|
+
let optionValue;
|
|
112
|
+
if (separator >= 0) {
|
|
113
|
+
optionValue = value.slice(separator + 1);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
optionValue = args[index + 1];
|
|
117
|
+
if (optionValue?.startsWith("--"))
|
|
118
|
+
optionValue = undefined;
|
|
119
|
+
index += 1;
|
|
120
|
+
}
|
|
121
|
+
if (!optionValue)
|
|
122
|
+
throw new Error(`Option ${option} requires a value.`);
|
|
123
|
+
if (repeatable.has(name)) {
|
|
124
|
+
repeated.set(name, [...(repeated.get(name) ?? []), optionValue]);
|
|
125
|
+
options.set(name, optionValue);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
105
128
|
if (options.has(name))
|
|
106
|
-
throw new Error(`Option ${
|
|
129
|
+
throw new Error(`Option ${option} may only be provided once.`);
|
|
107
130
|
options.set(name, optionValue);
|
|
108
|
-
index += 1;
|
|
109
131
|
}
|
|
110
|
-
return { positional, options };
|
|
132
|
+
return { positional, options, repeated };
|
|
111
133
|
};
|
|
112
134
|
const requireOnePositional = (parsed, label) => {
|
|
113
135
|
if (parsed.positional.length !== 1)
|
|
@@ -210,7 +232,7 @@ const inspectConnections = async (args, io) => {
|
|
|
210
232
|
throw new Error(`Unknown connection "${name}".`);
|
|
211
233
|
}
|
|
212
234
|
const runtimeModulePath = parsed.options.get("runtime-module");
|
|
213
|
-
const moduleRuntime = await
|
|
235
|
+
const moduleRuntime = await loadHostRuntime(runtimeModulePath, {
|
|
214
236
|
manifest: {
|
|
215
237
|
schemaVersion: "1.0",
|
|
216
238
|
connections: names.map((ref) => ({ ref })),
|
|
@@ -260,7 +282,7 @@ const inspect = async (args, io) => {
|
|
|
260
282
|
const runId = requireOnePositional(parsed, "run id");
|
|
261
283
|
const resolved = await resolveCliStore(parsed);
|
|
262
284
|
try {
|
|
263
|
-
const store = (await
|
|
285
|
+
const store = (await loadHostRunStore(parsed.options.get("runtime-module"), {
|
|
264
286
|
runId,
|
|
265
287
|
storeDirectory: resolved.baseDirectory,
|
|
266
288
|
storeDriver: resolved.driver,
|
|
@@ -304,244 +326,6 @@ const events = async (args, io) => {
|
|
|
304
326
|
for (const event of selected)
|
|
305
327
|
io.stdout(`${JSON.stringify(event)}\n`);
|
|
306
328
|
};
|
|
307
|
-
const adapterMethod = (value, name) => value != null &&
|
|
308
|
-
typeof value === "object" &&
|
|
309
|
-
typeof value[name] === "function";
|
|
310
|
-
const validateRuntime = (runtime) => {
|
|
311
|
-
if (runtime.shutdown !== undefined && typeof runtime.shutdown !== "function")
|
|
312
|
-
throw new Error("Runtime shutdown must be a function.");
|
|
313
|
-
if (runtime.runStore &&
|
|
314
|
-
(!adapterMethod(runtime.runStore, "createRun") ||
|
|
315
|
-
!adapterMethod(runtime.runStore, "loadRun") ||
|
|
316
|
-
!adapterMethod(runtime.runStore, "saveCheckpoint"))) {
|
|
317
|
-
throw new Error("Runtime runStore must implement the RunStore lifecycle methods.");
|
|
318
|
-
}
|
|
319
|
-
if (runtime.artifactStore &&
|
|
320
|
-
(!adapterMethod(runtime.artifactStore, "put") ||
|
|
321
|
-
!adapterMethod(runtime.artifactStore, "get"))) {
|
|
322
|
-
throw new Error("Runtime artifactStore must implement ArtifactStore.put() and get().");
|
|
323
|
-
}
|
|
324
|
-
if (runtime.model && !adapterMethod(runtime.model, "generate"))
|
|
325
|
-
throw new Error("Runtime model must implement ModelAdapter.generate().");
|
|
326
|
-
if (runtime.tools &&
|
|
327
|
-
(!adapterMethod(runtime.tools, "listTools") ||
|
|
328
|
-
!adapterMethod(runtime.tools, "executeTool"))) {
|
|
329
|
-
throw new Error("Runtime tools must implement ToolAdapter.listTools() and executeTool().");
|
|
330
|
-
}
|
|
331
|
-
if (runtime.connectionCredentials &&
|
|
332
|
-
!adapterMethod(runtime.connectionCredentials, "getCredential")) {
|
|
333
|
-
throw new Error("Runtime connectionCredentials must implement ConnectionCredentialProvider.getCredential().");
|
|
334
|
-
}
|
|
335
|
-
if (runtime.approvals && !adapterMethod(runtime.approvals, "requestApproval"))
|
|
336
|
-
throw new Error("Runtime approvals must implement ApprovalAdapter.requestApproval().");
|
|
337
|
-
if (runtime.sandbox && !adapterMethod(runtime.sandbox, "execute"))
|
|
338
|
-
throw new Error("Runtime sandbox must implement SandboxAdapter.execute().");
|
|
339
|
-
if (runtime.subRuns && !adapterMethod(runtime.subRuns, "execute"))
|
|
340
|
-
throw new Error("Runtime subRuns must implement SubRunAdapter.execute().");
|
|
341
|
-
if (runtime.summarizer && !adapterMethod(runtime.summarizer, "summarize"))
|
|
342
|
-
throw new Error("Runtime summarizer must implement ContextSummarizerAdapter.summarize().");
|
|
343
|
-
if (runtime.workspaces &&
|
|
344
|
-
!adapterMethod(runtime.workspaces, "resolveWorkspace")) {
|
|
345
|
-
throw new Error("Runtime workspaces must implement WorkspaceProvider.resolveWorkspace().");
|
|
346
|
-
}
|
|
347
|
-
if (runtime.runSandbox &&
|
|
348
|
-
(!adapterMethod(runtime.runSandbox, "open") ||
|
|
349
|
-
!adapterMethod(runtime.runSandbox, "validate") ||
|
|
350
|
-
!adapterMethod(runtime.runSandbox, "tools"))) {
|
|
351
|
-
throw new Error("Runtime runSandbox must implement RunSandboxProvider.tools(), validate(), and open().");
|
|
352
|
-
}
|
|
353
|
-
if (runtime.sandboxProvider &&
|
|
354
|
-
(!adapterMethod(runtime.sandboxProvider, "create") ||
|
|
355
|
-
!adapterMethod(runtime.sandboxProvider, "execute") ||
|
|
356
|
-
!adapterMethod(runtime.sandboxProvider, "terminate"))) {
|
|
357
|
-
throw new Error("Runtime sandboxProvider must implement the SandboxProvider lifecycle methods.");
|
|
358
|
-
}
|
|
359
|
-
if (runtime.eventSinks &&
|
|
360
|
-
(!Array.isArray(runtime.eventSinks) ||
|
|
361
|
-
runtime.eventSinks.some((sink) => !adapterMethod(sink, "emit")))) {
|
|
362
|
-
throw new Error("Runtime eventSinks must be an array of EventSink values.");
|
|
363
|
-
}
|
|
364
|
-
if (runtime.stepExecutors &&
|
|
365
|
-
(!Array.isArray(runtime.stepExecutors) ||
|
|
366
|
-
runtime.stepExecutors.some((executor) => !executor ||
|
|
367
|
-
typeof executor !== "object" ||
|
|
368
|
-
typeof executor.type !== "string" ||
|
|
369
|
-
!adapterMethod(executor, "execute")))) {
|
|
370
|
-
throw new Error("Runtime stepExecutors must implement StepExecutor.");
|
|
371
|
-
}
|
|
372
|
-
return runtime;
|
|
373
|
-
};
|
|
374
|
-
const normalizeRuntime = (runtime) => ({
|
|
375
|
-
...(runtime.shutdown ? { shutdown: runtime.shutdown } : {}),
|
|
376
|
-
...((runtime.runStore ?? runtime.store)
|
|
377
|
-
? { runStore: runtime.runStore ?? runtime.store }
|
|
378
|
-
: {}),
|
|
379
|
-
...((runtime.artifactStore ?? runtime.artifacts)
|
|
380
|
-
? { artifactStore: runtime.artifactStore ?? runtime.artifacts }
|
|
381
|
-
: {}),
|
|
382
|
-
...((runtime.model ?? runtime.modelAdapter)
|
|
383
|
-
? { model: runtime.model ?? runtime.modelAdapter }
|
|
384
|
-
: {}),
|
|
385
|
-
...((runtime.tools ?? runtime.toolAdapter)
|
|
386
|
-
? { tools: runtime.tools ?? runtime.toolAdapter }
|
|
387
|
-
: {}),
|
|
388
|
-
...((runtime.connectionCredentials ?? runtime.credentialProvider)
|
|
389
|
-
? {
|
|
390
|
-
connectionCredentials: runtime.connectionCredentials ?? runtime.credentialProvider,
|
|
391
|
-
}
|
|
392
|
-
: {}),
|
|
393
|
-
...((runtime.approvals ?? runtime.approvalAdapter)
|
|
394
|
-
? { approvals: runtime.approvals ?? runtime.approvalAdapter }
|
|
395
|
-
: {}),
|
|
396
|
-
...((runtime.sandbox ?? runtime.sandboxAdapter)
|
|
397
|
-
? { sandbox: runtime.sandbox ?? runtime.sandboxAdapter }
|
|
398
|
-
: {}),
|
|
399
|
-
...((runtime.subRuns ?? runtime.subRunAdapter)
|
|
400
|
-
? { subRuns: runtime.subRuns ?? runtime.subRunAdapter }
|
|
401
|
-
: {}),
|
|
402
|
-
...((runtime.workspaces ?? runtime.workspaceProvider)
|
|
403
|
-
? { workspaces: runtime.workspaces ?? runtime.workspaceProvider }
|
|
404
|
-
: {}),
|
|
405
|
-
...((runtime.runSandbox ?? runtime.runSandboxProvider)
|
|
406
|
-
? { runSandbox: runtime.runSandbox ?? runtime.runSandboxProvider }
|
|
407
|
-
: {}),
|
|
408
|
-
...(runtime.sandboxProvider
|
|
409
|
-
? { sandboxProvider: runtime.sandboxProvider }
|
|
410
|
-
: {}),
|
|
411
|
-
...(runtime.policies
|
|
412
|
-
? { policies: executionPoliciesSchema.parse(runtime.policies) }
|
|
413
|
-
: {}),
|
|
414
|
-
...(runtime.enforcedPolicies
|
|
415
|
-
? {
|
|
416
|
-
enforcedPolicies: executionPoliciesSchema.parse(runtime.enforcedPolicies),
|
|
417
|
-
}
|
|
418
|
-
: {}),
|
|
419
|
-
...(runtime.summarizer ? { summarizer: runtime.summarizer } : {}),
|
|
420
|
-
...((runtime.eventSinks?.length ?? 0) > 0 || runtime.eventSink
|
|
421
|
-
? {
|
|
422
|
-
eventSinks: [
|
|
423
|
-
...(runtime.eventSinks ?? []),
|
|
424
|
-
...(runtime.eventSink ? [runtime.eventSink] : []),
|
|
425
|
-
],
|
|
426
|
-
}
|
|
427
|
-
: {}),
|
|
428
|
-
...((runtime.stepExecutors?.length ?? 0) > 0 ||
|
|
429
|
-
(runtime.executors?.length ?? 0) > 0
|
|
430
|
-
? { stepExecutors: runtime.stepExecutors ?? runtime.executors }
|
|
431
|
-
: {}),
|
|
432
|
-
});
|
|
433
|
-
const defaultStepExecutors = (allowUnsafeWebhooks) => [
|
|
434
|
-
new PromptStepExecutor(),
|
|
435
|
-
new LoopStepExecutor(),
|
|
436
|
-
...(allowUnsafeWebhooks
|
|
437
|
-
? [new WebhookStepExecutor({ allowUnsafeDestinations: true })]
|
|
438
|
-
: []),
|
|
439
|
-
new ApprovalStepExecutor(),
|
|
440
|
-
new CodeStepExecutor(),
|
|
441
|
-
new SubRunStepExecutor(),
|
|
442
|
-
];
|
|
443
|
-
const resolveStepExecutors = (runtime, options = {}) => {
|
|
444
|
-
const byType = new Map(defaultStepExecutors(options.allowUnsafeWebhooks === true).map((executor) => [executor.type, executor]));
|
|
445
|
-
for (const executor of runtime.stepExecutors ?? [])
|
|
446
|
-
byType.set(executor.type, executor);
|
|
447
|
-
return [...byType.values()];
|
|
448
|
-
};
|
|
449
|
-
const loadRuntime = async (modulePath, context) => {
|
|
450
|
-
if (!modulePath)
|
|
451
|
-
return {};
|
|
452
|
-
const absolutePath = path.resolve(modulePath);
|
|
453
|
-
let imported;
|
|
454
|
-
try {
|
|
455
|
-
imported = (await import(pathToFileURL(absolutePath).href));
|
|
456
|
-
}
|
|
457
|
-
catch (error) {
|
|
458
|
-
throw new Error(`Could not load runtime module ${absolutePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
459
|
-
}
|
|
460
|
-
const staticRuntime = imported.default ?? imported.runtime ?? imported;
|
|
461
|
-
const composedRuntime = imported.createRuntime
|
|
462
|
-
? await imported.createRuntime(context)
|
|
463
|
-
: normalizeRuntime(staticRuntime);
|
|
464
|
-
if (!composedRuntime || typeof composedRuntime !== "object") {
|
|
465
|
-
throw new Error(`Runtime module ${absolutePath} did not export a runtime object.`);
|
|
466
|
-
}
|
|
467
|
-
const runtime = !composedRuntime.runStore && imported.createRunStore
|
|
468
|
-
? { ...composedRuntime, runStore: await imported.createRunStore(context) }
|
|
469
|
-
: composedRuntime;
|
|
470
|
-
return validateRuntime(runtime);
|
|
471
|
-
};
|
|
472
|
-
const loadRuntimeStore = async (modulePath, context) => {
|
|
473
|
-
if (!modulePath)
|
|
474
|
-
return undefined;
|
|
475
|
-
const absolutePath = path.resolve(modulePath);
|
|
476
|
-
let imported;
|
|
477
|
-
try {
|
|
478
|
-
imported = (await import(pathToFileURL(absolutePath).href));
|
|
479
|
-
}
|
|
480
|
-
catch (error) {
|
|
481
|
-
throw new Error(`Could not load runtime module ${absolutePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
482
|
-
}
|
|
483
|
-
const staticRuntime = imported.default ?? imported.runtime ?? imported;
|
|
484
|
-
const store = imported.createRunStore
|
|
485
|
-
? await imported.createRunStore(context)
|
|
486
|
-
: (staticRuntime.runStore ?? staticRuntime.store);
|
|
487
|
-
if (store &&
|
|
488
|
-
(!adapterMethod(store, "createRun") ||
|
|
489
|
-
!adapterMethod(store, "loadRun") ||
|
|
490
|
-
!adapterMethod(store, "saveCheckpoint"))) {
|
|
491
|
-
throw new Error("Runtime runStore must implement the RunStore lifecycle methods.");
|
|
492
|
-
}
|
|
493
|
-
return store;
|
|
494
|
-
};
|
|
495
|
-
const defaultConfigNames = [
|
|
496
|
-
"agent-runtime.config.yaml",
|
|
497
|
-
"agent-runtime.config.yml",
|
|
498
|
-
"agent-runtime.config.json",
|
|
499
|
-
];
|
|
500
|
-
const resolveConfig = async (requested, searchDirectory = process.cwd()) => {
|
|
501
|
-
if (requested)
|
|
502
|
-
return loadAgentRuntimeConfig(requested);
|
|
503
|
-
for (const candidate of defaultConfigNames) {
|
|
504
|
-
const absolute = path.resolve(searchDirectory, candidate);
|
|
505
|
-
try {
|
|
506
|
-
await access(absolute);
|
|
507
|
-
return await loadAgentRuntimeConfig(absolute);
|
|
508
|
-
}
|
|
509
|
-
catch (error) {
|
|
510
|
-
if (error.code !== "ENOENT")
|
|
511
|
-
throw error;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return emptyAgentRuntimeConfig();
|
|
515
|
-
};
|
|
516
|
-
/** Host-supplied workspace and sandbox adapters take precedence over configuration. */
|
|
517
|
-
const workspaceCompositionOptions = (...runtimes) => {
|
|
518
|
-
const options = {};
|
|
519
|
-
for (const runtime of runtimes) {
|
|
520
|
-
if (runtime.workspaces && !options.provider)
|
|
521
|
-
options.provider = runtime.workspaces;
|
|
522
|
-
if (runtime.runSandbox && !options.runSandbox)
|
|
523
|
-
options.runSandbox = runtime.runSandbox;
|
|
524
|
-
if (runtime.sandboxProvider && !options.sandboxProvider)
|
|
525
|
-
options.sandboxProvider = runtime.sandboxProvider;
|
|
526
|
-
}
|
|
527
|
-
return options;
|
|
528
|
-
};
|
|
529
|
-
const mergeRuntimes = (configured, moduleRuntime) => validateRuntime({
|
|
530
|
-
...configured,
|
|
531
|
-
...moduleRuntime,
|
|
532
|
-
...(configured.messages || moduleRuntime.messages
|
|
533
|
-
? { messages: { ...configured.messages, ...moduleRuntime.messages } }
|
|
534
|
-
: {}),
|
|
535
|
-
...((configured.eventSinks?.length ?? 0) > 0 ||
|
|
536
|
-
(moduleRuntime.eventSinks?.length ?? 0) > 0
|
|
537
|
-
? {
|
|
538
|
-
eventSinks: [
|
|
539
|
-
...(configured.eventSinks ?? []),
|
|
540
|
-
...(moduleRuntime.eventSinks ?? []),
|
|
541
|
-
],
|
|
542
|
-
}
|
|
543
|
-
: {}),
|
|
544
|
-
});
|
|
545
329
|
const sensitiveKey = /(?:authorization|cookie|credential|password|secret|token|api[-_]?key)/iu;
|
|
546
330
|
const redactValue = (value, key = "") => {
|
|
547
331
|
if (sensitiveKey.test(key))
|
|
@@ -674,11 +458,6 @@ class CliStreamingEventSink {
|
|
|
674
458
|
this.#io.stderr(`${label}\n`);
|
|
675
459
|
}
|
|
676
460
|
}
|
|
677
|
-
/** The run's message options with the prompt package's history compactor. */
|
|
678
|
-
const withHistoryCompactor = (options) => ({
|
|
679
|
-
compactor: new PromptMessageHistoryCompactor(),
|
|
680
|
-
...options,
|
|
681
|
-
});
|
|
682
461
|
/**
|
|
683
462
|
* Read `--messages`: a JSON or YAML array of messages, or `{ messages,
|
|
684
463
|
* signature }` as written by `--messages-out`.
|
|
@@ -770,7 +549,7 @@ const execute = async (command, args, io, signal) => {
|
|
|
770
549
|
const maxTotalTokens = positiveSafeIntegerOption(parsed, "max-total-tokens");
|
|
771
550
|
const runtimeModulePath = parsed.options.get("runtime-module");
|
|
772
551
|
const runtimeStore = command === "resume"
|
|
773
|
-
? await
|
|
552
|
+
? await loadHostRunStore(runtimeModulePath, {
|
|
774
553
|
runId: target,
|
|
775
554
|
storeDirectory,
|
|
776
555
|
storeDriver: resolvedStore.driver,
|
|
@@ -821,21 +600,13 @@ const execute = async (command, args, io, signal) => {
|
|
|
821
600
|
...(eventFile ? { eventFile } : {}),
|
|
822
601
|
...(artifactDirectory ? { artifactDirectory } : {}),
|
|
823
602
|
};
|
|
824
|
-
const loadedModuleRuntime = await
|
|
603
|
+
const loadedModuleRuntime = await loadHostRuntime(runtimeModulePath, context);
|
|
825
604
|
shutdown = loadedModuleRuntime.shutdown;
|
|
826
605
|
const moduleRuntime = runtimeStore
|
|
827
|
-
?
|
|
606
|
+
? validateHostRuntime({ ...loadedModuleRuntime, runStore: runtimeStore })
|
|
828
607
|
: loadedModuleRuntime;
|
|
829
|
-
const config = await
|
|
830
|
-
const
|
|
831
|
-
model: !moduleRuntime.model,
|
|
832
|
-
tools: !moduleRuntime.tools,
|
|
833
|
-
...(moduleRuntime.connectionCredentials
|
|
834
|
-
? { connectionCredentials: moduleRuntime.connectionCredentials }
|
|
835
|
-
: {}),
|
|
836
|
-
workspaceOptions: workspaceCompositionOptions(moduleRuntime),
|
|
837
|
-
});
|
|
838
|
-
const runtime = mergeRuntimes(configuredRuntime, moduleRuntime);
|
|
608
|
+
const config = await resolveAgentRuntimeConfig(parsed.options.get("config"), configSearchDirectory);
|
|
609
|
+
const runtime = composeHostRuntime(manifest, config, [moduleRuntime]);
|
|
839
610
|
const jsonlSink = eventFile ? new JsonlEventSink(eventFile) : undefined;
|
|
840
611
|
const requestedFormat = parsed.options.get("format") ??
|
|
841
612
|
(parsed.options.has("stream") ? "pretty" : "json");
|
|
@@ -847,7 +618,9 @@ const execute = async (command, args, io, signal) => {
|
|
|
847
618
|
? undefined
|
|
848
619
|
: new CliStreamingEventSink(io, outputFormat, parsed.options.has("show-reasoning"));
|
|
849
620
|
const warnedSinks = new Set();
|
|
850
|
-
const runner = new AgentRuntime({
|
|
621
|
+
const runner = new AgentRuntime(hostRuntimeDependencies(runtime, {
|
|
622
|
+
// The operator runs manifests they chose on their own machine.
|
|
623
|
+
trust: "local-operator",
|
|
851
624
|
onEventSinkError(_error, _event, sink) {
|
|
852
625
|
if (warnedSinks.has(sink))
|
|
853
626
|
return;
|
|
@@ -855,35 +628,16 @@ const execute = async (command, args, io, signal) => {
|
|
|
855
628
|
io.stderr(`Warning: event delivery failed for ${sink instanceof SafeLocalEventSink ? `local log ${eventFile}` : sink.constructor.name}. Check permissions and available disk space. Execution continues.\n`);
|
|
856
629
|
},
|
|
857
630
|
runStore: runtime.runStore ?? store,
|
|
858
|
-
|
|
859
|
-
stepExecutors: resolveStepExecutors(runtime, {
|
|
860
|
-
allowUnsafeWebhooks: true,
|
|
861
|
-
}),
|
|
862
|
-
conditionEvaluator: new JexlConditionEvaluator(),
|
|
631
|
+
agentManifestSource,
|
|
863
632
|
eventSinks: [
|
|
864
633
|
...(jsonlSink ? [new SafeLocalEventSink(jsonlSink)] : []),
|
|
865
634
|
...(streamingSink ? [streamingSink] : []),
|
|
866
|
-
...(runtime.eventSinks ?? []),
|
|
867
635
|
],
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
...(runtime.workspaces ? { workspaces: runtime.workspaces } : {}),
|
|
874
|
-
...(runtime.runSandbox ? { runSandbox: runtime.runSandbox } : {}),
|
|
875
|
-
...(runtime.policies ? { policies: runtime.policies } : {}),
|
|
876
|
-
...(runtime.enforcedPolicies
|
|
877
|
-
? { enforcedPolicies: runtime.enforcedPolicies }
|
|
878
|
-
: {}),
|
|
879
|
-
...(runtime.summarizer ? { summarizer: runtime.summarizer } : {}),
|
|
880
|
-
messages: withHistoryCompactor(runtime.messages),
|
|
881
|
-
...(runtime.artifactStore
|
|
882
|
-
? { artifacts: runtime.artifactStore }
|
|
883
|
-
: artifactDirectory
|
|
884
|
-
? { artifacts: new FileArtifactStore(artifactDirectory) }
|
|
885
|
-
: {}),
|
|
886
|
-
});
|
|
636
|
+
artifacts: runtime.artifactStore ??
|
|
637
|
+
(artifactDirectory
|
|
638
|
+
? new FileArtifactStore(artifactDirectory)
|
|
639
|
+
: undefined),
|
|
640
|
+
}));
|
|
887
641
|
try {
|
|
888
642
|
const result = await runner.run(command === "run-manifest" && agentRunManifest
|
|
889
643
|
? {
|
|
@@ -1027,8 +781,8 @@ export const executeWorkerInvocation = async (invocation, options) => {
|
|
|
1027
781
|
throw new Error("Worker request runtimeReference requires a host resolveRuntimeReference callback.");
|
|
1028
782
|
})()
|
|
1029
783
|
: undefined;
|
|
1030
|
-
const moduleRuntime = await
|
|
1031
|
-
const hostRuntime =
|
|
784
|
+
const moduleRuntime = await loadHostRuntime(runtimeReference, context);
|
|
785
|
+
const hostRuntime = validateHostRuntime(options.runtime ?? {});
|
|
1032
786
|
let requestSuppliedConfiguration = false;
|
|
1033
787
|
const config = options.configFile
|
|
1034
788
|
? await loadAgentRuntimeConfig(options.configFile)
|
|
@@ -1045,40 +799,22 @@ export const executeWorkerInvocation = async (invocation, options) => {
|
|
|
1045
799
|
: (() => {
|
|
1046
800
|
throw new Error("Worker request configReference requires a host resolveConfigReference callback.");
|
|
1047
801
|
})()
|
|
1048
|
-
: await
|
|
802
|
+
: await resolveAgentRuntimeConfig(undefined, process.cwd());
|
|
1049
803
|
if (requestSuppliedConfiguration) {
|
|
1050
804
|
assertSafeInlineWorkerConfiguration(config);
|
|
1051
805
|
}
|
|
1052
|
-
const
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
tools: !moduleRuntime.tools && !hostRuntime.tools,
|
|
1059
|
-
workspaceOptions: {
|
|
1060
|
-
...options.workspaceOptions,
|
|
1061
|
-
...workspaceCompositionOptions(hostRuntime, moduleRuntime),
|
|
1062
|
-
},
|
|
806
|
+
const runtime = composeHostRuntime(manifest, config, [moduleRuntime, hostRuntime], {
|
|
807
|
+
...(requestSuppliedConfiguration
|
|
808
|
+
? { environment: options.environment ?? {} }
|
|
809
|
+
: options.environment
|
|
810
|
+
? { environment: options.environment }
|
|
811
|
+
: {}),
|
|
1063
812
|
...(options.modelPolicy ? { modelPolicy: options.modelPolicy } : {}),
|
|
1064
|
-
...(options.toolOptions
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
? {
|
|
1068
|
-
toolOptions: {
|
|
1069
|
-
...options.toolOptions,
|
|
1070
|
-
...((hostRuntime.connectionCredentials ??
|
|
1071
|
-
moduleRuntime.connectionCredentials)
|
|
1072
|
-
? {
|
|
1073
|
-
credentialProvider: hostRuntime.connectionCredentials ??
|
|
1074
|
-
moduleRuntime.connectionCredentials,
|
|
1075
|
-
}
|
|
1076
|
-
: {}),
|
|
1077
|
-
},
|
|
1078
|
-
}
|
|
813
|
+
...(options.toolOptions ? { toolOptions: options.toolOptions } : {}),
|
|
814
|
+
...(options.workspaceOptions
|
|
815
|
+
? { workspaceOptions: options.workspaceOptions }
|
|
1079
816
|
: {}),
|
|
1080
817
|
});
|
|
1081
|
-
const runtime = mergeRuntimes(mergeRuntimes(configuredRuntime, moduleRuntime), hostRuntime);
|
|
1082
818
|
const store = runtime.runStore ??
|
|
1083
819
|
(storeDriver === "sqlite"
|
|
1084
820
|
? new (await import("@clearideas/agent-runtime-store-sqlite")).SqliteRunStore(storeLocation)
|
|
@@ -1120,37 +856,16 @@ export const executeWorkerInvocation = async (invocation, options) => {
|
|
|
1120
856
|
await store.saveCheckpoint(importedCheckpoint);
|
|
1121
857
|
}
|
|
1122
858
|
}
|
|
1123
|
-
const runner = new AgentRuntime({
|
|
859
|
+
const runner = new AgentRuntime(hostRuntimeDependencies(runtime, {
|
|
860
|
+
// Webhook execution is host-supplied in worker mode so destination
|
|
861
|
+
// policy cannot be bypassed by a remote manifest.
|
|
862
|
+
trust: "untrusted-request",
|
|
1124
863
|
runStore: store,
|
|
1125
|
-
|
|
1126
|
-
// cannot be bypassed by a remote manifest.
|
|
1127
|
-
stepExecutors: resolveStepExecutors(runtime),
|
|
1128
|
-
conditionEvaluator: new JexlConditionEvaluator(),
|
|
1129
|
-
eventSinks: [
|
|
1130
|
-
new PortableWorkerEventSink(options.onMessage),
|
|
1131
|
-
...(runtime.eventSinks ?? []),
|
|
1132
|
-
],
|
|
1133
|
-
...(runtime.model ? { model: runtime.model } : {}),
|
|
1134
|
-
...(runtime.tools ? { tools: runtime.tools } : {}),
|
|
1135
|
-
...(runtime.approvals ? { approvals: runtime.approvals } : {}),
|
|
1136
|
-
...(runtime.sandbox ? { sandbox: runtime.sandbox } : {}),
|
|
1137
|
-
...(runtime.subRuns ? { subRuns: runtime.subRuns } : {}),
|
|
1138
|
-
...(runtime.workspaces ? { workspaces: runtime.workspaces } : {}),
|
|
1139
|
-
...(runtime.runSandbox ? { runSandbox: runtime.runSandbox } : {}),
|
|
1140
|
-
...(runtime.policies ? { policies: runtime.policies } : {}),
|
|
1141
|
-
...(runtime.enforcedPolicies
|
|
1142
|
-
? { enforcedPolicies: runtime.enforcedPolicies }
|
|
1143
|
-
: {}),
|
|
1144
|
-
...(runtime.summarizer ? { summarizer: runtime.summarizer } : {}),
|
|
1145
|
-
messages: withHistoryCompactor(runtime.messages),
|
|
864
|
+
eventSinks: [new PortableWorkerEventSink(options.onMessage)],
|
|
1146
865
|
artifacts,
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
...(options.eventSinkFailurePolicy
|
|
1151
|
-
? { eventSinkFailurePolicy: options.eventSinkFailurePolicy }
|
|
1152
|
-
: {}),
|
|
1153
|
-
});
|
|
866
|
+
maxParallelSteps: options.maxParallelSteps,
|
|
867
|
+
eventSinkFailurePolicy: options.eventSinkFailurePolicy,
|
|
868
|
+
}));
|
|
1154
869
|
return await runner.run({
|
|
1155
870
|
manifest,
|
|
1156
871
|
...(request.runId ? { runId: request.runId } : {}),
|
|
@@ -1242,6 +957,139 @@ const worker = async (args, io, signal) => {
|
|
|
1242
957
|
return false;
|
|
1243
958
|
}
|
|
1244
959
|
};
|
|
960
|
+
const serveOptionNames = new Set([
|
|
961
|
+
"server-config",
|
|
962
|
+
"no-server-config",
|
|
963
|
+
"served-model-name",
|
|
964
|
+
"config",
|
|
965
|
+
"runtime-config",
|
|
966
|
+
"runtime-module",
|
|
967
|
+
"host",
|
|
968
|
+
"port",
|
|
969
|
+
"api-key-env",
|
|
970
|
+
"allow-unauthenticated",
|
|
971
|
+
"input",
|
|
972
|
+
"output",
|
|
973
|
+
"stream-mode",
|
|
974
|
+
"progress",
|
|
975
|
+
"store-driver",
|
|
976
|
+
"store",
|
|
977
|
+
"ledger",
|
|
978
|
+
"on-unrecognized",
|
|
979
|
+
"client-tools",
|
|
980
|
+
"max-concurrent-runs",
|
|
981
|
+
"request-timeout",
|
|
982
|
+
"warmup",
|
|
983
|
+
"check",
|
|
984
|
+
]);
|
|
985
|
+
const serveFlags = new Set([
|
|
986
|
+
"no-server-config",
|
|
987
|
+
"allow-unauthenticated",
|
|
988
|
+
"warmup",
|
|
989
|
+
"check",
|
|
990
|
+
]);
|
|
991
|
+
const INPUT_SOURCES = new Set([
|
|
992
|
+
"last-user",
|
|
993
|
+
"transcript",
|
|
994
|
+
"system",
|
|
995
|
+
"json",
|
|
996
|
+
"client",
|
|
997
|
+
]);
|
|
998
|
+
const oneOf = (parsed, name, values) => {
|
|
999
|
+
const value = parsed.options.get(name);
|
|
1000
|
+
if (value === undefined)
|
|
1001
|
+
return undefined;
|
|
1002
|
+
if (!values.includes(value))
|
|
1003
|
+
throw new Error(`--${name} must be one of ${values.join(", ")}.`);
|
|
1004
|
+
return value;
|
|
1005
|
+
};
|
|
1006
|
+
/** Parse `agent-runtime serve` arguments into server options. */
|
|
1007
|
+
export const parseServeArguments = (args) => {
|
|
1008
|
+
const parsed = parseOptions(args, serveOptionNames, serveFlags, new Set(["input"]));
|
|
1009
|
+
if (parsed.positional.length > 1)
|
|
1010
|
+
throw new Error("Serve one manifest, or use --server-config for several.");
|
|
1011
|
+
if (parsed.options.has("config") && parsed.options.has("runtime-config"))
|
|
1012
|
+
throw new Error("--runtime-config is an alias of --config; use one.");
|
|
1013
|
+
const manifest = parsed.positional[0];
|
|
1014
|
+
const input = {};
|
|
1015
|
+
for (const entry of parsed.repeated.get("input") ?? []) {
|
|
1016
|
+
const separator = entry.indexOf("=");
|
|
1017
|
+
const variable = entry.slice(0, separator);
|
|
1018
|
+
const source = entry.slice(separator + 1);
|
|
1019
|
+
if (separator <= 0 || !INPUT_SOURCES.has(source)) {
|
|
1020
|
+
throw new Error(`--input expects <variable>=<source> with source last-user, transcript, system, json, or client; got ${JSON.stringify(entry)}.`);
|
|
1021
|
+
}
|
|
1022
|
+
if (input[variable])
|
|
1023
|
+
throw new Error(`--input maps ${variable} twice.`);
|
|
1024
|
+
input[variable] = source;
|
|
1025
|
+
}
|
|
1026
|
+
const port = parsed.options.get("port");
|
|
1027
|
+
const portNumber = port === undefined ? undefined : Number(port);
|
|
1028
|
+
if (portNumber !== undefined &&
|
|
1029
|
+
(!Number.isInteger(portNumber) || portNumber < 0 || portNumber > 65_535))
|
|
1030
|
+
throw new Error("--port must be an integer from 0 to 65535.");
|
|
1031
|
+
const runtimeConfig = parsed.options.get("config") ?? parsed.options.get("runtime-config");
|
|
1032
|
+
const streamMode = oneOf(parsed, "stream-mode", [
|
|
1033
|
+
"auto",
|
|
1034
|
+
"live",
|
|
1035
|
+
"committed",
|
|
1036
|
+
]);
|
|
1037
|
+
const progress = oneOf(parsed, "progress", ["none", "status"]);
|
|
1038
|
+
const storeDriver = oneOf(parsed, "store-driver", [
|
|
1039
|
+
"memory",
|
|
1040
|
+
"sqlite",
|
|
1041
|
+
]);
|
|
1042
|
+
const onUnrecognized = oneOf(parsed, "on-unrecognized", [
|
|
1043
|
+
"unsigned",
|
|
1044
|
+
"reject",
|
|
1045
|
+
"restart",
|
|
1046
|
+
]);
|
|
1047
|
+
const clientTools = oneOf(parsed, "client-tools", [
|
|
1048
|
+
"ignore",
|
|
1049
|
+
"reject",
|
|
1050
|
+
]);
|
|
1051
|
+
const maxConcurrentRuns = positiveSafeIntegerOption(parsed, "max-concurrent-runs");
|
|
1052
|
+
const requestTimeoutMs = positiveSafeIntegerOption(parsed, "request-timeout");
|
|
1053
|
+
if (storeDriver === "sqlite" && !parsed.options.has("store"))
|
|
1054
|
+
throw new Error("--store-driver sqlite requires --store <path>.");
|
|
1055
|
+
const value = (name) => parsed.options.get(name);
|
|
1056
|
+
return {
|
|
1057
|
+
...(manifest ? { manifest } : {}),
|
|
1058
|
+
...(value("server-config")
|
|
1059
|
+
? { serverConfig: value("server-config") }
|
|
1060
|
+
: {}),
|
|
1061
|
+
...(parsed.options.has("no-server-config") ? { noServerConfig: true } : {}),
|
|
1062
|
+
...(value("served-model-name")
|
|
1063
|
+
? { servedModelName: value("served-model-name") }
|
|
1064
|
+
: {}),
|
|
1065
|
+
...(runtimeConfig ? { runtimeConfig } : {}),
|
|
1066
|
+
...(value("runtime-module")
|
|
1067
|
+
? { runtimeModule: value("runtime-module") }
|
|
1068
|
+
: {}),
|
|
1069
|
+
...(value("host") ? { host: value("host") } : {}),
|
|
1070
|
+
...(portNumber !== undefined ? { port: portNumber } : {}),
|
|
1071
|
+
...(value("api-key-env") ? { apiKeyEnv: value("api-key-env") } : {}),
|
|
1072
|
+
...(parsed.options.has("allow-unauthenticated")
|
|
1073
|
+
? { allowUnauthenticated: true }
|
|
1074
|
+
: {}),
|
|
1075
|
+
...(Object.keys(input).length > 0 ? { input } : {}),
|
|
1076
|
+
...(value("output") ? { output: value("output") } : {}),
|
|
1077
|
+
...(streamMode ? { streamMode } : {}),
|
|
1078
|
+
...(progress ? { progress } : {}),
|
|
1079
|
+
...(storeDriver ? { storeDriver } : {}),
|
|
1080
|
+
...(value("store") ? { store: value("store") } : {}),
|
|
1081
|
+
...(value("ledger") ? { ledger: value("ledger") } : {}),
|
|
1082
|
+
...(onUnrecognized ? { onUnrecognized } : {}),
|
|
1083
|
+
...(clientTools ? { clientTools } : {}),
|
|
1084
|
+
...(maxConcurrentRuns ? { maxConcurrentRuns } : {}),
|
|
1085
|
+
...(requestTimeoutMs ? { requestTimeoutMs } : {}),
|
|
1086
|
+
...(parsed.options.has("warmup") ? { warmup: true } : {}),
|
|
1087
|
+
...(parsed.options.has("check") ? { check: true } : {}),
|
|
1088
|
+
};
|
|
1089
|
+
};
|
|
1090
|
+
const serve = async (args, io, signal) => {
|
|
1091
|
+
await runServe(parseServeArguments(args), io, signal);
|
|
1092
|
+
};
|
|
1245
1093
|
const examples = async (args, io, signal) => {
|
|
1246
1094
|
const [subcommand, name, ...remaining] = args;
|
|
1247
1095
|
if (subcommand === "list") {
|
|
@@ -1296,6 +1144,8 @@ export const runCli = async (args, io = defaultIo, options = {}) => {
|
|
|
1296
1144
|
}
|
|
1297
1145
|
else if (command === "worker")
|
|
1298
1146
|
return (await worker(commandArgs, io, options.signal)) ? 0 : 1;
|
|
1147
|
+
else if (command === "serve")
|
|
1148
|
+
await serve(commandArgs, io, options.signal);
|
|
1299
1149
|
else {
|
|
1300
1150
|
io.stderr(`Unknown command: ${command}\n\n${usage}`);
|
|
1301
1151
|
return 2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearideas/agent-runtime-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Standalone CLI for validating, running, resuming, and inspecting declarative agents.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Clear Ideas Incorporated",
|
|
@@ -40,17 +40,13 @@
|
|
|
40
40
|
"postpack": "node ../../scripts/cleanup-package-license.mjs"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@clearideas/agent-runtime-
|
|
44
|
-
"@clearideas/agent-runtime-
|
|
45
|
-
"@clearideas/agent-runtime-
|
|
46
|
-
"@clearideas/agent-runtime-
|
|
47
|
-
"@clearideas/agent-runtime-
|
|
48
|
-
"@clearideas/agent-runtime-
|
|
49
|
-
"@clearideas/agent-runtime-
|
|
50
|
-
"@clearideas/agent-runtime-step-prompt": "0.8.0",
|
|
51
|
-
"@clearideas/agent-runtime-step-standard": "0.8.0",
|
|
52
|
-
"@clearideas/agent-runtime-store-local": "0.8.0",
|
|
53
|
-
"@clearideas/agent-runtime-store-sqlite": "0.8.0",
|
|
43
|
+
"@clearideas/agent-runtime-config": "0.9.0",
|
|
44
|
+
"@clearideas/agent-runtime-contracts": "0.9.0",
|
|
45
|
+
"@clearideas/agent-runtime-core": "0.9.0",
|
|
46
|
+
"@clearideas/agent-runtime-execution": "0.9.0",
|
|
47
|
+
"@clearideas/agent-runtime-server": "0.9.0",
|
|
48
|
+
"@clearideas/agent-runtime-store-local": "0.9.0",
|
|
49
|
+
"@clearideas/agent-runtime-store-sqlite": "0.9.0",
|
|
54
50
|
"yaml": "^2.9.1"
|
|
55
51
|
},
|
|
56
52
|
"devDependencies": {
|