@segmentstream/agent 0.38.3 → 0.40.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 +29 -11
- package/dist/_chunks/{build-metadata-CvNkh4kp.mjs → build-metadata-BZlbshZq.mjs} +1 -1
- package/dist/extension/config.d.ts +20 -0
- package/dist/extension/config.mjs +27 -4
- package/dist/extension/conventions.d.ts +23 -0
- package/dist/extension/conventions.mjs +48 -0
- package/dist/extension/extension.d.ts +1 -0
- package/dist/extension/extension.mjs +2 -1
- package/dist/extension/instructions/persona.d.ts +8 -0
- package/dist/extension/instructions/persona.mjs +21 -0
- package/dist/extension/instructions.md +5 -2
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/role-skill.d.ts +21 -0
- package/dist/extension/lib/role-skill.mjs +14 -0
- package/dist/extension/lib/skill-sources.d.ts +19 -0
- package/dist/extension/lib/skill-sources.mjs +39 -0
- 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/dist/extension/personas.d.ts +39 -0
- package/dist/extension/personas.mjs +103 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,25 +120,43 @@ See [Sandbox](#sandbox).
|
|
|
120
120
|
| `models.decision` | `"typesafe-ai/jev-1.14.0"` | The AI Gateway decision model of the inbound router |
|
|
121
121
|
| `ontology.connection` | `true` | Whether the agent reaches the ontology over MCP |
|
|
122
122
|
| `sandbox` | `false` | `true` adds `bash`, `read_file` and `write_file` in the agent's sandbox without network; see [Sandbox](#sandbox) |
|
|
123
|
+
| `personas` | none | `{ "byRole": { role: persona }, "default": persona }`: who the agent is to the person; see [Personas and skills by role](#personas-and-skills-by-role) |
|
|
123
124
|
|
|
124
125
|
An unknown field or an invalid value fails the mount with `SegmentStreamAgentConfigError`, naming
|
|
125
126
|
each path. `manifestOf(config)` returns the normalized configuration, defaults applied, for the
|
|
126
127
|
platform's deployment manifest.
|
|
127
128
|
|
|
129
|
+
## Personas and skills by role
|
|
130
|
+
|
|
131
|
+
The shared instructions (`agent/agent/instructions.md`) reach everyone the agent talks to. A
|
|
132
|
+
persona, `agent/personas/<name>.md`, says who the agent is to the person in a conversation: one
|
|
133
|
+
per conversation, the first `personas.byRole` entry whose role the person who started it holds,
|
|
134
|
+
else `personas.default`. The SDK reads each text when the agent is built and the platform puts it
|
|
135
|
+
inline when it deploys, so the mount stays `segmentstream(config)`; the build fails when a named
|
|
136
|
+
text is missing. Guidance for the group decision model lives the same way in
|
|
137
|
+
`agent/groups/instructions.md`, after the platform's rules.
|
|
138
|
+
|
|
139
|
+
Skills stay eve's, in `agent/agent/skills/`. A module there that exports
|
|
140
|
+
`forRoles(["accountant", "founder"], { description, content })` is a skill only those roles get:
|
|
141
|
+
it is an eve dynamic skill, listed and loadable only in sessions started by a person holding one
|
|
142
|
+
of the roles. See [personas and skills by role](../../docs/agent.md#personas-and-skills-by-role)
|
|
143
|
+
in the workspace agent guide.
|
|
144
|
+
|
|
128
145
|
## Channel admission and first contact
|
|
129
146
|
|
|
130
147
|
The platform and SDK provide admission, identity resolution, onboarding execution, notice tracking
|
|
131
|
-
and durable limits. Workspace apps own
|
|
132
|
-
content and lower limit values. No channel defaults to open, and no notice or limit
|
|
133
|
-
ships as a default. Existing invited-channel pairing and refusal replies remain unchanged.
|
|
134
|
-
|
|
135
|
-
Admission belongs in the ontology's `
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
and durable limits. Workspace apps own where sign-up is open, the roles it grants, onboarding
|
|
149
|
+
actions, notice content and lower limit values. No channel defaults to open, and no notice or limit
|
|
150
|
+
reply text ships as a default. Existing invited-channel pairing and refusal replies remain unchanged.
|
|
151
|
+
|
|
152
|
+
Admission belongs in the ontology's `signUp`: a stranger's first private message on a listed
|
|
153
|
+
channel makes them a user holding the roles `signUp` names; every other channel admits only
|
|
154
|
+
invited or paired people. Opening a channel is an explicit workspace opt-in, and `check` refuses
|
|
155
|
+
sign-up roles with wildcards or unscoped generated writes. Actions handling a person's own
|
|
156
|
+
records enforce ownership with `principal.id`. Groups never register users. Closing a channel
|
|
157
|
+
stops new registrations; block or deactivate an existing user to stop their access. The earlier
|
|
158
|
+
`signIn.channels.<provider>: "open"`, which gives strangers `member`, remains as a deprecated
|
|
159
|
+
alias.
|
|
142
160
|
|
|
143
161
|
Configure app-owned text and lower limits in `agent/segmentstream.json`. These placeholders
|
|
144
162
|
represent text authored by the workspace, not SDK defaults:
|
|
@@ -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.40.0";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -4,6 +4,7 @@ import { type StructuredInbound } from "./lib/telegram/structured-settings.js";
|
|
|
4
4
|
import type { WorkspaceActionHook } from "./lib/telegram/workspace-action.js";
|
|
5
5
|
import { type TelegramTexts } from "./lib/telegram/texts.js";
|
|
6
6
|
import type { AttachmentLifecycle } from "./lib/telegram/lifecycle.js";
|
|
7
|
+
import { type PersonaSettings } from "./personas.js";
|
|
7
8
|
import { type TelegramLinkPreviews } from "@segmentstream/ontology/telegram";
|
|
8
9
|
export declare const TELEGRAM_POLICIES: readonly ["mention", "smart"];
|
|
9
10
|
/**
|
|
@@ -159,6 +160,17 @@ export interface SegmentStreamAgentConfigInput {
|
|
|
159
160
|
*/
|
|
160
161
|
readonly idleResetHours?: unknown;
|
|
161
162
|
};
|
|
163
|
+
/**
|
|
164
|
+
* What the agent is to the person in a session: a persona per role, the first role the person
|
|
165
|
+
* who started the session holds winning in the order written, and a `default` for everyone else.
|
|
166
|
+
* Each persona's text is `agent/personas/<name>.md`; the SDK and the platform put it in
|
|
167
|
+
* `texts`, which is not written by hand.
|
|
168
|
+
*/
|
|
169
|
+
readonly personas?: {
|
|
170
|
+
readonly byRole?: Readonly<Record<string, string>>;
|
|
171
|
+
readonly default?: string;
|
|
172
|
+
readonly texts?: Readonly<Record<string, string>>;
|
|
173
|
+
};
|
|
162
174
|
}
|
|
163
175
|
export interface TelegramSettings {
|
|
164
176
|
readonly groups?: {
|
|
@@ -223,6 +235,8 @@ export interface SegmentStreamAgentConfig extends AdmissionSettings {
|
|
|
223
235
|
/** Whether the sandbox file tools are on; see {@link SegmentStreamAgentConfigInput.sandbox}. */
|
|
224
236
|
readonly sandbox: boolean;
|
|
225
237
|
readonly sessions: SessionSettings;
|
|
238
|
+
/** The personas, with their texts once read; absent when `segmentstream.json` declares none. */
|
|
239
|
+
readonly personas?: PersonaSettings;
|
|
226
240
|
}
|
|
227
241
|
/** One validation failure, in Standard Schema's issue shape. */
|
|
228
242
|
export interface ConfigIssue {
|
|
@@ -274,6 +288,12 @@ export declare function isLegacyAgentArchive(version: string | undefined): boole
|
|
|
274
288
|
/** Validates the authored configuration and applies the defaults. */
|
|
275
289
|
export declare function validateConfig(input: unknown, options?: {
|
|
276
290
|
readonly archiveSdkVersion?: string;
|
|
291
|
+
/**
|
|
292
|
+
* Whether the texts of the conventional files must be inline, as when the mount validates
|
|
293
|
+
* (see {@link configSchema}) or the platform validates a deployment's archive after putting
|
|
294
|
+
* them inline. Validating the JSON alone, as {@link manifestOf} does, leaves them out.
|
|
295
|
+
*/
|
|
296
|
+
readonly texts?: "required";
|
|
277
297
|
}): Validation;
|
|
278
298
|
/**
|
|
279
299
|
* The Standard Schema eve validates the mount with. `types` exists only for type inference, as the
|
|
@@ -9,6 +9,8 @@ import { localizedText as localizedText$1 } from "./lib/admission.mjs";
|
|
|
9
9
|
import { STRUCTURED_KINDS } from "./lib/telegram/structured-settings.mjs";
|
|
10
10
|
import { TELEGRAM_TEXT_KEYS } from "./lib/telegram/texts.mjs";
|
|
11
11
|
import { isTechnicalText } from "./lib/customer-text-safety.mjs";
|
|
12
|
+
import { inlineConventionFiles } from "./conventions.mjs";
|
|
13
|
+
import { personaSettings } from "./personas.mjs";
|
|
12
14
|
import { readFileSync, realpathSync } from "node:fs";
|
|
13
15
|
import { expandGroupFiles, groupPolicyIssues } from "@segmentstream/ontology/groups";
|
|
14
16
|
import { TELEGRAM_LINK_PREVIEWS, isHttpOrigin } from "@segmentstream/ontology/telegram";
|
|
@@ -58,7 +60,15 @@ function configWarnings(value) {
|
|
|
58
60
|
...inapplicableGroupThresholds(root?.groups).map((path) => ({
|
|
59
61
|
path: ["groups", ...path],
|
|
60
62
|
message: INAPPLICABLE_THRESHOLD
|
|
61
|
-
}))
|
|
63
|
+
})),
|
|
64
|
+
...isRecord(root?.groups) && isRecord(root.groups.smart) && root.groups.smart.instructions !== void 0 ? [{
|
|
65
|
+
path: [
|
|
66
|
+
"groups",
|
|
67
|
+
"smart",
|
|
68
|
+
"instructions"
|
|
69
|
+
],
|
|
70
|
+
message: "is deprecated: write the decision model's guidance in agent/groups/instructions.md, which the platform adds after its own rules, and remove this setting"
|
|
71
|
+
}] : []
|
|
62
72
|
];
|
|
63
73
|
}
|
|
64
74
|
var SegmentStreamAgentConfigError = class extends Error {
|
|
@@ -583,7 +593,8 @@ function validateConfig(input, options = {}) {
|
|
|
583
593
|
"firstContact",
|
|
584
594
|
"limits",
|
|
585
595
|
"replies",
|
|
586
|
-
"texts"
|
|
596
|
+
"texts",
|
|
597
|
+
"personas"
|
|
587
598
|
],
|
|
588
599
|
issues
|
|
589
600
|
});
|
|
@@ -764,6 +775,7 @@ function validateConfig(input, options = {}) {
|
|
|
764
775
|
message: "must be true or false",
|
|
765
776
|
path: ["sandbox"]
|
|
766
777
|
});
|
|
778
|
+
const personas = personaSettings(root?.personas, issues, options.texts === "required");
|
|
767
779
|
if (issues.length > 0) return { issues };
|
|
768
780
|
return { value: {
|
|
769
781
|
groups,
|
|
@@ -788,13 +800,24 @@ function validateConfig(input, options = {}) {
|
|
|
788
800
|
firstContact,
|
|
789
801
|
limits,
|
|
790
802
|
replies,
|
|
791
|
-
texts
|
|
803
|
+
texts,
|
|
804
|
+
...personas === null ? {} : { personas }
|
|
792
805
|
} };
|
|
793
806
|
}
|
|
807
|
+
function readAgentFile(path) {
|
|
808
|
+
try {
|
|
809
|
+
const root = realpathSync(process.cwd());
|
|
810
|
+
const file = realpathSync(resolve(root, path));
|
|
811
|
+
const local = relative(root, file);
|
|
812
|
+
return local.startsWith("..") || isAbsolute(local) ? void 0 : readFileSync(file, "utf8");
|
|
813
|
+
} catch {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
794
817
|
const configSchema = { "~standard": {
|
|
795
818
|
version: 1,
|
|
796
819
|
vendor: "segmentstream",
|
|
797
|
-
validate: (input) => validateConfig(input),
|
|
820
|
+
validate: (input) => validateConfig(inlineConventionFiles(input, readAgentFile), { texts: "required" }),
|
|
798
821
|
types: void 0
|
|
799
822
|
} };
|
|
800
823
|
function manifestOf(config) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The texts a workspace keeps in files beside `agent/segmentstream.json`, at fixed paths, so the
|
|
3
|
+
* JSON holds only choices and numbers:
|
|
4
|
+
*
|
|
5
|
+
* - `agent/personas/<persona>.md`: the text of each persona `personas` names;
|
|
6
|
+
* - `agent/groups/instructions.md`: guidance the group decision model reads after the platform's
|
|
7
|
+
* rules.
|
|
8
|
+
*
|
|
9
|
+
* The SDK reads them when the agent is built; the platform reads them from the deployment's
|
|
10
|
+
* archive and puts them inline in `segmentstream.json` before it builds, so the running agent,
|
|
11
|
+
* which has no files, reads the same texts.
|
|
12
|
+
*/
|
|
13
|
+
/** Guidance for the group decision model, appended to the platform's rules. */
|
|
14
|
+
export declare const GROUP_INSTRUCTIONS_FILE = "groups/instructions.md";
|
|
15
|
+
/** Reads a file by its path under `agent/`; `undefined` when there is none. */
|
|
16
|
+
export type AgentFileReader = (path: string) => string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* `agent/segmentstream.json` with the conventional files' texts inline: each persona's text in
|
|
19
|
+
* `personas.texts`, and `agent/groups/instructions.md` as `groups.smart.instructions.append`. A
|
|
20
|
+
* file that exists wins over an inline value; without the file, an inline value, such as the one
|
|
21
|
+
* the platform wrote at deploy, stays. Anything that is not an object is returned as it is.
|
|
22
|
+
*/
|
|
23
|
+
export declare function inlineConventionFiles(input: unknown, read: AgentFileReader): unknown;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
import { isPersonaName, personaFile } from "./personas.mjs";
|
|
8
|
+
const GROUP_INSTRUCTIONS_FILE = "groups/instructions.md";
|
|
9
|
+
function isRecord(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
function inlineConventionFiles(input, read) {
|
|
13
|
+
if (!isRecord(input)) return input;
|
|
14
|
+
let output = { ...input };
|
|
15
|
+
const guidance = read(GROUP_INSTRUCTIONS_FILE);
|
|
16
|
+
if (guidance !== void 0) {
|
|
17
|
+
const groups = isRecord(input.groups) ? input.groups : {};
|
|
18
|
+
const smart = isRecord(groups.smart) ? groups.smart : {};
|
|
19
|
+
output = {
|
|
20
|
+
...output,
|
|
21
|
+
groups: {
|
|
22
|
+
...groups,
|
|
23
|
+
smart: {
|
|
24
|
+
...smart,
|
|
25
|
+
instructions: { append: guidance }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (isRecord(input.personas)) {
|
|
31
|
+
const personas = input.personas;
|
|
32
|
+
const named = [...isRecord(personas.byRole) ? Object.values(personas.byRole) : [], personas.default].filter(isPersonaName);
|
|
33
|
+
const texts = isRecord(personas.texts) ? { ...personas.texts } : {};
|
|
34
|
+
for (const name of new Set(named)) {
|
|
35
|
+
const text = read(personaFile(name));
|
|
36
|
+
if (text !== void 0) texts[name] = text;
|
|
37
|
+
}
|
|
38
|
+
output = {
|
|
39
|
+
...output,
|
|
40
|
+
personas: {
|
|
41
|
+
...personas,
|
|
42
|
+
...Object.keys(texts).length === 0 ? {} : { texts }
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return output;
|
|
47
|
+
}
|
|
48
|
+
export { GROUP_INSTRUCTIONS_FILE, inlineConventionFiles };
|
|
@@ -22,6 +22,7 @@ export declare const segmentstream: import("eve/extension").ExtensionHandle<{
|
|
|
22
22
|
export default segmentstream;
|
|
23
23
|
export { DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, DEFAULT_ADMISSION_LIMITS, SegmentStreamAgentConfigError, manifestOf, type ChatModelChoice, type AdmissionLimits, type AdmissionLimitsInput, type AdmissionSettings, type AdmissionReplies, type FirstContactSettings, type LocalizedText, type SegmentStreamAgentConfig, type SegmentStreamAgentConfigInput, type SessionScope, type SessionSettings, type TelegramPolicy, type TelegramSettings, } from "./config.js";
|
|
24
24
|
export { chooseModel, model, type DynamicModel, type ModelChoice } from "./model.js";
|
|
25
|
+
export { forRoles } from "./lib/role-skill.js";
|
|
25
26
|
export { groupPolicy, effectiveGroupPolicy, DEFAULT_GROUP_POLICY, type GroupPolicy, type GroupPolicyInput, type SmartPolicyInput, type ChatOverrideInput, } from "./lib/group-routing/policy.js";
|
|
26
27
|
export { addressingReason as groupAddressingReason, conversationKey, type GroupMessageSignals, type AgentMessageSignals, type GroupChannelAdapter, } from "./lib/group-routing/signals.js";
|
|
27
28
|
export { routeMessage as routeGroupMessage, decisionRouter as groupDecisionRouter, } from "./lib/group-routing/router.js";
|
|
@@ -6,6 +6,7 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { DEFAULT_ADMISSION_LIMITS, DEFAULT_DECISION_MODEL, DEFAULT_STT_MODEL, SegmentStreamAgentConfigError, configSchema, manifestOf } from "./config.mjs";
|
|
8
8
|
import { chooseModel, model } from "./model.mjs";
|
|
9
|
+
import { forRoles } from "./lib/role-skill.mjs";
|
|
9
10
|
import { DEFAULT_GROUP_POLICY, effectiveGroupPolicy, groupPolicy } from "./lib/group-routing/policy.mjs";
|
|
10
11
|
import { addressingReason, conversationKey } from "./lib/group-routing/signals.mjs";
|
|
11
12
|
import { decisionRouter, routeMessage } from "./lib/group-routing/router.mjs";
|
|
@@ -20,4 +21,4 @@ const segmentstream = Object.assign(extension, {
|
|
|
20
21
|
model,
|
|
21
22
|
manifestOf
|
|
22
23
|
});
|
|
23
|
-
export { DEFAULT_ADMISSION_LIMITS, DEFAULT_DECISION_MODEL, DEFAULT_GROUP_POLICY, DEFAULT_STT_MODEL, SegmentStreamAgentConfigError, archivedRoutingMessages, chooseModel, conversationKey, segmentstream as default, segmentstream, effectiveGroupPolicy, addressingReason as groupAddressingReason, agentMessage as groupAgentMessage, conversationAddressing as groupConversationAddressing, decisionRouter as groupDecisionRouter, groupPolicy, manifestOf, model, replayRouterPayload, routeMessage as routeGroupMessage, routingBurst };
|
|
24
|
+
export { DEFAULT_ADMISSION_LIMITS, DEFAULT_DECISION_MODEL, DEFAULT_GROUP_POLICY, DEFAULT_STT_MODEL, SegmentStreamAgentConfigError, archivedRoutingMessages, chooseModel, conversationKey, segmentstream as default, segmentstream, effectiveGroupPolicy, forRoles, addressingReason as groupAddressingReason, agentMessage as groupAgentMessage, conversationAddressing as groupConversationAddressing, decisionRouter as groupDecisionRouter, groupPolicy, manifestOf, model, replayRouterPayload, routeMessage as routeGroupMessage, routingBurst };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persona of the session: a system instruction after the workspace's own, chosen from the
|
|
3
|
+
* roles of the person who started the session (the workflow's user for a workflow task), so it
|
|
4
|
+
* stays the same for the whole session and keeps the prompt prefix cached. Nothing without
|
|
5
|
+
* `personas` in `agent/segmentstream.json`, or when no role matches and there is no `default`.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: import("eve").DynamicSentinel<import("eve/instructions").DynamicInstructionsResult, import("eve").DynamicContext>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
import segmentstream from "../extension.mjs";
|
|
8
|
+
import { a as rolesOf } from "../../_chunks/principal-BIX7T6Hh.mjs";
|
|
9
|
+
import { personaFor } from "../personas.mjs";
|
|
10
|
+
import { defineDynamic, defineInstructions } from "eve/instructions";
|
|
11
|
+
var persona_default = defineDynamic((context) => {
|
|
12
|
+
const { personas } = segmentstream.config;
|
|
13
|
+
if (personas === void 0) return null;
|
|
14
|
+
const persona = personaFor(personas, rolesOf(context.session.auth.initiator ?? context.session.auth.current));
|
|
15
|
+
const content = persona === void 0 ? void 0 : personas.texts?.[persona];
|
|
16
|
+
return content === void 0 ? null : defineInstructions({
|
|
17
|
+
role: "system",
|
|
18
|
+
content
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
export { persona_default as default };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# SegmentStream platform
|
|
2
2
|
|
|
3
|
-
You are the workspace's agent on SegmentStream. Every conversation runs as the
|
|
4
|
-
talking to you,
|
|
3
|
+
You are the workspace's agent on SegmentStream. Every conversation runs as the person who is
|
|
4
|
+
talking to you, called the member below whether they were invited or signed up themselves, and
|
|
5
|
+
you act with exactly their permissions. When the workspace declares personas, a persona
|
|
6
|
+
instruction says who you are to this person; it refines the workspace's instructions, and neither
|
|
7
|
+
overrides these platform rules.
|
|
5
8
|
|
|
6
9
|
The company's records live in the ontology MCP connection `segmentstream__ontology`.
|
|
7
10
|
Use Eve's `eve__search` to find its operation tools and `eve__tool` to inspect/call them.
|
|
@@ -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-BZlbshZq.mjs";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type SkillDefinition } from "eve/skills";
|
|
2
|
+
/**
|
|
3
|
+
* A skill only the listed roles get, as the default export of a module in `agent/agent/skills/`:
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* // agent/agent/skills/accounting.ts
|
|
7
|
+
* import { forRoles } from "@segmentstream/agent";
|
|
8
|
+
*
|
|
9
|
+
* export default forRoles(["accountant", "founder"], {
|
|
10
|
+
* description: "Post journals and reconcile accounts. Use when …",
|
|
11
|
+
* content: `…`,
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* eve gives a static skill to every session, so this one is an eve dynamic skill: a session
|
|
16
|
+
* started by a person holding any of the roles lists and loads it under the module's name; any
|
|
17
|
+
* other session neither sees its name nor can load it. The roles are those of the person who
|
|
18
|
+
* started the session (the workflow's user for a workflow task), so a session keeps its skills.
|
|
19
|
+
* Write the roles as a list of strings: the platform reads that list to show who gets the skill.
|
|
20
|
+
*/
|
|
21
|
+
export declare function forRoles(roles: ReadonlyArray<string>, skill: SkillDefinition): import("eve").DynamicSentinel<import("eve/skills").DynamicSkillResult, import("eve").DynamicContext>;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
import { a as rolesOf } from "../../_chunks/principal-BIX7T6Hh.mjs";
|
|
8
|
+
import { defineDynamic, defineSkill } from "eve/skills";
|
|
9
|
+
function forRoles(roles, skill) {
|
|
10
|
+
if (!Array.isArray(roles) || roles.length === 0 || !roles.every((role) => typeof role === "string" && role.trim() !== "")) throw new TypeError("forRoles() needs at least one role name; a skill for everyone is an ordinary skill file.");
|
|
11
|
+
const definition = defineSkill(skill);
|
|
12
|
+
return defineDynamic((context) => rolesOf(context.session.auth.initiator ?? context.session.auth.current).some((role) => roles.includes(role)) ? definition : null);
|
|
13
|
+
}
|
|
14
|
+
export { forRoles };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the platform reads from the skill files of `agent/agent/skills/` to show them, without
|
|
3
|
+
* running them: a Markdown skill's description, and the roles a `forRoles([...])` module lists.
|
|
4
|
+
* eve remains what decides; these readers only describe.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A Markdown skill's description as eve reads it: the frontmatter's `description`, or else the
|
|
8
|
+
* first line of the body that is not a code fence, without its leading Markdown marker.
|
|
9
|
+
* `undefined` when there is neither.
|
|
10
|
+
*/
|
|
11
|
+
export declare function skillDescription(text: string): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* How a skill module limits who gets it: the roles of a `forRoles([...])` call written as a list
|
|
14
|
+
* of strings; `"code"` when it decides in some other way, such as roles computed in code or its
|
|
15
|
+
* own `defineDynamic`; `undefined` for a static skill everyone gets.
|
|
16
|
+
*/
|
|
17
|
+
export declare function skillModuleRoles(source: string): ReadonlyArray<string> | "code" | undefined;
|
|
18
|
+
/** The `description` a skill module writes as one string literal, when it does. */
|
|
19
|
+
export declare function skillModuleDescription(source: string): string | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
function skillDescription(text) {
|
|
8
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
|
|
9
|
+
const described = match === null ? void 0 : frontmatterDescription(match[1] ?? "");
|
|
10
|
+
if (described !== void 0) return described;
|
|
11
|
+
return (match === null ? text : text.slice(match[0].length)).split(/\r?\n/u).map((candidate) => candidate.trim()).find((candidate) => candidate !== "" && !candidate.startsWith("```"))?.replace(/^[#>*-]+\s*/u, "").trim() || void 0;
|
|
12
|
+
}
|
|
13
|
+
function frontmatterDescription(frontmatter) {
|
|
14
|
+
const lines = frontmatter.split(/\r?\n/u);
|
|
15
|
+
const index = lines.findIndex((line) => /^description:/u.test(line));
|
|
16
|
+
if (index === -1) return;
|
|
17
|
+
const value = lines[index].slice(12).trim();
|
|
18
|
+
if (/^[>|][+-]?$/u.test(value)) {
|
|
19
|
+
const block = [];
|
|
20
|
+
for (const line of lines.slice(index + 1)) {
|
|
21
|
+
if (line.trim() !== "" && !/^\s/u.test(line)) break;
|
|
22
|
+
block.push(line.trim());
|
|
23
|
+
}
|
|
24
|
+
return block.join(value.startsWith(">") ? " " : "\n").trim() || void 0;
|
|
25
|
+
}
|
|
26
|
+
return (/^(["'])(.*)\1$/u.exec(value)?.[2] ?? value).trim() || void 0;
|
|
27
|
+
}
|
|
28
|
+
function skillModuleRoles(source) {
|
|
29
|
+
const call = /\bforRoles\s*\(\s*\[([^\]]*)\]/u.exec(source);
|
|
30
|
+
if (call !== null) {
|
|
31
|
+
const roles = (call[1] ?? "").split(",").map((item) => item.trim()).filter((item) => item !== "").map((item) => /^(["'`])([^"'`]+)\1$/u.exec(item)?.[2]);
|
|
32
|
+
return roles.length > 0 && roles.every((role) => role !== void 0) ? roles : "code";
|
|
33
|
+
}
|
|
34
|
+
return /\bforRoles\s*\(|\bdefineDynamic\s*\(/u.test(source) ? "code" : void 0;
|
|
35
|
+
}
|
|
36
|
+
function skillModuleDescription(source) {
|
|
37
|
+
return (/\bdescription\s*:\s*(["'`])((?:(?!\1)[^\\]|\\.)*)\1/u.exec(source)?.[2])?.replace(/\\(.)/gu, "$1").trim() || void 0;
|
|
38
|
+
}
|
|
39
|
+
export { skillDescription, skillModuleDescription, skillModuleRoles };
|
|
@@ -10,7 +10,7 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
|
|
|
10
10
|
import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
|
|
11
11
|
import { handleWorkspaceCallback, isWorkspaceCallback } from "./callbacks.mjs";
|
|
12
12
|
import { telegramText, withTelegramTexts } from "./texts.mjs";
|
|
13
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
13
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-BZlbshZq.mjs";
|
|
14
14
|
import { attachmentLifecycle } from "./lifecycle.mjs";
|
|
15
15
|
import { manifestOf } from "../../config.mjs";
|
|
16
16
|
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-BZlbshZq.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 { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-BIX7T6Hh.mjs";
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
8
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-BZlbshZq.mjs";
|
|
9
9
|
import { n as currentInboundRequest } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
|
|
10
10
|
import { object } from "../confirmation-description.mjs";
|
|
11
11
|
import { needsConfirmation } from "../confirmations.mjs";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personas: what the agent is to the person in a conversation. `agent/segmentstream.json` says
|
|
3
|
+
* which roles get which persona; each persona's text is `agent/personas/<persona>.md`, which the
|
|
4
|
+
* SDK reads when the agent is built and the platform puts inline (`personas.texts`) when it
|
|
5
|
+
* deploys, so the running agent, which has no files, reads the same text. Selection reads only the
|
|
6
|
+
* roles of the person who started the session, so a session keeps one persona.
|
|
7
|
+
*/
|
|
8
|
+
/** The directory beside `segmentstream.json` that holds the persona texts. */
|
|
9
|
+
export declare const PERSONAS_DIRECTORY = "personas";
|
|
10
|
+
export interface PersonaSettings {
|
|
11
|
+
/** A persona per role; the first role the person holds wins, in the order written. */
|
|
12
|
+
readonly byRole: Readonly<Record<string, string>>;
|
|
13
|
+
/** The persona of anyone no role matches, including a person who holds no roles. */
|
|
14
|
+
readonly default?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Each persona's text, from `agent/personas/<persona>.md`. The SDK fills it when the agent is
|
|
17
|
+
* built and the platform when it deploys; it is not written by hand.
|
|
18
|
+
*/
|
|
19
|
+
readonly texts?: Readonly<Record<string, string>>;
|
|
20
|
+
}
|
|
21
|
+
/** One validation failure, in Standard Schema's issue shape. */
|
|
22
|
+
interface Issue {
|
|
23
|
+
readonly message: string;
|
|
24
|
+
readonly path: ReadonlyArray<string>;
|
|
25
|
+
}
|
|
26
|
+
/** The path of a persona's text, relative to the directory of `segmentstream.json`. */
|
|
27
|
+
export declare function personaFile(name: string): string;
|
|
28
|
+
/** The personas the settings name, in selection order: `byRole`'s, then the default. */
|
|
29
|
+
export declare function personaNames(settings: PersonaSettings | null): ReadonlyArray<string>;
|
|
30
|
+
/** The persona for a person with `roles`: the first `byRole` entry they hold, or the default. */
|
|
31
|
+
export declare function personaFor(settings: PersonaSettings | null, roles: ReadonlyArray<string>): string | undefined;
|
|
32
|
+
/** Whether a value is a persona name, safe as a file name under `agent/personas/`. */
|
|
33
|
+
export declare function isPersonaName(value: unknown): value is string;
|
|
34
|
+
/**
|
|
35
|
+
* Validates `personas` of `agent/segmentstream.json`; `null` when absent. With `requireTexts`, as
|
|
36
|
+
* when the agent is built or deployed, every persona it names needs its text.
|
|
37
|
+
*/
|
|
38
|
+
export declare function personaSettings(value: unknown, issues: Issue[], requireTexts?: boolean): PersonaSettings | null;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
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 PERSONAS_DIRECTORY = "personas";
|
|
8
|
+
const NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
9
|
+
const MAXIMUM_NAME_LENGTH = 64;
|
|
10
|
+
const NAME_RULE = "must be lowercase letters, digits and single hyphens, at most 64 characters";
|
|
11
|
+
function personaFile(name) {
|
|
12
|
+
return `${PERSONAS_DIRECTORY}/${name}.md`;
|
|
13
|
+
}
|
|
14
|
+
function personaNames(settings) {
|
|
15
|
+
if (settings === null) return [];
|
|
16
|
+
return [...new Set([...Object.values(settings.byRole), ...settings.default === void 0 ? [] : [settings.default]])];
|
|
17
|
+
}
|
|
18
|
+
function personaFor(settings, roles) {
|
|
19
|
+
if (settings === null) return;
|
|
20
|
+
for (const [role, persona] of Object.entries(settings.byRole)) if (roles.includes(role)) return persona;
|
|
21
|
+
return settings.default;
|
|
22
|
+
}
|
|
23
|
+
function isRecord(value) {
|
|
24
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
function isPersonaName(value) {
|
|
27
|
+
return validName(value);
|
|
28
|
+
}
|
|
29
|
+
function validName(value) {
|
|
30
|
+
return typeof value === "string" && value.length <= MAXIMUM_NAME_LENGTH && NAME.test(value);
|
|
31
|
+
}
|
|
32
|
+
function role(value) {
|
|
33
|
+
return typeof value === "string" && value.trim() !== "" && value.trim() === value;
|
|
34
|
+
}
|
|
35
|
+
function personaSettings(value, issues, requireTexts = false) {
|
|
36
|
+
const path = ["personas"];
|
|
37
|
+
if (value === void 0) return null;
|
|
38
|
+
if (!isRecord(value)) {
|
|
39
|
+
issues.push({
|
|
40
|
+
message: "must be an object",
|
|
41
|
+
path
|
|
42
|
+
});
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
for (const key of Object.keys(value)) if (key !== "byRole" && key !== "default" && key !== "texts") issues.push({
|
|
46
|
+
message: "is not a known setting",
|
|
47
|
+
path: [...path, key]
|
|
48
|
+
});
|
|
49
|
+
const byRole = {};
|
|
50
|
+
if (value.byRole !== void 0) {
|
|
51
|
+
if (!isRecord(value.byRole)) issues.push({
|
|
52
|
+
message: "must be an object of role to persona",
|
|
53
|
+
path: [...path, "byRole"]
|
|
54
|
+
});
|
|
55
|
+
else for (const [name, persona] of Object.entries(value.byRole)) if (!role(name)) issues.push({
|
|
56
|
+
message: "must be a role name",
|
|
57
|
+
path: [
|
|
58
|
+
...path,
|
|
59
|
+
"byRole",
|
|
60
|
+
name
|
|
61
|
+
]
|
|
62
|
+
});
|
|
63
|
+
else if (!validName(persona)) issues.push({
|
|
64
|
+
message: `names a persona that ${NAME_RULE}`,
|
|
65
|
+
path: [
|
|
66
|
+
...path,
|
|
67
|
+
"byRole",
|
|
68
|
+
name
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
else byRole[name] = persona;
|
|
72
|
+
}
|
|
73
|
+
if (value.default !== void 0 && !validName(value.default)) issues.push({
|
|
74
|
+
message: `names a persona that ${NAME_RULE}`,
|
|
75
|
+
path: [...path, "default"]
|
|
76
|
+
});
|
|
77
|
+
if (value.default === void 0 && Object.keys(byRole).length === 0) issues.push({
|
|
78
|
+
message: "needs byRole, default or both",
|
|
79
|
+
path
|
|
80
|
+
});
|
|
81
|
+
const settings = {
|
|
82
|
+
byRole,
|
|
83
|
+
...typeof value.default === "string" && validName(value.default) ? { default: value.default } : {}
|
|
84
|
+
};
|
|
85
|
+
const texts = {};
|
|
86
|
+
if (value.texts !== void 0 && !isRecord(value.texts)) issues.push({
|
|
87
|
+
message: "must be an object of persona to text",
|
|
88
|
+
path: [...path, "texts"]
|
|
89
|
+
});
|
|
90
|
+
for (const name of personaNames(settings)) {
|
|
91
|
+
const text = isRecord(value.texts) ? value.texts[name] : void 0;
|
|
92
|
+
if (typeof text === "string" && text.trim() !== "") texts[name] = text;
|
|
93
|
+
else if (requireTexts) issues.push({
|
|
94
|
+
message: `has no text: write it in agent/${personaFile(name)}`,
|
|
95
|
+
path: [...path, name]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return Object.keys(texts).length === 0 ? settings : {
|
|
99
|
+
...settings,
|
|
100
|
+
texts
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export { PERSONAS_DIRECTORY, isPersonaName, personaFile, personaFor, personaNames, personaSettings };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.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",
|