@syntropika/tembra-sdk 0.2.2 → 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 (241) hide show
  1. package/README.md +43 -17
  2. package/dist/authoring/types.d.ts +64 -3
  3. package/dist/authoring/wit.d.ts +6 -0
  4. package/dist/bridge/commands.d.ts +1190 -0
  5. package/dist/bridge/identifiers.d.ts +2 -0
  6. package/dist/bridge/kernel.d.ts +18 -107
  7. package/dist/bridge/protocol.d.ts +3 -138
  8. package/dist/browser.d.ts +14 -1
  9. package/dist/browser.js +141 -3332
  10. package/dist/chunks/browser-b8jamxw2.js +3399 -0
  11. package/dist/chunks/execution-nsqc6nrt.js +1419 -0
  12. package/dist/chunks/index-01zk0xqx.js +160 -0
  13. package/dist/chunks/index-3fjdfdfd.js +152 -0
  14. package/dist/chunks/index-aaymjn7v.js +787 -0
  15. package/dist/chunks/index-c1w7z9hx.js +356 -0
  16. package/dist/chunks/index-h8t0n42q.js +738 -0
  17. package/dist/chunks/index-hfds9mzp.js +308 -0
  18. package/dist/chunks/index-kr4x67wt.js +177 -0
  19. package/dist/chunks/index-kr6bnh34.js +117 -0
  20. package/dist/chunks/index-kyt9dj0a.js +1421 -0
  21. package/dist/chunks/index-n1wxzc9w.js +830 -0
  22. package/dist/chunks/index-pvac426d.js +74 -0
  23. package/dist/chunks/index-smyds5ce.js +3234 -0
  24. package/dist/chunks/index-sse8aapb.js +121 -0
  25. package/dist/chunks/index-v6heph77.js +643 -0
  26. package/dist/chunks/index-xrdvnv37.js +3448 -0
  27. package/dist/chunks/index-za4mg94e.js +26 -0
  28. package/dist/chunks/index-zkqmnjj8.js +167 -0
  29. package/dist/coordinator.js +9 -500
  30. package/dist/error.d.ts +2 -0
  31. package/dist/errors.d.ts +3 -0
  32. package/dist/guest.d.ts +173 -0
  33. package/dist/guest.js +26 -0
  34. package/dist/host.d.ts +36 -30
  35. package/dist/host.js +37 -3310
  36. package/dist/http/bytes.d.ts +8 -0
  37. package/dist/http/events.d.ts +7 -0
  38. package/dist/http.d.ts +45 -0
  39. package/dist/http.js +291 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.js +49 -862
  42. package/dist/infrastructure/rpc/client.d.ts +2 -1
  43. package/dist/infrastructure/rpc/resources.d.ts +28 -0
  44. package/dist/interpreter/abi.d.ts +54 -0
  45. package/dist/interpreter/acquire.d.ts +18 -0
  46. package/dist/interpreter/browser-network.d.ts +52 -0
  47. package/dist/interpreter/browser-port.d.ts +55 -0
  48. package/dist/interpreter/browser.d.ts +79 -0
  49. package/dist/interpreter/cli.d.ts +5 -0
  50. package/dist/interpreter/codec.d.ts +42 -0
  51. package/dist/interpreter/component/execution.d.ts +42 -0
  52. package/dist/interpreter/component/host.d.ts +69 -0
  53. package/dist/interpreter/component/instance.d.ts +40 -0
  54. package/dist/interpreter/component/kernel.d.ts +120 -0
  55. package/dist/interpreter/component/names.d.ts +5 -0
  56. package/dist/interpreter/component/port.d.ts +85 -0
  57. package/dist/interpreter/component/prepared.d.ts +97 -0
  58. package/dist/interpreter/component/resources.d.ts +45 -0
  59. package/dist/interpreter/component/revision.d.ts +87 -0
  60. package/dist/interpreter/component/scope.d.ts +116 -0
  61. package/dist/interpreter/component/streams.d.ts +28 -0
  62. package/dist/interpreter/component/values.d.ts +79 -0
  63. package/dist/interpreter/component/wasi-filesystem.d.ts +21 -0
  64. package/dist/interpreter/component/wasi-host.d.ts +64 -0
  65. package/dist/interpreter/component/wasi-http.d.ts +33 -0
  66. package/dist/interpreter/component/wasi-sockets.d.ts +183 -0
  67. package/dist/interpreter/component/wasi.d.ts +41 -0
  68. package/dist/interpreter/core.d.ts +64 -0
  69. package/dist/interpreter/fetch-http-provider.d.ts +17 -0
  70. package/dist/interpreter/filesystem/contract.d.ts +85 -0
  71. package/dist/interpreter/filesystem/memory.d.ts +3 -0
  72. package/dist/interpreter/filesystem/opfs.d.ts +3 -0
  73. package/dist/interpreter/filesystem/scope.d.ts +35 -0
  74. package/dist/interpreter/filesystem.d.ts +8 -0
  75. package/dist/interpreter/gate.d.ts +6 -0
  76. package/dist/interpreter/host-protocol.d.ts +100 -0
  77. package/dist/interpreter/http-ingress-fetch.d.ts +7 -0
  78. package/dist/interpreter/http-ingress.d.ts +96 -0
  79. package/dist/interpreter/http-provider.d.ts +85 -0
  80. package/dist/interpreter/io.d.ts +20 -0
  81. package/dist/interpreter/mobile.d.ts +149 -0
  82. package/dist/interpreter/native-ingress.d.ts +95 -0
  83. package/dist/interpreter/node-port.d.ts +25 -0
  84. package/dist/interpreter/node.d.ts +36 -0
  85. package/dist/interpreter/revision.d.ts +64 -0
  86. package/dist/interpreter/scope.d.ts +89 -0
  87. package/dist/interpreter/socket-addresses.d.ts +50 -0
  88. package/dist/interpreter/socket-provider.d.ts +110 -0
  89. package/dist/interpreter/standard-cli.d.ts +34 -0
  90. package/dist/interpreter/standard-codec.d.ts +96 -0
  91. package/dist/interpreter/standard-filesystem.d.ts +47 -0
  92. package/dist/interpreter/standard-host.d.ts +71 -0
  93. package/dist/interpreter/standard-http-values.d.ts +159 -0
  94. package/dist/interpreter/standard-http.d.ts +9 -0
  95. package/dist/interpreter/standard-ingress.d.ts +63 -0
  96. package/dist/interpreter/standard-sockets.d.ts +177 -0
  97. package/dist/interpreter/standard-streams.d.ts +218 -0
  98. package/dist/interpreter/standard-system.d.ts +35 -0
  99. package/dist/interpreter/standard-utf8.d.ts +4 -0
  100. package/dist/interpreter/standard.d.ts +18 -0
  101. package/dist/interpreter/types.d.ts +152 -0
  102. package/dist/interpreter/wit-shape.d.ts +92 -0
  103. package/dist/manager.js +5 -332
  104. package/dist/msgpack.js +9 -615
  105. package/dist/node.d.ts +8 -1
  106. package/dist/node.js +248 -3321
  107. package/dist/rpc.js +196 -699
  108. package/dist/runtime/adapters.d.ts +120 -0
  109. package/dist/runtime/adapters.js +38 -0
  110. package/dist/runtime/calls.d.ts +7 -6
  111. package/dist/runtime/lifecycle.d.ts +3 -1
  112. package/dist/runtime/orbs.d.ts +5 -4
  113. package/dist/runtime/references.d.ts +27 -1
  114. package/dist/runtime/reload.d.ts +5 -3
  115. package/dist/runtime/scopes.d.ts +1 -1
  116. package/dist/runtime/signals.d.ts +4 -0
  117. package/dist/runtime/wit-client.d.ts +38 -0
  118. package/dist/telemetry.js +4 -25
  119. package/dist/tooling/build.d.ts +2 -2
  120. package/dist/tooling/client-resources.d.ts +23 -0
  121. package/dist/tooling/client.d.ts +10 -0
  122. package/dist/tooling/component-glue.d.ts +17 -0
  123. package/dist/tooling/component.d.ts +11 -0
  124. package/dist/tooling/index.d.ts +3 -1
  125. package/dist/tooling/index.js +1155 -102
  126. package/dist/tooling/resolver.d.ts +4 -4
  127. package/dist/tooling/typecheck.d.ts +2 -1
  128. package/dist/tooling/types.d.ts +27 -12
  129. package/dist/tooling/wit.d.ts +9 -0
  130. package/dist/wasi/wasi-clocks-types.d.ts +2 -0
  131. package/dist/wasi/wasi-http-client.d.ts +5 -0
  132. package/dist/wasi/wasi-http-types.d.ts +285 -0
  133. package/dist/wasi/wasi-sockets-ip-name-lookup.d.ts +23 -0
  134. package/dist/wasi/wasi-sockets-types.d.ts +146 -0
  135. package/package.json +62 -35
  136. package/src/authoring/declaration.ts +1 -1
  137. package/src/authoring/types.ts +53 -3
  138. package/src/authoring/wit.ts +15 -0
  139. package/src/bridge/commands.ts +1105 -0
  140. package/src/bridge/identifiers.ts +2 -0
  141. package/src/bridge/kernel.ts +56 -98
  142. package/src/bridge/protocol.ts +3 -142
  143. package/src/browser.ts +90 -6
  144. package/src/context-key.ts +4 -7
  145. package/src/error.ts +1 -1
  146. package/src/errors.ts +7 -0
  147. package/src/guest.ts +327 -0
  148. package/src/host.ts +128 -23
  149. package/src/http/bytes.ts +87 -0
  150. package/src/http/events.ts +34 -0
  151. package/src/http.ts +272 -0
  152. package/src/index.ts +3 -0
  153. package/src/infrastructure/rpc/client.ts +136 -17
  154. package/src/infrastructure/rpc/resources.ts +123 -0
  155. package/src/interpreter/abi.ts +69 -0
  156. package/src/interpreter/acquire.ts +58 -0
  157. package/src/interpreter/browser-network.ts +170 -0
  158. package/src/interpreter/browser-port.ts +425 -0
  159. package/src/interpreter/browser.ts +340 -0
  160. package/src/interpreter/cli.ts +30 -0
  161. package/src/interpreter/codec.ts +298 -0
  162. package/src/interpreter/component/execution.ts +264 -0
  163. package/src/interpreter/component/host.ts +409 -0
  164. package/src/interpreter/component/instance.ts +138 -0
  165. package/src/interpreter/component/kernel.ts +611 -0
  166. package/src/interpreter/component/names.ts +13 -0
  167. package/src/interpreter/component/port.ts +598 -0
  168. package/src/interpreter/component/prepared.ts +194 -0
  169. package/src/interpreter/component/resources.ts +345 -0
  170. package/src/interpreter/component/revision.ts +702 -0
  171. package/src/interpreter/component/scope.ts +447 -0
  172. package/src/interpreter/component/streams.ts +180 -0
  173. package/src/interpreter/component/values.ts +254 -0
  174. package/src/interpreter/component/wasi-filesystem.ts +472 -0
  175. package/src/interpreter/component/wasi-host.ts +197 -0
  176. package/src/interpreter/component/wasi-http.ts +939 -0
  177. package/src/interpreter/component/wasi-sockets.ts +958 -0
  178. package/src/interpreter/component/wasi.ts +238 -0
  179. package/src/interpreter/core.ts +386 -0
  180. package/src/interpreter/fetch-http-provider.ts +98 -0
  181. package/src/interpreter/filesystem/contract.ts +138 -0
  182. package/src/interpreter/filesystem/memory.ts +180 -0
  183. package/src/interpreter/filesystem/opfs.ts +294 -0
  184. package/src/interpreter/filesystem/scope.ts +390 -0
  185. package/src/interpreter/filesystem.ts +20 -0
  186. package/src/interpreter/gate.ts +55 -0
  187. package/src/interpreter/host-protocol.ts +242 -0
  188. package/src/interpreter/http-ingress-fetch.ts +133 -0
  189. package/src/interpreter/http-ingress.ts +203 -0
  190. package/src/interpreter/http-provider.ts +105 -0
  191. package/src/interpreter/io.ts +66 -0
  192. package/src/interpreter/mobile.ts +385 -0
  193. package/src/interpreter/native-ingress.ts +550 -0
  194. package/src/interpreter/node-port.ts +218 -0
  195. package/src/interpreter/node.ts +114 -0
  196. package/src/interpreter/revision.ts +450 -0
  197. package/src/interpreter/scope.ts +453 -0
  198. package/src/interpreter/socket-addresses.ts +246 -0
  199. package/src/interpreter/socket-provider.ts +126 -0
  200. package/src/interpreter/standard-cli.ts +184 -0
  201. package/src/interpreter/standard-codec.ts +403 -0
  202. package/src/interpreter/standard-filesystem.ts +545 -0
  203. package/src/interpreter/standard-host.ts +840 -0
  204. package/src/interpreter/standard-http-values.ts +624 -0
  205. package/src/interpreter/standard-http.ts +622 -0
  206. package/src/interpreter/standard-ingress.ts +344 -0
  207. package/src/interpreter/standard-sockets.ts +847 -0
  208. package/src/interpreter/standard-streams.ts +710 -0
  209. package/src/interpreter/standard-system.ts +182 -0
  210. package/src/interpreter/standard-utf8.ts +72 -0
  211. package/src/interpreter/standard.ts +283 -0
  212. package/src/interpreter/types.ts +163 -0
  213. package/src/interpreter/wit-shape.ts +175 -0
  214. package/src/node.ts +43 -14
  215. package/src/runtime/activities.ts +6 -6
  216. package/src/runtime/adapters.ts +314 -0
  217. package/src/runtime/calls.ts +213 -90
  218. package/src/runtime/context.ts +7 -7
  219. package/src/runtime/lifecycle.ts +36 -17
  220. package/src/runtime/orbs.ts +81 -39
  221. package/src/runtime/programs.ts +16 -8
  222. package/src/runtime/references.ts +128 -11
  223. package/src/runtime/reload.ts +71 -30
  224. package/src/runtime/resources.ts +2 -2
  225. package/src/runtime/scopes.ts +17 -17
  226. package/src/runtime/session.ts +3 -1
  227. package/src/runtime/signals.ts +31 -0
  228. package/src/runtime/wit-client.ts +228 -0
  229. package/src/tooling/build.ts +152 -54
  230. package/src/tooling/client-resources.ts +74 -0
  231. package/src/tooling/client.ts +531 -0
  232. package/src/tooling/component-glue.ts +288 -0
  233. package/src/tooling/component.ts +225 -0
  234. package/src/tooling/index.ts +3 -7
  235. package/src/tooling/resolver.ts +42 -25
  236. package/src/tooling/typecheck.ts +59 -4
  237. package/src/tooling/types.ts +27 -12
  238. package/src/tooling/wit.ts +188 -0
  239. package/dist/embedded.d.ts +0 -1
  240. package/dist/embedded.js +0 -1
  241. package/src/embedded.ts +0 -301
@@ -0,0 +1,120 @@
1
+ import type { Declaration } from "../authoring/declaration.ts";
2
+ import type { HostOptions, OrbDefinition, OrbInput, OrbArtifact, ServiceDefinition, HookDefinition } from "../authoring/types.ts";
3
+ import type { Environment, ReferenceRecord } from "./records.ts";
4
+ import type { Session } from "./session.ts";
5
+ import type { Handler } from "../authoring/types.ts";
6
+ import type { Context } from "./context.ts";
7
+ import type { Encoded } from "../interpreter/codec.ts";
8
+ /** Internal platform-neutral resource transport; implementations keep their issuer state private. */
9
+ export interface ResourceReceiver {
10
+ redeem(issuer: object, environment: number, expected: {
11
+ readonly interface: string;
12
+ readonly name: string;
13
+ }): object;
14
+ }
15
+ export interface ResourceLoan {
16
+ (): void;
17
+ readonly receiver: ResourceReceiver;
18
+ }
19
+ export interface ResourceCapability extends ResourceReceiver {
20
+ readonly kind: "resource";
21
+ readonly nominal: {
22
+ readonly interface: string;
23
+ readonly name: string;
24
+ };
25
+ readonly reference: ReferenceRecord;
26
+ anchor(session: Session, reference: ReferenceRecord): void;
27
+ lend(): ResourceLoan;
28
+ /** Move authority out of this wrapper; stale aliases keep no backend or claim. */
29
+ move(): ResourceCapability;
30
+ issuedBy(issuer: object): boolean;
31
+ /** Return an owner to its issuing component instance, without running its destructor. */
32
+ take(issuer: object, expected: ResourceCapability["nominal"]): object;
33
+ whenClosed(operation: () => void): void;
34
+ close(): void;
35
+ }
36
+ /** Internal byte-source authority; concrete browser state never enters shared runtime types. */
37
+ export interface ByteStreamCapability {
38
+ readonly kind: "bytes";
39
+ readonly finished: Promise<void>;
40
+ /** Share one host notification across publication, receiver reads and abandonment. */
41
+ reportFailure(error: unknown, report: (error: unknown) => void): void;
42
+ bind(context: Context): void;
43
+ close(): void;
44
+ }
45
+ /** Private capability lane, available only between matched prepared handlers. */
46
+ export interface CapturedDelivery {
47
+ readonly value: Encoded;
48
+ readonly capabilities?: readonly (ResourceCapability | ByteStreamCapability)[];
49
+ /** Bounded provider outcome after an early result head; actual work uses the retain sink. */
50
+ readonly finished?: Promise<void>;
51
+ }
52
+ /** A private data path, never passed to ordinary application handlers or stored on Context. */
53
+ export interface CapturedInvocation {
54
+ readonly signature: string;
55
+ readonly input: Encoded;
56
+ /** Permit checked ordinary data results when this caller does not require captured delivery. */
57
+ readonly dataResult?: true;
58
+ output?: Encoded;
59
+ receiver?: ResourceCapability;
60
+ capabilities?: readonly (ResourceCapability | ByteStreamCapability)[];
61
+ arguments?: CapturedArguments;
62
+ }
63
+ /** Ownership is accepted only after checked preflight and entry into the receiving callback. */
64
+ export interface CapturedArguments {
65
+ readonly owners: readonly ResourceCapability[];
66
+ readonly accepted: boolean;
67
+ accept(): void;
68
+ }
69
+ /** The ordinary checked data entry of a prepared backend, with physical retention. */
70
+ type CapturedDataMethod = (environment: any, context: Context, args: readonly unknown[], retain: (physical: Promise<void>) => void) => Promise<unknown>;
71
+ interface CapturedMethod {
72
+ readonly signature: string | undefined;
73
+ readonly invokeData?: CapturedDataMethod;
74
+ invoke(environment: any, context: Context, input: Encoded, receiver?: ResourceReceiver,
75
+ /** Register actual physical completion before the bounded result may resolve or reject. */
76
+ retain?: (physical: Promise<void>) => void, arguments_?: CapturedArguments): Promise<Encoded | CapturedDelivery>;
77
+ }
78
+ /** Register the actual prepared handler, rather than certifying a caller-owned object or frame. */
79
+ export declare function bindCaptured(handle: Handler, signature: string | undefined, invoke: CapturedMethod["invoke"], invokeData?: CapturedDataMethod): Handler;
80
+ /** Resolve only the implementation selected by admission and only for an identical contract. */
81
+ export declare function capturedMethod(handle: Handler, signature: string): CapturedMethod | undefined;
82
+ /** Ordinary data callers retain backend work without receiving the capability channel. */
83
+ export declare function capturedDataMethod(handle: Handler): CapturedDataMethod | undefined;
84
+ export declare const declareFactory: unique symbol;
85
+ export declare const validateEnvironment: unique symbol;
86
+ export declare const isolate: unique symbol;
87
+ export declare const signature: unique symbol;
88
+ export declare const signatures: unique symbol;
89
+ export type AdaptedHostOptions = HostOptions & {
90
+ [isolate]?: (definition: OrbArtifact) => Promise<OrbDefinition>;
91
+ };
92
+ export declare const disposeOrb: unique symbol;
93
+ export declare const releaseEnvironment: unique symbol;
94
+ export declare const isolatedRevision: unique symbol;
95
+ export declare const admitFactory: unique symbol;
96
+ export type AdaptedOrb = OrbDefinition & {
97
+ [isolatedRevision]?: true;
98
+ [declareFactory]?: (declaration: Declaration) => Promise<unknown>;
99
+ [admitFactory]?: () => Promise<() => void>;
100
+ [disposeOrb]?: () => void | Promise<void>;
101
+ [validateEnvironment]?: (environment: Environment, value: unknown) => Promise<void>;
102
+ [releaseEnvironment]?: (environment: Environment) => void | Promise<void>;
103
+ };
104
+ export type AdaptedService = ServiceDefinition & {
105
+ [signature]?: string;
106
+ [declareFactory]?: (declaration: Declaration) => Promise<unknown>;
107
+ [admitFactory]?: () => Promise<() => void>;
108
+ };
109
+ export type AdaptedHook = HookDefinition & {
110
+ [signature]?: string;
111
+ };
112
+ /** Materialize a fresh revision per installation, disposing earlier candidates on failure. */
113
+ export declare function prepareDefinitions(definitions: readonly OrbInput[], isolated?: (definition: OrbArtifact) => Promise<OrbDefinition>): OrbDefinition[] | Promise<OrbDefinition[]>;
114
+ /** Dispose failed candidates while retaining both the operation and cleanup causes. */
115
+ export declare function discardDefinitions(definitions: readonly OrbDefinition[], error: unknown): Promise<never>;
116
+ /** Release backend revisions only after their physically owning scopes are gone. */
117
+ export declare function disposeDefinitions(definitions: readonly OrbDefinition[]): Promise<void>;
118
+ /** Keep source factories synchronous while a backend prepares their transport asynchronously. */
119
+ export declare function captureEnvironment(definition: OrbDefinition | ServiceDefinition, declaration: import("../authoring/declaration.ts").Declaration): import("./records.ts").Environment | Promise<import("./records.ts").Environment>;
120
+ export {};
@@ -0,0 +1,38 @@
1
+ import {
2
+ bindCaptured2,
3
+ capturedMethod2,
4
+ capturedDataMethod2,
5
+ declareFactory2,
6
+ validateEnvironment2,
7
+ isolate2,
8
+ signature2,
9
+ signatures2,
10
+ disposeOrb2,
11
+ releaseEnvironment2,
12
+ isolatedRevision2,
13
+ admitFactory2,
14
+ prepareDefinitions2,
15
+ discardDefinitions2,
16
+ disposeDefinitions2,
17
+ captureEnvironment2
18
+ } from "../chunks/index-zkqmnjj8.js";
19
+ import"../chunks/index-kr4x67wt.js";
20
+ import"../chunks/index-c1w7z9hx.js";
21
+ export {
22
+ admitFactory2 as admitFactory,
23
+ bindCaptured2 as bindCaptured,
24
+ captureEnvironment2 as captureEnvironment,
25
+ capturedDataMethod2 as capturedDataMethod,
26
+ capturedMethod2 as capturedMethod,
27
+ declareFactory2 as declareFactory,
28
+ discardDefinitions2 as discardDefinitions,
29
+ disposeDefinitions2 as disposeDefinitions,
30
+ disposeOrb2 as disposeOrb,
31
+ isolate2 as isolate,
32
+ isolatedRevision2 as isolatedRevision,
33
+ prepareDefinitions2 as prepareDefinitions,
34
+ releaseEnvironment2 as releaseEnvironment,
35
+ signature2 as signature,
36
+ signatures2 as signatures,
37
+ validateEnvironment2 as validateEnvironment
38
+ };
@@ -1,3 +1,4 @@
1
+ import { type CapturedInvocation } from "#tembra-adapters";
1
2
  import type { Completion } from "../authoring/types.ts";
2
3
  import { Context } from "./context.ts";
3
4
  import type { Environment, ReferenceRecord } from "./records.ts";
@@ -8,18 +9,18 @@ export declare class Calls {
8
9
  readonly session: Session;
9
10
  /** Connect JS callback execution to the session kernel. */
10
11
  constructor(session: Session);
11
- /** Settle JavaScript frames after the embedding has unwound a terminated V8 turn. */
12
- interrupt(): void;
13
- /** Keep the callback frame separate from its physical completion bookkeeping. */
12
+ /** Invoke callbacks in a microtask and retain their actual promise until physical settlement. */
14
13
  execute<T>(operation: () => Completion<T>): Promise<T>;
15
- /** Lazily mirror root cancellation into an AbortSignal. */
14
+ /** Read the root mirror; foreign-issued roots are checked before its first creation. */
16
15
  signal(root: number): AbortSignal;
17
16
  /** Revoke claims and cancellation mirrors when either language ends a root. */
18
17
  releaseRoot(root: number): void;
19
18
  /** Release root-owned references after the callback settles. */
20
19
  root<T>(operation: (context: Context) => Completion<T>, cleanup?: boolean, issuedRoot?: number, principal?: string): Promise<T>;
21
- /** Execute one admitted service call and retain physical ownership. */
22
- invoke(reference: ReferenceRecord, method: string, arguments_: unknown[], ctx: Context): Promise<unknown>;
20
+ /** Let an application stop observing a call while its actual work remains owned. */
21
+ invoke(reference: ReferenceRecord, method: string, arguments_: unknown[], ctx: Context, capture?: CapturedInvocation): Promise<unknown>;
22
+ /** Foreign callbacks retain their dependency until it physically settles, including on cancellation. */
23
+ invokePhysical(reference: ReferenceRecord, method: string, arguments_: unknown[], ctx: Context, capture?: CapturedInvocation): Promise<unknown>;
23
24
  /** Fresh callback roots inherit owner identity; supplied roots retain the caller's authority. */
24
25
  owned<T>(environment: Environment, operation: number, handle: (ctx: Context) => Completion<T>, root?: number | Context): Promise<T>;
25
26
  /** Stop waiting on cancellation while physical work remains tracked. */
@@ -10,7 +10,9 @@ export declare class Lifecycle {
10
10
  get closedDiagnostics(): ReturnType<Lifecycle["diagnostics"]> | undefined;
11
11
  /** Drain kernel actions without re-entering the dispatcher. */
12
12
  flush(initial?: Action[]): void;
13
- /** Compose kernel finish bookkeeping through the embedded adapter when available. */
13
+ /** End a logical root and dispatch its resulting cleanup without extra drain/deadline queries. */
14
+ endRoot(root: number): void;
15
+ /** Finish a call in one bounded kernel exchange: tick, finish, drain and next deadline. */
14
16
  finishCall(call: number): void;
15
17
  /** Execute one action using its owning JS module. */
16
18
  private action;
@@ -1,4 +1,5 @@
1
- import type { ContributionHandler, OrbDefinition } from "../authoring/types.ts";
1
+ import type { ContributionHandler, OrbDefinition, OrbInput } from "../authoring/types.ts";
2
+ import type { OrbDeclaration } from "../bridge/kernel.ts";
2
3
  import { Context } from "./context.ts";
3
4
  import type { Environment, OrbRecord } from "./records.ts";
4
5
  import type { Session } from "./session.ts";
@@ -15,12 +16,12 @@ export declare class Orbs {
15
16
  /** Capture definitions and encode their kernel-owned contracts. */
16
17
  declarations(definitions: readonly OrbDefinition[]): {
17
18
  definitions: OrbDefinition[];
18
- metadata: unknown[];
19
+ metadata: OrbDeclaration[];
19
20
  };
20
21
  /** Commit new orb metadata before opening its scopes. */
21
- install(definitions: readonly OrbDefinition[]): Promise<void>;
22
+ install(definitions: readonly OrbInput[]): Promise<void>;
22
23
  /** Declare one shared scope for this orb version. */
23
- scope(record: OrbRecord): Environment;
24
+ scope(record: OrbRecord): Environment | Promise<Environment>;
24
25
  /** Share pending activation and clean up failed orb scopes. */
25
26
  ready(record: OrbRecord): Promise<void>;
26
27
  /** Register callback identities with stable contribution order. */
@@ -3,6 +3,11 @@ import type { Acquisition } from "../bridge/kernel.ts";
3
3
  import { Context } from "./context.ts";
4
4
  import type { Address, OrbRecord, ObjectRecord, ReferenceRecord } from "./records.ts";
5
5
  import type { Session } from "./session.ts";
6
+ /** Resolve an SDK-issued handle for the existing portable WIT client lane. */
7
+ export declare function referenceOrigin(value: object): {
8
+ session: Session;
9
+ record: ReferenceRecord;
10
+ };
6
11
  /** JS reference handles and per-object visibility. */
7
12
  export declare class References {
8
13
  #private;
@@ -13,8 +18,29 @@ export declare class References {
13
18
  activateAcquired(acquired: Acquisition, address: Address, requiredMethods?: string[]): Promise<void>;
14
19
  /** Acquire ownership and create a local service handle. */
15
20
  hold(definition: string | ServiceDefinition, key: string | readonly string[], options?: AcquisitionOptions, ctx?: Context): DynamicReference;
16
- /** Release the acquired claim if activation fails. */
21
+ /** The canonical service name and effective options of an acquisition. */
22
+ private service;
23
+ /** The address an acquisition targets; the principal defaults to the caller's root. */
24
+ private address;
25
+ /**
26
+ * The physical disposal of the exact local instance a refusal names: the kernel refused
27
+ * because the previous instance at this address is still closing. Only a concrete matching
28
+ * object's `disposing` promise qualifies; anything else keeps the original refusal.
29
+ */
30
+ private closing;
31
+ /**
32
+ * Acquire and wait for activation; release the acquired claim if activation fails.
33
+ *
34
+ * Unlike the synchronous `hold`, an acquisition refused only because the previous instance
35
+ * at the same address is still closing waits for that instance's physical disposal, then
36
+ * acquires anew with every check repeated. The old instance is never revived or overlapped
37
+ * and no factory runs early. The caller's root cancellation ends the wait, never the
38
+ * teardown. A failed disposal is recorded and reported by the lifecycle that owns it; the
39
+ * caller then acquires a fresh instance. Every other refusal is returned at once.
40
+ */
17
41
  get(service: string | ServiceDefinition, key: string | readonly string[], options?: AcquisitionOptions, ctx?: Context): Promise<DynamicReference>;
42
+ /** Retain exactly this claim, without reacquisition or re-evaluating access policy. */
43
+ duplicate(original: ReferenceRecord): ReferenceRecord;
18
44
  /** Require a reference issued by this session. */
19
45
  reference(value: unknown): ReferenceRecord;
20
46
  /** Cache native orb metadata once per version. */
@@ -1,4 +1,4 @@
1
- import type { OrbDefinition, PreparedReload, ReloadOptions, ReloadReport } from "../authoring/types.ts";
1
+ import type { OrbInput, PreparedReload, ReloadOptions, ReloadReport } from "../authoring/types.ts";
2
2
  import type { Session } from "./session.ts";
3
3
  /** Captures JS factories and exposes the engine's transaction handle. No reload policy lives here. */
4
4
  export declare class Replacements {
@@ -7,11 +7,13 @@ export declare class Replacements {
7
7
  /** Track one replacement candidate for this session. */
8
8
  constructor(session: Session);
9
9
  /** Prepare and commit a replacement in one operation. */
10
- replace(definitions: readonly OrbDefinition[], options?: ReloadOptions, remove?: readonly string[]): Promise<ReloadReport>;
10
+ replace(definitions: readonly OrbInput[], options?: ReloadOptions, remove?: readonly string[]): Promise<ReloadReport>;
11
11
  /** Reject overlapping replacement attempts before capturing callbacks. */
12
- prepare(definitions: readonly OrbDefinition[], options?: ReloadOptions, remove?: readonly string[]): Promise<PreparedReload>;
12
+ prepare(definitions: readonly OrbInput[], options?: ReloadOptions, remove?: readonly string[]): Promise<PreparedReload>;
13
13
  /** Abort pending preparation and wait for physical recovery. */
14
14
  cancel(): Promise<void>;
15
+ /** Treat the expected abort acknowledgement as settlement while preserving recovery failures. */
16
+ private settleAbort;
15
17
  /** Bind candidate callbacks to the kernel's prepared replacement. */
16
18
  private capture;
17
19
  }
@@ -13,7 +13,7 @@ export declare class Scopes {
13
13
  /** Declare native or JS object scopes and wait for readiness. */
14
14
  activate(object: ObjectRecord, acquired: Acquisition): Promise<void>;
15
15
  /** Run a service factory synchronously and register its scope. */
16
- createEnvironment(object: ObjectRecord, orb: OrbRecord): Environment;
16
+ createEnvironment(object: ObjectRecord, orb: OrbRecord): Environment | Promise<Environment>;
17
17
  /** Share host activation and reopen retired resource scopes. */
18
18
  readyHostScope(): Promise<void>;
19
19
  /** Clean up the previous scope before rebinding its resources. */
@@ -0,0 +1,4 @@
1
+ /** Observe both browser signals and React Native's smaller AbortSignal implementation. */
2
+ export declare function checkSignal(signal: AbortSignal): void;
3
+ /** Link cancellation to a callback lifetime and remove fallback listeners when either ends. */
4
+ export declare function combinedSignal(owner: AbortSignal, ended: AbortSignal): AbortSignal;
@@ -0,0 +1,38 @@
1
+ /** Generated clients use checked WIT delivery on their reference's existing transport. */
2
+ import type { CapturedInvocation } from "#tembra-adapters";
3
+ import type { DynamicReference } from "../authoring/types.ts";
4
+ import type { GraphFunction, TypeGraph } from "../interpreter/component/values.ts";
5
+ import { Context } from "./context.ts";
6
+ /** Public ownership operations of a provider-issued WIT resource. */
7
+ export interface WitResource {
8
+ readonly resourceType: string;
9
+ /** Release this resource through its existing SDK owner. */
10
+ release(): void;
11
+ }
12
+ /** Build-time checked metadata retained by generated WIT clients. */
13
+ export interface WitClientSchema extends TypeGraph {
14
+ readonly imports?: readonly {
15
+ readonly binding: string;
16
+ readonly contract?: string;
17
+ }[];
18
+ readonly identity: string;
19
+ readonly signature: string;
20
+ readonly resources: Readonly<Record<string, number>>;
21
+ readonly functions: Readonly<Record<string, GraphFunction>>;
22
+ }
23
+ /** An awaitable invocation of one generated, precisely typed WIT signature. */
24
+ export interface WitClient {
25
+ call<T>(method: string, args: readonly unknown[]): Promise<T>;
26
+ }
27
+ /** Internal backend for the same generated wrappers and SDK resource capabilities. */
28
+ export interface WitClientBackend {
29
+ readonly identity: object;
30
+ /** Keep decoding inside the operation's existing cancellation and physical ownership scope. */
31
+ run<T>(supplied: Context | undefined, operation: (context: Context | undefined) => Promise<T>): Promise<T>;
32
+ /** Deliver through the backend selected by this issued reference. */
33
+ invoke(method: string, args: unknown[], capture: CapturedInvocation, context?: Context): Promise<void>;
34
+ }
35
+ /** Attach RPC delivery metadata to an issued reference; this grants no resource authority. */
36
+ export declare function bindWitReference(reference: object, backend: (schema: WitClientSchema) => WitClientBackend): void;
37
+ /** Bind typed wrappers to an SDK reference without creating another capability protocol. */
38
+ export declare function witClient(reference: DynamicReference, schema: WitClientSchema): WitClient;
package/dist/telemetry.js CHANGED
@@ -1,27 +1,6 @@
1
- // src/telemetry.ts
2
- class Telemetry {
3
- capacity;
4
- sampleEvery;
5
- #events = [];
6
- #next = 0;
7
- constructor(capacity = 256, sampleEvery = 1) {
8
- this.capacity = capacity;
9
- this.sampleEvery = sampleEvery;
10
- if (!Number.isInteger(capacity) || capacity <= 0 || !Number.isInteger(sampleEvery) || sampleEvery <= 0)
11
- throw new RangeError("Invalid telemetry limits");
12
- }
13
- sample() {
14
- return this.#next++ % this.sampleEvery === 0;
15
- }
16
- record(trace) {
17
- if (this.#events.length === this.capacity)
18
- this.#events.shift();
19
- this.#events.push(trace);
20
- }
21
- drain() {
22
- return this.#events.splice(0);
23
- }
24
- }
1
+ import {
2
+ Telemetry2
3
+ } from "./chunks/index-za4mg94e.js";
25
4
  export {
26
- Telemetry
5
+ Telemetry2 as Telemetry
27
6
  };
@@ -1,3 +1,3 @@
1
- import { type Artifact, type BuildConfig } from "./types.ts";
2
- /** Resolves packages at build time and emits exactly one content-addressed ESM file per target. */
1
+ import type { Artifact, BuildConfig } from "./types.ts";
2
+ /** Resolve dependencies and WIT types, then emit one closed Wasm artifact per Orb. */
3
3
  export declare function build(config: BuildConfig): Promise<readonly Artifact[]>;
@@ -0,0 +1,23 @@
1
+ /** Name one resource per nominal definition, preserving transparent WIT aliases. */
2
+ interface ResourceGraph {
3
+ readonly types: readonly {
4
+ readonly id: number;
5
+ readonly definition: {
6
+ readonly kind: string | {
7
+ readonly type?: string | number | null | undefined;
8
+ };
9
+ readonly owner?: string;
10
+ readonly name?: string;
11
+ };
12
+ }[];
13
+ }
14
+ /** Generated names, nominal identities and transparent alias declarations. */
15
+ interface ResourceNames {
16
+ readonly names: ReadonlyMap<number, string>;
17
+ readonly nominals: ReadonlyMap<number, string>;
18
+ readonly aliases: readonly string[];
19
+ canonical(id: number): number;
20
+ }
21
+ /** Group local and imported resource aliases by their original WIT definition. */
22
+ export declare function resourceNames(graph: ResourceGraph, resources: Readonly<Record<string, number>>, identity: string, occupied: Set<string>): ResourceNames;
23
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface ClientOptions {
2
+ /** The contract's entry `.wit` file; its directory and `deps/` resolve as for `build()`. */
3
+ wit: string;
4
+ /** The world whose exported interfaces get clients; the package's only world when omitted. */
5
+ world?: string;
6
+ /** The directory of the generated modules, one `<namespace>-<package>-<interface>.ts` each. */
7
+ out: string;
8
+ }
9
+ /** Write one typed client module per exported interface; returns every module's path. */
10
+ export declare function client(options: ClientOptions): Promise<readonly string[]>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Exact, fail-closed instrumentation of JCO 0.23.0 glue, applied at build time by Tembra tooling
3
+ * to bindings generated from natively verified component bytes; browsers never run this code.
4
+ * It adds per-instance export-task start, task exit (with rejection) and trap notifications plus
5
+ * a current-root-task accessor through the official 4th `instantiate(..., options)` argument.
6
+ * Every anchor must occur exactly once; any vendor drift refuses the glue instead of emitting
7
+ * uninstrumented code.
8
+ */
9
+ export declare const JCO_VERSION = "0.23.0";
10
+ /** Instrument generated glue through its task and trap notifications. */
11
+ export declare function instrumentGlue(source: string): string;
12
+ export declare function fixLiftOwnTables(source: string): string;
13
+ export declare function fixResultErrExit(source: string): string;
14
+ export declare function fixSchedulerTurns(source: string): string;
15
+ export declare function fixResourceClosures(source: string): string;
16
+ /** Apply every required rewrite to generated glue, in the order the anchors expect. */
17
+ export declare function prepareGlue(source: string): string;
@@ -0,0 +1,11 @@
1
+ /** Files written for one prepared adapter. */
2
+ export interface BrowserAdapter {
3
+ /** The ES module the application imports and passes to `createHost`. */
4
+ readonly module: string;
5
+ readonly files: readonly string[];
6
+ }
7
+ /**
8
+ * Prepare a verified compiled artifact for browsers into the build-owned `directory`.
9
+ * `artifact` must be the exact bytes the application will load; `sha256` is their digest.
10
+ */
11
+ export declare function prepareBrowserComponent(artifact: Uint8Array, sha256: string, directory: string): Promise<BrowserAdapter>;
@@ -1,2 +1,4 @@
1
1
  export { build } from "./build.ts";
2
- export { Platform, defineConfig, type Artifact, type BuildConfig, type BuildTarget, } from "./types.ts";
2
+ export { client, type ClientOptions } from "./client.ts";
3
+ export { prepareBrowserComponent, type BrowserAdapter } from "./component.ts";
4
+ export { defineConfig, type Artifact, type BuildConfig, type BuildTarget } from "./types.ts";