@multisetai/vps 1.0.7-beta.0 → 1.0.7-beta.2

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/README.md CHANGED
@@ -110,7 +110,7 @@ await controller.initialize();
110
110
  ### 4. Capture and localize
111
111
 
112
112
  ```typescript
113
- const result = await controller.captureFrame();
113
+ const result = await controller.localizeFrame();
114
114
  if (result?.localizeData?.poseFound) {
115
115
  console.log('Position:', result.localizeData.position);
116
116
  console.log('Rotation:', result.localizeData.rotation);
@@ -136,11 +136,14 @@ interface IMultisetSdkConfig {
136
136
  // Core
137
137
  clientId: string; // Your MultiSet client ID
138
138
  clientSecret: string; // Your MultiSet client secret
139
- code: string; // Map or map-set code (e.g., 'MAP_XXXXX')
140
- mapType: 'map' | 'map-set'; // Type of map to use
141
- endpoints?: Partial<IMultisetSdkEndpoints>; // Optional custom endpoints
142
- mapId?: string; // Optional map ID (overrides code-based lookup)
143
- mapSetId?: string; // Optional map-set ID (overrides code-based lookup)
139
+ /** Map or map-set code used for localization. */
140
+ code: string; // e.g., 'MAP_XXXXX'
141
+ /** Map or map-set type ('map' or 'map-set'). */
142
+ mapType: 'map' | 'map-set';
143
+ /** Override default API endpoints if needed. */
144
+ endpoints?: Partial<IMultisetSdkEndpoints>;
145
+ /** If true, show the VPS map mesh in the AR session (map-only). */
146
+ showMesh?: boolean;
144
147
 
145
148
  // Localization behavior
146
149
  /** If true, automatically start a localization run when the AR session starts. */
@@ -151,21 +154,16 @@ interface IMultisetSdkConfig {
151
154
  confidenceCheck?: boolean;
152
155
  /** Minimum confidence (0.2–0.8) required when confidenceCheck is enabled. */
153
156
  confidenceThreshold?: number;
154
- /** Total single-frame attempts per localization run (1–5). */
155
- requestAttempts?: number;
156
- /** Time in seconds between attempts in a localization run (1–5). */
157
- localizationInterval?: number;
158
157
  /** Include device geo pose as a hint in localization requests. */
159
158
  passGeoPose?: boolean;
160
159
  /** Request geo coordinates in the localization response (if supported by backend). */
161
160
  geoCoordinatesInResponse?: boolean;
161
+ /** Max time in ms to wait for a valid viewer pose before failing. Default: 10000. */
162
+ localizationTrackingTimeoutMs?: number;
162
163
 
163
164
  // Localization lifecycle callbacks
164
- /** Invoked at the start of a localization run. */
165
165
  onLocalizationInit?: () => void;
166
- /** Invoked after a successful localization that meets confidence criteria (if enabled). */
167
166
  onLocalizationSuccess?: (result: ILocalizeAndMapDetails) => void;
168
- /** Invoked when all attempts fail or the best result is below the confidence threshold. */
169
167
  onLocalizationFailure?: (reason?: string) => void;
170
168
 
171
169
  // Core callbacks
@@ -206,7 +204,7 @@ The client and controller emit events through callback functions:
206
204
 
207
205
  `MultisetClient` together with `WebxrController` supports a higher-level localization flow similar to the Unity SingleFrameLocalizationManager:
208
206
 
209
- - **Multiple attempts per run**: `requestAttempts` and `localizationInterval` control how many single-frame attempts are made and how long to wait between them.
207
+ - **Multiple attempts per run**: `localizeFrame` performs several internal single-frame attempts and picks the best result.
210
208
  - **Confidence-based acceptance**: When `confidenceCheck` is `true`, only results with `confidence >= confidenceThreshold` (0.2–0.8) are treated as successful.
211
209
  - **Auto-localize**: When `autoLocalize` is `true`, a localization run is started automatically when the AR session starts.
212
210
  - **Re-localize on tracking loss**: When `relocalization` is `true`, the controller automatically tries to re-localize after tracking has been lost for a short period.
@@ -250,24 +248,9 @@ const arButton = await controller.initialize(buttonContainer);
250
248
 
251
249
  **Returns**: The created AR button element.
252
250
 
253
- ##### `captureFrame(): Promise<ILocalizeAndMapDetails | null>`
254
-
255
- Captures the current camera frame and performs localization.
256
-
257
- ```typescript
258
- const result = await controller.captureFrame();
259
- if (result?.localizeData?.poseFound) {
260
- const { position, rotation, confidence } = result.localizeData;
261
- console.log('Localized at:', position);
262
- }
263
- ```
264
-
265
- **Returns**: Object with `localizeData` and optional `mapDetails`, or `null` if no pose is found or capture fails.
266
-
267
251
  ##### `localizeFrame(): Promise<ILocalizeAndMapDetails | null>`
268
252
 
269
- Runs a full localization cycle using the configured `requestAttempts`, `localizationInterval`,
270
- `confidenceCheck`, and `confidenceThreshold`:
253
+ Captures one frame from the active AR session and localizes against the configured map. Waits for a valid viewer pose up to `localizationTrackingTimeoutMs` before failing.
271
254
 
272
255
  ```typescript
273
256
  const result = await controller.localizeFrame();
@@ -279,7 +262,8 @@ if (result?.localizeData?.poseFound) {
279
262
  This method:
280
263
 
281
264
  - Fires `onLocalizationInit` at the start of the run
282
- - Performs multiple attempts and picks the best result by confidence
265
+ - Waits for a valid viewer pose (up to `localizationTrackingTimeoutMs`, default 10 s)
266
+ - Captures the camera frame and calls the localization API
283
267
  - Applies the confidence threshold when `confidenceCheck` is enabled
284
268
  - Calls `onLocalizationSuccess` or `onLocalizationFailure` accordingly
285
269
 
@@ -338,6 +322,7 @@ All TypeScript types are exported from the main entry points:
338
322
  // Core types
339
323
  import type {
340
324
  IMultisetSdkConfig,
325
+ IMultisetPublicConfig,
341
326
  IMultisetSdkEndpoints,
342
327
  IFrameCaptureEvent,
343
328
  ICameraIntrinsicsEvent,
@@ -378,8 +363,6 @@ const client = new MultisetClient({
378
363
  relocalization: true,
379
364
  confidenceCheck: true,
380
365
  confidenceThreshold: 0.5,
381
- requestAttempts: 3,
382
- localizationInterval: 2,
383
366
  passGeoPose: true,
384
367
  geoCoordinatesInResponse: true,
385
368
  onAuthorize: (token) => console.log('Authorized:', token),
@@ -408,7 +391,7 @@ cube.position.set(0, 0, -0.4);
408
391
  scene.add(cube);
409
392
 
410
393
  // Capture and localize
411
- const result = await controller.captureFrame();
394
+ const result = await controller.localizeFrame();
412
395
  if (result?.localizeData?.poseFound) {
413
396
  console.log('Position:', result.localizeData.position);
414
397
  }
@@ -463,7 +446,7 @@ export default function App() {
463
446
  };
464
447
 
465
448
  const handleCapture = async () => {
466
- const result = await controllerRef.current!.captureFrame();
449
+ const result = await controllerRef.current!.localizeFrame();
467
450
  if (result?.localizeData?.poseFound) {
468
451
  console.log('Localized!', result.localizeData.position);
469
452
  }
@@ -17,8 +17,11 @@ interface ILocalizeResponse {
17
17
  retrieval_scores: number[];
18
18
  num_matches: number[];
19
19
  confidence: number;
20
- retrieved_imgs: string[];
20
+ retreived_imgs: string[];
21
+ retrieved_imgs?: string[];
21
22
  mapIds: string[];
23
+ mapCodes: string[];
24
+ responseTime: number;
22
25
  }
23
26
  interface IMapLocation {
24
27
  type: string;
@@ -127,9 +130,9 @@ interface ILocalizeAndMapDetails {
127
130
  mapDetails?: IGetMapsDetailsResponse;
128
131
  }
129
132
 
133
+ /** The subset of config that is safe to expose publicly (no credentials). */
134
+ type IMultisetPublicConfig = Omit<IMultisetSdkConfig, 'clientId' | 'clientSecret'>;
130
135
  interface IMultisetSdkConfig {
131
- mapId?: string;
132
- mapSetId?: string;
133
136
  clientId: string;
134
137
  clientSecret: string;
135
138
  /** Map or map-set code used for localization. */
@@ -137,6 +140,8 @@ interface IMultisetSdkConfig {
137
140
  /** Map or map-set type ('map' or 'map-set'). */
138
141
  mapType: MapType;
139
142
  endpoints?: Partial<IMultisetSdkEndpoints>;
143
+ /** If true, show the mesh in the AR session. Default is false. */
144
+ showMesh?: boolean;
140
145
  /** If true, automatically start a localization run when the AR session starts. */
141
146
  autoLocalize?: boolean;
142
147
  /** If true, automatically re-localize when tracking is lost and then recovered. */
@@ -153,6 +158,8 @@ interface IMultisetSdkConfig {
153
158
  passGeoPose?: boolean;
154
159
  /** Request geo coordinates in the localization response (if supported by backend). */
155
160
  geoCoordinatesInResponse?: boolean;
161
+ /** Max time in ms to wait for a valid viewer pose before failing. Default 10000. */
162
+ localizationTrackingTimeoutMs?: number;
156
163
  /** Invoked at the start of a localization run. */
157
164
  onLocalizationInit?: () => void;
158
165
  /** Invoked after a successful localization that meets confidence criteria (if enabled). */
@@ -214,12 +221,15 @@ interface ILocalizeResultEvent {
214
221
  declare const DEFAULT_ENDPOINTS: IMultisetSdkEndpoints;
215
222
 
216
223
  declare class MultisetClient {
224
+ private readonly credentials;
217
225
  private readonly config;
218
226
  private readonly endpoints;
219
227
  private accessToken;
220
- constructor(config: IMultisetSdkConfig);
228
+ private mapDetailsCache;
229
+ constructor(input: IMultisetSdkConfig);
221
230
  get token(): string | null;
222
- getConfig(): IMultisetSdkConfig;
231
+ getConfig(): IMultisetPublicConfig;
232
+ downloadFile(key: string): Promise<string>;
223
233
  authorize(): Promise<string>;
224
234
  private handleError;
225
235
  localizeWithFrame(frame: IFrameCaptureEvent, intrinsics: ICameraIntrinsicsEvent): Promise<ILocalizeAndMapDetails | null>;
@@ -229,4 +239,4 @@ declare class MultisetClient {
229
239
  private fetchMapSetDetails;
230
240
  }
231
241
 
232
- export { DEFAULT_ENDPOINTS, type ICameraIntrinsicsEvent, type IFrameCaptureEvent, type IGetMapsDetailsResponse, type ILocalizeAndMapDetails, type ILocalizeResponse, type ILocalizeResultEvent, type IMapSetMapsResponse, type IMultisetSdkConfig as IMultisetClientOptions, type IMultisetSdkConfig, type IMultisetSdkEndpoints, type IPoseResultEvent, type MapType, MultisetClient };
242
+ export { DEFAULT_ENDPOINTS, type ICameraIntrinsicsEvent, type IFrameCaptureEvent, type IGetMapsDetailsResponse, type ILocalizeAndMapDetails, type ILocalizeResponse, type ILocalizeResultEvent, type IMapSetMapsResponse, type IMultisetSdkConfig as IMultisetClientOptions, type IMultisetPublicConfig, type IMultisetSdkConfig, type IMultisetSdkEndpoints, type IPoseResultEvent, type MapType, MultisetClient };
@@ -9,13 +9,15 @@ var DEFAULT_ENDPOINTS = {
9
9
  fileDownloadUrl: "https://api.multiset.ai/v1/file"
10
10
  };
11
11
  var MultisetClient = class {
12
- constructor(config) {
13
- this.config = config;
12
+ constructor(input) {
14
13
  this.accessToken = null;
15
- this.config = config;
14
+ this.mapDetailsCache = {};
15
+ const { clientId, clientSecret, ...rest } = input;
16
+ this.credentials = { clientId, clientSecret };
17
+ this.config = rest;
16
18
  this.endpoints = {
17
19
  ...DEFAULT_ENDPOINTS,
18
- ...config.endpoints
20
+ ...rest.endpoints
19
21
  };
20
22
  }
21
23
  get token() {
@@ -24,6 +26,25 @@ var MultisetClient = class {
24
26
  getConfig() {
25
27
  return this.config;
26
28
  }
29
+ async downloadFile(key) {
30
+ if (!this.accessToken || !key) {
31
+ return "";
32
+ }
33
+ try {
34
+ const response = await axios.get(
35
+ `${this.endpoints.fileDownloadUrl}?key=${encodeURIComponent(key)}`,
36
+ {
37
+ headers: {
38
+ Authorization: `Bearer ${this.accessToken}`
39
+ }
40
+ }
41
+ );
42
+ return response.status === 200 ? response.data.url : "";
43
+ } catch (error) {
44
+ this.handleError(error);
45
+ return "";
46
+ }
47
+ }
27
48
  async authorize() {
28
49
  var _a, _b, _c, _d, _e;
29
50
  try {
@@ -32,8 +53,8 @@ var MultisetClient = class {
32
53
  {},
33
54
  {
34
55
  auth: {
35
- username: this.config.clientId,
36
- password: this.config.clientSecret
56
+ username: this.credentials.clientId,
57
+ password: this.credentials.clientSecret
37
58
  }
38
59
  }
39
60
  );
@@ -85,16 +106,14 @@ var MultisetClient = class {
85
106
  });
86
107
  const { latitude, longitude, altitude } = position.coords;
87
108
  const safeAltitude = typeof altitude === "number" && !Number.isNaN(altitude) ? altitude : 0;
88
- return [latitude, longitude, safeAltitude];
109
+ return { latitude, longitude, altitude: safeAltitude };
89
110
  } catch {
90
111
  return null;
91
112
  }
92
113
  }
93
114
  async queryLocalization(frame, intrinsics) {
94
- var _a, _b, _c;
115
+ var _a;
95
116
  const formData = new FormData();
96
- formData.append("mapId", (_a = this.config.mapId) != null ? _a : "");
97
- formData.append("mapSetId", (_b = this.config.mapSetId) != null ? _b : "");
98
117
  if (this.config.mapType === "map") {
99
118
  formData.append("mapCode", this.config.code);
100
119
  } else {
@@ -114,7 +133,7 @@ var MultisetClient = class {
114
133
  if (this.config.passGeoPose) {
115
134
  const components = await this.getGeoPoseComponents();
116
135
  if (components) {
117
- const [latitude, longitude, altitude] = components;
136
+ const { latitude, longitude, altitude } = components;
118
137
  const geoHint = `${latitude},${longitude},${altitude}`;
119
138
  formData.append("geoHint", geoHint);
120
139
  }
@@ -136,10 +155,17 @@ var MultisetClient = class {
136
155
  const result = {
137
156
  localizeData: data
138
157
  };
139
- if ((_c = data.mapIds) == null ? void 0 : _c.length) {
140
- const mapDetails = await this.fetchMapDetails(data.mapIds[0]);
141
- if (mapDetails) {
142
- result.mapDetails = mapDetails;
158
+ if (this.config.showMesh && this.config.mapType === "map" && ((_a = data.mapCodes) == null ? void 0 : _a.length)) {
159
+ const mapCode = data.mapCodes[0];
160
+ const cached = this.mapDetailsCache[mapCode];
161
+ if (cached) {
162
+ result.mapDetails = cached;
163
+ } else {
164
+ const mapDetails = await this.fetchMapDetails(mapCode);
165
+ if (mapDetails) {
166
+ this.mapDetailsCache[mapCode] = mapDetails;
167
+ result.mapDetails = mapDetails;
168
+ }
143
169
  }
144
170
  }
145
171
  return result;
@@ -148,10 +174,10 @@ var MultisetClient = class {
148
174
  return null;
149
175
  }
150
176
  }
151
- async fetchMapDetails(mapId) {
177
+ async fetchMapDetails(mapCode) {
152
178
  try {
153
179
  const response = await axios.get(
154
- `${this.endpoints.mapDetailsUrl}${mapId}`,
180
+ `${this.endpoints.mapDetailsUrl}${mapCode}`,
155
181
  {
156
182
  headers: {
157
183
  Authorization: `Bearer ${this.accessToken}`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/core/config.ts","../../src/lib/core/client.ts"],"names":[],"mappings":";;;AA+FO,IAAM,iBAAA,GAA2C;AAAA,EACtD,OAAA,EAAS,sCAAA;AAAA,EACT,QAAA,EAAU,+CAAA;AAAA,EACV,aAAA,EAAe,qCAAA;AAAA,EACf,gBAAA,EAAkB,yCAAA;AAAA,EAClB,eAAA,EAAiB;AACnB;ACtFO,IAAM,iBAAN,MAAqB;AAAA,EAI1B,YAA6B,MAAA,EAA4B;AAA5B,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAF7B,IAAA,IAAA,CAAQ,WAAA,GAA6B,IAAA;AAGnC,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,SAAA,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AAA,CAAO,UAAA,GAAa,UAAA;AAAA,QACtB;AAAA,MACF;AAEA,MAAA,OAAO,MAAA;AAAA,IACT,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,YAAY,KAAK,CAAA;AACtB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAc,gBAAgB,KAAA,EAAwD;AACpF,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA;AAAA,QAC3B,CAAA,EAAG,IAAA,CAAK,SAAA,CAAU,aAAa,GAAG,KAAK,CAAA,CAAA;AAAA,QACvC;AAAA,UACE,OAAA,EAAS;AAAA,YACP,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK,WAAW,CAAA;AAAA;AAC3C;AACF,OACF;AACA,MAAA,OAAO,QAAA,CAAS,IAAA;AAAA,IAClB,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,YAAY,KAAK,CAAA;AACtB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAc,mBAAmB,QAAA,EAAuD;AACtF,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA;AAAA,QAC3B,CAAA,EAAG,IAAA,CAAK,SAAA,CAAU,gBAAgB,GAAG,QAAQ,CAAA,CAAA;AAAA,QAC7C;AAAA,UACE,OAAA,EAAS;AAAA,YACP,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK,WAAW,CAAA;AAAA;AAC3C;AACF,OACF;AACA,MAAA,OAAO,QAAA,CAAS,IAAA;AAAA,IAClB,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,YAAY,KAAK,CAAA;AACtB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { ILocalizeAndMapDetails, MapType } from './types';\n\nexport interface IMultisetSdkConfig {\n mapId?: string;\n mapSetId?: string;\n clientId: string;\n clientSecret: string;\n /** Map or map-set code used for localization. */\n code: string;\n /** Map or map-set type ('map' or 'map-set'). */\n mapType: MapType;\n endpoints?: Partial<IMultisetSdkEndpoints>;\n\n /** If true, automatically start a localization run when the AR session starts. */\n autoLocalize?: boolean;\n /** If true, automatically re-localize when tracking is lost and then recovered. */\n relocalization?: boolean;\n /** When enabled, only accept a localization result if confidence >= confidenceThreshold. */\n confidenceCheck?: boolean;\n /** Minimum confidence (0.2–0.8) required when confidenceCheck is enabled. */\n confidenceThreshold?: number;\n /** Total single-frame attempts per localization run (1–5). */\n requestAttempts?: number;\n /** Time in seconds between attempts in a localization run (1–5). */\n localizationInterval?: number;\n /** Include device geo pose as a hint in localization requests. */\n passGeoPose?: boolean;\n /** Request geo coordinates in the localization response (if supported by backend). */\n geoCoordinatesInResponse?: boolean;\n\n /** Invoked at the start of a localization run. */\n onLocalizationInit?: () => void;\n /** Invoked after a successful localization that meets confidence criteria (if enabled). */\n onLocalizationSuccess?: (result: ILocalizeAndMapDetails) => void;\n /** Invoked when all attempts fail or the best result is below the confidence threshold. */\n onLocalizationFailure?: (reason?: string) => void;\n\n /** Called after a successful authorization with the access token. */\n onAuthorize?: (token: string) => void;\n /** Called whenever a camera frame is captured and sent for localization. */\n onFrameCaptured?: (payload: IFrameCaptureEvent) => void;\n /** Called with the camera intrinsics used for a localization request. */\n onCameraIntrinsics?: (intrinsics: ICameraIntrinsicsEvent) => void;\n /** Called with the raw pose/localization result returned by the backend. */\n onPoseResult?: (payload: IPoseResultEvent) => void;\n /** Called when any error occurs during authorization or localization. */\n onError?: (error: unknown) => void;\n}\n\nexport interface IMultisetSdkEndpoints {\n authUrl: string;\n queryUrl: string;\n mapDetailsUrl: string;\n fileDownloadUrl: string;\n mapSetDetailsUrl: string;\n}\n\nexport interface IFrameCaptureEvent {\n blob: Blob;\n width: number;\n height: number;\n}\n\nexport interface ICameraIntrinsicsEvent {\n fx: number;\n fy: number;\n px: number;\n py: number;\n width: number;\n height: number;\n}\n\nexport interface IPoseResultEvent {\n poseFound: boolean;\n position: {\n x: number;\n y: number;\n z: number;\n };\n rotation: {\n x: number;\n y: number;\n z: number;\n w: number;\n };\n mapIds: string[];\n confidence?: number;\n}\n\nexport interface ILocalizeResultEvent {\n frame: IFrameCaptureEvent;\n intrinsics: ICameraIntrinsicsEvent;\n response: ILocalizeAndMapDetails | null;\n}\n\nexport const DEFAULT_ENDPOINTS: IMultisetSdkEndpoints = {\n authUrl: 'https://api.multiset.ai/v1/m2m/token',\n queryUrl: 'https://api.multiset.ai/v1/vps/map/query-form',\n mapDetailsUrl: 'https://api.multiset.ai/v1/vps/map/',\n mapSetDetailsUrl: 'https://api.multiset.ai/v1/vps/map-set/',\n fileDownloadUrl: 'https://api.multiset.ai/v1/file',\n};\n","import axios, { AxiosError } from 'axios';\nimport type {\n IMultisetSdkConfig,\n IMultisetSdkEndpoints,\n IFrameCaptureEvent,\n ICameraIntrinsicsEvent,\n} from './config';\nimport { DEFAULT_ENDPOINTS } from './config';\nimport type {\n ILocalizeAndMapDetails,\n ILocalizeResponse,\n IGetMapsDetailsResponse,\n IMapSetMapsResponse,\n} from './types';\n\nexport class MultisetClient {\n private readonly endpoints: IMultisetSdkEndpoints;\n private accessToken: string | null = null;\n\n constructor(private readonly config: IMultisetSdkConfig) {\n this.config = config;\n this.endpoints = {\n ...DEFAULT_ENDPOINTS,\n ...config.endpoints,\n };\n }\n\n get token(): string | null {\n return this.accessToken;\n }\n\n getConfig(): IMultisetSdkConfig {\n return this.config;\n }\n\n async authorize(): Promise<string> {\n try {\n const response = await axios.post(\n this.endpoints.authUrl,\n {},\n {\n auth: {\n username: this.config.clientId,\n password: this.config.clientSecret,\n },\n }\n );\n\n const token: string | undefined =\n response.data?.token ?? response.data?.access_token;\n\n if (!token) {\n throw new Error('Authorization succeeded but no token was returned.');\n }\n\n this.accessToken = token;\n this.config.onAuthorize?.(token);\n return token;\n } catch (error) {\n this.handleError(error);\n throw error;\n }\n }\n\n private handleError(error: unknown): void {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n this.config.onError?.(axiosError);\n } else {\n this.config.onError?.(error);\n }\n }\n\n async localizeWithFrame(\n frame: IFrameCaptureEvent,\n intrinsics: ICameraIntrinsicsEvent\n ): Promise<ILocalizeAndMapDetails | null> {\n if (!this.accessToken) {\n throw new Error('Access token is missing. Call authorize() first.');\n }\n\n this.config.onFrameCaptured?.(frame);\n this.config.onCameraIntrinsics?.(intrinsics);\n\n const queryResult = await this.queryLocalization(frame, intrinsics);\n\n if (queryResult?.localizeData?.poseFound) {\n this.config.onPoseResult?.(queryResult.localizeData);\n }\n\n return queryResult;\n }\n\n private async getGeoPoseComponents(): Promise<\n [latitude: number, longitude: number, altitude: number] | null\n > {\n if (\n typeof navigator === 'undefined' ||\n !('geolocation' in navigator) ||\n !navigator.geolocation\n ) {\n return null;\n }\n\n try {\n const position = await new Promise<GeolocationPosition>((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(resolve, reject, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: 0,\n });\n });\n\n const { latitude, longitude, altitude } = position.coords;\n const safeAltitude =\n typeof altitude === 'number' && !Number.isNaN(altitude) ? altitude : 0.0;\n\n return [latitude, longitude, safeAltitude];\n } catch {\n return null;\n }\n }\n\n private async queryLocalization(\n frame: IFrameCaptureEvent,\n intrinsics: ICameraIntrinsicsEvent\n ): Promise<ILocalizeAndMapDetails | null> {\n const formData = new FormData();\n\n formData.append('mapId', this.config.mapId ?? '');\n formData.append('mapSetId', this.config.mapSetId ?? '');\n if (this.config.mapType === 'map') {\n formData.append('mapCode', this.config.code);\n } else {\n formData.append('mapSetCode', this.config.code);\n }\n formData.append('isRightHanded', 'true');\n formData.append('fx', `${intrinsics.fx}`);\n formData.append('fy', `${intrinsics.fy}`);\n formData.append('px', `${intrinsics.px}`);\n formData.append('py', `${intrinsics.py}`);\n formData.append('width', `${frame.width}`);\n formData.append('height', `${frame.height}`);\n formData.append('queryImage', frame.blob);\n if (this.config.geoCoordinatesInResponse) {\n formData.append('geoCoordinatesInResponse', 'true');\n }\n if (this.config.passGeoPose) {\n const components = await this.getGeoPoseComponents();\n if (components) {\n const [latitude, longitude, altitude] = components;\n const geoHint = `${latitude},${longitude},${altitude}`;\n formData.append('geoHint', geoHint);\n }\n }\n\n try {\n const response = await axios.post<ILocalizeResponse>(\n this.endpoints.queryUrl,\n formData,\n {\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n }\n );\n\n const data = response.data;\n if (!data.poseFound) {\n return null;\n }\n\n const result: ILocalizeAndMapDetails = {\n localizeData: data,\n };\n\n if (data.mapIds?.length) {\n const mapDetails = await this.fetchMapDetails(data.mapIds[0]);\n if (mapDetails) {\n result.mapDetails = mapDetails;\n }\n }\n\n return result;\n } catch (error) {\n this.handleError(error);\n return null;\n }\n }\n\n private async fetchMapDetails(mapId: string): Promise<IGetMapsDetailsResponse | null> {\n try {\n const response = await axios.get<IGetMapsDetailsResponse>(\n `${this.endpoints.mapDetailsUrl}${mapId}`,\n {\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n }\n );\n return response.data;\n } catch (error) {\n this.handleError(error);\n return null;\n }\n }\n\n private async fetchMapSetDetails(mapSetId: string): Promise<IMapSetMapsResponse | null> {\n try {\n const response = await axios.get<IMapSetMapsResponse>(\n `${this.endpoints.mapSetDetailsUrl}${mapSetId}`,\n {\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n }\n );\n return response.data;\n } catch (error) {\n this.handleError(error);\n return null;\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/lib/core/config.ts","../../src/lib/core/client.ts"],"names":[],"mappings":";;;AAmGO,IAAM,iBAAA,GAA2C;AAAA,EACtD,OAAA,EAAS,sCAAA;AAAA,EACT,QAAA,EAAU,+CAAA;AAAA,EACV,aAAA,EAAe,qCAAA;AAAA,EACf,gBAAA,EAAkB,yCAAA;AAAA,EAClB,eAAA,EAAiB;AACnB;ACzFO,IAAM,iB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K,YAAY,KAAK,CAAA;AACtB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAc,gBAAgB,OAAA,EAA0D;AACtF,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA;AAAA,QAC3B,CAAA,EAAG,IAAA,CAAK,SAAA,CAAU,aAAa,GAAG,OAAO,CAAA,CAAA;AAAA,QACzC;AAAA,UACE,OAAA,EAAS;AAAA,YACP,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK,WAAW,CAAA;AAAA;AAC3C;AACF,OACF;AACA,MAAA,OAAO,QAAA,CAAS,IAAA;AAAA,IAClB,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,YAAY,KAAK,CAAA;AACtB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAc,mBAAmB,QAAA,EAAuD;AACtF,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA;AAAA,QAC3B,CAAA,EAAG,IAAA,CAAK,SAAA,CAAU,gBAAgB,GAAG,QAAQ,CAAA,CAAA;AAAA,QAC7C;AAAA,UACE,OAAA,EAAS;AAAA,YACP,aAAA,EAAe,CAAA,OAAA,EAAU,IAAA,CAAK,WAAW,CAAA;AAAA;AAC3C;AACF,OACF;AACA,MAAA,OAAO,QAAA,CAAS,IAAA;AAAA,IAClB,SAAS,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,YAAY,KAAK,CAAA;AACtB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { ILocalizeAndMapDetails, MapType } from './types';\n\n/** The subset of config that is safe to expose publicly (no credentials). */\nexport type IMultisetPublicConfig = Omit<IMultisetSdkConfig, 'clientId' | 'clientSecret'>;\n\nexport interface IMultisetSdkConfig {\n clientId: string;\n clientSecret: string;\n /** Map or map-set code used for localization. */\n code: string;\n /** Map or map-set type ('map' or 'map-set'). */\n mapType: MapType;\n endpoints?: Partial<IMultisetSdkEndpoints>;\n /** If true, show the mesh in the AR session. Default is false. */\n showMesh?: boolean;\n /** If true, automatically start a localization run when the AR session starts. */\n autoLocalize?: boolean;\n /** If true, automatically re-localize when tracking is lost and then recovered. */\n relocalization?: boolean;\n /** When enabled, only accept a localization result if confidence >= confidenceThreshold. */\n confidenceCheck?: boolean;\n /** Minimum confidence (0.2–0.8) required when confidenceCheck is enabled. */\n confidenceThreshold?: number;\n /** Total single-frame attempts per localization run (1–5). */\n requestAttempts?: number;\n /** Time in seconds between attempts in a localization run (1–5). */\n localizationInterval?: number;\n /** Include device geo pose as a hint in localization requests. */\n passGeoPose?: boolean;\n /** Request geo coordinates in the localization response (if supported by backend). */\n geoCoordinatesInResponse?: boolean;\n /** Max time in ms to wait for a valid viewer pose before failing. Default 10000. */\n localizationTrackingTimeoutMs?: number;\n\n /** Invoked at the start of a localization run. */\n onLocalizationInit?: () => void;\n /** Invoked after a successful localization that meets confidence criteria (if enabled). */\n onLocalizationSuccess?: (result: ILocalizeAndMapDetails) => void;\n /** Invoked when all attempts fail or the best result is below the confidence threshold. */\n onLocalizationFailure?: (reason?: string) => void;\n\n /** Called after a successful authorization with the access token. */\n onAuthorize?: (token: string) => void;\n /** Called whenever a camera frame is captured and sent for localization. */\n onFrameCaptured?: (payload: IFrameCaptureEvent) => void;\n /** Called with the camera intrinsics used for a localization request. */\n onCameraIntrinsics?: (intrinsics: ICameraIntrinsicsEvent) => void;\n /** Called with the raw pose/localization result returned by the backend. */\n onPoseResult?: (payload: IPoseResultEvent) => void;\n /** Called when any error occurs during authorization or localization. */\n onError?: (error: unknown) => void;\n}\n\nexport interface IMultisetSdkEndpoints {\n authUrl: string;\n queryUrl: string;\n mapDetailsUrl: string;\n fileDownloadUrl: string;\n mapSetDetailsUrl: string;\n}\n\nexport interface IFrameCaptureEvent {\n blob: Blob;\n width: number;\n height: number;\n}\n\nexport interface ICameraIntrinsicsEvent {\n fx: number;\n fy: number;\n px: number;\n py: number;\n width: number;\n height: number;\n}\n\nexport interface IPoseResultEvent {\n poseFound: boolean;\n position: {\n x: number;\n y: number;\n z: number;\n };\n rotation: {\n x: number;\n y: number;\n z: number;\n w: number;\n };\n mapIds: string[];\n confidence?: number;\n}\n\nexport interface ILocalizeResultEvent {\n frame: IFrameCaptureEvent;\n intrinsics: ICameraIntrinsicsEvent;\n response: ILocalizeAndMapDetails | null;\n}\n\nexport const DEFAULT_ENDPOINTS: IMultisetSdkEndpoints = {\n authUrl: 'https://api.multiset.ai/v1/m2m/token',\n queryUrl: 'https://api.multiset.ai/v1/vps/map/query-form',\n mapDetailsUrl: 'https://api.multiset.ai/v1/vps/map/',\n mapSetDetailsUrl: 'https://api.multiset.ai/v1/vps/map-set/',\n fileDownloadUrl: 'https://api.multiset.ai/v1/file',\n};\n","import axios, { AxiosError } from 'axios';\nimport type {\n IMultisetSdkConfig,\n IMultisetPublicConfig,\n IMultisetSdkEndpoints,\n IFrameCaptureEvent,\n ICameraIntrinsicsEvent,\n} from './config';\nimport { DEFAULT_ENDPOINTS } from './config';\nimport type {\n ILocalizeAndMapDetails,\n ILocalizeResponse,\n IGetMapsDetailsResponse,\n IMapSetMapsResponse,\n} from './types';\n\nexport class MultisetClient {\n private readonly credentials: { clientId: string; clientSecret: string };\n private readonly config: IMultisetPublicConfig;\n private readonly endpoints: IMultisetSdkEndpoints;\n private accessToken: string | null = null;\n private mapDetailsCache: Record<string, IGetMapsDetailsResponse> = {};\n\n constructor(input: IMultisetSdkConfig) {\n const { clientId, clientSecret, ...rest } = input;\n this.credentials = { clientId, clientSecret };\n this.config = rest;\n this.endpoints = {\n ...DEFAULT_ENDPOINTS,\n ...rest.endpoints,\n };\n }\n\n get token(): string | null {\n return this.accessToken;\n }\n\n getConfig(): IMultisetPublicConfig {\n return this.config;\n }\n\n async downloadFile(key: string): Promise<string> {\n if (!this.accessToken || !key) {\n return '';\n }\n\n try {\n const response = await axios.get<{ url: string }>(\n `${this.endpoints.fileDownloadUrl}?key=${encodeURIComponent(key)}`,\n {\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n }\n );\n\n return response.status === 200 ? response.data.url : '';\n } catch (error) {\n this.handleError(error);\n return '';\n }\n }\n\n async authorize(): Promise<string> {\n try {\n const response = await axios.post(\n this.endpoints.authUrl,\n {},\n {\n auth: {\n username: this.credentials.clientId,\n password: this.credentials.clientSecret,\n },\n }\n );\n\n const token: string | undefined =\n response.data?.token ?? response.data?.access_token;\n\n if (!token) {\n throw new Error('Authorization succeeded but no token was returned.');\n }\n\n this.accessToken = token;\n this.config.onAuthorize?.(token);\n return token;\n } catch (error) {\n this.handleError(error);\n throw error;\n }\n }\n\n private handleError(error: unknown): void {\n if (axios.isAxiosError(error)) {\n const axiosError = error as AxiosError;\n this.config.onError?.(axiosError);\n } else {\n this.config.onError?.(error);\n }\n }\n\n async localizeWithFrame(\n frame: IFrameCaptureEvent,\n intrinsics: ICameraIntrinsicsEvent\n ): Promise<ILocalizeAndMapDetails | null> {\n if (!this.accessToken) {\n throw new Error('Access token is missing. Call authorize() first.');\n }\n\n this.config.onFrameCaptured?.(frame);\n this.config.onCameraIntrinsics?.(intrinsics);\n\n const queryResult = await this.queryLocalization(frame, intrinsics);\n\n if (queryResult?.localizeData?.poseFound) {\n this.config.onPoseResult?.(queryResult.localizeData);\n }\n\n return queryResult;\n }\n\n private async getGeoPoseComponents(): Promise<\n { latitude: number, longitude: number, altitude: number } | null\n > {\n if (\n typeof navigator === 'undefined' ||\n !('geolocation' in navigator) ||\n !navigator.geolocation\n ) {\n return null;\n }\n\n try {\n const position = await new Promise<GeolocationPosition>((resolve, reject) => {\n navigator.geolocation.getCurrentPosition(resolve, reject, {\n enableHighAccuracy: true,\n timeout: 10000,\n maximumAge: 0,\n });\n });\n\n const { latitude, longitude, altitude } = position.coords;\n const safeAltitude =\n typeof altitude === 'number' && !Number.isNaN(altitude) ? altitude : 0.0;\n\n return { latitude, longitude, altitude: safeAltitude };\n } catch {\n return null;\n }\n }\n\n private async queryLocalization(\n frame: IFrameCaptureEvent,\n intrinsics: ICameraIntrinsicsEvent\n ): Promise<ILocalizeAndMapDetails | null> {\n const formData = new FormData();\n\n if (this.config.mapType === 'map') {\n formData.append('mapCode', this.config.code);\n } else {\n formData.append('mapSetCode', this.config.code);\n }\n formData.append('isRightHanded', 'true');\n formData.append('fx', `${intrinsics.fx}`);\n formData.append('fy', `${intrinsics.fy}`);\n formData.append('px', `${intrinsics.px}`);\n formData.append('py', `${intrinsics.py}`);\n formData.append('width', `${frame.width}`);\n formData.append('height', `${frame.height}`);\n formData.append('queryImage', frame.blob);\n if (this.config.geoCoordinatesInResponse) {\n formData.append('geoCoordinatesInResponse', 'true');\n }\n if (this.config.passGeoPose) {\n const components = await this.getGeoPoseComponents();\n if (components) {\n const { latitude, longitude, altitude } = components;\n const geoHint = `${latitude},${longitude},${altitude}`;\n formData.append('geoHint', geoHint);\n }\n }\n\n try {\n const response = await axios.post<ILocalizeResponse>(\n this.endpoints.queryUrl,\n formData,\n {\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n }\n );\n\n const data = response.data;\n if (!data.poseFound) {\n return null;\n }\n\n const result: ILocalizeAndMapDetails = {\n localizeData: data,\n };\n\n if (\n this.config.showMesh &&\n this.config.mapType === 'map' &&\n data.mapCodes?.length\n ) {\n const mapCode = data.mapCodes[0];\n const cached = this.mapDetailsCache[mapCode];\n if (cached) {\n result.mapDetails = cached;\n } else {\n const mapDetails = await this.fetchMapDetails(mapCode);\n if (mapDetails) {\n this.mapDetailsCache[mapCode] = mapDetails;\n result.mapDetails = mapDetails;\n }\n }\n }\n\n return result;\n } catch (error) {\n this.handleError(error);\n return null;\n }\n }\n\n private async fetchMapDetails(mapCode: string): Promise<IGetMapsDetailsResponse | null> {\n try {\n const response = await axios.get<IGetMapsDetailsResponse>(\n `${this.endpoints.mapDetailsUrl}${mapCode}`,\n {\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n }\n );\n return response.data;\n } catch (error) {\n this.handleError(error);\n return null;\n }\n }\n\n private async fetchMapSetDetails(mapSetId: string): Promise<IMapSetMapsResponse | null> {\n try {\n const response = await axios.get<IMapSetMapsResponse>(\n `${this.endpoints.mapSetDetailsUrl}${mapSetId}`,\n {\n headers: {\n Authorization: `Bearer ${this.accessToken}`,\n },\n }\n );\n return response.data;\n } catch (error) {\n this.handleError(error);\n return null;\n }\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { DEFAULT_ENDPOINTS, ICameraIntrinsicsEvent, IFrameCaptureEvent, IGetMapsDetailsResponse, ILocalizeAndMapDetails, ILocalizeResponse, ILocalizeResultEvent, IMapSetMapsResponse, IMultisetSdkConfig as IMultisetClientOptions, IMultisetSdkConfig, IMultisetSdkEndpoints, IPoseResultEvent, MapType, MultisetClient } from './core/index.js';
1
+ export { DEFAULT_ENDPOINTS, ICameraIntrinsicsEvent, IFrameCaptureEvent, IGetMapsDetailsResponse, ILocalizeAndMapDetails, ILocalizeResponse, ILocalizeResultEvent, IMapSetMapsResponse, IMultisetClientOptions, IMultisetPublicConfig, IMultisetClientOptions as IMultisetSdkConfig, IMultisetSdkEndpoints, IPoseResultEvent, MapType, MultisetClient } from './core/index.js';
2
2
  export { IWebxrControllerOptions, WebxrController } from './webxr/index.js';
3
3
  import 'three';