@agen-ai/agent-protocol 0.4.0 → 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 +115 -18
- package/dist/capabilities/types.d.ts +6 -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 +11214 -7152
- package/dist/jsonSchema/generated.js +2835 -227
- package/dist/public/index.d.ts +1 -0
- package/dist/public/index.js +1 -0
- package/dist/public/sessionInteractions.d.ts +2 -0
- package/dist/public/sessionInteractions.js +1 -0
- package/dist/requests/elicitation.d.ts +4 -0
- package/dist/requests/elicitation.js +107 -0
- package/dist/requests/parsers.js +2 -100
- package/dist/requests/types.d.ts +17 -4
- package/dist/sessionInteractions/index.d.ts +3 -0
- package/dist/sessionInteractions/index.js +2 -0
- package/dist/sessionInteractions/parsers.d.ts +37 -0
- package/dist/sessionInteractions/parsers.js +201 -0
- package/dist/sessionInteractions/types.d.ts +162 -0
- package/dist/sessionInteractions/types.js +34 -0
- package/dist/zod/capabilities.d.ts +72 -6
- package/dist/zod/capabilities.js +32 -30
- package/dist/zod/collaboration.d.ts +2 -2
- package/dist/zod/events.d.ts +75 -42
- package/dist/zod/events.js +8 -0
- package/dist/zod/foundation.d.ts +1 -0
- package/dist/zod/foundation.js +15 -2
- package/dist/zod/index.d.ts +2 -1
- package/dist/zod/index.js +60 -0
- package/dist/zod/operations.d.ts +1 -1
- package/dist/zod/requests.d.ts +175 -32
- package/dist/zod/requests.js +33 -10
- package/dist/zod/sessionInteractions.d.ts +925 -0
- package/dist/zod/sessionInteractions.js +284 -0
- package/dist/zod/turns.d.ts +1 -1
- package/dist/zod/typeEquality.generated.d.ts +38 -4
- package/package.json +6 -2
package/dist/public/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from '../foundation/index.js';
|
|
|
2
2
|
export * from '../failures/index.js';
|
|
3
3
|
export * from '../accountQuota/index.js';
|
|
4
4
|
export * from '../sessions/index.js';
|
|
5
|
+
export * from '../sessionInteractions/index.js';
|
|
5
6
|
export * from '../turns/index.js';
|
|
6
7
|
export * from '../requests/index.js';
|
|
7
8
|
export * from '../operations/index.js';
|
package/dist/public/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "../foundation/index.js";
|
|
|
2
2
|
export * from "../failures/index.js";
|
|
3
3
|
export * from "../accountQuota/index.js";
|
|
4
4
|
export * from "../sessions/index.js";
|
|
5
|
+
export * from "../sessionInteractions/index.js";
|
|
5
6
|
export * from "../turns/index.js";
|
|
6
7
|
export * from "../requests/index.js";
|
|
7
8
|
export * from "../operations/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../sessionInteractions/index.js";
|
|
@@ -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) {
|
package/dist/requests/types.d.ts
CHANGED
|
@@ -22,15 +22,28 @@ export type AgentApprovalSubject = (AgentApprovalSubjectBase & Readonly<{
|
|
|
22
22
|
kind: 'command' | 'file_change' | 'tool' | 'other';
|
|
23
23
|
itemId: AgentItemId;
|
|
24
24
|
}>);
|
|
25
|
+
export type AgentApprovalConsequence = Readonly<{
|
|
26
|
+
kind: 'scoped';
|
|
27
|
+
persistence: AgentApprovalPersistence;
|
|
28
|
+
scope: Readonly<{
|
|
29
|
+
kind: AgentApprovalScopeKind;
|
|
30
|
+
}>;
|
|
31
|
+
}> | Readonly<{
|
|
32
|
+
kind: 'provider_managed_remembrance';
|
|
33
|
+
duration: Readonly<{
|
|
34
|
+
kind: 'unknown';
|
|
35
|
+
}>;
|
|
36
|
+
applicability: Readonly<{
|
|
37
|
+
kind: 'unknown';
|
|
38
|
+
}>;
|
|
39
|
+
explanation: string;
|
|
40
|
+
}>;
|
|
25
41
|
export interface AgentApprovalOption {
|
|
26
42
|
readonly optionId: AgentApprovalOptionId;
|
|
27
43
|
readonly label: string;
|
|
28
44
|
readonly description?: string;
|
|
29
45
|
readonly decision: 'approved' | 'denied';
|
|
30
|
-
readonly
|
|
31
|
-
readonly scope: Readonly<{
|
|
32
|
-
kind: AgentApprovalScopeKind;
|
|
33
|
-
}>;
|
|
46
|
+
readonly consequence: AgentApprovalConsequence;
|
|
34
47
|
}
|
|
35
48
|
export interface AgentApprovalRequest {
|
|
36
49
|
readonly requestKind: 'approval';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type AgentProtocolParseResult } from '../foundation/index.js';
|
|
2
|
+
import type { AgentSessionDecisionChoiceId, AgentSessionFormChoiceId, AgentSessionPlanReviewChoiceId, AgentSessionPlanId, AgentSessionPlanRevision, AgentSessionDecisionRequest, AgentSessionFormRequest, AgentSessionPlanReviewRequest, AgentSessionRequest, AgentSessionDecisionResponse, AgentSessionFormResponse, AgentSessionPlanReviewResponse, AgentSessionResponse } from './types.js';
|
|
3
|
+
export declare function parseAgentSessionDecisionChoiceId(input: unknown): AgentSessionDecisionChoiceId;
|
|
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>;
|
|
13
|
+
export declare function parseAgentSessionDecisionRequest(input: unknown): AgentSessionDecisionRequest;
|
|
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>;
|
|
21
|
+
export declare function parseAgentSessionDecisionResponse(input: unknown): AgentSessionDecisionResponse;
|
|
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>;
|
|
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;
|
|
37
|
+
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentProtocolValidationError
|
|
3
|
+
} from "../foundation/index.js";
|
|
4
|
+
import { parseWithSchema, safeParseWithSchema } from "../internal/parsers.js";
|
|
5
|
+
import { elicitationResponseIssues } from "../requests/elicitation.js";
|
|
6
|
+
import {
|
|
7
|
+
AgentSessionDecisionChoiceIdSchema,
|
|
8
|
+
AgentSessionFormChoiceIdSchema,
|
|
9
|
+
AgentSessionPlanReviewChoiceIdSchema,
|
|
10
|
+
AgentSessionPlanIdSchema,
|
|
11
|
+
AgentSessionPlanRevisionSchema,
|
|
12
|
+
AgentSessionDecisionRequestSchema,
|
|
13
|
+
AgentSessionFormRequestSchema,
|
|
14
|
+
AgentSessionPlanReviewRequestSchema,
|
|
15
|
+
AgentSessionRequestSchema,
|
|
16
|
+
AgentSessionDecisionResponseSchema,
|
|
17
|
+
AgentSessionFormResponseSchema,
|
|
18
|
+
AgentSessionPlanReviewResponseSchema,
|
|
19
|
+
AgentSessionResponseSchema
|
|
20
|
+
} from "../zod/sessionInteractions.js";
|
|
21
|
+
function parseAgentSessionDecisionChoiceId(input) {
|
|
22
|
+
return parseWithSchema(AgentSessionDecisionChoiceIdSchema, input);
|
|
23
|
+
}
|
|
24
|
+
function safeParseAgentSessionDecisionChoiceId(input) {
|
|
25
|
+
return safeParseWithSchema(AgentSessionDecisionChoiceIdSchema, input);
|
|
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
|
+
}
|
|
51
|
+
function parseAgentSessionDecisionRequest(input) {
|
|
52
|
+
return parseWithSchema(AgentSessionDecisionRequestSchema, input);
|
|
53
|
+
}
|
|
54
|
+
function safeParseAgentSessionDecisionRequest(input) {
|
|
55
|
+
return safeParseWithSchema(AgentSessionDecisionRequestSchema, input);
|
|
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
|
+
}
|
|
75
|
+
function parseAgentSessionDecisionResponse(input) {
|
|
76
|
+
return parseWithSchema(AgentSessionDecisionResponseSchema, input);
|
|
77
|
+
}
|
|
78
|
+
function safeParseAgentSessionDecisionResponse(input) {
|
|
79
|
+
return safeParseWithSchema(AgentSessionDecisionResponseSchema, input);
|
|
80
|
+
}
|
|
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."));
|
|
112
|
+
}
|
|
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);
|
|
165
|
+
}
|
|
166
|
+
export {
|
|
167
|
+
parseAgentSessionDecisionChoiceId,
|
|
168
|
+
parseAgentSessionDecisionRequest,
|
|
169
|
+
parseAgentSessionDecisionResponse,
|
|
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,
|
|
184
|
+
safeParseAgentSessionDecisionChoiceId,
|
|
185
|
+
safeParseAgentSessionDecisionRequest,
|
|
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
|
|
201
|
+
};
|