// Laser SDK durable workflow, complete TypeScript program // npm install @laserdata/laser-sdk tsx // Run with: npx tsx main.mts // Needs only LASER_CONNECTION_STRING. No server to start when it is set. import { setTimeout as sleep } from "node:timers/promises" import { step, workflow } from "@laserdata/laser-sdk" const ingest = step("ingest", () => "frames from sat-7") const analyze = step("analyze", async (frames: string) => { await sleep(1000) return `analyzed ${frames}` }) const report = step("report", (analysis: string) => `report on ${analysis}`) const pipeline = workflow("pipeline", async () => report(await analyze(await ingest()))) const run = await pipeline.run() console.log(JSON.stringify({ status: run.status, steps: run.completedSteps, report: run.value })) // Laser SDK long-term memory, complete TypeScript program // npm install @laserdata/laser-sdk tsx // Run with: npx tsx main.mts // Needs only LASER_CONNECTION_STRING, which connectEnv() reads. No server to start when it is set. import { ConversationId, Laser, memoryItemText } from "@laserdata/laser-sdk" const user = "user-42" const query = "Where does the user live, and what should I know before booking dinner?" await using root = await Laser.connectEnv() await using scratch = await root.scratchStream("memory") const memory = scratch.laser.memory("assistant") // Conversation 1: the user shares three facts. const first = ConversationId.new() const city = await memory.remember("Lives in Gdansk").scope(first).user(user).send() await memory.remember("Allergic to peanuts").scope(first).user(user).send() await memory.remember("Prefers a window seat").scope(first).user(user).send() // Conversation 2: the user moved. supersede stores the new fact and forgets the old one. const second = ConversationId.new() await memory.supersede(city, "Lives in Lisbon").scope(second).user(user).send() // Recall for the user across every conversation. const facts = await memory.recall().user(user).semantic(query).limit(10).fetch() console.log(JSON.stringify({ user, query, facts: facts.map(memoryItemText) }, null, 2))