@zocomputer/agent-sdk 0.5.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 +21 -0
- package/README.md +673 -0
- package/dist/attachments.js +52 -0
- package/dist/gateway-fetch.js +67 -0
- package/dist/index.js +4169 -0
- package/dist/initiator-auth.js +49 -0
- package/dist/platform/agent-sandbox/index.js +691 -0
- package/dist/platform/cloud-tools/image.js +498 -0
- package/dist/platform/cloud-tools/index.js +507 -0
- package/dist/platform/cloud-tools/web-search.js +87 -0
- package/dist/platform/runtime-ai/gateway.js +87 -0
- package/dist/platform/runtime-ai/index.js +91 -0
- package/dist/platform/runtime-ai/register.js +88 -0
- package/dist/platform/runtime-ai/session-fetch.js +54 -0
- package/dist/platform/runtime-auth/index.js +141 -0
- package/dist/state-files.js +287 -0
- package/dist/state-sandbox.js +383 -0
- package/dist/state.js +29 -0
- package/dist/steer-inbox.js +84 -0
- package/dist/steer.js +83 -0
- package/package.json +143 -0
- package/platform/agent-sandbox/api-client.ts +196 -0
- package/platform/agent-sandbox/index.ts +27 -0
- package/platform/agent-sandbox/pure.ts +83 -0
- package/platform/agent-sandbox/sftp.ts +141 -0
- package/platform/agent-sandbox/ssh-connection.ts +165 -0
- package/platform/agent-sandbox/ssh-exec.ts +98 -0
- package/platform/agent-sandbox/ssh-session.ts +487 -0
- package/platform/agent-sandbox/zo-backend.ts +88 -0
- package/platform/agent-sandbox/zo-sandbox.ts +39 -0
- package/platform/cloud-tools/image-path.ts +44 -0
- package/platform/cloud-tools/image.ts +225 -0
- package/platform/cloud-tools/index.ts +22 -0
- package/platform/cloud-tools/state-files.ts +368 -0
- package/platform/cloud-tools/tool-meta.ts +32 -0
- package/platform/cloud-tools/web-search.ts +15 -0
- package/platform/runtime-ai/gateway.ts +76 -0
- package/platform/runtime-ai/index.ts +20 -0
- package/platform/runtime-ai/register.ts +26 -0
- package/platform/runtime-ai/session-fetch.ts +124 -0
- package/platform/runtime-auth/index.ts +331 -0
- package/src/async-tasks.ts +273 -0
- package/src/attachments.ts +109 -0
- package/src/backgroundable.ts +88 -0
- package/src/bounded-output.ts +159 -0
- package/src/dir-conventions.ts +238 -0
- package/src/extract/cache.ts +40 -0
- package/src/extract/docx.ts +18 -0
- package/src/extract/pdf.ts +54 -0
- package/src/extract/sheet.ts +56 -0
- package/src/file-kind.ts +258 -0
- package/src/file-view.ts +80 -0
- package/src/gateway-fetch.ts +115 -0
- package/src/glob-match.ts +13 -0
- package/src/hooks.ts +213 -0
- package/src/index.ts +419 -0
- package/src/initiator-auth.ts +81 -0
- package/src/instructions.ts +224 -0
- package/src/list-files.ts +41 -0
- package/src/mock-model.ts +572 -0
- package/src/park-delivery.ts +247 -0
- package/src/path-locks.ts +52 -0
- package/src/read-file-content.ts +142 -0
- package/src/read-text.ts +40 -0
- package/src/redeliver.ts +155 -0
- package/src/run.ts +159 -0
- package/src/sandbox-io.ts +414 -0
- package/src/state-files.ts +460 -0
- package/src/state-sandbox.ts +710 -0
- package/src/state.ts +96 -0
- package/src/steer-inbox.ts +105 -0
- package/src/steer-tool.ts +83 -0
- package/src/steer.ts +146 -0
- package/src/task.ts +320 -0
- package/src/tools/bash.ts +143 -0
- package/src/tools/edit.ts +58 -0
- package/src/tools/glob.ts +56 -0
- package/src/tools/grep.ts +188 -0
- package/src/tools/read.ts +319 -0
- package/src/tools/tasks.ts +241 -0
- package/src/tools/webfetch.ts +368 -0
- package/src/tools/write.ts +42 -0
- package/src/walk.ts +112 -0
- package/src/watch-output.ts +104 -0
- package/src/web-fetch.ts +324 -0
- package/src/web-page.ts +179 -0
- package/src/workspace-io.ts +225 -0
- package/src/workspace.ts +41 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// ../../var/folders/vh/qdfcqc514qj47bbvzslcwjsc0000gn/T/agent-sdk-publish-eDWqsZ/src/attachments.ts
|
|
2
|
+
var CHAT_ATTACHMENT_FIELD = "chatAttachment";
|
|
3
|
+
var DEFAULT_MAX_INLINE_IMAGE_BYTES = 3 * 1024 * 1024;
|
|
4
|
+
var DEFAULT_MAX_INLINE_MEDIA_BYTES = 10 * 1024 * 1024;
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function readChatAttachment(toolOutput) {
|
|
9
|
+
if (!isRecord(toolOutput))
|
|
10
|
+
return null;
|
|
11
|
+
const raw = toolOutput[CHAT_ATTACHMENT_FIELD];
|
|
12
|
+
if (!isRecord(raw))
|
|
13
|
+
return null;
|
|
14
|
+
if (typeof raw.dataUrl !== "string" || raw.dataUrl.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
if (typeof raw.mediaType !== "string" || raw.mediaType.length === 0)
|
|
17
|
+
return null;
|
|
18
|
+
const base = {
|
|
19
|
+
dataUrl: raw.dataUrl,
|
|
20
|
+
mediaType: raw.mediaType
|
|
21
|
+
};
|
|
22
|
+
switch (raw.kind) {
|
|
23
|
+
case "image":
|
|
24
|
+
return {
|
|
25
|
+
kind: "image",
|
|
26
|
+
...base,
|
|
27
|
+
filename: typeof raw.filename === "string" ? raw.filename : "image",
|
|
28
|
+
width: typeof raw.width === "number" ? raw.width : null,
|
|
29
|
+
height: typeof raw.height === "number" ? raw.height : null
|
|
30
|
+
};
|
|
31
|
+
case "video":
|
|
32
|
+
return {
|
|
33
|
+
kind: "video",
|
|
34
|
+
...base,
|
|
35
|
+
filename: typeof raw.filename === "string" ? raw.filename : "video"
|
|
36
|
+
};
|
|
37
|
+
case "audio":
|
|
38
|
+
return {
|
|
39
|
+
kind: "audio",
|
|
40
|
+
...base,
|
|
41
|
+
filename: typeof raw.filename === "string" ? raw.filename : "audio"
|
|
42
|
+
};
|
|
43
|
+
default:
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
readChatAttachment,
|
|
49
|
+
DEFAULT_MAX_INLINE_MEDIA_BYTES,
|
|
50
|
+
DEFAULT_MAX_INLINE_IMAGE_BYTES,
|
|
51
|
+
CHAT_ATTACHMENT_FIELD
|
|
52
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// ../../var/folders/vh/qdfcqc514qj47bbvzslcwjsc0000gn/T/agent-sdk-publish-eDWqsZ/src/gateway-fetch.ts
|
|
2
|
+
var DEFAULT_STREAM_GUARDS = {
|
|
3
|
+
firstByteMs: 60000,
|
|
4
|
+
idleMs: 180000
|
|
5
|
+
};
|
|
6
|
+
function withStreamGuards(baseFetch, options = DEFAULT_STREAM_GUARDS) {
|
|
7
|
+
const guarded = async (input, init) => {
|
|
8
|
+
const controller = new AbortController;
|
|
9
|
+
const outer = init?.signal;
|
|
10
|
+
if (outer != null) {
|
|
11
|
+
if (outer.aborted)
|
|
12
|
+
controller.abort(outer.reason);
|
|
13
|
+
else
|
|
14
|
+
outer.addEventListener("abort", () => controller.abort(outer.reason), { once: true });
|
|
15
|
+
}
|
|
16
|
+
const firstByteTimer = setTimeout(() => {
|
|
17
|
+
controller.abort(new Error(`gateway response headers not received within ${options.firstByteMs}ms`));
|
|
18
|
+
}, options.firstByteMs);
|
|
19
|
+
let response;
|
|
20
|
+
try {
|
|
21
|
+
response = await baseFetch(input, { ...init, signal: controller.signal });
|
|
22
|
+
} finally {
|
|
23
|
+
clearTimeout(firstByteTimer);
|
|
24
|
+
}
|
|
25
|
+
const body = response.body;
|
|
26
|
+
if (body === null)
|
|
27
|
+
return response;
|
|
28
|
+
const reader = body.getReader();
|
|
29
|
+
const guarded2 = new ReadableStream({
|
|
30
|
+
async pull(streamController) {
|
|
31
|
+
let idleTimer;
|
|
32
|
+
const idle = new Promise((_, reject) => {
|
|
33
|
+
idleTimer = setTimeout(() => {
|
|
34
|
+
const reason = new Error(`gateway stream idle for ${options.idleMs}ms`);
|
|
35
|
+
controller.abort(reason);
|
|
36
|
+
reject(reason);
|
|
37
|
+
}, options.idleMs);
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
const result = await Promise.race([reader.read(), idle]);
|
|
41
|
+
if (result.done)
|
|
42
|
+
streamController.close();
|
|
43
|
+
else
|
|
44
|
+
streamController.enqueue(result.value);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
await reader.cancel(error).catch(() => {});
|
|
47
|
+
throw error;
|
|
48
|
+
} finally {
|
|
49
|
+
clearTimeout(idleTimer);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
async cancel(reason) {
|
|
53
|
+
await reader.cancel(reason).catch(() => {});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return new Response(guarded2, {
|
|
57
|
+
status: response.status,
|
|
58
|
+
statusText: response.statusText,
|
|
59
|
+
headers: response.headers
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return Object.assign(guarded, { preconnect: globalThis.fetch.preconnect });
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
withStreamGuards,
|
|
66
|
+
DEFAULT_STREAM_GUARDS
|
|
67
|
+
};
|