@dexto/core 1.1.4
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/LICENSE +44 -0
- package/dist/chunk-D62MHQBE.js +2203 -0
- package/dist/chunk-F2QFAECT.js +87 -0
- package/dist/chunk-FCJVTIBV.js +535 -0
- package/dist/chunk-J6AXCN3H.js +1268 -0
- package/dist/chunk-MVKLS3LM.js +43 -0
- package/dist/chunk-PI6XFMEW.js +141 -0
- package/dist/chunk-TPERKLLN.js +75 -0
- package/dist/chunk-XFQLRBHE.js +122 -0
- package/dist/errors-ZZ4Z3FKB.js +10 -0
- package/dist/index.browser.cjs +250 -0
- package/dist/index.browser.d.cts +379 -0
- package/dist/index.browser.d.ts +379 -0
- package/dist/index.browser.js +217 -0
- package/dist/index.cjs +15283 -0
- package/dist/index.d.cts +6842 -0
- package/dist/index.d.ts +6842 -0
- package/dist/index.js +9914 -0
- package/dist/loader-HBNEYPQZ.js +20 -0
- package/dist/path-TP7WBDED.js +21 -0
- package/dist/postgres-backend-WMWS7RAT.js +216 -0
- package/dist/redis-backend-BNLN3XHX.js +169 -0
- package/dist/registry-Z4DFXODW.js +14 -0
- package/dist/sqlite-backend-AR6XNK2Q.js +248 -0
- package/package.json +61 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
10
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
|
|
30
|
+
// ../../node_modules/.pnpm/tsup@8.5.0_jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.2_yaml@2.8.1/node_modules/tsup/assets/esm_shims.js
|
|
31
|
+
import path from "path";
|
|
32
|
+
import { fileURLToPath } from "url";
|
|
33
|
+
var init_esm_shims = __esm({
|
|
34
|
+
"../../node_modules/.pnpm/tsup@8.5.0_jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.2_yaml@2.8.1/node_modules/tsup/assets/esm_shims.js"() {
|
|
35
|
+
"use strict";
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
__commonJS,
|
|
41
|
+
__toESM,
|
|
42
|
+
init_esm_shims
|
|
43
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DextoRuntimeError
|
|
3
|
+
} from "./chunk-TPERKLLN.js";
|
|
4
|
+
import {
|
|
5
|
+
init_esm_shims
|
|
6
|
+
} from "./chunk-MVKLS3LM.js";
|
|
7
|
+
|
|
8
|
+
// src/agent/registry/errors.ts
|
|
9
|
+
init_esm_shims();
|
|
10
|
+
var RegistryError = class {
|
|
11
|
+
// Agent lookup errors
|
|
12
|
+
static agentNotFound(agentName, availableAgents) {
|
|
13
|
+
return new DextoRuntimeError(
|
|
14
|
+
"registry_agent_not_found" /* AGENT_NOT_FOUND */,
|
|
15
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
16
|
+
"user" /* USER */,
|
|
17
|
+
`Agent '${agentName}' not found in registry`,
|
|
18
|
+
{ agentName, availableAgents },
|
|
19
|
+
`Available agents: ${availableAgents.join(", ")}. Use a file path for custom agents.`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
static agentInvalidEntry(agentName, reason) {
|
|
23
|
+
return new DextoRuntimeError(
|
|
24
|
+
"registry_agent_invalid_entry" /* AGENT_INVALID_ENTRY */,
|
|
25
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
26
|
+
"system" /* SYSTEM */,
|
|
27
|
+
`Registry entry for '${agentName}' is invalid: ${reason}`,
|
|
28
|
+
{ agentName, reason },
|
|
29
|
+
"This indicates a problem with the agent registry - please report this issue"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
// Installation errors
|
|
33
|
+
static installationFailed(agentName, cause) {
|
|
34
|
+
return new DextoRuntimeError(
|
|
35
|
+
"registry_installation_failed" /* INSTALLATION_FAILED */,
|
|
36
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
37
|
+
"system" /* SYSTEM */,
|
|
38
|
+
`Failed to install agent '${agentName}': ${cause}`,
|
|
39
|
+
{ agentName, cause },
|
|
40
|
+
"Check network connection and available disk space"
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
static installationValidationFailed(agentName, missingPath) {
|
|
44
|
+
return new DextoRuntimeError(
|
|
45
|
+
"registry_installation_validation_failed" /* INSTALLATION_VALIDATION_FAILED */,
|
|
46
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
47
|
+
"system" /* SYSTEM */,
|
|
48
|
+
`Installation validation failed for '${agentName}': missing main config`,
|
|
49
|
+
{ agentName, missingPath },
|
|
50
|
+
"This indicates a problem with the agent bundle - please report this issue"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
// Config file errors
|
|
54
|
+
static configNotFound(configPath) {
|
|
55
|
+
return new DextoRuntimeError(
|
|
56
|
+
"registry_config_not_found" /* CONFIG_NOT_FOUND */,
|
|
57
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
58
|
+
"system" /* SYSTEM */,
|
|
59
|
+
`Agent config file not found: ${configPath}`,
|
|
60
|
+
{ configPath },
|
|
61
|
+
"This indicates a problem with the agent installation"
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
static mainConfigMissing(agentName, expectedPath) {
|
|
65
|
+
return new DextoRuntimeError(
|
|
66
|
+
"registry_main_config_missing" /* MAIN_CONFIG_MISSING */,
|
|
67
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
68
|
+
"system" /* SYSTEM */,
|
|
69
|
+
`Main config file not found for agent '${agentName}': ${expectedPath}`,
|
|
70
|
+
{ agentName, expectedPath },
|
|
71
|
+
"This indicates a problem with the agent bundle structure"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
// Uninstallation errors
|
|
75
|
+
static agentNotInstalled(agentName) {
|
|
76
|
+
return new DextoRuntimeError(
|
|
77
|
+
"registry_agent_not_installed" /* AGENT_NOT_INSTALLED */,
|
|
78
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
79
|
+
"user" /* USER */,
|
|
80
|
+
`Agent '${agentName}' is not installed`,
|
|
81
|
+
{ agentName },
|
|
82
|
+
'Use "dexto list-agents --installed" to see installed agents'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
static agentProtected(agentName) {
|
|
86
|
+
return new DextoRuntimeError(
|
|
87
|
+
"registry_agent_protected" /* AGENT_PROTECTED */,
|
|
88
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
89
|
+
"user" /* USER */,
|
|
90
|
+
`Agent '${agentName}' is protected and cannot be uninstalled. Use --force to override (not recommended for critical agents)`,
|
|
91
|
+
{ agentName },
|
|
92
|
+
"Use --force to override (not recommended for critical agents)"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
static uninstallationFailed(agentName, cause) {
|
|
96
|
+
return new DextoRuntimeError(
|
|
97
|
+
"registry_uninstallation_failed" /* UNINSTALLATION_FAILED */,
|
|
98
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
99
|
+
"system" /* SYSTEM */,
|
|
100
|
+
`Failed to uninstall agent '${agentName}': ${cause}`,
|
|
101
|
+
{ agentName, cause },
|
|
102
|
+
"Check file permissions and ensure no processes are using the agent"
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
// Registry file errors
|
|
106
|
+
static registryNotFound(registryPath) {
|
|
107
|
+
return new DextoRuntimeError(
|
|
108
|
+
"registry_file_not_found" /* REGISTRY_NOT_FOUND */,
|
|
109
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
110
|
+
"system" /* SYSTEM */,
|
|
111
|
+
`Agent registry not found: ${registryPath}`,
|
|
112
|
+
{ registryPath },
|
|
113
|
+
"This indicates a problem with the Dexto installation - please reinstall or report this issue"
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
static registryParseError(registryPath, cause) {
|
|
117
|
+
return new DextoRuntimeError(
|
|
118
|
+
"registry_parse_error" /* REGISTRY_PARSE_ERROR */,
|
|
119
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
120
|
+
"system" /* SYSTEM */,
|
|
121
|
+
`Failed to parse agent registry from ${registryPath}: ${cause}`,
|
|
122
|
+
{ registryPath, cause },
|
|
123
|
+
"This indicates a corrupted registry file - please reinstall Dexto"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
// Auto-install control errors
|
|
127
|
+
static agentNotInstalledAutoInstallDisabled(agentName, availableAgents) {
|
|
128
|
+
return new DextoRuntimeError(
|
|
129
|
+
"registry_agent_not_installed_auto_install_disabled" /* AGENT_NOT_INSTALLED_AUTO_INSTALL_DISABLED */,
|
|
130
|
+
"agent_registry" /* AGENT_REGISTRY */,
|
|
131
|
+
"user" /* USER */,
|
|
132
|
+
`Agent '${agentName}' is not installed locally and auto-install is disabled`,
|
|
133
|
+
{ agentName, availableAgents },
|
|
134
|
+
`Use 'dexto install ${agentName}' to install it manually, or use a file path for custom agents`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export {
|
|
140
|
+
RegistryError
|
|
141
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_esm_shims
|
|
3
|
+
} from "./chunk-MVKLS3LM.js";
|
|
4
|
+
|
|
5
|
+
// src/errors/DextoBaseError.ts
|
|
6
|
+
init_esm_shims();
|
|
7
|
+
import { randomUUID } from "crypto";
|
|
8
|
+
var DextoBaseError = class extends Error {
|
|
9
|
+
traceId;
|
|
10
|
+
constructor(message, traceId) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.traceId = traceId || randomUUID();
|
|
13
|
+
this.name = this.constructor.name;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/errors/DextoRuntimeError.ts
|
|
18
|
+
init_esm_shims();
|
|
19
|
+
var DextoRuntimeError = class extends DextoBaseError {
|
|
20
|
+
constructor(code, scope, type, message, context, recovery, traceId) {
|
|
21
|
+
super(message, traceId);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.scope = scope;
|
|
24
|
+
this.type = type;
|
|
25
|
+
this.context = context;
|
|
26
|
+
this.recovery = recovery;
|
|
27
|
+
this.name = "DextoRuntimeError";
|
|
28
|
+
}
|
|
29
|
+
toJSON() {
|
|
30
|
+
return {
|
|
31
|
+
code: this.code,
|
|
32
|
+
message: this.message,
|
|
33
|
+
scope: this.scope,
|
|
34
|
+
type: this.type,
|
|
35
|
+
context: this.context,
|
|
36
|
+
recovery: this.recovery,
|
|
37
|
+
traceId: this.traceId
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/errors/types.ts
|
|
43
|
+
init_esm_shims();
|
|
44
|
+
var ErrorScope = /* @__PURE__ */ ((ErrorScope2) => {
|
|
45
|
+
ErrorScope2["LLM"] = "llm";
|
|
46
|
+
ErrorScope2["AGENT"] = "agent";
|
|
47
|
+
ErrorScope2["CONFIG"] = "config";
|
|
48
|
+
ErrorScope2["CONTEXT"] = "context";
|
|
49
|
+
ErrorScope2["SESSION"] = "session";
|
|
50
|
+
ErrorScope2["MCP"] = "mcp";
|
|
51
|
+
ErrorScope2["TOOLS"] = "tools";
|
|
52
|
+
ErrorScope2["STORAGE"] = "storage";
|
|
53
|
+
ErrorScope2["SYSTEM_PROMPT"] = "system_prompt";
|
|
54
|
+
ErrorScope2["PREFERENCE"] = "preference";
|
|
55
|
+
ErrorScope2["AGENT_REGISTRY"] = "agent_registry";
|
|
56
|
+
return ErrorScope2;
|
|
57
|
+
})(ErrorScope || {});
|
|
58
|
+
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
59
|
+
ErrorType2["USER"] = "user";
|
|
60
|
+
ErrorType2["NOT_FOUND"] = "not_found";
|
|
61
|
+
ErrorType2["FORBIDDEN"] = "forbidden";
|
|
62
|
+
ErrorType2["TIMEOUT"] = "timeout";
|
|
63
|
+
ErrorType2["RATE_LIMIT"] = "rate_limit";
|
|
64
|
+
ErrorType2["SYSTEM"] = "system";
|
|
65
|
+
ErrorType2["THIRD_PARTY"] = "third_party";
|
|
66
|
+
ErrorType2["UNKNOWN"] = "unknown";
|
|
67
|
+
return ErrorType2;
|
|
68
|
+
})(ErrorType || {});
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
DextoBaseError,
|
|
72
|
+
DextoRuntimeError,
|
|
73
|
+
ErrorScope,
|
|
74
|
+
ErrorType
|
|
75
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logger
|
|
3
|
+
} from "./chunk-D62MHQBE.js";
|
|
4
|
+
import {
|
|
5
|
+
DextoBaseError
|
|
6
|
+
} from "./chunk-TPERKLLN.js";
|
|
7
|
+
import {
|
|
8
|
+
init_esm_shims
|
|
9
|
+
} from "./chunk-MVKLS3LM.js";
|
|
10
|
+
|
|
11
|
+
// src/errors/DextoValidationError.ts
|
|
12
|
+
init_esm_shims();
|
|
13
|
+
var DextoValidationError = class _DextoValidationError extends DextoBaseError {
|
|
14
|
+
issues;
|
|
15
|
+
constructor(issues) {
|
|
16
|
+
const message = _DextoValidationError.formatMessage(issues);
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "DextoValidationError";
|
|
19
|
+
this.issues = issues;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Format multiple issues into a readable error message
|
|
23
|
+
*/
|
|
24
|
+
static formatMessage(issues) {
|
|
25
|
+
if (issues.length === 0) {
|
|
26
|
+
return "Validation failed";
|
|
27
|
+
}
|
|
28
|
+
if (issues.length === 1) {
|
|
29
|
+
return issues[0].message;
|
|
30
|
+
}
|
|
31
|
+
const errors = issues.filter((i) => i.severity === "error");
|
|
32
|
+
const warnings = issues.filter((i) => i.severity === "warning");
|
|
33
|
+
const parts = [];
|
|
34
|
+
if (errors.length > 0) {
|
|
35
|
+
parts.push(`${errors.length} error${errors.length > 1 ? "s" : ""}`);
|
|
36
|
+
}
|
|
37
|
+
if (warnings.length > 0) {
|
|
38
|
+
parts.push(`${warnings.length} warning${warnings.length > 1 ? "s" : ""}`);
|
|
39
|
+
}
|
|
40
|
+
return `Validation failed with ${parts.join(" and ")}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get only error-severity issues
|
|
44
|
+
*/
|
|
45
|
+
get errors() {
|
|
46
|
+
return this.issues.filter((i) => i.severity === "error");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get only warning-severity issues
|
|
50
|
+
*/
|
|
51
|
+
get warnings() {
|
|
52
|
+
return this.issues.filter((i) => i.severity === "warning");
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if there are any error-severity issues
|
|
56
|
+
*/
|
|
57
|
+
hasErrors() {
|
|
58
|
+
return this.errors.length > 0;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if there are any warning-severity issues
|
|
62
|
+
*/
|
|
63
|
+
hasWarnings() {
|
|
64
|
+
return this.warnings.length > 0;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the first error-severity issue (if any)
|
|
68
|
+
* Useful for getting the primary error when multiple exist
|
|
69
|
+
*/
|
|
70
|
+
get firstError() {
|
|
71
|
+
return this.errors[0];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the first warning-severity issue (if any)
|
|
75
|
+
*/
|
|
76
|
+
get firstWarning() {
|
|
77
|
+
return this.warnings[0];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Format issues for display
|
|
81
|
+
* Returns an object with categorized issues for easy logging
|
|
82
|
+
*/
|
|
83
|
+
format() {
|
|
84
|
+
return {
|
|
85
|
+
errors: this.errors.map((e) => `[${e.code}] ${e.message}`),
|
|
86
|
+
warnings: this.warnings.map((w) => `[${w.code}] ${w.message}`)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Convert to JSON representation
|
|
91
|
+
*/
|
|
92
|
+
toJSON() {
|
|
93
|
+
return {
|
|
94
|
+
name: this.name,
|
|
95
|
+
message: this.message,
|
|
96
|
+
issues: this.issues,
|
|
97
|
+
traceId: this.traceId,
|
|
98
|
+
errorCount: this.errors.length,
|
|
99
|
+
warningCount: this.warnings.length
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/errors/result-bridge.ts
|
|
105
|
+
init_esm_shims();
|
|
106
|
+
function ensureOk(result) {
|
|
107
|
+
if (result.ok) {
|
|
108
|
+
return result.data;
|
|
109
|
+
}
|
|
110
|
+
logger.error(
|
|
111
|
+
`ensureOk: found validation errors, throwing DextoValidationError: ${result.issues}`
|
|
112
|
+
);
|
|
113
|
+
throw new DextoValidationError(result.issues);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/errors/index.ts
|
|
117
|
+
init_esm_shims();
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
DextoValidationError,
|
|
121
|
+
ensureOk
|
|
122
|
+
};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.browser.ts
|
|
21
|
+
var index_browser_exports = {};
|
|
22
|
+
__export(index_browser_exports, {
|
|
23
|
+
ErrorScope: () => ErrorScope,
|
|
24
|
+
ErrorType: () => ErrorType,
|
|
25
|
+
LLM_PROVIDERS: () => LLM_PROVIDERS,
|
|
26
|
+
LLM_ROUTERS: () => LLM_ROUTERS,
|
|
27
|
+
SUPPORTED_FILE_TYPES: () => SUPPORTED_FILE_TYPES,
|
|
28
|
+
toError: () => toError,
|
|
29
|
+
zodToIssues: () => zodToIssues
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_browser_exports);
|
|
32
|
+
|
|
33
|
+
// src/utils/redactor.ts
|
|
34
|
+
var SENSITIVE_FIELDS = [
|
|
35
|
+
"apikey",
|
|
36
|
+
"api_key",
|
|
37
|
+
"token",
|
|
38
|
+
"access_token",
|
|
39
|
+
"refresh_token",
|
|
40
|
+
"password",
|
|
41
|
+
"secret"
|
|
42
|
+
];
|
|
43
|
+
var FILE_DATA_FIELDS = [
|
|
44
|
+
"base64",
|
|
45
|
+
"filedata",
|
|
46
|
+
"file_data",
|
|
47
|
+
"imagedata",
|
|
48
|
+
"image_data",
|
|
49
|
+
"audiodata",
|
|
50
|
+
"audio_data",
|
|
51
|
+
"data"
|
|
52
|
+
];
|
|
53
|
+
var SENSITIVE_PATTERNS = [
|
|
54
|
+
/\bsk-[A-Za-z0-9]{20,}\b/g,
|
|
55
|
+
// OpenAI API keys (at least 20 chars after sk-)
|
|
56
|
+
/\bBearer\s+[A-Za-z0-9\-_.=]+\b/gi,
|
|
57
|
+
// Bearer tokens
|
|
58
|
+
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
|
|
59
|
+
// Emails
|
|
60
|
+
/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*/g
|
|
61
|
+
// JWT tokens
|
|
62
|
+
];
|
|
63
|
+
var REDACTED = "[REDACTED]";
|
|
64
|
+
var REDACTED_CIRCULAR = "[REDACTED_CIRCULAR]";
|
|
65
|
+
var FILE_DATA_TRUNCATED = "[FILE_DATA_TRUNCATED]";
|
|
66
|
+
function isLargeBase64Data(value) {
|
|
67
|
+
return value.length > 1e3 && /^[A-Za-z0-9+/=]{1000,}$/.test(value.substring(0, 1e3));
|
|
68
|
+
}
|
|
69
|
+
function truncateFileData(value, key, parent) {
|
|
70
|
+
if (typeof value !== "string") return value;
|
|
71
|
+
const lowerKey = key.toLowerCase();
|
|
72
|
+
const hasFileContext = !!parent && ("mimeType" in parent || "filename" in parent || "fileName" in parent);
|
|
73
|
+
const looksLikeFileField = FILE_DATA_FIELDS.includes(lowerKey) || lowerKey === "data" && hasFileContext;
|
|
74
|
+
if (looksLikeFileField && isLargeBase64Data(value)) {
|
|
75
|
+
return `${FILE_DATA_TRUNCATED} (${value.length} chars)`;
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
|
|
80
|
+
if (typeof input === "string") {
|
|
81
|
+
let result = input;
|
|
82
|
+
for (const pattern of SENSITIVE_PATTERNS) {
|
|
83
|
+
result = result.replace(pattern, REDACTED);
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
if (Array.isArray(input)) {
|
|
88
|
+
if (seen.has(input)) return REDACTED_CIRCULAR;
|
|
89
|
+
seen.add(input);
|
|
90
|
+
return input.map((item) => redactSensitiveData(item, seen));
|
|
91
|
+
}
|
|
92
|
+
if (input && typeof input === "object") {
|
|
93
|
+
if (seen.has(input)) return REDACTED_CIRCULAR;
|
|
94
|
+
seen.add(input);
|
|
95
|
+
const result = {};
|
|
96
|
+
for (const [key, value] of Object.entries(input)) {
|
|
97
|
+
if (SENSITIVE_FIELDS.includes(key.toLowerCase())) {
|
|
98
|
+
result[key] = REDACTED;
|
|
99
|
+
} else {
|
|
100
|
+
const truncatedValue = truncateFileData(
|
|
101
|
+
value,
|
|
102
|
+
key,
|
|
103
|
+
input
|
|
104
|
+
);
|
|
105
|
+
result[key] = redactSensitiveData(truncatedValue, seen);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
return input;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/utils/safe-stringify.ts
|
|
114
|
+
function safeStringify(value, maxLen = 1e3) {
|
|
115
|
+
try {
|
|
116
|
+
if (typeof value === "bigint") {
|
|
117
|
+
return value.toString();
|
|
118
|
+
}
|
|
119
|
+
const redacted = redactSensitiveData(value);
|
|
120
|
+
const str = JSON.stringify(redacted, (_, v) => {
|
|
121
|
+
if (v instanceof Error) {
|
|
122
|
+
return { name: v.name, message: v.message, stack: v.stack };
|
|
123
|
+
}
|
|
124
|
+
if (typeof v === "bigint") return v.toString();
|
|
125
|
+
return v;
|
|
126
|
+
});
|
|
127
|
+
const indicator = "\u2026(truncated)";
|
|
128
|
+
const limit = Number.isFinite(maxLen) && maxLen > 0 ? Math.floor(maxLen) : 1e3;
|
|
129
|
+
if (typeof str === "string") {
|
|
130
|
+
if (str.length <= limit) return str;
|
|
131
|
+
const sliceLen = Math.max(0, limit - indicator.length);
|
|
132
|
+
return `${str.slice(0, sliceLen)}${indicator}`;
|
|
133
|
+
}
|
|
134
|
+
return String(value);
|
|
135
|
+
} catch {
|
|
136
|
+
try {
|
|
137
|
+
return String(value);
|
|
138
|
+
} catch {
|
|
139
|
+
return "[Unserializable value]";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/utils/error-conversion.ts
|
|
145
|
+
function toError(error) {
|
|
146
|
+
if (error instanceof Error) {
|
|
147
|
+
return error;
|
|
148
|
+
}
|
|
149
|
+
if (error && typeof error === "object") {
|
|
150
|
+
if ("message" in error && typeof error.message === "string") {
|
|
151
|
+
return new Error(error.message, { cause: error });
|
|
152
|
+
}
|
|
153
|
+
if ("error" in error && typeof error.error === "string") {
|
|
154
|
+
return new Error(error.error, { cause: error });
|
|
155
|
+
}
|
|
156
|
+
if ("details" in error && typeof error.details === "string") {
|
|
157
|
+
return new Error(error.details, { cause: error });
|
|
158
|
+
}
|
|
159
|
+
if ("description" in error && typeof error.description === "string") {
|
|
160
|
+
return new Error(error.description, { cause: error });
|
|
161
|
+
}
|
|
162
|
+
const serialized = safeStringify(error);
|
|
163
|
+
return new Error(serialized);
|
|
164
|
+
}
|
|
165
|
+
if (typeof error === "string") {
|
|
166
|
+
return new Error(error, { cause: error });
|
|
167
|
+
}
|
|
168
|
+
return new Error(String(error), { cause: error });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/utils/result.ts
|
|
172
|
+
var import_zod = require("zod");
|
|
173
|
+
|
|
174
|
+
// src/errors/types.ts
|
|
175
|
+
var ErrorScope = /* @__PURE__ */ ((ErrorScope2) => {
|
|
176
|
+
ErrorScope2["LLM"] = "llm";
|
|
177
|
+
ErrorScope2["AGENT"] = "agent";
|
|
178
|
+
ErrorScope2["CONFIG"] = "config";
|
|
179
|
+
ErrorScope2["CONTEXT"] = "context";
|
|
180
|
+
ErrorScope2["SESSION"] = "session";
|
|
181
|
+
ErrorScope2["MCP"] = "mcp";
|
|
182
|
+
ErrorScope2["TOOLS"] = "tools";
|
|
183
|
+
ErrorScope2["STORAGE"] = "storage";
|
|
184
|
+
ErrorScope2["SYSTEM_PROMPT"] = "system_prompt";
|
|
185
|
+
ErrorScope2["PREFERENCE"] = "preference";
|
|
186
|
+
ErrorScope2["AGENT_REGISTRY"] = "agent_registry";
|
|
187
|
+
return ErrorScope2;
|
|
188
|
+
})(ErrorScope || {});
|
|
189
|
+
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
190
|
+
ErrorType2["USER"] = "user";
|
|
191
|
+
ErrorType2["NOT_FOUND"] = "not_found";
|
|
192
|
+
ErrorType2["FORBIDDEN"] = "forbidden";
|
|
193
|
+
ErrorType2["TIMEOUT"] = "timeout";
|
|
194
|
+
ErrorType2["RATE_LIMIT"] = "rate_limit";
|
|
195
|
+
ErrorType2["SYSTEM"] = "system";
|
|
196
|
+
ErrorType2["THIRD_PARTY"] = "third_party";
|
|
197
|
+
ErrorType2["UNKNOWN"] = "unknown";
|
|
198
|
+
return ErrorType2;
|
|
199
|
+
})(ErrorType || {});
|
|
200
|
+
|
|
201
|
+
// src/utils/result.ts
|
|
202
|
+
var NonEmptyTrimmed = import_zod.z.string().transform((s) => s.trim()).refine((s) => s.length > 0, { message: "Required" });
|
|
203
|
+
function isValidUrl(s) {
|
|
204
|
+
try {
|
|
205
|
+
const u = new URL(s);
|
|
206
|
+
return u.protocol === "http:" || u.protocol === "https:";
|
|
207
|
+
} catch {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
var OptionalURL = import_zod.z.string().transform((s) => s.trim()).refine((s) => s === "" || isValidUrl(s), { message: "Invalid URL" }).transform((s) => s === "" ? void 0 : s).optional();
|
|
212
|
+
function zodToIssues(err, severity = "error") {
|
|
213
|
+
return err.errors.map((e) => {
|
|
214
|
+
const params = e.params || {};
|
|
215
|
+
return {
|
|
216
|
+
code: params.code ?? "schema_validation",
|
|
217
|
+
message: e.message,
|
|
218
|
+
scope: params.scope ?? "agent" /* AGENT */,
|
|
219
|
+
// Fallback for non-custom Zod errors
|
|
220
|
+
// Treat plain Zod schema failures as USER errors by default
|
|
221
|
+
type: params.type ?? "user" /* USER */,
|
|
222
|
+
path: e.path,
|
|
223
|
+
severity,
|
|
224
|
+
context: params
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/llm/types.ts
|
|
230
|
+
var LLM_PROVIDERS = [
|
|
231
|
+
"openai",
|
|
232
|
+
"openai-compatible",
|
|
233
|
+
"anthropic",
|
|
234
|
+
"google",
|
|
235
|
+
"groq",
|
|
236
|
+
"xai",
|
|
237
|
+
"cohere"
|
|
238
|
+
];
|
|
239
|
+
var LLM_ROUTERS = ["vercel", "in-built"];
|
|
240
|
+
var SUPPORTED_FILE_TYPES = ["pdf", "image", "audio"];
|
|
241
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
242
|
+
0 && (module.exports = {
|
|
243
|
+
ErrorScope,
|
|
244
|
+
ErrorType,
|
|
245
|
+
LLM_PROVIDERS,
|
|
246
|
+
LLM_ROUTERS,
|
|
247
|
+
SUPPORTED_FILE_TYPES,
|
|
248
|
+
toError,
|
|
249
|
+
zodToIssues
|
|
250
|
+
});
|