insightcrm 0.1.2 → 0.1.4
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 +1 -0
- package/SKILL.md +11 -0
- package/dist/cli.js +393 -54
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ crm login https://<你的服务器> # 浏览器里点「允许」(设备
|
|
|
10
10
|
crm schema --json # 字段契约,含每个字段的填写指引
|
|
11
11
|
echo '{"name":"王小明","company":"ACME"}' | crm add - --json
|
|
12
12
|
crm list --due-today --json
|
|
13
|
+
crm version # 当前版本 + npm 上有没有新版
|
|
13
14
|
crm skill # 打印给 agent 的使用说明;在 agent 指令里加一句「先运行 crm skill」
|
|
14
15
|
```
|
|
15
16
|
|
package/SKILL.md
CHANGED
|
@@ -37,6 +37,7 @@ crm login https://<服务器地址>
|
|
|
37
37
|
## 怎么从材料里抽取
|
|
38
38
|
|
|
39
39
|
**身份与联系**:`name`、`company`、`title`;`wechatId`、`city`。只填材料里明确出现的。看不到就省略,不要猜。
|
|
40
|
+
`city` 取 `crm schema --json` 里 `city` 字段的 `values`(城市枚举);写成「上海市」「Shanghai」「臺北」也会被自动归一化成「上海」「上海」「台北」,所以直接按你看到的写就行。
|
|
40
41
|
|
|
41
42
|
**画像**:
|
|
42
43
|
- `painPoints`:痛点和兴趣标签,每条几个字。
|
|
@@ -140,6 +141,16 @@ crm import backup.json # 重复导入同一份是安全的(相同 id
|
|
|
140
141
|
|
|
141
142
|
`crm rm <id> --yes` 删除客户,**先问用户**。客户的钩子会保留在钩子库里。
|
|
142
143
|
|
|
144
|
+
## 检查版本
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
crm version # 打印当前版本,并查 npm 上有没有新版
|
|
148
|
+
crm version --json # 结构化输出(agent 用这个)
|
|
149
|
+
crm version --offline # 只报本地版本,不联网
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
有新版时会给出 `update npm i -g insightcrm` 的提示,**升级前先问用户**。查不到(离线、npm 挂了)时命令仍然退出码 0,JSON 里的 `error` 字段说明原因,`latest` 为 `null`。
|
|
153
|
+
|
|
143
154
|
## 这份说明从哪来
|
|
144
155
|
|
|
145
156
|
`crm skill` 把这份说明打印出来,内容永远和当前安装的 CLI 版本一致。**处理客户相关的事(录入、更新、查询、推荐)之前先运行一次 `crm skill`,并按它执行。**
|
package/dist/cli.js
CHANGED
|
@@ -17,6 +17,102 @@ import { Command, Option } from "commander";
|
|
|
17
17
|
var CONVERSION_POTENTIALS = ["High", "Medium", "Low"];
|
|
18
18
|
var EVENT_TYPES = ["meeting", "follow_up", "deadline", "other"];
|
|
19
19
|
var RECOMMENDATION_TYPES = ["Article", "Product", "Service", "Event"];
|
|
20
|
+
var CITIES = [
|
|
21
|
+
// 一线 / 新一线
|
|
22
|
+
"\u4E0A\u6D77",
|
|
23
|
+
"\u5317\u4EAC",
|
|
24
|
+
"\u6DF1\u5733",
|
|
25
|
+
"\u5E7F\u5DDE",
|
|
26
|
+
"\u676D\u5DDE",
|
|
27
|
+
"\u6210\u90FD",
|
|
28
|
+
"\u91CD\u5E86",
|
|
29
|
+
"\u82CF\u5DDE",
|
|
30
|
+
"\u6B66\u6C49",
|
|
31
|
+
"\u897F\u5B89",
|
|
32
|
+
"\u5357\u4EAC",
|
|
33
|
+
"\u5929\u6D25",
|
|
34
|
+
"\u90D1\u5DDE",
|
|
35
|
+
"\u957F\u6C99",
|
|
36
|
+
"\u9752\u5C9B",
|
|
37
|
+
"\u4E1C\u839E",
|
|
38
|
+
"\u5408\u80A5",
|
|
39
|
+
// 省会 / 区域中心
|
|
40
|
+
"\u798F\u5DDE",
|
|
41
|
+
"\u53A6\u95E8",
|
|
42
|
+
"\u6D4E\u5357",
|
|
43
|
+
"\u6C88\u9633",
|
|
44
|
+
"\u5927\u8FDE",
|
|
45
|
+
"\u957F\u6625",
|
|
46
|
+
"\u54C8\u5C14\u6EE8",
|
|
47
|
+
"\u77F3\u5BB6\u5E84",
|
|
48
|
+
"\u592A\u539F",
|
|
49
|
+
"\u5357\u660C",
|
|
50
|
+
"\u6606\u660E",
|
|
51
|
+
"\u8D35\u9633",
|
|
52
|
+
"\u5357\u5B81",
|
|
53
|
+
"\u5170\u5DDE",
|
|
54
|
+
"\u4E4C\u9C81\u6728\u9F50",
|
|
55
|
+
"\u547C\u548C\u6D69\u7279",
|
|
56
|
+
"\u94F6\u5DDD",
|
|
57
|
+
"\u897F\u5B81",
|
|
58
|
+
"\u6D77\u53E3",
|
|
59
|
+
"\u62C9\u8428",
|
|
60
|
+
// 强二线 / 主要地级市
|
|
61
|
+
"\u5B81\u6CE2",
|
|
62
|
+
"\u4F5B\u5C71",
|
|
63
|
+
"\u6E29\u5DDE",
|
|
64
|
+
"\u65E0\u9521",
|
|
65
|
+
"\u5E38\u5DDE",
|
|
66
|
+
"\u5357\u901A",
|
|
67
|
+
"\u5609\u5174",
|
|
68
|
+
"\u7ECD\u5174",
|
|
69
|
+
"\u91D1\u534E",
|
|
70
|
+
"\u53F0\u5DDE",
|
|
71
|
+
"\u6CC9\u5DDE",
|
|
72
|
+
"\u5F90\u5DDE",
|
|
73
|
+
"\u626C\u5DDE",
|
|
74
|
+
"\u60E0\u5DDE",
|
|
75
|
+
"\u73E0\u6D77",
|
|
76
|
+
"\u4E2D\u5C71",
|
|
77
|
+
"\u6C55\u5934",
|
|
78
|
+
"\u6D1B\u9633",
|
|
79
|
+
"\u8944\u9633",
|
|
80
|
+
"\u6842\u6797",
|
|
81
|
+
"\u67F3\u5DDE",
|
|
82
|
+
"\u682A\u6D32",
|
|
83
|
+
"\u5CB3\u9633",
|
|
84
|
+
"\u5B9C\u660C",
|
|
85
|
+
"\u7EF5\u9633",
|
|
86
|
+
"\u9075\u4E49",
|
|
87
|
+
"\u4E3D\u6C5F",
|
|
88
|
+
"\u5927\u7406",
|
|
89
|
+
"\u4E09\u4E9A",
|
|
90
|
+
"\u5317\u6D77",
|
|
91
|
+
// 港澳台
|
|
92
|
+
"\u9999\u6E2F",
|
|
93
|
+
"\u6FB3\u95E8",
|
|
94
|
+
"\u53F0\u5317",
|
|
95
|
+
"\u9AD8\u96C4",
|
|
96
|
+
// 海外
|
|
97
|
+
"\u65B0\u52A0\u5761",
|
|
98
|
+
"\u4E1C\u4EAC",
|
|
99
|
+
"\u9996\u5C14",
|
|
100
|
+
"\u66FC\u8C37",
|
|
101
|
+
"\u5409\u9686\u5761",
|
|
102
|
+
"\u6CB3\u5185",
|
|
103
|
+
"\u80E1\u5FD7\u660E\u5E02",
|
|
104
|
+
"\u4F26\u6566",
|
|
105
|
+
"\u7EBD\u7EA6",
|
|
106
|
+
"\u6D1B\u6749\u77F6",
|
|
107
|
+
"\u65E7\u91D1\u5C71",
|
|
108
|
+
"\u897F\u96C5\u56FE",
|
|
109
|
+
"\u6E29\u54E5\u534E",
|
|
110
|
+
"\u591A\u4F26\u591A",
|
|
111
|
+
"\u6089\u5C3C",
|
|
112
|
+
"\u58A8\u5C14\u672C",
|
|
113
|
+
"\u8FEA\u62DC",
|
|
114
|
+
"\u67CF\u6797"
|
|
115
|
+
];
|
|
20
116
|
var EXIT = {
|
|
21
117
|
ok: 0,
|
|
22
118
|
error: 1,
|
|
@@ -26,11 +122,162 @@ var EXIT = {
|
|
|
26
122
|
failed: 5
|
|
27
123
|
};
|
|
28
124
|
var VERIFY_LINK_TTL_MS = 72 * 60 * 60 * 1e3;
|
|
125
|
+
var RESET_LINK_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
29
126
|
var CLI_AUTH = {
|
|
30
127
|
ttlMs: 10 * 60 * 1e3,
|
|
31
128
|
pollIntervalSec: 3
|
|
32
129
|
};
|
|
33
130
|
|
|
131
|
+
// ../shared/src/city.ts
|
|
132
|
+
var CITY_ALIASES = {
|
|
133
|
+
// 英文
|
|
134
|
+
beijing: "\u5317\u4EAC",
|
|
135
|
+
peking: "\u5317\u4EAC",
|
|
136
|
+
shanghai: "\u4E0A\u6D77",
|
|
137
|
+
shenzhen: "\u6DF1\u5733",
|
|
138
|
+
guangzhou: "\u5E7F\u5DDE",
|
|
139
|
+
canton: "\u5E7F\u5DDE",
|
|
140
|
+
hangzhou: "\u676D\u5DDE",
|
|
141
|
+
chengdu: "\u6210\u90FD",
|
|
142
|
+
chongqing: "\u91CD\u5E86",
|
|
143
|
+
suzhou: "\u82CF\u5DDE",
|
|
144
|
+
wuhan: "\u6B66\u6C49",
|
|
145
|
+
xian: "\u897F\u5B89",
|
|
146
|
+
"xi'an": "\u897F\u5B89",
|
|
147
|
+
nanjing: "\u5357\u4EAC",
|
|
148
|
+
tianjin: "\u5929\u6D25",
|
|
149
|
+
zhengzhou: "\u90D1\u5DDE",
|
|
150
|
+
changsha: "\u957F\u6C99",
|
|
151
|
+
qingdao: "\u9752\u5C9B",
|
|
152
|
+
dongguan: "\u4E1C\u839E",
|
|
153
|
+
ningbo: "\u5B81\u6CE2",
|
|
154
|
+
foshan: "\u4F5B\u5C71",
|
|
155
|
+
hefei: "\u5408\u80A5",
|
|
156
|
+
fuzhou: "\u798F\u5DDE",
|
|
157
|
+
xiamen: "\u53A6\u95E8",
|
|
158
|
+
jinan: "\u6D4E\u5357",
|
|
159
|
+
shenyang: "\u6C88\u9633",
|
|
160
|
+
dalian: "\u5927\u8FDE",
|
|
161
|
+
changchun: "\u957F\u6625",
|
|
162
|
+
kunming: "\u6606\u660E",
|
|
163
|
+
nanning: "\u5357\u5B81",
|
|
164
|
+
harbin: "\u54C8\u5C14\u6EE8",
|
|
165
|
+
hohhot: "\u547C\u548C\u6D69\u7279",
|
|
166
|
+
urumqi: "\u4E4C\u9C81\u6728\u9F50",
|
|
167
|
+
"hong kong": "\u9999\u6E2F",
|
|
168
|
+
hongkong: "\u9999\u6E2F",
|
|
169
|
+
macau: "\u6FB3\u95E8",
|
|
170
|
+
macao: "\u6FB3\u95E8",
|
|
171
|
+
taipei: "\u53F0\u5317",
|
|
172
|
+
singapore: "\u65B0\u52A0\u5761",
|
|
173
|
+
tokyo: "\u4E1C\u4EAC",
|
|
174
|
+
seoul: "\u9996\u5C14",
|
|
175
|
+
bangkok: "\u66FC\u8C37",
|
|
176
|
+
"kuala lumpur": "\u5409\u9686\u5761",
|
|
177
|
+
hanoi: "\u6CB3\u5185",
|
|
178
|
+
"ho chi minh": "\u80E1\u5FD7\u660E\u5E02",
|
|
179
|
+
hcmc: "\u80E1\u5FD7\u660E\u5E02",
|
|
180
|
+
london: "\u4F26\u6566",
|
|
181
|
+
"new york": "\u7EBD\u7EA6",
|
|
182
|
+
nyc: "\u7EBD\u7EA6",
|
|
183
|
+
"los angeles": "\u6D1B\u6749\u77F6",
|
|
184
|
+
"san francisco": "\u65E7\u91D1\u5C71",
|
|
185
|
+
seattle: "\u897F\u96C5\u56FE",
|
|
186
|
+
vancouver: "\u6E29\u54E5\u534E",
|
|
187
|
+
toronto: "\u591A\u4F26\u591A",
|
|
188
|
+
sydney: "\u6089\u5C3C",
|
|
189
|
+
melbourne: "\u58A8\u5C14\u672C",
|
|
190
|
+
dubai: "\u8FEA\u62DC",
|
|
191
|
+
berlin: "\u67CF\u6797",
|
|
192
|
+
// 整词差异(繁简字符表管不到的那些)
|
|
193
|
+
\u6C49\u57CE: "\u9996\u5C14",
|
|
194
|
+
\u96EA\u68A8: "\u6089\u5C3C",
|
|
195
|
+
\u675C\u62DC: "\u8FEA\u62DC"
|
|
196
|
+
};
|
|
197
|
+
var TRAD_TO_SIMP = {
|
|
198
|
+
\u6771: "\u4E1C",
|
|
199
|
+
\u5EE3: "\u5E7F",
|
|
200
|
+
\u8607: "\u82CF",
|
|
201
|
+
\u912D: "\u90D1",
|
|
202
|
+
\u6F22: "\u6C49",
|
|
203
|
+
\u5CF6: "\u5C9B",
|
|
204
|
+
\u5BE7: "\u5B81",
|
|
205
|
+
\u5EC8: "\u53A6",
|
|
206
|
+
\u6FDF: "\u6D4E",
|
|
207
|
+
\u700B: "\u6C88",
|
|
208
|
+
\u9023: "\u8FDE",
|
|
209
|
+
\u9577: "\u957F",
|
|
210
|
+
\u723E: "\u5C14",
|
|
211
|
+
\u6FF1: "\u6EE8",
|
|
212
|
+
\u838A: "\u5E84",
|
|
213
|
+
\u8CB4: "\u8D35",
|
|
214
|
+
\u70CF: "\u4E4C",
|
|
215
|
+
\u9B6F: "\u9C81",
|
|
216
|
+
\u9F4A: "\u9F50",
|
|
217
|
+
\u9280: "\u94F6",
|
|
218
|
+
\u85A9: "\u8428",
|
|
219
|
+
\u6EAB: "\u6E29",
|
|
220
|
+
\u932B: "\u9521",
|
|
221
|
+
\u8208: "\u5174",
|
|
222
|
+
\u83EF: "\u534E",
|
|
223
|
+
\u81FA: "\u53F0",
|
|
224
|
+
\u63DA: "\u626C",
|
|
225
|
+
\u982D: "\u5934",
|
|
226
|
+
\u967D: "\u9633",
|
|
227
|
+
\u4E9E: "\u4E9A",
|
|
228
|
+
\u7DBF: "\u7EF5",
|
|
229
|
+
\u7FA9: "\u4E49",
|
|
230
|
+
\u9E97: "\u4E3D",
|
|
231
|
+
\u5167: "\u5185",
|
|
232
|
+
\u502B: "\u4F26",
|
|
233
|
+
\u7D04: "\u7EA6",
|
|
234
|
+
\u7D10: "\u7EBD",
|
|
235
|
+
\u78EF: "\u77F6",
|
|
236
|
+
\u820A: "\u65E7",
|
|
237
|
+
\u862D: "\u5170",
|
|
238
|
+
\u7121: "\u65E0",
|
|
239
|
+
\u9751: "\u9752",
|
|
240
|
+
\u9580: "\u95E8",
|
|
241
|
+
\u9F8D: "\u9F99"
|
|
242
|
+
};
|
|
243
|
+
var toSimplified = (s) => s.replace(/[㐀-鿿]/g, (ch) => TRAD_TO_SIMP[ch] ?? ch);
|
|
244
|
+
var LOOKUP = /* @__PURE__ */ new Map();
|
|
245
|
+
for (const city2 of CITIES) LOOKUP.set(city2.toLowerCase(), city2);
|
|
246
|
+
for (const [alias, canonical] of Object.entries(CITY_ALIASES)) LOOKUP.set(alias.toLowerCase(), canonical);
|
|
247
|
+
function normalizeCity(input2) {
|
|
248
|
+
if (!input2) return "";
|
|
249
|
+
const cleaned = input2.replace(/[ \s]+/g, " ").trim();
|
|
250
|
+
if (!cleaned) return "";
|
|
251
|
+
const simplified = toSimplified(cleaned);
|
|
252
|
+
const forms = simplified === cleaned ? [cleaned] : [cleaned, simplified];
|
|
253
|
+
for (const form of forms) {
|
|
254
|
+
const hit = LOOKUP.get(form.toLowerCase());
|
|
255
|
+
if (hit) return hit;
|
|
256
|
+
}
|
|
257
|
+
for (const form of forms) {
|
|
258
|
+
const bare = form.replace(/(特别行政区|自治区|省|市|区|县|州|盟|旗)$/u, "");
|
|
259
|
+
if (bare && bare !== form) {
|
|
260
|
+
const hit = LOOKUP.get(bare.toLowerCase());
|
|
261
|
+
if (hit) return hit;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
for (const form of forms) {
|
|
265
|
+
const compact = form.replace(/\s+/g, "");
|
|
266
|
+
let best;
|
|
267
|
+
let bestAt = Infinity;
|
|
268
|
+
for (const c of CITIES) {
|
|
269
|
+
const at = compact.indexOf(c);
|
|
270
|
+
if (at === -1) continue;
|
|
271
|
+
if (at < bestAt) {
|
|
272
|
+
best = c;
|
|
273
|
+
bestAt = at;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (best) return best;
|
|
277
|
+
}
|
|
278
|
+
return cleaned;
|
|
279
|
+
}
|
|
280
|
+
|
|
34
281
|
// ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/external.js
|
|
35
282
|
var external_exports = {};
|
|
36
283
|
__export(external_exports, {
|
|
@@ -19752,6 +19999,7 @@ function date4(params) {
|
|
|
19752
19999
|
var short = (max) => external_exports.string().trim().max(max);
|
|
19753
20000
|
var tags = external_exports.array(external_exports.string().trim().min(1).max(200)).max(50);
|
|
19754
20001
|
var isoDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/, "YYYY-MM-DD");
|
|
20002
|
+
var city = external_exports.string().trim().max(100).transform(normalizeCity);
|
|
19755
20003
|
var eventInput = external_exports.object({
|
|
19756
20004
|
title: short(200).min(1),
|
|
19757
20005
|
date: isoDate,
|
|
@@ -19765,7 +20013,7 @@ var customerShape = {
|
|
|
19765
20013
|
name: short(200).min(1),
|
|
19766
20014
|
company: short(200),
|
|
19767
20015
|
title: short(200),
|
|
19768
|
-
city
|
|
20016
|
+
city,
|
|
19769
20017
|
wechatId: short(100).nullable(),
|
|
19770
20018
|
summary: short(5e3),
|
|
19771
20019
|
painPoints: tags,
|
|
@@ -19816,7 +20064,7 @@ var SCHEMA = {
|
|
|
19816
20064
|
{ name: "name", type: "string", required: true, guide: "\u5BA2\u6237\u59D3\u540D\u3002\u5BF9\u8BDD\u91CC\u51FA\u73B0\u7684\u79F0\u547C\u3001\u6635\u79F0\u82E5\u65E0\u6CD5\u786E\u5B9A\u771F\u540D\uFF0C\u5199\u5BF9\u65B9\u4F7F\u7528\u7684\u540D\u5B57" },
|
|
19817
20065
|
{ name: "company", type: "string", guide: "\u6240\u5728\u516C\u53F8\u6216\u7EC4\u7EC7" },
|
|
19818
20066
|
{ name: "title", type: "string", guide: "\u804C\u4F4D\u6216\u8EAB\u4EFD" },
|
|
19819
|
-
{ name: "city", type: "
|
|
20067
|
+
{ name: "city", type: "enum", values: CITIES, guide: "\u6240\u5728\u57CE\u5E02\u3002\u4F18\u5148\u53D6\u4E0B\u9762\u6E05\u5355\u91CC\u7684\u503C\uFF1B\u5199\u300C\u4E0A\u6D77\u5E02\u300D\u300CShanghai\u300D\u300C\u81FA\u5317\u300D\u4F1A\u81EA\u52A8\u5F52\u4E00\u5316\u6210\u300C\u4E0A\u6D77\u300D\u300C\u4E0A\u6D77\u300D\u300C\u53F0\u5317\u300D\u3002\u6E05\u5355\u5916\u7684\u5199\u6CD5\u4E0D\u4F1A\u62A5\u9519\uFF0C\u539F\u6837\u4FDD\u7559\uFF0C\u4E8B\u540E\u53EF\u5F52\u7C7B\u3002" },
|
|
19820
20068
|
{ name: "wechatId", type: "string", nullable: true, guide: "\u5FAE\u4FE1\u53F7\u3002\u53EA\u5728\u5BF9\u8BDD\u91CC\u660E\u786E\u51FA\u73B0\u65F6\u586B\u5199" },
|
|
19821
20069
|
{ name: "summary", type: "string", guide: "\u4E00\u6BB5\u8BDD\u6982\u62EC\u8FD9\u4E2A\u5BA2\u6237\u662F\u8C01\u3001\u5F53\u524D\u5904\u4E8E\u4EC0\u4E48\u9636\u6BB5" },
|
|
19822
20070
|
{ name: "painPoints", type: "string[]", guide: "\u75DB\u70B9\u6807\u7B7E\uFF0C\u6BCF\u6761\u7B80\u77ED\uFF08\u51E0\u4E2A\u5B57\u5230\u4E00\u53E5\u8BDD\uFF09\u3002\u540C\u4E00\u4E2A\u75DB\u70B9\u590D\u7528\u5DF2\u6709\u6807\u7B7E\u7684\u5199\u6CD5\uFF0C\u4FBF\u4E8E\u6309\u6807\u7B7E\u805A\u5408" },
|
|
@@ -19907,6 +20155,57 @@ function renderPrompt(text, customer) {
|
|
|
19907
20155
|
});
|
|
19908
20156
|
}
|
|
19909
20157
|
|
|
20158
|
+
// package.json
|
|
20159
|
+
var package_default = {
|
|
20160
|
+
name: "insightcrm",
|
|
20161
|
+
version: "0.1.4",
|
|
20162
|
+
description: "Command line and agent skill for InsightCRM: file customers from chats and screenshots with your own AI agent. Non-interactive, --json output, stable exit codes.",
|
|
20163
|
+
license: "MIT",
|
|
20164
|
+
type: "module",
|
|
20165
|
+
bin: {
|
|
20166
|
+
insightcrm: "dist/cli.js",
|
|
20167
|
+
crm: "dist/cli.js"
|
|
20168
|
+
},
|
|
20169
|
+
files: [
|
|
20170
|
+
"dist",
|
|
20171
|
+
"SKILL.md",
|
|
20172
|
+
"README.md"
|
|
20173
|
+
],
|
|
20174
|
+
engines: {
|
|
20175
|
+
node: ">=20"
|
|
20176
|
+
},
|
|
20177
|
+
scripts: {
|
|
20178
|
+
dev: "tsx src/cli.ts",
|
|
20179
|
+
build: "tsup",
|
|
20180
|
+
typecheck: "tsc -p .",
|
|
20181
|
+
prepack: "tsup"
|
|
20182
|
+
},
|
|
20183
|
+
devDependencies: {
|
|
20184
|
+
"@insightcrm/shared": "workspace:*"
|
|
20185
|
+
},
|
|
20186
|
+
dependencies: {
|
|
20187
|
+
commander: "^15.0.0"
|
|
20188
|
+
},
|
|
20189
|
+
keywords: [
|
|
20190
|
+
"crm",
|
|
20191
|
+
"cli",
|
|
20192
|
+
"agent",
|
|
20193
|
+
"mcp",
|
|
20194
|
+
"claude",
|
|
20195
|
+
"customer",
|
|
20196
|
+
"insightcrm"
|
|
20197
|
+
],
|
|
20198
|
+
repository: {
|
|
20199
|
+
type: "git",
|
|
20200
|
+
url: "git+https://github.com/shadowcz007/InsightCRM.git",
|
|
20201
|
+
directory: "packages/cli"
|
|
20202
|
+
},
|
|
20203
|
+
homepage: "https://github.com/shadowcz007/InsightCRM#readme",
|
|
20204
|
+
bugs: {
|
|
20205
|
+
url: "https://github.com/shadowcz007/InsightCRM/issues"
|
|
20206
|
+
}
|
|
20207
|
+
};
|
|
20208
|
+
|
|
19910
20209
|
// src/api.ts
|
|
19911
20210
|
var CliError = class extends Error {
|
|
19912
20211
|
constructor(code, message, exitCode, status) {
|
|
@@ -19922,7 +20221,7 @@ var CliError = class extends Error {
|
|
|
19922
20221
|
var exitFor = (status, code) => status === 401 || ["email_unverified", "banned", "access_denied", "expired_token", "forbidden", "bad_origin"].includes(code) ? EXIT.auth : status === 429 || code === "rate_limited" ? EXIT.quota : status === 400 ? EXIT.usage : status === 409 ? EXIT.failed : EXIT.error;
|
|
19923
20222
|
function createClient(apiUrl, token) {
|
|
19924
20223
|
async function call(method, p, body) {
|
|
19925
|
-
const headers = { "user-agent":
|
|
20224
|
+
const headers = { "user-agent": `insightcrm-cli/${package_default.version}` };
|
|
19926
20225
|
if (token) headers.authorization = `Bearer ${token}`;
|
|
19927
20226
|
let payload;
|
|
19928
20227
|
if (body !== void 0) {
|
|
@@ -20055,56 +20354,61 @@ function defaultLang(env = process.env) {
|
|
|
20055
20354
|
return v.startsWith("zh") ? "zh" : "en";
|
|
20056
20355
|
}
|
|
20057
20356
|
|
|
20058
|
-
//
|
|
20059
|
-
var
|
|
20060
|
-
|
|
20061
|
-
|
|
20062
|
-
|
|
20063
|
-
|
|
20064
|
-
|
|
20065
|
-
|
|
20066
|
-
|
|
20067
|
-
|
|
20068
|
-
|
|
20069
|
-
|
|
20070
|
-
|
|
20071
|
-
|
|
20072
|
-
|
|
20073
|
-
|
|
20074
|
-
|
|
20075
|
-
|
|
20076
|
-
|
|
20077
|
-
|
|
20078
|
-
|
|
20079
|
-
|
|
20080
|
-
|
|
20081
|
-
|
|
20082
|
-
|
|
20083
|
-
|
|
20084
|
-
|
|
20085
|
-
|
|
20086
|
-
|
|
20087
|
-
|
|
20088
|
-
|
|
20089
|
-
|
|
20090
|
-
|
|
20091
|
-
|
|
20092
|
-
|
|
20093
|
-
"mcp",
|
|
20094
|
-
"claude",
|
|
20095
|
-
"customer",
|
|
20096
|
-
"insightcrm"
|
|
20097
|
-
],
|
|
20098
|
-
repository: {
|
|
20099
|
-
type: "git",
|
|
20100
|
-
url: "git+https://github.com/shadowcz007/InsightCRM.git",
|
|
20101
|
-
directory: "packages/cli"
|
|
20102
|
-
},
|
|
20103
|
-
homepage: "https://github.com/shadowcz007/InsightCRM#readme",
|
|
20104
|
-
bugs: {
|
|
20105
|
-
url: "https://github.com/shadowcz007/InsightCRM/issues"
|
|
20357
|
+
// src/version.ts
|
|
20358
|
+
var REGISTRY_PACKAGE = package_default.name.replace("/", "%2f");
|
|
20359
|
+
var REGISTRY_URL = `https://registry.npmjs.org/${REGISTRY_PACKAGE}`;
|
|
20360
|
+
var UPDATE_COMMAND = `npm i -g ${package_default.name}`;
|
|
20361
|
+
function parseVersion(v) {
|
|
20362
|
+
const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(v.trim());
|
|
20363
|
+
if (!m) return null;
|
|
20364
|
+
return { parts: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split(".") : [] };
|
|
20365
|
+
}
|
|
20366
|
+
function compareVersions(a, b) {
|
|
20367
|
+
const pa = parseVersion(a);
|
|
20368
|
+
const pb = parseVersion(b);
|
|
20369
|
+
if (!pa || !pb) return 0;
|
|
20370
|
+
for (let i = 0; i < 3; i++) {
|
|
20371
|
+
const d = pa.parts[i] - pb.parts[i];
|
|
20372
|
+
if (d !== 0) return d < 0 ? -1 : 1;
|
|
20373
|
+
}
|
|
20374
|
+
if (pa.pre.length === 0 && pb.pre.length === 0) return 0;
|
|
20375
|
+
if (pa.pre.length === 0) return 1;
|
|
20376
|
+
if (pb.pre.length === 0) return -1;
|
|
20377
|
+
const len = Math.max(pa.pre.length, pb.pre.length);
|
|
20378
|
+
for (let i = 0; i < len; i++) {
|
|
20379
|
+
const x = pa.pre[i];
|
|
20380
|
+
const y = pb.pre[i];
|
|
20381
|
+
if (x === void 0) return -1;
|
|
20382
|
+
if (y === void 0) return 1;
|
|
20383
|
+
const nx = /^\d+$/.test(x) ? Number(x) : null;
|
|
20384
|
+
const ny = /^\d+$/.test(y) ? Number(y) : null;
|
|
20385
|
+
if (nx !== null && ny !== null) {
|
|
20386
|
+
if (nx !== ny) return nx < ny ? -1 : 1;
|
|
20387
|
+
continue;
|
|
20388
|
+
}
|
|
20389
|
+
if (nx !== null) return -1;
|
|
20390
|
+
if (ny !== null) return 1;
|
|
20391
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
20106
20392
|
}
|
|
20107
|
-
|
|
20393
|
+
return 0;
|
|
20394
|
+
}
|
|
20395
|
+
async function fetchLatestVersion(opts = {}) {
|
|
20396
|
+
const { timeoutMs = 5e3, fetchImpl = fetch, registry: registry2 = REGISTRY_URL } = opts;
|
|
20397
|
+
const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
20398
|
+
try {
|
|
20399
|
+
const res = await fetchImpl(`${registry2}/latest`, {
|
|
20400
|
+
headers: { accept: "application/json", "user-agent": `insightcrm-cli/${package_default.version}` },
|
|
20401
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
20402
|
+
});
|
|
20403
|
+
if (!res.ok) return { version: "", checkedAt, error: `npm registry returned HTTP ${res.status}` };
|
|
20404
|
+
const body = await res.json().catch(() => null);
|
|
20405
|
+
const version2 = typeof body?.version === "string" ? body.version : "";
|
|
20406
|
+
if (!version2) return { version: "", checkedAt, error: "npm registry response had no version" };
|
|
20407
|
+
return { version: version2, checkedAt };
|
|
20408
|
+
} catch (e) {
|
|
20409
|
+
return { version: "", checkedAt, error: e.message };
|
|
20410
|
+
}
|
|
20411
|
+
}
|
|
20108
20412
|
|
|
20109
20413
|
// src/cli.ts
|
|
20110
20414
|
var program = new Command().name("crm").description("InsightCRM command line: read and write your customer records. The AI lives in your agent, not here.").version(package_default.version).addOption(new Option("--json", "print one JSON object to stdout (also CRM_JSON=1)").default(process.env.CRM_JSON === "1")).option("-n, --server <name>", "use a saved server for this command (env CRM_SERVER); see `crm servers`").option("--api-url <url>", "server URL, overrides the saved one (env CRM_API_URL)").option("--token <token>", "API token, overrides the saved one (env CRM_TOKEN)").showHelpAfterError().addHelpText(
|
|
@@ -20353,11 +20657,31 @@ program.command("skill").description("Print the agent instructions (SKILL.md) fo
|
|
|
20353
20657
|
if (g().json) out("", { path: src, content: text });
|
|
20354
20658
|
else process.stdout.write(text);
|
|
20355
20659
|
});
|
|
20660
|
+
program.command("version").description("Show the installed version and check npm for a newer one.").option("--offline", "don't contact npm; just report the installed version").action(async (o) => {
|
|
20661
|
+
const current = package_default.version;
|
|
20662
|
+
if (o.offline) {
|
|
20663
|
+
out(`insightcrm ${current}
|
|
20664
|
+
latest (not checked)`, { current, latest: null, updateAvailable: null, checked: false, error: null, updateCommand: UPDATE_COMMAND });
|
|
20665
|
+
return;
|
|
20666
|
+
}
|
|
20667
|
+
const res = await fetchLatestVersion();
|
|
20668
|
+
const latest = res.error ? null : res.version;
|
|
20669
|
+
const updateAvailable = latest ? compareVersions(latest, current) > 0 : null;
|
|
20670
|
+
let latestLine;
|
|
20671
|
+
if (!latest) latestLine = `unknown (couldn't reach npm: ${res.error ?? "unknown error"})`;
|
|
20672
|
+
else if (updateAvailable) latestLine = `${latest} (new version available)`;
|
|
20673
|
+
else latestLine = `${latest} (up to date)`;
|
|
20674
|
+
const human = [`insightcrm ${current}`, `latest ${latestLine}`, ...updateAvailable ? [`update ${UPDATE_COMMAND}`] : []].join("\n");
|
|
20675
|
+
out(human, { current, latest, updateAvailable, checked: !res.error, error: res.error ?? null, updateCommand: UPDATE_COMMAND });
|
|
20676
|
+
});
|
|
20356
20677
|
program.command("schema").description('Field definitions AND filling guidance: the contract for writing records. Read the "guide" of every field before you add.').addOption(new Option("--entity <name>", "only this entity").choices([...ENTITIES])).action(async (o) => {
|
|
20357
20678
|
const entities = (o.entity ? [o.entity] : [...ENTITIES]).map((e) => ({ entity: e, ...SCHEMA[e] }));
|
|
20358
20679
|
const human = entities.map((e) => `# ${e.entity}: ${e.description}
|
|
20359
|
-
` + e.fields.map((f) =>
|
|
20360
|
-
|
|
20680
|
+
` + e.fields.map((f) => {
|
|
20681
|
+
const values = !f.values ? "" : f.values.length > 12 ? ` (${f.values.length} allowed values \u2014 see --json)` : ` (${f.values.join("|")})`;
|
|
20682
|
+
return ` ${f.name}${f.required ? "*" : ""} ${f.type}${values}
|
|
20683
|
+
${f.guide}`;
|
|
20684
|
+
}).join("\n")).join("\n\n");
|
|
20361
20685
|
out(human, { entities });
|
|
20362
20686
|
});
|
|
20363
20687
|
withCustomerOptions(
|
|
@@ -20442,6 +20766,21 @@ rec.command("rm").argument("<id>").option("-y, --yes").action(async (id, o) => {
|
|
|
20442
20766
|
out(`Deleted ${id}`, { ok: true, id });
|
|
20443
20767
|
});
|
|
20444
20768
|
var prompts = program.command("prompts").description("Prompt templates for your agent: extraction rules and task presets (draft a message, gift ideas\u2026). Built-in defaults you can override.");
|
|
20769
|
+
prompts.addHelpText(
|
|
20770
|
+
"after",
|
|
20771
|
+
`
|
|
20772
|
+
When to use (agents):
|
|
20773
|
+
extraction-rules Before \`add\` / \`update\` when extracting from chats or screenshots: \`prompts show extraction-rules\`, and follow it.
|
|
20774
|
+
draft / gift / starters / advice
|
|
20775
|
+
When the user asks for that task: \`prompts show <id> --customer <id>\` first, then do it.
|
|
20776
|
+
{{name}} {{company}} {{title}} {{city}} {{wechatId}} are filled from the customer; --json also returns the profile.
|
|
20777
|
+
\`draft\` has a placeholder ([\u8BF7\u8865\u5145] / [Insert Topic]): ask the user for the topic before answering.
|
|
20778
|
+
|
|
20779
|
+
Notes:
|
|
20780
|
+
Templates are stored on this machine only (~/.config/insightcrm/prompts.json); the web app does not show them and they do not sync.
|
|
20781
|
+
\`set <id>\` overrides a built-in or adds your own; \`reset <id>\` / \`reset --all\` undoes it.
|
|
20782
|
+
`
|
|
20783
|
+
);
|
|
20445
20784
|
var langOption = () => new Option("--lang <lang>", "language of the built-in templates (default: CRM_LANG, then the system language)").choices([...PROMPT_LANGS]);
|
|
20446
20785
|
var langOf = (o) => o.lang ?? defaultLang();
|
|
20447
20786
|
prompts.command("list").description("List templates. `customized` marks the ones you changed or added.").addOption(langOption()).action(async (o) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insightcrm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Command line and agent skill for InsightCRM: file customers from chats and screenshots with your own AI agent. Non-interactive, --json output, stable exit codes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|