-
Notifications
You must be signed in to change notification settings - Fork 1
feat(vs-agent): add the receipts module to the v2 didcomm api #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e50a101
feat(vs-agent): add the receipts module to the v2 didcomm api
tarunvadde baddbd3
fix(vs-agent): send receipts through the module api
tarunvadde 3225f8a
Merge branch 'main' into feat/659-receipts-module
tarunvadde 5a9d30e
Merge remote-tracking branch 'origin/main' into feat/659-receipts-module
tarunvadde 9b3f90a
Merge remote-tracking branch 'origin/main' into feat/659-receipts-module
tarunvadde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
apps/vs-agent/src/controllers/admin/v2/didcomm/V2DidcommReceiptsController.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { ChatAgentModules } from '@verana-labs/vs-agent-plugin-chat' | ||
| import type { VsAgent } from '@verana-labs/vs-agent-sdk' | ||
|
|
||
| import { Body, Controller, HttpStatus, Inject, Post, UsePipes, ValidationPipe } from '@nestjs/common' | ||
| import { ApiCreatedResponse, ApiNotFoundResponse, ApiOperation, ApiTags } from '@nestjs/swagger' | ||
|
|
||
| import { AdminApiError, AdminApiErrorCode, unknownConnection } from '../../../../common' | ||
| import { VsAgentService } from '../../../../services/VsAgentService' | ||
|
|
||
| import { SendReceiptsBodyDto, SendReceiptsResponseDto } from './dto' | ||
|
|
||
| /** | ||
| * The module stores no record, so there is no list or get method: an inbound `message-receipts` | ||
| * message reaches the caller as an event. | ||
| */ | ||
| @ApiTags('v2/didcomm') | ||
| @Controller({ path: 'didcomm/receipts', version: '2' }) | ||
| export class V2DidcommReceiptsController { | ||
| public constructor(@Inject(VsAgentService) private readonly vsAgentService: VsAgentService) {} | ||
|
|
||
| @Post() | ||
| @UsePipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true })) | ||
| @ApiOperation({ | ||
| summary: 'Send message receipts', | ||
| description: 'Sends message receipts on an established connection.', | ||
| }) | ||
| @ApiCreatedResponse({ description: 'The sent message', type: SendReceiptsResponseDto }) | ||
| @ApiNotFoundResponse({ description: 'No connection with the given id' }) | ||
| public async sendReceipts(@Body() body: SendReceiptsBodyDto): Promise<SendReceiptsResponseDto> { | ||
| const agent = await this.vsAgentService.getAgent() | ||
| const { modules } = agent as unknown as VsAgent<ChatAgentModules> | ||
|
|
||
| if (!('receipts' in modules)) { | ||
| throw new AdminApiError( | ||
| AdminApiErrorCode.UnknownId, | ||
| HttpStatus.NOT_FOUND, | ||
| 'this deployment does not serve the receipts module', | ||
| ) | ||
| } | ||
|
|
||
| const connection = await agent.didcomm.connections.findById(body.connectionId) | ||
| if (!connection) throw unknownConnection(body.connectionId) | ||
|
|
||
| const { messageId } = await modules.receipts.send({ | ||
| connectionId: body.connectionId, | ||
| receipts: body.receipts.map(receipt => ({ | ||
| messageId: receipt.messageId, | ||
| state: receipt.state, | ||
| timestamp: receipt.timestamp ? new Date(receipt.timestamp) : undefined, | ||
| })), | ||
| }) | ||
|
|
||
| return { id: messageId } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
apps/vs-agent/src/controllers/admin/v2/didcomm/dto/receipts.dto.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' | ||
| import { Type } from 'class-transformer' | ||
| import { | ||
| ArrayNotEmpty, | ||
| IsArray, | ||
| IsEnum, | ||
| IsISO8601, | ||
| IsNotEmpty, | ||
| IsOptional, | ||
| IsString, | ||
| ValidateNested, | ||
| } from 'class-validator' | ||
|
|
||
| export enum MessageState { | ||
| Created = 'created', | ||
| Submitted = 'submitted', | ||
| Received = 'received', | ||
| Viewed = 'viewed', | ||
| Deleted = 'deleted', | ||
| } | ||
|
|
||
| /** | ||
| * One entry of [VSA-ADM-DC-RC-SEND] sendReceipts. | ||
| */ | ||
| export class MessageReceiptDto { | ||
| @ApiProperty({ description: 'Identifier of the message the receipt refers to', example: 'msg-1234' }) | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| messageId!: string | ||
|
|
||
| @ApiProperty({ enum: MessageState, description: 'State reported for the message' }) | ||
| @IsEnum(MessageState) | ||
| state!: MessageState | ||
|
|
||
| @ApiPropertyOptional({ description: 'When the state was reached', example: '2026-09-07T12:00:00.000Z' }) | ||
| @IsOptional() | ||
| @IsISO8601() | ||
| timestamp?: string | ||
| } | ||
|
|
||
| /** | ||
| * Body of [VSA-ADM-DC-RC-SEND] sendReceipts. | ||
| */ | ||
| export class SendReceiptsBodyDto { | ||
| @ApiProperty({ description: 'Connection to send the receipts on', example: 'conn-1234-5678' }) | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| connectionId!: string | ||
|
|
||
| @ApiProperty({ type: [MessageReceiptDto], description: 'The receipts to send' }) | ||
| @IsArray() | ||
| @ArrayNotEmpty() | ||
| @ValidateNested({ each: true }) | ||
| @Type(() => MessageReceiptDto) | ||
| receipts!: MessageReceiptDto[] | ||
| } | ||
|
|
||
| /** | ||
| * Response of [VSA-ADM-DC-RC-SEND] sendReceipts. | ||
| */ | ||
| export class SendReceiptsResponseDto { | ||
| @ApiProperty({ | ||
| description: 'Identifier of the sent message', | ||
| example: 'a1b2c3d4-5678-90ab-cdef-1234567890ab', | ||
| }) | ||
| id!: string | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { plainToInstance } from 'class-transformer' | ||
| import { validateSync } from 'class-validator' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { SendReceiptsBodyDto } from '../src/controllers/admin/v2/didcomm/dto' | ||
|
|
||
| const check = (body: unknown) => | ||
| validateSync(plainToInstance(SendReceiptsBodyDto, body), { | ||
| whitelist: true, | ||
| forbidNonWhitelisted: true, | ||
| }) | ||
|
|
||
| describe('sendReceipts body validation', () => { | ||
| it('accepts a valid body', () => { | ||
| expect( | ||
| check({ | ||
| connectionId: 'conn-1', | ||
| receipts: [{ messageId: 'm1', state: 'viewed', timestamp: '2026-09-07T12:00:00.000Z' }], | ||
| }), | ||
| ).toHaveLength(0) | ||
| }) | ||
|
|
||
| it('refuses every shape the spec forbids', () => { | ||
| expect(check({ receipts: [{ messageId: 'm', state: 'viewed' }] }).length).toBeGreaterThan(0) | ||
| expect(check({ connectionId: 'c' }).length).toBeGreaterThan(0) | ||
| expect(check({ connectionId: 'c', receipts: [] }).length).toBeGreaterThan(0) | ||
| expect( | ||
| check({ connectionId: 'c', receipts: [{ messageId: 'm', state: 'nonsense' }] }).length, | ||
| ).toBeGreaterThan(0) | ||
| expect(check({ connectionId: 'c', receipts: [{ state: 'viewed' }] }).length).toBeGreaterThan(0) | ||
| expect( | ||
| check({ connectionId: 'c', receipts: [{ messageId: 'm', state: 'viewed', timestamp: 'nope' }] }).length, | ||
| ).toBeGreaterThan(0) | ||
| expect( | ||
| check({ connectionId: 'c', receipts: [{ messageId: 'm', state: 'viewed' }], extra: 1 }).length, | ||
| ).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it('accepts every state the spec names', () => { | ||
| for (const state of ['created', 'submitted', 'received', 'viewed', 'deleted']) { | ||
| expect(check({ connectionId: 'c', receipts: [{ messageId: 'm', state }] })).toHaveLength(0) | ||
| } | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --- a/build/index.mjs | ||
| +++ b/build/index.mjs | ||
| @@ -177,6 +177,7 @@ | ||
| agentContext: this.agentContext, | ||
| connection | ||
| })); | ||
| + return { messageId: message.id }; | ||
| } | ||
| async request(options) { | ||
| const connection = await this.connectionService.findById(this.agentContext, options.connectionId); | ||
| @@ -186,6 +187,7 @@ | ||
| agentContext: this.agentContext, | ||
| connection | ||
| })); | ||
| + return { messageId: message.id }; | ||
| } | ||
| }; | ||
| DidCommReceiptsApi = __decorate([injectable(), __decorateMetadata("design:paramtypes", [ | ||
| --- a/build/index.d.mts | ||
| +++ b/build/index.d.mts | ||
| @@ -94,11 +94,11 @@ | ||
| send(options: { | ||
| connectionId: string; | ||
| receipts: DidCommMessageReceiptOptions[]; | ||
| - }): Promise<void>; | ||
| + }): Promise<{ messageId: string; }>; | ||
| request(options: { | ||
| connectionId: string; | ||
| requestedReceipts: DidCommRequestedReceiptOptions[]; | ||
| - }): Promise<void>; | ||
| + }): Promise<{ messageId: string; }>; | ||
| } | ||
| //#endregion | ||
| //#region src/DidCommReceiptsModule.d.ts |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review the
listProtocolsrequirement, as it has not been implemented yet and is explicitly required by the issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left out on purpose, it does not exist yet. #666 carries the same task for seven more modules, so building it here would mean a hardcoded list that #666 rewrites. Raised it as #683.