@bubblelab/shared-schemas 0.1.25 → 0.1.27

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.d.ts CHANGED
@@ -26,4 +26,5 @@ export * from './param-utils.js';
26
26
  export * from './error-enhancer.js';
27
27
  export * from './hash-utils.js';
28
28
  export * from './agent-memory.js';
29
+ export * from './parameter-formatter.js';
29
30
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -3553,6 +3553,238 @@ function hashToVariableId(input) {
3553
3553
  function buildCallSiteKey(methodName, invocationIndex) {
3554
3554
  return `${methodName}#${invocationIndex}`;
3555
3555
  }
3556
+
3557
+ // src/parameter-formatter.ts
3558
+ var FUNCTION_LITERAL_PATTERNS = [
3559
+ "func:",
3560
+ // Object property with function value
3561
+ "=>",
3562
+ // Arrow function
3563
+ "function(",
3564
+ // Function expression
3565
+ "function (",
3566
+ // Function expression with space
3567
+ "async(",
3568
+ // Async arrow function
3569
+ "async ("
3570
+ // Async function with space
3571
+ ];
3572
+ function containsFunctionLiteral(value) {
3573
+ return FUNCTION_LITERAL_PATTERNS.some((pattern) => value.includes(pattern));
3574
+ }
3575
+ function formatParameterValue(value, type) {
3576
+ switch (type) {
3577
+ case "string": {
3578
+ const stringValue = String(value);
3579
+ if (stringValue.startsWith("`") && stringValue.endsWith("`")) {
3580
+ return stringValue;
3581
+ }
3582
+ const escapedValue = stringValue.replace(/'/g, "\\'");
3583
+ return `'${escapedValue}'`;
3584
+ }
3585
+ case "number":
3586
+ return String(value);
3587
+ case "boolean":
3588
+ return String(value);
3589
+ case "object":
3590
+ if (typeof value === "string") {
3591
+ const trimmed = value.trim();
3592
+ if (containsFunctionLiteral(trimmed)) {
3593
+ return value;
3594
+ }
3595
+ if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("new ")) {
3596
+ return value;
3597
+ }
3598
+ }
3599
+ return JSON.stringify(value, null, 2);
3600
+ case "array":
3601
+ if (typeof value === "string") {
3602
+ const trimmed = value.trim();
3603
+ if (containsFunctionLiteral(trimmed)) {
3604
+ return value;
3605
+ }
3606
+ if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
3607
+ return value;
3608
+ }
3609
+ }
3610
+ return JSON.stringify(value);
3611
+ case "env":
3612
+ return `process.env.${String(value)}`;
3613
+ case "variable":
3614
+ return String(value);
3615
+ // Reference to another variable
3616
+ case "expression":
3617
+ return String(value);
3618
+ // Return expressions unquoted so they can be evaluated
3619
+ default:
3620
+ return JSON.stringify(value);
3621
+ }
3622
+ }
3623
+ function condenseToSingleLine(input) {
3624
+ return input.replace(/\s*\n\s*/g, " ").replace(/\s{2,}/g, " ").replace(/\{\s+/g, "{ ").replace(/\s+\}/g, " }").replace(/\s*,\s*/g, ", ").trim();
3625
+ }
3626
+ function stripCommentsOutsideStrings(input) {
3627
+ let result = "";
3628
+ let inSingle = false;
3629
+ let inDouble = false;
3630
+ let inTemplate = false;
3631
+ let inLineComment = false;
3632
+ let inBlockComment = false;
3633
+ let escapeNext = false;
3634
+ for (let i = 0; i < input.length; i++) {
3635
+ const ch = input[i];
3636
+ const next = i + 1 < input.length ? input[i + 1] : "";
3637
+ if (inLineComment) {
3638
+ if (ch === "\n") {
3639
+ inLineComment = false;
3640
+ result += ch;
3641
+ }
3642
+ continue;
3643
+ }
3644
+ if (inBlockComment) {
3645
+ if (ch === "*" && next === "/") {
3646
+ inBlockComment = false;
3647
+ i++;
3648
+ }
3649
+ continue;
3650
+ }
3651
+ if (inSingle) {
3652
+ if (escapeNext) {
3653
+ result += ch;
3654
+ escapeNext = false;
3655
+ continue;
3656
+ }
3657
+ if (ch === "\\") {
3658
+ result += ch;
3659
+ escapeNext = true;
3660
+ continue;
3661
+ }
3662
+ result += ch;
3663
+ if (ch === "'") inSingle = false;
3664
+ continue;
3665
+ }
3666
+ if (inDouble) {
3667
+ if (escapeNext) {
3668
+ result += ch;
3669
+ escapeNext = false;
3670
+ continue;
3671
+ }
3672
+ if (ch === "\\") {
3673
+ result += ch;
3674
+ escapeNext = true;
3675
+ continue;
3676
+ }
3677
+ result += ch;
3678
+ if (ch === '"') inDouble = false;
3679
+ continue;
3680
+ }
3681
+ if (inTemplate) {
3682
+ if (escapeNext) {
3683
+ result += ch;
3684
+ escapeNext = false;
3685
+ continue;
3686
+ }
3687
+ if (ch === "\\") {
3688
+ result += ch;
3689
+ escapeNext = true;
3690
+ continue;
3691
+ }
3692
+ result += ch;
3693
+ if (ch === "`") inTemplate = false;
3694
+ continue;
3695
+ }
3696
+ if (ch === "/" && next === "/") {
3697
+ inLineComment = true;
3698
+ i++;
3699
+ continue;
3700
+ }
3701
+ if (ch === "/" && next === "*") {
3702
+ inBlockComment = true;
3703
+ i++;
3704
+ continue;
3705
+ }
3706
+ if (ch === "'") {
3707
+ inSingle = true;
3708
+ result += ch;
3709
+ continue;
3710
+ }
3711
+ if (ch === '"') {
3712
+ inDouble = true;
3713
+ result += ch;
3714
+ continue;
3715
+ }
3716
+ if (ch === "`") {
3717
+ inTemplate = true;
3718
+ result += ch;
3719
+ continue;
3720
+ }
3721
+ result += ch;
3722
+ }
3723
+ return result;
3724
+ }
3725
+ function buildParameterObjectLiteral(parameters, options) {
3726
+ const { preserveFormatting = false } = options ?? {};
3727
+ if (!parameters || parameters.length === 0) {
3728
+ return "{}";
3729
+ }
3730
+ if (parameters.length === 1 && parameters[0].type === "variable" /* VARIABLE */) {
3731
+ const paramValue = formatParameterValue(
3732
+ parameters[0].value,
3733
+ parameters[0].type
3734
+ );
3735
+ return paramValue;
3736
+ }
3737
+ const nonCredentialParams = parameters.filter(
3738
+ (p) => p.name !== "credentials"
3739
+ );
3740
+ const credentialsParam = parameters.find(
3741
+ (p) => p.name === "credentials" && p.type === "object" /* OBJECT */
3742
+ );
3743
+ if (credentialsParam && nonCredentialParams.length === 1 && nonCredentialParams[0].type === "variable" /* VARIABLE */) {
3744
+ const paramsParam = nonCredentialParams[0];
3745
+ const shouldSpread = paramsParam.source === "first-arg" || paramsParam.source === void 0 && paramsParam.name === "arg0";
3746
+ if (shouldSpread) {
3747
+ const paramsValue = formatParameterValue(
3748
+ paramsParam.value,
3749
+ paramsParam.type
3750
+ );
3751
+ const credentialsValue = formatParameterValue(
3752
+ credentialsParam.value,
3753
+ credentialsParam.type
3754
+ );
3755
+ return `{...${paramsValue}, credentials: ${credentialsValue}}`;
3756
+ }
3757
+ }
3758
+ const spreadParams = nonCredentialParams.filter((p) => p.source === "spread");
3759
+ const regularParams = nonCredentialParams.filter(
3760
+ (p) => p.source !== "spread"
3761
+ );
3762
+ const regularEntries = regularParams.map((param) => {
3763
+ const value = formatParameterValue(param.value, param.type);
3764
+ return `${param.name}: ${value}`;
3765
+ });
3766
+ const spreadEntries = spreadParams.map((param) => {
3767
+ const value = formatParameterValue(param.value, param.type);
3768
+ return `...${value}`;
3769
+ });
3770
+ const allEntries = [...regularEntries, ...spreadEntries];
3771
+ if (credentialsParam) {
3772
+ const credentialsValue = formatParameterValue(
3773
+ credentialsParam.value,
3774
+ credentialsParam.type
3775
+ );
3776
+ allEntries.push(`credentials: ${credentialsValue}`);
3777
+ }
3778
+ let paramsString = `{
3779
+ ${allEntries.join(",\n ")}
3780
+ }`;
3781
+ const hasFunctions = containsFunctionLiteral(paramsString);
3782
+ if (!preserveFormatting && !hasFunctions) {
3783
+ paramsString = stripCommentsOutsideStrings(paramsString);
3784
+ paramsString = condenseToSingleLine(paramsString);
3785
+ }
3786
+ return paramsString;
3787
+ }
3556
3788
  export {
3557
3789
  AssistantMessageSchema,
3558
3790
  AvailableModels,
@@ -3648,7 +3880,10 @@ export {
3648
3880
  bubbleFlowListResponseSchema,
3649
3881
  bubbleFlowTemplateResponseSchema,
3650
3882
  buildCallSiteKey,
3883
+ buildParameterObjectLiteral,
3651
3884
  cleanUpObjectForDisplayAndStorage,
3885
+ condenseToSingleLine,
3886
+ containsFunctionLiteral,
3652
3887
  createBubbleFlowResponseSchema,
3653
3888
  createBubbleFlowSchema,
3654
3889
  createCredentialResponseSchema,
@@ -3662,6 +3897,7 @@ export {
3662
3897
  errorResponseSchema,
3663
3898
  executeBubbleFlowResponseSchema,
3664
3899
  executeBubbleFlowSchema,
3900
+ formatParameterValue,
3665
3901
  generateBubbleFlowCodeResponseSchema,
3666
3902
  generateBubbleFlowCodeSchema,
3667
3903
  generateBubbleFlowTemplateSchema,
@@ -3695,6 +3931,7 @@ export {
3695
3931
  slackUrlVerificationResponseSchema,
3696
3932
  slackUrlVerificationSchema,
3697
3933
  specialOfferSchema,
3934
+ stripCommentsOutsideStrings,
3698
3935
  subscriptionStatusResponseSchema,
3699
3936
  successMessageResponseSchema,
3700
3937
  updateBubbleFlowNameSchema,