@dremio/js-sdk 0.43.0 → 0.43.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +186 -121
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -251,31 +251,23 @@ Represents a conversation with the Dremio AI Agent.
251
251
 
252
252
  #### Properties
253
253
 
254
- - `id: string` - Unique identifier for the conversation
255
- - `title: string` - The conversation title
256
254
  - `createdAt: Temporal.Instant` - When the conversation was created
257
- - `modifiedAt: Temporal.Instant` - When the conversation was last modified
255
+ - `currentRunId: string | null` - The ID of the currently active run, if any
256
+ - `id: string` - Unique identifier for the conversation
258
257
  - `modelName: string | null` - The AI model name last used for this conversation
259
258
  - `modelProviderId: string | null` - The AI model provider ID last used for this conversation
260
-
261
- #### `AgentConversation` implements the [`Observable` contract](https://github.com/WICG/observable) using `Symbol.observable`:
262
-
263
- ```typescript
264
- import { from } from "rxjs";
265
-
266
- from(conversation).subscribe((chatEvent) => {
267
- console.log(chatEvent);
268
- });
269
- ```
259
+ - `modifiedAt: Temporal.Instant` - When the conversation was last modified
260
+ - `tag: string` - Version tag for optimistic concurrency control
261
+ - `title: string` - The conversation title
270
262
 
271
263
  #### Create an `AgentConversation`
272
264
 
273
265
  ```typescript
266
+ import { UserChatMessage } from "@dremio/js-sdk/enterprise/ai";
267
+
274
268
  const conversation = await dremio.ai("PROJECT_ID").createConversation({
275
- message: new UserChatMessage(
276
- new UserChatMessageStringContent(
277
- "Can you help me visualize the data in the Citibike sample dataset?",
278
- ),
269
+ message: UserChatMessage.new(
270
+ "Can you help me visualize the data in the Citibike sample dataset?",
279
271
  ),
280
272
  });
281
273
  ```
@@ -291,7 +283,21 @@ const conversation = await dremio
291
283
  #### Update `AgentConversation`
292
284
 
293
285
  ```typescript
294
- const result = await conversation.update({ title: "New title" });
286
+ await conversation.update({ title: "New title" });
287
+ ```
288
+
289
+ The `update()` method supports optimistic concurrency control with conflict resolution:
290
+
291
+ ```typescript
292
+ await conversation.update(
293
+ { title: "New title" },
294
+ {
295
+ onConflict: async (local, remote, changes) => {
296
+ // Overwrite with local title
297
+ return { title: local.title };
298
+ },
299
+ },
300
+ );
295
301
  ```
296
302
 
297
303
  #### Delete `AgentConversation`
@@ -316,141 +322,200 @@ for await (const conversation of dremio
316
322
  To send a message to the Agent, use the `startRun()` method:
317
323
 
318
324
  ```typescript
319
- await conversation.startRun({
320
- message: new UserChatMessage(
321
- new UserChatMessageStringContent(
322
- "Please adjust the x-axis range to show only 2025-2026",
323
- ),
325
+ import { UserChatMessage } from "@dremio/js-sdk/enterprise/ai";
326
+
327
+ const runId = await conversation.startRun({
328
+ message: UserChatMessage.new(
329
+ "Please adjust the x-axis range to show only 2025-2026",
324
330
  ),
325
331
  });
326
332
  ```
327
333
 
328
- ### `AgentConversationSnapshotBuilder`
334
+ #### Stream Run Events
329
335
 
330
- Compiles a sequence of `ChatEvent`s into a structured view of the current conversation state.
336
+ Monitor chat events as they stream in from a run:
331
337
 
332
- #### Building a Snapshot
338
+ ```typescript
339
+ import { UserChatMessage } from "@dremio/js-sdk/enterprise/ai";
333
340
 
334
- Create a snapshot from existing conversation history:
341
+ const runId = await conversation.startRun({
342
+ message: UserChatMessage.new("What data is available to me in Dremio?"),
343
+ });
344
+
345
+ conversation.runEvents$(runId).subscribe((chatEvent) => {
346
+ console.log("Event:", chatEvent.content.chunkType);
347
+ if (chatEvent.content.chunkType === "model") {
348
+ console.log("Model response:", chatEvent.content.result);
349
+ }
350
+ });
351
+ ```
352
+
353
+ #### Retrieve Conversation History
354
+
355
+ Get the full history of chat events for a conversation:
335
356
 
336
357
  ```typescript
337
- const conversation = (
338
- await dremio.ai("PROJECT_ID").retrieveConversation("CONVERSATION_ID")
339
- ).unwrap();
358
+ const history = await conversation.history();
340
359
 
341
- const conversationSnapshot = AgentConversationSnapshotBuilder.fromChatEvents(
342
- conversation.id,
343
- (await conversation.history()).unwrap(),
344
- );
360
+ console.log(`Conversation has ${history.length} events`);
345
361
  ```
346
362
 
347
- #### Adding Events in Real-Time
363
+ ### Working with Chat Events
364
+
365
+ The state of a conversation is represented as a stream of `ChatEvent` objects. These events include user messages, tool call requests and results, and Agent replies. While the event stream enables incremental UI updates, it contains implicit relationships that need to be made explicit for easier consumption.
348
366
 
349
- Monitor chat events as they stream in and add them to the snapshot:
367
+ #### Chat Event Types
368
+
369
+ - `userMessage` - A message from the user
370
+ - `model` - A response from the AI model
371
+ - `toolRequest` - A request to execute a tool (tool calls can run in parallel)
372
+ - `toolResponse` - The result of a tool execution
373
+ - `error` - An error message
374
+
375
+ #### Building a Conversation Snapshot
376
+
377
+ The `AgentConversation.reduceChatEvents()` method transforms a stream of chat events into a structured snapshot that makes implicit relationships explicit:
378
+
379
+ - **Groups events by exchange** - Each user-agent interaction (identified by `runId`) becomes a separate exchange
380
+ - **Pairs tool calls** - Tool requests and responses are matched by `callId` and combined into a single object
381
+ - **Derives tool state** - Automatically determines if a tool call is `pending`, `success`, or `error`
382
+ - **Handles duplicates** - Efficiently filters duplicate events when merging history and live streams
383
+ - **Preserves order** - Maintains insertion order for messages and tool calls
350
384
 
351
385
  ```typescript
352
- const runId = await conversation
353
- .startRun({
354
- message: new UserChatMessage(
355
- new UserChatMessageStringContent(
356
- "What data is available to me in Dremio?",
357
- ),
358
- ),
359
- })
360
- .then((res) => res.unwrap());
386
+ import { AgentConversation } from "@dremio/js-sdk/enterprise/ai";
387
+
388
+ const conversation = await dremio
389
+ .ai("PROJECT_ID")
390
+ .retrieveConversation("CONVERSATION_ID");
391
+
392
+ const history = await conversation.history();
393
+
394
+ const snapshot = AgentConversation.reduceChatEvents([], history);
395
+ ```
396
+
397
+ Each exchange in the snapshot represents a single user-agent interaction:
398
+
399
+ ```typescript
400
+ type ConversationExchange = {
401
+ id: string; // The run ID
402
+ messages: Map<string, ConversationExchangeMessage>;
403
+ toolCalls: Map<string, AgentToolCall>;
404
+ submittedUserMessage?: UserChatMessage;
405
+ };
406
+
407
+ type AgentToolCall = {
408
+ id: string;
409
+ state: "error" | "pending" | "success";
410
+ request: ChatEventWithChunkType<"toolRequest"> | undefined;
411
+ result: ChatEventWithChunkType<"toolResponse"> | undefined;
412
+ };
413
+ ```
414
+
415
+ #### Incremental Updates
416
+
417
+ The reducer is a pure function with signature `(snapshot, events) => newSnapshot`. You can incrementally update a snapshot as new events arrive:
418
+
419
+ ```typescript
420
+ import {
421
+ AgentConversation,
422
+ UserChatMessage,
423
+ } from "@dremio/js-sdk/enterprise/ai";
424
+
425
+ let snapshot = AgentConversation.reduceChatEvents([], historyEvents);
426
+
427
+ const runId = await conversation.startRun({
428
+ message: UserChatMessage.new("What tables exist?"),
429
+ });
361
430
 
362
431
  conversation.runEvents$(runId).subscribe((chatEvent) => {
363
- conversationSnapshot.addChatEvent(chatEvent);
364
- console.log(conversationSnapshot.get(runId)!.toJSON());
432
+ snapshot = AgentConversation.reduceChatEvents(snapshot, [chatEvent]);
433
+
434
+ const currentExchange = snapshot[snapshot.length - 1];
435
+ console.log("Current exchange:", currentExchange);
365
436
  });
366
437
  ```
367
438
 
368
- #### Accessing Snapshot Data
439
+ ### `UserChatMessage`
440
+
441
+ Create user messages to send to the AI Agent.
369
442
 
370
- The snapshot is iterable and provides access to exchanges:
443
+ #### Create a Simple Message
371
444
 
372
445
  ```typescript
373
- // Iterate through all exchanges
374
- for (const exchange of conversationSnapshot) {
375
- console.log("Exchange ID:", exchange.id);
376
- for (const message of exchange.messages) {
377
- console.log("Message:", message);
378
- }
379
- for (const toolCall of exchange.toolCalls) {
380
- console.log("Tool Call:", toolCall.id, toolCall.state);
381
- }
382
- }
446
+ import { UserChatMessage } from "@dremio/js-sdk/enterprise/ai";
383
447
 
384
- // Get a specific exchange
385
- const exchange = conversationSnapshot.get(runId);
448
+ const message = UserChatMessage.new("What tables are available?");
386
449
  ```
387
450
 
388
- #### Snapshot Methods
451
+ #### Create a Message with Context
389
452
 
390
- - `length: number` - Get the number of exchanges in the snapshot
391
- - `clone(): AgentConversationSnapshotBuilder` - Create a deep clone of the builder
392
- - `slice(startExchangeId, endExchangeId?)` - Get a shallow clone containing exchanges in a range
393
- - `toJSON()` - Serialize the snapshot to JSON
453
+ ```typescript
454
+ import { UserChatMessage } from "@dremio/js-sdk/enterprise/ai";
394
455
 
395
- #### Snapshot Output Example
456
+ const message = UserChatMessage.new("Analyze this data", {
457
+ context: "Additional context about the request",
458
+ skillIds: ["skill-id-1", "skill-id-2"],
459
+ });
460
+ ```
396
461
 
397
- The `toJSON()` method returns an array of exchanges with their messages and tool calls:
462
+ #### Message Properties
398
463
 
399
- ```json
400
- [
401
- {
402
- "id": "run-id-1",
403
- "messages": [
404
- {
405
- "id": "msg-1",
406
- "runId": "run-id-1",
407
- "conversationId": "conv-id",
408
- "role": "user",
409
- "content": {
410
- "chunkType": "userMessage",
411
- "text": "What data is available?"
412
- }
413
- },
414
- {
415
- "id": "msg-2",
416
- "runId": "run-id-1",
417
- "conversationId": "conv-id",
418
- "role": "agent",
419
- "content": {
420
- "chunkType": "model",
421
- "name": "modelGeneric",
422
- "result": {
423
- "text": "Here are the available datasets..."
424
- }
425
- }
426
- }
427
- ],
428
- "toolCalls": [
429
- {
430
- "id": "tool-call-1",
431
- "state": "success",
432
- "request": {
433
- "content": {
434
- "chunkType": "toolRequest",
435
- "name": "queryTool",
436
- "arguments": { "query": "SELECT * FROM schemas" }
437
- }
438
- },
439
- "result": {
440
- "content": {
441
- "chunkType": "toolResponse",
442
- "name": "queryTool",
443
- "result": {
444
- "rows": [{ "schema_name": "public" }]
445
- }
446
- }
447
- }
448
- }
449
- ]
450
- }
451
- ]
464
+ - `id: string` - Unique identifier for the message
465
+ - `createdAt: Temporal.ZonedDateTime` - When the message was created
466
+ - `content: string` - The message text
467
+ - `prompt?: object` - Optional prompt configuration including context, skillIds, and approvals
468
+
469
+ ### `AgentConversationMachine`
470
+
471
+ An XState state machine for managing conversation lifecycle with built-in state management.
472
+
473
+ #### Create and Use the Machine
474
+
475
+ ```typescript
476
+ import { createActor } from "xstate";
477
+ import { UserChatMessage } from "@dremio/js-sdk/enterprise/ai";
478
+
479
+ const conversationMachine = dremio.ai("PROJECT_ID").conversationMachine;
480
+
481
+ // Create a new conversation
482
+ const actor = createActor(conversationMachine, {
483
+ input: {
484
+ conversationId: null,
485
+ initialMessage: UserChatMessage.new("Hello, can you help me?"),
486
+ },
487
+ });
488
+
489
+ actor.subscribe((snapshot) => {
490
+ console.log("State:", snapshot.value);
491
+ console.log("Exchanges:", snapshot.context.conversationSnapshot);
492
+ });
493
+
494
+ actor.start();
495
+
496
+ // Send additional messages
497
+ actor.send({
498
+ type: "SUBMIT_USER_MESSAGE",
499
+ message: UserChatMessage.new("What data sources are available?"),
500
+ });
452
501
  ```
453
502
 
503
+ #### Machine States
504
+
505
+ - `uninitialized` - Initial state before conversation is created
506
+ - `creating_conversation` - Creating a new conversation
507
+ - `retrieving_history` - Fetching conversation history
508
+ - `idle` - Ready to accept new messages
509
+ - `submitting_message` - Sending a user message
510
+ - `streaming` - Receiving agent responses
511
+ - `retrieve_history_failed` - Error state when history retrieval fails
512
+
513
+ #### Machine Events
514
+
515
+ - `SUBMIT_USER_MESSAGE` - Send a new message
516
+ - `REFRESH_HISTORY` - Reload conversation history
517
+ - `CANCEL_RUN` - Cancel the current run
518
+
454
519
  ## Catalog
455
520
 
456
521
  ### `CatalogReference` Interface
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dremio/js-sdk",
3
- "version": "0.43.0",
3
+ "version": "0.43.1",
4
4
  "description": "JavaScript library for the Dremio API",
5
5
  "keywords": [
6
6
  "dremio",