Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,25 @@ link-local, CGNAT, multicast and reserved ranges, redirects re-checked hop by ho
## License

MIT

## Money plugins (0.2.0)

`FINANCE_CATALOG` lists Mercury (business banking), CoinPay (crypto payments)
and moomoo (brokerage and trading); `DEFAULT_PLUGINS` are the ones apps turn
on for every account (Mercury and CoinPay; each person signs in to their own
account). The confirmation gate goes in your tool-call layer:

```js
import { applyPolicy, describeAction, policyFor, listTools } from "@profullstack/chat-plugins";

const policy = policyFor(plugin.url); // by server, not slug
const tools = applyPolicy(policy, await listTools(plugin), plugin.tradingMode ?? "paper");
// Only allowlisted reads run alone; every other tool (and any unknown name)
// is destructiveHint: true, so needsApproval() stops the loop for the person.
// describeAction(policy, tool, args) is the approval card: amount, currency,
// from, to, memo; or symbol, side, qty, type, prices, estimated cost, paper/live.
```

moomoo in paper mode offers reads plus `sim_trade_*` orders only; live order
tools appear only in `"live"` mode, and still ask. `redactLog()` masks tokens,
long digit runs and amounts before anything reaches a log.
41 changes: 41 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,44 @@ export function fetchJson(
export function parseWwwAuthenticate(header: string): Record<string, string>;
export function protectedResourceCandidates(resource: URL): string[];
export function authServerCandidates(issuer: string): string[];

// ── money plugins (src/money.js) ────────────────────────────────────────────

export type MoneyKind = "banking" | "crypto" | "trading";
export type TradingMode = "paper" | "live";
export interface PluginPolicy {
slug: string;
kind: MoneyKind;
/** Tools that only read. Exact names; anything else asks first. */
readOnly: ReadonlySet<string>;
/** OAuth scopes to ask for instead of everything the server offers. */
scopes?: string[];
/** Brokerage: tools that place, change or cancel PAPER orders. */
paperWrites?: ReadonlySet<string>;
}
export interface FinanceCatalogEntry {
slug: string;
name: string;
url: string;
description: string;
homepage: string;
icon: string;
/** On for every account (listed and switched on, not signed in). */
default: boolean;
}
export interface ActionSummary {
title: string;
lines: { label: string; value: string }[];
account?: TradingMode;
note?: string;
}
export const MODEL_CAN_BE_WRONG: string;
export const FINANCE_CATALOG: readonly FinanceCatalogEntry[];
export const DEFAULT_PLUGINS: readonly FinanceCatalogEntry[];
export const POLICIES: Record<string, PluginPolicy>;
export function policyFor(url: string): PluginPolicy | null;
export function needsConfirmation(policy: PluginPolicy, tool: string): boolean;
export function visibleInMode(policy: PluginPolicy, tool: string, mode: TradingMode): boolean;
export function applyPolicy<T extends { name: string; annotations?: object }>(policy: PluginPolicy | null, tools: T[], mode?: TradingMode): T[];
export function describeAction(policy: PluginPolicy | null, tool: string, args: Record<string, unknown>): ActionSummary | null;
export function redactLog(v: unknown): string;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@profullstack/chat-plugins",
"version": "0.1.0",
"version": "0.2.0",
"type": "module",
"description": "Chat plugins = remote MCP servers, with less hoops than connectors: paste a URL or pick from a catalog, sign-in is automatic (OAuth 2.1 + DCR + PKCE), and an agent loop runs the tools even on models with no native tool calling. Zero dependencies.",
"keywords": [
Expand Down
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ export { toOpenAITools, toolName, buildToolIndex, resolveTool, needsApproval, sl
export { runToolLoop, iterateToolLoop, parseToolCall, normalizeReply, toolPrompt, wrapToolResult } from "./loop.js";
export { CATALOG, makeCatalog, resolvePluginInput, uniqueSlug } from "./catalog.js";
export { sealToken, openToken } from "./seal.js";
export {
MODEL_CAN_BE_WRONG,
FINANCE_CATALOG,
DEFAULT_PLUGINS,
POLICIES,
policyFor,
needsConfirmation,
visibleInMode,
applyPolicy,
describeAction,
redactLog,
} from "./money.js";
Loading
Loading