@scalar/api-reference 1.44.3 → 1.44.6
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/CHANGELOG.md +95 -0
- package/dist/browser/standalone.js +19661 -19589
- package/dist/browser/webpack-stats.json +1 -1
- package/dist/components/AgentScalar/AgentScalarButton.vue.d.ts +3 -0
- package/dist/components/AgentScalar/AgentScalarButton.vue.d.ts.map +1 -0
- package/dist/components/AgentScalar/AgentScalarButton.vue.js +22 -0
- package/dist/components/AgentScalar/AgentScalarButton.vue2.js +4 -0
- package/dist/components/{AgentChat.vue.d.ts → AgentScalar/AgentScalarChatInterface.vue.d.ts} +4 -2
- package/dist/components/AgentScalar/AgentScalarChatInterface.vue.d.ts.map +1 -0
- package/dist/components/AgentScalar/AgentScalarChatInterface.vue.js +4 -0
- package/dist/components/{AgentChat.vue2.js → AgentScalar/AgentScalarChatInterface.vue2.js} +9 -7
- package/dist/components/AgentScalar/AgentScalarDrawer.vue.d.ts +12 -0
- package/dist/components/AgentScalar/AgentScalarDrawer.vue.d.ts.map +1 -0
- package/dist/components/AgentScalar/AgentScalarDrawer.vue.js +7 -0
- package/dist/components/AgentScalar/AgentScalarDrawer.vue2.js +53 -0
- package/dist/components/AgentScalar/AgentScalarTooltip.vue.d.ts +19 -0
- package/dist/components/AgentScalar/AgentScalarTooltip.vue.d.ts.map +1 -0
- package/dist/components/AgentScalar/AgentScalarTooltip.vue.js +35 -0
- package/dist/components/AgentScalar/AgentScalarTooltip.vue2.js +4 -0
- package/dist/components/AgentScalar/index.d.ts +4 -0
- package/dist/components/AgentScalar/index.d.ts.map +1 -0
- package/dist/components/ApiReference.vue.d.ts.map +1 -1
- package/dist/components/ApiReference.vue.js +1 -1
- package/dist/components/ApiReference.vue2.js +51 -70
- package/dist/components/Content/Schema/SchemaComposition.vue.d.ts +3 -2
- package/dist/components/Content/Schema/SchemaComposition.vue.d.ts.map +1 -1
- package/dist/components/Content/Schema/SchemaProperty.vue.d.ts.map +1 -1
- package/dist/components/Content/Schema/SchemaProperty.vue.js +1 -1
- package/dist/components/Content/Schema/SchemaProperty.vue2.js +1 -1
- package/dist/components/Content/Schema/helpers/get-ref-name.d.ts +1 -2
- package/dist/components/Content/Schema/helpers/get-ref-name.d.ts.map +1 -1
- package/dist/components/Content/Schema/helpers/get-ref-name.js +1 -5
- package/dist/components/Content/Schema/helpers/get-schema-type.d.ts +2 -1
- package/dist/components/Content/Schema/helpers/get-schema-type.d.ts.map +1 -1
- package/dist/components/Content/Schema/helpers/get-schema-type.js +7 -1
- package/dist/components/Content/Schema/helpers/optimize-value-for-display.d.ts +5 -1
- package/dist/components/Content/Schema/helpers/optimize-value-for-display.d.ts.map +1 -1
- package/dist/components/Content/Schema/helpers/optimize-value-for-display.js +2 -0
- package/dist/components/Content/Schema/helpers/schema-name.js +1 -1
- package/dist/components/MobileHeader.vue.js +2 -2
- package/dist/features/Operation/layouts/ModernLayout.vue.d.ts.map +1 -1
- package/dist/features/Operation/layouts/ModernLayout.vue.js +1 -1
- package/dist/features/Operation/layouts/ModernLayout.vue2.js +2 -0
- package/dist/features/ask-agent-button/AskAgentButton.vue.d.ts +3 -0
- package/dist/features/ask-agent-button/AskAgentButton.vue.d.ts.map +1 -0
- package/dist/features/ask-agent-button/AskAgentButton.vue.js +7 -0
- package/dist/features/ask-agent-button/AskAgentButton.vue2.js +47 -0
- package/dist/helpers/lazy-bus.d.ts.map +1 -1
- package/dist/helpers/lazy-bus.js +5 -3
- package/dist/helpers/storage.d.ts +2 -2
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/use-agent.d.ts +36 -0
- package/dist/hooks/use-agent.d.ts.map +1 -0
- package/dist/hooks/use-agent.js +42 -0
- package/dist/style.css +318 -244
- package/package.json +14 -14
- package/dist/components/AgentChat.vue.d.ts.map +0 -1
- package/dist/components/AgentChat.vue.js +0 -4
|
@@ -47,8 +47,14 @@ const getSchemaType = (valueOrRef) => {
|
|
|
47
47
|
if ("type" in value && value.type && value.contentEncoding) {
|
|
48
48
|
return `${value.type} • ${value.contentEncoding}`;
|
|
49
49
|
}
|
|
50
|
+
if ("originalRef" in valueOrRef && valueOrRef.originalRef) {
|
|
51
|
+
const refName = getRefName(valueOrRef.originalRef);
|
|
52
|
+
if (refName) {
|
|
53
|
+
return refName;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
50
56
|
if ("$ref" in valueOrRef) {
|
|
51
|
-
const refName = getRefName(valueOrRef);
|
|
57
|
+
const refName = getRefName(valueOrRef.$ref);
|
|
52
58
|
if (refName) {
|
|
53
59
|
return refName;
|
|
54
60
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { SchemaObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
|
|
2
|
+
/** We need to keep the original ref after we resolve for display purposes */
|
|
3
|
+
export type SchemaWithOriginalRef = SchemaObject & {
|
|
4
|
+
originalRef?: string;
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* Optimize the value by removing nulls from compositions and merging root properties.
|
|
4
8
|
*
|
|
5
9
|
* TODO: figure out what this does
|
|
6
10
|
*/
|
|
7
|
-
export declare function optimizeValueForDisplay(value: SchemaObject | undefined):
|
|
11
|
+
export declare function optimizeValueForDisplay(value: SchemaObject | undefined): SchemaWithOriginalRef | undefined;
|
|
8
12
|
//# sourceMappingURL=optimize-value-for-display.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimize-value-for-display.d.ts","sourceRoot":"","sources":["../../../../../src/components/Content/Schema/helpers/optimize-value-for-display.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAIhG;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"optimize-value-for-display.d.ts","sourceRoot":"","sources":["../../../../../src/components/Content/Schema/helpers/optimize-value-for-display.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAIhG,6EAA6E;AAC7E,MAAM,MAAM,qBAAqB,GAAG,YAAY,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3E;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,qBAAqB,GAAG,SAAS,CA0F1G"}
|
|
@@ -19,6 +19,8 @@ function optimizeValueForDisplay(value) {
|
|
|
19
19
|
const schema = getResolvedRef(_schema);
|
|
20
20
|
if ("type" in schema && schema.type === "null") {
|
|
21
21
|
acc.hasNullSchema = true;
|
|
22
|
+
} else if ("$ref" in _schema && _schema.$ref) {
|
|
23
|
+
acc.filteredSchemas.push({ ...schema, originalRef: _schema.$ref });
|
|
22
24
|
} else {
|
|
23
25
|
acc.filteredSchemas.push(schema);
|
|
24
26
|
}
|
|
@@ -20,7 +20,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
20
20
|
const emit = __emit;
|
|
21
21
|
const { mediaQueries } = useBreakpoints();
|
|
22
22
|
const variants = cva({
|
|
23
|
-
base: "items-center bg-b-1 sticky top-(--scalar-custom-header-height) z-10",
|
|
23
|
+
base: "items-center bg-b-1 sticky top-(--scalar-custom-header-height,0) z-10",
|
|
24
24
|
variants: {
|
|
25
25
|
open: {
|
|
26
26
|
true: "h-(--refs-sidebar-height) custom-scrollbar flex flex-col"
|
|
@@ -32,7 +32,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
32
32
|
});
|
|
33
33
|
return (_ctx, _cache) => {
|
|
34
34
|
return unref(mediaQueries).lg.value ? renderSlot(_ctx.$slots, "sidebar", normalizeProps(mergeProps({ key: 0 }, {
|
|
35
|
-
sidebarClasses: "sticky top-(--refs-header-height) h-(--refs-sidebar-height) [grid-area:navigation]"
|
|
35
|
+
sidebarClasses: "sticky top-(--refs-header-height) h-(--refs-sidebar-height) w-(--refs-sidebar-width) [grid-area:navigation]"
|
|
36
36
|
}))) : (openBlock(), createElementBlock("div", {
|
|
37
37
|
key: 1,
|
|
38
38
|
class: normalizeClass(["t-doc__header", unref(variants)({ open: __props.isSidebarOpen, lg: unref(mediaQueries).lg.value })])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModernLayout.vue.d.ts","sourceRoot":"","sources":["../../../../src/features/Operation/layouts/ModernLayout.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ModernLayout.vue.d.ts","sourceRoot":"","sources":["../../../../src/features/Operation/layouts/ModernLayout.vue"],"names":[],"mappings":"AA2PA,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,YAAY,EACb,MAAM,8DAA8D,CAAA;AAqBrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAMxE,KAAK,WAAW,GAAG,IAAI,CACnB,cAAc,EACd,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,aAAa,GAAG,iBAAiB,CACxE,GAAG;IACF,wCAAwC;IACxC,SAAS,EAAE,eAAe,CAAA;IAC1B,4CAA4C;IAC5C,cAAc,EAAE,YAAY,GAAG,IAAI,CAAA;IACnC,sDAAsD;IACtD,uBAAuB,EAAE,oBAAoB,EAAE,CAAA;CAChD,CAAC;;AA8fJ,wBAMG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _sfc_main from "./ModernLayout.vue2.js";
|
|
2
2
|
/* empty css */
|
|
3
3
|
import _export_sfc from "../../../_virtual/_plugin-vue_export-helper.js";
|
|
4
|
-
const ModernLayout = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
|
4
|
+
const ModernLayout = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-e67d0b83"]]);
|
|
5
5
|
export {
|
|
6
6
|
ModernLayout as default
|
|
7
7
|
};
|
|
@@ -5,6 +5,7 @@ import { ScalarIconWebhooksLogo } from "@scalar/icons";
|
|
|
5
5
|
import { getOperationStability, getOperationStabilityColor, isOperationDeprecated } from "@scalar/oas-utils/helpers";
|
|
6
6
|
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
7
7
|
import OperationPath from "../../../components/OperationPath.vue.js";
|
|
8
|
+
import AskAgentButton from "../../ask-agent-button/AskAgentButton.vue.js";
|
|
8
9
|
import _sfc_main$6 from "../components/callbacks/Callbacks.vue.js";
|
|
9
10
|
import _sfc_main$4 from "../components/OperationParameters.vue.js";
|
|
10
11
|
import _sfc_main$5 from "../components/OperationResponses.vue.js";
|
|
@@ -205,6 +206,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
205
206
|
!__props.isWebhook ? {
|
|
206
207
|
name: "footer",
|
|
207
208
|
fn: withCtx(() => [
|
|
209
|
+
createVNode(AskAgentButton),
|
|
208
210
|
!__props.options.hideTestRequestButton ? (openBlock(), createBlock(unref(TestRequestButton), {
|
|
209
211
|
key: 0,
|
|
210
212
|
id: __props.id,
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
|
3
|
+
//# sourceMappingURL=AskAgentButton.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AskAgentButton.vue.d.ts","sourceRoot":"","sources":["../../../src/features/ask-agent-button/AskAgentButton.vue"],"names":[],"mappings":";AAiPA,wBAKG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import _sfc_main from "./AskAgentButton.vue2.js";
|
|
2
|
+
/* empty css */
|
|
3
|
+
import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
|
|
4
|
+
const AskAgentButton = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-b5a61e43"]]);
|
|
5
|
+
export {
|
|
6
|
+
AskAgentButton as default
|
|
7
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defineComponent, ref, createElementBlock, createCommentVNode, unref, openBlock, createVNode, withDirectives, createElementVNode, withKeys, withModifiers, vModelText } from "vue";
|
|
2
|
+
import { ScalarIconSparkle, ScalarIconArrowUp } from "@scalar/icons";
|
|
3
|
+
import { useAgentContext } from "../../hooks/use-agent.js";
|
|
4
|
+
const _hoisted_1 = {
|
|
5
|
+
key: 0,
|
|
6
|
+
class: "agent-button-container flex"
|
|
7
|
+
};
|
|
8
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
9
|
+
__name: "AskAgentButton",
|
|
10
|
+
setup(__props) {
|
|
11
|
+
const agentContext = useAgentContext();
|
|
12
|
+
const message = ref("");
|
|
13
|
+
function handleSubmit() {
|
|
14
|
+
agentContext.value?.openAgent(message.value);
|
|
15
|
+
message.value = "";
|
|
16
|
+
}
|
|
17
|
+
return (_ctx, _cache) => {
|
|
18
|
+
return unref(agentContext)?.agentEnabled.value ? (openBlock(), createElementBlock("div", _hoisted_1, [
|
|
19
|
+
createVNode(unref(ScalarIconSparkle), {
|
|
20
|
+
class: "size-3 shrink-0",
|
|
21
|
+
weight: "fill"
|
|
22
|
+
}),
|
|
23
|
+
withDirectives(createElementVNode("input", {
|
|
24
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => message.value = $event),
|
|
25
|
+
class: "ask-agent-scalar-input",
|
|
26
|
+
placeholder: "Ask AI Agent",
|
|
27
|
+
onKeydown: _cache[1] || (_cache[1] = withKeys(withModifiers(($event) => handleSubmit(), ["stop"]), ["enter"]))
|
|
28
|
+
}, null, 544), [
|
|
29
|
+
[vModelText, message.value]
|
|
30
|
+
]),
|
|
31
|
+
createElementVNode("button", {
|
|
32
|
+
class: "ask-agent-scalar-send",
|
|
33
|
+
type: "button",
|
|
34
|
+
onClick: _cache[2] || (_cache[2] = ($event) => handleSubmit())
|
|
35
|
+
}, [
|
|
36
|
+
createVNode(unref(ScalarIconArrowUp), {
|
|
37
|
+
class: "size-3",
|
|
38
|
+
weight: "bold"
|
|
39
|
+
})
|
|
40
|
+
])
|
|
41
|
+
])) : createCommentVNode("", true);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export {
|
|
46
|
+
_sfc_main as default
|
|
47
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-bus.d.ts","sourceRoot":"","sources":["../../src/helpers/lazy-bus.ts"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,qCAAa,CAAA;AAc/C,KAAK,SAAS,GAAG,MAAM,IAAI,CAAA;AAE3B;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAO,SAMpC,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,oCAAkD,CAAA;
|
|
1
|
+
{"version":3,"file":"lazy-bus.d.ts","sourceRoot":"","sources":["../../src/helpers/lazy-bus.ts"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,qCAAa,CAAA;AAc/C,KAAK,SAAS,GAAG,MAAM,IAAI,CAAA;AAE3B;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAAO,SAMpC,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,oCAAkD,CAAA;AAkGlF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM;;EAUpC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GACvB,IAAI,MAAM,EACV,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,EACjD,cAAc,CAAC,EAAE,EAAE,MAAM,KAAK;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,QAAQ,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,GAAG,SAAS,SA2D/G,CAAA"}
|
package/dist/helpers/lazy-bus.js
CHANGED
|
@@ -29,7 +29,9 @@ const runLazyBus = () => {
|
|
|
29
29
|
if (pendingQueue.size > 0 || priorityQueue.size > 0) {
|
|
30
30
|
isRunning.value = true;
|
|
31
31
|
for (const id of [...pendingQueue, ...priorityQueue]) {
|
|
32
|
-
readyQueue.
|
|
32
|
+
if (!readyQueue.has(id)) {
|
|
33
|
+
readyQueue.add(id);
|
|
34
|
+
}
|
|
33
35
|
pendingQueue.delete(id);
|
|
34
36
|
priorityQueue.delete(id);
|
|
35
37
|
}
|
|
@@ -57,12 +59,12 @@ watchDebounced(
|
|
|
57
59
|
{ debounce: 300, maxWait: 1500 }
|
|
58
60
|
);
|
|
59
61
|
const addToPendingQueue = (id) => {
|
|
60
|
-
if (!!id && !priorityQueue.has(id)) {
|
|
62
|
+
if (!!id && !readyQueue.has(id) && !priorityQueue.has(id)) {
|
|
61
63
|
pendingQueue.add(id);
|
|
62
64
|
}
|
|
63
65
|
};
|
|
64
66
|
const addToPriorityQueue = (id) => {
|
|
65
|
-
if (id) {
|
|
67
|
+
if (id && !priorityQueue.has(id)) {
|
|
66
68
|
priorityQueue.add(id);
|
|
67
69
|
}
|
|
68
70
|
};
|
|
@@ -31,8 +31,8 @@ export declare const authStorage: () => {
|
|
|
31
31
|
'x-scalar-secret-token': string;
|
|
32
32
|
} & {
|
|
33
33
|
type: "apiKey";
|
|
34
|
-
name: string;
|
|
35
34
|
in: "header" | "query" | "cookie";
|
|
35
|
+
name: string;
|
|
36
36
|
}) | ({
|
|
37
37
|
description?: string | undefined;
|
|
38
38
|
} & {
|
|
@@ -181,8 +181,8 @@ export declare const authStorage: () => {
|
|
|
181
181
|
'x-scalar-secret-token': string;
|
|
182
182
|
} & {
|
|
183
183
|
type: "apiKey";
|
|
184
|
-
name: string;
|
|
185
184
|
in: "header" | "query" | "cookie";
|
|
185
|
+
name: string;
|
|
186
186
|
}) | ({
|
|
187
187
|
description?: string | undefined;
|
|
188
188
|
} & {
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,QAAQ,EACR,eAAe,GAChB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { type InjectionKey } from 'vue';
|
|
3
|
+
type UseAgentOptions = {
|
|
4
|
+
/** Optional. When provided, controls whether the agent UI is enabled (e.g. from doc config). Defaults to isLocalUrl. */
|
|
5
|
+
agentEnabled?: ComputedRef<boolean>;
|
|
6
|
+
};
|
|
7
|
+
type UseAgentReturn = {
|
|
8
|
+
showAgent: Ref<boolean>;
|
|
9
|
+
agentEnabled: ComputedRef<boolean>;
|
|
10
|
+
/** Ref used to pass a prefill message into the agent when opening. Cleared on close. */
|
|
11
|
+
prefilledMessage: Ref<string>;
|
|
12
|
+
openAgent: (message?: string) => void;
|
|
13
|
+
closeAgent: () => void;
|
|
14
|
+
toggleAgent: () => void;
|
|
15
|
+
};
|
|
16
|
+
export declare const AGENT_CONTEXT_SYMBOL: InjectionKey<UseAgentReturn>;
|
|
17
|
+
/**
|
|
18
|
+
* Hook for agent visibility and enabled state.
|
|
19
|
+
* Call from the API Reference root (e.g. ApiReference.vue) with options to create the state, then provide it so descendants can inject it.
|
|
20
|
+
*
|
|
21
|
+
* Returns:
|
|
22
|
+
* - showAgent: whether the agent panel is visible
|
|
23
|
+
* - agentEnabled: whether the agent is enabled
|
|
24
|
+
* - openAgent, closeAgent, toggleAgent: imperative controls
|
|
25
|
+
*/
|
|
26
|
+
export declare function useAgent(options: UseAgentOptions): UseAgentReturn;
|
|
27
|
+
/**
|
|
28
|
+
* Inject the agent context provided by ApiReference.
|
|
29
|
+
* Falls back to module-level state when inject is undefined (e.g. async boundary or mount order).
|
|
30
|
+
* Use in descendant components (e.g. AskAgentButton) to open the agent or check if it is enabled.
|
|
31
|
+
*
|
|
32
|
+
* Returns a computed ref; use v-if="agentContext?.agentEnabled" so the button only renders when context exists and agent is enabled.
|
|
33
|
+
*/
|
|
34
|
+
export declare function useAgentContext(): ComputedRef<UseAgentReturn | undefined>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=use-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-agent.d.ts","sourceRoot":"","sources":["../../src/hooks/use-agent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,KAAK,YAAY,EAAyB,MAAM,KAAK,CAAA;AAE9D,KAAK,eAAe,GAAG;IACrB,wHAAwH;IACxH,YAAY,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CACpC,CAAA;AAED,KAAK,cAAc,GAAG;IACpB,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IACvB,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAClC,wFAAwF;IACxF,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC7B,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACrC,UAAU,EAAE,MAAM,IAAI,CAAA;IACtB,WAAW,EAAE,MAAM,IAAI,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,oBAAoB,EAAe,YAAY,CAAC,cAAc,CAAC,CAAA;AAQ5E;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAiCjE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,WAAW,CAAC,cAAc,GAAG,SAAS,CAAC,CAGzE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isLocalUrl } from "@scalar/helpers/url/is-local-url";
|
|
2
|
+
import { ref, computed, inject } from "vue";
|
|
3
|
+
const AGENT_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol();
|
|
4
|
+
const agentStateRef = ref(null);
|
|
5
|
+
function useAgent(options) {
|
|
6
|
+
const showAgent = ref(false);
|
|
7
|
+
const prefilledMessage = ref("");
|
|
8
|
+
const agentEnabled = options.agentEnabled ?? computed(() => isLocalUrl(window.location.href));
|
|
9
|
+
const openAgent = (message) => {
|
|
10
|
+
prefilledMessage.value = message ?? "";
|
|
11
|
+
showAgent.value = true;
|
|
12
|
+
};
|
|
13
|
+
const closeAgent = () => {
|
|
14
|
+
showAgent.value = false;
|
|
15
|
+
prefilledMessage.value = "";
|
|
16
|
+
};
|
|
17
|
+
const toggleAgent = () => {
|
|
18
|
+
showAgent.value = !showAgent.value;
|
|
19
|
+
if (!showAgent.value) {
|
|
20
|
+
prefilledMessage.value = "";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const state = {
|
|
24
|
+
showAgent,
|
|
25
|
+
agentEnabled,
|
|
26
|
+
prefilledMessage,
|
|
27
|
+
openAgent,
|
|
28
|
+
closeAgent,
|
|
29
|
+
toggleAgent
|
|
30
|
+
};
|
|
31
|
+
agentStateRef.value = state;
|
|
32
|
+
return state;
|
|
33
|
+
}
|
|
34
|
+
function useAgentContext() {
|
|
35
|
+
const injected = inject(AGENT_CONTEXT_SYMBOL, void 0);
|
|
36
|
+
return computed(() => injected ?? agentStateRef.value ?? void 0);
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
AGENT_CONTEXT_SYMBOL,
|
|
40
|
+
useAgent,
|
|
41
|
+
useAgentContext
|
|
42
|
+
};
|