@getpaseo/cli 0.3.1 → 0.4.0-beta.2
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/dist/cli.js +0 -5
- package/dist/commands/hub/connect.d.ts +1 -1
- package/dist/commands/hub/deploy-bundle.d.ts +16 -0
- package/dist/commands/hub/deploy-bundle.js +248 -0
- package/dist/commands/hub/deploy.d.ts +3 -2
- package/dist/commands/hub/deploy.js +17 -10
- package/dist/commands/hub/hub-client/index.d.ts +18 -0
- package/dist/commands/hub/hub-client/index.js +88 -0
- package/dist/commands/hub/{client.d.ts → hub-client/internal/contracts.d.ts} +16 -22
- package/dist/commands/hub/hub-client/internal/contracts.js +47 -0
- package/dist/commands/hub/hub-client/internal/problem.d.ts +3 -0
- package/dist/commands/hub/hub-client/internal/problem.js +72 -0
- package/dist/commands/hub/hub-client/internal/transport.d.ts +15 -0
- package/dist/commands/hub/hub-client/internal/transport.js +30 -0
- package/dist/commands/hub/index.d.ts +1 -1
- package/dist/commands/hub/index.js +1 -1
- package/dist/commands/hub/login-flow.d.ts +1 -1
- package/dist/commands/hub/projects.d.ts +1 -1
- package/dist/commands/provider/diagnostic.d.ts +12 -0
- package/dist/commands/provider/diagnostic.js +31 -0
- package/dist/commands/provider/index.js +5 -0
- package/dist/commands/workspace/index.js +10 -0
- package/dist/commands/workspace/rename.d.ts +22 -0
- package/dist/commands/workspace/rename.js +61 -0
- package/package.json +4 -4
- package/dist/commands/chat/create.d.ts +0 -9
- package/dist/commands/chat/create.js +0 -23
- package/dist/commands/chat/delete.d.ts +0 -6
- package/dist/commands/chat/delete.js +0 -20
- package/dist/commands/chat/index.d.ts +0 -3
- package/dist/commands/chat/index.js +0 -47
- package/dist/commands/chat/inspect.d.ts +0 -6
- package/dist/commands/chat/inspect.js +0 -20
- package/dist/commands/chat/ls.d.ts +0 -6
- package/dist/commands/chat/ls.js +0 -20
- package/dist/commands/chat/post.d.ts +0 -9
- package/dist/commands/chat/post.js +0 -28
- package/dist/commands/chat/read.d.ts +0 -11
- package/dist/commands/chat/read.js +0 -40
- package/dist/commands/chat/schema.d.ts +0 -36
- package/dist/commands/chat/schema.js +0 -81
- package/dist/commands/chat/shared.d.ts +0 -19
- package/dist/commands/chat/shared.js +0 -118
- package/dist/commands/chat/wait.d.ts +0 -9
- package/dist/commands/chat/wait.js +0 -45
- package/dist/commands/hub/client.js +0 -234
- package/dist/commands/hub/deploy-input.d.ts +0 -17
- package/dist/commands/hub/deploy-input.js +0 -264
- package/dist/commands/loop/index.d.ts +0 -3
- package/dist/commands/loop/index.js +0 -18
- package/dist/commands/loop/inspect.d.ts +0 -13
- package/dist/commands/loop/inspect.js +0 -100
- package/dist/commands/loop/logs.d.ts +0 -8
- package/dist/commands/loop/logs.js +0 -69
- package/dist/commands/loop/ls.d.ts +0 -18
- package/dist/commands/loop/ls.js +0 -62
- package/dist/commands/loop/run.d.ts +0 -30
- package/dist/commands/loop/run.js +0 -162
- package/dist/commands/loop/stop.d.ts +0 -15
- package/dist/commands/loop/stop.js +0 -56
- package/dist/commands/loop/types.d.ts +0 -138
- package/dist/commands/loop/types.js +0 -2
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { OutputSchema } from "../../output/index.js";
|
|
2
|
-
export interface ChatRoomRow {
|
|
3
|
-
name: string;
|
|
4
|
-
id: string;
|
|
5
|
-
purpose: string;
|
|
6
|
-
messages: number;
|
|
7
|
-
lastMessageAt: string;
|
|
8
|
-
}
|
|
9
|
-
export interface ChatMessageRow {
|
|
10
|
-
id: string;
|
|
11
|
-
author: string;
|
|
12
|
-
authorName: string | null;
|
|
13
|
-
createdAt: string;
|
|
14
|
-
replyTo: string;
|
|
15
|
-
mentionAgentIds: string[];
|
|
16
|
-
mentionLabels: string[];
|
|
17
|
-
body: string;
|
|
18
|
-
}
|
|
19
|
-
export declare const chatRoomSchema: OutputSchema<ChatRoomRow>;
|
|
20
|
-
export declare const chatMessageSchema: OutputSchema<ChatMessageRow>;
|
|
21
|
-
export declare function toChatRoomRow(room: {
|
|
22
|
-
id: string;
|
|
23
|
-
name: string;
|
|
24
|
-
purpose: string | null;
|
|
25
|
-
messageCount: number;
|
|
26
|
-
lastMessageAt: string | null;
|
|
27
|
-
}): ChatRoomRow;
|
|
28
|
-
export declare function toChatMessageRow(message: {
|
|
29
|
-
id: string;
|
|
30
|
-
authorAgentId: string;
|
|
31
|
-
createdAt: string;
|
|
32
|
-
replyToMessageId: string | null;
|
|
33
|
-
mentionAgentIds: string[];
|
|
34
|
-
body: string;
|
|
35
|
-
}): ChatMessageRow;
|
|
36
|
-
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
export const chatRoomSchema = {
|
|
2
|
-
idField: "id",
|
|
3
|
-
columns: [
|
|
4
|
-
{ header: "NAME", field: "name", width: 22 },
|
|
5
|
-
{ header: "ID", field: "id", width: 36 },
|
|
6
|
-
{ header: "PURPOSE", field: "purpose", width: 30 },
|
|
7
|
-
{ header: "MESSAGES", field: "messages", width: 10, align: "right" },
|
|
8
|
-
{ header: "LAST MESSAGE", field: "lastMessageAt", width: 24 },
|
|
9
|
-
],
|
|
10
|
-
};
|
|
11
|
-
export const chatMessageSchema = {
|
|
12
|
-
idField: "id",
|
|
13
|
-
columns: [
|
|
14
|
-
{ header: "ID", field: "id", width: 36 },
|
|
15
|
-
{ header: "AUTHOR", field: "author", width: 16 },
|
|
16
|
-
{ header: "AUTHOR NAME", field: (row) => row.authorName ?? "-", width: 20 },
|
|
17
|
-
{ header: "CREATED", field: "createdAt", width: 24 },
|
|
18
|
-
{ header: "REPLY TO", field: "replyTo", width: 36 },
|
|
19
|
-
{ header: "MENTIONS", field: (row) => row.mentionLabels.join(", ") || "-", width: 24 },
|
|
20
|
-
{ header: "MESSAGE", field: "body", width: 60 },
|
|
21
|
-
],
|
|
22
|
-
renderHuman: renderChatTranscript,
|
|
23
|
-
};
|
|
24
|
-
function renderChatTranscript(result, _options) {
|
|
25
|
-
const data = result.type === "list" ? result.data : [result.data];
|
|
26
|
-
if (data.length === 0) {
|
|
27
|
-
return "";
|
|
28
|
-
}
|
|
29
|
-
return data.map(renderChatMessageBlock).join("\n\n");
|
|
30
|
-
}
|
|
31
|
-
function renderChatMessageBlock(message) {
|
|
32
|
-
const authorLabel = message.authorName
|
|
33
|
-
? `${message.authorName} (${message.author})`
|
|
34
|
-
: message.author;
|
|
35
|
-
const lines = [
|
|
36
|
-
`┌─ ${authorLabel} ── ${formatTimestamp(message.createdAt)} ── [msg ${message.id}]`,
|
|
37
|
-
];
|
|
38
|
-
if (message.replyTo !== "-") {
|
|
39
|
-
lines.push(`│ reply-to: msg ${message.replyTo}`);
|
|
40
|
-
}
|
|
41
|
-
if (message.mentionLabels.length > 0) {
|
|
42
|
-
lines.push(`│ mentions: ${message.mentionLabels.join(", ")}`);
|
|
43
|
-
}
|
|
44
|
-
lines.push("│");
|
|
45
|
-
const bodyLines = message.body.split(/\r?\n/);
|
|
46
|
-
for (const line of bodyLines) {
|
|
47
|
-
lines.push(`│ ${line}`);
|
|
48
|
-
}
|
|
49
|
-
lines.push("│");
|
|
50
|
-
lines.push("└─");
|
|
51
|
-
return lines.join("\n");
|
|
52
|
-
}
|
|
53
|
-
function formatTimestamp(input) {
|
|
54
|
-
const date = new Date(input);
|
|
55
|
-
if (Number.isNaN(date.getTime())) {
|
|
56
|
-
return input;
|
|
57
|
-
}
|
|
58
|
-
return date.toISOString().replace("T", " ").replace(".000Z", "Z");
|
|
59
|
-
}
|
|
60
|
-
export function toChatRoomRow(room) {
|
|
61
|
-
return {
|
|
62
|
-
id: room.id,
|
|
63
|
-
name: room.name,
|
|
64
|
-
purpose: room.purpose ?? "-",
|
|
65
|
-
messages: room.messageCount,
|
|
66
|
-
lastMessageAt: room.lastMessageAt ?? "-",
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
export function toChatMessageRow(message) {
|
|
70
|
-
return {
|
|
71
|
-
id: message.id,
|
|
72
|
-
author: message.authorAgentId,
|
|
73
|
-
authorName: null,
|
|
74
|
-
createdAt: message.createdAt,
|
|
75
|
-
replyTo: message.replyToMessageId ?? "-",
|
|
76
|
-
mentionAgentIds: message.mentionAgentIds,
|
|
77
|
-
mentionLabels: message.mentionAgentIds,
|
|
78
|
-
body: message.body,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { connectToDaemon } from "../../utils/client.js";
|
|
2
|
-
import type { CommandError, CommandOptions } from "../../output/index.js";
|
|
3
|
-
import type { ChatMessageRow } from "./schema.js";
|
|
4
|
-
export interface ChatCommandOptions extends CommandOptions {
|
|
5
|
-
host?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function connectChatClient(host?: string): Promise<{
|
|
8
|
-
client: import("@getpaseo/client/internal/daemon-client").DaemonClient;
|
|
9
|
-
daemonHost: string;
|
|
10
|
-
}>;
|
|
11
|
-
export declare function attachAgentNamesToMessages(client: Awaited<ReturnType<typeof connectToDaemon>>, messages: ChatMessageRow[], options?: {
|
|
12
|
-
timeout?: number;
|
|
13
|
-
bestEffort?: boolean;
|
|
14
|
-
}): Promise<ChatMessageRow[]>;
|
|
15
|
-
export declare function toChatCommandError(code: string, action: string, err: unknown): CommandError;
|
|
16
|
-
export declare function parseSinceValue(input?: string): string | undefined;
|
|
17
|
-
export declare function parseTimeoutMs(input?: string): number | undefined;
|
|
18
|
-
export declare function resolveChatAuthorAgentId(): string;
|
|
19
|
-
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
|
|
2
|
-
import { parseDuration } from "../../utils/duration.js";
|
|
3
|
-
export async function connectChatClient(host) {
|
|
4
|
-
const daemonHost = getDaemonHost({ host });
|
|
5
|
-
try {
|
|
6
|
-
const client = await connectToDaemon({ host });
|
|
7
|
-
return { client, daemonHost };
|
|
8
|
-
}
|
|
9
|
-
catch (err) {
|
|
10
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
11
|
-
const error = {
|
|
12
|
-
code: "DAEMON_NOT_RUNNING",
|
|
13
|
-
message: `Cannot connect to daemon at ${daemonHost}: ${message}`,
|
|
14
|
-
details: "Start the daemon with: paseo daemon start",
|
|
15
|
-
};
|
|
16
|
-
throw error;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export async function attachAgentNamesToMessages(client, messages, options = {}) {
|
|
20
|
-
const agentIds = new Set();
|
|
21
|
-
for (const message of messages) {
|
|
22
|
-
agentIds.add(message.author);
|
|
23
|
-
for (const mentionId of message.mentionAgentIds) {
|
|
24
|
-
agentIds.add(mentionId);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (agentIds.size === 0) {
|
|
28
|
-
return messages;
|
|
29
|
-
}
|
|
30
|
-
let payload;
|
|
31
|
-
try {
|
|
32
|
-
payload = await client.fetchAgents({
|
|
33
|
-
filter: { includeArchived: true },
|
|
34
|
-
...(typeof options.timeout === "number" ? { timeout: options.timeout } : {}),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
if (options.bestEffort) {
|
|
39
|
-
return messages;
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
const agentNames = new Map();
|
|
44
|
-
for (const entry of payload.entries) {
|
|
45
|
-
const title = entry.agent.title?.trim();
|
|
46
|
-
if (title) {
|
|
47
|
-
agentNames.set(entry.agent.id, title);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return messages.map((message) => ({
|
|
51
|
-
...message,
|
|
52
|
-
authorName: agentNames.get(message.author) ?? null,
|
|
53
|
-
mentionLabels: message.mentionAgentIds.map((agentId) => {
|
|
54
|
-
const name = agentNames.get(agentId);
|
|
55
|
-
return name ? `${name} (${agentId})` : agentId;
|
|
56
|
-
}),
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
export function toChatCommandError(code, action, err) {
|
|
60
|
-
if (err && typeof err === "object" && "code" in err && "message" in err) {
|
|
61
|
-
return err;
|
|
62
|
-
}
|
|
63
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
64
|
-
const rpcCode = typeof err === "object" && err !== null && "code" in err && typeof err.code === "string"
|
|
65
|
-
? err.code
|
|
66
|
-
: undefined;
|
|
67
|
-
return {
|
|
68
|
-
code: rpcCode ?? code,
|
|
69
|
-
message: `Failed to ${action}: ${message}`,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
export function parseSinceValue(input) {
|
|
73
|
-
if (!input) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
const durationMs = parseDuration(input);
|
|
78
|
-
return new Date(Date.now() - durationMs).toISOString();
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
const timestamp = new Date(input);
|
|
82
|
-
if (Number.isNaN(timestamp.getTime())) {
|
|
83
|
-
const error = {
|
|
84
|
-
code: "INVALID_SINCE",
|
|
85
|
-
message: "Invalid --since value",
|
|
86
|
-
details: "Use a duration like 10m or an ISO timestamp.",
|
|
87
|
-
};
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
return timestamp.toISOString();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
export function parseTimeoutMs(input) {
|
|
94
|
-
if (!input) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
const timeoutMs = parseDuration(input);
|
|
99
|
-
if (timeoutMs <= 0) {
|
|
100
|
-
throw new Error("Timeout must be positive");
|
|
101
|
-
}
|
|
102
|
-
return timeoutMs;
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
106
|
-
const error = {
|
|
107
|
-
code: "INVALID_TIMEOUT",
|
|
108
|
-
message: "Invalid timeout value",
|
|
109
|
-
details: message,
|
|
110
|
-
};
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
export function resolveChatAuthorAgentId() {
|
|
115
|
-
const agentId = process.env.PASEO_AGENT_ID?.trim();
|
|
116
|
-
return agentId && agentId.length > 0 ? agentId : "manual";
|
|
117
|
-
}
|
|
118
|
-
//# sourceMappingURL=shared.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Command } from "commander";
|
|
2
|
-
import type { ListResult } from "../../output/index.js";
|
|
3
|
-
import { type ChatCommandOptions } from "./shared.js";
|
|
4
|
-
import { type ChatMessageRow } from "./schema.js";
|
|
5
|
-
export interface ChatWaitOptions extends ChatCommandOptions {
|
|
6
|
-
timeout?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function runWaitCommand(room: string, options: ChatWaitOptions, _command: Command): Promise<ListResult<ChatMessageRow>>;
|
|
9
|
-
//# sourceMappingURL=wait.d.ts.map
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { attachAgentNamesToMessages, connectChatClient, parseTimeoutMs, toChatCommandError, } from "./shared.js";
|
|
2
|
-
import { chatMessageSchema, toChatMessageRow } from "./schema.js";
|
|
3
|
-
const CHAT_WAIT_PREFLIGHT_TIMEOUT_MS = 2000;
|
|
4
|
-
export async function runWaitCommand(room, options, _command) {
|
|
5
|
-
const timeoutMs = parseTimeoutMs(options.timeout);
|
|
6
|
-
const { client } = await connectChatClient(options.host);
|
|
7
|
-
const deadline = typeof timeoutMs === "number" ? Date.now() + timeoutMs : null;
|
|
8
|
-
const hasExplicitTimeout = deadline !== null;
|
|
9
|
-
const remainingTimeoutMs = () => deadline === null ? undefined : Math.max(1, deadline - Date.now());
|
|
10
|
-
try {
|
|
11
|
-
const latest = await client.readChatMessages({
|
|
12
|
-
room,
|
|
13
|
-
limit: 1,
|
|
14
|
-
...(hasExplicitTimeout
|
|
15
|
-
? {
|
|
16
|
-
timeout: Math.min(remainingTimeoutMs() ?? 1, CHAT_WAIT_PREFLIGHT_TIMEOUT_MS),
|
|
17
|
-
}
|
|
18
|
-
: {}),
|
|
19
|
-
});
|
|
20
|
-
const afterMessageId = latest.messages[0]?.id;
|
|
21
|
-
const payload = await client.waitForChatMessages({
|
|
22
|
-
room,
|
|
23
|
-
afterMessageId,
|
|
24
|
-
timeoutMs: remainingTimeoutMs() ?? timeoutMs,
|
|
25
|
-
});
|
|
26
|
-
const messages = await attachAgentNamesToMessages(client, payload.messages.map(toChatMessageRow), hasExplicitTimeout
|
|
27
|
-
? {
|
|
28
|
-
timeout: remainingTimeoutMs(),
|
|
29
|
-
bestEffort: true,
|
|
30
|
-
}
|
|
31
|
-
: {});
|
|
32
|
-
return {
|
|
33
|
-
type: "list",
|
|
34
|
-
data: messages,
|
|
35
|
-
schema: chatMessageSchema,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
throw toChatCommandError("CHAT_WAIT_FAILED", "wait for chat messages", err);
|
|
40
|
-
}
|
|
41
|
-
finally {
|
|
42
|
-
await client.close().catch(() => { });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=wait.js.map
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { HubCommandError } from "./error.js";
|
|
3
|
-
const activationUrlSchema = z.url({ protocol: /^https?$/u });
|
|
4
|
-
const authorizationSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
deviceCode: z.string().min(32),
|
|
7
|
-
userCode: z.string().min(1),
|
|
8
|
-
verificationUri: activationUrlSchema,
|
|
9
|
-
verificationUriComplete: activationUrlSchema,
|
|
10
|
-
expiresAt: z.string().datetime(),
|
|
11
|
-
interval: z.number().int().min(1),
|
|
12
|
-
})
|
|
13
|
-
.strict();
|
|
14
|
-
const authorizationPollSchema = z.discriminatedUnion("status", [
|
|
15
|
-
z.object({ status: z.literal("pending"), interval: z.number().int().min(1) }).strict(),
|
|
16
|
-
z.object({ status: z.literal("slow_down"), interval: z.number().int().min(1) }).strict(),
|
|
17
|
-
z
|
|
18
|
-
.object({
|
|
19
|
-
status: z.literal("authorized"),
|
|
20
|
-
interval: z.number().int().min(1),
|
|
21
|
-
credential: z.string().min(32),
|
|
22
|
-
organizationId: z.string().min(1),
|
|
23
|
-
})
|
|
24
|
-
.strict(),
|
|
25
|
-
z.object({ status: z.literal("denied"), interval: z.number().int().min(1) }).strict(),
|
|
26
|
-
z.object({ status: z.literal("expired"), interval: z.number().int().min(1) }).strict(),
|
|
27
|
-
z.object({ status: z.literal("disclosed"), interval: z.number().int().min(1) }).strict(),
|
|
28
|
-
z.object({ status: z.literal("retry_later") }).strict(),
|
|
29
|
-
]);
|
|
30
|
-
const projectSchema = z
|
|
31
|
-
.object({ id: z.string().uuid(), slug: z.string().min(1), name: z.string().min(1) })
|
|
32
|
-
.strict();
|
|
33
|
-
const projectsResponseSchema = z.object({ projects: z.array(projectSchema) }).strict();
|
|
34
|
-
const installResponseSchema = z
|
|
35
|
-
.object({
|
|
36
|
-
projectSlug: z.string().min(1),
|
|
37
|
-
version: z.number().int().positive(),
|
|
38
|
-
versionId: z.string().uuid(),
|
|
39
|
-
active: z.literal(true),
|
|
40
|
-
})
|
|
41
|
-
.strict();
|
|
42
|
-
const validationResponseSchema = z
|
|
43
|
-
.object({ projectSlug: z.string().min(1), valid: z.literal(true) })
|
|
44
|
-
.strict();
|
|
45
|
-
const enrollmentTokenSchema = z
|
|
46
|
-
.object({ token: z.string().min(32), expiresAt: z.string().datetime() })
|
|
47
|
-
.strict();
|
|
48
|
-
const issuePathSchema = z.union([z.string(), z.array(z.union([z.string(), z.number()]))]);
|
|
49
|
-
const fieldIssueSchema = z.object({
|
|
50
|
-
field: z.string().optional(),
|
|
51
|
-
path: issuePathSchema.optional(),
|
|
52
|
-
message: z.string(),
|
|
53
|
-
});
|
|
54
|
-
const problemSchema = z.object({
|
|
55
|
-
type: z.string().optional(),
|
|
56
|
-
title: z.string().optional(),
|
|
57
|
-
status: z.number().int().optional(),
|
|
58
|
-
detail: z.string().optional(),
|
|
59
|
-
instance: z.string().optional(),
|
|
60
|
-
errors: z
|
|
61
|
-
.union([z.array(fieldIssueSchema), z.record(z.string(), z.array(z.string()))])
|
|
62
|
-
.optional(),
|
|
63
|
-
issues: z.array(fieldIssueSchema).optional(),
|
|
64
|
-
});
|
|
65
|
-
export class HubHttpClient {
|
|
66
|
-
async startCliAuthorization(origin) {
|
|
67
|
-
return this.request({
|
|
68
|
-
origin,
|
|
69
|
-
path: "/api/v1/cli-authorizations",
|
|
70
|
-
method: "POST",
|
|
71
|
-
body: {},
|
|
72
|
-
successStatus: 201,
|
|
73
|
-
schema: authorizationSchema,
|
|
74
|
-
failureMessage: "Hub CLI login could not be started",
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
async pollCliAuthorization(origin, deviceCode, timeoutMilliseconds) {
|
|
78
|
-
try {
|
|
79
|
-
return await this.request({
|
|
80
|
-
origin,
|
|
81
|
-
path: "/api/v1/cli-authorizations/poll",
|
|
82
|
-
method: "POST",
|
|
83
|
-
body: { deviceCode },
|
|
84
|
-
successStatus: 200,
|
|
85
|
-
schema: authorizationPollSchema,
|
|
86
|
-
timeoutMilliseconds,
|
|
87
|
-
failureMessage: "Hub CLI login polling failed",
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
if (error instanceof HubCommandError && error.code === "HUB_NETWORK_ERROR") {
|
|
92
|
-
return { status: "retry_later" };
|
|
93
|
-
}
|
|
94
|
-
throw error;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async listProjects(origin, apiKey) {
|
|
98
|
-
const response = await this.request({
|
|
99
|
-
origin,
|
|
100
|
-
path: "/api/v1/projects",
|
|
101
|
-
method: "GET",
|
|
102
|
-
apiKey,
|
|
103
|
-
successStatus: 200,
|
|
104
|
-
schema: projectsResponseSchema,
|
|
105
|
-
failureMessage: "Hub project listing failed",
|
|
106
|
-
});
|
|
107
|
-
return response.projects;
|
|
108
|
-
}
|
|
109
|
-
installConfiguration(input) {
|
|
110
|
-
return this.request({
|
|
111
|
-
origin: input.origin,
|
|
112
|
-
path: "/api/v1/configurations/install",
|
|
113
|
-
method: "POST",
|
|
114
|
-
apiKey: input.apiKey,
|
|
115
|
-
body: configurationBody(input),
|
|
116
|
-
successStatus: 201,
|
|
117
|
-
schema: installResponseSchema,
|
|
118
|
-
failureMessage: "Hub deployment failed",
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
validateConfiguration(input) {
|
|
122
|
-
return this.request({
|
|
123
|
-
origin: input.origin,
|
|
124
|
-
path: "/api/v1/configurations/validate",
|
|
125
|
-
method: "POST",
|
|
126
|
-
apiKey: input.apiKey,
|
|
127
|
-
body: configurationBody(input),
|
|
128
|
-
successStatus: 200,
|
|
129
|
-
schema: validationResponseSchema,
|
|
130
|
-
failureMessage: "Hub configuration validation failed",
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
async issueEnrollmentToken(origin, apiKey) {
|
|
134
|
-
const response = await this.request({
|
|
135
|
-
origin,
|
|
136
|
-
path: "/api/v1/daemons/enrollment-tokens",
|
|
137
|
-
method: "POST",
|
|
138
|
-
apiKey,
|
|
139
|
-
successStatus: 201,
|
|
140
|
-
schema: enrollmentTokenSchema,
|
|
141
|
-
failureMessage: "Hub daemon enrollment authorization failed",
|
|
142
|
-
});
|
|
143
|
-
return response.token;
|
|
144
|
-
}
|
|
145
|
-
async request(input) {
|
|
146
|
-
const signal = AbortSignal.timeout(input.timeoutMilliseconds ?? 15000);
|
|
147
|
-
let response;
|
|
148
|
-
try {
|
|
149
|
-
response = await fetch(`${input.origin}${input.path}`, {
|
|
150
|
-
method: input.method,
|
|
151
|
-
headers: {
|
|
152
|
-
...(input.apiKey === undefined ? {} : { authorization: `Bearer ${input.apiKey}` }),
|
|
153
|
-
...(input.body === undefined ? {} : { "content-type": "application/json" }),
|
|
154
|
-
},
|
|
155
|
-
...(input.body === undefined ? {} : { body: JSON.stringify(input.body) }),
|
|
156
|
-
signal,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
catch {
|
|
160
|
-
throw new HubCommandError("HUB_NETWORK_ERROR", `Could not reach Paseo Hub at ${input.origin}. Check the Hub URL and network connection.`);
|
|
161
|
-
}
|
|
162
|
-
if (response.status !== input.successStatus) {
|
|
163
|
-
throw await requestFailure(response, input.failureMessage, input.apiKey);
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
return input.schema.parse(await response.json());
|
|
167
|
-
}
|
|
168
|
-
catch {
|
|
169
|
-
throw new HubCommandError("HUB_INVALID_RESPONSE", "Hub returned a malformed response.");
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function configurationBody(input) {
|
|
174
|
-
return {
|
|
175
|
-
projectSlug: input.projectSlug,
|
|
176
|
-
yaml: input.yaml,
|
|
177
|
-
...(input.partials === undefined || input.partials.length === 0
|
|
178
|
-
? {}
|
|
179
|
-
: { partials: input.partials }),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
async function requestFailure(response, failureMessage, apiKey) {
|
|
183
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
184
|
-
if (!contentType.toLowerCase().includes("application/problem+json")) {
|
|
185
|
-
return new HubCommandError("HUB_REQUEST_FAILED", `${failureMessage} with HTTP ${response.status}.`);
|
|
186
|
-
}
|
|
187
|
-
let body;
|
|
188
|
-
try {
|
|
189
|
-
body = await response.json();
|
|
190
|
-
}
|
|
191
|
-
catch {
|
|
192
|
-
return new HubCommandError("HUB_INVALID_RESPONSE", `Hub returned malformed problem details for HTTP ${response.status}.`);
|
|
193
|
-
}
|
|
194
|
-
const parsed = problemSchema.safeParse(body);
|
|
195
|
-
if (!parsed.success ||
|
|
196
|
-
(parsed.data.status !== undefined && parsed.data.status !== response.status)) {
|
|
197
|
-
return new HubCommandError("HUB_INVALID_RESPONSE", `Hub returned nonconforming problem details for HTTP ${response.status}.`);
|
|
198
|
-
}
|
|
199
|
-
const title = parsed.data.title ?? `${failureMessage} with HTTP ${response.status}`;
|
|
200
|
-
const message = parsed.data.detail === undefined ? title : `${title}: ${parsed.data.detail}`;
|
|
201
|
-
const details = formatFieldIssues(parsed.data.errors, parsed.data.issues);
|
|
202
|
-
const code = response.status === 422 ? "HUB_VALIDATION_FAILED" : "HUB_REQUEST_FAILED";
|
|
203
|
-
return new HubCommandError(code, redactSecret(message, apiKey), details === undefined ? undefined : redactSecret(details, apiKey));
|
|
204
|
-
}
|
|
205
|
-
function formatFieldIssues(errors, issues) {
|
|
206
|
-
const fieldIssues = Array.isArray(errors) ? errors : issues;
|
|
207
|
-
if (fieldIssues !== undefined) {
|
|
208
|
-
const lines = fieldIssues.map((issue) => {
|
|
209
|
-
const field = issue.field ?? formatIssuePath(issue.path);
|
|
210
|
-
return field === undefined ? issue.message : `${field}: ${issue.message}`;
|
|
211
|
-
});
|
|
212
|
-
return lines.length === 0 ? undefined : lines.join("\n");
|
|
213
|
-
}
|
|
214
|
-
if (errors === undefined)
|
|
215
|
-
return undefined;
|
|
216
|
-
const lines = Object.entries(errors).flatMap(([field, messages]) => messages.map((message) => `${field}: ${message}`));
|
|
217
|
-
return lines.length === 0 ? undefined : lines.join("\n");
|
|
218
|
-
}
|
|
219
|
-
function formatIssuePath(path) {
|
|
220
|
-
if (path === undefined || typeof path === "string")
|
|
221
|
-
return path;
|
|
222
|
-
let formatted = "";
|
|
223
|
-
for (const segment of path) {
|
|
224
|
-
if (typeof segment === "number")
|
|
225
|
-
formatted += `[${segment}]`;
|
|
226
|
-
else
|
|
227
|
-
formatted += formatted.length === 0 ? segment : `.${segment}`;
|
|
228
|
-
}
|
|
229
|
-
return formatted || undefined;
|
|
230
|
-
}
|
|
231
|
-
function redactSecret(value, secret) {
|
|
232
|
-
return secret === undefined ? value : value.split(secret).join("[redacted]");
|
|
233
|
-
}
|
|
234
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface HubDeployPartial {
|
|
2
|
-
path: string;
|
|
3
|
-
content: string;
|
|
4
|
-
}
|
|
5
|
-
export interface HubDeployInput {
|
|
6
|
-
projectSlug: string;
|
|
7
|
-
yaml: string;
|
|
8
|
-
partials?: readonly HubDeployPartial[];
|
|
9
|
-
}
|
|
10
|
-
interface ResolveHubDeployInput {
|
|
11
|
-
cwd: string;
|
|
12
|
-
file?: string;
|
|
13
|
-
project?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function resolveHubDeployInput(input: ResolveHubDeployInput): Promise<HubDeployInput>;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=deploy-input.d.ts.map
|