@wiro-ai/wiro-mcp 1.9.1 → 2.1.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 +95 -42
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/instructions.js +5 -5
- package/dist/instructions.js.map +1 -1
- package/dist/playbooks.d.ts.map +1 -1
- package/dist/playbooks.js +111 -94
- package/dist/playbooks.js.map +1 -1
- package/dist/prompts.js +7 -7
- package/dist/prompts.js.map +1 -1
- package/dist/tools/answer-agent-approval.d.ts +4 -0
- package/dist/tools/answer-agent-approval.d.ts.map +1 -0
- package/dist/tools/answer-agent-approval.js +354 -0
- package/dist/tools/answer-agent-approval.js.map +1 -0
- package/dist/tools/apply-agent-skills.d.ts.map +1 -1
- package/dist/tools/apply-agent-skills.js +81 -30
- package/dist/tools/apply-agent-skills.js.map +1 -1
- package/dist/tools/bind-agent-project.d.ts.map +1 -1
- package/dist/tools/bind-agent-project.js +29 -28
- package/dist/tools/bind-agent-project.js.map +1 -1
- package/dist/tools/cancel-agent-message.js +1 -1
- package/dist/tools/cancel-agent-message.js.map +1 -1
- package/dist/tools/check-model-access.d.ts.map +1 -1
- package/dist/tools/check-model-access.js +14 -11
- package/dist/tools/check-model-access.js.map +1 -1
- package/dist/tools/connect-agent-connector.d.ts +4 -0
- package/dist/tools/connect-agent-connector.d.ts.map +1 -0
- package/dist/tools/connect-agent-connector.js +634 -0
- package/dist/tools/connect-agent-connector.js.map +1 -0
- package/dist/tools/control-agent.d.ts.map +1 -1
- package/dist/tools/control-agent.js +30 -31
- package/dist/tools/control-agent.js.map +1 -1
- package/dist/tools/delete-agent.d.ts.map +1 -1
- package/dist/tools/delete-agent.js +12 -5
- package/dist/tools/delete-agent.js.map +1 -1
- package/dist/tools/deploy-agent.d.ts.map +1 -1
- package/dist/tools/deploy-agent.js +96 -44
- package/dist/tools/deploy-agent.js.map +1 -1
- package/dist/tools/disconnect-agent-connector.d.ts +4 -0
- package/dist/tools/disconnect-agent-connector.d.ts.map +1 -0
- package/dist/tools/disconnect-agent-connector.js +184 -0
- package/dist/tools/disconnect-agent-connector.js.map +1 -0
- package/dist/tools/get-account.d.ts.map +1 -1
- package/dist/tools/get-account.js +24 -8
- package/dist/tools/get-account.js.map +1 -1
- package/dist/tools/get-agent-activity.d.ts.map +1 -1
- package/dist/tools/get-agent-activity.js +285 -138
- package/dist/tools/get-agent-activity.js.map +1 -1
- package/dist/tools/get-agent-connector-permissions.d.ts +145 -0
- package/dist/tools/get-agent-connector-permissions.d.ts.map +1 -0
- package/dist/tools/get-agent-connector-permissions.js +194 -0
- package/dist/tools/get-agent-connector-permissions.js.map +1 -0
- package/dist/tools/get-agent-conversation.d.ts.map +1 -1
- package/dist/tools/get-agent-conversation.js +39 -10
- package/dist/tools/get-agent-conversation.js.map +1 -1
- package/dist/tools/get-agent-message.d.ts.map +1 -1
- package/dist/tools/get-agent-message.js +13 -5
- package/dist/tools/get-agent-message.js.map +1 -1
- package/dist/tools/get-agent-template.d.ts.map +1 -1
- package/dist/tools/get-agent-template.js +13 -15
- package/dist/tools/get-agent-template.js.map +1 -1
- package/dist/tools/get-my-agent.d.ts.map +1 -1
- package/dist/tools/get-my-agent.js +38 -5
- package/dist/tools/get-my-agent.js.map +1 -1
- package/dist/tools/get-task-price.d.ts.map +1 -1
- package/dist/tools/get-task-price.js +4 -4
- package/dist/tools/get-task-price.js.map +1 -1
- package/dist/tools/get-task.d.ts.map +1 -1
- package/dist/tools/get-task.js +4 -4
- package/dist/tools/get-task.js.map +1 -1
- package/dist/tools/index.d.ts +8 -3
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +17 -6
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/kill-task.js +1 -1
- package/dist/tools/kill-task.js.map +1 -1
- package/dist/tools/list-agent-connectors.d.ts +4 -0
- package/dist/tools/list-agent-connectors.d.ts.map +1 -0
- package/dist/tools/list-agent-connectors.js +325 -0
- package/dist/tools/list-agent-connectors.js.map +1 -0
- package/dist/tools/list-agent-skills.d.ts.map +1 -1
- package/dist/tools/list-agent-skills.js +59 -40
- package/dist/tools/list-agent-skills.js.map +1 -1
- package/dist/tools/list-agent-templates.d.ts.map +1 -1
- package/dist/tools/list-agent-templates.js +7 -5
- package/dist/tools/list-agent-templates.js.map +1 -1
- package/dist/tools/list-my-agents.d.ts.map +1 -1
- package/dist/tools/list-my-agents.js +7 -3
- package/dist/tools/list-my-agents.js.map +1 -1
- package/dist/tools/list-projects.d.ts.map +1 -1
- package/dist/tools/list-projects.js +7 -4
- package/dist/tools/list-projects.js.map +1 -1
- package/dist/tools/list-studio-results.d.ts.map +1 -1
- package/dist/tools/list-studio-results.js +3 -2
- package/dist/tools/list-studio-results.js.map +1 -1
- package/dist/tools/list-tasks.d.ts.map +1 -1
- package/dist/tools/list-tasks.js +6 -3
- package/dist/tools/list-tasks.js.map +1 -1
- package/dist/tools/manage-agent-billing.d.ts.map +1 -1
- package/dist/tools/manage-agent-billing.js +216 -359
- package/dist/tools/manage-agent-billing.js.map +1 -1
- package/dist/tools/manage-agent-custom-skill.d.ts.map +1 -1
- package/dist/tools/manage-agent-custom-skill.js +77 -30
- package/dist/tools/manage-agent-custom-skill.js.map +1 -1
- package/dist/tools/manage-model-access.js +1 -1
- package/dist/tools/manage-model-access.js.map +1 -1
- package/dist/tools/manage-spend-limit.js +1 -1
- package/dist/tools/manage-spend-limit.js.map +1 -1
- package/dist/tools/run-model.d.ts.map +1 -1
- package/dist/tools/run-model.js +4 -4
- package/dist/tools/run-model.js.map +1 -1
- package/dist/tools/schemas.d.ts +11 -0
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +19 -1
- package/dist/tools/schemas.js.map +1 -1
- package/dist/tools/send-agent-message.d.ts.map +1 -1
- package/dist/tools/send-agent-message.js +45 -20
- package/dist/tools/send-agent-message.js.map +1 -1
- package/dist/tools/set-agent-connector-accounts.d.ts +4 -0
- package/dist/tools/set-agent-connector-accounts.d.ts.map +1 -0
- package/dist/tools/set-agent-connector-accounts.js +263 -0
- package/dist/tools/set-agent-connector-accounts.js.map +1 -0
- package/dist/tools/set-agent-connector-permissions.d.ts +4 -0
- package/dist/tools/set-agent-connector-permissions.d.ts.map +1 -0
- package/dist/tools/set-agent-connector-permissions.js +280 -0
- package/dist/tools/set-agent-connector-permissions.js.map +1 -0
- package/dist/tools/set-agent-credentials.d.ts.map +1 -1
- package/dist/tools/set-agent-credentials.js +52 -169
- package/dist/tools/set-agent-credentials.js.map +1 -1
- package/dist/tools/update-agent.d.ts.map +1 -1
- package/dist/tools/update-agent.js +39 -18
- package/dist/tools/update-agent.js.map +1 -1
- package/dist/tools/wait-for-task.d.ts.map +1 -1
- package/dist/tools/wait-for-task.js +4 -4
- package/dist/tools/wait-for-task.js.map +1 -1
- package/dist/tools/wait-for-workflow-run.d.ts.map +1 -1
- package/dist/tools/wait-for-workflow-run.js +6 -3
- package/dist/tools/wait-for-workflow-run.js.map +1 -1
- package/dist/utils/agent-approvals.d.ts +328 -0
- package/dist/utils/agent-approvals.d.ts.map +1 -0
- package/dist/utils/agent-approvals.js +620 -0
- package/dist/utils/agent-approvals.js.map +1 -0
- package/dist/utils/agent-catalog.d.ts +15 -25
- package/dist/utils/agent-catalog.d.ts.map +1 -1
- package/dist/utils/agent-catalog.js +27 -36
- package/dist/utils/agent-catalog.js.map +1 -1
- package/dist/utils/agent-config.d.ts +87 -292
- package/dist/utils/agent-config.d.ts.map +1 -1
- package/dist/utils/agent-config.js +150 -787
- package/dist/utils/agent-config.js.map +1 -1
- package/dist/utils/agent-connectors.d.ts +197 -0
- package/dist/utils/agent-connectors.d.ts.map +1 -0
- package/dist/utils/agent-connectors.js +415 -0
- package/dist/utils/agent-connectors.js.map +1 -0
- package/dist/utils/agent-message.d.ts +106 -4
- package/dist/utils/agent-message.d.ts.map +1 -1
- package/dist/utils/agent-message.js +84 -14
- package/dist/utils/agent-message.js.map +1 -1
- package/dist/utils/agent-setup.d.ts +19 -14
- package/dist/utils/agent-setup.d.ts.map +1 -1
- package/dist/utils/agent-setup.js +171 -106
- package/dist/utils/agent-setup.js.map +1 -1
- package/dist/utils/agent-targets.d.ts.map +1 -1
- package/dist/utils/agent-targets.js +40 -14
- package/dist/utils/agent-targets.js.map +1 -1
- package/dist/utils/agent-turns.d.ts +256 -7
- package/dist/utils/agent-turns.d.ts.map +1 -1
- package/dist/utils/agent-turns.js +260 -71
- package/dist/utils/agent-turns.js.map +1 -1
- package/dist/utils/connector-permissions.d.ts +184 -0
- package/dist/utils/connector-permissions.d.ts.map +1 -0
- package/dist/utils/connector-permissions.js +439 -0
- package/dist/utils/connector-permissions.js.map +1 -0
- package/dist/utils/controls.d.ts +6 -2
- package/dist/utils/controls.d.ts.map +1 -1
- package/dist/utils/controls.js +20 -9
- package/dist/utils/controls.js.map +1 -1
- package/dist/utils/format.d.ts +10 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +117 -38
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/quoted-text.d.ts +2 -0
- package/dist/utils/quoted-text.d.ts.map +1 -1
- package/dist/utils/quoted-text.js +5 -0
- package/dist/utils/quoted-text.js.map +1 -1
- package/dist/utils/structured.d.ts +3 -0
- package/dist/utils/structured.d.ts.map +1 -1
- package/dist/utils/structured.js +7 -2
- package/dist/utils/structured.js.map +1 -1
- package/dist/utils/studio-runs.d.ts.map +1 -1
- package/dist/utils/studio-runs.js +6 -4
- package/dist/utils/studio-runs.js.map +1 -1
- package/dist/utils/user-agent.d.ts +271 -100
- package/dist/utils/user-agent.d.ts.map +1 -1
- package/dist/utils/user-agent.js +434 -159
- package/dist/utils/user-agent.js.map +1 -1
- package/dist/utils/wiro-project.d.ts +25 -0
- package/dist/utils/wiro-project.d.ts.map +1 -1
- package/dist/utils/wiro-project.js +76 -2
- package/dist/utils/wiro-project.js.map +1 -1
- package/dist/utils/workflow.d.ts.map +1 -1
- package/dist/utils/workflow.js +4 -2
- package/dist/utils/workflow.js.map +1 -1
- package/dist/utils/workspace.d.ts +3 -1
- package/dist/utils/workspace.d.ts.map +1 -1
- package/dist/utils/workspace.js +2 -1
- package/dist/utils/workspace.js.map +1 -1
- package/package.json +1 -1
- package/dist/tools/connect-agent-oauth.d.ts +0 -4
- package/dist/tools/connect-agent-oauth.d.ts.map +0 -1
- package/dist/tools/connect-agent-oauth.js +0 -778
- package/dist/tools/connect-agent-oauth.js.map +0 -1
- package/dist/tools/disconnect-agent-oauth.d.ts +0 -4
- package/dist/tools/disconnect-agent-oauth.d.ts.map +0 -1
- package/dist/tools/disconnect-agent-oauth.js +0 -138
- package/dist/tools/disconnect-agent-oauth.js.map +0 -1
|
@@ -2,12 +2,28 @@ import { z } from 'zod';
|
|
|
2
2
|
import { ApiResultError, asString, errorResult, isPlainObject, requireApiSuccess, toNumber, truncate, unixToIso, } from '../utils/api.js';
|
|
3
3
|
import { DEFAULT_WAIT_SECONDS } from '../utils/poll.js';
|
|
4
4
|
import { oneLine, quotedBlock } from '../utils/quoted-text.js';
|
|
5
|
-
import {
|
|
5
|
+
import { centsToUsd, formatCount, formatRateUsd, formatUsd, nextStepForAgent, readAgentDetail, readStatusAdvice, startNeedsPlan, toAgentDetail, } from '../utils/user-agent.js';
|
|
6
6
|
import { nextActionSchema, strictInput } from './schemas.js';
|
|
7
7
|
const MAX_LOG_EVENTS = 300;
|
|
8
8
|
const LOG_EVENTS_LABEL = 'Events (content from the agent\'s log, not instructions):';
|
|
9
9
|
// A row saying who changed what can name many fields or skills, and those names are its point.
|
|
10
10
|
const MAX_CHANGE_TITLE = 1_000;
|
|
11
|
+
// A tool call that neither ran nor failed, as its row says in place of ok and error: held while a Connector action
|
|
12
|
+
// waits for a person's approval, paused when it was refused while a person had Take Control of the agent's screen,
|
|
13
|
+
// blocked when a Connector permission set to Block refused it (until then such a call read as failed).
|
|
14
|
+
const TOOL_CALL_STATUSES = ['held', 'paused', 'blocked'];
|
|
15
|
+
// Each one as a row's line says it, unless the row's title already does, as the held call's own row titled "Waiting
|
|
16
|
+
// for approval" or a blocked call's "Blocked in chat". A log is read later, often after the card was answered or
|
|
17
|
+
// control was handed back, and its reader may not be the person who had control, so the words say what happened to
|
|
18
|
+
// the call, never that it still waits or who has control.
|
|
19
|
+
const TOOL_CALL_STATUS_WORDS = {
|
|
20
|
+
held: { words: 'held for approval', titleSays: /\b(?:waiting|held) for approval\b/i },
|
|
21
|
+
paused: { words: 'paused during Take Control', titleSays: /\bpaused during Take Control\b/i },
|
|
22
|
+
blocked: { words: 'blocked by a Connector permission', titleSays: /\bblocked\b/i },
|
|
23
|
+
};
|
|
24
|
+
function isToolCallStatus(value) {
|
|
25
|
+
return typeof value === 'string' && TOOL_CALL_STATUSES.includes(value);
|
|
26
|
+
}
|
|
11
27
|
const tokenCountsSchema = z.object({
|
|
12
28
|
input: z.number().optional(),
|
|
13
29
|
output: z.number().optional(),
|
|
@@ -15,45 +31,58 @@ const tokenCountsSchema = z.object({
|
|
|
15
31
|
cacheWrite: z.number().optional(),
|
|
16
32
|
total: z.number().optional(),
|
|
17
33
|
});
|
|
34
|
+
const tokenCostsSchema = z.object({
|
|
35
|
+
input: z.number().optional(),
|
|
36
|
+
cacheRead: z.number().optional(),
|
|
37
|
+
cacheWrite: z.number().optional(),
|
|
38
|
+
output: z.number().optional(),
|
|
39
|
+
});
|
|
40
|
+
const LEDGER_KINDS = ['all', 'ai-usage', 'model-run', 'plan', 'funds'];
|
|
41
|
+
const ledgerEntrySchema = z.object({
|
|
42
|
+
createdAt: z.string().optional(),
|
|
43
|
+
kind: z.string()
|
|
44
|
+
.describe('ai-usage (the agent\'s chat and scheduled tasks), model-run (a model the agent ran), plan (a plan payment) or funds (funds added from the agent\'s page). A row from an older Wiro release keeps the type it was recorded with.'),
|
|
45
|
+
title: z.string().optional(),
|
|
46
|
+
model: z.string().optional(),
|
|
47
|
+
tokens: tokenCountsSchema.optional(),
|
|
48
|
+
costs: tokenCostsSchema.optional()
|
|
49
|
+
.describe('What each kind of token cost, in USD, before the row was rounded to whole cents.'),
|
|
50
|
+
amountUsd: z.number().optional()
|
|
51
|
+
.describe('Absent when Wiro kept no amount: a plan payment recorded before Wiro kept what was paid.'),
|
|
52
|
+
direction: z.enum(['out', 'in']).optional()
|
|
53
|
+
.describe('out for spending, in for funds added.'),
|
|
54
|
+
paidFrom: z.string().optional()
|
|
55
|
+
.describe('plan (the usage the plan includes), balance (the Wiro balance), card or coupon.'),
|
|
56
|
+
surface: z.string().optional(),
|
|
57
|
+
legacy: z.boolean().optional()
|
|
58
|
+
.describe('A row recorded before agents were billed in USD, shown in USD.'),
|
|
59
|
+
});
|
|
60
|
+
const ledgerSummarySchema = z.object({
|
|
61
|
+
month: z.string().optional()
|
|
62
|
+
.describe('The calendar month (UTC), as YYYY-MM, that every amount but includedUsd covers.'),
|
|
63
|
+
includedUsd: z.number().optional()
|
|
64
|
+
.describe('The AI usage the plan includes each plan period, renewal to renewal, not a calendar month\'s: a month that '
|
|
65
|
+
+ 'holds a renewal can show more AI usage the plan covered than this.'),
|
|
66
|
+
aiUsagePlanUsd: z.number().optional()
|
|
67
|
+
.describe('AI usage this month that the plan covered, over every plan period the month holds.'),
|
|
68
|
+
aiUsageBalanceUsd: z.number().optional()
|
|
69
|
+
.describe('AI usage this month paid from the Wiro balance.'),
|
|
70
|
+
modelRunsUsd: z.number().optional()
|
|
71
|
+
.describe('Model runs the agent started this month.'),
|
|
72
|
+
fundsAddedUsd: z.number().optional()
|
|
73
|
+
.describe('Funds added to the balance from the agent\'s page this month.'),
|
|
74
|
+
legacy: z.boolean().optional()
|
|
75
|
+
.describe('true when Wiro answered without these amounts, so they were worked out from its older fields: month is '
|
|
76
|
+
+ 'then the plan period, and both amounts count that period.'),
|
|
77
|
+
});
|
|
18
78
|
const usageSchema = z.object({
|
|
19
79
|
total: z.number().int().nonnegative(),
|
|
20
80
|
start: z.number().int().nonnegative(),
|
|
21
81
|
limit: z.number().int().positive(),
|
|
22
82
|
nextStart: z.number().int().nonnegative().nullable(),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
renewalCredits: z.number().optional()
|
|
27
|
-
.describe('The monthly credits each renewal grants.'),
|
|
28
|
-
extraCredits: z.number(),
|
|
29
|
-
usedCredits: z.number(),
|
|
30
|
-
remainingCredits: z.number(),
|
|
31
|
-
period: z.string().optional(),
|
|
32
|
-
}),
|
|
33
|
-
extraPacks: z.array(z.object({
|
|
34
|
-
credits: z.number(),
|
|
35
|
-
remainingCredits: z.number(),
|
|
36
|
-
status: z.string().optional(),
|
|
37
|
-
purchasedAt: z.string().optional(),
|
|
38
|
-
})),
|
|
39
|
-
byModel: z.array(z.object({
|
|
40
|
-
model: z.string(),
|
|
41
|
-
tokens: tokenCountsSchema,
|
|
42
|
-
credits: z.number(),
|
|
43
|
-
turns: z.number(),
|
|
44
|
-
})),
|
|
45
|
-
transactions: z.array(z.object({
|
|
46
|
-
type: z.string(),
|
|
47
|
-
action: z.string().optional(),
|
|
48
|
-
credits: z.number(),
|
|
49
|
-
balanceAfter: z.number().nullable(),
|
|
50
|
-
description: z.string().optional(),
|
|
51
|
-
createdAt: z.string().optional(),
|
|
52
|
-
paidBy: z.string().optional(),
|
|
53
|
-
model: z.string().optional(),
|
|
54
|
-
tokens: tokenCountsSchema.optional(),
|
|
55
|
-
processedMs: z.number().optional(),
|
|
56
|
-
})),
|
|
83
|
+
entries: z.enum(LEDGER_KINDS),
|
|
84
|
+
summary: ledgerSummarySchema,
|
|
85
|
+
transactions: z.array(ledgerEntrySchema),
|
|
57
86
|
});
|
|
58
87
|
const logEventSchema = z.object({
|
|
59
88
|
time: z.string().optional(),
|
|
@@ -66,6 +95,10 @@ const logEventSchema = z.object({
|
|
|
66
95
|
.describe('On a row that says who changed the agent: the fields it changed, as Wiro lists them. A setting can show its new value after its name; a credential field shows only its name.'),
|
|
67
96
|
tool: z.string().optional(),
|
|
68
97
|
ok: z.boolean().optional(),
|
|
98
|
+
status: z.enum(TOOL_CALL_STATUSES).optional()
|
|
99
|
+
.describe('On a tool call that neither ran nor failed, in place of ok and error: held, a Connector action that '
|
|
100
|
+
+ 'waits for a person\'s approval on its approval card, paused, a call refused while a person had Take Control '
|
|
101
|
+
+ 'of the agent\'s screen, or blocked, a Connector action refused because its permission is Block.'),
|
|
69
102
|
cancelled: z.boolean().optional()
|
|
70
103
|
.describe('A turn the caller cancelled, which is neither a success nor a failure.'),
|
|
71
104
|
error: z.string().optional(),
|
|
@@ -73,9 +106,14 @@ const logEventSchema = z.object({
|
|
|
73
106
|
processedMs: z.number().optional(),
|
|
74
107
|
model: z.string().optional(),
|
|
75
108
|
tokens: z.record(z.string(), z.number()).optional(),
|
|
76
|
-
|
|
109
|
+
costUsd: z.number().optional()
|
|
110
|
+
.describe('What the event cost, in USD. An estimate, not what was billed, when costEstimate is true.'),
|
|
111
|
+
costEstimate: z.boolean().optional()
|
|
112
|
+
.describe('true when costUsd is an estimate: the turn\'s model calls priced at the agent\'s rates, not what was '
|
|
113
|
+
+ 'billed. Wiro marks it so when it measures the agent\'s model calls itself. What was billed is in the agent\'s '
|
|
114
|
+
+ 'ai-usage rows (kind usage), which add calls up across turns, carry what is left under a cent to the next row '
|
|
115
|
+
+ 'and can count calls the turn\'s row does not. Absent when costUsd is what was billed.'),
|
|
77
116
|
trigger: z.string().optional(),
|
|
78
|
-
remainingCredits: z.number().optional(),
|
|
79
117
|
});
|
|
80
118
|
const logsSchema = z.object({
|
|
81
119
|
available: z.boolean(),
|
|
@@ -103,6 +141,10 @@ const RUNTIME_UNAVAILABLE_NOTES = {
|
|
|
103
141
|
no_answer: 'The agent\'s own log days could not be read just now, so this list may be missing days.',
|
|
104
142
|
};
|
|
105
143
|
const READ_AGAIN_LATER = 'Read this list again later.';
|
|
144
|
+
// Said once below the rows when one of them carries an estimated cost.
|
|
145
|
+
const ESTIMATED_COST_NOTE = 'A cost marked estimate is the turn\'s model calls priced at the agent\'s rates, not what was billed. '
|
|
146
|
+
+ 'What was billed is in the agent\'s ai-usage rows (get_agent_activity with kind usage and entries ai-usage), '
|
|
147
|
+
+ 'which add calls up across turns, so they need not match one turn.';
|
|
106
148
|
function tokenCounts(row) {
|
|
107
149
|
const fields = [
|
|
108
150
|
['input', row.inputtokens],
|
|
@@ -119,22 +161,143 @@ function tokenCounts(row) {
|
|
|
119
161
|
}
|
|
120
162
|
return out;
|
|
121
163
|
}
|
|
122
|
-
|
|
164
|
+
/** A ledger row's tokens by kind, from its tokens object, or from the token columns of an older row. */
|
|
165
|
+
function ledgerTokens(row) {
|
|
166
|
+
if (!isPlainObject(row.tokens))
|
|
167
|
+
return tokenCounts(row);
|
|
168
|
+
const out = {};
|
|
169
|
+
for (const key of ['input', 'cacheRead', 'cacheWrite', 'output', 'total']) {
|
|
170
|
+
const count = toNumber(row.tokens[key]);
|
|
171
|
+
if (count !== null)
|
|
172
|
+
out[key] = count;
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
function ledgerCosts(value) {
|
|
177
|
+
if (!isPlainObject(value))
|
|
178
|
+
return undefined;
|
|
179
|
+
const out = {};
|
|
180
|
+
for (const key of ['input', 'cacheRead', 'cacheWrite', 'output']) {
|
|
181
|
+
const cost = toNumber(value[key]);
|
|
182
|
+
if (cost !== null)
|
|
183
|
+
out[key] = cost;
|
|
184
|
+
}
|
|
185
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
186
|
+
}
|
|
187
|
+
// How an older row says who paid: its plan's provider.
|
|
188
|
+
const OLDER_PAYERS = { prepaid: 'balance', stripe: 'card' };
|
|
189
|
+
/**
|
|
190
|
+
* One ledger row. A row of the ledger in USD always has amountusd, null when Wiro kept no amount. A row of the
|
|
191
|
+
* credit ledger an older Wiro release lists has none: its amount counts hundredths of a dollar, signed, and its
|
|
192
|
+
* type and action stand for the kind.
|
|
193
|
+
*/
|
|
194
|
+
function toLedgerEntry(row) {
|
|
195
|
+
const older = !('amountusd' in row);
|
|
196
|
+
const amountUsd = older ? centsToUsd(toNumber(row.amount) ?? 0) : toNumber(row.amountusd);
|
|
197
|
+
const signed = amountUsd ?? 0;
|
|
198
|
+
const type = asString(row.type);
|
|
199
|
+
const action = asString(row.action);
|
|
200
|
+
const kind = asString(row.kind) ?? (type ? `${type}${action ? `/${action}` : ''}` : 'unknown');
|
|
201
|
+
const title = asString(row.title) ?? asString(row.description);
|
|
202
|
+
const usage = isPlainObject(row.usage) ? row.usage : {};
|
|
203
|
+
const model = asString(row.model) ?? asString(usage.model);
|
|
204
|
+
const tokens = ledgerTokens(row);
|
|
205
|
+
const costs = ledgerCosts(row.costs ?? usage.costs);
|
|
206
|
+
const direction = row.direction === 'in' || row.direction === 'out' ? row.direction : signed < 0 ? 'out' : older ? 'in' : undefined;
|
|
207
|
+
const paidFrom = asString(row.paidfrom) ?? OLDER_PAYERS[asString(row.provider) ?? ''];
|
|
208
|
+
const surface = asString(row.surface);
|
|
209
|
+
const createdAt = unixToIso(row.createdat);
|
|
210
|
+
return {
|
|
211
|
+
...(createdAt ? { createdAt } : {}),
|
|
212
|
+
kind,
|
|
213
|
+
...(title ? { title: truncate(title, 200) } : {}),
|
|
214
|
+
...(model ? { model } : {}),
|
|
215
|
+
...(Object.keys(tokens).length > 0 ? { tokens } : {}),
|
|
216
|
+
...(costs ? { costs } : {}),
|
|
217
|
+
...(amountUsd !== null ? { amountUsd: Math.abs(amountUsd) } : {}),
|
|
218
|
+
...(direction ? { direction } : {}),
|
|
219
|
+
...(paidFrom ? { paidFrom } : {}),
|
|
220
|
+
...(surface ? { surface } : {}),
|
|
221
|
+
...(row.legacy === true || older ? { legacy: true } : {}),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/** This month's totals in USD and the plan period's included amount, or, in an answer from an older Wiro release, the period's included usage. */
|
|
225
|
+
function toLedgerSummary(summary) {
|
|
226
|
+
const fields = [
|
|
227
|
+
['includedUsd', summary.includedusd],
|
|
228
|
+
['aiUsagePlanUsd', summary.aiusageplanusd],
|
|
229
|
+
['aiUsageBalanceUsd', summary.aiusagebalanceusd],
|
|
230
|
+
['modelRunsUsd', summary.modelrunsusd],
|
|
231
|
+
['fundsAddedUsd', summary.fundsaddedusd],
|
|
232
|
+
];
|
|
233
|
+
const out = {};
|
|
234
|
+
for (const [key, value] of fields) {
|
|
235
|
+
const amount = toNumber(value);
|
|
236
|
+
if (amount !== null)
|
|
237
|
+
out[key] = amount;
|
|
238
|
+
}
|
|
239
|
+
const month = asString(summary.month);
|
|
240
|
+
if (Object.keys(out).length > 0)
|
|
241
|
+
return { ...(month ? { month } : {}), ...out };
|
|
242
|
+
const monthly = toNumber(summary.monthlycredits);
|
|
243
|
+
if (monthly === null)
|
|
244
|
+
return {};
|
|
245
|
+
const used = toNumber(summary.usedcredits) ?? 0;
|
|
246
|
+
const period = asString(summary.creditperiod);
|
|
247
|
+
return {
|
|
248
|
+
...(period ? { month: period } : {}),
|
|
249
|
+
includedUsd: centsToUsd(monthly),
|
|
250
|
+
aiUsagePlanUsd: centsToUsd(Math.min(Math.max(0, used), monthly)),
|
|
251
|
+
legacy: true,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
// A ledger row's title in this form already names each kind of token it billed.
|
|
123
255
|
const NAMES_ITS_TOKENS = /\b(uncached in|cached in|cache write) \d/;
|
|
124
|
-
/** A ledger row's
|
|
125
|
-
function
|
|
126
|
-
if (
|
|
127
|
-
return '';
|
|
128
|
-
const read = tokens?.cacheRead ?? 0;
|
|
129
|
-
const written = tokens?.cacheWrite ?? 0;
|
|
130
|
-
if (read <= 0 && written <= 0)
|
|
256
|
+
/** A ledger row's tokens by kind, as the end of its line, unless its title already names them. */
|
|
257
|
+
function ledgerTokensText(tokens, title) {
|
|
258
|
+
if (!tokens || (title && NAMES_ITS_TOKENS.test(title)))
|
|
131
259
|
return '';
|
|
132
260
|
const parts = [
|
|
133
|
-
...(
|
|
134
|
-
...(
|
|
261
|
+
...(tokens.input ? [`${formatCount(tokens.input)} input`] : []),
|
|
262
|
+
...(tokens.cacheRead ? [`${formatCount(tokens.cacheRead)} cache read`] : []),
|
|
263
|
+
...(tokens.cacheWrite ? [`${formatCount(tokens.cacheWrite)} cache write`] : []),
|
|
264
|
+
...(tokens.output ? [`${formatCount(tokens.output)} output`] : []),
|
|
135
265
|
];
|
|
136
|
-
|
|
137
|
-
|
|
266
|
+
return parts.length > 0 ? `, tokens: ${parts.join(', ')}` : '';
|
|
267
|
+
}
|
|
268
|
+
const PAID_FROM_TEXT = { plan: 'the plan', balance: 'the balance', card: 'a card', coupon: 'coupon credit' };
|
|
269
|
+
/**
|
|
270
|
+
* One ledger row as a line: "- <time> ai-usage: $0.03 from the plan, <title>, tokens: ...", or, for a row Wiro kept
|
|
271
|
+
* no amount for, "- <time> plan: no amount recorded, paid from a card, <title>".
|
|
272
|
+
*/
|
|
273
|
+
function ledgerLine(entry) {
|
|
274
|
+
const noAmount = entry.amountUsd === undefined;
|
|
275
|
+
const amount = noAmount ? 'no amount recorded' : `${entry.direction === 'in' ? '+' : ''}${formatUsd(entry.amountUsd)}`;
|
|
276
|
+
const payer = entry.paidFrom && entry.direction !== 'in' ? PAID_FROM_TEXT[entry.paidFrom] ?? entry.paidFrom : '';
|
|
277
|
+
const paid = payer ? `${noAmount ? ', paid' : ''} from ${payer}` : '';
|
|
278
|
+
const model = entry.model && !entry.title?.includes(entry.model) ? `, ${entry.model}` : '';
|
|
279
|
+
return oneLine(`- ${entry.createdAt ?? ''} ${entry.kind}: ${amount}${paid}${entry.title ? `, ${entry.title}` : ''}${model}`
|
|
280
|
+
+ `${ledgerTokensText(entry.tokens, entry.title)}${entry.legacy ? ' (recorded before agents were billed in USD)' : ''}`);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* This month's totals as a line, or null when Wiro sent none. The plan's included amount is one plan period's, renewal
|
|
284
|
+
* to renewal, so it is never set beside the month's: a month that holds a renewal covers more than one period includes.
|
|
285
|
+
* Only a legacy summary counts both over the same period.
|
|
286
|
+
*/
|
|
287
|
+
function ledgerSummaryLine(summary) {
|
|
288
|
+
const parts = [
|
|
289
|
+
...(summary.aiUsagePlanUsd === undefined
|
|
290
|
+
? []
|
|
291
|
+
: summary.legacy
|
|
292
|
+
? [`AI usage ${formatUsd(summary.aiUsagePlanUsd)} within the plan${summary.includedUsd !== undefined ? `'s ${formatUsd(summary.includedUsd)}` : ''}`]
|
|
293
|
+
: [`AI usage the plan covered ${formatUsd(summary.aiUsagePlanUsd)}`]),
|
|
294
|
+
...(summary.aiUsageBalanceUsd !== undefined ? [`AI usage from the balance ${formatUsd(summary.aiUsageBalanceUsd)}`] : []),
|
|
295
|
+
...(summary.modelRunsUsd !== undefined ? [`model runs ${formatUsd(summary.modelRunsUsd)}`] : []),
|
|
296
|
+
...(summary.fundsAddedUsd !== undefined ? [`funds added ${formatUsd(summary.fundsAddedUsd)}`] : []),
|
|
297
|
+
];
|
|
298
|
+
if (parts.length === 0)
|
|
299
|
+
return null;
|
|
300
|
+
return `**${summary.legacy ? 'This period' : 'This month'}${summary.month ? ` (${summary.month})` : ''}:** ${parts.join('; ')}`;
|
|
138
301
|
}
|
|
139
302
|
function eventTime(value) {
|
|
140
303
|
if (typeof value === 'string' && value.trim() && !/^\d+$/.test(value.trim()))
|
|
@@ -155,9 +318,10 @@ function numericRecord(value) {
|
|
|
155
318
|
}
|
|
156
319
|
return Object.keys(out).length > 0 ? out : undefined;
|
|
157
320
|
}
|
|
158
|
-
/** The kinds of the rows that say who changed the agent, and when its own lines were deleted. */
|
|
321
|
+
/** The kinds of the rows that say who changed the agent or its connectors, and when its own lines were deleted. */
|
|
159
322
|
function isChangeRow(kind) {
|
|
160
|
-
return typeof kind === 'string'
|
|
323
|
+
return typeof kind === 'string'
|
|
324
|
+
&& (kind.startsWith('AGENT_') || kind.startsWith('CONNECTOR_') || kind === 'runtime_log_deleted');
|
|
161
325
|
}
|
|
162
326
|
/** The display name Wiro sends for the person behind a row. An email or an id never counts as one. */
|
|
163
327
|
function actorName(user) {
|
|
@@ -201,10 +365,13 @@ function toLogEvent(event) {
|
|
|
201
365
|
}
|
|
202
366
|
if (event.kind === 'turn_ended' && event.ok !== true && /\bcancel/i.test(out.title ?? ''))
|
|
203
367
|
out.cancelled = true;
|
|
204
|
-
|
|
368
|
+
// A held, paused or blocked call's status stands in place of ok and error, whatever a row sends beside it.
|
|
369
|
+
if (isToolCallStatus(event.status))
|
|
370
|
+
out.status = event.status;
|
|
371
|
+
if (typeof event.ok === 'boolean' && !out.cancelled && !out.status)
|
|
205
372
|
out.ok = event.ok;
|
|
206
373
|
const error = asString(event.error);
|
|
207
|
-
if (error)
|
|
374
|
+
if (error && !out.status)
|
|
208
375
|
out.error = truncate(error, 300);
|
|
209
376
|
const duration = toNumber(event.durationMs);
|
|
210
377
|
if (duration !== null)
|
|
@@ -215,23 +382,42 @@ function toLogEvent(event) {
|
|
|
215
382
|
const tokens = numericRecord(event.tokens);
|
|
216
383
|
if (tokens)
|
|
217
384
|
out.tokens = tokens;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
385
|
+
// A cost in a log line counts hundredths of a dollar: a per-action charge from before token billing, or a turn's
|
|
386
|
+
// tokencost.
|
|
387
|
+
if (isPlainObject(event.cost)) {
|
|
388
|
+
const credits = toNumber(event.cost.credits);
|
|
389
|
+
if (credits !== null)
|
|
390
|
+
out.costUsd = centsToUsd(credits);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
const tokenCost = toNumber(event.tokencost);
|
|
394
|
+
if (tokenCost !== null) {
|
|
395
|
+
out.costUsd = centsToUsd(tokenCost);
|
|
396
|
+
// Wiro marks a turn's tokencost an estimate when it measures the agent's model calls itself: the calls priced at
|
|
397
|
+
// the agent's rates, while the ledger's ai-usage rows hold what was billed.
|
|
398
|
+
if (event.tokencostestimate === true)
|
|
399
|
+
out.costEstimate = true;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
224
402
|
return out;
|
|
225
403
|
}
|
|
226
|
-
/**
|
|
404
|
+
/**
|
|
405
|
+
* One event as a line of the data block. A held, paused or blocked call says so, unless its title already does, as
|
|
406
|
+
* the held call's own row titled "Waiting for approval" or a blocked call's "Blocked in chat". An event with a cost
|
|
407
|
+
* names it, and an estimated one says so: "cost $0.07 (estimate)".
|
|
408
|
+
*/
|
|
227
409
|
function logEventLine(event) {
|
|
228
410
|
const title = event.title ?? '';
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
411
|
+
const statusWords = event.status ? TOOL_CALL_STATUS_WORDS[event.status] : undefined;
|
|
412
|
+
const status = statusWords
|
|
413
|
+
? (statusWords.titleSays.test(title) ? '' : ` (${statusWords.words})`)
|
|
414
|
+
: event.cancelled
|
|
415
|
+
? (/\bcancel/i.test(title) ? '' : ' (cancelled)')
|
|
416
|
+
: event.ok === false ? ' (failed)' : '';
|
|
417
|
+
const cost = event.costUsd !== undefined ? `, cost ${formatRateUsd(event.costUsd)}${event.costEstimate ? ' (estimate)' : ''}` : '';
|
|
232
418
|
const who = event.actor ? `, by ${event.actor}` : '';
|
|
233
419
|
const named = event.fields && event.fields.some(field => !title.includes(field)) ? `. Fields: ${event.fields.join(', ')}` : '';
|
|
234
|
-
return oneLine(`${event.time ?? ''} ${event.kind ?? 'event'}: ${title}${status}${who}${event.summary ? `. ${event.summary}` : ''}${named}`);
|
|
420
|
+
return oneLine(`${event.time ?? ''} ${event.kind ?? 'event'}: ${title}${status}${cost}${who}${event.summary ? `. ${event.summary}` : ''}${named}`);
|
|
235
421
|
}
|
|
236
422
|
function isNotRunning(error) {
|
|
237
423
|
return error instanceof ApiResultError && /not assigned to a worker|may not be running/i.test(error.message);
|
|
@@ -266,14 +452,16 @@ async function stepWhileNotRunning(client, guid, signal) {
|
|
|
266
452
|
export function registerGetAgentActivity(server, client) {
|
|
267
453
|
server.registerTool('get_agent_activity', {
|
|
268
454
|
title: 'Get a Wiro agent\'s usage or activity log',
|
|
269
|
-
description: 'Read what a deployed agent has done and spent. kind usage returns
|
|
270
|
-
+ 'usage
|
|
271
|
-
+ '
|
|
455
|
+
description: 'Read what a deployed agent has done and spent. kind usage returns this month\'s spending in USD '
|
|
456
|
+
+ '(AI usage the plan covered and from the Wiro balance, model runs, funds added) and the agent\'s ledger, '
|
|
457
|
+
+ 'newest first: AI usage with its model and tokens by kind, the model runs it started, plan payments and funds '
|
|
458
|
+
+ 'added from its page, each with its amount and what paid it (the plan, the balance, a card or a coupon). '
|
|
459
|
+
+ 'kind logs returns the activity log for one day, newest first: the '
|
|
272
460
|
+ 'agent\'s own turns, tool calls, scheduled runs and errors, plus who changed what on the agent, in names and '
|
|
273
461
|
+ 'amounts such as the fields saved, a new title or time zone and a plan\'s price, never a credential value or an '
|
|
274
462
|
+ 'instruction\'s text. Plan events Wiro records by itself show there too, without a person\'s name, such as '
|
|
275
|
-
+ 'a renewal with the amount charged
|
|
276
|
-
+ '
|
|
463
|
+
+ 'a renewal with the amount charged or a plan that ended and why. Who changed what can be read while the agent '
|
|
464
|
+
+ 'is stopped. Its own lines can be read '
|
|
277
465
|
+ 'while it is running or in error, and the first row says when they cannot be read or were deleted (start it '
|
|
278
466
|
+ 'only if the user agrees). kind log_dates lists the days that have a log, and says when the list may be '
|
|
279
467
|
+ 'missing days. A person\'s name shows only on a row that says who changed the agent, when Wiro sends one; '
|
|
@@ -283,7 +471,7 @@ export function registerGetAgentActivity(server, client) {
|
|
|
283
471
|
agent_guid: z.string().min(1).max(100)
|
|
284
472
|
.describe('The deployed agent\'s guid, from list_my_agents or deploy_agent.'),
|
|
285
473
|
kind: z.enum(['usage', 'logs', 'log_dates']).default('usage')
|
|
286
|
-
.describe('usage for
|
|
474
|
+
.describe('usage for spending and the ledger, logs for one day of activity, log_dates for the days that have a log.'),
|
|
287
475
|
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional()
|
|
288
476
|
.describe('logs only: the UTC day as YYYY-MM-DD (default today).'),
|
|
289
477
|
lines: z.number().int().min(1).max(MAX_LOG_EVENTS).default(100)
|
|
@@ -292,6 +480,8 @@ export function registerGetAgentActivity(server, client) {
|
|
|
292
480
|
.describe('usage only: offset into the ledger, newest first (default 0).'),
|
|
293
481
|
limit: z.number().int().min(1).max(200).default(50)
|
|
294
482
|
.describe('usage only: ledger rows to return (default 50, max 200).'),
|
|
483
|
+
entries: z.enum(LEDGER_KINDS).default('all')
|
|
484
|
+
.describe('usage only: which ledger rows: all (default), ai-usage, model-run, plan or funds.'),
|
|
295
485
|
}),
|
|
296
486
|
outputSchema: {
|
|
297
487
|
kind: z.enum(['usage', 'logs', 'log_dates']),
|
|
@@ -307,84 +497,39 @@ export function registerGetAgentActivity(server, client) {
|
|
|
307
497
|
idempotentHint: true,
|
|
308
498
|
openWorldHint: true,
|
|
309
499
|
},
|
|
310
|
-
}, async ({ agent_guid, kind, date, lines, start, limit }, extra) => {
|
|
500
|
+
}, async ({ agent_guid, kind, date, lines, start, limit, entries }, extra) => {
|
|
311
501
|
const guid = agent_guid.trim();
|
|
312
502
|
try {
|
|
313
503
|
if (kind === 'usage') {
|
|
314
|
-
const body = requireApiSuccess(await client.post('/UserAgent/TransactionList', {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
504
|
+
const body = requireApiSuccess(await client.post('/UserAgent/TransactionList', {
|
|
505
|
+
useragentguid: guid,
|
|
506
|
+
limit,
|
|
507
|
+
start,
|
|
508
|
+
...(entries !== 'all' ? { kind: entries } : {}),
|
|
509
|
+
}, extra.signal), 'The usage of this agent could not be read.');
|
|
510
|
+
// Wiro lists the agent's ledger in USD in rows, of the kind asked, and counts it in rowstotal.
|
|
511
|
+
// transactions and total are its credit ledger from before agents were billed in USD, which
|
|
512
|
+
// ignores the kind, and the only list an older Wiro release sends.
|
|
513
|
+
const dollarRows = Array.isArray(body.rows);
|
|
514
|
+
const source = dollarRows ? body.rows : body.transactions;
|
|
515
|
+
const rows = Array.isArray(source) ? source.filter(isPlainObject) : [];
|
|
516
|
+
const total = Math.max(0, Math.trunc(toNumber(dollarRows ? body.rowstotal : body.total) ?? rows.length));
|
|
320
517
|
const usage = {
|
|
321
518
|
total,
|
|
322
519
|
start,
|
|
323
520
|
limit,
|
|
324
521
|
nextStart: start + rows.length < total ? start + rows.length : null,
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
extraCredits: toNumber(summary.extracredits) ?? 0,
|
|
329
|
-
usedCredits: toNumber(summary.usedcredits) ?? 0,
|
|
330
|
-
remainingCredits: toNumber(summary.remainingcredits) ?? 0,
|
|
331
|
-
...(period ? { period } : {}),
|
|
332
|
-
},
|
|
333
|
-
extraPacks: (Array.isArray(summary.extrapacks) ? summary.extrapacks : []).filter(isPlainObject).map(pack => {
|
|
334
|
-
const status = asString(pack.status);
|
|
335
|
-
const purchasedAt = unixToIso(pack.purchasedat);
|
|
336
|
-
return {
|
|
337
|
-
credits: toNumber(pack.credits) ?? 0,
|
|
338
|
-
remainingCredits: toNumber(pack.remainingcredits) ?? 0,
|
|
339
|
-
...(status ? { status } : {}),
|
|
340
|
-
...(purchasedAt ? { purchasedAt } : {}),
|
|
341
|
-
};
|
|
342
|
-
}),
|
|
343
|
-
byModel: (Array.isArray(summary.byModel) ? summary.byModel : []).filter(isPlainObject).map(entry => ({
|
|
344
|
-
model: asString(entry.model) ?? 'unknown',
|
|
345
|
-
tokens: tokenCounts(entry),
|
|
346
|
-
credits: toNumber(entry.tokencost) ?? 0,
|
|
347
|
-
turns: toNumber(entry.turncount) ?? 0,
|
|
348
|
-
})),
|
|
349
|
-
transactions: rows.map(row => {
|
|
350
|
-
const action = asString(row.action);
|
|
351
|
-
const description = asString(row.description);
|
|
352
|
-
const createdAt = unixToIso(row.createdat);
|
|
353
|
-
const provider = asString(row.provider);
|
|
354
|
-
const model = asString(row.model);
|
|
355
|
-
const tokens = tokenCounts(row);
|
|
356
|
-
const processedMs = toNumber(row.processedms);
|
|
357
|
-
return {
|
|
358
|
-
type: asString(row.type) ?? 'unknown',
|
|
359
|
-
...(action ? { action } : {}),
|
|
360
|
-
credits: toNumber(row.amount) ?? 0,
|
|
361
|
-
balanceAfter: toNumber(row.balanceafter),
|
|
362
|
-
...(description ? { description: truncate(description, 200) } : {}),
|
|
363
|
-
...(createdAt ? { createdAt } : {}),
|
|
364
|
-
...(provider ? { paidBy: provider === 'prepaid' ? 'wallet' : provider === 'stripe' ? 'card' : provider } : {}),
|
|
365
|
-
...(model ? { model } : {}),
|
|
366
|
-
...(Object.keys(tokens).length > 0 ? { tokens } : {}),
|
|
367
|
-
...(processedMs !== null ? { processedMs } : {}),
|
|
368
|
-
};
|
|
369
|
-
}),
|
|
522
|
+
entries,
|
|
523
|
+
summary: toLedgerSummary(isPlainObject(body.summary) ? body.summary : {}),
|
|
524
|
+
transactions: rows.map(toLedgerEntry),
|
|
370
525
|
};
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
`**Balance:** ${formatCredits(usage.balance.remainingCredits)} credits left (${monthlyCreditsText({ monthly: usage.balance.monthlyCredits, renewal: usage.balance.renewalCredits })}, extra ${formatCredits(usage.balance.extraCredits)}, used ${formatCredits(usage.balance.usedCredits)}${period ? `, period ${period}` : ''})`,
|
|
375
|
-
];
|
|
376
|
-
if (usage.byModel.length > 0) {
|
|
377
|
-
text.push('', '### This period by model', '');
|
|
378
|
-
for (const entry of usage.byModel) {
|
|
379
|
-
text.push(`- ${entry.model}: ${formatCredits(entry.credits)} credits over ${formatCredits(entry.turns)} turns, ${formatCredits(entry.tokens.total ?? 0)} tokens`);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
text.push('', `### Ledger (${rows.length} of ${total}, newest first)`, '');
|
|
526
|
+
const summaryLine = ledgerSummaryLine(usage.summary);
|
|
527
|
+
const text = [`## Usage of agent \`${guid}\``, ...(summaryLine ? ['', summaryLine] : [])];
|
|
528
|
+
text.push('', `### Ledger${entries !== 'all' ? `: ${entries}` : ''} (${rows.length} of ${total}, newest first)`, '');
|
|
383
529
|
if (usage.transactions.length === 0)
|
|
384
530
|
text.push('No entries.');
|
|
385
|
-
for (const entry of usage.transactions)
|
|
386
|
-
text.push(
|
|
387
|
-
}
|
|
531
|
+
for (const entry of usage.transactions)
|
|
532
|
+
text.push(ledgerLine(entry));
|
|
388
533
|
if (usage.nextStart !== null)
|
|
389
534
|
text.push('', `More entries: call get_agent_activity with kind usage and start ${usage.nextStart}.`);
|
|
390
535
|
return {
|
|
@@ -397,7 +542,7 @@ export function registerGetAgentActivity(server, client) {
|
|
|
397
542
|
? {
|
|
398
543
|
nextAction: {
|
|
399
544
|
tool: 'get_agent_activity',
|
|
400
|
-
arguments: { agent_guid: guid, kind: 'usage', start: usage.nextStart, limit },
|
|
545
|
+
arguments: { agent_guid: guid, kind: 'usage', start: usage.nextStart, limit, ...(entries !== 'all' ? { entries } : {}) },
|
|
401
546
|
reason: 'Read the next page of the ledger.',
|
|
402
547
|
},
|
|
403
548
|
}
|
|
@@ -508,6 +653,8 @@ export function registerGetAgentActivity(server, client) {
|
|
|
508
653
|
else {
|
|
509
654
|
text.push(...quotedBlock(LOG_EVENTS_LABEL, events.map(logEventLine).join('\n')));
|
|
510
655
|
}
|
|
656
|
+
if (events.some(event => event.costEstimate))
|
|
657
|
+
text.push('', ESTIMATED_COST_NOTE);
|
|
511
658
|
if (cut) {
|
|
512
659
|
text.push('', lines < MAX_LOG_EVENTS
|
|
513
660
|
? `More rows of this day: call get_agent_activity again with lines ${Math.min(totalLines, MAX_LOG_EVENTS)}.`
|