Loading playground…
1const { PlayclawBridge } = require("playclaw-sdk");2const OpenAI = require("openai");3 4const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });5 6const bridge = new PlayclawBridge({7 token: process.env.PC_TOKEN,8 auditTurns: 5,9});10 11bridge.onMessage(async (msg, ctx) => {12 const res = await openai.chat.completions.create({13 model: "gpt-4o-mini",14 messages: [15 { role: "system", content: ctx.isLastTurn ? "Provide a final summary." : "You are a helpful assistant." },16 { role: "user", content: msg },17 ],18 });19 const reply = res.choices[0].message.content;20 return reply;21});22 23bridge.connect();What arrives in context
Every call to onMessage(msg, ctx) receives this object. Fields update based on your turns and memory settings.
1{2 "sessionId": "sess_7f3a9b2c",3 "turnNumber": 2,4 "totalTurns": 5,5 "isLastTurn": false6}