@particle-academy/agent-integrations 0.20.0 → 0.21.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/bridges/catalog.d.cts +150 -0
- package/dist/bridges/catalog.d.ts +150 -0
- package/dist/bridges/features.d.cts +108 -0
- package/dist/bridges/features.d.ts +108 -0
- package/dist/bridges-catalog.cjs +428 -0
- package/dist/bridges-catalog.cjs.map +1 -0
- package/dist/bridges-catalog.js +7 -0
- package/dist/bridges-catalog.js.map +1 -0
- package/dist/bridges-features.cjs +341 -0
- package/dist/bridges-features.cjs.map +1 -0
- package/dist/bridges-features.js +7 -0
- package/dist/bridges-features.js.map +1 -0
- package/dist/chunk-267JS64O.js +308 -0
- package/dist/chunk-267JS64O.js.map +1 -0
- package/dist/chunk-XQZGB4FP.js +221 -0
- package/dist/chunk-XQZGB4FP.js.map +1 -0
- package/dist/index.cjs +519 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/package.json +31 -1
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { ensureUndoToolsRegistered, pushUndoEntry } from './chunk-KJ5AOOV7.js';
|
|
2
|
+
import { wrapToolWithActivity } from './chunk-ULJL53DL.js';
|
|
3
|
+
import { textResult, errorResult } from './chunk-4KAIV6OD.js';
|
|
4
|
+
|
|
5
|
+
// src/bridges/catalog.ts
|
|
6
|
+
var DEFAULT_AGENT = { id: "agent", name: "Agent", color: "#a855f7" };
|
|
7
|
+
var str = (v, fallback = "") => typeof v === "string" ? v : fallback;
|
|
8
|
+
var num = (v, fallback = 0) => typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
9
|
+
function registerCatalogBridge(host, options) {
|
|
10
|
+
const { adapter } = options;
|
|
11
|
+
const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
|
|
12
|
+
const pendingMode = options.pendingMode ?? true;
|
|
13
|
+
const catalogId = adapter.id ?? "catalog";
|
|
14
|
+
const disposers = [];
|
|
15
|
+
ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });
|
|
16
|
+
const target = (elementId, label) => ({
|
|
17
|
+
kind: "custom",
|
|
18
|
+
screenId: adapter.screenId,
|
|
19
|
+
elementId,
|
|
20
|
+
label: label ?? catalogId
|
|
21
|
+
});
|
|
22
|
+
const reg = (name, description, properties, required, handler, resolveTarget) => {
|
|
23
|
+
const wrapped = async (args) => {
|
|
24
|
+
try {
|
|
25
|
+
return await handler(args);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return errorResult(e instanceof Error ? e.message : String(e));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const final = resolveTarget ? wrapToolWithActivity(wrapped, {
|
|
31
|
+
toolName: name,
|
|
32
|
+
agent,
|
|
33
|
+
kind: "custom",
|
|
34
|
+
screenId: adapter.screenId,
|
|
35
|
+
resolveTarget: ({ args }) => resolveTarget(args)
|
|
36
|
+
}) : wrapped;
|
|
37
|
+
disposers.push(
|
|
38
|
+
host.registerTool(
|
|
39
|
+
{ name, description, inputSchema: { type: "object", properties, required, additionalProperties: false } },
|
|
40
|
+
final
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
const guardDestructive = async (action, id, label, hasConfirmArg) => {
|
|
45
|
+
if (!pendingMode) return null;
|
|
46
|
+
if (options.confirm) {
|
|
47
|
+
const ok = await options.confirm({ action, id, label });
|
|
48
|
+
return ok ? null : errorResult(`Declined: ${action} ${id} (human did not confirm).`);
|
|
49
|
+
}
|
|
50
|
+
if (!hasConfirmArg) {
|
|
51
|
+
return errorResult(`${action} is staged (pendingMode). Re-call with confirm:true to apply, or wire a host confirm hook.`);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
reg(
|
|
56
|
+
"catalog_list_products",
|
|
57
|
+
"List products: { id, name, active, lookupKey, priceCount }. Pass withTrashed:true to include soft-deleted.",
|
|
58
|
+
{ withTrashed: { type: "boolean" } },
|
|
59
|
+
[],
|
|
60
|
+
async (args) => {
|
|
61
|
+
const products = await adapter.products.all({ withTrashed: args.withTrashed === true });
|
|
62
|
+
const list = await Promise.all(
|
|
63
|
+
products.map(async (p) => ({
|
|
64
|
+
id: p.id,
|
|
65
|
+
name: p.name,
|
|
66
|
+
active: p.active ?? true,
|
|
67
|
+
lookupKey: p.lookupKey ?? null,
|
|
68
|
+
priceCount: (await adapter.prices.forProduct(p.id)).length
|
|
69
|
+
}))
|
|
70
|
+
);
|
|
71
|
+
return textResult(JSON.stringify(list, null, 2), list);
|
|
72
|
+
},
|
|
73
|
+
false
|
|
74
|
+
);
|
|
75
|
+
reg(
|
|
76
|
+
"catalog_get_product",
|
|
77
|
+
"Read a product's full JSON plus its prices.",
|
|
78
|
+
{ id: { type: "string" }, withTrashed: { type: "boolean" } },
|
|
79
|
+
["id"],
|
|
80
|
+
async (args) => {
|
|
81
|
+
const id = str(args.id);
|
|
82
|
+
const product = await adapter.products.find(id, { withTrashed: args.withTrashed === true });
|
|
83
|
+
if (!product) return errorResult(`No product with id ${id}`);
|
|
84
|
+
const prices = await adapter.prices.forProduct(id, { withTrashed: args.withTrashed === true });
|
|
85
|
+
const out = { product, prices };
|
|
86
|
+
return textResult(JSON.stringify(out, null, 2), out);
|
|
87
|
+
},
|
|
88
|
+
false
|
|
89
|
+
);
|
|
90
|
+
reg(
|
|
91
|
+
"catalog_list_prices",
|
|
92
|
+
"List prices for a product (pass productId), or every price (omit it).",
|
|
93
|
+
{ productId: { type: "string" }, withTrashed: { type: "boolean" } },
|
|
94
|
+
[],
|
|
95
|
+
async (args) => {
|
|
96
|
+
const withTrashed = args.withTrashed === true;
|
|
97
|
+
const prices = args.productId !== void 0 ? await adapter.prices.forProduct(str(args.productId), { withTrashed }) : await adapter.prices.all({ withTrashed });
|
|
98
|
+
const list = prices.map((p) => ({
|
|
99
|
+
id: p.id,
|
|
100
|
+
productId: p.productId,
|
|
101
|
+
currency: p.currency,
|
|
102
|
+
unitAmount: p.unitAmount,
|
|
103
|
+
type: p.type,
|
|
104
|
+
active: p.active ?? true,
|
|
105
|
+
externalId: p.externalId ?? null
|
|
106
|
+
}));
|
|
107
|
+
return textResult(JSON.stringify(list, null, 2), list);
|
|
108
|
+
},
|
|
109
|
+
false
|
|
110
|
+
);
|
|
111
|
+
reg(
|
|
112
|
+
"catalog_create_product",
|
|
113
|
+
"Create a product. `name` is required; id (ULID) is auto-assigned. Returns the created product.",
|
|
114
|
+
{
|
|
115
|
+
name: { type: "string" },
|
|
116
|
+
description: { type: "string" },
|
|
117
|
+
active: { type: "boolean" },
|
|
118
|
+
lookupKey: { type: "string" },
|
|
119
|
+
metadata: { type: "object" }
|
|
120
|
+
},
|
|
121
|
+
["name"],
|
|
122
|
+
async (args) => {
|
|
123
|
+
const name = str(args.name);
|
|
124
|
+
if (!name) return errorResult("name is required.");
|
|
125
|
+
const product = await adapter.createProduct({
|
|
126
|
+
name,
|
|
127
|
+
...args.description !== void 0 ? { description: str(args.description) } : {},
|
|
128
|
+
...args.active !== void 0 ? { active: args.active === true } : {},
|
|
129
|
+
...args.lookupKey !== void 0 ? { lookupKey: str(args.lookupKey) } : {},
|
|
130
|
+
...args.metadata && typeof args.metadata === "object" ? { metadata: args.metadata } : {}
|
|
131
|
+
});
|
|
132
|
+
pushUndoEntry(agent.id, {
|
|
133
|
+
timestamp: Date.now(),
|
|
134
|
+
bridgeId: catalogId,
|
|
135
|
+
action: "catalog_create_product",
|
|
136
|
+
label: `Created product ${product.id} (${product.name})`,
|
|
137
|
+
undo: () => void adapter.products.remove(product.id),
|
|
138
|
+
redo: () => void adapter.createProduct({ ...product })
|
|
139
|
+
});
|
|
140
|
+
return textResult(`Created product ${product.id} (${product.name})`, product);
|
|
141
|
+
},
|
|
142
|
+
(args) => target(void 0, `create product ${str(args.name)}`)
|
|
143
|
+
);
|
|
144
|
+
reg(
|
|
145
|
+
"catalog_create_price",
|
|
146
|
+
"Create a price under a product. unitAmount is integer minor units (cents). type is 'recurring' | 'one_time'.",
|
|
147
|
+
{
|
|
148
|
+
productId: { type: "string" },
|
|
149
|
+
currency: { type: "string", description: "ISO-4217, e.g. 'USD'." },
|
|
150
|
+
unitAmount: { type: "number", description: "Price in cents." },
|
|
151
|
+
type: { type: "string", enum: ["recurring", "one_time"] },
|
|
152
|
+
recurringInterval: { type: "string", description: "'month' | 'year' | \u2026 (recurring only)." },
|
|
153
|
+
nickname: { type: "string" },
|
|
154
|
+
lookupKey: { type: "string" },
|
|
155
|
+
metadata: { type: "object" }
|
|
156
|
+
},
|
|
157
|
+
["productId", "currency", "unitAmount", "type"],
|
|
158
|
+
async (args) => {
|
|
159
|
+
const productId = str(args.productId);
|
|
160
|
+
const product = await adapter.products.find(productId);
|
|
161
|
+
if (!product) return errorResult(`No product with id ${productId}`);
|
|
162
|
+
const type = str(args.type);
|
|
163
|
+
if (type !== "recurring" && type !== "one_time") return errorResult("type must be 'recurring' or 'one_time'.");
|
|
164
|
+
const price = await adapter.createPrice({
|
|
165
|
+
productId,
|
|
166
|
+
currency: str(args.currency),
|
|
167
|
+
unitAmount: num(args.unitAmount),
|
|
168
|
+
type,
|
|
169
|
+
...args.recurringInterval !== void 0 ? { recurringInterval: str(args.recurringInterval) } : {},
|
|
170
|
+
...args.nickname !== void 0 ? { nickname: str(args.nickname) } : {},
|
|
171
|
+
...args.lookupKey !== void 0 ? { lookupKey: str(args.lookupKey) } : {},
|
|
172
|
+
...args.metadata && typeof args.metadata === "object" ? { metadata: args.metadata } : {}
|
|
173
|
+
});
|
|
174
|
+
pushUndoEntry(agent.id, {
|
|
175
|
+
timestamp: Date.now(),
|
|
176
|
+
bridgeId: catalogId,
|
|
177
|
+
action: "catalog_create_price",
|
|
178
|
+
label: `Created price ${price.id} on ${productId}`,
|
|
179
|
+
undo: () => void adapter.prices.remove(price.id),
|
|
180
|
+
redo: () => void adapter.createPrice({ ...price })
|
|
181
|
+
});
|
|
182
|
+
return textResult(`Created ${type} price ${price.id} on ${productId}`, price);
|
|
183
|
+
},
|
|
184
|
+
(args) => target(str(args.productId), `create price on ${str(args.productId)}`)
|
|
185
|
+
);
|
|
186
|
+
reg(
|
|
187
|
+
"catalog_delete_product",
|
|
188
|
+
"Soft-delete a product (preserves financial history). Staged in pendingMode \u2014 pass confirm:true or wire a host confirm hook.",
|
|
189
|
+
{ id: { type: "string" }, confirm: { type: "boolean" } },
|
|
190
|
+
["id"],
|
|
191
|
+
async (args) => {
|
|
192
|
+
const id = str(args.id);
|
|
193
|
+
const product = await adapter.products.find(id, { withTrashed: true });
|
|
194
|
+
if (!product) return errorResult(`No product with id ${id}`);
|
|
195
|
+
const blocked = await guardDestructive("catalog_delete_product", id, product.name, args.confirm === true);
|
|
196
|
+
if (blocked) return blocked;
|
|
197
|
+
const snapshot = { ...product };
|
|
198
|
+
await adapter.products.remove(id);
|
|
199
|
+
pushUndoEntry(agent.id, {
|
|
200
|
+
timestamp: Date.now(),
|
|
201
|
+
bridgeId: catalogId,
|
|
202
|
+
action: "catalog_delete_product",
|
|
203
|
+
label: `Deleted product ${id} (${product.name})`,
|
|
204
|
+
undo: () => void adapter.createProduct({ ...snapshot }),
|
|
205
|
+
redo: () => void adapter.products.remove(id)
|
|
206
|
+
});
|
|
207
|
+
return textResult(`Deleted product ${id}`, { id });
|
|
208
|
+
},
|
|
209
|
+
(args) => target(str(args.id), `delete product ${str(args.id)}`)
|
|
210
|
+
);
|
|
211
|
+
reg(
|
|
212
|
+
"catalog_delete_price",
|
|
213
|
+
"Soft-delete a price (mirrors Stripe archiving). Staged in pendingMode \u2014 pass confirm:true or wire a host confirm hook.",
|
|
214
|
+
{ id: { type: "string" }, confirm: { type: "boolean" } },
|
|
215
|
+
["id"],
|
|
216
|
+
async (args) => {
|
|
217
|
+
const id = str(args.id);
|
|
218
|
+
const price = await adapter.prices.find(id, { withTrashed: true });
|
|
219
|
+
if (!price) return errorResult(`No price with id ${id}`);
|
|
220
|
+
const blocked = await guardDestructive("catalog_delete_price", id, id, args.confirm === true);
|
|
221
|
+
if (blocked) return blocked;
|
|
222
|
+
const snapshot = { ...price };
|
|
223
|
+
await adapter.prices.remove(id);
|
|
224
|
+
pushUndoEntry(agent.id, {
|
|
225
|
+
timestamp: Date.now(),
|
|
226
|
+
bridgeId: catalogId,
|
|
227
|
+
action: "catalog_delete_price",
|
|
228
|
+
label: `Deleted price ${id}`,
|
|
229
|
+
undo: () => void adapter.createPrice({ ...snapshot }),
|
|
230
|
+
redo: () => void adapter.prices.remove(id)
|
|
231
|
+
});
|
|
232
|
+
return textResult(`Deleted price ${id}`, { id });
|
|
233
|
+
},
|
|
234
|
+
(args) => target(str(args.id), `delete price ${str(args.id)}`)
|
|
235
|
+
);
|
|
236
|
+
reg(
|
|
237
|
+
"catalog_sync_product",
|
|
238
|
+
"Push a product + its prices to Stripe (creates/updates the Stripe Product + Prices, stamps external ids).",
|
|
239
|
+
{ id: { type: "string" } },
|
|
240
|
+
["id"],
|
|
241
|
+
async (args) => {
|
|
242
|
+
if (!adapter.syncProductAndPrices) return errorResult("Host did not wire Stripe sync.");
|
|
243
|
+
const id = str(args.id);
|
|
244
|
+
const product = await adapter.products.find(id);
|
|
245
|
+
if (!product) return errorResult(`No product with id ${id}`);
|
|
246
|
+
const synced = await adapter.syncProductAndPrices(product);
|
|
247
|
+
return textResult(`Synced product ${id} to Stripe (${synced.externalId ?? "no external id"})`, synced);
|
|
248
|
+
},
|
|
249
|
+
(args) => target(str(args.id), `sync product ${str(args.id)}`)
|
|
250
|
+
);
|
|
251
|
+
reg(
|
|
252
|
+
"catalog_test_connection",
|
|
253
|
+
"Verify the Stripe connection \u2014 returns { success, message, productCount? }.",
|
|
254
|
+
{},
|
|
255
|
+
[],
|
|
256
|
+
async () => {
|
|
257
|
+
if (!adapter.testConnection) return errorResult("Host did not wire a Stripe connection test.");
|
|
258
|
+
const result = await adapter.testConnection();
|
|
259
|
+
return textResult(JSON.stringify(result, null, 2), result);
|
|
260
|
+
},
|
|
261
|
+
false
|
|
262
|
+
);
|
|
263
|
+
reg(
|
|
264
|
+
"catalog_create_checkout",
|
|
265
|
+
"Build a hosted Stripe Checkout URL for a price. Recurring prices \u2192 subscription; one-time \u2192 payment (pass quantity). Requires the price be synced to Stripe first.",
|
|
266
|
+
{
|
|
267
|
+
priceId: { type: "string" },
|
|
268
|
+
successUrl: { type: "string" },
|
|
269
|
+
cancelUrl: { type: "string" },
|
|
270
|
+
customer: { type: "string", description: "Stripe customer id (optional \u2014 Checkout collects one if omitted)." },
|
|
271
|
+
quantity: { type: "number", description: "One-time checkouts only. Default 1." },
|
|
272
|
+
metadata: { type: "object" }
|
|
273
|
+
},
|
|
274
|
+
["priceId", "successUrl", "cancelUrl"],
|
|
275
|
+
async (args) => {
|
|
276
|
+
const priceId = str(args.priceId);
|
|
277
|
+
const price = await adapter.prices.find(priceId);
|
|
278
|
+
if (!price) return errorResult(`No price with id ${priceId}`);
|
|
279
|
+
const checkoutArgs = {
|
|
280
|
+
successUrl: str(args.successUrl),
|
|
281
|
+
cancelUrl: str(args.cancelUrl),
|
|
282
|
+
...args.customer !== void 0 ? { customer: str(args.customer) } : {},
|
|
283
|
+
...args.metadata && typeof args.metadata === "object" ? { metadata: args.metadata } : {}
|
|
284
|
+
};
|
|
285
|
+
let url;
|
|
286
|
+
if (price.type === "recurring") {
|
|
287
|
+
if (!adapter.getSubscriptionCheckoutUrl) return errorResult("Host did not wire subscription checkout.");
|
|
288
|
+
url = await adapter.getSubscriptionCheckoutUrl(price, checkoutArgs);
|
|
289
|
+
} else {
|
|
290
|
+
if (!adapter.getOneTimeCheckoutUrl) return errorResult("Host did not wire one-time checkout.");
|
|
291
|
+
url = await adapter.getOneTimeCheckoutUrl(price, { ...checkoutArgs, quantity: num(args.quantity, 1) });
|
|
292
|
+
}
|
|
293
|
+
return textResult(url || "(no url)", { priceId, type: price.type, url });
|
|
294
|
+
},
|
|
295
|
+
(args) => target(str(args.priceId), `checkout ${str(args.priceId)}`)
|
|
296
|
+
);
|
|
297
|
+
return {
|
|
298
|
+
id: `catalog:${catalogId}`,
|
|
299
|
+
title: adapter.title ?? "Catalog",
|
|
300
|
+
dispose: () => {
|
|
301
|
+
for (const d of disposers.splice(0)) d();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export { registerCatalogBridge };
|
|
307
|
+
//# sourceMappingURL=chunk-267JS64O.js.map
|
|
308
|
+
//# sourceMappingURL=chunk-267JS64O.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bridges/catalog.ts"],"names":[],"mappings":";;;;;AAkHA,IAAM,gBAAgB,EAAE,EAAA,EAAI,SAAS,IAAA,EAAM,OAAA,EAAS,OAAO,SAAA,EAAU;AAErE,IAAM,GAAA,GAAM,CAAC,CAAA,EAAY,QAAA,GAAW,OAAgB,OAAO,CAAA,KAAM,WAAW,CAAA,GAAI,QAAA;AAChF,IAAM,GAAA,GAAM,CAAC,CAAA,EAAY,QAAA,GAAW,CAAA,KAAe,OAAO,CAAA,KAAM,QAAA,IAAY,MAAA,CAAO,QAAA,CAAS,CAAC,CAAA,GAAI,CAAA,GAAI,QAAA;AAmB9F,SAAS,qBAAA,CAAsB,MAAgB,OAAA,EAAuC;AAC3F,EAAA,MAAM,EAAE,SAAQ,GAAI,OAAA;AACpB,EAAA,MAAM,KAAA,GAAQ,EAAE,GAAG,aAAA,EAAe,GAAI,OAAA,CAAQ,KAAA,IAAS,EAAC,EAAG;AAC3D,EAAA,MAAM,WAAA,GAAc,QAAQ,WAAA,IAAe,IAAA;AAC3C,EAAA,MAAM,SAAA,GAAY,QAAQ,EAAA,IAAM,SAAA;AAChC,EAAA,MAAM,YAA+B,EAAC;AAEtC,EAAA,yBAAA,CAA0B,IAAA,EAAM,EAAE,cAAA,EAAgB,KAAA,CAAM,IAAI,CAAA;AAE5D,EAAA,MAAM,MAAA,GAAS,CAAC,SAAA,E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AS,CAAA,CAAA;AAAA,IACxB,KAAA,EAAO,QAAQ,KAAA,IAAS,SAAA;AAAA,IACxB,SAAS,MAAM;AACb,MAAA,KAAA,MAAW,CAAA,IAAK,SAAA,CAAU,MAAA,CAAO,CAAC,GAAG,CAAA,EAAE;AAAA,IACzC;AAAA,GACF;AACF","file":"chunk-267JS64O.js","sourcesContent":["import { textResult, errorResult } from \"../mcp/server\";\nimport type { ToolHost } from \"../mcp/tool-host\";\nimport type { JsonObject } from \"../mcp/types\";\nimport type { Bridge } from \"./types\";\nimport { wrapToolWithActivity } from \"../presence/wrap-tool-with-activity\";\nimport type { AgentTarget } from \"../presence/types\";\nimport { pushUndoEntry } from \"../undo/undo-stack\";\nimport { ensureUndoToolsRegistered } from \"../undo/undo-tools\";\n\n/**\n * Headless bridge for `@particle-academy/fancy-catalog` — a Stripe catalog with\n * NO UI surface. The adapter exposes the catalog's STORES + operations (not UI\n * getters/setters), and the tools are CRUD over products / prices + checkout +\n * Stripe sync. Mutations still funnel through `wrapToolWithActivity` so presence\n * + undo compose, and the destructive delete is `pendingMode`-gated.\n *\n * The adapter shapes below are STRUCTURAL mirrors of fancy-catalog's public\n * `Catalog` + store interfaces, defined LOCALLY so this bridge builds with the\n * sibling package absent (it's an optional peer). A real `Catalog` instance is\n * assignable to `CatalogBridgeAdapter` with no import — TypeScript is structural.\n */\n\n/** Minimal product shape crossing the MCP wire (mirror of fancy-catalog `Product`). */\nexport type CatalogProduct = {\n id: string;\n name: string;\n description?: string | null;\n active?: boolean;\n lookupKey?: string | null;\n externalId?: string | null;\n metadata?: Record<string, unknown> | null;\n [k: string]: unknown;\n};\n\n/** Minimal price shape crossing the MCP wire (mirror of fancy-catalog `Price`). */\nexport type CatalogPrice = {\n id: string;\n productId: string;\n active?: boolean;\n currency: string;\n unitAmount: number;\n type: \"recurring\" | \"one_time\";\n externalId?: string | null;\n [k: string]: unknown;\n};\n\n/** Common checkout args (mirror of fancy-catalog `CheckoutArgs`). */\nexport type CatalogCheckoutArgs = {\n customer?: string;\n successUrl: string;\n cancelUrl: string;\n metadata?: Record<string, string>;\n /** One-time checkouts only. */\n quantity?: number;\n};\n\n/**\n * Adapter = the catalog instance / stores. A live `Catalog` from fancy-catalog\n * satisfies this directly (`catalog.products`, `catalog.createProduct`, …); a\n * host can also hand-roll one over its own persistence.\n */\nexport type CatalogBridgeAdapter = {\n /** Stable id for this catalog instance (multiple catalogs ⇒ distinct ids). */\n id?: string;\n /** Display label for logs / presence. */\n title?: string;\n /** Optional fancy-screens screen id (usually unset — this is headless). */\n screenId?: string;\n\n /** Product store — `catalog.products`. */\n products: {\n find(id: string, opts?: { withTrashed?: boolean }): CatalogProduct | null | Promise<CatalogProduct | null>;\n all(opts?: { withTrashed?: boolean }): CatalogProduct[] | Promise<CatalogProduct[]>;\n remove(id: string): void | Promise<void>;\n };\n /** Price store — `catalog.prices`. */\n prices: {\n find(id: string, opts?: { withTrashed?: boolean }): CatalogPrice | null | Promise<CatalogPrice | null>;\n forProduct(productId: string, opts?: { withTrashed?: boolean }): CatalogPrice[] | Promise<CatalogPrice[]>;\n all(opts?: { withTrashed?: boolean }): CatalogPrice[] | Promise<CatalogPrice[]>;\n remove(id: string): void | Promise<void>;\n };\n\n /** Authoring helpers — `catalog.createProduct` / `catalog.createPrice` (ULIDs auto-assigned). */\n createProduct(input: Partial<CatalogProduct> & { name: string }): Promise<CatalogProduct> | CatalogProduct;\n createPrice(\n input: Partial<CatalogPrice> & { productId: string; currency: string; unitAmount: number; type: \"recurring\" | \"one_time\" },\n ): Promise<CatalogPrice> | CatalogPrice;\n\n /** Stripe sync — `catalog.syncProductAndPrices`. Optional (no-op when absent). */\n syncProductAndPrices?(product: CatalogProduct): Promise<CatalogProduct> | CatalogProduct;\n /** Connection test — `catalog.testConnection`. Optional. */\n testConnection?(): Promise<{ success: boolean; message: string; productCount?: number }> | { success: boolean; message: string; productCount?: number };\n\n /** Hosted Checkout — `catalog.getSubscriptionCheckoutUrl` / `getOneTimeCheckoutUrl`. Optional. */\n getSubscriptionCheckoutUrl?(price: CatalogPrice, args: CatalogCheckoutArgs): Promise<string> | string;\n getOneTimeCheckoutUrl?(price: CatalogPrice, args: CatalogCheckoutArgs): Promise<string> | string;\n};\n\nexport type CatalogBridgeOptions = {\n adapter: CatalogBridgeAdapter;\n /** Identity stamped on activity + undo entries. */\n agent?: { id: string; name?: string; color?: string };\n /**\n * Trust-but-verify. When on (default), destructive ops (`catalog_delete_product`,\n * `catalog_delete_price`) route through `adapter`-less staging: they require an\n * explicit `confirm: true` arg OR a host `confirm` callback. Read + create +\n * checkout-url tools are unaffected.\n */\n pendingMode?: boolean;\n /** Host confirm hook for destructive ops (pendingMode). Resolves true to proceed. */\n confirm?: (req: { action: string; id: string; label: string }) => Promise<boolean> | boolean;\n};\n\nconst DEFAULT_AGENT = { id: \"agent\", name: \"Agent\", color: \"#a855f7\" };\n\nconst str = (v: unknown, fallback = \"\"): string => (typeof v === \"string\" ? v : fallback);\nconst num = (v: unknown, fallback = 0): number => (typeof v === \"number\" && Number.isFinite(v) ? v : fallback);\n\n/**\n * registerCatalogBridge — full MCP tool set over a headless Stripe catalog.\n *\n * catalog_list_products list products ({ id, name, active, priceCount })\n * catalog_get_product full product JSON + its prices\n * catalog_create_product create a product (ULID auto-assigned)\n * catalog_delete_product soft-delete a product (pendingMode-gated, undoable*)\n * catalog_list_prices list a product's prices (or all)\n * catalog_create_price create a price under a product\n * catalog_delete_price soft-delete a price (pendingMode-gated)\n * catalog_sync_product push a product + its prices to Stripe\n * catalog_test_connection verify the Stripe connection\n * catalog_create_checkout build a hosted Checkout URL for a price\n *\n * *delete undo is best-effort: stores expose soft-delete (`remove`) but no\n * un-delete, so the undo closure re-creates from the captured snapshot.\n */\nexport function registerCatalogBridge(host: ToolHost, options: CatalogBridgeOptions): Bridge {\n const { adapter } = options;\n const agent = { ...DEFAULT_AGENT, ...(options.agent ?? {}) };\n const pendingMode = options.pendingMode ?? true;\n const catalogId = adapter.id ?? \"catalog\";\n const disposers: Array<() => void> = [];\n\n ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });\n\n const target = (elementId?: string, label?: string): AgentTarget => ({\n kind: \"custom\",\n screenId: adapter.screenId,\n elementId,\n label: label ?? catalogId,\n });\n\n const reg = (\n name: string,\n description: string,\n properties: Record<string, unknown>,\n required: string[],\n handler: (args: JsonObject) => Promise<unknown> | unknown,\n resolveTarget: false | ((args: JsonObject) => AgentTarget),\n ) => {\n const wrapped = async (args: JsonObject) => {\n try {\n return await handler(args);\n } catch (e) {\n return errorResult(e instanceof Error ? e.message : String(e));\n }\n };\n const final = resolveTarget\n ? wrapToolWithActivity(wrapped as never, {\n toolName: name,\n agent,\n kind: \"custom\",\n screenId: adapter.screenId,\n resolveTarget: ({ args }) => resolveTarget(args as JsonObject),\n })\n : wrapped;\n disposers.push(\n host.registerTool(\n { name, description, inputSchema: { type: \"object\", properties: properties as Record<string, never>, required, additionalProperties: false } },\n final as never,\n ),\n );\n };\n\n /** Stage a destructive op behind the human (pendingMode). Returns null to proceed, or an errorResult to block. */\n const guardDestructive = async (action: string, id: string, label: string, hasConfirmArg: boolean) => {\n if (!pendingMode) return null;\n if (options.confirm) {\n const ok = await options.confirm({ action, id, label });\n return ok ? null : errorResult(`Declined: ${action} ${id} (human did not confirm).`);\n }\n // No host confirm hook → require an explicit confirm:true arg as the staged ack.\n if (!hasConfirmArg) {\n return errorResult(`${action} is staged (pendingMode). Re-call with confirm:true to apply, or wire a host confirm hook.`);\n }\n return null;\n };\n\n // ─── Read tools ──────────────────────────────────────────────────────────\n\n reg(\n \"catalog_list_products\",\n \"List products: { id, name, active, lookupKey, priceCount }. Pass withTrashed:true to include soft-deleted.\",\n { withTrashed: { type: \"boolean\" } },\n [],\n async (args) => {\n const products = await adapter.products.all({ withTrashed: args.withTrashed === true });\n const list = await Promise.all(\n products.map(async (p) => ({\n id: p.id,\n name: p.name,\n active: p.active ?? true,\n lookupKey: p.lookupKey ?? null,\n priceCount: (await adapter.prices.forProduct(p.id)).length,\n })),\n );\n return textResult(JSON.stringify(list, null, 2), list);\n },\n false,\n );\n\n reg(\n \"catalog_get_product\",\n \"Read a product's full JSON plus its prices.\",\n { id: { type: \"string\" }, withTrashed: { type: \"boolean\" } },\n [\"id\"],\n async (args) => {\n const id = str(args.id);\n const product = await adapter.products.find(id, { withTrashed: args.withTrashed === true });\n if (!product) return errorResult(`No product with id ${id}`);\n const prices = await adapter.prices.forProduct(id, { withTrashed: args.withTrashed === true });\n const out = { product, prices };\n return textResult(JSON.stringify(out, null, 2), out);\n },\n false,\n );\n\n reg(\n \"catalog_list_prices\",\n \"List prices for a product (pass productId), or every price (omit it).\",\n { productId: { type: \"string\" }, withTrashed: { type: \"boolean\" } },\n [],\n async (args) => {\n const withTrashed = args.withTrashed === true;\n const prices = args.productId !== undefined\n ? await adapter.prices.forProduct(str(args.productId), { withTrashed })\n : await adapter.prices.all({ withTrashed });\n const list = prices.map((p) => ({\n id: p.id,\n productId: p.productId,\n currency: p.currency,\n unitAmount: p.unitAmount,\n type: p.type,\n active: p.active ?? true,\n externalId: p.externalId ?? null,\n }));\n return textResult(JSON.stringify(list, null, 2), list);\n },\n false,\n );\n\n // ─── Create tools ────────────────────────────────────────────────────────\n\n reg(\n \"catalog_create_product\",\n \"Create a product. `name` is required; id (ULID) is auto-assigned. Returns the created product.\",\n {\n name: { type: \"string\" },\n description: { type: \"string\" },\n active: { type: \"boolean\" },\n lookupKey: { type: \"string\" },\n metadata: { type: \"object\" },\n },\n [\"name\"],\n async (args) => {\n const name = str(args.name);\n if (!name) return errorResult(\"name is required.\");\n const product = await adapter.createProduct({\n name,\n ...(args.description !== undefined ? { description: str(args.description) } : {}),\n ...(args.active !== undefined ? { active: args.active === true } : {}),\n ...(args.lookupKey !== undefined ? { lookupKey: str(args.lookupKey) } : {}),\n ...(args.metadata && typeof args.metadata === \"object\" ? { metadata: args.metadata as Record<string, unknown> } : {}),\n });\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: catalogId,\n action: \"catalog_create_product\",\n label: `Created product ${product.id} (${product.name})`,\n undo: () => void adapter.products.remove(product.id),\n redo: () => void adapter.createProduct({ ...product }),\n });\n return textResult(`Created product ${product.id} (${product.name})`, product);\n },\n (args) => target(undefined, `create product ${str(args.name)}`),\n );\n\n reg(\n \"catalog_create_price\",\n \"Create a price under a product. unitAmount is integer minor units (cents). type is 'recurring' | 'one_time'.\",\n {\n productId: { type: \"string\" },\n currency: { type: \"string\", description: \"ISO-4217, e.g. 'USD'.\" },\n unitAmount: { type: \"number\", description: \"Price in cents.\" },\n type: { type: \"string\", enum: [\"recurring\", \"one_time\"] },\n recurringInterval: { type: \"string\", description: \"'month' | 'year' | … (recurring only).\" },\n nickname: { type: \"string\" },\n lookupKey: { type: \"string\" },\n metadata: { type: \"object\" },\n },\n [\"productId\", \"currency\", \"unitAmount\", \"type\"],\n async (args) => {\n const productId = str(args.productId);\n const product = await adapter.products.find(productId);\n if (!product) return errorResult(`No product with id ${productId}`);\n const type = str(args.type) as \"recurring\" | \"one_time\";\n if (type !== \"recurring\" && type !== \"one_time\") return errorResult(\"type must be 'recurring' or 'one_time'.\");\n const price = await adapter.createPrice({\n productId,\n currency: str(args.currency),\n unitAmount: num(args.unitAmount),\n type,\n ...(args.recurringInterval !== undefined ? { recurringInterval: str(args.recurringInterval) } : {}),\n ...(args.nickname !== undefined ? { nickname: str(args.nickname) } : {}),\n ...(args.lookupKey !== undefined ? { lookupKey: str(args.lookupKey) } : {}),\n ...(args.metadata && typeof args.metadata === \"object\" ? { metadata: args.metadata as Record<string, unknown> } : {}),\n });\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: catalogId,\n action: \"catalog_create_price\",\n label: `Created price ${price.id} on ${productId}`,\n undo: () => void adapter.prices.remove(price.id),\n redo: () => void adapter.createPrice({ ...price }),\n });\n return textResult(`Created ${type} price ${price.id} on ${productId}`, price);\n },\n (args) => target(str(args.productId), `create price on ${str(args.productId)}`),\n );\n\n // ─── Destructive tools (pendingMode-gated) ───────────────────────────────\n\n reg(\n \"catalog_delete_product\",\n \"Soft-delete a product (preserves financial history). Staged in pendingMode — pass confirm:true or wire a host confirm hook.\",\n { id: { type: \"string\" }, confirm: { type: \"boolean\" } },\n [\"id\"],\n async (args) => {\n const id = str(args.id);\n const product = await adapter.products.find(id, { withTrashed: true });\n if (!product) return errorResult(`No product with id ${id}`);\n const blocked = await guardDestructive(\"catalog_delete_product\", id, product.name, args.confirm === true);\n if (blocked) return blocked;\n const snapshot = { ...product };\n await adapter.products.remove(id);\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: catalogId,\n action: \"catalog_delete_product\",\n label: `Deleted product ${id} (${product.name})`,\n undo: () => void adapter.createProduct({ ...snapshot }),\n redo: () => void adapter.products.remove(id),\n });\n return textResult(`Deleted product ${id}`, { id });\n },\n (args) => target(str(args.id), `delete product ${str(args.id)}`),\n );\n\n reg(\n \"catalog_delete_price\",\n \"Soft-delete a price (mirrors Stripe archiving). Staged in pendingMode — pass confirm:true or wire a host confirm hook.\",\n { id: { type: \"string\" }, confirm: { type: \"boolean\" } },\n [\"id\"],\n async (args) => {\n const id = str(args.id);\n const price = await adapter.prices.find(id, { withTrashed: true });\n if (!price) return errorResult(`No price with id ${id}`);\n const blocked = await guardDestructive(\"catalog_delete_price\", id, id, args.confirm === true);\n if (blocked) return blocked;\n const snapshot = { ...price };\n await adapter.prices.remove(id);\n pushUndoEntry(agent.id, {\n timestamp: Date.now(),\n bridgeId: catalogId,\n action: \"catalog_delete_price\",\n label: `Deleted price ${id}`,\n undo: () => void adapter.createPrice({ ...snapshot }),\n redo: () => void adapter.prices.remove(id),\n });\n return textResult(`Deleted price ${id}`, { id });\n },\n (args) => target(str(args.id), `delete price ${str(args.id)}`),\n );\n\n // ─── Stripe sync ─────────────────────────────────────────────────────────\n\n reg(\n \"catalog_sync_product\",\n \"Push a product + its prices to Stripe (creates/updates the Stripe Product + Prices, stamps external ids).\",\n { id: { type: \"string\" } },\n [\"id\"],\n async (args) => {\n if (!adapter.syncProductAndPrices) return errorResult(\"Host did not wire Stripe sync.\");\n const id = str(args.id);\n const product = await adapter.products.find(id);\n if (!product) return errorResult(`No product with id ${id}`);\n const synced = await adapter.syncProductAndPrices(product);\n return textResult(`Synced product ${id} to Stripe (${synced.externalId ?? \"no external id\"})`, synced);\n },\n (args) => target(str(args.id), `sync product ${str(args.id)}`),\n );\n\n reg(\n \"catalog_test_connection\",\n \"Verify the Stripe connection — returns { success, message, productCount? }.\",\n {},\n [],\n async () => {\n if (!adapter.testConnection) return errorResult(\"Host did not wire a Stripe connection test.\");\n const result = await adapter.testConnection();\n return textResult(JSON.stringify(result, null, 2), result);\n },\n false,\n );\n\n // ─── Checkout ────────────────────────────────────────────────────────────\n\n reg(\n \"catalog_create_checkout\",\n \"Build a hosted Stripe Checkout URL for a price. Recurring prices → subscription; one-time → payment (pass quantity). Requires the price be synced to Stripe first.\",\n {\n priceId: { type: \"string\" },\n successUrl: { type: \"string\" },\n cancelUrl: { type: \"string\" },\n customer: { type: \"string\", description: \"Stripe customer id (optional — Checkout collects one if omitted).\" },\n quantity: { type: \"number\", description: \"One-time checkouts only. Default 1.\" },\n metadata: { type: \"object\" },\n },\n [\"priceId\", \"successUrl\", \"cancelUrl\"],\n async (args) => {\n const priceId = str(args.priceId);\n const price = await adapter.prices.find(priceId);\n if (!price) return errorResult(`No price with id ${priceId}`);\n const checkoutArgs: CatalogCheckoutArgs = {\n successUrl: str(args.successUrl),\n cancelUrl: str(args.cancelUrl),\n ...(args.customer !== undefined ? { customer: str(args.customer) } : {}),\n ...(args.metadata && typeof args.metadata === \"object\" ? { metadata: args.metadata as Record<string, string> } : {}),\n };\n let url: string;\n if (price.type === \"recurring\") {\n if (!adapter.getSubscriptionCheckoutUrl) return errorResult(\"Host did not wire subscription checkout.\");\n url = await adapter.getSubscriptionCheckoutUrl(price, checkoutArgs);\n } else {\n if (!adapter.getOneTimeCheckoutUrl) return errorResult(\"Host did not wire one-time checkout.\");\n url = await adapter.getOneTimeCheckoutUrl(price, { ...checkoutArgs, quantity: num(args.quantity, 1) });\n }\n return textResult(url || \"(no url)\", { priceId, type: price.type, url });\n },\n (args) => target(str(args.priceId), `checkout ${str(args.priceId)}`),\n );\n\n return {\n id: `catalog:${catalogId}`,\n title: adapter.title ?? \"Catalog\",\n dispose: () => {\n for (const d of disposers.splice(0)) d();\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { ensureUndoToolsRegistered, pushUndoEntry } from './chunk-KJ5AOOV7.js';
|
|
2
|
+
import { wrapToolWithActivity } from './chunk-ULJL53DL.js';
|
|
3
|
+
import { textResult, errorResult } from './chunk-4KAIV6OD.js';
|
|
4
|
+
|
|
5
|
+
// src/bridges/features.ts
|
|
6
|
+
var DEFAULT_AGENT = { id: "agent", name: "Agent", color: "#a855f7" };
|
|
7
|
+
var str = (v, fallback = "") => typeof v === "string" ? v : fallback;
|
|
8
|
+
var num = (v, fallback = 0) => typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
9
|
+
function registerFeaturesBridge(host, options) {
|
|
10
|
+
const { adapter } = options;
|
|
11
|
+
const agent = { ...DEFAULT_AGENT, ...options.agent ?? {} };
|
|
12
|
+
const pendingMode = options.pendingMode ?? true;
|
|
13
|
+
const featuresId = adapter.id ?? "features";
|
|
14
|
+
const disposers = [];
|
|
15
|
+
ensureUndoToolsRegistered(host, { defaultAgentId: agent.id });
|
|
16
|
+
const target = (elementId, label) => ({
|
|
17
|
+
kind: "custom",
|
|
18
|
+
screenId: adapter.screenId,
|
|
19
|
+
elementId,
|
|
20
|
+
label: label ?? featuresId
|
|
21
|
+
});
|
|
22
|
+
const reg = (name, description, properties, required, handler, resolveTarget) => {
|
|
23
|
+
const wrapped = async (args) => {
|
|
24
|
+
try {
|
|
25
|
+
return await handler(args);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return errorResult(e instanceof Error ? e.message : String(e));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const final = resolveTarget ? wrapToolWithActivity(wrapped, {
|
|
31
|
+
toolName: name,
|
|
32
|
+
agent,
|
|
33
|
+
kind: "custom",
|
|
34
|
+
screenId: adapter.screenId,
|
|
35
|
+
resolveTarget: ({ args }) => resolveTarget(args)
|
|
36
|
+
}) : wrapped;
|
|
37
|
+
disposers.push(
|
|
38
|
+
host.registerTool(
|
|
39
|
+
{ name, description, inputSchema: { type: "object", properties, required, additionalProperties: false } },
|
|
40
|
+
final
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
const guardGrant = async (action, subject, groupKey, hasConfirmArg) => {
|
|
45
|
+
if (!pendingMode) return null;
|
|
46
|
+
if (options.confirm) {
|
|
47
|
+
const ok = await options.confirm({ action, subject, groupKey });
|
|
48
|
+
return ok ? null : errorResult(`Declined: ${action} ${groupKey} (human did not confirm).`);
|
|
49
|
+
}
|
|
50
|
+
if (!hasConfirmArg) {
|
|
51
|
+
return errorResult(`${action} is staged (pendingMode). Re-call with confirm:true to apply, or wire a host confirm hook.`);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
reg(
|
|
56
|
+
"features_list",
|
|
57
|
+
"List the feature keys enabled for a subject. Pass `subject` (a string id or object).",
|
|
58
|
+
{ subject: { description: "Opaque subject \u2014 string id or { id, \u2026 } object." }, context: { description: "Optional resolution context." } },
|
|
59
|
+
[],
|
|
60
|
+
async (args) => {
|
|
61
|
+
const keys = await adapter.enabled(args.subject, args.context);
|
|
62
|
+
return textResult(JSON.stringify(keys, null, 2), { subject: args.subject, enabled: keys });
|
|
63
|
+
},
|
|
64
|
+
false
|
|
65
|
+
);
|
|
66
|
+
reg(
|
|
67
|
+
"features_check",
|
|
68
|
+
"Check whether a subject can access a feature. For resource features also returns the remaining quota.",
|
|
69
|
+
{ feature: { type: "string" }, subject: { description: "Opaque subject." }, context: { description: "Optional context." } },
|
|
70
|
+
["feature"],
|
|
71
|
+
async (args) => {
|
|
72
|
+
const feature = str(args.feature);
|
|
73
|
+
const allowed = await adapter.canAccess(feature, args.subject, args.context);
|
|
74
|
+
const remaining = await adapter.remaining(feature, args.subject, args.context);
|
|
75
|
+
const out = { feature, allowed, remaining };
|
|
76
|
+
return textResult(JSON.stringify(out), out);
|
|
77
|
+
},
|
|
78
|
+
false
|
|
79
|
+
);
|
|
80
|
+
reg(
|
|
81
|
+
"features_explain",
|
|
82
|
+
"Trace why a feature is on/off for a subject \u2014 returns the AccessResult (source, remaining, limit, used).",
|
|
83
|
+
{ feature: { type: "string" }, subject: { description: "Opaque subject." }, context: { description: "Optional context." } },
|
|
84
|
+
["feature"],
|
|
85
|
+
async (args) => {
|
|
86
|
+
if (!adapter.explain) return errorResult("Host did not wire explain().");
|
|
87
|
+
const result = await adapter.explain(str(args.feature), args.subject, args.context);
|
|
88
|
+
return textResult(JSON.stringify(result, null, 2), result);
|
|
89
|
+
},
|
|
90
|
+
false
|
|
91
|
+
);
|
|
92
|
+
reg(
|
|
93
|
+
"features_groups",
|
|
94
|
+
"List the feature groups a subject is assigned to.",
|
|
95
|
+
{ subject: { description: "Opaque subject." } },
|
|
96
|
+
["subject"],
|
|
97
|
+
async (args) => {
|
|
98
|
+
const groups = await adapter.listGroups(args.subject);
|
|
99
|
+
return textResult(JSON.stringify(groups, null, 2), { subject: args.subject, groups });
|
|
100
|
+
},
|
|
101
|
+
false
|
|
102
|
+
);
|
|
103
|
+
reg(
|
|
104
|
+
"features_define",
|
|
105
|
+
"Register a feature definition. type 'boolean' (on/off) or 'resource' (metered with a `limit`). `enabled` sets the default gate.",
|
|
106
|
+
{
|
|
107
|
+
key: { type: "string" },
|
|
108
|
+
name: { type: "string" },
|
|
109
|
+
description: { type: "string" },
|
|
110
|
+
type: { type: "string", enum: ["boolean", "resource"] },
|
|
111
|
+
enabled: { type: "boolean" },
|
|
112
|
+
limit: { type: "number", description: "Resource quota per period (resource type)." }
|
|
113
|
+
},
|
|
114
|
+
["key"],
|
|
115
|
+
(args) => {
|
|
116
|
+
const key = str(args.key);
|
|
117
|
+
if (!key) return errorResult("key is required.");
|
|
118
|
+
const existed = adapter.registryKeys().includes(key);
|
|
119
|
+
const definition = {
|
|
120
|
+
...args.name !== void 0 ? { name: str(args.name) } : {},
|
|
121
|
+
...args.description !== void 0 ? { description: str(args.description) } : {},
|
|
122
|
+
...args.type !== void 0 ? { type: str(args.type) } : {},
|
|
123
|
+
...args.enabled !== void 0 ? { enabled: args.enabled === true } : {},
|
|
124
|
+
...args.limit !== void 0 ? { limit: num(args.limit) } : {}
|
|
125
|
+
};
|
|
126
|
+
adapter.registerFeature(key, definition);
|
|
127
|
+
pushUndoEntry(agent.id, {
|
|
128
|
+
timestamp: Date.now(),
|
|
129
|
+
bridgeId: featuresId,
|
|
130
|
+
action: "features_define",
|
|
131
|
+
// Registry has no unregister; undo re-registers the prior definition when we had one.
|
|
132
|
+
label: existed ? `Redefined feature ${key}` : `Defined feature ${key}`,
|
|
133
|
+
undo: () => {
|
|
134
|
+
},
|
|
135
|
+
redo: () => adapter.registerFeature(key, definition)
|
|
136
|
+
});
|
|
137
|
+
return textResult(`${existed ? "Redefined" : "Defined"} feature ${key} (${definition.type ?? "boolean"})`, { key, definition });
|
|
138
|
+
},
|
|
139
|
+
(args) => target(str(args.key), `define ${str(args.key)}`)
|
|
140
|
+
);
|
|
141
|
+
reg(
|
|
142
|
+
"features_grant",
|
|
143
|
+
"Grant a subject access by assigning it to a feature group. Staged in pendingMode \u2014 pass confirm:true or wire a host confirm hook.",
|
|
144
|
+
{ subject: { description: "Opaque subject." }, group: { type: "string", description: "Feature group key." }, confirm: { type: "boolean" } },
|
|
145
|
+
["subject", "group"],
|
|
146
|
+
async (args) => {
|
|
147
|
+
const groupKey = str(args.group);
|
|
148
|
+
if (!groupKey) return errorResult("group is required.");
|
|
149
|
+
const blocked = await guardGrant("features_grant", args.subject, groupKey, args.confirm === true);
|
|
150
|
+
if (blocked) return blocked;
|
|
151
|
+
const already = (await adapter.listGroups(args.subject)).includes(groupKey);
|
|
152
|
+
await adapter.assignGroup(args.subject, groupKey);
|
|
153
|
+
pushUndoEntry(agent.id, {
|
|
154
|
+
timestamp: Date.now(),
|
|
155
|
+
bridgeId: featuresId,
|
|
156
|
+
action: "features_grant",
|
|
157
|
+
label: `Granted group ${groupKey}`,
|
|
158
|
+
// Only reverse if WE added it (idempotent assign — don't revoke a pre-existing grant).
|
|
159
|
+
undo: () => {
|
|
160
|
+
if (!already) void adapter.detachGroup(args.subject, groupKey);
|
|
161
|
+
},
|
|
162
|
+
redo: () => void adapter.assignGroup(args.subject, groupKey)
|
|
163
|
+
});
|
|
164
|
+
return textResult(`Granted group ${groupKey}`, { subject: args.subject, group: groupKey });
|
|
165
|
+
},
|
|
166
|
+
(args) => target(str(args.group), `grant ${str(args.group)}`)
|
|
167
|
+
);
|
|
168
|
+
reg(
|
|
169
|
+
"features_revoke",
|
|
170
|
+
"Revoke access by detaching a subject from a feature group. Staged in pendingMode \u2014 pass confirm:true or wire a host confirm hook.",
|
|
171
|
+
{ subject: { description: "Opaque subject." }, group: { type: "string" }, confirm: { type: "boolean" } },
|
|
172
|
+
["subject", "group"],
|
|
173
|
+
async (args) => {
|
|
174
|
+
const groupKey = str(args.group);
|
|
175
|
+
if (!groupKey) return errorResult("group is required.");
|
|
176
|
+
const blocked = await guardGrant("features_revoke", args.subject, groupKey, args.confirm === true);
|
|
177
|
+
if (blocked) return blocked;
|
|
178
|
+
const had = (await adapter.listGroups(args.subject)).includes(groupKey);
|
|
179
|
+
await adapter.detachGroup(args.subject, groupKey);
|
|
180
|
+
pushUndoEntry(agent.id, {
|
|
181
|
+
timestamp: Date.now(),
|
|
182
|
+
bridgeId: featuresId,
|
|
183
|
+
action: "features_revoke",
|
|
184
|
+
label: `Revoked group ${groupKey}`,
|
|
185
|
+
undo: () => {
|
|
186
|
+
if (had) void adapter.assignGroup(args.subject, groupKey);
|
|
187
|
+
},
|
|
188
|
+
redo: () => void adapter.detachGroup(args.subject, groupKey)
|
|
189
|
+
});
|
|
190
|
+
return textResult(`Revoked group ${groupKey}`, { subject: args.subject, group: groupKey });
|
|
191
|
+
},
|
|
192
|
+
(args) => target(str(args.group), `revoke ${str(args.group)}`)
|
|
193
|
+
);
|
|
194
|
+
reg(
|
|
195
|
+
"features_consume",
|
|
196
|
+
"Meter a resource feature: atomic check-and-increment. Returns ok:false if the quota would be exceeded (nothing recorded).",
|
|
197
|
+
{ feature: { type: "string" }, subject: { description: "Opaque subject." }, amount: { type: "number", description: "Units to consume. Default 1." }, context: { description: "Optional context." } },
|
|
198
|
+
["feature", "subject"],
|
|
199
|
+
async (args) => {
|
|
200
|
+
if (!adapter.tryConsume) return errorResult("Host did not wire usage metering (tryConsume).");
|
|
201
|
+
const feature = str(args.feature);
|
|
202
|
+
const amount = num(args.amount, 1);
|
|
203
|
+
const ok = await adapter.tryConsume(feature, args.subject, amount, args.context);
|
|
204
|
+
const remaining = await adapter.remaining(feature, args.subject, args.context);
|
|
205
|
+
const out = { feature, ok, amount, remaining };
|
|
206
|
+
return textResult(JSON.stringify(out), out);
|
|
207
|
+
},
|
|
208
|
+
(args) => target(str(args.feature), `consume ${str(args.feature)}`)
|
|
209
|
+
);
|
|
210
|
+
return {
|
|
211
|
+
id: `features:${featuresId}`,
|
|
212
|
+
title: adapter.title ?? "Features",
|
|
213
|
+
dispose: () => {
|
|
214
|
+
for (const d of disposers.splice(0)) d();
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export { registerFeaturesBridge };
|
|
220
|
+
//# sourceMappingURL=chunk-XQZGB4FP.js.map
|
|
221
|
+
//# sourceMappingURL=chunk-XQZGB4FP.js.map
|