Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3import { ThreadId, TrimmedNonEmptyString, TurnItemId } from "./baseSchemas.ts";
4
5/** Server stores the value under a one-use SecretRef; the thread learns only status. */
6export const SecretRequestAnswerInput = Schema.Struct({
7 threadId: ThreadId,
8 turnItemId: TurnItemId,
9 answer: Schema.Union([
10 Schema.Struct({ type: Schema.Literal("save"), secret: TrimmedNonEmptyString }),
11 Schema.Struct({ type: Schema.Literal("decline") }),
12 ]),
13});
14export type SecretRequestAnswerInput = typeof SecretRequestAnswerInput.Type;
15
16/** What the agent reads when its card ends without a secret. */
17export const SECRET_REQUEST_UNSAVED_NOTE = {
18 declined:
19 "The user declined. Don't ask for it in chat or another way; say what's blocked and go on without it.",
20 cancelled:
21 "The card closed with the run. Ask again with a new clientRequestId only if the secret is still needed.",
22 timed_out:
23 "No answer in time. Don't ask in chat; ask again with a new clientRequestId only if it is still needed.",
24} as const;
25
26const SECRET_REQUEST_FAILURE_MESSAGES = {
27 load_failed: "Could not load the secret request.",
28 not_found: "This secret request no longer exists.",
29 already_answered: "This secret request was already answered.",
30 agent_stopped: "The agent that asked has stopped, so this secret can't be used.",
31 store_failed: "Could not store the secret.",
32 record_failed: "Saved the secret, but could not update the request.",
33 invalid_ref: "That secretRef is not valid.",
34 read_failed: "Could not read the secret.",
35 ref_unavailable:
36 "That secretRef was already used or does not exist. Ask the user again with request_secret.",
37 ref_expired: "That secretRef expired. Ask the user again with request_secret.",
38 consume_failed: "Could not use that secretRef. Try again.",
39 not_a_file_request:
40 'The user did not save this secret for shell use. Ask again with request_secret and delivery: "file".',
41} as const;
42
43export const SecretRequestFailureReason = Schema.Literals(
44 Object.keys(SECRET_REQUEST_FAILURE_MESSAGES) as Array<
45 keyof typeof SECRET_REQUEST_FAILURE_MESSAGES
46 >,
47);
48export type SecretRequestFailureReason = typeof SecretRequestFailureReason.Type;
49
50export class SecretRequestError extends Schema.TaggedError<SecretRequestError>()(
51 "SecretRequestError",
52 {
53 reason: SecretRequestFailureReason,
54 cause: Schema.optionalKey(Schema.Defect()),
55 },
56) {
57 override get message(): string {
58 return SECRET_REQUEST_FAILURE_MESSAGES[this.reason];
59 }
60}