@tencent-ai/agent-sdk 0.3.206 → 0.3.210
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/cli/CHANGELOG.md +61 -0
- package/cli/builtin/workflows/deep-research.workflow.js +77 -20
- package/cli/dist/codebuddy-headless.js +294 -246
- package/cli/dist/web-ui/assets/index-CH6e4vvI.css +32 -0
- package/cli/dist/web-ui/assets/index-GcU4pZms.js +1102 -0
- package/cli/dist/web-ui/index.html +2 -2
- package/cli/dist/web-ui/sw.js +1 -1
- package/cli/package.json +4 -4
- package/cli/product.cloudhosted.json +2 -2
- package/cli/product.internal.json +2 -2
- package/cli/product.ioa.json +2 -2
- package/cli/product.json +3 -3
- package/cli/product.selfhosted.json +2 -2
- package/cli/vendor/native-builds.json +18 -0
- package/cli/vendor/shim/broker-ipc-client.cjs +158 -0
- package/cli/vendor/shim/brokered-bin/codebuddy-toybox-dispatch +381 -0
- package/cli/vendor/shim/brokered-sandbox-bash-env.sh +10 -0
- package/cli/vendor/shim/genie-safe-delete.cjs +4 -781
- package/cli/vendor/shim/native/binding.gyp +13 -0
- package/cli/vendor/shim/native/brokered_sandbox_native.c +293 -0
- package/cli/vendor/shim/native/darwin-arm64/brokered-sandbox-native.node +0 -0
- package/cli/vendor/shim/native/darwin-x64/brokered-sandbox-native.node +0 -0
- package/cli/vendor/shim/node-brokered-fs-shim.cjs +932 -0
- package/cli/vendor/shim/node-language-shim.cjs +35 -0
- package/cli/vendor/shim/node-safe-delete-shim.cjs +810 -0
- package/cli/vendor/shim/safe-bin/safe-delete-bash-env.sh +1 -1
- package/cli/vendor/shim/safe-bin/safe-delete-common.sh +95 -34
- package/cli/vendor/shim/safe-delete-broker-delete.cjs +166 -0
- package/cli/vendor/shim/shell-runtime-bash-env.sh +8 -0
- package/cli/vendor/shim/sitecustomize.py +551 -22
- package/cli/vendor/toybox-macos/LICENSE +12 -0
- package/cli/vendor/toybox-macos/toybox +0 -0
- package/cli/vendor/toybox-macos/toybox.sb +19 -0
- package/cli/vendor/zsh-macos/LICENSE +37 -0
- package/cli/vendor/zsh-macos/bin/zsh +0 -0
- package/package.json +1 -1
- package/cli/dist/web-ui/assets/index-BZjhFKbY.js +0 -1051
- package/cli/dist/web-ui/assets/index-C5EhSt3C.css +0 -32
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
#include <node_api.h>
|
|
2
|
+
|
|
3
|
+
#include <errno.h>
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <string.h>
|
|
8
|
+
|
|
9
|
+
#if defined(__APPLE__)
|
|
10
|
+
#include <dlfcn.h>
|
|
11
|
+
#include <sys/socket.h>
|
|
12
|
+
#include <sys/time.h>
|
|
13
|
+
#include <sys/un.h>
|
|
14
|
+
#include <unistd.h>
|
|
15
|
+
#endif
|
|
16
|
+
|
|
17
|
+
#define BROKER_RESPONSE_MAX_BYTES (1024 * 1024)
|
|
18
|
+
|
|
19
|
+
static napi_value throw_error(napi_env env, const char *message) {
|
|
20
|
+
napi_throw_error(env, NULL, message);
|
|
21
|
+
return NULL;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static char *read_string_arg(napi_env env, napi_value value, const char *name) {
|
|
25
|
+
size_t length = 0;
|
|
26
|
+
napi_status status = napi_get_value_string_utf8(env, value, NULL, 0, &length);
|
|
27
|
+
if (status != napi_ok) {
|
|
28
|
+
char message[128];
|
|
29
|
+
snprintf(message, sizeof(message), "%s must be a string", name);
|
|
30
|
+
napi_throw_type_error(env, NULL, message);
|
|
31
|
+
return NULL;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
char *buffer = (char *)malloc(length + 1);
|
|
35
|
+
if (!buffer) {
|
|
36
|
+
napi_throw_error(env, NULL, "Out of memory");
|
|
37
|
+
return NULL;
|
|
38
|
+
}
|
|
39
|
+
status = napi_get_value_string_utf8(env, value, buffer, length + 1, &length);
|
|
40
|
+
if (status != napi_ok) {
|
|
41
|
+
free(buffer);
|
|
42
|
+
char message[128];
|
|
43
|
+
snprintf(message, sizeof(message), "Failed to read %s", name);
|
|
44
|
+
napi_throw_error(env, NULL, message);
|
|
45
|
+
return NULL;
|
|
46
|
+
}
|
|
47
|
+
return buffer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static uint32_t read_timeout_arg(napi_env env, napi_value value) {
|
|
51
|
+
uint32_t timeout_ms = 5000;
|
|
52
|
+
if (value) {
|
|
53
|
+
napi_get_value_uint32(env, value, &timeout_ms);
|
|
54
|
+
}
|
|
55
|
+
if (timeout_ms == 0) {
|
|
56
|
+
timeout_ms = 5000;
|
|
57
|
+
}
|
|
58
|
+
return timeout_ms;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#if defined(__APPLE__)
|
|
62
|
+
typedef int64_t (*sandbox_extension_consume_fn)(const char *);
|
|
63
|
+
|
|
64
|
+
static sandbox_extension_consume_fn get_sandbox_extension_consume(void) {
|
|
65
|
+
static sandbox_extension_consume_fn fn = NULL;
|
|
66
|
+
static int loaded = 0;
|
|
67
|
+
if (loaded) {
|
|
68
|
+
return fn;
|
|
69
|
+
}
|
|
70
|
+
loaded = 1;
|
|
71
|
+
|
|
72
|
+
fn = (sandbox_extension_consume_fn)dlsym(RTLD_DEFAULT, "sandbox_extension_consume");
|
|
73
|
+
if (fn) {
|
|
74
|
+
return fn;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
void *handle = dlopen("/usr/lib/libsandbox.dylib", RTLD_LAZY);
|
|
78
|
+
if (!handle) {
|
|
79
|
+
return NULL;
|
|
80
|
+
}
|
|
81
|
+
fn = (sandbox_extension_consume_fn)dlsym(handle, "sandbox_extension_consume");
|
|
82
|
+
return fn;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static int set_socket_timeout(int fd, uint32_t timeout_ms) {
|
|
86
|
+
struct timeval tv;
|
|
87
|
+
tv.tv_sec = timeout_ms / 1000;
|
|
88
|
+
tv.tv_usec = (timeout_ms % 1000) * 1000;
|
|
89
|
+
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) != 0) {
|
|
90
|
+
return -1;
|
|
91
|
+
}
|
|
92
|
+
if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) != 0) {
|
|
93
|
+
return -1;
|
|
94
|
+
}
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static int write_all(int fd, const char *buffer, size_t length) {
|
|
99
|
+
size_t offset = 0;
|
|
100
|
+
while (offset < length) {
|
|
101
|
+
ssize_t written = write(fd, buffer + offset, length - offset);
|
|
102
|
+
if (written < 0) {
|
|
103
|
+
if (errno == EINTR) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
return -1;
|
|
107
|
+
}
|
|
108
|
+
if (written == 0) {
|
|
109
|
+
errno = EPIPE;
|
|
110
|
+
return -1;
|
|
111
|
+
}
|
|
112
|
+
offset += (size_t)written;
|
|
113
|
+
}
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static char *request_broker_sync(const char *socket_path, const char *line, uint32_t timeout_ms, char *error, size_t error_size) {
|
|
118
|
+
int fd = -1;
|
|
119
|
+
char *response = NULL;
|
|
120
|
+
size_t length = 0;
|
|
121
|
+
size_t capacity = 4096;
|
|
122
|
+
|
|
123
|
+
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
124
|
+
if (fd < 0) {
|
|
125
|
+
snprintf(error, error_size, "socket failed: %s", strerror(errno));
|
|
126
|
+
return NULL;
|
|
127
|
+
}
|
|
128
|
+
if (set_socket_timeout(fd, timeout_ms) != 0) {
|
|
129
|
+
snprintf(error, error_size, "setsockopt timeout failed: %s", strerror(errno));
|
|
130
|
+
close(fd);
|
|
131
|
+
return NULL;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
struct sockaddr_un addr;
|
|
135
|
+
memset(&addr, 0, sizeof(addr));
|
|
136
|
+
addr.sun_family = AF_UNIX;
|
|
137
|
+
if (strlen(socket_path) >= sizeof(addr.sun_path)) {
|
|
138
|
+
snprintf(error, error_size, "broker socket path is too long");
|
|
139
|
+
close(fd);
|
|
140
|
+
return NULL;
|
|
141
|
+
}
|
|
142
|
+
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
|
|
143
|
+
|
|
144
|
+
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
|
|
145
|
+
snprintf(error, error_size, "connect failed: %s", strerror(errno));
|
|
146
|
+
close(fd);
|
|
147
|
+
return NULL;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (write_all(fd, line, strlen(line)) != 0 || write_all(fd, "\n", 1) != 0) {
|
|
151
|
+
snprintf(error, error_size, "write failed: %s", strerror(errno));
|
|
152
|
+
close(fd);
|
|
153
|
+
return NULL;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
response = (char *)malloc(capacity);
|
|
157
|
+
if (!response) {
|
|
158
|
+
snprintf(error, error_size, "out of memory");
|
|
159
|
+
close(fd);
|
|
160
|
+
return NULL;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
while (length + 1 < BROKER_RESPONSE_MAX_BYTES) {
|
|
164
|
+
char chunk[1024];
|
|
165
|
+
ssize_t count = read(fd, chunk, sizeof(chunk));
|
|
166
|
+
if (count < 0) {
|
|
167
|
+
if (errno == EINTR) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
snprintf(error, error_size, "read failed: %s", strerror(errno));
|
|
171
|
+
free(response);
|
|
172
|
+
close(fd);
|
|
173
|
+
return NULL;
|
|
174
|
+
}
|
|
175
|
+
if (count == 0) {
|
|
176
|
+
snprintf(error, error_size, "broker closed without a response");
|
|
177
|
+
free(response);
|
|
178
|
+
close(fd);
|
|
179
|
+
return NULL;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
for (ssize_t i = 0; i < count; i++) {
|
|
183
|
+
if (chunk[i] == '\n') {
|
|
184
|
+
response[length] = '\0';
|
|
185
|
+
close(fd);
|
|
186
|
+
return response;
|
|
187
|
+
}
|
|
188
|
+
if (length + 1 >= capacity) {
|
|
189
|
+
size_t next_capacity = capacity * 2;
|
|
190
|
+
if (next_capacity > BROKER_RESPONSE_MAX_BYTES) {
|
|
191
|
+
next_capacity = BROKER_RESPONSE_MAX_BYTES;
|
|
192
|
+
}
|
|
193
|
+
char *next = (char *)realloc(response, next_capacity);
|
|
194
|
+
if (!next) {
|
|
195
|
+
snprintf(error, error_size, "out of memory");
|
|
196
|
+
free(response);
|
|
197
|
+
close(fd);
|
|
198
|
+
return NULL;
|
|
199
|
+
}
|
|
200
|
+
response = next;
|
|
201
|
+
capacity = next_capacity;
|
|
202
|
+
}
|
|
203
|
+
response[length++] = chunk[i];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
snprintf(error, error_size, "broker response exceeds limit");
|
|
208
|
+
free(response);
|
|
209
|
+
close(fd);
|
|
210
|
+
return NULL;
|
|
211
|
+
}
|
|
212
|
+
#endif
|
|
213
|
+
|
|
214
|
+
static napi_value ConsumeSandboxExtension(napi_env env, napi_callback_info info) {
|
|
215
|
+
#if defined(__APPLE__)
|
|
216
|
+
size_t argc = 1;
|
|
217
|
+
napi_value argv[1];
|
|
218
|
+
napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
|
|
219
|
+
if (argc < 1) {
|
|
220
|
+
return throw_error(env, "consumeSandboxExtension requires a token");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
char *token = read_string_arg(env, argv[0], "token");
|
|
224
|
+
if (!token) {
|
|
225
|
+
return NULL;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
sandbox_extension_consume_fn consume = get_sandbox_extension_consume();
|
|
229
|
+
if (!consume) {
|
|
230
|
+
free(token);
|
|
231
|
+
return throw_error(env, "sandbox_extension_consume is unavailable");
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
int64_t handle = consume(token);
|
|
235
|
+
free(token);
|
|
236
|
+
napi_value result;
|
|
237
|
+
napi_create_int64(env, handle, &result);
|
|
238
|
+
return result;
|
|
239
|
+
#else
|
|
240
|
+
(void)info;
|
|
241
|
+
return throw_error(env, "sandbox_extension_consume is only available on macOS");
|
|
242
|
+
#endif
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
static napi_value RequestBrokerSync(napi_env env, napi_callback_info info) {
|
|
246
|
+
#if defined(__APPLE__)
|
|
247
|
+
size_t argc = 3;
|
|
248
|
+
napi_value argv[3];
|
|
249
|
+
napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
|
|
250
|
+
if (argc < 2) {
|
|
251
|
+
return throw_error(env, "requestBrokerSync requires socketPath and line");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
char *socket_path = read_string_arg(env, argv[0], "socketPath");
|
|
255
|
+
if (!socket_path) {
|
|
256
|
+
return NULL;
|
|
257
|
+
}
|
|
258
|
+
char *line = read_string_arg(env, argv[1], "line");
|
|
259
|
+
if (!line) {
|
|
260
|
+
free(socket_path);
|
|
261
|
+
return NULL;
|
|
262
|
+
}
|
|
263
|
+
uint32_t timeout_ms = argc >= 3 ? read_timeout_arg(env, argv[2]) : 5000;
|
|
264
|
+
|
|
265
|
+
char error[512];
|
|
266
|
+
error[0] = '\0';
|
|
267
|
+
char *response = request_broker_sync(socket_path, line, timeout_ms, error, sizeof(error));
|
|
268
|
+
free(socket_path);
|
|
269
|
+
free(line);
|
|
270
|
+
if (!response) {
|
|
271
|
+
return throw_error(env, error[0] ? error : "broker request failed");
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
napi_value result;
|
|
275
|
+
napi_create_string_utf8(env, response, NAPI_AUTO_LENGTH, &result);
|
|
276
|
+
free(response);
|
|
277
|
+
return result;
|
|
278
|
+
#else
|
|
279
|
+
(void)info;
|
|
280
|
+
return throw_error(env, "broker sync IPC is only available on macOS");
|
|
281
|
+
#endif
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static napi_value Init(napi_env env, napi_value exports) {
|
|
285
|
+
napi_property_descriptor descriptors[] = {
|
|
286
|
+
{ "consumeSandboxExtension", NULL, ConsumeSandboxExtension, NULL, NULL, NULL, napi_default, NULL },
|
|
287
|
+
{ "requestBrokerSync", NULL, RequestBrokerSync, NULL, NULL, NULL, napi_default, NULL },
|
|
288
|
+
};
|
|
289
|
+
napi_define_properties(env, exports, sizeof(descriptors) / sizeof(descriptors[0]), descriptors);
|
|
290
|
+
return exports;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
|
|
Binary file
|
|
Binary file
|