@reverbia/sdk 1.0.0-next.20251202130234 → 1.0.0-next.20251202225102
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/dist/react/index.cjs +94 -0
- package/dist/react/index.d.mts +127 -1
- package/dist/react/index.d.ts +127 -1
- package/dist/react/index.mjs +93 -0
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -46680,6 +46680,7 @@ __export(index_exports, {
|
|
|
46680
46680
|
selectTool: () => selectTool,
|
|
46681
46681
|
useChat: () => useChat,
|
|
46682
46682
|
useEncryption: () => useEncryption,
|
|
46683
|
+
useImageGeneration: () => useImageGeneration,
|
|
46683
46684
|
useMemory: () => useMemory,
|
|
46684
46685
|
useModels: () => useModels
|
|
46685
46686
|
});
|
|
@@ -48430,6 +48431,16 @@ var postApiV1Embeddings = (options) => {
|
|
|
48430
48431
|
}
|
|
48431
48432
|
});
|
|
48432
48433
|
};
|
|
48434
|
+
var postApiV1ImagesGenerations = (options) => {
|
|
48435
|
+
return (options.client ?? client).post({
|
|
48436
|
+
url: "/api/v1/images/generations",
|
|
48437
|
+
...options,
|
|
48438
|
+
headers: {
|
|
48439
|
+
"Content-Type": "application/json",
|
|
48440
|
+
...options.headers
|
|
48441
|
+
}
|
|
48442
|
+
});
|
|
48443
|
+
};
|
|
48433
48444
|
var getApiV1Models = (options) => {
|
|
48434
48445
|
return (options?.client ?? client).get({
|
|
48435
48446
|
url: "/api/v1/models",
|
|
@@ -48913,6 +48924,88 @@ function useModels(options = {}) {
|
|
|
48913
48924
|
};
|
|
48914
48925
|
}
|
|
48915
48926
|
|
|
48927
|
+
// src/react/useImageGeneration.ts
|
|
48928
|
+
var import_react5 = require("react");
|
|
48929
|
+
function useImageGeneration(options = {}) {
|
|
48930
|
+
const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
|
|
48931
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
48932
|
+
const abortControllerRef = (0, import_react5.useRef)(null);
|
|
48933
|
+
(0, import_react5.useEffect)(() => {
|
|
48934
|
+
return () => {
|
|
48935
|
+
if (abortControllerRef.current) {
|
|
48936
|
+
abortControllerRef.current.abort();
|
|
48937
|
+
abortControllerRef.current = null;
|
|
48938
|
+
}
|
|
48939
|
+
};
|
|
48940
|
+
}, []);
|
|
48941
|
+
const stop = (0, import_react5.useCallback)(() => {
|
|
48942
|
+
if (abortControllerRef.current) {
|
|
48943
|
+
abortControllerRef.current.abort();
|
|
48944
|
+
abortControllerRef.current = null;
|
|
48945
|
+
}
|
|
48946
|
+
}, []);
|
|
48947
|
+
const generateImage = (0, import_react5.useCallback)(
|
|
48948
|
+
async (args) => {
|
|
48949
|
+
if (abortControllerRef.current) {
|
|
48950
|
+
abortControllerRef.current.abort();
|
|
48951
|
+
}
|
|
48952
|
+
const abortController = new AbortController();
|
|
48953
|
+
abortControllerRef.current = abortController;
|
|
48954
|
+
setIsLoading(true);
|
|
48955
|
+
try {
|
|
48956
|
+
if (!getToken) {
|
|
48957
|
+
throw new Error("Token getter function is required.");
|
|
48958
|
+
}
|
|
48959
|
+
const token = await getToken();
|
|
48960
|
+
if (!token) {
|
|
48961
|
+
throw new Error("No access token available.");
|
|
48962
|
+
}
|
|
48963
|
+
const response = await postApiV1ImagesGenerations({
|
|
48964
|
+
baseUrl,
|
|
48965
|
+
body: args,
|
|
48966
|
+
headers: {
|
|
48967
|
+
Authorization: `Bearer ${token}`
|
|
48968
|
+
},
|
|
48969
|
+
signal: abortController.signal
|
|
48970
|
+
});
|
|
48971
|
+
if (response.error) {
|
|
48972
|
+
const errorMsg = response.error.error || "Failed to generate image";
|
|
48973
|
+
throw new Error(errorMsg);
|
|
48974
|
+
}
|
|
48975
|
+
if (!response.data) {
|
|
48976
|
+
throw new Error("No data received from image generation API");
|
|
48977
|
+
}
|
|
48978
|
+
const result = response.data;
|
|
48979
|
+
if (onFinish) {
|
|
48980
|
+
onFinish(result);
|
|
48981
|
+
}
|
|
48982
|
+
return { data: result, error: null };
|
|
48983
|
+
} catch (err) {
|
|
48984
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
48985
|
+
return { data: null, error: "Request aborted" };
|
|
48986
|
+
}
|
|
48987
|
+
const errorMsg = err instanceof Error ? err.message : "Failed to generate image.";
|
|
48988
|
+
const errorObj = err instanceof Error ? err : new Error(errorMsg);
|
|
48989
|
+
if (onError) {
|
|
48990
|
+
onError(errorObj);
|
|
48991
|
+
}
|
|
48992
|
+
return { data: null, error: errorMsg };
|
|
48993
|
+
} finally {
|
|
48994
|
+
if (abortControllerRef.current === abortController) {
|
|
48995
|
+
setIsLoading(false);
|
|
48996
|
+
abortControllerRef.current = null;
|
|
48997
|
+
}
|
|
48998
|
+
}
|
|
48999
|
+
},
|
|
49000
|
+
[getToken, baseUrl, onFinish, onError]
|
|
49001
|
+
);
|
|
49002
|
+
return {
|
|
49003
|
+
isLoading,
|
|
49004
|
+
generateImage,
|
|
49005
|
+
stop
|
|
49006
|
+
};
|
|
49007
|
+
}
|
|
49008
|
+
|
|
48916
49009
|
// src/lib/memory/chat.ts
|
|
48917
49010
|
var formatMemoriesForChat = (memories, format = "compact") => {
|
|
48918
49011
|
if (memories.length === 0) {
|
|
@@ -48980,6 +49073,7 @@ var extractConversationContext = (messages, maxMessages = 3) => {
|
|
|
48980
49073
|
selectTool,
|
|
48981
49074
|
useChat,
|
|
48982
49075
|
useEncryption,
|
|
49076
|
+
useImageGeneration,
|
|
48983
49077
|
useMemory,
|
|
48984
49078
|
useModels
|
|
48985
49079
|
});
|
package/dist/react/index.d.mts
CHANGED
|
@@ -67,6 +67,96 @@ type LlmapiChoice = {
|
|
|
67
67
|
index?: number;
|
|
68
68
|
message?: LlmapiMessage;
|
|
69
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* ExtraFields contains additional metadata such as provider/model information.
|
|
72
|
+
*/
|
|
73
|
+
type LlmapiImageGenerationExtraFields = {
|
|
74
|
+
/**
|
|
75
|
+
* ModelRequested is the model identifier that the client asked for.
|
|
76
|
+
*/
|
|
77
|
+
model_requested?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Provider is the gateway that serviced this request.
|
|
80
|
+
*/
|
|
81
|
+
provider?: string;
|
|
82
|
+
/**
|
|
83
|
+
* RequestType is always "image_generation".
|
|
84
|
+
*/
|
|
85
|
+
request_type?: string;
|
|
86
|
+
};
|
|
87
|
+
type LlmapiImageGenerationImage = {
|
|
88
|
+
/**
|
|
89
|
+
* B64JSON is the base64 payload for models that can only return binary.
|
|
90
|
+
*/
|
|
91
|
+
b64_json?: string;
|
|
92
|
+
/**
|
|
93
|
+
* URL is the signed URL to download the image.
|
|
94
|
+
*/
|
|
95
|
+
url?: string;
|
|
96
|
+
};
|
|
97
|
+
type LlmapiImageGenerationRequest = {
|
|
98
|
+
/**
|
|
99
|
+
* Model is the model identifier to use for generation (e.g., "gpt-image-1").
|
|
100
|
+
*/
|
|
101
|
+
model?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Prompt is the text description of the desired image.
|
|
104
|
+
*/
|
|
105
|
+
prompt?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Quality targets a quality preset (e.g., "auto", "high").
|
|
108
|
+
*/
|
|
109
|
+
quality?: string;
|
|
110
|
+
/**
|
|
111
|
+
* ResponseFormat controls how the generated image is returned (e.g., "url" or "b64_json").
|
|
112
|
+
*/
|
|
113
|
+
response_format?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Size controls the dimensions of the generated image (e.g., "1024x1024").
|
|
116
|
+
*/
|
|
117
|
+
size?: string;
|
|
118
|
+
};
|
|
119
|
+
type LlmapiImageGenerationResponse = {
|
|
120
|
+
/**
|
|
121
|
+
* Created is the Unix timestamp when the image was generated.
|
|
122
|
+
*/
|
|
123
|
+
created?: number;
|
|
124
|
+
extra_fields?: LlmapiImageGenerationExtraFields;
|
|
125
|
+
/**
|
|
126
|
+
* Images contains the generated images.
|
|
127
|
+
*/
|
|
128
|
+
images?: Array<LlmapiImageGenerationImage>;
|
|
129
|
+
/**
|
|
130
|
+
* Model is the model identifier that generated the image.
|
|
131
|
+
*/
|
|
132
|
+
model?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Provider is the gateway that produced the image.
|
|
135
|
+
*/
|
|
136
|
+
provider?: string;
|
|
137
|
+
usage?: LlmapiImageGenerationUsage;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Usage documents token usage (when available).
|
|
141
|
+
*/
|
|
142
|
+
type LlmapiImageGenerationUsage = {
|
|
143
|
+
/**
|
|
144
|
+
* CostMicroUSD is the inference cost for this image generation request
|
|
145
|
+
*/
|
|
146
|
+
cost_micro_usd?: number;
|
|
147
|
+
/**
|
|
148
|
+
* InputTokens is the number of tokens sent in the prompt.
|
|
149
|
+
*/
|
|
150
|
+
input_tokens?: number;
|
|
151
|
+
/**
|
|
152
|
+
* OutputTokens is the number of tokens returned by the model.
|
|
153
|
+
*/
|
|
154
|
+
output_tokens?: number;
|
|
155
|
+
/**
|
|
156
|
+
* TotalTokens is the total number of tokens consumed.
|
|
157
|
+
*/
|
|
158
|
+
total_tokens?: number;
|
|
159
|
+
};
|
|
70
160
|
/**
|
|
71
161
|
* Message is the generated message
|
|
72
162
|
*/
|
|
@@ -554,6 +644,42 @@ type UseModelsResult = {
|
|
|
554
644
|
*/
|
|
555
645
|
declare function useModels(options?: UseModelsOptions): UseModelsResult;
|
|
556
646
|
|
|
647
|
+
type UseImageGenerationOptions = {
|
|
648
|
+
/**
|
|
649
|
+
* Custom function to get auth token for API calls
|
|
650
|
+
*/
|
|
651
|
+
getToken?: () => Promise<string | null>;
|
|
652
|
+
/**
|
|
653
|
+
* Optional base URL for the API requests.
|
|
654
|
+
*/
|
|
655
|
+
baseUrl?: string;
|
|
656
|
+
/**
|
|
657
|
+
* Callback function to be called when the generation finishes successfully.
|
|
658
|
+
*/
|
|
659
|
+
onFinish?: (response: LlmapiImageGenerationResponse) => void;
|
|
660
|
+
/**
|
|
661
|
+
* Callback function to be called when an unexpected error is encountered.
|
|
662
|
+
*/
|
|
663
|
+
onError?: (error: Error) => void;
|
|
664
|
+
};
|
|
665
|
+
type GenerateImageArgs = LlmapiImageGenerationRequest;
|
|
666
|
+
type GenerateImageResult = {
|
|
667
|
+
data: LlmapiImageGenerationResponse;
|
|
668
|
+
error: null;
|
|
669
|
+
} | {
|
|
670
|
+
data: null;
|
|
671
|
+
error: string;
|
|
672
|
+
};
|
|
673
|
+
type UseImageGenerationResult = {
|
|
674
|
+
isLoading: boolean;
|
|
675
|
+
generateImage: (args: GenerateImageArgs) => Promise<GenerateImageResult>;
|
|
676
|
+
stop: () => void;
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* React hook for generating images using the LLM API.
|
|
680
|
+
*/
|
|
681
|
+
declare function useImageGeneration(options?: UseImageGenerationOptions): UseImageGenerationResult;
|
|
682
|
+
|
|
557
683
|
/**
|
|
558
684
|
* Format memories into a context string that can be included in chat messages
|
|
559
685
|
* @param memories Array of memories with similarity scores
|
|
@@ -605,4 +731,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
|
|
|
605
731
|
error?: string;
|
|
606
732
|
}>;
|
|
607
733
|
|
|
608
|
-
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useMemory, useModels };
|
|
734
|
+
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -67,6 +67,96 @@ type LlmapiChoice = {
|
|
|
67
67
|
index?: number;
|
|
68
68
|
message?: LlmapiMessage;
|
|
69
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* ExtraFields contains additional metadata such as provider/model information.
|
|
72
|
+
*/
|
|
73
|
+
type LlmapiImageGenerationExtraFields = {
|
|
74
|
+
/**
|
|
75
|
+
* ModelRequested is the model identifier that the client asked for.
|
|
76
|
+
*/
|
|
77
|
+
model_requested?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Provider is the gateway that serviced this request.
|
|
80
|
+
*/
|
|
81
|
+
provider?: string;
|
|
82
|
+
/**
|
|
83
|
+
* RequestType is always "image_generation".
|
|
84
|
+
*/
|
|
85
|
+
request_type?: string;
|
|
86
|
+
};
|
|
87
|
+
type LlmapiImageGenerationImage = {
|
|
88
|
+
/**
|
|
89
|
+
* B64JSON is the base64 payload for models that can only return binary.
|
|
90
|
+
*/
|
|
91
|
+
b64_json?: string;
|
|
92
|
+
/**
|
|
93
|
+
* URL is the signed URL to download the image.
|
|
94
|
+
*/
|
|
95
|
+
url?: string;
|
|
96
|
+
};
|
|
97
|
+
type LlmapiImageGenerationRequest = {
|
|
98
|
+
/**
|
|
99
|
+
* Model is the model identifier to use for generation (e.g., "gpt-image-1").
|
|
100
|
+
*/
|
|
101
|
+
model?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Prompt is the text description of the desired image.
|
|
104
|
+
*/
|
|
105
|
+
prompt?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Quality targets a quality preset (e.g., "auto", "high").
|
|
108
|
+
*/
|
|
109
|
+
quality?: string;
|
|
110
|
+
/**
|
|
111
|
+
* ResponseFormat controls how the generated image is returned (e.g., "url" or "b64_json").
|
|
112
|
+
*/
|
|
113
|
+
response_format?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Size controls the dimensions of the generated image (e.g., "1024x1024").
|
|
116
|
+
*/
|
|
117
|
+
size?: string;
|
|
118
|
+
};
|
|
119
|
+
type LlmapiImageGenerationResponse = {
|
|
120
|
+
/**
|
|
121
|
+
* Created is the Unix timestamp when the image was generated.
|
|
122
|
+
*/
|
|
123
|
+
created?: number;
|
|
124
|
+
extra_fields?: LlmapiImageGenerationExtraFields;
|
|
125
|
+
/**
|
|
126
|
+
* Images contains the generated images.
|
|
127
|
+
*/
|
|
128
|
+
images?: Array<LlmapiImageGenerationImage>;
|
|
129
|
+
/**
|
|
130
|
+
* Model is the model identifier that generated the image.
|
|
131
|
+
*/
|
|
132
|
+
model?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Provider is the gateway that produced the image.
|
|
135
|
+
*/
|
|
136
|
+
provider?: string;
|
|
137
|
+
usage?: LlmapiImageGenerationUsage;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Usage documents token usage (when available).
|
|
141
|
+
*/
|
|
142
|
+
type LlmapiImageGenerationUsage = {
|
|
143
|
+
/**
|
|
144
|
+
* CostMicroUSD is the inference cost for this image generation request
|
|
145
|
+
*/
|
|
146
|
+
cost_micro_usd?: number;
|
|
147
|
+
/**
|
|
148
|
+
* InputTokens is the number of tokens sent in the prompt.
|
|
149
|
+
*/
|
|
150
|
+
input_tokens?: number;
|
|
151
|
+
/**
|
|
152
|
+
* OutputTokens is the number of tokens returned by the model.
|
|
153
|
+
*/
|
|
154
|
+
output_tokens?: number;
|
|
155
|
+
/**
|
|
156
|
+
* TotalTokens is the total number of tokens consumed.
|
|
157
|
+
*/
|
|
158
|
+
total_tokens?: number;
|
|
159
|
+
};
|
|
70
160
|
/**
|
|
71
161
|
* Message is the generated message
|
|
72
162
|
*/
|
|
@@ -554,6 +644,42 @@ type UseModelsResult = {
|
|
|
554
644
|
*/
|
|
555
645
|
declare function useModels(options?: UseModelsOptions): UseModelsResult;
|
|
556
646
|
|
|
647
|
+
type UseImageGenerationOptions = {
|
|
648
|
+
/**
|
|
649
|
+
* Custom function to get auth token for API calls
|
|
650
|
+
*/
|
|
651
|
+
getToken?: () => Promise<string | null>;
|
|
652
|
+
/**
|
|
653
|
+
* Optional base URL for the API requests.
|
|
654
|
+
*/
|
|
655
|
+
baseUrl?: string;
|
|
656
|
+
/**
|
|
657
|
+
* Callback function to be called when the generation finishes successfully.
|
|
658
|
+
*/
|
|
659
|
+
onFinish?: (response: LlmapiImageGenerationResponse) => void;
|
|
660
|
+
/**
|
|
661
|
+
* Callback function to be called when an unexpected error is encountered.
|
|
662
|
+
*/
|
|
663
|
+
onError?: (error: Error) => void;
|
|
664
|
+
};
|
|
665
|
+
type GenerateImageArgs = LlmapiImageGenerationRequest;
|
|
666
|
+
type GenerateImageResult = {
|
|
667
|
+
data: LlmapiImageGenerationResponse;
|
|
668
|
+
error: null;
|
|
669
|
+
} | {
|
|
670
|
+
data: null;
|
|
671
|
+
error: string;
|
|
672
|
+
};
|
|
673
|
+
type UseImageGenerationResult = {
|
|
674
|
+
isLoading: boolean;
|
|
675
|
+
generateImage: (args: GenerateImageArgs) => Promise<GenerateImageResult>;
|
|
676
|
+
stop: () => void;
|
|
677
|
+
};
|
|
678
|
+
/**
|
|
679
|
+
* React hook for generating images using the LLM API.
|
|
680
|
+
*/
|
|
681
|
+
declare function useImageGeneration(options?: UseImageGenerationOptions): UseImageGenerationResult;
|
|
682
|
+
|
|
557
683
|
/**
|
|
558
684
|
* Format memories into a context string that can be included in chat messages
|
|
559
685
|
* @param memories Array of memories with similarity scores
|
|
@@ -605,4 +731,4 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
|
|
|
605
731
|
error?: string;
|
|
606
732
|
}>;
|
|
607
733
|
|
|
608
|
-
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useMemory, useModels };
|
|
734
|
+
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useImageGeneration, useMemory, useModels };
|
package/dist/react/index.mjs
CHANGED
|
@@ -1745,6 +1745,16 @@ var postApiV1Embeddings = (options) => {
|
|
|
1745
1745
|
}
|
|
1746
1746
|
});
|
|
1747
1747
|
};
|
|
1748
|
+
var postApiV1ImagesGenerations = (options) => {
|
|
1749
|
+
return (options.client ?? client).post({
|
|
1750
|
+
url: "/api/v1/images/generations",
|
|
1751
|
+
...options,
|
|
1752
|
+
headers: {
|
|
1753
|
+
"Content-Type": "application/json",
|
|
1754
|
+
...options.headers
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1757
|
+
};
|
|
1748
1758
|
var getApiV1Models = (options) => {
|
|
1749
1759
|
return (options?.client ?? client).get({
|
|
1750
1760
|
url: "/api/v1/models",
|
|
@@ -2228,6 +2238,88 @@ function useModels(options = {}) {
|
|
|
2228
2238
|
};
|
|
2229
2239
|
}
|
|
2230
2240
|
|
|
2241
|
+
// src/react/useImageGeneration.ts
|
|
2242
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useRef as useRef5, useState as useState3 } from "react";
|
|
2243
|
+
function useImageGeneration(options = {}) {
|
|
2244
|
+
const { getToken, baseUrl = BASE_URL, onFinish, onError } = options;
|
|
2245
|
+
const [isLoading, setIsLoading] = useState3(false);
|
|
2246
|
+
const abortControllerRef = useRef5(null);
|
|
2247
|
+
useEffect4(() => {
|
|
2248
|
+
return () => {
|
|
2249
|
+
if (abortControllerRef.current) {
|
|
2250
|
+
abortControllerRef.current.abort();
|
|
2251
|
+
abortControllerRef.current = null;
|
|
2252
|
+
}
|
|
2253
|
+
};
|
|
2254
|
+
}, []);
|
|
2255
|
+
const stop = useCallback4(() => {
|
|
2256
|
+
if (abortControllerRef.current) {
|
|
2257
|
+
abortControllerRef.current.abort();
|
|
2258
|
+
abortControllerRef.current = null;
|
|
2259
|
+
}
|
|
2260
|
+
}, []);
|
|
2261
|
+
const generateImage = useCallback4(
|
|
2262
|
+
async (args) => {
|
|
2263
|
+
if (abortControllerRef.current) {
|
|
2264
|
+
abortControllerRef.current.abort();
|
|
2265
|
+
}
|
|
2266
|
+
const abortController = new AbortController();
|
|
2267
|
+
abortControllerRef.current = abortController;
|
|
2268
|
+
setIsLoading(true);
|
|
2269
|
+
try {
|
|
2270
|
+
if (!getToken) {
|
|
2271
|
+
throw new Error("Token getter function is required.");
|
|
2272
|
+
}
|
|
2273
|
+
const token = await getToken();
|
|
2274
|
+
if (!token) {
|
|
2275
|
+
throw new Error("No access token available.");
|
|
2276
|
+
}
|
|
2277
|
+
const response = await postApiV1ImagesGenerations({
|
|
2278
|
+
baseUrl,
|
|
2279
|
+
body: args,
|
|
2280
|
+
headers: {
|
|
2281
|
+
Authorization: `Bearer ${token}`
|
|
2282
|
+
},
|
|
2283
|
+
signal: abortController.signal
|
|
2284
|
+
});
|
|
2285
|
+
if (response.error) {
|
|
2286
|
+
const errorMsg = response.error.error || "Failed to generate image";
|
|
2287
|
+
throw new Error(errorMsg);
|
|
2288
|
+
}
|
|
2289
|
+
if (!response.data) {
|
|
2290
|
+
throw new Error("No data received from image generation API");
|
|
2291
|
+
}
|
|
2292
|
+
const result = response.data;
|
|
2293
|
+
if (onFinish) {
|
|
2294
|
+
onFinish(result);
|
|
2295
|
+
}
|
|
2296
|
+
return { data: result, error: null };
|
|
2297
|
+
} catch (err) {
|
|
2298
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
2299
|
+
return { data: null, error: "Request aborted" };
|
|
2300
|
+
}
|
|
2301
|
+
const errorMsg = err instanceof Error ? err.message : "Failed to generate image.";
|
|
2302
|
+
const errorObj = err instanceof Error ? err : new Error(errorMsg);
|
|
2303
|
+
if (onError) {
|
|
2304
|
+
onError(errorObj);
|
|
2305
|
+
}
|
|
2306
|
+
return { data: null, error: errorMsg };
|
|
2307
|
+
} finally {
|
|
2308
|
+
if (abortControllerRef.current === abortController) {
|
|
2309
|
+
setIsLoading(false);
|
|
2310
|
+
abortControllerRef.current = null;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
},
|
|
2314
|
+
[getToken, baseUrl, onFinish, onError]
|
|
2315
|
+
);
|
|
2316
|
+
return {
|
|
2317
|
+
isLoading,
|
|
2318
|
+
generateImage,
|
|
2319
|
+
stop
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2231
2323
|
// src/lib/memory/chat.ts
|
|
2232
2324
|
var formatMemoriesForChat = (memories, format = "compact") => {
|
|
2233
2325
|
if (memories.length === 0) {
|
|
@@ -2294,6 +2386,7 @@ export {
|
|
|
2294
2386
|
selectTool,
|
|
2295
2387
|
useChat,
|
|
2296
2388
|
useEncryption,
|
|
2389
|
+
useImageGeneration,
|
|
2297
2390
|
useMemory,
|
|
2298
2391
|
useModels
|
|
2299
2392
|
};
|