@assistant-ui/react 0.10.18 → 0.10.20

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 (41) hide show
  1. package/dist/api/ContentPartRuntime.d.ts +3 -2
  2. package/dist/api/ContentPartRuntime.d.ts.map +1 -1
  3. package/dist/api/ContentPartRuntime.js +5 -1
  4. package/dist/api/ContentPartRuntime.js.map +1 -1
  5. package/dist/api/ThreadRuntime.d.ts +3 -0
  6. package/dist/api/ThreadRuntime.d.ts.map +1 -1
  7. package/dist/api/ThreadRuntime.js +6 -5
  8. package/dist/api/ThreadRuntime.js.map +1 -1
  9. package/dist/primitives/message/MessageIf.js +1 -1
  10. package/dist/primitives/message/MessageIf.js.map +1 -1
  11. package/dist/runtimes/adapters/index.d.ts +2 -0
  12. package/dist/runtimes/adapters/index.d.ts.map +1 -1
  13. package/dist/runtimes/adapters/index.js +2 -0
  14. package/dist/runtimes/adapters/index.js.map +1 -1
  15. package/dist/runtimes/core/ThreadRuntimeCore.d.ts +3 -1
  16. package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
  17. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
  18. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +10 -2
  19. package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
  20. package/dist/runtimes/external-store/external-message-converter.d.ts +2 -0
  21. package/dist/runtimes/external-store/external-message-converter.d.ts.map +1 -1
  22. package/dist/runtimes/external-store/external-message-converter.js +3 -1
  23. package/dist/runtimes/external-store/external-message-converter.js.map +1 -1
  24. package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts +2 -2
  25. package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
  26. package/dist/runtimes/local/LocalThreadRuntimeCore.js +6 -2
  27. package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
  28. package/dist/tests/setup.js +8 -8
  29. package/dist/tests/setup.js.map +1 -1
  30. package/dist/types/ContentPartComponentTypes.d.ts +2 -1
  31. package/dist/types/ContentPartComponentTypes.d.ts.map +1 -1
  32. package/package.json +2 -2
  33. package/src/api/ContentPartRuntime.ts +7 -3
  34. package/src/api/ThreadRuntime.ts +8 -5
  35. package/src/primitives/message/MessageIf.tsx +1 -1
  36. package/src/runtimes/adapters/index.ts +2 -0
  37. package/src/runtimes/core/ThreadRuntimeCore.tsx +3 -1
  38. package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +10 -2
  39. package/src/runtimes/external-store/external-message-converter.tsx +4 -0
  40. package/src/runtimes/local/LocalThreadRuntimeCore.tsx +4 -0
  41. package/src/types/ContentPartComponentTypes.tsx +2 -1
@@ -1,6 +1,7 @@
1
1
  import type { ComponentType } from "react";
2
2
  import type { ContentPartStatus, FileContentPart, ImageContentPart, ReasoningContentPart, SourceContentPart, TextContentPart, ToolCallContentPart, Unstable_AudioContentPart } from "./AssistantTypes";
3
3
  import { ContentPartState } from "../api/ContentPartRuntime";
4
+ import { ToolResponse } from "assistant-stream";
4
5
  export type EmptyContentPartProps = {
5
6
  status: ContentPartStatus;
6
7
  };
@@ -18,7 +19,7 @@ export type FileContentPartComponent = ComponentType<FileContentPartProps>;
18
19
  export type Unstable_AudioContentPartProps = ContentPartState & Unstable_AudioContentPart;
19
20
  export type Unstable_AudioContentPartComponent = ComponentType<Unstable_AudioContentPartProps>;
20
21
  export type ToolCallContentPartProps<TArgs = any, TResult = unknown> = ContentPartState & ToolCallContentPart<TArgs, TResult> & {
21
- addResult: (result: TResult) => void;
22
+ addResult: (result: TResult | ToolResponse<TResult>) => void;
22
23
  };
23
24
  export type ToolCallContentPartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallContentPartProps<TArgs, TResult>>;
24
25
  //# sourceMappingURL=ContentPartComponentTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentPartComponentTypes.d.ts","sourceRoot":"","sources":["../../src/types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a,CAAC,sBAAsB,CAAC,CAAC;AAE/E,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AACxE,MAAM,MAAM,yBAAyB,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC;AAE7E,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG,eAAe,CAAC;AACtE,MAAM,MAAM,wBAAwB,GAAG,aAAa,CAAC,oBAAoB,CAAC,CAAC;AAE3E,MAAM,MAAM,8BAA8B,GAAG,gBAAgB,GAC3D,yBAAyB,CAAC;AAC5B,MAAM,MAAM,kCAAkC,GAC5C,aAAa,CAAC,8BAA8B,CAAC,CAAC;AAEhD,MAAM,MAAM,wBAAwB,CAClC,KAAK,GAAG,GAAG,EACX,OAAO,GAAG,OAAO,IACf,gBAAgB,GAClB,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG;IACpC,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CAC9D,CAAC;AAEJ,MAAM,MAAM,4BAA4B,CACtC,KAAK,GAAG,GAAG,EACX,OAAO,GAAG,GAAG,IACX,aAAa,CAAC,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "conversational-ui",
29
29
  "conversational-ai"
30
30
  ],
31
- "version": "0.10.18",
31
+ "version": "0.10.20",
32
32
  "license": "MIT",
33
33
  "type": "module",
34
34
  "exports": {
@@ -57,7 +57,7 @@
57
57
  "@radix-ui/react-use-callback-ref": "^1.1.1",
58
58
  "@radix-ui/react-use-escape-keydown": "^1.1.1",
59
59
  "@standard-schema/spec": "^1.0.0",
60
- "assistant-stream": "^0.2.13",
60
+ "assistant-stream": "^0.2.14",
61
61
  "json-schema": "^0.4.0",
62
62
  "nanoid": "5.1.5",
63
63
  "react-textarea-autosize": "^8.5.9",
@@ -9,6 +9,7 @@ import { MessageStateBinding } from "./MessageRuntime";
9
9
  import { SubscribableWithState } from "./subscribable/Subscribable";
10
10
  import { Unsubscribe } from "../types";
11
11
  import { ContentPartRuntimePath } from "./RuntimePathTypes";
12
+ import { ToolResponse } from "assistant-stream";
12
13
 
13
14
  export type ContentPartState = (
14
15
  | ThreadUserContentPart
@@ -27,7 +28,7 @@ export type ContentPartRuntime = {
27
28
  * Add tool result to a tool call content part that has no tool result yet.
28
29
  * This is useful when you are collecting a tool result via user input ("human tool calls").
29
30
  */
30
- addToolResult(result: any): void;
31
+ addToolResult(result: any | ToolResponse<any>): void;
31
32
 
32
33
  readonly path: ContentPartRuntimePath;
33
34
  getState(): ContentPartState;
@@ -55,7 +56,7 @@ export class ContentPartRuntimeImpl implements ContentPartRuntime {
55
56
  return this.contentBinding.getState();
56
57
  }
57
58
 
58
- public addToolResult(result: any) {
59
+ public addToolResult(result: any | ToolResponse<any>) {
59
60
  const state = this.contentBinding.getState();
60
61
  if (!state) throw new Error("Content part is not available");
61
62
 
@@ -74,11 +75,14 @@ export class ContentPartRuntimeImpl implements ContentPartRuntime {
74
75
  const toolName = state.toolName;
75
76
  const toolCallId = state.toolCallId;
76
77
 
78
+ const response = ToolResponse.toResponse(result);
77
79
  this.threadApi.getState().addToolResult({
78
80
  messageId: message.id,
79
81
  toolName,
80
82
  toolCallId,
81
- result,
83
+ result: response.result,
84
+ artifact: response.artifact,
85
+ isError: response.isError,
82
86
  });
83
87
  }
84
88
 
@@ -72,6 +72,9 @@ export type CreateAppendMessage =
72
72
  role?: AppendMessage["role"] | undefined;
73
73
  content: AppendMessage["content"];
74
74
  attachments?: AppendMessage["attachments"] | undefined;
75
+ metadata?: AppendMessage["metadata"] | undefined;
76
+ createdAt?: Date | undefined;
77
+ runConfig?: AppendMessage["runConfig"] | undefined;
75
78
  startRun?: boolean | undefined;
76
79
  };
77
80
 
@@ -92,16 +95,16 @@ const toAppendMessage = (
92
95
  };
93
96
  }
94
97
 
95
- if (message.role && message.parentId && message.attachments) {
96
- return message as AppendMessage;
97
- }
98
-
99
98
  return {
100
- ...message,
99
+ createdAt: message.createdAt ?? new Date(),
101
100
  parentId: message.parentId ?? messages.at(-1)?.id ?? null,
102
101
  sourceId: message.sourceId ?? null,
103
102
  role: message.role ?? "user",
103
+ content: message.content,
104
104
  attachments: message.attachments ?? [],
105
+ metadata: message.metadata ?? { custom: {} },
106
+ runConfig: message.runConfig ?? {},
107
+ startRun: message.startRun,
105
108
  } as AppendMessage;
106
109
  };
107
110
 
@@ -48,7 +48,7 @@ const useMessageIf = (props: UseMessageIfProps) => {
48
48
  if (props.system && role !== "system") return false;
49
49
 
50
50
  if (props.lastOrHover === true && !isHovering && !isLast) return false;
51
- if (props.last === true && !isLast) return false;
51
+ if (props.last !== undefined && props.last !== isLast) return false;
52
52
 
53
53
  if (props.copied === true && !isCopied) return false;
54
54
  if (props.copied === false && isCopied) return false;
@@ -2,3 +2,5 @@ export * from "./attachment";
2
2
  export * from "./feedback";
3
3
  export * from "./speech";
4
4
  export * from "./suggestion";
5
+ export * from "./RuntimeAdapterProvider";
6
+ export * from "./thread-history/ThreadHistoryAdapter";
@@ -26,7 +26,9 @@ export type AddToolResultOptions = {
26
26
  messageId: string;
27
27
  toolName: string;
28
28
  toolCallId: string;
29
- result: any;
29
+ result: ReadonlyJSONValue;
30
+ isError: boolean;
31
+ artifact?: ReadonlyJSONValue | undefined;
30
32
  };
31
33
 
32
34
  export type SubmitFeedbackOptions = {
@@ -247,9 +247,17 @@ export class ExternalStoreThreadRuntimeCore
247
247
  }
248
248
 
249
249
  public addToolResult(options: AddToolResultOptions) {
250
- if (!this._store.onAddToolResult)
250
+ if (!this._store.onAddToolResult && !this._store.onAddToolResult)
251
251
  throw new Error("Runtime does not support tool results.");
252
- this._store.onAddToolResult(options);
252
+ this._store.onAddToolResult?.({
253
+ messageId: options.messageId,
254
+ toolName: options.toolName,
255
+ toolCallId: options.toolCallId,
256
+ result: options.result,
257
+ isError: options.isError,
258
+ artifact: options.artifact,
259
+ });
260
+ this._store.onAddToolResult?.(options);
253
261
  }
254
262
 
255
263
  private updateMessages = (messages: readonly ThreadMessage[]) => {
@@ -22,6 +22,8 @@ export namespace useExternalMessageConverter {
22
22
  toolCallId: string;
23
23
  toolName?: string | undefined;
24
24
  result: any;
25
+ artifact?: any;
26
+ isError?: boolean;
25
27
  };
26
28
 
27
29
  export type Callback<T> = (message: T) => Message | Message[];
@@ -75,6 +77,8 @@ const joinExternalMessages = (
75
77
  ],
76
78
  },
77
79
  result: output.result,
80
+ artifact: output.artifact,
81
+ isError: output.isError,
78
82
  };
79
83
  } else {
80
84
  throw new Error(
@@ -385,6 +385,8 @@ export class LocalThreadRuntimeCore
385
385
  messageId,
386
386
  toolCallId,
387
387
  result,
388
+ isError,
389
+ artifact,
388
390
  }: AddToolResultOptions) {
389
391
  const messageData = this.repository.getMessage(messageId);
390
392
  const { parentId } = messageData;
@@ -403,6 +405,8 @@ export class LocalThreadRuntimeCore
403
405
  return {
404
406
  ...c,
405
407
  result,
408
+ artifact,
409
+ isError,
406
410
  };
407
411
  });
408
412
 
@@ -10,6 +10,7 @@ import type {
10
10
  Unstable_AudioContentPart,
11
11
  } from "./AssistantTypes";
12
12
  import { ContentPartState } from "../api/ContentPartRuntime";
13
+ import { ToolResponse } from "assistant-stream";
13
14
 
14
15
  export type EmptyContentPartProps = {
15
16
  status: ContentPartStatus;
@@ -42,7 +43,7 @@ export type ToolCallContentPartProps<
42
43
  TResult = unknown,
43
44
  > = ContentPartState &
44
45
  ToolCallContentPart<TArgs, TResult> & {
45
- addResult: (result: TResult) => void;
46
+ addResult: (result: TResult | ToolResponse<TResult>) => void;
46
47
  };
47
48
 
48
49
  export type ToolCallContentPartComponent<