tywrap 0.2.0 → 0.3.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 (163) hide show
  1. package/README.md +65 -31
  2. package/dist/cli.js +49 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/config/index.d.ts +11 -7
  5. package/dist/config/index.d.ts.map +1 -1
  6. package/dist/config/index.js +43 -7
  7. package/dist/config/index.js.map +1 -1
  8. package/dist/core/analyzer.d.ts +1 -0
  9. package/dist/core/analyzer.d.ts.map +1 -1
  10. package/dist/core/analyzer.js +47 -12
  11. package/dist/core/analyzer.js.map +1 -1
  12. package/dist/core/annotation-parser.d.ts +8 -0
  13. package/dist/core/annotation-parser.d.ts.map +1 -0
  14. package/dist/core/annotation-parser.js +409 -0
  15. package/dist/core/annotation-parser.js.map +1 -0
  16. package/dist/core/discovery.d.ts +1 -0
  17. package/dist/core/discovery.d.ts.map +1 -1
  18. package/dist/core/discovery.js +9 -9
  19. package/dist/core/discovery.js.map +1 -1
  20. package/dist/core/generator.d.ts +9 -1
  21. package/dist/core/generator.d.ts.map +1 -1
  22. package/dist/core/generator.js +738 -104
  23. package/dist/core/generator.js.map +1 -1
  24. package/dist/core/mapper.d.ts +9 -7
  25. package/dist/core/mapper.d.ts.map +1 -1
  26. package/dist/core/mapper.js +129 -44
  27. package/dist/core/mapper.js.map +1 -1
  28. package/dist/index.d.ts +23 -7
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +23 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/runtime/base.d.ts +17 -7
  33. package/dist/runtime/base.d.ts.map +1 -1
  34. package/dist/runtime/base.js +18 -1
  35. package/dist/runtime/base.js.map +1 -1
  36. package/dist/runtime/bounded-context.d.ts +252 -0
  37. package/dist/runtime/bounded-context.d.ts.map +1 -0
  38. package/dist/runtime/bounded-context.js +454 -0
  39. package/dist/runtime/bounded-context.js.map +1 -0
  40. package/dist/runtime/bridge-core.d.ts +1 -0
  41. package/dist/runtime/bridge-core.d.ts.map +1 -1
  42. package/dist/runtime/bridge-core.js +52 -17
  43. package/dist/runtime/bridge-core.js.map +1 -1
  44. package/dist/runtime/bridge-protocol.d.ts +184 -0
  45. package/dist/runtime/bridge-protocol.d.ts.map +1 -0
  46. package/dist/runtime/bridge-protocol.js +344 -0
  47. package/dist/runtime/bridge-protocol.js.map +1 -0
  48. package/dist/runtime/disposable.d.ts +40 -0
  49. package/dist/runtime/disposable.d.ts.map +1 -0
  50. package/dist/runtime/disposable.js +49 -0
  51. package/dist/runtime/disposable.js.map +1 -0
  52. package/dist/runtime/errors.d.ts +10 -0
  53. package/dist/runtime/errors.d.ts.map +1 -1
  54. package/dist/runtime/errors.js +9 -0
  55. package/dist/runtime/errors.js.map +1 -1
  56. package/dist/runtime/http-io.d.ts +91 -0
  57. package/dist/runtime/http-io.d.ts.map +1 -0
  58. package/dist/runtime/http-io.js +195 -0
  59. package/dist/runtime/http-io.js.map +1 -0
  60. package/dist/runtime/http.d.ts +48 -13
  61. package/dist/runtime/http.d.ts.map +1 -1
  62. package/dist/runtime/http.js +60 -73
  63. package/dist/runtime/http.js.map +1 -1
  64. package/dist/runtime/node.d.ts +97 -130
  65. package/dist/runtime/node.d.ts.map +1 -1
  66. package/dist/runtime/node.js +392 -521
  67. package/dist/runtime/node.js.map +1 -1
  68. package/dist/runtime/optimized-node.d.ts +1 -1
  69. package/dist/runtime/optimized-node.d.ts.map +1 -1
  70. package/dist/runtime/optimized-node.js +1 -1
  71. package/dist/runtime/optimized-node.js.map +1 -1
  72. package/dist/runtime/pooled-transport.d.ts +135 -0
  73. package/dist/runtime/pooled-transport.d.ts.map +1 -0
  74. package/dist/runtime/pooled-transport.js +177 -0
  75. package/dist/runtime/pooled-transport.js.map +1 -0
  76. package/dist/runtime/process-io.d.ts +209 -0
  77. package/dist/runtime/process-io.d.ts.map +1 -0
  78. package/dist/runtime/process-io.js +729 -0
  79. package/dist/runtime/process-io.js.map +1 -0
  80. package/dist/runtime/pyodide-io.d.ts +154 -0
  81. package/dist/runtime/pyodide-io.d.ts.map +1 -0
  82. package/dist/runtime/pyodide-io.js +459 -0
  83. package/dist/runtime/pyodide-io.js.map +1 -0
  84. package/dist/runtime/pyodide.d.ts +51 -19
  85. package/dist/runtime/pyodide.d.ts.map +1 -1
  86. package/dist/runtime/pyodide.js +57 -186
  87. package/dist/runtime/pyodide.js.map +1 -1
  88. package/dist/runtime/safe-codec.d.ts +103 -0
  89. package/dist/runtime/safe-codec.d.ts.map +1 -0
  90. package/dist/runtime/safe-codec.js +519 -0
  91. package/dist/runtime/safe-codec.js.map +1 -0
  92. package/dist/runtime/transport.d.ts +191 -0
  93. package/dist/runtime/transport.d.ts.map +1 -0
  94. package/dist/runtime/transport.js +86 -0
  95. package/dist/runtime/transport.js.map +1 -0
  96. package/dist/runtime/validators.d.ts +120 -0
  97. package/dist/runtime/validators.d.ts.map +1 -0
  98. package/dist/runtime/validators.js +229 -0
  99. package/dist/runtime/validators.js.map +1 -0
  100. package/dist/runtime/worker-pool.d.ts +208 -0
  101. package/dist/runtime/worker-pool.d.ts.map +1 -0
  102. package/dist/runtime/worker-pool.js +419 -0
  103. package/dist/runtime/worker-pool.js.map +1 -0
  104. package/dist/types/index.d.ts +51 -1
  105. package/dist/types/index.d.ts.map +1 -1
  106. package/dist/tywrap.d.ts.map +1 -1
  107. package/dist/tywrap.js +227 -328
  108. package/dist/tywrap.js.map +1 -1
  109. package/dist/utils/cache.d.ts.map +1 -1
  110. package/dist/utils/cache.js +53 -5
  111. package/dist/utils/cache.js.map +1 -1
  112. package/dist/utils/codec.d.ts.map +1 -1
  113. package/dist/utils/codec.js +114 -1
  114. package/dist/utils/codec.js.map +1 -1
  115. package/dist/utils/ir-cache.d.ts +28 -0
  116. package/dist/utils/ir-cache.d.ts.map +1 -0
  117. package/dist/utils/ir-cache.js +29 -0
  118. package/dist/utils/ir-cache.js.map +1 -0
  119. package/dist/utils/parallel-processor.d.ts +1 -1
  120. package/dist/utils/parallel-processor.d.ts.map +1 -1
  121. package/dist/utils/parallel-processor.js +111 -40
  122. package/dist/utils/parallel-processor.js.map +1 -1
  123. package/dist/utils/runtime.d.ts +5 -1
  124. package/dist/utils/runtime.d.ts.map +1 -1
  125. package/dist/utils/runtime.js +112 -18
  126. package/dist/utils/runtime.js.map +1 -1
  127. package/package.json +40 -18
  128. package/runtime/python_bridge.py +108 -15
  129. package/runtime/safe_codec.py +344 -0
  130. package/src/cli.ts +61 -2
  131. package/src/config/index.ts +63 -17
  132. package/src/core/analyzer.ts +52 -15
  133. package/src/core/annotation-parser.ts +500 -0
  134. package/src/core/discovery.ts +26 -12
  135. package/src/core/generator.ts +956 -116
  136. package/src/core/mapper.ts +158 -51
  137. package/src/index.ts +78 -6
  138. package/src/runtime/base.ts +18 -26
  139. package/src/runtime/bounded-context.ts +608 -0
  140. package/src/runtime/bridge-core.ts +58 -18
  141. package/src/runtime/bridge-protocol.ts +483 -0
  142. package/src/runtime/disposable.ts +65 -0
  143. package/src/runtime/errors.ts +14 -0
  144. package/src/runtime/http-io.ts +245 -0
  145. package/src/runtime/http.ts +76 -115
  146. package/src/runtime/node.ts +563 -676
  147. package/src/runtime/optimized-node.ts +4 -1
  148. package/src/runtime/pooled-transport.ts +263 -0
  149. package/src/runtime/process-io.ts +930 -0
  150. package/src/runtime/pyodide-io.ts +551 -0
  151. package/src/runtime/pyodide.ts +75 -215
  152. package/src/runtime/safe-codec.ts +651 -0
  153. package/src/runtime/transport.ts +278 -0
  154. package/src/runtime/validators.ts +252 -0
  155. package/src/runtime/worker-pool.ts +559 -0
  156. package/src/types/global.d.ts +11 -1
  157. package/src/types/index.ts +63 -0
  158. package/src/tywrap.ts +279 -358
  159. package/src/utils/cache.ts +59 -5
  160. package/src/utils/codec.ts +122 -1
  161. package/src/utils/ir-cache.ts +51 -0
  162. package/src/utils/parallel-processor.ts +119 -43
  163. package/src/utils/runtime.ts +129 -18
@@ -9,7 +9,13 @@ import type {
9
9
  UnionType as PyUnionType,
10
10
  OptionalType as PyOptionalType,
11
11
  GenericType as PyGenericType,
12
+ CallableType as PyCallableType,
12
13
  TypeVarType as PyTypeVarType,
14
+ ParamSpecType as PyParamSpecType,
15
+ ParamSpecArgsType as PyParamSpecArgsType,
16
+ ParamSpecKwargsType as PyParamSpecKwargsType,
17
+ TypeVarTupleType as PyTypeVarTupleType,
18
+ UnpackType as PyUnpackType,
13
19
  FinalType as PyFinalType,
14
20
  ClassVarType as PyClassVarType,
15
21
  TypescriptType,
@@ -62,6 +68,16 @@ export class TypeMapper {
62
68
  return this.mapPythonType(pythonType.base, context);
63
69
  case 'typevar':
64
70
  return this.mapTypeVarType(pythonType, context);
71
+ case 'paramspec':
72
+ return this.mapParamSpecType(pythonType);
73
+ case 'paramspec_args':
74
+ return this.mapParamSpecArgsType(pythonType);
75
+ case 'paramspec_kwargs':
76
+ return this.mapParamSpecKwargsType();
77
+ case 'typevartuple':
78
+ return this.mapTypeVarTupleType(pythonType);
79
+ case 'unpack':
80
+ return this.mapUnpackType(pythonType, context);
65
81
  case 'final':
66
82
  return this.mapFinalType(pythonType, context);
67
83
  case 'classvar':
@@ -103,6 +119,17 @@ export class TypeMapper {
103
119
 
104
120
  // tuple[T1, T2, ...] -> [T1, T2, ...] (exact arity)
105
121
  if (type.name === 'tuple') {
122
+ if (
123
+ type.itemTypes.length === 2 &&
124
+ type.itemTypes[1]?.kind === 'custom' &&
125
+ (type.itemTypes[1] as { kind: 'custom'; name: string }).name === '...'
126
+ ) {
127
+ return {
128
+ kind: 'array',
129
+ elementType: this.mapPythonType(type.itemTypes[0] ?? { kind: 'primitive', name: 'None' }),
130
+ } satisfies TSArrayType;
131
+ }
132
+
106
133
  const elementTypes: TypescriptType[] =
107
134
  type.itemTypes.length > 0
108
135
  ? type.itemTypes.map(t => this.mapPythonType(t))
@@ -167,11 +194,17 @@ export class TypeMapper {
167
194
  };
168
195
  }
169
196
 
170
- mapGenericType(type: PyGenericType, context: MappingContext = 'value'): TSGenericType {
197
+ mapGenericType(type: PyGenericType, context: MappingContext = 'value'): TypescriptType {
198
+ const normalized = this.normalizeCustomType({ name: type.name, module: type.module });
199
+ const typeArgs = type.typeArgs.map(t => this.mapPythonType(t, context));
200
+ const knownGenericType = this.mapKnownGenericType(normalized, typeArgs);
201
+ if (knownGenericType) {
202
+ return knownGenericType;
203
+ }
171
204
  return {
172
205
  kind: 'generic',
173
- name: type.name,
174
- typeArgs: type.typeArgs.map(t => this.mapPythonType(t, context)),
206
+ name: normalized.name,
207
+ typeArgs,
175
208
  };
176
209
  }
177
210
 
@@ -226,39 +259,9 @@ export class TypeMapper {
226
259
  };
227
260
  }
228
261
 
229
- // Async types
230
- if (name === 'Awaitable' || fullName === 'typing.Awaitable') {
231
- return {
232
- kind: 'generic',
233
- name: 'Promise',
234
- typeArgs: [{ kind: 'primitive', name: 'unknown' }],
235
- };
236
- }
237
- if (name === 'Coroutine' || fullName === 'typing.Coroutine') {
238
- return {
239
- kind: 'generic',
240
- name: 'Promise',
241
- typeArgs: [{ kind: 'primitive', name: 'unknown' }],
242
- };
243
- }
244
-
245
- // Collection types that should be generics
246
- if (name === 'Sequence' || fullName === 'typing.Sequence') {
247
- return {
248
- kind: 'generic',
249
- name: 'Array',
250
- typeArgs: [{ kind: 'primitive', name: 'unknown' }],
251
- };
252
- }
253
- if (name === 'Mapping' || fullName === 'typing.Mapping') {
254
- return {
255
- kind: 'object',
256
- properties: [],
257
- indexSignature: {
258
- keyType: { kind: 'primitive', name: 'string' },
259
- valueType: { kind: 'primitive', name: 'unknown' },
260
- },
261
- };
262
+ const knownGenericType = this.mapKnownGenericType(this.normalizeCustomType(type));
263
+ if (knownGenericType) {
264
+ return knownGenericType;
262
265
  }
263
266
 
264
267
  const presetType = this.mapPresetType(type);
@@ -266,16 +269,19 @@ export class TypeMapper {
266
269
  return presetType;
267
270
  }
268
271
 
272
+ // The generator does not synthesize TS generic parameters from Python typing
273
+ // helpers, so unsupported placeholders must degrade to unknown instead of
274
+ // leaking undeclared identifiers like T, P, or Ts into emitted code.
275
+ if (type.module === 'typing' || type.module === 'typing_extensions') {
276
+ return { kind: 'primitive', name: 'unknown' };
277
+ }
278
+
269
279
  // Forward references and user types
270
280
  const normalized = this.normalizeCustomType(type);
271
281
  return { kind: 'custom', name: normalized.name, module: normalized.module };
272
282
  }
273
283
 
274
- mapCallableType(type: {
275
- kind: 'callable';
276
- parameters: PythonType[];
277
- returnType: PythonType;
278
- }): TSFunctionType {
284
+ mapCallableType(type: PyCallableType): TSFunctionType {
279
285
  // Support Callable[[...], R] → (...args: unknown[]) => R
280
286
  const onlyEllipsis =
281
287
  type.parameters.length === 1 &&
@@ -285,21 +291,30 @@ export class TypeMapper {
285
291
  return {
286
292
  kind: 'function',
287
293
  isAsync: false,
288
- parameters: onlyEllipsis
294
+ parameters: type.parameterSpec
289
295
  ? ([
290
296
  {
291
297
  name: 'args',
292
- type: { kind: 'array', elementType: { kind: 'primitive', name: 'unknown' } },
298
+ type: this.mapParamSpecType(type.parameterSpec),
293
299
  optional: false,
294
300
  rest: true,
295
301
  },
296
302
  ] as const satisfies TSFunctionType['parameters'])
297
- : type.parameters.map((p, i) => ({
298
- name: `arg${i}`,
299
- type: this.mapPythonType(p, 'value'),
300
- optional: false,
301
- rest: false,
302
- })),
303
+ : onlyEllipsis
304
+ ? ([
305
+ {
306
+ name: 'args',
307
+ type: { kind: 'array', elementType: { kind: 'primitive', name: 'unknown' } },
308
+ optional: false,
309
+ rest: true,
310
+ },
311
+ ] as const satisfies TSFunctionType['parameters'])
312
+ : type.parameters.map((p, i) => ({
313
+ name: `arg${i}`,
314
+ type: this.mapPythonType(p, 'value'),
315
+ optional: false,
316
+ rest: false,
317
+ })),
303
318
  returnType: this.mapPythonType(type.returnType, 'return'),
304
319
  } satisfies TSFunctionType;
305
320
  }
@@ -312,8 +327,15 @@ export class TypeMapper {
312
327
  }
313
328
 
314
329
  mapTypeVarType(type: PyTypeVarType, _context: MappingContext = 'value'): TSCustomType {
315
- // TypeVar maps to a generic type parameter in TypeScript
316
- // Bounds and constraints are not directly expressible in TypeScript type system
330
+ // TypeVar maps to a generic type parameter in TypeScript.
331
+ return {
332
+ kind: 'custom',
333
+ name: type.name,
334
+ module: 'typing',
335
+ };
336
+ }
337
+
338
+ mapParamSpecType(type: PyParamSpecType): TSCustomType {
317
339
  return {
318
340
  kind: 'custom',
319
341
  name: type.name,
@@ -321,6 +343,32 @@ export class TypeMapper {
321
343
  };
322
344
  }
323
345
 
346
+ mapParamSpecArgsType(_type: PyParamSpecArgsType): TSArrayType {
347
+ return {
348
+ kind: 'array',
349
+ elementType: { kind: 'primitive', name: 'unknown' },
350
+ };
351
+ }
352
+
353
+ mapParamSpecKwargsType(): TSObjectType {
354
+ return {
355
+ kind: 'object',
356
+ properties: [],
357
+ indexSignature: {
358
+ keyType: { kind: 'primitive', name: 'string' },
359
+ valueType: { kind: 'primitive', name: 'unknown' },
360
+ },
361
+ };
362
+ }
363
+
364
+ mapTypeVarTupleType(_type: PyTypeVarTupleType): TSPrimitiveType {
365
+ return { kind: 'primitive', name: 'unknown' };
366
+ }
367
+
368
+ mapUnpackType(_type: PyUnpackType, _context: MappingContext = 'value'): TSPrimitiveType {
369
+ return { kind: 'primitive', name: 'unknown' };
370
+ }
371
+
324
372
  mapFinalType(type: PyFinalType, context: MappingContext = 'value'): TypescriptType {
325
373
  // Final[T] maps to T in TypeScript (no direct Final equivalent)
326
374
  // The Final qualifier is more of a static analysis hint
@@ -333,6 +381,58 @@ export class TypeMapper {
333
381
  return this.mapPythonType(type.type, context);
334
382
  }
335
383
 
384
+ private mapKnownGenericType(
385
+ type: { name: string; module?: string },
386
+ typeArgs: TypescriptType[] = []
387
+ ): TypescriptType | undefined {
388
+ const unknownType: TSPrimitiveType = { kind: 'primitive', name: 'unknown' };
389
+ const isKnownTypingModule =
390
+ type.module === undefined ||
391
+ type.module === 'typing' ||
392
+ type.module === 'typing_extensions' ||
393
+ type.module === 'collections.abc';
394
+
395
+ if (!isKnownTypingModule) {
396
+ return undefined;
397
+ }
398
+
399
+ if (type.name === 'Awaitable') {
400
+ return {
401
+ kind: 'generic',
402
+ name: 'Promise',
403
+ typeArgs: [typeArgs[0] ?? unknownType],
404
+ } satisfies TSGenericType;
405
+ }
406
+
407
+ if (type.name === 'Coroutine') {
408
+ return {
409
+ kind: 'generic',
410
+ name: 'Promise',
411
+ typeArgs: [typeArgs[typeArgs.length - 1] ?? unknownType],
412
+ } satisfies TSGenericType;
413
+ }
414
+
415
+ if (type.name === 'Sequence') {
416
+ return {
417
+ kind: 'array',
418
+ elementType: typeArgs[0] ?? unknownType,
419
+ } satisfies TSArrayType;
420
+ }
421
+
422
+ if (type.name === 'Mapping') {
423
+ return {
424
+ kind: 'object',
425
+ properties: [],
426
+ indexSignature: {
427
+ keyType: this.asIndexKeyType(typeArgs[0] ?? unknownType),
428
+ valueType: typeArgs[1] ?? unknownType,
429
+ },
430
+ } satisfies TSObjectType;
431
+ }
432
+
433
+ return undefined;
434
+ }
435
+
336
436
  private asIndexKeyType(key: TypescriptType): TSPrimitiveType {
337
437
  if (key.kind === 'primitive' && (key.name === 'string' || key.name === 'number')) {
338
438
  return key;
@@ -449,6 +549,13 @@ export class TypeMapper {
449
549
  }
450
550
  }
451
551
 
552
+ if (this.hasPreset('pydantic')) {
553
+ const allowModule = !moduleName || moduleName.startsWith('pydantic');
554
+ if (allowModule && name === 'BaseModel') {
555
+ return recordObject;
556
+ }
557
+ }
558
+
452
559
  if (this.hasPreset('scipy')) {
453
560
  const allowModule = !moduleName || moduleName.startsWith('scipy');
454
561
  if (allowModule) {
package/src/index.ts CHANGED
@@ -7,11 +7,69 @@
7
7
 
8
8
  import { tywrap } from './tywrap.js';
9
9
 
10
- export type { TywrapConfig } from './config/index.js';
10
+ export type { TywrapConfig, ResolvedTywrapConfig } from './config/index.js';
11
11
  export { defineConfig, resolveConfig } from './config/index.js';
12
+ // BoundedContext - unified abstraction for cross-boundary concerns
13
+ export {
14
+ BoundedContext,
15
+ type ContextState,
16
+ type ExecuteOptions,
17
+ } from './runtime/bounded-context.js';
18
+ // BridgeProtocol - unified BoundedContext + SafeCodec + Transport
19
+ export { BridgeProtocol, type BridgeProtocolOptions } from './runtime/bridge-protocol.js';
20
+ // SafeCodec - validation and serialization for JS<->Python boundary
21
+ export { SafeCodec, type CodecOptions } from './runtime/safe-codec.js';
22
+ // Transport - abstract I/O channel interface
23
+ export type {
24
+ Transport,
25
+ TransportOptions,
26
+ ProtocolMessage,
27
+ ProtocolResponse,
28
+ } from './runtime/transport.js';
29
+ export {
30
+ PROTOCOL_ID,
31
+ isTransport,
32
+ isProtocolMessage,
33
+ isProtocolResponse,
34
+ } from './runtime/transport.js';
35
+ // Transport implementations
36
+ export { ProcessIO, type ProcessIOOptions } from './runtime/process-io.js';
37
+ export { HttpIO, type HttpIOOptions } from './runtime/http-io.js';
38
+ export { PyodideIO, type PyodideIOOptions } from './runtime/pyodide-io.js';
39
+ // WorkerPool - concurrent transport management
40
+ export { WorkerPool, type WorkerPoolOptions, type PooledWorker } from './runtime/worker-pool.js';
41
+ // PooledTransport - Transport adapter that wraps WorkerPool
42
+ export { PooledTransport, type PooledTransportOptions } from './runtime/pooled-transport.js';
43
+ export type { Disposable } from './runtime/disposable.js';
44
+ export { isDisposable, safeDispose, disposeAll } from './runtime/disposable.js';
45
+ export {
46
+ ValidationError,
47
+ isFiniteNumber,
48
+ isPositiveNumber,
49
+ isNonNegativeNumber,
50
+ isNonEmptyString,
51
+ isPlainObject,
52
+ assertFiniteNumber,
53
+ assertPositive,
54
+ assertNonNegative,
55
+ assertString,
56
+ assertNonEmptyString,
57
+ assertArray,
58
+ assertObject,
59
+ containsSpecialFloat,
60
+ assertNoSpecialFloats,
61
+ sanitizeForFilename,
62
+ containsPathTraversal,
63
+ } from './runtime/validators.js';
64
+
65
+ /**
66
+ * @deprecated Use BoundedContext instead. RuntimeBridge will be removed in the next major version.
67
+ */
12
68
  export { RuntimeBridge } from './runtime/base.js';
69
+
13
70
  export {
14
71
  BridgeError,
72
+ BridgeCodecError,
15
73
  BridgeProtocolError,
16
74
  BridgeTimeoutError,
17
75
  BridgeDisposedError,
@@ -19,23 +77,37 @@ export {
19
77
  } from './runtime/errors.js';
20
78
  export { getRuntimeBridge, setRuntimeBridge, clearRuntimeBridge } from './runtime/index.js';
21
79
 
22
- // Runtime-specific exports
23
- export { NodeBridge } from './runtime/node.js';
24
- export { PyodideBridge } from './runtime/pyodide.js';
25
- export { HttpBridge } from './runtime/http.js';
80
+ // Runtime-specific exports (Bridges using new BridgeProtocol architecture)
81
+ export { NodeBridge, type NodeBridgeOptions } from './runtime/node.js';
82
+ export { PyodideBridge, type PyodideBridgeOptions } from './runtime/pyodide.js';
83
+ export { HttpBridge, type HttpBridgeOptions } from './runtime/http.js';
26
84
 
27
85
  // Core types
28
86
  export type {
29
87
  PythonModule,
30
88
  PythonFunction,
31
89
  PythonClass,
90
+ PythonTypeAlias,
32
91
  PythonType,
92
+ PythonGenericParameter,
93
+ PythonGenericParameterKind,
33
94
  PrimitiveType,
34
95
  CollectionType,
35
96
  UnionType,
36
97
  OptionalType,
37
98
  CustomType,
38
99
  GenericType,
100
+ CallableType,
101
+ LiteralType,
102
+ AnnotatedType,
103
+ TypeVarType,
104
+ ParamSpecType,
105
+ ParamSpecArgsType,
106
+ ParamSpecKwargsType,
107
+ TypeVarTupleType,
108
+ UnpackType,
109
+ FinalType,
110
+ ClassVarType,
39
111
  Parameter,
40
112
  Property,
41
113
  PythonImport,
@@ -75,7 +147,7 @@ export {
75
147
  } from './utils/codec.js';
76
148
 
77
149
  // Version info
78
- export const VERSION = '0.2.0';
150
+ export const VERSION = '0.3.0';
79
151
 
80
152
  /**
81
153
  * Quick setup function for getting started
@@ -1,32 +1,24 @@
1
1
  /**
2
2
  * Base runtime bridge
3
+ *
4
+ * @deprecated Use BoundedContext instead. RuntimeBridge will be removed in the next major version.
3
5
  */
4
6
 
5
- import type { RuntimeExecution } from '../types/index.js';
7
+ import { BoundedContext } from './bounded-context.js';
6
8
 
7
- export abstract class RuntimeBridge implements RuntimeExecution {
8
- abstract call<T = unknown>(
9
- module: string,
10
- functionName: string,
11
- args: unknown[],
12
- kwargs?: Record<string, unknown>
13
- ): Promise<T>;
14
-
15
- abstract instantiate<T = unknown>(
16
- module: string,
17
- className: string,
18
- args: unknown[],
19
- kwargs?: Record<string, unknown>
20
- ): Promise<T>;
21
-
22
- abstract callMethod<T = unknown>(
23
- handle: string,
24
- methodName: string,
25
- args: unknown[],
26
- kwargs?: Record<string, unknown>
27
- ): Promise<T>;
28
-
29
- abstract disposeInstance(handle: string): Promise<void>;
9
+ /**
10
+ * @deprecated Use BoundedContext instead. RuntimeBridge will be removed in the next major version.
11
+ *
12
+ * All bridges now extend BoundedContext which provides:
13
+ * - Lifecycle management (init/dispose state machine)
14
+ * - Validation helpers
15
+ * - Error classification
16
+ * - Bounded execution (timeout, retry)
17
+ * - Resource ownership tracking
18
+ *
19
+ * @see BoundedContext
20
+ */
21
+ export abstract class RuntimeBridge extends BoundedContext {}
30
22
 
31
- abstract dispose(): Promise<void>;
32
- }
23
+ // Re-export BoundedContext for backwards compatibility
24
+ export { BoundedContext };