kimaki 0.4.2 → 0.4.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/dist/cli.js +34 -38
- package/dist/discordBot.js +345 -145
- package/dist/escape-backticks.test.js +125 -0
- package/dist/tools.js +2 -1
- package/package.json +12 -14
- package/src/cli.ts +37 -50
- package/src/discordBot.ts +468 -159
- package/src/escape-backticks.test.ts +146 -0
- package/src/tools.ts +2 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { test, expect } from 'vitest'
|
|
2
|
+
import { Lexer } from 'marked'
|
|
3
|
+
import { escapeBackticksInCodeBlocks } from './discordBot.js'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
test('escapes single backticks in code blocks', () => {
|
|
8
|
+
const input = '```js\nconst x = `hello`\n```'
|
|
9
|
+
const result = escapeBackticksInCodeBlocks(input)
|
|
10
|
+
|
|
11
|
+
expect(result).toMatchInlineSnapshot(`
|
|
12
|
+
"\`\`\`js
|
|
13
|
+
const x = \\\`hello\\\`
|
|
14
|
+
\`\`\`
|
|
15
|
+
"
|
|
16
|
+
`)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('escapes backticks in code blocks with language', () => {
|
|
20
|
+
const input = '```typescript\nconst greeting = `Hello, ${name}!`\nconst inline = `test`\n```'
|
|
21
|
+
const result = escapeBackticksInCodeBlocks(input)
|
|
22
|
+
|
|
23
|
+
expect(result).toMatchInlineSnapshot(`
|
|
24
|
+
"\`\`\`typescript
|
|
25
|
+
const greeting = \\\`Hello, \${name}!\\\`
|
|
26
|
+
const inline = \\\`test\\\`
|
|
27
|
+
\`\`\`
|
|
28
|
+
"
|
|
29
|
+
`)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('does not escape backticks outside code blocks', () => {
|
|
33
|
+
const input = 'This is `inline code` and this is a code block:\n```\nconst x = `template`\n```'
|
|
34
|
+
const result = escapeBackticksInCodeBlocks(input)
|
|
35
|
+
|
|
36
|
+
expect(result).toMatchInlineSnapshot(`
|
|
37
|
+
"This is \`inline code\` and this is a code block:
|
|
38
|
+
\`\`\`
|
|
39
|
+
const x = \\\`template\\\`
|
|
40
|
+
\`\`\`
|
|
41
|
+
"
|
|
42
|
+
`)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('handles multiple code blocks', () => {
|
|
46
|
+
const input = `First block:
|
|
47
|
+
\`\`\`js
|
|
48
|
+
const a = \`test\`
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
Some text with \`inline\` code
|
|
52
|
+
|
|
53
|
+
Second block:
|
|
54
|
+
\`\`\`python
|
|
55
|
+
name = f\`hello {world}\`
|
|
56
|
+
\`\`\``
|
|
57
|
+
|
|
58
|
+
const result = escapeBackticksInCodeBlocks(input)
|
|
59
|
+
|
|
60
|
+
expect(result).toMatchInlineSnapshot(`
|
|
61
|
+
"First block:
|
|
62
|
+
\`\`\`js
|
|
63
|
+
const a = \\\`test\\\`
|
|
64
|
+
\`\`\`
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
Some text with \`inline\` code
|
|
68
|
+
|
|
69
|
+
Second block:
|
|
70
|
+
\`\`\`python
|
|
71
|
+
name = f\\\`hello {world}\\\`
|
|
72
|
+
\`\`\`
|
|
73
|
+
"
|
|
74
|
+
`)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('handles code blocks without language', () => {
|
|
78
|
+
const input = '```\nconst x = `value`\n```'
|
|
79
|
+
const result = escapeBackticksInCodeBlocks(input)
|
|
80
|
+
|
|
81
|
+
expect(result).toMatchInlineSnapshot(`
|
|
82
|
+
"\`\`\`
|
|
83
|
+
const x = \\\`value\\\`
|
|
84
|
+
\`\`\`
|
|
85
|
+
"
|
|
86
|
+
`)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('handles nested backticks in code blocks', () => {
|
|
90
|
+
const input = '```js\nconst nested = `outer ${`inner`} text`\n```'
|
|
91
|
+
const result = escapeBackticksInCodeBlocks(input)
|
|
92
|
+
|
|
93
|
+
expect(result).toMatchInlineSnapshot(`
|
|
94
|
+
"\`\`\`js
|
|
95
|
+
const nested = \\\`outer \${\\\`inner\\\`} text\\\`
|
|
96
|
+
\`\`\`
|
|
97
|
+
"
|
|
98
|
+
`)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('preserves markdown outside code blocks', () => {
|
|
102
|
+
const input = `# Heading
|
|
103
|
+
|
|
104
|
+
This is **bold** and *italic* text
|
|
105
|
+
|
|
106
|
+
\`\`\`js
|
|
107
|
+
const code = \`with template\`
|
|
108
|
+
\`\`\`
|
|
109
|
+
|
|
110
|
+
- List item 1
|
|
111
|
+
- List item 2`
|
|
112
|
+
|
|
113
|
+
const result = escapeBackticksInCodeBlocks(input)
|
|
114
|
+
|
|
115
|
+
expect(result).toMatchInlineSnapshot(`
|
|
116
|
+
"# Heading
|
|
117
|
+
|
|
118
|
+
This is **bold** and *italic* text
|
|
119
|
+
|
|
120
|
+
\`\`\`js
|
|
121
|
+
const code = \\\`with template\\\`
|
|
122
|
+
\`\`\`
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
- List item 1
|
|
126
|
+
- List item 2"
|
|
127
|
+
`)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('does not escape code block delimiter backticks', () => {
|
|
131
|
+
const input = '```js\nconst x = `hello`\n```'
|
|
132
|
+
const result = escapeBackticksInCodeBlocks(input)
|
|
133
|
+
|
|
134
|
+
expect(result.startsWith('```')).toBe(true)
|
|
135
|
+
expect(result.endsWith('```\n')).toBe(true)
|
|
136
|
+
expect(result).toContain('\\`hello\\`')
|
|
137
|
+
expect(result).not.toContain('\\`\\`\\`js')
|
|
138
|
+
expect(result).not.toContain('\\`\\`\\`\n')
|
|
139
|
+
|
|
140
|
+
expect(result).toMatchInlineSnapshot(`
|
|
141
|
+
"\`\`\`js
|
|
142
|
+
const x = \\\`hello\\\`
|
|
143
|
+
\`\`\`
|
|
144
|
+
"
|
|
145
|
+
`)
|
|
146
|
+
})
|
package/src/tools.ts
CHANGED
|
@@ -127,7 +127,7 @@ export async function getTools({
|
|
|
127
127
|
.optional()
|
|
128
128
|
.describe('Optional model to use for this session'),
|
|
129
129
|
}),
|
|
130
|
-
execute: async ({ message, title,
|
|
130
|
+
execute: async ({ message, title, }) => {
|
|
131
131
|
if (!message.trim()) {
|
|
132
132
|
throw new Error(`message must be a non empty string`)
|
|
133
133
|
}
|
|
@@ -149,6 +149,7 @@ export async function getTools({
|
|
|
149
149
|
path: { id: session.data.id },
|
|
150
150
|
body: {
|
|
151
151
|
parts: [{ type: 'text', text: message }],
|
|
152
|
+
// model,
|
|
152
153
|
},
|
|
153
154
|
})
|
|
154
155
|
.then(async (response) => {
|