@crouton-kit/humanloop 0.3.39 → 0.4.0

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.
@@ -0,0 +1,130 @@
1
+ import type { CanonicalInteraction, Interaction, VisualRequest as PanelVisualRequest } from '../types.js';
2
+ import { type CompletionHandler } from './registry.js';
3
+ export declare const VISUAL_CAPABILITY: "humanloop.visual/v1";
4
+ export interface VisualClaimIdentity {
5
+ token: string;
6
+ host: string;
7
+ pid: number;
8
+ claimedAt: string;
9
+ }
10
+ export interface VisualCleanupObligation {
11
+ reason: 'canceled' | 'unreceipted_start_error';
12
+ attempts: number;
13
+ nextAttemptAt: string;
14
+ lastAttemptAt?: string;
15
+ lastError?: string;
16
+ }
17
+ interface VisualBinding {
18
+ capability: typeof VISUAL_CAPABILITY;
19
+ owner: string;
20
+ root: string;
21
+ dir: string;
22
+ ticketId: string;
23
+ requestId: string;
24
+ generationId: string;
25
+ interactionId: string;
26
+ interaction: CanonicalInteraction;
27
+ claim: VisualClaimIdentity;
28
+ handler: CompletionHandler;
29
+ }
30
+ export interface VisualProtocolRequest extends VisualBinding {
31
+ schema: 'humanloop.visual-request/v1';
32
+ state: 'running' | 'canceled' | 'terminal';
33
+ requestedAt: string;
34
+ settledAt?: string;
35
+ cleanup?: VisualCleanupObligation;
36
+ }
37
+ export interface VisualRequestEvent extends VisualBinding {
38
+ schema: 'humanloop.visual-request-event/v1';
39
+ action: 'start' | 'cancel';
40
+ }
41
+ interface VisualResultBinding extends VisualBinding {
42
+ schema: 'humanloop.visual-result/v1';
43
+ completedAt: string;
44
+ }
45
+ export type VisualProtocolResult = (VisualResultBinding & {
46
+ status: 'ready';
47
+ markdown: string;
48
+ }) | (VisualResultBinding & {
49
+ status: 'error';
50
+ error: string;
51
+ });
52
+ export type VisualResultSubmission = {
53
+ requestId: string;
54
+ generationId: string;
55
+ interactionId: string;
56
+ interaction: CanonicalInteraction;
57
+ claimToken: string;
58
+ status: 'ready';
59
+ markdown: string;
60
+ } | {
61
+ requestId: string;
62
+ generationId: string;
63
+ interactionId: string;
64
+ interaction: CanonicalInteraction;
65
+ claimToken: string;
66
+ status: 'error';
67
+ error: string;
68
+ };
69
+ export interface StartVisualRequestOptions {
70
+ root: string;
71
+ dir: string;
72
+ claimToken: string;
73
+ request: PanelVisualRequest;
74
+ }
75
+ export type VisualStartDeliveryResult = 'delivered' | 'already_attempted' | 'ineligible' | 'failed';
76
+ export type VisualCleanupDeliveryResult = 'delivered' | 'pending' | 'none';
77
+ export interface StartedVisualRequest {
78
+ request: VisualProtocolRequest;
79
+ /** Resolves after the one permitted start attempt reaches a determinate outcome. */
80
+ delivery: Promise<VisualStartDeliveryResult>;
81
+ }
82
+ export interface VisualCleanupTask {
83
+ root: string;
84
+ dir: string;
85
+ requestId: string;
86
+ reason: VisualCleanupObligation['reason'];
87
+ nextAttemptAt: string;
88
+ }
89
+ /** Normalize one Interaction into the sole persisted/event correlation shape. */
90
+ export declare function canonicalizeInteraction(raw: Interaction | CanonicalInteraction): CanonicalInteraction;
91
+ /** Stable bytes used for every interaction equality check across the protocol. */
92
+ export declare function canonicalInteractionJson(raw: Interaction | CanonicalInteraction): string;
93
+ export declare function parseVisualRequestEvent(raw: unknown): VisualRequestEvent;
94
+ /** Strict, repairing reader; malformed or unbound request bytes return null. */
95
+ export declare function readVisualRequest(root: string, dir: string, requestId: string): VisualProtocolRequest | null;
96
+ /** Strict, repairing reader; canceled and mismatched results are never returned. */
97
+ export declare function readVisualResult(root: string, dir: string, requestId: string): VisualProtocolResult | null;
98
+ /** Decode an event and atomically bind it to Humanloop's immutable request state. */
99
+ export declare function readVisualRequestForEvent(raw: unknown): VisualProtocolRequest | null;
100
+ /** Persist one claim-bound request and dispatch its frozen handler at most once. */
101
+ export declare function startVisualRequest(opts: StartVisualRequestOptions): StartedVisualRequest;
102
+ /** Compare-publish the first fully correlated ready/error result. Stale writers are no-ops. */
103
+ export declare function submitVisualResult(root: string, dir: string, raw: VisualResultSubmission): {
104
+ published: boolean;
105
+ };
106
+ /** Attempt one due cleanup delivery through the request's frozen handler. */
107
+ export declare function dispatchVisualCleanup(root: string, dir: string, requestId: string): Promise<VisualCleanupDeliveryResult>;
108
+ /** State-first cancellation for one handle; the returned promise is cleanup delivery only. */
109
+ export declare function cancelVisualRequest(root: string, dir: string, requestId: string): Promise<VisualCleanupDeliveryResult>;
110
+ /** State-first cancel every running request, then dispatch every owed cleanup (including start failures). */
111
+ export declare function cancelVisualRequestsForTicket(root: string, dir: string): Promise<{
112
+ canceled: number;
113
+ cleanupOwed: number;
114
+ }>;
115
+ /** Durable tasks the next controller-owned retry executor should schedule. */
116
+ export declare function listVisualCleanupObligations(root: string, dir: string): VisualCleanupTask[];
117
+ export interface VisualRequestReconciliation {
118
+ retired: number;
119
+ cleanupOwed: number;
120
+ /** Cleanup delivery only; reconciliation never redelivers a start. */
121
+ delivery: Promise<VisualCleanupDeliveryResult[]>;
122
+ }
123
+ /** Retire abandoned generations under the ticket claim boundary. A live claim is
124
+ * authoritative; a newly acquired claim retires every older generation first. */
125
+ export declare function reconcileVisualRequestsForTicket(root: string, dir: string, currentClaimToken?: string): VisualRequestReconciliation;
126
+ /** Enumerate direct ticket children only, including resolved tickets whose cleanup is still owed. */
127
+ export declare function listVisualCleanupObligationsForRoot(root: string): VisualCleanupTask[];
128
+ /** Startup reconciliation only retires stale/missing-claim work; live owners stay untouched. */
129
+ export declare function reconcileStaleVisualRequestsForRoot(root: string): VisualRequestReconciliation[];
130
+ export {};