@kya-os/contracts 1.6.17 → 1.6.19

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,283 @@
1
+ "use strict";
2
+ /**
3
+ * One-Click Deployment Zod Validation Schemas
4
+ *
5
+ * Runtime validation schemas for the AgentShield One-Click Deployment API.
6
+ * These schemas ensure request/response validation at API boundaries.
7
+ *
8
+ * @package @kya-os/contracts/deploy
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.deploymentProgressSchema = exports.deployStepSchema = exports.deployStepStatusSchema = exports.scaffolderResultSchema = exports.scaffolderOptionsSchema = exports.generatedFileSchema = exports.listDeployedRepositoriesResponseSchema = exports.deployedRepositorySchema = exports.deployToGitHubResultSchema = exports.deployErrorResponseSchema = exports.deployToGitHubResponseSchema = exports.deployToGitHubDataSchema = exports.deployedProjectSchema = exports.deployToGitHubRequestSchema = exports.repoNameSchema = exports.deployErrorCodeSchema = exports.gitHubDisconnectResponseSchema = exports.gitHubStatusResponseSchema = exports.gitHubCallbackResponseSchema = exports.gitHubCallbackQuerySchema = exports.gitHubInstallInitResponseSchema = exports.gitHubRepositorySchema = exports.gitHubInstallationSchema = exports.gitHubAccountTypeSchema = exports.deployPlatformSchema = exports.templateTypeSchema = void 0;
12
+ const zod_1 = require("zod");
13
+ // ============================================================================
14
+ // Template & Platform Schemas
15
+ // ============================================================================
16
+ /**
17
+ * Valid template types for deployment
18
+ */
19
+ exports.templateTypeSchema = zod_1.z.enum([
20
+ "blank",
21
+ "ecommerce",
22
+ "hardware-world",
23
+ ]);
24
+ /**
25
+ * Valid deployment platforms
26
+ */
27
+ exports.deployPlatformSchema = zod_1.z.enum(["cloudflare", "vercel"]);
28
+ // ============================================================================
29
+ // GitHub Installation Schemas
30
+ // ============================================================================
31
+ /**
32
+ * GitHub account type schema
33
+ */
34
+ exports.gitHubAccountTypeSchema = zod_1.z.enum(["User", "Organization"]);
35
+ /**
36
+ * GitHub installation schema
37
+ */
38
+ exports.gitHubInstallationSchema = zod_1.z.object({
39
+ id: zod_1.z.string().uuid(),
40
+ installationId: zod_1.z.number().int().positive(),
41
+ account: zod_1.z.object({
42
+ login: zod_1.z.string().min(1),
43
+ avatarUrl: zod_1.z.string().url(),
44
+ type: exports.gitHubAccountTypeSchema,
45
+ id: zod_1.z.number().int().positive(),
46
+ }),
47
+ permissions: zod_1.z.array(zod_1.z.string()),
48
+ suspendedAt: zod_1.z.string().datetime().nullable().optional(),
49
+ createdAt: zod_1.z.string().datetime(),
50
+ updatedAt: zod_1.z.string().datetime(),
51
+ });
52
+ /**
53
+ * GitHub repository schema
54
+ */
55
+ exports.gitHubRepositorySchema = zod_1.z.object({
56
+ name: zod_1.z.string().min(1),
57
+ fullName: zod_1.z.string().regex(/^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_.-]+$/),
58
+ private: zod_1.z.boolean(),
59
+ url: zod_1.z.string().url(),
60
+ defaultBranch: zod_1.z.string().min(1),
61
+ });
62
+ // ============================================================================
63
+ // GitHub OAuth/Installation API Schemas
64
+ // ============================================================================
65
+ /**
66
+ * GitHub install initiation response schema
67
+ */
68
+ exports.gitHubInstallInitResponseSchema = zod_1.z.object({
69
+ success: zod_1.z.literal(true),
70
+ installationUrl: zod_1.z.string().url(),
71
+ });
72
+ /**
73
+ * GitHub callback query schema
74
+ */
75
+ exports.gitHubCallbackQuerySchema = zod_1.z.object({
76
+ installation_id: zod_1.z.string().regex(/^\d+$/),
77
+ setup_action: zod_1.z.enum(["install", "update"]),
78
+ code: zod_1.z.string().optional(),
79
+ });
80
+ /**
81
+ * GitHub callback response schema
82
+ */
83
+ exports.gitHubCallbackResponseSchema = zod_1.z.object({
84
+ success: zod_1.z.literal(true),
85
+ installation: exports.gitHubInstallationSchema,
86
+ });
87
+ /**
88
+ * GitHub status response schema
89
+ */
90
+ exports.gitHubStatusResponseSchema = zod_1.z.object({
91
+ success: zod_1.z.literal(true),
92
+ data: zod_1.z.object({
93
+ connected: zod_1.z.boolean(),
94
+ installation: exports.gitHubInstallationSchema.optional(),
95
+ repositories: zod_1.z.array(exports.gitHubRepositorySchema).optional(),
96
+ }),
97
+ });
98
+ /**
99
+ * GitHub disconnect response schema
100
+ */
101
+ exports.gitHubDisconnectResponseSchema = zod_1.z.object({
102
+ success: zod_1.z.literal(true),
103
+ disconnected: zod_1.z.boolean(),
104
+ });
105
+ // ============================================================================
106
+ // Deploy API Schemas
107
+ // ============================================================================
108
+ /**
109
+ * Deploy error code schema
110
+ */
111
+ exports.deployErrorCodeSchema = zod_1.z.enum([
112
+ "GITHUB_NOT_CONNECTED",
113
+ "REPO_NAME_TAKEN",
114
+ "REPO_NAME_INVALID",
115
+ "RATE_LIMIT_EXCEEDED",
116
+ "PLAN_LIMIT_EXCEEDED",
117
+ "TEMPLATE_NOT_FOUND",
118
+ "GITHUB_API_ERROR",
119
+ "SCAFFOLDER_ERROR",
120
+ "PROJECT_CREATION_ERROR",
121
+ "SECRETS_ERROR",
122
+ "INTERNAL_ERROR",
123
+ ]);
124
+ /**
125
+ * Repository name validation
126
+ * - Must be lowercase alphanumeric with hyphens
127
+ * - Cannot start or end with hyphen
128
+ * - Length 1-100 characters
129
+ */
130
+ exports.repoNameSchema = zod_1.z
131
+ .string()
132
+ .min(1, "Repository name is required")
133
+ .max(100, "Repository name must be 100 characters or less")
134
+ .regex(/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/, "Repository name must be lowercase, alphanumeric, and can contain hyphens (but not at start/end)");
135
+ /**
136
+ * Deploy to GitHub request schema
137
+ */
138
+ exports.deployToGitHubRequestSchema = zod_1.z.object({
139
+ repoName: exports.repoNameSchema,
140
+ template: exports.templateTypeSchema,
141
+ platform: exports.deployPlatformSchema,
142
+ isPrivate: zod_1.z.boolean().optional().default(true),
143
+ description: zod_1.z.string().max(500).optional(),
144
+ });
145
+ /**
146
+ * Deployed project schema
147
+ */
148
+ exports.deployedProjectSchema = zod_1.z.object({
149
+ id: zod_1.z.string().uuid(),
150
+ friendlyId: zod_1.z.string().min(1),
151
+ apiKey: zod_1.z.string().min(1), // API key - sensitive, shown only once
152
+ });
153
+ /**
154
+ * Deploy to GitHub data schema
155
+ */
156
+ exports.deployToGitHubDataSchema = zod_1.z.object({
157
+ repoUrl: zod_1.z.string().url(),
158
+ repoFullName: zod_1.z.string().regex(/^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_.-]+$/),
159
+ project: exports.deployedProjectSchema,
160
+ deployUrl: zod_1.z.string().url(),
161
+ nextSteps: zod_1.z.array(zod_1.z.string()),
162
+ });
163
+ /**
164
+ * Deploy success response schema
165
+ */
166
+ exports.deployToGitHubResponseSchema = zod_1.z.object({
167
+ success: zod_1.z.literal(true),
168
+ data: exports.deployToGitHubDataSchema,
169
+ });
170
+ /**
171
+ * Deploy error response schema
172
+ */
173
+ exports.deployErrorResponseSchema = zod_1.z.object({
174
+ success: zod_1.z.literal(false),
175
+ error: zod_1.z.object({
176
+ code: exports.deployErrorCodeSchema,
177
+ message: zod_1.z.string(),
178
+ details: zod_1.z.record(zod_1.z.unknown()).optional(),
179
+ }),
180
+ });
181
+ /**
182
+ * Deploy result union schema
183
+ */
184
+ exports.deployToGitHubResultSchema = zod_1.z.discriminatedUnion("success", [
185
+ exports.deployToGitHubResponseSchema,
186
+ exports.deployErrorResponseSchema,
187
+ ]);
188
+ // ============================================================================
189
+ // Deployed Repository Schemas
190
+ // ============================================================================
191
+ /**
192
+ * Deployed repository schema
193
+ */
194
+ exports.deployedRepositorySchema = zod_1.z.object({
195
+ id: zod_1.z.string().uuid(),
196
+ userId: zod_1.z.string().uuid(),
197
+ projectId: zod_1.z.string().uuid(),
198
+ installationId: zod_1.z.string().uuid(),
199
+ repoFullName: zod_1.z.string(),
200
+ repoUrl: zod_1.z.string().url(),
201
+ template: exports.templateTypeSchema,
202
+ platform: exports.deployPlatformSchema,
203
+ cloudflareDeployed: zod_1.z.boolean(),
204
+ cloudflareUrl: zod_1.z.string().url().nullable().optional(),
205
+ createdAt: zod_1.z.string().datetime(),
206
+ updatedAt: zod_1.z.string().datetime(),
207
+ });
208
+ /**
209
+ * List deployed repositories response schema
210
+ */
211
+ exports.listDeployedRepositoriesResponseSchema = zod_1.z.object({
212
+ success: zod_1.z.literal(true),
213
+ data: zod_1.z.array(exports.deployedRepositorySchema),
214
+ });
215
+ // ============================================================================
216
+ // File Generation Schemas (for scaffolder)
217
+ // ============================================================================
218
+ /**
219
+ * Generated file schema
220
+ */
221
+ exports.generatedFileSchema = zod_1.z.object({
222
+ path: zod_1.z.string().min(1),
223
+ content: zod_1.z.string(),
224
+ isBase64: zod_1.z.boolean().optional(),
225
+ });
226
+ /**
227
+ * Scaffolder options schema
228
+ */
229
+ exports.scaffolderOptionsSchema = zod_1.z.object({
230
+ projectName: zod_1.z.string().min(1).max(100),
231
+ template: exports.templateTypeSchema,
232
+ platform: exports.deployPlatformSchema,
233
+ agentShieldProjectId: zod_1.z.string().optional(),
234
+ agentShieldApiKey: zod_1.z.string().optional(),
235
+ skipIdentity: zod_1.z.boolean().optional(),
236
+ });
237
+ /**
238
+ * Scaffolder result schema
239
+ */
240
+ exports.scaffolderResultSchema = zod_1.z.object({
241
+ success: zod_1.z.boolean(),
242
+ files: zod_1.z.array(exports.generatedFileSchema),
243
+ identity: zod_1.z
244
+ .object({
245
+ did: zod_1.z.string().min(1),
246
+ publicKey: zod_1.z.string().min(1),
247
+ privateKey: zod_1.z.string().min(1),
248
+ })
249
+ .optional(),
250
+ warnings: zod_1.z.array(zod_1.z.string()).optional(),
251
+ });
252
+ // ============================================================================
253
+ // Deployment Progress Schemas
254
+ // ============================================================================
255
+ /**
256
+ * Deploy step status schema
257
+ */
258
+ exports.deployStepStatusSchema = zod_1.z.enum([
259
+ "pending",
260
+ "in_progress",
261
+ "completed",
262
+ "failed",
263
+ ]);
264
+ /**
265
+ * Deploy step schema
266
+ */
267
+ exports.deployStepSchema = zod_1.z.object({
268
+ id: zod_1.z.string().min(1),
269
+ name: zod_1.z.string().min(1),
270
+ status: exports.deployStepStatusSchema,
271
+ message: zod_1.z.string().optional(),
272
+ startedAt: zod_1.z.string().datetime().optional(),
273
+ completedAt: zod_1.z.string().datetime().optional(),
274
+ });
275
+ /**
276
+ * Deployment progress schema
277
+ */
278
+ exports.deploymentProgressSchema = zod_1.z.object({
279
+ steps: zod_1.z.array(exports.deployStepSchema),
280
+ currentStep: zod_1.z.number().int().min(0),
281
+ totalSteps: zod_1.z.number().int().positive(),
282
+ overallStatus: zod_1.z.enum(["pending", "in_progress", "completed", "failed"]),
283
+ });
@@ -0,0 +1,256 @@
1
+ /**
2
+ * One-Click Deployment API Type Definitions
3
+ *
4
+ * TypeScript interfaces for the AgentShield One-Click Deployment feature.
5
+ * Enables users to deploy MCP-I agents to Cloudflare Workers with a single click.
6
+ *
7
+ * @package @kya-os/contracts/deploy
8
+ */
9
+ import type { AgentShieldAPIResponse } from "../agentshield-api/types.js";
10
+ /**
11
+ * Supported deployment templates
12
+ * - blank: Minimal MCP-I server with a greet tool
13
+ * - ecommerce: E-commerce focused with cart/checkout tools
14
+ * - hardware-world: IoT/Hardware world demo template
15
+ */
16
+ export type TemplateType = "blank" | "ecommerce" | "hardware-world";
17
+ /**
18
+ * Supported deployment platforms
19
+ * - cloudflare: Cloudflare Workers
20
+ * - vercel: Vercel Edge Functions (future)
21
+ */
22
+ export type DeployPlatformType = "cloudflare" | "vercel";
23
+ /**
24
+ * GitHub account type (user or organization)
25
+ */
26
+ export type GitHubAccountType = "User" | "Organization";
27
+ /**
28
+ * GitHub App installation status
29
+ */
30
+ export interface GitHubInstallation {
31
+ id: string;
32
+ installationId: number;
33
+ account: {
34
+ login: string;
35
+ avatarUrl: string;
36
+ type: GitHubAccountType;
37
+ id: number;
38
+ };
39
+ permissions: string[];
40
+ suspendedAt?: string | null;
41
+ createdAt: string;
42
+ updatedAt: string;
43
+ }
44
+ /**
45
+ * Repository information returned from GitHub API
46
+ */
47
+ export interface GitHubRepository {
48
+ name: string;
49
+ fullName: string;
50
+ private: boolean;
51
+ url: string;
52
+ defaultBranch: string;
53
+ }
54
+ /**
55
+ * Response from GitHub App installation initiation
56
+ * GET /api/internal/github/install
57
+ */
58
+ export interface GitHubInstallInitResponse {
59
+ success: true;
60
+ installationUrl: string;
61
+ }
62
+ /**
63
+ * Query parameters for GitHub App callback
64
+ * GET /api/internal/github/callback
65
+ */
66
+ export interface GitHubCallbackQuery {
67
+ installation_id: string;
68
+ setup_action: "install" | "update";
69
+ code?: string;
70
+ }
71
+ /**
72
+ * Response from GitHub App callback
73
+ */
74
+ export interface GitHubCallbackResponse {
75
+ success: true;
76
+ installation: GitHubInstallation;
77
+ }
78
+ /**
79
+ * Response from GitHub connection status endpoint
80
+ * GET /api/internal/github/status
81
+ */
82
+ export interface GitHubStatusResponse {
83
+ success: true;
84
+ data: {
85
+ connected: boolean;
86
+ installation?: GitHubInstallation;
87
+ repositories?: GitHubRepository[];
88
+ };
89
+ }
90
+ /**
91
+ * Request to disconnect GitHub
92
+ * DELETE /api/internal/github/disconnect
93
+ */
94
+ export interface GitHubDisconnectResponse {
95
+ success: true;
96
+ disconnected: boolean;
97
+ }
98
+ /**
99
+ * Error codes for deployment failures
100
+ */
101
+ export type DeployErrorCode = "GITHUB_NOT_CONNECTED" | "REPO_NAME_TAKEN" | "REPO_NAME_INVALID" | "RATE_LIMIT_EXCEEDED" | "PLAN_LIMIT_EXCEEDED" | "TEMPLATE_NOT_FOUND" | "GITHUB_API_ERROR" | "SCAFFOLDER_ERROR" | "PROJECT_CREATION_ERROR" | "SECRETS_ERROR" | "INTERNAL_ERROR";
102
+ /**
103
+ * Request body for deploy to GitHub endpoint
104
+ * POST /api/internal/deploy/github
105
+ */
106
+ export interface DeployToGitHubRequest {
107
+ /** Repository name (e.g., "my-mcp-agent") */
108
+ repoName: string;
109
+ /** Template to use for scaffolding */
110
+ template: TemplateType;
111
+ /** Target deployment platform */
112
+ platform: DeployPlatformType;
113
+ /** Optional: Make repository private (default: true) */
114
+ isPrivate?: boolean;
115
+ /** Optional: Repository description */
116
+ description?: string;
117
+ }
118
+ /**
119
+ * AgentShield project information created during deployment
120
+ */
121
+ export interface DeployedProject {
122
+ id: string;
123
+ friendlyId: string;
124
+ /** API key - shown only once, must be saved by user */
125
+ apiKey: string;
126
+ }
127
+ /**
128
+ * Deployment result data
129
+ */
130
+ export interface DeployToGitHubData {
131
+ /** GitHub repository URL */
132
+ repoUrl: string;
133
+ /** Full repository name (e.g., "user/my-mcp-agent") */
134
+ repoFullName: string;
135
+ /** AgentShield project (auto-created) */
136
+ project: DeployedProject;
137
+ /** Cloudflare Deploy Button URL */
138
+ deployUrl: string;
139
+ /** Next steps for the user */
140
+ nextSteps: string[];
141
+ }
142
+ /**
143
+ * Successful deploy response
144
+ * POST /api/internal/deploy/github
145
+ */
146
+ export interface DeployToGitHubResponse {
147
+ success: true;
148
+ data: DeployToGitHubData;
149
+ }
150
+ /**
151
+ * Deploy error response
152
+ */
153
+ export interface DeployErrorResponse {
154
+ success: false;
155
+ error: {
156
+ code: DeployErrorCode;
157
+ message: string;
158
+ details?: Record<string, unknown>;
159
+ };
160
+ }
161
+ /**
162
+ * Union type for deploy response
163
+ */
164
+ export type DeployToGitHubResult = DeployToGitHubResponse | DeployErrorResponse;
165
+ /**
166
+ * Tracked deployed repository
167
+ */
168
+ export interface DeployedRepository {
169
+ id: string;
170
+ userId: string;
171
+ projectId: string;
172
+ installationId: string;
173
+ repoFullName: string;
174
+ repoUrl: string;
175
+ template: TemplateType;
176
+ platform: DeployPlatformType;
177
+ cloudflareDeployed: boolean;
178
+ cloudflareUrl?: string | null;
179
+ createdAt: string;
180
+ updatedAt: string;
181
+ }
182
+ /**
183
+ * Response for listing deployed repositories
184
+ * GET /api/internal/deploy/repositories
185
+ */
186
+ export interface ListDeployedRepositoriesResponse {
187
+ success: true;
188
+ data: DeployedRepository[];
189
+ }
190
+ /**
191
+ * Generated file for GitHub commit
192
+ */
193
+ export interface GeneratedFile {
194
+ /** File path relative to repository root */
195
+ path: string;
196
+ /** File content (UTF-8 string or base64 for binary) */
197
+ content: string;
198
+ /** Whether content is base64 encoded */
199
+ isBase64?: boolean;
200
+ }
201
+ /**
202
+ * Scaffolder options for in-memory file generation
203
+ */
204
+ export interface ScaffolderOptions {
205
+ projectName: string;
206
+ template: TemplateType;
207
+ platform: DeployPlatformType;
208
+ agentShieldProjectId?: string;
209
+ agentShieldApiKey?: string;
210
+ skipIdentity?: boolean;
211
+ }
212
+ /**
213
+ * Result of scaffolder file generation
214
+ */
215
+ export interface ScaffolderResult {
216
+ success: boolean;
217
+ files: GeneratedFile[];
218
+ identity?: {
219
+ did: string;
220
+ publicKey: string;
221
+ privateKey: string;
222
+ };
223
+ warnings?: string[];
224
+ }
225
+ /**
226
+ * Deployment step status
227
+ */
228
+ export type DeployStepStatus = "pending" | "in_progress" | "completed" | "failed";
229
+ /**
230
+ * Individual deployment step
231
+ */
232
+ export interface DeployStep {
233
+ id: string;
234
+ name: string;
235
+ status: DeployStepStatus;
236
+ message?: string;
237
+ startedAt?: string;
238
+ completedAt?: string;
239
+ }
240
+ /**
241
+ * Overall deployment progress
242
+ */
243
+ export interface DeploymentProgress {
244
+ steps: DeployStep[];
245
+ currentStep: number;
246
+ totalSteps: number;
247
+ overallStatus: "pending" | "in_progress" | "completed" | "failed";
248
+ }
249
+ /**
250
+ * Wrapped GitHub status response
251
+ */
252
+ export type GitHubStatusAPIResponse = AgentShieldAPIResponse<GitHubStatusResponse["data"]>;
253
+ /**
254
+ * Wrapped deploy response
255
+ */
256
+ export type DeployToGitHubAPIResponse = AgentShieldAPIResponse<DeployToGitHubData>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * One-Click Deployment API Type Definitions
4
+ *
5
+ * TypeScript interfaces for the AgentShield One-Click Deployment feature.
6
+ * Enables users to deploy MCP-I agents to Cloudflare Workers with a single click.
7
+ *
8
+ * @package @kya-os/contracts/deploy
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,5 +3,8 @@
3
3
  *
4
4
  * Exports for OAuth identity → persistent user DID resolution.
5
5
  * Part of Phase 5: Identity Resolution Integration
6
+ *
7
+ * Also exports KTA registration types for reputation tracking.
6
8
  */
7
9
  export * from "./schemas.js";
10
+ export { KTARegistration, KTARegistrationSchema, AgentIdentity, AgentIdentitySchema, } from "../config/identity.js";
@@ -4,6 +4,8 @@
4
4
  *
5
5
  * Exports for OAuth identity → persistent user DID resolution.
6
6
  * Part of Phase 5: Identity Resolution Integration
7
+ *
8
+ * Also exports KTA registration types for reputation tracking.
7
9
  */
8
10
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
11
  if (k2 === undefined) k2 = k;
@@ -20,4 +22,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
22
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
23
  };
22
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.AgentIdentitySchema = exports.KTARegistrationSchema = void 0;
23
26
  __exportStar(require("./schemas.js"), exports);
27
+ // Re-export KTA registration and AgentIdentity types from config/identity (canonical location)
28
+ var identity_js_1 = require("../config/identity.js");
29
+ Object.defineProperty(exports, "KTARegistrationSchema", { enumerable: true, get: function () { return identity_js_1.KTARegistrationSchema; } });
30
+ Object.defineProperty(exports, "AgentIdentitySchema", { enumerable: true, get: function () { return identity_js_1.AgentIdentitySchema; } });
package/dist/index.js CHANGED
@@ -56,3 +56,4 @@ exports.SUPPORTED_XMCP_I_VERSION = "^1.0.0";
56
56
  // import { ... } from '@kya-os/contracts/tool-protection'
57
57
  // import { ... } from '@kya-os/contracts/well-known'
58
58
  // import { ... } from '@kya-os/contracts/identity' // Phase 5: Identity resolution
59
+ // import { ... } from '@kya-os/contracts/reputation' // Reputation scoring system