@promptbook/node 0.114.0-24 → 0.114.0-25
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/esm/index.es.js +226 -46
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-codex-prompts/runners/common/estimateUsageFromTextLength.d.ts +33 -0
- package/esm/scripts/run-codex-prompts/runners/common/modelPricing.d.ts +41 -0
- package/esm/scripts/run-codex-prompts/runners/gemini/gemini-pricing.d.ts +5 -18
- package/esm/scripts/run-codex-prompts/runners/qwen-code/QwenCodeRunner.d.ts +23 -0
- package/esm/scripts/run-codex-prompts/runners/qwen-code/buildQwenCodeScript.d.ts +8 -0
- package/esm/scripts/run-codex-prompts/runners/qwen-code/parseQwenCodeUsageFromOutput.d.ts +9 -0
- package/esm/scripts/run-codex-prompts/runners/qwen-code/qwen-code-pricing.d.ts +30 -0
- package/esm/src/book-3.0/cliAgentEnv.d.ts +3 -3
- package/esm/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +8 -2
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +226 -46
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-codex-prompts/runners/common/estimateUsageFromTextLength.d.ts +33 -0
- package/umd/scripts/run-codex-prompts/runners/common/modelPricing.d.ts +41 -0
- package/umd/scripts/run-codex-prompts/runners/gemini/gemini-pricing.d.ts +5 -18
- package/umd/scripts/run-codex-prompts/runners/qwen-code/QwenCodeRunner.d.ts +23 -0
- package/umd/scripts/run-codex-prompts/runners/qwen-code/buildQwenCodeScript.d.ts +8 -0
- package/umd/scripts/run-codex-prompts/runners/qwen-code/parseQwenCodeUsageFromOutput.d.ts +9 -0
- package/umd/scripts/run-codex-prompts/runners/qwen-code/qwen-code-pricing.d.ts +30 -0
- package/umd/src/book-3.0/cliAgentEnv.d.ts +3 -3
- package/umd/src/cli/cli-commands/common/promptRunnerCliOptions.d.ts +8 -2
- package/umd/src/version.d.ts +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Usage } from '../../../../src/execution/Usage';
|
|
2
|
+
import type { ModelPricing } from './modelPricing';
|
|
3
|
+
/**
|
|
4
|
+
* Options for estimating the usage of one harness run.
|
|
5
|
+
*/
|
|
6
|
+
export type EstimateUsageFromTextLengthOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Human-readable harness name used when the estimation itself fails.
|
|
9
|
+
*/
|
|
10
|
+
readonly harnessLabel: string;
|
|
11
|
+
/**
|
|
12
|
+
* The prompt that was sent to the harness.
|
|
13
|
+
*/
|
|
14
|
+
readonly prompt: string;
|
|
15
|
+
/**
|
|
16
|
+
* The output which the harness has printed.
|
|
17
|
+
*/
|
|
18
|
+
readonly output: string;
|
|
19
|
+
/**
|
|
20
|
+
* Reads the pricing of the model which was used for this run.
|
|
21
|
+
*
|
|
22
|
+
* It is resolved lazily so that a broken pricing table degrades to an uncertain estimate
|
|
23
|
+
* instead of failing the coding round, because a price estimate must never block coding work.
|
|
24
|
+
*/
|
|
25
|
+
readonly resolvePricing: () => ModelPricing;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Estimates the usage of one harness run from the length of its prompt and its output.
|
|
29
|
+
*
|
|
30
|
+
* Harnesses which do not report their own token counts are billed per token anyway, so the
|
|
31
|
+
* character counts are the only signal available for a price estimate.
|
|
32
|
+
*/
|
|
33
|
+
export declare function estimateUsageFromTextLength(options: EstimateUsageFromTextLengthOptions): Usage;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Price of one model per 1 million tokens in USD.
|
|
3
|
+
*/
|
|
4
|
+
export type ModelPricing = {
|
|
5
|
+
/**
|
|
6
|
+
* Price of 1 million input tokens in USD.
|
|
7
|
+
*/
|
|
8
|
+
readonly input: number;
|
|
9
|
+
/**
|
|
10
|
+
* Price of 1 million output tokens in USD.
|
|
11
|
+
*/
|
|
12
|
+
readonly output: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Pricing of all known models of one harness, keyed by the model identifier.
|
|
16
|
+
*/
|
|
17
|
+
export type ModelPricingTable = Readonly<Record<string, ModelPricing>>;
|
|
18
|
+
/**
|
|
19
|
+
* Options for resolving the pricing of one model.
|
|
20
|
+
*/
|
|
21
|
+
export type ResolveModelPricingOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* Pricing of all models known to one harness.
|
|
24
|
+
*/
|
|
25
|
+
readonly pricingTable: ModelPricingTable;
|
|
26
|
+
/**
|
|
27
|
+
* Model whose pricing is used when the requested model is unknown.
|
|
28
|
+
*/
|
|
29
|
+
readonly modelNameForEstimation: string;
|
|
30
|
+
/**
|
|
31
|
+
* Model requested for the run, or `undefined` when the harness picks its own model.
|
|
32
|
+
*/
|
|
33
|
+
readonly modelName?: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Resolves the pricing of one model of one harness.
|
|
37
|
+
*
|
|
38
|
+
* It first tries exact match, then prefix match, then falls back to the pricing of a stable
|
|
39
|
+
* default model, because every harness names new models faster than the pricing tables grow.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveModelPricing(options: ResolveModelPricingOptions): ModelPricing;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ModelPricing } from '../common/modelPricing';
|
|
1
2
|
/**
|
|
2
3
|
* The pricing for Gemini models per 1 million tokens in USD.
|
|
3
4
|
*
|
|
@@ -6,30 +7,16 @@
|
|
|
6
7
|
* @see https://ai.google.dev/pricing
|
|
7
8
|
*/
|
|
8
9
|
export declare const GEMINI_PRICING: {
|
|
9
|
-
'gemini-1.5-flash': {
|
|
10
|
-
input:
|
|
11
|
-
output:
|
|
10
|
+
readonly 'gemini-1.5-flash': {
|
|
11
|
+
readonly input: 0.1125;
|
|
12
|
+
readonly output: 0.45;
|
|
12
13
|
};
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
16
|
* The model to use for price estimation.
|
|
16
17
|
*/
|
|
17
18
|
export declare const GEMINI_MODEL_FOR_ESTIMATION = "gemini-1.5-flash";
|
|
18
|
-
/**
|
|
19
|
-
* Gemini pricing entry per 1 million tokens.
|
|
20
|
-
*/
|
|
21
|
-
export type GeminiPricing = {
|
|
22
|
-
input: number;
|
|
23
|
-
output: number;
|
|
24
|
-
};
|
|
25
19
|
/**
|
|
26
20
|
* Resolves Gemini pricing for the requested model.
|
|
27
|
-
*
|
|
28
|
-
* It first tries exact match, then prefix match, then falls back to a stable
|
|
29
|
-
* default pricing model.
|
|
30
|
-
*/
|
|
31
|
-
export declare function resolveGeminiPricing(modelName?: string): GeminiPricing;
|
|
32
|
-
/**
|
|
33
|
-
* A an estimation of how many characters are in one token.
|
|
34
21
|
*/
|
|
35
|
-
export declare
|
|
22
|
+
export declare function resolveGeminiPricing(modelName?: string): ModelPricing;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PromptRunner } from '../types/PromptRunner';
|
|
2
|
+
import type { PromptRunOptions } from '../types/PromptRunOptions';
|
|
3
|
+
import type { PromptRunResult } from '../types/PromptRunResult';
|
|
4
|
+
import type { QwenCodeRunnerOptions } from './QwenCodeRunnerOptions';
|
|
5
|
+
/**
|
|
6
|
+
* Default Qwen Code model used by the coding runner.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_QWEN_CODE_MODEL = "qwen3.8-max";
|
|
9
|
+
/**
|
|
10
|
+
* Runs prompts via the Qwen Code CLI.
|
|
11
|
+
*/
|
|
12
|
+
export declare class QwenCodeRunner implements PromptRunner {
|
|
13
|
+
private readonly options;
|
|
14
|
+
readonly name = "qwen-code";
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Qwen Code runner.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options: QwenCodeRunnerOptions);
|
|
19
|
+
/**
|
|
20
|
+
* Runs the prompt using Qwen Code and parses usage output.
|
|
21
|
+
*/
|
|
22
|
+
runPrompt(options: PromptRunOptions): Promise<PromptRunResult>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { QwenCodeScriptOptions } from './QwenCodeScriptOptions';
|
|
2
|
+
/**
|
|
3
|
+
* Builds the shell script that runs Qwen Code with the prompt and coding context.
|
|
4
|
+
*
|
|
5
|
+
* Note: `-y` runs the harness unattended, because `ptbk coder` approves the whole prompt
|
|
6
|
+
* up front and there is nobody at the keyboard to confirm the single tool calls.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildQwenCodeScript(options: QwenCodeScriptOptions): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Usage } from '../../../../src/execution/Usage';
|
|
2
|
+
/**
|
|
3
|
+
* Parses Qwen Code CLI output and extracts usage information.
|
|
4
|
+
*
|
|
5
|
+
* @param output The output from the Qwen Code CLI.
|
|
6
|
+
* @param prompt The prompt that was sent to the Qwen Code CLI.
|
|
7
|
+
* @param modelName The Qwen Code model used for this run.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseQwenCodeUsageFromOutput(output: string, prompt: string, modelName?: string): Usage;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ModelPricing } from '../common/modelPricing';
|
|
2
|
+
/**
|
|
3
|
+
* The pricing for Qwen Code models per 1 million tokens in USD.
|
|
4
|
+
*
|
|
5
|
+
* Note: This is an estimation.
|
|
6
|
+
*
|
|
7
|
+
* @see https://www.alibabacloud.com/help/en/model-studio/models
|
|
8
|
+
*/
|
|
9
|
+
export declare const QWEN_CODE_PRICING: {
|
|
10
|
+
readonly 'qwen3-coder-plus': {
|
|
11
|
+
readonly input: 1;
|
|
12
|
+
readonly output: 5;
|
|
13
|
+
};
|
|
14
|
+
readonly 'qwen3-coder-flash': {
|
|
15
|
+
readonly input: 0.3;
|
|
16
|
+
readonly output: 1.5;
|
|
17
|
+
};
|
|
18
|
+
readonly 'qwen3-max': {
|
|
19
|
+
readonly input: 1.2;
|
|
20
|
+
readonly output: 6;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The model to use for price estimation.
|
|
25
|
+
*/
|
|
26
|
+
export declare const QWEN_CODE_MODEL_FOR_ESTIMATION = "qwen3-coder-plus";
|
|
27
|
+
/**
|
|
28
|
+
* Resolves Qwen Code pricing for the requested model.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveQwenCodePricing(modelName?: string): ModelPricing;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @public exported from `@promptbook/node`
|
|
5
5
|
*/
|
|
6
|
-
export declare const CLI_AGENT_HARNESS_NAMES: readonly ["openai-codex", "github-copilot", "cline", "claude-code", "opencode", "gemini"];
|
|
6
|
+
export declare const CLI_AGENT_HARNESS_NAMES: readonly ["openai-codex", "github-copilot", "cline", "claude-code", "opencode", "gemini", "qwen-code"];
|
|
7
7
|
/**
|
|
8
8
|
* All supported thinking-level values for CLI coding-agent runners.
|
|
9
9
|
*
|
|
@@ -13,8 +13,8 @@ export declare const CLI_AGENT_THINKING_LEVEL_VALUES: readonly ["low", "medium",
|
|
|
13
13
|
/**
|
|
14
14
|
* Environment variable used as the default runner identifier when `--harness` is omitted or not set in `CliAgent`.
|
|
15
15
|
*
|
|
16
|
-
* Set this to one of the harness names (`openai-codex`, `github-copilot`, `cline`, `claude-code`, `opencode`, `gemini
|
|
17
|
-
* so that `CliAgent` and `ptbk agent exec` can run without an explicit `harness` option.
|
|
16
|
+
* Set this to one of the harness names (`openai-codex`, `github-copilot`, `cline`, `claude-code`, `opencode`, `gemini`,
|
|
17
|
+
* `qwen-code`) so that `CliAgent` and `ptbk agent exec` can run without an explicit `harness` option.
|
|
18
18
|
*
|
|
19
19
|
* @public exported from `@promptbook/node`
|
|
20
20
|
*/
|
|
@@ -8,7 +8,7 @@ export { PTBK_HARNESS_ENV, PTBK_MODEL_ENV, PTBK_THINKING_LEVEL_ENV };
|
|
|
8
8
|
*
|
|
9
9
|
* @private internal utility of `promptbookCli`
|
|
10
10
|
*/
|
|
11
|
-
export declare const PROMPT_RUNNER_HARNESS_NAMES: readonly ["openai-codex", "github-copilot", "cline", "claude-code", "opencode", "gemini"];
|
|
11
|
+
export declare const PROMPT_RUNNER_HARNESS_NAMES: readonly ["openai-codex", "github-copilot", "cline", "claude-code", "opencode", "gemini", "qwen-code"];
|
|
12
12
|
/**
|
|
13
13
|
* Runner identifier supported by Promptbook CLI agent orchestration commands.
|
|
14
14
|
*
|
|
@@ -72,7 +72,13 @@ export declare const PROMPT_RUNNER_DESCRIPTION: string;
|
|
|
72
72
|
*
|
|
73
73
|
* @private internal utility of `promptbookCli`
|
|
74
74
|
*/
|
|
75
|
-
export declare const PROMPT_RUNNER_HARNESS_OPTION_DESCRIPTION
|
|
75
|
+
export declare const PROMPT_RUNNER_HARNESS_OPTION_DESCRIPTION: string;
|
|
76
|
+
/**
|
|
77
|
+
* Runner harness names listed as alternatives of the `--harness` option in error messages.
|
|
78
|
+
*
|
|
79
|
+
* @private internal utility of `promptbookCli`
|
|
80
|
+
*/
|
|
81
|
+
export declare const PROMPT_RUNNER_HARNESS_OPTION_HINT: string;
|
|
76
82
|
/**
|
|
77
83
|
* Commander description for the `--model` option.
|
|
78
84
|
*
|
package/esm/src/version.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
|
|
|
15
15
|
export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
|
|
16
16
|
/**
|
|
17
17
|
* Represents the version string of the Promptbook engine.
|
|
18
|
-
* It follows semantic versioning (e.g., `0.114.0-
|
|
18
|
+
* It follows semantic versioning (e.g., `0.114.0-24`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/node",
|
|
3
|
-
"version": "0.114.0-
|
|
3
|
+
"version": "0.114.0-25",
|
|
4
4
|
"description": "Promptbook: Create persistent AI agents that turn your company's scattered knowledge into action",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"types": "./esm/src/_packages/node.index.d.ts",
|
|
98
98
|
"typings": "./esm/src/_packages/node.index.d.ts",
|
|
99
99
|
"peerDependencies": {
|
|
100
|
-
"@promptbook/core": "0.114.0-
|
|
100
|
+
"@promptbook/core": "0.114.0-25"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
103
|
"@openai/agents": "0.4.15",
|
package/umd/index.umd.js
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
* @generated
|
|
48
48
|
* @see https://github.com/webgptorg/promptbook
|
|
49
49
|
*/
|
|
50
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-
|
|
50
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.114.0-25';
|
|
51
51
|
/**
|
|
52
52
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
53
53
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -1837,6 +1837,12 @@
|
|
|
1837
1837
|
commandName: 'gemini',
|
|
1838
1838
|
npmPackageName: '@google/gemini-cli',
|
|
1839
1839
|
},
|
|
1840
|
+
'qwen-code': {
|
|
1841
|
+
harnessName: 'qwen-code',
|
|
1842
|
+
label: 'Qwen Code',
|
|
1843
|
+
commandName: 'qwen',
|
|
1844
|
+
npmPackageName: '@qwen-code/qwen-code',
|
|
1845
|
+
},
|
|
1840
1846
|
};
|
|
1841
1847
|
/**
|
|
1842
1848
|
* Looks up the definition of one supported CLI coding harness.
|
|
@@ -4136,6 +4142,71 @@
|
|
|
4136
4142
|
return { value };
|
|
4137
4143
|
}
|
|
4138
4144
|
|
|
4145
|
+
/**
|
|
4146
|
+
* An estimation of how many characters are in one token.
|
|
4147
|
+
*/
|
|
4148
|
+
const CHARS_PER_TOKEN = 4;
|
|
4149
|
+
/**
|
|
4150
|
+
* Estimates the usage of one harness run from the length of its prompt and its output.
|
|
4151
|
+
*
|
|
4152
|
+
* Harnesses which do not report their own token counts are billed per token anyway, so the
|
|
4153
|
+
* character counts are the only signal available for a price estimate.
|
|
4154
|
+
*/
|
|
4155
|
+
function estimateUsageFromTextLength(options) {
|
|
4156
|
+
const { harnessLabel, prompt, output, resolvePricing } = options;
|
|
4157
|
+
try {
|
|
4158
|
+
const pricing = resolvePricing();
|
|
4159
|
+
const inputTokens = Math.ceil(prompt.length / CHARS_PER_TOKEN);
|
|
4160
|
+
const outputTokens = Math.ceil(output.length / CHARS_PER_TOKEN);
|
|
4161
|
+
const price = uncertainNumber((inputTokens / 1000000) * pricing.input + (outputTokens / 1000000) * pricing.output);
|
|
4162
|
+
return {
|
|
4163
|
+
...UNCERTAIN_USAGE,
|
|
4164
|
+
price,
|
|
4165
|
+
input: {
|
|
4166
|
+
...UNCERTAIN_USAGE.input,
|
|
4167
|
+
tokensCount: uncertainNumber(inputTokens),
|
|
4168
|
+
},
|
|
4169
|
+
output: {
|
|
4170
|
+
...UNCERTAIN_USAGE.output,
|
|
4171
|
+
tokensCount: uncertainNumber(outputTokens),
|
|
4172
|
+
},
|
|
4173
|
+
};
|
|
4174
|
+
}
|
|
4175
|
+
catch (error) {
|
|
4176
|
+
console.error(colors__default["default"].bgRed(`Error parsing ${harnessLabel} usage output:`), error);
|
|
4177
|
+
return UNCERTAIN_USAGE;
|
|
4178
|
+
}
|
|
4179
|
+
}
|
|
4180
|
+
|
|
4181
|
+
/**
|
|
4182
|
+
* Resolves the pricing of one model of one harness.
|
|
4183
|
+
*
|
|
4184
|
+
* It first tries exact match, then prefix match, then falls back to the pricing of a stable
|
|
4185
|
+
* default model, because every harness names new models faster than the pricing tables grow.
|
|
4186
|
+
*/
|
|
4187
|
+
function resolveModelPricing(options) {
|
|
4188
|
+
var _a;
|
|
4189
|
+
const { pricingTable, modelNameForEstimation, modelName } = options;
|
|
4190
|
+
const fallbackPricing = pricingTable[modelNameForEstimation];
|
|
4191
|
+
if (fallbackPricing === undefined) {
|
|
4192
|
+
throw new UnexpectedError(spaceTrim(`
|
|
4193
|
+
Missing pricing of the model \`${modelNameForEstimation}\` used for price estimation.
|
|
4194
|
+
|
|
4195
|
+
**The model used for estimation must always be listed in its own pricing table.**
|
|
4196
|
+
`));
|
|
4197
|
+
}
|
|
4198
|
+
if (!modelName) {
|
|
4199
|
+
return fallbackPricing;
|
|
4200
|
+
}
|
|
4201
|
+
const exactMatch = pricingTable[modelName];
|
|
4202
|
+
if (exactMatch) {
|
|
4203
|
+
return exactMatch;
|
|
4204
|
+
}
|
|
4205
|
+
const prefixMatch = (_a = Object.entries(pricingTable).find(([knownModelName]) => modelName.startsWith(knownModelName))) === null || _a === void 0 ? void 0 : _a[1];
|
|
4206
|
+
return prefixMatch !== null && prefixMatch !== void 0 ? prefixMatch : fallbackPricing;
|
|
4207
|
+
}
|
|
4208
|
+
// Note: [💞] Ignore a discrepancy between file name and entity name
|
|
4209
|
+
|
|
4139
4210
|
/**
|
|
4140
4211
|
* The pricing for Gemini models per 1 million tokens in USD.
|
|
4141
4212
|
*
|
|
@@ -4155,27 +4226,14 @@
|
|
|
4155
4226
|
const GEMINI_MODEL_FOR_ESTIMATION = 'gemini-1.5-flash';
|
|
4156
4227
|
/**
|
|
4157
4228
|
* Resolves Gemini pricing for the requested model.
|
|
4158
|
-
*
|
|
4159
|
-
* It first tries exact match, then prefix match, then falls back to a stable
|
|
4160
|
-
* default pricing model.
|
|
4161
4229
|
*/
|
|
4162
4230
|
function resolveGeminiPricing(modelName) {
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
}
|
|
4168
|
-
const exactMatch = GEMINI_PRICING[modelName];
|
|
4169
|
-
if (exactMatch) {
|
|
4170
|
-
return exactMatch;
|
|
4171
|
-
}
|
|
4172
|
-
const prefixMatch = (_a = Object.entries(GEMINI_PRICING).find(([knownModel]) => modelName.startsWith(knownModel))) === null || _a === void 0 ? void 0 : _a[1];
|
|
4173
|
-
return prefixMatch !== null && prefixMatch !== void 0 ? prefixMatch : fallbackPricing;
|
|
4231
|
+
return resolveModelPricing({
|
|
4232
|
+
pricingTable: GEMINI_PRICING,
|
|
4233
|
+
modelNameForEstimation: GEMINI_MODEL_FOR_ESTIMATION,
|
|
4234
|
+
modelName,
|
|
4235
|
+
});
|
|
4174
4236
|
}
|
|
4175
|
-
/**
|
|
4176
|
-
* A an estimation of how many characters are in one token.
|
|
4177
|
-
*/
|
|
4178
|
-
const CHARS_PER_TOKEN = 4;
|
|
4179
4237
|
|
|
4180
4238
|
/**
|
|
4181
4239
|
* Parses Gemini CLI output and extracts usage information.
|
|
@@ -4185,28 +4243,12 @@
|
|
|
4185
4243
|
* @param modelName The Gemini model used for this run.
|
|
4186
4244
|
*/
|
|
4187
4245
|
function parseGeminiUsageFromOutput(output, prompt, modelName) {
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
...UNCERTAIN_USAGE,
|
|
4195
|
-
price,
|
|
4196
|
-
input: {
|
|
4197
|
-
...UNCERTAIN_USAGE.input,
|
|
4198
|
-
tokensCount: uncertainNumber(inputTokens),
|
|
4199
|
-
},
|
|
4200
|
-
output: {
|
|
4201
|
-
...UNCERTAIN_USAGE.output,
|
|
4202
|
-
tokensCount: uncertainNumber(outputTokens),
|
|
4203
|
-
},
|
|
4204
|
-
};
|
|
4205
|
-
}
|
|
4206
|
-
catch (error) {
|
|
4207
|
-
console.error(colors__default["default"].bgRed('Error parsing Gemini usage output:'), error);
|
|
4208
|
-
return UNCERTAIN_USAGE;
|
|
4209
|
-
}
|
|
4246
|
+
return estimateUsageFromTextLength({
|
|
4247
|
+
harnessLabel: 'Gemini',
|
|
4248
|
+
prompt,
|
|
4249
|
+
output,
|
|
4250
|
+
resolvePricing: () => resolveGeminiPricing(modelName),
|
|
4251
|
+
});
|
|
4210
4252
|
}
|
|
4211
4253
|
|
|
4212
4254
|
/**
|
|
@@ -5653,6 +5695,114 @@
|
|
|
5653
5695
|
}
|
|
5654
5696
|
}
|
|
5655
5697
|
|
|
5698
|
+
/**
|
|
5699
|
+
* Delimiter used for passing large prompts to the Qwen Code CLI.
|
|
5700
|
+
*/
|
|
5701
|
+
const QWEN_CODE_PROMPT_DELIMITER = 'QWEN_CODE_PROMPT';
|
|
5702
|
+
/**
|
|
5703
|
+
* Builds the shell script that runs Qwen Code with the prompt and coding context.
|
|
5704
|
+
*
|
|
5705
|
+
* Note: `-y` runs the harness unattended, because `ptbk coder` approves the whole prompt
|
|
5706
|
+
* up front and there is nobody at the keyboard to confirm the single tool calls.
|
|
5707
|
+
*/
|
|
5708
|
+
function buildQwenCodeScript(options) {
|
|
5709
|
+
return spaceTrim((block) => `
|
|
5710
|
+
qwen -y -m ${options.model} -p "$(cat <<'${QWEN_CODE_PROMPT_DELIMITER}'
|
|
5711
|
+
|
|
5712
|
+
${block(options.prompt)}
|
|
5713
|
+
|
|
5714
|
+
${QWEN_CODE_PROMPT_DELIMITER}
|
|
5715
|
+
)"
|
|
5716
|
+
`);
|
|
5717
|
+
}
|
|
5718
|
+
|
|
5719
|
+
/**
|
|
5720
|
+
* The pricing for Qwen Code models per 1 million tokens in USD.
|
|
5721
|
+
*
|
|
5722
|
+
* Note: This is an estimation.
|
|
5723
|
+
*
|
|
5724
|
+
* @see https://www.alibabacloud.com/help/en/model-studio/models
|
|
5725
|
+
*/
|
|
5726
|
+
const QWEN_CODE_PRICING = {
|
|
5727
|
+
'qwen3-coder-plus': {
|
|
5728
|
+
input: 1,
|
|
5729
|
+
output: 5,
|
|
5730
|
+
},
|
|
5731
|
+
'qwen3-coder-flash': {
|
|
5732
|
+
input: 0.3,
|
|
5733
|
+
output: 1.5,
|
|
5734
|
+
},
|
|
5735
|
+
'qwen3-max': {
|
|
5736
|
+
input: 1.2,
|
|
5737
|
+
output: 6,
|
|
5738
|
+
},
|
|
5739
|
+
};
|
|
5740
|
+
/**
|
|
5741
|
+
* The model to use for price estimation.
|
|
5742
|
+
*/
|
|
5743
|
+
const QWEN_CODE_MODEL_FOR_ESTIMATION = 'qwen3-coder-plus';
|
|
5744
|
+
/**
|
|
5745
|
+
* Resolves Qwen Code pricing for the requested model.
|
|
5746
|
+
*/
|
|
5747
|
+
function resolveQwenCodePricing(modelName) {
|
|
5748
|
+
return resolveModelPricing({
|
|
5749
|
+
pricingTable: QWEN_CODE_PRICING,
|
|
5750
|
+
modelNameForEstimation: QWEN_CODE_MODEL_FOR_ESTIMATION,
|
|
5751
|
+
modelName,
|
|
5752
|
+
});
|
|
5753
|
+
}
|
|
5754
|
+
|
|
5755
|
+
/**
|
|
5756
|
+
* Parses Qwen Code CLI output and extracts usage information.
|
|
5757
|
+
*
|
|
5758
|
+
* @param output The output from the Qwen Code CLI.
|
|
5759
|
+
* @param prompt The prompt that was sent to the Qwen Code CLI.
|
|
5760
|
+
* @param modelName The Qwen Code model used for this run.
|
|
5761
|
+
*/
|
|
5762
|
+
function parseQwenCodeUsageFromOutput(output, prompt, modelName) {
|
|
5763
|
+
return estimateUsageFromTextLength({
|
|
5764
|
+
harnessLabel: 'Qwen Code',
|
|
5765
|
+
prompt,
|
|
5766
|
+
output,
|
|
5767
|
+
resolvePricing: () => resolveQwenCodePricing(modelName),
|
|
5768
|
+
});
|
|
5769
|
+
}
|
|
5770
|
+
|
|
5771
|
+
/**
|
|
5772
|
+
* Default Qwen Code model used by the coding runner.
|
|
5773
|
+
*/
|
|
5774
|
+
const DEFAULT_QWEN_CODE_MODEL = 'qwen3.8-max';
|
|
5775
|
+
/**
|
|
5776
|
+
* Runs prompts via the Qwen Code CLI.
|
|
5777
|
+
*/
|
|
5778
|
+
class QwenCodeRunner {
|
|
5779
|
+
/**
|
|
5780
|
+
* Creates a new Qwen Code runner.
|
|
5781
|
+
*/
|
|
5782
|
+
constructor(options) {
|
|
5783
|
+
this.options = options;
|
|
5784
|
+
this.name = 'qwen-code';
|
|
5785
|
+
}
|
|
5786
|
+
/**
|
|
5787
|
+
* Runs the prompt using Qwen Code and parses usage output.
|
|
5788
|
+
*/
|
|
5789
|
+
async runPrompt(options) {
|
|
5790
|
+
const scriptContent = buildQwenCodeScript({
|
|
5791
|
+
prompt: options.prompt,
|
|
5792
|
+
model: this.options.model,
|
|
5793
|
+
});
|
|
5794
|
+
const output = await $runGoScriptWithOutput({
|
|
5795
|
+
scriptPath: options.scriptPath,
|
|
5796
|
+
scriptContent,
|
|
5797
|
+
logPath: options.logPath,
|
|
5798
|
+
shouldPrintLiveOutput: options.shouldPrintLiveOutput,
|
|
5799
|
+
preserveArtifactsOnSuccess: options.preserveArtifactsOnSuccess,
|
|
5800
|
+
});
|
|
5801
|
+
const usage = parseQwenCodeUsageFromOutput(output, options.prompt, this.options.model);
|
|
5802
|
+
return { usage };
|
|
5803
|
+
}
|
|
5804
|
+
}
|
|
5805
|
+
|
|
5656
5806
|
/**
|
|
5657
5807
|
* Constant for default codex model.
|
|
5658
5808
|
*/
|
|
@@ -5661,6 +5811,11 @@
|
|
|
5661
5811
|
* Constant for cline model.
|
|
5662
5812
|
*/
|
|
5663
5813
|
const CLINE_MODEL = 'gemini:gemini-3-flash-preview';
|
|
5814
|
+
/**
|
|
5815
|
+
* Harnesses which refuse to run without an explicit `--model`, because they expose many models
|
|
5816
|
+
* of very different capability and price and never pick a sensible one on their own.
|
|
5817
|
+
*/
|
|
5818
|
+
const MODEL_REQUIRING_HARNESS_NAMES = ['openai-codex', 'gemini', 'qwen-code'];
|
|
5664
5819
|
/**
|
|
5665
5820
|
* Resolves the configured prompt runner together with status-line metadata.
|
|
5666
5821
|
*
|
|
@@ -5698,6 +5853,9 @@
|
|
|
5698
5853
|
if (agentName === 'gemini') {
|
|
5699
5854
|
return createGeminiRunnerResolution(options);
|
|
5700
5855
|
}
|
|
5856
|
+
if (agentName === 'qwen-code') {
|
|
5857
|
+
return createQwenCodeRunnerResolution(options);
|
|
5858
|
+
}
|
|
5701
5859
|
throw new Error(`Unknown harness: ${agentName}`);
|
|
5702
5860
|
}
|
|
5703
5861
|
/**
|
|
@@ -5739,6 +5897,23 @@
|
|
|
5739
5897
|
model: actualRunnerModel,
|
|
5740
5898
|
}), actualRunnerModel);
|
|
5741
5899
|
}
|
|
5900
|
+
/**
|
|
5901
|
+
* Builds the Qwen Code CLI runner resolution, including required-model validation.
|
|
5902
|
+
*/
|
|
5903
|
+
function createQwenCodeRunnerResolution(options) {
|
|
5904
|
+
const actualRunnerModel = resolveRequiredModel({
|
|
5905
|
+
agentName: 'qwen-code',
|
|
5906
|
+
providedModel: options.model,
|
|
5907
|
+
defaultModel: DEFAULT_QWEN_CODE_MODEL,
|
|
5908
|
+
exampleUsages: [
|
|
5909
|
+
`--harness qwen-code --model ${DEFAULT_QWEN_CODE_MODEL}`,
|
|
5910
|
+
'--harness qwen-code --model default',
|
|
5911
|
+
],
|
|
5912
|
+
});
|
|
5913
|
+
return createRunnerResolution(options, new QwenCodeRunner({
|
|
5914
|
+
model: actualRunnerModel,
|
|
5915
|
+
}), actualRunnerModel);
|
|
5916
|
+
}
|
|
5742
5917
|
/**
|
|
5743
5918
|
* Combines the instantiated runner with prompt status metadata.
|
|
5744
5919
|
*/
|
|
@@ -5754,9 +5929,7 @@
|
|
|
5754
5929
|
*/
|
|
5755
5930
|
function getRunnerMetadata(options, actualRunnerModel) {
|
|
5756
5931
|
const runnerName = options.agentName ? getHarnessDefinition(options.agentName).label : 'unknown';
|
|
5757
|
-
if (options.agentName === '
|
|
5758
|
-
options.agentName === 'github-copilot' ||
|
|
5759
|
-
options.agentName === 'gemini') {
|
|
5932
|
+
if (options.agentName === 'github-copilot' || isModelRequiringHarnessName(options.agentName)) {
|
|
5760
5933
|
return { runnerName, modelName: actualRunnerModel };
|
|
5761
5934
|
}
|
|
5762
5935
|
if (options.agentName === 'cline') {
|
|
@@ -5767,6 +5940,12 @@
|
|
|
5767
5940
|
}
|
|
5768
5941
|
return { runnerName };
|
|
5769
5942
|
}
|
|
5943
|
+
/**
|
|
5944
|
+
* Checks whether one harness refuses to run without an explicit `--model`.
|
|
5945
|
+
*/
|
|
5946
|
+
function isModelRequiringHarnessName(agentName) {
|
|
5947
|
+
return MODEL_REQUIRING_HARNESS_NAMES.includes(agentName);
|
|
5948
|
+
}
|
|
5770
5949
|
/**
|
|
5771
5950
|
* Resolves a runner model, allowing `default` but otherwise requiring an explicit value.
|
|
5772
5951
|
*/
|
|
@@ -30280,6 +30459,7 @@
|
|
|
30280
30459
|
'claude-code',
|
|
30281
30460
|
'opencode',
|
|
30282
30461
|
'gemini',
|
|
30462
|
+
'qwen-code',
|
|
30283
30463
|
];
|
|
30284
30464
|
/**
|
|
30285
30465
|
* All supported thinking-level values for CLI coding-agent runners.
|
|
@@ -30290,8 +30470,8 @@
|
|
|
30290
30470
|
/**
|
|
30291
30471
|
* Environment variable used as the default runner identifier when `--harness` is omitted or not set in `CliAgent`.
|
|
30292
30472
|
*
|
|
30293
|
-
* Set this to one of the harness names (`openai-codex`, `github-copilot`, `cline`, `claude-code`, `opencode`, `gemini
|
|
30294
|
-
* so that `CliAgent` and `ptbk agent exec` can run without an explicit `harness` option.
|
|
30473
|
+
* Set this to one of the harness names (`openai-codex`, `github-copilot`, `cline`, `claude-code`, `opencode`, `gemini`,
|
|
30474
|
+
* `qwen-code`) so that `CliAgent` and `ptbk agent exec` can run without an explicit `harness` option.
|
|
30295
30475
|
*
|
|
30296
30476
|
* @public exported from `@promptbook/node`
|
|
30297
30477
|
*/
|