@agentsky/sky 2.10.0 → 2.12.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/dist/chunk-7LUCHBX6.js +168 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-RF5JICNX.js +54 -0
- package/dist/{chunk-5QRKU3BR.js → chunk-XXDQKVPS.js} +2690 -2566
- package/dist/harness-connect-DUC7GIBL.js +102 -0
- package/dist/index.js +862 -328
- package/dist/products.d.ts +9 -0
- package/dist/products.js +2 -1
- package/dist/{src-RYECJN5I.js → src-S777KCS5.js} +21 -2
- package/dist/trace-UJTFSXNM.js +367 -0
- package/dist/trace-library-474QJTAZ.js +710 -0
- package/dist/worker-6Q4K4HZW.js +190 -0
- package/package.json +4 -3
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
USER_AGENT,
|
|
3
|
+
apiBase,
|
|
4
|
+
apiToken,
|
|
5
|
+
currentUniverse
|
|
6
|
+
} from "./chunk-RF5JICNX.js";
|
|
7
|
+
|
|
8
|
+
// src/api.ts
|
|
9
|
+
var ApiError = class extends Error {
|
|
10
|
+
constructor(status, code, message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
status;
|
|
16
|
+
code;
|
|
17
|
+
};
|
|
18
|
+
function authHeaders() {
|
|
19
|
+
const token = apiToken();
|
|
20
|
+
if (!token) {
|
|
21
|
+
throw new ApiError(401, "not_logged_in", "not logged in \u2014 run `sky auth login`");
|
|
22
|
+
}
|
|
23
|
+
const headers = { authorization: `Bearer ${token}` };
|
|
24
|
+
const universe = currentUniverse();
|
|
25
|
+
if (universe) headers["x-universe"] = universe;
|
|
26
|
+
return headers;
|
|
27
|
+
}
|
|
28
|
+
async function parseError(res) {
|
|
29
|
+
let code = "http_error";
|
|
30
|
+
let message = `${res.status} ${res.statusText}`;
|
|
31
|
+
try {
|
|
32
|
+
const body = await res.json();
|
|
33
|
+
if (body.error?.message) {
|
|
34
|
+
code = body.error.code ?? code;
|
|
35
|
+
message = body.error.message;
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
throw new ApiError(res.status, code, message);
|
|
40
|
+
}
|
|
41
|
+
async function api(method, path, body, opts = {}) {
|
|
42
|
+
const res = await fetch(`${apiBase()}${path}`, {
|
|
43
|
+
method,
|
|
44
|
+
headers: {
|
|
45
|
+
"user-agent": USER_AGENT,
|
|
46
|
+
...opts.auth === false ? {} : authHeaders(),
|
|
47
|
+
...body !== void 0 ? { "content-type": "application/json" } : {},
|
|
48
|
+
...opts.idempotencyKey ? { "idempotency-key": opts.idempotencyKey } : {}
|
|
49
|
+
},
|
|
50
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
51
|
+
});
|
|
52
|
+
if (!res.ok) await parseError(res);
|
|
53
|
+
if (res.status === 204) return void 0;
|
|
54
|
+
return await res.json();
|
|
55
|
+
}
|
|
56
|
+
async function postEvents(sessionId, events, idempotencyKey) {
|
|
57
|
+
const res = await fetch(`${apiBase()}/sessions/${encodeURIComponent(sessionId)}/events`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: {
|
|
60
|
+
"user-agent": USER_AGENT,
|
|
61
|
+
...authHeaders(),
|
|
62
|
+
"content-type": "application/json",
|
|
63
|
+
...idempotencyKey ? { "idempotency-key": idempotencyKey } : {}
|
|
64
|
+
},
|
|
65
|
+
body: JSON.stringify({ events })
|
|
66
|
+
});
|
|
67
|
+
if (!res.ok) await parseError(res);
|
|
68
|
+
return await res.json();
|
|
69
|
+
}
|
|
70
|
+
async function uploadFile(bytes, filename, mediaType, expiresInSeconds) {
|
|
71
|
+
const form = new FormData();
|
|
72
|
+
form.append("file", new Blob([new Uint8Array(bytes)], { type: mediaType }), filename);
|
|
73
|
+
if (expiresInSeconds) form.append("expires_in_seconds", String(expiresInSeconds));
|
|
74
|
+
const res = await fetch(`${apiBase()}/files`, {
|
|
75
|
+
method: "POST",
|
|
76
|
+
headers: { "user-agent": USER_AGENT, ...authHeaders() },
|
|
77
|
+
body: form
|
|
78
|
+
});
|
|
79
|
+
if (!res.ok) await parseError(res);
|
|
80
|
+
return await res.json();
|
|
81
|
+
}
|
|
82
|
+
async function apiForm(method, path, form) {
|
|
83
|
+
const res = await fetch(`${apiBase()}${path}`, {
|
|
84
|
+
method,
|
|
85
|
+
headers: { "user-agent": USER_AGENT, ...authHeaders() },
|
|
86
|
+
body: form
|
|
87
|
+
});
|
|
88
|
+
if (!res.ok) await parseError(res);
|
|
89
|
+
return await res.json();
|
|
90
|
+
}
|
|
91
|
+
async function downloadFile(fileId) {
|
|
92
|
+
const res = await fetch(`${apiBase()}/files/${encodeURIComponent(fileId)}/content`, {
|
|
93
|
+
headers: { "user-agent": USER_AGENT, ...authHeaders() }
|
|
94
|
+
});
|
|
95
|
+
if (!res.ok) await parseError(res);
|
|
96
|
+
return { bytes: new Uint8Array(await res.arrayBuffer()), mediaType: res.headers.get("content-type") ?? "application/octet-stream" };
|
|
97
|
+
}
|
|
98
|
+
async function apiBytes(method, path, body) {
|
|
99
|
+
const res = await fetch(`${apiBase()}${path}`, {
|
|
100
|
+
method,
|
|
101
|
+
headers: {
|
|
102
|
+
"user-agent": USER_AGENT,
|
|
103
|
+
...authHeaders(),
|
|
104
|
+
...body ? { "content-type": body.mediaType } : {}
|
|
105
|
+
},
|
|
106
|
+
body: body ? new Uint8Array(body.bytes) : void 0
|
|
107
|
+
});
|
|
108
|
+
if (!res.ok) await parseError(res);
|
|
109
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
110
|
+
return {
|
|
111
|
+
bytes,
|
|
112
|
+
mediaType: res.headers.get("content-type") ?? "application/octet-stream",
|
|
113
|
+
json: () => JSON.parse(new TextDecoder().decode(bytes))
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async function resolveSessionRef(ref) {
|
|
117
|
+
if (ref.startsWith("sess-")) return ref;
|
|
118
|
+
const { agent } = await api(
|
|
119
|
+
"GET",
|
|
120
|
+
`/agents/${encodeURIComponent(ref)}`
|
|
121
|
+
).catch(async () => {
|
|
122
|
+
await api("GET", `/sessions/${encodeURIComponent(ref)}`);
|
|
123
|
+
return { agent: { id: ref, defaultSessionId: ref } };
|
|
124
|
+
});
|
|
125
|
+
if (!agent.defaultSessionId) {
|
|
126
|
+
throw new ApiError(
|
|
127
|
+
404,
|
|
128
|
+
"no_sessions",
|
|
129
|
+
`agent ${agent.id} has no sessions \u2014 create one: sky session create ${agent.id}`
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return agent.defaultSessionId;
|
|
133
|
+
}
|
|
134
|
+
async function* streamEvents(sessionId, signal) {
|
|
135
|
+
const { parseSseStream } = await import("./src-S777KCS5.js");
|
|
136
|
+
const res = await fetch(
|
|
137
|
+
`${apiBase()}/sessions/${encodeURIComponent(sessionId)}/stream`,
|
|
138
|
+
{
|
|
139
|
+
headers: { "user-agent": USER_AGENT, ...authHeaders(), accept: "text/event-stream" },
|
|
140
|
+
signal
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
if (!res.ok) await parseError(res);
|
|
144
|
+
if (!res.body) throw new ApiError(502, "no_body", "stream returned no body");
|
|
145
|
+
try {
|
|
146
|
+
for await (const frame of parseSseStream(res.body)) {
|
|
147
|
+
if (!frame.data) continue;
|
|
148
|
+
try {
|
|
149
|
+
yield { id: frame.id, event: frame.event, data: JSON.parse(frame.data) };
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (!(error instanceof DOMException && error.name === "AbortError")) throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export {
|
|
159
|
+
ApiError,
|
|
160
|
+
api,
|
|
161
|
+
postEvents,
|
|
162
|
+
uploadFile,
|
|
163
|
+
apiForm,
|
|
164
|
+
downloadFile,
|
|
165
|
+
apiBytes,
|
|
166
|
+
resolveSessionRef,
|
|
167
|
+
streamEvents
|
|
168
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { dirname, join } from "path";
|
|
5
|
+
var DEFAULT_API_BASE = "https://api.agentsky.dev/v1";
|
|
6
|
+
var DEFAULT_CONSOLE_BASE = "https://platform.agentsky.dev";
|
|
7
|
+
function configPath() {
|
|
8
|
+
return join(process.env.SKY_CONFIG_DIR ?? join(homedir(), ".config", "sky"), "config.json");
|
|
9
|
+
}
|
|
10
|
+
function loadConfig() {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(readFileSync(configPath(), "utf8"));
|
|
13
|
+
} catch {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function saveConfig(config) {
|
|
18
|
+
const path = configPath();
|
|
19
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
20
|
+
writeFileSync(path, `${JSON.stringify(config, null, 2)}
|
|
21
|
+
`, { mode: 384 });
|
|
22
|
+
}
|
|
23
|
+
function apiBase() {
|
|
24
|
+
return (process.env.SKY_API_URL ?? loadConfig().apiBase ?? DEFAULT_API_BASE).replace(/\/$/, "");
|
|
25
|
+
}
|
|
26
|
+
function consoleBase() {
|
|
27
|
+
const configured = process.env.SKY_CONSOLE_URL ?? loadConfig().consoleBase;
|
|
28
|
+
if (configured) return configured.replace(/\/$/, "");
|
|
29
|
+
const api = apiBase();
|
|
30
|
+
if (api === DEFAULT_API_BASE) return DEFAULT_CONSOLE_BASE;
|
|
31
|
+
return api.replace(/\/(?:api\/)?v1$/, "") || api;
|
|
32
|
+
}
|
|
33
|
+
function apiToken() {
|
|
34
|
+
return process.env.SKY_API_TOKEN ?? loadConfig().token;
|
|
35
|
+
}
|
|
36
|
+
function currentUniverse() {
|
|
37
|
+
return process.env.SKY_WORKSPACE ?? process.env.SKY_UNIVERSE ?? loadConfig().currentUniverse;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/version.ts
|
|
41
|
+
var CLI_VERSION = "2.12.0";
|
|
42
|
+
var USER_AGENT = `sky-cli/${CLI_VERSION} (${process.platform}; node/${process.versions.node})`;
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
configPath,
|
|
46
|
+
loadConfig,
|
|
47
|
+
saveConfig,
|
|
48
|
+
apiBase,
|
|
49
|
+
consoleBase,
|
|
50
|
+
apiToken,
|
|
51
|
+
currentUniverse,
|
|
52
|
+
CLI_VERSION,
|
|
53
|
+
USER_AGENT
|
|
54
|
+
};
|