llmz 0.0.2

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.
Files changed (96) hide show
  1. package/README.md +41 -0
  2. package/dist/chunk-3CGLDS5T.cjs +3059 -0
  3. package/dist/chunk-3T465BEW.js +96 -0
  4. package/dist/chunk-6QDFMQHA.js +98 -0
  5. package/dist/chunk-7FIPXMZR.js +33 -0
  6. package/dist/chunk-7S3UY52U.js +3059 -0
  7. package/dist/chunk-A7BDFLAE.cjs +30 -0
  8. package/dist/chunk-BKGPO722.cjs +3079 -0
  9. package/dist/chunk-BOLDQGES.cjs +33 -0
  10. package/dist/chunk-C2TSWGYC.cjs +91 -0
  11. package/dist/chunk-DFZ6GX5C.js +220 -0
  12. package/dist/chunk-DILHJIMP.js +180 -0
  13. package/dist/chunk-E2B5DRIC.cjs +419 -0
  14. package/dist/chunk-E5W3P7EO.cjs +96 -0
  15. package/dist/chunk-ENFB45AI.cjs +220 -0
  16. package/dist/chunk-MSTBEKOQ.js +28 -0
  17. package/dist/chunk-PQN6HW7A.cjs +28 -0
  18. package/dist/chunk-Q4DEJGXD.js +344 -0
  19. package/dist/chunk-QPSUMPLP.js +419 -0
  20. package/dist/chunk-QZGFCB4T.cjs +344 -0
  21. package/dist/chunk-R2N2UUKC.cjs +98 -0
  22. package/dist/chunk-RB2L33ZR.js +3079 -0
  23. package/dist/chunk-RJHDQL4C.js +161 -0
  24. package/dist/chunk-UG2GCPHF.js +91 -0
  25. package/dist/chunk-UVSOAH2H.js +152 -0
  26. package/dist/chunk-VP6WWAE2.cjs +152 -0
  27. package/dist/chunk-YPOOKE3A.cjs +180 -0
  28. package/dist/chunk-YSQDPG26.js +30 -0
  29. package/dist/chunk-YUDUY7XW.cjs +284 -0
  30. package/dist/chunk-ZSRC3TN4.js +284 -0
  31. package/dist/chunk-ZUAFUOUR.cjs +161 -0
  32. package/dist/compiler/compiler.d.ts +28 -0
  33. package/dist/compiler/index.d.ts +2 -0
  34. package/dist/compiler/plugins/async-iterator.d.ts +4 -0
  35. package/dist/compiler/plugins/braces-tsx.d.ts +3 -0
  36. package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +5 -0
  37. package/dist/compiler/plugins/line-tracking.d.ts +5 -0
  38. package/dist/compiler/plugins/replace-comment.d.ts +5 -0
  39. package/dist/compiler/plugins/return-async.d.ts +4 -0
  40. package/dist/compiler/plugins/track-tool-calls.d.ts +16 -0
  41. package/dist/compiler/plugins/variable-extraction.d.ts +5 -0
  42. package/dist/component-DWBRHLEN.cjs +9 -0
  43. package/dist/component-R3ZAVXUC.js +9 -0
  44. package/dist/component.d.ts +51 -0
  45. package/dist/component.default.d.ts +10 -0
  46. package/dist/context.d.ts +167 -0
  47. package/dist/dual-modes-2VDEOJ5D.js +13 -0
  48. package/dist/dual-modes-3MH5N6RY.cjs +13 -0
  49. package/dist/errors.d.ts +64 -0
  50. package/dist/exit-GYMXZZ4I.js +9 -0
  51. package/dist/exit-PQHMJEOG.cjs +9 -0
  52. package/dist/exit.d.ts +20 -0
  53. package/dist/formatting.d.ts +5 -0
  54. package/dist/getter.d.ts +2 -0
  55. package/dist/handlers.d.ts +10 -0
  56. package/dist/hoist.d.ts +2 -0
  57. package/dist/index.cjs +811 -0
  58. package/dist/index.d.ts +18 -0
  59. package/dist/index.js +811 -0
  60. package/dist/inspect.d.ts +6 -0
  61. package/dist/jsx-CJ2RBODH.js +14 -0
  62. package/dist/jsx-PPLE5YTB.cjs +14 -0
  63. package/dist/jsx.d.ts +11 -0
  64. package/dist/llmz-EGTGPSTX.cjs +1049 -0
  65. package/dist/llmz-WY74UVE3.js +1049 -0
  66. package/dist/llmz.d.ts +41 -0
  67. package/dist/objects.d.ts +24 -0
  68. package/dist/openai.d.ts +8 -0
  69. package/dist/prompts/chat-mode/system.md.d.ts +2 -0
  70. package/dist/prompts/chat-mode/user.md.d.ts +2 -0
  71. package/dist/prompts/common.d.ts +6 -0
  72. package/dist/prompts/dual-modes.d.ts +2 -0
  73. package/dist/prompts/prompt.d.ts +50 -0
  74. package/dist/prompts/worker-mode/system.md.d.ts +2 -0
  75. package/dist/prompts/worker-mode/user.md.d.ts +2 -0
  76. package/dist/snapshots.d.ts +61 -0
  77. package/dist/stack-traces.d.ts +1 -0
  78. package/dist/tool-AY47ML65.cjs +12 -0
  79. package/dist/tool-WVIPESKN.js +12 -0
  80. package/dist/tool.d.ts +30 -0
  81. package/dist/transcript.d.ts +9 -0
  82. package/dist/truncator-MTONQESU.js +11 -0
  83. package/dist/truncator-ZKPOW2I3.cjs +11 -0
  84. package/dist/truncator.d.ts +21 -0
  85. package/dist/types.d.ts +131 -0
  86. package/dist/typings-HTYLRNIC.js +11 -0
  87. package/dist/typings-QRJGGNUM.cjs +11 -0
  88. package/dist/typings.d.ts +5 -0
  89. package/dist/utils-TS23YJPE.js +38 -0
  90. package/dist/utils-UR4IMUHC.cjs +38 -0
  91. package/dist/utils.d.ts +21 -0
  92. package/dist/vm-4JFSZAMR.cjs +13 -0
  93. package/dist/vm-SMMA664M.js +13 -0
  94. package/dist/vm.d.ts +3 -0
  95. package/package.json +85 -0
  96. package/patches/source-map-js@1.2.1.patch +16 -0
@@ -0,0 +1,220 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+
4
+
5
+
6
+
7
+ var _chunk3CGLDS5Tcjs = require('./chunk-3CGLDS5T.cjs');
8
+
9
+ // src/utils.ts
10
+ var _thicktoken = require('@bpinternal/thicktoken');
11
+ var _zui = require('@bpinternal/zui');
12
+ var tokenizer = null;
13
+ var init = async () => {
14
+ if (tokenizer) {
15
+ return;
16
+ }
17
+ while (typeof _thicktoken.getWasmTokenizer !== "function") {
18
+ await new Promise((resolve) => setTimeout(resolve, 50));
19
+ }
20
+ tokenizer = await _thicktoken.getWasmTokenizer.call(void 0, );
21
+ };
22
+ var getTokenizer = () => {
23
+ if (!tokenizer) {
24
+ throw new Error("Tokenizer not initialized, make sure to call init() first and await it");
25
+ }
26
+ return tokenizer;
27
+ };
28
+ var Tokens = (min, max) => {
29
+ return _zui.z.string().superRefine((value, ctx) => {
30
+ const tokens = tokenizer.count(value);
31
+ if (value.length < min) {
32
+ ctx.addIssue({
33
+ code: "too_small",
34
+ minimum: min,
35
+ type: "string",
36
+ message: `Text is ${tokens} but expected at least ${min} tokens`,
37
+ inclusive: true
38
+ });
39
+ }
40
+ if (value.length > max) {
41
+ ctx.addIssue({
42
+ code: "too_big",
43
+ maximum: max,
44
+ type: "string",
45
+ message: `Text is ${tokens} tokens but expected at most ${max} tokens`,
46
+ inclusive: true
47
+ });
48
+ }
49
+ return value;
50
+ });
51
+ };
52
+ var Identifier = _zui.z.string().min(1).max(100).regex(
53
+ /^([a-zA-Z_][a-zA-Z0-9_]*)$/,
54
+ "Identifiers must start with a letter and can only contain letters, numbers and underscores"
55
+ );
56
+ function escapeString(str) {
57
+ if (typeof str !== "string") {
58
+ return "";
59
+ }
60
+ const rawStr = String.raw`${str}`;
61
+ const escapedStr = rawStr.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, '\\"').replace(/'/g, "\\'");
62
+ if (escapedStr.includes("`")) {
63
+ return `"${escapedStr}"`;
64
+ } else if (escapedStr.includes("'")) {
65
+ return `"${escapedStr}"`;
66
+ } else {
67
+ return `'${escapedStr}'`;
68
+ }
69
+ }
70
+ var toPropertyKey = (key) => {
71
+ if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key)) {
72
+ return key;
73
+ }
74
+ return escapeString(key);
75
+ };
76
+ var trimEmptyLines = (lines) => {
77
+ var _a;
78
+ while (lines.length && !((_a = lines[0]) == null ? void 0 : _a.trim())) {
79
+ lines.shift();
80
+ }
81
+ while (lines.length && !lines[lines.length - 1].trim()) {
82
+ lines.pop();
83
+ }
84
+ };
85
+ var getMultilineComment = (description) => {
86
+ description = description == null ? void 0 : description.replace(/(\n(\s*)?){3,}/g, "\n\n");
87
+ const ensureLineStartsWithAsterisk = (line) => line.startsWith("* ") ? ` ${line}` : ` * ${line}`;
88
+ const escapeCommentEnd = (line) => line.replace(/\*\//g, "*\\/");
89
+ const descLines = (_nullishCoalesce(description, () => ( ""))).split("\n").map((line) => line.trim());
90
+ trimEmptyLines(descLines);
91
+ if (descLines.length) {
92
+ descLines[0] = descLines[0].replace(/^\/\*\*?/, "");
93
+ descLines[descLines.length - 1] = descLines[descLines.length - 1].replace(/\*\/$/, "");
94
+ }
95
+ trimEmptyLines(descLines);
96
+ return descLines.length === 0 ? "" : descLines.length === 1 ? `/** ${escapeCommentEnd(descLines[0])} */` : `/**
97
+ ${descLines.map(ensureLineStartsWithAsterisk).map(escapeCommentEnd).join("\n")}
98
+ */`;
99
+ };
100
+ var toValidFunctionName = (str) => {
101
+ let name = _chunk3CGLDS5Tcjs.deburr_default.call(void 0, str);
102
+ name = name.replace(/[^a-zA-Z0-9_$]/g, "");
103
+ if (!/^[a-zA-Z_$]/.test(name)) {
104
+ name = `_${name}`;
105
+ }
106
+ return _chunk3CGLDS5Tcjs.camelCase_default.call(void 0, name);
107
+ };
108
+ var awaitObject = async (obj) => {
109
+ const newObj = { ...obj };
110
+ const promises = [];
111
+ const setProp = async (key, value) => {
112
+ newObj[key] = await value;
113
+ };
114
+ for (const [key, value] of Object.entries(obj)) {
115
+ if (value instanceof Promise) {
116
+ promises.push(setProp(key, value));
117
+ } else if (_chunk3CGLDS5Tcjs.isPlainObject_default.call(void 0, value)) {
118
+ promises.push(setProp(key, await awaitObject(value)));
119
+ }
120
+ }
121
+ await Promise.all(promises);
122
+ return newObj;
123
+ };
124
+ var toValidObjectName = (str) => {
125
+ let name = _chunk3CGLDS5Tcjs.deburr_default.call(void 0, str);
126
+ name = name.split(/[^a-zA-Z0-9_$]/g).map(_chunk3CGLDS5Tcjs.startCase_default).join("");
127
+ if (!/^[a-zA-Z_$]/.test(name)) {
128
+ name = `_${name}`;
129
+ }
130
+ return name.replaceAll(" ", "");
131
+ };
132
+ var stripInvalidIdentifiers = (object) => {
133
+ if (typeof object !== "object") {
134
+ return object;
135
+ }
136
+ if (Array.isArray(object)) {
137
+ return object.map(stripInvalidIdentifiers);
138
+ }
139
+ return _chunk3CGLDS5Tcjs.pickBy_default.call(void 0, object, (__, key) => Identifier.safeParse(key).success);
140
+ };
141
+ var convertObjectToZuiLiterals = (obj, nested = false) => {
142
+ if (typeof obj === "string") {
143
+ return _zui.z.literal(obj).catch(() => obj);
144
+ }
145
+ if (typeof obj === "number") {
146
+ return _zui.z.literal(obj).catch(() => obj);
147
+ }
148
+ if (typeof obj === "boolean") {
149
+ return _zui.z.literal(obj).catch(() => obj);
150
+ }
151
+ if (Array.isArray(obj)) {
152
+ if (obj.length === 0) {
153
+ return _zui.z.tuple([]).catch(() => obj);
154
+ }
155
+ return _zui.z.tuple([
156
+ // the tuple needs to have at least one element
157
+ convertObjectToZuiLiterals(obj[0]),
158
+ ...obj.slice(1).map((child) => convertObjectToZuiLiterals(child))
159
+ ]).catch(() => obj);
160
+ }
161
+ if (obj !== null && typeof obj === "object") {
162
+ const shape = {};
163
+ for (const key in obj) {
164
+ shape[key] = convertObjectToZuiLiterals(obj[key], true);
165
+ }
166
+ if (nested) {
167
+ return _zui.z.object(shape).catch(() => shape);
168
+ }
169
+ return shape;
170
+ }
171
+ if (obj === void 0) {
172
+ return _zui.z.undefined().catch(() => void 0);
173
+ }
174
+ if (obj === null) {
175
+ return _zui.z.null().catch(() => null);
176
+ }
177
+ throw new Error(`Unsupported object type ${typeof obj}, ${obj})`);
178
+ };
179
+ var isValidSchema = (schema) => {
180
+ try {
181
+ _zui.z.fromJsonSchema(schema);
182
+ return typeof schema.type === "string";
183
+ } catch (e) {
184
+ return false;
185
+ }
186
+ };
187
+ function isJsonSchema(schema) {
188
+ return !!schema && typeof schema === "object" && ("$schema" in schema || "type" in schema || "properties" in schema);
189
+ }
190
+ function isValidIdentifier(name) {
191
+ if (typeof name !== "string") {
192
+ return false;
193
+ }
194
+ return /^[A-Z]{1,}[A-Z0-9_]{0,50}$/i.test(name);
195
+ }
196
+ function isValidMessageName(name) {
197
+ if (typeof name !== "string") {
198
+ return false;
199
+ }
200
+ return /^[A-Z]{1,50}$/i.test(name);
201
+ }
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+ exports.init = init; exports.getTokenizer = getTokenizer; exports.Tokens = Tokens; exports.Identifier = Identifier; exports.escapeString = escapeString; exports.toPropertyKey = toPropertyKey; exports.getMultilineComment = getMultilineComment; exports.toValidFunctionName = toValidFunctionName; exports.awaitObject = awaitObject; exports.toValidObjectName = toValidObjectName; exports.stripInvalidIdentifiers = stripInvalidIdentifiers; exports.convertObjectToZuiLiterals = convertObjectToZuiLiterals; exports.isValidSchema = isValidSchema; exports.isJsonSchema = isJsonSchema; exports.isValidIdentifier = isValidIdentifier; exports.isValidMessageName = isValidMessageName;
@@ -0,0 +1,28 @@
1
+ // src/stack-traces.ts
2
+ var isInternalLine = (line) => {
3
+ return line.includes("llmz/src/") || line.includes("\\llmz\\src\\") || line.includes("node_modules");
4
+ };
5
+ function cleanStackTrace(stack, cleanInternal = true) {
6
+ const lines = stack.split("\n");
7
+ for (let i = 0; i < lines.length; i++) {
8
+ const line = lines[i];
9
+ let llmzIndex = line.indexOf("llmz/src/");
10
+ if (llmzIndex === -1) {
11
+ llmzIndex = line.indexOf("\\llmz\\src\\");
12
+ }
13
+ if (llmzIndex === -1) {
14
+ continue;
15
+ }
16
+ let lastSpaceIndex = line.lastIndexOf(" ", llmzIndex);
17
+ if (lastSpaceIndex === -1) {
18
+ lastSpaceIndex = 0;
19
+ }
20
+ const maybeParen = line[lastSpaceIndex + 1] === "(" ? "(" : "";
21
+ lines[i] = line.slice(0, lastSpaceIndex + 1) + maybeParen + line.slice(llmzIndex);
22
+ }
23
+ return lines.filter((x) => !cleanInternal || !isInternalLine(x)).join("\n");
24
+ }
25
+
26
+ export {
27
+ cleanStackTrace
28
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/stack-traces.ts
2
+ var isInternalLine = (line) => {
3
+ return line.includes("llmz/src/") || line.includes("\\llmz\\src\\") || line.includes("node_modules");
4
+ };
5
+ function cleanStackTrace(stack, cleanInternal = true) {
6
+ const lines = stack.split("\n");
7
+ for (let i = 0; i < lines.length; i++) {
8
+ const line = lines[i];
9
+ let llmzIndex = line.indexOf("llmz/src/");
10
+ if (llmzIndex === -1) {
11
+ llmzIndex = line.indexOf("\\llmz\\src\\");
12
+ }
13
+ if (llmzIndex === -1) {
14
+ continue;
15
+ }
16
+ let lastSpaceIndex = line.lastIndexOf(" ", llmzIndex);
17
+ if (lastSpaceIndex === -1) {
18
+ lastSpaceIndex = 0;
19
+ }
20
+ const maybeParen = line[lastSpaceIndex + 1] === "(" ? "(" : "";
21
+ lines[i] = line.slice(0, lastSpaceIndex + 1) + maybeParen + line.slice(llmzIndex);
22
+ }
23
+ return lines.filter((x) => !cleanInternal || !isInternalLine(x)).join("\n");
24
+ }
25
+
26
+
27
+
28
+ exports.cleanStackTrace = cleanStackTrace;
@@ -0,0 +1,344 @@
1
+ import {
2
+ escapeString,
3
+ getTokenizer
4
+ } from "./chunk-DFZ6GX5C.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-7S3UY52U.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
+ };