@agentsky/sky 3.37.0 → 3.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +14 -0
- package/agent-plugins/.agents/plugins/marketplace.json +14 -2
- package/agent-plugins/.claude-plugin/marketplace.json +11 -4
- package/agent-plugins/.grok-plugin/marketplace.json +14 -4
- package/agent-plugins/.grok-plugin/plugin-index.json +13 -3
- package/agent-plugins/dsh/agentsky.patch.yml +11 -3
- package/agent-plugins/plugins/apps/.claude-plugin/plugin.json +8 -0
- package/agent-plugins/plugins/apps/.codex-plugin/plugin.json +23 -0
- package/agent-plugins/plugins/{browser → apps}/.mcp.json +2 -2
- package/agent-plugins/plugins/apps/skills/agentsky-apps/SKILL.md +24 -0
- package/agent-plugins/plugins/computer-use/.claude-plugin/plugin.json +8 -0
- package/agent-plugins/plugins/computer-use/.codex-plugin/plugin.json +23 -0
- package/agent-plugins/plugins/computer-use/.mcp.json +11 -0
- package/agent-plugins/plugins/{browser/skills/agentsky-browser → computer-use/skills/agentsky-computer-use}/SKILL.md +4 -3
- package/agent-plugins/plugins/crm/skills/agentsky-crm/SKILL.md +1 -0
- package/agent-plugins/plugins/meetings/.codex-plugin/plugin.json +1 -1
- package/agent-plugins/plugins/meetings/skills/agentsky-meetings/SKILL.md +2 -1
- package/agent-plugins/plugins/wechat/skills/agentsky-wechat/SKILL.md +1 -0
- package/dist/{chunk-GH5VMYMK.js → chunk-7A3BLBKU.js} +12 -5
- package/dist/{chunk-VI2JL2OC.js → chunk-SC5RAJVJ.js} +20321 -21805
- package/dist/index.js +3556 -1142
- package/dist/sse-GSK4TBYZ.js +38 -0
- package/dist/{trace-AI2MDTNU.js → trace-PB2LPQCZ.js} +2 -4
- package/dist/{trace-library-HT2OZ3PS.js → trace-library-EOEW45OX.js} +3 -5
- package/dist/worker-KD5TINHF.js +1150 -0
- package/package.json +5 -5
- package/agent-plugins/plugins/browser/.claude-plugin/plugin.json +0 -8
- package/agent-plugins/plugins/browser/.codex-plugin/plugin.json +0 -23
- package/dist/chunk-HKZ5CTZB.js +0 -8
- package/dist/src-NDBT3SB7.js +0 -346
- package/dist/worker-6Q4K4HZW.js +0 -190
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentsky/sky",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.39.0",
|
|
4
4
|
"description": "sky \u2014 the AgentSky developer CLI: launch and talk to long-lived agents from your terminal.",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
8
|
"sky": "./dist/index.js"
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
12
|
"vendor",
|
|
13
|
-
"agent-plugins"
|
|
13
|
+
"agent-plugins",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"NOTICE"
|
|
14
16
|
],
|
|
15
17
|
"engines": {
|
|
16
18
|
"node": ">=20"
|
|
@@ -29,7 +31,6 @@
|
|
|
29
31
|
"zod": "4.5.4"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@agent/chat": "*",
|
|
33
34
|
"@agent/spec": "*",
|
|
34
35
|
"@types/node": "^20",
|
|
35
36
|
"tsup": "^8.5.0",
|
|
@@ -39,7 +40,6 @@
|
|
|
39
40
|
},
|
|
40
41
|
"tsup": {
|
|
41
42
|
"noExternal": [
|
|
42
|
-
"@agent/chat",
|
|
43
43
|
"@agent/spec",
|
|
44
44
|
"zod"
|
|
45
45
|
],
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "browser",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Let AI agents use the apps and browser on your Mac in the background, without taking your pointer. Uses your account’s Mac permissions; Esc stops them.",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "AgentSky"
|
|
7
|
-
},
|
|
8
|
-
"skills": "./skills/",
|
|
9
|
-
"mcpServers": "./.mcp.json",
|
|
10
|
-
"interface": {
|
|
11
|
-
"displayName": "Computer use",
|
|
12
|
-
"shortDescription": "Agents use your apps and browser",
|
|
13
|
-
"longDescription": "Every new chat can use your Mac's apps and browser when its task needs them, in AgentSky Mac and in the Claude Code and Codex chats it runs on your Mac. Agents read an app's window through macOS Accessibility and a screenshot, so they can read a page in Chrome or a thread in Slack, then click, type and scroll in the background without moving your pointer. Verified owner requests use your Mac defaults unless explicitly limited; a bar shows while an agent works, and Esc stops it. Sites you sign in to in AgentSky's own browser windows are signed in for the workspace's cloud agents too.",
|
|
14
|
-
"developerName": "AgentSky",
|
|
15
|
-
"category": "This Mac",
|
|
16
|
-
"capabilities": [],
|
|
17
|
-
"defaultPrompt": [
|
|
18
|
-
"Open the Slack thread about the launch and summarize it.",
|
|
19
|
-
"Check my Chrome tab for the latest order status."
|
|
20
|
-
],
|
|
21
|
-
"websiteURL": "https://agentsky.dev/plugins/browser"
|
|
22
|
-
}
|
|
23
|
-
}
|
package/dist/chunk-HKZ5CTZB.js
DELETED
package/dist/src-NDBT3SB7.js
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
admittedInputScopeSchema,
|
|
3
|
-
external_exports,
|
|
4
|
-
messagePartSchema
|
|
5
|
-
} from "./chunk-VI2JL2OC.js";
|
|
6
|
-
import "./chunk-MLKGABMK.js";
|
|
7
|
-
|
|
8
|
-
// ../../packages/chat/src/stream.ts
|
|
9
|
-
async function* parseSseStream(body) {
|
|
10
|
-
const reader = body.getReader();
|
|
11
|
-
const decoder = new TextDecoder();
|
|
12
|
-
let buffer = "";
|
|
13
|
-
try {
|
|
14
|
-
while (true) {
|
|
15
|
-
const { done, value } = await reader.read();
|
|
16
|
-
if (done) break;
|
|
17
|
-
buffer += decoder.decode(value, { stream: true });
|
|
18
|
-
let sep;
|
|
19
|
-
while ((sep = buffer.match(/\r?\n\r?\n/)) && sep.index !== void 0) {
|
|
20
|
-
const raw = buffer.slice(0, sep.index);
|
|
21
|
-
buffer = buffer.slice(sep.index + sep[0].length);
|
|
22
|
-
const frame = { data: "" };
|
|
23
|
-
const dataLines = [];
|
|
24
|
-
for (const line of raw.split(/\r?\n/)) {
|
|
25
|
-
if (!line || line.startsWith(":")) continue;
|
|
26
|
-
const colon = line.indexOf(":");
|
|
27
|
-
const field = colon === -1 ? line : line.slice(0, colon);
|
|
28
|
-
const value2 = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
29
|
-
if (field === "id") frame.id = value2;
|
|
30
|
-
else if (field === "event") frame.event = value2;
|
|
31
|
-
else if (field === "data") dataLines.push(value2);
|
|
32
|
-
}
|
|
33
|
-
frame.data = dataLines.join("\n");
|
|
34
|
-
if (frame.id !== void 0 || frame.event !== void 0 || frame.data) yield frame;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
} finally {
|
|
38
|
-
reader.releaseLock();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async function* streamAgentEvents(baseUrl, options = {}) {
|
|
42
|
-
const headers = {
|
|
43
|
-
accept: "text/event-stream",
|
|
44
|
-
...options.headers ?? {}
|
|
45
|
-
};
|
|
46
|
-
if (options.lastEventId) headers["last-event-id"] = options.lastEventId;
|
|
47
|
-
const watchdog = new AbortController();
|
|
48
|
-
const onOuterAbort = () => watchdog.abort();
|
|
49
|
-
options.signal?.addEventListener("abort", onOuterAbort, { once: true });
|
|
50
|
-
if (options.signal?.aborted) watchdog.abort();
|
|
51
|
-
let idleTimer;
|
|
52
|
-
const armIdle = () => {
|
|
53
|
-
if (!options.idleTimeoutMs) return;
|
|
54
|
-
clearTimeout(idleTimer);
|
|
55
|
-
idleTimer = setTimeout(() => watchdog.abort(), options.idleTimeoutMs);
|
|
56
|
-
};
|
|
57
|
-
try {
|
|
58
|
-
armIdle();
|
|
59
|
-
const res = await fetch(`${baseUrl}/stream`, { headers, signal: watchdog.signal });
|
|
60
|
-
if (!res.ok) throw new Error(`pod stream failed ${res.status}: ${await res.text()}`);
|
|
61
|
-
if (!res.body) throw new Error("pod stream returned no body");
|
|
62
|
-
options.onOpen?.();
|
|
63
|
-
for await (const frame of parseSseStream(res.body)) {
|
|
64
|
-
armIdle();
|
|
65
|
-
let payload = {};
|
|
66
|
-
try {
|
|
67
|
-
payload = frame.data ? JSON.parse(frame.data) : {};
|
|
68
|
-
} catch {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
yield {
|
|
72
|
-
id: frame.id ?? "",
|
|
73
|
-
type: frame.event ?? (typeof payload.type === "string" ? payload.type : "unknown"),
|
|
74
|
-
detail: payload.detail ?? null,
|
|
75
|
-
data: payload.data ?? payload,
|
|
76
|
-
created_at: payload.created_at
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
} catch (error) {
|
|
80
|
-
if (!(error instanceof DOMException && error.name === "AbortError")) throw error;
|
|
81
|
-
} finally {
|
|
82
|
-
clearTimeout(idleTimer);
|
|
83
|
-
options.signal?.removeEventListener("abort", onOuterAbort);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ../../packages/chat/src/index.ts
|
|
88
|
-
var internalEventSchema = external_exports.object({
|
|
89
|
-
sessionId: external_exports.string().min(1).optional(),
|
|
90
|
-
/** Deploy-skew alias for sessionId; dropped one release after the cutover. */
|
|
91
|
-
agentInstanceId: external_exports.string().min(1).optional(),
|
|
92
|
-
message: external_exports.object({
|
|
93
|
-
id: external_exports.string().optional(),
|
|
94
|
-
podId: external_exports.string().min(1).optional(),
|
|
95
|
-
parts: external_exports.array(messagePartSchema).min(1)
|
|
96
|
-
}).optional(),
|
|
97
|
-
/** A pre-built lifecycle event from the web host (session.updated /
|
|
98
|
-
* session.deleted) — emitted verbatim; the host already persisted it. */
|
|
99
|
-
lifecycle: external_exports.object({ id: external_exports.string().min(1), type: external_exports.string().min(1) }).passthrough().optional()
|
|
100
|
-
});
|
|
101
|
-
function workspaceIdentityForPod(body, supported) {
|
|
102
|
-
const { workspace_identity: token, ...rest } = body;
|
|
103
|
-
if (!token || supported) return body;
|
|
104
|
-
const text = `This runtime cannot receive the private workspace-identity file. Use this value instead wherever the instructions read the file ~/.config/agentsky/workspace-identity: ${token}. Never print, persist or share it.`;
|
|
105
|
-
const parts = [...rest.parts, { type: "text", index: Math.max(-1, ...rest.parts.map((part) => part.index)) + 1, text }];
|
|
106
|
-
if (!rest.events) return { ...rest, parts };
|
|
107
|
-
const previous = rest.events.find((event) => event.type === "system.message");
|
|
108
|
-
const system = { type: "system.message", content: [{ type: "text", text: [...previous?.type === "system.message" ? previous.content.map((block) => block.text) : [], text].join("\n\n") }] };
|
|
109
|
-
return { ...rest, parts, events: [...rest.events.filter((event) => event.type !== "system.message"), system] };
|
|
110
|
-
}
|
|
111
|
-
function personalContextForPod(body, supported) {
|
|
112
|
-
const { personal_context: grant, ...rest } = body;
|
|
113
|
-
if (!grant || supported) return body;
|
|
114
|
-
const text = `This runtime cannot receive the private personal-context credential file. Use this value instead, as X-Personal-Context on memory and context API requests and as ACTL_PERSONAL_CONTEXT for actl grep: ${grant}. Never print, persist or share it.`;
|
|
115
|
-
const parts = [...rest.parts, { type: "text", index: Math.max(-1, ...rest.parts.map((part) => part.index)) + 1, text }];
|
|
116
|
-
if (!rest.events) return { ...rest, parts };
|
|
117
|
-
const previous = rest.events.find((event) => event.type === "system.message");
|
|
118
|
-
const system = { type: "system.message", content: [{ type: "text", text: [...previous?.type === "system.message" ? previous.content.map((block) => block.text) : [], text].join("\n\n") }] };
|
|
119
|
-
return { ...rest, parts, events: [...rest.events.filter((event) => event.type !== "system.message"), system] };
|
|
120
|
-
}
|
|
121
|
-
function podMessageBody(messageId, turn, resourcesRevision = 0, inputScope) {
|
|
122
|
-
const scope = inputScope ? admittedInputScopeSchema.parse(inputScope) : void 0;
|
|
123
|
-
if (scope && scope.message_id !== messageId) throw new Error("input_scope_identity_mismatch");
|
|
124
|
-
const preparation = scope ? { input_scope: scope } : {};
|
|
125
|
-
if ("events" in turn) {
|
|
126
|
-
const envelope = {
|
|
127
|
-
events: turn.events.system ? [turn.events.message, turn.events.system] : [turn.events.message],
|
|
128
|
-
...resourcesRevision > 0 ? { resources_revision: resourcesRevision } : {}
|
|
129
|
-
};
|
|
130
|
-
return { id: messageId, ...envelope, parts: legacyPartsOf(envelope), ...preparation };
|
|
131
|
-
}
|
|
132
|
-
return { id: messageId, parts: turn.parts, ...resourcesRevision > 0 ? { resources_revision: resourcesRevision } : {}, ...preparation };
|
|
133
|
-
}
|
|
134
|
-
var UNREACHABLE_CODES = /* @__PURE__ */ new Set([
|
|
135
|
-
"ECONNREFUSED",
|
|
136
|
-
"ENOTFOUND",
|
|
137
|
-
"EAI_AGAIN",
|
|
138
|
-
"EHOSTUNREACH",
|
|
139
|
-
"ENETUNREACH",
|
|
140
|
-
"UND_ERR_CONNECT_TIMEOUT"
|
|
141
|
-
]);
|
|
142
|
-
var UNREACHABLE_PREFIXES = ["CERT_", "ERR_TLS_", "UNABLE_TO_", "DEPTH_ZERO_", "SELF_SIGNED_"];
|
|
143
|
-
function errorCode(error) {
|
|
144
|
-
const cause = error?.cause ?? error;
|
|
145
|
-
const code = cause?.code;
|
|
146
|
-
if (typeof code === "string") return code;
|
|
147
|
-
const nested = cause?.errors?.find(
|
|
148
|
-
(e) => typeof e?.code === "string"
|
|
149
|
-
);
|
|
150
|
-
return nested ? nested.code : void 0;
|
|
151
|
-
}
|
|
152
|
-
function classifyPodSendError(error) {
|
|
153
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
154
|
-
const name = error?.name;
|
|
155
|
-
if (name === "TimeoutError" || name === "AbortError") return { kind: "uncertain", reason: "timeout", detail };
|
|
156
|
-
const code = errorCode(error);
|
|
157
|
-
if (code && (UNREACHABLE_CODES.has(code) || UNREACHABLE_PREFIXES.some((prefix) => code.startsWith(prefix)))) {
|
|
158
|
-
return { kind: "undelivered", reason: "unreachable", detail: `${detail} (${code})` };
|
|
159
|
-
}
|
|
160
|
-
return { kind: "uncertain", reason: "reset", detail: code ? `${detail} (${code})` : detail };
|
|
161
|
-
}
|
|
162
|
-
function classifyPodSendStatus(status, detail) {
|
|
163
|
-
if (status >= 200 && status < 300) return { kind: "accepted", status };
|
|
164
|
-
if (status === 403) return { kind: "undelivered", reason: "forbidden", status, detail };
|
|
165
|
-
if (status === 409) return { kind: "undelivered", reason: "parked", status, detail };
|
|
166
|
-
if (status === 502 || status === 503) return { kind: "undelivered", reason: "not_serving", status, detail };
|
|
167
|
-
if (status === 504) return { kind: "uncertain", reason: "gateway_timeout", status, detail };
|
|
168
|
-
if (status >= 500) return { kind: "uncertain", reason: "server_error", status, detail };
|
|
169
|
-
return { kind: "rejected", status, detail };
|
|
170
|
-
}
|
|
171
|
-
var PERSONAL_CONTEXT_PODS = /* @__PURE__ */ new Set();
|
|
172
|
-
var WORKSPACE_IDENTITY_PODS = /* @__PURE__ */ new Set();
|
|
173
|
-
async function sendPodMessage(baseUrl, body, options = {}) {
|
|
174
|
-
const headers = {
|
|
175
|
-
"content-type": "application/json",
|
|
176
|
-
...options.headers ?? {}
|
|
177
|
-
};
|
|
178
|
-
if (options.idempotencyKey) headers["idempotency-key"] = options.idempotencyKey;
|
|
179
|
-
let res;
|
|
180
|
-
try {
|
|
181
|
-
if (body.personal_context && !PERSONAL_CONTEXT_PODS.has(baseUrl)) {
|
|
182
|
-
const health = await getPodHealth(baseUrl, options);
|
|
183
|
-
if (health.personalContext) PERSONAL_CONTEXT_PODS.add(baseUrl);
|
|
184
|
-
else if (health.ok) body = personalContextForPod(body, false);
|
|
185
|
-
}
|
|
186
|
-
if (body.workspace_identity && !WORKSPACE_IDENTITY_PODS.has(baseUrl)) {
|
|
187
|
-
const health = await getPodHealth(baseUrl, options);
|
|
188
|
-
if (health.workspaceIdentity) WORKSPACE_IDENTITY_PODS.add(baseUrl);
|
|
189
|
-
else if (health.ok) body = workspaceIdentityForPod(body, false);
|
|
190
|
-
}
|
|
191
|
-
const user = body.events?.find((event) => event.type === "user.message");
|
|
192
|
-
const mode = user?.type === "user.message" ? user.interaction_mode : body.interaction_mode;
|
|
193
|
-
if (mode) {
|
|
194
|
-
const health = await getPodHealth(baseUrl, options);
|
|
195
|
-
if (!health.ok) return { kind: "undelivered", reason: "unreachable", status: health.status, detail: "Planning protocol could not be observed before delivery" };
|
|
196
|
-
if (!health.interactionModes?.includes(mode)) {
|
|
197
|
-
const events = body.events?.map((event) => {
|
|
198
|
-
if (event.type !== "user.message") return event;
|
|
199
|
-
const { interaction_mode: _mode, ...legacy } = event;
|
|
200
|
-
return legacy;
|
|
201
|
-
}) ?? [];
|
|
202
|
-
const context = mode === "plan" ? "Interaction mode: plan. Investigate and return a reviewable plan. Do not implement, edit files, run mutating commands or cause external side effects. Wait for an explicit implementation choice." : "Interaction mode: build. Respond to the current request normally; the previous planning-only restriction no longer applies. Preserve all applicable permissions and approvals.";
|
|
203
|
-
const previous = events.find((event) => event.type === "system.message");
|
|
204
|
-
const content = [...previous?.type === "system.message" ? previous.content : [], { type: "text", text: context }];
|
|
205
|
-
const system = { type: "system.message", content: [{ type: "text", text: content.map((block) => block.text).join("\n\n") }] };
|
|
206
|
-
const forwarded = [...events.filter((event) => event.type !== "system.message"), system];
|
|
207
|
-
const { interaction_mode: _legacyMode, ...compatible } = body;
|
|
208
|
-
body = body.events ? { ...compatible, events: forwarded, parts: legacyPartsOf({ events: forwarded }) } : { ...compatible, parts: [...body.parts, { type: "text", index: body.parts.length, text: context }] };
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
res = await fetch(`${baseUrl}/messages`, {
|
|
212
|
-
method: "POST",
|
|
213
|
-
headers,
|
|
214
|
-
body: JSON.stringify(body),
|
|
215
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 2e4)
|
|
216
|
-
});
|
|
217
|
-
} catch (error) {
|
|
218
|
-
return classifyPodSendError(error);
|
|
219
|
-
}
|
|
220
|
-
const detail = res.ok ? "" : await res.text().catch(() => "");
|
|
221
|
-
return classifyPodSendStatus(res.status, detail);
|
|
222
|
-
}
|
|
223
|
-
async function getPodHealth(baseUrl, options = {}) {
|
|
224
|
-
try {
|
|
225
|
-
const res = await fetch(`${baseUrl}/health`, {
|
|
226
|
-
headers: options.headers ?? {},
|
|
227
|
-
signal: AbortSignal.timeout(options.timeoutMs ?? 5e3)
|
|
228
|
-
});
|
|
229
|
-
const body = await res.json().catch(() => ({}));
|
|
230
|
-
const open = body.open_message_id ?? body.open_turn_id;
|
|
231
|
-
return {
|
|
232
|
-
ok: res.ok,
|
|
233
|
-
status: res.status,
|
|
234
|
-
state: typeof body.state === "string" ? body.state : void 0,
|
|
235
|
-
openMessageId: typeof open === "string" && open ? open : null,
|
|
236
|
-
interactionModes: Array.isArray(body.interaction_modes) ? body.interaction_modes.filter((mode) => mode === "plan" || mode === "build") : void 0,
|
|
237
|
-
personalContext: body.personal_context === true,
|
|
238
|
-
workspaceIdentity: body.workspace_identity === true
|
|
239
|
-
};
|
|
240
|
-
} catch {
|
|
241
|
-
return { ok: false, openMessageId: null };
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
function legacyPartsOf(body) {
|
|
245
|
-
const parts = [];
|
|
246
|
-
const user = body.events[0];
|
|
247
|
-
if (user.type !== "user.message") return parts;
|
|
248
|
-
for (const block of user.content) {
|
|
249
|
-
const index = parts.length;
|
|
250
|
-
if (block.type === "text") {
|
|
251
|
-
parts.push({ type: "text", index, text: block.text });
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
if (block.source.type !== "file") continue;
|
|
255
|
-
const uri = `blob://assets/${block.source.file_id.replace(/^file_/, "")}`;
|
|
256
|
-
if (block.type === "image") parts.push({ type: "image", index, media_type: "image/*", uri });
|
|
257
|
-
else parts.push({ type: "file", index, name: block.title ?? "document", media_type: "application/octet-stream", uri });
|
|
258
|
-
}
|
|
259
|
-
return parts;
|
|
260
|
-
}
|
|
261
|
-
function textFromParts(parts) {
|
|
262
|
-
const texts = [];
|
|
263
|
-
let previous;
|
|
264
|
-
for (const part of parts) {
|
|
265
|
-
const stream = part.type === "text" && part.stream_id && typeof part.stream_index === "number" && Number.isInteger(part.stream_index) && part.stream_index >= 0 ? { id: part.stream_id, index: part.stream_index } : void 0;
|
|
266
|
-
if (part.type === "text") {
|
|
267
|
-
if (stream && previous && stream.id === previous.id && stream.index === previous.index + 1) {
|
|
268
|
-
texts[texts.length - 1] += part.text;
|
|
269
|
-
} else {
|
|
270
|
-
texts.push(part.text);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
previous = stream;
|
|
274
|
-
}
|
|
275
|
-
return texts.filter(Boolean).join(" ").trim();
|
|
276
|
-
}
|
|
277
|
-
function normalizeBaseUrl(baseUrl) {
|
|
278
|
-
return baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
279
|
-
}
|
|
280
|
-
var PROMOTION_SCOPE_HEADER = "x-agentsky-promotion-scope";
|
|
281
|
-
var SURFACE_HEADER = "x-agentsky-surface";
|
|
282
|
-
async function postSessionEvents(args) {
|
|
283
|
-
const url = new URL(
|
|
284
|
-
`/api/v1/sessions/${encodeURIComponent(args.sessionId)}/events`,
|
|
285
|
-
normalizeBaseUrl(args.baseUrl)
|
|
286
|
-
);
|
|
287
|
-
const body = JSON.stringify({ events: args.events, ...args.requireIdle ? { requireIdle: true } : {} });
|
|
288
|
-
const send = async (token) => fetch(url, {
|
|
289
|
-
method: "POST",
|
|
290
|
-
headers: {
|
|
291
|
-
authorization: `Bearer ${token}`,
|
|
292
|
-
"content-type": "application/json",
|
|
293
|
-
...args.idempotencyKey ? { "idempotency-key": args.idempotencyKey } : {},
|
|
294
|
-
...args.routineRunId ? { "x-agentsky-routine-run": args.routineRunId } : {},
|
|
295
|
-
...args.promotionScope ? { [PROMOTION_SCOPE_HEADER]: args.promotionScope } : {},
|
|
296
|
-
...args.surface ? { [SURFACE_HEADER]: args.surface } : {}
|
|
297
|
-
},
|
|
298
|
-
body,
|
|
299
|
-
signal: AbortSignal.timeout(args.timeoutMs ?? 95e3)
|
|
300
|
-
});
|
|
301
|
-
let response = await send(await args.credentials.token());
|
|
302
|
-
if (response.status === 401) response = await send(await args.credentials.renew());
|
|
303
|
-
return readResult(response);
|
|
304
|
-
}
|
|
305
|
-
async function interruptSession(args) {
|
|
306
|
-
const url = new URL(
|
|
307
|
-
`/api/v1/sessions/${encodeURIComponent(args.sessionId)}/interrupt`,
|
|
308
|
-
normalizeBaseUrl(args.baseUrl)
|
|
309
|
-
);
|
|
310
|
-
const send = async (token) => fetch(url, {
|
|
311
|
-
method: "POST",
|
|
312
|
-
headers: { authorization: `Bearer ${token}` },
|
|
313
|
-
signal: AbortSignal.timeout(args.timeoutMs ?? 1e4)
|
|
314
|
-
});
|
|
315
|
-
let response = await send(await args.credentials.token());
|
|
316
|
-
if (response.status === 401) response = await send(await args.credentials.renew());
|
|
317
|
-
return readResult(response);
|
|
318
|
-
}
|
|
319
|
-
async function readResult(response) {
|
|
320
|
-
const payload = await response.json().catch(() => ({}));
|
|
321
|
-
if (response.ok) return { ok: true, status: response.status, data: payload.data ?? [] };
|
|
322
|
-
return {
|
|
323
|
-
ok: false,
|
|
324
|
-
status: response.status,
|
|
325
|
-
code: payload.error?.code ?? `http_${response.status}`,
|
|
326
|
-
message: payload.error?.message ?? `conversation plane answered ${response.status}`
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
export {
|
|
330
|
-
PROMOTION_SCOPE_HEADER,
|
|
331
|
-
SURFACE_HEADER,
|
|
332
|
-
classifyPodSendError,
|
|
333
|
-
classifyPodSendStatus,
|
|
334
|
-
getPodHealth,
|
|
335
|
-
internalEventSchema,
|
|
336
|
-
interruptSession,
|
|
337
|
-
legacyPartsOf,
|
|
338
|
-
parseSseStream,
|
|
339
|
-
personalContextForPod,
|
|
340
|
-
podMessageBody,
|
|
341
|
-
postSessionEvents,
|
|
342
|
-
sendPodMessage,
|
|
343
|
-
streamAgentEvents,
|
|
344
|
-
textFromParts,
|
|
345
|
-
workspaceIdentityForPod
|
|
346
|
-
};
|
package/dist/worker-6Q4K4HZW.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import "./chunk-MLKGABMK.js";
|
|
2
|
-
|
|
3
|
-
// src/worker.ts
|
|
4
|
-
import { mkdirSync, writeFileSync, rmSync } from "fs";
|
|
5
|
-
import { tmpdir } from "os";
|
|
6
|
-
import { join } from "path";
|
|
7
|
-
import { randomBytes } from "crypto";
|
|
8
|
-
var RealDockerRunner = class {
|
|
9
|
-
async run({ image, envFile, port, signal }) {
|
|
10
|
-
const { spawn } = await import("child_process");
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const child = spawn(
|
|
13
|
-
"docker",
|
|
14
|
-
[
|
|
15
|
-
"run",
|
|
16
|
-
"--rm",
|
|
17
|
-
"--pull=always",
|
|
18
|
-
`--env-file=${envFile}`,
|
|
19
|
-
`-p`,
|
|
20
|
-
`127.0.0.1:${port}:8080`,
|
|
21
|
-
image
|
|
22
|
-
],
|
|
23
|
-
{ stdio: "inherit" }
|
|
24
|
-
);
|
|
25
|
-
signal.addEventListener("abort", () => {
|
|
26
|
-
child.kill("SIGTERM");
|
|
27
|
-
});
|
|
28
|
-
child.on("error", reject);
|
|
29
|
-
child.on("exit", (code) => {
|
|
30
|
-
if (code === 0 || signal.aborted) resolve();
|
|
31
|
-
else reject(new Error(`docker exited with code ${code}`));
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var POD_PORT = 18080;
|
|
37
|
-
var HEARTBEAT_INTERVAL_MS = 15e3;
|
|
38
|
-
async function startWorker(opts) {
|
|
39
|
-
const docker = opts.docker ?? new RealDockerRunner();
|
|
40
|
-
const signal = opts.signal ?? new AbortController().signal;
|
|
41
|
-
const wsUrl = opts.apiBase.replace(/^https?:\/\//, (m) => m === "https://" ? "wss://" : "ws://").replace(/\/$/, "");
|
|
42
|
-
const connectUrl = `${wsUrl}/api/v1/worker-pools/${opts.poolId}/connect`;
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
import("ws").then(({ default: WS }) => {
|
|
45
|
-
const ws = new WS(connectUrl, {
|
|
46
|
-
headers: { authorization: `Bearer ${opts.token}` }
|
|
47
|
-
});
|
|
48
|
-
let currentContainer = null;
|
|
49
|
-
const heartbeatTimer = setInterval(() => {
|
|
50
|
-
if (ws.readyState === WS.OPEN) {
|
|
51
|
-
ws.send(JSON.stringify({ type: "heartbeat" }));
|
|
52
|
-
}
|
|
53
|
-
}, HEARTBEAT_INTERVAL_MS);
|
|
54
|
-
signal.addEventListener("abort", () => {
|
|
55
|
-
clearInterval(heartbeatTimer);
|
|
56
|
-
currentContainer?.abort();
|
|
57
|
-
ws.close();
|
|
58
|
-
resolve();
|
|
59
|
-
});
|
|
60
|
-
ws.on("open", () => {
|
|
61
|
-
ws.send(JSON.stringify({
|
|
62
|
-
type: "hello",
|
|
63
|
-
label: opts.label,
|
|
64
|
-
imageDigest: "unknown",
|
|
65
|
-
capacity: 1
|
|
66
|
-
}));
|
|
67
|
-
console.log(`[sky worker] connected to pool ${opts.poolId}`);
|
|
68
|
-
});
|
|
69
|
-
ws.on("message", async (raw) => {
|
|
70
|
-
let msg;
|
|
71
|
-
try {
|
|
72
|
-
msg = JSON.parse(raw.toString());
|
|
73
|
-
} catch {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (msg.type === "start") {
|
|
77
|
-
await handleStart(msg, ws, WS, docker, currentContainer);
|
|
78
|
-
} else if (msg.type === "stop") {
|
|
79
|
-
currentContainer?.abort();
|
|
80
|
-
currentContainer = null;
|
|
81
|
-
} else if (msg.type === "http") {
|
|
82
|
-
await handleHttp(msg, ws);
|
|
83
|
-
} else if (msg.type === "stream_open") {
|
|
84
|
-
void handleStreamOpen(msg, ws);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
ws.on("close", () => {
|
|
88
|
-
clearInterval(heartbeatTimer);
|
|
89
|
-
currentContainer?.abort();
|
|
90
|
-
resolve();
|
|
91
|
-
});
|
|
92
|
-
ws.on("error", (err) => {
|
|
93
|
-
clearInterval(heartbeatTimer);
|
|
94
|
-
currentContainer?.abort();
|
|
95
|
-
reject(err);
|
|
96
|
-
});
|
|
97
|
-
}).catch(reject);
|
|
98
|
-
});
|
|
99
|
-
async function handleStart(msg, ws, WS, docker2, existingContainer) {
|
|
100
|
-
if (existingContainer) existingContainer.abort();
|
|
101
|
-
const dir = join(tmpdir(), `sky-worker-${randomBytes(6).toString("hex")}`);
|
|
102
|
-
mkdirSync(dir, { mode: 448 });
|
|
103
|
-
const envFile = join(dir, "pod.env");
|
|
104
|
-
const envLines = Object.entries(msg.env).map(([k, v]) => `${k}=${v.replace(/\n/g, "\\n")}`).join("\n");
|
|
105
|
-
writeFileSync(envFile, envLines, { mode: 384 });
|
|
106
|
-
const containerAbort = new AbortController();
|
|
107
|
-
try {
|
|
108
|
-
void docker2.run({
|
|
109
|
-
image: msg.image,
|
|
110
|
-
envFile,
|
|
111
|
-
port: POD_PORT,
|
|
112
|
-
signal: containerAbort.signal
|
|
113
|
-
}).finally(() => {
|
|
114
|
-
try {
|
|
115
|
-
rmSync(dir, { recursive: true });
|
|
116
|
-
} catch {
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
} catch (err) {
|
|
120
|
-
try {
|
|
121
|
-
rmSync(dir, { recursive: true });
|
|
122
|
-
} catch {
|
|
123
|
-
}
|
|
124
|
-
console.error("[sky worker] docker run failed:", err);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
async function handleHttp(msg, ws) {
|
|
128
|
-
const url = `http://127.0.0.1:${POD_PORT}${msg.path}`;
|
|
129
|
-
try {
|
|
130
|
-
const response = await fetch(url, {
|
|
131
|
-
method: msg.method,
|
|
132
|
-
headers: msg.headers,
|
|
133
|
-
body: msg.body || void 0,
|
|
134
|
-
signal: AbortSignal.timeout(3e4)
|
|
135
|
-
});
|
|
136
|
-
const body = await response.text();
|
|
137
|
-
const headers = {};
|
|
138
|
-
response.headers.forEach((v, k) => {
|
|
139
|
-
headers[k] = v;
|
|
140
|
-
});
|
|
141
|
-
const resp = {
|
|
142
|
-
type: "http_response",
|
|
143
|
-
id: msg.id,
|
|
144
|
-
status: response.status,
|
|
145
|
-
headers,
|
|
146
|
-
body
|
|
147
|
-
};
|
|
148
|
-
ws.send(JSON.stringify(resp));
|
|
149
|
-
} catch (err) {
|
|
150
|
-
ws.send(JSON.stringify({
|
|
151
|
-
type: "http_response",
|
|
152
|
-
id: msg.id,
|
|
153
|
-
status: 502,
|
|
154
|
-
headers: {},
|
|
155
|
-
body: String(err)
|
|
156
|
-
}));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async function handleStreamOpen(msg, ws) {
|
|
160
|
-
const url = `http://127.0.0.1:${POD_PORT}${msg.path}`;
|
|
161
|
-
try {
|
|
162
|
-
const response = await fetch(url, {
|
|
163
|
-
headers: { accept: "text/event-stream" },
|
|
164
|
-
signal: AbortSignal.timeout(3e5)
|
|
165
|
-
});
|
|
166
|
-
const reader = response.body?.getReader();
|
|
167
|
-
if (!reader) {
|
|
168
|
-
ws.send(JSON.stringify({ type: "stream_close", id: msg.id }));
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const decoder = new TextDecoder();
|
|
172
|
-
for (; ; ) {
|
|
173
|
-
const { done, value } = await reader.read();
|
|
174
|
-
if (done) break;
|
|
175
|
-
ws.send(JSON.stringify({
|
|
176
|
-
type: "stream_event",
|
|
177
|
-
id: msg.id,
|
|
178
|
-
data: decoder.decode(value, { stream: true })
|
|
179
|
-
}));
|
|
180
|
-
}
|
|
181
|
-
ws.send(JSON.stringify({ type: "stream_close", id: msg.id }));
|
|
182
|
-
} catch {
|
|
183
|
-
ws.send(JSON.stringify({ type: "stream_close", id: msg.id }));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
export {
|
|
188
|
-
RealDockerRunner,
|
|
189
|
-
startWorker
|
|
190
|
-
};
|