• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dialoguedb / client-nodejs / 26546440990

28 May 2026 12:12AM UTC coverage: 80.205%. First build
26546440990

Pull #78

github

web-flow
Merge 22684c44d into 8461e5412
Pull Request #78: add cli build

797 of 1003 branches covered (79.46%)

Branch coverage included in aggregate %.

0 of 236 new or added lines in 6 files covered. (0.0%)

1002 of 1240 relevant lines covered (80.81%)

38.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/cli/message.ts
1
import { Command } from "commander";
NEW
2
import { readFile } from "node:fs/promises";
×
NEW
3
import { getDialogue } from "../methods/getDialogue";
×
NEW
4
import {
×
5
  output,
6
  parseIntStrict,
7
  parseJSON,
8
  resolveContent,
9
  withErrorHandler,
10
} from "./shared";
11

12
async function loadDialogueOrExit(id: string, namespace?: string) {
NEW
13
  const d = await getDialogue({
×
14
    id,
15
    ...(namespace && { namespace }),
×
16
  });
NEW
17
  if (!d) {
×
NEW
18
    process.stderr.write(`Dialogue ${id} not found\n`);
×
NEW
19
    process.exit(1);
×
20
  }
NEW
21
  return d;
×
22
}
23

NEW
24
export function registerMessageCommands(program: Command): void {
×
NEW
25
  const message = program
×
26
    .command("message")
27
    .description("Manage messages within a dialogue");
28

NEW
29
  message
×
30
    .command("add <dialogueId>")
31
    .description("Add a message to a dialogue")
32
    .requiredOption("--role <role>", "Message role (e.g. user, assistant)")
33
    .option("--content <content>", "Message content (string)")
34
    .option("--content-json <json>", "Message content (JSON)")
35
    .option("--stdin", "Read content from stdin")
36
    .option("--name <name>", "Optional name")
37
    .option("--namespace <namespace>", "Namespace")
38
    .option("--tags <csv>", "Tags (comma-separated)")
39
    .action(
40
      withErrorHandler(async (dialogueId: string, opts) => {
NEW
41
        const d = await loadDialogueOrExit(dialogueId, opts.namespace);
×
42

43
        let content: unknown;
NEW
44
        if (opts.contentJson) {
×
NEW
45
          content = parseJSON("content-json", opts.contentJson);
×
46
        } else {
NEW
47
          content = await resolveContent({
×
48
            content: opts.content,
49
            stdin: opts.stdin,
50
          });
51
        }
52

NEW
53
        const msg = await d.saveMessage({
×
54
          role: opts.role,
55
          content: content as any,
56
          ...(opts.name && { name: opts.name }),
×
57
          ...(opts.tags && {
×
NEW
58
            tags: opts.tags.split(",").map((s: string) => s.trim()),
×
59
          }),
60
        });
NEW
61
        output(msg);
×
62
      })
63
    );
64

NEW
65
  message
×
66
    .command("add-batch <dialogueId>")
67
    .description("Add multiple messages from a JSON file")
68
    .requiredOption(
69
      "--file <path>",
70
      "Path to JSON file containing array of {role, content}"
71
    )
72
    .option("--namespace <namespace>", "Namespace")
73
    .action(
74
      withErrorHandler(async (dialogueId: string, opts) => {
NEW
75
        const d = await loadDialogueOrExit(dialogueId, opts.namespace);
×
NEW
76
        const raw = await readFile(opts.file, "utf8");
×
NEW
77
        const messages = parseJSON("file", raw);
×
NEW
78
        if (!Array.isArray(messages)) {
×
NEW
79
          throw new Error(
×
80
            `--file must contain a JSON array, got ${typeof messages}`
81
          );
82
        }
NEW
83
        const saved = await d.saveMessages(messages as any);
×
NEW
84
        output(saved);
×
85
      })
86
    );
87

NEW
88
  message
×
89
    .command("list <dialogueId>")
90
    .description("List messages in a dialogue")
91
    .option("--limit <n>", "Limit")
92
    .option("--order <asc|desc>", "Sort order")
93
    .option("--namespace <namespace>", "Namespace")
94
    .option("--next-page", "Append next page using cached cursor")
95
    .action(
96
      withErrorHandler(async (dialogueId: string, opts) => {
NEW
97
        const d = await loadDialogueOrExit(dialogueId, opts.namespace);
×
NEW
98
        const filters: Record<string, unknown> = {};
×
NEW
99
        if (opts.limit) filters.limit = parseIntStrict("limit", opts.limit);
×
NEW
100
        if (opts.order) filters.order = opts.order;
×
NEW
101
        if (opts.nextPage) filters.next = true;
×
NEW
102
        const items = await d.loadMessages(filters as any);
×
NEW
103
        output(items);
×
104
      })
105
    );
106

NEW
107
  message
×
108
    .command("get <dialogueId> <messageId>")
109
    .description("Get a single message by ID")
110
    .option("--namespace <namespace>", "Namespace")
111
    .action(
112
      withErrorHandler(async (dialogueId: string, messageId: string, opts) => {
NEW
113
        const d = await loadDialogueOrExit(dialogueId, opts.namespace);
×
NEW
114
        const msg = await d.getMessage(messageId);
×
NEW
115
        output(msg);
×
116
      })
117
    );
118

NEW
119
  message
×
120
    .command("delete <dialogueId> <messageId>")
121
    .description("Delete a message by ID")
122
    .option("--namespace <namespace>", "Namespace")
123
    .action(
124
      withErrorHandler(async (dialogueId: string, messageId: string, opts) => {
NEW
125
        const d = await loadDialogueOrExit(dialogueId, opts.namespace);
×
NEW
126
        await d.deleteMessage(messageId);
×
NEW
127
        output({ deleted: messageId });
×
128
      })
129
    );
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc