1
0

python-snapshot-image-offload.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /** One admitted image and one authored failure for the Python SDK event snapshot. */
  2. /** Cordis fixture identity. */
  3. export const name = 'python-snapshot-image-offload'
  4. /** Admission and request hooks supplied by the shipped SDK profile. */
  5. export const inject = ['attachments', 'agents', 'llm']
  6. /**
  7. * @param {import('@deepseek-ai/cordis').Context} ctx - Scenario-local host context.
  8. * @param {{ parentSessionId: string }} config - The one session receiving the authored failure.
  9. */
  10. export function apply(ctx, config) {
  11. let injected = false
  12. let failed = false
  13. ctx.on('agent/pre-step', async ({ agent }, next) => {
  14. const decision = await next()
  15. if (agent.id !== config.parentSessionId || injected || decision.kind === 'reject') return decision
  16. const content = await ctx.attachments.admitPromptContent([{
  17. type: 'image',
  18. mediaType: 'image/png',
  19. data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC',
  20. }])
  21. injected = true
  22. return {
  23. ...decision,
  24. messages: [...decision.messages, { id: 'python-snapshot-image', role: 'user', content, source: { kind: 'plugin', plugin: name } }],
  25. }
  26. })
  27. ctx.on('llm/stream', async function* (options, next) {
  28. if (options.sessionId !== config.parentSessionId || options.purpose !== undefined || failed) {
  29. yield* next()
  30. return
  31. }
  32. failed = true
  33. yield {
  34. type: 'finish',
  35. reason: { kind: 'error', failure: {
  36. code: 'IMAGE_OFFLOAD_REQUIRED', message: 'authored image budget failure', offloadImages: 1,
  37. } },
  38. }
  39. })
  40. }