@task-mcp/shared 1.0.7 → 1.0.9
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/schemas/index.d.ts +2 -1
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +2 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/project.d.ts +37 -28
- package/dist/schemas/project.d.ts.map +1 -1
- package/dist/schemas/project.js +3 -0
- package/dist/schemas/project.js.map +1 -1
- package/dist/schemas/response-format.d.ts +73 -0
- package/dist/schemas/response-format.d.ts.map +1 -1
- package/dist/schemas/response-format.js +1 -0
- package/dist/schemas/response-format.js.map +1 -1
- package/dist/schemas/response-schema.d.ts +307 -0
- package/dist/schemas/response-schema.d.ts.map +1 -0
- package/dist/schemas/response-schema.js +75 -0
- package/dist/schemas/response-schema.js.map +1 -0
- package/dist/schemas/response-schema.test.d.ts +2 -0
- package/dist/schemas/response-schema.test.d.ts.map +1 -0
- package/dist/schemas/response-schema.test.js +256 -0
- package/dist/schemas/response-schema.test.js.map +1 -0
- package/package.json +1 -1
- package/src/schemas/index.ts +23 -0
- package/src/schemas/project.ts +3 -0
- package/src/schemas/response-format.ts +96 -0
- package/src/schemas/response-schema.test.ts +314 -0
- package/src/schemas/response-schema.ts +92 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
ResponseType,
|
|
4
|
+
ResponsePriority,
|
|
5
|
+
ResponseOption,
|
|
6
|
+
QuestionResponse,
|
|
7
|
+
SuggestionResponse,
|
|
8
|
+
ConfirmationResponse,
|
|
9
|
+
GenerateResponseInput,
|
|
10
|
+
} from "./response-schema.js";
|
|
11
|
+
|
|
12
|
+
describe("Response Schema", () => {
|
|
13
|
+
describe("ResponseType", () => {
|
|
14
|
+
it("should accept valid response types", () => {
|
|
15
|
+
expect(() => ResponseType.parse("question")).not.toThrow();
|
|
16
|
+
expect(() => ResponseType.parse("suggestion")).not.toThrow();
|
|
17
|
+
expect(() => ResponseType.parse("confirmation")).not.toThrow();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should reject invalid response types", () => {
|
|
21
|
+
expect(() => ResponseType.parse("invalid")).toThrow();
|
|
22
|
+
expect(() => ResponseType.parse("ask")).toThrow();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("ResponsePriority", () => {
|
|
27
|
+
it("should accept valid priority levels", () => {
|
|
28
|
+
expect(() => ResponsePriority.parse("low")).not.toThrow();
|
|
29
|
+
expect(() => ResponsePriority.parse("medium")).not.toThrow();
|
|
30
|
+
expect(() => ResponsePriority.parse("high")).not.toThrow();
|
|
31
|
+
expect(() => ResponsePriority.parse("critical")).not.toThrow();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should reject invalid priority levels", () => {
|
|
35
|
+
expect(() => ResponsePriority.parse("urgent")).toThrow();
|
|
36
|
+
expect(() => ResponsePriority.parse("normal")).toThrow();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("ResponseOption", () => {
|
|
41
|
+
it("should validate option with all fields", () => {
|
|
42
|
+
const option = {
|
|
43
|
+
label: "High Priority",
|
|
44
|
+
value: "high",
|
|
45
|
+
description: "For urgent tasks",
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
expect(() => ResponseOption.parse(option)).not.toThrow();
|
|
49
|
+
const parsed = ResponseOption.parse(option);
|
|
50
|
+
expect(parsed.label).toBe("High Priority");
|
|
51
|
+
expect(parsed.value).toBe("high");
|
|
52
|
+
expect(parsed.description).toBe("For urgent tasks");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should validate option without description", () => {
|
|
56
|
+
const option = {
|
|
57
|
+
label: "Low Priority",
|
|
58
|
+
value: "low",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
expect(() => ResponseOption.parse(option)).not.toThrow();
|
|
62
|
+
const parsed = ResponseOption.parse(option);
|
|
63
|
+
expect(parsed.label).toBe("Low Priority");
|
|
64
|
+
expect(parsed.value).toBe("low");
|
|
65
|
+
expect(parsed.description).toBeUndefined();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should reject option without required fields", () => {
|
|
69
|
+
expect(() => ResponseOption.parse({ label: "Test" })).toThrow();
|
|
70
|
+
expect(() => ResponseOption.parse({ value: "test" })).toThrow();
|
|
71
|
+
expect(() => ResponseOption.parse({})).toThrow();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("QuestionResponse", () => {
|
|
76
|
+
it("should validate question with all fields", () => {
|
|
77
|
+
const question = {
|
|
78
|
+
type: "question" as const,
|
|
79
|
+
message: "What should we do?",
|
|
80
|
+
context: "Need clarification on approach",
|
|
81
|
+
priority: "high" as const,
|
|
82
|
+
options: [
|
|
83
|
+
{ label: "Option A", value: "a" },
|
|
84
|
+
{ label: "Option B", value: "b" },
|
|
85
|
+
],
|
|
86
|
+
defaultOption: "a",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
expect(() => QuestionResponse.parse(question)).not.toThrow();
|
|
90
|
+
const parsed = QuestionResponse.parse(question);
|
|
91
|
+
expect(parsed.type).toBe("question");
|
|
92
|
+
expect(parsed.message).toBe("What should we do?");
|
|
93
|
+
expect(parsed.options).toHaveLength(2);
|
|
94
|
+
expect(parsed.defaultOption).toBe("a");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should validate question with minimal fields", () => {
|
|
98
|
+
const question = {
|
|
99
|
+
type: "question" as const,
|
|
100
|
+
message: "Proceed?",
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
expect(() => QuestionResponse.parse(question)).not.toThrow();
|
|
104
|
+
const parsed = QuestionResponse.parse(question);
|
|
105
|
+
expect(parsed.type).toBe("question");
|
|
106
|
+
expect(parsed.message).toBe("Proceed?");
|
|
107
|
+
expect(parsed.context).toBeUndefined();
|
|
108
|
+
expect(parsed.options).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should reject question without message", () => {
|
|
112
|
+
expect(() => QuestionResponse.parse({ type: "question" })).toThrow();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("should reject question with wrong type", () => {
|
|
116
|
+
expect(() =>
|
|
117
|
+
QuestionResponse.parse({
|
|
118
|
+
type: "suggestion",
|
|
119
|
+
message: "Test",
|
|
120
|
+
})
|
|
121
|
+
).toThrow();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("SuggestionResponse", () => {
|
|
126
|
+
it("should validate suggestion with all fields", () => {
|
|
127
|
+
const suggestion = {
|
|
128
|
+
type: "suggestion" as const,
|
|
129
|
+
message: "Consider breaking down this task",
|
|
130
|
+
context: "Task is complex",
|
|
131
|
+
priority: "medium" as const,
|
|
132
|
+
options: [
|
|
133
|
+
{ label: "3 subtasks", value: "sub_3" },
|
|
134
|
+
{ label: "5 subtasks", value: "sub_5" },
|
|
135
|
+
],
|
|
136
|
+
reasoning: "Based on complexity analysis",
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
expect(() => SuggestionResponse.parse(suggestion)).not.toThrow();
|
|
140
|
+
const parsed = SuggestionResponse.parse(suggestion);
|
|
141
|
+
expect(parsed.type).toBe("suggestion");
|
|
142
|
+
expect(parsed.options).toHaveLength(2);
|
|
143
|
+
expect(parsed.reasoning).toBe("Based on complexity analysis");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should validate suggestion with minimal fields", () => {
|
|
147
|
+
const suggestion = {
|
|
148
|
+
type: "suggestion" as const,
|
|
149
|
+
message: "Try this",
|
|
150
|
+
options: [{ label: "Do it", value: "yes" }],
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
expect(() => SuggestionResponse.parse(suggestion)).not.toThrow();
|
|
154
|
+
const parsed = SuggestionResponse.parse(suggestion);
|
|
155
|
+
expect(parsed.options).toHaveLength(1);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("should reject suggestion without options", () => {
|
|
159
|
+
expect(() =>
|
|
160
|
+
SuggestionResponse.parse({
|
|
161
|
+
type: "suggestion",
|
|
162
|
+
message: "Test",
|
|
163
|
+
})
|
|
164
|
+
).toThrow();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("should reject suggestion with empty options array", () => {
|
|
168
|
+
expect(() =>
|
|
169
|
+
SuggestionResponse.parse({
|
|
170
|
+
type: "suggestion",
|
|
171
|
+
message: "Test",
|
|
172
|
+
options: [],
|
|
173
|
+
})
|
|
174
|
+
).toThrow();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe("ConfirmationResponse", () => {
|
|
179
|
+
it("should validate confirmation with all fields", () => {
|
|
180
|
+
const confirmation = {
|
|
181
|
+
type: "confirmation" as const,
|
|
182
|
+
message: "Are you sure?",
|
|
183
|
+
action: "Delete all completed tasks",
|
|
184
|
+
context: "This operation is irreversible",
|
|
185
|
+
priority: "critical" as const,
|
|
186
|
+
consequences: ["10 tasks will be removed", "Cannot be undone"],
|
|
187
|
+
defaultConfirm: false,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
expect(() => ConfirmationResponse.parse(confirmation)).not.toThrow();
|
|
191
|
+
const parsed = ConfirmationResponse.parse(confirmation);
|
|
192
|
+
expect(parsed.type).toBe("confirmation");
|
|
193
|
+
expect(parsed.action).toBe("Delete all completed tasks");
|
|
194
|
+
expect(parsed.consequences).toHaveLength(2);
|
|
195
|
+
expect(parsed.defaultConfirm).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should validate confirmation with minimal fields", () => {
|
|
199
|
+
const confirmation = {
|
|
200
|
+
type: "confirmation" as const,
|
|
201
|
+
message: "Delete this?",
|
|
202
|
+
action: "Delete task",
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
expect(() => ConfirmationResponse.parse(confirmation)).not.toThrow();
|
|
206
|
+
const parsed = ConfirmationResponse.parse(confirmation);
|
|
207
|
+
expect(parsed.action).toBe("Delete task");
|
|
208
|
+
expect(parsed.consequences).toBeUndefined();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("should reject confirmation without action", () => {
|
|
212
|
+
expect(() =>
|
|
213
|
+
ConfirmationResponse.parse({
|
|
214
|
+
type: "confirmation",
|
|
215
|
+
message: "Confirm?",
|
|
216
|
+
})
|
|
217
|
+
).toThrow();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("should reject confirmation without message", () => {
|
|
221
|
+
expect(() =>
|
|
222
|
+
ConfirmationResponse.parse({
|
|
223
|
+
type: "confirmation",
|
|
224
|
+
action: "Do something",
|
|
225
|
+
})
|
|
226
|
+
).toThrow();
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe("GenerateResponseInput", () => {
|
|
231
|
+
it("should validate input for question type", () => {
|
|
232
|
+
const input = {
|
|
233
|
+
type: "question" as const,
|
|
234
|
+
message: "What to do?",
|
|
235
|
+
options: [{ label: "Yes", value: "yes" }],
|
|
236
|
+
defaultOption: "yes",
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
expect(() => GenerateResponseInput.parse(input)).not.toThrow();
|
|
240
|
+
const parsed = GenerateResponseInput.parse(input);
|
|
241
|
+
expect(parsed.type).toBe("question");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("should validate input for suggestion type", () => {
|
|
245
|
+
const input = {
|
|
246
|
+
type: "suggestion" as const,
|
|
247
|
+
message: "Try this",
|
|
248
|
+
options: [{ label: "Option", value: "opt" }],
|
|
249
|
+
reasoning: "Because reasons",
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
expect(() => GenerateResponseInput.parse(input)).not.toThrow();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("should validate input for confirmation type", () => {
|
|
256
|
+
const input = {
|
|
257
|
+
type: "confirmation" as const,
|
|
258
|
+
message: "Sure?",
|
|
259
|
+
action: "Delete",
|
|
260
|
+
consequences: ["Gone forever"],
|
|
261
|
+
defaultConfirm: false,
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
expect(() => GenerateResponseInput.parse(input)).not.toThrow();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("should use default priority of medium", () => {
|
|
268
|
+
const input = {
|
|
269
|
+
type: "question" as const,
|
|
270
|
+
message: "Test?",
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const parsed = GenerateResponseInput.parse(input);
|
|
274
|
+
expect(parsed.priority).toBe("medium");
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("should allow custom priority", () => {
|
|
278
|
+
const input = {
|
|
279
|
+
type: "question" as const,
|
|
280
|
+
message: "Test?",
|
|
281
|
+
priority: "critical" as const,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const parsed = GenerateResponseInput.parse(input);
|
|
285
|
+
expect(parsed.priority).toBe("critical");
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
describe("Type discrimination", () => {
|
|
290
|
+
it("should differentiate response types at compile time", () => {
|
|
291
|
+
const question: QuestionResponse = {
|
|
292
|
+
type: "question",
|
|
293
|
+
message: "Test",
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const suggestion: SuggestionResponse = {
|
|
297
|
+
type: "suggestion",
|
|
298
|
+
message: "Test",
|
|
299
|
+
options: [{ label: "A", value: "a" }],
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const confirmation: ConfirmationResponse = {
|
|
303
|
+
type: "confirmation",
|
|
304
|
+
message: "Test",
|
|
305
|
+
action: "Do it",
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// TypeScript should allow this
|
|
309
|
+
expect(question.type).toBe("question");
|
|
310
|
+
expect(suggestion.type).toBe("suggestion");
|
|
311
|
+
expect(confirmation.type).toBe("confirmation");
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Response Schema
|
|
5
|
+
*
|
|
6
|
+
* Standardized formats for AI agents to ask questions, make suggestions,
|
|
7
|
+
* or request confirmation from users.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Response types
|
|
11
|
+
export const ResponseType = z.enum(["question", "suggestion", "confirmation"]);
|
|
12
|
+
export type ResponseType = z.infer<typeof ResponseType>;
|
|
13
|
+
|
|
14
|
+
// Priority level for responses
|
|
15
|
+
export const ResponsePriority = z.enum(["low", "medium", "high", "critical"]);
|
|
16
|
+
export type ResponsePriority = z.infer<typeof ResponsePriority>;
|
|
17
|
+
|
|
18
|
+
// Option for multiple choice responses
|
|
19
|
+
export const ResponseOption = z.object({
|
|
20
|
+
label: z.string().describe("Display text for the option"),
|
|
21
|
+
value: z.string().describe("Value to return when selected"),
|
|
22
|
+
description: z.string().optional().describe("Additional explanation"),
|
|
23
|
+
});
|
|
24
|
+
export type ResponseOption = z.infer<typeof ResponseOption>;
|
|
25
|
+
|
|
26
|
+
// Base response schema
|
|
27
|
+
const BaseResponse = z.object({
|
|
28
|
+
type: ResponseType.describe("Type of response: question, suggestion, or confirmation"),
|
|
29
|
+
message: z.string().describe("Main message to display to user"),
|
|
30
|
+
context: z.string().optional().describe("Additional context or explanation"),
|
|
31
|
+
priority: ResponsePriority.optional().describe("Urgency/importance of response (default: medium)"),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Question response - for clarification
|
|
35
|
+
export const QuestionResponse = BaseResponse.extend({
|
|
36
|
+
type: z.literal("question"),
|
|
37
|
+
options: z.array(ResponseOption).optional()
|
|
38
|
+
.describe("Multiple choice options (omit for free-form answer)"),
|
|
39
|
+
defaultOption: z.string().optional()
|
|
40
|
+
.describe("Default option value if user provides no input"),
|
|
41
|
+
});
|
|
42
|
+
export type QuestionResponse = z.infer<typeof QuestionResponse>;
|
|
43
|
+
|
|
44
|
+
// Suggestion response - for recommendations
|
|
45
|
+
export const SuggestionResponse = BaseResponse.extend({
|
|
46
|
+
type: z.literal("suggestion"),
|
|
47
|
+
options: z.array(ResponseOption).min(1)
|
|
48
|
+
.describe("Suggested options for user to choose from"),
|
|
49
|
+
reasoning: z.string().optional()
|
|
50
|
+
.describe("Explanation of why these suggestions were made"),
|
|
51
|
+
});
|
|
52
|
+
export type SuggestionResponse = z.infer<typeof SuggestionResponse>;
|
|
53
|
+
|
|
54
|
+
// Confirmation response - for explicit approval
|
|
55
|
+
export const ConfirmationResponse = BaseResponse.extend({
|
|
56
|
+
type: z.literal("confirmation"),
|
|
57
|
+
action: z.string().describe("Action that will be taken if confirmed"),
|
|
58
|
+
consequences: z.array(z.string()).optional()
|
|
59
|
+
.describe("List of effects or changes that will occur"),
|
|
60
|
+
defaultConfirm: z.boolean().optional()
|
|
61
|
+
.describe("Default choice if user provides no input (default: false)"),
|
|
62
|
+
});
|
|
63
|
+
export type ConfirmationResponse = z.infer<typeof ConfirmationResponse>;
|
|
64
|
+
|
|
65
|
+
// Union type for all response types
|
|
66
|
+
export const AgentResponse = z.discriminatedUnion("type", [
|
|
67
|
+
QuestionResponse,
|
|
68
|
+
SuggestionResponse,
|
|
69
|
+
ConfirmationResponse,
|
|
70
|
+
]);
|
|
71
|
+
export type AgentResponse = z.infer<typeof AgentResponse>;
|
|
72
|
+
|
|
73
|
+
// Input schema for generating responses
|
|
74
|
+
export const GenerateResponseInput = z.object({
|
|
75
|
+
type: ResponseType.describe("Type of response to generate"),
|
|
76
|
+
message: z.string().describe("Main message"),
|
|
77
|
+
options: z.array(ResponseOption).optional()
|
|
78
|
+
.describe("Options for question/suggestion types"),
|
|
79
|
+
context: z.string().optional(),
|
|
80
|
+
priority: ResponsePriority.optional().default("medium"),
|
|
81
|
+
action: z.string().optional()
|
|
82
|
+
.describe("Action description (for confirmation type)"),
|
|
83
|
+
consequences: z.array(z.string()).optional()
|
|
84
|
+
.describe("Consequences list (for confirmation type)"),
|
|
85
|
+
reasoning: z.string().optional()
|
|
86
|
+
.describe("Reasoning explanation (for suggestion type)"),
|
|
87
|
+
defaultOption: z.string().optional()
|
|
88
|
+
.describe("Default option value (for question type)"),
|
|
89
|
+
defaultConfirm: z.boolean().optional()
|
|
90
|
+
.describe("Default confirmation choice (for confirmation type)"),
|
|
91
|
+
});
|
|
92
|
+
export type GenerateResponseInput = z.infer<typeof GenerateResponseInput>;
|