@allternit/ix 0.1.0 → 0.1.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.
Files changed (103) hide show
  1. package/README.md +6 -6
  2. package/dist/adapters/json-render.d.ts +5 -5
  3. package/dist/adapters/json-render.js +12 -12
  4. package/dist/collab/visual-editor.d.ts +1 -1
  5. package/dist/collab/visual-editor.js +4 -4
  6. package/dist/collab/visual-editor.js.map +1 -1
  7. package/dist/collab/yjs-adapter.d.ts +1 -1
  8. package/dist/collab/yjs-adapter.js +2 -2
  9. package/dist/collab/yjs-adapter.js.map +1 -1
  10. package/dist/collab/yjs-client.js +1 -1
  11. package/dist/collab/yjs-client.js.map +1 -1
  12. package/dist/collab/yjs-types.js +1 -1
  13. package/dist/collab/yjs-types.js.map +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/pipeline/llm-to-ix.d.ts +5 -5
  17. package/dist/pipeline/llm-to-ix.d.ts.map +1 -1
  18. package/dist/pipeline/llm-to-ix.js +6 -6
  19. package/dist/react/renderer.d.ts +2 -2
  20. package/dist/react/renderer.js +3 -3
  21. package/dist/react/renderer.js.map +1 -1
  22. package/dist/renderer/renderer.d.ts +1 -1
  23. package/dist/renderer/renderer.js +1 -1
  24. package/dist/runtime/capsule-runtime.d.ts +1 -1
  25. package/dist/runtime/capsule-runtime.js +1 -1
  26. package/dist/sdk/api.d.ts +3 -3
  27. package/dist/sdk/api.js +3 -3
  28. package/dist/sdk/index.d.ts +2 -2
  29. package/dist/sdk/index.js +2 -2
  30. package/dist/sdk/react.d.ts +2 -2
  31. package/dist/sdk/react.js +2 -2
  32. package/dist/state/index.d.ts +1 -1
  33. package/dist/state/index.js +1 -1
  34. package/dist/state/store.d.ts +1 -1
  35. package/dist/state/store.js +3 -3
  36. package/dist/state/store.js.map +1 -1
  37. package/dist/svelte/index.d.ts +1 -1
  38. package/dist/svelte/index.js +1 -1
  39. package/dist/svelte/renderer.d.ts +3 -3
  40. package/dist/svelte/renderer.js +4 -4
  41. package/dist/svelte/renderer.js.map +1 -1
  42. package/dist/types/index.d.ts +1 -1
  43. package/dist/types/index.js +1 -1
  44. package/dist/vue/renderer.d.ts +3 -3
  45. package/dist/vue/renderer.js +5 -5
  46. package/dist/vue/renderer.js.map +1 -1
  47. package/package.json +8 -8
  48. package/dist/adapters/json-render.d.ts.bak +0 -211
  49. package/dist/adapters/json-render.js.bak +0 -576
  50. package/dist/catalog/registry.d.ts.bak +0 -65
  51. package/dist/catalog/registry.js.bak +0 -388
  52. package/dist/collab/capsule-registry.d.ts.bak +0 -114
  53. package/dist/collab/capsule-registry.js.bak +0 -271
  54. package/dist/collab/index.d.ts.bak +0 -21
  55. package/dist/collab/index.js.bak +0 -32
  56. package/dist/collab/visual-editor.d.ts.bak +0 -199
  57. package/dist/collab/visual-editor.js.bak +0 -259
  58. package/dist/collab/yjs-adapter.d.ts.bak +0 -95
  59. package/dist/collab/yjs-adapter.js.bak +0 -282
  60. package/dist/collab/yjs-client.d.ts.bak +0 -101
  61. package/dist/collab/yjs-client.js.bak +0 -193
  62. package/dist/collab/yjs-protocols.d.ts.bak +0 -128
  63. package/dist/collab/yjs-protocols.js.bak +0 -245
  64. package/dist/collab/yjs-types.d.ts.bak +0 -201
  65. package/dist/collab/yjs-types.js.bak +0 -45
  66. package/dist/index.d.ts.bak +0 -38
  67. package/dist/index.js.bak +0 -48
  68. package/dist/pipeline/llm-to-ix.d.ts.bak +0 -249
  69. package/dist/pipeline/llm-to-ix.js.bak +0 -992
  70. package/dist/react/index.d.ts.bak +0 -18
  71. package/dist/react/index.js.bak +0 -18
  72. package/dist/react/renderer.d.ts.bak +0 -47
  73. package/dist/react/renderer.js.bak +0 -420
  74. package/dist/renderer/renderer.d.ts.bak +0 -55
  75. package/dist/renderer/renderer.js.bak +0 -232
  76. package/dist/runtime/capsule-runtime.d.ts.bak +0 -227
  77. package/dist/runtime/capsule-runtime.js.bak +0 -563
  78. package/dist/runtime/policy-gates.d.ts.bak +0 -116
  79. package/dist/runtime/policy-gates.js.bak +0 -317
  80. package/dist/schema/ui-ir.d.ts.bak +0 -26
  81. package/dist/schema/ui-ir.js.bak +0 -51
  82. package/dist/sdk/api.d.ts.bak +0 -101
  83. package/dist/sdk/api.js.bak +0 -177
  84. package/dist/sdk/index.d.ts.bak +0 -9
  85. package/dist/sdk/index.js.bak +0 -10
  86. package/dist/sdk/react.d.ts.bak +0 -63
  87. package/dist/sdk/react.js.bak +0 -161
  88. package/dist/state/index.d.ts.bak +0 -8
  89. package/dist/state/index.js.bak +0 -8
  90. package/dist/state/patch.d.ts.bak +0 -73
  91. package/dist/state/patch.js.bak +0 -437
  92. package/dist/state/store.d.ts.bak +0 -50
  93. package/dist/state/store.js.bak +0 -246
  94. package/dist/svelte/index.d.ts.bak +0 -15
  95. package/dist/svelte/index.js.bak +0 -15
  96. package/dist/svelte/renderer.d.ts.bak +0 -35
  97. package/dist/svelte/renderer.js.bak +0 -317
  98. package/dist/types/index.d.ts.bak +0 -349
  99. package/dist/types/index.js.bak +0 -152
  100. package/dist/vue/index.d.ts.bak +0 -18
  101. package/dist/vue/index.js.bak +0 -18
  102. package/dist/vue/renderer.d.ts.bak +0 -46
  103. package/dist/vue/renderer.js.bak +0 -302
@@ -1,317 +0,0 @@
1
- /**
2
- * Policy Gates
3
- *
4
- * Security controls for IX capsule execution.
5
- *
6
- * Policy gates enforce security boundaries for:
7
- * - Action execution (rate limiting, allowlists)
8
- * - State changes (validation, sanitization)
9
- * - Rendering (component restrictions, prop filtering)
10
- */
11
- /**
12
- * Rate Limiting Policy Gate
13
- *
14
- * Limits action execution rate per capsule.
15
- */
16
- export function createRateLimitGate(options) {
17
- const { maxActionsPerMinute, burstSize = maxActionsPerMinute, windowMs = 60000 } = options;
18
- const actionLog = new Map();
19
- return {
20
- name: 'rate-limit',
21
- check: (_type, context) => {
22
- if (_type !== 'action')
23
- return { allowed: true };
24
- const now = Date.now();
25
- const log = actionLog.get(context.capsuleId) || [];
26
- // Remove old entries outside window
27
- const validLog = log.filter((ts) => now - ts < windowMs);
28
- // Check burst limit
29
- if (validLog.length >= burstSize) {
30
- return {
31
- allowed: false,
32
- reason: `Rate limit exceeded: ${maxActionsPerMinute} actions per minute`,
33
- };
34
- }
35
- // Record action
36
- validLog.push(now);
37
- actionLog.set(context.capsuleId, validLog);
38
- return { allowed: true };
39
- },
40
- };
41
- }
42
- /**
43
- * Action Allowlist Policy Gate
44
- *
45
- * Only allows specific actions to execute.
46
- */
47
- export function createActionAllowlistGate(allowedActions) {
48
- const allowedSet = new Set(allowedActions);
49
- return {
50
- name: 'action-allowlist',
51
- check: (type, context) => {
52
- if (type !== 'action')
53
- return { allowed: true };
54
- if (!context.actionId || !allowedSet.has(context.actionId)) {
55
- return {
56
- allowed: false,
57
- reason: `Action '${context.actionId}' is not in allowlist`,
58
- };
59
- }
60
- return { allowed: true };
61
- },
62
- };
63
- }
64
- /**
65
- * Component Restrictions Policy Gate
66
- *
67
- * Restricts which components can be rendered.
68
- */
69
- export function createComponentRestrictionsGate(options) {
70
- const { allowedComponents, blockedComponents = [], maxDepth = 10 } = options;
71
- const allowedSet = allowedComponents ? new Set(allowedComponents) : null;
72
- const blockedSet = new Set(blockedComponents);
73
- return {
74
- name: 'component-restrictions',
75
- check: (type, context) => {
76
- if (type !== 'render')
77
- return { allowed: true };
78
- if (!context.component)
79
- return { allowed: true };
80
- // Check blocked
81
- if (blockedSet.has(context.component)) {
82
- return {
83
- allowed: false,
84
- reason: `Component '${context.component}' is blocked`,
85
- };
86
- }
87
- // Check allowed
88
- if (allowedSet && !allowedSet.has(context.component)) {
89
- return {
90
- allowed: false,
91
- reason: `Component '${context.component}' is not in allowlist`,
92
- };
93
- }
94
- return { allowed: true };
95
- },
96
- };
97
- }
98
- /**
99
- * State Validation Policy Gate
100
- *
101
- * Validates state changes against schema.
102
- */
103
- export function createStateValidationGate(schema) {
104
- return {
105
- name: 'state-validation',
106
- check: (type, context) => {
107
- if (type !== 'state-change')
108
- return { allowed: true };
109
- // This would need the actual path and value being changed
110
- // For now, validate entire state snapshot
111
- if (!context.state)
112
- return { allowed: true };
113
- for (const [path, rules] of Object.entries(schema)) {
114
- const value = getPathValue(context.state, path);
115
- // Check required
116
- if (rules.required && (value === undefined || value === null)) {
117
- return {
118
- allowed: false,
119
- reason: `State path '${path}' is required`,
120
- };
121
- }
122
- // Skip if not required and undefined
123
- if (!rules.required && (value === undefined || value === null)) {
124
- continue;
125
- }
126
- // Check type
127
- if (rules.type) {
128
- const actualType = getValueType(value);
129
- if (actualType !== rules.type) {
130
- return {
131
- allowed: false,
132
- reason: `State path '${path}' must be ${rules.type}, got ${actualType}`,
133
- };
134
- }
135
- }
136
- // Run custom validation
137
- if (rules.validate) {
138
- const result = rules.validate(value);
139
- if (result !== true) {
140
- return {
141
- allowed: false,
142
- reason: typeof result === 'string' ? result : `Validation failed for '${path}'`,
143
- };
144
- }
145
- }
146
- }
147
- return { allowed: true };
148
- },
149
- };
150
- }
151
- /**
152
- * Prop Sanitization Policy Gate
153
- *
154
- * Sanitizes component props to prevent XSS and injection attacks.
155
- */
156
- export function createPropSanitizationGate(options) {
157
- const { allowHTML = false, allowedTags = [], allowedAttributes = [] } = options;
158
- return {
159
- name: 'prop-sanitization',
160
- check: (type, context) => {
161
- if (type !== 'render' || !context.props)
162
- return { allowed: true };
163
- const sanitizedProps = { ...context.props };
164
- let modified = false;
165
- for (const [key, value] of Object.entries(context.props)) {
166
- // Sanitize string values
167
- if (typeof value === 'string') {
168
- // Remove script tags and event handlers
169
- let sanitized = value;
170
- if (!allowHTML) {
171
- // Strip all HTML
172
- sanitized = sanitized.replace(/<[^>]*>/g, '');
173
- }
174
- else {
175
- // Remove script tags and their content completely
176
- sanitized = sanitized.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
177
- // Allow only specific tags
178
- const tagRegex = /<\/?([a-z][a-z0-9]*)[^>]*>/gi;
179
- sanitized = sanitized.replace(tagRegex, (match, tag) => {
180
- return allowedTags.includes(tag.toLowerCase()) ? match : '';
181
- });
182
- // Remove event handlers
183
- sanitized = sanitized.replace(/on\w+\s*=/gi, '');
184
- // Remove javascript: URLs
185
- sanitized = sanitized.replace(/javascript:/gi, '');
186
- }
187
- if (sanitized !== value) {
188
- sanitizedProps[key] = sanitized;
189
- modified = true;
190
- }
191
- }
192
- // Block dangerous props
193
- if (key.startsWith('on') && typeof value === 'string') {
194
- // Block string-based event handlers
195
- delete sanitizedProps[key];
196
- modified = true;
197
- }
198
- }
199
- return {
200
- allowed: true,
201
- context: modified ? { ...context, props: sanitizedProps } : context,
202
- };
203
- },
204
- };
205
- }
206
- /**
207
- * Resource Limiting Policy Gate
208
- *
209
- * Enforces resource limits on capsules.
210
- */
211
- export function createResourceLimitGate(options) {
212
- const { maxStateSize = 1024 * 1024, maxComponents = 100, maxActions = 1000 } = options;
213
- const actionCounts = new Map();
214
- return {
215
- name: 'resource-limit',
216
- check: (type, context) => {
217
- // Check state size
218
- if (type === 'state-change' && context.state) {
219
- const stateSize = JSON.stringify(context.state).length;
220
- if (stateSize > maxStateSize) {
221
- return {
222
- allowed: false,
223
- reason: `State size (${stateSize} bytes) exceeds limit (${maxStateSize} bytes)`,
224
- };
225
- }
226
- }
227
- // Check action count
228
- if (type === 'action') {
229
- const count = (actionCounts.get(context.capsuleId) || 0) + 1;
230
- if (count > maxActions) {
231
- return {
232
- allowed: false,
233
- reason: `Maximum action count (${maxActions}) exceeded`,
234
- };
235
- }
236
- actionCounts.set(context.capsuleId, count);
237
- }
238
- return { allowed: true };
239
- },
240
- };
241
- }
242
- /**
243
- * Audit Logging Policy Gate
244
- *
245
- * Logs all policy decisions for audit purposes.
246
- */
247
- export function createAuditLogGate(options) {
248
- const { logFn, logAllowed = false } = options;
249
- return {
250
- name: 'audit-log',
251
- check: (type, context) => {
252
- const shouldLog = logAllowed || type === 'action';
253
- if (shouldLog) {
254
- logFn({
255
- timestamp: Date.now(),
256
- capsuleId: context.capsuleId,
257
- actionId: context.actionId,
258
- type,
259
- agentId: context.agentId,
260
- });
261
- }
262
- return { allowed: true };
263
- },
264
- };
265
- }
266
- /**
267
- * Compose multiple policy gates
268
- */
269
- export function composePolicyGates(...gates) {
270
- return {
271
- name: `composed(${gates.map((g) => g.name).join(', ')})`,
272
- check: async (type, context) => {
273
- let currentContext = context;
274
- for (const gate of gates) {
275
- const result = await gate.check(type, currentContext);
276
- if (!result.allowed) {
277
- return result;
278
- }
279
- if (result.context) {
280
- currentContext = result.context;
281
- }
282
- }
283
- return { allowed: true, context: currentContext };
284
- },
285
- };
286
- }
287
- /**
288
- * Create default security policy gates
289
- */
290
- export function createDefaultPolicyGates() {
291
- return [
292
- createRateLimitGate({ maxActionsPerMinute: 60 }),
293
- createPropSanitizationGate({ allowHTML: false }),
294
- createResourceLimitGate({
295
- maxStateSize: 1024 * 1024, // 1MB
296
- maxComponents: 100,
297
- maxActions: 1000,
298
- }),
299
- ];
300
- }
301
- // Helper functions
302
- function getPathValue(obj, path) {
303
- return path.split('.').reduce((acc, key) => {
304
- if (acc && typeof acc === 'object') {
305
- return acc[key];
306
- }
307
- return undefined;
308
- }, obj);
309
- }
310
- function getValueType(value) {
311
- if (value === null)
312
- return 'null';
313
- if (Array.isArray(value))
314
- return 'array';
315
- return typeof value;
316
- }
317
- //# sourceMappingURL=policy-gates.js.map
@@ -1,26 +0,0 @@
1
- /**
2
- * UI Intermediate Representation Schema
3
- *
4
- * Core schema definitions for declarative UI generation.
5
- */
6
- import type { UIRoot, UIComponent, UIState, UIAction, StateVariable, StateBinding, EventHandler, Expression } from '../types';
7
- export type { UIRoot, UIComponent, UIState, UIAction, StateVariable, StateBinding, EventHandler, Expression, };
8
- /**
9
- * Schema version
10
- */
11
- export declare const UI_IR_VERSION = "1.0.0";
12
- /**
13
- * Validate UIRoot structure
14
- */
15
- export declare function validateUIRoot(root: unknown): root is UIRoot;
16
- /**
17
- * Create empty UI root
18
- */
19
- export declare function createEmptyRoot(): UIRoot;
20
- /**
21
- * Create UI root from template
22
- */
23
- export declare function createRootFromTemplate(template: Partial<UIRoot> & {
24
- components: UIComponent[];
25
- }): UIRoot;
26
- //# sourceMappingURL=ui-ir.d.ts.map
@@ -1,51 +0,0 @@
1
- /**
2
- * UI Intermediate Representation Schema
3
- *
4
- * Core schema definitions for declarative UI generation.
5
- */
6
- /**
7
- * Schema version
8
- */
9
- export const UI_IR_VERSION = '1.0.0';
10
- /**
11
- * Validate UIRoot structure
12
- */
13
- export function validateUIRoot(root) {
14
- if (!root || typeof root !== 'object')
15
- return false;
16
- const r = root;
17
- if (typeof r.version !== 'string')
18
- return false;
19
- if (!Array.isArray(r.components))
20
- return false;
21
- if (!r.state || typeof r.state !== 'object')
22
- return false;
23
- if (!Array.isArray(r.actions))
24
- return false;
25
- return true;
26
- }
27
- /**
28
- * Create empty UI root
29
- */
30
- export function createEmptyRoot() {
31
- return {
32
- version: UI_IR_VERSION,
33
- components: [],
34
- state: {
35
- variables: [],
36
- },
37
- actions: [],
38
- };
39
- }
40
- /**
41
- * Create UI root from template
42
- */
43
- export function createRootFromTemplate(template) {
44
- return {
45
- version: UI_IR_VERSION,
46
- state: { variables: [] },
47
- actions: [],
48
- ...template,
49
- };
50
- }
51
- //# sourceMappingURL=ui-ir.js.map
@@ -1,101 +0,0 @@
1
- /**
2
- * A2R-IX API SDK
3
- *
4
- * Client for interacting with the A2R-IX API.
5
- */
6
- import type { UIRoot } from '../types';
7
- import type { JSONPatch } from '../state/patch';
8
- export interface IXCapsuleClientConfig {
9
- /** API base URL */
10
- baseUrl: string;
11
- /** Optional auth token */
12
- token?: string;
13
- /** Event callbacks */
14
- onEvent?: (event: IXCapsuleEvent) => void;
15
- /** Error handler */
16
- onError?: (error: Error) => void;
17
- }
18
- export interface IXCapsuleEvent {
19
- event_type: 'lifecycle' | 'action' | 'state-change' | 'error';
20
- capsule_id: string;
21
- lifecycle?: 'mount' | 'unmount' | 'update';
22
- action?: string;
23
- action_params?: Record<string, unknown>;
24
- state_update?: Record<string, unknown>;
25
- error?: string;
26
- }
27
- export interface CreateCapsuleRequest {
28
- ui: UIRoot;
29
- initial_state?: Record<string, unknown>;
30
- ttl_seconds?: number;
31
- }
32
- export interface CreateCapsuleResponse {
33
- capsule_id: string;
34
- status: string;
35
- }
36
- export interface CapsuleState {
37
- capsule_id: string;
38
- ui: UIRoot;
39
- state: Record<string, unknown>;
40
- created_at: string;
41
- updated_at: string;
42
- }
43
- export interface JsonRenderRequest {
44
- schema: Record<string, unknown>;
45
- initial_state?: Record<string, unknown>;
46
- ttl_seconds?: number;
47
- }
48
- export interface ActionRequest {
49
- action_id: string;
50
- params?: Record<string, unknown>;
51
- }
52
- /**
53
- * A2R-IX Capsule Client
54
- */
55
- export declare class IXCapsuleClient {
56
- private config;
57
- private eventSource;
58
- private activeCapsules;
59
- constructor(config: IXCapsuleClientConfig);
60
- /**
61
- * Create a new IX capsule
62
- */
63
- createCapsule(request: CreateCapsuleRequest): Promise<CreateCapsuleResponse>;
64
- /**
65
- * Create capsule from json-render format
66
- */
67
- createFromJsonRender(request: JsonRenderRequest): Promise<CreateCapsuleResponse>;
68
- /**
69
- * Get capsule state
70
- */
71
- getCapsule(capsuleId: string): Promise<CapsuleState>;
72
- /**
73
- * Apply JSON Patch to capsule state
74
- */
75
- applyPatch(capsuleId: string, patch: JSONPatch): Promise<void>;
76
- /**
77
- * Dispatch action to capsule
78
- */
79
- dispatchAction(capsuleId: string, action: ActionRequest): Promise<void>;
80
- /**
81
- * Delete capsule
82
- */
83
- deleteCapsule(capsuleId: string): Promise<void>;
84
- /**
85
- * Connect to event stream
86
- */
87
- private connectEventStream;
88
- /**
89
- * Disconnect event stream
90
- */
91
- private disconnectEventStream;
92
- /**
93
- * Cleanup all connections
94
- */
95
- dispose(): void;
96
- }
97
- /**
98
- * Create IX capsule client
99
- */
100
- export declare function createIXClient(config: IXCapsuleClientConfig): IXCapsuleClient;
101
- //# sourceMappingURL=api.d.ts.map
@@ -1,177 +0,0 @@
1
- /**
2
- * A2R-IX API SDK
3
- *
4
- * Client for interacting with the A2R-IX API.
5
- */
6
- /**
7
- * A2R-IX Capsule Client
8
- */
9
- export class IXCapsuleClient {
10
- config;
11
- eventSource = null;
12
- activeCapsules = new Set();
13
- constructor(config) {
14
- this.config = config;
15
- }
16
- /**
17
- * Create a new IX capsule
18
- */
19
- async createCapsule(request) {
20
- const response = await fetch(`${this.config.baseUrl}/ix/capsules`, {
21
- method: 'POST',
22
- headers: {
23
- 'Content-Type': 'application/json',
24
- ...(this.config.token && { 'Authorization': `Bearer ${this.config.token}` }),
25
- },
26
- body: JSON.stringify(request),
27
- });
28
- if (!response.ok) {
29
- throw new Error(`Failed to create capsule: ${response.statusText}`);
30
- }
31
- const result = await response.json();
32
- this.activeCapsules.add(result.capsule_id);
33
- // Start event stream
34
- this.connectEventStream(result.capsule_id);
35
- return result;
36
- }
37
- /**
38
- * Create capsule from json-render format
39
- */
40
- async createFromJsonRender(request) {
41
- const response = await fetch(`${this.config.baseUrl}/ix/capsules/json-render`, {
42
- method: 'POST',
43
- headers: {
44
- 'Content-Type': 'application/json',
45
- ...(this.config.token && { 'Authorization': `Bearer ${this.config.token}` }),
46
- },
47
- body: JSON.stringify(request),
48
- });
49
- if (!response.ok) {
50
- throw new Error(`Failed to create capsule: ${response.statusText}`);
51
- }
52
- const result = await response.json();
53
- this.activeCapsules.add(result.capsule_id);
54
- // Start event stream
55
- this.connectEventStream(result.capsule_id);
56
- return result;
57
- }
58
- /**
59
- * Get capsule state
60
- */
61
- async getCapsule(capsuleId) {
62
- const response = await fetch(`${this.config.baseUrl}/ix/capsules/${capsuleId}`, {
63
- headers: {
64
- ...(this.config.token && { 'Authorization': `Bearer ${this.config.token}` }),
65
- },
66
- });
67
- if (!response.ok) {
68
- throw new Error(`Failed to get capsule: ${response.statusText}`);
69
- }
70
- return response.json();
71
- }
72
- /**
73
- * Apply JSON Patch to capsule state
74
- */
75
- async applyPatch(capsuleId, patch) {
76
- const response = await fetch(`${this.config.baseUrl}/ix/capsules/${capsuleId}/patch`, {
77
- method: 'POST',
78
- headers: {
79
- 'Content-Type': 'application/json',
80
- ...(this.config.token && { 'Authorization': `Bearer ${this.config.token}` }),
81
- },
82
- body: JSON.stringify({ operations: patch }),
83
- });
84
- if (!response.ok) {
85
- throw new Error(`Failed to apply patch: ${response.statusText}`);
86
- }
87
- }
88
- /**
89
- * Dispatch action to capsule
90
- */
91
- async dispatchAction(capsuleId, action) {
92
- const response = await fetch(`${this.config.baseUrl}/ix/capsules/${capsuleId}/action`, {
93
- method: 'POST',
94
- headers: {
95
- 'Content-Type': 'application/json',
96
- ...(this.config.token && { 'Authorization': `Bearer ${this.config.token}` }),
97
- },
98
- body: JSON.stringify(action),
99
- });
100
- if (!response.ok) {
101
- throw new Error(`Failed to dispatch action: ${response.statusText}`);
102
- }
103
- }
104
- /**
105
- * Delete capsule
106
- */
107
- async deleteCapsule(capsuleId) {
108
- const response = await fetch(`${this.config.baseUrl}/ix/capsules/${capsuleId}`, {
109
- method: 'DELETE',
110
- headers: {
111
- ...(this.config.token && { 'Authorization': `Bearer ${this.config.token}` }),
112
- },
113
- });
114
- if (!response.ok) {
115
- throw new Error(`Failed to delete capsule: ${response.statusText}`);
116
- }
117
- this.activeCapsules.delete(capsuleId);
118
- this.disconnectEventStream(capsuleId);
119
- }
120
- /**
121
- * Connect to event stream
122
- */
123
- connectEventStream(capsuleId) {
124
- if (typeof EventSource === 'undefined') {
125
- console.warn('EventSource not available');
126
- return;
127
- }
128
- const url = new URL(`${this.config.baseUrl}/ix/capsules/${capsuleId}/stream`);
129
- if (this.config.token) {
130
- url.searchParams.set('token', this.config.token);
131
- }
132
- const es = new EventSource(url.toString());
133
- this.eventSource = es;
134
- es.onmessage = (event) => {
135
- try {
136
- const data = JSON.parse(event.data);
137
- this.config.onEvent?.(data);
138
- // Handle unmount - cleanup
139
- if (data.event_type === 'lifecycle' && data.lifecycle === 'unmount') {
140
- this.activeCapsules.delete(capsuleId);
141
- this.disconnectEventStream(capsuleId);
142
- }
143
- }
144
- catch (error) {
145
- this.config.onError?.(error);
146
- }
147
- };
148
- es.onerror = (error) => {
149
- this.config.onError?.(new Error('EventSource error'));
150
- };
151
- }
152
- /**
153
- * Disconnect event stream
154
- */
155
- disconnectEventStream(capsuleId) {
156
- if (this.eventSource) {
157
- this.eventSource.close();
158
- this.eventSource = null;
159
- }
160
- }
161
- /**
162
- * Cleanup all connections
163
- */
164
- dispose() {
165
- this.activeCapsules.forEach((id) => {
166
- this.disconnectEventStream(id);
167
- });
168
- this.activeCapsules.clear();
169
- }
170
- }
171
- /**
172
- * Create IX capsule client
173
- */
174
- export function createIXClient(config) {
175
- return new IXCapsuleClient(config);
176
- }
177
- //# sourceMappingURL=api.js.map
@@ -1,9 +0,0 @@
1
- /**
2
- * A2R-IX SDK
3
- *
4
- * Client SDK for A2R-IX integration.
5
- */
6
- export { IXCapsuleClient, createIXClient, type IXCapsuleClientConfig, type IXCapsuleEvent, type CreateCapsuleRequest, type CreateCapsuleResponse, type CapsuleState, type JsonRenderRequest, type ActionRequest, } from './api';
7
- export { IXProvider, IXRenderer, useIX, useIXState, useIXAction, } from './react';
8
- export type { UIRoot, JSONPatch } from '../types';
9
- //# sourceMappingURL=index.d.ts.map
@@ -1,10 +0,0 @@
1
- /**
2
- * A2R-IX SDK
3
- *
4
- * Client SDK for A2R-IX integration.
5
- */
6
- // API Client
7
- export { IXCapsuleClient, createIXClient, } from './api';
8
- // React Integration
9
- export { IXProvider, IXRenderer, useIX, useIXState, useIXAction, } from './react';
10
- //# sourceMappingURL=index.js.map