@wiro-ai/wiro-mcp 1.5.8 → 1.6.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.
Files changed (93) hide show
  1. package/README.md +14 -12
  2. package/dist/client.d.ts +4 -0
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +6 -1
  5. package/dist/client.js.map +1 -1
  6. package/dist/instructions.js +2 -2
  7. package/dist/instructions.js.map +1 -1
  8. package/dist/playbooks.d.ts.map +1 -1
  9. package/dist/playbooks.js +44 -40
  10. package/dist/playbooks.js.map +1 -1
  11. package/dist/prompts.js +3 -3
  12. package/dist/prompts.js.map +1 -1
  13. package/dist/tools/apply-agent-skills.d.ts.map +1 -1
  14. package/dist/tools/apply-agent-skills.js +102 -639
  15. package/dist/tools/apply-agent-skills.js.map +1 -1
  16. package/dist/tools/connect-agent-oauth.d.ts.map +1 -1
  17. package/dist/tools/connect-agent-oauth.js +260 -111
  18. package/dist/tools/connect-agent-oauth.js.map +1 -1
  19. package/dist/tools/control-agent.d.ts.map +1 -1
  20. package/dist/tools/control-agent.js +20 -9
  21. package/dist/tools/control-agent.js.map +1 -1
  22. package/dist/tools/deploy-agent.d.ts.map +1 -1
  23. package/dist/tools/deploy-agent.js +42 -28
  24. package/dist/tools/deploy-agent.js.map +1 -1
  25. package/dist/tools/get-agent-activity.d.ts.map +1 -1
  26. package/dist/tools/get-agent-activity.js +3 -1
  27. package/dist/tools/get-agent-activity.js.map +1 -1
  28. package/dist/tools/get-agent-conversation.d.ts.map +1 -1
  29. package/dist/tools/get-agent-conversation.js +7 -4
  30. package/dist/tools/get-agent-conversation.js.map +1 -1
  31. package/dist/tools/get-agent-message.d.ts.map +1 -1
  32. package/dist/tools/get-agent-message.js +5 -1
  33. package/dist/tools/get-agent-message.js.map +1 -1
  34. package/dist/tools/get-agent-template.d.ts.map +1 -1
  35. package/dist/tools/get-agent-template.js +11 -9
  36. package/dist/tools/get-agent-template.js.map +1 -1
  37. package/dist/tools/get-my-agent.js +4 -4
  38. package/dist/tools/get-my-agent.js.map +1 -1
  39. package/dist/tools/list-agent-skills.d.ts.map +1 -1
  40. package/dist/tools/list-agent-skills.js +22 -17
  41. package/dist/tools/list-agent-skills.js.map +1 -1
  42. package/dist/tools/list-agent-templates.d.ts.map +1 -1
  43. package/dist/tools/list-agent-templates.js +16 -10
  44. package/dist/tools/list-agent-templates.js.map +1 -1
  45. package/dist/tools/list-my-agents.d.ts.map +1 -1
  46. package/dist/tools/list-my-agents.js +2 -2
  47. package/dist/tools/list-my-agents.js.map +1 -1
  48. package/dist/tools/manage-agent-billing.d.ts.map +1 -1
  49. package/dist/tools/manage-agent-billing.js +476 -187
  50. package/dist/tools/manage-agent-billing.js.map +1 -1
  51. package/dist/tools/send-agent-message.d.ts.map +1 -1
  52. package/dist/tools/send-agent-message.js +10 -5
  53. package/dist/tools/send-agent-message.js.map +1 -1
  54. package/dist/tools/set-agent-credentials.d.ts.map +1 -1
  55. package/dist/tools/set-agent-credentials.js +24 -6
  56. package/dist/tools/set-agent-credentials.js.map +1 -1
  57. package/dist/tools/update-agent.d.ts.map +1 -1
  58. package/dist/tools/update-agent.js +2 -1
  59. package/dist/tools/update-agent.js.map +1 -1
  60. package/dist/utils/agent-catalog.d.ts +16 -12
  61. package/dist/utils/agent-catalog.d.ts.map +1 -1
  62. package/dist/utils/agent-catalog.js +4 -11
  63. package/dist/utils/agent-catalog.js.map +1 -1
  64. package/dist/utils/agent-config.d.ts +98 -45
  65. package/dist/utils/agent-config.d.ts.map +1 -1
  66. package/dist/utils/agent-config.js +246 -147
  67. package/dist/utils/agent-config.js.map +1 -1
  68. package/dist/utils/agent-message.d.ts +18 -0
  69. package/dist/utils/agent-message.d.ts.map +1 -1
  70. package/dist/utils/agent-setup.d.ts +53 -2
  71. package/dist/utils/agent-setup.d.ts.map +1 -1
  72. package/dist/utils/agent-setup.js +371 -22
  73. package/dist/utils/agent-setup.js.map +1 -1
  74. package/dist/utils/agent-targets.d.ts.map +1 -1
  75. package/dist/utils/agent-targets.js +9 -2
  76. package/dist/utils/agent-targets.js.map +1 -1
  77. package/dist/utils/agent-turns.d.ts +18 -0
  78. package/dist/utils/agent-turns.d.ts.map +1 -1
  79. package/dist/utils/agent-turns.js +73 -14
  80. package/dist/utils/agent-turns.js.map +1 -1
  81. package/dist/utils/api.d.ts +1 -1
  82. package/dist/utils/api.d.ts.map +1 -1
  83. package/dist/utils/api.js +3 -3
  84. package/dist/utils/api.js.map +1 -1
  85. package/dist/utils/quoted-text.d.ts +7 -0
  86. package/dist/utils/quoted-text.d.ts.map +1 -1
  87. package/dist/utils/quoted-text.js +14 -0
  88. package/dist/utils/quoted-text.js.map +1 -1
  89. package/dist/utils/user-agent.d.ts +76 -18
  90. package/dist/utils/user-agent.d.ts.map +1 -1
  91. package/dist/utils/user-agent.js +202 -49
  92. package/dist/utils/user-agent.js.map +1 -1
  93. package/package.json +1 -1
@@ -65,10 +65,8 @@ export function describeAgentStatus(status) {
65
65
  // can read it and message it, so their hints say who can act instead of naming
66
66
  // a call they cannot make.
67
67
  const TEAM_AGENT_MANAGERS = 'a team admin or the person who deployed it';
68
- // Connected accounts are the exception: Wiro lets only the person who
69
- // deployed the agent connect them (connect_agent_oauth).
70
- export const MEMBER_SETUP_HELP = `On this team agent, ${TEAM_AGENT_MANAGERS} saves credentials and pays for the plan. `
71
- + 'Only the person who deployed it can connect accounts, such as Instagram or Google Ads.';
68
+ export const MEMBER_SETUP_HELP = `On this team agent, ${TEAM_AGENT_MANAGERS} saves credentials, connects accounts such `
69
+ + 'as Instagram or Google Ads, and pays for the plan.';
72
70
  const MEMBER_STATUS_HINT = {
73
71
  stopped: `It is not running. On this team agent, ${TEAM_AGENT_MANAGERS} can start it.`,
74
72
  error: `The start failed or the agent stopped unexpectedly. On this team agent, ${TEAM_AGENT_MANAGERS} can start it again and read its logs.`,
@@ -86,16 +84,35 @@ export function isTransitionalStatus(status) {
86
84
  // ---------------------------------------------------------------------------
87
85
  // Prices, plans and credits
88
86
  // ---------------------------------------------------------------------------
89
- export const AGENT_TIERS = ['starter', 'pro'];
90
- export const tierPriceSchema = z.object({
87
+ /**
88
+ * The plans an agent can have, smallest first. Every plan includes every skill,
89
+ * and each has a fixed monthly price and monthly credits, the same for every
90
+ * template and custom build. The numbers come from Wiro, never from here.
91
+ */
92
+ export const AGENT_PLANS = ['starter', 'pro', 'max'];
93
+ const PLAN_NAMES = { starter: 'Starter', pro: 'Pro', max: 'Max' };
94
+ export function asPlan(value) {
95
+ return typeof value === 'string' && AGENT_PLANS.includes(value) ? value : undefined;
96
+ }
97
+ /** A plan as people read it: Starter, Pro or Max. Another value is shown as it is. */
98
+ export function planName(plan) {
99
+ const known = asPlan(plan);
100
+ return known ? PLAN_NAMES[known] : (plan ?? '');
101
+ }
102
+ /** Below 0 when a is a smaller plan than b, 0 for the same plan and above 0 for a larger one. */
103
+ export function comparePlans(a, b) {
104
+ return AGENT_PLANS.indexOf(a) - AGENT_PLANS.indexOf(b);
105
+ }
106
+ export const planPriceSchema = z.object({
91
107
  priceUsd: z.number(),
92
108
  monthlyCredits: z.number(),
93
109
  });
94
- export const tierPricingSchema = z.object({
95
- starter: tierPriceSchema,
96
- pro: tierPriceSchema,
110
+ export const planPricingSchema = z.object({
111
+ starter: planPriceSchema.optional(),
112
+ pro: planPriceSchema.optional(),
113
+ max: planPriceSchema.optional(),
97
114
  });
98
- function toTierPrice(value) {
115
+ function toPlanPrice(value) {
99
116
  if (!isPlainObject(value))
100
117
  return null;
101
118
  const priceUsd = toNumber(value.priceUsd);
@@ -104,16 +121,36 @@ function toTierPrice(value) {
104
121
  return null;
105
122
  return { priceUsd, monthlyCredits: credits };
106
123
  }
107
- /** Starter and Pro prices, or null when Wiro could not price the agent. */
108
- export function toTierPricing(value) {
124
+ /** Each plan's price and monthly credits as Wiro lists them (its tiers), or null when it lists none. */
125
+ export function toPlanPricing(value) {
109
126
  if (!isPlainObject(value))
110
127
  return null;
111
- const starter = toTierPrice(value.starter);
112
- const pro = toTierPrice(value.pro);
113
- return starter && pro ? { starter, pro } : null;
128
+ const pricing = {};
129
+ for (const plan of AGENT_PLANS) {
130
+ const price = toPlanPrice(value[plan]);
131
+ if (price)
132
+ pricing[plan] = price;
133
+ }
134
+ return Object.keys(pricing).length > 0 ? pricing : null;
135
+ }
136
+ /** A plan's monthly price in a list: whole dollars without cents, such as $5, and other amounts with them. */
137
+ export function formatPlanUsd(value) {
138
+ return Number.isInteger(value) ? `$${value}` : `$${value.toFixed(2)}`;
114
139
  }
115
- export function asTier(value) {
116
- return value === 'starter' || value === 'pro' ? value : undefined;
140
+ /** One plan with its price and credits: "Pro $30 (3,000 credits)". */
141
+ export function planPriceText(plan, price) {
142
+ return `${PLAN_NAMES[plan]} ${formatPlanUsd(price.priceUsd)} (${formatCredits(price.monthlyCredits)} credits)`;
143
+ }
144
+ /**
145
+ * The plans Wiro lists, smallest first, as one line: "Starter $5 (500 credits), Pro $30 (3,000 credits),
146
+ * Max $100 (10,000 credits) per month". except leaves one plan out, such as the one a quote is for.
147
+ */
148
+ export function planLineText(pricing, except) {
149
+ const listed = AGENT_PLANS.flatMap(plan => {
150
+ const price = pricing[plan];
151
+ return price && plan !== except ? [planPriceText(plan, price)] : [];
152
+ });
153
+ return listed.length > 0 ? `${listed.join(', ')} per month` : '';
117
154
  }
118
155
  export function formatUsd(value) {
119
156
  if (value === null || value === undefined || !Number.isFinite(value))
@@ -139,7 +176,7 @@ export const subscriptionSchema = z.object({
139
176
  billing: z.enum(['wallet', 'card']),
140
177
  switchingToWallet: z.boolean(),
141
178
  amountUsd: z.number().nullable()
142
- .describe('What the plan costs every 30 days. For a plan that has ended, the agent\'s monthly price, which is what a renew charges.'),
179
+ .describe('What the plan costs every 30 days. For a plan that has ended, what a new period costs: the price of its plan today.'),
143
180
  periodEndsAt: z.string().optional(),
144
181
  daysRemaining: z.number().nullable(),
145
182
  cancelAtPeriodEnd: z.boolean(),
@@ -189,6 +226,43 @@ export function chargeRoute(subscription) {
189
226
  return 'wallet';
190
227
  return 'card';
191
228
  }
229
+ // The plan statuses Wiro counts as ended. Every other status is a plan that has not ended, a card plan
230
+ // whose renewal payment did not go through included, and Wiro starts no second plan beside it.
231
+ const ENDED_PLAN_STATUSES = new Set(['expired', 'cancelled', 'refunded']);
232
+ // A card plan whose renewal payment did not go through: past_due while the card is tried again, unpaid after.
233
+ const PAYMENT_FAILED_STATUSES = new Set(['past_due', 'unpaid']);
234
+ /** Whether a plan with this status has not ended, as Wiro reads it: any status but expired, cancelled and refunded. */
235
+ function isLivePlanStatus(status) {
236
+ return typeof status === 'string' && status.trim() !== '' && !ENDED_PLAN_STATUSES.has(status);
237
+ }
238
+ /** A plan that has not ended and is not active, such as a card plan whose last payment did not go through. */
239
+ export function isUnsettledPlan(plan) {
240
+ return Boolean(plan) && plan?.status !== 'active' && isLivePlanStatus(plan?.status);
241
+ }
242
+ // Billing in the dashboard's personal workspace. Its Open Billing Portal button is where a card plan whose last
243
+ // payment did not go through is paid or cancelled: the agent's page offers the billing portal only for an active
244
+ // plan, and a team workspace has no billing portal, since a team's card plans are billed to the member who pays.
245
+ const BILLING_PAGE_URL = 'https://wiro.ai/panel/billing';
246
+ /**
247
+ * What to do about a plan that has not ended and is not active. Wiro starts no new plan beside it, and renews,
248
+ * changes, cancels and adds packs only to an active plan, so the dashboard settles it: a card plan whose last
249
+ * payment did not go through renews by itself once its open invoice is paid in the billing portal, which Billing
250
+ * opens in the personal workspace of whoever pays for the plan. lead says what the call could not do, after the
251
+ * plan's state.
252
+ */
253
+ export function unsettledPlanText(plan, agent, lead = '') {
254
+ const failed = plan.billing === 'card' && PAYMENT_FAILED_STATUSES.has(plan.status);
255
+ const state = failed
256
+ ? `The last payment for this card plan did not go through (${plan.status}), so the plan has not ended.`
257
+ : `This ${plan.billing === 'card' ? 'card ' : ''}plan is ${plan.status}, so it has not ended.`;
258
+ const fix = failed
259
+ ? 'To fix the payment, open Billing in the personal workspace of the Wiro dashboard and choose Open Billing Portal. '
260
+ + 'Pay the open invoice there, with another card if needed, and the plan renews by itself. The plan can also be cancelled there. '
261
+ + (agent.workspace === 'team' ? 'On a team agent, the member whose card pays for the plan does this, from their own personal workspace. ' : '')
262
+ + BILLING_PAGE_URL
263
+ : `It is managed in the Wiro dashboard: ${agentDashboardUrl(agent.guid)}`;
264
+ return [state, lead, fix].filter(Boolean).join(' ');
265
+ }
192
266
  export const creditsSchema = z.object({
193
267
  monthly: z.number()
194
268
  .describe('The monthly credits this period grants. A plan change inside a period moves it for the time left, so it can differ from renewal.'),
@@ -426,7 +500,10 @@ export const agentSummarySchema = z.object({
426
500
  .describe('Whether the agent waits for setup. list_my_agents goes by the status (6). get_my_agent also checks each required credential and names what is missing.'),
427
501
  workspace: z.enum(['personal', 'team']),
428
502
  template: agentTemplateRefSchema,
429
- tier: z.string().optional(),
503
+ tier: z.string().optional()
504
+ .describe('The agent\'s plan: starter, pro or max.'),
505
+ nextPlan: z.string().nullable().optional()
506
+ .describe('The plan the agent moves to at its next renewal, when a move is set: another plan, or its own plan at today\'s price. null when none is set; left out when Wiro does not say.'),
430
507
  monthlyPriceUsd: z.number().nullable(),
431
508
  credits: creditsSchema,
432
509
  subscription: subscriptionSchema.nullable(),
@@ -442,9 +519,10 @@ export const agentDetailSchema = agentSummarySchema.extend({
442
519
  description: z.string().optional(),
443
520
  cover: z.string().optional(),
444
521
  categories: z.array(z.string()),
445
- pricing: tierPricingSchema.nullable(),
522
+ pricing: planPricingSchema.nullable()
523
+ .describe('Each plan\'s price and monthly credits, the same for every agent. null when Wiro could not list them.'),
446
524
  extraCreditPacks: z.array(extraCreditPackSchema)
447
- .describe('The extra credit packs this plan can buy. Only an active Pro plan can buy them, so any other plan lists none.'),
525
+ .describe('The extra credit packs this agent can buy, the same on every plan. Only an agent with an active plan can buy them, so any other agent lists none.'),
448
526
  models: modelSettingsSchema.optional(),
449
527
  selectableModels: z.array(selectableModelSchema).optional(),
450
528
  enabledCommands: z.array(z.string()).nullable(),
@@ -498,18 +576,40 @@ function timestamps(row, map) {
498
576
  return out;
499
577
  }
500
578
  /**
501
- * The plan as it is shown. A plan that has ended renews at the agent's monthly
502
- * price, not at the amount of its last period, so that is its one price.
579
+ * The plan a move is set for at the next renewal: null when none is set, undefined when Wiro does not say.
580
+ * It can be the agent's own plan, which then renews at that plan's price today.
581
+ */
582
+ export function readNextPlan(row) {
583
+ const value = row.nextplan !== undefined ? row.nextplan : row.nextPlan;
584
+ if (value === null || value === '')
585
+ return null;
586
+ return asPlan(value);
587
+ }
588
+ /** The plans' prices on an agent row (its agent's tiers), or null when it lists none. */
589
+ export function rowPlanPricing(row) {
590
+ return toPlanPricing(isPlainObject(row.agent) ? row.agent.tiers : undefined);
591
+ }
592
+ /**
593
+ * The plan as it is shown. A plan that has ended costs a whole new period at the price its plan has today,
594
+ * not the amount of its last period, so that is its one price. Without the plans' prices on the row, the
595
+ * agent's monthly price stands in for it. A plan that has not ended, such as a card plan whose last payment
596
+ * did not go through, keeps its own amount.
503
597
  */
504
598
  function planOf(row) {
505
599
  const plan = toSubscription(row.subscription, row.stripecancelatperiodend);
506
- const price = toNumber(row.monthlypriceusd);
507
- return plan && plan.status !== 'active' && price !== null && price > 0 ? { ...plan, amountUsd: price } : plan;
600
+ if (!plan || isLivePlanStatus(plan.status))
601
+ return plan;
602
+ const key = readNextPlan(row) ?? asPlan(row.tier);
603
+ const today = key ? rowPlanPricing(row)?.[key]?.priceUsd : undefined;
604
+ const own = toNumber(row.monthlypriceusd);
605
+ const price = today ?? (own !== null && own > 0 ? own : null);
606
+ return price !== null ? { ...plan, amountUsd: price } : plan;
508
607
  }
509
608
  /** The compact row used by list_my_agents. */
510
609
  export function toAgentSummary(row) {
511
610
  const status = readAgentStatus(row);
512
611
  const tier = asString(row.tier);
612
+ const nextPlan = readNextPlan(row);
513
613
  const timezone = row.timezone === null ? null : asString(row.timezone);
514
614
  const sessionMode = asString(row.teamsessionmode);
515
615
  return {
@@ -521,6 +621,7 @@ export function toAgentSummary(row) {
521
621
  workspace: row.teamguid ? 'team' : 'personal',
522
622
  template: templateRef(row),
523
623
  ...(tier ? { tier } : {}),
624
+ ...(nextPlan !== undefined ? { nextPlan } : {}),
524
625
  monthlyPriceUsd: toNumber(row.monthlypriceusd),
525
626
  credits: toCredits(row),
526
627
  subscription: planOf(row),
@@ -600,8 +701,8 @@ export function toAgentDetail(row) {
600
701
  const agentModel = isPlainObject(row.agentModel) ? row.agentModel : undefined;
601
702
  const models = selectableModels(row.tokenRates);
602
703
  const chatSetup = readChatSetupMode(row.chatSetup);
603
- // Packs are bought only on an active Pro plan, so only that plan lists them.
604
- const canBuyPacks = summary.tier === 'pro' && summary.subscription?.status === 'active';
704
+ // Every plan can buy packs, but only while it is active, so only an active plan lists them.
705
+ const canBuyPacks = summary.subscription?.status === 'active';
605
706
  const packs = canBuyPacks && Array.isArray(agent.extracreditpacks)
606
707
  ? agent.extracreditpacks.filter(isPlainObject).filter(pack => pack.enabled !== false)
607
708
  : [];
@@ -610,7 +711,7 @@ export function toAgentDetail(row) {
610
711
  ...(description ? { description: truncate(description, 2_000) } : {}),
611
712
  ...(cover ? { cover } : {}),
612
713
  categories: toStringArray(row.categories),
613
- pricing: toTierPricing(agent.tiers),
714
+ pricing: toPlanPricing(agent.tiers),
614
715
  extraCreditPacks: packs.flatMap(pack => {
615
716
  const name = asString(pack.packkey);
616
717
  const credits = toNumber(pack.credits);
@@ -656,10 +757,16 @@ export function formatSubscriptionLine(subscription, plainMember = false) {
656
757
  const parts = [`${subscription.status}, billed ${subscription.billing === 'wallet' ? 'from the wallet' : 'by card'}`];
657
758
  if (subscription.amountUsd !== null) {
658
759
  parts.push(subscription.status === 'expired' && subscription.billing === 'wallet'
659
- ? `a renew charges ${formatUsd(subscription.amountUsd)} per 30 days`
760
+ ? `a new period costs ${formatUsd(subscription.amountUsd)} per 30 days`
660
761
  : `${formatUsd(subscription.amountUsd)} per 30 days`);
661
762
  }
662
- if (subscription.periodEndsAt) {
763
+ if (isUnsettledPlan(subscription)) {
764
+ // It has not ended, so no period is said to have ended; a payment that did not go through is named.
765
+ if (subscription.billing === 'card' && PAYMENT_FAILED_STATUSES.has(subscription.status)) {
766
+ parts.push('its last payment did not go through');
767
+ }
768
+ }
769
+ else if (subscription.periodEndsAt) {
663
770
  const atPeriodEnd = subscription.atPeriodEnd ?? (subscription.cancelAtPeriodEnd ? 'ends' : 'renews');
664
771
  if (subscription.status !== 'active') {
665
772
  parts.push(`period ended ${subscription.periodEndsAt}`);
@@ -683,12 +790,21 @@ export function formatSubscriptionLine(subscription, plainMember = false) {
683
790
  export function startNeedsPlan(agent) {
684
791
  return agent.subscription?.status !== 'active' && agent.credits.extra <= 0;
685
792
  }
686
- /** renew brings back an expired wallet plan; any other agent without an active plan takes a new one. */
793
+ /**
794
+ * renew brings back an expired wallet plan; any other agent without an active plan takes a new one. A plan that
795
+ * has not ended, such as a card plan whose last payment did not go through, takes neither: null.
796
+ */
687
797
  function planActionForStart(agent) {
798
+ if (isUnsettledPlan(agent.subscription))
799
+ return null;
688
800
  return agent.subscription?.status === 'expired' && agent.subscription.billing === 'wallet' ? 'renew' : 'subscribe';
689
801
  }
802
+ const NO_PLAN_TO_START = 'It has no active plan and no extra credits left, so it cannot start.';
690
803
  function noPlanStartHint(agent) {
691
- return 'It has no active plan and no extra credits left, so it cannot start. '
804
+ if (agent.subscription && isUnsettledPlan(agent.subscription)) {
805
+ return unsettledPlanText(agent.subscription, agent, 'The agent cannot start until the plan is active again, since it has no extra credits left.');
806
+ }
807
+ return `${NO_PLAN_TO_START} `
692
808
  + (planActionForStart(agent) === 'renew'
693
809
  ? 'Its wallet plan has expired; manage_agent_billing with action renew restarts it.'
694
810
  : 'manage_agent_billing with action subscribe pays for a plan and starts the agent.');
@@ -697,6 +813,26 @@ function noPlanStartHint(agent) {
697
813
  export function agentTitleSpan(title) {
698
814
  return title.trim() ? quotedSpan(title) : 'Untitled agent';
699
815
  }
816
+ /**
817
+ * The move set for the next renewal, as a clause after the plan: "moves to Starter from the renewal after
818
+ * <date>", or for the agent's own plan "from the renewal after <date> it is billed at today's Starter
819
+ * price". Empty when none is set, or when the plan ends with its period instead of renewing.
820
+ */
821
+ export function nextPlanText(agent) {
822
+ const next = agent.nextPlan;
823
+ const subscription = agent.subscription;
824
+ if (!next || subscription?.status !== 'active' || subscription.atPeriodEnd === 'ends')
825
+ return '';
826
+ const when = subscription.periodEndsAt ? `the renewal after ${subscription.periodEndsAt}` : 'the next renewal';
827
+ return next === agent.tier
828
+ ? `from ${when} it is billed at today's ${planName(next)} price`
829
+ : `moves to ${planName(next)} from ${when}`;
830
+ }
831
+ /** The plan by name, with the move set for its next renewal: "Max, moves to Starter from the renewal after ...". */
832
+ export function planSummaryText(agent) {
833
+ const next = nextPlanText(agent);
834
+ return `${agent.tier ? planName(agent.tier) : 'no plan'}${next ? `, ${next}` : ''}`;
835
+ }
700
836
  export function formatAgentSummaryLines(agent, plainMember = false) {
701
837
  const template = agent.template.custom
702
838
  ? 'custom build'
@@ -704,10 +840,11 @@ export function formatAgentSummaryLines(agent, plainMember = false) {
704
840
  const hint = !plainMember && (agent.status === 0 || agent.status === 5) && startNeedsPlan(agent)
705
841
  ? `${agent.status === 5 ? 'The start failed or the agent stopped unexpectedly.' : 'It is not running.'} ${noPlanStartHint(agent)}`
706
842
  : agentStatusHint(agent.status, plainMember);
843
+ const next = nextPlanText(agent);
707
844
  return [
708
845
  `**Agent:** ${agentTitleSpan(agent.title)} (\`${agent.guid}\`), ${template}, ${agent.workspace} workspace`,
709
846
  `**Status:** ${describeAgentStatus(agent.status)}. ${hint}`,
710
- `**Plan:** ${agent.tier ?? 'no tier'}; ${formatSubscriptionLine(agent.subscription, plainMember)}`,
847
+ `**Plan:** ${agent.tier ? planName(agent.tier) : 'no plan'}; ${formatSubscriptionLine(agent.subscription, plainMember)}${next ? `; ${next}` : ''}`,
711
848
  `**Credits:** ${formatCredits(agent.credits.remaining)} left (${monthlyCreditsText(agent.credits)}, extra ${formatCredits(agent.credits.extra)}, used ${formatCredits(agent.credits.used)})`,
712
849
  ];
713
850
  }
@@ -871,11 +1008,11 @@ export function formatAgentDetail(agent, plainMember = false, titles) {
871
1008
  const lines = formatAgentSummaryLines(agent, plainMember);
872
1009
  if (agent.lastActivityAt)
873
1010
  lines.push(`**Last activity:** ${agent.lastActivityAt}`);
874
- if (agent.pricing) {
875
- // Today's Starter and Pro prices for this agent's own skills, which can
876
- // differ from its template's and from the price its plan pays.
877
- const { starter, pro } = agent.pricing;
878
- lines.push(`**Prices now:** Starter ${formatUsd(starter.priceUsd)} per 30 days with ${formatCredits(starter.monthlyCredits)} credits per month; Pro ${formatUsd(pro.priceUsd)} per 30 days with ${formatCredits(pro.monthlyCredits)} credits per month. A new plan or an upgrade uses these, and a skill change moves the plan to today's prices for all its skills.`);
1011
+ const plans = agent.pricing ? planLineText(agent.pricing) : '';
1012
+ if (plans) {
1013
+ // The plans' prices today, the same for every agent. A plan that started at
1014
+ // another price keeps it until a change or a renewal moves it.
1015
+ lines.push(`**Plans:** ${plans}. Every plan includes every skill. A move to a larger plan starts now, and a move to a smaller one at the next renewal.`);
879
1016
  }
880
1017
  const models = formatModelsLine(agent);
881
1018
  if (models)
@@ -1030,7 +1167,8 @@ export function nextStepForAgent(agent, waitSeconds, plainMember = false) {
1030
1167
  : undefined;
1031
1168
  if (plainMember)
1032
1169
  return wait;
1033
- if (agent.status === 6 && agent.subscription?.status !== 'active') {
1170
+ // A plan that has not ended takes no new one: its payment is settled in the dashboard.
1171
+ if (agent.status === 6 && agent.subscription?.status !== 'active' && !isUnsettledPlan(agent.subscription)) {
1034
1172
  return {
1035
1173
  tool: 'manage_agent_billing',
1036
1174
  arguments: { agent_guid: agent.guid, action: 'subscribe' },
@@ -1043,11 +1181,14 @@ export function nextStepForAgent(agent, waitSeconds, plainMember = false) {
1043
1181
  if (wait)
1044
1182
  return wait;
1045
1183
  if ((agent.status === 0 || agent.status === 5) && startNeedsPlan(agent)) {
1046
- return {
1047
- tool: 'manage_agent_billing',
1048
- arguments: { agent_guid: agent.guid, action: planActionForStart(agent) },
1049
- reason: 'The agent has no active plan and no extra credits left, so it cannot start. This returns the price; nothing is charged without confirm: true.',
1050
- };
1184
+ const action = planActionForStart(agent);
1185
+ return action
1186
+ ? {
1187
+ tool: 'manage_agent_billing',
1188
+ arguments: { agent_guid: agent.guid, action },
1189
+ reason: 'The agent has no active plan and no extra credits left, so it cannot start. This returns the price; nothing is charged without confirm: true.',
1190
+ }
1191
+ : undefined;
1051
1192
  }
1052
1193
  if (agent.status === 0 || agent.status === 5) {
1053
1194
  return {
@@ -1072,12 +1213,12 @@ const PRE_CHARGE_REFUSALS = [
1072
1213
  WALLET_NOT_READ,
1073
1214
  /wallet deduction failed/i,
1074
1215
  /subscription (is )?already active/i,
1075
- /already on (the )?(pro|starter) tier/i,
1216
+ /already on (the )?(starter|pro|max) (tier|plan)/i,
1076
1217
  /no active subscription|active subscription required|no expired subscription found/i,
1077
1218
  /stripe subscriptions must be/i,
1078
1219
  /extra credit pack|pack key required|purchase request id/i,
1079
1220
  /could not (initialize|resume) prepaid credit purchase|prepaid credit purchase cannot be resumed/i,
1080
- /downgrading to starter is not supported|targettier must be|tier must be 'starter' or 'pro'/i,
1221
+ /downgrading to starter is not supported|targettier must be|tier must be 'starter'|change the plan with upgradetier/i,
1081
1222
  /failed to compute (target-tier )?pricing|must be greater than \$0|failed to apply pricing snapshot/i,
1082
1223
  /failed to create subscription record|subscription record returned invalid id/i,
1083
1224
  /payment for this agent is already being processed|checkout for this agent is already being opened/i,
@@ -1087,10 +1228,22 @@ const PRE_CHARGE_REFUSALS = [
1087
1228
  /^request parameter \[/i,
1088
1229
  /mutually exclusive|agent terms acceptance|customskills must be|skill key may only contain/i,
1089
1230
  /^unknown skill: /i,
1090
- /^the tier change could not be saved\./i,
1231
+ /is not in the skill registry\./i,
1232
+ /^the (tier|plan) change could not be saved\./i,
1233
+ // Anchored: "The wallet was charged $X, but the plan could not be saved." is a paid outcome.
1234
+ /^the plan could not be saved\. nothing was charged; please try again in a minute\./i,
1235
+ /^no active plan\.|plan changed while this was asked for|no renewal to change/i,
1236
+ /^could not read the agent's plan\. nothing was changed; please retry\./i,
1237
+ /^the agent's plan could not be read\. nothing was charged; please retry\./i,
1238
+ /^the (starter|pro|max) plan is smaller than this agent's (starter|pro|max) plan, so this is not an upgrade\. nothing was changed\./i,
1239
+ /^this agent is on the (starter|pro|max) plan now, so (starter|pro|max) is an upgrade\. nothing was changed\./i,
1240
+ /^the move to the (starter|pro|max) plan started with this billing period, and its payment moves the agent there, so it can no longer be undone\. nothing was changed\./i,
1241
+ /^the (scheduled )?plan change could not be (scheduled|cancelled)\./i,
1091
1242
  /^we couldn't (schedule|undo) the cancellation\./i,
1092
1243
  /enabledchannels is not accepted|credentials must be an object|credential field|is missing required fields/i,
1093
- /chat mode is not accepted|is managed by (wiro|the connection flow)|^agent-[a-z-]+$/i,
1244
+ // A field the connection flow fills, or one Wiro fills: "is managed by the platform", as Wiro words it now, or
1245
+ // "by Wiro", as it did.
1246
+ /chat mode is not accepted|is managed by (wiro|the platform|the connection flow)|^agent-[a-z-]+$/i,
1094
1247
  /^failed to deploy agent|failed to save communication channel settings|failed to save custom skill/i,
1095
1248
  ];
1096
1249
  /** Whether a result:false answer is one of the refusals known to leave the wallet untouched. */
@@ -1102,7 +1255,7 @@ export function isPreChargeRefusal(error) {
1102
1255
  return PRE_CHARGE_REFUSALS.some(pattern => pattern.test(error.message.trim()));
1103
1256
  }
1104
1257
  const CHARGED_START = 'The wallet was charged ';
1105
- const CHARGED_END = /, but the (tier change|renewal) did not finish\. Please contact support and do not try again\.$/;
1258
+ const CHARGED_END = /, but the ((tier change|plan change|renewal) did not finish|plan could not be saved)\. Please contact support and do not try again\.$/;
1106
1259
  /**
1107
1260
  * Whether a result:false answer says what the wallet paid. Its sentence is the
1108
1261
  * whole outcome: it is shown as it is, and the call is not repeated.