6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
139 lines
4.4 KiB
TypeScript
139 lines
4.4 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
AGENT_STREAM_PROTOCOL_HEADER,
|
|
AGENT_STREAM_PROTOCOL_V1,
|
|
clientAcceptsAgentStreamProtocol,
|
|
hasAgentStreamPolicy,
|
|
isChatChunkFrame,
|
|
isChatChunkResetFrame,
|
|
isChatToolFrame,
|
|
shouldEmitAgentStreamEvents,
|
|
} from '@/lib/workflows/streaming/agent-stream-protocol'
|
|
|
|
function headers(init?: Record<string, string>): Headers {
|
|
return new Headers(init)
|
|
}
|
|
|
|
describe('clientAcceptsAgentStreamProtocol', () => {
|
|
it('depends on the header alone, never on a policy', () => {
|
|
expect(
|
|
clientAcceptsAgentStreamProtocol(
|
|
headers({ [AGENT_STREAM_PROTOCOL_HEADER]: AGENT_STREAM_PROTOCOL_V1 })
|
|
)
|
|
).toBe(true)
|
|
expect(
|
|
clientAcceptsAgentStreamProtocol(headers({ [AGENT_STREAM_PROTOCOL_HEADER]: ' V1 ' }))
|
|
).toBe(false)
|
|
expect(clientAcceptsAgentStreamProtocol(headers())).toBe(false)
|
|
})
|
|
|
|
it('tolerates casing and comma lists from proxies', () => {
|
|
expect(
|
|
clientAcceptsAgentStreamProtocol(
|
|
headers({ [AGENT_STREAM_PROTOCOL_HEADER]: ' Agent-Events-V1 ' })
|
|
)
|
|
).toBe(true)
|
|
expect(
|
|
clientAcceptsAgentStreamProtocol(
|
|
headers({ [AGENT_STREAM_PROTOCOL_HEADER]: 'text, agent-events-v1' })
|
|
)
|
|
).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('tool frame guard', () => {
|
|
const base = { event: 'tool', blockId: 'agent-1', phase: 'end', id: 'call_1', name: 'search' }
|
|
|
|
it('accepts every documented terminal status and a start frame without one', () => {
|
|
expect(isChatToolFrame({ ...base, phase: 'start' })).toBe(true)
|
|
for (const status of ['success', 'error', 'cancelled']) {
|
|
expect(isChatToolFrame({ ...base, status })).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('rejects an unrecognized status instead of letting it settle as success', () => {
|
|
expect(isChatToolFrame({ ...base, status: 'timeout' })).toBe(false)
|
|
expect(isChatToolFrame({ ...base, status: 42 })).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('chunk_reset frame guard', () => {
|
|
it('identifies reset frames and keeps them out of the chunk guard', () => {
|
|
const reset = { blockId: 'agent-1', event: 'chunk_reset' }
|
|
expect(isChatChunkResetFrame(reset)).toBe(true)
|
|
// A reset must never be appended as answer text.
|
|
expect(isChatChunkFrame(reset)).toBe(false)
|
|
|
|
expect(isChatChunkResetFrame({ event: 'chunk_reset' })).toBe(false)
|
|
expect(isChatChunkResetFrame({ blockId: 'agent-1', chunk: 'text' })).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('shouldEmitAgentStreamEvents', () => {
|
|
const negotiated = () => headers({ [AGENT_STREAM_PROTOCOL_HEADER]: AGENT_STREAM_PROTOCOL_V1 })
|
|
|
|
it('is off when neither policy is set', () => {
|
|
expect(
|
|
shouldEmitAgentStreamEvents({
|
|
includeThinking: false,
|
|
includeToolCalls: false,
|
|
requestHeaders: negotiated(),
|
|
})
|
|
).toBe(false)
|
|
expect(
|
|
shouldEmitAgentStreamEvents({
|
|
includeThinking: undefined,
|
|
includeToolCalls: undefined,
|
|
requestHeaders: negotiated(),
|
|
})
|
|
).toBe(false)
|
|
})
|
|
|
|
it('is on when either policy is set on a negotiated client', () => {
|
|
expect(
|
|
shouldEmitAgentStreamEvents({
|
|
includeThinking: true,
|
|
includeToolCalls: false,
|
|
requestHeaders: negotiated(),
|
|
})
|
|
).toBe(true)
|
|
expect(
|
|
shouldEmitAgentStreamEvents({
|
|
includeThinking: false,
|
|
includeToolCalls: true,
|
|
requestHeaders: negotiated(),
|
|
})
|
|
).toBe(true)
|
|
})
|
|
|
|
/**
|
|
* Frames have no defined shape for a client that never declared a version,
|
|
* so policy alone is not enough.
|
|
*/
|
|
it('is off without the protocol header even when policy is on', () => {
|
|
expect(
|
|
shouldEmitAgentStreamEvents({
|
|
includeThinking: true,
|
|
includeToolCalls: true,
|
|
requestHeaders: headers(),
|
|
})
|
|
).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('hasAgentStreamPolicy', () => {
|
|
/**
|
|
* Surfaces where the caller sets the policy use this to reject an
|
|
* un-negotiated request instead of silently dropping the flags.
|
|
*/
|
|
it('reports the policy independently of negotiation', () => {
|
|
expect(hasAgentStreamPolicy({ includeThinking: true, includeToolCalls: false })).toBe(true)
|
|
expect(hasAgentStreamPolicy({ includeThinking: false, includeToolCalls: true })).toBe(true)
|
|
expect(hasAgentStreamPolicy({ includeThinking: false, includeToolCalls: false })).toBe(false)
|
|
expect(hasAgentStreamPolicy({ includeThinking: undefined, includeToolCalls: null })).toBe(false)
|
|
})
|
|
})
|