@tstdl/base 0.92.91 → 0.92.92
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/ai/ai-file.service.js +26 -87
- package/package.json +3 -2
- package/queue/postgres/queue.js +1 -0
package/ai/ai-file.service.js
CHANGED
|
@@ -4,64 +4,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
8
|
-
if (value !== null && value !== void 0) {
|
|
9
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
10
|
-
var dispose, inner;
|
|
11
|
-
if (async) {
|
|
12
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
13
|
-
dispose = value[Symbol.asyncDispose];
|
|
14
|
-
}
|
|
15
|
-
if (dispose === void 0) {
|
|
16
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
17
|
-
dispose = value[Symbol.dispose];
|
|
18
|
-
if (async) inner = dispose;
|
|
19
|
-
}
|
|
20
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
21
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
22
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
23
|
-
}
|
|
24
|
-
else if (async) {
|
|
25
|
-
env.stack.push({ async: true });
|
|
26
|
-
}
|
|
27
|
-
return value;
|
|
28
|
-
};
|
|
29
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
30
|
-
return function (env) {
|
|
31
|
-
function fail(e) {
|
|
32
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
33
|
-
env.hasError = true;
|
|
34
|
-
}
|
|
35
|
-
var r, s = 0;
|
|
36
|
-
function next() {
|
|
37
|
-
while (r = env.stack.pop()) {
|
|
38
|
-
try {
|
|
39
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
40
|
-
if (r.dispose) {
|
|
41
|
-
var result = r.dispose.call(r.value);
|
|
42
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
43
|
-
}
|
|
44
|
-
else s |= 1;
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
fail(e);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
51
|
-
if (env.hasError) throw env.error;
|
|
52
|
-
}
|
|
53
|
-
return next();
|
|
54
|
-
};
|
|
55
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
56
|
-
var e = new Error(message);
|
|
57
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
58
|
-
});
|
|
59
7
|
import '../polyfills.js';
|
|
8
|
+
import { readFile } from 'node:fs/promises';
|
|
60
9
|
import { Storage } from '@google-cloud/storage';
|
|
61
10
|
import { FileState, GoogleAIFileManager } from '@google/generative-ai/server';
|
|
62
11
|
import { AsyncEnumerable } from '../enumerable/async-enumerable.js';
|
|
63
12
|
import { DetailsError } from '../errors/details.error.js';
|
|
64
|
-
import {
|
|
13
|
+
import { NotImplementedError } from '../errors/not-implemented.error.js';
|
|
65
14
|
import { Singleton } from '../injector/decorators.js';
|
|
66
15
|
import { inject, injectArgument } from '../injector/inject.js';
|
|
67
16
|
import { Logger } from '../logger/logger.js';
|
|
@@ -113,43 +62,33 @@ let AiFileService = class AiFileService {
|
|
|
113
62
|
return files;
|
|
114
63
|
}
|
|
115
64
|
async uploadFile(fileInput, id) {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const [file] = await bucket.upload(path, { destination: id, contentType: mimeType });
|
|
129
|
-
return {
|
|
130
|
-
id,
|
|
131
|
-
name: id,
|
|
132
|
-
uri: file.cloudStorageURI.toString(),
|
|
133
|
-
mimeType
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const response = await this.#fileManager.uploadFile(path, { mimeType });
|
|
65
|
+
const inputIsBlob = isBlob(fileInput);
|
|
66
|
+
const buffer = inputIsBlob
|
|
67
|
+
? await fileInput.bytes()
|
|
68
|
+
: await readFile(fileInput.path);
|
|
69
|
+
const mimeType = inputIsBlob ? fileInput.type : fileInput.mimeType;
|
|
70
|
+
this.#logger.verbose(`Uploading file "${id}" (${formatBytes(buffer.length)})...`);
|
|
71
|
+
if (isDefined(this.#storage)) {
|
|
72
|
+
throw new NotImplementedError();
|
|
73
|
+
/*
|
|
74
|
+
const bucket = await this.getBucket();
|
|
75
|
+
const [file] = await bucket.upload(path, { destination: id, contentType: mimeType });
|
|
76
|
+
|
|
137
77
|
return {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
78
|
+
id,
|
|
79
|
+
name: id,
|
|
80
|
+
uri: file.cloudStorageURI.toString(),
|
|
81
|
+
mimeType
|
|
142
82
|
};
|
|
83
|
+
*/
|
|
143
84
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
await result_1;
|
|
152
|
-
}
|
|
85
|
+
const response = await this.#fileManager.uploadFile(buffer, { mimeType });
|
|
86
|
+
return {
|
|
87
|
+
id,
|
|
88
|
+
name: response.file.name,
|
|
89
|
+
uri: response.file.uri,
|
|
90
|
+
mimeType: response.file.mimeType
|
|
91
|
+
};
|
|
153
92
|
}
|
|
154
93
|
async getBucket() {
|
|
155
94
|
if (isUndefined(this.#options.vertex)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.92.
|
|
3
|
+
"version": "0.92.92",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
"./promise": "./promise/index.js",
|
|
94
94
|
"./queue": "./queue/index.js",
|
|
95
95
|
"./queue/mongo": "./queue/mongo/index.js",
|
|
96
|
+
"./queue/postgres": "./queue/postgres/index.js",
|
|
96
97
|
"./random": "./random/index.js",
|
|
97
98
|
"./reflection": "./reflection/index.js",
|
|
98
99
|
"./rpc": "./rpc/index.js",
|
|
@@ -159,7 +160,7 @@
|
|
|
159
160
|
},
|
|
160
161
|
"peerDependencies": {
|
|
161
162
|
"@elastic/elasticsearch": "^8.17",
|
|
162
|
-
"@google/generative-ai": "^0.
|
|
163
|
+
"@google/generative-ai": "^0.24",
|
|
163
164
|
"@tstdl/angular": "^0.92",
|
|
164
165
|
"@zxcvbn-ts/core": "^3.0",
|
|
165
166
|
"@zxcvbn-ts/language-common": "^3.0",
|
package/queue/postgres/queue.js
CHANGED
|
@@ -139,6 +139,7 @@ let PostgresQueue = class PostgresQueue extends Queue {
|
|
|
139
139
|
};
|
|
140
140
|
PostgresQueue = __decorate([
|
|
141
141
|
Singleton({
|
|
142
|
+
argumentIdentityProvider: JSON.stringify,
|
|
142
143
|
providers: [
|
|
143
144
|
provide(EntityRepositoryConfig, { useValue: { schema: 'queue' } }),
|
|
144
145
|
provide(DatabaseConfig, { useFactory: (_, context) => context.resolve(PostgresQueueModuleConfig).database ?? context.resolve(DatabaseConfig, undefined, { skipSelf: true }) })
|