opencode-querit 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.
- package/LICENSE +21 -0
- package/README-zh.md +126 -0
- package/README.md +126 -0
- package/lib/client.d.ts +94 -0
- package/lib/client.js +265 -0
- package/lib/config.d.ts +95 -0
- package/lib/config.js +172 -0
- package/lib/format.d.ts +13 -0
- package/lib/format.js +96 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +200 -0
- package/lib/sanitize.d.ts +7 -0
- package/lib/sanitize.js +98 -0
- package/package.json +64 -0
package/lib/sanitize.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove terminal escape/control sequences from untrusted remote text.
|
|
3
|
+
* Newlines and tabs are preserved so page content remains readable.
|
|
4
|
+
* Ported from pi-querit / dsh-querit (MIT).
|
|
5
|
+
* @module opencode-querit/sanitize
|
|
6
|
+
*/
|
|
7
|
+
const ESC = 0x1b;
|
|
8
|
+
const BEL = 0x07;
|
|
9
|
+
const DELETE = 0x7f;
|
|
10
|
+
const CSI = 0x9b;
|
|
11
|
+
const ST = 0x9c;
|
|
12
|
+
const OSC = 0x9d;
|
|
13
|
+
const CONTROL_STRING_STARTS = new Set([0x90, 0x98, 0x9e, 0x9f]);
|
|
14
|
+
const ESC_CONTROL_STRING_STARTS = new Set([0x50, 0x58, 0x5e, 0x5f]);
|
|
15
|
+
const BIDI_CONTROLS = /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/gu;
|
|
16
|
+
export function sanitizeUntrustedText(value) {
|
|
17
|
+
let output = "";
|
|
18
|
+
for (let index = 0; index < value.length;) {
|
|
19
|
+
const code = value.charCodeAt(index);
|
|
20
|
+
if (code === ESC) {
|
|
21
|
+
const next = value.charCodeAt(index + 1);
|
|
22
|
+
if (next === 0x5b) {
|
|
23
|
+
index = skipCsi(value, index + 2);
|
|
24
|
+
}
|
|
25
|
+
else if (next === 0x5d) {
|
|
26
|
+
index = skipOsc(value, index + 2);
|
|
27
|
+
}
|
|
28
|
+
else if (ESC_CONTROL_STRING_STARTS.has(next)) {
|
|
29
|
+
index = skipControlString(value, index + 2);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
index += Number.isNaN(next) ? 1 : 2;
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (code === CSI) {
|
|
37
|
+
index = skipCsi(value, index + 1);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (code === OSC) {
|
|
41
|
+
index = skipOsc(value, index + 1);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (CONTROL_STRING_STARTS.has(code)) {
|
|
45
|
+
index = skipControlString(value, index + 1);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (code === 0x0a || code === 0x09) {
|
|
49
|
+
output += value[index];
|
|
50
|
+
index += 1;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (code < 0x20 || (code >= 0x80 && code <= 0x9f) || code === DELETE) {
|
|
54
|
+
index += 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const codePoint = value.codePointAt(index);
|
|
58
|
+
if (codePoint === undefined)
|
|
59
|
+
break;
|
|
60
|
+
output += String.fromCodePoint(codePoint);
|
|
61
|
+
index += codePoint > 0xffff ? 2 : 1;
|
|
62
|
+
}
|
|
63
|
+
return output.replace(BIDI_CONTROLS, "");
|
|
64
|
+
}
|
|
65
|
+
function skipCsi(value, start) {
|
|
66
|
+
let index = start;
|
|
67
|
+
while (index < value.length) {
|
|
68
|
+
const code = value.charCodeAt(index);
|
|
69
|
+
index += 1;
|
|
70
|
+
if (code >= 0x40 && code <= 0x7e)
|
|
71
|
+
return index;
|
|
72
|
+
}
|
|
73
|
+
return index;
|
|
74
|
+
}
|
|
75
|
+
function skipOsc(value, start) {
|
|
76
|
+
let index = start;
|
|
77
|
+
while (index < value.length) {
|
|
78
|
+
const code = value.charCodeAt(index);
|
|
79
|
+
if (code === BEL || code === ST)
|
|
80
|
+
return index + 1;
|
|
81
|
+
if (code === ESC && value.charCodeAt(index + 1) === 0x5c)
|
|
82
|
+
return index + 2;
|
|
83
|
+
index += 1;
|
|
84
|
+
}
|
|
85
|
+
return index;
|
|
86
|
+
}
|
|
87
|
+
function skipControlString(value, start) {
|
|
88
|
+
let index = start;
|
|
89
|
+
while (index < value.length) {
|
|
90
|
+
const code = value.charCodeAt(index);
|
|
91
|
+
if (code === ST)
|
|
92
|
+
return index + 1;
|
|
93
|
+
if (code === ESC && value.charCodeAt(index + 1) === 0x5c)
|
|
94
|
+
return index + 2;
|
|
95
|
+
index += 1;
|
|
96
|
+
}
|
|
97
|
+
return index;
|
|
98
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-querit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Querit web search and page retrieval tools (web_search / web_fetch) for OpenCode",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"README.md",
|
|
18
|
+
"README-zh.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "QUERIT PRIVATE LIMITED",
|
|
23
|
+
"homepage": "https://www.querit.ai",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/querit-ai/querit-plugins.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/querit-ai/querit-plugins/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"opencode",
|
|
33
|
+
"opencode-plugin",
|
|
34
|
+
"querit",
|
|
35
|
+
"web-search",
|
|
36
|
+
"web-fetch",
|
|
37
|
+
"ai",
|
|
38
|
+
"llm"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"check": "tsc -p tsconfig.check.json",
|
|
42
|
+
"build": "tsc -p tsconfig.json",
|
|
43
|
+
"test": "vitest run tests",
|
|
44
|
+
"test:live": "tsx scripts/live-smoke.ts",
|
|
45
|
+
"pack:check": "npm pack --dry-run",
|
|
46
|
+
"prepack": "npm run check && npm test && npm run build"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@opencode-ai/plugin": ">=0.15.0 <2"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@opencode-ai/plugin": "^1.18.18",
|
|
53
|
+
"@types/node": "^24.0.0",
|
|
54
|
+
"tsx": "^4.20.0",
|
|
55
|
+
"typescript": "^5.9.0",
|
|
56
|
+
"vitest": "^4.1.0"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=22.19.0"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
}
|
|
64
|
+
}
|