@advertising-chat/mcp 0.17.3 → 0.18.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 +24 -36
- package/bin/cli.js +1 -1
- package/bin/client.d.ts +5 -2
- package/bin/client.js.map +1 -1
- package/bin/index.d.ts +3 -4
- package/bin/index.js +3 -4
- package/bin/index.js.map +1 -1
- package/bin/routeInventory.d.ts +8 -19
- package/bin/routeInventory.js +2 -61
- package/bin/routeInventory.js.map +1 -1
- package/bin/serve.js +9 -9
- package/bin/serve.js.map +1 -1
- package/bin/server.d.ts +2 -2
- package/bin/server.js +8 -9
- package/bin/server.js.map +1 -1
- package/bin/tool.d.ts +8 -11
- package/bin/tool.js +0 -1
- package/bin/tool.js.map +1 -1
- package/bin/tools/account.js +2 -2
- package/bin/tools/account.js.map +1 -1
- package/bin/tools/decisions.d.ts +8 -1
- package/bin/tools/decisions.js +78 -57
- package/bin/tools/decisions.js.map +1 -1
- package/bin/tools/docs.js +4 -4
- package/bin/tools/docs.js.map +1 -1
- package/bin/tools/index.d.ts +1 -6
- package/bin/tools/index.js +0 -15
- package/bin/tools/index.js.map +1 -1
- package/bin/tools/moments.js +27 -25
- package/bin/tools/moments.js.map +1 -1
- package/bin/tools/network.js +8 -8
- package/bin/tools/network.js.map +1 -1
- package/bin/tools/results.d.ts +0 -1
- package/bin/tools/results.js +7 -23
- package/bin/tools/results.js.map +1 -1
- package/bin/tools/shared.d.ts +5 -7
- package/bin/tools/shared.js +9 -34
- package/bin/tools/shared.js.map +1 -1
- package/bin/version.d.ts +1 -1
- package/bin/version.js +1 -1
- package/package.json +36 -9
- package/bin/tools/attributes.d.ts +0 -10
- package/bin/tools/attributes.js +0 -200
- package/bin/tools/attributes.js.map +0 -1
- package/bin/tools/offers.d.ts +0 -11
- package/bin/tools/offers.js +0 -239
- package/bin/tools/offers.js.map +0 -1
- package/bin/tools/rules.d.ts +0 -9
- package/bin/tools/rules.js +0 -318
- package/bin/tools/rules.js.map +0 -1
- package/bin/tools/settings.d.ts +0 -3
- package/bin/tools/settings.js +0 -54
- package/bin/tools/settings.js.map +0 -1
- package/bin/tools/translation.d.ts +0 -6
- package/bin/tools/translation.js +0 -139
- package/bin/tools/translation.js.map +0 -1
package/bin/tools/attributes.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.attributeTools = exports.deleteAttribute = exports.updateAttribute = exports.documentAttribute = exports.addAttribute = exports.getAttribute = exports.listAttributes = void 0;
|
|
4
|
-
exports.attributeRow = attributeRow;
|
|
5
|
-
/**
|
|
6
|
-
* The attribute catalog: the vocabulary rules are written in. Each agent
|
|
7
|
-
* has its own catalog; a rule can use only attributes in its agent's
|
|
8
|
-
* catalog. The agent platform registers types; marketers document what an
|
|
9
|
-
* attribute means (`document_attribute`). Input schemas come from
|
|
10
|
-
* `@advertising-chat/offer-rules`, the package the server validates with.
|
|
11
|
-
*/
|
|
12
|
-
const offer_rules_1 = require("@advertising-chat/offer-rules");
|
|
13
|
-
const zod_1 = require("zod");
|
|
14
|
-
const tool_1 = require("../tool");
|
|
15
|
-
const shared_1 = require("./shared");
|
|
16
|
-
const A = offer_rules_1.AttributeCreate.shape;
|
|
17
|
-
const U = offer_rules_1.AttributeUpdate.shape;
|
|
18
|
-
const CATALOG = 'https://docs.advertising.chat/reference/catalog/';
|
|
19
|
-
const fields = {
|
|
20
|
-
key: A.key.describe('The attribute key exactly as the agent sends it on fetch requests, e.g. `data_limit_streak_months`. Unique within the agent.'),
|
|
21
|
-
type: A.type.describe('string, number, boolean, date, enum, or list. It decides how values are read and which operators a condition can use; enum needs `values`.'),
|
|
22
|
-
label: A.label.describe('What marketers call it, e.g. "Months at data limit in a row".'),
|
|
23
|
-
description: A.description.describe('What it means and how it is computed, for people and for the Assistant.'),
|
|
24
|
-
values: A.values.describe('For enum only: the allowed values, as { value, label? }.'),
|
|
25
|
-
examples: A.examples.describe('Up to 10 sample values.'),
|
|
26
|
-
source: A.source.describe('Who supplies it: agent (default), context_layer, or data_feed.'),
|
|
27
|
-
};
|
|
28
|
-
/** `the customer detail “Plan” (plan)`, from an entry or an input. */
|
|
29
|
-
function attrName(e) {
|
|
30
|
-
const label = typeof e.label === 'string' && e.label ? e.label : undefined;
|
|
31
|
-
const key = typeof e.key === 'string' && e.key ? e.key : undefined;
|
|
32
|
-
if (label)
|
|
33
|
-
return `the customer detail ${(0, shared_1.quoted)(label, '')}`;
|
|
34
|
-
if (key)
|
|
35
|
-
return `the customer detail “${key}”`;
|
|
36
|
-
return 'this customer detail';
|
|
37
|
-
}
|
|
38
|
-
/** A catalog entry as the list shows it. */
|
|
39
|
-
function attributeRow(e) {
|
|
40
|
-
return {
|
|
41
|
-
id: (0, shared_1.str)(e._id) ?? (0, shared_1.str)(e.id),
|
|
42
|
-
key: e.key,
|
|
43
|
-
type: e.type,
|
|
44
|
-
label: e.label,
|
|
45
|
-
status: e.status,
|
|
46
|
-
values: Array.isArray(e.values)
|
|
47
|
-
? e.values.map((v) => v.value)
|
|
48
|
-
: undefined,
|
|
49
|
-
coverage: typeof e.coverage === 'number' ? e.coverage : undefined,
|
|
50
|
-
lastSeenAt: e.lastSeenAt,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
exports.listAttributes = (0, tool_1.defineTool)({
|
|
54
|
-
name: 'list_attributes',
|
|
55
|
-
title: 'List an agent’s attributes',
|
|
56
|
-
description: `The attribute catalog of one agent: the attributes it sends on fetch requests (or will), with key, type, label, enum values, status (observed: seen but undescribed; documented; retired), coverage (share of the agent's requests in the last 7 days that carry it, 0 to 1), and lastSeenAt. A rule can only use attributes in its agent's catalog, with operators that fit their type; check here before writing an audience or exclusions condition. Reference: ${CATALOG} Maps to GET /system/offer-manager/attributes.`,
|
|
57
|
-
kind: 'read',
|
|
58
|
-
roleFloor: 'viewer',
|
|
59
|
-
capability: 'offer-manager',
|
|
60
|
-
input: {
|
|
61
|
-
application: shared_1.application,
|
|
62
|
-
status: zod_1.z
|
|
63
|
-
.enum(['observed', 'documented', 'retired'])
|
|
64
|
-
.optional()
|
|
65
|
-
.describe('Only entries with this status.'),
|
|
66
|
-
},
|
|
67
|
-
async run({ client }, args) {
|
|
68
|
-
const body = await client.get(`${shared_1.OM}/attributes`, (0, shared_1.defined)(args));
|
|
69
|
-
return (Array.isArray(body) ? body : []).map(attributeRow);
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
exports.getAttribute = (0, tool_1.defineTool)({
|
|
73
|
-
name: 'get_attribute',
|
|
74
|
-
title: 'Get an attribute',
|
|
75
|
-
description: 'One catalog entry with every field, including its description, examples, coverage per moment, who wrote each field (writtenBy: observed, platform, marketer), and the rules whose conditions use it (rulesUsing). Maps to GET /system/offer-manager/attributes/{id}.',
|
|
76
|
-
kind: 'read',
|
|
77
|
-
roleFloor: 'viewer',
|
|
78
|
-
capability: 'offer-manager',
|
|
79
|
-
input: { id: (0, shared_1.id)('attribute') },
|
|
80
|
-
async run({ client }, { id: attributeId }) {
|
|
81
|
-
return client.get(`${shared_1.OM}/attributes/${(0, shared_1.enc)(attributeId)}`);
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
exports.addAttribute = (0, tool_1.defineTool)({
|
|
85
|
-
name: 'add_attribute',
|
|
86
|
-
title: 'Add an attribute',
|
|
87
|
-
description: 'Add an attribute to an agent’s catalog, before or after the agent starts sending it, so rules can use it. The entry is documented. Until the agent sends it, a rule on it matches no one; say so, and say what the agent’s team must send. A key the catalog already has is refused (409); use document_attribute or update_attribute on that entry instead. Maps to POST /system/offer-manager/attributes.',
|
|
88
|
-
kind: 'write',
|
|
89
|
-
roleFloor: 'editor',
|
|
90
|
-
capability: 'offer-manager',
|
|
91
|
-
input: { application: shared_1.application, ...fields },
|
|
92
|
-
approval: args => `Add ${(0, shared_1.quoted)(args.label ?? args.key, 'a detail')} to this agent’s customer details, so offers can use it to choose who sees them. An audience that uses it reaches no one until the agent sends “${args.key}”.`,
|
|
93
|
-
async run({ client }, args) {
|
|
94
|
-
const parsed = offer_rules_1.AttributeCreate.safeParse((0, shared_1.defined)(args));
|
|
95
|
-
if (!parsed.success) {
|
|
96
|
-
throw new shared_1.ToolInputError(`The attribute is not valid:\n${(0, shared_1.issues)(parsed.error)}`);
|
|
97
|
-
}
|
|
98
|
-
return client.post(`${shared_1.OM}/attributes`, parsed.data);
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
const nullable = (s, what) => s.describe(`${what} Pass null to clear yours; the agent platform’s value, if it registered one, shows again.`);
|
|
102
|
-
exports.documentAttribute = (0, tool_1.defineTool)({
|
|
103
|
-
name: 'document_attribute',
|
|
104
|
-
title: 'Document an attribute',
|
|
105
|
-
description: 'Write the marketer’s words on a catalog entry: its label, description, and examples. They are shown over what the agent platform registered, and they are what the console, rule cards, and translations call the attribute. Documenting an observed entry makes it documented. To change how values are read (type, enum values) or retire it, use update_attribute. Maps to PATCH /system/offer-manager/attributes/{id}.',
|
|
106
|
-
kind: 'write',
|
|
107
|
-
roleFloor: 'editor',
|
|
108
|
-
reader: 'get_attribute',
|
|
109
|
-
capability: 'offer-manager',
|
|
110
|
-
input: {
|
|
111
|
-
id: (0, shared_1.id)('attribute'),
|
|
112
|
-
label: nullable(U.label, 'What marketers call it, e.g. "Months at data limit in a row".'),
|
|
113
|
-
description: nullable(U.description, 'What it means and how it is computed, for people and for the Assistant.'),
|
|
114
|
-
examples: nullable(U.examples, 'Up to 10 sample values.'),
|
|
115
|
-
},
|
|
116
|
-
approval: (args, before) => {
|
|
117
|
-
const what = ['label', 'description', 'examples']
|
|
118
|
-
.filter(k => args[k] !== undefined)
|
|
119
|
-
.map(k => (k === 'label' ? 'name' : k));
|
|
120
|
-
const label = typeof args.label === 'string' && args.label !== before?.label
|
|
121
|
-
? ` It will be called ${(0, shared_1.quoted)(args.label, '')}.`
|
|
122
|
-
: '';
|
|
123
|
-
return `Update the ${(0, shared_1.listWords)(what) || 'description'} of ${attrName(before ?? args)}.${label}`;
|
|
124
|
-
},
|
|
125
|
-
async run({ client }, args) {
|
|
126
|
-
const body = (0, shared_1.patchBody)(args);
|
|
127
|
-
const parsed = offer_rules_1.AttributeUpdate.safeParse(body);
|
|
128
|
-
if (!parsed.success) {
|
|
129
|
-
throw new shared_1.ToolInputError(`The change is not valid:\n${(0, shared_1.issues)(parsed.error)}`);
|
|
130
|
-
}
|
|
131
|
-
return client.patch(`${shared_1.OM}/attributes/${(0, shared_1.enc)(args.id)}`, parsed.data);
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
exports.updateAttribute = (0, tool_1.defineTool)({
|
|
135
|
-
name: 'update_attribute',
|
|
136
|
-
title: 'Update an attribute',
|
|
137
|
-
description: 'Change how a catalog entry is read: its type, enum values (null clears them), or source, or its status (documented, or retired so rules can no longer use it). For the label, description, or examples, use document_attribute. A type the agent platform registered cannot change, and a change that would break a saved rule is refused (409, naming the rules). Retiring is allowed while rules use it: get_attribute and the answer list them in rulesUsing; they keep serving as saved, but cannot be saved again until the condition is removed, so name them to the user before retiring. Maps to PATCH /system/offer-manager/attributes/{id}.',
|
|
138
|
-
kind: 'write',
|
|
139
|
-
roleFloor: 'editor',
|
|
140
|
-
reader: 'get_attribute',
|
|
141
|
-
capability: 'offer-manager',
|
|
142
|
-
input: {
|
|
143
|
-
id: (0, shared_1.id)('attribute'),
|
|
144
|
-
type: U.type.describe(fields.type.description ?? ''),
|
|
145
|
-
values: U.values.describe('For enum only: the allowed values, as { value, label? }. null clears them.'),
|
|
146
|
-
source: U.source.describe(fields.source.description ?? ''),
|
|
147
|
-
status: U.status.describe('documented, or retired: rules can no longer use it.'),
|
|
148
|
-
},
|
|
149
|
-
approval: (args, before) => {
|
|
150
|
-
const name = attrName(before ?? args);
|
|
151
|
-
const using = Array.isArray(before?.rulesUsing)
|
|
152
|
-
? before.rulesUsing.length
|
|
153
|
-
: 0;
|
|
154
|
-
if (args.status === 'retired')
|
|
155
|
-
return `Retire ${name}: offers can no longer start using it.${using
|
|
156
|
-
? ` ${using === 1 ? 'One audience uses it; it keeps' : `${using} audiences use it; they keep`} working as saved, but cannot be saved again until the detail is removed from ${using === 1 ? 'it' : 'them'}.`
|
|
157
|
-
: ''}`;
|
|
158
|
-
const what = [];
|
|
159
|
-
if (args.type !== undefined)
|
|
160
|
-
what.push('how its values are read');
|
|
161
|
-
if (args.values !== undefined)
|
|
162
|
-
what.push('its allowed values');
|
|
163
|
-
if (args.source !== undefined)
|
|
164
|
-
what.push('who supplies it');
|
|
165
|
-
if (args.status === 'documented')
|
|
166
|
-
what.push('its status, to documented');
|
|
167
|
-
return `Change ${(0, shared_1.listWords)(what) || 'the settings'} of ${name}.`;
|
|
168
|
-
},
|
|
169
|
-
async run({ client }, args) {
|
|
170
|
-
const body = (0, shared_1.patchBody)(args);
|
|
171
|
-
const parsed = offer_rules_1.AttributeUpdate.safeParse(body);
|
|
172
|
-
if (!parsed.success) {
|
|
173
|
-
throw new shared_1.ToolInputError(`The change is not valid:\n${(0, shared_1.issues)(parsed.error)}`);
|
|
174
|
-
}
|
|
175
|
-
return client.patch(`${shared_1.OM}/attributes/${(0, shared_1.enc)(args.id)}`, parsed.data);
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
exports.deleteAttribute = (0, tool_1.defineTool)({
|
|
179
|
-
name: 'delete_attribute',
|
|
180
|
-
title: 'Delete an attribute',
|
|
181
|
-
description: 'Remove an entry from an agent’s catalog. Refused (409) while a rule uses it; the error names those rules. Prefer retiring it with update_attribute. If the agent still sends the key, it returns as observed. Maps to DELETE /system/offer-manager/attributes/{id}.',
|
|
182
|
-
kind: 'destructive',
|
|
183
|
-
roleFloor: 'editor',
|
|
184
|
-
reader: 'get_attribute',
|
|
185
|
-
capability: 'offer-manager',
|
|
186
|
-
input: { id: (0, shared_1.id)('attribute') },
|
|
187
|
-
approval: (_args, before) => `Remove ${attrName(before ?? {})} from this agent’s customer details. If the agent still sends it, it comes back as seen but not described.`,
|
|
188
|
-
async run({ client }, { id: attributeId }) {
|
|
189
|
-
return client.delete(`${shared_1.OM}/attributes/${(0, shared_1.enc)(attributeId)}`);
|
|
190
|
-
},
|
|
191
|
-
});
|
|
192
|
-
exports.attributeTools = [
|
|
193
|
-
exports.listAttributes,
|
|
194
|
-
exports.getAttribute,
|
|
195
|
-
exports.addAttribute,
|
|
196
|
-
exports.documentAttribute,
|
|
197
|
-
exports.updateAttribute,
|
|
198
|
-
exports.deleteAttribute,
|
|
199
|
-
];
|
|
200
|
-
//# sourceMappingURL=attributes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../src/tools/attributes.ts"],"names":[],"mappings":";;;AAiEA,oCAaC;AA9ED;;;;;;GAMG;AACH,+DAGuC;AACvC,6BAAwB;AACxB,kCAAqC;AACrC,qCAakB;AAElB,MAAM,CAAC,GAAG,6BAAe,CAAC,KAAK,CAAC;AAChC,MAAM,CAAC,GAAG,6BAAe,CAAC,KAAK,CAAC;AAEhC,MAAM,OAAO,GAAG,kDAAkD,CAAC;AAEnE,MAAM,MAAM,GAAG;IACb,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CACjB,8HAA8H,CAC/H;IACD,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CACnB,4IAA4I,CAC7I;IACD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CACrB,+DAA+D,CAChE;IACD,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC,QAAQ,CACjC,yEAAyE,CAC1E;IACD,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CACvB,0DAA0D,CAC3D;IACD,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,yBAAyB,CAAC;IACxD,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CACvB,gEAAgE,CACjE;CACF,CAAC;AAEF,sE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F,CAAC,CAAC;AAEU,QAAA,eAAe,GAAG,IAAA,iBAAU,EAAC;IACxC,IAAI,EAAE,kBAAkB;IACxB,KAAK,EAAE,qBAAqB;IAC5B,WAAW,EACT,qQAAqQ;IACvQ,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE,eAAe;IACvB,UAAU,EAAE,eAAe;IAC3B,KAAK,EAAE,EAAE,EAAE,EAAE,IAAA,WAAE,EAAC,WAAW,CAAC,EAAE;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAC1B,UAAU,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,4GAA4G;IAC9I,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE;QACvC,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,WAAE,eAAe,IAAA,YAAG,EAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC,CAAC;AAEU,QAAA,cAAc,GAAG;IAC5B,sBAAc;IACd,oBAAY;IACZ,oBAAY;IACZ,yBAAiB;IACjB,uBAAe;IACf,uBAAe;CAChB,CAAC"}
|
package/bin/tools/offers.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Doc } from './shared';
|
|
2
|
-
/** An offer as the list shows it. */
|
|
3
|
-
export declare function offerRow(c: Doc): Doc;
|
|
4
|
-
export declare const listOffers: import("../tool").AnyTool;
|
|
5
|
-
export declare const getOffer: import("../tool").AnyTool;
|
|
6
|
-
export declare const createOffer: import("../tool").AnyTool;
|
|
7
|
-
export declare const updateOffer: import("../tool").AnyTool;
|
|
8
|
-
export declare const publishOffer: import("../tool").AnyTool;
|
|
9
|
-
export declare const pauseOffer: import("../tool").AnyTool;
|
|
10
|
-
export declare const deleteOffer: import("../tool").AnyTool;
|
|
11
|
-
export declare const offerTools: import("../tool").AnyTool[];
|
package/bin/tools/offers.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.offerTools = exports.deleteOffer = exports.pauseOffer = exports.publishOffer = exports.updateOffer = exports.createOffer = exports.getOffer = exports.listOffers = void 0;
|
|
4
|
-
exports.offerRow = offerRow;
|
|
5
|
-
/**
|
|
6
|
-
* Offers (the API's creatives): what a customer sees. Offers are an
|
|
7
|
-
* org-wide library that any agent's rules can use. Reads and publishing go
|
|
8
|
-
* through `/offers` (each offer with its status, rules, and last 7 days);
|
|
9
|
-
* the content is written on `/creative`.
|
|
10
|
-
*/
|
|
11
|
-
const offer_rules_1 = require("@advertising-chat/offer-rules");
|
|
12
|
-
const zod_1 = require("zod");
|
|
13
|
-
const flowValidator_1 = require("../flow/flowValidator");
|
|
14
|
-
const flowZod_1 = require("../flow/flowZod");
|
|
15
|
-
const tool_1 = require("../tool");
|
|
16
|
-
const shared_1 = require("./shared");
|
|
17
|
-
const FORMATS = ['Universal', 'Flow'];
|
|
18
|
-
const format = zod_1.z
|
|
19
|
-
.enum(FORMATS)
|
|
20
|
-
.describe('Universal is the card (title, subtitle, image, replies), rendered for each channel: a rich card on RCS, text and a link on SMS, a card on webchat. Flow is a short scripted conversation, served only to agents that ask for flows. The payload variant must match.');
|
|
21
|
-
const payload = zod_1.z
|
|
22
|
-
.object({
|
|
23
|
-
universal: zod_1.z
|
|
24
|
-
.object({
|
|
25
|
-
title: zod_1.z.string(),
|
|
26
|
-
subtitle: zod_1.z.string().optional(),
|
|
27
|
-
imageUrl: zod_1.z.string().optional(),
|
|
28
|
-
altText: zod_1.z.string().optional(),
|
|
29
|
-
})
|
|
30
|
-
.optional()
|
|
31
|
-
.describe('For Universal.'),
|
|
32
|
-
flow: flowZod_1.flowPayload
|
|
33
|
-
.optional()
|
|
34
|
-
.describe('For Flow: the conversation graph, checked against the flow spec before anything is sent.'),
|
|
35
|
-
})
|
|
36
|
-
.describe('The content, in the variant that matches `format`.');
|
|
37
|
-
const actions = zod_1.z
|
|
38
|
-
.array(zod_1.z.object({
|
|
39
|
-
actionType: zod_1.z.enum(['Text', 'Navigate', 'Call']),
|
|
40
|
-
text: zod_1.z.string().optional().describe('The reply or button label.'),
|
|
41
|
-
action: zod_1.z
|
|
42
|
-
.string()
|
|
43
|
-
.describe('The URL for Navigate, the number for Call, the text for Text.'),
|
|
44
|
-
role: zod_1.z
|
|
45
|
-
.enum(offer_rules_1.REPLY_ROLES)
|
|
46
|
-
.optional()
|
|
47
|
-
.describe('What tapping it means: `accept` records an acceptance of the offer, `decline` a decline. History conditions in rules count them.'),
|
|
48
|
-
}))
|
|
49
|
-
.describe('Replies and buttons shown with the offer. Not for Flow.');
|
|
50
|
-
const properties = zod_1.z
|
|
51
|
-
.array(zod_1.z.object({ name: zod_1.z.string(), value: zod_1.z.string() }))
|
|
52
|
-
.describe('Custom name and value pairs returned to the agent with the offer.');
|
|
53
|
-
/** Client-side flow checks, so authoring errors come back before a write. */
|
|
54
|
-
function checkOfferBody(body, isUpdate) {
|
|
55
|
-
const flow = body.payload?.flow;
|
|
56
|
-
if (body.format !== 'Flow' && flow === undefined)
|
|
57
|
-
return;
|
|
58
|
-
if (!isUpdate || body.format === 'Flow') {
|
|
59
|
-
if (flow === undefined)
|
|
60
|
-
throw new shared_1.ToolInputError('A Flow offer needs payload.flow.');
|
|
61
|
-
}
|
|
62
|
-
if (body.payload?.universal)
|
|
63
|
-
throw new shared_1.ToolInputError('A Flow offer carries only payload.flow, no other payload variant.');
|
|
64
|
-
if (body.actions?.length)
|
|
65
|
-
throw new shared_1.ToolInputError('A Flow offer has no top-level actions: its actions are nodes in the graph.');
|
|
66
|
-
if (flow !== undefined) {
|
|
67
|
-
const result = (0, flowValidator_1.validateFlowPayload)(flow);
|
|
68
|
-
if (!result.valid)
|
|
69
|
-
throw new shared_1.ToolInputError(`The flow is invalid; nothing was sent. Fix these and retry:\n- ${result.errors.join('\n- ')}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/** An offer as the list shows it. */
|
|
73
|
-
function offerRow(c) {
|
|
74
|
-
return {
|
|
75
|
-
id: (0, shared_1.str)(c._id) ?? (0, shared_1.str)(c.id),
|
|
76
|
-
name: c.name,
|
|
77
|
-
format: c.format,
|
|
78
|
-
status: c.status,
|
|
79
|
-
title: (0, shared_1.str)(c.payload?.universal?.title),
|
|
80
|
-
rules: Array.isArray(c.rules) ? c.rules.length : undefined,
|
|
81
|
-
last7Days: c.last7Days,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
const STATUS = 'status is draft (never published: no rule uses it yet, or none has been turned on), live (an enabled rule that uses it is within its dates), paused (published before, now off), or ended (every rule’s dates are over)';
|
|
85
|
-
/** The words for an offer's fields, for approval sentences. */
|
|
86
|
-
const OFFER_WORDS = {
|
|
87
|
-
name: 'name',
|
|
88
|
-
format: 'format',
|
|
89
|
-
description: 'description',
|
|
90
|
-
payload: 'content',
|
|
91
|
-
actions: 'replies and buttons',
|
|
92
|
-
properties: 'custom properties',
|
|
93
|
-
};
|
|
94
|
-
/** What a live offer's change means, for approval sentences. */
|
|
95
|
-
function liveNote(before) {
|
|
96
|
-
return before?.status === 'live'
|
|
97
|
-
? ' Customers see the change from the next request.'
|
|
98
|
-
: '';
|
|
99
|
-
}
|
|
100
|
-
exports.listOffers = (0, tool_1.defineTool)({
|
|
101
|
-
name: 'list_offers',
|
|
102
|
-
title: 'List offers',
|
|
103
|
-
description: `The workspace’s offers, each with id, name, format, ${STATUS}, the title, how many rules use it, and last7Days (shown and accepted over the last 7 days in the workspace’s time zone). Any agent’s rules can use any offer. Read one in full with get_offer. Maps to GET /system/offer-manager/offers.`,
|
|
104
|
-
kind: 'read',
|
|
105
|
-
roleFloor: 'viewer',
|
|
106
|
-
capability: 'offer-manager',
|
|
107
|
-
input: {},
|
|
108
|
-
async run({ client }) {
|
|
109
|
-
const body = await client.get(`${shared_1.OM}/offers`);
|
|
110
|
-
return (0, shared_1.rows)(body).map(offerRow);
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
exports.getOffer = (0, tool_1.defineTool)({
|
|
114
|
-
name: 'get_offer',
|
|
115
|
-
title: 'Get an offer',
|
|
116
|
-
description: `One offer with every field: content, replies and their roles, properties, its ${STATUS}, the rules that use it (name, agent, moments, enabled, schedule), and last7Days (shown and accepted). Maps to GET /system/offer-manager/offers/{id}.`,
|
|
117
|
-
kind: 'read',
|
|
118
|
-
roleFloor: 'viewer',
|
|
119
|
-
capability: 'offer-manager',
|
|
120
|
-
input: { id: (0, shared_1.id)('offer') },
|
|
121
|
-
async run({ client }, { id: offerId }) {
|
|
122
|
-
return client.get(`${shared_1.OM}/offers/${(0, shared_1.enc)(offerId)}`);
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
exports.createOffer = (0, tool_1.defineTool)({
|
|
126
|
-
name: 'create_offer',
|
|
127
|
-
title: 'Create an offer',
|
|
128
|
-
description: 'Create an offer as a draft. It appears only through a rule that uses it, so creating it changes nothing a customer sees until a rule uses it and is published. Maps to POST /system/offer-manager/creative.',
|
|
129
|
-
kind: 'write',
|
|
130
|
-
roleFloor: 'editor',
|
|
131
|
-
capability: 'offer-manager',
|
|
132
|
-
input: {
|
|
133
|
-
name: zod_1.z.string().min(1).max(200).describe('Display name.'),
|
|
134
|
-
format,
|
|
135
|
-
description: zod_1.z.string().optional(),
|
|
136
|
-
payload: payload.optional(),
|
|
137
|
-
actions: actions.optional(),
|
|
138
|
-
properties: properties.optional(),
|
|
139
|
-
},
|
|
140
|
-
approval: args => `Create the offer ${(0, shared_1.quoted)(args.name, '')} as a draft. Customers see it only once you choose who sees it and publish it.`,
|
|
141
|
-
async run({ client }, args) {
|
|
142
|
-
const body = (0, shared_1.defined)(args);
|
|
143
|
-
checkOfferBody(body, false);
|
|
144
|
-
return client.post(`${shared_1.OM}/creative`, body);
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
exports.updateOffer = (0, tool_1.defineTool)({
|
|
148
|
-
name: 'update_offer',
|
|
149
|
-
title: 'Update an offer',
|
|
150
|
-
description: 'Change an offer’s content. Only the fields given change; `actions` and `properties` replace the whole list. Customers see the change on the next request through any rule that uses it. Maps to PATCH /system/offer-manager/creative/{id}.',
|
|
151
|
-
kind: 'write',
|
|
152
|
-
roleFloor: 'editor',
|
|
153
|
-
reader: 'get_offer',
|
|
154
|
-
capability: 'offer-manager',
|
|
155
|
-
input: {
|
|
156
|
-
id: (0, shared_1.id)('offer'),
|
|
157
|
-
name: zod_1.z.string().min(1).max(200).optional(),
|
|
158
|
-
format: format.optional(),
|
|
159
|
-
description: zod_1.z.string().optional(),
|
|
160
|
-
payload: payload.optional(),
|
|
161
|
-
actions: actions.optional(),
|
|
162
|
-
properties: properties.optional(),
|
|
163
|
-
},
|
|
164
|
-
approval: (args, before) => {
|
|
165
|
-
const what = (0, shared_1.changedWords)(args, OFFER_WORDS);
|
|
166
|
-
const renamed = args.name && before?.name && args.name !== before.name
|
|
167
|
-
? ` It will be called ${(0, shared_1.quoted)(args.name, '')}.`
|
|
168
|
-
: '';
|
|
169
|
-
const offer = (0, shared_1.named)('offer', before?.name ?? args.name);
|
|
170
|
-
const change = what.length
|
|
171
|
-
? `Change the ${(0, shared_1.listWords)(what)} of ${offer}.`
|
|
172
|
-
: `Change ${offer}.`;
|
|
173
|
-
return `${change}${renamed}${liveNote(before)}`;
|
|
174
|
-
},
|
|
175
|
-
async run({ client }, args) {
|
|
176
|
-
const body = (0, shared_1.patchBody)(args);
|
|
177
|
-
checkOfferBody(body, true);
|
|
178
|
-
return client.patch(`${shared_1.OM}/creative/${(0, shared_1.enc)(args.id)}`, body);
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
/** `its 2 audiences`, from the offer as it stands (an audience is a rule). */
|
|
182
|
-
function audiences(before) {
|
|
183
|
-
const n = Array.isArray(before?.rules) ? before.rules.length : undefined;
|
|
184
|
-
if (n === 1)
|
|
185
|
-
return 'its audience';
|
|
186
|
-
return n === undefined ? 'its audiences' : `its ${n} audiences`;
|
|
187
|
-
}
|
|
188
|
-
exports.publishOffer = (0, tool_1.defineTool)({
|
|
189
|
-
name: 'publish_offer',
|
|
190
|
-
title: 'Publish an offer',
|
|
191
|
-
description: 'Publish an offer: turn on every rule that uses it, so it can appear wherever those rules apply, within their dates. Refused (409) when no rule uses the offer: create one first (create_rule). Returns the offer with its new status. Maps to POST /system/offer-manager/offers/{id}/publish.',
|
|
192
|
-
kind: 'write',
|
|
193
|
-
roleFloor: 'editor',
|
|
194
|
-
reader: 'get_offer',
|
|
195
|
-
capability: 'offer-manager',
|
|
196
|
-
input: { id: (0, shared_1.id)('offer') },
|
|
197
|
-
approval: (_args, before) => `Publish ${(0, shared_1.named)('offer', before?.name)}: it starts showing to ${audiences(before)} from the next request.`,
|
|
198
|
-
async run({ client }, { id: offerId }) {
|
|
199
|
-
return client.post(`${shared_1.OM}/offers/${(0, shared_1.enc)(offerId)}/publish`);
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
exports.pauseOffer = (0, tool_1.defineTool)({
|
|
203
|
-
name: 'pause_offer',
|
|
204
|
-
title: 'Pause an offer',
|
|
205
|
-
description: 'Pause an offer: turn off every rule that uses it, so it stops appearing at once. Undo with publish_offer. Returns the offer with its new status. Maps to POST /system/offer-manager/offers/{id}/pause.',
|
|
206
|
-
kind: 'write',
|
|
207
|
-
roleFloor: 'editor',
|
|
208
|
-
reader: 'get_offer',
|
|
209
|
-
capability: 'offer-manager',
|
|
210
|
-
input: { id: (0, shared_1.id)('offer') },
|
|
211
|
-
approval: (_args, before) => `Pause ${(0, shared_1.named)('offer', before?.name)}: it stops showing to ${audiences(before)} at once.`,
|
|
212
|
-
async run({ client }, { id: offerId }) {
|
|
213
|
-
return client.post(`${shared_1.OM}/offers/${(0, shared_1.enc)(offerId)}/pause`);
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
exports.deleteOffer = (0, tool_1.defineTool)({
|
|
217
|
-
name: 'delete_offer',
|
|
218
|
-
title: 'Delete an offer',
|
|
219
|
-
description: 'Permanently delete an offer in one step: the rules that show only this offer are deleted with it, and it is taken out of rules that rotate it with other offers. Returns what was removed (`rulesDeleted`, `rulesChanged`, and `message`, a sentence to relay). To stop it for now, use pause_offer. Maps to DELETE /system/offer-manager/offers/{id}.',
|
|
220
|
-
kind: 'destructive',
|
|
221
|
-
roleFloor: 'editor',
|
|
222
|
-
reader: 'get_offer',
|
|
223
|
-
capability: 'offer-manager',
|
|
224
|
-
input: { id: (0, shared_1.id)('offer') },
|
|
225
|
-
approval: (_args, before) => `Delete ${(0, shared_1.named)('offer', before?.name)} for good, with the rules that show only it, and take it out of any rotation. This cannot be undone.`,
|
|
226
|
-
async run({ client }, { id: offerId }) {
|
|
227
|
-
return client.delete(`${shared_1.OM}/offers/${(0, shared_1.enc)(offerId)}`);
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
exports.offerTools = [
|
|
231
|
-
exports.listOffers,
|
|
232
|
-
exports.getOffer,
|
|
233
|
-
exports.createOffer,
|
|
234
|
-
exports.updateOffer,
|
|
235
|
-
exports.publishOffer,
|
|
236
|
-
exports.pauseOffer,
|
|
237
|
-
exports.deleteOffer,
|
|
238
|
-
];
|
|
239
|
-
//# sourceMappingURL=offers.js.map
|
package/bin/tools/offers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"offers.js","sourceRoot":"","sources":["../../src/tools/offers.ts"],"names":[],"mappings":";;;AA0GA,4BAUC;AApHD;;;;;GAKG;AACH,+DAA4D;AAC5D,6BAAwB;AACxB,yDAA4D;AAC5D,6CAA8C;AAC9C,kCAAqC;AACrC,qCAckB;AAElB,MAAM,OAAO,GAAG,CAAC,WAAW,EAAE,MAAM,CAAU,CAAC;AAE/C,MAAM,MAAM,GAAG,OAAC;KACb,IAAI,CAAC,OAAO,CAAC;KACb,QAAQ,CACP,qQAAqQ,CACtQ,CAAC;AAEJ,M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AE,MAAM,EAAE,EAAE,CAC1B,UAAU,IAAA,cAAK,EAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,sGAAsG;IAC9I,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE;QACnC,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,WAAE,WAAW,IAAA,YAAG,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC;CACF,CAAC,CAAC;AAEU,QAAA,UAAU,GAAG;IACxB,kBAAU;IACV,gBAAQ;IACR,mBAAW;IACX,mBAAW;IACX,oBAAY;IACZ,kBAAU;IACV,mBAAW;CACZ,CAAC"}
|
package/bin/tools/rules.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Doc } from './shared';
|
|
2
|
-
/** A rule as the list shows it. */
|
|
3
|
-
export declare function ruleRow(r: Doc): Doc;
|
|
4
|
-
export declare const listRules: import("../tool").AnyTool;
|
|
5
|
-
export declare const getRule: import("../tool").AnyTool;
|
|
6
|
-
export declare const createRule: import("../tool").AnyTool;
|
|
7
|
-
export declare const updateRule: import("../tool").AnyTool;
|
|
8
|
-
export declare const deleteRule: import("../tool").AnyTool;
|
|
9
|
-
export declare const ruleTools: import("../tool").AnyTool[];
|