@sentisec/sdk 0.1.0-rc.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/dist/index.js ADDED
@@ -0,0 +1,741 @@
1
+ // src/errors.ts
2
+ var SentisecHijackError = class extends Error {
3
+ sessionId;
4
+ detail;
5
+ constructor(sessionId, detail) {
6
+ const base = `Sentisec HALT for session ${JSON.stringify(sessionId)}.`;
7
+ super(detail !== void 0 ? `${base} ${detail}` : base);
8
+ this.name = "SentisecHijackError";
9
+ this.sessionId = sessionId;
10
+ this.detail = detail;
11
+ Object.setPrototypeOf(this, new.target.prototype);
12
+ }
13
+ };
14
+
15
+ // src/openai.ts
16
+ var DEFAULT_INGRESS_TEMPLATE = "https://ingress.sentisec.ch/ws/{workspace}/v1";
17
+ function resolveProxyBaseUrl(workspace, opts) {
18
+ if (opts?.baseUrl !== void 0) return opts.baseUrl;
19
+ return DEFAULT_INGRESS_TEMPLATE.replace("{workspace}", workspace);
20
+ }
21
+
22
+ // src/wrap-openai.ts
23
+ function isOpenAILike(client) {
24
+ if (client === null || typeof client !== "object") return false;
25
+ const c = client;
26
+ if (typeof c.baseURL !== "string") return false;
27
+ if (typeof c.defaultHeaders !== "object" || c.defaultHeaders === null) return false;
28
+ const chat = c.chat;
29
+ if (chat === void 0 || chat.completions === void 0) return false;
30
+ if (typeof chat.completions.create !== "function") return false;
31
+ return true;
32
+ }
33
+ function isHaltBody(body) {
34
+ if (body === null || typeof body !== "object") return false;
35
+ const b = body;
36
+ return b.verdict === "HIJACK" && typeof b.session_id === "string";
37
+ }
38
+ function wrapOpenAI(client, ctx, opts) {
39
+ if (!isOpenAILike(client)) {
40
+ throw new Error(
41
+ "wrap-openai: client failed isOpenAILike() but the OpenAI adapter was selected \u2014 vendor-registry mismatch."
42
+ );
43
+ }
44
+ const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts);
45
+ client.baseURL = proxyBaseUrl;
46
+ client.defaultHeaders = {
47
+ ...client.defaultHeaders,
48
+ "x-sentisec-session-id": ctx.sessionId
49
+ };
50
+ const originalCreate = client.chat.completions.create.bind(client.chat.completions);
51
+ client.chat.completions.create = async (params) => {
52
+ try {
53
+ return await originalCreate(params);
54
+ } catch (err) {
55
+ const halt = await tryReadHaltBody(err);
56
+ if (halt !== null) {
57
+ throw new SentisecHijackError(halt.session_id, halt.detail);
58
+ }
59
+ throw err;
60
+ }
61
+ };
62
+ return client;
63
+ }
64
+ async function tryReadHaltBody(err) {
65
+ if (err === null || typeof err !== "object") return null;
66
+ const e = err;
67
+ for (const candidate of [e.error, e.body]) {
68
+ if (isHaltBody(candidate)) return candidate;
69
+ }
70
+ if (e.response !== void 0 && typeof e.response.json === "function") {
71
+ try {
72
+ const parsed = await e.response.json();
73
+ if (isHaltBody(parsed)) return parsed;
74
+ } catch {
75
+ }
76
+ }
77
+ return null;
78
+ }
79
+ var openAIVendorEntry = {
80
+ name: "openai",
81
+ detect: isOpenAILike,
82
+ wrap: wrapOpenAI
83
+ };
84
+
85
+ // src/anthropic.ts
86
+ var SentisecAnthropicBlockError = class extends Error {
87
+ sessionId;
88
+ forensicId;
89
+ row;
90
+ intervention;
91
+ detail;
92
+ constructor(init) {
93
+ const base = `Sentisec HALT for Anthropic session ${JSON.stringify(init.sessionId)}.`;
94
+ const tail = ` row=${init.row} forensic_id=${init.forensicId}`;
95
+ const message = init.detail !== void 0 ? `${base}${tail} ${init.detail}` : `${base}${tail}`;
96
+ super(message);
97
+ this.name = "SentisecAnthropicBlockError";
98
+ this.sessionId = init.sessionId;
99
+ this.forensicId = init.forensicId;
100
+ this.row = init.row;
101
+ this.intervention = init.intervention;
102
+ this.detail = init.detail;
103
+ Object.setPrototypeOf(this, new.target.prototype);
104
+ }
105
+ };
106
+
107
+ // src/wrap-anthropic.ts
108
+ function isAnthropicLike(client) {
109
+ if (client === null || typeof client !== "object") return false;
110
+ const c = client;
111
+ if (typeof c.baseURL !== "string") return false;
112
+ if (typeof c.defaultHeaders !== "object" || c.defaultHeaders === null) return false;
113
+ const messages = c.messages;
114
+ if (messages === void 0 || typeof messages.create !== "function") return false;
115
+ if (c.chat !== void 0 && c.chat.completions !== void 0 && typeof c.chat.completions.create === "function") {
116
+ return false;
117
+ }
118
+ return true;
119
+ }
120
+ function detectHaltEnvelope(response) {
121
+ if (typeof response !== "object" || response === null) return null;
122
+ const r = response;
123
+ const verdict = r["verdict"];
124
+ const intervention = r["intervention"];
125
+ const isHaltVerdict = verdict === "HIJACK" || verdict === "ABORT";
126
+ const isHaltIntervention = intervention === "HALT" || intervention === "ABORT";
127
+ if (!isHaltVerdict && !isHaltIntervention) return null;
128
+ const env = {
129
+ ...verdict === "HIJACK" || verdict === "ABORT" ? { verdict } : {},
130
+ ...intervention === "HALT" || intervention === "ABORT" ? { intervention } : {},
131
+ ...typeof r["session_id"] === "string" ? { session_id: r["session_id"] } : {},
132
+ ...typeof r["decision_table_version"] === "string" ? { decision_table_version: r["decision_table_version"] } : {},
133
+ ...typeof r["forensic_id"] === "string" ? { forensic_id: r["forensic_id"] } : {},
134
+ ...typeof r["row"] === "string" ? { row: r["row"] } : {},
135
+ ...typeof r["detail"] === "string" ? { detail: r["detail"] } : {}
136
+ };
137
+ return env;
138
+ }
139
+ function buildBlockedResponse(fallbackSessionId, params, halt) {
140
+ const sessionId = halt.session_id ?? fallbackSessionId;
141
+ const toolUseId = `toolu_sentisec_${randomHex(12)}`;
142
+ const finalBlock = {
143
+ type: "tool_use",
144
+ id: toolUseId,
145
+ name: "sentisec_block",
146
+ input: {
147
+ sentisec_blocked: true,
148
+ intervention: halt.intervention ?? "HALT",
149
+ forensic_id: halt.forensic_id ?? "",
150
+ row: halt.row ?? "",
151
+ decision_table_version: halt.decision_table_version ?? "v1.0-phase1",
152
+ ...halt.detail !== void 0 ? { detail: halt.detail } : {}
153
+ }
154
+ };
155
+ return {
156
+ id: `msg_${sessionId}_blocked`,
157
+ type: "message",
158
+ role: "assistant",
159
+ model: params.model,
160
+ content: [finalBlock],
161
+ stop_reason: "tool_use"
162
+ };
163
+ }
164
+ function tryRescueHaltEnvelopeFromError(err) {
165
+ if (typeof err !== "object" || err === null) return null;
166
+ const e = err;
167
+ for (const key of ["error", "body", "response"]) {
168
+ const candidate = e[key];
169
+ if (candidate !== void 0) {
170
+ const halt = detectHaltEnvelope(candidate);
171
+ if (halt !== null) return halt;
172
+ }
173
+ }
174
+ return null;
175
+ }
176
+ function randomHex(n) {
177
+ let out = "";
178
+ for (let i = 0; i < n; i += 1) {
179
+ out += Math.floor(Math.random() * 16).toString(16);
180
+ }
181
+ return out;
182
+ }
183
+ function wrapAnthropic(client, ctx, opts) {
184
+ if (!isAnthropicLike(client)) {
185
+ throw new Error(
186
+ "wrap-anthropic: client failed isAnthropicLike() but the Anthropic adapter was selected \u2014 vendor-registry mismatch."
187
+ );
188
+ }
189
+ const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts);
190
+ client.baseURL = proxyBaseUrl;
191
+ client.defaultHeaders = {
192
+ ...client.defaultHeaders,
193
+ "x-sentisec-session-id": ctx.sessionId
194
+ };
195
+ const onBlock = opts?.onBlock ?? "gated_return";
196
+ const originalCreate = client.messages.create.bind(client.messages);
197
+ client.messages.create = async (params) => {
198
+ let response;
199
+ try {
200
+ response = await originalCreate(params);
201
+ } catch (err) {
202
+ const rescued = tryRescueHaltEnvelopeFromError(err);
203
+ if (rescued !== null) {
204
+ response = rescued;
205
+ } else {
206
+ throw err;
207
+ }
208
+ }
209
+ const halt = detectHaltEnvelope(response);
210
+ if (halt !== null) {
211
+ if (onBlock === "throw") {
212
+ throw new SentisecAnthropicBlockError({
213
+ sessionId: halt.session_id ?? ctx.sessionId,
214
+ forensicId: halt.forensic_id ?? "",
215
+ row: halt.row ?? "",
216
+ intervention: halt.intervention ?? "HALT",
217
+ ...halt.detail !== void 0 ? { detail: halt.detail } : {}
218
+ });
219
+ }
220
+ return buildBlockedResponse(ctx.sessionId, params, halt);
221
+ }
222
+ return response;
223
+ };
224
+ return client;
225
+ }
226
+ var anthropicVendorEntry = {
227
+ name: "anthropic",
228
+ detect: isAnthropicLike,
229
+ wrap: wrapAnthropic
230
+ };
231
+
232
+ // src/monitor.ts
233
+ var registry = [];
234
+ function register(entry) {
235
+ if (registry.some((e) => e.name === entry.name)) return;
236
+ registry.push(entry);
237
+ }
238
+ register(openAIVendorEntry);
239
+ register(anthropicVendorEntry);
240
+ function newSessionId() {
241
+ const hex = globalThis.crypto.randomUUID().replace(/-/g, "");
242
+ return `ses_${hex.slice(0, 16)}`;
243
+ }
244
+ function installWrap(MonitorCtor) {
245
+ MonitorCtor.prototype.wrap = function(client, opts) {
246
+ const ctx = {
247
+ workspace: this.customerId,
248
+ sessionId: newSessionId(),
249
+ apiKey: this.apiKey,
250
+ model: this.model,
251
+ task: this.task,
252
+ policy: this.policy
253
+ };
254
+ for (const entry of registry) {
255
+ if (entry.detect(client)) {
256
+ return entry.wrap(client, ctx, opts);
257
+ }
258
+ }
259
+ throw new Error(
260
+ `Monitor.wrap: no registered vendor adapter matched the client. Registered vendors: [${registry.map((e) => e.name).join(", ")}]. OpenAI shape requires {baseURL, defaultHeaders, chat.completions.create}; Anthropic support lands with T-152.`
261
+ );
262
+ };
263
+ }
264
+
265
+ // src/streaming.ts
266
+ function parseSSEChunk(raw) {
267
+ const events = [];
268
+ const lines = raw.split("\n");
269
+ let currentEvent;
270
+ let currentData = [];
271
+ for (const line of lines) {
272
+ if (line.startsWith(":")) {
273
+ continue;
274
+ }
275
+ if (line.trim() === "") {
276
+ if (currentData.length > 0) {
277
+ events.push({
278
+ ...currentEvent !== void 0 ? { event: currentEvent } : {},
279
+ data: currentData.join("\n")
280
+ });
281
+ }
282
+ currentEvent = void 0;
283
+ currentData = [];
284
+ continue;
285
+ }
286
+ const colonIdx = line.indexOf(":");
287
+ if (colonIdx === -1) {
288
+ if (line === "data") currentData.push("");
289
+ continue;
290
+ }
291
+ const field = line.slice(0, colonIdx);
292
+ const value = line.slice(colonIdx + 1).replace(/^ /, "");
293
+ if (field === "data") {
294
+ currentData.push(value);
295
+ } else if (field === "event") {
296
+ currentEvent = value;
297
+ }
298
+ }
299
+ if (currentData.length > 0) {
300
+ events.push({
301
+ ...currentEvent !== void 0 ? { event: currentEvent } : {},
302
+ data: currentData.join("\n")
303
+ });
304
+ }
305
+ return events;
306
+ }
307
+ function abortPromise(signal) {
308
+ const p = new Promise((_resolve, reject) => {
309
+ if (signal.aborted) {
310
+ reject(new DOMException("Aborted", "AbortError"));
311
+ return;
312
+ }
313
+ signal.addEventListener(
314
+ "abort",
315
+ () => reject(new DOMException("Aborted", "AbortError")),
316
+ { once: true }
317
+ );
318
+ });
319
+ p.catch(() => void 0);
320
+ return p;
321
+ }
322
+ async function* readSSEStream(response, signal) {
323
+ const body = response.body;
324
+ if (body === null) {
325
+ yield { type: "done" };
326
+ return;
327
+ }
328
+ const reader = body.getReader();
329
+ const decoder = new TextDecoder();
330
+ let buffer = "";
331
+ const abortRace = signal !== void 0 ? abortPromise(signal) : null;
332
+ try {
333
+ while (true) {
334
+ if (signal?.aborted === true) {
335
+ reader.cancel().catch(() => void 0);
336
+ yield { type: "aborted" };
337
+ return;
338
+ }
339
+ let done;
340
+ let value;
341
+ try {
342
+ const readPromise = reader.read();
343
+ const result = abortRace !== null ? await Promise.race([readPromise, abortRace]) : await readPromise;
344
+ done = result.done;
345
+ value = result.value;
346
+ } catch (err) {
347
+ const isAbort = err instanceof DOMException && err.name === "AbortError" || !!signal?.aborted;
348
+ if (isAbort) {
349
+ reader.cancel().catch(() => void 0);
350
+ yield { type: "aborted" };
351
+ return;
352
+ }
353
+ throw err;
354
+ }
355
+ if (done) {
356
+ if (buffer.trim().length > 0) {
357
+ const events2 = parseSSEChunk(buffer + "\n\n");
358
+ for (const ev of events2) {
359
+ if (ev.data === "[DONE]") {
360
+ yield { type: "done" };
361
+ return;
362
+ }
363
+ try {
364
+ yield { type: "data", payload: JSON.parse(ev.data) };
365
+ } catch {
366
+ }
367
+ }
368
+ }
369
+ yield { type: "done" };
370
+ return;
371
+ }
372
+ if (value !== void 0) {
373
+ buffer += decoder.decode(value, { stream: true });
374
+ }
375
+ const splitIdx = buffer.lastIndexOf("\n\n");
376
+ if (splitIdx === -1) continue;
377
+ const complete = buffer.slice(0, splitIdx + 2);
378
+ buffer = buffer.slice(splitIdx + 2);
379
+ const events = parseSSEChunk(complete);
380
+ for (const ev of events) {
381
+ if (ev.data === "[DONE]") {
382
+ yield { type: "done" };
383
+ return;
384
+ }
385
+ try {
386
+ yield { type: "data", payload: JSON.parse(ev.data) };
387
+ } catch {
388
+ }
389
+ }
390
+ }
391
+ } finally {
392
+ reader.releaseLock();
393
+ }
394
+ }
395
+ async function collectSSEEvents(response, signal) {
396
+ const events = [];
397
+ const gen = readSSEStream(response, signal);
398
+ for await (const ev of gen) {
399
+ events.push(ev);
400
+ if (ev.type === "done" || ev.type === "aborted") break;
401
+ }
402
+ return events;
403
+ }
404
+ function isOpenAIHaltChunk(chunk) {
405
+ if (typeof chunk !== "object" || chunk === null) return false;
406
+ const c = chunk;
407
+ const choices = c.choices;
408
+ if (!Array.isArray(choices) || choices.length === 0) return false;
409
+ const first = choices[0];
410
+ if (first === void 0) return false;
411
+ return first.finish_reason === "sentisec_halted";
412
+ }
413
+ function wrapOpenAIStream(client, sessionId, opts) {
414
+ const originalCreate = client.chat.completions.create.bind(client.chat.completions);
415
+ client.chat.completions.create = async function(params) {
416
+ if (params.stream !== true) {
417
+ return originalCreate(params);
418
+ }
419
+ const url = `${client.baseURL}/chat/completions`;
420
+ const headers = {
421
+ "content-type": "application/json",
422
+ accept: "text/event-stream",
423
+ ...client.defaultHeaders
424
+ };
425
+ const abortController = new AbortController();
426
+ if (opts?.signal !== void 0) {
427
+ opts.signal.addEventListener("abort", () => abortController.abort(), { once: true });
428
+ }
429
+ const response = await globalThis.fetch(url, {
430
+ method: "POST",
431
+ headers,
432
+ body: JSON.stringify(params),
433
+ signal: abortController.signal
434
+ });
435
+ const rawEvents = await collectSSEEvents(response, opts?.signal);
436
+ const chunks = [];
437
+ let aborted = false;
438
+ for (const ev of rawEvents) {
439
+ if (ev.type === "aborted") {
440
+ aborted = true;
441
+ break;
442
+ }
443
+ if (ev.type === "done") break;
444
+ if (ev.type === "data") {
445
+ chunks.push(ev.payload);
446
+ }
447
+ }
448
+ const output = [];
449
+ if (aborted) {
450
+ for (const chunk of chunks) {
451
+ output.push(chunk);
452
+ }
453
+ const closedChunk = {
454
+ id: `sentisec_closed_${sessionId}`,
455
+ object: "chat.completion.chunk",
456
+ choices: [{ index: 0, delta: {}, finish_reason: "session_closed" }],
457
+ sentisec: {
458
+ verdict: "ABORT",
459
+ session_id: sessionId,
460
+ detail: "stream aborted by consumer"
461
+ }
462
+ };
463
+ output.push(closedChunk);
464
+ } else {
465
+ const lastIdx = chunks.length - 1;
466
+ const lastChunk = chunks[lastIdx];
467
+ for (let i = 0; i < chunks.length; i++) {
468
+ const chunk = chunks[i];
469
+ if (chunk === void 0) continue;
470
+ if (i === lastIdx && !isOpenAIHaltChunk(chunk)) {
471
+ const withVerdict = Object.assign({}, chunk, {
472
+ sentisec: { verdict: "PASS", session_id: sessionId }
473
+ });
474
+ output.push(withVerdict);
475
+ } else if (isOpenAIHaltChunk(chunk)) {
476
+ output.push(chunk);
477
+ break;
478
+ } else {
479
+ output.push(chunk);
480
+ }
481
+ if (lastChunk !== void 0 && isOpenAIHaltChunk(lastChunk) && i === lastIdx) {
482
+ break;
483
+ }
484
+ }
485
+ }
486
+ let idx = 0;
487
+ return {
488
+ [Symbol.asyncIterator]() {
489
+ return {
490
+ next() {
491
+ if (idx < output.length) {
492
+ const chunk = output[idx];
493
+ idx += 1;
494
+ if (chunk !== void 0) {
495
+ return Promise.resolve({ done: false, value: chunk });
496
+ }
497
+ }
498
+ return Promise.resolve({
499
+ done: true,
500
+ value: void 0
501
+ });
502
+ },
503
+ return() {
504
+ abortController.abort();
505
+ idx = output.length;
506
+ return Promise.resolve({
507
+ done: true,
508
+ value: void 0
509
+ });
510
+ }
511
+ };
512
+ }
513
+ };
514
+ };
515
+ return client;
516
+ }
517
+ function isAnthropicHaltEvent(event) {
518
+ if (typeof event !== "object" || event === null) return false;
519
+ const e = event;
520
+ if (e["type"] !== "content_block_delta") return false;
521
+ const delta = e["delta"];
522
+ if (delta === void 0) return false;
523
+ return delta["type"] === "sentisec_halted";
524
+ }
525
+ function wrapAnthropicStream(client, sessionId, opts) {
526
+ const originalCreate = client.messages.create.bind(client.messages);
527
+ client.messages.create = async function(params) {
528
+ if (params.stream !== true) {
529
+ return originalCreate(params);
530
+ }
531
+ const url = `${client.baseURL}/messages`;
532
+ const headers = {
533
+ "content-type": "application/json",
534
+ accept: "text/event-stream",
535
+ "anthropic-version": "2023-06-01",
536
+ ...client.defaultHeaders
537
+ };
538
+ const abortController = new AbortController();
539
+ if (opts?.signal !== void 0) {
540
+ opts.signal.addEventListener("abort", () => abortController.abort(), { once: true });
541
+ }
542
+ const response = await globalThis.fetch(url, {
543
+ method: "POST",
544
+ headers,
545
+ body: JSON.stringify(params),
546
+ signal: abortController.signal
547
+ });
548
+ const rawEvents = await collectSSEEvents(response, opts?.signal);
549
+ const output = [];
550
+ let aborted = false;
551
+ for (const ev of rawEvents) {
552
+ if (ev.type === "aborted") {
553
+ aborted = true;
554
+ break;
555
+ }
556
+ if (ev.type === "done") break;
557
+ if (ev.type === "data") {
558
+ const anthropicEvent = ev.payload;
559
+ if (isAnthropicHaltEvent(anthropicEvent)) {
560
+ output.push(anthropicEvent);
561
+ break;
562
+ }
563
+ if (anthropicEvent.type === "message_stop") {
564
+ output.push({
565
+ ...anthropicEvent,
566
+ sentisec: { verdict: "PASS", session_id: sessionId }
567
+ });
568
+ } else {
569
+ output.push(anthropicEvent);
570
+ }
571
+ }
572
+ }
573
+ if (aborted) {
574
+ const closedEvent = {
575
+ type: "message_stop",
576
+ sentisec: {
577
+ verdict: "ABORT",
578
+ session_id: sessionId,
579
+ detail: "stream aborted by consumer"
580
+ }
581
+ };
582
+ output.push(closedEvent);
583
+ }
584
+ let idx = 0;
585
+ return {
586
+ [Symbol.asyncIterator]() {
587
+ return {
588
+ next() {
589
+ if (idx < output.length) {
590
+ const ev = output[idx];
591
+ idx += 1;
592
+ if (ev !== void 0) {
593
+ return Promise.resolve({ done: false, value: ev });
594
+ }
595
+ }
596
+ return Promise.resolve({
597
+ done: true,
598
+ value: void 0
599
+ });
600
+ },
601
+ return() {
602
+ abortController.abort();
603
+ idx = output.length;
604
+ return Promise.resolve({
605
+ done: true,
606
+ value: void 0
607
+ });
608
+ }
609
+ };
610
+ }
611
+ };
612
+ };
613
+ return client;
614
+ }
615
+
616
+ // src/index.ts
617
+ var SentisecError = class extends Error {
618
+ constructor(message) {
619
+ super(message);
620
+ this.name = "SentisecError";
621
+ Object.setPrototypeOf(this, new.target.prototype);
622
+ }
623
+ };
624
+ var UnknownPolicyError = class extends SentisecError {
625
+ policyName;
626
+ constructor(policyName, message) {
627
+ super(message ?? `Unknown policy: ${JSON.stringify(policyName)}`);
628
+ this.name = "UnknownPolicyError";
629
+ this.policyName = policyName;
630
+ Object.setPrototypeOf(this, new.target.prototype);
631
+ }
632
+ };
633
+ var VerifierBackendNotConfigured = class extends SentisecError {
634
+ hint;
635
+ constructor(hint) {
636
+ const base = "Verifier backend is not configured.";
637
+ super(hint !== void 0 ? `${base} ${hint}` : base);
638
+ this.name = "VerifierBackendNotConfigured";
639
+ this.hint = hint;
640
+ Object.setPrototypeOf(this, new.target.prototype);
641
+ }
642
+ };
643
+ var TaskTamperError = class extends SentisecError {
644
+ sessionId;
645
+ detail;
646
+ constructor(sessionId, detail) {
647
+ const base = `Task tamper detected for session ${JSON.stringify(sessionId)}.`;
648
+ super(detail !== void 0 ? `${base} ${detail}` : base);
649
+ this.name = "TaskTamperError";
650
+ this.sessionId = sessionId;
651
+ this.detail = detail;
652
+ Object.setPrototypeOf(this, new.target.prototype);
653
+ }
654
+ };
655
+ var BUILTIN_POLICIES = ["research_agent", "customer_support", "coding_agent"];
656
+ var Session = class {
657
+ sessionId;
658
+ customerId;
659
+ model;
660
+ task;
661
+ taskImmutableHash;
662
+ startedAt;
663
+ status;
664
+ constructor(init) {
665
+ this.sessionId = init.sessionId;
666
+ this.customerId = init.customerId;
667
+ this.model = init.model;
668
+ this.task = init.task;
669
+ this.taskImmutableHash = init.taskImmutableHash;
670
+ this.startedAt = /* @__PURE__ */ new Date();
671
+ this.status = "ACTIVE";
672
+ }
673
+ /**
674
+ * Wrap a provider SDK client so every request/response is monitored.
675
+ *
676
+ * T-151 (OpenAI) and T-152 (Anthropic) fill this in. Calling it at
677
+ * T-150 throws so downstream code can't accidentally ship against
678
+ * a silently-passthrough stub.
679
+ */
680
+ wrap(_client) {
681
+ throw new Error(
682
+ "Session.wrap lands with T-151 (OpenAI) and T-152 (Anthropic) in the wave-2 TS SDK cards."
683
+ );
684
+ }
685
+ /**
686
+ * Emit the hash-chained forensic bundle for this session. Lands with
687
+ * T-153 alongside the Python `export_forensic_bundle` parity work.
688
+ */
689
+ exportForensicBundle() {
690
+ throw new Error(
691
+ "Forensic bundle export lands with T-153: Session.exportForensicBundle lands with T-153."
692
+ );
693
+ }
694
+ };
695
+ function isBuiltinPolicy(policy) {
696
+ return BUILTIN_POLICIES.includes(policy);
697
+ }
698
+ var Monitor = class {
699
+ apiKey;
700
+ model;
701
+ task;
702
+ policy;
703
+ responsePolicy;
704
+ customerId;
705
+ constructor(config) {
706
+ this.apiKey = config.apiKey;
707
+ this.model = config.model;
708
+ this.task = config.task;
709
+ this.policy = config.policy ?? "research_agent";
710
+ this.responsePolicy = config.responsePolicy ?? "gated";
711
+ this.customerId = config.customerId ?? "cust_local";
712
+ this.validatePolicy();
713
+ }
714
+ validatePolicy() {
715
+ if (isBuiltinPolicy(this.policy)) return;
716
+ if (this.policy.endsWith(".yaml")) return;
717
+ throw new UnknownPolicyError(
718
+ this.policy,
719
+ `policy ${JSON.stringify(this.policy)} is neither a built-in bundle (${JSON.stringify([...BUILTIN_POLICIES])}) nor a .yaml path.`
720
+ );
721
+ }
722
+ /**
723
+ * Start a new monitored session.
724
+ *
725
+ * T-153 fills in the sha256 task-hash computation + `_checkTaskIntegrity`
726
+ * parity. T-150 throws a `NotImplementedError`-shaped exception so
727
+ * accidental usage during wave-2 development does not silently
728
+ * produce a session with an empty hash.
729
+ */
730
+ session() {
731
+ throw new Error(
732
+ "Monitor.session() lands with T-153 (Session lifecycle parity \u2014 sha256 task-hash + __enter__/__exit__ analog)."
733
+ );
734
+ }
735
+ };
736
+ var src_default = Monitor;
737
+ Object.setPrototypeOf(SentisecHijackError.prototype, SentisecError.prototype);
738
+ Object.setPrototypeOf(SentisecAnthropicBlockError.prototype, SentisecError.prototype);
739
+ installWrap(Monitor);
740
+
741
+ export { BUILTIN_POLICIES, DEFAULT_INGRESS_TEMPLATE, Monitor, SentisecAnthropicBlockError, SentisecError, SentisecHijackError, Session, TaskTamperError, UnknownPolicyError, VerifierBackendNotConfigured, src_default as default, wrapAnthropicStream, wrapOpenAIStream };