paracosm 0.7.471 → 0.7.475
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/dist/cli/cli-run-options.d.ts +1 -1
- package/dist/cli/cli-run-options.d.ts.map +1 -1
- package/dist/cli/cli-run-options.js.map +1 -1
- package/dist/cli/compile-cli-options.d.ts +1 -1
- package/dist/cli/compile-cli-options.d.ts.map +1 -1
- package/dist/cli/compile-cli-options.js.map +1 -1
- package/dist/cli/server-app.d.ts.map +1 -1
- package/dist/cli/server-app.js +57 -142
- package/dist/cli/server-app.js.map +1 -1
- package/dist/engine/compiler/generate-fingerprint.d.ts.map +1 -1
- package/dist/engine/compiler/generate-fingerprint.js +6 -3
- package/dist/engine/compiler/generate-fingerprint.js.map +1 -1
- package/dist/engine/compiler/generate-politics.d.ts.map +1 -1
- package/dist/engine/compiler/generate-politics.js +5 -2
- package/dist/engine/compiler/generate-politics.js.map +1 -1
- package/dist/engine/compiler/generate-progression.d.ts.map +1 -1
- package/dist/engine/compiler/generate-progression.js +8 -3
- package/dist/engine/compiler/generate-progression.js.map +1 -1
- package/dist/engine/compiler/generate-prompts.d.ts.map +1 -1
- package/dist/engine/compiler/generate-prompts.js +6 -3
- package/dist/engine/compiler/generate-prompts.js.map +1 -1
- package/dist/engine/compiler/generate-reactions.d.ts.map +1 -1
- package/dist/engine/compiler/generate-reactions.js +5 -2
- package/dist/engine/compiler/generate-reactions.js.map +1 -1
- package/dist/engine/compiler/index.d.ts.map +1 -1
- package/dist/engine/compiler/index.js +44 -14
- package/dist/engine/compiler/index.js.map +1 -1
- package/dist/engine/compiler/source-validation.d.ts +48 -0
- package/dist/engine/compiler/source-validation.d.ts.map +1 -0
- package/dist/engine/compiler/source-validation.js +60 -0
- package/dist/engine/compiler/source-validation.js.map +1 -0
- package/dist/runtime/orchestrator.js +1 -1
- package/dist/runtime/orchestrator.js.map +1 -1
- package/dist/runtime/trait-cues/trajectory.d.ts +8 -2
- package/dist/runtime/trait-cues/trajectory.d.ts.map +1 -1
- package/dist/runtime/trait-cues/trajectory.js +1 -0
- package/dist/runtime/trait-cues/trajectory.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,5 +7,5 @@ export interface CliRunOptions {
|
|
|
7
7
|
provider?: LlmProvider;
|
|
8
8
|
models?: Partial<SimulationModelConfig>;
|
|
9
9
|
}
|
|
10
|
-
export declare function parseCliRunOptions(argv: string[]): CliRunOptions;
|
|
10
|
+
export declare function parseCliRunOptions(argv: readonly string[]): CliRunOptions;
|
|
11
11
|
//# sourceMappingURL=cli-run-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-run-options.d.ts","sourceRoot":"","sources":["../../src/cli/cli-run-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACzC;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"cli-run-options.d.ts","sourceRoot":"","sources":["../../src/cli/cli-run-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACzC;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,CAwCzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-run-options.js","sourceRoot":"","sources":["../../src/cli/cli-run-options.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"cli-run-options.js","sourceRoot":"","sources":["../../src/cli/cli-run-options.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,kBAAkB,CAAC,IAAuB;IACxD,MAAM,OAAO,GAAkB,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAErD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAExB,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC5D,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACvC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;YACrD,SAAS;QACX,CAAC;QAED,QAAQ,GAAG,EAAE,CAAC;YACZ,KAAK,QAAQ;gBACX,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;gBAC1B,MAAM;YACR,KAAK,QAAQ;gBACX,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBACxD,MAAM;YACR,KAAK,cAAc;gBACjB,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC7D,MAAM;YACR,KAAK,YAAY;gBACf,OAAO,CAAC,QAAQ,GAAI,IAAI,CAAC,EAAE,KAAK,CAA6B,CAAC;gBAC9D,MAAM;YACR,KAAK,mBAAmB;gBACtB,OAAO,CAAC,MAAM,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;gBACzE,MAAM;YACR,KAAK,oBAAoB;gBACvB,OAAO,CAAC,MAAM,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;gBAC3E,MAAM;YACR,KAAK,eAAe;gBAClB,OAAO,CAAC,MAAM,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;gBACrE,MAAM;YACR;gBACE,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -10,5 +10,5 @@ export interface CompileCliOptions {
|
|
|
10
10
|
webSearch: boolean;
|
|
11
11
|
maxSearches?: number;
|
|
12
12
|
}
|
|
13
|
-
export declare function parseCompileCliOptions(argv: string[]): CompileCliOptions;
|
|
13
|
+
export declare function parseCompileCliOptions(argv: readonly string[]): CompileCliOptions;
|
|
14
14
|
//# sourceMappingURL=compile-cli-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-cli-options.d.ts","sourceRoot":"","sources":["../../src/cli/compile-cli-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"compile-cli-options.d.ts","sourceRoot":"","sources":["../../src/cli/compile-cli-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,iBAAiB,CAkDjF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-cli-options.js","sourceRoot":"","sources":["../../src/cli/compile-cli-options.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,sBAAsB,CAAC,
|
|
1
|
+
{"version":3,"file":"compile-cli-options.js","sourceRoot":"","sources":["../../src/cli/compile-cli-options.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,sBA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AC;gBAC1B,MAAM;YACR,KAAK,gBAAgB,CAAC,CAAC,CAAC;gBACtB,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBACvD,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;gBACjE,MAAM;YACR,CAAC;YACD;gBACE,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-app.d.ts","sourceRoot":"","sources":["../../src/cli/server-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,MAAM,EAAuB,MAAM,WAAW,CAAC;AAIjG,OAAO,EAA4C,KAAK,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EAA8D,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAShH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"server-app.d.ts","sourceRoot":"","sources":["../../src/cli/server-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,MAAM,EAAuB,MAAM,WAAW,CAAC;AAIjG,OAAO,EAA4C,KAAK,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EAA8D,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAShH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAuB1D,OAAO,EAAoB,KAAK,YAAY,EAAyB,MAAM,oBAAoB,CAAC;AAKhG,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAmGhG,MAAM,WAAW,uBAAuB;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC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AC,EAAE,MAAM,CAAC;YAAC,OAAO,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;YAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,CAAC;YAAC,SAAS,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;wBAC3L,KAAK,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC;YAAC,cAAc,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;oBAC3F,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;0BACxB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;;;EAoEnD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,UAAU,CAi0DlF"}
|
package/dist/cli/server-app.js
CHANGED
|
@@ -9,6 +9,7 @@ import { handleSimulate } from './simulate-route.js';
|
|
|
9
9
|
import { compileScenario as compileScenarioReal } from '../engine/compiler/index.js';
|
|
10
10
|
import { marsScenario } from '../engine/mars/index.js';
|
|
11
11
|
import { lunarScenario } from '../engine/lunar/index.js';
|
|
12
|
+
import { hasProviderCredentials, normalizeCredential, resolveProviderFromCredentials, } from '../engine/provider-credentials.js';
|
|
12
13
|
import { describeCustomScenarioSource, isRunnableScenarioPackage, loadDiskCustomScenarios, } from './custom-scenarios.js';
|
|
13
14
|
import { IpRateLimiter } from './rate-limiter.js';
|
|
14
15
|
import { aggregateSchemaRetries, aggregateForgeStats, aggregateCacheStats, aggregateProviderErrors, } from './retry-stats.js';
|
|
@@ -948,8 +949,17 @@ export function createMarsServer(options = {}) {
|
|
|
948
949
|
return customScenarioCatalog.get(id)?.scenario;
|
|
949
950
|
},
|
|
950
951
|
fetchSeedFromUrl,
|
|
951
|
-
|
|
952
|
-
|
|
952
|
+
// Default to OpenAI to match compileScenario's existing
|
|
953
|
+
// default (compiler/index.ts:162) and the codebase's
|
|
954
|
+
// default-to-openai posture. The quickstart SeedInput form
|
|
955
|
+
// does not yet collect user-supplied keys, so this default
|
|
956
|
+
// is what hosted prod hits when the user does not override.
|
|
957
|
+
// Self-hosted deployments can change this at the call site
|
|
958
|
+
// (or pass `defaultProvider` from a custom server).
|
|
959
|
+
// `inferProviderFromCredentials` still honors single-key
|
|
960
|
+
// intent when only one of OPENAI/ANTHROPIC is in env.
|
|
961
|
+
defaultProvider: 'openai',
|
|
962
|
+
defaultModel: 'gpt-5.4-mini',
|
|
953
963
|
};
|
|
954
964
|
if (req.url === '/api/quickstart/fetch-seed') {
|
|
955
965
|
await handleFetchSeed(req, res, body, quickstartDeps);
|
|
@@ -982,7 +992,11 @@ export function createMarsServer(options = {}) {
|
|
|
982
992
|
const body = JSON.parse(await readBody(req, maxRequestBodyBytes));
|
|
983
993
|
const userApiKey = typeof req.headers['x-api-key'] === 'string' ? req.headers['x-api-key'] : undefined;
|
|
984
994
|
const userAnthropicKey = typeof req.headers['x-anthropic-key'] === 'string' ? req.headers['x-anthropic-key'] : undefined;
|
|
985
|
-
const
|
|
995
|
+
const simulateCredentials = {
|
|
996
|
+
apiKey: normalizeCredential(userApiKey),
|
|
997
|
+
anthropicKey: normalizeCredential(userAnthropicKey),
|
|
998
|
+
};
|
|
999
|
+
const hasUserKeys = hasProviderCredentials(simulateCredentials);
|
|
986
1000
|
// Rate limit with BYO-key bypass, matching the /setup pattern.
|
|
987
1001
|
// `.check()` alone is advisory; `.record()` consumes the slot.
|
|
988
1002
|
if (rateLimiter && !hasUserKeys) {
|
|
@@ -1009,29 +1023,6 @@ export function createMarsServer(options = {}) {
|
|
|
1009
1023
|
else if (hasUserKeys) {
|
|
1010
1024
|
console.log(` [rate-limit] /simulate bypassed. BYO key present.`);
|
|
1011
1025
|
}
|
|
1012
|
-
// Scope user-supplied API keys into the env for the duration of
|
|
1013
|
-
// the simulate call. The orchestrator's downstream LLM providers
|
|
1014
|
-
// read `process.env.OPENAI_API_KEY` / `ANTHROPIC_API_KEY`; passing
|
|
1015
|
-
// the keys through `RunOptions` does nothing because RunOptions
|
|
1016
|
-
// does not declare those fields. Mirrors the inline `scopeKey`
|
|
1017
|
-
// pattern used at the /setup handler around line 1732.
|
|
1018
|
-
const simulateEnvSnapshot = [];
|
|
1019
|
-
const scopeSimulateKey = (envName, userValue) => {
|
|
1020
|
-
if (!userValue || userValue.includes('...'))
|
|
1021
|
-
return;
|
|
1022
|
-
simulateEnvSnapshot.push([envName, env[envName]]);
|
|
1023
|
-
env[envName] = userValue;
|
|
1024
|
-
};
|
|
1025
|
-
scopeSimulateKey('OPENAI_API_KEY', userApiKey);
|
|
1026
|
-
scopeSimulateKey('ANTHROPIC_API_KEY', userAnthropicKey);
|
|
1027
|
-
const restoreSimulateEnv = () => {
|
|
1028
|
-
for (const [name, prior] of simulateEnvSnapshot) {
|
|
1029
|
-
if (prior === undefined)
|
|
1030
|
-
delete env[name];
|
|
1031
|
-
else
|
|
1032
|
-
env[name] = prior;
|
|
1033
|
-
}
|
|
1034
|
-
};
|
|
1035
1026
|
const deps = {
|
|
1036
1027
|
compileScenario: (raw, opts) => {
|
|
1037
1028
|
const userCompile = options.compileScenario;
|
|
@@ -1044,12 +1035,7 @@ export function createMarsServer(options = {}) {
|
|
|
1044
1035
|
return runSimulation(leader, keyPersonnel, runOpts);
|
|
1045
1036
|
},
|
|
1046
1037
|
};
|
|
1047
|
-
|
|
1048
|
-
await handleSimulate(req, res, body, deps);
|
|
1049
|
-
}
|
|
1050
|
-
finally {
|
|
1051
|
-
restoreSimulateEnv();
|
|
1052
|
-
}
|
|
1038
|
+
await handleSimulate(req, res, body, deps, simulateCredentials);
|
|
1053
1039
|
}
|
|
1054
1040
|
catch (err) {
|
|
1055
1041
|
writeJsonError(res, err);
|
|
@@ -1066,13 +1052,17 @@ export function createMarsServer(options = {}) {
|
|
|
1066
1052
|
res.end(JSON.stringify({ error: 'scenario JSON object required' }));
|
|
1067
1053
|
return;
|
|
1068
1054
|
}
|
|
1055
|
+
const compileCredentials = {
|
|
1056
|
+
apiKey: normalizeCredential(apiKey),
|
|
1057
|
+
anthropicKey: normalizeCredential(anthropicKey),
|
|
1058
|
+
};
|
|
1069
1059
|
// Rate-limit compile against its own daily bucket. Each compile
|
|
1070
1060
|
// costs ~$0.10 against the host's API key, so even 10 uncontrolled
|
|
1071
1061
|
// hits is a real line item. Bypassed when the caller is not
|
|
1072
1062
|
// billing the host: either a session key was supplied, or the
|
|
1073
1063
|
// server is in local mode (PARACOSM_HOSTED_DEMO unset) where
|
|
1074
1064
|
// env keys belong to the operator.
|
|
1075
|
-
const userSuppliedKey =
|
|
1065
|
+
const userSuppliedKey = hasProviderCredentials(compileCredentials);
|
|
1076
1066
|
const isHostedDemoCompile = serverMode === 'hosted_demo';
|
|
1077
1067
|
const hostBilled = !userSuppliedKey && isHostedDemoCompile;
|
|
1078
1068
|
if (rateLimiter && hostBilled) {
|
|
@@ -1095,30 +1085,8 @@ export function createMarsServer(options = {}) {
|
|
|
1095
1085
|
}
|
|
1096
1086
|
console.log(` [rate-limit] /compile ${ip}: ${remaining} remaining of ${limit}`);
|
|
1097
1087
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
// snapshotted + restored after the compile completes so they don't
|
|
1101
|
-
// leak into subsequent unrelated requests. Placeholder values
|
|
1102
|
-
// (e.g. "sk-...") are ignored so a masked display string never
|
|
1103
|
-
// replaces a real key.
|
|
1104
|
-
const compileEnvSnapshot = [];
|
|
1105
|
-
const scopeCompileKey = (name, value) => {
|
|
1106
|
-
if (typeof value !== 'string' || !value || value.includes('...'))
|
|
1107
|
-
return;
|
|
1108
|
-
compileEnvSnapshot.push([name, env[name]]);
|
|
1109
|
-
env[name] = value;
|
|
1110
|
-
};
|
|
1111
|
-
scopeCompileKey('OPENAI_API_KEY', apiKey);
|
|
1112
|
-
scopeCompileKey('ANTHROPIC_API_KEY', anthropicKey);
|
|
1113
|
-
const restoreCompileEnv = () => {
|
|
1114
|
-
for (const [name, prior] of compileEnvSnapshot) {
|
|
1115
|
-
if (prior === undefined)
|
|
1116
|
-
delete env[name];
|
|
1117
|
-
else
|
|
1118
|
-
env[name] = prior;
|
|
1119
|
-
}
|
|
1120
|
-
};
|
|
1121
|
-
const provider = requestedProvider || (env.ANTHROPIC_API_KEY ? 'anthropic' : 'openai');
|
|
1088
|
+
const envDefaultProvider = env.ANTHROPIC_API_KEY && !env.OPENAI_API_KEY ? 'anthropic' : 'openai';
|
|
1089
|
+
const provider = resolveProviderFromCredentials(requestedProvider, compileCredentials, envDefaultProvider);
|
|
1122
1090
|
// Force the cheapest class only when the host is billing
|
|
1123
1091
|
// (hosted-demo mode + no session key). Local dev and BYO-key
|
|
1124
1092
|
// paths honor the requested model.
|
|
@@ -1147,25 +1115,21 @@ export function createMarsServer(options = {}) {
|
|
|
1147
1115
|
},
|
|
1148
1116
|
snapshot: () => baseCompileTelemetry.snapshot(),
|
|
1149
1117
|
};
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1166
|
-
finally {
|
|
1167
|
-
restoreCompileEnv();
|
|
1168
|
-
}
|
|
1118
|
+
const compiled = await runCompileScenario(scenarioJson, {
|
|
1119
|
+
provider,
|
|
1120
|
+
model,
|
|
1121
|
+
cache: true,
|
|
1122
|
+
seedText,
|
|
1123
|
+
seedUrl,
|
|
1124
|
+
webSearch: webSearch ?? true,
|
|
1125
|
+
maxSearches,
|
|
1126
|
+
apiKey: compileCredentials.apiKey,
|
|
1127
|
+
anthropicKey: compileCredentials.anthropicKey,
|
|
1128
|
+
telemetry: compileTelemetry,
|
|
1129
|
+
onProgress(hookName, status) {
|
|
1130
|
+
res.write(`event: progress\ndata: ${JSON.stringify({ hook: hookName, status })}\n\n`);
|
|
1131
|
+
},
|
|
1132
|
+
});
|
|
1169
1133
|
// Update the active scenario for GET /scenario
|
|
1170
1134
|
activeScenario = compiled;
|
|
1171
1135
|
memoryScenarios.set(compiled.id, compiled);
|
|
@@ -1224,19 +1188,6 @@ export function createMarsServer(options = {}) {
|
|
|
1224
1188
|
// Rate limit status endpoint
|
|
1225
1189
|
// Post-simulation colonist chat
|
|
1226
1190
|
if (req.url === '/chat' && req.method === 'POST') {
|
|
1227
|
-
// Hoist env-scoping helpers OUTSIDE the try so the catch can
|
|
1228
|
-
// still call restoreChatEnv. Without this, an exception thrown
|
|
1229
|
-
// between scopeChatKey() and the inner restore would leak the
|
|
1230
|
-
// caller's keys into subsequent requests.
|
|
1231
|
-
const chatEnvSnapshot = [];
|
|
1232
|
-
const restoreChatEnv = () => {
|
|
1233
|
-
for (const [name, prior] of chatEnvSnapshot) {
|
|
1234
|
-
if (prior === undefined)
|
|
1235
|
-
delete env[name];
|
|
1236
|
-
else
|
|
1237
|
-
env[name] = prior;
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
1191
|
try {
|
|
1241
1192
|
const { agentId, message, apiKey, anthropicKey } = JSON.parse(await readBody(req, maxRequestBodyBytes));
|
|
1242
1193
|
if (!agentId || !message) {
|
|
@@ -1244,19 +1195,11 @@ export function createMarsServer(options = {}) {
|
|
|
1244
1195
|
res.end(JSON.stringify({ error: 'agentId and message required' }));
|
|
1245
1196
|
return;
|
|
1246
1197
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
// rejected so a displayed masked string never replaces a real key.
|
|
1251
|
-
const chatUserKey = !!(apiKey || anthropicKey);
|
|
1252
|
-
const scopeChatKey = (name, value) => {
|
|
1253
|
-
if (typeof value !== 'string' || !value || value.includes('...'))
|
|
1254
|
-
return;
|
|
1255
|
-
chatEnvSnapshot.push([name, env[name]]);
|
|
1256
|
-
env[name] = value;
|
|
1198
|
+
const chatCredentials = {
|
|
1199
|
+
apiKey: normalizeCredential(apiKey),
|
|
1200
|
+
anthropicKey: normalizeCredential(anthropicKey),
|
|
1257
1201
|
};
|
|
1258
|
-
|
|
1259
|
-
scopeChatKey('ANTHROPIC_API_KEY', anthropicKey);
|
|
1202
|
+
const chatUserKey = hasProviderCredentials(chatCredentials);
|
|
1260
1203
|
// Rate-limit chat per IP per hour. Runs against the host's
|
|
1261
1204
|
// key unless a session key was provided in the request body,
|
|
1262
1205
|
// in which case the caller is paying and the cap is bypassed
|
|
@@ -1334,16 +1277,18 @@ export function createMarsServer(options = {}) {
|
|
|
1334
1277
|
// confabulates fake bios for any name the user invents.
|
|
1335
1278
|
const roster = extractColonistRoster(simEvents);
|
|
1336
1279
|
// Get or create the agent (lazy init with memory seeding)
|
|
1337
|
-
const
|
|
1280
|
+
const envDefaultProvider = env.ANTHROPIC_API_KEY && !env.OPENAI_API_KEY ? 'anthropic' : 'openai';
|
|
1281
|
+
const provider = resolveProviderFromCredentials(simConfig?.provider, chatCredentials, envDefaultProvider);
|
|
1338
1282
|
const { session, isNew } = await getOrCreateChatAgent(profile, memories, {
|
|
1339
1283
|
provider,
|
|
1284
|
+
apiKey: chatCredentials.apiKey,
|
|
1285
|
+
anthropicKey: chatCredentials.anthropicKey,
|
|
1340
1286
|
settlementNoun: activeScenario.labels?.settlementNoun,
|
|
1341
1287
|
populationNoun: activeScenario.labels?.populationNoun,
|
|
1342
1288
|
roster,
|
|
1343
1289
|
});
|
|
1344
1290
|
// Send message through the agent session (full history + memory + RAG automatic)
|
|
1345
1291
|
const result = await session.send(message);
|
|
1346
|
-
restoreChatEnv();
|
|
1347
1292
|
// Surface per-turn token usage + cost so the dashboard footer
|
|
1348
1293
|
// can fold chat spend into the run-total display. Without this,
|
|
1349
1294
|
// the cost readout only reflected the simulation pipeline and
|
|
@@ -1366,13 +1311,6 @@ export function createMarsServer(options = {}) {
|
|
|
1366
1311
|
}));
|
|
1367
1312
|
}
|
|
1368
1313
|
catch (err) {
|
|
1369
|
-
// Restore env on error path too — mutations happened before
|
|
1370
|
-
// whatever threw. Without this, a failed chat call leaves the
|
|
1371
|
-
// caller's keys persisted in env for subsequent requests.
|
|
1372
|
-
try {
|
|
1373
|
-
restoreChatEnv();
|
|
1374
|
-
}
|
|
1375
|
-
catch { }
|
|
1376
1314
|
writeJsonError(res, err, 500);
|
|
1377
1315
|
}
|
|
1378
1316
|
return;
|
|
@@ -1593,8 +1531,12 @@ export function createMarsServer(options = {}) {
|
|
|
1593
1531
|
if (req.url === '/setup' && req.method === 'POST') {
|
|
1594
1532
|
try {
|
|
1595
1533
|
const config = JSON.parse(await readBody(req, maxRequestBodyBytes));
|
|
1596
|
-
// Rate limit check: bypass when user provides
|
|
1597
|
-
const
|
|
1534
|
+
// Rate limit check: bypass when user provides real API keys.
|
|
1535
|
+
const requestCredentials = {
|
|
1536
|
+
apiKey: normalizeCredential(config.apiKey),
|
|
1537
|
+
anthropicKey: normalizeCredential(config.anthropicKey),
|
|
1538
|
+
};
|
|
1539
|
+
const hasUserKeys = hasProviderCredentials(requestCredentials);
|
|
1598
1540
|
if (rateLimiter && !hasUserKeys) {
|
|
1599
1541
|
const ip = IpRateLimiter.getIp(req);
|
|
1600
1542
|
const { allowed, remaining, limit } = rateLimiter.check(ip);
|
|
@@ -1716,32 +1658,6 @@ export function createMarsServer(options = {}) {
|
|
|
1716
1658
|
console.warn('[run-history] per-artifact insert failed:', error);
|
|
1717
1659
|
}
|
|
1718
1660
|
};
|
|
1719
|
-
// Key-scope safety: snapshot the env values we're about to mutate
|
|
1720
|
-
// so we can restore them when THIS sim ends. Without this, user A's
|
|
1721
|
-
// key persists in process.env after their sim completes; user B's
|
|
1722
|
-
// subsequent sim then silently uses A's key if B didn't provide one.
|
|
1723
|
-
// The restore runs in the startWithConfig().finally() below.
|
|
1724
|
-
const envKeysToRestore = [];
|
|
1725
|
-
const scopeKey = (envName, userValue) => {
|
|
1726
|
-
if (!userValue || userValue.includes('...'))
|
|
1727
|
-
return;
|
|
1728
|
-
envKeysToRestore.push([envName, env[envName]]);
|
|
1729
|
-
env[envName] = userValue;
|
|
1730
|
-
};
|
|
1731
|
-
scopeKey('OPENAI_API_KEY', simConfig.apiKey);
|
|
1732
|
-
scopeKey('ANTHROPIC_API_KEY', simConfig.anthropicKey);
|
|
1733
|
-
scopeKey('SERPER_API_KEY', simConfig.serperKey);
|
|
1734
|
-
scopeKey('FIRECRAWL_API_KEY', simConfig.firecrawlKey);
|
|
1735
|
-
scopeKey('TAVILY_API_KEY', simConfig.tavilyKey);
|
|
1736
|
-
scopeKey('COHERE_API_KEY', simConfig.cohereKey);
|
|
1737
|
-
const restoreEnv = () => {
|
|
1738
|
-
for (const [name, prior] of envKeysToRestore) {
|
|
1739
|
-
if (prior === undefined)
|
|
1740
|
-
delete env[name];
|
|
1741
|
-
else
|
|
1742
|
-
env[name] = prior;
|
|
1743
|
-
}
|
|
1744
|
-
};
|
|
1745
1661
|
// If a run is already in flight, abort it before starting the
|
|
1746
1662
|
// new one. Previously /setup silently no-op'd on simRunning,
|
|
1747
1663
|
// which left the old sim draining API credits while the user
|
|
@@ -1776,10 +1692,9 @@ export function createMarsServer(options = {}) {
|
|
|
1776
1692
|
departments: activeScenario.departments?.length ?? 0,
|
|
1777
1693
|
});
|
|
1778
1694
|
console.log(` Running scenario: "${activeScenario.labels?.name ?? activeScenario.id}" (${activeScenario.id})`);
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
marsServer.startWithConfig(simConfig, { onArtifact: onArtifactPersist }).finally(restoreEnv);
|
|
1695
|
+
marsServer.startWithConfig(simConfig, { onArtifact: onArtifactPersist }).catch((error) => {
|
|
1696
|
+
console.warn('[setup] simulation failed:', error);
|
|
1697
|
+
});
|
|
1783
1698
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1784
1699
|
res.end(JSON.stringify({
|
|
1785
1700
|
redirect: '/sim',
|