llmz 0.0.4 → 0.0.5
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/chat.d.ts +17 -0
- package/dist/chunk-3U57H7GT.js +608 -0
- package/dist/{chunk-LVKZYKTP.cjs → chunk-4I7UPBLN.cjs} +2 -2
- package/dist/{chunk-W6U2VXSF.cjs → chunk-6WT5VZBG.cjs} +348 -12
- package/dist/{chunk-JK2LZW2G.cjs → chunk-EJRCDWBA.cjs} +45 -6
- package/dist/{chunk-ZCPQ3QOW.js → chunk-HP7RKM25.js} +45 -6
- package/dist/chunk-MU4LFVY7.cjs +608 -0
- package/dist/{chunk-S6WICIDW.js → chunk-S6FOL2HY.js} +2 -2
- package/dist/{chunk-TJQVC4CE.js → chunk-WLUVY5QU.js} +341 -5
- package/dist/{component-LQDU72LX.js → component-R2Y74VUI.js} +3 -1
- package/dist/component-TSNW3SC7.cjs +16 -0
- package/dist/component.d.ts +6 -19
- package/dist/component.default.d.ts +131 -151
- package/dist/context.d.ts +6 -5
- package/dist/{dual-modes-YE4S2AIL.cjs → dual-modes-UHNDHNIF.cjs} +3 -4
- package/dist/{dual-modes-QHBOFWHM.js → dual-modes-ZUQKPJFH.js} +2 -3
- package/dist/{exit-IDKGZD7M.cjs → exit-KJ4COC5N.cjs} +2 -2
- package/dist/{exit-F6ZUL2NV.js → exit-OIYZLBVJ.js} +1 -1
- package/dist/exit.d.ts +5 -1
- package/dist/getter.d.ts +1 -1
- package/dist/index.cjs +72 -127
- package/dist/index.d.ts +7 -5
- package/dist/index.js +67 -122
- package/dist/llmz-VDA4M42R.cjs +604 -0
- package/dist/llmz-YE5N54IU.js +604 -0
- package/dist/llmz.d.ts +6 -9
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunk-4KB5WXHR.js +0 -92
- package/dist/chunk-6YWYCVAB.cjs +0 -92
- package/dist/chunk-EFGXTO64.js +0 -344
- package/dist/chunk-VAF2H6UD.cjs +0 -344
- package/dist/component-HQ5YQNRX.cjs +0 -14
- package/dist/llmz-AS5TGCQS.js +0 -1108
- package/dist/llmz-R6XZG3JQ.cjs +0 -1108
package/dist/chunk-4KB5WXHR.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extractType,
|
|
3
|
-
inspect
|
|
4
|
-
} from "./chunk-EFGXTO64.js";
|
|
5
|
-
|
|
6
|
-
// src/snapshots.ts
|
|
7
|
-
import { ulid } from "ulid";
|
|
8
|
-
var MAX_SNAPSHOT_SIZE_BYTES = 4e3;
|
|
9
|
-
var Snapshot = class _Snapshot {
|
|
10
|
-
id;
|
|
11
|
-
reason;
|
|
12
|
-
stack;
|
|
13
|
-
variables;
|
|
14
|
-
toolCall;
|
|
15
|
-
#status;
|
|
16
|
-
get status() {
|
|
17
|
-
return Object.freeze({ ...this.#status });
|
|
18
|
-
}
|
|
19
|
-
constructor(props) {
|
|
20
|
-
this.id = props.id;
|
|
21
|
-
this.stack = props.stack;
|
|
22
|
-
this.reason = props.reason;
|
|
23
|
-
this.variables = props.variables;
|
|
24
|
-
this.toolCall = props.toolCall;
|
|
25
|
-
this.#status = props.status;
|
|
26
|
-
}
|
|
27
|
-
static fromSignal(signal) {
|
|
28
|
-
const variables = Object.entries(signal.variables).map(([name, value]) => {
|
|
29
|
-
const type = extractType(value);
|
|
30
|
-
const bytes = JSON.stringify(value || "").length;
|
|
31
|
-
const truncated = bytes > MAX_SNAPSHOT_SIZE_BYTES;
|
|
32
|
-
return truncated ? { name, type, bytes, truncated: true, preview: inspect(value, name) ?? "N/A" } : { name, type, bytes, truncated: false, value };
|
|
33
|
-
});
|
|
34
|
-
return new _Snapshot({
|
|
35
|
-
id: "snapshot_" + ulid(),
|
|
36
|
-
reason: signal.message,
|
|
37
|
-
stack: signal.truncatedCode,
|
|
38
|
-
variables,
|
|
39
|
-
toolCall: signal.toolCall,
|
|
40
|
-
status: { type: "pending" }
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
toJSON() {
|
|
44
|
-
return {
|
|
45
|
-
id: this.id,
|
|
46
|
-
reason: this.reason,
|
|
47
|
-
stack: this.stack,
|
|
48
|
-
variables: this.variables,
|
|
49
|
-
toolCall: this.toolCall,
|
|
50
|
-
status: this.#status
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
static fromJSON(json) {
|
|
54
|
-
return new _Snapshot({
|
|
55
|
-
id: json.id,
|
|
56
|
-
reason: json.reason,
|
|
57
|
-
stack: json.stack,
|
|
58
|
-
variables: json.variables,
|
|
59
|
-
toolCall: json.toolCall,
|
|
60
|
-
status: json.status
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
clone() {
|
|
64
|
-
return new _Snapshot({
|
|
65
|
-
id: this.id,
|
|
66
|
-
reason: this.reason,
|
|
67
|
-
stack: this.stack,
|
|
68
|
-
variables: this.variables,
|
|
69
|
-
toolCall: this.toolCall,
|
|
70
|
-
status: this.#status
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
reset() {
|
|
74
|
-
this.#status = { type: "pending" };
|
|
75
|
-
}
|
|
76
|
-
resolve(value) {
|
|
77
|
-
if (this.#status.type !== "pending") {
|
|
78
|
-
throw new Error(`Cannot resolve snapshot because it is already settled: ${this.#status.type}`);
|
|
79
|
-
}
|
|
80
|
-
this.#status = { type: "resolved", value };
|
|
81
|
-
}
|
|
82
|
-
reject(error) {
|
|
83
|
-
if (this.#status.type !== "pending") {
|
|
84
|
-
throw new Error(`Cannot reject snapshot because it is already settled: ${this.#status.type}`);
|
|
85
|
-
}
|
|
86
|
-
this.#status = { type: "rejected", error };
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export {
|
|
91
|
-
Snapshot
|
|
92
|
-
};
|
package/dist/chunk-6YWYCVAB.cjs
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkVAF2H6UDcjs = require('./chunk-VAF2H6UD.cjs');
|
|
5
|
-
|
|
6
|
-
// src/snapshots.ts
|
|
7
|
-
var _ulid = require('ulid');
|
|
8
|
-
var MAX_SNAPSHOT_SIZE_BYTES = 4e3;
|
|
9
|
-
var Snapshot = class _Snapshot {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
#status;
|
|
16
|
-
get status() {
|
|
17
|
-
return Object.freeze({ ...this.#status });
|
|
18
|
-
}
|
|
19
|
-
constructor(props) {
|
|
20
|
-
this.id = props.id;
|
|
21
|
-
this.stack = props.stack;
|
|
22
|
-
this.reason = props.reason;
|
|
23
|
-
this.variables = props.variables;
|
|
24
|
-
this.toolCall = props.toolCall;
|
|
25
|
-
this.#status = props.status;
|
|
26
|
-
}
|
|
27
|
-
static fromSignal(signal) {
|
|
28
|
-
const variables = Object.entries(signal.variables).map(([name, value]) => {
|
|
29
|
-
const type = _chunkVAF2H6UDcjs.extractType.call(void 0, value);
|
|
30
|
-
const bytes = JSON.stringify(value || "").length;
|
|
31
|
-
const truncated = bytes > MAX_SNAPSHOT_SIZE_BYTES;
|
|
32
|
-
return truncated ? { name, type, bytes, truncated: true, preview: _nullishCoalesce(_chunkVAF2H6UDcjs.inspect.call(void 0, value, name), () => ( "N/A")) } : { name, type, bytes, truncated: false, value };
|
|
33
|
-
});
|
|
34
|
-
return new _Snapshot({
|
|
35
|
-
id: "snapshot_" + _ulid.ulid.call(void 0, ),
|
|
36
|
-
reason: signal.message,
|
|
37
|
-
stack: signal.truncatedCode,
|
|
38
|
-
variables,
|
|
39
|
-
toolCall: signal.toolCall,
|
|
40
|
-
status: { type: "pending" }
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
toJSON() {
|
|
44
|
-
return {
|
|
45
|
-
id: this.id,
|
|
46
|
-
reason: this.reason,
|
|
47
|
-
stack: this.stack,
|
|
48
|
-
variables: this.variables,
|
|
49
|
-
toolCall: this.toolCall,
|
|
50
|
-
status: this.#status
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
static fromJSON(json) {
|
|
54
|
-
return new _Snapshot({
|
|
55
|
-
id: json.id,
|
|
56
|
-
reason: json.reason,
|
|
57
|
-
stack: json.stack,
|
|
58
|
-
variables: json.variables,
|
|
59
|
-
toolCall: json.toolCall,
|
|
60
|
-
status: json.status
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
clone() {
|
|
64
|
-
return new _Snapshot({
|
|
65
|
-
id: this.id,
|
|
66
|
-
reason: this.reason,
|
|
67
|
-
stack: this.stack,
|
|
68
|
-
variables: this.variables,
|
|
69
|
-
toolCall: this.toolCall,
|
|
70
|
-
status: this.#status
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
reset() {
|
|
74
|
-
this.#status = { type: "pending" };
|
|
75
|
-
}
|
|
76
|
-
resolve(value) {
|
|
77
|
-
if (this.#status.type !== "pending") {
|
|
78
|
-
throw new Error(`Cannot resolve snapshot because it is already settled: ${this.#status.type}`);
|
|
79
|
-
}
|
|
80
|
-
this.#status = { type: "resolved", value };
|
|
81
|
-
}
|
|
82
|
-
reject(error) {
|
|
83
|
-
if (this.#status.type !== "pending") {
|
|
84
|
-
throw new Error(`Cannot reject snapshot because it is already settled: ${this.#status.type}`);
|
|
85
|
-
}
|
|
86
|
-
this.#status = { type: "rejected", error };
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
exports.Snapshot = Snapshot;
|
package/dist/chunk-EFGXTO64.js
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
escapeString,
|
|
3
|
-
getTokenizer
|
|
4
|
-
} from "./chunk-5TRUJES5.js";
|
|
5
|
-
import {
|
|
6
|
-
chain_default,
|
|
7
|
-
countBy_default,
|
|
8
|
-
filter_default,
|
|
9
|
-
isEmpty_default,
|
|
10
|
-
isEqual_default,
|
|
11
|
-
isNil_default,
|
|
12
|
-
mapKeys_default,
|
|
13
|
-
orderBy_default,
|
|
14
|
-
uniqWith_default,
|
|
15
|
-
uniq_default
|
|
16
|
-
} from "./chunk-7WRN4E42.js";
|
|
17
|
-
|
|
18
|
-
// src/inspect.ts
|
|
19
|
-
import bytes from "bytes";
|
|
20
|
-
var SUBTITLE_LN = "--------------";
|
|
21
|
-
var SECTION_SEP = "\n";
|
|
22
|
-
var NUMBER_LOCALE = new Intl.NumberFormat("en-US");
|
|
23
|
-
var LONG_TEXT_LENGTH = 4096;
|
|
24
|
-
var DEFAULT_OPTIONS = {
|
|
25
|
-
tokens: 1e5
|
|
26
|
-
};
|
|
27
|
-
function printLimitedJson(obj, maxDepth, maxLength, maxKeys) {
|
|
28
|
-
const indent = 2;
|
|
29
|
-
let currentLength = 0;
|
|
30
|
-
let wasTruncated = false;
|
|
31
|
-
function recurse(currentObj, depth, currentIndent) {
|
|
32
|
-
if (depth > maxDepth || currentLength >= maxLength) {
|
|
33
|
-
wasTruncated = true;
|
|
34
|
-
return "...";
|
|
35
|
-
}
|
|
36
|
-
if (typeof currentObj === "object" && currentObj instanceof Date) {
|
|
37
|
-
currentIndent += 3;
|
|
38
|
-
try {
|
|
39
|
-
return currentObj.toISOString();
|
|
40
|
-
} catch (err) {
|
|
41
|
-
return `<Date: ${(err == null ? void 0 : err.message) ?? "Invalid Date"}>`;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (typeof currentObj !== "object" || currentObj === null) {
|
|
45
|
-
const value = JSON.stringify(currentObj);
|
|
46
|
-
currentLength += getTokenizer().count(value);
|
|
47
|
-
return value;
|
|
48
|
-
}
|
|
49
|
-
const indentation = " ".repeat(currentIndent);
|
|
50
|
-
if (Array.isArray(currentObj)) {
|
|
51
|
-
let result = "[\n";
|
|
52
|
-
for (let i = 0; i < currentObj.length && currentLength < maxLength; i++) {
|
|
53
|
-
if (i > 0) {
|
|
54
|
-
result += ",\n";
|
|
55
|
-
}
|
|
56
|
-
result += indentation + " ".repeat(indent) + recurse(currentObj[i], depth + 1, currentIndent + indent);
|
|
57
|
-
}
|
|
58
|
-
result += "\n" + indentation + "]";
|
|
59
|
-
currentLength += getTokenizer().count(result);
|
|
60
|
-
return result;
|
|
61
|
-
} else {
|
|
62
|
-
let result = "{\n";
|
|
63
|
-
const keys = Object.keys(currentObj);
|
|
64
|
-
const numKeys = keys.length;
|
|
65
|
-
for (let i = 0; i < Math.min(numKeys, maxKeys) && currentLength < maxLength; i++) {
|
|
66
|
-
const key = keys[i];
|
|
67
|
-
if (i > 0) {
|
|
68
|
-
result += ",\n";
|
|
69
|
-
}
|
|
70
|
-
const value = recurse(currentObj[key], depth + 1, currentIndent + indent);
|
|
71
|
-
result += indentation + " ".repeat(indent) + `"${key}": ${value}`;
|
|
72
|
-
}
|
|
73
|
-
if (numKeys > maxKeys) {
|
|
74
|
-
wasTruncated = true;
|
|
75
|
-
result += ",\n" + indentation + `... (${numKeys - maxKeys} more keys)`;
|
|
76
|
-
}
|
|
77
|
-
result += "\n" + indentation + "}";
|
|
78
|
-
currentLength += getTokenizer().count(result);
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const output = getTokenizer().truncate(recurse(obj, 0, 0), maxLength);
|
|
83
|
-
return { output, truncated: wasTruncated };
|
|
84
|
-
}
|
|
85
|
-
function extractType(value, generic = true) {
|
|
86
|
-
if (value === null) {
|
|
87
|
-
return "null";
|
|
88
|
-
}
|
|
89
|
-
if (value === void 0 || typeof value === "undefined") {
|
|
90
|
-
return "undefined";
|
|
91
|
-
}
|
|
92
|
-
if (typeof value === "object" && Array.isArray(value)) {
|
|
93
|
-
if (!generic) {
|
|
94
|
-
return "Array";
|
|
95
|
-
}
|
|
96
|
-
if (value.length === 0) {
|
|
97
|
-
return "Array (empty)";
|
|
98
|
-
}
|
|
99
|
-
if (value.length === 1) {
|
|
100
|
-
return `Array<${extractType(value[0])}>`;
|
|
101
|
-
}
|
|
102
|
-
const types = /* @__PURE__ */ new Map();
|
|
103
|
-
for (const element of value) {
|
|
104
|
-
const type = extractType(element, false);
|
|
105
|
-
types.set(type, (types.get(type) || 0) + 1);
|
|
106
|
-
}
|
|
107
|
-
if (types.size <= 3) {
|
|
108
|
-
return `Array<${Array.from(types.keys()).join(" | ")}>`;
|
|
109
|
-
}
|
|
110
|
-
return "Array";
|
|
111
|
-
}
|
|
112
|
-
if (typeof value === "number") {
|
|
113
|
-
return "number";
|
|
114
|
-
}
|
|
115
|
-
if (typeof value === "boolean") {
|
|
116
|
-
return "boolean";
|
|
117
|
-
}
|
|
118
|
-
if (typeof value === "bigint") {
|
|
119
|
-
return "bigint";
|
|
120
|
-
}
|
|
121
|
-
if (typeof value === "function") {
|
|
122
|
-
return "function";
|
|
123
|
-
}
|
|
124
|
-
if (typeof value === "object" && value instanceof Date) {
|
|
125
|
-
return "date";
|
|
126
|
-
}
|
|
127
|
-
if (typeof value === "object" && value instanceof RegExp) {
|
|
128
|
-
return "regexp";
|
|
129
|
-
}
|
|
130
|
-
if (value instanceof Error) {
|
|
131
|
-
return "error";
|
|
132
|
-
}
|
|
133
|
-
if (typeof value === "string" && value.trim().length === 0) {
|
|
134
|
-
return "<empty string>";
|
|
135
|
-
}
|
|
136
|
-
return typeof value;
|
|
137
|
-
}
|
|
138
|
-
function previewValue(value, length = LONG_TEXT_LENGTH) {
|
|
139
|
-
if (value === null) {
|
|
140
|
-
return "<nil>";
|
|
141
|
-
}
|
|
142
|
-
if (value === void 0) {
|
|
143
|
-
return "<undefined>";
|
|
144
|
-
}
|
|
145
|
-
const previewStr = (str) => {
|
|
146
|
-
if (str.length > length) {
|
|
147
|
-
return escapeString(str.slice(0, length)) + " ... <truncated>";
|
|
148
|
-
}
|
|
149
|
-
return escapeString(str);
|
|
150
|
-
};
|
|
151
|
-
const previewObj = (obj) => {
|
|
152
|
-
const mapped = mapKeys_default(obj, (_value, key) => previewStr(key));
|
|
153
|
-
return JSON.stringify(mapped);
|
|
154
|
-
};
|
|
155
|
-
if (typeof value === "string") {
|
|
156
|
-
return "<string> " + previewStr(value);
|
|
157
|
-
}
|
|
158
|
-
if (typeof value === "object" && Array.isArray(value)) {
|
|
159
|
-
return "<array> " + previewStr(JSON.stringify(value));
|
|
160
|
-
}
|
|
161
|
-
if (typeof value === "object" && value instanceof Date) {
|
|
162
|
-
return "<date> " + value.toISOString();
|
|
163
|
-
}
|
|
164
|
-
if (typeof value === "object" && value instanceof RegExp) {
|
|
165
|
-
return "<regexp> " + value.toString();
|
|
166
|
-
}
|
|
167
|
-
if (typeof value === "object") {
|
|
168
|
-
return "<object> " + previewObj(value);
|
|
169
|
-
}
|
|
170
|
-
if (typeof value === "bigint") {
|
|
171
|
-
return "<bigint> " + value.toString();
|
|
172
|
-
}
|
|
173
|
-
if (typeof value === "function") {
|
|
174
|
-
return "<function> " + value.toString();
|
|
175
|
-
}
|
|
176
|
-
if (typeof value === "boolean") {
|
|
177
|
-
return "<boolean> " + value.toString();
|
|
178
|
-
}
|
|
179
|
-
if (value instanceof Error) {
|
|
180
|
-
return "<error> " + previewError(value);
|
|
181
|
-
}
|
|
182
|
-
if (typeof value === "number") {
|
|
183
|
-
return "<number> " + value.toString();
|
|
184
|
-
}
|
|
185
|
-
if (typeof value === "symbol") {
|
|
186
|
-
return "<symbol> " + value.toString();
|
|
187
|
-
}
|
|
188
|
-
return `${typeof value} ` + ((value == null ? void 0 : value.toString()) ?? "<unknown>");
|
|
189
|
-
}
|
|
190
|
-
function previewError(err) {
|
|
191
|
-
const lines = [];
|
|
192
|
-
lines.push("Error: " + err.name);
|
|
193
|
-
lines.push(SUBTITLE_LN);
|
|
194
|
-
lines.push(previewValue(err.message));
|
|
195
|
-
lines.push(SECTION_SEP);
|
|
196
|
-
lines.push("Stack Trace:");
|
|
197
|
-
lines.push(SUBTITLE_LN);
|
|
198
|
-
lines.push(previewValue(err.stack ?? "<no stack trace>"));
|
|
199
|
-
return lines.join("\n");
|
|
200
|
-
}
|
|
201
|
-
function previewArray(arr) {
|
|
202
|
-
if (!Array.isArray(arr)) {
|
|
203
|
-
throw new Error("Expected an array");
|
|
204
|
-
}
|
|
205
|
-
const lines = [];
|
|
206
|
-
const getItemPreview = (value, index) => `[${index}]`.padEnd(15) + ` ${previewValue(value)}`;
|
|
207
|
-
if (arr.length === 0) {
|
|
208
|
-
lines.push("// Array Is Empty (0 element)");
|
|
209
|
-
return lines.join("\n").replace(/\n{2,}/g, SECTION_SEP);
|
|
210
|
-
}
|
|
211
|
-
if (arr.length <= 10) {
|
|
212
|
-
lines.push("// Full Array Preview");
|
|
213
|
-
lines.push(SUBTITLE_LN);
|
|
214
|
-
lines.push(...arr.map(getItemPreview));
|
|
215
|
-
return lines.join("\n").replace(/\n{2,}/g, SECTION_SEP);
|
|
216
|
-
}
|
|
217
|
-
lines.push("// Analysis Summary");
|
|
218
|
-
lines.push(SUBTITLE_LN);
|
|
219
|
-
const typesCount = countBy_default(arr, (item) => extractType(item, false));
|
|
220
|
-
const ordered = orderBy_default(
|
|
221
|
-
arr.filter((item) => !isNil_default(item) && JSON.stringify(item).length < 100),
|
|
222
|
-
(item) => JSON.stringify(item),
|
|
223
|
-
"asc"
|
|
224
|
-
);
|
|
225
|
-
const minValues = ordered.slice(0, 3).map((item) => previewValue(item, 10));
|
|
226
|
-
const maxValues = ordered.slice(-3).map((item) => previewValue(item, 10));
|
|
227
|
-
const uniqueItems = uniqWith_default(arr, isEqual_default);
|
|
228
|
-
const nullValues = filter_default(arr, isNil_default).length;
|
|
229
|
-
const memoryUsage = bytes(JSON.stringify(arr).length);
|
|
230
|
-
lines.push(`Total Items: ${arr.length}`);
|
|
231
|
-
lines.push(`Unique Items: ${uniqueItems.length}`);
|
|
232
|
-
lines.push(`Types: ${JSON.stringify(typesCount)}`);
|
|
233
|
-
lines.push(`Minimum Values: [${minValues.join(", ")}]`);
|
|
234
|
-
lines.push(`Maximum Values: [${maxValues.join(", ")}]`);
|
|
235
|
-
lines.push(`Memory Usage: ${memoryUsage}`);
|
|
236
|
-
lines.push(`Nil Values: ${nullValues}`);
|
|
237
|
-
lines.push("// Array Preview (truncated)");
|
|
238
|
-
lines.push(SUBTITLE_LN);
|
|
239
|
-
lines.push(...arr.map(getItemPreview));
|
|
240
|
-
return lines.join("\n").replace(/\n{2,}/g, SECTION_SEP);
|
|
241
|
-
}
|
|
242
|
-
function previewObject(obj, options) {
|
|
243
|
-
if (typeof obj !== "object" || Array.isArray(obj) || obj === null) {
|
|
244
|
-
throw new Error("Expected an object");
|
|
245
|
-
}
|
|
246
|
-
const lines = [];
|
|
247
|
-
const { output, truncated } = printLimitedJson(obj, 10, options.tokens, 20);
|
|
248
|
-
if (truncated) {
|
|
249
|
-
lines.push(SECTION_SEP);
|
|
250
|
-
lines.push("// Analysis Summary");
|
|
251
|
-
lines.push(SUBTITLE_LN);
|
|
252
|
-
const entries = Object.entries(obj);
|
|
253
|
-
const typesCount = chain_default(entries).countBy(([, value]) => extractType(value, false)).entries().orderBy(1, "desc").filter(([, count]) => count > 1).slice(0, 3).fromPairs().value();
|
|
254
|
-
const keys = Object.keys(obj);
|
|
255
|
-
const uniqueEntries = uniq_default(Object.values(obj));
|
|
256
|
-
const nilValues = filter_default(entries, ([, value]) => isNil_default(value)).length;
|
|
257
|
-
const memoryUsage = bytes(JSON.stringify(obj).length);
|
|
258
|
-
lines.push(`Total Entries: ${NUMBER_LOCALE.format(entries.length)}`);
|
|
259
|
-
lines.push(`Keys: ${previewValue(keys)}`);
|
|
260
|
-
lines.push(`Popular Types: ${previewValue(typesCount)}`);
|
|
261
|
-
lines.push(`Unique Values: ${NUMBER_LOCALE.format(uniqueEntries.length)}`);
|
|
262
|
-
lines.push(`Nil Values: ${NUMBER_LOCALE.format(nilValues)}`);
|
|
263
|
-
lines.push(`Memory Usage: ${memoryUsage}`);
|
|
264
|
-
}
|
|
265
|
-
if (isEmpty_default(obj)) {
|
|
266
|
-
lines.push("// Empty Object {}");
|
|
267
|
-
} else {
|
|
268
|
-
lines.push(truncated ? "// Object Preview (truncated)" : "// Full Object Preview");
|
|
269
|
-
lines.push(SUBTITLE_LN);
|
|
270
|
-
lines.push(output);
|
|
271
|
-
}
|
|
272
|
-
return lines.join("\n").replace(/\n{2,}/g, SECTION_SEP);
|
|
273
|
-
}
|
|
274
|
-
function previewLongText(text, length = LONG_TEXT_LENGTH) {
|
|
275
|
-
const lines = [];
|
|
276
|
-
const urlPattern = /https?:\/\/[^\s]+/g;
|
|
277
|
-
const emailPattern = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
|
|
278
|
-
lines.push("// The string is too long to fully display, here is a preview:");
|
|
279
|
-
const previewStr = (str) => {
|
|
280
|
-
if (str.length > length) {
|
|
281
|
-
return str.slice(0, length) + " ... <truncated>";
|
|
282
|
-
}
|
|
283
|
-
return str;
|
|
284
|
-
};
|
|
285
|
-
lines.push(previewStr(text));
|
|
286
|
-
lines.push(SUBTITLE_LN);
|
|
287
|
-
lines.push("// Analysis Summary");
|
|
288
|
-
lines.push(SUBTITLE_LN);
|
|
289
|
-
const words = text.split(/\s+/);
|
|
290
|
-
const wordCount = words.length;
|
|
291
|
-
const uniqueWords = uniq_default(words).length;
|
|
292
|
-
const wordFrequency = countBy_default(words);
|
|
293
|
-
const mostCommonWords = chain_default(wordFrequency).toPairs().orderBy(1, "desc").filter(([, count]) => count > 1).take(20).map(([word, count]) => `"${word}" ${count} times`).value().join("\n" + " ".repeat(22));
|
|
294
|
-
const urls = text.match(urlPattern) || [];
|
|
295
|
-
const emails = text.match(emailPattern) || [];
|
|
296
|
-
if (urls.length > 0) {
|
|
297
|
-
lines.push(`Found URLs: ${urls.length}`);
|
|
298
|
-
lines.push(`URLs: ${urls.join(", ")}`);
|
|
299
|
-
}
|
|
300
|
-
if (emails.length > 0) {
|
|
301
|
-
lines.push(`Found Emails: ${emails.length}`);
|
|
302
|
-
lines.push(`Emails: ${emails.join(", ")}`);
|
|
303
|
-
}
|
|
304
|
-
lines.push(`Length: ${NUMBER_LOCALE.format(text.length)} chars`);
|
|
305
|
-
lines.push(`Word Count: ${NUMBER_LOCALE.format(wordCount)} words`);
|
|
306
|
-
lines.push(`Unique Words: ${NUMBER_LOCALE.format(uniqueWords)}`);
|
|
307
|
-
lines.push(`Most Common Words: ${mostCommonWords}`);
|
|
308
|
-
return lines.join("\n").replace(/\n{2,}/g, SECTION_SEP);
|
|
309
|
-
}
|
|
310
|
-
var inspect = (value, name, options = DEFAULT_OPTIONS) => {
|
|
311
|
-
options ??= DEFAULT_OPTIONS;
|
|
312
|
-
options.tokens ??= DEFAULT_OPTIONS.tokens;
|
|
313
|
-
try {
|
|
314
|
-
const genericType = extractType(value, false);
|
|
315
|
-
let header = "";
|
|
316
|
-
if (name) {
|
|
317
|
-
header = `// const ${name}: ${genericType}
|
|
318
|
-
`;
|
|
319
|
-
}
|
|
320
|
-
if (genericType === "Array") {
|
|
321
|
-
return header + previewArray(value);
|
|
322
|
-
} else if (genericType === "error") {
|
|
323
|
-
return header + previewError(value);
|
|
324
|
-
} else if (genericType === "object") {
|
|
325
|
-
return header + previewObject(value, options);
|
|
326
|
-
} else if (genericType === "boolean") {
|
|
327
|
-
return header + previewValue(value);
|
|
328
|
-
} else if (typeof value === "string") {
|
|
329
|
-
if (getTokenizer().count(value) < options.tokens) {
|
|
330
|
-
return header + previewValue(value);
|
|
331
|
-
} else {
|
|
332
|
-
return header + previewLongText(value);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return header + previewValue(value);
|
|
336
|
-
} catch (err) {
|
|
337
|
-
return `Error: ${(err == null ? void 0 : err.message) ?? "Unknown Error"}`;
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
export {
|
|
342
|
-
extractType,
|
|
343
|
-
inspect
|
|
344
|
-
};
|