@perstack/runtime 0.0.69 → 0.0.71
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 +202 -0
- package/README.md +0 -1
- package/dist/bin/cli.js +12 -5
- package/dist/bin/cli.js.map +1 -1
- package/dist/{chunk-H65LPOAK.js → chunk-LDJKVMQK.js} +755 -753
- package/dist/chunk-LDJKVMQK.js.map +1 -0
- package/dist/chunk-RG4QHAGG.js +935 -0
- package/dist/chunk-RG4QHAGG.js.map +1 -0
- package/dist/lockfile-skill-manager-LG2E4KAZ.js +3 -0
- package/dist/lockfile-skill-manager-LG2E4KAZ.js.map +1 -0
- package/dist/src/index.d.ts +160 -16
- package/dist/src/index.js +8 -6
- package/dist/src/index.js.map +1 -1
- package/package.json +39 -35
- package/bin/cli.ts +0 -99
- package/dist/chunk-H65LPOAK.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [2025] [Wintermute Technologies Inc.]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -25,7 +25,6 @@ perstack-runtime run <expertKey> <query> [options]
|
|
|
25
25
|
| `--config <path>` | Path to perstack.toml |
|
|
26
26
|
| `--provider <provider>` | LLM provider |
|
|
27
27
|
| `--model <model>` | Model name |
|
|
28
|
-
| `--temperature <temp>` | Temperature (0.0-1.0) |
|
|
29
28
|
| `--max-steps <n>` | Maximum steps |
|
|
30
29
|
| `--max-retries <n>` | Maximum retries |
|
|
31
30
|
| `--timeout <ms>` | Timeout in milliseconds |
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { package_default, run } from '../chunk-
|
|
2
|
+
import { package_default, findLockfile, loadLockfile, run } from '../chunk-LDJKVMQK.js';
|
|
3
|
+
import '../chunk-RG4QHAGG.js';
|
|
3
4
|
import { parseWithFriendlyError, runCommandInputSchema, perstackConfigSchema } from '@perstack/core';
|
|
4
5
|
import { Command } from 'commander';
|
|
5
6
|
import dotenv from 'dotenv';
|
|
@@ -183,7 +184,8 @@ var defaultProvider = "anthropic";
|
|
|
183
184
|
var defaultModel = "claude-sonnet-4-5";
|
|
184
185
|
async function resolveRunContext(input) {
|
|
185
186
|
const perstackConfig = await getPerstackConfig(input.configPath);
|
|
186
|
-
const
|
|
187
|
+
const envPath = input.envPath && input.envPath.length > 0 ? input.envPath : perstackConfig.envPath ?? [".env", ".env.local"];
|
|
188
|
+
const env = getEnv(envPath);
|
|
187
189
|
const provider = input.provider ?? perstackConfig.provider?.providerName ?? defaultProvider;
|
|
188
190
|
const model = input.model ?? perstackConfig.model ?? defaultModel;
|
|
189
191
|
const providerConfig = getProviderConfig(provider, env, perstackConfig.provider);
|
|
@@ -227,7 +229,10 @@ var retrieveCheckpoint = async (_jobId, checkpointId) => {
|
|
|
227
229
|
return checkpoint;
|
|
228
230
|
};
|
|
229
231
|
var program = new Command().name("perstack-runtime").description("Perstack Runtime CLI - Execute Experts directly").version(package_default.version);
|
|
230
|
-
program.command("run").description("Run an Expert with JSON event output").argument("<expertKey>", "Expert key to run").argument("<query>", "Query to run").option("--config <configPath>", "Path to perstack.toml config file").option("--provider <provider>", "Provider to use").option("--model <model>", "Model to use").option(
|
|
232
|
+
program.command("run").description("Run an Expert with JSON event output").argument("<expertKey>", "Expert key to run").argument("<query>", "Query to run").option("--config <configPath>", "Path to perstack.toml config file").option("--provider <provider>", "Provider to use").option("--model <model>", "Model to use").option(
|
|
233
|
+
"--reasoning-budget <budget>",
|
|
234
|
+
"Reasoning budget for native LLM reasoning (minimal, low, medium, high, or token count)"
|
|
235
|
+
).option(
|
|
231
236
|
"--max-steps <maxSteps>",
|
|
232
237
|
"Maximum number of steps to run, default is undefined (no limit)"
|
|
233
238
|
).option("--max-retries <maxRetries>", "Maximum number of generation retries, default is 5").option(
|
|
@@ -247,6 +252,8 @@ program.command("run").description("Run an Expert with JSON event output").argum
|
|
|
247
252
|
model: input.options.model,
|
|
248
253
|
envPath: input.options.envPath
|
|
249
254
|
});
|
|
255
|
+
const lockfilePath = findLockfile(input.options.config);
|
|
256
|
+
const lockfile = lockfilePath ? loadLockfile(lockfilePath) ?? void 0 : void 0;
|
|
250
257
|
await run(
|
|
251
258
|
{
|
|
252
259
|
setting: {
|
|
@@ -257,7 +264,7 @@ program.command("run").description("Run an Expert with JSON event output").argum
|
|
|
257
264
|
experts,
|
|
258
265
|
model,
|
|
259
266
|
providerConfig,
|
|
260
|
-
|
|
267
|
+
reasoningBudget: input.options.reasoningBudget ?? perstackConfig.reasoningBudget,
|
|
261
268
|
maxSteps: input.options.maxSteps ?? perstackConfig.maxSteps,
|
|
262
269
|
maxRetries: input.options.maxRetries ?? perstackConfig.maxRetries,
|
|
263
270
|
timeout: input.options.timeout ?? perstackConfig.timeout,
|
|
@@ -269,7 +276,7 @@ program.command("run").description("Run an Expert with JSON event output").argum
|
|
|
269
276
|
verbose: input.options.verbose
|
|
270
277
|
}
|
|
271
278
|
},
|
|
272
|
-
{ eventListener: defaultEventListener, storeCheckpoint, retrieveCheckpoint }
|
|
279
|
+
{ eventListener: defaultEventListener, storeCheckpoint, retrieveCheckpoint, lockfile }
|
|
273
280
|
);
|
|
274
281
|
} catch (error) {
|
|
275
282
|
if (error instanceof Error) {
|
package/dist/bin/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/get-env.ts","../../src/cli/perstack-toml.ts","../../src/cli/provider-config.ts","../../src/cli/context.ts","../../bin/cli.ts"],"names":["parseWithFriendlyError"],"mappings":";;;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cesContent":["import dotenv from \"dotenv\"\n\nexport function getEnv(envPath: string[]): Record<string, string> {\n const env: Record<string, string> = Object.fromEntries(\n Object.entries(process.env)\n .filter(([_, value]) => !!value)\n .map(([key, value]) => [key, value as string]),\n )\n dotenv.config({ path: envPath, processEnv: env, quiet: true })\n return env\n}\n","import { readFile } from \"node:fs/promises\"\nimport path from \"node:path\"\nimport { type PerstackConfig, parseWithFriendlyError, perstackConfigSchema } from \"@perstack/core\"\nimport TOML from \"smol-toml\"\n\nconst ALLOWED_CONFIG_HOSTS = [\"raw.githubusercontent.com\"]\n\nexport async function getPerstackConfig(configPath?: string): Promise<PerstackConfig> {\n const configString = await findPerstackConfigString(configPath)\n if (configString === null) {\n throw new Error(\"perstack.toml not found. Create one or specify --config path.\")\n }\n return await parsePerstackConfig(configString)\n}\n\nfunction isRemoteUrl(configPath: string): boolean {\n const lower = configPath.toLowerCase()\n return lower.startsWith(\"https://\") || lower.startsWith(\"http://\")\n}\n\nasync function fetchRemoteConfig(url: string): Promise<string> {\n let parsed: URL\n try {\n parsed = new URL(url)\n } catch {\n throw new Error(`Invalid remote config URL: ${url}`)\n }\n if (parsed.protocol !== \"https:\") {\n throw new Error(\"Remote config requires HTTPS\")\n }\n if (!ALLOWED_CONFIG_HOSTS.includes(parsed.hostname)) {\n throw new Error(`Remote config only allowed from: ${ALLOWED_CONFIG_HOSTS.join(\", \")}`)\n }\n try {\n const response = await fetch(url, { redirect: \"error\" })\n if (!response.ok) {\n throw new Error(`${response.status} ${response.statusText}`)\n }\n return await response.text()\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(`Failed to fetch remote config: ${message}`)\n }\n}\n\nasync function findPerstackConfigString(configPath?: string): Promise<string | null> {\n if (configPath) {\n if (isRemoteUrl(configPath)) {\n return await fetchRemoteConfig(configPath)\n }\n try {\n const tomlString = await readFile(path.resolve(process.cwd(), configPath), \"utf-8\")\n return tomlString\n } catch {\n throw new Error(`Given config path \"${configPath}\" is not found`)\n }\n }\n return await findPerstackConfigStringRecursively(path.resolve(process.cwd()))\n}\n\nasync function findPerstackConfigStringRecursively(cwd: string): Promise<string | null> {\n try {\n const tomlString = await readFile(path.resolve(cwd, \"perstack.toml\"), \"utf-8\")\n return tomlString\n } catch {\n if (cwd === path.parse(cwd).root) {\n return null\n }\n return await findPerstackConfigStringRecursively(path.dirname(cwd))\n }\n}\n\nasync function parsePerstackConfig(config: string): Promise<PerstackConfig> {\n const toml = TOML.parse(config ?? \"\")\n return parseWithFriendlyError(perstackConfigSchema, toml, \"perstack.toml\")\n}\n","import type { ProviderConfig, ProviderName, ProviderTable } from \"@perstack/core\"\n\ntype SettingRecord = Record<string, unknown>\n\nexport function getProviderConfig(\n provider: ProviderName,\n env: Record<string, string>,\n providerTable?: ProviderTable,\n): ProviderConfig {\n const setting = (providerTable?.setting ?? {}) as SettingRecord\n switch (provider) {\n case \"anthropic\": {\n const apiKey = env.ANTHROPIC_API_KEY\n if (!apiKey) throw new Error(\"ANTHROPIC_API_KEY is not set\")\n return {\n providerName: \"anthropic\",\n apiKey,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.ANTHROPIC_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"google\": {\n const apiKey = env.GOOGLE_GENERATIVE_AI_API_KEY\n if (!apiKey) throw new Error(\"GOOGLE_GENERATIVE_AI_API_KEY is not set\")\n return {\n providerName: \"google\",\n apiKey,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.GOOGLE_GENERATIVE_AI_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"openai\": {\n const apiKey = env.OPENAI_API_KEY\n if (!apiKey) throw new Error(\"OPENAI_API_KEY is not set\")\n return {\n providerName: \"openai\",\n apiKey,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.OPENAI_BASE_URL,\n organization: (setting.organization as string | undefined) ?? env.OPENAI_ORGANIZATION,\n project: (setting.project as string | undefined) ?? env.OPENAI_PROJECT,\n name: setting.name as string | undefined,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"ollama\": {\n return {\n providerName: \"ollama\",\n baseUrl: (setting.baseUrl as string | undefined) ?? env.OLLAMA_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"azure-openai\": {\n const apiKey = env.AZURE_API_KEY\n if (!apiKey) throw new Error(\"AZURE_API_KEY is not set\")\n const resourceName = (setting.resourceName as string | undefined) ?? env.AZURE_RESOURCE_NAME\n const baseUrl = (setting.baseUrl as string | undefined) ?? env.AZURE_BASE_URL\n if (!resourceName && !baseUrl) throw new Error(\"AZURE_RESOURCE_NAME or baseUrl is not set\")\n return {\n providerName: \"azure-openai\",\n apiKey,\n resourceName,\n apiVersion: (setting.apiVersion as string | undefined) ?? env.AZURE_API_VERSION,\n baseUrl,\n headers: setting.headers as Record<string, string> | undefined,\n useDeploymentBasedUrls: setting.useDeploymentBasedUrls as boolean | undefined,\n }\n }\n case \"amazon-bedrock\": {\n const accessKeyId = env.AWS_ACCESS_KEY_ID\n const secretAccessKey = env.AWS_SECRET_ACCESS_KEY\n const sessionToken = env.AWS_SESSION_TOKEN\n if (!accessKeyId) throw new Error(\"AWS_ACCESS_KEY_ID is not set\")\n if (!secretAccessKey) throw new Error(\"AWS_SECRET_ACCESS_KEY is not set\")\n const region = (setting.region as string | undefined) ?? env.AWS_REGION\n if (!region) throw new Error(\"AWS_REGION is not set\")\n return {\n providerName: \"amazon-bedrock\",\n accessKeyId,\n secretAccessKey,\n region,\n sessionToken,\n }\n }\n case \"google-vertex\": {\n return {\n providerName: \"google-vertex\",\n project: (setting.project as string | undefined) ?? env.GOOGLE_VERTEX_PROJECT,\n location: (setting.location as string | undefined) ?? env.GOOGLE_VERTEX_LOCATION,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.GOOGLE_VERTEX_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"deepseek\": {\n const apiKey = env.DEEPSEEK_API_KEY\n if (!apiKey) throw new Error(\"DEEPSEEK_API_KEY is not set\")\n return {\n providerName: \"deepseek\",\n apiKey,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.DEEPSEEK_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n }\n}\n","import type { PerstackConfig, ProviderConfig, ProviderName } from \"@perstack/core\"\nimport { getEnv } from \"./get-env.js\"\nimport { getPerstackConfig } from \"./perstack-toml.js\"\nimport { getProviderConfig } from \"./provider-config.js\"\n\nconst defaultProvider: ProviderName = \"anthropic\"\nconst defaultModel = \"claude-sonnet-4-5\"\n\nexport type ExpertConfig = NonNullable<PerstackConfig[\"experts\"]>[string]\n\nexport type RunContext = {\n perstackConfig: PerstackConfig\n env: Record<string, string>\n providerConfig: ProviderConfig\n model: string\n experts: Record<string, ExpertConfig & { key: string; name: string; version: string }>\n}\n\nexport type ResolveRunContextInput = {\n configPath?: string\n provider?: string\n model?: string\n envPath?: string[]\n}\n\nexport async function resolveRunContext(input: ResolveRunContextInput): Promise<RunContext> {\n const perstackConfig = await getPerstackConfig(input.configPath)\n const env = getEnv(input.envPath ?? perstackConfig.envPath ?? [\".env\", \".env.local\"])\n const provider = (input.provider ??\n perstackConfig.provider?.providerName ??\n defaultProvider) as ProviderName\n const model = input.model ?? perstackConfig.model ?? defaultModel\n const providerConfig = getProviderConfig(provider, env, perstackConfig.provider)\n const experts = Object.fromEntries(\n Object.entries(perstackConfig.experts ?? {}).map(([name, expert]) => {\n return [\n name,\n {\n key: name,\n name,\n version: expert.version ?? \"1.0.0\",\n description: expert.description,\n instruction: expert.instruction,\n skills: expert.skills ?? {},\n delegates: expert.delegates ?? [],\n tags: expert.tags ?? [],\n },\n ]\n }),\n )\n return {\n perstackConfig,\n env,\n providerConfig,\n model,\n experts: experts as Record<\n string,\n ExpertConfig & { key: string; name: string; version: string }\n >,\n }\n}\n","#!/usr/bin/env node\n\nimport type { Checkpoint, RunEvent, RuntimeEvent } from \"@perstack/core\"\nimport { parseWithFriendlyError, runCommandInputSchema } from \"@perstack/core\"\nimport { Command } from \"commander\"\nimport pkg from \"../package.json\" with { type: \"json\" }\nimport { resolveRunContext } from \"../src/cli/context.js\"\nimport { run } from \"../src/run.js\"\n\nconst defaultEventListener = (event: RunEvent | RuntimeEvent) => console.log(JSON.stringify(event))\n\nconst checkpointStore = new Map<string, Checkpoint>()\nconst storeCheckpoint = async (checkpoint: Checkpoint) => {\n checkpointStore.set(checkpoint.id, checkpoint)\n}\nconst retrieveCheckpoint = async (_jobId: string, checkpointId: string) => {\n const checkpoint = checkpointStore.get(checkpointId)\n if (!checkpoint) {\n throw new Error(`Checkpoint not found: ${checkpointId}`)\n }\n return checkpoint\n}\n\nconst program = new Command()\n .name(\"perstack-runtime\")\n .description(\"Perstack Runtime CLI - Execute Experts directly\")\n .version(pkg.version)\n\nprogram\n .command(\"run\")\n .description(\"Run an Expert with JSON event output\")\n .argument(\"<expertKey>\", \"Expert key to run\")\n .argument(\"<query>\", \"Query to run\")\n .option(\"--config <configPath>\", \"Path to perstack.toml config file\")\n .option(\"--provider <provider>\", \"Provider to use\")\n .option(\"--model <model>\", \"Model to use\")\n .option(\"--temperature <temperature>\", \"Temperature for the model, default is 0.3\")\n .option(\n \"--max-steps <maxSteps>\",\n \"Maximum number of steps to run, default is undefined (no limit)\",\n )\n .option(\"--max-retries <maxRetries>\", \"Maximum number of generation retries, default is 5\")\n .option(\n \"--timeout <timeout>\",\n \"Timeout for each generation in milliseconds, default is 60000 (1 minute)\",\n )\n .option(\"--job-id <jobId>\", \"Job ID for identifying the job\")\n .option(\"--run-id <runId>\", \"Run ID for identifying the run\")\n .option(\n \"--env-path <path>\",\n \"Path to the environment file (can be specified multiple times), default is .env and .env.local\",\n (value: string, previous: string[]) => previous.concat(value),\n [] as string[],\n )\n .option(\"--verbose\", \"Enable verbose logging\")\n .action(async (expertKey, query, options) => {\n const input = parseWithFriendlyError(runCommandInputSchema, { expertKey, query, options })\n try {\n const { perstackConfig, env, providerConfig, model, experts } = await resolveRunContext({\n configPath: input.options.config,\n provider: input.options.provider,\n model: input.options.model,\n envPath: input.options.envPath,\n })\n await run(\n {\n setting: {\n jobId: input.options.jobId,\n runId: input.options.runId,\n expertKey: input.expertKey,\n input: { text: input.query },\n experts,\n model,\n providerConfig,\n temperature: input.options.temperature ?? perstackConfig.temperature,\n maxSteps: input.options.maxSteps ?? perstackConfig.maxSteps,\n maxRetries: input.options.maxRetries ?? perstackConfig.maxRetries,\n timeout: input.options.timeout ?? perstackConfig.timeout,\n perstackApiBaseUrl: perstackConfig.perstackApiBaseUrl,\n perstackApiKey: env.PERSTACK_API_KEY,\n perstackBaseSkillCommand: perstackConfig.perstackBaseSkillCommand,\n env,\n proxyUrl: process.env.PERSTACK_PROXY_URL,\n verbose: input.options.verbose,\n },\n },\n { eventListener: defaultEventListener, storeCheckpoint, retrieveCheckpoint },\n )\n } catch (error) {\n if (error instanceof Error) {\n console.error(error.message)\n } else {\n console.error(error)\n }\n process.exit(1)\n }\n })\n\nprogram.parse()\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/cli/get-env.ts","../../src/cli/perstack-toml.ts","../../src/cli/provider-config.ts","../../src/cli/context.ts","../../bin/cli.ts"],"names":["parseWithFriendlyError"],"mappings":";;;;;;;;;;AAEO,SAAS,OAAO,OAAA,EAA2C;AAChE,EAAA,MAAM,MAA8B,MAAA,CAAO,WAAA;AAAA,IACzC,MAAA,CAAO,OAAA,CAAQ,OAAA,CAAQ,GAAG,CAAA,CACvB,OAAO,CAAC,CAAC,CAAA,EAAG,KAAK,CAAA,KAAM,CAAC,CAAC,KAAK,CAAA,CAC9B,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,GAAA,EAAK,KAAe,CAAC;AAAA,GACjD;AACA,EAAA,MAAA,CAAO,MAAA,CAAO,EAAE,IAAA,EAAM,OAAA,EAAS,YAAY,GAAA,EAAK,KAAA,EAAO,MAAM,CAAA;AAC7D,EAAA,OAAO,GAAA;AACT;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EAAE,IAAA,EAAM,KAAA,CAAM,KAAA,EAAM;AAAA,UAC3B,OAAA;AAAA,UACA,KAAA;AAAA,UACA,cAAA;AAAA,UACA,eAAA,EAAiB,KAAA,CAAM,OAAA,CAAQ,eAAA,IAAmB,cAAA,CAAe,eAAA;AAAA,UACjE,QAAA,EAAU,KAAA,CAAM,OAAA,CAAQ,QAAA,IAAY,cAAA,CAAe,QAAA;AAAA,UACnD,UAAA,EAAY,KAAA,CAAM,OAAA,CAAQ,UAAA,IAAc,cAAA,CAAe,UAAA;AAAA,UACvD,OAAA,EAAS,KAAA,CAAM,OAAA,CAAQ,OAAA,IAAW,cAAA,CAAe,OAAA;AAAA,UACjD,oBAAoB,cAAA,CAAe,kBAAA;AAAA,UACnC,gBAAgB,GAAA,CAAI,gBAAA;AAAA,UACpB,0BAA0B,cAAA,CAAe,wBAAA;AAAA,UACzC,GAAA;AAAA,UACA,QAAA,EAAU,QAAQ,GAAA,CAAI,kBAAA;AAAA,UACtB,OAAA,EAAS,MAAM,OAAA,CAAQ;AAAA;AACzB,OACF;AAAA,MACA,EAAE,aAAA,EAAe,oBAAA,EAAsB,eAAA,EAAiB,oBAAoB,QAAA;AAAS,KACvF;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,MAAA,OAAA,CAAQ,KAAA,CAAM,MAAM,OAAO,CAAA;AAAA,IAC7B,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA,IACrB;AACA,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF,CAAC,CAAA;AAEH,OAAA,CAAQ,KAAA,EAAM","file":"cli.js","sourcesContent":["import dotenv from \"dotenv\"\n\nexport function getEnv(envPath: string[]): Record<string, string> {\n const env: Record<string, string> = Object.fromEntries(\n Object.entries(process.env)\n .filter(([_, value]) => !!value)\n .map(([key, value]) => [key, value as string]),\n )\n dotenv.config({ path: envPath, processEnv: env, quiet: true })\n return env\n}\n","import { readFile } from \"node:fs/promises\"\nimport path from \"node:path\"\nimport { type PerstackConfig, parseWithFriendlyError, perstackConfigSchema } from \"@perstack/core\"\nimport TOML from \"smol-toml\"\n\nconst ALLOWED_CONFIG_HOSTS = [\"raw.githubusercontent.com\"]\n\nexport async function getPerstackConfig(configPath?: string): Promise<PerstackConfig> {\n const configString = await findPerstackConfigString(configPath)\n if (configString === null) {\n throw new Error(\"perstack.toml not found. Create one or specify --config path.\")\n }\n return await parsePerstackConfig(configString)\n}\n\nfunction isRemoteUrl(configPath: string): boolean {\n const lower = configPath.toLowerCase()\n return lower.startsWith(\"https://\") || lower.startsWith(\"http://\")\n}\n\nasync function fetchRemoteConfig(url: string): Promise<string> {\n let parsed: URL\n try {\n parsed = new URL(url)\n } catch {\n throw new Error(`Invalid remote config URL: ${url}`)\n }\n if (parsed.protocol !== \"https:\") {\n throw new Error(\"Remote config requires HTTPS\")\n }\n if (!ALLOWED_CONFIG_HOSTS.includes(parsed.hostname)) {\n throw new Error(`Remote config only allowed from: ${ALLOWED_CONFIG_HOSTS.join(\", \")}`)\n }\n try {\n const response = await fetch(url, { redirect: \"error\" })\n if (!response.ok) {\n throw new Error(`${response.status} ${response.statusText}`)\n }\n return await response.text()\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n throw new Error(`Failed to fetch remote config: ${message}`)\n }\n}\n\nasync function findPerstackConfigString(configPath?: string): Promise<string | null> {\n if (configPath) {\n if (isRemoteUrl(configPath)) {\n return await fetchRemoteConfig(configPath)\n }\n try {\n const tomlString = await readFile(path.resolve(process.cwd(), configPath), \"utf-8\")\n return tomlString\n } catch {\n throw new Error(`Given config path \"${configPath}\" is not found`)\n }\n }\n return await findPerstackConfigStringRecursively(path.resolve(process.cwd()))\n}\n\nasync function findPerstackConfigStringRecursively(cwd: string): Promise<string | null> {\n try {\n const tomlString = await readFile(path.resolve(cwd, \"perstack.toml\"), \"utf-8\")\n return tomlString\n } catch {\n if (cwd === path.parse(cwd).root) {\n return null\n }\n return await findPerstackConfigStringRecursively(path.dirname(cwd))\n }\n}\n\nasync function parsePerstackConfig(config: string): Promise<PerstackConfig> {\n const toml = TOML.parse(config ?? \"\")\n return parseWithFriendlyError(perstackConfigSchema, toml, \"perstack.toml\")\n}\n","import type { ProviderConfig, ProviderName, ProviderTable } from \"@perstack/core\"\n\ntype SettingRecord = Record<string, unknown>\n\nexport function getProviderConfig(\n provider: ProviderName,\n env: Record<string, string>,\n providerTable?: ProviderTable,\n): ProviderConfig {\n const setting = (providerTable?.setting ?? {}) as SettingRecord\n switch (provider) {\n case \"anthropic\": {\n const apiKey = env.ANTHROPIC_API_KEY\n if (!apiKey) throw new Error(\"ANTHROPIC_API_KEY is not set\")\n return {\n providerName: \"anthropic\",\n apiKey,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.ANTHROPIC_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"google\": {\n const apiKey = env.GOOGLE_GENERATIVE_AI_API_KEY\n if (!apiKey) throw new Error(\"GOOGLE_GENERATIVE_AI_API_KEY is not set\")\n return {\n providerName: \"google\",\n apiKey,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.GOOGLE_GENERATIVE_AI_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"openai\": {\n const apiKey = env.OPENAI_API_KEY\n if (!apiKey) throw new Error(\"OPENAI_API_KEY is not set\")\n return {\n providerName: \"openai\",\n apiKey,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.OPENAI_BASE_URL,\n organization: (setting.organization as string | undefined) ?? env.OPENAI_ORGANIZATION,\n project: (setting.project as string | undefined) ?? env.OPENAI_PROJECT,\n name: setting.name as string | undefined,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"ollama\": {\n return {\n providerName: \"ollama\",\n baseUrl: (setting.baseUrl as string | undefined) ?? env.OLLAMA_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"azure-openai\": {\n const apiKey = env.AZURE_API_KEY\n if (!apiKey) throw new Error(\"AZURE_API_KEY is not set\")\n const resourceName = (setting.resourceName as string | undefined) ?? env.AZURE_RESOURCE_NAME\n const baseUrl = (setting.baseUrl as string | undefined) ?? env.AZURE_BASE_URL\n if (!resourceName && !baseUrl) throw new Error(\"AZURE_RESOURCE_NAME or baseUrl is not set\")\n return {\n providerName: \"azure-openai\",\n apiKey,\n resourceName,\n apiVersion: (setting.apiVersion as string | undefined) ?? env.AZURE_API_VERSION,\n baseUrl,\n headers: setting.headers as Record<string, string> | undefined,\n useDeploymentBasedUrls: setting.useDeploymentBasedUrls as boolean | undefined,\n }\n }\n case \"amazon-bedrock\": {\n const accessKeyId = env.AWS_ACCESS_KEY_ID\n const secretAccessKey = env.AWS_SECRET_ACCESS_KEY\n const sessionToken = env.AWS_SESSION_TOKEN\n if (!accessKeyId) throw new Error(\"AWS_ACCESS_KEY_ID is not set\")\n if (!secretAccessKey) throw new Error(\"AWS_SECRET_ACCESS_KEY is not set\")\n const region = (setting.region as string | undefined) ?? env.AWS_REGION\n if (!region) throw new Error(\"AWS_REGION is not set\")\n return {\n providerName: \"amazon-bedrock\",\n accessKeyId,\n secretAccessKey,\n region,\n sessionToken,\n }\n }\n case \"google-vertex\": {\n return {\n providerName: \"google-vertex\",\n project: (setting.project as string | undefined) ?? env.GOOGLE_VERTEX_PROJECT,\n location: (setting.location as string | undefined) ?? env.GOOGLE_VERTEX_LOCATION,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.GOOGLE_VERTEX_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n case \"deepseek\": {\n const apiKey = env.DEEPSEEK_API_KEY\n if (!apiKey) throw new Error(\"DEEPSEEK_API_KEY is not set\")\n return {\n providerName: \"deepseek\",\n apiKey,\n baseUrl: (setting.baseUrl as string | undefined) ?? env.DEEPSEEK_BASE_URL,\n headers: setting.headers as Record<string, string> | undefined,\n }\n }\n }\n}\n","import type { PerstackConfig, ProviderConfig, ProviderName } from \"@perstack/core\"\nimport { getEnv } from \"./get-env.js\"\nimport { getPerstackConfig } from \"./perstack-toml.js\"\nimport { getProviderConfig } from \"./provider-config.js\"\n\nconst defaultProvider: ProviderName = \"anthropic\"\nconst defaultModel = \"claude-sonnet-4-5\"\n\nexport type ExpertConfig = NonNullable<PerstackConfig[\"experts\"]>[string]\n\nexport type RunContext = {\n perstackConfig: PerstackConfig\n env: Record<string, string>\n providerConfig: ProviderConfig\n model: string\n experts: Record<string, ExpertConfig & { key: string; name: string; version: string }>\n}\n\nexport type ResolveRunContextInput = {\n configPath?: string\n provider?: string\n model?: string\n envPath?: string[]\n}\n\nexport async function resolveRunContext(input: ResolveRunContextInput): Promise<RunContext> {\n const perstackConfig = await getPerstackConfig(input.configPath)\n const envPath =\n input.envPath && input.envPath.length > 0\n ? input.envPath\n : (perstackConfig.envPath ?? [\".env\", \".env.local\"])\n const env = getEnv(envPath)\n const provider = (input.provider ??\n perstackConfig.provider?.providerName ??\n defaultProvider) as ProviderName\n const model = input.model ?? perstackConfig.model ?? defaultModel\n const providerConfig = getProviderConfig(provider, env, perstackConfig.provider)\n const experts = Object.fromEntries(\n Object.entries(perstackConfig.experts ?? {}).map(([name, expert]) => {\n return [\n name,\n {\n key: name,\n name,\n version: expert.version ?? \"1.0.0\",\n description: expert.description,\n instruction: expert.instruction,\n skills: expert.skills ?? {},\n delegates: expert.delegates ?? [],\n tags: expert.tags ?? [],\n },\n ]\n }),\n )\n return {\n perstackConfig,\n env,\n providerConfig,\n model,\n experts: experts as Record<\n string,\n ExpertConfig & { key: string; name: string; version: string }\n >,\n }\n}\n","#!/usr/bin/env node\n\nimport type { Checkpoint, RunEvent, RuntimeEvent } from \"@perstack/core\"\nimport { parseWithFriendlyError, runCommandInputSchema } from \"@perstack/core\"\nimport { Command } from \"commander\"\nimport pkg from \"../package.json\" with { type: \"json\" }\nimport { resolveRunContext } from \"../src/cli/context.js\"\nimport { findLockfile, loadLockfile } from \"../src/helpers/lockfile.js\"\nimport { run } from \"../src/run.js\"\n\nconst defaultEventListener = (event: RunEvent | RuntimeEvent) => console.log(JSON.stringify(event))\n\nconst checkpointStore = new Map<string, Checkpoint>()\nconst storeCheckpoint = async (checkpoint: Checkpoint) => {\n checkpointStore.set(checkpoint.id, checkpoint)\n}\nconst retrieveCheckpoint = async (_jobId: string, checkpointId: string) => {\n const checkpoint = checkpointStore.get(checkpointId)\n if (!checkpoint) {\n throw new Error(`Checkpoint not found: ${checkpointId}`)\n }\n return checkpoint\n}\n\nconst program = new Command()\n .name(\"perstack-runtime\")\n .description(\"Perstack Runtime CLI - Execute Experts directly\")\n .version(pkg.version)\n\nprogram\n .command(\"run\")\n .description(\"Run an Expert with JSON event output\")\n .argument(\"<expertKey>\", \"Expert key to run\")\n .argument(\"<query>\", \"Query to run\")\n .option(\"--config <configPath>\", \"Path to perstack.toml config file\")\n .option(\"--provider <provider>\", \"Provider to use\")\n .option(\"--model <model>\", \"Model to use\")\n .option(\n \"--reasoning-budget <budget>\",\n \"Reasoning budget for native LLM reasoning (minimal, low, medium, high, or token count)\",\n )\n .option(\n \"--max-steps <maxSteps>\",\n \"Maximum number of steps to run, default is undefined (no limit)\",\n )\n .option(\"--max-retries <maxRetries>\", \"Maximum number of generation retries, default is 5\")\n .option(\n \"--timeout <timeout>\",\n \"Timeout for each generation in milliseconds, default is 60000 (1 minute)\",\n )\n .option(\"--job-id <jobId>\", \"Job ID for identifying the job\")\n .option(\"--run-id <runId>\", \"Run ID for identifying the run\")\n .option(\n \"--env-path <path>\",\n \"Path to the environment file (can be specified multiple times), default is .env and .env.local\",\n (value: string, previous: string[]) => previous.concat(value),\n [] as string[],\n )\n .option(\"--verbose\", \"Enable verbose logging\")\n .action(async (expertKey, query, options) => {\n const input = parseWithFriendlyError(runCommandInputSchema, { expertKey, query, options })\n try {\n const { perstackConfig, env, providerConfig, model, experts } = await resolveRunContext({\n configPath: input.options.config,\n provider: input.options.provider,\n model: input.options.model,\n envPath: input.options.envPath,\n })\n const lockfilePath = findLockfile(input.options.config)\n const lockfile = lockfilePath ? (loadLockfile(lockfilePath) ?? undefined) : undefined\n await run(\n {\n setting: {\n jobId: input.options.jobId,\n runId: input.options.runId,\n expertKey: input.expertKey,\n input: { text: input.query },\n experts,\n model,\n providerConfig,\n reasoningBudget: input.options.reasoningBudget ?? perstackConfig.reasoningBudget,\n maxSteps: input.options.maxSteps ?? perstackConfig.maxSteps,\n maxRetries: input.options.maxRetries ?? perstackConfig.maxRetries,\n timeout: input.options.timeout ?? perstackConfig.timeout,\n perstackApiBaseUrl: perstackConfig.perstackApiBaseUrl,\n perstackApiKey: env.PERSTACK_API_KEY,\n perstackBaseSkillCommand: perstackConfig.perstackBaseSkillCommand,\n env,\n proxyUrl: process.env.PERSTACK_PROXY_URL,\n verbose: input.options.verbose,\n },\n },\n { eventListener: defaultEventListener, storeCheckpoint, retrieveCheckpoint, lockfile },\n )\n } catch (error) {\n if (error instanceof Error) {\n console.error(error.message)\n } else {\n console.error(error)\n }\n process.exit(1)\n }\n })\n\nprogram.parse()\n"]}
|