@promptbook/node 0.113.0-10 → 0.113.0-11
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/esm/index.es.js +79 -42
- package/esm/index.es.js.map +1 -1
- package/esm/scripts/run-codex-prompts/common/waitUntilWorldTimeDeadline.d.ts +17 -0
- package/esm/src/utils/agents/terminalAgentAvatarVisual.d.ts +94 -0
- package/esm/src/utils/agents/terminalAgentAvatarVisual.test.d.ts +1 -0
- package/esm/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +79 -42
- package/umd/index.umd.js.map +1 -1
- package/umd/scripts/run-codex-prompts/common/waitUntilWorldTimeDeadline.d.ts +17 -0
- package/umd/src/utils/agents/terminalAgentAvatarVisual.d.ts +94 -0
- package/umd/src/utils/agents/terminalAgentAvatarVisual.test.d.ts +1 -0
- package/umd/src/version.d.ts +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callback called before each short sleep while waiting for a wall-clock deadline.
|
|
3
|
+
*/
|
|
4
|
+
export type WorldTimeDeadlineTick = (remainingDurationMs: number) => void | Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Waits until one wall-clock deadline has passed.
|
|
7
|
+
*
|
|
8
|
+
* The remaining time is recalculated from `Date.now()` after every poll and after every tick callback.
|
|
9
|
+
* This makes waits elapse while the process is paused at a checkpoint or the computer is asleep.
|
|
10
|
+
*
|
|
11
|
+
* @private internal utility of `ptbk coder` wait handling
|
|
12
|
+
*/
|
|
13
|
+
export declare function waitUntilWorldTimeDeadline(options: {
|
|
14
|
+
readonly deadlineTimeMs: number;
|
|
15
|
+
readonly pollIntervalMs: number;
|
|
16
|
+
readonly onTick?: WorldTimeDeadlineTick;
|
|
17
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type CreateCanvasForAsciiArt } from '../../avatars/renderAvatarVisualAsciiArt';
|
|
2
|
+
import type { AvatarVisualId } from '../../avatars/types/AvatarVisualDefinition';
|
|
3
|
+
import type { string_book } from '../../book-2.0/agent-source/string_book';
|
|
4
|
+
import type { AsciiArtColorDepth } from '../ascii-art/convertImageDataToAsciiArt';
|
|
5
|
+
/**
|
|
6
|
+
* Output width of the terminal agent avatar visual in character cells.
|
|
7
|
+
*
|
|
8
|
+
* @private shared helper for terminal avatar rendering
|
|
9
|
+
*/
|
|
10
|
+
export declare const TERMINAL_AGENT_AVATAR_VISUAL_COLUMNS = 48;
|
|
11
|
+
/**
|
|
12
|
+
* Output height of the terminal agent avatar visual in character cells.
|
|
13
|
+
*
|
|
14
|
+
* @private shared helper for terminal avatar rendering
|
|
15
|
+
*/
|
|
16
|
+
export declare const TERMINAL_AGENT_AVATAR_VISUAL_ROWS = 12;
|
|
17
|
+
/**
|
|
18
|
+
* Refresh cadence used while a terminal agent avatar visual is animated.
|
|
19
|
+
*
|
|
20
|
+
* @private shared helper for terminal avatar rendering
|
|
21
|
+
*/
|
|
22
|
+
export declare const TERMINAL_AGENT_AVATAR_VISUAL_REFRESH_INTERVAL_MS = 300;
|
|
23
|
+
/**
|
|
24
|
+
* Options passed when rendering one animated terminal avatar frame.
|
|
25
|
+
*
|
|
26
|
+
* @private shared helper for terminal avatar rendering
|
|
27
|
+
*/
|
|
28
|
+
export type TerminalAgentAvatarVisualFrameOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* Current animation time forwarded to the shared avatar renderer.
|
|
31
|
+
*/
|
|
32
|
+
readonly animationTimeMs: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Runtime renderer for an agent avatar visual shown in a terminal.
|
|
36
|
+
*
|
|
37
|
+
* @private shared helper for terminal avatar rendering
|
|
38
|
+
*/
|
|
39
|
+
export type TerminalAgentAvatarVisual = {
|
|
40
|
+
/**
|
|
41
|
+
* Whether the selected built-in visual changes over time.
|
|
42
|
+
*/
|
|
43
|
+
readonly isAnimated: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Renders one ANSI ASCII-art frame for the current terminal timestamp.
|
|
46
|
+
*/
|
|
47
|
+
readonly renderFrame: (options: TerminalAgentAvatarVisualFrameOptions) => ReadonlyArray<string>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Options for creating a terminal avatar visual renderer from an agent book source.
|
|
51
|
+
*
|
|
52
|
+
* @private shared helper for terminal avatar rendering
|
|
53
|
+
*/
|
|
54
|
+
export type CreateTerminalAgentAvatarVisualOptions = {
|
|
55
|
+
/**
|
|
56
|
+
* Source of the agent book whose metadata controls avatar identity.
|
|
57
|
+
*/
|
|
58
|
+
readonly agentSource: string_book;
|
|
59
|
+
/**
|
|
60
|
+
* Built-in avatar visual used when the agent does not declare `META AVATAR` or `META VISUAL`.
|
|
61
|
+
*/
|
|
62
|
+
readonly defaultAvatarVisualId?: AvatarVisualId;
|
|
63
|
+
/**
|
|
64
|
+
* Color depth of the emitted ANSI escape codes.
|
|
65
|
+
*/
|
|
66
|
+
readonly colorDepth?: AsciiArtColorDepth;
|
|
67
|
+
/**
|
|
68
|
+
* Platform-specific canvas factory used to rasterize the visual.
|
|
69
|
+
*/
|
|
70
|
+
readonly createCanvas: CreateCanvasForAsciiArt;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Resolves the built-in avatar visual selected for terminal rendering of one agent source.
|
|
74
|
+
*
|
|
75
|
+
* @param agentSource Source of the agent book.
|
|
76
|
+
* @param defaultAvatarVisualId Built-in fallback used when the source does not declare an avatar visual.
|
|
77
|
+
* @returns Supported built-in avatar visual id.
|
|
78
|
+
*
|
|
79
|
+
* @private shared helper for terminal avatar rendering
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveTerminalAgentAvatarVisualId(agentSource: string_book, defaultAvatarVisualId?: AvatarVisualId): AvatarVisualId;
|
|
82
|
+
/**
|
|
83
|
+
* Creates an ANSI ASCII-art avatar renderer for terminal UIs.
|
|
84
|
+
*
|
|
85
|
+
* The agent's avatar visual is resolved the same way as on the website: `META AVATAR`
|
|
86
|
+
* / `META VISUAL` wins, then the provided fallback visual, then the shared default visual.
|
|
87
|
+
* The terminal variant uses a transparent horizontal canvas instead of the website's framed square surface.
|
|
88
|
+
*
|
|
89
|
+
* @param options Agent source, canvas factory, and optional terminal color settings.
|
|
90
|
+
* @returns Runtime terminal avatar visual renderer.
|
|
91
|
+
*
|
|
92
|
+
* @private shared helper for terminal avatar rendering
|
|
93
|
+
*/
|
|
94
|
+
export declare function createTerminalAgentAvatarVisual(options: CreateTerminalAgentAvatarVisualOptions): TerminalAgentAvatarVisual;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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.113.0-
|
|
18
|
+
* It follows semantic versioning (e.g., `0.113.0-10`).
|
|
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.113.0-
|
|
3
|
+
"version": "0.113.0-11",
|
|
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.113.0-
|
|
100
|
+
"@promptbook/core": "0.113.0-11"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
103
|
"@mozilla/readability": "0.6.0",
|
package/umd/index.umd.js
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* @generated
|
|
52
52
|
* @see https://github.com/webgptorg/promptbook
|
|
53
53
|
*/
|
|
54
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.113.0-
|
|
54
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.113.0-11';
|
|
55
55
|
/**
|
|
56
56
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
57
57
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -3076,6 +3076,47 @@
|
|
|
3076
3076
|
});
|
|
3077
3077
|
}
|
|
3078
3078
|
|
|
3079
|
+
/**
|
|
3080
|
+
* Minimum timer duration used to avoid a zero-millisecond polling loop.
|
|
3081
|
+
*/
|
|
3082
|
+
const MINIMUM_WORLD_TIME_WAIT_POLL_INTERVAL_MS = 1;
|
|
3083
|
+
/**
|
|
3084
|
+
* Waits until one wall-clock deadline has passed.
|
|
3085
|
+
*
|
|
3086
|
+
* The remaining time is recalculated from `Date.now()` after every poll and after every tick callback.
|
|
3087
|
+
* This makes waits elapse while the process is paused at a checkpoint or the computer is asleep.
|
|
3088
|
+
*
|
|
3089
|
+
* @private internal utility of `ptbk coder` wait handling
|
|
3090
|
+
*/
|
|
3091
|
+
async function waitUntilWorldTimeDeadline(options) {
|
|
3092
|
+
const { deadlineTimeMs, pollIntervalMs, onTick } = options;
|
|
3093
|
+
const normalizedPollIntervalMs = Math.max(MINIMUM_WORLD_TIME_WAIT_POLL_INTERVAL_MS, pollIntervalMs);
|
|
3094
|
+
while (true) {
|
|
3095
|
+
const remainingDurationMs = getRemainingDurationMs(deadlineTimeMs);
|
|
3096
|
+
if (remainingDurationMs <= 0) {
|
|
3097
|
+
return;
|
|
3098
|
+
}
|
|
3099
|
+
await (onTick === null || onTick === void 0 ? void 0 : onTick(remainingDurationMs));
|
|
3100
|
+
const remainingDurationAfterTickMs = getRemainingDurationMs(deadlineTimeMs);
|
|
3101
|
+
if (remainingDurationAfterTickMs <= 0) {
|
|
3102
|
+
return;
|
|
3103
|
+
}
|
|
3104
|
+
await waitForMilliseconds(Math.min(normalizedPollIntervalMs, remainingDurationAfterTickMs));
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
/**
|
|
3108
|
+
* Returns the remaining wall-clock duration until a timestamp.
|
|
3109
|
+
*/
|
|
3110
|
+
function getRemainingDurationMs(deadlineTimeMs) {
|
|
3111
|
+
return Math.max(0, deadlineTimeMs - Date.now());
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Waits for one short polling interval.
|
|
3115
|
+
*/
|
|
3116
|
+
async function waitForMilliseconds(durationMs) {
|
|
3117
|
+
await new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3079
3120
|
/**
|
|
3080
3121
|
* Base delimiter used for passing large prompts through stdin.
|
|
3081
3122
|
*/
|
|
@@ -3485,36 +3526,32 @@
|
|
|
3485
3526
|
* Waits until the Claude Code session can be resumed, keeping terminal status clear.
|
|
3486
3527
|
*/
|
|
3487
3528
|
async function waitForClaudeCodeSessionLimitReset(sessionLimit, resurrectionCount, options) {
|
|
3488
|
-
var _a, _b
|
|
3529
|
+
var _a, _b;
|
|
3489
3530
|
const delayMs = getClaudeCodeSessionLimitDelayMs(sessionLimit);
|
|
3531
|
+
const resetDeadlineTimeMs = Date.now() + delayMs;
|
|
3490
3532
|
const sessionLabel = formatClaudeCodeSessionIdForDisplay(sessionLimit.sessionId);
|
|
3491
3533
|
const resetSummary = formatClaudeCodeSessionLimitForDisplay(sessionLimit);
|
|
3492
3534
|
if ((_a = options.shouldPrintLiveOutput) !== null && _a !== void 0 ? _a : true) {
|
|
3493
3535
|
console.warn(colors__default["default"].yellow(`[claude-code] Session limit detected for ${sessionLimit.sessionId}. Resurrection #${resurrectionCount} will resume with --resume after ${formatDurationMs(delayMs)}. ${resetSummary}`));
|
|
3494
3536
|
}
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3537
|
+
await waitUntilWorldTimeDeadline({
|
|
3538
|
+
deadlineTimeMs: resetDeadlineTimeMs,
|
|
3539
|
+
pollIntervalMs: CLAUDE_CODE_SESSION_RESURRECTION_POLL_MS,
|
|
3540
|
+
onTick: async (remainingDelayMs) => {
|
|
3541
|
+
var _a;
|
|
3542
|
+
await ((_a = options.waitForPauseCheckpoint) === null || _a === void 0 ? void 0 : _a.call(options, {
|
|
3543
|
+
checkpointLabel: 'the Claude Code session limit reset',
|
|
3544
|
+
phase: 'waiting',
|
|
3545
|
+
statusMessage: `Claude Code session ${sessionLabel} hit its limit; resurrection #${resurrectionCount} resumes in ${formatDurationMs(Math.min(remainingDelayMs, delayMs))}`,
|
|
3546
|
+
}));
|
|
3547
|
+
},
|
|
3548
|
+
});
|
|
3549
|
+
await ((_b = options.waitForPauseCheckpoint) === null || _b === void 0 ? void 0 : _b.call(options, {
|
|
3507
3550
|
checkpointLabel: 'resurrecting the Claude Code session with --resume',
|
|
3508
3551
|
phase: 'running',
|
|
3509
3552
|
statusMessage: `Resurrecting Claude Code session ${sessionLabel} with --resume`,
|
|
3510
3553
|
}));
|
|
3511
3554
|
}
|
|
3512
|
-
/**
|
|
3513
|
-
* Waits for a fixed amount of milliseconds.
|
|
3514
|
-
*/
|
|
3515
|
-
async function waitFor$1(delayMs) {
|
|
3516
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
3517
|
-
}
|
|
3518
3555
|
/**
|
|
3519
3556
|
* Formats a Claude Code session id for compact terminal status lines.
|
|
3520
3557
|
*/
|
|
@@ -4475,12 +4512,6 @@
|
|
|
4475
4512
|
* Randomized delay proportion added/subtracted for retry jitter.
|
|
4476
4513
|
*/
|
|
4477
4514
|
const RATE_LIMIT_BACKOFF_JITTER_RATIO = 0.15;
|
|
4478
|
-
/**
|
|
4479
|
-
* Waits for one given amount of milliseconds.
|
|
4480
|
-
*/
|
|
4481
|
-
async function waitFor(delayMs) {
|
|
4482
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
4483
|
-
}
|
|
4484
4515
|
/**
|
|
4485
4516
|
* Formats a delay value into a concise `xh ym zs` style label.
|
|
4486
4517
|
*/
|
|
@@ -4570,13 +4601,18 @@
|
|
|
4570
4601
|
throw error;
|
|
4571
4602
|
}
|
|
4572
4603
|
const delayMs = this.rateLimitBackoff.nextDelayMs();
|
|
4573
|
-
const
|
|
4604
|
+
const retryDeadlineTimeMs = Date.now() + delayMs;
|
|
4605
|
+
const retryAt = new Date(retryDeadlineTimeMs).toISOString();
|
|
4574
4606
|
const retryIndex = this.rateLimitBackoff.retryCount;
|
|
4575
4607
|
const summary = extractFailureSummary(details);
|
|
4576
4608
|
if ((_b = options.shouldPrintLiveOutput) !== null && _b !== void 0 ? _b : true) {
|
|
4577
4609
|
console.warn(colors__default["default"].yellow(`[codex] Rate limit/quota detected (${summary}). Retry #${retryIndex} in ${formatDelay(delayMs)} at ${retryAt}.`));
|
|
4578
4610
|
}
|
|
4579
|
-
await waitForRetryDelay(
|
|
4611
|
+
await waitForRetryDelay({
|
|
4612
|
+
delayMs,
|
|
4613
|
+
retryDeadlineTimeMs,
|
|
4614
|
+
promptRunOptions: options,
|
|
4615
|
+
});
|
|
4580
4616
|
}
|
|
4581
4617
|
}
|
|
4582
4618
|
}
|
|
@@ -4584,20 +4620,21 @@
|
|
|
4584
4620
|
/**
|
|
4585
4621
|
* Waits for the next Codex retry while polling for requested pause checkpoints.
|
|
4586
4622
|
*/
|
|
4587
|
-
async function waitForRetryDelay(
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4623
|
+
async function waitForRetryDelay(options) {
|
|
4624
|
+
const { delayMs, retryDeadlineTimeMs, promptRunOptions } = options;
|
|
4625
|
+
await waitUntilWorldTimeDeadline({
|
|
4626
|
+
deadlineTimeMs: retryDeadlineTimeMs,
|
|
4627
|
+
pollIntervalMs: RATE_LIMIT_BACKOFF_POLL_MS,
|
|
4628
|
+
onTick: async (remainingDelayMs) => {
|
|
4629
|
+
var _a;
|
|
4630
|
+
const remainingDelayLabel = formatDelay(Math.min(remainingDelayMs, delayMs));
|
|
4631
|
+
await ((_a = promptRunOptions.waitForPauseCheckpoint) === null || _a === void 0 ? void 0 : _a.call(promptRunOptions, {
|
|
4632
|
+
checkpointLabel: 'the next OpenAI Codex retry after rate limit',
|
|
4633
|
+
phase: 'running',
|
|
4634
|
+
statusMessage: `Waiting ${remainingDelayLabel} before retrying OpenAI Codex`,
|
|
4635
|
+
}));
|
|
4636
|
+
},
|
|
4637
|
+
});
|
|
4601
4638
|
}
|
|
4602
4639
|
|
|
4603
4640
|
/**
|