@saturn-universe/runtime-host 0.0.0-stage → 0.1.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 +661 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/README.md +13 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/index.mjs +1473 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/package.json +10 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/board.mjs +321 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/ledger.mjs +1143 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/ctfd.mjs +154 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/ctfplus.mjs +769 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/gzctf.mjs +130 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/http.mjs +336 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/index.mjs +133 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/platform/lease.mjs +153 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/server.mjs +336 -0
- package/dist/builtin-plugins/saturn-plugin-ctf/src/view.mjs +714 -0
- package/dist/command-dispatch.d.ts +10 -0
- package/dist/command-dispatch.js +65 -0
- package/dist/completion-judge.d.ts +10 -0
- package/dist/completion-judge.js +156 -0
- package/dist/composition.d.ts +108 -0
- package/dist/composition.js +1180 -0
- package/dist/configuration.d.ts +49 -0
- package/dist/configuration.js +51 -0
- package/dist/context-extensions.d.ts +681 -0
- package/dist/context-extensions.js +289 -0
- package/dist/cordis/context-core-plugin.d.ts +35 -0
- package/dist/cordis/context-core-plugin.js +296 -0
- package/dist/cordis/env-probe-plugin.d.ts +27 -0
- package/dist/cordis/env-probe-plugin.js +114 -0
- package/dist/cordis/host-context.d.ts +65 -0
- package/dist/cordis/host-context.js +199 -0
- package/dist/cordis/model-responses-plugin.d.ts +81 -0
- package/dist/cordis/model-responses-plugin.js +209 -0
- package/dist/cordis/plugin-contributions.d.ts +47 -0
- package/dist/cordis/plugin-contributions.js +119 -0
- package/dist/cordis/plugin-lifecycle.d.ts +57 -0
- package/dist/cordis/plugin-lifecycle.js +222 -0
- package/dist/cordis/plugin-loader.d.ts +18 -0
- package/dist/cordis/plugin-loader.js +310 -0
- package/dist/cordis/plugin-sdk-adapter.d.ts +17 -0
- package/dist/cordis/plugin-sdk-adapter.js +283 -0
- package/dist/cordis/required-host-plugin.d.ts +6 -0
- package/dist/cordis/required-host-plugin.js +1 -0
- package/dist/cordis/runtime-hooks-plugin.d.ts +23 -0
- package/dist/cordis/runtime-hooks-plugin.js +103 -0
- package/dist/cordis/sandbox-plugin.d.ts +18 -0
- package/dist/cordis/sandbox-plugin.js +21 -0
- package/dist/cordis/scoped-layers.d.ts +63 -0
- package/dist/cordis/scoped-layers.js +170 -0
- package/dist/cordis/tools/builtin-agent-tools-plugin.d.ts +11 -0
- package/dist/cordis/tools/builtin-agent-tools-plugin.js +171 -0
- package/dist/cordis/tools/index.d.ts +17 -0
- package/dist/cordis/tools/index.js +40 -0
- package/dist/cordis/tools/mcp-tools-plugin.d.ts +7 -0
- package/dist/cordis/tools/mcp-tools-plugin.js +116 -0
- package/dist/cordis/tools/process-manager-plugin.d.ts +11 -0
- package/dist/cordis/tools/process-manager-plugin.js +39 -0
- package/dist/cordis/tools/sandbox-target-tools-plugin.d.ts +13 -0
- package/dist/cordis/tools/sandbox-target-tools-plugin.js +255 -0
- package/dist/cordis/tools/tool-guidance.d.ts +4 -0
- package/dist/cordis/tools/tool-guidance.js +30 -0
- package/dist/cordis/tools/tools-core-plugin.d.ts +128 -0
- package/dist/cordis/tools/tools-core-plugin.js +486 -0
- package/dist/cordis/tools/web-fetch.d.ts +17 -0
- package/dist/cordis/tools/web-fetch.js +529 -0
- package/dist/cordis/tools/web-search-tools-plugin.d.ts +10 -0
- package/dist/cordis/tools/web-search-tools-plugin.js +191 -0
- package/dist/cordis/tools/workspace-tools-plugin.d.ts +8 -0
- package/dist/cordis/tools/workspace-tools-plugin.js +145 -0
- package/dist/env-probe.d.ts +8 -0
- package/dist/env-probe.js +172 -0
- package/dist/host-configuration.d.ts +27 -0
- package/dist/host-configuration.js +185 -0
- package/dist/host-tools.d.ts +19 -0
- package/dist/host-tools.js +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +140 -0
- package/dist/ipc.d.ts +24 -0
- package/dist/ipc.js +162 -0
- package/dist/logger.d.ts +11 -0
- package/dist/logger.js +84 -0
- package/dist/mcp-configuration.d.ts +17 -0
- package/dist/mcp-configuration.js +50 -0
- package/dist/modes.d.ts +27 -0
- package/dist/modes.js +472 -0
- package/dist/ownership.d.ts +7 -0
- package/dist/ownership.js +100 -0
- package/dist/plugin-configuration.d.ts +9 -0
- package/dist/plugin-configuration.js +21 -0
- package/dist/plugin-tool-grants.d.ts +18 -0
- package/dist/plugin-tool-grants.js +21 -0
- package/dist/process-workspaces.d.ts +4 -0
- package/dist/process-workspaces.js +28 -0
- package/dist/progress.d.ts +30 -0
- package/dist/progress.js +699 -0
- package/dist/provider-catalog.d.ts +754 -0
- package/dist/provider-catalog.js +471 -0
- package/dist/run-budget.d.ts +24 -0
- package/dist/run-budget.js +47 -0
- package/dist/run-checkpoint.d.ts +2 -0
- package/dist/run-checkpoint.js +52 -0
- package/dist/sandbox-manager.d.ts +111 -0
- package/dist/sandbox-manager.js +1519 -0
- package/dist/session-paths.d.ts +15 -0
- package/dist/session-paths.js +40 -0
- package/dist/side-question.d.ts +14 -0
- package/dist/side-question.js +89 -0
- package/dist/skills-runtime.d.ts +13 -0
- package/dist/skills-runtime.js +243 -0
- package/dist/token-estimator.d.ts +3 -0
- package/dist/token-estimator.js +73 -0
- package/dist/tool-result.d.ts +2 -0
- package/dist/tool-result.js +91 -0
- package/dist/user-config.d.ts +23 -0
- package/dist/user-config.js +36 -0
- package/package.json +28 -3
- package/README.md +0 -3
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { webSearchConfig } from './user-config.js';
|
|
3
|
+
import { parse, stringify } from 'smol-toml';
|
|
4
|
+
import { DEFAULT_MODE_REF, RuntimeError, lookupModelMetadata, normalizeProviderBaseUrl, normalizeProviderProtocol, providerProtocolInputs, validateTeamConfig, validateWorkSubpath, } from '@saturn-universe/core';
|
|
5
|
+
import { credentialRefSchema, providerIdSchema } from '@saturn-universe/protocol';
|
|
6
|
+
import { maxShellTimeoutMs } from '@saturn-universe/tools';
|
|
7
|
+
import { capabilities, defaultCapabilities } from './configuration.js';
|
|
8
|
+
import { mcpServersSchema } from './mcp-configuration.js';
|
|
9
|
+
import { modeDefinitionsSchema, skillDefinitionsSchema } from './context-extensions.js';
|
|
10
|
+
import { configurationTable } from './plugin-configuration.js';
|
|
11
|
+
import { configuredRunBudgetShape, resolveRunBudget } from './run-budget.js';
|
|
12
|
+
const id = z.string().trim().min(1).max(200);
|
|
13
|
+
const positive = z.number().int().positive().safe();
|
|
14
|
+
const nonnegativeNumber = z.number().nonnegative().finite();
|
|
15
|
+
const duplicateProfileName = 'Duplicate Provider profile name';
|
|
16
|
+
const pricingSchema = z.strictObject({
|
|
17
|
+
input_per_million: nonnegativeNumber,
|
|
18
|
+
cached_input_per_million: nonnegativeNumber.optional(),
|
|
19
|
+
output_per_million: nonnegativeNumber,
|
|
20
|
+
});
|
|
21
|
+
const codecVersion = z.union([z.literal(1), z.literal(2)]);
|
|
22
|
+
const baseUrl = z.string().transform((value, ctx) => {
|
|
23
|
+
const url = normalizeProviderBaseUrl(value);
|
|
24
|
+
if (url !== undefined)
|
|
25
|
+
return url;
|
|
26
|
+
ctx.addIssue({ code: 'custom', message: 'Invalid endpoint' });
|
|
27
|
+
return z.NEVER;
|
|
28
|
+
});
|
|
29
|
+
const profile = z
|
|
30
|
+
.strictObject({
|
|
31
|
+
provider_id: id,
|
|
32
|
+
revision: id,
|
|
33
|
+
codec_version: codecVersion,
|
|
34
|
+
base_url: baseUrl,
|
|
35
|
+
model_id: id,
|
|
36
|
+
credential_ref: credentialRefSchema,
|
|
37
|
+
default_reasoning_effort: id.optional(),
|
|
38
|
+
capabilities: capabilities.optional(),
|
|
39
|
+
pricing: pricingSchema.optional(),
|
|
40
|
+
})
|
|
41
|
+
.refine((value) => value.codec_version !== 2 || value.revision !== '1');
|
|
42
|
+
export const hardLimits = {
|
|
43
|
+
maxModelAttempts: 10000,
|
|
44
|
+
maxToolCalls: 10000,
|
|
45
|
+
maxSteps: 20000,
|
|
46
|
+
maxTotalTokens: 10000000,
|
|
47
|
+
subagentMaxModelAttempts: 10000,
|
|
48
|
+
wallTimeMs: 86400000,
|
|
49
|
+
subagentWallTimeMs: 86400000,
|
|
50
|
+
modelTimeoutMs: 600000,
|
|
51
|
+
streamIdleTimeoutMs: 600000,
|
|
52
|
+
requestTotalTimeoutMs: 600000,
|
|
53
|
+
toolTimeoutMs: 600000,
|
|
54
|
+
shellTimeoutMs: maxShellTimeoutMs,
|
|
55
|
+
maxParallelTools: 64,
|
|
56
|
+
};
|
|
57
|
+
const runDefaults = z.strictObject({
|
|
58
|
+
mode_ref: id.optional(),
|
|
59
|
+
permission_mode: z.enum(['strict', 'default', 'full']).optional(),
|
|
60
|
+
policy_version: id.optional(),
|
|
61
|
+
tool_set_version: id.optional(),
|
|
62
|
+
planner: z.enum(['auto', 'off']).optional(),
|
|
63
|
+
search: z.enum(['selective', 'off']).optional(),
|
|
64
|
+
reasoning_effort: id.optional(),
|
|
65
|
+
worker_reasoning_effort: id.optional(),
|
|
66
|
+
reasoning_summary: z.enum(['auto', 'concise', 'detailed']).optional(),
|
|
67
|
+
...configuredRunBudgetShape(hardLimits),
|
|
68
|
+
model_timeout_ms: positive.max(hardLimits.modelTimeoutMs).optional(),
|
|
69
|
+
model_idle_timeout_ms: positive.max(hardLimits.streamIdleTimeoutMs).optional(),
|
|
70
|
+
model_total_timeout_ms: positive.max(hardLimits.requestTotalTimeoutMs).optional(),
|
|
71
|
+
tool_timeout_ms: positive.max(hardLimits.toolTimeoutMs).optional(),
|
|
72
|
+
max_parallel_tools: positive.max(hardLimits.maxParallelTools).optional(),
|
|
73
|
+
});
|
|
74
|
+
const teamPresetSchema = z.strictObject({
|
|
75
|
+
concurrency: positive.max(16).optional(),
|
|
76
|
+
members: z
|
|
77
|
+
.array(z.strictObject({
|
|
78
|
+
id,
|
|
79
|
+
parent: id,
|
|
80
|
+
task: z.string().trim().min(1),
|
|
81
|
+
sandbox_profile: z.enum(['default', 'readonly', 'build']).optional(),
|
|
82
|
+
work_subpath: z.string().trim().min(1).max(512).optional(),
|
|
83
|
+
}))
|
|
84
|
+
.min(1)
|
|
85
|
+
.max(15),
|
|
86
|
+
});
|
|
87
|
+
const modelOverride = z.strictObject({
|
|
88
|
+
context_window: positive.optional(),
|
|
89
|
+
max_output_tokens: positive.optional(),
|
|
90
|
+
default_reasoning_effort: id.optional(),
|
|
91
|
+
reasoning_model: z.boolean().optional(),
|
|
92
|
+
reasoning_efforts: z.array(id).optional(),
|
|
93
|
+
tools: z.boolean().optional(),
|
|
94
|
+
parallel_tool_calls: z.boolean().optional(),
|
|
95
|
+
streaming: z.boolean().optional(),
|
|
96
|
+
images: z.boolean().optional(),
|
|
97
|
+
pricing: pricingSchema.partial().optional(),
|
|
98
|
+
});
|
|
99
|
+
const provider = z
|
|
100
|
+
.strictObject({
|
|
101
|
+
base_url: baseUrl,
|
|
102
|
+
protocol: z.enum(providerProtocolInputs).transform(normalizeProviderProtocol).optional(),
|
|
103
|
+
credential_ref: credentialRefSchema,
|
|
104
|
+
models: z.array(id.regex(/^[^\u0000-\u001f\u007f]+$/)).min(1),
|
|
105
|
+
revision: id.optional(),
|
|
106
|
+
codec_version: codecVersion.optional(),
|
|
107
|
+
default_reasoning_effort: id.optional(),
|
|
108
|
+
model_overrides: configurationTable(id, modelOverride).optional(),
|
|
109
|
+
})
|
|
110
|
+
.refine((value) => value.codec_version !== 2 || (value.revision ?? '1') !== '1');
|
|
111
|
+
const catalogSchema = z.strictObject({
|
|
112
|
+
version: z.literal(1),
|
|
113
|
+
default_profile: id.optional(),
|
|
114
|
+
profiles: z.record(id, profile).optional(),
|
|
115
|
+
providers: configurationTable(providerIdSchema, provider).optional(),
|
|
116
|
+
task_profiles: z.record(id, id).optional(),
|
|
117
|
+
run_defaults: runDefaults.optional(),
|
|
118
|
+
workspace_tools: z.boolean().optional(),
|
|
119
|
+
web_search: webSearchConfig.optional(),
|
|
120
|
+
mcp_servers: mcpServersSchema.optional(),
|
|
121
|
+
trusted_mcp_workspaces: z.array(z.string().trim().min(1).max(4096)).max(256).optional(),
|
|
122
|
+
modes: modeDefinitionsSchema.optional(),
|
|
123
|
+
skills: skillDefinitionsSchema.optional(),
|
|
124
|
+
team_presets: z.record(id, teamPresetSchema).optional(),
|
|
125
|
+
counter: z
|
|
126
|
+
.strictObject({
|
|
127
|
+
approval: z.enum(['allow', 'ask', 'deny']),
|
|
128
|
+
reconcile: z.boolean().optional(),
|
|
129
|
+
holdAfterApply: z.boolean().optional(),
|
|
130
|
+
})
|
|
131
|
+
.optional(),
|
|
132
|
+
});
|
|
133
|
+
export function parseProviderCatalog(value) {
|
|
134
|
+
const parsed = catalogSchema.safeParse(value);
|
|
135
|
+
if (!parsed.success)
|
|
136
|
+
throw invalid();
|
|
137
|
+
const data = parsed.data;
|
|
138
|
+
for (const preset of Object.values(data.team_presets ?? {})) {
|
|
139
|
+
validateTeamConfig({
|
|
140
|
+
...(preset.concurrency !== undefined ? { concurrency: preset.concurrency } : {}),
|
|
141
|
+
members: preset.members.map((m) => ({
|
|
142
|
+
id: m.id,
|
|
143
|
+
parent: m.parent,
|
|
144
|
+
task: m.task,
|
|
145
|
+
...(m.sandbox_profile ? { sandboxProfile: m.sandbox_profile } : {}),
|
|
146
|
+
...(m.work_subpath ? { workSubpath: validateWorkSubpath(m.work_subpath) } : {}),
|
|
147
|
+
})),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const profiles = Object.entries(data.profiles ?? {}).map(([name, value]) => {
|
|
151
|
+
return {
|
|
152
|
+
name,
|
|
153
|
+
providerId: value.provider_id,
|
|
154
|
+
revision: value.revision,
|
|
155
|
+
codecVersion: value.codec_version,
|
|
156
|
+
baseURL: value.base_url,
|
|
157
|
+
modelId: value.model_id,
|
|
158
|
+
credentialRef: value.credential_ref,
|
|
159
|
+
...(value.default_reasoning_effort ? { defaultReasoningEffort: value.default_reasoning_effort } : {}),
|
|
160
|
+
...(value.capabilities ? { capabilities: value.capabilities } : {}),
|
|
161
|
+
...(value.pricing
|
|
162
|
+
? {
|
|
163
|
+
pricing: {
|
|
164
|
+
inputPerMillion: value.pricing.input_per_million,
|
|
165
|
+
...(value.pricing.cached_input_per_million !== undefined
|
|
166
|
+
? { cachedInputPerMillion: value.pricing.cached_input_per_million }
|
|
167
|
+
: {}),
|
|
168
|
+
outputPerMillion: value.pricing.output_per_million,
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
: {}),
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
for (const [providerId, value] of Object.entries(data.providers ?? {})) {
|
|
175
|
+
if (`${providerId}@${value.revision ?? '1'}`.length > 200 ||
|
|
176
|
+
Object.keys(value.model_overrides ?? {}).some((model) => !value.models.includes(model)))
|
|
177
|
+
throw invalid();
|
|
178
|
+
for (const modelId of value.models)
|
|
179
|
+
profiles.push(expandProfile(providerId, modelId, value));
|
|
180
|
+
}
|
|
181
|
+
if (!data.providers && !data.profiles)
|
|
182
|
+
throw invalid();
|
|
183
|
+
const names = new Set();
|
|
184
|
+
const identities = new Set();
|
|
185
|
+
const revisions = new Map();
|
|
186
|
+
for (const p of profiles) {
|
|
187
|
+
if (names.has(p.name))
|
|
188
|
+
throw invalid(duplicateProfileName);
|
|
189
|
+
names.add(p.name);
|
|
190
|
+
const identity = JSON.stringify([p.providerId, p.revision, p.modelId, p.codecVersion]);
|
|
191
|
+
if (identities.has(identity))
|
|
192
|
+
throw invalid();
|
|
193
|
+
identities.add(identity);
|
|
194
|
+
const revisionRef = `${p.providerId}@${p.revision}`;
|
|
195
|
+
const binding = JSON.stringify([
|
|
196
|
+
p.baseURL,
|
|
197
|
+
p.credentialRef,
|
|
198
|
+
p.codecVersion,
|
|
199
|
+
p.protocol ?? 'openai-responses',
|
|
200
|
+
]);
|
|
201
|
+
if (revisions.has(revisionRef) && revisions.get(revisionRef) !== binding)
|
|
202
|
+
throw invalid();
|
|
203
|
+
revisions.set(revisionRef, binding);
|
|
204
|
+
}
|
|
205
|
+
if ((profiles.length
|
|
206
|
+
? !data.default_profile || !names.has(data.default_profile)
|
|
207
|
+
: data.default_profile !== undefined) ||
|
|
208
|
+
Object.values(data.task_profiles ?? {}).some((name) => !names.has(name)))
|
|
209
|
+
throw invalid();
|
|
210
|
+
const result = {
|
|
211
|
+
profiles,
|
|
212
|
+
...(data.default_profile ? { defaultProfile: data.default_profile } : {}),
|
|
213
|
+
...(data.providers ? { providers: data.providers } : {}),
|
|
214
|
+
taskProfiles: data.task_profiles ?? {},
|
|
215
|
+
...(data.run_defaults ? { runDefaults: data.run_defaults } : {}),
|
|
216
|
+
...(data.workspace_tools === undefined ? {} : { workspaceTools: data.workspace_tools }),
|
|
217
|
+
...(data.web_search ? { webSearch: data.web_search } : {}),
|
|
218
|
+
...(data.mcp_servers ? { mcpServers: data.mcp_servers } : {}),
|
|
219
|
+
...(data.trusted_mcp_workspaces ? { trustedMcpWorkspaces: data.trusted_mcp_workspaces } : {}),
|
|
220
|
+
...(data.modes ? { modes: data.modes } : {}),
|
|
221
|
+
...(data.skills ? { skills: data.skills } : {}),
|
|
222
|
+
...(data.team_presets ? { teamPresets: data.team_presets } : {}),
|
|
223
|
+
...(data.counter ? { counter: data.counter } : {}),
|
|
224
|
+
};
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
function expandProfile(providerId, modelId, value) {
|
|
228
|
+
const name = `${providerId}/${modelId}`;
|
|
229
|
+
if (name.length > 200)
|
|
230
|
+
throw invalid();
|
|
231
|
+
const model = lookupModelMetadata(modelId);
|
|
232
|
+
const override = Object.hasOwn(value.model_overrides ?? {}, modelId)
|
|
233
|
+
? value.model_overrides?.[modelId]
|
|
234
|
+
: undefined;
|
|
235
|
+
const reasoningModel = override?.reasoning_model ?? model?.reasoningModel ?? Boolean(override?.reasoning_efforts?.length);
|
|
236
|
+
const tools = override?.tools ?? model?.tools ?? defaultCapabilities.tools;
|
|
237
|
+
const parallelToolCalls = override?.parallel_tool_calls ?? (tools && (model?.parallelToolCalls ?? false));
|
|
238
|
+
const protocol = value.protocol ?? 'openai-responses';
|
|
239
|
+
const input = override?.pricing?.input_per_million ?? model?.pricing.inputPerMillion;
|
|
240
|
+
const output = override?.pricing?.output_per_million ?? model?.pricing.outputPerMillion;
|
|
241
|
+
const cached = override?.pricing?.cached_input_per_million ?? model?.pricing.cachedInputPerMillion;
|
|
242
|
+
if (override?.pricing && (input === undefined || output === undefined))
|
|
243
|
+
throw invalid();
|
|
244
|
+
const effort = override?.default_reasoning_effort ?? value.default_reasoning_effort;
|
|
245
|
+
return {
|
|
246
|
+
name,
|
|
247
|
+
providerId,
|
|
248
|
+
revision: value.revision ?? '1',
|
|
249
|
+
codecVersion: value.codec_version ?? 1,
|
|
250
|
+
baseURL: value.base_url,
|
|
251
|
+
modelId,
|
|
252
|
+
credentialRef: value.credential_ref,
|
|
253
|
+
protocol,
|
|
254
|
+
...(effort ? { defaultReasoningEffort: effort } : {}),
|
|
255
|
+
capabilities: {
|
|
256
|
+
...defaultCapabilities,
|
|
257
|
+
contextWindow: override?.context_window ?? model?.contextWindow ?? defaultCapabilities.contextWindow,
|
|
258
|
+
maxOutputTokens: override?.max_output_tokens ?? model?.maxOutputTokens ?? defaultCapabilities.maxOutputTokens,
|
|
259
|
+
tools,
|
|
260
|
+
parallelToolCalls,
|
|
261
|
+
streaming: override?.streaming ?? model?.streaming ?? defaultCapabilities.streaming,
|
|
262
|
+
images: override?.images ?? model?.images ?? defaultCapabilities.images,
|
|
263
|
+
responses: {
|
|
264
|
+
...defaultCapabilities.responses,
|
|
265
|
+
reasoningModel,
|
|
266
|
+
reasoningEfforts: reasoningModel
|
|
267
|
+
? (override?.reasoning_efforts ?? model?.reasoningEfforts ?? [])
|
|
268
|
+
: [],
|
|
269
|
+
parallelToolCallsParameter: protocol !== 'gemini' && parallelToolCalls,
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
...(input !== undefined && output !== undefined
|
|
273
|
+
? {
|
|
274
|
+
pricing: {
|
|
275
|
+
inputPerMillion: input,
|
|
276
|
+
outputPerMillion: output,
|
|
277
|
+
...(cached === undefined ? {} : { cachedInputPerMillion: cached }),
|
|
278
|
+
},
|
|
279
|
+
...(model && !Object.keys(override?.pricing ?? {}).length
|
|
280
|
+
? { pricingSource: 'builtin' }
|
|
281
|
+
: {}),
|
|
282
|
+
}
|
|
283
|
+
: {}),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
export function parseProviderToml(text) {
|
|
287
|
+
try {
|
|
288
|
+
return parseProviderCatalog(parse(text));
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
if (error instanceof RuntimeError && error.message === duplicateProfileName)
|
|
292
|
+
throw error;
|
|
293
|
+
throw invalid();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
export function formatProviderCatalog(catalog) {
|
|
297
|
+
const profiles = Object.fromEntries(catalog.profiles
|
|
298
|
+
.filter((p) => p.protocol === undefined)
|
|
299
|
+
.map((p) => [
|
|
300
|
+
p.name,
|
|
301
|
+
{
|
|
302
|
+
provider_id: p.providerId,
|
|
303
|
+
revision: p.revision,
|
|
304
|
+
codec_version: p.codecVersion,
|
|
305
|
+
base_url: p.baseURL,
|
|
306
|
+
model_id: p.modelId,
|
|
307
|
+
credential_ref: p.credentialRef,
|
|
308
|
+
...(p.defaultReasoningEffort ? { default_reasoning_effort: p.defaultReasoningEffort } : {}),
|
|
309
|
+
...(p.capabilities ? { capabilities: p.capabilities } : {}),
|
|
310
|
+
...(p.pricing
|
|
311
|
+
? {
|
|
312
|
+
pricing: {
|
|
313
|
+
input_per_million: p.pricing.inputPerMillion,
|
|
314
|
+
...(p.pricing.cachedInputPerMillion !== undefined
|
|
315
|
+
? { cached_input_per_million: p.pricing.cachedInputPerMillion }
|
|
316
|
+
: {}),
|
|
317
|
+
output_per_million: p.pricing.outputPerMillion,
|
|
318
|
+
},
|
|
319
|
+
}
|
|
320
|
+
: {}),
|
|
321
|
+
},
|
|
322
|
+
]));
|
|
323
|
+
return stringify({
|
|
324
|
+
version: 1,
|
|
325
|
+
...(catalog.defaultProfile === undefined ? {} : { default_profile: catalog.defaultProfile }),
|
|
326
|
+
...(catalog.providers ? { providers: catalog.providers } : {}),
|
|
327
|
+
...(!catalog.providers || Object.keys(profiles).length ? { profiles } : {}),
|
|
328
|
+
task_profiles: catalog.taskProfiles,
|
|
329
|
+
...(catalog.runDefaults ? { run_defaults: catalog.runDefaults } : {}),
|
|
330
|
+
...(catalog.workspaceTools === undefined ? {} : { workspace_tools: catalog.workspaceTools }),
|
|
331
|
+
...(catalog.webSearch ? { web_search: catalog.webSearch } : {}),
|
|
332
|
+
...(catalog.mcpServers ? { mcp_servers: catalog.mcpServers } : {}),
|
|
333
|
+
...(catalog.trustedMcpWorkspaces ? { trusted_mcp_workspaces: [...catalog.trustedMcpWorkspaces] } : {}),
|
|
334
|
+
...(catalog.modes ? { modes: catalog.modes } : {}),
|
|
335
|
+
...(catalog.skills ? { skills: catalog.skills } : {}),
|
|
336
|
+
...(catalog.teamPresets ? { team_presets: catalog.teamPresets } : {}),
|
|
337
|
+
...(catalog.counter ? { counter: catalog.counter } : {}),
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
export const profileModel = (p) => ({
|
|
341
|
+
providerId: p.providerId,
|
|
342
|
+
modelId: p.modelId,
|
|
343
|
+
profileRef: `${p.providerId}@${p.revision}`,
|
|
344
|
+
});
|
|
345
|
+
export function catalogRegistrations(catalog) {
|
|
346
|
+
const groups = new Map();
|
|
347
|
+
for (const p of catalog.profiles) {
|
|
348
|
+
const ref = profileModel(p).profileRef;
|
|
349
|
+
const entry = {
|
|
350
|
+
id: p.providerId,
|
|
351
|
+
revision: p.revision,
|
|
352
|
+
protocol: p.protocol ?? 'openai-responses',
|
|
353
|
+
baseURL: p.baseURL,
|
|
354
|
+
apiKeyRef: p.credentialRef,
|
|
355
|
+
headers: {},
|
|
356
|
+
credentialScopeRef: p.credentialRef,
|
|
357
|
+
codecId: 'saturn-responses',
|
|
358
|
+
codecVersion: p.codecVersion,
|
|
359
|
+
models: { [p.modelId]: p.capabilities ?? defaultCapabilities },
|
|
360
|
+
};
|
|
361
|
+
const previous = groups.get(ref);
|
|
362
|
+
groups.set(ref, previous ? { ...previous, models: { ...previous.models, ...entry.models } } : entry);
|
|
363
|
+
}
|
|
364
|
+
return [...groups.values()];
|
|
365
|
+
}
|
|
366
|
+
export function selectProfile(catalog, selection) {
|
|
367
|
+
if ((selection.profile && selection.model) ||
|
|
368
|
+
(selection.profile && selection.taskProfile) ||
|
|
369
|
+
(selection.model && selection.taskProfile))
|
|
370
|
+
throw invalid();
|
|
371
|
+
if (selection.taskProfile && !Object.hasOwn(catalog.taskProfiles, selection.taskProfile))
|
|
372
|
+
throw invalid();
|
|
373
|
+
if (selection.entryProfile !== undefined &&
|
|
374
|
+
!catalog.profiles.some((p) => p.name === selection.entryProfile))
|
|
375
|
+
throw invalid();
|
|
376
|
+
const explicit = selection.profile;
|
|
377
|
+
const model = selection.model;
|
|
378
|
+
const byModel = model &&
|
|
379
|
+
catalog.profiles.find((p) => {
|
|
380
|
+
const ref = profileModel(p);
|
|
381
|
+
return (ref.providerId === model.providerId &&
|
|
382
|
+
ref.modelId === model.modelId &&
|
|
383
|
+
ref.profileRef === model.profileRef);
|
|
384
|
+
});
|
|
385
|
+
if (model && !byModel)
|
|
386
|
+
throw invalid();
|
|
387
|
+
const name = explicit ??
|
|
388
|
+
(model
|
|
389
|
+
? byModel.name
|
|
390
|
+
: ((selection.taskProfile ? catalog.taskProfiles[selection.taskProfile] : undefined) ??
|
|
391
|
+
selection.entryProfile ??
|
|
392
|
+
catalog.defaultProfile));
|
|
393
|
+
const selected = catalog.profiles.find((p) => p.name === name);
|
|
394
|
+
if (!selected || (model && selected !== byModel))
|
|
395
|
+
throw invalid();
|
|
396
|
+
return selected;
|
|
397
|
+
}
|
|
398
|
+
export function resolveRunDefaults(model, defaults, options) {
|
|
399
|
+
const reasoning = resolveDefaultReasoning(defaults, options);
|
|
400
|
+
return {
|
|
401
|
+
model,
|
|
402
|
+
modeRef: defaults?.mode_ref ?? DEFAULT_MODE_REF,
|
|
403
|
+
policyVersion: defaults?.policy_version ?? '1',
|
|
404
|
+
toolSetVersion: defaults?.tool_set_version ?? '1',
|
|
405
|
+
...(defaults?.search ? { search: { mode: defaults.search } } : {}),
|
|
406
|
+
...(defaults?.worker_reasoning_effort ? { workerReasoningEffort: defaults.worker_reasoning_effort } : {}),
|
|
407
|
+
responses: {
|
|
408
|
+
storage: 'local_stateless',
|
|
409
|
+
...(reasoning ? { reasoning } : {}),
|
|
410
|
+
},
|
|
411
|
+
retry: { modelMaxAttemptsPerCall: 3, toolMaxAttemptsPerCall: 1, baseDelayMs: 2000, maxDelayMs: 5000 },
|
|
412
|
+
limits: {
|
|
413
|
+
...resolveRunBudget(defaults, options?.modeBudget),
|
|
414
|
+
modelTimeoutMs: defaults?.model_timeout_ms ?? 300000,
|
|
415
|
+
...(defaults?.model_idle_timeout_ms !== undefined
|
|
416
|
+
? { streamIdleTimeoutMs: defaults.model_idle_timeout_ms }
|
|
417
|
+
: {}),
|
|
418
|
+
...(defaults?.model_total_timeout_ms !== undefined
|
|
419
|
+
? { requestTotalTimeoutMs: defaults.model_total_timeout_ms }
|
|
420
|
+
: {}),
|
|
421
|
+
toolTimeoutMs: defaults?.tool_timeout_ms ?? 30000,
|
|
422
|
+
...(defaults?.tool_timeout_ms === undefined ? { shellTimeoutMs: maxShellTimeoutMs } : {}),
|
|
423
|
+
maxParallelTools: defaults?.max_parallel_tools ?? 4,
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
export function resolveWorkerReasoning(config, capabilities) {
|
|
428
|
+
const effort = config.workerReasoningEffort;
|
|
429
|
+
const responses = capabilities?.responses;
|
|
430
|
+
if (!effort)
|
|
431
|
+
return config;
|
|
432
|
+
if (effort === 'off' || effort === 'none') {
|
|
433
|
+
const { reasoning: _removed, ...restResponses } = config.responses;
|
|
434
|
+
return { ...config, responses: restResponses };
|
|
435
|
+
}
|
|
436
|
+
if (!responses?.reasoningModel ||
|
|
437
|
+
(responses.reasoningEfforts.length > 0 && !responses.reasoningEfforts.includes(effort)))
|
|
438
|
+
return config;
|
|
439
|
+
return {
|
|
440
|
+
...config,
|
|
441
|
+
responses: { ...config.responses, reasoning: { ...config.responses.reasoning, effort } },
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function resolveDefaultReasoning(defaults, options) {
|
|
445
|
+
const caps = options?.capabilities?.responses;
|
|
446
|
+
if (!caps?.reasoningModel)
|
|
447
|
+
return undefined;
|
|
448
|
+
const supportedEfforts = caps.reasoningEfforts;
|
|
449
|
+
const requestedEffort = defaults?.reasoning_effort ?? options?.profileReasoningEffort;
|
|
450
|
+
if (requestedEffort === 'off' || requestedEffort === 'none')
|
|
451
|
+
return undefined;
|
|
452
|
+
const effort = requestedEffort && (!supportedEfforts.length || supportedEfforts.includes(requestedEffort))
|
|
453
|
+
? requestedEffort
|
|
454
|
+
: !requestedEffort && supportedEfforts.length > 0
|
|
455
|
+
? supportedEfforts.includes('high')
|
|
456
|
+
? 'high'
|
|
457
|
+
: supportedEfforts.includes('medium')
|
|
458
|
+
? 'medium'
|
|
459
|
+
: supportedEfforts[0]
|
|
460
|
+
: undefined;
|
|
461
|
+
const summary = defaults?.reasoning_summary && caps.reasoningSummary ? defaults.reasoning_summary : undefined;
|
|
462
|
+
if (!effort && !summary)
|
|
463
|
+
return undefined;
|
|
464
|
+
return {
|
|
465
|
+
...(effort ? { effort } : {}),
|
|
466
|
+
...(summary ? { summary } : {}),
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function invalid(message = 'Invalid Provider configuration or selection') {
|
|
470
|
+
return new RuntimeError('INVALID_CONFIG', message);
|
|
471
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ModeLimitsConfig, RuntimeLimits } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
declare const budgetFields: {
|
|
4
|
+
readonly maxModelAttempts: "max_model_attempts";
|
|
5
|
+
readonly maxToolCalls: "max_tool_calls";
|
|
6
|
+
readonly maxSteps: "max_steps";
|
|
7
|
+
readonly maxTotalTokens: "max_total_tokens";
|
|
8
|
+
readonly subagentMaxModelAttempts: "subagent_max_model_attempts";
|
|
9
|
+
readonly wallTimeMs: "wall_time_ms";
|
|
10
|
+
readonly subagentWallTimeMs: "subagent_wall_time_ms";
|
|
11
|
+
};
|
|
12
|
+
type BudgetField = keyof typeof budgetFields;
|
|
13
|
+
type ConfiguredBudgetField = (typeof budgetFields)[BudgetField];
|
|
14
|
+
type ConfiguredRunBudget = Partial<Record<ConfiguredBudgetField, number | undefined>>;
|
|
15
|
+
type ConfiguredBudgetShape = Record<ConfiguredBudgetField, z.ZodOptional<ReturnType<typeof unlimitedInt>>>;
|
|
16
|
+
export declare function unlimitedInt(max?: number): z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"unlimited">, z.ZodNull]>, z.ZodTransform<number, number | "unlimited" | null>>;
|
|
17
|
+
export declare function configuredRunBudgetShape(maximums?: Required<ModeLimitsConfig>): ConfiguredBudgetShape;
|
|
18
|
+
export interface ModeBudgetLayers {
|
|
19
|
+
readonly defaults?: ModeLimitsConfig;
|
|
20
|
+
readonly overrides?: ModeLimitsConfig;
|
|
21
|
+
}
|
|
22
|
+
export declare function readConfiguredRunBudget(raw: ConfiguredRunBudget | undefined): ModeLimitsConfig;
|
|
23
|
+
export declare function resolveRunBudget(rawDefaults: ConfiguredRunBudget | undefined, modeBudget?: ModeBudgetLayers): Pick<RuntimeLimits, keyof ModeLimitsConfig>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DEFAULT_SUBAGENT_MAX_MODEL_ATTEMPTS, DEFAULT_SUBAGENT_WALL_TIME_MS, isLimited, } from '@saturn-universe/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const budgetFields = {
|
|
4
|
+
maxModelAttempts: 'max_model_attempts',
|
|
5
|
+
maxToolCalls: 'max_tool_calls',
|
|
6
|
+
maxSteps: 'max_steps',
|
|
7
|
+
maxTotalTokens: 'max_total_tokens',
|
|
8
|
+
subagentMaxModelAttempts: 'subagent_max_model_attempts',
|
|
9
|
+
wallTimeMs: 'wall_time_ms',
|
|
10
|
+
subagentWallTimeMs: 'subagent_wall_time_ms',
|
|
11
|
+
};
|
|
12
|
+
const budgetKeys = Object.keys(budgetFields);
|
|
13
|
+
export function unlimitedInt(max) {
|
|
14
|
+
const integer = z.number().int().min(0).safe();
|
|
15
|
+
return z
|
|
16
|
+
.union([max === undefined ? integer : integer.max(max), z.literal('unlimited'), z.null()])
|
|
17
|
+
.transform((value) => (value === 'unlimited' || value === null ? 0 : value));
|
|
18
|
+
}
|
|
19
|
+
export function configuredRunBudgetShape(maximums) {
|
|
20
|
+
return Object.fromEntries(budgetKeys.map((field) => [budgetFields[field], unlimitedInt(maximums?.[field]).optional()]));
|
|
21
|
+
}
|
|
22
|
+
export function readConfiguredRunBudget(raw) {
|
|
23
|
+
const budget = {};
|
|
24
|
+
for (const field of budgetKeys) {
|
|
25
|
+
const value = raw?.[budgetFields[field]];
|
|
26
|
+
if (value !== undefined)
|
|
27
|
+
budget[field] = value;
|
|
28
|
+
}
|
|
29
|
+
return budget;
|
|
30
|
+
}
|
|
31
|
+
export function resolveRunBudget(rawDefaults, modeBudget) {
|
|
32
|
+
const budget = {
|
|
33
|
+
...modeBudget?.defaults,
|
|
34
|
+
...readConfiguredRunBudget(rawDefaults),
|
|
35
|
+
...modeBudget?.overrides,
|
|
36
|
+
};
|
|
37
|
+
const { wallTimeMs } = budget;
|
|
38
|
+
return {
|
|
39
|
+
maxModelAttempts: budget.maxModelAttempts ?? 0,
|
|
40
|
+
maxToolCalls: budget.maxToolCalls ?? 0,
|
|
41
|
+
maxSteps: budget.maxSteps ?? 0,
|
|
42
|
+
maxTotalTokens: budget.maxTotalTokens ?? 0,
|
|
43
|
+
subagentMaxModelAttempts: budget.subagentMaxModelAttempts ?? DEFAULT_SUBAGENT_MAX_MODEL_ATTEMPTS,
|
|
44
|
+
...(isLimited(wallTimeMs) ? { wallTimeMs } : {}),
|
|
45
|
+
subagentWallTimeMs: budget.subagentWallTimeMs ?? DEFAULT_SUBAGENT_WALL_TIME_MS,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { canonicalJson } from '@saturn-universe/core';
|
|
2
|
+
import { modelToolOutcome } from '@saturn-universe/context';
|
|
3
|
+
export async function createRunCheckpoint(reader, input, prior) {
|
|
4
|
+
const surface = await reader.read(input.agentSessionId);
|
|
5
|
+
const messages = surface.items
|
|
6
|
+
.filter(({ active, message }) => active && message.turnId === input.turnId)
|
|
7
|
+
.map(({ message }) => message);
|
|
8
|
+
const calls = new Map(messages.flatMap((message) => message.role === 'assistant' ? message.toolCalls.map((call) => [call.id, call]) : []));
|
|
9
|
+
const results = messages.filter((message) => message.role === 'tool');
|
|
10
|
+
if (!results.some(({ result }) => result.outcome.status === 'success' || result.effect === 'applied'))
|
|
11
|
+
return;
|
|
12
|
+
const resultLines = results.map(({ result }) => {
|
|
13
|
+
const call = calls.get(result.toolCallId);
|
|
14
|
+
const args = call?.arguments.kind === 'json' ? clipped(canonicalJson(call.arguments.value), 130) : '';
|
|
15
|
+
const outcome = modelToolOutcome(result);
|
|
16
|
+
const excerpt = outcome.status === 'success'
|
|
17
|
+
? (outcome.content.find((part) => part.type === 'text')?.text ?? '')
|
|
18
|
+
: outcome.error.code;
|
|
19
|
+
return `${call?.toolName ?? 'tool'} ${args} [${result.effect}/${outcome.status}] id=${result.toolCallId} ${clipped(excerpt, 140)}`;
|
|
20
|
+
});
|
|
21
|
+
const lastNote = messages
|
|
22
|
+
.filter((m) => m.role === 'assistant')
|
|
23
|
+
.map(text)
|
|
24
|
+
.filter(Boolean)
|
|
25
|
+
.at(-1);
|
|
26
|
+
const summary = [
|
|
27
|
+
'A previous run reached a budget boundary. These are recorded observations. Continue the original task from completed work. Verify workspace state before attempting another write.',
|
|
28
|
+
...(prior ? [`Previous checkpoint excerpt: ${clipped(prior.summary, 576)}`] : []),
|
|
29
|
+
...(lastNote ? [`Last assistant observation: ${clipped(lastNote, 384)}`] : []),
|
|
30
|
+
`${results.length} tools settled in this run. Recent results (use read_tool_result for full results where available):`,
|
|
31
|
+
...resultLines.slice(-8),
|
|
32
|
+
].join('\n');
|
|
33
|
+
return {
|
|
34
|
+
sourceRunId: input.runId,
|
|
35
|
+
originalInputId: prior?.originalInputId ?? input.inputMessageId,
|
|
36
|
+
summary,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function clipped(value, limit) {
|
|
40
|
+
const bytes = Buffer.from(value);
|
|
41
|
+
return bytes.length <= limit
|
|
42
|
+
? value
|
|
43
|
+
: bytes
|
|
44
|
+
.subarray(0, limit)
|
|
45
|
+
.toString('utf8')
|
|
46
|
+
.replace(/\uFFFD$/, '') + '…';
|
|
47
|
+
}
|
|
48
|
+
function text(message) {
|
|
49
|
+
return message.role === 'tool'
|
|
50
|
+
? ''
|
|
51
|
+
: message.content.flatMap((part) => (part.type === 'text' ? [part.text] : [])).join('\n');
|
|
52
|
+
}
|