@agen-ai/agent-protocol 0.4.1 → 0.4.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/README.md +89 -49
- package/dist/capabilities/types.d.ts +1 -1
- package/dist/events/types.d.ts +9 -3
- package/dist/events/types.js +4 -1
- package/dist/foundation/types.d.ts +1 -1
- package/dist/foundation/types.js +1 -1
- package/dist/jsonSchema/generated.d.ts +11294 -7902
- package/dist/jsonSchema/generated.js +2271 -96
- package/dist/requests/elicitation.d.ts +4 -0
- package/dist/requests/elicitation.js +107 -0
- package/dist/requests/parsers.js +2 -100
- package/dist/sessionInteractions/parsers.d.ts +28 -1
- package/dist/sessionInteractions/parsers.js +165 -12
- package/dist/sessionInteractions/types.d.ts +113 -1
- package/dist/sessionInteractions/types.js +18 -2
- package/dist/zod/capabilities.d.ts +8 -8
- package/dist/zod/collaboration.d.ts +2 -2
- package/dist/zod/events.d.ts +50 -29
- package/dist/zod/events.js +8 -0
- package/dist/zod/index.d.ts +1 -1
- package/dist/zod/index.js +43 -1
- package/dist/zod/operations.d.ts +1 -1
- package/dist/zod/requests.d.ts +99 -7
- package/dist/zod/requests.js +18 -8
- package/dist/zod/sessionInteractions.d.ts +875 -5
- package/dist/zod/sessionInteractions.js +203 -33
- package/dist/zod/turns.d.ts +1 -1
- package/dist/zod/typeEquality.generated.d.ts +20 -2
- package/package.json +2 -2
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ValidationIssue } from '@agen-ai/validation';
|
|
2
|
+
import type { AgentElicitationAnswer, AgentElicitationField } from './types.js';
|
|
3
|
+
export declare function elicitationResponseIssues(fieldsInput: readonly AgentElicitationField[], answers: readonly AgentElicitationAnswer[]): readonly ValidationIssue[];
|
|
4
|
+
//# sourceMappingURL=elicitation.d.ts.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
function issue(path, message) {
|
|
2
|
+
return { code: "custom", path, message };
|
|
3
|
+
}
|
|
4
|
+
function singleSelectAnswerIssues(field, answer, answerIndex) {
|
|
5
|
+
const issues = [];
|
|
6
|
+
const allowedValues = new Set(field.options.map((option) => option.value));
|
|
7
|
+
if (answer.value !== void 0 && !allowedValues.has(answer.value)) {
|
|
8
|
+
issues.push(issue(
|
|
9
|
+
["answers", answerIndex, "value"],
|
|
10
|
+
"Single-select answers must reference an option declared by the request."
|
|
11
|
+
));
|
|
12
|
+
}
|
|
13
|
+
if (answer.other !== void 0 && !field.allowOther) {
|
|
14
|
+
issues.push(issue(
|
|
15
|
+
["answers", answerIndex, "other"],
|
|
16
|
+
"This request field does not accept a custom choice."
|
|
17
|
+
));
|
|
18
|
+
}
|
|
19
|
+
return issues;
|
|
20
|
+
}
|
|
21
|
+
function multiSelectAnswerIssues(field, answer, answerIndex) {
|
|
22
|
+
const issues = [];
|
|
23
|
+
const allowedValues = new Set(field.options.map((option) => option.value));
|
|
24
|
+
if (answer.values.some((value) => !allowedValues.has(value))) {
|
|
25
|
+
issues.push(issue(
|
|
26
|
+
["answers", answerIndex, "values"],
|
|
27
|
+
"Multi-select answers must reference options declared by the request."
|
|
28
|
+
));
|
|
29
|
+
}
|
|
30
|
+
if (answer.other !== void 0 && !field.allowOther) {
|
|
31
|
+
issues.push(issue(
|
|
32
|
+
["answers", answerIndex, "other"],
|
|
33
|
+
"This request field does not accept a custom choice."
|
|
34
|
+
));
|
|
35
|
+
}
|
|
36
|
+
const selectionCount = answer.values.length + (answer.other === void 0 ? 0 : 1);
|
|
37
|
+
if (field.required && selectionCount === 0) {
|
|
38
|
+
issues.push(issue(
|
|
39
|
+
["answers", answerIndex],
|
|
40
|
+
"A required multi-select answer needs a declared option or a custom choice."
|
|
41
|
+
));
|
|
42
|
+
}
|
|
43
|
+
if (selectionCount > field.maxSelections) {
|
|
44
|
+
issues.push(issue(
|
|
45
|
+
["answers", answerIndex],
|
|
46
|
+
"This request field exceeds its maximum selection count."
|
|
47
|
+
));
|
|
48
|
+
}
|
|
49
|
+
return issues;
|
|
50
|
+
}
|
|
51
|
+
function answerIssues(field, answer, answerIndex) {
|
|
52
|
+
if (field.kind !== answer.kind) {
|
|
53
|
+
return [issue(
|
|
54
|
+
["answers", answerIndex, "kind"],
|
|
55
|
+
"Answer kind must match the corresponding request field."
|
|
56
|
+
)];
|
|
57
|
+
}
|
|
58
|
+
if (field.kind === "text" && answer.kind === "text") {
|
|
59
|
+
return answer.value.length <= field.maxLength ? [] : [issue(
|
|
60
|
+
["answers", answerIndex, "value"],
|
|
61
|
+
"Text answer exceeds the field maximum length."
|
|
62
|
+
)];
|
|
63
|
+
}
|
|
64
|
+
if (field.kind === "single_select" && answer.kind === "single_select") {
|
|
65
|
+
return singleSelectAnswerIssues(field, answer, answerIndex);
|
|
66
|
+
}
|
|
67
|
+
if (field.kind === "multi_select" && answer.kind === "multi_select") {
|
|
68
|
+
return multiSelectAnswerIssues(field, answer, answerIndex);
|
|
69
|
+
}
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
function elicitationResponseIssues(fieldsInput, answers) {
|
|
73
|
+
const issues = [];
|
|
74
|
+
const fields = new Map(fieldsInput.map((field) => [field.fieldId, field]));
|
|
75
|
+
const answered = /* @__PURE__ */ new Set();
|
|
76
|
+
answers.forEach((answer, answerIndex) => {
|
|
77
|
+
if (answered.has(answer.fieldId)) {
|
|
78
|
+
issues.push(issue(
|
|
79
|
+
["answers", answerIndex, "fieldId"],
|
|
80
|
+
"Each request field may be answered once."
|
|
81
|
+
));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
answered.add(answer.fieldId);
|
|
85
|
+
const field = fields.get(answer.fieldId);
|
|
86
|
+
if (!field) {
|
|
87
|
+
issues.push(issue(
|
|
88
|
+
["answers", answerIndex, "fieldId"],
|
|
89
|
+
"Answer fieldId must reference a field declared by the request."
|
|
90
|
+
));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
issues.push(...answerIssues(field, answer, answerIndex));
|
|
94
|
+
});
|
|
95
|
+
for (const field of fieldsInput) {
|
|
96
|
+
if (field.required && !answered.has(field.fieldId)) {
|
|
97
|
+
issues.push(issue(
|
|
98
|
+
["answers"],
|
|
99
|
+
`Required request field ${field.fieldId} is missing an answer.`
|
|
100
|
+
));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return issues;
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
elicitationResponseIssues
|
|
107
|
+
};
|
package/dist/requests/parsers.js
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
AgentProtocolValidationError
|
|
3
3
|
} from "../foundation/index.js";
|
|
4
4
|
import { parseWithSchema, safeParseWithSchema } from "../internal/parsers.js";
|
|
5
|
+
import { elicitationResponseIssues } from "./elicitation.js";
|
|
5
6
|
import {
|
|
6
7
|
AgentApprovalRequestSchema,
|
|
7
8
|
AgentApprovalResolutionSchema,
|
|
@@ -35,77 +36,6 @@ function safeParseAgentApprovalResolution(input) {
|
|
|
35
36
|
function issue(path, message) {
|
|
36
37
|
return { code: "custom", path, message };
|
|
37
38
|
}
|
|
38
|
-
function fieldMap(request) {
|
|
39
|
-
return new Map(request.fields.map((field) => [field.fieldId, field]));
|
|
40
|
-
}
|
|
41
|
-
function singleSelectAnswerIssues(field, answer, answerIndex) {
|
|
42
|
-
const issues = [];
|
|
43
|
-
const allowedValues = new Set(field.options.map((option) => option.value));
|
|
44
|
-
if (answer.value !== void 0 && !allowedValues.has(answer.value)) {
|
|
45
|
-
issues.push(issue(
|
|
46
|
-
["answers", answerIndex, "value"],
|
|
47
|
-
"Single-select answers must reference an option declared by the request."
|
|
48
|
-
));
|
|
49
|
-
}
|
|
50
|
-
if (answer.other !== void 0 && !field.allowOther) {
|
|
51
|
-
issues.push(issue(
|
|
52
|
-
["answers", answerIndex, "other"],
|
|
53
|
-
"This request field does not accept a custom choice."
|
|
54
|
-
));
|
|
55
|
-
}
|
|
56
|
-
return issues;
|
|
57
|
-
}
|
|
58
|
-
function multiSelectAnswerIssues(field, answer, answerIndex) {
|
|
59
|
-
const issues = [];
|
|
60
|
-
const allowedValues = new Set(field.options.map((option) => option.value));
|
|
61
|
-
if (answer.values.some((value) => !allowedValues.has(value))) {
|
|
62
|
-
issues.push(issue(
|
|
63
|
-
["answers", answerIndex, "values"],
|
|
64
|
-
"Multi-select answers must reference options declared by the request."
|
|
65
|
-
));
|
|
66
|
-
}
|
|
67
|
-
if (answer.other !== void 0 && !field.allowOther) {
|
|
68
|
-
issues.push(issue(
|
|
69
|
-
["answers", answerIndex, "other"],
|
|
70
|
-
"This request field does not accept a custom choice."
|
|
71
|
-
));
|
|
72
|
-
}
|
|
73
|
-
const selectionCount = answer.values.length + (answer.other === void 0 ? 0 : 1);
|
|
74
|
-
if (field.required && selectionCount === 0) {
|
|
75
|
-
issues.push(issue(
|
|
76
|
-
["answers", answerIndex],
|
|
77
|
-
"A required multi-select answer needs a declared option or a custom choice."
|
|
78
|
-
));
|
|
79
|
-
}
|
|
80
|
-
if (selectionCount > field.maxSelections) {
|
|
81
|
-
issues.push(issue(
|
|
82
|
-
["answers", answerIndex],
|
|
83
|
-
"This request field exceeds its maximum selection count."
|
|
84
|
-
));
|
|
85
|
-
}
|
|
86
|
-
return issues;
|
|
87
|
-
}
|
|
88
|
-
function answerIssues(field, answer, answerIndex) {
|
|
89
|
-
if (field.kind !== answer.kind) {
|
|
90
|
-
return [issue(
|
|
91
|
-
["answers", answerIndex, "kind"],
|
|
92
|
-
"Answer kind must match the corresponding request field."
|
|
93
|
-
)];
|
|
94
|
-
}
|
|
95
|
-
if (field.kind === "text" && answer.kind === "text") {
|
|
96
|
-
return answer.value.length <= field.maxLength ? [] : [issue(
|
|
97
|
-
["answers", answerIndex, "value"],
|
|
98
|
-
"Text answer exceeds the field maximum length."
|
|
99
|
-
)];
|
|
100
|
-
}
|
|
101
|
-
if (field.kind === "single_select" && answer.kind === "single_select") {
|
|
102
|
-
return singleSelectAnswerIssues(field, answer, answerIndex);
|
|
103
|
-
}
|
|
104
|
-
if (field.kind === "multi_select" && answer.kind === "multi_select") {
|
|
105
|
-
return multiSelectAnswerIssues(field, answer, answerIndex);
|
|
106
|
-
}
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
39
|
function resolutionIssues(request, resolution) {
|
|
110
40
|
const issues = [];
|
|
111
41
|
if (request.requestKind !== resolution.requestKind) {
|
|
@@ -131,35 +61,7 @@ function resolutionIssues(request, resolution) {
|
|
|
131
61
|
if (request.requestKind !== "elicitation" || resolution.requestKind !== "elicitation" || resolution.disposition !== "answered") {
|
|
132
62
|
return issues;
|
|
133
63
|
}
|
|
134
|
-
|
|
135
|
-
const answered = /* @__PURE__ */ new Set();
|
|
136
|
-
resolution.answers.forEach((answer, answerIndex) => {
|
|
137
|
-
if (answered.has(answer.fieldId)) {
|
|
138
|
-
issues.push(issue(
|
|
139
|
-
["answers", answerIndex, "fieldId"],
|
|
140
|
-
"Each request field may be answered once."
|
|
141
|
-
));
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
answered.add(answer.fieldId);
|
|
145
|
-
const field = fields.get(answer.fieldId);
|
|
146
|
-
if (!field) {
|
|
147
|
-
issues.push(issue(
|
|
148
|
-
["answers", answerIndex, "fieldId"],
|
|
149
|
-
"Answer fieldId must reference a field declared by the request."
|
|
150
|
-
));
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
issues.push(...answerIssues(field, answer, answerIndex));
|
|
154
|
-
});
|
|
155
|
-
for (const field of request.fields) {
|
|
156
|
-
if (field.required && !answered.has(field.fieldId)) {
|
|
157
|
-
issues.push(issue(
|
|
158
|
-
["answers"],
|
|
159
|
-
`Required request field ${field.fieldId} is missing an answer.`
|
|
160
|
-
));
|
|
161
|
-
}
|
|
162
|
-
}
|
|
64
|
+
issues.push(...elicitationResponseIssues(request.fields, resolution.answers));
|
|
163
65
|
return issues;
|
|
164
66
|
}
|
|
165
67
|
function safeParseAgentRequestResolutionFor(requestInput, resolutionInput) {
|
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
import { type AgentProtocolParseResult } from '../foundation/index.js';
|
|
2
|
-
import type { AgentSessionDecisionChoiceId, AgentSessionDecisionRequest, AgentSessionDecisionResponse } from './types.js';
|
|
2
|
+
import type { AgentSessionDecisionChoiceId, AgentSessionFormChoiceId, AgentSessionPlanReviewChoiceId, AgentSessionPlanId, AgentSessionPlanRevision, AgentSessionDecisionRequest, AgentSessionFormRequest, AgentSessionPlanReviewRequest, AgentSessionRequest, AgentSessionDecisionResponse, AgentSessionFormResponse, AgentSessionPlanReviewResponse, AgentSessionResponse } from './types.js';
|
|
3
3
|
export declare function parseAgentSessionDecisionChoiceId(input: unknown): AgentSessionDecisionChoiceId;
|
|
4
4
|
export declare function safeParseAgentSessionDecisionChoiceId(input: unknown): AgentProtocolParseResult<AgentSessionDecisionChoiceId>;
|
|
5
|
+
export declare function parseAgentSessionFormChoiceId(input: unknown): AgentSessionFormChoiceId;
|
|
6
|
+
export declare function safeParseAgentSessionFormChoiceId(input: unknown): AgentProtocolParseResult<AgentSessionFormChoiceId>;
|
|
7
|
+
export declare function parseAgentSessionPlanReviewChoiceId(input: unknown): AgentSessionPlanReviewChoiceId;
|
|
8
|
+
export declare function safeParseAgentSessionPlanReviewChoiceId(input: unknown): AgentProtocolParseResult<AgentSessionPlanReviewChoiceId>;
|
|
9
|
+
export declare function parseAgentSessionPlanId(input: unknown): AgentSessionPlanId;
|
|
10
|
+
export declare function safeParseAgentSessionPlanId(input: unknown): AgentProtocolParseResult<AgentSessionPlanId>;
|
|
11
|
+
export declare function parseAgentSessionPlanRevision(input: unknown): AgentSessionPlanRevision;
|
|
12
|
+
export declare function safeParseAgentSessionPlanRevision(input: unknown): AgentProtocolParseResult<AgentSessionPlanRevision>;
|
|
5
13
|
export declare function parseAgentSessionDecisionRequest(input: unknown): AgentSessionDecisionRequest;
|
|
6
14
|
export declare function safeParseAgentSessionDecisionRequest(input: unknown): AgentProtocolParseResult<AgentSessionDecisionRequest>;
|
|
15
|
+
export declare function parseAgentSessionFormRequest(input: unknown): AgentSessionFormRequest;
|
|
16
|
+
export declare function safeParseAgentSessionFormRequest(input: unknown): AgentProtocolParseResult<AgentSessionFormRequest>;
|
|
17
|
+
export declare function parseAgentSessionPlanReviewRequest(input: unknown): AgentSessionPlanReviewRequest;
|
|
18
|
+
export declare function safeParseAgentSessionPlanReviewRequest(input: unknown): AgentProtocolParseResult<AgentSessionPlanReviewRequest>;
|
|
19
|
+
export declare function parseAgentSessionRequest(input: unknown): AgentSessionRequest;
|
|
20
|
+
export declare function safeParseAgentSessionRequest(input: unknown): AgentProtocolParseResult<AgentSessionRequest>;
|
|
7
21
|
export declare function parseAgentSessionDecisionResponse(input: unknown): AgentSessionDecisionResponse;
|
|
8
22
|
export declare function safeParseAgentSessionDecisionResponse(input: unknown): AgentProtocolParseResult<AgentSessionDecisionResponse>;
|
|
23
|
+
export declare function parseAgentSessionFormResponse(input: unknown): AgentSessionFormResponse;
|
|
24
|
+
export declare function safeParseAgentSessionFormResponse(input: unknown): AgentProtocolParseResult<AgentSessionFormResponse>;
|
|
25
|
+
export declare function parseAgentSessionPlanReviewResponse(input: unknown): AgentSessionPlanReviewResponse;
|
|
26
|
+
export declare function safeParseAgentSessionPlanReviewResponse(input: unknown): AgentProtocolParseResult<AgentSessionPlanReviewResponse>;
|
|
27
|
+
export declare function parseAgentSessionResponse(input: unknown): AgentSessionResponse;
|
|
28
|
+
export declare function safeParseAgentSessionResponse(input: unknown): AgentProtocolParseResult<AgentSessionResponse>;
|
|
29
|
+
export declare function safeParseAgentSessionDecisionResponseFor(requestInput: unknown, responseInput: unknown): AgentProtocolParseResult<AgentSessionDecisionResponse>;
|
|
9
30
|
export declare function parseAgentSessionDecisionResponseFor(request: AgentSessionDecisionRequest, input: unknown): AgentSessionDecisionResponse;
|
|
31
|
+
export declare function safeParseAgentSessionFormResponseFor(requestInput: unknown, responseInput: unknown): AgentProtocolParseResult<AgentSessionFormResponse>;
|
|
32
|
+
export declare function parseAgentSessionFormResponseFor(request: AgentSessionFormRequest, input: unknown): AgentSessionFormResponse;
|
|
33
|
+
export declare function safeParseAgentSessionPlanReviewResponseFor(requestInput: unknown, responseInput: unknown): AgentProtocolParseResult<AgentSessionPlanReviewResponse>;
|
|
34
|
+
export declare function parseAgentSessionPlanReviewResponseFor(request: AgentSessionPlanReviewRequest, input: unknown): AgentSessionPlanReviewResponse;
|
|
35
|
+
export declare function safeParseAgentSessionResponseFor(requestInput: unknown, responseInput: unknown): AgentProtocolParseResult<AgentSessionResponse>;
|
|
36
|
+
export declare function parseAgentSessionResponseFor(request: AgentSessionRequest, input: unknown): AgentSessionResponse;
|
|
10
37
|
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -2,10 +2,21 @@ import {
|
|
|
2
2
|
AgentProtocolValidationError
|
|
3
3
|
} from "../foundation/index.js";
|
|
4
4
|
import { parseWithSchema, safeParseWithSchema } from "../internal/parsers.js";
|
|
5
|
+
import { elicitationResponseIssues } from "../requests/elicitation.js";
|
|
5
6
|
import {
|
|
6
7
|
AgentSessionDecisionChoiceIdSchema,
|
|
8
|
+
AgentSessionFormChoiceIdSchema,
|
|
9
|
+
AgentSessionPlanReviewChoiceIdSchema,
|
|
10
|
+
AgentSessionPlanIdSchema,
|
|
11
|
+
AgentSessionPlanRevisionSchema,
|
|
7
12
|
AgentSessionDecisionRequestSchema,
|
|
8
|
-
|
|
13
|
+
AgentSessionFormRequestSchema,
|
|
14
|
+
AgentSessionPlanReviewRequestSchema,
|
|
15
|
+
AgentSessionRequestSchema,
|
|
16
|
+
AgentSessionDecisionResponseSchema,
|
|
17
|
+
AgentSessionFormResponseSchema,
|
|
18
|
+
AgentSessionPlanReviewResponseSchema,
|
|
19
|
+
AgentSessionResponseSchema
|
|
9
20
|
} from "../zod/sessionInteractions.js";
|
|
10
21
|
function parseAgentSessionDecisionChoiceId(input) {
|
|
11
22
|
return parseWithSchema(AgentSessionDecisionChoiceIdSchema, input);
|
|
@@ -13,36 +24,178 @@ function parseAgentSessionDecisionChoiceId(input) {
|
|
|
13
24
|
function safeParseAgentSessionDecisionChoiceId(input) {
|
|
14
25
|
return safeParseWithSchema(AgentSessionDecisionChoiceIdSchema, input);
|
|
15
26
|
}
|
|
27
|
+
function parseAgentSessionFormChoiceId(input) {
|
|
28
|
+
return parseWithSchema(AgentSessionFormChoiceIdSchema, input);
|
|
29
|
+
}
|
|
30
|
+
function safeParseAgentSessionFormChoiceId(input) {
|
|
31
|
+
return safeParseWithSchema(AgentSessionFormChoiceIdSchema, input);
|
|
32
|
+
}
|
|
33
|
+
function parseAgentSessionPlanReviewChoiceId(input) {
|
|
34
|
+
return parseWithSchema(AgentSessionPlanReviewChoiceIdSchema, input);
|
|
35
|
+
}
|
|
36
|
+
function safeParseAgentSessionPlanReviewChoiceId(input) {
|
|
37
|
+
return safeParseWithSchema(AgentSessionPlanReviewChoiceIdSchema, input);
|
|
38
|
+
}
|
|
39
|
+
function parseAgentSessionPlanId(input) {
|
|
40
|
+
return parseWithSchema(AgentSessionPlanIdSchema, input);
|
|
41
|
+
}
|
|
42
|
+
function safeParseAgentSessionPlanId(input) {
|
|
43
|
+
return safeParseWithSchema(AgentSessionPlanIdSchema, input);
|
|
44
|
+
}
|
|
45
|
+
function parseAgentSessionPlanRevision(input) {
|
|
46
|
+
return parseWithSchema(AgentSessionPlanRevisionSchema, input);
|
|
47
|
+
}
|
|
48
|
+
function safeParseAgentSessionPlanRevision(input) {
|
|
49
|
+
return safeParseWithSchema(AgentSessionPlanRevisionSchema, input);
|
|
50
|
+
}
|
|
16
51
|
function parseAgentSessionDecisionRequest(input) {
|
|
17
52
|
return parseWithSchema(AgentSessionDecisionRequestSchema, input);
|
|
18
53
|
}
|
|
19
54
|
function safeParseAgentSessionDecisionRequest(input) {
|
|
20
55
|
return safeParseWithSchema(AgentSessionDecisionRequestSchema, input);
|
|
21
56
|
}
|
|
57
|
+
function parseAgentSessionFormRequest(input) {
|
|
58
|
+
return parseWithSchema(AgentSessionFormRequestSchema, input);
|
|
59
|
+
}
|
|
60
|
+
function safeParseAgentSessionFormRequest(input) {
|
|
61
|
+
return safeParseWithSchema(AgentSessionFormRequestSchema, input);
|
|
62
|
+
}
|
|
63
|
+
function parseAgentSessionPlanReviewRequest(input) {
|
|
64
|
+
return parseWithSchema(AgentSessionPlanReviewRequestSchema, input);
|
|
65
|
+
}
|
|
66
|
+
function safeParseAgentSessionPlanReviewRequest(input) {
|
|
67
|
+
return safeParseWithSchema(AgentSessionPlanReviewRequestSchema, input);
|
|
68
|
+
}
|
|
69
|
+
function parseAgentSessionRequest(input) {
|
|
70
|
+
return parseWithSchema(AgentSessionRequestSchema, input);
|
|
71
|
+
}
|
|
72
|
+
function safeParseAgentSessionRequest(input) {
|
|
73
|
+
return safeParseWithSchema(AgentSessionRequestSchema, input);
|
|
74
|
+
}
|
|
22
75
|
function parseAgentSessionDecisionResponse(input) {
|
|
23
76
|
return parseWithSchema(AgentSessionDecisionResponseSchema, input);
|
|
24
77
|
}
|
|
25
78
|
function safeParseAgentSessionDecisionResponse(input) {
|
|
26
79
|
return safeParseWithSchema(AgentSessionDecisionResponseSchema, input);
|
|
27
80
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
81
|
+
function parseAgentSessionFormResponse(input) {
|
|
82
|
+
return parseWithSchema(AgentSessionFormResponseSchema, input);
|
|
83
|
+
}
|
|
84
|
+
function safeParseAgentSessionFormResponse(input) {
|
|
85
|
+
return safeParseWithSchema(AgentSessionFormResponseSchema, input);
|
|
86
|
+
}
|
|
87
|
+
function parseAgentSessionPlanReviewResponse(input) {
|
|
88
|
+
return parseWithSchema(AgentSessionPlanReviewResponseSchema, input);
|
|
89
|
+
}
|
|
90
|
+
function safeParseAgentSessionPlanReviewResponse(input) {
|
|
91
|
+
return safeParseWithSchema(AgentSessionPlanReviewResponseSchema, input);
|
|
92
|
+
}
|
|
93
|
+
function parseAgentSessionResponse(input) {
|
|
94
|
+
return parseWithSchema(AgentSessionResponseSchema, input);
|
|
95
|
+
}
|
|
96
|
+
function safeParseAgentSessionResponse(input) {
|
|
97
|
+
return safeParseWithSchema(AgentSessionResponseSchema, input);
|
|
98
|
+
}
|
|
99
|
+
function issue(path, message) {
|
|
100
|
+
return { code: "custom", path, message };
|
|
101
|
+
}
|
|
102
|
+
function sessionResponseIssues(request, response) {
|
|
103
|
+
if (request.kind !== response.kind) {
|
|
104
|
+
return [issue(["kind"], "Session response kind must match the offered request.")];
|
|
105
|
+
}
|
|
106
|
+
const issues = [];
|
|
107
|
+
const choice = request.choices.find((offered) => offered.choiceId === response.choiceId);
|
|
108
|
+
if (!choice) {
|
|
109
|
+
issues.push(issue(["choiceId"], "The response must select a choice offered by this session request."));
|
|
110
|
+
} else if ("action" in choice && "action" in response && choice.action !== response.action) {
|
|
111
|
+
issues.push(issue(["action"], "The response action must match the selected offered choice."));
|
|
37
112
|
}
|
|
38
|
-
|
|
113
|
+
if (request.kind === "form" && response.kind === "form" && response.action === "submit") {
|
|
114
|
+
issues.push(...elicitationResponseIssues(request.fields, response.answers));
|
|
115
|
+
}
|
|
116
|
+
if (request.kind === "plan_review" && response.kind === "plan_review") {
|
|
117
|
+
if (request.plan.planId !== response.planId) {
|
|
118
|
+
issues.push(issue(["planId"], "The response must identify the exact offered plan."));
|
|
119
|
+
}
|
|
120
|
+
if (request.plan.revision !== response.revision) {
|
|
121
|
+
issues.push(issue(["revision"], "The response must identify the exact offered plan revision."));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return issues;
|
|
125
|
+
}
|
|
126
|
+
function safeParseSessionResponseFor(requestSchema, responseSchema, requestInput, responseInput) {
|
|
127
|
+
const request = safeParseWithSchema(requestSchema, requestInput);
|
|
128
|
+
if (!request.success) return request;
|
|
129
|
+
const response = safeParseWithSchema(responseSchema, responseInput);
|
|
130
|
+
if (!response.success) return response;
|
|
131
|
+
const issues = sessionResponseIssues(request.data, response.data);
|
|
132
|
+
return issues.length === 0 ? response : { success: false, issues };
|
|
133
|
+
}
|
|
134
|
+
function safeParseAgentSessionDecisionResponseFor(requestInput, responseInput) {
|
|
135
|
+
return safeParseSessionResponseFor(AgentSessionDecisionRequestSchema, AgentSessionDecisionResponseSchema, requestInput, responseInput);
|
|
136
|
+
}
|
|
137
|
+
function parseAgentSessionDecisionResponseFor(request, input) {
|
|
138
|
+
const parsed = safeParseAgentSessionDecisionResponseFor(request, input);
|
|
139
|
+
if (parsed.success) return parsed.data;
|
|
140
|
+
throw new AgentProtocolValidationError(parsed.issues);
|
|
141
|
+
}
|
|
142
|
+
function safeParseAgentSessionFormResponseFor(requestInput, responseInput) {
|
|
143
|
+
return safeParseSessionResponseFor(AgentSessionFormRequestSchema, AgentSessionFormResponseSchema, requestInput, responseInput);
|
|
144
|
+
}
|
|
145
|
+
function parseAgentSessionFormResponseFor(request, input) {
|
|
146
|
+
const parsed = safeParseAgentSessionFormResponseFor(request, input);
|
|
147
|
+
if (parsed.success) return parsed.data;
|
|
148
|
+
throw new AgentProtocolValidationError(parsed.issues);
|
|
149
|
+
}
|
|
150
|
+
function safeParseAgentSessionPlanReviewResponseFor(requestInput, responseInput) {
|
|
151
|
+
return safeParseSessionResponseFor(AgentSessionPlanReviewRequestSchema, AgentSessionPlanReviewResponseSchema, requestInput, responseInput);
|
|
152
|
+
}
|
|
153
|
+
function parseAgentSessionPlanReviewResponseFor(request, input) {
|
|
154
|
+
const parsed = safeParseAgentSessionPlanReviewResponseFor(request, input);
|
|
155
|
+
if (parsed.success) return parsed.data;
|
|
156
|
+
throw new AgentProtocolValidationError(parsed.issues);
|
|
157
|
+
}
|
|
158
|
+
function safeParseAgentSessionResponseFor(requestInput, responseInput) {
|
|
159
|
+
return safeParseSessionResponseFor(AgentSessionRequestSchema, AgentSessionResponseSchema, requestInput, responseInput);
|
|
160
|
+
}
|
|
161
|
+
function parseAgentSessionResponseFor(request, input) {
|
|
162
|
+
const parsed = safeParseAgentSessionResponseFor(request, input);
|
|
163
|
+
if (parsed.success) return parsed.data;
|
|
164
|
+
throw new AgentProtocolValidationError(parsed.issues);
|
|
39
165
|
}
|
|
40
166
|
export {
|
|
41
167
|
parseAgentSessionDecisionChoiceId,
|
|
42
168
|
parseAgentSessionDecisionRequest,
|
|
43
169
|
parseAgentSessionDecisionResponse,
|
|
44
170
|
parseAgentSessionDecisionResponseFor,
|
|
171
|
+
parseAgentSessionFormChoiceId,
|
|
172
|
+
parseAgentSessionFormRequest,
|
|
173
|
+
parseAgentSessionFormResponse,
|
|
174
|
+
parseAgentSessionFormResponseFor,
|
|
175
|
+
parseAgentSessionPlanId,
|
|
176
|
+
parseAgentSessionPlanReviewChoiceId,
|
|
177
|
+
parseAgentSessionPlanReviewRequest,
|
|
178
|
+
parseAgentSessionPlanReviewResponse,
|
|
179
|
+
parseAgentSessionPlanReviewResponseFor,
|
|
180
|
+
parseAgentSessionPlanRevision,
|
|
181
|
+
parseAgentSessionRequest,
|
|
182
|
+
parseAgentSessionResponse,
|
|
183
|
+
parseAgentSessionResponseFor,
|
|
45
184
|
safeParseAgentSessionDecisionChoiceId,
|
|
46
185
|
safeParseAgentSessionDecisionRequest,
|
|
47
|
-
safeParseAgentSessionDecisionResponse
|
|
186
|
+
safeParseAgentSessionDecisionResponse,
|
|
187
|
+
safeParseAgentSessionDecisionResponseFor,
|
|
188
|
+
safeParseAgentSessionFormChoiceId,
|
|
189
|
+
safeParseAgentSessionFormRequest,
|
|
190
|
+
safeParseAgentSessionFormResponse,
|
|
191
|
+
safeParseAgentSessionFormResponseFor,
|
|
192
|
+
safeParseAgentSessionPlanId,
|
|
193
|
+
safeParseAgentSessionPlanReviewChoiceId,
|
|
194
|
+
safeParseAgentSessionPlanReviewRequest,
|
|
195
|
+
safeParseAgentSessionPlanReviewResponse,
|
|
196
|
+
safeParseAgentSessionPlanReviewResponseFor,
|
|
197
|
+
safeParseAgentSessionPlanRevision,
|
|
198
|
+
safeParseAgentSessionRequest,
|
|
199
|
+
safeParseAgentSessionResponse,
|
|
200
|
+
safeParseAgentSessionResponseFor
|
|
48
201
|
};
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import type { AgentIsoDateTime, AgentRequestId, AgentSessionId } from '../foundation/index.js';
|
|
2
|
+
import type { AgentElicitationAnswer, AgentElicitationField } from '../requests/types.js';
|
|
2
3
|
declare const agentSessionDecisionChoiceIdBrand: unique symbol;
|
|
4
|
+
declare const agentSessionFormChoiceIdBrand: unique symbol;
|
|
5
|
+
declare const agentSessionPlanReviewChoiceIdBrand: unique symbol;
|
|
6
|
+
declare const agentSessionPlanIdBrand: unique symbol;
|
|
7
|
+
declare const agentSessionPlanRevisionBrand: unique symbol;
|
|
8
|
+
export type AgentSessionRequestKind = 'decision' | 'form' | 'plan_review';
|
|
3
9
|
export type AgentSessionDecisionChoiceId = string & {
|
|
4
10
|
readonly [agentSessionDecisionChoiceIdBrand]: 'AgentSessionDecisionChoiceId';
|
|
5
11
|
};
|
|
12
|
+
export type AgentSessionFormChoiceId = string & {
|
|
13
|
+
readonly [agentSessionFormChoiceIdBrand]: 'AgentSessionFormChoiceId';
|
|
14
|
+
};
|
|
15
|
+
export type AgentSessionPlanReviewChoiceId = string & {
|
|
16
|
+
readonly [agentSessionPlanReviewChoiceIdBrand]: 'AgentSessionPlanReviewChoiceId';
|
|
17
|
+
};
|
|
18
|
+
export type AgentSessionPlanId = string & {
|
|
19
|
+
readonly [agentSessionPlanIdBrand]: 'AgentSessionPlanId';
|
|
20
|
+
};
|
|
21
|
+
export type AgentSessionPlanRevision = string & {
|
|
22
|
+
readonly [agentSessionPlanRevisionBrand]: 'AgentSessionPlanRevision';
|
|
23
|
+
};
|
|
6
24
|
export interface AgentSessionWorkspaceTarget {
|
|
7
25
|
readonly kind: 'workspace';
|
|
8
26
|
readonly path: string;
|
|
@@ -32,14 +50,108 @@ export interface AgentSessionDecisionRequest {
|
|
|
32
50
|
readonly title: string;
|
|
33
51
|
readonly description?: string;
|
|
34
52
|
readonly target: AgentSessionWorkspaceTarget;
|
|
35
|
-
readonly expiresAt
|
|
53
|
+
readonly expiresAt?: AgentIsoDateTime;
|
|
36
54
|
readonly choices: readonly [AgentSessionDecisionChoice, ...AgentSessionDecisionChoice[]];
|
|
37
55
|
}
|
|
38
56
|
export interface AgentSessionDecisionResponse {
|
|
57
|
+
readonly kind: 'decision';
|
|
39
58
|
readonly choiceId: AgentSessionDecisionChoiceId;
|
|
40
59
|
}
|
|
60
|
+
export type AgentSessionFormChoice = Readonly<{
|
|
61
|
+
choiceId: AgentSessionFormChoiceId;
|
|
62
|
+
action: 'submit';
|
|
63
|
+
label: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
}> | Readonly<{
|
|
66
|
+
choiceId: AgentSessionFormChoiceId;
|
|
67
|
+
action: 'cancel';
|
|
68
|
+
label: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
}>;
|
|
71
|
+
export interface AgentSessionFormRequest {
|
|
72
|
+
readonly kind: 'form';
|
|
73
|
+
readonly requestId: AgentRequestId;
|
|
74
|
+
readonly sessionId: AgentSessionId;
|
|
75
|
+
readonly title: string;
|
|
76
|
+
readonly description?: string;
|
|
77
|
+
readonly fields: readonly [AgentElicitationField, ...AgentElicitationField[]];
|
|
78
|
+
readonly choices: readonly [AgentSessionFormChoice, ...AgentSessionFormChoice[]];
|
|
79
|
+
readonly expiresAt?: AgentIsoDateTime;
|
|
80
|
+
}
|
|
81
|
+
export type AgentSessionPlanReviewAction = 'approve' | 'revise' | 'abandon';
|
|
82
|
+
export interface AgentSessionPlanSnapshot {
|
|
83
|
+
readonly planId: AgentSessionPlanId;
|
|
84
|
+
readonly revision: AgentSessionPlanRevision;
|
|
85
|
+
readonly title: string;
|
|
86
|
+
readonly content: Readonly<{
|
|
87
|
+
kind: 'text';
|
|
88
|
+
format: 'plain_text' | 'markdown';
|
|
89
|
+
text: string;
|
|
90
|
+
}>;
|
|
91
|
+
}
|
|
92
|
+
export interface AgentSessionPlanReviewChoice {
|
|
93
|
+
readonly choiceId: AgentSessionPlanReviewChoiceId;
|
|
94
|
+
readonly action: AgentSessionPlanReviewAction;
|
|
95
|
+
readonly label: string;
|
|
96
|
+
readonly description?: string;
|
|
97
|
+
}
|
|
98
|
+
export interface AgentSessionPlanReviewRequest {
|
|
99
|
+
readonly kind: 'plan_review';
|
|
100
|
+
readonly requestId: AgentRequestId;
|
|
101
|
+
readonly sessionId: AgentSessionId;
|
|
102
|
+
readonly title: string;
|
|
103
|
+
readonly description?: string;
|
|
104
|
+
readonly plan: AgentSessionPlanSnapshot;
|
|
105
|
+
readonly choices: readonly [AgentSessionPlanReviewChoice, ...AgentSessionPlanReviewChoice[]];
|
|
106
|
+
readonly expiresAt?: AgentIsoDateTime;
|
|
107
|
+
}
|
|
108
|
+
export type AgentSessionRequest = AgentSessionDecisionRequest | AgentSessionFormRequest | AgentSessionPlanReviewRequest;
|
|
109
|
+
export type AgentSessionFormResponse = Readonly<{
|
|
110
|
+
kind: 'form';
|
|
111
|
+
action: 'submit';
|
|
112
|
+
choiceId: AgentSessionFormChoiceId;
|
|
113
|
+
answers: readonly AgentElicitationAnswer[];
|
|
114
|
+
}> | Readonly<{
|
|
115
|
+
kind: 'form';
|
|
116
|
+
action: 'cancel';
|
|
117
|
+
choiceId: AgentSessionFormChoiceId;
|
|
118
|
+
}>;
|
|
119
|
+
export type AgentSessionPlanReviewResponse = Readonly<{
|
|
120
|
+
kind: 'plan_review';
|
|
121
|
+
action: 'approve' | 'abandon';
|
|
122
|
+
choiceId: AgentSessionPlanReviewChoiceId;
|
|
123
|
+
planId: AgentSessionPlanId;
|
|
124
|
+
revision: AgentSessionPlanRevision;
|
|
125
|
+
}> | Readonly<{
|
|
126
|
+
kind: 'plan_review';
|
|
127
|
+
action: 'revise';
|
|
128
|
+
choiceId: AgentSessionPlanReviewChoiceId;
|
|
129
|
+
planId: AgentSessionPlanId;
|
|
130
|
+
revision: AgentSessionPlanRevision;
|
|
131
|
+
feedback: string;
|
|
132
|
+
}>;
|
|
133
|
+
export type AgentSessionResponse = AgentSessionDecisionResponse | AgentSessionFormResponse | AgentSessionPlanReviewResponse;
|
|
134
|
+
export type AgentSessionAcceptedResponse = AgentSessionDecisionResponse | Readonly<{
|
|
135
|
+
kind: 'form';
|
|
136
|
+
action: 'submit' | 'cancel';
|
|
137
|
+
choiceId: AgentSessionFormChoiceId;
|
|
138
|
+
}> | Readonly<{
|
|
139
|
+
kind: 'plan_review';
|
|
140
|
+
action: AgentSessionPlanReviewAction;
|
|
141
|
+
choiceId: AgentSessionPlanReviewChoiceId;
|
|
142
|
+
planId: AgentSessionPlanId;
|
|
143
|
+
revision: AgentSessionPlanRevision;
|
|
144
|
+
}>;
|
|
145
|
+
export declare const AGENT_SESSION_REQUEST_BYTES_LIMIT = 65536;
|
|
41
146
|
export declare const AGENT_SESSION_DECISION_REQUEST_BYTES_LIMIT = 65536;
|
|
42
147
|
export declare const AGENT_SESSION_DECISION_RESPONSE_BYTES_LIMIT = 1024;
|
|
148
|
+
export declare const AGENT_SESSION_FORM_RESPONSE_BYTES_LIMIT = 65536;
|
|
149
|
+
export declare const AGENT_SESSION_PLAN_REVIEW_RESPONSE_BYTES_LIMIT = 65536;
|
|
150
|
+
export declare const AGENT_SESSION_PLAN_TEXT_BYTES_LIMIT = 49152;
|
|
151
|
+
export declare const AGENT_SESSION_PLAN_ID_BYTES_LIMIT = 128;
|
|
152
|
+
export declare const AGENT_SESSION_PLAN_REVISION_BYTES_LIMIT = 128;
|
|
153
|
+
export declare const AGENT_SESSION_PLAN_REVIEW_FEEDBACK_MAX_LENGTH = 4000;
|
|
154
|
+
export declare const AGENT_SESSION_PLAN_REVIEW_FEEDBACK_BYTES_LIMIT = 16384;
|
|
43
155
|
export declare const AGENT_SESSION_DECISION_CHOICES_MAX_LENGTH = 16;
|
|
44
156
|
export declare const AGENT_SESSION_DECISION_CHOICE_ID_BYTES_LIMIT = 128;
|
|
45
157
|
export declare const AGENT_SESSION_DECISION_TITLE_MAX_LENGTH = 120;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const AGENT_SESSION_REQUEST_BYTES_LIMIT = 65536;
|
|
2
|
+
const AGENT_SESSION_DECISION_REQUEST_BYTES_LIMIT = AGENT_SESSION_REQUEST_BYTES_LIMIT;
|
|
2
3
|
const AGENT_SESSION_DECISION_RESPONSE_BYTES_LIMIT = 1024;
|
|
4
|
+
const AGENT_SESSION_FORM_RESPONSE_BYTES_LIMIT = 65536;
|
|
5
|
+
const AGENT_SESSION_PLAN_REVIEW_RESPONSE_BYTES_LIMIT = 65536;
|
|
6
|
+
const AGENT_SESSION_PLAN_TEXT_BYTES_LIMIT = 49152;
|
|
7
|
+
const AGENT_SESSION_PLAN_ID_BYTES_LIMIT = 128;
|
|
8
|
+
const AGENT_SESSION_PLAN_REVISION_BYTES_LIMIT = 128;
|
|
9
|
+
const AGENT_SESSION_PLAN_REVIEW_FEEDBACK_MAX_LENGTH = 4e3;
|
|
10
|
+
const AGENT_SESSION_PLAN_REVIEW_FEEDBACK_BYTES_LIMIT = 16384;
|
|
3
11
|
const AGENT_SESSION_DECISION_CHOICES_MAX_LENGTH = 16;
|
|
4
12
|
const AGENT_SESSION_DECISION_CHOICE_ID_BYTES_LIMIT = 128;
|
|
5
13
|
const AGENT_SESSION_DECISION_TITLE_MAX_LENGTH = 120;
|
|
@@ -14,5 +22,13 @@ export {
|
|
|
14
22
|
AGENT_SESSION_DECISION_REQUEST_BYTES_LIMIT,
|
|
15
23
|
AGENT_SESSION_DECISION_RESPONSE_BYTES_LIMIT,
|
|
16
24
|
AGENT_SESSION_DECISION_TITLE_MAX_LENGTH,
|
|
17
|
-
AGENT_SESSION_DECISION_WORKSPACE_PATH_BYTES_LIMIT
|
|
25
|
+
AGENT_SESSION_DECISION_WORKSPACE_PATH_BYTES_LIMIT,
|
|
26
|
+
AGENT_SESSION_FORM_RESPONSE_BYTES_LIMIT,
|
|
27
|
+
AGENT_SESSION_PLAN_ID_BYTES_LIMIT,
|
|
28
|
+
AGENT_SESSION_PLAN_REVIEW_FEEDBACK_BYTES_LIMIT,
|
|
29
|
+
AGENT_SESSION_PLAN_REVIEW_FEEDBACK_MAX_LENGTH,
|
|
30
|
+
AGENT_SESSION_PLAN_REVIEW_RESPONSE_BYTES_LIMIT,
|
|
31
|
+
AGENT_SESSION_PLAN_REVISION_BYTES_LIMIT,
|
|
32
|
+
AGENT_SESSION_PLAN_TEXT_BYTES_LIMIT,
|
|
33
|
+
AGENT_SESSION_REQUEST_BYTES_LIMIT
|
|
18
34
|
};
|