@parcha/agentrun-serve 0.0.0-bootstrap.0 → 0.1.0-beta.29
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 +560 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +1724 -0
- package/dist/adapters.d.ts +205 -0
- package/dist/adapters.js +459 -0
- package/dist/agents.d.ts +124 -0
- package/dist/agents.js +302 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +324 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +283 -0
- package/dist/box-relay.d.ts +42 -0
- package/dist/box-relay.js +222 -0
- package/dist/boxes.d.ts +54 -0
- package/dist/boxes.js +182 -0
- package/dist/cap.d.ts +224 -0
- package/dist/cap.js +721 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +31 -0
- package/dist/coding-tools.js +81 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
- package/dist/console/assets/index-BN7oVcO4.js +445 -0
- package/dist/console/assets/index-By-jkqki.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +11 -0
- package/dist/decision-rows.js +116 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +66 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +60 -0
- package/dist/files.js +153 -0
- package/dist/grade.d.ts +96 -0
- package/dist/grade.js +348 -0
- package/dist/graph-view.d.ts +100 -0
- package/dist/graph-view.js +212 -0
- package/dist/harness-app.d.ts +38 -0
- package/dist/harness-app.js +626 -0
- package/dist/harness.d.ts +53 -0
- package/dist/harness.js +74 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +20 -0
- package/dist/host-tools.js +140 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +81 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +129 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1221 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +36 -0
- package/dist/key-check.js +108 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +187 -0
- package/dist/learn/check.d.ts +99 -0
- package/dist/learn/check.js +259 -0
- package/dist/learn/grade.d.ts +79 -0
- package/dist/learn/grade.js +433 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +146 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +167 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +111 -0
- package/dist/learn/skills.d.ts +84 -0
- package/dist/learn/skills.js +198 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +304 -0
- package/dist/learning-run.js +797 -0
- package/dist/learning-words.d.ts +73 -0
- package/dist/learning-words.js +171 -0
- package/dist/learning.d.ts +377 -0
- package/dist/learning.js +801 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +115 -0
- package/dist/mcp-servers.js +445 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +184 -0
- package/dist/model.js +484 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4805 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1417 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +46 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +68 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +46 -0
- package/dist/place.js +105 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +38 -0
- package/dist/propose.js +82 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +14 -0
- package/dist/request-start.js +226 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +134 -0
- package/dist/run-box.js +440 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +80 -0
- package/dist/runnable.js +162 -0
- package/dist/runs.d.ts +840 -0
- package/dist/runs.js +2279 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +50 -0
- package/dist/secrets.js +140 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +626 -0
- package/dist/server.js +1756 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/skills.d.ts +31 -0
- package/dist/skills.js +68 -0
- package/dist/stats.d.ts +101 -0
- package/dist/stats.js +82 -0
- package/dist/tool-keys.d.ts +151 -0
- package/dist/tool-keys.js +273 -0
- package/dist/tool-plane.d.ts +143 -0
- package/dist/tool-plane.js +242 -0
- package/dist/tools.d.ts +147 -0
- package/dist/tools.js +253 -0
- package/dist/turn-end.d.ts +23 -0
- package/dist/turn-end.js +14 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +55 -0
- package/dist/validate.js +175 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +182 -0
- package/dist/webhooks.js +487 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +96 -1
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { clip, TITLE_CAP } from "./fetch-page.js";
|
|
2
|
+
import { sideRequests } from "./cap.js";
|
|
3
|
+
import { ANSWER_MAX, snippetOf } from "./web-search.js";
|
|
4
|
+
export const HOSTED_MAX_USES = 5;
|
|
5
|
+
/** One search's results billed as input: about 25,000 tokens, a working estimate. */
|
|
6
|
+
export const SEARCH_INPUT_TOKENS = 25_000;
|
|
7
|
+
/** What the request may read into its input beyond its context, for the run's cap: each of its searches' results. */
|
|
8
|
+
export const HOSTED_SEARCH_ALLOWANCE_TOKENS = HOSTED_MAX_USES * SEARCH_INPUT_TOKENS;
|
|
9
|
+
export const ANTHROPIC_SEARCH_TOOL = Object.freeze({ type: "web_search_20250305", name: "web_search", max_uses: HOSTED_MAX_USES });
|
|
10
|
+
export const OPENAI_SEARCH_TOOL = Object.freeze({ type: "web_search" });
|
|
11
|
+
/** OpenAI's hosted search has no per-tool limit: the Responses API's `max_tool_calls` caps the built-in tool calls of the
|
|
12
|
+
* request at the HOSTED_MAX_USES its fee is reserved for, as Anthropic's tool's `max_uses` does. */
|
|
13
|
+
export const OPENAI_SEARCH_LIMIT = Object.freeze({ max_tool_calls: HOSTED_MAX_USES });
|
|
14
|
+
/** $10 per 1,000 searches (Anthropic) or calls (OpenAI). */
|
|
15
|
+
export const SEARCH_USD = 0.01;
|
|
16
|
+
/** OpenAI's models that bill each call's search content as a fixed block of 8,000 input tokens apart from the response's
|
|
17
|
+
* usage: the block is added to the fee at the model's input price. */
|
|
18
|
+
const BLOCK_BILLED = /^gpt-(?:4o|4\.1)-mini(?:-|$)/;
|
|
19
|
+
const ANSWER_TOKENS = 2_048;
|
|
20
|
+
/** As Exa's and Parallel's searches stop. */
|
|
21
|
+
const TIMEOUT_MS = 60_000;
|
|
22
|
+
let runModels;
|
|
23
|
+
/** The run's models, marked and capped, handed over by the run's app before its tools are bound. */
|
|
24
|
+
export function searchOn(models) {
|
|
25
|
+
runModels = models;
|
|
26
|
+
}
|
|
27
|
+
const list = (value) => (Array.isArray(value) ? value.filter((item) => typeof item === "object" && item !== null) : []);
|
|
28
|
+
const text = (value) => (typeof value === "string" ? value : undefined);
|
|
29
|
+
/** What a provider's events say of the search: its results by URL, first seen first, and how many searches it ran. */
|
|
30
|
+
function reader(anthropic) {
|
|
31
|
+
const hits = new Map();
|
|
32
|
+
const add = (url, found) => {
|
|
33
|
+
if (typeof url !== "string" || !URL.canParse(url))
|
|
34
|
+
return;
|
|
35
|
+
const hit = hits.get(url) ?? {};
|
|
36
|
+
hits.set(url, { ...found, ...Object.fromEntries(Object.entries(hit).filter(([, value]) => value)) });
|
|
37
|
+
};
|
|
38
|
+
let reported;
|
|
39
|
+
let calls = 0;
|
|
40
|
+
let failed;
|
|
41
|
+
const anthropicEvent = (event) => {
|
|
42
|
+
const block = event.content_block;
|
|
43
|
+
if (event.type === "content_block_start" && block?.type === "server_tool_use" && block.name === "web_search")
|
|
44
|
+
calls += 1;
|
|
45
|
+
if (event.type === "content_block_start" && block?.type === "web_search_tool_result") {
|
|
46
|
+
if (!Array.isArray(block.content))
|
|
47
|
+
failed = text(block.content?.error_code) ?? "the search failed";
|
|
48
|
+
for (const result of list(block.content))
|
|
49
|
+
if (result.type === "web_search_result")
|
|
50
|
+
add(result.url, { title: text(result.title), published: text(result.page_age) });
|
|
51
|
+
}
|
|
52
|
+
const citation = event.delta?.type === "citations_delta" ? event.delta.citation : undefined;
|
|
53
|
+
if (citation)
|
|
54
|
+
add(citation.url, { title: text(citation.title), snippet: text(citation.cited_text) });
|
|
55
|
+
const used = event.usage?.server_tool_use?.web_search_requests;
|
|
56
|
+
if (event.type === "message_delta" && typeof used === "number")
|
|
57
|
+
reported = used;
|
|
58
|
+
};
|
|
59
|
+
const openaiEvent = (event) => {
|
|
60
|
+
const item = event.item;
|
|
61
|
+
if (event.type === "response.output_item.done" && item?.type === "web_search_call") {
|
|
62
|
+
calls += 1;
|
|
63
|
+
for (const source of list(item.action?.sources))
|
|
64
|
+
add(source.url, {});
|
|
65
|
+
}
|
|
66
|
+
if (event.type === "response.output_item.done" && item?.type === "message") {
|
|
67
|
+
for (const part of list(item.content)) {
|
|
68
|
+
const said = text(part.text) ?? "";
|
|
69
|
+
for (const note of list(part.annotations)) {
|
|
70
|
+
if (note.type !== "url_citation")
|
|
71
|
+
continue;
|
|
72
|
+
// The sentence the citation follows: OpenAI marks the cited source after the claim it supports.
|
|
73
|
+
const before = said.slice(0, typeof note.start_index === "number" ? note.start_index : 0).trimEnd();
|
|
74
|
+
add(note.url, { title: text(note.title), snippet: before.slice(Math.max(before.lastIndexOf(". "), before.lastIndexOf("\n")) + 1).trim() });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const used = (event.response?.tool_usage?.web_search)?.num_requests;
|
|
79
|
+
if ((event.type === "response.completed" || event.type === "response.incomplete") && typeof used === "number")
|
|
80
|
+
reported = used;
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
event: (event) => (anthropic ? anthropicEvent : openaiEvent)((event ?? {})),
|
|
84
|
+
/** The searches the provider reported, else the search calls its answer held. */
|
|
85
|
+
searches: () => reported ?? calls,
|
|
86
|
+
failed: () => (hits.size ? undefined : failed),
|
|
87
|
+
hits: () => [...hits].map(([url, hit]) => ({ url, title: clip(hit.title ?? "", TITLE_CAP), snippet: snippetOf(hit.snippet ?? ""), ...(hit.published ? { published: hit.published } : {}) })),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** `query` searched by `ref`'s provider (`provider/model-id`, the model the server resolved web_search on) through the
|
|
91
|
+
* run's models, at most `n` results: a Search. `models`: the run's (searchOn). */
|
|
92
|
+
export async function hostedSearch(query, n, ref, signal, models = runModels) {
|
|
93
|
+
const slash = ref?.indexOf("/") ?? -1;
|
|
94
|
+
const model = models && ref && slash > 0 ? models.getModel(ref.slice(0, slash), ref.slice(slash + 1)) : undefined;
|
|
95
|
+
if (!models || !model)
|
|
96
|
+
return { error: `web_search has no model to search on in this run${ref ? ` (${ref})` : ""}` };
|
|
97
|
+
const anthropic = model.api === "anthropic-messages";
|
|
98
|
+
if (!anthropic && model.api !== "openai-responses")
|
|
99
|
+
return { error: `web_search: ${ref} has no hosted web search here` };
|
|
100
|
+
const read = reader(anthropic);
|
|
101
|
+
const context = { messages: [{ role: "user", content: [{ type: "text", text: `Search the web for: ${query}\n\nAnswer briefly from what the search finds, and name each source by its URL.` }], timestamp: Date.now() }] };
|
|
102
|
+
const block = BLOCK_BILLED.test(model.id) ? (8_000 * (model.cost?.input ?? 0)) / 1e6 : 0;
|
|
103
|
+
sideRequests.set(context, { label: "web_search", extraInputTokens: HOSTED_SEARCH_ALLOWANCE_TOKENS, maxFeeUsd: HOSTED_MAX_USES * (SEARCH_USD + block), feeUsd: () => read.searches() * (SEARCH_USD + block) });
|
|
104
|
+
let answer;
|
|
105
|
+
try {
|
|
106
|
+
answer = await models.completeSimple(model, context, {
|
|
107
|
+
maxTokens: ANSWER_TOKENS,
|
|
108
|
+
maxRetries: 0,
|
|
109
|
+
timeoutMs: TIMEOUT_MS,
|
|
110
|
+
...(signal ? { signal } : {}),
|
|
111
|
+
// The hosted tool, exactly, and no other: the context offers none of its own.
|
|
112
|
+
onPayload: (payload) => {
|
|
113
|
+
const body = payload;
|
|
114
|
+
return anthropic ? { ...body, tools: [ANTHROPIC_SEARCH_TOOL] } : { ...body, ...OPENAI_SEARCH_LIMIT, tools: [OPENAI_SEARCH_TOOL], include: [...(Array.isArray(body.include) ? body.include : []), "web_search_call.action.sources"] };
|
|
115
|
+
},
|
|
116
|
+
onProviderStreamEvent: (event) => read.event(event),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return { error: `the provider's search failed: ${String(error?.message ?? error).slice(0, 300)}` };
|
|
121
|
+
}
|
|
122
|
+
if (answer.stopReason === "error" || answer.stopReason === "aborted")
|
|
123
|
+
return { error: answer.stopReason === "aborted" ? "the search was stopped" : `the provider's search failed: ${(answer.errorMessage ?? "no detail").slice(0, 300)}` };
|
|
124
|
+
const failed = read.failed();
|
|
125
|
+
if (failed)
|
|
126
|
+
return { error: `the provider's search failed: ${failed}` };
|
|
127
|
+
const said = answer.content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("").trim();
|
|
128
|
+
return { provider: "native", query, results: read.hits().slice(0, n), ...(said ? { text: clip(said, ANSWER_MAX) } : {}) };
|
|
129
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export declare const SOURCES: readonly ["claude-code", "codex", "pi"];
|
|
2
|
+
export type Source = (typeof SOURCES)[number];
|
|
3
|
+
/** The harness of serve that runs what each source ran. */
|
|
4
|
+
export declare const HARNESS_OF: Record<Source, string>;
|
|
5
|
+
export type ToolCall = {
|
|
6
|
+
type: "toolCall";
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
arguments: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
/** A request's tokens as pi counts them: `input` is the input neither read from nor written to the cache;
|
|
12
|
+
* `cacheWrite1h`, the part of `cacheWrite` kept for an hour, which Anthropic prices higher. */
|
|
13
|
+
export type Usage = {
|
|
14
|
+
input: number;
|
|
15
|
+
output: number;
|
|
16
|
+
cacheRead: number;
|
|
17
|
+
cacheWrite: number;
|
|
18
|
+
cacheWrite1h?: number;
|
|
19
|
+
};
|
|
20
|
+
/** An assistant turn is one model request: `model` the one it ran on ("provider/model"), `effort` the effort or
|
|
21
|
+
* thinking level it ran at, `usage` its tokens, each absent when the source does not say; `error`, why it failed. A
|
|
22
|
+
* note is a line the harness itself wrote in the conversation: no request, nor the person's. */
|
|
23
|
+
export type Turn = ({
|
|
24
|
+
role: "user";
|
|
25
|
+
text: string;
|
|
26
|
+
at: number;
|
|
27
|
+
} | {
|
|
28
|
+
role: "note";
|
|
29
|
+
author: string;
|
|
30
|
+
text: string;
|
|
31
|
+
at: number;
|
|
32
|
+
} | {
|
|
33
|
+
role: "assistant";
|
|
34
|
+
text: string;
|
|
35
|
+
calls: ToolCall[];
|
|
36
|
+
at: number;
|
|
37
|
+
costUsd?: number;
|
|
38
|
+
key?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
effort?: string;
|
|
41
|
+
usage?: Usage;
|
|
42
|
+
error?: string;
|
|
43
|
+
} | {
|
|
44
|
+
role: "toolResult";
|
|
45
|
+
callId: string;
|
|
46
|
+
name: string;
|
|
47
|
+
text: string;
|
|
48
|
+
isError: boolean;
|
|
49
|
+
at: number;
|
|
50
|
+
}) & {
|
|
51
|
+
/** The source's own ids of the records the turn was read from (Claude Code's uuids): a later import counts them once. */
|
|
52
|
+
uuids?: string[];
|
|
53
|
+
};
|
|
54
|
+
export type Ended = "completed" | "failed" | "stopped";
|
|
55
|
+
/** The longest gap between two records counted as time at work, as WakaTime counts it: a longer gap is a session left
|
|
56
|
+
* open and counts nothing. Claude Code's Bash tool runs a call for up to 10 minutes with nothing written. */
|
|
57
|
+
export declare const ACTIVE_GAP_MS: number;
|
|
58
|
+
export type Session = {
|
|
59
|
+
source: Source;
|
|
60
|
+
/** The source's own id for the session. */
|
|
61
|
+
id: string;
|
|
62
|
+
file: string;
|
|
63
|
+
cwd?: string;
|
|
64
|
+
/** "provider/model", from the session's latest model. */
|
|
65
|
+
model?: string;
|
|
66
|
+
startedAt?: string;
|
|
67
|
+
endedAt?: string;
|
|
68
|
+
state: Ended;
|
|
69
|
+
/** The whole session's cost, when the source records it; absent is unknown. */
|
|
70
|
+
costUsd?: number;
|
|
71
|
+
firstPrompt?: string;
|
|
72
|
+
/** A subagent's or another session's child: not imported as a run; its usage is its parent's. */
|
|
73
|
+
child: boolean;
|
|
74
|
+
/** A child's parent session, when its file names it (Codex's parent thread). */
|
|
75
|
+
parent?: string;
|
|
76
|
+
/** Read only when asked for: a dry run reads none. */
|
|
77
|
+
turns: Turn[];
|
|
78
|
+
users: number;
|
|
79
|
+
/** Time at work: the gaps between its records of at most ACTIVE_GAP_MS each. */
|
|
80
|
+
activeMs: number;
|
|
81
|
+
/** Records it holds that were read already (in an earlier file of the import, or earlier in this one): copies. */
|
|
82
|
+
copies: number;
|
|
83
|
+
/** The effort or thinking level most of its requests ran at, as the source names it; with its turns only. */
|
|
84
|
+
effort?: string;
|
|
85
|
+
};
|
|
86
|
+
/** The session files of `source` under `home`, never through a link. */
|
|
87
|
+
export declare function sessionFiles(home: string, source: Source): Promise<string[]>;
|
|
88
|
+
/** Claude Code's subagents' session files under `home`, in <session id>/subagents/ (a workflow's a folder deeper), each
|
|
89
|
+
* with the session file it ran under (`of`): the one beside the folder it sits in. A session moved to another project
|
|
90
|
+
* folder keeps its id there, with copies of its subagents' files: each folder's are its own file's. Never through a
|
|
91
|
+
* link. */
|
|
92
|
+
export declare function childFiles(home: string): Promise<{
|
|
93
|
+
file: string;
|
|
94
|
+
of: string;
|
|
95
|
+
}[]>;
|
|
96
|
+
/** One session file of `source`, read whole; `turns: false` keeps only what a listing shows. `seen`: the records and
|
|
97
|
+
* responses an import has read already, across its files; a record in it (a copy a resumed session's file carries) adds
|
|
98
|
+
* nothing, and this file's are added to it. */
|
|
99
|
+
export declare function readSession(file: string, source: Source, { turns: keep, seen }?: {
|
|
100
|
+
turns?: boolean;
|
|
101
|
+
seen?: Set<string>;
|
|
102
|
+
}): Promise<Session>;
|
|
103
|
+
/** The effort most of `turns`' requests ran at, as the model of most requests is a run's model: the first seen of a tie. */
|
|
104
|
+
export declare function mostEffortOf(turns: readonly Turn[]): string | undefined;
|