pleaxy-mcp 0.1.2 → 0.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.
package/dist/cli.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { apiOrigin, isSignedIn, pleaxyAccountRequest } from "./api.js";
3
3
  import { CredentialStore } from "./auth/credentials.js";
4
- import { claimsOf, fetchAgentConfig, revokeRefreshToken, signInWithBrowser } from "./auth/oauth.js";
4
+ import { discoverPleaxyAuthServer, revokeRefreshToken, signInWithPleaxy } from "./auth/oauth.js";
5
+ import { configOf } from "./auth/session.js";
5
6
  export const CLI_COMMANDS = new Set(["login", "logout", "whoami"]);
6
7
  const say = (line) => process.stderr.write(`${line}\n`);
7
8
  function openBrowser(url) {
@@ -11,19 +12,20 @@ function openBrowser(url) {
11
12
  }
12
13
  async function login(store) {
13
14
  const origin = apiOrigin();
14
- const config = await fetchAgentConfig(origin);
15
- const tokens = await signInWithBrowser(config, openBrowser);
16
- const email = tokens.idToken ? claimsOf(tokens.idToken).email : undefined;
15
+ const pleaxy = await discoverPleaxyAuthServer(origin);
16
+ const tokens = await signInWithPleaxy(pleaxy, openBrowser);
17
17
  store.put({
18
18
  apiOrigin: origin,
19
- clientId: config.clientId,
20
- authDomain: config.authDomain,
19
+ kind: "pleaxy",
20
+ clientId: tokens.config.clientId,
21
+ issuer: pleaxy.issuer,
22
+ tokenEndpoint: pleaxy.tokenEndpoint,
23
+ ...(pleaxy.revocationEndpoint ? { revocationEndpoint: pleaxy.revocationEndpoint } : {}),
21
24
  refreshToken: tokens.refreshToken,
22
25
  accessToken: tokens.accessToken,
23
26
  accessExpiresAt: tokens.accessExpiresAt,
24
- ...(typeof email === "string" ? { email } : {}),
25
27
  });
26
- say(`Signed in to Pleaxy at ${origin}${typeof email === "string" ? ` as ${email}` : ""}.`);
28
+ say(`Connected to Pleaxy at ${origin}.`);
27
29
  await whoami();
28
30
  return 0;
29
31
  }
@@ -31,10 +33,15 @@ async function logout(store) {
31
33
  const origin = apiOrigin();
32
34
  const signIn = store.get(origin);
33
35
  if (!signIn) {
34
- say(`This agent isn't signed in to Pleaxy at ${origin}.`);
36
+ if (store.entry(origin)) {
37
+ store.delete(origin);
38
+ say(`Removed an old sign-in to Pleaxy at ${origin} from this machine.`);
39
+ }
40
+ else
41
+ say(`This agent isn't signed in to Pleaxy at ${origin}.`);
35
42
  return 0;
36
43
  }
37
- const revoked = await revokeRefreshToken({ clientId: signIn.clientId, authDomain: signIn.authDomain }, signIn.refreshToken);
44
+ const revoked = await revokeRefreshToken(configOf(signIn), signIn.refreshToken);
38
45
  store.delete(origin);
39
46
  say(revoked ? `Signed out of Pleaxy at ${origin}.` : `Signed out on this machine. Pleaxy couldn't be reached to end the sign-in there too: sign the agent out in Pleaxy, under Security & Sign-in → Agents.`);
40
47
  return 0;
@@ -46,10 +53,11 @@ async function whoami() {
46
53
  }
47
54
  const me = await pleaxyAccountRequest("/auth/me");
48
55
  const who = me.employee?.name ?? me.employee?.email ?? "you";
49
- say(`Acting as ${who}${me.agentSession ? `, signed in ${me.agentSession.signedInAt}` : ""}.`);
56
+ const until = me.agentSession?.expiresAt ? `, connected until ${me.agentSession.expiresAt}` : "";
57
+ say(`Acting as ${who}${me.agentSession ? `, signed in ${me.agentSession.signedInAt}${until}` : ""}.`);
50
58
  const workspaces = me.workspaces ?? [];
51
59
  if (workspaces.length) {
52
- say("Workspaces it can reach (set one as PLEAXY_WORKSPACE_ID):");
60
+ say("Workspaces it can use (tools take one per call; PLEAXY_WORKSPACE_ID sets a default):");
53
61
  for (const w of workspaces) {
54
62
  const name = w.companyName ?? w.regionName;
55
63
  const locked = w.locked ? ` - not reachable by an agent (${w.locked.reason ?? "locked"})` : "";
@@ -0,0 +1,66 @@
1
+ import { z } from "zod";
2
+ export const invoiceAiLineShape = {
3
+ invoicer: z.string().describe("Who bills the line: a cloud (aws, gcp, azure, oci) or an AI provider (openai, anthropic, mistral, ...)."),
4
+ vendor: z.string().describe("The model's maker, e.g. anthropic, openai, google."),
5
+ model: z.string().describe("The model id, e.g. claude-sonnet-4-5."),
6
+ meter: z.string().describe("What is metered: input_tokens, output_tokens, cached_input_tokens, batch_input_tokens, batch_output_tokens, ..."),
7
+ region: z.string().optional(),
8
+ period: z
9
+ .string()
10
+ .regex(/^\d{4}-(0[1-9]|1[0-2])$/, "A month as YYYY-MM")
11
+ .optional()
12
+ .describe("The month of usage the line bills, YYYY-MM; default the month before the invoice date."),
13
+ };
14
+ export const invoiceLineShape = {
15
+ description: z.string().min(1).max(200),
16
+ qty: z.number().positive().describe("Greater than 0. For an AI line, in the meter's unit: millions of tokens, hours."),
17
+ unitPrice: z.number().min(0).describe("0 or more, per unit of qty. A reduction is a discount, never a negative price."),
18
+ discount: z.number().min(0).optional().describe("Total discount on this line."),
19
+ charge: z.number().min(0).optional().describe("Total charges on this line (freight, handling)."),
20
+ ai: z
21
+ .object(invoiceAiLineShape)
22
+ .optional()
23
+ .describe("Only for a line that bills an AI model: it is then held to the contract's rate for that model and meter, the public price list and the provider's reported usage."),
24
+ };
25
+ export function feedInvoice(invoice) {
26
+ const { connectionId, ...body } = invoice;
27
+ return { connectionId, body };
28
+ }
29
+ export const invoiceShape = {
30
+ connectionId: z.string().min(1).max(100).describe("Who the invoice is between: the connection's id from list_invoice_counterparties."),
31
+ poId: z.string().optional().describe("The open purchase order it bills, from that counterparty's openPurchaseOrders. Leave it out only when there is no order."),
32
+ poLineNo: z.number().int().optional().describe("Against an order with several lines: the one line this invoice bills (its lineNo)."),
33
+ billsNoPoLine: z.boolean().optional().describe("true when it bills none of the order's lines (freight, a one-off fee). It still draws on the order's balance."),
34
+ invoiceNumber: z.string().min(1).max(64).describe("The supplier's own invoice number: unique per supplier at this buyer."),
35
+ invoiceDate: z
36
+ .string()
37
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "A date as YYYY-MM-DD")
38
+ .describe("YYYY-MM-DD: not in the future, not more than 365 days back."),
39
+ dueInDays: z.number().int().min(0).max(365).optional().describe("Days until it is due; default 30."),
40
+ lineItems: z.array(z.object(invoiceLineShape)).min(1),
41
+ taxAmount: z.number().min(0).optional().describe("The tax stated on the invoice, added to the lines' total."),
42
+ currency: z.string().optional().describe("Omit it: the invoice is in the buyer's currency. Another currency is refused for a supplier on Pleaxy; an off-platform supplier's invoice may name its own."),
43
+ documentType: z
44
+ .enum(["invoice", "debit_note"])
45
+ .optional()
46
+ .describe('"debit_note" for an amendment that raises what an earlier invoice asked for: name that invoice in amendsInvoiceId or amendsInvoiceNumber. Leave it out for an ordinary invoice.'),
47
+ amendsInvoiceId: z.string().optional().describe("Debit note: the Pleaxy id of the invoice it amends."),
48
+ amendsInvoiceNumber: z.string().optional().describe("Debit note: the supplier's number of the invoice it amends, when the Pleaxy id isn't known."),
49
+ replacesInvoiceIds: z.array(z.string()).min(1).max(20).optional().describe("A replacement invoice (credit and rebill): the Pleaxy ids of the invoices and debit notes it replaces, all from this supplier."),
50
+ replacesInvoiceNumbers: z.array(z.string()).min(1).max(20).optional().describe("A replacement invoice: the supplier's numbers of the invoices it replaces, when the Pleaxy ids aren't known."),
51
+ };
52
+ export const creditNoteShape = {
53
+ invoiceId: z.string().optional().describe("The invoice it corrects: its buyer, supplier, currency, PO and PO line become the credit note's. Give this or connectionId."),
54
+ connectionId: z.string().optional().describe("The counterparty it is for, from list_invoice_counterparties, when it corrects no one invoice."),
55
+ externalCreditNoteNumber: z.string().min(1).max(64).describe("The supplier's own number for it: unique per supplier at this buyer."),
56
+ issueDate: z
57
+ .string()
58
+ .regex(/^\d{4}-\d{2}-\d{2}$/, "A date as YYYY-MM-DD")
59
+ .describe("YYYY-MM-DD: not in the future, not more than 365 days back."),
60
+ reason: z.enum(["returned_goods", "price_adjustment", "service_credit", "rebate", "other", "early_payment_discount"]),
61
+ correctsBilling: z.boolean().optional().describe('Reason "other" only: it corrects what was billed, so it gives PO balance back too.'),
62
+ note: z.string().max(1000).optional().describe("For the other company to read, e.g. the return's RMA number."),
63
+ currency: z.string().optional().describe("ISO 4217. Required without invoiceId; with one, it must be the invoice's."),
64
+ lineItems: z.array(z.object(invoiceLineShape)).min(1).describe("What is credited, before tax: positive quantities and prices."),
65
+ taxAmount: z.number().min(0).optional().describe("The tax credited, included in the credit note's total."),
66
+ };
@@ -22,10 +22,16 @@ export const lineItemShape = {
22
22
  .describe('e.g. "Net 30". Omit it unless the user gave terms: the line then takes the default payment terms of the contract it falls under (contractId, or the contract its catalog price came from), else the catalog item\'s, else "Net 30".'),
23
23
  validFrom: z.string(),
24
24
  validUntil: z.string(),
25
- customerLineNo: z.string().max(40).optional().describe("Optional: the buyer's own number for this line (e.g. from their ERP), up to 40 letters, numbers, spaces, or . _ - /."),
25
+ customerLineNo: z
26
+ .string()
27
+ .max(40)
28
+ .optional()
29
+ .describe("Optional: the buyer's own number for this line (e.g. from their ERP), up to 40 letters, numbers, spaces, or . _ - /."),
26
30
  };
27
31
  export const createPurchaseOrderShape = {
28
- supplier: z.string().describe("The supplier/counterparty you're purchasing from, e.g. \"aws\""),
32
+ supplier: z
33
+ .string()
34
+ .describe('The supplier/counterparty you\'re purchasing from, e.g. "aws"'),
29
35
  supplierRegionId: z
30
36
  .string()
31
37
  .optional()
@@ -34,6 +40,15 @@ export const createPurchaseOrderShape = {
34
40
  billTo: z.string().optional(),
35
41
  costCenter: z.string().optional(),
36
42
  budgetOwner: z.string().optional(),
43
+ blanket: z
44
+ .boolean()
45
+ .optional()
46
+ .describe("A blanket order: billed as used, up to its total (a subscription, support hours, a reseller's monthly licences). Its total never uses the cost center's budget at once; expectedMonthly does, month by month, and its invoices as they are approved. Cloud orders (provider) are blanket orders either way. Only when the user says so."),
47
+ expectedMonthly: z
48
+ .number()
49
+ .min(0)
50
+ .optional()
51
+ .describe("Only on a blanket or cloud order, when the user gives it: what it is expected to bill each month, in the order's currency. The cost center's budget reserves it each month until invoiced."),
37
52
  notes: z.string().optional(),
38
53
  contractId: z
39
54
  .string()
@@ -1,6 +1,10 @@
1
1
  import { z } from "zod";
2
2
  export const purchaseRequestLineShape = {
3
3
  name: z.string().min(1).max(200).describe("What is needed, e.g. 27-inch monitor."),
4
+ lineType: z
5
+ .enum(["goods", "service"])
6
+ .optional()
7
+ .describe("goods (shipped and received) or service (work, hours, milestones). Only if the user said or it is plain from the line."),
4
8
  qty: z.number().positive().describe("How many."),
5
9
  unit: z.string().max(20).optional().describe("e.g. each, hour, month."),
6
10
  unitPrice: z.number().min(0).describe("Roughly what one costs, in the request's currency. Ask the user; never guess a price."),
@@ -10,6 +14,11 @@ export const purchaseRequestSupplierShape = {
10
14
  supplierConnectionId: z.string().max(64).optional().describe("Only if the supplier is on the workspace's supplier list and you know its connection id."),
11
15
  supplierRegionId: z.string().max(64).optional(),
12
16
  };
17
+ export const purchaseRequestAnswerShape = {
18
+ fieldId: z.string().min(1).max(100).describe("The question's id, from list_request_types."),
19
+ textAnswer: z.string().max(5000).optional().describe("text, long_text, number (e.g. 1250.5) and date (YYYY-MM-DD) questions."),
20
+ selectedOptionIds: z.array(z.string()).optional().describe('Choice questions: option ids ("yes"/"no" for yes/no questions).'),
21
+ };
13
22
  export const createPurchaseRequestShape = {
14
23
  title: z.string().min(1).max(200).describe("What is needed, in a few words."),
15
24
  description: z.string().max(4000).optional().describe("Why it is needed: the business reason, in the user's words. Required to submit."),
@@ -28,6 +37,16 @@ export const createPurchaseRequestShape = {
28
37
  .optional()
29
38
  .describe("When it's needed, YYYY-MM-DD."),
30
39
  notes: z.string().max(2000).optional().describe("Anything procurement should know."),
40
+ requestTypeId: z
41
+ .string()
42
+ .max(16)
43
+ .optional()
44
+ .describe("The request type (rt_...) from list_request_types that fits what is needed. Required when the workspace has request types."),
45
+ answers: z
46
+ .array(z.object(purchaseRequestAnswerShape))
47
+ .max(100)
48
+ .optional()
49
+ .describe("Answers to the type's questions. Ask a follow-up (showIf) only after the answer it depends on. Submitting needs every required question that is asked."),
31
50
  submit: z.boolean().optional().describe("true sends it for approval at once; otherwise it's saved as a draft the user can submit."),
32
51
  };
33
52
  export const convertPurchaseRequestShape = {
package/dist/rejection.js CHANGED
@@ -35,3 +35,29 @@ export function quoteRejectionNotes(data) {
35
35
  }
36
36
  return out;
37
37
  }
38
+ export function quoteComments(data) {
39
+ if (!data || typeof data !== "object" || !Array.isArray(data.comments))
40
+ return data;
41
+ const quote = (body) => `<comment_text>${body.split(/\r\n|[\r\n]/).map(cleanRejectionNote).join("\n").replace(/</g, "&lt;").replace(/>/g, "&gt;")}</comment_text>`;
42
+ const meeting = (m) => {
43
+ if (!m || typeof m !== "object")
44
+ return m;
45
+ const { attendees, ...rest } = m;
46
+ const quoted = { ...rest };
47
+ for (const field of ["topic", "link", "declineReason"])
48
+ if (typeof quoted[field] === "string")
49
+ quoted[field] = quote(quoted[field]);
50
+ if (Array.isArray(attendees))
51
+ quoted.attendees = attendees.map((a) => (a && typeof a === "object" ? { side: a.side, name: a.name } : a));
52
+ return quoted;
53
+ };
54
+ return {
55
+ ...data,
56
+ comments: data.comments.map((c) => {
57
+ if (!c || typeof c !== "object")
58
+ return c;
59
+ const comment = c;
60
+ return { ...comment, ...(typeof comment.body === "string" ? { body: quote(comment.body) } : {}), ...(comment.meeting ? { meeting: meeting(comment.meeting) } : {}) };
61
+ }),
62
+ };
63
+ }