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

secretRequest.ts

50 lines2.0 KB

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​
16const SECRET_REQUEST_FAILURE_MESSAGES = {
17 load_failed: "Could not load the secret request.",
18 not_found: "This secret request no longer exists.",
19 already_answered: "This secret request was already answered.",
20 agent_stopped: "The agent that asked has stopped, so this secret can't be used.",
21 store_failed: "Could not store the secret.",
22 record_failed: "Saved the secret, but could not update the request.",
23 invalid_ref: "That secretRef is not valid.",
24 read_failed: "Could not read the secret.",
25 ref_unavailable:
26 "That secretRef was already used or does not exist. Ask the user again with request_secret.",
27 ref_expired: "That secretRef expired. Ask the user again with request_secret.",
28 consume_failed: "Could not use that secretRef. Try again.",
29 not_a_file_request:
30 'The user did not save this secret for shell use. Ask again with request_secret and delivery: "file".',
31} as const;
32​
33export const SecretRequestFailureReason = Schema.Literals(
34 Object.keys(SECRET_REQUEST_FAILURE_MESSAGES) as Array<
35 keyof typeof SECRET_REQUEST_FAILURE_MESSAGES
36 >,
37);
38export type SecretRequestFailureReason = typeof SecretRequestFailureReason.Type;
39​
40export class SecretRequestError extends Schema.TaggedError<SecretRequestError>()(
41 "SecretRequestError",
42 {
43 reason: SecretRequestFailureReason,
44 cause: Schema.optionalKey(Schema.Defect()),
45 },
46) {
47 override get message(): string {
48 return SECRET_REQUEST_FAILURE_MESSAGES[this.reason];
49 }