Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(call): batch preview endpoint (#2835)

Will Hutchinsona038de46b638
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreview.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreview.ts
new file mode 100644
index 0000000000..48fe195d89
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreview.ts
@@ -0,0 +1,19 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { CallRecordPreviewOneOf } from './callRecordPreviewOneOf';
+import type { CallRecordPreviewOneOfFour } from './callRecordPreviewOneOfFour';
+
+/**
+ * Lightweight preview of a call record, returned by the batch preview endpoint.
+
+Each requested id resolves to one of two outcomes: the call exists
+(`Exists`) or it does not (`DoesNotExist`). The endpoint does not perform
+access checks, so there is no separate "not authorized" variant.
+ */
+export type CallRecordPreview =
+ | CallRecordPreviewOneOf
+ | CallRecordPreviewOneOfFour;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewData.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewData.ts
new file mode 100644
index 0000000000..fbc834f7b3
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewData.ts
@@ -0,0 +1,24 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { CallRecordPreviewDataChannelName } from './callRecordPreviewDataChannelName';
+import type { CallRecordPreviewDataEndedAt } from './callRecordPreviewDataEndedAt';
+
+/**
+ * Preview payload returned for each found call id.
+ */
+export interface CallRecordPreviewData {
+ /** The call identifier. */
+ callId: string;
+ /** The channel this call belongs to. */
+ channelId: string;
+ /** Resolved display name for the channel. */
+ channelName?: CallRecordPreviewDataChannelName;
+ /** When the call ended (None if still active). */
+ endedAt?: CallRecordPreviewDataEndedAt;
+ /** When the call started (created_at for active, started_at for archived). */
+ startedAt: string;
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewDataChannelName.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewDataChannelName.ts
new file mode 100644
index 0000000000..c70af3f311
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewDataChannelName.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * Resolved display name for the channel.
+ */
+export type CallRecordPreviewDataChannelName = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewDataEndedAt.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewDataEndedAt.ts
new file mode 100644
index 0000000000..f250e91540
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewDataEndedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * When the call ended (None if still active).
+ */
+export type CallRecordPreviewDataEndedAt = string | null;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOf.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOf.ts
new file mode 100644
index 0000000000..8915a48b93
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOf.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { CallRecordPreviewData } from './callRecordPreviewData';
+import type { CallRecordPreviewOneOfAllOf } from './callRecordPreviewOneOfAllOf';
+
+/**
+ * The call exists (in either the active or archived table).
+ */
+export type CallRecordPreviewOneOf = CallRecordPreviewData &
+ CallRecordPreviewOneOfAllOf;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfAllOf.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfAllOf.ts
new file mode 100644
index 0000000000..5eb12a714d
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfAllOf.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { CallRecordPreviewOneOfAllOfType } from './callRecordPreviewOneOfAllOfType';
+
+export type CallRecordPreviewOneOfAllOf = {
+ type: CallRecordPreviewOneOfAllOfType;
+};
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfAllOfType.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfAllOfType.ts
new file mode 100644
index 0000000000..658c8cc310
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfAllOfType.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export type CallRecordPreviewOneOfAllOfType =
+ (typeof CallRecordPreviewOneOfAllOfType)[keyof typeof CallRecordPreviewOneOfAllOfType];
+
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+export const CallRecordPreviewOneOfAllOfType = {
+ exists: 'exists',
+} as const;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFour.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFour.ts
new file mode 100644
index 0000000000..3e51ecb6bb
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFour.ts
@@ -0,0 +1,15 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+import type { CallRecordPreviewOneOfFourAllOf } from './callRecordPreviewOneOfFourAllOf';
+import type { WithCallId } from './withCallId';
+
+/**
+ * No call with this id exists in either the active or archived tables.
+ */
+export type CallRecordPreviewOneOfFour = WithCallId &
+ CallRecordPreviewOneOfFourAllOf;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFourAllOf.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFourAllOf.ts
new file mode 100644
index 0000000000..0880097f69
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFourAllOf.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { CallRecordPreviewOneOfFourAllOfType } from './callRecordPreviewOneOfFourAllOfType';
+
+export type CallRecordPreviewOneOfFourAllOf = {
+ type: CallRecordPreviewOneOfFourAllOfType;
+};
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFourAllOfType.ts b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFourAllOfType.ts
new file mode 100644
index 0000000000..1253e432a1
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/callRecordPreviewOneOfFourAllOfType.ts
@@ -0,0 +1,14 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export type CallRecordPreviewOneOfFourAllOfType =
+ (typeof CallRecordPreviewOneOfFourAllOfType)[keyof typeof CallRecordPreviewOneOfFourAllOfType];
+
+// eslint-disable-next-line @typescript-eslint/no-redeclare
+export const CallRecordPreviewOneOfFourAllOfType = {
+ does_not_exist: 'does_not_exist',
+} as const;
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/getBatchCallRecordPreviewRequest.ts b/js/app/packages/service-clients/service-storage/generated/schemas/getBatchCallRecordPreviewRequest.ts
new file mode 100644
index 0000000000..6b7ba4827c
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/getBatchCallRecordPreviewRequest.ts
@@ -0,0 +1,18 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * Request body for `POST /call/record/preview`.
+
+The `call_ids` list is bounded at [`MAX_BATCH_CALL_IDS`]; the handler
+rejects anything larger with a 400 before touching the database.
+ */
+export interface GetBatchCallRecordPreviewRequest {
+ /** The call ids to preview. Duplicate ids are deduplicated server-side.
+Capped at [`MAX_BATCH_CALL_IDS`] entries. */
+ callIds: string[];
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/getBatchCallRecordPreviewResponse.ts b/js/app/packages/service-clients/service-storage/generated/schemas/getBatchCallRecordPreviewResponse.ts
new file mode 100644
index 0000000000..9111c7de62
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/getBatchCallRecordPreviewResponse.ts
@@ -0,0 +1,15 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { CallRecordPreview } from './callRecordPreview';
+
+/**
+ * Response body for `POST /call/record/preview`.
+ */
+export interface GetBatchCallRecordPreviewResponse {
+ /** One entry per deduplicated input id. */
+ previews: CallRecordPreview[];
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
index 8c2eda9849..637c91b9bf 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
@@ -86,6 +86,16 @@ export * from './callRecordEgressId';
export * from './callRecordEndedAt';
export * from './callRecordParticipant';
export * from './callRecordParticipantLeftAt';
+export * from './callRecordPreview';
+export * from './callRecordPreviewData';
+export * from './callRecordPreviewDataChannelName';
+export * from './callRecordPreviewDataEndedAt';
+export * from './callRecordPreviewOneOf';
+export * from './callRecordPreviewOneOfAllOf';
+export * from './callRecordPreviewOneOfAllOfType';
+export * from './callRecordPreviewOneOfFour';
+export * from './callRecordPreviewOneOfFourAllOf';
+export * from './callRecordPreviewOneOfFourAllOfType';
export * from './callRecordRecordingUrl';
export * from './callRecordTranscriptSegment';
export * from './callRecordTranscriptSegmentEndedAt';
@@ -330,6 +340,8 @@ export * from './genericResponseMessage';
export * from './genericSuccessResponse';
export * from './getActivitiesResponse';
export * from './getActivitiesResponseData';
+export * from './getBatchCallRecordPreviewRequest';
+export * from './getBatchCallRecordPreviewResponse';
export * from './getBatchPreviewRequest';
export * from './getBatchPreviewResponse';
export * from './getBatchProjectPreviewRequest';
@@ -664,5 +676,6 @@ export * from './view';
export * from './viewPatch';
export * from './viewPatchName';
export * from './viewsResponse';
+export * from './withCallId';
export * from './withDocumentId';
export * from './withProjectId';
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/withCallId.ts b/js/app/packages/service-clients/service-storage/generated/schemas/withCallId.ts
new file mode 100644
index 0000000000..f6b13fcfd4
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/withCallId.ts
@@ -0,0 +1,15 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * Wrapper carrying just a call id. Used by the [`CallRecordPreview::DoesNotExist`]
+variant.
+ */
+export interface WithCallId {
+ /** The call identifier. */
+ callId: string;
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index 44b9a62526..1b9a0de8c2 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -810,6 +810,87 @@ export const createCommentResponse = zod
})
);
+/**
+ * Batch-fetches lightweight previews for a list of call ids. Mirrors the
+`POST /documents/preview` endpoint: no per-id access checks, duplicate
+ids are deduplicated server-side, and missing ids come back as
+`CallRecordPreview::DoesNotExist` rather than producing an error.
+ * @summary Handler for `POST /call/record/preview`.
+ */
+export const getBatchCallRecordPreviewBody = zod
+ .object({
+ callIds: zod
+ .array(zod.string().uuid())
+ .describe(
+ 'The call ids to preview. Duplicate ids are deduplicated server-side.\nCapped at [`MAX_BATCH_CALL_IDS`] entries.'
+ ),
+ })
+ .describe(
+ 'Request body for `POST \/call\/record\/preview`.\n\nThe `call_ids` list is bounded at [`MAX_BATCH_CALL_IDS`]; the handler\nrejects anything larger with a 400 before touching the database.'
+ );
+
+export const getBatchCallRecordPreviewResponse = zod
+ .object({
+ previews: zod
+ .array(
+ zod
+ .union([
+ zod
+ .object({
+ callId: zod.string().uuid().describe('The call identifier.'),
+ channelId: zod
+ .string()
+ .uuid()
+ .describe('The channel this call belongs to.'),
+ channelName: zod
+ .string()
+ .nullish()
+ .describe('Resolved display name for the channel.'),
+ endedAt: zod
+ .string()
+ .datetime({})
+ .nullish()
+ .describe('When the call ended (None if still active).'),
+ startedAt: zod
+ .string()
+ .datetime({})
+ .describe(
+ 'When the call started (created_at for active, started_at for archived).'
+ ),
+ })
+ .describe('Preview payload returned for each found call id.')
+ .and(
+ zod.object({
+ type: zod.enum(['exists']),
+ })
+ )
+ .describe(
+ 'The call exists (in either the active or archived table).'
+ ),
+ zod
+ .object({
+ callId: zod.string().uuid().describe('The call identifier.'),
+ })
+ .describe(
+ 'Wrapper carrying just a call id. Used by the [`CallRecordPreview::DoesNotExist`]\nvariant.'
+ )
+ .and(
+ zod.object({
+ type: zod.enum(['does_not_exist']),
+ })
+ )
+ .describe(
+ 'No call with this id exists in either the active or archived tables.'
+ ),
+ ])
+ .describe(
+ 'Lightweight preview of a call record, returned by the batch preview endpoint.\n\nEach requested id resolves to one of two outcomes: the call exists\n(`Exists`) or it does not (`DoesNotExist`). The endpoint does not perform\naccess checks, so there is no separate \"not authorized\" variant.'
+ )
+ )
+ .describe('One entry per deduplicated input id.'),
+ })
+ .describe('Response body for `POST \/call\/record\/preview`.');
+
/**
* Returns the full [`CallRecord`] (metadata + participants + transcript)
for a call identified by its own id. Covers both active and archived calls.
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index a7b758e97e..839cf3041e 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -594,6 +594,66 @@
}
}
},
+ "/call/record/preview": {
+ "post": {
+ "tags": ["call::inbound::axum_router"],
+ "summary": "Handler for `POST /call/record/preview`.",
+ "description": "Batch-fetches lightweight previews for a list of call ids. Mirrors the\n`POST /documents/preview` endpoint: no per-id access checks, duplicate\nids are deduplicated server-side, and missing ids come back as\n`CallRecordPreview::DoesNotExist` rather than producing an error.",
+ "operationId": "get_batch_call_record_preview",
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GetBatchCallRecordPreviewRequest"
+ }
+ }
+ },
+ "required": true
+ },
+ "responses": {
+ "200": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GetBatchCallRecordPreviewResponse"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "call_ids exceeds MAX_BATCH_CALL_IDS",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "401": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/call/record/{call_id}": {
"get": {
"tags": ["call::inbound::axum_router"],
@@ -6248,6 +6308,80 @@
}
}
},
+ "CallRecordPreview": {
+ "oneOf": [
+ {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/CallRecordPreviewData",
+ "description": "The call exists (in either the active or archived table)."
+ },
+ {
+ "type": "object",
+ "required": ["type"],
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": ["exists"]
+ }
+ }
+ }
+ ],
+ "description": "The call exists (in either the active or archived table)."
+ },
+ {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/WithCallId",
+ "description": "No call with this id exists in either the active or archived tables."
+ },
+ {
+ "type": "object",
+ "required": ["type"],
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": ["does_not_exist"]
+ }
+ }
+ }
+ ],
+ "description": "No call with this id exists in either the active or archived tables."
+ }
+ ],
+ "description": "Lightweight preview of a call record, returned by the batch preview endpoint.\n\nEach requested id resolves to one of two outcomes: the call exists\n(`Exists`) or it does not (`DoesNotExist`). The endpoint does not perform\naccess checks, so there is no separate \"not authorized\" variant."
+ },
+ "CallRecordPreviewData": {
+ "type": "object",
+ "description": "Preview payload returned for each found call id.",
+ "required": ["callId", "channelId", "startedAt"],
+ "properties": {
+ "callId": {
+ "type": "string",
+ "format": "uuid",
+ "description": "The call identifier."
+ },
+ "channelId": {
+ "type": "string",
+ "format": "uuid",
+ "description": "The channel this call belongs to."
+ },
+ "channelName": {
+ "type": ["string", "null"],
+ "description": "Resolved display name for the channel."
+ },
+ "endedAt": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "When the call ended (None if still active)."
+ },
+ "startedAt": {
+ "type": "string",
+ "format": "date-time",
+ "description": "When the call started (created_at for active, started_at for archived)."
+ }
+ }
+ },
"CallRecordTranscriptSegment": {
"type": "object",
"description": "A transcript segment as returned in a [`CallRecord`].",
@@ -8729,6 +8863,35 @@
},
"deprecated": true
},
+ "GetBatchCallRecordPreviewRequest": {
+ "type": "object",
+ "description": "Request body for `POST /call/record/preview`.\n\nThe `call_ids` list is bounded at [`MAX_BATCH_CALL_IDS`]; the handler\nrejects anything larger with a 400 before touching the database.",
+ "required": ["callIds"],
+ "properties": {
+ "callIds": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "format": "uuid"
+ },
+ "description": "The call ids to preview. Duplicate ids are deduplicated server-side.\nCapped at [`MAX_BATCH_CALL_IDS`] entries."
+ }
+ }
+ },
+ "GetBatchCallRecordPreviewResponse": {
+ "type": "object",
+ "description": "Response body for `POST /call/record/preview`.",
+ "required": ["previews"],
+ "properties": {
+ "previews": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/CallRecordPreview"
+ },
+ "description": "One entry per deduplicated input id."
+ }
+ }
+ },
"GetBatchPreviewRequest": {
"type": "object",
"required": ["document_ids"],
@@ -11854,6 +12017,18 @@
}
}
},
+ "WithCallId": {
+ "type": "object",
+ "description": "Wrapper carrying just a call id. Used by the [`CallRecordPreview::DoesNotExist`]\nvariant.",
+ "required": ["callId"],
+ "properties": {
+ "callId": {
+ "type": "string",
+ "format": "uuid",
+ "description": "The call identifier."
+ }
+ }
+ },
"WithDocumentId": {
"type": "object",
"required": ["document_id"],
diff --git a/rust/cloud-storage/call/.sqlx/query-3d13e3995ba4fb30b9e2df9b41a42099d88663620b9139706c54340e757a47fc.json b/rust/cloud-storage/call/.sqlx/query-3d13e3995ba4fb30b9e2df9b41a42099d88663620b9139706c54340e757a47fc.json
new file mode 100644
index 0000000000..30a463452c
--- /dev/null
+++ b/rust/cloud-storage/call/.sqlx/query-3d13e3995ba4fb30b9e2df9b41a42099d88663620b9139706c54340e757a47fc.json
@@ -0,0 +1,40 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id as \"call_id!\",\n channel_id as \"channel_id!\",\n created_at as \"started_at!\",\n NULL::timestamptz as \"ended_at\"\n FROM calls\n WHERE id = ANY($1)\n UNION ALL\n SELECT\n id as \"call_id!\",\n channel_id as \"channel_id!\",\n started_at as \"started_at!\",\n ended_at as \"ended_at\"\n FROM call_records\n WHERE id = ANY($1)\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "call_id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "channel_id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 2,
+ "name": "started_at!",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 3,
+ "name": "ended_at",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "UuidArray"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "3d13e3995ba4fb30b9e2df9b41a42099d88663620b9139706c54340e757a47fc"
+}
diff --git a/rust/cloud-storage/call/src/domain/models.rs b/rust/cloud-storage/call/src/domain/models.rs
index 8af2fbeb01..f36c41b1f6 100644
--- a/rust/cloud-storage/call/src/domain/models.rs
+++ b/rust/cloud-storage/call/src/domain/models.rs
@@ -222,6 +222,76 @@ pub struct CallRecord {
pub transcript: Vec<CallRecordTranscriptSegment>,
}
+/// Lightweight preview of a call record, returned by the batch preview endpoint.
+///
+/// Each requested id resolves to one of two outcomes: the call exists
+/// (`Exists`) or it does not (`DoesNotExist`). The endpoint does not perform
+/// access checks, so there is no separate "not authorized" variant.
+#[derive(Debug, Clone, serde::Serialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+#[serde(tag = "type", rename_all = "snake_case")]
+pub enum CallRecordPreview {
+ /// The call exists (in either the active or archived table).
+ Exists(CallRecordPreviewData),
+ /// No call with this id exists in either the active or archived tables.
+ DoesNotExist(WithCallId),
+}
+
+/// Wrapper carrying just a call id. Used by the [`CallRecordPreview::DoesNotExist`]
+/// variant.
+#[derive(Debug, Clone, serde::Serialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct WithCallId {
+ /// The call identifier.
+ pub call_id: Uuid,
+}
+
+/// Preview payload returned for each found call id.
+#[derive(Debug, Clone, serde::Serialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct CallRecordPreviewData {
+ /// The call identifier.
+ pub call_id: Uuid,
+ /// The channel this call belongs to.
+ pub channel_id: Uuid,
+ /// Resolved display name for the channel.
+ pub channel_name: Option<String>,
+ /// When the call started (created_at for active, started_at for archived).
+ pub started_at: DateTime<Utc>,
+ /// When the call ended (None if still active).
+ pub ended_at: Option<DateTime<Utc>>,
+}
+
+/// Maximum number of call ids accepted in a single batch preview request.
+///
+/// Requests exceeding this limit are rejected with `400 Bad Request` so that
+/// DB work and response size remain bounded per call.
+pub const MAX_BATCH_CALL_IDS: usize = 100;
+
+/// Request body for `POST /call/record/preview`.
+///
+/// The `call_ids` list is bounded at [`MAX_BATCH_CALL_IDS`]; the handler
+/// rejects anything larger with a 400 before touching the database.
+#[derive(Debug, serde::Deserialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct GetBatchCallRecordPreviewRequest {
+ /// The call ids to preview. Duplicate ids are deduplicated server-side.
+ /// Capped at [`MAX_BATCH_CALL_IDS`] entries.
+ pub call_ids: Vec<Uuid>,
+}
+
+/// Response body for `POST /call/record/preview`.
+#[derive(Debug, serde::Serialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+#[serde(rename_all = "camelCase")]
+pub struct GetBatchCallRecordPreviewResponse {
+ /// One entry per deduplicated input id.
+ pub previews: Vec<CallRecordPreview>,
+}
+
/// Request to fetch recent call records for a user (used by Soup).
#[derive(Debug)]
pub struct GetCallRecordsRequest {
@@ -266,6 +336,9 @@ pub enum CallError {
/// Authentication or signature validation failed.
#[error("authentication failed")]
Auth,
+ /// The request body violates an API contract (e.g. exceeds a size cap).
+ #[error("{0}")]
+ InvalidRequest(String),
/// An internal error occurred.
#[error(transparent)]
Internal(#[from] anyhow::Error),
diff --git a/rust/cloud-storage/call/src/domain/ports.rs b/rust/cloud-storage/call/src/domain/ports.rs
index 126119e3be..08fc08f857 100644
--- a/rust/cloud-storage/call/src/domain/ports.rs
+++ b/rust/cloud-storage/call/src/domain/ports.rs
@@ -15,8 +15,9 @@ use crate::domain::models::EditCallRecordRequest;
use super::models::{
AddParticipantError, Call, CallActiveResponse, CallError, CallParticipant, CallRecord,
- CallTokenResponse, CallWebhookEvent, EgressS3Config, GetCallRecordsRequest, LeaveCallResponse,
- TranscriptSegmentRequest,
+ CallRecordPreview, CallTokenResponse, CallWebhookEvent, EgressS3Config,
+ GetBatchCallRecordPreviewRequest, GetBatchCallRecordPreviewResponse, GetCallRecordsRequest,
+ LeaveCallResponse, TranscriptSegmentRequest,
};
/// Repository port for persisting call state to the database.
@@ -166,6 +167,22 @@ pub trait CallRepository: Send + Sync + 'static {
call_id: &Uuid,
) -> impl Future<Output = Result<Option<CallRecord>, Self::Err>> + Send;
+ /// Batch-fetch lightweight previews for the given call ids.
+ ///
+ /// Returns one [`CallRecordPreview`] per deduplicated id in `call_ids`,
+ /// in the order supplied. Ids that resolve to a row (in either `calls`
+ /// or `call_records`) come back as [`CallRecordPreview::Exists`]; ids
+ /// that match neither come back as [`CallRecordPreview::DoesNotExist`].
+ /// No access checks are performed.
+ ///
+ /// `user_id` is used solely to resolve channel display names (e.g. the
+ /// "other participant" in a DM) and is not used for authorization.
+ fn batch_get_call_record_previews<'a>(
+ &self,
+ call_ids: &[Uuid],
+ user_id: MacroUserIdStr<'a>,
+ ) -> impl Future<Output = Result<Vec<CallRecordPreview>, Self::Err>> + Send;
+
/// Fetch the most recent call records where the given user was a
/// participant, spanning both active (`calls` + `call_participants`)
/// and archived (`call_records` + `call_record_participants`) tables.
@@ -366,6 +383,19 @@ pub trait CallService: Send + Sync + 'static {
&self,
receipt: EntityAccessReceipt<EditAccessLevel>,
) -> impl Future<Output = Result<bool, CallError>> + Send;
+
+ /// Batch-fetch lightweight previews for a list of call ids.
+ ///
+ /// Mirrors the `POST /documents/preview` endpoint in
+ /// `document_storage_service`: no per-id access checks, duplicate ids
+ /// are deduplicated, and the response preserves the deduplicated input
+ /// order. `user_id` is passed through to the repository solely for
+ /// channel-name resolution.
+ fn get_batch_call_record_previews<'a>(
+ &self,
+ request: GetBatchCallRecordPreviewRequest,
+ user_id: MacroUserIdStr<'a>,
+ ) -> impl Future<Output = Result<GetBatchCallRecordPreviewResponse, CallError>> + Send;
}
/// Lightweight read-only port for querying call records in Soup.
diff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rs
index 4bf66b8586..e0582b313d 100644
--- a/rust/cloud-storage/call/src/domain/service.rs
+++ b/rust/cloud-storage/call/src/domain/service.rs
@@ -25,7 +25,8 @@ use crate::domain::models::EditCallRecordRequest;
use super::models::{
AddParticipantError, CallActiveResponse, CallError, CallRecord, CallTokenResponse,
- EgressS3Config, GetCallRecordsRequest, LeaveCallResponse, TranscriptSegmentRequest,
+ EgressS3Config, GetBatchCallRecordPreviewRequest, GetBatchCallRecordPreviewResponse,
+ GetCallRecordsRequest, LeaveCallResponse, TranscriptSegmentRequest,
};
use super::ports::{
CallRecordQueryService, CallRepository, CallRtcClient, CallService, RecordingStorage,
@@ -858,6 +859,20 @@ impl<
Ok(new_value)
}
+
+ #[tracing::instrument(err, skip(self, request, user_id), fields(num_call_ids = request.call_ids.len()))]
+ async fn get_batch_call_record_previews<'a>(
+ &self,
+ request: GetBatchCallRecordPreviewRequest,
+ user_id: MacroUserIdStr<'a>,
+ ) -> Result<GetBatchCallRecordPreviewResponse, CallError> {
+ let previews = self
+ .repo
+ .batch_get_call_record_previews(&request.call_ids, user_id)
+ .await
+ .map_err(|e| CallError::Internal(e.into()))?;
+ Ok(GetBatchCallRecordPreviewResponse { previews })
+ }
}
/// Extract the recording key from a full S3 URL.
diff --git a/rust/cloud-storage/call/src/inbound/axum_router.rs b/rust/cloud-storage/call/src/inbound/axum_router.rs
index 744cb21e03..417ad7450f 100644
--- a/rust/cloud-storage/call/src/inbound/axum_router.rs
+++ b/rust/cloud-storage/call/src/inbound/axum_router.rs
@@ -33,7 +33,8 @@ use uuid::Uuid;
use crate::domain::models::{
CallActiveResponse, CallError, CallRecord, CallTokenResponse, EditCallRecordRequest,
- LeaveCallResponse, TranscriptSegmentRequest,
+ GetBatchCallRecordPreviewRequest, GetBatchCallRecordPreviewResponse, LeaveCallResponse,
+ MAX_BATCH_CALL_IDS, TranscriptSegmentRequest,
};
use crate::domain::ports::CallService;
@@ -82,6 +83,7 @@ impl<S, Svc> FromRef<CallRouterState<S, Svc>> for Arc<Svc> {
/// - `PATCH /record/{call_id}` — edit a call record (e.g. share permissions)
/// - `DELETE /record/{call_id}` — delete a call record
/// - `POST /record/{call_id}/share-with-team/toggle` — flip the call's share_with_team flag
+/// - `POST /record/preview` — batch-fetch lightweight previews for many call ids
pub fn call_router<S, Svc, T>(state: CallRouterState<S, Svc>) -> Router<T>
where
S: CallService,
@@ -97,6 +99,10 @@ where
"/{channel_id}/active",
get(check_active_call_handler::<S, Svc>),
)
+ .route(
+ "/record/preview",
+ post(get_batch_call_record_preview_handler::<S, Svc>),
+ )
.route(
"/record/{call_id}",
get(get_call_record_handler::<S, Svc>)
@@ -421,6 +427,43 @@ pub async fn toggle_share_with_team_handler<S: CallService, Svc: EntityAccessSer
Ok(Json(new_value))
}
+/// Handler for `POST /call/record/preview`.
+///
+/// Batch-fetches lightweight previews for a list of call ids. Mirrors the
+/// `POST /documents/preview` endpoint: no per-id access checks, duplicate
+/// ids are deduplicated server-side, and missing ids come back as
+/// `CallRecordPreview::DoesNotExist` rather than producing an error.
+#[utoipa::path(
+ post,
+ operation_id = "get_batch_call_record_preview",
+ path = "/call/record/preview",
+ request_body = GetBatchCallRecordPreviewRequest,
+ responses(
+ (status = 200, body = GetBatchCallRecordPreviewResponse),
+ (status = 400, body = ErrorResponse, description = "call_ids exceeds MAX_BATCH_CALL_IDS"),
+ (status = 401, body = ErrorResponse),
+ (status = 500, body = ErrorResponse),
+ )
+)]
+#[tracing::instrument(err, skip_all)]
+pub async fn get_batch_call_record_preview_handler<S: CallService, Svc: EntityAccessService>(
+ State(state): State<CallRouterState<S, Svc>>,
+ user: MacroUserExtractor,
+ Json(request): Json<GetBatchCallRecordPreviewRequest>,
+) -> Result<Json<GetBatchCallRecordPreviewResponse>, CallError> {
+ if request.call_ids.len() > MAX_BATCH_CALL_IDS {
+ return Err(CallError::InvalidRequest(format!(
+ "call_ids exceeds maximum batch size of {MAX_BATCH_CALL_IDS}"
+ )));
+ }
+
+ let response = state
+ .service
+ .get_batch_call_record_previews(request, user.macro_user_id)
+ .await?;
+ Ok(Json(response))
+}
+
/// Handler for `DELETE /call/{channel_id}`.
#[utoipa::path(
delete,
@@ -532,6 +575,7 @@ impl IntoResponse for CallError {
CallError::NotInCall => StatusCode::BAD_REQUEST,
CallError::AlreadyInCall(_) => StatusCode::CONFLICT,
CallError::Auth => StatusCode::UNAUTHORIZED,
+ CallError::InvalidRequest(_) => StatusCode::BAD_REQUEST,
CallError::Internal(_) => {
tracing::error!(error=?self, "internal server error");
StatusCode::INTERNAL_SERVER_ERROR
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
index 4629cd4df3..0e982f2b9f 100644
--- a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs
@@ -20,7 +20,8 @@ use uuid::Uuid;
use crate::domain::channel_name::{NameLookup, display_name, resolve_channel_name};
use crate::domain::models::{
AddParticipantError, Call, CallParticipant, CallRecord, CallRecordParticipant,
- CallRecordTranscriptSegment, EditCallRecordRequest, TranscriptSegmentRequest,
+ CallRecordPreview, CallRecordPreviewData, CallRecordTranscriptSegment, EditCallRecordRequest,
+ TranscriptSegmentRequest, WithCallId,
};
use crate::domain::ports::CallRepository;
@@ -89,6 +90,112 @@ impl PgCallRepo {
pub fn new(pool: PgPool) -> Self {
Self { pool }
}
+
+ /// Batch-resolve display names for a list of channel ids from the
+ /// perspective of `viewer_user_id`. The viewer is only used to pick the
+ /// right "other person" for DM channels; it is not an authorization check.
+ ///
+ /// Channels the query can't find simply have no entry in the returned map.
+ async fn batch_resolve_channel_names<'a>(
+ &self,
+ channel_ids: &[Uuid],
+ viewer_user_id: MacroUserIdStr<'a>,
+ ) -> Result<HashMap<Uuid, String>, sqlx::Error> {
+ if channel_ids.is_empty() {
+ return Ok(HashMap::new());
+ }
+
+ let channel_info_rows = sqlx::query!(
+ r#"
+ SELECT id, name, channel_type::text as "channel_type!"
+ FROM comms_channels
+ WHERE id = ANY($1)
+ "#,
+ channel_ids,
+ )
+ .fetch_all(&self.pool)
+ .await?;
+
+ let channel_map: HashMap<Uuid, (Option<String>, String)> = channel_info_rows
+ .into_iter()
+ .map(|r| (r.id, (r.name, r.channel_type)))
+ .collect();
+
+ // Channels that need participant-derived names (DMs, unnamed privates).
+ let needs_participants: Vec<Uuid> = channel_map
+ .iter()
+ .filter(|(_, (name, ct))| {
+ ct == "direct_message"
+ || (ct == "private" && name.as_ref().is_none_or(|n| n.trim().is_empty()))
+ })
+ .map(|(id, _)| *id)
+ .collect();
+
+ let (participant_map, name_lookup) = if needs_participants.is_empty() {
+ (HashMap::new(), NameLookup::new())
+ } else {
+ let participant_rows = sqlx::query!(
+ r#"
+ SELECT channel_id, user_id
+ FROM comms_channel_participants
+ WHERE channel_id = ANY($1) AND left_at IS NULL
+ "#,
+ &needs_participants
+ )
+ .fetch_all(&self.pool)
+ .await?;
+
+ let mut part_map: HashMap<Uuid, Vec<MacroUserIdStr<'static>>> = HashMap::new();
+ let mut all_user_ids = HashSet::new();
+ for row in participant_rows {
+ let uid = MacroUserIdStr::parse_from_str(&row.user_id)
+ .expect("valid user id from db")
+ .into_owned();
+ all_user_ids.insert(row.user_id);
+ part_map.entry(row.channel_id).or_default().push(uid);
+ }
+
+ let user_id_strings: Vec<String> = all_user_ids.into_iter().collect();
+ let name_rows = sqlx::query!(
+ r#"
+ SELECT u.id as user_profile_id, mui.first_name, mui.last_name
+ FROM macro_user_info mui
+ JOIN "User" u ON mui.macro_user_id = u.macro_user_id
+ WHERE u.id = ANY($1)
+ "#,
+ &user_id_strings
+ )
+ .fetch_all(&self.pool)
+ .await?;
+
+ let lookup: NameLookup = name_rows
+ .into_iter()
+ .filter_map(|row| {
+ let name = display_name(row.first_name.as_deref(), row.last_name.as_deref())?;
+ Some((row.user_profile_id, name))
+ })
+ .collect();
+
+ (part_map, lookup)
+ };
+
+ let mut resolved: HashMap<Uuid, String> = HashMap::with_capacity(channel_map.len());
+ for (channel_id, (name, channel_type)) in &channel_map {
+ let empty = Vec::new();
+ let participants = participant_map.get(channel_id).unwrap_or(&empty);
+ let resolved_name = resolve_channel_name(
+ channel_type,
+ name.as_deref(),
+ participants,
+ channel_id,
+ viewer_user_id.copied(),
+ &name_lookup,
+ );
+ resolved.insert(*channel_id, resolved_name);
+ }
+
+ Ok(resolved)
+ }
}
impl CallRepository for PgCallRepo {
@@ -808,6 +915,95 @@ impl CallRepository for PgCallRepo {
}))
}
+ #[tracing::instrument(err, skip(self, call_ids), fields(num_call_ids = call_ids.len()))]
+ async fn batch_get_call_record_previews<'a>(
+ &self,
+ call_ids: &[Uuid],
+ user_id: MacroUserIdStr<'a>,
+ ) -> Result<Vec<CallRecordPreview>, Self::Err> {
+ if call_ids.is_empty() {
+ return Ok(Vec::new());
+ }
+
+ // Deduplicate ids while preserving first-occurrence order for the response.
+ let mut seen = HashSet::new();
+ let unique_call_ids: Vec<Uuid> = call_ids
+ .iter()
+ .copied()
+ .filter(|id| seen.insert(*id))
+ .collect();
+
+ // Single query across both `calls` (active) and `call_records` (archived).
+ // An id in both tables should be impossible; if it somehow happens the
+ // active row wins by appearing first.
+ let rows = sqlx::query!(
+ r#"
+ SELECT
+ id as "call_id!",
+ channel_id as "channel_id!",
+ created_at as "started_at!",
+ NULL::timestamptz as "ended_at"
+ FROM calls
+ WHERE id = ANY($1)
+ UNION ALL
+ SELECT
+ id as "call_id!",
+ channel_id as "channel_id!",
+ started_at as "started_at!",
+ ended_at as "ended_at"
+ FROM call_records
+ WHERE id = ANY($1)
+ "#,
+ &unique_call_ids,
+ )
+ .fetch_all(&self.pool)
+ .await?;
+
+ struct Found {
+ channel_id: Uuid,
+ started_at: chrono::DateTime<Utc>,
+ ended_at: Option<chrono::DateTime<Utc>>,
+ }
+
+ let mut found: HashMap<Uuid, Found> = HashMap::with_capacity(rows.len());
+ for row in rows {
+ // If the same id ever shows up twice, keep the first (active) hit.
+ found.entry(row.call_id).or_insert(Found {
+ channel_id: row.channel_id,
+ started_at: row.started_at,
+ ended_at: row.ended_at,
+ });
+ }
+
+ let unique_channel_ids: Vec<Uuid> = {
+ let mut seen = HashSet::new();
+ found
+ .values()
+ .filter_map(|f| seen.insert(f.channel_id).then_some(f.channel_id))
+ .collect()
+ };
+
+ let channel_names = self
+ .batch_resolve_channel_names(&unique_channel_ids, user_id)
+ .await?;
+
+ let previews = unique_call_ids
+ .into_iter()
+ .map(|call_id| match found.remove(&call_id) {
+ Some(f) => CallRecordPreview::Exists(CallRecordPreviewData {
+ call_id,
+ channel_id: f.channel_id,
+ channel_name: channel_names.get(&f.channel_id).cloned(),
+ started_at: f.started_at,
+ ended_at: f.ended_at,
+ }),
+ None => CallRecordPreview::DoesNotExist(WithCallId { call_id }),
+ })
+ .collect();
+
+ Ok(previews)
+ }
+
#[tracing::instrument(err, skip(self))]
async fn get_call_records_by_user<'a>(
&self,
@@ -953,94 +1149,12 @@ impl CallRepository for PgCallRepo {
.collect()
};
- let channel_info_rows = sqlx::query!(
- r#"
- SELECT id, name, channel_type::text as "channel_type!"
- FROM comms_channels
- WHERE id = ANY($1)
- "#,
- &unique_channel_ids
- )
- .fetch_all(&self.pool)
- .await?;
-
- let channel_map: HashMap<Uuid, (Option<String>, String)> = channel_info_rows
- .into_iter()
- .map(|r| (r.id, (r.name, r.channel_type)))
- .collect();
-
- // Identify channels needing participant-based name resolution
- // (DM channels or unnamed private channels).
- let needs_participants: Vec<Uuid> = channel_map
- .iter()
- .filter(|(_, (name, ct))| {
- ct == "direct_message"
- || (ct == "private" && name.as_ref().is_none_or(|n| n.trim().is_empty()))
- })
- .map(|(id, _)| *id)
- .collect();
-
- let (participant_map, name_lookup) = if needs_participants.is_empty() {
- (HashMap::new(), NameLookup::new())
- } else {
- let participant_rows = sqlx::query!(
- r#"
- SELECT channel_id, user_id
- FROM comms_channel_participants
- WHERE channel_id = ANY($1) AND left_at IS NULL
- "#,
- &needs_participants
- )
- .fetch_all(&self.pool)
- .await?;
-
- let mut part_map: HashMap<Uuid, Vec<MacroUserIdStr<'static>>> = HashMap::new();
- let mut all_user_ids = HashSet::new();
- for row in participant_rows {
- let uid = MacroUserIdStr::parse_from_str(&row.user_id)
- .expect("valid user id from db")
- .into_owned();
- all_user_ids.insert(row.user_id);
- part_map.entry(row.channel_id).or_default().push(uid);
- }
-
- let user_id_strings: Vec<String> = all_user_ids.into_iter().collect();
- let name_rows = sqlx::query!(
- r#"
- SELECT u.id as user_profile_id, mui.first_name, mui.last_name
- FROM macro_user_info mui
- JOIN "User" u ON mui.macro_user_id = u.macro_user_id
- WHERE u.id = ANY($1)
- "#,
- &user_id_strings
- )
- .fetch_all(&self.pool)
+ let channel_names = self
+ .batch_resolve_channel_names(&unique_channel_ids, user_id.copied())
.await?;
- let lookup: NameLookup = name_rows
- .into_iter()
- .filter_map(|row| {
- let name = display_name(row.first_name.as_deref(), row.last_name.as_deref())?;
- Some((row.user_profile_id, name))
- })
- .collect();
-
- (part_map, lookup)
- };
-
for record in &mut records {
- if let Some((name, channel_type)) = channel_map.get(&record.channel_id) {
- let empty = Vec::new();
- let participants = participant_map.get(&record.channel_id).unwrap_or(&empty);
- record.channel_name = Some(resolve_channel_name(
- channel_type,
- name.as_deref(),
- participants,
- &record.channel_id,
- user_id.copied(),
- &name_lookup,
- ));
- }
+ record.channel_name = channel_names.get(&record.channel_id).cloned();
}
Ok(records)
diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs
index 3c92d310f4..cf0c298001 100644
--- a/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs
+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo/test.rs
@@ -1,6 +1,8 @@
use std::{ops::Deref, sync::Arc, sync::LazyLock};
-use crate::domain::models::{AddParticipantError, EditCallRecordRequest, TranscriptSegmentRequest};
+use crate::domain::models::{
+ AddParticipantError, CallRecordPreview, EditCallRecordRequest, TranscriptSegmentRequest,
+};
use crate::domain::ports::CallRepository;
use crate::outbound::pg_call_repo::PgCallRepo;
use chrono::Utc;
@@ -887,6 +889,100 @@ async fn get_call_record_returns_none_for_unknown(pool: Pool<Postgres>) -> anyho
Ok(())
}
+// -- batch_get_call_record_previews -------------------------------------------
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn batch_get_call_record_previews_mixes_active_archived_and_missing(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool);
+ let missing = Uuid::now_v7();
+
+ let previews = repo
+ .batch_get_call_record_previews(&[CALL1, CALL_ARCHIVED, missing], USER_A.deref().copied())
+ .await?;
+
+ assert_eq!(previews.len(), 3);
+
+ // Active call comes back as Exists with ended_at = None.
+ match &previews[0] {
+ CallRecordPreview::Exists(data) => {
+ assert_eq!(data.call_id, CALL1);
+ assert_eq!(data.channel_id, CH1);
+ assert_eq!(data.channel_name.as_deref(), Some("call-test-channel"));
+ assert!(data.ended_at.is_none());
+ }
+ other => panic!("expected Exists for active call, got {other:?}"),
+ }
+
+ // Archived call comes back as Exists with ended_at populated.
+ match &previews[1] {
+ CallRecordPreview::Exists(data) => {
+ assert_eq!(data.call_id, CALL_ARCHIVED);
+ assert_eq!(data.channel_id, CH1);
+ assert!(data.ended_at.is_some());
+ }
+ other => panic!("expected Exists for archived call, got {other:?}"),
+ }
+
+ // Missing id comes back as DoesNotExist.
+ match &previews[2] {
+ CallRecordPreview::DoesNotExist(w) => assert_eq!(w.call_id, missing),
+ other => panic!("expected DoesNotExist for missing id, got {other:?}"),
+ }
+
+ Ok(())
+}
+
+#[sqlx::test(
+ fixtures(path = "../../../fixtures", scripts("call_repo")),
+ migrator = "MACRO_DB_MIGRATIONS"
+)]
+async fn batch_get_call_record_previews_deduplicates_input(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool);
+
+ // Four inputs but only two distinct ids; response should have exactly two.
+ let previews = repo
+ .batch_get_call_record_previews(
+ &[CALL1, CALL1, CALL_ARCHIVED, CALL1],
+ USER_A.deref().copied(),
+ )
+ .await?;
+
+ assert_eq!(previews.len(), 2, "duplicates should be collapsed");
+
+ let ids: Vec<Uuid> = previews
+ .iter()
+ .map(|p| match p {
+ CallRecordPreview::Exists(d) => d.call_id,
+ CallRecordPreview::DoesNotExist(w) => w.call_id,
+ })
+ .collect();
+ assert_eq!(
+ ids,
+ vec![CALL1, CALL_ARCHIVED],
+ "first-occurrence order must be preserved"
+ );
+ Ok(())
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn batch_get_call_record_previews_empty_input_returns_empty(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let repo = repo(pool);
+ let previews = repo
+ .batch_get_call_record_previews(&[], USER_A.deref().copied())
+ .await?;
+ assert!(previews.is_empty());
+ Ok(())
+}
+
#[sqlx::test(
fixtures(path = "../../../fixtures", scripts("call_repo")),
migrator = "MACRO_DB_MIGRATIONS"
diff --git a/rust/cloud-storage/document_storage_service/src/api/swagger.rs b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
index 50535e2f18..0f8dc94767 100644
--- a/rust/cloud-storage/document_storage_service/src/api/swagger.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
@@ -200,6 +200,7 @@ use utoipa::OpenApi;
call::inbound::axum_router::edit_call_record_handler,
call::inbound::axum_router::delete_call_record_handler,
call::inbound::axum_router::toggle_share_with_team_handler,
+ call::inbound::axum_router::get_batch_call_record_preview_handler,
call::inbound::axum_router::webhook_handler,
call::inbound::axum_router::transcript_handler,
@@ -350,6 +351,11 @@ use utoipa::OpenApi;
call::domain::models::CallRecordParticipant,
call::domain::models::CallRecordTranscriptSegment,
call::domain::models::EditCallRecordRequest,
+ call::domain::models::CallRecordPreview,
+ call::domain::models::CallRecordPreviewData,
+ call::domain::models::WithCallId,
+ call::domain::models::GetBatchCallRecordPreviewRequest,
+ call::domain::models::GetBatchCallRecordPreviewResponse,
SoupCallRecord,
SoupCallRecordParticipant,