@copilotkit/react-core
Advanced tools
Comparing version
# ui | ||
## 0.3.0 | ||
### Minor Changes | ||
- working version | ||
- 9d2f3cb: semi compiling | ||
## 0.2.0 | ||
@@ -4,0 +11,0 @@ |
@@ -1,1 +0,55 @@ | ||
export { useTurbo } from './hook.js'; | ||
import React$1, { ReactNode } from 'react'; | ||
import { ChatCompletionFunctions } from 'openai-edge/types/api'; | ||
import { FunctionCallHandler, UseChatOptions, Message, CreateMessage, ChatRequestOptions } from 'ai'; | ||
declare function CopilotProvider({ children }: { | ||
children: ReactNode; | ||
}): JSX.Element; | ||
interface AnnotatedFunctionArgument { | ||
name: string; | ||
type: string; | ||
description: string; | ||
allowedValues?: any[]; | ||
required: boolean; | ||
} | ||
interface AnnotatedFunction<Inputs extends any[]> { | ||
name: string; | ||
description: string; | ||
argumentAnnotations: AnnotatedFunctionArgument[]; | ||
implementation: (...args: Inputs) => Promise<void>; | ||
} | ||
type TreeNodeId = string; | ||
interface CopilotContextParams { | ||
entryPoints: Record<string, AnnotatedFunction<any[]>>; | ||
getChatCompletionFunctions: () => ChatCompletionFunctions[]; | ||
getFunctionCallHandler: () => FunctionCallHandler; | ||
setEntryPoint: (id: string, entryPoint: AnnotatedFunction<any[]>) => void; | ||
removeEntryPoint: (id: string) => void; | ||
getContextString: () => string; | ||
addContext: (context: string, parentId?: string) => TreeNodeId; | ||
removeContext: (id: TreeNodeId) => void; | ||
} | ||
declare const CopilotContext: React$1.Context<CopilotContextParams>; | ||
interface UseCopilotChatOptions extends UseChatOptions { | ||
makeSystemMessage?: (contextString: string) => string; | ||
} | ||
interface UseCopilotChatReturn { | ||
visibleMessages: Message[]; | ||
append: (message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>; | ||
reload: (chatRequestOptions?: ChatRequestOptions) => Promise<string | null | undefined>; | ||
stop: () => void; | ||
isLoading: boolean; | ||
input: string; | ||
setInput: React.Dispatch<React.SetStateAction<string>>; | ||
} | ||
declare function useCopilotChat({ makeSystemMessage, ...options }: UseCopilotChatOptions): UseCopilotChatReturn; | ||
declare function useMakeCopilotActionable<ActionInput extends any[]>(annotatedFunction: AnnotatedFunction<ActionInput>, dependencies: any[]): void; | ||
declare function useMakeCopilotReadable(information: string, parentId?: string): string | undefined; | ||
export { AnnotatedFunction, AnnotatedFunctionArgument, CopilotContext, CopilotContextParams, CopilotProvider, UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat, useMakeCopilotActionable, useMakeCopilotReadable }; |
'use strict'; | ||
var chunkKFCOT2YX_js = require('./chunk-KFCOT2YX.js'); | ||
var V = require('react'); | ||
var nanoid = require('nanoid'); | ||
var jsxRuntime = require('react/jsx-runtime'); | ||
var react = require('ai/react'); | ||
var k=Object.defineProperty,q=Object.defineProperties;var U=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var N=(e,t,n)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,h=(e,t)=>{for(var n in t||(t={}))P.call(t,n)&&N(e,n,t[n]);if(x)for(var n of x(t))A.call(t,n)&&N(e,n,t[n]);return e},T=(e,t)=>q(e,U(t));var E=(e,t)=>{var n={};for(var o in e)P.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(e!=null&&x)for(var o of x(e))t.indexOf(o)<0&&A.call(e,o)&&(n[o]=e[o]);return n};var v=(e,t,n)=>new Promise((o,r)=>{var i=u=>{try{a(n.next(u));}catch(c){r(c);}},s=u=>{try{a(n.throw(u));}catch(c){r(c);}},a=u=>u.done?o(u.value):Promise.resolve(u.value).then(i,s);a((n=n.apply(e,t)).next());});var I=(e,t)=>{for(let n of e){if(n.id===t)return n;let o=I(n.children,t);if(o)return o}},M=(e,t)=>e.reduce((n,o)=>{if(o.id!==t){let r=T(h({},o),{children:M(o.children,t)});n.push(r);}return n},[]),b=(e,t)=>{if(t===0)return (e+1).toString();if(t===1)return String.fromCharCode(65+e);if(t===2)return String.fromCharCode(97+e);throw new Error("Indentation level not supported")},O=(e,t="",n=0)=>{let o=" ".repeat(3).repeat(n),r=t.length+o.length,i=" ".repeat(r),s=e.value.split(` | ||
`),a=`${o}${t}${s[0]}`,u=s.slice(1).map(l=>`${i}${l}`).join(` | ||
`),c=`${a} | ||
`;return u&&(c+=`${u} | ||
`),e.children.forEach((l,g)=>c+=O(l,`${t}${b(g,n+1)}. `,n+1)),c};function j(e,t){switch(t.type){case"ADD_NODE":{let{value:n,parentId:o,id:r}=t,i={id:r,value:n,children:[]};if(o){let s=I(e,o);if(s)i.parentId=o,s.children.push(i);else throw new Error(`Parent with id ${o} not found`)}else return [...e,i];return e}case"REMOVE_NODE":return M(e,t.id);default:return e}}var L=()=>{let[e,t]=V.useReducer(j,[]),n=V.useCallback((i,s)=>{let a=nanoid.nanoid();return t({type:"ADD_NODE",value:i,parentId:s,id:a}),a},[]),o=V.useCallback(i=>{t({type:"REMOVE_NODE",id:i});},[]);return {tree:e,addElement:n,printTree:()=>{let i="";return e.forEach((s,a)=>i+=O(s,`${b(a,0)}. `)),i},removeElement:o}},w=L;var J={entryPoints:{},getChatCompletionFunctions:()=>[],getFunctionCallHandler:()=>()=>v(void 0,null,function*(){}),setEntryPoint:()=>{},removeEntryPoint:()=>{},getContextString:()=>"",addContext:()=>"",removeContext:()=>{}},d=V.createContext(J);function B({children:e}){let[t,n]=V.useState({}),{addElement:o,removeElement:r,printTree:i}=w(),s=V.useCallback((p,m)=>{n(C=>T(h({},C),{[p]:m}));},[]),a=V.useCallback(p=>{n(m=>{let C=h({},m);return delete C[p],C});},[]),u=V.useCallback(()=>i(),[i]),c=V.useCallback((p,m)=>o(p,m),[o]),l=V.useCallback(p=>{r(p);},[r]),g=V.useCallback(()=>X(Object.values(t)),[t]),F=V.useCallback(()=>W(Object.values(t)),[t]);return jsxRuntime.jsx(d.Provider,{value:{entryPoints:t,getChatCompletionFunctions:g,getFunctionCallHandler:F,setEntryPoint:s,removeEntryPoint:a,getContextString:u,addContext:c,removeContext:l},children:e})}function W(e){return (t,n)=>v(this,null,function*(){let o={};for(let i of e)o[i.name]=i;let r=o[n.name||""];if(r){let i=[];n.arguments&&(i=JSON.parse(n.arguments));let s=[];for(let a of r.argumentAnnotations)s.push(i[a.name]);yield r.implementation(...s);}})}function X(e){return e.map(Y)}function Y(e){let t={};for(let r of e.argumentAnnotations)t[r.name]={type:r.type,description:r.description};let n=[];for(let r of e.argumentAnnotations)r.required&&n.push(r.name);return {name:e.name,description:e.description,parameters:{type:"object",properties:t,required:n}}}function Z(n){var o=n,{makeSystemMessage:e}=o,t=E(o,["makeSystemMessage"]);let{getContextString:r,getChatCompletionFunctions:i,getFunctionCallHandler:s}=V.useContext(d),u=[V.useMemo(()=>{let y=e||te,$=r();return {id:"system",content:y($),role:"system"}},[r,e])].concat(t.initialMessages||[]),c=V.useMemo(()=>i(),[i]),{messages:l,append:g,reload:F,stop:p,isLoading:m,input:C,setInput:D}=react.useChat({id:t.id,initialMessages:u,experimental_onFunctionCall:s(),body:{id:t.id,previewToken:ee,functions:c}});return {visibleMessages:l.filter(y=>y.role==="user"||y.role==="assistant"),append:g,reload:F,stop:p,isLoading:m,input:C,setInput:D}}var ee="TODO123";function te(e){return ` | ||
Please act as a efficient, competent, and conscientious professional assistant. | ||
You help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism. | ||
Always be polite and respectful, and prefer brevity over verbosity. | ||
The user has provided you with the following context: | ||
\`\`\` | ||
${e} | ||
\`\`\` | ||
Object.defineProperty(exports, 'useTurbo', { | ||
enumerable: true, | ||
get: function () { return chunkKFCOT2YX_js.a; } | ||
}); | ||
They have also provided you with functions you can call to initiate actions on their behalf, or functions you can call to receive more information. | ||
Please assist them as best you can. | ||
If you are not sure how to proceed to best fulfill their requests, please ask them for more information. | ||
`}function ae(e,t){let n=V.useRef(nanoid.nanoid()),{setEntryPoint:o,removeEntryPoint:r}=V.useContext(d),i=V.useMemo(()=>({name:e.name,description:e.description,argumentAnnotations:e.argumentAnnotations,implementation:e.implementation}),t);V.useEffect(()=>(o(n.current,i),()=>{r(n.current);}),[i,o,r]);}function de(e,t){let{addContext:n,removeContext:o}=V.useContext(d),r=V.useRef();return V.useEffect(()=>{let i=n(e,t);return r.current=i,()=>{o(i);}},[e,t,n,o]),r.current} | ||
exports.CopilotContext = d; | ||
exports.CopilotProvider = B; | ||
exports.useCopilotChat = Z; | ||
exports.useMakeCopilotActionable = ae; | ||
exports.useMakeCopilotReadable = de; |
@@ -7,11 +7,8 @@ { | ||
}, | ||
"version": "0.2.0", | ||
"sideEffects": [ | ||
"**/*.css" | ||
], | ||
"version": "0.3.0", | ||
"sideEffects": false, | ||
"main": "./dist/index.mjs", | ||
"module": "./dist/index.mjs", | ||
"exports": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": "./dist", | ||
"./styles.css": "./dist/index.css" | ||
}, | ||
"license": "MIT", | ||
@@ -27,10 +24,16 @@ "peerDependencies": { | ||
"typescript": "^4.9.4", | ||
"eslint-config-custom": "0.0.0", | ||
"tsconfig": "0.0.0" | ||
"eslint-config-custom": "0.1.0", | ||
"tsconfig": "0.1.0" | ||
}, | ||
"dependencies": { | ||
"ai": "^2.1.19", | ||
"nanoid": "^4.0.2", | ||
"openai-edge": "^1.2.0" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format cjs --dts", | ||
"dev": "tsup --watch", | ||
"check-types": "tsc --noEmit" | ||
"build": "tsup src/index.tsx --format esm,cjs --dts --external react", | ||
"dev": "tsup src/index.tsx --format esm,cjs --dts --external react --watch", | ||
"check-types": "tsc --noEmit", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next" | ||
} | ||
} |
@@ -14,1 +14,2 @@ import { defineConfig, Options } from "tsup"; | ||
})); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
31231
946.62%20
66.67%614
940.68%4
300%4
100%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added