@shashu-ai/sdk 1.2.0 → 1.3.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/CHANGELOG.md +16 -0
- package/README.md +36 -5
- package/package.json +2 -2
- package/dist/_joiner-D_FGAaoc.d.cts +0 -38
- package/dist/_joiner-D_FGAaoc.d.ts +0 -38
- package/dist/chunk-CWC6GQTL.js +0 -800
- package/dist/chunk-K4ZIXS2U.js +0 -40
- package/dist/chunk-MLFWJAEH.js +0 -74
- package/dist/chunk-MZGHCDWX.js +0 -530
- package/dist/chunk-TI45NK2R.js +0 -71
- package/dist/chunk-YSAQRZFP.js +0 -343
- package/dist/index.cjs +0 -2580
- package/dist/index.d.cts +0 -748
- package/dist/index.d.ts +0 -748
- package/dist/index.js +0 -974
- package/dist/langchain-CoNoZ_vQ.d.cts +0 -322
- package/dist/langchain-D9Xo9IMm.d.ts +0 -322
- package/dist/middleware/anthropic.cjs +0 -930
- package/dist/middleware/anthropic.d.cts +0 -49
- package/dist/middleware/anthropic.d.ts +0 -49
- package/dist/middleware/anthropic.js +0 -10
- package/dist/middleware/google.cjs +0 -530
- package/dist/middleware/google.d.cts +0 -71
- package/dist/middleware/google.d.ts +0 -71
- package/dist/middleware/google.js +0 -9
- package/dist/middleware/langchain.cjs +0 -1342
- package/dist/middleware/langchain.d.cts +0 -3
- package/dist/middleware/langchain.d.ts +0 -3
- package/dist/middleware/langchain.js +0 -22
- package/dist/middleware/vercel-ai.cjs +0 -927
- package/dist/middleware/vercel-ai.d.cts +0 -70
- package/dist/middleware/vercel-ai.d.ts +0 -70
- package/dist/middleware/vercel-ai.js +0 -10
- package/dist/types-BQVfxZJP.d.cts +0 -448
- package/dist/types-BQVfxZJP.d.ts +0 -448
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { S as ShashuConfig } from '../types-BQVfxZJP.cjs';
|
|
2
|
-
import { F as FetchLike } from '../_joiner-D_FGAaoc.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Vercel AI SDK middleware: swap the provider to Shashu with one line.
|
|
6
|
-
*
|
|
7
|
-
* Use createOpenAI from @openai/api or the AI SDK's OpenAI provider, and point
|
|
8
|
-
* baseURL to your Shashu gateway. This ensures all LLM calls go through
|
|
9
|
-
* Shashu with workflow context for Shadow AI detection.
|
|
10
|
-
*
|
|
11
|
-
* Example:
|
|
12
|
-
*
|
|
13
|
-
* import { createOpenAI } from '@ai-sdk/openai';
|
|
14
|
-
* import { createShashuOpenAI } from '@shashu-ai/sdk/middleware/vercel-ai';
|
|
15
|
-
*
|
|
16
|
-
* const openai = createShashuOpenAI({
|
|
17
|
-
* baseUrl: process.env.SHASHU_BASE_URL!,
|
|
18
|
-
* apiKey: process.env.SHASHU_API_KEY,
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* // Then use `openai` with streamText() as usual — requests go through Shashu.
|
|
22
|
-
* const result = streamText({ model: openai('gpt-4'), messages, ... });
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
interface ShashuOpenAIOptions extends ShashuConfig {
|
|
26
|
-
/**
|
|
27
|
-
* Optional OpenAI-compatible API key (if your gateway expects it in addition to Shashu key).
|
|
28
|
-
*/
|
|
29
|
-
openaiApiKey?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Returns extra headers (lowercase keys) to pass to the Vercel AI SDK OpenAI provider
|
|
33
|
-
* so that requests sent to Shashu include workflow context and x-shashu-source-tool
|
|
34
|
-
* JSON for Shadow AI detection. Use with createOpenAI({ baseURL, headers: getShashuHeaders() }).
|
|
35
|
-
*/
|
|
36
|
-
declare function getShashuHeaders(workflowContext?: ShashuConfig['workflowContext'], sessionId?: string, contractVersion?: ShashuConfig['contractVersion']): Record<string, string>;
|
|
37
|
-
/**
|
|
38
|
-
* Creates options suitable for the Vercel AI SDK's OpenAI provider so that
|
|
39
|
-
* you can swap the provider to Shashu in one line.
|
|
40
|
-
*
|
|
41
|
-
* Usage with AI SDK 3.x:
|
|
42
|
-
*
|
|
43
|
-
* import { createOpenAI } from '@ai-sdk/openai';
|
|
44
|
-
* import { createShashuOpenAIOptions } from '@shashu-ai/sdk/middleware/vercel-ai';
|
|
45
|
-
*
|
|
46
|
-
* const openaiOptions = createShashuOpenAIOptions({
|
|
47
|
-
* baseUrl: process.env.SHASHU_BASE_URL!,
|
|
48
|
-
* apiKey: process.env.SHASHU_API_KEY,
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* const openai = createOpenAI(openaiOptions);
|
|
52
|
-
* // use openai('gpt-4') with streamText()
|
|
53
|
-
*
|
|
54
|
-
* Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
|
|
55
|
-
* exactly as it was — its own endpoint, its own credential, no Shashu context
|
|
56
|
-
* headers — which is the same no-op the Python SDK's patchers perform. The
|
|
57
|
-
* caller's shashu_sk_ key is deliberately NOT handed back, since it would be sent to
|
|
58
|
-
* the provider directly.
|
|
59
|
-
*
|
|
60
|
-
* @throws {ShashuConfigError} when no address is configured and the SDK is
|
|
61
|
-
* not disabled. There is no default host. See ../config.ts.
|
|
62
|
-
*/
|
|
63
|
-
declare function createShashuOpenAIOptions(options: ShashuOpenAIOptions): {
|
|
64
|
-
baseURL?: string;
|
|
65
|
-
apiKey?: string;
|
|
66
|
-
headers?: Record<string, string>;
|
|
67
|
-
fetch?: FetchLike;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export { type ShashuOpenAIOptions, createShashuOpenAIOptions, getShashuHeaders };
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { S as ShashuConfig } from '../types-BQVfxZJP.js';
|
|
2
|
-
import { F as FetchLike } from '../_joiner-D_FGAaoc.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Vercel AI SDK middleware: swap the provider to Shashu with one line.
|
|
6
|
-
*
|
|
7
|
-
* Use createOpenAI from @openai/api or the AI SDK's OpenAI provider, and point
|
|
8
|
-
* baseURL to your Shashu gateway. This ensures all LLM calls go through
|
|
9
|
-
* Shashu with workflow context for Shadow AI detection.
|
|
10
|
-
*
|
|
11
|
-
* Example:
|
|
12
|
-
*
|
|
13
|
-
* import { createOpenAI } from '@ai-sdk/openai';
|
|
14
|
-
* import { createShashuOpenAI } from '@shashu-ai/sdk/middleware/vercel-ai';
|
|
15
|
-
*
|
|
16
|
-
* const openai = createShashuOpenAI({
|
|
17
|
-
* baseUrl: process.env.SHASHU_BASE_URL!,
|
|
18
|
-
* apiKey: process.env.SHASHU_API_KEY,
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* // Then use `openai` with streamText() as usual — requests go through Shashu.
|
|
22
|
-
* const result = streamText({ model: openai('gpt-4'), messages, ... });
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
interface ShashuOpenAIOptions extends ShashuConfig {
|
|
26
|
-
/**
|
|
27
|
-
* Optional OpenAI-compatible API key (if your gateway expects it in addition to Shashu key).
|
|
28
|
-
*/
|
|
29
|
-
openaiApiKey?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Returns extra headers (lowercase keys) to pass to the Vercel AI SDK OpenAI provider
|
|
33
|
-
* so that requests sent to Shashu include workflow context and x-shashu-source-tool
|
|
34
|
-
* JSON for Shadow AI detection. Use with createOpenAI({ baseURL, headers: getShashuHeaders() }).
|
|
35
|
-
*/
|
|
36
|
-
declare function getShashuHeaders(workflowContext?: ShashuConfig['workflowContext'], sessionId?: string, contractVersion?: ShashuConfig['contractVersion']): Record<string, string>;
|
|
37
|
-
/**
|
|
38
|
-
* Creates options suitable for the Vercel AI SDK's OpenAI provider so that
|
|
39
|
-
* you can swap the provider to Shashu in one line.
|
|
40
|
-
*
|
|
41
|
-
* Usage with AI SDK 3.x:
|
|
42
|
-
*
|
|
43
|
-
* import { createOpenAI } from '@ai-sdk/openai';
|
|
44
|
-
* import { createShashuOpenAIOptions } from '@shashu-ai/sdk/middleware/vercel-ai';
|
|
45
|
-
*
|
|
46
|
-
* const openaiOptions = createShashuOpenAIOptions({
|
|
47
|
-
* baseUrl: process.env.SHASHU_BASE_URL!,
|
|
48
|
-
* apiKey: process.env.SHASHU_API_KEY,
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* const openai = createOpenAI(openaiOptions);
|
|
52
|
-
* // use openai('gpt-4') with streamText()
|
|
53
|
-
*
|
|
54
|
-
* Returns `{}` when SHASHU_DISABLE is set: the provider client is then left
|
|
55
|
-
* exactly as it was — its own endpoint, its own credential, no Shashu context
|
|
56
|
-
* headers — which is the same no-op the Python SDK's patchers perform. The
|
|
57
|
-
* caller's shashu_sk_ key is deliberately NOT handed back, since it would be sent to
|
|
58
|
-
* the provider directly.
|
|
59
|
-
*
|
|
60
|
-
* @throws {ShashuConfigError} when no address is configured and the SDK is
|
|
61
|
-
* not disabled. There is no default host. See ../config.ts.
|
|
62
|
-
*/
|
|
63
|
-
declare function createShashuOpenAIOptions(options: ShashuOpenAIOptions): {
|
|
64
|
-
baseURL?: string;
|
|
65
|
-
apiKey?: string;
|
|
66
|
-
headers?: Record<string, string>;
|
|
67
|
-
fetch?: FetchLike;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export { type ShashuOpenAIOptions, createShashuOpenAIOptions, getShashuHeaders };
|
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conservative client-side retry policy for the Shashu Node SDK (mirrors Python).
|
|
3
|
-
*
|
|
4
|
-
* The gateway already retries upstream providers (3 attempts, backoff+jitter,
|
|
5
|
-
* per-provider circuit breakers, honoring Retry-After), so the SDK does not
|
|
6
|
-
* retry provider 5xx by default — stacking retries would amplify load during an
|
|
7
|
-
* incident.
|
|
8
|
-
*
|
|
9
|
-
* **A status code is not a retry signal.** The gateway returns 429 for two
|
|
10
|
-
* unrelated reasons and only one of them clears on its own:
|
|
11
|
-
*
|
|
12
|
-
* - the **token bucket** (tenant/agent RPS, tenant TPM) sends `Retry-After`
|
|
13
|
-
* and `error.details.error.retry_after_seconds`. It is telling you when to
|
|
14
|
-
* come back. Retryable, at that time.
|
|
15
|
-
* - the **identical-request breaker** — the same request body repeated inside
|
|
16
|
-
* one trace id — sends **no** `Retry-After` and no structured detail.
|
|
17
|
-
* Retrying is worse than useless: the counter is incremented by the retry
|
|
18
|
-
* and its 60-second window is refreshed from the last hit, so a client that
|
|
19
|
-
* retries holds itself in the block it is trying to escape.
|
|
20
|
-
*
|
|
21
|
-
* So the rule this module enforces is: **retry a refusal only when the gateway
|
|
22
|
-
* named a time to come back.** No `Retry-After` and no `retry_after_seconds`
|
|
23
|
-
* means the gateway is not inviting a retry, whatever the status says — see
|
|
24
|
-
* `gatewayRetryAfter` in ./exceptions.js.
|
|
25
|
-
*
|
|
26
|
-
* That also declines to retry a provider rate limit passed through from
|
|
27
|
-
* upstream, which carries no retry time either. Deliberate, and consistent with
|
|
28
|
-
* the 5xx default above: by the time a provider error reaches you the gateway
|
|
29
|
-
* has already spent its own three attempts on it.
|
|
30
|
-
*
|
|
31
|
-
* By default the SDK retries:
|
|
32
|
-
* - transport failures before any request byte is sent (ECONNREFUSED, DNS,
|
|
33
|
-
* connect timeout), and
|
|
34
|
-
* - HTTP 429 **that carries a retry time**, honoring it.
|
|
35
|
-
*
|
|
36
|
-
* A dropped connection after the request has left is raised, not retried —
|
|
37
|
-
* the gateway may already have run the call.
|
|
38
|
-
*
|
|
39
|
-
* 401/400/403/404, a 429 with no retry time, and 200-`content_filter` are never
|
|
40
|
-
* retried — they are decisions, not transient failures.
|
|
41
|
-
*/
|
|
42
|
-
interface RetryPolicy {
|
|
43
|
-
/** Max retries after the initial attempt. Default 2. */
|
|
44
|
-
maxRetries: number;
|
|
45
|
-
/** Base for exponential backoff (seconds). Default 0.5. */
|
|
46
|
-
backoffBaseSeconds: number;
|
|
47
|
-
/** Cap on any single backoff (seconds). Default 30. */
|
|
48
|
-
backoffMaxSeconds: number;
|
|
49
|
-
/** Retry transport failures that happen before any request byte is sent. Default true. */
|
|
50
|
-
retryOnConnectionErrors: boolean;
|
|
51
|
-
/** Retry HTTP 429. Default true. */
|
|
52
|
-
retryOn429: boolean;
|
|
53
|
-
/** Retry HTTP 5xx. Default false — the gateway already retries providers. */
|
|
54
|
-
retryOn5xx: boolean;
|
|
55
|
-
/** Statuses that are never retried, even if a flag above would allow it. */
|
|
56
|
-
neverRetryStatus: number[];
|
|
57
|
-
/** Ignore the Retry-After header on 429/503 and use exponential backoff instead. */
|
|
58
|
-
ignoreRetryAfter: boolean;
|
|
59
|
-
/** Extra wait as a fraction of the chosen delay (0–20% by default). */
|
|
60
|
-
jitterFraction: number;
|
|
61
|
-
}
|
|
62
|
-
declare const DEFAULT_RETRY_POLICY: RetryPolicy;
|
|
63
|
-
/** Resolve a config's retryPolicy: undefined -> default; null -> disabled; object -> merged over defaults. */
|
|
64
|
-
declare function resolveRetryPolicy(policy: Partial<RetryPolicy> | null | undefined): RetryPolicy | null;
|
|
65
|
-
/**
|
|
66
|
-
* Run `send` with retries per `policy`; returns the final Response.
|
|
67
|
-
* Retry decisions are made on raw status / connection errors BEFORE typed-exception
|
|
68
|
-
* dispatch, so the caller still maps the final response to the exception hierarchy.
|
|
69
|
-
*/
|
|
70
|
-
declare function executeWithRetry(send: () => Promise<Response>, policy: RetryPolicy | null, sleep?: (seconds: number) => Promise<void>): Promise<Response>;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Reading the gateway's decision — the six outcomes, from both carriers.
|
|
74
|
-
*
|
|
75
|
-
* Every name in this module is taken from `contracts/decision-envelope.v1.md`,
|
|
76
|
-
* this repository's vendored copy of the gateway's
|
|
77
|
-
* `core/app/contract/envelope.py`. Nothing here is retyped from prose.
|
|
78
|
-
*
|
|
79
|
-
* **The one thing a client does is read `decision`.** Not the message, which is
|
|
80
|
-
* prose and gets reworded; not `code`, whose vocabulary grows and which four
|
|
81
|
-
* SDKs would each have to edit if any of them branched on a hardcoded copy.
|
|
82
|
-
*
|
|
83
|
-
* Three properties, in this order:
|
|
84
|
-
*
|
|
85
|
-
* 1. **Absence is today's behaviour.** A response carrying neither carrier
|
|
86
|
-
* yields `undefined` — not a synthesised `allow`, not a `fail`.
|
|
87
|
-
* 2. **An unrecognised `decision` is a BLOCK.** The gateway's own
|
|
88
|
-
* `decision_of()` fails closed and the contract binds the client libraries
|
|
89
|
-
* identically. The wire value is preserved on `Decision.rawDecision`.
|
|
90
|
-
* 3. **Both carriers are read, and a disagreement is reported.** The body is
|
|
91
|
-
* the richer copy and wins; `carrierDisagreement` names any field the two
|
|
92
|
-
* placements did not agree on rather than smoothing it away.
|
|
93
|
-
*
|
|
94
|
-
* The decision is NEVER attached by mutating a response dict. Python's
|
|
95
|
-
* `_ResponseWithDecision` subclass leaked upward when that shape was tried
|
|
96
|
-
* here, and a shared mutable carrier handed concurrent tasks each other's
|
|
97
|
-
* documents. A `WeakMap` keyed by the `Response` object holds the read, so a
|
|
98
|
-
* response that carried neither carrier is the same object it has always been.
|
|
99
|
-
*/
|
|
100
|
-
declare const DECISION_ALLOW = "allow";
|
|
101
|
-
declare const DECISION_ALLOW_ALTERED = "allow_altered";
|
|
102
|
-
declare const DECISION_NOT_CHECKED = "not_checked";
|
|
103
|
-
declare const DECISION_BLOCK = "block";
|
|
104
|
-
declare const DECISION_REFUSE = "refuse";
|
|
105
|
-
declare const DECISION_FAIL = "fail";
|
|
106
|
-
/** Every decision the wire may carry, in the contract's card order. */
|
|
107
|
-
declare const DECISIONS: readonly ["allow", "allow_altered", "not_checked", "block", "refuse", "fail"];
|
|
108
|
-
/** The three where the caller is holding the provider's content. */
|
|
109
|
-
declare const DELIVERED_DECISIONS: ReadonlySet<string>;
|
|
110
|
-
/** Top-level on a 200 body; nested INSIDE `error` on an error body. */
|
|
111
|
-
declare const BODY_KEY = "shashu";
|
|
112
|
-
declare const HEADER_DECISION = "x-shashu-decision";
|
|
113
|
-
declare const HEADER_CODE = "x-shashu-code";
|
|
114
|
-
declare const HEADER_INSPECTION = "x-shashu-inspection";
|
|
115
|
-
declare const HEADER_SHOULD_RETRY = "x-should-retry";
|
|
116
|
-
declare const HEADER_REQUEST_ID = "x-request-id";
|
|
117
|
-
declare const HEADER_SHASHU_REQUEST_ID = "x-shashu-request-id";
|
|
118
|
-
declare const HEADER_TRACE_ID = "x-shashu-trace-id";
|
|
119
|
-
/** Counts only (`total=N;scanned=N;not_inspected=N;blocked=N`), only when one is above zero. */
|
|
120
|
-
declare const HEADER_ATTACHMENTS = "x-shashu-attachments";
|
|
121
|
-
/** Counts only (`writes=N;blocked=N;recalls=N;flagged=N`), only when one is above zero. */
|
|
122
|
-
declare const HEADER_MEMORY = "x-shashu-memory";
|
|
123
|
-
/**
|
|
124
|
-
* What happened to one attached file. A closed set on the gateway; a value
|
|
125
|
-
* this SDK does not know arrives as `"unknown"`, with the wire string kept on
|
|
126
|
-
* `Attachment.rawState` — never thrown on.
|
|
127
|
-
*/
|
|
128
|
-
type AttachmentState = 'scanned' | 'scanned_partial' | 'not_inspected' | 'blocked' | 'unknown';
|
|
129
|
-
/** One finding inside a file. `detector` and `category` are open sets. */
|
|
130
|
-
interface AttachmentFinding {
|
|
131
|
-
readonly detector: string | undefined;
|
|
132
|
-
readonly category: string | undefined;
|
|
133
|
-
/** The finding's reason code, passed through raw. Never branch on it. */
|
|
134
|
-
readonly code: string | undefined;
|
|
135
|
-
readonly severity: string | undefined;
|
|
136
|
-
readonly locator: string | undefined;
|
|
137
|
-
}
|
|
138
|
-
/** One attached file, as the gateway reported it. */
|
|
139
|
-
interface Attachment {
|
|
140
|
-
readonly state: AttachmentState;
|
|
141
|
-
/** The verbatim wire value of `state`, known or not. */
|
|
142
|
-
readonly rawState: string | undefined;
|
|
143
|
-
/** Passed through raw: a reason this SDK has never heard of is still a string. */
|
|
144
|
-
readonly reason: string | undefined;
|
|
145
|
-
readonly filename: string | undefined;
|
|
146
|
-
readonly declaredType: string | undefined;
|
|
147
|
-
readonly sniffedType: string | undefined;
|
|
148
|
-
readonly sha256: string | undefined;
|
|
149
|
-
readonly bytes: number | undefined;
|
|
150
|
-
readonly source: string | undefined;
|
|
151
|
-
readonly index: number | undefined;
|
|
152
|
-
readonly path: string | undefined;
|
|
153
|
-
readonly findings: readonly AttachmentFinding[];
|
|
154
|
-
}
|
|
155
|
-
/** The `attachments` block, or its header counts when that is all there is. */
|
|
156
|
-
interface Attachments {
|
|
157
|
-
readonly total: number;
|
|
158
|
-
readonly scanned: number;
|
|
159
|
-
readonly scannedPartial: number;
|
|
160
|
-
readonly notInspected: number;
|
|
161
|
-
readonly blocked: number;
|
|
162
|
-
/** Empty when read off the header, which never carries per-file detail. */
|
|
163
|
-
readonly items: readonly Attachment[];
|
|
164
|
-
/** Which placement these came from. */
|
|
165
|
-
readonly carrier: 'body' | 'header';
|
|
166
|
-
}
|
|
167
|
-
/** One memory write or recall. Every field is passed through raw. */
|
|
168
|
-
interface MemoryItem {
|
|
169
|
-
/** `write` or `recall` today; a new kind is still just a string. */
|
|
170
|
-
readonly kind: string | undefined;
|
|
171
|
-
readonly state: string | undefined;
|
|
172
|
-
readonly reason: string | undefined;
|
|
173
|
-
readonly tool: string | undefined;
|
|
174
|
-
readonly store: string | undefined;
|
|
175
|
-
readonly scope: string | undefined;
|
|
176
|
-
readonly source: string | undefined;
|
|
177
|
-
readonly enforcement: string | undefined;
|
|
178
|
-
readonly memoryRef: string | undefined;
|
|
179
|
-
readonly writeRef: string | undefined;
|
|
180
|
-
readonly seenBefore: boolean | undefined;
|
|
181
|
-
}
|
|
182
|
-
/** The `memory` block, or its header counts when that is all there is. */
|
|
183
|
-
interface MemoryActivity {
|
|
184
|
-
readonly writes: number;
|
|
185
|
-
readonly writesBlocked: number;
|
|
186
|
-
readonly recalls: number;
|
|
187
|
-
readonly recallsFlagged: number;
|
|
188
|
-
/** `gateway` / `observed` / `hosted` / `mixed`, raw; undefined off a header. */
|
|
189
|
-
readonly coverage: string | undefined;
|
|
190
|
-
readonly items: readonly MemoryItem[];
|
|
191
|
-
readonly carrier: 'body' | 'header';
|
|
192
|
-
}
|
|
193
|
-
/** Why a route was refused for the data in the request. */
|
|
194
|
-
interface RoutePolicy {
|
|
195
|
-
readonly route: string | undefined;
|
|
196
|
-
readonly category: string | undefined;
|
|
197
|
-
readonly reason: string | undefined;
|
|
198
|
-
readonly requestedRoute: string | undefined;
|
|
199
|
-
readonly degradedRoute: string | undefined;
|
|
200
|
-
}
|
|
201
|
-
interface Decision {
|
|
202
|
-
/** One of `DECISIONS`. An unrecognised wire value arrives here as `"block"`. */
|
|
203
|
-
readonly decision: string;
|
|
204
|
-
/** The verbatim wire value, whether or not it was recognised. */
|
|
205
|
-
readonly rawDecision: string | undefined;
|
|
206
|
-
/** The reason code. **Never branch on it** — the vocabulary grows. */
|
|
207
|
-
readonly code: string | undefined;
|
|
208
|
-
readonly retryable: boolean;
|
|
209
|
-
/** Resolves to the stored audit record. Same value as `x-request-id`. */
|
|
210
|
-
readonly id: string | undefined;
|
|
211
|
-
/** The per-hop request id (`x-shashu-request-id`), or undefined. */
|
|
212
|
-
readonly requestId: string | undefined;
|
|
213
|
-
/** The flow's trace id — the same value as `id`, under its own name. */
|
|
214
|
-
readonly traceId: string | undefined;
|
|
215
|
-
readonly inspection: Record<string, unknown> | undefined;
|
|
216
|
-
readonly versions: Record<string, string> | undefined;
|
|
217
|
-
/** Prose. Present so it can be logged, never so it can be parsed. */
|
|
218
|
-
readonly message: string | undefined;
|
|
219
|
-
readonly retryAfterMs: number | undefined;
|
|
220
|
-
/** Counts of what policy edited. Present only on `allow_altered`. */
|
|
221
|
-
readonly altered: Record<string, unknown> | undefined;
|
|
222
|
-
/** `"body"`, `"headers"`, or both. */
|
|
223
|
-
readonly carriers: readonly string[];
|
|
224
|
-
/** `{field: [bodyValue, headerValue]}` for anything the two disagreed on. */
|
|
225
|
-
readonly carrierDisagreement: Record<string, [unknown, unknown]>;
|
|
226
|
-
/**
|
|
227
|
-
* What happened to each attached file; undefined when the request had none.
|
|
228
|
-
* Read off the body; off the `x-shashu-attachments` counts when the body
|
|
229
|
-
* carried no envelope. `attachments.carrier` says which.
|
|
230
|
-
*/
|
|
231
|
-
readonly attachments: Attachments | undefined;
|
|
232
|
-
/** Memory writes and recalls; undefined when there were none. Same carrier rule. */
|
|
233
|
-
readonly memory: MemoryActivity | undefined;
|
|
234
|
-
/** Why a route was refused for the data in the request. Body only. */
|
|
235
|
-
readonly routePolicy: RoutePolicy | undefined;
|
|
236
|
-
/** Files the model received without a complete inspection. */
|
|
237
|
-
readonly filesUnverified: number;
|
|
238
|
-
readonly filesBlocked: number;
|
|
239
|
-
/** Memory writes the gateway refused to store. */
|
|
240
|
-
readonly memoryBlocked: number;
|
|
241
|
-
readonly memoryRecallsFlagged: number;
|
|
242
|
-
readonly memoryCoverage: string | undefined;
|
|
243
|
-
readonly delivered: boolean;
|
|
244
|
-
readonly isBlock: boolean;
|
|
245
|
-
readonly isAltered: boolean;
|
|
246
|
-
readonly unverified: boolean;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* The decision carried by a parsed body and a headers mapping, or `undefined`.
|
|
250
|
-
*
|
|
251
|
-
* Either argument may be absent. Absence in both is `undefined`, never a
|
|
252
|
-
* synthesised `allow`.
|
|
253
|
-
*/
|
|
254
|
-
declare function decisionFrom(body: unknown, headers: unknown): Decision | undefined;
|
|
255
|
-
/**
|
|
256
|
-
* The gateway's decision about a request, or `undefined` if it did not say one.
|
|
257
|
-
*
|
|
258
|
-
* Give it a `Response`, a parsed body, or an error. Never throws. Anything it
|
|
259
|
-
* cannot read is `undefined`.
|
|
260
|
-
*/
|
|
261
|
-
declare function shashuDecision(obj: unknown): Decision | undefined;
|
|
262
|
-
/**
|
|
263
|
-
* True when `err` is Shashu blocking content. Inspects; changes nothing.
|
|
264
|
-
*
|
|
265
|
-
* It patches nothing, wraps nothing and replaces nothing.
|
|
266
|
-
*
|
|
267
|
-
* **It FAILS CLOSED, and that is the opposite direction to
|
|
268
|
-
* {@link raiseForResponse}. Both are correct, because they are answering
|
|
269
|
-
* different questions:**
|
|
270
|
-
*
|
|
271
|
-
* - `raiseForResponse` decides whether to REPLACE a provider's own error with
|
|
272
|
-
* a Shashu type. Turning a genuine provider 400 into a fake block would
|
|
273
|
-
* break `catch` clauses a customer already has, so it needs a positive
|
|
274
|
-
* signal to act and fails OPEN as to block-ness — silence leaves the
|
|
275
|
-
* provider's error alone.
|
|
276
|
-
* - `isShashuBlock` is called on an error the customer already holds and
|
|
277
|
-
* replaces nothing. The cost of a wrong answer is asymmetric: calling a
|
|
278
|
-
* block "not a block" sends blocked content down a path that assumes it was
|
|
279
|
-
* delivered, while calling a non-block a block costs one unnecessary trip
|
|
280
|
-
* through a review branch. So a Shashu block signal we cannot fully
|
|
281
|
-
* parse — an unrecognised `decision`, an unrecognised `code` — answers true.
|
|
282
|
-
*
|
|
283
|
-
* **There is no copy of the block-code list here, deliberately.** `code` is a
|
|
284
|
-
* growing vocabulary; block-ness is carried by `decision` and by nothing else.
|
|
285
|
-
*
|
|
286
|
-
* @see raiseForResponse — the matching fail-open statement, on the function
|
|
287
|
-
* that replaces.
|
|
288
|
-
*/
|
|
289
|
-
declare function isShashuBlock(err: unknown): boolean;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Runtime metadata included in every context for parity with the Python SDK.
|
|
293
|
-
* Sent in x-shashu-source-tool and in x-shashu-meta-* headers.
|
|
294
|
-
*/
|
|
295
|
-
interface RuntimeMetadata {
|
|
296
|
-
/** SDK version (e.g. "1.0.0"). */
|
|
297
|
-
sdk_version: string;
|
|
298
|
-
/** Node.js version (e.g. "v20.1.0"). */
|
|
299
|
-
node_version: string;
|
|
300
|
-
/** Operating system platform (process.platform, e.g. "win32", "darwin", "linux"). */
|
|
301
|
-
os: string;
|
|
302
|
-
/** CPU architecture (process.arch, e.g. "x64", "arm64"). */
|
|
303
|
-
arch: string;
|
|
304
|
-
[key: string]: string;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Workflow/source metadata for Shadow AI detection and observability.
|
|
308
|
-
* Populated from n8n, Vercel, GitHub Actions, or default "local_script".
|
|
309
|
-
* Metadata always includes sdk_version, node_version, os, arch for Python parity.
|
|
310
|
-
*/
|
|
311
|
-
interface WorkflowContext {
|
|
312
|
-
/** Source: "n8n" | "vercel" | "github" | "local_script" | "custom". Never null. */
|
|
313
|
-
source: string;
|
|
314
|
-
/** Workflow or execution identifier */
|
|
315
|
-
workflow_id?: string;
|
|
316
|
-
/** Execution or run ID */
|
|
317
|
-
execution_id?: string;
|
|
318
|
-
/** Step identifier; key for generating Gantt chart bars in the Agent Intelligence dashboard. */
|
|
319
|
-
workflow_step?: string;
|
|
320
|
-
/** Runtime + environment metadata. When omitted, SDK fills sdk_version, node_version, os, arch. */
|
|
321
|
-
metadata?: RuntimeMetadata;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Base class for every Shashu gateway error. Subclasses in ./exceptions.ts
|
|
325
|
-
* narrow it by status; catch this to catch all of them.
|
|
326
|
-
*
|
|
327
|
-
* `message` is the gateway's `error.message`, except on a rate-limit 429 where
|
|
328
|
-
* that field is the literal string "error" and the readable sentence lives at
|
|
329
|
-
* `error.details.error.message` -- the dispatcher reads the inner one.
|
|
330
|
-
*
|
|
331
|
-
* `type` is NOT a policy discriminator: every 4xx the gateway raises itself
|
|
332
|
-
* carries "invalid_request_error". It is meaningful only on errors passed
|
|
333
|
-
* through from an upstream provider.
|
|
334
|
-
*/
|
|
335
|
-
declare class ShashuError extends Error {
|
|
336
|
-
/** HTTP status code (e.g. 403). */
|
|
337
|
-
readonly status: number;
|
|
338
|
-
/** Raw response body if available (parsed JSON when possible, else text). */
|
|
339
|
-
readonly body?: unknown;
|
|
340
|
-
/** `error.type` from the gateway body, when present. */
|
|
341
|
-
readonly type?: string;
|
|
342
|
-
/** `error.code` from the gateway body, when present. */
|
|
343
|
-
readonly code?: string;
|
|
344
|
-
/**
|
|
345
|
-
* The gateway's decision, when either carrier was present at raise time.
|
|
346
|
-
* Absent (undefined) is today's behaviour — a response that carried none.
|
|
347
|
-
*/
|
|
348
|
-
readonly decision?: Decision;
|
|
349
|
-
/** Response headers, kept so a later read can still see the header carrier. */
|
|
350
|
-
readonly responseHeaders?: Headers;
|
|
351
|
-
/**
|
|
352
|
-
* Why a route was refused for the data in the request, off the decision.
|
|
353
|
-
* Set on a `route_data_policy` refusal, so an app can say which route is not
|
|
354
|
-
* approved for which category without parsing the message.
|
|
355
|
-
*/
|
|
356
|
-
get routePolicy(): RoutePolicy | undefined;
|
|
357
|
-
constructor(message: string, status: number, body?: unknown, details?: {
|
|
358
|
-
type?: string;
|
|
359
|
-
code?: string;
|
|
360
|
-
decision?: Decision;
|
|
361
|
-
responseHeaders?: Headers;
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
/** Supported LLM providers (kept for middleware compatibility; gateway handles routing by model). */
|
|
365
|
-
type Provider = 'openai' | 'anthropic' | 'google';
|
|
366
|
-
/**
|
|
367
|
-
* Shashu client configuration.
|
|
368
|
-
*/
|
|
369
|
-
interface ShashuConfig {
|
|
370
|
-
/**
|
|
371
|
-
* Shashu gateway base URL. Falls back to process.env.SHASHU_BASE_URL.
|
|
372
|
-
* There is NO default: SHASHU is self-hosted, so an unset address is a
|
|
373
|
-
* ShashuConfigError, never a vendor host. See ./config.ts.
|
|
374
|
-
*/
|
|
375
|
-
baseUrl?: string;
|
|
376
|
-
/** API key (e.g. shashu_sk_...). Sent as Authorization: Bearer <apiKey>; gateway handles provider routing. */
|
|
377
|
-
apiKey?: string;
|
|
378
|
-
/**
|
|
379
|
-
* Callable returning the current cloud pass (string or Promise). Mutually
|
|
380
|
-
* exclusive with {@link apiKey}. The SDK never calls Entra, Google or AWS.
|
|
381
|
-
*/
|
|
382
|
-
tokenProvider?: () => string | Promise<string>;
|
|
383
|
-
/**
|
|
384
|
-
* This agent's OWN id (ADR-007 §4.1). NOT sent on the gateway call (that FORWARDS the
|
|
385
|
-
* captured inbound caller); used by `buildInvocationHeaders()` to stamp caller = self when
|
|
386
|
-
* THIS agent invokes a downstream agent. Seeds the self-id cache, which is then refreshed
|
|
387
|
-
* from each gateway response's `x-shashu-agent-id` header. Advisory lineage only —
|
|
388
|
-
* NEVER an auth credential.
|
|
389
|
-
*/
|
|
390
|
-
agentId?: string;
|
|
391
|
-
/**
|
|
392
|
-
* Session this client joins. Minted once when omitted, so every request the
|
|
393
|
-
* client makes — every hop of a tool loop — lands in one Sessions row. A
|
|
394
|
-
* captured inbound A2A session overrides this default; a per-request
|
|
395
|
-
* `sessionId` on {@link RequestOptions} overrides both. See
|
|
396
|
-
* `contracts/sdk-surface.v1.md`, "Which session a request joins".
|
|
397
|
-
*/
|
|
398
|
-
sessionId?: string;
|
|
399
|
-
/** Override workflow context; if not set, context is derived from process.env (never null). */
|
|
400
|
-
workflowContext?: WorkflowContext;
|
|
401
|
-
/** Extra headers sent with every request */
|
|
402
|
-
headers?: Record<string, string>;
|
|
403
|
-
/**
|
|
404
|
-
* `shashu-version`: the contract generation to ask the gateway for.
|
|
405
|
-
* Default `DEFAULT_CONTRACT_VERSION` (`"2026-09-01"`, the Python SDK's
|
|
406
|
-
* value): refusals arrive as errors and the body carries the full decision.
|
|
407
|
-
* Pass `null` to send no such header — the gateway then serves the account
|
|
408
|
-
* default, which is the legacy contract unless an operator moved it.
|
|
409
|
-
* A `shashu-version` entry in `headers` wins over this.
|
|
410
|
-
*/
|
|
411
|
-
contractVersion?: string | null;
|
|
412
|
-
/**
|
|
413
|
-
* Client-side retry policy. Omit for the conservative default (retry
|
|
414
|
-
* connection errors + 429 honoring Retry-After; 5xx off). Pass `null` to
|
|
415
|
-
* disable retries, or a partial object to override specific fields.
|
|
416
|
-
*/
|
|
417
|
-
retryPolicy?: Partial<RetryPolicy> | null;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Options for a single request (merge with client config).
|
|
421
|
-
*/
|
|
422
|
-
interface RequestOptions {
|
|
423
|
-
/** Override workflow context for this request only */
|
|
424
|
-
workflowContext?: WorkflowContext;
|
|
425
|
-
/**
|
|
426
|
-
* Per-request session. An INSTRUCTION: it wins over a captured A2A session
|
|
427
|
-
* and over the client's construction-time default, and applies to this
|
|
428
|
-
* request only.
|
|
429
|
-
*/
|
|
430
|
-
sessionId?: string;
|
|
431
|
-
/** Additional headers for this request */
|
|
432
|
-
headers?: Record<string, string>;
|
|
433
|
-
/** Request timeout in ms */
|
|
434
|
-
timeout?: number;
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Pre-formatted headers for n8n HTTP Request node (name/value pairs).
|
|
438
|
-
*/
|
|
439
|
-
interface N8nHeaderSnippet {
|
|
440
|
-
headers: Array<{
|
|
441
|
-
name: string;
|
|
442
|
-
value: string;
|
|
443
|
-
}>;
|
|
444
|
-
/** JSON string suitable for pasting into n8n */
|
|
445
|
-
json: string;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
export { type Attachment as A, BODY_KEY as B, executeWithRetry as C, type Decision as D, isShashuBlock as E, resolveRetryPolicy as F, shashuDecision as G, HEADER_ATTACHMENTS as H, type MemoryActivity as M, type N8nHeaderSnippet as N, type Provider as P, type RequestOptions as R, type ShashuConfig as S, type WorkflowContext as W, ShashuError as a, type AttachmentFinding as b, type AttachmentState as c, type Attachments as d, DECISIONS as e, DECISION_ALLOW as f, DECISION_ALLOW_ALTERED as g, DECISION_BLOCK as h, DECISION_FAIL as i, DECISION_NOT_CHECKED as j, DECISION_REFUSE as k, DEFAULT_RETRY_POLICY as l, DELIVERED_DECISIONS as m, HEADER_CODE as n, HEADER_DECISION as o, HEADER_INSPECTION as p, HEADER_MEMORY as q, HEADER_REQUEST_ID as r, HEADER_SHASHU_REQUEST_ID as s, HEADER_SHOULD_RETRY as t, HEADER_TRACE_ID as u, type MemoryItem as v, type RetryPolicy as w, type RoutePolicy as x, type RuntimeMetadata as y, decisionFrom as z };
|