@segmentstream/agent 0.40.1 → 0.42.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.
Files changed (33) hide show
  1. package/README.md +12 -0
  2. package/dist/_chunks/{build-metadata-D8Vmcz9g.mjs → build-metadata-CUyA2hlu.mjs} +1 -1
  3. package/dist/extension/channels/telegram.mjs +5 -1
  4. package/dist/extension/channels/whatsapp.mjs +7 -1
  5. package/dist/extension/config.d.ts +24 -0
  6. package/dist/extension/config.mjs +6 -2
  7. package/dist/extension/conventions.d.ts +5 -2
  8. package/dist/extension/conventions.mjs +32 -0
  9. package/dist/extension/hooks/conversations.mjs +4 -1
  10. package/dist/extension/lib/build-metadata.mjs +1 -1
  11. package/dist/extension/lib/conversation-runtime.d.ts +6 -1
  12. package/dist/extension/lib/conversation-runtime.mjs +2 -2
  13. package/dist/extension/lib/identities.d.ts +6 -0
  14. package/dist/extension/lib/identities.mjs +1 -1
  15. package/dist/extension/lib/review/client.d.ts +13 -0
  16. package/dist/extension/lib/review/client.mjs +58 -0
  17. package/dist/extension/lib/review/hold.d.ts +64 -0
  18. package/dist/extension/lib/review/hold.mjs +59 -0
  19. package/dist/extension/lib/review/judge.d.ts +58 -0
  20. package/dist/extension/lib/review/judge.mjs +67 -0
  21. package/dist/extension/lib/review/reply.d.ts +65 -0
  22. package/dist/extension/lib/review/reply.mjs +159 -0
  23. package/dist/extension/lib/telegram/adapter.d.ts +6 -0
  24. package/dist/extension/lib/telegram/adapter.mjs +12 -2
  25. package/dist/extension/lib/telegram/health.mjs +1 -1
  26. package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
  27. package/dist/extension/lib/telegram/silent.d.ts +4 -2
  28. package/dist/extension/lib/telegram/silent.mjs +10 -1
  29. package/dist/extension/lib/whatsapp/adapter.d.ts +13 -3
  30. package/dist/extension/lib/whatsapp/adapter.mjs +21 -4
  31. package/dist/extension/review.d.ts +65 -0
  32. package/dist/extension/review.mjs +171 -0
  33. package/package.json +2 -2
@@ -0,0 +1,171 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ const REVIEW_DIRECTORY = "review";
8
+ const MAXIMUM_CRITERIA_LENGTH = 8e3;
9
+ const DEFAULT_CONVERSATION = "default";
10
+ const REVIEW_MODES = [
11
+ "never",
12
+ "always",
13
+ "whenUnsure"
14
+ ];
15
+ const SEND_REPLIES = { review: { mode: "never" } };
16
+ const FILE_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
17
+ function isRecord(value) {
18
+ return typeof value === "object" && value !== null && !Array.isArray(value);
19
+ }
20
+ function reviewFile(key) {
21
+ return FILE_NAME.test(key) ? `${REVIEW_DIRECTORY}/${key}.md` : void 0;
22
+ }
23
+ function conversationFor(settings, roles) {
24
+ if (settings === void 0) return SEND_REPLIES;
25
+ for (const [role, conversation] of Object.entries(settings.byRole)) if (roles.includes(role)) return conversation;
26
+ return settings.default;
27
+ }
28
+ function review(value, path, issues) {
29
+ if (!isRecord(value)) {
30
+ issues.push({
31
+ message: "must be an object with mode \"never\", \"always\" or \"whenUnsure\"",
32
+ path
33
+ });
34
+ return;
35
+ }
36
+ const mode = value.mode;
37
+ if (!REVIEW_MODES.some((candidate) => candidate === mode)) {
38
+ issues.push({
39
+ message: "must be \"never\", \"always\" or \"whenUnsure\"",
40
+ path: [...path, "mode"]
41
+ });
42
+ return;
43
+ }
44
+ const allowed = mode === "whenUnsure" ? [
45
+ "mode",
46
+ "minConfidence",
47
+ "criteria"
48
+ ] : ["mode"];
49
+ for (const key of Object.keys(value)) if (!allowed.includes(key)) issues.push({
50
+ message: key === "minConfidence" ? "applies only to mode \"whenUnsure\"" : key === "criteria" ? `is written in agent/${REVIEW_DIRECTORY}/<role>.md, and applies only to mode "whenUnsure"` : "is not a known setting",
51
+ path: [...path, key]
52
+ });
53
+ if (mode !== "whenUnsure") return { mode };
54
+ const minConfidence = value.minConfidence;
55
+ if (typeof minConfidence !== "number" || !Number.isFinite(minConfidence) || minConfidence <= 0 || minConfidence > 1) {
56
+ issues.push({
57
+ message: "must be a number greater than 0 and at most 1",
58
+ path: [...path, "minConfidence"]
59
+ });
60
+ return;
61
+ }
62
+ if (value.criteria !== void 0 && (typeof value.criteria !== "string" || value.criteria.trim() === "")) {
63
+ issues.push({
64
+ message: "must be text",
65
+ path: [...path, "criteria"]
66
+ });
67
+ return;
68
+ }
69
+ if (typeof value.criteria === "string" && value.criteria.length > 8e3) {
70
+ issues.push({
71
+ message: "is longer than the 8,000 characters the decision model reads: shorten agent/review/<role>.md",
72
+ path: [...path, "criteria"]
73
+ });
74
+ return;
75
+ }
76
+ return {
77
+ mode,
78
+ minConfidence,
79
+ ...typeof value.criteria === "string" ? { criteria: value.criteria } : {}
80
+ };
81
+ }
82
+ function conversation(value, path, issues) {
83
+ if (!isRecord(value)) {
84
+ issues.push({
85
+ message: "must be an object",
86
+ path
87
+ });
88
+ return;
89
+ }
90
+ for (const key of Object.keys(value)) if (key !== "review") issues.push({
91
+ message: "is not a known setting",
92
+ path: [...path, key]
93
+ });
94
+ if (value.review === void 0) {
95
+ issues.push({
96
+ message: "is required",
97
+ path: [...path, "review"]
98
+ });
99
+ return;
100
+ }
101
+ const settings = review(value.review, [...path, "review"], issues);
102
+ return settings === void 0 ? void 0 : { review: settings };
103
+ }
104
+ function role(value) {
105
+ return value.trim() !== "" && value.trim() === value;
106
+ }
107
+ function conversationsSettings(value, issues) {
108
+ const path = ["conversations"];
109
+ if (value === void 0) return;
110
+ if (!isRecord(value)) {
111
+ issues.push({
112
+ message: "must be an object",
113
+ path
114
+ });
115
+ return;
116
+ }
117
+ for (const key of Object.keys(value)) if (key !== "byRole" && key !== "default") issues.push({
118
+ message: "is not a known setting",
119
+ path: [...path, key]
120
+ });
121
+ if (value.byRole === void 0 && value.default === void 0) issues.push({
122
+ message: "needs byRole, default or both",
123
+ path
124
+ });
125
+ const byRole = {};
126
+ if (value.byRole !== void 0) {
127
+ if (!isRecord(value.byRole)) issues.push({
128
+ message: "must be an object of role to settings",
129
+ path: [...path, "byRole"]
130
+ });
131
+ else for (const [name, entry] of Object.entries(value.byRole)) {
132
+ if (!role(name)) {
133
+ issues.push({
134
+ message: "must be a role name",
135
+ path: [
136
+ ...path,
137
+ "byRole",
138
+ name
139
+ ]
140
+ });
141
+ continue;
142
+ }
143
+ const settings = conversation(entry, [
144
+ ...path,
145
+ "byRole",
146
+ name
147
+ ], issues);
148
+ if (settings !== void 0) byRole[name] = settings;
149
+ }
150
+ }
151
+ return {
152
+ byRole,
153
+ default: (value.default === void 0 ? SEND_REPLIES : conversation(value.default, [...path, "default"], issues)) ?? SEND_REPLIES
154
+ };
155
+ }
156
+ function criteriaFiles(value) {
157
+ if (!isRecord(value)) return [];
158
+ return [...isRecord(value.byRole) ? Object.entries(value.byRole).map(([name, entry]) => ({
159
+ path: ["byRole", name],
160
+ entry,
161
+ file: reviewFile(name)
162
+ })) : [], {
163
+ path: [DEFAULT_CONVERSATION],
164
+ entry: value.default,
165
+ file: reviewFile(DEFAULT_CONVERSATION)
166
+ }].flatMap(({ path, entry, file }) => file !== void 0 && isRecord(entry) && isRecord(entry.review) && entry.review.mode === "whenUnsure" ? [{
167
+ path,
168
+ file
169
+ }] : []);
170
+ }
171
+ export { DEFAULT_CONVERSATION, MAXIMUM_CRITERIA_LENGTH, REVIEW_DIRECTORY, REVIEW_MODES, SEND_REPLIES, conversationFor, conversationsSettings, criteriaFiles, reviewFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.40.1",
3
+ "version": "0.42.0",
4
4
  "description": "Mount a SegmentStream workspace's agent on eve: the ontology as tools, acting as the member who writes, and Telegram, WhatsApp and Slack through the workspace's connections.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",
@@ -76,7 +76,7 @@
76
76
  "@chat-adapter/state-memory": "4.42.0",
77
77
  "@chat-adapter/telegram": "4.41.0",
78
78
  "@chat-adapter/whatsapp": "4.42.0",
79
- "@segmentstream/ontology": "0.97.0",
79
+ "@segmentstream/ontology": "0.98.0",
80
80
  "@vercel/oidc": "^3.8.4",
81
81
  "ai": "^7.0.137",
82
82
  "chat": "4.42.0",