Upgrade an Existing TypeScript SDK Integration to Log System Prompts
You are a coding agent tasked with updating our existing TypeScript SDK integration with the Greenflash Messages API so that it correctly logs system prompts for prompt optimization & management. We already have a working integration but are not currently submitting any system prompts alongside messages. Your goal is to enhance our integration so that Greenflash can automatically version, analyze, and optimize system prompts based on real conversation data.High-Level Objective
Refactor or extend the existing implementation to:- Include system prompts when logging conversations
- Support both simple string prompts and structured
promptComponents - Ensure dynamic and variable content in complex prompts is logged properly
- Use the correct TypeScript SDK syntax
- Determine the right logging pattern (batch vs individual calls) based on how the existing code is written
Logging System Prompts: Two Valid Formats
Greenflash supports two ways to include a system prompt when logging a conversation. You must choose between them based on the complexity of the prompt being submitted.Option A: Simple String Prompt
Use this when the system prompt is a single static string.- Easy to implement
- Automatically gets tracked & versioned
- Good for most use cases
- Cannot express structured or dynamic prompts
- Less granular optimization
Option B: Structured Prompt with promptComponents
Use this when the prompt includes multiple pieces, variables, dynamic slots, templates, or RAG context elements. A structured prompt lets you segment instructions into named components, version them independently, and optimize at the component level.externalTemplateIdgroups all versions of this prompt under a single lineage. Use a stable, human-readable identifier (e.g.,"customer-support-agent"). Without this, each unique prompt creates a separate lineage.- Valid component
typevalues:system,user,tool,guardrail,rag,agent,other. Each component can also have asource:customer(default),participant,greenflash, oragent. - Use
isDynamic: truefor parts of the prompt that vary per conversation (e.g., retrieved context, dynamic instructions) - Use
variableson the systemPrompt object to pass template variable values (e.g.,{{companyName}})
- Modular prompt structure
- Component-level optimization
- Variable interpolation
- Dynamic content slots for RAG or agent outputs
Fire-and-Forget Logging
For logging, you typically don’t want to block your LLM response while waiting for the Greenflash API call to complete. Use fire-and-forget by not awaiting the promise:
Note: The .catch() is recommended to prevent unhandled promise rejections from crashing your app, but the logging call runs in the background without blocking your response.
Detecting the Right Pattern
Inspect the existing codebase and choose the pattern that minimally disrupts current logic:- If prompts are static strings and there is no variable logic or dynamic content, use Simple String Format
- If prompts are assembled from pieces, templates, or dynamic slots, use Structured Prompt with Components
- If code emits prompt text dynamically as it runs, wrap that logic into structured components with
isDynamic: truewhere needed
Logging Messages with Prompts
After adding the system prompt, the rest of the messages follow the existing logging pattern:- You may send all messages in a batch if they are known at the end of execution
- Or you may log messages incrementally as they happen (e.g., streaming)
- Use
client.messages.create(...)for each call when logging incrementally - For batch mode, send a single call with
systemPromptand message array
TypeScript SDK Integration Checklist
Your code should:- Initialize the TypeScript SDK with our API key
- Construct
systemPrompt:- As a simple string, or
- As a structured object with
promptComponents
- Include
systemPrompton everymessages.create(...)call - Respect dynamic variables using
variableson the systemPrompt object if structured prompts have templates - Choose batching vs streaming appropriately
- Preserve existing logging semantics for message bodies
- Use fire-and-forget pattern (no
await) with.catch()to avoid blocking LLM responses
Tips
- String prompts are great to start with and will get metrics and analytics immediately
- Structured prompts unlock component-level optimization and versioning
- Dynamic components (
isDynamic: true) allow RAG and other runtime context to be logged correctly - Interpolated variables let you keep templates generic while capturing personalized conversation data
Summary of What to Deliver
- Updated TypeScript SDK integration that logs system prompts
- Support for both simple string prompts and structured prompt components
- Logic to choose the right pattern
- Ensure dynamic data and variables are logged properly
- No disruption to existing message logging behavior

