@adminforth/agent 1.0.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.
Files changed (66) hide show
  1. package/.woodpecker/buildRelease.sh +13 -0
  2. package/.woodpecker/buildSlackNotify.sh +46 -0
  3. package/.woodpecker/release.yml +57 -0
  4. package/agent/middleware/apiBasedTools.ts +109 -0
  5. package/agent/middleware/sequenceDebug.ts +302 -0
  6. package/agent/simpleAgent.ts +291 -0
  7. package/agent/skills/registry.ts +135 -0
  8. package/agent/systemPrompt.ts +69 -0
  9. package/agent/toolCallEvents.ts +17 -0
  10. package/agent/tools/apiTool.ts +99 -0
  11. package/agent/tools/fetchSkill.ts +58 -0
  12. package/agent/tools/fetchToolSchema.ts +50 -0
  13. package/agent/tools/index.ts +26 -0
  14. package/apiBasedTools.ts +625 -0
  15. package/build.log +30 -0
  16. package/custom/ChatSurface.vue +184 -0
  17. package/custom/ConversationArea.vue +175 -0
  18. package/custom/Message.vue +206 -0
  19. package/custom/SessionsHistory.vue +93 -0
  20. package/custom/ToolRenderer.vue +131 -0
  21. package/custom/ToolsGroup.vue +67 -0
  22. package/custom/incremark_code_renderers/IncremarkShikiCodeBlock.vue +301 -0
  23. package/custom/incremark_code_renderers/incremarkCodeHighlight.ts +285 -0
  24. package/custom/incremark_code_renderers/incremarkRenderer.ts +653 -0
  25. package/custom/incremark_code_renderers/renderIncremarkMarkdown.ts +118 -0
  26. package/custom/package.json +26 -0
  27. package/custom/pnpm-lock.yaml +1467 -0
  28. package/custom/skills/fetch_data/SKILL.md +15 -0
  29. package/custom/skills/mutate_data/SKILL.md +108 -0
  30. package/custom/tsconfig.json +16 -0
  31. package/custom/types.ts +34 -0
  32. package/custom/useAgentStore.ts +349 -0
  33. package/dist/agent/middleware/apiBasedTools.js +91 -0
  34. package/dist/agent/middleware/sequenceDebug.js +210 -0
  35. package/dist/agent/simpleAgent.js +173 -0
  36. package/dist/agent/skills/registry.js +108 -0
  37. package/dist/agent/systemPrompt.js +64 -0
  38. package/dist/agent/toolCallEvents.js +1 -0
  39. package/dist/agent/tools/apiTool.js +93 -0
  40. package/dist/agent/tools/fetchSkill.js +51 -0
  41. package/dist/agent/tools/fetchToolSchema.js +36 -0
  42. package/dist/agent/tools/index.js +28 -0
  43. package/dist/apiBasedTools.js +412 -0
  44. package/dist/custom/ChatSurface.vue +184 -0
  45. package/dist/custom/ConversationArea.vue +175 -0
  46. package/dist/custom/Message.vue +206 -0
  47. package/dist/custom/SessionsHistory.vue +93 -0
  48. package/dist/custom/ToolRenderer.vue +131 -0
  49. package/dist/custom/ToolsGroup.vue +67 -0
  50. package/dist/custom/incremark_code_renderers/IncremarkShikiCodeBlock.vue +301 -0
  51. package/dist/custom/incremark_code_renderers/incremarkCodeHighlight.ts +285 -0
  52. package/dist/custom/incremark_code_renderers/incremarkRenderer.ts +653 -0
  53. package/dist/custom/incremark_code_renderers/renderIncremarkMarkdown.ts +118 -0
  54. package/dist/custom/package.json +26 -0
  55. package/dist/custom/pnpm-lock.yaml +1467 -0
  56. package/dist/custom/skills/fetch_data/SKILL.md +15 -0
  57. package/dist/custom/skills/mutate_data/SKILL.md +108 -0
  58. package/dist/custom/tsconfig.json +16 -0
  59. package/dist/custom/types.ts +34 -0
  60. package/dist/custom/useAgentStore.ts +349 -0
  61. package/dist/index.js +415 -0
  62. package/dist/types.js +1 -0
  63. package/index.ts +457 -0
  64. package/package.json +58 -0
  65. package/tsconfig.json +13 -0
  66. package/types.ts +45 -0
@@ -0,0 +1,285 @@
1
+ import {
2
+ createBundledHighlighter,
3
+ type HighlighterGeneric,
4
+ type LanguageInput,
5
+ type ThemeInput
6
+ } from 'shiki/core';
7
+ import { createOnigurumaEngine } from 'shiki/engine/oniguruma';
8
+
9
+ export type IncremarkCodeTheme = 'dark' | 'light';
10
+
11
+ export const TOP_SHIKI_LANGS = [
12
+ 'typescript',
13
+ 'javascript',
14
+ 'python',
15
+ 'html',
16
+ 'css',
17
+ 'sql',
18
+ 'shellscript',
19
+ 'json',
20
+ 'yaml',
21
+ 'markdown',
22
+ 'java',
23
+ 'csharp',
24
+ 'cpp',
25
+ 'c',
26
+ 'php',
27
+ 'go',
28
+ 'rust',
29
+ 'powershell',
30
+ 'kotlin',
31
+ 'lua',
32
+ 'swift',
33
+ 'ruby',
34
+ 'dart',
35
+ 'scala',
36
+ 'perl',
37
+ 'r',
38
+ 'tsx',
39
+ 'jsx',
40
+ 'dockerfile',
41
+ 'vue'
42
+ ] as const;
43
+
44
+ type SupportedShikiLanguage = (typeof TOP_SHIKI_LANGS)[number];
45
+ type SupportedShikiTheme = 'github-dark' | 'github-light';
46
+ type ActiveShikiLanguage = SupportedShikiLanguage | typeof FALLBACK_LANGUAGE;
47
+
48
+ const SHIKI_THEME_BY_MODE = {
49
+ dark: 'github-dark',
50
+ light: 'github-light'
51
+ } as const satisfies Record<IncremarkCodeTheme, SupportedShikiTheme>;
52
+ const FALLBACK_LANGUAGE = 'text' as const;
53
+ const SUPPORTED_SHIKI_LANG_SET = new Set<string>(TOP_SHIKI_LANGS);
54
+ const LANGUAGE_ALIASES = {
55
+ bash: 'shellscript',
56
+ 'c#': 'csharp',
57
+ cjs: 'javascript',
58
+ 'c++': 'cpp',
59
+ cs: 'csharp',
60
+ docker: 'dockerfile',
61
+ golang: 'go',
62
+ html: 'html',
63
+ js: 'javascript',
64
+ jsx: 'jsx',
65
+ kt: 'kotlin',
66
+ kts: 'kotlin',
67
+ md: 'markdown',
68
+ mjs: 'javascript',
69
+ ps: 'powershell',
70
+ ps1: 'powershell',
71
+ py: 'python',
72
+ rb: 'ruby',
73
+ sh: 'shellscript',
74
+ shell: 'shellscript',
75
+ ts: 'typescript',
76
+ tsx: 'tsx',
77
+ yml: 'yaml',
78
+ zsh: 'shellscript'
79
+ } as const satisfies Record<string, SupportedShikiLanguage>;
80
+
81
+ const SHIKI_THEME_LOADERS = {
82
+ 'github-dark': () => import('@shikijs/themes/github-dark'),
83
+ 'github-light': () => import('@shikijs/themes/github-light')
84
+ } as const satisfies Record<SupportedShikiTheme, ThemeInput>;
85
+
86
+ const SHIKI_LANGUAGE_LOADERS = {
87
+ typescript: () => import('@shikijs/langs/typescript'),
88
+ javascript: () => import('@shikijs/langs/javascript'),
89
+ python: () => import('@shikijs/langs/python'),
90
+ html: () => import('@shikijs/langs/html'),
91
+ css: () => import('@shikijs/langs/css'),
92
+ sql: () => import('@shikijs/langs/sql'),
93
+ shellscript: () => import('@shikijs/langs/shellscript'),
94
+ json: () => import('@shikijs/langs/json'),
95
+ yaml: () => import('@shikijs/langs/yaml'),
96
+ markdown: () => import('@shikijs/langs/markdown'),
97
+ java: () => import('@shikijs/langs/java'),
98
+ csharp: () => import('@shikijs/langs/csharp'),
99
+ cpp: () => import('@shikijs/langs/cpp'),
100
+ c: () => import('@shikijs/langs/c'),
101
+ php: () => import('@shikijs/langs/php'),
102
+ go: () => import('@shikijs/langs/go'),
103
+ rust: () => import('@shikijs/langs/rust'),
104
+ powershell: () => import('@shikijs/langs/powershell'),
105
+ kotlin: () => import('@shikijs/langs/kotlin'),
106
+ lua: () => import('@shikijs/langs/lua'),
107
+ swift: () => import('@shikijs/langs/swift'),
108
+ ruby: () => import('@shikijs/langs/ruby'),
109
+ dart: () => import('@shikijs/langs/dart'),
110
+ scala: () => import('@shikijs/langs/scala'),
111
+ perl: () => import('@shikijs/langs/perl'),
112
+ r: () => import('@shikijs/langs/r'),
113
+ tsx: () => import('@shikijs/langs/tsx'),
114
+ jsx: () => import('@shikijs/langs/jsx'),
115
+ dockerfile: () => import('@shikijs/langs/dockerfile'),
116
+ vue: () => import('@shikijs/langs/vue')
117
+ } as const satisfies Record<SupportedShikiLanguage, LanguageInput>;
118
+
119
+ const createShikiHighlighter = createBundledHighlighter({
120
+ themes: SHIKI_THEME_LOADERS,
121
+ langs: SHIKI_LANGUAGE_LOADERS,
122
+ engine: () => createOnigurumaEngine(() => import('shiki/wasm'))
123
+ });
124
+
125
+ interface HighlighterState {
126
+ highlighter: HighlighterGeneric<SupportedShikiLanguage, SupportedShikiTheme>;
127
+ loadedLanguages: Set<SupportedShikiLanguage>;
128
+ loadedThemes: Set<SupportedShikiTheme>;
129
+ }
130
+
131
+ const MAX_HIGHLIGHT_CACHE_ENTRIES = 200;
132
+ const highlightedHtmlCache = new Map<string, string>();
133
+ const unsupportedLanguageCache = new Set<string>();
134
+
135
+ let highlighterPromise: Promise<HighlighterState> | null = null;
136
+
137
+ export async function highlightCodeSnippetHtml(
138
+ code: string,
139
+ language: string,
140
+ theme: IncremarkCodeTheme = 'dark'
141
+ ): Promise<string> {
142
+ return highlightCodeToHtml(code, language, theme);
143
+ }
144
+
145
+ export async function highlightRenderedIncremarkHtml(
146
+ html: string,
147
+ theme: IncremarkCodeTheme = 'dark'
148
+ ): Promise<string> {
149
+ if (typeof DOMParser === 'undefined' || !html.includes('incremark-code')) {
150
+ return html;
151
+ }
152
+ const document = new DOMParser().parseFromString(`<body>${html}</body>`, 'text/html');
153
+ const codeBlocks = Array.from(document.body.querySelectorAll('.incremark-code'));
154
+
155
+ await Promise.all(codeBlocks.map(async (block) => {
156
+ const preElement = block.querySelector('pre');
157
+ const codeElement = preElement?.querySelector('code');
158
+ if (!preElement || !codeElement) {
159
+ return;
160
+ }
161
+
162
+ const sourceCode = codeElement.textContent ?? '';
163
+ if (!sourceCode.trim()) {
164
+ return;
165
+ }
166
+
167
+ const languageClass = Array.from(codeElement.classList).find((className) => className.startsWith('language-'));
168
+ const language = languageClass ? languageClass.slice('language-'.length) : FALLBACK_LANGUAGE;
169
+ const highlightedHtml = await highlightCodeToHtml(sourceCode, language, theme);
170
+ const template = document.createElement('template');
171
+ template.innerHTML = highlightedHtml.trim();
172
+
173
+ const highlightedPre = template.content.firstElementChild;
174
+ if (!highlightedPre) {
175
+ return;
176
+ }
177
+
178
+ highlightedPre.classList.add('incremark-code-highlight');
179
+ preElement.replaceWith(highlightedPre);
180
+ }));
181
+ return document.body.innerHTML;
182
+ }
183
+
184
+ async function highlightCodeToHtml(
185
+ code: string,
186
+ language: string,
187
+ theme: IncremarkCodeTheme
188
+ ): Promise<string> {
189
+ const normalizedLanguage = normalizeLanguage(language);
190
+ const shikiTheme = SHIKI_THEME_BY_MODE[theme];
191
+ const cacheKey = `${shikiTheme}\u0000${normalizedLanguage}\u0000${code}`;
192
+ const cachedHtml = highlightedHtmlCache.get(cacheKey);
193
+ if (cachedHtml) {
194
+ return cachedHtml;
195
+ }
196
+
197
+ const state = await getHighlighter();
198
+ await ensureTheme(state, shikiTheme);
199
+ const activeLanguage = await ensureLanguage(state, normalizedLanguage);
200
+ const highlightedHtml = state.highlighter.codeToHtml(code, {
201
+ lang: activeLanguage,
202
+ theme: shikiTheme
203
+ });
204
+
205
+ setHighlightedHtmlCache(cacheKey, highlightedHtml);
206
+ return highlightedHtml;
207
+ }
208
+
209
+ function setHighlightedHtmlCache(cacheKey: string, highlightedHtml: string): void {
210
+ if (highlightedHtmlCache.has(cacheKey)) {
211
+ highlightedHtmlCache.delete(cacheKey);
212
+ }
213
+
214
+ highlightedHtmlCache.set(cacheKey, highlightedHtml);
215
+
216
+ if (highlightedHtmlCache.size <= MAX_HIGHLIGHT_CACHE_ENTRIES) {
217
+ return;
218
+ }
219
+
220
+ const oldestCacheKey = highlightedHtmlCache.keys().next().value;
221
+ if (oldestCacheKey) {
222
+ highlightedHtmlCache.delete(oldestCacheKey);
223
+ }
224
+ }
225
+
226
+ async function getHighlighter(): Promise<HighlighterState> {
227
+ if (!highlighterPromise) {
228
+ highlighterPromise = (async () => {
229
+ const highlighter = await createShikiHighlighter({
230
+ themes: [],
231
+ langs: []
232
+ });
233
+
234
+ return {
235
+ highlighter,
236
+ loadedLanguages: new Set(),
237
+ loadedThemes: new Set()
238
+ };
239
+ })();
240
+ }
241
+
242
+ return highlighterPromise;
243
+ }
244
+
245
+ async function ensureTheme(state: HighlighterState, theme: SupportedShikiTheme): Promise<void> {
246
+ if (state.loadedThemes.has(theme)) {
247
+ return;
248
+ }
249
+
250
+ await state.highlighter.loadTheme(theme);
251
+ state.loadedThemes.add(theme);
252
+ }
253
+
254
+ async function ensureLanguage(state: HighlighterState, language: string): Promise<ActiveShikiLanguage> {
255
+ if (language === FALLBACK_LANGUAGE || unsupportedLanguageCache.has(language)) {
256
+ return FALLBACK_LANGUAGE;
257
+ }
258
+
259
+ if (!isSupportedShikiLanguage(language)) {
260
+ unsupportedLanguageCache.add(language);
261
+ return FALLBACK_LANGUAGE;
262
+ }
263
+
264
+ if (state.loadedLanguages.has(language)) {
265
+ return language;
266
+ }
267
+
268
+ await state.highlighter.loadLanguage(language);
269
+ state.loadedLanguages.add(language);
270
+ return language;
271
+ }
272
+
273
+ function normalizeLanguage(language: string): string {
274
+ const normalized = language.trim().toLowerCase();
275
+ if (!normalized) {
276
+ return FALLBACK_LANGUAGE;
277
+ }
278
+
279
+ const aliasedLanguage = LANGUAGE_ALIASES[normalized as keyof typeof LANGUAGE_ALIASES];
280
+ return aliasedLanguage ?? normalized;
281
+ }
282
+
283
+ function isSupportedShikiLanguage(language: string): language is SupportedShikiLanguage {
284
+ return SUPPORTED_SHIKI_LANG_SET.has(language);
285
+ }