human-in-the-loop 0.1.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,344 @@
1
+ import { z } from 'zod';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import React from 'react';
4
+
5
+ /**
6
+ * Supported platforms for human-in-the-loop interactions
7
+ */
8
+ type HumanPlatform = 'slack' | 'teams' | 'react' | 'email';
9
+ /**
10
+ * Status of a human task
11
+ */
12
+ type HumanTaskStatus = 'pending' | 'completed' | 'timeout';
13
+ /**
14
+ * Base configuration for Human Functions
15
+ */
16
+ interface HumanFunctionConfig {
17
+ /**
18
+ * Title of the request shown to humans
19
+ */
20
+ title: string;
21
+ /**
22
+ * Description of the task for humans
23
+ */
24
+ description: string;
25
+ /**
26
+ * Platform to use for human interaction
27
+ */
28
+ platform: HumanPlatform;
29
+ /**
30
+ * Timeout in milliseconds after which the task is marked as timed out
31
+ */
32
+ timeout?: number;
33
+ /**
34
+ * Additional platform-specific options
35
+ */
36
+ [key: string]: any;
37
+ }
38
+ /**
39
+ * A request for human input
40
+ */
41
+ interface HumanTaskRequest {
42
+ /**
43
+ * Unique identifier for the task
44
+ */
45
+ taskId: string;
46
+ /**
47
+ * Current status of the task
48
+ */
49
+ status: HumanTaskStatus;
50
+ /**
51
+ * Platform-specific message ID
52
+ */
53
+ messageId?: Record<HumanPlatform, string>;
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 };
@@ -0,0 +1,344 @@
1
+ import { z } from 'zod';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import React from 'react';
4
+
5
+ /**
6
+ * Supported platforms for human-in-the-loop interactions
7
+ */
8
+ type HumanPlatform = 'slack' | 'teams' | 'react' | 'email';
9
+ /**
10
+ * Status of a human task
11
+ */
12
+ type HumanTaskStatus = 'pending' | 'completed' | 'timeout';
13
+ /**
14
+ * Base configuration for Human Functions
15
+ */
16
+ interface HumanFunctionConfig {
17
+ /**
18
+ * Title of the request shown to humans
19
+ */
20
+ title: string;
21
+ /**
22
+ * Description of the task for humans
23
+ */
24
+ description: string;
25
+ /**
26
+ * Platform to use for human interaction
27
+ */
28
+ platform: HumanPlatform;
29
+ /**
30
+ * Timeout in milliseconds after which the task is marked as timed out
31
+ */
32
+ timeout?: number;
33
+ /**
34
+ * Additional platform-specific options
35
+ */
36
+ [key: string]: any;
37
+ }
38
+ /**
39
+ * A request for human input
40
+ */
41
+ interface HumanTaskRequest {
42
+ /**
43
+ * Unique identifier for the task
44
+ */
45
+ taskId: string;
46
+ /**
47
+ * Current status of the task
48
+ */
49
+ status: HumanTaskStatus;
50
+ /**
51
+ * Platform-specific message ID
52
+ */
53
+ messageId?: Record<HumanPlatform, string>;
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 };