Skip to content

Commit 0136c85

Browse files
Merge branch 'main' into fix/supported-locale-link
2 parents 5111912 + 2631491 commit 0136c85

File tree

11 files changed

+103
-40
lines changed

11 files changed

+103
-40
lines changed

.changeset/config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
"linked": [],
77
"access": "public",
88
"baseBranch": "main",
9-
"updateInternalDependencies": "patch",
10-
"ignore": ["react-explorer"]
9+
"updateInternalDependencies": "patch"
1110
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ Just add the ChatKit component, give it a client token, and customize the chat e
8383
}
8484
```
8585

86+
## See working examples
87+
88+
- [Starter app](https://github.com/openai/openai-chatkit-starter-app) - Clone a repo to start with a fully working template
89+
- [Samples](https://github.com/openai/openai-chatkit-advanced-samples) - See working examples of ChatKit and get inspired
90+
8691
## License
8792

8893
This project is licensed under the [Apache License 2.0](LICENSE).
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# @openai/chatkit-react
2+
3+
## 1.1.1
4+
5+
### Patch Changes
6+
7+
- 7385e2f: Fix issue where ref was not being set
8+
9+
## 1.1.0
10+
11+
### Minor Changes
12+
13+
- 3de3243: Exposed a ref to the underlying `OpenAIChatKit` DOM element in the return value of `useChatKit`
14+
15+
### Patch Changes
16+
17+
- 3de3243: Removed usage of React 19 only ref callback cleanup function
18+
19+
## 1.0.0
20+
21+
### Major Changes
22+
23+
- 5e4488e: Initial release
24+
25+
### Patch Changes
26+
27+
- Updated dependencies [5e4488e]
28+
- @openai/chatkit@1.0.0

packages/chatkit-react/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openai/chatkit-react",
3-
"version": "0.0.0",
3+
"version": "1.1.1",
44
"description": "React bindings for the ChatKit Web Component.",
55
"type": "module",
66
"sideEffects": false,
@@ -43,5 +43,9 @@
4343
"access": "public",
4444
"provenance": false
4545
},
46+
"repository": {
47+
"type": "git",
48+
"url": "https://github.com/openai/chatkit-js"
49+
},
4650
"license": "MIT"
4751
}

packages/chatkit-react/src/ChatKit.tsx

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export const ChatKit = React.forwardRef<OpenAIChatKit, ChatKitProps>(
2222
const ref = React.useRef<OpenAIChatKit | null>(null);
2323

2424
React.useLayoutEffect(() => {
25-
if (!ref.current) return;
2625
const el = ref.current;
26+
if (!el) return;
2727

2828
// Fast path: element is already defined
2929
if (customElements.get('openai-chatkit')) {
@@ -46,45 +46,40 @@ export const ChatKit = React.forwardRef<OpenAIChatKit, ChatKitProps>(
4646
<openai-chatkit
4747
ref={(chatKit) => {
4848
ref.current = chatKit;
49+
4950
control.setInstance(chatKit);
51+
5052
if (typeof forwardedRef === 'function') {
5153
forwardedRef(chatKit);
5254
} else if (forwardedRef) {
5355
forwardedRef.current = chatKit;
5456
}
5557

56-
if (ref.current) {
57-
const abortController = new AbortController();
58-
const events = {
59-
'chatkit.error': 'onError',
60-
'chatkit.response.end': 'onResponseEnd',
61-
'chatkit.response.start': 'onResponseStart',
62-
'chatkit.log': 'onLog',
63-
'chatkit.thread.change': 'onThreadChange',
64-
'chatkit.thread.load.start': 'onThreadLoadStart',
65-
'chatkit.thread.load.end': 'onThreadLoadEnd',
66-
} satisfies {
67-
[K in keyof ChatKitEvents]: ToEventHandlerKey<K>;
68-
};
58+
if (!ref.current) {
59+
return;
60+
}
61+
62+
const events: {
63+
[K in keyof ChatKitEvents]: ToEventHandlerKey<K>;
64+
} = {
65+
'chatkit.error': 'onError',
66+
'chatkit.response.end': 'onResponseEnd',
67+
'chatkit.response.start': 'onResponseStart',
68+
'chatkit.log': 'onLog',
69+
'chatkit.thread.change': 'onThreadChange',
70+
'chatkit.thread.load.start': 'onThreadLoadStart',
71+
'chatkit.thread.load.end': 'onThreadLoadEnd',
72+
};
6973

70-
for (const eventName of Object.keys(
71-
events,
72-
) as (keyof ChatKitEvents)[]) {
73-
ref.current.addEventListener(
74-
eventName,
75-
(e) => {
76-
const handler = control.handlers[events[eventName]];
77-
if (typeof handler === 'function') {
78-
handler(e.detail as any);
79-
}
80-
},
81-
{ signal: abortController.signal },
82-
);
83-
}
74+
const eventNames = Object.keys(events) as (keyof ChatKitEvents)[];
8475

85-
return () => {
86-
abortController.abort();
87-
};
76+
for (const event of eventNames) {
77+
ref.current.addEventListener(event, (e) => {
78+
const handler = control.handlers[events[event]];
79+
if (typeof handler === 'function') {
80+
handler(e.detail as any);
81+
}
82+
});
8883
}
8984
}}
9085
{...htmlProps}

packages/chatkit-react/src/useChatKit.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export type ChatKitControl = {
5050

5151
export type UseChatKitReturn = ChatKitMethods & {
5252
control: ChatKitControl;
53+
ref: React.RefObject<OpenAIChatKit | null>;
5354
};
5455

5556
export function useChatKit(options: UseChatKitOptions): UseChatKitReturn {
@@ -98,5 +99,8 @@ export function useChatKit(options: UseChatKitOptions): UseChatKitReturn {
9899
};
99100
}, [stableOptions, setInstance]);
100101

101-
return React.useMemo(() => ({ ...methods, control }), [methods, control]);
102+
return React.useMemo(
103+
() => ({ ...methods, control, ref }),
104+
[methods, control],
105+
);
102106
}

packages/chatkit/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# @openai/chatkit
2+
3+
## 1.0.0
4+
5+
### Major Changes
6+
7+
- 5e4488e: Initial release

packages/chatkit/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openai/chatkit",
3-
"version": "0.0.0",
3+
"version": "1.0.0",
44
"type": "module",
55
"description": "Type definitions for the ChatKit Web Component.",
66
"sideEffects": false,
@@ -22,5 +22,9 @@
2222
"access": "public",
2323
"provenance": false
2424
},
25+
"repository": {
26+
"type": "git",
27+
"url": "https://github.com/openai/chatkit-js"
28+
},
2529
"license": "MIT"
2630
}

packages/docs/astro.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ const sidebar = [
6666
},
6767
],
6868
},
69+
{
70+
label: 'Examples',
71+
items: [
72+
{
73+
label: 'Starter App',
74+
link: 'https://github.com/openai/openai-chatkit-starter-app',
75+
},
76+
{
77+
label: 'Advanced Samples',
78+
link: 'https://github.com/openai/openai-chatkit-advanced-samples',
79+
},
80+
],
81+
},
6982
];
7083

7184
export default defineConfig({

packages/docs/src/content/docs/guides/theming-customization.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const { control } = useChatKit({
2020
typography: { fontFamily: "Open Sans, sans-serif" },
2121
},
2222
header: {
23-
customButtonLeft: {
23+
leftAction: {
2424
icon: "settings-cog",
2525
onClick: () => alert("Profile settings"),
2626
},
@@ -63,7 +63,7 @@ el.setOptions({
6363
typography: { fontFamily: "Open Sans, sans-serif" },
6464
},
6565
header: {
66-
customButtonLeft: {
66+
leftAction: {
6767
icon: "settings-cog",
6868
onClick: () => alert("Profile settings"),
6969
},
@@ -184,11 +184,11 @@ Custom header buttons help you add navigation, context, or actions relevant to y
184184
```jsx
185185
const options: Partial<ChatKitOptions> = {
186186
header: {
187-
customButtonLeft: {
187+
leftAction: {
188188
icon: "settings-cog",
189189
onClick: () => openProfileSettings(),
190190
},
191-
customButtonRight: {
191+
rightAction: {
192192
icon: "home",
193193
onClick: () => openHomePage(),
194194
},

0 commit comments

Comments
 (0)