@rebasepro/plugin-ai 0.0.1-canary.4829d6e

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.
Files changed (37) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +81 -0
  3. package/dist/api.d.ts +34 -0
  4. package/dist/components/DataEnhancementControllerProvider.d.ts +14 -0
  5. package/dist/components/FormEnhanceAction.d.ts +3 -0
  6. package/dist/editor/useEditorAIController.d.ts +4 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.es.js +741 -0
  9. package/dist/index.es.js.map +1 -0
  10. package/dist/index.umd.js +772 -0
  11. package/dist/index.umd.js.map +1 -0
  12. package/dist/types/data_enhancement_controller.d.ts +71 -0
  13. package/dist/useDataEnhancementPlugin.d.ts +29 -0
  14. package/dist/utils/diffStrings.d.ts +7 -0
  15. package/dist/utils/properties.d.ts +3 -0
  16. package/dist/utils/strings_counter.d.ts +2 -0
  17. package/dist/utils/suggestions.d.ts +1 -0
  18. package/dist/utils/values.d.ts +1 -0
  19. package/package.json +99 -0
  20. package/src/api.ts +198 -0
  21. package/src/components/DataEnhancementControllerProvider.tsx +342 -0
  22. package/src/components/FormEnhanceAction.tsx +277 -0
  23. package/src/editor/useEditorAIController.tsx +37 -0
  24. package/src/index.ts +9 -0
  25. package/src/tests/diffStrings.test.ts +128 -0
  26. package/src/tests/strings_counter.test.ts +117 -0
  27. package/src/tests/suggestions.test.ts +53 -0
  28. package/src/tests/useDataEnhancementPlugin.test.tsx +51 -0
  29. package/src/tests/values.test.ts +87 -0
  30. package/src/types/data_enhancement_controller.tsx +75 -0
  31. package/src/useDataEnhancementPlugin.tsx +66 -0
  32. package/src/utils/diffStrings.ts +70 -0
  33. package/src/utils/properties.ts +168 -0
  34. package/src/utils/strings_counter.ts +22 -0
  35. package/src/utils/suggestions.ts +6 -0
  36. package/src/utils/values.ts +12 -0
  37. package/src/vite-env.d.ts +1 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rebase
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @rebasepro/plugin-ai
2
+
3
+ AI-powered data autofill and text autocomplete plugin for Rebase.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @rebasepro/plugin-ai
9
+ ```
10
+
11
+ **Peer dependencies:** `react >= 19.0.0`, `react-dom >= 19.0.0`, `react-router >= 6.28.0`, `react-router-dom >= 6.28.0`
12
+
13
+ ## What This Package Does
14
+
15
+ This plugin adds AI-powered capabilities to the Rebase admin panel:
16
+
17
+ - **Form autofill** — An "Enhance" action button injected into snapshot forms that uses AI to suggest and fill field values based on collection schema and existing data.
18
+ - **Editor autocomplete** — A streaming text autocomplete controller for rich text editors, powered by an AI backend.
19
+
20
+ It registers as a standard `RebasePlugin`, injecting UI slots and providers automatically.
21
+
22
+ ## Key Exports
23
+
24
+ | Export | Type | Description |
25
+ |---|---|---|
26
+ | `useDataEnhancementPlugin` | Hook | Creates the plugin. Returns a `RebasePlugin` to pass to your app's `plugins` array |
27
+ | `DataEnhancementPluginProps` | Type | Configuration options for the plugin |
28
+ | `useEditorAIController` | Hook | Returns an `EditorAIController` with a streaming `autocomplete` method for rich text editors |
29
+
30
+ ### `DataEnhancementPluginProps`
31
+
32
+ | Prop | Type | Default | Description |
33
+ |---|---|---|---|
34
+ | `apiKey` | `string` | Built-in default key | API key for the data enhancement service |
35
+ | `getConfigForPath` | `(props: { path, collection, user }) => boolean` | — | Return `false` to disable enhancement for specific paths |
36
+ | `host` | `string` | — | Custom API host (development only) |
37
+
38
+ ## Quick Start
39
+
40
+ ```tsx
41
+ import { useDataEnhancementPlugin } from "@rebasepro/plugin-ai";
42
+
43
+ // In your app setup:
44
+ const dataEnhancementPlugin = useDataEnhancementPlugin({
45
+ getConfigForPath: ({ path, collection }) => {
46
+ // Disable for certain collections
47
+ return collection.name !== "system_logs";
48
+ }
49
+ });
50
+
51
+ // Pass to your Rebase app:
52
+ <RebaseFirebaseApp
53
+ plugins={[dataEnhancementPlugin]}
54
+ // ...other props
55
+ />
56
+ ```
57
+
58
+ ### Editor AI Autocomplete
59
+
60
+ ```tsx
61
+ import { useEditorAIController } from "@rebasepro/plugin-ai";
62
+
63
+ const aiController = useEditorAIController({
64
+ getAuthToken: () => firebaseUser.getIdToken()
65
+ });
66
+
67
+ // Use in a rich text editor:
68
+ await aiController.autocomplete(
69
+ "The quick brown", // text before cursor
70
+ " over the fence", // text after cursor
71
+ (delta) => { // streaming callback
72
+ appendText(delta);
73
+ }
74
+ );
75
+ ```
76
+
77
+ ## Related Packages
78
+
79
+ - `@rebasepro/admin` — The admin panel this plugin extends
80
+ - `@rebasepro/app` — Core framework providing the plugin system
81
+ - `@rebasepro/types` — Shared types (`RebasePlugin`, `CollectionConfig`, etc.)
package/dist/api.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { EnhancedDataResult, InputProperty, SamplePromptsResult } from "./types/data_enhancement_controller";
2
+ import { EntityValues } from "@rebasepro/types";
3
+ export declare function enhanceDataAPIStream<M extends Record<string, unknown>>(props: {
4
+ apiKey: string;
5
+ entityId?: string | number;
6
+ entityName: string;
7
+ entityDescription?: string;
8
+ propertyKey?: string;
9
+ propertyInstructions?: string;
10
+ values: EntityValues<M>;
11
+ path: string;
12
+ properties: Record<string, InputProperty>;
13
+ instructions?: string;
14
+ firebaseToken: string;
15
+ onUpdate: (suggestions: Record<string, string | number>) => void;
16
+ onUpdateDelta: (propertyKey: string, partialValue: string) => void;
17
+ onError: (error: Error) => void;
18
+ onEnd: (result: EnhancedDataResult) => void;
19
+ host?: string;
20
+ }): Promise<void>;
21
+ export declare function fetchEntityPromptSuggestion<M extends object>(props: {
22
+ input?: string;
23
+ entityName: string;
24
+ firebaseToken: string;
25
+ apiKey: string;
26
+ host?: string;
27
+ }): Promise<SamplePromptsResult>;
28
+ export declare function autocompleteStream(props: {
29
+ firebaseToken: string;
30
+ textBefore?: string;
31
+ textAfter: string;
32
+ host?: string;
33
+ onUpdate: (delta: string) => void;
34
+ }): Promise<string>;
@@ -0,0 +1,14 @@
1
+ import React, { PropsWithChildren } from "react";
2
+ import { DataEnhancementController } from "../types/data_enhancement_controller";
3
+ import { CollectionConfig, PluginFormActionProps } from "@rebasepro/types";
4
+ type DataEnhancementControllerProviderProps = {
5
+ apiKey: string;
6
+ getConfigForPath?: (props: {
7
+ path: string;
8
+ collection: CollectionConfig;
9
+ }) => boolean;
10
+ host?: string;
11
+ };
12
+ export declare const useDataEnhancementController: () => DataEnhancementController;
13
+ export declare function DataEnhancementControllerProvider({ apiKey, getConfigForPath, children, host, path, collection, formContext }: PropsWithChildren<DataEnhancementControllerProviderProps & PluginFormActionProps>): React.JSX.Element;
14
+ export {};
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { PluginFormActionProps } from "@rebasepro/types";
3
+ export declare function FormEnhanceAction({ entityId, path, status, collection, formContext, openEntityMode }: PluginFormActionProps): React.JSX.Element | null;
@@ -0,0 +1,4 @@
1
+ import { EditorAIController } from "@rebasepro/admin";
2
+ export declare function useEditorAIController({ getAuthToken }: {
3
+ getAuthToken?: () => Promise<string>;
4
+ }): EditorAIController;
@@ -0,0 +1,3 @@
1
+ export { useDataEnhancementPlugin } from "./useDataEnhancementPlugin";
2
+ export type { DataEnhancementPluginProps } from "./useDataEnhancementPlugin";
3
+ export * from "./editor/useEditorAIController";