@segmentstream/agent 0.99.0 → 0.100.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 +6 -0
- package/README.md +8 -0
- package/dist/_chunks/{build-metadata-BdnkQsB3.mjs → build-metadata-fPSw1vHg.mjs} +1 -1
- package/dist/extension/config.d.ts +2 -0
- package/dist/extension/config.mjs +5 -3
- package/dist/extension/extension.d.ts +1 -0
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-persona.d.ts +1 -1
- package/dist/extension/lib/chat-persona.mjs +2 -2
- package/dist/extension/lib/public-group.d.ts +9 -0
- package/dist/extension/lib/public-group.mjs +28 -4
- package/dist/extension/lib/telegram/adapter.mjs +1 -1
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.100.0
|
|
4
|
+
|
|
5
|
+
Opened groups can use a workspace-authored response handler and one explicitly granted ontology action. The action acts for a sender scoped to that group.
|
|
6
|
+
|
|
7
|
+
Pins @segmentstream/ontology 0.179.0.
|
|
8
|
+
|
|
3
9
|
## 0.99.0
|
|
4
10
|
|
|
5
11
|
The workspace gives the words of a `whenUnsure` review's judge, the decision model that reads a
|
package/README.md
CHANGED
|
@@ -1104,6 +1104,14 @@ The reference alone grants no access or messaging authority.
|
|
|
1104
1104
|
|
|
1105
1105
|
## Grounding replies in opened groups
|
|
1106
1106
|
|
|
1107
|
+
An opened group's workspace can bind a TypeScript `publicGroups.respond` handler. It receives the
|
|
1108
|
+
current text, locale, lazy verified evidence, a metered private model call and `act(input)`. Returning
|
|
1109
|
+
a string sends that reply. Returning `undefined` continues the ordinary answer. The model receives
|
|
1110
|
+
no action tool. The ontology opts in separately with `publicGroupAction: { entity, action, role }`.
|
|
1111
|
+
Only that authored action runs, under its explicit permission, for a sender scoped to the group.
|
|
1112
|
+
Use this for narrow requests, with workspace-owned confirmation, deduplication and public-safe
|
|
1113
|
+
receipts. The ontology rechecks group access on every call.
|
|
1114
|
+
|
|
1107
1115
|
For an isolated group answer, the workspace can declare `publicGroups.knowledge`
|
|
1108
1116
|
with a `connection` key and localized `unavailable` text in its agent configuration.
|
|
1109
1117
|
In the agent's extension mount, add a `lookup` function to that object. Its
|
|
@@ -4,7 +4,7 @@ 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
|
-
var version = "0.
|
|
7
|
+
var version = "0.100.0";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -77,6 +77,8 @@ export interface FirstContactSettings {
|
|
|
77
77
|
export declare const ADMISSION_REPLY_KEYS: readonly ["pairingRequired", "pairingButton", "groupPairingButton", "limited", "perSenderLimited", "workspaceLimited", "registrationsLimited", "groupPairingRequired", "refused"];
|
|
78
78
|
export type AdmissionReplies = Partial<Record<(typeof ADMISSION_REPLY_KEYS)[number], LocalizedText>>;
|
|
79
79
|
export interface PublicGroupSettings {
|
|
80
|
+
/** Trusted workspace responder. Its action is bound and authorized by the ontology. */
|
|
81
|
+
readonly respond?: (context: import("./lib/public-group.js").PublicGroupResponseContext) => Promise<string | undefined>;
|
|
80
82
|
readonly knowledge?: PublicGroupKnowledge;
|
|
81
83
|
readonly model: string;
|
|
82
84
|
/** Workspace-published material for an isolated, text-only answer. */
|
|
@@ -1300,13 +1300,14 @@ function validateConfig(input, options = {}) {
|
|
|
1300
1300
|
"model",
|
|
1301
1301
|
"instructions",
|
|
1302
1302
|
"trustedJoinChannels",
|
|
1303
|
-
"knowledge"
|
|
1303
|
+
"knowledge",
|
|
1304
|
+
"respond"
|
|
1304
1305
|
],
|
|
1305
1306
|
issues
|
|
1306
1307
|
});
|
|
1307
1308
|
let publicGroups;
|
|
1308
1309
|
if (publicGroupInput) {
|
|
1309
|
-
const { model, instructions, trustedJoinChannels } = publicGroupInput;
|
|
1310
|
+
const { model, instructions, trustedJoinChannels, respond } = publicGroupInput;
|
|
1310
1311
|
const knowledge = section({
|
|
1311
1312
|
value: publicGroupInput.knowledge,
|
|
1312
1313
|
path: ["publicGroups", "knowledge"],
|
|
@@ -1334,12 +1335,13 @@ function validateConfig(input, options = {}) {
|
|
|
1334
1335
|
...knowledge.lookup && { lookup: knowledge.lookup }
|
|
1335
1336
|
};
|
|
1336
1337
|
}
|
|
1337
|
-
if (typeof model !== "string" || !model.trim() || model.length > 256 || typeof instructions !== "string" || !instructions.trim() || instructions.length > 32e3 || trustedJoinChannels !== void 0 && (!Array.isArray(trustedJoinChannels) || !trustedJoinChannels.every((channel) => typeof channel === "string" && Object.hasOwn(channels ?? {}, channel)))) issues.push({
|
|
1338
|
+
if (typeof model !== "string" || !model.trim() || model.length > 256 || typeof instructions !== "string" || !instructions.trim() || instructions.length > 32e3 || respond !== void 0 && typeof respond !== "function" || trustedJoinChannels !== void 0 && (!Array.isArray(trustedJoinChannels) || !trustedJoinChannels.every((channel) => typeof channel === "string" && Object.hasOwn(channels ?? {}, channel)))) issues.push({
|
|
1338
1339
|
path: ["publicGroups"],
|
|
1339
1340
|
message: "Supply a model, public instructions and optional configured channel names."
|
|
1340
1341
|
});
|
|
1341
1342
|
else publicGroups = {
|
|
1342
1343
|
...source && { knowledge: source },
|
|
1344
|
+
...typeof respond === "function" && { respond },
|
|
1343
1345
|
model,
|
|
1344
1346
|
instructions,
|
|
1345
1347
|
...trustedJoinChannels ? { trustedJoinChannels } : {}
|
|
@@ -61,4 +61,5 @@ export { replayRouterPayload } from "./lib/group-routing/replay.js";
|
|
|
61
61
|
export { chatAddressing as groupChatAddressing } from "./lib/group-routing/addressing.js";
|
|
62
62
|
export { routingBurst } from "./lib/group-routing/burst.js";
|
|
63
63
|
export type { TelegramTexts } from "./lib/telegram/texts.js";
|
|
64
|
+
export type { PublicGroupResponseContext } from "./lib/public-group.js";
|
|
64
65
|
export type { PublicGroupKnowledge, PublicGroupKnowledgeContext, } from "./lib/public-group-knowledge.js";
|
|
@@ -4,4 +4,4 @@ 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
|
-
export { t as agentBuild } from "../../_chunks/build-metadata-
|
|
7
|
+
export { t as agentBuild } from "../../_chunks/build-metadata-fPSw1vHg.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SessionAuthContext } from "eve/context";
|
|
2
2
|
import { chatPersona, type PersonaSettings } from "../personas.js";
|
|
3
3
|
/** A production runtime lookup on the current chat. An outage must not silently change its persona. */
|
|
4
|
-
export declare function chatRuntimeRequest(operation: string, data: Record<string, unknown
|
|
4
|
+
export declare function chatRuntimeRequest(operation: string, data: Record<string, unknown>, signal?: AbortSignal): Promise<any>;
|
|
5
5
|
export declare function resolveChatPersona(settings: PersonaSettings, principal: SessionAuthContext | null | undefined, read?: (key: string) => Promise<string | null>): Promise<{
|
|
6
6
|
readonly name: string;
|
|
7
7
|
readonly source: "chat";
|
|
@@ -9,7 +9,7 @@ import { Ft as chatAddressOf, It as chatChannel, i as memberIdOf, ot as guestIdO
|
|
|
9
9
|
import { appOrigin, ontologyDeploymentHeaders } from "./environment.mjs";
|
|
10
10
|
import { localizedText } from "./admission.mjs";
|
|
11
11
|
import { runtimeToken } from "./runtime-token.mjs";
|
|
12
|
-
async function chatRuntimeRequest(operation, data) {
|
|
12
|
+
async function chatRuntimeRequest(operation, data, signal = AbortSignal.timeout(5e3)) {
|
|
13
13
|
const response = await fetch(`${appOrigin()}/api/ontology/agent/chats/${operation}`, {
|
|
14
14
|
method: "POST",
|
|
15
15
|
redirect: "error",
|
|
@@ -19,7 +19,7 @@ async function chatRuntimeRequest(operation, data) {
|
|
|
19
19
|
"content-type": "application/json"
|
|
20
20
|
},
|
|
21
21
|
body: JSON.stringify(data),
|
|
22
|
-
signal
|
|
22
|
+
signal
|
|
23
23
|
});
|
|
24
24
|
if (!response.ok) throw new Error(`The chat runtime request failed (HTTP ${response.status}).`);
|
|
25
25
|
return response.json();
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { AdmissionSettings } from "../config.js";
|
|
2
|
+
export interface PublicGroupResponseContext {
|
|
3
|
+
readonly question: string;
|
|
4
|
+
readonly locale?: string;
|
|
5
|
+
/** Privately verified facts, fetched at most once. */
|
|
6
|
+
readonly evidence: () => Promise<readonly string[]>;
|
|
7
|
+
readonly reason: (instructions: string, prompt: string) => Promise<string>;
|
|
8
|
+
/** The workspace-authored ontology action. Never offered to a model. */
|
|
9
|
+
readonly act: (input: Readonly<Record<string, unknown>>) => Promise<unknown>;
|
|
10
|
+
}
|
|
2
11
|
/** Everyone in an opened group sees the reply, including when an employee asks. */
|
|
3
12
|
export declare function isPublicGroup(admission: AdmissionSettings, channel: string, chat: string, sender: string): Promise<boolean>;
|
|
4
13
|
/** An unlinked sender can only submit this message to the workspace's public instructions.
|
|
@@ -50,7 +50,7 @@ async function answerPublicGroup(input) {
|
|
|
50
50
|
input.message
|
|
51
51
|
]);
|
|
52
52
|
let stage = 0;
|
|
53
|
-
const generate = async (system, prompt, privateCall = false) => {
|
|
53
|
+
const generate = async (system, prompt, privateCall = false, signal = AbortSignal.timeout(3e4)) => {
|
|
54
54
|
const usageKey = privateCall ? `research:${++stage}:${messageKey}` : messageKey;
|
|
55
55
|
const reply = await generateText({
|
|
56
56
|
model: gateway(settings.model),
|
|
@@ -58,7 +58,7 @@ async function answerPublicGroup(input) {
|
|
|
58
58
|
prompt,
|
|
59
59
|
maxRetries: 0,
|
|
60
60
|
maxOutputTokens: privateCall ? 1e3 : 600,
|
|
61
|
-
abortSignal:
|
|
61
|
+
abortSignal: signal
|
|
62
62
|
});
|
|
63
63
|
const costUsd = gatewayCostOf(reply.providerMetadata);
|
|
64
64
|
if (costUsd > 0) await ontologyGuestUsage()({
|
|
@@ -68,12 +68,36 @@ async function answerPublicGroup(input) {
|
|
|
68
68
|
});
|
|
69
69
|
return reply.text.trim();
|
|
70
70
|
};
|
|
71
|
-
|
|
71
|
+
let research;
|
|
72
|
+
const evidenceForTurn = () => research ??= settings.knowledge ? publicGroupEvidence(settings.knowledge, question, (system, prompt) => generate(system, prompt, true, researchDeadline), researchDeadline) : Promise.resolve([]);
|
|
73
|
+
let calls = 0;
|
|
74
|
+
let actions = 0;
|
|
75
|
+
const response = await settings.respond?.({
|
|
76
|
+
question,
|
|
77
|
+
locale: input.locale,
|
|
78
|
+
evidence: evidenceForTurn,
|
|
79
|
+
reason: (system, prompt) => {
|
|
80
|
+
if (++calls > 2 || system.length > 8e3 || prompt.length > 2e4) throw new Error("Public response limit exceeded.");
|
|
81
|
+
return generate(system, prompt, true);
|
|
82
|
+
},
|
|
83
|
+
act: async (data) => {
|
|
84
|
+
if (++actions > 4 || JSON.stringify(data).length > 12e3) throw new Error("Public action limit exceeded.");
|
|
85
|
+
const reply = await chatRuntimeRequest("public-action", {
|
|
86
|
+
channel: input.channel,
|
|
87
|
+
chat: input.chat,
|
|
88
|
+
sender: input.sender,
|
|
89
|
+
input: data
|
|
90
|
+
}, AbortSignal.timeout(25e3));
|
|
91
|
+
if (!reply || !Object.hasOwn(reply, "result")) throw new Error("Public action failed.");
|
|
92
|
+
return reply.result;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const evidence = response === void 0 && settings.knowledge ? await evidenceForTurn() : void 0;
|
|
72
96
|
const prompt = evidence === void 0 ? question : JSON.stringify({
|
|
73
97
|
question,
|
|
74
98
|
evidence
|
|
75
99
|
});
|
|
76
|
-
const text = settings.knowledge && !evidence?.length ? localizedText(settings.knowledge.unavailable, input.locale) : await generate(settings.instructions, prompt);
|
|
100
|
+
const text = response ?? (settings.knowledge && !evidence?.length ? localizedText(settings.knowledge.unavailable, input.locale) : await generate(settings.instructions, prompt));
|
|
77
101
|
if (!text) throw new Error("The public group answer was empty.");
|
|
78
102
|
await input.post(text.slice(0, 3500));
|
|
79
103
|
delivered = true;
|
|
@@ -13,7 +13,7 @@ import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
|
|
|
13
13
|
import { handleWorkspaceCallback } from "./callbacks.mjs";
|
|
14
14
|
import { workspaceTriage } from "../triage.mjs";
|
|
15
15
|
import { telegramText, withTelegramTexts } from "./texts.mjs";
|
|
16
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
16
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-fPSw1vHg.mjs";
|
|
17
17
|
import { attachmentLifecycle } from "./lifecycle.mjs";
|
|
18
18
|
import { manifestOf } from "../../config.mjs";
|
|
19
19
|
import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
|
|
@@ -4,7 +4,7 @@ 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 { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
7
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-fPSw1vHg.mjs";
|
|
8
8
|
import { runtimeRequestFailure } from "./runtime-request.mjs";
|
|
9
9
|
import { GET } from "eve/channels";
|
|
10
10
|
const HEALTH_ROUTE = "/eve/v1/telegram/health";
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { E as OntologyActionNotPermitted, Et as principalRuntimeSource, L as needsConfirmation, Ot as runtimeEnvelope, W as member, c as currentInboundRequest, j as ontologyTools, k as actionToolName, kt as telegramRuntimeSource } from "../../../_chunks/principal-DL9NdRRP.mjs";
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
8
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-fPSw1vHg.mjs";
|
|
9
9
|
import { object } from "../confirmation-description.mjs";
|
|
10
10
|
var AttachmentLifecycleNotPermitted = class extends Error {
|
|
11
11
|
code = "attachment_lifecycle_not_permitted";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.100.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.179.0",
|
|
92
92
|
"@vercel/oidc": "^3.8.4",
|
|
93
93
|
"ai": "^7.0.172",
|
|
94
94
|
"chat": "4.42.0",
|