@agent-watch/protocol 0.1.0

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 (50) hide show
  1. package/README.md +322 -0
  2. package/dist/index.d.ts +15 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +35 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/schemas/action.schema.json +71 -0
  7. package/dist/schemas/approval-request.schema.json +36 -0
  8. package/dist/schemas/approval-response.schema.json +36 -0
  9. package/dist/schemas/entitlement-request.schema.json +25 -0
  10. package/dist/schemas/entitlement-response.schema.json +38 -0
  11. package/dist/schemas/hook-input.schema.json +34 -0
  12. package/dist/schemas/hook-output.schema.json +20 -0
  13. package/dist/schemas/push.schema.json +30 -0
  14. package/dist/schemas/registration.schema.json +30 -0
  15. package/dist/schemas/session.schema.json +47 -0
  16. package/dist/schemas/subscription-event.schema.json +41 -0
  17. package/dist/schemas/subscription-status.schema.json +46 -0
  18. package/dist/types/action.d.ts +34 -0
  19. package/dist/types/action.d.ts.map +1 -0
  20. package/dist/types/action.js +6 -0
  21. package/dist/types/action.js.map +1 -0
  22. package/dist/types/approval.d.ts +30 -0
  23. package/dist/types/approval.d.ts.map +1 -0
  24. package/dist/types/approval.js +6 -0
  25. package/dist/types/approval.js.map +1 -0
  26. package/dist/types/hook.d.ts +24 -0
  27. package/dist/types/hook.d.ts.map +1 -0
  28. package/dist/types/hook.js +6 -0
  29. package/dist/types/hook.js.map +1 -0
  30. package/dist/types/push.d.ts +15 -0
  31. package/dist/types/push.d.ts.map +1 -0
  32. package/dist/types/push.js +6 -0
  33. package/dist/types/push.js.map +1 -0
  34. package/dist/types/registration.d.ts +15 -0
  35. package/dist/types/registration.d.ts.map +1 -0
  36. package/dist/types/registration.js +6 -0
  37. package/dist/types/registration.js.map +1 -0
  38. package/dist/types/session.d.ts +21 -0
  39. package/dist/types/session.d.ts.map +1 -0
  40. package/dist/types/session.js +6 -0
  41. package/dist/types/session.js.map +1 -0
  42. package/dist/types/subscription.d.ts +58 -0
  43. package/dist/types/subscription.d.ts.map +1 -0
  44. package/dist/types/subscription.js +6 -0
  45. package/dist/types/subscription.js.map +1 -0
  46. package/dist/validators.d.ts +36 -0
  47. package/dist/validators.d.ts.map +1 -0
  48. package/dist/validators.js +92 -0
  49. package/dist/validators.js.map +1 -0
  50. package/package.json +37 -0
@@ -0,0 +1,30 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "title": "DeviceRegistration",
5
+ "description": "Phone app registration data",
6
+ "additionalProperties": false,
7
+ "required": ["deviceToken", "platform", "pairingId"],
8
+ "properties": {
9
+ "deviceToken": {
10
+ "type": "string",
11
+ "description": "FCM or APNs device token",
12
+ "maxLength": 1024
13
+ },
14
+ "platform": {
15
+ "type": "string",
16
+ "description": "Platform type",
17
+ "enum": ["ios", "android"]
18
+ },
19
+ "sessionId": {
20
+ "type": "string",
21
+ "description": "Current session ID if registering during session",
22
+ "maxLength": 255
23
+ },
24
+ "pairingId": {
25
+ "type": "string",
26
+ "description": "Pairing ID for device linkage",
27
+ "maxLength": 255
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "title": "Session",
5
+ "description": "A single agent conversation",
6
+ "additionalProperties": false,
7
+ "required": ["id", "ide", "cwd", "startedAt", "status"],
8
+ "properties": {
9
+ "id": {
10
+ "type": "string",
11
+ "description": "Unique session identifier",
12
+ "maxLength": 255
13
+ },
14
+ "ide": {
15
+ "type": "string",
16
+ "description": "IDE name",
17
+ "maxLength": 100
18
+ },
19
+ "cwd": {
20
+ "type": "string",
21
+ "description": "Current working directory",
22
+ "maxLength": 4096
23
+ },
24
+ "startedAt": {
25
+ "type": "string",
26
+ "description": "ISO 8601 timestamp when session started",
27
+ "format": "date-time",
28
+ "maxLength": 64
29
+ },
30
+ "endedAt": {
31
+ "type": "string",
32
+ "description": "ISO 8601 timestamp when session ended",
33
+ "format": "date-time",
34
+ "maxLength": 64
35
+ },
36
+ "status": {
37
+ "type": "string",
38
+ "description": "Current session status",
39
+ "enum": ["active", "completed", "failed", "cancelled"]
40
+ },
41
+ "pairingId": {
42
+ "type": "string",
43
+ "description": "Pairing ID if session is paired to a device",
44
+ "maxLength": 255
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "title": "SubscriptionEvent",
5
+ "description": "FCM message for subscription limit events",
6
+ "additionalProperties": false,
7
+ "required": ["eventType"],
8
+ "properties": {
9
+ "eventType": {
10
+ "type": "string",
11
+ "description": "Type of subscription event",
12
+ "enum": ["limit_reached", "limit_warning", "plan_upgraded", "plan_downgraded"]
13
+ },
14
+ "limitType": {
15
+ "type": "string",
16
+ "description": "Limit type for limit events",
17
+ "enum": ["daily", "monthly"]
18
+ },
19
+ "count": {
20
+ "type": "integer",
21
+ "description": "Current count for limit events",
22
+ "minimum": 0
23
+ },
24
+ "limit": {
25
+ "type": "integer",
26
+ "description": "Limit value for limit events",
27
+ "minimum": 0
28
+ },
29
+ "resetDate": {
30
+ "type": "string",
31
+ "description": "ISO 8601 timestamp when count resets",
32
+ "format": "date-time",
33
+ "maxLength": 64
34
+ },
35
+ "newPlan": {
36
+ "type": "string",
37
+ "description": "New plan for upgrade/downgrade events",
38
+ "enum": ["free", "pro", "enterprise"]
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "title": "SubscriptionStatus",
5
+ "description": "User's subscription and entitlement status",
6
+ "additionalProperties": false,
7
+ "required": ["plan", "approvalCount", "approvalLimit", "resetDate", "deviceCount", "featureFlags"],
8
+ "properties": {
9
+ "plan": {
10
+ "type": "string",
11
+ "description": "Current subscription plan",
12
+ "enum": ["free", "pro", "enterprise"]
13
+ },
14
+ "approvalCount": {
15
+ "type": "integer",
16
+ "description": "Current approval count in period",
17
+ "minimum": 0
18
+ },
19
+ "approvalLimit": {
20
+ "description": "Approval limit for current plan (null = unlimited)",
21
+ "oneOf": [
22
+ { "type": "integer", "minimum": 0 },
23
+ { "type": "null" }
24
+ ]
25
+ },
26
+ "resetDate": {
27
+ "type": "string",
28
+ "description": "ISO 8601 timestamp when approval count resets",
29
+ "format": "date-time",
30
+ "maxLength": 64
31
+ },
32
+ "deviceCount": {
33
+ "type": "integer",
34
+ "description": "Number of paired devices",
35
+ "minimum": 0
36
+ },
37
+ "featureFlags": {
38
+ "type": "array",
39
+ "description": "Enabled feature flags",
40
+ "items": {
41
+ "type": "string",
42
+ "enum": ["unlimited_approvals", "priority_support", "custom_branding"]
43
+ }
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * AgentAction — A single agent tool call
3
+ */
4
+ export type ActionTier = 'read' | 'write' | 'run';
5
+ export type ActionOutcome = 'allowed' | 'denied' | 'auto_approved';
6
+ export interface AutoApprovalRecord {
7
+ /** Reason for auto-approval */
8
+ reason: 'limit_reached';
9
+ /** Type of limit that was reached */
10
+ limitType: 'daily' | 'monthly';
11
+ /** ISO 8601 timestamp when the limit resets */
12
+ resetDate: string;
13
+ }
14
+ export interface AgentAction {
15
+ /** Unique action identifier */
16
+ id: string;
17
+ /** Session this action belongs to */
18
+ sessionId: string;
19
+ /** Tool name (e.g., "read_file", "run_in_terminal") */
20
+ toolName: string;
21
+ /** Tool input parameters as JSON object */
22
+ input: Record<string, unknown>;
23
+ /** Human-readable summary of the action */
24
+ summary: string;
25
+ /** Action tier (read/write/run) */
26
+ tier: ActionTier;
27
+ /** ISO 8601 timestamp when action was requested */
28
+ timestamp: string;
29
+ /** Action outcome - how it was resolved */
30
+ outcome?: ActionOutcome;
31
+ /** Auto-approval details if outcome is auto_approved */
32
+ autoApprovalRecord?: AutoApprovalRecord;
33
+ }
34
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/types/action.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEnE,MAAM,WAAW,kBAAkB;IACjC,+BAA+B;IAC/B,MAAM,EAAE,eAAe,CAAC;IAExB,qCAAqC;IACrC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAE/B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IAEX,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAElB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IAEjB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE/B,2CAA2C;IAC3C,OAAO,EAAE,MAAM,CAAC;IAEhB,mCAAmC;IACnC,IAAI,EAAE,UAAU,CAAC;IAEjB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAElB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * AgentAction — A single agent tool call
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/types/action.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * ApprovalRequest and ApprovalResponse — Pending decision and user response
3
+ */
4
+ import { AgentAction } from './action';
5
+ export interface ApprovalRequest {
6
+ /** Unique approval request identifier */
7
+ approvalId: string;
8
+ /** Session this approval belongs to */
9
+ sessionId: string;
10
+ /** The action requiring approval */
11
+ action: AgentAction;
12
+ /** Previous actions in this session for context */
13
+ precedingActions: AgentAction[];
14
+ /** ISO 8601 timestamp when request expires */
15
+ timeout: string;
16
+ }
17
+ export type ApprovalDecision = 'allow' | 'deny';
18
+ export interface ApprovalResponse {
19
+ /** Approval request ID this response is for */
20
+ approvalId: string;
21
+ /** Session ID */
22
+ sessionId: string;
23
+ /** User's decision */
24
+ decision: ApprovalDecision;
25
+ /** HMAC signature for authenticity verification */
26
+ signature: string;
27
+ /** ISO 8601 timestamp when decision was made */
28
+ timestamp: string;
29
+ }
30
+ //# sourceMappingURL=approval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval.d.ts","sourceRoot":"","sources":["../../src/types/approval.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IAEnB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAElB,oCAAoC;IACpC,MAAM,EAAE,WAAW,CAAC;IAEpB,mDAAmD;IACnD,gBAAgB,EAAE,WAAW,EAAE,CAAC;IAEhC,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IAEnB,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAElB,sBAAsB;IACtB,QAAQ,EAAE,gBAAgB,CAAC;IAE3B,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAElB,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * ApprovalRequest and ApprovalResponse — Pending decision and user response
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=approval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/types/approval.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * HookInput and HookOutput — IDE stdin/stdout payloads for hook script
3
+ */
4
+ export type HookEventName = 'tool_call' | 'session_start' | 'session_end';
5
+ export interface HookInput {
6
+ /** Event being reported */
7
+ eventName: HookEventName;
8
+ /** Session ID */
9
+ sessionId: string;
10
+ /** Current working directory */
11
+ cwd: string;
12
+ /** Tool name (for tool_call events) */
13
+ toolName?: string;
14
+ /** Tool input parameters (for tool_call events) */
15
+ toolInput?: Record<string, unknown>;
16
+ }
17
+ export type HookDecision = 'allow' | 'deny';
18
+ export interface HookOutput {
19
+ /** Decision for the hook event */
20
+ decision: HookDecision;
21
+ /** Optional reason for denial */
22
+ reason?: string;
23
+ }
24
+ //# sourceMappingURL=hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.d.ts","sourceRoot":"","sources":["../../src/types/hook.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,eAAe,GAAG,aAAa,CAAC;AAE1E,MAAM,WAAW,SAAS;IACxB,2BAA2B;IAC3B,SAAS,EAAE,aAAa,CAAC;IAEzB,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAElB,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;IAEZ,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,CAAC;AAE5C,MAAM,WAAW,UAAU;IACzB,kCAAkC;IAClC,QAAQ,EAAE,YAAY,CAAC;IAEvB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * HookInput and HookOutput — IDE stdin/stdout payloads for hook script
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.js","sourceRoot":"","sources":["../../src/types/hook.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * PushPayload — Relay envelope for encrypted messages
3
+ */
4
+ export type PushPayloadType = 'approval_request' | 'session_start' | 'session_end' | 'subscription_event';
5
+ export interface PushPayload {
6
+ /** Type of payload being sent */
7
+ type: PushPayloadType;
8
+ /** Session ID (if applicable) */
9
+ sessionId?: string;
10
+ /** Pairing ID for routing */
11
+ pairingId: string;
12
+ /** Encrypted message blob (base64 encoded) */
13
+ encryptedBlob: string;
14
+ }
15
+ //# sourceMappingURL=push.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../src/types/push.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,eAAe,GAAG,kBAAkB,GAAG,eAAe,GAAG,aAAa,GAAG,oBAAoB,CAAC;AAE1G,MAAM,WAAW,WAAW;IAC1B,iCAAiC;IACjC,IAAI,EAAE,eAAe,CAAC;IAEtB,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAElB,8CAA8C;IAC9C,aAAa,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * PushPayload — Relay envelope for encrypted messages
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push.js","sourceRoot":"","sources":["../../src/types/push.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * DeviceRegistration — Phone app registration data
3
+ */
4
+ export type DevicePlatform = 'ios' | 'android';
5
+ export interface DeviceRegistration {
6
+ /** FCM or APNs device token */
7
+ deviceToken: string;
8
+ /** Platform type */
9
+ platform: DevicePlatform;
10
+ /** Current session ID (if registering during session) */
11
+ sessionId?: string;
12
+ /** Pairing ID for device linkage */
13
+ pairingId: string;
14
+ }
15
+ //# sourceMappingURL=registration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/types/registration.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,SAAS,CAAC;AAE/C,MAAM,WAAW,kBAAkB;IACjC,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;IAEpB,oBAAoB;IACpB,QAAQ,EAAE,cAAc,CAAC;IAEzB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * DeviceRegistration — Phone app registration data
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=registration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/types/registration.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Session — A single agent conversation
3
+ */
4
+ export type SessionStatus = 'active' | 'completed' | 'failed' | 'cancelled';
5
+ export interface Session {
6
+ /** Unique session identifier */
7
+ id: string;
8
+ /** IDE name (e.g., "vscode", "cursor", "windsurf") */
9
+ ide: string;
10
+ /** Current working directory at session start */
11
+ cwd: string;
12
+ /** ISO 8601 timestamp when session started */
13
+ startedAt: string;
14
+ /** ISO 8601 timestamp when session ended (if completed) */
15
+ endedAt?: string;
16
+ /** Current session status */
17
+ status: SessionStatus;
18
+ /** Pairing ID if session is paired to a device */
19
+ pairingId?: string;
20
+ }
21
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE5E,MAAM,WAAW,OAAO;IACtB,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IAEX,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAC;IAEZ,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;IAEZ,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAElB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,6BAA6B;IAC7B,MAAM,EAAE,aAAa,CAAC;IAEtB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Session — A single agent conversation
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/types/session.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Subscription type definitions (v2)
3
+ */
4
+ export type SubscriptionPlan = 'free' | 'pro' | 'enterprise';
5
+ export type FeatureFlag = 'unlimited_approvals' | 'priority_support' | 'custom_branding';
6
+ export interface SubscriptionStatus {
7
+ /** User's current plan */
8
+ plan: SubscriptionPlan;
9
+ /** Current approval count in period */
10
+ approvalCount: number;
11
+ /** Approval limit for current plan (null = unlimited) */
12
+ approvalLimit: number | null;
13
+ /** ISO 8601 timestamp when approval count resets */
14
+ resetDate: string;
15
+ /** Number of paired devices */
16
+ deviceCount: number;
17
+ /** Enabled feature flags */
18
+ featureFlags: FeatureFlag[];
19
+ }
20
+ export interface EntitlementRequest {
21
+ /** Pairing ID making the request */
22
+ pairingId: string;
23
+ /** Account ID for the user */
24
+ accountId: string;
25
+ /** Action type being checked */
26
+ actionType: string;
27
+ }
28
+ export type EntitlementDecision = 'allowed' | 'denied' | 'soft_limit_warning';
29
+ export type EntitlementErrorCode = 'limit_exceeded' | 'plan_downgraded' | 'account_suspended' | 'invalid_pairing';
30
+ export interface EntitlementResponse {
31
+ /** Whether action is allowed */
32
+ decision: EntitlementDecision;
33
+ /** Error code if denied */
34
+ errorCode?: EntitlementErrorCode;
35
+ /** Current count in period */
36
+ count: number;
37
+ /** Limit for current plan (null = unlimited) */
38
+ limit: number | null;
39
+ /** ISO 8601 timestamp when count resets */
40
+ resetDate: string;
41
+ }
42
+ export type SubscriptionEventType = 'limit_reached' | 'limit_warning' | 'plan_upgraded' | 'plan_downgraded';
43
+ export type LimitType = 'daily' | 'monthly';
44
+ export interface SubscriptionEvent {
45
+ /** Type of subscription event */
46
+ eventType: SubscriptionEventType;
47
+ /** Limit type (for limit events) */
48
+ limitType?: LimitType;
49
+ /** Current count (for limit events) */
50
+ count?: number;
51
+ /** Limit value (for limit events) */
52
+ limit?: number;
53
+ /** ISO 8601 timestamp when count resets */
54
+ resetDate?: string;
55
+ /** New plan (for upgrade/downgrade events) */
56
+ newPlan?: SubscriptionPlan;
57
+ }
58
+ //# sourceMappingURL=subscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../src/types/subscription.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,KAAK,GAAG,YAAY,CAAC;AAE7D,MAA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oC;IACpC,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Subscription type definitions (v2)
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=subscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../src/types/subscription.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Validation utilities using JSON schemas
3
+ */
4
+ import { Session } from './types/session';
5
+ import { AgentAction } from './types/action';
6
+ import { ApprovalRequest, ApprovalResponse } from './types/approval';
7
+ import { PushPayload } from './types/push';
8
+ import { DeviceRegistration } from './types/registration';
9
+ import { HookInput, HookOutput } from './types/hook';
10
+ import { SubscriptionStatus, EntitlementRequest, EntitlementResponse, SubscriptionEvent } from './types/subscription';
11
+ /** Validation result with typed data or error details */
12
+ export type ValidationResult<T> = {
13
+ success: true;
14
+ data: T;
15
+ } | {
16
+ success: false;
17
+ errors: Array<{
18
+ field: string;
19
+ message: string;
20
+ }>;
21
+ };
22
+ export declare const validate: {
23
+ session: (data: unknown) => ValidationResult<Session>;
24
+ agentAction: (data: unknown) => ValidationResult<AgentAction>;
25
+ approvalRequest: (data: unknown) => ValidationResult<ApprovalRequest>;
26
+ approvalResponse: (data: unknown) => ValidationResult<ApprovalResponse>;
27
+ pushPayload: (data: unknown) => ValidationResult<PushPayload>;
28
+ deviceRegistration: (data: unknown) => ValidationResult<DeviceRegistration>;
29
+ hookInput: (data: unknown) => ValidationResult<HookInput>;
30
+ hookOutput: (data: unknown) => ValidationResult<HookOutput>;
31
+ subscriptionStatus: (data: unknown) => ValidationResult<SubscriptionStatus>;
32
+ entitlementRequest: (data: unknown) => ValidationResult<EntitlementRequest>;
33
+ entitlementResponse: (data: unknown) => ValidationResult<EntitlementResponse>;
34
+ subscriptionEvent: (data: unknown) => ValidationResult<SubscriptionEvent>;
35
+ };
36
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA;;GAEG;AAoBH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAuC9B,yDAAyD;AACzD,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAC1B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC;AAuB1E,eAAO,MAAM,QAAQ;oBATL,OAAO;wBAAP,OAAO;4BAAP,OAAO;6BAAP,OAAO;wBAAP,OAAO;+BAAP,OAAO;sBAAP,OAAO;uBAAP,OAAO;+BAAP,OAAO;+BAAP,OAAO;gCAAP,OAAO;8BAAP,OAAO;CAsBtB,CAAC"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ /**
3
+ * Validation utilities using JSON schemas
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validate = void 0;
10
+ const ajv_1 = __importDefault(require("ajv"));
11
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
12
+ // Import all schemas
13
+ const session_schema_json_1 = __importDefault(require("./schemas/session.schema.json"));
14
+ const action_schema_json_1 = __importDefault(require("./schemas/action.schema.json"));
15
+ const approval_request_schema_json_1 = __importDefault(require("./schemas/approval-request.schema.json"));
16
+ const approval_response_schema_json_1 = __importDefault(require("./schemas/approval-response.schema.json"));
17
+ const push_schema_json_1 = __importDefault(require("./schemas/push.schema.json"));
18
+ const registration_schema_json_1 = __importDefault(require("./schemas/registration.schema.json"));
19
+ const hook_input_schema_json_1 = __importDefault(require("./schemas/hook-input.schema.json"));
20
+ const hook_output_schema_json_1 = __importDefault(require("./schemas/hook-output.schema.json"));
21
+ const subscription_status_schema_json_1 = __importDefault(require("./schemas/subscription-status.schema.json"));
22
+ const entitlement_request_schema_json_1 = __importDefault(require("./schemas/entitlement-request.schema.json"));
23
+ const entitlement_response_schema_json_1 = __importDefault(require("./schemas/entitlement-response.schema.json"));
24
+ const subscription_event_schema_json_1 = __importDefault(require("./schemas/subscription-event.schema.json"));
25
+ // Initialize Ajv with strict mode
26
+ const ajv = new ajv_1.default({
27
+ strict: true,
28
+ allErrors: true,
29
+ schemas: [
30
+ session_schema_json_1.default,
31
+ action_schema_json_1.default,
32
+ approval_request_schema_json_1.default,
33
+ approval_response_schema_json_1.default,
34
+ push_schema_json_1.default,
35
+ registration_schema_json_1.default,
36
+ hook_input_schema_json_1.default,
37
+ hook_output_schema_json_1.default,
38
+ subscription_status_schema_json_1.default,
39
+ entitlement_request_schema_json_1.default,
40
+ entitlement_response_schema_json_1.default,
41
+ subscription_event_schema_json_1.default,
42
+ ]
43
+ });
44
+ // Add format validators
45
+ (0, ajv_formats_1.default)(ajv);
46
+ // Create typed validators
47
+ const validateSession = ajv.compile(session_schema_json_1.default);
48
+ const validateAgentAction = ajv.compile(action_schema_json_1.default);
49
+ const validateApprovalRequest = ajv.compile(approval_request_schema_json_1.default);
50
+ const validateApprovalResponse = ajv.compile(approval_response_schema_json_1.default);
51
+ const validatePushPayload = ajv.compile(push_schema_json_1.default);
52
+ const validateDeviceRegistration = ajv.compile(registration_schema_json_1.default);
53
+ const validateHookInput = ajv.compile(hook_input_schema_json_1.default);
54
+ const validateHookOutput = ajv.compile(hook_output_schema_json_1.default);
55
+ const validateSubscriptionStatus = ajv.compile(subscription_status_schema_json_1.default);
56
+ const validateEntitlementRequest = ajv.compile(entitlement_request_schema_json_1.default);
57
+ const validateEntitlementResponse = ajv.compile(entitlement_response_schema_json_1.default);
58
+ const validateSubscriptionEvent = ajv.compile(subscription_event_schema_json_1.default);
59
+ /** Format Ajv errors for better readability */
60
+ function formatErrors(validator) {
61
+ if (!validator.errors)
62
+ return [{ field: 'unknown', message: 'Validation failed' }];
63
+ return validator.errors.map(err => ({
64
+ field: err.instancePath || err.schemaPath,
65
+ message: err.message || 'Validation error',
66
+ }));
67
+ }
68
+ /** Generic validate function wrapper */
69
+ function createValidator(validator) {
70
+ return (data) => {
71
+ if (validator(data)) {
72
+ return { success: true, data };
73
+ }
74
+ return { success: false, errors: formatErrors(validator) };
75
+ };
76
+ }
77
+ // Export validation functions
78
+ exports.validate = {
79
+ session: createValidator(validateSession),
80
+ agentAction: createValidator(validateAgentAction),
81
+ approvalRequest: createValidator(validateApprovalRequest),
82
+ approvalResponse: createValidator(validateApprovalResponse),
83
+ pushPayload: createValidator(validatePushPayload),
84
+ deviceRegistration: createValidator(validateDeviceRegistration),
85
+ hookInput: createValidator(validateHookInput),
86
+ hookOutput: createValidator(validateHookOutput),
87
+ subscriptionStatus: createValidator(validateSubscriptionStatus),
88
+ entitlementRequest: createValidator(validateEntitlementRequest),
89
+ entitlementResponse: createValidator(validateEntitlementResponse),
90
+ subscriptionEvent: createValidator(validateSubscriptionEvent),
91
+ };
92
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,8CAA4C;AAC5C,8DAAqC;AAErC,qBAAqB;AACrB,wFAA0D;AAC1D,sFAAwD;AACxD,0GAA2E;AAC3E,4GAA6E;AAC7E,kFAAoD;AACpD,kGAAoE;AACpE,8FAA+D;AAC/D,gGAAiE;AACjE,gHAAiF;AACjF,gHAAiF;AACjF,kHAAmF;AACnF,8GAA+E;AAgB/E,kCAAkC;AAClC,MAAM,GAAG,GAAG,IAAI,aAAG,CAAC;IAClB,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;IACf,OAAO,EAAE;QACP,6BAAa;QACb,4BAAY;QACZ,sCAAqB;QACrB,uCAAsB;QACtB,0BAAU;QACV,kCAAkB;QAClB,gCAAe;QACf,iCAAgB;QAChB,yCAAwB;QACxB,yCAAwB;QACxB,0CAAyB;QACzB,wCAAuB;KACxB;CACF,CAAC,CAAC;AAEH,wBAAwB;AACxB,IAAA,qBAAU,EAAC,GAAG,CAAC,CAAC;AAEhB,0BAA0B;AAC1B,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,6BAAa,CAA8B,CAAC;AAChF,MAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC,4BAAY,CAAkC,CAAC;AACvF,MAAM,uBAAuB,GAAG,GAAG,CAAC,OAAO,CAAC,sCAAqB,CAAsC,CAAC;AACxG,MAAM,wBAAwB,GAAG,GAAG,CAAC,OAAO,CAAC,uCAAsB,CAAuC,CAAC;AAC3G,MAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC,0BAAU,CAAkC,CAAC;AACrF,MAAM,0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