@pickaxeproject/react 0.0.1 → 0.0.2

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 (58) hide show
  1. package/README.md +6 -0
  2. package/dist/cjs/_virtual/_tslib.js +1 -0
  3. package/dist/cjs/common/api/index.d.ts +2 -0
  4. package/dist/cjs/common/api/index.js +1 -0
  5. package/dist/cjs/common/api/streamer.d.ts +7 -0
  6. package/dist/cjs/common/api/utils.d.ts +2 -0
  7. package/dist/cjs/common/cn.js +1 -0
  8. package/dist/cjs/common/env.d.ts +2 -0
  9. package/dist/cjs/common/env.js +1 -0
  10. package/dist/cjs/common/utils.d.ts +1 -0
  11. package/dist/cjs/components/Pickaxe/index.d.ts +4 -2
  12. package/dist/cjs/components/Pickaxe/index.js +1 -1
  13. package/dist/cjs/hooks/useConversation.d.ts +8 -0
  14. package/dist/cjs/hooks/useHistory.d.ts +11 -0
  15. package/dist/cjs/hooks/usePickaxe.d.ts +7 -0
  16. package/dist/cjs/hooks/usePickaxe.js +1 -0
  17. package/dist/cjs/hooks/usePickaxeContext.d.ts +16 -0
  18. package/dist/cjs/hooks/usePickaxeContext.js +1 -0
  19. package/dist/cjs/hooks/useSubmit.d.ts +23 -0
  20. package/dist/cjs/hooks/useSubmitDocument.d.ts +16 -0
  21. package/dist/cjs/hooks/useSubmitResult.d.ts +27 -0
  22. package/dist/cjs/providers/PickaxeProvider.d.ts +25 -0
  23. package/dist/cjs/providers/PickaxeProvider.js +1 -0
  24. package/dist/cjs/types/chat.d.ts +8 -0
  25. package/dist/cjs/types/common.d.ts +2 -0
  26. package/dist/cjs/types/form.d.ts +37 -0
  27. package/dist/cjs/types/history.d.ts +37 -0
  28. package/dist/cjs/types/pickaxe.d.ts +59 -0
  29. package/dist/esm/_virtual/_tslib.js +1 -0
  30. package/dist/esm/common/api/index.d.ts +2 -0
  31. package/dist/esm/common/api/index.js +1 -0
  32. package/dist/esm/common/api/streamer.d.ts +7 -0
  33. package/dist/esm/common/api/utils.d.ts +2 -0
  34. package/dist/esm/common/cn.js +1 -0
  35. package/dist/esm/common/env.d.ts +2 -0
  36. package/dist/esm/common/env.js +1 -0
  37. package/dist/esm/common/utils.d.ts +1 -0
  38. package/dist/esm/components/Pickaxe/index.d.ts +4 -2
  39. package/dist/esm/components/Pickaxe/index.js +1 -1
  40. package/dist/esm/hooks/useConversation.d.ts +8 -0
  41. package/dist/esm/hooks/useHistory.d.ts +11 -0
  42. package/dist/esm/hooks/usePickaxe.d.ts +7 -0
  43. package/dist/esm/hooks/usePickaxe.js +1 -0
  44. package/dist/esm/hooks/usePickaxeContext.d.ts +16 -0
  45. package/dist/esm/hooks/usePickaxeContext.js +1 -0
  46. package/dist/esm/hooks/useSubmit.d.ts +23 -0
  47. package/dist/esm/hooks/useSubmitDocument.d.ts +16 -0
  48. package/dist/esm/hooks/useSubmitResult.d.ts +27 -0
  49. package/dist/esm/providers/PickaxeProvider.d.ts +25 -0
  50. package/dist/esm/providers/PickaxeProvider.js +1 -0
  51. package/dist/esm/types/chat.d.ts +8 -0
  52. package/dist/esm/types/common.d.ts +2 -0
  53. package/dist/esm/types/form.d.ts +37 -0
  54. package/dist/esm/types/history.d.ts +37 -0
  55. package/dist/esm/types/pickaxe.d.ts +59 -0
  56. package/package.json +7 -2
  57. /package/dist/cjs/{utils → common}/cn.d.ts +0 -0
  58. /package/dist/esm/{utils → common}/cn.d.ts +0 -0
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
1
  # Pickaxe - React
2
2
 
3
3
  > Client utility library for Pickaxe
4
+
5
+ ## How to publish
6
+
7
+ - push to main branhc
8
+
9
+ - merge auto-generated PR
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),"function"==typeof SuppressedError&&SuppressedError,exports.__awaiter=function(e,t,n,r){return new(n||(n=Promise))((function(o,u){function c(e){try{s(r.next(e))}catch(e){u(e)}}function i(e){try{s(r.throw(e))}catch(e){u(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,i)}s((r=r.apply(e,t||[])).next())}))};
@@ -0,0 +1,2 @@
1
+ declare const api: import("axios").AxiosInstance;
2
+ export default api;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("axios"),t=require("../env.js");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(e);const o=t.getEnv("API_URL");if(!o)throw new Error("[px/react] API_URL is not defined");const s=t.getEnv("PICKAXE_SESSION_TOKEN");if(!s)throw new Error("[px/react] SESSION_TOKEN is not defined");const i=n.default.create(Object.assign({baseURL:o},t.isDevelopment&&s&&{headers:{"x-pickaxe-session-token":s}}));exports.default=i;
@@ -0,0 +1,7 @@
1
+ interface StreamerOptions {
2
+ formId: string;
3
+ responseId: string;
4
+ data: string;
5
+ }
6
+ export declare const streamer: (payload: StreamerOptions) => Promise<Response>;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const apiUtils: import("axios").AxiosInstance;
2
+ export default apiUtils;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("clsx"),r=require("tailwind-merge");exports.default=(...t)=>r.twMerge(e.clsx(t));
@@ -0,0 +1,2 @@
1
+ export declare const getEnv: (key: string) => string | null;
2
+ export declare const isDevelopment: boolean;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=e=>process.env[e]||process.env[`NEXT_PUBLIC_${e}`]||process.env[`VITE_${e}"`]||process.env[`REACT_APP_${e}`]||null,s="development"===e("NODE_ENV");exports.getEnv=e,exports.isDevelopment=s;
@@ -0,0 +1 @@
1
+ export declare const generateId: (length: number, prefix?: string, suffix?: string) => string;
@@ -1,4 +1,6 @@
1
1
  export interface PickaxeProps {
2
- pickaxeId: string;
2
+ formId: string;
3
+ chatId?: string;
4
+ className?: string;
3
5
  }
4
- export declare const Pickaxe: ({ pickaxeId }: PickaxeProps) => import("react/jsx-runtime").JSX.Element;
6
+ export declare const Pickaxe: ({ formId, chatId, className }: PickaxeProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime");exports.Pickaxe=({pickaxeId:s})=>e.jsxs("div",Object.assign({className:"text-sm text-c-red text-[28px] font-semibold p-4 rounded-lg shadow-md"},{children:["This is a pickaxe ",s]}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("../../hooks/usePickaxe.js"),s=require("react"),a=require("../../hooks/usePickaxeContext.js"),r=require("../../common/cn.js");exports.Pickaxe=({formId:c,chatId:i,className:u})=>{const{setFormId:o,setChatId:d,setPickaxe:n}=a.usePickaxeContext(),x=t.usePickaxe();return s.useEffect((()=>{o(c)}),[c]),s.useEffect((()=>{"string"==typeof i&&d(i)}),[i]),s.useEffect((()=>{x.data&&n(x.data)}),[x.data]),e.jsx("div",Object.assign({className:r.default("flex flex-col",u)},{children:x.data?e.jsx("pre",{children:JSON.stringify(x.data,null,2)}):"Loading..."}))};
@@ -0,0 +1,8 @@
1
+ import type { ChatMessage } from "../types/chat";
2
+ interface QueryResponse {
3
+ success: boolean;
4
+ messages: ChatMessage[];
5
+ error?: boolean;
6
+ }
7
+ export declare const useConversation: () => import("@tanstack/react-query/build/legacy/types").UseQueryResult<QueryResponse, Error>;
8
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { PickaxeHistory } from "../types/history";
2
+ import { InfiniteData, UseInfiniteQueryResult } from "@tanstack/react-query";
3
+ type QueryInfiniteResponse = {
4
+ next: number | undefined;
5
+ data: PickaxeHistory[];
6
+ };
7
+ interface UseHistoryQueryProps {
8
+ enabled?: boolean;
9
+ }
10
+ export declare const useHistory: ({ enabled }?: UseHistoryQueryProps) => UseInfiniteQueryResult<InfiniteData<QueryInfiniteResponse, unknown>, Error>;
11
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { Pickaxe } from "../types/pickaxe";
2
+ export type QueryResponse = {
3
+ success: boolean;
4
+ pickaxe: Pickaxe;
5
+ error?: string;
6
+ };
7
+ export declare const usePickaxe: () => import("@tanstack/react-query/build/legacy/types").UseQueryResult<Pickaxe | null, Error>;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../_virtual/_tslib.js"),r=require("@tanstack/react-query"),t=require("./usePickaxeContext.js"),i=require("../common/api/index.js");exports.usePickaxe=()=>{const{formId:a}=t.usePickaxeContext();return r.useQuery({queryKey:["form",a],queryFn:()=>e.__awaiter(void 0,void 0,void 0,(function*(){return(r=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!r)return null;const e=yield i.default.get(`/pickaxe?formid=${r}`),t=e.data;if(200!==e.status)throw new Error("[_getPickaxe] Failed to fetch pickaxe "+t);return t.pickaxe})))(a||"")})),enabled:!!a,staleTime:18e4})};
@@ -0,0 +1,16 @@
1
+ export declare const usePickaxeContext: () => {
2
+ formId: string;
3
+ chatId: string;
4
+ pickaxe: import("../types/pickaxe").Pickaxe | null;
5
+ status: import("../types/pickaxe").PickaxeStatus;
6
+ isNewChat: boolean;
7
+ isShowIceBreaker: boolean;
8
+ isShowHistory: boolean;
9
+ setFormId: import("../types/common").SetState<string>;
10
+ setChatId: import("../types/common").SetState<string>;
11
+ setPickaxe: import("../types/common").SetState<import("../types/pickaxe").Pickaxe | null>;
12
+ setStatus: import("../types/common").SetState<import("../types/pickaxe").PickaxeStatus>;
13
+ setIsNewChat: import("../types/common").SetState<boolean>;
14
+ setIsShowIceBreaker: import("../types/common").SetState<boolean>;
15
+ setIsShowHistory: import("../types/common").SetState<boolean>;
16
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("../providers/PickaxeProvider.js");exports.usePickaxeContext=()=>e.useContext(r.PickaxeContext);
@@ -0,0 +1,23 @@
1
+ import type { Pickaxe } from "../types/pickaxe";
2
+ type MutationParams = {
3
+ formId: string;
4
+ responseId?: string;
5
+ documentId?: string;
6
+ pickaxe?: Partial<Pickaxe>;
7
+ value?: string;
8
+ valueObj?: Record<string, string>;
9
+ };
10
+ type MutationResponse = {
11
+ success: boolean;
12
+ data: string;
13
+ responseId: string;
14
+ usedDocumentIds: string[];
15
+ newDocumentId: string;
16
+ newDocumentName: string;
17
+ rawUserInput: string;
18
+ isInsertedFile: boolean;
19
+ isCountedAsOwnerUse: boolean;
20
+ error?: string;
21
+ };
22
+ export declare const useSubmit: () => import("@tanstack/react-query/build/legacy/types").UseMutationResult<MutationResponse, Error, MutationParams, unknown>;
23
+ export {};
@@ -0,0 +1,16 @@
1
+ export declare const useSubmitDocument: () => {
2
+ document: (file: File) => Promise<{
3
+ success: boolean;
4
+ documentid: string;
5
+ error?: string | undefined;
6
+ }>;
7
+ website: (website: string) => Promise<{
8
+ success: boolean;
9
+ numchunks: number;
10
+ pages: number;
11
+ documentid: string;
12
+ name: string;
13
+ call_id: string;
14
+ error?: string | undefined;
15
+ }>;
16
+ };
@@ -0,0 +1,27 @@
1
+ import type { ChatRole } from "../types/chat";
2
+ type MutationParams = {
3
+ formId: string;
4
+ responseId: string;
5
+ documentIds?: string[];
6
+ userId?: string;
7
+ studioId?: string;
8
+ studioUserId?: string;
9
+ messages?: {
10
+ role: ChatRole;
11
+ message: string;
12
+ sentAt: Date;
13
+ }[];
14
+ questions?: {
15
+ id?: string;
16
+ question: string;
17
+ answer: string;
18
+ }[];
19
+ questionPrompt?: string;
20
+ questionResponse?: string;
21
+ };
22
+ type MutationResponse = {
23
+ success: boolean;
24
+ error?: string;
25
+ };
26
+ export declare const useSubmitResult: () => import("@tanstack/react-query/build/legacy/types").UseMutationResult<MutationResponse, Error, MutationParams, unknown>;
27
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { SetState } from "../types/common";
2
+ import type { Pickaxe, PickaxeStatus } from "../types/pickaxe";
3
+ import { type ReactNode } from "react";
4
+ type PickaxeContextType = {
5
+ formId: string;
6
+ chatId: string;
7
+ pickaxe: Pickaxe | null;
8
+ status: PickaxeStatus;
9
+ isNewChat: boolean;
10
+ isShowIceBreaker: boolean;
11
+ isShowHistory: boolean;
12
+ setFormId: SetState<string>;
13
+ setChatId: SetState<string>;
14
+ setPickaxe: SetState<Pickaxe | null>;
15
+ setStatus: SetState<PickaxeStatus>;
16
+ setIsNewChat: SetState<boolean>;
17
+ setIsShowIceBreaker: SetState<boolean>;
18
+ setIsShowHistory: SetState<boolean>;
19
+ };
20
+ interface IPickaxeProviderProps {
21
+ children: ReactNode;
22
+ }
23
+ export declare const PickaxeContext: import("react").Context<PickaxeContextType>;
24
+ export declare const PickaxeProvider: ({ children }: IPickaxeProviderProps) => import("react/jsx-runtime").JSX.Element;
25
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("react/jsx-runtime");const e=require("react").createContext({});exports.PickaxeContext=e;
@@ -0,0 +1,8 @@
1
+ export type ChatRole = "user" | "assistant";
2
+ export type ChatMessage = {
3
+ role: ChatRole;
4
+ content: string;
5
+ };
6
+ export type MemoryStoredChatMessage = {
7
+ id: number;
8
+ } & ChatMessage;
@@ -0,0 +1,2 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ export type SetState<T> = Dispatch<SetStateAction<T>>;
@@ -0,0 +1,37 @@
1
+ import type { MemoryStoredChatMessage } from "./chat";
2
+ import type { PickaxeHistoryQuestion } from "./history";
3
+ export type PickaxeQuestionType = "Short Answer" | "short" | "Long Answer" | "long" | "Multiple Choice" | "multiple" | "Checkbox" | "Knowledge Upload";
4
+ export type CachedPickaxeQuestion = {
5
+ id: string;
6
+ answerlength: string;
7
+ example: string;
8
+ main: string;
9
+ secondary: string;
10
+ type: PickaxeQuestionType;
11
+ isRequired?: boolean;
12
+ isDropdown?: boolean;
13
+ };
14
+ export type MemoryStoredQuestionField = {
15
+ order: number;
16
+ id: string;
17
+ type: PickaxeQuestionType;
18
+ main: string;
19
+ maxLength: number;
20
+ length: number;
21
+ input: string;
22
+ example: string;
23
+ documentId?: string;
24
+ isRequired?: boolean;
25
+ isDropdown?: boolean;
26
+ };
27
+ export type MemoryStoredResponse = {
28
+ formId: string;
29
+ responseId: string;
30
+ documentIds: string[];
31
+ messages: MemoryStoredChatMessage[];
32
+ questions: PickaxeHistoryQuestion[];
33
+ questionPrompt: string;
34
+ questionResponse: string;
35
+ userId?: string;
36
+ createdAt: Date;
37
+ };
@@ -0,0 +1,37 @@
1
+ import type { ChatRole } from "./chat";
2
+ export type PickaxeHistoryType = "chat" | "form";
3
+ export type PickaxeHistoryQuestion = {
4
+ id: string;
5
+ question: string;
6
+ answer: string;
7
+ };
8
+ export type PickaxeHistoryMessage = {
9
+ message: string;
10
+ role: ChatRole;
11
+ sentAt: Date;
12
+ };
13
+ export type PickaxeHistoryChat = {
14
+ type: "chat";
15
+ messages: PickaxeHistoryMessage[];
16
+ };
17
+ export type PickaxeHistoryForm = {
18
+ type: "form";
19
+ questions: PickaxeHistoryQuestion[];
20
+ questionPrompt: string;
21
+ questionResponse: string;
22
+ };
23
+ export type PickaxeHistory = {
24
+ _id: string;
25
+ historyId: string;
26
+ responseId: string;
27
+ formId: string;
28
+ userId?: string;
29
+ studioId?: string;
30
+ studioUserId?: string;
31
+ type: PickaxeHistoryType;
32
+ documentIds: string[];
33
+ clientIPAddress?: string;
34
+ timestamp: number;
35
+ createdAt: Date;
36
+ updatedAt: Date;
37
+ } & (PickaxeHistoryChat | PickaxeHistoryForm);
@@ -0,0 +1,59 @@
1
+ import type { CachedPickaxeQuestion } from "./form";
2
+ export type PickaxeImageOrText = "text" | "image";
3
+ export type PickaxePrivacySetting = "public" | "unlisted" | "private" | "deleted";
4
+ export type PickaxeCloneable = "true" | "false";
5
+ export type PickaxeDocumentUploadType = "ownerupload" | "enduserupload";
6
+ export type PickaxeModel = "gpt-4o-mini" | "gpt-4o" | "gpt-4-1106-preview" | "gpt-4" | "gpt-3.5-turbo" | "mistral-small" | "mistral-large-latest" | "claude-3-opus-20240229" | "claude-3-5-sonnet-20240620";
7
+ export type Pickaxe = {
8
+ _id: string;
9
+ formid: string;
10
+ adminid: string;
11
+ workspaceid?: string;
12
+ studioid?: string;
13
+ apikey: string;
14
+ category: string;
15
+ coverphoto: string;
16
+ chatflag: boolean;
17
+ chatinputlength: number;
18
+ chaticon: string;
19
+ documentprompt: string;
20
+ documentuploadtype: PickaxeDocumentUploadType;
21
+ embedlink: string;
22
+ enablechatresponses: boolean;
23
+ featured: boolean;
24
+ formdescription: string;
25
+ formtitle: string;
26
+ freqpenalty: number;
27
+ imageortext: PickaxeImageOrText;
28
+ ip_address: string;
29
+ knowledgetokens: number;
30
+ endusertokens?: number;
31
+ maxlength: number;
32
+ membuffer: number;
33
+ model: PickaxeModel;
34
+ owner: string;
35
+ placeholdertext: string;
36
+ prespenalty: number;
37
+ privacysetting: PickaxePrivacySetting;
38
+ public: PickaxeCloneable;
39
+ rawpromptframe?: string;
40
+ relevancethreshold: number;
41
+ responseprefix: string;
42
+ role: string;
43
+ special: string;
44
+ stopwords: string;
45
+ streaming: boolean;
46
+ temperature: number;
47
+ wordbiasless: string;
48
+ wordbiasmore: string;
49
+ icebreakers: string[];
50
+ submittext?: string;
51
+ previewimage?: string;
52
+ linked: boolean;
53
+ usestoday: number;
54
+ usestotal: number;
55
+ useslimit: number;
56
+ timestamp: number;
57
+ _questions?: CachedPickaxeQuestion[];
58
+ };
59
+ export type PickaxeStatus = "fetching" | "streaming" | "idle";
@@ -0,0 +1 @@
1
+ function n(n,t,e,r){return new(e||(e=Promise))((function(o,c){function u(n){try{i(r.next(n))}catch(n){c(n)}}function f(n){try{i(r.throw(n))}catch(n){c(n)}}function i(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(u,f)}i((r=r.apply(n,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;export{n as __awaiter};
@@ -0,0 +1,2 @@
1
+ declare const api: import("axios").AxiosInstance;
2
+ export default api;
@@ -0,0 +1 @@
1
+ import e from"axios";import{getEnv as o,isDevelopment as r}from"../env.js";const t=o("API_URL");if(!t)throw new Error("[px/react] API_URL is not defined");const s=o("PICKAXE_SESSION_TOKEN");if(!s)throw new Error("[px/react] SESSION_TOKEN is not defined");const n=e.create(Object.assign({baseURL:t},r&&s&&{headers:{"x-pickaxe-session-token":s}}));export{n as default};
@@ -0,0 +1,7 @@
1
+ interface StreamerOptions {
2
+ formId: string;
3
+ responseId: string;
4
+ data: string;
5
+ }
6
+ export declare const streamer: (payload: StreamerOptions) => Promise<Response>;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const apiUtils: import("axios").AxiosInstance;
2
+ export default apiUtils;
@@ -0,0 +1 @@
1
+ import{clsx as o}from"clsx";import{twMerge as r}from"tailwind-merge";const t=(...t)=>r(o(t));export{t as default};
@@ -0,0 +1,2 @@
1
+ export declare const getEnv: (key: string) => string | null;
2
+ export declare const isDevelopment: boolean;
@@ -0,0 +1 @@
1
+ const e=e=>process.env[e]||process.env[`NEXT_PUBLIC_${e}`]||process.env[`VITE_${e}"`]||process.env[`REACT_APP_${e}`]||null,s="development"===e("NODE_ENV");export{e as getEnv,s as isDevelopment};
@@ -0,0 +1 @@
1
+ export declare const generateId: (length: number, prefix?: string, suffix?: string) => string;
@@ -1,4 +1,6 @@
1
1
  export interface PickaxeProps {
2
- pickaxeId: string;
2
+ formId: string;
3
+ chatId?: string;
4
+ className?: string;
3
5
  }
4
- export declare const Pickaxe: ({ pickaxeId }: PickaxeProps) => import("react/jsx-runtime").JSX.Element;
6
+ export declare const Pickaxe: ({ formId, chatId, className }: PickaxeProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- import{jsxs as e}from"react/jsx-runtime";const t=({pickaxeId:t})=>e("div",Object.assign({className:"text-sm text-c-red text-[28px] font-semibold p-4 rounded-lg shadow-md"},{children:["This is a pickaxe ",t]}));export{t as Pickaxe};
1
+ import{jsx as t}from"react/jsx-runtime";import{usePickaxe as o}from"../../hooks/usePickaxe.js";import{useEffect as a}from"react";import{usePickaxeContext as e}from"../../hooks/usePickaxeContext.js";import r from"../../common/cn.js";const s=({formId:s,chatId:i,className:m})=>{const{setFormId:c,setChatId:n,setPickaxe:d}=e(),f=o();return a((()=>{c(s)}),[s]),a((()=>{"string"==typeof i&&n(i)}),[i]),a((()=>{f.data&&d(f.data)}),[f.data]),t("div",Object.assign({className:r("flex flex-col",m)},{children:f.data?t("pre",{children:JSON.stringify(f.data,null,2)}):"Loading..."}))};export{s as Pickaxe};
@@ -0,0 +1,8 @@
1
+ import type { ChatMessage } from "../types/chat";
2
+ interface QueryResponse {
3
+ success: boolean;
4
+ messages: ChatMessage[];
5
+ error?: boolean;
6
+ }
7
+ export declare const useConversation: () => import("@tanstack/react-query/build/legacy/types").UseQueryResult<QueryResponse, Error>;
8
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { PickaxeHistory } from "../types/history";
2
+ import { InfiniteData, UseInfiniteQueryResult } from "@tanstack/react-query";
3
+ type QueryInfiniteResponse = {
4
+ next: number | undefined;
5
+ data: PickaxeHistory[];
6
+ };
7
+ interface UseHistoryQueryProps {
8
+ enabled?: boolean;
9
+ }
10
+ export declare const useHistory: ({ enabled }?: UseHistoryQueryProps) => UseInfiniteQueryResult<InfiniteData<QueryInfiniteResponse, unknown>, Error>;
11
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { Pickaxe } from "../types/pickaxe";
2
+ export type QueryResponse = {
3
+ success: boolean;
4
+ pickaxe: Pickaxe;
5
+ error?: string;
6
+ };
7
+ export declare const usePickaxe: () => import("@tanstack/react-query/build/legacy/types").UseQueryResult<Pickaxe | null, Error>;
@@ -0,0 +1 @@
1
+ import{__awaiter as t}from"../_virtual/_tslib.js";import{useQuery as e}from"@tanstack/react-query";import{usePickaxeContext as o}from"./usePickaxeContext.js";import r from"../common/api/index.js";const i=()=>{const{formId:i}=o();return e({queryKey:["form",i],queryFn:()=>t(void 0,void 0,void 0,(function*(){return(e=>t(void 0,void 0,void 0,(function*(){if(!e)return null;const t=yield r.get(`/pickaxe?formid=${e}`),o=t.data;if(200!==t.status)throw new Error("[_getPickaxe] Failed to fetch pickaxe "+o);return o.pickaxe})))(i||"")})),enabled:!!i,staleTime:18e4})};export{i as usePickaxe};
@@ -0,0 +1,16 @@
1
+ export declare const usePickaxeContext: () => {
2
+ formId: string;
3
+ chatId: string;
4
+ pickaxe: import("../types/pickaxe").Pickaxe | null;
5
+ status: import("../types/pickaxe").PickaxeStatus;
6
+ isNewChat: boolean;
7
+ isShowIceBreaker: boolean;
8
+ isShowHistory: boolean;
9
+ setFormId: import("../types/common").SetState<string>;
10
+ setChatId: import("../types/common").SetState<string>;
11
+ setPickaxe: import("../types/common").SetState<import("../types/pickaxe").Pickaxe | null>;
12
+ setStatus: import("../types/common").SetState<import("../types/pickaxe").PickaxeStatus>;
13
+ setIsNewChat: import("../types/common").SetState<boolean>;
14
+ setIsShowIceBreaker: import("../types/common").SetState<boolean>;
15
+ setIsShowHistory: import("../types/common").SetState<boolean>;
16
+ };
@@ -0,0 +1 @@
1
+ import{useContext as r}from"react";import{PickaxeContext as o}from"../providers/PickaxeProvider.js";const e=()=>r(o);export{e as usePickaxeContext};
@@ -0,0 +1,23 @@
1
+ import type { Pickaxe } from "../types/pickaxe";
2
+ type MutationParams = {
3
+ formId: string;
4
+ responseId?: string;
5
+ documentId?: string;
6
+ pickaxe?: Partial<Pickaxe>;
7
+ value?: string;
8
+ valueObj?: Record<string, string>;
9
+ };
10
+ type MutationResponse = {
11
+ success: boolean;
12
+ data: string;
13
+ responseId: string;
14
+ usedDocumentIds: string[];
15
+ newDocumentId: string;
16
+ newDocumentName: string;
17
+ rawUserInput: string;
18
+ isInsertedFile: boolean;
19
+ isCountedAsOwnerUse: boolean;
20
+ error?: string;
21
+ };
22
+ export declare const useSubmit: () => import("@tanstack/react-query/build/legacy/types").UseMutationResult<MutationResponse, Error, MutationParams, unknown>;
23
+ export {};
@@ -0,0 +1,16 @@
1
+ export declare const useSubmitDocument: () => {
2
+ document: (file: File) => Promise<{
3
+ success: boolean;
4
+ documentid: string;
5
+ error?: string | undefined;
6
+ }>;
7
+ website: (website: string) => Promise<{
8
+ success: boolean;
9
+ numchunks: number;
10
+ pages: number;
11
+ documentid: string;
12
+ name: string;
13
+ call_id: string;
14
+ error?: string | undefined;
15
+ }>;
16
+ };
@@ -0,0 +1,27 @@
1
+ import type { ChatRole } from "../types/chat";
2
+ type MutationParams = {
3
+ formId: string;
4
+ responseId: string;
5
+ documentIds?: string[];
6
+ userId?: string;
7
+ studioId?: string;
8
+ studioUserId?: string;
9
+ messages?: {
10
+ role: ChatRole;
11
+ message: string;
12
+ sentAt: Date;
13
+ }[];
14
+ questions?: {
15
+ id?: string;
16
+ question: string;
17
+ answer: string;
18
+ }[];
19
+ questionPrompt?: string;
20
+ questionResponse?: string;
21
+ };
22
+ type MutationResponse = {
23
+ success: boolean;
24
+ error?: string;
25
+ };
26
+ export declare const useSubmitResult: () => import("@tanstack/react-query/build/legacy/types").UseMutationResult<MutationResponse, Error, MutationParams, unknown>;
27
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { SetState } from "../types/common";
2
+ import type { Pickaxe, PickaxeStatus } from "../types/pickaxe";
3
+ import { type ReactNode } from "react";
4
+ type PickaxeContextType = {
5
+ formId: string;
6
+ chatId: string;
7
+ pickaxe: Pickaxe | null;
8
+ status: PickaxeStatus;
9
+ isNewChat: boolean;
10
+ isShowIceBreaker: boolean;
11
+ isShowHistory: boolean;
12
+ setFormId: SetState<string>;
13
+ setChatId: SetState<string>;
14
+ setPickaxe: SetState<Pickaxe | null>;
15
+ setStatus: SetState<PickaxeStatus>;
16
+ setIsNewChat: SetState<boolean>;
17
+ setIsShowIceBreaker: SetState<boolean>;
18
+ setIsShowHistory: SetState<boolean>;
19
+ };
20
+ interface IPickaxeProviderProps {
21
+ children: ReactNode;
22
+ }
23
+ export declare const PickaxeContext: import("react").Context<PickaxeContextType>;
24
+ export declare const PickaxeProvider: ({ children }: IPickaxeProviderProps) => import("react/jsx-runtime").JSX.Element;
25
+ export {};
@@ -0,0 +1 @@
1
+ import"react/jsx-runtime";import{createContext as r}from"react";const t=r({});export{t as PickaxeContext};
@@ -0,0 +1,8 @@
1
+ export type ChatRole = "user" | "assistant";
2
+ export type ChatMessage = {
3
+ role: ChatRole;
4
+ content: string;
5
+ };
6
+ export type MemoryStoredChatMessage = {
7
+ id: number;
8
+ } & ChatMessage;
@@ -0,0 +1,2 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ export type SetState<T> = Dispatch<SetStateAction<T>>;
@@ -0,0 +1,37 @@
1
+ import type { MemoryStoredChatMessage } from "./chat";
2
+ import type { PickaxeHistoryQuestion } from "./history";
3
+ export type PickaxeQuestionType = "Short Answer" | "short" | "Long Answer" | "long" | "Multiple Choice" | "multiple" | "Checkbox" | "Knowledge Upload";
4
+ export type CachedPickaxeQuestion = {
5
+ id: string;
6
+ answerlength: string;
7
+ example: string;
8
+ main: string;
9
+ secondary: string;
10
+ type: PickaxeQuestionType;
11
+ isRequired?: boolean;
12
+ isDropdown?: boolean;
13
+ };
14
+ export type MemoryStoredQuestionField = {
15
+ order: number;
16
+ id: string;
17
+ type: PickaxeQuestionType;
18
+ main: string;
19
+ maxLength: number;
20
+ length: number;
21
+ input: string;
22
+ example: string;
23
+ documentId?: string;
24
+ isRequired?: boolean;
25
+ isDropdown?: boolean;
26
+ };
27
+ export type MemoryStoredResponse = {
28
+ formId: string;
29
+ responseId: string;
30
+ documentIds: string[];
31
+ messages: MemoryStoredChatMessage[];
32
+ questions: PickaxeHistoryQuestion[];
33
+ questionPrompt: string;
34
+ questionResponse: string;
35
+ userId?: string;
36
+ createdAt: Date;
37
+ };
@@ -0,0 +1,37 @@
1
+ import type { ChatRole } from "./chat";
2
+ export type PickaxeHistoryType = "chat" | "form";
3
+ export type PickaxeHistoryQuestion = {
4
+ id: string;
5
+ question: string;
6
+ answer: string;
7
+ };
8
+ export type PickaxeHistoryMessage = {
9
+ message: string;
10
+ role: ChatRole;
11
+ sentAt: Date;
12
+ };
13
+ export type PickaxeHistoryChat = {
14
+ type: "chat";
15
+ messages: PickaxeHistoryMessage[];
16
+ };
17
+ export type PickaxeHistoryForm = {
18
+ type: "form";
19
+ questions: PickaxeHistoryQuestion[];
20
+ questionPrompt: string;
21
+ questionResponse: string;
22
+ };
23
+ export type PickaxeHistory = {
24
+ _id: string;
25
+ historyId: string;
26
+ responseId: string;
27
+ formId: string;
28
+ userId?: string;
29
+ studioId?: string;
30
+ studioUserId?: string;
31
+ type: PickaxeHistoryType;
32
+ documentIds: string[];
33
+ clientIPAddress?: string;
34
+ timestamp: number;
35
+ createdAt: Date;
36
+ updatedAt: Date;
37
+ } & (PickaxeHistoryChat | PickaxeHistoryForm);
@@ -0,0 +1,59 @@
1
+ import type { CachedPickaxeQuestion } from "./form";
2
+ export type PickaxeImageOrText = "text" | "image";
3
+ export type PickaxePrivacySetting = "public" | "unlisted" | "private" | "deleted";
4
+ export type PickaxeCloneable = "true" | "false";
5
+ export type PickaxeDocumentUploadType = "ownerupload" | "enduserupload";
6
+ export type PickaxeModel = "gpt-4o-mini" | "gpt-4o" | "gpt-4-1106-preview" | "gpt-4" | "gpt-3.5-turbo" | "mistral-small" | "mistral-large-latest" | "claude-3-opus-20240229" | "claude-3-5-sonnet-20240620";
7
+ export type Pickaxe = {
8
+ _id: string;
9
+ formid: string;
10
+ adminid: string;
11
+ workspaceid?: string;
12
+ studioid?: string;
13
+ apikey: string;
14
+ category: string;
15
+ coverphoto: string;
16
+ chatflag: boolean;
17
+ chatinputlength: number;
18
+ chaticon: string;
19
+ documentprompt: string;
20
+ documentuploadtype: PickaxeDocumentUploadType;
21
+ embedlink: string;
22
+ enablechatresponses: boolean;
23
+ featured: boolean;
24
+ formdescription: string;
25
+ formtitle: string;
26
+ freqpenalty: number;
27
+ imageortext: PickaxeImageOrText;
28
+ ip_address: string;
29
+ knowledgetokens: number;
30
+ endusertokens?: number;
31
+ maxlength: number;
32
+ membuffer: number;
33
+ model: PickaxeModel;
34
+ owner: string;
35
+ placeholdertext: string;
36
+ prespenalty: number;
37
+ privacysetting: PickaxePrivacySetting;
38
+ public: PickaxeCloneable;
39
+ rawpromptframe?: string;
40
+ relevancethreshold: number;
41
+ responseprefix: string;
42
+ role: string;
43
+ special: string;
44
+ stopwords: string;
45
+ streaming: boolean;
46
+ temperature: number;
47
+ wordbiasless: string;
48
+ wordbiasmore: string;
49
+ icebreakers: string[];
50
+ submittext?: string;
51
+ previewimage?: string;
52
+ linked: boolean;
53
+ usestoday: number;
54
+ usestotal: number;
55
+ useslimit: number;
56
+ timestamp: number;
57
+ _questions?: CachedPickaxeQuestion[];
58
+ };
59
+ export type PickaxeStatus = "fetching" | "streaming" | "idle";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pickaxeproject/react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Client utility library for Pickaxe",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,6 +47,7 @@
47
47
  "@rollup/plugin-node-resolve": "^15.0.1",
48
48
  "@rollup/plugin-terser": "^0.3.0",
49
49
  "@tailwindcss/container-queries": "^0.1.1",
50
+ "@tanstack/react-query": "^5.63.0",
50
51
  "@types/node": "^18.11.18",
51
52
  "@types/react": "^18.0.26",
52
53
  "@types/react-dom": "^18.0.10",
@@ -54,8 +55,10 @@
54
55
  "@typescript-eslint/parser": "^5.48.1",
55
56
  "@zerollup/ts-transform-paths": "^1.7.18",
56
57
  "autoprefixer": "^10.4.20",
58
+ "axios": "^1.7.9",
57
59
  "babel-loader": "^9.1.2",
58
60
  "clsx": "^2.1.1",
61
+ "cross-env": "^7.0.3",
59
62
  "eslint": "8.31.0",
60
63
  "eslint-config-prettier": "^8.6.0",
61
64
  "eslint-plugin-jsx-a11y": "^6.7.1",
@@ -84,6 +87,8 @@
84
87
  },
85
88
  "peerDependencies": {
86
89
  "@tailwindcss/container-queries": "^0.1.1",
90
+ "@tanstack/react-query": "^5.63.0",
91
+ "axios": "^1.7.9",
87
92
  "clsx": "^2.1.1",
88
93
  "react": "^16.8.0 || ^17 || ^18",
89
94
  "react-dom": "^16.8.0 || ^17 || ^18",
@@ -94,7 +99,7 @@
94
99
  "node": ">=18"
95
100
  },
96
101
  "scripts": {
97
- "build": "NODE_ENV=production rollup -c",
102
+ "build": "cross-env NODE_ENV=production rollup -c",
98
103
  "lint": "eslint . --ext .ts,.tsx,.js,.jsx",
99
104
  "changeset": "changeset",
100
105
  "release": "changeset publish",
File without changes
File without changes