@alwith/module-chat 0.1.16 → 0.1.18
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/dist/approval/choice-schema.d.ts +1 -1
- package/dist/approval/schema-elicitation-form.d.ts +1 -1
- package/dist/composer/prompt-input-context.d.ts +13 -1
- package/dist/composer/prompt-input-context.js +1 -1
- package/dist/composer/prompt-input.d.ts +3 -1
- package/dist/composer/prompt-input.js +1 -1
- package/dist/types.d.ts +2 -2
- package/package.json +5 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ElicitationPropertySchema, ElicitationSchema } from "@agentclientprotocol/sdk/experimental/v2";
|
|
1
|
+
import type { ElicitationPropertySchema, ElicitationSchema } from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
2
2
|
export interface ElicitationField {
|
|
3
3
|
key: string;
|
|
4
4
|
property: ElicitationPropertySchema;
|
|
@@ -29,6 +29,8 @@ export type TextInputContext = {
|
|
|
29
29
|
value: string;
|
|
30
30
|
setInput: (v: string) => void;
|
|
31
31
|
clear: () => void;
|
|
32
|
+
getRevision?: () => number;
|
|
33
|
+
clearSubmitted?: () => void;
|
|
32
34
|
};
|
|
33
35
|
export type PromptInputControllerProps = {
|
|
34
36
|
textInput: TextInputContext;
|
|
@@ -37,12 +39,22 @@ export type PromptInputControllerProps = {
|
|
|
37
39
|
};
|
|
38
40
|
export declare const PromptInputSubmitContext: import("react").Context<((text: string) => void) | null>;
|
|
39
41
|
export declare function usePromptInputSubmit(): ((text: string) => void) | null;
|
|
42
|
+
export type PromptSubmitResult = {
|
|
43
|
+
status: "accepted";
|
|
44
|
+
} | {
|
|
45
|
+
status: "blocked";
|
|
46
|
+
reason: string;
|
|
47
|
+
};
|
|
48
|
+
export declare const PromptInputSubmissionContext: import("react").Context<(() => Promise<PromptSubmitResult>) | null>;
|
|
49
|
+
export declare function usePromptInputSubmission(): (() => Promise<PromptSubmitResult>) | null;
|
|
40
50
|
export declare const ProviderAttachmentsContext: import("react").Context<AttachmentsContext | null>;
|
|
41
51
|
export declare function usePromptInputController(): PromptInputControllerProps;
|
|
42
52
|
export declare const useOptionalPromptInputController: () => PromptInputControllerProps | null;
|
|
43
53
|
export declare function useProviderAttachments(): AttachmentsContext;
|
|
44
54
|
export type PromptInputProviderProps = PropsWithChildren<{
|
|
45
55
|
initialInput?: string;
|
|
56
|
+
revision?: number;
|
|
57
|
+
onSubmittedClear?: () => void;
|
|
46
58
|
attachmentPolicy?: AttachmentPolicy;
|
|
47
59
|
onRemoveAttachment?: () => void;
|
|
48
60
|
value?: string;
|
|
@@ -54,6 +66,6 @@ export type PromptInputProviderProps = PropsWithChildren<{
|
|
|
54
66
|
id: string;
|
|
55
67
|
})[]) => void;
|
|
56
68
|
}>;
|
|
57
|
-
export declare function PromptInputProvider({ initialInput: initialTextInput, onRemoveAttachment, attachmentPolicy, value, onValueChange, attachments: attachmentsControlled, onAttachmentsChange, children }: PromptInputProviderProps): import("react").JSX.Element;
|
|
69
|
+
export declare function PromptInputProvider({ initialInput: initialTextInput, revision, onSubmittedClear, onRemoveAttachment, attachmentPolicy, value, onValueChange, attachments: attachmentsControlled, onAttachmentsChange, children }: PromptInputProviderProps): import("react").JSX.Element;
|
|
58
70
|
export declare const LocalAttachmentsContext: import("react").Context<AttachmentsContext | null>;
|
|
59
71
|
export declare function usePromptInputAttachments(): AttachmentsContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as z}from"react/jsx-runtime";import{createContext as m,useCallback as n,useContext as u,useEffect as X,useMemo as D,useRef as v,useState as B}from"react";var w=m(null),Y=m(null);function rt(){return u(Y)}var Z=m(null);function ot(){return u(Z)}var A=m(null);function ut(){let r=u(w);if(!r)throw Error("Wrap your component inside <PromptInputProvider> to use usePromptInputController().");return r}var st=()=>u(w);function it(){let r=u(A);if(!r)throw Error("Wrap your component inside <PromptInputProvider> to use useProviderAttachments().");return r}var V=()=>u(A);function ct({initialInput:r="",revision:p,onSubmittedClear:s,onRemoveAttachment:L,attachmentPolicy:a,value:g,onValueChange:j,attachments:h,onAttachmentsChange:W,children:G}){let y=n((t)=>{if(t.type)return t.type;let e=(t.name||"").toLowerCase();if(e.endsWith(".png"))return"image/png";if(e.endsWith(".jpg")||e.endsWith(".jpeg"))return"image/jpeg";if(e.endsWith(".webp"))return"image/webp";if(e.endsWith(".gif"))return"image/gif";if(e.endsWith(".bmp"))return"image/bmp";if(e.endsWith(".svg"))return"image/svg+xml";return""},[]),T=g!==void 0,[H,J]=B(r),l=g!==void 0?g:H,o=v({value:l,external:p,revision:0});if(o.current.value!==l||o.current.external!==p)o.current={value:l,external:p,revision:o.current.revision+1};let C=n(()=>o.current.revision,[]),x=n((t)=>{if(o.current.value=t,o.current.revision++,T)j?.(t);else J(t)},[T,j]),b=n(()=>x(""),[x]),I=h!==void 0,[K,N]=B([]),P=h!==void 0?h:K,R=v(P);R.current=P;let i=n((t)=>{let e=typeof t==="function"?t(R.current):t;if(I)W?.(e);else N(e)},[I,W]),O=v(null),k=v(()=>{}),F=n((t)=>{let e=Array.from(t);if(e.length===0)return;i((f)=>{let d=a===void 0?e:a.uniqueFiles(e,f);return f.concat(d.map((c)=>{let q=a?.sourcePath(c);return{id:crypto.randomUUID(),type:"file",url:URL.createObjectURL(c),mediaType:y(c),filename:c.name,size:c.size,lastModified:c.lastModified,...q===void 0?{}:{sourcePath:q}}}))})},[a,y,i]),E=n((t)=>{i((e)=>{let f=e.find((d)=>d.id===t);if(f?.url)URL.revokeObjectURL(f.url);return e.filter((d)=>d.id!==t)}),L?.()},[L,i]),M=n(()=>{i((t)=>{for(let e of t)if(e.url)URL.revokeObjectURL(e.url);return[]})},[i]);X(()=>{if(I)return;return()=>{for(let t of R.current)if(t.url)URL.revokeObjectURL(t.url)}},[I]);let S=n(()=>{k.current?.()},[]),U=D(()=>({files:P,add:F,remove:E,clear:M,openFileDialog:S,fileInputRef:O}),[P,F,E,M,S]),_=n((t,e)=>{O.current=t.current,k.current=e},[]),Q=D(()=>({textInput:{value:l,setInput:x,clear:b,getRevision:C,clearSubmitted:s===void 0?b:s},attachments:U,__registerFileInput:_}),[l,x,b,C,s,U,_]);return z(w.Provider,{value:Q,children:z(A.Provider,{value:U,children:G})})}var tt=m(null);function pt(){let r=V(),p=u(tt),s=r??p;if(!s)throw Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return s}export{tt as LocalAttachmentsContext,ct as PromptInputProvider,Z as PromptInputSubmissionContext,Y as PromptInputSubmitContext,A as ProviderAttachmentsContext,st as useOptionalPromptInputController,pt as usePromptInputAttachments,ut as usePromptInputController,ot as usePromptInputSubmission,rt as usePromptInputSubmit,it as useProviderAttachments};
|
|
@@ -13,6 +13,8 @@ export type PromptInputProps = Omit<HTMLAttributes<HTMLFormElement>, "onSubmit"
|
|
|
13
13
|
attachmentPolicy?: AttachmentPolicy;
|
|
14
14
|
onCommand?: (text: string) => boolean;
|
|
15
15
|
onSubmitError: (error: unknown) => void;
|
|
16
|
+
canSubmit?: () => true | string;
|
|
17
|
+
onSubmitAsync?: (message: PromptInputMessage) => Promise<void>;
|
|
16
18
|
accept?: string;
|
|
17
19
|
multiple?: boolean;
|
|
18
20
|
globalDrop?: boolean;
|
|
@@ -25,7 +27,7 @@ export type PromptInputProps = Omit<HTMLAttributes<HTMLFormElement>, "onSubmit"
|
|
|
25
27
|
}) => void;
|
|
26
28
|
onSubmit: (message: PromptInputMessage, event: FormEvent<HTMLFormElement>) => void | Promise<void>;
|
|
27
29
|
};
|
|
28
|
-
export declare const PromptInput: ({ className, bashMode, attachmentPolicy, onCommand, onSubmitError, accept, multiple, globalDrop, syncHiddenInput, maxFiles, maxFileSize, onError, onSubmit, children, ...props }: PromptInputProps) => import("react").JSX.Element;
|
|
30
|
+
export declare const PromptInput: ({ className, bashMode, attachmentPolicy, onCommand, onSubmitError, canSubmit, onSubmitAsync, accept, multiple, globalDrop, syncHiddenInput, maxFiles, maxFileSize, onError, onSubmit, children, ...props }: PromptInputProps) => import("react").JSX.Element;
|
|
29
31
|
export type PromptInputBodyProps = HTMLAttributes<HTMLDivElement>;
|
|
30
32
|
export declare function PromptInputBody({ className, ...props }: PromptInputBodyProps): import("react").JSX.Element;
|
|
31
33
|
export type PromptInputHeaderProps = Omit<ComponentProps<typeof InputGroupAddon>, "align">;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as o,jsxs as
|
|
1
|
+
import{jsx as o,jsxs as me}from"react/jsx-runtime";import{ArrowUpIcon as pe,Loader2Icon as ge,SquareIcon as he,XIcon as be}from"lucide-react";import{Children as V,useCallback as v,useEffect as z,useMemo as ve,useRef as _,useState as xe}from"react";import{flushSync as Ie}from"react-dom";import{cn as x}from"cn";import{InputGroup as ye,InputGroupAddon as Y,InputGroupButton as Z}from"../ui/input-group.js";import{exceedsImageLimit as Le,MAX_TOTAL_IMAGE_MB as we}from"../lib/limits.js";import{preparePromptFiles as Te}from"../lib/prepare-prompt-files.js";import{LocalAttachmentsContext as ze,PromptInputSubmitContext as _e,PromptInputSubmissionContext as ke,ProviderAttachmentsContext as Ae,useOptionalPromptInputController as Pe}from"./prompt-input-context.js";import{MAX_TOTAL_IMAGE_MB as Je}from"../lib/limits.js";var Fe=({className:c,bashMode:l=!1,attachmentPolicy:I,onCommand:m,onSubmitError:y,canSubmit:p,onSubmitAsync:g,accept:k,multiple:ee,globalDrop:A,syncHiddenInput:D,maxFiles:S,maxFileSize:j,onError:h,onSubmit:te,children:re,...ne})=>{let s=Pe(),a=!!s,se=l&&a&&s.textInput.value.startsWith("!"),L=_(null),P=_(null),M=_(!1),[ie,U]=xe([]),d=a?s.attachments.files:ie,F=_(d);F.current=d;let oe=v(()=>{L.current?.click()},[]),O=v((e)=>{if(!k||k.trim()==="")return!0;return k.split(",").map((t)=>t.trim()).filter(Boolean).some((t)=>{if(t.endsWith("/*")){let n=t.slice(0,-1);return e.type.startsWith(n)}return e.type===t})},[k]),B=v((e)=>{if(e.type)return e.type;let r=(e.name||"").toLowerCase();if(r.endsWith(".png"))return"image/png";if(r.endsWith(".jpg")||r.endsWith(".jpeg"))return"image/jpeg";if(r.endsWith(".webp"))return"image/webp";if(r.endsWith(".gif"))return"image/gif";if(r.endsWith(".bmp"))return"image/bmp";if(r.endsWith(".svg"))return"image/svg+xml";return""},[]),ae=v((e)=>{let r=Array.from(e),t=r.filter((i)=>O(i));if(r.length&&t.length===0){h?.({code:"accept",message:"No files match the accepted types."});return}let n=(i)=>j?i.size<=j:!0,f=t.filter(n);if(t.length>0&&f.length===0){h?.({code:"max_file_size",message:"All files exceed the maximum size."});return}U((i)=>{let b=I?I.uniqueFiles(f,i):f,u=typeof S==="number"?Math.max(0,S-i.length):void 0,N=typeof u==="number"?b.slice(0,u):b;if(typeof u==="number"&&b.length>u)h?.({code:"max_files",message:"Too many files. Some were not added."});let K=[];for(let T of N){let Q=I?.sourcePath(T);K.push({id:crypto.randomUUID(),type:"file",url:URL.createObjectURL(T),mediaType:B(T),filename:T.name,size:T.size,lastModified:T.lastModified,...Q===void 0?{}:{sourcePath:Q}})}return i.concat(K)})},[I,B,O,S,j,h]),ue=v((e)=>U((r)=>{let t=r.find((n)=>n.id===e);if(t?.url)URL.revokeObjectURL(t.url);return r.filter((n)=>n.id!==e)}),[]),ce=v(()=>U((e)=>{for(let r of e)if(r.url)URL.revokeObjectURL(r.url);return[]}),[]),q=a?s.attachments.add:ae,w=v((e)=>{let r=Array.from(e),t=r.filter((f)=>!(f.type??"").toLowerCase().startsWith("image/"));if(t.length>0){h?.({code:"unsupported_type",message:`Only image attachments are supported. ${t.length} non-image file(s) were ignored.`});return}let n=r.reduce((f,i)=>f+i.size,0);if(n>0){let f=d.filter((i)=>(i.mediaType??"").toLowerCase().startsWith("image/")).reduce((i,b)=>i+(b.size??0),0);if(Le(f,n)){h?.({code:"max_total_size",message:`Total image size must not exceed ${we}MB.`});return}}q(r)},[d,q,h]),E=a?s.attachments.remove:ue,W=a?s.attachments.clear:ce,G=a?s.attachments.openFileDialog:oe;z(()=>{if(!a)return;s.__registerFileInput(L,()=>L.current?.click())},[a,s]),z(()=>{if(D&&L.current&&d.length===0)L.current.value=""},[d,D]),z(()=>{let e=P.current;if(!e)return;if(A)return;let r=(n)=>{if(n.dataTransfer?.types?.includes("Files"))n.preventDefault()},t=(n)=>{if(n.dataTransfer?.types?.includes("Files"))n.preventDefault();if(n.dataTransfer?.files&&n.dataTransfer.files.length>0)w(n.dataTransfer.files)};return e.addEventListener("dragover",r),e.addEventListener("drop",t),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",t)}},[w,A]),z(()=>{if(!A)return;let e=(t)=>{if(t.dataTransfer?.types?.includes("Files"))t.preventDefault()},r=(t)=>{if(t.dataTransfer?.types?.includes("Files"))t.preventDefault();if(t.dataTransfer?.files&&t.dataTransfer.files.length>0)w(t.dataTransfer.files)};return document.addEventListener("dragover",e),document.addEventListener("drop",r),()=>{document.removeEventListener("dragover",e),document.removeEventListener("drop",r)}},[w,A]),z(()=>()=>{if(!a){for(let e of F.current)if(e.url)URL.revokeObjectURL(e.url)}},[a]);let le=(e)=>{if(e.currentTarget.files)w(e.currentTarget.files);e.currentTarget.value=""},X=ve(()=>({files:d.map((e)=>({...e,id:e.id})),add:w,remove:E,clear:W,openFileDialog:G,fileInputRef:L}),[d,w,E,W,G]),R=_({controller:s,files:d,canSubmit:p});R.current={controller:s,files:d,canSubmit:p};let C=_(!0);z(()=>(C.current=!0,()=>{C.current=!1}),[]);let H=async(e)=>{let r=p===void 0?!0:p();if(r!==!0)return{status:"blocked",reason:r};if(M.current)return{status:"blocked",reason:"submission_pending"};if(e===null&&g===void 0)throw Error("Awaitable submission requires onSubmitAsync");let t=P.current;if(t===null)return{status:"blocked",reason:"form_unmounted"};let n=a?s.textInput.value:String(new FormData(t).get("message")??""),f=s?.textInput.getRevision?.(),i=d,b=()=>{if(!C.current)return;let u=R.current;if(u.files!==i)return;if(a){if(f===void 0||u.controller===null||u.controller.textInput.getRevision?.()!==f)return;if(u.controller.textInput.clearSubmitted===void 0)u.controller.textInput.clear();else u.controller.textInput.clearSubmitted()}else if(String(new FormData(t).get("message")??"")===n)t.reset();W()};M.current=!0;try{if(m?.(n.trim()))return b(),{status:"accepted"};let u=await Te(i),N=R.current.canSubmit===void 0?!0:R.current.canSubmit();if(N!==!0)return{status:"blocked",reason:N};if(!C.current)return{status:"blocked",reason:"form_unmounted"};if(u.rejectedCount>0)h?.({code:"accept",message:"One or more images are corrupted and were removed before sending."});if(g!==void 0)await g({text:n,files:u.files});else if(e!==null)await te({text:n,files:u.files},e);return b(),{status:"accepted"}}finally{M.current=!1}},fe=(e)=>{e.preventDefault(),H(e).catch(y)},de=v((e)=>{if(!e.trim())return;if(a&&s)Ie(()=>{s.textInput.setInput(e)});P.current?.requestSubmit()},[s,a]),J=o(ke.Provider,{value:()=>H(null),children:me(_e.Provider,{value:de,children:[o("input",{accept:k,"aria-label":"Upload files",className:"hidden",multiple:ee,onChange:le,ref:L,title:"Upload files",type:"file"}),o("form",{className:x("w-full",c),onSubmit:fe,ref:P,"data-tour":"chat-input",...ne,children:o(ye,{className:x("codex-composer-surface overflow-y-auto has-[[data-slot=input-group-control]:focus-visible]:ring-0",se&&"border! border-[rgb(255,0,135)] has-[[data-slot=input-group-control]:focus-visible]:border-[rgb(255,0,135)] dark:border-[rgb(253,93,177)] dark:has-[[data-slot=input-group-control]:focus-visible]:border-[rgb(253,93,177)]"),children:re})})]})});return a?o(Ae.Provider,{value:X,children:J}):o(ze.Provider,{value:X,children:J})};function Oe({className:c,...l}){return o("div",{className:x("flex w-full min-w-0 flex-row items-end gap-2",c),...l})}function Be({className:c,...l}){return o(Y,{align:"block-end",className:x("order-first flex-wrap gap-1 p-2 pb-1.5",c),...l})}function qe({className:c,...l}){return o(Y,{align:"block-end",className:x("mt-3.5 justify-between gap-1 p-0",c),...l})}function Ee({className:c,...l}){return o("div",{className:x("flex items-center gap-1",c),...l})}var Ge=({variant:c="ghost",className:l,size:I,collapsed:m=!1,...y})=>{let p=m||V.count(y.children)<=1?"icon-xs":"xs";return o(Z,{className:x("h-7 rounded-full text-xs font-medium hover:bg-transparent dark:hover:bg-transparent",(m||V.count(y.children)<=1)&&"size-7",l),size:p,type:"button",variant:c,...y})},Xe=({className:c,variant:l="ghost",size:I="icon-xs",status:m,children:y,...p})=>{let g=o(pe,{className:"size-4"});if(m==="submitted")g=o(ge,{className:"size-4 animate-spin"});else if(m==="streaming")g=o(he,{className:"size-3 fill-current"});else if(m==="error")g=o(be,{className:"size-4"});return o(Z,{"aria-label":"Submit",className:x("bg-foreground text-background hover:bg-foreground/70 size-7 rounded-full p-0 transition-opacity disabled:opacity-50",c),size:I,type:"submit",variant:l,...p,children:y??g})};export{Je as MAX_TOTAL_IMAGE_MB,Fe as PromptInput,Oe as PromptInputBody,Ge as PromptInputButton,qe as PromptInputFooter,Be as PromptInputHeader,Xe as PromptInputSubmit,Ee as PromptInputTools};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Cost, ElicitationSchema, PlanEntry, ToolCallContent, ToolCallLocation, ToolCallStatus } from "@agentclientprotocol/sdk/experimental/v2";
|
|
2
|
-
export type { Cost, PlanEntry, ToolCallContent, ToolCallLocation, ToolCallStatus } from "@agentclientprotocol/sdk/experimental/v2";
|
|
1
|
+
import type { Cost, ElicitationSchema, PlanEntry, ToolCallContent, ToolCallLocation, ToolCallStatus } from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
2
|
+
export type { Cost, PlanEntry, ToolCallContent, ToolCallLocation, ToolCallStatus } from "@agentclientprotocol/sdk/experimental/v2/unstable";
|
|
3
3
|
export type MentionUri = {
|
|
4
4
|
kind: "file";
|
|
5
5
|
absPath: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwith/module-chat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -269,9 +269,9 @@
|
|
|
269
269
|
},
|
|
270
270
|
"peerDependencies": {
|
|
271
271
|
"react": "^19.3.0",
|
|
272
|
-
"@agentclientprotocol/sdk": "^
|
|
272
|
+
"@agentclientprotocol/sdk": "^2.0.0",
|
|
273
273
|
"react-dom": "^19.3.0",
|
|
274
|
-
"@alwith/api": "^0.
|
|
274
|
+
"@alwith/api": "^0.4.13"
|
|
275
275
|
},
|
|
276
276
|
"files": [
|
|
277
277
|
"dist",
|
|
@@ -292,6 +292,8 @@
|
|
|
292
292
|
"prepack": "bun run build && bun test ../../scripts/__tests__/chat-worker-distribution.test.ts"
|
|
293
293
|
},
|
|
294
294
|
"devDependencies": {
|
|
295
|
+
"@agentclientprotocol/sdk": "^2.0.0",
|
|
296
|
+
"@alwith/api": "^0.4.13",
|
|
295
297
|
"@happy-dom/global-registrator": "^20.14.3",
|
|
296
298
|
"@testing-library/dom": "^10.4.1",
|
|
297
299
|
"@testing-library/react": "^16.3.3",
|