@traceai/google-genai-sdk 0.0.0-stage → 0.1.0
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/README.md +72 -2
- package/dist/capture.d.ts +44 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +414 -0
- package/dist/capture.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +543 -0
- package/dist/index.js.map +1 -0
- package/dist/promise.d.ts +6 -0
- package/dist/promise.d.ts.map +1 -0
- package/dist/promise.js +46 -0
- package/dist/promise.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +47 -3
- package/src/capture.ts +443 -0
- package/src/index.ts +668 -0
- package/src/promise.ts +52 -0
- package/src/version.ts +1 -0
package/src/promise.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { context, type Context } from "@opentelemetry/api";
|
|
2
|
+
import { record } from "./capture.js";
|
|
3
|
+
|
|
4
|
+
/** Older Interactions APIs return APIPromise, not a plain Promise. In particular,
|
|
5
|
+
* asResponse() must not trigger JSON parsing or consume the caller's raw body.
|
|
6
|
+
*/
|
|
7
|
+
export function wrapAPIPromise(
|
|
8
|
+
target: object,
|
|
9
|
+
child: Context,
|
|
10
|
+
resolve: (value: unknown) => unknown,
|
|
11
|
+
reject: (error: unknown) => never,
|
|
12
|
+
requestOnly: () => void,
|
|
13
|
+
): object {
|
|
14
|
+
let consumed: Promise<unknown> | undefined;
|
|
15
|
+
const consume = () =>
|
|
16
|
+
(consumed ??= context.with(child, () =>
|
|
17
|
+
Promise.resolve(target).then(resolve, reject),
|
|
18
|
+
));
|
|
19
|
+
return new Proxy(target, {
|
|
20
|
+
get(object, key) {
|
|
21
|
+
if (key === "then" || key === "catch" || key === "finally") {
|
|
22
|
+
// Accessing .then itself must not start consuming a lazy response.
|
|
23
|
+
return (...args: unknown[]) => {
|
|
24
|
+
const promise = consume();
|
|
25
|
+
return Reflect.apply(Reflect.get(promise, key), promise, args);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const method = Reflect.get(object, key, object);
|
|
29
|
+
if (typeof method !== "function") return method;
|
|
30
|
+
if (key === "withResponse" || key === "asResponse")
|
|
31
|
+
return (...args: unknown[]) => {
|
|
32
|
+
try {
|
|
33
|
+
return Promise.resolve(
|
|
34
|
+
context.with(child, () => Reflect.apply(method, object, args)),
|
|
35
|
+
).then((value) => {
|
|
36
|
+
if (key === "asResponse") {
|
|
37
|
+
requestOnly();
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
const envelope = record(value);
|
|
41
|
+
const data = resolve(envelope.data);
|
|
42
|
+
// Non-stream data keeps identity. Streaming data alone gets the iterator observer.
|
|
43
|
+
return data === envelope.data ? value : { ...envelope, data };
|
|
44
|
+
}, reject);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return reject(error);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return method.bind(object);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = "0.1.0"; // x-release-please-version
|