@superblocksteam/library 2.0.93 → 2.0.94-next.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.
package/dist/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as consoleLogAttributes, t as early_console_buffer_default } from "../early-console-buffer-D4wVuyBf.js";
2
- import { A as useSuperblocksGroups, B as createManagedPropsList, C as addNewPromise, D as getAppMode, E as SuperblocksContextProvider, F as editorBridge, G as getEditStore, H as PropsCategory, I as iframeMessageHandler, L as isEmbeddedBySuperblocksFirstParty, M as useSuperblocksUser, N as sendNotification, O as useSuperblocksContext, P as colors$1, R as sendMessageImmediately, S as api_hmr_tracker_default, T as resolveById, U as Section, V as Prop, W as createPropertiesPanelDefinition, _ as root_store_default, a as FixWithClarkButton, b as createIframeSpan, c as ErrorContent, d as ErrorMessage$1, f as ErrorStack, g as StyledClarkIcon, h as SecondaryButton, i as getWidgetRectAnchorName, j as useSuperblocksProfiles, k as useSuperblocksDataTags, l as ErrorDetails, m as ErrorTitle, n as useJSXContext, o as ActionsContainer, p as ErrorSummary, r as getWidgetAnchorName, s as ErrorContainer, u as ErrorIconContainer, v as startEditorSync, w as rejectById, x as getContextFromTraceHeaders, y as generateId, z as isEditMode } from "../jsx-wrapper-C8LEtdzp.js";
2
+ import { A as useSuperblocksProfiles, B as createManagedPropsList, C as rejectById, D as useSuperblocksContext, E as getAppMode, F as editorBridge, G as getEditStore, H as PropsCategory, I as iframeMessageHandler, L as isEmbeddedBySuperblocksFirstParty, M as generateId, N as sendNotification, O as useSuperblocksDataTags, P as colors$1, R as sendMessageImmediately, S as addNewPromise, T as SuperblocksContextProvider, U as Section, V as Prop, W as createPropertiesPanelDefinition, _ as root_store_default, a as FixWithClarkButton, b as getContextFromTraceHeaders, c as ErrorContent, d as ErrorMessage$1, f as ErrorStack, g as StyledClarkIcon, h as SecondaryButton, i as getWidgetRectAnchorName, j as useSuperblocksUser, k as useSuperblocksGroups, l as ErrorDetails, m as ErrorTitle, n as useJSXContext, o as ActionsContainer, p as ErrorSummary, r as getWidgetAnchorName, s as ErrorContainer, u as ErrorIconContainer, v as startEditorSync, w as resolveById, x as api_hmr_tracker_default, y as createIframeSpan, z as isEditMode } from "../jsx-wrapper-DdcywsRY.js";
3
3
  import { n as initTracerProviderWithOrigin } from "../utils-BGEEeYie.js";
4
4
  import { action, autorun, computed, makeAutoObservable, makeObservable, observable, reaction, when } from "mobx";
5
5
  import { Dim, NATIVE_COMPONENT_TYPES, NO_SELECT_ATTRIBUTE, Property, Property as Property$1, SELECTOR_ID_ATTRIBUTE, SOURCE_ID_ATTRIBUTE, generateSourceId, getBindingIdentifier } from "@superblocksteam/library-shared";
@@ -890,6 +890,9 @@ const handleBootstrapResponse = (event) => {
890
890
  root_store_default.setSdkUser({ userId: event.data.payload.userId });
891
891
  } else console.log("[handle-bootstrap-response] No user info available for SDK API execution. Neither auth0 JWT nor userId was provided in the bootstrap payload.");
892
892
  root_store_default.apis.setTokens(event.data.payload.token, event.data.payload.accessToken);
893
+ if (event.data.payload.profile) root_store_default.setProfile(event.data.payload.profile);
894
+ if (event.data.payload.branchName) root_store_default.setBranchName(event.data.payload.branchName);
895
+ if (event.data.payload.commitId) root_store_default.setCommitId(event.data.payload.commitId);
893
896
  root_store_default.apis.notifyBootstrapComplete();
894
897
  const featureFlags = event.data.payload.featureFlags;
895
898
  if (featureFlags && root_store_default.editStore) {
@@ -1068,12 +1071,15 @@ function extractSdkApiMetadata(name, api, sourceCode) {
1068
1071
  let chunkSchema;
1069
1072
  if (streaming) chunkSchema = convertZodSchema(api.chunkSchema);
1070
1073
  else outputSchema = convertZodSchema(api.outputSchema);
1074
+ const entryPoint = "entryPoint" in api ? api.entryPoint : void 0;
1071
1075
  return {
1072
1076
  name,
1077
+ description: api.description,
1073
1078
  inputSchema,
1074
1079
  outputSchema,
1075
1080
  chunkSchema,
1076
1081
  isStreaming: streaming,
1082
+ entryPoint,
1077
1083
  integrations: (api.integrations ?? []).map((integration) => ({
1078
1084
  key: integration.key,
1079
1085
  pluginId: integration.pluginId,
@@ -1147,9 +1153,13 @@ function clearSdkApiRegistry() {
1147
1153
  *
1148
1154
  * Imports server/apis/index.ts (the same registry used by useApi for type
1149
1155
  * inference) and registers each exported API with the SDK API registry.
1156
+ *
1157
+ * Entry points are read from the `entryPoint` field on each CompiledApi,
1158
+ * which is injected automatically by the sdkApiEntryPointPlugin Vite plugin.
1150
1159
  */
1151
1160
  async function discoverAndRegisterSdkApis() {
1152
1161
  if (!root_store_default.sdkApiEnabled) return;
1162
+ if (!root_store_default.hasUnresolvedGate()) root_store_default.initDiscoveryGate();
1153
1163
  try {
1154
1164
  const apis = (await import(new URL("/server/apis/index.ts", window.location.origin).href)).default;
1155
1165
  const apiNames = Object.keys(apis);
@@ -1158,9 +1168,19 @@ async function discoverAndRegisterSdkApis() {
1158
1168
  return;
1159
1169
  }
1160
1170
  console.debug(`[sdk-api-discovery] Discovering ${apiNames.length} SDK APIs:`, apiNames);
1161
- const sourcePromises = apiNames.map(async (name) => {
1171
+ const sourcePromises = apiNames.map((name) => {
1172
+ const apiModule = apis[name];
1173
+ const ep = apiModule && "entryPoint" in apiModule ? apiModule.entryPoint : void 0;
1174
+ if (typeof ep !== "string") {
1175
+ console.error(`[sdk-api-discovery] API "${name}" has no entryPoint. Was the Vite plugin applied?`);
1176
+ return;
1177
+ }
1178
+ root_store_default.setApiEntryPoint(name, ep);
1179
+ return ep;
1180
+ }).map(async (ep) => {
1181
+ if (!ep) return void 0;
1162
1182
  try {
1163
- const resp = await fetch(`/sb-raw-source/server/apis/${name}/api.ts`);
1183
+ const resp = await fetch(`/sb-raw-source/${ep}`);
1164
1184
  return resp.ok ? await resp.text() : void 0;
1165
1185
  } catch {
1166
1186
  return;
@@ -1177,12 +1197,15 @@ async function discoverAndRegisterSdkApis() {
1177
1197
  console.debug(`[sdk-api-discovery] Registered ${succeeded} APIs, ${failed} failed`);
1178
1198
  } catch (error) {
1179
1199
  console.error("[sdk-api-discovery] Failed to discover SDK APIs:", error);
1200
+ } finally {
1201
+ root_store_default.notifyDiscoveryComplete();
1180
1202
  }
1181
1203
  }
1182
1204
  if (import.meta.hot) import.meta.hot.accept("/server/apis/index.ts", () => {
1183
1205
  if (!root_store_default.sdkApiEnabled) return;
1184
1206
  console.debug("[sdk-api-discovery] API registry updated via HMR, re-running discovery");
1185
1207
  clearSdkApiRegistry();
1208
+ root_store_default.clearApiEntryPoints();
1186
1209
  discoverAndRegisterSdkApis();
1187
1210
  });
1188
1211
 
@@ -1195,8 +1218,9 @@ if (import.meta.hot) import.meta.hot.accept("/server/apis/index.ts", () => {
1195
1218
  * new SDK-based API system (`useSdkApi`). The public `useApi` hook delegates
1196
1219
  * to one or the other based on the `sdkApiEnabled` feature flag on rootStore.
1197
1220
  *
1198
- * The flag is set once at bootstrap time and never changes within a session,
1199
- * so the conditional hook delegation is safe.
1221
+ * Delegation happens at RUN TIME (when run() is invoked), not render time,
1222
+ * so components that mount before bootstrap completes still use the SDK path
1223
+ * once the user triggers execution.
1200
1224
  */
1201
1225
  /**
1202
1226
  * Get the API path for an API by name.
@@ -1206,9 +1230,10 @@ if (import.meta.hot) import.meta.hot.accept("/server/apis/index.ts", () => {
1206
1230
  */
1207
1231
  const getApiPath = (name) => {
1208
1232
  if (root_store_default.sdkApiEnabled) {
1209
- let apiPath$1 = name;
1210
- if (!apiPath$1.startsWith("/server/apis")) apiPath$1 = `/server/apis/${name}/api.ts`;
1211
- return apiPath$1;
1233
+ if (name.startsWith("/")) return name;
1234
+ const registered$1 = root_store_default.getApiEntryPoint(name);
1235
+ if (!registered$1) throw new Error(`No entryPoint registered for API "${name}". Was it discovered?`);
1236
+ return `/${registered$1}`;
1212
1237
  }
1213
1238
  let apiPath = name;
1214
1239
  if (!apiPath.startsWith("/apis")) apiPath = `/apis/${name}/api.yaml`;
@@ -1271,27 +1296,56 @@ function useApiStateful(name) {
1271
1296
  };
1272
1297
  }
1273
1298
  /**
1274
- * React hook for calling SDK-based APIs via postMessage to the parent frame.
1299
+ * React hook for calling SDK-based APIs by executing directly against the
1300
+ * orchestrator's v3/execute endpoint from within the library iframe.
1275
1301
  * Only active when `rootStore.sdkApiEnabled` is true.
1302
+ *
1303
+ * Execution tracking notifications (started/completed/failed) are sent to
1304
+ * the parent so the SDK API editor's execution log stays up to date.
1276
1305
  */
1277
1306
  function useSdkApi(apiName) {
1278
1307
  return {
1279
1308
  run: useCallback(async (inputs) => {
1280
- return new Promise((resolve, reject) => {
1281
- const callbackId = addNewPromise((result) => {
1282
- const executionResult = result;
1283
- if (executionResult.success) resolve(executionResult.output);
1284
- else reject(executionResult.error ?? /* @__PURE__ */ new Error("API execution failed"));
1285
- }, false, reject);
1286
- sendMessageImmediately({
1287
- type: "sdk-execute-api",
1309
+ const executionId = generateId();
1310
+ const inputRecord = inputs ?? {};
1311
+ const startTime = Date.now();
1312
+ const editMode = isEditMode();
1313
+ if (editMode) sendMessageImmediately({
1314
+ type: "sdk-api-execution-started",
1315
+ payload: {
1316
+ executionId,
1317
+ apiName,
1318
+ input: inputRecord
1319
+ }
1320
+ });
1321
+ const result = await root_store_default.apis.executeSdkApiV3(apiName, inputRecord);
1322
+ const durationMs = Date.now() - startTime;
1323
+ if (result.success) {
1324
+ if (editMode) sendMessageImmediately({
1325
+ type: "sdk-api-execution-completed",
1288
1326
  payload: {
1327
+ executionId,
1289
1328
  apiName,
1290
- input: inputs ?? {},
1291
- callbackId
1329
+ output: result.output,
1330
+ durationMs
1292
1331
  }
1293
1332
  });
1333
+ return result.output;
1334
+ }
1335
+ const error = result.error ?? {
1336
+ code: "UNKNOWN",
1337
+ message: "API execution failed"
1338
+ };
1339
+ if (editMode) sendMessageImmediately({
1340
+ type: "sdk-api-execution-failed",
1341
+ payload: {
1342
+ executionId,
1343
+ apiName,
1344
+ error,
1345
+ durationMs
1346
+ }
1294
1347
  });
1348
+ throw error;
1295
1349
  }, [apiName]),
1296
1350
  cancel: useCallback(async () => {
1297
1351
  throw new Error(`Cancellation is not yet implemented for SDK APIs. API "${apiName}" will continue executing.`);
@@ -1299,8 +1353,33 @@ function useSdkApi(apiName) {
1299
1353
  };
1300
1354
  }
1301
1355
  function useApi(apiName) {
1302
- if (root_store_default.sdkApiEnabled) return useSdkApi(apiName);
1303
- return useApiStateful(apiName);
1356
+ const { run: sdkRun, cancel: sdkCancel } = useSdkApi(apiName);
1357
+ const { run: legacyRun, cancel: legacyCancel } = useApiStateful(apiName);
1358
+ return {
1359
+ run: useCallback(async (inputs) => {
1360
+ let sdkApiEnabled = root_store_default.sdkApiEnabled;
1361
+ let hasEntryPoint = !!root_store_default.getApiEntryPoint(apiName);
1362
+ if (!sdkApiEnabled && !hasEntryPoint) {
1363
+ await root_store_default.awaitDiscovery();
1364
+ sdkApiEnabled = root_store_default.sdkApiEnabled;
1365
+ hasEntryPoint = !!root_store_default.getApiEntryPoint(apiName);
1366
+ }
1367
+ if (sdkApiEnabled || hasEntryPoint) return sdkRun(inputs ?? {});
1368
+ return legacyRun(inputs);
1369
+ }, [
1370
+ apiName,
1371
+ sdkRun,
1372
+ legacyRun
1373
+ ]),
1374
+ cancel: useCallback(async () => {
1375
+ if (root_store_default.sdkApiEnabled || !!root_store_default.getApiEntryPoint(apiName)) return sdkCancel();
1376
+ return legacyCancel();
1377
+ }, [
1378
+ apiName,
1379
+ sdkCancel,
1380
+ legacyCancel
1381
+ ])
1382
+ };
1304
1383
  }
1305
1384
  /**
1306
1385
  * Creates a typed version of useApi bound to a specific API registry type.
@@ -4602,7 +4681,56 @@ const EmbedWrapper$2 = (props) => {
4602
4681
  inputs,
4603
4682
  traceHeaders
4604
4683
  });
4605
- if (isTestRun) {
4684
+ if (root_store_default.sdkApiEnabled) {
4685
+ const executionId = generateId();
4686
+ const inputRecord = inputs ?? {};
4687
+ const startTime = Date.now();
4688
+ sendMessageImmediately({
4689
+ type: "sdk-api-execution-started",
4690
+ payload: {
4691
+ executionId,
4692
+ apiName,
4693
+ input: inputRecord
4694
+ }
4695
+ });
4696
+ root_store_default.apis.executeSdkApiV3(apiName, inputRecord).then((result) => {
4697
+ const durationMs = Date.now() - startTime;
4698
+ if (result.success) sendMessageImmediately({
4699
+ type: "sdk-api-execution-completed",
4700
+ payload: {
4701
+ executionId,
4702
+ apiName,
4703
+ output: result.output,
4704
+ durationMs
4705
+ }
4706
+ });
4707
+ else sendMessageImmediately({
4708
+ type: "sdk-api-execution-failed",
4709
+ payload: {
4710
+ executionId,
4711
+ apiName,
4712
+ error: result.error ?? {
4713
+ code: "UNKNOWN",
4714
+ message: "API execution failed"
4715
+ },
4716
+ durationMs
4717
+ }
4718
+ });
4719
+ }).catch((error$1) => {
4720
+ sendMessageImmediately({
4721
+ type: "sdk-api-execution-failed",
4722
+ payload: {
4723
+ executionId,
4724
+ apiName,
4725
+ error: {
4726
+ code: "UNKNOWN",
4727
+ message: error$1 instanceof Error ? error$1.message : "Unknown error"
4728
+ },
4729
+ durationMs: Date.now() - startTime
4730
+ }
4731
+ });
4732
+ });
4733
+ } else if (isTestRun) {
4606
4734
  console.log("[iframe-wrappers] Running as test run");
4607
4735
  root_store_default.apis.runApiByPath({
4608
4736
  path: getApiPath(apiName),
@@ -5244,6 +5372,19 @@ var InternalErrorBoundary = class extends React.Component {
5244
5372
  }
5245
5373
  };
5246
5374
 
5375
+ //#endregion
5376
+ //#region src/lib/internal-details/lib/apply-sdk-context-payload.ts
5377
+ /**
5378
+ * Apply SDK context updates from the editor.
5379
+ * Uses "key" in payload so that undefined values can clear the previous state
5380
+ * (e.g. switching from a named profile back to default).
5381
+ */
5382
+ function applySdkContextPayload(payload) {
5383
+ if ("profile" in payload) root_store_default.setProfile(payload.profile);
5384
+ if ("branchName" in payload) root_store_default.setBranchName(payload.branchName);
5385
+ if ("commitId" in payload) root_store_default.setCommitId(payload.commitId);
5386
+ }
5387
+
5247
5388
  //#endregion
5248
5389
  //#region src/lib/internal-details/lib/devtools/index.tsx
5249
5390
  const SUPPORTED_MODES = ["local-dev"];
@@ -5282,6 +5423,25 @@ function useTrackRouteChange() {
5282
5423
  ]);
5283
5424
  }
5284
5425
 
5426
+ //#endregion
5427
+ //#region src/lib/user-facing/load-build-manifest.ts
5428
+ /**
5429
+ * Load the build manifest and register APIs.
5430
+ * - When sdkApis has entries: populate entryPoints for direct v3/execute calls.
5431
+ * - When sdkApis is empty: relay to loadApiManifest for YAML orchestrator registration.
5432
+ */
5433
+ async function loadBuildManifest() {
5434
+ if (isEditMode()) return;
5435
+ try {
5436
+ const mod = await import("../build-manifest-BOqMhObV.js");
5437
+ const sdkApis = mod.default.sdkApis ?? {};
5438
+ if (Object.keys(sdkApis).length > 0) for (const [name, meta] of Object.entries(sdkApis)) root_store_default.setApiEntryPoint(name, meta.entryPoint);
5439
+ else root_store_default.apis.loadApiManifest(mod.default);
5440
+ } catch (error) {
5441
+ console.error("Error loading build manifest", error);
5442
+ }
5443
+ }
5444
+
5285
5445
  //#endregion
5286
5446
  //#region src/lib/user-facing/sb-provider-tracker.ts
5287
5447
  const hasSbProviderRenderedEditMode = () => globalThis.__SB_PROVIDER_RENDERED_EDIT_MODE__ === true;
@@ -5384,14 +5544,6 @@ console.log = (...args) => {
5384
5544
  }));
5385
5545
  } catch {}
5386
5546
  };
5387
- const loadApisIntoLibrary = async function loadApisIntoLibrary$1() {
5388
- if (!isEditMode()) try {
5389
- const mod = await import("../build-manifest-BOqMhObV.js");
5390
- root_store_default.apis.loadApiManifest(mod.default);
5391
- } catch (error) {
5392
- console.error("Error loading apis into library", error);
5393
- }
5394
- };
5395
5547
  const Auth0Wrapper = isEditMode() ? Auth0Wrapper$2 : Auth0Wrapper$1;
5396
5548
  const EmbedWrapper = isEditMode() ? EmbedWrapper$2 : EmbedWrapper$1;
5397
5549
  const SbProvider = function SbProvider$1({ name = "codemode", children, className, context: context$1 }) {
@@ -5400,7 +5552,7 @@ const SbProvider = function SbProvider$1({ name = "codemode", children, classNam
5400
5552
  const [isApisInitialized, setIsApisInitialized] = useState(false);
5401
5553
  useEffect(() => {
5402
5554
  (async () => {
5403
- await loadApisIntoLibrary();
5555
+ await loadBuildManifest();
5404
5556
  setIsApisInitialized(true);
5405
5557
  })();
5406
5558
  }, []);
@@ -5411,11 +5563,16 @@ const SbProvider = function SbProvider$1({ name = "codemode", children, classNam
5411
5563
  const rejectPromiseListener = (event) => {
5412
5564
  rejectById(event.data.callbackId, event.data.payload);
5413
5565
  };
5566
+ const handleSdkContextUpdate = (event) => {
5567
+ applySdkContextPayload(event.data.payload);
5568
+ };
5414
5569
  iframeMessageHandler.addEventListener("resolve-promise", resolvePromiseListener);
5415
5570
  iframeMessageHandler.addEventListener("reject-promise", rejectPromiseListener);
5571
+ iframeMessageHandler.addEventListener("sb-update-sdk-context", handleSdkContextUpdate);
5416
5572
  return () => {
5417
5573
  iframeMessageHandler.removeEventListener("resolve-promise", resolvePromiseListener);
5418
5574
  iframeMessageHandler.removeEventListener("reject-promise", rejectPromiseListener);
5575
+ iframeMessageHandler.removeEventListener("sb-update-sdk-context", handleSdkContextUpdate);
5419
5576
  };
5420
5577
  }, []);
5421
5578
  useEffect(() => {