primitive 1.72.1 → 1.73.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/README.md +41 -10
- package/bin/claude-pending-mail.mjs +292 -136
- package/bin/claude-wake.mjs +129 -60
- package/dist/api-command-fKP3NYa7.js +2904 -0
- package/dist/{cli-config--YTRdJ3t.js → cli-config-C0Y_Ppol.js} +3 -598
- package/dist/client.gen-CaaMP86o.js +597 -0
- package/dist/{listen-background--0peztKE.js → listen-background-cD6n8VYO.js} +1 -1
- package/dist/{machine-session-Be6j29GE.js → machine-session-B6V5-grn.js} +907 -207
- package/dist/{notify-session-Byt5sPWW.js → notify-session-DJAb9SGm.js} +3 -3
- package/dist/oclif/auto-signal-worker.js +4 -3
- package/dist/oclif/auto-signals.js +2 -2
- package/dist/oclif/index.js +264 -203
- package/dist/oclif/listen-supervisor.js +1 -1
- package/dist/oclif/receiver-heal.js +4 -4
- package/dist/oclif/root-signup-hint.js +1 -1
- package/dist/{repeats-BL7ZC-_6-CKMKBlx7.js → repeats-BL7ZC-_6-B_ESsWTH.js} +4005 -1
- package/dist/{scoped-chat-DTFkP360.js → scoped-chat-DAiOb622.js} +10 -2
- package/dist/{shared-mail-files-MwlVE90c.js → shared-mail-files-CZfm7E2k.js} +21 -1
- package/dist/{shared-mail-watch-DtKpsgg8.js → shared-mail-watch-DyQB0MK0.js} +1 -1
- package/dist/{signal-command-DeEEZPbQ.js → signal-command-Cte4mAL3.js} +8 -7
- package/man/primitive.1 +1 -1
- package/package.json +1 -1
- package/dist/api-command-BrwPbyPP.js +0 -6546
|
@@ -1,604 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as createConfig, t as createClient } from "./client.gen-CaaMP86o.js";
|
|
2
|
+
import { c as mailTime, d as readMailJson, h as writeMailJson, i as mailId, l as privateMailDirectory, o as mailObject, r as mailAddress, s as mailString } from "./shared-mail-files-CZfm7E2k.js";
|
|
2
3
|
import { Errors } from "@oclif/core";
|
|
3
4
|
import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
5
|
import { randomUUID } from "node:crypto";
|
|
5
6
|
import { dirname, join } from "node:path";
|
|
6
|
-
//#region ../packages/api-core/src/api/core/bodySerializer.gen.ts
|
|
7
|
-
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region ../packages/api-core/src/api/core/serverSentEvents.gen.ts
|
|
10
|
-
function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
|
|
11
|
-
let lastEventId;
|
|
12
|
-
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
13
|
-
const createStream = async function* () {
|
|
14
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
15
|
-
let attempt = 0;
|
|
16
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
17
|
-
while (true) {
|
|
18
|
-
if (signal.aborted) break;
|
|
19
|
-
attempt++;
|
|
20
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
21
|
-
if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
|
|
22
|
-
try {
|
|
23
|
-
const requestInit = {
|
|
24
|
-
redirect: "follow",
|
|
25
|
-
...options,
|
|
26
|
-
body: options.serializedBody,
|
|
27
|
-
headers,
|
|
28
|
-
signal
|
|
29
|
-
};
|
|
30
|
-
let request = new Request(url, requestInit);
|
|
31
|
-
if (onRequest) request = await onRequest(url, requestInit);
|
|
32
|
-
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
33
|
-
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
34
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
35
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
36
|
-
let buffer = "";
|
|
37
|
-
const abortHandler = () => {
|
|
38
|
-
try {
|
|
39
|
-
reader.cancel();
|
|
40
|
-
} catch {}
|
|
41
|
-
};
|
|
42
|
-
signal.addEventListener("abort", abortHandler);
|
|
43
|
-
try {
|
|
44
|
-
while (true) {
|
|
45
|
-
const { done, value } = await reader.read();
|
|
46
|
-
if (done) break;
|
|
47
|
-
buffer += value;
|
|
48
|
-
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
49
|
-
const chunks = buffer.split("\n\n");
|
|
50
|
-
buffer = chunks.pop() ?? "";
|
|
51
|
-
for (const chunk of chunks) {
|
|
52
|
-
const lines = chunk.split("\n");
|
|
53
|
-
const dataLines = [];
|
|
54
|
-
let eventName;
|
|
55
|
-
for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
|
|
56
|
-
else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
|
|
57
|
-
else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
|
|
58
|
-
else if (line.startsWith("retry:")) {
|
|
59
|
-
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
60
|
-
if (!Number.isNaN(parsed)) retryDelay = parsed;
|
|
61
|
-
}
|
|
62
|
-
let data;
|
|
63
|
-
let parsedJson = false;
|
|
64
|
-
if (dataLines.length) {
|
|
65
|
-
const rawData = dataLines.join("\n");
|
|
66
|
-
try {
|
|
67
|
-
data = JSON.parse(rawData);
|
|
68
|
-
parsedJson = true;
|
|
69
|
-
} catch {
|
|
70
|
-
data = rawData;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (parsedJson) {
|
|
74
|
-
if (responseValidator) await responseValidator(data);
|
|
75
|
-
if (responseTransformer) data = await responseTransformer(data);
|
|
76
|
-
}
|
|
77
|
-
onSseEvent?.({
|
|
78
|
-
data,
|
|
79
|
-
event: eventName,
|
|
80
|
-
id: lastEventId,
|
|
81
|
-
retry: retryDelay
|
|
82
|
-
});
|
|
83
|
-
if (dataLines.length) yield data;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
} finally {
|
|
87
|
-
signal.removeEventListener("abort", abortHandler);
|
|
88
|
-
reader.releaseLock();
|
|
89
|
-
}
|
|
90
|
-
break;
|
|
91
|
-
} catch (error) {
|
|
92
|
-
onSseError?.(error);
|
|
93
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
94
|
-
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
95
|
-
await sleep(backoff);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
return { stream: createStream() };
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region ../packages/api-core/src/api/core/pathSerializer.gen.ts
|
|
103
|
-
const separatorArrayExplode = (style) => {
|
|
104
|
-
switch (style) {
|
|
105
|
-
case "label": return ".";
|
|
106
|
-
case "matrix": return ";";
|
|
107
|
-
case "simple": return ",";
|
|
108
|
-
default: return "&";
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
const separatorArrayNoExplode = (style) => {
|
|
112
|
-
switch (style) {
|
|
113
|
-
case "form": return ",";
|
|
114
|
-
case "pipeDelimited": return "|";
|
|
115
|
-
case "spaceDelimited": return "%20";
|
|
116
|
-
default: return ",";
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
const separatorObjectExplode = (style) => {
|
|
120
|
-
switch (style) {
|
|
121
|
-
case "label": return ".";
|
|
122
|
-
case "matrix": return ";";
|
|
123
|
-
case "simple": return ",";
|
|
124
|
-
default: return "&";
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
128
|
-
if (!explode) {
|
|
129
|
-
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
130
|
-
switch (style) {
|
|
131
|
-
case "label": return `.${joinedValues}`;
|
|
132
|
-
case "matrix": return `;${name}=${joinedValues}`;
|
|
133
|
-
case "simple": return joinedValues;
|
|
134
|
-
default: return `${name}=${joinedValues}`;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const separator = separatorArrayExplode(style);
|
|
138
|
-
const joinedValues = value.map((v) => {
|
|
139
|
-
if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
|
|
140
|
-
return serializePrimitiveParam({
|
|
141
|
-
allowReserved,
|
|
142
|
-
name,
|
|
143
|
-
value: v
|
|
144
|
-
});
|
|
145
|
-
}).join(separator);
|
|
146
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
147
|
-
};
|
|
148
|
-
const serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
149
|
-
if (value === void 0 || value === null) return "";
|
|
150
|
-
if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
151
|
-
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
152
|
-
};
|
|
153
|
-
const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
154
|
-
if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
155
|
-
if (style !== "deepObject" && !explode) {
|
|
156
|
-
let values = [];
|
|
157
|
-
Object.entries(value).forEach(([key, v]) => {
|
|
158
|
-
values = [
|
|
159
|
-
...values,
|
|
160
|
-
key,
|
|
161
|
-
allowReserved ? v : encodeURIComponent(v)
|
|
162
|
-
];
|
|
163
|
-
});
|
|
164
|
-
const joinedValues = values.join(",");
|
|
165
|
-
switch (style) {
|
|
166
|
-
case "form": return `${name}=${joinedValues}`;
|
|
167
|
-
case "label": return `.${joinedValues}`;
|
|
168
|
-
case "matrix": return `;${name}=${joinedValues}`;
|
|
169
|
-
default: return joinedValues;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
const separator = separatorObjectExplode(style);
|
|
173
|
-
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
174
|
-
allowReserved,
|
|
175
|
-
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
176
|
-
value: v
|
|
177
|
-
})).join(separator);
|
|
178
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
179
|
-
};
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region ../packages/api-core/src/api/core/utils.gen.ts
|
|
182
|
-
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
183
|
-
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
184
|
-
let url = _url;
|
|
185
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
186
|
-
if (matches) for (const match of matches) {
|
|
187
|
-
let explode = false;
|
|
188
|
-
let name = match.substring(1, match.length - 1);
|
|
189
|
-
let style = "simple";
|
|
190
|
-
if (name.endsWith("*")) {
|
|
191
|
-
explode = true;
|
|
192
|
-
name = name.substring(0, name.length - 1);
|
|
193
|
-
}
|
|
194
|
-
if (name.startsWith(".")) {
|
|
195
|
-
name = name.substring(1);
|
|
196
|
-
style = "label";
|
|
197
|
-
} else if (name.startsWith(";")) {
|
|
198
|
-
name = name.substring(1);
|
|
199
|
-
style = "matrix";
|
|
200
|
-
}
|
|
201
|
-
const value = path[name];
|
|
202
|
-
if (value === void 0 || value === null) continue;
|
|
203
|
-
if (Array.isArray(value)) {
|
|
204
|
-
url = url.replace(match, serializeArrayParam({
|
|
205
|
-
explode,
|
|
206
|
-
name,
|
|
207
|
-
style,
|
|
208
|
-
value
|
|
209
|
-
}));
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
if (typeof value === "object") {
|
|
213
|
-
url = url.replace(match, serializeObjectParam({
|
|
214
|
-
explode,
|
|
215
|
-
name,
|
|
216
|
-
style,
|
|
217
|
-
value,
|
|
218
|
-
valueOnly: true
|
|
219
|
-
}));
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
if (style === "matrix") {
|
|
223
|
-
url = url.replace(match, `;${serializePrimitiveParam({
|
|
224
|
-
name,
|
|
225
|
-
value
|
|
226
|
-
})}`);
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
230
|
-
url = url.replace(match, replaceValue);
|
|
231
|
-
}
|
|
232
|
-
return url;
|
|
233
|
-
};
|
|
234
|
-
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
235
|
-
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
236
|
-
let url = (baseUrl ?? "") + pathUrl;
|
|
237
|
-
if (path) url = defaultPathSerializer({
|
|
238
|
-
path,
|
|
239
|
-
url
|
|
240
|
-
});
|
|
241
|
-
let search = query ? querySerializer(query) : "";
|
|
242
|
-
if (search.startsWith("?")) search = search.substring(1);
|
|
243
|
-
if (search) url += `?${search}`;
|
|
244
|
-
return url;
|
|
245
|
-
};
|
|
246
|
-
function getValidRequestBody(options) {
|
|
247
|
-
const hasBody = options.body !== void 0;
|
|
248
|
-
if (hasBody && options.bodySerializer) {
|
|
249
|
-
if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
|
|
250
|
-
return options.body !== "" ? options.body : null;
|
|
251
|
-
}
|
|
252
|
-
if (hasBody) return options.body;
|
|
253
|
-
}
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region ../packages/api-core/src/api/core/auth.gen.ts
|
|
256
|
-
const getAuthToken = async (auth, callback) => {
|
|
257
|
-
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
258
|
-
if (!token) return;
|
|
259
|
-
if (auth.scheme === "bearer") return `Bearer ${token}`;
|
|
260
|
-
if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
|
|
261
|
-
return token;
|
|
262
|
-
};
|
|
263
|
-
//#endregion
|
|
264
|
-
//#region ../packages/api-core/src/api/client/utils.gen.ts
|
|
265
|
-
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
266
|
-
const querySerializer = (queryParams) => {
|
|
267
|
-
const search = [];
|
|
268
|
-
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
269
|
-
const value = queryParams[name];
|
|
270
|
-
if (value === void 0 || value === null) continue;
|
|
271
|
-
const options = parameters[name] || args;
|
|
272
|
-
if (Array.isArray(value)) {
|
|
273
|
-
const serializedArray = serializeArrayParam({
|
|
274
|
-
allowReserved: options.allowReserved,
|
|
275
|
-
explode: true,
|
|
276
|
-
name,
|
|
277
|
-
style: "form",
|
|
278
|
-
value,
|
|
279
|
-
...options.array
|
|
280
|
-
});
|
|
281
|
-
if (serializedArray) search.push(serializedArray);
|
|
282
|
-
} else if (typeof value === "object") {
|
|
283
|
-
const serializedObject = serializeObjectParam({
|
|
284
|
-
allowReserved: options.allowReserved,
|
|
285
|
-
explode: true,
|
|
286
|
-
name,
|
|
287
|
-
style: "deepObject",
|
|
288
|
-
value,
|
|
289
|
-
...options.object
|
|
290
|
-
});
|
|
291
|
-
if (serializedObject) search.push(serializedObject);
|
|
292
|
-
} else {
|
|
293
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
294
|
-
allowReserved: options.allowReserved,
|
|
295
|
-
name,
|
|
296
|
-
value
|
|
297
|
-
});
|
|
298
|
-
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return search.join("&");
|
|
302
|
-
};
|
|
303
|
-
return querySerializer;
|
|
304
|
-
};
|
|
305
|
-
/**
|
|
306
|
-
* Infers parseAs value from provided Content-Type header.
|
|
307
|
-
*/
|
|
308
|
-
const getParseAs = (contentType) => {
|
|
309
|
-
if (!contentType) return "stream";
|
|
310
|
-
const cleanContent = contentType.split(";")[0]?.trim();
|
|
311
|
-
if (!cleanContent) return;
|
|
312
|
-
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
|
|
313
|
-
if (cleanContent === "multipart/form-data") return "formData";
|
|
314
|
-
if ([
|
|
315
|
-
"application/",
|
|
316
|
-
"audio/",
|
|
317
|
-
"image/",
|
|
318
|
-
"video/"
|
|
319
|
-
].some((type) => cleanContent.startsWith(type))) return "blob";
|
|
320
|
-
if (cleanContent.startsWith("text/")) return "text";
|
|
321
|
-
};
|
|
322
|
-
const checkForExistence = (options, name) => {
|
|
323
|
-
if (!name) return false;
|
|
324
|
-
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
|
|
325
|
-
return false;
|
|
326
|
-
};
|
|
327
|
-
async function setAuthParams(options) {
|
|
328
|
-
for (const auth of options.security ?? []) {
|
|
329
|
-
if (checkForExistence(options, auth.name)) continue;
|
|
330
|
-
const token = await getAuthToken(auth, options.auth);
|
|
331
|
-
if (!token) continue;
|
|
332
|
-
const name = auth.name ?? "Authorization";
|
|
333
|
-
switch (auth.in) {
|
|
334
|
-
case "query":
|
|
335
|
-
if (!options.query) options.query = {};
|
|
336
|
-
options.query[name] = token;
|
|
337
|
-
break;
|
|
338
|
-
case "cookie":
|
|
339
|
-
options.headers.append("Cookie", `${name}=${token}`);
|
|
340
|
-
break;
|
|
341
|
-
default: options.headers.set(name, token);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
const buildUrl = (options) => getUrl({
|
|
346
|
-
baseUrl: options.baseUrl,
|
|
347
|
-
path: options.path,
|
|
348
|
-
query: options.query,
|
|
349
|
-
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
350
|
-
url: options.url
|
|
351
|
-
});
|
|
352
|
-
const mergeConfigs = (a, b) => {
|
|
353
|
-
const config = {
|
|
354
|
-
...a,
|
|
355
|
-
...b
|
|
356
|
-
};
|
|
357
|
-
if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
358
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
359
|
-
return config;
|
|
360
|
-
};
|
|
361
|
-
const headersEntries = (headers) => {
|
|
362
|
-
const entries = [];
|
|
363
|
-
headers.forEach((value, key) => {
|
|
364
|
-
entries.push([key, value]);
|
|
365
|
-
});
|
|
366
|
-
return entries;
|
|
367
|
-
};
|
|
368
|
-
const mergeHeaders = (...headers) => {
|
|
369
|
-
const mergedHeaders = new Headers();
|
|
370
|
-
for (const header of headers) {
|
|
371
|
-
if (!header) continue;
|
|
372
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
373
|
-
for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
|
|
374
|
-
else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
|
|
375
|
-
else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
376
|
-
}
|
|
377
|
-
return mergedHeaders;
|
|
378
|
-
};
|
|
379
|
-
var Interceptors = class {
|
|
380
|
-
fns = [];
|
|
381
|
-
clear() {
|
|
382
|
-
this.fns = [];
|
|
383
|
-
}
|
|
384
|
-
eject(id) {
|
|
385
|
-
const index = this.getInterceptorIndex(id);
|
|
386
|
-
if (this.fns[index]) this.fns[index] = null;
|
|
387
|
-
}
|
|
388
|
-
exists(id) {
|
|
389
|
-
const index = this.getInterceptorIndex(id);
|
|
390
|
-
return Boolean(this.fns[index]);
|
|
391
|
-
}
|
|
392
|
-
getInterceptorIndex(id) {
|
|
393
|
-
if (typeof id === "number") return this.fns[id] ? id : -1;
|
|
394
|
-
return this.fns.indexOf(id);
|
|
395
|
-
}
|
|
396
|
-
update(id, fn) {
|
|
397
|
-
const index = this.getInterceptorIndex(id);
|
|
398
|
-
if (this.fns[index]) {
|
|
399
|
-
this.fns[index] = fn;
|
|
400
|
-
return id;
|
|
401
|
-
}
|
|
402
|
-
return false;
|
|
403
|
-
}
|
|
404
|
-
use(fn) {
|
|
405
|
-
this.fns.push(fn);
|
|
406
|
-
return this.fns.length - 1;
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
const createInterceptors = () => ({
|
|
410
|
-
error: new Interceptors(),
|
|
411
|
-
request: new Interceptors(),
|
|
412
|
-
response: new Interceptors()
|
|
413
|
-
});
|
|
414
|
-
const defaultQuerySerializer = createQuerySerializer({
|
|
415
|
-
allowReserved: false,
|
|
416
|
-
array: {
|
|
417
|
-
explode: true,
|
|
418
|
-
style: "form"
|
|
419
|
-
},
|
|
420
|
-
object: {
|
|
421
|
-
explode: true,
|
|
422
|
-
style: "deepObject"
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
const defaultHeaders = { "Content-Type": "application/json" };
|
|
426
|
-
const createConfig = (override = {}) => ({
|
|
427
|
-
...jsonBodySerializer,
|
|
428
|
-
headers: defaultHeaders,
|
|
429
|
-
parseAs: "auto",
|
|
430
|
-
querySerializer: defaultQuerySerializer,
|
|
431
|
-
...override
|
|
432
|
-
});
|
|
433
|
-
//#endregion
|
|
434
|
-
//#region ../packages/api-core/src/api/client/client.gen.ts
|
|
435
|
-
const createClient = (config = {}) => {
|
|
436
|
-
let _config = mergeConfigs(createConfig(), config);
|
|
437
|
-
const getConfig = () => ({ ..._config });
|
|
438
|
-
const setConfig = (config) => {
|
|
439
|
-
_config = mergeConfigs(_config, config);
|
|
440
|
-
return getConfig();
|
|
441
|
-
};
|
|
442
|
-
const interceptors = createInterceptors();
|
|
443
|
-
const beforeRequest = async (options) => {
|
|
444
|
-
const opts = {
|
|
445
|
-
..._config,
|
|
446
|
-
...options,
|
|
447
|
-
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
448
|
-
headers: mergeHeaders(_config.headers, options.headers),
|
|
449
|
-
serializedBody: void 0
|
|
450
|
-
};
|
|
451
|
-
if (opts.security) await setAuthParams(opts);
|
|
452
|
-
if (opts.requestValidator) await opts.requestValidator(opts);
|
|
453
|
-
if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
|
|
454
|
-
if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
|
|
455
|
-
const resolvedOpts = opts;
|
|
456
|
-
return {
|
|
457
|
-
opts: resolvedOpts,
|
|
458
|
-
url: buildUrl(resolvedOpts)
|
|
459
|
-
};
|
|
460
|
-
};
|
|
461
|
-
const request = async (options) => {
|
|
462
|
-
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
463
|
-
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
464
|
-
let request;
|
|
465
|
-
let response;
|
|
466
|
-
try {
|
|
467
|
-
const { opts, url } = await beforeRequest(options);
|
|
468
|
-
const requestInit = {
|
|
469
|
-
redirect: "follow",
|
|
470
|
-
...opts,
|
|
471
|
-
body: getValidRequestBody(opts)
|
|
472
|
-
};
|
|
473
|
-
request = new Request(url, requestInit);
|
|
474
|
-
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
475
|
-
const _fetch = opts.fetch;
|
|
476
|
-
response = await _fetch(request);
|
|
477
|
-
for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
|
|
478
|
-
const result = {
|
|
479
|
-
request,
|
|
480
|
-
response
|
|
481
|
-
};
|
|
482
|
-
if (response.ok) {
|
|
483
|
-
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
484
|
-
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
485
|
-
let emptyData;
|
|
486
|
-
switch (parseAs) {
|
|
487
|
-
case "arrayBuffer":
|
|
488
|
-
case "blob":
|
|
489
|
-
case "text":
|
|
490
|
-
emptyData = await response[parseAs]();
|
|
491
|
-
break;
|
|
492
|
-
case "formData":
|
|
493
|
-
emptyData = new FormData();
|
|
494
|
-
break;
|
|
495
|
-
case "stream":
|
|
496
|
-
emptyData = response.body;
|
|
497
|
-
break;
|
|
498
|
-
default: emptyData = {};
|
|
499
|
-
}
|
|
500
|
-
return opts.responseStyle === "data" ? emptyData : {
|
|
501
|
-
data: emptyData,
|
|
502
|
-
...result
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
let data;
|
|
506
|
-
switch (parseAs) {
|
|
507
|
-
case "arrayBuffer":
|
|
508
|
-
case "blob":
|
|
509
|
-
case "formData":
|
|
510
|
-
case "text":
|
|
511
|
-
data = await response[parseAs]();
|
|
512
|
-
break;
|
|
513
|
-
case "json": {
|
|
514
|
-
const text = await response.text();
|
|
515
|
-
data = text ? JSON.parse(text) : {};
|
|
516
|
-
break;
|
|
517
|
-
}
|
|
518
|
-
case "stream": return opts.responseStyle === "data" ? response.body : {
|
|
519
|
-
data: response.body,
|
|
520
|
-
...result
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
if (parseAs === "json") {
|
|
524
|
-
if (opts.responseValidator) await opts.responseValidator(data);
|
|
525
|
-
if (opts.responseTransformer) data = await opts.responseTransformer(data);
|
|
526
|
-
}
|
|
527
|
-
return opts.responseStyle === "data" ? data : {
|
|
528
|
-
data,
|
|
529
|
-
...result
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
const textError = await response.text();
|
|
533
|
-
let jsonError;
|
|
534
|
-
try {
|
|
535
|
-
jsonError = JSON.parse(textError);
|
|
536
|
-
} catch {}
|
|
537
|
-
throw jsonError ?? textError;
|
|
538
|
-
} catch (error) {
|
|
539
|
-
let finalError = error;
|
|
540
|
-
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(finalError, response, request, options);
|
|
541
|
-
finalError = finalError || {};
|
|
542
|
-
if (throwOnError) throw finalError;
|
|
543
|
-
return responseStyle === "data" ? void 0 : {
|
|
544
|
-
error: finalError,
|
|
545
|
-
request,
|
|
546
|
-
response
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
};
|
|
550
|
-
const makeMethodFn = (method) => (options) => request({
|
|
551
|
-
...options,
|
|
552
|
-
method
|
|
553
|
-
});
|
|
554
|
-
const makeSseFn = (method) => async (options) => {
|
|
555
|
-
const { opts, url } = await beforeRequest(options);
|
|
556
|
-
return createSseClient({
|
|
557
|
-
...opts,
|
|
558
|
-
body: opts.body,
|
|
559
|
-
method,
|
|
560
|
-
onRequest: async (url, init) => {
|
|
561
|
-
let request = new Request(url, init);
|
|
562
|
-
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
563
|
-
return request;
|
|
564
|
-
},
|
|
565
|
-
serializedBody: getValidRequestBody(opts),
|
|
566
|
-
url
|
|
567
|
-
});
|
|
568
|
-
};
|
|
569
|
-
const _buildUrl = (options) => buildUrl({
|
|
570
|
-
..._config,
|
|
571
|
-
...options
|
|
572
|
-
});
|
|
573
|
-
return {
|
|
574
|
-
buildUrl: _buildUrl,
|
|
575
|
-
connect: makeMethodFn("CONNECT"),
|
|
576
|
-
delete: makeMethodFn("DELETE"),
|
|
577
|
-
get: makeMethodFn("GET"),
|
|
578
|
-
getConfig,
|
|
579
|
-
head: makeMethodFn("HEAD"),
|
|
580
|
-
interceptors,
|
|
581
|
-
options: makeMethodFn("OPTIONS"),
|
|
582
|
-
patch: makeMethodFn("PATCH"),
|
|
583
|
-
post: makeMethodFn("POST"),
|
|
584
|
-
put: makeMethodFn("PUT"),
|
|
585
|
-
request,
|
|
586
|
-
setConfig,
|
|
587
|
-
sse: {
|
|
588
|
-
connect: makeSseFn("CONNECT"),
|
|
589
|
-
delete: makeSseFn("DELETE"),
|
|
590
|
-
get: makeSseFn("GET"),
|
|
591
|
-
head: makeSseFn("HEAD"),
|
|
592
|
-
options: makeSseFn("OPTIONS"),
|
|
593
|
-
patch: makeSseFn("PATCH"),
|
|
594
|
-
post: makeSseFn("POST"),
|
|
595
|
-
put: makeSseFn("PUT"),
|
|
596
|
-
trace: makeSseFn("TRACE")
|
|
597
|
-
},
|
|
598
|
-
trace: makeMethodFn("TRACE")
|
|
599
|
-
};
|
|
600
|
-
};
|
|
601
|
-
//#endregion
|
|
602
7
|
//#region ../packages/api-core/src/client.ts
|
|
603
8
|
/**
|
|
604
9
|
* Host-aware Primitive API client and shared error type.
|
|
@@ -1503,4 +908,4 @@ function redactCliEnvironment(environment) {
|
|
|
1503
908
|
};
|
|
1504
909
|
}
|
|
1505
910
|
//#endregion
|
|
1506
|
-
export { saveActiveChatState as A, parseConnectedAgentProfile as B, resolveCliAuth as C, deleteChatState as D, chatStatePath as E, agentProfileName as F, PrimitiveApiClient as G, profileAlreadyConnectedMessage as H, agentProfilesDirectory as I,
|
|
911
|
+
export { saveActiveChatState as A, parseConnectedAgentProfile as B, resolveCliAuth as C, deleteChatState as D, chatStatePath as E, agentProfileName as F, PrimitiveApiClient as G, profileAlreadyConnectedMessage as H, agentProfilesDirectory as I, connectedAgentIdentity as L, AGENT_PROFILE_ENV as M, AgentConnectionSetupError as N, loadActiveChatState as O, agentProfileDirectory as P, connectedApiBaseUrl as R, normalizeApiBaseUrl as S, saveSignupCredentials as T, requireDefaultLoginProfile as U, parseOwnerMemberAddress as V, saveConnectedAgentProfile as W, deleteCliCredentials as _, normalizeCliEnvironmentName as a, hasStoredCliLogin as b, resolveConfigEnvironment as c, validateCliHeaderName as d, validateCliHeaderValue as f, credentialsPath as g, credentialsLockPath as h, loadCliConfig as i, AGENT_ADDRESS_ENV as j, loadChatConversationByLocalId as k, saveCliConfig as l, cliAccessTokenExpiresAt as m, deleteCliConfig as n, redactCliEnvironment as o, acquireCliCredentialsLock as p, emptyCliConfig as r, removeCliEnvironment as s, DEFAULT_ENVIRONMENT as t, upsertCliEnvironment as u, deleteCliCredentialsLock as v, saveCliCredentials as w, loadCliCredentials as x, detectPrimitiveKeyEnvMisname as y, loadConnectedAgentProfile as z };
|