@llmguard/opencode 0.0.0-stage → 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/MANUAL-TEST-G.md +167 -0
- package/README.md +334 -2
- package/RELEASE.md +122 -0
- package/bin/darwin-amd64/helper +0 -0
- package/bin/darwin-arm64/helper +0 -0
- package/bin/linux-amd64/helper +0 -0
- package/bin/linux-arm64/helper +0 -0
- package/bin/manifest.json +51 -0
- package/bin/windows-amd64/helper.exe +0 -0
- package/bin/windows-arm64/helper.exe +0 -0
- package/bridge/client.d.ts +55 -0
- package/bridge/client.js +425 -0
- package/bridge/framing.d.ts +19 -0
- package/bridge/framing.js +110 -0
- package/bridge/process.d.ts +38 -0
- package/bridge/process.js +378 -0
- package/bridge/protocol.d.ts +184 -0
- package/bridge/protocol.js +683 -0
- package/connection-catalog.d.ts +69 -0
- package/connection-catalog.js +287 -0
- package/connections-tui.d.ts +11 -0
- package/connections-tui.js +394 -0
- package/demasking.d.ts +2 -0
- package/demasking.js +445 -0
- package/gui-experimental.cjs +33 -0
- package/hook-trace.d.ts +2 -0
- package/hook-trace.js +35 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/licenses/Go-LICENSE +27 -0
- package/messages.d.ts +230 -0
- package/messages.js +231 -0
- package/native/index.d.ts +1 -0
- package/native/index.js +1 -0
- package/native/tui.d.ts +1 -0
- package/native/tui.js +1 -0
- package/package.json +49 -4
- package/plugin-runtime.d.ts +3 -0
- package/plugin-runtime.js +3 -0
- package/plugin-settings.d.ts +77 -0
- package/plugin-settings.js +487 -0
- package/plugin.d.ts +41 -0
- package/plugin.js +10 -0
- package/response-diagnostics.d.ts +13 -0
- package/response-diagnostics.js +142 -0
- package/runtime/attachments.d.ts +4 -0
- package/runtime/attachments.js +19 -0
- package/runtime/errors.d.ts +18 -0
- package/runtime/errors.js +26 -0
- package/runtime/json.d.ts +14 -0
- package/runtime/json.js +243 -0
- package/runtime/limits.d.ts +2 -0
- package/runtime/limits.js +3 -0
- package/runtime/native-edit.d.ts +14 -0
- package/runtime/native-edit.js +73 -0
- package/runtime/runtime.d.ts +43 -0
- package/runtime/runtime.js +345 -0
- package/runtime/session-state.d.ts +13 -0
- package/runtime/session-state.js +73 -0
- package/runtime/text-layout.d.ts +9 -0
- package/runtime/text-layout.js +47 -0
- package/server.d.ts +1 -0
- package/server.js +1 -0
- package/settings-rpc.d.ts +511 -0
- package/settings-rpc.js +197 -0
- package/tui-messages.d.ts +1 -0
- package/tui-messages.js +84 -0
- package/tui.d.ts +17 -0
- package/tui.js +427 -0
- package/v1/hooks.d.ts +81 -0
- package/v1/hooks.js +97 -0
- package/v1/projection.d.ts +32 -0
- package/v1/projection.js +217 -0
- package/v1.d.ts +2 -0
- package/v1.js +2 -0
- package/v2/projection.d.ts +36 -0
- package/v2/projection.js +374 -0
- package/v2/server.d.ts +6 -0
- package/v2/server.js +633 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OpenCodeGuardError } from "./errors.js";
|
|
2
|
+
import { maxAttachmentBytes, maxAttachments } from "../bridge/protocol.js";
|
|
3
|
+
// Decides whether the attachments of a request go to the helper. With inspection
|
|
4
|
+
// off it returns nothing and the request is handled as before. With it on, an
|
|
5
|
+
// attachment set too large to hand over is refused: it cannot be inspected, and
|
|
6
|
+
// sending it unchecked is not an option.
|
|
7
|
+
export async function attachmentsForCheck(runtime, attachments, deadline) {
|
|
8
|
+
if (!(await runtime.inspectsAttachments(deadline))) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
let bytes = 0;
|
|
12
|
+
for (const item of attachments) {
|
|
13
|
+
bytes += item.data_b64 ? (item.data_b64.length / 4) * 3 : 0;
|
|
14
|
+
}
|
|
15
|
+
if (attachments.length > maxAttachments || bytes > maxAttachmentBytes) {
|
|
16
|
+
throw new OpenCodeGuardError("blocked", "LLMGuard: вложения в запросе слишком велики для проверки. Удалите часть вложений из диалога и повторите запрос.");
|
|
17
|
+
}
|
|
18
|
+
return attachments;
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type RecordValue = Record<string, unknown>;
|
|
2
|
+
declare const messages: {
|
|
3
|
+
readonly blocked: "LLMGuard: operation blocked or check unavailable";
|
|
4
|
+
readonly not_configured: "LLMGuard: защита включена, но подключение не готово. Задайте ключ Guard в /llmguard или настройках LLMGuard и проверьте связь.";
|
|
5
|
+
readonly configuration_pending: "LLMGuard: подключение обновляется. Повторите операцию после завершения настройки.";
|
|
6
|
+
readonly disposed: "LLMGuard: экземпляр плагина выгружен. Перезапустите OpenCode.";
|
|
7
|
+
readonly guard_denied: "LLMGuard: операция запрещена политикой Guard.";
|
|
8
|
+
readonly timeout: "LLMGuard: истекло время проверки Guard. Операция заблокирована.";
|
|
9
|
+
readonly unavailable: "LLMGuard: проверка Guard недоступна или ответ не прошёл проверку. Операция заблокирована.";
|
|
10
|
+
};
|
|
11
|
+
export type GuardErrorCode = keyof typeof messages;
|
|
12
|
+
export declare class OpenCodeGuardError extends Error {
|
|
13
|
+
readonly code: GuardErrorCode;
|
|
14
|
+
constructor(code?: GuardErrorCode, message?: string);
|
|
15
|
+
}
|
|
16
|
+
export declare const blocked: () => never;
|
|
17
|
+
export declare const object: (value: unknown) => RecordValue;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const messages = {
|
|
2
|
+
blocked: "LLMGuard: operation blocked or check unavailable",
|
|
3
|
+
not_configured: "LLMGuard: защита включена, но подключение не готово. Задайте ключ Guard в /llmguard или настройках LLMGuard и проверьте связь.",
|
|
4
|
+
configuration_pending: "LLMGuard: подключение обновляется. Повторите операцию после завершения настройки.",
|
|
5
|
+
disposed: "LLMGuard: экземпляр плагина выгружен. Перезапустите OpenCode.",
|
|
6
|
+
guard_denied: "LLMGuard: операция запрещена политикой Guard.",
|
|
7
|
+
timeout: "LLMGuard: истекло время проверки Guard. Операция заблокирована.",
|
|
8
|
+
unavailable: "LLMGuard: проверка Guard недоступна или ответ не прошёл проверку. Операция заблокирована.",
|
|
9
|
+
};
|
|
10
|
+
export class OpenCodeGuardError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
constructor(code = "blocked", message) {
|
|
13
|
+
super(message ?? messages[code]);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.name = "OpenCodeGuardError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const blocked = () => {
|
|
19
|
+
throw new OpenCodeGuardError();
|
|
20
|
+
};
|
|
21
|
+
export const object = (value) => {
|
|
22
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
23
|
+
return blocked();
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class JSONCodecError extends Error {
|
|
2
|
+
readonly code: "invalid_json" | "invalid_number" | "depth_exceeded" | "too_large";
|
|
3
|
+
constructor(code: "invalid_json" | "invalid_number" | "depth_exceeded" | "too_large");
|
|
4
|
+
}
|
|
5
|
+
export declare class NumberToken {
|
|
6
|
+
readonly token: string;
|
|
7
|
+
constructor(token: string);
|
|
8
|
+
toJSON(): unknown;
|
|
9
|
+
}
|
|
10
|
+
export type JsonValue = null | boolean | number | NumberToken | string | JsonValue[] | {
|
|
11
|
+
[key: string]: JsonValue;
|
|
12
|
+
};
|
|
13
|
+
export declare function parseLossless(data: Uint8Array): unknown;
|
|
14
|
+
export declare const encodeLossless: (value: unknown) => Uint8Array;
|
package/runtime/json.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { maxJSONDepth, maxResponseBytes } from "./limits.js";
|
|
2
|
+
// Generic JSON syntax/number mechanics only: no Agent Event or Guard validation.
|
|
3
|
+
export class JSONCodecError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code) {
|
|
6
|
+
super(`json: ${code}`);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class NumberToken {
|
|
11
|
+
token;
|
|
12
|
+
constructor(token) {
|
|
13
|
+
this.token = token;
|
|
14
|
+
}
|
|
15
|
+
toJSON() {
|
|
16
|
+
return JSON.rawJSON(this.token);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const encoder = new TextEncoder();
|
|
20
|
+
const fail = () => {
|
|
21
|
+
throw new JSONCodecError("invalid_json");
|
|
22
|
+
};
|
|
23
|
+
const matches = (value, pattern) => typeof value === "string" && pattern.exec(value)?.[0] === value;
|
|
24
|
+
const object = (v) => {
|
|
25
|
+
if (!v ||
|
|
26
|
+
typeof v !== "object" ||
|
|
27
|
+
Array.isArray(v) ||
|
|
28
|
+
v instanceof NumberToken) {
|
|
29
|
+
return fail();
|
|
30
|
+
}
|
|
31
|
+
return v;
|
|
32
|
+
};
|
|
33
|
+
function invalid() {
|
|
34
|
+
throw new JSONCodecError("invalid_json");
|
|
35
|
+
}
|
|
36
|
+
function numeric(raw) {
|
|
37
|
+
const pieces = raw.toLowerCase().split("e");
|
|
38
|
+
const exponent = Number(pieces[1] ?? 0);
|
|
39
|
+
if (raw.length > 128 ||
|
|
40
|
+
!Number.isFinite(exponent) ||
|
|
41
|
+
Math.abs(exponent) > 308) {
|
|
42
|
+
throw new JSONCodecError("invalid_number");
|
|
43
|
+
}
|
|
44
|
+
const mantissa = pieces[0].replace(/^-/, "");
|
|
45
|
+
const fraction = mantissa.split(".")[1]?.length ?? 0;
|
|
46
|
+
let numerator = BigInt(mantissa.replace(".", ""));
|
|
47
|
+
let maximum = 9007199254740991n;
|
|
48
|
+
const shift = exponent - fraction;
|
|
49
|
+
if (shift >= 0) {
|
|
50
|
+
numerator *= 10n ** BigInt(shift);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
maximum *= 10n ** BigInt(-shift);
|
|
54
|
+
}
|
|
55
|
+
if (numerator > maximum) {
|
|
56
|
+
throw new JSONCodecError("invalid_number");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Validate the original wire text before JSON.parse can discard duplicate keys
|
|
60
|
+
// or round unsafe numbers. The scanner does not interpret event data.
|
|
61
|
+
function parseStrict(data) {
|
|
62
|
+
if (data.byteLength > maxResponseBytes) {
|
|
63
|
+
throw new JSONCodecError("too_large");
|
|
64
|
+
}
|
|
65
|
+
let source;
|
|
66
|
+
try {
|
|
67
|
+
source = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(data);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return invalid();
|
|
71
|
+
}
|
|
72
|
+
let i = 0;
|
|
73
|
+
const whitespace = () => {
|
|
74
|
+
while (i < source.length && /[ \t\r\n]/.test(source[i])) {
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const string = () => {
|
|
79
|
+
if (source[i] !== '"') {
|
|
80
|
+
return invalid();
|
|
81
|
+
}
|
|
82
|
+
const start = i++;
|
|
83
|
+
while (i < source.length) {
|
|
84
|
+
const char = source[i++];
|
|
85
|
+
if (char === "\\") {
|
|
86
|
+
i++;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (char === '"') {
|
|
90
|
+
let value;
|
|
91
|
+
try {
|
|
92
|
+
value = JSON.parse(source.slice(start, i));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return invalid();
|
|
96
|
+
}
|
|
97
|
+
for (let pos = 0; pos < value.length; pos++) {
|
|
98
|
+
const unit = value.charCodeAt(pos);
|
|
99
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
100
|
+
const next = value.charCodeAt(++pos);
|
|
101
|
+
if (!(next >= 0xdc00 && next <= 0xdfff)) {
|
|
102
|
+
return invalid();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (unit >= 0xdc00 && unit <= 0xdfff) {
|
|
106
|
+
return invalid();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return invalid();
|
|
113
|
+
};
|
|
114
|
+
const value = (depth) => {
|
|
115
|
+
whitespace();
|
|
116
|
+
const char = source[i];
|
|
117
|
+
if (char === "{" || char === "[") {
|
|
118
|
+
if (depth + 1 > maxJSONDepth) {
|
|
119
|
+
throw new JSONCodecError("depth_exceeded");
|
|
120
|
+
}
|
|
121
|
+
i++;
|
|
122
|
+
const end = char === "{" ? "}" : "]";
|
|
123
|
+
const keys = new Set();
|
|
124
|
+
whitespace();
|
|
125
|
+
if (source[i] === end) {
|
|
126
|
+
i++;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
while (i < source.length) {
|
|
130
|
+
if (char === "{") {
|
|
131
|
+
whitespace();
|
|
132
|
+
const key = string();
|
|
133
|
+
if (keys.has(key)) {
|
|
134
|
+
return invalid();
|
|
135
|
+
}
|
|
136
|
+
keys.add(key);
|
|
137
|
+
whitespace();
|
|
138
|
+
if (source[i++] !== ":") {
|
|
139
|
+
return invalid();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
value(depth + 1);
|
|
143
|
+
whitespace();
|
|
144
|
+
if (source[i] === end) {
|
|
145
|
+
i++;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (source[i++] !== ",") {
|
|
149
|
+
return invalid();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return invalid();
|
|
153
|
+
}
|
|
154
|
+
if (char === '"') {
|
|
155
|
+
string();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
for (const literal of ["true", "false", "null"]) {
|
|
159
|
+
if (source.startsWith(literal, i)) {
|
|
160
|
+
i += literal.length;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const number = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(source.slice(i));
|
|
165
|
+
if (!number) {
|
|
166
|
+
return invalid();
|
|
167
|
+
}
|
|
168
|
+
numeric(number[0]);
|
|
169
|
+
i += number[0].length;
|
|
170
|
+
};
|
|
171
|
+
value(0);
|
|
172
|
+
whitespace();
|
|
173
|
+
if (i !== source.length) {
|
|
174
|
+
return invalid();
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
return JSON.parse(source);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return invalid();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
export function parseLossless(data) {
|
|
184
|
+
parseStrict(data);
|
|
185
|
+
const text = new TextDecoder("utf-8", {
|
|
186
|
+
fatal: true,
|
|
187
|
+
ignoreBOM: true,
|
|
188
|
+
}).decode(data);
|
|
189
|
+
const reviver = (_key, value, context) => typeof value === "number"
|
|
190
|
+
? new NumberToken(context.source ?? fail())
|
|
191
|
+
: value;
|
|
192
|
+
// Node 24's reviver source preserves the original token even if its temporary
|
|
193
|
+
// numeric value was rounded. parseStrict already validated its exact range.
|
|
194
|
+
return JSON.parse(text, reviver);
|
|
195
|
+
}
|
|
196
|
+
function canonical(value, depth = 0) {
|
|
197
|
+
if (value instanceof NumberToken) {
|
|
198
|
+
if (!matches(value.token, /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/) ||
|
|
199
|
+
typeof parseStrict(encoder.encode(value.token)) !== "number") {
|
|
200
|
+
return fail();
|
|
201
|
+
}
|
|
202
|
+
return value.token;
|
|
203
|
+
}
|
|
204
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
205
|
+
return canonical(new NumberToken(JSON.stringify(value)));
|
|
206
|
+
}
|
|
207
|
+
if (value === null || typeof value === "boolean") {
|
|
208
|
+
return String(value);
|
|
209
|
+
}
|
|
210
|
+
if (typeof value === "string") {
|
|
211
|
+
for (const scalar of value) {
|
|
212
|
+
const n = scalar.charCodeAt(0);
|
|
213
|
+
if (scalar.length === 1 && n >= 0xd800 && n <= 0xdfff) {
|
|
214
|
+
return fail();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return ('"' +
|
|
218
|
+
// Control characters must use canonical lowercase escapes.
|
|
219
|
+
// eslint-disable-next-line no-control-regex
|
|
220
|
+
value.replace(/["\\\u0000-\u001f]/g, (c) => c === '"' || c === "\\"
|
|
221
|
+
? "\\" + c
|
|
222
|
+
: "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0")) +
|
|
223
|
+
'"');
|
|
224
|
+
}
|
|
225
|
+
if (depth + 1 > maxJSONDepth) {
|
|
226
|
+
throw new JSONCodecError("depth_exceeded");
|
|
227
|
+
}
|
|
228
|
+
if (Array.isArray(value)) {
|
|
229
|
+
return ("[" + value.map((child) => canonical(child, depth + 1)).join(",") + "]");
|
|
230
|
+
}
|
|
231
|
+
const v = object(value);
|
|
232
|
+
const keys = Object.keys(v).sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)));
|
|
233
|
+
return ("{" +
|
|
234
|
+
keys.map((k) => canonical(k) + ":" + canonical(v[k], depth + 1)).join(",") +
|
|
235
|
+
"}");
|
|
236
|
+
}
|
|
237
|
+
export const encodeLossless = (value) => {
|
|
238
|
+
const bytes = encoder.encode(canonical(value));
|
|
239
|
+
if (bytes.byteLength > maxResponseBytes) {
|
|
240
|
+
throw new JSONCodecError("too_large");
|
|
241
|
+
}
|
|
242
|
+
return bytes;
|
|
243
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RecordValue } from "./errors.js";
|
|
2
|
+
export type NativeEdit = {
|
|
3
|
+
target: object;
|
|
4
|
+
key: string;
|
|
5
|
+
value: unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare function applyNativeEdits(edits: NativeEdit[]): void;
|
|
8
|
+
export declare function snapshotObject(root: unknown): () => boolean;
|
|
9
|
+
export declare function applyTextEdits(edits: {
|
|
10
|
+
target: RecordValue;
|
|
11
|
+
key: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[]): void;
|
|
14
|
+
export declare function applyArgumentStrings(target: RecordValue, candidate: RecordValue): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { blocked } from "./errors.js";
|
|
2
|
+
import { NumberToken } from "./json.js";
|
|
3
|
+
// Validate the complete commit, including attachment and system-array writes,
|
|
4
|
+
// before changing any SDK data record. Accessors cannot be safe destinations.
|
|
5
|
+
export function applyNativeEdits(edits) {
|
|
6
|
+
for (const edit of edits) {
|
|
7
|
+
const descriptor = Object.getOwnPropertyDescriptor(edit.target, edit.key);
|
|
8
|
+
if (!descriptor || !("value" in descriptor) || !descriptor.writable) {
|
|
9
|
+
blocked();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
for (const edit of edits) {
|
|
13
|
+
edit.target[edit.key] = edit.value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Native object identity/values stay bound while Go checks a serialized clone.
|
|
17
|
+
// This traverses tool arguments, never attachment URLs or unselected messages.
|
|
18
|
+
export function snapshotObject(root) {
|
|
19
|
+
const checks = [];
|
|
20
|
+
const visit = (node, depth = 0) => {
|
|
21
|
+
if (depth > 32) {
|
|
22
|
+
blocked();
|
|
23
|
+
}
|
|
24
|
+
if (!node || typeof node !== "object" || node instanceof NumberToken) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const target = node;
|
|
28
|
+
const keys = Object.keys(target);
|
|
29
|
+
const values = keys.map((key) => target[key]);
|
|
30
|
+
checks.push(() => Object.keys(target).join("\0") === keys.join("\0") &&
|
|
31
|
+
keys.every((key, i) => Object.is(target[key], values[i])));
|
|
32
|
+
values.forEach((value) => visit(value, depth + 1));
|
|
33
|
+
};
|
|
34
|
+
visit(root);
|
|
35
|
+
return () => checks.every((check) => check());
|
|
36
|
+
}
|
|
37
|
+
export function applyTextEdits(edits) {
|
|
38
|
+
// Preflight every destination before touching the first string. SDK payloads
|
|
39
|
+
// are data records; getters/setters and read-only slots are not safe commits.
|
|
40
|
+
for (const edit of edits) {
|
|
41
|
+
const descriptor = Object.getOwnPropertyDescriptor(edit.target, edit.key);
|
|
42
|
+
if (!descriptor ||
|
|
43
|
+
!("value" in descriptor) ||
|
|
44
|
+
!descriptor.writable ||
|
|
45
|
+
typeof descriptor.value !== "string") {
|
|
46
|
+
blocked();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
applyNativeEdits(edits);
|
|
50
|
+
}
|
|
51
|
+
export function applyArgumentStrings(target, candidate) {
|
|
52
|
+
const edits = [];
|
|
53
|
+
const visit = (node, next) => {
|
|
54
|
+
if (!next || typeof next !== "object") {
|
|
55
|
+
blocked();
|
|
56
|
+
}
|
|
57
|
+
for (const [key, value] of Object.entries(node)) {
|
|
58
|
+
if (typeof value === "string") {
|
|
59
|
+
if (typeof next[key] !== "string") {
|
|
60
|
+
blocked();
|
|
61
|
+
}
|
|
62
|
+
edits.push({ target: node, key, value: next[key] });
|
|
63
|
+
}
|
|
64
|
+
else if (value &&
|
|
65
|
+
typeof value === "object" &&
|
|
66
|
+
!(value instanceof NumberToken)) {
|
|
67
|
+
visit(value, next[key]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
visit(target, candidate);
|
|
72
|
+
applyTextEdits(edits);
|
|
73
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BridgeClient } from "../bridge/client.js";
|
|
2
|
+
import type { AttachmentParam, AttachmentReplacement } from "../bridge/protocol.js";
|
|
3
|
+
import type { JsonValue } from "./json.js";
|
|
4
|
+
import { type RecordValue } from "./errors.js";
|
|
5
|
+
export interface PluginOptions {
|
|
6
|
+
baseURL: string;
|
|
7
|
+
projectSID: string;
|
|
8
|
+
token: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
allowLoopbackHTTP?: boolean;
|
|
11
|
+
cwd?: string;
|
|
12
|
+
}
|
|
13
|
+
export type ToolInput = {
|
|
14
|
+
sessionID: string;
|
|
15
|
+
callID: string;
|
|
16
|
+
tool: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const DEFAULT_GUARD_TIMEOUT_MS = 10000;
|
|
19
|
+
export declare function createOpenCodeRuntime(options: PluginOptions, supplied?: BridgeClient, shared?: {
|
|
20
|
+
configured: Promise<unknown>;
|
|
21
|
+
}): {
|
|
22
|
+
deadline: (started?: number) => number;
|
|
23
|
+
checkModelTexts: (name: string, texts: string[], session: string | null, sourcePayload?: Record<string, JsonValue>, commit?: (texts: string[], replacements: AttachmentReplacement[]) => void, deadline?: number, attachments?: AttachmentParam[]) => Promise<string[]>;
|
|
24
|
+
inspectsAttachments(deadline: number): Promise<boolean>;
|
|
25
|
+
routeStatus(session: string): Promise<{
|
|
26
|
+
local: boolean;
|
|
27
|
+
gateway_required: boolean;
|
|
28
|
+
}>;
|
|
29
|
+
checkProviderRequest(session: string, path: string, body: Uint8Array, deadline: number): Promise<{
|
|
30
|
+
routeLease?: string;
|
|
31
|
+
leaseAction?: (action: "renew" | "release") => Promise<number>;
|
|
32
|
+
local: boolean | undefined;
|
|
33
|
+
body: Buffer<ArrayBuffer>;
|
|
34
|
+
}>;
|
|
35
|
+
checkToolArguments: (input: ToolInput, argsValue: unknown, commit?: (candidate: RecordValue) => void, deadline?: number, profile?: "v1.tool.before" | "v2.tool.before") => Promise<RecordValue>;
|
|
36
|
+
checkToolTexts(input: ToolInput, texts: string[], commit: (texts: string[]) => void, deadline?: number): Promise<string[]>;
|
|
37
|
+
hasRestoration: (session: string) => boolean;
|
|
38
|
+
restoreText: (session: string, text: string) => string;
|
|
39
|
+
observeToolAfter(tool: ToolInput, output: string): Promise<void>;
|
|
40
|
+
demaskResponse(session: string | null, response: Response, trace?: (reason: string) => void): Promise<Response>;
|
|
41
|
+
forgetSession: (session: string) => Promise<void>;
|
|
42
|
+
dispose(): Promise<void>;
|
|
43
|
+
};
|