tool-output-available.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Derived from vercel/ai-elements (skills/ai-elements/scripts/tool-output-available.tsx).
  3. * Copyright 2023 Vercel, Inc. Licensed under Apache-2.0.
  4. * Modified by ZCode: local integration, formatting and adaptations.
  5. * See THIRD-PARTY-NOTICES.md in the repository root for license and provenance.
  6. */
  7. "use client";
  8. import { CodeBlock } from "@/components/ai-elements/code-block";
  9. import {
  10. Tool,
  11. ToolContent,
  12. ToolHeader,
  13. ToolInput,
  14. ToolOutput,
  15. } from "@/components/ai-elements/tool";
  16. import type { ToolUIPart } from "ai";
  17. import { nanoid } from "nanoid";
  18. const toolCall: ToolUIPart = {
  19. errorText: undefined,
  20. input: {
  21. database: "analytics",
  22. params: ["2024-01-01"],
  23. query: "SELECT COUNT(*) FROM users WHERE created_at >= ?",
  24. },
  25. output: [
  26. {
  27. "Created At": "2024-01-15",
  28. Email: "john@example.com",
  29. Name: "John Doe",
  30. "User ID": 1,
  31. },
  32. {
  33. "Created At": "2024-01-20",
  34. Email: "jane@example.com",
  35. Name: "Jane Smith",
  36. "User ID": 2,
  37. },
  38. {
  39. "Created At": "2024-02-01",
  40. Email: "bob@example.com",
  41. Name: "Bob Wilson",
  42. "User ID": 3,
  43. },
  44. {
  45. "Created At": "2024-02-10",
  46. Email: "alice@example.com",
  47. Name: "Alice Brown",
  48. "User ID": 4,
  49. },
  50. {
  51. "Created At": "2024-02-15",
  52. Email: "charlie@example.com",
  53. Name: "Charlie Davis",
  54. "User ID": 5,
  55. },
  56. ],
  57. state: "output-available" as const,
  58. toolCallId: nanoid(),
  59. type: "tool-database_query" as const,
  60. };
  61. const Example = () => (
  62. <div style={{ height: "500px" }}>
  63. <Tool>
  64. <ToolHeader state={toolCall.state} type={toolCall.type} />
  65. <ToolContent>
  66. <ToolInput input={toolCall.input} />
  67. {toolCall.state === "output-available" && (
  68. <ToolOutput
  69. errorText={toolCall.errorText}
  70. output={<CodeBlock code={JSON.stringify(toolCall.output)} language="json" />}
  71. />
  72. )}
  73. </ToolContent>
  74. </Tool>
  75. </div>
  76. );
  77. export default Example;