@worktango/ai-assistant 0.0.1 → 0.0.2-beta-gd2

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 (206) hide show
  1. package/README.md +107 -6
  2. package/backendTypes.ts +268 -0
  3. package/build/constants.js +80 -0
  4. package/build/dist/express.d.ts +2 -0
  5. package/build/dist/express.js +10457 -0
  6. package/build/express.d.ts +2 -0
  7. package/build/express.js +21 -0
  8. package/build/react.d.ts +4 -0
  9. package/build/react.js +44 -0
  10. package/build/src/backend/express.d.ts +63 -0
  11. package/build/src/backend/express.js +366 -0
  12. package/constants.js +80 -0
  13. package/dist/Absenteeism-DnYRfCGD.mjs +49 -0
  14. package/dist/ActivityFeed-CMR7d8a9.mjs +41 -0
  15. package/dist/AddUser-BxN71Gq-.mjs +128 -0
  16. package/dist/Admin-BNwEEcul.mjs +55 -0
  17. package/dist/Admin-CCOxh4NQ.mjs +70 -0
  18. package/dist/AiGeneral-6P2eop9s.mjs +43 -0
  19. package/dist/AiScoring-Be2EIJC_.mjs +67 -0
  20. package/dist/AiText-D4UwoEoT.mjs +67 -0
  21. package/dist/Anniversary-B3ZoAqa5.mjs +35 -0
  22. package/dist/Appreciation-B_rgIegc.mjs +55 -0
  23. package/dist/ArrowDown-CWFXlxhX.mjs +38 -0
  24. package/dist/ArrowLeft-D7rl_Ecd.mjs +12 -0
  25. package/dist/ArrowRight-BPLLV4yW.mjs +12 -0
  26. package/dist/ArrowUp-DYWuwxJM.mjs +31 -0
  27. package/dist/Attachment-CR6plcc5.mjs +20 -0
  28. package/dist/BeQuickDontHurry-BPnXAKBa.mjs +94 -0
  29. package/dist/Birthday-BihgKHOQ.mjs +66 -0
  30. package/dist/BrandPromise-fU0oR23R.mjs +57 -0
  31. package/dist/BrandVision-B37SFqTc.mjs +96 -0
  32. package/dist/Calendar-BdAku_za.mjs +24 -0
  33. package/dist/CaretDn-De_oYPN-.mjs +11 -0
  34. package/dist/CaretDown-DnGml5_x.mjs +5 -0
  35. package/dist/CaretLeft-D0BOxHEC.mjs +11 -0
  36. package/dist/CaretRight-dCjBT9bB.mjs +11 -0
  37. package/dist/CaretUp-BCw0fqJn.mjs +11 -0
  38. package/dist/ChallengeAccepted-CNaeHk1I.mjs +49 -0
  39. package/dist/CheckIn-CwG42QYQ.mjs +34 -0
  40. package/dist/CheckIns-A1Kkc_2W.mjs +33 -0
  41. package/dist/CheckSeal-Dqw_lc0S.mjs +31 -0
  42. package/dist/Checkmark-BHE91v8D.mjs +16 -0
  43. package/dist/Clock-CuAJQmxQ.mjs +33 -0
  44. package/dist/Close-D-f_iwQ8.mjs +12 -0
  45. package/dist/CloudDownload-CfQ7V21B.mjs +40 -0
  46. package/dist/Comment-GrrKaBsi.mjs +167 -0
  47. package/dist/Comments-YOn2eJUt.mjs +48 -0
  48. package/dist/Connections-CPlNaCbu.mjs +49 -0
  49. package/dist/Copy-NDpa2_F3.mjs +72 -0
  50. package/dist/CustomQuestion-OzfWoJV3.mjs +40 -0
  51. package/dist/CustomerSuccess-DAH7mRDK.mjs +50 -0
  52. package/dist/DatePicker-BxfSRn5x.mjs +303 -0
  53. package/dist/Dot-DCoU7aD3.mjs +12 -0
  54. package/dist/Download-DpF3elMl.mjs +38 -0
  55. package/dist/Drag-DWbGJvhn.mjs +41 -0
  56. package/dist/DragIndicator-CnDCSf3A.mjs +12 -0
  57. package/dist/Earn-7uXfIfZU.mjs +15 -0
  58. package/dist/Email-zAMtQLoS.mjs +24 -0
  59. package/dist/EmojiDisplay-DSZOjKek.mjs +38975 -0
  60. package/dist/EmojiPicker-DgtE9CiW.mjs +29560 -0
  61. package/dist/EnpsSurvey-Y9at0I5m.mjs +49 -0
  62. package/dist/Expired-BNR7WTVX.mjs +33 -0
  63. package/dist/Eye-DzoufmcZ.mjs +27 -0
  64. package/dist/Feedback-D7sxcXQ1.mjs +41 -0
  65. package/dist/Feedback-JZEpzb79.mjs +49 -0
  66. package/dist/Filter-C1JuLCfg.mjs +64 -0
  67. package/dist/Flag-C4l9OPVK.mjs +35 -0
  68. package/dist/Giphy-Bhmd8ypI.mjs +22 -0
  69. package/dist/GoalCount-CDtW2B-F.mjs +10 -0
  70. package/dist/GoalPercent-CEIqOHFH.mjs +21 -0
  71. package/dist/GoalTask-BRQInXIl.mjs +20 -0
  72. package/dist/GoalTask-Bhh_sX7J.mjs +42 -0
  73. package/dist/Goals-BMFrqSmc.mjs +79 -0
  74. package/dist/Goals-CPiQ13bO.mjs +70 -0
  75. package/dist/Growth-Ck1OiXeO.mjs +85 -0
  76. package/dist/Hamburger-BkqfmMmA.mjs +9 -0
  77. package/dist/Help-B2KqPPam.mjs +36 -0
  78. package/dist/HighFive-BYcQw328.mjs +33 -0
  79. package/dist/HighFive-Bi71jYQj.mjs +38 -0
  80. package/dist/Home-CHOKwBnN.mjs +21 -0
  81. package/dist/Home-DPyqkkoX.mjs +31 -0
  82. package/dist/HorizontalLine-DzBF5cf2.mjs +17 -0
  83. package/dist/Hourglass-sPcwiWfl.mjs +53 -0
  84. package/dist/Image-D-LHXhOl.mjs +41 -0
  85. package/dist/ImageFile-By-HPKcE.mjs +60 -0
  86. package/dist/InGoodCompany-CvfwTAMs.mjs +33 -0
  87. package/dist/Incentives-DnZQM_QS.mjs +155 -0
  88. package/dist/Info-CQnSKd8J.mjs +31 -0
  89. package/dist/Insights-BApP3QUO.mjs +20 -0
  90. package/dist/Insights-BivxsIhR.mjs +41 -0
  91. package/dist/Integrations-DUqcLKml.mjs +33 -0
  92. package/dist/KazooLogo-BVRhaQ-1.mjs +38 -0
  93. package/dist/KnowYourAudience-jvdpa8Co.mjs +91 -0
  94. package/dist/Launch-C5QbSdJn.mjs +83 -0
  95. package/dist/Link-CzMOWVHw.mjs +43 -0
  96. package/dist/LinkArrow-D7My064p.mjs +12 -0
  97. package/dist/Loading-C5wJAaZ-.mjs +6 -0
  98. package/dist/Lock-CrpqckDI.mjs +31 -0
  99. package/dist/Management-CfJCyzy8.mjs +87 -0
  100. package/dist/MeatballMenu-1RqUBn4Y.mjs +9 -0
  101. package/dist/MediaError-9_d5oB_T.mjs +40 -0
  102. package/dist/Messages-4waJxvel.mjs +221 -0
  103. package/dist/Microphone-8fk2NyjC.mjs +63 -0
  104. package/dist/Mobile-B7UDVCjR.mjs +31 -0
  105. package/dist/Nomination-DyVMjiwX.mjs +12 -0
  106. package/dist/NominationsAndAwards-DV8lxdIs.mjs +57 -0
  107. package/dist/Notification-DgAbq7ar.mjs +28 -0
  108. package/dist/Okrs-B5p8LEMY.mjs +55 -0
  109. package/dist/Pause-B7pDb0Ur.mjs +12 -0
  110. package/dist/PeerToPeer-EFRm2-Ns.mjs +64 -0
  111. package/dist/Pencil-6UZn-x0W.mjs +25 -0
  112. package/dist/People-DOYJOgS0.mjs +43 -0
  113. package/dist/PerformanceManagement-DavgifML.mjs +57 -0
  114. package/dist/Pin-C0KIHJ16.mjs +24 -0
  115. package/dist/PinnedIconAward-DUe5bm5u.mjs +20 -0
  116. package/dist/PinnedIconBrightIdea-BNdCStK9.mjs +20 -0
  117. package/dist/PinnedIconBullseye-DD7dZCoQ.mjs +36 -0
  118. package/dist/PinnedIconChampagne-HIJE7Yf3.mjs +20 -0
  119. package/dist/PinnedIconCheer-Pmd1imX0.mjs +20 -0
  120. package/dist/PinnedIconCrown-CPwPqzC4.mjs +20 -0
  121. package/dist/PinnedIconDiamond-D00JW81W.mjs +20 -0
  122. package/dist/PinnedIconHoleInOne-D6jh0Ane.mjs +20 -0
  123. package/dist/PinnedIconMedal-CEc_ezUs.mjs +20 -0
  124. package/dist/PinnedIconMetrics-CDU1uqhK.mjs +20 -0
  125. package/dist/PinnedIconPin-CSCDM0mw.mjs +20 -0
  126. package/dist/PinnedIconRockAndRoll-CQxSgO5d.mjs +23 -0
  127. package/dist/PinnedIconRocket-B1tXrzTg.mjs +20 -0
  128. package/dist/PinnedIconStrength-CVyMBzjV.mjs +20 -0
  129. package/dist/PinnedIconTeddyBear-C1YYmDoh.mjs +20 -0
  130. package/dist/PlatformLogo-0AOI2Cr9.mjs +57 -0
  131. package/dist/Plus-Dgh_a2E8.mjs +19 -0
  132. package/dist/Popper-DAaZXie8.mjs +1118 -0
  133. package/dist/PrivateEye-BUgV7GQk.mjs +127 -0
  134. package/dist/PrivatePushPin-C4ph6ZhF.mjs +33 -0
  135. package/dist/Processing-DOgV5nVT.mjs +80 -0
  136. package/dist/Productivity-BZuPAu6h.mjs +41 -0
  137. package/dist/ProgressCircle-C1bIKxWu.mjs +12 -0
  138. package/dist/PulseSurvey-YW8pgO3g.mjs +48 -0
  139. package/dist/PushPin-C0Vt7Qgz.mjs +18 -0
  140. package/dist/QuotesLeft-BrcaBZPo.mjs +18 -0
  141. package/dist/QuotesRight-VYMthud9.mjs +18 -0
  142. package/dist/Recognition-BLb29jsR.mjs +38 -0
  143. package/dist/Recognition-BlojPoTY.mjs +76 -0
  144. package/dist/Retention-D04eGyj2.mjs +47 -0
  145. package/dist/Rewards-BQ_4-Xnm.mjs +67 -0
  146. package/dist/Rewards-Cbm9UlJN.mjs +54 -0
  147. package/dist/RewardsCatalog-6bMpoD6s.mjs +49 -0
  148. package/dist/Roadmap-DK7G7m1M.mjs +122 -0
  149. package/dist/Search-BL5oOF1V.mjs +14 -0
  150. package/dist/Security-C7DgqkmM.mjs +33 -0
  151. package/dist/SendRecognition-CXWoOD5B.mjs +5 -0
  152. package/dist/ShareLink-DsdD7S2M.mjs +27 -0
  153. package/dist/SidebarCollapse-BycFfuBy.mjs +48 -0
  154. package/dist/Skill-C9DRN5_x.mjs +23 -0
  155. package/dist/Skills-Bf7uNero.mjs +68 -0
  156. package/dist/Smiley-C0W0nvQw.mjs +84 -0
  157. package/dist/Stop-B6-Rv84N.mjs +178 -0
  158. package/dist/Survey-B1ICwGfc.mjs +59 -0
  159. package/dist/Surveys-BygAscLB.mjs +54 -0
  160. package/dist/SyncUps-DNmrE_No.mjs +30 -0
  161. package/dist/Syncs-BCJtdDyW.mjs +29 -0
  162. package/dist/TalentReview-Bsf5rU5C.mjs +88 -0
  163. package/dist/TalentReview-Du4M8y3m.mjs +33 -0
  164. package/dist/TalentReviewInsights-p0rYC_2I.mjs +100 -0
  165. package/dist/TaskCompleted-DhURRWUZ.mjs +97 -0
  166. package/dist/Team-Rs8iU_vt.mjs +63 -0
  167. package/dist/Teams-BrkkrHW9.mjs +80 -0
  168. package/dist/TextBold-CgZBuifH.mjs +71 -0
  169. package/dist/TextBulletList-B6e_IEP-.mjs +128 -0
  170. package/dist/TextInput-B8AOwiHn.mjs +121 -0
  171. package/dist/TextItalic-C9jJChss.mjs +71 -0
  172. package/dist/TextNumberList-BfahObnv.mjs +147 -0
  173. package/dist/TextUnderline-n9b1v8UJ.mjs +90 -0
  174. package/dist/ThumbsDown-ZkPlc2MC.mjs +46 -0
  175. package/dist/ThumbsUp-C5EEURtj.mjs +46 -0
  176. package/dist/Toggle-CZuD0uCq.mjs +76 -0
  177. package/dist/Translate-DcOpGRTB.mjs +98 -0
  178. package/dist/Trash-CRdG3IYb.mjs +44 -0
  179. package/dist/TrendDown-CB3cl_u7.mjs +5 -0
  180. package/dist/TrendUp-D_f6etsq.mjs +5 -0
  181. package/dist/Undo-BfRfs2YI.mjs +41 -0
  182. package/dist/Unplugged-qrnvAmIJ.mjs +201 -0
  183. package/dist/UpDownCaret-CdoiwMWU.mjs +12 -0
  184. package/dist/VerifiedCheckmark-2saHRxh6.mjs +20 -0
  185. package/dist/VerticalLine-XjlxBP9Z.mjs +50 -0
  186. package/dist/Warning-B8864P6W.mjs +37 -0
  187. package/dist/WarningNoOutline-llm3ebvI.mjs +41 -0
  188. package/dist/YesAnd-DLEvdXw9.mjs +31 -0
  189. package/dist/ai-assistant.css +1 -0
  190. package/dist/emoji-CJuSGYZk.mjs +2310 -0
  191. package/dist/express.js +10936 -0
  192. package/dist/html2canvas.esm-DgdJBc_o.mjs +4871 -0
  193. package/dist/index-BEKNcH9V.mjs +721 -0
  194. package/dist/react-apexcharts.min-DLm6NZyI.mjs +11326 -0
  195. package/dist/react.es.js +15 -0
  196. package/dist/react.umd.js +1691 -0
  197. package/dist/reactComponent-CGfCiP84.mjs +44091 -0
  198. package/express.d.ts +88 -1
  199. package/express.js +4 -1
  200. package/generated/apiHooks.tsx +5644 -0
  201. package/generated/sdk.ts +5119 -0
  202. package/generated/stitchedSdk.ts +1174 -0
  203. package/package.json +46 -21
  204. package/react.d.ts +215 -0
  205. package/react.js +4 -1
  206. package/sharedTypes.ts +386 -0
package/package.json CHANGED
@@ -1,38 +1,63 @@
1
1
  {
2
2
  "name": "@worktango/ai-assistant",
3
- "version": "0.0.1",
4
- "main": "dist/ai-assistant.umd.js",
5
- "module": "dist/ai-assistant.es.js",
6
- "types": "react.d.ts",
3
+ "version": "0.0.2-beta-gd2",
7
4
  "files": [
8
- "dist/*",
9
- "react.js",
10
- "react.d.ts",
5
+ "backendTypes.ts",
6
+ "constants.js",
7
+ "dist",
8
+ "express.d.ts",
11
9
  "express.js",
12
- "express.d.ts"
10
+ "generated",
11
+ "react.d.ts",
12
+ "react.js",
13
+ "sharedTypes.ts"
13
14
  ],
14
15
  "scripts": {
15
- "checkIfPublishable": "git status --porcelain | grep . && echo 'Dirty tree. Aborting.' && exit 1 || exit 0",
16
16
  "dev": "vite --config vite.config.ts src/dev",
17
17
  "dev:backend": "nodemon express.js",
18
- "build:backend": "esbuild src/backend/express.ts --bundle --platform=node --outfile=dist/express.js \"--external:*\"",
18
+ "build:backend": "esbuild src/backend/express.ts --bundle --platform=node --outfile=dist/express.js \"--external:express\"",
19
19
  "build:frontend": "vite build",
20
- "build": "yarn build:backend && yarn build:frontend && yarn ts-node -T scripts/injectCss.ts",
21
- "prepareForPublish": "yarn ts-node -T scripts/prepareForPublish.ts",
22
- "prepublishOnly": "yarn checkIfPublishable && rm -rf dist && yarn build",
23
- "publish": "yarn prepareForPublish && yarn npm publish --access public --tolerate-republish; git reset --hard HEAD"
20
+ "build:all": "rm -rf dist && yarn build:backend && yarn build:frontend && yarn ts-node -T scripts/injectCssIntoBuild.ts",
21
+ "prepareBuildForPublish": "yarn ts-node -T scripts/prepareBuildForPublish.ts",
22
+ "publish": "yarn build:all && yarn prepareBuildForPublish && yarn actuallyPublishPackage",
23
+ "actuallyPublishPackage": "yarn npm publish --access public --tolerate-republish",
24
+ "gql:generate": "gql-generate",
25
+ "link:pulse-web": "bash scripts/linkToPulseWeb.sh"
24
26
  },
25
27
  "dependencies": {
26
- "express": "4.21.2",
27
- "react": "18"
28
+ "@apollo/client": "^3.0.0",
29
+ "@ricky0123/vad-react": "^0.0.28",
30
+ "@sinclair/typebox": "^0.34",
31
+ "apexcharts": "^4.7.0",
32
+ "classnames": "^2.2.6",
33
+ "dom-to-semantic-markdown": "^1.3",
34
+ "html2canvas": "^1.4.1",
35
+ "http-proxy-middleware": "^3",
36
+ "json-nd": "^1",
37
+ "lodash.clonedeep": "^4",
38
+ "micromark": "^4",
39
+ "micromark-extension-gfm-table": "^2.1.1",
40
+ "react-apexcharts": "^1.7.0",
41
+ "uuid": "^9"
28
42
  },
29
43
  "devDependencies": {
30
- "@types/react": "^18",
31
44
  "@vitejs/plugin-react": "^4.2.1",
32
45
  "esbuild": "^0.17.11",
33
- "ts-node": "^10.9.1",
34
- "typescript": "~5.6",
35
- "vite": "~6.2.4",
36
- "vite-plugin-css-modules": "0.0.1"
46
+ "ts-node": "^10.9.2",
47
+ "typescript": "~5.8",
48
+ "vite": "~6.3.5"
49
+ },
50
+ "graphqlCodeGeneration": {
51
+ "apiHooks": {
52
+ "config": {
53
+ "enumsAsTypes": true
54
+ }
55
+ }
56
+ },
57
+ "$schema": "../../packages/build-tools/schema.json",
58
+ "peerDependencies": {
59
+ "express": ">=4",
60
+ "react": ">=18",
61
+ "react-dom": ">=18"
37
62
  }
38
63
  }
package/react.d.ts ADDED
@@ -0,0 +1,215 @@
1
+ import type { TSchema, Type, Static } from "@sinclair/typebox";
2
+ import {
3
+ AiAssistantProps,
4
+ ChatData,
5
+ ChatItem,
6
+ GetChatCompletionOptions,
7
+ GetStructuredResponseOptions,
8
+ ToolDeclaration,
9
+ AiAssistantSuggestedPromptsProps,
10
+ GetFollowUpSuggestions,
11
+ ChatDataFile,
12
+ } from "./sharedTypes";
13
+
14
+ export const getDefaultGetFollowUpSuggestions: (args: {
15
+ promptOverride?: string;
16
+ }) => GetFollowUpSuggestions;
17
+
18
+ export function AiAssistant(args: AiAssistantProps): JSX.Element;
19
+
20
+ export function AiAssistantSuggestedPrompts(
21
+ args: AiAssistantSuggestedPromptsProps
22
+ ): JSX.Element;
23
+
24
+ /**
25
+ * IMPORTANT: These types must be kept in sync with the source files:
26
+ * - AiResponseRating and GenAIRatingComponentProps are defined in src/frontend/components/GenAIRatingComponent.tsx
27
+ * - GenAIRatingComponentApolloWrappedProps is defined in src/frontend/components/GenAIRatingComponentApolloWrapped.tsx
28
+ *
29
+ * When updating these types in the source, you MUST also update them here.
30
+ */
31
+
32
+ export interface AiResponseRating {
33
+ id: string;
34
+ userRating?: "THUMBS_UP" | "THUMBS_DOWN" | null;
35
+ userComment?: string | null;
36
+ }
37
+
38
+ export interface GenAIRatingComponentProps {
39
+ responseType: "WTC_MESSAGE" | "SURVEY_SUMMARY" | "COMMENTS_SUMMARY";
40
+ responseId: string;
41
+ genAiMessage: string;
42
+ genAiMessageTimestamp: string;
43
+ onSubmitRating: (input: any) => Promise<any>;
44
+ isLoading?: boolean;
45
+ error?: Error;
46
+ aiResponseRating?: AiResponseRating | null;
47
+ }
48
+
49
+ export type GenAIRatingComponentApolloWrappedProps = Omit<
50
+ GenAIRatingComponentProps,
51
+ "onSubmitRating" | "isLoading" | "error" | "aiResponseRating"
52
+ > & {
53
+ /**
54
+ * Optional CSS value for the top position of success/error toasts.
55
+ *
56
+ * Use this to position toasts below fixed headers or other UI elements that might
57
+ * obscure them. Accepts any valid CSS top value (e.g., "80px", "5rem", "10%").
58
+ *
59
+ * @example
60
+ * // Position toasts 80px from the top, below a fixed admin header
61
+ * <GenAIRatingComponentApolloWrapped
62
+ * responseType="WTC_MESSAGE"
63
+ * responseId={id}
64
+ * genAiMessage={message}
65
+ * genAiMessageTimestamp={timestamp}
66
+ * toastTop="80px"
67
+ * />
68
+ *
69
+ * @default undefined (uses the default toast position from Confetti)
70
+ */
71
+ toastTop?: string;
72
+ };
73
+
74
+ export function GenAIRatingComponent(
75
+ args: GenAIRatingComponentProps
76
+ ): JSX.Element;
77
+
78
+ export function GenAIRatingComponentApolloWrapped(
79
+ args: GenAIRatingComponentApolloWrappedProps
80
+ ): JSX.Element;
81
+
82
+ export const tools: {
83
+ kazooTools: {
84
+ getRewardsAndRecognitionCurrentUserTool: ToolDeclaration;
85
+ };
86
+ sharedTools: {
87
+ doMathTool: ToolDeclaration;
88
+ getCurrentTimeTool: ToolDeclaration;
89
+ askSingleShotQuestion: ToolDeclaration;
90
+ analyzeCurrentPage: ToolDeclaration;
91
+ };
92
+ /**
93
+ * Helper function to define a new tool for the AI Assistant.
94
+ *
95
+ * The tool's name, description, and the full schema of its parameters (including
96
+ * their descriptions) are sent to the LLM at the beginning of every interaction.
97
+ * The LLM uses this information to understand what the tool does and decide
98
+ * when and how to call it.
99
+ *
100
+ * Providing a clear, descriptive tool `description` and detailed descriptions
101
+ * for each field in the `parameters` object is essential for reliable tool calling.
102
+ */
103
+ createTool<TParams extends TSchema = TSchema>(args: {
104
+ name: string;
105
+ /**
106
+ * A description of the tool that is provided to the LLM.
107
+ * This tells the LLM what the tool is capable of getting or doing, helping it
108
+ * decide when to invoke it.
109
+ */
110
+ description: string;
111
+ /**
112
+ * A user-friendly, present-tense name for the tool (e.g., "Performing calculations").
113
+ * This is shown in the AI Assistant UI while the tool is executing.
114
+ */
115
+ displayName: string;
116
+ /**
117
+ * A user-friendly, past-tense name for the tool (e.g., "Performed calculations").
118
+ * This is shown in the AI Assistant's debug mode after the tool has finished executing.
119
+ */
120
+ pastTenseDisplayName: string;
121
+ /**
122
+ * A function that returns a JSON schema (using TypeBox) defining the arguments
123
+ * required by the tool. Each field in the schema should include a `description`
124
+ * to help the LLM provide accurate values.
125
+ */
126
+ parameters?: (t: typeof Type) => TParams;
127
+ /**
128
+ * The implementation function for the tool. This is called when the LLM
129
+ * decides to invoke the tool.
130
+ */
131
+ fulfill: (args: Static<TParams>) => Promise<string | ChatDataFile>;
132
+ /**
133
+ * Currently unused. Investigate intent and potential removal before using.
134
+ */
135
+ chatItemMatches?: (chatItem: ChatItem) => boolean;
136
+ }): ToolDeclaration;
137
+ } = {};
138
+
139
+ export const config: {
140
+ /**
141
+ * Get the URL for the LLM call.
142
+ */
143
+ getLlmCallUrl: () => string;
144
+ /**
145
+ * Get the URL for the structured response call.
146
+ */
147
+ getStructuredResponseUrl: () => string;
148
+ /**
149
+ * Get the URL for the Kazoo service.
150
+ */
151
+ getKazooUrl: (urlPath: string) => string;
152
+ /**
153
+ * Get the URL for the Pulse service.
154
+ */
155
+ getPulseUrl: (urlPath: string) => string;
156
+ /**
157
+ * Get the Pulse bearer token.
158
+ */
159
+ getPulseBearerToken: () => string;
160
+ /**
161
+ * Set the strategy for getting Kazoo URLs.
162
+ */
163
+ setKazooUrlStrategy: (strategy: (urlPath: string) => string) => void;
164
+ /**
165
+ * Set the strategy for getting LLM call URLs.
166
+ */
167
+ setLlmCallUrlStrategy: (strategy: (path: string) => string) => void;
168
+ /**
169
+ * Set the strategy for getting Pulse URLs.
170
+ */
171
+ setPulseUrlStrategy: (strategy: (urlPath: string) => string) => void;
172
+ /**
173
+ * Set the strategy for getting Pulse bearer tokens.
174
+ */
175
+ setPulseBearerTokenStrategy: (strategy: () => string) => void;
176
+ /**
177
+ * Set the strategy for getting structured response URLs.
178
+ */
179
+ setStructuredResponseUrlStrategy: (
180
+ strategy: (path: string) => string
181
+ ) => void;
182
+ /**
183
+ * Set the main content selector for the page for when taking screenshots.
184
+ */
185
+ setScreenshotMainContentSelector: (selector: string) => void;
186
+ /**
187
+ * Get the main content selector for the page for when taking screenshots.
188
+ */
189
+ getScreenshotMainContentSelector: () => string;
190
+ /**
191
+ * Set the strategy for getting synthesize URLs.
192
+ */
193
+ setSynthesizeUrlStrategy: (strategy: () => string) => void;
194
+ /**
195
+ * Set the strategy for getting transcribe URLs.
196
+ */
197
+ setTranscribeUrlStrategy: (strategy: () => string) => void;
198
+ } = {};
199
+
200
+ /**
201
+ * Makes a structured response request to the LLM API.
202
+ */
203
+ export function getStructuredResponse<T extends TSchema>(
204
+ args: GetStructuredResponseOptions<T>
205
+ ): Promise<Static<T>>;
206
+
207
+ /**
208
+ * Makes a chat completion request to the LLM API. Can be used both with streaming and non-streaming responses.
209
+ * For streaming responses, provides callbacks for handling chunks and errors.
210
+ */
211
+ export function getChatCompletion(
212
+ args: GetChatCompletionOptions
213
+ ): Promise<ChatData[]>;
214
+
215
+ export * from "./sharedTypes";
package/react.js CHANGED
@@ -1 +1,4 @@
1
- export { AiAssistant } from "./dist/react.es.js";
1
+ // istanbul ignore file - for public bundles only
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-ignore
4
+ module.exports = require("./dist/react.umd.js");
package/sharedTypes.ts ADDED
@@ -0,0 +1,386 @@
1
+ // Don't import from the generated folder, as it is removed when we build and publish the package.
2
+
3
+ import type { Static, TSchema, Type } from "@sinclair/typebox";
4
+
5
+ export type Maybe<T> = T | undefined;
6
+ export interface Scalars {
7
+ ID: string;
8
+ String: string;
9
+ Boolean: boolean;
10
+ Int: number;
11
+ Float: number;
12
+ Upload: any;
13
+ /** All dates within this schema are ISO-8601 strings without time or timezone. */
14
+ Date: any;
15
+ /** All date-times are supposed to be are ISO-8601 strings, but we do accept input in other formats. That behavior will change and we will replace Date and DateTime's behavior with that of StrictDate. */
16
+ DateTime: any;
17
+ /** A datetime input and output type only accepts ISO-8601 dates. */
18
+ StrictDateTimeInput: string;
19
+ /** General-use Upload input scalar */
20
+ FileToUpload: any;
21
+ /** General-use scalar to use for fields of JSON data. See https://www.npmjs.com/package/graphql-type-json for more information. */
22
+ JSONObject: any;
23
+ /** Represents a rich text document in its native ProseMirror document format. This is a JSON object with a specific schema. Use a TipTap editor instance from the @kazoohr/richtext-components package to interact with this format. */
24
+ RichTextDocument: any;
25
+ }
26
+
27
+ export type AiAssistantConversationMessageRole =
28
+ /** A message that was sent by the LLM */
29
+ | "MODEL"
30
+ /** A message comes from tool calling. */
31
+ | "TOOL"
32
+ /** A message that was sent by the user. */
33
+ | "USER";
34
+
35
+ export interface Message {
36
+ __typename?: "Message";
37
+ /** The unique identifier of the message. */
38
+ id: Scalars["ID"];
39
+ /** The role of the message. */
40
+ role: AiAssistantConversationMessageRole;
41
+ /** The text content of the message. */
42
+ messageText: Scalars["String"];
43
+ /** The conversation that the message belongs to. */
44
+ conversationId: Scalars["String"];
45
+ /** Optional metadata for the message to store such as toolNames etc */
46
+ metadata?: Maybe<Scalars["JSONObject"]>;
47
+ }
48
+
49
+ export type AiAssistantSuggestedPromptsProps = {
50
+ suggestedPrompts: Record<string, AiAssistantSuggestedPrompt[]>;
51
+ onSelect: (prompt: AiAssistantSuggestedPrompt) => void | Promise<void>;
52
+ includeGlobalPrompts?: boolean;
53
+ };
54
+
55
+ export type AiAssistantSuggestedPrompt = {
56
+ title: string;
57
+ fullPrompt?: string;
58
+ // Allow customization of the suggested action button in the UI
59
+ className?: string;
60
+ };
61
+
62
+ export type SupportedTextModel = "small" | "medium" | "large";
63
+
64
+ export type ChatItem = {
65
+ role: "user" | "model" | "tool";
66
+ parts: ChatData[];
67
+ };
68
+
69
+ export type ToolDeclaration<TParams extends TSchema = TSchema> = {
70
+ name: string;
71
+ description: string;
72
+ /**
73
+ * A user-friendly, present-tense name for the tool (e.g., "Performing calculations").
74
+ * This is shown in the AI Assistant UI while the tool is executing.
75
+ */
76
+ displayName: string;
77
+ /**
78
+ * A user-friendly, past-tense name for the tool (e.g., "Performed calculations").
79
+ * This is shown in the AI Assistant's debug mode after the tool has finished executing.
80
+ */
81
+ pastTenseDisplayName: string;
82
+ parameters?: any;
83
+ /**
84
+ * Currently unused. Investigate intent and potential removal before using.
85
+ */
86
+ chatItemMatches?: (chatItem: {
87
+ role: "user" | "model" | "tool";
88
+ parts: ChatData[];
89
+ }) => boolean;
90
+ fulfill: (result: Static<TParams>) => Promise<string | ChatDataFile>;
91
+ };
92
+
93
+ /**
94
+ * Debug info added during the execution of the AI assistant.
95
+ */
96
+ export type DebugInfo = {
97
+ time: Date;
98
+ message: string;
99
+ data?: any;
100
+ level: "info" | "error" | "warn";
101
+ }[];
102
+
103
+ export type PropRefs = {
104
+ onAfterLlmCall?: (messages: Omit<Message, "__typename">[]) => void;
105
+ onBeforeLlmCall?: () => void;
106
+ onError?: (error: Error) => void;
107
+ onChunkAdded?: () => void;
108
+ tools?: ToolDeclaration[];
109
+ model?: SupportedTextModel;
110
+ /**
111
+ * The current state of the chat.
112
+ *
113
+ * When to access this:
114
+ * - When you're in async handler functions
115
+ * - When you're in callbacks
116
+ *
117
+ * When NOT to access this:
118
+ * - When you're in anywhere in the UI state rendering path
119
+ *
120
+ * If you're rendering the UI, use the `messages` prop, please. This is for
121
+ * AI assistant state, which often requires up-to-date state for making
122
+ * updates.
123
+ */
124
+ messages: ChatStateTree;
125
+ temperature?: number;
126
+ isMounted: boolean;
127
+ systemInstruction?: () => string | Promise<string>;
128
+ getConversationById: (
129
+ conversationId: string
130
+ ) => ChatStateTree[string] | undefined;
131
+ getFollowUpSuggestions?: GetFollowUpSuggestions;
132
+ setFollowUpSuggestionsByConversationId: React.Dispatch<
133
+ React.SetStateAction<Record<string, FollowUpSuggestion[]>>
134
+ >;
135
+ handleSendUserMessage: (args: {
136
+ conversationId?: string;
137
+ messageText: string;
138
+ }) => Promise<void>;
139
+ setPrompt: (
140
+ conversationId: string | undefined,
141
+ prompt: string | ((prev: string) => string)
142
+ ) => void;
143
+ onSelectedConversationChange?: (
144
+ conversationId: string | undefined,
145
+ messages: ChatStateTree
146
+ ) => void;
147
+ selectedConversationId: string | undefined;
148
+ onSelectedConversationLoaded?: (
149
+ /**
150
+ * The conversation that loaded.
151
+ */
152
+ conversationId: string | undefined,
153
+ /**
154
+ * The conversation that is currently selected
155
+ */
156
+ selectedConversationId: string | undefined,
157
+ messages: ChatStateTree
158
+ ) => void;
159
+ sendMessages: (conversationId: string) => Promise<boolean>;
160
+ setMessages: React.Dispatch<React.SetStateAction<ChatStateTree>>;
161
+ };
162
+
163
+ export type ChatData =
164
+ | ChatDataText
165
+ | ChatDataToolCall
166
+ | ChatDataToolResult
167
+ | ChatDataFile;
168
+
169
+ export type ChatDataText = { type: "text"; text: string };
170
+
171
+ export type ChatDataFile = {
172
+ type: "file";
173
+ toolName: string;
174
+ fileUri: string;
175
+ mimeType: string;
176
+ args?: unknown;
177
+ };
178
+
179
+ export type ChatDataToolCall = {
180
+ type: "toolCall";
181
+ toolName: string;
182
+ args: Record<string, unknown>;
183
+ };
184
+
185
+ export type ChatDataToolResult = {
186
+ type: "toolResult";
187
+ toolName: string;
188
+ args?: unknown;
189
+ result: any;
190
+ };
191
+
192
+ export type ChatHistoryItem = {
193
+ title: string;
194
+ messages: any[];
195
+ [key: string]: any;
196
+ };
197
+
198
+ export type GetFollowUpSuggestions = (args: {
199
+ conversation: ChatStateTree[string];
200
+ }) => Promise<AiAssistantSuggestedPrompt[]>;
201
+
202
+ export type ChatHistory = Record<string, ChatHistoryItem[]>;
203
+
204
+ export type ChatSizes = "half" | "full";
205
+
206
+ export type AiAssistantControls = {
207
+ /**
208
+ * Set the prompt to use for the AI assistant.
209
+ * @param prompt - The prompt to set.
210
+ * @param submit - Whether to submit the prompt to the AI assistant once the new prompt is set.
211
+ */
212
+ setPrompt?: (prompt: string, submit?: boolean) => void;
213
+ };
214
+
215
+ export type AiAssistantProps = {
216
+ /**
217
+ * The title to display in the window. Default: "WorkTango AI Assistant".
218
+ */
219
+ windowTitle?: React.ReactNode;
220
+ /**
221
+ * The full suite of tools to use for the AI assistant.
222
+ */
223
+ tools?: ToolDeclaration<any>[];
224
+ /**
225
+ * Whether to enable debug mode. Default: false.
226
+ */
227
+ enableDebug?: boolean;
228
+ /**
229
+ * Whether to enable voice features. Default: false.
230
+ */
231
+ enableVoiceFeatures?: boolean;
232
+ /**
233
+ * The function to call when the AI assistant is closed.
234
+ */
235
+ onClose: () => void;
236
+ /**
237
+ * This is a callback event that is invoked when the user sends a message.
238
+ */
239
+ onSendMessage?: (message: string) => void;
240
+ /**
241
+ * Whether to show a close button in the chat window. Default: true.
242
+ */
243
+ hasCloseButton?: boolean;
244
+ /**
245
+ * The zero state to display when the chat window is empty.
246
+ */
247
+ chatWindowZeroState?: React.ReactNode;
248
+ /**
249
+ * Whether to show a button to toggle the chat size. Default: true.
250
+ */
251
+ hasToggleChatSizeButton?: boolean;
252
+ /**
253
+ * If true, the chat history (list of past conversations) will be shown, by default
254
+ */
255
+ hasChatHistory?: boolean;
256
+ /**
257
+ * The initial width of the chat window. Default: "default".
258
+ */
259
+ startingWidth?: ChatSizes;
260
+ /**
261
+ * The system instruction to use for the AI assistant.
262
+ */
263
+ systemInstruction?: () => string | Promise<string>;
264
+ /**
265
+ * The initial prompt to use for the AI assistant.
266
+ */
267
+ initialPrompt?: string;
268
+ /**
269
+ * A ref to the controls object for the AI assistant. Used to allow some form
270
+ * of control over the AI assistant from outside the component, allowing things
271
+ * like recommended prompts to be set from outside the component.
272
+ */
273
+ controls?: React.MutableRefObject<AiAssistantControls>;
274
+ /**
275
+ * Whether to show the chat history by default. Default: true.
276
+ */
277
+ chatHistoryShownByDefault?: boolean;
278
+ /**
279
+ * Otherwise, if there's a chat history, we start with the latest history, so
280
+ * the user can continue the previous conversation.
281
+ */
282
+ startWithNewChat?: boolean;
283
+ /**
284
+ * The minimum number of characters that must be entered before the user can
285
+ * submit a message. Default: 5.
286
+ */
287
+ minimumCharacterCount?: number;
288
+ /**
289
+ * The ID of the conversation to start with. If not provided, a new conversation will be created.
290
+ */
291
+ initialConversationId?: string;
292
+ /**
293
+ * Returns a set of follow-up suggestions for the given conversation.
294
+ */
295
+ getFollowUpSuggestions?: GetFollowUpSuggestions;
296
+ /**
297
+ * Invoked with a raw string of the chat (in plain text) to get a possible title
298
+ */
299
+ getChatTitle?: (chat: string) => Promise<string>;
300
+ /**
301
+ * The model size to use for the AI assistant. Default: "large".
302
+ */
303
+ model?: SupportedTextModel;
304
+ /**
305
+ * Whether to enable the AI response rating component. Default: false.
306
+ * Cannot bundle feature-flags-react in packages/ai-assistant so this is how we have to pass feature flags to the Ai Assistant.
307
+ */
308
+ enableResponseRating?: boolean;
309
+ };
310
+
311
+ export type ChatStateTree = Record<
312
+ string,
313
+ {
314
+ id: string;
315
+ title: string;
316
+ isUpdatingTitle?: boolean;
317
+ updatedAt: Date;
318
+ isLoading: boolean;
319
+ messages: Omit<Message, "__typename">[];
320
+ }
321
+ >;
322
+
323
+ // ChatItem augmented with some UI stuff
324
+ export type AugmentedChatItem = ChatItem & {
325
+ id?: string;
326
+ timestamp?: Date;
327
+ isPending?: boolean;
328
+ filterFromApiCalls?: boolean;
329
+ };
330
+
331
+ /**
332
+ * If { loading: true }, a small loader will be shown. You can use this show a
333
+ * loading state in any place of the UI.
334
+ */
335
+ export type FollowUpSuggestion =
336
+ | { type: "loading"; id?: string }
337
+ | {
338
+ type?: "suggestion";
339
+ /**
340
+ * A unique identifier for the follow-up suggestion. This will be used to keep user-level state for dismissed items.
341
+ */
342
+ id: string;
343
+ /**
344
+ * The title of the follow-up suggestion. This will be displayed in the UI as a pill button, so keep it short.
345
+ */
346
+ title: string;
347
+ /**
348
+ * The function to call when the follow-up suggestion is clicked.
349
+ */
350
+ onClick: () => void;
351
+ /**
352
+ * Optional CSS class name for custom styling of the pill.
353
+ */
354
+ className?: string;
355
+ };
356
+
357
+ export interface Conversation {
358
+ id: string;
359
+ title: string;
360
+ updatedAt?: Date;
361
+ messages: {
362
+ conversationId: string;
363
+ id: string;
364
+ messageText: string;
365
+ role: string;
366
+ }[];
367
+ }
368
+
369
+ export type GetStructuredResponseOptions<T extends TSchema> = {
370
+ model?: SupportedTextModel | undefined;
371
+ temperature?: number | undefined;
372
+ prompt: string;
373
+ schema: (t: typeof Type) => T;
374
+ };
375
+
376
+ export type GetChatCompletionOptions = {
377
+ model?: SupportedTextModel | undefined;
378
+ temperature?: number | undefined;
379
+ systemInstruction?: string | undefined;
380
+ stream?: boolean;
381
+ messages: ChatItem[];
382
+ tools?: ToolDeclaration[] | undefined;
383
+ onChunk?: (chunk: ChatData) => void;
384
+ onError?: (error: Error) => void;
385
+ onComplete?: () => void;
386
+ };