@kinotic-ai/core 5.0.0-beta.24 → 5.0.0-beta.25

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.
package/dist/index.cjs CHANGED
@@ -69,6 +69,7 @@ __export(exports_src, {
69
69
  scopeOptionalMethodNames: () => scopeOptionalMethodNames,
70
70
  receivesContext: () => receivesContext,
71
71
  isAdvertised: () => isAdvertised,
72
+ declareServiceDefinitions: () => declareServiceDefinitions,
72
73
  createCRI: () => createCRI,
73
74
  buildServerUrl: () => buildServerUrl,
74
75
  buildBrokerUrl: () => buildBrokerUrl,
@@ -1297,7 +1298,7 @@ var import_api2 = __toESM(require("@opentelemetry/api"));
1297
1298
  // packages/core/package.json
1298
1299
  var package_default = {
1299
1300
  name: "@kinotic-ai/core",
1300
- version: "5.0.0-beta.24",
1301
+ version: "5.0.0-beta.25",
1301
1302
  type: "module",
1302
1303
  files: [
1303
1304
  "dist"
@@ -1366,6 +1367,7 @@ var package_default = {
1366
1367
  vitest: "^4.1.4"
1367
1368
  },
1368
1369
  dependencies: {
1370
+ "@kinotic-ai/idl": "workspace:^",
1369
1371
  "@opentelemetry/api": "^1.9.1",
1370
1372
  "@opentelemetry/semantic-conventions": "^1.40.0",
1371
1373
  "@stomp/rx-stomp": "^2.4.0",
@@ -1756,10 +1758,59 @@ class TextEventFactory {
1756
1758
  return event;
1757
1759
  }
1758
1760
  }
1761
+ var APPLICATION_SERVICE_DIRECTORY = "app-api~org.kinotic.app.api.services.ApplicationServiceDirectory";
1762
+ var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
1763
+ var declaredDefinitions = new Map;
1764
+ function declareServiceDefinitions(definitions) {
1765
+ for (const definition of definitions) {
1766
+ declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
1767
+ }
1768
+ }
1769
+ function qualifiedNameOf(namespace, name) {
1770
+ return namespace ? `${namespace}.${name}` : name;
1771
+ }
1772
+ function servedFunctions(serviceInstance) {
1773
+ const ret = new Set;
1774
+ let proto = Object.getPrototypeOf(serviceInstance);
1775
+ while (proto && proto !== Object.prototype) {
1776
+ for (const key of Object.getOwnPropertyNames(proto)) {
1777
+ const descriptor = Object.getOwnPropertyDescriptor(proto, key);
1778
+ if (typeof descriptor?.value === "function" && key !== "constructor") {
1779
+ ret.add(key);
1780
+ }
1781
+ }
1782
+ proto = Object.getPrototypeOf(proto);
1783
+ }
1784
+ return [...ret].sort();
1785
+ }
1786
+ function directoryEntryOf(serviceInstance, serviceIdentifier) {
1787
+ let ret = null;
1788
+ const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
1789
+ if (application) {
1790
+ const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
1791
+ const definition = declaredDefinitions.get(qualifiedName);
1792
+ if (definition) {
1793
+ const declared = definition.functions.map((f) => f.name).sort();
1794
+ const served = servedFunctions(serviceInstance);
1795
+ if (declared.join() !== served.join()) {
1796
+ throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
1797
+ }
1798
+ ret = {
1799
+ applicationId: application[1],
1800
+ zone: serviceIdentifier.zone,
1801
+ version: serviceIdentifier.version ?? null,
1802
+ advertised: isAdvertised(serviceInstance),
1803
+ serviceDefinition: definition
1804
+ };
1805
+ }
1806
+ }
1807
+ return ret;
1808
+ }
1759
1809
 
1760
1810
  class ServiceRegistry {
1761
1811
  _eventBus;
1762
1812
  supervisors = new Map;
1813
+ entries = new Map;
1763
1814
  contextInterceptor = null;
1764
1815
  debugLogger = import_debug3.default("kinotic:serviceRegistry");
1765
1816
  constructor(eventBus) {
@@ -1781,9 +1832,16 @@ class ServiceRegistry {
1781
1832
  const criString = serviceIdentifier.cri().raw();
1782
1833
  if (!this.supervisors.has(criString)) {
1783
1834
  this.debugLogger(`Registering service for CRI: ${criString}`);
1835
+ const entry = directoryEntryOf(service, serviceIdentifier);
1784
1836
  const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
1785
1837
  this.supervisors.set(criString, supervisor);
1786
1838
  supervisor.start();
1839
+ if (entry) {
1840
+ this.entries.set(criString, entry);
1841
+ if (this.eventBus.isConnected()) {
1842
+ this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
1843
+ }
1844
+ }
1787
1845
  }
1788
1846
  }
1789
1847
  unRegister(serviceIdentifier) {
@@ -1793,8 +1851,18 @@ class ServiceRegistry {
1793
1851
  this.debugLogger(`Unregistering service for CRI: ${criString}`);
1794
1852
  supervisor.stop();
1795
1853
  this.supervisors.delete(criString);
1854
+ this.entries.delete(criString);
1855
+ }
1856
+ }
1857
+ async registerEntries() {
1858
+ for (const entry of this.entries.values()) {
1859
+ await this.registerEntry(entry);
1796
1860
  }
1797
1861
  }
1862
+ async registerEntry(entry) {
1863
+ this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
1864
+ await this.serviceProxy(APPLICATION_SERVICE_DIRECTORY).invoke("register", [entry]);
1865
+ }
1798
1866
  registerContextInterceptor(interceptor) {
1799
1867
  this.contextInterceptor = interceptor;
1800
1868
  }
@@ -1886,8 +1954,10 @@ class KinoticSingleton {
1886
1954
  this._eventBus = eventBus;
1887
1955
  this.serviceRegistry.eventBus = eventBus;
1888
1956
  }
1889
- connect(options) {
1890
- return this._eventBus.connect(Util.resolveConnectOptions(options));
1957
+ async connect(options) {
1958
+ const ret = await this._eventBus.connect(Util.resolveConnectOptions(options));
1959
+ await this.serviceRegistry.registerEntries();
1960
+ return ret;
1891
1961
  }
1892
1962
  disconnect(force) {
1893
1963
  return this._eventBus.disconnect(force);
package/dist/index.d.cts CHANGED
@@ -647,6 +647,7 @@ interface IServiceRegistry {
647
647
  */
648
648
  registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
649
649
  }
650
+ import { ServiceDefinition } from "@kinotic-ai/idl";
650
651
  /**
651
652
  * An implementation of a {@link IEventFactory} which uses JSON content
652
653
  */
@@ -660,11 +661,20 @@ declare class TextEventFactory implements IEventFactory {
660
661
  create(cri: string, args: any[] | null | undefined): IEvent;
661
662
  }
662
663
  /**
664
+ * Declares the definitions of the project's published services, as `kinotic sync` generates them into the
665
+ * project's ServiceDefinitions module, so every registry registers each service in the platform's service
666
+ * directory with its definition when the service comes online. A definition declared again for a qualified
667
+ * name replaces the one held.
668
+ * @param definitions the generated definitions
669
+ */
670
+ declare function declareServiceDefinitions(definitions: ServiceDefinition[]): void;
671
+ /**
663
672
  * The default implementation of {@link IServiceRegistry}
664
673
  */
665
674
  declare class ServiceRegistry implements IServiceRegistry {
666
675
  private _eventBus;
667
676
  private supervisors;
677
+ private entries;
668
678
  private contextInterceptor;
669
679
  private debugLogger;
670
680
  constructor(eventBus: IEventBus);
@@ -673,6 +683,14 @@ declare class ServiceRegistry implements IServiceRegistry {
673
683
  serviceProxy(serviceIdentifier: string): IServiceProxy;
674
684
  register(serviceIdentifier: ServiceIdentifier, service: any): void;
675
685
  unRegister(serviceIdentifier: ServiceIdentifier): void;
686
+ /**
687
+ * Registers every application service registered so far in the platform's service directory, with the
688
+ * definition the project declared for it, so the directory lists the service and the platform checks
689
+ * requests to it; a service the platform refuses fails the registration. A service registered later is
690
+ * registered in the directory as it registers here.
691
+ */
692
+ registerEntries(): Promise<void>;
693
+ private registerEntry;
676
694
  registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
677
695
  }
678
696
  /**
@@ -740,8 +758,9 @@ declare class KinoticSingleton implements IKinotic {
740
758
  get eventBus(): IEventBus;
741
759
  set eventBus(eventBus: IEventBus);
742
760
  /**
743
- * Connects to a Kinotic server. Every option is optional: absent server fields and
744
- * credentials resolve from the environment — see {@link ConnectOptions}.
761
+ * Connects to a Kinotic server and registers the application services registered so far in the platform's
762
+ * service directory. Every option is optional: absent server fields and credentials resolve from the
763
+ * environment — see {@link ConnectOptions}.
745
764
  * @param options overrides for the resolved connection, or nothing to resolve everything
746
765
  * @return Promise containing the result of the initial connection attempt
747
766
  */
@@ -829,6 +848,34 @@ declare function receivesContext(serviceInstance: object, methodName: string): b
829
848
  * so it appears in directory listings
830
849
  */
831
850
  declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
851
+ import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
852
+ /**
853
+ * A service of an application as its runtime registers it in the platform's service directory: the application
854
+ * it belongs to, where it is addressed, whether it is advertised, and its definition. The platform owns
855
+ * everything else about the directory's entry, such as the service's liveness.
856
+ */
857
+ interface ServiceDirectoryEntry {
858
+ /**
859
+ * The application the service belongs to, which its zone names.
860
+ */
861
+ applicationId: string;
862
+ /**
863
+ * The zone the service is addressed in, the application's or a label under it.
864
+ */
865
+ zone: string;
866
+ /**
867
+ * The version the service registers under, or null for none.
868
+ */
869
+ version: string | null;
870
+ /**
871
+ * True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
872
+ */
873
+ advertised: boolean;
874
+ /**
875
+ * The service's definition: its functions, with the parameters a request carries and what each returns.
876
+ */
877
+ serviceDefinition: ServiceDefinition2;
878
+ }
832
879
  /**
833
880
  * Validates that the given zone satisfies the zone grammar
834
881
  * @param zone the zone to validate
@@ -1426,4 +1473,4 @@ declare class ParticipantConstants {
1426
1473
  /** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
1427
1474
  static readonly CLI_PARTICIPANT_ID: string;
1428
1475
  }
1429
- export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, ResolvedCredentials, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, FunctionalIterablePage, EventConstants, EventBus, Event, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AuthorizationException, AbstractIterablePage };
1476
+ export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, declareServiceDefinitions, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceDirectoryEntry, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, ResolvedCredentials, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, FunctionalIterablePage, EventConstants, EventBus, Event, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AuthorizationException, AbstractIterablePage };
package/dist/index.d.ts CHANGED
@@ -647,6 +647,7 @@ interface IServiceRegistry {
647
647
  */
648
648
  registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
649
649
  }
650
+ import { ServiceDefinition } from "@kinotic-ai/idl";
650
651
  /**
651
652
  * An implementation of a {@link IEventFactory} which uses JSON content
652
653
  */
@@ -660,11 +661,20 @@ declare class TextEventFactory implements IEventFactory {
660
661
  create(cri: string, args: any[] | null | undefined): IEvent;
661
662
  }
662
663
  /**
664
+ * Declares the definitions of the project's published services, as `kinotic sync` generates them into the
665
+ * project's ServiceDefinitions module, so every registry registers each service in the platform's service
666
+ * directory with its definition when the service comes online. A definition declared again for a qualified
667
+ * name replaces the one held.
668
+ * @param definitions the generated definitions
669
+ */
670
+ declare function declareServiceDefinitions(definitions: ServiceDefinition[]): void;
671
+ /**
663
672
  * The default implementation of {@link IServiceRegistry}
664
673
  */
665
674
  declare class ServiceRegistry implements IServiceRegistry {
666
675
  private _eventBus;
667
676
  private supervisors;
677
+ private entries;
668
678
  private contextInterceptor;
669
679
  private debugLogger;
670
680
  constructor(eventBus: IEventBus);
@@ -673,6 +683,14 @@ declare class ServiceRegistry implements IServiceRegistry {
673
683
  serviceProxy(serviceIdentifier: string): IServiceProxy;
674
684
  register(serviceIdentifier: ServiceIdentifier, service: any): void;
675
685
  unRegister(serviceIdentifier: ServiceIdentifier): void;
686
+ /**
687
+ * Registers every application service registered so far in the platform's service directory, with the
688
+ * definition the project declared for it, so the directory lists the service and the platform checks
689
+ * requests to it; a service the platform refuses fails the registration. A service registered later is
690
+ * registered in the directory as it registers here.
691
+ */
692
+ registerEntries(): Promise<void>;
693
+ private registerEntry;
676
694
  registerContextInterceptor<T extends ServiceContext>(interceptor: ContextInterceptor<T> | null): void;
677
695
  }
678
696
  /**
@@ -740,8 +758,9 @@ declare class KinoticSingleton implements IKinotic {
740
758
  get eventBus(): IEventBus;
741
759
  set eventBus(eventBus: IEventBus);
742
760
  /**
743
- * Connects to a Kinotic server. Every option is optional: absent server fields and
744
- * credentials resolve from the environment — see {@link ConnectOptions}.
761
+ * Connects to a Kinotic server and registers the application services registered so far in the platform's
762
+ * service directory. Every option is optional: absent server fields and credentials resolve from the
763
+ * environment — see {@link ConnectOptions}.
745
764
  * @param options overrides for the resolved connection, or nothing to resolve everything
746
765
  * @return Promise containing the result of the initial connection attempt
747
766
  */
@@ -829,6 +848,34 @@ declare function receivesContext(serviceInstance: object, methodName: string): b
829
848
  * so it appears in directory listings
830
849
  */
831
850
  declare function Publish(namespace?: string | null, name?: string, advertise?: boolean): <T extends new (...args: any[]) => object>(value: T, _context: ClassDecoratorContext<any>) => T;
851
+ import { ServiceDefinition as ServiceDefinition2 } from "@kinotic-ai/idl";
852
+ /**
853
+ * A service of an application as its runtime registers it in the platform's service directory: the application
854
+ * it belongs to, where it is addressed, whether it is advertised, and its definition. The platform owns
855
+ * everything else about the directory's entry, such as the service's liveness.
856
+ */
857
+ interface ServiceDirectoryEntry {
858
+ /**
859
+ * The application the service belongs to, which its zone names.
860
+ */
861
+ applicationId: string;
862
+ /**
863
+ * The zone the service is addressed in, the application's or a label under it.
864
+ */
865
+ zone: string;
866
+ /**
867
+ * The version the service registers under, or null for none.
868
+ */
869
+ version: string | null;
870
+ /**
871
+ * True when the service advertised itself with `@Publish(advertise = true)` and appears in directory listings.
872
+ */
873
+ advertised: boolean;
874
+ /**
875
+ * The service's definition: its functions, with the parameters a request carries and what each returns.
876
+ */
877
+ serviceDefinition: ServiceDefinition2;
878
+ }
832
879
  /**
833
880
  * Validates that the given zone satisfies the zone grammar
834
881
  * @param zone the zone to validate
@@ -1426,4 +1473,4 @@ declare class ParticipantConstants {
1426
1473
  /** The clientId the test server's TestSecurityService maps to the ANONYMOUS role in core package tests. */
1427
1474
  static readonly CLI_PARTICIPANT_ID: string;
1428
1475
  }
1429
- export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, ResolvedCredentials, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, FunctionalIterablePage, EventConstants, EventBus, Event, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AuthorizationException, AbstractIterablePage };
1476
+ export { validateZone, validateLabel, scopeOptionalMethodNames, receivesContext, isAdvertised, declareServiceDefinitions, createCRI, buildServerUrl, buildBrokerUrl, Zone, WebSocketFactory, Version, TextEventFactory, Sort, SessionKeepAliveMode, SessionCredentialsResolver, ServiceRegistry, ServiceIdentifier, ServiceDirectoryEntry, ServiceContext, ServerInfo, ScopeOptional, Scope, RpcError, ResolvedCredentials, Publish, ParticipantConstants, Participant, Pageable, Page, Order, OffsetPageable, NullHandling, KinoticSingleton, KinoticPlugin, Kinotic, JsonEventFactory, IterablePage, Identifiable, IWebSocket, IServiceRegistry, IServiceProxy, IParticipant, IKinotic, IEventFactory, IEventBus, IEvent, IEditableDataSource, IDataSource, ICrudServiceProxyFactory, ICrudServiceProxy, FunctionalIterablePage, EventConstants, EventBus, Event, EnvCredentialsResolver, Direction, DefaultCRI, DataSourceUtils, CursorPageable, CrudServiceProxyFactory, CrudServiceProxy, CredentialsResolver, ContextInterceptor, Context, ConnectedInfo, ConnectOptions, ChainedCredentialsResolver, CRI, BearerCredentialsResolver, BasicCredentialsResolver, AuthorizationException, AbstractIterablePage };
package/dist/index.js CHANGED
@@ -1181,7 +1181,7 @@ import opentelemetry, { context as context2, propagation as propagation2, trace,
1181
1181
  // packages/core/package.json
1182
1182
  var package_default = {
1183
1183
  name: "@kinotic-ai/core",
1184
- version: "5.0.0-beta.24",
1184
+ version: "5.0.0-beta.25",
1185
1185
  type: "module",
1186
1186
  files: [
1187
1187
  "dist"
@@ -1250,6 +1250,7 @@ var package_default = {
1250
1250
  vitest: "^4.1.4"
1251
1251
  },
1252
1252
  dependencies: {
1253
+ "@kinotic-ai/idl": "workspace:^",
1253
1254
  "@opentelemetry/api": "^1.9.1",
1254
1255
  "@opentelemetry/semantic-conventions": "^1.40.0",
1255
1256
  "@stomp/rx-stomp": "^2.4.0",
@@ -1643,10 +1644,59 @@ class TextEventFactory {
1643
1644
  return event;
1644
1645
  }
1645
1646
  }
1647
+ var APPLICATION_SERVICE_DIRECTORY = "app-api~org.kinotic.app.api.services.ApplicationServiceDirectory";
1648
+ var APPLICATION_ZONE = /^app\.[^.]+\.([^.]+)(\.|$)/;
1649
+ var declaredDefinitions = new Map;
1650
+ function declareServiceDefinitions(definitions) {
1651
+ for (const definition of definitions) {
1652
+ declaredDefinitions.set(qualifiedNameOf(definition.namespace, definition.name), definition);
1653
+ }
1654
+ }
1655
+ function qualifiedNameOf(namespace, name) {
1656
+ return namespace ? `${namespace}.${name}` : name;
1657
+ }
1658
+ function servedFunctions(serviceInstance) {
1659
+ const ret = new Set;
1660
+ let proto = Object.getPrototypeOf(serviceInstance);
1661
+ while (proto && proto !== Object.prototype) {
1662
+ for (const key of Object.getOwnPropertyNames(proto)) {
1663
+ const descriptor = Object.getOwnPropertyDescriptor(proto, key);
1664
+ if (typeof descriptor?.value === "function" && key !== "constructor") {
1665
+ ret.add(key);
1666
+ }
1667
+ }
1668
+ proto = Object.getPrototypeOf(proto);
1669
+ }
1670
+ return [...ret].sort();
1671
+ }
1672
+ function directoryEntryOf(serviceInstance, serviceIdentifier) {
1673
+ let ret = null;
1674
+ const application = serviceIdentifier.zone ? APPLICATION_ZONE.exec(serviceIdentifier.zone) : null;
1675
+ if (application) {
1676
+ const qualifiedName = qualifiedNameOf(serviceIdentifier.namespace, serviceIdentifier.name);
1677
+ const definition = declaredDefinitions.get(qualifiedName);
1678
+ if (definition) {
1679
+ const declared = definition.functions.map((f) => f.name).sort();
1680
+ const served = servedFunctions(serviceInstance);
1681
+ if (declared.join() !== served.join()) {
1682
+ throw new Error(`${qualifiedName} serves the functions [${served}] but its definition declares [${declared}];` + " run kinotic sync and import the generated ServiceDefinitions module");
1683
+ }
1684
+ ret = {
1685
+ applicationId: application[1],
1686
+ zone: serviceIdentifier.zone,
1687
+ version: serviceIdentifier.version ?? null,
1688
+ advertised: isAdvertised(serviceInstance),
1689
+ serviceDefinition: definition
1690
+ };
1691
+ }
1692
+ }
1693
+ return ret;
1694
+ }
1646
1695
 
1647
1696
  class ServiceRegistry {
1648
1697
  _eventBus;
1649
1698
  supervisors = new Map;
1699
+ entries = new Map;
1650
1700
  contextInterceptor = null;
1651
1701
  debugLogger = debug3("kinotic:serviceRegistry");
1652
1702
  constructor(eventBus) {
@@ -1668,9 +1718,16 @@ class ServiceRegistry {
1668
1718
  const criString = serviceIdentifier.cri().raw();
1669
1719
  if (!this.supervisors.has(criString)) {
1670
1720
  this.debugLogger(`Registering service for CRI: ${criString}`);
1721
+ const entry = directoryEntryOf(service, serviceIdentifier);
1671
1722
  const supervisor = new ServiceInvocationSupervisor(serviceIdentifier, service, this.eventBus, () => this.contextInterceptor);
1672
1723
  this.supervisors.set(criString, supervisor);
1673
1724
  supervisor.start();
1725
+ if (entry) {
1726
+ this.entries.set(criString, entry);
1727
+ if (this.eventBus.isConnected()) {
1728
+ this.registerEntry(entry).catch((error) => this.debugLogger(`Failed to register ${criString} in the directory`, error));
1729
+ }
1730
+ }
1674
1731
  }
1675
1732
  }
1676
1733
  unRegister(serviceIdentifier) {
@@ -1680,8 +1737,18 @@ class ServiceRegistry {
1680
1737
  this.debugLogger(`Unregistering service for CRI: ${criString}`);
1681
1738
  supervisor.stop();
1682
1739
  this.supervisors.delete(criString);
1740
+ this.entries.delete(criString);
1741
+ }
1742
+ }
1743
+ async registerEntries() {
1744
+ for (const entry of this.entries.values()) {
1745
+ await this.registerEntry(entry);
1683
1746
  }
1684
1747
  }
1748
+ async registerEntry(entry) {
1749
+ this.debugLogger(`Registering ${entry.zone}~${qualifiedNameOf(entry.serviceDefinition.namespace, entry.serviceDefinition.name)} in the directory`);
1750
+ await this.serviceProxy(APPLICATION_SERVICE_DIRECTORY).invoke("register", [entry]);
1751
+ }
1685
1752
  registerContextInterceptor(interceptor) {
1686
1753
  this.contextInterceptor = interceptor;
1687
1754
  }
@@ -1773,8 +1840,10 @@ class KinoticSingleton {
1773
1840
  this._eventBus = eventBus;
1774
1841
  this.serviceRegistry.eventBus = eventBus;
1775
1842
  }
1776
- connect(options) {
1777
- return this._eventBus.connect(Util.resolveConnectOptions(options));
1843
+ async connect(options) {
1844
+ const ret = await this._eventBus.connect(Util.resolveConnectOptions(options));
1845
+ await this.serviceRegistry.registerEntries();
1846
+ return ret;
1778
1847
  }
1779
1848
  disconnect(force) {
1780
1849
  return this._eventBus.disconnect(force);
@@ -2046,6 +2115,7 @@ export {
2046
2115
  scopeOptionalMethodNames,
2047
2116
  receivesContext,
2048
2117
  isAdvertised,
2118
+ declareServiceDefinitions,
2049
2119
  createCRI,
2050
2120
  buildServerUrl,
2051
2121
  buildBrokerUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinotic-ai/core",
3
- "version": "5.0.0-beta.24",
3
+ "version": "5.0.0-beta.25",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -69,6 +69,7 @@
69
69
  "vitest": "^4.1.4"
70
70
  },
71
71
  "dependencies": {
72
+ "@kinotic-ai/idl": "^5.0.0-beta.5",
72
73
  "@opentelemetry/api": "^1.9.1",
73
74
  "@opentelemetry/semantic-conventions": "^1.40.0",
74
75
  "@stomp/rx-stomp": "^2.4.0",