paracosm 0.7.450 → 0.7.455
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 +2 -2
- package/dist/engine/compiler/compile-from-seed.d.ts +12 -3
- package/dist/engine/compiler/compile-from-seed.d.ts.map +1 -1
- package/dist/engine/compiler/compile-from-seed.js +72 -22
- package/dist/engine/compiler/compile-from-seed.js.map +1 -1
- package/dist/engine/provider-credentials.d.ts +40 -0
- package/dist/engine/provider-credentials.d.ts.map +1 -0
- package/dist/engine/provider-credentials.js +58 -0
- package/dist/engine/provider-credentials.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -465,9 +465,9 @@ Non-SSE consumers (curl, Python integrations, third-party dashboards) can run a
|
|
|
465
465
|
|
|
466
466
|
```bash
|
|
467
467
|
export PARACOSM_ENABLE_SIMULATE_ENDPOINT=true
|
|
468
|
-
|
|
468
|
+
paracosm dashboard # or bring up your own server via createMarsServer
|
|
469
469
|
|
|
470
|
-
curl -s -X POST http://localhost:
|
|
470
|
+
curl -s -X POST http://localhost:3456/simulate \
|
|
471
471
|
-H 'Content-Type: application/json' \
|
|
472
472
|
-H 'X-Anthropic-Key: sk-ant-...' \
|
|
473
473
|
-d '{
|
|
@@ -69,10 +69,19 @@ export interface CompileFromSeedOptions extends CompileOptions {
|
|
|
69
69
|
* the existing `compileScenario` pipeline with `seedText` threading
|
|
70
70
|
* through for research grounding.
|
|
71
71
|
*
|
|
72
|
-
* Retries
|
|
73
|
-
*
|
|
72
|
+
* Retries up to 3 times on Zod-validation failure. The first failure
|
|
73
|
+
* usually surfaces as an off-bound numeric (defaultPopulation pasted
|
|
74
|
+
* from a real-world headcount) or a non-kebab id; the explicit
|
|
75
|
+
* constraints in DRAFT_SYSTEM_PROMPT plus the retry budget recover
|
|
76
|
+
* cleanly in practice.
|
|
74
77
|
*
|
|
75
|
-
*
|
|
78
|
+
* Wraps ObjectGenerationError with a more actionable message that
|
|
79
|
+
* preserves the raw model output so the caller can see what the LLM
|
|
80
|
+
* tried to produce.
|
|
81
|
+
*
|
|
82
|
+
* @throws Error when the LLM fails to produce a valid draft after the
|
|
83
|
+
* retry budget is exhausted. Wraps any ObjectGenerationError so the
|
|
84
|
+
* message names the field bounds that likely tripped validation.
|
|
76
85
|
*/
|
|
77
86
|
export declare function compileFromSeed(input: CompileFromSeedInput, options?: CompileFromSeedOptions): Promise<ScenarioPackage>;
|
|
78
87
|
//# sourceMappingURL=compile-from-seed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-from-seed.d.ts","sourceRoot":"","sources":["../../../src/engine/compiler/compile-from-seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"compile-from-seed.d.ts","sourceRoot":"","sources":["../../../src/engine/compiler/compile-from-seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0B9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,wEAAwE;AACxE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA0CD,4FAA4F;AAC5F,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0FAA0F;IAC1F,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,oBAAoB,EAC3B,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,eAAe,CAAC,CAwC1B"}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { z } from 'zod';
|
|
14
14
|
import { compileScenario } from './index.js';
|
|
15
|
+
import { apiKeyForProvider, resolveProviderFromCredentials } from '../provider-credentials.js';
|
|
15
16
|
import { generateValidatedObject } from '../../runtime/llm-invocations/generateValidatedObject.js';
|
|
16
17
|
/**
|
|
17
18
|
* The subset of a scenario JSON the LLM is asked to propose. Lean on
|
|
@@ -46,41 +47,90 @@ export const DraftScenarioSchema = z.object({
|
|
|
46
47
|
theme: z.string().min(10).max(400).optional(),
|
|
47
48
|
});
|
|
48
49
|
/**
|
|
49
|
-
* LLM system prompt for draft generation. Emphasizes
|
|
50
|
-
*
|
|
51
|
-
*
|
|
50
|
+
* LLM system prompt for draft generation. Emphasizes domain fit AND
|
|
51
|
+
* names every numeric / format constraint enforced by
|
|
52
|
+
* DraftScenarioSchema so the LLM doesn't waste retries on validation
|
|
53
|
+
* failures the schema would have caught (real-world counts pasted
|
|
54
|
+
* verbatim into defaultPopulation, capitalized ids, instructions
|
|
55
|
+
* bursting past 400 chars, etc.).
|
|
52
56
|
*/
|
|
53
57
|
const DRAFT_SYSTEM_PROMPT = `You are a scenario architect for paracosm, a structured world-model simulator for AI agents.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
|
|
59
|
+
Given seed source material, propose a paracosm scenario JSON that matches the domain. The output is validated by Zod; producing any field outside the bounds below will be rejected.
|
|
60
|
+
|
|
61
|
+
DOMAIN NOUNS
|
|
62
|
+
- populationNoun (plural), settlementNoun (singular), timeUnitNoun (singular).
|
|
63
|
+
- Examples: submarine -> "crew" / "habitat" / "day". Corporate -> "employees" / "company" / "quarter". Space settlement -> "colonists" / "colony" / "year". Game studio -> "players" / "studio" / "week". Public health -> "residents" / "state" / "day".
|
|
64
|
+
|
|
65
|
+
ID FIELDS (id, departments[].id, metrics[].id)
|
|
66
|
+
- kebab-case ONLY: lowercase letters, digits, hyphens. Length 3-64 (top-level), 2-48 (department), 2-32 (metric).
|
|
67
|
+
- WRONG: "Stardrift Online", "Seasonal_Content". RIGHT: "stardrift-online", "seasonal-content".
|
|
68
|
+
|
|
69
|
+
SETUP
|
|
70
|
+
- defaultTurns: integer between 2 and 12. Pick 4-8 for most scenarios.
|
|
71
|
+
- defaultPopulation: integer between 10 and 1000. This is a REPRESENTATIVE SAMPLE the simulation will agentize, NOT real-world headcount. A 380,000-MAU MMO becomes defaultPopulation: 200. A nation of millions becomes defaultPopulation: 500. Never paste real counts here.
|
|
72
|
+
- defaultStartTime: integer appropriate for the domain (year for space, quarter index for corporate, day index for daily-cadence sims, etc.).
|
|
73
|
+
|
|
74
|
+
DEPARTMENTS (2-8 entries)
|
|
75
|
+
- label: 2-48 chars human-readable.
|
|
76
|
+
- role: 2-80 chars short title.
|
|
77
|
+
- instructions: 10-400 chars MAX. Keep terse and action-oriented.
|
|
78
|
+
|
|
79
|
+
METRICS (2-12 entries)
|
|
80
|
+
- format: one of "number", "percent", "currency".
|
|
81
|
+
- Pick the metrics the leader actually steers on, not every available stat.
|
|
82
|
+
|
|
83
|
+
LABELS
|
|
84
|
+
- name: 2-80 chars, prose-y title for the scenario as a whole.
|
|
85
|
+
- currency (optional): 1-16 chars, e.g. "USD".
|
|
86
|
+
|
|
87
|
+
Keep all labels natural language. Leave hooks, citations, and implementation details to downstream compilation.`;
|
|
59
88
|
/**
|
|
60
89
|
* Compile a scenario from seed source material. Calls the LLM to
|
|
61
90
|
* propose a `DraftScenario`, validates it via Zod, then routes into
|
|
62
91
|
* the existing `compileScenario` pipeline with `seedText` threading
|
|
63
92
|
* through for research grounding.
|
|
64
93
|
*
|
|
65
|
-
* Retries
|
|
66
|
-
*
|
|
94
|
+
* Retries up to 3 times on Zod-validation failure. The first failure
|
|
95
|
+
* usually surfaces as an off-bound numeric (defaultPopulation pasted
|
|
96
|
+
* from a real-world headcount) or a non-kebab id; the explicit
|
|
97
|
+
* constraints in DRAFT_SYSTEM_PROMPT plus the retry budget recover
|
|
98
|
+
* cleanly in practice.
|
|
67
99
|
*
|
|
68
|
-
*
|
|
100
|
+
* Wraps ObjectGenerationError with a more actionable message that
|
|
101
|
+
* preserves the raw model output so the caller can see what the LLM
|
|
102
|
+
* tried to produce.
|
|
103
|
+
*
|
|
104
|
+
* @throws Error when the LLM fails to produce a valid draft after the
|
|
105
|
+
* retry budget is exhausted. Wraps any ObjectGenerationError so the
|
|
106
|
+
* message names the field bounds that likely tripped validation.
|
|
69
107
|
*/
|
|
70
108
|
export async function compileFromSeed(input, options = {}) {
|
|
71
|
-
const provider = options.draftProvider ?? options.provider
|
|
109
|
+
const provider = resolveProviderFromCredentials((options.draftProvider ?? options.provider), options, 'anthropic');
|
|
72
110
|
const model = options.draftModel ?? options.model ?? 'claude-sonnet-4-6';
|
|
73
111
|
const hint = input.domainHint ? `\n\nDomain hint: ${input.domainHint}` : '';
|
|
74
|
-
const prompt = `Seed source material:\n"""\n${input.seedText}\n"""${hint}\n\nRespond with a scenario JSON that matches DraftScenarioSchema.`;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
const prompt = `Seed source material:\n"""\n${input.seedText}\n"""${hint}\n\nRespond with a scenario JSON that matches DraftScenarioSchema. Remember: defaultPopulation must be 10-1000 (representative sample, NOT the real-world headcount from the seed). All ids must be kebab-case. Department instructions must be 10-400 chars.`;
|
|
113
|
+
let result;
|
|
114
|
+
try {
|
|
115
|
+
result = await generateValidatedObject({
|
|
116
|
+
provider,
|
|
117
|
+
model,
|
|
118
|
+
schema: DraftScenarioSchema,
|
|
119
|
+
schemaName: 'DraftScenario',
|
|
120
|
+
systemCacheable: DRAFT_SYSTEM_PROMPT,
|
|
121
|
+
prompt,
|
|
122
|
+
maxRetries: 3,
|
|
123
|
+
apiKey: apiKeyForProvider(provider, options),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
const rawText = err.rawText;
|
|
128
|
+
const baseMessage = err instanceof Error ? err.message : String(err);
|
|
129
|
+
const failureHint = ' (common cause: defaultPopulation > 1000 from a real-world count, or a non-kebab id like "Stardrift Online")';
|
|
130
|
+
const wrapped = new Error(`compileFromSeed: ${baseMessage}.${failureHint}${rawText ? `\nLast LLM raw output:\n${rawText.slice(0, 800)}` : ''}`);
|
|
131
|
+
wrapped.cause = err;
|
|
132
|
+
throw wrapped;
|
|
133
|
+
}
|
|
84
134
|
// Route the validated draft into the existing compiler with
|
|
85
135
|
// seedText grounding so the research + hook-generation stages
|
|
86
136
|
// still pull citations and generate TypeScript.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-from-seed.js","sourceRoot":"","sources":["../../../src/engine/compiler/compile-from-seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0DAA0D,CAAC;AAEnG;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAA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CAAC,CAAC,2BAA2B,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/I,OAAuC,CAAC,KAAK,GAAG,GAAG,CAAC;QACrD,MAAM,OAAO,CAAC;IAChB,CAAC;IAED,4DAA4D;IAC5D,8DAA8D;IAC9D,gDAAgD;IAChD,OAAO,eAAe,CAAC,MAAM,CAAC,MAA4C,EAAE;QAC1E,GAAG,OAAO;QACV,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE,KAAK,CAAC,SAAS;KACzB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { LlmProvider } from './types.js';
|
|
2
|
+
/** Provider credentials accepted by hosted routes and runtime calls. */
|
|
3
|
+
export interface ProviderCredentialOptions {
|
|
4
|
+
/** OpenAI API key. Historical dashboard field name. */
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
/** Anthropic API key. */
|
|
7
|
+
anthropicKey?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Search-provider credentials accepted by setup/run paths. */
|
|
10
|
+
export interface SearchCredentialOptions {
|
|
11
|
+
serperKey?: string;
|
|
12
|
+
firecrawlKey?: string;
|
|
13
|
+
tavilyKey?: string;
|
|
14
|
+
braveKey?: string;
|
|
15
|
+
cohereKey?: string;
|
|
16
|
+
}
|
|
17
|
+
export type RuntimeCredentialOptions = ProviderCredentialOptions & SearchCredentialOptions;
|
|
18
|
+
/**
|
|
19
|
+
* Return a usable secret or undefined for empty and masked placeholder
|
|
20
|
+
* values. The dashboard persists masks such as "sk-..."; those must
|
|
21
|
+
* never replace a real server-side key.
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeCredential(value: unknown): string | undefined;
|
|
24
|
+
/** True when either supported LLM provider has a real explicit key. */
|
|
25
|
+
export declare function hasProviderCredentials(credentials: ProviderCredentialOptions): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Infer provider from explicit keys. A single real key is treated as
|
|
28
|
+
* user intent; when both are present, the caller's provider selection
|
|
29
|
+
* remains authoritative.
|
|
30
|
+
*/
|
|
31
|
+
export declare function inferProviderFromCredentials(credentials: ProviderCredentialOptions): LlmProvider | undefined;
|
|
32
|
+
/** Resolve provider, preferring unambiguous explicit-key intent. */
|
|
33
|
+
export declare function resolveProviderFromCredentials(requested: LlmProvider | undefined, credentials: ProviderCredentialOptions, fallback?: LlmProvider): LlmProvider;
|
|
34
|
+
/** Return the explicit API key for the selected provider, if present. */
|
|
35
|
+
export declare function apiKeyForProvider(provider: LlmProvider, credentials: ProviderCredentialOptions): string | undefined;
|
|
36
|
+
/** Stable non-secret identity for cache keys that must vary by credential. */
|
|
37
|
+
export declare function credentialFingerprint(value: string | undefined): string;
|
|
38
|
+
/** Explicit search key first, then host env fallback. */
|
|
39
|
+
export declare function searchCredential(explicitValue: unknown, envName: string, env?: NodeJS.ProcessEnv | undefined): string | undefined;
|
|
40
|
+
//# sourceMappingURL=provider-credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-credentials.d.ts","sourceRoot":"","sources":["../../src/engine/provider-credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,wEAAwE;AACxE,MAAM,WAAW,yBAAyB;IACxC,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,+DAA+D;AAC/D,MAAM,WAAW,uBAAuB;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,wBAAwB,GAAG,yBAAyB,GAAG,uBAAuB,CAAC;AAE3F;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKtE;AAED,uEAAuE;AACvE,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,yBAAyB,GAAG,OAAO,CAEtF;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,yBAAyB,GACrC,WAAW,GAAG,SAAS,CAMzB;AAED,oEAAoE;AACpE,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,WAAW,GAAG,SAAS,EAClC,WAAW,EAAE,yBAAyB,EACtC,QAAQ,GAAE,WAAsB,GAC/B,WAAW,CAEb;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,WAAW,EACrB,WAAW,EAAE,yBAAyB,GACrC,MAAM,GAAG,SAAS,CAIpB;AAED,8EAA8E;AAC9E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CASvE;AAED,yDAAyD;AACzD,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,OAAO,EACtB,OAAO,EAAE,MAAM,EACf,GAAG,GAAE,MAAM,CAAC,UAAU,GAAG,SAAoE,GAC5F,MAAM,GAAG,SAAS,CAEpB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return a usable secret or undefined for empty and masked placeholder
|
|
3
|
+
* values. The dashboard persists masks such as "sk-..."; those must
|
|
4
|
+
* never replace a real server-side key.
|
|
5
|
+
*/
|
|
6
|
+
export function normalizeCredential(value) {
|
|
7
|
+
if (typeof value !== 'string')
|
|
8
|
+
return undefined;
|
|
9
|
+
const trimmed = value.trim();
|
|
10
|
+
if (!trimmed || trimmed.includes('...'))
|
|
11
|
+
return undefined;
|
|
12
|
+
return trimmed;
|
|
13
|
+
}
|
|
14
|
+
/** True when either supported LLM provider has a real explicit key. */
|
|
15
|
+
export function hasProviderCredentials(credentials) {
|
|
16
|
+
return !!(normalizeCredential(credentials.apiKey) || normalizeCredential(credentials.anthropicKey));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Infer provider from explicit keys. A single real key is treated as
|
|
20
|
+
* user intent; when both are present, the caller's provider selection
|
|
21
|
+
* remains authoritative.
|
|
22
|
+
*/
|
|
23
|
+
export function inferProviderFromCredentials(credentials) {
|
|
24
|
+
const hasOpenAI = !!normalizeCredential(credentials.apiKey);
|
|
25
|
+
const hasAnthropic = !!normalizeCredential(credentials.anthropicKey);
|
|
26
|
+
if (hasOpenAI && !hasAnthropic)
|
|
27
|
+
return 'openai';
|
|
28
|
+
if (hasAnthropic && !hasOpenAI)
|
|
29
|
+
return 'anthropic';
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Resolve provider, preferring unambiguous explicit-key intent. */
|
|
33
|
+
export function resolveProviderFromCredentials(requested, credentials, fallback = 'openai') {
|
|
34
|
+
return inferProviderFromCredentials(credentials) ?? requested ?? fallback;
|
|
35
|
+
}
|
|
36
|
+
/** Return the explicit API key for the selected provider, if present. */
|
|
37
|
+
export function apiKeyForProvider(provider, credentials) {
|
|
38
|
+
return provider === 'anthropic'
|
|
39
|
+
? normalizeCredential(credentials.anthropicKey)
|
|
40
|
+
: normalizeCredential(credentials.apiKey);
|
|
41
|
+
}
|
|
42
|
+
/** Stable non-secret identity for cache keys that must vary by credential. */
|
|
43
|
+
export function credentialFingerprint(value) {
|
|
44
|
+
const key = normalizeCredential(value);
|
|
45
|
+
if (!key)
|
|
46
|
+
return 'env';
|
|
47
|
+
let hash = 0x811c9dc5;
|
|
48
|
+
for (let i = 0; i < key.length; i += 1) {
|
|
49
|
+
hash ^= key.charCodeAt(i);
|
|
50
|
+
hash = Math.imul(hash, 0x01000193);
|
|
51
|
+
}
|
|
52
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
53
|
+
}
|
|
54
|
+
/** Explicit search key first, then host env fallback. */
|
|
55
|
+
export function searchCredential(explicitValue, envName, env = typeof process !== 'undefined' ? process.env : undefined) {
|
|
56
|
+
return normalizeCredential(explicitValue) ?? normalizeCredential(env?.[envName]);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=provider-credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-credentials.js","sourceRoot":"","sources":["../../src/engine/provider-credentials.ts"],"names":[],"mappings":"AAqBA;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1D,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,sBAAsB,CAAC,WAAsC;IAC3E,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,mBAAmB,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;AACtG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,WAAsC;IAEtC,MAAM,SAAS,GAAG,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5D,MAAM,YAAY,GAAG,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IACrE,IAAI,SAAS,IAAI,CAAC,YAAY;QAAE,OAAO,QAAQ,CAAC;IAChD,IAAI,YAAY,IAAI,CAAC,SAAS;QAAE,OAAO,WAAW,CAAC;IACnD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,8BAA8B,CAC5C,SAAkC,EAClC,WAAsC,EACtC,WAAw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|
|
1
1
|
{
|
|
2
2
|
"name": "paracosm",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.455",
|
|
4
4
|
"description": "Prompt/document/URL-grounded structured world model for AI agents: typed ScenarioPackages, deterministic kernels, HEXACO leaders, LLM events, runtime tool forging, and reproducible counterfactual RunArtifacts. Built on AgentOS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/engine/index.js",
|