MCPcopy Create free account
hub / github.com/arctic-cli/interface / run

Function run

packages/arctic/src/session/usage.ts:21–138  ·  view source on GitHub ↗
(input: RunInput)

Source from the content-addressed store, hash-verified

19 }
20
21 export async function run(input: RunInput): Promise<MessageV2.WithParts> {
22 const parentID = (await createSyntheticUserMessage(input)).info.id
23 const now = Date.now()
24
25 const loaderMessage = (await Session.updateMessage({
26 id: Identifier.ascending("message"),
27 role: "assistant",
28 parentID,
29 sessionID: input.sessionID,
30 mode: input.agent,
31 path: {
32 cwd: Instance.directory,
33 root: Instance.worktree,
34 },
35 cost: 0,
36 tokens: {
37 input: 0,
38 output: 0,
39 reasoning: 0,
40 cache: {
41 read: 0,
42 write: 0,
43 },
44 },
45 modelID: input.model.modelID,
46 providerID: input.model.providerID,
47 time: {
48 created: now,
49 completed: now,
50 },
51 finish: "usage",
52 })) as MessageV2.Assistant
53
54 await Session.updatePart({
55 id: Identifier.ascending("part"),
56 messageID: loaderMessage.id,
57 sessionID: input.sessionID,
58 type: "text",
59 text: "Fetching usage...",
60 synthetic: true,
61 time: {
62 start: now,
63 end: now,
64 },
65 })
66
67 let summaryText = ""
68 let providerCount = 0
69 try {
70 const usageRecords = await ProviderUsage.fetch(undefined, { sessionID: input.sessionID })
71 providerCount = usageRecords.length
72 summaryText = formatUsageSummary(usageRecords)
73 log.info("usage summary created", {
74 sessionID: input.sessionID,
75 providerCount,
76 })
77 } catch (error) {
78 const message = error instanceof Error ? error.message : String(error)

Callers

nothing calls this directly

Calls 2

formatUsageSummaryFunction · 0.90

Tested by

no test coverage detected