@segmentstream/agent 0.100.0 → 0.102.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/CHANGELOG.md +43 -0
- package/dist/_chunks/{build-metadata-fPSw1vHg.mjs → build-metadata-BtB38zQ0.mjs} +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/connection-proxy.d.ts +12 -1
- package/dist/extension/lib/connection-proxy.mjs +24 -3
- package/dist/extension/lib/email/channel.d.ts +2 -0
- package/dist/extension/lib/email/channel.mjs +45 -11
- package/dist/extension/lib/review/client.d.ts +75 -0
- package/dist/extension/lib/review/client.mjs +103 -1
- package/dist/extension/lib/review/hold.d.ts +24 -0
- package/dist/extension/lib/review/hold.mjs +31 -1
- package/dist/extension/lib/review/reply.d.ts +54 -1
- package/dist/extension/lib/review/reply.mjs +150 -78
- package/dist/extension/lib/sent-files.d.ts +24 -8
- package/dist/extension/lib/sent-files.mjs +39 -2
- package/dist/extension/lib/slack/attachments-send.d.ts +5 -4
- package/dist/extension/lib/slack/attachments-send.mjs +24 -24
- package/dist/extension/lib/telegram/adapter.mjs +1 -1
- package/dist/extension/lib/telegram/attachments-send.mjs +36 -31
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
- package/dist/extension/lib/whatsapp/attachments-send.d.ts +12 -0
- package/dist/extension/lib/whatsapp/attachments-send.mjs +10 -17
- package/dist/extension/lib/workspace-channel/channel.d.ts +6 -6
- package/dist/extension/lib/workspace-channel/channel.mjs +14 -20
- package/dist/extension/review.d.ts +20 -23
- package/dist/extension/review.mjs +14 -15
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Channel, type ChannelEvents } from "eve/channels";
|
|
2
2
|
import type { SessionAuthContext } from "eve/context";
|
|
3
|
-
import { type WorkspaceChannelRefusal } from "@segmentstream/ontology/workspace-channel";
|
|
3
|
+
import { splitReply, type WorkspaceChannelRefusal } from "@segmentstream/ontology/workspace-channel";
|
|
4
4
|
import { type SegmentStreamAgentConfigInput } from "../../config.js";
|
|
5
5
|
import { type AgentAttachments } from "../attachments.js";
|
|
6
6
|
import { type ChatArchive } from "../chat-archive.js";
|
|
@@ -10,6 +10,7 @@ import { type AgentIdentities, type PairedMember } from "../identities.js";
|
|
|
10
10
|
import { type CapabilityLookup } from "../inbound-media/plan.js";
|
|
11
11
|
import { type ImageDescriber } from "../inbound-media/images.js";
|
|
12
12
|
import { type Transcriber } from "../inbound-media/speech.js";
|
|
13
|
+
import type { ProposeReply } from "../review/client.js";
|
|
13
14
|
import type { HoldReply } from "../review/hold.js";
|
|
14
15
|
import type { ReviewDecideFunction } from "../review/judge.js";
|
|
15
16
|
import { type RuntimeTokenVerifier } from "../runtime-identity.js";
|
|
@@ -265,6 +266,8 @@ export interface WorkspaceChannelOptions extends ChannelDefinition {
|
|
|
265
266
|
/** Tests pass an archive and a hold in place of the ontology's. */
|
|
266
267
|
readonly archive?: ChatArchive;
|
|
267
268
|
readonly hold?: HoldReply;
|
|
269
|
+
/** Tests pass a proposal in place of the ontology's. */
|
|
270
|
+
readonly propose?: ProposeReply;
|
|
268
271
|
};
|
|
269
272
|
readonly environment?: Environment;
|
|
270
273
|
readonly token?: RuntimeToken;
|
|
@@ -289,11 +292,8 @@ export interface WorkspaceChannelOptions extends ChannelDefinition {
|
|
|
289
292
|
* delivery is answered 413.
|
|
290
293
|
*/
|
|
291
294
|
export declare const MAXIMUM_MESSAGES = 50;
|
|
292
|
-
/**
|
|
293
|
-
|
|
294
|
-
* else where the length ends.
|
|
295
|
-
*/
|
|
296
|
-
export declare function splitReply(text: string, maxLength: number | undefined): ReadonlyArray<string>;
|
|
295
|
+
/** A reply in parts the provider takes, as the ontology splits a turn's reply it sends. */
|
|
296
|
+
export { splitReply };
|
|
297
297
|
/**
|
|
298
298
|
* The principal of a workspace channel's session: the member who writes from the account, on the
|
|
299
299
|
* channel, in their private chat with it.
|
|
@@ -32,7 +32,7 @@ import { ChannelCheckUnavailable, channelChecks } from "./secrets.mjs";
|
|
|
32
32
|
import { decide } from "eve/ai";
|
|
33
33
|
import { createHash, createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
34
34
|
import { reply } from "eve/events";
|
|
35
|
-
import { WORKSPACE_CHANNEL_FILES_BYTES, WORKSPACE_CHANNEL_ID, WORKSPACE_CHANNEL_MAXIMUM_FILES_BYTES, isWorkspaceChannelRefusal, workspaceChannelRoute, workspaceChannelSendRoute } from "@segmentstream/ontology/workspace-channel";
|
|
35
|
+
import { WORKSPACE_CHANNEL_FILES_BYTES, WORKSPACE_CHANNEL_ID, WORKSPACE_CHANNEL_MAXIMUM_FILES_BYTES, isWorkspaceChannelRefusal, splitReply, workspaceChannelRoute, workspaceChannelSendRoute } from "@segmentstream/ontology/workspace-channel";
|
|
36
36
|
import { POST, defineChannel as defineChannel$1 } from "eve/channels";
|
|
37
37
|
const WORKSPACE_CHANNEL_AUTHENTICATOR = "segmentstream-channel";
|
|
38
38
|
const MAXIMUM_CURSOR_LENGTH = 16384;
|
|
@@ -169,23 +169,6 @@ function validEvent(value) {
|
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
|
-
function splitReply(text, maxLength) {
|
|
173
|
-
if (maxLength === void 0 || text.length <= maxLength) return [text];
|
|
174
|
-
const parts = [];
|
|
175
|
-
let rest = text;
|
|
176
|
-
while (rest.length > maxLength) {
|
|
177
|
-
const window = rest.slice(0, maxLength);
|
|
178
|
-
const end = [
|
|
179
|
-
window.lastIndexOf("\n\n"),
|
|
180
|
-
window.lastIndexOf("\n"),
|
|
181
|
-
window.lastIndexOf(" ")
|
|
182
|
-
].find((index) => index > 0) ?? maxLength;
|
|
183
|
-
parts.push(rest.slice(0, end).trimEnd());
|
|
184
|
-
rest = rest.slice(end).trimStart();
|
|
185
|
-
}
|
|
186
|
-
if (rest !== "") parts.push(rest);
|
|
187
|
-
return parts;
|
|
188
|
-
}
|
|
189
172
|
function replyText(view, turnId) {
|
|
190
173
|
return reply(view, turnId).filter((part) => part.kind === "text" && part.interrupted !== true).flatMap((part) => typeof part.value === "string" ? [part.value] : []).join("\n").trim();
|
|
191
174
|
}
|
|
@@ -290,6 +273,7 @@ function workspaceChannelDefinition(options) {
|
|
|
290
273
|
model: () => config.models.decision,
|
|
291
274
|
...options.review.archive === void 0 ? {} : { archive: options.review.archive },
|
|
292
275
|
...options.review.hold === void 0 ? {} : { hold: options.review.hold },
|
|
276
|
+
...options.review.propose === void 0 ? {} : { propose: options.review.propose },
|
|
293
277
|
sendFiles: replyFilesSender(() => config.channels)
|
|
294
278
|
}, {
|
|
295
279
|
environment,
|
|
@@ -766,14 +750,24 @@ function workspaceChannelDefinition(options) {
|
|
|
766
750
|
});
|
|
767
751
|
return;
|
|
768
752
|
}
|
|
769
|
-
|
|
753
|
+
const reply = {
|
|
770
754
|
principal,
|
|
771
755
|
sessionId: ctx.session.id,
|
|
772
756
|
turnId,
|
|
773
757
|
partId: turnId,
|
|
774
758
|
text,
|
|
775
759
|
...files === void 0 || files.files.length === 0 ? {} : { files }
|
|
776
|
-
}
|
|
760
|
+
};
|
|
761
|
+
const proposed = reviewing !== void 0 && reviewing.proposes(principal) ? await reviewing.propose({
|
|
762
|
+
...reply,
|
|
763
|
+
...maxLength === void 0 ? {} : { maxLength }
|
|
764
|
+
}) : void 0;
|
|
765
|
+
if (proposed?.by === "ontology") {
|
|
766
|
+
if (proposed.outcome !== "sent" && proposed.outcome !== "held") report("reply_failed", new Error(`The ontology's send of the reply was ${proposed.outcome}` + (proposed.refusal === void 0 ? "." : ` (${proposed.refusal}).`)));
|
|
767
|
+
else if (proposed.outcome === "sent" && proposed.files !== void 0 && proposed.files !== "sent") report("reply_files_failed", new Error(`The ontology's send of the reply's files was ${proposed.files}.`));
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (!(proposed !== void 0 ? proposed.send : reviewing === void 0 ? true : await reviewing.sendOrHold(reply))) return;
|
|
777
771
|
let parts;
|
|
778
772
|
try {
|
|
779
773
|
parts = await deliver({
|
|
@@ -15,33 +15,33 @@
|
|
|
15
15
|
* as persona texts are: by the SDK when the agent is built, and put inline by the platform when it
|
|
16
16
|
* deploys.
|
|
17
17
|
*/
|
|
18
|
+
import { DEFAULT_REVIEW, REVIEW_MODES, reviewFor, SEND_REPLIES, type Review as PolicyReview, type ReviewMode, type ReviewSettings as PolicySettings } from "@segmentstream/ontology/review";
|
|
18
19
|
/** The directory beside `segmentstream.json` that holds the review criteria. */
|
|
19
20
|
export declare const REVIEW_DIRECTORY = "review";
|
|
20
21
|
/** The longest criteria the decision model reads; longer ones fail validation. */
|
|
21
22
|
export declare const MAXIMUM_CRITERIA_LENGTH = 8000;
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The modes, the default's key and which review applies to a person are the policy's, which the
|
|
25
|
+
* ontology service applies with the person's current roles: one source for both
|
|
26
|
+
* (`@segmentstream/ontology/review`).
|
|
27
|
+
*/
|
|
28
|
+
export { DEFAULT_REVIEW, REVIEW_MODES, reviewFor, SEND_REPLIES, type ReviewMode };
|
|
29
|
+
/** A review as the agent declares it: the policy's, with a `whenUnsure` review's criteria. */
|
|
30
|
+
export type Review = Exclude<PolicyReview, {
|
|
31
|
+
readonly mode: "whenUnsure";
|
|
32
|
+
}> | (Extract<PolicyReview, {
|
|
31
33
|
readonly mode: "whenUnsure";
|
|
32
|
-
|
|
33
|
-
readonly minConfidence: number;
|
|
34
|
+
}> & {
|
|
34
35
|
/** `agent/review/<role>.md`: what staff check a reply for. Put inline, not written by hand. */
|
|
35
36
|
readonly criteria?: string;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export declare const SEND_REPLIES: Review;
|
|
37
|
+
});
|
|
38
|
+
/** The review per role of the person the agent replies to; the first role they hold wins. */
|
|
39
|
+
export type ReviewSettings = PolicySettings<Review>;
|
|
40
|
+
/**
|
|
41
|
+
* The policy of `settings` as the ontology service applies it: every mode and threshold, without
|
|
42
|
+
* the criteria, which never leave the agent.
|
|
43
|
+
*/
|
|
44
|
+
export declare function reviewPolicy(settings: ReviewSettings): PolicySettings;
|
|
45
45
|
/** One validation failure, in Standard Schema's issue shape. */
|
|
46
46
|
interface Issue {
|
|
47
47
|
readonly message: string;
|
|
@@ -49,8 +49,6 @@ interface Issue {
|
|
|
49
49
|
}
|
|
50
50
|
/** The path of a key's criteria, relative to the directory of `segmentstream.json`. */
|
|
51
51
|
export declare function reviewFile(key: string): string | undefined;
|
|
52
|
-
/** The review for a person with `roles`: the first `byRole` entry they hold, or the default. */
|
|
53
|
-
export declare function reviewFor(settings: ReviewSettings | undefined, roles: ReadonlyArray<string>): Review;
|
|
54
52
|
/** Validates `review` of `agent/segmentstream.json`; `undefined` when absent. */
|
|
55
53
|
export declare function reviewSettings(value: unknown, issues: Issue[]): ReviewSettings | undefined;
|
|
56
54
|
/**
|
|
@@ -67,4 +65,3 @@ export declare function criteriaFiles(value: unknown): ReadonlyArray<{
|
|
|
67
65
|
readonly path: ReadonlyArray<string>;
|
|
68
66
|
readonly file: string;
|
|
69
67
|
}>;
|
|
70
|
-
export {};
|
|
@@ -4,15 +4,19 @@ import { createRequire as __eveCreateRequire } from "node:module";
|
|
|
4
4
|
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import { DEFAULT_REVIEW, REVIEW_MODES, SEND_REPLIES, reviewFor } from "@segmentstream/ontology/review";
|
|
7
8
|
const REVIEW_DIRECTORY = "review";
|
|
8
9
|
const MAXIMUM_CRITERIA_LENGTH = 8e3;
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
function reviewPolicy(settings) {
|
|
11
|
+
const policy = (review) => review.mode === "whenUnsure" ? {
|
|
12
|
+
mode: review.mode,
|
|
13
|
+
minConfidence: review.minConfidence
|
|
14
|
+
} : { mode: review.mode };
|
|
15
|
+
return {
|
|
16
|
+
byRole: Object.fromEntries(Object.entries(settings.byRole).map(([role, review]) => [role, policy(review)])),
|
|
17
|
+
default: policy(settings.default)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
16
20
|
const FILE_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
17
21
|
function isRecord(value) {
|
|
18
22
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -20,11 +24,6 @@ function isRecord(value) {
|
|
|
20
24
|
function reviewFile(key) {
|
|
21
25
|
return FILE_NAME.test(key) ? `${REVIEW_DIRECTORY}/${key}.md` : void 0;
|
|
22
26
|
}
|
|
23
|
-
function reviewFor(settings, roles) {
|
|
24
|
-
if (settings === void 0) return SEND_REPLIES;
|
|
25
|
-
for (const [role, review] of Object.entries(settings.byRole)) if (roles.includes(role)) return review;
|
|
26
|
-
return settings.default;
|
|
27
|
-
}
|
|
28
27
|
function review(value, path, issues) {
|
|
29
28
|
if (!isRecord(value)) {
|
|
30
29
|
issues.push({
|
|
@@ -92,7 +91,7 @@ function reviewSettings(value, issues) {
|
|
|
92
91
|
});
|
|
93
92
|
return;
|
|
94
93
|
}
|
|
95
|
-
for (const key of Object.keys(value)) if (key !== "byRole" && key !==
|
|
94
|
+
for (const key of Object.keys(value)) if (key !== "byRole" && key !== DEFAULT_REVIEW) issues.push({
|
|
96
95
|
message: "is not a known setting",
|
|
97
96
|
path: [...path, key]
|
|
98
97
|
});
|
|
@@ -128,7 +127,7 @@ function reviewSettings(value, issues) {
|
|
|
128
127
|
}
|
|
129
128
|
return {
|
|
130
129
|
byRole,
|
|
131
|
-
default: (value.default === void 0 ? SEND_REPLIES : review(value.default, [...path,
|
|
130
|
+
default: (value.default === void 0 ? SEND_REPLIES : review(value.default, [...path, DEFAULT_REVIEW], issues)) ?? SEND_REPLIES
|
|
132
131
|
};
|
|
133
132
|
}
|
|
134
133
|
function earlierReviewInput(value) {
|
|
@@ -155,4 +154,4 @@ function criteriaFiles(value) {
|
|
|
155
154
|
file
|
|
156
155
|
}] : []);
|
|
157
156
|
}
|
|
158
|
-
export { DEFAULT_REVIEW, MAXIMUM_CRITERIA_LENGTH, REVIEW_DIRECTORY, REVIEW_MODES, SEND_REPLIES, criteriaFiles, earlierReviewInput, reviewFile, reviewFor, reviewSettings };
|
|
157
|
+
export { DEFAULT_REVIEW, MAXIMUM_CRITERIA_LENGTH, REVIEW_DIRECTORY, REVIEW_MODES, SEND_REPLIES, criteriaFiles, earlierReviewInput, reviewFile, reviewFor, reviewPolicy, reviewSettings };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.102.0",
|
|
4
4
|
"description": "The SegmentStream workspace agent: the ontology as tools, acting as the member who writes, and the browser, Telegram, WhatsApp and Slack through the workspace's connections.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"@chat-adapter/state-memory": "4.42.0",
|
|
89
89
|
"@chat-adapter/telegram": "4.41.0",
|
|
90
90
|
"@chat-adapter/whatsapp": "4.42.0",
|
|
91
|
-
"@segmentstream/ontology": "0.
|
|
91
|
+
"@segmentstream/ontology": "0.181.0",
|
|
92
92
|
"@vercel/oidc": "^3.8.4",
|
|
93
93
|
"ai": "^7.0.172",
|
|
94
94
|
"chat": "4.42.0",
|