| 20 | ]) |
| 21 | |
| 22 | function createRuntimeContextAdapter(scenario: string): AnyTextAdapter { |
| 23 | return { |
| 24 | kind: 'text', |
| 25 | name: 'runtime-context-test', |
| 26 | model: 'runtime-context-test', |
| 27 | '~types': { |
| 28 | providerOptions: {}, |
| 29 | inputModalities: ['text'], |
| 30 | messageMetadataByModality: {}, |
| 31 | toolCapabilities: [], |
| 32 | toolCallMetadata: undefined, |
| 33 | systemPromptMetadata: undefined, |
| 34 | }, |
| 35 | async *chatStream(options): AsyncGenerator<StreamChunk> { |
| 36 | const model = 'runtime-context-test' |
| 37 | const runId = options.runId ?? 'runtime-context-run' |
| 38 | const threadId = options.threadId ?? 'runtime-context-thread' |
| 39 | const messageId = `${runId}-message` |
| 40 | const hasToolResult = options.messages.some( |
| 41 | (message) => message.role === 'tool', |
| 42 | ) |
| 43 | |
| 44 | yield { |
| 45 | type: EventType.RUN_STARTED, |
| 46 | runId, |
| 47 | threadId, |
| 48 | model, |
| 49 | timestamp: Date.now(), |
| 50 | } |
| 51 | |
| 52 | if (!hasToolResult) { |
| 53 | const toolName = |
| 54 | scenario === 'client-context' |
| 55 | ? 'read_client_context' |
| 56 | : 'read_server_context' |
| 57 | const toolCallId = `${scenario}-tool-call` |
| 58 | |
| 59 | yield { |
| 60 | type: EventType.TEXT_MESSAGE_START, |
| 61 | messageId, |
| 62 | role: 'assistant', |
| 63 | model, |
| 64 | timestamp: Date.now(), |
| 65 | } |
| 66 | yield { |
| 67 | type: EventType.TEXT_MESSAGE_CONTENT, |
| 68 | messageId, |
| 69 | delta: 'Reading runtime context.', |
| 70 | model, |
| 71 | timestamp: Date.now(), |
| 72 | } |
| 73 | yield { |
| 74 | type: EventType.TEXT_MESSAGE_END, |
| 75 | messageId, |
| 76 | model, |
| 77 | timestamp: Date.now(), |
| 78 | } |
| 79 | yield { |