@tinkrapp/widget 1.0.0
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/client-CExUGn7b.d.cts +147 -0
- package/dist/client-CExUGn7b.d.ts +147 -0
- package/dist/course-ai-widget.css +2 -0
- package/dist/course-ai-widget.css.map +1 -0
- package/dist/course-ai-widget.global.js +632 -0
- package/dist/course-ai-widget.global.js.map +1 -0
- package/dist/index.cjs +233 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +229 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +4857 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +165 -0
- package/dist/react.d.ts +165 -0
- package/dist/react.js +4815 -0
- package/dist/react.js.map +1 -0
- package/package.json +104 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
interface WidgetConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The API key for this widget instance.
|
|
4
|
+
* This is the Assistant ID that identifies which AI assistant to use.
|
|
5
|
+
* Get this from your Tinkr dashboard after creating an assistant.
|
|
6
|
+
*/
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/**
|
|
9
|
+
* The Assistant ID that identifies which AI assistant to use.
|
|
10
|
+
* @deprecated Use apiKey instead - they serve the same purpose.
|
|
11
|
+
*/
|
|
12
|
+
assistantId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The base URL for the API.
|
|
15
|
+
* Defaults to 'http://localhost:3000' in development.
|
|
16
|
+
* Set to your production URL when deploying.
|
|
17
|
+
*/
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional user ID to identify the user across sessions.
|
|
21
|
+
* If not provided, a random UUID will be generated.
|
|
22
|
+
*/
|
|
23
|
+
userId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Enable debug logging in the console.
|
|
26
|
+
*/
|
|
27
|
+
debug?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface Message {
|
|
30
|
+
id: string;
|
|
31
|
+
role: 'user' | 'assistant' | 'system';
|
|
32
|
+
content: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
interface ChatSession {
|
|
37
|
+
id: string;
|
|
38
|
+
/** The API key (Assistant ID) this session belongs to */
|
|
39
|
+
apiKey: string;
|
|
40
|
+
messages: Message[];
|
|
41
|
+
createdAt: number;
|
|
42
|
+
}
|
|
43
|
+
interface Artifact {
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
category: ArtifactCategory;
|
|
47
|
+
content: string;
|
|
48
|
+
createdAt: number;
|
|
49
|
+
updatedAt: number;
|
|
50
|
+
}
|
|
51
|
+
type ArtifactCategory = 'audio' | 'audio-overview' | 'flashcards' | 'infographic' | 'mind-map' | 'quiz' | 'reports' | 'slide-deck' | 'video-overview';
|
|
52
|
+
type WidgetState = {
|
|
53
|
+
status: 'idle';
|
|
54
|
+
} | {
|
|
55
|
+
status: 'initializing';
|
|
56
|
+
} | {
|
|
57
|
+
status: 'ready';
|
|
58
|
+
session: ChatSession;
|
|
59
|
+
} | {
|
|
60
|
+
status: 'loading';
|
|
61
|
+
} | {
|
|
62
|
+
status: 'error';
|
|
63
|
+
error: WidgetError;
|
|
64
|
+
};
|
|
65
|
+
interface WidgetError {
|
|
66
|
+
code: string;
|
|
67
|
+
message: string;
|
|
68
|
+
details?: unknown;
|
|
69
|
+
}
|
|
70
|
+
type WidgetEvents = {
|
|
71
|
+
'state:change': {
|
|
72
|
+
previous: WidgetState;
|
|
73
|
+
current: WidgetState;
|
|
74
|
+
};
|
|
75
|
+
'message:sent': {
|
|
76
|
+
message: Message;
|
|
77
|
+
};
|
|
78
|
+
'message:received': {
|
|
79
|
+
message: Message;
|
|
80
|
+
};
|
|
81
|
+
'error': {
|
|
82
|
+
error: WidgetError;
|
|
83
|
+
};
|
|
84
|
+
'session:created': {
|
|
85
|
+
session: ChatSession;
|
|
86
|
+
};
|
|
87
|
+
'artifact:created': {
|
|
88
|
+
artifact: Artifact;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
declare class WidgetAPI {
|
|
93
|
+
private config;
|
|
94
|
+
constructor(config: WidgetConfig);
|
|
95
|
+
createSession(): Promise<ChatSession>;
|
|
96
|
+
sendMessage(sessionId: string, content: string): Promise<Message>;
|
|
97
|
+
getHistory(sessionId: string): Promise<Message[]>;
|
|
98
|
+
getSessions(): Promise<ChatSession[]>;
|
|
99
|
+
getArtifacts(): Promise<Artifact[]>;
|
|
100
|
+
getArtifact(id: string): Promise<Artifact>;
|
|
101
|
+
createArtifact(artifact: Omit<Artifact, 'id' | 'createdAt' | 'updatedAt'>): Promise<Artifact>;
|
|
102
|
+
private request;
|
|
103
|
+
private log;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
declare class WidgetClient {
|
|
107
|
+
private config;
|
|
108
|
+
private state;
|
|
109
|
+
private events;
|
|
110
|
+
private api;
|
|
111
|
+
constructor(config: WidgetConfig);
|
|
112
|
+
/**
|
|
113
|
+
* Initialize the widget and create a chat session
|
|
114
|
+
*/
|
|
115
|
+
initialize(): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Send a message to the AI assistant
|
|
118
|
+
*/
|
|
119
|
+
sendMessage(content: string): Promise<Message>;
|
|
120
|
+
/**
|
|
121
|
+
* Get current state
|
|
122
|
+
*/
|
|
123
|
+
getState(): WidgetState;
|
|
124
|
+
/**
|
|
125
|
+
* Get the API instance for direct calls
|
|
126
|
+
*/
|
|
127
|
+
getAPI(): WidgetAPI;
|
|
128
|
+
/**
|
|
129
|
+
* Get the widget configuration
|
|
130
|
+
*/
|
|
131
|
+
getConfig(): WidgetConfig;
|
|
132
|
+
/**
|
|
133
|
+
* Subscribe to events
|
|
134
|
+
*/
|
|
135
|
+
on<K extends keyof WidgetEvents>(event: K, handler: (payload: WidgetEvents[K]) => void): () => void;
|
|
136
|
+
/**
|
|
137
|
+
* Unsubscribe from events
|
|
138
|
+
*/
|
|
139
|
+
off<K extends keyof WidgetEvents>(event: K, handler: (payload: WidgetEvents[K]) => void): void;
|
|
140
|
+
/**
|
|
141
|
+
* Clean up resources
|
|
142
|
+
*/
|
|
143
|
+
destroy(): void;
|
|
144
|
+
private setState;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { type Artifact as A, type ChatSession as C, type Message as M, WidgetClient as W, WidgetAPI as a, type WidgetConfig as b, type WidgetState as c, type WidgetEvents as d, type WidgetError as e, type ArtifactCategory as f };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
interface WidgetConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The API key for this widget instance.
|
|
4
|
+
* This is the Assistant ID that identifies which AI assistant to use.
|
|
5
|
+
* Get this from your Tinkr dashboard after creating an assistant.
|
|
6
|
+
*/
|
|
7
|
+
apiKey: string;
|
|
8
|
+
/**
|
|
9
|
+
* The Assistant ID that identifies which AI assistant to use.
|
|
10
|
+
* @deprecated Use apiKey instead - they serve the same purpose.
|
|
11
|
+
*/
|
|
12
|
+
assistantId?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The base URL for the API.
|
|
15
|
+
* Defaults to 'http://localhost:3000' in development.
|
|
16
|
+
* Set to your production URL when deploying.
|
|
17
|
+
*/
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional user ID to identify the user across sessions.
|
|
21
|
+
* If not provided, a random UUID will be generated.
|
|
22
|
+
*/
|
|
23
|
+
userId?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Enable debug logging in the console.
|
|
26
|
+
*/
|
|
27
|
+
debug?: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface Message {
|
|
30
|
+
id: string;
|
|
31
|
+
role: 'user' | 'assistant' | 'system';
|
|
32
|
+
content: string;
|
|
33
|
+
timestamp: number;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
interface ChatSession {
|
|
37
|
+
id: string;
|
|
38
|
+
/** The API key (Assistant ID) this session belongs to */
|
|
39
|
+
apiKey: string;
|
|
40
|
+
messages: Message[];
|
|
41
|
+
createdAt: number;
|
|
42
|
+
}
|
|
43
|
+
interface Artifact {
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
category: ArtifactCategory;
|
|
47
|
+
content: string;
|
|
48
|
+
createdAt: number;
|
|
49
|
+
updatedAt: number;
|
|
50
|
+
}
|
|
51
|
+
type ArtifactCategory = 'audio' | 'audio-overview' | 'flashcards' | 'infographic' | 'mind-map' | 'quiz' | 'reports' | 'slide-deck' | 'video-overview';
|
|
52
|
+
type WidgetState = {
|
|
53
|
+
status: 'idle';
|
|
54
|
+
} | {
|
|
55
|
+
status: 'initializing';
|
|
56
|
+
} | {
|
|
57
|
+
status: 'ready';
|
|
58
|
+
session: ChatSession;
|
|
59
|
+
} | {
|
|
60
|
+
status: 'loading';
|
|
61
|
+
} | {
|
|
62
|
+
status: 'error';
|
|
63
|
+
error: WidgetError;
|
|
64
|
+
};
|
|
65
|
+
interface WidgetError {
|
|
66
|
+
code: string;
|
|
67
|
+
message: string;
|
|
68
|
+
details?: unknown;
|
|
69
|
+
}
|
|
70
|
+
type WidgetEvents = {
|
|
71
|
+
'state:change': {
|
|
72
|
+
previous: WidgetState;
|
|
73
|
+
current: WidgetState;
|
|
74
|
+
};
|
|
75
|
+
'message:sent': {
|
|
76
|
+
message: Message;
|
|
77
|
+
};
|
|
78
|
+
'message:received': {
|
|
79
|
+
message: Message;
|
|
80
|
+
};
|
|
81
|
+
'error': {
|
|
82
|
+
error: WidgetError;
|
|
83
|
+
};
|
|
84
|
+
'session:created': {
|
|
85
|
+
session: ChatSession;
|
|
86
|
+
};
|
|
87
|
+
'artifact:created': {
|
|
88
|
+
artifact: Artifact;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
declare class WidgetAPI {
|
|
93
|
+
private config;
|
|
94
|
+
constructor(config: WidgetConfig);
|
|
95
|
+
createSession(): Promise<ChatSession>;
|
|
96
|
+
sendMessage(sessionId: string, content: string): Promise<Message>;
|
|
97
|
+
getHistory(sessionId: string): Promise<Message[]>;
|
|
98
|
+
getSessions(): Promise<ChatSession[]>;
|
|
99
|
+
getArtifacts(): Promise<Artifact[]>;
|
|
100
|
+
getArtifact(id: string): Promise<Artifact>;
|
|
101
|
+
createArtifact(artifact: Omit<Artifact, 'id' | 'createdAt' | 'updatedAt'>): Promise<Artifact>;
|
|
102
|
+
private request;
|
|
103
|
+
private log;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
declare class WidgetClient {
|
|
107
|
+
private config;
|
|
108
|
+
private state;
|
|
109
|
+
private events;
|
|
110
|
+
private api;
|
|
111
|
+
constructor(config: WidgetConfig);
|
|
112
|
+
/**
|
|
113
|
+
* Initialize the widget and create a chat session
|
|
114
|
+
*/
|
|
115
|
+
initialize(): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Send a message to the AI assistant
|
|
118
|
+
*/
|
|
119
|
+
sendMessage(content: string): Promise<Message>;
|
|
120
|
+
/**
|
|
121
|
+
* Get current state
|
|
122
|
+
*/
|
|
123
|
+
getState(): WidgetState;
|
|
124
|
+
/**
|
|
125
|
+
* Get the API instance for direct calls
|
|
126
|
+
*/
|
|
127
|
+
getAPI(): WidgetAPI;
|
|
128
|
+
/**
|
|
129
|
+
* Get the widget configuration
|
|
130
|
+
*/
|
|
131
|
+
getConfig(): WidgetConfig;
|
|
132
|
+
/**
|
|
133
|
+
* Subscribe to events
|
|
134
|
+
*/
|
|
135
|
+
on<K extends keyof WidgetEvents>(event: K, handler: (payload: WidgetEvents[K]) => void): () => void;
|
|
136
|
+
/**
|
|
137
|
+
* Unsubscribe from events
|
|
138
|
+
*/
|
|
139
|
+
off<K extends keyof WidgetEvents>(event: K, handler: (payload: WidgetEvents[K]) => void): void;
|
|
140
|
+
/**
|
|
141
|
+
* Clean up resources
|
|
142
|
+
*/
|
|
143
|
+
destroy(): void;
|
|
144
|
+
private setState;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { type Artifact as A, type ChatSession as C, type Message as M, WidgetClient as W, WidgetAPI as a, type WidgetConfig as b, type WidgetState as c, type WidgetEvents as d, type WidgetError as e, type ArtifactCategory as f };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
@keyframes aui-pulse{50%{opacity:.5}}:where(.aui-md[data-status=running]):empty:after,:where(.aui-md[data-status=running])>:where(:not(ol):not(ul):not(pre)):last-child:after,:where(.aui-md[data-status=running])>pre:last-child code:after,:where(.aui-md[data-status=running])>:where(:is(ol,ul):last-child)>:where(li:last-child:not(:has(*>li))):after,:where(.aui-md[data-status=running])>:where(:is(ol,ul):last-child)>:where(li:last-child)>:where(:is(ol,ul):last-child)>:where(li:last-child:not(:has(*>li))):after,:where(.aui-md[data-status=running])>:where(:is(ol,ul):last-child)>:where(li:last-child)>:where(:is(ol,ul):last-child)>:where(li:last-child)>:where(:is(ol,ul):last-child)>:where(li:last-child):after{animation:aui-pulse 2s cubic-bezier(.4,0,.6,1) infinite;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";--aui-content: "\25cf";content:var(--aui-content);margin-left:.25rem;margin-right:.25rem}
|
|
2
|
+
/*# sourceMappingURL=course-ai-widget.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/@assistant-ui/react-markdown/styles/dot.css"],"sourcesContent":["@keyframes aui-pulse {\n 50% {\n opacity: 0.5;\n }\n}\n\n:where(.aui-md[data-status=\"running\"]):empty::after,\n:where(.aui-md[data-status=\"running\"])\n > :where(:not(ol):not(ul):not(pre)):last-child::after,\n:where(.aui-md[data-status=\"running\"]) > pre:last-child code::after,\n:where(.aui-md[data-status=\"running\"])\n > :where(:is(ol, ul):last-child)\n > :where(li:last-child:not(:has(* > li)))::after,\n:where(.aui-md[data-status=\"running\"])\n > :where(:is(ol, ul):last-child)\n > :where(li:last-child)\n > :where(:is(ol, ul):last-child)\n > :where(li:last-child:not(:has(* > li)))::after,\n:where(.aui-md[data-status=\"running\"])\n > :where(:is(ol, ul):last-child)\n > :where(li:last-child)\n > :where(:is(ol, ul):last-child)\n > :where(li:last-child)\n > :where(:is(ol, ul):last-child)\n > :where(li:last-child)::after {\n animation: aui-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;\n font-family:\n ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\",\n \"Segoe UI Symbol\", \"Noto Color Emoji\";\n --aui-content: \"\\25cf\";\n content: var(--aui-content);\n margin-left: 0.25rem;\n margin-right: 0.25rem;\n}\n"],"mappings":"AAAA,WAAW,UACT,IACE,QAAS,EACX,CACF,CAEA,OAAO,CAAC,MAAM,CAAC,qBAAuB,MAAM,OAC5C,OAAO,CADC,MACM,CAAC,qBACb,CAAE,OAAO,KAAK,GAAG,KAAK,GAAG,KAAK,KAAK,WAAW,OAChD,OAAO,CAHC,MAGM,CAAC,qBAAwB,CAAE,GAAG,YAAY,IAAI,OAC5D,OAAO,CAJC,MAIM,CAAC,qBACb,CAAE,OAAO,IAAI,GAAI,GAAG,YACpB,CAAE,OAAO,EAAE,WAAW,KAAK,KAAK,CAAE,CAAE,KAAK,OAC3C,OAAO,CAPC,MAOM,CAAC,qBACb,CAAE,OAAO,IAAI,GAAI,GAAG,YACpB,CAAE,OAAO,EAAE,YACX,CAAE,OAAO,IAAI,GAAI,GAAG,YACpB,CAAE,OAAO,EAAE,WAAW,KAAK,KAAK,CAAE,CAAE,KAAK,OAC3C,OAAO,CAZC,MAYM,CAAC,qBACb,CAAE,OAAO,IAAI,GAAI,GAAG,YACpB,CAAE,OAAO,EAAE,YACX,CAAE,OAAO,IAAI,GAAI,GAAG,YACpB,CAAE,OAAO,EAAE,YACX,CAAE,OAAO,IAAI,GAAI,GAAG,YACpB,CAAE,OAAO,EAAE,YAAY,OACvB,UAAW,UAAU,GAAG,aAAa,EAAG,CAAE,CAAC,CAAE,EAAG,CAAE,GAAG,SACrD,YACE,aAAa,CAAE,SAAS,CAAE,UAAU,CAAE,mBAAmB,CAAE,gBAAgB,CAC3E,eAAiB,CAAE,mBACrB,eAAe,QACf,QAAS,IAAI,eACb,YAAa,OACb,aAAc,MAChB","names":[]}
|