@geminixiang/mikan 1.0.0-beta.95 → 1.0.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/CHANGELOG.md +387 -391
- package/README.md +33 -42
- package/dist/adapters/github/bot.js +1 -1
- package/dist/adapters/github/bot.js.map +1 -1
- package/dist/adapters/github/policy.d.ts +2 -9
- package/dist/adapters/github/policy.d.ts.map +1 -1
- package/dist/adapters/github/policy.js +18 -26
- package/dist/adapters/github/policy.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +2 -4
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +28 -56
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/socket-agent.d.ts +9 -0
- package/dist/adapters/slack/socket-agent.d.ts.map +1 -0
- package/dist/adapters/slack/socket-agent.js +17 -0
- package/dist/adapters/slack/socket-agent.js.map +1 -0
- package/dist/adapters/telegram/bot.d.ts +1 -0
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +6 -1
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/adapters/telegram/types.d.ts +1 -0
- package/dist/adapters/telegram/types.d.ts.map +1 -1
- package/dist/adapters/telegram/types.js.map +1 -1
- package/dist/cli/arg-grammar.d.ts +1 -2
- package/dist/cli/arg-grammar.d.ts.map +1 -1
- package/dist/cli/arg-grammar.js +2 -17
- package/dist/cli/arg-grammar.js.map +1 -1
- package/dist/cli/boot.d.ts.map +1 -1
- package/dist/cli/boot.js +5 -11
- package/dist/cli/boot.js.map +1 -1
- package/dist/cli/migrate.d.ts.map +1 -1
- package/dist/cli/migrate.js +22 -7
- package/dist/cli/migrate.js.map +1 -1
- package/dist/cli/office.d.ts.map +1 -1
- package/dist/cli/office.js +3 -5
- package/dist/cli/office.js.map +1 -1
- package/dist/cli/onboard.js +18 -20
- package/dist/cli/onboard.js.map +1 -1
- package/dist/cli/types.d.ts +1 -2
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js.map +1 -1
- package/dist/env-manifest.d.ts +2 -0
- package/dist/env-manifest.d.ts.map +1 -1
- package/dist/env-manifest.js +76 -43
- package/dist/env-manifest.js.map +1 -1
- package/dist/events/index.d.ts +5 -5
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +1 -7
- package/dist/events/index.js.map +1 -1
- package/dist/file-guards.d.ts +1 -0
- package/dist/file-guards.d.ts.map +1 -1
- package/dist/file-guards.js +4 -1
- package/dist/file-guards.js.map +1 -1
- package/dist/harness/execution-resolver.d.ts.map +1 -1
- package/dist/harness/execution-resolver.js +1 -7
- package/dist/harness/execution-resolver.js.map +1 -1
- package/dist/harness/http.d.ts +1 -2
- package/dist/harness/http.d.ts.map +1 -1
- package/dist/harness/http.js +3 -16
- package/dist/harness/http.js.map +1 -1
- package/dist/harness/jev.d.ts +2 -1
- package/dist/harness/jev.d.ts.map +1 -1
- package/dist/harness/jev.js.map +1 -1
- package/dist/harness/prompt.d.ts.map +1 -1
- package/dist/harness/prompt.js +0 -6
- package/dist/harness/prompt.js.map +1 -1
- package/dist/harness/session.d.ts +2 -9
- package/dist/harness/session.d.ts.map +1 -1
- package/dist/harness/session.js +3 -3
- package/dist/harness/session.js.map +1 -1
- package/dist/harness/tools/event.d.ts +0 -1
- package/dist/harness/tools/event.d.ts.map +1 -1
- package/dist/harness/tools/event.js +1 -7
- package/dist/harness/tools/event.js.map +1 -1
- package/dist/harness/types.d.ts +3 -3
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/index.d.ts +8 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -15
- package/dist/index.js.map +1 -1
- package/dist/main.js +26 -36
- package/dist/main.js.map +1 -1
- package/dist/migrations/index.d.ts +0 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +4 -4
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/legacy-office-files.d.ts +3 -0
- package/dist/migrations/legacy-office-files.d.ts.map +1 -0
- package/dist/migrations/legacy-office-files.js +29 -0
- package/dist/migrations/legacy-office-files.js.map +1 -0
- package/dist/observability/instrument.js +2 -3
- package/dist/observability/instrument.js.map +1 -1
- package/dist/observability/sentry.js +1 -1
- package/dist/observability/sentry.js.map +1 -1
- package/dist/office/projection.js +2 -2
- package/dist/office/projection.js.map +1 -1
- package/dist/sandbox/identity.d.ts +0 -1
- package/dist/sandbox/identity.d.ts.map +1 -1
- package/dist/sandbox/identity.js +0 -3
- package/dist/sandbox/identity.js.map +1 -1
- package/dist/sandbox/registry.d.ts +1 -5
- package/dist/sandbox/registry.d.ts.map +1 -1
- package/dist/sandbox/registry.js +4 -13
- package/dist/sandbox/registry.js.map +1 -1
- package/dist/sandbox/types.d.ts +1 -5
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sandbox/types.js.map +1 -1
- package/dist/sessions/types.d.ts +1 -1
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/settings/index.d.ts +56 -2
- package/dist/settings/index.d.ts.map +1 -1
- package/dist/settings/index.js +57 -37
- package/dist/settings/index.js.map +1 -1
- package/dist/types.d.ts +1 -25
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/vault/index.js +1 -1
- package/dist/vault/index.js.map +1 -1
- package/package.json +4 -17
- package/dist/cli/download.d.ts +0 -2
- package/dist/cli/download.d.ts.map +0 -1
- package/dist/cli/download.js +0 -84
- package/dist/cli/download.js.map +0 -1
- package/dist/harness/index.d.ts +0 -20
- package/dist/harness/index.d.ts.map +0 -1
- package/dist/harness/index.js +0 -14
- package/dist/harness/index.js.map +0 -1
- package/dist/sandbox/cloudflare.d.ts +0 -17
- package/dist/sandbox/cloudflare.d.ts.map +0 -1
- package/dist/sandbox/cloudflare.js +0 -142
- package/dist/sandbox/cloudflare.js.map +0 -1
- package/dist/sandbox/index.d.ts +0 -7
- package/dist/sandbox/index.d.ts.map +0 -1
- package/dist/sandbox/index.js +0 -6
- package/dist/sandbox/index.js.map +0 -1
package/dist/cli/download.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { LogLevel, WebClient } from "@slack/web-api";
|
|
2
|
-
function formatTs(ts) {
|
|
3
|
-
const date = new Date(parseFloat(ts) * 1000);
|
|
4
|
-
return date
|
|
5
|
-
.toISOString()
|
|
6
|
-
.replace("T", " ")
|
|
7
|
-
.replace(/\.\d+Z$/, "");
|
|
8
|
-
}
|
|
9
|
-
function formatMessage(ts, user, text, indent = "") {
|
|
10
|
-
const prefix = `[${formatTs(ts)}] ${user}: `;
|
|
11
|
-
const lines = text.split("\n");
|
|
12
|
-
const firstLine = `${indent}${prefix}${lines[0]}`;
|
|
13
|
-
if (lines.length === 1)
|
|
14
|
-
return firstLine;
|
|
15
|
-
const contentIndent = indent + " ".repeat(prefix.length);
|
|
16
|
-
return [firstLine, ...lines.slice(1).map((l) => contentIndent + l)].join("\n");
|
|
17
|
-
}
|
|
18
|
-
export async function downloadChannel(channelId, botToken) {
|
|
19
|
-
const client = new WebClient(botToken, { logLevel: LogLevel.ERROR });
|
|
20
|
-
console.error(`Fetching channel info for ${channelId}...`);
|
|
21
|
-
const channelName = await resolveChannelName(client, channelId);
|
|
22
|
-
console.error(`Downloading history for #${channelName} (${channelId})...`);
|
|
23
|
-
const messages = await fetchHistory(client, channelId);
|
|
24
|
-
messages.reverse();
|
|
25
|
-
const threadReplies = await fetchThreadReplies(client, channelId, messages);
|
|
26
|
-
const totalReplies = printTranscript(messages, threadReplies);
|
|
27
|
-
console.error(`Done! ${messages.length} messages, ${totalReplies} thread replies`);
|
|
28
|
-
}
|
|
29
|
-
async function resolveChannelName(client, channelId) {
|
|
30
|
-
try {
|
|
31
|
-
const info = await client.conversations.info({ channel: channelId });
|
|
32
|
-
return typeof info.channel?.name === "string" ? info.channel.name : channelId;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return channelId;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async function* pages(fetchPage) {
|
|
39
|
-
let cursor;
|
|
40
|
-
do {
|
|
41
|
-
const response = await fetchPage(cursor);
|
|
42
|
-
yield (response.messages ?? []);
|
|
43
|
-
cursor = response.response_metadata?.next_cursor;
|
|
44
|
-
} while (cursor);
|
|
45
|
-
}
|
|
46
|
-
async function fetchHistory(client, channelId) {
|
|
47
|
-
const messages = [];
|
|
48
|
-
const fetchPage = (cursor) => client.conversations.history({ channel: channelId, limit: 200, cursor });
|
|
49
|
-
for await (const page of pages(fetchPage)) {
|
|
50
|
-
messages.push(...page);
|
|
51
|
-
console.error(` Fetched ${messages.length} messages...`);
|
|
52
|
-
}
|
|
53
|
-
return messages;
|
|
54
|
-
}
|
|
55
|
-
async function fetchThreadReplies(client, channelId, messages) {
|
|
56
|
-
const parents = messages.filter((message) => message.reply_count && message.reply_count > 0);
|
|
57
|
-
console.error(`Fetching ${parents.length} threads...`);
|
|
58
|
-
const threadReplies = new Map();
|
|
59
|
-
for (const [index, parent] of parents.entries()) {
|
|
60
|
-
console.error(` Thread ${index + 1}/${parents.length} (${parent.reply_count} replies)...`);
|
|
61
|
-
threadReplies.set(parent.ts, await fetchReplies(client, channelId, parent.ts));
|
|
62
|
-
}
|
|
63
|
-
return threadReplies;
|
|
64
|
-
}
|
|
65
|
-
async function fetchReplies(client, channelId, ts) {
|
|
66
|
-
const replies = [];
|
|
67
|
-
const fetchPage = (cursor) => client.conversations.replies({ channel: channelId, ts, limit: 200, cursor });
|
|
68
|
-
for await (const page of pages(fetchPage)) {
|
|
69
|
-
replies.push(...page.slice(1));
|
|
70
|
-
}
|
|
71
|
-
return replies;
|
|
72
|
-
}
|
|
73
|
-
function printTranscript(messages, threadReplies) {
|
|
74
|
-
let totalReplies = 0;
|
|
75
|
-
for (const message of messages) {
|
|
76
|
-
console.log(formatMessage(message.ts, message.user || "unknown", message.text || ""));
|
|
77
|
-
for (const reply of threadReplies.get(message.ts) ?? []) {
|
|
78
|
-
console.log(formatMessage(reply.ts, reply.user || "unknown", reply.text || "", " "));
|
|
79
|
-
totalReplies++;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return totalReplies;
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=download.js.map
|
package/dist/cli/download.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download.js","sourceRoot":"","sources":["../../src/cli/download.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAWrD,SAAS,QAAQ,CAAC,EAAU;IAC1B,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7C,OAAO,IAAI;SACR,WAAW,EAAE;SACb,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;SACjB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,aAAa,CAAC,EAAU,EAAE,IAAY,EAAE,IAAY,EAAE,MAAM,GAAG,EAAE;IACxE,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAG,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACzC,MAAM,aAAa,GAAG,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACzD,OAAO,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE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G,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,IAAI,SAAS,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;YACtF,YAAY,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import { LogLevel, WebClient } from \"@slack/web-api\";\n\ninterface Message {\n ts: string;\n user?: string;\n text?: string;\n thread_ts?: string;\n reply_count?: number;\n files?: Array<{ name: string; url_private?: string }>;\n}\n\nfunction formatTs(ts: string): string {\n const date = new Date(parseFloat(ts) * 1000);\n return date\n .toISOString()\n .replace(\"T\", \" \")\n .replace(/\\.\\d+Z$/, \"\");\n}\n\nfunction formatMessage(ts: string, user: string, text: string, indent = \"\"): string {\n const prefix = `[${formatTs(ts)}] ${user}: `;\n const lines = text.split(\"\\n\");\n const firstLine = `${indent}${prefix}${lines[0]}`;\n if (lines.length === 1) return firstLine;\n const contentIndent = indent + \" \".repeat(prefix.length);\n return [firstLine, ...lines.slice(1).map((l) => contentIndent + l)].join(\"\\n\");\n}\n\nexport async function downloadChannel(channelId: string, botToken: string): Promise<void> {\n const client = new WebClient(botToken, { logLevel: LogLevel.ERROR });\n\n console.error(`Fetching channel info for ${channelId}...`);\n const channelName = await resolveChannelName(client, channelId);\n console.error(`Downloading history for #${channelName} (${channelId})...`);\n\n const messages = await fetchHistory(client, channelId);\n messages.reverse();\n\n const threadReplies = await fetchThreadReplies(client, channelId, messages);\n const totalReplies = printTranscript(messages, threadReplies);\n console.error(`Done! ${messages.length} messages, ${totalReplies} thread replies`);\n}\n\nasync function resolveChannelName(client: WebClient, channelId: string): Promise<string> {\n try {\n const info = await client.conversations.info({ channel: channelId });\n return typeof info.channel?.name === \"string\" ? info.channel.name : channelId;\n } catch {\n return channelId;\n }\n}\n\ninterface Page {\n messages?: unknown[];\n response_metadata?: { next_cursor?: string };\n}\n\nasync function* pages(fetchPage: (cursor?: string) => Promise<Page>): AsyncGenerator<Message[]> {\n let cursor: string | undefined;\n do {\n const response = await fetchPage(cursor);\n yield (response.messages ?? []) as Message[];\n cursor = response.response_metadata?.next_cursor;\n } while (cursor);\n}\n\nasync function fetchHistory(client: WebClient, channelId: string): Promise<Message[]> {\n const messages: Message[] = [];\n const fetchPage = (cursor?: string) =>\n client.conversations.history({ channel: channelId, limit: 200, cursor });\n for await (const page of pages(fetchPage)) {\n messages.push(...page);\n console.error(` Fetched ${messages.length} messages...`);\n }\n return messages;\n}\n\nasync function fetchThreadReplies(\n client: WebClient,\n channelId: string,\n messages: readonly Message[],\n): Promise<Map<string, Message[]>> {\n const parents = messages.filter((message) => message.reply_count && message.reply_count > 0);\n console.error(`Fetching ${parents.length} threads...`);\n\n const threadReplies = new Map<string, Message[]>();\n for (const [index, parent] of parents.entries()) {\n console.error(` Thread ${index + 1}/${parents.length} (${parent.reply_count} replies)...`);\n threadReplies.set(parent.ts, await fetchReplies(client, channelId, parent.ts));\n }\n return threadReplies;\n}\n\nasync function fetchReplies(client: WebClient, channelId: string, ts: string): Promise<Message[]> {\n const replies: Message[] = [];\n const fetchPage = (cursor?: string) =>\n client.conversations.replies({ channel: channelId, ts, limit: 200, cursor });\n for await (const page of pages(fetchPage)) {\n replies.push(...page.slice(1));\n }\n return replies;\n}\n\nfunction printTranscript(\n messages: readonly Message[],\n threadReplies: ReadonlyMap<string, Message[]>,\n): number {\n let totalReplies = 0;\n for (const message of messages) {\n console.log(formatMessage(message.ts, message.user || \"unknown\", message.text || \"\"));\n for (const reply of threadReplies.get(message.ts) ?? []) {\n console.log(formatMessage(reply.ts, reply.user || \"unknown\", reply.text || \"\", \" \"));\n totalReplies++;\n }\n }\n return totalReplies;\n}\n"]}
|
package/dist/harness/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export { DEFAULT_HTTP_IDLE_TIMEOUT_MS, configureHttpDispatcher, parseHttpIdleTimeoutMs, } from "./http.js";
|
|
2
|
-
export { MikanModels, defaultModelsJsonPath } from "./models.js";
|
|
3
|
-
export type { CreateMikanModelsOptions } from "./types.js";
|
|
4
|
-
export { JEV_MODEL_ID, JevNotConfiguredError, JevRequestError, evaluateWithJev, type EvaluateWithJevOptions, type JevAnswer, type JevEntry, type JevQuestion, type JevQuestions, type JevResult, } from "./jev.js";
|
|
5
|
-
export { SessionStore } from "../sessions/session-store.js";
|
|
6
|
-
export type { SessionContext, SessionCompactionEntry, SessionCustomEntry, SessionEntry, SessionHeader, SessionMessageEntry, } from "../sessions/types.js";
|
|
7
|
-
export { MikanAgentSession } from "./session.js";
|
|
8
|
-
export { runSubagent } from "./subagent.js";
|
|
9
|
-
export { resolveTriggerAttribution } from "./prompt.js";
|
|
10
|
-
export { isEventTriggerAttribution } from "./presenter.js";
|
|
11
|
-
export { redactSecrets } from "./tools/secret-redaction.js";
|
|
12
|
-
export type { CompactionReason, HarnessEvent, HarnessEventListener, MikanAgentSessionOptions, } from "./types.js";
|
|
13
|
-
export { formatSkillsForPrompt, loadSkillsFromDir, parseFrontmatter, validateSkill, } from "./skills.js";
|
|
14
|
-
export type { LoadSkillsResult, MikanSkill, SkillDiagnostic } from "./types.js";
|
|
15
|
-
export { loadSubagentProfiles } from "./subagent-profiles.js";
|
|
16
|
-
export type { LoadSubagentProfilesResult, SubagentProfileDiagnostic } from "./types.js";
|
|
17
|
-
export { DEFAULT_BUDGET_SETTINGS, DEFAULT_EVENT_BUDGET, DEFAULT_RETRY_SETTINGS, resolveHarnessSettings, type CompactionSettings, } from "./session.js";
|
|
18
|
-
export type { BudgetSettings, HarnessSettings, RetrySettings } from "./types.js";
|
|
19
|
-
export { type SubagentModelSpec, type SubagentProfile, type SubagentParentContext, type SubagentRunBudget, type SubagentRunOutput, type SubagentRunRequest, type SubagentRunResult, type SubagentRunStatus, type SubagentUsage, type SubagentUsageSink, } from "./types.js";
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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AAE,MAAM,YAAY,CAAC;AACxF,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,kBAAkB,GACxB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,iBAAiB,GACvB,MAAM,YAAY,CAAC"}
|
package/dist/harness/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { DEFAULT_HTTP_IDLE_TIMEOUT_MS, configureHttpDispatcher, parseHttpIdleTimeoutMs, } from "./http.js";
|
|
2
|
-
export { MikanModels, defaultModelsJsonPath } from "./models.js";
|
|
3
|
-
export { JEV_MODEL_ID, JevNotConfiguredError, JevRequestError, evaluateWithJev, } from "./jev.js";
|
|
4
|
-
export { SessionStore } from "../sessions/session-store.js";
|
|
5
|
-
export { MikanAgentSession } from "./session.js";
|
|
6
|
-
export { runSubagent } from "./subagent.js";
|
|
7
|
-
export { resolveTriggerAttribution } from "./prompt.js";
|
|
8
|
-
export { isEventTriggerAttribution } from "./presenter.js";
|
|
9
|
-
export { redactSecrets } from "./tools/secret-redaction.js";
|
|
10
|
-
export { formatSkillsForPrompt, loadSkillsFromDir, parseFrontmatter, validateSkill, } from "./skills.js";
|
|
11
|
-
export { loadSubagentProfiles } from "./subagent-profiles.js";
|
|
12
|
-
export { DEFAULT_BUDGET_SETTINGS, DEFAULT_EVENT_BUDGET, DEFAULT_RETRY_SETTINGS, resolveHarnessSettings, } from "./session.js";
|
|
13
|
-
export {} from "./types.js";
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/harness/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,eAAe,GAOhB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAS5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAO5D,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GAEvB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAWN,MAAM,YAAY,CAAC","sourcesContent":["export {\n DEFAULT_HTTP_IDLE_TIMEOUT_MS,\n configureHttpDispatcher,\n parseHttpIdleTimeoutMs,\n} from \"./http.js\";\nexport { MikanModels, defaultModelsJsonPath } from \"./models.js\";\nexport type { CreateMikanModelsOptions } from \"./types.js\";\nexport {\n JEV_MODEL_ID,\n JevNotConfiguredError,\n JevRequestError,\n evaluateWithJev,\n type EvaluateWithJevOptions,\n type JevAnswer,\n type JevEntry,\n type JevQuestion,\n type JevQuestions,\n type JevResult,\n} from \"./jev.js\";\nexport { SessionStore } from \"../sessions/session-store.js\";\nexport type {\n SessionContext,\n SessionCompactionEntry,\n SessionCustomEntry,\n SessionEntry,\n SessionHeader,\n SessionMessageEntry,\n} from \"../sessions/types.js\";\nexport { MikanAgentSession } from \"./session.js\";\nexport { runSubagent } from \"./subagent.js\";\nexport { resolveTriggerAttribution } from \"./prompt.js\";\nexport { isEventTriggerAttribution } from \"./presenter.js\";\nexport { redactSecrets } from \"./tools/secret-redaction.js\";\nexport type {\n CompactionReason,\n HarnessEvent,\n HarnessEventListener,\n MikanAgentSessionOptions,\n} from \"./types.js\";\nexport {\n formatSkillsForPrompt,\n loadSkillsFromDir,\n parseFrontmatter,\n validateSkill,\n} from \"./skills.js\";\nexport type { LoadSkillsResult, MikanSkill, SkillDiagnostic } from \"./types.js\";\nexport { loadSubagentProfiles } from \"./subagent-profiles.js\";\nexport type { LoadSubagentProfilesResult, SubagentProfileDiagnostic } from \"./types.js\";\nexport {\n DEFAULT_BUDGET_SETTINGS,\n DEFAULT_EVENT_BUDGET,\n DEFAULT_RETRY_SETTINGS,\n resolveHarnessSettings,\n type CompactionSettings,\n} from \"./session.js\";\nexport type { BudgetSettings, HarnessSettings, RetrySettings } from \"./types.js\";\nexport {\n type SubagentModelSpec,\n type SubagentProfile,\n type SubagentParentContext,\n type SubagentRunBudget,\n type SubagentRunOutput,\n type SubagentRunRequest,\n type SubagentRunResult,\n type SubagentRunStatus,\n type SubagentUsage,\n type SubagentUsageSink,\n} from \"./types.js\";\n"]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { CloudflareSandboxConfig, ExecOptions, ExecResult, Executor, RuntimePathContext, SandboxAdapter } from "./types.js";
|
|
2
|
-
export declare class CloudflareSandboxExecutor implements Executor {
|
|
3
|
-
private readonly sandboxId;
|
|
4
|
-
private readonly env?;
|
|
5
|
-
private readonly cwd;
|
|
6
|
-
constructor(sandboxId: string, env?: Record<string, string> | undefined, _ensureReady?: () => Promise<void>);
|
|
7
|
-
exec(command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
8
|
-
private postExec;
|
|
9
|
-
readFile(path: string, options?: ExecOptions): Promise<string>;
|
|
10
|
-
readFileBase64(path: string, options?: ExecOptions): Promise<string>;
|
|
11
|
-
writeFile(path: string, content: string, options?: ExecOptions): Promise<void>;
|
|
12
|
-
getWorkspacePath(_hostPath: string): string;
|
|
13
|
-
getPathContext(hostWorkspaceRoot: string): RuntimePathContext;
|
|
14
|
-
getSandboxConfig(): CloudflareSandboxConfig;
|
|
15
|
-
}
|
|
16
|
-
export declare const cloudflareSandboxAdapter: SandboxAdapter<CloudflareSandboxConfig>;
|
|
17
|
-
//# sourceMappingURL=cloudflare.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/sandbox/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,kBAAkB,EAClB,cAAc,EACf,MAAM,YAAY,CAAC;AAoEpB,qBAAa,yBAA0B,YAAW,QAAQ;IAItD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;IAJvB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAE7B,YACmB,SAAS,EAAE,MAAM,EACjB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,YAAA,EAC7C,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAGnC;IAEK,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAkBtE;YAEa,QAAQ;IAwCtB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAE7D;IAED,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAEnE;IAED,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7E;IAED,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE1C;IAED,cAAc,CAAC,iBAAiB,EAAE,MAAM,GAAG,kBAAkB,CAK5D;IAED,gBAAgB,IAAI,uBAAuB,CAE1C;CACF;AAED,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,uBAAuB,CAQ5E,CAAC"}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { SandboxError, execReadFile, execReadFileBase64, execWriteFile, linkAbortSignal, } from "./utils.js";
|
|
2
|
-
import { readEnv } from "../env-manifest.js";
|
|
3
|
-
import { GUEST_WORKSPACE_ROOT } from "./layout.js";
|
|
4
|
-
import { errorMessage } from "../unknown-values.js";
|
|
5
|
-
const DEFAULT_CLOUDFLARE_CWD = GUEST_WORKSPACE_ROOT;
|
|
6
|
-
function parseCloudflareSandboxArg(value) {
|
|
7
|
-
if (!value.startsWith("cloudflare:")) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
const sandboxId = value.slice("cloudflare:".length).trim();
|
|
11
|
-
if (!sandboxId) {
|
|
12
|
-
throw new SandboxError("Error: cloudflare sandbox requires sandbox id (e.g., cloudflare:slack-u123)");
|
|
13
|
-
}
|
|
14
|
-
return { type: "cloudflare", sandboxId };
|
|
15
|
-
}
|
|
16
|
-
async function validateCloudflareSandbox(_config) {
|
|
17
|
-
const url = resolveCloudflareSandboxUrl();
|
|
18
|
-
try {
|
|
19
|
-
const response = await fetch(new URL("/health", url), {
|
|
20
|
-
headers: buildCloudflareHeaders(),
|
|
21
|
-
});
|
|
22
|
-
if (!response.ok) {
|
|
23
|
-
throw new SandboxError(`Error: Cloudflare sandbox bridge health check failed with HTTP ${response.status}`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
if (error instanceof SandboxError) {
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
const detail = errorMessage(error);
|
|
31
|
-
throw new SandboxError(`Error: Cloudflare sandbox bridge is not reachable: ${detail}`);
|
|
32
|
-
}
|
|
33
|
-
console.log(` Cloudflare sandbox bridge enabled. Base URL: ${url.toString().replace(/\/$/, "")}`);
|
|
34
|
-
}
|
|
35
|
-
export class CloudflareSandboxExecutor {
|
|
36
|
-
constructor(sandboxId, env, _ensureReady) {
|
|
37
|
-
this.sandboxId = sandboxId;
|
|
38
|
-
this.env = env;
|
|
39
|
-
this.cwd = DEFAULT_CLOUDFLARE_CWD;
|
|
40
|
-
}
|
|
41
|
-
async exec(command, options) {
|
|
42
|
-
const controller = new AbortController();
|
|
43
|
-
const timeoutHandle = options?.timeout && options.timeout > 0
|
|
44
|
-
? setTimeout(() => controller.abort(), options.timeout * 1000)
|
|
45
|
-
: undefined;
|
|
46
|
-
const unlinkSignal = linkAbortSignal(options?.signal, () => controller.abort());
|
|
47
|
-
try {
|
|
48
|
-
return await this.postExec(command, options, controller.signal);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
if (!controller.signal.aborted)
|
|
52
|
-
throw error;
|
|
53
|
-
if (options?.signal?.aborted)
|
|
54
|
-
throw new Error("Command aborted", { cause: error });
|
|
55
|
-
throw new Error(`Command timed out after ${options?.timeout} seconds`, { cause: error });
|
|
56
|
-
}
|
|
57
|
-
finally {
|
|
58
|
-
if (timeoutHandle)
|
|
59
|
-
clearTimeout(timeoutHandle);
|
|
60
|
-
unlinkSignal();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
async postExec(command, options, signal) {
|
|
64
|
-
const payload = {
|
|
65
|
-
sandboxId: this.sandboxId,
|
|
66
|
-
command,
|
|
67
|
-
cwd: options?.cwd ?? this.cwd,
|
|
68
|
-
};
|
|
69
|
-
if (options?.timeout)
|
|
70
|
-
payload.timeoutSeconds = options.timeout;
|
|
71
|
-
if (this.env && Object.keys(this.env).length > 0)
|
|
72
|
-
payload.env = this.env;
|
|
73
|
-
const response = await fetch(new URL("/exec", resolveCloudflareSandboxUrl()), {
|
|
74
|
-
method: "POST",
|
|
75
|
-
headers: {
|
|
76
|
-
"content-type": "application/json",
|
|
77
|
-
...buildCloudflareHeaders(),
|
|
78
|
-
},
|
|
79
|
-
body: JSON.stringify(payload),
|
|
80
|
-
signal,
|
|
81
|
-
});
|
|
82
|
-
const raw = (await response.text()).trim();
|
|
83
|
-
const parsed = raw ? JSON.parse(raw) : {};
|
|
84
|
-
if (!response.ok) {
|
|
85
|
-
throw new Error(parsed.error ||
|
|
86
|
-
parsed.stderr ||
|
|
87
|
-
`Cloudflare sandbox bridge returned HTTP ${response.status}`);
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
stdout: parsed.stdout || "",
|
|
91
|
-
stderr: parsed.stderr || "",
|
|
92
|
-
code: parsed.code ?? 0,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
readFile(path, options) {
|
|
96
|
-
return execReadFile(this, path, options);
|
|
97
|
-
}
|
|
98
|
-
readFileBase64(path, options) {
|
|
99
|
-
return execReadFileBase64(this, path, options);
|
|
100
|
-
}
|
|
101
|
-
writeFile(path, content, options) {
|
|
102
|
-
return execWriteFile(this, path, content, options);
|
|
103
|
-
}
|
|
104
|
-
getWorkspacePath(_hostPath) {
|
|
105
|
-
return this.cwd;
|
|
106
|
-
}
|
|
107
|
-
getPathContext(hostWorkspaceRoot) {
|
|
108
|
-
return {
|
|
109
|
-
hostWorkspaceRoot,
|
|
110
|
-
runtimeWorkspaceRoot: this.cwd,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
getSandboxConfig() {
|
|
114
|
-
return { type: "cloudflare", sandboxId: this.sandboxId };
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
export const cloudflareSandboxAdapter = {
|
|
118
|
-
type: "cloudflare",
|
|
119
|
-
credentials: { env: true, fileMounts: false },
|
|
120
|
-
workspace: { managedProjection: false },
|
|
121
|
-
parse: parseCloudflareSandboxArg,
|
|
122
|
-
validate: validateCloudflareSandbox,
|
|
123
|
-
createExecutor: (config, env, ensureReady) => new CloudflareSandboxExecutor(config.sandboxId, env, ensureReady),
|
|
124
|
-
};
|
|
125
|
-
function resolveCloudflareSandboxUrl() {
|
|
126
|
-
const raw = readEnv("CLOUDFLARE_SANDBOX_URL");
|
|
127
|
-
if (!raw) {
|
|
128
|
-
throw new SandboxError("Error: CLOUDFLARE_SANDBOX_URL or MIKAN_CLOUDFLARE_SANDBOX_URL is required for cloudflare sandbox mode");
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
return new URL(raw);
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
const detail = errorMessage(error);
|
|
135
|
-
throw new SandboxError(`Error: invalid CLOUDFLARE_SANDBOX_URL: ${detail}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function buildCloudflareHeaders() {
|
|
139
|
-
const token = readEnv("CLOUDFLARE_SANDBOX_TOKEN");
|
|
140
|
-
return token ? { authorization: `Bearer ${token}` } : {};
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=cloudflare.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../../src/sandbox/cloudflare.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,sBAAsB,G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;IACJ,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QACnC,MAAM,IAAI,YAAY,CAAC,0CAA0C,MAAM,EAAE,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAClD,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3D,CAAC","sourcesContent":["import type {\n CloudflareSandboxConfig,\n ExecOptions,\n ExecResult,\n Executor,\n RuntimePathContext,\n SandboxAdapter,\n} from \"./types.js\";\nimport {\n SandboxError,\n execReadFile,\n execReadFileBase64,\n execWriteFile,\n linkAbortSignal,\n} from \"./utils.js\";\nimport { readEnv } from \"../env-manifest.js\";\nimport { GUEST_WORKSPACE_ROOT } from \"./layout.js\";\nimport { errorMessage } from \"../unknown-values.js\";\n\nconst DEFAULT_CLOUDFLARE_CWD = GUEST_WORKSPACE_ROOT;\n\ninterface CloudflareExecPayload {\n sandboxId: string;\n command: string;\n timeoutSeconds?: number;\n cwd?: string;\n env?: Record<string, string>;\n}\n\ninterface CloudflareExecResponse {\n stdout?: string;\n stderr?: string;\n code?: number;\n error?: string;\n}\n\nfunction parseCloudflareSandboxArg(value: string): CloudflareSandboxConfig | undefined {\n if (!value.startsWith(\"cloudflare:\")) {\n return undefined;\n }\n\n const sandboxId = value.slice(\"cloudflare:\".length).trim();\n if (!sandboxId) {\n throw new SandboxError(\n \"Error: cloudflare sandbox requires sandbox id (e.g., cloudflare:slack-u123)\",\n );\n }\n\n return { type: \"cloudflare\", sandboxId };\n}\n\nasync function validateCloudflareSandbox(_config: CloudflareSandboxConfig): Promise<void> {\n const url = resolveCloudflareSandboxUrl();\n try {\n const response = await fetch(new URL(\"/health\", url), {\n headers: buildCloudflareHeaders(),\n });\n if (!response.ok) {\n throw new SandboxError(\n `Error: Cloudflare sandbox bridge health check failed with HTTP ${response.status}`,\n );\n }\n } catch (error) {\n if (error instanceof SandboxError) {\n throw error;\n }\n const detail = errorMessage(error);\n throw new SandboxError(`Error: Cloudflare sandbox bridge is not reachable: ${detail}`);\n }\n\n console.log(\n ` Cloudflare sandbox bridge enabled. Base URL: ${url.toString().replace(/\\/$/, \"\")}`,\n );\n}\n\nexport class CloudflareSandboxExecutor implements Executor {\n private readonly cwd: string;\n\n constructor(\n private readonly sandboxId: string,\n private readonly env?: Record<string, string>,\n _ensureReady?: () => Promise<void>,\n ) {\n this.cwd = DEFAULT_CLOUDFLARE_CWD;\n }\n\n async exec(command: string, options?: ExecOptions): Promise<ExecResult> {\n const controller = new AbortController();\n const timeoutHandle =\n options?.timeout && options.timeout > 0\n ? setTimeout(() => controller.abort(), options.timeout * 1000)\n : undefined;\n const unlinkSignal = linkAbortSignal(options?.signal, () => controller.abort());\n\n try {\n return await this.postExec(command, options, controller.signal);\n } catch (error) {\n if (!controller.signal.aborted) throw error;\n if (options?.signal?.aborted) throw new Error(\"Command aborted\", { cause: error });\n throw new Error(`Command timed out after ${options?.timeout} seconds`, { cause: error });\n } finally {\n if (timeoutHandle) clearTimeout(timeoutHandle);\n unlinkSignal();\n }\n }\n\n private async postExec(\n command: string,\n options: ExecOptions | undefined,\n signal: AbortSignal,\n ): Promise<ExecResult> {\n const payload: CloudflareExecPayload = {\n sandboxId: this.sandboxId,\n command,\n cwd: options?.cwd ?? this.cwd,\n };\n if (options?.timeout) payload.timeoutSeconds = options.timeout;\n if (this.env && Object.keys(this.env).length > 0) payload.env = this.env;\n\n const response = await fetch(new URL(\"/exec\", resolveCloudflareSandboxUrl()), {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...buildCloudflareHeaders(),\n },\n body: JSON.stringify(payload),\n signal,\n });\n\n const raw = (await response.text()).trim();\n const parsed = raw ? (JSON.parse(raw) as CloudflareExecResponse) : {};\n if (!response.ok) {\n throw new Error(\n parsed.error ||\n parsed.stderr ||\n `Cloudflare sandbox bridge returned HTTP ${response.status}`,\n );\n }\n\n return {\n stdout: parsed.stdout || \"\",\n stderr: parsed.stderr || \"\",\n code: parsed.code ?? 0,\n };\n }\n\n readFile(path: string, options?: ExecOptions): Promise<string> {\n return execReadFile(this, path, options);\n }\n\n readFileBase64(path: string, options?: ExecOptions): Promise<string> {\n return execReadFileBase64(this, path, options);\n }\n\n writeFile(path: string, content: string, options?: ExecOptions): Promise<void> {\n return execWriteFile(this, path, content, options);\n }\n\n getWorkspacePath(_hostPath: string): string {\n return this.cwd;\n }\n\n getPathContext(hostWorkspaceRoot: string): RuntimePathContext {\n return {\n hostWorkspaceRoot,\n runtimeWorkspaceRoot: this.cwd,\n };\n }\n\n getSandboxConfig(): CloudflareSandboxConfig {\n return { type: \"cloudflare\", sandboxId: this.sandboxId };\n }\n}\n\nexport const cloudflareSandboxAdapter: SandboxAdapter<CloudflareSandboxConfig> = {\n type: \"cloudflare\",\n credentials: { env: true, fileMounts: false },\n workspace: { managedProjection: false },\n parse: parseCloudflareSandboxArg,\n validate: validateCloudflareSandbox,\n createExecutor: (config, env, ensureReady) =>\n new CloudflareSandboxExecutor(config.sandboxId, env, ensureReady),\n};\n\nfunction resolveCloudflareSandboxUrl(): URL {\n const raw = readEnv(\"CLOUDFLARE_SANDBOX_URL\");\n if (!raw) {\n throw new SandboxError(\n \"Error: CLOUDFLARE_SANDBOX_URL or MIKAN_CLOUDFLARE_SANDBOX_URL is required for cloudflare sandbox mode\",\n );\n }\n\n try {\n return new URL(raw);\n } catch (error) {\n const detail = errorMessage(error);\n throw new SandboxError(`Error: invalid CLOUDFLARE_SANDBOX_URL: ${detail}`);\n }\n}\n\nfunction buildCloudflareHeaders(): Record<string, string> {\n const token = readEnv(\"CLOUDFLARE_SANDBOX_TOKEN\");\n return token ? { authorization: `Bearer ${token}` } : {};\n}\n"]}
|
package/dist/sandbox/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type { CloudflareSandboxConfig, ExecOptions, ExecResult, Executor, RuntimePathContext, SandboxAdapter, SandboxConfig, } from "./types.js";
|
|
2
|
-
export { CloudflareSandboxExecutor } from "./cloudflare.js";
|
|
3
|
-
export { ContainerExecutor } from "./container.js";
|
|
4
|
-
export { HostExecutor } from "./host.js";
|
|
5
|
-
export { SandboxError } from "./utils.js";
|
|
6
|
-
export { warnUnenforcedPrivateOffice, createExecutor, getSandboxAdapters, getSandboxCredentialCapabilities, getSandboxWorkspaceCapabilities, getUnresolvedSandboxPathContext, parseSandboxArg, validateSandbox, } from "./registry.js";
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,uBAAuB,EACvB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,kBAAkB,EAClB,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EACL,2BAA2B,EAC3B,cAAc,EACd,kBAAkB,EAClB,gCAAgC,EAChC,+BAA+B,EAC/B,+BAA+B,EAC/B,eAAe,EACf,eAAe,GAChB,MAAM,eAAe,CAAC"}
|
package/dist/sandbox/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { CloudflareSandboxExecutor } from "./cloudflare.js";
|
|
2
|
-
export { ContainerExecutor } from "./container.js";
|
|
3
|
-
export { HostExecutor } from "./host.js";
|
|
4
|
-
export { SandboxError } from "./utils.js";
|
|
5
|
-
export { warnUnenforcedPrivateOffice, createExecutor, getSandboxAdapters, getSandboxCredentialCapabilities, getSandboxWorkspaceCapabilities, getUnresolvedSandboxPathContext, parseSandboxArg, validateSandbox, } from "./registry.js";
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EACL,2BAA2B,EAC3B,cAAc,EACd,kBAAkB,EAClB,gCAAgC,EAChC,+BAA+B,EAC/B,+BAA+B,EAC/B,eAAe,EACf,eAAe,GAChB,MAAM,eAAe,CAAC","sourcesContent":["export type {\n CloudflareSandboxConfig,\n ExecOptions,\n ExecResult,\n Executor,\n RuntimePathContext,\n SandboxAdapter,\n SandboxConfig,\n} from \"./types.js\";\nexport { CloudflareSandboxExecutor } from \"./cloudflare.js\";\nexport { ContainerExecutor } from \"./container.js\";\nexport { HostExecutor } from \"./host.js\";\nexport { SandboxError } from \"./utils.js\";\nexport {\n warnUnenforcedPrivateOffice,\n createExecutor,\n getSandboxAdapters,\n getSandboxCredentialCapabilities,\n getSandboxWorkspaceCapabilities,\n getUnresolvedSandboxPathContext,\n parseSandboxArg,\n validateSandbox,\n} from \"./registry.js\";\n"]}
|