chesly 0.0.1 → 0.3.0
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/LICENSE +21 -0
- package/README.md +465 -3
- package/dist/errors.js +173 -0
- package/dist/index.js +2968 -0
- package/package.json +43 -6
- package/cli.js +0 -2
package/dist/errors.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var EXIT = {
|
|
3
|
+
OK: 0,
|
|
4
|
+
ERROR: 1,
|
|
5
|
+
USAGE: 2,
|
|
6
|
+
NOT_SIGNED_IN: 3,
|
|
7
|
+
NOT_FOUND: 4,
|
|
8
|
+
/**
|
|
9
|
+
* Temporary: a 429 (a limit), a 408 (a request, such as an upload, too slow to arrive), a 502-504
|
|
10
|
+
* (briefly unavailable) or a first attempt still running (409). Retry later.
|
|
11
|
+
*/
|
|
12
|
+
RETRY_LATER: 5,
|
|
13
|
+
/** A 402: the account needs an API plan, or the plan's transcription minutes for the period are used up. */
|
|
14
|
+
PAYMENT_REQUIRED: 6
|
|
15
|
+
};
|
|
16
|
+
var HTTP_ERROR_TITLES = {
|
|
17
|
+
400: "Bad Request, without details.",
|
|
18
|
+
404: "Not Found, without details.",
|
|
19
|
+
413: "Payload Too Large, without details.",
|
|
20
|
+
429: "Too Many Requests, without details.",
|
|
21
|
+
500: "Internal Server Error, without details.",
|
|
22
|
+
502: "Bad Gateway, without details.",
|
|
23
|
+
503: "Service Unavailable, without details.",
|
|
24
|
+
504: "Gateway Timeout, without details."
|
|
25
|
+
};
|
|
26
|
+
function httpErrorCode(status) {
|
|
27
|
+
return status in HTTP_ERROR_TITLES ? `http_${status}` : "http_error";
|
|
28
|
+
}
|
|
29
|
+
var LOCAL_ERROR_CODES = [
|
|
30
|
+
{ code: "access_denied", title: "The sign-in was denied." },
|
|
31
|
+
{ code: "ambiguous_chat", title: "The chat name matches more than one chat." },
|
|
32
|
+
{ code: "chat_not_found", title: "Chat not found." },
|
|
33
|
+
{ code: "credentials_file_error", title: "The credentials file couldn't be read or written." },
|
|
34
|
+
{ code: "delivery_failed", title: "The network did not take the message." },
|
|
35
|
+
{ code: "delivery_unconfirmed", title: "The network didn't confirm the message, so it may have been delivered." },
|
|
36
|
+
{ code: "expired_token", title: "The sign-in code expired." },
|
|
37
|
+
{ code: "file_unreadable", title: "The file can't be read." },
|
|
38
|
+
{ code: "internal_error", title: "Something went wrong on our side." },
|
|
39
|
+
{ code: "invalid_api_url", title: "CHESLY_API_URL is not a usable API URL." },
|
|
40
|
+
{ code: "invalid_key_format", title: "The API key is not well formed." },
|
|
41
|
+
{ code: "invalid_response", title: "The API's answer is not what the CLI expects." },
|
|
42
|
+
{ code: "keychain_error", title: "The OS keychain refused." },
|
|
43
|
+
{ code: "keychain_timeout", title: "The OS keychain didn't answer in time." },
|
|
44
|
+
{ code: "login_not_started", title: "No sign-in is waiting to finish." },
|
|
45
|
+
{ code: "media_too_large", title: "The media is too large." },
|
|
46
|
+
{ code: "network_error", title: "The CLI couldn't reach the API." },
|
|
47
|
+
{ code: "not_signed_in", title: "Not signed in." },
|
|
48
|
+
{ code: "usage_error", title: "The command is not valid." },
|
|
49
|
+
...Object.entries(HTTP_ERROR_TITLES).map(([status, title]) => ({ code: `http_${status}`, title })),
|
|
50
|
+
{ code: "http_error", title: "An HTTP error without details." }
|
|
51
|
+
];
|
|
52
|
+
var API_ERROR_CODES = [
|
|
53
|
+
{ code: "invalid_api_key", status: 401, title: "The API key is missing or not valid." },
|
|
54
|
+
{ code: "forbidden", status: 403, title: "This request is not allowed." },
|
|
55
|
+
{ code: "not_found", status: 404, title: "Not found." },
|
|
56
|
+
{ code: "internal_error", status: 500, title: "Something went wrong on our side." },
|
|
57
|
+
{ code: "invalid_request", status: 400, title: "The request is not valid." },
|
|
58
|
+
{ code: "insufficient_scope", status: 403, title: "This API key does not allow this request." },
|
|
59
|
+
{ code: "account_not_found", status: 404, title: "Account not found." },
|
|
60
|
+
{ code: "chat_not_found", status: 404, title: "Chat not found." },
|
|
61
|
+
{ code: "message_not_found", status: 404, title: "Message not found." },
|
|
62
|
+
{ code: "media_not_found", status: 404, title: "Media not found." },
|
|
63
|
+
{ code: "media_expired", status: 410, title: "The media has expired." },
|
|
64
|
+
{ code: "media_too_large", status: 400, title: "The media is too large." },
|
|
65
|
+
{ code: "media_unavailable", status: 503, title: "The media is temporarily unavailable." },
|
|
66
|
+
{ code: "invalid_cursor", status: 400, title: "The cursor is not valid." },
|
|
67
|
+
{ code: "rate_limited", status: 429, title: "Too many requests." },
|
|
68
|
+
{ code: "network_unavailable", status: 503, title: "This network is temporarily unavailable." },
|
|
69
|
+
{ code: "search_unavailable", status: 503, title: "Search is temporarily unavailable." },
|
|
70
|
+
{ code: "feed_unavailable", status: 503, title: "The feed is temporarily unavailable." },
|
|
71
|
+
{ code: "upstream_unavailable", status: 503, title: "Your messages are temporarily unavailable." },
|
|
72
|
+
{ code: "signing_key_missing", status: 403, title: "The account signing key is missing." },
|
|
73
|
+
{ code: "idempotency_key_invalid", status: 400, title: "The Idempotency-Key header is not valid." },
|
|
74
|
+
{ code: "idempotency_key_reused", status: 422, title: "This Idempotency-Key was used for a different request." },
|
|
75
|
+
{ code: "idempotency_in_progress", status: 409, title: "A request with this Idempotency-Key is still running." },
|
|
76
|
+
{ code: "message_request", status: 409, title: "This chat is a message request." },
|
|
77
|
+
{ code: "message_not_editable", status: 409, title: "This message can't be edited." },
|
|
78
|
+
{ code: "message_not_deletable", status: 409, title: "This message can't be deleted." },
|
|
79
|
+
{ code: "send_limit_reached", status: 429, title: "This account's send limit is reached." },
|
|
80
|
+
{ code: "text_too_long", status: 400, title: "The text is too long for this network." },
|
|
81
|
+
{ code: "invalid_reply_to", status: 400, title: "reply_to must be a message in this chat." },
|
|
82
|
+
{ code: "unsupported_chat", status: 400, title: "Chesly can't send to this chat." },
|
|
83
|
+
{ code: "upload_timeout", status: 408, title: "The upload took too long to arrive." },
|
|
84
|
+
{ code: "events_expired", status: 410, title: "These events are no longer kept." },
|
|
85
|
+
{ code: "too_many_streams", status: 429, title: "Too many open event streams." },
|
|
86
|
+
{ code: "webhook_not_found", status: 404, title: "Webhook not found." },
|
|
87
|
+
{ code: "webhook_limit_reached", status: 400, title: "This account has the most webhooks allowed." },
|
|
88
|
+
{ code: "invalid_webhook_url", status: 400, title: "This webhook URL can't be used." },
|
|
89
|
+
{ code: "not_a_voice_note", status: 400, title: "This message is not a voice note." },
|
|
90
|
+
{ code: "transcription_unavailable", status: 503, title: "Transcription is temporarily unavailable." },
|
|
91
|
+
{ code: "transcription_failed", status: 422, title: "This voice message could not be transcribed." },
|
|
92
|
+
{ code: "key_not_found", status: 404, title: "API key not found." },
|
|
93
|
+
{ code: "api_plan_required", status: 402, title: "An API plan is required." },
|
|
94
|
+
{ code: "transcription_limit_reached", status: 402, title: "This period's transcription minutes are used up." },
|
|
95
|
+
{ code: "already_subscribed", status: 409, title: "You already have an API plan." },
|
|
96
|
+
{ code: "terms_changed", status: 409, title: "The API Terms changed." },
|
|
97
|
+
{ code: "plan_unavailable", status: 503, title: "Your API plan can't be checked just now." },
|
|
98
|
+
{ code: "plan_change_in_progress", status: 409, title: "A change to your plan is already under way." },
|
|
99
|
+
{ code: "email_send_failed", status: 502, title: "The email provider refused the message." },
|
|
100
|
+
{ code: "account_reconnect_required", status: 409, title: "This account needs to be reconnected." },
|
|
101
|
+
{ code: "api_paused", status: 503, title: "The Chesly API is paused." },
|
|
102
|
+
{ code: "payload_too_large", status: 413, title: "The request body is too large." }
|
|
103
|
+
];
|
|
104
|
+
var RETRY_LATER_STATUSES = /* @__PURE__ */ new Set([408, 429, 502, 503, 504]);
|
|
105
|
+
function apiExitCode(status, code) {
|
|
106
|
+
if (status === 400 && code === "invalid_request") return EXIT.USAGE;
|
|
107
|
+
if (status === 401) return EXIT.NOT_SIGNED_IN;
|
|
108
|
+
if (status === 402) return EXIT.PAYMENT_REQUIRED;
|
|
109
|
+
if (status === 404) return EXIT.NOT_FOUND;
|
|
110
|
+
if (RETRY_LATER_STATUSES.has(status)) return EXIT.RETRY_LATER;
|
|
111
|
+
if (status === 409 && code === "idempotency_in_progress") return EXIT.RETRY_LATER;
|
|
112
|
+
return EXIT.ERROR;
|
|
113
|
+
}
|
|
114
|
+
var LOCAL_WARNING_CODES = [
|
|
115
|
+
{ code: "delivery_wait_failed", title: "The message was sent, but following its delivery failed." },
|
|
116
|
+
{ code: "env_key_set", title: "CHESLY_API_KEY wins over the key login stored." },
|
|
117
|
+
{ code: "event_too_large", title: "An event too large to read was skipped." },
|
|
118
|
+
{ code: "events_expired", title: "The resume point is no longer kept, so watching starts from now." },
|
|
119
|
+
{ code: "invalid_event", title: "An event the CLI could not read was skipped." },
|
|
120
|
+
{ code: "key_details_unavailable", title: "The new key's details didn't load." },
|
|
121
|
+
{ code: "key_still_active", title: "A key this CLI no longer uses is still active." },
|
|
122
|
+
{ code: "reconnecting", title: "The event stream dropped and is reconnecting." }
|
|
123
|
+
];
|
|
124
|
+
var KeychainTimeoutError = class extends Error {
|
|
125
|
+
constructor(seconds) {
|
|
126
|
+
super(`The keychain didn't answer within ${seconds} s.`);
|
|
127
|
+
this.seconds = seconds;
|
|
128
|
+
this.name = "KeychainTimeoutError";
|
|
129
|
+
}
|
|
130
|
+
seconds;
|
|
131
|
+
};
|
|
132
|
+
function errorType(code) {
|
|
133
|
+
return `https://agents.chesly.app/docs/errors#${code}`;
|
|
134
|
+
}
|
|
135
|
+
var AnnotatedError = class extends Error {
|
|
136
|
+
constructor(error, extras, hint) {
|
|
137
|
+
super(error.message);
|
|
138
|
+
this.error = error;
|
|
139
|
+
this.extras = extras;
|
|
140
|
+
this.hint = hint;
|
|
141
|
+
this.name = "AnnotatedError";
|
|
142
|
+
}
|
|
143
|
+
error;
|
|
144
|
+
extras;
|
|
145
|
+
hint;
|
|
146
|
+
};
|
|
147
|
+
var CliError = class extends Error {
|
|
148
|
+
constructor(code, message, exitCode = EXIT.ERROR, details = {}) {
|
|
149
|
+
super(message);
|
|
150
|
+
this.code = code;
|
|
151
|
+
this.exitCode = exitCode;
|
|
152
|
+
this.name = "CliError";
|
|
153
|
+
this.extras = details.extras ?? {};
|
|
154
|
+
this.hint = details.hint;
|
|
155
|
+
}
|
|
156
|
+
code;
|
|
157
|
+
exitCode;
|
|
158
|
+
extras;
|
|
159
|
+
hint;
|
|
160
|
+
};
|
|
161
|
+
export {
|
|
162
|
+
API_ERROR_CODES,
|
|
163
|
+
AnnotatedError,
|
|
164
|
+
CliError,
|
|
165
|
+
EXIT,
|
|
166
|
+
KeychainTimeoutError,
|
|
167
|
+
LOCAL_ERROR_CODES,
|
|
168
|
+
LOCAL_WARNING_CODES,
|
|
169
|
+
RETRY_LATER_STATUSES,
|
|
170
|
+
apiExitCode,
|
|
171
|
+
errorType,
|
|
172
|
+
httpErrorCode
|
|
173
|
+
};
|