@crouton-kit/humanloop 0.3.5 → 0.3.7
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/dist/api.js +3 -22
- package/dist/inbox/deck-factories.d.ts +12 -0
- package/dist/inbox/deck-factories.js +29 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/render/termrender.js +16 -17
- package/dist/render/version.d.ts +1 -1
- package/dist/render/version.js +1 -1
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -6,6 +6,7 @@ import { scanInbox } from './inbox/scan.js';
|
|
|
6
6
|
import { pickFromInbox } from './inbox/tui.js';
|
|
7
7
|
import { deckPath, atomicWriteJson, readJson } from './inbox/convention.js';
|
|
8
8
|
import { getTerminalSize } from './tui/terminal.js';
|
|
9
|
+
import { approveDeck, notifyDeck } from './inbox/deck-factories.js';
|
|
9
10
|
const RESPONSE_SCHEMA_ID = 'humanloop.response/v2';
|
|
10
11
|
function managedDir() {
|
|
11
12
|
return mkdtempSync(join(tmpdir(), 'hl-ix-'));
|
|
@@ -72,33 +73,13 @@ export async function ask(deck, opts = {}) {
|
|
|
72
73
|
}
|
|
73
74
|
/** Sugar: a single `kind:'validation'` Yes/No interaction. */
|
|
74
75
|
export async function approve(title, opts = {}) {
|
|
75
|
-
const deck = {
|
|
76
|
-
interactions: [{
|
|
77
|
-
id: 'approve',
|
|
78
|
-
title,
|
|
79
|
-
...(opts.subtitle !== undefined ? { subtitle: opts.subtitle } : {}),
|
|
80
|
-
...(opts.body !== undefined ? { body: opts.body } : {}),
|
|
81
|
-
kind: 'validation',
|
|
82
|
-
options: [
|
|
83
|
-
{ id: 'yes', label: 'Yes' },
|
|
84
|
-
{ id: 'no', label: 'No' },
|
|
85
|
-
],
|
|
86
|
-
}],
|
|
87
|
-
};
|
|
76
|
+
const deck = approveDeck(title, { subtitle: opts.subtitle, body: opts.body });
|
|
88
77
|
const env = await ask(deck, { dir: opts.dir, sessionId: opts.sessionId });
|
|
89
78
|
return env.responses[0]?.selectedOptionId === 'yes';
|
|
90
79
|
}
|
|
91
80
|
/** Sugar: a single `kind:'notify'` acknowledgement. */
|
|
92
81
|
export async function notify(title, body) {
|
|
93
|
-
const deck = {
|
|
94
|
-
interactions: [{
|
|
95
|
-
id: 'notify',
|
|
96
|
-
title,
|
|
97
|
-
...(body !== undefined ? { body } : {}),
|
|
98
|
-
kind: 'notify',
|
|
99
|
-
options: [{ id: 'ok', label: 'OK' }],
|
|
100
|
-
}],
|
|
101
|
-
};
|
|
82
|
+
const deck = notifyDeck(title, body !== undefined ? { body } : {});
|
|
102
83
|
await ask(deck, {});
|
|
103
84
|
}
|
|
104
85
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Deck } from '../types.js';
|
|
2
|
+
export interface ApproveDeckOpts {
|
|
3
|
+
subtitle?: string;
|
|
4
|
+
body?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Build a validated Yes/No validation deck. id: 'approve', kind: 'validation'. */
|
|
7
|
+
export declare function approveDeck(title: string, opts?: ApproveDeckOpts): Deck;
|
|
8
|
+
export interface NotifyDeckOpts {
|
|
9
|
+
body?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Build a validated single-option notify deck. id: 'notify', kind: 'notify'. */
|
|
12
|
+
export declare function notifyDeck(title: string, opts?: NotifyDeckOpts): Deck;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { validateDeck } from './deck-schema.js';
|
|
2
|
+
/** Build a validated Yes/No validation deck. id: 'approve', kind: 'validation'. */
|
|
3
|
+
export function approveDeck(title, opts = {}) {
|
|
4
|
+
return validateDeck({
|
|
5
|
+
interactions: [{
|
|
6
|
+
id: 'approve',
|
|
7
|
+
title,
|
|
8
|
+
...(opts.subtitle !== undefined ? { subtitle: opts.subtitle } : {}),
|
|
9
|
+
...(opts.body !== undefined ? { body: opts.body } : {}),
|
|
10
|
+
kind: 'validation',
|
|
11
|
+
options: [
|
|
12
|
+
{ id: 'yes', label: 'Yes' },
|
|
13
|
+
{ id: 'no', label: 'No' },
|
|
14
|
+
],
|
|
15
|
+
}],
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Build a validated single-option notify deck. id: 'notify', kind: 'notify'. */
|
|
19
|
+
export function notifyDeck(title, opts = {}) {
|
|
20
|
+
return validateDeck({
|
|
21
|
+
interactions: [{
|
|
22
|
+
id: 'notify',
|
|
23
|
+
title,
|
|
24
|
+
...(opts.body !== undefined ? { body: opts.body } : {}),
|
|
25
|
+
kind: 'notify',
|
|
26
|
+
options: [{ id: 'ok', label: 'OK' }],
|
|
27
|
+
}],
|
|
28
|
+
});
|
|
29
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { display } from './surfaces/display.js';
|
|
|
8
8
|
export { scanInbox } from './inbox/scan.js';
|
|
9
9
|
export { renderMarkdown, checkMarkdown, ensureRenderer, isRendererReady, } from './render/termrender.js';
|
|
10
10
|
export { parseDeck, validateDeck, deckSchema } from './inbox/deck-schema.js';
|
|
11
|
+
export { approveDeck, notifyDeck } from './inbox/deck-factories.js';
|
|
12
|
+
export type { ApproveDeckOpts, NotifyDeckOpts } from './inbox/deck-factories.js';
|
|
11
13
|
export { deckPath, responsePath, progressPath, visualsDir, interactionState, isResolved, isClaimed, atomicWriteJson, readJson, writeResponse, writeProgress, clearProgress, } from './inbox/convention.js';
|
|
12
14
|
export type { InteractionState } from './inbox/convention.js';
|
|
13
15
|
export type { Interaction, InteractionOption, InteractionResponse, InteractionKind, Deck, DeckSource, MountedPanel, MountedPanelOpts, GenerateVisual, VisualBlock, FeedbackComment, FeedbackResult, ResolutionEnvelope, InboxItem, DisplayOpts, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -11,5 +11,8 @@ export { scanInbox } from './inbox/scan.js';
|
|
|
11
11
|
export { renderMarkdown, checkMarkdown, ensureRenderer, isRendererReady, } from './render/termrender.js';
|
|
12
12
|
// Canonical deck schema + parsing/validation (consumers stop forking it).
|
|
13
13
|
export { parseDeck, validateDeck, deckSchema } from './inbox/deck-schema.js';
|
|
14
|
+
// Deck factories — pure builders for common deck shapes (sugar for SDK consumers
|
|
15
|
+
// who want validated Yes/No or notify decks without inline construction).
|
|
16
|
+
export { approveDeck, notifyDeck } from './inbox/deck-factories.js';
|
|
14
17
|
// Interaction-directory convention helpers (§B) — names humanloop owns.
|
|
15
18
|
export { deckPath, responsePath, progressPath, visualsDir, interactionState, isResolved, isClaimed, atomicWriteJson, readJson, writeResponse, writeProgress, clearProgress, } from './inbox/convention.js';
|
|
@@ -97,11 +97,14 @@ export function ensureRenderer() {
|
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
try {
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
// (Re)create the venv whenever the interpreter is missing — covers both
|
|
101
|
+
// "directory absent" and "directory present but bin/python stripped"
|
|
102
|
+
// (seen in the wild when pnpm rebuilds/dedupes node_modules or uv rotates
|
|
103
|
+
// its managed Python store). `--clear` makes uv wipe any partial state
|
|
104
|
+
// rather than refusing on the existing dir. If the interpreter is intact,
|
|
105
|
+
// skip straight to `uv pip install` so version drift reuses the venv.
|
|
106
|
+
if (!existsSync(VENV_PYTHON)) {
|
|
107
|
+
execFileSync('uv', ['venv', '--clear', VENV_DIR], { stdio: 'pipe', timeout: 60000 });
|
|
105
108
|
}
|
|
106
109
|
execFileSync('uv', ['pip', 'install', '--python', VENV_PYTHON, `termrender==${TERMRENDER_VERSION}`], { stdio: 'pipe', timeout: 120000 });
|
|
107
110
|
}
|
|
@@ -193,9 +196,8 @@ export function renderMarkdown(md, width) {
|
|
|
193
196
|
ensureRenderer();
|
|
194
197
|
if (rendererState === 'ready') {
|
|
195
198
|
try {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
input,
|
|
199
|
+
const out = execFileSync(VENV_BIN, ['doc', 'render', '--width', String(width), '--color', 'on'], {
|
|
200
|
+
input: md,
|
|
199
201
|
encoding: 'utf-8',
|
|
200
202
|
timeout: 5000,
|
|
201
203
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
@@ -221,9 +223,8 @@ export function checkMarkdown(md) {
|
|
|
221
223
|
// plaintext later. Bricking deck validation here would be the wrong default.
|
|
222
224
|
if (rendererState !== 'ready')
|
|
223
225
|
return { ok: true };
|
|
224
|
-
const input = JSON.stringify({ source: md });
|
|
225
226
|
const result = spawnSync(VENV_BIN, ['doc', 'check'], {
|
|
226
|
-
input,
|
|
227
|
+
input: md,
|
|
227
228
|
encoding: 'utf-8',
|
|
228
229
|
timeout: 5000,
|
|
229
230
|
});
|
|
@@ -262,13 +263,11 @@ export function displayInPane(path, opts = {}) {
|
|
|
262
263
|
ensureRenderer();
|
|
263
264
|
if (rendererState !== 'ready')
|
|
264
265
|
return {};
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const result = spawnSync(VENV_BIN, ['pane', 'open'], {
|
|
271
|
-
input,
|
|
266
|
+
const args = ['pane', 'open', path];
|
|
267
|
+
if (opts.watch !== false)
|
|
268
|
+
args.push('--watch');
|
|
269
|
+
args.push('--window', opts.newWindow ? 'new' : 'split');
|
|
270
|
+
const result = spawnSync(VENV_BIN, args, {
|
|
272
271
|
encoding: 'utf-8',
|
|
273
272
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
274
273
|
});
|
package/dist/render/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const TERMRENDER_VERSION = "
|
|
1
|
+
export declare const TERMRENDER_VERSION = "3.0.0";
|
package/dist/render/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const TERMRENDER_VERSION = '
|
|
1
|
+
export const TERMRENDER_VERSION = '3.0.0';
|