@winning-sales/nexo 0.8.0 → 0.9.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 +35 -0
- package/assets/docs/pages.json +1 -1
- package/assets/skills/nexo-automations/SKILL.md +4 -0
- package/dist/commands/brain.js +16 -1
- package/dist/commands/context-company.js +137 -0
- package/dist/commands/knowledge.js +261 -0
- package/dist/program-brain.js +1 -0
- package/dist/program-context.js +61 -0
- package/dist/program-knowledge.js +130 -0
- package/dist/program.js +8 -1
- package/dist/tools/tool-manifest.js +17 -0
- package/package.json +1 -1
- package/reference.json +643 -1
|
@@ -33,6 +33,10 @@ Além dos gatilhos de cada registro, três gatilhos escutam **qualquer entidade*
|
|
|
33
33
|
|
|
34
34
|
`crm.chegada.registrada` dispara a cada chegada de uma pessoa no Nexo, de qualquer fonte, e roda sobre o lead da chegada ou, com `{ "subject": "contact" }` na `config`, sobre o contato em que ela caiu sem abrir lead. A condição e o texto leem os campos da chegada que disparou, só nesta regra: `chegada.fonte`, `chegada.sistema`, `chegada.conector`, `chegada.campanha`, `chegada.anuncio`, `chegada.formulario`, `chegada.utm_source`, `chegada.utm_medium`, `chegada.utm_campaign`, `chegada.utm_term`, `chegada.utm_content`, `chegada.url_entrada`, `chegada.hora` e `chegada.desfecho` (`nexo automations catalog --json` os lista). `chegada.sistema` é o identificador do sistema do catálogo do Connect a que o conector está ligado, em minúsculas; sem sistema ligado ele fica vazio, e a condição é por `chegada.conector`. Sob qualquer outro gatilho esses campos chegam vazios, e a conferência recusa, com o motivo em português, a condição que compara um campo `chegada.*` com um texto sob outro gatilho (as outras comparações não são conferidas: confira você o gatilho). Um pedido que junta o outro sistema e o aviso (conector com webhook que cria o lead com origem, depois esta regra) são dois passos com o sim da pessoa em cada um: o conector primeiro (`nexo-connect`), a regra depois. Campo de chegada que o catálogo não traz não existe: diga isso à pessoa em vez de trocar por outro.
|
|
35
35
|
|
|
36
|
+
## SDR ativo: WhatsApp ou e-mail pelo fluxo
|
|
37
|
+
|
|
38
|
+
O canal do lead é escolha do fluxo, não do agente, e usar o condicional é decisão da pessoa: não o ponha em regra que ela não pediu. `agente.sdr.abordar` só envia por WhatsApp; um lead sem telefone nesse passo falha na execução (nada é enviado). Exemplo opcional, só se a pessoa quiser: para o lead que pode chegar só com e-mail, a regra pode ter antes uma `condition` com `lead.telefone` `is_not_empty`: o ramo com telefone vai para `agente.sdr.abordar`, e o `elseBranch` para `mensagem.enviar.email` com um modelo de e-mail. O e-mail não abre prospecção do SDR. Os dois envios saem sozinhos: diga isso antes de publicar.
|
|
39
|
+
|
|
36
40
|
## O ciclo
|
|
37
41
|
|
|
38
42
|
1. **Catálogo primeiro.** `nexo automations catalog` (e `--json` para os campos de cada registro, as comparações e os limites). Use só `kind` que estiver lá, com a `config` do `configHint`. Não invente.
|
package/dist/commands/brain.js
CHANGED
|
@@ -53,15 +53,30 @@ function required(value, flag) {
|
|
|
53
53
|
}
|
|
54
54
|
return value;
|
|
55
55
|
}
|
|
56
|
+
const AGENT_ROLE_MOMENT = 'attendance_agent_turn';
|
|
57
|
+
function agentRoleOf(value, moment) {
|
|
58
|
+
if (value === undefined) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
if (value !== 'sdr' && value !== 'cs') {
|
|
62
|
+
throw usageError('--agent-role aceita sdr (o padrão) ou cs.');
|
|
63
|
+
}
|
|
64
|
+
if (moment !== AGENT_ROLE_MOMENT) {
|
|
65
|
+
throw usageError(`--agent-role só vale com --moment ${AGENT_ROLE_MOMENT}.`);
|
|
66
|
+
}
|
|
67
|
+
return { agentRole: value };
|
|
68
|
+
}
|
|
56
69
|
function ideaOf(options) {
|
|
57
70
|
const always = listOf(options.always);
|
|
58
71
|
const never = listOf(options.never);
|
|
59
72
|
if (always.length + never.length === 0) {
|
|
60
73
|
throw usageError('Diga ao menos uma coisa para fazer sempre (--always) ou para nunca fazer (--never).');
|
|
61
74
|
}
|
|
75
|
+
const moment = required(options.moment, '--moment');
|
|
62
76
|
return {
|
|
63
77
|
objective: required(options.objective, '--objective'),
|
|
64
|
-
moment
|
|
78
|
+
moment,
|
|
79
|
+
...agentRoleOf(options.agentRole, moment),
|
|
65
80
|
always,
|
|
66
81
|
never,
|
|
67
82
|
example: required(options.example, '--example')
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { clientOf, printJson, printLine, sessionOf } from '../context.js';
|
|
2
|
+
import { usageError } from '../errors.js';
|
|
3
|
+
import { confirmed } from '../input/confirm.js';
|
|
4
|
+
/** O bloco da rota de escrita (português) e o canvas que GET /v1/company/context devolve. */
|
|
5
|
+
const BLOCKS = {
|
|
6
|
+
empresa: 'company',
|
|
7
|
+
icp: 'icp',
|
|
8
|
+
persona: 'persona',
|
|
9
|
+
proposta_de_valor: 'value-prop',
|
|
10
|
+
posicionamento: 'positioning',
|
|
11
|
+
oferta: 'offer',
|
|
12
|
+
prova: 'proof'
|
|
13
|
+
};
|
|
14
|
+
const STATES = { confirmed: 'confirmado', draft: 'rascunho', empty: 'vazio' };
|
|
15
|
+
async function call(context, options, method, path, body) {
|
|
16
|
+
const response = await clientOf(context, sessionOf(context, options)).request({
|
|
17
|
+
method,
|
|
18
|
+
path,
|
|
19
|
+
...(body === undefined ? {} : { body })
|
|
20
|
+
});
|
|
21
|
+
return response.body;
|
|
22
|
+
}
|
|
23
|
+
function blockOf(raw) {
|
|
24
|
+
const name = raw.trim().toLowerCase().replaceAll('-', '_');
|
|
25
|
+
if (BLOCKS[name] === undefined) {
|
|
26
|
+
throw usageError(`Bloco "${raw}" não existe: use ${Object.keys(BLOCKS).join(', ')}.`);
|
|
27
|
+
}
|
|
28
|
+
return name;
|
|
29
|
+
}
|
|
30
|
+
function valueOf(raw, options) {
|
|
31
|
+
if (options.valueJson !== true) {
|
|
32
|
+
return raw;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(raw);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw usageError('Com --value-json, o valor precisa ser JSON válido (texto vai entre aspas).');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function itemOf(raw, index) {
|
|
42
|
+
if ((raw === undefined) === (index === undefined)) {
|
|
43
|
+
throw usageError('Diga o item (o texto exato) ou --index <posição>, um dos dois.');
|
|
44
|
+
}
|
|
45
|
+
if (index === undefined) {
|
|
46
|
+
return raw;
|
|
47
|
+
}
|
|
48
|
+
if (!/^\d+$/.test(index)) {
|
|
49
|
+
throw usageError(`--index precisa de um número a partir de 0 (recebi "${index}").`);
|
|
50
|
+
}
|
|
51
|
+
return Number(index);
|
|
52
|
+
}
|
|
53
|
+
function isRecord(value) {
|
|
54
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
55
|
+
}
|
|
56
|
+
function isField(value) {
|
|
57
|
+
return 'value' in value && 'origin' in value;
|
|
58
|
+
}
|
|
59
|
+
function leaves(node, path) {
|
|
60
|
+
if (Array.isArray(node)) {
|
|
61
|
+
return node.flatMap((child, index) => leaves(child, path === '' ? String(index) : `${path}.${String(index)}`));
|
|
62
|
+
}
|
|
63
|
+
if (!isRecord(node)) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
if (isField(node)) {
|
|
67
|
+
const value = node['value'];
|
|
68
|
+
const text = typeof value === 'string' ? value : JSON.stringify(value);
|
|
69
|
+
return [` ${path} = ${text === '' ? '(vazio)' : text} [${String(node['origin'])}]`];
|
|
70
|
+
}
|
|
71
|
+
return Object.entries(node).flatMap(([key, child]) => leaves(child, path === '' ? key : `${path}.${key}`));
|
|
72
|
+
}
|
|
73
|
+
function printBlock(context, name, canvas) {
|
|
74
|
+
const state = STATES[canvas.state] ?? canvas.state;
|
|
75
|
+
printLine(context, `${name}: ${state}${canvas.version === null ? '' : `, versão ${String(canvas.version)}`}`);
|
|
76
|
+
leaves(canvas.canvas, '').forEach((line) => {
|
|
77
|
+
printLine(context, line);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export async function contextShow(context, rawBlock, options) {
|
|
81
|
+
const only = rawBlock === undefined ? undefined : blockOf(rawBlock);
|
|
82
|
+
const body = (await call(context, options, 'GET', '/v1/company/context'));
|
|
83
|
+
const names = only === undefined ? Object.keys(BLOCKS) : [only];
|
|
84
|
+
if (options.json === true) {
|
|
85
|
+
printJson(context, only === undefined ? body : { [only]: body.canvases[BLOCKS[only]] });
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
for (const name of names) {
|
|
89
|
+
const canvas = body.canvases[BLOCKS[name]];
|
|
90
|
+
if (canvas !== undefined) {
|
|
91
|
+
printBlock(context, name, canvas);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function change(context, request, options) {
|
|
96
|
+
const body = options.changeConfirmed === true ? { ...request, confirmaBlocoConfirmado: true } : request;
|
|
97
|
+
const card = (await call(context, options, 'POST', '/v1/company/context/changes/preview', body));
|
|
98
|
+
if (options.json !== true) {
|
|
99
|
+
printLine(context, card.title);
|
|
100
|
+
card.details.forEach((line) => {
|
|
101
|
+
printLine(context, ` ${line}`);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (!(await confirmed(context, options.yes, 'Gravar assim?'))) {
|
|
105
|
+
if (options.json === true) {
|
|
106
|
+
printJson(context, card);
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const applied = (await call(context, options, 'POST', '/v1/company/context/changes/apply', {
|
|
111
|
+
...body,
|
|
112
|
+
confirmationToken: card.confirmation.token
|
|
113
|
+
}));
|
|
114
|
+
if (options.json === true) {
|
|
115
|
+
printJson(context, applied);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
printLine(context, applied.message);
|
|
119
|
+
}
|
|
120
|
+
function fieldOf(raw) {
|
|
121
|
+
if (raw.trim() === '') {
|
|
122
|
+
throw usageError('Diga o campo, com pontos e posições a partir de 0 (como `nexo context show` mostra).');
|
|
123
|
+
}
|
|
124
|
+
return raw.trim();
|
|
125
|
+
}
|
|
126
|
+
export async function contextSet(context, rawBlock, field, value, options) {
|
|
127
|
+
await change(context, { bloco: blockOf(rawBlock), acao: 'campo_mudar', campo: fieldOf(field), valor: valueOf(value, options) }, options);
|
|
128
|
+
}
|
|
129
|
+
export async function contextAdd(context, rawBlock, field, value, options) {
|
|
130
|
+
await change(context, { bloco: blockOf(rawBlock), acao: 'item_somar', campo: fieldOf(field), valor: valueOf(value, options) }, options);
|
|
131
|
+
}
|
|
132
|
+
export async function contextRemove(context, rawBlock, field, item, options) {
|
|
133
|
+
await change(context, { bloco: blockOf(rawBlock), acao: 'item_tirar', campo: fieldOf(field), item: itemOf(item, options.index) }, options);
|
|
134
|
+
}
|
|
135
|
+
export async function contextConfirm(context, rawBlock, options) {
|
|
136
|
+
await change(context, { bloco: blockOf(rawBlock), acao: 'bloco_confirmar' }, options);
|
|
137
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { clientOf, printJson, printLine, printNotice, sessionOf } from '../context.js';
|
|
2
|
+
import { usageError } from '../errors.js';
|
|
3
|
+
import { confirmed } from '../input/confirm.js';
|
|
4
|
+
export const RULE_SUBJECTS = [
|
|
5
|
+
'discount',
|
|
6
|
+
'minimum_price',
|
|
7
|
+
'deadline',
|
|
8
|
+
'payment_terms',
|
|
9
|
+
'integration',
|
|
10
|
+
'scope',
|
|
11
|
+
'implementation'
|
|
12
|
+
];
|
|
13
|
+
export const RESOLVE_ACTIONS = ['choose', 'approve', 'use', 'rewrite', 'discard'];
|
|
14
|
+
export const ITEM_TYPES = ['rule', 'practice', 'product_fact', 'price', 'proof', 'standard'];
|
|
15
|
+
const MAX_MOVE = 100;
|
|
16
|
+
async function call(context, options, method, path, extra = {}) {
|
|
17
|
+
const response = await clientOf(context, sessionOf(context, options)).request({ method, path, ...extra });
|
|
18
|
+
return response.body;
|
|
19
|
+
}
|
|
20
|
+
function typeOf(raw) {
|
|
21
|
+
if (raw === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (!ITEM_TYPES.includes(raw)) {
|
|
25
|
+
throw usageError(`Tipo "${raw}" não existe: use ${ITEM_TYPES.join(', ')}.`);
|
|
26
|
+
}
|
|
27
|
+
return raw;
|
|
28
|
+
}
|
|
29
|
+
/** The structured fields of a rule, as the server wants them: the subject plus four nullable strings. */
|
|
30
|
+
function ruleOf(options) {
|
|
31
|
+
const given = [options.subject, options.condition, options.limit, options.exception, options.approver];
|
|
32
|
+
if (given.every((value) => value === undefined)) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
if (options.subject === undefined || !RULE_SUBJECTS.includes(options.subject)) {
|
|
36
|
+
throw usageError(`Os campos da regra pedem --subject: ${RULE_SUBJECTS.join(', ')}.`, '--condition, --limit, --exception e --approver são opcionais; numa edição, o que não vier fica vazio.');
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
subject: options.subject,
|
|
40
|
+
condition: options.condition ?? null,
|
|
41
|
+
limit: options.limit ?? null,
|
|
42
|
+
exception: options.exception ?? null,
|
|
43
|
+
approver: options.approver ?? null
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function themeName(item) {
|
|
47
|
+
return item.theme?.name ?? item.themeId ?? '-';
|
|
48
|
+
}
|
|
49
|
+
function printItem(context, item) {
|
|
50
|
+
printLine(context, `${item.id} ${item.type.padEnd(12)} [${item.status}] tema: ${themeName(item)}`);
|
|
51
|
+
printLine(context, ` ${item.text}`);
|
|
52
|
+
}
|
|
53
|
+
const MAX_LIST_PAGES = 200;
|
|
54
|
+
async function listPage(context, options, query) {
|
|
55
|
+
return (await call(context, options, 'GET', '/v1/knowledge/items', { query }));
|
|
56
|
+
}
|
|
57
|
+
function inTheme(items, themeId) {
|
|
58
|
+
return items.filter((item) => (item.themeId ?? item.theme?.id) === themeId);
|
|
59
|
+
}
|
|
60
|
+
/** Walks every page and keeps the items of one theme: the API has no theme filter on the list. */
|
|
61
|
+
async function itemsOfTheme(context, options, base, themeId) {
|
|
62
|
+
const kept = [];
|
|
63
|
+
let page = 1;
|
|
64
|
+
let totalPages = 1;
|
|
65
|
+
while (page <= totalPages && page <= MAX_LIST_PAGES) {
|
|
66
|
+
const result = await listPage(context, options, { ...base, page: String(page), pageSize: '100' });
|
|
67
|
+
kept.push(...inTheme(result.data, themeId));
|
|
68
|
+
totalPages = result.pagination.totalPages;
|
|
69
|
+
page += 1;
|
|
70
|
+
}
|
|
71
|
+
return { data: kept, pagination: { page: 1, totalPages: 1, totalRecords: kept.length } };
|
|
72
|
+
}
|
|
73
|
+
function listQueryOf(options) {
|
|
74
|
+
const query = {};
|
|
75
|
+
const type = typeOf(options.type);
|
|
76
|
+
if (type !== undefined) {
|
|
77
|
+
query.type = type;
|
|
78
|
+
}
|
|
79
|
+
if (options.needsYou === true) {
|
|
80
|
+
query.needsYou = 'true';
|
|
81
|
+
}
|
|
82
|
+
if (options.theme === undefined) {
|
|
83
|
+
if (options.page !== undefined) {
|
|
84
|
+
query.page = options.page;
|
|
85
|
+
}
|
|
86
|
+
if (options.pageSize !== undefined) {
|
|
87
|
+
query.pageSize = options.pageSize;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return query;
|
|
91
|
+
}
|
|
92
|
+
export async function itemsList(context, options) {
|
|
93
|
+
const query = listQueryOf(options);
|
|
94
|
+
const page = options.theme === undefined ? await listPage(context, options, query) : await itemsOfTheme(context, options, query, options.theme);
|
|
95
|
+
if (options.json === true) {
|
|
96
|
+
printJson(context, page);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (page.data.length === 0) {
|
|
100
|
+
printLine(context, 'Nenhum item.');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
page.data.forEach((item) => {
|
|
104
|
+
printItem(context, item);
|
|
105
|
+
});
|
|
106
|
+
if (page.pagination.page < page.pagination.totalPages) {
|
|
107
|
+
printNotice(context, `Página ${String(page.pagination.page)} de ${String(page.pagination.totalPages)}: veja a próxima com --page.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export async function itemsCreate(context, options) {
|
|
111
|
+
const type = typeOf(options.type);
|
|
112
|
+
if (type === undefined || options.text === undefined || options.text.trim() === '') {
|
|
113
|
+
throw usageError('Diga o tipo (--type) e o texto (--text) do item.', `Tipos: ${ITEM_TYPES.join(', ')}.`);
|
|
114
|
+
}
|
|
115
|
+
const rule = ruleOf(options);
|
|
116
|
+
if (type === 'rule' && rule === undefined) {
|
|
117
|
+
throw usageError('Item do tipo rule pede --subject (e, se quiser, --condition, --limit, --exception, --approver).');
|
|
118
|
+
}
|
|
119
|
+
const body = { type, text: options.text };
|
|
120
|
+
if (rule !== undefined) {
|
|
121
|
+
body.rule = rule;
|
|
122
|
+
}
|
|
123
|
+
if (options.theme !== undefined) {
|
|
124
|
+
body.themeId = options.theme;
|
|
125
|
+
}
|
|
126
|
+
const item = (await call(context, options, 'POST', '/v1/knowledge/items', { body }));
|
|
127
|
+
if (options.json === true) {
|
|
128
|
+
printJson(context, item);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
printLine(context, 'Item criado; já está em uso.');
|
|
132
|
+
printItem(context, item);
|
|
133
|
+
}
|
|
134
|
+
export async function itemsEdit(context, itemId, options) {
|
|
135
|
+
const body = {};
|
|
136
|
+
const type = typeOf(options.type);
|
|
137
|
+
if (type !== undefined) {
|
|
138
|
+
body.type = type;
|
|
139
|
+
}
|
|
140
|
+
if (options.theme !== undefined) {
|
|
141
|
+
body.themeId = options.theme;
|
|
142
|
+
}
|
|
143
|
+
if (options.text !== undefined) {
|
|
144
|
+
body.text = options.text;
|
|
145
|
+
}
|
|
146
|
+
const rule = ruleOf(options);
|
|
147
|
+
if (rule !== undefined) {
|
|
148
|
+
body.rule = rule;
|
|
149
|
+
}
|
|
150
|
+
if (Object.keys(body).length === 0) {
|
|
151
|
+
throw usageError('Nenhuma mudança: use --text, --type, --theme ou os campos da regra (--subject ...).');
|
|
152
|
+
}
|
|
153
|
+
const item = (await call(context, options, 'PATCH', `/v1/knowledge/items/${encodeURIComponent(itemId)}`, { body }));
|
|
154
|
+
if (options.json === true) {
|
|
155
|
+
printJson(context, item);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
printLine(context, 'Item editado.');
|
|
159
|
+
printItem(context, item);
|
|
160
|
+
}
|
|
161
|
+
export async function itemsMove(context, itemIds, options) {
|
|
162
|
+
if (options.theme === undefined) {
|
|
163
|
+
throw usageError('Diga o tema de destino com --theme <id> (`nexo knowledge themes list`).');
|
|
164
|
+
}
|
|
165
|
+
if (itemIds.length === 0 || itemIds.length > MAX_MOVE) {
|
|
166
|
+
throw usageError(`Passe de 1 a ${String(MAX_MOVE)} ids de item.`);
|
|
167
|
+
}
|
|
168
|
+
const result = (await call(context, options, 'POST', '/v1/knowledge/items/move', {
|
|
169
|
+
body: { itemIds, themeId: options.theme }
|
|
170
|
+
}));
|
|
171
|
+
if (options.json === true) {
|
|
172
|
+
printJson(context, result);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
printLine(context, `${String(result.moved)} item(ns) no tema ${result.themeId}.`);
|
|
176
|
+
}
|
|
177
|
+
export async function themesList(context, options) {
|
|
178
|
+
const list = (await call(context, options, 'GET', '/v1/knowledge/themes'));
|
|
179
|
+
if (options.json === true) {
|
|
180
|
+
printJson(context, list);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (list.data.length === 0) {
|
|
184
|
+
printLine(context, 'Nenhum tema.');
|
|
185
|
+
}
|
|
186
|
+
for (const theme of list.data) {
|
|
187
|
+
printLine(context, `${theme.id} ${theme.name} (${String(theme.itemCount)} itens, ${String(theme.materialCount)} arquivos, ${String(theme.webSourceCount)} fontes web)`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function nameOf(name) {
|
|
191
|
+
if (name.trim() === '') {
|
|
192
|
+
throw usageError('O nome do tema não pode ser vazio.');
|
|
193
|
+
}
|
|
194
|
+
return name;
|
|
195
|
+
}
|
|
196
|
+
export async function themesCreate(context, name, options) {
|
|
197
|
+
const theme = (await call(context, options, 'POST', '/v1/knowledge/themes', { body: { name: nameOf(name) } }));
|
|
198
|
+
if (options.json === true) {
|
|
199
|
+
printJson(context, theme);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
printLine(context, `Tema criado: ${theme.id} ${theme.name}`);
|
|
203
|
+
}
|
|
204
|
+
export async function themesRename(context, themeId, name, options) {
|
|
205
|
+
const theme = (await call(context, options, 'PATCH', `/v1/knowledge/themes/${encodeURIComponent(themeId)}`, {
|
|
206
|
+
body: { name: nameOf(name) }
|
|
207
|
+
}));
|
|
208
|
+
if (options.json === true) {
|
|
209
|
+
printJson(context, theme);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
printLine(context, `Tema renomeado: ${theme.id} ${theme.name}`);
|
|
213
|
+
}
|
|
214
|
+
export async function themesRemove(context, themeId, options) {
|
|
215
|
+
if (!(await confirmed(context, options.yes, `Apagar o tema ${themeId}? Só passa se ele estiver vazio.`))) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
await call(context, options, 'DELETE', `/v1/knowledge/themes/${encodeURIComponent(themeId)}`);
|
|
219
|
+
printLine(context, 'Tema apagado.');
|
|
220
|
+
}
|
|
221
|
+
function itemPath(itemId, suffix = '') {
|
|
222
|
+
return `/v1/knowledge/items/${encodeURIComponent(itemId)}${suffix}`;
|
|
223
|
+
}
|
|
224
|
+
export async function itemsSwitch(context, itemId, on, options) {
|
|
225
|
+
const item = (await call(context, options, 'POST', itemPath(itemId, on ? '/enable' : '/disable')));
|
|
226
|
+
if (options.json === true) {
|
|
227
|
+
printJson(context, item);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
printLine(context, on ? 'Item ligado: de volta em uso.' : 'Item desligado: fora de uso, sem apagar.');
|
|
231
|
+
printItem(context, item);
|
|
232
|
+
}
|
|
233
|
+
export async function itemsResolve(context, itemId, options) {
|
|
234
|
+
const action = options.action;
|
|
235
|
+
if (action === undefined || !RESOLVE_ACTIONS.includes(action)) {
|
|
236
|
+
throw usageError(`Diga a ação com --action: ${RESOLVE_ACTIONS.join(', ')}.`);
|
|
237
|
+
}
|
|
238
|
+
if (action === 'rewrite' && (options.text === undefined || options.text.trim() === '')) {
|
|
239
|
+
throw usageError('A ação rewrite pede o texto novo com --text.');
|
|
240
|
+
}
|
|
241
|
+
if (action === 'discard' && !(await confirmed(context, options.yes, `Descartar o item ${itemId}? Ele sai da Base de vez.`))) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const body = { action };
|
|
245
|
+
if (action === 'rewrite') {
|
|
246
|
+
body.text = options.text;
|
|
247
|
+
}
|
|
248
|
+
const result = await call(context, options, 'POST', itemPath(itemId, '/resolve'), { body });
|
|
249
|
+
if (options.json === true) {
|
|
250
|
+
printJson(context, result);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
printLine(context, `Pendência resolvida (${action}).`);
|
|
254
|
+
}
|
|
255
|
+
export async function itemsRemove(context, itemId, options) {
|
|
256
|
+
if (!(await confirmed(context, options.yes, `Remover o item ${itemId}? Ele não volta com o mesmo material (para tirar de uso, use off).`))) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
await call(context, options, 'DELETE', itemPath(itemId));
|
|
260
|
+
printLine(context, 'Item removido.');
|
|
261
|
+
}
|
package/dist/program-brain.js
CHANGED
|
@@ -35,6 +35,7 @@ function addWriteCommands(brain, context) {
|
|
|
35
35
|
.option('--team <id>', 'o time da skill (nível team)')
|
|
36
36
|
.option('--objective <texto>', 'o objetivo, em uma linha')
|
|
37
37
|
.option('--moment <momento>', 'o momento da lista (nexo brain moments)')
|
|
38
|
+
.option('--agent-role <papel>', 'só com o momento attendance_agent_turn: sdr (o padrão) ou cs')
|
|
38
39
|
.option('--always <texto>', 'o que fazer sempre (repita para mais de um)', collect, [])
|
|
39
40
|
.option('--never <texto>', 'o que nunca fazer (repita para mais de um)', collect, [])
|
|
40
41
|
.option('--example <texto>', 'um exemplo de como deve sair, em uma linha')
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { contextAdd, contextConfirm, contextRemove, contextSet, contextShow } from './commands/context-company.js';
|
|
2
|
+
const BLOCK_HELP = 'empresa, icp, persona, proposta_de_valor, posicionamento, oferta ou prova';
|
|
3
|
+
const WRITE_NOTE = 'Só admin, com o escopo context:write, que precisa ser pedido pelo nome no login (nexo login --scopes <os que você usa>,context:write)';
|
|
4
|
+
function addWriteOptions(command, withValue) {
|
|
5
|
+
if (withValue) {
|
|
6
|
+
command.option('--value-json', 'o valor é JSON (objeto, lista, número); sem isso é texto');
|
|
7
|
+
}
|
|
8
|
+
return command
|
|
9
|
+
.option('--change-confirmed', 'confirma que quer mudar um bloco que a empresa já confirmou')
|
|
10
|
+
.option('-y, --yes', 'grava logo depois de mostrar a prévia');
|
|
11
|
+
}
|
|
12
|
+
function addValueCommands(group, context) {
|
|
13
|
+
addWriteOptions(group
|
|
14
|
+
.command('set')
|
|
15
|
+
.description(`Muda um campo, com a prévia de antes e depois e o sim. ${WRITE_NOTE}`)
|
|
16
|
+
.argument('<bloco>', BLOCK_HELP)
|
|
17
|
+
.argument('<campo>', 'caminho do campo, como offerings.0.whatItIs (veja `nexo context show`)')
|
|
18
|
+
.argument('<valor>', 'o texto novo inteiro'), true).action(async (block, field, value, _options, command) => {
|
|
19
|
+
await contextSet(context, block, field, value, command.optsWithGlobals());
|
|
20
|
+
});
|
|
21
|
+
addWriteOptions(group
|
|
22
|
+
.command('add')
|
|
23
|
+
.description(`Soma um item a uma lista, com a prévia e o sim. ${WRITE_NOTE}`)
|
|
24
|
+
.argument('<bloco>', BLOCK_HELP)
|
|
25
|
+
.argument('<lista>', 'caminho da lista, como offerings')
|
|
26
|
+
.argument('<valor>', 'o item: um texto, ou com --value-json o objeto inteiro'), true).action(async (block, field, value, _options, command) => {
|
|
27
|
+
await contextAdd(context, block, field, value, command.optsWithGlobals());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function addRemoveCommands(group, context) {
|
|
31
|
+
addWriteOptions(group
|
|
32
|
+
.command('remove')
|
|
33
|
+
.description(`Tira um item de uma lista, com a prévia e o sim. ${WRITE_NOTE}`)
|
|
34
|
+
.argument('<bloco>', BLOCK_HELP)
|
|
35
|
+
.argument('<lista>', 'caminho da lista, como offerings')
|
|
36
|
+
.argument('[item]', 'o texto exato do item (para uma posição, use --index)')
|
|
37
|
+
.option('--index <n>', 'a posição do item na lista, a partir de 0, no lugar do texto'), false).action(async (block, field, item, _options, command) => {
|
|
38
|
+
await contextRemove(context, block, field, item, command.optsWithGlobals());
|
|
39
|
+
});
|
|
40
|
+
addWriteOptions(group
|
|
41
|
+
.command('confirm')
|
|
42
|
+
.description(`Confirma o rascunho de um bloco como está, com a prévia e o sim. ${WRITE_NOTE}`)
|
|
43
|
+
.argument('<bloco>', BLOCK_HELP), false).action(async (block, _options, command) => {
|
|
44
|
+
await contextConfirm(context, block, command.optsWithGlobals());
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function addContextCommands(program, context) {
|
|
48
|
+
const group = program
|
|
49
|
+
.command('context')
|
|
50
|
+
.alias('contexto')
|
|
51
|
+
.description('O contexto da empresa (empresa, ICP, persona, proposta de valor, posicionamento, oferta e prova): ler e editar');
|
|
52
|
+
group
|
|
53
|
+
.command('show', { isDefault: true })
|
|
54
|
+
.description('Lê o contexto, bloco por bloco, com a origem de cada campo (precisa de context:read)')
|
|
55
|
+
.argument('[bloco]', `só um bloco: ${BLOCK_HELP}`)
|
|
56
|
+
.action(async (block, _options, command) => {
|
|
57
|
+
await contextShow(context, block, command.optsWithGlobals());
|
|
58
|
+
});
|
|
59
|
+
addValueCommands(group, context);
|
|
60
|
+
addRemoveCommands(group, context);
|
|
61
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { itemsCreate, itemsEdit, itemsList, itemsMove, itemsRemove, itemsResolve, itemsSwitch, themesCreate, themesList, themesRemove, themesRename } from './commands/knowledge.js';
|
|
2
|
+
const TYPE_HELP = 'rule, practice, product_fact, price, proof ou standard';
|
|
3
|
+
function addItemReads(items, context) {
|
|
4
|
+
items
|
|
5
|
+
.command('list')
|
|
6
|
+
.description('Lista os itens, com o tema de cada um')
|
|
7
|
+
.option('--type <tipo>', `só os itens deste tipo (${TYPE_HELP})`)
|
|
8
|
+
.option('--theme <id>', 'só os itens deste tema (a CLI percorre as páginas e filtra)')
|
|
9
|
+
.option('--needs-you', 'só os pendentes')
|
|
10
|
+
.option('--page <n>', 'a página')
|
|
11
|
+
.option('--page-size <n>', 'itens por página (até 100)')
|
|
12
|
+
.action(async (_options, command) => {
|
|
13
|
+
await itemsList(context, command.optsWithGlobals());
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function withRuleOptions(command) {
|
|
17
|
+
return command
|
|
18
|
+
.option('--subject <assunto>', 'campos da regra (type rule): discount, minimum_price, deadline, payment_terms, integration, scope ou implementation')
|
|
19
|
+
.option('--condition <texto>', 'regra: a condição que ativa')
|
|
20
|
+
.option('--limit <texto>', 'regra: o valor do limite')
|
|
21
|
+
.option('--exception <texto>', 'regra: a exceção conhecida')
|
|
22
|
+
.option('--approver <texto>', 'regra: quem aprova a exceção');
|
|
23
|
+
}
|
|
24
|
+
function addItemCreateEdit(items, context) {
|
|
25
|
+
withRuleOptions(items
|
|
26
|
+
.command('create')
|
|
27
|
+
.description('Escreve um item à mão; entra em uso na hora')
|
|
28
|
+
.option('--type <tipo>', TYPE_HELP)
|
|
29
|
+
.option('--text <texto>', 'o texto curto do item')
|
|
30
|
+
.option('--theme <id>', 'o tema do item (sem ele, o tema padrão)')).action(async (_options, command) => {
|
|
31
|
+
await itemsCreate(context, command.optsWithGlobals());
|
|
32
|
+
});
|
|
33
|
+
withRuleOptions(items
|
|
34
|
+
.command('edit')
|
|
35
|
+
.description('Edita um item: texto, tipo, tema ou campos da regra')
|
|
36
|
+
.argument('<item>', 'id do item')
|
|
37
|
+
.option('--text <texto>', 'o texto novo')
|
|
38
|
+
.option('--type <tipo>', `o tipo novo (${TYPE_HELP})`)
|
|
39
|
+
.option('--theme <id>', 'o tema novo (nexo knowledge themes list)')).action(async (itemId, _options, command) => {
|
|
40
|
+
await itemsEdit(context, itemId, command.optsWithGlobals());
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function addItemStates(items, context) {
|
|
44
|
+
for (const on of [true, false]) {
|
|
45
|
+
items
|
|
46
|
+
.command(on ? 'on' : 'off')
|
|
47
|
+
.description(on ? 'Liga um item desligado: volta a ficar em uso' : 'Desliga um item: sai de uso, sem apagar')
|
|
48
|
+
.argument('<item>', 'id do item')
|
|
49
|
+
.action(async (itemId, _options, command) => {
|
|
50
|
+
await itemsSwitch(context, itemId, on, command.optsWithGlobals());
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
items
|
|
54
|
+
.command('resolve')
|
|
55
|
+
.description('Resolve uma pendência: choose (este lado do conflito), approve (aprova a prova), use (aceita como está), rewrite, discard')
|
|
56
|
+
.argument('<item>', 'id do item')
|
|
57
|
+
.option('--action <ação>', 'choose, approve, use, rewrite ou discard')
|
|
58
|
+
.option('--text <texto>', 'o texto novo (só com rewrite)')
|
|
59
|
+
.option('-y, --yes', 'descarta sem perguntar (só depois do sim da pessoa)')
|
|
60
|
+
.action(async (itemId, _options, command) => {
|
|
61
|
+
await itemsResolve(context, itemId, command.optsWithGlobals());
|
|
62
|
+
});
|
|
63
|
+
items
|
|
64
|
+
.command('remove')
|
|
65
|
+
.description('Remove um item de vez; para tirar de uso por um tempo, use off')
|
|
66
|
+
.argument('<item>', 'id do item')
|
|
67
|
+
.option('-y, --yes', 'remove sem perguntar (só depois do sim da pessoa)')
|
|
68
|
+
.action(async (itemId, _options, command) => {
|
|
69
|
+
await itemsRemove(context, itemId, command.optsWithGlobals());
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function addItemWrites(items, context) {
|
|
73
|
+
addItemCreateEdit(items, context);
|
|
74
|
+
addItemStates(items, context);
|
|
75
|
+
items
|
|
76
|
+
.command('move')
|
|
77
|
+
.description('Move até 100 itens para um tema; um id que não existe recusa tudo')
|
|
78
|
+
.argument('<item...>', 'ids dos itens')
|
|
79
|
+
.option('--theme <id>', 'o tema de destino')
|
|
80
|
+
.action(async (itemIds, _options, command) => {
|
|
81
|
+
await itemsMove(context, itemIds, command.optsWithGlobals());
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function addThemeCommands(knowledge, context) {
|
|
85
|
+
const themes = knowledge.command('themes').description('Os temas da Base');
|
|
86
|
+
themes
|
|
87
|
+
.command('list')
|
|
88
|
+
.description('Lista os temas, com o que cada um guarda')
|
|
89
|
+
.action(async (_options, command) => {
|
|
90
|
+
await themesList(context, command.optsWithGlobals());
|
|
91
|
+
});
|
|
92
|
+
themes
|
|
93
|
+
.command('create')
|
|
94
|
+
.description('Cria um tema')
|
|
95
|
+
.argument('<nome>', 'o nome do tema')
|
|
96
|
+
.action(async (name, _options, command) => {
|
|
97
|
+
await themesCreate(context, name, command.optsWithGlobals());
|
|
98
|
+
});
|
|
99
|
+
themes
|
|
100
|
+
.command('rename')
|
|
101
|
+
.description('Renomeia um tema')
|
|
102
|
+
.argument('<tema>', 'id do tema')
|
|
103
|
+
.argument('<nome>', 'o nome novo')
|
|
104
|
+
.action(async (themeId, name, _options, command) => {
|
|
105
|
+
await themesRename(context, themeId, name, command.optsWithGlobals());
|
|
106
|
+
});
|
|
107
|
+
themes
|
|
108
|
+
.command('remove')
|
|
109
|
+
.description('Apaga um tema vazio (com conteúdo, a API recusa com 409)')
|
|
110
|
+
.argument('<tema>', 'id do tema')
|
|
111
|
+
.option('-y, --yes', 'apaga sem perguntar (só depois do sim da pessoa)')
|
|
112
|
+
.action(async (themeId, _options, command) => {
|
|
113
|
+
await themesRemove(context, themeId, command.optsWithGlobals());
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function addItemCommands(knowledge, context) {
|
|
117
|
+
const items = knowledge
|
|
118
|
+
.command('items')
|
|
119
|
+
.description('Os itens da Base: lista, cria, edita (texto, tipo, tema) e move de tema');
|
|
120
|
+
addItemReads(items, context);
|
|
121
|
+
addItemWrites(items, context);
|
|
122
|
+
}
|
|
123
|
+
export function addKnowledgeCommands(program, context) {
|
|
124
|
+
const knowledge = program
|
|
125
|
+
.command('knowledge')
|
|
126
|
+
.alias('base')
|
|
127
|
+
.description('A Base de conhecimento: itens e temas. Só admin, com o escopo calibration:write para escrever');
|
|
128
|
+
addItemCommands(knowledge, context);
|
|
129
|
+
addThemeCommands(knowledge, context);
|
|
130
|
+
}
|
package/dist/program.js
CHANGED
|
@@ -9,8 +9,10 @@ import { addDocumentCommands } from './program-documents.js';
|
|
|
9
9
|
import { addArtifactCommands, addDealCommands } from './program-artifacts.js';
|
|
10
10
|
import { addTemplateCommands } from './program-templates.js';
|
|
11
11
|
import { addBrainCommands } from './program-brain.js';
|
|
12
|
+
import { addKnowledgeCommands } from './program-knowledge.js';
|
|
12
13
|
import { addErpCommands } from './program-erp.js';
|
|
13
14
|
import { addAgentCommands } from './program-agents.js';
|
|
15
|
+
import { addContextCommands } from './program-context.js';
|
|
14
16
|
import { addDashboardCommands } from './program-dashboards.js';
|
|
15
17
|
import { skillsInstall, skillsList, skillsShow } from './commands/skills.js';
|
|
16
18
|
import { login } from './commands/login.js';
|
|
@@ -165,6 +167,11 @@ function addBillingCommands(program, context) {
|
|
|
165
167
|
await billingInvoices(context, id, command.optsWithGlobals());
|
|
166
168
|
});
|
|
167
169
|
}
|
|
170
|
+
function addCompanyBrainCommands(program, context) {
|
|
171
|
+
addBrainCommands(program, context);
|
|
172
|
+
addKnowledgeCommands(program, context);
|
|
173
|
+
addContextCommands(program, context);
|
|
174
|
+
}
|
|
168
175
|
export function buildProgram(context) {
|
|
169
176
|
const program = new Command('nexo')
|
|
170
177
|
.description('CLI do Nexo: a API, o Connect, os dashboards, os fluxos, os documentos e as análises no terminal')
|
|
@@ -192,7 +199,7 @@ export function buildProgram(context) {
|
|
|
192
199
|
addDealCommands(program, context);
|
|
193
200
|
addArtifactCommands(program, context);
|
|
194
201
|
addTemplateCommands(program, context);
|
|
195
|
-
|
|
202
|
+
addCompanyBrainCommands(program, context);
|
|
196
203
|
addErpCommands(program, context);
|
|
197
204
|
addAgentCommands(program, context);
|
|
198
205
|
return program;
|