@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,118 @@
1
+ import { createIncremarkParser, type IncremarkParserOptions } from '@incremark/core';
2
+
3
+ import {
4
+ highlightCodeSnippetHtml,
5
+ type IncremarkCodeTheme
6
+ } from './incremarkCodeHighlight';
7
+ import { renderIncremarkAst, renderKatexIncremarkHtml } from './incremarkRenderer';
8
+
9
+ const INCREMARK_PARSER_OPTIONS = {
10
+ gfm: true,
11
+ math: { tex: true },
12
+ containers: true,
13
+ htmlTree: true
14
+ } satisfies IncremarkParserOptions;
15
+
16
+ const INCREMARK_CODE_BLOCK_PATTERN =
17
+ /(<div class="incremark-block incremark-code"><div class="incremark-code-toolbar">[\s\S]*?<\/div>)<pre><code(?: class="language-([^"]+)")?>([\s\S]*?)<\/code><\/pre><\/div>/g;
18
+ const HTML_ENTITY_RE = /&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g;
19
+
20
+ const NAMED_HTML_ENTITIES: Record<string, string> = {
21
+ amp: '&',
22
+ apos: "'",
23
+ gt: '>',
24
+ lt: '<',
25
+ quot: '"'
26
+ };
27
+
28
+ export async function renderIncremarkMarkdown(
29
+ markdown: string,
30
+ theme: IncremarkCodeTheme = 'dark'
31
+ ): Promise<string> {
32
+ const parser = createIncremarkParser(INCREMARK_PARSER_OPTIONS);
33
+
34
+ if (markdown) {
35
+ parser.append(markdown);
36
+ }
37
+
38
+ parser.finalize();
39
+
40
+ const baseHtml = renderIncremarkAst(parser.getAst());
41
+ const mathHtml = await renderKatexIncremarkHtml(baseHtml);
42
+ return highlightRenderedIncremarkHtmlServer(mathHtml, theme);
43
+ }
44
+
45
+ async function highlightRenderedIncremarkHtmlServer(
46
+ html: string,
47
+ theme: IncremarkCodeTheme
48
+ ): Promise<string> {
49
+ if (!html.includes('incremark-code')) {
50
+ return html;
51
+ }
52
+
53
+ return replaceAsync(html, INCREMARK_CODE_BLOCK_PATTERN, async (_match, prefix, language, code) => {
54
+ const highlightedHtml = await highlightCodeSnippetHtml(
55
+ decodeHtmlEntities(code),
56
+ language ?? 'text',
57
+ theme
58
+ );
59
+
60
+ return `${prefix}${addClassToPreTag(highlightedHtml, 'incremark-code-highlight')}</div>`;
61
+ });
62
+ }
63
+
64
+ async function replaceAsync(
65
+ value: string,
66
+ pattern: RegExp,
67
+ replacer: (...args: string[]) => Promise<string>
68
+ ): Promise<string> {
69
+ pattern.lastIndex = 0;
70
+ const matches = Array.from(value.matchAll(pattern));
71
+ if (matches.length === 0) {
72
+ return value;
73
+ }
74
+
75
+ const replacements = await Promise.all(matches.map((match) => replacer(...match)));
76
+
77
+ let cursor = 0;
78
+ let result = '';
79
+
80
+ for (const [index, match] of matches.entries()) {
81
+ const fullMatch = match[0];
82
+ const matchIndex = match.index ?? 0;
83
+ result += value.slice(cursor, matchIndex);
84
+ result += replacements[index];
85
+ cursor = matchIndex + fullMatch.length;
86
+ }
87
+
88
+ result += value.slice(cursor);
89
+ return result;
90
+ }
91
+
92
+ function addClassToPreTag(html: string, className: string): string {
93
+ if (html.startsWith('<pre class="')) {
94
+ return html.replace('<pre class="', `<pre class="${className} `);
95
+ }
96
+
97
+ if (html.startsWith('<pre ')) {
98
+ return html.replace('<pre ', `<pre class="${className}" `);
99
+ }
100
+
101
+ return html.replace('<pre>', `<pre class="${className}">`);
102
+ }
103
+
104
+ function decodeHtmlEntities(value: string): string {
105
+ return value.replace(HTML_ENTITY_RE, (match, entity) => {
106
+ if (entity.startsWith('#x') || entity.startsWith('#X')) {
107
+ const codePoint = Number.parseInt(entity.slice(2), 16);
108
+ return Number.isNaN(codePoint) ? match : String.fromCodePoint(codePoint);
109
+ }
110
+
111
+ if (entity.startsWith('#')) {
112
+ const codePoint = Number.parseInt(entity.slice(1), 10);
113
+ return Number.isNaN(codePoint) ? match : String.fromCodePoint(codePoint);
114
+ }
115
+
116
+ return NAMED_HTML_ENTITIES[entity] ?? match;
117
+ });
118
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "custom",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "packageManager": "pnpm@10.33.0",
13
+ "dependencies": {
14
+ "@ai-sdk/vue": "^3.0.158",
15
+ "@incremark/core": "^1.0.2",
16
+ "@incremark/theme": "^1.0.2",
17
+ "@incremark/vue": "^1.0.2",
18
+ "@shikijs/langs": "^4.0.2",
19
+ "@shikijs/themes": "^4.0.2",
20
+ "@vueuse/core": "^14.2.1",
21
+ "ai": "^6.0.158",
22
+ "dompurify": "^3.3.3",
23
+ "katex": "^0.16.45",
24
+ "marked": "^18.0.0"
25
+ }
26
+ }