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.
- package/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +17 -0
- package/README.md +600 -166
- package/dist/helpers.d.ts +308 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +275 -0
- package/dist/helpers.js.map +1 -0
- package/dist/human.d.ts +315 -0
- package/dist/human.d.ts.map +1 -0
- package/dist/human.js +476 -0
- package/dist/human.js.map +1 -0
- package/dist/index.d.ts +48 -343
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -793
- package/dist/index.js.map +1 -0
- package/dist/store.d.ts +61 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +162 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +399 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/examples/basic-usage.ts +386 -0
- package/package.json +23 -54
- package/src/helpers.ts +379 -0
- package/src/human.test.ts +384 -0
- package/src/human.ts +626 -0
- package/src/index.ts +102 -6
- package/src/store.ts +201 -0
- package/src/types.ts +431 -0
- package/tsconfig.json +6 -11
- package/TODO.md +0 -53
- package/dist/index.cjs +0 -899
- package/dist/index.d.cts +0 -344
- package/src/core/factory.test.ts +0 -69
- package/src/core/factory.ts +0 -30
- package/src/core/types.ts +0 -191
- package/src/platforms/email/index.tsx +0 -137
- package/src/platforms/react/index.tsx +0 -218
- package/src/platforms/slack/index.ts +0 -84
- package/src/platforms/teams/index.ts +0 -84
- package/vitest.config.ts +0 -15
package/dist/index.d.ts
CHANGED
|
@@ -1,344 +1,49 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
interface
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Human Function interface with strongly-typed input and output
|
|
57
|
-
*/
|
|
58
|
-
interface HumanFunction<TInput, TOutput> {
|
|
59
|
-
/**
|
|
60
|
-
* Request human input with the given input data
|
|
61
|
-
*/
|
|
62
|
-
request(input: TInput): Promise<HumanTaskRequest>;
|
|
63
|
-
/**
|
|
64
|
-
* Get the human response for a given task
|
|
65
|
-
*/
|
|
66
|
-
getResponse(taskId: string): Promise<TOutput | null>;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Platform-specific configurations
|
|
70
|
-
*/
|
|
71
|
-
interface PlatformConfigs {
|
|
72
|
-
slack?: SlackConfig;
|
|
73
|
-
teams?: TeamsConfig;
|
|
74
|
-
react?: ReactConfig;
|
|
75
|
-
email?: EmailConfig;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Slack-specific configuration
|
|
79
|
-
*/
|
|
80
|
-
interface SlackConfig {
|
|
81
|
-
/**
|
|
82
|
-
* Slack channel to send the message to
|
|
83
|
-
*/
|
|
84
|
-
channel?: string;
|
|
85
|
-
/**
|
|
86
|
-
* User IDs to mention in the message
|
|
87
|
-
*/
|
|
88
|
-
mentions?: string[];
|
|
89
|
-
/**
|
|
90
|
-
* Whether to use a modal dialog instead of a message
|
|
91
|
-
*/
|
|
92
|
-
modal?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Custom Slack blocks
|
|
95
|
-
*/
|
|
96
|
-
blocks?: any[];
|
|
97
|
-
/**
|
|
98
|
-
* Webhook URL for callbacks
|
|
99
|
-
*/
|
|
100
|
-
webhookUrl?: string;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Microsoft Teams specific configuration
|
|
104
|
-
*/
|
|
105
|
-
interface TeamsConfig {
|
|
106
|
-
/**
|
|
107
|
-
* Teams webhook URL
|
|
108
|
-
*/
|
|
109
|
-
webhookUrl?: string;
|
|
110
|
-
/**
|
|
111
|
-
* Whether to use adaptive cards
|
|
112
|
-
*/
|
|
113
|
-
useAdaptiveCards?: boolean;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* React-specific configuration
|
|
117
|
-
*/
|
|
118
|
-
interface ReactConfig {
|
|
119
|
-
/**
|
|
120
|
-
* Custom component styling
|
|
121
|
-
*/
|
|
122
|
-
styles?: Record<string, any>;
|
|
123
|
-
/**
|
|
124
|
-
* Theme configuration
|
|
125
|
-
*/
|
|
126
|
-
theme?: 'light' | 'dark' | 'system';
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Email-specific configuration
|
|
130
|
-
*/
|
|
131
|
-
interface EmailConfig {
|
|
132
|
-
/**
|
|
133
|
-
* Recipients of the email
|
|
134
|
-
*/
|
|
135
|
-
to: string | string[];
|
|
136
|
-
/**
|
|
137
|
-
* CC recipients
|
|
138
|
-
*/
|
|
139
|
-
cc?: string | string[];
|
|
140
|
-
/**
|
|
141
|
-
* BCC recipients
|
|
142
|
-
*/
|
|
143
|
-
bcc?: string | string[];
|
|
144
|
-
/**
|
|
145
|
-
* From address
|
|
146
|
-
*/
|
|
147
|
-
from?: string;
|
|
148
|
-
/**
|
|
149
|
-
* Reply-to address
|
|
150
|
-
*/
|
|
151
|
-
replyTo?: string;
|
|
152
|
-
/**
|
|
153
|
-
* Callback URL for email responses
|
|
154
|
-
*/
|
|
155
|
-
callbackUrl?: string;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Options for creating human functions
|
|
159
|
-
*/
|
|
160
|
-
interface CreateHumanFunctionOptions extends HumanFunctionConfig, PlatformConfigs {
|
|
161
|
-
/**
|
|
162
|
-
* Optional validation schema for the output
|
|
163
|
-
*/
|
|
164
|
-
outputSchema?: z.ZodType<any>;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Create a strongly-typed human function
|
|
169
|
-
*/
|
|
170
|
-
declare function createHumanFunction<TInput, TOutput>(options: CreateHumanFunctionOptions): HumanFunction<TInput, TOutput>;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Slack-specific response option
|
|
174
|
-
*/
|
|
175
|
-
interface SlackResponseOption {
|
|
176
|
-
value: string;
|
|
177
|
-
label: string;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Create a Slack message with the given options
|
|
181
|
-
*/
|
|
182
|
-
declare function createSlackMessage<TInput, TOutput>(taskId: string, input: TInput, config: SlackConfig & {
|
|
183
|
-
title: string;
|
|
184
|
-
description: string;
|
|
185
|
-
options?: string[] | SlackResponseOption[];
|
|
186
|
-
freeText?: boolean;
|
|
187
|
-
}): Promise<{
|
|
188
|
-
messageId: string;
|
|
189
|
-
}>;
|
|
190
|
-
/**
|
|
191
|
-
* Get the response for a Slack task
|
|
192
|
-
*/
|
|
193
|
-
declare function getSlackResponse<TOutput>(taskId: string): Promise<TOutput | null>;
|
|
194
|
-
/**
|
|
195
|
-
* Implementation of HumanFunction for Slack
|
|
196
|
-
*/
|
|
197
|
-
declare class SlackHumanFunction<TInput, TOutput> implements HumanFunction<TInput, TOutput> {
|
|
198
|
-
private config;
|
|
199
|
-
constructor(config: SlackConfig & {
|
|
200
|
-
title: string;
|
|
201
|
-
description: string;
|
|
202
|
-
options?: string[] | SlackResponseOption[];
|
|
203
|
-
freeText?: boolean;
|
|
204
|
-
});
|
|
205
|
-
request(input: TInput): Promise<HumanTaskRequest>;
|
|
206
|
-
getResponse(taskId: string): Promise<TOutput | null>;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Teams-specific response option
|
|
211
|
-
*/
|
|
212
|
-
interface TeamsResponseOption {
|
|
213
|
-
value: string;
|
|
214
|
-
label: string;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Create a Teams message with the given options
|
|
218
|
-
*/
|
|
219
|
-
declare function createTeamsMessage<TInput, TOutput>(taskId: string, input: TInput, config: TeamsConfig & {
|
|
220
|
-
title: string;
|
|
221
|
-
description: string;
|
|
222
|
-
options?: string[] | TeamsResponseOption[];
|
|
223
|
-
freeText?: boolean;
|
|
224
|
-
}): Promise<{
|
|
225
|
-
messageId: string;
|
|
226
|
-
}>;
|
|
227
|
-
/**
|
|
228
|
-
* Get the response for a Teams task
|
|
229
|
-
*/
|
|
230
|
-
declare function getTeamsResponse<TOutput>(taskId: string): Promise<TOutput | null>;
|
|
231
|
-
/**
|
|
232
|
-
* Implementation of HumanFunction for Microsoft Teams
|
|
233
|
-
*/
|
|
234
|
-
declare class TeamsHumanFunction<TInput, TOutput> implements HumanFunction<TInput, TOutput> {
|
|
235
|
-
private config;
|
|
236
|
-
constructor(config: TeamsConfig & {
|
|
237
|
-
title: string;
|
|
238
|
-
description: string;
|
|
239
|
-
options?: string[] | TeamsResponseOption[];
|
|
240
|
-
freeText?: boolean;
|
|
241
|
-
});
|
|
242
|
-
request(input: TInput): Promise<HumanTaskRequest>;
|
|
243
|
-
getResponse(taskId: string): Promise<TOutput | null>;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Props for the HumanFeedback component
|
|
248
|
-
*/
|
|
249
|
-
interface HumanFeedbackProps<TInput, TOutput> {
|
|
250
|
-
taskId: string;
|
|
251
|
-
title: string;
|
|
252
|
-
description: string;
|
|
253
|
-
input: TInput;
|
|
254
|
-
options?: string[] | Array<{
|
|
255
|
-
value: string;
|
|
256
|
-
label: string;
|
|
257
|
-
}>;
|
|
258
|
-
freeText?: boolean;
|
|
259
|
-
onSubmit: (response: Partial<TOutput>) => void;
|
|
260
|
-
config?: ReactConfig;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Simple React component for human feedback
|
|
264
|
-
*/
|
|
265
|
-
declare function HumanFeedback<TInput, TOutput>({ taskId, title, description, input, options, freeText, onSubmit, config }: HumanFeedbackProps<TInput, TOutput>): react_jsx_runtime.JSX.Element;
|
|
266
|
-
/**
|
|
267
|
-
* Implementation of HumanFunction for React
|
|
268
|
-
*/
|
|
269
|
-
declare class ReactHumanFunction<TInput, TOutput> implements HumanFunction<TInput, TOutput> {
|
|
270
|
-
private config;
|
|
271
|
-
constructor(config: ReactConfig & {
|
|
272
|
-
title: string;
|
|
273
|
-
description: string;
|
|
274
|
-
options?: string[] | Array<{
|
|
275
|
-
value: string;
|
|
276
|
-
label: string;
|
|
277
|
-
}>;
|
|
278
|
-
freeText?: boolean;
|
|
279
|
-
});
|
|
280
|
-
request(input: TInput): Promise<HumanTaskRequest>;
|
|
281
|
-
getResponse(taskId: string): Promise<TOutput | null>;
|
|
282
|
-
/**
|
|
283
|
-
* Handle a response submission
|
|
284
|
-
*/
|
|
285
|
-
handleResponse(taskId: string, response: TOutput): void;
|
|
286
|
-
/**
|
|
287
|
-
* Get a React component for this human function
|
|
288
|
-
*/
|
|
289
|
-
getComponent(taskId: string, input: TInput): React.ReactNode;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Basic Email Template component
|
|
294
|
-
*/
|
|
295
|
-
declare function EmailTemplate({ taskId, title, description, options, callbackUrl }: {
|
|
296
|
-
taskId: string;
|
|
297
|
-
title: string;
|
|
298
|
-
description: string;
|
|
299
|
-
options?: string[] | Array<{
|
|
300
|
-
value: string;
|
|
301
|
-
label: string;
|
|
302
|
-
}>;
|
|
303
|
-
callbackUrl?: string;
|
|
304
|
-
}): react_jsx_runtime.JSX.Element;
|
|
305
|
-
/**
|
|
306
|
-
* Mock function to send an email
|
|
307
|
-
*/
|
|
308
|
-
declare function sendEmail(config: EmailConfig & {
|
|
309
|
-
title: string;
|
|
310
|
-
description: string;
|
|
311
|
-
options?: string[] | Array<{
|
|
312
|
-
value: string;
|
|
313
|
-
label: string;
|
|
314
|
-
}>;
|
|
315
|
-
taskId: string;
|
|
316
|
-
}): Promise<{
|
|
317
|
-
messageId: string;
|
|
318
|
-
}>;
|
|
319
|
-
/**
|
|
320
|
-
* Get the response for an email task
|
|
321
|
-
*/
|
|
322
|
-
declare function getEmailResponse<TOutput>(taskId: string): Promise<TOutput | null>;
|
|
323
|
-
/**
|
|
324
|
-
* Implementation of HumanFunction for Email
|
|
325
|
-
*/
|
|
326
|
-
declare class EmailHumanFunction<TInput, TOutput> implements HumanFunction<TInput, TOutput> {
|
|
327
|
-
private config;
|
|
328
|
-
constructor(config: EmailConfig & {
|
|
329
|
-
title: string;
|
|
330
|
-
description: string;
|
|
331
|
-
options?: string[] | Array<{
|
|
332
|
-
value: string;
|
|
333
|
-
label: string;
|
|
334
|
-
}>;
|
|
335
|
-
});
|
|
336
|
-
request(input: TInput): Promise<HumanTaskRequest>;
|
|
337
|
-
getResponse(taskId: string): Promise<TOutput | null>;
|
|
338
|
-
/**
|
|
339
|
-
* Get a React component for this email template
|
|
340
|
-
*/
|
|
341
|
-
getEmailComponent(taskId: string): React.ReactNode;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
export { type CreateHumanFunctionOptions, type EmailConfig, EmailHumanFunction, EmailTemplate, HumanFeedback, type HumanFeedbackProps, type HumanFunction, type HumanFunctionConfig, type HumanPlatform, type HumanTaskRequest, type HumanTaskStatus, type PlatformConfigs, type ReactConfig, ReactHumanFunction, type SlackConfig, SlackHumanFunction, type SlackResponseOption, type TeamsConfig, TeamsHumanFunction, type TeamsResponseOption, createHumanFunction, createSlackMessage, createTeamsMessage, getEmailResponse, getSlackResponse, getTeamsResponse, sendEmail };
|
|
2
|
+
* human-in-the-loop - Primitives for integrating human oversight and intervention in AI workflows
|
|
3
|
+
*
|
|
4
|
+
* This package provides primitives for human oversight and intervention in AI workflows:
|
|
5
|
+
* - Approval gates and workflows
|
|
6
|
+
* - Review processes and queues
|
|
7
|
+
* - Escalation paths
|
|
8
|
+
* - Human intervention points
|
|
9
|
+
* - Role and team management
|
|
10
|
+
* - Goals, KPIs, and OKRs tracking
|
|
11
|
+
*
|
|
12
|
+
* Implements the digital-workers interface for humans operating within a company boundary.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { Human, approve, ask, notify } from 'human-in-the-loop'
|
|
18
|
+
*
|
|
19
|
+
* // Create a Human-in-the-loop manager
|
|
20
|
+
* const human = Human({
|
|
21
|
+
* defaultTimeout: 3600000, // 1 hour
|
|
22
|
+
* autoEscalate: true,
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* // Request approval
|
|
26
|
+
* const result = await approve({
|
|
27
|
+
* title: 'Deploy to production',
|
|
28
|
+
* description: 'Approve deployment of v2.0.0',
|
|
29
|
+
* subject: 'Production Deployment',
|
|
30
|
+
* assignee: 'tech-lead@example.com',
|
|
31
|
+
* priority: 'high',
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* if (result.approved) {
|
|
35
|
+
* await deploy()
|
|
36
|
+
* await notify({
|
|
37
|
+
* type: 'success',
|
|
38
|
+
* title: 'Deployment complete',
|
|
39
|
+
* message: 'v2.0.0 deployed to production',
|
|
40
|
+
* recipient: 'team@example.com',
|
|
41
|
+
* })
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export { Human, HumanManager } from './human.js';
|
|
46
|
+
export { Role, Team, Goals, approve, ask, do, decide, generate, is, notify, kpis, okrs, registerHuman, getDefaultHuman, } from './helpers.js';
|
|
47
|
+
export { InMemoryHumanStore } from './store.js';
|
|
48
|
+
export type { HumanRequestStatus, Priority, Role as RoleType, Team as TeamType, Human as HumanType, Goals as GoalsType, KPIs, OKRs, HumanRequest, ApprovalRequest, ApprovalResponse, QuestionRequest, TaskRequest, DecisionRequest, ReviewRequest, ReviewResponse, Notification, ReviewQueue, EscalationPolicy, ApprovalWorkflow, HumanStore, HumanOptions, } from './types.js';
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAGH,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAGhD,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,OAAO,EACP,GAAG,EACH,EAAE,EACF,MAAM,EACN,QAAQ,EACR,EAAE,EACF,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,aAAa,EACb,eAAe,GAChB,MAAM,cAAc,CAAA;AAGrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAG/C,YAAY,EAEV,kBAAkB,EAClB,QAAQ,EAGR,IAAI,IAAI,QAAQ,EAChB,IAAI,IAAI,QAAQ,EAChB,KAAK,IAAI,SAAS,EAClB,KAAK,IAAI,SAAS,EAClB,IAAI,EACJ,IAAI,EAGJ,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,EAGZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAGhB,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAA"}
|