@gravityai-dev/output
v1.0.20
Published
Output nodes for GravityWorkflow - UI rendering components
Maintainers
Readme
QuestionOutput Publishing Updates
This document outlines the updates made to the QuestionOutput package to align with the modern TextOutput publishing pattern.
Overview
The QuestionOutput package has been updated to use the unified Redis Streams publishing infrastructure, moving away from the legacy Redis publisher pattern to match TextOutput's implementation.
Changes Made
1. Updated service/publishQuestions.ts
Before:
- Used
getQuestionsPublisher()from@gravityai-dev/gravity-server - Complex Redis configuration with multiple parameters
- Published to various channels based on configuration
After:
- Uses
getRedisClient()from shared platform utilities - Uses
buildOutputEvent()andOUTPUT_CHANNELfrom shared publisher - Publishes to unified
workflow:events:streamusing Redis Streams
// New implementation
const event = buildOutputEvent({
eventType: "questions",
chatId: config.chatId,
conversationId: config.conversationId,
userId: config.userId,
providerId: config.providerId,
data: {
questions: config.questions,
metadata: {
...config.metadata,
workflowId: config.workflowId,
workflowRunId: config.workflowRunId,
},
},
});
await redis.xadd(
"workflow:events:stream",
"*",
"conversationId", conversationId,
"channel", OUTPUT_CHANNEL,
"message", JSON.stringify(event)
);2. Updated node/executor.ts
Changes:
- Removed
AI_RESULT_CHANNELimport (no longer needed) - Simplified
publishQuestions()call by removing channel fallback - The service now handles channel routing internally
Before:
import { AI_RESULT_CHANNEL } from "@gravityai-dev/gravity-server";
const result = await publishQuestions({
// ...
redisChannel: config.redisChannel || AI_RESULT_CHANNEL,
// ...
});After:
const result = await publishQuestions({
// ...
redisChannel: config.redisChannel,
// ...
});3. Files Not Changed
node/index.ts- Still importsAI_RESULT_CHANNELfor UI dropdown options (correct)util/files - No publishing dependencies, only types and validation
Benefits
- Unified Event Structure: All output events now use the same
GravityEventformat - Reliable Delivery: Redis Streams provide better reliability than Pub/Sub
- Consistent Architecture: Matches TextOutput and other modern output nodes
- Simplified Dependencies: Removed complex legacy publisher dependencies
Event Structure
Questions are now published as:
{
id: "uuid",
timestamp: "2025-01-12T17:03:11.000Z",
providerId: "gravity-services",
chatId: "chat-123",
conversationId: "conv-456",
userId: "user-789",
__typename: "GravityEvent",
type: "GRAVITY_EVENT",
eventType: "questions",
data: {
questions: ["Question 1?", "Question 2?"],
metadata: {
workflowId: "workflow-123",
workflowRunId: "run-456",
// ... other metadata
}
}
}Migration Pattern
This same pattern can be applied to other output nodes:
- Replace legacy publisher with
getRedisClient()from shared platform - Use
buildOutputEvent()with appropriateeventType - Publish to Redis Streams using
workflow:events:stream - Use
OUTPUT_CHANNELfor consistent routing - Remove legacy imports from executors
Files Updated
- ✅
service/publishQuestions.ts- Complete rewrite using shared utilities - ✅
node/executor.ts- Removed legacy imports and simplified calls - ✅
node/index.ts- No changes needed (UI configuration only) - ✅
util/files - No changes needed (no publishing logic)
Testing
After these changes, questions should:
- Publish successfully to the unified event stream
- Appear in the UI with the same functionality
- Include all required metadata for proper routing
- Use reliable Redis Streams delivery
Next Steps
Consider applying this same publishing pattern to other output nodes in the package for consistency across the entire output system.
