@apollo/client-ai-apps 0.3.2 → 0.4.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/.github/workflows/pr.yaml +52 -3
- package/.github/workflows/prep-release.yml +38 -0
- package/.github/workflows/release.yaml +8 -4
- package/.github/workflows/verify-changeset.yml +58 -0
- package/CHANGELOG.md +88 -0
- package/dist/core/ApolloClient.d.ts +3 -2
- package/dist/core/ApolloClient.d.ts.map +1 -0
- package/dist/core/ApolloClient.js +65 -0
- package/dist/core/ApolloClient.js.map +1 -0
- package/dist/index.d.ts +18 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -279
- package/dist/index.js.map +1 -0
- package/dist/link/ToolCallLink.d.ts +1 -0
- package/dist/link/ToolCallLink.d.ts.map +1 -0
- package/dist/link/ToolCallLink.js +39 -0
- package/dist/link/ToolCallLink.js.map +1 -0
- package/dist/react/ApolloProvider.d.ts +4 -3
- package/dist/react/ApolloProvider.d.ts.map +1 -0
- package/dist/react/ApolloProvider.js +30 -0
- package/dist/react/ApolloProvider.js.map +1 -0
- package/dist/react/context/ToolUseContext.d.ts +4 -3
- package/dist/react/context/ToolUseContext.d.ts.map +1 -0
- package/dist/react/context/ToolUseContext.js +11 -0
- package/dist/react/context/ToolUseContext.js.map +1 -0
- package/dist/react/hooks/useCallTool.d.ts +4 -0
- package/dist/react/hooks/useCallTool.d.ts.map +1 -0
- package/dist/react/hooks/useCallTool.js +5 -0
- package/dist/react/hooks/useCallTool.js.map +1 -0
- package/dist/react/hooks/useOpenAiGlobal.d.ts +2 -1
- package/dist/react/hooks/useOpenAiGlobal.d.ts.map +1 -0
- package/dist/react/hooks/useOpenAiGlobal.js +20 -0
- package/dist/react/hooks/useOpenAiGlobal.js.map +1 -0
- package/dist/react/hooks/useOpenExternal.d.ts +1 -0
- package/dist/react/hooks/useOpenExternal.d.ts.map +1 -0
- package/dist/react/hooks/useOpenExternal.js +5 -0
- package/dist/react/hooks/useOpenExternal.js.map +1 -0
- package/dist/react/hooks/useRequestDisplayMode.d.ts +2 -1
- package/dist/react/hooks/useRequestDisplayMode.d.ts.map +1 -0
- package/dist/react/hooks/useRequestDisplayMode.js +6 -0
- package/dist/react/hooks/useRequestDisplayMode.js.map +1 -0
- package/dist/react/hooks/useSendFollowUpMessage.d.ts +1 -0
- package/dist/react/hooks/useSendFollowUpMessage.d.ts.map +1 -0
- package/dist/react/hooks/useSendFollowUpMessage.js +8 -0
- package/dist/react/hooks/useSendFollowUpMessage.js.map +1 -0
- package/dist/react/hooks/useToolEffect.d.ts +1 -0
- package/dist/react/hooks/useToolEffect.d.ts.map +1 -0
- package/dist/react/hooks/useToolEffect.js +28 -0
- package/dist/react/hooks/useToolEffect.js.map +1 -0
- package/dist/react/hooks/useToolInput.d.ts +1 -0
- package/dist/react/hooks/useToolInput.d.ts.map +1 -0
- package/dist/react/hooks/useToolInput.js +6 -0
- package/dist/react/hooks/useToolInput.js.map +1 -0
- package/dist/react/hooks/useToolName.d.ts +1 -0
- package/dist/react/hooks/useToolName.d.ts.map +1 -0
- package/dist/react/hooks/useToolName.js +6 -0
- package/dist/react/hooks/useToolName.js.map +1 -0
- package/dist/react/hooks/useToolOutput.d.ts +2 -1
- package/dist/react/hooks/useToolOutput.d.ts.map +1 -0
- package/dist/react/hooks/useToolOutput.js +5 -0
- package/dist/react/hooks/useToolOutput.js.map +1 -0
- package/dist/react/hooks/useToolResponseMetadata.d.ts +2 -1
- package/dist/react/hooks/useToolResponseMetadata.d.ts.map +1 -0
- package/dist/react/hooks/useToolResponseMetadata.js +5 -0
- package/dist/react/hooks/useToolResponseMetadata.js.map +1 -0
- package/dist/react/hooks/useWidgetState.d.ts +3 -2
- package/dist/react/hooks/useWidgetState.d.ts.map +1 -0
- package/dist/react/hooks/useWidgetState.js +27 -0
- package/dist/react/hooks/useWidgetState.js.map +1 -0
- package/dist/types/application-manifest.d.ts +15 -0
- package/dist/types/application-manifest.d.ts.map +1 -0
- package/dist/types/application-manifest.js +2 -0
- package/dist/types/application-manifest.js.map +1 -0
- package/dist/types/openai.d.ts +1 -0
- package/dist/types/openai.d.ts.map +1 -0
- package/dist/types/openai.js +6 -0
- package/dist/types/openai.js.map +1 -0
- package/dist/vite/absolute_asset_imports_plugin.d.ts +1 -0
- package/dist/vite/absolute_asset_imports_plugin.d.ts.map +1 -0
- package/dist/vite/absolute_asset_imports_plugin.js +17 -0
- package/dist/vite/absolute_asset_imports_plugin.js.map +1 -0
- package/dist/vite/application_manifest_plugin.d.ts +2 -1
- package/dist/vite/application_manifest_plugin.d.ts.map +1 -0
- package/dist/vite/application_manifest_plugin.js +317 -0
- package/dist/vite/application_manifest_plugin.js.map +1 -0
- package/dist/vite/index.d.ts +3 -2
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +3 -307
- package/dist/vite/index.js.map +1 -0
- package/knope.toml +63 -0
- package/package.json +19 -11
- package/src/core/ApolloClient.ts +10 -5
- package/src/core/__tests__/ApolloClient.test.ts +33 -10
- package/src/index.ts +19 -18
- package/src/react/ApolloProvider.tsx +4 -3
- package/src/react/__tests__/ApolloProvider.test.tsx +3 -3
- package/src/react/context/ToolUseContext.tsx +2 -1
- package/src/react/hooks/__tests__/useCallTool.test.ts +1 -1
- package/src/react/hooks/__tests__/useOpenAiGlobal.test.ts +6 -6
- package/src/react/hooks/__tests__/useOpenExternal.test.tsx +2 -2
- package/src/react/hooks/__tests__/useRequestDisplayMode.test.ts +2 -2
- package/src/react/hooks/__tests__/useSendFollowUpMessage.test.ts +1 -1
- package/src/react/hooks/__tests__/useToolEffect.test.tsx +2 -2
- package/src/react/hooks/__tests__/useToolInput.test.ts +1 -1
- package/src/react/hooks/__tests__/useToolName.test.ts +1 -1
- package/src/react/hooks/__tests__/useToolOutput.test.tsx +2 -2
- package/src/react/hooks/__tests__/useToolResponseMetadata.test.tsx +2 -2
- package/src/react/hooks/__tests__/useWidgetState.test.tsx +2 -2
- package/src/react/hooks/useOpenAiGlobal.ts +2 -5
- package/src/react/hooks/useOpenExternal.ts +1 -1
- package/src/react/hooks/useRequestDisplayMode.ts +1 -1
- package/src/react/hooks/useToolEffect.tsx +3 -3
- package/src/react/hooks/useToolInput.ts +1 -1
- package/src/react/hooks/useToolName.ts +1 -1
- package/src/react/hooks/useToolOutput.ts +1 -1
- package/src/react/hooks/useToolResponseMetadata.ts +1 -1
- package/src/react/hooks/useWidgetState.ts +4 -3
- package/src/testing/internal/index.ts +2 -2
- package/src/testing/internal/matchers/index.ts +1 -1
- package/src/testing/internal/matchers/toRerender.ts +2 -2
- package/src/testing/internal/matchers/{index.d.ts → types.ts} +1 -1
- package/src/testing/internal/openai/dispatchStateChange.ts +1 -1
- package/src/testing/internal/openai/stubOpenAiGlobals.ts +6 -2
- package/src/types/application-manifest.ts +16 -0
- package/src/vite/__tests__/absolute_asset_imports_plugin.test.ts +2 -2
- package/src/vite/__tests__/application_manifest_plugin.test.ts +460 -240
- package/src/vite/application_manifest_plugin.ts +253 -93
- package/src/vite/index.ts +2 -2
- package/tsconfig.base.build.json +13 -0
- package/tsconfig.base.json +21 -0
- package/tsconfig.config.json +9 -0
- package/tsconfig.json +10 -0
- package/tsconfig.src.build.json +14 -0
- package/tsconfig.src.json +17 -0
- package/tsconfig.test.json +20 -0
- package/tsconfig.vite.build.json +6 -0
- package/tsconfig.vite.json +16 -0
- package/scripts/build-vite.mjs +0 -18
- package/scripts/build.mjs +0 -7
- package/scripts/shared.mjs +0 -9
package/dist/index.js
CHANGED
|
@@ -1,279 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// src/react/hooks/useOpenAiGlobal.ts
|
|
19
|
-
import { useSyncExternalStore, useCallback } from "react";
|
|
20
|
-
function useOpenAiGlobal(key) {
|
|
21
|
-
return useSyncExternalStore(
|
|
22
|
-
useCallback((onChange) => {
|
|
23
|
-
const handleSetGlobal = (event) => {
|
|
24
|
-
const value = event.detail.globals[key];
|
|
25
|
-
if (value === void 0) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
onChange();
|
|
29
|
-
};
|
|
30
|
-
window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
|
|
31
|
-
passive: true
|
|
32
|
-
});
|
|
33
|
-
return () => {
|
|
34
|
-
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
35
|
-
};
|
|
36
|
-
}, []),
|
|
37
|
-
() => window.openai[key]
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/react/hooks/useToolName.ts
|
|
42
|
-
var useToolName = () => {
|
|
43
|
-
const toolResponseMetadata = useOpenAiGlobal("toolResponseMetadata");
|
|
44
|
-
return toolResponseMetadata?.toolName;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// src/react/hooks/useToolInput.ts
|
|
48
|
-
var useToolInput = () => {
|
|
49
|
-
const toolInput = useOpenAiGlobal("toolInput");
|
|
50
|
-
return toolInput;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/react/hooks/useSendFollowUpMessage.ts
|
|
54
|
-
var useSendFollowUpMessage = () => {
|
|
55
|
-
return async (prompt) => {
|
|
56
|
-
await window.openai?.sendFollowUpMessage({
|
|
57
|
-
prompt
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// src/react/hooks/useRequestDisplayMode.ts
|
|
63
|
-
var useRequestDisplayMode = () => {
|
|
64
|
-
return async (args) => {
|
|
65
|
-
return await window.openai?.requestDisplayMode(args);
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// src/react/hooks/useToolEffect.tsx
|
|
70
|
-
import { useEffect } from "react";
|
|
71
|
-
var useToolEffect = (toolName, effect, deps = []) => {
|
|
72
|
-
const ctx = useToolUseState();
|
|
73
|
-
const fullToolName = useToolName();
|
|
74
|
-
const toolInput = useToolInput();
|
|
75
|
-
if (!ctx)
|
|
76
|
-
throw new Error("useToolEffect must be used within ToolUseProvider");
|
|
77
|
-
const toolNames = Array.isArray(toolName) ? toolName : [toolName];
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
const matches = toolNames.some(
|
|
80
|
-
(name) => fullToolName === `${ctx.appName}--${name}`
|
|
81
|
-
);
|
|
82
|
-
if (!ctx.hasNavigated && matches) {
|
|
83
|
-
effect(toolInput);
|
|
84
|
-
ctx.setHasNavigated(true);
|
|
85
|
-
}
|
|
86
|
-
}, [
|
|
87
|
-
ctx.hasNavigated,
|
|
88
|
-
ctx.setHasNavigated,
|
|
89
|
-
ctx.appName,
|
|
90
|
-
toolNames,
|
|
91
|
-
fullToolName,
|
|
92
|
-
toolInput,
|
|
93
|
-
...deps
|
|
94
|
-
]);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// src/react/hooks/useOpenExternal.ts
|
|
98
|
-
import { useCallback as useCallback2 } from "react";
|
|
99
|
-
function useOpenExternal() {
|
|
100
|
-
return useCallback2(
|
|
101
|
-
(...args) => window.openai.openExternal(...args),
|
|
102
|
-
[]
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// src/react/hooks/useToolOutput.ts
|
|
107
|
-
function useToolOutput() {
|
|
108
|
-
return useOpenAiGlobal("toolOutput") ?? null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// src/react/hooks/useToolResponseMetadata.ts
|
|
112
|
-
function useToolResponseMetadata() {
|
|
113
|
-
return useOpenAiGlobal("toolResponseMetadata") ?? null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/react/hooks/useWidgetState.ts
|
|
117
|
-
import { useCallback as useCallback3, useState as useState2 } from "react";
|
|
118
|
-
function useWidgetState(defaultState) {
|
|
119
|
-
const widgetStateFromWindow = useOpenAiGlobal("widgetState");
|
|
120
|
-
const [previousWidgetStateFromWindow, setPreviousWidgetStateFromWindow] = useState2(widgetStateFromWindow);
|
|
121
|
-
let [widgetState, _setWidgetState] = useState2(() => {
|
|
122
|
-
if (widgetStateFromWindow != null) {
|
|
123
|
-
return widgetStateFromWindow;
|
|
124
|
-
}
|
|
125
|
-
return typeof defaultState === "function" ? defaultState() : defaultState ?? null;
|
|
126
|
-
});
|
|
127
|
-
if (previousWidgetStateFromWindow !== widgetStateFromWindow) {
|
|
128
|
-
_setWidgetState(widgetState = widgetStateFromWindow);
|
|
129
|
-
setPreviousWidgetStateFromWindow(widgetStateFromWindow);
|
|
130
|
-
}
|
|
131
|
-
const setWidgetState = useCallback3((state) => {
|
|
132
|
-
_setWidgetState((prevState) => {
|
|
133
|
-
const newState = typeof state === "function" ? state(prevState) : state;
|
|
134
|
-
if (newState != null && typeof window !== "undefined") {
|
|
135
|
-
void window.openai?.setWidgetState?.(newState);
|
|
136
|
-
}
|
|
137
|
-
return newState;
|
|
138
|
-
});
|
|
139
|
-
}, []);
|
|
140
|
-
return [widgetState, setWidgetState];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// src/index.ts
|
|
144
|
-
export * from "@apollo/client";
|
|
145
|
-
|
|
146
|
-
// src/core/ApolloClient.ts
|
|
147
|
-
import { ApolloClient as BaseApolloClient } from "@apollo/client";
|
|
148
|
-
import { DocumentTransform } from "@apollo/client";
|
|
149
|
-
import { removeDirectivesFromDocument } from "@apollo/client/utilities/internal";
|
|
150
|
-
import { parse } from "graphql";
|
|
151
|
-
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
152
|
-
|
|
153
|
-
// src/link/ToolCallLink.ts
|
|
154
|
-
import { ApolloLink } from "@apollo/client";
|
|
155
|
-
import { from, map } from "rxjs";
|
|
156
|
-
import {
|
|
157
|
-
fallbackHttpConfig,
|
|
158
|
-
selectHttpOptionsAndBody
|
|
159
|
-
} from "@apollo/client/link/http";
|
|
160
|
-
var ToolCallLink = class extends ApolloLink {
|
|
161
|
-
request(operation) {
|
|
162
|
-
const context = operation.getContext();
|
|
163
|
-
const contextConfig = {
|
|
164
|
-
http: context.http,
|
|
165
|
-
options: context.fetchOptions,
|
|
166
|
-
credentials: context.credentials,
|
|
167
|
-
headers: context.headers
|
|
168
|
-
};
|
|
169
|
-
const { query, variables } = selectHttpOptionsAndBody(
|
|
170
|
-
operation,
|
|
171
|
-
fallbackHttpConfig,
|
|
172
|
-
contextConfig
|
|
173
|
-
).body;
|
|
174
|
-
return from(window.openai.callTool("execute", { query, variables })).pipe(
|
|
175
|
-
map((result) => ({ data: result.structuredContent.data }))
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
// src/core/ApolloClient.ts
|
|
181
|
-
var ApolloClient = class extends BaseApolloClient {
|
|
182
|
-
manifest;
|
|
183
|
-
constructor(options) {
|
|
184
|
-
const link = options.link ?? new ToolCallLink();
|
|
185
|
-
if (__DEV__) {
|
|
186
|
-
validateTerminatingLink(link);
|
|
187
|
-
}
|
|
188
|
-
super({
|
|
189
|
-
...options,
|
|
190
|
-
link,
|
|
191
|
-
// Strip out the prefetch/tool directives so they don't get sent with the operation to the server
|
|
192
|
-
documentTransform: new DocumentTransform((document) => {
|
|
193
|
-
return removeDirectivesFromDocument(
|
|
194
|
-
[{ name: "prefetch" }, { name: "tool" }],
|
|
195
|
-
document
|
|
196
|
-
);
|
|
197
|
-
})
|
|
198
|
-
});
|
|
199
|
-
this.manifest = options.manifest;
|
|
200
|
-
}
|
|
201
|
-
async prefetchData() {
|
|
202
|
-
this.manifest.operations.forEach((operation) => {
|
|
203
|
-
if (operation.prefetch && operation.prefetchID && window.openai.toolOutput?.prefetch?.[operation.prefetchID]) {
|
|
204
|
-
this.writeQuery({
|
|
205
|
-
query: parse(operation.body),
|
|
206
|
-
data: window.openai.toolOutput.prefetch[operation.prefetchID].data
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
if (operation.tools?.find(
|
|
210
|
-
(tool) => `${this.manifest.name}--${tool.name}` === window.openai.toolResponseMetadata?.toolName
|
|
211
|
-
)) {
|
|
212
|
-
const variables = Object.keys(window.openai.toolInput).reduce(
|
|
213
|
-
(obj, key) => operation.variables?.[key] ? { ...obj, [key]: window.openai.toolInput[key] } : obj,
|
|
214
|
-
{}
|
|
215
|
-
);
|
|
216
|
-
if (window.openai.toolOutput) {
|
|
217
|
-
this.writeQuery({
|
|
218
|
-
query: parse(operation.body),
|
|
219
|
-
data: window.openai.toolOutput.result.data,
|
|
220
|
-
variables
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
function validateTerminatingLink(link) {
|
|
228
|
-
let terminatingLink = link;
|
|
229
|
-
while (terminatingLink.right) {
|
|
230
|
-
terminatingLink = terminatingLink.right;
|
|
231
|
-
}
|
|
232
|
-
if (terminatingLink.constructor.name !== "ToolCallLink") {
|
|
233
|
-
throw new Error(
|
|
234
|
-
"The terminating link must be a `ToolCallLink`. If you are using a `split` link, ensure the `right` branch uses a `ToolCallLink` as the terminating link."
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// src/react/ApolloProvider.tsx
|
|
240
|
-
import React3, { useEffect as useEffect2, useState as useState3 } from "react";
|
|
241
|
-
import { ApolloProvider as BaseApolloProvider } from "@apollo/client/react";
|
|
242
|
-
var ApolloProvider = ({ children, client }) => {
|
|
243
|
-
const [hasPreloaded, setHasPreloaded] = useState3(false);
|
|
244
|
-
useEffect2(() => {
|
|
245
|
-
const prefetchData = async () => {
|
|
246
|
-
await client.prefetchData();
|
|
247
|
-
setHasPreloaded(true);
|
|
248
|
-
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData);
|
|
249
|
-
};
|
|
250
|
-
window.addEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData, {
|
|
251
|
-
passive: true
|
|
252
|
-
});
|
|
253
|
-
if (window.openai?.toolOutput) {
|
|
254
|
-
window.dispatchEvent(new CustomEvent(SET_GLOBALS_EVENT_TYPE));
|
|
255
|
-
}
|
|
256
|
-
return () => {
|
|
257
|
-
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData);
|
|
258
|
-
};
|
|
259
|
-
}, []);
|
|
260
|
-
return hasPreloaded ? /* @__PURE__ */ React3.createElement(BaseApolloProvider, { client }, children) : null;
|
|
261
|
-
};
|
|
262
|
-
export {
|
|
263
|
-
ApolloClient,
|
|
264
|
-
ApolloProvider,
|
|
265
|
-
SET_GLOBALS_EVENT_TYPE,
|
|
266
|
-
SetGlobalsEvent,
|
|
267
|
-
ToolCallLink,
|
|
268
|
-
ToolUseProvider,
|
|
269
|
-
useOpenAiGlobal,
|
|
270
|
-
useOpenExternal,
|
|
271
|
-
useRequestDisplayMode,
|
|
272
|
-
useSendFollowUpMessage,
|
|
273
|
-
useToolEffect,
|
|
274
|
-
useToolInput,
|
|
275
|
-
useToolName,
|
|
276
|
-
useToolOutput,
|
|
277
|
-
useToolResponseMetadata,
|
|
278
|
-
useWidgetState
|
|
279
|
-
};
|
|
1
|
+
export { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types/openai.js";
|
|
2
|
+
export { ToolUseProvider } from "./react/context/ToolUseContext.js";
|
|
3
|
+
export { useOpenAiGlobal } from "./react/hooks/useOpenAiGlobal.js";
|
|
4
|
+
export { useToolName } from "./react/hooks/useToolName.js";
|
|
5
|
+
export { useToolInput } from "./react/hooks/useToolInput.js";
|
|
6
|
+
export { useSendFollowUpMessage } from "./react/hooks/useSendFollowUpMessage.js";
|
|
7
|
+
export { useRequestDisplayMode } from "./react/hooks/useRequestDisplayMode.js";
|
|
8
|
+
export { useToolEffect } from "./react/hooks/useToolEffect.js";
|
|
9
|
+
export { useOpenExternal } from "./react/hooks/useOpenExternal.js";
|
|
10
|
+
export { useToolOutput } from "./react/hooks/useToolOutput.js";
|
|
11
|
+
export { useToolResponseMetadata } from "./react/hooks/useToolResponseMetadata.js";
|
|
12
|
+
export { useWidgetState } from "./react/hooks/useWidgetState.js";
|
|
13
|
+
export { ApolloClient } from "./core/ApolloClient.js";
|
|
14
|
+
export { ApolloProvider } from "./react/ApolloProvider.js";
|
|
15
|
+
export { ToolCallLink } from "./link/ToolCallLink.js";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAY5E,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export type {\n API,\n CallTool,\n DeviceType,\n DisplayMode,\n OpenAiGlobals,\n SafeArea,\n SafeAreaInsets,\n Theme,\n UserAgent,\n UnknownObject,\n} from \"./types/openai.js\";\nexport { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from \"./types/openai.js\";\n\nexport type {\n ApplicationManifest,\n ManifestOperation,\n ManifestTool,\n ManifestExtraInput,\n ManifestCsp,\n ManifestLabels,\n ManifestWidgetSettings,\n} from \"./types/application-manifest.js\";\n\nexport { ToolUseProvider } from \"./react/context/ToolUseContext.js\";\nexport { useOpenAiGlobal } from \"./react/hooks/useOpenAiGlobal.js\";\nexport { useToolName } from \"./react/hooks/useToolName.js\";\nexport { useToolInput } from \"./react/hooks/useToolInput.js\";\nexport { useSendFollowUpMessage } from \"./react/hooks/useSendFollowUpMessage.js\";\nexport { useRequestDisplayMode } from \"./react/hooks/useRequestDisplayMode.js\";\nexport { useToolEffect } from \"./react/hooks/useToolEffect.js\";\nexport { useOpenExternal } from \"./react/hooks/useOpenExternal.js\";\nexport { useToolOutput } from \"./react/hooks/useToolOutput.js\";\nexport { useToolResponseMetadata } from \"./react/hooks/useToolResponseMetadata.js\";\nexport { useWidgetState } from \"./react/hooks/useWidgetState.js\";\n\nexport { ApolloClient } from \"./core/ApolloClient.js\";\nexport { ApolloProvider } from \"./react/ApolloProvider.js\";\nexport { ToolCallLink } from \"./link/ToolCallLink.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallLink.d.ts","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAOxD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC;CAkBxE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ApolloLink, Observable } from "@apollo/client";
|
|
2
|
+
import { from, map } from "rxjs";
|
|
3
|
+
import { fallbackHttpConfig, selectHttpOptionsAndBody, } from "@apollo/client/link/http";
|
|
4
|
+
/**
|
|
5
|
+
* A terminating link that sends a GraphQL request through an agent tool call.
|
|
6
|
+
* When providing a custom link chain to `ApolloClient`, `ApolloClient` will
|
|
7
|
+
* validate that the terminating link is an instance of this link.
|
|
8
|
+
*
|
|
9
|
+
* @example Provding a custom link chain
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { ApolloLink } from "@apollo/client";
|
|
13
|
+
* import { ApolloClient, ToolCallLink } from "@apollo/client-ai-apps";
|
|
14
|
+
*
|
|
15
|
+
* const link = ApolloLink.from([
|
|
16
|
+
* ...otherLinks,
|
|
17
|
+
* new ToolCallLink()
|
|
18
|
+
* ]);
|
|
19
|
+
*
|
|
20
|
+
* const client = new ApolloClient({
|
|
21
|
+
* link,
|
|
22
|
+
* // ...
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class ToolCallLink extends ApolloLink {
|
|
27
|
+
request(operation) {
|
|
28
|
+
const context = operation.getContext();
|
|
29
|
+
const contextConfig = {
|
|
30
|
+
http: context.http,
|
|
31
|
+
options: context.fetchOptions,
|
|
32
|
+
credentials: context.credentials,
|
|
33
|
+
headers: context.headers,
|
|
34
|
+
};
|
|
35
|
+
const { query, variables } = selectHttpOptionsAndBody(operation, fallbackHttpConfig, contextConfig).body;
|
|
36
|
+
return from(window.openai.callTool("execute", { query, variables })).pipe(map((result) => ({ data: result.structuredContent.data })));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=ToolCallLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolCallLink.js","sourceRoot":"","sources":["../../src/link/ToolCallLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C,OAAO,CAAC,SAA+B;QACrC,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;QACvC,MAAM,aAAa,GAAG;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,OAAO,CAAC,YAAY;YAC7B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;QACF,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,wBAAwB,CACnD,SAAS,EACT,kBAAkB,EAClB,aAAa,CACd,CAAC,IAAI,CAAC;QAEP,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CACvE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,CAC3D,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ApolloLink, Observable } from \"@apollo/client\";\nimport { from, map } from \"rxjs\";\nimport {\n fallbackHttpConfig,\n selectHttpOptionsAndBody,\n} from \"@apollo/client/link/http\";\n\n/**\n * A terminating link that sends a GraphQL request through an agent tool call.\n * When providing a custom link chain to `ApolloClient`, `ApolloClient` will\n * validate that the terminating link is an instance of this link.\n *\n * @example Provding a custom link chain\n *\n * ```ts\n * import { ApolloLink } from \"@apollo/client\";\n * import { ApolloClient, ToolCallLink } from \"@apollo/client-ai-apps\";\n *\n * const link = ApolloLink.from([\n * ...otherLinks,\n * new ToolCallLink()\n * ]);\n *\n * const client = new ApolloClient({\n * link,\n * // ...\n * });\n * ```\n */\nexport class ToolCallLink extends ApolloLink {\n request(operation: ApolloLink.Operation): Observable<ApolloLink.Result> {\n const context = operation.getContext();\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n const { query, variables } = selectHttpOptionsAndBody(\n operation,\n fallbackHttpConfig,\n contextConfig\n ).body;\n\n return from(window.openai.callTool(\"execute\", { query, variables })).pipe(\n map((result) => ({ data: result.structuredContent.data }))\n );\n }\n}\n"]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ApolloClient } from "../core/ApolloClient";
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ApolloClient } from "../core/ApolloClient.js";
|
|
3
3
|
export declare namespace ApolloProvider {
|
|
4
4
|
interface Props {
|
|
5
5
|
children?: ReactNode;
|
|
6
6
|
client: ApolloClient;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export declare const ApolloProvider: ({ children, client }: ApolloProvider.Props) =>
|
|
9
|
+
export declare const ApolloProvider: ({ children, client }: ApolloProvider.Props) => import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
//# sourceMappingURL=ApolloProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApolloProvider.d.ts","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D,MAAM,CAAC,OAAO,WAAW,cAAc,CAAC;IACtC,UAAiB,KAAK;QACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;QACrB,MAAM,EAAE,YAAY,CAAC;KACtB;CACF;AAED,eAAO,MAAM,cAAc,GAAI,sBAAsB,cAAc,CAAC,KAAK,mDA6BxE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { ApolloProvider as BaseApolloProvider } from "@apollo/client/react";
|
|
4
|
+
import { SET_GLOBALS_EVENT_TYPE } from "../types/openai.js";
|
|
5
|
+
export const ApolloProvider = ({ children, client }) => {
|
|
6
|
+
const [hasPreloaded, setHasPreloaded] = useState(false);
|
|
7
|
+
// This is to prevent against a race condition. We don't know if window.openai will be available when this loads or if it will become available shortly after.
|
|
8
|
+
// So... we create the event listener and whenever it is available, then we can process the prefetch/tool data.
|
|
9
|
+
// In practice, this should be pretty much instant
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const prefetchData = async () => {
|
|
12
|
+
await client.prefetchData();
|
|
13
|
+
setHasPreloaded(true);
|
|
14
|
+
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData);
|
|
15
|
+
};
|
|
16
|
+
window.addEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData, {
|
|
17
|
+
passive: true,
|
|
18
|
+
});
|
|
19
|
+
if (window.openai?.toolOutput) {
|
|
20
|
+
window.dispatchEvent(new CustomEvent(SET_GLOBALS_EVENT_TYPE));
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData);
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
return hasPreloaded ?
|
|
27
|
+
_jsx(BaseApolloProvider, { client: client, children: children })
|
|
28
|
+
: null;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=ApolloProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApolloProvider.js","sourceRoot":"","sources":["../../src/react/ApolloProvider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAS5D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAwB,EAAE,EAAE;IAC3E,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,8JAA8J;IAC9J,+GAA+G;IAC/G,kDAAkD;IAClD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;YAC9B,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;YAC5B,eAAe,CAAC,IAAI,CAAC,CAAC;YACtB,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,YAAY,CAAC,CAAC;QACnE,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,YAAY,EAAE;YAC5D,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;YAC9B,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,YAAY,CAAC,CAAC;QACnE,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,YAAY,CAAC,CAAC;QACjB,KAAC,kBAAkB,IAAC,MAAM,EAAE,MAAM,YAAG,QAAQ,GAAsB;QACrE,CAAC,CAAC,IAAI,CAAC;AACX,CAAC,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { useEffect, useState } from \"react\";\nimport { ApolloProvider as BaseApolloProvider } from \"@apollo/client/react\";\nimport type { ApolloClient } from \"../core/ApolloClient.js\";\nimport { SET_GLOBALS_EVENT_TYPE } from \"../types/openai.js\";\n\nexport declare namespace ApolloProvider {\n export interface Props {\n children?: ReactNode;\n client: ApolloClient;\n }\n}\n\nexport const ApolloProvider = ({ children, client }: ApolloProvider.Props) => {\n const [hasPreloaded, setHasPreloaded] = useState(false);\n\n // This is to prevent against a race condition. We don't know if window.openai will be available when this loads or if it will become available shortly after.\n // So... we create the event listener and whenever it is available, then we can process the prefetch/tool data.\n // In practice, this should be pretty much instant\n useEffect(() => {\n const prefetchData = async () => {\n await client.prefetchData();\n setHasPreloaded(true);\n window.removeEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData);\n };\n\n window.addEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData, {\n passive: true,\n });\n\n if (window.openai?.toolOutput) {\n window.dispatchEvent(new CustomEvent(SET_GLOBALS_EVENT_TYPE));\n }\n\n return () => {\n window.removeEventListener(SET_GLOBALS_EVENT_TYPE, prefetchData);\n };\n }, []);\n\n return hasPreloaded ?\n <BaseApolloProvider client={client}>{children}</BaseApolloProvider>\n : null;\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
2
|
interface ToolUseState {
|
|
3
3
|
appName: string;
|
|
4
4
|
hasNavigated: boolean;
|
|
@@ -10,6 +10,7 @@ export declare namespace ToolUseProvider {
|
|
|
10
10
|
appName: string;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export declare function ToolUseProvider({ children, appName }: ToolUseProvider.Props):
|
|
14
|
-
export declare function useToolUseState(): ToolUseState;
|
|
13
|
+
export declare function ToolUseProvider({ children, appName }: ToolUseProvider.Props): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare function useToolUseState(): ToolUseState | null;
|
|
15
15
|
export {};
|
|
16
|
+
//# sourceMappingURL=ToolUseContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolUseContext.d.ts","sourceRoot":"","sources":["../../../src/react/context/ToolUseContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC;AAID,MAAM,CAAC,OAAO,WAAW,eAAe,CAAC;IACvC,UAAiB,KAAK;QACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,eAAe,CAAC,KAAK,2CAQ3E;AAED,wBAAgB,eAAe,wBAE9B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useState } from "react";
|
|
3
|
+
const ToolUseContext = createContext(null);
|
|
4
|
+
export function ToolUseProvider({ children, appName }) {
|
|
5
|
+
const [hasNavigated, setHasNavigated] = useState(false);
|
|
6
|
+
return (_jsx(ToolUseContext.Provider, { value: { hasNavigated, setHasNavigated, appName }, children: children }));
|
|
7
|
+
}
|
|
8
|
+
export function useToolUseState() {
|
|
9
|
+
return useContext(ToolUseContext);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ToolUseContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolUseContext.js","sourceRoot":"","sources":["../../../src/react/context/ToolUseContext.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAQ5D,MAAM,cAAc,GAAG,aAAa,CAAsB,IAAI,CAAC,CAAC;AAShE,MAAM,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAyB;IAC1E,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExD,OAAO,CACL,KAAC,cAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,YACvE,QAAQ,GACe,CAC3B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,cAAc,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import type { ReactNode } from \"react\";\nimport { createContext, useContext, useState } from \"react\";\n\ninterface ToolUseState {\n appName: string;\n hasNavigated: boolean;\n setHasNavigated: (v: boolean) => void;\n}\n\nconst ToolUseContext = createContext<ToolUseState | null>(null);\n\nexport declare namespace ToolUseProvider {\n export interface Props {\n children?: ReactNode;\n appName: string;\n }\n}\n\nexport function ToolUseProvider({ children, appName }: ToolUseProvider.Props) {\n const [hasNavigated, setHasNavigated] = useState(false);\n\n return (\n <ToolUseContext.Provider value={{ hasNavigated, setHasNavigated, appName }}>\n {children}\n </ToolUseContext.Provider>\n );\n}\n\nexport function useToolUseState() {\n return useContext(ToolUseContext);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCallTool.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useCallTool.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,KAC5C,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,eAAO,MAAM,WAAW,QAAO,iBAO9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCallTool.js","sourceRoot":"","sources":["../../../src/react/hooks/useCallTool.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,WAAW,GAAG,GAAsB,EAAE;IACjD,MAAM,QAAQ,GAAG,KAAK,EACpB,MAAc,EACd,YAAiD,EAAE,EACnD,EAAE,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEtD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["type UseCallToolResult = <K>(\n toolId: string,\n variables?: Record<string, unknown> | undefined\n) => Promise<K>;\n\nexport const useCallTool = (): UseCallToolResult => {\n const callTool = async (\n toolId: string,\n variables: Record<string, unknown> | undefined = {}\n ) => await window.openai?.callTool(toolId, variables);\n\n return callTool;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpenAiGlobal.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useOpenAiGlobal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG5E,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,aAAa,EAC3D,GAAG,EAAE,CAAC,GACL,aAAa,CAAC,CAAC,CAAC,CAsBlB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useSyncExternalStore, useCallback } from "react";
|
|
2
|
+
import { SET_GLOBALS_EVENT_TYPE } from "../../types/openai.js";
|
|
3
|
+
export function useOpenAiGlobal(key) {
|
|
4
|
+
return useSyncExternalStore(useCallback((onChange) => {
|
|
5
|
+
const handleSetGlobal = (event) => {
|
|
6
|
+
const value = event.detail.globals[key];
|
|
7
|
+
if (value === undefined) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
onChange();
|
|
11
|
+
};
|
|
12
|
+
window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
|
|
13
|
+
passive: true,
|
|
14
|
+
});
|
|
15
|
+
return () => {
|
|
16
|
+
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
17
|
+
};
|
|
18
|
+
}, []), () => window.openai[key]);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=useOpenAiGlobal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpenAiGlobal.js","sourceRoot":"","sources":["../../../src/react/hooks/useOpenAiGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,UAAU,eAAe,CAC7B,GAAM;IAEN,OAAO,oBAAoB,CACzB,WAAW,CAAC,CAAC,QAAQ,EAAE,EAAE;QACvB,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;YACjD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO;YACT,CAAC;YAED,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,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,EAAE,EAAE,CAAC,EACN,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CACzB,CAAC;AACJ,CAAC","sourcesContent":["import { useSyncExternalStore, useCallback } from \"react\";\nimport type { SetGlobalsEvent, OpenAiGlobals } from \"../../types/openai.js\";\nimport { SET_GLOBALS_EVENT_TYPE } from \"../../types/openai.js\";\n\nexport function useOpenAiGlobal<K extends keyof OpenAiGlobals>(\n key: K\n): OpenAiGlobals[K] {\n return useSyncExternalStore(\n useCallback((onChange) => {\n const handleSetGlobal = (event: SetGlobalsEvent) => {\n const value = event.detail.globals[key];\n if (value === undefined) {\n return;\n }\n\n onChange();\n };\n\n window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {\n passive: true,\n });\n\n return () => {\n window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);\n };\n }, []),\n () => window.openai[key]\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpenExternal.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useOpenExternal.ts"],"names":[],"mappings":"AAKA,wBAAgB,eAAe;;WAK9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpenExternal.js","sourceRoot":"","sources":["../../../src/react/hooks/useOpenExternal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAKpC,MAAM,UAAU,eAAe;IAC7B,OAAO,WAAW,CAChB,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,EAChD,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { useCallback } from \"react\";\nimport type { API } from \"../../types/openai.js\";\n\ntype OpenExternalFn = API<any>[\"openExternal\"];\n\nexport function useOpenExternal() {\n return useCallback<OpenExternalFn>(\n (...args) => window.openai.openExternal(...args),\n []\n );\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DisplayMode } from "../../types/openai";
|
|
1
|
+
import type { DisplayMode } from "../../types/openai.js";
|
|
2
2
|
export declare const useRequestDisplayMode: () => (args: {
|
|
3
3
|
mode: DisplayMode;
|
|
4
4
|
}) => Promise<{
|
|
5
5
|
mode: DisplayMode;
|
|
6
6
|
}>;
|
|
7
|
+
//# sourceMappingURL=useRequestDisplayMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestDisplayMode.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useRequestDisplayMode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,eAAO,MAAM,qBAAqB,SAClB,MAAM;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE;;EAG1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRequestDisplayMode.js","sourceRoot":"","sources":["../../../src/react/hooks/useRequestDisplayMode.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,OAAO,KAAK,EAAE,IAA2B,EAAE,EAAE;QAC3C,OAAO,MAAM,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { DisplayMode } from \"../../types/openai.js\";\n\nexport const useRequestDisplayMode = () => {\n return async (args: { mode: DisplayMode }) => {\n return await window.openai?.requestDisplayMode(args);\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSendFollowUpMessage.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useSendFollowUpMessage.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,SACnB,QAAQ,MAAM,kBAK7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSendFollowUpMessage.js","sourceRoot":"","sources":["../../../src/react/hooks/useSendFollowUpMessage.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,OAAO,KAAK,EAAE,MAAc,EAAE,EAAE;QAC9B,MAAM,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC;YACvC,MAAM;SACP,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export const useSendFollowUpMessage = () => {\n return async (prompt: string) => {\n await window.openai?.sendFollowUpMessage({\n prompt,\n });\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolEffect.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useToolEffect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAKzC,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,GAAG,MAAM,EAAE,EAC3B,QAAQ,CAAC,SAAS,EAAE,GAAG,KAAK,IAAI,EAChC,OAAM,KAAK,CAAC,cAAmB,SA4BhC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { useToolName } from "./useToolName.js";
|
|
3
|
+
import { useToolInput } from "./useToolInput.js";
|
|
4
|
+
import { useToolUseState } from "../context/ToolUseContext.js";
|
|
5
|
+
export const useToolEffect = (toolName, effect, deps = []) => {
|
|
6
|
+
const ctx = useToolUseState();
|
|
7
|
+
const fullToolName = useToolName();
|
|
8
|
+
const toolInput = useToolInput();
|
|
9
|
+
if (!ctx)
|
|
10
|
+
throw new Error("useToolEffect must be used within ToolUseProvider");
|
|
11
|
+
const toolNames = Array.isArray(toolName) ? toolName : [toolName];
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const matches = toolNames.some((name) => fullToolName === `${ctx.appName}--${name}`);
|
|
14
|
+
if (!ctx.hasNavigated && matches) {
|
|
15
|
+
effect(toolInput);
|
|
16
|
+
ctx.setHasNavigated(true);
|
|
17
|
+
}
|
|
18
|
+
}, [
|
|
19
|
+
ctx.hasNavigated,
|
|
20
|
+
ctx.setHasNavigated,
|
|
21
|
+
ctx.appName,
|
|
22
|
+
toolNames,
|
|
23
|
+
fullToolName,
|
|
24
|
+
toolInput,
|
|
25
|
+
...deps,
|
|
26
|
+
]);
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=useToolEffect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolEffect.js","sourceRoot":"","sources":["../../../src/react/hooks/useToolEffect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,QAA2B,EAC3B,MAAgC,EAChC,OAA6B,EAAE,EAC/B,EAAE;IACF,MAAM,GAAG,GAAG,eAAe,EAAE,CAAC;IAC9B,MAAM,YAAY,GAAG,WAAW,EAAE,CAAC;IACnC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,IAAI,CAAC,GAAG;QACN,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAEvE,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAElE,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAC5B,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,KAAK,GAAG,GAAG,CAAC,OAAO,KAAK,IAAI,EAAE,CACrD,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,EAAE,CAAC;YACjC,MAAM,CAAC,SAAS,CAAC,CAAC;YAClB,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC,EAAE;QACD,GAAG,CAAC,YAAY;QAChB,GAAG,CAAC,eAAe;QACnB,GAAG,CAAC,OAAO;QACX,SAAS;QACT,YAAY;QACZ,SAAS;QACT,GAAG,IAAI;KACR,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import React, { useEffect } from \"react\";\nimport { useToolName } from \"./useToolName.js\";\nimport { useToolInput } from \"./useToolInput.js\";\nimport { useToolUseState } from \"../context/ToolUseContext.js\";\n\nexport const useToolEffect = (\n toolName: string | string[],\n effect: (toolInput: any) => void,\n deps: React.DependencyList = []\n) => {\n const ctx = useToolUseState();\n const fullToolName = useToolName();\n const toolInput = useToolInput();\n if (!ctx)\n throw new Error(\"useToolEffect must be used within ToolUseProvider\");\n\n const toolNames = Array.isArray(toolName) ? toolName : [toolName];\n\n useEffect(() => {\n const matches = toolNames.some(\n (name) => fullToolName === `${ctx.appName}--${name}`\n );\n\n if (!ctx.hasNavigated && matches) {\n effect(toolInput);\n ctx.setHasNavigated(true);\n }\n }, [\n ctx.hasNavigated,\n ctx.setHasNavigated,\n ctx.appName,\n toolNames,\n fullToolName,\n toolInput,\n ...deps,\n ]);\n};\n"]}
|