Skip to content

Commit

Permalink
accept OSS as Client Index on external components
Browse files Browse the repository at this point in the history
  • Loading branch information
rjborba committed Oct 7, 2024
1 parent fbcbaad commit 7a3674d
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 213 deletions.
12 changes: 6 additions & 6 deletions packages/ui-stencil/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import { ButtonProps } from "./components/internal/orama-button/orama-button";
import { CloudIndexConfig, ColorScheme, ResultMap, SearchResult, SearchResultBySection, SourcesMap } from "./types/index";
import { TChatInteraction } from "./context/chatContext";
import { OramaClient } from "@oramacloud/client";
import { AnyOrama, Orama, SearchParams } from "@orama/orama";
import { Facet } from "./components/internal/orama-facets/orama-facets";
import { InputProps } from "./components/internal/orama-input/orama-input";
import { ModalStatus } from "./components/internal/orama-modal/orama-modal";
import { TThemeOverrides } from "./config/theme";
import { AnyOrama, Orama, SearchParams } from "@orama/orama";
import { TThemeOverrides as TThemeOverrides1 } from "./components.d";
import { SearchResultsProps } from "./components/internal/orama-search-results/orama-search-results";
import { TextProps } from "./components/internal/orama-text/orama-text";
export { ButtonProps } from "./components/internal/orama-button/orama-button";
export { CloudIndexConfig, ColorScheme, ResultMap, SearchResult, SearchResultBySection, SourcesMap } from "./types/index";
export { TChatInteraction } from "./context/chatContext";
export { OramaClient } from "@oramacloud/client";
export { AnyOrama, Orama, SearchParams } from "@orama/orama";
export { Facet } from "./components/internal/orama-facets/orama-facets";
export { InputProps } from "./components/internal/orama-input/orama-input";
export { ModalStatus } from "./components/internal/orama-modal/orama-modal";
export { TThemeOverrides } from "./config/theme";
export { AnyOrama, Orama, SearchParams } from "@orama/orama";
export { TThemeOverrides as TThemeOverrides1 } from "./components.d";
export { SearchResultsProps } from "./components/internal/orama-search-results/orama-search-results";
export { TextProps } from "./components/internal/orama-text/orama-text";
Expand All @@ -52,7 +52,7 @@ export namespace Components {
"interaction": TChatInteraction;
}
interface OramaChatBox {
"clientInstance"?: OramaClient;
"clientInstance"?: OramaClient | Orama<unknown>;
"index"?: CloudIndexConfig;
"placeholder"?: string;
"sourceBaseUrl"?: string;
Expand Down Expand Up @@ -123,7 +123,7 @@ export namespace Components {
}
interface OramaSearchBox {
"chatPlaceholder"?: string;
"clientInstance"?: OramaClient;
"clientInstance"?: OramaClient | Orama<unknown>;
"colorScheme"?: ColorScheme;
"disableChat"?: boolean;
"facetProperty"?: string;
Expand Down Expand Up @@ -465,7 +465,7 @@ declare namespace LocalJSX {
"interaction"?: TChatInteraction;
}
interface OramaChatBox {
"clientInstance"?: OramaClient;
"clientInstance"?: OramaClient | Orama<unknown>;
"index"?: CloudIndexConfig;
"placeholder"?: string;
"sourceBaseUrl"?: string;
Expand Down Expand Up @@ -538,7 +538,7 @@ declare namespace LocalJSX {
}
interface OramaSearchBox {
"chatPlaceholder"?: string;
"clientInstance"?: OramaClient;
"clientInstance"?: OramaClient | Orama<unknown>;
"colorScheme"?: ColorScheme;
"disableChat"?: boolean;
"facetProperty"?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { generateRandomID, initOramaClient, validateCloudIndexConfig } from '@/u
import type { CloudIndexConfig, SourcesMap } from '@/types'
import type { OramaClient } from '@oramacloud/client'
import '@phosphor-icons/webcomponents/dist/icons/PhArrowClockwise.mjs'
import type { Orama } from '@orama/orama'
import { Switch } from '@orama/switch'

@Component({
tag: 'orama-chat-box',
Expand All @@ -14,13 +16,12 @@ import '@phosphor-icons/webcomponents/dist/icons/PhArrowClockwise.mjs'
export class ChatBox {
@Element() el: HTMLElement
@Prop() index?: CloudIndexConfig
@Prop() clientInstance?: OramaClient
@Prop() clientInstance?: OramaClient | Orama<unknown>
@Prop() sourceBaseUrl?: string
@Prop() placeholder?: string
@Prop() sourcesMap?: SourcesMap
@Prop() suggestions?: string[]

@State() oramaClient: OramaClient
@State() componentID = generateRandomID('chat-box')

@Watch('index')
Expand All @@ -35,9 +36,10 @@ export class ChatBox {

startChatService() {
validateCloudIndexConfig(this.el, this.index, this.clientInstance)
this.oramaClient = this.clientInstance || initOramaClient(this.index)
const oramaClient = this.clientInstance || initOramaClient(this.index)
const switchInstance = new Switch(oramaClient)

chatContext.chatService = new ChatService(this.oramaClient)
chatContext.chatService = new ChatService(switchInstance)
}

render() {
Expand Down
16 changes: 8 additions & 8 deletions packages/ui-stencil/src/components/orama-chat-box/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ---------------- | ----------------- | ----------- | ---------------------------------------------------------- | ----------- |
| `clientInstance` | -- | | `OramaClient` | `undefined` |
| `index` | -- | | `{ api_key: string; endpoint: string; }` | `undefined` |
| `placeholder` | `placeholder` | | `string` | `undefined` |
| `sourceBaseUrl` | `source-base-url` | | `string` | `undefined` |
| `sourcesMap` | -- | | `{ title?: string; path?: string; description?: string; }` | `undefined` |
| `suggestions` | -- | | `string[]` | `undefined` |
| Property | Attribute | Description | Type | Default |
| ---------------- | ----------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `clientInstance` | -- | | `FunctionComponents<unknown> & Internals<unknown, Index, DocumentsStore, Sorter> & ArrayCallbackComponents<any> & OramaID & { plugins: OramaPlugin<unknown>[]; } \| OramaClient` | `undefined` |
| `index` | -- | | `{ api_key: string; endpoint: string; }` | `undefined` |
| `placeholder` | `placeholder` | | `string` | `undefined` |
| `sourceBaseUrl` | `source-base-url` | | `string` | `undefined` |
| `sourcesMap` | -- | | `{ title?: string; path?: string; description?: string; }` | `undefined` |
| `suggestions` | -- | | `string[]` | `undefined` |


## Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { TThemeOverrides } from '@/config/theme'
import { generateRandomID, initOramaClient, validateCloudIndexConfig } from '@/utils/utils'
import type { ColorScheme, ResultMap, SourcesMap } from '@/types'
import type { CloudIndexConfig } from '@/types'
import { Switch } from '@orama/switch'

// TODO: AI components should be lazyly loaded. In case of Disable AI flag, it should not be loaded at all
// https://linear.app/oramasearch/issue/ORM-1824/ai-components-should-be-lazyly-loaded-in-case-of-disable-ai-flag-they
Expand All @@ -26,7 +27,7 @@ export class SearchBox {
@Prop() themeConfig?: Partial<TThemeOverrides>
@Prop() colorScheme?: ColorScheme = 'light'
@Prop() index?: CloudIndexConfig
@Prop() clientInstance?: OramaClient
@Prop() clientInstance?: OramaClient | Orama<unknown>
@Prop({ mutable: true }) open = false
@Prop() facetProperty?: string
@Prop() resultMap?: Partial<ResultMap> = {}
Expand All @@ -42,7 +43,6 @@ export class SearchBox {
@Prop() suggestions?: string[]
@Prop() searchParams?: SearchParams<Orama<AnyOrama | OramaClient>>

@State() oramaClient: OramaClient
@State() componentID = generateRandomID('search-box')
@State() systemScheme: Omit<ColorScheme, 'system'> = 'light'
@State() windowWidth: number
Expand Down Expand Up @@ -141,10 +141,11 @@ export class SearchBox {

startServices() {
validateCloudIndexConfig(this.htmlElement, this.index, this.clientInstance)
this.oramaClient = this.clientInstance ? this.clientInstance : initOramaClient(this.index)
const oramaClient = this.clientInstance ? this.clientInstance : initOramaClient(this.index)
const switchInstance = new Switch(oramaClient)

searchState.searchService = new SearchService(this.oramaClient)
chatContext.chatService = new ChatService(this.oramaClient)
searchState.searchService = new SearchService(switchInstance)
chatContext.chatService = new ChatService(switchInstance)
}

componentWillLoad() {
Expand Down
Loading

0 comments on commit 7a3674d

Please sign in to comment.