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/dist/index.d.cts DELETED
@@ -1,344 +0,0 @@
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 };
@@ -1,69 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { createHumanFunction } from './factory'
3
- import { SlackHumanFunction } from '../platforms/slack'
4
- import { TeamsHumanFunction } from '../platforms/teams'
5
- import { ReactHumanFunction } from '../platforms/react'
6
- import { EmailHumanFunction } from '../platforms/email'
7
-
8
- describe('createHumanFunction', () => {
9
- it('should create a Slack human function', () => {
10
- const humanFunction = createHumanFunction<{}, {}>({
11
- platform: 'slack',
12
- title: 'Test',
13
- description: 'Test description'
14
- })
15
-
16
- expect(humanFunction).toBeInstanceOf(SlackHumanFunction)
17
- })
18
-
19
- it('should create a Teams human function', () => {
20
- const humanFunction = createHumanFunction<{}, {}>({
21
- platform: 'teams',
22
- title: 'Test',
23
- description: 'Test description'
24
- })
25
-
26
- expect(humanFunction).toBeInstanceOf(TeamsHumanFunction)
27
- })
28
-
29
- it('should create a React human function', () => {
30
- const humanFunction = createHumanFunction<{}, {}>({
31
- platform: 'react',
32
- title: 'Test',
33
- description: 'Test description'
34
- })
35
-
36
- expect(humanFunction).toBeInstanceOf(ReactHumanFunction)
37
- })
38
-
39
- it('should create an Email human function', () => {
40
- const humanFunction = createHumanFunction<{}, {}>({
41
- platform: 'email',
42
- title: 'Test',
43
- description: 'Test description',
44
- to: 'test@example.com'
45
- })
46
-
47
- expect(humanFunction).toBeInstanceOf(EmailHumanFunction)
48
- })
49
-
50
- it('should throw an error for unsupported platforms', () => {
51
- expect(() => {
52
- createHumanFunction<{}, {}>({
53
- platform: 'invalid' as any,
54
- title: 'Test',
55
- description: 'Test description'
56
- })
57
- }).toThrow('Unsupported platform: invalid')
58
- })
59
-
60
- it('should throw an error for email platform without to field', () => {
61
- expect(() => {
62
- createHumanFunction<{}, {}>({
63
- platform: 'email',
64
- title: 'Test',
65
- description: 'Test description'
66
- })
67
- }).toThrow('Email platform requires a "to" field in options')
68
- })
69
- })
@@ -1,30 +0,0 @@
1
- import type { CreateHumanFunctionOptions, HumanFunction } from './types'
2
- import { SlackHumanFunction } from '../platforms/slack'
3
- import { TeamsHumanFunction } from '../platforms/teams'
4
- import { ReactHumanFunction } from '../platforms/react'
5
- import { EmailHumanFunction } from '../platforms/email'
6
-
7
- /**
8
- * Create a strongly-typed human function
9
- */
10
- export function createHumanFunction<TInput, TOutput>(
11
- options: CreateHumanFunctionOptions
12
- ): HumanFunction<TInput, TOutput> {
13
- const { platform } = options
14
-
15
- switch (platform) {
16
- case 'slack':
17
- return new SlackHumanFunction<TInput, TOutput>(options)
18
- case 'teams':
19
- return new TeamsHumanFunction<TInput, TOutput>(options)
20
- case 'react':
21
- return new ReactHumanFunction<TInput, TOutput>(options)
22
- case 'email':
23
- if (!options.to) {
24
- throw new Error('Email platform requires a "to" field in options')
25
- }
26
- return new EmailHumanFunction<TInput, TOutput>(options as any)
27
- default:
28
- throw new Error(`Unsupported platform: ${platform}`)
29
- }
30
- }
package/src/core/types.ts DELETED
@@ -1,191 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- /**
4
- * Supported platforms for human-in-the-loop interactions
5
- */
6
- export type HumanPlatform = 'slack' | 'teams' | 'react' | 'email'
7
-
8
- /**
9
- * Status of a human task
10
- */
11
- export type HumanTaskStatus = 'pending' | 'completed' | 'timeout'
12
-
13
- /**
14
- * Base configuration for Human Functions
15
- */
16
- export interface HumanFunctionConfig {
17
- /**
18
- * Title of the request shown to humans
19
- */
20
- title: string
21
-
22
- /**
23
- * Description of the task for humans
24
- */
25
- description: string
26
-
27
- /**
28
- * Platform to use for human interaction
29
- */
30
- platform: HumanPlatform
31
-
32
- /**
33
- * Timeout in milliseconds after which the task is marked as timed out
34
- */
35
- timeout?: number
36
-
37
- /**
38
- * Additional platform-specific options
39
- */
40
- [key: string]: any
41
- }
42
-
43
- /**
44
- * A request for human input
45
- */
46
- export interface HumanTaskRequest {
47
- /**
48
- * Unique identifier for the task
49
- */
50
- taskId: string
51
-
52
- /**
53
- * Current status of the task
54
- */
55
- status: HumanTaskStatus
56
-
57
- /**
58
- * Platform-specific message ID
59
- */
60
- messageId?: Record<HumanPlatform, string>
61
- }
62
-
63
- /**
64
- * Human Function interface with strongly-typed input and output
65
- */
66
- export interface HumanFunction<TInput, TOutput> {
67
- /**
68
- * Request human input with the given input data
69
- */
70
- request(input: TInput): Promise<HumanTaskRequest>
71
-
72
- /**
73
- * Get the human response for a given task
74
- */
75
- getResponse(taskId: string): Promise<TOutput | null>
76
- }
77
-
78
- /**
79
- * Platform-specific configurations
80
- */
81
- export interface PlatformConfigs {
82
- slack?: SlackConfig
83
- teams?: TeamsConfig
84
- react?: ReactConfig
85
- email?: EmailConfig
86
- }
87
-
88
- /**
89
- * Slack-specific configuration
90
- */
91
- export interface SlackConfig {
92
- /**
93
- * Slack channel to send the message to
94
- */
95
- channel?: string
96
-
97
- /**
98
- * User IDs to mention in the message
99
- */
100
- mentions?: string[]
101
-
102
- /**
103
- * Whether to use a modal dialog instead of a message
104
- */
105
- modal?: boolean
106
-
107
- /**
108
- * Custom Slack blocks
109
- */
110
- blocks?: any[]
111
-
112
- /**
113
- * Webhook URL for callbacks
114
- */
115
- webhookUrl?: string
116
- }
117
-
118
- /**
119
- * Microsoft Teams specific configuration
120
- */
121
- export interface TeamsConfig {
122
- /**
123
- * Teams webhook URL
124
- */
125
- webhookUrl?: string
126
-
127
- /**
128
- * Whether to use adaptive cards
129
- */
130
- useAdaptiveCards?: boolean
131
- }
132
-
133
- /**
134
- * React-specific configuration
135
- */
136
- export interface ReactConfig {
137
- /**
138
- * Custom component styling
139
- */
140
- styles?: Record<string, any>
141
-
142
- /**
143
- * Theme configuration
144
- */
145
- theme?: 'light' | 'dark' | 'system'
146
- }
147
-
148
- /**
149
- * Email-specific configuration
150
- */
151
- export interface EmailConfig {
152
- /**
153
- * Recipients of the email
154
- */
155
- to: string | string[]
156
-
157
- /**
158
- * CC recipients
159
- */
160
- cc?: string | string[]
161
-
162
- /**
163
- * BCC recipients
164
- */
165
- bcc?: string | string[]
166
-
167
- /**
168
- * From address
169
- */
170
- from?: string
171
-
172
- /**
173
- * Reply-to address
174
- */
175
- replyTo?: string
176
-
177
- /**
178
- * Callback URL for email responses
179
- */
180
- callbackUrl?: string
181
- }
182
-
183
- /**
184
- * Options for creating human functions
185
- */
186
- export interface CreateHumanFunctionOptions extends HumanFunctionConfig, PlatformConfigs {
187
- /**
188
- * Optional validation schema for the output
189
- */
190
- outputSchema?: z.ZodType<any>
191
- }