skybridge 0.0.0-dev.66b8f6b → 0.0.0-dev.6a8ad04

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 (141) hide show
  1. package/README.md +196 -1
  2. package/dist/{server → src/server}/index.d.ts +0 -1
  3. package/dist/{server → src/server}/index.js +0 -1
  4. package/dist/src/server/index.js.map +1 -0
  5. package/dist/{server → src/server}/server.d.ts +1 -0
  6. package/dist/src/server/server.js +57 -0
  7. package/dist/src/server/server.js.map +1 -0
  8. package/dist/src/server/templateHelper.d.ts +15 -0
  9. package/dist/src/server/templateHelper.js +29 -0
  10. package/dist/src/server/templateHelper.js.map +1 -0
  11. package/dist/src/server/templates/development.hbs +12 -0
  12. package/dist/src/server/templates/production.hbs +6 -0
  13. package/dist/{server → src/server}/widgetsDevServer.d.ts +5 -2
  14. package/dist/{server → src/server}/widgetsDevServer.js +5 -2
  15. package/dist/src/server/widgetsDevServer.js.map +1 -0
  16. package/dist/src/test/utils.d.ts +28 -0
  17. package/dist/src/test/utils.js +43 -0
  18. package/dist/src/test/utils.js.map +1 -0
  19. package/dist/src/test/widget.test.d.ts +1 -0
  20. package/dist/src/test/widget.test.js +90 -0
  21. package/dist/src/test/widget.test.js.map +1 -0
  22. package/dist/src/web/data-llm.d.ts +13 -0
  23. package/dist/src/web/data-llm.js +67 -0
  24. package/dist/src/web/data-llm.js.map +1 -0
  25. package/dist/src/web/data-llm.test.d.ts +1 -0
  26. package/dist/src/web/data-llm.test.js +76 -0
  27. package/dist/src/web/data-llm.test.js.map +1 -0
  28. package/dist/src/web/hooks/index.d.ts +13 -0
  29. package/dist/src/web/hooks/index.js +14 -0
  30. package/dist/src/web/hooks/index.js.map +1 -0
  31. package/dist/src/web/hooks/use-call-tool.d.ts +62 -0
  32. package/dist/src/web/hooks/use-call-tool.js +68 -0
  33. package/dist/src/web/hooks/use-call-tool.js.map +1 -0
  34. package/dist/src/web/hooks/use-call-tool.test.d.ts +1 -0
  35. package/dist/src/web/hooks/use-call-tool.test.js +163 -0
  36. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
  37. package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
  38. package/dist/src/web/hooks/use-display-mode.js +7 -0
  39. package/dist/src/web/hooks/use-display-mode.js.map +1 -0
  40. package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
  41. package/dist/src/web/hooks/use-display-mode.test.js +40 -0
  42. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
  43. package/dist/src/web/hooks/use-locale.d.ts +1 -0
  44. package/dist/src/web/hooks/use-locale.js +5 -0
  45. package/dist/src/web/hooks/use-locale.js.map +1 -0
  46. package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
  47. package/dist/src/web/hooks/use-locale.test.js +21 -0
  48. package/dist/src/web/hooks/use-locale.test.js.map +1 -0
  49. package/dist/src/web/hooks/use-open-external.d.ts +1 -0
  50. package/dist/src/web/hooks/use-open-external.js +6 -0
  51. package/dist/src/web/hooks/use-open-external.js.map +1 -0
  52. package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
  53. package/dist/src/web/hooks/use-open-external.test.js +24 -0
  54. package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
  55. package/dist/{web → src/web/hooks}/use-openai-global.d.ts +1 -1
  56. package/dist/{web → src/web/hooks}/use-openai-global.js +4 -2
  57. package/dist/src/web/hooks/use-openai-global.js.map +1 -0
  58. package/dist/src/web/hooks/use-request-modal.d.ts +5 -0
  59. package/dist/src/web/hooks/use-request-modal.js +9 -0
  60. package/dist/src/web/hooks/use-request-modal.js.map +1 -0
  61. package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
  62. package/dist/src/web/hooks/use-request-modal.test.js +24 -0
  63. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
  64. package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
  65. package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
  66. package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
  67. package/dist/src/web/hooks/use-theme.d.ts +1 -0
  68. package/dist/src/web/hooks/use-theme.js +5 -0
  69. package/dist/src/web/hooks/use-theme.js.map +1 -0
  70. package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
  71. package/dist/src/web/hooks/use-theme.test.js +26 -0
  72. package/dist/src/web/hooks/use-theme.test.js.map +1 -0
  73. package/dist/src/web/hooks/use-tool-info.d.ts +25 -0
  74. package/dist/src/web/hooks/use-tool-info.js +22 -0
  75. package/dist/src/web/hooks/use-tool-info.js.map +1 -0
  76. package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
  77. package/dist/src/web/hooks/use-tool-info.test-d.js +74 -0
  78. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
  79. package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
  80. package/dist/src/web/hooks/use-tool-info.test.js +59 -0
  81. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
  82. package/dist/src/web/hooks/use-tool-output.d.ts +4 -0
  83. package/dist/src/web/hooks/use-tool-output.js +9 -0
  84. package/dist/src/web/hooks/use-tool-output.js.map +1 -0
  85. package/dist/src/web/hooks/use-tool-response-metadata.d.ts +4 -0
  86. package/dist/src/web/hooks/use-tool-response-metadata.js +8 -0
  87. package/dist/src/web/hooks/use-tool-response-metadata.js.map +1 -0
  88. package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
  89. package/dist/src/web/hooks/use-user-agent.js +5 -0
  90. package/dist/src/web/hooks/use-user-agent.js.map +1 -0
  91. package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
  92. package/dist/src/web/hooks/use-user-agent.test.js +31 -0
  93. package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
  94. package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
  95. package/dist/src/web/hooks/use-widget-state.js +54 -0
  96. package/dist/src/web/hooks/use-widget-state.js.map +1 -0
  97. package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
  98. package/dist/src/web/hooks/use-widget-state.test.js +60 -0
  99. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
  100. package/dist/src/web/index.d.ts +5 -0
  101. package/dist/src/web/index.js +6 -0
  102. package/dist/src/web/index.js.map +1 -0
  103. package/dist/src/web/mount-widget.js +14 -0
  104. package/dist/src/web/mount-widget.js.map +1 -0
  105. package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
  106. package/dist/src/web/plugin/data-llm.test.js +81 -0
  107. package/dist/src/web/plugin/data-llm.test.js.map +1 -0
  108. package/dist/src/web/plugin/plugin.d.ts +2 -0
  109. package/dist/src/web/plugin/plugin.js +33 -0
  110. package/dist/src/web/plugin/plugin.js.map +1 -0
  111. package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
  112. package/dist/src/web/plugin/transform-data-llm.js +93 -0
  113. package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
  114. package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
  115. package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
  116. package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
  117. package/dist/{web → src/web}/types.d.ts +26 -4
  118. package/dist/{web → src/web}/types.js +1 -0
  119. package/dist/src/web/types.js.map +1 -0
  120. package/dist/vitest.config.d.ts +2 -0
  121. package/dist/vitest.config.js +8 -0
  122. package/dist/vitest.config.js.map +1 -0
  123. package/package.json +28 -12
  124. package/dist/server/index.js.map +0 -1
  125. package/dist/server/middleware.d.ts +0 -3
  126. package/dist/server/middleware.js +0 -47
  127. package/dist/server/middleware.js.map +0 -1
  128. package/dist/server/server.js +0 -70
  129. package/dist/server/server.js.map +0 -1
  130. package/dist/server/widgetsDevServer.js.map +0 -1
  131. package/dist/web/index.d.ts +0 -4
  132. package/dist/web/index.js +0 -5
  133. package/dist/web/index.js.map +0 -1
  134. package/dist/web/mount-widget.js +0 -10
  135. package/dist/web/mount-widget.js.map +0 -1
  136. package/dist/web/types.js.map +0 -1
  137. package/dist/web/use-openai-global.js.map +0 -1
  138. package/dist/web/use-tool-output.d.ts +0 -3
  139. package/dist/web/use-tool-output.js +0 -5
  140. package/dist/web/use-tool-output.js.map +0 -1
  141. /package/dist/{web → src/web}/mount-widget.d.ts +0 -0
@@ -0,0 +1,81 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { transform } from "./transform-data-llm.js";
3
+ describe("data-llm plugin", () => {
4
+ it("should transform JSX element with data-llm string attribute", async () => {
5
+ const code = `
6
+ function Component() {
7
+ return <div data-llm="Test description">Content</div>;
8
+ }
9
+ `;
10
+ const result = await transform(code, "test.tsx");
11
+ expect(result).not.toBeNull();
12
+ expect(result?.code).toContain("DataLLM");
13
+ expect(result?.code).toContain('content="Test description"');
14
+ expect(result?.code).not.toContain("data-llm");
15
+ });
16
+ it("should transform JSX element with data-llm expression attribute", async () => {
17
+ const code = `
18
+ function Component() {
19
+ const desc = "Dynamic description";
20
+ return <div data-llm={desc}>Content</div>;
21
+ }
22
+ `;
23
+ const result = await transform(code, "test.tsx");
24
+ expect(result).not.toBeNull();
25
+ expect(result?.code).toContain("DataLLM");
26
+ expect(result?.code).toContain("content={desc}");
27
+ expect(result?.code).not.toContain("data-llm");
28
+ });
29
+ it("should add import for DataLLM when not present", async () => {
30
+ const code = `
31
+ function Component() {
32
+ return <div data-llm="Test">Content</div>;
33
+ }
34
+ `;
35
+ const result = await transform(code, "test.tsx");
36
+ expect(result).not.toBeNull();
37
+ expect(result?.code).toContain('import { DataLLM } from "skybridge/web"');
38
+ });
39
+ it("should handle DataLLM imports correctly", async () => {
40
+ // No duplicate import
41
+ const codeWithImport = `
42
+ import { DataLLM } from "skybridge/web";
43
+ function Component() {
44
+ return <div data-llm="Test">Content</div>;
45
+ }
46
+ `;
47
+ const result1 = await transform(codeWithImport, "test.tsx");
48
+ expect(result1?.code.match(/import.*DataLLM.*from.*skybridge\/web/g)).toHaveLength(1);
49
+ // Preserve other imports and add missing DataLLM
50
+ const codeWithOthers = `
51
+ import React from "react";
52
+ import { useState } from "react";
53
+ function Component() {
54
+ return <div data-llm="Test">Content</div>;
55
+ }
56
+ `;
57
+ const result2 = await transform(codeWithOthers, "test.tsx");
58
+ expect(result2?.code).toContain('import React from "react"');
59
+ expect(result2?.code).toContain('import { useState } from "react"');
60
+ expect(result2?.code).toContain('import { DataLLM } from "skybridge/web"');
61
+ });
62
+ it("should handle complex JSX with multiple data-llm attributes", async () => {
63
+ const code = `
64
+ function Component() {
65
+ return (
66
+ <div>
67
+ <section data-llm="Section 1">
68
+ <p>Content 1</p>
69
+ </section>
70
+ <section data-llm="Section 2">
71
+ <p>Content 2</p>
72
+ </section>
73
+ </div>
74
+ );
75
+ }
76
+ `;
77
+ const result = await transform(code, "test.tsx");
78
+ expect(result).toMatchSnapshot();
79
+ });
80
+ });
81
+ //# sourceMappingURL=data-llm.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-llm.test.js","sourceRoot":"","sources":["../../../../src/web/plugin/data-llm.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,IAAI,GAAG;;;;KAIZ,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC9B,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;QAC7D,MAAM,CAAC,MAAM,E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AElB,iDAAiD;QACjD,MAAM,cAAc,GAAG;;;;;;KAMtB,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;QAC7D,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,kCAAkC,CAAC,CAAC;QACpE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,yCAAyC,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,IAAI,GAAG;;;;;;;;;;;;;KAaZ,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "vite";
2
+ export declare function skybridge(): Plugin;
@@ -0,0 +1,33 @@
1
+ import { transform as dataLlmTransform } from "./transform-data-llm.js";
2
+ export function skybridge() {
3
+ return {
4
+ name: "skybridge",
5
+ async config(config) {
6
+ // Dynamic imports to ensure Node modules are only loaded in Node.js context
7
+ const { globSync } = await import("node:fs");
8
+ const { resolve } = await import("node:path");
9
+ const projectRoot = config.root || process.cwd();
10
+ const widgetsPattern = resolve(projectRoot, "src/widgets/*.{js,ts,jsx,tsx,html}");
11
+ const input = Object.fromEntries(globSync(widgetsPattern).map((file) => [
12
+ file.match(/src\/widgets\/(.+)\.tsx$/)?.[1],
13
+ file,
14
+ ]));
15
+ return {
16
+ base: "/assets",
17
+ build: {
18
+ manifest: true,
19
+ minify: true,
20
+ cssCodeSplit: false,
21
+ rollupOptions: {
22
+ input,
23
+ },
24
+ },
25
+ };
26
+ },
27
+ enforce: "pre",
28
+ async transform(code, id) {
29
+ return await dataLlmTransform(code, id);
30
+ },
31
+ };
32
+ }
33
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../../src/web/plugin/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAExE,MAAM,UAAU,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,4EAA4E;YAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;YAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;YAE9C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YACjD,MAAM,cAAc,GAAG,OAAO,CAC5B,WAAW,EACX,oCAAoC,CACrC,CAAC;YAEF,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACrC,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3C,IAAI;aACL,CAAC,CACH,CAAC;YAEF,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE;oBACL,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;oBACZ,YAAY,EAAE,KAAK;oBACnB,aAAa,EAAE;wBACb,KAAK;qBACN;iBACF;aACF,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;YACtB,OAAO,MAAM,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ export declare const transform: (code: string, id: string) => Promise<{
2
+ code: string;
3
+ map: {
4
+ version: number;
5
+ sources: string[];
6
+ names: string[];
7
+ sourceRoot?: string | undefined;
8
+ sourcesContent?: string[] | undefined;
9
+ mappings: string;
10
+ file: string;
11
+ } | null;
12
+ } | null>;
@@ -0,0 +1,93 @@
1
+ const LLM_IMPORT_SOURCE = "skybridge/web";
2
+ function createBabelPlugin(t) {
3
+ return {
4
+ name: "data-llm-babel",
5
+ visitor: {
6
+ Program: {
7
+ enter(path, state) {
8
+ state.hasDataLLMImport = false;
9
+ state.needsDataLLMImport = false;
10
+ for (const node of path.node.body) {
11
+ if (!t.isImportDeclaration(node))
12
+ continue;
13
+ if (node.source.value !== LLM_IMPORT_SOURCE)
14
+ continue;
15
+ const hasSpecifier = node.specifiers.some((s) => t.isImportSpecifier(s) &&
16
+ t.isIdentifier(s.imported, { name: "DataLLM" }));
17
+ if (hasSpecifier) {
18
+ state.hasDataLLMImport = true;
19
+ break;
20
+ }
21
+ }
22
+ },
23
+ exit(path, state) {
24
+ if (state.needsDataLLMImport && !state.hasDataLLMImport) {
25
+ const importDecl = t.importDeclaration([
26
+ t.importSpecifier(t.identifier("DataLLM"), t.identifier("DataLLM")),
27
+ ], t.stringLiteral(LLM_IMPORT_SOURCE));
28
+ path.node.body.unshift(importDecl);
29
+ }
30
+ },
31
+ },
32
+ JSXElement(path, state) {
33
+ const opening = path.node.openingElement;
34
+ const attributes = opening.attributes;
35
+ const llmAttributeIndex = attributes.findIndex((attribute) => t.isJSXAttribute(attribute) &&
36
+ t.isJSXIdentifier(attribute.name, { name: "data-llm" }));
37
+ if (llmAttributeIndex === -1)
38
+ return;
39
+ const llmAttribute = attributes[llmAttributeIndex];
40
+ let contentExpression;
41
+ if (t.isStringLiteral(llmAttribute.value)) {
42
+ contentExpression = llmAttribute.value;
43
+ }
44
+ else if (t.isJSXExpressionContainer(llmAttribute.value)) {
45
+ contentExpression = llmAttribute.value.expression;
46
+ }
47
+ else {
48
+ return;
49
+ }
50
+ const contentAttr = t.jsxAttribute(t.jsxIdentifier("content"), t.isStringLiteral(contentExpression)
51
+ ? contentExpression
52
+ : t.jsxExpressionContainer(contentExpression));
53
+ const filteredAttributes = attributes.filter((_, index) => index !== llmAttributeIndex);
54
+ const newOpening = t.jsxOpeningElement(opening.name, filteredAttributes, opening.selfClosing);
55
+ const elementWithoutLlm = t.jsxElement(newOpening, path.node.closingElement, path.node.children, path.node.selfClosing);
56
+ const llmOpening = t.jsxOpeningElement(t.jsxIdentifier("DataLLM"), [
57
+ contentAttr,
58
+ ]);
59
+ const llmClosing = t.jsxClosingElement(t.jsxIdentifier("DataLLM"));
60
+ const wrapped = t.jsxElement(llmOpening, llmClosing, [elementWithoutLlm], false);
61
+ state.needsDataLLMImport = true;
62
+ path.replaceWith(wrapped);
63
+ },
64
+ },
65
+ };
66
+ }
67
+ export const transform = async (code, id) => {
68
+ if (!/\.(jsx|tsx)$/.test(id)) {
69
+ return null;
70
+ }
71
+ if (id.includes("node_modules")) {
72
+ return null;
73
+ }
74
+ // Dynamic import to ensure @babel/core is only loaded in Node.js context
75
+ const { types: t, transformSync } = await import("@babel/core");
76
+ const babelOptions = {
77
+ plugins: [createBabelPlugin(t)],
78
+ parserOpts: {
79
+ plugins: ["jsx", "typescript"],
80
+ },
81
+ filename: id,
82
+ sourceFileName: id,
83
+ };
84
+ const result = transformSync(code, babelOptions);
85
+ if (!result || !result.code) {
86
+ return null;
87
+ }
88
+ return {
89
+ code: result.code,
90
+ map: result.map || null,
91
+ };
92
+ };
93
+ //# sourceMappingURL=transform-data-llm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-data-llm.js","sourceRoot":"","sources":["../../../../src/web/plugin/transform-data-llm.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAO1C,SAAS,iBAAiB,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O,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC;SAC/B;QACD,QAAQ,EAAE,EAAE;QACZ,cAAc,EAAE,EAAE;KACnB,CAAC;IAEF,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAEjD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI;KACxB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { transform } from "./transform-data-llm.js";
3
+ describe("data-llm plugin", () => {
4
+ it("should transform JSX element with data-llm string attribute", async () => {
5
+ const code = `
6
+ function Component() {
7
+ return <div data-llm="Test description">Content</div>;
8
+ }
9
+ `;
10
+ const result = await transform(code, "test.tsx");
11
+ expect(result).not.toBeNull();
12
+ expect(result?.code).toContain("DataLLM");
13
+ expect(result?.code).toContain('content="Test description"');
14
+ expect(result?.code).not.toContain("data-llm");
15
+ });
16
+ it("should transform JSX element with data-llm expression attribute", async () => {
17
+ const code = `
18
+ function Component() {
19
+ const desc = "Dynamic description";
20
+ return <div data-llm={desc}>Content</div>;
21
+ }
22
+ `;
23
+ const result = await transform(code, "test.tsx");
24
+ expect(result).not.toBeNull();
25
+ expect(result?.code).toContain("DataLLM");
26
+ expect(result?.code).toContain("content={desc}");
27
+ expect(result?.code).not.toContain("data-llm");
28
+ });
29
+ it("should add import for DataLLM when not present", async () => {
30
+ const code = `
31
+ function Component() {
32
+ return <div data-llm="Test">Content</div>;
33
+ }
34
+ `;
35
+ const result = await transform(code, "test.tsx");
36
+ expect(result).not.toBeNull();
37
+ expect(result?.code).toContain('import { DataLLM } from "skybridge/web"');
38
+ });
39
+ it("should handle DataLLM imports correctly", async () => {
40
+ // No duplicate import
41
+ const codeWithImport = `
42
+ import { DataLLM } from "skybridge/web";
43
+ function Component() {
44
+ return <div data-llm="Test">Content</div>;
45
+ }
46
+ `;
47
+ const result1 = await transform(codeWithImport, "test.tsx");
48
+ expect(result1?.code.match(/import.*DataLLM.*from.*skybridge\/web/g)).toHaveLength(1);
49
+ // Preserve other imports and add missing DataLLM
50
+ const codeWithOthers = `
51
+ import React from "react";
52
+ import { useState } from "react";
53
+ function Component() {
54
+ return <div data-llm="Test">Content</div>;
55
+ }
56
+ `;
57
+ const result2 = await transform(codeWithOthers, "test.tsx");
58
+ expect(result2?.code).toContain('import React from "react"');
59
+ expect(result2?.code).toContain('import { useState } from "react"');
60
+ expect(result2?.code).toContain('import { DataLLM } from "skybridge/web"');
61
+ });
62
+ it("should handle complex JSX with multiple data-llm attributes", async () => {
63
+ const code = `
64
+ function Component() {
65
+ return (
66
+ <div>
67
+ <section data-llm="Section 1">
68
+ <p>Content 1</p>
69
+ </section>
70
+ <section data-llm="Section 2">
71
+ <p>Content 2</p>
72
+ </section>
73
+ </div>
74
+ );
75
+ }
76
+ `;
77
+ const result = await transform(code, "test.tsx");
78
+ expect(result).toMatchSnapshot();
79
+ });
80
+ });
81
+ //# sourceMappingURL=transform-data-llm.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-data-llm.test.js","sourceRoot":"","sources":["../../../../src/web/plugin/transform-data-llm.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,IAAI,GAAG;;;;KAIZ,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,UA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AAyC,EAAE,KAAK,IAAI,EAAE;QACvD,sBAAsB;QACtB,MAAM,cAAc,GAAG;;;;;KAKtB,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAC5D,MAAM,CACJ,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAC9D,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAElB,iDAAiD;QACjD,MAAM,cAAc,GAAG;;;;;;KAMtB,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAC5D,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;QAC7D,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,kCAAkC,CAAC,CAAC;QACpE,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,yCAAyC,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,IAAI,GAAG;;;;;;;;;;;;;KAaZ,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,4 +1,10 @@
1
- type UnknownObject = Record<string, unknown>;
1
+ import "react";
2
+ declare module "react" {
3
+ interface HTMLAttributes<T extends Element = HTMLElement> {
4
+ "data-llm"?: string;
5
+ }
6
+ }
7
+ export type UnknownObject = Record<string, unknown>;
2
8
  export type WidgetState = UnknownObject;
3
9
  export type SetWidgetState = (state: WidgetState) => Promise<void>;
4
10
  export type SendFollowUpMessage = (args: {
@@ -9,6 +15,10 @@ export type RequestDisplayMode = (args: {
9
15
  }) => Promise<{
10
16
  mode: DisplayMode;
11
17
  }>;
18
+ export type RequestModal = (options: RequestModalOptions) => Promise<void>;
19
+ export type RequestModalOptions = {
20
+ title: string;
21
+ };
12
22
  export declare const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
13
23
  export declare class ToolResponseEvent extends CustomEvent<{
14
24
  tool: {
@@ -26,7 +36,7 @@ declare global {
26
36
  [SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
27
37
  }
28
38
  }
29
- export type OpenAiGlobals<ToolInput extends UnknownObject = UnknownObject, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
39
+ export type OpenAiGlobals<ToolInput extends UnknownObject = {}, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
30
40
  theme: Theme;
31
41
  userAgent: UserAgent;
32
42
  locale: string;
@@ -34,16 +44,28 @@ export type OpenAiGlobals<ToolInput extends UnknownObject = UnknownObject, ToolO
34
44
  displayMode: DisplayMode;
35
45
  safeArea: SafeArea;
36
46
  toolInput: ToolInput;
37
- toolOutput: ToolOutput | null;
47
+ toolOutput: ToolOutput | {
48
+ text: string;
49
+ } | null;
38
50
  toolResponseMetadata: ToolResponseMetadata | null;
39
51
  widgetState: WidgetState | null;
52
+ requestDisplayMode: RequestDisplayMode;
53
+ requestModal: RequestModal;
40
54
  };
55
+ export type CallToolArgs = Record<string, unknown> | null;
41
56
  export type CallToolResponse = {
57
+ content: {
58
+ type: "text";
59
+ text: string;
60
+ }[];
61
+ structuredContent: Record<string, unknown>;
62
+ isError: boolean;
42
63
  result: string;
64
+ meta: Record<string, unknown>;
43
65
  };
44
66
  type API<WidgetState extends UnknownObject> = {
45
67
  /** Calls a tool on your MCP. Returns the full response. */
46
- callTool: (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
68
+ callTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
47
69
  /** Triggers a followup turn in the ChatGPT conversation */
48
70
  sendFollowUpMessage: (args: {
49
71
  prompt: string;
@@ -1,3 +1,4 @@
1
+ import "react";
1
2
  export const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
2
3
  export class ToolResponseEvent extends CustomEvent {
3
4
  type = TOOL_RESPONSE_EVENT_TYPE;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,CAAC;AA0Bf,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA6ED,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "vitest/config";
2
+ export default defineConfig({
3
+ test: {
4
+ environment: "jsdom",
5
+ globals: true,
6
+ },
7
+ });
8
+ //# sourceMappingURL=vitest.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.config.js","sourceRoot":"","sources":["../vitest.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAe,YAAY,CAAC;IAC1B,IAAI,EAAE;QACJ,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,IAAI;KACd;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skybridge",
3
- "version": "0.0.0-dev.66b8f6b",
3
+ "version": "0.0.0-dev.6a8ad04",
4
4
  "description": "Skybridge is a framework for building ChatGPT apps",
5
5
  "type": "module",
6
6
  "files": [
@@ -8,16 +8,23 @@
8
8
  ],
9
9
  "exports": {
10
10
  "./server": {
11
- "types": "./dist/server/index.d.ts",
12
- "default": "./dist/server/index.js"
11
+ "types": "./dist/src/server/index.d.ts",
12
+ "default": "./dist/src/server/index.js"
13
13
  },
14
14
  "./web": {
15
- "types": "./dist/web/index.d.ts",
16
- "default": "./dist/web/index.js"
15
+ "types": "./dist/src/web/index.d.ts",
16
+ "default": "./dist/src/web/index.js"
17
17
  }
18
18
  },
19
19
  "scripts": {
20
- "build": "tsc"
20
+ "build": "tsc && pnpm run build:templates",
21
+ "build:templates": "cp -r src/server/templates dist/src/server/",
22
+ "test": "pnpm run test:unit && pnpm run test:type",
23
+ "test:unit": "vitest run --silent",
24
+ "test:type": "tsc --noEmit",
25
+ "docs:dev": "pnpm --filter @skybridge/docs start",
26
+ "docs:build": "pnpm --filter @skybridge/docs build",
27
+ "docs:serve": "pnpm --filter @skybridge/docs serve"
21
28
  },
22
29
  "keywords": [
23
30
  "chatgpt",
@@ -28,24 +35,33 @@
28
35
  "author": "Frédéric Barthelet",
29
36
  "license": "ISC",
30
37
  "peerDependencies": {
31
- "react": ">=19.0.0",
32
- "react-dom": ">=19.0.0"
38
+ "react": ">=18.0.0",
39
+ "react-dom": ">=18.0.0"
33
40
  },
34
41
  "dependencies": {
42
+ "@babel/core": "^7.28.5",
35
43
  "@modelcontextprotocol/sdk": "^1.20.0",
36
- "zod": "^3.25.51",
37
44
  "cors": "^2.8.5",
38
45
  "express": "^5.1.0",
39
- "vite": "^7.1.11"
46
+ "handlebars": "^4.7.8",
47
+ "vite": "^7.1.11",
48
+ "zod": "^3.25.51"
40
49
  },
41
50
  "devDependencies": {
51
+ "@testing-library/dom": "^10.4.1",
52
+ "@testing-library/react": "^16.3.0",
42
53
  "@total-typescript/tsconfig": "^1.0.4",
54
+ "@types/babel__core": "^7.20.5",
43
55
  "@types/cors": "^2.8.19",
44
56
  "@types/express": "^5.0.3",
57
+ "@types/jsdom": "^21.1.6",
45
58
  "@types/node": "^22.15.30",
46
- "@types/react-dom": "^19.2.2",
47
59
  "@types/react": "^19.2.2",
48
- "typescript": "^5.9.3"
60
+ "@types/react-dom": "^19.2.2",
61
+ "@vitest/ui": "^2.1.8",
62
+ "jsdom": "^25.0.1",
63
+ "typescript": "^5.9.3",
64
+ "vitest": "^2.1.8"
49
65
  },
50
66
  "packageManager": "pnpm@10.17.1"
51
67
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,3 +0,0 @@
1
- import { type Request, type Response, type NextFunction } from "express";
2
- import type { McpServer } from "./server.js";
3
- export declare const mcp: (server: McpServer) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -1,47 +0,0 @@
1
- import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
2
- import {} from "express";
3
- export const mcp = (server) => async (req, res, next) => {
4
- // Only handle requests to the /mcp path
5
- if (req.path !== "/mcp") {
6
- return next();
7
- }
8
- if (req.method === "POST") {
9
- try {
10
- const transport = new StreamableHTTPServerTransport({
11
- sessionIdGenerator: undefined,
12
- });
13
- res.on("close", () => {
14
- transport.close();
15
- });
16
- await server.connect(transport);
17
- await transport.handleRequest(req, res, req.body);
18
- }
19
- catch (error) {
20
- console.error("Error handling MCP request:", error);
21
- if (!res.headersSent) {
22
- res.status(500).json({
23
- jsonrpc: "2.0",
24
- error: {
25
- code: -32603,
26
- message: "Internal server error",
27
- },
28
- id: null,
29
- });
30
- }
31
- }
32
- }
33
- else if (req.method === "GET" || req.method === "DELETE") {
34
- res.writeHead(405).end(JSON.stringify({
35
- jsonrpc: "2.0",
36
- error: {
37
- code: -32000,
38
- message: "Method not allowed.",
39
- },
40
- id: null,
41
- }));
42
- }
43
- else {
44
- next();
45
- }
46
- };
47
- //# sourceMappingURL=middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/server/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAkD,MAAM,SAAS,CAAC;AAIzE,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,MAAiB,EAAE,EAAE,CAAC,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAClG,wCAAwC;IACxC,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACxB,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,6BAA6B,CAAC;gBAClD,kBAAkB,EAAE,SAAS;aAC9B,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACnB,SAAS,CAAC,KAAK,EAAE,CAAC;YACpB,CAAC,CAAC,CAAC;YAEH,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAEhC,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;YACpD,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;gBACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACnB,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE;wBACL,IAAI,EAAE,CAAC,KAAK;wBACZ,OAAO,EAAE,uBAAuB;qBACjC;oBACD,EAAE,EAAE,IAAI;iBACT,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;SAAM,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,GAAG,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC3D,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,CACpB,IAAI,CAAC,SAAS,CAAC;YACb,OAAO,EAAE,KAAK;YACd,KAAK,EAAE;gBACL,IAAI,EAAE,CAAC,KAAK;gBACZ,OAAO,EAAE,qBAAqB;aAC/B;YACD,EAAE,EAAE,IAAI;SACT,CAAC,CACH,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,IAAI,EAAE,CAAC;IACT,CAAC;AACH,CAAC,CAAC"}
@@ -1,70 +0,0 @@
1
- import { McpServer as McpServerBase } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- export class McpServer extends McpServerBase {
3
- widget(name, resourceConfig, toolConfig, toolCallback) {
4
- const uri = `ui://widgets/${name}.html`;
5
- const resourceMetadata = { ...(resourceConfig._meta ?? {}) };
6
- if (toolConfig.description !== undefined) {
7
- resourceMetadata["openai/widgetDescription"] = toolConfig.description;
8
- }
9
- this.resource(name, uri, {
10
- ...resourceConfig,
11
- _meta: resourceMetadata,
12
- }, async (_uri, extra) => {
13
- const serverUrl = process.env.NODE_ENV === "production"
14
- ? `https://${extra?.requestInfo?.headers?.host}`
15
- : `http://localhost:3000`;
16
- const injectViteClient = (html) => `
17
- <script type="module">import { injectIntoGlobalHook } from "${serverUrl}/@react-refresh";
18
- injectIntoGlobalHook(window);
19
- window.$RefreshReg$ = () => {};
20
- window.$RefreshSig$ = () => (type) => type;
21
- window.__vite_plugin_react_preamble_installed__ = true;
22
- </script>
23
-
24
- <script type="module" src="${serverUrl}/@vite/client"></script>
25
- ` + html;
26
- const buildHtml = () => {
27
- if (process.env.NODE_ENV === "production") {
28
- try {
29
- return `
30
- <div id="root"></div>
31
- <script type="module">
32
- import('${serverUrl}/assets/${name}.js');
33
- </script>
34
- <link rel="stylesheet" crossorigin href="${serverUrl}/assets/style.css">
35
- `;
36
- }
37
- catch (error) {
38
- console.error("Failed to load production assets:", error);
39
- return "";
40
- }
41
- }
42
- return `
43
- <div id="root"></div>
44
- <script type="module">
45
- import('${serverUrl}/src/widgets/${name}.tsx');
46
- </script>
47
- `;
48
- };
49
- const html = buildHtml();
50
- return {
51
- contents: [
52
- {
53
- uri,
54
- mimeType: "text/html+skybridge",
55
- text: process.env.NODE_ENV === "production" ? html : injectViteClient(html),
56
- },
57
- ],
58
- };
59
- });
60
- const toolMeta = {
61
- ...toolConfig._meta,
62
- "openai/outputTemplate": uri,
63
- };
64
- this.registerTool(name, {
65
- ...toolConfig,
66
- _meta: toolMeta,
67
- }, toolCallback);
68
- }
69
- }
70
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAqB,MAAM,yCAAyC,CAAC;AAwBxG,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,MAAM,CACJ,IAAY,EACZ,cAA+C,EAC/C,UAGC,EACD,YAAqC;QAErC,MAAM,GAAG,GAAG,gBAAgB,IAAI,OAAO,CAAC;QACxC,MAAM,gBAAgB,GAAiB,EAAE,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;QAC3E,IAAI,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACzC,gBAAgB,CAAC,0BAA0B,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC;QACxE,CAAC;QAED,IAAI,CAAC,QAAQ,CACX,IAAI,EACJ,GAAG,EACH;YACE,GAAG,cAAc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