quantum-ai-sdk 0.4.0 → 0.6.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 +174 -0
- package/dist/chat.js +21 -0
- package/dist/index.d.ts +4 -1
- package/dist/missions.d.ts +280 -0
- package/dist/missions.js +278 -0
- package/dist/security.d.ts +158 -0
- package/dist/security.js +135 -0
- package/dist/types.d.ts +83 -1
- package/dist/vision.d.ts +130 -0
- package/dist/vision.js +124 -0
- package/package.json +1 -1
package/dist/missions.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// ── Wire format helpers ──────────────────────────────────────────
|
|
2
|
+
/** @internal */
|
|
3
|
+
function createReqToWire(req) {
|
|
4
|
+
const out = { goal: req.goal };
|
|
5
|
+
if (req.strategy !== undefined)
|
|
6
|
+
out.strategy = req.strategy;
|
|
7
|
+
if (req.conductorModel !== undefined)
|
|
8
|
+
out.conductor_model = req.conductorModel;
|
|
9
|
+
if (req.workers !== undefined)
|
|
10
|
+
out.workers = req.workers;
|
|
11
|
+
if (req.maxSteps !== undefined)
|
|
12
|
+
out.max_steps = req.maxSteps;
|
|
13
|
+
if (req.systemPrompt !== undefined)
|
|
14
|
+
out.system_prompt = req.systemPrompt;
|
|
15
|
+
if (req.sessionId !== undefined)
|
|
16
|
+
out.session_id = req.sessionId;
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
function chatReqToWire(req) {
|
|
21
|
+
const out = { message: req.message };
|
|
22
|
+
if (req.stream !== undefined)
|
|
23
|
+
out.stream = req.stream;
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
/** @internal */
|
|
27
|
+
function planUpdateToWire(req) {
|
|
28
|
+
const out = {};
|
|
29
|
+
if (req.tasks !== undefined)
|
|
30
|
+
out.tasks = req.tasks;
|
|
31
|
+
if (req.workers !== undefined)
|
|
32
|
+
out.workers = req.workers;
|
|
33
|
+
if (req.systemPrompt !== undefined)
|
|
34
|
+
out.system_prompt = req.systemPrompt;
|
|
35
|
+
if (req.maxSteps !== undefined)
|
|
36
|
+
out.max_steps = req.maxSteps;
|
|
37
|
+
if (req.context !== undefined)
|
|
38
|
+
out.context = req.context;
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
/** @internal */
|
|
42
|
+
function approveReqToWire(req) {
|
|
43
|
+
const out = {};
|
|
44
|
+
if (req.commitSha !== undefined)
|
|
45
|
+
out.commit_sha = req.commitSha;
|
|
46
|
+
if (req.comment !== undefined)
|
|
47
|
+
out.comment = req.comment;
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** @internal */
|
|
51
|
+
function importReqToWire(req) {
|
|
52
|
+
const out = { goal: req.goal, tasks: req.tasks };
|
|
53
|
+
if (req.strategy !== undefined)
|
|
54
|
+
out.strategy = req.strategy;
|
|
55
|
+
if (req.conductorModel !== undefined)
|
|
56
|
+
out.conductor_model = req.conductorModel;
|
|
57
|
+
if (req.workers !== undefined)
|
|
58
|
+
out.workers = req.workers;
|
|
59
|
+
if (req.systemPrompt !== undefined)
|
|
60
|
+
out.system_prompt = req.systemPrompt;
|
|
61
|
+
if (req.maxSteps !== undefined)
|
|
62
|
+
out.max_steps = req.maxSteps;
|
|
63
|
+
if (req.autoExecute !== undefined)
|
|
64
|
+
out.auto_execute = req.autoExecute;
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/** @internal */
|
|
68
|
+
function taskFromWire(raw) {
|
|
69
|
+
return {
|
|
70
|
+
id: raw.id,
|
|
71
|
+
name: raw.name,
|
|
72
|
+
description: raw.description,
|
|
73
|
+
worker: raw.worker,
|
|
74
|
+
model: raw.model,
|
|
75
|
+
status: raw.status,
|
|
76
|
+
result: raw.result,
|
|
77
|
+
error: raw.error,
|
|
78
|
+
step: raw.step ?? 0,
|
|
79
|
+
tokensIn: raw.tokens_in ?? 0,
|
|
80
|
+
tokensOut: raw.tokens_out ?? 0,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** @internal */
|
|
84
|
+
function detailFromWire(raw) {
|
|
85
|
+
const tasks = (raw.tasks ?? []).map(taskFromWire);
|
|
86
|
+
return {
|
|
87
|
+
id: raw.id,
|
|
88
|
+
userId: raw.user_id,
|
|
89
|
+
goal: raw.goal,
|
|
90
|
+
strategy: raw.strategy,
|
|
91
|
+
conductorModel: raw.conductor_model,
|
|
92
|
+
status: raw.status,
|
|
93
|
+
createdAt: raw.created_at,
|
|
94
|
+
startedAt: raw.started_at,
|
|
95
|
+
completedAt: raw.completed_at,
|
|
96
|
+
error: raw.error,
|
|
97
|
+
costTicks: raw.cost_ticks ?? 0,
|
|
98
|
+
totalSteps: raw.total_steps ?? 0,
|
|
99
|
+
sessionId: raw.session_id,
|
|
100
|
+
result: raw.result,
|
|
101
|
+
tasks,
|
|
102
|
+
approved: raw.approved ?? false,
|
|
103
|
+
commitSha: raw.commit_sha,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** @internal */
|
|
107
|
+
function createRespFromWire(raw) {
|
|
108
|
+
return {
|
|
109
|
+
missionId: raw.mission_id ?? "",
|
|
110
|
+
status: raw.status ?? "",
|
|
111
|
+
sessionId: raw.session_id,
|
|
112
|
+
conductorModel: raw.conductor_model,
|
|
113
|
+
strategy: raw.strategy,
|
|
114
|
+
workers: raw.workers,
|
|
115
|
+
createdAt: raw.created_at,
|
|
116
|
+
requestId: raw.request_id,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** @internal */
|
|
120
|
+
function chatRespFromWire(raw) {
|
|
121
|
+
let usage;
|
|
122
|
+
if (raw.usage) {
|
|
123
|
+
const u = raw.usage;
|
|
124
|
+
usage = {
|
|
125
|
+
inputTokens: u.input_tokens ?? 0,
|
|
126
|
+
outputTokens: u.output_tokens ?? 0,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
missionId: raw.mission_id,
|
|
131
|
+
content: raw.content,
|
|
132
|
+
model: raw.model,
|
|
133
|
+
costTicks: raw.cost_ticks ?? 0,
|
|
134
|
+
usage,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** @internal */
|
|
138
|
+
function statusRespFromWire(raw) {
|
|
139
|
+
return {
|
|
140
|
+
missionId: raw.mission_id,
|
|
141
|
+
status: raw.status,
|
|
142
|
+
confirmed: raw.confirmed,
|
|
143
|
+
approved: raw.approved,
|
|
144
|
+
deleted: raw.deleted,
|
|
145
|
+
updated: raw.updated,
|
|
146
|
+
commitSha: raw.commit_sha,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** @internal */
|
|
150
|
+
function checkpointFromWire(raw) {
|
|
151
|
+
return {
|
|
152
|
+
id: raw.id,
|
|
153
|
+
commitSha: raw.commit_sha,
|
|
154
|
+
message: raw.message,
|
|
155
|
+
createdAt: raw.created_at,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// ── Client methods ───────────────────────────────────────────────
|
|
159
|
+
/**
|
|
160
|
+
* Create and execute a mission asynchronously.
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
export async function missionCreate(client, req) {
|
|
164
|
+
const { data } = await client._doJSON("POST", "/qai/v1/missions/create", createReqToWire(req));
|
|
165
|
+
return createRespFromWire(data);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* List missions for the authenticated user.
|
|
169
|
+
* @internal
|
|
170
|
+
*/
|
|
171
|
+
export async function missionList(client, status) {
|
|
172
|
+
const path = status
|
|
173
|
+
? `/qai/v1/missions/list?status=${encodeURIComponent(status)}`
|
|
174
|
+
: "/qai/v1/missions/list";
|
|
175
|
+
const { data } = await client._doJSON("GET", path, undefined);
|
|
176
|
+
const missions = (data.missions ?? []).map(detailFromWire);
|
|
177
|
+
return { missions };
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get mission details including tasks.
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
export async function missionGet(client, missionId) {
|
|
184
|
+
const { data } = await client._doJSON("GET", `/qai/v1/missions/${encodeURIComponent(missionId)}`, undefined);
|
|
185
|
+
return detailFromWire(data);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Delete a mission.
|
|
189
|
+
* @internal
|
|
190
|
+
*/
|
|
191
|
+
export async function missionDelete(client, missionId) {
|
|
192
|
+
const { data } = await client._doJSON("DELETE", `/qai/v1/missions/${encodeURIComponent(missionId)}`, undefined);
|
|
193
|
+
return statusRespFromWire(data);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Cancel a running mission.
|
|
197
|
+
* @internal
|
|
198
|
+
*/
|
|
199
|
+
export async function missionCancel(client, missionId) {
|
|
200
|
+
const { data } = await client._doJSON("POST", `/qai/v1/missions/${encodeURIComponent(missionId)}/cancel`, undefined);
|
|
201
|
+
return statusRespFromWire(data);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Pause a running mission.
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
207
|
+
export async function missionPause(client, missionId) {
|
|
208
|
+
const { data } = await client._doJSON("POST", `/qai/v1/missions/${encodeURIComponent(missionId)}/pause`, undefined);
|
|
209
|
+
return statusRespFromWire(data);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Resume a paused mission.
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
215
|
+
export async function missionResume(client, missionId) {
|
|
216
|
+
const { data } = await client._doJSON("POST", `/qai/v1/missions/${encodeURIComponent(missionId)}/resume`, undefined);
|
|
217
|
+
return statusRespFromWire(data);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Chat with the mission's architect.
|
|
221
|
+
* @internal
|
|
222
|
+
*/
|
|
223
|
+
export async function missionChat(client, missionId, req) {
|
|
224
|
+
const { data } = await client._doJSON("POST", `/qai/v1/missions/${encodeURIComponent(missionId)}/chat`, chatReqToWire(req));
|
|
225
|
+
return chatRespFromWire(data);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Retry a failed task.
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
231
|
+
export async function missionRetryTask(client, missionId, taskId) {
|
|
232
|
+
const { data } = await client._doJSON("POST", `/qai/v1/missions/${encodeURIComponent(missionId)}/retry/${encodeURIComponent(taskId)}`, undefined);
|
|
233
|
+
return statusRespFromWire(data);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Approve a completed mission.
|
|
237
|
+
* @internal
|
|
238
|
+
*/
|
|
239
|
+
export async function missionApprove(client, missionId, req) {
|
|
240
|
+
const { data } = await client._doJSON("POST", `/qai/v1/missions/${encodeURIComponent(missionId)}/approve`, approveReqToWire(req));
|
|
241
|
+
return statusRespFromWire(data);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Update the mission plan.
|
|
245
|
+
* @internal
|
|
246
|
+
*/
|
|
247
|
+
export async function missionUpdatePlan(client, missionId, req) {
|
|
248
|
+
const { data } = await client._doJSON("PUT", `/qai/v1/missions/${encodeURIComponent(missionId)}/plan`, planUpdateToWire(req));
|
|
249
|
+
return statusRespFromWire(data);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Confirm or reject the proposed execution structure.
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
export async function missionConfirmStructure(client, missionId, req) {
|
|
256
|
+
const { data } = await client._doJSON("POST", `/qai/v1/missions/${encodeURIComponent(missionId)}/confirm-structure`, req);
|
|
257
|
+
return statusRespFromWire(data);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* List git checkpoints for a mission.
|
|
261
|
+
* @internal
|
|
262
|
+
*/
|
|
263
|
+
export async function missionCheckpoints(client, missionId) {
|
|
264
|
+
const { data } = await client._doJSON("GET", `/qai/v1/missions/${encodeURIComponent(missionId)}/checkpoints`, undefined);
|
|
265
|
+
const checkpoints = (data.checkpoints ?? []).map(checkpointFromWire);
|
|
266
|
+
return {
|
|
267
|
+
missionId: data.mission_id,
|
|
268
|
+
checkpoints,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Import an existing plan as a new mission.
|
|
273
|
+
* @internal
|
|
274
|
+
*/
|
|
275
|
+
export async function missionImport(client, req) {
|
|
276
|
+
const { data } = await client._doJSON("POST", "/qai/v1/missions/import", importReqToWire(req));
|
|
277
|
+
return createRespFromWire(data);
|
|
278
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
/** Request body for scanning a URL for prompt injection. */
|
|
3
|
+
export interface SecurityScanUrlRequest {
|
|
4
|
+
/** URL to scan. */
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
/** Request body for scanning raw HTML content. */
|
|
8
|
+
export interface SecurityScanHtmlRequest {
|
|
9
|
+
/** Raw HTML to scan. */
|
|
10
|
+
html: string;
|
|
11
|
+
/** Rendered visible text (for structural analysis). */
|
|
12
|
+
visibleText?: string;
|
|
13
|
+
/** Source URL (for context). */
|
|
14
|
+
url?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Request body for reporting a suspicious URL. */
|
|
17
|
+
export interface SecurityReportRequest {
|
|
18
|
+
/** URL to report. */
|
|
19
|
+
url: string;
|
|
20
|
+
/** Description of the suspected threat. */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Category of the suspected threat. */
|
|
23
|
+
category?: string;
|
|
24
|
+
}
|
|
25
|
+
/** A single detected injection pattern. */
|
|
26
|
+
export interface SecurityFinding {
|
|
27
|
+
/** Category: "instruction_override", "role_impersonation", "data_exfiltration", etc. */
|
|
28
|
+
category: string;
|
|
29
|
+
/** Pattern that matched. */
|
|
30
|
+
pattern: string;
|
|
31
|
+
/** Offending content (truncated). */
|
|
32
|
+
content: string;
|
|
33
|
+
/** Location in the page. */
|
|
34
|
+
location: string;
|
|
35
|
+
/** Threat level for this finding. */
|
|
36
|
+
threat: string;
|
|
37
|
+
/** Detection confidence (0.0 - 1.0). */
|
|
38
|
+
confidence: number;
|
|
39
|
+
/** Human-readable description. */
|
|
40
|
+
description: string;
|
|
41
|
+
}
|
|
42
|
+
/** Threat assessment for a scanned page. */
|
|
43
|
+
export interface SecurityAssessment {
|
|
44
|
+
/** Source URL. */
|
|
45
|
+
url: string;
|
|
46
|
+
/** Overall threat level: "none", "low", "medium", "high", "critical". */
|
|
47
|
+
threatLevel: string;
|
|
48
|
+
/** Numeric threat score (0.0 - 100.0). */
|
|
49
|
+
threatScore: number;
|
|
50
|
+
/** Individual findings. */
|
|
51
|
+
findings: SecurityFinding[];
|
|
52
|
+
/** Length of hidden text content detected. */
|
|
53
|
+
hiddenTextLength: number;
|
|
54
|
+
/** Length of visible text content. */
|
|
55
|
+
visibleTextLength: number;
|
|
56
|
+
/** Ratio of hidden to total content. */
|
|
57
|
+
hiddenRatio: number;
|
|
58
|
+
/** Human-readable summary. */
|
|
59
|
+
summary: string;
|
|
60
|
+
}
|
|
61
|
+
/** Response from a security scan. */
|
|
62
|
+
export interface SecurityScanResponse {
|
|
63
|
+
/** Full threat assessment. */
|
|
64
|
+
assessment: SecurityAssessment;
|
|
65
|
+
/** Request identifier. */
|
|
66
|
+
requestId: string;
|
|
67
|
+
}
|
|
68
|
+
/** Response from checking a URL against the registry. */
|
|
69
|
+
export interface SecurityCheckResponse {
|
|
70
|
+
/** URL that was checked. */
|
|
71
|
+
url: string;
|
|
72
|
+
/** Whether the URL is blocked. */
|
|
73
|
+
blocked: boolean;
|
|
74
|
+
/** Threat level (if blocked). */
|
|
75
|
+
threatLevel?: string;
|
|
76
|
+
/** Threat score (if blocked). */
|
|
77
|
+
threatScore?: number;
|
|
78
|
+
/** Detection categories (if blocked). */
|
|
79
|
+
categories?: string[];
|
|
80
|
+
/** First seen timestamp. */
|
|
81
|
+
firstSeen?: string;
|
|
82
|
+
/** Last seen timestamp. */
|
|
83
|
+
lastSeen?: string;
|
|
84
|
+
/** Number of reports. */
|
|
85
|
+
reportCount?: number;
|
|
86
|
+
/** Registry status: "confirmed", "suspected". */
|
|
87
|
+
status?: string;
|
|
88
|
+
/** Human-readable message. */
|
|
89
|
+
message?: string;
|
|
90
|
+
}
|
|
91
|
+
/** A single blocklist entry. */
|
|
92
|
+
export interface SecurityBlocklistEntry {
|
|
93
|
+
/** Entry identifier. */
|
|
94
|
+
id?: string;
|
|
95
|
+
/** Blocked URL. */
|
|
96
|
+
url: string;
|
|
97
|
+
/** Registry status. */
|
|
98
|
+
status: string;
|
|
99
|
+
/** Threat level. */
|
|
100
|
+
threatLevel: string;
|
|
101
|
+
/** Threat score. */
|
|
102
|
+
threatScore: number;
|
|
103
|
+
/** Detection categories. */
|
|
104
|
+
categories: string[];
|
|
105
|
+
/** Number of findings. */
|
|
106
|
+
findingsCount: number;
|
|
107
|
+
/** Hidden content ratio. */
|
|
108
|
+
hiddenRatio: number;
|
|
109
|
+
/** First seen timestamp. */
|
|
110
|
+
firstSeen?: string;
|
|
111
|
+
/** Summary. */
|
|
112
|
+
summary: string;
|
|
113
|
+
}
|
|
114
|
+
/** Response from the blocklist feed. */
|
|
115
|
+
export interface SecurityBlocklistResponse {
|
|
116
|
+
/** Blocklist entries. */
|
|
117
|
+
entries: SecurityBlocklistEntry[];
|
|
118
|
+
/** Total count. */
|
|
119
|
+
count: number;
|
|
120
|
+
/** Filter status used. */
|
|
121
|
+
status: string;
|
|
122
|
+
}
|
|
123
|
+
/** Response from reporting a URL. */
|
|
124
|
+
export interface SecurityReportResponse {
|
|
125
|
+
/** URL that was reported. */
|
|
126
|
+
url: string;
|
|
127
|
+
/** Report status: "existing" or "suspected". */
|
|
128
|
+
status: string;
|
|
129
|
+
/** Message. */
|
|
130
|
+
message: string;
|
|
131
|
+
/** Threat level (if already in registry). */
|
|
132
|
+
threatLevel?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Scan a URL for prompt injection attacks.
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
export declare function securityScanUrl(client: QuantumClient, url: string): Promise<SecurityScanResponse>;
|
|
139
|
+
/**
|
|
140
|
+
* Scan raw HTML content for prompt injection.
|
|
141
|
+
* @internal
|
|
142
|
+
*/
|
|
143
|
+
export declare function securityScanHtml(client: QuantumClient, req: SecurityScanHtmlRequest): Promise<SecurityScanResponse>;
|
|
144
|
+
/**
|
|
145
|
+
* Check a URL against the injection registry.
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
export declare function securityCheck(client: QuantumClient, url: string): Promise<SecurityCheckResponse>;
|
|
149
|
+
/**
|
|
150
|
+
* Get the injection blocklist feed.
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
export declare function securityBlocklist(client: QuantumClient, status?: string): Promise<SecurityBlocklistResponse>;
|
|
154
|
+
/**
|
|
155
|
+
* Report a suspicious URL.
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
export declare function securityReport(client: QuantumClient, req: SecurityReportRequest): Promise<SecurityReportResponse>;
|
package/dist/security.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// ── Wire format helpers ──────────────────────────────────────────
|
|
2
|
+
/** @internal */
|
|
3
|
+
function scanHtmlToWire(req) {
|
|
4
|
+
const out = { html: req.html };
|
|
5
|
+
if (req.visibleText !== undefined)
|
|
6
|
+
out.visible_text = req.visibleText;
|
|
7
|
+
if (req.url !== undefined)
|
|
8
|
+
out.url = req.url;
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
/** @internal */
|
|
12
|
+
function findingFromWire(raw) {
|
|
13
|
+
return {
|
|
14
|
+
category: raw.category ?? "",
|
|
15
|
+
pattern: raw.pattern ?? "",
|
|
16
|
+
content: raw.content ?? "",
|
|
17
|
+
location: raw.location ?? "",
|
|
18
|
+
threat: raw.threat ?? "",
|
|
19
|
+
confidence: raw.confidence ?? 0,
|
|
20
|
+
description: raw.description ?? "",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
function assessmentFromWire(raw) {
|
|
25
|
+
const findings = (raw.findings ?? []).map(findingFromWire);
|
|
26
|
+
return {
|
|
27
|
+
url: raw.url ?? "",
|
|
28
|
+
threatLevel: raw.threat_level ?? "",
|
|
29
|
+
threatScore: raw.threat_score ?? 0,
|
|
30
|
+
findings,
|
|
31
|
+
hiddenTextLength: raw.hidden_text_length ?? 0,
|
|
32
|
+
visibleTextLength: raw.visible_text_length ?? 0,
|
|
33
|
+
hiddenRatio: raw.hidden_ratio ?? 0,
|
|
34
|
+
summary: raw.summary ?? "",
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** @internal */
|
|
38
|
+
function scanRespFromWire(raw) {
|
|
39
|
+
return {
|
|
40
|
+
assessment: assessmentFromWire(raw.assessment ?? {}),
|
|
41
|
+
requestId: raw.request_id ?? "",
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** @internal */
|
|
45
|
+
function checkRespFromWire(raw) {
|
|
46
|
+
return {
|
|
47
|
+
url: raw.url ?? "",
|
|
48
|
+
blocked: raw.blocked ?? false,
|
|
49
|
+
threatLevel: raw.threat_level,
|
|
50
|
+
threatScore: raw.threat_score,
|
|
51
|
+
categories: raw.categories,
|
|
52
|
+
firstSeen: raw.first_seen,
|
|
53
|
+
lastSeen: raw.last_seen,
|
|
54
|
+
reportCount: raw.report_count,
|
|
55
|
+
status: raw.status,
|
|
56
|
+
message: raw.message,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** @internal */
|
|
60
|
+
function blocklistEntryFromWire(raw) {
|
|
61
|
+
return {
|
|
62
|
+
id: raw.id,
|
|
63
|
+
url: raw.url ?? "",
|
|
64
|
+
status: raw.status ?? "",
|
|
65
|
+
threatLevel: raw.threat_level ?? "",
|
|
66
|
+
threatScore: raw.threat_score ?? 0,
|
|
67
|
+
categories: raw.categories ?? [],
|
|
68
|
+
findingsCount: raw.findings_count ?? 0,
|
|
69
|
+
hiddenRatio: raw.hidden_ratio ?? 0,
|
|
70
|
+
firstSeen: raw.first_seen,
|
|
71
|
+
summary: raw.summary ?? "",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** @internal */
|
|
75
|
+
function blocklistRespFromWire(raw) {
|
|
76
|
+
const entries = (raw.entries ?? []).map(blocklistEntryFromWire);
|
|
77
|
+
return {
|
|
78
|
+
entries,
|
|
79
|
+
count: raw.count ?? 0,
|
|
80
|
+
status: raw.status ?? "",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** @internal */
|
|
84
|
+
function reportRespFromWire(raw) {
|
|
85
|
+
return {
|
|
86
|
+
url: raw.url ?? "",
|
|
87
|
+
status: raw.status ?? "",
|
|
88
|
+
message: raw.message ?? "",
|
|
89
|
+
threatLevel: raw.threat_level,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// ── Client methods ───────────────────────────────────────────────
|
|
93
|
+
/**
|
|
94
|
+
* Scan a URL for prompt injection attacks.
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
export async function securityScanUrl(client, url) {
|
|
98
|
+
const { data } = await client._doJSON("POST", "/qai/v1/security/scan-url", { url });
|
|
99
|
+
return scanRespFromWire(data);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Scan raw HTML content for prompt injection.
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export async function securityScanHtml(client, req) {
|
|
106
|
+
const { data } = await client._doJSON("POST", "/qai/v1/security/scan-html", scanHtmlToWire(req));
|
|
107
|
+
return scanRespFromWire(data);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Check a URL against the injection registry.
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
export async function securityCheck(client, url) {
|
|
114
|
+
const { data } = await client._doJSON("GET", `/qai/v1/security/check?url=${encodeURIComponent(url)}`, undefined);
|
|
115
|
+
return checkRespFromWire(data);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get the injection blocklist feed.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
export async function securityBlocklist(client, status) {
|
|
122
|
+
const path = status
|
|
123
|
+
? `/qai/v1/security/blocklist?status=${encodeURIComponent(status)}`
|
|
124
|
+
: "/qai/v1/security/blocklist";
|
|
125
|
+
const { data } = await client._doJSON("GET", path, undefined);
|
|
126
|
+
return blocklistRespFromWire(data);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Report a suspicious URL.
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
export async function securityReport(client, req) {
|
|
133
|
+
const { data } = await client._doJSON("POST", "/qai/v1/security/report", req);
|
|
134
|
+
return reportRespFromWire(data);
|
|
135
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -84,12 +84,39 @@ export interface StreamToolUse {
|
|
|
84
84
|
name: string;
|
|
85
85
|
input: Record<string, unknown>;
|
|
86
86
|
}
|
|
87
|
+
/** New since v0.6: tool-use streaming triplet. */
|
|
88
|
+
export interface StreamToolUseStart {
|
|
89
|
+
id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
}
|
|
92
|
+
export interface StreamToolUseInputDelta {
|
|
93
|
+
id: string;
|
|
94
|
+
/** Raw JSON fragment — may not parse on its own; accumulate until tool_use_complete. */
|
|
95
|
+
partial_json: string;
|
|
96
|
+
}
|
|
97
|
+
export interface StreamToolUseComplete {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
/** Server-accumulated, fully-parsed tool arguments. */
|
|
101
|
+
input: Record<string, unknown>;
|
|
102
|
+
}
|
|
87
103
|
export interface StreamEvent {
|
|
88
104
|
type: string;
|
|
89
|
-
/** Event type (e.g. "content_delta", "thinking_delta", "
|
|
105
|
+
/** Event type (e.g. "content_delta", "thinking_delta", "tool_use_start",
|
|
106
|
+
* "tool_use_input_delta", "tool_use_complete", "tool_use" (legacy),
|
|
107
|
+
* "usage", "error", "done"). */
|
|
90
108
|
event_type?: string;
|
|
91
109
|
delta?: StreamDelta;
|
|
110
|
+
/** Populated for the legacy atomic "tool_use" event. New code should
|
|
111
|
+
* prefer the triplet (tool_use_start / tool_use_input_delta /
|
|
112
|
+
* tool_use_complete). */
|
|
92
113
|
tool_use?: StreamToolUse;
|
|
114
|
+
/** Populated for "tool_use_start" events. */
|
|
115
|
+
tool_use_start?: StreamToolUseStart;
|
|
116
|
+
/** Populated for "tool_use_input_delta" events. */
|
|
117
|
+
tool_use_input_delta?: StreamToolUseInputDelta;
|
|
118
|
+
/** Populated for "tool_use_complete" events. */
|
|
119
|
+
tool_use_complete?: StreamToolUseComplete;
|
|
93
120
|
usage?: ChatUsage;
|
|
94
121
|
error?: string;
|
|
95
122
|
done?: boolean;
|
|
@@ -99,6 +126,11 @@ export interface RawStreamEvent {
|
|
|
99
126
|
type?: string;
|
|
100
127
|
delta?: StreamDelta;
|
|
101
128
|
tool_use?: StreamToolUse;
|
|
129
|
+
/** Fields shared by the triplet — flattened in the wire format. */
|
|
130
|
+
id?: string;
|
|
131
|
+
name?: string;
|
|
132
|
+
input?: Record<string, unknown>;
|
|
133
|
+
partial_json?: string;
|
|
102
134
|
usage?: ChatUsage;
|
|
103
135
|
message?: string;
|
|
104
136
|
input_tokens?: number;
|
|
@@ -2208,3 +2240,53 @@ export interface SearchOptions {
|
|
|
2208
2240
|
freshness?: string;
|
|
2209
2241
|
safe_search?: string;
|
|
2210
2242
|
}
|
|
2243
|
+
/** A single scrape target. */
|
|
2244
|
+
export interface ScrapeTarget {
|
|
2245
|
+
name: string;
|
|
2246
|
+
url: string;
|
|
2247
|
+
type?: string;
|
|
2248
|
+
selector?: string;
|
|
2249
|
+
content?: string;
|
|
2250
|
+
notebook?: string;
|
|
2251
|
+
recursive?: boolean;
|
|
2252
|
+
max_pages?: number;
|
|
2253
|
+
delay_ms?: number;
|
|
2254
|
+
ingest?: string;
|
|
2255
|
+
}
|
|
2256
|
+
/** Request body for submitting a scrape job. */
|
|
2257
|
+
export interface ScrapeRequest {
|
|
2258
|
+
targets: ScrapeTarget[];
|
|
2259
|
+
}
|
|
2260
|
+
/** Response from submitting a scrape job. */
|
|
2261
|
+
export interface ScrapeResponse {
|
|
2262
|
+
job_id: string;
|
|
2263
|
+
status: string;
|
|
2264
|
+
targets: number;
|
|
2265
|
+
request_id: string;
|
|
2266
|
+
}
|
|
2267
|
+
/** A single URL to screenshot. */
|
|
2268
|
+
export interface ScreenshotURL {
|
|
2269
|
+
url: string;
|
|
2270
|
+
width?: number;
|
|
2271
|
+
height?: number;
|
|
2272
|
+
full_page?: boolean;
|
|
2273
|
+
delay_ms?: number;
|
|
2274
|
+
}
|
|
2275
|
+
/** Request body for taking screenshots. */
|
|
2276
|
+
export interface ScreenshotRequest {
|
|
2277
|
+
urls: ScreenshotURL[];
|
|
2278
|
+
}
|
|
2279
|
+
/** A single screenshot result. */
|
|
2280
|
+
export interface ScreenshotResult {
|
|
2281
|
+
url: string;
|
|
2282
|
+
base64: string;
|
|
2283
|
+
format: string;
|
|
2284
|
+
width: number;
|
|
2285
|
+
height: number;
|
|
2286
|
+
error?: string;
|
|
2287
|
+
}
|
|
2288
|
+
/** Response from the screenshot endpoint. */
|
|
2289
|
+
export interface ScreenshotResponse {
|
|
2290
|
+
screenshots: ScreenshotResult[];
|
|
2291
|
+
count: number;
|
|
2292
|
+
}
|