@smart-cloud/ai-kit-core 1.4.7 → 1.4.8

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.
@@ -0,0 +1,25 @@
1
+ import type { AiKitLanguageCode, AiModePreference, AnyCreateCoreOptions, BackendTransport, BuiltInAiFeature, CapabilityDecision, DeviceAvailability } from "../types";
2
+ export declare function resolveBackend(): Promise<{
3
+ available: boolean;
4
+ transport?: BackendTransport;
5
+ apiName?: string;
6
+ baseUrl?: string;
7
+ reason?: string;
8
+ }>;
9
+ /**
10
+ * Browser gate for Chrome Built-in AI.
11
+ *
12
+ * Motivation:
13
+ * Some Chromium-derived browsers (Edge/Brave/etc.) may expose partial globals that look
14
+ * present but crash later on availability()/create(). We pre-filter to "real" Chrome/Chromium
15
+ * and enforce per-feature minimum Chrome major versions.
16
+ *
17
+ * Approach:
18
+ * - Prefer UA-CH (navigator.userAgentData) brands/fullVersionList when available.
19
+ * - Fall back to navigator.userAgent parsing.
20
+ * - Explicitly exclude Edge/Opera/Vivaldi/Samsung/Firefox/Safari/Brave.
21
+ */
22
+ export declare const MIN_CHROME_VERSION: Partial<Record<BuiltInAiFeature, number>>;
23
+ export declare function checkOnDeviceAvailability(feature: BuiltInAiFeature, availabilityOptions?: AnyCreateCoreOptions): Promise<DeviceAvailability>;
24
+ export declare function isOnDeviceLanguageSupported(outputLanguage: AiKitLanguageCode): boolean;
25
+ export declare function decideCapability(feature: BuiltInAiFeature, availabilityOptions?: AnyCreateCoreOptions, modeOverride?: AiModePreference): Promise<CapabilityDecision>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Text chunking utilities for handling large inputs in AI features
3
+ *
4
+ * Chunking is needed for:
5
+ * - On-device models with token quotas (~8000 tokens)
6
+ * - AWS Translate backend (10,000 character limit)
7
+ */
8
+ export interface TextChunk {
9
+ text: string;
10
+ start: number;
11
+ end: number;
12
+ }
13
+ /**
14
+ * Split text into chunks at intelligent boundaries
15
+ *
16
+ * Priority order for splitting:
17
+ * 1. Paragraph breaks (\n\n)
18
+ * 2. Sentence endings (. ! ?)
19
+ * 3. Clause markers (, ; :)
20
+ * 4. Word boundaries (space)
21
+ */
22
+ export declare function splitTextIntoChunks(text: string, maxCharsPerChunk: number): TextChunk[];
@@ -0,0 +1,17 @@
1
+ import type { Features, PromptArgs, RewriteArgs, SummarizeArgs, TranslateArgs, WriteArgs } from "../types";
2
+ export declare const getWriteOptions: (args: Partial<WriteArgs>) => Promise<WriterCreateCoreOptions>;
3
+ export declare const write: Features["write"];
4
+ export declare const getRewriteOptions: (args: Partial<RewriteArgs>) => Promise<RewriterCreateCoreOptions>;
5
+ export declare const rewrite: Features["rewrite"];
6
+ export declare const getProofreadOptions: () => Promise<ProofreaderCreateCoreOptions>;
7
+ export declare const proofread: Features["proofread"];
8
+ export declare const getSummarizeOptions: (args: Partial<SummarizeArgs>) => Promise<SummarizerCreateCoreOptions>;
9
+ export declare const summarize: Features["summarize"];
10
+ export declare const detectLanguage: Features["detectLanguage"];
11
+ export declare const getTranslateOptions: (args: Partial<TranslateArgs>) => Promise<TranslatorCreateCoreOptions>;
12
+ export declare const translate: Features["translate"];
13
+ export declare const getPromptOptions: (args: Partial<PromptArgs>) => Promise<LanguageModelCreateCoreOptions>;
14
+ export declare const prompt: Features["prompt"];
15
+ export declare const sendChatMessage: Features["sendChatMessage"];
16
+ export declare const sendSearchMessage: Features["sendSearchMessage"];
17
+ export declare const sendFeedbackMessage: Features["sendFeedbackMessage"];
@@ -0,0 +1,3 @@
1
+ import { BackendCallOptions, BuiltInAiFeature, CapabilityDecision, ContextKind } from "../types";
2
+ export declare function dispatchFeatureBackend<TResponse>(_decision: CapabilityDecision, _context: ContextKind, _feature: BuiltInAiFeature, _requestBody: unknown, _options: BackendCallOptions): Promise<TResponse>;
3
+ export declare function dispatchCustomBackend<TResponse>(_decision: CapabilityDecision, _context: ContextKind, _customPath: string, _method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", _requestBody: unknown, _options: BackendCallOptions): Promise<TResponse>;
@@ -0,0 +1,14 @@
1
+ import { AiKitLanguageCode, AiModePreference, AnyCreateCoreOptions, BackendTransport, BuiltInAiFeature, CapabilityDecision } from "../types";
2
+ export declare const isOnDeviceLanguageSupported: (_outputLanguage: AiKitLanguageCode) => boolean;
3
+ export declare const checkOnDeviceAvailability: (_feature: BuiltInAiFeature, _availabilityOptions?: never) => Promise<{
4
+ available: boolean;
5
+ status: string;
6
+ }>;
7
+ export declare const decideCapability: (_feature: BuiltInAiFeature, _availabilityOptions?: AnyCreateCoreOptions, _modeOverride?: AiModePreference) => Promise<CapabilityDecision>;
8
+ export declare function resolveBackend(): Promise<{
9
+ available: boolean;
10
+ transport?: BackendTransport;
11
+ apiName?: string;
12
+ baseUrl?: string;
13
+ reason?: string;
14
+ }>;
@@ -0,0 +1,17 @@
1
+ import type { PromptArgs, RewriteArgs, SummarizeArgs, TranslateArgs, WriteArgs, Features } from "../types";
2
+ export declare const getWriteOptions: (args: Partial<WriteArgs>) => Promise<WriterCreateCoreOptions>;
3
+ export declare const write: Features["write"];
4
+ export declare const getRewriteOptions: (args: Partial<RewriteArgs>) => Promise<RewriterCreateCoreOptions>;
5
+ export declare const rewrite: Features["rewrite"];
6
+ export declare const getProofreadOptions: () => Promise<ProofreaderCreateCoreOptions>;
7
+ export declare const proofread: Features["proofread"];
8
+ export declare const getSummarizeOptions: (args: Partial<SummarizeArgs>) => Promise<SummarizerCreateCoreOptions>;
9
+ export declare const summarize: Features["summarize"];
10
+ export declare const getTranslateOptions: (args: Partial<TranslateArgs>) => Promise<TranslatorCreateCoreOptions>;
11
+ export declare const translate: Features["translate"];
12
+ export declare const detectLanguage: Features["detectLanguage"];
13
+ export declare const getPromptOptions: (args: Partial<PromptArgs>) => Promise<LanguageModelCreateCoreOptions>;
14
+ export declare const prompt: Features["prompt"];
15
+ export declare const sendChatMessage: Features["sendChatMessage"];
16
+ export declare const sendFeedbackMessage: Features["sendFeedbackMessage"];
17
+ export declare const sendSearchMessage: Features["sendSearchMessage"];
@@ -0,0 +1,8 @@
1
+ import { WpSuitePluginBase } from "@smart-cloud/wpsuite-core";
2
+ import { AiKit } from "./index";
3
+ export type AiKitReadyEvent = "wpsuite:ai-kit:ready";
4
+ export type AiKitErrorEvent = "wpsuite:ai-kit:error";
5
+ export type AiKitPlugin = WpSuitePluginBase & AiKit;
6
+ export declare function getAiKitPlugin(): AiKitPlugin;
7
+ export declare function waitForAiKitReady(timeoutMs?: number): Promise<void>;
8
+ export declare function getStore(timeoutMs?: number): Promise<import("./store").Store>;
@@ -0,0 +1,65 @@
1
+ import { type SubscriptionType } from "@smart-cloud/wpsuite-core";
2
+ import { type StoreDescriptor } from "@wordpress/data";
3
+ import { AiChatbotProps, type AiModePreference, type BackendTransport } from "./types";
4
+ export interface AiKitConfig {
5
+ mode?: AiModePreference;
6
+ backendTransport?: BackendTransport;
7
+ backendApiName?: string;
8
+ backendBaseUrl?: string;
9
+ subscriptionType?: SubscriptionType;
10
+ enableChatbot?: boolean;
11
+ chatbot?: AiChatbotProps;
12
+ }
13
+ /**
14
+ * Ensures we only keep runtime keys that are part of AiKitConfig.
15
+ *
16
+ * Defensive: upstream getConfig("ai-kit") or persisted site.settings may include
17
+ * additional keys, but the admin UI and core should only operate on AiKitConfig.
18
+ */
19
+ export declare const sanitizeAiKitConfig: (input: unknown) => AiKitConfig;
20
+ declare const actions: {
21
+ setShowChatbotPreview(showChatbotPreview: boolean): {
22
+ type: string;
23
+ showChatbotPreview: boolean;
24
+ };
25
+ setLanguage(language: string | undefined | null): {
26
+ type: string;
27
+ language: string | null | undefined;
28
+ };
29
+ setDirection(direction: "ltr" | "rtl" | "auto" | undefined | null): {
30
+ type: string;
31
+ direction: "ltr" | "rtl" | "auto" | null | undefined;
32
+ };
33
+ setConfig: (config: AiKitConfig) => {
34
+ type: "SET_CONFIG";
35
+ config: AiKitConfig;
36
+ };
37
+ };
38
+ export interface CustomTranslations {
39
+ [key: string]: Record<string, string>;
40
+ }
41
+ export interface State {
42
+ config: AiKitConfig | null;
43
+ showChatbotPreview: boolean;
44
+ language: string | undefined | null;
45
+ direction: "ltr" | "rtl" | "auto" | undefined | null;
46
+ customTranslations: CustomTranslations | null;
47
+ }
48
+ export type Store = StoreDescriptor;
49
+ export type StoreSelectors = {
50
+ getConfig(): AiKitConfig | null;
51
+ isShowChatbotPreview(): boolean;
52
+ getCustomTranslations(): CustomTranslations | null;
53
+ getLanguage(): string | undefined | null;
54
+ getDirection(): "ltr" | "rtl" | "auto" | undefined | null;
55
+ getState(): State;
56
+ };
57
+ export type StoreActions = Omit<typeof actions, "setConfig"> & {
58
+ setConfig?: typeof actions.setConfig;
59
+ };
60
+ export declare const getStoreDispatch: (store: Store) => Omit<StoreActions, "setConfig">;
61
+ export declare const getStoreSelect: (store: Store) => StoreSelectors;
62
+ export declare const reloadConfig: (store: Store) => Promise<void>;
63
+ export declare const createStore: () => Promise<Store>;
64
+ export declare const observeStore: (observableStore: Store, selector: (state: State) => boolean | number | string | null | undefined, onChange: (nextValue: boolean | number | string | null | undefined, previousValue: boolean | number | string | null | undefined) => void) => () => void;
65
+ export {};
@@ -1,80 +1,17 @@
1
- import { SubscriptionType, WpSuitePluginBase } from '@smart-cloud/wpsuite-core';
2
- import { StoreDescriptor } from '@wordpress/data';
3
-
4
- interface AiKitConfig {
5
- mode?: AiModePreference;
6
- backendTransport?: BackendTransport;
7
- backendApiName?: string;
8
- backendBaseUrl?: string;
9
- subscriptionType?: SubscriptionType;
10
- enableChatbot?: boolean;
11
- chatbot?: AiChatbotProps;
12
- }
13
- /**
14
- * Ensures we only keep runtime keys that are part of AiKitConfig.
15
- *
16
- * Defensive: upstream getConfig("ai-kit") or persisted site.settings may include
17
- * additional keys, but the admin UI and core should only operate on AiKitConfig.
18
- */
19
- declare const sanitizeAiKitConfig: (input: unknown) => AiKitConfig;
20
- declare const actions: {
21
- setShowChatbotPreview(showChatbotPreview: boolean): {
22
- type: string;
23
- showChatbotPreview: boolean;
24
- };
25
- setLanguage(language: string | undefined | null): {
26
- type: string;
27
- language: string | null | undefined;
28
- };
29
- setDirection(direction: "ltr" | "rtl" | "auto" | undefined | null): {
30
- type: string;
31
- direction: "ltr" | "rtl" | "auto" | null | undefined;
32
- };
33
- setConfig: (config: AiKitConfig) => {
34
- type: "SET_CONFIG";
35
- config: AiKitConfig;
36
- };
37
- };
38
- interface CustomTranslations {
39
- [key: string]: Record<string, string>;
40
- }
41
- interface State {
42
- config: AiKitConfig | null;
43
- showChatbotPreview: boolean;
44
- language: string | undefined | null;
45
- direction: "ltr" | "rtl" | "auto" | undefined | null;
46
- customTranslations: CustomTranslations | null;
47
- }
48
- type Store = StoreDescriptor;
49
- type StoreSelectors = {
50
- getConfig(): AiKitConfig | null;
51
- isShowChatbotPreview(): boolean;
52
- getCustomTranslations(): CustomTranslations | null;
53
- getLanguage(): string | undefined | null;
54
- getDirection(): "ltr" | "rtl" | "auto" | undefined | null;
55
- getState(): State;
56
- };
57
- type StoreActions = Omit<typeof actions, "setConfig"> & {
58
- setConfig?: typeof actions.setConfig;
59
- };
60
- declare const getStoreDispatch: (store: Store) => Omit<StoreActions, "setConfig">;
61
- declare const getStoreSelect: (store: Store) => StoreSelectors;
62
- declare const reloadConfig: (store: Store) => Promise<void>;
63
- declare const observeStore: (observableStore: Store, selector: (state: State) => boolean | number | string | null | undefined, onChange: (nextValue: boolean | number | string | null | undefined, previousValue: boolean | number | string | null | undefined) => void) => () => void;
64
-
65
- type ContextKind = "admin" | "frontend";
66
- type AiModePreference = "local-only" | "backend-fallback" | "backend-only";
67
- type BuiltInAiFeature = "prompt" | "summarizer" | "writer" | "rewriter" | "proofreader" | "language-detector" | "translator";
68
- type CapabilitySource = "on-device" | "backend" | "none";
69
- type BackendTransport = "gatey" | "fetch";
70
- interface AiKit {
1
+ import { Store } from "./store";
2
+ export type ContextKind = "admin" | "frontend";
3
+ export type AiModePreference = "local-only" | "backend-fallback" | "backend-only";
4
+ export type BuiltInAiFeature = "prompt" | "summarizer" | "writer" | "rewriter" | "proofreader" | "language-detector" | "translator";
5
+ export type CapabilitySource = "on-device" | "backend" | "none";
6
+ export type BackendTransport = "gatey" | "fetch";
7
+ export interface AiKit {
71
8
  features: AiKitFeatures;
72
9
  settings: AiKitSettings;
73
10
  nonce: string;
74
11
  restUrl: string;
75
12
  view: "settings" | "diagnostics";
76
13
  }
77
- interface AiKitFeatures {
14
+ export interface AiKitFeatures {
78
15
  readonly store: Promise<Store>;
79
16
  readonly write: Features["write"];
80
17
  readonly rewrite: Features["rewrite"];
@@ -89,7 +26,7 @@ interface AiKitFeatures {
89
26
  readonly renderFeature: (args: AiFeatureArgs) => Promise<AiWorkerHandle>;
90
27
  readonly renderSearchComponent: (args: DocSearchArgs) => Promise<AiWorkerHandle>;
91
28
  }
92
- interface AiKitSettings {
29
+ export interface AiKitSettings {
93
30
  /**
94
31
  * Context injected into supported Chrome APIs (Writer/Rewriter/Summarizer) and/or backend.
95
32
  */
@@ -108,13 +45,13 @@ interface AiKitSettings {
108
45
  /** Whether to enable server-side debug logging for AI-Kit. */
109
46
  debugLoggingEnabled?: boolean;
110
47
  }
111
- interface DeviceAvailability {
48
+ export interface DeviceAvailability {
112
49
  available: boolean;
113
50
  status?: Availability | "api-not-present" | "unknown-feature" | "error";
114
51
  reason?: string;
115
52
  error?: Error;
116
53
  }
117
- interface CapabilityDecision {
54
+ export interface CapabilityDecision {
118
55
  feature: BuiltInAiFeature;
119
56
  source: CapabilitySource;
120
57
  mode: AiModePreference;
@@ -128,7 +65,7 @@ interface CapabilityDecision {
128
65
  backendReason?: string;
129
66
  reason: string;
130
67
  }
131
- interface BackendCallOptions {
68
+ export interface BackendCallOptions {
132
69
  signal?: AbortSignal;
133
70
  headers?: Record<string, string>;
134
71
  query?: Record<string, string | number | boolean>;
@@ -137,12 +74,12 @@ interface BackendCallOptions {
137
74
  */
138
75
  onStatus?: (event: AiKitStatusEvent) => void;
139
76
  }
140
- type AiKitLanguageCode = "ar" | "en" | "zh" | "nl" | "fr" | "de" | "he" | "hi" | "hu" | "id" | "it" | "ja" | "ko" | "no" | "pl" | "pt" | "ru" | "es" | "sv" | "th" | "tr" | "uk";
141
- type AiKitLanguageRef = "site" | "admin" | "content" | AiKitLanguageCode;
142
- type AiKitLanguageProfile = "singleSite" | "englishAdminSingleFrontend" | "multilingual" | "custom";
143
- type OnDeviceUnsupportedLanguageStrategy = "prefer-backend" | "pivot-translate";
144
- type AiKitStatusStep = "decide" | "on-device:init" | "on-device:download" | "on-device:ready" | "on-device:run" | "backend:request" | "backend:waiting" | "backend:response" | "done" | "error";
145
- interface AiKitStatusEvent {
77
+ export type AiKitLanguageCode = "ar" | "en" | "zh" | "nl" | "fr" | "de" | "he" | "hi" | "hu" | "id" | "it" | "ja" | "ko" | "no" | "pl" | "pt" | "ru" | "es" | "sv" | "th" | "tr" | "uk";
78
+ export type AiKitLanguageRef = "site" | "admin" | "content" | AiKitLanguageCode;
79
+ export type AiKitLanguageProfile = "singleSite" | "englishAdminSingleFrontend" | "multilingual" | "custom";
80
+ export type OnDeviceUnsupportedLanguageStrategy = "prefer-backend" | "pivot-translate";
81
+ export type AiKitStatusStep = "decide" | "on-device:init" | "on-device:download" | "on-device:ready" | "on-device:run" | "backend:request" | "backend:waiting" | "backend:response" | "done" | "error";
82
+ export interface AiKitStatusEvent {
146
83
  feature: BuiltInAiFeature;
147
84
  context: ContextKind;
148
85
  step: AiKitStatusStep;
@@ -155,21 +92,21 @@ interface AiKitStatusEvent {
155
92
  message?: string;
156
93
  silent?: boolean;
157
94
  }
158
- declare class BackendError extends Error {
95
+ export declare class BackendError extends Error {
159
96
  readonly decision?: CapabilityDecision | undefined;
160
97
  readonly status?: number | undefined;
161
98
  constructor(message: string, decision?: CapabilityDecision | undefined, status?: number | undefined);
162
99
  }
163
- type AiWorkerHandle = {
100
+ export type AiWorkerHandle = {
164
101
  container: HTMLDivElement;
165
102
  close: () => void;
166
103
  unmount: () => void;
167
104
  };
168
- type AiFeatureArgs = AiFeatureProps & {
105
+ export type AiFeatureArgs = AiFeatureProps & {
169
106
  target?: string | HTMLElement;
170
107
  };
171
- type AiFeatureMode = "proofread" | "translate" | "write" | "rewrite" | "summarize" | "generatePostMetadata" | "generateImageMetadata";
172
- type AiWorkerProps = {
108
+ export type AiFeatureMode = "proofread" | "translate" | "write" | "rewrite" | "summarize" | "generatePostMetadata" | "generateImageMetadata";
109
+ export type AiWorkerProps = {
173
110
  store: Store;
174
111
  variation?: "default" | "modal";
175
112
  language?: string;
@@ -190,10 +127,10 @@ type AiWorkerProps = {
190
127
  title?: string;
191
128
  onClose: () => void;
192
129
  };
193
- type HistoryStorageMode = "localstorage" | "sessionstorage" | "nostorage";
194
- type OpenButtonIconLayout = "top" | "bottom" | "left" | "right";
195
- type OpenButtonPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
196
- type AiChatbotLabels = Partial<{
130
+ export type HistoryStorageMode = "localstorage" | "sessionstorage" | "nostorage";
131
+ export type OpenButtonIconLayout = "top" | "bottom" | "left" | "right";
132
+ export type OpenButtonPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
133
+ export type AiChatbotLabels = Partial<{
197
134
  modalTitle: string;
198
135
  userLabel: string;
199
136
  assistantLabel: string;
@@ -222,7 +159,7 @@ type AiChatbotLabels = Partial<{
222
159
  emptyResponseLabel: string;
223
160
  unexpectedErrorLabel: string;
224
161
  }>;
225
- type AiChatbotProps = AiWorkerProps & {
162
+ export type AiChatbotProps = AiWorkerProps & {
226
163
  context?: ContextKind;
227
164
  placeholder?: string;
228
165
  maxImages?: number;
@@ -255,7 +192,7 @@ type AiChatbotProps = AiWorkerProps & {
255
192
  */
256
193
  openButtonPosition?: OpenButtonPosition;
257
194
  };
258
- type AiFeatureOptions = {
195
+ export type AiFeatureOptions = {
259
196
  text?: string;
260
197
  instructions?: string;
261
198
  inputLanguage?: AiKitLanguageCode | "auto";
@@ -265,7 +202,7 @@ type AiFeatureOptions = {
265
202
  type?: SummarizerType;
266
203
  outputFormat?: "plain-text" | "markdown" | "html";
267
204
  };
268
- type AiFeatureProps = AiWorkerProps & {
205
+ export type AiFeatureProps = AiWorkerProps & {
269
206
  mode: AiFeatureMode;
270
207
  context?: ContextKind;
271
208
  modeOverride?: AiModePreference;
@@ -291,7 +228,7 @@ type AiFeatureProps = AiWorkerProps & {
291
228
  onAccept?: (result: unknown) => void;
292
229
  onOptionsChanged?: (options: AiFeatureOptions) => void;
293
230
  };
294
- interface SummarizeArgs {
231
+ export interface SummarizeArgs {
295
232
  text: string;
296
233
  context?: string;
297
234
  sharedContext?: string;
@@ -300,10 +237,10 @@ interface SummarizeArgs {
300
237
  length?: SummarizerLength;
301
238
  outputLanguage?: AiKitLanguageCode;
302
239
  }
303
- interface SummarizeResult {
240
+ export interface SummarizeResult {
304
241
  result: string;
305
242
  }
306
- interface WriteArgs {
243
+ export interface WriteArgs {
307
244
  prompt: string;
308
245
  context?: string;
309
246
  sharedContext?: string;
@@ -312,10 +249,10 @@ interface WriteArgs {
312
249
  length?: WriterLength;
313
250
  outputLanguage?: AiKitLanguageCode;
314
251
  }
315
- interface WriteResult {
252
+ export interface WriteResult {
316
253
  result: string;
317
254
  }
318
- interface RewriteArgs {
255
+ export interface RewriteArgs {
319
256
  text: string;
320
257
  context?: string;
321
258
  sharedContext?: string;
@@ -324,10 +261,10 @@ interface RewriteArgs {
324
261
  length?: RewriterLength;
325
262
  outputLanguage?: AiKitLanguageCode;
326
263
  }
327
- interface RewriteResult {
264
+ export interface RewriteResult {
328
265
  result: string;
329
266
  }
330
- interface ProofreadArgs {
267
+ export interface ProofreadArgs {
331
268
  text: string;
332
269
  expectedInputLanguages?: AiKitLanguageCode[];
333
270
  includeCorrectionTypes?: boolean;
@@ -338,26 +275,26 @@ interface ProofreadArgs {
338
275
  * ProofreadResult is provided by dom-chromium-ai:
339
276
  * interface ProofreadResult { correctedInput: string; corrections: ProofreadCorrection[] }
340
277
  */
341
- interface ProofreadOutput {
278
+ export interface ProofreadOutput {
342
279
  result: ProofreadResult;
343
280
  }
344
- interface DetectLanguageArgs {
281
+ export interface DetectLanguageArgs {
345
282
  text: string;
346
283
  }
347
- interface DetectLanguageOutput {
284
+ export interface DetectLanguageOutput {
348
285
  result: {
349
286
  candidates: LanguageDetectionResult[];
350
287
  };
351
288
  }
352
- interface TranslateArgs {
289
+ export interface TranslateArgs {
353
290
  text: string;
354
291
  sourceLanguage: AiKitLanguageCode;
355
292
  targetLanguage: AiKitLanguageCode;
356
293
  }
357
- interface TranslateResult {
294
+ export interface TranslateResult {
358
295
  result: string;
359
296
  }
360
- type PromptMessages = Array<{
297
+ export type PromptMessages = Array<{
361
298
  role: "system" | "user" | "assistant";
362
299
  content: string;
363
300
  }>;
@@ -365,16 +302,16 @@ type PromptMessages = Array<{
365
302
  * Visual inputs supported by Chrome Prompt API multimodal prompting.
366
303
  * Note: For backend uploads we only handle Blob/File inputs.
367
304
  */
368
- type PromptImageInput = Blob | File | HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap | VideoFrame | ImageData;
305
+ export type PromptImageInput = Blob | File | HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap | VideoFrame | ImageData;
369
306
  /**
370
307
  * Audio input for multimodal prompting.
371
308
  * Backend supports base64-encoded audio with format specification.
372
309
  */
373
- type PromptAudioInput = {
310
+ export type PromptAudioInput = {
374
311
  format: string;
375
312
  data: string;
376
313
  };
377
- interface PromptArgs {
314
+ export interface PromptArgs {
378
315
  messages: PromptMessages;
379
316
  sharedContext?: string;
380
317
  outputLanguage?: AiKitLanguageCode;
@@ -405,26 +342,26 @@ interface PromptArgs {
405
342
  topK?: number;
406
343
  temperature?: number;
407
344
  }
408
- interface PromptResult {
345
+ export interface PromptResult {
409
346
  result: string;
410
347
  sessionId?: string;
411
348
  metadata?: {
412
349
  messageId: string;
413
350
  };
414
351
  }
415
- interface RetrievedDoc {
352
+ export interface RetrievedDoc {
416
353
  docId: string;
417
354
  title?: string;
418
355
  description?: string;
419
356
  author?: string;
420
357
  sourceUrl?: string;
421
358
  }
422
- interface RetrievedChunk {
359
+ export interface RetrievedChunk {
423
360
  docId: string;
424
361
  chunkId: string;
425
362
  snippet?: string;
426
363
  }
427
- interface ProcessedCitations {
364
+ export interface ProcessedCitations {
428
365
  docs: Array<RetrievedDoc>;
429
366
  chunks: Array<RetrievedChunk>;
430
367
  anchors?: Array<{
@@ -435,7 +372,7 @@ interface ProcessedCitations {
435
372
  chunkIds: Array<string>;
436
373
  }>;
437
374
  }
438
- interface SearchResult {
375
+ export interface SearchResult {
439
376
  result: string;
440
377
  sessionId?: string;
441
378
  citations?: ProcessedCitations;
@@ -450,7 +387,7 @@ interface SearchResult {
450
387
  fallbackReason?: string;
451
388
  };
452
389
  }
453
- interface SearchMessageArgs {
390
+ export interface SearchMessageArgs {
454
391
  /** Search query in the user's language (required if no audio). */
455
392
  query?: string;
456
393
  /** Optional audio query (alternative to text query). Blob will be uploaded to S3. */
@@ -472,7 +409,7 @@ interface SearchMessageArgs {
472
409
  /** User-selected tag filters */
473
410
  userSelectedTags?: string[];
474
411
  }
475
- interface ChatMessageArgs {
412
+ export interface ChatMessageArgs {
476
413
  sessionId?: string;
477
414
  message?: string;
478
415
  audio?: Blob;
@@ -484,12 +421,12 @@ interface ChatMessageArgs {
484
421
  topK?: number;
485
422
  temperature?: number;
486
423
  }
487
- interface FeedbackMessageArgs {
424
+ export interface FeedbackMessageArgs {
488
425
  feedbackType: "accepted" | "rejected";
489
426
  feedbackMessageId: string;
490
427
  sessionId: string;
491
428
  }
492
- type DocSearchProps = AiWorkerProps & {
429
+ export type DocSearchProps = AiWorkerProps & {
493
430
  context?: ContextKind;
494
431
  autoRun?: boolean;
495
432
  /** Title shown above the search input (optional). */
@@ -515,11 +452,11 @@ type DocSearchProps = AiWorkerProps & {
515
452
  /** Available tags for user selection */
516
453
  availableTags?: string[];
517
454
  };
518
- type DocSearchArgs = DocSearchProps & {
455
+ export type DocSearchArgs = DocSearchProps & {
519
456
  target?: string | HTMLElement;
520
457
  };
521
- type AnyCreateCoreOptions = LanguageModelCreateCoreOptions | SummarizerCreateCoreOptions | WriterCreateCoreOptions | RewriterCreateCoreOptions | ProofreaderCreateCoreOptions | LanguageDetectorCreateCoreOptions | TranslatorCreateCoreOptions;
522
- interface Capabilities {
458
+ export type AnyCreateCoreOptions = LanguageModelCreateCoreOptions | SummarizerCreateCoreOptions | WriterCreateCoreOptions | RewriterCreateCoreOptions | ProofreaderCreateCoreOptions | LanguageDetectorCreateCoreOptions | TranslatorCreateCoreOptions;
459
+ export interface Capabilities {
523
460
  MIN_CHROME_VERSION?: Partial<Record<BuiltInAiFeature, number>>;
524
461
  isOnDeviceLanguageSupported: (outputLanguage: AiKitLanguageCode) => boolean;
525
462
  checkOnDeviceAvailability: (feature: BuiltInAiFeature, availabilityOptions?: AnyCreateCoreOptions) => Promise<DeviceAvailability>;
@@ -534,17 +471,17 @@ interface Capabilities {
534
471
  willUseOnDevice: (feature: BuiltInAiFeature, availabilityOptions?: AnyCreateCoreOptions) => Promise<boolean>;
535
472
  willUseBackend: (feature: BuiltInAiFeature, availabilityOptions?: AnyCreateCoreOptions) => Promise<boolean>;
536
473
  }
537
- interface Backend<TResponse> {
474
+ export interface Backend<TResponse> {
538
475
  dispatchFeatureBackend: (decision: CapabilityDecision, context: ContextKind, feature: BuiltInAiFeature, requestBody: unknown, options: BackendCallOptions) => Promise<TResponse>;
539
476
  dispatchCustomBackend: (decision: CapabilityDecision, context: ContextKind, customPath: string, method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", requestBody: unknown, options: BackendCallOptions) => Promise<TResponse>;
540
477
  }
541
- type FeatureOptions = BackendCallOptions & {
478
+ export type FeatureOptions = BackendCallOptions & {
542
479
  context?: ContextKind;
543
480
  modeOverride?: AiModePreference;
544
481
  onDeviceTimeoutOverride?: number;
545
482
  silent?: boolean;
546
483
  };
547
- interface Features {
484
+ export interface Features {
548
485
  getWriteOptions: (args: Partial<WriteArgs>) => Promise<WriterCreateCoreOptions>;
549
486
  write: (args: WriteArgs, options?: FeatureOptions) => Promise<WriteResult>;
550
487
  getRewriteOptions: (args: Partial<RewriteArgs>) => Promise<RewriterCreateCoreOptions>;
@@ -562,52 +499,3 @@ interface Features {
562
499
  sendFeedbackMessage: (args: FeedbackMessageArgs, options?: FeatureOptions) => Promise<PromptResult>;
563
500
  sendSearchMessage: (args: SearchMessageArgs, options?: FeatureOptions) => Promise<SearchResult>;
564
501
  }
565
-
566
- type AiKitReadyEvent = "wpsuite:ai-kit:ready";
567
- type AiKitErrorEvent = "wpsuite:ai-kit:error";
568
- type AiKitPlugin = WpSuitePluginBase & AiKit;
569
- declare function getAiKitPlugin(): AiKitPlugin;
570
- declare function waitForAiKitReady(timeoutMs?: number): Promise<void>;
571
- declare function getStore(timeoutMs?: number): Promise<Store>;
572
-
573
- declare const TEXT_DOMAIN = "smartcloud-ai-kit";
574
-
575
- declare const AiKitFeatureIcon: React.FC<React.SVGProps<SVGSVGElement>>;
576
- declare const AiKitChatbotIcon: React.FC<React.SVGProps<SVGSVGElement>>;
577
- declare const AiKitDocSearchIcon: React.FC<React.SVGProps<SVGSVGElement>>;
578
-
579
- declare const LANGUAGE_OPTIONS: {
580
- label: string;
581
- value: AiKitLanguageCode;
582
- }[];
583
- declare const getMinChromeVersions: () => Promise<Partial<Record<BuiltInAiFeature, number>> | undefined>;
584
- declare const isOnDeviceLanguageSupported: (...args: Parameters<Capabilities["isOnDeviceLanguageSupported"]>) => Promise<boolean>;
585
- declare const decideCapability: (...args: Parameters<Capabilities["decideCapability"]>) => Promise<CapabilityDecision>;
586
- declare const checkOnDeviceAvailability: (...args: Parameters<Capabilities["checkOnDeviceAvailability"]>) => Promise<DeviceAvailability>;
587
- declare const resolveBackend: (...args: Parameters<Capabilities["resolveBackend"]>) => Promise<{
588
- available: boolean;
589
- transport?: BackendTransport;
590
- apiName?: string;
591
- baseUrl?: string;
592
- reason?: string;
593
- }>;
594
- declare const dispatchBackend: (...args: Parameters<Backend<unknown>["dispatchCustomBackend"]>) => Promise<unknown>;
595
- declare const getWriteOptions: (...args: Parameters<Features["getWriteOptions"]>) => Promise<WriterCreateCoreOptions>;
596
- declare const write: (...args: Parameters<Features["write"]>) => Promise<WriteResult>;
597
- declare const getRewriteOptions: (...args: Parameters<Features["getRewriteOptions"]>) => Promise<RewriterCreateCoreOptions>;
598
- declare const rewrite: (...args: Parameters<Features["rewrite"]>) => Promise<RewriteResult>;
599
- declare const getProofreadOptions: (...args: Parameters<Features["getProofreadOptions"]>) => Promise<ProofreaderCreateCoreOptions>;
600
- declare const proofread: (...args: Parameters<Features["proofread"]>) => Promise<ProofreadOutput>;
601
- declare const getSummarizeOptions: (...args: Parameters<Features["getSummarizeOptions"]>) => Promise<SummarizerCreateCoreOptions>;
602
- declare const summarize: (...args: Parameters<Features["summarize"]>) => Promise<SummarizeResult>;
603
- declare const getTranslateOptions: (...args: Parameters<Features["getTranslateOptions"]>) => Promise<TranslatorCreateCoreOptions>;
604
- declare const translate: (...args: Parameters<Features["translate"]>) => Promise<TranslateResult>;
605
- declare const detectLanguage: (...args: Parameters<Features["detectLanguage"]>) => Promise<DetectLanguageOutput>;
606
- declare const getPromptOptions: (...args: Parameters<Features["getPromptOptions"]>) => Promise<LanguageModelCreateCoreOptions>;
607
- declare const prompt: (...args: Parameters<Features["prompt"]>) => Promise<PromptResult>;
608
- declare const sendChatMessage: (...args: Parameters<Features["sendChatMessage"]>) => Promise<PromptResult>;
609
- declare const sendFeedbackMessage: (...args: Parameters<Features["sendFeedbackMessage"]>) => Promise<PromptResult>;
610
- declare const sendSearchMessage: (...args: Parameters<Features["sendSearchMessage"]>) => Promise<SearchResult>;
611
- declare const initializeAiKit: (renderFeature: (args: AiFeatureArgs) => Promise<AiWorkerHandle>, renderSearchComponent?: (args: DocSearchArgs) => Promise<AiWorkerHandle>) => AiKitPlugin;
612
-
613
- export { type AiChatbotLabels, type AiChatbotProps, type AiFeatureArgs, type AiFeatureMode, type AiFeatureOptions, type AiFeatureProps, type AiKit, AiKitChatbotIcon, type AiKitConfig, AiKitDocSearchIcon, type AiKitErrorEvent, AiKitFeatureIcon, type AiKitFeatures, type AiKitLanguageCode, type AiKitLanguageProfile, type AiKitLanguageRef, type AiKitPlugin, type AiKitReadyEvent, type AiKitSettings, type AiKitStatusEvent, type AiKitStatusStep, type AiModePreference, type AiWorkerHandle, type AiWorkerProps, type AnyCreateCoreOptions, type Backend, type BackendCallOptions, BackendError, type BackendTransport, type BuiltInAiFeature, type Capabilities, type CapabilityDecision, type CapabilitySource, type ChatMessageArgs, type ContextKind, type CustomTranslations, type DetectLanguageArgs, type DetectLanguageOutput, type DeviceAvailability, type DocSearchArgs, type DocSearchProps, type FeatureOptions, type Features, type FeedbackMessageArgs, type HistoryStorageMode, LANGUAGE_OPTIONS, type OnDeviceUnsupportedLanguageStrategy, type OpenButtonIconLayout, type OpenButtonPosition, type ProcessedCitations, type PromptArgs, type PromptAudioInput, type PromptImageInput, type PromptMessages, type PromptResult, type ProofreadArgs, type ProofreadOutput, type RetrievedChunk, type RetrievedDoc, type RewriteArgs, type RewriteResult, type SearchMessageArgs, type SearchResult, type State, type Store, type SummarizeArgs, type SummarizeResult, TEXT_DOMAIN, type TranslateArgs, type TranslateResult, type WriteArgs, type WriteResult, checkOnDeviceAvailability, decideCapability, detectLanguage, dispatchBackend, getAiKitPlugin, getMinChromeVersions, getPromptOptions, getProofreadOptions, getRewriteOptions, getStore, getStoreDispatch, getStoreSelect, getSummarizeOptions, getTranslateOptions, getWriteOptions, initializeAiKit, isOnDeviceLanguageSupported, observeStore, prompt, proofread, reloadConfig, resolveBackend, rewrite, sanitizeAiKitConfig, sendChatMessage, sendFeedbackMessage, sendSearchMessage, summarize, translate, waitForAiKitReady, write };