@nuxt-atelier/ai 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/module.d.mts +15 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +37 -0
- package/dist/runtime/admin/AiAltText.d.vue.ts +11 -0
- package/dist/runtime/admin/AiAltText.vue +78 -0
- package/dist/runtime/admin/AiAltText.vue.d.ts +11 -0
- package/dist/runtime/admin/AiAssistant.d.vue.ts +10 -0
- package/dist/runtime/admin/AiAssistant.vue +111 -0
- package/dist/runtime/admin/AiAssistant.vue.d.ts +10 -0
- package/dist/runtime/admin/AiSeo.d.vue.ts +18 -0
- package/dist/runtime/admin/AiSeo.vue +86 -0
- package/dist/runtime/admin/AiSeo.vue.d.ts +18 -0
- package/dist/runtime/admin/AiTextActions.d.vue.ts +14 -0
- package/dist/runtime/admin/AiTextActions.vue +123 -0
- package/dist/runtime/admin/AiTextActions.vue.d.ts +14 -0
- package/dist/runtime/admin/AiUsage.d.vue.ts +3 -0
- package/dist/runtime/admin/AiUsage.vue +89 -0
- package/dist/runtime/admin/AiUsage.vue.d.ts +3 -0
- package/dist/runtime/admin/index.d.ts +11 -0
- package/dist/runtime/admin/index.js +14 -0
- package/dist/runtime/content/server/atelier/tables.d.ts +2 -0
- package/dist/runtime/content/server/atelier/tables.js +14 -0
- package/dist/runtime/server/adapter.d.ts +31 -0
- package/dist/runtime/server/adapter.js +36 -0
- package/dist/runtime/server/api.d.ts +21 -0
- package/dist/runtime/server/api.js +145 -0
- package/dist/runtime/server/prompts.d.ts +52 -0
- package/dist/runtime/server/prompts.js +98 -0
- package/dist/types.d.mts +5 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ano Rebel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nuxt-atelier/ai
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Provider-agnostic AI assist adapter for Nuxt Atelier
|
|
4
|
+
|
|
5
|
+
Part of [Nuxt Atelier](https://nuxt-atelier.anorebel.net), a visual CMS for Nuxt. See the [documentation](https://nuxt-atelier.anorebel.net) to get started, or try the [live demo](https://nuxt-atelier-demo.anorebel.net).
|
|
6
|
+
|
|
7
|
+
MIT License
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NuxtModule } from '@nuxt/schema';
|
|
2
|
+
export { AiAdapter, AiRequest, AiResult } from '../dist/runtime/server/adapter.js';
|
|
3
|
+
|
|
4
|
+
interface ModuleOptions {
|
|
5
|
+
/** Content types (`posts`) or fields (`posts.internalNotes`), and `media`, never sent to the provider. */
|
|
6
|
+
exclude?: string[];
|
|
7
|
+
/** AI requests per user per hour (default 60). */
|
|
8
|
+
requestsPerHour?: number;
|
|
9
|
+
/** Tokens (in and out) per user per 24 hours (default 200000). */
|
|
10
|
+
tokensPerDay?: number;
|
|
11
|
+
}
|
|
12
|
+
declare const module$1: NuxtModule<ModuleOptions>;
|
|
13
|
+
|
|
14
|
+
export { module$1 as default };
|
|
15
|
+
export type { ModuleOptions };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerHandler, addTypeTemplate, hasNuxtModule } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const module$1 = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@nuxt-atelier/ai",
|
|
6
|
+
configKey: "atelierAi",
|
|
7
|
+
compatibility: {
|
|
8
|
+
nuxt: ">=4.6.0"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
defaults: { exclude: [], requestsPerHour: 60, tokensPerDay: 2e5 },
|
|
12
|
+
setup(options, nuxt) {
|
|
13
|
+
const { resolve } = createResolver(import.meta.url);
|
|
14
|
+
nuxt.options.runtimeConfig.atelierAi = { exclude: options.exclude ?? [], requestsPerHour: options.requestsPerHour ?? 60, tokensPerDay: options.tokensPerDay ?? 2e5 };
|
|
15
|
+
addServerHandler({ route: "/api/_atelier/ai", handler: resolve("./runtime/server/api") });
|
|
16
|
+
addServerHandler({ route: "/api/_atelier/ai/**", handler: resolve("./runtime/server/api") });
|
|
17
|
+
nuxt.options.nitro.alias = { ...nuxt.options.nitro.alias, "#atelier-ai": resolve("./runtime/server/adapter") };
|
|
18
|
+
addTypeTemplate({
|
|
19
|
+
filename: "types/atelier-ai.d.ts",
|
|
20
|
+
getContents: () => `declare module '#atelier-ai' {
|
|
21
|
+
export * from ${JSON.stringify(resolve("./runtime/server/adapter"))}
|
|
22
|
+
}
|
|
23
|
+
`
|
|
24
|
+
}, { nitro: true, nuxt: true });
|
|
25
|
+
nuxt.hook("atelier:dirs", (dirs) => void dirs.push(resolve("./runtime/content")));
|
|
26
|
+
nuxt.hook("modules:done", () => {
|
|
27
|
+
if (!hasNuxtModule("@nuxt-atelier/admin", nuxt))
|
|
28
|
+
return;
|
|
29
|
+
nuxt.options.alias["#atelier-admin-ai"] = resolve("./runtime/admin/index");
|
|
30
|
+
});
|
|
31
|
+
nuxt.hook("atelier:admin:pages", (pages) => {
|
|
32
|
+
pages.push({ path: "ai-usage", label: "AI usage", icon: "sparkles", requires: "users", component: resolve("./runtime/admin/AiUsage.vue") });
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export { module$1 as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
media: string;
|
|
3
|
+
locale?: string;
|
|
4
|
+
};
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
6
|
+
apply: (value: string) => any;
|
|
7
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
8
|
+
onApply?: ((value: string) => any) | undefined;
|
|
9
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { useAdminI18n, useAtelierAdmin } from "#imports";
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
media: { type: String, required: true },
|
|
6
|
+
locale: { type: String, required: false }
|
|
7
|
+
});
|
|
8
|
+
const emit = defineEmits(["apply"]);
|
|
9
|
+
const { t } = useAdminI18n();
|
|
10
|
+
const { api } = useAtelierAdmin();
|
|
11
|
+
const busy = ref(false);
|
|
12
|
+
const error = ref("");
|
|
13
|
+
const suggestion = ref(null);
|
|
14
|
+
async function ask() {
|
|
15
|
+
busy.value = true;
|
|
16
|
+
error.value = "";
|
|
17
|
+
try {
|
|
18
|
+
suggestion.value = (await api("/ai/suggest", { method: "POST", body: { action: "alt", media: props.media, locale: props.locale } })).suggestion;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
error.value = e.message ?? t("ai.failed");
|
|
21
|
+
} finally {
|
|
22
|
+
busy.value = false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div
|
|
29
|
+
class="app-ai"
|
|
30
|
+
data-ai-alt
|
|
31
|
+
>
|
|
32
|
+
<button
|
|
33
|
+
v-if="suggestion === null"
|
|
34
|
+
type="button"
|
|
35
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
36
|
+
:disabled="busy"
|
|
37
|
+
@click="ask"
|
|
38
|
+
>
|
|
39
|
+
{{ busy ? t("ai.working") : t("ai.altText") }}
|
|
40
|
+
</button>
|
|
41
|
+
<div
|
|
42
|
+
v-else
|
|
43
|
+
class="app-ai__suggestion"
|
|
44
|
+
data-ai-suggestion
|
|
45
|
+
>
|
|
46
|
+
<label class="cn-field">
|
|
47
|
+
<span class="cn-field__label">{{ t("ai.suggestion") }}</span>
|
|
48
|
+
<textarea
|
|
49
|
+
v-model="suggestion"
|
|
50
|
+
class="cn-textarea cn-input--size-md"
|
|
51
|
+
rows="2"
|
|
52
|
+
/>
|
|
53
|
+
</label>
|
|
54
|
+
<div class="app-row">
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
class="cn-button cn-button--primary cn-button--size-sm"
|
|
58
|
+
@click="emit('apply', suggestion), suggestion = null"
|
|
59
|
+
>
|
|
60
|
+
{{ t("ai.accept") }}
|
|
61
|
+
</button>
|
|
62
|
+
<button
|
|
63
|
+
type="button"
|
|
64
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
65
|
+
@click="suggestion = null"
|
|
66
|
+
>
|
|
67
|
+
{{ t("ai.discard") }}
|
|
68
|
+
</button>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
<p
|
|
72
|
+
v-if="error"
|
|
73
|
+
role="alert"
|
|
74
|
+
>
|
|
75
|
+
{{ error }}
|
|
76
|
+
</p>
|
|
77
|
+
</div>
|
|
78
|
+
</template>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
media: string;
|
|
3
|
+
locale?: string;
|
|
4
|
+
};
|
|
5
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
6
|
+
apply: (value: string) => any;
|
|
7
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
8
|
+
onApply?: ((value: string) => any) | undefined;
|
|
9
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
request: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
5
|
+
close: () => any;
|
|
6
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
7
|
+
onClose?: (() => any) | undefined;
|
|
8
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { onMounted, ref } from "vue";
|
|
3
|
+
import { useAdminI18n, useAtelierAdmin } from "#imports";
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
request: { type: String, required: true }
|
|
6
|
+
});
|
|
7
|
+
const emit = defineEmits(["close"]);
|
|
8
|
+
const { t } = useAdminI18n();
|
|
9
|
+
const { api } = useAtelierAdmin();
|
|
10
|
+
const thinking = ref(true);
|
|
11
|
+
const running = ref(false);
|
|
12
|
+
const error = ref("");
|
|
13
|
+
const steps = ref([]);
|
|
14
|
+
onMounted(async () => {
|
|
15
|
+
try {
|
|
16
|
+
const { proposals } = await api("/ai/assistant", { method: "POST", body: { request: props.request } });
|
|
17
|
+
steps.value = proposals.map((p) => ({ ...p, approved: false }));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
error.value = e.message ?? t("ai.failed");
|
|
20
|
+
} finally {
|
|
21
|
+
thinking.value = false;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
async function run() {
|
|
25
|
+
running.value = true;
|
|
26
|
+
for (const step of steps.value.filter((s) => s.approved && !s.status)) {
|
|
27
|
+
try {
|
|
28
|
+
const [path, search] = step.path.replace(/^\/api\/_atelier/, "").split("?");
|
|
29
|
+
const query = Object.fromEntries(new URLSearchParams(search ?? ""));
|
|
30
|
+
const answer = await api(path, { method: step.method, body: step.body, query });
|
|
31
|
+
step.status = "done";
|
|
32
|
+
step.result = JSON.stringify(answer, null, 2).slice(0, 2e3);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
step.status = "failed";
|
|
35
|
+
step.result = e.message;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
running.value = false;
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<section
|
|
44
|
+
class="app-ai app-ai__assistant"
|
|
45
|
+
data-ai-assistant
|
|
46
|
+
:aria-label="t('ai.assistant')"
|
|
47
|
+
>
|
|
48
|
+
<p><strong>{{ t("ai.asked") }}</strong> {{ request }}</p>
|
|
49
|
+
<p
|
|
50
|
+
v-if="thinking"
|
|
51
|
+
role="status"
|
|
52
|
+
>
|
|
53
|
+
{{ t("ai.working") }}
|
|
54
|
+
</p>
|
|
55
|
+
<p
|
|
56
|
+
v-else-if="error"
|
|
57
|
+
role="alert"
|
|
58
|
+
>
|
|
59
|
+
{{ error }}
|
|
60
|
+
</p>
|
|
61
|
+
<p v-else-if="!steps.length">
|
|
62
|
+
{{ t("ai.noProposals") }}
|
|
63
|
+
</p>
|
|
64
|
+
<ol
|
|
65
|
+
v-else
|
|
66
|
+
class="app-ai__steps"
|
|
67
|
+
>
|
|
68
|
+
<li
|
|
69
|
+
v-for="(step, i) in steps"
|
|
70
|
+
:key="i"
|
|
71
|
+
:data-step="i"
|
|
72
|
+
:data-status="step.status"
|
|
73
|
+
>
|
|
74
|
+
<label class="app-row">
|
|
75
|
+
<input
|
|
76
|
+
v-model="step.approved"
|
|
77
|
+
type="checkbox"
|
|
78
|
+
:disabled="!!step.status || running"
|
|
79
|
+
>
|
|
80
|
+
<span>{{ step.summary }}</span>
|
|
81
|
+
</label>
|
|
82
|
+
<code>{{ step.method }} {{ step.path }}</code>
|
|
83
|
+
<pre v-if="step.body !== void 0">{{ JSON.stringify(step.body, null, 2) }}</pre>
|
|
84
|
+
<p
|
|
85
|
+
v-if="step.status"
|
|
86
|
+
:role="step.status === 'failed' ? 'alert' : 'status'"
|
|
87
|
+
>
|
|
88
|
+
{{ step.status === "done" ? t("ai.done") : t("ai.refused", { reason: step.result ?? "" }) }}
|
|
89
|
+
</p>
|
|
90
|
+
</li>
|
|
91
|
+
</ol>
|
|
92
|
+
<div class="app-row">
|
|
93
|
+
<button
|
|
94
|
+
v-if="steps.length"
|
|
95
|
+
type="button"
|
|
96
|
+
class="cn-button cn-button--primary cn-button--size-sm"
|
|
97
|
+
:disabled="running || !steps.some((s) => s.approved && !s.status)"
|
|
98
|
+
@click="run"
|
|
99
|
+
>
|
|
100
|
+
{{ t("ai.runApproved") }}
|
|
101
|
+
</button>
|
|
102
|
+
<button
|
|
103
|
+
type="button"
|
|
104
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
105
|
+
@click="emit('close')"
|
|
106
|
+
>
|
|
107
|
+
{{ t("ai.close") }}
|
|
108
|
+
</button>
|
|
109
|
+
</div>
|
|
110
|
+
</section>
|
|
111
|
+
</template>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
request: string;
|
|
3
|
+
};
|
|
4
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
5
|
+
close: () => any;
|
|
6
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
7
|
+
onClose?: (() => any) | undefined;
|
|
8
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
declare const _default: typeof __VLS_export;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
type: string;
|
|
3
|
+
id?: string;
|
|
4
|
+
locale?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
7
|
+
apply: (value: {
|
|
8
|
+
title: string;
|
|
9
|
+
description: string;
|
|
10
|
+
}) => any;
|
|
11
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
12
|
+
onApply?: ((value: {
|
|
13
|
+
title: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}) => any) | undefined;
|
|
16
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
|
+
declare const _default: typeof __VLS_export;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { useAdminI18n, useAtelierAdmin } from "#imports";
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
type: { type: String, required: true },
|
|
6
|
+
id: { type: String, required: false },
|
|
7
|
+
locale: { type: String, required: false }
|
|
8
|
+
});
|
|
9
|
+
const emit = defineEmits(["apply"]);
|
|
10
|
+
const { t } = useAdminI18n();
|
|
11
|
+
const { api } = useAtelierAdmin();
|
|
12
|
+
const busy = ref(false);
|
|
13
|
+
const error = ref("");
|
|
14
|
+
const suggestion = ref(null);
|
|
15
|
+
async function ask() {
|
|
16
|
+
busy.value = true;
|
|
17
|
+
error.value = "";
|
|
18
|
+
try {
|
|
19
|
+
suggestion.value = (await api("/ai/suggest", { method: "POST", body: { action: "seo", type: props.type, id: props.id, locale: props.locale } })).suggestion;
|
|
20
|
+
} catch (e) {
|
|
21
|
+
error.value = e.message ?? t("ai.failed");
|
|
22
|
+
} finally {
|
|
23
|
+
busy.value = false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<div
|
|
30
|
+
class="app-ai"
|
|
31
|
+
data-ai-seo
|
|
32
|
+
>
|
|
33
|
+
<button
|
|
34
|
+
v-if="!suggestion"
|
|
35
|
+
type="button"
|
|
36
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
37
|
+
:disabled="busy"
|
|
38
|
+
@click="ask"
|
|
39
|
+
>
|
|
40
|
+
{{ busy ? t("ai.working") : t("ai.seo") }}
|
|
41
|
+
</button>
|
|
42
|
+
<div
|
|
43
|
+
v-else
|
|
44
|
+
class="app-ai__suggestion"
|
|
45
|
+
data-ai-suggestion
|
|
46
|
+
>
|
|
47
|
+
<label class="cn-field">
|
|
48
|
+
<span class="cn-field__label">{{ t("ai.seoTitle") }}</span>
|
|
49
|
+
<input
|
|
50
|
+
v-model="suggestion.title"
|
|
51
|
+
class="cn-input cn-input--size-md"
|
|
52
|
+
>
|
|
53
|
+
</label>
|
|
54
|
+
<label class="cn-field">
|
|
55
|
+
<span class="cn-field__label">{{ t("ai.seoDescription") }}</span>
|
|
56
|
+
<textarea
|
|
57
|
+
v-model="suggestion.description"
|
|
58
|
+
class="cn-textarea cn-input--size-md"
|
|
59
|
+
rows="3"
|
|
60
|
+
/>
|
|
61
|
+
</label>
|
|
62
|
+
<div class="app-row">
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
class="cn-button cn-button--primary cn-button--size-sm"
|
|
66
|
+
@click="emit('apply', suggestion), suggestion = null"
|
|
67
|
+
>
|
|
68
|
+
{{ t("ai.accept") }}
|
|
69
|
+
</button>
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
73
|
+
@click="suggestion = null"
|
|
74
|
+
>
|
|
75
|
+
{{ t("ai.discard") }}
|
|
76
|
+
</button>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
<p
|
|
80
|
+
v-if="error"
|
|
81
|
+
role="alert"
|
|
82
|
+
>
|
|
83
|
+
{{ error }}
|
|
84
|
+
</p>
|
|
85
|
+
</div>
|
|
86
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
type: string;
|
|
3
|
+
id?: string;
|
|
4
|
+
locale?: string;
|
|
5
|
+
};
|
|
6
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
7
|
+
apply: (value: {
|
|
8
|
+
title: string;
|
|
9
|
+
description: string;
|
|
10
|
+
}) => any;
|
|
11
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
12
|
+
onApply?: ((value: {
|
|
13
|
+
title: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}) => any) | undefined;
|
|
16
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
|
+
declare const _default: typeof __VLS_export;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
type: string;
|
|
3
|
+
field: string;
|
|
4
|
+
value: string;
|
|
5
|
+
locale?: string;
|
|
6
|
+
locales?: string[];
|
|
7
|
+
};
|
|
8
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
9
|
+
apply: (value: string) => any;
|
|
10
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
11
|
+
onApply?: ((value: string) => any) | undefined;
|
|
12
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
declare const _default: typeof __VLS_export;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
|
+
import { useAdminI18n, useAtelierAdmin } from "#imports";
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
type: { type: String, required: true },
|
|
6
|
+
field: { type: String, required: true },
|
|
7
|
+
value: { type: String, required: true },
|
|
8
|
+
locale: { type: String, required: false },
|
|
9
|
+
locales: { type: Array, required: false }
|
|
10
|
+
});
|
|
11
|
+
const emit = defineEmits(["apply"]);
|
|
12
|
+
const { t } = useAdminI18n();
|
|
13
|
+
const { api } = useAtelierAdmin();
|
|
14
|
+
const busy = ref(false);
|
|
15
|
+
const error = ref("");
|
|
16
|
+
const suggestion = ref(null);
|
|
17
|
+
const previous = ref(null);
|
|
18
|
+
const others = computed(() => (props.locales ?? []).filter((code) => code !== props.locale));
|
|
19
|
+
async function ask(action, to) {
|
|
20
|
+
busy.value = true;
|
|
21
|
+
error.value = "";
|
|
22
|
+
previous.value = null;
|
|
23
|
+
try {
|
|
24
|
+
const body = action === "translate" ? { action, type: props.type, field: props.field, value: props.value, to, from: props.locale } : { action, type: props.type, field: props.field, text: props.value, locale: props.locale };
|
|
25
|
+
suggestion.value = (await api("/ai/suggest", { method: "POST", body })).suggestion;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
error.value = e.message ?? t("ai.failed");
|
|
28
|
+
} finally {
|
|
29
|
+
busy.value = false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function accept() {
|
|
33
|
+
previous.value = props.value;
|
|
34
|
+
emit("apply", suggestion.value);
|
|
35
|
+
suggestion.value = null;
|
|
36
|
+
}
|
|
37
|
+
function undo() {
|
|
38
|
+
emit("apply", previous.value);
|
|
39
|
+
previous.value = null;
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<div
|
|
45
|
+
class="app-ai"
|
|
46
|
+
data-ai-actions
|
|
47
|
+
>
|
|
48
|
+
<div
|
|
49
|
+
v-if="suggestion === null"
|
|
50
|
+
class="app-row"
|
|
51
|
+
>
|
|
52
|
+
<button
|
|
53
|
+
v-for="action in ['rewrite', 'shorten', 'expand']"
|
|
54
|
+
:key="action"
|
|
55
|
+
type="button"
|
|
56
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
57
|
+
:disabled="busy || !value"
|
|
58
|
+
@click="ask(action)"
|
|
59
|
+
>
|
|
60
|
+
{{ t(`ai.${action}`) }}
|
|
61
|
+
</button>
|
|
62
|
+
<button
|
|
63
|
+
v-for="code in others"
|
|
64
|
+
:key="code"
|
|
65
|
+
type="button"
|
|
66
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
67
|
+
:disabled="busy || !value"
|
|
68
|
+
@click="ask('translate', code)"
|
|
69
|
+
>
|
|
70
|
+
{{ t("ai.translateTo", { locale: code.toUpperCase() }) }}
|
|
71
|
+
</button>
|
|
72
|
+
<button
|
|
73
|
+
v-if="previous !== null"
|
|
74
|
+
type="button"
|
|
75
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
76
|
+
@click="undo"
|
|
77
|
+
>
|
|
78
|
+
{{ t("ai.undo") }}
|
|
79
|
+
</button>
|
|
80
|
+
<span
|
|
81
|
+
v-if="busy"
|
|
82
|
+
role="status"
|
|
83
|
+
>{{ t("ai.working") }}</span>
|
|
84
|
+
</div>
|
|
85
|
+
<div
|
|
86
|
+
v-else
|
|
87
|
+
class="app-ai__suggestion"
|
|
88
|
+
data-ai-suggestion
|
|
89
|
+
>
|
|
90
|
+
<label class="cn-field">
|
|
91
|
+
<span class="cn-field__label">{{ t("ai.suggestion") }}</span>
|
|
92
|
+
<textarea
|
|
93
|
+
v-model="suggestion"
|
|
94
|
+
class="cn-textarea cn-input--size-md"
|
|
95
|
+
rows="4"
|
|
96
|
+
/>
|
|
97
|
+
</label>
|
|
98
|
+
<div class="app-row">
|
|
99
|
+
<button
|
|
100
|
+
type="button"
|
|
101
|
+
class="cn-button cn-button--primary cn-button--size-sm"
|
|
102
|
+
@click="accept"
|
|
103
|
+
>
|
|
104
|
+
{{ t("ai.accept") }}
|
|
105
|
+
</button>
|
|
106
|
+
<button
|
|
107
|
+
type="button"
|
|
108
|
+
class="cn-button cn-button--ghost cn-button--size-sm"
|
|
109
|
+
@click="suggestion = null"
|
|
110
|
+
>
|
|
111
|
+
{{ t("ai.discard") }}
|
|
112
|
+
</button>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
<p
|
|
116
|
+
v-if="error"
|
|
117
|
+
class="app-ai__error"
|
|
118
|
+
role="alert"
|
|
119
|
+
>
|
|
120
|
+
{{ error }}
|
|
121
|
+
</p>
|
|
122
|
+
</div>
|
|
123
|
+
</template>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
type: string;
|
|
3
|
+
field: string;
|
|
4
|
+
value: string;
|
|
5
|
+
locale?: string;
|
|
6
|
+
locales?: string[];
|
|
7
|
+
};
|
|
8
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
9
|
+
apply: (value: string) => any;
|
|
10
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
11
|
+
onApply?: ((value: string) => any) | undefined;
|
|
12
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
declare const _default: typeof __VLS_export;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, watch } from "vue";
|
|
3
|
+
import { useAdminI18n, useAtelierAdmin } from "#imports";
|
|
4
|
+
const { t } = useAdminI18n();
|
|
5
|
+
const { api } = useAtelierAdmin();
|
|
6
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
7
|
+
const from = ref(new Date(Date.now() - 30 * 24 * 36e5).toISOString().slice(0, 10));
|
|
8
|
+
const to = ref(today);
|
|
9
|
+
const rows = ref(null);
|
|
10
|
+
const error = ref("");
|
|
11
|
+
watch([from, to], async () => {
|
|
12
|
+
try {
|
|
13
|
+
rows.value = await api("/ai/usage", { query: { from: from.value, to: to.value } });
|
|
14
|
+
error.value = "";
|
|
15
|
+
} catch (e) {
|
|
16
|
+
error.value = e.message ?? t("ai.failed");
|
|
17
|
+
}
|
|
18
|
+
}, { immediate: true });
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<section
|
|
23
|
+
class="app-section"
|
|
24
|
+
data-ai-usage
|
|
25
|
+
>
|
|
26
|
+
<h1 class="app-section__title">
|
|
27
|
+
{{ t("ai.usage") }}
|
|
28
|
+
</h1>
|
|
29
|
+
<div class="app-row">
|
|
30
|
+
<label class="cn-field">
|
|
31
|
+
<span class="cn-field__label">{{ t("forms.from") }}</span>
|
|
32
|
+
<input
|
|
33
|
+
v-model="from"
|
|
34
|
+
type="date"
|
|
35
|
+
class="cn-input cn-input--size-md"
|
|
36
|
+
>
|
|
37
|
+
</label>
|
|
38
|
+
<label class="cn-field">
|
|
39
|
+
<span class="cn-field__label">{{ t("forms.to") }}</span>
|
|
40
|
+
<input
|
|
41
|
+
v-model="to"
|
|
42
|
+
type="date"
|
|
43
|
+
class="cn-input cn-input--size-md"
|
|
44
|
+
>
|
|
45
|
+
</label>
|
|
46
|
+
</div>
|
|
47
|
+
<p
|
|
48
|
+
v-if="error"
|
|
49
|
+
role="alert"
|
|
50
|
+
>
|
|
51
|
+
{{ error }}
|
|
52
|
+
</p>
|
|
53
|
+
<p v-else-if="rows && !rows.length">
|
|
54
|
+
{{ t("ai.noUsage") }}
|
|
55
|
+
</p>
|
|
56
|
+
<table
|
|
57
|
+
v-else-if="rows"
|
|
58
|
+
class="cn-table cn-table--default cn-table--size-sm"
|
|
59
|
+
>
|
|
60
|
+
<thead>
|
|
61
|
+
<tr>
|
|
62
|
+
<th scope="col">
|
|
63
|
+
{{ t("common.name") }}
|
|
64
|
+
</th>
|
|
65
|
+
<th scope="col">
|
|
66
|
+
{{ t("ai.action") }}
|
|
67
|
+
</th>
|
|
68
|
+
<th scope="col">
|
|
69
|
+
{{ t("ai.requests") }}
|
|
70
|
+
</th>
|
|
71
|
+
<th scope="col">
|
|
72
|
+
{{ t("ai.tokens") }}
|
|
73
|
+
</th>
|
|
74
|
+
</tr>
|
|
75
|
+
</thead>
|
|
76
|
+
<tbody>
|
|
77
|
+
<tr
|
|
78
|
+
v-for="row in rows"
|
|
79
|
+
:key="`${row.userId}:${row.action}`"
|
|
80
|
+
>
|
|
81
|
+
<td>{{ row.name }}</td>
|
|
82
|
+
<td>{{ row.action }}</td>
|
|
83
|
+
<td>{{ row.requests }}</td>
|
|
84
|
+
<td>{{ row.inputTokens + row.outputTokens }}</td>
|
|
85
|
+
</tr>
|
|
86
|
+
</tbody>
|
|
87
|
+
</table>
|
|
88
|
+
</section>
|
|
89
|
+
</template>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
/** Whether AI actions show: the server has an adapter, and the user has the `ai` capability. */
|
|
3
|
+
declare function enabled(): Ref<boolean>;
|
|
4
|
+
export declare const ai: {
|
|
5
|
+
enabled: typeof enabled;
|
|
6
|
+
TextActions: any;
|
|
7
|
+
AltText: any;
|
|
8
|
+
Seo: any;
|
|
9
|
+
Assistant: any;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
import { useAtelierAdmin, useAtelierPermissions } from "#imports";
|
|
3
|
+
import AltText from "./AiAltText.vue";
|
|
4
|
+
import Assistant from "./AiAssistant.vue";
|
|
5
|
+
import Seo from "./AiSeo.vue";
|
|
6
|
+
import TextActions from "./AiTextActions.vue";
|
|
7
|
+
const set = ref(false);
|
|
8
|
+
let asked;
|
|
9
|
+
function enabled() {
|
|
10
|
+
const { manages } = useAtelierPermissions();
|
|
11
|
+
asked ??= useAtelierAdmin().api("/ai").then(() => void (set.value = true), () => void (asked = void 0));
|
|
12
|
+
return computed(() => set.value && manages("ai"));
|
|
13
|
+
}
|
|
14
|
+
export const ai = { enabled, TextActions, AltText, Seo, Assistant };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineTables } from "#atelier/server";
|
|
2
|
+
export default defineTables({
|
|
3
|
+
atelier_ai_usage: {
|
|
4
|
+
columns: {
|
|
5
|
+
user_id: { type: "string", required: true, index: true },
|
|
6
|
+
action: { type: "string", required: true },
|
|
7
|
+
content_type: { type: "string" },
|
|
8
|
+
site: { type: "string", required: true },
|
|
9
|
+
input_tokens: { type: "number", required: true },
|
|
10
|
+
output_tokens: { type: "number", required: true },
|
|
11
|
+
created_at: { type: "string", required: true, index: true }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LanguageModel } from 'ai';
|
|
2
|
+
export interface AiRequest {
|
|
3
|
+
system: string;
|
|
4
|
+
prompt: string;
|
|
5
|
+
/** Images the model looks at (alt text): their bytes and type. */
|
|
6
|
+
images?: {
|
|
7
|
+
data: Uint8Array;
|
|
8
|
+
mediaType: string;
|
|
9
|
+
}[];
|
|
10
|
+
maxOutputTokens?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AiResult {
|
|
13
|
+
text: string;
|
|
14
|
+
/** Tokens, when the provider reports them. */
|
|
15
|
+
usage?: {
|
|
16
|
+
inputTokens?: number;
|
|
17
|
+
outputTokens?: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface AiAdapter {
|
|
21
|
+
generate: (request: AiRequest) => Promise<AiResult>;
|
|
22
|
+
}
|
|
23
|
+
/** An adapter on the AI SDK: `aiSdkAdapter({ model: anthropic('claude-sonnet-5-5') })`, or any provider's model. */
|
|
24
|
+
export declare function aiSdkAdapter(options: {
|
|
25
|
+
model: LanguageModel;
|
|
26
|
+
temperature?: number;
|
|
27
|
+
}): AiAdapter;
|
|
28
|
+
/** Turns AI assist on with this provider. Call it from a server plugin. */
|
|
29
|
+
export declare function registerAiAdapter(create: () => AiAdapter | Promise<AiAdapter>): void;
|
|
30
|
+
/** The registered adapter, or undefined: AI assist is off. */
|
|
31
|
+
export declare function useAiAdapter(): Promise<AiAdapter> | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { generateText } from "ai";
|
|
2
|
+
export function aiSdkAdapter(options) {
|
|
3
|
+
return {
|
|
4
|
+
async generate(request) {
|
|
5
|
+
const result = await generateText({
|
|
6
|
+
model: options.model,
|
|
7
|
+
system: request.system,
|
|
8
|
+
...options.temperature === void 0 ? {} : { temperature: options.temperature },
|
|
9
|
+
maxOutputTokens: request.maxOutputTokens ?? 1024,
|
|
10
|
+
messages: [{
|
|
11
|
+
role: "user",
|
|
12
|
+
content: [
|
|
13
|
+
{ type: "text", text: request.prompt },
|
|
14
|
+
...(request.images ?? []).map((image) => ({ type: "file", mediaType: image.mediaType, data: image.data }))
|
|
15
|
+
]
|
|
16
|
+
}]
|
|
17
|
+
});
|
|
18
|
+
return { text: result.text, usage: { inputTokens: result.usage.inputTokens, outputTokens: result.usage.outputTokens } };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
let factory;
|
|
23
|
+
let adapter;
|
|
24
|
+
export function registerAiAdapter(create) {
|
|
25
|
+
factory = create;
|
|
26
|
+
adapter = void 0;
|
|
27
|
+
}
|
|
28
|
+
export function useAiAdapter() {
|
|
29
|
+
if (!factory)
|
|
30
|
+
return void 0;
|
|
31
|
+
adapter ??= Promise.resolve(factory()).catch((error) => {
|
|
32
|
+
adapter = void 0;
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
return adapter;
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<{
|
|
2
|
+
userId: string;
|
|
3
|
+
name: string;
|
|
4
|
+
action: string;
|
|
5
|
+
requests: number;
|
|
6
|
+
inputTokens: number;
|
|
7
|
+
outputTokens: number;
|
|
8
|
+
}[] | {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
suggestion?: undefined;
|
|
11
|
+
proposals?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
suggestion: any;
|
|
14
|
+
enabled?: undefined;
|
|
15
|
+
proposals?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
proposals: import("./prompts.js").Proposal[];
|
|
18
|
+
enabled?: undefined;
|
|
19
|
+
suggestion?: undefined;
|
|
20
|
+
}>>;
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { and, gte, lte, sql } from "drizzle-orm";
|
|
2
|
+
import { defineEventHandler, getQuery, getRequestURL, useRuntimeConfig } from "nuxt/server";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
import { apiError, readValid, requireUser, useAtelierAuth, useAtelierDatabase, useAtelierEntries, useAtelierMedia, useAtelierPolicy, useAtelierRateLimiter, useAtelierSchema, useAtelierSite, useAtelierStorage, useAtelierTables, validated } from "#atelier/server";
|
|
5
|
+
import { useAiAdapter } from "./adapter.js";
|
|
6
|
+
import { altPrompt, assistantPrompt, excluded, mergeTranslation, parseProposals, parseSeo, seoPrompt, textPrompt, translatePrompt } from "./prompts.js";
|
|
7
|
+
const config = () => {
|
|
8
|
+
const c = useRuntimeConfig().atelierAi;
|
|
9
|
+
return { ...c, exclude: typeof c.exclude === "string" ? JSON.parse(c.exclude || "[]") : c.exclude };
|
|
10
|
+
};
|
|
11
|
+
const locale = v.optional(v.pipe(v.string(), v.regex(/^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i, "expected a locale code")));
|
|
12
|
+
const Suggest = v.variant("action", [
|
|
13
|
+
v.object({ action: v.picklist(["rewrite", "shorten", "expand"]), type: v.string(), field: v.string(), text: v.pipe(v.string(), v.nonEmpty("text: nothing to work on"), v.maxLength(2e4)), locale }),
|
|
14
|
+
v.object({ action: v.literal("translate"), type: v.string(), field: v.string(), value: v.unknown(), to: v.pipe(v.string(), v.regex(/^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i, "to: expected a locale code")), from: locale }),
|
|
15
|
+
v.object({ action: v.literal("seo"), type: v.string(), id: v.optional(v.string()), locale }),
|
|
16
|
+
v.object({ action: v.literal("alt"), media: v.string(), locale })
|
|
17
|
+
], "action: expected rewrite, shorten, expand, translate, seo or alt");
|
|
18
|
+
const Assistant = v.object({ request: v.pipe(v.string(), v.trim(), v.nonEmpty("request: say what you need"), v.maxLength(2e3)) });
|
|
19
|
+
const Period = v.object({ from: v.optional(v.pipe(v.string(), v.isoDate())), to: v.optional(v.pipe(v.string(), v.isoDate())) });
|
|
20
|
+
const plainText = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map(plainText).filter(Boolean).join(" ") : value && typeof value === "object" ? Object.entries(value).filter(([k]) => k !== "id" && k !== "type").map(([, v2]) => plainText(v2)).filter(Boolean).join(" ") : "";
|
|
21
|
+
async function usageTable() {
|
|
22
|
+
const tables = await useAtelierTables();
|
|
23
|
+
return { db: (await useAtelierDatabase()).db, table: tables.atelier_ai_usage };
|
|
24
|
+
}
|
|
25
|
+
async function limit(event, user) {
|
|
26
|
+
const { requestsPerHour, tokensPerDay } = config();
|
|
27
|
+
const limits = [{ key: `ai:${user.id}`, max: requestsPerHour, window: 3600 }];
|
|
28
|
+
const limiter = await useAtelierRateLimiter();
|
|
29
|
+
await limiter.check(event, limits);
|
|
30
|
+
const { db, table } = await usageTable();
|
|
31
|
+
const since = new Date(Date.now() - 24 * 36e5).toISOString();
|
|
32
|
+
const [used] = await db.select({ tokens: sql`coalesce(sum(${table.input_tokens} + ${table.output_tokens}), 0)` }).from(table).where(and(sql`${table.user_id} = ${user.id}`, gte(table.created_at, since)));
|
|
33
|
+
if (Number(used?.tokens ?? 0) >= tokensPerDay)
|
|
34
|
+
throw apiError(429, "You've used today's AI allowance: try again tomorrow");
|
|
35
|
+
await limiter.hit(limits);
|
|
36
|
+
}
|
|
37
|
+
async function record(event, user, action, type, usage) {
|
|
38
|
+
const { db, table } = await usageTable();
|
|
39
|
+
await db.insert(table).values({ id: crypto.randomUUID(), user_id: user.id, action, content_type: type, site: useAtelierSite(event).name, input_tokens: usage?.inputTokens ?? 0, output_tokens: usage?.outputTokens ?? 0, created_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
40
|
+
}
|
|
41
|
+
export default defineEventHandler(async (event) => {
|
|
42
|
+
const adapter = useAiAdapter();
|
|
43
|
+
const action = getRequestURL(event).pathname.replace(/^\/api\/_atelier\/ai\/?/, "").replace(/\/$/, "");
|
|
44
|
+
if (!adapter)
|
|
45
|
+
throw apiError(404, "AI assist isn't set up");
|
|
46
|
+
const user = await requireUser(event, "ai");
|
|
47
|
+
const method = event.req.method;
|
|
48
|
+
const { exclude } = config();
|
|
49
|
+
const schema = await useAtelierSchema();
|
|
50
|
+
const policy = await useAtelierPolicy();
|
|
51
|
+
const allowed = (type, field) => {
|
|
52
|
+
const definition = schema.collections[type] ?? schema.singletons[type];
|
|
53
|
+
if (!definition || !policy.can(user, "read", type))
|
|
54
|
+
throw apiError(404, `No content type "${type}"`);
|
|
55
|
+
if (field !== void 0 && (!definition.fields[field] || policy.fields(user, type).hidden.has(field)))
|
|
56
|
+
throw apiError(404, `No field "${field}" in "${type}"`);
|
|
57
|
+
if (excluded(exclude, type, field))
|
|
58
|
+
throw apiError(403, `${field ? `"${type}.${field}"` : `"${type}"`} is excluded from AI assist`);
|
|
59
|
+
return definition;
|
|
60
|
+
};
|
|
61
|
+
if (!action && method === "GET")
|
|
62
|
+
return { enabled: true };
|
|
63
|
+
if (action === "suggest" && method === "POST") {
|
|
64
|
+
const input = await readValid(event, Suggest);
|
|
65
|
+
await limit(event, user);
|
|
66
|
+
const ai = await adapter;
|
|
67
|
+
if (input.action === "rewrite" || input.action === "shorten" || input.action === "expand") {
|
|
68
|
+
const definition = allowed(input.type, input.field);
|
|
69
|
+
const label = definition.fields[input.field].label ?? input.field;
|
|
70
|
+
const result2 = await ai.generate(textPrompt(input.action, input.text, { label, locale: input.locale }));
|
|
71
|
+
await record(event, user, input.action, input.type, result2.usage);
|
|
72
|
+
return { suggestion: result2.text.trim() };
|
|
73
|
+
}
|
|
74
|
+
if (input.action === "translate") {
|
|
75
|
+
allowed(input.type, input.field);
|
|
76
|
+
const result2 = await ai.generate({ ...translatePrompt(input.value, input.to, input.from), maxOutputTokens: 4096 });
|
|
77
|
+
await record(event, user, "translate", input.type, result2.usage);
|
|
78
|
+
return { suggestion: typeof input.value === "string" ? result2.text.trim() : mergeTranslation(input.value, result2.text) };
|
|
79
|
+
}
|
|
80
|
+
if (input.action === "seo") {
|
|
81
|
+
const definition = allowed(input.type);
|
|
82
|
+
const entries = await useAtelierEntries(useAtelierSite(event));
|
|
83
|
+
const entry = schema.singletons[input.type] ? await entries.getSingleton(input.type, { stage: "draft" }) : input.id ? await entries.get(input.type, input.id, { stage: "draft" }) : void 0;
|
|
84
|
+
if (!entry)
|
|
85
|
+
throw apiError(404, "No such entry");
|
|
86
|
+
const hidden = policy.fields(user, input.type).hidden;
|
|
87
|
+
const texts = Object.fromEntries(Object.entries(definition.fields).filter(([key, field]) => ["text", "textarea", "richText", "blocks"].includes(field.type) && !hidden.has(key) && !excluded(exclude, input.type, key)).map(([key, field]) => [field.label ?? key, plainText(entry.data[key]).slice(0, 4e3)]).filter(([, text]) => text));
|
|
88
|
+
if (!Object.keys(texts).length)
|
|
89
|
+
throw apiError(422, "There's no text to write a title and description from");
|
|
90
|
+
const result2 = await ai.generate(seoPrompt(texts, input.locale));
|
|
91
|
+
await record(event, user, "seo", input.type, result2.usage);
|
|
92
|
+
return { suggestion: parseSeo(result2.text) };
|
|
93
|
+
}
|
|
94
|
+
if (exclude.includes("media"))
|
|
95
|
+
throw apiError(403, "Media is excluded from AI assist");
|
|
96
|
+
const item = await (await useAtelierMedia(useAtelierSite(event))).get(input.media);
|
|
97
|
+
if (!item)
|
|
98
|
+
throw apiError(404, "No such media item");
|
|
99
|
+
if (!item.mime.startsWith("image/") || item.size > 5 * 1024 * 1024)
|
|
100
|
+
throw apiError(422, "Alt text needs an image of at most 5 MB");
|
|
101
|
+
const file = await (await useAtelierStorage()).get(item.key);
|
|
102
|
+
if (!file)
|
|
103
|
+
throw apiError(404, "The file is missing from storage");
|
|
104
|
+
const data = new Uint8Array(await new Response(file.stream).arrayBuffer());
|
|
105
|
+
const result = await ai.generate({ ...altPrompt(item.filename, input.locale), images: [{ data, mediaType: item.mime }] });
|
|
106
|
+
await record(event, user, "alt", null, result.usage);
|
|
107
|
+
return { suggestion: result.text.trim().slice(0, 300) };
|
|
108
|
+
}
|
|
109
|
+
if (action === "assistant" && method === "POST") {
|
|
110
|
+
const { request } = await readValid(event, Assistant);
|
|
111
|
+
await limit(event, user);
|
|
112
|
+
const describe = (kind) => ([name, d]) => ({
|
|
113
|
+
name,
|
|
114
|
+
kind,
|
|
115
|
+
fields: Object.keys(d.fields).filter((key) => !policy.fields(user, name).hidden.has(key) && !excluded(exclude, name, key)),
|
|
116
|
+
actions: ["read", "create", "update", "delete", "publish"].filter((a) => policy.can(user, a, name))
|
|
117
|
+
});
|
|
118
|
+
const types = [
|
|
119
|
+
...Object.entries(schema.collections).filter(([name]) => policy.can(user, "read", name) && !excluded(exclude, name)).map(describe("collection")),
|
|
120
|
+
...Object.entries(schema.singletons).filter(([name]) => policy.can(user, "read", name) && !excluded(exclude, name)).map(describe("singleton"))
|
|
121
|
+
];
|
|
122
|
+
const result = await (await adapter).generate({ ...assistantPrompt(request, types), maxOutputTokens: 2048 });
|
|
123
|
+
await record(event, user, "assistant", null, result.usage);
|
|
124
|
+
return { proposals: parseProposals(result.text) };
|
|
125
|
+
}
|
|
126
|
+
if (action === "usage" && method === "GET") {
|
|
127
|
+
if (!policy.can(user, "manage", "users"))
|
|
128
|
+
throw apiError(403, "Only those who manage users see AI usage");
|
|
129
|
+
const { from, to } = validated(Period, getQuery(event));
|
|
130
|
+
const { db, table } = await usageTable();
|
|
131
|
+
const rows = await db.select().from(table).where(and(from ? gte(table.created_at, from) : void 0, to ? lte(table.created_at, `${to}T23:59:59.999Z`) : void 0));
|
|
132
|
+
const names = new Map((await (await useAtelierAuth()).users.list()).map((u) => [u.id, u.name || u.email]));
|
|
133
|
+
const groups = /* @__PURE__ */ new Map();
|
|
134
|
+
for (const row of rows) {
|
|
135
|
+
const key = `${row.user_id}\0${row.action}`;
|
|
136
|
+
const group = groups.get(key) ?? { userId: row.user_id, name: names.get(row.user_id) ?? row.user_id, action: row.action, requests: 0, inputTokens: 0, outputTokens: 0 };
|
|
137
|
+
group.requests++;
|
|
138
|
+
group.inputTokens += Number(row.input_tokens);
|
|
139
|
+
group.outputTokens += Number(row.output_tokens);
|
|
140
|
+
groups.set(key, group);
|
|
141
|
+
}
|
|
142
|
+
return [...groups.values()].toSorted((a, b) => a.name.localeCompare(b.name) || a.action.localeCompare(b.action));
|
|
143
|
+
}
|
|
144
|
+
throw apiError(404, "Not found");
|
|
145
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Whether `exclude` (`type`, or `type.field`) keeps this content type or field from the provider. */
|
|
2
|
+
export declare function excluded(exclude: readonly string[], type: string, field?: string): boolean;
|
|
3
|
+
/** Rewrite, shorten or expand a text. */
|
|
4
|
+
export declare function textPrompt(action: 'rewrite' | 'shorten' | 'expand', text: string, context: {
|
|
5
|
+
label: string;
|
|
6
|
+
locale?: string;
|
|
7
|
+
}): {
|
|
8
|
+
system: string;
|
|
9
|
+
prompt: string;
|
|
10
|
+
};
|
|
11
|
+
/** Translate a text, or a JSON value (rich text, a block) whose structure must come back unchanged. */
|
|
12
|
+
export declare function translatePrompt(value: unknown, to: string, from?: string): {
|
|
13
|
+
system: string;
|
|
14
|
+
prompt: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The translation of a JSON value, taken from the model's answer only where the original has a text that
|
|
18
|
+
* may change: the structure, ids, types and links stay the original's whatever the model did.
|
|
19
|
+
*/
|
|
20
|
+
export declare function mergeTranslation<T>(original: T, answer: string): T;
|
|
21
|
+
/** SEO title and description, from an entry's (allowed) text. */
|
|
22
|
+
export declare function seoPrompt(fields: Record<string, string>, locale?: string): {
|
|
23
|
+
system: string;
|
|
24
|
+
prompt: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function parseSeo(answer: string): {
|
|
27
|
+
title: string;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
30
|
+
/** Alt text for an image (sent alongside). */
|
|
31
|
+
export declare function altPrompt(filename: string, locale?: string): {
|
|
32
|
+
system: string;
|
|
33
|
+
prompt: string;
|
|
34
|
+
};
|
|
35
|
+
export interface Proposal {
|
|
36
|
+
method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
37
|
+
path: string;
|
|
38
|
+
body?: unknown;
|
|
39
|
+
summary: string;
|
|
40
|
+
}
|
|
41
|
+
/** What the assistant is told: what it may propose, and the content the user can see. */
|
|
42
|
+
export declare function assistantPrompt(request: string, types: {
|
|
43
|
+
name: string;
|
|
44
|
+
kind: 'collection' | 'singleton';
|
|
45
|
+
fields: string[];
|
|
46
|
+
actions: string[];
|
|
47
|
+
}[]): {
|
|
48
|
+
system: string;
|
|
49
|
+
prompt: string;
|
|
50
|
+
};
|
|
51
|
+
/** The proposals in the model's answer that are content API requests; anything else is dropped. */
|
|
52
|
+
export declare function parseProposals(answer: string): Proposal[];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const RULES = "Answer with the result only: no preamble, no quotes around it, no explanation.";
|
|
2
|
+
export function excluded(exclude, type, field) {
|
|
3
|
+
return exclude.includes(type) || field !== void 0 && exclude.includes(`${type}.${field}`);
|
|
4
|
+
}
|
|
5
|
+
export function textPrompt(action, text, context) {
|
|
6
|
+
const how = { rewrite: "Rewrite it to read more clearly, keeping its meaning, tone and length.", shorten: "Make it shorter, keeping what matters.", expand: "Expand it with more detail, in the same voice, without inventing facts." }[action];
|
|
7
|
+
return {
|
|
8
|
+
system: `You edit website copy. ${how} Keep its language${context.locale ? ` (${context.locale})` : ""}. ${RULES}`,
|
|
9
|
+
prompt: `The "${context.label}" field:
|
|
10
|
+
|
|
11
|
+
${text}`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const PROTECTED = /* @__PURE__ */ new Set(["id", "type", "href", "src", "url", "slug", "to", "ref", "key"]);
|
|
15
|
+
export function translatePrompt(value, to, from) {
|
|
16
|
+
const json = typeof value !== "string";
|
|
17
|
+
return {
|
|
18
|
+
system: `You translate website content into ${to}${from ? ` from ${from}` : ""}. Keep meaning, tone and formatting. ${json ? `The content is JSON: answer with the same JSON, translating only human-readable text values; keep every key, and every value of ${[...PROTECTED].join(", ")} and every non-text value, as it is. Answer with the JSON only.` : RULES}`,
|
|
19
|
+
prompt: json ? JSON.stringify(value) : String(value)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function mergeTranslation(original, answer) {
|
|
23
|
+
let translated;
|
|
24
|
+
try {
|
|
25
|
+
translated = JSON.parse(answer.trim().replace(/^```(?:json)?\s*|\s*```$/g, ""));
|
|
26
|
+
} catch {
|
|
27
|
+
throw new Error("The model's translation wasn't JSON");
|
|
28
|
+
}
|
|
29
|
+
const walk = (a, b, key) => {
|
|
30
|
+
if (typeof a === "string")
|
|
31
|
+
return typeof b === "string" && !PROTECTED.has(key ?? "") ? b : a;
|
|
32
|
+
if (Array.isArray(a))
|
|
33
|
+
return a.map((item, i) => walk(item, Array.isArray(b) ? b[i] : void 0));
|
|
34
|
+
if (a && typeof a === "object")
|
|
35
|
+
return Object.fromEntries(Object.entries(a).map(([k, v]) => [k, walk(v, b && typeof b === "object" ? b[k] : void 0, k)]));
|
|
36
|
+
return a;
|
|
37
|
+
};
|
|
38
|
+
return walk(original, translated);
|
|
39
|
+
}
|
|
40
|
+
export function seoPrompt(fields, locale) {
|
|
41
|
+
return {
|
|
42
|
+
system: `You write search engine titles and descriptions${locale ? ` in ${locale}` : ""}: a title of at most 60 characters and a description of at most 155, accurate to the page, without clickbait. Answer with JSON only: {"title": "\u2026", "description": "\u2026"}.`,
|
|
43
|
+
prompt: Object.entries(fields).map(([label, text]) => `${label}:
|
|
44
|
+
${text}`).join("\n\n")
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function parseSeo(answer) {
|
|
48
|
+
const json = JSON.parse(answer.trim().replace(/^```(?:json)?\s*|\s*```$/g, ""));
|
|
49
|
+
if (typeof json.title !== "string" || typeof json.description !== "string")
|
|
50
|
+
throw new Error("The model's answer had no title and description");
|
|
51
|
+
return { title: json.title.slice(0, 120), description: json.description.slice(0, 300) };
|
|
52
|
+
}
|
|
53
|
+
export function altPrompt(filename, locale) {
|
|
54
|
+
return {
|
|
55
|
+
system: `You write alt text for images on websites${locale ? `, in ${locale}` : ""}: what the image shows that matters to someone who can't see it, in one sentence of at most 125 characters, without "image of". ${RULES}`,
|
|
56
|
+
prompt: `The file is called "${filename}". Describe it.`
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const METHODS = /* @__PURE__ */ new Set(["GET", "POST", "PATCH", "DELETE"]);
|
|
60
|
+
const ALLOWED = /^\/api\/_atelier\/(?:collections|singletons|media)(?:\/[\w%-]+)*(?:\?[^\s#]*)?$/;
|
|
61
|
+
export function assistantPrompt(request, types) {
|
|
62
|
+
return {
|
|
63
|
+
system: `You help an editor work with a CMS by proposing requests to its content API. You never act yourself: the editor reviews each request, and the ones they approve are sent with their own permissions.
|
|
64
|
+
|
|
65
|
+
The API (JSON):
|
|
66
|
+
- GET /api/_atelier/collections/<type>?filter=<json>&sort=<json>&limit=<n>: list entries
|
|
67
|
+
- GET /api/_atelier/collections/<type>/<id>?draft=true: one entry
|
|
68
|
+
- POST /api/_atelier/collections/<type> {"data": {\u2026}, "publish"?: true}: create
|
|
69
|
+
- PATCH /api/_atelier/collections/<type>/<id> {"version": <the version read>, "data": {\u2026changed fields}}: update
|
|
70
|
+
- POST /api/_atelier/collections/<type>/<id>/publish {"version": n}, POST \u2026/unpublish
|
|
71
|
+
- DELETE /api/_atelier/collections/<type>/<id>
|
|
72
|
+
- GET and PATCH /api/_atelier/singletons/<name> {"version", "data"}
|
|
73
|
+
Filters: {"field": {"eq"|"ne"|"gt"|"lt"|"contains"|"in": value}}.
|
|
74
|
+
|
|
75
|
+
The content types (and what this editor may do with each):
|
|
76
|
+
${types.map((t) => `- ${t.kind} "${t.name}": fields ${t.fields.join(", ")}; may ${t.actions.join(", ") || "nothing"}`).join("\n")}
|
|
77
|
+
|
|
78
|
+
Answer with JSON only: [{"method": "\u2026", "path": "\u2026", "body": \u2026, "summary": "what this does, in a sentence"}]. Propose reads first when you need ids or versions you don't know; never invent them. An empty list when you can't help.`,
|
|
79
|
+
prompt: request
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function parseProposals(answer) {
|
|
83
|
+
let list;
|
|
84
|
+
try {
|
|
85
|
+
list = JSON.parse(answer.trim().replace(/^```(?:json)?\s*|\s*```$/g, ""));
|
|
86
|
+
} catch {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
if (!Array.isArray(list))
|
|
90
|
+
return [];
|
|
91
|
+
return list.flatMap((item) => {
|
|
92
|
+
const p = item;
|
|
93
|
+
const method = String(p.method ?? "").toUpperCase();
|
|
94
|
+
if (!METHODS.has(method) || typeof p.path !== "string" || !ALLOWED.test(p.path) || p.path.includes(".."))
|
|
95
|
+
return [];
|
|
96
|
+
return [{ method, path: p.path, ...p.body === void 0 || method === "GET" || method === "DELETE" ? {} : { body: p.body }, summary: String(p.summary ?? `${method} ${p.path}`).slice(0, 300) }];
|
|
97
|
+
}).slice(0, 20);
|
|
98
|
+
}
|
package/dist/types.d.mts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt-atelier/ai",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/AnoRebel/nuxt-atelier.git",
|
|
9
|
+
"directory": "packages/ai"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://nuxt-atelier.anorebel.net",
|
|
12
|
+
"description": "Provider-agnostic AI assist adapter for Nuxt Atelier",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/types.d.mts",
|
|
16
|
+
"import": "./dist/module.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/module.mjs",
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
"*": {
|
|
22
|
+
".": [
|
|
23
|
+
"./dist/types.d.mts"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "nuxt-module-build build",
|
|
32
|
+
"prepack": "nuxt-module-build build",
|
|
33
|
+
"check:pkg": "publint --pack bun && attw --pack . --profile esm-only"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"nuxt": ">=4.6.0",
|
|
37
|
+
"nuxt-atelier": "^0.1.0",
|
|
38
|
+
"@nuxt-atelier/admin": "^0.1.0"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@nuxt/kit": "^4.6.3",
|
|
42
|
+
"ai": "7.0.159",
|
|
43
|
+
"zod": "4.6.7"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@nuxt/schema": "4.6.3"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"@nuxt-atelier/admin": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|