@xyd-js/ask-ai 0.0.0-build-7376fe0-20251003015041
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/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/_rollupPluginBabelHelpers-B0vHBMb8.js +4 -0
- package/dist/_rollupPluginBabelHelpers-B0vHBMb8.js.map +1 -0
- package/dist/components/index.d.ts +92 -0
- package/dist/components/index.js +2 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index-BgPZ1C19.js +30 -0
- package/dist/index-BgPZ1C19.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/node/index.d.ts +15 -0
- package/dist/node/index.js +2 -0
- package/dist/node/index.js.map +1 -0
- package/dist/react/index.d.ts +117 -0
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ReactWebComponent } from '@lit/react';
|
|
2
|
+
import * as lit_html from 'lit-html';
|
|
3
|
+
import * as lit from 'lit';
|
|
4
|
+
import { LitElement } from 'lit';
|
|
5
|
+
|
|
6
|
+
type Variant$1 = "default" | "secondary";
|
|
7
|
+
declare class AskAIButton extends LitElement {
|
|
8
|
+
inputValue: string;
|
|
9
|
+
isFocused: boolean;
|
|
10
|
+
readonly disabled = false;
|
|
11
|
+
readonly placeholder = "Ask a question...";
|
|
12
|
+
readonly variant: Variant$1;
|
|
13
|
+
static readonly styles: lit.CSSResult[];
|
|
14
|
+
render(): lit_html.TemplateResult<1>;
|
|
15
|
+
private isButtonDisabled;
|
|
16
|
+
private handleInput;
|
|
17
|
+
private handleFocus;
|
|
18
|
+
private handleBlur;
|
|
19
|
+
triggerSubmitOnEnter(e: KeyboardEvent): void;
|
|
20
|
+
private handleSubmit;
|
|
21
|
+
}
|
|
22
|
+
declare global {
|
|
23
|
+
interface HTMLElementTagNameMap {
|
|
24
|
+
"ask-ai-button": AskAIButton;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Variant = "default" | "compact" | "header";
|
|
29
|
+
declare class AskAIButtonIcon extends LitElement {
|
|
30
|
+
title: string;
|
|
31
|
+
ariaLabel: string;
|
|
32
|
+
icon: string;
|
|
33
|
+
disabled: boolean;
|
|
34
|
+
variant: Variant;
|
|
35
|
+
static styles: lit.CSSResult[];
|
|
36
|
+
render(): lit_html.TemplateResult<1>;
|
|
37
|
+
private renderIcon;
|
|
38
|
+
private handleClick;
|
|
39
|
+
}
|
|
40
|
+
declare global {
|
|
41
|
+
interface HTMLElementTagNameMap {
|
|
42
|
+
"ask-ai-button-icon": AskAIButtonIcon;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type MessageType = "user" | "assistant";
|
|
47
|
+
declare class AskAIMessage extends LitElement {
|
|
48
|
+
content: string;
|
|
49
|
+
type: MessageType;
|
|
50
|
+
showActions: boolean;
|
|
51
|
+
static styles: lit.CSSResult[];
|
|
52
|
+
render(): lit_html.TemplateResult<1>;
|
|
53
|
+
private renderActions;
|
|
54
|
+
}
|
|
55
|
+
declare global {
|
|
56
|
+
interface HTMLElementTagNameMap {
|
|
57
|
+
"ask-ai-msg": AskAIMessage;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare class AskAIDrawer extends LitElement {
|
|
62
|
+
open: boolean;
|
|
63
|
+
static styles: lit.CSSResult[];
|
|
64
|
+
render(): lit_html.TemplateResult<1>;
|
|
65
|
+
scrollToBottom(options?: ScrollToOptions): void;
|
|
66
|
+
protected updated(changed: Map<string, unknown>): void;
|
|
67
|
+
private closeDrawer;
|
|
68
|
+
}
|
|
69
|
+
declare global {
|
|
70
|
+
interface HTMLElementTagNameMap {
|
|
71
|
+
"ask-ai-drawer": AskAIDrawer;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare class AskAI$1 extends LitElement {
|
|
76
|
+
placeholder: string;
|
|
77
|
+
disabled: boolean;
|
|
78
|
+
drawerOpen: boolean;
|
|
79
|
+
private drawerEl;
|
|
80
|
+
static styles: lit.CSSResult[];
|
|
81
|
+
render(): lit_html.TemplateResult<1>;
|
|
82
|
+
private handleSlotchange;
|
|
83
|
+
private welcomeButton;
|
|
84
|
+
private handleMessageSent;
|
|
85
|
+
private handleDrawerClose;
|
|
86
|
+
}
|
|
87
|
+
declare global {
|
|
88
|
+
interface HTMLElementTagNameMap {
|
|
89
|
+
"ask-ai": AskAI$1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
type AskAIComponent = ReactWebComponent<AskAI$1> & {
|
|
94
|
+
Message: ReactWebComponent<AskAIMessage>;
|
|
95
|
+
} & {
|
|
96
|
+
onSubmit?: (event: CustomEvent<{
|
|
97
|
+
message: string;
|
|
98
|
+
}>) => void;
|
|
99
|
+
};
|
|
100
|
+
declare const AskAI: AskAIComponent;
|
|
101
|
+
|
|
102
|
+
interface Message {
|
|
103
|
+
id: string;
|
|
104
|
+
content: string;
|
|
105
|
+
type: "user" | "assistant";
|
|
106
|
+
showActions?: boolean;
|
|
107
|
+
}
|
|
108
|
+
declare function useAskAI(askUrl?: string): {
|
|
109
|
+
messages: Message[];
|
|
110
|
+
submit: (event: CustomEvent<{
|
|
111
|
+
message: string;
|
|
112
|
+
}>) => Promise<void>;
|
|
113
|
+
disabled: boolean;
|
|
114
|
+
loading: boolean;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export { AskAI, useAskAI };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e,{useState as t}from"react";import{createComponent as o}from"@lit/react";import{A as r,a as s}from"../index-BgPZ1C19.js";import"lit";import"../_rollupPluginBabelHelpers-B0vHBMb8.js";const a=o({tagName:"ask-ai",elementClass:r,react:e,events:{onSubmit:"submit"}});function n(e){const[o,r]=t([]),[s,a]=t(!1),[n,i]=t(!1);return{messages:o,submit:async t=>{const o={id:Date.now().toString(),content:t.detail.message,type:"user"};r(e=>[...e,o]);const s=(Date.now()+1).toString(),c={id:s,content:"",type:"assistant",showActions:!1};a(!0),i(!0),r(e=>[...e,c]);try{const o=await fetch(e||"/ask",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:t.detail.message})});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const a=o.body?.getReader();if(!a)throw new Error("No response body");const c=new TextDecoder;let m="";const d=async()=>{try{for(;;){const{done:e,value:t}=await a.read();if(e)break;const o=c.decode(t,{stream:!0});m+=o,m&&n&&i(!1),r(e=>e.map(e=>e.id===s?{...e,content:m}:e))}}catch(e){throw console.error("Stream processing error:",e),e}};await d(),r(e=>e.map(e=>e.id===s?{...e,showActions:!0}:e))}catch(e){console.error("Error making request:",e),r(t=>t.map(t=>t.id===s?{...t,content:`Error: ${e instanceof Error?e.message:"Unknown error occurred"}`}:t))}finally{a(!1),i(!1)}},disabled:s,loading:n}}a.Message=o({tagName:"ask-ai-message",elementClass:s,react:e});export{a as AskAI,n as useAskAI};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyd-js/ask-ai",
|
|
3
|
+
"version": "0.0.0-build-7376fe0-20251003015041",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./components": {
|
|
14
|
+
"import": "./dist/components/index.js",
|
|
15
|
+
"types": "./dist/components/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./react": {
|
|
18
|
+
"import": "./dist/react/index.js",
|
|
19
|
+
"types": "./dist/react/index.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./node": {
|
|
22
|
+
"import": "./dist/node/index.js",
|
|
23
|
+
"types": "./dist/node/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@ai-sdk/anthropic": "^2.0.23",
|
|
31
|
+
"@ai-sdk/openai": "^2.0.42",
|
|
32
|
+
"@lit/react": "^1.0.8",
|
|
33
|
+
"@modelcontextprotocol/sdk": "^1.18.1",
|
|
34
|
+
"ai": "^5.0.59",
|
|
35
|
+
"lit": "^3.3.1",
|
|
36
|
+
"react": "^19.0.0",
|
|
37
|
+
"react-dom": "^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@babel/core": "^7.25.0",
|
|
41
|
+
"@babel/plugin-proposal-decorators": "^7.25.0",
|
|
42
|
+
"@babel/preset-env": "^7.25.0",
|
|
43
|
+
"@babel/preset-react": "^7.25.0",
|
|
44
|
+
"@babel/preset-typescript": "^7.25.0",
|
|
45
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
46
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
47
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
48
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
|
49
|
+
"@types/node": "^24.6.2",
|
|
50
|
+
"@types/react": "^19.0.1",
|
|
51
|
+
"@types/react-dom": "^19.0.2",
|
|
52
|
+
"autoprefixer": "^10.4.20",
|
|
53
|
+
"netlify-cli": "^17.0.0",
|
|
54
|
+
"postcss": "^8.4.49",
|
|
55
|
+
"postcss-import": "^16.1.0",
|
|
56
|
+
"rollup": "^4.28.1",
|
|
57
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
58
|
+
"rollup-plugin-minify-html-literals": "^1.2.6",
|
|
59
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
60
|
+
"rollup-plugin-summary": "^1.4.0",
|
|
61
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
62
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
63
|
+
"typescript": "~5.8.3"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"build": "rollup -c",
|
|
67
|
+
"dev": "rollup -c --watch"
|
|
68
|
+
}
|
|
69
|
+
}
|