File size: 1,609 Bytes
488d96b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/** One admitted image and one authored failure for the Python SDK event snapshot. */

/** Cordis fixture identity. */
export const name = 'python-snapshot-image-offload'

/** Admission and request hooks supplied by the shipped SDK profile. */
export const inject = ['attachments', 'agents', 'llm']

/**
 * @param {import('@deepseek-ai/cordis').Context} ctx - Scenario-local host context.
 * @param {{ parentSessionId: string }} config - The one session receiving the authored failure.
 */
export function apply(ctx, config) {
  let injected = false
  let failed = false
  ctx.on('agent/pre-step', async ({ agent }, next) => {
    const decision = await next()
    if (agent.id !== config.parentSessionId || injected || decision.kind === 'reject') return decision
    const content = await ctx.attachments.admitPromptContent([{
      type: 'image',
      mediaType: 'image/png',
      data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC',
    }])
    injected = true
    return {
      ...decision,
      messages: [...decision.messages, { id: 'python-snapshot-image', role: 'user', content, source: { kind: 'plugin', plugin: name } }],
    }
  })
  ctx.on('llm/stream', async function* (options, next) {
    if (options.sessionId !== config.parentSessionId || options.purpose !== undefined || failed) {
      yield* next()
      return
    }
    failed = true
    yield {
      type: 'finish',
      reason: { kind: 'error', failure: {
        code: 'IMAGE_OFFLOAD_REQUIRED', message: 'authored image budget failure', offloadImages: 1,
      } },
    }
  })
}