@segmentstream/ontology 0.156.1 → 0.158.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/README.md +8 -7
- package/dist/agent-chat.d.ts +1 -1
- package/dist/agent-chat.js +8 -8
- package/dist/agent-draft.d.ts +287 -0
- package/dist/{agent-review.js → agent-draft.js} +103 -82
- package/dist/analyze.d.ts +1 -1
- package/dist/analyze.js +71 -14
- package/dist/channel-files.d.ts +70 -0
- package/dist/channel-files.js +58 -0
- package/dist/chat.d.ts +2 -2
- package/dist/earlier-entity-names.d.ts +35 -0
- package/dist/earlier-entity-names.js +88 -0
- package/dist/email.d.ts +2 -0
- package/dist/email.js +1 -0
- package/dist/gmail-send.d.ts +39 -0
- package/dist/gmail-send.js +179 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/migrate/plan.js +31 -2
- package/dist/permissions.d.ts +5 -5
- package/dist/permissions.js +13 -10
- package/dist/replicated-entities.d.ts +1 -1
- package/dist/replicated-entities.js +4 -1
- package/dist/replication/bigquery.d.ts +24 -2
- package/dist/replication/bigquery.js +72 -12
- package/dist/runtime/agents.d.ts +1 -1
- package/dist/runtime/agents.js +43 -38
- package/dist/runtime/service-binding.js +1 -1
- package/dist/service/agent/protocol.d.ts +4 -4
- package/dist/service/agent/protocol.js +7 -7
- package/dist/service/agent/server.js +14 -9
- package/dist/service/chat/envelope.d.ts +12 -12
- package/dist/service/chat/review-delivery.js +23 -22
- package/dist/service/chat/review-revision.d.ts +1 -1
- package/dist/service/chat/review-revision.js +13 -13
- package/dist/service/mcp/runtime-policy.js +1 -1
- package/dist/service/mcp/server.js +9 -1
- package/dist/service/mcp/tools.js +1 -1
- package/dist/service/operations.js +11 -5
- package/dist/service/runtime-contract.d.ts +3 -3
- package/dist/service/service.d.ts +6 -0
- package/dist/service/service.js +21 -3
- package/dist/slack-files.d.ts +53 -0
- package/dist/slack-files.js +183 -0
- package/dist/slack.d.ts +3 -0
- package/dist/slack.js +2 -0
- package/dist/telegram-files.d.ts +81 -0
- package/dist/telegram-files.js +244 -0
- package/dist/telegram.d.ts +3 -1
- package/dist/telegram.js +2 -0
- package/dist/whatsapp-files.d.ts +54 -0
- package/dist/whatsapp-files.js +138 -0
- package/dist/whatsapp.d.ts +3 -0
- package/dist/whatsapp.js +2 -0
- package/dist/workspace-channel.d.ts +20 -0
- package/dist/workspace-channel.js +10 -0
- package/package.json +1 -1
- package/dist/agent-review.d.ts +0 -154
|
@@ -25,6 +25,9 @@ const PAIRINGS_PATH = `${AGENT_PATH}/pairings`;
|
|
|
25
25
|
const IDENTITIES_PATH = `${AGENT_PATH}/identities`;
|
|
26
26
|
const CHATS_SEEN_PATH = `${AGENT_PATH}/chats/seen`;
|
|
27
27
|
const CHATS_HANDOFF_PATH = `${AGENT_PATH}/chats/handoff`;
|
|
28
|
+
const DRAFTS_PATH = `${AGENT_PATH}/drafts`;
|
|
29
|
+
// @legacy agent.review-runtime-paths
|
|
30
|
+
// The drafts' routes under their earlier name, which agent SDKs released before them call.
|
|
28
31
|
const REVIEWS_PATH = `${AGENT_PATH}/reviews`;
|
|
29
32
|
/** Where a signed-in member gets an agent token, and where the agent asks whom one stands for. */
|
|
30
33
|
export const AGENT_TOKENS_PATH = `${AGENT_PATH}/tokens`;
|
|
@@ -346,9 +349,9 @@ function seeChat(store) {
|
|
|
346
349
|
});
|
|
347
350
|
}
|
|
348
351
|
/**
|
|
349
|
-
* `POST /api/ontology/agent/
|
|
350
|
-
* pending `
|
|
351
|
-
* active member, so the reply is neither sent nor
|
|
352
|
+
* `POST /api/ontology/agent/drafts` (runtime): the agent kept a reply for review. It becomes a
|
|
353
|
+
* pending `agent_draft` for the member it answers, once per key; 404 when that member is not an
|
|
354
|
+
* active member, so the reply is neither sent nor kept.
|
|
352
355
|
*/
|
|
353
356
|
function holdReply(store) {
|
|
354
357
|
return (request) => Effect.gen(function* () {
|
|
@@ -418,8 +421,8 @@ function holdReply(store) {
|
|
|
418
421
|
});
|
|
419
422
|
}
|
|
420
423
|
/**
|
|
421
|
-
* `POST /api/ontology/agent/
|
|
422
|
-
* back, or could not. The new draft becomes a pending
|
|
424
|
+
* `POST /api/ontology/agent/drafts/revision` (runtime): the agent redrafted a reply a member sent
|
|
425
|
+
* back, or could not. The new draft becomes a pending draft for the same person and chat that
|
|
423
426
|
* replaces the earlier one, which becomes `superseded`, once per redraft; a redraft the member no
|
|
424
427
|
* longer waits for, because the reply was decided or redrafted again since, replaces nothing.
|
|
425
428
|
*/
|
|
@@ -465,7 +468,7 @@ function revision(store) {
|
|
|
465
468
|
});
|
|
466
469
|
}
|
|
467
470
|
/**
|
|
468
|
-
* `POST /api/ontology/agent/
|
|
471
|
+
* `POST /api/ontology/agent/drafts/session` (runtime): the drafts the session kept for review,
|
|
469
472
|
* newest first, with what became of each. Nothing a member wrote about them is in it.
|
|
470
473
|
*/
|
|
471
474
|
function sessionReviews(store) {
|
|
@@ -618,9 +621,11 @@ export function agentLayer(options) {
|
|
|
618
621
|
yield* router.add("GET", `${AGENT_PATH}${CHAT_MESSAGE_PATHS.purge}`, purge);
|
|
619
622
|
yield* router.add("POST", `${AGENT_PATH}${CHAT_MESSAGE_PATHS.purge}`, purge);
|
|
620
623
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
+
for (const path of [DRAFTS_PATH, REVIEWS_PATH]) {
|
|
625
|
+
yield* router.add("POST", path, asRuntime(holdReply(store)));
|
|
626
|
+
yield* router.add("POST", `${path}/session`, asRuntime(sessionReviews(store)));
|
|
627
|
+
yield* router.add("POST", `${path}/revision`, asRuntime(revision(store)));
|
|
628
|
+
}
|
|
624
629
|
yield* router.add("DELETE", `${IDENTITIES_PATH}/:id`, asMember((_, member) => revokeIdentity(store, member)));
|
|
625
630
|
if (store.web !== undefined && backend.oauth !== undefined) {
|
|
626
631
|
yield* router.add("POST", AGENT_TOKENS_PATH, asMember(issueAgentToken(store, store.web, fixedWindowLimiter(AGENT_TOKEN_LIMIT))));
|
|
@@ -54,6 +54,12 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
|
|
|
54
54
|
readonly thread_id: string;
|
|
55
55
|
readonly message_id?: string | undefined;
|
|
56
56
|
readonly channel?: string | undefined;
|
|
57
|
+
readonly location?: {
|
|
58
|
+
readonly latitude: number;
|
|
59
|
+
readonly longitude: number;
|
|
60
|
+
readonly horizontal_accuracy?: number | undefined;
|
|
61
|
+
readonly live_period?: number | undefined;
|
|
62
|
+
} | undefined;
|
|
57
63
|
readonly attachments?: readonly {
|
|
58
64
|
readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
|
|
59
65
|
readonly file_id: string;
|
|
@@ -64,12 +70,6 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
|
|
|
64
70
|
readonly reply_to_message_id?: string | undefined;
|
|
65
71
|
readonly callback_query_id?: string | undefined;
|
|
66
72
|
readonly sender?: string | undefined;
|
|
67
|
-
readonly location?: {
|
|
68
|
-
readonly latitude: number;
|
|
69
|
-
readonly longitude: number;
|
|
70
|
-
readonly horizontal_accuracy?: number | undefined;
|
|
71
|
-
readonly live_period?: number | undefined;
|
|
72
|
-
} | undefined;
|
|
73
73
|
} | {
|
|
74
74
|
readonly kind: "private" | "group";
|
|
75
75
|
readonly provider: "slack" | "whatsapp";
|
|
@@ -108,6 +108,12 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
|
|
|
108
108
|
readonly thread_id: string;
|
|
109
109
|
readonly message_id?: string | undefined;
|
|
110
110
|
readonly channel?: string | undefined;
|
|
111
|
+
readonly location?: {
|
|
112
|
+
readonly latitude: number;
|
|
113
|
+
readonly longitude: number;
|
|
114
|
+
readonly horizontal_accuracy?: number | undefined;
|
|
115
|
+
readonly live_period?: number | undefined;
|
|
116
|
+
} | undefined;
|
|
111
117
|
readonly attachments?: readonly {
|
|
112
118
|
readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
|
|
113
119
|
readonly file_id: string;
|
|
@@ -118,12 +124,6 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
|
|
|
118
124
|
readonly reply_to_message_id?: string | undefined;
|
|
119
125
|
readonly callback_query_id?: string | undefined;
|
|
120
126
|
readonly sender?: string | undefined;
|
|
121
|
-
readonly location?: {
|
|
122
|
-
readonly latitude: number;
|
|
123
|
-
readonly longitude: number;
|
|
124
|
-
readonly horizontal_accuracy?: number | undefined;
|
|
125
|
-
readonly live_period?: number | undefined;
|
|
126
|
-
} | undefined;
|
|
127
127
|
} | {
|
|
128
128
|
readonly kind: "private" | "group";
|
|
129
129
|
readonly provider: "slack" | "whatsapp";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { addressesOfDraft, AGENT_DRAFT_TEXT_LIMIT, participantsOfDraft, } from "../../agent-draft.js";
|
|
3
3
|
import { EMAIL_RECIPIENTS_LIMIT, emailRecipients } from "../../email.js";
|
|
4
4
|
import { ActionRejected, PermissionDenied } from "../../errors.js";
|
|
5
5
|
import { effectiveScope } from "../../permissions.js";
|
|
@@ -14,10 +14,10 @@ import { deliveryArchiveOf } from "./store-delivery.js";
|
|
|
14
14
|
* recipient, and its `cc`, whatever their order and case.
|
|
15
15
|
*/
|
|
16
16
|
function sameRecipients(recipients, review) {
|
|
17
|
-
const held =
|
|
17
|
+
const held = addressesOfDraft(review.to);
|
|
18
18
|
const set = (list) => [...new Set(list.map((address) => address.toLowerCase()))].sort().join(",");
|
|
19
19
|
return (set(recipients.to) ===
|
|
20
|
-
set(held.length > 0 ? held : typeof review.recipient === "string" ? [review.recipient] : []) && set(recipients.cc) === set(
|
|
20
|
+
set(held.length > 0 ? held : typeof review.recipient === "string" ? [review.recipient] : []) && set(recipients.cc) === set(addressesOfDraft(review.cc)));
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Sends a reply the agent held for review, once a member approved it: the draft or the member's
|
|
@@ -31,7 +31,7 @@ function sameRecipients(recipients, review) {
|
|
|
31
31
|
*/
|
|
32
32
|
export function reviewSender(input) {
|
|
33
33
|
const { backend, principal } = input;
|
|
34
|
-
const report = (phase, cause) => Effect.logWarning("ontology.
|
|
34
|
+
const report = (phase, cause) => Effect.logWarning("ontology.agent_draft.delivery_diagnostic").pipe(Effect.annotateLogs({
|
|
35
35
|
phase,
|
|
36
36
|
requestId: input.requestId,
|
|
37
37
|
error: describeChatError(cause, (text) => input.identityToken ? text.split(input.identityToken).join("[redacted]") : text),
|
|
@@ -40,30 +40,30 @@ export function reviewSender(input) {
|
|
|
40
40
|
// A role may hold the approval within a scope. The send happens before the action's
|
|
41
41
|
// transaction, whose write guard comes too late for it: a review outside the scope is
|
|
42
42
|
// refused here, read through the approval's own scope.
|
|
43
|
-
const approvable = effectiveScope("
|
|
43
|
+
const approvable = effectiveScope("agent_draft:approve", principal);
|
|
44
44
|
if (approvable !== undefined) {
|
|
45
45
|
yield* backend
|
|
46
46
|
.get({
|
|
47
|
-
entity: "
|
|
47
|
+
entity: "agent_draft",
|
|
48
48
|
id: send.review,
|
|
49
49
|
reader: {
|
|
50
50
|
...principal,
|
|
51
|
-
permissions: ["
|
|
52
|
-
scopes: [{ permission: "
|
|
51
|
+
permissions: ["agent_draft:read"],
|
|
52
|
+
scopes: [{ permission: "agent_draft:read", where: approvable }],
|
|
53
53
|
},
|
|
54
54
|
})
|
|
55
55
|
.pipe(Effect.mapError(() => new PermissionDenied({
|
|
56
|
-
message: "The
|
|
57
|
-
permission: "
|
|
56
|
+
message: "The draft is outside the records agent_draft:approve covers.",
|
|
57
|
+
permission: "agent_draft:approve",
|
|
58
58
|
})));
|
|
59
59
|
}
|
|
60
60
|
const review = yield* backend
|
|
61
|
-
.get({ entity: "
|
|
62
|
-
.pipe(Effect.mapError(() => new ActionRejected({ message: "The
|
|
61
|
+
.get({ entity: "agent_draft", id: send.review })
|
|
62
|
+
.pipe(Effect.mapError(() => new ActionRejected({ message: "The draft does not exist." })));
|
|
63
63
|
const draft = String(review.draft ?? "");
|
|
64
64
|
const text = send.text ?? draft;
|
|
65
65
|
const status = String(review.status);
|
|
66
|
-
const email = String(review.
|
|
66
|
+
const email = String(review.channel_kind) === "email";
|
|
67
67
|
// Only a reply to mail names whom it goes to beside its chat.
|
|
68
68
|
if (!email && (send.to !== undefined || send.cc !== undefined)) {
|
|
69
69
|
return yield* new ActionRejected({
|
|
@@ -72,7 +72,7 @@ export function reviewSender(input) {
|
|
|
72
72
|
}
|
|
73
73
|
// A reply to mail goes to the review's `to` and `cc`, the thread's people, unless the member
|
|
74
74
|
// names others; one held before replies named them goes to its recipient alone.
|
|
75
|
-
const held =
|
|
75
|
+
const held = addressesOfDraft(review.to);
|
|
76
76
|
const recipients = email
|
|
77
77
|
? yield* Effect.try({
|
|
78
78
|
try: () => emailRecipients({
|
|
@@ -82,7 +82,7 @@ export function reviewSender(input) {
|
|
|
82
82
|
: typeof review.recipient === "string"
|
|
83
83
|
? [review.recipient]
|
|
84
84
|
: []),
|
|
85
|
-
cc: send.cc ??
|
|
85
|
+
cc: send.cc ?? addressesOfDraft(review.cc),
|
|
86
86
|
}),
|
|
87
87
|
catch: (cause) => new ActionRejected({
|
|
88
88
|
message: `A reply to mail goes to 1 to ${EMAIL_RECIPIENTS_LIMIT} plain addresses ` +
|
|
@@ -114,17 +114,17 @@ export function reviewSender(input) {
|
|
|
114
114
|
// @legacy ontology.reviews-without-channel
|
|
115
115
|
const providerName = typeof review.channel === "string" && review.channel !== ""
|
|
116
116
|
? review.channel
|
|
117
|
-
: String(review.
|
|
117
|
+
: String(review.channel_kind);
|
|
118
118
|
const provider = channelProvider(input.ontology.manifest.chat, providerName);
|
|
119
119
|
const connection = chatConnection(input.ontology.manifest.chat, providerName) ?? "";
|
|
120
120
|
const channelKind = chatKind(input.ontology.manifest.chat, providerName);
|
|
121
121
|
// A workspace channel needs no connection of the ontology's: the agent sends through it.
|
|
122
122
|
if (provider === undefined ||
|
|
123
123
|
(!connection && channelKind !== WORKSPACE_CHANNEL_KIND) ||
|
|
124
|
-
channelKind !== String(review.
|
|
124
|
+
channelKind !== String(review.channel_kind)) {
|
|
125
125
|
return yield* new ActionRejected({
|
|
126
126
|
message: `Sending a reviewed reply needs chat.${providerName}.connection in defineOntology, ` +
|
|
127
|
-
`of kind ${String(review.
|
|
127
|
+
`of kind ${String(review.channel_kind)}: the connection of the bot, number or mailbox ` +
|
|
128
128
|
"the person talks to.",
|
|
129
129
|
});
|
|
130
130
|
}
|
|
@@ -147,7 +147,7 @@ export function reviewSender(input) {
|
|
|
147
147
|
catch: (cause) => new ActionRejected({ message: "The Markdown could not be rendered.", cause }),
|
|
148
148
|
});
|
|
149
149
|
if (text.trim() === "" ||
|
|
150
|
-
text.length >
|
|
150
|
+
text.length > AGENT_DRAFT_TEXT_LIMIT ||
|
|
151
151
|
finalText.length > provider.limit ||
|
|
152
152
|
plainText.length > provider.limit ||
|
|
153
153
|
!provider.isTargetId(externalId, kind) ||
|
|
@@ -158,7 +158,7 @@ export function reviewSender(input) {
|
|
|
158
158
|
"sent or truncated.",
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
-
// A guest is no user; `
|
|
161
|
+
// A guest is no user; `agent_draft` is not theirs to approve.
|
|
162
162
|
if (principal.kind === "guest") {
|
|
163
163
|
return yield* new PermissionDenied({ message: "The approver is unknown." });
|
|
164
164
|
}
|
|
@@ -191,7 +191,7 @@ export function reviewSender(input) {
|
|
|
191
191
|
participantIds: [
|
|
192
192
|
...new Set([
|
|
193
193
|
...(person === null ? [] : [person]),
|
|
194
|
-
...
|
|
194
|
+
...participantsOfDraft(review.participants),
|
|
195
195
|
]),
|
|
196
196
|
],
|
|
197
197
|
};
|
|
@@ -208,6 +208,7 @@ export function reviewSender(input) {
|
|
|
208
208
|
const operationId = String(review.id);
|
|
209
209
|
const scope = deliveryScopeDigest({
|
|
210
210
|
via: "service",
|
|
211
|
+
// The delivery keys keep the entity's first name: a renamed key would send an approval again.
|
|
211
212
|
subjectId: `agent_review:${operationId}`,
|
|
212
213
|
clientId: null,
|
|
213
214
|
});
|
|
@@ -319,7 +320,7 @@ export function reviewSender(input) {
|
|
|
319
320
|
transport: input.connections({
|
|
320
321
|
identityToken: input.identityToken,
|
|
321
322
|
audit: {
|
|
322
|
-
action: "
|
|
323
|
+
action: "agent_draft.approve",
|
|
323
324
|
principalId: principal.id,
|
|
324
325
|
requestId: input.requestId,
|
|
325
326
|
},
|
|
@@ -9,7 +9,7 @@ export declare const AGENT_REVISION_ROUTE = "/eve/segmentstream/v1/reviews/revis
|
|
|
9
9
|
/**
|
|
10
10
|
* Hands a reply the agent held for review back to it with a member's note: the agent redrafts it in
|
|
11
11
|
* a session of its own, acting as the person the reply is for and reading only, and reports the new
|
|
12
|
-
* draft to `POST /api/ontology/agent/
|
|
12
|
+
* draft to `POST /api/ontology/agent/drafts/revision`, where it replaces the draft while the draft
|
|
13
13
|
* still waits and this is the last redraft asked for. The request is recorded before the agent is
|
|
14
14
|
* called, so however soon the agent reports, its report finds it, and it names everything the agent
|
|
15
15
|
* needs: the agent never looks the review up.
|
|
@@ -13,14 +13,14 @@ const text = (value) => typeof value === "string" && value !== "" ? value : null
|
|
|
13
13
|
/**
|
|
14
14
|
* Hands a reply the agent held for review back to it with a member's note: the agent redrafts it in
|
|
15
15
|
* a session of its own, acting as the person the reply is for and reading only, and reports the new
|
|
16
|
-
* draft to `POST /api/ontology/agent/
|
|
16
|
+
* draft to `POST /api/ontology/agent/drafts/revision`, where it replaces the draft while the draft
|
|
17
17
|
* still waits and this is the last redraft asked for. The request is recorded before the agent is
|
|
18
18
|
* called, so however soon the agent reports, its report finds it, and it names everything the agent
|
|
19
19
|
* needs: the agent never looks the review up.
|
|
20
20
|
*/
|
|
21
21
|
export function reviewReviser(input) {
|
|
22
22
|
const { backend, principal, agent } = input;
|
|
23
|
-
const report = (phase, cause) => Effect.logWarning("ontology.
|
|
23
|
+
const report = (phase, cause) => Effect.logWarning("ontology.agent_draft.revision_diagnostic").pipe(Effect.annotateLogs({
|
|
24
24
|
phase,
|
|
25
25
|
requestId: input.requestId,
|
|
26
26
|
error: describeChatError(cause, (value) => agent.identityToken ? value.split(agent.identityToken).join("[redacted]") : value),
|
|
@@ -28,29 +28,29 @@ export function reviewReviser(input) {
|
|
|
28
28
|
return (revise) => Effect.gen(function* () {
|
|
29
29
|
// The call happens before the action's transaction, whose write guard comes too late for it:
|
|
30
30
|
// a review outside the scope is refused here, read through the request's own scope.
|
|
31
|
-
const revisable = effectiveScope("
|
|
31
|
+
const revisable = effectiveScope("agent_draft:revise", principal);
|
|
32
32
|
if (revisable !== undefined) {
|
|
33
33
|
yield* backend
|
|
34
34
|
.get({
|
|
35
|
-
entity: "
|
|
35
|
+
entity: "agent_draft",
|
|
36
36
|
id: revise.review,
|
|
37
37
|
reader: {
|
|
38
38
|
...principal,
|
|
39
|
-
permissions: ["
|
|
40
|
-
scopes: [{ permission: "
|
|
39
|
+
permissions: ["agent_draft:read"],
|
|
40
|
+
scopes: [{ permission: "agent_draft:read", where: revisable }],
|
|
41
41
|
},
|
|
42
42
|
})
|
|
43
43
|
.pipe(Effect.mapError(() => new PermissionDenied({
|
|
44
|
-
message: "The
|
|
45
|
-
permission: "
|
|
44
|
+
message: "The draft is outside the records agent_draft:revise covers.",
|
|
45
|
+
permission: "agent_draft:revise",
|
|
46
46
|
})));
|
|
47
47
|
}
|
|
48
48
|
if (principal.kind === "guest") {
|
|
49
49
|
return yield* new PermissionDenied({ message: "The member is unknown." });
|
|
50
50
|
}
|
|
51
51
|
const review = yield* backend
|
|
52
|
-
.get({ entity: "
|
|
53
|
-
.pipe(Effect.mapError(() => new ActionRejected({ message: "The
|
|
52
|
+
.get({ entity: "agent_draft", id: revise.review })
|
|
53
|
+
.pipe(Effect.mapError(() => new ActionRejected({ message: "The draft does not exist." })));
|
|
54
54
|
if (review.status !== "pending") {
|
|
55
55
|
return yield* new ActionRejected({
|
|
56
56
|
message: "Only a reply that still waits for a member can be redrafted.",
|
|
@@ -83,7 +83,7 @@ export function reviewReviser(input) {
|
|
|
83
83
|
break;
|
|
84
84
|
}
|
|
85
85
|
const found = yield* backend
|
|
86
|
-
.get({ entity: "
|
|
86
|
+
.get({ entity: "agent_draft", id: earlier })
|
|
87
87
|
.pipe(Effect.option);
|
|
88
88
|
if (Option.isNone(found)) {
|
|
89
89
|
break;
|
|
@@ -115,8 +115,8 @@ export function reviewReviser(input) {
|
|
|
115
115
|
roles: person.principal.roles,
|
|
116
116
|
session_id: String(review.session_id),
|
|
117
117
|
key: String(first.key),
|
|
118
|
-
provider: String(review.
|
|
119
|
-
channel: text(review.channel) ?? String(review.
|
|
118
|
+
provider: String(review.channel_kind),
|
|
119
|
+
channel: text(review.channel) ?? String(review.channel_kind),
|
|
120
120
|
chat_id: String(review.chat_id),
|
|
121
121
|
thread_id: text(review.thread_id),
|
|
122
122
|
chat_kind: review.chat_kind === "group" ? "group" : "private",
|
|
@@ -39,7 +39,7 @@ export function requireRuntimeOperation(operation) {
|
|
|
39
39
|
if (deployment) {
|
|
40
40
|
yield* Effect.sync(() => requireDeploymentCapability(deployment, invokesAgent(operation) ||
|
|
41
41
|
operation.entity === "agent_chat" ||
|
|
42
|
-
operation.entity === "
|
|
42
|
+
operation.entity === "agent_draft"
|
|
43
43
|
? "agents"
|
|
44
44
|
: undefined));
|
|
45
45
|
}
|
|
@@ -2,6 +2,7 @@ import { Cause, Data, Effect, Layer, Option, Redacted, Schema, SchemaTransformat
|
|
|
2
2
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
3
3
|
import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
4
4
|
import { ActionRejected } from "../../errors.js";
|
|
5
|
+
import { currentToolName } from "../../earlier-entity-names.js";
|
|
5
6
|
import { DeploymentAdmissionError } from "../../deployment.js";
|
|
6
7
|
import { effectivePermissions } from "../../permissions.js";
|
|
7
8
|
import { declaredChatRetentionDaysOf, encodeManifest } from "../../manifest.js";
|
|
@@ -527,7 +528,14 @@ function callTool(server, params, request, preview) {
|
|
|
527
528
|
const requestId = yield* RequestId;
|
|
528
529
|
const caller = yield* currentCaller;
|
|
529
530
|
const principal = yield* CurrentPrincipal;
|
|
530
|
-
|
|
531
|
+
// @legacy ontology.agent-review-entity-name
|
|
532
|
+
// A tool named by a built-in entity's earlier name is called under its current name.
|
|
533
|
+
// A tool the server has by the name given is that tool, whatever its name starts with.
|
|
534
|
+
const call = typeof params.name === "string" &&
|
|
535
|
+
!server.tools.some((candidate) => candidate.name === params.name) &&
|
|
536
|
+
currentToolName(params.name) !== params.name
|
|
537
|
+
? { ...params, name: currentToolName(params.name) }
|
|
538
|
+
: params;
|
|
531
539
|
const tool = server.tools.find((candidate) => candidate.name === call.name);
|
|
532
540
|
const allowed = yield* requireRuntimeOperation({
|
|
533
541
|
...(typeof call.name === "string" ? { name: call.name } : {}),
|
|
@@ -836,7 +836,7 @@ export function mcpTools(built, chatHistory = false, storage = {}, navigation =
|
|
|
836
836
|
"agent_chat:read) and DMs in which you participated. Dates are ISO 8601; before is the " +
|
|
837
837
|
"nextCursor of the previous page. " +
|
|
838
838
|
"Workspace administrators can read all DMs through the platform API."
|
|
839
|
-
: "Search retained chat messages. Requires an available
|
|
839
|
+
: "Search retained chat messages. Requires an available chat store and chat read access.",
|
|
840
840
|
inputSchema: encodedJsonSchema(ChatSearch),
|
|
841
841
|
annotations: READ,
|
|
842
842
|
permissions: [],
|
|
@@ -20,6 +20,9 @@ import { InvalidActionInput, RequestId } from "./errors.js";
|
|
|
20
20
|
import { recordReads } from "./record-reads.js";
|
|
21
21
|
import { runToolsetToolOf } from "./toolsets.js";
|
|
22
22
|
import { AGENT_TASK_AUTHENTICATION } from "./agent/task-caller.js";
|
|
23
|
+
import { AgentDraft } from "../agent-draft.js";
|
|
24
|
+
import { currentActionInput } from "../earlier-entity-names.js";
|
|
25
|
+
const AGENT_DRAFT = AgentDraft.name;
|
|
23
26
|
/**
|
|
24
27
|
* What the service does for a caller, whatever the transport: the reads and actions of every entity
|
|
25
28
|
* and the caller's own account. The HTTP routes and the MCP tools both call these, so a permission
|
|
@@ -241,20 +244,23 @@ function runActionOf(backend, plan, hooks, connections, replicate, chatDelivery)
|
|
|
241
244
|
}
|
|
242
245
|
input = { ...values, idempotency_key: envelope.operation_id };
|
|
243
246
|
}
|
|
244
|
-
// Approving a
|
|
247
|
+
// Approving a draft sends it to a person: a member, or the agent acting for one with
|
|
245
248
|
// their confirmation, decides; an agent task has no one to confirm it.
|
|
246
|
-
if (planned.name ===
|
|
249
|
+
if (planned.name === AGENT_DRAFT &&
|
|
247
250
|
name === "approve" &&
|
|
248
251
|
principal.authenticatedVia === AGENT_TASK_AUTHENTICATION) {
|
|
249
252
|
return yield* new ActionRejected({
|
|
250
|
-
message: "Agent tasks cannot approve a
|
|
253
|
+
message: "Agent tasks cannot approve a draft: agent_draft.approve needs a member to " +
|
|
251
254
|
"confirm the text the person receives.",
|
|
252
255
|
});
|
|
253
256
|
}
|
|
257
|
+
// @legacy ontology.agent-review-entity-name
|
|
258
|
+
// Callers written for the entity's earlier name still send its input keys.
|
|
259
|
+
input = currentActionInput(planned.name, input);
|
|
254
260
|
const requestId = yield* RequestId;
|
|
255
|
-
// Every action of the chat registry and of
|
|
261
|
+
// Every action of the chat registry and of drafts reaches chats through the service:
|
|
256
262
|
// posts, takeovers, imports, approvals and redrafts.
|
|
257
|
-
const delivery = planned.name === "agent_chat" || planned.name ===
|
|
263
|
+
const delivery = planned.name === "agent_chat" || planned.name === AGENT_DRAFT
|
|
258
264
|
? chatDelivery?.({
|
|
259
265
|
backend,
|
|
260
266
|
principal,
|
|
@@ -689,7 +689,7 @@ export interface AgentStore {
|
|
|
689
689
|
*/
|
|
690
690
|
readonly seeGuestChat?: (guestId: string) => Effect.Effect<SeenChat | undefined>;
|
|
691
691
|
/**
|
|
692
|
-
* A reply the agent
|
|
692
|
+
* A reply the agent kept for review becomes a pending `agent_draft` for the member it answers,
|
|
693
693
|
* once per `key`: a repeated report answers the review it created. `undefined` when the member is
|
|
694
694
|
* not an active member of the app. Absent on stores that predate reviews.
|
|
695
695
|
*/
|
|
@@ -733,7 +733,7 @@ export interface AgentStore {
|
|
|
733
733
|
/** The chats' messages, in `_chat_messages`. Absent on stores that predate the chat store. */
|
|
734
734
|
readonly chatMessages?: import("../runtime/chat-messages.js").ChatMessageStore;
|
|
735
735
|
}
|
|
736
|
-
/** A reply the agent held for review, as `POST /api/ontology/agent/
|
|
736
|
+
/** A reply the agent held for review, as `POST /api/ontology/agent/drafts` reports it. */
|
|
737
737
|
export interface HeldReplyInput {
|
|
738
738
|
readonly key: string;
|
|
739
739
|
/** The kind of channel the chat is on, such as whatsapp. */
|
|
@@ -760,7 +760,7 @@ export interface HeldReplyInput {
|
|
|
760
760
|
readonly mode: "always" | "whenUnsure";
|
|
761
761
|
readonly confidence: number | null;
|
|
762
762
|
}
|
|
763
|
-
/** A reply the agent redrafted, as `POST /api/ontology/agent/
|
|
763
|
+
/** A reply the agent redrafted, as `POST /api/ontology/agent/drafts/revision` reports it. */
|
|
764
764
|
export interface RevisedReplyInput {
|
|
765
765
|
/** The review the redraft replaces. */
|
|
766
766
|
readonly review: string;
|
|
@@ -19,3 +19,9 @@ export interface OntologyService {
|
|
|
19
19
|
* and `x-request-id`; failures answer with a JSON error and never a stack or SQL.
|
|
20
20
|
*/
|
|
21
21
|
export declare function createOntologyService(ontology: Ontology, config: OntologyServiceConfig): OntologyService;
|
|
22
|
+
/**
|
|
23
|
+
* The request with a path that names a built-in entity by its earlier name, `/api/ontology/<earlier>/…`,
|
|
24
|
+
* under the current one, so that callers written for the earlier name reach the entity's routes;
|
|
25
|
+
* any other request as it is. Only the current names are listed in the catalog and the docs.
|
|
26
|
+
*/
|
|
27
|
+
export declare function withCurrentEntityPath(request: Request): Request;
|
package/dist/service/service.js
CHANGED
|
@@ -30,7 +30,7 @@ import { agentTasksLayer } from "./agent/tasks.js";
|
|
|
30
30
|
import { makeMetricQueries } from "./metric-query.js";
|
|
31
31
|
import { platformMetricQueries } from "./metric-query-platform.js";
|
|
32
32
|
import { platformWarehouseQueries, WarehouseQueries } from "./warehouse-platform.js";
|
|
33
|
-
import { ErrorResponsesLive, buildApi } from "./api.js";
|
|
33
|
+
import { BASE_PATH, ErrorResponsesLive, buildApi } from "./api.js";
|
|
34
34
|
import { CurrentPrincipal, authenticationLayer, neonAuthSessionExchange, tokenVerifier, withPrincipal, } from "./authentication.js";
|
|
35
35
|
import { currentCaller } from "./caller-context.js";
|
|
36
36
|
import { OntologyServiceConfigError, } from "./config.js";
|
|
@@ -55,6 +55,7 @@ import { neonEmailCodes } from "./agent/guest-sign-up.js";
|
|
|
55
55
|
import { vercelWorkflowEngine, workflowStarter, workflowsLayer } from "./workflows.js";
|
|
56
56
|
import { deploymentWorkflowEngine } from "./workflow-deployment.js";
|
|
57
57
|
import { OntologyBackend } from "./runtime-contract.js";
|
|
58
|
+
import { currentEntityPath } from "../earlier-entity-names.js";
|
|
58
59
|
import { runtimeCredential, runtimeTokenVerifier, } from "./runtime-identity.js";
|
|
59
60
|
/** The header every response carries: the hash of the manifest the service serves. */
|
|
60
61
|
export const ONTOLOGY_HASH_HEADER = "x-ontology-hash";
|
|
@@ -518,7 +519,9 @@ export function createOntologyService(ontology, config) {
|
|
|
518
519
|
const hash = ontology.manifest.hash;
|
|
519
520
|
// Only names from the deployed plan enter diagnostics; arbitrary path segments may be private.
|
|
520
521
|
function operationOf(request) {
|
|
521
|
-
const
|
|
522
|
+
const requested = new URL(request.url).pathname;
|
|
523
|
+
// @legacy ontology.agent-review-entity-name
|
|
524
|
+
const path = currentEntityPath(requested, BASE_PATH) ?? requested;
|
|
522
525
|
const parts = path.split("/");
|
|
523
526
|
const entity = plan.entities.find((candidate) => candidate.name === parts[3]);
|
|
524
527
|
if (parts[1] === "api" && parts[2] === "ontology" && entity !== undefined) {
|
|
@@ -555,7 +558,7 @@ export function createOntologyService(ontology, config) {
|
|
|
555
558
|
throw new DeploymentAdmissionError("preview_authentication_unavailable");
|
|
556
559
|
}
|
|
557
560
|
}
|
|
558
|
-
response = await web.handler(request, Context.make(RequestId, requestId));
|
|
561
|
+
response = await web.handler(withCurrentEntityPath(request), Context.make(RequestId, requestId));
|
|
559
562
|
}
|
|
560
563
|
catch (error) {
|
|
561
564
|
if (error instanceof DeploymentAdmissionError) {
|
|
@@ -588,3 +591,18 @@ export function createOntologyService(ontology, config) {
|
|
|
588
591
|
},
|
|
589
592
|
};
|
|
590
593
|
}
|
|
594
|
+
// @legacy ontology.agent-review-entity-name
|
|
595
|
+
/**
|
|
596
|
+
* The request with a path that names a built-in entity by its earlier name, `/api/ontology/<earlier>/…`,
|
|
597
|
+
* under the current one, so that callers written for the earlier name reach the entity's routes;
|
|
598
|
+
* any other request as it is. Only the current names are listed in the catalog and the docs.
|
|
599
|
+
*/
|
|
600
|
+
export function withCurrentEntityPath(request) {
|
|
601
|
+
const url = new URL(request.url);
|
|
602
|
+
const current = currentEntityPath(url.pathname, BASE_PATH);
|
|
603
|
+
if (current === undefined) {
|
|
604
|
+
return request;
|
|
605
|
+
}
|
|
606
|
+
url.pathname = current;
|
|
607
|
+
return new Request(url, request);
|
|
608
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ChannelFile, type ChannelPart, type ChannelRequest, type DefiniteFailure } from "./channel-files.js";
|
|
2
|
+
/**
|
|
3
|
+
* Slack's message with files, which the agent's `attachments_send` and the ontology's delivery of
|
|
4
|
+
* an approved draft both send, with Slack's external upload: each file's bytes go to the address
|
|
5
|
+
* `files.getUploadURLExternal` answers, then one `files.completeUploadExternal` shares all of them
|
|
6
|
+
* in the chat with the text, as one visible message. Nothing is visible until that share, so a
|
|
7
|
+
* file that fails to upload is left out without anything reaching the person. The Web API calls
|
|
8
|
+
* go on the connection's `web` API and the bytes on its `files` API.
|
|
9
|
+
*/
|
|
10
|
+
/** The most bytes of one file a single connection request carries to Slack. */
|
|
11
|
+
export declare const SLACK_FILE_BYTES: number;
|
|
12
|
+
/** The most files one `files.completeUploadExternal` shares. */
|
|
13
|
+
export declare const SLACK_FILES_PER_MESSAGE = 10;
|
|
14
|
+
/** Why Slack cannot take this file through one connection request, or undefined when it can. */
|
|
15
|
+
export declare function slackFileRefusal(file: {
|
|
16
|
+
readonly size: number;
|
|
17
|
+
}): {
|
|
18
|
+
readonly code: "too_large" | "empty";
|
|
19
|
+
readonly message: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
/** What Slack's upload of the files and its share became. */
|
|
22
|
+
export interface SlackFilesResult {
|
|
23
|
+
/**
|
|
24
|
+
* Each file's upload in the order given, which nobody sees: Slack's file id, or why it did not
|
|
25
|
+
* upload. A file that did not upload is not shared.
|
|
26
|
+
*/
|
|
27
|
+
readonly uploads: ReadonlyArray<{
|
|
28
|
+
readonly index: number;
|
|
29
|
+
readonly slackFileId: string;
|
|
30
|
+
} | {
|
|
31
|
+
readonly index: number;
|
|
32
|
+
readonly code: string;
|
|
33
|
+
readonly cause: unknown;
|
|
34
|
+
}>;
|
|
35
|
+
/** The one visible message, absent when no file uploaded. */
|
|
36
|
+
readonly share?: ChannelPart;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Uploads `files`, then shares those that uploaded in `channel`, in `threadTs` when given, with
|
|
40
|
+
* `text` as the message's text. The share is `sent` when Slack confirms it, `failed` when Slack
|
|
41
|
+
* refused it with a code that proves nothing was posted, otherwise `uncertain`. Nothing is
|
|
42
|
+
* retried.
|
|
43
|
+
*/
|
|
44
|
+
export declare function sendSlackFiles(options: {
|
|
45
|
+
readonly request: ChannelRequest;
|
|
46
|
+
readonly channel: string;
|
|
47
|
+
readonly threadTs?: string;
|
|
48
|
+
readonly files: ReadonlyArray<ChannelFile & {
|
|
49
|
+
readonly index?: number;
|
|
50
|
+
}>;
|
|
51
|
+
readonly text?: string;
|
|
52
|
+
readonly definite?: DefiniteFailure;
|
|
53
|
+
}): Promise<SlackFilesResult>;
|