@lucid-agents/taskmarket 1.16.0 → 1.17.1
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/THIRD_PARTY_NOTICES.md +14 -0
- package/dist/THIRD_PARTY_NOTICES.md +3108 -0
- package/dist/agent-compatibility.json +54 -0
- package/dist/budget-view-XKZC3GY5.js +36 -0
- package/dist/channels-Q7XMSUSO.js +29 -0
- package/dist/chunk-3S63AB3C.js +16068 -0
- package/dist/chunk-73RXOYME.js +185 -0
- package/dist/chunk-EIHZYRIU.js +1099 -0
- package/dist/chunk-F5SS4NUF.js +1062 -0
- package/dist/chunk-JAZ5BWPB.js +181 -0
- package/dist/chunk-MI2GPMCZ.js +154 -0
- package/dist/chunk-OKZ2NRYZ.js +133 -0
- package/dist/chunk-S7SJMJ2I.js +38 -0
- package/dist/chunk-YM4S6IE4.js +15 -0
- package/dist/compatibility-KUYGZSUC.js +19 -0
- package/dist/doctor-BY2PBHS7.js +216 -0
- package/dist/errors-2L357HGA.js +8 -0
- package/dist/index.js +1186 -13492
- package/dist/launch-DE65XO5C.js +22476 -0
- package/dist/pi/CHANGELOG.md +5689 -0
- package/dist/pi/README.md +718 -0
- package/dist/pi/dist/bundle/chunks/anthropic-messages-VWZZOSJQ.js +6 -0
- package/dist/pi/dist/bundle/chunks/anthropic.js +75 -0
- package/dist/pi/dist/bundle/chunks/azure-openai-responses-BJLAM6CD.js +2 -0
- package/dist/pi/dist/bundle/chunks/bedrock-converse-stream.js +74 -0
- package/dist/pi/dist/bundle/chunks/chunk-4L3WN2XY.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-6CYCI3EJ.js +12 -0
- package/dist/pi/dist/bundle/chunks/chunk-6R7UI4IY.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-AXIIZGTV.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-CLNPYIDP.js +42 -0
- package/dist/pi/dist/bundle/chunks/chunk-DRQDKNXA.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-GMWCTUPB.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-IDDQWTHI.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-JVUZSMYM.js +1547 -0
- package/dist/pi/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-NUHFSC37.js +25 -0
- package/dist/pi/dist/bundle/chunks/chunk-OUXLLA64.js +11 -0
- package/dist/pi/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-TRDNDS6A.js +4 -0
- package/dist/pi/dist/bundle/chunks/chunk-U6ZMQKGD.js +50 -0
- package/dist/pi/dist/bundle/chunks/chunk-UAQELI3K.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-USJZMAIR.js +2 -0
- package/dist/pi/dist/bundle/chunks/chunk-XDUWOHPL.js +6 -0
- package/dist/pi/dist/bundle/chunks/chunk-XNGRGP62.js +2 -0
- package/dist/pi/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/pi/dist/bundle/chunks/google-generative-ai-Q2K7FBDI.js +2 -0
- package/dist/pi/dist/bundle/chunks/google-vertex-7UJBF4S7.js +2 -0
- package/dist/pi/dist/bundle/chunks/https-proxy-agent-2VXB7436.js +13 -0
- package/dist/pi/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/pi/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/pi/dist/bundle/chunks/lib-HGQMNYVT.js +9 -0
- package/dist/pi/dist/bundle/chunks/mistral-conversations-4M6BZBX6.js +5 -0
- package/dist/pi/dist/bundle/chunks/multipart-parser-SQ6GDJL7.js +3 -0
- package/dist/pi/dist/bundle/chunks/node-KG362ECQ.js +16 -0
- package/dist/pi/dist/bundle/chunks/node-TWVVAGPO.js +2 -0
- package/dist/pi/dist/bundle/chunks/openai-codex-responses-R6VYZTVY.js +10 -0
- package/dist/pi/dist/bundle/chunks/openai-codex.js +75 -0
- package/dist/pi/dist/bundle/chunks/openai-completions-EKZT2IH2.js +7 -0
- package/dist/pi/dist/bundle/chunks/openai-responses-TFDINO6W.js +2 -0
- package/dist/pi/dist/bundle/chunks/openrouter-images-N4XVVFSD.js +2 -0
- package/dist/pi/dist/bundle/chunks/openrouter.js +75 -0
- package/dist/pi/dist/bundle/chunks/pi-messages-PML4SPVJ.js +8 -0
- package/dist/pi/dist/bundle/chunks/radius.js +75 -0
- package/dist/pi/dist/bundle/chunks/src-UK77SYZE.js +4 -0
- package/dist/pi/dist/bundle/chunks/xai.js +2 -0
- package/dist/pi/dist/bundle/cli.js +3 -0
- package/dist/pi/dist/bundle/index.js +2 -0
- package/dist/pi/dist/bundle/rpc-entry.js +3 -0
- package/dist/pi/dist/core/export-html/template.css +1066 -0
- package/dist/pi/dist/core/export-html/template.html +55 -0
- package/dist/pi/dist/core/export-html/template.js +1864 -0
- package/dist/pi/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/pi/dist/core/export-html/vendor/marked.min.js +78 -0
- package/dist/pi/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/pi/dist/modes/interactive/theme/dark.json +91 -0
- package/dist/pi/dist/modes/interactive/theme/light.json +90 -0
- package/dist/pi/dist/modes/interactive/theme/theme-schema.json +356 -0
- package/dist/pi/docs/compaction.md +418 -0
- package/dist/pi/docs/containerization.md +156 -0
- package/dist/pi/docs/custom-provider.md +777 -0
- package/dist/pi/docs/development.md +90 -0
- package/dist/pi/docs/environment-variables.md +99 -0
- package/dist/pi/docs/extensions.md +3023 -0
- package/dist/pi/docs/index.md +84 -0
- package/dist/pi/docs/json.md +98 -0
- package/dist/pi/docs/keybindings.md +239 -0
- package/dist/pi/docs/llama-cpp.md +101 -0
- package/dist/pi/docs/models.md +574 -0
- package/dist/pi/docs/packages.md +228 -0
- package/dist/pi/docs/prompt-templates.md +96 -0
- package/dist/pi/docs/providers.md +317 -0
- package/dist/pi/docs/quickstart.md +167 -0
- package/dist/pi/docs/rpc.md +1618 -0
- package/dist/pi/docs/sdk.md +1224 -0
- package/dist/pi/docs/security.md +59 -0
- package/dist/pi/docs/session-format.md +438 -0
- package/dist/pi/docs/sessions.md +145 -0
- package/dist/pi/docs/settings.md +369 -0
- package/dist/pi/docs/shell-aliases.md +13 -0
- package/dist/pi/docs/skills.md +232 -0
- package/dist/pi/docs/terminal-setup.md +192 -0
- package/dist/pi/docs/termux.md +127 -0
- package/dist/pi/docs/themes.md +322 -0
- package/dist/pi/docs/tmux.md +63 -0
- package/dist/pi/docs/tui.md +961 -0
- package/dist/pi/docs/usage.md +311 -0
- package/dist/pi/docs/windows.md +39 -0
- package/dist/pi/package.json +15 -0
- package/dist/pi/vendor/chord-context.js +96 -0
- package/dist/pi/vendor/jiti/LICENSE +21 -0
- package/dist/pi/vendor/jiti/dist/babel.cjs +257 -0
- package/dist/pi/vendor/jiti/dist/jiti.cjs +1 -0
- package/dist/pi/vendor/jiti/lib/jiti.cjs +30 -0
- package/dist/pi/vendor/jiti/package.json +6 -0
- package/dist/pi/vendor/photon-node/LICENSE.md +201 -0
- package/dist/pi/vendor/photon-node/package.json +6 -0
- package/dist/pi/vendor/photon-node/photon_rs.js +4521 -0
- package/dist/pi/vendor/photon-node/photon_rs_bg.wasm +0 -0
- package/dist/pi-extensions/lockdown.cjs +433 -0
- package/dist/pi-extensions/remote-tools.cjs +22320 -0
- package/dist/pi-extensions/xgate.cjs +2565 -0
- package/dist/reconcile-VEMPNIAO.js +83 -0
- package/dist/status-3Q55PBFC.js +18 -0
- package/package.json +13 -2
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
import {
|
|
3
|
+
computeAllocationId,
|
|
4
|
+
readComputeView
|
|
5
|
+
} from "./chunk-MI2GPMCZ.js";
|
|
6
|
+
import {
|
|
7
|
+
allocationViews,
|
|
8
|
+
channelView,
|
|
9
|
+
getAgentPolicyPath,
|
|
10
|
+
openAgentChannels,
|
|
11
|
+
uncertainPurchases,
|
|
12
|
+
withdrawalHatch
|
|
13
|
+
} from "./chunk-F5SS4NUF.js";
|
|
14
|
+
import {
|
|
15
|
+
SandboxListOutputSchema,
|
|
16
|
+
apiUrl
|
|
17
|
+
} from "./chunk-3S63AB3C.js";
|
|
18
|
+
import {
|
|
19
|
+
AgentLaunchError
|
|
20
|
+
} from "./chunk-YM4S6IE4.js";
|
|
21
|
+
import {
|
|
22
|
+
AGENT_VIEW_VERSION,
|
|
23
|
+
blockingPurchases,
|
|
24
|
+
channelLines,
|
|
25
|
+
computeLines,
|
|
26
|
+
formatUsdc
|
|
27
|
+
} from "./chunk-73RXOYME.js";
|
|
28
|
+
|
|
29
|
+
// src/lib/agent/status.ts
|
|
30
|
+
async function listSandboxes(credentials, fetchImpl = fetch) {
|
|
31
|
+
const response = await fetchImpl(`${apiUrl().replace(/\/+$/, "")}/api/sandboxes/list`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
redirect: "error",
|
|
34
|
+
headers: { "content-type": "application/json" },
|
|
35
|
+
body: JSON.stringify(credentials),
|
|
36
|
+
signal: AbortSignal.timeout(15e3)
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
await response.body?.cancel().catch(() => void 0);
|
|
40
|
+
throw new Error(`the sandbox broker answered ${response.status}`);
|
|
41
|
+
}
|
|
42
|
+
const parsed = SandboxListOutputSchema.safeParse(await response.json());
|
|
43
|
+
if (!parsed.success) throw new Error("the sandbox list is malformed");
|
|
44
|
+
return parsed.data.sandboxes.map((s) => ({
|
|
45
|
+
sandboxId: s.sandboxId,
|
|
46
|
+
purpose: s.purpose,
|
|
47
|
+
state: s.state,
|
|
48
|
+
meteredSeconds: s.meteredSeconds,
|
|
49
|
+
lastActiveAt: s.lastActiveAt,
|
|
50
|
+
expiresAt: s.expiresAt,
|
|
51
|
+
creditWarning: s.creditWarning,
|
|
52
|
+
creditGraceUntil: s.creditGraceUntil
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
function message(error) {
|
|
56
|
+
return error.code ?? error.message;
|
|
57
|
+
}
|
|
58
|
+
async function collectAgentStatus(deps = {}) {
|
|
59
|
+
const now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
60
|
+
const view = {
|
|
61
|
+
version: AGENT_VIEW_VERSION,
|
|
62
|
+
kind: "taskmarket.agent.status",
|
|
63
|
+
generatedAt: now().toISOString(),
|
|
64
|
+
wallet: null,
|
|
65
|
+
policy: { state: "missing", path: getAgentPolicyPath(), models: [] },
|
|
66
|
+
channels: [],
|
|
67
|
+
purchases: { uncertain: [] },
|
|
68
|
+
inference: { blocked: false, reasons: [] },
|
|
69
|
+
allocations: [],
|
|
70
|
+
sandbox: { state: "no_wallet", sandboxes: [] },
|
|
71
|
+
compute: {
|
|
72
|
+
configured: false,
|
|
73
|
+
availableCredits: null,
|
|
74
|
+
reservedCredits: null,
|
|
75
|
+
burnCreditsPerHour: null,
|
|
76
|
+
low: false,
|
|
77
|
+
warning: null,
|
|
78
|
+
pendingPurchases: 0,
|
|
79
|
+
autoTopUp: null
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const reasons = view.inference.reasons;
|
|
83
|
+
let credentials;
|
|
84
|
+
try {
|
|
85
|
+
const opened = await (deps.openChannels ?? openAgentChannels)();
|
|
86
|
+
view.wallet = { address: opened.keystore.walletAddress };
|
|
87
|
+
credentials = { deviceId: opened.keystore.deviceId, apiToken: opened.keystore.apiToken };
|
|
88
|
+
view.policy = { state: "approved", path: view.policy.path, models: [...opened.policy.models] };
|
|
89
|
+
const statuses = /* @__PURE__ */ new Map();
|
|
90
|
+
for (const rail of opened.rails) {
|
|
91
|
+
const status = await rail.payer.channelStatus();
|
|
92
|
+
statuses.set(rail.rail.id, status);
|
|
93
|
+
const channel = await channelView(rail, status);
|
|
94
|
+
view.channels.push({ ...channel, withdrawal: withdrawalHatch(channel) });
|
|
95
|
+
}
|
|
96
|
+
for (const rail of opened.retired ?? []) {
|
|
97
|
+
const channel = await channelView(rail, void 0, { retired: true });
|
|
98
|
+
view.channels.push({ ...channel, withdrawal: withdrawalHatch(channel) });
|
|
99
|
+
}
|
|
100
|
+
view.purchases.uncertain = [
|
|
101
|
+
...await uncertainPurchases(opened.rails, statuses),
|
|
102
|
+
...await uncertainPurchases(opened.retired ?? [])
|
|
103
|
+
];
|
|
104
|
+
view.allocations = await allocationViews(opened.rails, [
|
|
105
|
+
await (deps.computeAllocation ?? computeAllocationId)()
|
|
106
|
+
]);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (error instanceof AgentLaunchError && error.code === "wallet_required") {
|
|
109
|
+
reasons.push("no wallet: run taskmarket wallet import");
|
|
110
|
+
} else if (error instanceof AgentLaunchError && error.code === "setup_required") {
|
|
111
|
+
reasons.push("no approved spending policy");
|
|
112
|
+
} else {
|
|
113
|
+
view.policy = { ...view.policy, state: "invalid", error: message(error) };
|
|
114
|
+
reasons.push(`the spending policy cannot be used: ${message(error)}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const active = view.channels.filter((channel) => !channel.retired);
|
|
118
|
+
for (const id of blockingPurchases({ channels: active, unresolved: [] })) {
|
|
119
|
+
reasons.push(`purchase ${id} is unresolved: taskmarket agent reconcile ${id}`);
|
|
120
|
+
}
|
|
121
|
+
for (const channel of active) {
|
|
122
|
+
if (channel.state !== "open") reasons.push(`channel ${channel.rail} is ${channel.state}`);
|
|
123
|
+
}
|
|
124
|
+
if (credentials) {
|
|
125
|
+
try {
|
|
126
|
+
view.sandbox = {
|
|
127
|
+
state: "ok",
|
|
128
|
+
sandboxes: await (deps.listSandboxes ?? listSandboxes)(credentials)
|
|
129
|
+
};
|
|
130
|
+
} catch (error) {
|
|
131
|
+
view.sandbox = { state: "unavailable", sandboxes: [], error: message(error) };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const warning = view.sandbox.sandboxes.find((s) => s.purpose === "interactive" && s.creditWarning)?.creditWarning ?? null;
|
|
135
|
+
view.compute = await (deps.readCompute ?? readComputeView)({ warning });
|
|
136
|
+
view.inference.blocked = reasons.length > 0;
|
|
137
|
+
return view;
|
|
138
|
+
}
|
|
139
|
+
function statusLines(view) {
|
|
140
|
+
const lines = [
|
|
141
|
+
`taskmarket agent status (view v${view.version}, ${view.generatedAt})`,
|
|
142
|
+
view.wallet ? `Wallet: ${view.wallet.address}` : "Wallet: none",
|
|
143
|
+
`Spending policy: ${view.policy.state}${view.policy.models.length ? ` (${view.policy.models.join(", ")})` : ""}${view.policy.error ? `: ${view.policy.error}` : ""}`
|
|
144
|
+
];
|
|
145
|
+
for (const channel of view.channels) {
|
|
146
|
+
lines.push(...channelLines(channel));
|
|
147
|
+
if (channel.state === "blocked" || channel.state === "withdrawal_pending") {
|
|
148
|
+
lines.push(` ${channel.withdrawal.note}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (view.purchases.uncertain.length === 0) {
|
|
152
|
+
lines.push("Purchases with an unknown outcome: none");
|
|
153
|
+
} else {
|
|
154
|
+
lines.push("Purchases with an unknown outcome (never resent; reconcile them):");
|
|
155
|
+
for (const purchase of view.purchases.uncertain) {
|
|
156
|
+
lines.push(
|
|
157
|
+
` ${purchase.invocationId} on ${purchase.rail}: ${purchase.state}, at most ${formatUsdc(purchase.authorizedAtomic)}${purchase.blocking ? ", blocks new turns" : ""}`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
lines.push(
|
|
162
|
+
view.inference.blocked ? `New inference: blocked (${view.inference.reasons.join("; ")})` : "New inference: ready"
|
|
163
|
+
);
|
|
164
|
+
if (view.sandbox.state === "ok") {
|
|
165
|
+
lines.push(
|
|
166
|
+
view.sandbox.sandboxes.length === 0 ? "Sandbox: none" : `Sandbox: ${view.sandbox.sandboxes.map(
|
|
167
|
+
(s) => `${s.sandboxId} ${s.purpose} ${s.state}${s.creditWarning ? ` (${s.creditWarning})` : ""}`
|
|
168
|
+
).join("; ")}`
|
|
169
|
+
);
|
|
170
|
+
} else if (view.sandbox.state === "unavailable") {
|
|
171
|
+
lines.push(`Sandbox: unavailable (${view.sandbox.error})`);
|
|
172
|
+
}
|
|
173
|
+
lines.push(...computeLines(view.compute));
|
|
174
|
+
return lines;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
listSandboxes,
|
|
179
|
+
collectAgentStatus,
|
|
180
|
+
statusLines
|
|
181
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
import {
|
|
3
|
+
buyComputeCredit,
|
|
4
|
+
fetchComputePricing,
|
|
5
|
+
listPendingComputePurchases,
|
|
6
|
+
loadComputeCreditConfig,
|
|
7
|
+
onComputeBalanceObserved,
|
|
8
|
+
readComputeCreditStatus
|
|
9
|
+
} from "./chunk-EIHZYRIU.js";
|
|
10
|
+
import {
|
|
11
|
+
AgentLaunchError
|
|
12
|
+
} from "./chunk-YM4S6IE4.js";
|
|
13
|
+
import {
|
|
14
|
+
burnRate,
|
|
15
|
+
computeLow
|
|
16
|
+
} from "./chunk-73RXOYME.js";
|
|
17
|
+
|
|
18
|
+
// ../../packages/remote-tools/dist/backend.js
|
|
19
|
+
var SANDBOX_TOOL_USER = "agent";
|
|
20
|
+
var SandboxUnavailableError = class extends Error {
|
|
21
|
+
reason;
|
|
22
|
+
constructor(reason, options) {
|
|
23
|
+
super(`Sandbox unavailable, tools are disabled (no local fallback): ${reason}`, options);
|
|
24
|
+
this.name = "SandboxUnavailableError";
|
|
25
|
+
this.reason = reason;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/lib/agent/compute.ts
|
|
30
|
+
async function readComputeView(options = {}) {
|
|
31
|
+
const warning = options.warning ?? null;
|
|
32
|
+
const empty = {
|
|
33
|
+
availableCredits: null,
|
|
34
|
+
reservedCredits: null,
|
|
35
|
+
burnCreditsPerHour: null,
|
|
36
|
+
low: warning === "low_credit" || warning === "credit_exhausted",
|
|
37
|
+
warning,
|
|
38
|
+
pendingPurchases: 0,
|
|
39
|
+
autoTopUp: null
|
|
40
|
+
};
|
|
41
|
+
let config;
|
|
42
|
+
try {
|
|
43
|
+
config = await loadComputeCreditConfig();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return { configured: false, ...empty, error: error.message };
|
|
46
|
+
}
|
|
47
|
+
if (!config) return { configured: false, ...empty };
|
|
48
|
+
try {
|
|
49
|
+
let status = await readComputeCreditStatus();
|
|
50
|
+
if (options.observe && await options.observe({ availableCredits: status.balance.availableCredits })) {
|
|
51
|
+
status = await readComputeCreditStatus();
|
|
52
|
+
}
|
|
53
|
+
const burn = burnRate(status.debits);
|
|
54
|
+
const autoTopUp = config.autoTopUp ? {
|
|
55
|
+
thresholdCredits: config.autoTopUp.thresholdCredits,
|
|
56
|
+
amountUsd: config.autoTopUp.amountUsd,
|
|
57
|
+
maxChunksPerDay: config.autoTopUp.maxChunksPerDay
|
|
58
|
+
} : null;
|
|
59
|
+
return {
|
|
60
|
+
configured: true,
|
|
61
|
+
availableCredits: status.balance.availableCredits,
|
|
62
|
+
reservedCredits: status.balance.reservedCredits,
|
|
63
|
+
burnCreditsPerHour: burn,
|
|
64
|
+
low: computeLow({
|
|
65
|
+
availableCredits: status.balance.availableCredits,
|
|
66
|
+
burnCreditsPerHour: burn,
|
|
67
|
+
warning,
|
|
68
|
+
...autoTopUp ? { thresholdCredits: autoTopUp.thresholdCredits } : {}
|
|
69
|
+
}),
|
|
70
|
+
warning,
|
|
71
|
+
pendingPurchases: (await listPendingComputePurchases()).length,
|
|
72
|
+
autoTopUp
|
|
73
|
+
};
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return {
|
|
76
|
+
configured: true,
|
|
77
|
+
...empty,
|
|
78
|
+
error: error.code ?? error.message
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function computeAllocationId() {
|
|
83
|
+
return (await loadComputeCreditConfig().catch(() => void 0))?.allocationId;
|
|
84
|
+
}
|
|
85
|
+
async function computeCreditOffer() {
|
|
86
|
+
const pricing = await fetchComputePricing();
|
|
87
|
+
return {
|
|
88
|
+
usdPerCredit: pricing.usdPerCredit,
|
|
89
|
+
denominations: pricing.denominations.map((entry) => ({
|
|
90
|
+
amountUsd: entry.amountUsd,
|
|
91
|
+
credits: entry.credits,
|
|
92
|
+
default: entry.default
|
|
93
|
+
}))
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function buyComputeChunk(amountUsd) {
|
|
97
|
+
const pricing = await fetchComputePricing();
|
|
98
|
+
const size = amountUsd ?? (pricing.denominations.find((entry) => entry.default) ?? pricing.denominations[0])?.amountUsd;
|
|
99
|
+
if (size === void 0) {
|
|
100
|
+
throw new AgentLaunchError("invalid_amount", "The API sells no compute credit sizes");
|
|
101
|
+
}
|
|
102
|
+
const bought = await buyComputeCredit({ amountUsd: size });
|
|
103
|
+
return { purchase: bought.purchase, balance: bought.balance, amountUsd: size };
|
|
104
|
+
}
|
|
105
|
+
function computeCreditObserver(log) {
|
|
106
|
+
return async (observation) => {
|
|
107
|
+
try {
|
|
108
|
+
const { topUp } = await onComputeBalanceObserved(observation);
|
|
109
|
+
if (topUp.action === "bought") log("Compute credit auto-top-up bought one chunk");
|
|
110
|
+
else if (topUp.action === "skipped")
|
|
111
|
+
log(`Compute credit auto-top-up skipped: ${topUp.reason}`);
|
|
112
|
+
return topUp.action === "bought";
|
|
113
|
+
} catch (error) {
|
|
114
|
+
log(
|
|
115
|
+
`Compute credit auto-top-up failed: ${error.code ?? error.message}`
|
|
116
|
+
);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function insufficientCredit(error) {
|
|
122
|
+
return error instanceof SandboxUnavailableError && /\binsufficient_credit\b/.test(error.reason);
|
|
123
|
+
}
|
|
124
|
+
async function openSandbox(createBroker, observe) {
|
|
125
|
+
const first = createBroker();
|
|
126
|
+
try {
|
|
127
|
+
await first.connect("start");
|
|
128
|
+
return first;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (!insufficientCredit(error)) throw error;
|
|
131
|
+
if (!await observe({ creditWarning: "credit_exhausted" })) {
|
|
132
|
+
throw new AgentLaunchError("insufficient_credit", error.reason);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const retry = createBroker();
|
|
136
|
+
try {
|
|
137
|
+
await retry.connect("start");
|
|
138
|
+
return retry;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (insufficientCredit(error)) throw new AgentLaunchError("insufficient_credit", error.reason);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
SANDBOX_TOOL_USER,
|
|
147
|
+
SandboxUnavailableError,
|
|
148
|
+
readComputeView,
|
|
149
|
+
computeAllocationId,
|
|
150
|
+
computeCreditOffer,
|
|
151
|
+
buyComputeChunk,
|
|
152
|
+
computeCreditObserver,
|
|
153
|
+
openSandbox
|
|
154
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
import {
|
|
3
|
+
AgentLaunchError
|
|
4
|
+
} from "./chunk-YM4S6IE4.js";
|
|
5
|
+
|
|
6
|
+
// src/lib/agent/compatibility.ts
|
|
7
|
+
import { existsSync, readFileSync } from "fs";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
var AGENT_COMPATIBILITY = {
|
|
11
|
+
manifestVersion: 1,
|
|
12
|
+
pi: { package: "@earendil-works/pi-coding-agent", version: "0.85.1" },
|
|
13
|
+
piAi: { package: "@earendil-works/pi-ai", version: "0.85.1" },
|
|
14
|
+
piXgate: { package: "@lucid-agents/pi-xgate", version: "0.1.6" },
|
|
15
|
+
xgateClient: { package: "@lucid-agents/xgate-client", version: "0.1.6" },
|
|
16
|
+
/**
|
|
17
|
+
* Pi 0.85.1 takes these (and pi-ai) at `^0.85.1`, so a later 0.85.x could otherwise be installed
|
|
18
|
+
* under the pinned Pi without anyone verifying it. Checked as Pi itself resolves them, with
|
|
19
|
+
* pi-ai.
|
|
20
|
+
*/
|
|
21
|
+
piPackages: [
|
|
22
|
+
{ package: "@earendil-works/pi-agent-core", version: "0.85.1" },
|
|
23
|
+
{ package: "@earendil-works/pi-tui", version: "0.85.1" },
|
|
24
|
+
{ package: "@earendil-works/chord", version: "0.85.1" },
|
|
25
|
+
{ package: "@earendil-works/pi-telemetry", version: "0.85.1" }
|
|
26
|
+
],
|
|
27
|
+
/** What the remote tool extension and the broker connector are built with besides Pi. */
|
|
28
|
+
support: [{ package: "ssh2", version: "1.17.0" }],
|
|
29
|
+
/**
|
|
30
|
+
* pi-xgate 0.1.6 and xgate-client 0.1.6 declare `>=24.19 <25`. The lower bound is enforced at
|
|
31
|
+
* launch; no upper bound is, since nothing the agent runs is known to break on a later Node.
|
|
32
|
+
*/
|
|
33
|
+
node: { minimum: "24.19.0" },
|
|
34
|
+
protocol: {
|
|
35
|
+
/** `@taskmarket/x402-payer` request/status/reconcile API. */
|
|
36
|
+
payerApi: 1,
|
|
37
|
+
/** The router's channel profile the payer speaks to xgate. */
|
|
38
|
+
paymentProfile: "base-batch-channel-v1",
|
|
39
|
+
/** JSON lines between pi-xgate inside Pi and the controller's payer (fds 6 and 7). */
|
|
40
|
+
inferenceChannel: 1,
|
|
41
|
+
/** JSON lines between the remote tools inside Pi and the controller's broker (fds 4 and 5). */
|
|
42
|
+
sandboxChannel: 1,
|
|
43
|
+
/** The redaction values the controller hands the Pi guard (fd 3). */
|
|
44
|
+
secretsChannel: 1
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function agentCompatibility(taskmarketVersion) {
|
|
48
|
+
return { taskmarket: taskmarketVersion, ...AGENT_COMPATIBILITY };
|
|
49
|
+
}
|
|
50
|
+
function parseVersion(version) {
|
|
51
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version.trim());
|
|
52
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : void 0;
|
|
53
|
+
}
|
|
54
|
+
function compare(a, b) {
|
|
55
|
+
for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
function nodeVersionSupported(version) {
|
|
59
|
+
const parsed = parseVersion(version);
|
|
60
|
+
return !!parsed && compare(parsed, parseVersion(AGENT_COMPATIBILITY.node.minimum)) >= 0;
|
|
61
|
+
}
|
|
62
|
+
function findInstalledPackage(name, fromDir) {
|
|
63
|
+
let dir = fromDir;
|
|
64
|
+
for (; ; ) {
|
|
65
|
+
const manifest = path.join(dir, "node_modules", ...name.split("/"), "package.json");
|
|
66
|
+
if (existsSync(manifest)) {
|
|
67
|
+
const pkg = JSON.parse(readFileSync(manifest, "utf8"));
|
|
68
|
+
return {
|
|
69
|
+
dir: path.dirname(manifest),
|
|
70
|
+
version: typeof pkg.version === "string" ? pkg.version : ""
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const parent = path.dirname(dir);
|
|
74
|
+
if (parent === dir) return void 0;
|
|
75
|
+
dir = parent;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
var here = path.dirname(fileURLToPath(import.meta.url));
|
|
79
|
+
function piRuntime(fromDir = here) {
|
|
80
|
+
const staged = path.join(fromDir, "pi");
|
|
81
|
+
const packageDir = existsSync(path.join(staged, "package.json")) ? staged : findInstalledPackage(AGENT_COMPATIBILITY.pi.package, fromDir)?.dir;
|
|
82
|
+
if (!packageDir) return void 0;
|
|
83
|
+
return { packageDir, cliPath: path.join(packageDir, "dist", "bundle", "cli.js") };
|
|
84
|
+
}
|
|
85
|
+
var reinstall = "reinstall @lucid-agents/taskmarket";
|
|
86
|
+
function assertAgentCompatibility(options = {}) {
|
|
87
|
+
const nodeVersion = options.nodeVersion ?? process.versions.node;
|
|
88
|
+
if (!nodeVersionSupported(nodeVersion)) {
|
|
89
|
+
throw new AgentLaunchError(
|
|
90
|
+
"unsupported_node",
|
|
91
|
+
`taskmarket agent needs Node ${AGENT_COMPATIBILITY.node.minimum} or later; this is Node ${nodeVersion}. Other taskmarket commands work on this Node.`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const fromDir = options.fromDir ?? here;
|
|
95
|
+
const runtime = piRuntime(fromDir);
|
|
96
|
+
if (!runtime || !existsSync(runtime.cliPath)) {
|
|
97
|
+
throw new AgentLaunchError(
|
|
98
|
+
"incompatible_install",
|
|
99
|
+
`Pi, which taskmarket agent runs, is missing from this install; ${reinstall}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
const pi = JSON.parse(readFileSync(path.join(runtime.packageDir, "package.json"), "utf8"));
|
|
103
|
+
const expected = AGENT_COMPATIBILITY.pi;
|
|
104
|
+
if (pi.name !== expected.package || pi.version !== expected.version) {
|
|
105
|
+
throw new AgentLaunchError(
|
|
106
|
+
"incompatible_install",
|
|
107
|
+
`This install has ${String(pi.name)} ${String(pi.version)}; taskmarket agent requires ${expected.package} ${expected.version}. ${reinstall}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
const shipped = path.join(fromDir, "agent-compatibility.json");
|
|
111
|
+
if (existsSync(shipped)) {
|
|
112
|
+
const manifest = JSON.parse(readFileSync(shipped, "utf8"));
|
|
113
|
+
const mismatched = ["pi", "piAi", "piXgate", "xgateClient"].filter(
|
|
114
|
+
(key) => manifest[key]?.version !== AGENT_COMPATIBILITY[key].version
|
|
115
|
+
);
|
|
116
|
+
if (mismatched.length > 0 || manifest.protocol?.inferenceChannel !== AGENT_COMPATIBILITY.protocol.inferenceChannel) {
|
|
117
|
+
throw new AgentLaunchError(
|
|
118
|
+
"incompatible_install",
|
|
119
|
+
`dist/agent-compatibility.json does not match this build of taskmarket agent; ${reinstall}`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return runtime;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
AGENT_COMPATIBILITY,
|
|
128
|
+
agentCompatibility,
|
|
129
|
+
nodeVersionSupported,
|
|
130
|
+
findInstalledPackage,
|
|
131
|
+
piRuntime,
|
|
132
|
+
assertAgentCompatibility
|
|
133
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
__require,
|
|
36
|
+
__commonJS,
|
|
37
|
+
__toESM
|
|
38
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
|
|
3
|
+
// src/lib/agent/errors.ts
|
|
4
|
+
var AgentLaunchError = class extends Error {
|
|
5
|
+
constructor(code, message, details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.details = details;
|
|
9
|
+
this.name = "AgentLaunchError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
AgentLaunchError
|
|
15
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
import {
|
|
3
|
+
AGENT_COMPATIBILITY,
|
|
4
|
+
agentCompatibility,
|
|
5
|
+
assertAgentCompatibility,
|
|
6
|
+
findInstalledPackage,
|
|
7
|
+
nodeVersionSupported,
|
|
8
|
+
piRuntime
|
|
9
|
+
} from "./chunk-OKZ2NRYZ.js";
|
|
10
|
+
import "./chunk-YM4S6IE4.js";
|
|
11
|
+
import "./chunk-S7SJMJ2I.js";
|
|
12
|
+
export {
|
|
13
|
+
AGENT_COMPATIBILITY,
|
|
14
|
+
agentCompatibility,
|
|
15
|
+
assertAgentCompatibility,
|
|
16
|
+
findInstalledPackage,
|
|
17
|
+
nodeVersionSupported,
|
|
18
|
+
piRuntime
|
|
19
|
+
};
|