human-in-the-loop 0.1.0 → 2.0.2

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,315 @@
1
+ /**
2
+ * Human-in-the-loop primitives implementation
3
+ */
4
+ import type { Role, Team, Human as HumanType, Goals, KPIs, OKRs, HumanOptions, ApprovalResponse, ReviewResponse, Notification, ReviewQueue, ApprovalWorkflow, Priority, HumanRequest } from './types.js';
5
+ /**
6
+ * Human-in-the-loop manager
7
+ *
8
+ * Provides primitives for integrating human oversight and intervention
9
+ * in AI workflows.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const human = Human({
14
+ * defaultTimeout: 3600000, // 1 hour
15
+ * autoEscalate: true,
16
+ * })
17
+ *
18
+ * // Request approval
19
+ * const approval = await human.approve({
20
+ * title: 'Deploy to production',
21
+ * description: 'Approve deployment of v2.0.0',
22
+ * subject: 'Production Deployment',
23
+ * assignee: 'tech-lead@example.com',
24
+ * priority: 'high',
25
+ * })
26
+ *
27
+ * if (approval.approved) {
28
+ * await deploy()
29
+ * }
30
+ * ```
31
+ */
32
+ export declare class HumanManager {
33
+ private store;
34
+ private options;
35
+ private roles;
36
+ private teams;
37
+ private humans;
38
+ private escalationPolicies;
39
+ private workflows;
40
+ constructor(options?: HumanOptions);
41
+ /**
42
+ * Define a role
43
+ */
44
+ defineRole(role: Role): Role;
45
+ /**
46
+ * Get a role by ID
47
+ */
48
+ getRole(id: string): Role | undefined;
49
+ /**
50
+ * Define a team
51
+ */
52
+ defineTeam(team: Team): Team;
53
+ /**
54
+ * Get a team by ID
55
+ */
56
+ getTeam(id: string): Team | undefined;
57
+ /**
58
+ * Register a human worker
59
+ */
60
+ registerHuman(human: HumanType): HumanType;
61
+ /**
62
+ * Get a human by ID
63
+ */
64
+ getHuman(id: string): HumanType | undefined;
65
+ /**
66
+ * Request approval from a human
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const result = await human.approve({
71
+ * title: 'Approve expense',
72
+ * description: 'Employee expense claim for $150',
73
+ * subject: 'Expense Claim #1234',
74
+ * input: { amount: 150, category: 'Travel' },
75
+ * assignee: 'manager@example.com',
76
+ * priority: 'normal',
77
+ * })
78
+ * ```
79
+ */
80
+ approve<TData = unknown>(params: {
81
+ title: string;
82
+ description: string;
83
+ subject: string;
84
+ input: TData;
85
+ assignee?: string | string[];
86
+ role?: string;
87
+ team?: string;
88
+ priority?: Priority;
89
+ timeout?: number;
90
+ escalatesTo?: string | string[];
91
+ requiresApproval?: boolean;
92
+ approvers?: string[];
93
+ metadata?: Record<string, unknown>;
94
+ }): Promise<ApprovalResponse>;
95
+ /**
96
+ * Ask a question to a human
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const answer = await human.ask({
101
+ * title: 'Product naming',
102
+ * question: 'What should we name the new feature?',
103
+ * context: { feature: 'AI Assistant' },
104
+ * assignee: 'product-manager@example.com',
105
+ * })
106
+ * ```
107
+ */
108
+ ask(params: {
109
+ title: string;
110
+ question: string;
111
+ context?: unknown;
112
+ assignee?: string | string[];
113
+ role?: string;
114
+ team?: string;
115
+ priority?: Priority;
116
+ timeout?: number;
117
+ suggestions?: string[];
118
+ metadata?: Record<string, unknown>;
119
+ }): Promise<string>;
120
+ /**
121
+ * Request a human to perform a task
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const result = await human.do({
126
+ * title: 'Review code',
127
+ * instructions: 'Review the PR and provide feedback',
128
+ * input: { prUrl: 'https://github.com/...' },
129
+ * assignee: 'senior-dev@example.com',
130
+ * })
131
+ * ```
132
+ */
133
+ do<TInput = unknown, TOutput = unknown>(params: {
134
+ title: string;
135
+ instructions: string;
136
+ input: TInput;
137
+ assignee?: string | string[];
138
+ role?: string;
139
+ team?: string;
140
+ priority?: Priority;
141
+ timeout?: number;
142
+ tools?: any[];
143
+ estimatedEffort?: string;
144
+ metadata?: Record<string, unknown>;
145
+ }): Promise<TOutput>;
146
+ /**
147
+ * Request a human to make a decision
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const choice = await human.decide({
152
+ * title: 'Pick deployment strategy',
153
+ * options: ['blue-green', 'canary', 'rolling'],
154
+ * context: { risk: 'high', users: 100000 },
155
+ * assignee: 'devops-lead@example.com',
156
+ * })
157
+ * ```
158
+ */
159
+ decide<TOptions extends string = string>(params: {
160
+ title: string;
161
+ description?: string;
162
+ options: TOptions[];
163
+ context?: unknown;
164
+ assignee?: string | string[];
165
+ role?: string;
166
+ team?: string;
167
+ priority?: Priority;
168
+ timeout?: number;
169
+ criteria?: string[];
170
+ metadata?: Record<string, unknown>;
171
+ }): Promise<TOptions>;
172
+ /**
173
+ * Request a human to review content
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * const review = await human.review({
178
+ * title: 'Review blog post',
179
+ * content: { title: 'My Post', body: '...' },
180
+ * reviewType: 'content',
181
+ * criteria: ['Grammar', 'Tone', 'Accuracy'],
182
+ * assignee: 'editor@example.com',
183
+ * })
184
+ * ```
185
+ */
186
+ review<TContent = unknown>(params: {
187
+ title: string;
188
+ description?: string;
189
+ content: TContent;
190
+ reviewType?: 'code' | 'content' | 'design' | 'data' | 'other';
191
+ criteria?: string[];
192
+ assignee?: string | string[];
193
+ role?: string;
194
+ team?: string;
195
+ priority?: Priority;
196
+ timeout?: number;
197
+ metadata?: Record<string, unknown>;
198
+ }): Promise<ReviewResponse>;
199
+ /**
200
+ * Send a notification to a human
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * await human.notify({
205
+ * type: 'info',
206
+ * title: 'Deployment complete',
207
+ * message: 'Version 2.0.0 deployed successfully',
208
+ * recipient: 'team@example.com',
209
+ * channels: ['slack', 'email'],
210
+ * })
211
+ * ```
212
+ */
213
+ notify(params: {
214
+ type: 'info' | 'warning' | 'error' | 'success';
215
+ title: string;
216
+ message: string;
217
+ recipient: string | string[];
218
+ channels?: ('slack' | 'email' | 'sms' | 'web')[];
219
+ priority?: Priority;
220
+ data?: unknown;
221
+ }): Promise<Notification>;
222
+ /**
223
+ * Get a review queue
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * const queue = await human.getQueue({
228
+ * name: 'Pending Approvals',
229
+ * filters: {
230
+ * status: ['pending'],
231
+ * priority: ['high', 'critical'],
232
+ * },
233
+ * })
234
+ * ```
235
+ */
236
+ getQueue(params: {
237
+ name: string;
238
+ description?: string;
239
+ filters?: ReviewQueue['filters'];
240
+ sortBy?: 'createdAt' | 'priority' | 'updatedAt';
241
+ sortDirection?: 'asc' | 'desc';
242
+ limit?: number;
243
+ }): Promise<ReviewQueue>;
244
+ /**
245
+ * Get a request by ID
246
+ */
247
+ getRequest<T extends HumanRequest = HumanRequest>(id: string): Promise<T | null>;
248
+ /**
249
+ * Complete a request with a response
250
+ */
251
+ completeRequest<T extends HumanRequest = HumanRequest>(id: string, response: T['response']): Promise<T>;
252
+ /**
253
+ * Reject a request
254
+ */
255
+ rejectRequest(id: string, reason: string): Promise<HumanRequest>;
256
+ /**
257
+ * Escalate a request
258
+ */
259
+ escalateRequest(id: string, to: string): Promise<HumanRequest>;
260
+ /**
261
+ * Cancel a request
262
+ */
263
+ cancelRequest(id: string): Promise<HumanRequest>;
264
+ /**
265
+ * Define or update goals
266
+ */
267
+ defineGoals(goals: Goals): Goals;
268
+ /**
269
+ * Track KPIs
270
+ */
271
+ trackKPIs(kpis: KPIs): KPIs;
272
+ /**
273
+ * Define or update OKRs
274
+ */
275
+ defineOKRs(okrs: OKRs): OKRs;
276
+ /**
277
+ * Create an approval workflow
278
+ */
279
+ createWorkflow(workflow: ApprovalWorkflow): ApprovalWorkflow;
280
+ /**
281
+ * Get a workflow by ID
282
+ */
283
+ getWorkflow(id: string): ApprovalWorkflow | undefined;
284
+ /**
285
+ * Wait for a human response
286
+ *
287
+ * In a real implementation, this would:
288
+ * 1. Poll the store for updates
289
+ * 2. Listen for webhooks/events
290
+ * 3. Handle timeouts and escalations
291
+ * 4. Return the response when available
292
+ *
293
+ * For now, this throws an error to indicate manual completion is needed
294
+ */
295
+ private waitForResponse;
296
+ /**
297
+ * Poll for request completion
298
+ */
299
+ private pollForCompletion;
300
+ }
301
+ /**
302
+ * Create a Human-in-the-loop manager instance
303
+ *
304
+ * @example
305
+ * ```ts
306
+ * import { Human } from 'human-in-the-loop'
307
+ *
308
+ * const human = Human({
309
+ * defaultTimeout: 3600000, // 1 hour
310
+ * autoEscalate: true,
311
+ * })
312
+ * ```
313
+ */
314
+ export declare function Human(options?: HumanOptions): HumanManager;
315
+ //# sourceMappingURL=human.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"human.d.ts","sourceRoot":"","sources":["../src/human.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,IAAI,EACJ,IAAI,EACJ,KAAK,IAAI,SAAS,EAClB,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,YAAY,EAGZ,gBAAgB,EAKhB,cAAc,EACd,YAAY,EACZ,WAAW,EAEX,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACb,MAAM,YAAY,CAAA;AAGnB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAY;IACzB,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,MAAM,CAA+B;IAC7C,OAAO,CAAC,kBAAkB,CAAsC;IAChE,OAAO,CAAC,SAAS,CAAsC;gBAE3C,OAAO,GAAE,YAAiB;IAgBtC;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAK5B;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIrC;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAK5B;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIrC;;OAEG;IACH,aAAa,CA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