@sentisec/sdk 1.0.0 → 1.1.1
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/CHANGELOG.md +95 -0
- package/README.md +102 -5
- package/bin/sentisec.js +40 -54
- package/dist/index.cjs +589 -48
- package/dist/index.d.cts +364 -16
- package/dist/index.d.ts +364 -16
- package/dist/index.js +569 -49
- package/package.json +2 -5
- package/scripts/install-binary.js +130 -31
package/dist/index.d.cts
CHANGED
|
@@ -10,14 +10,16 @@
|
|
|
10
10
|
* or mutates are listed:
|
|
11
11
|
*
|
|
12
12
|
* - `baseURL` — read + rewritten to the Sentisec proxy URL.
|
|
13
|
-
* - `defaultHeaders` —
|
|
13
|
+
* - `defaultHeaders` — when the client exposes it as an object (openai-node v4
|
|
14
|
+
* stubs, duck types), extended with `x-sentisec-session-id`; openai-node v5+
|
|
15
|
+
* keeps no such property, and the header then rides each call's options.
|
|
14
16
|
* - `chat.completions.create` — the call site whose Promise return
|
|
15
17
|
* is post-processed to translate proxy HALT bodies into
|
|
16
18
|
* `SentisecHijackError` (see `wrap-openai.ts`).
|
|
17
19
|
*/
|
|
18
20
|
interface OpenAILike {
|
|
19
21
|
baseURL: string;
|
|
20
|
-
defaultHeaders
|
|
22
|
+
defaultHeaders?: Record<string, string>;
|
|
21
23
|
chat: {
|
|
22
24
|
completions: {
|
|
23
25
|
create: (params: {
|
|
@@ -26,7 +28,9 @@ interface OpenAILike {
|
|
|
26
28
|
role: string;
|
|
27
29
|
content: string;
|
|
28
30
|
}[];
|
|
29
|
-
}
|
|
31
|
+
},
|
|
32
|
+
/** The SDK's per-request options (`headers`, `timeout`, `signal`), passed through. */
|
|
33
|
+
options?: Record<string, unknown>) => Promise<unknown>;
|
|
30
34
|
};
|
|
31
35
|
};
|
|
32
36
|
}
|
|
@@ -90,9 +94,10 @@ declare module "./index.js" {
|
|
|
90
94
|
* - The client's `baseURL` is rewritten to the Sentisec proxy
|
|
91
95
|
* URL (default `https://api.sentisec.ch/ws/<workspace>/v1`,
|
|
92
96
|
* overridable via `opts.baseUrl`).
|
|
93
|
-
* -
|
|
94
|
-
* `
|
|
95
|
-
*
|
|
97
|
+
* - Each call carries `x-sentisec-session-id` (through the
|
|
98
|
+
* client's `defaultHeaders` when it keeps them as an object,
|
|
99
|
+
* else through the call's options). Per-call options — headers,
|
|
100
|
+
* `timeout`, `signal` — pass through.
|
|
96
101
|
*
|
|
97
102
|
* Returns the same client reference, type-preserved via the
|
|
98
103
|
* generic so customer code keeps full IDE autocomplete on the
|
|
@@ -144,9 +149,11 @@ declare class SentisecHijackError extends Error {
|
|
|
144
149
|
interface AnthropicLike {
|
|
145
150
|
apiKey: string;
|
|
146
151
|
baseURL: string;
|
|
147
|
-
defaultHeaders
|
|
152
|
+
defaultHeaders?: Record<string, string>;
|
|
148
153
|
messages: {
|
|
149
|
-
create: (params: AnthropicMessageCreateParams
|
|
154
|
+
create: (params: AnthropicMessageCreateParams,
|
|
155
|
+
/** The SDK's per-request options (`headers`, `timeout`, `signal`), passed through. */
|
|
156
|
+
options?: Record<string, unknown>) => Promise<AnthropicMessageResponse>;
|
|
150
157
|
};
|
|
151
158
|
}
|
|
152
159
|
/** Subset of `MessageCreateParams` from `@anthropic-ai/sdk` we touch. */
|
|
@@ -236,17 +243,150 @@ declare class SentisecAnthropicBlockError extends Error {
|
|
|
236
243
|
});
|
|
237
244
|
}
|
|
238
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Reading a held call's offer off a provider response (the Python twin is
|
|
248
|
+
* `sentisec_sdk.approvals.offer`).
|
|
249
|
+
*
|
|
250
|
+
* When Sentisec holds a tool call for a person's approval, the response the
|
|
251
|
+
* app receives carries a machine offer beside the model's message: in a JSON
|
|
252
|
+
* body, `sentisec.approval.calls[]` (one entry per held call: its action id,
|
|
253
|
+
* its review id, the `status_url` the app's own key may read, the opaque
|
|
254
|
+
* continuation handle); a JSON reply with one held call also carries
|
|
255
|
+
* `X-Sentisec-Continuation`. A reply the plane held open while a person
|
|
256
|
+
* decided (rung i) has neither header: its body's `completed[]` names each
|
|
257
|
+
* call settled while it waited, `calls[]` the ones still waiting. A stream
|
|
258
|
+
* carries the same objects in comments (`sse-verdicts.ts`). This module reads;
|
|
259
|
+
* it never writes into a message.
|
|
260
|
+
*/
|
|
261
|
+
declare const CONTINUATION_HEADER = "X-Sentisec-Continuation";
|
|
262
|
+
declare const REFUSED_HEADER = "X-Sentisec-Continuation-Refused";
|
|
263
|
+
declare const SESSION_HEADER = "x-session-id";
|
|
264
|
+
declare const APPLICATION_HEADER = "X-Sentisec-Application";
|
|
265
|
+
/** On a held reply: the most seconds it waited for a person (rung i). */
|
|
266
|
+
declare const IN_BAND_HEADER = "X-Sentisec-In-Band-Wait";
|
|
267
|
+
/** One call Sentisec holds until a person decides (store it with `JSON.stringify`). */
|
|
268
|
+
interface PendingApproval {
|
|
269
|
+
actionId: string;
|
|
270
|
+
/** A path on the Sentisec plane, readable by the key that sent the call. */
|
|
271
|
+
statusUrl: string;
|
|
272
|
+
reviewId?: string;
|
|
273
|
+
callId?: string;
|
|
274
|
+
/** The handle: a credential for this one call. Never put it in a prompt. */
|
|
275
|
+
continuation?: string;
|
|
276
|
+
/** The held tool and arguments, when the workspace captures them in full. */
|
|
277
|
+
exactCall?: {
|
|
278
|
+
tool: string;
|
|
279
|
+
arguments: Record<string, unknown>;
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/** A held call a person settled while its reply waited (rung i). */
|
|
283
|
+
interface CompletedCall {
|
|
284
|
+
callId: string;
|
|
285
|
+
/** `released` (the call is in the same reply under `releasedAs`) or `declined`. */
|
|
286
|
+
outcome: string;
|
|
287
|
+
/** `in_band`. */
|
|
288
|
+
rung?: string;
|
|
289
|
+
/** `<callId>_ib`: run it and answer it under this id, like any call. */
|
|
290
|
+
releasedAs?: string;
|
|
291
|
+
}
|
|
292
|
+
/** Every held call `response` says was settled while it waited (rung i); `[]` when none. */
|
|
293
|
+
declare function completedCalls(response: unknown): CompletedCall[];
|
|
294
|
+
/**
|
|
295
|
+
* Every call `response` says is waiting for approval; `[]` when none.
|
|
296
|
+
* Accepts a parsed body (the OpenAI / Anthropic SDK result keeps the
|
|
297
|
+
* `sentisec` field) or `{ data, response }` from `.withResponse()`.
|
|
298
|
+
*/
|
|
299
|
+
declare function pendingApprovals(response: unknown): PendingApproval[];
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* A stream's verdict comments: what the plane said about held calls while
|
|
303
|
+
* the app read it (the Python twin is `sentisec_sdk.approvals.stream`).
|
|
304
|
+
*
|
|
305
|
+
* A stream cannot carry the offer in a JSON body, so the plane sends SSE
|
|
306
|
+
* **comments**, which every SSE client skips (openai-node and
|
|
307
|
+
* @anthropic-ai/sdk included):
|
|
308
|
+
*
|
|
309
|
+
* - `: sentisec-verdict {"approval": {"status": "pending", "calls": [...]}}`
|
|
310
|
+
* — a call the plane holds for a person, with its handle, before the
|
|
311
|
+
* call's own frames;
|
|
312
|
+
* - `: sentisec-in-band-wait` — the reply is waiting for that person
|
|
313
|
+
* (rung i), at least every 10 seconds;
|
|
314
|
+
* - `: sentisec-verdict {"approval": {"status": "completed", "completed": [...]}}`
|
|
315
|
+
* — what a person settled while it waited: `released` (the call's frames
|
|
316
|
+
* follow under `<call_id>_ib`) or `declined`;
|
|
317
|
+
* - `: sentisec-verdict {"verdict": "<label>"}` — the turn's trailing verdict.
|
|
318
|
+
*
|
|
319
|
+
* So a call announced as pending is still pending only when no later
|
|
320
|
+
* comment of the same stream completed it. `SseVerdicts` reads them in that
|
|
321
|
+
* order, fed bytes or text as they arrive; `tapSse` reads them off a
|
|
322
|
+
* `fetch` Response while its body passes through unchanged.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
declare class SseVerdicts {
|
|
326
|
+
private partial;
|
|
327
|
+
private readonly decoder;
|
|
328
|
+
private readonly announced;
|
|
329
|
+
private readonly settled;
|
|
330
|
+
/** How many keep-alives arrived (`> 0`: the reply waited for a person). */
|
|
331
|
+
waits: number;
|
|
332
|
+
/** The trailing verdict label, when the plane sent one. */
|
|
333
|
+
verdict: string | undefined;
|
|
334
|
+
/** Read one chunk; a line split across chunks is joined first. */
|
|
335
|
+
feed(chunk: Uint8Array | string): void;
|
|
336
|
+
/** Read a last line that had no newline. */
|
|
337
|
+
close(): void;
|
|
338
|
+
private line;
|
|
339
|
+
/** The calls still held at the point read so far (announced, not completed). */
|
|
340
|
+
get pending(): PendingApproval[];
|
|
341
|
+
/** The calls a person settled while the stream waited. */
|
|
342
|
+
get completed(): CompletedCall[];
|
|
343
|
+
}
|
|
344
|
+
/** Every held call a raw SSE stream left waiting (announced and not completed). */
|
|
345
|
+
declare function pendingFromSse(stream: string): PendingApproval[];
|
|
346
|
+
/** Every held call a raw SSE stream says a person settled while it waited. */
|
|
347
|
+
declare function completedFromSse(stream: string): CompletedCall[];
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* The request and the final metadata of the SSE adapters (`streaming.ts`).
|
|
351
|
+
*
|
|
352
|
+
* A stream request carries what the client itself would send — its key,
|
|
353
|
+
* its default headers when it keeps a plain object of them, then the
|
|
354
|
+
* call's own `options.headers` — and the final event's `sentisec` field
|
|
355
|
+
* says only what the plane's comments said.
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
/** A stream request the plane (or the upstream) answered with a non-2xx status. */
|
|
359
|
+
declare class SentisecStreamError extends Error {
|
|
360
|
+
readonly status: number;
|
|
361
|
+
readonly body: string;
|
|
362
|
+
constructor(status: number, body: string);
|
|
363
|
+
}
|
|
364
|
+
|
|
239
365
|
/**
|
|
240
366
|
* SSE adapters for OpenAI and Anthropic clients.
|
|
241
367
|
*
|
|
242
368
|
* Uses fetch, ReadableStream and TextDecoder to pass through stream
|
|
243
369
|
* events, attach Sentisec verdict metadata and honour AbortSignal.
|
|
370
|
+
*
|
|
371
|
+
* The request carries what the client itself would send: its key
|
|
372
|
+
* (`apiKey` as `Authorization: Bearer` for OpenAI, `x-api-key` — or
|
|
373
|
+
* `authToken` as a Bearer — for Anthropic), its `defaultHeaders` when it
|
|
374
|
+
* keeps a plain object of them, then the call's own `options.headers`
|
|
375
|
+
* (an approvals handle, a session label). A non-2xx answer throws
|
|
376
|
+
* `SentisecStreamError`. The `sentisec` metadata on the last event is
|
|
377
|
+
* read from the plane's own SSE comments — its trailing verdict label
|
|
378
|
+
* (`UNKNOWN` when it sent none) and the approval offer or in-band
|
|
379
|
+
* completion — never assumed.
|
|
244
380
|
*/
|
|
381
|
+
|
|
245
382
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
383
|
+
* The verdict label on a stream's last event: the plane's own trailing
|
|
384
|
+
* label (`NOMINAL`, `ELEVATED`, `SUSPICIOUS`, `HIJACK`), `UNKNOWN` when the
|
|
385
|
+
* plane sent none, or `ABORT` when the consumer aborted. `PASS`,
|
|
386
|
+
* `SANITIZE` and `PENDING` are kept for type compatibility; the adapters no
|
|
387
|
+
* longer produce them.
|
|
248
388
|
*/
|
|
249
|
-
type VerdictValue = "
|
|
389
|
+
type VerdictValue = "NOMINAL" | "ELEVATED" | "SUSPICIOUS" | "HIJACK" | "UNKNOWN" | "ABORT" | "PASS" | "SANITIZE" | "PENDING";
|
|
250
390
|
/**
|
|
251
391
|
* Sentisec verdict metadata attached to stream chunks.
|
|
252
392
|
*/
|
|
@@ -256,6 +396,16 @@ interface Verdict {
|
|
|
256
396
|
row?: string;
|
|
257
397
|
forensic_id?: string;
|
|
258
398
|
detail?: string;
|
|
399
|
+
/**
|
|
400
|
+
* Held calls, from the plane's comments: `pending` still wait for a person
|
|
401
|
+
* (each with its `continuation` handle, for `Approvals.resume`);
|
|
402
|
+
* `completed` were settled while the stream waited (a released call is in
|
|
403
|
+
* the stream under its `releasedAs` id). Absent when nothing was held.
|
|
404
|
+
*/
|
|
405
|
+
approval?: {
|
|
406
|
+
pending: PendingApproval[];
|
|
407
|
+
completed: CompletedCall[];
|
|
408
|
+
};
|
|
259
409
|
}
|
|
260
410
|
/**
|
|
261
411
|
* OpenAI-flavoured streaming chunk carrying an optional Sentisec
|
|
@@ -317,7 +467,10 @@ interface StreamOptions {
|
|
|
317
467
|
*/
|
|
318
468
|
interface OpenAIStreamingLike {
|
|
319
469
|
baseURL: string;
|
|
320
|
-
|
|
470
|
+
/** Sent as `Authorization: Bearer` (the client's own key). */
|
|
471
|
+
apiKey?: string;
|
|
472
|
+
/** Extra headers, when the client keeps a plain object of them (openai-node 5+ has none). */
|
|
473
|
+
defaultHeaders?: Record<string, string>;
|
|
321
474
|
chat: {
|
|
322
475
|
completions: {
|
|
323
476
|
create: (params: {
|
|
@@ -328,7 +481,7 @@ interface OpenAIStreamingLike {
|
|
|
328
481
|
}[];
|
|
329
482
|
stream?: boolean;
|
|
330
483
|
[key: string]: unknown;
|
|
331
|
-
}) => Promise<unknown> | AsyncIterable<OpenAIStreamChunk>;
|
|
484
|
+
}, options?: Record<string, unknown>) => Promise<unknown> | AsyncIterable<OpenAIStreamChunk>;
|
|
332
485
|
};
|
|
333
486
|
};
|
|
334
487
|
}
|
|
@@ -353,7 +506,12 @@ declare function wrapOpenAIStream<T extends OpenAIStreamingLike>(client: T, sess
|
|
|
353
506
|
*/
|
|
354
507
|
interface AnthropicStreamingLike {
|
|
355
508
|
baseURL: string;
|
|
356
|
-
|
|
509
|
+
/** Sent as `x-api-key` (the client's own key). */
|
|
510
|
+
apiKey?: string | null;
|
|
511
|
+
/** Sent as `Authorization: Bearer` when there is no `apiKey`. */
|
|
512
|
+
authToken?: string | null;
|
|
513
|
+
/** Extra headers, when the client keeps a plain object of them. */
|
|
514
|
+
defaultHeaders?: Record<string, string>;
|
|
357
515
|
messages: {
|
|
358
516
|
create: (params: {
|
|
359
517
|
model: string;
|
|
@@ -364,7 +522,7 @@ interface AnthropicStreamingLike {
|
|
|
364
522
|
}[];
|
|
365
523
|
stream?: boolean;
|
|
366
524
|
[key: string]: unknown;
|
|
367
|
-
}) => Promise<unknown> | AsyncIterable<AnthropicStreamEvent>;
|
|
525
|
+
}, options?: Record<string, unknown>) => Promise<unknown> | AsyncIterable<AnthropicStreamEvent>;
|
|
368
526
|
};
|
|
369
527
|
}
|
|
370
528
|
/**
|
|
@@ -381,6 +539,196 @@ interface AnthropicStreamingLike {
|
|
|
381
539
|
*/
|
|
382
540
|
declare function wrapAnthropicStream<T extends AnthropicStreamingLike>(client: T, sessionId: string, opts?: StreamOptions): T;
|
|
383
541
|
|
|
542
|
+
/**
|
|
543
|
+
* Held tool calls: read the offer, wait for the decision, re-send once.
|
|
544
|
+
*
|
|
545
|
+
* Sentisec can hold a tool call the model proposed until a person
|
|
546
|
+
* approves it. Most apps need no code for that (the plane holds the reply
|
|
547
|
+
* open for a short window, or tells the model the step is waiting). An
|
|
548
|
+
* app that keeps a ticket or a job open across minutes uses this helper:
|
|
549
|
+
*
|
|
550
|
+
* ```ts
|
|
551
|
+
* const approvals = Approvals.fromClient(openai); // or new Approvals({ apiKey, endpoint })
|
|
552
|
+
* const result = await approvals.complete(
|
|
553
|
+
* (body, options) => openai.chat.completions.create(body, options),
|
|
554
|
+
* { model, messages, tools },
|
|
555
|
+
* { sessionId: ticket.id },
|
|
556
|
+
* );
|
|
557
|
+
* ```
|
|
558
|
+
*
|
|
559
|
+
* For fetch-based stacks (the AI SDK, Mastra, LangChain.js) the same flow
|
|
560
|
+
* runs inside a `fetch`: `createOpenAI({ fetch: approvals.fetch() })`.
|
|
561
|
+
*
|
|
562
|
+
* A reply the plane held open while a person decided (rung i,
|
|
563
|
+
* `X-Sentisec-In-Band-Wait`) is read to its end: its headers left before
|
|
564
|
+
* the ruling, so it has no `X-Sentisec-Approval` / `X-Sentisec-Continuation`
|
|
565
|
+
* and the body's `sentisec.approval` is the truth — `completed[]` names a
|
|
566
|
+
* call released in band (it is in the reply under `<call_id>_ib`) or
|
|
567
|
+
* declined; `calls[]` the ones still waiting, each with its handle.
|
|
568
|
+
*
|
|
569
|
+
* When an answer still holds a call, the helper reads the call's stored
|
|
570
|
+
* outcome at `status_url` (with the key that sent it) until a person
|
|
571
|
+
* decides, and once approved re-sends the **same request** once with the
|
|
572
|
+
* continuation handle in `X-Sentisec-Continuation`; the model proposes the
|
|
573
|
+
* call again and the plane releases it once. A refused handle (409
|
|
574
|
+
* `continuation_refused`) ends the attempt. A call the plane did not let
|
|
575
|
+
* leave comes back renamed `sentisec_tool_call_blocked`: answer it with
|
|
576
|
+
* `blockedResults(response)`, never run it. The helper never adds text to
|
|
577
|
+
* a message: the handle travels only in the header (never shown to the
|
|
578
|
+
* model or the user). The Python twin is `sentisec_sdk.approvals`.
|
|
579
|
+
*
|
|
580
|
+
* Streams: the offer and the in-band completion ride SSE comments, which
|
|
581
|
+
* the provider SDKs skip. `approvals.fetch()` reads them while the client
|
|
582
|
+
* reads the stream (bytes unchanged) and hands a call still waiting at the
|
|
583
|
+
* end to `onPending`; `pendingFromSse` / `completedFromSse` / `SseVerdicts`
|
|
584
|
+
* read them from raw text. `complete` reads JSON answers only.
|
|
585
|
+
*/
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* The plane's longest in-band wait (45 s) plus 15 s: the least total
|
|
589
|
+
* deadline a client using `approvals.fetch()` (or any `AbortSignal.timeout`)
|
|
590
|
+
* needs to read a held reply.
|
|
591
|
+
*/
|
|
592
|
+
declare const HOLD_TIMEOUT_MS = 60000;
|
|
593
|
+
/** What `complete` / `resume` did (`outcome` vocabulary: the plane's stored outcome). */
|
|
594
|
+
interface ApprovalResult<T> {
|
|
595
|
+
/** The answer to continue with: the re-sent request's, else the first (undefined if nothing was sent). */
|
|
596
|
+
response: T | undefined;
|
|
597
|
+
/**
|
|
598
|
+
* undefined: nothing was held; `released` / `declined` when a person decided while the reply
|
|
599
|
+
* waited (`rung` `in_band`); `approved_not_run` when re-sent (`rung` `handle`); `waiting` when
|
|
600
|
+
* the wait ran out; else the stored outcome (`declined`, `lapsed`, `expired`, `revoked`, `released`).
|
|
601
|
+
*/
|
|
602
|
+
outcome?: string;
|
|
603
|
+
/** The calls still held after the first answer, for the app's memory. */
|
|
604
|
+
pending: PendingApproval[];
|
|
605
|
+
resent: boolean;
|
|
606
|
+
/** The `X-Sentisec-Continuation-Refused` reason when the re-send was refused (409). */
|
|
607
|
+
refused?: string;
|
|
608
|
+
states: Record<string, string>;
|
|
609
|
+
/** How it completed: `in_band` (the reply waited) or `handle` (the helper re-sent). */
|
|
610
|
+
rung?: string;
|
|
611
|
+
/** The calls settled while the first reply waited. */
|
|
612
|
+
completed: CompletedCall[];
|
|
613
|
+
}
|
|
614
|
+
interface WaitOptions {
|
|
615
|
+
/** How long to wait for a decision (default 15 min; 0 reads once). */
|
|
616
|
+
waitMs?: number;
|
|
617
|
+
/** The app's own id for this task (a ticket id), sent as `x-session-id`. */
|
|
618
|
+
sessionId?: string;
|
|
619
|
+
}
|
|
620
|
+
type Create<B, T> = (body: B, options: {
|
|
621
|
+
headers: Record<string, string>;
|
|
622
|
+
}) => Promise<T>;
|
|
623
|
+
/** The plane's root for a client base URL (`…/ws/<id>/v1`, `…/v1/proxy/openai`). */
|
|
624
|
+
declare function planeOrigin(baseUrl: string): string;
|
|
625
|
+
/** The refusal reason when `err` is the plane's 409 for a handle (SDK error or a Response). */
|
|
626
|
+
declare function refusalOf(err: unknown): string | undefined;
|
|
627
|
+
declare class Approvals {
|
|
628
|
+
private readonly origin;
|
|
629
|
+
private readonly apiKey;
|
|
630
|
+
private readonly application;
|
|
631
|
+
private readonly pollMs;
|
|
632
|
+
/** `apiKey` must be the key that sent the call; `endpoint` the plane root. */
|
|
633
|
+
constructor(opts: {
|
|
634
|
+
apiKey: string;
|
|
635
|
+
endpoint: string;
|
|
636
|
+
application?: string;
|
|
637
|
+
pollMs?: number;
|
|
638
|
+
});
|
|
639
|
+
/** From an OpenAI / Anthropic client already pointed at Sentisec. */
|
|
640
|
+
static fromClient(client: {
|
|
641
|
+
apiKey: string;
|
|
642
|
+
baseURL: string;
|
|
643
|
+
}, opts?: {
|
|
644
|
+
application?: string;
|
|
645
|
+
pollMs?: number;
|
|
646
|
+
}): Approvals;
|
|
647
|
+
private labels;
|
|
648
|
+
private read;
|
|
649
|
+
/** The held call's stored outcome now (one read). */
|
|
650
|
+
status(p: PendingApproval): Promise<string>;
|
|
651
|
+
/** Read every held call until none is still deciding, `waitMs` passes, or `signal` aborts. */
|
|
652
|
+
wait(pending: PendingApproval[], waitMs?: number, signal?: AbortSignal | null): Promise<Record<string, string>>;
|
|
653
|
+
private resend;
|
|
654
|
+
/** Send `body`; if a call is held, wait for its decision and re-send once (JSON, not streams). */
|
|
655
|
+
complete<B, T>(create: Create<B, T>, body: B, opts?: WaitOptions): Promise<ApprovalResult<T>>;
|
|
656
|
+
/** For stored calls: read their outcome (`waitMs` > 0 waits) and re-send `body` once if approved. */
|
|
657
|
+
resume<B, T>(create: Create<B, T>, pending: PendingApproval[], body: B, opts?: WaitOptions): Promise<ApprovalResult<T>>;
|
|
658
|
+
/**
|
|
659
|
+
* A `fetch` that completes held calls in place: a JSON answer holding a
|
|
660
|
+
* call waits for the decision and, once approved, the identical request
|
|
661
|
+
* is re-sent once with the handle; the caller receives the final answer.
|
|
662
|
+
* A reply held open by the plane (rung i) is read to its end first.
|
|
663
|
+
* `onPending` sees each held call (store it to resume after a restart).
|
|
664
|
+
*
|
|
665
|
+
* The whole wait runs inside one `fetch`, so the caller's deadline bounds
|
|
666
|
+
* it: openai-node's `timeout` (default 10 min) or an `AbortSignal`. When it
|
|
667
|
+
* aborts, the wait stops and the caller gets the held answer (the call
|
|
668
|
+
* still waits; `onPending` has its offer). Give the client at least
|
|
669
|
+
* `HOLD_TIMEOUT_MS` (60 s) so a held reply is read to its end.
|
|
670
|
+
*
|
|
671
|
+
* A stream answer passes through unchanged and live: the plane holds it
|
|
672
|
+
* open itself while a person decides inside the window (rung i), and the
|
|
673
|
+
* released call arrives in it under `<call_id>_ib`. Its comments are read
|
|
674
|
+
* on the way; a call still waiting when the stream ends goes to
|
|
675
|
+
* `onPending` (nothing is re-sent inside a stream the client already read).
|
|
676
|
+
*/
|
|
677
|
+
fetch(opts?: WaitOptions & {
|
|
678
|
+
onPending?: (p: PendingApproval[]) => void;
|
|
679
|
+
}, inner?: typeof fetch): typeof fetch;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* The renamed call: answer `sentisec_tool_call_blocked` with a short result, never run it.
|
|
684
|
+
*
|
|
685
|
+
* When the request declares tools, a call Sentisec did not let leave comes
|
|
686
|
+
* back under its own id, renamed `sentisec_tool_call_blocked`, with one
|
|
687
|
+
* argument, `reason`: a plain sentence (it waits for a person, a person
|
|
688
|
+
* declined it, or its arguments were unreadable). There is no tool by that
|
|
689
|
+
* name, so there is nothing to run. The app answers it like any other call
|
|
690
|
+
* with a short result; the plane replaces that result with its own ruling
|
|
691
|
+
* before the model reads it, so the model learns what happened in fixed
|
|
692
|
+
* words it can relay to a person unchanged.
|
|
693
|
+
*
|
|
694
|
+
* ```ts
|
|
695
|
+
* const message = completion.choices[0].message;
|
|
696
|
+
* messages.push(message);
|
|
697
|
+
* for (const call of message.tool_calls ?? []) {
|
|
698
|
+
* if (!isBlocked(call)) messages.push(await runMyTool(call)); // the app's own tools
|
|
699
|
+
* }
|
|
700
|
+
* messages.push(...blockedResults(completion)); // the renamed calls, answered
|
|
701
|
+
* ```
|
|
702
|
+
*
|
|
703
|
+
* Fetch-based frameworks (the AI SDK, Mastra) answer an unknown tool name
|
|
704
|
+
* with their own tool error, which the plane replaces the same way. The
|
|
705
|
+
* result text is fixed and short: no JSON, no id, no handle. The Python
|
|
706
|
+
* twin is `sentisec_sdk.approvals.blocked`.
|
|
707
|
+
*/
|
|
708
|
+
/** The name the plane gives a call it did not let leave (its id is kept). */
|
|
709
|
+
declare const BLOCKED_TOOL_NAME = "sentisec_tool_call_blocked";
|
|
710
|
+
/** What the helper answers a renamed call with; the plane puts its ruling in its place. */
|
|
711
|
+
declare const NOT_RUN_RESULT = "This action has not run.";
|
|
712
|
+
/** A renamed call in a response: answer it with `blockedResult`, never run it. */
|
|
713
|
+
interface BlockedCall {
|
|
714
|
+
callId: string;
|
|
715
|
+
/** The plane's sentence from the call's arguments (for the app's own log or screen). */
|
|
716
|
+
reason?: string;
|
|
717
|
+
wire: "chat" | "messages" | "responses";
|
|
718
|
+
}
|
|
719
|
+
/** Whether `call` (a Chat tool call, a `tool_use` block or a Responses `function_call`) is a renamed call. */
|
|
720
|
+
declare function isBlocked(call: unknown): boolean;
|
|
721
|
+
/** Every renamed call (`sentisec_tool_call_blocked`) in `response`, on any of the three wires. */
|
|
722
|
+
declare function blockedCalls(response: unknown): BlockedCall[];
|
|
723
|
+
/** The tool result entry answering one renamed call, in its wire's shape (short, fixed text). */
|
|
724
|
+
declare function blockedResult(call: BlockedCall): Record<string, unknown>;
|
|
725
|
+
/**
|
|
726
|
+
* The tool results answering every renamed call in `response`. Chat: append them as
|
|
727
|
+
* messages; Messages: put them in the next user turn's content; Responses: add them to
|
|
728
|
+
* the next `input`. The app runs its other calls as usual and never this one.
|
|
729
|
+
*/
|
|
730
|
+
declare function blockedResults(response: unknown): Array<Record<string, unknown>>;
|
|
731
|
+
|
|
384
732
|
/**
|
|
385
733
|
* @sentisec/sdk — TypeScript SDK public surface.
|
|
386
734
|
*
|
|
@@ -514,4 +862,4 @@ declare class Monitor {
|
|
|
514
862
|
session(): Session;
|
|
515
863
|
}
|
|
516
864
|
|
|
517
|
-
export { type AnthropicContentBlock, type AnthropicInputMessage, type AnthropicLike, type AnthropicMessageCreateParams, type AnthropicMessageResponse, type AnthropicStreamEvent, type AnthropicStreamingLike, type AnthropicTextBlock, type AnthropicToolUseBlock, BUILTIN_POLICIES, type BuiltinPolicy, DEFAULT_ENDPOINT, DEFAULT_INGRESS_TEMPLATE, ENV_ENDPOINT, Monitor, type MonitorConfig, type OpenAILike, type OpenAIStreamChunk, type OpenAIStreamingLike, type ResponsePolicy, SentisecAnthropicBlockError, SentisecError, type SentisecHaltEnvelope, SentisecHijackError, Session, type SessionStatus, type StreamCloseReason, type StreamOptions, TaskTamperError, UnknownPolicyError, type Verdict, type VerdictValue, VerifierBackendNotConfigured, WORKSPACE_PROXY_PATH, type WrapOptions, Monitor as default, resolveProxyBaseUrl, wrapAnthropicStream, wrapOpenAIStream };
|
|
865
|
+
export { APPLICATION_HEADER, type AnthropicContentBlock, type AnthropicInputMessage, type AnthropicLike, type AnthropicMessageCreateParams, type AnthropicMessageResponse, type AnthropicStreamEvent, type AnthropicStreamingLike, type AnthropicTextBlock, type AnthropicToolUseBlock, type ApprovalResult, Approvals, BLOCKED_TOOL_NAME, BUILTIN_POLICIES, type BlockedCall, type BuiltinPolicy, CONTINUATION_HEADER, type CompletedCall, DEFAULT_ENDPOINT, DEFAULT_INGRESS_TEMPLATE, ENV_ENDPOINT, HOLD_TIMEOUT_MS, IN_BAND_HEADER, Monitor, type MonitorConfig, NOT_RUN_RESULT, type OpenAILike, type OpenAIStreamChunk, type OpenAIStreamingLike, type PendingApproval, REFUSED_HEADER, type ResponsePolicy, SESSION_HEADER, SentisecAnthropicBlockError, SentisecError, type SentisecHaltEnvelope, SentisecHijackError, SentisecStreamError, Session, type SessionStatus, SseVerdicts, type StreamCloseReason, type StreamOptions, TaskTamperError, UnknownPolicyError, type Verdict, type VerdictValue, VerifierBackendNotConfigured, WORKSPACE_PROXY_PATH, type WaitOptions, type WrapOptions, blockedCalls, blockedResult, blockedResults, completedCalls, completedFromSse, Monitor as default, isBlocked, pendingApprovals, pendingFromSse, planeOrigin, refusalOf, resolveProxyBaseUrl, wrapAnthropicStream, wrapOpenAIStream };
|