@perstack/runtime 0.0.67 → 0.0.69
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/bin/cli.ts +99 -0
- package/dist/bin/cli.js +1 -1
- package/dist/{chunk-AQSRQW5R.js → chunk-H65LPOAK.js} +780 -533
- package/dist/chunk-H65LPOAK.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +2 -2
- package/package.json +26 -19
- package/LICENSE +0 -202
- package/dist/chunk-AQSRQW5R.js.map +0 -1
package/bin/cli.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import type { Checkpoint, RunEvent, RuntimeEvent } from "@perstack/core"
|
|
4
|
+
import { parseWithFriendlyError, runCommandInputSchema } from "@perstack/core"
|
|
5
|
+
import { Command } from "commander"
|
|
6
|
+
import pkg from "../package.json" with { type: "json" }
|
|
7
|
+
import { resolveRunContext } from "../src/cli/context.js"
|
|
8
|
+
import { run } from "../src/run.js"
|
|
9
|
+
|
|
10
|
+
const defaultEventListener = (event: RunEvent | RuntimeEvent) => console.log(JSON.stringify(event))
|
|
11
|
+
|
|
12
|
+
const checkpointStore = new Map<string, Checkpoint>()
|
|
13
|
+
const storeCheckpoint = async (checkpoint: Checkpoint) => {
|
|
14
|
+
checkpointStore.set(checkpoint.id, checkpoint)
|
|
15
|
+
}
|
|
16
|
+
const retrieveCheckpoint = async (_jobId: string, checkpointId: string) => {
|
|
17
|
+
const checkpoint = checkpointStore.get(checkpointId)
|
|
18
|
+
if (!checkpoint) {
|
|
19
|
+
throw new Error(`Checkpoint not found: ${checkpointId}`)
|
|
20
|
+
}
|
|
21
|
+
return checkpoint
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const program = new Command()
|
|
25
|
+
.name("perstack-runtime")
|
|
26
|
+
.description("Perstack Runtime CLI - Execute Experts directly")
|
|
27
|
+
.version(pkg.version)
|
|
28
|
+
|
|
29
|
+
program
|
|
30
|
+
.command("run")
|
|
31
|
+
.description("Run an Expert with JSON event output")
|
|
32
|
+
.argument("<expertKey>", "Expert key to run")
|
|
33
|
+
.argument("<query>", "Query to run")
|
|
34
|
+
.option("--config <configPath>", "Path to perstack.toml config file")
|
|
35
|
+
.option("--provider <provider>", "Provider to use")
|
|
36
|
+
.option("--model <model>", "Model to use")
|
|
37
|
+
.option("--temperature <temperature>", "Temperature for the model, default is 0.3")
|
|
38
|
+
.option(
|
|
39
|
+
"--max-steps <maxSteps>",
|
|
40
|
+
"Maximum number of steps to run, default is undefined (no limit)",
|
|
41
|
+
)
|
|
42
|
+
.option("--max-retries <maxRetries>", "Maximum number of generation retries, default is 5")
|
|
43
|
+
.option(
|
|
44
|
+
"--timeout <timeout>",
|
|
45
|
+
"Timeout for each generation in milliseconds, default is 60000 (1 minute)",
|
|
46
|
+
)
|
|
47
|
+
.option("--job-id <jobId>", "Job ID for identifying the job")
|
|
48
|
+
.option("--run-id <runId>", "Run ID for identifying the run")
|
|
49
|
+
.option(
|
|
50
|
+
"--env-path <path>",
|
|
51
|
+
"Path to the environment file (can be specified multiple times), default is .env and .env.local",
|
|
52
|
+
(value: string, previous: string[]) => previous.concat(value),
|
|
53
|
+
[] as string[],
|
|
54
|
+
)
|
|
55
|
+
.option("--verbose", "Enable verbose logging")
|
|
56
|
+
.action(async (expertKey, query, options) => {
|
|
57
|
+
const input = parseWithFriendlyError(runCommandInputSchema, { expertKey, query, options })
|
|
58
|
+
try {
|
|
59
|
+
const { perstackConfig, env, providerConfig, model, experts } = await resolveRunContext({
|
|
60
|
+
configPath: input.options.config,
|
|
61
|
+
provider: input.options.provider,
|
|
62
|
+
model: input.options.model,
|
|
63
|
+
envPath: input.options.envPath,
|
|
64
|
+
})
|
|
65
|
+
await run(
|
|
66
|
+
{
|
|
67
|
+
setting: {
|
|
68
|
+
jobId: input.options.jobId,
|
|
69
|
+
runId: input.options.runId,
|
|
70
|
+
expertKey: input.expertKey,
|
|
71
|
+
input: { text: input.query },
|
|
72
|
+
experts,
|
|
73
|
+
model,
|
|
74
|
+
providerConfig,
|
|
75
|
+
temperature: input.options.temperature ?? perstackConfig.temperature,
|
|
76
|
+
maxSteps: input.options.maxSteps ?? perstackConfig.maxSteps,
|
|
77
|
+
maxRetries: input.options.maxRetries ?? perstackConfig.maxRetries,
|
|
78
|
+
timeout: input.options.timeout ?? perstackConfig.timeout,
|
|
79
|
+
perstackApiBaseUrl: perstackConfig.perstackApiBaseUrl,
|
|
80
|
+
perstackApiKey: env.PERSTACK_API_KEY,
|
|
81
|
+
perstackBaseSkillCommand: perstackConfig.perstackBaseSkillCommand,
|
|
82
|
+
env,
|
|
83
|
+
proxyUrl: process.env.PERSTACK_PROXY_URL,
|
|
84
|
+
verbose: input.options.verbose,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{ eventListener: defaultEventListener, storeCheckpoint, retrieveCheckpoint },
|
|
88
|
+
)
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (error instanceof Error) {
|
|
91
|
+
console.error(error.message)
|
|
92
|
+
} else {
|
|
93
|
+
console.error(error)
|
|
94
|
+
}
|
|
95
|
+
process.exit(1)
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
program.parse()
|
package/dist/bin/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { package_default, run } from '../chunk-
|
|
2
|
+
import { package_default, run } from '../chunk-H65LPOAK.js';
|
|
3
3
|
import { parseWithFriendlyError, runCommandInputSchema, perstackConfigSchema } from '@perstack/core';
|
|
4
4
|
import { Command } from 'commander';
|
|
5
5
|
import dotenv from 'dotenv';
|