@wiro-ai/wiro-mcp 1.5.8 → 1.6.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/README.md +15 -13
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +6 -1
- package/dist/client.js.map +1 -1
- package/dist/instructions.js +2 -2
- package/dist/instructions.js.map +1 -1
- package/dist/playbooks.d.ts.map +1 -1
- package/dist/playbooks.js +44 -40
- package/dist/playbooks.js.map +1 -1
- package/dist/prompts.js +3 -3
- package/dist/prompts.js.map +1 -1
- package/dist/tools/apply-agent-skills.d.ts.map +1 -1
- package/dist/tools/apply-agent-skills.js +102 -639
- package/dist/tools/apply-agent-skills.js.map +1 -1
- package/dist/tools/connect-agent-oauth.d.ts.map +1 -1
- package/dist/tools/connect-agent-oauth.js +260 -111
- package/dist/tools/connect-agent-oauth.js.map +1 -1
- package/dist/tools/control-agent.d.ts.map +1 -1
- package/dist/tools/control-agent.js +20 -9
- package/dist/tools/control-agent.js.map +1 -1
- package/dist/tools/deploy-agent.d.ts.map +1 -1
- package/dist/tools/deploy-agent.js +42 -28
- package/dist/tools/deploy-agent.js.map +1 -1
- package/dist/tools/get-agent-activity.d.ts.map +1 -1
- package/dist/tools/get-agent-activity.js +3 -1
- package/dist/tools/get-agent-activity.js.map +1 -1
- package/dist/tools/get-agent-conversation.d.ts.map +1 -1
- package/dist/tools/get-agent-conversation.js +7 -4
- 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 +5 -1
- 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 +11 -9
- package/dist/tools/get-agent-template.js.map +1 -1
- package/dist/tools/get-my-agent.js +4 -4
- package/dist/tools/get-my-agent.js.map +1 -1
- package/dist/tools/list-agent-skills.d.ts.map +1 -1
- package/dist/tools/list-agent-skills.js +22 -17
- 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 +16 -10
- 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 +2 -2
- package/dist/tools/list-my-agents.js.map +1 -1
- package/dist/tools/manage-agent-billing.d.ts.map +1 -1
- package/dist/tools/manage-agent-billing.js +476 -187
- package/dist/tools/manage-agent-billing.js.map +1 -1
- package/dist/tools/send-agent-message.d.ts.map +1 -1
- package/dist/tools/send-agent-message.js +10 -5
- package/dist/tools/send-agent-message.js.map +1 -1
- package/dist/tools/set-agent-credentials.d.ts.map +1 -1
- package/dist/tools/set-agent-credentials.js +24 -6
- 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 +2 -1
- package/dist/tools/update-agent.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/agent-catalog.d.ts +16 -12
- package/dist/utils/agent-catalog.d.ts.map +1 -1
- package/dist/utils/agent-catalog.js +4 -11
- package/dist/utils/agent-catalog.js.map +1 -1
- package/dist/utils/agent-config.d.ts +98 -45
- package/dist/utils/agent-config.d.ts.map +1 -1
- package/dist/utils/agent-config.js +246 -147
- package/dist/utils/agent-config.js.map +1 -1
- package/dist/utils/agent-message.d.ts +18 -0
- package/dist/utils/agent-message.d.ts.map +1 -1
- package/dist/utils/agent-setup.d.ts +53 -2
- package/dist/utils/agent-setup.d.ts.map +1 -1
- package/dist/utils/agent-setup.js +371 -22
- 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 +9 -2
- package/dist/utils/agent-targets.js.map +1 -1
- package/dist/utils/agent-turns.d.ts +18 -0
- package/dist/utils/agent-turns.d.ts.map +1 -1
- package/dist/utils/agent-turns.js +73 -14
- package/dist/utils/agent-turns.js.map +1 -1
- package/dist/utils/api.d.ts +1 -1
- package/dist/utils/api.d.ts.map +1 -1
- package/dist/utils/api.js +3 -3
- package/dist/utils/api.js.map +1 -1
- package/dist/utils/format.d.ts +8 -1
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +16 -2
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/quoted-text.d.ts +7 -0
- package/dist/utils/quoted-text.d.ts.map +1 -1
- package/dist/utils/quoted-text.js +14 -0
- package/dist/utils/quoted-text.js.map +1 -1
- package/dist/utils/structured.d.ts.map +1 -1
- package/dist/utils/structured.js +2 -2
- package/dist/utils/structured.js.map +1 -1
- package/dist/utils/user-agent.d.ts +76 -18
- package/dist/utils/user-agent.d.ts.map +1 -1
- package/dist/utils/user-agent.js +202 -49
- package/dist/utils/user-agent.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,70 +1,33 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { asString, errorResult, errorText,
|
|
3
|
-
import { agentStatusLabel, agentStatusOf, checkSkillSet, credentialLabel, credentialTitles, credentialsNeededFor, customSkillEntries,
|
|
4
|
-
import {
|
|
2
|
+
import { asString, errorResult, errorText, requireApiSuccess, } from '../utils/api.js';
|
|
3
|
+
import { agentStatusLabel, agentStatusOf, checkSkillSet, credentialLabel, credentialTitles, credentialsNeededFor, customSkillEntries, describeSkillsApplyError, diffSkills, enabledSkillNames, isAgentRunning, loadSkillRegistry, newSkillChangeKey, parseSkillChangeKey, pausedSkillTitles, planSkillChanges, readUserAgent, registryTitles, restartNote, skillChangeDigest, workspaceHint, } from '../utils/agent-config.js';
|
|
4
|
+
import { bindProjectStep, outcomeUnknown, skillLabel, skillOffTasksNote, WIRO_PROJECT_CREDENTIAL } from '../utils/user-agent.js';
|
|
5
5
|
import { DEFAULT_WAIT_SECONDS } from '../utils/poll.js';
|
|
6
6
|
import { isPlainTeamMember, teamAgentBillingRefused } from '../utils/workspace.js';
|
|
7
7
|
import { nextActionSchema, strictInput } from './schemas.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.describe('The monthly credits each renewal grants now.'),
|
|
14
|
-
newMonthlyCredits: z.number().nullable()
|
|
15
|
-
.describe('The monthly credits each renewal grants after the change.'),
|
|
16
|
-
deltaMonthlyCredits: z.number().nullable(),
|
|
17
|
-
creditsNow: z.number().optional()
|
|
18
|
-
.describe('The credits this period gains now, below 0 when it loses them: the change counts for the time left in the period.'),
|
|
19
|
-
creditsThisPeriod: z.number().optional()
|
|
20
|
-
.describe('The monthly credits this period grants in all after the change.'),
|
|
21
|
-
creditsFromRenewal: z.number().optional()
|
|
22
|
-
.describe('The monthly credits every renewal grants after the change.'),
|
|
23
|
-
periodEnd: z.string().optional()
|
|
24
|
-
.describe('When the current period ends.'),
|
|
25
|
-
note: z.string().optional(),
|
|
26
|
-
});
|
|
8
|
+
// Every plan includes every skill, so a skill change moves no money and leaves the plan as it is.
|
|
9
|
+
const FREE_NOTE = 'A skill change costs nothing: the plan keeps its price and monthly credits.';
|
|
10
|
+
// Turning a skill on is free, but the work it does is not.
|
|
11
|
+
const WORK_NOTE = 'The skills\' work uses the agent\'s credits, and model runs they start are billed to the wallet '
|
|
12
|
+
+ 'of the workspace that owns the Wiro project connected to the agent.';
|
|
27
13
|
const outputSchema = {
|
|
28
14
|
agentGuid: z.string(),
|
|
29
|
-
status: z.enum(['
|
|
30
|
-
idempotencyKey: z.string().optional()
|
|
31
|
-
|
|
15
|
+
status: z.enum(['applied', 'no_change', 'refused']),
|
|
16
|
+
idempotencyKey: z.string().optional()
|
|
17
|
+
.describe('The key of this change. If the answer to it does not arrive, repeating the same change with this key never applies it twice.'),
|
|
32
18
|
changes: z.object({
|
|
33
19
|
enable: z.array(z.string()),
|
|
34
20
|
disable: z.array(z.string()),
|
|
35
21
|
addedDependencies: z.array(z.string()),
|
|
36
22
|
alreadySet: z.array(z.string()),
|
|
37
23
|
}),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
next: z.string().nullable(),
|
|
41
|
-
}),
|
|
42
|
-
pricing: pricingSchema.optional(),
|
|
43
|
-
billing: z.object({
|
|
44
|
-
plan: z.enum(['prepaid', 'card', 'none']),
|
|
45
|
-
subscriptionStatus: z.string().nullable(),
|
|
46
|
-
wallet: z.enum(['team', 'personal']),
|
|
47
|
-
estimatedChargeNowUsd: z.number().nullable().optional()
|
|
48
|
-
.describe('What a wallet plan pays now at list price, as Wiro works it out, before any discount on the wallet; 0 on a card plan, whose difference goes to the card subscription.'),
|
|
49
|
-
creditNowUsd: z.number().nullable().optional()
|
|
50
|
-
.describe('For a drop on a wallet plan, what goes back to the balances that paid; null when it is worked out when the change is applied.'),
|
|
51
|
-
usedCreditsUsd: z.number().nullable().optional()
|
|
52
|
-
.describe('The part of a credit that comes off for credits already used above what the plan keeps.'),
|
|
53
|
-
chargedNowUsd: z.number().nullable().optional(),
|
|
54
|
-
note: z.string(),
|
|
55
|
-
}),
|
|
24
|
+
note: z.string()
|
|
25
|
+
.describe('What the change does to the plan and its cost: nothing, since every plan includes every skill.'),
|
|
56
26
|
enabledSkills: z.array(z.string()).optional(),
|
|
57
27
|
credentialsNeeded: z.array(z.object({
|
|
58
28
|
skill: z.string(),
|
|
59
29
|
credentials: z.array(z.string()),
|
|
60
30
|
})),
|
|
61
|
-
scheduledTasks: z.object({
|
|
62
|
-
stop: z.array(z.string())
|
|
63
|
-
.describe('Scheduled tasks this change stops: they run now, or would once an agent that is not running starts. They keep their text, schedule and on/off state, and get_my_agent then shows what each waits for.'),
|
|
64
|
-
resume: z.array(z.string())
|
|
65
|
-
.describe('Scheduled tasks that do not run now and start running once this change is applied, and the agent is running.'),
|
|
66
|
-
}).nullable().optional()
|
|
67
|
-
.describe('Quote: the scheduled tasks this change stops or starts, as Wiro works it out; null when Wiro could not tell.'),
|
|
68
31
|
pausedTasks: z.array(z.string()).optional()
|
|
69
32
|
.describe('After an applied change: the scheduled tasks it paused, which wait for skills that are off. get_my_agent names those skills.'),
|
|
70
33
|
agentStatus: z.string(),
|
|
@@ -74,292 +37,15 @@ const outputSchema = {
|
|
|
74
37
|
message: z.string(),
|
|
75
38
|
deps: z.array(z.object({ skill: z.string(), requires: z.string() })).optional(),
|
|
76
39
|
conflicts: z.array(z.object({ a: z.string(), b: z.string() })).optional(),
|
|
77
|
-
requiredUsd: z.number().nullable().optional(),
|
|
78
|
-
availableUsd: z.number().nullable().optional(),
|
|
79
40
|
}).optional(),
|
|
80
41
|
nextAction: nextActionSchema.optional(),
|
|
81
42
|
};
|
|
82
43
|
const UNCHANGED_RESTART = 'Nothing changed, so the agent does not restart.';
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return Math.round(usd * 100) / 100;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* How long an applied credit lasts, from the parts Wiro says it split into. Each
|
|
90
|
-
* part went back to the balance that paid it and keeps that balance's end date,
|
|
91
|
-
* except the part whose source has ended since (each ...UntilPeriodEndUsd): that
|
|
92
|
-
* part lasts until the plan's current period ends. The two amounts add up to the
|
|
93
|
-
* credit, and parts that come to nothing say nothing.
|
|
94
|
-
*/
|
|
95
|
-
function creditTerms(parts) {
|
|
96
|
-
if (!isPlainObject(parts))
|
|
97
|
-
return '';
|
|
98
|
-
const usd = (key) => toNumber(parts[key]) ?? 0;
|
|
99
|
-
const untilEnd = roundCents(usd('couponUntilPeriodEndUsd') + usd('storeUntilPeriodEndUsd') + usd('depositUntilPeriodEndUsd'));
|
|
100
|
-
const keepsEnd = roundCents(roundCents(usd('couponUsd') + usd('storeUsd') + usd('depositUsd')) - untilEnd);
|
|
101
|
-
if (keepsEnd > 0 && untilEnd > 0) {
|
|
102
|
-
return `${formatUsd(keepsEnd)} of it went back to the balances that paid and keeps their end dates, and ${formatUsd(untilEnd)} lasts until this period ends, because the credit that paid it has ended.`;
|
|
103
|
-
}
|
|
104
|
-
if (keepsEnd > 0)
|
|
105
|
-
return 'It went back to the balances that paid and keeps their end dates.';
|
|
106
|
-
return untilEnd > 0 ? 'It lasts until this period ends, because the credit that paid it has ended.' : '';
|
|
107
|
-
}
|
|
108
|
-
/** A count of credits with its sign, such as +97 or -690. */
|
|
109
|
-
function signedCredits(credits) {
|
|
110
|
-
return `${credits > 0 ? '+' : ''}${formatCredits(credits)}`;
|
|
111
|
-
}
|
|
112
|
-
/** The fields of Wiro's plan change that the pricing output carries. */
|
|
113
|
-
function periodFields(change) {
|
|
114
|
-
if (!change)
|
|
115
|
-
return {};
|
|
116
|
-
const periodEnd = unixToIso(change.periodEnd);
|
|
117
|
-
return {
|
|
118
|
-
...(change.creditsNow !== null ? { creditsNow: change.creditsNow } : {}),
|
|
119
|
-
...(change.creditsThisPeriod !== null ? { creditsThisPeriod: change.creditsThisPeriod } : {}),
|
|
120
|
-
...(change.creditsFromRenewal !== null ? { creditsFromRenewal: change.creditsFromRenewal } : {}),
|
|
121
|
-
...(periodEnd ? { periodEnd } : {}),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* What a change does to this period's credits when none come with it: those it takes away end for the
|
|
126
|
-
* time left, and the period keeps the rest. A plan priced again at today's rates can also keep its
|
|
127
|
-
* credits, or gain some, while its price drops.
|
|
128
|
-
*/
|
|
129
|
-
function creditsEndNote(skillsOff, creditsNow, creditsThisPeriod) {
|
|
130
|
-
if (creditsNow !== null && creditsNow > 0) {
|
|
131
|
-
return `This period gains ${formatCredits(creditsNow)} credits for the time left${creditsThisPeriod !== null ? `, ${formatCredits(creditsThisPeriod)} in all` : ''}.`;
|
|
132
|
-
}
|
|
133
|
-
if (creditsNow === 0) {
|
|
134
|
-
return creditsThisPeriod !== null ? `This period keeps its ${formatCredits(creditsThisPeriod)} credits.` : 'This period keeps its credits.';
|
|
135
|
-
}
|
|
136
|
-
const keeps = creditsThisPeriod !== null ? `, and this period keeps ${formatCredits(creditsThisPeriod)}` : '';
|
|
137
|
-
if (skillsOff === 0)
|
|
138
|
-
return `The credits the change takes away end now for the time left${keeps}.`;
|
|
139
|
-
return `${skillsOff === 1 ? 'Its' : 'Their'} credits for the time left end now${keeps}.`;
|
|
140
|
-
}
|
|
141
|
-
function difference(next, current) {
|
|
142
|
-
return next === null || current === null ? null : Math.round((next - current) * 100) / 100;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* A skill change prices the plan at today's prices for all its skills, so a
|
|
146
|
-
* plan that started at other prices also changes for the skills it already
|
|
147
|
-
* has, and so do its monthly credits. The agent's tiers carry today's prices
|
|
148
|
-
* and credits for those skills. They are the base of the new price, not a price
|
|
149
|
-
* the plan reaches. An agent without an active plan cannot take the change yet,
|
|
150
|
-
* and a move to Pro prices the whole plan at today's Pro prices, which the quote
|
|
151
|
-
* already shows.
|
|
152
|
-
*/
|
|
153
|
-
function todayPriceNote(row, billing, currentPrice, currentCredits, tierChange) {
|
|
154
|
-
if (tierChange)
|
|
155
|
-
return null;
|
|
156
|
-
const tier = asTier(row.tier);
|
|
157
|
-
const tiers = toTierPricing(isPlainObject(row.agent) ? row.agent.tiers : undefined);
|
|
158
|
-
const today = tier && tiers ? tiers[tier] : null;
|
|
159
|
-
if (billing.status !== 'active' || currentPrice === null || today === null || !difference(today.priceUsd, currentPrice))
|
|
160
|
-
return null;
|
|
161
|
-
const versus = currentCredits !== null && today.monthlyCredits !== currentCredits
|
|
162
|
-
? ` with ${formatCredits(today.monthlyCredits)} monthly credits, not its current ${formatUsd(currentPrice)} and ${formatCredits(currentCredits)}`
|
|
163
|
-
: `, not its current ${formatUsd(currentPrice)}`;
|
|
164
|
-
return `Today's ${tier === 'pro' ? 'Pro' : 'Starter'} price for the skills this plan already has is ${formatUsd(today.priceUsd)} a month${versus}. A skill change counts from today's price, and the new price in this quote already includes that.`;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* The wallet of the agent's workspace, which Wiro charges or credits for a
|
|
168
|
-
* skill change: the team's for a team agent, else its owner's personal wallet.
|
|
169
|
-
* Only the owner can change a personal agent's skills, so that wallet is the
|
|
170
|
-
* caller's own.
|
|
171
|
-
*/
|
|
172
|
-
function walletName(billing) {
|
|
173
|
-
return billing.wallet === 'team' ? 'the team wallet' : 'your personal wallet';
|
|
174
|
-
}
|
|
175
|
-
/** When the new monthly credits come: a plan set to end renews only if it is kept, and an agent without a plan gets them once it is subscribed. */
|
|
176
|
-
function creditsWhen(billing) {
|
|
177
|
-
if (billing.plan === 'none')
|
|
178
|
-
return 'a month once it is subscribed';
|
|
179
|
-
return billing.status === 'active' && billing.cancelAtPeriodEnd === true
|
|
180
|
-
? 'at each renewal after the change, if the plan is kept'
|
|
181
|
-
: 'at each renewal after the change';
|
|
182
|
-
}
|
|
183
|
-
/** When an active plan's next renewal gives the new monthly credits. A card plan whose renewal is not known names it as a condition. */
|
|
184
|
-
function renewalWhen(billing) {
|
|
185
|
-
if (billing.cancelAtPeriodEnd === true)
|
|
186
|
-
return 'from the next renewal, if the plan is kept';
|
|
187
|
-
return billing.cancelAtPeriodEnd === null ? 'from the next renewal, if the plan renews' : 'from the next renewal';
|
|
188
|
-
}
|
|
189
|
-
/** What renewals give after an applied change: a plan that may not renew names it as a condition, as its quote did. */
|
|
190
|
-
function renewalGives(billing, credits) {
|
|
191
|
-
return billing.cancelAtPeriodEnd === false ? `every renewal gives ${formatCredits(credits)}` : `${formatCredits(credits)} ${renewalWhen(billing)}`;
|
|
192
|
-
}
|
|
193
|
-
/** For a cancelled plan, a skill change only covers the time left: nothing renews at the new price. */
|
|
194
|
-
function cancelledNote(billing) {
|
|
195
|
-
const end = billing.periodEnd !== null ? unixToIso(billing.periodEnd) : undefined;
|
|
196
|
-
if (billing.plan === 'card') {
|
|
197
|
-
return `The plan is set to end${end ? ` after ${end}` : ' with this period'} and does not renew.`;
|
|
198
|
-
}
|
|
199
|
-
return `The plan is cancelled and ends about a day after ${end ?? 'the end of this period'}, so this covers only the time left and the new price is not renewed. Undo the cancellation with manage_agent_billing (renew) to keep the plan.`;
|
|
200
|
-
}
|
|
201
|
-
/** A card subscription that ends with this period: the plan is set to end, or it moves to wallet billing. */
|
|
202
|
-
function cardEndsWithPeriod(billing) {
|
|
203
|
-
return billing.plan === 'card' && (billing.cancelAtPeriodEnd === true || billing.switchingToWallet);
|
|
204
|
-
}
|
|
205
|
-
function walletSwitchNote(billing, price) {
|
|
206
|
-
return `When this period ends, the plan moves to wallet billing and renews from ${walletName(billing)}${price !== null ? ` at ${formatUsd(price)} a month` : ''}.`;
|
|
207
|
-
}
|
|
208
|
-
// A card subscription that ends with this period is not renewed by card, so its notes point to no next invoice.
|
|
209
|
-
const CARD_ENDS_QUOTE = 'Nothing is charged now. The card subscription is updated to the new price for the rest of this period.';
|
|
210
|
-
// A card plan whose renewal is not known may also end with this period, so its next invoice is named only for a plan that renews by card.
|
|
211
|
-
const CARD_UNKNOWN_QUOTE = 'Nothing is charged now. The card subscription is updated to the new price, and a plan that renews by card shows the prorated difference on its next invoice.';
|
|
212
|
-
/** Only a wallet plan that has ended comes back with renew; any other plan that is not active takes a new one (manage_agent_billing). */
|
|
213
|
-
function renewsBack(billing) {
|
|
214
|
-
return billing.plan === 'prepaid' && billing.status === 'expired';
|
|
215
|
-
}
|
|
216
|
-
/** What a price drop on a wallet plan gives back now, from Wiro's own plan change. */
|
|
217
|
-
function walletCreditNote(change) {
|
|
218
|
-
const used = change.usedCreditsUsd ?? 0;
|
|
219
|
-
// A credit is at most 1 cent for each credit the change takes away unused, so one that takes none away gives nothing back.
|
|
220
|
-
if (change.creditNowUsd === 0 && used > 0 && change.creditsNow !== null && change.creditsNow >= 0) {
|
|
221
|
-
return 'Nothing comes back: the change takes no credits away.';
|
|
222
|
-
}
|
|
223
|
-
if (change.creditNowUsd === null) {
|
|
224
|
-
return 'What comes back is worked out when the change is applied: what the time left is worth, less 1 cent for each credit already used above what the plan keeps.';
|
|
225
|
-
}
|
|
226
|
-
if (change.creditNowUsd > 0) {
|
|
227
|
-
return `${formatUsd(change.creditNowUsd)} goes back to the balances that paid, and each keeps its own end date.`
|
|
228
|
-
+ (used > 0 ? ` ${formatUsd(used)} comes off for credits already used above what the plan keeps.` : '');
|
|
229
|
-
}
|
|
230
|
-
return used > 0
|
|
231
|
-
? 'Nothing comes back: the credits already used are worth more than the time left.'
|
|
232
|
-
: 'Nothing comes back to the wallet now.';
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* The quote's billing line. An active plan's money and credits come from the
|
|
236
|
-
* plan change Wiro works out on the plan as it is now (change); without it,
|
|
237
|
-
* the line says what happens without a number.
|
|
238
|
-
*/
|
|
239
|
-
function quoteBillingNote(billing, delta, change, nextPrice, skillsOff) {
|
|
240
|
-
// A card plan whose renewal is not known gets the new price without a renewal claim.
|
|
241
|
-
const after = billing.cancelAtPeriodEnd === true
|
|
242
|
-
? ` ${cancelledNote(billing)}`
|
|
243
|
-
: billing.switchingToWallet
|
|
244
|
-
? ` ${walletSwitchNote(billing, nextPrice)}`
|
|
245
|
-
: nextPrice === null
|
|
246
|
-
? ''
|
|
247
|
-
: billing.cancelAtPeriodEnd === false
|
|
248
|
-
? ` The plan then renews at ${formatUsd(nextPrice)} a month.`
|
|
249
|
-
: ` The new monthly price is ${formatUsd(nextPrice)}.`;
|
|
250
|
-
if (billing.plan === 'none') {
|
|
251
|
-
return 'The agent has no subscription yet, so nothing is charged now. The new monthly price applies once it is subscribed.';
|
|
252
|
-
}
|
|
253
|
-
if (billing.status !== 'active') {
|
|
254
|
-
return renewsBack(billing)
|
|
255
|
-
? `The subscription is ${billing.status ?? 'not active'}. Skills can only change on an active subscription, so renew it with manage_agent_billing first.`
|
|
256
|
-
: `The subscription is ${billing.status ?? 'not active'}. Skills can only change on an active subscription, so start a new plan with manage_agent_billing (subscribe) first.`;
|
|
257
|
-
}
|
|
258
|
-
if (delta !== null && Math.abs(delta) < 0.005)
|
|
259
|
-
return 'The monthly price does not change, so nothing is charged.';
|
|
260
|
-
if (delta === null || change === null) {
|
|
261
|
-
return billing.plan === 'prepaid'
|
|
262
|
-
? `The difference for the rest of this period is taken from, or credited to, ${walletName(billing)} when the change is applied. A credit goes back to the balances that paid, and each keeps its own end date.${after}`
|
|
263
|
-
: cardEndsWithPeriod(billing)
|
|
264
|
-
? `${CARD_ENDS_QUOTE}${after}`
|
|
265
|
-
: billing.cancelAtPeriodEnd === null
|
|
266
|
-
? `${CARD_UNKNOWN_QUOTE}${after}`
|
|
267
|
-
: `Any prorated difference appears on the next invoice.${after}`;
|
|
268
|
-
}
|
|
269
|
-
const ends = creditsEndNote(skillsOff, change.creditsNow, change.creditsThisPeriod);
|
|
270
|
-
// Credits come with a rise when this period gains them. A plan priced again at today's rates can also
|
|
271
|
-
// lose credits, or keep them, while its price rises.
|
|
272
|
-
const gained = change.creditsNow !== null && change.creditsNow > 0 ? change.creditsNow : null;
|
|
273
|
-
const notGained = change.creditsNow !== null && change.creditsNow <= 0 ? ` ${ends}` : '';
|
|
274
|
-
if (!change.wallet) {
|
|
275
|
-
if (delta > 0) {
|
|
276
|
-
const added = gained !== null ? ` ${formatCredits(gained)} credits come now for the rest of this period.` : notGained;
|
|
277
|
-
if (cardEndsWithPeriod(billing))
|
|
278
|
-
return `${CARD_ENDS_QUOTE}${added}${after}`;
|
|
279
|
-
if (billing.cancelAtPeriodEnd === null)
|
|
280
|
-
return `${CARD_UNKNOWN_QUOTE}${added}${after}`;
|
|
281
|
-
return gained !== null
|
|
282
|
-
? `Nothing is charged now. The prorated difference appears on the next invoice, and ${formatCredits(gained)} credits come now for the rest of this period.${after}`
|
|
283
|
-
: `Nothing is charged now. The prorated difference appears on the next invoice.${notGained}${after}`;
|
|
284
|
-
}
|
|
285
|
-
if (cardEndsWithPeriod(billing))
|
|
286
|
-
return `${CARD_ENDS_QUOTE} ${ends}${after}`;
|
|
287
|
-
if (billing.cancelAtPeriodEnd === null)
|
|
288
|
-
return `${CARD_UNKNOWN_QUOTE} ${ends}${after}`;
|
|
289
|
-
return `The prorated difference comes off the next invoice. ${ends}${after}`;
|
|
290
|
-
}
|
|
291
|
-
if (delta > 0) {
|
|
292
|
-
const charge = formatUsd(change.chargeNowUsd ?? 0);
|
|
293
|
-
const credits = gained !== null ? `, and ${formatCredits(gained)} credits come with it` : '';
|
|
294
|
-
const days = daysLeftText(change.secondsLeft);
|
|
295
|
-
return underOneDayLeft(change.secondsLeft)
|
|
296
|
-
? `${charge} is taken from ${walletName(billing)} now at the one-day minimum${credits}.${notGained}${after}`
|
|
297
|
-
: `${charge} is taken from ${walletName(billing)} now for the rest of this period${days ? ` (${days})` : ''}${credits}.${notGained}${after}`;
|
|
298
|
-
}
|
|
299
|
-
return `${walletCreditNote(change)} ${ends}${after}`;
|
|
300
|
-
}
|
|
301
|
-
function chargeNote(billing, body) {
|
|
302
|
-
const charged = toNumber(body.prepaidWalletDelta);
|
|
303
|
-
const used = toNumber(body.usedCreditsUsd) ?? 0;
|
|
304
|
-
const creditsNow = isPlainObject(body.pricing) ? toNumber(body.pricing.creditsNow) : null;
|
|
305
|
-
const cancelled = billing.cancelAtPeriodEnd === true && billing.status === 'active' ? ` ${cancelledNote(billing)}` : '';
|
|
306
|
-
if (charged !== null && charged > 0) {
|
|
307
|
-
const credits = creditsNow !== null && creditsNow > 0 ? `, and ${formatCredits(creditsNow)} credits came with it` : '';
|
|
308
|
-
return { charged, note: `${formatUsd(charged)} was taken from ${walletName(billing)} for the rest of this period${credits}.${cancelled}` };
|
|
309
|
-
}
|
|
310
|
-
if (charged !== null && charged < 0) {
|
|
311
|
-
const terms = creditTerms(body.prepaidCreditParts);
|
|
312
|
-
const usedNote = used > 0 ? ` ${formatUsd(used)} came off for credits already used above what the plan keeps.` : '';
|
|
313
|
-
return { charged, note: `${formatUsd(Math.abs(charged))} was credited to ${walletName(billing)}.${terms ? ` ${terms}` : ''}${usedNote}${cancelled}` };
|
|
314
|
-
}
|
|
315
|
-
// A change that took no credits away had nothing to credit, and nothing failed.
|
|
316
|
-
if (billing.plan === 'prepaid' && used > 0 && creditsNow !== null && creditsNow >= 0) {
|
|
317
|
-
return { charged: null, note: `Nothing came back: the change took no credits away.${cancelled}` };
|
|
318
|
-
}
|
|
319
|
-
// The credits already used came to more than the time left was worth: no credit, and nothing failed.
|
|
320
|
-
// A part Wiro could not add (prepaidCreditFailedUsd) was due all the same: its warning follows, and the
|
|
321
|
-
// credits used took only what Wiro names.
|
|
322
|
-
if (billing.plan === 'prepaid' && used > 0) {
|
|
323
|
-
return (toNumber(body.prepaidCreditFailedUsd) ?? 0) > 0
|
|
324
|
-
? { charged: null, note: `Nothing came back now. ${formatUsd(used)} came off for credits already used above what the plan keeps.${cancelled}` }
|
|
325
|
-
: { charged: null, note: `Nothing came back: the credits already used were worth more than the time left.${cancelled}` };
|
|
326
|
-
}
|
|
327
|
-
if (body.stripeProrationApplied === true) {
|
|
328
|
-
const moved = isPlainObject(body.pricing) ? toNumber(body.pricing.deltaUsd) : null;
|
|
329
|
-
if (moved !== null && Math.abs(moved) < 0.005) {
|
|
330
|
-
return { charged: null, note: `The monthly price did not change, so nothing was charged.${cancelled}` };
|
|
331
|
-
}
|
|
332
|
-
const added = moved !== null && moved > 0 && creditsNow !== null && creditsNow > 0
|
|
333
|
-
? ` ${formatCredits(creditsNow)} credits came now for the rest of this period.`
|
|
334
|
-
: '';
|
|
335
|
-
if (cardEndsWithPeriod(billing)) {
|
|
336
|
-
const price = isPlainObject(body.pricing) ? toNumber(body.pricing.newPriceUsd) : null;
|
|
337
|
-
const switching = billing.switchingToWallet ? ` ${walletSwitchNote(billing, price)}` : '';
|
|
338
|
-
return { charged: null, note: `Nothing was charged now. The card subscription was updated to the new price for the rest of this period.${added}${cancelled}${switching}` };
|
|
339
|
-
}
|
|
340
|
-
if (billing.cancelAtPeriodEnd === null) {
|
|
341
|
-
return { charged: null, note: `Nothing was charged now. The card subscription was updated to the new price, and a plan that renews by card shows the prorated difference on its next invoice.${added}` };
|
|
342
|
-
}
|
|
343
|
-
return { charged: null, note: `The card subscription was updated; any prorated difference appears on the next invoice.${added}${cancelled}` };
|
|
344
|
-
}
|
|
345
|
-
if (billing.plan === 'none') {
|
|
346
|
-
return { charged: null, note: 'Nothing was charged: the agent has no subscription yet.' };
|
|
347
|
-
}
|
|
348
|
-
return { charged: null, note: `Nothing was charged now.${cancelled}` };
|
|
349
|
-
}
|
|
350
|
-
/** What the change charged, then any notes Wiro adds about its billing, as Wiro wrote them. */
|
|
351
|
-
function appliedBillingNote(billing, body) {
|
|
352
|
-
const result = chargeNote(billing, body);
|
|
353
|
-
const warnings = (Array.isArray(body.warnings) ? body.warnings : [])
|
|
44
|
+
/** Wiro's own notes on an applied change, as it wrote them. */
|
|
45
|
+
function warningsOf(body) {
|
|
46
|
+
return (Array.isArray(body.warnings) ? body.warnings : [])
|
|
354
47
|
.map(warning => asString(warning)?.trim())
|
|
355
48
|
.filter((warning) => Boolean(warning));
|
|
356
|
-
return warnings.length > 0 ? { ...result, note: [result.note, ...warnings].join(' ') } : result;
|
|
357
|
-
}
|
|
358
|
-
/** The sentence for a change whose skills need a Wiro project. */
|
|
359
|
-
function bindProjectNote(needed) {
|
|
360
|
-
return needed.some(entry => entry.credentials.includes(WIRO_PROJECT_CREDENTIAL))
|
|
361
|
-
? ' bind_agent_project connects a Wiro project, with no key to paste.'
|
|
362
|
-
: '';
|
|
363
49
|
}
|
|
364
50
|
/** How to give the new skills what they still need. A Wiro project comes first, since it takes no key. */
|
|
365
51
|
function stillNeededSteps(needed) {
|
|
@@ -378,64 +64,19 @@ function listLine(label, names, titles) {
|
|
|
378
64
|
function neededText(needed, row, titles, serviceTitles) {
|
|
379
65
|
return needed.map(entry => `${skillLabel(entry.skill, titles)}: ${entry.credentials.map(key => credentialLabel(row, key, serviceTitles)).join(', ')}`).join('; ');
|
|
380
66
|
}
|
|
381
|
-
/**
|
|
382
|
-
|
|
383
|
-
* could not tell (it sends null or nothing), undefined when there are none.
|
|
384
|
-
*/
|
|
385
|
-
function scheduledTasksOf(value) {
|
|
386
|
-
if (!isPlainObject(value))
|
|
387
|
-
return null;
|
|
388
|
-
const stop = toStringArray(value.stop);
|
|
389
|
-
const resume = toStringArray(value.resume);
|
|
390
|
-
return stop.length > 0 || resume.length > 0 ? { stop, resume } : undefined;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* The quote's lines for the scheduled tasks the change stops or starts, or that Wiro could not tell. Wiro
|
|
394
|
-
* counts a task as running by its gates, so on an agent that is not running it is a task that would run once
|
|
395
|
-
* the agent starts. Each task is named as people see it.
|
|
396
|
-
*/
|
|
397
|
-
function movedTaskLines(moved, row, running) {
|
|
398
|
-
if (moved === null) {
|
|
399
|
-
return ['**Scheduled tasks:** Wiro could not tell which scheduled tasks this change stops or starts. Once it is applied, the result names the tasks it paused.'];
|
|
400
|
-
}
|
|
401
|
-
if (!moved)
|
|
402
|
-
return [];
|
|
403
|
-
const entries = new Map(customSkillEntries(row).map(entry => [entry.key, entry]));
|
|
404
|
-
const names = (list) => list.map(key => {
|
|
405
|
-
const entry = entries.get(key);
|
|
406
|
-
return taskLabel(key, entry ? taskNamedByWiro(entry) : true);
|
|
407
|
-
}).join(', ');
|
|
408
|
-
const lines = [];
|
|
409
|
-
if (moved.stop.length > 0) {
|
|
410
|
-
const one = moved.stop.length === 1;
|
|
411
|
-
const now = running
|
|
412
|
-
? (one ? 'It runs now and stops with this change.' : 'They run now and stop with this change.')
|
|
413
|
-
: (one ? 'It would run once the agent starts, and this change stops it.' : 'They would run once the agent starts, and this change stops them.');
|
|
414
|
-
lines.push(`**Scheduled tasks that stop:** ${names(moved.stop)}. ${now} ${one ? 'It keeps its' : 'They keep their'} text, schedule and on/off state, and get_my_agent then shows what ${one ? 'it waits' : 'each waits'} for.`);
|
|
415
|
-
}
|
|
416
|
-
if (moved.resume.length > 0) {
|
|
417
|
-
const one = moved.resume.length === 1;
|
|
418
|
-
const after = running ? 'once this change is applied' : 'once this change is applied and the agent starts';
|
|
419
|
-
lines.push(`**Scheduled tasks that start running:** ${names(moved.resume)}. ${one ? 'It does not run now and runs' : 'They do not run now and run'} ${after}.`);
|
|
420
|
-
}
|
|
421
|
-
return lines;
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* The scheduled tasks the change paused: on and paused in the agent read after it, not paused before it, and
|
|
425
|
-
* among those Wiro said the change stops (stops), when it could tell.
|
|
426
|
-
*/
|
|
427
|
-
function newlyPaused(before, after, stops) {
|
|
67
|
+
/** The scheduled tasks the change paused: on and paused in the agent read after it, and not paused before it. */
|
|
68
|
+
function newlyPaused(before, after) {
|
|
428
69
|
if (!after)
|
|
429
70
|
return [];
|
|
430
71
|
const pausedBefore = new Set(customSkillEntries(before).filter(entry => entry.skillOff).map(entry => entry.key));
|
|
431
72
|
return customSkillEntries(after).filter(entry => entry.kind === 'scheduled_task' && entry.enabled && entry.skillOff
|
|
432
|
-
&& !pausedBefore.has(entry.key)
|
|
73
|
+
&& !pausedBefore.has(entry.key));
|
|
433
74
|
}
|
|
434
75
|
/**
|
|
435
|
-
* The agent read again after the change, and whether its live skills
|
|
436
|
-
*
|
|
76
|
+
* The agent read again after the change, and whether its live skills are what this change asked for; both
|
|
77
|
+
* null when it cannot be read.
|
|
437
78
|
*/
|
|
438
|
-
async function readAfterChange(client, agentGuid, requested,
|
|
79
|
+
async function readAfterChange(client, agentGuid, requested, signal) {
|
|
439
80
|
let live;
|
|
440
81
|
try {
|
|
441
82
|
live = await readUserAgent(client, agentGuid, signal);
|
|
@@ -444,8 +85,7 @@ async function readAfterChange(client, agentGuid, requested, tier, signal) {
|
|
|
444
85
|
return { holds: null, live: null };
|
|
445
86
|
}
|
|
446
87
|
const enabled = new Set(enabledSkillNames(live));
|
|
447
|
-
|
|
448
|
-
return { holds: skillsHold && (!tier || asString(live.tier) === tier), live };
|
|
88
|
+
return { holds: Object.entries(requested).every(([name, on]) => enabled.has(name) === on), live };
|
|
449
89
|
}
|
|
450
90
|
/** The line that names the tasks a change paused, with the skills each waits for. */
|
|
451
91
|
async function pausedLine(client, paused, signal) {
|
|
@@ -454,43 +94,30 @@ async function pausedLine(client, paused, signal) {
|
|
|
454
94
|
export function registerApplyAgentSkills(server, client) {
|
|
455
95
|
server.registerTool('apply_agent_skills', {
|
|
456
96
|
title: 'Change an agent\'s skills',
|
|
457
|
-
description: 'Turn registry skills on or off for a deployed agent
|
|
458
|
-
+ '
|
|
459
|
-
+ '
|
|
460
|
-
+ '
|
|
461
|
-
+ '
|
|
462
|
-
+ '
|
|
463
|
-
+ '
|
|
464
|
-
+ '
|
|
465
|
-
+ '
|
|
466
|
-
+ '
|
|
467
|
-
+ '
|
|
468
|
-
+ '
|
|
469
|
-
+ '
|
|
470
|
-
+ '
|
|
471
|
-
+ '
|
|
472
|
-
+ 'credits for the time left; the ones the time already passed paid for stay until the renewal. '
|
|
473
|
-
+ 'On a card plan nothing is charged at once: the card subscription is updated to the new price, '
|
|
474
|
-
+ 'a plan that renews by card shows the difference on its next invoice, and the added credits come '
|
|
475
|
-
+ 'for the time left. A running agent restarts once when a skill turns on or off; a change of the '
|
|
476
|
-
+ 'tier alone leaves it running. Newly enabled skills may still need credentials '
|
|
477
|
-
+ '(set_agent_credentials, connect_agent_oauth, bind_agent_project for a Wiro project) and do not create scheduled tasks '
|
|
478
|
-
+ '(manage_agent_custom_skill does). Find skill names with list_agent_skills and the '
|
|
479
|
-
+ 'agent\'s current skills with get_my_agent. The agents playbook (get_playbook) has the '
|
|
480
|
-
+ 'full setup walkthrough.',
|
|
97
|
+
description: 'Turn registry skills on or off for a deployed agent. Every plan includes every skill, so a '
|
|
98
|
+
+ 'skill change costs nothing: the plan keeps its price and monthly credits, and no active plan is '
|
|
99
|
+
+ 'needed. The change is applied on the first call, so tell the user what turns on or off and get '
|
|
100
|
+
+ 'their yes first. The tool checks the names and turns on the skills they depend on '
|
|
101
|
+
+ '(add_dependencies); the result lists them, the credentials the new skills still need and the '
|
|
102
|
+
+ 'scheduled tasks the change paused. A running agent restarts once when a skill turns on or off. '
|
|
103
|
+
+ 'A skill\'s work uses the agent\'s credits, and model runs it starts are billed to the wallet of the '
|
|
104
|
+
+ 'workspace that owns the Wiro project connected to the agent. Newly enabled skills may still need '
|
|
105
|
+
+ 'credentials (set_agent_credentials, connect_agent_oauth, bind_agent_project for a Wiro project) and do '
|
|
106
|
+
+ 'not create scheduled tasks (manage_agent_custom_skill does). On a team agent only a team admin or the '
|
|
107
|
+
+ 'person who deployed the agent can change its skills; other members are refused and nothing changes. '
|
|
108
|
+
+ 'Every result gives an idempotency_key: if an answer does not arrive, repeat the same change with it, '
|
|
109
|
+
+ 'which never applies the change twice. To change the plan, use manage_agent_billing (change_plan). '
|
|
110
|
+
+ 'Find skill names with list_agent_skills and the agent\'s current skills with get_my_agent. The agents '
|
|
111
|
+
+ 'playbook (get_playbook) has the full setup walkthrough.',
|
|
481
112
|
inputSchema: strictInput({
|
|
482
113
|
agent_guid: z.string().min(1).describe('The deployed agent\'s guid, from list_my_agents.'),
|
|
483
114
|
skills: z.record(z.string(), z.boolean())
|
|
484
115
|
.describe('Skills to change, as name: true to turn on or name: false to turn off, for example {"int-instagram-post": true}. Registry names only (list_agent_skills). Custom skills and scheduled tasks (cs-...) are managed with manage_agent_custom_skill; channels such as Telegram turn on through set_agent_credentials.'),
|
|
485
|
-
tier: z.enum(['starter', 'pro']).optional()
|
|
486
|
-
.describe('Optional: also move from Starter to Pro in this billed change. To upgrade without a skill change, use manage_agent_billing (upgrade_to_pro).'),
|
|
487
116
|
add_dependencies: z.boolean().default(true)
|
|
488
117
|
.describe('Also turn on the skills that the enabled skills depend on (default true). Without them the change is refused.'),
|
|
489
|
-
confirm: z.boolean().default(false)
|
|
490
|
-
.describe('false (default) only returns the quote. true applies the change and charges it; it needs the idempotency_key from the quote.'),
|
|
491
118
|
idempotency_key: z.string().min(8).max(128).optional()
|
|
492
|
-
.describe('
|
|
493
|
-
}),
|
|
119
|
+
.describe('Only to repeat a change whose answer did not arrive: the idempotency_key that change returned or its error names. Repeating it never applies the change twice. Leave it out for a new change.'),
|
|
120
|
+
}, 'A skill change applies on the first call and takes no confirm; manage_agent_billing with action change_plan changes the plan.'),
|
|
494
121
|
outputSchema,
|
|
495
122
|
annotations: {
|
|
496
123
|
readOnlyHint: false,
|
|
@@ -498,10 +125,10 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
498
125
|
idempotentHint: true,
|
|
499
126
|
openWorldHint: true,
|
|
500
127
|
},
|
|
501
|
-
}, async ({ agent_guid, skills,
|
|
128
|
+
}, async ({ agent_guid, skills, add_dependencies, idempotency_key }, extra) => {
|
|
502
129
|
try {
|
|
503
|
-
if (Object.keys(skills).length === 0
|
|
504
|
-
return errorResult(new Error('Nothing to change: pass at least one skill
|
|
130
|
+
if (Object.keys(skills).length === 0) {
|
|
131
|
+
return errorResult(new Error('Nothing to change: pass at least one skill.'));
|
|
505
132
|
}
|
|
506
133
|
const registry = await loadSkillRegistry(client, extra.signal);
|
|
507
134
|
const titles = registryTitles(registry);
|
|
@@ -511,15 +138,10 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
511
138
|
}
|
|
512
139
|
const row = await readUserAgent(client, agent_guid, extra.signal);
|
|
513
140
|
const status = agentStatusOf(row);
|
|
514
|
-
const
|
|
515
|
-
if (tier === 'starter' && currentTier === 'pro') {
|
|
516
|
-
return errorResult(new Error('A Pro plan cannot be moved back to Starter here. Cancel the plan with manage_agent_billing and subscribe again at Starter once it ends.'));
|
|
517
|
-
}
|
|
518
|
-
const tierChange = tier && tier !== currentTier ? tier : undefined;
|
|
519
|
-
const digest = skillChangeDigest(agent_guid, plan.requested, tier);
|
|
141
|
+
const digest = skillChangeDigest(agent_guid, plan.requested);
|
|
520
142
|
const givenKey = idempotency_key ? parseSkillChangeKey(idempotency_key) : null;
|
|
521
143
|
if (givenKey && givenKey.digest !== digest) {
|
|
522
|
-
return errorResult(new Error('This idempotency_key belongs to a different skill change. Omit idempotency_key to
|
|
144
|
+
return errorResult(new Error('This idempotency_key belongs to a different skill change. Omit idempotency_key to make a new change, or repeat the exact change it was issued for.'));
|
|
523
145
|
}
|
|
524
146
|
const enabledNow = enabledSkillNames(row);
|
|
525
147
|
const diff = diffSkills(plan.requested, enabledNow);
|
|
@@ -536,7 +158,6 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
536
158
|
];
|
|
537
159
|
return errorResult(new Error(`The change was not sent:\n\n- ${[...new Set(problems)].join('\n- ')}`));
|
|
538
160
|
}
|
|
539
|
-
const billing = planBilling(row);
|
|
540
161
|
const running = isAgentRunning(status);
|
|
541
162
|
const changes = {
|
|
542
163
|
enable: diff.enable,
|
|
@@ -548,190 +169,66 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
548
169
|
const serviceTitles = await credentialTitles(client, credentialsNeeded.flatMap(entry => entry.credentials), extra.signal);
|
|
549
170
|
// A running agent restarts only for a skill that turns on or off.
|
|
550
171
|
const skillsMove = Object.keys(diff.changes).length > 0;
|
|
551
|
-
const nothingToDo = !skillsMove && !tierChange;
|
|
552
172
|
const base = {
|
|
553
173
|
agentGuid: agent_guid,
|
|
554
174
|
changes,
|
|
555
|
-
tier: { current: currentTier, next: tierChange ?? currentTier },
|
|
556
175
|
credentialsNeeded,
|
|
557
176
|
agentStatus: agentStatusLabel(status),
|
|
558
177
|
};
|
|
559
|
-
|
|
560
|
-
//
|
|
561
|
-
|
|
562
|
-
// of the earlier call with that key.
|
|
563
|
-
if (nothingToDo && !(confirm && givenKey)) {
|
|
178
|
+
// An empty change does nothing. With a key issued for this same change it is still sent, so a repeat
|
|
179
|
+
// gets the result of the earlier call with that key.
|
|
180
|
+
if (!skillsMove && !idempotency_key) {
|
|
564
181
|
return {
|
|
565
|
-
content: [{ type: 'text', text: `## No change needed\n\nThe skills
|
|
182
|
+
content: [{ type: 'text', text: `## No change needed\n\nThe skills are already as requested on agent \`${agent_guid}\`. Nothing changed.` }],
|
|
566
183
|
structuredContent: {
|
|
567
184
|
...base,
|
|
568
185
|
status: 'no_change',
|
|
569
|
-
|
|
186
|
+
note: FREE_NOTE,
|
|
570
187
|
restart: UNCHANGED_RESTART,
|
|
571
188
|
},
|
|
572
189
|
};
|
|
573
190
|
}
|
|
574
|
-
|
|
575
|
-
//
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
// Every team member can read a team agent and price a change, but only a
|
|
579
|
-
// team admin or the person who deployed it can apply one. The credit
|
|
580
|
-
// history check refuses the other members up front; the organization's
|
|
581
|
-
// owner passes it and gets Wiro's answer on confirm.
|
|
582
|
-
if (!nothingToDo && await isPlainTeamMember(client, row, extra.signal)
|
|
191
|
+
// Every team member can read a team agent, but only a team admin or the person who deployed it can
|
|
192
|
+
// change its skills. The credit history check refuses the other members up front; the organization's
|
|
193
|
+
// owner passes it and gets Wiro's own answer.
|
|
194
|
+
if (skillsMove && await isPlainTeamMember(client, row, extra.signal)
|
|
583
195
|
&& await teamAgentBillingRefused(client, agent_guid, extra.signal)) {
|
|
584
196
|
const message = 'Only a team admin or the person who deployed this agent can change its skills, and this '
|
|
585
|
-
+ 'connection acts as a team member without those rights. Nothing was
|
|
586
|
-
+ '
|
|
197
|
+
+ 'connection acts as a team member without those rights. Nothing was changed. Ask a team admin or the '
|
|
198
|
+
+ 'person who deployed the agent to make the change.';
|
|
587
199
|
return {
|
|
588
200
|
content: [{ type: 'text', text: `## Skill change not possible\n\n${message}` }],
|
|
589
201
|
structuredContent: {
|
|
590
202
|
...base,
|
|
591
203
|
status: 'refused',
|
|
592
|
-
|
|
204
|
+
note: FREE_NOTE,
|
|
593
205
|
restart: UNCHANGED_RESTART,
|
|
594
206
|
error: { code: 97, message },
|
|
595
207
|
},
|
|
596
208
|
isError: true,
|
|
597
209
|
};
|
|
598
210
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if (!nothingToDo) {
|
|
602
|
-
const preview = requireApiSuccess(await client.post('/UserAgent/PricingPreview', {
|
|
603
|
-
useragentguid: agent_guid,
|
|
604
|
-
skillOverrides: diff.changes,
|
|
605
|
-
...(tierChange ? { tier: tierChange } : {}),
|
|
606
|
-
withScheduledTasks: true,
|
|
607
|
-
}, extra.signal), 'Could not price this change.');
|
|
608
|
-
const moved = scheduledTasksOf(preview.scheduledTasks);
|
|
609
|
-
stops = moved === null ? null : moved?.stop ?? [];
|
|
610
|
-
const newPrice = toNumber(preview.totalPriceUsd);
|
|
611
|
-
if (newPrice === null) {
|
|
612
|
-
throw new Error('Wiro did not return the new monthly price of this change, so it cannot be quoted. Try again later.');
|
|
613
|
-
}
|
|
614
|
-
const priceTag = skillPriceTag(currentPrice, newPrice, billing.plan === 'prepaid' ? billing.periodEnd : null);
|
|
615
|
-
const approved = confirm && givenKey !== null && givenKey.priceTag === priceTag;
|
|
616
|
-
if (!approved) {
|
|
617
|
-
const newCredits = toNumber(preview.totalMonthlyCredits);
|
|
618
|
-
const delta = difference(newPrice, currentPrice);
|
|
619
|
-
// What Wiro works out for this change on the plan as it is now. Only an active plan has one.
|
|
620
|
-
const change = billing.plan !== 'none' && billing.status === 'active' ? readPlanChange(preview.planChange) : null;
|
|
621
|
-
const note = quoteBillingNote(billing, delta, change, newPrice, changes.disable.length);
|
|
622
|
-
const walletDrop = change !== null && change.wallet && delta !== null && delta < 0;
|
|
623
|
-
const quoteKey = givenKey?.priceTag === priceTag ? key : newSkillChangeKey(digest, priceTag);
|
|
624
|
-
const priceChanged = confirm && givenKey !== null;
|
|
625
|
-
const blocked = billing.plan !== 'none' && billing.status !== 'active';
|
|
626
|
-
const restart = skillsMove ? restartNote(status, 'skill change') : TIER_ONLY_RESTART;
|
|
627
|
-
const priceNote = todayPriceNote(row, billing, currentPrice, currentCredits, tierChange);
|
|
628
|
-
const pricing = {
|
|
629
|
-
currentMonthlyUsd: currentPrice,
|
|
630
|
-
newMonthlyUsd: newPrice,
|
|
631
|
-
deltaMonthlyUsd: delta,
|
|
632
|
-
currentMonthlyCredits: currentCredits,
|
|
633
|
-
newMonthlyCredits: newCredits,
|
|
634
|
-
deltaMonthlyCredits: difference(newCredits, currentCredits),
|
|
635
|
-
...periodFields(change),
|
|
636
|
-
...(priceNote ? { note: priceNote } : {}),
|
|
637
|
-
};
|
|
638
|
-
const nextAction = blocked
|
|
639
|
-
? {
|
|
640
|
-
tool: 'manage_agent_billing',
|
|
641
|
-
arguments: { agent_guid, action: renewsBack(billing) ? 'renew' : 'subscribe' },
|
|
642
|
-
reason: 'The subscription must be active before skills can change.',
|
|
643
|
-
}
|
|
644
|
-
: {
|
|
645
|
-
tool: 'apply_agent_skills',
|
|
646
|
-
arguments: {
|
|
647
|
-
agent_guid,
|
|
648
|
-
skills,
|
|
649
|
-
...(tier ? { tier } : {}),
|
|
650
|
-
add_dependencies,
|
|
651
|
-
confirm: true,
|
|
652
|
-
idempotency_key: quoteKey,
|
|
653
|
-
},
|
|
654
|
-
reason: delta === null || delta > 0
|
|
655
|
-
? 'Ask the user to approve this charge first.'
|
|
656
|
-
: 'Ask the user to confirm this change first.',
|
|
657
|
-
};
|
|
658
|
-
const lead = !confirm
|
|
659
|
-
? null
|
|
660
|
-
: priceChanged
|
|
661
|
-
? 'The price or the billing period changed since the quote, so nothing was applied or charged. This is the new quote with a new idempotency_key; show it to the user and ask again.'
|
|
662
|
-
: 'Nothing was applied: confirming needs the idempotency_key of a quote, which ties the approval to the price. This is the quote; show it to the user first.';
|
|
663
|
-
const lines = [
|
|
664
|
-
'## Skill change quote',
|
|
665
|
-
'',
|
|
666
|
-
...(lead ? [lead, ''] : []),
|
|
667
|
-
`**Agent:** \`${agent_guid}\` (${agentStatusLabel(status)})`,
|
|
668
|
-
listLine('Turn on', changes.enable, titles),
|
|
669
|
-
listLine('Added because other skills need them', changes.addedDependencies, titles),
|
|
670
|
-
listLine('Turn off', changes.disable, titles),
|
|
671
|
-
listLine('Already as requested', changes.alreadySet, titles),
|
|
672
|
-
tierChange ? `**Plan:** ${currentTier ?? 'unknown'} to ${tierChange}` : null,
|
|
673
|
-
`**Monthly price:** ${currentPrice !== null ? formatUsd(currentPrice) : 'unknown'} now, ${formatUsd(newPrice)} after the change${delta !== null ? ` (${delta >= 0 ? '+' : ''}${formatUsd(delta)})` : ''}`,
|
|
674
|
-
priceNote ? `**Price update:** ${priceNote}` : null,
|
|
675
|
-
change?.creditsFromRenewal !== null && change?.creditsFromRenewal !== undefined
|
|
676
|
-
? `**Monthly credits:** ${currentCredits !== null ? formatCredits(currentCredits) : 'unknown'} now, ${formatCredits(change.creditsFromRenewal)} ${renewalWhen(billing)}`
|
|
677
|
-
: newCredits !== null ? `**Monthly credits:** ${currentCredits !== null ? formatCredits(currentCredits) : 'unknown'} now, ${formatCredits(newCredits)} ${creditsWhen(billing)}` : null,
|
|
678
|
-
change && change.creditsNow !== null && change.creditsThisPeriod !== null
|
|
679
|
-
? `**This period:** ${signedCredits(change.creditsNow)} credits now, ${formatCredits(change.creditsThisPeriod)} in all until ${unixToIso(change.periodEnd) ?? 'the period ends'}`
|
|
680
|
-
: null,
|
|
681
|
-
`**Billing:** ${note}`,
|
|
682
|
-
`**Restart:** ${restart}`,
|
|
683
|
-
...movedTaskLines(moved, row, running),
|
|
684
|
-
credentialsNeeded.length > 0
|
|
685
|
-
? `**Credentials the new skills need:** ${neededText(credentialsNeeded, row, titles, serviceTitles)}.${bindProjectNote(credentialsNeeded)}`
|
|
686
|
-
: null,
|
|
687
|
-
'',
|
|
688
|
-
blocked
|
|
689
|
-
? `${renewsBack(billing) ? 'Renew the subscription' : 'Start a new plan'} with manage_agent_billing before applying this change.`
|
|
690
|
-
: `Nothing has changed yet. After the user approves, call apply_agent_skills again with confirm: true and idempotency_key \`${quoteKey}\`.`,
|
|
691
|
-
].filter((line) => line !== null);
|
|
692
|
-
return {
|
|
693
|
-
content: [{ type: 'text', text: lines.join('\n') }],
|
|
694
|
-
structuredContent: {
|
|
695
|
-
...base,
|
|
696
|
-
status: 'quote',
|
|
697
|
-
idempotencyKey: quoteKey,
|
|
698
|
-
...(priceChanged ? { priceChanged: true } : {}),
|
|
699
|
-
pricing,
|
|
700
|
-
billing: {
|
|
701
|
-
...billingBase,
|
|
702
|
-
estimatedChargeNowUsd: change ? change.chargeNowUsd : null,
|
|
703
|
-
...(walletDrop ? { creditNowUsd: change.creditNowUsd, usedCreditsUsd: change.usedCreditsUsd } : {}),
|
|
704
|
-
note,
|
|
705
|
-
},
|
|
706
|
-
...(Array.isArray(preview.enabledSkills) ? { enabledSkills: preview.enabledSkills.map(String) } : {}),
|
|
707
|
-
...(moved !== undefined ? { scheduledTasks: moved } : {}),
|
|
708
|
-
restart,
|
|
709
|
-
nextAction,
|
|
710
|
-
},
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
const sentEmpty = nothingToDo;
|
|
211
|
+
const key = idempotency_key?.trim() || newSkillChangeKey(digest);
|
|
212
|
+
const sentEmpty = !skillsMove;
|
|
715
213
|
let applied;
|
|
716
214
|
try {
|
|
717
215
|
applied = requireApiSuccess(await client.post('/UserAgent/SkillsApply', {
|
|
718
216
|
useragentguid: agent_guid,
|
|
719
217
|
skills: diff.changes,
|
|
720
218
|
idempotencyKey: key,
|
|
721
|
-
...(tierChange ? { tier: tierChange } : {}),
|
|
722
219
|
}, extra.signal), 'The skill change was refused.');
|
|
723
220
|
}
|
|
724
221
|
catch (error) {
|
|
725
222
|
if (extra.signal.aborted)
|
|
726
223
|
throw error;
|
|
727
224
|
if (!outcomeUnknown(error)) {
|
|
728
|
-
const failure = describeSkillsApplyError(error,
|
|
225
|
+
const failure = describeSkillsApplyError(error, titles);
|
|
729
226
|
// Code 110 is the whole outcome: the next step reads the agent, and the call is not repeated.
|
|
730
227
|
const failedChange = failure.code === 110;
|
|
731
228
|
const nextAction = failedChange
|
|
732
|
-
? { tool: 'get_my_agent', arguments: { agent_guid }, reason: 'Check the agent\'s skills
|
|
229
|
+
? { tool: 'get_my_agent', arguments: { agent_guid }, reason: 'Check the agent\'s skills. Do not repeat the change.' }
|
|
733
230
|
: failure.code === 107
|
|
734
|
-
? { tool: 'apply_agent_skills', arguments: { agent_guid, skills,
|
|
231
|
+
? { tool: 'apply_agent_skills', arguments: { agent_guid, skills, add_dependencies }, reason: 'Make the change again with a new key.' }
|
|
735
232
|
: undefined;
|
|
736
233
|
const text = [
|
|
737
234
|
failedChange ? '## Skill change failed' : '## Skill change not applied',
|
|
@@ -746,15 +243,13 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
746
243
|
...base,
|
|
747
244
|
status: 'refused',
|
|
748
245
|
idempotencyKey: key,
|
|
749
|
-
|
|
246
|
+
note: failure.guidance || failure.message,
|
|
750
247
|
restart: failedChange ? 'The agent does not restart for this change.' : UNCHANGED_RESTART,
|
|
751
248
|
error: {
|
|
752
249
|
code: failure.code,
|
|
753
250
|
message: failure.message,
|
|
754
251
|
...(failure.deps ? { deps: failure.deps } : {}),
|
|
755
252
|
...(failure.conflicts ? { conflicts: failure.conflicts } : {}),
|
|
756
|
-
...(failure.requiredUsd !== undefined ? { requiredUsd: failure.requiredUsd } : {}),
|
|
757
|
-
...(failure.availableUsd !== undefined ? { availableUsd: failure.availableUsd } : {}),
|
|
758
253
|
},
|
|
759
254
|
...(nextAction ? { nextAction } : {}),
|
|
760
255
|
},
|
|
@@ -763,27 +258,23 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
763
258
|
}
|
|
764
259
|
const message = errorText(error);
|
|
765
260
|
if (sentEmpty) {
|
|
766
|
-
const note = 'The agent\'s skills already match the request, so the change is in place. Do not repeat it.
|
|
767
|
-
+ (billing.plan === 'prepaid'
|
|
768
|
-
? `What the earlier call with this idempotency_key took from, or credited to, ${walletName(billing)} is not shown here; get_account with recent_transactions shows it.`
|
|
769
|
-
: 'Any price difference follows the plan\'s usual billing.');
|
|
261
|
+
const note = 'The agent\'s skills already match the request, so the change is in place. Do not repeat it.';
|
|
770
262
|
return {
|
|
771
263
|
content: [{ type: 'text', text: `## No change needed\n\n${note}` }],
|
|
772
264
|
structuredContent: {
|
|
773
265
|
...base,
|
|
774
266
|
status: 'no_change',
|
|
775
267
|
idempotencyKey: key,
|
|
776
|
-
|
|
268
|
+
note: `${note} ${FREE_NOTE}`,
|
|
777
269
|
restart: UNCHANGED_RESTART,
|
|
778
270
|
},
|
|
779
271
|
};
|
|
780
272
|
}
|
|
781
|
-
// The agent is read again to see whether the change is in place
|
|
782
|
-
|
|
783
|
-
const { holds, live } = await readAfterChange(client, agent_guid, plan.requested, tierChange, extra.signal);
|
|
273
|
+
// The agent is read again to see whether the change is in place before anything is reported.
|
|
274
|
+
const { holds, live } = await readAfterChange(client, agent_guid, plan.requested, extra.signal);
|
|
784
275
|
if (holds === true) {
|
|
785
|
-
const paused = newlyPaused(row, live
|
|
786
|
-
const note = `The agent's skills now match the request, so the change is in place. Do not repeat it. ${
|
|
276
|
+
const paused = newlyPaused(row, live);
|
|
277
|
+
const note = `The agent's skills now match the request, so the change is in place. Do not repeat it. ${FREE_NOTE}`;
|
|
787
278
|
return {
|
|
788
279
|
content: [{ type: 'text', text: [
|
|
789
280
|
'## Skills updated',
|
|
@@ -791,16 +282,16 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
791
282
|
`**Agent:** \`${agent_guid}\``,
|
|
792
283
|
listLine('Turned on', changes.enable, titles),
|
|
793
284
|
listLine('Turned off', changes.disable, titles),
|
|
794
|
-
|
|
795
|
-
`**Restart:** ${
|
|
285
|
+
note,
|
|
286
|
+
`**Restart:** ${restartNote(status, 'skill change')}`,
|
|
796
287
|
await pausedLine(client, paused, extra.signal),
|
|
797
288
|
].filter((line) => line !== null).join('\n') }],
|
|
798
289
|
structuredContent: {
|
|
799
290
|
...base,
|
|
800
291
|
status: 'applied',
|
|
801
292
|
idempotencyKey: key,
|
|
802
|
-
|
|
803
|
-
restart:
|
|
293
|
+
note,
|
|
294
|
+
restart: restartNote(status, 'skill change'),
|
|
804
295
|
...(paused.length > 0 ? { pausedTasks: paused.map(entry => entry.key) } : {}),
|
|
805
296
|
},
|
|
806
297
|
};
|
|
@@ -815,69 +306,49 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
815
306
|
...base,
|
|
816
307
|
status: 'refused',
|
|
817
308
|
idempotencyKey: key,
|
|
818
|
-
|
|
819
|
-
restart:
|
|
309
|
+
note,
|
|
310
|
+
restart: unverified ? 'The agent restarts if the change was saved.' : UNCHANGED_RESTART,
|
|
820
311
|
error: { code: null, message },
|
|
821
312
|
},
|
|
822
313
|
isError: true,
|
|
823
314
|
};
|
|
824
315
|
}
|
|
825
|
-
// The live agent is checked against this change before it is reported
|
|
826
|
-
|
|
827
|
-
const { holds, live } = await readAfterChange(client, agent_guid, plan.requested, tierChange, extra.signal);
|
|
316
|
+
// The live agent is checked against this change before it is reported as applied.
|
|
317
|
+
const { holds, live } = await readAfterChange(client, agent_guid, plan.requested, extra.signal);
|
|
828
318
|
if (holds === false) {
|
|
829
319
|
const note = 'The agent\'s skills do not match this change, so it is not in place. Check get_my_agent; if they '
|
|
830
|
-
+ 'still do not match the request, call apply_agent_skills again without idempotency_key
|
|
320
|
+
+ 'still do not match the request, call apply_agent_skills again without idempotency_key.';
|
|
831
321
|
return {
|
|
832
322
|
content: [{ type: 'text', text: `## Skill change not applied\n\n${note}` }],
|
|
833
323
|
structuredContent: {
|
|
834
324
|
...base,
|
|
835
325
|
status: 'refused',
|
|
836
326
|
idempotencyKey: key,
|
|
837
|
-
|
|
327
|
+
note,
|
|
838
328
|
restart: UNCHANGED_RESTART,
|
|
839
329
|
error: { code: null, message: note },
|
|
840
330
|
nextAction: {
|
|
841
331
|
tool: 'apply_agent_skills',
|
|
842
|
-
arguments: { agent_guid, skills,
|
|
843
|
-
reason: '
|
|
332
|
+
arguments: { agent_guid, skills, add_dependencies },
|
|
333
|
+
reason: 'Make the change again with a new key.',
|
|
844
334
|
},
|
|
845
335
|
},
|
|
846
336
|
isError: true,
|
|
847
337
|
};
|
|
848
338
|
}
|
|
849
|
-
// An empty request that comes back as a real change is the saved
|
|
850
|
-
//
|
|
339
|
+
// An empty request that comes back as a real change is the saved result of the earlier call with this
|
|
340
|
+
// key, not a new change.
|
|
851
341
|
const replayed = sentEmpty && !applied.noOp;
|
|
852
|
-
const serverPricing = applied.pricing ?? {};
|
|
853
|
-
// An agent with no plan has no period and no renewal yet, as its quote says.
|
|
854
|
-
const appliedChange = billing.plan === 'none' ? null : readPlanChange({
|
|
855
|
-
creditsNow: serverPricing.creditsNow,
|
|
856
|
-
creditsThisPeriod: serverPricing.creditsThisPeriod,
|
|
857
|
-
creditsFromRenewal: serverPricing.creditsFromRenewal,
|
|
858
|
-
periodEnd: serverPricing.periodEnd,
|
|
859
|
-
});
|
|
860
|
-
const pricing = applied.noOp
|
|
861
|
-
? undefined
|
|
862
|
-
: {
|
|
863
|
-
currentMonthlyUsd: toNumber(serverPricing.previousPriceUsd),
|
|
864
|
-
newMonthlyUsd: toNumber(serverPricing.newPriceUsd),
|
|
865
|
-
deltaMonthlyUsd: toNumber(serverPricing.deltaUsd),
|
|
866
|
-
currentMonthlyCredits: toNumber(serverPricing.previousMonthlyCredits),
|
|
867
|
-
newMonthlyCredits: toNumber(serverPricing.newMonthlyCredits),
|
|
868
|
-
deltaMonthlyCredits: toNumber(serverPricing.deltaCredits),
|
|
869
|
-
...periodFields(appliedChange),
|
|
870
|
-
};
|
|
871
|
-
const charge = appliedBillingNote(billing, applied);
|
|
872
|
-
const usedCreditsUsd = toNumber(applied.usedCreditsUsd);
|
|
873
|
-
const billingNote = replayed
|
|
874
|
-
? `This change was already applied by an earlier call with this idempotency_key, and nothing new was charged now. That call's billing: ${charge.note}`
|
|
875
|
-
: charge.note;
|
|
876
342
|
// Wiro says whether this change restarts a running agent; an answer without it goes by the skills that move.
|
|
877
343
|
const restarts = typeof applied.restartTriggered === 'boolean' ? applied.restartTriggered : skillsMove;
|
|
878
|
-
const restart = applied.noOp || replayed
|
|
344
|
+
const restart = applied.noOp || replayed || !skillsMove
|
|
879
345
|
? UNCHANGED_RESTART
|
|
880
|
-
:
|
|
346
|
+
: running && !restarts
|
|
347
|
+
? 'The agent keeps running: Wiro did not restart it for this change. control_agent with action restart loads it now.'
|
|
348
|
+
: restartNote(status, 'skill change');
|
|
349
|
+
const note = replayed
|
|
350
|
+
? `This change was already applied by an earlier call with this idempotency_key. ${FREE_NOTE}`
|
|
351
|
+
: FREE_NOTE;
|
|
881
352
|
const firstCredential = credentialsNeeded[0]?.credentials[0];
|
|
882
353
|
const nextAction = applied.noOp || replayed
|
|
883
354
|
? undefined
|
|
@@ -896,29 +367,28 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
896
367
|
reason: 'Check that the agent is running again with the new skills.',
|
|
897
368
|
}
|
|
898
369
|
: undefined;
|
|
899
|
-
// Read from the agent after the change: the tasks it paused
|
|
900
|
-
const paused = applied.noOp || replayed ? [] : newlyPaused(row, live
|
|
370
|
+
// Read from the agent after the change: the tasks it paused.
|
|
371
|
+
const paused = applied.noOp || replayed ? [] : newlyPaused(row, live);
|
|
372
|
+
const warnings = warningsOf(applied);
|
|
373
|
+
const enabledSkills = applied.pricing && Array.isArray(applied.pricing.enabledSkills)
|
|
374
|
+
? applied.pricing.enabledSkills.map(String)
|
|
375
|
+
: undefined;
|
|
901
376
|
const lines = [
|
|
902
377
|
applied.noOp ? '## No change needed' : replayed ? '## Already applied' : '## Skills updated',
|
|
903
378
|
'',
|
|
904
379
|
`**Agent:** \`${agent_guid}\``,
|
|
905
380
|
listLine('Turned on', changes.enable, titles),
|
|
381
|
+
listLine('Added because other skills need them', changes.addedDependencies, titles),
|
|
906
382
|
listLine('Turned off', changes.disable, titles),
|
|
907
383
|
applied.noOp || replayed ? listLine('Already as requested', changes.alreadySet, titles) : null,
|
|
908
|
-
|
|
909
|
-
pricing?.newMonthlyUsd !== undefined && pricing.newMonthlyUsd !== null
|
|
910
|
-
? `**Monthly price:** ${formatUsd(pricing.newMonthlyUsd)}${pricing.currentMonthlyUsd !== null ? ` (was ${formatUsd(pricing.currentMonthlyUsd)})` : ''}`
|
|
911
|
-
: null,
|
|
912
|
-
pricing && appliedChange?.creditsNow !== null && appliedChange?.creditsNow !== undefined && appliedChange.creditsThisPeriod !== null
|
|
913
|
-
? `**This period:** ${signedCredits(appliedChange.creditsNow)} credits, ${formatCredits(appliedChange.creditsThisPeriod)} in all until ${unixToIso(appliedChange.periodEnd) ?? 'the period ends'}${appliedChange.creditsFromRenewal !== null ? `; ${renewalGives(billing, appliedChange.creditsFromRenewal)}` : ''}`
|
|
914
|
-
: null,
|
|
915
|
-
`**Billing:** ${billingNote}`,
|
|
384
|
+
`**Cost:** ${note}${changes.enable.length > 0 && !applied.noOp && !replayed ? ` ${WORK_NOTE}` : ''}`,
|
|
916
385
|
`**Restart:** ${restart}`,
|
|
917
386
|
holds === null ? 'The agent could not be read afterwards to confirm the new skills; get_my_agent shows them.' : null,
|
|
918
387
|
await pausedLine(client, paused, extra.signal),
|
|
919
|
-
credentialsNeeded.length > 0
|
|
388
|
+
credentialsNeeded.length > 0 && !applied.noOp && !replayed
|
|
920
389
|
? `**Still needed:** credentials for ${neededText(credentialsNeeded, row, titles, serviceTitles)}. ${stillNeededSteps(credentialsNeeded)}`
|
|
921
390
|
: null,
|
|
391
|
+
warnings.length > 0 ? `**From Wiro:** ${warnings.join(' ')}` : null,
|
|
922
392
|
].filter((line) => line !== null);
|
|
923
393
|
return {
|
|
924
394
|
content: [{ type: 'text', text: lines.join('\n') }],
|
|
@@ -926,15 +396,8 @@ export function registerApplyAgentSkills(server, client) {
|
|
|
926
396
|
...base,
|
|
927
397
|
status: applied.noOp ? 'no_change' : 'applied',
|
|
928
398
|
idempotencyKey: key,
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
billing: {
|
|
932
|
-
...billingBase,
|
|
933
|
-
chargedNowUsd: replayed ? 0 : charge.charged,
|
|
934
|
-
...(usedCreditsUsd !== null && usedCreditsUsd > 0 ? { usedCreditsUsd } : {}),
|
|
935
|
-
note: billingNote,
|
|
936
|
-
},
|
|
937
|
-
...(Array.isArray(serverPricing.enabledSkills) ? { enabledSkills: serverPricing.enabledSkills.map(String) } : {}),
|
|
399
|
+
note,
|
|
400
|
+
...(enabledSkills ? { enabledSkills } : {}),
|
|
938
401
|
restart,
|
|
939
402
|
...(paused.length > 0 ? { pausedTasks: paused.map(entry => entry.key) } : {}),
|
|
940
403
|
...(nextAction ? { nextAction } : {}),
|