Skip to content

feat: support custom message ids#40

Open
varin-nair-factory wants to merge 3 commits into
mainfrom
vn/message-id-sdk
Open

feat: support custom message ids#40
varin-nair-factory wants to merge 3 commits into
mainfrom
vn/message-id-sdk

Conversation

@varin-nair-factory
Copy link
Copy Markdown
Contributor

@varin-nair-factory varin-nair-factory commented May 19, 2026

Summary

Custom message IDs can now be supplied through both run() and session.stream(), letting SDK callers correlate their own IDs with the user message echoed by the daemon. The SDK validates caller-provided IDs before sending an RPC, while omitted IDs continue to be assigned by the daemon as before.

What changed

  • Added messageId to message options and forwards it through droid.add_user_message.
  • Validates IDs with a shared MessageIdSchema: strings only, non-empty after trimming, and at most 512 characters.
  • Reuses that schema for rewind request messageId fields so message ID rules stay consistent.
  • Validates only messageId in DroidClient.addUserMessage() instead of parsing the full message payload, avoiding extra work for large images, files, or structured output schemas.
  • Adds unit coverage and manual smoke examples for run() and session.stream() custom IDs.
  • Refreshes existing streaming examples to use the current DroidMessageType.Assistant event.

Usage

run():

import { run } from "@factory-ai/droid-sdk";

const result = await run("Reply with exactly: RUN_OK", {
  cwd: process.cwd(),
  messageId: "sdk-run-123e4567-e89b-12d3-a456-426614174000",
});

session.stream():

import { createSession, DroidMessageType } from "@factory-ai/droid-sdk";

const session = await createSession({ cwd: process.cwd() });
try {
  for await (const msg of session.stream("Reply with exactly: STREAM_OK", {
    messageId: "sdk-stream-123e4567-e89b-12d3-a456-426614174000",
  })) {
    if (msg.type === DroidMessageType.User) {
      console.log("echoed messageId:", msg.message.id);
    }
  }
} finally {
  await session.close();
}

Invalid values (empty, whitespace-only, longer than 512 characters, or non-string) reject before any add_user_message RPC is sent.

Validation

  • npm run typecheck
  • npm test
  • npm run lint
  • npm run format:check
  • npm run typecheck:examples

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@varin-nair-factory varin-nair-factory self-assigned this May 19, 2026
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants