@d4y/agent-runtime-nuxt 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/README.md +314 -0
- package/dist/module.d.mts +69 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +60 -0
- package/dist/runtime/components/AgentRuntimeArtifactPreview.d.vue.ts +14 -0
- package/dist/runtime/components/AgentRuntimeArtifactPreview.vue +112 -0
- package/dist/runtime/components/AgentRuntimeArtifactPreview.vue.d.ts +14 -0
- package/dist/runtime/composables/useAgentRuntime.d.ts +130 -0
- package/dist/runtime/composables/useAgentRuntime.js +306 -0
- package/dist/runtime/composables/useAgentRuntimeMarkdown.d.ts +15 -0
- package/dist/runtime/composables/useAgentRuntimeMarkdown.js +109 -0
- package/dist/runtime/server/api/app.get.d.ts +6 -0
- package/dist/runtime/server/api/app.get.js +26 -0
- package/dist/runtime/server/api/conversations/[id]/abort.post.d.ts +6 -0
- package/dist/runtime/server/api/conversations/[id]/abort.post.js +18 -0
- package/dist/runtime/server/api/conversations/[id]/env.post.d.ts +10 -0
- package/dist/runtime/server/api/conversations/[id]/env.post.js +22 -0
- package/dist/runtime/server/api/conversations/[id]/files/raw/[...path].get.d.ts +11 -0
- package/dist/runtime/server/api/conversations/[id]/files/raw/[...path].get.js +31 -0
- package/dist/runtime/server/api/conversations/[id]/files.get.d.ts +14 -0
- package/dist/runtime/server/api/conversations/[id]/files.get.js +16 -0
- package/dist/runtime/server/api/conversations/[id]/history.get.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id]/history.get.js +16 -0
- package/dist/runtime/server/api/conversations/[id]/messages.post.d.ts +7 -0
- package/dist/runtime/server/api/conversations/[id]/messages.post.js +20 -0
- package/dist/runtime/server/api/conversations/[id]/stream.get.d.ts +9 -0
- package/dist/runtime/server/api/conversations/[id]/stream.get.js +28 -0
- package/dist/runtime/server/api/conversations/[id].delete.d.ts +2 -0
- package/dist/runtime/server/api/conversations/[id].delete.js +18 -0
- package/dist/runtime/server/api/conversations.post.d.ts +7 -0
- package/dist/runtime/server/api/conversations.post.js +17 -0
- package/dist/runtime/server/utils/agent-runtime.d.ts +12 -0
- package/dist/runtime/server/utils/agent-runtime.js +12 -0
- package/dist/runtime/utils/files.d.ts +16 -0
- package/dist/runtime/utils/files.js +42 -0
- package/dist/types.d.mts +9 -0
- package/package.json +67 -0
- package/src/frontend.ts +16 -0
- package/src/module.ts +155 -0
- package/src/nitro-globals.d.ts +8 -0
- package/src/runtime/components/AgentRuntimeArtifactPreview.vue +192 -0
- package/src/runtime/composables/useAgentRuntime.ts +527 -0
- package/src/runtime/composables/useAgentRuntimeMarkdown.ts +145 -0
- package/src/runtime/server/api/app.get.ts +50 -0
- package/src/runtime/server/api/conversations/[id]/abort.post.ts +26 -0
- package/src/runtime/server/api/conversations/[id]/env.post.ts +34 -0
- package/src/runtime/server/api/conversations/[id]/files/raw/[...path].get.ts +48 -0
- package/src/runtime/server/api/conversations/[id]/files.get.ts +33 -0
- package/src/runtime/server/api/conversations/[id]/history.get.ts +20 -0
- package/src/runtime/server/api/conversations/[id]/messages.post.ts +29 -0
- package/src/runtime/server/api/conversations/[id]/stream.get.ts +41 -0
- package/src/runtime/server/api/conversations/[id].delete.ts +22 -0
- package/src/runtime/server/api/conversations.post.ts +26 -0
- package/src/runtime/server/utils/agent-runtime.ts +33 -0
- package/src/runtime/utils/files.ts +78 -0
- package/src/shared.ts +46 -0
- package/src/vue-shim.d.ts +6 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
|
3
|
+
import { getAgentRuntimeFilePreviewKind, type AgentRuntimeFileLike } from '../utils/files'
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(defineProps<{
|
|
6
|
+
file: AgentRuntimeFileLike
|
|
7
|
+
src?: string | null
|
|
8
|
+
resolveSrc?: ((relPath: string) => string | null | undefined) | null
|
|
9
|
+
textMaxChars?: number
|
|
10
|
+
}>(), {
|
|
11
|
+
src: null,
|
|
12
|
+
resolveSrc: null,
|
|
13
|
+
textMaxChars: 120_000,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const kind = computed(() => getAgentRuntimeFilePreviewKind(props.file))
|
|
17
|
+
const resolvedSrc = computed(() => {
|
|
18
|
+
if (props.src) {
|
|
19
|
+
return props.src
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!props.file.relPath || !props.resolveSrc) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return props.resolveSrc(props.file.relPath) ?? null
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const textContent = ref('')
|
|
30
|
+
const textError = ref<string | null>(null)
|
|
31
|
+
const textLoading = ref(false)
|
|
32
|
+
let textAbortController: AbortController | null = null
|
|
33
|
+
|
|
34
|
+
const abortTextLoad = () => {
|
|
35
|
+
textAbortController?.abort()
|
|
36
|
+
textAbortController = null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const loadTextPreview = async () => {
|
|
40
|
+
abortTextLoad()
|
|
41
|
+
textContent.value = ''
|
|
42
|
+
textError.value = null
|
|
43
|
+
|
|
44
|
+
if (kind.value !== 'text' || !resolvedSrc.value) {
|
|
45
|
+
textLoading.value = false
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const controller = new AbortController()
|
|
50
|
+
textAbortController = controller
|
|
51
|
+
textLoading.value = true
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const response = await fetch(resolvedSrc.value, {
|
|
55
|
+
signal: controller.signal,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
throw new Error(`Failed to load preview (${response.status})`)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const body = await response.text()
|
|
63
|
+
textContent.value =
|
|
64
|
+
body.length > props.textMaxChars
|
|
65
|
+
? `${body.slice(0, props.textMaxChars).trimEnd()}\n\n…`
|
|
66
|
+
: body
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (controller.signal.aborted) {
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
textError.value = error instanceof Error ? error.message : 'Failed to load preview'
|
|
73
|
+
} finally {
|
|
74
|
+
if (textAbortController === controller) {
|
|
75
|
+
textAbortController = null
|
|
76
|
+
}
|
|
77
|
+
textLoading.value = false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
watch([kind, resolvedSrc], () => {
|
|
82
|
+
void loadTextPreview()
|
|
83
|
+
}, { immediate: true })
|
|
84
|
+
|
|
85
|
+
onBeforeUnmount(() => {
|
|
86
|
+
abortTextLoad()
|
|
87
|
+
})
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<template>
|
|
91
|
+
<div class="agent-runtime-artifact-preview">
|
|
92
|
+
<img
|
|
93
|
+
v-if="kind === 'image' && resolvedSrc"
|
|
94
|
+
:src="resolvedSrc"
|
|
95
|
+
:alt="file.name ?? file.relPath ?? 'Preview image'"
|
|
96
|
+
class="agent-runtime-artifact-preview__image">
|
|
97
|
+
|
|
98
|
+
<iframe
|
|
99
|
+
v-else-if="kind === 'pdf' && resolvedSrc"
|
|
100
|
+
:src="resolvedSrc"
|
|
101
|
+
:title="file.name ?? file.relPath ?? 'PDF preview'"
|
|
102
|
+
class="agent-runtime-artifact-preview__frame" />
|
|
103
|
+
|
|
104
|
+
<div v-else-if="kind === 'text'" class="agent-runtime-artifact-preview__text-shell">
|
|
105
|
+
<div v-if="textLoading" class="agent-runtime-artifact-preview__note">
|
|
106
|
+
Loading preview…
|
|
107
|
+
</div>
|
|
108
|
+
<div v-else-if="textError" class="agent-runtime-artifact-preview__note agent-runtime-artifact-preview__note--error">
|
|
109
|
+
{{ textError }}
|
|
110
|
+
</div>
|
|
111
|
+
<pre v-else class="agent-runtime-artifact-preview__text">{{ textContent }}</pre>
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div v-else class="agent-runtime-artifact-preview__fallback">
|
|
115
|
+
<p class="agent-runtime-artifact-preview__note">
|
|
116
|
+
Preview unavailable for this file type.
|
|
117
|
+
</p>
|
|
118
|
+
<a
|
|
119
|
+
v-if="resolvedSrc"
|
|
120
|
+
:href="resolvedSrc"
|
|
121
|
+
target="_blank"
|
|
122
|
+
rel="noopener noreferrer"
|
|
123
|
+
class="agent-runtime-artifact-preview__link">
|
|
124
|
+
Open file
|
|
125
|
+
</a>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</template>
|
|
129
|
+
|
|
130
|
+
<style scoped>
|
|
131
|
+
.agent-runtime-artifact-preview {
|
|
132
|
+
display: block;
|
|
133
|
+
width: 100%;
|
|
134
|
+
min-height: 12rem;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.agent-runtime-artifact-preview__image,
|
|
138
|
+
.agent-runtime-artifact-preview__frame {
|
|
139
|
+
display: block;
|
|
140
|
+
width: 100%;
|
|
141
|
+
border: 0;
|
|
142
|
+
border-radius: 0.875rem;
|
|
143
|
+
background: rgba(15, 23, 42, 0.04);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.agent-runtime-artifact-preview__image {
|
|
147
|
+
max-height: min(70vh, 48rem);
|
|
148
|
+
object-fit: contain;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.agent-runtime-artifact-preview__frame {
|
|
152
|
+
min-height: min(78vh, 52rem);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.agent-runtime-artifact-preview__text-shell,
|
|
156
|
+
.agent-runtime-artifact-preview__fallback {
|
|
157
|
+
min-height: 18rem;
|
|
158
|
+
border-radius: 0.875rem;
|
|
159
|
+
border: 1px solid rgba(15, 23, 42, 0.1);
|
|
160
|
+
background: rgba(15, 23, 42, 0.03);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.agent-runtime-artifact-preview__text {
|
|
164
|
+
margin: 0;
|
|
165
|
+
max-height: min(72vh, 52rem);
|
|
166
|
+
overflow: auto;
|
|
167
|
+
padding: 1rem;
|
|
168
|
+
font-family: ui-monospace, SFMono-Regular, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace;
|
|
169
|
+
font-size: 0.8rem;
|
|
170
|
+
line-height: 1.55;
|
|
171
|
+
white-space: pre-wrap;
|
|
172
|
+
word-break: break-word;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.agent-runtime-artifact-preview__note {
|
|
176
|
+
padding: 1rem;
|
|
177
|
+
font-size: 0.875rem;
|
|
178
|
+
color: rgba(15, 23, 42, 0.72);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.agent-runtime-artifact-preview__note--error {
|
|
182
|
+
color: rgb(185, 28, 28);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.agent-runtime-artifact-preview__link {
|
|
186
|
+
display: inline-flex;
|
|
187
|
+
margin: 0 1rem 1rem;
|
|
188
|
+
color: inherit;
|
|
189
|
+
text-decoration: underline;
|
|
190
|
+
text-underline-offset: 0.18em;
|
|
191
|
+
}
|
|
192
|
+
</style>
|