@clearideas/agent-runtime-server 0.0.0-stage → 0.10.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/LICENSE +201 -0
- package/NOTICE +8 -0
- package/README.md +44 -2
- package/dist/admission.d.ts +19 -0
- package/dist/admission.js +106 -0
- package/dist/answer.d.ts +51 -0
- package/dist/answer.js +100 -0
- package/dist/auth.d.ts +49 -0
- package/dist/auth.js +89 -0
- package/dist/config.d.ts +350 -0
- package/dist/config.js +543 -0
- package/dist/convert.d.ts +46 -0
- package/dist/convert.js +180 -0
- package/dist/errors.d.ts +36 -0
- package/dist/errors.js +100 -0
- package/dist/host.d.ts +150 -0
- package/dist/host.js +359 -0
- package/dist/http.d.ts +29 -0
- package/dist/http.js +243 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/kv.d.ts +51 -0
- package/dist/kv.js +144 -0
- package/dist/ledger.d.ts +59 -0
- package/dist/ledger.js +94 -0
- package/dist/media.d.ts +37 -0
- package/dist/media.js +136 -0
- package/dist/openai.d.ts +180 -0
- package/dist/openai.js +172 -0
- package/dist/serve.d.ts +61 -0
- package/dist/serve.js +201 -0
- package/dist/service.d.ts +85 -0
- package/dist/service.js +1147 -0
- package/dist/stream.d.ts +62 -0
- package/dist/stream.js +255 -0
- package/package.json +71 -4
package/dist/convert.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { invalidRequest } from "./errors.js";
|
|
2
|
+
const textOf = (content, role, index) => {
|
|
3
|
+
if (content == null)
|
|
4
|
+
return "";
|
|
5
|
+
if (typeof content === "string")
|
|
6
|
+
return content;
|
|
7
|
+
return content
|
|
8
|
+
.map((part) => {
|
|
9
|
+
if (part.type === "text" && "text" in part)
|
|
10
|
+
return String(part.text);
|
|
11
|
+
if (part.type === "refusal" && "refusal" in part)
|
|
12
|
+
return String(part.refusal);
|
|
13
|
+
throw invalidRequest(`messages[${index}]: ${role} messages may contain only text.`, "messages");
|
|
14
|
+
})
|
|
15
|
+
.join("\n");
|
|
16
|
+
};
|
|
17
|
+
const convertPart = async (part, index, options) => {
|
|
18
|
+
if (part.type === "text" && "text" in part)
|
|
19
|
+
return { type: "text", text: String(part.text) };
|
|
20
|
+
if (part.type === "refusal" && "refusal" in part)
|
|
21
|
+
return { type: "text", text: String(part.refusal) };
|
|
22
|
+
if (part.type === "image_url" || part.type === "file") {
|
|
23
|
+
if (!options.allowMedia)
|
|
24
|
+
throw invalidRequest(`messages[${index}]: this model accepts text only.`, "messages");
|
|
25
|
+
if (part.type === "image_url" && "image_url" in part) {
|
|
26
|
+
const imageUrl = part.image_url;
|
|
27
|
+
return options.media.part({
|
|
28
|
+
kind: "image",
|
|
29
|
+
source: imageUrl.url,
|
|
30
|
+
scope: options.scope,
|
|
31
|
+
artifacts: options.artifacts,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const file = part.file;
|
|
35
|
+
if (file?.file_id || !file?.file_data) {
|
|
36
|
+
throw invalidRequest(`messages[${index}]: file references (file_id) are not supported; send file_data.`, "messages");
|
|
37
|
+
}
|
|
38
|
+
return options.media.part({
|
|
39
|
+
kind: "file",
|
|
40
|
+
source: file.file_data,
|
|
41
|
+
...(file.filename ? { name: file.filename } : {}),
|
|
42
|
+
scope: options.scope,
|
|
43
|
+
artifacts: options.artifacts,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
throw invalidRequest(`messages[${index}]: content parts of type ${JSON.stringify(part.type)} are not supported.`, "messages");
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Convert chat messages. Client system and developer messages become
|
|
50
|
+
* `instructions`; tool messages and tool calls are dropped or refused, per
|
|
51
|
+
* the `clientTools` policy; audio and file ids are refused; an assistant
|
|
52
|
+
* message with no text is omitted. The request must end with a user message.
|
|
53
|
+
*/
|
|
54
|
+
export const convertChatMessages = async (messages, options) => {
|
|
55
|
+
const instructions = [];
|
|
56
|
+
const converted = [];
|
|
57
|
+
for (const [index, message] of messages.entries()) {
|
|
58
|
+
switch (message.role) {
|
|
59
|
+
case "system":
|
|
60
|
+
case "developer":
|
|
61
|
+
instructions.push(textOf(message.content, message.role, index));
|
|
62
|
+
break;
|
|
63
|
+
case "tool":
|
|
64
|
+
case "function":
|
|
65
|
+
if (options.clientTools === "ignore")
|
|
66
|
+
break;
|
|
67
|
+
throw invalidRequest(`messages[${index}]: ${message.role} messages are not supported; the served agent's tools are configured by the host.`, "messages");
|
|
68
|
+
case "assistant": {
|
|
69
|
+
if (options.clientTools === "reject" &&
|
|
70
|
+
((message.tool_calls?.length ?? 0) > 0 || message.function_call))
|
|
71
|
+
throw invalidRequest(`messages[${index}]: assistant tool calls are not supported.`, "messages");
|
|
72
|
+
const text = textOf(message.content, message.role, index);
|
|
73
|
+
const refusal = message.refusal ?? "";
|
|
74
|
+
const reply = text || refusal;
|
|
75
|
+
if (reply) {
|
|
76
|
+
converted.push({
|
|
77
|
+
role: "assistant",
|
|
78
|
+
content: [{ type: "text", text: reply }],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "user": {
|
|
84
|
+
const content = typeof message.content === "string" || message.content == null
|
|
85
|
+
? [{ type: "text", text: message.content ?? "" }]
|
|
86
|
+
: await Promise.all(message.content.map((part) => convertPart(part, index, options)));
|
|
87
|
+
converted.push({
|
|
88
|
+
role: "user",
|
|
89
|
+
content: content.length > 0 ? content : [{ type: "text", text: "" }],
|
|
90
|
+
});
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (converted.at(-1)?.role !== "user") {
|
|
96
|
+
throw invalidRequest("The last message must be a user message.", "messages");
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
instructions: instructions.filter(Boolean).join("\n\n"),
|
|
100
|
+
messages: converted,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
/** Messages up to and including the last assistant message, and the new turn after it. */
|
|
104
|
+
export const splitNewTurn = (messages) => {
|
|
105
|
+
let index = messages.length;
|
|
106
|
+
while (index > 0 && messages[index - 1].role === "user")
|
|
107
|
+
index -= 1;
|
|
108
|
+
return {
|
|
109
|
+
prefix: messages.slice(0, index),
|
|
110
|
+
newTurn: messages.slice(index),
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
const messageText = (message) => message.content
|
|
114
|
+
.map((part) => part.type === "text"
|
|
115
|
+
? part.text
|
|
116
|
+
: part.type === "json"
|
|
117
|
+
? JSON.stringify(part.value)
|
|
118
|
+
: `[${part.type}]`)
|
|
119
|
+
.join("\n");
|
|
120
|
+
/**
|
|
121
|
+
* Variable overrides for operator-mapped inputs. Values are validated by the
|
|
122
|
+
* runtime against the manifest's declarations before a run is created.
|
|
123
|
+
*/
|
|
124
|
+
export const mapInputVariables = (input) => {
|
|
125
|
+
const { chat, request } = input;
|
|
126
|
+
let lastUserIndex = chat.messages.length - 1;
|
|
127
|
+
while (lastUserIndex >= 0 && chat.messages[lastUserIndex].role !== "user")
|
|
128
|
+
lastUserIndex -= 1;
|
|
129
|
+
const lastUser = lastUserIndex >= 0 ? messageText(chat.messages[lastUserIndex]) : "";
|
|
130
|
+
let parsedJson;
|
|
131
|
+
const json = () => {
|
|
132
|
+
if (parsedJson)
|
|
133
|
+
return parsedJson;
|
|
134
|
+
let value;
|
|
135
|
+
try {
|
|
136
|
+
value = JSON.parse(lastUser);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
throw invalidRequest("This model expects the last user message to be a JSON object.", "messages");
|
|
140
|
+
}
|
|
141
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
142
|
+
throw invalidRequest("This model expects the last user message to be a JSON object.", "messages");
|
|
143
|
+
}
|
|
144
|
+
parsedJson = value;
|
|
145
|
+
return parsedJson;
|
|
146
|
+
};
|
|
147
|
+
const overrides = [];
|
|
148
|
+
for (const mapping of input.mappings) {
|
|
149
|
+
let value;
|
|
150
|
+
switch (mapping.source) {
|
|
151
|
+
case "last-user":
|
|
152
|
+
value = lastUser;
|
|
153
|
+
break;
|
|
154
|
+
case "system":
|
|
155
|
+
value = chat.instructions;
|
|
156
|
+
break;
|
|
157
|
+
case "transcript": {
|
|
158
|
+
const earlier = chat.messages.slice(0, Math.max(lastUserIndex, 0));
|
|
159
|
+
const window = mapping.maxMessages != null
|
|
160
|
+
? earlier.slice(-mapping.maxMessages)
|
|
161
|
+
: earlier;
|
|
162
|
+
value = window
|
|
163
|
+
.map((message) => `${message.role}: ${messageText(message)}`)
|
|
164
|
+
.join("\n\n");
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case "json":
|
|
168
|
+
value = json()[mapping.key];
|
|
169
|
+
break;
|
|
170
|
+
case "client": {
|
|
171
|
+
const supplied = request.variables?.[mapping.key];
|
|
172
|
+
value = supplied === undefined ? undefined : supplied;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (value !== undefined)
|
|
177
|
+
overrides.push({ key: mapping.variable, value });
|
|
178
|
+
}
|
|
179
|
+
return overrides;
|
|
180
|
+
};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The OpenAI error body: `{ "error": { message, type, param, code } }`. */
|
|
2
|
+
export interface OpenAiErrorBody {
|
|
3
|
+
error: {
|
|
4
|
+
message: string;
|
|
5
|
+
type: string;
|
|
6
|
+
param: string | null;
|
|
7
|
+
code: string | null;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/** An error with an HTTP status and an OpenAI-shaped body. */
|
|
11
|
+
export declare class ServerError extends Error {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
readonly type: string;
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly param: string | null;
|
|
16
|
+
/** Seconds, sent as Retry-After. */
|
|
17
|
+
readonly retryAfter: number | undefined;
|
|
18
|
+
constructor(status: number, code: string, message: string, options?: {
|
|
19
|
+
type?: string;
|
|
20
|
+
param?: string;
|
|
21
|
+
retryAfter?: number;
|
|
22
|
+
cause?: unknown;
|
|
23
|
+
});
|
|
24
|
+
toBody(): OpenAiErrorBody;
|
|
25
|
+
}
|
|
26
|
+
export declare const invalidRequest: (message: string, param?: string) => ServerError;
|
|
27
|
+
/**
|
|
28
|
+
* Map an error thrown while creating or executing a run. Client input
|
|
29
|
+
* problems the runtime reports before a run exists keep their message, which
|
|
30
|
+
* describes the request. Run failures are redacted to their code unless the
|
|
31
|
+
* operator exposes error messages: they can contain model output, tool data,
|
|
32
|
+
* or configuration detail.
|
|
33
|
+
*/
|
|
34
|
+
export declare const fromRunError: (caught: unknown, options: {
|
|
35
|
+
exposeErrors: boolean;
|
|
36
|
+
}) => ServerError;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { AgentRuntimeError, MessagesValidationError, RUN_BLOCKED_REASON, isRunSuspendedError, } from "@clearideas/agent-runtime-core";
|
|
2
|
+
/** An error with an HTTP status and an OpenAI-shaped body. */
|
|
3
|
+
export class ServerError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
type;
|
|
6
|
+
code;
|
|
7
|
+
param;
|
|
8
|
+
/** Seconds, sent as Retry-After. */
|
|
9
|
+
retryAfter;
|
|
10
|
+
constructor(status, code, message, options = {}) {
|
|
11
|
+
super(message, options.cause !== undefined ? { cause: options.cause } : {});
|
|
12
|
+
this.name = "ServerError";
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.type = options.type ?? defaultType(status);
|
|
16
|
+
this.param = options.param ?? null;
|
|
17
|
+
this.retryAfter = options.retryAfter;
|
|
18
|
+
}
|
|
19
|
+
toBody() {
|
|
20
|
+
return {
|
|
21
|
+
error: {
|
|
22
|
+
message: this.message,
|
|
23
|
+
type: this.type,
|
|
24
|
+
param: this.param,
|
|
25
|
+
code: this.code,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const defaultType = (status) => {
|
|
31
|
+
if (status === 401)
|
|
32
|
+
return "authentication_error";
|
|
33
|
+
if (status === 403)
|
|
34
|
+
return "permission_error";
|
|
35
|
+
if (status === 404)
|
|
36
|
+
return "not_found_error";
|
|
37
|
+
if (status === 429)
|
|
38
|
+
return "rate_limit_error";
|
|
39
|
+
if (status >= 500)
|
|
40
|
+
return "server_error";
|
|
41
|
+
return "invalid_request_error";
|
|
42
|
+
};
|
|
43
|
+
export const invalidRequest = (message, param) => new ServerError(400, "invalid_request_error", message, {
|
|
44
|
+
...(param ? { param } : {}),
|
|
45
|
+
});
|
|
46
|
+
const MESSAGES_ERROR_STATUS = {
|
|
47
|
+
MESSAGES_NOT_ACCEPTED: 400,
|
|
48
|
+
MESSAGES_REQUIRED: 400,
|
|
49
|
+
MESSAGES_INVALID: 400,
|
|
50
|
+
MESSAGES_MEDIA_UNSUPPORTED: 400,
|
|
51
|
+
MESSAGES_ARTIFACT_UNAUTHORIZED: 400,
|
|
52
|
+
MESSAGES_LIMIT_EXCEEDED: 413,
|
|
53
|
+
MESSAGES_SIGNATURE_REQUIRED: 409,
|
|
54
|
+
MESSAGES_SIGNATURE_INVALID: 409,
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Map an error thrown while creating or executing a run. Client input
|
|
58
|
+
* problems the runtime reports before a run exists keep their message, which
|
|
59
|
+
* describes the request. Run failures are redacted to their code unless the
|
|
60
|
+
* operator exposes error messages: they can contain model output, tool data,
|
|
61
|
+
* or configuration detail.
|
|
62
|
+
*/
|
|
63
|
+
export const fromRunError = (caught, options) => {
|
|
64
|
+
// A run blocked by an error keeps that error as its cause; report it as
|
|
65
|
+
// the failure it is. The run itself stays resumable in the store.
|
|
66
|
+
const error = isRunSuspendedError(caught) &&
|
|
67
|
+
caught.reason === RUN_BLOCKED_REASON &&
|
|
68
|
+
caught.cause !== undefined
|
|
69
|
+
? caught.cause
|
|
70
|
+
: caught;
|
|
71
|
+
if (error instanceof ServerError)
|
|
72
|
+
return error;
|
|
73
|
+
if (error instanceof MessagesValidationError) {
|
|
74
|
+
const status = MESSAGES_ERROR_STATUS[error.code] ?? 400;
|
|
75
|
+
if (status === 409) {
|
|
76
|
+
return new ServerError(409, "conversation_not_recognized", error.message, {
|
|
77
|
+
type: "invalid_request_error",
|
|
78
|
+
param: "messages",
|
|
79
|
+
cause: error,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (status === 413) {
|
|
83
|
+
return new ServerError(413, "context_length_exceeded", error.message, {
|
|
84
|
+
type: "invalid_request_error",
|
|
85
|
+
param: "messages",
|
|
86
|
+
cause: error,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return new ServerError(status, error.code, error.message, {
|
|
90
|
+
type: "invalid_request_error",
|
|
91
|
+
param: "messages",
|
|
92
|
+
cause: error,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const code = error instanceof AgentRuntimeError ? error.code : "AGENT_EXECUTION_FAILED";
|
|
96
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
97
|
+
return new ServerError(500, "agent_execution_failed", options.exposeErrors
|
|
98
|
+
? `The agent run failed (${code}): ${detail}`
|
|
99
|
+
: `The agent run failed (${code}).`, { cause: error });
|
|
100
|
+
};
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { type AgentRuntimeConfig, type ConfiguredMcpToolAdapterOptions, type ModelAuthorizationPolicy, type WorkspaceCompositionOptions } from "@clearideas/agent-runtime-config";
|
|
2
|
+
import type { AgentManifest, ExecutionPolicies, RunEvent, RunLimits } from "@clearideas/agent-runtime-contracts";
|
|
3
|
+
import type { AgentManifestSource, AgentRuntimeDependencies, AgentRuntimeMessagesOptions, ApprovalAdapter, ArtifactStore, ConnectionCredentialProvider, ContextSummarizerAdapter, EventSink, ModelAdapter, RunSandboxProvider, RunStore, SandboxAdapter, StepExecutor, SubRunAdapter, ToolAdapter, WorkspaceProvider } from "@clearideas/agent-runtime-core";
|
|
4
|
+
import type { SandboxProvider } from "@clearideas/agent-runtime-sandbox";
|
|
5
|
+
/** Adapters a trusted runtime module may contribute to a host. */
|
|
6
|
+
export interface HostRuntime {
|
|
7
|
+
/** Called once after execution, including failed setup. Own only module-created resources. */
|
|
8
|
+
shutdown?: () => void | Promise<void>;
|
|
9
|
+
runStore?: RunStore;
|
|
10
|
+
artifactStore?: ArtifactStore;
|
|
11
|
+
model?: ModelAdapter;
|
|
12
|
+
tools?: ToolAdapter;
|
|
13
|
+
connectionCredentials?: ConnectionCredentialProvider;
|
|
14
|
+
approvals?: ApprovalAdapter;
|
|
15
|
+
sandbox?: SandboxAdapter;
|
|
16
|
+
subRuns?: SubRunAdapter;
|
|
17
|
+
/** Resolves manifest workspace bindings instead of the configuration's `workspaces` section. */
|
|
18
|
+
workspaces?: WorkspaceProvider;
|
|
19
|
+
/** Opens run sandboxes instead of the configuration's `sandbox` section. */
|
|
20
|
+
runSandbox?: RunSandboxProvider;
|
|
21
|
+
/** Backs `sandbox.driver: host` in the configuration. */
|
|
22
|
+
sandboxProvider?: SandboxProvider;
|
|
23
|
+
eventSinks?: EventSink[];
|
|
24
|
+
stepExecutors?: StepExecutor[];
|
|
25
|
+
/** Host default execution policies; manifests and steps override them. */
|
|
26
|
+
policies?: ExecutionPolicies;
|
|
27
|
+
/** Host execution policies applied last; manifests cannot override them. */
|
|
28
|
+
enforcedPolicies?: ExecutionPolicies;
|
|
29
|
+
/**
|
|
30
|
+
* Host default run limits, replacing values of `DEFAULT_RUN_LIMITS`;
|
|
31
|
+
* manifests and resume grants override them.
|
|
32
|
+
*/
|
|
33
|
+
limits?: RunLimits;
|
|
34
|
+
/** Host ceilings on run limits; nothing can exceed them. */
|
|
35
|
+
enforcedLimits?: RunLimits;
|
|
36
|
+
/** Observes, changes, or replaces context summarization. */
|
|
37
|
+
summarizer?: ContextSummarizerAdapter;
|
|
38
|
+
/**
|
|
39
|
+
* Conversation message options, merged over the configuration's `messages`
|
|
40
|
+
* section: for example `authorizeArtifact` or a KMS-backed signer.
|
|
41
|
+
*/
|
|
42
|
+
messages?: AgentRuntimeMessagesOptions;
|
|
43
|
+
}
|
|
44
|
+
/** Where a host keeps run state. */
|
|
45
|
+
export type HostStoreDriver = "file" | "sqlite" | "memory" | "module";
|
|
46
|
+
/** What a runtime module's `createRuntime` receives. */
|
|
47
|
+
export interface HostRuntimeContext {
|
|
48
|
+
manifest: AgentManifest;
|
|
49
|
+
runId?: string;
|
|
50
|
+
storeDirectory: string;
|
|
51
|
+
storeDriver?: HostStoreDriver;
|
|
52
|
+
storeLocation?: string;
|
|
53
|
+
eventFile?: string;
|
|
54
|
+
artifactDirectory?: string;
|
|
55
|
+
}
|
|
56
|
+
/** What a runtime module's `createRunStore` receives. */
|
|
57
|
+
export type HostStoreContext = Omit<HostRuntimeContext, "manifest">;
|
|
58
|
+
/** The exports a runtime module may use, including accepted aliases. */
|
|
59
|
+
export interface HostRuntimeModule extends HostRuntime {
|
|
60
|
+
store?: RunStore;
|
|
61
|
+
artifacts?: ArtifactStore;
|
|
62
|
+
modelAdapter?: ModelAdapter;
|
|
63
|
+
toolAdapter?: ToolAdapter;
|
|
64
|
+
credentialProvider?: ConnectionCredentialProvider;
|
|
65
|
+
approvalAdapter?: ApprovalAdapter;
|
|
66
|
+
sandboxAdapter?: SandboxAdapter;
|
|
67
|
+
subRunAdapter?: SubRunAdapter;
|
|
68
|
+
workspaceProvider?: WorkspaceProvider;
|
|
69
|
+
runSandboxProvider?: RunSandboxProvider;
|
|
70
|
+
eventSink?: EventSink;
|
|
71
|
+
executors?: StepExecutor[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* How far the host trusts the manifests it runs.
|
|
75
|
+
*
|
|
76
|
+
* - `local-operator`: an operator runs manifests they wrote on their own
|
|
77
|
+
* machine (`agent-runtime run`). Webhook steps may reach any destination.
|
|
78
|
+
* - `untrusted-request`: manifests or inputs arrive from another party (the
|
|
79
|
+
* worker protocol, the HTTP server). Webhook steps run only with a
|
|
80
|
+
* host-supplied executor that authorizes destinations.
|
|
81
|
+
*/
|
|
82
|
+
export type HostTrustMode = "local-operator" | "untrusted-request";
|
|
83
|
+
/** Reject adapters that do not implement their port. */
|
|
84
|
+
export declare const validateHostRuntime: (runtime: HostRuntime) => HostRuntime;
|
|
85
|
+
/**
|
|
86
|
+
* The step executors for a trust mode. Executors supplied by the runtime
|
|
87
|
+
* replace the default for their step type.
|
|
88
|
+
*/
|
|
89
|
+
export declare const resolveHostStepExecutors: (runtime: HostRuntime, trust: HostTrustMode) => StepExecutor[];
|
|
90
|
+
/**
|
|
91
|
+
* Load a trusted local ESM runtime module and return its validated
|
|
92
|
+
* adapters. A module exports adapters directly, as `default` or `runtime`,
|
|
93
|
+
* or through `createRuntime(context)`. Without a path, returns no adapters.
|
|
94
|
+
* A host that manages its own run store passes `createRunStore: false`, so a
|
|
95
|
+
* module's `createRunStore` is not called for every run.
|
|
96
|
+
*/
|
|
97
|
+
export declare const loadHostRuntime: (modulePath: string | undefined, context: HostRuntimeContext, options?: {
|
|
98
|
+
createRunStore?: boolean;
|
|
99
|
+
}) => Promise<HostRuntime>;
|
|
100
|
+
/** Load only a runtime module's run store, for commands that need no manifest. */
|
|
101
|
+
export declare const loadHostRunStore: (modulePath: string | undefined, context: HostStoreContext) => Promise<RunStore | undefined>;
|
|
102
|
+
/** Runtime configuration files discovered beside a manifest, in order. */
|
|
103
|
+
export declare const RUNTIME_CONFIG_FILE_NAMES: readonly ["agent-runtime.config.yaml", "agent-runtime.config.yml", "agent-runtime.config.json"];
|
|
104
|
+
/**
|
|
105
|
+
* Load the requested runtime configuration, or the first discovered
|
|
106
|
+
* `agent-runtime.config.*` in `searchDirectory`, or an empty configuration.
|
|
107
|
+
*/
|
|
108
|
+
export declare const resolveAgentRuntimeConfig: (requested?: string, searchDirectory?: string) => Promise<AgentRuntimeConfig>;
|
|
109
|
+
/**
|
|
110
|
+
* Workspace and sandbox adapters from runtimes, highest precedence first.
|
|
111
|
+
* Host-supplied adapters take precedence over the configuration.
|
|
112
|
+
*/
|
|
113
|
+
export declare const hostWorkspaceCompositionOptions: (...runtimes: HostRuntime[]) => WorkspaceCompositionOptions;
|
|
114
|
+
/** Overlay a runtime on another; message options and event sinks combine. */
|
|
115
|
+
export declare const mergeHostRuntimes: (base: HostRuntime, overlay: HostRuntime) => HostRuntime;
|
|
116
|
+
export interface ComposeHostRuntimeOptions {
|
|
117
|
+
/** Environment visible to the configuration's references. Defaults to the process environment. */
|
|
118
|
+
environment?: Readonly<Record<string, string | undefined>>;
|
|
119
|
+
/** Host policy applied before configured model adapters are created. */
|
|
120
|
+
modelPolicy?: ModelAuthorizationPolicy;
|
|
121
|
+
/** Host policy and credentials applied to configured MCP adapters. */
|
|
122
|
+
toolOptions?: ConfiguredMcpToolAdapterOptions;
|
|
123
|
+
/** Host policy, hooks, and providers applied to configured workspaces and the run sandbox. */
|
|
124
|
+
workspaceOptions?: WorkspaceCompositionOptions;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Compose a manifest's runtime: adapters from the configuration, overlaid by
|
|
128
|
+
* supplied runtimes in increasing precedence (for example, the runtime
|
|
129
|
+
* module, then adapters an embedding host passes in code). A supplied model
|
|
130
|
+
* or tool adapter replaces the configured one.
|
|
131
|
+
*/
|
|
132
|
+
export declare const composeHostRuntime: (manifest: AgentManifest, config: AgentRuntimeConfig, supplied: readonly HostRuntime[], options?: ComposeHostRuntimeOptions) => HostRuntime;
|
|
133
|
+
/**
|
|
134
|
+
* A runtime's message options with the prompt package's history compactor,
|
|
135
|
+
* so summarizing history policies pass preflight.
|
|
136
|
+
*/
|
|
137
|
+
export declare const withHistoryCompactor: (options: AgentRuntimeMessagesOptions | undefined) => AgentRuntimeMessagesOptions;
|
|
138
|
+
export interface HostRuntimeDependencyOptions {
|
|
139
|
+
trust: HostTrustMode;
|
|
140
|
+
runStore: RunStore;
|
|
141
|
+
artifacts?: ArtifactStore | undefined;
|
|
142
|
+
agentManifestSource?: AgentManifestSource | undefined;
|
|
143
|
+
/** Host sinks that receive events before the runtime's own sinks. */
|
|
144
|
+
eventSinks?: EventSink[];
|
|
145
|
+
maxParallelSteps?: number | undefined;
|
|
146
|
+
eventSinkFailurePolicy?: "continue" | "fail-run" | undefined;
|
|
147
|
+
onEventSinkError?: (error: unknown, event: RunEvent, sink: EventSink) => void;
|
|
148
|
+
}
|
|
149
|
+
/** `AgentRuntime` dependencies for a composed host runtime. */
|
|
150
|
+
export declare const hostRuntimeDependencies: (runtime: HostRuntime, options: HostRuntimeDependencyOptions) => AgentRuntimeDependencies;
|