@suwujs/king-ai 0.2.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/README.md +96 -0
- package/dist/src/agent-config-validation.d.ts +9 -0
- package/dist/src/agent-config-validation.js +30 -0
- package/dist/src/api.d.ts +4 -0
- package/dist/src/api.js +48 -0
- package/dist/src/attachments.d.ts +45 -0
- package/dist/src/attachments.js +322 -0
- package/dist/src/cli.d.ts +20 -0
- package/dist/src/cli.js +1697 -0
- package/dist/src/config.d.ts +3 -0
- package/dist/src/config.js +20 -0
- package/dist/src/cron.d.ts +11 -0
- package/dist/src/cron.js +65 -0
- package/dist/src/daemon.d.ts +36 -0
- package/dist/src/daemon.js +373 -0
- package/dist/src/engine.d.ts +32 -0
- package/dist/src/engine.js +1014 -0
- package/dist/src/heartbeat.d.ts +18 -0
- package/dist/src/heartbeat.js +28 -0
- package/dist/src/host-api.d.ts +40 -0
- package/dist/src/host-api.js +59 -0
- package/dist/src/host-control.d.ts +48 -0
- package/dist/src/host-control.js +1279 -0
- package/dist/src/host-export.d.ts +50 -0
- package/dist/src/host-export.js +187 -0
- package/dist/src/host-feedback.d.ts +78 -0
- package/dist/src/host-feedback.js +178 -0
- package/dist/src/host-home.d.ts +13 -0
- package/dist/src/host-home.js +54 -0
- package/dist/src/host-ledger.d.ts +261 -0
- package/dist/src/host-ledger.js +554 -0
- package/dist/src/host-loop-events.d.ts +69 -0
- package/dist/src/host-loop-events.js +288 -0
- package/dist/src/host-permission.d.ts +36 -0
- package/dist/src/host-permission.js +180 -0
- package/dist/src/host-policy.d.ts +15 -0
- package/dist/src/host-policy.js +36 -0
- package/dist/src/host-run-executor.d.ts +13 -0
- package/dist/src/host-run-executor.js +221 -0
- package/dist/src/host-run-heartbeat.d.ts +40 -0
- package/dist/src/host-run-heartbeat.js +103 -0
- package/dist/src/host-run-layout.d.ts +17 -0
- package/dist/src/host-run-layout.js +387 -0
- package/dist/src/host-run-meta.d.ts +41 -0
- package/dist/src/host-run-meta.js +115 -0
- package/dist/src/host-run-spec.d.ts +149 -0
- package/dist/src/host-run-spec.js +465 -0
- package/dist/src/host-runs.d.ts +77 -0
- package/dist/src/host-runs.js +195 -0
- package/dist/src/host-sdk.d.ts +412 -0
- package/dist/src/host-sdk.js +628 -0
- package/dist/src/host-server.d.ts +26 -0
- package/dist/src/host-server.js +921 -0
- package/dist/src/host-timeline.d.ts +24 -0
- package/dist/src/host-timeline.js +161 -0
- package/dist/src/jsonl.d.ts +13 -0
- package/dist/src/jsonl.js +47 -0
- package/dist/src/lifecycle.d.ts +5 -0
- package/dist/src/lifecycle.js +18 -0
- package/dist/src/message-routing.d.ts +32 -0
- package/dist/src/message-routing.js +119 -0
- package/dist/src/paths.d.ts +19 -0
- package/dist/src/paths.js +26 -0
- package/dist/src/project-profile.d.ts +49 -0
- package/dist/src/project-profile.js +356 -0
- package/dist/src/remediation.d.ts +14 -0
- package/dist/src/remediation.js +114 -0
- package/dist/src/remote-devices.d.ts +41 -0
- package/dist/src/remote-devices.js +156 -0
- package/dist/src/remote-diagnostics.d.ts +39 -0
- package/dist/src/remote-diagnostics.js +199 -0
- package/dist/src/remote-ssh.d.ts +39 -0
- package/dist/src/remote-ssh.js +129 -0
- package/dist/src/run-stream.d.ts +57 -0
- package/dist/src/run-stream.js +119 -0
- package/dist/src/runner.d.ts +131 -0
- package/dist/src/runner.js +1161 -0
- package/dist/src/runtime-data.d.ts +68 -0
- package/dist/src/runtime-data.js +172 -0
- package/dist/src/service.d.ts +114 -0
- package/dist/src/service.js +631 -0
- package/dist/src/shared-skills.d.ts +26 -0
- package/dist/src/shared-skills.js +85 -0
- package/dist/src/shim.d.ts +1 -0
- package/dist/src/shim.js +64 -0
- package/dist/src/skill-check.d.ts +17 -0
- package/dist/src/skill-check.js +158 -0
- package/dist/src/sse.d.ts +9 -0
- package/dist/src/sse.js +36 -0
- package/dist/src/team-routing.d.ts +55 -0
- package/dist/src/team-routing.js +131 -0
- package/dist/src/team-workflow.d.ts +78 -0
- package/dist/src/team-workflow.js +253 -0
- package/dist/src/text.d.ts +7 -0
- package/dist/src/text.js +27 -0
- package/dist/src/types.d.ts +98 -0
- package/dist/src/types.js +1 -0
- package/dist/src/usage.d.ts +116 -0
- package/dist/src/usage.js +350 -0
- package/dist/src/workspace.d.ts +9 -0
- package/dist/src/workspace.js +56 -0
- package/dist/src/worktree.d.ts +47 -0
- package/dist/src/worktree.js +201 -0
- package/package.json +63 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { HOST_RUNS_PATH } from "./paths.js";
|
|
4
|
+
import { createHostLaunchPlan, formatHostLaunchPlanSummary, toJsonSafeHostLaunchPlan } from "./host-run-spec.js";
|
|
5
|
+
export async function submitHostRunRequest(input, options = {}) {
|
|
6
|
+
const createdAt = (options.now ?? (() => new Date()))().toISOString();
|
|
7
|
+
const launchPlan = createHostLaunchPlan(input, options.env ?? process.env, options.availableEngines);
|
|
8
|
+
const request = {
|
|
9
|
+
id: cleanId(input.requestId) || launchPlan.runId,
|
|
10
|
+
status: "pending",
|
|
11
|
+
createdAt,
|
|
12
|
+
spec: input,
|
|
13
|
+
ready: launchPlan.ready,
|
|
14
|
+
effectiveEngine: launchPlan.effectiveEngine,
|
|
15
|
+
summary: formatHostLaunchPlanSummary(launchPlan),
|
|
16
|
+
executor: normalizeExecutor(input.executor)
|
|
17
|
+
};
|
|
18
|
+
await appendHostRunRequest(request, options.path);
|
|
19
|
+
return {
|
|
20
|
+
request,
|
|
21
|
+
launchPlan: toJsonSafeHostLaunchPlan(launchPlan),
|
|
22
|
+
summary: formatHostRunRequestSummary(request)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export async function listHostRunRequests(input = {}, path = HOST_RUNS_PATH) {
|
|
26
|
+
const limit = normalizeLimit(input.limit);
|
|
27
|
+
const requests = await readMergedHostRunRequests(path);
|
|
28
|
+
const status = normalizeStatus(input.status, true);
|
|
29
|
+
const filtered = status ? requests.filter((request) => request.status === status) : requests;
|
|
30
|
+
return filtered.slice(-limit).reverse();
|
|
31
|
+
}
|
|
32
|
+
export async function getHostRunRequest(input, path = HOST_RUNS_PATH) {
|
|
33
|
+
const id = cleanRequiredId(input.id, "run request id");
|
|
34
|
+
const requests = await readMergedHostRunRequests(path);
|
|
35
|
+
return requests.find((request) => request.id === id) ?? null;
|
|
36
|
+
}
|
|
37
|
+
export async function updateHostRunRequest(input, options = {}) {
|
|
38
|
+
const id = cleanRequiredId(input.id, "run request id");
|
|
39
|
+
const status = normalizeStatus(input.status, false);
|
|
40
|
+
const existing = await getHostRunRequest({ id }, options.path);
|
|
41
|
+
if (!existing)
|
|
42
|
+
throw new Error(`host run request not found: ${id}`);
|
|
43
|
+
const update = {
|
|
44
|
+
id,
|
|
45
|
+
status,
|
|
46
|
+
updatedAt: (options.now ?? (() => new Date()))().toISOString(),
|
|
47
|
+
detail: cleanString(input.detail),
|
|
48
|
+
result: normalizeExecutionResult(input.result)
|
|
49
|
+
};
|
|
50
|
+
await appendHostRunRecord(update, options.path);
|
|
51
|
+
const request = applyHostRunUpdate(existing, update);
|
|
52
|
+
return {
|
|
53
|
+
request,
|
|
54
|
+
summary: formatHostRunRequestSummary(request)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function formatHostRunRequests(requests) {
|
|
58
|
+
if (requests.length === 0)
|
|
59
|
+
return "no host run requests";
|
|
60
|
+
return requests.map(formatHostRunRequestSummary).join("\n\n");
|
|
61
|
+
}
|
|
62
|
+
export function formatHostRunRequestSummary(request) {
|
|
63
|
+
return [
|
|
64
|
+
`host run request: ${request.id} ${request.status}`,
|
|
65
|
+
`created: ${request.createdAt}`,
|
|
66
|
+
request.updatedAt ? `updated: ${request.updatedAt}` : "",
|
|
67
|
+
`ready: ${request.ready ? "yes" : "no"}`,
|
|
68
|
+
`effective engine: ${request.effectiveEngine ?? "(none)"}`,
|
|
69
|
+
request.detail ? `detail: ${request.detail}` : "",
|
|
70
|
+
request.executor ? `executor: ${request.executor.kind} ${request.executor.command}` : "",
|
|
71
|
+
request.result ? `result: ${request.result.command} ${request.result.ok ? "ok" : "failed"} exit=${request.result.exitCode}` : "",
|
|
72
|
+
request.summary
|
|
73
|
+
].filter(Boolean).join("\n");
|
|
74
|
+
}
|
|
75
|
+
async function appendHostRunRequest(request, path = HOST_RUNS_PATH) {
|
|
76
|
+
await appendHostRunRecord(request, path);
|
|
77
|
+
}
|
|
78
|
+
async function appendHostRunRecord(record, path = HOST_RUNS_PATH) {
|
|
79
|
+
await mkdir(dirname(path), { recursive: true });
|
|
80
|
+
await writeFile(path, `${JSON.stringify(record)}\n`, { encoding: "utf8", flag: "a" });
|
|
81
|
+
}
|
|
82
|
+
async function readMergedHostRunRequests(path = HOST_RUNS_PATH) {
|
|
83
|
+
const text = await readFile(path, "utf8").catch((err) => {
|
|
84
|
+
if (err && typeof err === "object" && "code" in err && err.code === "ENOENT")
|
|
85
|
+
return "";
|
|
86
|
+
throw err;
|
|
87
|
+
});
|
|
88
|
+
const byId = new Map();
|
|
89
|
+
for (const line of text.split(/\r?\n/).map((entry) => entry.trim()).filter(Boolean)) {
|
|
90
|
+
const parsed = JSON.parse(line);
|
|
91
|
+
if (isHostRunRequest(parsed)) {
|
|
92
|
+
byId.set(parsed.id, parsed);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (isHostRunRequestUpdate(parsed)) {
|
|
96
|
+
const existing = byId.get(parsed.id);
|
|
97
|
+
if (existing)
|
|
98
|
+
byId.set(parsed.id, applyHostRunUpdate(existing, parsed));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return [...byId.values()];
|
|
102
|
+
}
|
|
103
|
+
function applyHostRunUpdate(request, update) {
|
|
104
|
+
return {
|
|
105
|
+
...request,
|
|
106
|
+
status: update.status,
|
|
107
|
+
updatedAt: update.updatedAt,
|
|
108
|
+
detail: update.detail ?? request.detail,
|
|
109
|
+
result: update.result ?? request.result
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function normalizeLimit(value) {
|
|
113
|
+
if (value === undefined)
|
|
114
|
+
return 20;
|
|
115
|
+
const limit = typeof value === "number" ? value : Number.parseInt(String(value), 10);
|
|
116
|
+
if (!Number.isFinite(limit) || limit < 1)
|
|
117
|
+
throw new Error("host run request limit must be a positive integer");
|
|
118
|
+
return Math.floor(limit);
|
|
119
|
+
}
|
|
120
|
+
function cleanId(value) {
|
|
121
|
+
if (typeof value !== "string" || !value.trim())
|
|
122
|
+
return undefined;
|
|
123
|
+
return value.trim().replace(/[^a-zA-Z0-9_.:-]+/g, "-").slice(0, 80);
|
|
124
|
+
}
|
|
125
|
+
function cleanRequiredId(value, label) {
|
|
126
|
+
const id = cleanId(value);
|
|
127
|
+
if (!id)
|
|
128
|
+
throw new Error(`${label} is required`);
|
|
129
|
+
return id;
|
|
130
|
+
}
|
|
131
|
+
function cleanString(value) {
|
|
132
|
+
if (typeof value !== "string" || !value.trim())
|
|
133
|
+
return undefined;
|
|
134
|
+
return value.trim().slice(0, 1000);
|
|
135
|
+
}
|
|
136
|
+
function normalizeExecutor(value) {
|
|
137
|
+
if (!value || typeof value !== "object")
|
|
138
|
+
return undefined;
|
|
139
|
+
const executor = value;
|
|
140
|
+
if (executor.kind !== "host-command")
|
|
141
|
+
return undefined;
|
|
142
|
+
const command = cleanString(executor.command);
|
|
143
|
+
if (!command)
|
|
144
|
+
return undefined;
|
|
145
|
+
return {
|
|
146
|
+
kind: "host-command",
|
|
147
|
+
command,
|
|
148
|
+
input: executor.input,
|
|
149
|
+
format: executor.format === "json" ? "json" : "text",
|
|
150
|
+
actorRole: cleanString(executor.actorRole),
|
|
151
|
+
trusted: executor.trusted === true
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function normalizeExecutionResult(value) {
|
|
155
|
+
if (!value || typeof value !== "object")
|
|
156
|
+
return undefined;
|
|
157
|
+
const result = value;
|
|
158
|
+
const command = cleanString(result.command);
|
|
159
|
+
if (!command || typeof result.ok !== "boolean")
|
|
160
|
+
return undefined;
|
|
161
|
+
const exitCode = Number(result.exitCode);
|
|
162
|
+
return {
|
|
163
|
+
command,
|
|
164
|
+
ok: result.ok,
|
|
165
|
+
exitCode: Number.isFinite(exitCode) ? Math.floor(exitCode) : result.ok ? 0 : 1,
|
|
166
|
+
textPreview: cleanString(result.textPreview),
|
|
167
|
+
error: cleanString(result.error)
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function normalizeStatus(value, allowPending) {
|
|
171
|
+
if (value === undefined)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (value === "pending" && allowPending)
|
|
174
|
+
return value;
|
|
175
|
+
if (value === "running" || value === "completed" || value === "failed" || value === "cancelled")
|
|
176
|
+
return value;
|
|
177
|
+
throw new Error(`host run request status must be ${allowPending ? "pending, " : ""}running, completed, failed, or cancelled`);
|
|
178
|
+
}
|
|
179
|
+
function isHostRunRequest(value) {
|
|
180
|
+
return Boolean(value) &&
|
|
181
|
+
typeof value === "object" &&
|
|
182
|
+
typeof value.id === "string" &&
|
|
183
|
+
value.status === "pending" &&
|
|
184
|
+
typeof value.createdAt === "string" &&
|
|
185
|
+
typeof value.ready === "boolean" &&
|
|
186
|
+
typeof value.summary === "string";
|
|
187
|
+
}
|
|
188
|
+
function isHostRunRequestUpdate(value) {
|
|
189
|
+
const status = value?.status;
|
|
190
|
+
return Boolean(value) &&
|
|
191
|
+
typeof value === "object" &&
|
|
192
|
+
typeof value.id === "string" &&
|
|
193
|
+
typeof value.updatedAt === "string" &&
|
|
194
|
+
(status === "running" || status === "completed" || status === "failed" || status === "cancelled");
|
|
195
|
+
}
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import type { HostStatusSnapshot } from "./host-api.js";
|
|
2
|
+
import type { HostCommandDefinition, HostCommandRequest, HostCommandResult } from "./host-control.js";
|
|
3
|
+
import type { DoctorResult } from "./daemon.js";
|
|
4
|
+
import type { HostExportInput, HostExportPlan, HostExportResult } from "./host-export.js";
|
|
5
|
+
import type { HostLoopEvent, HostLoopEventsInput, HostLoopEventsResult, HostLoopResultsInput, HostLoopResultsTable } from "./host-loop-events.js";
|
|
6
|
+
import type { HostRunExecuteResult } from "./host-run-executor.js";
|
|
7
|
+
import type { HostRunHeartbeatReadInput, HostRunHeartbeatReadResult } from "./host-run-heartbeat.js";
|
|
8
|
+
import type { HostRunMetaReadInput, HostRunMetaReadResult } from "./host-run-meta.js";
|
|
9
|
+
import type { HostRunLayoutResult } from "./host-run-layout.js";
|
|
10
|
+
import type { HostPolicyCheck } from "./host-policy.js";
|
|
11
|
+
import type { HostRunSpecInput, JsonSafeHostLaunchPlan, ProjectRunSpec, ThreadSyncSpec } from "./host-run-spec.js";
|
|
12
|
+
import type { HostRunRequest, HostRunRequestStatus, HostRunSubmitInput, HostRunSubmitResult, HostRunUpdateResult } from "./host-runs.js";
|
|
13
|
+
import type { HostTimelineEvent } from "./host-timeline.js";
|
|
14
|
+
import type { EngineId } from "./types.js";
|
|
15
|
+
import type { UsageExpenseRow, UsageSummary } from "./usage.js";
|
|
16
|
+
export interface HostSdkOptions {
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
fetch?: typeof fetch;
|
|
19
|
+
}
|
|
20
|
+
export type HostSdkEnvLike = Partial<Record<string, string | undefined>>;
|
|
21
|
+
export interface KingHostSdkConfig extends HostSdkOptions {
|
|
22
|
+
env?: HostSdkEnvLike;
|
|
23
|
+
}
|
|
24
|
+
export interface HostSdkEnvOptions extends Omit<HostSdkOptions, "baseUrl"> {
|
|
25
|
+
env?: HostSdkEnvLike;
|
|
26
|
+
}
|
|
27
|
+
export interface HostSdkLocationLike {
|
|
28
|
+
protocol: string;
|
|
29
|
+
hostname: string;
|
|
30
|
+
port?: string;
|
|
31
|
+
origin?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface HostSdkBrowserOptions extends HostSdkOptions {
|
|
34
|
+
location?: HostSdkLocationLike;
|
|
35
|
+
port?: number | string;
|
|
36
|
+
useCurrentOrigin?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface HostSdkWaitOptions {
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
intervalMs?: number;
|
|
41
|
+
requireDaemon?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface HostSdkWaitForRunOptions {
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
intervalMs?: number;
|
|
46
|
+
terminalStatuses?: HostRunRequestStatus[];
|
|
47
|
+
}
|
|
48
|
+
export interface HostSdkStatusStreamOptions {
|
|
49
|
+
intervalMs?: number;
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
}
|
|
52
|
+
export interface HostSdkTimelineStreamOptions {
|
|
53
|
+
intervalMs?: number;
|
|
54
|
+
limit?: number;
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}
|
|
57
|
+
export interface HostSdkRunRequestsStreamOptions {
|
|
58
|
+
intervalMs?: number;
|
|
59
|
+
limit?: number;
|
|
60
|
+
status?: HostRunRequestStatus;
|
|
61
|
+
signal?: AbortSignal;
|
|
62
|
+
}
|
|
63
|
+
export interface HostSdkRunRequestStreamOptions {
|
|
64
|
+
intervalMs?: number;
|
|
65
|
+
signal?: AbortSignal;
|
|
66
|
+
}
|
|
67
|
+
export interface HostSdkRunEventsOptions extends Omit<HostLoopEventsInput, "id"> {
|
|
68
|
+
}
|
|
69
|
+
export interface HostSdkRunEventEmitInput extends HostLoopEvent {
|
|
70
|
+
payload?: unknown;
|
|
71
|
+
}
|
|
72
|
+
export interface HostSdkRunResultsOptions extends Omit<HostLoopResultsInput, "id"> {
|
|
73
|
+
}
|
|
74
|
+
export interface HostSdkRunHeartbeatOptions extends Omit<HostRunHeartbeatReadInput, "id"> {
|
|
75
|
+
}
|
|
76
|
+
export interface HostSdkRunMetaOptions extends Omit<HostRunMetaReadInput, "id"> {
|
|
77
|
+
}
|
|
78
|
+
export interface HostSdkRunStateFrame {
|
|
79
|
+
request: HostRunRequest | null;
|
|
80
|
+
heartbeat: HostRunHeartbeatReadResult["heartbeat"];
|
|
81
|
+
meta: HostRunMetaReadResult["meta"];
|
|
82
|
+
}
|
|
83
|
+
export interface HostSdkHostStreamOptions {
|
|
84
|
+
intervalMs?: number;
|
|
85
|
+
limit?: number;
|
|
86
|
+
timelineLimit?: number;
|
|
87
|
+
runLimit?: number;
|
|
88
|
+
status?: HostRunRequestStatus;
|
|
89
|
+
signal?: AbortSignal;
|
|
90
|
+
}
|
|
91
|
+
export interface HostSdkWatchOptions extends HostSdkHostStreamOptions {
|
|
92
|
+
includeInitialSnapshot?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export type HostSdkStreamFrame = {
|
|
95
|
+
event: "status";
|
|
96
|
+
data: HostStatusSnapshot;
|
|
97
|
+
} | {
|
|
98
|
+
event: "timeline";
|
|
99
|
+
data: HostTimelineEvent[];
|
|
100
|
+
} | {
|
|
101
|
+
event: "runs";
|
|
102
|
+
data: HostRunRequest[];
|
|
103
|
+
};
|
|
104
|
+
export type HostSdkWatchFrame = {
|
|
105
|
+
event: "snapshot";
|
|
106
|
+
data: HostSnapshotResponse;
|
|
107
|
+
} | HostSdkStreamFrame;
|
|
108
|
+
export interface HostSdkRunOptions {
|
|
109
|
+
loops?: number;
|
|
110
|
+
pollInterval?: number;
|
|
111
|
+
pollIntervalSeconds?: number;
|
|
112
|
+
infinite?: boolean;
|
|
113
|
+
runtime?: EngineId;
|
|
114
|
+
engine?: EngineId;
|
|
115
|
+
codexModel?: string;
|
|
116
|
+
model?: string;
|
|
117
|
+
fastModel?: string;
|
|
118
|
+
codexReasoningEffort?: "low" | "medium" | "high" | "xhigh";
|
|
119
|
+
configPath?: string;
|
|
120
|
+
workerUrl?: string;
|
|
121
|
+
workerModel?: string;
|
|
122
|
+
workerKey?: string;
|
|
123
|
+
noBrain?: boolean;
|
|
124
|
+
enableBrain?: boolean;
|
|
125
|
+
projectDir?: string;
|
|
126
|
+
repoSourceDir?: string;
|
|
127
|
+
repoCloneUrl?: string;
|
|
128
|
+
workspaceRoot?: string;
|
|
129
|
+
gitRoot?: string;
|
|
130
|
+
outputDir?: string;
|
|
131
|
+
output?: string;
|
|
132
|
+
keepArtifacts?: boolean;
|
|
133
|
+
keep?: boolean;
|
|
134
|
+
errorLimit?: number;
|
|
135
|
+
}
|
|
136
|
+
export interface HostSdkTakeoverOptions extends HostSdkRunOptions {
|
|
137
|
+
projectPath?: string;
|
|
138
|
+
goalOverride?: string;
|
|
139
|
+
}
|
|
140
|
+
export type RunOptions = HostSdkRunOptions;
|
|
141
|
+
export type { ProjectRunSpec, ThreadSyncSpec };
|
|
142
|
+
export type KingHostRunOptions = HostSdkRunOptions;
|
|
143
|
+
export type KingHostRunInvocation = HostSdkRunOptions;
|
|
144
|
+
export type KingHostTakeoverOptions = HostSdkTakeoverOptions;
|
|
145
|
+
export interface KingHostSdkBindings {
|
|
146
|
+
hostEnv: HostSdkEnvLike;
|
|
147
|
+
}
|
|
148
|
+
export interface KingHostSdkAdapters<TProjectRunSpec, TPreparedTakeoverPlan, TConcreteTakeoverOptions extends object> {
|
|
149
|
+
runGoal(goal: string, options: HostSdkRunOptions, spec: TProjectRunSpec, bindings: KingHostSdkBindings): Promise<void>;
|
|
150
|
+
prepareTakeoverPlan(options: TConcreteTakeoverOptions): TPreparedTakeoverPlan;
|
|
151
|
+
executePreparedTakeoverPlan(plan: TPreparedTakeoverPlan, options: HostSdkRunOptions, bindings: KingHostSdkBindings): Promise<void>;
|
|
152
|
+
normalizeTakeoverOptions(options: TConcreteTakeoverOptions | KingHostTakeoverOptions): TConcreteTakeoverOptions;
|
|
153
|
+
}
|
|
154
|
+
export interface HostHealth {
|
|
155
|
+
ok: boolean;
|
|
156
|
+
service: string;
|
|
157
|
+
readOnly: boolean;
|
|
158
|
+
commands: string[];
|
|
159
|
+
}
|
|
160
|
+
export interface HostCommandsResponse {
|
|
161
|
+
ok: boolean;
|
|
162
|
+
commands: HostCommandDefinition[];
|
|
163
|
+
}
|
|
164
|
+
export interface HostCapabilitiesResponse extends HostCommandsResponse {
|
|
165
|
+
service: string;
|
|
166
|
+
readOnly: boolean;
|
|
167
|
+
localhostOnly: boolean;
|
|
168
|
+
cors?: {
|
|
169
|
+
enabled: boolean;
|
|
170
|
+
allowedOrigins: string[];
|
|
171
|
+
};
|
|
172
|
+
resources: string[];
|
|
173
|
+
streams: string[];
|
|
174
|
+
safeExecutorCommands: string[];
|
|
175
|
+
destructiveCommands: string[];
|
|
176
|
+
commandEnvelope: {
|
|
177
|
+
path: string;
|
|
178
|
+
method: string;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export interface HostEventsResponse {
|
|
182
|
+
ok: boolean;
|
|
183
|
+
events: HostStatusSnapshot["events"];
|
|
184
|
+
}
|
|
185
|
+
export interface HostTimelineResponse {
|
|
186
|
+
events: HostTimelineEvent[];
|
|
187
|
+
}
|
|
188
|
+
export interface HostSnapshotResponse {
|
|
189
|
+
ok: boolean;
|
|
190
|
+
status: HostStatusSnapshot;
|
|
191
|
+
capabilities: HostCapabilitiesResponse;
|
|
192
|
+
timeline: HostTimelineEvent[];
|
|
193
|
+
runs: HostRunRequest[];
|
|
194
|
+
}
|
|
195
|
+
export interface HostDoctorResponse {
|
|
196
|
+
results: DoctorResult[];
|
|
197
|
+
exitCode: number;
|
|
198
|
+
}
|
|
199
|
+
export interface HostExpensesResponse {
|
|
200
|
+
expenses: UsageExpenseRow[];
|
|
201
|
+
usage: UsageSummary;
|
|
202
|
+
}
|
|
203
|
+
export interface HostRunRequestsResponse {
|
|
204
|
+
requests: HostRunRequest[];
|
|
205
|
+
}
|
|
206
|
+
export interface HostRunRequestResponse {
|
|
207
|
+
request: HostRunRequest;
|
|
208
|
+
}
|
|
209
|
+
export interface HostSdkPrepareRunLayoutInput extends HostRunSpecInput {
|
|
210
|
+
force?: boolean;
|
|
211
|
+
confirmed?: boolean;
|
|
212
|
+
confirmation?: string;
|
|
213
|
+
}
|
|
214
|
+
export interface HostSdkSubmitAndExecuteResult {
|
|
215
|
+
submitted: HostCommandResult & {
|
|
216
|
+
json?: HostRunSubmitResult;
|
|
217
|
+
};
|
|
218
|
+
executed: HostCommandResult & {
|
|
219
|
+
json?: HostRunExecuteResult;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
export interface HostSdkPreparedTakeover {
|
|
223
|
+
options: HostSdkTakeoverOptions;
|
|
224
|
+
runOptions: HostSdkRunOptions;
|
|
225
|
+
input: HostRunSpecInput;
|
|
226
|
+
preflight: HostCommandResult & {
|
|
227
|
+
json?: JsonSafeHostLaunchPlan;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export interface HostSdkSubmitAndWatchOptions extends HostSdkRunRequestStreamOptions {
|
|
231
|
+
terminalStatuses?: HostRunRequestStatus[];
|
|
232
|
+
}
|
|
233
|
+
export type HostSdkSubmitAndWatchFrame = {
|
|
234
|
+
event: "submitted";
|
|
235
|
+
data: HostCommandResult & {
|
|
236
|
+
json?: HostRunSubmitResult;
|
|
237
|
+
};
|
|
238
|
+
} | {
|
|
239
|
+
event: "run";
|
|
240
|
+
data: HostRunRequest | null;
|
|
241
|
+
};
|
|
242
|
+
export type HostSdkSubmitAndWatchStateFrame = {
|
|
243
|
+
event: "submitted";
|
|
244
|
+
data: HostCommandResult & {
|
|
245
|
+
json?: HostRunSubmitResult;
|
|
246
|
+
};
|
|
247
|
+
} | {
|
|
248
|
+
event: "state";
|
|
249
|
+
data: HostSdkRunStateFrame;
|
|
250
|
+
};
|
|
251
|
+
export type HostSdk = ReturnType<typeof createHostSdk>;
|
|
252
|
+
export interface KingAdapterHostSdk<TProjectRunSpec = unknown, TPreparedTakeoverPlan = unknown, TTakeoverInvocation = KingHostTakeoverOptions> {
|
|
253
|
+
run(goal: string, options?: KingHostRunInvocation, spec?: TProjectRunSpec): Promise<void>;
|
|
254
|
+
prepareTakeover(options: TTakeoverInvocation): TPreparedTakeoverPlan;
|
|
255
|
+
executePreparedTakeover(plan: TPreparedTakeoverPlan, options?: KingHostRunInvocation): Promise<void>;
|
|
256
|
+
takeover(options: TTakeoverInvocation, runOptions?: KingHostRunInvocation): Promise<void>;
|
|
257
|
+
}
|
|
258
|
+
export type KingHostSdk<TProjectRunSpec = unknown, TPreparedTakeoverPlan = unknown, TTakeoverInvocation = KingHostTakeoverOptions> = HostSdk | KingAdapterHostSdk<TProjectRunSpec, TPreparedTakeoverPlan, TTakeoverInvocation>;
|
|
259
|
+
export declare function createDefaultHostSdkRunOptions(overrides?: HostSdkRunOptions): HostSdkRunOptions;
|
|
260
|
+
export declare function createHostSdkRunOptions(overrides?: HostSdkRunOptions): HostSdkRunOptions;
|
|
261
|
+
export declare function createHostSdkTakeoverRunOptions(overrides?: HostSdkRunOptions): HostSdkRunOptions;
|
|
262
|
+
export declare const createDefaultRunOptions: typeof createDefaultHostSdkRunOptions;
|
|
263
|
+
export declare const createRunOptions: typeof createHostSdkRunOptions;
|
|
264
|
+
export declare const createTakeoverRunOptions: typeof createHostSdkTakeoverRunOptions;
|
|
265
|
+
export declare function createHostSdk(options?: HostSdkOptions): {
|
|
266
|
+
health: () => Promise<HostHealth>;
|
|
267
|
+
status: () => Promise<HostStatusSnapshot>;
|
|
268
|
+
statusStream: (streamOptions?: HostSdkStatusStreamOptions) => AsyncGenerator<HostStatusSnapshot, any, any>;
|
|
269
|
+
events: () => Promise<HostEventsResponse>;
|
|
270
|
+
usage: () => Promise<HostCommandResult & {
|
|
271
|
+
json?: UsageSummary;
|
|
272
|
+
}>;
|
|
273
|
+
expenses: () => Promise<HostCommandResult & {
|
|
274
|
+
json?: HostExpensesResponse;
|
|
275
|
+
}>;
|
|
276
|
+
doctor: () => Promise<HostCommandResult & {
|
|
277
|
+
json?: HostDoctorResponse;
|
|
278
|
+
}>;
|
|
279
|
+
commands: () => Promise<HostCommandsResponse>;
|
|
280
|
+
capabilities: () => Promise<HostCapabilitiesResponse>;
|
|
281
|
+
snapshot: (limit?: number, status?: HostRunRequestStatus) => Promise<HostSnapshotResponse>;
|
|
282
|
+
waitForReady: (waitOptions?: HostSdkWaitOptions) => Promise<HostStatusSnapshot>;
|
|
283
|
+
watch: (watchOptions?: HostSdkWatchOptions) => AsyncGenerator<HostSdkWatchFrame, any, any>;
|
|
284
|
+
hostStream: (streamOptions?: HostSdkHostStreamOptions) => AsyncGenerator<HostSdkStreamFrame, any, any>;
|
|
285
|
+
timelineStream: (streamOptions?: HostSdkTimelineStreamOptions) => AsyncGenerator<HostTimelineEvent[], any, any>;
|
|
286
|
+
run: (goal: string, options?: HostSdkRunOptions, spec?: Partial<HostRunSpecInput>) => Promise<HostCommandResult & {
|
|
287
|
+
json?: JsonSafeHostLaunchPlan;
|
|
288
|
+
}>;
|
|
289
|
+
runAndWatch: (goal: string, options?: HostSdkRunOptions, spec?: Partial<HostRunSubmitInput>, watchOptions?: HostSdkSubmitAndWatchOptions) => AsyncGenerator<HostSdkSubmitAndWatchFrame, any, any>;
|
|
290
|
+
runAndWatchState: (goal: string, options?: HostSdkRunOptions, spec?: Partial<HostRunSubmitInput>, watchOptions?: HostSdkSubmitAndWatchOptions) => AsyncGenerator<HostSdkSubmitAndWatchStateFrame, any, any>;
|
|
291
|
+
takeover: (options: HostSdkTakeoverOptions, runOptions?: HostSdkRunOptions) => Promise<HostCommandResult & {
|
|
292
|
+
json?: JsonSafeHostLaunchPlan;
|
|
293
|
+
}>;
|
|
294
|
+
prepareTakeover: (options: HostSdkTakeoverOptions, runOptions?: HostSdkRunOptions) => Promise<HostSdkPreparedTakeover>;
|
|
295
|
+
executePreparedTakeover: (prepared: HostSdkPreparedTakeover, spec?: Partial<HostRunSubmitInput>, watchOptions?: HostSdkSubmitAndWatchOptions) => AsyncGenerator<HostSdkSubmitAndWatchFrame, any, any>;
|
|
296
|
+
executePreparedTakeoverState: (prepared: HostSdkPreparedTakeover, spec?: Partial<HostRunSubmitInput>, watchOptions?: HostSdkSubmitAndWatchOptions) => AsyncGenerator<HostSdkSubmitAndWatchStateFrame, any, any>;
|
|
297
|
+
takeoverAndWatch: (options: HostSdkTakeoverOptions, runOptions?: HostSdkRunOptions, spec?: Partial<HostRunSubmitInput>, watchOptions?: HostSdkSubmitAndWatchOptions) => AsyncGenerator<HostSdkSubmitAndWatchFrame, any, any>;
|
|
298
|
+
takeoverAndWatchState: (options: HostSdkTakeoverOptions, runOptions?: HostSdkRunOptions, spec?: Partial<HostRunSubmitInput>, watchOptions?: HostSdkSubmitAndWatchOptions) => AsyncGenerator<HostSdkSubmitAndWatchStateFrame, any, any>;
|
|
299
|
+
runCommand: <TJson = unknown>(request: HostCommandRequest) => Promise<HostCommandResult & {
|
|
300
|
+
json?: TJson | undefined;
|
|
301
|
+
}>;
|
|
302
|
+
planRun: (input: HostRunSpecInput) => Promise<HostCommandResult & {
|
|
303
|
+
json?: JsonSafeHostLaunchPlan;
|
|
304
|
+
}>;
|
|
305
|
+
preflight: (input: HostRunSpecInput) => Promise<HostCommandResult & {
|
|
306
|
+
json?: JsonSafeHostLaunchPlan;
|
|
307
|
+
}>;
|
|
308
|
+
prepareRunLayout: (input: HostSdkPrepareRunLayoutInput) => Promise<HostCommandResult & {
|
|
309
|
+
json?: HostRunLayoutResult;
|
|
310
|
+
}>;
|
|
311
|
+
submitRun: (input: HostRunSubmitInput) => Promise<HostCommandResult & {
|
|
312
|
+
json?: HostRunSubmitResult;
|
|
313
|
+
}>;
|
|
314
|
+
submitAndExecuteRun: (input: HostRunSubmitInput) => Promise<HostSdkSubmitAndExecuteResult>;
|
|
315
|
+
submitAndWatchRun: (input: HostRunSubmitInput, watchOptions?: HostSdkSubmitAndWatchOptions) => AsyncGenerator<HostSdkSubmitAndWatchFrame, any, any>;
|
|
316
|
+
submitAndWatchRunState: (input: HostRunSubmitInput, watchOptions?: HostSdkSubmitAndWatchOptions) => AsyncGenerator<HostSdkSubmitAndWatchStateFrame, any, any>;
|
|
317
|
+
runRequests: (limit?: number, status?: HostRunRequestStatus) => Promise<HostCommandResult & {
|
|
318
|
+
json?: HostRunRequestsResponse;
|
|
319
|
+
}>;
|
|
320
|
+
runRequestsStream: (streamOptions?: HostSdkRunRequestsStreamOptions) => AsyncGenerator<HostRunRequest[], any, any>;
|
|
321
|
+
runRequest: (id: string) => Promise<HostCommandResult & {
|
|
322
|
+
json?: HostRunRequestResponse;
|
|
323
|
+
}>;
|
|
324
|
+
runRequestStream: (id: string, streamOptions?: HostSdkRunRequestStreamOptions) => AsyncGenerator<HostRunRequest | null, any, any>;
|
|
325
|
+
runStateStream: (id: string, streamOptions?: HostSdkRunRequestStreamOptions) => AsyncGenerator<HostSdkRunStateFrame, any, any>;
|
|
326
|
+
emitRunEvent: (id: string, event: HostSdkRunEventEmitInput) => Promise<HostCommandResult & {
|
|
327
|
+
json?: {
|
|
328
|
+
file: string;
|
|
329
|
+
event: HostLoopEvent;
|
|
330
|
+
};
|
|
331
|
+
}>;
|
|
332
|
+
runEvents: (id: string, eventsOptions?: HostSdkRunEventsOptions) => Promise<HostCommandResult & {
|
|
333
|
+
json?: HostLoopEventsResult;
|
|
334
|
+
}>;
|
|
335
|
+
watchRun: (id: string, eventsOptions?: HostSdkRunEventsOptions) => Promise<HostCommandResult & {
|
|
336
|
+
json?: HostLoopEventsResult;
|
|
337
|
+
}>;
|
|
338
|
+
runResults: (id: string, resultsOptions?: HostSdkRunResultsOptions) => Promise<HostCommandResult & {
|
|
339
|
+
json?: HostLoopResultsTable;
|
|
340
|
+
}>;
|
|
341
|
+
runHeartbeat: (id: string, heartbeatOptions?: HostSdkRunHeartbeatOptions) => Promise<HostCommandResult & {
|
|
342
|
+
json?: HostRunHeartbeatReadResult;
|
|
343
|
+
}>;
|
|
344
|
+
runMeta: (id: string, metaOptions?: HostSdkRunMetaOptions) => Promise<HostCommandResult & {
|
|
345
|
+
json?: HostRunMetaReadResult;
|
|
346
|
+
}>;
|
|
347
|
+
waitForRun: (id: string, waitOptions?: HostSdkWaitForRunOptions) => Promise<HostCommandResult & {
|
|
348
|
+
json?: HostRunRequestResponse;
|
|
349
|
+
}>;
|
|
350
|
+
updateRun: (id: string, status: Exclude<HostRunRequestStatus, "pending">, detail?: string) => Promise<HostCommandResult & {
|
|
351
|
+
json?: HostRunUpdateResult;
|
|
352
|
+
}>;
|
|
353
|
+
completeRun: (id: string, detail?: string) => Promise<HostCommandResult & {
|
|
354
|
+
json?: HostRunUpdateResult;
|
|
355
|
+
}>;
|
|
356
|
+
failRun: (id: string, detail?: string) => Promise<HostCommandResult & {
|
|
357
|
+
json?: HostRunUpdateResult;
|
|
358
|
+
}>;
|
|
359
|
+
cancelRun: (id: string, detail?: string) => Promise<HostCommandResult & {
|
|
360
|
+
json?: HostRunUpdateResult;
|
|
361
|
+
}>;
|
|
362
|
+
executeRun: (id?: string) => Promise<HostCommandResult & {
|
|
363
|
+
json?: HostRunExecuteResult;
|
|
364
|
+
}>;
|
|
365
|
+
planExport: (input: HostExportInput) => Promise<HostCommandResult & {
|
|
366
|
+
json?: HostExportPlan;
|
|
367
|
+
}>;
|
|
368
|
+
exportArtifacts: (input: HostExportInput & {
|
|
369
|
+
confirmed?: boolean;
|
|
370
|
+
confirmation?: string;
|
|
371
|
+
}) => Promise<HostCommandResult & {
|
|
372
|
+
json?: HostExportResult;
|
|
373
|
+
}>;
|
|
374
|
+
policy: (command: string, input?: {
|
|
375
|
+
confirmed?: boolean;
|
|
376
|
+
confirmation?: string;
|
|
377
|
+
}) => Promise<HostCommandResult & {
|
|
378
|
+
json?: HostPolicyCheck;
|
|
379
|
+
}>;
|
|
380
|
+
timeline: (limit?: number) => Promise<HostCommandResult & {
|
|
381
|
+
json?: HostTimelineResponse;
|
|
382
|
+
}>;
|
|
383
|
+
};
|
|
384
|
+
export declare function createKingHostSdk(config?: HostSdkOptions): HostSdk;
|
|
385
|
+
export declare function createKingHostSdk<TProjectRunSpec = unknown, TPreparedTakeoverPlan = unknown, TConcreteTakeoverOptions extends object = KingHostTakeoverOptions>(config: KingHostSdkConfig, adapters: KingHostSdkAdapters<TProjectRunSpec, TPreparedTakeoverPlan, TConcreteTakeoverOptions>): KingAdapterHostSdk<TProjectRunSpec, TPreparedTakeoverPlan, TConcreteTakeoverOptions | KingHostTakeoverOptions>;
|
|
386
|
+
export declare function createEnvBackedHostSdk(env?: HostSdkEnvLike, options?: Omit<HostSdkOptions, "baseUrl">): HostSdk;
|
|
387
|
+
export declare function createEnvBackedKingHostSdk(env?: HostSdkEnvLike, options?: Omit<HostSdkOptions, "baseUrl">): HostSdk;
|
|
388
|
+
export declare function createEnvBackedKingHostSdk<TProjectRunSpec = unknown, TPreparedTakeoverPlan = unknown, TConcreteTakeoverOptions extends object = KingHostTakeoverOptions>(env: HostSdkEnvLike, config: Omit<KingHostSdkConfig, "env">, adapters: KingHostSdkAdapters<TProjectRunSpec, TPreparedTakeoverPlan, TConcreteTakeoverOptions>): KingAdapterHostSdk<TProjectRunSpec, TPreparedTakeoverPlan, TConcreteTakeoverOptions | KingHostTakeoverOptions>;
|
|
389
|
+
export declare function createBrowserHostSdk(options?: HostSdkBrowserOptions): HostSdk;
|
|
390
|
+
export declare function hostBaseUrlFromEnv(env?: HostSdkEnvLike): string;
|
|
391
|
+
export declare function hostBaseUrlFromLocation(location: HostSdkLocationLike | undefined, options?: {
|
|
392
|
+
port?: number | string;
|
|
393
|
+
useCurrentOrigin?: boolean;
|
|
394
|
+
}): string;
|
|
395
|
+
export declare function waitForHostReady(fetchImpl: typeof fetch, baseUrl: string, options?: HostSdkWaitOptions): Promise<HostStatusSnapshot>;
|
|
396
|
+
export declare function waitForHostRun(fetchImpl: typeof fetch, baseUrl: string, id: string, options?: HostSdkWaitForRunOptions): Promise<HostCommandResult & {
|
|
397
|
+
json?: HostRunRequestResponse;
|
|
398
|
+
}>;
|
|
399
|
+
export declare function submitAndExecuteHostRun(fetchImpl: typeof fetch, baseUrl: string, input: HostRunSubmitInput): Promise<HostSdkSubmitAndExecuteResult>;
|
|
400
|
+
export declare function submitAndWatchHostRun(fetchImpl: typeof fetch, baseUrl: string, input: HostRunSubmitInput, options?: HostSdkSubmitAndWatchOptions): AsyncGenerator<HostSdkSubmitAndWatchFrame>;
|
|
401
|
+
export declare function submitAndWatchHostRunState(fetchImpl: typeof fetch, baseUrl: string, input: HostRunSubmitInput, options?: HostSdkSubmitAndWatchOptions): AsyncGenerator<HostSdkSubmitAndWatchStateFrame>;
|
|
402
|
+
export declare function prepareHostSdkTakeover(fetchImpl: typeof fetch, baseUrl: string, options: HostSdkTakeoverOptions, runOptions?: HostSdkRunOptions): Promise<HostSdkPreparedTakeover>;
|
|
403
|
+
export declare function streamHostStatus(fetchImpl: typeof fetch, baseUrl: string, options?: HostSdkStatusStreamOptions): AsyncGenerator<HostStatusSnapshot>;
|
|
404
|
+
export declare function streamHostTimeline(fetchImpl: typeof fetch, baseUrl: string, options?: HostSdkTimelineStreamOptions): AsyncGenerator<HostTimelineEvent[]>;
|
|
405
|
+
export declare function streamHostFrames(fetchImpl: typeof fetch, baseUrl: string, options?: HostSdkHostStreamOptions): AsyncGenerator<HostSdkStreamFrame>;
|
|
406
|
+
export declare function watchHost(fetchImpl: typeof fetch, baseUrl: string, options?: HostSdkWatchOptions): AsyncGenerator<HostSdkWatchFrame>;
|
|
407
|
+
export declare function streamHostRunRequests(fetchImpl: typeof fetch, baseUrl: string, options?: HostSdkRunRequestsStreamOptions): AsyncGenerator<HostRunRequest[]>;
|
|
408
|
+
export declare function streamHostRunRequest(fetchImpl: typeof fetch, baseUrl: string, id: string, options?: HostSdkRunRequestStreamOptions): AsyncGenerator<HostRunRequest | null>;
|
|
409
|
+
export declare function streamHostRunState(fetchImpl: typeof fetch, baseUrl: string, id: string, options?: HostSdkRunRequestStreamOptions): AsyncGenerator<HostSdkRunStateFrame>;
|
|
410
|
+
export declare function runHostSdkCommand<TJson = unknown>(fetchImpl: typeof fetch, baseUrl: string, request: HostCommandRequest): Promise<HostCommandResult & {
|
|
411
|
+
json?: TJson;
|
|
412
|
+
}>;
|