@blinkdotnew/dev-sdk 2.1.6 → 2.1.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.
- package/dist/index.d.mts +9 -291
- package/dist/index.d.ts +9 -291
- package/dist/index.js +140 -444
- package/dist/index.mjs +141 -442
- package/package.json +3 -5
package/dist/index.js
CHANGED
|
@@ -7,33 +7,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
// ../core/src/platform.ts
|
|
11
|
-
function detectPlatform() {
|
|
12
|
-
if (typeof Deno !== "undefined") {
|
|
13
|
-
return "deno";
|
|
14
|
-
}
|
|
15
|
-
if (typeof process !== "undefined" && process.versions?.node) {
|
|
16
|
-
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
17
|
-
return "react-native";
|
|
18
|
-
}
|
|
19
|
-
return "node";
|
|
20
|
-
}
|
|
21
|
-
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
22
|
-
return "react-native";
|
|
23
|
-
}
|
|
24
|
-
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
25
|
-
return "web";
|
|
26
|
-
}
|
|
27
|
-
return "node";
|
|
28
|
-
}
|
|
29
|
-
var platform = detectPlatform();
|
|
30
|
-
var isWeb = platform === "web";
|
|
31
|
-
var isReactNative = platform === "react-native";
|
|
32
|
-
var isNode = platform === "node";
|
|
33
|
-
var isDeno = platform === "deno";
|
|
34
|
-
var isBrowser = isWeb || isReactNative;
|
|
35
|
-
var isServer = isNode || isDeno;
|
|
36
|
-
|
|
37
10
|
// ../core/src/storage-adapter.ts
|
|
38
11
|
var WebStorageAdapter = class {
|
|
39
12
|
getItem(key) {
|
|
@@ -119,9 +92,6 @@ var NoOpStorageAdapter = class {
|
|
|
119
92
|
}
|
|
120
93
|
};
|
|
121
94
|
function getDefaultStorageAdapter() {
|
|
122
|
-
if (isDeno) {
|
|
123
|
-
return new NoOpStorageAdapter();
|
|
124
|
-
}
|
|
125
95
|
if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
|
|
126
96
|
try {
|
|
127
97
|
localStorage.setItem("__test__", "test");
|
|
@@ -133,6 +103,28 @@ function getDefaultStorageAdapter() {
|
|
|
133
103
|
return new NoOpStorageAdapter();
|
|
134
104
|
}
|
|
135
105
|
|
|
106
|
+
// ../core/src/platform.ts
|
|
107
|
+
function detectPlatform() {
|
|
108
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
109
|
+
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
110
|
+
return "react-native";
|
|
111
|
+
}
|
|
112
|
+
return "node";
|
|
113
|
+
}
|
|
114
|
+
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
115
|
+
return "react-native";
|
|
116
|
+
}
|
|
117
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
118
|
+
return "web";
|
|
119
|
+
}
|
|
120
|
+
return "node";
|
|
121
|
+
}
|
|
122
|
+
var platform = detectPlatform();
|
|
123
|
+
var isWeb = platform === "web";
|
|
124
|
+
var isReactNative = platform === "react-native";
|
|
125
|
+
var isNode = platform === "node";
|
|
126
|
+
var isBrowser = isWeb || isReactNative;
|
|
127
|
+
|
|
136
128
|
// ../core/src/types.ts
|
|
137
129
|
var BlinkError = class extends Error {
|
|
138
130
|
constructor(message, code, status, details) {
|
|
@@ -396,44 +388,17 @@ function convertKeysToCamelCase(obj) {
|
|
|
396
388
|
return converted;
|
|
397
389
|
}
|
|
398
390
|
var HttpClient = class {
|
|
399
|
-
authUrl
|
|
400
|
-
coreUrl
|
|
391
|
+
authUrl;
|
|
392
|
+
coreUrl;
|
|
401
393
|
projectId;
|
|
402
|
-
publishableKey;
|
|
403
|
-
secretKey;
|
|
404
|
-
// Permanent, non-expiring key (like Stripe's sk_live_...)
|
|
405
394
|
getToken;
|
|
406
395
|
getValidToken;
|
|
407
396
|
constructor(config, getToken, getValidToken) {
|
|
408
397
|
this.projectId = config.projectId;
|
|
409
|
-
this.publishableKey = config.publishableKey;
|
|
410
|
-
this.secretKey = config.secretKey || config.serviceToken;
|
|
411
398
|
this.getToken = getToken;
|
|
412
399
|
this.getValidToken = getValidToken;
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (method !== "GET" && method !== "POST") return false;
|
|
416
|
-
if (path.includes("/api/analytics/")) return true;
|
|
417
|
-
if (path.includes("/api/storage/")) return true;
|
|
418
|
-
if (path.includes("/api/db/") && path.includes("/rest/v1/")) return method === "GET";
|
|
419
|
-
return false;
|
|
420
|
-
}
|
|
421
|
-
shouldSkipSecretKey(url) {
|
|
422
|
-
try {
|
|
423
|
-
const parsed = new URL(url);
|
|
424
|
-
return parsed.hostname.endsWith(".functions.blink.new");
|
|
425
|
-
} catch {
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
getAuthorizationHeader(url, token) {
|
|
430
|
-
if (this.secretKey && !this.shouldSkipSecretKey(url)) {
|
|
431
|
-
return `Bearer ${this.secretKey}`;
|
|
432
|
-
}
|
|
433
|
-
if (token) {
|
|
434
|
-
return `Bearer ${token}`;
|
|
435
|
-
}
|
|
436
|
-
return null;
|
|
400
|
+
this.authUrl = config.auth?.authUrl ?? "https://blink.new";
|
|
401
|
+
this.coreUrl = config.auth?.coreUrl ?? "https://dev.core.blink.new";
|
|
437
402
|
}
|
|
438
403
|
/**
|
|
439
404
|
* Make an authenticated request to the Blink API
|
|
@@ -441,23 +406,19 @@ var HttpClient = class {
|
|
|
441
406
|
async request(path, options = {}) {
|
|
442
407
|
const url = this.buildUrl(path, options.searchParams);
|
|
443
408
|
const token = this.getValidToken ? await this.getValidToken() : this.getToken();
|
|
444
|
-
const method = options.method || "GET";
|
|
445
409
|
const headers = {
|
|
446
410
|
"Content-Type": "application/json",
|
|
447
411
|
...options.headers
|
|
448
412
|
};
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
headers.Authorization = auth;
|
|
452
|
-
} else if (this.publishableKey && !headers["x-blink-publishable-key"] && this.shouldAttachPublishableKey(path, method)) {
|
|
453
|
-
headers["x-blink-publishable-key"] = this.publishableKey;
|
|
413
|
+
if (token) {
|
|
414
|
+
headers.Authorization = `Bearer ${token}`;
|
|
454
415
|
}
|
|
455
416
|
const requestInit = {
|
|
456
|
-
method,
|
|
417
|
+
method: options.method || "GET",
|
|
457
418
|
headers,
|
|
458
419
|
signal: options.signal
|
|
459
420
|
};
|
|
460
|
-
if (options.body && method !== "GET") {
|
|
421
|
+
if (options.body && options.method !== "GET") {
|
|
461
422
|
requestInit.body = typeof options.body === "string" ? options.body : JSON.stringify(options.body);
|
|
462
423
|
}
|
|
463
424
|
try {
|
|
@@ -611,12 +572,12 @@ var HttpClient = class {
|
|
|
611
572
|
throw new BlinkValidationError("Unsupported file type");
|
|
612
573
|
}
|
|
613
574
|
formData.append("path", filePath);
|
|
575
|
+
if (options.upsert !== void 0) {
|
|
576
|
+
formData.append("options", JSON.stringify({ upsert: options.upsert }));
|
|
577
|
+
}
|
|
614
578
|
const headers = {};
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
headers.Authorization = auth;
|
|
618
|
-
} else if (this.publishableKey && path.includes("/api/storage/") && !headers["x-blink-publishable-key"]) {
|
|
619
|
-
headers["x-blink-publishable-key"] = this.publishableKey;
|
|
579
|
+
if (token) {
|
|
580
|
+
headers.Authorization = `Bearer ${token}`;
|
|
620
581
|
}
|
|
621
582
|
try {
|
|
622
583
|
if (typeof XMLHttpRequest !== "undefined" && options.onProgress) {
|
|
@@ -717,7 +678,7 @@ var HttpClient = class {
|
|
|
717
678
|
});
|
|
718
679
|
}
|
|
719
680
|
/**
|
|
720
|
-
* Stream AI text generation
|
|
681
|
+
* Stream AI text generation with Vercel AI SDK data stream format
|
|
721
682
|
*/
|
|
722
683
|
async streamAiText(prompt, options = {}, onChunk) {
|
|
723
684
|
const url = this.buildUrl(`/api/ai/${this.projectId}/text`);
|
|
@@ -725,8 +686,9 @@ var HttpClient = class {
|
|
|
725
686
|
const headers = {
|
|
726
687
|
"Content-Type": "application/json"
|
|
727
688
|
};
|
|
728
|
-
|
|
729
|
-
|
|
689
|
+
if (token) {
|
|
690
|
+
headers.Authorization = `Bearer ${token}`;
|
|
691
|
+
}
|
|
730
692
|
const body = {
|
|
731
693
|
prompt,
|
|
732
694
|
stream: true,
|
|
@@ -746,7 +708,7 @@ var HttpClient = class {
|
|
|
746
708
|
if (!response.body) {
|
|
747
709
|
throw new BlinkNetworkError("No response body for streaming");
|
|
748
710
|
}
|
|
749
|
-
return this.
|
|
711
|
+
return this.parseDataStream(response.body, onChunk);
|
|
750
712
|
} catch (error) {
|
|
751
713
|
if (error instanceof BlinkError) {
|
|
752
714
|
throw error;
|
|
@@ -771,7 +733,7 @@ var HttpClient = class {
|
|
|
771
733
|
});
|
|
772
734
|
}
|
|
773
735
|
/**
|
|
774
|
-
* Stream AI object generation
|
|
736
|
+
* Stream AI object generation with Vercel AI SDK data stream format
|
|
775
737
|
*/
|
|
776
738
|
async streamAiObject(prompt, options = {}, onPartial) {
|
|
777
739
|
const url = this.buildUrl(`/api/ai/${this.projectId}/object`);
|
|
@@ -779,8 +741,9 @@ var HttpClient = class {
|
|
|
779
741
|
const headers = {
|
|
780
742
|
"Content-Type": "application/json"
|
|
781
743
|
};
|
|
782
|
-
|
|
783
|
-
|
|
744
|
+
if (token) {
|
|
745
|
+
headers.Authorization = `Bearer ${token}`;
|
|
746
|
+
}
|
|
784
747
|
const body = {
|
|
785
748
|
prompt,
|
|
786
749
|
stream: true,
|
|
@@ -800,35 +763,7 @@ var HttpClient = class {
|
|
|
800
763
|
if (!response.body) {
|
|
801
764
|
throw new BlinkNetworkError("No response body for streaming");
|
|
802
765
|
}
|
|
803
|
-
|
|
804
|
-
const decoder = new TextDecoder();
|
|
805
|
-
let buffer = "";
|
|
806
|
-
let latestObject = {};
|
|
807
|
-
try {
|
|
808
|
-
while (true) {
|
|
809
|
-
const { done, value } = await reader.read();
|
|
810
|
-
if (done) break;
|
|
811
|
-
const chunk = decoder.decode(value, { stream: true });
|
|
812
|
-
buffer += chunk;
|
|
813
|
-
try {
|
|
814
|
-
const parsed = JSON.parse(buffer);
|
|
815
|
-
latestObject = parsed;
|
|
816
|
-
if (onPartial) {
|
|
817
|
-
onPartial(parsed);
|
|
818
|
-
}
|
|
819
|
-
} catch {
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
if (buffer) {
|
|
823
|
-
try {
|
|
824
|
-
latestObject = JSON.parse(buffer);
|
|
825
|
-
} catch {
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
return { object: latestObject };
|
|
829
|
-
} finally {
|
|
830
|
-
reader.releaseLock();
|
|
831
|
-
}
|
|
766
|
+
return this.parseDataStream(response.body, void 0, onPartial);
|
|
832
767
|
} catch (error) {
|
|
833
768
|
if (error instanceof BlinkError) {
|
|
834
769
|
throw error;
|
|
@@ -885,17 +820,6 @@ var HttpClient = class {
|
|
|
885
820
|
signal
|
|
886
821
|
});
|
|
887
822
|
}
|
|
888
|
-
async aiVideo(prompt, options = {}) {
|
|
889
|
-
const { signal, ...body } = options;
|
|
890
|
-
return this.request(`/api/ai/${this.projectId}/video`, {
|
|
891
|
-
method: "POST",
|
|
892
|
-
body: {
|
|
893
|
-
prompt,
|
|
894
|
-
...body
|
|
895
|
-
},
|
|
896
|
-
signal
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
823
|
/**
|
|
900
824
|
* Data-specific requests
|
|
901
825
|
*/
|
|
@@ -937,38 +861,6 @@ var HttpClient = class {
|
|
|
937
861
|
async dataSearch(projectId, request) {
|
|
938
862
|
return this.post(`/api/data/${projectId}/search`, request);
|
|
939
863
|
}
|
|
940
|
-
/**
|
|
941
|
-
* Connector requests
|
|
942
|
-
*/
|
|
943
|
-
formatProviderForPath(provider) {
|
|
944
|
-
return provider.replace("_", "-");
|
|
945
|
-
}
|
|
946
|
-
async connectorStatus(provider) {
|
|
947
|
-
return this.request(`/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}/status`, {
|
|
948
|
-
method: "GET"
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
async connectorExecute(provider, request) {
|
|
952
|
-
const path = request.method.startsWith("/") ? request.method : `/${request.method}`;
|
|
953
|
-
const url = `/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}${path}`;
|
|
954
|
-
const method = (request.http_method || "GET").toUpperCase();
|
|
955
|
-
if (method === "GET") {
|
|
956
|
-
return this.request(url, {
|
|
957
|
-
method: "GET",
|
|
958
|
-
searchParams: request.params
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
return this.request(url, {
|
|
962
|
-
method,
|
|
963
|
-
body: request.params || {}
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
async connectorSaveApiKey(provider, request) {
|
|
967
|
-
return this.request(`/api/connectors/${this.formatProviderForPath(provider)}/${this.projectId}/api-key`, {
|
|
968
|
-
method: "POST",
|
|
969
|
-
body: request
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
864
|
/**
|
|
973
865
|
* Realtime-specific requests
|
|
974
866
|
*/
|
|
@@ -1034,94 +926,93 @@ var HttpClient = class {
|
|
|
1034
926
|
}
|
|
1035
927
|
}
|
|
1036
928
|
/**
|
|
1037
|
-
* Parse Vercel AI SDK
|
|
1038
|
-
*
|
|
929
|
+
* Parse Vercel AI SDK data stream format
|
|
930
|
+
* Handles text chunks (0:"text"), partial objects (2:[...]), and metadata (d:, e:)
|
|
1039
931
|
*/
|
|
1040
|
-
async
|
|
932
|
+
async parseDataStream(body, onChunk, onPartial) {
|
|
1041
933
|
const reader = body.getReader();
|
|
1042
934
|
const decoder = new TextDecoder();
|
|
1043
|
-
const finalResult = {
|
|
1044
|
-
text: "",
|
|
1045
|
-
toolCalls: [],
|
|
1046
|
-
toolResults: [],
|
|
1047
|
-
sources: [],
|
|
1048
|
-
files: [],
|
|
1049
|
-
reasoning: []
|
|
1050
|
-
};
|
|
1051
935
|
let buffer = "";
|
|
936
|
+
let finalResult = {};
|
|
1052
937
|
try {
|
|
1053
938
|
while (true) {
|
|
1054
939
|
const { done, value } = await reader.read();
|
|
1055
940
|
if (done) break;
|
|
1056
941
|
buffer += decoder.decode(value, { stream: true });
|
|
1057
|
-
const lines = buffer.split(
|
|
942
|
+
const lines = buffer.split(/\r?\n/);
|
|
1058
943
|
buffer = lines.pop() || "";
|
|
1059
944
|
for (const line of lines) {
|
|
1060
945
|
if (!line.trim()) continue;
|
|
1061
|
-
if (line === "[DONE]") {
|
|
1062
|
-
continue;
|
|
1063
|
-
}
|
|
1064
|
-
if (!line.startsWith("data: ")) continue;
|
|
1065
946
|
try {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
947
|
+
if (line.startsWith("f:")) {
|
|
948
|
+
const metadata = JSON.parse(line.slice(2));
|
|
949
|
+
finalResult.messageId = metadata.messageId;
|
|
950
|
+
} else if (line.startsWith("0:")) {
|
|
951
|
+
const textChunk = JSON.parse(line.slice(2));
|
|
952
|
+
if (onChunk) {
|
|
953
|
+
onChunk(textChunk);
|
|
954
|
+
}
|
|
955
|
+
finalResult.text = (finalResult.text || "") + textChunk;
|
|
956
|
+
} else if (line.startsWith("2:")) {
|
|
957
|
+
const data = JSON.parse(line.slice(2));
|
|
958
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
959
|
+
const item = data[0];
|
|
960
|
+
if (typeof item === "string") {
|
|
961
|
+
finalResult.status = item;
|
|
962
|
+
} else if (typeof item === "object") {
|
|
963
|
+
if (onPartial) {
|
|
964
|
+
onPartial(item);
|
|
965
|
+
}
|
|
966
|
+
finalResult.object = item;
|
|
1075
967
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
968
|
+
}
|
|
969
|
+
} else if (line.startsWith("d:")) {
|
|
970
|
+
const metadata = JSON.parse(line.slice(2));
|
|
971
|
+
if (metadata.usage) {
|
|
972
|
+
finalResult.usage = metadata.usage;
|
|
973
|
+
}
|
|
974
|
+
if (metadata.finishReason) {
|
|
975
|
+
finalResult.finishReason = metadata.finishReason;
|
|
976
|
+
}
|
|
977
|
+
} else if (line.startsWith("e:")) {
|
|
978
|
+
const errorData = JSON.parse(line.slice(2));
|
|
979
|
+
finalResult.error = errorData;
|
|
980
|
+
}
|
|
981
|
+
} catch (error) {
|
|
982
|
+
console.warn("Failed to parse stream line:", line, error);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (buffer.trim()) {
|
|
987
|
+
try {
|
|
988
|
+
if (buffer.startsWith("0:")) {
|
|
989
|
+
const textChunk = JSON.parse(buffer.slice(2));
|
|
990
|
+
if (onChunk) {
|
|
991
|
+
onChunk(textChunk);
|
|
992
|
+
}
|
|
993
|
+
finalResult.text = (finalResult.text || "") + textChunk;
|
|
994
|
+
} else if (buffer.startsWith("2:")) {
|
|
995
|
+
const data = JSON.parse(buffer.slice(2));
|
|
996
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
997
|
+
const item = data[0];
|
|
998
|
+
if (typeof item === "object") {
|
|
999
|
+
if (onPartial) {
|
|
1000
|
+
onPartial(item);
|
|
1079
1001
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
case "tool-result":
|
|
1091
|
-
finalResult.toolResults.push({
|
|
1092
|
-
toolCallId: part.toolCallId,
|
|
1093
|
-
toolName: part.toolName,
|
|
1094
|
-
result: part.result
|
|
1095
|
-
});
|
|
1096
|
-
break;
|
|
1097
|
-
case "source-url":
|
|
1098
|
-
finalResult.sources.push({
|
|
1099
|
-
id: part.id,
|
|
1100
|
-
url: part.url,
|
|
1101
|
-
title: part.title
|
|
1102
|
-
});
|
|
1103
|
-
break;
|
|
1104
|
-
case "file":
|
|
1105
|
-
finalResult.files.push(part.file);
|
|
1106
|
-
break;
|
|
1107
|
-
case "reasoning":
|
|
1108
|
-
finalResult.reasoning.push(part.content);
|
|
1109
|
-
break;
|
|
1110
|
-
case "finish":
|
|
1111
|
-
finalResult.finishReason = part.finishReason;
|
|
1112
|
-
finalResult.usage = part.usage;
|
|
1113
|
-
if (part.response) finalResult.response = part.response;
|
|
1114
|
-
break;
|
|
1115
|
-
case "error":
|
|
1116
|
-
finalResult.error = part.error;
|
|
1117
|
-
throw new Error(part.error);
|
|
1118
|
-
case "data":
|
|
1119
|
-
if (!finalResult.customData) finalResult.customData = [];
|
|
1120
|
-
finalResult.customData.push(part.value);
|
|
1121
|
-
break;
|
|
1002
|
+
finalResult.object = item;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
} else if (buffer.startsWith("d:")) {
|
|
1006
|
+
const metadata = JSON.parse(buffer.slice(2));
|
|
1007
|
+
if (metadata.usage) {
|
|
1008
|
+
finalResult.usage = metadata.usage;
|
|
1009
|
+
}
|
|
1010
|
+
if (metadata.finishReason) {
|
|
1011
|
+
finalResult.finishReason = metadata.finishReason;
|
|
1122
1012
|
}
|
|
1123
|
-
} catch (e) {
|
|
1124
1013
|
}
|
|
1014
|
+
} catch (error) {
|
|
1015
|
+
console.warn("Failed to parse final buffer:", buffer, error);
|
|
1125
1016
|
}
|
|
1126
1017
|
}
|
|
1127
1018
|
return finalResult;
|
|
@@ -1289,13 +1180,13 @@ var BlinkAuth = class {
|
|
|
1289
1180
|
mode: "managed",
|
|
1290
1181
|
// Default mode
|
|
1291
1182
|
authUrl: "https://blink.new",
|
|
1292
|
-
coreUrl: "https://core.blink.new",
|
|
1183
|
+
coreUrl: "https://dev.core.blink.new",
|
|
1293
1184
|
detectSessionInUrl: true,
|
|
1294
1185
|
// Default to true for web compatibility
|
|
1295
1186
|
...config.auth
|
|
1296
1187
|
};
|
|
1297
1188
|
this.authUrl = this.authConfig.authUrl || "https://blink.new";
|
|
1298
|
-
this.coreUrl = this.authConfig.coreUrl || "https://core.blink.new";
|
|
1189
|
+
this.coreUrl = this.authConfig.coreUrl || "https://dev.core.blink.new";
|
|
1299
1190
|
const hostname = getLocationHostname();
|
|
1300
1191
|
if (hostname && this.authUrl === "https://blink.new" && (hostname === "localhost" || hostname === "127.0.0.1")) {
|
|
1301
1192
|
console.warn("\u26A0\uFE0F Using default authUrl in development. Set auth.authUrl to your app origin for headless auth endpoints to work.");
|
|
@@ -1469,7 +1360,6 @@ var BlinkAuth = class {
|
|
|
1469
1360
|
if (this.config.projectId) {
|
|
1470
1361
|
authUrl.searchParams.set("project_id", this.config.projectId);
|
|
1471
1362
|
}
|
|
1472
|
-
authUrl.searchParams.set("prompt", "select_account");
|
|
1473
1363
|
window.location.href = authUrl.toString();
|
|
1474
1364
|
}
|
|
1475
1365
|
/**
|
|
@@ -3049,11 +2939,6 @@ var BlinkAuth = class {
|
|
|
3049
2939
|
};
|
|
3050
2940
|
|
|
3051
2941
|
// src/database.ts
|
|
3052
|
-
function assertServerOnly(methodName) {
|
|
3053
|
-
if (typeof window !== "undefined") {
|
|
3054
|
-
throw new Error(`${methodName} is server-only. Use Blink CRUD methods (blink.db.<table>.*) instead.`);
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
2942
|
function camelToSnake3(str) {
|
|
3058
2943
|
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
3059
2944
|
}
|
|
@@ -3272,7 +3157,6 @@ var BlinkTable = class {
|
|
|
3272
3157
|
* Raw SQL query on this table (for advanced use cases)
|
|
3273
3158
|
*/
|
|
3274
3159
|
async sql(query, params) {
|
|
3275
|
-
assertServerOnly("blink.db.<table>.sql");
|
|
3276
3160
|
const response = await this.httpClient.dbSql(query, params);
|
|
3277
3161
|
return response.data;
|
|
3278
3162
|
}
|
|
@@ -3321,7 +3205,6 @@ var BlinkDatabase = class {
|
|
|
3321
3205
|
* Execute raw SQL query
|
|
3322
3206
|
*/
|
|
3323
3207
|
async sql(query, params) {
|
|
3324
|
-
assertServerOnly("blink.db.sql");
|
|
3325
3208
|
const response = await this.httpClient.dbSql(query, params);
|
|
3326
3209
|
return response.data;
|
|
3327
3210
|
}
|
|
@@ -3329,7 +3212,6 @@ var BlinkDatabase = class {
|
|
|
3329
3212
|
* Execute batch SQL operations
|
|
3330
3213
|
*/
|
|
3331
3214
|
async batch(statements, mode = "write") {
|
|
3332
|
-
assertServerOnly("blink.db.batch");
|
|
3333
3215
|
const response = await this.httpClient.dbBatch(statements, mode);
|
|
3334
3216
|
return response.data;
|
|
3335
3217
|
}
|
|
@@ -3392,6 +3274,7 @@ var BlinkStorageImpl = class {
|
|
|
3392
3274
|
correctedPath,
|
|
3393
3275
|
// Use corrected path with proper extension
|
|
3394
3276
|
{
|
|
3277
|
+
upsert: options.upsert,
|
|
3395
3278
|
onProgress: options.onProgress,
|
|
3396
3279
|
contentType: detectedContentType
|
|
3397
3280
|
// Pass detected content type
|
|
@@ -3411,7 +3294,7 @@ var BlinkStorageImpl = class {
|
|
|
3411
3294
|
if (error instanceof Error && "status" in error) {
|
|
3412
3295
|
const status = error.status;
|
|
3413
3296
|
if (status === 409) {
|
|
3414
|
-
throw new BlinkStorageError("File already exists.", 409);
|
|
3297
|
+
throw new BlinkStorageError("File already exists. Set upsert: true to overwrite.", 409);
|
|
3415
3298
|
}
|
|
3416
3299
|
if (status === 400) {
|
|
3417
3300
|
throw new BlinkStorageError("Invalid request parameters", 400);
|
|
@@ -3456,6 +3339,7 @@ var BlinkStorageImpl = class {
|
|
|
3456
3339
|
detectedContentType
|
|
3457
3340
|
};
|
|
3458
3341
|
} catch (error) {
|
|
3342
|
+
console.warn("File type detection failed, using original path:", error);
|
|
3459
3343
|
return {
|
|
3460
3344
|
correctedPath: originalPath,
|
|
3461
3345
|
detectedContentType: "application/octet-stream"
|
|
@@ -3845,7 +3729,13 @@ var BlinkAIImpl = class {
|
|
|
3845
3729
|
options.prompt || "",
|
|
3846
3730
|
requestBody
|
|
3847
3731
|
);
|
|
3848
|
-
|
|
3732
|
+
if (response.data?.result) {
|
|
3733
|
+
return response.data.result;
|
|
3734
|
+
} else if (response.data?.text) {
|
|
3735
|
+
return response.data;
|
|
3736
|
+
} else {
|
|
3737
|
+
throw new BlinkAIError("Invalid response format: missing text");
|
|
3738
|
+
}
|
|
3849
3739
|
} catch (error) {
|
|
3850
3740
|
if (error instanceof BlinkAIError) {
|
|
3851
3741
|
throw error;
|
|
@@ -3914,14 +3804,9 @@ var BlinkAIImpl = class {
|
|
|
3914
3804
|
);
|
|
3915
3805
|
return {
|
|
3916
3806
|
text: result.text || "",
|
|
3917
|
-
finishReason:
|
|
3807
|
+
finishReason: "stop",
|
|
3918
3808
|
usage: result.usage,
|
|
3919
|
-
|
|
3920
|
-
toolResults: result.toolResults,
|
|
3921
|
-
sources: result.sources,
|
|
3922
|
-
files: result.files,
|
|
3923
|
-
reasoningDetails: result.reasoning,
|
|
3924
|
-
response: result.response
|
|
3809
|
+
...result
|
|
3925
3810
|
};
|
|
3926
3811
|
} catch (error) {
|
|
3927
3812
|
if (error instanceof BlinkAIError) {
|
|
@@ -4000,7 +3885,13 @@ var BlinkAIImpl = class {
|
|
|
4000
3885
|
signal: options.signal
|
|
4001
3886
|
}
|
|
4002
3887
|
);
|
|
4003
|
-
|
|
3888
|
+
if (response.data?.result) {
|
|
3889
|
+
return response.data.result;
|
|
3890
|
+
} else if (response.data?.object) {
|
|
3891
|
+
return response.data;
|
|
3892
|
+
} else {
|
|
3893
|
+
throw new BlinkAIError("Invalid response format: missing object");
|
|
3894
|
+
}
|
|
4004
3895
|
} catch (error) {
|
|
4005
3896
|
if (error instanceof BlinkAIError) {
|
|
4006
3897
|
throw error;
|
|
@@ -4062,7 +3953,8 @@ var BlinkAIImpl = class {
|
|
|
4062
3953
|
return {
|
|
4063
3954
|
object: result.object || {},
|
|
4064
3955
|
finishReason: "stop",
|
|
4065
|
-
usage: result.usage
|
|
3956
|
+
usage: result.usage,
|
|
3957
|
+
...result
|
|
4066
3958
|
};
|
|
4067
3959
|
} catch (error) {
|
|
4068
3960
|
if (error instanceof BlinkAIError) {
|
|
@@ -4323,131 +4215,6 @@ var BlinkAIImpl = class {
|
|
|
4323
4215
|
);
|
|
4324
4216
|
}
|
|
4325
4217
|
}
|
|
4326
|
-
/**
|
|
4327
|
-
* Generates videos from text prompts or images using AI video generation models.
|
|
4328
|
-
*
|
|
4329
|
-
* @param options - Object containing:
|
|
4330
|
-
* - `prompt`: Text description of the video to generate (required)
|
|
4331
|
-
* - `model`: Video model to use (optional). Available models:
|
|
4332
|
-
* **Text-to-Video Models:**
|
|
4333
|
-
* - `"fal-ai/veo3.1"` - Google Veo 3.1 (best quality)
|
|
4334
|
-
* - `"fal-ai/veo3.1/fast"` (default) - Veo 3.1 fast mode (faster, cheaper)
|
|
4335
|
-
* - `"fal-ai/sora-2/text-to-video/pro"` - OpenAI Sora 2
|
|
4336
|
-
* - `"fal-ai/kling-video/v2.6/pro/text-to-video"` - Kling 2.6
|
|
4337
|
-
* **Image-to-Video Models:**
|
|
4338
|
-
* - `"fal-ai/veo3.1/image-to-video"` - Veo 3.1 I2V
|
|
4339
|
-
* - `"fal-ai/veo3.1/fast/image-to-video"` - Veo 3.1 fast I2V
|
|
4340
|
-
* - `"fal-ai/sora-2/image-to-video/pro"` - Sora 2 I2V
|
|
4341
|
-
* - `"fal-ai/kling-video/v2.6/pro/image-to-video"` - Kling 2.6 I2V
|
|
4342
|
-
* - `image_url`: Source image URL for image-to-video (required for I2V models)
|
|
4343
|
-
* - `duration`: Video duration ("4s", "5s", "6s", "8s", "10s", "12s")
|
|
4344
|
-
* - `aspect_ratio`: Aspect ratio ("16:9", "9:16", "1:1")
|
|
4345
|
-
* - `resolution`: Resolution ("720p", "1080p") - Veo/Sora only
|
|
4346
|
-
* - `negative_prompt`: What to avoid in generation - Veo/Kling only
|
|
4347
|
-
* - `generate_audio`: Generate audio with video (default: true)
|
|
4348
|
-
* - `seed`: For reproducibility - Veo only
|
|
4349
|
-
* - `cfg_scale`: Guidance scale (0-1) - Kling only
|
|
4350
|
-
* - Plus optional signal parameter
|
|
4351
|
-
*
|
|
4352
|
-
* @example
|
|
4353
|
-
* ```ts
|
|
4354
|
-
* // Basic text-to-video generation (uses default fast model)
|
|
4355
|
-
* const { result } = await blink.ai.generateVideo({
|
|
4356
|
-
* prompt: "A serene sunset over the ocean with gentle waves"
|
|
4357
|
-
* });
|
|
4358
|
-
* console.log("Video URL:", result.video.url);
|
|
4359
|
-
*
|
|
4360
|
-
* // High quality with Veo 3.1
|
|
4361
|
-
* const { result } = await blink.ai.generateVideo({
|
|
4362
|
-
* prompt: "A cinematic shot of a futuristic city at night",
|
|
4363
|
-
* model: "fal-ai/veo3.1",
|
|
4364
|
-
* resolution: "1080p",
|
|
4365
|
-
* aspect_ratio: "16:9"
|
|
4366
|
-
* });
|
|
4367
|
-
*
|
|
4368
|
-
* // Image-to-video animation
|
|
4369
|
-
* const { result } = await blink.ai.generateVideo({
|
|
4370
|
-
* prompt: "Animate this image with gentle camera movement",
|
|
4371
|
-
* model: "fal-ai/veo3.1/fast/image-to-video",
|
|
4372
|
-
* image_url: "https://example.com/my-image.jpg",
|
|
4373
|
-
* duration: "5s"
|
|
4374
|
-
* });
|
|
4375
|
-
*
|
|
4376
|
-
* // Using Sora 2 for creative videos
|
|
4377
|
-
* const { result } = await blink.ai.generateVideo({
|
|
4378
|
-
* prompt: "A magical forest with glowing fireflies",
|
|
4379
|
-
* model: "fal-ai/sora-2/text-to-video/pro",
|
|
4380
|
-
* duration: "8s"
|
|
4381
|
-
* });
|
|
4382
|
-
*
|
|
4383
|
-
* // Using Kling for detailed videos
|
|
4384
|
-
* const { result, usage } = await blink.ai.generateVideo({
|
|
4385
|
-
* prompt: "A professional cooking tutorial scene",
|
|
4386
|
-
* model: "fal-ai/kling-video/v2.6/pro/text-to-video",
|
|
4387
|
-
* negative_prompt: "blur, distort, low quality",
|
|
4388
|
-
* cfg_scale: 0.7
|
|
4389
|
-
* });
|
|
4390
|
-
* console.log("Credits charged:", usage?.creditsCharged);
|
|
4391
|
-
* ```
|
|
4392
|
-
*
|
|
4393
|
-
* @returns Promise<VideoGenerationResponse> - Object containing:
|
|
4394
|
-
* - `result.video.url`: URL to the generated video
|
|
4395
|
-
* - `result.video.content_type`: MIME type (video/mp4)
|
|
4396
|
-
* - `result.video.file_name`: Generated filename
|
|
4397
|
-
* - `result.video.file_size`: File size in bytes
|
|
4398
|
-
* - `metadata`: Generation metadata (projectId, timestamp, model)
|
|
4399
|
-
* - `usage`: Credits charged and cost information
|
|
4400
|
-
*/
|
|
4401
|
-
async generateVideo(options) {
|
|
4402
|
-
try {
|
|
4403
|
-
if (!options.prompt) {
|
|
4404
|
-
throw new BlinkAIError("Prompt is required");
|
|
4405
|
-
}
|
|
4406
|
-
const i2vModels = [
|
|
4407
|
-
"fal-ai/veo3.1/image-to-video",
|
|
4408
|
-
"fal-ai/veo3.1/fast/image-to-video",
|
|
4409
|
-
"fal-ai/sora-2/image-to-video/pro",
|
|
4410
|
-
"fal-ai/kling-video/v2.6/pro/image-to-video"
|
|
4411
|
-
];
|
|
4412
|
-
if (options.model && i2vModels.includes(options.model) && !options.image_url) {
|
|
4413
|
-
throw new BlinkAIError("image_url is required for image-to-video models");
|
|
4414
|
-
}
|
|
4415
|
-
if (options.image_url) {
|
|
4416
|
-
const validation = this.validateImageUrl(options.image_url);
|
|
4417
|
-
if (!validation.isValid) {
|
|
4418
|
-
throw new BlinkAIError(`Invalid image_url: ${validation.error}`);
|
|
4419
|
-
}
|
|
4420
|
-
}
|
|
4421
|
-
const response = await this.httpClient.aiVideo(
|
|
4422
|
-
options.prompt,
|
|
4423
|
-
{
|
|
4424
|
-
model: options.model,
|
|
4425
|
-
image_url: options.image_url,
|
|
4426
|
-
duration: options.duration,
|
|
4427
|
-
aspect_ratio: options.aspect_ratio,
|
|
4428
|
-
resolution: options.resolution,
|
|
4429
|
-
negative_prompt: options.negative_prompt,
|
|
4430
|
-
generate_audio: options.generate_audio,
|
|
4431
|
-
seed: options.seed,
|
|
4432
|
-
cfg_scale: options.cfg_scale,
|
|
4433
|
-
signal: options.signal
|
|
4434
|
-
}
|
|
4435
|
-
);
|
|
4436
|
-
if (!response.data?.result?.video?.url) {
|
|
4437
|
-
throw new BlinkAIError("Invalid response format: missing video URL");
|
|
4438
|
-
}
|
|
4439
|
-
return response.data;
|
|
4440
|
-
} catch (error) {
|
|
4441
|
-
if (error instanceof BlinkAIError) {
|
|
4442
|
-
throw error;
|
|
4443
|
-
}
|
|
4444
|
-
throw new BlinkAIError(
|
|
4445
|
-
`Video generation failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
4446
|
-
void 0,
|
|
4447
|
-
{ originalError: error }
|
|
4448
|
-
);
|
|
4449
|
-
}
|
|
4450
|
-
}
|
|
4451
4218
|
/**
|
|
4452
4219
|
* Converts text to speech using AI voice synthesis models.
|
|
4453
4220
|
*
|
|
@@ -5037,7 +4804,7 @@ var BlinkRealtimeChannel = class {
|
|
|
5037
4804
|
return new Promise((resolve, reject) => {
|
|
5038
4805
|
try {
|
|
5039
4806
|
const httpClient = this.httpClient;
|
|
5040
|
-
const coreUrl = httpClient.coreUrl || "https://core.blink.new";
|
|
4807
|
+
const coreUrl = httpClient.coreUrl || "https://dev.core.blink.new";
|
|
5041
4808
|
const baseUrl = coreUrl.replace("https://", "wss://").replace("http://", "ws://");
|
|
5042
4809
|
const wsUrl = `${baseUrl}?project_id=${this.projectId}`;
|
|
5043
4810
|
console.log(`\u{1F517} Attempting WebSocket connection to: ${wsUrl}`);
|
|
@@ -5506,6 +5273,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
5506
5273
|
} catch (error) {
|
|
5507
5274
|
this.queue = [...events, ...this.queue];
|
|
5508
5275
|
this.persistQueue();
|
|
5276
|
+
console.error("Failed to send analytics events:", error);
|
|
5509
5277
|
}
|
|
5510
5278
|
if (this.queue.length > 0) {
|
|
5511
5279
|
this.timer = setTimeout(() => this.flush(), BATCH_TIMEOUT);
|
|
@@ -5696,64 +5464,6 @@ var BlinkAnalyticsImpl = class {
|
|
|
5696
5464
|
}
|
|
5697
5465
|
};
|
|
5698
5466
|
|
|
5699
|
-
// src/connectors.ts
|
|
5700
|
-
var BlinkConnectorsImpl = class {
|
|
5701
|
-
constructor(httpClient) {
|
|
5702
|
-
this.httpClient = httpClient;
|
|
5703
|
-
}
|
|
5704
|
-
async status(provider, options) {
|
|
5705
|
-
const response = await this.httpClient.connectorStatus(provider);
|
|
5706
|
-
return response.data;
|
|
5707
|
-
}
|
|
5708
|
-
async execute(provider, request) {
|
|
5709
|
-
const response = await this.httpClient.connectorExecute(provider, request);
|
|
5710
|
-
return response.data;
|
|
5711
|
-
}
|
|
5712
|
-
async saveApiKey(provider, request) {
|
|
5713
|
-
const response = await this.httpClient.connectorSaveApiKey(provider, request);
|
|
5714
|
-
return response.data;
|
|
5715
|
-
}
|
|
5716
|
-
};
|
|
5717
|
-
|
|
5718
|
-
// src/functions.ts
|
|
5719
|
-
var BlinkFunctionsImpl = class {
|
|
5720
|
-
httpClient;
|
|
5721
|
-
projectId;
|
|
5722
|
-
constructor(httpClient, projectId, _getToken) {
|
|
5723
|
-
this.httpClient = httpClient;
|
|
5724
|
-
this.projectId = projectId;
|
|
5725
|
-
}
|
|
5726
|
-
/**
|
|
5727
|
-
* Get the project suffix from the full project ID.
|
|
5728
|
-
* Project IDs are formatted as: prj_xxxxx
|
|
5729
|
-
* The suffix is the last 8 characters used in function URLs.
|
|
5730
|
-
*/
|
|
5731
|
-
getProjectSuffix() {
|
|
5732
|
-
return this.projectId.slice(-8);
|
|
5733
|
-
}
|
|
5734
|
-
/**
|
|
5735
|
-
* Build the full function URL
|
|
5736
|
-
*/
|
|
5737
|
-
buildFunctionUrl(functionSlug, searchParams) {
|
|
5738
|
-
const suffix = this.getProjectSuffix();
|
|
5739
|
-
const baseUrl = `https://${suffix}--${functionSlug}.functions.blink.new`;
|
|
5740
|
-
if (!searchParams || Object.keys(searchParams).length === 0) {
|
|
5741
|
-
return baseUrl;
|
|
5742
|
-
}
|
|
5743
|
-
const url = new URL(baseUrl);
|
|
5744
|
-
Object.entries(searchParams).forEach(([key, value]) => {
|
|
5745
|
-
url.searchParams.set(key, value);
|
|
5746
|
-
});
|
|
5747
|
-
return url.toString();
|
|
5748
|
-
}
|
|
5749
|
-
async invoke(functionSlug, options = {}) {
|
|
5750
|
-
const { method = "POST", body, headers = {}, searchParams } = options;
|
|
5751
|
-
const url = this.buildFunctionUrl(functionSlug, searchParams);
|
|
5752
|
-
const res = await this.httpClient.request(url, { method, body, headers });
|
|
5753
|
-
return { data: res.data, status: res.status, headers: res.headers };
|
|
5754
|
-
}
|
|
5755
|
-
};
|
|
5756
|
-
|
|
5757
5467
|
// src/client.ts
|
|
5758
5468
|
var BlinkClientImpl = class {
|
|
5759
5469
|
auth;
|
|
@@ -5764,13 +5474,8 @@ var BlinkClientImpl = class {
|
|
|
5764
5474
|
realtime;
|
|
5765
5475
|
notifications;
|
|
5766
5476
|
analytics;
|
|
5767
|
-
connectors;
|
|
5768
|
-
functions;
|
|
5769
5477
|
httpClient;
|
|
5770
5478
|
constructor(config) {
|
|
5771
|
-
if ((config.secretKey || config.serviceToken) && isBrowser) {
|
|
5772
|
-
throw new Error("secretKey/serviceToken is server-only. Do not provide it in browser/React Native clients.");
|
|
5773
|
-
}
|
|
5774
5479
|
this.auth = new BlinkAuth(config);
|
|
5775
5480
|
this.httpClient = new HttpClient(
|
|
5776
5481
|
config,
|
|
@@ -5784,12 +5489,6 @@ var BlinkClientImpl = class {
|
|
|
5784
5489
|
this.realtime = new BlinkRealtimeImpl(this.httpClient, config.projectId);
|
|
5785
5490
|
this.notifications = new BlinkNotificationsImpl(this.httpClient);
|
|
5786
5491
|
this.analytics = new BlinkAnalyticsImpl(this.httpClient, config.projectId);
|
|
5787
|
-
this.connectors = new BlinkConnectorsImpl(this.httpClient);
|
|
5788
|
-
this.functions = new BlinkFunctionsImpl(
|
|
5789
|
-
this.httpClient,
|
|
5790
|
-
config.projectId,
|
|
5791
|
-
() => this.auth.getValidToken()
|
|
5792
|
-
);
|
|
5793
5492
|
this.auth.onAuthStateChanged((state) => {
|
|
5794
5493
|
if (state.isAuthenticated && state.user) {
|
|
5795
5494
|
this.analytics.setUserId(state.user.id);
|
|
@@ -5811,7 +5510,6 @@ function createClient(config) {
|
|
|
5811
5510
|
exports.AsyncStorageAdapter = AsyncStorageAdapter;
|
|
5812
5511
|
exports.BlinkAIImpl = BlinkAIImpl;
|
|
5813
5512
|
exports.BlinkAnalyticsImpl = BlinkAnalyticsImpl;
|
|
5814
|
-
exports.BlinkConnectorsImpl = BlinkConnectorsImpl;
|
|
5815
5513
|
exports.BlinkDataImpl = BlinkDataImpl;
|
|
5816
5514
|
exports.BlinkDatabase = BlinkDatabase;
|
|
5817
5515
|
exports.BlinkRealtimeChannel = BlinkRealtimeChannel;
|
|
@@ -5823,10 +5521,8 @@ exports.WebStorageAdapter = WebStorageAdapter;
|
|
|
5823
5521
|
exports.createClient = createClient;
|
|
5824
5522
|
exports.getDefaultStorageAdapter = getDefaultStorageAdapter;
|
|
5825
5523
|
exports.isBrowser = isBrowser;
|
|
5826
|
-
exports.isDeno = isDeno;
|
|
5827
5524
|
exports.isNode = isNode;
|
|
5828
5525
|
exports.isReactNative = isReactNative;
|
|
5829
|
-
exports.isServer = isServer;
|
|
5830
5526
|
exports.isWeb = isWeb;
|
|
5831
5527
|
exports.platform = platform;
|
|
5832
5528
|
//# sourceMappingURL=index.js.map
|