@segmentstream/agent 0.51.1 → 0.52.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 +49 -0
- package/README.md +65 -27
- package/dist/_chunks/{build-metadata-BDr_toej.mjs → build-metadata-DJ3WHCte.mjs} +1 -1
- package/dist/_chunks/{principal-ie0lHCpn.mjs → principal-JoaOmdFL.mjs} +114 -11
- package/dist/extension/config.d.ts +37 -1
- package/dist/extension/config.mjs +74 -3
- package/dist/extension/connections/ontology.mjs +1 -1
- package/dist/extension/extension.d.ts +1 -1
- package/dist/extension/hooks/authorization.mjs +1 -1
- package/dist/extension/instructions/persona.mjs +1 -1
- package/dist/extension/instructions/sandbox.mjs +2 -1
- package/dist/extension/lib/actor.d.ts +17 -6
- package/dist/extension/lib/actor.mjs +1 -1
- package/dist/extension/lib/admission.mjs +10 -1
- package/dist/extension/lib/agent-task.d.ts +2 -0
- package/dist/extension/lib/agent-task.mjs +6 -2
- package/dist/extension/lib/agent-tools.d.ts +42 -0
- package/dist/extension/lib/agent-tools.mjs +43 -0
- package/dist/extension/lib/attachment-tools.mjs +1 -1
- package/dist/extension/lib/attachments.mjs +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-address.mjs +1 -1
- package/dist/extension/lib/chat-context.mjs +1 -1
- package/dist/extension/lib/chat-recorder.mjs +10 -1
- package/dist/extension/lib/confirmations.mjs +1 -1
- package/dist/extension/lib/email/channel.mjs +3 -1
- package/dist/extension/lib/html-text.d.ts +14 -0
- package/dist/extension/lib/html-text.mjs +198 -0
- package/dist/extension/lib/identities.d.ts +5 -0
- package/dist/extension/lib/identities.mjs +4 -1
- package/dist/extension/lib/inbound-media/files.mjs +1 -1
- package/dist/extension/lib/inbound-media/index.mjs +1 -1
- package/dist/extension/lib/ontology-connection.mjs +1 -1
- package/dist/extension/lib/ontology-file-call.mjs +7 -1
- package/dist/extension/lib/ontology-tools.mjs +1 -1
- package/dist/extension/lib/review/hold.mjs +1 -1
- package/dist/extension/lib/review/reply.mjs +1 -1
- package/dist/extension/lib/role-skill.mjs +1 -1
- package/dist/extension/lib/runtime-envelope.mjs +1 -1
- package/dist/extension/lib/sent-files.mjs +1 -1
- package/dist/extension/lib/slack/adapter.mjs +3 -1
- package/dist/extension/lib/slack/attachments-send.mjs +1 -1
- package/dist/extension/lib/stored-files.mjs +1 -1
- package/dist/extension/lib/telegram/adapter.mjs +2 -2
- package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
- package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
- package/dist/extension/lib/telegram/callbacks.mjs +1 -1
- package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
- package/dist/extension/lib/telegram/confirmations.mjs +1 -1
- package/dist/extension/lib/telegram/customer-text.mjs +1 -1
- package/dist/extension/lib/telegram/files.mjs +1 -1
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
- package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +1 -1
- package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
- package/dist/extension/lib/telegram/principal.mjs +1 -1
- package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
- package/dist/extension/lib/telegram/silent.mjs +1 -1
- package/dist/extension/lib/telegram/structured.mjs +1 -1
- package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
- package/dist/extension/lib/telegram/workspace-action.mjs +1 -1
- package/dist/extension/lib/web/auth.d.ts +65 -8
- package/dist/extension/lib/web/auth.mjs +1 -1
- package/dist/extension/lib/web/channel.d.ts +10 -6
- package/dist/extension/lib/web/channel.mjs +1 -1
- package/dist/extension/lib/web-fetch.d.ts +60 -0
- package/dist/extension/lib/web-fetch.mjs +244 -0
- package/dist/extension/lib/whatsapp/adapter.mjs +3 -1
- package/dist/extension/lib/whatsapp/files.mjs +1 -1
- package/dist/extension/lib/workspace-source.mjs +1 -1
- package/dist/extension/model.mjs +1 -1
- package/dist/extension/tools/attachments_discard.mjs +1 -1
- package/dist/extension/tools/attachments_list.mjs +1 -1
- package/dist/extension/tools/attachments_promote.mjs +3 -1
- package/dist/extension/tools/attachments_read.mjs +1 -1
- package/dist/extension/tools/attachments_send.mjs +1 -1
- package/dist/extension/tools/attachments_stage.d.ts +2 -2
- package/dist/extension/tools/attachments_stage.mjs +7 -2
- package/dist/extension/tools/attachments_table.mjs +1 -1
- package/dist/extension/tools/ontology_call_file.d.ts +1 -0
- package/dist/extension/tools/ontology_call_file.mjs +2 -1
- package/dist/extension/tools/questions_ask.d.ts +1 -3
- package/dist/extension/tools/questions_ask.mjs +3 -3
- package/dist/extension/tools/sandbox.mjs +5 -1
- package/dist/extension/tools/web_fetch.d.ts +2 -0
- package/dist/extension/tools/web_fetch.mjs +73 -0
- package/dist/extension/tools/workspace_source.mjs +4 -2
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.mjs +2 -1
- package/package.json +2 -2
|
@@ -28,7 +28,11 @@ const DEFAULT_ADMISSION_LIMITS = {
|
|
|
28
28
|
turnsPerDay: 80
|
|
29
29
|
},
|
|
30
30
|
newUsersPerHour: 30,
|
|
31
|
-
workspaceTurnsPerDay: 3e3
|
|
31
|
+
workspaceTurnsPerDay: 3e3,
|
|
32
|
+
guest: {
|
|
33
|
+
turnsPerDay: 20,
|
|
34
|
+
workspaceTurnsPerDay: 1e3
|
|
35
|
+
}
|
|
32
36
|
};
|
|
33
37
|
const ADMISSION_REPLY_KEYS = [
|
|
34
38
|
"pairingRequired",
|
|
@@ -184,6 +188,46 @@ const EMAIL_CHECK_MINUTES = {
|
|
|
184
188
|
};
|
|
185
189
|
const DEFAULT_EMAIL_QUERY = "in:inbox";
|
|
186
190
|
const PUBSUB_TOPIC = /^projects\/[a-z][a-z0-9-]{4,28}[a-z0-9]\/topics\/[A-Za-z][A-Za-z0-9._~%+-]{2,254}$/;
|
|
191
|
+
const MAXIMUM_WEB_DOMAINS = 50;
|
|
192
|
+
const WEB_DOMAIN = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
193
|
+
function webSettings(value, issues) {
|
|
194
|
+
const path = ["web"];
|
|
195
|
+
const web = section({
|
|
196
|
+
value,
|
|
197
|
+
path,
|
|
198
|
+
allowed: ["domains"],
|
|
199
|
+
issues
|
|
200
|
+
});
|
|
201
|
+
if (web === void 0) return null;
|
|
202
|
+
const domains = web.domains;
|
|
203
|
+
if (!Array.isArray(domains) || domains.length === 0 || domains.length > 50) {
|
|
204
|
+
issues.push({
|
|
205
|
+
message: `must list from 1 to 50 domains, such as ["example.com"]; remove web for no web tools`,
|
|
206
|
+
path: [...path, "domains"]
|
|
207
|
+
});
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const before = issues.length;
|
|
211
|
+
domains.forEach((domain, index) => {
|
|
212
|
+
if (typeof domain !== "string" || !WEB_DOMAIN.test(domain)) issues.push({
|
|
213
|
+
message: "must be a bare lower-case domain such as example.com, without scheme, port, path or wildcard; it covers its subdomains",
|
|
214
|
+
path: [
|
|
215
|
+
...path,
|
|
216
|
+
"domains",
|
|
217
|
+
String(index)
|
|
218
|
+
]
|
|
219
|
+
});
|
|
220
|
+
else if (domains.indexOf(domain) !== index) issues.push({
|
|
221
|
+
message: "is listed twice",
|
|
222
|
+
path: [
|
|
223
|
+
...path,
|
|
224
|
+
"domains",
|
|
225
|
+
String(index)
|
|
226
|
+
]
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
return issues.length > before ? null : { domains };
|
|
230
|
+
}
|
|
187
231
|
function emailSettings(value, issues) {
|
|
188
232
|
const path = ["channels", "email"];
|
|
189
233
|
const email = section({
|
|
@@ -550,6 +594,12 @@ function firstContactSettings(value, issues, safe = true) {
|
|
|
550
594
|
notice
|
|
551
595
|
};
|
|
552
596
|
}
|
|
597
|
+
function admissionLimitsOf(value) {
|
|
598
|
+
const issues = [];
|
|
599
|
+
const limits = admissionLimits(value, issues);
|
|
600
|
+
if (issues.length > 0) throw new SegmentStreamAgentConfigError(issues);
|
|
601
|
+
return limits;
|
|
602
|
+
}
|
|
553
603
|
function admissionLimits(value, issues) {
|
|
554
604
|
const path = ["limits"];
|
|
555
605
|
const limits = section({
|
|
@@ -564,6 +614,12 @@ function admissionLimits(value, issues) {
|
|
|
564
614
|
allowed: Object.keys(DEFAULT_ADMISSION_LIMITS.perSender),
|
|
565
615
|
issues
|
|
566
616
|
});
|
|
617
|
+
const guest = section({
|
|
618
|
+
value: limits?.guest,
|
|
619
|
+
path: [...path, "guest"],
|
|
620
|
+
allowed: Object.keys(DEFAULT_ADMISSION_LIMITS.guest),
|
|
621
|
+
issues
|
|
622
|
+
});
|
|
567
623
|
function limit(value, ceiling, path) {
|
|
568
624
|
if (value === void 0) return ceiling;
|
|
569
625
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > ceiling) {
|
|
@@ -589,7 +645,19 @@ function admissionLimits(value, issues) {
|
|
|
589
645
|
])
|
|
590
646
|
},
|
|
591
647
|
newUsersPerHour: limit(limits?.newUsersPerHour, DEFAULT_ADMISSION_LIMITS.newUsersPerHour, [...path, "newUsersPerHour"]),
|
|
592
|
-
workspaceTurnsPerDay: limit(limits?.workspaceTurnsPerDay, DEFAULT_ADMISSION_LIMITS.workspaceTurnsPerDay, [...path, "workspaceTurnsPerDay"])
|
|
648
|
+
workspaceTurnsPerDay: limit(limits?.workspaceTurnsPerDay, DEFAULT_ADMISSION_LIMITS.workspaceTurnsPerDay, [...path, "workspaceTurnsPerDay"]),
|
|
649
|
+
guest: {
|
|
650
|
+
turnsPerDay: limit(guest?.turnsPerDay, DEFAULT_ADMISSION_LIMITS.guest.turnsPerDay, [
|
|
651
|
+
...path,
|
|
652
|
+
"guest",
|
|
653
|
+
"turnsPerDay"
|
|
654
|
+
]),
|
|
655
|
+
workspaceTurnsPerDay: limit(guest?.workspaceTurnsPerDay, DEFAULT_ADMISSION_LIMITS.guest.workspaceTurnsPerDay, [
|
|
656
|
+
...path,
|
|
657
|
+
"guest",
|
|
658
|
+
"workspaceTurnsPerDay"
|
|
659
|
+
])
|
|
660
|
+
}
|
|
593
661
|
};
|
|
594
662
|
}
|
|
595
663
|
function admissionReplies(value, issues, safe = true) {
|
|
@@ -695,6 +763,7 @@ function validateConfig(input, options = {}) {
|
|
|
695
763
|
"ontology",
|
|
696
764
|
"sandbox",
|
|
697
765
|
"workspaceSource",
|
|
766
|
+
"web",
|
|
698
767
|
"sessions",
|
|
699
768
|
"confirmations",
|
|
700
769
|
"firstContact",
|
|
@@ -896,6 +965,7 @@ function validateConfig(input, options = {}) {
|
|
|
896
965
|
message: "requires sandbox to be true",
|
|
897
966
|
path: ["workspaceSource"]
|
|
898
967
|
});
|
|
968
|
+
const web = webSettings(root?.web, issues);
|
|
899
969
|
const personas = personaSettings(root?.personas, issues, options.texts === "required");
|
|
900
970
|
if (root?.review !== void 0 && root.conversations !== void 0) issues.push({
|
|
901
971
|
path: ["conversations"],
|
|
@@ -924,6 +994,7 @@ function validateConfig(input, options = {}) {
|
|
|
924
994
|
ontology: { connection: connection === true },
|
|
925
995
|
sandbox: sandbox === true,
|
|
926
996
|
...workspaceSource === true ? { workspaceSource: true } : {},
|
|
997
|
+
...web === null ? {} : { web },
|
|
927
998
|
sessions,
|
|
928
999
|
firstContact,
|
|
929
1000
|
limits,
|
|
@@ -954,4 +1025,4 @@ function manifestOf(config) {
|
|
|
954
1025
|
if (validation.issues !== void 0) throw new SegmentStreamAgentConfigError(validation.issues);
|
|
955
1026
|
return validation.value;
|
|
956
1027
|
}
|
|
957
|
-
export { ADMISSION_REPLY_KEYS, DEFAULT_ADMISSION_LIMITS, DEFAULT_ATTACHMENTS_MODEL, DEFAULT_DECISION_MODEL, DEFAULT_EMAIL_QUERY, DEFAULT_IMAGE_DESCRIPTION_MODEL, DEFAULT_STT_MODEL, EMAIL_CHECK_MINUTES, PUBSUB_TOPIC, SESSION_SCOPES, SegmentStreamAgentConfigError, TELEGRAM_POLICIES, chatModelChoiceOf, configSchema, configWarnings, isLegacyAgentArchive, manifestOf, validateConfig };
|
|
1028
|
+
export { ADMISSION_REPLY_KEYS, DEFAULT_ADMISSION_LIMITS, DEFAULT_ATTACHMENTS_MODEL, DEFAULT_DECISION_MODEL, DEFAULT_EMAIL_QUERY, DEFAULT_IMAGE_DESCRIPTION_MODEL, DEFAULT_STT_MODEL, EMAIL_CHECK_MINUTES, MAXIMUM_WEB_DOMAINS, PUBSUB_TOPIC, SESSION_SCOPES, SegmentStreamAgentConfigError, TELEGRAM_POLICIES, admissionLimitsOf, chatModelChoiceOf, configSchema, configWarnings, isLegacyAgentArchive, manifestOf, validateConfig };
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
-
import { D as ontologyConnection } from "../../_chunks/principal-
|
|
8
|
+
import { D as ontologyConnection } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
9
9
|
import { defineDynamic } from "eve/connections";
|
|
10
10
|
var ontology_default = defineDynamic(async (context) => {
|
|
11
11
|
if (!segmentstream.config.ontology.connection) return null;
|
|
@@ -25,7 +25,7 @@ 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
|
-
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";
|
|
28
|
+
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, type WebSettings, } from "./config.js";
|
|
29
29
|
export { chooseModel, model, type DynamicModel, type ModelChoice } from "./model.js";
|
|
30
30
|
export { forRoles } from "./lib/role-skill.js";
|
|
31
31
|
export { groupPolicy, effectiveGroupPolicy, DEFAULT_GROUP_POLICY, type GroupPolicy, type GroupPolicyInput, type SmartPolicyInput, type ChatOverrideInput, } from "./lib/group-routing/policy.js";
|
|
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
|
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
8
|
import { localizedText } from "../lib/admission.mjs";
|
|
9
9
|
import { confirmationLocale } from "../lib/telegram/confirmation-text.mjs";
|
|
10
|
-
import "../../_chunks/principal-
|
|
10
|
+
import "../../_chunks/principal-JoaOmdFL.mjs";
|
|
11
11
|
import { defineHook } from "eve/hooks";
|
|
12
12
|
var authorization_default = defineHook({ events: { "interaction.opened": (event, context) => {
|
|
13
13
|
const principal = context.session.auth.current;
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
-
import { a as rolesOf } from "../../_chunks/principal-
|
|
8
|
+
import { a as rolesOf } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
9
9
|
import { personaFor } from "../personas.mjs";
|
|
10
10
|
import { defineDynamic, defineInstructions } from "eve/instructions";
|
|
11
11
|
var persona_default = defineDynamic((context) => {
|
|
@@ -5,6 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import segmentstream from "../extension.mjs";
|
|
8
|
+
import { holdsAgentTool } from "../lib/agent-tools.mjs";
|
|
8
9
|
import { defineDynamic, defineInstructions } from "eve/instructions";
|
|
9
10
|
const WORKSPACE_SOURCE_INSTRUCTIONS = `- To find out what this workspace can and cannot do, or why
|
|
10
11
|
something the member asked for fails, when the tools' own descriptions do not settle it, read
|
|
@@ -65,7 +66,7 @@ const SANDBOX_RULES = `- \`segmentstream__read_file\` shows PNG, JPEG, GIF and W
|
|
|
65
66
|
- The sandbox is temporary. It is discarded when the chat's history resets and replaced after a
|
|
66
67
|
day; keep what matters through the ontology. To keep a file you produced, pass its path inside
|
|
67
68
|
/workspace to \`segmentstream__attachments_promote\` instead of an id.`;
|
|
68
|
-
var sandbox_default = defineDynamic(() => segmentstream.config.sandbox ? defineInstructions({
|
|
69
|
+
var sandbox_default = defineDynamic((context) => segmentstream.config.sandbox && holdsAgentTool(context.session.auth.current, "sandbox") ? defineInstructions({
|
|
69
70
|
role: "system",
|
|
70
71
|
content: SANDBOX_INSTRUCTIONS + (segmentstream.config.workspaceSource === true ? WORKSPACE_SOURCE_INSTRUCTIONS : "") + SANDBOX_RULES
|
|
71
72
|
}) : null);
|
|
@@ -3,21 +3,26 @@ import { type DynamicToolEntry } from "eve/tools";
|
|
|
3
3
|
/** The header that names the member a runtime caller acts for. */
|
|
4
4
|
export declare const ACT_AS_HEADER = "X-SegmentStream-Act-As";
|
|
5
5
|
/**
|
|
6
|
-
* Whom a session acts for at the ontology: the paired member who writes,
|
|
7
|
-
*
|
|
8
|
-
* SegmentStream channel stamped, never from the model.
|
|
6
|
+
* Whom a session acts for at the ontology: the paired member who writes, a guest of a declared
|
|
7
|
+
* website, who is no member, or the workflow user of a task, whom the ontology resolves from the
|
|
8
|
+
* task's secret. It comes from the principal a SegmentStream channel stamped, never from the model.
|
|
9
9
|
*/
|
|
10
10
|
export type OntologyActor = {
|
|
11
11
|
readonly kind: "member";
|
|
12
12
|
readonly memberId: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "guest";
|
|
15
|
+
readonly guestId: string;
|
|
13
16
|
} | {
|
|
14
17
|
readonly kind: "task";
|
|
15
18
|
readonly taskId: string;
|
|
16
19
|
};
|
|
17
20
|
export declare function member(memberId: string): OntologyActor;
|
|
18
21
|
export declare function actorOf(principal: SessionAuthContext | null | undefined): OntologyActor | undefined;
|
|
19
|
-
/** A stable key per actor, such as `member:<id>` or `task:<id>`. */
|
|
22
|
+
/** A stable key per actor, such as `member:<id>`, `guest:<id>` or `task:<id>`. */
|
|
20
23
|
export declare function actorKey(actor: OntologyActor): string;
|
|
24
|
+
/** Whether a session acts for a guest, who is no member and has no chat but their own. */
|
|
25
|
+
export declare function isGuestSession(principal: SessionAuthContext | null | undefined): boolean;
|
|
21
26
|
/** The session has no member or task to act for, or not the one a client was opened for. */
|
|
22
27
|
export declare class ActorRequiredError extends Error {
|
|
23
28
|
readonly name = "ActorRequiredError";
|
|
@@ -33,7 +38,13 @@ export declare function actorHeaders(input: {
|
|
|
33
38
|
readonly secret?: (taskId: string) => string | undefined;
|
|
34
39
|
}): Record<string, string>;
|
|
35
40
|
/**
|
|
36
|
-
* A tool only a member's session offers. A task has no chat, attachments or member files,
|
|
37
|
-
*
|
|
41
|
+
* A tool only a member's session offers. A task has no chat, attachments or member files, and a
|
|
42
|
+
* guest is no member, so neither session is offered the tool at all; other sessions get it as
|
|
43
|
+
* before.
|
|
38
44
|
*/
|
|
39
45
|
export declare function memberTool<Tool extends DynamicToolEntry>(tool: Tool): import("eve").DynamicSentinel<import("eve/tools").DynamicToolResult, import("eve").DynamicContext>;
|
|
46
|
+
/**
|
|
47
|
+
* A tool every session but a guest's offers: a guest has no attachments, files, sandbox or
|
|
48
|
+
* questions to wait on, whatever the agent's configuration says.
|
|
49
|
+
*/
|
|
50
|
+
export declare function notForGuests<Tool extends DynamicToolEntry>(tool: Tool): import("eve").DynamicSentinel<import("eve/tools").DynamicToolResult, import("eve").DynamicContext>;
|
|
@@ -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 { B as ACT_AS_HEADER, V as ActorRequiredError, H as actorHeaders, U as actorKey, W as actorOf, G as
|
|
7
|
+
export { B as ACT_AS_HEADER, V as ActorRequiredError, H as actorHeaders, U as actorKey, W as actorOf, G as isGuestSession, K as member, q as memberTool, J as notForGuests } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
@@ -14,13 +14,22 @@ function localizedText(texts, languageCode) {
|
|
|
14
14
|
const english = entries.find(([locale]) => locale.toLowerCase() === "en");
|
|
15
15
|
return (exact ?? base ?? english ?? entries[0])?.[1];
|
|
16
16
|
}
|
|
17
|
+
function messengerLimits(limits) {
|
|
18
|
+
if (limits === void 0) return;
|
|
19
|
+
const { perSender, newUsersPerHour, workspaceTurnsPerDay } = limits;
|
|
20
|
+
return {
|
|
21
|
+
perSender,
|
|
22
|
+
newUsersPerHour,
|
|
23
|
+
workspaceTurnsPerDay
|
|
24
|
+
};
|
|
25
|
+
}
|
|
17
26
|
async function admitMessage(input) {
|
|
18
27
|
const firstContact = input.settings.firstContact;
|
|
19
28
|
const notice = localizedText(firstContact?.notice, input.languageCode);
|
|
20
29
|
const sha256 = notice === void 0 ? void 0 : createHash("sha256").update(notice).digest("hex");
|
|
21
30
|
const resolved = await input.identities.resolve({
|
|
22
31
|
...input.identity,
|
|
23
|
-
limits: input.settings.limits,
|
|
32
|
+
limits: messengerLimits(input.settings.limits),
|
|
24
33
|
...firstContact === null ? {} : {
|
|
25
34
|
noticeVersion: firstContact.version,
|
|
26
35
|
noticeSha256: sha256
|
|
@@ -33,6 +33,8 @@ export interface CurrentTask {
|
|
|
33
33
|
readonly id: string;
|
|
34
34
|
readonly name: string;
|
|
35
35
|
readonly roles: ReadonlyArray<string>;
|
|
36
|
+
/** The agent's own tools the user's roles grant, such as `sandbox`; none when absent. */
|
|
37
|
+
readonly agentTools?: ReadonlyArray<string>;
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
@@ -4,6 +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 { agentToolsAnswer, agentToolsAttribute } from "./agent-tools.mjs";
|
|
7
8
|
import { redactDiagnostic } from "./diagnostics.mjs";
|
|
8
9
|
import { appOrigin } from "./environment.mjs";
|
|
9
10
|
import { runtimeToken } from "./runtime-token.mjs";
|
|
@@ -30,6 +31,7 @@ function taskPrincipal(task) {
|
|
|
30
31
|
taskId: task.id,
|
|
31
32
|
workflow: task.workflow,
|
|
32
33
|
roles: task.principal.roles,
|
|
34
|
+
...agentToolsAttribute(task.principal.agentTools),
|
|
33
35
|
name: task.principal.name
|
|
34
36
|
}
|
|
35
37
|
};
|
|
@@ -75,7 +77,8 @@ function isRecord(value) {
|
|
|
75
77
|
}
|
|
76
78
|
function currentTask(value) {
|
|
77
79
|
const principal = isRecord(value) ? value.principal : void 0;
|
|
78
|
-
|
|
80
|
+
const agentTools = isRecord(principal) ? agentToolsAnswer(principal.agent_tools) : void 0;
|
|
81
|
+
if (!isRecord(value) || typeof value.id !== "string" || value.id === "" || typeof value.workflow !== "string" || typeof value.prompt !== "string" || typeof value.deadline_at !== "string" || Number.isNaN(Date.parse(value.deadline_at)) || !isRecord(principal) || typeof principal.id !== "string" || principal.id === "" || typeof principal.name !== "string" || !Array.isArray(principal.roles) || !principal.roles.every((role) => typeof role === "string") || agentTools === void 0) throw new AgentTaskError("The ontology answered the current task with an invalid body.");
|
|
79
82
|
return {
|
|
80
83
|
id: value.id,
|
|
81
84
|
workflow: value.workflow,
|
|
@@ -84,7 +87,8 @@ function currentTask(value) {
|
|
|
84
87
|
principal: {
|
|
85
88
|
id: principal.id,
|
|
86
89
|
name: principal.name,
|
|
87
|
-
roles: principal.roles
|
|
90
|
+
roles: principal.roles,
|
|
91
|
+
agentTools
|
|
88
92
|
}
|
|
89
93
|
};
|
|
90
94
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { SessionAuthContext } from "eve/context";
|
|
2
|
+
/**
|
|
3
|
+
* The agent's own tools, beside the ontology's, are ordinary permissions of the ontology's one
|
|
4
|
+
* permission model: `agent_tool:<tool>`. The agent's configuration says which tools the agent has;
|
|
5
|
+
* the ontology's roles say who gets them. Wherever the ontology tells the agent whom it acts for,
|
|
6
|
+
* it names the tools that caller's current roles grant (`agent_tools`), and the channel stamps
|
|
7
|
+
* them on the session principal as {@link AGENT_TOOLS_ATTRIBUTE}, next to `roles`. A principal
|
|
8
|
+
* that carries none holds none.
|
|
9
|
+
*/
|
|
10
|
+
export declare const AGENT_TOOLS_ATTRIBUTE = "agentTools";
|
|
11
|
+
/** The shell and file tools in the sandbox, staging files into it and file-argument calls. */
|
|
12
|
+
export declare const SANDBOX_TOOL = "sandbox";
|
|
13
|
+
/** Fetching pages from the domains `web.domains` lists. */
|
|
14
|
+
export declare const WEB_TOOL = "web";
|
|
15
|
+
export type AgentTool = typeof SANDBOX_TOOL | typeof WEB_TOOL;
|
|
16
|
+
/**
|
|
17
|
+
* The agent tools the session's principal holds, as its channel stamped them from the ontology's
|
|
18
|
+
* answer; none for a principal without them. The developer at `eve dev` holds every one, so that
|
|
19
|
+
* the tools the configuration turns on can be tried locally.
|
|
20
|
+
*/
|
|
21
|
+
export declare function agentToolsOf(principal: SessionAuthContext | null | undefined): ReadonlyArray<string>;
|
|
22
|
+
/** Whether the session's principal holds `agent_tool:<tool>`. */
|
|
23
|
+
export declare function holdsAgentTool(principal: SessionAuthContext | null | undefined, tool: AgentTool): boolean;
|
|
24
|
+
/** A tool ran for a caller whose roles do not grant it, as a tool list offered earlier can. */
|
|
25
|
+
export declare class AgentToolRefusedError extends Error {
|
|
26
|
+
readonly tool: AgentTool;
|
|
27
|
+
readonly name = "AgentToolRefusedError";
|
|
28
|
+
constructor(tool: AgentTool);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Checks, as a tool runs, that the session's current principal still holds the tool: the list of
|
|
32
|
+
* tools the model was offered may be older than the turn, such as in a group chat where another
|
|
33
|
+
* member writes, so every run checks again.
|
|
34
|
+
*/
|
|
35
|
+
export declare function requireAgentTool(principal: SessionAuthContext | null | undefined, tool: AgentTool): void;
|
|
36
|
+
/**
|
|
37
|
+
* The agent tools an ontology answer names in `agent_tools`, or `undefined` when the field is not
|
|
38
|
+
* a list of strings.
|
|
39
|
+
*/
|
|
40
|
+
export declare function agentToolsAnswer(value: unknown): ReadonlyArray<string> | undefined;
|
|
41
|
+
/** The principal attribute for the tools a channel stamps: absent when the member names none. */
|
|
42
|
+
export declare function agentToolsAttribute(tools: ReadonlyArray<string> | undefined): Readonly<Record<string, readonly string[]>>;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { getLocalDevCapability } from "eve/local-dev";
|
|
8
|
+
const AGENT_TOOLS_ATTRIBUTE = "agentTools";
|
|
9
|
+
const SANDBOX_TOOL = "sandbox";
|
|
10
|
+
const WEB_TOOL = "web";
|
|
11
|
+
const AGENT_TOOLS = [SANDBOX_TOOL, "web"];
|
|
12
|
+
const LOCAL_DEV = "local-dev";
|
|
13
|
+
function isLocalDeveloper(principal) {
|
|
14
|
+
return principal.authenticator === LOCAL_DEV && principal.principalType === LOCAL_DEV && getLocalDevCapability() !== void 0;
|
|
15
|
+
}
|
|
16
|
+
function agentToolsOf(principal) {
|
|
17
|
+
if (principal === null || principal === void 0) return [];
|
|
18
|
+
if (isLocalDeveloper(principal)) return AGENT_TOOLS;
|
|
19
|
+
const tools = principal.attributes[AGENT_TOOLS_ATTRIBUTE];
|
|
20
|
+
return typeof tools === "string" ? [tools] : tools ?? [];
|
|
21
|
+
}
|
|
22
|
+
function holdsAgentTool(principal, tool) {
|
|
23
|
+
return agentToolsOf(principal).includes(tool);
|
|
24
|
+
}
|
|
25
|
+
var AgentToolRefusedError = class extends Error {
|
|
26
|
+
tool;
|
|
27
|
+
name = "AgentToolRefusedError";
|
|
28
|
+
constructor(tool) {
|
|
29
|
+
super(`The caller's roles do not grant agent_tool:${tool}, so this tool cannot run for them.`);
|
|
30
|
+
this.tool = tool;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function requireAgentTool(principal, tool) {
|
|
34
|
+
if (!holdsAgentTool(principal, tool)) throw new AgentToolRefusedError(tool);
|
|
35
|
+
}
|
|
36
|
+
function agentToolsAnswer(value) {
|
|
37
|
+
if (value === void 0) return [SANDBOX_TOOL];
|
|
38
|
+
return Array.isArray(value) && value.every((tool) => typeof tool === "string") ? value : void 0;
|
|
39
|
+
}
|
|
40
|
+
function agentToolsAttribute(tools) {
|
|
41
|
+
return tools === void 0 ? {} : { [AGENT_TOOLS_ATTRIBUTE]: tools };
|
|
42
|
+
}
|
|
43
|
+
export { AGENT_TOOLS_ATTRIBUTE, AgentToolRefusedError, SANDBOX_TOOL, WEB_TOOL, agentToolsAnswer, agentToolsAttribute, agentToolsOf, holdsAgentTool, requireAgentTool };
|
|
@@ -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 { S as agentAttachments, i as memberIdOf,
|
|
7
|
+
import { S as agentAttachments, i as memberIdOf, mt as chatAddressOf } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
8
8
|
import { detectFile, documentText } from "./attachment-formats.mjs";
|
|
9
9
|
import { readSheets, typedTable } from "./attachment-tables.mjs";
|
|
10
10
|
import { appOrigin } from "./environment.mjs";
|
|
@@ -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 { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, v as CHAT_HEADER, y as EARLIER_CHAT_HEADER, b as MAXIMUM_ATTACHMENT_BYTES, x as SESSION_HEADER, S as agentAttachments, C as attachmentUrl, w as fetchStoredAttachment, T as parseAttachmentUrl } from "../../_chunks/principal-
|
|
7
|
+
export { h as ATTACHMENT_TTL_HOURS, g as ATTACHMENT_URL_PROTOCOL, _ as AttachmentError, v as CHAT_HEADER, y as EARLIER_CHAT_HEADER, b as MAXIMUM_ATTACHMENT_BYTES, x as SESSION_HEADER, S as agentAttachments, C as attachmentUrl, w as fetchStoredAttachment, T as parseAttachmentUrl } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
@@ -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-DJ3WHCte.mjs";
|
|
@@ -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 {
|
|
7
|
+
export { pt as CHAT_ATTRIBUTE, mt as chatAddressOf, ht as isSameChat, gt as withChatAddress } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
|
|
|
7
7
|
import { agentTaskIdOf } from "./agent-task.mjs";
|
|
8
8
|
import { chatCoordinates } from "./chat-recorder.mjs";
|
|
9
9
|
import { chatArchive, collapseChatEvents, topicContext } from "./chat-archive.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { Tt as reportTelegramError } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
12
|
import { deliveries, runs, turns } from "eve/events";
|
|
13
13
|
import { defineState } from "eve/context";
|
|
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
|
|
|
7
7
|
import { n as contentText, t as CONTENT_CAPS } from "../../_chunks/content-cDtVnr8Y.mjs";
|
|
8
8
|
import { chatArchive, chatEvent, sessionFailureEventId, summarizeArguments } from "./chat-archive.mjs";
|
|
9
9
|
import { agentTaskIdOf } from "./agent-task.mjs";
|
|
10
|
-
import { i as memberIdOf,
|
|
10
|
+
import { i as memberIdOf, mt as chatAddressOf, ot as guestIdOf } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
11
11
|
import { parseAddress } from "./telegram/sessions.mjs";
|
|
12
12
|
import { completionKind } from "./telegram/silent.mjs";
|
|
13
13
|
import { recordModelServiceAlert } from "./model-service-alert.mjs";
|
|
@@ -33,6 +33,15 @@ function chatCoordinates(context) {
|
|
|
33
33
|
participantIds: [webMemberId],
|
|
34
34
|
senderId: webMemberId
|
|
35
35
|
};
|
|
36
|
+
const guestId = guestIdOf(principal);
|
|
37
|
+
if (chat?.provider === "web" && guestId !== void 0) return {
|
|
38
|
+
provider: "web",
|
|
39
|
+
chatId: chat.chatId,
|
|
40
|
+
chatType: "private",
|
|
41
|
+
threadId: null,
|
|
42
|
+
participantIds: [],
|
|
43
|
+
senderId: `guest:${guestId}`
|
|
44
|
+
};
|
|
36
45
|
if (chat?.provider === "email" && webMemberId !== void 0) return {
|
|
37
46
|
provider: "email",
|
|
38
47
|
chatId: chat.chatId,
|
|
@@ -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 { F as CONFIRMATION_TTL_MS, I as actionApproval, L as confirmations, R as inputHash, z as needsConfirmation } from "../../_chunks/principal-
|
|
7
|
+
export { F as CONFIRMATION_TTL_MS, I as actionApproval, L as confirmations, R as inputHash, z as needsConfirmation } from "../../_chunks/principal-JoaOmdFL.mjs";
|
|
@@ -6,8 +6,9 @@ __eveDirname(__filename);
|
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { PUBSUB_TOPIC } from "../../config.mjs";
|
|
8
8
|
import { admitMessage, localizedText } from "../admission.mjs";
|
|
9
|
+
import { agentToolsAttribute } from "../agent-tools.mjs";
|
|
9
10
|
import { providerChat } from "../attachment-tools.mjs";
|
|
10
|
-
import { S as agentAttachments, d as prepareInboundMedia,
|
|
11
|
+
import { S as agentAttachments, d as prepareInboundMedia, gt as withChatAddress, i as memberIdOf, m as turnContent, mt as chatAddressOf, w as fetchStoredAttachment } from "../../../_chunks/principal-JoaOmdFL.mjs";
|
|
11
12
|
import { chatEvent } from "../chat-archive.mjs";
|
|
12
13
|
import { ConnectionProxyError, connectionProxy } from "../connection-proxy.mjs";
|
|
13
14
|
import { redactDiagnostic } from "../diagnostics.mjs";
|
|
@@ -103,6 +104,7 @@ function emailPrincipal(member, sender, threadId) {
|
|
|
103
104
|
memberId: member.id,
|
|
104
105
|
identityProvider: "email",
|
|
105
106
|
roles: member.roles,
|
|
107
|
+
...agentToolsAttribute(member.agentTools),
|
|
106
108
|
...member.name === null ? {} : { memberName: member.name },
|
|
107
109
|
...member.locale === void 0 ? {} : { locale: member.locale }
|
|
108
110
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A web page's HTML as text the model reads: its words in reading order, blocks on lines of their
|
|
3
|
+
* own, and in Markdown its headings, list items and links. Scripts, styles and other parts no
|
|
4
|
+
* reader sees are left out. eve converts pages the same way inside its own `web_fetch`, but does
|
|
5
|
+
* not export the conversion, so the SDK's domain-bound fetch has its own. One pass, never
|
|
6
|
+
* backtracking, so a page's size alone bounds the work.
|
|
7
|
+
*/
|
|
8
|
+
/** `&`, `'` and `'` as their characters; an unknown name stays as written. */
|
|
9
|
+
export declare function decodeEntities(text: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* The text of `html`. In `markdown`, headings start with `#`, list items with `-`, links read
|
|
12
|
+
* `[text](url)` with `url` resolved against `base`, and preformatted text is fenced.
|
|
13
|
+
*/
|
|
14
|
+
export declare function htmlToText(html: string, format: "markdown" | "text", base?: string): string;
|