wave-agent-sdk 0.0.1 → 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.
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Configuration resolver utilities for Agent Constructor Configuration
3
+ * Resolves configuration from constructor arguments with environment fallbacks
4
+ */
5
+
6
+ import {
7
+ GatewayConfig,
8
+ ModelConfig,
9
+ ConfigurationError,
10
+ CONFIG_ERRORS,
11
+ } from "../types.js";
12
+
13
+ export class ConfigResolver {
14
+ /**
15
+ * Resolves gateway configuration from constructor args and environment
16
+ * @param apiKey - API key from constructor (optional)
17
+ * @param baseURL - Base URL from constructor (optional)
18
+ * @returns Resolved gateway configuration
19
+ * @throws ConfigurationError if required configuration is missing after fallbacks
20
+ */
21
+ static resolveGatewayConfig(
22
+ apiKey?: string,
23
+ baseURL?: string,
24
+ ): GatewayConfig {
25
+ // Resolve API key: constructor > environment variable
26
+ // Note: Explicitly provided empty strings should be treated as invalid, not fall back to env
27
+ let resolvedApiKey: string;
28
+ if (apiKey !== undefined) {
29
+ resolvedApiKey = apiKey;
30
+ } else {
31
+ resolvedApiKey = process.env.AIGW_TOKEN || "";
32
+ }
33
+
34
+ if (!resolvedApiKey && apiKey === undefined) {
35
+ throw new ConfigurationError(CONFIG_ERRORS.MISSING_API_KEY, "apiKey", {
36
+ constructor: apiKey,
37
+ environment: process.env.AIGW_TOKEN,
38
+ });
39
+ }
40
+
41
+ if (resolvedApiKey.trim() === "") {
42
+ throw new ConfigurationError(
43
+ CONFIG_ERRORS.EMPTY_API_KEY,
44
+ "apiKey",
45
+ resolvedApiKey,
46
+ );
47
+ }
48
+
49
+ // Resolve base URL: constructor > environment variable
50
+ // Note: Explicitly provided empty strings should be treated as invalid, not fall back to env
51
+ let resolvedBaseURL: string;
52
+ if (baseURL !== undefined) {
53
+ resolvedBaseURL = baseURL;
54
+ } else {
55
+ resolvedBaseURL = process.env.AIGW_URL || "";
56
+ }
57
+
58
+ if (!resolvedBaseURL && baseURL === undefined) {
59
+ throw new ConfigurationError(CONFIG_ERRORS.MISSING_BASE_URL, "baseURL", {
60
+ constructor: baseURL,
61
+ environment: process.env.AIGW_URL,
62
+ });
63
+ }
64
+
65
+ if (resolvedBaseURL.trim() === "") {
66
+ throw new ConfigurationError(
67
+ CONFIG_ERRORS.EMPTY_BASE_URL,
68
+ "baseURL",
69
+ resolvedBaseURL,
70
+ );
71
+ }
72
+
73
+ return {
74
+ apiKey: resolvedApiKey,
75
+ baseURL: resolvedBaseURL,
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Resolves model configuration with fallbacks
81
+ * @param agentModel - Agent model from constructor (optional)
82
+ * @param fastModel - Fast model from constructor (optional)
83
+ * @returns Resolved model configuration with defaults
84
+ */
85
+ static resolveModelConfig(
86
+ agentModel?: string,
87
+ fastModel?: string,
88
+ ): ModelConfig {
89
+ // Default values as per data-model.md
90
+ const DEFAULT_AGENT_MODEL = "claude-sonnet-4-20250514";
91
+ const DEFAULT_FAST_MODEL = "gemini-2.5-flash";
92
+
93
+ // Resolve agent model: constructor > environment > default
94
+ const resolvedAgentModel =
95
+ agentModel || process.env.AIGW_MODEL || DEFAULT_AGENT_MODEL;
96
+
97
+ // Resolve fast model: constructor > environment > default
98
+ const resolvedFastModel =
99
+ fastModel || process.env.AIGW_FAST_MODEL || DEFAULT_FAST_MODEL;
100
+
101
+ return {
102
+ agentModel: resolvedAgentModel,
103
+ fastModel: resolvedFastModel,
104
+ };
105
+ }
106
+
107
+ /**
108
+ * Resolves token limit with fallbacks
109
+ * @param constructorLimit - Token limit from constructor (optional)
110
+ * @returns Resolved token limit
111
+ */
112
+ static resolveTokenLimit(constructorLimit?: number): number {
113
+ const DEFAULT_TOKEN_LIMIT = 64000;
114
+
115
+ // If constructor value provided, use it
116
+ if (constructorLimit !== undefined) {
117
+ return constructorLimit;
118
+ }
119
+
120
+ // Try environment variable
121
+ const envTokenLimit = process.env.TOKEN_LIMIT;
122
+ if (envTokenLimit) {
123
+ const parsed = parseInt(envTokenLimit, 10);
124
+ if (!isNaN(parsed)) {
125
+ return parsed;
126
+ }
127
+ }
128
+
129
+ // Use default
130
+ return DEFAULT_TOKEN_LIMIT;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Static configuration resolver instance
136
+ * Implements ConfigurationResolver interface from types.ts
137
+ */
138
+ export const configResolver = {
139
+ resolveGatewayConfig: ConfigResolver.resolveGatewayConfig,
140
+ resolveModelConfig: ConfigResolver.resolveModelConfig,
141
+ resolveTokenLimit: ConfigResolver.resolveTokenLimit,
142
+ };
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Configuration validator utilities for Agent Constructor Configuration
3
+ * Validates configuration values for correctness and security
4
+ */
5
+
6
+ import { GatewayConfig, ConfigurationError, CONFIG_ERRORS } from "../types.js";
7
+
8
+ export class ConfigValidator {
9
+ /**
10
+ * Validates gateway configuration
11
+ * @param config - Configuration to validate
12
+ * @throws ConfigurationError with descriptive message if invalid
13
+ */
14
+ static validateGatewayConfig(config: GatewayConfig): void {
15
+ // Validate API key
16
+ if (!config.apiKey || typeof config.apiKey !== "string") {
17
+ throw new ConfigurationError(
18
+ CONFIG_ERRORS.EMPTY_API_KEY,
19
+ "apiKey",
20
+ config.apiKey,
21
+ );
22
+ }
23
+
24
+ if (config.apiKey.trim() === "") {
25
+ throw new ConfigurationError(
26
+ CONFIG_ERRORS.EMPTY_API_KEY,
27
+ "apiKey",
28
+ config.apiKey,
29
+ );
30
+ }
31
+
32
+ // Validate base URL
33
+ if (!config.baseURL || typeof config.baseURL !== "string") {
34
+ throw new ConfigurationError(
35
+ CONFIG_ERRORS.EMPTY_BASE_URL,
36
+ "baseURL",
37
+ config.baseURL,
38
+ );
39
+ }
40
+
41
+ if (config.baseURL.trim() === "") {
42
+ throw new ConfigurationError(
43
+ CONFIG_ERRORS.EMPTY_BASE_URL,
44
+ "baseURL",
45
+ config.baseURL,
46
+ );
47
+ }
48
+
49
+ // Basic URL format validation
50
+ try {
51
+ new URL(config.baseURL);
52
+ } catch {
53
+ throw new ConfigurationError(
54
+ `Base URL must be a valid URL format. Received: ${config.baseURL}`,
55
+ "baseURL",
56
+ config.baseURL,
57
+ );
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Validates token limit value
63
+ * @param tokenLimit - Token limit to validate
64
+ * @throws ConfigurationError if invalid
65
+ */
66
+ static validateTokenLimit(tokenLimit: number): void {
67
+ if (typeof tokenLimit !== "number") {
68
+ throw new ConfigurationError(
69
+ CONFIG_ERRORS.INVALID_TOKEN_LIMIT,
70
+ "tokenLimit",
71
+ tokenLimit,
72
+ );
73
+ }
74
+
75
+ if (!Number.isInteger(tokenLimit)) {
76
+ throw new ConfigurationError(
77
+ CONFIG_ERRORS.INVALID_TOKEN_LIMIT,
78
+ "tokenLimit",
79
+ tokenLimit,
80
+ );
81
+ }
82
+
83
+ if (tokenLimit <= 0) {
84
+ throw new ConfigurationError(
85
+ CONFIG_ERRORS.INVALID_TOKEN_LIMIT,
86
+ "tokenLimit",
87
+ tokenLimit,
88
+ );
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Validates model configuration (basic validation)
94
+ * @param agentModel - Agent model string
95
+ * @param fastModel - Fast model string
96
+ * @throws ConfigurationError if invalid
97
+ */
98
+ static validateModelConfig(agentModel: string, fastModel: string): void {
99
+ if (
100
+ !agentModel ||
101
+ typeof agentModel !== "string" ||
102
+ agentModel.trim() === ""
103
+ ) {
104
+ throw new ConfigurationError(
105
+ "Agent model must be a non-empty string.",
106
+ "agentModel",
107
+ agentModel,
108
+ );
109
+ }
110
+
111
+ if (
112
+ !fastModel ||
113
+ typeof fastModel !== "string" ||
114
+ fastModel.trim() === ""
115
+ ) {
116
+ throw new ConfigurationError(
117
+ "Fast model must be a non-empty string.",
118
+ "fastModel",
119
+ fastModel,
120
+ );
121
+ }
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Static configuration validator instance
127
+ * Implements ConfigurationValidator interface from types.ts
128
+ */
129
+ export const configValidator = {
130
+ validateGatewayConfig: ConfigValidator.validateGatewayConfig,
131
+ validateTokenLimit: ConfigValidator.validateTokenLimit,
132
+ validateModelConfig: ConfigValidator.validateModelConfig,
133
+ };
@@ -31,7 +31,17 @@ export const USER_MEMORY_FILE = path.join(DATA_DIRECTORY, "user-memory.md");
31
31
  */
32
32
  export const DEFAULT_TOKEN_LIMIT = 64000; // Default token limit
33
33
 
34
+ /**
35
+ * @deprecated These constants are now legacy. Use ModelConfig through Agent constructor instead.
36
+ * They are maintained for backward compatibility with existing code that might still reference them,
37
+ * but the actual AI services now use configuration injection.
38
+ */
34
39
  export const FAST_MODEL_ID = process.env.AIGW_FAST_MODEL || "gemini-2.5-flash";
35
40
 
41
+ /**
42
+ * @deprecated These constants are now legacy. Use ModelConfig through Agent constructor instead.
43
+ * They are maintained for backward compatibility with existing code that might still reference them,
44
+ * but the actual AI services now use configuration injection.
45
+ */
36
46
  export const AGENT_MODEL_ID =
37
47
  process.env.AIGW_MODEL || "claude-sonnet-4-20250514";