skybridge 0.0.0-dev.b77fc82 → 0.0.0-dev.bd84fae
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 +74 -2
- package/dist/src/server/server.d.ts +1 -1
- package/dist/src/server/server.js +15 -14
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templateHelper.d.ts +9 -8
- package/dist/src/server/templateHelper.js +0 -8
- package/dist/src/server/templateHelper.js.map +1 -1
- package/dist/src/server/templates/production.hbs +2 -6
- package/dist/src/test/widget.test.js +23 -2
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/hooks/index.d.ts +13 -0
- package/dist/src/web/hooks/index.js +14 -0
- package/dist/src/web/hooks/index.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.d.ts +62 -0
- package/dist/src/web/hooks/use-call-tool.js +68 -0
- package/dist/src/web/hooks/use-call-tool.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.test.js +163 -0
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
- package/dist/src/web/hooks/use-display-mode.js +7 -0
- package/dist/src/web/hooks/use-display-mode.js.map +1 -0
- package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
- package/dist/src/web/hooks/use-display-mode.test.js +40 -0
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/src/web/hooks/use-locale.d.ts +1 -0
- package/dist/src/web/hooks/use-locale.js +5 -0
- package/dist/src/web/hooks/use-locale.js.map +1 -0
- package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
- package/dist/src/web/hooks/use-locale.test.js +21 -0
- package/dist/src/web/hooks/use-locale.test.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.d.ts +1 -0
- package/dist/src/web/hooks/use-open-external.js +6 -0
- package/dist/src/web/hooks/use-open-external.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/src/web/hooks/use-open-external.test.js +24 -0
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/src/web/{use-openai-global.d.ts → hooks/use-openai-global.d.ts} +1 -1
- package/dist/src/web/{use-openai-global.js → hooks/use-openai-global.js} +4 -2
- package/dist/src/web/hooks/use-openai-global.js.map +1 -0
- package/dist/src/web/hooks/use-request-modal.d.ts +5 -0
- package/dist/src/web/hooks/use-request-modal.js +9 -0
- package/dist/src/web/hooks/use-request-modal.js.map +1 -0
- package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
- package/dist/src/web/hooks/use-request-modal.test.js +24 -0
- package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
- package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/src/web/hooks/use-theme.d.ts +1 -0
- package/dist/src/web/hooks/use-theme.js +5 -0
- package/dist/src/web/hooks/use-theme.js.map +1 -0
- package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
- package/dist/src/web/hooks/use-theme.test.js +26 -0
- package/dist/src/web/hooks/use-theme.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.d.ts +25 -0
- package/dist/src/web/hooks/use-tool-info.js +22 -0
- package/dist/src/web/hooks/use-tool-info.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
- package/dist/src/web/hooks/use-tool-info.test-d.js +74 -0
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/src/web/hooks/use-tool-info.test.js +59 -0
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-output.d.ts +4 -0
- package/dist/src/web/hooks/use-tool-output.js +9 -0
- package/dist/src/web/hooks/use-tool-output.js.map +1 -0
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +4 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js +8 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js.map +1 -0
- package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
- package/dist/src/web/hooks/use-user-agent.js +5 -0
- package/dist/src/web/hooks/use-user-agent.js.map +1 -0
- package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
- package/dist/src/web/hooks/use-user-agent.test.js +31 -0
- package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
- package/dist/src/web/hooks/use-widget-state.js +54 -0
- package/dist/src/web/hooks/use-widget-state.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/src/web/hooks/use-widget-state.test.js +60 -0
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/src/web/index.d.ts +3 -3
- package/dist/src/web/index.js +3 -3
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/llm-describe.d.ts +13 -0
- package/dist/src/web/llm-describe.js +62 -0
- package/dist/src/web/llm-describe.js.map +1 -0
- package/dist/src/web/plugin/data-llm.d.ts +12 -0
- package/dist/src/web/plugin/data-llm.js +96 -0
- package/dist/src/web/plugin/data-llm.js.map +1 -0
- package/dist/src/web/{plugin.js → plugin/plugin.js} +5 -0
- package/dist/src/web/plugin/plugin.js.map +1 -0
- package/dist/src/web/types.d.ts +26 -4
- package/dist/src/web/types.js +1 -0
- package/dist/src/web/types.js.map +1 -1
- package/dist/vitest.config.js +0 -1
- package/dist/vitest.config.js.map +1 -1
- package/package.json +11 -2
- package/dist/src/test/setup.js +0 -9
- package/dist/src/test/setup.js.map +0 -1
- package/dist/src/web/plugin.js.map +0 -1
- package/dist/src/web/use-openai-global.js.map +0 -1
- package/dist/src/web/use-tool-output.d.ts +0 -3
- package/dist/src/web/use-tool-output.js +0 -5
- package/dist/src/web/use-tool-output.js.map +0 -1
- /package/dist/src/{test/setup.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
- /package/dist/src/web/{plugin.d.ts → plugin/plugin.d.ts} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { useOpenAiGlobal } from "./use-openai-global.js";
|
|
3
|
+
const WIDGET_CONTEXT_KEY = "__widget_context";
|
|
4
|
+
function filterWidgetContext(state) {
|
|
5
|
+
if (state === null) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const { [WIDGET_CONTEXT_KEY]: _, ...filteredState } = state;
|
|
9
|
+
return filteredState;
|
|
10
|
+
}
|
|
11
|
+
function preserveWidgetContext(newState) {
|
|
12
|
+
if (newState === null) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const currentWindowState = window.openai?.widgetState;
|
|
16
|
+
if (currentWindowState !== null &&
|
|
17
|
+
currentWindowState !== undefined &&
|
|
18
|
+
WIDGET_CONTEXT_KEY in currentWindowState) {
|
|
19
|
+
return {
|
|
20
|
+
...newState,
|
|
21
|
+
[WIDGET_CONTEXT_KEY]: currentWindowState[WIDGET_CONTEXT_KEY],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return newState;
|
|
25
|
+
}
|
|
26
|
+
export function useWidgetState(defaultState) {
|
|
27
|
+
const widgetStateFromWindow = useOpenAiGlobal("widgetState");
|
|
28
|
+
const [widgetState, _setWidgetState] = useState(() => {
|
|
29
|
+
if (widgetStateFromWindow !== null) {
|
|
30
|
+
return filterWidgetContext(widgetStateFromWindow);
|
|
31
|
+
}
|
|
32
|
+
return typeof defaultState === "function"
|
|
33
|
+
? defaultState()
|
|
34
|
+
: defaultState ?? null;
|
|
35
|
+
});
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
// Fixes openai implementation bug
|
|
38
|
+
if (widgetStateFromWindow !== null) {
|
|
39
|
+
_setWidgetState(filterWidgetContext(widgetStateFromWindow));
|
|
40
|
+
}
|
|
41
|
+
}, [widgetStateFromWindow]);
|
|
42
|
+
const setWidgetState = useCallback((state) => {
|
|
43
|
+
_setWidgetState((prevState) => {
|
|
44
|
+
const newState = typeof state === "function" ? state(prevState) : state;
|
|
45
|
+
const stateToSet = preserveWidgetContext(newState);
|
|
46
|
+
if (stateToSet !== null) {
|
|
47
|
+
window.openai.setWidgetState(stateToSet);
|
|
48
|
+
}
|
|
49
|
+
return filterWidgetContext(stateToSet);
|
|
50
|
+
});
|
|
51
|
+
}, []);
|
|
52
|
+
return [widgetState, setWidgetState];
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=use-widget-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-widget-state.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-widget-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAuB,MAAM,OAAO,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,kBAAkB,GAAG,kBAA2B,CAAC;AAEvD,SAAS,mBAAmB,CAC1B,KAAe;IAEf,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,EAAE,GAAG,aAAa,EAAE,GAAG,KAErD,CAAC;IAEF,OAAO,aAAkB,CAAC;AAC5B,CAAC;AAED,SAAS,qBAAqB,CAC5B,QAAkB;IAElB,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,WAG7B,CAAC;IAEd,IACE,kBAAkB,KAAK,IAAI;QAC3B,kBAAkB,KAAK,SAAS;QAChC,kBAAkB,IAAI,kBAAkB,EACxC,CAAC;QACD,OAAO;YACL,GAAG,QAAQ;YACX,CAAC,kB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,OAAO,CAAC,WAAW,EAAE,cAAc,CAAU,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useWidgetState } from "./use-widget-state.js";
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
|
|
3
|
+
import { renderHook, act } from "@testing-library/react";
|
|
4
|
+
describe("useWidgetState", () => {
|
|
5
|
+
let OpenaiMock;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
OpenaiMock = {
|
|
8
|
+
widgetState: null,
|
|
9
|
+
setWidgetState: vi.fn().mockResolvedValue(undefined),
|
|
10
|
+
};
|
|
11
|
+
vi.stubGlobal("openai", OpenaiMock);
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
vi.unstubAllGlobals();
|
|
15
|
+
vi.resetAllMocks();
|
|
16
|
+
});
|
|
17
|
+
const defaultState = { count: 0, name: "test" };
|
|
18
|
+
const windowState = { count: 5, name: "window" };
|
|
19
|
+
it("should initialize with default state when window.openai.widgetState is null", () => {
|
|
20
|
+
OpenaiMock.widgetState = null;
|
|
21
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
22
|
+
expect(result.current[0]).toEqual(defaultState);
|
|
23
|
+
});
|
|
24
|
+
it("should initialize with window.openai.widgetState when available", () => {
|
|
25
|
+
OpenaiMock.widgetState = windowState;
|
|
26
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
27
|
+
expect(result.current[0]).toEqual(windowState);
|
|
28
|
+
});
|
|
29
|
+
it("should call window.openai.setWidgetState when setWidgetState is called with a new state", async () => {
|
|
30
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
31
|
+
const newState = { count: 10, name: "updated" };
|
|
32
|
+
act(() => {
|
|
33
|
+
result.current[1](newState);
|
|
34
|
+
});
|
|
35
|
+
expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith(newState);
|
|
36
|
+
expect(result.current[0]).toEqual(newState);
|
|
37
|
+
});
|
|
38
|
+
it("should call window.openai.setWidgetState when setWidgetState is called with a function updater", async () => {
|
|
39
|
+
const { result } = renderHook(() => useWidgetState(defaultState));
|
|
40
|
+
act(() => {
|
|
41
|
+
result.current[1]((prev) => ({ ...prev, count: prev.count + 1 }));
|
|
42
|
+
});
|
|
43
|
+
expect(OpenaiMock.setWidgetState).toHaveBeenCalledWith({
|
|
44
|
+
count: 1,
|
|
45
|
+
name: "test",
|
|
46
|
+
});
|
|
47
|
+
expect(result.current[0]).toEqual({ count: 1, name: "test" });
|
|
48
|
+
});
|
|
49
|
+
it("should update state when window.openai.widgetState changes", () => {
|
|
50
|
+
OpenaiMock.widgetState = defaultState;
|
|
51
|
+
const { result, rerender } = renderHook(() => useWidgetState(defaultState));
|
|
52
|
+
expect(result.current[0]).toEqual(defaultState);
|
|
53
|
+
// Simulate window.openai.widgetState changing
|
|
54
|
+
OpenaiMock.widgetState = windowState;
|
|
55
|
+
// Trigger re-render to simulate the useEffect running
|
|
56
|
+
rerender();
|
|
57
|
+
expect(result.current[0]).toEqual(windowState);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=use-widget-state.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-widget-state.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-widget-state.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAEzD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,IAAI,UAA0D,CAAC;IAE/D,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,WAA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Q,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;QAE5E,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAEhD,8CAA8C;QAC9C,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;QACrC,sDAAsD;QACtD,QAAQ,EAAE,CAAC;QAEX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/web/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
|
-
export { useToolOutput } from "./use-tool-output.js";
|
|
3
1
|
export * from "./types.js";
|
|
2
|
+
export * from "./llm-describe.js";
|
|
4
3
|
export { mountWidget } from "./mount-widget.js";
|
|
5
|
-
export { skybridge } from "./plugin.js";
|
|
4
|
+
export { skybridge } from "./plugin/plugin.js";
|
|
5
|
+
export * from "./hooks/index.js";
|
package/dist/src/web/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
|
-
export { useToolOutput } from "./use-tool-output.js";
|
|
3
1
|
export * from "./types.js";
|
|
2
|
+
export * from "./llm-describe.js";
|
|
4
3
|
export { mountWidget } from "./mount-widget.js";
|
|
5
|
-
export { skybridge } from "./plugin.js";
|
|
4
|
+
export { skybridge } from "./plugin/plugin.js";
|
|
5
|
+
export * from "./hooks/index.js";
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type LLMDescribeContent = string;
|
|
3
|
+
export interface LLMDescribeNode {
|
|
4
|
+
id: string;
|
|
5
|
+
parentId: string | null;
|
|
6
|
+
content: string | null;
|
|
7
|
+
}
|
|
8
|
+
interface LLMDescribeProps {
|
|
9
|
+
content: LLMDescribeContent | null | undefined;
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare function LLMDescribe({ content, children }: LLMDescribeProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useId, } from "react";
|
|
3
|
+
const nodes = new Map();
|
|
4
|
+
function setNode(node) {
|
|
5
|
+
nodes.set(node.id, node);
|
|
6
|
+
onChange();
|
|
7
|
+
}
|
|
8
|
+
function removeNode(id) {
|
|
9
|
+
nodes.delete(id);
|
|
10
|
+
onChange();
|
|
11
|
+
}
|
|
12
|
+
function onChange() {
|
|
13
|
+
const description = getLLMDescriptionString();
|
|
14
|
+
window.openai.setWidgetState({
|
|
15
|
+
...window.openai.widgetState,
|
|
16
|
+
__widget_context: description,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const ParentIdContext = createContext(null);
|
|
20
|
+
export function LLMDescribe({ content, children }) {
|
|
21
|
+
const parentId = useContext(ParentIdContext);
|
|
22
|
+
const id = useId();
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
setNode({
|
|
25
|
+
id,
|
|
26
|
+
parentId,
|
|
27
|
+
content: content ?? null,
|
|
28
|
+
});
|
|
29
|
+
return () => {
|
|
30
|
+
removeNode(id);
|
|
31
|
+
};
|
|
32
|
+
}, [id, parentId, content]);
|
|
33
|
+
return (_jsx(ParentIdContext.Provider, { value: id, children: children }));
|
|
34
|
+
}
|
|
35
|
+
function getLLMDescriptionString() {
|
|
36
|
+
const byParent = new Map();
|
|
37
|
+
for (const node of Array.from(nodes.values())) {
|
|
38
|
+
const key = node.parentId ?? null;
|
|
39
|
+
if (!byParent.has(key))
|
|
40
|
+
byParent.set(key, []);
|
|
41
|
+
byParent.get(key).push(node);
|
|
42
|
+
}
|
|
43
|
+
for (const list of byParent.values()) {
|
|
44
|
+
list.sort((a, b) => a.id.localeCompare(b.id));
|
|
45
|
+
}
|
|
46
|
+
const lines = [];
|
|
47
|
+
function traverseTree(parentId, depth) {
|
|
48
|
+
const children = byParent.get(parentId);
|
|
49
|
+
if (!children)
|
|
50
|
+
return;
|
|
51
|
+
for (const child of children) {
|
|
52
|
+
if (child.content && child.content.trim()) {
|
|
53
|
+
const indent = " ".repeat(depth);
|
|
54
|
+
lines.push(`${indent}- ${child.content.trim()}`);
|
|
55
|
+
}
|
|
56
|
+
traverseTree(child.id, depth + 1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
traverseTree(null, 0);
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=llm-describe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-describe.js","sourceRoot":"","sources":["../../../src/web/llm-describe.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,KAAK,GAEN,MAAM,OAAO,CAAC;AAUf,MAAM,KAAK,GAAG,IAAI,GAAG,EAA2B,CAAC;AAEjD,SAAS,OAAO,CAAC,IAAqB;IACpC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EA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
|
|
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,96 @@
|
|
|
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.hasLLMDescribeImport = false;
|
|
9
|
+
state.needsLLMDescribeImport = 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: "LLMDescribe" }));
|
|
17
|
+
if (hasSpecifier) {
|
|
18
|
+
state.hasLLMDescribeImport = true;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
exit(path, state) {
|
|
24
|
+
if (state.needsLLMDescribeImport && !state.hasLLMDescribeImport) {
|
|
25
|
+
const importDecl = t.importDeclaration([
|
|
26
|
+
t.importSpecifier(t.identifier("LLMDescribe"), t.identifier("LLMDescribe")),
|
|
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 attrs = opening.attributes;
|
|
35
|
+
const llmAttrIndex = attrs.findIndex((attr) => t.isJSXAttribute(attr) &&
|
|
36
|
+
t.isJSXIdentifier(attr.name, { name: "data-llm" }));
|
|
37
|
+
if (llmAttrIndex === -1)
|
|
38
|
+
return;
|
|
39
|
+
const llmAttr = attrs[llmAttrIndex];
|
|
40
|
+
const newAttrs = [...attrs];
|
|
41
|
+
newAttrs.splice(llmAttrIndex, 1);
|
|
42
|
+
opening.attributes = newAttrs;
|
|
43
|
+
let contentExpression;
|
|
44
|
+
if (!llmAttr.value) {
|
|
45
|
+
contentExpression = t.stringLiteral("");
|
|
46
|
+
}
|
|
47
|
+
else if (t.isStringLiteral(llmAttr.value)) {
|
|
48
|
+
contentExpression = llmAttr.value;
|
|
49
|
+
}
|
|
50
|
+
else if (t.isJSXExpressionContainer(llmAttr.value)) {
|
|
51
|
+
contentExpression = llmAttr.value.expression;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const contentAttr = t.jsxAttribute(t.jsxIdentifier("content"), t.isStringLiteral(contentExpression)
|
|
57
|
+
? contentExpression
|
|
58
|
+
: t.jsxExpressionContainer(contentExpression));
|
|
59
|
+
const llmOpening = t.jsxOpeningElement(t.jsxIdentifier("LLMDescribe"), [
|
|
60
|
+
contentAttr,
|
|
61
|
+
]);
|
|
62
|
+
const llmClosing = t.jsxClosingElement(t.jsxIdentifier("LLMDescribe"));
|
|
63
|
+
const wrapped = t.jsxElement(llmOpening, llmClosing, [path.node], false);
|
|
64
|
+
state.needsLLMDescribeImport = true;
|
|
65
|
+
path.replaceWith(wrapped);
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export const transform = async (code, id) => {
|
|
71
|
+
if (!/\.(jsx|tsx)$/.test(id)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (id.includes("node_modules")) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
// Dynamic import to ensure @babel/core is only loaded in Node.js context
|
|
78
|
+
const { types: t, transformSync } = await import("@babel/core");
|
|
79
|
+
const babelOptions = {
|
|
80
|
+
plugins: [createBabelPlugin(t)],
|
|
81
|
+
parserOpts: {
|
|
82
|
+
plugins: ["jsx", "typescript"],
|
|
83
|
+
},
|
|
84
|
+
filename: id,
|
|
85
|
+
sourceFileName: id,
|
|
86
|
+
};
|
|
87
|
+
const result = transformSync(code, babelOptions);
|
|
88
|
+
if (!result || !result.code) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
code: result.code,
|
|
93
|
+
map: result.map || null,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=data-llm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-llm.js","sourceRoot":"","sources":["../../../../src/web/plugin/data-llm.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAO1C,SAAS,iBAAiB,CAAC,CAAe;IACxC,OAAO;QACL,IAAI,EAAE,gBAAgB;QAEtB,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,KAAK,CAAC,IAAI,EAAE,KAAK;oBACf,KAAK,CAAC,oBAAoB,GAAG,KAAK,CAAC;oBACnC,KAAK,CAAC,sBAAsB,GAAG,KAAK,CAAC;oBAErC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;wBAClC,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC;4BAAE,SAAS;wBAC3C,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,iBAAiB;4BAAE,SAAS;wBAEtD,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CACvC,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;4BACtB,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,IAAI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AS,GAAG,KAAK,EAAE,IAAY,EAAE,EAAU,EAAE,EAAE;IAC1D,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,yEAAyE;IACzE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAEhE,MAAM,YAAY,GAAqB;QACrC,OAAO,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAC/B,UAAU,EAAE;YACV,OAAO,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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { transform as dataLlmTransform } from "./data-llm.js";
|
|
1
2
|
export function skybridge() {
|
|
2
3
|
return {
|
|
3
4
|
name: "skybridge",
|
|
@@ -23,6 +24,10 @@ export function skybridge() {
|
|
|
23
24
|
},
|
|
24
25
|
};
|
|
25
26
|
},
|
|
27
|
+
enforce: "pre",
|
|
28
|
+
async transform(code, id) {
|
|
29
|
+
return await dataLlmTransform(code, id);
|
|
30
|
+
},
|
|
26
31
|
};
|
|
27
32
|
}
|
|
28
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,eAAe,CAAC;AAE9D,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"}
|
package/dist/src/web/types.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
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 =
|
|
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 |
|
|
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:
|
|
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;
|
package/dist/src/web/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/vitest.config.js
CHANGED
|
@@ -1 +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;
|
|
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.
|
|
3
|
+
"version": "0.0.0-dev.bd84fae",
|
|
4
4
|
"description": "Skybridge is a framework for building ChatGPT apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,12 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsc && pnpm run build:templates",
|
|
21
21
|
"build:templates": "cp -r src/server/templates dist/src/server/",
|
|
22
|
-
"test": "
|
|
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"
|
|
23
28
|
},
|
|
24
29
|
"keywords": [
|
|
25
30
|
"chatgpt",
|
|
@@ -34,6 +39,7 @@
|
|
|
34
39
|
"react-dom": ">=18.0.0"
|
|
35
40
|
},
|
|
36
41
|
"dependencies": {
|
|
42
|
+
"@babel/core": "^7.28.5",
|
|
37
43
|
"@modelcontextprotocol/sdk": "^1.20.0",
|
|
38
44
|
"cors": "^2.8.5",
|
|
39
45
|
"express": "^5.1.0",
|
|
@@ -42,7 +48,10 @@
|
|
|
42
48
|
"zod": "^3.25.51"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
51
|
+
"@testing-library/dom": "^10.4.1",
|
|
52
|
+
"@testing-library/react": "^16.3.0",
|
|
45
53
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
54
|
+
"@types/babel__core": "^7.20.5",
|
|
46
55
|
"@types/cors": "^2.8.19",
|
|
47
56
|
"@types/express": "^5.0.3",
|
|
48
57
|
"@types/jsdom": "^21.1.6",
|
package/dist/src/test/setup.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/test/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,+CAA+C;AAC/C,MAAM,CAAC,OAAO,GAAG;IACf,GAAG,OAAO;IACV,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;IACd,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;IACb,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;CACb,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin.ts"],"names":[],"mappings":"AAEA,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,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CAAC,sBAAsB,EAAE,eAAe,EAAE;YAC/D,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC;QACtE,CAAC,CAAC;IACJ,CAAC,EACD,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-tool-output.js","sourceRoot":"","sources":["../../../src/web/use-tool-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,UAAU,aAAa;IAC3B,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;AACvC,CAAC"}
|
|
File without changes
|
|
File without changes
|