@kya-os/contracts 1.5.1 → 1.5.2-canary.1

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,186 @@
1
+ "use strict";
2
+ /**
3
+ * Consent Schemas
4
+ *
5
+ * Zod schemas for runtime validation of consent-related data structures.
6
+ * All types are derived from these schemas using z.infer.
7
+ *
8
+ * Related Spec: MCP-I Phase 0 Implementation Plan
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.consentConfigSchema = exports.consentApprovalResponseSchema = exports.consentApprovalRequestSchema = exports.consentPageConfigSchema = exports.consentCustomFieldSchema = exports.consentCustomFieldOptionSchema = exports.consentTermsSchema = exports.consentBrandingSchema = void 0;
12
+ exports.validateConsentPageConfig = validateConsentPageConfig;
13
+ exports.validateConsentApprovalRequest = validateConsentApprovalRequest;
14
+ exports.validateConsentApprovalResponse = validateConsentApprovalResponse;
15
+ exports.validateConsentConfig = validateConsentConfig;
16
+ const zod_1 = require("zod");
17
+ /**
18
+ * Consent Branding Schema
19
+ */
20
+ exports.consentBrandingSchema = zod_1.z.object({
21
+ primaryColor: zod_1.z
22
+ .string()
23
+ .regex(/^#[0-9A-Fa-f]{6}$/, 'Must be a valid hex color (e.g., #0066CC)')
24
+ .optional(),
25
+ logoUrl: zod_1.z.string().url('Must be a valid URL').optional(),
26
+ companyName: zod_1.z.string().max(100, 'Company name must be 100 characters or less').optional(),
27
+ theme: zod_1.z.enum(['light', 'dark', 'auto']).optional(),
28
+ });
29
+ /**
30
+ * Consent Terms Schema
31
+ */
32
+ exports.consentTermsSchema = zod_1.z.object({
33
+ text: zod_1.z.string().max(10000, 'Terms text must be 10000 characters or less').optional(),
34
+ url: zod_1.z.string().url('Must be a valid URL').optional(),
35
+ version: zod_1.z.string().max(50, 'Version must be 50 characters or less').optional(),
36
+ required: zod_1.z.boolean().default(true),
37
+ });
38
+ /**
39
+ * Consent Custom Field Option Schema
40
+ */
41
+ exports.consentCustomFieldOptionSchema = zod_1.z.object({
42
+ value: zod_1.z.string().max(100, 'Option value must be 100 characters or less'),
43
+ label: zod_1.z.string().max(100, 'Option label must be 100 characters or less'),
44
+ });
45
+ /**
46
+ * Consent Custom Field Schema
47
+ */
48
+ exports.consentCustomFieldSchema = zod_1.z.object({
49
+ name: zod_1.z
50
+ .string()
51
+ .min(1, 'Field name is required')
52
+ .max(50, 'Field name must be 50 characters or less')
53
+ .regex(/^[a-zA-Z0-9_]+$/, 'Field name must contain only letters, numbers, and underscores'),
54
+ label: zod_1.z.string().min(1, 'Field label is required').max(100, 'Field label must be 100 characters or less'),
55
+ type: zod_1.z.enum(['text', 'textarea', 'checkbox', 'select']),
56
+ required: zod_1.z.boolean(),
57
+ placeholder: zod_1.z.string().max(200, 'Placeholder must be 200 characters or less').optional(),
58
+ options: zod_1.z
59
+ .array(exports.consentCustomFieldOptionSchema)
60
+ .min(1, 'Select fields must have at least one option')
61
+ .optional(),
62
+ pattern: zod_1.z.string().max(500, 'Pattern must be 500 characters or less').optional(),
63
+ }).refine((data) => {
64
+ // Select fields must have options
65
+ if (data.type === 'select' && (!data.options || data.options.length === 0)) {
66
+ return false;
67
+ }
68
+ // Non-select fields should not have options
69
+ if (data.type !== 'select' && data.options) {
70
+ return false;
71
+ }
72
+ return true;
73
+ }, {
74
+ message: 'Select fields must have options, and non-select fields must not have options',
75
+ });
76
+ /**
77
+ * Consent Page Config Schema
78
+ */
79
+ exports.consentPageConfigSchema = zod_1.z.object({
80
+ tool: zod_1.z.string().min(1, 'Tool name is required'),
81
+ toolDescription: zod_1.z.string().max(500, 'Tool description must be 500 characters or less'),
82
+ scopes: zod_1.z.array(zod_1.z.string()).min(0, 'Scopes array cannot be negative'),
83
+ agentDid: zod_1.z.string().min(1, 'Agent DID is required'),
84
+ sessionId: zod_1.z.string().min(1, 'Session ID is required'),
85
+ projectId: zod_1.z.string().min(1, 'Project ID is required'),
86
+ branding: exports.consentBrandingSchema.optional(),
87
+ terms: exports.consentTermsSchema.optional(),
88
+ customFields: zod_1.z
89
+ .array(exports.consentCustomFieldSchema)
90
+ .max(10, 'Maximum 10 custom fields allowed')
91
+ .optional(),
92
+ serverUrl: zod_1.z.string().url('Server URL must be a valid URL'),
93
+ autoClose: zod_1.z.boolean().optional(),
94
+ });
95
+ /**
96
+ * Consent Approval Request Schema
97
+ *
98
+ * Note: Uses snake_case for API compatibility (agent_did, session_id, project_id)
99
+ */
100
+ exports.consentApprovalRequestSchema = zod_1.z.object({
101
+ tool: zod_1.z.string().min(1, 'Tool name is required'),
102
+ scopes: zod_1.z.array(zod_1.z.string()).min(0, 'Scopes array cannot be negative'),
103
+ agent_did: zod_1.z.string().min(1, 'Agent DID is required'),
104
+ session_id: zod_1.z.string().min(1, 'Session ID is required'),
105
+ project_id: zod_1.z.string().min(1, 'Project ID is required'),
106
+ termsAccepted: zod_1.z.boolean(),
107
+ termsVersion: zod_1.z.string().max(50, 'Terms version must be 50 characters or less').optional(),
108
+ customFields: zod_1.z
109
+ .record(zod_1.z.union([zod_1.z.string(), zod_1.z.boolean()]))
110
+ .optional(),
111
+ });
112
+ /**
113
+ * Consent Approval Response Schema
114
+ */
115
+ exports.consentApprovalResponseSchema = zod_1.z.object({
116
+ success: zod_1.z.boolean(),
117
+ delegation_id: zod_1.z.string().min(1).optional(),
118
+ delegation_token: zod_1.z.string().min(1).optional(),
119
+ error: zod_1.z.string().optional(),
120
+ error_code: zod_1.z.string().optional(),
121
+ }).refine((data) => {
122
+ // If success is true, must have delegation_id and delegation_token
123
+ if (data.success) {
124
+ return !!data.delegation_id && !!data.delegation_token;
125
+ }
126
+ // If success is false, must have error or error_code
127
+ return !!data.error || !!data.error_code;
128
+ }, {
129
+ message: 'Successful responses must include delegation_id and delegation_token. Failed responses must include error or error_code',
130
+ });
131
+ /**
132
+ * Consent Config Schema
133
+ */
134
+ exports.consentConfigSchema = zod_1.z.object({
135
+ branding: exports.consentBrandingSchema.optional(),
136
+ terms: exports.consentTermsSchema.optional(),
137
+ customFields: zod_1.z
138
+ .array(exports.consentCustomFieldSchema)
139
+ .max(10, 'Maximum 10 custom fields allowed')
140
+ .optional(),
141
+ ui: zod_1.z.object({
142
+ theme: zod_1.z.enum(['light', 'dark', 'auto']).optional(),
143
+ popupEnabled: zod_1.z.boolean().optional(),
144
+ autoClose: zod_1.z.boolean().optional(),
145
+ autoCloseDelay: zod_1.z.number().int().positive().max(60000, 'Auto-close delay must be 60000ms or less').optional(),
146
+ }).optional(),
147
+ });
148
+ /**
149
+ * Validation Helpers
150
+ */
151
+ /**
152
+ * Validate a consent page config
153
+ *
154
+ * @param config - The config to validate
155
+ * @returns Validation result
156
+ */
157
+ function validateConsentPageConfig(config) {
158
+ return exports.consentPageConfigSchema.safeParse(config);
159
+ }
160
+ /**
161
+ * Validate a consent approval request
162
+ *
163
+ * @param request - The request to validate
164
+ * @returns Validation result
165
+ */
166
+ function validateConsentApprovalRequest(request) {
167
+ return exports.consentApprovalRequestSchema.safeParse(request);
168
+ }
169
+ /**
170
+ * Validate a consent approval response
171
+ *
172
+ * @param response - The response to validate
173
+ * @returns Validation result
174
+ */
175
+ function validateConsentApprovalResponse(response) {
176
+ return exports.consentApprovalResponseSchema.safeParse(response);
177
+ }
178
+ /**
179
+ * Validate a consent config
180
+ *
181
+ * @param config - The config to validate
182
+ * @returns Validation result
183
+ */
184
+ function validateConsentConfig(config) {
185
+ return exports.consentConfigSchema.safeParse(config);
186
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Consent Types
3
+ *
4
+ * TypeScript type definitions for consent page configuration and approval handling.
5
+ * These types are used for server-hosted consent pages in HTTP/SSE transports.
6
+ *
7
+ * Related Spec: MCP-I Phase 0 Implementation Plan
8
+ */
9
+ /**
10
+ * Consent Branding Configuration
11
+ *
12
+ * Customization options for consent page appearance
13
+ */
14
+ export interface ConsentBranding {
15
+ /** Primary brand color (hex format, e.g., '#0066CC') */
16
+ primaryColor?: string;
17
+ /** Logo URL for display on consent page */
18
+ logoUrl?: string;
19
+ /** Company/application name */
20
+ companyName?: string;
21
+ /** Theme preference ('light', 'dark', or 'auto' for system preference) */
22
+ theme?: 'light' | 'dark' | 'auto';
23
+ }
24
+ /**
25
+ * Consent Terms Configuration
26
+ *
27
+ * Terms of service or privacy policy information
28
+ */
29
+ export interface ConsentTerms {
30
+ /** Full terms text (displayed on page) */
31
+ text?: string;
32
+ /** URL to terms document */
33
+ url?: string;
34
+ /** Version identifier for terms */
35
+ version?: string;
36
+ /** Whether terms acceptance is required */
37
+ required?: boolean;
38
+ }
39
+ /**
40
+ * Consent Custom Field
41
+ *
42
+ * Additional fields to collect during consent (e.g., email, preferences)
43
+ */
44
+ export interface ConsentCustomField {
45
+ /** Field name (used as form field name, must be valid identifier) */
46
+ name: string;
47
+ /** Display label for the field */
48
+ label: string;
49
+ /** Field type */
50
+ type: 'text' | 'textarea' | 'checkbox' | 'select';
51
+ /** Whether field is required */
52
+ required: boolean;
53
+ /** Placeholder text */
54
+ placeholder?: string;
55
+ /** Options for select fields */
56
+ options?: Array<{
57
+ value: string;
58
+ label: string;
59
+ }>;
60
+ /** Validation pattern (regex) */
61
+ pattern?: string;
62
+ }
63
+ /**
64
+ * Consent Page Configuration
65
+ *
66
+ * Complete configuration for rendering a consent page
67
+ */
68
+ export interface ConsentPageConfig {
69
+ /** Tool name requiring authorization */
70
+ tool: string;
71
+ /** Description of what the tool does */
72
+ toolDescription: string;
73
+ /** Scopes being requested */
74
+ scopes: string[];
75
+ /** Agent DID requesting authorization */
76
+ agentDid: string;
77
+ /** Session ID for tracking */
78
+ sessionId: string;
79
+ /** Project ID from AgentShield */
80
+ projectId: string;
81
+ /** Branding configuration */
82
+ branding?: ConsentBranding;
83
+ /** Terms configuration */
84
+ terms?: ConsentTerms;
85
+ /** Custom fields to collect */
86
+ customFields?: ConsentCustomField[];
87
+ /** Server URL for form submission */
88
+ serverUrl: string;
89
+ /** Whether to auto-close window after success */
90
+ autoClose?: boolean;
91
+ }
92
+ /**
93
+ * Consent Approval Request
94
+ *
95
+ * Request payload when user approves consent
96
+ */
97
+ export interface ConsentApprovalRequest {
98
+ /** Tool name */
99
+ tool: string;
100
+ /** Approved scopes */
101
+ scopes: string[];
102
+ /** Agent DID (snake_case for API compatibility) */
103
+ agent_did: string;
104
+ /** Session ID (snake_case for API compatibility) */
105
+ session_id: string;
106
+ /** Project ID (snake_case for API compatibility) */
107
+ project_id: string;
108
+ /** Whether terms were accepted */
109
+ termsAccepted: boolean;
110
+ /** Terms version (if applicable) */
111
+ termsVersion?: string;
112
+ /** Custom field values */
113
+ customFields?: Record<string, string | boolean>;
114
+ }
115
+ /**
116
+ * Consent Approval Response
117
+ *
118
+ * Response after processing consent approval
119
+ */
120
+ export interface ConsentApprovalResponse {
121
+ /** Whether approval was successful */
122
+ success: boolean;
123
+ /** Delegation ID (if successful) */
124
+ delegation_id?: string;
125
+ /** Delegation token (if successful) */
126
+ delegation_token?: string;
127
+ /** Error message (if failed) */
128
+ error?: string;
129
+ /** Error code (if failed) */
130
+ error_code?: string;
131
+ }
132
+ /**
133
+ * Consent Configuration
134
+ *
135
+ * Complete consent configuration fetched from AgentShield or defaults
136
+ */
137
+ export interface ConsentConfig {
138
+ /** Branding configuration */
139
+ branding?: ConsentBranding;
140
+ /** Terms configuration */
141
+ terms?: ConsentTerms;
142
+ /** Custom fields configuration */
143
+ customFields?: ConsentCustomField[];
144
+ /** UI preferences */
145
+ ui?: {
146
+ /** Theme preference */
147
+ theme?: 'light' | 'dark' | 'auto';
148
+ /** Whether popup mode is enabled */
149
+ popupEnabled?: boolean;
150
+ /** Whether to auto-close after success */
151
+ autoClose?: boolean;
152
+ /** Delay before auto-close (milliseconds) */
153
+ autoCloseDelay?: number;
154
+ };
155
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * Consent Types
4
+ *
5
+ * TypeScript type definitions for consent page configuration and approval handling.
6
+ * These types are used for server-hosted consent pages in HTTP/SSE transports.
7
+ *
8
+ * Related Spec: MCP-I Phase 0 Implementation Plan
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -47,3 +47,4 @@ export declare function getDefaultConfigForPlatform(platform: "node" | "cloudfla
47
47
  * ```
48
48
  */
49
49
  export declare function mergeWithDefaults(partial: Partial<MCPIServerConfig>): MCPIServerConfig;
50
+ //# sourceMappingURL=default-config.d.ts.map
@@ -19,7 +19,8 @@ const zod_1 = require("zod");
19
19
  */
20
20
  const defaultConfigJson = {
21
21
  identity: {
22
- agentDid: "",
22
+ // agentDid removed - deprecated, use serverDid instead
23
+ serverDid: "", // New field - will be populated when identity is generated
23
24
  environment: "development",
24
25
  storageLocation: "env-vars",
25
26
  },
@@ -105,10 +106,17 @@ const defaultConfigJson = {
105
106
  /**
106
107
  * Relaxed schema for default config validation
107
108
  * Allows empty strings for fields that will be populated later
109
+ *
110
+ * Note: Empty `agentDid` is valid for new/incomplete configurations.
111
+ * This allows users to create configs before registering their agent DID.
112
+ * The base schema (mcpIServerConfigSchema) requires non-empty agentDid for
113
+ * complete configurations, but defaults allow empty to support progressive
114
+ * configuration.
108
115
  */
109
116
  const defaultConfigSchema = schemas_js_1.mcpIServerConfigSchema.extend({
110
117
  identity: schemas_js_1.mcpIServerConfigSchema.shape.identity.extend({
111
- agentDid: zod_1.z.string(), // Allow empty string for defaults
118
+ agentDid: zod_1.z.string().optional(), // Allow empty string or undefined for defaults (deprecated)
119
+ serverDid: zod_1.z.string(), // Allow empty string for defaults (will be populated later)
112
120
  }),
113
121
  metadata: schemas_js_1.mcpIServerConfigSchema.shape.metadata.extend({
114
122
  lastUpdated: zod_1.z.string(), // Allow empty string (will be set dynamically)
@@ -191,14 +199,21 @@ function getDefaultConfigForPlatform(platform) {
191
199
  function deepMerge(target, source) {
192
200
  const result = { ...target };
193
201
  for (const key in source) {
194
- if (source[key] &&
195
- typeof source[key] === "object" &&
196
- !Array.isArray(source[key]) &&
197
- source[key] !== null) {
198
- result[key] = deepMerge((target[key] || {}), source[key]);
202
+ const sourceValue = source[key];
203
+ if (sourceValue &&
204
+ typeof sourceValue === "object" &&
205
+ !Array.isArray(sourceValue) &&
206
+ sourceValue !== null) {
207
+ const targetValue = target[key];
208
+ if (targetValue &&
209
+ typeof targetValue === "object" &&
210
+ !Array.isArray(targetValue) &&
211
+ targetValue !== null) {
212
+ result[key] = deepMerge(targetValue, sourceValue);
213
+ }
199
214
  }
200
- else if (source[key] !== undefined) {
201
- result[key] = source[key];
215
+ else if (sourceValue !== undefined) {
216
+ result[key] = sourceValue;
202
217
  }
203
218
  }
204
219
  return result;
@@ -223,3 +238,4 @@ function deepMerge(target, source) {
223
238
  function mergeWithDefaults(partial) {
224
239
  return deepMerge(exports.defaultConfig, partial);
225
240
  }
241
+ //# sourceMappingURL=default-config.js.map
@@ -8,3 +8,4 @@
8
8
  export type { MCPIServerConfig, GetServerConfigRequest, GetServerConfigResponse, UpdateServerConfigRequest, UpdateServerConfigResponse, ValidateServerConfigRequest, ValidateServerConfigResponse, } from './types.js';
9
9
  export { identityConfigSchema, proofingConfigSchema, delegationConfigSchema, toolProtectionConfigSchema, auditConfigSchema, sessionConfigSchema, platformConfigSchema, cloudflarePlatformConfigSchema, nodePlatformConfigSchema, vercelPlatformConfigSchema, configMetadataSchema, mcpIServerConfigSchema, getServerConfigRequestSchema, getServerConfigResponseSchema, updateServerConfigRequestSchema, updateServerConfigResponseSchema, validateServerConfigRequestSchema, validateServerConfigResponseSchema, } from './schemas.js';
10
10
  export { defaultConfig, getDefaultConfigForPlatform, mergeWithDefaults, } from './default-config.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -33,3 +33,4 @@ var default_config_js_1 = require("./default-config.js");
33
33
  Object.defineProperty(exports, "defaultConfig", { enumerable: true, get: function () { return default_config_js_1.defaultConfig; } });
34
34
  Object.defineProperty(exports, "getDefaultConfigForPlatform", { enumerable: true, get: function () { return default_config_js_1.getDefaultConfigForPlatform; } });
35
35
  Object.defineProperty(exports, "mergeWithDefaults", { enumerable: true, get: function () { return default_config_js_1.mergeWithDefaults; } });
36
+ //# sourceMappingURL=index.js.map