@askalf/dario 3.30.9 → 3.30.10

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.
@@ -170,6 +170,20 @@ export interface RequestContext {
170
170
  * Replaces the entire request structure — tools, fields, ordering — with
171
171
  * what real CC sends. Only the conversation content is preserved.
172
172
  */
173
+ /** Valid values for the `--effort` flag. `'client'` passes through the client's own `output_config.effort` (falling back to `'high'` if the client didn't send one). dario#87. */
174
+ export type EffortValue = 'low' | 'medium' | 'high' | 'xhigh' | 'client';
175
+ export declare const VALID_EFFORT_VALUES: ReadonlyArray<EffortValue>;
176
+ /**
177
+ * Resolve the outbound `output_config.effort` value.
178
+ *
179
+ * undefined / 'high' → 'high' (current default, matches CC 2.1.116 wire value)
180
+ * 'low' / 'medium' / 'xhigh' → pin to that value
181
+ * 'client' → extract from `clientBody.output_config.effort`; fall back
182
+ * to 'high' if the client didn't send one or sent a non-string
183
+ *
184
+ * Exported for tests.
185
+ */
186
+ export declare function resolveEffort(flag: EffortValue | undefined, clientBody: Record<string, unknown>): string;
173
187
  export declare function buildCCRequest(clientBody: Record<string, unknown>, billingTag: string, cacheControl: {
174
188
  type: 'ephemeral';
175
189
  }, identity: {
@@ -180,6 +194,7 @@ export declare function buildCCRequest(clientBody: Record<string, unknown>, bill
180
194
  preserveTools?: boolean;
181
195
  hybridTools?: boolean;
182
196
  noAutoDetect?: boolean;
197
+ effort?: EffortValue;
183
198
  }): {
184
199
  body: Record<string, unknown>;
185
200
  toolMap: Map<string, ToolMapping>;
@@ -708,11 +708,29 @@ const TOOL_MAP = {
708
708
  },
709
709
  exit_worktree: { ccTool: 'ExitWorktree' },
710
710
  };
711
+ export const VALID_EFFORT_VALUES = ['low', 'medium', 'high', 'xhigh', 'client'];
711
712
  /**
712
- * Build a CC-template request from a client request.
713
- * Replaces the entire request structure — tools, fields, ordering — with
714
- * what real CC sends. Only the conversation content is preserved.
713
+ * Resolve the outbound `output_config.effort` value.
714
+ *
715
+ * undefined / 'high' 'high' (current default, matches CC 2.1.116 wire value)
716
+ * 'low' / 'medium' / 'xhigh' → pin to that value
717
+ * 'client' → extract from `clientBody.output_config.effort`; fall back
718
+ * to 'high' if the client didn't send one or sent a non-string
719
+ *
720
+ * Exported for tests.
715
721
  */
722
+ export function resolveEffort(flag, clientBody) {
723
+ if (flag === undefined)
724
+ return 'high';
725
+ if (flag === 'client') {
726
+ const clientOC = clientBody.output_config;
727
+ const clientEffort = clientOC?.effort;
728
+ if (typeof clientEffort === 'string' && clientEffort.length > 0)
729
+ return clientEffort;
730
+ return 'high';
731
+ }
732
+ return flag;
733
+ }
716
734
  export function buildCCRequest(clientBody, billingTag, cacheControl, identity, opts = {}) {
717
735
  const model = clientBody.model || 'claude-sonnet-4-6';
718
736
  const isHaiku = model.toLowerCase().includes('haiku');
@@ -979,7 +997,11 @@ export function buildCCRequest(clientBody, billingTag, cacheControl, identity, o
979
997
  if (!isHaiku) {
980
998
  ccRequest.thinking = { type: 'adaptive' };
981
999
  ccRequest.context_management = { edits: [{ type: 'clear_thinking_20251015', keep: 'all' }] };
982
- ccRequest.output_config = { effort: 'high' };
1000
+ // output_config.effort default is `'high'` (matches CC 2.1.116's wire
1001
+ // value). `--effort` flag overrides; `'client'` passes through whatever
1002
+ // the client sent (or falls back to `'high'` if the client didn't
1003
+ // include an output_config). See dario#87.
1004
+ ccRequest.output_config = { effort: resolveEffort(opts.effort, clientBody) };
983
1005
  }
984
1006
  ccRequest.stream = stream;
985
1007
  // Replay the captured top-level key order. The hardcoded build order above
package/dist/cli.d.ts CHANGED
@@ -9,6 +9,14 @@
9
9
  * dario refresh — Force token refresh
10
10
  * dario logout — Remove saved credentials
11
11
  */
12
+ import { type EffortValue } from './cc-template.js';
13
+ /**
14
+ * Parse the `--effort` flag + `DARIO_EFFORT` env. Validates against the
15
+ * allowed set; unrecognised values cause a non-zero exit with the list of
16
+ * valid choices (same philosophy as other strict parsers in this CLI).
17
+ * Flag value wins over env. Exported for tests. dario#87.
18
+ */
19
+ export declare function resolveEffortFlag(args: string[], env: string | undefined): EffortValue | undefined;
12
20
  /**
13
21
  * Parse a positive-integer env var. Returns undefined on unset, empty,
14
22
  * non-numeric, or non-positive values so the caller's default applies.
package/dist/cli.js CHANGED
@@ -37,6 +37,7 @@ import { join } from 'node:path';
37
37
  import { homedir } from 'node:os';
38
38
  import { startAutoOAuthFlow, startManualOAuthFlow, detectHeadlessEnvironment, getStatus, refreshTokens, loadCredentials } from './oauth.js';
39
39
  import { startProxy, sanitizeError } from './proxy.js';
40
+ import { VALID_EFFORT_VALUES } from './cc-template.js';
40
41
  import { listAccountAliases, loadAllAccounts, addAccountViaOAuth, removeAccount } from './accounts.js';
41
42
  import { listBackends, saveBackend, removeBackend } from './openai-backend.js';
42
43
  const args = process.argv.slice(2);
@@ -260,6 +261,16 @@ async function proxy() {
260
261
  ?? parsePositiveIntEnv(process.env['DARIO_MAX_QUEUED']);
261
262
  const queueTimeoutMs = parsePositiveIntFlag('--queue-timeout=')
262
263
  ?? parsePositiveIntEnv(process.env['DARIO_QUEUE_TIMEOUT_MS']);
264
+ // --effort=low|medium|high|xhigh|client — override the outbound
265
+ // output_config.effort (dario#87). Default (unset) pins 'high' to match
266
+ // CC 2.1.116's wire value. 'client' passes through whatever the client
267
+ // sent, falling back to 'high' if the client didn't include one.
268
+ //
269
+ // Risk: setting effort to a non-CC-default value may cause Anthropic's
270
+ // classifier to flip requests to 'overage' billing. Users opting in
271
+ // should watch the `representative-claim` response header via -v logs
272
+ // and revert to default if subscription billing breaks.
273
+ const effort = resolveEffortFlag(args, process.env['DARIO_EFFORT']);
263
274
  // Non-loopback bind without DARIO_API_KEY turns dario into an open
264
275
  // OAuth-subscription relay for anyone on the reachable network. Refuse
265
276
  // to start rather than rely on the operator to read the startup banner.
@@ -279,7 +290,25 @@ async function proxy() {
279
290
  console.error(`[dario] Override (not recommended): pass --unsafe-no-auth if you have out-of-band network controls and accept the risk.`);
280
291
  process.exit(1);
281
292
  }
282
- await startProxy({ port, host, verbose, verboseBodies, model, passthrough, preserveTools, hybridTools, noAutoDetect, strictTls, pacingMinMs, pacingJitterMs, drainOnClose, sessionIdleRotateMs, sessionRotateJitterMs, sessionMaxAgeMs, sessionPerClient, preserveOrchestrationTags, noLiveCapture, strictTemplate, maxConcurrent, maxQueued, queueTimeoutMs });
293
+ await startProxy({ port, host, verbose, verboseBodies, model, passthrough, preserveTools, hybridTools, noAutoDetect, strictTls, pacingMinMs, pacingJitterMs, drainOnClose, sessionIdleRotateMs, sessionRotateJitterMs, sessionMaxAgeMs, sessionPerClient, preserveOrchestrationTags, noLiveCapture, strictTemplate, maxConcurrent, maxQueued, queueTimeoutMs, effort });
294
+ }
295
+ /**
296
+ * Parse the `--effort` flag + `DARIO_EFFORT` env. Validates against the
297
+ * allowed set; unrecognised values cause a non-zero exit with the list of
298
+ * valid choices (same philosophy as other strict parsers in this CLI).
299
+ * Flag value wins over env. Exported for tests. dario#87.
300
+ */
301
+ export function resolveEffortFlag(args, env) {
302
+ const withValue = args.find(a => a.startsWith('--effort='));
303
+ const raw = withValue ? withValue.slice('--effort='.length) : env;
304
+ if (raw === undefined || raw === '')
305
+ return undefined;
306
+ const normalized = raw.trim().toLowerCase();
307
+ if (VALID_EFFORT_VALUES.includes(normalized)) {
308
+ return normalized;
309
+ }
310
+ console.error(`[dario] Invalid --effort value: ${JSON.stringify(raw)}. Must be one of: ${VALID_EFFORT_VALUES.join(', ')}.`);
311
+ process.exit(1);
283
312
  }
284
313
  /**
285
314
  * Parse a positive-integer env var. Returns undefined on unset, empty,
@@ -682,6 +711,17 @@ async function help() {
682
711
  dario returns 504 "queue-timeout"
683
712
  (default: 60000).
684
713
  Env: DARIO_QUEUE_TIMEOUT_MS. (dario#80)
714
+ --effort=<low|medium|high|xhigh|client>
715
+ Override the outbound output_config.effort
716
+ on non-haiku requests. Default (unset)
717
+ pins 'high' — matches CC 2.1.116's wire
718
+ value. 'client' passes through what the
719
+ client sent (falls back to 'high' if none).
720
+ WARNING: non-'high' values may cause
721
+ Anthropic's classifier to flip requests
722
+ to 'overage' billing; watch -v logs for
723
+ representative-claim changes.
724
+ Env: DARIO_EFFORT. (dario#87)
685
725
  --port=PORT Port to listen on (default: 3456)
686
726
  --host=ADDRESS Address to bind to (default: 127.0.0.1)
687
727
  Use 0.0.0.0 for LAN; see README for DARIO_API_KEY
package/dist/proxy.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type IncomingMessage } from 'node:http';
2
+ import { type EffortValue } from './cc-template.js';
2
3
  export declare function parseProviderPrefix(model: string): {
3
4
  provider: 'openai' | 'claude';
4
5
  model: string;
@@ -71,6 +72,14 @@ interface ProxyOptions {
71
72
  maxQueued?: number;
72
73
  /** Max ms a queued request waits before it times out with 504. Default 60000. dario#80. */
73
74
  queueTimeoutMs?: number;
75
+ /**
76
+ * Override the outbound `output_config.effort` value on non-haiku
77
+ * requests. Default (undefined) pins `'high'`, matching CC 2.1.116's
78
+ * wire value. `'client'` passes through whatever the client sent (or
79
+ * falls back to `'high'` if the client didn't include an output_config).
80
+ * dario#87.
81
+ */
82
+ effort?: EffortValue;
74
83
  }
75
84
  export declare function sanitizeError(err: unknown): string;
76
85
  /**
package/dist/proxy.js CHANGED
@@ -978,6 +978,7 @@ export async function startProxy(opts = {}) {
978
978
  preserveTools: opts.preserveTools ?? false,
979
979
  hybridTools: opts.hybridTools ?? false,
980
980
  noAutoDetect: opts.noAutoDetect ?? false,
981
+ effort: opts.effort,
981
982
  });
982
983
  // Log the auto-preserve-tools switch once per text-tool
983
984
  // client family. Skip when the operator already opted into
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askalf/dario",
3
- "version": "3.30.9",
3
+ "version": "3.30.10",
4
4
  "description": "A local LLM router. One endpoint, every provider — Claude subscriptions, OpenAI, OpenRouter, Groq, local LiteLLM, any OpenAI-compat endpoint — your tools don't need to change.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "scripts": {
23
23
  "build": "tsc && cp src/cc-template-data.json dist/ && node -e \"require('fs').mkdirSync('dist/shim',{recursive:true})\" && cp src/shim/runtime.cjs dist/shim/",
24
- "test": "node test/issue-29-tool-translation.mjs && node test/hybrid-tools.mjs && node test/tool-schema-contract.mjs && node test/scrub-paths.mjs && node test/provider-prefix.mjs && node test/analytics-recording.mjs && node test/analytics-billing-bucket.mjs && node test/failover-429.mjs && node test/pool-sticky.mjs && node test/live-fingerprint.mjs && node test/shim-runtime.mjs && node test/shim-e2e.mjs && node test/proxy-header-order.mjs && node test/proxy-body-order.mjs && node test/runtime-fingerprint.mjs && node test/pacing.mjs && node test/stream-drain.mjs && node test/subagent.mjs && node test/mcp-protocol.mjs && node test/mcp-tools.mjs && node test/mcp-e2e.mjs && node test/session-rotation.mjs && node test/drift-detection.mjs && node test/cc-authorize-probe-classifier.mjs && node test/compat-range.mjs && node test/doctor-formatter.mjs && node test/atomic-write.mjs && node test/account-refresh-singleflight.mjs && node test/streaming-edge-cases.mjs && node test/client-detection.mjs && node test/manual-oauth-flow.mjs && node test/scrub-template.mjs && node test/sanitize-messages.mjs && node test/platform-tools.mjs && node test/strict-template-flags.mjs && node test/request-queue.mjs",
24
+ "test": "node test/issue-29-tool-translation.mjs && node test/hybrid-tools.mjs && node test/tool-schema-contract.mjs && node test/scrub-paths.mjs && node test/provider-prefix.mjs && node test/analytics-recording.mjs && node test/analytics-billing-bucket.mjs && node test/failover-429.mjs && node test/pool-sticky.mjs && node test/live-fingerprint.mjs && node test/shim-runtime.mjs && node test/shim-e2e.mjs && node test/proxy-header-order.mjs && node test/proxy-body-order.mjs && node test/runtime-fingerprint.mjs && node test/pacing.mjs && node test/stream-drain.mjs && node test/subagent.mjs && node test/mcp-protocol.mjs && node test/mcp-tools.mjs && node test/mcp-e2e.mjs && node test/session-rotation.mjs && node test/drift-detection.mjs && node test/cc-authorize-probe-classifier.mjs && node test/compat-range.mjs && node test/doctor-formatter.mjs && node test/atomic-write.mjs && node test/account-refresh-singleflight.mjs && node test/streaming-edge-cases.mjs && node test/client-detection.mjs && node test/manual-oauth-flow.mjs && node test/scrub-template.mjs && node test/sanitize-messages.mjs && node test/platform-tools.mjs && node test/strict-template-flags.mjs && node test/request-queue.mjs && node test/effort-flag.mjs",
25
25
  "audit": "npm audit --production --audit-level=high",
26
26
  "prepublishOnly": "npm run build",
27
27
  "start": "node dist/cli.js",