@wiro-ai/wiro-mcp 1.5.7 → 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.
- 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 +45 -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 +54 -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 +15 -0
- 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 +8 -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 +49 -2
- 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 +12 -2
- package/dist/tools/update-agent.js.map +1 -1
- package/dist/utils/agent-catalog.d.ts +18 -14
- 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 +46 -0
- package/dist/utils/agent-message.d.ts.map +1 -1
- package/dist/utils/agent-message.js +22 -3
- package/dist/utils/agent-message.js.map +1 -1
- package/dist/utils/agent-setup.d.ts +134 -0
- package/dist/utils/agent-setup.d.ts.map +1 -0
- package/dist/utils/agent-setup.js +608 -0
- package/dist/utils/agent-setup.js.map +1 -0
- 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 +63 -0
- package/dist/utils/agent-turns.d.ts.map +1 -1
- package/dist/utils/agent-turns.js +162 -2
- 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/quoted-text.d.ts +10 -0
- package/dist/utils/quoted-text.d.ts.map +1 -1
- package/dist/utils/quoted-text.js +18 -0
- package/dist/utils/quoted-text.js.map +1 -1
- package/dist/utils/user-agent.d.ts +89 -21
- package/dist/utils/user-agent.d.ts.map +1 -1
- package/dist/utils/user-agent.js +211 -49
- package/dist/utils/user-agent.js.map +1 -1
- package/package.json +1 -1
package/dist/utils/user-agent.js
CHANGED
|
@@ -3,6 +3,7 @@ import { WiroApiError } from '../client.js';
|
|
|
3
3
|
import { AGENT_NOT_FOUND_TEXT, ApiResultError, asString, isPlainObject, requireApiSuccess, toNumber, truncate, unixToIso, } from './api.js';
|
|
4
4
|
import { pollUntil, reportProgress } from './poll.js';
|
|
5
5
|
import { quotedSpan } from './quoted-text.js';
|
|
6
|
+
import { CHAT_SETUP_MODES, chatSetupLabel, readChatSetupMode } from './agent-setup.js';
|
|
6
7
|
// Deployed agents and the agent catalog. Results are rebuilt from an
|
|
7
8
|
// allowlist: only states, labels, prices and settings are returned.
|
|
8
9
|
export const AGENT_DASHBOARD_URL = 'https://wiro.ai/panel/agents';
|
|
@@ -64,10 +65,8 @@ export function describeAgentStatus(status) {
|
|
|
64
65
|
// can read it and message it, so their hints say who can act instead of naming
|
|
65
66
|
// a call they cannot make.
|
|
66
67
|
const TEAM_AGENT_MANAGERS = 'a team admin or the person who deployed it';
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export const MEMBER_SETUP_HELP = `On this team agent, ${TEAM_AGENT_MANAGERS} saves credentials and pays for the plan. `
|
|
70
|
-
+ '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.';
|
|
71
70
|
const MEMBER_STATUS_HINT = {
|
|
72
71
|
stopped: `It is not running. On this team agent, ${TEAM_AGENT_MANAGERS} can start it.`,
|
|
73
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.`,
|
|
@@ -85,16 +84,35 @@ export function isTransitionalStatus(status) {
|
|
|
85
84
|
// ---------------------------------------------------------------------------
|
|
86
85
|
// Prices, plans and credits
|
|
87
86
|
// ---------------------------------------------------------------------------
|
|
88
|
-
|
|
89
|
-
|
|
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({
|
|
90
107
|
priceUsd: z.number(),
|
|
91
108
|
monthlyCredits: z.number(),
|
|
92
109
|
});
|
|
93
|
-
export const
|
|
94
|
-
starter:
|
|
95
|
-
pro:
|
|
110
|
+
export const planPricingSchema = z.object({
|
|
111
|
+
starter: planPriceSchema.optional(),
|
|
112
|
+
pro: planPriceSchema.optional(),
|
|
113
|
+
max: planPriceSchema.optional(),
|
|
96
114
|
});
|
|
97
|
-
function
|
|
115
|
+
function toPlanPrice(value) {
|
|
98
116
|
if (!isPlainObject(value))
|
|
99
117
|
return null;
|
|
100
118
|
const priceUsd = toNumber(value.priceUsd);
|
|
@@ -103,16 +121,36 @@ function toTierPrice(value) {
|
|
|
103
121
|
return null;
|
|
104
122
|
return { priceUsd, monthlyCredits: credits };
|
|
105
123
|
}
|
|
106
|
-
/**
|
|
107
|
-
export function
|
|
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) {
|
|
108
126
|
if (!isPlainObject(value))
|
|
109
127
|
return null;
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
|
|
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)}`;
|
|
113
139
|
}
|
|
114
|
-
|
|
115
|
-
|
|
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` : '';
|
|
116
154
|
}
|
|
117
155
|
export function formatUsd(value) {
|
|
118
156
|
if (value === null || value === undefined || !Number.isFinite(value))
|
|
@@ -138,7 +176,7 @@ export const subscriptionSchema = z.object({
|
|
|
138
176
|
billing: z.enum(['wallet', 'card']),
|
|
139
177
|
switchingToWallet: z.boolean(),
|
|
140
178
|
amountUsd: z.number().nullable()
|
|
141
|
-
.describe('What the plan costs every 30 days. For a plan that has ended,
|
|
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.'),
|
|
142
180
|
periodEndsAt: z.string().optional(),
|
|
143
181
|
daysRemaining: z.number().nullable(),
|
|
144
182
|
cancelAtPeriodEnd: z.boolean(),
|
|
@@ -188,6 +226,43 @@ export function chargeRoute(subscription) {
|
|
|
188
226
|
return 'wallet';
|
|
189
227
|
return 'card';
|
|
190
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
|
+
}
|
|
191
266
|
export const creditsSchema = z.object({
|
|
192
267
|
monthly: z.number()
|
|
193
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.'),
|
|
@@ -425,7 +500,10 @@ export const agentSummarySchema = z.object({
|
|
|
425
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.'),
|
|
426
501
|
workspace: z.enum(['personal', 'team']),
|
|
427
502
|
template: agentTemplateRefSchema,
|
|
428
|
-
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.'),
|
|
429
507
|
monthlyPriceUsd: z.number().nullable(),
|
|
430
508
|
credits: creditsSchema,
|
|
431
509
|
subscription: subscriptionSchema.nullable(),
|
|
@@ -441,12 +519,16 @@ export const agentDetailSchema = agentSummarySchema.extend({
|
|
|
441
519
|
description: z.string().optional(),
|
|
442
520
|
cover: z.string().optional(),
|
|
443
521
|
categories: z.array(z.string()),
|
|
444
|
-
pricing:
|
|
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.'),
|
|
445
524
|
extraCreditPacks: z.array(extraCreditPackSchema)
|
|
446
|
-
.describe('The extra credit packs this
|
|
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.'),
|
|
447
526
|
models: modelSettingsSchema.optional(),
|
|
448
527
|
selectableModels: z.array(selectableModelSchema).optional(),
|
|
449
528
|
enabledCommands: z.array(z.string()).nullable(),
|
|
529
|
+
chatSetup: z.enum(CHAT_SETUP_MODES).optional()
|
|
530
|
+
.describe('Setup from chat: where the agent may propose setup changes that a person then approves. off, webchat '
|
|
531
|
+
+ '(the Wiro web chat only) or all (also messages sent with an API key). Left out when Wiro does not report it.'),
|
|
450
532
|
credentials: z.array(credentialStatusSchema),
|
|
451
533
|
missingCredentials: z.array(z.object({ key: z.string(), title: z.string(), oauth: z.boolean() })),
|
|
452
534
|
channels: z.array(channelStatusSchema),
|
|
@@ -461,6 +543,7 @@ export const agentDetailSchema = agentSummarySchema.extend({
|
|
|
461
543
|
});
|
|
462
544
|
/** The part of a new agent that matters right after deploying it. */
|
|
463
545
|
export const deployedAgentSchema = agentSummarySchema.extend({
|
|
546
|
+
chatSetup: agentDetailSchema.shape.chatSetup,
|
|
464
547
|
missingCredentials: agentDetailSchema.shape.missingCredentials,
|
|
465
548
|
channels: agentDetailSchema.shape.channels,
|
|
466
549
|
dashboardUrl: z.string(),
|
|
@@ -493,18 +576,40 @@ function timestamps(row, map) {
|
|
|
493
576
|
return out;
|
|
494
577
|
}
|
|
495
578
|
/**
|
|
496
|
-
* The plan
|
|
497
|
-
*
|
|
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.
|
|
498
597
|
*/
|
|
499
598
|
function planOf(row) {
|
|
500
599
|
const plan = toSubscription(row.subscription, row.stripecancelatperiodend);
|
|
501
|
-
|
|
502
|
-
|
|
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;
|
|
503
607
|
}
|
|
504
608
|
/** The compact row used by list_my_agents. */
|
|
505
609
|
export function toAgentSummary(row) {
|
|
506
610
|
const status = readAgentStatus(row);
|
|
507
611
|
const tier = asString(row.tier);
|
|
612
|
+
const nextPlan = readNextPlan(row);
|
|
508
613
|
const timezone = row.timezone === null ? null : asString(row.timezone);
|
|
509
614
|
const sessionMode = asString(row.teamsessionmode);
|
|
510
615
|
return {
|
|
@@ -516,6 +621,7 @@ export function toAgentSummary(row) {
|
|
|
516
621
|
workspace: row.teamguid ? 'team' : 'personal',
|
|
517
622
|
template: templateRef(row),
|
|
518
623
|
...(tier ? { tier } : {}),
|
|
624
|
+
...(nextPlan !== undefined ? { nextPlan } : {}),
|
|
519
625
|
monthlyPriceUsd: toNumber(row.monthlypriceusd),
|
|
520
626
|
credits: toCredits(row),
|
|
521
627
|
subscription: planOf(row),
|
|
@@ -594,8 +700,9 @@ export function toAgentDetail(row) {
|
|
|
594
700
|
const cover = asString(row.cover) || asString(agent.cover);
|
|
595
701
|
const agentModel = isPlainObject(row.agentModel) ? row.agentModel : undefined;
|
|
596
702
|
const models = selectableModels(row.tokenRates);
|
|
597
|
-
|
|
598
|
-
|
|
703
|
+
const chatSetup = readChatSetupMode(row.chatSetup);
|
|
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';
|
|
599
706
|
const packs = canBuyPacks && Array.isArray(agent.extracreditpacks)
|
|
600
707
|
? agent.extracreditpacks.filter(isPlainObject).filter(pack => pack.enabled !== false)
|
|
601
708
|
: [];
|
|
@@ -604,7 +711,7 @@ export function toAgentDetail(row) {
|
|
|
604
711
|
...(description ? { description: truncate(description, 2_000) } : {}),
|
|
605
712
|
...(cover ? { cover } : {}),
|
|
606
713
|
categories: toStringArray(row.categories),
|
|
607
|
-
pricing:
|
|
714
|
+
pricing: toPlanPricing(agent.tiers),
|
|
608
715
|
extraCreditPacks: packs.flatMap(pack => {
|
|
609
716
|
const name = asString(pack.packkey);
|
|
610
717
|
const credits = toNumber(pack.credits);
|
|
@@ -623,6 +730,7 @@ export function toAgentDetail(row) {
|
|
|
623
730
|
: {}),
|
|
624
731
|
...(models.length > 0 ? { selectableModels: models } : {}),
|
|
625
732
|
enabledCommands: Array.isArray(row.enabledCommands) ? toStringArray(row.enabledCommands) : null,
|
|
733
|
+
...(chatSetup ? { chatSetup } : {}),
|
|
626
734
|
credentials,
|
|
627
735
|
missingCredentials: credentials
|
|
628
736
|
.filter(credential => credential.requiredMissing)
|
|
@@ -649,10 +757,16 @@ export function formatSubscriptionLine(subscription, plainMember = false) {
|
|
|
649
757
|
const parts = [`${subscription.status}, billed ${subscription.billing === 'wallet' ? 'from the wallet' : 'by card'}`];
|
|
650
758
|
if (subscription.amountUsd !== null) {
|
|
651
759
|
parts.push(subscription.status === 'expired' && subscription.billing === 'wallet'
|
|
652
|
-
? `a
|
|
760
|
+
? `a new period costs ${formatUsd(subscription.amountUsd)} per 30 days`
|
|
653
761
|
: `${formatUsd(subscription.amountUsd)} per 30 days`);
|
|
654
762
|
}
|
|
655
|
-
if (subscription
|
|
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) {
|
|
656
770
|
const atPeriodEnd = subscription.atPeriodEnd ?? (subscription.cancelAtPeriodEnd ? 'ends' : 'renews');
|
|
657
771
|
if (subscription.status !== 'active') {
|
|
658
772
|
parts.push(`period ended ${subscription.periodEndsAt}`);
|
|
@@ -676,12 +790,21 @@ export function formatSubscriptionLine(subscription, plainMember = false) {
|
|
|
676
790
|
export function startNeedsPlan(agent) {
|
|
677
791
|
return agent.subscription?.status !== 'active' && agent.credits.extra <= 0;
|
|
678
792
|
}
|
|
679
|
-
/**
|
|
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
|
+
*/
|
|
680
797
|
function planActionForStart(agent) {
|
|
798
|
+
if (isUnsettledPlan(agent.subscription))
|
|
799
|
+
return null;
|
|
681
800
|
return agent.subscription?.status === 'expired' && agent.subscription.billing === 'wallet' ? 'renew' : 'subscribe';
|
|
682
801
|
}
|
|
802
|
+
const NO_PLAN_TO_START = 'It has no active plan and no extra credits left, so it cannot start.';
|
|
683
803
|
function noPlanStartHint(agent) {
|
|
684
|
-
|
|
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} `
|
|
685
808
|
+ (planActionForStart(agent) === 'renew'
|
|
686
809
|
? 'Its wallet plan has expired; manage_agent_billing with action renew restarts it.'
|
|
687
810
|
: 'manage_agent_billing with action subscribe pays for a plan and starts the agent.');
|
|
@@ -690,6 +813,26 @@ function noPlanStartHint(agent) {
|
|
|
690
813
|
export function agentTitleSpan(title) {
|
|
691
814
|
return title.trim() ? quotedSpan(title) : 'Untitled agent';
|
|
692
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
|
+
}
|
|
693
836
|
export function formatAgentSummaryLines(agent, plainMember = false) {
|
|
694
837
|
const template = agent.template.custom
|
|
695
838
|
? 'custom build'
|
|
@@ -697,10 +840,11 @@ export function formatAgentSummaryLines(agent, plainMember = false) {
|
|
|
697
840
|
const hint = !plainMember && (agent.status === 0 || agent.status === 5) && startNeedsPlan(agent)
|
|
698
841
|
? `${agent.status === 5 ? 'The start failed or the agent stopped unexpectedly.' : 'It is not running.'} ${noPlanStartHint(agent)}`
|
|
699
842
|
: agentStatusHint(agent.status, plainMember);
|
|
843
|
+
const next = nextPlanText(agent);
|
|
700
844
|
return [
|
|
701
845
|
`**Agent:** ${agentTitleSpan(agent.title)} (\`${agent.guid}\`), ${template}, ${agent.workspace} workspace`,
|
|
702
846
|
`**Status:** ${describeAgentStatus(agent.status)}. ${hint}`,
|
|
703
|
-
`**Plan:** ${agent.tier
|
|
847
|
+
`**Plan:** ${agent.tier ? planName(agent.tier) : 'no plan'}; ${formatSubscriptionLine(agent.subscription, plainMember)}${next ? `; ${next}` : ''}`,
|
|
704
848
|
`**Credits:** ${formatCredits(agent.credits.remaining)} left (${monthlyCreditsText(agent.credits)}, extra ${formatCredits(agent.credits.extra)}, used ${formatCredits(agent.credits.used)})`,
|
|
705
849
|
];
|
|
706
850
|
}
|
|
@@ -864,11 +1008,11 @@ export function formatAgentDetail(agent, plainMember = false, titles) {
|
|
|
864
1008
|
const lines = formatAgentSummaryLines(agent, plainMember);
|
|
865
1009
|
if (agent.lastActivityAt)
|
|
866
1010
|
lines.push(`**Last activity:** ${agent.lastActivityAt}`);
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
//
|
|
870
|
-
|
|
871
|
-
lines.push(`**
|
|
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.`);
|
|
872
1016
|
}
|
|
873
1017
|
const models = formatModelsLine(agent);
|
|
874
1018
|
if (models)
|
|
@@ -876,6 +1020,8 @@ export function formatAgentDetail(agent, plainMember = false, titles) {
|
|
|
876
1020
|
if (agent.timezone !== undefined) {
|
|
877
1021
|
lines.push(`**Time zone:** ${agent.timezone?.trim() ? agent.timezone : 'UTC, the default'}. Scheduled tasks run in it.`);
|
|
878
1022
|
}
|
|
1023
|
+
if (agent.chatSetup)
|
|
1024
|
+
lines.push(`**Setup from chat:** ${chatSetupLabel(agent.chatSetup)}`);
|
|
879
1025
|
if (agent.setupRequired) {
|
|
880
1026
|
lines.push(agent.missingCredentials.length > 0
|
|
881
1027
|
? `**Setup required:** missing ${agent.missingCredentials.map(item => item.title).join(', ')}`
|
|
@@ -1021,7 +1167,8 @@ export function nextStepForAgent(agent, waitSeconds, plainMember = false) {
|
|
|
1021
1167
|
: undefined;
|
|
1022
1168
|
if (plainMember)
|
|
1023
1169
|
return wait;
|
|
1024
|
-
|
|
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)) {
|
|
1025
1172
|
return {
|
|
1026
1173
|
tool: 'manage_agent_billing',
|
|
1027
1174
|
arguments: { agent_guid: agent.guid, action: 'subscribe' },
|
|
@@ -1034,11 +1181,14 @@ export function nextStepForAgent(agent, waitSeconds, plainMember = false) {
|
|
|
1034
1181
|
if (wait)
|
|
1035
1182
|
return wait;
|
|
1036
1183
|
if ((agent.status === 0 || agent.status === 5) && startNeedsPlan(agent)) {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
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;
|
|
1042
1192
|
}
|
|
1043
1193
|
if (agent.status === 0 || agent.status === 5) {
|
|
1044
1194
|
return {
|
|
@@ -1063,12 +1213,12 @@ const PRE_CHARGE_REFUSALS = [
|
|
|
1063
1213
|
WALLET_NOT_READ,
|
|
1064
1214
|
/wallet deduction failed/i,
|
|
1065
1215
|
/subscription (is )?already active/i,
|
|
1066
|
-
/already on (the )?(pro|
|
|
1216
|
+
/already on (the )?(starter|pro|max) (tier|plan)/i,
|
|
1067
1217
|
/no active subscription|active subscription required|no expired subscription found/i,
|
|
1068
1218
|
/stripe subscriptions must be/i,
|
|
1069
1219
|
/extra credit pack|pack key required|purchase request id/i,
|
|
1070
1220
|
/could not (initialize|resume) prepaid credit purchase|prepaid credit purchase cannot be resumed/i,
|
|
1071
|
-
/downgrading to starter is not supported|targettier must be|tier must be 'starter'
|
|
1221
|
+
/downgrading to starter is not supported|targettier must be|tier must be 'starter'|change the plan with upgradetier/i,
|
|
1072
1222
|
/failed to compute (target-tier )?pricing|must be greater than \$0|failed to apply pricing snapshot/i,
|
|
1073
1223
|
/failed to create subscription record|subscription record returned invalid id/i,
|
|
1074
1224
|
/payment for this agent is already being processed|checkout for this agent is already being opened/i,
|
|
@@ -1078,10 +1228,22 @@ const PRE_CHARGE_REFUSALS = [
|
|
|
1078
1228
|
/^request parameter \[/i,
|
|
1079
1229
|
/mutually exclusive|agent terms acceptance|customskills must be|skill key may only contain/i,
|
|
1080
1230
|
/^unknown skill: /i,
|
|
1081
|
-
|
|
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,
|
|
1082
1242
|
/^we couldn't (schedule|undo) the cancellation\./i,
|
|
1083
1243
|
/enabledchannels is not accepted|credentials must be an object|credential field|is missing required fields/i,
|
|
1084
|
-
|
|
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,
|
|
1085
1247
|
/^failed to deploy agent|failed to save communication channel settings|failed to save custom skill/i,
|
|
1086
1248
|
];
|
|
1087
1249
|
/** Whether a result:false answer is one of the refusals known to leave the wallet untouched. */
|
|
@@ -1093,7 +1255,7 @@ export function isPreChargeRefusal(error) {
|
|
|
1093
1255
|
return PRE_CHARGE_REFUSALS.some(pattern => pattern.test(error.message.trim()));
|
|
1094
1256
|
}
|
|
1095
1257
|
const CHARGED_START = 'The wallet was charged ';
|
|
1096
|
-
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\.$/;
|
|
1097
1259
|
/**
|
|
1098
1260
|
* Whether a result:false answer says what the wallet paid. Its sentence is the
|
|
1099
1261
|
* whole outcome: it is shown as it is, and the call is not repeated.
|