@segmentstream/agent 0.80.1 → 0.81.1
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 +20 -0
- package/README.md +11 -0
- package/dist/_chunks/{build-metadata-BuTCjnNS.mjs → build-metadata-DyupzJpt.mjs} +1 -1
- package/dist/extension/extension.d.ts +15 -0
- package/dist/extension/extension.mjs +6 -2
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/evals.d.ts +7 -0
- package/dist/extension/lib/evals.mjs +7 -0
- package/dist/extension/lib/ontology-recall.d.ts +101 -0
- package/dist/extension/lib/ontology-recall.mjs +142 -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/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.81.1
|
|
4
|
+
|
|
5
|
+
Pins @segmentstream/ontology 0.156.1.
|
|
6
|
+
|
|
7
|
+
## 0.81.0
|
|
8
|
+
|
|
9
|
+
The agent can recall the workspace's ontology records at the start of every turn. `ontologyRecall()`
|
|
10
|
+
is a memory provider: a slot the workspace declares in `agent/agent/memory/<slot>.ts` with
|
|
11
|
+
`defineMemory` runs the reads it names (`entity`, `where` with `$me`, `select`, `orderBy`, `limit`)
|
|
12
|
+
as the session's person, through the same authorization as the agent's ontology tools, and puts
|
|
13
|
+
their result into the model's context, formatted by an optional `render`. It stores nothing and
|
|
14
|
+
adds no tools. A refused read, or a session without a person, recalls nothing and never fails the
|
|
15
|
+
turn. Each read returns at most 50 records and the recall at most 16,000 characters. `byPerson`
|
|
16
|
+
scopes a slot per person, and `byRoles` per set of roles for shared reads such as rules.
|
|
17
|
+
|
|
18
|
+
The package also re-exports eve's `defineMemory`, `defineHook`, `defineDynamic` and
|
|
19
|
+
`defineInstructions`, and `defineEval` and `defineEvalConfig` on the new
|
|
20
|
+
`@segmentstream/agent/evals` subpath, so the agent's files and evals import only SegmentStream's
|
|
21
|
+
packages.
|
|
22
|
+
|
|
3
23
|
## 0.80.1
|
|
4
24
|
|
|
5
25
|
Pins @segmentstream/ontology 0.156.0.
|
package/README.md
CHANGED
|
@@ -164,6 +164,17 @@ it is an eve dynamic skill, listed and loadable only in sessions started by a pe
|
|
|
164
164
|
of the roles. See personas and skills by role (`docs/agent.md#personas-and-skills-by-role`)
|
|
165
165
|
in the workspace agent guide.
|
|
166
166
|
|
|
167
|
+
## Memory: recall from the ontology
|
|
168
|
+
|
|
169
|
+
`ontologyRecall({ reads, render?, maxCharacters? })` is an eve memory provider. A slot the
|
|
170
|
+
workspace declares in `agent/agent/memory/<slot>.ts` with `defineMemory` runs the declared
|
|
171
|
+
`<entity>_find` reads as the session's person at the start of every turn and puts their result
|
|
172
|
+
into the model's context; it stores nothing and adds no tools. Scope it with `byPerson`, or
|
|
173
|
+
`byRoles` for shared reads. See memory (`docs/agent.md#memory-recall-from-the-ontology`) in the
|
|
174
|
+
workspace agent guide. The package also re-exports eve's `defineMemory`, `defineHook`,
|
|
175
|
+
`defineDynamic` and `defineInstructions`, and `defineEval` and `defineEvalConfig` on
|
|
176
|
+
`@segmentstream/agent/evals`.
|
|
177
|
+
|
|
167
178
|
## Reply review
|
|
168
179
|
|
|
169
180
|
`review` says, per role of the person the agent replies to, who sends its replies on every
|
|
@@ -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.81.1";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -25,6 +25,21 @@ export default segmentstream;
|
|
|
25
25
|
* runtime's own definition, offered here so that the agent's files import only this package.
|
|
26
26
|
*/
|
|
27
27
|
export { defineAgent } from "eve";
|
|
28
|
+
/**
|
|
29
|
+
* eve's seams for the workspace's own code in the agent, offered here so that its files import only
|
|
30
|
+
* this package: event hooks in `agent/agent/hooks/*.ts`, definitions computed per session (a
|
|
31
|
+
* model, tool, skill or instructions) and instructions in `agent/agent/instructions/*.ts`.
|
|
32
|
+
*/
|
|
33
|
+
export { defineDynamic } from "eve";
|
|
34
|
+
export { defineHook } from "eve/hooks";
|
|
35
|
+
export { defineInstructions } from "eve/instructions";
|
|
36
|
+
/**
|
|
37
|
+
* Memory: the workspace declares a slot in `agent/agent/memory/<slot>.ts` with `defineMemory`, as
|
|
38
|
+
* eve lets only the agent declare slots, and binds `ontologyRecall()`, which recalls ontology reads
|
|
39
|
+
* as the session's person at the start of each turn.
|
|
40
|
+
*/
|
|
41
|
+
export { defineMemory } from "eve/memory";
|
|
42
|
+
export { byPerson, byRoles, ontologyRecall, DEFAULT_RECALL_CHARACTERS, DEFAULT_RECALL_ROWS, MAX_RECALL_CHARACTERS, MAX_RECALL_READS, MAX_RECALL_ROWS, type OntologyRecallOptions, type RecallOrder, type RecallRead, type RecallResults, type RecallRow, } from "./lib/ontology-recall.js";
|
|
28
43
|
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 RecordSetting, type SegmentStreamAgentConfig, type SegmentStreamAgentConfigInput, type SessionScope, type SessionSettings, type TelegramPolicy, type TelegramSettings, type WebSettings, type BrowserSettings, type BrowserSettingsInput, type BrowserProxySettings, type WorkspaceChannelInput, type WorkspaceChannelSettings, } from "./config.js";
|
|
29
44
|
/**
|
|
30
45
|
* Defines a channel in the workspace's own code, `agent/agent/channels/<name>.ts`, for a provider
|
|
@@ -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 { DEFAULT_RECALL_CHARACTERS, DEFAULT_RECALL_ROWS, MAX_RECALL_CHARACTERS, MAX_RECALL_READS, MAX_RECALL_ROWS, byPerson, byRoles, ontologyRecall } from "./lib/ontology-recall.mjs";
|
|
9
10
|
import { defineChannel } from "./lib/workspace-channel/channel.mjs";
|
|
10
11
|
import { forRoles } from "./lib/role-skill.mjs";
|
|
11
12
|
import { DEFAULT_GROUP_POLICY, effectiveGroupPolicy, groupPolicy } from "./lib/group-routing/policy.mjs";
|
|
@@ -17,10 +18,13 @@ import { replayRouterPayload } from "./lib/group-routing/replay.mjs";
|
|
|
17
18
|
import { chatAddressing } from "./lib/group-routing/addressing.mjs";
|
|
18
19
|
import { routingBurst } from "./lib/group-routing/burst.mjs";
|
|
19
20
|
import { defineExtension } from "eve/extension";
|
|
20
|
-
import { defineAgent } from "eve";
|
|
21
|
+
import { defineAgent, defineDynamic } from "eve";
|
|
22
|
+
import { defineHook } from "eve/hooks";
|
|
23
|
+
import { defineInstructions } from "eve/instructions";
|
|
24
|
+
import { defineMemory } from "eve/memory";
|
|
21
25
|
const extension = defineExtension({ config: configSchema });
|
|
22
26
|
const segmentstream = Object.assign(extension, {
|
|
23
27
|
model,
|
|
24
28
|
manifestOf
|
|
25
29
|
});
|
|
26
|
-
export { DEFAULT_ADMISSION_LIMITS, DEFAULT_DECISION_MODEL, DEFAULT_GROUP_POLICY, DEFAULT_STT_MODEL, SegmentStreamAgentConfigError, archivedRoutingMessages, chatKey, chooseModel, segmentstream as default, segmentstream, defineAgent, defineChannel, effectiveGroupPolicy, forRoles, addressingReason as groupAddressingReason, agentMessage as groupAgentMessage, chatAddressing as groupChatAddressing, decisionRouter as groupDecisionRouter, groupPolicy, manifestOf, model, replayRouterPayload, routeMessage as routeGroupMessage, routingBurst };
|
|
30
|
+
export { DEFAULT_ADMISSION_LIMITS, DEFAULT_DECISION_MODEL, DEFAULT_GROUP_POLICY, DEFAULT_RECALL_CHARACTERS, DEFAULT_RECALL_ROWS, DEFAULT_STT_MODEL, MAX_RECALL_CHARACTERS, MAX_RECALL_READS, MAX_RECALL_ROWS, SegmentStreamAgentConfigError, archivedRoutingMessages, byPerson, byRoles, chatKey, chooseModel, segmentstream as default, segmentstream, defineAgent, defineChannel, defineDynamic, defineHook, defineInstructions, defineMemory, effectiveGroupPolicy, forRoles, addressingReason as groupAddressingReason, agentMessage as groupAgentMessage, chatAddressing as groupChatAddressing, decisionRouter as groupDecisionRouter, groupPolicy, manifestOf, model, ontologyRecall, replayRouterPayload, routeMessage as routeGroupMessage, routingBurst };
|
|
@@ -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-DyupzJpt.mjs";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* eve's evals, offered here so that a workspace's `evals/*.eval.ts` and `evals/evals.config.ts`
|
|
3
|
+
* import only this package. They are a subpath of their own: evals run beside the agent, and the
|
|
4
|
+
* agent's own bundle never loads them.
|
|
5
|
+
*/
|
|
6
|
+
export { defineEval, defineEvalConfig } from "eve/evals";
|
|
7
|
+
export type { EveEval, EveEvalConfig, EveEvalContext, EveEvalDefinition } from "eve/evals";
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
export { defineEval, defineEvalConfig } from "eve/evals";
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type MemoryProvider, type MemoryScopeContext } from "eve/memory";
|
|
2
|
+
import { ontologyTools } from "./ontology-tools.js";
|
|
3
|
+
/**
|
|
4
|
+
* Recall from the ontology: an eve memory provider whose recall puts the result of ontology reads
|
|
5
|
+
* the workspace declares into the agent's context at the start of each turn. The reads run as the
|
|
6
|
+
* session's person, through the same ontology client and headers as the agent's ontology tools, so
|
|
7
|
+
* the ontology's permissions decide what is recalled. The provider stores nothing, captures nothing
|
|
8
|
+
* and offers no tools: the agent writes through the workspace's own actions.
|
|
9
|
+
*
|
|
10
|
+
* eve lets only the agent declare memory slots, so the workspace binds the provider in its own
|
|
11
|
+
* `agent/agent/memory/<slot>.ts`:
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { byPerson, defineMemory, ontologyRecall } from "@segmentstream/agent";
|
|
15
|
+
*
|
|
16
|
+
* export default defineMemory({
|
|
17
|
+
* provider: ontologyRecall({
|
|
18
|
+
* reads: {
|
|
19
|
+
* me: { entity: "person", where: { user: { $me: [] } }, limit: 1 },
|
|
20
|
+
* notes: {
|
|
21
|
+
* entity: "note",
|
|
22
|
+
* where: { person: { user: { $me: [] } } },
|
|
23
|
+
* orderBy: [{ field: "created_at", direction: "desc" }],
|
|
24
|
+
* limit: 5,
|
|
25
|
+
* },
|
|
26
|
+
* },
|
|
27
|
+
* }),
|
|
28
|
+
* scope: byPerson,
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
/** The most rows one read recalls, whatever it asks for. */
|
|
33
|
+
export declare const MAX_RECALL_ROWS = 50;
|
|
34
|
+
/** The rows a read recalls when it names no `limit`. */
|
|
35
|
+
export declare const DEFAULT_RECALL_ROWS = 10;
|
|
36
|
+
/** The most characters one slot's recall puts into context, whatever it asks for. */
|
|
37
|
+
export declare const MAX_RECALL_CHARACTERS = 16000;
|
|
38
|
+
/** The characters a slot's recall puts into context when it names no `maxCharacters`. */
|
|
39
|
+
export declare const DEFAULT_RECALL_CHARACTERS = 4000;
|
|
40
|
+
/** The most reads one slot declares. */
|
|
41
|
+
export declare const MAX_RECALL_READS = 8;
|
|
42
|
+
/** One sort key of a read, as `<entity>_find` takes it. */
|
|
43
|
+
export interface RecallOrder {
|
|
44
|
+
readonly field: string;
|
|
45
|
+
readonly direction?: "asc" | "desc";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* One declared read: the records of `entity` that match `where`, as the agent's `<entity>_find`
|
|
49
|
+
* tool reads them for the session's person. `where` is that tool's query language, where
|
|
50
|
+
* `{ "$me": [] }` is the person's user id.
|
|
51
|
+
*/
|
|
52
|
+
export interface RecallRead {
|
|
53
|
+
readonly entity: string;
|
|
54
|
+
readonly where?: Readonly<Record<string, unknown>>;
|
|
55
|
+
/** The fields to recall; the id always comes too. All of them when omitted. */
|
|
56
|
+
readonly select?: ReadonlyArray<string>;
|
|
57
|
+
readonly orderBy?: ReadonlyArray<RecallOrder>;
|
|
58
|
+
/** At most {@link MAX_RECALL_ROWS}; {@link DEFAULT_RECALL_ROWS} when omitted. */
|
|
59
|
+
readonly limit?: number;
|
|
60
|
+
}
|
|
61
|
+
/** A recalled record, as `<entity>_find` returns it. */
|
|
62
|
+
export type RecallRow = Readonly<Record<string, unknown>>;
|
|
63
|
+
/**
|
|
64
|
+
* The rows of each read that answered. A read the ontology refused, or that failed, is absent, so
|
|
65
|
+
* `render` can tell "none" from "not allowed".
|
|
66
|
+
*/
|
|
67
|
+
export type RecallResults<Reads extends Readonly<Record<string, RecallRead>>> = {
|
|
68
|
+
readonly [Name in keyof Reads]?: ReadonlyArray<RecallRow>;
|
|
69
|
+
};
|
|
70
|
+
export interface OntologyRecallOptions<Reads extends Readonly<Record<string, RecallRead>>> {
|
|
71
|
+
/** The reads, by a name of the workspace's choosing, which the default rendering shows. */
|
|
72
|
+
readonly reads: Reads;
|
|
73
|
+
/**
|
|
74
|
+
* Formats the recalled rows into the text the model reads; a pure function of its input. Without
|
|
75
|
+
* it, each read is its name followed by one JSON line per row. Blank text recalls nothing.
|
|
76
|
+
*/
|
|
77
|
+
readonly render?: (results: RecallResults<Reads>) => string;
|
|
78
|
+
/** At most {@link MAX_RECALL_CHARACTERS}; {@link DEFAULT_RECALL_CHARACTERS} when omitted. */
|
|
79
|
+
readonly maxCharacters?: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Memory scope per person, from the principal a SegmentStream channel stamped, never from model
|
|
83
|
+
* input. Use it for any read whose answer depends on who asks, such as one with `$me`: when another
|
|
84
|
+
* person speaks in the session, eve drops what was recalled for the previous one. Sessions without a
|
|
85
|
+
* person, such as a workflow task's, have no scope, which turns the slot off.
|
|
86
|
+
*/
|
|
87
|
+
export declare function byPerson(context: MemoryScopeContext): string | null;
|
|
88
|
+
/**
|
|
89
|
+
* Memory scope per set of roles, for shared reads whose answer is the same for everyone holding
|
|
90
|
+
* those roles, such as a workspace's sales rules. The reads still run as the session's person; the
|
|
91
|
+
* scope only lets people with the same roles share eve's slot. Never use it for a read with `$me`.
|
|
92
|
+
*/
|
|
93
|
+
export declare function byRoles(context: MemoryScopeContext): string | readonly string[] | null;
|
|
94
|
+
/**
|
|
95
|
+
* An eve memory provider that recalls the declared ontology reads as the session's person. A
|
|
96
|
+
* session without a person recalls nothing; a read the ontology refuses or that fails recalls
|
|
97
|
+
* nothing and never fails the turn, and is never retried more widely.
|
|
98
|
+
*/
|
|
99
|
+
export declare function ontologyRecall<const Reads extends Readonly<Record<string, RecallRead>>>(options: OntologyRecallOptions<Reads>): MemoryProvider;
|
|
100
|
+
/** {@link ontologyRecall} with the ontology client's transport, which tests replace. */
|
|
101
|
+
export declare function recallProvider<const Reads extends Readonly<Record<string, RecallRead>>>(options: OntologyRecallOptions<Reads>, transport?: Omit<Parameters<typeof ontologyTools>[0], "principal" | "sessionId">): MemoryProvider;
|
|
@@ -0,0 +1,142 @@
|
|
|
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 { H as actorOf, a as rolesOf, j as ontologyTools, k as actionToolName } from "../../_chunks/principal-CVV9C_nO.mjs";
|
|
8
|
+
import { object } from "./confirmation-description.mjs";
|
|
9
|
+
import { redactDiagnostic } from "./diagnostics.mjs";
|
|
10
|
+
import { defineMemoryProvider } from "eve/memory";
|
|
11
|
+
const MAX_RECALL_ROWS = 50;
|
|
12
|
+
const DEFAULT_RECALL_ROWS = 10;
|
|
13
|
+
const MAX_RECALL_CHARACTERS = 16e3;
|
|
14
|
+
const DEFAULT_RECALL_CHARACTERS = 4e3;
|
|
15
|
+
const MAX_RECALL_READS = 8;
|
|
16
|
+
const RECALL_TIMEOUT_MS = 1e4;
|
|
17
|
+
const RECALL_ID = "ontology-recall";
|
|
18
|
+
const NAME = /^[a-z][a-zA-Z0-9_]*$/;
|
|
19
|
+
const ENTITY = /^(?:[a-z][a-zA-Z0-9]*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$/;
|
|
20
|
+
function bounded(value, fallback, maximum, what) {
|
|
21
|
+
if (value === void 0) return fallback;
|
|
22
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > maximum) throw new TypeError(`ontologyRecall() takes ${what} from 1 to ${maximum}.`);
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function personOf(principal) {
|
|
26
|
+
const actor = actorOf(principal);
|
|
27
|
+
return actor === void 0 || actor.kind === "task" ? void 0 : actor;
|
|
28
|
+
}
|
|
29
|
+
function personKey(actor) {
|
|
30
|
+
switch (actor.kind) {
|
|
31
|
+
case "guest": return `guest:${actor.guestId}`;
|
|
32
|
+
case "member":
|
|
33
|
+
case "revision": return `member:${actor.memberId}`;
|
|
34
|
+
case "task": return `task:${actor.taskId}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function byPerson(context) {
|
|
38
|
+
const actor = personOf(context.session.auth.current);
|
|
39
|
+
return actor === void 0 ? null : personKey(actor);
|
|
40
|
+
}
|
|
41
|
+
function byRoles(context) {
|
|
42
|
+
const principal = context.session.auth.current;
|
|
43
|
+
if (personOf(principal) === void 0) return null;
|
|
44
|
+
const roles = [...new Set(rolesOf(principal))].sort();
|
|
45
|
+
return roles.length <= 15 ? ["roles", ...roles] : ["roles", JSON.stringify(roles)];
|
|
46
|
+
}
|
|
47
|
+
function defaultRender(results, budget) {
|
|
48
|
+
const lines = [];
|
|
49
|
+
let used = 0;
|
|
50
|
+
for (const [name, rows] of Object.entries(results)) {
|
|
51
|
+
if (rows === void 0) continue;
|
|
52
|
+
const header = `${name}:`;
|
|
53
|
+
if (used + header.length + 1 > budget) break;
|
|
54
|
+
lines.push(header);
|
|
55
|
+
used += header.length + 1;
|
|
56
|
+
for (const row of rows) {
|
|
57
|
+
const line = JSON.stringify(row);
|
|
58
|
+
if (used + line.length + 1 > budget) break;
|
|
59
|
+
lines.push(line);
|
|
60
|
+
used += line.length + 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return lines.join("\n");
|
|
64
|
+
}
|
|
65
|
+
function cut(text, limit) {
|
|
66
|
+
if (text.length <= limit) return text;
|
|
67
|
+
const end = /[\uD800-\uDBFF]/.test(text[limit - 1] ?? "") ? limit - 1 : limit;
|
|
68
|
+
return text.slice(0, end);
|
|
69
|
+
}
|
|
70
|
+
function ontologyRecall(options) {
|
|
71
|
+
return recallProvider(options);
|
|
72
|
+
}
|
|
73
|
+
function recallProvider(options, transport = {}) {
|
|
74
|
+
const entries = Object.entries(options.reads ?? {});
|
|
75
|
+
if (entries.length === 0 || entries.length > 8) throw new TypeError(`ontologyRecall() takes from 1 to 8 reads.`);
|
|
76
|
+
const reads = entries.map(([name, read]) => {
|
|
77
|
+
if (!NAME.test(name)) throw new TypeError(`ontologyRecall() read name "${name}" must be an identifier.`);
|
|
78
|
+
if (typeof read?.entity !== "string" || !ENTITY.test(read.entity)) throw new TypeError(`ontologyRecall() read "${name}" needs an entity name.`);
|
|
79
|
+
return {
|
|
80
|
+
name,
|
|
81
|
+
tool: actionToolName(read.entity, "find"),
|
|
82
|
+
limit: bounded(read.limit, 10, 50, `a read's limit`),
|
|
83
|
+
arguments: {
|
|
84
|
+
...read.where === void 0 ? {} : { where: read.where },
|
|
85
|
+
...read.select === void 0 ? {} : { select: [...read.select] },
|
|
86
|
+
...read.orderBy === void 0 ? {} : { order_by: read.orderBy.map((order) => ({ ...order })) }
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
const maxCharacters = bounded(options.maxCharacters, DEFAULT_RECALL_CHARACTERS, MAX_RECALL_CHARACTERS, "maxCharacters");
|
|
91
|
+
async function recall(context) {
|
|
92
|
+
const principal = context.session.auth.current;
|
|
93
|
+
const actor = personOf(principal);
|
|
94
|
+
if (actor === void 0) return null;
|
|
95
|
+
const client = ontologyTools({
|
|
96
|
+
...transport,
|
|
97
|
+
principal,
|
|
98
|
+
sessionId: context.session.id
|
|
99
|
+
});
|
|
100
|
+
const signal = AbortSignal.any([context.abortSignal, AbortSignal.timeout(RECALL_TIMEOUT_MS)]);
|
|
101
|
+
const answers = await Promise.all(reads.map(async (read) => {
|
|
102
|
+
try {
|
|
103
|
+
const result = await client.rpc(actor, "tools/call", {
|
|
104
|
+
name: read.tool,
|
|
105
|
+
arguments: {
|
|
106
|
+
...read.arguments,
|
|
107
|
+
limit: read.limit
|
|
108
|
+
}
|
|
109
|
+
}, signal);
|
|
110
|
+
const items = object(result.structuredContent).items;
|
|
111
|
+
if (!Array.isArray(items)) throw new Error("The ontology answered a recall read without items.");
|
|
112
|
+
const rows = items.slice(0, read.limit).filter((row) => typeof row === "object" && row !== null);
|
|
113
|
+
return [read.name, rows];
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.warn("[segmentstream] ontology_recall_read_failed", {
|
|
116
|
+
slot: context.memory.slot,
|
|
117
|
+
read: read.name,
|
|
118
|
+
error: redactDiagnostic(error, new Set())
|
|
119
|
+
});
|
|
120
|
+
return [read.name, void 0];
|
|
121
|
+
}
|
|
122
|
+
}));
|
|
123
|
+
const results = Object.fromEntries(answers.filter((answer) => answer[1] !== void 0));
|
|
124
|
+
let text;
|
|
125
|
+
try {
|
|
126
|
+
text = options.render === void 0 ? defaultRender(results, maxCharacters) : String(options.render(results) ?? "");
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.warn("[segmentstream] ontology_recall_render_failed", {
|
|
129
|
+
slot: context.memory.slot,
|
|
130
|
+
error: redactDiagnostic(error, new Set())
|
|
131
|
+
});
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const content = cut(text, maxCharacters);
|
|
135
|
+
return content.trim() === "" ? null : { messages: [{
|
|
136
|
+
id: RECALL_ID,
|
|
137
|
+
content
|
|
138
|
+
}] };
|
|
139
|
+
}
|
|
140
|
+
return defineMemoryProvider({ recall: { "turn.started": recall } });
|
|
141
|
+
}
|
|
142
|
+
export { DEFAULT_RECALL_CHARACTERS, DEFAULT_RECALL_ROWS, MAX_RECALL_CHARACTERS, MAX_RECALL_READS, MAX_RECALL_ROWS, byPerson, byRoles, ontologyRecall, recallProvider };
|
|
@@ -10,7 +10,7 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
|
|
|
10
10
|
import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
|
|
11
11
|
import { handleWorkspaceCallback } 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-DyupzJpt.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-DyupzJpt.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-CVV9C_nO.mjs";
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
8
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-DyupzJpt.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.81.1",
|
|
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",
|
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
"types": "./dist/extension/lib/traces.d.ts",
|
|
43
43
|
"default": "./dist/extension/lib/traces.mjs"
|
|
44
44
|
},
|
|
45
|
+
"./evals": {
|
|
46
|
+
"types": "./dist/extension/lib/evals.d.ts",
|
|
47
|
+
"default": "./dist/extension/lib/evals.mjs"
|
|
48
|
+
},
|
|
45
49
|
"./tools": {
|
|
46
50
|
"types": "./dist/tools/index.d.ts",
|
|
47
51
|
"default": "./dist/tools/index.mjs"
|
|
@@ -84,7 +88,7 @@
|
|
|
84
88
|
"@chat-adapter/state-memory": "4.42.0",
|
|
85
89
|
"@chat-adapter/telegram": "4.41.0",
|
|
86
90
|
"@chat-adapter/whatsapp": "4.42.0",
|
|
87
|
-
"@segmentstream/ontology": "0.156.
|
|
91
|
+
"@segmentstream/ontology": "0.156.1",
|
|
88
92
|
"@vercel/oidc": "^3.8.4",
|
|
89
93
|
"ai": "^7.0.172",
|
|
90
94
|
"chat": "4.42.0",
|