fixdog 0.0.1

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/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "fixdog",
3
+ "version": "0.0.1",
4
+ "description": "FixDog - In-browser IDE to fix your frontend",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/index.js",
11
+ "import": "./dist/index.mjs",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./client": {
15
+ "require": "./dist/client/index.js",
16
+ "import": "./dist/client/index.mjs",
17
+ "types": "./dist/client/index.d.ts"
18
+ },
19
+ "./init": {
20
+ "require": "./dist/client/init.js",
21
+ "import": "./dist/client/init.mjs",
22
+ "types": "./dist/client/init.d.ts"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "dev": "tsup --watch",
29
+ "prepublishOnly": "npm run build"
30
+ },
31
+ "keywords": [
32
+ "uidog",
33
+ "nextjs",
34
+ "react",
35
+ "devtools",
36
+ "bippy",
37
+ "element-inspector",
38
+ "source-location"
39
+ ],
40
+ "author": "Infi-PC",
41
+ "license": "MIT",
42
+ "dependencies": {
43
+ "bippy": "^0.5.25"
44
+ },
45
+ "peerDependencies": {
46
+ "next": ">=14.0.0",
47
+ "react": ">=17.0.0",
48
+ "react-dom": ">=17.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^24.10.1",
52
+ "@types/react": "^18.2.0",
53
+ "@types/react-dom": "^18.2.0",
54
+ "tsup": "^7.2.0",
55
+ "typescript": "^5.2.0"
56
+ }
57
+ }
@@ -0,0 +1,141 @@
1
+ export interface EditRequest {
2
+ editorUrl: string;
3
+ userInput: string;
4
+ }
5
+
6
+ export interface EditResponse {
7
+ sessionId: string;
8
+ message: string;
9
+ status: "success" | "error";
10
+ error?: string;
11
+ }
12
+
13
+ export interface ChatRequest {
14
+ prompt: string;
15
+ sessionId?: string;
16
+ }
17
+
18
+ export interface ChatResponse {
19
+ ok: boolean;
20
+ message: string;
21
+ sessionId?: string;
22
+ error?: string;
23
+ }
24
+
25
+ export interface SendToDevRequest {
26
+ sessionId: string;
27
+ }
28
+
29
+ export interface SendToDevResponse {
30
+ ok: boolean;
31
+ prUrl?: string;
32
+ prNumber?: number;
33
+ branchName?: string;
34
+ error?: string;
35
+ }
36
+
37
+ export async function createEditSession(
38
+ request: EditRequest,
39
+ apiEndpoint: string = "https://api.ui.dog"
40
+ ): Promise<EditResponse> {
41
+ try {
42
+ const response = await fetch(`${apiEndpoint}/api/sessions`, {
43
+ method: "POST",
44
+ headers: {
45
+ "Content-Type": "application/json",
46
+ },
47
+ body: JSON.stringify(request),
48
+ });
49
+
50
+ if (!response.ok) {
51
+ const errorText = await response.text().catch(() => response.statusText);
52
+ throw new Error(`API error (${response.status}): ${errorText}`);
53
+ }
54
+
55
+ return await response.json();
56
+ } catch (error) {
57
+ if (error instanceof Error) {
58
+ throw error;
59
+ }
60
+ throw new Error("Unknown error occurred");
61
+ }
62
+ }
63
+
64
+ export async function sendChatPrompt(
65
+ request: ChatRequest,
66
+ apiEndpoint: string = "http://localhost:3000"
67
+ ): Promise<ChatResponse> {
68
+ try {
69
+ const response = await fetch(`${apiEndpoint}/chat`, {
70
+ method: "POST",
71
+ headers: {
72
+ "Content-Type": "application/json",
73
+ },
74
+ body: JSON.stringify(request),
75
+ });
76
+
77
+ if (!response.ok) {
78
+ const errorData = await response
79
+ .json()
80
+ .catch(() => ({ error: response.statusText }));
81
+ return {
82
+ ok: false,
83
+ message: "",
84
+ error: errorData.error || `API error (${response.status})`,
85
+ };
86
+ }
87
+
88
+ return await response.json();
89
+ } catch (error) {
90
+ if (error instanceof Error) {
91
+ return {
92
+ ok: false,
93
+ message: "",
94
+ error: error.message,
95
+ };
96
+ }
97
+ return {
98
+ ok: false,
99
+ message: "",
100
+ error: "Unknown error occurred",
101
+ };
102
+ }
103
+ }
104
+
105
+ export async function sendToDeveloper(
106
+ request: SendToDevRequest,
107
+ apiEndpoint: string = "http://localhost:3000"
108
+ ): Promise<SendToDevResponse> {
109
+ try {
110
+ const response = await fetch(`${apiEndpoint}/send-to-dev`, {
111
+ method: "POST",
112
+ headers: {
113
+ "Content-Type": "application/json",
114
+ },
115
+ body: JSON.stringify(request),
116
+ });
117
+
118
+ if (!response.ok) {
119
+ const errorData = await response
120
+ .json()
121
+ .catch(() => ({ error: response.statusText }));
122
+ return {
123
+ ok: false,
124
+ error: errorData.error || `API error (${response.status})`,
125
+ };
126
+ }
127
+
128
+ return await response.json();
129
+ } catch (error) {
130
+ if (error instanceof Error) {
131
+ return {
132
+ ok: false,
133
+ error: error.message,
134
+ };
135
+ }
136
+ return {
137
+ ok: false,
138
+ error: "Unknown error occurred",
139
+ };
140
+ }
141
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Client entry point for UiDog Next.js integration
3
+ *
4
+ * This file is designed to be imported in:
5
+ * - Next.js 15.3+: instrumentation-client.ts at project root
6
+ * - Next.js 14.x / Pages Router: top of _app.tsx (must be first import)
7
+ *
8
+ * IMPORTANT: This file MUST be imported BEFORE React loads to properly
9
+ * install Bippy's React DevTools hook.
10
+ *
11
+ * Usage:
12
+ * ```typescript
13
+ * // instrumentation-client.ts (Next.js 15.3+)
14
+ * import 'uidog-sdk-next/client';
15
+ * ```
16
+ *
17
+ * ```typescript
18
+ * // pages/_app.tsx (Next.js 14.x / Pages Router)
19
+ * import 'uidog-sdk-next/client'; // MUST be first import
20
+ * import type { AppProps } from 'next/app';
21
+ * // ... rest of your imports
22
+ * ```
23
+ */
24
+
25
+ // Import bippy FIRST to install the React DevTools hook
26
+ // This must happen before React is imported anywhere
27
+ import "bippy";
28
+
29
+ import { initializeUiDogNext } from "../index";
30
+ import type { UiDogNextOptions } from "../types";
31
+
32
+ // Store options for deferred initialization
33
+ let pendingOptions: UiDogNextOptions = {};
34
+ let isAutoInitEnabled = true;
35
+
36
+ /**
37
+ * Configure UiDog options before initialization
38
+ * Call this before auto-initialization happens (at DOMContentLoaded)
39
+ */
40
+ export function configureUiDogNext(options: UiDogNextOptions): void {
41
+ pendingOptions = { ...pendingOptions, ...options };
42
+ }
43
+
44
+ /**
45
+ * Disable auto-initialization
46
+ * Use this if you want to manually initialize UiDog later
47
+ */
48
+ export function disableAutoInit(): void {
49
+ isAutoInitEnabled = false;
50
+ }
51
+
52
+ /**
53
+ * Initialize UiDog with the configured options
54
+ */
55
+ function initialize(): void {
56
+ if (!isAutoInitEnabled) return;
57
+
58
+ initializeUiDogNext(pendingOptions);
59
+ }
60
+
61
+ // Auto-initialize when imported (browser only)
62
+ if (typeof window !== "undefined") {
63
+ // Initialize when DOM is ready
64
+ if (document.readyState === "loading") {
65
+ document.addEventListener("DOMContentLoaded", initialize);
66
+ } else {
67
+ // DOM is already ready, initialize immediately
68
+ // Use setTimeout to ensure this runs after any synchronous configuration
69
+ setTimeout(initialize, 0);
70
+ }
71
+ }
72
+
73
+ // Re-export main functions for convenience
74
+ export { initializeUiDogNext } from "../index";
75
+ export type { UiDogNextOptions } from "../types";
@@ -0,0 +1,78 @@
1
+ /**
2
+ * UiDogProvider - React component for configuring UiDog in Next.js App Router
3
+ *
4
+ * This component provides a declarative way to configure UiDog options.
5
+ * It should be used in your root layout.tsx for App Router apps.
6
+ *
7
+ * Usage:
8
+ * ```tsx
9
+ * // app/layout.tsx
10
+ * import { UiDogProvider } from 'uidog-sdk-next/init';
11
+ *
12
+ * export default function RootLayout({ children }) {
13
+ * return (
14
+ * <html>
15
+ * <body>
16
+ * <UiDogProvider editor="cursor" enableSidebar>
17
+ * {children}
18
+ * </UiDogProvider>
19
+ * </body>
20
+ * </html>
21
+ * );
22
+ * }
23
+ * ```
24
+ *
25
+ * Note: You still need to import 'uidog-sdk-next/client' in instrumentation-client.ts
26
+ * This provider is for configuration, not initialization.
27
+ */
28
+
29
+ "use client";
30
+
31
+ import { useEffect, type ReactNode } from "react";
32
+ import { initializeUiDogNext, cleanupUiDogNext, isUiDogNextInitialized } from "../index";
33
+ import type { UiDogNextOptions, EditorType } from "../types";
34
+
35
+ export interface UiDogProviderProps extends UiDogNextOptions {
36
+ children: ReactNode;
37
+ }
38
+
39
+ export function UiDogProvider({
40
+ children,
41
+ editor = "cursor",
42
+ projectPath = "",
43
+ modifier = "alt",
44
+ enableSidebar = true,
45
+ apiEndpoint = "https://api.ui.dog",
46
+ }: UiDogProviderProps) {
47
+ useEffect(() => {
48
+ // Only initialize in development mode
49
+ if (process.env.NODE_ENV !== "development") {
50
+ return;
51
+ }
52
+
53
+ // Don't re-initialize if already done
54
+ if (isUiDogNextInitialized()) {
55
+ return;
56
+ }
57
+
58
+ initializeUiDogNext({
59
+ editor,
60
+ projectPath,
61
+ modifier,
62
+ enableSidebar,
63
+ apiEndpoint,
64
+ });
65
+
66
+ // Cleanup on unmount (though this rarely happens for root providers)
67
+ return () => {
68
+ // Note: We typically don't cleanup on unmount as this is a root-level provider
69
+ // Uncomment if needed for testing:
70
+ // cleanupUiDogNext();
71
+ };
72
+ }, [editor, projectPath, modifier, enableSidebar, apiEndpoint]);
73
+
74
+ return <>{children}</>;
75
+ }
76
+
77
+ // Re-export types for convenience
78
+ export type { UiDogNextOptions, EditorType };