Skip to content

Commit f2e5f0f

Browse files
committed
addressmore comments
1 parent 741d755 commit f2e5f0f

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

strands-ts/src/vended-plugins/context-offloader/__tests__/plugin.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ContextOffloader } from '../plugin.js'
33
import { InMemoryStorage } from '../storage.js'
44
import { AfterToolCallEvent } from '../../../hooks/events.js'
55
import { TextBlock, JsonBlock, ToolResultBlock } from '../../../types/messages.js'
6-
import { ImageBlock, DocumentBlock } from '../../../types/media.js'
6+
import { ImageBlock, VideoBlock, DocumentBlock } from '../../../types/media.js'
77
import { createMockAgent, invokeTrackedHook } from '../../../__fixtures__/agent-helpers.js'
88
import { MockMessageModel } from '../../../__fixtures__/mock-message-model.js'
99

@@ -14,7 +14,9 @@ function makeMockAgent() {
1414
}
1515

1616
function makeEvent(
17-
content: InstanceType<typeof TextBlock | typeof JsonBlock | typeof ImageBlock | typeof DocumentBlock>[],
17+
content: InstanceType<
18+
typeof TextBlock | typeof JsonBlock | typeof ImageBlock | typeof VideoBlock | typeof DocumentBlock
19+
>[],
1820
overrides?: { status?: 'success' | 'error'; toolName?: string }
1921
) {
2022
const agent = makeMockAgent()
@@ -312,6 +314,21 @@ describe('ContextOffloader', () => {
312314
expect((result as ImageBlock).format).toBe('png')
313315
})
314316

317+
it('retrieves video content as VideoBlock', async () => {
318+
const storage = new InMemoryStorage()
319+
const vidBytes = new Uint8Array([0x00, 0x00, 0x00, 0x1c])
320+
const ref = await storage.store('k1', vidBytes, 'video/mp4')
321+
322+
const plugin = new ContextOffloader({ storage, includeRetrievalTool: true })
323+
const tools = plugin.getTools()
324+
const retrievalTool = tools[0]!
325+
const result = await (retrievalTool as unknown as { invoke(input: unknown): Promise<unknown> }).invoke({
326+
reference: ref,
327+
})
328+
expect(result).toBeInstanceOf(VideoBlock)
329+
expect((result as VideoBlock).format).toBe('mp4')
330+
})
331+
315332
it('retrieves document content as DocumentBlock', async () => {
316333
const storage = new InMemoryStorage()
317334
const docBytes = new Uint8Array([0x25, 0x50, 0x44, 0x46])

strands-ts/src/vended-plugins/context-offloader/plugin.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AfterToolCallEvent } from '../../hooks/events.js'
66
import { TextBlock, JsonBlock, ToolResultBlock, Message } from '../../types/messages.js'
77
import type { ToolResultContent } from '../../types/messages.js'
88
import { ImageBlock, VideoBlock, DocumentBlock } from '../../types/media.js'
9+
import type { ImageFormat, VideoFormat, DocumentFormat } from '../../types/media.js'
910
import { tool } from '../../tools/tool-factory.js'
1011
import { z } from 'zod'
1112
import { logger } from '../../logging/logger.js'
@@ -55,21 +56,21 @@ function decodeStoredContent(content: Uint8Array, contentType: string, reference
5556
if (contentType.startsWith('image/')) {
5657
const format = contentType.split('/').pop()!
5758
return new ImageBlock({
58-
format: format as import('../../types/media.js').ImageFormat,
59+
format: format as ImageFormat,
5960
source: { bytes: content },
6061
}) as unknown as JSONValue
6162
}
6263
if (contentType.startsWith('video/')) {
6364
const format = contentType.split('/').pop()!
6465
return new VideoBlock({
65-
format: format as import('../../types/media.js').VideoFormat,
66+
format: format as VideoFormat,
6667
source: { bytes: content },
6768
}) as unknown as JSONValue
6869
}
6970
if (contentType.startsWith('application/')) {
7071
const format = contentType.split('/').pop()!
7172
return new DocumentBlock({
72-
format: format as import('../../types/media.js').DocumentFormat,
73+
format: format as DocumentFormat,
7374
name: reference,
7475
source: { bytes: content },
7576
}) as unknown as JSONValue
@@ -190,7 +191,7 @@ export class ContextOffloader implements Plugin {
190191
}
191192
return { ref: '', contentType, description: `${label}, 0 bytes` }
192193
}
193-
logger.warn(`Unsupported content block type encountered during offloading, skipping`)
194+
logger.warn('unsupported content block type encountered during offloading, skipping')
194195
return { ref: '', contentType: 'unknown', description: 'unknown block type' }
195196
}
196197

0 commit comments

Comments
 (0)