@quadient/skillshare 1.17.1 → 1.19.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/README.md +14 -8
- package/dist/agents-claude.js +135 -10
- package/dist/agents-codex.js +185 -14
- package/dist/agents-detect.js +96 -13
- package/dist/agents-form-worker.js +33 -0
- package/dist/agents-forms.js +79 -0
- package/dist/agents-process.js +12 -1
- package/dist/agents-request-upload.js +55 -0
- package/dist/agents-response-hash.js +31 -0
- package/dist/agents-service.js +17 -1
- package/dist/agents-session.js +160 -5
- package/dist/agents-settings.js +133 -0
- package/dist/agents.js +117 -23
- package/dist/cli-args.js +3 -0
- package/dist/help.js +43 -6
- package/dist/index.js +9 -0
- package/dist/news.js +409 -0
- package/dist/teams.js +2 -2
- package/package.json +4 -2
package/dist/agents-detect.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
2
|
+
import { readFile, mkdtemp, readdir, rm } from 'node:fs/promises';
|
|
3
|
+
import { homedir, tmpdir } from 'node:os';
|
|
4
4
|
import { basename, isAbsolute, join, resolve } from 'node:path';
|
|
5
5
|
import { startAgentProcess } from './agents-process.js';
|
|
6
|
+
import { loadAgentSettings, migrateAgentSettings } from './agents-settings.js';
|
|
7
|
+
import crossSpawn from 'cross-spawn';
|
|
6
8
|
/** Model aliases Claude Code resolves to the latest release; Claude Code itself has no command that lists models. */
|
|
7
9
|
export const CLAUDE_MODELS = ['fable', 'opus', 'sonnet', 'haiku'];
|
|
8
10
|
export const CLAUDE_EFFORT_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
@@ -18,14 +20,29 @@ export async function detectAgents(options = {}) {
|
|
|
18
20
|
const read = options.read ?? readOptional;
|
|
19
21
|
const agents = [];
|
|
20
22
|
const problems = [];
|
|
21
|
-
const
|
|
23
|
+
const detectionFailures = [];
|
|
24
|
+
const version = async (kind) => {
|
|
25
|
+
let failure;
|
|
26
|
+
const output = options.version ? await options.version(kind) : await commandVersion(kind, env, problem => {
|
|
27
|
+
failure = problem;
|
|
28
|
+
problems.push(problem);
|
|
29
|
+
});
|
|
30
|
+
// Send only our bounded diagnostic, never stderr, the environment or the full local PATH.
|
|
31
|
+
if (output === null)
|
|
32
|
+
detectionFailures.push({ kind, message: failure ?? `${kind} --version could not be run. Check the executable and PATH.` });
|
|
33
|
+
return output;
|
|
34
|
+
};
|
|
22
35
|
const claudeVersion = await version('claude');
|
|
23
36
|
if (claudeVersion !== null) {
|
|
24
37
|
const settings = parseJson(await read(join(env.CLAUDE_CONFIG_DIR ?? join(home, '.claude'), 'settings.json')));
|
|
25
38
|
const configured = Array.isArray(settings?.availableModels) ? settings.availableModels.filter((m) => typeof m === 'string') : [];
|
|
26
39
|
const models = [...new Set([...CLAUDE_MODELS, ...configured])].filter(id => NAME.test(id) && id !== 'default')
|
|
27
40
|
.map(id => ({ id, reasoningLevels: CLAUDE_EFFORT_LEVELS }));
|
|
28
|
-
|
|
41
|
+
const approvalModes = options.approvalModes ? await options.approvalModes('claude', claudeVersion)
|
|
42
|
+
: options.version ? undefined : await detectApprovalModes('claude', claudeVersion, env);
|
|
43
|
+
agents.push({ kind: 'claude', version: parseVersion(claudeVersion), models,
|
|
44
|
+
warnings: approvalModes?.length === 0 ? ['Could not verify approval modes. Check the installed Claude Code version and restart the listener after updating it.'] : [],
|
|
45
|
+
...(approvalModes ? { approvalModes } : {}) });
|
|
29
46
|
}
|
|
30
47
|
const codexVersion = await version('codex');
|
|
31
48
|
if (codexVersion !== null) {
|
|
@@ -39,21 +56,91 @@ export async function detectAgents(options = {}) {
|
|
|
39
56
|
const configured = defaultCodexModel(await read(join(codexHome, 'config.toml')));
|
|
40
57
|
if (configured && models.length > 0 && !models.some(m => m.id === configured))
|
|
41
58
|
warnings.push(`The default model "${configured}" from config.toml is not in the Codex model list and may be rejected; pick a model explicitly.`);
|
|
42
|
-
|
|
59
|
+
const approvalModes = options.approvalModes ? await options.approvalModes('codex', codexVersion)
|
|
60
|
+
: options.version ? undefined : await detectApprovalModes('codex', codexVersion, env);
|
|
61
|
+
if (approvalModes?.length === 0)
|
|
62
|
+
warnings.push('Could not verify approval modes from Codex app-server schema. Update Codex and restart the listener.');
|
|
63
|
+
agents.push({ kind: 'codex', version: parseVersion(codexVersion), models, warnings, ...(approvalModes ? { approvalModes } : {}) });
|
|
43
64
|
}
|
|
44
|
-
const
|
|
65
|
+
const settingsText = options.read ? await read(profilesPath(home)) : null;
|
|
66
|
+
const settings = options.read ? migrateAgentSettings(settingsText === null ? {} : JSON.parse(settingsText)) : await loadAgentSettings(profilesPath(home));
|
|
67
|
+
const profiles = parseProfiles(JSON.stringify({ ...settings, profiles: settings.profiles ?? [] }), home, problems);
|
|
45
68
|
for (const profile of profiles)
|
|
46
69
|
if (!agents.some(agent => agent.kind === profile.agent))
|
|
47
70
|
problems.push(`Profile "${profile.name}" uses ${profile.agent}, which is not installed.`);
|
|
48
71
|
if (agents.length === 0)
|
|
49
72
|
problems.push(`Could not run claude --version or codex --version. Check that an agent is installed and runnable on PATH: ${env.PATH ?? env.Path ?? ''}. For a service, check skillshare agents service status and reinstall from a fresh terminal if needed.`);
|
|
50
73
|
return {
|
|
51
|
-
capabilities: { agents,
|
|
52
|
-
|
|
74
|
+
capabilities: { agents, ...(detectionFailures.length ? { detectionFailures } : {}), ...(settings.approvalMode ? { defaultApprovalMode: settings.approvalMode } : {}),
|
|
75
|
+
profiles: profiles.map(p => ({ name: p.name, agent: p.agent, model: p.model, reasoning: p.reasoning,
|
|
76
|
+
workdir: p.workdir ? basename(p.workdir) : undefined, ...(p.defaultApprovalMode ? { defaultApprovalMode: p.defaultApprovalMode } : {}) })) },
|
|
53
77
|
profiles,
|
|
54
78
|
problems,
|
|
55
79
|
};
|
|
56
80
|
}
|
|
81
|
+
const approvalModeCache = new Map();
|
|
82
|
+
/** Pure capability interpretation is separately testable; unknown schemas never advertise automatic review. */
|
|
83
|
+
export function approvalModesFromDescription(kind, text) {
|
|
84
|
+
if (kind === 'claude') {
|
|
85
|
+
return [/\bdefault\b/.test(text) ? 'supervised' : null, /\bacceptEdits\b/.test(text) ? 'autoEdits' : null,
|
|
86
|
+
/\bauto\b/.test(text) ? 'auto' : null, /\bbypassPermissions\b/.test(text) ? 'fullAccess' : null].filter((v) => v !== null);
|
|
87
|
+
}
|
|
88
|
+
const policy = text.includes('approvalPolicy') && text.includes('sandbox');
|
|
89
|
+
return [policy && text.includes('untrusted') ? 'supervised' : null, policy && text.includes('on-request') ? 'autoEdits' : null,
|
|
90
|
+
policy && text.includes('approvalsReviewer') && text.includes('auto_review') ? 'auto' : null,
|
|
91
|
+
policy && text.includes('never') && text.includes('danger-full-access') ? 'fullAccess' : null].filter((v) => v !== null);
|
|
92
|
+
}
|
|
93
|
+
/** Commander wraps choices across lines at narrower terminal widths. Read only this option's explicit choices. */
|
|
94
|
+
export function claudeApprovalModesFromHelp(help) {
|
|
95
|
+
const lines = help.split(/\r?\n/);
|
|
96
|
+
const index = lines.findIndex(line => /--permission-mode\b/.test(line));
|
|
97
|
+
if (index < 0)
|
|
98
|
+
return [];
|
|
99
|
+
const remainder = lines.slice(index + 1);
|
|
100
|
+
const nextOption = remainder.findIndex(line => /^\s*(?:-{1,2}[A-Za-z?]|[A-Z][A-Za-z ]+:)/.test(line));
|
|
101
|
+
const description = [lines[index], ...remainder.slice(0, nextOption < 0 ? remainder.length : nextOption)].join('\n');
|
|
102
|
+
const choices = /choices?:\s*([^)]*)/i.exec(description)?.[1];
|
|
103
|
+
return choices ? approvalModesFromDescription('claude', choices) : [];
|
|
104
|
+
}
|
|
105
|
+
function detectApprovalModes(kind, version, env) {
|
|
106
|
+
const key = `${kind}\0${version}\0${env.PATH ?? env.Path ?? ''}`;
|
|
107
|
+
let cached = approvalModeCache.get(key);
|
|
108
|
+
if (!cached) {
|
|
109
|
+
cached = (async () => {
|
|
110
|
+
if (kind === 'claude') {
|
|
111
|
+
const help = await commandOutput('claude', ['--help'], env);
|
|
112
|
+
return claudeApprovalModesFromHelp(help);
|
|
113
|
+
}
|
|
114
|
+
const directory = await mkdtemp(join(tmpdir(), 'skillshare-codex-schema-'));
|
|
115
|
+
try {
|
|
116
|
+
await commandOutput('codex', ['app-server', 'generate-json-schema', '--out', directory, '--experimental'], env);
|
|
117
|
+
const readSchemas = async (folder) => (await Promise.all((await readdir(folder, { withFileTypes: true })).map(async (entry) => entry.isDirectory() ? readSchemas(join(folder, entry.name)) : entry.name.endsWith('.json') ? [await readFile(join(folder, entry.name), 'utf8')] : []))).flat();
|
|
118
|
+
return approvalModesFromDescription(kind, (await readSchemas(directory)).join('\n'));
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
await rm(directory, { recursive: true, force: true });
|
|
122
|
+
}
|
|
123
|
+
})().catch(() => []);
|
|
124
|
+
approvalModeCache.set(key, cached);
|
|
125
|
+
}
|
|
126
|
+
return cached;
|
|
127
|
+
}
|
|
128
|
+
function commandOutput(command, args, env) {
|
|
129
|
+
return new Promise((resolvePromise, reject) => {
|
|
130
|
+
const child = crossSpawn(command, args, { env, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
131
|
+
let output = '';
|
|
132
|
+
const timer = setTimeout(() => { child.kill(); reject(new Error('Agent capability detection timed out.')); }, 15_000);
|
|
133
|
+
child.stdout?.on('data', chunk => {
|
|
134
|
+
output += String(chunk);
|
|
135
|
+
if (output.length > 2 * 1024 * 1024) {
|
|
136
|
+
child.kill();
|
|
137
|
+
reject(new Error('Agent capability output is too large.'));
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
child.on('error', error => { clearTimeout(timer); reject(error); });
|
|
141
|
+
child.on('exit', code => { clearTimeout(timer); code === 0 ? resolvePromise(output) : reject(new Error('Agent capability detection failed.')); });
|
|
142
|
+
});
|
|
143
|
+
}
|
|
57
144
|
/** Keeps the list within what the server accepts: valid names, no "default", and bounded sizes. */
|
|
58
145
|
function codexModel(id, displayName, levels, fallback) {
|
|
59
146
|
if (typeof id !== 'string' || !NAME.test(id) || id === 'default')
|
|
@@ -150,17 +237,13 @@ export function parseProfiles(text, home, problems = []) {
|
|
|
150
237
|
problems.push(`Profile "${name}" has an invalid model or reasoning.`);
|
|
151
238
|
continue;
|
|
152
239
|
}
|
|
153
|
-
if (raw.sandbox !== undefined && typeof raw.sandbox !== 'boolean') {
|
|
154
|
-
problems.push(`Profile "${name}" sandbox must be true or false.`);
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
240
|
if (raw.args !== undefined && (!Array.isArray(raw.args) || raw.args.some(arg => typeof arg !== 'string'))) {
|
|
158
241
|
problems.push(`Profile "${name}" args must be a list of strings.`);
|
|
159
242
|
continue;
|
|
160
243
|
}
|
|
161
244
|
profiles.push({ name, agent: raw.agent, model: optional('model'), reasoning: optional('reasoning'),
|
|
162
245
|
workdir: typeof raw.workdir === 'string' && raw.workdir.length > 0 ? expandHome(raw.workdir, home) : undefined,
|
|
163
|
-
args: raw.args ?? [], ...(raw.
|
|
246
|
+
args: raw.args ?? [], ...(raw.approvalMode ? { defaultApprovalMode: raw.approvalMode } : {}) });
|
|
164
247
|
}
|
|
165
248
|
return profiles.slice(0, 32);
|
|
166
249
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { Ajv } from 'ajv';
|
|
3
|
+
import { Ajv2019 } from 'ajv/dist/2019.js';
|
|
4
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
5
|
+
import addFormats from 'ajv-formats';
|
|
6
|
+
/** No reference loader, filesystem access or native agent writes enter this worker. */
|
|
7
|
+
export function validateNativeForm(schema, value) {
|
|
8
|
+
try {
|
|
9
|
+
const dialect = schema && typeof schema === 'object' && '$schema' in schema && typeof schema.$schema === 'string' ? schema.$schema : '';
|
|
10
|
+
const Constructor = dialect.includes('2020-12') ? Ajv2020 : dialect.includes('2019-09') ? Ajv2019 : Ajv;
|
|
11
|
+
const ajv = new Constructor({ strictSchema: true, strictTypes: false, strictTuples: false, strictRequired: false,
|
|
12
|
+
allErrors: false, ownProperties: true, coerceTypes: false, useDefaults: false, removeAdditional: false,
|
|
13
|
+
loopEnum: 32, loopRequired: 32, inlineRefs: false, logger: false });
|
|
14
|
+
addFormats.default(ajv);
|
|
15
|
+
ajv.addKeyword({ keyword: 'enumNames', schemaType: ['array', 'null'], valid: true });
|
|
16
|
+
const validate = ajv.compile(schema);
|
|
17
|
+
if ('$async' in validate && validate.$async)
|
|
18
|
+
return { warning: 'Asynchronous native form schemas are not supported. The request is still waiting; you can decline or cancel it.' };
|
|
19
|
+
if (validate(value))
|
|
20
|
+
return { value, valid: true };
|
|
21
|
+
const error = validate.errors?.[0];
|
|
22
|
+
return { valid: false, error: `The response does not match the native form schema at ${error?.instancePath || '/'} (${error?.keyword ?? 'validation'}).` };
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
const message = error instanceof Error ? error.message : '';
|
|
26
|
+
const keyword = /unknown keyword: "([A-Za-z0-9_$-]+)"/.exec(message)?.[1];
|
|
27
|
+
const reason = keyword ? `unsupported schema keyword ${keyword}` : /can't resolve reference/.test(message) ? 'a schema reference is unavailable locally'
|
|
28
|
+
: /unknown format/.test(message) ? 'an unsupported value format' : 'invalid or unsupported schema';
|
|
29
|
+
return { warning: `The native form schema cannot be validated: ${reason}. The request is still waiting; you can decline or cancel it.` };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (parentPort)
|
|
33
|
+
parentPort.postMessage(validateNativeForm(workerData.schema, workerData.value));
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Worker } from 'node:worker_threads';
|
|
2
|
+
const FORM_TIMEOUT_MS = 5_000;
|
|
3
|
+
let activeValidators = 0;
|
|
4
|
+
const waitingValidators = [];
|
|
5
|
+
async function acquireValidator() {
|
|
6
|
+
await new Promise(resolve => {
|
|
7
|
+
const enter = () => { activeValidators++; resolve(); };
|
|
8
|
+
if (activeValidators < 2)
|
|
9
|
+
enter();
|
|
10
|
+
else
|
|
11
|
+
waitingValidators.push(enter);
|
|
12
|
+
});
|
|
13
|
+
return () => { activeValidators--; waitingValidators.shift()?.(); };
|
|
14
|
+
}
|
|
15
|
+
/** Untrusted schema code and regular expressions cannot block the listener's lease/close timers. */
|
|
16
|
+
async function validateInWorker(schema, value) {
|
|
17
|
+
const release = await acquireValidator();
|
|
18
|
+
return new Promise(resolve => {
|
|
19
|
+
let worker;
|
|
20
|
+
let settled = false;
|
|
21
|
+
let timer;
|
|
22
|
+
const finish = (result) => {
|
|
23
|
+
if (settled)
|
|
24
|
+
return;
|
|
25
|
+
settled = true;
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
const done = () => { release(); resolve(result); };
|
|
28
|
+
if (worker)
|
|
29
|
+
void worker.terminate().then(done, done);
|
|
30
|
+
else
|
|
31
|
+
done();
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
worker = new Worker(new URL(import.meta.url.endsWith('.ts') ? './agents-form-worker.ts' : './agents-form-worker.js', import.meta.url), {
|
|
35
|
+
workerData: { schema, value }, resourceLimits: { maxOldGenerationSizeMb: 64, maxYoungGenerationSizeMb: 16, stackSizeMb: 4 },
|
|
36
|
+
});
|
|
37
|
+
worker.once('message', (result) => finish(result));
|
|
38
|
+
worker.once('error', () => finish({ error: 'The native form validator could not complete. The request is still waiting; you can correct the response or cancel it.' }));
|
|
39
|
+
worker.once('exit', () => finish({ error: 'The native form validator stopped. The request is still waiting; you can try again or cancel it.' }));
|
|
40
|
+
timer = setTimeout(() => finish({ error: 'The native form validator exceeded its time limit. The request is still waiting; you can correct the response or cancel it.' }), FORM_TIMEOUT_MS);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
finish({ error: 'The native form validator could not start. The request is still waiting; no response has been sent.' });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Compilation probes run in an isolated worker; original schemas remain intact for display. */
|
|
48
|
+
export async function nativeForm(schema) {
|
|
49
|
+
const root = schema && typeof schema === 'object' ? schema : undefined;
|
|
50
|
+
const initialValue = root?.type === 'string' ? '' : JSON.stringify(root?.default ?? (root?.type === 'array' ? [] : {}), null, 2);
|
|
51
|
+
const result = await validateInWorker(schema, {});
|
|
52
|
+
return { initialValue, emptyValid: result.valid === true, warning: result.warning ?? (result.valid === undefined ? result.error : undefined) };
|
|
53
|
+
}
|
|
54
|
+
/** Invalid input never consumes the request or becomes an automatic native decline. */
|
|
55
|
+
export async function nativeFormResponse(schema, text) {
|
|
56
|
+
if (text === undefined)
|
|
57
|
+
return { error: 'Enter a response to the native form.' };
|
|
58
|
+
let value = text;
|
|
59
|
+
if (schema && typeof schema === 'object' && schema.type === 'string') {
|
|
60
|
+
if (text.trimStart().startsWith('"')) {
|
|
61
|
+
try {
|
|
62
|
+
const parsed = JSON.parse(text);
|
|
63
|
+
if (typeof parsed === 'string')
|
|
64
|
+
value = parsed;
|
|
65
|
+
}
|
|
66
|
+
catch { }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
try {
|
|
71
|
+
value = JSON.parse(text);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return { error: 'Enter valid JSON matching the displayed native form schema.' };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const result = await validateInWorker(schema, value);
|
|
78
|
+
return result.warning ? { error: result.warning } : result;
|
|
79
|
+
}
|
package/dist/agents-process.js
CHANGED
|
@@ -28,7 +28,18 @@ export function startAgentProcess(options) {
|
|
|
28
28
|
child,
|
|
29
29
|
exited,
|
|
30
30
|
stderrTail: () => stderr.trim().split(/\r?\n/).filter(line => line.trim()).slice(-3).join(' ').slice(-300),
|
|
31
|
-
write:
|
|
31
|
+
// write(false) signals backpressure, not rejection: the frame is already buffered and must not be resent.
|
|
32
|
+
write: line => {
|
|
33
|
+
if (!child.stdin?.writable)
|
|
34
|
+
return false;
|
|
35
|
+
try {
|
|
36
|
+
child.stdin.write(line + '\n');
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
32
43
|
kill() {
|
|
33
44
|
killing ??= (async () => {
|
|
34
45
|
const signal = (sig) => {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
const EVENT_BYTES = 3 * 1024 * 1024;
|
|
3
|
+
const CHUNK_BYTES = 256 * 1024;
|
|
4
|
+
const MAX_REQUEST_BYTES = 32 * 1024 * 1024;
|
|
5
|
+
/** Preserve event order and native request content without increasing the ordinary events endpoint limit. */
|
|
6
|
+
export async function uploadSessionEvents(events, leaseToken, post, acknowledged = new WeakSet()) {
|
|
7
|
+
let batch = [];
|
|
8
|
+
let bytes = Buffer.byteLength(JSON.stringify({ leaseToken, events: [] }));
|
|
9
|
+
const flush = async () => {
|
|
10
|
+
if (!batch.length)
|
|
11
|
+
return;
|
|
12
|
+
await post('/events', { leaseToken, events: batch });
|
|
13
|
+
for (const event of batch)
|
|
14
|
+
acknowledged.add(event);
|
|
15
|
+
batch = [];
|
|
16
|
+
bytes = Buffer.byteLength(JSON.stringify({ leaseToken, events: [] }));
|
|
17
|
+
};
|
|
18
|
+
for (const event of events) {
|
|
19
|
+
// EventQueue retries its original snapshots after a partial upload. Successful prefixes must not replay.
|
|
20
|
+
if (acknowledged.has(event))
|
|
21
|
+
continue;
|
|
22
|
+
const eventBytes = Buffer.byteLength(JSON.stringify(event)) + 1;
|
|
23
|
+
if (event.type === 'request' && eventBytes > EVENT_BYTES / 2) {
|
|
24
|
+
await flush();
|
|
25
|
+
const data = Buffer.from(JSON.stringify(event.request), 'utf8');
|
|
26
|
+
const identity = { leaseToken, requestId: event.request.id, hash: createHash('sha256').update(data).digest('hex') };
|
|
27
|
+
const begin = await post('/request-uploads', { ...identity, operation: 'begin', size: data.length,
|
|
28
|
+
chunks: Math.ceil(data.length / CHUNK_BYTES), title: event.request.title.slice(0, 200) });
|
|
29
|
+
if (begin?.complete) {
|
|
30
|
+
acknowledged.add(event);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (!begin?.success)
|
|
34
|
+
throw new Error(begin?.error ?? 'The full request upload is pending; no response has been sent.');
|
|
35
|
+
if (data.length > MAX_REQUEST_BYTES)
|
|
36
|
+
throw new Error('The request exceeds the upload limit and remains visible and pending.');
|
|
37
|
+
for (let offset = 0; offset < data.length; offset += CHUNK_BYTES) {
|
|
38
|
+
const chunk = await post('/request-uploads', { ...identity, operation: 'chunk', index: offset / CHUNK_BYTES,
|
|
39
|
+
data: data.subarray(offset, offset + CHUNK_BYTES).toString('base64') });
|
|
40
|
+
if (!chunk?.success)
|
|
41
|
+
throw new Error(chunk?.error ?? 'The request upload was interrupted; no response has been sent.');
|
|
42
|
+
}
|
|
43
|
+
const completed = await post('/request-uploads', { ...identity, operation: 'complete' });
|
|
44
|
+
if (!completed?.complete)
|
|
45
|
+
throw new Error(completed?.error ?? 'The full request upload is pending; no response has been sent.');
|
|
46
|
+
acknowledged.add(event);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (bytes + eventBytes > EVENT_BYTES)
|
|
50
|
+
await flush();
|
|
51
|
+
batch.push(event);
|
|
52
|
+
bytes += eventBytes;
|
|
53
|
+
}
|
|
54
|
+
await flush();
|
|
55
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/** Same length-prefixed UTF-8 protocol as AgentResponseFingerprint; never depend on JSON property order or escaping. */
|
|
3
|
+
export function responseFingerprint(response) {
|
|
4
|
+
const hash = createHash('sha256');
|
|
5
|
+
const integer = (value) => { const bytes = Buffer.allocUnsafe(4); bytes.writeInt32LE(value); hash.update(bytes); };
|
|
6
|
+
const text = (value) => {
|
|
7
|
+
if (value == null) {
|
|
8
|
+
integer(-1);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const bytes = Buffer.from(value, 'utf8');
|
|
12
|
+
integer(bytes.length);
|
|
13
|
+
hash.update(bytes);
|
|
14
|
+
};
|
|
15
|
+
text('skillshare-response-v1');
|
|
16
|
+
text(response.requestId);
|
|
17
|
+
text(response.decision);
|
|
18
|
+
text(response.formData);
|
|
19
|
+
integer(response.revision ?? 0);
|
|
20
|
+
const answers = response.answers;
|
|
21
|
+
integer(answers == null ? -1 : Object.keys(answers).length);
|
|
22
|
+
if (answers != null)
|
|
23
|
+
for (const key of Object.keys(answers).sort()) {
|
|
24
|
+
text(key);
|
|
25
|
+
const values = answers[key];
|
|
26
|
+
integer(values.length);
|
|
27
|
+
for (const value of values)
|
|
28
|
+
text(value);
|
|
29
|
+
}
|
|
30
|
+
return hash.digest('hex');
|
|
31
|
+
}
|
package/dist/agents-service.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { detectAgents } from './agents-detect.js';
|
|
1
|
+
import { detectAgents, profilesPath } from './agents-detect.js';
|
|
2
|
+
import { loadAgentSettings, updateAgentJson, withoutLegacySandboxArgs } from './agents-settings.js';
|
|
2
3
|
import { refreshServicePath } from './agents-service-path.js';
|
|
3
4
|
import { existsSync } from 'node:fs';
|
|
4
5
|
import { chmod, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
@@ -28,6 +29,21 @@ export function servicePaths(appDir) {
|
|
|
28
29
|
windowsTask: join(appDir, 'agents-service-task.xml'),
|
|
29
30
|
};
|
|
30
31
|
}
|
|
32
|
+
/** Runs on the next service start, including with launchers written by older CLIs. Seed before removing the old argument. */
|
|
33
|
+
export async function migrateServiceApprovalOptions(appDir, settingsPath = profilesPath()) {
|
|
34
|
+
const path = servicePaths(appDir).config;
|
|
35
|
+
if (!existsSync(path))
|
|
36
|
+
return;
|
|
37
|
+
const stored = JSON.parse(await readFile(path, 'utf8'));
|
|
38
|
+
if (!stored.args?.some(arg => arg === '--sandbox' || arg === '--sandbox=true'))
|
|
39
|
+
return;
|
|
40
|
+
await loadAgentSettings(settingsPath, true);
|
|
41
|
+
await updateAgentJson(path, value => {
|
|
42
|
+
if (!Array.isArray(value.args) || value.args.some((arg) => typeof arg !== 'string'))
|
|
43
|
+
throw new Error('Service args must be a list of strings.');
|
|
44
|
+
value.args = withoutLegacySandboxArgs(value.args);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
31
47
|
/** Where the service manager keeps the service definition. */
|
|
32
48
|
export function definitionPath(environment) {
|
|
33
49
|
switch (environment.platform) {
|