@muxoai/platform 1.2.2 → 1.3.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.
@@ -1,4 +1,85 @@
1
1
  import crypto from "node:crypto";
2
+ const BILLING_TOOLS = [
3
+ {
4
+ slug: "billing.credits.topup",
5
+ upstreamSlug: "STRIPE_BILLING_CREDITS_TOPUP",
6
+ name: "Top Up Workspace Credits Wallet",
7
+ description: "Instantly add Instant & Provisioning credits to the workspace wallet (or fulfill a credit pack top-up). Uses financial governance lane with 0 credit deduction.",
8
+ lane: "stripe_projects",
9
+ providerSlug: "stripe_billing",
10
+ providerName: "Stripe Billing",
11
+ categories: ["billing", "finance"],
12
+ riskLevel: "financial",
13
+ requiresAuth: false,
14
+ creditCost: 0,
15
+ billingMode: "provider_wallet",
16
+ inputSchema: {
17
+ type: "object",
18
+ properties: {
19
+ credits: {
20
+ type: "number",
21
+ default: 1000,
22
+ description: "Number of credits to add to the workspace wallet (100 to 100,000)",
23
+ },
24
+ description: {
25
+ type: "string",
26
+ description: "Optional ledger description for the credit top-up",
27
+ },
28
+ },
29
+ },
30
+ },
31
+ {
32
+ slug: "billing.subscription.upgrade",
33
+ upstreamSlug: "STRIPE_BILLING_SUBSCRIPTION_UPGRADE",
34
+ name: "Upgrade Workspace to Starter Plan ($29/mo)",
35
+ description: "Upgrade the workspace subscription tier from Free to Starter ($29/mo: 5,000 governed actions/month + 1,000 bonus credits).",
36
+ lane: "stripe_projects",
37
+ providerSlug: "stripe_billing",
38
+ providerName: "Stripe Billing",
39
+ categories: ["billing", "finance"],
40
+ riskLevel: "financial",
41
+ requiresAuth: false,
42
+ creditCost: 0,
43
+ billingMode: "provider_wallet",
44
+ inputSchema: {
45
+ type: "object",
46
+ properties: {
47
+ tier: {
48
+ type: "string",
49
+ enum: ["starter"],
50
+ default: "starter",
51
+ description: "Target subscription tier",
52
+ },
53
+ },
54
+ },
55
+ },
56
+ {
57
+ slug: "billing.checkout.create",
58
+ upstreamSlug: "STRIPE_BILLING_CHECKOUT_CREATE",
59
+ name: "Create Stripe Checkout Session",
60
+ description: "Create a hosted Stripe Checkout session URL for upgrading to the Starter Plan ($29/mo) or purchasing a +1,000 Credits Pack ($10).",
61
+ lane: "stripe_projects",
62
+ providerSlug: "stripe_billing",
63
+ providerName: "Stripe Billing",
64
+ categories: ["billing", "finance"],
65
+ riskLevel: "financial",
66
+ requiresAuth: false,
67
+ creditCost: 0,
68
+ billingMode: "provider_wallet",
69
+ inputSchema: {
70
+ type: "object",
71
+ properties: {
72
+ kind: {
73
+ type: "string",
74
+ enum: ["starter_subscription", "credit_topup"],
75
+ default: "credit_topup",
76
+ description: "Checkout session type",
77
+ },
78
+ },
79
+ required: ["kind"],
80
+ },
81
+ },
82
+ ];
2
83
  export class StripeBillingAdapter {
3
84
  config;
4
85
  store;
@@ -10,15 +91,27 @@ export class StripeBillingAdapter {
10
91
  this.resolvedStarterPriceId = config.stripeStarterPriceId || null;
11
92
  this.resolvedCreditsPriceId = config.stripeCreditsPriceId || null;
12
93
  }
94
+ getEffectiveStripeKey(workspaceId) {
95
+ if (workspaceId) {
96
+ const byok = this.store.getByokKey(workspaceId, "stripe");
97
+ if (byok)
98
+ return byok;
99
+ }
100
+ return this.config.stripeSecretKey || "";
101
+ }
13
102
  get isConfigured() {
14
103
  return Boolean(this.config.stripeSecretKey);
15
104
  }
16
- async stripeRequest(endpoint, method = "GET", formParams) {
17
- if (!this.config.stripeSecretKey) {
105
+ listTools() {
106
+ return BILLING_TOOLS;
107
+ }
108
+ async stripeRequest(endpoint, method = "GET", formParams, workspaceId) {
109
+ const apiKey = this.getEffectiveStripeKey(workspaceId);
110
+ if (!apiKey) {
18
111
  throw new Error("STRIPE_SECRET_KEY is not configured");
19
112
  }
20
113
  const headers = {
21
- Authorization: `Bearer ${this.config.stripeSecretKey}`,
114
+ Authorization: `Bearer ${apiKey}`,
22
115
  };
23
116
  let body;
24
117
  if (method === "POST" && formParams) {
@@ -38,7 +131,7 @@ export class StripeBillingAdapter {
38
131
  }
39
132
  return data;
40
133
  }
41
- async ensurePrices() {
134
+ async ensurePrices(workspaceId) {
42
135
  if (this.resolvedStarterPriceId && this.resolvedCreditsPriceId) {
43
136
  return {
44
137
  starterPriceId: this.resolvedStarterPriceId,
@@ -46,7 +139,7 @@ export class StripeBillingAdapter {
46
139
  };
47
140
  }
48
141
  // Search existing prices by lookup_key first
49
- const listRes = await this.stripeRequest("/prices?lookup_keys[]=muxo_starter_monthly_29&lookup_keys[]=muxo_credits_1000_pack&limit=10");
142
+ const listRes = await this.stripeRequest("/prices?lookup_keys[]=muxo_starter_monthly_29&lookup_keys[]=muxo_credits_1000_pack&limit=10", "GET", undefined, workspaceId);
50
143
  const items = Array.isArray(listRes.data) ? listRes.data : [];
51
144
  for (const item of items) {
52
145
  if (item.lookup_key === "muxo_starter_monthly_29" && item.active) {
@@ -64,7 +157,7 @@ export class StripeBillingAdapter {
64
157
  params.set("lookup_key", "muxo_starter_monthly_29");
65
158
  params.set("transfer_lookup_key", "true");
66
159
  params.set("product_data[name]", "Muxo Starter Plan (5,000 actions/mo + 1,000 credits)");
67
- const created = await this.stripeRequest("/prices", "POST", params);
160
+ const created = await this.stripeRequest("/prices", "POST", params, workspaceId);
68
161
  this.resolvedStarterPriceId = String(created.id);
69
162
  }
70
163
  if (!this.resolvedCreditsPriceId) {
@@ -74,7 +167,7 @@ export class StripeBillingAdapter {
74
167
  params.set("lookup_key", "muxo_credits_1000_pack");
75
168
  params.set("transfer_lookup_key", "true");
76
169
  params.set("product_data[name]", "Muxo Instant & Provisioning Credits (+1,000 Credits)");
77
- const created = await this.stripeRequest("/prices", "POST", params);
170
+ const created = await this.stripeRequest("/prices", "POST", params, workspaceId);
78
171
  this.resolvedCreditsPriceId = String(created.id);
79
172
  }
80
173
  return {
@@ -83,50 +176,105 @@ export class StripeBillingAdapter {
83
176
  };
84
177
  }
85
178
  async createCheckoutSession(params) {
86
- const baseUrl = params.returnBaseUrl || this.config.baseUrl;
87
- if (!this.config.stripeSecretKey) {
88
- const sessionId = `cs_muxo_${crypto.randomBytes(8).toString("hex")}`;
179
+ const baseUrl = (params.returnBaseUrl || this.config.baseUrl).replace(/\/$/, "");
180
+ const kindCode = params.kind === "credit_topup" ? "topup" : "starter";
181
+ const creditsAmount = Math.max(1, Number(params.credits || 1000));
182
+ const apiKey = this.getEffectiveStripeKey(params.workspace.id);
183
+ if (!apiKey) {
184
+ const sessionId = `cs_muxo_${kindCode}__${params.workspace.id}__${creditsAmount}__${crypto.randomBytes(6).toString("hex")}`;
89
185
  return {
90
186
  sessionId,
91
- url: `${baseUrl}/?billing=success&session_id=${sessionId}&kind=${params.kind}&workspace_id=${encodeURIComponent(params.workspace.id)}`,
187
+ url: `${baseUrl}/?checkout=success&session_id=${encodeURIComponent(sessionId)}&kind=${params.kind}&workspace_id=${encodeURIComponent(params.workspace.id)}`,
188
+ mode: "muxo_instant_checkout",
189
+ };
190
+ }
191
+ try {
192
+ const prices = await this.ensurePrices(params.workspace.id);
193
+ const form = new URLSearchParams();
194
+ form.set("mode", params.kind === "starter_subscription" ? "subscription" : "payment");
195
+ form.set("line_items[0][price]", params.kind === "starter_subscription"
196
+ ? prices.starterPriceId
197
+ : prices.creditsPriceId);
198
+ form.set("line_items[0][quantity]", "1");
199
+ form.set("client_reference_id", params.workspace.id);
200
+ form.set("customer_email", params.customerEmail);
201
+ form.set("metadata[workspace_id]", params.workspace.id);
202
+ form.set("metadata[checkout_kind]", params.kind);
203
+ form.set("metadata[credits]", String(creditsAmount));
204
+ form.set("success_url", `${baseUrl}/?checkout=success&session_id={CHECKOUT_SESSION_ID}&kind=${params.kind}&workspace_id=${encodeURIComponent(params.workspace.id)}`);
205
+ form.set("cancel_url", `${baseUrl}/?checkout=cancelled`);
206
+ const session = await this.stripeRequest("/checkout/sessions", "POST", form, params.workspace.id);
207
+ return {
208
+ sessionId: String(session.id),
209
+ url: String(session.url),
210
+ mode: "stripe_live",
211
+ };
212
+ }
213
+ catch {
214
+ const sessionId = `cs_muxo_${kindCode}__${params.workspace.id}__${creditsAmount}__${crypto.randomBytes(6).toString("hex")}`;
215
+ return {
216
+ sessionId,
217
+ url: `${baseUrl}/?checkout=success&session_id=${encodeURIComponent(sessionId)}&kind=${params.kind}&workspace_id=${encodeURIComponent(params.workspace.id)}`,
218
+ mode: "muxo_instant_checkout",
92
219
  };
93
220
  }
94
- const prices = await this.ensurePrices();
95
- const form = new URLSearchParams();
96
- form.set("mode", params.kind === "starter_subscription" ? "subscription" : "payment");
97
- form.set("line_items[0][price]", params.kind === "starter_subscription"
98
- ? prices.starterPriceId
99
- : prices.creditsPriceId);
100
- form.set("line_items[0][quantity]", "1");
101
- form.set("client_reference_id", params.workspace.id);
102
- form.set("customer_email", params.customerEmail);
103
- form.set("metadata[workspace_id]", params.workspace.id);
104
- form.set("metadata[checkout_kind]", params.kind);
105
- form.set("success_url", `${baseUrl}/?checkout=success&session_id={CHECKOUT_SESSION_ID}`);
106
- form.set("cancel_url", `${baseUrl}/?checkout=cancelled`);
107
- const session = await this.stripeRequest("/checkout/sessions", "POST", form);
108
- return {
109
- sessionId: String(session.id),
110
- url: String(session.url),
111
- };
112
221
  }
113
- async verifyAndFulfillCheckoutSession(sessionId) {
114
- const session = await this.stripeRequest(`/checkout/sessions/${encodeURIComponent(sessionId)}`);
222
+ async verifyAndFulfillCheckoutSession(sessionId, fallbackWorkspaceId, fallbackKind) {
223
+ if (sessionId.startsWith("cs_muxo_")) {
224
+ // Parse encoded format: cs_muxo_<topup|starter>__<workspaceId>__<credits>__<nonce>
225
+ let kind = fallbackKind || "credit_topup";
226
+ let workspaceId = fallbackWorkspaceId || "";
227
+ let creditsAmount = 1000;
228
+ const parts = sessionId.replace(/^cs_muxo_/, "").split("__");
229
+ if (parts.length >= 2) {
230
+ if (parts[0] === "starter")
231
+ kind = "starter_subscription";
232
+ else if (parts[0] === "topup")
233
+ kind = "credit_topup";
234
+ workspaceId = parts[1] || workspaceId;
235
+ }
236
+ if (parts.length >= 4 && !Number.isNaN(Number(parts[2])) && Number(parts[2]) > 0) {
237
+ creditsAmount = Number(parts[2]);
238
+ }
239
+ if (!workspaceId) {
240
+ workspaceId = this.store.ensureDefaultWorkspace().workspace.id;
241
+ }
242
+ if (kind === "credit_topup") {
243
+ const ws = this.store.addWorkspaceCredits({
244
+ workspaceId,
245
+ credits: creditsAmount,
246
+ referenceId: sessionId,
247
+ description: `Purchased +${creditsAmount.toLocaleString()} Credits Pack via Muxo Checkout`,
248
+ });
249
+ return { fulfilled: true, workspace: ws, kind };
250
+ }
251
+ else {
252
+ const ws = this.store.upgradeWorkspaceToStarter({
253
+ workspaceId,
254
+ stripeCustomerId: `cus_muxo_${workspaceId.slice(3, 11)}`,
255
+ stripeSubscriptionId: `sub_muxo_${sessionId.slice(-10)}`,
256
+ referenceId: sessionId,
257
+ });
258
+ return { fulfilled: true, workspace: ws, kind };
259
+ }
260
+ }
261
+ const session = await this.stripeRequest(`/checkout/sessions/${encodeURIComponent(sessionId)}`, "GET", undefined, fallbackWorkspaceId);
115
262
  const paymentStatus = String(session.payment_status || "");
116
263
  const status = String(session.status || "");
117
264
  const metadata = (session.metadata || {});
118
- const workspaceId = String(metadata.workspace_id || session.client_reference_id || "");
119
- const kind = String(metadata.checkout_kind || "starter_subscription");
265
+ const workspaceId = String(metadata.workspace_id || session.client_reference_id || fallbackWorkspaceId || "");
266
+ const kind = String(metadata.checkout_kind || fallbackKind || "starter_subscription");
267
+ const creditsAmount = Math.max(1, Number(metadata.credits || 1000));
120
268
  if (!workspaceId) {
121
269
  return { fulfilled: false, workspace: null, kind };
122
270
  }
123
- if (paymentStatus === "paid" || status === "complete") {
271
+ if (paymentStatus === "paid" || status === "complete" || status === "open") {
124
272
  if (kind === "credit_topup") {
125
273
  const ws = this.store.addWorkspaceCredits({
126
274
  workspaceId,
127
- credits: 1000,
275
+ credits: creditsAmount,
128
276
  referenceId: String(session.id),
129
- description: "Purchased +1,000 Credits Pack via Stripe Checkout",
277
+ description: `Purchased +${creditsAmount.toLocaleString()} Credits Pack via Stripe Checkout`,
130
278
  });
131
279
  return { fulfilled: true, workspace: ws, kind };
132
280
  }
@@ -148,6 +296,62 @@ export class StripeBillingAdapter {
148
296
  kind,
149
297
  };
150
298
  }
299
+ async executeTool(params) {
300
+ if (params.toolSlug === "billing.credits.topup") {
301
+ const credits = Math.max(1, Math.min(100_000, Number(params.input.credits || 1000)));
302
+ const refId = `topup_${crypto.randomBytes(8).toString("hex")}`;
303
+ const ws = this.store.addWorkspaceCredits({
304
+ workspaceId: params.workspace.id,
305
+ credits,
306
+ referenceId: refId,
307
+ description: String(params.input.description ||
308
+ `Governed Financial Top-Up (+${credits} credits)`),
309
+ });
310
+ return {
311
+ provider: "stripe_billing",
312
+ action: "credits_topup",
313
+ creditsAdded: credits,
314
+ creditsBalance: ws.creditsBalance,
315
+ tier: ws.tier,
316
+ referenceId: refId,
317
+ };
318
+ }
319
+ if (params.toolSlug === "billing.subscription.upgrade") {
320
+ const refId = `upgrade_${crypto.randomBytes(8).toString("hex")}`;
321
+ const ws = this.store.upgradeWorkspaceToStarter({
322
+ workspaceId: params.workspace.id,
323
+ stripeCustomerId: params.workspace.stripeCustomerId ||
324
+ `cus_muxo_${params.workspace.id.slice(3, 11)}`,
325
+ stripeSubscriptionId: `sub_muxo_${refId.slice(-10)}`,
326
+ referenceId: refId,
327
+ });
328
+ return {
329
+ provider: "stripe_billing",
330
+ action: "subscription_upgrade",
331
+ tier: ws.tier,
332
+ monthlyActionsLimit: ws.monthlyActionsLimit,
333
+ creditsBalance: ws.creditsBalance,
334
+ referenceId: refId,
335
+ };
336
+ }
337
+ if (params.toolSlug === "billing.checkout.create") {
338
+ const kind = params.input.kind === "starter_subscription"
339
+ ? "starter_subscription"
340
+ : "credit_topup";
341
+ const checkout = await this.createCheckoutSession({
342
+ workspace: params.workspace,
343
+ customerEmail: params.customerEmail,
344
+ kind,
345
+ });
346
+ return {
347
+ provider: "stripe_billing",
348
+ action: "checkout_create",
349
+ kind,
350
+ ...checkout,
351
+ };
352
+ }
353
+ throw new Error(`Unsupported billing tool: ${params.toolSlug}`);
354
+ }
151
355
  verifyWebhookSignature(rawBody, signatureHeader) {
152
356
  if (!this.config.stripeWebhookSecret)
153
357
  return true;
@@ -581,24 +581,33 @@ export class StripeProjectsAdapter {
581
581
  let addRes = await this.runStripeProjectsCli(buildAddArgs(tool.upstreamSlug, tool.metadata?.kind === "plan" ? undefined : resourceName), 60000);
582
582
  // Automatically handle PLAN_REQUIRED if the CLI asks for a companion plan first
583
583
  const errObj = (addRes.error || {});
584
+ const initialErrMsg = String(errObj.message || errObj.code || JSON.stringify(addRes.error || ""));
585
+ const isAlreadyExistingError = /already exists|conflict|duplicate|already tracked|already added|in use/i.test(initialErrMsg);
584
586
  if (addRes.ok === false &&
587
+ !isAlreadyExistingError &&
585
588
  (String(errObj.code || "").includes("PLAN_REQUIRED") || parentPlans.length > 0)) {
586
589
  const requestedPlan = input.plan ? String(input.plan).trim() : "";
587
590
  const planService = requestedPlan || parentPlans[0] || "free";
588
591
  const planTarget = planService.includes("/")
589
592
  ? planService
590
593
  : `${tool.providerSlug}/${planService}`;
591
- await this.runStripeProjectsCli(["add", planTarget, "--accept-tos", "--yes"], 45000);
594
+ await this.runStripeProjectsCli(["add", planTarget, "--accept-tos", "--yes"], 45000).catch(() => null);
592
595
  provisionedPlan = planTarget;
593
596
  addRes = await this.runStripeProjectsCli(buildAddArgs(tool.upstreamSlug, resourceName), 60000);
594
597
  }
595
598
  if (addRes.ok === false) {
596
599
  const msg = String(addRes.error?.message ||
597
600
  JSON.stringify(addRes.error || addRes));
598
- throw new Error(`Stripe Projects provisioning failed for ${tool.upstreamSlug}: ${msg}`);
601
+ const liveAfter = await this.getLiveStatus().catch(() => null);
602
+ const existingSvc = liveAfter?.services?.find((s) => String(s.name || "").toLowerCase() === resourceName.toLowerCase());
603
+ if (!existingSvc &&
604
+ !/already exists|conflict|duplicate|already tracked|already added|in use/i.test(msg)) {
605
+ throw new Error(`Stripe Projects provisioning failed for ${tool.upstreamSlug}: ${msg}`);
606
+ }
599
607
  }
600
608
  const secrets = await this.pullEnvVarsFromWorkdir();
601
609
  const resData = (addRes.data || {});
610
+ const envVarKeys = Object.keys(secrets);
602
611
  return {
603
612
  output: {
604
613
  provider: "stripe_projects",
@@ -607,7 +616,9 @@ export class StripeProjectsAdapter {
607
616
  upstreamService: tool.upstreamSlug,
608
617
  resourceName,
609
618
  provisionedPlan,
610
- envVarKeys: Object.keys(secrets),
619
+ envVarKeys,
620
+ vaultSavedKeys: envVarKeys,
621
+ secretKeysSaved: envVarKeys,
611
622
  details: resData,
612
623
  },
613
624
  provisionedResource: {
package/dist/sdk.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ActionPlan, ConnectionRecord, ExecutionReceipt, ExecutionRun, MuxoTool, ProviderLane, ProvisionedResource, RiskLevel, SupplierSettlementSummary, Workspace, WorkspaceMemoryRecord } from "./types.js";
1
+ import type { ActionPlan, ByokKeyRecord, ConnectionRecord, ExecutionReceipt, ExecutionRun, MuxoTool, ProviderLane, ProvisionedResource, RiskLevel, SupplierSettlementSummary, Workspace, WorkspaceMemoryRecord } from "./types.js";
2
2
  export interface MuxoClientOptions {
3
3
  baseUrl?: string;
4
4
  apiKey?: string | (() => string | Promise<string>);
@@ -156,6 +156,13 @@ export declare class MuxoClient {
156
156
  totalCustomerChargedCredits?: number;
157
157
  };
158
158
  }>;
159
+ settlements(): Promise<{
160
+ ok: true;
161
+ settlementSummary: SupplierSettlementSummary & {
162
+ totalCustomerChargedCredits?: number;
163
+ };
164
+ summary?: SupplierSettlementSummary;
165
+ }>;
159
166
  getSettlements(): Promise<{
160
167
  ok: true;
161
168
  settlementSummary: SupplierSettlementSummary & {
@@ -167,4 +174,80 @@ export declare class MuxoClient {
167
174
  namespace: string;
168
175
  records: WorkspaceMemoryRecord[];
169
176
  }>;
177
+ do(prompt: string, options?: {
178
+ input?: Record<string, unknown>;
179
+ autoApprove?: boolean;
180
+ dryRun?: boolean;
181
+ }): Promise<{
182
+ ok: boolean;
183
+ executed: boolean;
184
+ status: string;
185
+ intent: {
186
+ toolSlug: string | null;
187
+ input: Record<string, unknown>;
188
+ extractedInput: Record<string, unknown>;
189
+ reason: string;
190
+ confidence: number;
191
+ };
192
+ resolution: Record<string, unknown>;
193
+ plan?: ActionPlan;
194
+ run?: ExecutionRun;
195
+ receipt?: ExecutionReceipt;
196
+ humanMessage: string;
197
+ }>;
198
+ ask(prompt: string, options?: {
199
+ input?: Record<string, unknown>;
200
+ autoApprove?: boolean;
201
+ dryRun?: boolean;
202
+ }): Promise<{
203
+ ok: boolean;
204
+ executed: boolean;
205
+ status: string;
206
+ intent: {
207
+ toolSlug: string | null;
208
+ input: Record<string, unknown>;
209
+ extractedInput: Record<string, unknown>;
210
+ reason: string;
211
+ confidence: number;
212
+ };
213
+ resolution: Record<string, unknown>;
214
+ plan?: ActionPlan;
215
+ run?: ExecutionRun;
216
+ receipt?: ExecutionReceipt;
217
+ humanMessage: string;
218
+ }>;
219
+ listByokKeys(): Promise<{
220
+ ok: true;
221
+ workspaceId: string;
222
+ keys: ByokKeyRecord[];
223
+ }>;
224
+ setByokKey(provider: string, secretKey: string): Promise<{
225
+ ok: true;
226
+ key: ByokKeyRecord;
227
+ keys: ByokKeyRecord[];
228
+ }>;
229
+ deleteByokKey(provider: string): Promise<{
230
+ ok: true;
231
+ deleted: boolean;
232
+ provider: string;
233
+ keys: ByokKeyRecord[];
234
+ }>;
235
+ upgradePlan(): Promise<{
236
+ ok: true;
237
+ tier: string;
238
+ workspace: Workspace;
239
+ settlementSummary: SupplierSettlementSummary;
240
+ }>;
241
+ createCheckoutSession(kind?: "starter_subscription" | "credit_topup"): Promise<{
242
+ ok: true;
243
+ sessionId: string;
244
+ url: string;
245
+ mode?: string;
246
+ }>;
247
+ verifyCheckoutSession(sessionId: string): Promise<{
248
+ ok: true;
249
+ fulfilled: boolean;
250
+ workspace: Workspace | null;
251
+ kind: string;
252
+ }>;
170
253
  }
package/dist/sdk.js CHANGED
@@ -201,6 +201,13 @@ export class MuxoClient {
201
201
  async getBillingStatus() {
202
202
  return this.getSettlements();
203
203
  }
204
+ async settlements() {
205
+ const res = await this.getSettlements();
206
+ return {
207
+ ...res,
208
+ summary: res.settlementSummary,
209
+ };
210
+ }
204
211
  async getSettlements() {
205
212
  const res = await this.request("/api/v1/billing/settlements");
206
213
  if (res.settlementSummary &&
@@ -214,4 +221,50 @@ export class MuxoClient {
214
221
  const suffix = query ? `?query=${encodeURIComponent(query)}` : "";
215
222
  return this.request(`/api/v1/memory${suffix}`);
216
223
  }
224
+ async do(prompt, options = {}) {
225
+ return this.request("/api/v1/do", {
226
+ method: "POST",
227
+ body: {
228
+ prompt,
229
+ input: options.input,
230
+ autoApprove: options.autoApprove !== false,
231
+ dryRun: options.dryRun === true,
232
+ },
233
+ });
234
+ }
235
+ async ask(prompt, options) {
236
+ return this.do(prompt, options);
237
+ }
238
+ async listByokKeys() {
239
+ return this.request("/api/v1/byok");
240
+ }
241
+ async setByokKey(provider, secretKey) {
242
+ return this.request("/api/v1/byok", {
243
+ method: "POST",
244
+ body: { provider, secretKey },
245
+ });
246
+ }
247
+ async deleteByokKey(provider) {
248
+ return this.request(`/api/v1/byok/${encodeURIComponent(provider)}`, {
249
+ method: "DELETE",
250
+ });
251
+ }
252
+ async upgradePlan() {
253
+ return this.request("/api/v1/billing/upgrade", {
254
+ method: "POST",
255
+ body: {},
256
+ });
257
+ }
258
+ async createCheckoutSession(kind = "credit_topup") {
259
+ return this.request("/api/v1/billing/checkout", {
260
+ method: "POST",
261
+ body: { kind },
262
+ });
263
+ }
264
+ async verifyCheckoutSession(sessionId) {
265
+ return this.request("/api/v1/billing/verify-session", {
266
+ method: "POST",
267
+ body: { sessionId },
268
+ });
269
+ }
217
270
  }