@sentisec/sdk 0.1.0-rc.4 → 0.1.0-rc.5

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 CHANGED
@@ -6,6 +6,46 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ---
8
8
 
9
+ ## [Unreleased]
10
+
11
+ Closes the endpoint trap S1-FU-05 found on the Python side. A reader
12
+ running a local or self-hosted control plane had no way to say so:
13
+ `new Monitor({...})` always resolved to `https://api.sentisec.ch`, and
14
+ `wrap()` rewrote the client's `baseURL` unconditionally — so their
15
+ prompts left the machine. Python already had `Monitor(endpoint=...)`;
16
+ this brings the TypeScript SDK to parity.
17
+
18
+ ### Added
19
+
20
+ - `MonitorConfig.endpoint` — the control-plane HOST (e.g.
21
+ `http://localhost:8080`); `wrap()` appends `/ws/<workspace>/v1`.
22
+ Same field and semantics as the Python SDK's `Monitor(endpoint=...)`.
23
+ - `SENTISEC_ENDPOINT` env var support, matching the Python SDK.
24
+ - Exported `DEFAULT_ENDPOINT`, `ENV_ENDPOINT`, `WORKSPACE_PROXY_PATH`,
25
+ and `resolveProxyBaseUrl`.
26
+ - A one-line stderr warning when `wrap()` discards a base URL the caller
27
+ had deliberately set (anything that is not a stock provider URL), so a
28
+ client already pointed at Azure or a local vLLM is not silently
29
+ redirected. Naming the remedy in the message beats leaving it to be
30
+ found in a network trace.
31
+ - `tests/endpoint_resolution.test.ts` — 13 cases covering the
32
+ precedence chain, both vendors, and the warning's quiet cases.
33
+
34
+ ### Changed
35
+
36
+ - `resolveProxyBaseUrl(workspace, opts?, endpoint?)` takes a third
37
+ argument. Precedence is `opts.baseUrl` -> `endpoint` -> env -> hosted
38
+ default; the first two steps are unchanged for existing callers.
39
+ - README: the two non-streaming quickstarts pass `endpoint` explicitly,
40
+ with a warning that an unset endpoint means production and a note that
41
+ `wrap()` replaces the client's `baseURL`.
42
+
43
+ Behaviour with no endpoint set anywhere is deliberately unchanged — it
44
+ still resolves to the hosted plane. The fix is that an override now
45
+ exists and the docs stop implying one is unnecessary.
46
+
47
+ ---
48
+
9
49
  ## [0.1.0-rc.4] — 2026-05-17
10
50
 
11
51
  Routes the CLI binary fetch through the public Cloudflare R2 mirror
package/README.md CHANGED
@@ -22,6 +22,40 @@ Requires Node 20+.
22
22
 
23
23
  ---
24
24
 
25
+ ## Choose your control plane first
26
+
27
+ > **Warning — an unset endpoint means production.**
28
+ > `new Monitor({ ... })` with no `endpoint` sends every wrapped request
29
+ > to the hosted plane at `https://api.sentisec.ch`. If you are running
30
+ > Sentisec locally or self-hosted and you skip this, your prompts leave
31
+ > your machine. Set it explicitly; the SDK cannot infer your intent.
32
+
33
+ Resolution order, highest first:
34
+
35
+ 1. `wrap(client, { baseUrl })` — a literal, fully-formed URL for one
36
+ wrap call. Nothing is appended to it.
37
+ 2. `new Monitor({ endpoint })` — a control-plane **host**; the SDK
38
+ appends `/ws/<workspace>/v1`.
39
+ 3. `SENTISEC_ENDPOINT` — same host semantics, from the environment.
40
+ 4. the hosted default, `https://api.sentisec.ch`.
41
+
42
+ ```bash
43
+ # Local or self-hosted: set this once and both SDKs obey it.
44
+ export SENTISEC_ENDPOINT=http://localhost:8080
45
+ ```
46
+
47
+ Identical field, identical precedence, identical failure mode as the
48
+ Python SDK's `Monitor(endpoint=...)`.
49
+
50
+ **`wrap()` replaces your client's `baseURL`.** That is what the wrapper
51
+ is for — traffic has to go through Sentisec to be gated. But if your
52
+ client already pointed at Azure, a local vLLM, or another gateway, that
53
+ destination is discarded, and the SDK prints a one-line warning naming
54
+ the remedy. Route the upstream through Sentisec rather than setting it
55
+ on the client.
56
+
57
+ ---
58
+
25
59
  ## Quick start — OpenAI (non-streaming)
26
60
 
27
61
  ```ts
@@ -35,6 +69,9 @@ const monitor = new Monitor({
35
69
  policy: "research_agent",
36
70
  responsePolicy: "gated",
37
71
  customerId: "ws_acme",
72
+ // Explicit on purpose — omit it and this snippet targets the hosted
73
+ // plane. Point it at your own control plane when self-hosting.
74
+ endpoint: process.env.SENTISEC_ENDPOINT ?? "https://api.sentisec.ch",
38
75
  });
39
76
 
40
77
  // Wraps the OpenAI client in place — type is preserved.
@@ -71,6 +108,7 @@ const monitor = new Monitor({
71
108
  task: "answer customer support tickets",
72
109
  policy: "customer_support",
73
110
  customerId: "ws_support",
111
+ endpoint: process.env.SENTISEC_ENDPOINT ?? "https://api.sentisec.ch",
74
112
  });
75
113
 
76
114
  const anthropic = monitor.wrap(new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }));
@@ -228,7 +266,7 @@ pinned at `sdk_error_surface_version: v1.0-phase1`.
228
266
  ```bash
229
267
  pnpm install # from repo root
230
268
  pnpm --filter @sentisec/sdk build # tsup → dist/
231
- pnpm --filter @sentisec/sdk test # vitest (23 tests)
269
+ pnpm --filter @sentisec/sdk test # vitest (36 tests)
232
270
  pnpm --filter @sentisec/sdk typecheck
233
271
  ```
234
272
 
package/dist/index.cjs CHANGED
@@ -17,9 +17,44 @@ var SentisecHijackError = class extends Error {
17
17
  };
18
18
 
19
19
  // src/openai.ts
20
+ var ENV_ENDPOINT = "SENTISEC_ENDPOINT";
21
+ var DEFAULT_ENDPOINT = "https://api.sentisec.ch";
22
+ var WORKSPACE_PROXY_PATH = "/ws/{workspace}/v1";
23
+ function endpointFromEnv() {
24
+ const env = globalThis.process?.env;
25
+ const raw = env?.[ENV_ENDPOINT];
26
+ return raw !== void 0 && raw.trim() !== "" ? raw.trim() : void 0;
27
+ }
28
+ function composeWorkspaceUrl(endpoint, workspace) {
29
+ return endpoint.replace(/\/+$/, "") + WORKSPACE_PROXY_PATH.replace("{workspace}", workspace);
30
+ }
31
+ var VENDOR_DEFAULT_BASE_URLS = /* @__PURE__ */ new Set([
32
+ "https://api.openai.com/v1",
33
+ "https://api.openai.com",
34
+ "https://api.anthropic.com/v1",
35
+ "https://api.anthropic.com"
36
+ ]);
37
+ function canonicalUrl(url) {
38
+ return url.trim().replace(/\/+$/, "");
39
+ }
40
+ function warnIfDiscardingExplicitBaseUrl(previous, next) {
41
+ if (typeof previous !== "string") return;
42
+ const before = canonicalUrl(previous);
43
+ if (before === "") return;
44
+ if (before === canonicalUrl(next)) return;
45
+ if (VENDOR_DEFAULT_BASE_URLS.has(before)) return;
46
+ console.warn(
47
+ `[sentisec] wrap() replaced the client's baseURL ${before} with ${next}. If that was deliberate, pass it through Sentisec instead \u2014 new Monitor({ endpoint }) for a Sentisec control plane on another host, or wrap(client, { baseUrl }) to target one wrap at a literal URL.`
48
+ );
49
+ }
20
50
  var DEFAULT_INGRESS_TEMPLATE = "https://api.sentisec.ch/ws/{workspace}/v1";
21
- function resolveProxyBaseUrl(workspace, opts) {
51
+ function resolveProxyBaseUrl(workspace, opts, endpoint) {
22
52
  if (opts?.baseUrl !== void 0) return opts.baseUrl;
53
+ if (endpoint !== void 0 && endpoint.trim() !== "") {
54
+ return composeWorkspaceUrl(endpoint.trim(), workspace);
55
+ }
56
+ const fromEnv = endpointFromEnv();
57
+ if (fromEnv !== void 0) return composeWorkspaceUrl(fromEnv, workspace);
23
58
  return DEFAULT_INGRESS_TEMPLATE.replace("{workspace}", workspace);
24
59
  }
25
60
 
@@ -45,7 +80,8 @@ function wrapOpenAI(client, ctx, opts) {
45
80
  "wrap-openai: client failed isOpenAILike() but the OpenAI adapter was selected \u2014 vendor-registry mismatch."
46
81
  );
47
82
  }
48
- const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts);
83
+ const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts, ctx.endpoint);
84
+ warnIfDiscardingExplicitBaseUrl(client.baseURL, proxyBaseUrl);
49
85
  client.baseURL = proxyBaseUrl;
50
86
  client.defaultHeaders = {
51
87
  ...client.defaultHeaders,
@@ -190,7 +226,8 @@ function wrapAnthropic(client, ctx, opts) {
190
226
  "wrap-anthropic: client failed isAnthropicLike() but the Anthropic adapter was selected \u2014 vendor-registry mismatch."
191
227
  );
192
228
  }
193
- const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts);
229
+ const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts, ctx.endpoint);
230
+ warnIfDiscardingExplicitBaseUrl(client.baseURL, proxyBaseUrl);
194
231
  client.baseURL = proxyBaseUrl;
195
232
  client.defaultHeaders = {
196
233
  ...client.defaultHeaders,
@@ -253,7 +290,8 @@ function installWrap(MonitorCtor) {
253
290
  apiKey: this.apiKey,
254
291
  model: this.model,
255
292
  task: this.task,
256
- policy: this.policy
293
+ policy: this.policy,
294
+ endpoint: this.endpoint
257
295
  };
258
296
  for (const entry of registry) {
259
297
  if (entry.detect(client)) {
@@ -706,6 +744,7 @@ var Monitor = class {
706
744
  policy;
707
745
  responsePolicy;
708
746
  customerId;
747
+ endpoint;
709
748
  constructor(config) {
710
749
  this.apiKey = config.apiKey;
711
750
  this.model = config.model;
@@ -713,6 +752,7 @@ var Monitor = class {
713
752
  this.policy = config.policy ?? "research_agent";
714
753
  this.responsePolicy = config.responsePolicy ?? "gated";
715
754
  this.customerId = config.customerId ?? "cust_local";
755
+ this.endpoint = config.endpoint;
716
756
  this.validatePolicy();
717
757
  }
718
758
  validatePolicy() {
@@ -743,7 +783,9 @@ Object.setPrototypeOf(SentisecAnthropicBlockError.prototype, SentisecError.proto
743
783
  installWrap(Monitor);
744
784
 
745
785
  exports.BUILTIN_POLICIES = BUILTIN_POLICIES;
786
+ exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
746
787
  exports.DEFAULT_INGRESS_TEMPLATE = DEFAULT_INGRESS_TEMPLATE;
788
+ exports.ENV_ENDPOINT = ENV_ENDPOINT;
747
789
  exports.Monitor = Monitor;
748
790
  exports.SentisecAnthropicBlockError = SentisecAnthropicBlockError;
749
791
  exports.SentisecError = SentisecError;
@@ -752,6 +794,8 @@ exports.Session = Session;
752
794
  exports.TaskTamperError = TaskTamperError;
753
795
  exports.UnknownPolicyError = UnknownPolicyError;
754
796
  exports.VerifierBackendNotConfigured = VerifierBackendNotConfigured;
797
+ exports.WORKSPACE_PROXY_PATH = WORKSPACE_PROXY_PATH;
755
798
  exports.default = src_default;
799
+ exports.resolveProxyBaseUrl = resolveProxyBaseUrl;
756
800
  exports.wrapAnthropicStream = wrapAnthropicStream;
757
801
  exports.wrapOpenAIStream = wrapOpenAIStream;
package/dist/index.d.cts CHANGED
@@ -61,6 +61,22 @@ interface OpenAILike {
61
61
  interface WrapOptions {
62
62
  baseUrl?: string;
63
63
  }
64
+ /**
65
+ * Environment variable naming the Sentisec control-plane host. Parity
66
+ * with the Python SDK's `SENTISEC_ENDPOINT` (`credentials.py`), so a
67
+ * self-hosted operator sets one variable and both SDKs obey it.
68
+ */
69
+ declare const ENV_ENDPOINT = "SENTISEC_ENDPOINT";
70
+ /**
71
+ * Hosted control-plane host, used when nothing overrides it. Parity
72
+ * with the Python SDK's `DEFAULT_ENDPOINT`.
73
+ */
74
+ declare const DEFAULT_ENDPOINT = "https://api.sentisec.ch";
75
+ /**
76
+ * Workspace-scoped proxy path appended to an endpoint host. The hosted
77
+ * default below is this path joined onto `DEFAULT_ENDPOINT`.
78
+ */
79
+ declare const WORKSPACE_PROXY_PATH = "/ws/{workspace}/v1";
64
80
  /**
65
81
  * The Sentisec hosted-ingress base URL template. The `{workspace}`
66
82
  * placeholder is substituted with `Monitor.customerId` at wrap
@@ -73,6 +89,30 @@ interface WrapOptions {
73
89
  * `test_wrap_rewrites_base_url` grep-guards the literal.
74
90
  */
75
91
  declare const DEFAULT_INGRESS_TEMPLATE = "https://api.sentisec.ch/ws/{workspace}/v1";
92
+ /**
93
+ * Resolve the proxy base URL for a given workspace.
94
+ *
95
+ * Precedence, highest first — mirroring the Python SDK's
96
+ * arg -> env -> default chain (`resolve_credentials`):
97
+ *
98
+ * 1. `opts.baseUrl` — a literal, fully-formed URL for this one
99
+ * wrap call. No path is appended.
100
+ * 2. `endpoint` — `new Monitor({ endpoint })`, a HOST
101
+ * (e.g. `http://localhost:8080`); the
102
+ * workspace path is appended to it.
103
+ * 3. `SENTISEC_ENDPOINT` — same host semantics, from the environment.
104
+ * 4. the hosted default — `https://api.sentisec.ch/ws/<ws>/v1`.
105
+ *
106
+ * Step 4 is the trap S1-FU-05 caught on the Python side: a reader
107
+ * running a local control plane who never set a destination had their
108
+ * prompts silently routed to production. The SDK cannot detect that
109
+ * intent, so the fix is to make steps 2 and 3 exist and to say so
110
+ * loudly in the docs — not to guess.
111
+ *
112
+ * Pure function so it can be unit-tested without constructing a
113
+ * `Monitor`.
114
+ */
115
+ declare function resolveProxyBaseUrl(workspace: string, opts?: WrapOptions, endpoint?: string): string;
76
116
 
77
117
  /**
78
118
  * @sentisec/sdk · monitor.ts — Monitor.wrap dispatcher (T-151).
@@ -582,6 +622,18 @@ interface MonitorConfig {
582
622
  policy?: string;
583
623
  responsePolicy?: ResponsePolicy;
584
624
  customerId?: string;
625
+ /**
626
+ * Sentisec control-plane HOST (e.g. `http://localhost:8080`), not a
627
+ * full URL — `wrap()` appends the workspace-scoped path.
628
+ *
629
+ * Set this whenever you are not talking to the hosted plane. Leaving
630
+ * it unset falls back to `SENTISEC_ENDPOINT` and then to
631
+ * `https://api.sentisec.ch`, which means a local or self-hosted
632
+ * deployment that forgets it ships its prompts to production. Same
633
+ * field, same precedence, same failure mode as the Python SDK's
634
+ * `Monitor(endpoint=...)`.
635
+ */
636
+ endpoint?: string;
585
637
  }
586
638
  /**
587
639
  * A monitored session handle. T-150 pins the shape; the wave-2 cards
@@ -638,6 +690,7 @@ declare class Monitor {
638
690
  readonly policy: string;
639
691
  readonly responsePolicy: ResponsePolicy;
640
692
  readonly customerId: string;
693
+ readonly endpoint: string | undefined;
641
694
  constructor(config: MonitorConfig);
642
695
  private validatePolicy;
643
696
  /**
@@ -651,4 +704,4 @@ declare class Monitor {
651
704
  session(): Session;
652
705
  }
653
706
 
654
- export { type AnthropicContentBlock, type AnthropicInputMessage, type AnthropicLike, type AnthropicMessageCreateParams, type AnthropicMessageResponse, type AnthropicStreamEvent, type AnthropicStreamingLike, type AnthropicTextBlock, type AnthropicToolUseBlock, BUILTIN_POLICIES, type BuiltinPolicy, DEFAULT_INGRESS_TEMPLATE, 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, type WrapOptions, Monitor as default, wrapAnthropicStream, wrapOpenAIStream };
707
+ 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 };
package/dist/index.d.ts CHANGED
@@ -61,6 +61,22 @@ interface OpenAILike {
61
61
  interface WrapOptions {
62
62
  baseUrl?: string;
63
63
  }
64
+ /**
65
+ * Environment variable naming the Sentisec control-plane host. Parity
66
+ * with the Python SDK's `SENTISEC_ENDPOINT` (`credentials.py`), so a
67
+ * self-hosted operator sets one variable and both SDKs obey it.
68
+ */
69
+ declare const ENV_ENDPOINT = "SENTISEC_ENDPOINT";
70
+ /**
71
+ * Hosted control-plane host, used when nothing overrides it. Parity
72
+ * with the Python SDK's `DEFAULT_ENDPOINT`.
73
+ */
74
+ declare const DEFAULT_ENDPOINT = "https://api.sentisec.ch";
75
+ /**
76
+ * Workspace-scoped proxy path appended to an endpoint host. The hosted
77
+ * default below is this path joined onto `DEFAULT_ENDPOINT`.
78
+ */
79
+ declare const WORKSPACE_PROXY_PATH = "/ws/{workspace}/v1";
64
80
  /**
65
81
  * The Sentisec hosted-ingress base URL template. The `{workspace}`
66
82
  * placeholder is substituted with `Monitor.customerId` at wrap
@@ -73,6 +89,30 @@ interface WrapOptions {
73
89
  * `test_wrap_rewrites_base_url` grep-guards the literal.
74
90
  */
75
91
  declare const DEFAULT_INGRESS_TEMPLATE = "https://api.sentisec.ch/ws/{workspace}/v1";
92
+ /**
93
+ * Resolve the proxy base URL for a given workspace.
94
+ *
95
+ * Precedence, highest first — mirroring the Python SDK's
96
+ * arg -> env -> default chain (`resolve_credentials`):
97
+ *
98
+ * 1. `opts.baseUrl` — a literal, fully-formed URL for this one
99
+ * wrap call. No path is appended.
100
+ * 2. `endpoint` — `new Monitor({ endpoint })`, a HOST
101
+ * (e.g. `http://localhost:8080`); the
102
+ * workspace path is appended to it.
103
+ * 3. `SENTISEC_ENDPOINT` — same host semantics, from the environment.
104
+ * 4. the hosted default — `https://api.sentisec.ch/ws/<ws>/v1`.
105
+ *
106
+ * Step 4 is the trap S1-FU-05 caught on the Python side: a reader
107
+ * running a local control plane who never set a destination had their
108
+ * prompts silently routed to production. The SDK cannot detect that
109
+ * intent, so the fix is to make steps 2 and 3 exist and to say so
110
+ * loudly in the docs — not to guess.
111
+ *
112
+ * Pure function so it can be unit-tested without constructing a
113
+ * `Monitor`.
114
+ */
115
+ declare function resolveProxyBaseUrl(workspace: string, opts?: WrapOptions, endpoint?: string): string;
76
116
 
77
117
  /**
78
118
  * @sentisec/sdk · monitor.ts — Monitor.wrap dispatcher (T-151).
@@ -582,6 +622,18 @@ interface MonitorConfig {
582
622
  policy?: string;
583
623
  responsePolicy?: ResponsePolicy;
584
624
  customerId?: string;
625
+ /**
626
+ * Sentisec control-plane HOST (e.g. `http://localhost:8080`), not a
627
+ * full URL — `wrap()` appends the workspace-scoped path.
628
+ *
629
+ * Set this whenever you are not talking to the hosted plane. Leaving
630
+ * it unset falls back to `SENTISEC_ENDPOINT` and then to
631
+ * `https://api.sentisec.ch`, which means a local or self-hosted
632
+ * deployment that forgets it ships its prompts to production. Same
633
+ * field, same precedence, same failure mode as the Python SDK's
634
+ * `Monitor(endpoint=...)`.
635
+ */
636
+ endpoint?: string;
585
637
  }
586
638
  /**
587
639
  * A monitored session handle. T-150 pins the shape; the wave-2 cards
@@ -638,6 +690,7 @@ declare class Monitor {
638
690
  readonly policy: string;
639
691
  readonly responsePolicy: ResponsePolicy;
640
692
  readonly customerId: string;
693
+ readonly endpoint: string | undefined;
641
694
  constructor(config: MonitorConfig);
642
695
  private validatePolicy;
643
696
  /**
@@ -651,4 +704,4 @@ declare class Monitor {
651
704
  session(): Session;
652
705
  }
653
706
 
654
- export { type AnthropicContentBlock, type AnthropicInputMessage, type AnthropicLike, type AnthropicMessageCreateParams, type AnthropicMessageResponse, type AnthropicStreamEvent, type AnthropicStreamingLike, type AnthropicTextBlock, type AnthropicToolUseBlock, BUILTIN_POLICIES, type BuiltinPolicy, DEFAULT_INGRESS_TEMPLATE, 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, type WrapOptions, Monitor as default, wrapAnthropicStream, wrapOpenAIStream };
707
+ 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 };
package/dist/index.js CHANGED
@@ -13,9 +13,44 @@ var SentisecHijackError = class extends Error {
13
13
  };
14
14
 
15
15
  // src/openai.ts
16
+ var ENV_ENDPOINT = "SENTISEC_ENDPOINT";
17
+ var DEFAULT_ENDPOINT = "https://api.sentisec.ch";
18
+ var WORKSPACE_PROXY_PATH = "/ws/{workspace}/v1";
19
+ function endpointFromEnv() {
20
+ const env = globalThis.process?.env;
21
+ const raw = env?.[ENV_ENDPOINT];
22
+ return raw !== void 0 && raw.trim() !== "" ? raw.trim() : void 0;
23
+ }
24
+ function composeWorkspaceUrl(endpoint, workspace) {
25
+ return endpoint.replace(/\/+$/, "") + WORKSPACE_PROXY_PATH.replace("{workspace}", workspace);
26
+ }
27
+ var VENDOR_DEFAULT_BASE_URLS = /* @__PURE__ */ new Set([
28
+ "https://api.openai.com/v1",
29
+ "https://api.openai.com",
30
+ "https://api.anthropic.com/v1",
31
+ "https://api.anthropic.com"
32
+ ]);
33
+ function canonicalUrl(url) {
34
+ return url.trim().replace(/\/+$/, "");
35
+ }
36
+ function warnIfDiscardingExplicitBaseUrl(previous, next) {
37
+ if (typeof previous !== "string") return;
38
+ const before = canonicalUrl(previous);
39
+ if (before === "") return;
40
+ if (before === canonicalUrl(next)) return;
41
+ if (VENDOR_DEFAULT_BASE_URLS.has(before)) return;
42
+ console.warn(
43
+ `[sentisec] wrap() replaced the client's baseURL ${before} with ${next}. If that was deliberate, pass it through Sentisec instead \u2014 new Monitor({ endpoint }) for a Sentisec control plane on another host, or wrap(client, { baseUrl }) to target one wrap at a literal URL.`
44
+ );
45
+ }
16
46
  var DEFAULT_INGRESS_TEMPLATE = "https://api.sentisec.ch/ws/{workspace}/v1";
17
- function resolveProxyBaseUrl(workspace, opts) {
47
+ function resolveProxyBaseUrl(workspace, opts, endpoint) {
18
48
  if (opts?.baseUrl !== void 0) return opts.baseUrl;
49
+ if (endpoint !== void 0 && endpoint.trim() !== "") {
50
+ return composeWorkspaceUrl(endpoint.trim(), workspace);
51
+ }
52
+ const fromEnv = endpointFromEnv();
53
+ if (fromEnv !== void 0) return composeWorkspaceUrl(fromEnv, workspace);
19
54
  return DEFAULT_INGRESS_TEMPLATE.replace("{workspace}", workspace);
20
55
  }
21
56
 
@@ -41,7 +76,8 @@ function wrapOpenAI(client, ctx, opts) {
41
76
  "wrap-openai: client failed isOpenAILike() but the OpenAI adapter was selected \u2014 vendor-registry mismatch."
42
77
  );
43
78
  }
44
- const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts);
79
+ const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts, ctx.endpoint);
80
+ warnIfDiscardingExplicitBaseUrl(client.baseURL, proxyBaseUrl);
45
81
  client.baseURL = proxyBaseUrl;
46
82
  client.defaultHeaders = {
47
83
  ...client.defaultHeaders,
@@ -186,7 +222,8 @@ function wrapAnthropic(client, ctx, opts) {
186
222
  "wrap-anthropic: client failed isAnthropicLike() but the Anthropic adapter was selected \u2014 vendor-registry mismatch."
187
223
  );
188
224
  }
189
- const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts);
225
+ const proxyBaseUrl = resolveProxyBaseUrl(ctx.workspace, opts, ctx.endpoint);
226
+ warnIfDiscardingExplicitBaseUrl(client.baseURL, proxyBaseUrl);
190
227
  client.baseURL = proxyBaseUrl;
191
228
  client.defaultHeaders = {
192
229
  ...client.defaultHeaders,
@@ -249,7 +286,8 @@ function installWrap(MonitorCtor) {
249
286
  apiKey: this.apiKey,
250
287
  model: this.model,
251
288
  task: this.task,
252
- policy: this.policy
289
+ policy: this.policy,
290
+ endpoint: this.endpoint
253
291
  };
254
292
  for (const entry of registry) {
255
293
  if (entry.detect(client)) {
@@ -702,6 +740,7 @@ var Monitor = class {
702
740
  policy;
703
741
  responsePolicy;
704
742
  customerId;
743
+ endpoint;
705
744
  constructor(config) {
706
745
  this.apiKey = config.apiKey;
707
746
  this.model = config.model;
@@ -709,6 +748,7 @@ var Monitor = class {
709
748
  this.policy = config.policy ?? "research_agent";
710
749
  this.responsePolicy = config.responsePolicy ?? "gated";
711
750
  this.customerId = config.customerId ?? "cust_local";
751
+ this.endpoint = config.endpoint;
712
752
  this.validatePolicy();
713
753
  }
714
754
  validatePolicy() {
@@ -738,4 +778,4 @@ Object.setPrototypeOf(SentisecHijackError.prototype, SentisecError.prototype);
738
778
  Object.setPrototypeOf(SentisecAnthropicBlockError.prototype, SentisecError.prototype);
739
779
  installWrap(Monitor);
740
780
 
741
- export { BUILTIN_POLICIES, DEFAULT_INGRESS_TEMPLATE, Monitor, SentisecAnthropicBlockError, SentisecError, SentisecHijackError, Session, TaskTamperError, UnknownPolicyError, VerifierBackendNotConfigured, src_default as default, wrapAnthropicStream, wrapOpenAIStream };
781
+ export { BUILTIN_POLICIES, DEFAULT_ENDPOINT, DEFAULT_INGRESS_TEMPLATE, ENV_ENDPOINT, Monitor, SentisecAnthropicBlockError, SentisecError, SentisecHijackError, Session, TaskTamperError, UnknownPolicyError, VerifierBackendNotConfigured, WORKSPACE_PROXY_PATH, src_default as default, resolveProxyBaseUrl, wrapAnthropicStream, wrapOpenAIStream };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentisec/sdk",
3
- "version": "0.1.0-rc.4",
3
+ "version": "0.1.0-rc.5",
4
4
  "description": "Sentisec TypeScript SDK — cognitive integrity monitoring for autonomous agents. Monitor + wrap(...) for OpenAI / Anthropic agent loops with SSE streaming support.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",