Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

agentFeedback.ts

84 lines2.8 KB

1import * as Schema from "effect/Schema";
2​
3import { ThreadId, TurnItemId } from "./baseSchemas.ts";
4​
5export const AgentFeedbackKind = Schema.Literals([
6 "bug",
7 "confusing",
8 "missing_capability",
9 "wrong_docs",
10 "other",
11]);
12​
13/** Built by the server from the thread's stored items; the agent never writes it. */
14export const AgentFeedbackTrace = Schema.Struct({
15 turns: Schema.Int,
16 textTurns: Schema.Int,
17 /** A cap dropped an entry or cut or dropped a message text. */
18 truncated: Schema.Boolean,
19 entries: Schema.Array(
20 Schema.Struct({
21 turn: Schema.Int,
22 type: Schema.Literals(["user", "assistant", "tool"]),
23 tool: Schema.optionalKey(Schema.String),
24 outcome: Schema.optionalKey(Schema.Literals(["ok", "error", "unfinished"])),
25 durationMs: Schema.optionalKey(Schema.Int),
26 /** A message's length in characters. */
27 length: Schema.optionalKey(Schema.Int),
28 text: Schema.optionalKey(Schema.String),
29 }),
30 ),
31});
32export type AgentFeedbackTrace = typeof AgentFeedbackTrace.Type;
33​
34/** Exactly what a requested report sends once the user approves it, already scrubbed. */
35export const AgentFeedbackPreview = Schema.Struct({
36 kind: AgentFeedbackKind,
37 subject: Schema.String,
38 expected: Schema.String,
39 actual: Schema.String,
40 workaround: Schema.String,
41 trace: Schema.NullOr(AgentFeedbackTrace),
42});
43export type AgentFeedbackPreview = typeof AgentFeedbackPreview.Type;
44​
45export const AgentFeedbackRequestStatus = Schema.Literals([
46 "pending",
47 "sent",
48 "declined",
49 "cancelled",
50]);
51export type AgentFeedbackRequestStatus = typeof AgentFeedbackRequestStatus.Type;
52​
53export const AgentFeedbackAnswerInput = Schema.Struct({
54 threadId: ThreadId,
55 turnItemId: TurnItemId,
56 answer: Schema.Literals(["send", "decline"]),
57 /** Send the card's conversation trace instead of its outline. */
58 includeConversation: Schema.optionalKey(Schema.Boolean),
59});
60export type AgentFeedbackAnswerInput = typeof AgentFeedbackAnswerInput.Type;
61​
62const AGENT_FEEDBACK_REQUEST_FAILURE_MESSAGES = {
63 load_failed: "Could not load the feedback report.",
64 not_found: "This feedback report no longer exists.",
65 already_answered: "This feedback report was already answered.",
66 feedback_off: "Agent feedback is off, so this report was not sent.",
67 record_failed: "Could not record your answer.",
68} as const;
69​
70export class AgentFeedbackRequestError extends Schema.TaggedError<AgentFeedbackRequestError>()(
71 "AgentFeedbackRequestError",
72 {
73 reason: Schema.Literals(
74 Object.keys(AGENT_FEEDBACK_REQUEST_FAILURE_MESSAGES) as Array<
75 keyof typeof AGENT_FEEDBACK_REQUEST_FAILURE_MESSAGES
76 >,
77 ),
78 cause: Schema.optionalKey(Schema.Defect()),
79 },
80) {
81 override get message(): string {
82 return AGENT_FEEDBACK_REQUEST_FAILURE_MESSAGES[this.reason];
83 }