@vibes.diy/use-vibes-base 0.19.8-dev → 0.19.14-dev-cli

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 (90) hide show
  1. package/README.md +27 -27
  2. package/components/ControlsBar.d.ts +2 -2
  3. package/components/ControlsBar.js +35 -39
  4. package/components/ControlsBar.js.map +1 -1
  5. package/components/ImgGen.d.ts +5 -5
  6. package/components/ImgGen.js +40 -43
  7. package/components/ImgGen.js.map +1 -1
  8. package/components/ImgGenUtils/AsyncImg.d.ts +2 -2
  9. package/components/ImgGenUtils/AsyncImg.js +5 -5
  10. package/components/ImgGenUtils/ImgGenDisplay.d.ts +2 -2
  11. package/components/ImgGenUtils/ImgGenDisplay.js +57 -67
  12. package/components/ImgGenUtils/ImgGenDisplay.js.map +1 -1
  13. package/components/ImgGenUtils/ImgGenDisplayPlaceholder.d.ts +2 -2
  14. package/components/ImgGenUtils/ImgGenDisplayPlaceholder.js +28 -29
  15. package/components/ImgGenUtils/ImgGenDisplayPlaceholder.js.map +1 -1
  16. package/components/ImgGenUtils/ImgGenDisplayUtils.d.ts +1 -1
  17. package/components/ImgGenUtils/ImgGenDisplayUtils.js +13 -18
  18. package/components/ImgGenUtils/ImgGenDisplayUtils.js.map +1 -1
  19. package/components/ImgGenUtils/ImgGenError.d.ts +2 -2
  20. package/components/ImgGenUtils/ImgGenError.js +6 -6
  21. package/components/ImgGenUtils/ImgGenError.js.map +1 -1
  22. package/components/ImgGenUtils/ImgGenFileDrop.d.ts +1 -1
  23. package/components/ImgGenUtils/ImgGenFileDrop.js +7 -7
  24. package/components/ImgGenUtils/ImgGenFileDrop.js.map +1 -1
  25. package/components/ImgGenUtils/ImgGenModal.d.ts +3 -3
  26. package/components/ImgGenUtils/ImgGenModal.js +35 -35
  27. package/components/ImgGenUtils/ImgGenModeUtils.d.ts +2 -2
  28. package/components/ImgGenUtils/ImgGenModeUtils.js +17 -17
  29. package/components/ImgGenUtils/ImgGenModeUtils.js.map +1 -1
  30. package/components/ImgGenUtils/ImgGenPromptWaiting.d.ts +2 -2
  31. package/components/ImgGenUtils/ImgGenPromptWaiting.js +13 -13
  32. package/components/ImgGenUtils/ImgGenPromptWaiting.js.map +1 -1
  33. package/components/ImgGenUtils/ImgGenUploadWaiting.d.ts +4 -4
  34. package/components/ImgGenUtils/ImgGenUploadWaiting.js +26 -26
  35. package/components/ImgGenUtils/ImgGenUploadWaiting.js.map +1 -1
  36. package/components/ImgGenUtils/index.d.ts +6 -6
  37. package/components/ImgGenUtils/index.js +6 -6
  38. package/components/ImgGenUtils/overlays/DeleteConfirmationOverlay.d.ts +2 -2
  39. package/components/ImgGenUtils/overlays/DeleteConfirmationOverlay.js +18 -18
  40. package/components/ImgGenUtils/overlays/ImageOverlay.d.ts +2 -2
  41. package/components/ImgGenUtils/overlays/ImageOverlay.js +6 -6
  42. package/components/ImgGenUtils/types.d.ts +2 -2
  43. package/components/ImgGenUtils.d.ts +2 -2
  44. package/components/ImgGenUtils.js +2 -2
  45. package/components/ImgGenUtils.js.map +1 -1
  46. package/components/PromptBar.d.ts +2 -2
  47. package/components/PromptBar.js +5 -5
  48. package/constants.js +1 -1
  49. package/contexts/VibeContext.d.ts +23 -11
  50. package/contexts/VibeContext.js +113 -48
  51. package/contexts/VibeContext.js.map +1 -1
  52. package/hooks/image-gen/image-generator.d.ts +2 -2
  53. package/hooks/image-gen/image-generator.js +12 -12
  54. package/hooks/image-gen/image-generator.js.map +1 -1
  55. package/hooks/image-gen/index.d.ts +4 -4
  56. package/hooks/image-gen/index.js +3 -3
  57. package/hooks/image-gen/index.js.map +1 -1
  58. package/hooks/image-gen/use-image-gen.d.ts +1 -1
  59. package/hooks/image-gen/use-image-gen.js +41 -48
  60. package/hooks/image-gen/use-image-gen.js.map +1 -1
  61. package/hooks/image-gen/utils.d.ts +2 -2
  62. package/hooks/image-gen/utils.js +14 -14
  63. package/hooks/image-gen/utils.js.map +1 -1
  64. package/hooks/useMobile.js +7 -7
  65. package/hooks/useThemeDetection.js +5 -5
  66. package/hooks/vibes-gen/IframeVibesComponent.d.ts +1 -1
  67. package/hooks/vibes-gen/IframeVibesComponent.js +15 -19
  68. package/hooks/vibes-gen/IframeVibesComponent.js.map +1 -1
  69. package/hooks/vibes-gen/index.d.ts +2 -2
  70. package/hooks/vibes-gen/index.js +1 -1
  71. package/hooks/vibes-gen/use-vibes.d.ts +2 -2
  72. package/hooks/vibes-gen/use-vibes.js +21 -17
  73. package/hooks/vibes-gen/use-vibes.js.map +1 -1
  74. package/index.d.ts +76 -51
  75. package/index.js +137 -184
  76. package/index.js.map +1 -1
  77. package/package.json +18 -21
  78. package/utils/appSlug.js +16 -16
  79. package/utils/base64.js +2 -4
  80. package/utils/base64.js.map +1 -1
  81. package/utils/databaseName.d.ts +2 -0
  82. package/utils/databaseName.js +4 -0
  83. package/utils/databaseName.js.map +1 -0
  84. package/utils/debug.js +1 -1
  85. package/utils/style-utils.d.ts +1 -1
  86. package/utils/style-utils.js +3 -3
  87. package/utils/styles.d.ts +2 -2
  88. package/utils/styles.js +170 -170
  89. package/utils/vibe-control-styles.d.ts +1 -1
  90. package/utils/vibe-control-styles.js +75 -75
@@ -1,2 +1,2 @@
1
- export { useVibes } from './use-vibes.js';
2
- export type { UseVibesOptions, UseVibesResult, VibeDocument } from '@vibes.diy/use-vibes-types';
1
+ export { useVibes } from "./use-vibes.js";
2
+ export type { UseVibesOptions, UseVibesResult, VibeDocument } from "@vibes.diy/use-vibes-types";
@@ -1,2 +1,2 @@
1
- export { useVibes } from './use-vibes.js';
1
+ export { useVibes } from "./use-vibes.js";
2
2
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- import type { UseVibesOptions, UseVibesResult } from '@vibes.diy/use-vibes-types';
2
- import { callAI as defaultCallAI } from 'call-ai';
1
+ import type { UseVibesOptions, UseVibesResult } from "@vibes.diy/use-vibes-types";
2
+ import { callAI as defaultCallAI } from "call-ai";
3
3
  export declare function useVibes(prompt: string, options?: UseVibesOptions, callAI?: typeof defaultCallAI): UseVibesResult;
@@ -1,7 +1,7 @@
1
- import { makeBaseSystemPrompt, parseContent } from '@vibes.diy/prompts';
2
- import { callAI as defaultCallAI } from 'call-ai';
3
- import React, { useCallback, useEffect, useRef, useState } from 'react';
4
- import IframeVibesComponent from './IframeVibesComponent.js';
1
+ import { makeBaseSystemPrompt, parseContent } from "@vibes.diy/prompts";
2
+ import { callAI as defaultCallAI } from "call-ai";
3
+ import React, { useCallback, useEffect, useRef, useState } from "react";
4
+ import IframeVibesComponent from "./IframeVibesComponent.js";
5
5
  export function useVibes(prompt, options = {}, callAI = defaultCallAI) {
6
6
  const [state, setState] = useState({
7
7
  App: null,
@@ -32,11 +32,11 @@ export function useVibes(prompt, options = {}, callAI = defaultCallAI) {
32
32
  useEffect(() => {
33
33
  if (!mountedRef.current)
34
34
  return;
35
- if (!prompt || typeof prompt !== 'string' || prompt.trim().length === 0) {
35
+ if (!prompt || typeof prompt !== "string" || prompt.trim().length === 0) {
36
36
  setState((prev) => ({
37
37
  ...prev,
38
38
  loading: false,
39
- error: new Error('Prompt required'),
39
+ error: new Error("Prompt required"),
40
40
  App: null,
41
41
  code: null,
42
42
  progress: 0,
@@ -73,10 +73,14 @@ export function useVibes(prompt, options = {}, callAI = defaultCallAI) {
73
73
  simulateProgress(0);
74
74
  let result;
75
75
  try {
76
- result = await makeBaseSystemPrompt(options.model || 'anthropic/claude-sonnet-4.5', {
76
+ result = await makeBaseSystemPrompt(options.model || "anthropic/claude-sonnet-4.5", {
77
77
  userPrompt: prompt,
78
78
  history: [],
79
- fallBackUrl: 'https://esm.sh/@vibes.diy/prompts/llms',
79
+ callAi: {
80
+ ModuleAndOptionsSelection: () => {
81
+ throw new Error("ModuleAndOptionsSelection not implemented in Cycle 1");
82
+ },
83
+ },
80
84
  dependencies: options.dependencies,
81
85
  dependenciesUserOverride: !!options.dependencies,
82
86
  });
@@ -86,9 +90,9 @@ export function useVibes(prompt, options = {}, callAI = defaultCallAI) {
86
90
  systemPrompt: `You are a React component generator. Generate a complete React component based on the user's prompt.
87
91
  Use Fireproof for data persistence. Begin the component with the import statements.
88
92
  Return only the JSX code with a default export. Use modern React patterns with hooks if needed.`,
89
- dependencies: options.dependencies || ['useFireproof'],
93
+ dependencies: options.dependencies || ["useFireproof"],
90
94
  demoData: false,
91
- model: options.model || 'anthropic/claude-sonnet-4.5',
95
+ model: options.model || "anthropic/claude-sonnet-4.5",
92
96
  };
93
97
  }
94
98
  const systemPrompt = result.systemPrompt;
@@ -100,8 +104,8 @@ Return only the JSX code with a default export. Use modern React patterns with h
100
104
  timestamp: Date.now(),
101
105
  };
102
106
  const messages = [
103
- { role: 'system', content: systemPrompt },
104
- { role: 'user', content: prompt },
107
+ { role: "system", content: systemPrompt },
108
+ { role: "user", content: prompt },
105
109
  ];
106
110
  const aiResponse = await callAI(messages, {
107
111
  model: metadata.model,
@@ -110,10 +114,10 @@ Return only the JSX code with a default export. Use modern React patterns with h
110
114
  if (generationIdRef.current !== generationId || !mountedRef.current) {
111
115
  return;
112
116
  }
113
- const rawResponse = typeof aiResponse === 'string' ? aiResponse : '';
117
+ const rawResponse = typeof aiResponse === "string" ? aiResponse : "";
114
118
  const { segments } = parseContent(rawResponse);
115
- const codeSegment = segments.find((segment) => segment.type === 'code');
116
- const extractedCode = codeSegment ? codeSegment.content : '';
119
+ const codeSegment = segments.find((segment) => segment.type === "code");
120
+ const extractedCode = codeSegment ? codeSegment.content : "";
117
121
  const codeToUse = extractedCode || rawResponse;
118
122
  const sessionId = `vibes-${Date.now()}`;
119
123
  const App = () => React.createElement(IframeVibesComponent, {
@@ -135,7 +139,7 @@ Return only the JSX code with a default export. Use modern React patterns with h
135
139
  _id: `vibe-${Date.now()}`,
136
140
  prompt,
137
141
  code: codeToUse,
138
- title: 'Generated Component',
142
+ title: "Generated Component",
139
143
  ...metadata,
140
144
  created_at: Date.now(),
141
145
  version: 1,
@@ -149,7 +153,7 @@ Return only the JSX code with a default export. Use modern React patterns with h
149
153
  setState((prev) => ({
150
154
  ...prev,
151
155
  loading: false,
152
- error: error instanceof Error ? error : new Error('Generation failed'),
156
+ error: error instanceof Error ? error : new Error("Generation failed"),
153
157
  progress: 0,
154
158
  }));
155
159
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-vibes.js","sourceRoot":"","sources":["../../../jsr/hooks/vibes-gen/use-vibes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAM7D,MAAM,UAAU,QAAQ,CACtB,MAAc,EACd,OAAO,GAAoB,EAAE,EAC7B,MAAM,GAAyB,aAAa,EAC5B;IAEhB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB;QAChD,GAAG,EAAE,IAAI;QACT,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,KAAK,EAAE,6DAA6D;QAC7E,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IAGH,MAAM,eAAe,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,gBAAgB,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IAC7D,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,QAAQ,CAAS,CAAC,CAAC,CAAC;IAG1E,MAAM,gBAAgB,GAAG,WAAW,CAAC,CAAC,eAAe,GAAG,CAAC,EAAE,EAAE,CAAC;QAC5D,MAAM,SAAS,GAAG,IAAI,CAAC,MA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E,CAAC;QAGpB,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,gBAAgB,CAAC,OAAO,EAAE,CAAC;gBAC7B,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;gBACvC,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;YAClC,CAAC;QAAA,CACF,CAAC;IAAA,CACH,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAGrF,SAAS,CAAC,GAAG,EAAE,CAAC;QACd,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;QAE1B,OAAO,GAAG,EAAE,CAAC;YACX,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC;YAC3B,IAAI,gBAAgB,CAAC,OAAO,EAAE,CAAC;gBAC7B,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YACzC,CAAC;QAAA,CACF,CAAC;IAAA,CACH,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,UAAU;QACV,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC;AAAA,CACH"}
package/index.d.ts CHANGED
@@ -1,53 +1,78 @@
1
- import type { ToCloudAttachable } from '@fireproof/core-types-protocols-cloud';
2
- import { fireproof, ImgFile, type Database, type UseFpToCloudParam } from 'use-fireproof';
1
+ import type { ToCloudAttachable, TokenStrategie } from "@fireproof/core-types-protocols-cloud";
2
+ import { Attached, fireproof, ImgFile, UseFireproof, UseFPConfig, type Database, type UseFpToCloudParam } from "@fireproof/use-fireproof";
3
+ import { Vibe } from "./contexts/VibeContext.js";
4
+ import { callAI } from "call-ai";
5
+ export * from "./contexts/VibeContext.js";
3
6
  export { fireproof, ImgFile };
4
- export type * as Fireproof from 'use-fireproof';
5
- export declare function isJWTExpired(token: string): Promise<boolean>;
6
- export declare function toCloud(opts?: UseFpToCloudParam): ToCloudAttachable;
7
- export declare function useFireproof(nameOrDatabase?: string | Database): {
8
- database: Database;
9
- useDocument: import("use-fireproof").UseDocument;
10
- useLiveQuery: import("use-fireproof").UseLiveQuery;
11
- useAllDocs: import("use-fireproof").UseAllDocs;
12
- useChanges: import("use-fireproof").UseChanges;
13
- attach: import("use-fireproof").AttachState;
14
- enableSync: () => void;
15
- disableSync: () => void;
16
- syncEnabled: boolean;
17
- share: (options: {
18
- email: string;
19
- role?: "admin" | "member" | undefined;
20
- right?: "read" | "write" | undefined;
21
- token?: string | undefined;
22
- }) => Promise<{
23
- success: boolean;
24
- email: string;
25
- role: string;
26
- right: string;
27
- message: string;
28
- }>;
29
- };
30
- import { callAI } from 'call-ai';
7
+ export type * as Fireproof from "@fireproof/use-fireproof";
8
+ export declare const vibesEnvSchema: import("arktype/internal/variants/object.ts").ObjectType<{
9
+ FPCLOUD_URL: string;
10
+ DASHBOARD_URL: string;
11
+ VIBES_DIY_STYLES_URL: string;
12
+ }, {}>;
13
+ export type VibesEnv = typeof vibesEnvSchema.infer;
14
+ export declare const vibeEnv: import("arktype/internal/variants/object.ts").ObjectType<Record<string, string>, {}>;
15
+ export type VibeEnv = typeof vibeEnv.infer;
16
+ export declare const vibeBindings: import("arktype/internal/variants/object.ts").ObjectType<{
17
+ appSlug: string;
18
+ userSlug: string;
19
+ fsId: string;
20
+ groupId?: string | undefined;
21
+ }, {}>;
22
+ export type VibeBindings = typeof vibeBindings.infer;
23
+ export declare const vibesDiyMountParams: import("arktype/internal/variants/object.ts").ObjectType<{
24
+ bindings: {
25
+ appSlug: string;
26
+ userSlug: string;
27
+ fsId: string;
28
+ groupId?: string | undefined;
29
+ };
30
+ env: {
31
+ [x: string]: string;
32
+ FPCLOUD_URL: string;
33
+ DASHBOARD_URL: string;
34
+ VIBES_DIY_STYLES_URL: string;
35
+ };
36
+ }, {}>;
37
+ export type VibesDiyMountParams = typeof vibesDiyMountParams.infer;
38
+ interface ToCloudWithClerkOpts extends UseFpToCloudParam {
39
+ readonly env: VibesEnv;
40
+ readonly fpCloudStrategie?: TokenStrategie;
41
+ }
42
+ export declare function injectDefaultVibesCtx(ctx: Vibe): void;
43
+ export declare function toCloud(iopts?: ToCloudWithClerkOpts): ToCloudAttachable;
44
+ export interface AttachState {
45
+ readonly state: "detached" | "attaching" | "attached" | "detaching" | "error";
46
+ readonly error?: Error;
47
+ readonly attach?: Attached;
48
+ }
49
+ export interface UseVibesFireproof extends UseFireproof {
50
+ readonly doAttach: () => void;
51
+ readonly doDetach: () => void;
52
+ readonly attachState: AttachState;
53
+ readonly syncEnabled?: boolean;
54
+ }
55
+ export declare function useFireproof(nameOrDatabase: string | Database, config?: UseFPConfig): UseVibesFireproof;
31
56
  export { callAI, callAI as callAi };
32
- export type * as CallAI from 'call-ai';
33
- export { default as ImgGen } from './components/ImgGen.js';
34
- export type { ImgGenProps } from './components/ImgGen.js';
35
- export { ControlsBar } from './components/ControlsBar.js';
36
- export { PromptBar } from './components/PromptBar.js';
37
- export { hashInput, useImageGen } from './hooks/image-gen/index.js';
38
- export { useThemeDetection } from './hooks/useThemeDetection.js';
39
- export { useMobile } from './hooks/useMobile.js';
40
- export { defaultClasses } from './utils/style-utils.js';
41
- export type { ImgGenClasses } from '@vibes.diy/use-vibes-types';
42
- export { base64ToFile } from './utils/base64.js';
43
- export { ImgGenDisplay } from './components/ImgGenUtils/ImgGenDisplay.js';
44
- export { ImgGenDisplayPlaceholder } from './components/ImgGenUtils/ImgGenDisplayPlaceholder.js';
45
- export { ImgGenModal, type ImgGenModalProps } from './components/ImgGenUtils/ImgGenModal.js';
46
- export { ImageOverlay } from './components/ImgGenUtils/overlays/ImageOverlay.js';
47
- export { addNewVersion, MODULE_STATE } from './hooks/image-gen/utils.js';
48
- export type { ImageDocument, PartialImageDocument, UseImageGenOptions, UseImageGenResult, } from '@vibes.diy/use-vibes-types';
49
- export type { UseVibesOptions, UseVibesResult, VibeDocument } from '@vibes.diy/use-vibes-types';
50
- export { useVibes } from './hooks/vibes-gen/index.js';
51
- export { getAppSlug, getInstanceId, getFullAppIdentifier, isDevelopmentEnvironment, isProductionEnvironment, generateRandomInstanceId, generateFreshDataUrl, generateRemixUrl, generateInstallId, } from './utils/appSlug.js';
52
- export { VibeContextProvider, useVibeContext, VibeMetadataValidationError, VIBE_METADATA_ERROR_CODES, validateVibeMetadata, } from './contexts/VibeContext.js';
53
- export type { VibeMetadata } from './contexts/VibeContext.js';
57
+ export type * as CallAI from "call-ai";
58
+ export { default as ImgGen } from "./components/ImgGen.js";
59
+ export type { ImgGenProps } from "./components/ImgGen.js";
60
+ export { ControlsBar } from "./components/ControlsBar.js";
61
+ export { PromptBar } from "./components/PromptBar.js";
62
+ export { hashInput, useImageGen } from "./hooks/image-gen/index.js";
63
+ export { useThemeDetection } from "./hooks/useThemeDetection.js";
64
+ export { useMobile } from "./hooks/useMobile.js";
65
+ export { defaultClasses } from "./utils/style-utils.js";
66
+ export type { ImgGenClasses } from "@vibes.diy/use-vibes-types";
67
+ export { base64ToFile } from "./utils/base64.js";
68
+ export { constructVibesDatabaseName } from "./utils/databaseName.js";
69
+ export { ImgGenDisplay } from "./components/ImgGenUtils/ImgGenDisplay.js";
70
+ export { ImgGenDisplayPlaceholder } from "./components/ImgGenUtils/ImgGenDisplayPlaceholder.js";
71
+ export { ImgGenModal, type ImgGenModalProps } from "./components/ImgGenUtils/ImgGenModal.js";
72
+ export { ImageOverlay } from "./components/ImgGenUtils/overlays/ImageOverlay.js";
73
+ export { addNewVersion, MODULE_STATE } from "./hooks/image-gen/utils.js";
74
+ export type { ImageDocument, PartialImageDocument, UseImageGenOptions, UseImageGenResult } from "@vibes.diy/use-vibes-types";
75
+ export type { UseVibesOptions, UseVibesResult, VibeDocument } from "@vibes.diy/use-vibes-types";
76
+ export { useVibes } from "./hooks/vibes-gen/index.js";
77
+ export { getAppSlug, getInstanceId, getFullAppIdentifier, isDevelopmentEnvironment, isProductionEnvironment, generateRandomInstanceId, generateFreshDataUrl, generateRemixUrl, generateInstallId, } from "./utils/appSlug.js";
78
+ export { VibeContextProvider, useVibeContext, VibeMetadataValidationError } from "./contexts/VibeContext.js";
package/index.js CHANGED
@@ -1,205 +1,158 @@
1
- import { getKeyBag } from '@fireproof/core-keybag';
2
- import { Lazy } from '@adviser/cement';
3
- import { ensureSuperThis } from '@fireproof/core-runtime';
4
- import { useCallback, useEffect } from 'react';
5
- import { fireproof, ImgFile, toCloud as originalToCloud, useFireproof as originalUseFireproof, } from 'use-fireproof';
6
- import { VIBES_SYNC_ENABLED_CLASS } from './constants.js';
7
- import { useVibeContext } from './contexts/VibeContext.js';
8
- const syncEnabledInstances = new Map();
9
- let instanceCounter = 0;
10
- function updateBodyClass() {
11
- if (typeof window === 'undefined' || !document?.body)
12
- return;
13
- const hasAnySyncEnabled = Array.from(syncEnabledInstances.values()).some((instanceSet) => instanceSet.size > 0);
14
- if (hasAnySyncEnabled) {
15
- document.body.classList.add(VIBES_SYNC_ENABLED_CLASS);
16
- }
17
- else {
18
- document.body.classList.remove(VIBES_SYNC_ENABLED_CLASS);
19
- }
20
- }
21
- const sthis = Lazy(() => ensureSuperThis());
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { fireproof, ImgFile, isDatabase, toCloud as originalToCloud, useFireproof as originalUseFireproof, } from "@fireproof/use-fireproof";
3
+ import { useVibeContext } from "./contexts/VibeContext.js";
4
+ import { constructVibesDatabaseName } from "./utils/databaseName.js";
5
+ import { callAI } from "call-ai";
6
+ import { ResolveOnce } from "@adviser/cement";
7
+ import { type } from "arktype";
8
+ export * from "./contexts/VibeContext.js";
22
9
  export { fireproof, ImgFile };
23
- export async function isJWTExpired(token) {
24
- try {
25
- const kb = await getKeyBag(sthis());
26
- await kb.setJwt('vibes-temp-check', token);
27
- const result = await kb.getJwt('vibes-temp-check');
28
- if (result.isErr())
29
- return true;
30
- const claims = result.Ok().claims;
31
- if (!claims?.exp || typeof claims.exp !== 'number')
32
- return true;
33
- return Date.now() >= claims.exp * 1000 - 60000;
34
- }
35
- catch {
36
- return true;
10
+ export const vibesEnvSchema = type({
11
+ FPCLOUD_URL: "string",
12
+ DASHBOARD_URL: "string",
13
+ VIBES_DIY_STYLES_URL: "string",
14
+ });
15
+ export const vibeEnv = type("Record<string, string>");
16
+ const slugPattern = /^(?!.*\/|.*--|.*\.\.)[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]$/;
17
+ export const vibeBindings = type({
18
+ appSlug: slugPattern,
19
+ userSlug: slugPattern,
20
+ fsId: slugPattern,
21
+ "groupId?": slugPattern,
22
+ });
23
+ export const vibesDiyMountParams = type({
24
+ bindings: vibeBindings,
25
+ env: vibeEnv.and(vibesEnvSchema),
26
+ });
27
+ let injectedVibesCtx = undefined;
28
+ function defVibesCtx() {
29
+ if (!injectedVibesCtx) {
30
+ throw new Error("VibesCtx not injected. Please call injectDefaultVibes");
37
31
  }
32
+ return injectedVibesCtx;
33
+ }
34
+ export function injectDefaultVibesCtx(ctx) {
35
+ injectedVibesCtx = ctx;
38
36
  }
39
- export function toCloud(opts) {
37
+ export function toCloud(iopts) {
38
+ const defCtx = defVibesCtx();
39
+ const opts = {
40
+ ...defCtx,
41
+ ...iopts,
42
+ };
40
43
  const attachable = originalToCloud({
41
- ...opts,
42
- dashboardURI: 'https://connect.fireproof.direct/fp/cloud/api/token-auto',
43
- tokenApiURI: 'https://connect.fireproof.direct/api',
44
- urls: { base: 'fpcloud://cloud.fireproof.direct' },
44
+ strategy: opts.strategy,
45
+ dashboardURI: opts.env.DASHBOARD_URL,
46
+ urls: { base: opts.env.FPCLOUD_URL },
45
47
  });
46
48
  return attachable;
47
49
  }
48
- function constructDatabaseName(nameOrDatabase, vibeMetadata) {
49
- if (typeof nameOrDatabase === 'object' && nameOrDatabase !== null) {
50
- return nameOrDatabase;
50
+ export function useFireproof(nameOrDatabase, config) {
51
+ const vibeCtx = useVibeContext();
52
+ let dbName;
53
+ if (isDatabase(nameOrDatabase)) {
54
+ dbName = nameOrDatabase.ledger.ctx.get("UseVibes.AppId") || nameOrDatabase.name;
51
55
  }
52
- const baseName = nameOrDatabase || 'default';
53
- if (!vibeMetadata) {
54
- return baseName;
56
+ else {
57
+ dbName = constructVibesDatabaseName(vibeCtx.bindings, nameOrDatabase);
55
58
  }
56
- return `vf-${baseName}-${vibeMetadata.titleId}-${vibeMetadata.installId}`;
57
- }
58
- export function useFireproof(nameOrDatabase) {
59
- const vibeMetadata = useVibeContext();
60
- const augmentedDbName = constructDatabaseName(nameOrDatabase, vibeMetadata);
61
- const instanceId = `instance-${++instanceCounter}`;
62
- const dbName = typeof augmentedDbName === 'string' ? augmentedDbName : augmentedDbName?.name || 'default';
63
- const syncKey = 'fireproof-sync-enabled';
64
- const wasSyncEnabled = typeof window !== 'undefined' && localStorage.getItem(syncKey) === 'true';
65
- const attachConfig = wasSyncEnabled ? toCloud() : undefined;
66
- const result = originalUseFireproof(augmentedDbName, attachConfig ? { attach: attachConfig } : {});
67
- const enableSync = useCallback(() => {
68
- console.log('enableSync() not implemented - TODO: Enable sync with Clerk token');
69
- }, []);
70
- const disableSync = useCallback(() => {
71
- console.log('disableSync() not implemented - TODO: Disable sync with Clerk token');
72
- }, []);
73
- const syncEnabled = wasSyncEnabled && (result.attach?.state === 'attached' || result.attach?.state === 'attaching');
74
- const share = useCallback(async (options) => {
75
- const token = options.token;
76
- if (!token) {
77
- throw new Error('Authentication token required for sharing.');
59
+ let fpRet;
60
+ if (isDatabase(nameOrDatabase)) {
61
+ fpRet = originalUseFireproof(nameOrDatabase, config);
62
+ }
63
+ else {
64
+ fpRet = originalUseFireproof(dbName, config);
65
+ }
66
+ if (!fpRet.database.ledger.ctx.get("UseVibes.AppId")) {
67
+ fpRet.database.ledger.ctx.set("UseVibes.AppId", dbName);
68
+ }
69
+ if (!fpRet.database.ledger.ctx.get("UseVibes.Mutex")) {
70
+ fpRet.database.ledger.ctx.set("UseVibes.Mutex", new ResolveOnce());
71
+ }
72
+ const mutexAttachState = fpRet.database.ledger.ctx.get("UseVibes.Mutex");
73
+ const [attachState, setAttachState] = useState({ state: "detached" });
74
+ const doAttach = useCallback(( /* in future we will be able to override defVibesCtx */ /* in future we will be able to override defVibesCtx */) => {
75
+ if (!vibeCtx.sessionReady()) {
76
+ console.error("Session not ready for attach");
77
+ setAttachState({ state: "error", error: new Error("Session not ready for attach") });
78
78
  }
79
- const auth = {
80
- type: 'clerk',
81
- token,
82
- };
83
- const apiUrl = 'https://connect.fireproof.direct/api';
84
- const response = await fetch(apiUrl, {
85
- method: 'PUT',
86
- headers: {
87
- 'Content-Type': 'application/json',
88
- Accept: 'application/json',
89
- },
90
- body: JSON.stringify({
91
- type: 'reqShareWithUser',
92
- auth: auth,
93
- email: options.email,
94
- role: options.role || 'member',
95
- right: options.right || 'read',
96
- }),
79
+ setAttachState({ state: "attaching" });
80
+ mutexAttachState.once(() => {
81
+ vibeCtx.dashApi.ensureUser({}).then((rUser) => {
82
+ if (rUser.isErr()) {
83
+ console.error("Failed to ensure user for attach:", rUser);
84
+ setAttachState({ state: "error", error: rUser.Err() });
85
+ return;
86
+ }
87
+ const user = rUser.unwrap();
88
+ console.log("Ensured user for attach:", user);
89
+ });
90
+ console.log("attach invoked", defVibesCtx());
91
+ fpRet.database
92
+ .attach(toCloud({
93
+ env: defVibesCtx().env,
94
+ strategy: defVibesCtx().fpCloudStrategie(),
95
+ }))
96
+ .then((at) => {
97
+ console.log("Database attached");
98
+ setAttachState({ state: "attached", attach: at });
99
+ })
100
+ .catch((err) => {
101
+ console.error("Database attach failed:", err);
102
+ setAttachState({ state: "error", error: err });
103
+ });
97
104
  });
98
- if (!response.ok) {
99
- const errorText = await response.text();
100
- throw new Error(`Share failed: HTTP ${response.status} ${response.statusText}: ${errorText}`);
101
- }
102
- const shareData = (await response.json());
103
- return {
104
- success: shareData.success,
105
- email: shareData.email,
106
- role: shareData.role,
107
- right: shareData.right,
108
- message: shareData.message || 'User added to ledger successfully',
109
- };
110
- }, [dbName, result.attach]);
111
- useEffect(() => {
112
- if (typeof window === 'undefined')
113
- return;
114
- const handleShareRequest = async (event) => {
115
- const customEvent = event;
116
- const { email, role = 'member', right = 'read', token } = customEvent.detail || {};
117
- if (!email) {
118
- const error = new Error('vibes-share-request requires email in event detail');
119
- document.dispatchEvent(new CustomEvent('vibes-share-error', {
120
- detail: { error, originalEvent: event },
121
- bubbles: true,
122
- }));
123
- return;
124
- }
125
- if (!token) {
126
- const error = new Error('vibes-share-request requires token in event detail');
127
- document.dispatchEvent(new CustomEvent('vibes-share-error', {
128
- detail: { error, originalEvent: event },
129
- bubbles: true,
130
- }));
131
- return;
132
- }
133
- try {
134
- const result = await share({ email, role, right, token });
135
- document.dispatchEvent(new CustomEvent('vibes-share-success', {
136
- detail: { ...result, originalEvent: event },
137
- bubbles: true,
138
- }));
139
- }
140
- catch (error) {
141
- document.dispatchEvent(new CustomEvent('vibes-share-error', {
142
- detail: { error, originalEvent: event },
143
- bubbles: true,
144
- }));
145
- }
146
- };
147
- document.addEventListener('vibes-share-request', handleShareRequest);
148
- return () => {
149
- document.removeEventListener('vibes-share-request', handleShareRequest);
150
- };
151
- }, [share]);
152
- useEffect(() => {
153
- if (typeof window === 'undefined')
105
+ }, []);
106
+ const doDetach = useCallback(() => {
107
+ if (attachState.state !== "attached") {
154
108
  return;
155
- if (!syncEnabledInstances.has(dbName)) {
156
- syncEnabledInstances.set(dbName, new Set());
157
109
  }
158
- const instanceSet = syncEnabledInstances.get(dbName);
159
- if (!instanceSet)
160
- return;
161
- if (syncEnabled) {
162
- instanceSet.add(instanceId);
110
+ console.log("doDetach invoked");
111
+ setAttachState({ ...attachState, state: "detaching" });
112
+ mutexAttachState.reset(() => {
113
+ attachState.attach
114
+ ?.detach()
115
+ .then(() => {
116
+ console.log("Database detached");
117
+ setAttachState({ state: "detached" });
118
+ })
119
+ .catch((err) => {
120
+ console.error("Database detach failed:", err);
121
+ setAttachState({ state: "error", error: err });
122
+ });
123
+ });
124
+ }, []);
125
+ useEffect(() => {
126
+ if (vibeCtx.sessionReady()) {
127
+ doAttach();
163
128
  }
164
129
  else {
165
- instanceSet.delete(instanceId);
130
+ doDetach();
166
131
  }
167
- updateBodyClass();
168
- return () => {
169
- const currentInstanceSet = syncEnabledInstances.get(dbName);
170
- if (currentInstanceSet) {
171
- currentInstanceSet.delete(instanceId);
172
- if (currentInstanceSet.size === 0) {
173
- syncEnabledInstances.delete(dbName);
174
- }
175
- updateBodyClass();
176
- }
177
- };
178
- }, [syncEnabled, dbName, instanceId]);
132
+ });
179
133
  return {
180
- ...result,
181
- enableSync,
182
- disableSync,
183
- syncEnabled,
184
- share,
134
+ ...fpRet,
135
+ doAttach,
136
+ doDetach,
137
+ attachState,
185
138
  };
186
139
  }
187
- import { callAI } from 'call-ai';
188
140
  export { callAI, callAI as callAi };
189
- export { default as ImgGen } from './components/ImgGen.js';
190
- export { ControlsBar } from './components/ControlsBar.js';
191
- export { PromptBar } from './components/PromptBar.js';
192
- export { hashInput, useImageGen } from './hooks/image-gen/index.js';
193
- export { useThemeDetection } from './hooks/useThemeDetection.js';
194
- export { useMobile } from './hooks/useMobile.js';
195
- export { defaultClasses } from './utils/style-utils.js';
196
- export { base64ToFile } from './utils/base64.js';
197
- export { ImgGenDisplay } from './components/ImgGenUtils/ImgGenDisplay.js';
198
- export { ImgGenDisplayPlaceholder } from './components/ImgGenUtils/ImgGenDisplayPlaceholder.js';
199
- export { ImgGenModal } from './components/ImgGenUtils/ImgGenModal.js';
200
- export { ImageOverlay } from './components/ImgGenUtils/overlays/ImageOverlay.js';
201
- export { addNewVersion, MODULE_STATE } from './hooks/image-gen/utils.js';
202
- export { useVibes } from './hooks/vibes-gen/index.js';
203
- export { getAppSlug, getInstanceId, getFullAppIdentifier, isDevelopmentEnvironment, isProductionEnvironment, generateRandomInstanceId, generateFreshDataUrl, generateRemixUrl, generateInstallId, } from './utils/appSlug.js';
204
- export { VibeContextProvider, useVibeContext, VibeMetadataValidationError, VIBE_METADATA_ERROR_CODES, validateVibeMetadata, } from './contexts/VibeContext.js';
141
+ export { default as ImgGen } from "./components/ImgGen.js";
142
+ export { ControlsBar } from "./components/ControlsBar.js";
143
+ export { PromptBar } from "./components/PromptBar.js";
144
+ export { hashInput, useImageGen } from "./hooks/image-gen/index.js";
145
+ export { useThemeDetection } from "./hooks/useThemeDetection.js";
146
+ export { useMobile } from "./hooks/useMobile.js";
147
+ export { defaultClasses } from "./utils/style-utils.js";
148
+ export { base64ToFile } from "./utils/base64.js";
149
+ export { constructVibesDatabaseName } from "./utils/databaseName.js";
150
+ export { ImgGenDisplay } from "./components/ImgGenUtils/ImgGenDisplay.js";
151
+ export { ImgGenDisplayPlaceholder } from "./components/ImgGenUtils/ImgGenDisplayPlaceholder.js";
152
+ export { ImgGenModal } from "./components/ImgGenUtils/ImgGenModal.js";
153
+ export { ImageOverlay } from "./components/ImgGenUtils/overlays/ImageOverlay.js";
154
+ export { addNewVersion, MODULE_STATE } from "./hooks/image-gen/utils.js";
155
+ export { useVibes } from "./hooks/vibes-gen/index.js";
156
+ export { getAppSlug, getInstanceId, getFullAppIdentifier, isDevelopmentEnvironment, isProductionEnvironment, generateRandomInstanceId, generateFreshDataUrl, generateRemixUrl, generateInstallId, } from "./utils/appSlug.js";
157
+ export { VibeContextProvider, useVibeContext, VibeMetadataValidationError } from "./contexts/VibeContext.js";
205
158
  //# sourceMappingURL=index.js.map