primcli 1.40.0 → 1.42.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 +47 -1
- package/bin/claude-pending-mail.mjs +39 -1
- package/bin/claude-wake.mjs +1 -1
- package/dist/{auto-signals-C8nMME8J.js → auto-signals-D3NqwgYA.js} +1 -1
- package/dist/{cli-config-UOlrfcPz.js → cli-config-BoZ1lMUQ.js} +729 -2
- package/dist/{connect-skill-DjKt8NC8.js → connect-skill-BHxdjtkK.js} +5 -3
- package/dist/{sdk.gen-CgKZwHs3.js → interaction-actions-D5o_frTT.js} +1828 -2
- package/dist/{listen-background-Bsofqq_6.js → listen-background-TTBqrO_R.js} +1 -1
- package/dist/oclif/auto-signal-worker.js +4 -4
- package/dist/oclif/auto-signals.js +1 -1
- package/dist/oclif/index.js +2318 -1877
- package/dist/oclif/listen-supervisor.js +1 -1
- package/dist/oclif/proxy-auto-detect.js +1 -1
- package/dist/oclif/receiver-heal.js +4 -4
- package/dist/oclif/root-signup-hint.js +1 -1
- package/dist/{signal-command-C8Ph0ylh.js → signal-command-D5YGxi_o.js} +12 -1570
- package/package.json +1 -1
- package/dist/connected-agent-profile-8tpOMdq3.js +0 -730
- /package/dist/{json-output-BVRgl6jf.js → json-output-CJXNOsUI.js} +0 -0
- /package/dist/{shared-mail-files-CZqI1kj6.js → shared-mail-files-SPPcis9g.js} +0 -0
|
@@ -1,730 +0,0 @@
|
|
|
1
|
-
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-CZqI1kj6.js";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
//#region ../packages/api-core/src/api/core/bodySerializer.gen.ts
|
|
4
|
-
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region ../packages/api-core/src/api/core/serverSentEvents.gen.ts
|
|
7
|
-
function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
|
|
8
|
-
let lastEventId;
|
|
9
|
-
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
10
|
-
const createStream = async function* () {
|
|
11
|
-
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
12
|
-
let attempt = 0;
|
|
13
|
-
const signal = options.signal ?? new AbortController().signal;
|
|
14
|
-
while (true) {
|
|
15
|
-
if (signal.aborted) break;
|
|
16
|
-
attempt++;
|
|
17
|
-
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
18
|
-
if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
|
|
19
|
-
try {
|
|
20
|
-
const requestInit = {
|
|
21
|
-
redirect: "follow",
|
|
22
|
-
...options,
|
|
23
|
-
body: options.serializedBody,
|
|
24
|
-
headers,
|
|
25
|
-
signal
|
|
26
|
-
};
|
|
27
|
-
let request = new Request(url, requestInit);
|
|
28
|
-
if (onRequest) request = await onRequest(url, requestInit);
|
|
29
|
-
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
30
|
-
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
31
|
-
if (!response.body) throw new Error("No body in SSE response");
|
|
32
|
-
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
33
|
-
let buffer = "";
|
|
34
|
-
const abortHandler = () => {
|
|
35
|
-
try {
|
|
36
|
-
reader.cancel();
|
|
37
|
-
} catch {}
|
|
38
|
-
};
|
|
39
|
-
signal.addEventListener("abort", abortHandler);
|
|
40
|
-
try {
|
|
41
|
-
while (true) {
|
|
42
|
-
const { done, value } = await reader.read();
|
|
43
|
-
if (done) break;
|
|
44
|
-
buffer += value;
|
|
45
|
-
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
46
|
-
const chunks = buffer.split("\n\n");
|
|
47
|
-
buffer = chunks.pop() ?? "";
|
|
48
|
-
for (const chunk of chunks) {
|
|
49
|
-
const lines = chunk.split("\n");
|
|
50
|
-
const dataLines = [];
|
|
51
|
-
let eventName;
|
|
52
|
-
for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
|
|
53
|
-
else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
|
|
54
|
-
else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
|
|
55
|
-
else if (line.startsWith("retry:")) {
|
|
56
|
-
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
57
|
-
if (!Number.isNaN(parsed)) retryDelay = parsed;
|
|
58
|
-
}
|
|
59
|
-
let data;
|
|
60
|
-
let parsedJson = false;
|
|
61
|
-
if (dataLines.length) {
|
|
62
|
-
const rawData = dataLines.join("\n");
|
|
63
|
-
try {
|
|
64
|
-
data = JSON.parse(rawData);
|
|
65
|
-
parsedJson = true;
|
|
66
|
-
} catch {
|
|
67
|
-
data = rawData;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (parsedJson) {
|
|
71
|
-
if (responseValidator) await responseValidator(data);
|
|
72
|
-
if (responseTransformer) data = await responseTransformer(data);
|
|
73
|
-
}
|
|
74
|
-
onSseEvent?.({
|
|
75
|
-
data,
|
|
76
|
-
event: eventName,
|
|
77
|
-
id: lastEventId,
|
|
78
|
-
retry: retryDelay
|
|
79
|
-
});
|
|
80
|
-
if (dataLines.length) yield data;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
} finally {
|
|
84
|
-
signal.removeEventListener("abort", abortHandler);
|
|
85
|
-
reader.releaseLock();
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
} catch (error) {
|
|
89
|
-
onSseError?.(error);
|
|
90
|
-
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
91
|
-
await sleep(Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
return { stream: createStream() };
|
|
96
|
-
}
|
|
97
|
-
//#endregion
|
|
98
|
-
//#region ../packages/api-core/src/api/core/pathSerializer.gen.ts
|
|
99
|
-
const separatorArrayExplode = (style) => {
|
|
100
|
-
switch (style) {
|
|
101
|
-
case "label": return ".";
|
|
102
|
-
case "matrix": return ";";
|
|
103
|
-
case "simple": return ",";
|
|
104
|
-
default: return "&";
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const separatorArrayNoExplode = (style) => {
|
|
108
|
-
switch (style) {
|
|
109
|
-
case "form": return ",";
|
|
110
|
-
case "pipeDelimited": return "|";
|
|
111
|
-
case "spaceDelimited": return "%20";
|
|
112
|
-
default: return ",";
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
const separatorObjectExplode = (style) => {
|
|
116
|
-
switch (style) {
|
|
117
|
-
case "label": return ".";
|
|
118
|
-
case "matrix": return ";";
|
|
119
|
-
case "simple": return ",";
|
|
120
|
-
default: return "&";
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
124
|
-
if (!explode) {
|
|
125
|
-
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
126
|
-
switch (style) {
|
|
127
|
-
case "label": return `.${joinedValues}`;
|
|
128
|
-
case "matrix": return `;${name}=${joinedValues}`;
|
|
129
|
-
case "simple": return joinedValues;
|
|
130
|
-
default: return `${name}=${joinedValues}`;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const separator = separatorArrayExplode(style);
|
|
134
|
-
const joinedValues = value.map((v) => {
|
|
135
|
-
if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
|
|
136
|
-
return serializePrimitiveParam({
|
|
137
|
-
allowReserved,
|
|
138
|
-
name,
|
|
139
|
-
value: v
|
|
140
|
-
});
|
|
141
|
-
}).join(separator);
|
|
142
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
143
|
-
};
|
|
144
|
-
const serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
145
|
-
if (value === void 0 || value === null) return "";
|
|
146
|
-
if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
147
|
-
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
148
|
-
};
|
|
149
|
-
const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
150
|
-
if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
151
|
-
if (style !== "deepObject" && !explode) {
|
|
152
|
-
let values = [];
|
|
153
|
-
Object.entries(value).forEach(([key, v]) => {
|
|
154
|
-
values = [
|
|
155
|
-
...values,
|
|
156
|
-
key,
|
|
157
|
-
allowReserved ? v : encodeURIComponent(v)
|
|
158
|
-
];
|
|
159
|
-
});
|
|
160
|
-
const joinedValues = values.join(",");
|
|
161
|
-
switch (style) {
|
|
162
|
-
case "form": return `${name}=${joinedValues}`;
|
|
163
|
-
case "label": return `.${joinedValues}`;
|
|
164
|
-
case "matrix": return `;${name}=${joinedValues}`;
|
|
165
|
-
default: return joinedValues;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const separator = separatorObjectExplode(style);
|
|
169
|
-
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
170
|
-
allowReserved,
|
|
171
|
-
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
172
|
-
value: v
|
|
173
|
-
})).join(separator);
|
|
174
|
-
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
175
|
-
};
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region ../packages/api-core/src/api/core/utils.gen.ts
|
|
178
|
-
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
179
|
-
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
180
|
-
let url = _url;
|
|
181
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
182
|
-
if (matches) for (const match of matches) {
|
|
183
|
-
let explode = false;
|
|
184
|
-
let name = match.substring(1, match.length - 1);
|
|
185
|
-
let style = "simple";
|
|
186
|
-
if (name.endsWith("*")) {
|
|
187
|
-
explode = true;
|
|
188
|
-
name = name.substring(0, name.length - 1);
|
|
189
|
-
}
|
|
190
|
-
if (name.startsWith(".")) {
|
|
191
|
-
name = name.substring(1);
|
|
192
|
-
style = "label";
|
|
193
|
-
} else if (name.startsWith(";")) {
|
|
194
|
-
name = name.substring(1);
|
|
195
|
-
style = "matrix";
|
|
196
|
-
}
|
|
197
|
-
const value = path[name];
|
|
198
|
-
if (value === void 0 || value === null) continue;
|
|
199
|
-
if (Array.isArray(value)) {
|
|
200
|
-
url = url.replace(match, serializeArrayParam({
|
|
201
|
-
explode,
|
|
202
|
-
name,
|
|
203
|
-
style,
|
|
204
|
-
value
|
|
205
|
-
}));
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
if (typeof value === "object") {
|
|
209
|
-
url = url.replace(match, serializeObjectParam({
|
|
210
|
-
explode,
|
|
211
|
-
name,
|
|
212
|
-
style,
|
|
213
|
-
value,
|
|
214
|
-
valueOnly: true
|
|
215
|
-
}));
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
if (style === "matrix") {
|
|
219
|
-
url = url.replace(match, `;${serializePrimitiveParam({
|
|
220
|
-
name,
|
|
221
|
-
value
|
|
222
|
-
})}`);
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
226
|
-
url = url.replace(match, replaceValue);
|
|
227
|
-
}
|
|
228
|
-
return url;
|
|
229
|
-
};
|
|
230
|
-
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
231
|
-
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
232
|
-
let url = (baseUrl ?? "") + pathUrl;
|
|
233
|
-
if (path) url = defaultPathSerializer({
|
|
234
|
-
path,
|
|
235
|
-
url
|
|
236
|
-
});
|
|
237
|
-
let search = query ? querySerializer(query) : "";
|
|
238
|
-
if (search.startsWith("?")) search = search.substring(1);
|
|
239
|
-
if (search) url += `?${search}`;
|
|
240
|
-
return url;
|
|
241
|
-
};
|
|
242
|
-
function getValidRequestBody(options) {
|
|
243
|
-
const hasBody = options.body !== void 0;
|
|
244
|
-
if (hasBody && options.bodySerializer) {
|
|
245
|
-
if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
|
|
246
|
-
return options.body !== "" ? options.body : null;
|
|
247
|
-
}
|
|
248
|
-
if (hasBody) return options.body;
|
|
249
|
-
}
|
|
250
|
-
//#endregion
|
|
251
|
-
//#region ../packages/api-core/src/api/core/auth.gen.ts
|
|
252
|
-
const getAuthToken = async (auth, callback) => {
|
|
253
|
-
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
254
|
-
if (!token) return;
|
|
255
|
-
if (auth.scheme === "bearer") return `Bearer ${token}`;
|
|
256
|
-
if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
|
|
257
|
-
return token;
|
|
258
|
-
};
|
|
259
|
-
//#endregion
|
|
260
|
-
//#region ../packages/api-core/src/api/client/utils.gen.ts
|
|
261
|
-
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
262
|
-
const querySerializer = (queryParams) => {
|
|
263
|
-
const search = [];
|
|
264
|
-
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
265
|
-
const value = queryParams[name];
|
|
266
|
-
if (value === void 0 || value === null) continue;
|
|
267
|
-
const options = parameters[name] || args;
|
|
268
|
-
if (Array.isArray(value)) {
|
|
269
|
-
const serializedArray = serializeArrayParam({
|
|
270
|
-
allowReserved: options.allowReserved,
|
|
271
|
-
explode: true,
|
|
272
|
-
name,
|
|
273
|
-
style: "form",
|
|
274
|
-
value,
|
|
275
|
-
...options.array
|
|
276
|
-
});
|
|
277
|
-
if (serializedArray) search.push(serializedArray);
|
|
278
|
-
} else if (typeof value === "object") {
|
|
279
|
-
const serializedObject = serializeObjectParam({
|
|
280
|
-
allowReserved: options.allowReserved,
|
|
281
|
-
explode: true,
|
|
282
|
-
name,
|
|
283
|
-
style: "deepObject",
|
|
284
|
-
value,
|
|
285
|
-
...options.object
|
|
286
|
-
});
|
|
287
|
-
if (serializedObject) search.push(serializedObject);
|
|
288
|
-
} else {
|
|
289
|
-
const serializedPrimitive = serializePrimitiveParam({
|
|
290
|
-
allowReserved: options.allowReserved,
|
|
291
|
-
name,
|
|
292
|
-
value
|
|
293
|
-
});
|
|
294
|
-
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
return search.join("&");
|
|
298
|
-
};
|
|
299
|
-
return querySerializer;
|
|
300
|
-
};
|
|
301
|
-
/**
|
|
302
|
-
* Infers parseAs value from provided Content-Type header.
|
|
303
|
-
*/
|
|
304
|
-
const getParseAs = (contentType) => {
|
|
305
|
-
if (!contentType) return "stream";
|
|
306
|
-
const cleanContent = contentType.split(";")[0]?.trim();
|
|
307
|
-
if (!cleanContent) return;
|
|
308
|
-
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
|
|
309
|
-
if (cleanContent === "multipart/form-data") return "formData";
|
|
310
|
-
if ([
|
|
311
|
-
"application/",
|
|
312
|
-
"audio/",
|
|
313
|
-
"image/",
|
|
314
|
-
"video/"
|
|
315
|
-
].some((type) => cleanContent.startsWith(type))) return "blob";
|
|
316
|
-
if (cleanContent.startsWith("text/")) return "text";
|
|
317
|
-
};
|
|
318
|
-
const checkForExistence = (options, name) => {
|
|
319
|
-
if (!name) return false;
|
|
320
|
-
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
|
|
321
|
-
return false;
|
|
322
|
-
};
|
|
323
|
-
async function setAuthParams(options) {
|
|
324
|
-
for (const auth of options.security ?? []) {
|
|
325
|
-
if (checkForExistence(options, auth.name)) continue;
|
|
326
|
-
const token = await getAuthToken(auth, options.auth);
|
|
327
|
-
if (!token) continue;
|
|
328
|
-
const name = auth.name ?? "Authorization";
|
|
329
|
-
switch (auth.in) {
|
|
330
|
-
case "query":
|
|
331
|
-
if (!options.query) options.query = {};
|
|
332
|
-
options.query[name] = token;
|
|
333
|
-
break;
|
|
334
|
-
case "cookie":
|
|
335
|
-
options.headers.append("Cookie", `${name}=${token}`);
|
|
336
|
-
break;
|
|
337
|
-
default:
|
|
338
|
-
options.headers.set(name, token);
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
const buildUrl = (options) => getUrl({
|
|
344
|
-
baseUrl: options.baseUrl,
|
|
345
|
-
path: options.path,
|
|
346
|
-
query: options.query,
|
|
347
|
-
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
348
|
-
url: options.url
|
|
349
|
-
});
|
|
350
|
-
const mergeConfigs = (a, b) => {
|
|
351
|
-
const config = {
|
|
352
|
-
...a,
|
|
353
|
-
...b
|
|
354
|
-
};
|
|
355
|
-
if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
356
|
-
config.headers = mergeHeaders(a.headers, b.headers);
|
|
357
|
-
return config;
|
|
358
|
-
};
|
|
359
|
-
const headersEntries = (headers) => {
|
|
360
|
-
const entries = [];
|
|
361
|
-
headers.forEach((value, key) => {
|
|
362
|
-
entries.push([key, value]);
|
|
363
|
-
});
|
|
364
|
-
return entries;
|
|
365
|
-
};
|
|
366
|
-
const mergeHeaders = (...headers) => {
|
|
367
|
-
const mergedHeaders = new Headers();
|
|
368
|
-
for (const header of headers) {
|
|
369
|
-
if (!header) continue;
|
|
370
|
-
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
371
|
-
for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
|
|
372
|
-
else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
|
|
373
|
-
else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
374
|
-
}
|
|
375
|
-
return mergedHeaders;
|
|
376
|
-
};
|
|
377
|
-
var Interceptors = class {
|
|
378
|
-
fns = [];
|
|
379
|
-
clear() {
|
|
380
|
-
this.fns = [];
|
|
381
|
-
}
|
|
382
|
-
eject(id) {
|
|
383
|
-
const index = this.getInterceptorIndex(id);
|
|
384
|
-
if (this.fns[index]) this.fns[index] = null;
|
|
385
|
-
}
|
|
386
|
-
exists(id) {
|
|
387
|
-
const index = this.getInterceptorIndex(id);
|
|
388
|
-
return Boolean(this.fns[index]);
|
|
389
|
-
}
|
|
390
|
-
getInterceptorIndex(id) {
|
|
391
|
-
if (typeof id === "number") return this.fns[id] ? id : -1;
|
|
392
|
-
return this.fns.indexOf(id);
|
|
393
|
-
}
|
|
394
|
-
update(id, fn) {
|
|
395
|
-
const index = this.getInterceptorIndex(id);
|
|
396
|
-
if (this.fns[index]) {
|
|
397
|
-
this.fns[index] = fn;
|
|
398
|
-
return id;
|
|
399
|
-
}
|
|
400
|
-
return false;
|
|
401
|
-
}
|
|
402
|
-
use(fn) {
|
|
403
|
-
this.fns.push(fn);
|
|
404
|
-
return this.fns.length - 1;
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
const createInterceptors = () => ({
|
|
408
|
-
error: new Interceptors(),
|
|
409
|
-
request: new Interceptors(),
|
|
410
|
-
response: new Interceptors()
|
|
411
|
-
});
|
|
412
|
-
const defaultQuerySerializer = createQuerySerializer({
|
|
413
|
-
allowReserved: false,
|
|
414
|
-
array: {
|
|
415
|
-
explode: true,
|
|
416
|
-
style: "form"
|
|
417
|
-
},
|
|
418
|
-
object: {
|
|
419
|
-
explode: true,
|
|
420
|
-
style: "deepObject"
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
const defaultHeaders = { "Content-Type": "application/json" };
|
|
424
|
-
const createConfig = (override = {}) => ({
|
|
425
|
-
...jsonBodySerializer,
|
|
426
|
-
headers: defaultHeaders,
|
|
427
|
-
parseAs: "auto",
|
|
428
|
-
querySerializer: defaultQuerySerializer,
|
|
429
|
-
...override
|
|
430
|
-
});
|
|
431
|
-
//#endregion
|
|
432
|
-
//#region ../packages/api-core/src/api/client/client.gen.ts
|
|
433
|
-
const createClient = (config = {}) => {
|
|
434
|
-
let _config = mergeConfigs(createConfig(), config);
|
|
435
|
-
const getConfig = () => ({ ..._config });
|
|
436
|
-
const setConfig = (config) => {
|
|
437
|
-
_config = mergeConfigs(_config, config);
|
|
438
|
-
return getConfig();
|
|
439
|
-
};
|
|
440
|
-
const interceptors = createInterceptors();
|
|
441
|
-
const beforeRequest = async (options) => {
|
|
442
|
-
const opts = {
|
|
443
|
-
..._config,
|
|
444
|
-
...options,
|
|
445
|
-
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
446
|
-
headers: mergeHeaders(_config.headers, options.headers),
|
|
447
|
-
serializedBody: void 0
|
|
448
|
-
};
|
|
449
|
-
if (opts.security) await setAuthParams(opts);
|
|
450
|
-
if (opts.requestValidator) await opts.requestValidator(opts);
|
|
451
|
-
if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
|
|
452
|
-
if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
|
|
453
|
-
const resolvedOpts = opts;
|
|
454
|
-
return {
|
|
455
|
-
opts: resolvedOpts,
|
|
456
|
-
url: buildUrl(resolvedOpts)
|
|
457
|
-
};
|
|
458
|
-
};
|
|
459
|
-
const request = async (options) => {
|
|
460
|
-
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
461
|
-
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
462
|
-
let request;
|
|
463
|
-
let response;
|
|
464
|
-
try {
|
|
465
|
-
const { opts, url } = await beforeRequest(options);
|
|
466
|
-
const requestInit = {
|
|
467
|
-
redirect: "follow",
|
|
468
|
-
...opts,
|
|
469
|
-
body: getValidRequestBody(opts)
|
|
470
|
-
};
|
|
471
|
-
request = new Request(url, requestInit);
|
|
472
|
-
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
473
|
-
const _fetch = opts.fetch;
|
|
474
|
-
response = await _fetch(request);
|
|
475
|
-
for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
|
|
476
|
-
const result = {
|
|
477
|
-
request,
|
|
478
|
-
response
|
|
479
|
-
};
|
|
480
|
-
if (response.ok) {
|
|
481
|
-
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
482
|
-
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
483
|
-
let emptyData;
|
|
484
|
-
switch (parseAs) {
|
|
485
|
-
case "arrayBuffer":
|
|
486
|
-
case "blob":
|
|
487
|
-
case "text":
|
|
488
|
-
emptyData = await response[parseAs]();
|
|
489
|
-
break;
|
|
490
|
-
case "formData":
|
|
491
|
-
emptyData = new FormData();
|
|
492
|
-
break;
|
|
493
|
-
case "stream":
|
|
494
|
-
emptyData = response.body;
|
|
495
|
-
break;
|
|
496
|
-
default:
|
|
497
|
-
emptyData = {};
|
|
498
|
-
break;
|
|
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
|
-
//#region src/oclif/connected-agent-profile.ts
|
|
603
|
-
const AGENT_PROFILE_ENV = "PRIMITIVE_AGENT_PROFILE";
|
|
604
|
-
function parsePresenceProfile(value, owner) {
|
|
605
|
-
const row = mailObject(value, [
|
|
606
|
-
"protocol",
|
|
607
|
-
"version",
|
|
608
|
-
"authentication_profile",
|
|
609
|
-
"return_address"
|
|
610
|
-
]);
|
|
611
|
-
if (row.protocol !== "primitive.presence" || row.version !== 1 || row.authentication_profile !== "primitive-issued-v1" || mailAddress(row.return_address) !== owner) throw new AgentConnectionSetupError("The presence authentication profile is not supported.");
|
|
612
|
-
return {
|
|
613
|
-
protocol: "primitive.presence",
|
|
614
|
-
version: 1,
|
|
615
|
-
authentication_profile: "primitive-issued-v1",
|
|
616
|
-
return_address: owner
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
function supportedPresenceProfile(value, owner) {
|
|
620
|
-
if (value === void 0) return void 0;
|
|
621
|
-
try {
|
|
622
|
-
return parsePresenceProfile(value, owner);
|
|
623
|
-
} catch {
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
var AgentConnectionSetupError = class extends Error {};
|
|
628
|
-
function requireDefaultLoginProfile() {
|
|
629
|
-
if (process.env["PRIMITIVE_AGENT_PROFILE"]?.trim()) throw new AgentConnectionSetupError("This command manages the default OAuth login. Unset PRIMITIVE_AGENT_PROFILE before using it; the connected-agent profile is unchanged.");
|
|
630
|
-
}
|
|
631
|
-
function agentProfileName(value) {
|
|
632
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/.test(value)) throw new AgentConnectionSetupError("Agent profile must start with a letter or number and contain only letters, numbers, dots, underscores or hyphens (at most 63 characters).");
|
|
633
|
-
return value;
|
|
634
|
-
}
|
|
635
|
-
function connectedApiBaseUrl(value) {
|
|
636
|
-
if (value !== "https://api.primitive.dev/v1" && value !== "https://api.primitive-staging-1.com/v1") throw new AgentConnectionSetupError("Agent setup requires an official Primitive API origin.");
|
|
637
|
-
return value;
|
|
638
|
-
}
|
|
639
|
-
function agentProfilesDirectory(configDir) {
|
|
640
|
-
return join(configDir, "agent-connections");
|
|
641
|
-
}
|
|
642
|
-
function agentProfileDirectory(configDir, profileName) {
|
|
643
|
-
return join(agentProfilesDirectory(configDir), "profiles", agentProfileName(profileName));
|
|
644
|
-
}
|
|
645
|
-
function profilePath(configDir, profileName) {
|
|
646
|
-
return join(agentProfileDirectory(configDir, profileName), "connection.json");
|
|
647
|
-
}
|
|
648
|
-
function parseConnectedAgentProfile(value) {
|
|
649
|
-
try {
|
|
650
|
-
const keys = [
|
|
651
|
-
"version",
|
|
652
|
-
"auth_method",
|
|
653
|
-
"api_key",
|
|
654
|
-
"api_base_url",
|
|
655
|
-
"org_id",
|
|
656
|
-
"agent_address",
|
|
657
|
-
"owner_address",
|
|
658
|
-
"invitation_hash",
|
|
659
|
-
"created_at"
|
|
660
|
-
];
|
|
661
|
-
const has = (key) => Boolean(value && typeof value === "object" && Object.hasOwn(value, key));
|
|
662
|
-
const row = mailObject(value, [
|
|
663
|
-
...keys,
|
|
664
|
-
...has("presence_profile") ? ["presence_profile"] : [],
|
|
665
|
-
...has("owner_member_address") ? ["owner_member_address"] : []
|
|
666
|
-
]);
|
|
667
|
-
const apiKey = mailString(row.api_key, 4096);
|
|
668
|
-
const invitationHash = mailString(row.invitation_hash, 64);
|
|
669
|
-
if (row.version !== 1 || row.auth_method !== "agent_connection" || !apiKey.startsWith("pconn_") || /\s/.test(apiKey) || !/^[a-f0-9]{64}$/.test(invitationHash)) throw new Error();
|
|
670
|
-
const presence = supportedPresenceProfile(row.presence_profile, mailAddress(row.owner_address));
|
|
671
|
-
const ownerMember = has("owner_member_address") ? parseOwnerMemberAddress(row.owner_member_address, mailAddress(row.owner_address), mailAddress(row.agent_address)) : void 0;
|
|
672
|
-
return {
|
|
673
|
-
version: 1,
|
|
674
|
-
auth_method: "agent_connection",
|
|
675
|
-
api_key: apiKey,
|
|
676
|
-
api_base_url: connectedApiBaseUrl(row.api_base_url),
|
|
677
|
-
org_id: mailId(row.org_id),
|
|
678
|
-
agent_address: mailAddress(row.agent_address),
|
|
679
|
-
owner_address: mailAddress(row.owner_address),
|
|
680
|
-
...ownerMember === void 0 ? {} : { owner_member_address: ownerMember },
|
|
681
|
-
invitation_hash: invitationHash,
|
|
682
|
-
created_at: mailTime(row.created_at),
|
|
683
|
-
...presence === void 0 ? {} : { presence_profile: presence }
|
|
684
|
-
};
|
|
685
|
-
} catch {
|
|
686
|
-
throw new AgentConnectionSetupError("Saved agent profile is invalid. Preserve its private files and request a fresh setup invitation.");
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
function loadConnectedAgentProfile(configDir, profileName) {
|
|
690
|
-
agentProfileName(profileName);
|
|
691
|
-
try {
|
|
692
|
-
privateMailDirectory(agentProfilesDirectory(configDir));
|
|
693
|
-
privateMailDirectory(join(agentProfilesDirectory(configDir), "profiles"));
|
|
694
|
-
privateMailDirectory(agentProfileDirectory(configDir, profileName));
|
|
695
|
-
const value = readMailJson(profilePath(configDir, profileName));
|
|
696
|
-
return value === null ? null : parseConnectedAgentProfile(value);
|
|
697
|
-
} catch (error) {
|
|
698
|
-
if (error.code === "ENOENT") return null;
|
|
699
|
-
throw new AgentConnectionSetupError("Cannot read the private agent profile. Check its ownership and permissions without exposing its contents.");
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
function saveConnectedAgentProfile(configDir, profileName, profile) {
|
|
703
|
-
const validated = parseConnectedAgentProfile(profile);
|
|
704
|
-
privateMailDirectory(agentProfilesDirectory(configDir), true);
|
|
705
|
-
privateMailDirectory(join(agentProfilesDirectory(configDir), "profiles"), true);
|
|
706
|
-
privateMailDirectory(agentProfileDirectory(configDir, profileName), true);
|
|
707
|
-
writeMailJson(profilePath(configDir, profileName), validated);
|
|
708
|
-
}
|
|
709
|
-
function connectedAgentIdentity(profileName, profile) {
|
|
710
|
-
return {
|
|
711
|
-
profileName,
|
|
712
|
-
orgId: profile.org_id,
|
|
713
|
-
agentAddress: profile.agent_address,
|
|
714
|
-
ownerAddress: profile.owner_address,
|
|
715
|
-
ownerMemberAddress: profile.owner_member_address ?? null,
|
|
716
|
-
apiBaseUrl: profile.api_base_url
|
|
717
|
-
};
|
|
718
|
-
}
|
|
719
|
-
/**
|
|
720
|
-
* Validates a server-reported owner personal address. It is a person's
|
|
721
|
-
* mailbox, so it can never be the control sender or the agent itself.
|
|
722
|
-
*/
|
|
723
|
-
function parseOwnerMemberAddress(value, ownerAddress, agentAddress) {
|
|
724
|
-
if (value === null) return null;
|
|
725
|
-
const address = mailAddress(value);
|
|
726
|
-
if (address === ownerAddress || address === agentAddress) throw new Error();
|
|
727
|
-
return address;
|
|
728
|
-
}
|
|
729
|
-
//#endregion
|
|
730
|
-
export { agentProfilesDirectory as a, loadConnectedAgentProfile as c, requireDefaultLoginProfile as d, saveConnectedAgentProfile as f, agentProfileName as i, parseConnectedAgentProfile as l, createConfig as m, AgentConnectionSetupError as n, connectedAgentIdentity as o, createClient as p, agentProfileDirectory as r, connectedApiBaseUrl as s, AGENT_PROFILE_ENV as t, parseOwnerMemberAddress as u };
|