@segmentstream/ontology 0.98.1 → 0.99.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 +1246 -0
- package/README.md +8 -5
- package/dist/agent-review.d.ts +4 -4
- package/dist/agent-review.js +10 -10
- package/dist/analyze.js +40 -5
- package/dist/app-feedback.js +1 -1
- package/dist/feedback-config.js +17 -8
- package/dist/groups.d.ts +11 -4
- package/dist/groups.js +54 -11
- package/dist/permissions.d.ts +1 -1
- package/dist/permissions.js +1 -1
- package/dist/runtime-source.js +3 -3
- package/dist/service/agent/{conversation-routes.d.ts → archive-routes.d.ts} +7 -4
- package/dist/service/agent/{conversation-routes.js → archive-routes.js} +8 -5
- package/dist/service/agent/attachments.d.ts +2 -2
- package/dist/service/agent/attachments.js +2 -2
- package/dist/service/agent/authentication.d.ts +1 -1
- package/dist/service/agent/authentication.js +7 -5
- package/dist/service/agent/{conversations.d.ts → chat-archive.d.ts} +11 -11
- package/dist/service/agent/{conversations.js → chat-archive.js} +12 -12
- package/dist/service/agent/protocol.js +2 -2
- package/dist/service/chat/archive.d.ts +2 -2
- package/dist/service/chat/archive.js +1 -1
- package/dist/service/chat/attribution.d.ts +1 -1
- package/dist/service/chat/delivery.d.ts +2 -2
- package/dist/service/chat/delivery.js +2 -2
- package/dist/service/chat/idempotency.d.ts +3 -3
- package/dist/service/chat/reads.d.ts +3 -3
- package/dist/service/chat/reads.js +10 -10
- package/dist/service/chat/resolve.d.ts +6 -6
- package/dist/service/chat/resolve.js +7 -7
- package/dist/service/chat/review-delivery.d.ts +1 -1
- package/dist/service/chat/review-delivery.js +4 -4
- package/dist/service/chat/routes.d.ts +2 -2
- package/dist/service/chat/routes.js +7 -7
- package/dist/service/errors.js +3 -3
- package/dist/service/mcp/server.d.ts +3 -3
- package/dist/service/mcp/server.js +15 -15
- package/dist/service/mcp/tools.d.ts +2 -2
- package/dist/service/mcp/tools.js +12 -14
- package/dist/service/member-file-routes.js +26 -2
- package/dist/service/member-files.d.ts +7 -7
- package/dist/service/member-files.js +2 -2
- package/dist/service/service.js +9 -9
- package/dist/storage/attachments.d.ts +3 -3
- package/dist/storage/attachments.js +16 -15
- package/dist/storage/tables.d.ts +4 -0
- package/dist/storage/tables.js +4 -0
- package/package.json +2 -1
|
@@ -8,7 +8,7 @@ import { metricDescription, metricsFor, modelMetricDescription, modelMetricsFor,
|
|
|
8
8
|
import { actionInputJsonSchema } from "../../runtime/generated-actions.js";
|
|
9
9
|
import { uploadFields } from "../../storage/attachments.js";
|
|
10
10
|
import { MEMBER_FILE_SCHEMAS } from "../member-files.js";
|
|
11
|
-
import {
|
|
11
|
+
import { ChatSearch } from "../agent/chat-archive.js";
|
|
12
12
|
import { declaredChatProviders } from "../chat/providers/index.js";
|
|
13
13
|
import { runtimeAllows } from "./runtime-policy.js";
|
|
14
14
|
import { confirmationFacts, needsConfirmation, withConfirmation, } from "./confirmation.js";
|
|
@@ -709,7 +709,7 @@ function metricTools(manifest) {
|
|
|
709
709
|
* as they have no record routes. Throws {@link InvalidOntology} when two tools share a name, which
|
|
710
710
|
* `check` already refuses.
|
|
711
711
|
*/
|
|
712
|
-
export function mcpTools(built,
|
|
712
|
+
export function mcpTools(built, chatHistory = false, storage = {}, navigation = false) {
|
|
713
713
|
const { manifest } = built.plan.ontology;
|
|
714
714
|
const tools = [
|
|
715
715
|
...GLOBAL_TOOLS,
|
|
@@ -798,8 +798,8 @@ export function mcpTools(built, conversations = false, storage = {}, navigation
|
|
|
798
798
|
});
|
|
799
799
|
tools.push({
|
|
800
800
|
name: "chat_history",
|
|
801
|
-
title: "Read chat
|
|
802
|
-
description: "Read messages for an exact chat ID/title, with
|
|
801
|
+
title: "Read chat history",
|
|
802
|
+
description: "Read messages for an exact chat ID/title, with their own pagination. " +
|
|
803
803
|
"Reads a group chat you are in (every group with agent_chat:read) or your own private chat.",
|
|
804
804
|
inputSchema: encodedJsonSchema(ChatHistory),
|
|
805
805
|
annotations: READ,
|
|
@@ -809,24 +809,22 @@ export function mcpTools(built, conversations = false, storage = {}, navigation
|
|
|
809
809
|
});
|
|
810
810
|
tools.push({
|
|
811
811
|
name: "chat_search",
|
|
812
|
-
title: "Search stored
|
|
813
|
-
description:
|
|
814
|
-
? "Search retained
|
|
812
|
+
title: "Search stored chats",
|
|
813
|
+
description: chatHistory
|
|
814
|
+
? "Search retained chat messages, decisions and tool calls by text, provider chat ID, " +
|
|
815
815
|
"sender ID, topic and date range. Returns the group chats you are in (every group with " +
|
|
816
816
|
"agent_chat:read) and DMs in which you participated. Dates are ISO 8601; before is the " +
|
|
817
817
|
"nextCursor of the previous page. " +
|
|
818
818
|
"Workspace administrators can read all DMs through the platform API."
|
|
819
|
-
: "Search retained
|
|
820
|
-
inputSchema: encodedJsonSchema(
|
|
819
|
+
: "Search retained chat messages. Requires an available archive and chat archive read access.",
|
|
820
|
+
inputSchema: encodedJsonSchema(ChatSearch),
|
|
821
821
|
annotations: READ,
|
|
822
822
|
permissions: [],
|
|
823
|
-
target: { kind: "
|
|
824
|
-
inputSchemaFor: (caller) => "kind" in caller && caller.kind === "member"
|
|
825
|
-
? encodedJsonSchema(ConversationSearch)
|
|
826
|
-
: undefined,
|
|
823
|
+
target: { kind: "chat-search" },
|
|
824
|
+
inputSchemaFor: (caller) => "kind" in caller && caller.kind === "member" ? encodedJsonSchema(ChatSearch) : undefined,
|
|
827
825
|
});
|
|
828
826
|
const descriptions = {
|
|
829
|
-
"attachments-list": "List chat attachments by
|
|
827
|
+
"attachments-list": "List chat attachments by chat (provider:chat ID), sender member UUID and ISO time range. " +
|
|
830
828
|
"Returns a bounded page and nextCursor; use before to resume. Includes expired metadata. " +
|
|
831
829
|
"Administrators with agent_chat:update may access any workspace chat; active group participants " +
|
|
832
830
|
"and DM senders may access their files.",
|
|
@@ -18,9 +18,14 @@ export function memberFileRoutes(options) {
|
|
|
18
18
|
const params = yield* HttpRouter.params;
|
|
19
19
|
let args = params;
|
|
20
20
|
if (kind === "attachments-list") {
|
|
21
|
-
|
|
21
|
+
// @legacy ontology.attachment-conversation-field
|
|
22
|
+
// CLIs before `chat` filter by `conversation` and print each attachment's.
|
|
23
|
+
const { conversation, ...query } = Object.fromEntries(new URL(request.url, "https://app.invalid").searchParams);
|
|
22
24
|
args = {
|
|
23
25
|
...query,
|
|
26
|
+
...(query.chat === undefined && conversation !== undefined
|
|
27
|
+
? { chat: conversation }
|
|
28
|
+
: {}),
|
|
24
29
|
...(query.limit === undefined ? {} : { limit: Number(query.limit) }),
|
|
25
30
|
};
|
|
26
31
|
}
|
|
@@ -32,7 +37,7 @@ export function memberFileRoutes(options) {
|
|
|
32
37
|
: body;
|
|
33
38
|
}
|
|
34
39
|
const answer = yield* run(kind, args, identityToken(request));
|
|
35
|
-
return HttpServerResponse.jsonUnsafe(answer, {
|
|
40
|
+
return HttpServerResponse.jsonUnsafe(withEarlierChatField(kind, answer), {
|
|
36
41
|
headers: { "cache-control": "private, no-store" },
|
|
37
42
|
});
|
|
38
43
|
}).pipe(Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause)
|
|
@@ -50,3 +55,22 @@ export function memberFileRoutes(options) {
|
|
|
50
55
|
yield* router.add("GET", "/api/ontology/files/:entity/:id", route("files-download"));
|
|
51
56
|
}));
|
|
52
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* @legacy ontology.attachment-conversation-field
|
|
60
|
+
* Each listed attachment's chat also under `conversation`, which CLIs before `chat` print.
|
|
61
|
+
*/
|
|
62
|
+
function withEarlierChatField(kind, answer) {
|
|
63
|
+
if (kind !== "attachments-list" || typeof answer !== "object" || answer === null) {
|
|
64
|
+
return answer;
|
|
65
|
+
}
|
|
66
|
+
const list = answer;
|
|
67
|
+
return list.attachments === undefined
|
|
68
|
+
? answer
|
|
69
|
+
: {
|
|
70
|
+
...answer,
|
|
71
|
+
attachments: list.attachments.map((attachment) => ({
|
|
72
|
+
...attachment,
|
|
73
|
+
conversation: attachment.chat,
|
|
74
|
+
})),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -5,7 +5,7 @@ import type { Operations } from "./operations.js";
|
|
|
5
5
|
import type { ApiPlan } from "./plan.js";
|
|
6
6
|
import type { OntologyBackend } from "./runtime-contract.js";
|
|
7
7
|
export declare const AttachmentFilters: Schema.Struct<{
|
|
8
|
-
readonly
|
|
8
|
+
readonly chat: Schema.optionalKey<Schema.String>;
|
|
9
9
|
readonly sender_id: Schema.optionalKey<Schema.String>;
|
|
10
10
|
readonly from: Schema.optionalKey<Schema.String>;
|
|
11
11
|
readonly to: Schema.optionalKey<Schema.String>;
|
|
@@ -14,7 +14,7 @@ export declare const AttachmentFilters: Schema.Struct<{
|
|
|
14
14
|
}>;
|
|
15
15
|
export declare const MEMBER_FILE_SCHEMAS: {
|
|
16
16
|
"attachments-list": Schema.Struct<{
|
|
17
|
-
readonly
|
|
17
|
+
readonly chat: Schema.optionalKey<Schema.String>;
|
|
18
18
|
readonly sender_id: Schema.optionalKey<Schema.String>;
|
|
19
19
|
readonly from: Schema.optionalKey<Schema.String>;
|
|
20
20
|
readonly to: Schema.optionalKey<Schema.String>;
|
|
@@ -84,7 +84,7 @@ export declare function attachmentForWire(attachment: import("../storage/attachm
|
|
|
84
84
|
created_at: string;
|
|
85
85
|
expires_at: string;
|
|
86
86
|
promotion: unknown;
|
|
87
|
-
|
|
87
|
+
chat: string | undefined;
|
|
88
88
|
sender_id: string | undefined;
|
|
89
89
|
};
|
|
90
90
|
/** The member REST and MCP surfaces run the same runtime operations and action pipeline. */
|
|
@@ -174,7 +174,7 @@ export declare function memberFileOperations(backend: OntologyBackend["Service"]
|
|
|
174
174
|
created_at: string;
|
|
175
175
|
expires_at: string;
|
|
176
176
|
promotion: unknown;
|
|
177
|
-
|
|
177
|
+
chat: string | undefined;
|
|
178
178
|
sender_id: string | undefined;
|
|
179
179
|
}[];
|
|
180
180
|
nextCursor: string | null;
|
|
@@ -192,7 +192,7 @@ export declare function memberFileOperations(backend: OntologyBackend["Service"]
|
|
|
192
192
|
created_at: string;
|
|
193
193
|
expires_at: string;
|
|
194
194
|
promotion: unknown;
|
|
195
|
-
|
|
195
|
+
chat: string | undefined;
|
|
196
196
|
sender_id: string | undefined;
|
|
197
197
|
};
|
|
198
198
|
deduplicated: boolean;
|
|
@@ -212,7 +212,7 @@ export declare function memberFileOperations(backend: OntologyBackend["Service"]
|
|
|
212
212
|
created_at: string;
|
|
213
213
|
expires_at: string;
|
|
214
214
|
promotion: unknown;
|
|
215
|
-
|
|
215
|
+
chat: string | undefined;
|
|
216
216
|
sender_id: string | undefined;
|
|
217
217
|
};
|
|
218
218
|
upload?: undefined;
|
|
@@ -230,7 +230,7 @@ export declare function memberFileOperations(backend: OntologyBackend["Service"]
|
|
|
230
230
|
created_at: string;
|
|
231
231
|
expires_at: string;
|
|
232
232
|
promotion: unknown;
|
|
233
|
-
|
|
233
|
+
chat: string | undefined;
|
|
234
234
|
sender_id: string | undefined;
|
|
235
235
|
};
|
|
236
236
|
download: {
|
|
@@ -10,7 +10,7 @@ import { InvalidRequestBody, RequestId } from "./errors.js";
|
|
|
10
10
|
const Id = Schema.String.check(Schema.isUUID());
|
|
11
11
|
const DateTime = Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/));
|
|
12
12
|
export const AttachmentFilters = Schema.Struct({
|
|
13
|
-
|
|
13
|
+
chat: Schema.optionalKey(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(200))),
|
|
14
14
|
sender_id: Schema.optionalKey(Id),
|
|
15
15
|
from: Schema.optionalKey(DateTime),
|
|
16
16
|
to: Schema.optionalKey(DateTime),
|
|
@@ -88,7 +88,7 @@ export function attachmentForWire(attachment) {
|
|
|
88
88
|
created_at: attachment.createdAt,
|
|
89
89
|
expires_at: attachment.expiresAt,
|
|
90
90
|
promotion: attachment.promotion,
|
|
91
|
-
|
|
91
|
+
chat: attachment.chat,
|
|
92
92
|
sender_id: attachment.senderId,
|
|
93
93
|
};
|
|
94
94
|
}
|
package/dist/service/service.js
CHANGED
|
@@ -15,8 +15,8 @@ import { neonSignInLinks, segmentstreamSignInLinks } from "../runtime/sign-in-li
|
|
|
15
15
|
import { memberFileRoutes } from "./member-file-routes.js";
|
|
16
16
|
import { attachmentsLayer } from "./agent/attachments.js";
|
|
17
17
|
import { filesLayer } from "./agent/files.js";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import { platformChatArchive } from "./agent/chat-archive.js";
|
|
19
|
+
import { archiveRoutes } from "./agent/archive-routes.js";
|
|
20
20
|
import { makeChatDelivery } from "./chat/delivery.js";
|
|
21
21
|
import { platformDeliveryArchive } from "./chat/archive.js";
|
|
22
22
|
import { chatRoutes } from "./chat/routes.js";
|
|
@@ -338,7 +338,7 @@ export function createOntologyService(ontology, config) {
|
|
|
338
338
|
: localConnections(config.localConnections)));
|
|
339
339
|
const replicate = deployedReplication(config);
|
|
340
340
|
const chatDelivery = makeChatDelivery(ontology, connections, config.chatArchive ?? platformDeliveryArchive(config), { settings: config.channels?.telegram, ownOrigins: config.appOrigins });
|
|
341
|
-
const
|
|
341
|
+
const chatHistory = config.runtimeIdentity === undefined ? undefined : platformChatArchive(config);
|
|
342
342
|
const metricQueries = makeMetricQueries({
|
|
343
343
|
ontology,
|
|
344
344
|
transport: platformMetricQueries({ ...config, manifestHash: ontology.manifest.hash }),
|
|
@@ -359,7 +359,7 @@ export function createOntologyService(ontology, config) {
|
|
|
359
359
|
replicate,
|
|
360
360
|
metricQueries,
|
|
361
361
|
chatDelivery,
|
|
362
|
-
|
|
362
|
+
chatHistory,
|
|
363
363
|
...(navigation === undefined ? {} : { navigation }),
|
|
364
364
|
appOrigins: config.appOrigins,
|
|
365
365
|
streamMaxDurationMs: config.mcpStreamMaxDurationMs,
|
|
@@ -397,7 +397,7 @@ export function createOntologyService(ontology, config) {
|
|
|
397
397
|
connections,
|
|
398
398
|
replicate,
|
|
399
399
|
chatDelivery,
|
|
400
|
-
|
|
400
|
+
chatHistory,
|
|
401
401
|
verifyToken,
|
|
402
402
|
verifyRuntime,
|
|
403
403
|
exchangeSession,
|
|
@@ -409,10 +409,10 @@ export function createOntologyService(ontology, config) {
|
|
|
409
409
|
chatDelivery,
|
|
410
410
|
verifyToken,
|
|
411
411
|
exchangeSession,
|
|
412
|
-
}), preview ? Layer.empty : filesLayer({ plan: built.plan, verifyRuntime }),
|
|
412
|
+
}), preview ? Layer.empty : filesLayer({ plan: built.plan, verifyRuntime }), chatHistory === undefined
|
|
413
413
|
? Layer.empty
|
|
414
|
-
:
|
|
415
|
-
transport:
|
|
414
|
+
: archiveRoutes({
|
|
415
|
+
transport: chatHistory,
|
|
416
416
|
verifyToken,
|
|
417
417
|
verifyRuntime,
|
|
418
418
|
exchangeSession,
|
|
@@ -479,7 +479,7 @@ export function createOntologyService(ontology, config) {
|
|
|
479
479
|
requireDeploymentCapability(deployment);
|
|
480
480
|
if (preview) {
|
|
481
481
|
const path = new URL(request.url).pathname;
|
|
482
|
-
const blocked = /^\/api\/ontology\/(?:agent|agents|chat|
|
|
482
|
+
const blocked = /^\/api\/ontology\/(?:agent|agents|chat|attachments|channels)(?:\/|$)/.test(path)
|
|
483
483
|
? "agents"
|
|
484
484
|
: undefined;
|
|
485
485
|
if (blocked) {
|
|
@@ -25,7 +25,7 @@ export { ATTACHMENT_SOURCES };
|
|
|
25
25
|
export interface AttachmentCaller {
|
|
26
26
|
readonly principal: Principal;
|
|
27
27
|
/** The chat the attachment arrived in, such as `telegram:12345`. */
|
|
28
|
-
readonly
|
|
28
|
+
readonly chat: string;
|
|
29
29
|
/**
|
|
30
30
|
* The agent session the request comes from. Private attachments stay bound to the first session
|
|
31
31
|
* that reads them. Group attachments are shared across authorized sessions in the same chat.
|
|
@@ -64,11 +64,11 @@ export interface AttachmentView {
|
|
|
64
64
|
readonly createdAt: string;
|
|
65
65
|
readonly expiresAt: string;
|
|
66
66
|
readonly promotion: unknown;
|
|
67
|
-
readonly
|
|
67
|
+
readonly chat?: string;
|
|
68
68
|
readonly senderId?: string;
|
|
69
69
|
}
|
|
70
70
|
export interface AttachmentSearch {
|
|
71
|
-
readonly
|
|
71
|
+
readonly chat?: string;
|
|
72
72
|
readonly senderId?: string;
|
|
73
73
|
readonly from?: string;
|
|
74
74
|
readonly to?: string;
|
|
@@ -25,7 +25,8 @@ export const ATTACHMENT_TTL_HOURS = 24;
|
|
|
25
25
|
export const MAX_LIVE_ATTACHMENTS = 50;
|
|
26
26
|
export { ATTACHMENT_SOURCES };
|
|
27
27
|
const SHA256 = /^[0-9a-f]{64}$/;
|
|
28
|
-
|
|
28
|
+
// @legacy ontology.attachment-conversation-column: the SQL here names the chat column `conversation`.
|
|
29
|
+
const SELECT = `SELECT a.id::text, a.blob_id::text, b.key, a.owner_id::text, a.conversation AS chat,
|
|
29
30
|
a.session_id, a.filename, a.content_type, a.size::text, a.sha256, a.state, a.provider_upload_id,
|
|
30
31
|
a.promotion,
|
|
31
32
|
to_char(a.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') AS created_at,
|
|
@@ -97,7 +98,7 @@ function view(row) {
|
|
|
97
98
|
createdAt: row.created_at,
|
|
98
99
|
expiresAt: row.expires_at,
|
|
99
100
|
promotion: row.promotion ?? null,
|
|
100
|
-
|
|
101
|
+
chat: row.chat,
|
|
101
102
|
senderId: row.owner_id,
|
|
102
103
|
};
|
|
103
104
|
}
|
|
@@ -121,9 +122,9 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
121
122
|
return "administrator";
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
|
-
const separator = caller.
|
|
125
|
+
const separator = caller.chat.indexOf(":");
|
|
125
126
|
const [chat] = yield* sql.unsafe(`SELECT id::text FROM "agent_chat"
|
|
126
|
-
WHERE provider = $1 AND external_id = $2 FOR SHARE`, [caller.
|
|
127
|
+
WHERE provider = $1 AND external_id = $2 FOR SHARE`, [caller.chat.slice(0, separator), caller.chat.slice(separator + 1)]);
|
|
127
128
|
if (chat === undefined) {
|
|
128
129
|
return "private";
|
|
129
130
|
}
|
|
@@ -157,7 +158,7 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
157
158
|
AND a.branch_id = $4 FOR UPDATE OF a, b`, [
|
|
158
159
|
id,
|
|
159
160
|
caller.principal.id,
|
|
160
|
-
caller.
|
|
161
|
+
caller.chat,
|
|
161
162
|
binding.branchId,
|
|
162
163
|
(access === "group" || access === "administrator") && scope === "session",
|
|
163
164
|
]);
|
|
@@ -210,7 +211,7 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
210
211
|
yield* authorizeBlobOperation(ontology, sql, caller.principal.id, [], caller.principal.execution);
|
|
211
212
|
yield* sql.unsafe(`SELECT pg_advisory_xact_lock(818724)`);
|
|
212
213
|
const [existing] = yield* sql.unsafe(`SELECT id::text FROM "${ATTACHMENTS_TABLE}"
|
|
213
|
-
WHERE owner_id = $1::uuid AND conversation = $2 AND source_ref = $3`, [caller.principal.id, caller.
|
|
214
|
+
WHERE owner_id = $1::uuid AND conversation = $2 AND source_ref = $3`, [caller.principal.id, caller.chat, input.sourceRef]);
|
|
214
215
|
if (existing) {
|
|
215
216
|
const row = yield* load(existing.id, caller, "source");
|
|
216
217
|
if (row.sha256 !== input.sha256 || Number(row.size) !== input.size) {
|
|
@@ -259,7 +260,7 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
259
260
|
blobId,
|
|
260
261
|
binding.branchId,
|
|
261
262
|
caller.principal.id,
|
|
262
|
-
caller.
|
|
263
|
+
caller.chat,
|
|
263
264
|
caller.sessionId ?? null,
|
|
264
265
|
input.source,
|
|
265
266
|
input.sourceRef,
|
|
@@ -346,7 +347,7 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
346
347
|
AND ($5 OR a.session_id IS NULL OR a.session_id = $4)
|
|
347
348
|
ORDER BY a.created_at DESC LIMIT ${MAX_LIVE_ATTACHMENTS}`, [
|
|
348
349
|
caller.principal.id,
|
|
349
|
-
caller.
|
|
350
|
+
caller.chat,
|
|
350
351
|
binding.branchId,
|
|
351
352
|
caller.sessionId ?? null,
|
|
352
353
|
access === "group",
|
|
@@ -453,7 +454,7 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
453
454
|
binding.branchId,
|
|
454
455
|
row.id,
|
|
455
456
|
qualified,
|
|
456
|
-
caller.
|
|
457
|
+
caller.chat,
|
|
457
458
|
caller.principal.id,
|
|
458
459
|
["group", "administrator"].includes(yield* accessScope(caller)),
|
|
459
460
|
caller.sessionId ?? null,
|
|
@@ -562,13 +563,13 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
562
563
|
if (!/^[0-9a-f-]{36}$/i.test(id)) {
|
|
563
564
|
return yield* missing(id);
|
|
564
565
|
}
|
|
565
|
-
const [row] = yield* sql.unsafe(`SELECT conversation FROM "${ATTACHMENTS_TABLE}" WHERE id = $1::uuid AND branch_id = $2`, [id, binding.branchId]);
|
|
566
|
+
const [row] = yield* sql.unsafe(`SELECT conversation AS chat FROM "${ATTACHMENTS_TABLE}" WHERE id = $1::uuid AND branch_id = $2`, [id, binding.branchId]);
|
|
566
567
|
if (!row) {
|
|
567
568
|
return yield* missing(id);
|
|
568
569
|
}
|
|
569
570
|
const caller = {
|
|
570
571
|
principal,
|
|
571
|
-
|
|
572
|
+
chat: row.chat,
|
|
572
573
|
access: "member",
|
|
573
574
|
};
|
|
574
575
|
yield* load(id, caller);
|
|
@@ -597,10 +598,10 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
597
598
|
const admin = yield* authorizeBlobOperation(ontology, sql, principal.id, [
|
|
598
599
|
"agent_chat:update",
|
|
599
600
|
]).pipe(Effect.as(true), Effect.catchTag("PermissionDenied", () => Effect.succeed(false)));
|
|
600
|
-
if (filters.
|
|
601
|
+
if (filters.chat !== undefined) {
|
|
601
602
|
const scope = yield* accessScope({
|
|
602
603
|
principal,
|
|
603
|
-
|
|
604
|
+
chat: filters.chat,
|
|
604
605
|
access: "member",
|
|
605
606
|
});
|
|
606
607
|
if (scope === "denied") {
|
|
@@ -608,7 +609,7 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
608
609
|
}
|
|
609
610
|
if (scope === "private") {
|
|
610
611
|
const [sent] = yield* sql.unsafe(`SELECT 1 FROM "${ATTACHMENTS_TABLE}" WHERE branch_id = $1 AND conversation = $2
|
|
611
|
-
AND owner_id = $3::uuid LIMIT 1`, [binding.branchId, filters.
|
|
612
|
+
AND owner_id = $3::uuid LIMIT 1`, [binding.branchId, filters.chat, principal.id]);
|
|
612
613
|
if (sent === undefined) {
|
|
613
614
|
return yield* missing("chat");
|
|
614
615
|
}
|
|
@@ -633,7 +634,7 @@ export function attachmentRuntime(ontology, sql, provider) {
|
|
|
633
634
|
binding.branchId,
|
|
634
635
|
admin,
|
|
635
636
|
principal.id,
|
|
636
|
-
filters.
|
|
637
|
+
filters.chat ?? null,
|
|
637
638
|
filters.senderId ?? null,
|
|
638
639
|
filters.from ?? null,
|
|
639
640
|
filters.to ?? null,
|
package/dist/storage/tables.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ export declare const ATTACHMENT_SOURCE_CHECK = "_agent_attachments_source_check"
|
|
|
14
14
|
* a `_blobs` revision in the same storage as uploads; the row binds them to their owner, the chat
|
|
15
15
|
* and, for private chats, the first agent session that reads them. Group access follows the chat
|
|
16
16
|
* registry's current members. Attachments expire 24 hours after receipt unless promoted.
|
|
17
|
+
*
|
|
18
|
+
* @legacy ontology.attachment-conversation-column
|
|
19
|
+
* The column `conversation` holds the chat, `provider:external_id`: SDKs sharing this database
|
|
20
|
+
* still read and write it under that name.
|
|
17
21
|
*/
|
|
18
22
|
export declare const ATTACHMENT_TABLES_DDL: ReadonlyArray<string>;
|
|
19
23
|
/** The pending and started workflow starts of action triggers, beside the blob action results. */
|
package/dist/storage/tables.js
CHANGED
|
@@ -68,6 +68,10 @@ const SOURCE_CHECK = `CHECK ("source" IN (${ATTACHMENT_SOURCES.map((source) => `
|
|
|
68
68
|
* a `_blobs` revision in the same storage as uploads; the row binds them to their owner, the chat
|
|
69
69
|
* and, for private chats, the first agent session that reads them. Group access follows the chat
|
|
70
70
|
* registry's current members. Attachments expire 24 hours after receipt unless promoted.
|
|
71
|
+
*
|
|
72
|
+
* @legacy ontology.attachment-conversation-column
|
|
73
|
+
* The column `conversation` holds the chat, `provider:external_id`: SDKs sharing this database
|
|
74
|
+
* still read and write it under that name.
|
|
71
75
|
*/
|
|
72
76
|
export const ATTACHMENT_TABLES_DDL = [
|
|
73
77
|
`CREATE TABLE IF NOT EXISTS "${ATTACHMENTS_TABLE}" (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.99.1",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"files": [
|
|
70
70
|
"dist",
|
|
71
71
|
"README.md",
|
|
72
|
+
"CHANGELOG.md",
|
|
72
73
|
"LICENSE",
|
|
73
74
|
"NOTICE"
|
|
74
75
|
],
|