utils.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. export function _isToolCall(toolCall) {
  2. return !!(toolCall &&
  3. typeof toolCall === "object" &&
  4. "type" in toolCall &&
  5. toolCall.type === "tool_call");
  6. }
  7. export function _configHasToolCallId(config) {
  8. return !!(config &&
  9. typeof config === "object" &&
  10. "toolCall" in config &&
  11. config.toolCall != null &&
  12. typeof config.toolCall === "object" &&
  13. "id" in config.toolCall &&
  14. typeof config.toolCall.id === "string");
  15. }
  16. /**
  17. * Custom error class used to handle exceptions related to tool input parsing.
  18. * It extends the built-in `Error` class and adds an optional `output`
  19. * property that can hold the output that caused the exception.
  20. */
  21. export class ToolInputParsingException extends Error {
  22. constructor(message, output) {
  23. super(message);
  24. Object.defineProperty(this, "output", {
  25. enumerable: true,
  26. configurable: true,
  27. writable: true,
  28. value: void 0
  29. });
  30. this.output = output;
  31. }
  32. }