@promptbook/node 0.114.0-21 → 0.114.0-22

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.
@@ -1,6 +1,7 @@
1
1
  import type { PromptRunOptions } from '../types/PromptRunOptions';
2
2
  import type { PromptRunResult } from '../types/PromptRunResult';
3
3
  import type { PromptRunner } from '../types/PromptRunner';
4
+ import { type HarnessSubscriptionUsage } from '../types/HarnessSubscriptionUsage';
4
5
  import type { ClaudeCodeRunnerOptions } from './ClaudeCodeRunnerOptions';
5
6
  /**
6
7
  * Runs prompts via the Claude Code CLI.
@@ -8,10 +9,17 @@ import type { ClaudeCodeRunnerOptions } from './ClaudeCodeRunnerOptions';
8
9
  export declare class ClaudeCodeRunner implements PromptRunner {
9
10
  private readonly options;
10
11
  readonly name = "claude-code";
12
+ private subscriptionUsage;
11
13
  /**
12
14
  * Creates a new Claude Code runner.
13
15
  */
14
16
  constructor(options?: ClaudeCodeRunnerOptions);
17
+ /**
18
+ * Returns the latest subscription-limit snapshot emitted by this Claude Code session.
19
+ *
20
+ * Claude exposes these values in the normal stream after a response, so no separate quota-only model call is made.
21
+ */
22
+ getSubscriptionUsage(): Promise<HarnessSubscriptionUsage | undefined>;
15
23
  /**
16
24
  * Runs the prompt using Claude Code and parses usage output.
17
25
  */
@@ -20,4 +28,11 @@ export declare class ClaudeCodeRunner implements PromptRunner {
20
28
  * Runs one Claude Code CLI process and returns its raw output.
21
29
  */
22
30
  private runClaudeCodeOnce;
31
+ /**
32
+ * Keeps the newest usable Claude subscription-limit values reported by the stream.
33
+ *
34
+ * A stream can omit these values for API-key users or unsupported plan types; retaining the prior snapshot avoids
35
+ * a temporary omission erasing a still-valid dashboard value while a long queue is running.
36
+ */
37
+ private updateSubscriptionUsage;
23
38
  }
@@ -12,7 +12,10 @@ export type ClaudeCodeOutputEvent = {
12
12
  readonly rate_limit_info?: {
13
13
  readonly status?: string;
14
14
  readonly resetsAt?: number;
15
+ readonly resets_at?: number;
15
16
  readonly rateLimitType?: string;
17
+ readonly rate_limit_type?: string;
18
+ readonly utilization?: number;
16
19
  };
17
20
  readonly usage?: {
18
21
  readonly input_tokens?: number;
@@ -0,0 +1,11 @@
1
+ import type { HarnessSubscriptionUsage } from '../types/HarnessSubscriptionUsage';
2
+ /**
3
+ * Converts Claude Code stream-json rate-limit events into the shared subscription-usage snapshot.
4
+ *
5
+ * Claude Code can emit one event for each applicable limit, so the parser preserves every distinct window instead of
6
+ * assuming the familiar 5-hour and seven-day pair. This lets a new vendor-side limit appear in the dashboard without
7
+ * changing its renderer.
8
+ *
9
+ * @private internal utility of the Claude Code runner
10
+ */
11
+ export declare function parseClaudeCodeSubscriptionUsage(output: string): HarnessSubscriptionUsage | undefined;
@@ -1,6 +1,7 @@
1
1
  import type { PromptRunOptions } from '../types/PromptRunOptions';
2
2
  import type { PromptRunResult } from '../types/PromptRunResult';
3
3
  import type { PromptRunner } from '../types/PromptRunner';
4
+ import type { HarnessSubscriptionUsage } from '../types/HarnessSubscriptionUsage';
4
5
  import type { OpenAiCodexRunnerOptions } from './OpenAiCodexRunnerOptions';
5
6
  /**
6
7
  * Runs prompts via the OpenAI Codex CLI.
@@ -13,6 +14,13 @@ export declare class OpenAiCodexRunner implements PromptRunner {
13
14
  * Creates a new Codex runner.
14
15
  */
15
16
  constructor(options: OpenAiCodexRunnerOptions);
17
+ /**
18
+ * Reads the current ChatGPT subscription quota snapshot through Codex's local app server.
19
+ *
20
+ * API-key sessions and unsupported Codex versions simply return no snapshot, which keeps this optional dashboard
21
+ * information from affecting the actual prompt execution.
22
+ */
23
+ getSubscriptionUsage(): Promise<HarnessSubscriptionUsage | undefined>;
16
24
  /**
17
25
  * Runs the Codex prompt in a temporary script and waits for completion output.
18
26
  */
@@ -0,0 +1,19 @@
1
+ import type { HarnessSubscriptionUsage } from '../types/HarnessSubscriptionUsage';
2
+ /**
3
+ * Reads the current Codex subscription limit windows through its local app-server protocol.
4
+ *
5
+ * Codex versions without this optional protocol, API-key sessions, and transient account failures simply provide no
6
+ * snapshot. Subscription usage is contextual UI information, so it must never make a coding prompt fail.
7
+ *
8
+ * @private internal utility of the OpenAI Codex runner
9
+ */
10
+ export declare function getCodexSubscriptionUsage(codexCommand: string): Promise<HarnessSubscriptionUsage | undefined>;
11
+ /**
12
+ * Converts the raw Codex app-server rate-limit response into Promptbook's harness-neutral subscription snapshot.
13
+ *
14
+ * Modern Codex versions can report several metered buckets, while older versions expose a single compatibility
15
+ * bucket. In both cases every primary and secondary rolling window is preserved for the terminal dashboard.
16
+ *
17
+ * @private internal utility of the OpenAI Codex runner
18
+ */
19
+ export declare function buildCodexSubscriptionUsage(response: unknown): HarnessSubscriptionUsage | undefined;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * One rolling subscription limit reported by a coding harness.
3
+ *
4
+ * @private internal type of `ptbk coder`
5
+ */
6
+ export type HarnessSubscriptionUsageLimit = {
7
+ /**
8
+ * Short, user-facing name of the limit window, for example `5h` or `7d`.
9
+ */
10
+ readonly label: string;
11
+ /**
12
+ * Percentage of this limit which has already been consumed, from 0 through 100.
13
+ */
14
+ readonly usedPercentage: number;
15
+ /**
16
+ * Unix timestamp in seconds at which this limit window resets, when reported by the harness.
17
+ */
18
+ readonly resetsAt?: number;
19
+ };
20
+ /**
21
+ * Subscription usage snapshot which a coding harness can optionally report.
22
+ *
23
+ * The runner contract deliberately keeps this independent from per-prompt token usage: subscription limits can be
24
+ * shared with other tools and can contain several rolling windows.
25
+ *
26
+ * @private internal type of `ptbk coder`
27
+ */
28
+ export type HarnessSubscriptionUsage = {
29
+ /**
30
+ * Every subscription limit currently reported by the harness, in display order.
31
+ */
32
+ readonly limits: ReadonlyArray<HarnessSubscriptionUsageLimit>;
33
+ };
34
+ /**
35
+ * Merges a newly reported subset of subscription windows into the latest complete snapshot.
36
+ *
37
+ * Some harnesses emit an update only for the limit whose state changed. Keeping the previous windows means a
38
+ * five-hour update cannot make a still-valid weekly limit disappear from the dashboard. Existing order is preserved
39
+ * and newly discovered windows are appended, which keeps the terminal presentation stable between refreshes.
40
+ *
41
+ * @private internal utility of `ptbk coder`
42
+ */
43
+ export declare function mergeHarnessSubscriptionUsage(previousSubscriptionUsage: HarnessSubscriptionUsage | undefined, latestSubscriptionUsage: HarnessSubscriptionUsage): HarnessSubscriptionUsage;
@@ -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-20`).
18
+ * It follows semantic versioning (e.g., `0.114.0-21`).
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-21",
3
+ "version": "0.114.0-22",
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-21"
100
+ "@promptbook/core": "0.114.0-22"
101
101
  },
102
102
  "dependencies": {
103
103
  "@openai/agents": "0.4.15",