The ChatMessageInput interface does not allow the tool role, even though this role is allowed in other parts of the SDK.
ChatMessageInput:
export declare interface ChatMessageInput {
/**
* The sender of this message. Only "user", "assistant", and "system" is allowed. Defaults to
* "user" if not specified.
*/
role?: "user" | "assistant" | "system";
...
This issue becomes apparent when trying to create messages using Chat.from, where the tool role is not allowed because of the above TypeScript declaration. This is, however, still able to be done using a less straightforward way, as ChatMessageRoleData does seem to allow the tool role. It seems strange that the shorthand version of the same API does not allow this role, while the workaround does, which is why I am reporting it here.
ChatMessageRoleData:
/**
* @public
*/
export declare type ChatMessageRoleData = "assistant" | "user" | "system" | "tool";
This is the less straightforward way, which would be equivalent to Chat.from if the tool role was allowed:
const chat = Chat.empty();
for (let i = 0; i < messages.length; i++) {
const message = messages[i];
chat.append(message.role, message.content);
}
The
ChatMessageInputinterface does not allow thetoolrole, even though this role is allowed in other parts of the SDK.ChatMessageInput:This issue becomes apparent when trying to create messages using
Chat.from, where thetoolrole is not allowed because of the above TypeScript declaration. This is, however, still able to be done using a less straightforward way, asChatMessageRoleDatadoes seem to allow thetoolrole. It seems strange that the shorthand version of the same API does not allow this role, while the workaround does, which is why I am reporting it here.ChatMessageRoleData:This is the less straightforward way, which would be equivalent to
Chat.fromif thetoolrole was allowed: