@stackfactor/agent-utils 1.0.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/dist/cjs/const.d.ts +15 -0
- package/dist/cjs/const.d.ts.map +1 -0
- package/dist/cjs/const.js +15 -0
- package/dist/cjs/errorHandling.d.ts +20 -0
- package/dist/cjs/errorHandling.d.ts.map +1 -0
- package/dist/cjs/errorHandling.js +23 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/langChain.d.ts +10 -0
- package/dist/cjs/langChain.d.ts.map +1 -0
- package/dist/cjs/langChain.js +1241 -0
- package/dist/cjs/logger.d.ts +29 -0
- package/dist/cjs/logger.d.ts.map +1 -0
- package/dist/cjs/logger.js +77 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/const.d.ts +15 -0
- package/dist/esm/const.d.ts.map +1 -0
- package/dist/esm/const.js +13 -0
- package/dist/esm/errorHandling.d.ts +20 -0
- package/dist/esm/errorHandling.d.ts.map +1 -0
- package/dist/esm/errorHandling.js +21 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/langChain.d.ts +10 -0
- package/dist/esm/langChain.d.ts.map +1 -0
- package/dist/esm/langChain.js +1236 -0
- package/dist/esm/logger.d.ts +29 -0
- package/dist/esm/logger.d.ts.map +1 -0
- package/dist/esm/logger.js +72 -0
- package/dist/esm/package.json +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes a structured log entry via Winston using the GCP-compatible format. The
|
|
3
|
+
* current OpenTelemetry span context is read to enrich the entry with `trace` and
|
|
4
|
+
* `spanId` fields when an active span is present. The user's email (if available on the
|
|
5
|
+
* request) is prepended to the message string along with an icon derived from the log
|
|
6
|
+
* level. Any additional fields supplied in `options` are merged into the log record.
|
|
7
|
+
* @param request - The HTTP request object; used to extract `request.user.email` for
|
|
8
|
+
* the log message prefix; may be `null`
|
|
9
|
+
* @param level - The Winston log level string (e.g. `"info"`, `"error"`, `"warn"`);
|
|
10
|
+
* must be one of the keys in the `levels` constant
|
|
11
|
+
* @param message - The primary log message string
|
|
12
|
+
* @param options - Additional key-value pairs merged into the log record for structured
|
|
13
|
+
* logging (e.g. `{ service: "auth", requestId: "..." }`); defaults to `{}`
|
|
14
|
+
*/
|
|
15
|
+
type LogLevel = "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
|
|
16
|
+
declare const _default: {
|
|
17
|
+
log: (request: any, level: LogLevel, message: string, options?: any) => void;
|
|
18
|
+
levels: {
|
|
19
|
+
readonly error: "error";
|
|
20
|
+
readonly warn: "warn";
|
|
21
|
+
readonly info: "info";
|
|
22
|
+
readonly http: "http";
|
|
23
|
+
readonly verbose: "verbose";
|
|
24
|
+
readonly debug: "debug";
|
|
25
|
+
readonly silly: "silly";
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export default _default;
|
|
29
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAiEA;;;;;;;;;;;;;GAaG;AACH,KAAK,QAAQ,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,SAAS,GACT,OAAO,GACP,OAAO,CAAC;;mBAGD,GAAG,SACL,QAAQ,WACN,MAAM,YACN,GAAG,KACX,IAAI;;;;;;;;;;;AA0BP,wBAGE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import winston from "winston";
|
|
2
|
+
import { trace, context } from "@opentelemetry/api";
|
|
3
|
+
const { combine, timestamp, printf } = winston.format;
|
|
4
|
+
const levels = {
|
|
5
|
+
error: "error",
|
|
6
|
+
warn: "warn",
|
|
7
|
+
info: "info",
|
|
8
|
+
http: "http",
|
|
9
|
+
verbose: "verbose",
|
|
10
|
+
debug: "debug",
|
|
11
|
+
silly: "silly",
|
|
12
|
+
};
|
|
13
|
+
const levelIcons = {
|
|
14
|
+
error: "â",
|
|
15
|
+
warn: "â ī¸",
|
|
16
|
+
info: "đ",
|
|
17
|
+
http: "đ",
|
|
18
|
+
verbose: "đ",
|
|
19
|
+
debug: "đ",
|
|
20
|
+
silly: "đ",
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Custom Winston printf formatter that serialises log records to a single-line JSON
|
|
24
|
+
* string compatible with Google Cloud Platform (GCP) structured logging. The `level`
|
|
25
|
+
* field is mapped to GCP's `severity` key (uppercased) and all standard fields plus any
|
|
26
|
+
* additional metadata are included in the output.
|
|
27
|
+
*/
|
|
28
|
+
const gcpFormat = printf((info) => {
|
|
29
|
+
const { level, message, timestamp: ts, service, environment, requestId, userId, trace, spanId, sourceLocation, ...rest } = info;
|
|
30
|
+
return JSON.stringify({
|
|
31
|
+
severity: level ? level.toUpperCase() : undefined,
|
|
32
|
+
message,
|
|
33
|
+
timestamp: ts,
|
|
34
|
+
service,
|
|
35
|
+
environment,
|
|
36
|
+
requestId,
|
|
37
|
+
userId,
|
|
38
|
+
trace,
|
|
39
|
+
spanId,
|
|
40
|
+
sourceLocation,
|
|
41
|
+
...rest,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
const logger = winston.createLogger({
|
|
45
|
+
format: combine(timestamp(), gcpFormat),
|
|
46
|
+
transports: [new winston.transports.Console()],
|
|
47
|
+
});
|
|
48
|
+
const log = (request, level, message, options = {}) => {
|
|
49
|
+
// Get current OpenTelemetry span context
|
|
50
|
+
const span = trace.getSpan(context.active());
|
|
51
|
+
let traceId, spanId;
|
|
52
|
+
if (span) {
|
|
53
|
+
const spanContext = span.spanContext();
|
|
54
|
+
traceId = spanContext.traceId;
|
|
55
|
+
spanId = spanContext.spanId;
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
58
|
+
const icon = levelIcons[level] || "âšī¸";
|
|
59
|
+
logger.log({
|
|
60
|
+
level: level,
|
|
61
|
+
message: `${icon} ${request && request.user ? request.user.email + " - " : ""}${message}`,
|
|
62
|
+
trace: traceId
|
|
63
|
+
? `projects/${process.env.GOOGLE_CLOUD_PROJECT}/traces/${traceId}`
|
|
64
|
+
: undefined,
|
|
65
|
+
spanId: spanId,
|
|
66
|
+
...options,
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
export default {
|
|
70
|
+
log,
|
|
71
|
+
levels,
|
|
72
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stackfactor/agent-utils",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "restricted"
|
|
5
|
+
},
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"description": "",
|
|
8
|
+
"main": "dist/cjs/index.js",
|
|
9
|
+
"module": "dist/esm/index.js",
|
|
10
|
+
"types": "dist/cjs/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"clean": "rm -rf dist",
|
|
16
|
+
"build": "npm run clean && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json && echo '{\"type\":\"module\"}' > dist/esm/package.json"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/StackFactor/stackfactor-agent-utils.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [],
|
|
23
|
+
"author": "StackFactor Inc",
|
|
24
|
+
"license": "Not licensed",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/cjs/index.d.ts",
|
|
29
|
+
"default": "./dist/cjs/index.js"
|
|
30
|
+
},
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/esm/index.d.ts",
|
|
33
|
+
"default": "./dist/esm/index.js"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/StackFactor/stackfactor-agent-utils/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/StackFactor/stackfactor-agent-utils#readme",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@google/genai": "^1.46.0",
|
|
43
|
+
"@langchain/anthropic": "^1.3.25",
|
|
44
|
+
"@langchain/google-genai": "^2.1.26",
|
|
45
|
+
"@langchain/openai": "^1.3.0",
|
|
46
|
+
"@opentelemetry/api": "^1.9.0",
|
|
47
|
+
"langchain": "^1.2.35",
|
|
48
|
+
"mongoose": "^9.3.1",
|
|
49
|
+
"openai": "^6.32.0",
|
|
50
|
+
"winston": "^3.19.0",
|
|
51
|
+
"zod": "^4.3.6",
|
|
52
|
+
"zod-to-json-schema": "^3.25.1"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"typescript": "^5.9.3"
|
|
56
|
+
}
|
|
57
|
+
}
|