@rkat/mobkit-sdk 0.4.9

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 (82) hide show
  1. package/dist/agent-builder.d.ts +44 -0
  2. package/dist/agent-builder.d.ts.map +1 -0
  3. package/dist/agent-builder.js +111 -0
  4. package/dist/agent-builder.js.map +1 -0
  5. package/dist/builder.d.ts +74 -0
  6. package/dist/builder.d.ts.map +1 -0
  7. package/dist/builder.js +145 -0
  8. package/dist/builder.js.map +1 -0
  9. package/dist/cjs/agent-builder.cjs +114 -0
  10. package/dist/cjs/builder.cjs +182 -0
  11. package/dist/cjs/client.cjs +182 -0
  12. package/dist/cjs/config/auth.cjs +44 -0
  13. package/dist/cjs/config/index.cjs +51 -0
  14. package/dist/cjs/config/memory.cjs +28 -0
  15. package/dist/cjs/config/session-store.cjs +41 -0
  16. package/dist/cjs/errors.cjs +82 -0
  17. package/dist/cjs/events.cjs +176 -0
  18. package/dist/cjs/helpers.cjs +72 -0
  19. package/dist/cjs/index.cjs +130 -0
  20. package/dist/cjs/models.cjs +124 -0
  21. package/dist/cjs/runtime.cjs +476 -0
  22. package/dist/cjs/sse.cjs +79 -0
  23. package/dist/cjs/transport.cjs +282 -0
  24. package/dist/cjs/types.cjs +376 -0
  25. package/dist/client.d.ts +79 -0
  26. package/dist/client.d.ts.map +1 -0
  27. package/dist/client.js +178 -0
  28. package/dist/client.js.map +1 -0
  29. package/dist/config/auth.d.ts +28 -0
  30. package/dist/config/auth.d.ts.map +1 -0
  31. package/dist/config/auth.js +39 -0
  32. package/dist/config/auth.js.map +1 -0
  33. package/dist/config/index.d.ts +16 -0
  34. package/dist/config/index.d.ts.map +1 -0
  35. package/dist/config/index.js +16 -0
  36. package/dist/config/index.js.map +1 -0
  37. package/dist/config/memory.d.ts +16 -0
  38. package/dist/config/memory.d.ts.map +1 -0
  39. package/dist/config/memory.js +25 -0
  40. package/dist/config/memory.js.map +1 -0
  41. package/dist/config/session-store.d.ts +23 -0
  42. package/dist/config/session-store.d.ts.map +1 -0
  43. package/dist/config/session-store.js +36 -0
  44. package/dist/config/session-store.js.map +1 -0
  45. package/dist/errors.d.ts +48 -0
  46. package/dist/errors.d.ts.map +1 -0
  47. package/dist/errors.js +74 -0
  48. package/dist/errors.js.map +1 -0
  49. package/dist/events.d.ts +126 -0
  50. package/dist/events.d.ts.map +1 -0
  51. package/dist/events.js +164 -0
  52. package/dist/events.js.map +1 -0
  53. package/dist/helpers.d.ts +58 -0
  54. package/dist/helpers.d.ts.map +1 -0
  55. package/dist/helpers.js +62 -0
  56. package/dist/helpers.js.map +1 -0
  57. package/dist/index.cjs +2 -0
  58. package/dist/index.d.ts +48 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +49 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/models.d.ts +61 -0
  63. package/dist/models.d.ts.map +1 -0
  64. package/dist/models.js +118 -0
  65. package/dist/models.js.map +1 -0
  66. package/dist/runtime.d.ts +131 -0
  67. package/dist/runtime.d.ts.map +1 -0
  68. package/dist/runtime.js +470 -0
  69. package/dist/runtime.js.map +1 -0
  70. package/dist/sse.d.ts +21 -0
  71. package/dist/sse.d.ts.map +1 -0
  72. package/dist/sse.js +76 -0
  73. package/dist/sse.js.map +1 -0
  74. package/dist/transport.d.ts +84 -0
  75. package/dist/transport.d.ts.map +1 -0
  76. package/dist/transport.js +275 -0
  77. package/dist/transport.js.map +1 -0
  78. package/dist/types.d.ts +209 -0
  79. package/dist/types.d.ts.map +1 -0
  80. package/dist/types.js +348 -0
  81. package/dist/types.js.map +1 -0
  82. package/package.json +34 -0
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ /**
3
+ * MobKit builder chain — chainable configuration for the runtime.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { MobKit } from "@rkat/mobkit-sdk";
8
+ *
9
+ * const rt = await MobKit.builder()
10
+ * .mob("config/mob.toml")
11
+ * .sessionService(builder, store)
12
+ * .discovery(discoverFn)
13
+ * .build();
14
+ *
15
+ * const handle = rt.mobHandle();
16
+ * const status = await handle.status();
17
+ * ```
18
+ */
19
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
26
+ }) : (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ o[k2] = m[k];
29
+ }));
30
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
31
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
32
+ }) : function(o, v) {
33
+ o["default"] = v;
34
+ });
35
+ var __importStar = (this && this.__importStar) || (function () {
36
+ var ownKeys = function(o) {
37
+ ownKeys = Object.getOwnPropertyNames || function (o) {
38
+ var ar = [];
39
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
40
+ return ar;
41
+ };
42
+ return ownKeys(o);
43
+ };
44
+ return function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ })();
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.MobKit = exports.MobKitBuilder = void 0;
54
+ const node_fs_1 = require("node:fs");
55
+ function defaultConfig() {
56
+ return {
57
+ mobConfigPath: null,
58
+ sessionBuilder: null,
59
+ sessionStore: null,
60
+ discoveryCallback: null,
61
+ preSpawnCallback: null,
62
+ errorCallback: null,
63
+ eventLog: null,
64
+ gatingConfigPath: null,
65
+ routingConfigPath: null,
66
+ schedulingFiles: [],
67
+ memoryConfig: null,
68
+ authConfig: null,
69
+ gatewayBin: null,
70
+ modules: [],
71
+ };
72
+ }
73
+ // -- MobKitBuilder --------------------------------------------------------
74
+ /**
75
+ * Chainable builder for MobKit runtime configuration.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const rt = await MobKit.builder()
80
+ * .mob("config/mob.toml")
81
+ * .gateway("./target/release/phase0b_rpc_gateway")
82
+ * .build();
83
+ * ```
84
+ */
85
+ class MobKitBuilder {
86
+ /** @internal */
87
+ _config = defaultConfig();
88
+ mob(configPath) {
89
+ this._config.mobConfigPath = configPath;
90
+ return this;
91
+ }
92
+ sessionService(builder, store) {
93
+ this._config.sessionBuilder = builder;
94
+ this._config.sessionStore = store ?? null;
95
+ return this;
96
+ }
97
+ discovery(callback) {
98
+ this._config.discoveryCallback = callback;
99
+ return this;
100
+ }
101
+ preSpawn(callback) {
102
+ this._config.preSpawnCallback = callback;
103
+ return this;
104
+ }
105
+ eventLog(options) {
106
+ this._config.eventLog = { ...options };
107
+ return this;
108
+ }
109
+ onError(callback) {
110
+ this._config.errorCallback = callback;
111
+ return this;
112
+ }
113
+ gating(configPath) {
114
+ this._config.gatingConfigPath = configPath;
115
+ return this;
116
+ }
117
+ routing(configPath) {
118
+ this._config.routingConfigPath = configPath;
119
+ return this;
120
+ }
121
+ scheduling(...scheduleFiles) {
122
+ this._config.schedulingFiles = scheduleFiles;
123
+ return this;
124
+ }
125
+ memory(config, options) {
126
+ this._config.memoryConfig =
127
+ config ?? { stores: options?.stores ?? [] };
128
+ return this;
129
+ }
130
+ auth(config) {
131
+ this._config.authConfig = config;
132
+ return this;
133
+ }
134
+ gateway(binPath) {
135
+ this._config.gatewayBin = binPath;
136
+ return this;
137
+ }
138
+ modules(moduleSpecs) {
139
+ this._config.modules = moduleSpecs;
140
+ return this;
141
+ }
142
+ async build() {
143
+ this._applyConventionDefaults();
144
+ // Dynamic import to break circular dep (runtime imports from builder config type)
145
+ const { MobKitRuntime } = await Promise.resolve().then(() => __importStar(require("./runtime.cjs")));
146
+ return MobKitRuntime._create(this._config);
147
+ }
148
+ _applyConventionDefaults() {
149
+ if (this._config.gatingConfigPath === null) {
150
+ const candidate = "config/gating.toml";
151
+ if ((0, node_fs_1.existsSync)(candidate)) {
152
+ this._config.gatingConfigPath = candidate;
153
+ }
154
+ }
155
+ if (this._config.routingConfigPath === null) {
156
+ const candidate = "deployment/routing.toml";
157
+ if ((0, node_fs_1.existsSync)(candidate)) {
158
+ this._config.routingConfigPath = candidate;
159
+ }
160
+ }
161
+ if (this._config.schedulingFiles.length === 0) {
162
+ const files = [];
163
+ const defaultFile = "config/defaults/schedules.toml";
164
+ if ((0, node_fs_1.existsSync)(defaultFile))
165
+ files.push(defaultFile);
166
+ const overrideFile = "deployment/schedules.toml";
167
+ if ((0, node_fs_1.existsSync)(overrideFile))
168
+ files.push(overrideFile);
169
+ if (files.length > 0) {
170
+ this._config.schedulingFiles = files;
171
+ }
172
+ }
173
+ }
174
+ }
175
+ exports.MobKitBuilder = MobKitBuilder;
176
+ // -- MobKit static factory ------------------------------------------------
177
+ class MobKit {
178
+ static builder() {
179
+ return new MobKitBuilder();
180
+ }
181
+ }
182
+ exports.MobKit = MobKit;
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ /**
3
+ * Low-level JSON-RPC clients for MobKit.
4
+ *
5
+ * These are the original typed client classes preserved for backward
6
+ * compatibility. For new code, prefer the high-level {@link MobHandle} API
7
+ * via `runtime.mobHandle()`.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.MobkitAsyncClient = exports.MobkitTypedClient = void 0;
11
+ const errors_js_1 = require("./errors.cjs");
12
+ const transport_js_1 = require("./transport.cjs");
13
+ // -- Type guards ----------------------------------------------------------
14
+ function asValueObject(value) {
15
+ if (typeof value !== "object" || value === null)
16
+ return {};
17
+ return value;
18
+ }
19
+ function isStringArray(value) {
20
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
21
+ }
22
+ function isMobkitStatusResult(value) {
23
+ const o = asValueObject(value);
24
+ return (typeof o.contract_version === "string" &&
25
+ typeof o.running === "boolean" &&
26
+ isStringArray(o.loaded_modules));
27
+ }
28
+ function isMobkitCapabilitiesResult(value) {
29
+ const o = asValueObject(value);
30
+ return (typeof o.contract_version === "string" &&
31
+ isStringArray(o.methods) &&
32
+ isStringArray(o.loaded_modules));
33
+ }
34
+ function isMobkitReconcileResult(value) {
35
+ const o = asValueObject(value);
36
+ return (typeof o.accepted === "boolean" &&
37
+ isStringArray(o.reconciled_modules) &&
38
+ typeof o.added === "number" &&
39
+ Number.isInteger(o.added));
40
+ }
41
+ function isMobkitSpawnMemberResult(value) {
42
+ const o = asValueObject(value);
43
+ return typeof o.accepted === "boolean" && typeof o.module_id === "string";
44
+ }
45
+ function isMobkitSubscribeResult(value) {
46
+ const o = asValueObject(value);
47
+ if (o.scope !== "mob" && o.scope !== "agent" && o.scope !== "interaction") {
48
+ return false;
49
+ }
50
+ if (!(o.replay_from_event_id === null ||
51
+ typeof o.replay_from_event_id === "string")) {
52
+ return false;
53
+ }
54
+ const ka = asValueObject(o.keep_alive);
55
+ if (!Number.isInteger(ka.interval_ms) || typeof ka.event !== "string") {
56
+ return false;
57
+ }
58
+ if (typeof o.keep_alive_comment !== "string")
59
+ return false;
60
+ if (!isStringArray(o.event_frames))
61
+ return false;
62
+ if (!Array.isArray(o.events))
63
+ return false;
64
+ return o.events.every((ev) => {
65
+ const e = asValueObject(ev);
66
+ return (typeof e.event_id === "string" &&
67
+ typeof e.source === "string" &&
68
+ typeof e.timestamp_ms === "number" &&
69
+ Number.isInteger(e.timestamp_ms) &&
70
+ Object.prototype.hasOwnProperty.call(e, "event"));
71
+ });
72
+ }
73
+ // -- Response parsing -----------------------------------------------------
74
+ function parseJsonRpcResponse(payload, expectedId) {
75
+ if (typeof payload !== "object" || payload === null) {
76
+ throw new Error("invalid JSON-RPC response envelope");
77
+ }
78
+ const envelope = payload;
79
+ if (envelope.jsonrpc !== "2.0" || envelope.id !== expectedId) {
80
+ throw new Error("invalid JSON-RPC response envelope");
81
+ }
82
+ const hasResult = Object.prototype.hasOwnProperty.call(envelope, "result");
83
+ const hasError = Object.prototype.hasOwnProperty.call(envelope, "error");
84
+ if (hasResult === hasError) {
85
+ throw new Error("invalid JSON-RPC response envelope");
86
+ }
87
+ if (hasError) {
88
+ const rpcError = asValueObject(envelope.error);
89
+ if (!Number.isInteger(rpcError.code) ||
90
+ typeof rpcError.message !== "string") {
91
+ throw new Error("invalid JSON-RPC response envelope");
92
+ }
93
+ }
94
+ return envelope;
95
+ }
96
+ function unwrapTypedResult(response, requestId, method, isExpected) {
97
+ if ("error" in response && response.error) {
98
+ throw new errors_js_1.RpcError(response.error.code, response.error.message, requestId, method);
99
+ }
100
+ const result = response.result;
101
+ if (!isExpected(result)) {
102
+ throw new Error(`invalid result payload for ${method}`);
103
+ }
104
+ return result;
105
+ }
106
+ function buildSubscribeParams(params) {
107
+ const next = {};
108
+ if (params.scope !== undefined)
109
+ next.scope = params.scope;
110
+ if (params.last_event_id !== undefined) {
111
+ next.last_event_id = params.last_event_id;
112
+ }
113
+ if (params.agent_id !== undefined)
114
+ next.agent_id = params.agent_id;
115
+ return next;
116
+ }
117
+ // -- MobkitTypedClient (sync) ---------------------------------------------
118
+ class MobkitTypedClient {
119
+ gatewayBin;
120
+ syncTransport;
121
+ constructor(gatewayBin) {
122
+ this.gatewayBin = gatewayBin;
123
+ this.syncTransport = (0, transport_js_1.createGatewaySyncTransport)(gatewayBin);
124
+ }
125
+ rpc(id, method, params) {
126
+ const payload = this.syncTransport((0, transport_js_1.buildJsonRpcRequest)(id, method, params));
127
+ return parseJsonRpcResponse(payload, id);
128
+ }
129
+ status(requestId = "status") {
130
+ return unwrapTypedResult(this.rpc(requestId, "mobkit/status", {}), requestId, "mobkit/status", isMobkitStatusResult);
131
+ }
132
+ capabilities(requestId = "capabilities") {
133
+ return unwrapTypedResult(this.rpc(requestId, "mobkit/capabilities", {}), requestId, "mobkit/capabilities", isMobkitCapabilitiesResult);
134
+ }
135
+ reconcile(modules, requestId = "reconcile") {
136
+ return unwrapTypedResult(this.rpc(requestId, "mobkit/reconcile", { modules }), requestId, "mobkit/reconcile", isMobkitReconcileResult);
137
+ }
138
+ spawnMember(moduleId, requestId = "spawn_member") {
139
+ return unwrapTypedResult(this.rpc(requestId, "mobkit/spawn_member", { module_id: moduleId }), requestId, "mobkit/spawn_member", isMobkitSpawnMemberResult);
140
+ }
141
+ subscribeEvents(params = {}, requestId = "events_subscribe") {
142
+ return unwrapTypedResult(this.rpc(requestId, "mobkit/events/subscribe", buildSubscribeParams(params)), requestId, "mobkit/events/subscribe", isMobkitSubscribeResult);
143
+ }
144
+ }
145
+ exports.MobkitTypedClient = MobkitTypedClient;
146
+ // -- MobkitAsyncClient (async) --------------------------------------------
147
+ class MobkitAsyncClient {
148
+ transport;
149
+ constructor(transport) {
150
+ this.transport = transport;
151
+ }
152
+ static fromGatewayBin(gatewayBin) {
153
+ return new MobkitAsyncClient((0, transport_js_1.createGatewayAsyncTransport)(gatewayBin));
154
+ }
155
+ static fromHttp(endpoint, options = {}) {
156
+ return new MobkitAsyncClient((0, transport_js_1.createJsonRpcHttpTransport)(endpoint, options));
157
+ }
158
+ async rpc(id, method, params) {
159
+ const payload = await this.transport((0, transport_js_1.buildJsonRpcRequest)(id, method, params));
160
+ return parseJsonRpcResponse(payload, id);
161
+ }
162
+ async request(id, method, params, isExpected) {
163
+ const response = await this.rpc(id, method, params);
164
+ return unwrapTypedResult(response, id, method, isExpected);
165
+ }
166
+ async status(requestId = "status") {
167
+ return this.request(requestId, "mobkit/status", {}, isMobkitStatusResult);
168
+ }
169
+ async capabilities(requestId = "capabilities") {
170
+ return this.request(requestId, "mobkit/capabilities", {}, isMobkitCapabilitiesResult);
171
+ }
172
+ async reconcile(modules, requestId = "reconcile") {
173
+ return this.request(requestId, "mobkit/reconcile", { modules }, isMobkitReconcileResult);
174
+ }
175
+ async spawnMember(moduleId, requestId = "spawn_member") {
176
+ return this.request(requestId, "mobkit/spawn_member", { module_id: moduleId }, isMobkitSpawnMemberResult);
177
+ }
178
+ async subscribeEvents(params = {}, requestId = "events_subscribe") {
179
+ return this.request(requestId, "mobkit/events/subscribe", buildSubscribeParams(params), isMobkitSubscribeResult);
180
+ }
181
+ }
182
+ exports.MobkitAsyncClient = MobkitAsyncClient;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Auth configuration for MobKit runtime.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.google = google;
7
+ exports.googleAuthConfigToDict = googleAuthConfigToDict;
8
+ exports.jwt = jwt;
9
+ exports.jwtAuthConfigToDict = jwtAuthConfigToDict;
10
+ function google(clientId, options) {
11
+ return {
12
+ clientId,
13
+ discoveryUrl: options?.discoveryUrl ??
14
+ "https://accounts.google.com/.well-known/openid-configuration",
15
+ audience: options?.audience ?? null,
16
+ leewaySeconds: options?.leewaySeconds ?? 60,
17
+ };
18
+ }
19
+ function googleAuthConfigToDict(config) {
20
+ return {
21
+ provider: "google",
22
+ client_id: config.clientId,
23
+ discovery_url: config.discoveryUrl,
24
+ audience: config.audience ?? config.clientId,
25
+ leeway_seconds: config.leewaySeconds,
26
+ };
27
+ }
28
+ function jwt(sharedSecret, options) {
29
+ return {
30
+ sharedSecret,
31
+ issuer: options?.issuer ?? null,
32
+ audience: options?.audience ?? null,
33
+ leewaySeconds: options?.leewaySeconds ?? 60,
34
+ };
35
+ }
36
+ function jwtAuthConfigToDict(config) {
37
+ return {
38
+ provider: "jwt",
39
+ shared_secret: config.sharedSecret,
40
+ issuer: config.issuer,
41
+ audience: config.audience,
42
+ leeway_seconds: config.leewaySeconds,
43
+ };
44
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration modules for MobKit runtime.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { auth, memory, sessionStore } from "@rkat/mobkit-sdk";
8
+ *
9
+ * const authConfig = auth.google("my-client-id");
10
+ * const memConfig = memory.elephant("http://elephant:8080");
11
+ * const storeConfig = sessionStore.json("./sessions.json");
12
+ * ```
13
+ */
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.sessionStore = exports.memory = exports.auth = void 0;
49
+ exports.auth = __importStar(require("./auth.cjs"));
50
+ exports.memory = __importStar(require("./memory.cjs"));
51
+ exports.sessionStore = __importStar(require("./session-store.cjs"));
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * Memory backend configuration for MobKit runtime.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.elephant = elephant;
7
+ exports.elephantMemoryConfigToDict = elephantMemoryConfigToDict;
8
+ function elephant(endpoint, options) {
9
+ return {
10
+ endpoint,
11
+ spaceId: options?.spaceId ?? null,
12
+ collection: options?.collection ?? null,
13
+ stores: options?.stores ?? [],
14
+ };
15
+ }
16
+ function elephantMemoryConfigToDict(config) {
17
+ const result = {
18
+ backend: "elephant",
19
+ endpoint: config.endpoint,
20
+ };
21
+ if (config.spaceId)
22
+ result.space_id = config.spaceId;
23
+ if (config.collection)
24
+ result.collection = config.collection;
25
+ if (config.stores.length > 0)
26
+ result.stores = [...config.stores];
27
+ return result;
28
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * Session store configuration for MobKit runtime.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.json = json;
7
+ exports.jsonSessionStoreConfigToDict = jsonSessionStoreConfigToDict;
8
+ exports.bigquery = bigquery;
9
+ exports.bigquerySessionStoreConfigToDict = bigquerySessionStoreConfigToDict;
10
+ function json(path, options) {
11
+ return {
12
+ path,
13
+ staleLockThresholdSeconds: options?.staleLockThresholdSeconds ?? 30,
14
+ };
15
+ }
16
+ function jsonSessionStoreConfigToDict(config) {
17
+ return {
18
+ store: "json_file",
19
+ path: config.path,
20
+ stale_lock_threshold_seconds: config.staleLockThresholdSeconds,
21
+ };
22
+ }
23
+ function bigquery(dataset, table, options) {
24
+ return {
25
+ dataset,
26
+ table,
27
+ projectId: options?.projectId ?? null,
28
+ gcIntervalHours: options?.gcIntervalHours ?? 6,
29
+ };
30
+ }
31
+ function bigquerySessionStoreConfigToDict(config) {
32
+ const result = {
33
+ store: "bigquery",
34
+ dataset: config.dataset,
35
+ table: config.table,
36
+ gc_interval_hours: config.gcIntervalHours,
37
+ };
38
+ if (config.projectId)
39
+ result.project_id = config.projectId;
40
+ return result;
41
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /**
3
+ * Typed error hierarchy for the MobKit SDK.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { RpcError, MobKitError } from "@rkat/mobkit-sdk";
8
+ *
9
+ * try {
10
+ * await handle.status();
11
+ * } catch (err) {
12
+ * if (err instanceof RpcError) {
13
+ * console.error(`RPC ${err.method} failed: code=${err.code}`);
14
+ * }
15
+ * }
16
+ * ```
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.MobkitRpcError = exports.NotConnectedError = exports.ContractMismatchError = exports.CapabilityUnavailableError = exports.RpcError = exports.TransportError = exports.MobKitError = void 0;
20
+ // -- Base error -----------------------------------------------------------
21
+ /** Base exception for all MobKit SDK errors. */
22
+ class MobKitError extends Error {
23
+ constructor(message) {
24
+ super(message);
25
+ this.name = "MobKitError";
26
+ }
27
+ }
28
+ exports.MobKitError = MobKitError;
29
+ // -- Transport errors -----------------------------------------------------
30
+ /** Raised when the transport layer fails (subprocess died, connection refused, etc.). */
31
+ class TransportError extends MobKitError {
32
+ constructor(message) {
33
+ super(message);
34
+ this.name = "TransportError";
35
+ }
36
+ }
37
+ exports.TransportError = TransportError;
38
+ // -- RPC errors -----------------------------------------------------------
39
+ /** Raised when a JSON-RPC call returns an error response. */
40
+ class RpcError extends MobKitError {
41
+ code;
42
+ requestId;
43
+ method;
44
+ constructor(code, message, requestId, method) {
45
+ super(message);
46
+ this.code = code;
47
+ this.requestId = requestId;
48
+ this.method = method;
49
+ this.name = "RpcError";
50
+ }
51
+ }
52
+ exports.RpcError = RpcError;
53
+ // -- Capability errors ----------------------------------------------------
54
+ /** Raised when a requested capability is not available on the runtime. */
55
+ class CapabilityUnavailableError extends MobKitError {
56
+ constructor(message) {
57
+ super(message);
58
+ this.name = "CapabilityUnavailableError";
59
+ }
60
+ }
61
+ exports.CapabilityUnavailableError = CapabilityUnavailableError;
62
+ // -- Contract errors ------------------------------------------------------
63
+ /** Raised when the SDK and runtime contract versions are incompatible. */
64
+ class ContractMismatchError extends MobKitError {
65
+ constructor(message) {
66
+ super(message);
67
+ this.name = "ContractMismatchError";
68
+ }
69
+ }
70
+ exports.ContractMismatchError = ContractMismatchError;
71
+ // -- Connection errors ----------------------------------------------------
72
+ /** Raised when an operation requires a connected runtime but none is available. */
73
+ class NotConnectedError extends MobKitError {
74
+ constructor(message) {
75
+ super(message);
76
+ this.name = "NotConnectedError";
77
+ }
78
+ }
79
+ exports.NotConnectedError = NotConnectedError;
80
+ // -- Backward compatibility -----------------------------------------------
81
+ /** @deprecated Use {@link RpcError} instead. */
82
+ exports.MobkitRpcError = RpcError;