@copilotkit/react-ui 1.3.16-mme-copilot-suggestions.1 → 1.3.16-mme-reset-chat.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.
- package/CHANGELOG.md +20 -10
- package/dist/{chunk-DTI5DZSK.mjs → chunk-3EYL2DRG.mjs} +5 -5
- package/dist/{chunk-T7DQWLTN.mjs → chunk-3JNDMHS4.mjs} +2 -2
- package/dist/{chunk-PIK3RYPJ.mjs → chunk-AX7CAT7V.mjs} +2 -2
- package/dist/{chunk-UYT3USIS.mjs → chunk-NLIDKNNS.mjs} +5 -5
- package/dist/{chunk-W3TDOLUY.mjs → chunk-RS6UPR5N.mjs} +8 -8
- package/dist/chunk-T26KLXLH.mjs +1 -0
- package/dist/{chunk-HGQFDT5I.mjs → chunk-Z2UZSN3K.mjs} +1 -1
- package/dist/chunk-Z2UZSN3K.mjs.map +1 -0
- package/dist/components/chat/Chat.mjs +5 -5
- package/dist/components/chat/Modal.mjs +6 -6
- package/dist/components/chat/Popup.mjs +7 -7
- package/dist/components/chat/Sidebar.mjs +7 -7
- package/dist/components/chat/index.mjs +8 -8
- package/dist/components/chat/messages/RenderTextMessage.mjs +1 -1
- package/dist/components/dev-console/console.mjs +2 -2
- package/dist/components/dev-console/index.mjs +2 -2
- package/dist/components/index.mjs +8 -8
- package/dist/hooks/index.d.ts +0 -2
- package/dist/hooks/index.js +2 -136
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +3 -7
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +3 -1
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +2 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -15
- package/package.json +7 -7
- package/src/hooks/index.ts +0 -1
- package/src/hooks/use-copilot-chat-suggestions.tsx +3 -1
- package/dist/chunk-G7A3YV3L.mjs +0 -109
- package/dist/chunk-G7A3YV3L.mjs.map +0 -1
- package/dist/chunk-HGQFDT5I.mjs.map +0 -1
- package/dist/chunk-RJ54B6VE.mjs +0 -1
- package/dist/hooks/use-copilot-suggestions.d.ts +0 -79
- package/dist/hooks/use-copilot-suggestions.js +0 -160
- package/dist/hooks/use-copilot-suggestions.js.map +0 -1
- package/dist/hooks/use-copilot-suggestions.mjs +0 -8
- package/dist/hooks/use-copilot-suggestions.mjs.map +0 -1
- package/src/hooks/use-copilot-suggestions.ts +0 -190
- /package/dist/{chunk-DTI5DZSK.mjs.map → chunk-3EYL2DRG.mjs.map} +0 -0
- /package/dist/{chunk-T7DQWLTN.mjs.map → chunk-3JNDMHS4.mjs.map} +0 -0
- /package/dist/{chunk-PIK3RYPJ.mjs.map → chunk-AX7CAT7V.mjs.map} +0 -0
- /package/dist/{chunk-UYT3USIS.mjs.map → chunk-NLIDKNNS.mjs.map} +0 -0
- /package/dist/{chunk-W3TDOLUY.mjs.map → chunk-RS6UPR5N.mjs.map} +0 -0
- /package/dist/{chunk-RJ54B6VE.mjs.map → chunk-T26KLXLH.mjs.map} +0 -0
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/index.ts","../../src/hooks/use-copilot-chat-suggestions.tsx","../../src/hooks/use-copilot-suggestions.ts"],"sourcesContent":["export * from \"./use-copilot-chat-suggestions\";\nexport * from \"./use-copilot-suggestions\";\n","/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotChatSuggestions` is a React hook that provides auto-suggestions in the Copilot chat.\n *\n * <br/>\n * <img src=\"/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotChatSuggestions({\n * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,\n * });\n * }\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\n * );\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect } from \"react\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { randomId } from \"@copilotkit/shared\";\n\ninterface UseCopilotChatSuggestionsConfiguration {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n}\n\nexport function useCopilotChatSuggestions(\n {\n instructions,\n className,\n minSuggestions = 1,\n maxSuggestions = 3,\n }: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n) {\n const context = useCopilotContext();\n\n useEffect(() => {\n const id = randomId();\n\n context.addChatSuggestionConfiguration(id, {\n instructions,\n minSuggestions,\n maxSuggestions,\n className,\n });\n\n return () => {\n context.removeChatSuggestionConfiguration(id);\n };\n }, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);\n}\n","/**\n * <Callout type=\"warning\">\n * useCopilotSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotSuggestions` is a React hook that provides auto-suggestions that can be added to any\n * UI component.\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * TODO\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * TODO\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect, useState, useRef, useCallback } from \"react\";\nimport {\n CopilotContextParams,\n CopilotMessagesContextParams,\n extract,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"@copilotkit/react-core\";\nimport { MappedParameterTypes, Parameter, randomId } from \"@copilotkit/shared\";\nimport { CopilotRequestType } from \"@copilotkit/runtime-client-gql\";\n\nexport interface UseCopilotSuggestionsConfiguration<T extends Parameter[] = []> {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions?: string;\n\n /**\n * The data to pass to the suggestions.\n */\n parameters: T;\n\n /**\n * The current value of the parameter.\n */\n value?: Partial<MappedParameterTypes<T>>;\n\n /**\n * Whether the suggestions are enabled.\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The debounce time in milliseconds.\n * @default 1000\n */\n debounceTime?: number;\n}\nexport type SuggestionsResult<T extends Parameter[]> =\n | { suggestions: undefined; isAvailable: false; isLoading: boolean }\n | { suggestions: MappedParameterTypes<T>; isAvailable: true; isLoading: boolean };\n\nexport function useCopilotSuggestions<const T extends Parameter[]>(\n {\n instructions,\n parameters,\n value,\n enabled = true,\n debounceTime = 1000,\n }: UseCopilotSuggestionsConfiguration<T>,\n dependencies: any[] = [],\n): SuggestionsResult<T> {\n const suggestionsAbortControllerRef = useRef<AbortController | null>(null);\n const debounceTimerRef = useRef<any>();\n const [suggestions, setSuggestions] = useState<SuggestionsResult<T>>({\n suggestions: undefined,\n isAvailable: false,\n isLoading: false,\n });\n const isFirstRunRef = useRef(true);\n\n const abortSuggestions = useCallback(() => {\n suggestionsAbortControllerRef.current?.abort();\n suggestionsAbortControllerRef.current = null;\n }, []);\n\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n\n useEffect(() => {\n abortSuggestions();\n if (!enabled) {\n setSuggestions({ suggestions: undefined, isAvailable: false, isLoading: false });\n return;\n }\n\n // if value is the same as the last suggestions, don't reload\n if (JSON.stringify(value) === JSON.stringify(suggestions.suggestions)) {\n return;\n }\n\n debounceTimerRef.current = setTimeout(\n async () => {\n isFirstRunRef.current = false;\n suggestionsAbortControllerRef.current = new AbortController();\n setSuggestions({ ...suggestions, isLoading: true });\n await reloadSuggestions(\n context,\n instructions,\n parameters,\n value,\n suggestionsAbortControllerRef,\n setSuggestions,\n );\n },\n isFirstRunRef.current === true ? 0 : debounceTime,\n );\n\n return () => {\n clearTimeout(debounceTimerRef.current);\n };\n }, [\n instructions,\n JSON.stringify(parameters),\n JSON.stringify(value),\n enabled,\n debounceTime,\n ...dependencies,\n ]);\n\n return suggestions;\n}\n\nasync function reloadSuggestions(\n context: CopilotContextParams & CopilotMessagesContextParams,\n instructions: string | undefined,\n parameters: Parameter[],\n value: any,\n abortControllerRef: React.MutableRefObject<AbortController | null>,\n setSuggestions: (suggestions: any) => void,\n) {\n const abortController = abortControllerRef.current;\n let fullInstructions = `It's your task to generate suggestions based on the application context.`;\n if (instructions) {\n fullInstructions += `\\n\\nIn addition, follow these specific instructions: ${instructions}`;\n }\n if (value) {\n fullInstructions +=\n `\\n\\nThe current value of the parameter is: ${JSON.stringify(value)}.` +\n `If it makes sense to complete the existing data, i.e. expand string values, add new elements to arrays, etc., do so. ` +\n `Otherwise, generate a new value.`;\n }\n\n await extract({\n context,\n instructions: instructions || \"\",\n data: fullInstructions,\n parameters,\n abortSignal: abortController?.signal,\n requestType: CopilotRequestType.Task,\n stream({ args, status }) {\n if (status === \"complete\") {\n setSuggestions({ suggestions: args, isAvailable: true, isLoading: false });\n }\n },\n });\n}\n"],"mappings":"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","names":["import_react","import_react_core"]}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/index.ts","../../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["export * from \"./use-copilot-chat-suggestions\";\n","/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * <br/>\n * <img src=\"/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotChatSuggestions({\n * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,\n * });\n * }\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\n * );\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect } from \"react\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { randomId } from \"@copilotkit/shared\";\n\ninterface UseCopilotChatSuggestionsConfiguration {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n}\n\nexport function useCopilotChatSuggestions(\n {\n instructions,\n className,\n minSuggestions = 1,\n maxSuggestions = 3,\n }: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n) {\n const context = useCopilotContext();\n\n useEffect(() => {\n const id = randomId();\n\n context.addChatSuggestionConfiguration(id, {\n instructions,\n minSuggestions,\n maxSuggestions,\n className,\n });\n\n return () => {\n context.removeChatSuggestionConfiguration(id);\n };\n }, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC6DA,mBAA0B;AAC1B,wBAAkC;AAClC,oBAAyB;AAuBlB,SAAS,0BACd;AAAA,EACE;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,iBAAiB;AACnB,GACA,eAAsB,CAAC,GACvB;AACA,QAAM,cAAU,qCAAkB;AAElC,8BAAU,MAAM;AACd,UAAM,SAAK,wBAAS;AAEpB,YAAQ,+BAA+B,IAAI;AAAA,MACzC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,cAAQ,kCAAkC,EAAE;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,GAAG,cAAc,cAAc,gBAAgB,gBAAgB,SAAS,CAAC;AAC/E;","names":[]}
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-T26KLXLH.mjs";
|
|
2
2
|
import {
|
|
3
3
|
useCopilotChatSuggestions
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import {
|
|
6
|
-
useCopilotSuggestions
|
|
7
|
-
} from "../chunk-G7A3YV3L.mjs";
|
|
4
|
+
} from "../chunk-Z2UZSN3K.mjs";
|
|
8
5
|
import "../chunk-MRXNTQOX.mjs";
|
|
9
6
|
export {
|
|
10
|
-
useCopilotChatSuggestions
|
|
11
|
-
useCopilotSuggestions
|
|
7
|
+
useCopilotChatSuggestions
|
|
12
8
|
};
|
|
13
9
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* can change without notice.
|
|
5
5
|
* </Callout>
|
|
6
6
|
*
|
|
7
|
-
* `
|
|
7
|
+
* `useCopilotReadable` is a React hook that provides app-state and other information
|
|
8
|
+
* to the Copilot. Optionally, the hook can also handle hierarchical state within your
|
|
9
|
+
* application, passing these parent-child relationships to the Copilot.
|
|
8
10
|
*
|
|
9
11
|
* <br/>
|
|
10
12
|
* <img src="/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif" width="500" />
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-copilot-chat-suggestions.tsx"],"sourcesContent":["/**\n * <Callout type=\"warning\">\n * useCopilotChatSuggestions is experimental. The interface is not final and\n * can change without notice.\n * </Callout>\n *\n * `useCopilotReadable` is a React hook that provides app-state and other information\n * to the Copilot. Optionally, the hook can also handle hierarchical state within your\n * application, passing these parent-child relationships to the Copilot.\n *\n * <br/>\n * <img src=\"/images/use-copilot-chat-suggestions/use-copilot-chat-suggestions.gif\" width=\"500\" />\n *\n * ## Usage\n *\n * ### Install Dependencies\n *\n * This component is part of the [@copilotkit/react-ui](https://npmjs.com/package/@copilotkit/react-ui) package.\n *\n * ```shell npm2yarn \\\"@copilotkit/react-ui\"\\\n * npm install @copilotkit/react-core @copilotkit/react-ui\n * ```\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * const [employees, setEmployees] = useState([]);\n *\n * useCopilotChatSuggestions({\n * instructions: `The following employees are on duty: ${JSON.stringify(employees)}`,\n * });\n * }\n * ```\n *\n * ### Dependency Management\n *\n * ```tsx\n * import { useCopilotChatSuggestions } from \"@copilotkit/react-ui\";\n *\n * export function MyComponent() {\n * useCopilotChatSuggestions(\n * {\n * instructions: \"Suggest the most relevant next actions.\",\n * },\n * [appState],\n * );\n * }\n * ```\n *\n * In the example above, the suggestions are generated based on the given instructions.\n * The hook monitors `appState`, and updates suggestions accordingly whenever it changes.\n *\n * ### Behavior and Lifecycle\n *\n * The hook registers the configuration with the chat context upon component mount and\n * removes it on unmount, ensuring a clean and efficient lifecycle management.\n */\n\nimport { useEffect } from \"react\";\nimport { useCopilotContext } from \"@copilotkit/react-core\";\nimport { randomId } from \"@copilotkit/shared\";\n\ninterface UseCopilotChatSuggestionsConfiguration {\n /**\n * A prompt or instructions for the GPT to generate suggestions.\n */\n instructions: string;\n /**\n * The minimum number of suggestions to generate. Defaults to `1`.\n * @default 1\n */\n minSuggestions?: number;\n /**\n * The maximum number of suggestions to generate. Defaults to `3`.\n * @default 1\n */\n maxSuggestions?: number;\n /**\n * An optional class name to apply to the suggestions.\n */\n className?: string;\n}\n\nexport function useCopilotChatSuggestions(\n {\n instructions,\n className,\n minSuggestions = 1,\n maxSuggestions = 3,\n }: UseCopilotChatSuggestionsConfiguration,\n dependencies: any[] = [],\n) {\n const context = useCopilotContext();\n\n useEffect(() => {\n const id = randomId();\n\n context.addChatSuggestionConfiguration(id, {\n instructions,\n minSuggestions,\n maxSuggestions,\n className,\n });\n\n return () => {\n context.removeChatSuggestionConfiguration(id);\n };\n }, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6DA,mBAA0B;AAC1B,wBAAkC;AAClC,oBAAyB;AAuBlB,SAAS,0BACd;AAAA,EACE;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB,iBAAiB;AACnB,GACA,eAAsB,CAAC,GACvB;AACA,QAAM,cAAU,qCAAkB;AAElC,8BAAU,MAAM;AACd,UAAM,SAAK,wBAAS;AAEpB,YAAQ,+BAA+B,IAAI;AAAA,MACzC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,cAAQ,kCAAkC,EAAE;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,GAAG,cAAc,cAAc,gBAAgB,gBAAgB,SAAS,CAAC;AAC/E;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export { CopilotSidebar } from './components/chat/Sidebar.js';
|
|
|
4
4
|
export { CopilotChat } from './components/chat/Chat.js';
|
|
5
5
|
export { useChatContext } from './components/chat/ChatContext.js';
|
|
6
6
|
export { useCopilotChatSuggestions } from './hooks/use-copilot-chat-suggestions.js';
|
|
7
|
-
export { SuggestionsResult, UseCopilotSuggestionsConfiguration, useCopilotSuggestions } from './hooks/use-copilot-suggestions.js';
|
|
8
7
|
export { CopilotKitCSSProperties } from './types/css.js';
|
|
9
8
|
import '@copilotkit/runtime-client-gql';
|
|
10
9
|
import 'react/jsx-runtime';
|
|
@@ -12,4 +11,3 @@ import './components/chat/Modal.js';
|
|
|
12
11
|
import 'react';
|
|
13
12
|
import '@copilotkit/react-core';
|
|
14
13
|
import './types/suggestions.js';
|
|
15
|
-
import '@copilotkit/shared';
|
package/dist/index.js
CHANGED
|
@@ -84,8 +84,7 @@ __export(src_exports, {
|
|
|
84
84
|
CopilotPopup: () => CopilotPopup,
|
|
85
85
|
CopilotSidebar: () => CopilotSidebar,
|
|
86
86
|
useChatContext: () => useChatContext,
|
|
87
|
-
useCopilotChatSuggestions: () => useCopilotChatSuggestions
|
|
88
|
-
useCopilotSuggestions: () => useCopilotSuggestions
|
|
87
|
+
useCopilotChatSuggestions: () => useCopilotChatSuggestions
|
|
89
88
|
});
|
|
90
89
|
module.exports = __toCommonJS(src_exports);
|
|
91
90
|
|
|
@@ -2310,108 +2309,12 @@ function useCopilotChatSuggestions({
|
|
|
2310
2309
|
};
|
|
2311
2310
|
}, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);
|
|
2312
2311
|
}
|
|
2313
|
-
|
|
2314
|
-
// src/hooks/use-copilot-suggestions.ts
|
|
2315
|
-
var import_react15 = require("react");
|
|
2316
|
-
var import_react_core10 = require("@copilotkit/react-core");
|
|
2317
|
-
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
2318
|
-
function useCopilotSuggestions({
|
|
2319
|
-
instructions,
|
|
2320
|
-
parameters,
|
|
2321
|
-
value,
|
|
2322
|
-
enabled = true,
|
|
2323
|
-
debounceTime = 1e3
|
|
2324
|
-
}, dependencies = []) {
|
|
2325
|
-
const suggestionsAbortControllerRef = (0, import_react15.useRef)(null);
|
|
2326
|
-
const debounceTimerRef = (0, import_react15.useRef)();
|
|
2327
|
-
const [suggestions, setSuggestions] = (0, import_react15.useState)({
|
|
2328
|
-
suggestions: void 0,
|
|
2329
|
-
isAvailable: false,
|
|
2330
|
-
isLoading: false
|
|
2331
|
-
});
|
|
2332
|
-
const isFirstRunRef = (0, import_react15.useRef)(true);
|
|
2333
|
-
const abortSuggestions = (0, import_react15.useCallback)(() => {
|
|
2334
|
-
var _a;
|
|
2335
|
-
(_a = suggestionsAbortControllerRef.current) == null ? void 0 : _a.abort();
|
|
2336
|
-
suggestionsAbortControllerRef.current = null;
|
|
2337
|
-
}, []);
|
|
2338
|
-
const generalContext = (0, import_react_core10.useCopilotContext)();
|
|
2339
|
-
const messagesContext = (0, import_react_core10.useCopilotMessagesContext)();
|
|
2340
|
-
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2341
|
-
(0, import_react15.useEffect)(() => {
|
|
2342
|
-
abortSuggestions();
|
|
2343
|
-
if (!enabled) {
|
|
2344
|
-
setSuggestions({ suggestions: void 0, isAvailable: false, isLoading: false });
|
|
2345
|
-
return;
|
|
2346
|
-
}
|
|
2347
|
-
if (JSON.stringify(value) === JSON.stringify(suggestions.suggestions)) {
|
|
2348
|
-
return;
|
|
2349
|
-
}
|
|
2350
|
-
debounceTimerRef.current = setTimeout(
|
|
2351
|
-
() => __async(this, null, function* () {
|
|
2352
|
-
isFirstRunRef.current = false;
|
|
2353
|
-
suggestionsAbortControllerRef.current = new AbortController();
|
|
2354
|
-
setSuggestions(__spreadProps(__spreadValues({}, suggestions), { isLoading: true }));
|
|
2355
|
-
yield reloadSuggestions2(
|
|
2356
|
-
context,
|
|
2357
|
-
instructions,
|
|
2358
|
-
parameters,
|
|
2359
|
-
value,
|
|
2360
|
-
suggestionsAbortControllerRef,
|
|
2361
|
-
setSuggestions
|
|
2362
|
-
);
|
|
2363
|
-
}),
|
|
2364
|
-
isFirstRunRef.current === true ? 0 : debounceTime
|
|
2365
|
-
);
|
|
2366
|
-
return () => {
|
|
2367
|
-
clearTimeout(debounceTimerRef.current);
|
|
2368
|
-
};
|
|
2369
|
-
}, [
|
|
2370
|
-
instructions,
|
|
2371
|
-
JSON.stringify(parameters),
|
|
2372
|
-
JSON.stringify(value),
|
|
2373
|
-
enabled,
|
|
2374
|
-
debounceTime,
|
|
2375
|
-
...dependencies
|
|
2376
|
-
]);
|
|
2377
|
-
return suggestions;
|
|
2378
|
-
}
|
|
2379
|
-
function reloadSuggestions2(context, instructions, parameters, value, abortControllerRef, setSuggestions) {
|
|
2380
|
-
return __async(this, null, function* () {
|
|
2381
|
-
const abortController = abortControllerRef.current;
|
|
2382
|
-
let fullInstructions = `It's your task to generate suggestions based on the application context.`;
|
|
2383
|
-
if (instructions) {
|
|
2384
|
-
fullInstructions += `
|
|
2385
|
-
|
|
2386
|
-
In addition, follow these specific instructions: ${instructions}`;
|
|
2387
|
-
}
|
|
2388
|
-
if (value) {
|
|
2389
|
-
fullInstructions += `
|
|
2390
|
-
|
|
2391
|
-
The current value of the parameter is: ${JSON.stringify(value)}.If it makes sense to complete the existing data, i.e. expand string values, add new elements to arrays, etc., do so. Otherwise, generate a new value.`;
|
|
2392
|
-
}
|
|
2393
|
-
yield (0, import_react_core10.extract)({
|
|
2394
|
-
context,
|
|
2395
|
-
instructions: instructions || "",
|
|
2396
|
-
data: fullInstructions,
|
|
2397
|
-
parameters,
|
|
2398
|
-
abortSignal: abortController == null ? void 0 : abortController.signal,
|
|
2399
|
-
requestType: import_runtime_client_gql5.CopilotRequestType.Task,
|
|
2400
|
-
stream({ args, status }) {
|
|
2401
|
-
if (status === "complete") {
|
|
2402
|
-
setSuggestions({ suggestions: args, isAvailable: true, isLoading: false });
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
});
|
|
2406
|
-
});
|
|
2407
|
-
}
|
|
2408
2312
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2409
2313
|
0 && (module.exports = {
|
|
2410
2314
|
CopilotChat,
|
|
2411
2315
|
CopilotPopup,
|
|
2412
2316
|
CopilotSidebar,
|
|
2413
2317
|
useChatContext,
|
|
2414
|
-
useCopilotChatSuggestions
|
|
2415
|
-
useCopilotSuggestions
|
|
2318
|
+
useCopilotChatSuggestions
|
|
2416
2319
|
});
|
|
2417
2320
|
//# sourceMappingURL=index.js.map
|