anthale 0.0.2 → 0.2.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +49 -16
  3. package/client.d.mts +2 -1
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +2 -1
  6. package/client.d.ts.map +1 -1
  7. package/client.js +17 -14
  8. package/client.js.map +1 -1
  9. package/client.mjs +17 -14
  10. package/client.mjs.map +1 -1
  11. package/internal/parse.d.mts.map +1 -1
  12. package/internal/parse.d.ts.map +1 -1
  13. package/internal/parse.js +5 -0
  14. package/internal/parse.js.map +1 -1
  15. package/internal/parse.mjs +5 -0
  16. package/internal/parse.mjs.map +1 -1
  17. package/internal/utils/query.d.mts +5 -0
  18. package/internal/utils/query.d.mts.map +1 -0
  19. package/internal/utils/query.d.ts +5 -0
  20. package/internal/utils/query.d.ts.map +1 -0
  21. package/internal/utils/query.js +23 -0
  22. package/internal/utils/query.js.map +1 -0
  23. package/internal/utils/query.mjs +20 -0
  24. package/internal/utils/query.mjs.map +1 -0
  25. package/internal/utils.d.mts +1 -0
  26. package/internal/utils.d.ts +1 -0
  27. package/internal/utils.js +1 -0
  28. package/internal/utils.js.map +1 -1
  29. package/internal/utils.mjs +1 -0
  30. package/package.json +2 -2
  31. package/resources/organizations/index.d.mts +1 -1
  32. package/resources/organizations/index.d.mts.map +1 -1
  33. package/resources/organizations/index.d.ts +1 -1
  34. package/resources/organizations/index.d.ts.map +1 -1
  35. package/resources/organizations/organizations.d.mts +2 -2
  36. package/resources/organizations/organizations.d.mts.map +1 -1
  37. package/resources/organizations/organizations.d.ts +2 -2
  38. package/resources/organizations/organizations.d.ts.map +1 -1
  39. package/resources/organizations/policies.d.mts +45 -37
  40. package/resources/organizations/policies.d.mts.map +1 -1
  41. package/resources/organizations/policies.d.ts +45 -37
  42. package/resources/organizations/policies.d.ts.map +1 -1
  43. package/src/client.ts +22 -19
  44. package/src/internal/parse.ts +6 -0
  45. package/src/internal/utils/query.ts +23 -0
  46. package/src/internal/utils.ts +1 -0
  47. package/src/resources/organizations/index.ts +1 -1
  48. package/src/resources/organizations/organizations.ts +2 -2
  49. package/src/resources/organizations/policies.ts +51 -41
  50. package/src/version.ts +1 -1
  51. package/version.d.mts +1 -1
  52. package/version.d.ts +1 -1
  53. package/version.js +1 -1
  54. package/version.mjs +1 -1
@@ -30,7 +30,7 @@ export declare class Policies extends APIResource {
30
30
  /**
31
31
  * Enum representing possible policy enforcement result actions.
32
32
  */
33
- export type PolicyEnforcementResultActionValue = 'block' | 'redact' | 'detect' | 'allow';
33
+ export type PolicyEnforcementResultAction = 'block' | 'redact' | 'detect' | 'allow';
34
34
  /**
35
35
  * Policy enforcement response schema.
36
36
  */
@@ -38,41 +38,45 @@ export interface PolicyEnforceResponse {
38
38
  /**
39
39
  * Overall action decided by the policy (allow, detect, redact, block).
40
40
  */
41
- action: PolicyEnforcementResultActionValue;
41
+ action: PolicyEnforcementResultAction;
42
+ /**
43
+ * Identifier of the policy enforcer that processed the request.
44
+ */
45
+ enforcerIdentifier: string;
42
46
  /**
43
47
  * Per-guardrail evaluation results.
44
48
  */
45
- evaluations: Array<PolicyEnforceResponse.PromptInjectionEvaluationResponseSchema | PolicyEnforceResponse.ContentSafetyEvaluationResponseSchema | PolicyEnforceResponse.DataLeakageEvaluationResponseSchema | PolicyEnforceResponse.ContextSafetyEvaluationResponseSchema>;
49
+ evaluations?: Array<PolicyEnforceResponse.PromptInjectionEvaluation | PolicyEnforceResponse.ContentSafetyEvaluation | PolicyEnforceResponse.DataLeakageEvaluation | PolicyEnforceResponse.ContextSafetyEvaluation>;
46
50
  }
47
51
  export declare namespace PolicyEnforceResponse {
48
52
  /**
49
53
  * Evaluation payload for prompt injection guardrail.
50
54
  */
51
- interface PromptInjectionEvaluationResponseSchema {
55
+ interface PromptInjectionEvaluation {
52
56
  /**
53
57
  * Action suggested by this guardrail (allow, detect, redact, block).
54
58
  */
55
- action: PoliciesAPI.PolicyEnforcementResultActionValue;
59
+ action: PoliciesAPI.PolicyEnforcementResultAction;
56
60
  /**
57
61
  * Guardrail key that produced this evaluation.
58
62
  */
59
- guardrailKey: 'prompt_injection_protection';
63
+ guardrailKey: 'prompt-injection-protection';
60
64
  /**
61
65
  * Overall confidence score.
62
66
  */
63
67
  score: number;
64
- /**
65
- * Evidence or reasoning threads generated by the guardrail.
66
- */
67
- threads: Array<PromptInjectionEvaluationResponseSchema.Thread>;
68
68
  /**
69
69
  * Additional guardrail-specific metadata.
70
70
  */
71
71
  metadata?: {
72
72
  [key: string]: unknown;
73
73
  };
74
+ /**
75
+ * Evidence or reasoning threads generated by the guardrail.
76
+ */
77
+ threads?: Array<PromptInjectionEvaluation.Thread>;
74
78
  }
75
- namespace PromptInjectionEvaluationResponseSchema {
79
+ namespace PromptInjectionEvaluation {
76
80
  /**
77
81
  * Thread details for prompt injection guardrail.
78
82
  */
@@ -94,31 +98,31 @@ export declare namespace PolicyEnforceResponse {
94
98
  /**
95
99
  * Evaluation payload for content safety guardrail.
96
100
  */
97
- interface ContentSafetyEvaluationResponseSchema {
101
+ interface ContentSafetyEvaluation {
98
102
  /**
99
103
  * Action suggested by this guardrail (allow, detect, redact, block).
100
104
  */
101
- action: PoliciesAPI.PolicyEnforcementResultActionValue;
105
+ action: PoliciesAPI.PolicyEnforcementResultAction;
102
106
  /**
103
107
  * Guardrail key that produced this evaluation.
104
108
  */
105
- guardrailKey: 'content_safety_filtering';
109
+ guardrailKey: 'content-moderation';
106
110
  /**
107
111
  * Overall confidence score.
108
112
  */
109
113
  score: number;
110
- /**
111
- * Evidence or reasoning threads generated by the guardrail.
112
- */
113
- threads: Array<ContentSafetyEvaluationResponseSchema.Thread>;
114
114
  /**
115
115
  * Additional guardrail-specific metadata.
116
116
  */
117
117
  metadata?: {
118
118
  [key: string]: unknown;
119
119
  };
120
+ /**
121
+ * Evidence or reasoning threads generated by the guardrail.
122
+ */
123
+ threads?: Array<ContentSafetyEvaluation.Thread>;
120
124
  }
121
- namespace ContentSafetyEvaluationResponseSchema {
125
+ namespace ContentSafetyEvaluation {
122
126
  /**
123
127
  * Thread details for content safety guardrail.
124
128
  */
@@ -144,31 +148,31 @@ export declare namespace PolicyEnforceResponse {
144
148
  /**
145
149
  * Evaluation payload for data leakage guardrail.
146
150
  */
147
- interface DataLeakageEvaluationResponseSchema {
151
+ interface DataLeakageEvaluation {
148
152
  /**
149
153
  * Action suggested by this guardrail (allow, detect, redact, block).
150
154
  */
151
- action: PoliciesAPI.PolicyEnforcementResultActionValue;
155
+ action: PoliciesAPI.PolicyEnforcementResultAction;
152
156
  /**
153
157
  * Guardrail key that produced this evaluation.
154
158
  */
155
- guardrailKey: 'data_leakage_protection';
159
+ guardrailKey: 'data-leakage-prevention';
156
160
  /**
157
161
  * Overall confidence score.
158
162
  */
159
163
  score: number;
160
- /**
161
- * Evidence or reasoning threads generated by the guardrail.
162
- */
163
- threads: Array<DataLeakageEvaluationResponseSchema.Thread>;
164
164
  /**
165
165
  * Additional guardrail-specific metadata.
166
166
  */
167
167
  metadata?: {
168
168
  [key: string]: unknown;
169
169
  };
170
+ /**
171
+ * Evidence or reasoning threads generated by the guardrail.
172
+ */
173
+ threads?: Array<DataLeakageEvaluation.Thread>;
170
174
  }
171
- namespace DataLeakageEvaluationResponseSchema {
175
+ namespace DataLeakageEvaluation {
172
176
  /**
173
177
  * Thread details for data leakage guardrail.
174
178
  */
@@ -198,31 +202,31 @@ export declare namespace PolicyEnforceResponse {
198
202
  /**
199
203
  * Evaluation payload for context safety guardrail.
200
204
  */
201
- interface ContextSafetyEvaluationResponseSchema {
205
+ interface ContextSafetyEvaluation {
202
206
  /**
203
207
  * Action suggested by this guardrail (allow, detect, redact, block).
204
208
  */
205
- action: PoliciesAPI.PolicyEnforcementResultActionValue;
209
+ action: PoliciesAPI.PolicyEnforcementResultAction;
206
210
  /**
207
211
  * Guardrail key that produced this evaluation.
208
212
  */
209
- guardrailKey: 'context_safety_filtering';
213
+ guardrailKey: 'topic-control';
210
214
  /**
211
215
  * Overall confidence score.
212
216
  */
213
217
  score: number;
214
- /**
215
- * Evidence or reasoning threads generated by the guardrail.
216
- */
217
- threads: Array<ContextSafetyEvaluationResponseSchema.Thread>;
218
218
  /**
219
219
  * Additional guardrail-specific metadata.
220
220
  */
221
221
  metadata?: {
222
222
  [key: string]: unknown;
223
223
  };
224
+ /**
225
+ * Evidence or reasoning threads generated by the guardrail.
226
+ */
227
+ threads?: Array<ContextSafetyEvaluation.Thread>;
224
228
  }
225
- namespace ContextSafetyEvaluationResponseSchema {
229
+ namespace ContextSafetyEvaluation {
226
230
  /**
227
231
  * Thread details for context safety guardrail.
228
232
  */
@@ -255,6 +259,10 @@ export interface PolicyEnforceParams {
255
259
  * Ordered list of messages that compose the conversation to evaluate.
256
260
  */
257
261
  messages: Array<PolicyEnforceParams.Message>;
262
+ /**
263
+ * Whether to include evaluation details in the response.
264
+ */
265
+ includeEvaluations?: boolean;
258
266
  /**
259
267
  * Optional contextual metadata forwarded to guardrails.
260
268
  */
@@ -274,7 +282,7 @@ export declare namespace PolicyEnforceParams {
274
282
  /**
275
283
  * Message role within the conversation.
276
284
  */
277
- role: 'system' | 'user' | 'assistant';
285
+ role: 'system' | 'user' | 'assistant' | 'tool';
278
286
  }
279
287
  namespace Message {
280
288
  /**
@@ -293,6 +301,6 @@ export declare namespace PolicyEnforceParams {
293
301
  }
294
302
  }
295
303
  export declare namespace Policies {
296
- export { type PolicyEnforcementResultActionValue as PolicyEnforcementResultActionValue, type PolicyEnforceResponse as PolicyEnforceResponse, type PolicyEnforceParams as PolicyEnforceParams, };
304
+ export { type PolicyEnforcementResultAction as PolicyEnforcementResultAction, type PolicyEnforceResponse as PolicyEnforceResponse, type PolicyEnforceParams as PolicyEnforceParams, };
297
305
  }
298
306
  //# sourceMappingURL=policies.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/resources/organizations/policies.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,KAAK,CAAC,CAAC;QAEvC;;WAEG;QACH,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;KACvC;IAED,UAAiB,OAAO,CAAC;QACvB;;WAEG;QACH,UAAiB,KAAK;YACpB;;eAEG;YACH,IAAI,EAAE,MAAM,CAAC;YAEb;;eAEG;YACH,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;SACzD;KACF;CACF;AAED,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC;IAChC,OAAO,EACL,KAAK,kCAAkC,IAAI,kCAAkC,EAC7E,KAAK,qBAAqB,IAAI,qBAAqB,EACnD,KAAK,mBAAmB,IAAI,mBAAmB,GAChD,CAAC;CACH"}
1
+ {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/resources/organizations/policies.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,KAAK,WAAW;OAChB,EAAE,UAAU,EAAE;OACd,EAAE,cAAc,EAAE;AAGzB,qBAAa,QAAS,SAAQ,WAAW;IACvC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CACL,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,mBAAmB,EACzB,OAAO,CAAC,EAAE,cAAc,GACvB,UAAU,CAAC,qBAAqB,CAAC;CAGrC;AAED;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEpF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,MAAM,EAAE,6BAA6B,CAAC;IAEtC;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,WAAW,CAAC,EAAE,KAAK,CACf,qBAAqB,CAAC,yBAAyB,GAC/C,qBAAqB,CAAC,uBAAuB,GAC7C,qBAAqB,CAAC,qBAAqB,GAC3C,qBAAqB,CAAC,uBAAuB,CACh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C;;WAEG;QACH,UAAiB,MAAM;YACrB;;eAEG;YACH,iBAAiB,EAAE,MAAM,CAAC;YAE1B;;eAEG;YACH,iBAAiB,EAAE,MAAM,CAAC;YAE1B;;eAEG;YACH,KAAK,EAAE,MAAM,CAAC;YAEd;;eAEG;YACH,KAAK,EAAE,MAAM,CAAC;SACf;KACF;CACF;AAED,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,SAAS,EAAE,OAAO,GAAG,QAAQ,CAAC;IAE9B;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAE7C;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACvC;AAED,yBAAiB,mBAAmB,CAAC;IACnC;;OAEG;IACH,UAAiB,OAAO;QACtB;;WAEG;QACH,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAEvC;;WAEG;QACH,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;KAChD;IAED,UAAiB,OAAO,CAAC;QACvB;;WAEG;QACH,UAAiB,KAAK;YACpB;;eAEG;YACH,IAAI,EAAE,MAAM,CAAC;YAEb;;eAEG;YACH,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;SACzD;KACF;CACF;AAED,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC;IAChC,OAAO,EACL,KAAK,6BAA6B,IAAI,6BAA6B,EACnE,KAAK,qBAAqB,IAAI,qBAAqB,EACnD,KAAK,mBAAmB,IAAI,mBAAmB,GAChD,CAAC;CACH"}
package/src/client.ts CHANGED
@@ -11,6 +11,7 @@ import type { APIResponseProps } from './internal/parse';
11
11
  import { getPlatformHeaders } from './internal/detect-platform';
12
12
  import * as Shims from './internal/shims';
13
13
  import * as Opts from './internal/request-options';
14
+ import { stringifyQuery } from './internal/utils/query';
14
15
  import { VERSION } from './version';
15
16
  import * as Errors from './core/error';
16
17
  import * as Uploads from './core/uploads';
@@ -213,21 +214,8 @@ export class Anthale {
213
214
  /**
214
215
  * Basic re-implementation of `qs.stringify` for primitive types.
215
216
  */
216
- protected stringifyQuery(query: Record<string, unknown>): string {
217
- return Object.entries(query)
218
- .filter(([_, value]) => typeof value !== 'undefined')
219
- .map(([key, value]) => {
220
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
221
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
222
- }
223
- if (value === null) {
224
- return `${encodeURIComponent(key)}=`;
225
- }
226
- throw new Errors.AnthaleError(
227
- `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
228
- );
229
- })
230
- .join('&');
217
+ protected stringifyQuery(query: object | Record<string, unknown>): string {
218
+ return stringifyQuery(query);
231
219
  }
232
220
 
233
221
  private getUserAgent(): string {
@@ -264,7 +252,7 @@ export class Anthale {
264
252
  }
265
253
 
266
254
  if (typeof query === 'object' && query && !Array.isArray(query)) {
267
- url.search = this.stringifyQuery(query as Record<string, unknown>);
255
+ url.search = this.stringifyQuery(query);
268
256
  }
269
257
 
270
258
  return url.toString();
@@ -448,7 +436,7 @@ export class Anthale {
448
436
  loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
449
437
 
450
438
  const errText = await response.text().catch((err: any) => castToError(err).message);
451
- const errJSON = safeJSON(errText);
439
+ const errJSON = safeJSON(errText) as any;
452
440
  const errMessage = errJSON ? undefined : errText;
453
441
 
454
442
  loggerFor(this).debug(
@@ -489,9 +477,10 @@ export class Anthale {
489
477
  controller: AbortController,
490
478
  ): Promise<Response> {
491
479
  const { signal, method, ...options } = init || {};
492
- if (signal) signal.addEventListener('abort', () => controller.abort());
480
+ const abort = this._makeAbort(controller);
481
+ if (signal) signal.addEventListener('abort', abort, { once: true });
493
482
 
494
- const timeout = setTimeout(() => controller.abort(), ms);
483
+ const timeout = setTimeout(abort, ms);
495
484
 
496
485
  const isReadableBody =
497
486
  ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
@@ -658,6 +647,12 @@ export class Anthale {
658
647
  return headers.values;
659
648
  }
660
649
 
650
+ private _makeAbort(controller: AbortController) {
651
+ // note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
652
+ // would capture all request options, and cause a memory leak.
653
+ return () => controller.abort();
654
+ }
655
+
661
656
  private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
662
657
  bodyHeaders: HeadersLike;
663
658
  body: BodyInit | undefined;
@@ -690,6 +685,14 @@ export class Anthale {
690
685
  (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
691
686
  ) {
692
687
  return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
688
+ } else if (
689
+ typeof body === 'object' &&
690
+ headers.values.get('content-type') === 'application/x-www-form-urlencoded'
691
+ ) {
692
+ return {
693
+ bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
694
+ body: this.stringifyQuery(body),
695
+ };
693
696
  } else {
694
697
  return this.#encoder({ body, headers });
695
698
  }
@@ -29,6 +29,12 @@ export async function defaultParseResponse<T>(client: Anthale, props: APIRespons
29
29
  const mediaType = contentType?.split(';')[0]?.trim();
30
30
  const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
31
31
  if (isJSON) {
32
+ const contentLength = response.headers.get('content-length');
33
+ if (contentLength === '0') {
34
+ // if there is no content we can't do anything
35
+ return undefined as T;
36
+ }
37
+
32
38
  const json = await response.json();
33
39
  return json as T;
34
40
  }
@@ -0,0 +1,23 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { AnthaleError } from '../../core/error';
4
+
5
+ /**
6
+ * Basic re-implementation of `qs.stringify` for primitive types.
7
+ */
8
+ export function stringifyQuery(query: object | Record<string, unknown>) {
9
+ return Object.entries(query)
10
+ .filter(([_, value]) => typeof value !== 'undefined')
11
+ .map(([key, value]) => {
12
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
13
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
14
+ }
15
+ if (value === null) {
16
+ return `${encodeURIComponent(key)}=`;
17
+ }
18
+ throw new AnthaleError(
19
+ `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
20
+ );
21
+ })
22
+ .join('&');
23
+ }
@@ -6,3 +6,4 @@ export * from './utils/env';
6
6
  export * from './utils/log';
7
7
  export * from './utils/uuid';
8
8
  export * from './utils/sleep';
9
+ export * from './utils/query';
@@ -3,7 +3,7 @@
3
3
  export { Organizations } from './organizations';
4
4
  export {
5
5
  Policies,
6
- type PolicyEnforcementResultActionValue,
6
+ type PolicyEnforcementResultAction,
7
7
  type PolicyEnforceResponse,
8
8
  type PolicyEnforceParams,
9
9
  } from './policies';
@@ -6,7 +6,7 @@ import {
6
6
  Policies,
7
7
  PolicyEnforceParams,
8
8
  PolicyEnforceResponse,
9
- PolicyEnforcementResultActionValue,
9
+ PolicyEnforcementResultAction,
10
10
  } from './policies';
11
11
 
12
12
  export class Organizations extends APIResource {
@@ -18,7 +18,7 @@ Organizations.Policies = Policies;
18
18
  export declare namespace Organizations {
19
19
  export {
20
20
  Policies as Policies,
21
- type PolicyEnforcementResultActionValue as PolicyEnforcementResultActionValue,
21
+ type PolicyEnforcementResultAction as PolicyEnforcementResultAction,
22
22
  type PolicyEnforceResponse as PolicyEnforceResponse,
23
23
  type PolicyEnforceParams as PolicyEnforceParams,
24
24
  };
@@ -41,7 +41,7 @@ export class Policies extends APIResource {
41
41
  /**
42
42
  * Enum representing possible policy enforcement result actions.
43
43
  */
44
- export type PolicyEnforcementResultActionValue = 'block' | 'redact' | 'detect' | 'allow';
44
+ export type PolicyEnforcementResultAction = 'block' | 'redact' | 'detect' | 'allow';
45
45
 
46
46
  /**
47
47
  * Policy enforcement response schema.
@@ -50,16 +50,21 @@ export interface PolicyEnforceResponse {
50
50
  /**
51
51
  * Overall action decided by the policy (allow, detect, redact, block).
52
52
  */
53
- action: PolicyEnforcementResultActionValue;
53
+ action: PolicyEnforcementResultAction;
54
+
55
+ /**
56
+ * Identifier of the policy enforcer that processed the request.
57
+ */
58
+ enforcerIdentifier: string;
54
59
 
55
60
  /**
56
61
  * Per-guardrail evaluation results.
57
62
  */
58
- evaluations: Array<
59
- | PolicyEnforceResponse.PromptInjectionEvaluationResponseSchema
60
- | PolicyEnforceResponse.ContentSafetyEvaluationResponseSchema
61
- | PolicyEnforceResponse.DataLeakageEvaluationResponseSchema
62
- | PolicyEnforceResponse.ContextSafetyEvaluationResponseSchema
63
+ evaluations?: Array<
64
+ | PolicyEnforceResponse.PromptInjectionEvaluation
65
+ | PolicyEnforceResponse.ContentSafetyEvaluation
66
+ | PolicyEnforceResponse.DataLeakageEvaluation
67
+ | PolicyEnforceResponse.ContextSafetyEvaluation
63
68
  >;
64
69
  }
65
70
 
@@ -67,16 +72,16 @@ export namespace PolicyEnforceResponse {
67
72
  /**
68
73
  * Evaluation payload for prompt injection guardrail.
69
74
  */
70
- export interface PromptInjectionEvaluationResponseSchema {
75
+ export interface PromptInjectionEvaluation {
71
76
  /**
72
77
  * Action suggested by this guardrail (allow, detect, redact, block).
73
78
  */
74
- action: PoliciesAPI.PolicyEnforcementResultActionValue;
79
+ action: PoliciesAPI.PolicyEnforcementResultAction;
75
80
 
76
81
  /**
77
82
  * Guardrail key that produced this evaluation.
78
83
  */
79
- guardrailKey: 'prompt_injection_protection';
84
+ guardrailKey: 'prompt-injection-protection';
80
85
 
81
86
  /**
82
87
  * Overall confidence score.
@@ -84,17 +89,17 @@ export namespace PolicyEnforceResponse {
84
89
  score: number;
85
90
 
86
91
  /**
87
- * Evidence or reasoning threads generated by the guardrail.
92
+ * Additional guardrail-specific metadata.
88
93
  */
89
- threads: Array<PromptInjectionEvaluationResponseSchema.Thread>;
94
+ metadata?: { [key: string]: unknown };
90
95
 
91
96
  /**
92
- * Additional guardrail-specific metadata.
97
+ * Evidence or reasoning threads generated by the guardrail.
93
98
  */
94
- metadata?: { [key: string]: unknown };
99
+ threads?: Array<PromptInjectionEvaluation.Thread>;
95
100
  }
96
101
 
97
- export namespace PromptInjectionEvaluationResponseSchema {
102
+ export namespace PromptInjectionEvaluation {
98
103
  /**
99
104
  * Thread details for prompt injection guardrail.
100
105
  */
@@ -119,16 +124,16 @@ export namespace PolicyEnforceResponse {
119
124
  /**
120
125
  * Evaluation payload for content safety guardrail.
121
126
  */
122
- export interface ContentSafetyEvaluationResponseSchema {
127
+ export interface ContentSafetyEvaluation {
123
128
  /**
124
129
  * Action suggested by this guardrail (allow, detect, redact, block).
125
130
  */
126
- action: PoliciesAPI.PolicyEnforcementResultActionValue;
131
+ action: PoliciesAPI.PolicyEnforcementResultAction;
127
132
 
128
133
  /**
129
134
  * Guardrail key that produced this evaluation.
130
135
  */
131
- guardrailKey: 'content_safety_filtering';
136
+ guardrailKey: 'content-moderation';
132
137
 
133
138
  /**
134
139
  * Overall confidence score.
@@ -136,17 +141,17 @@ export namespace PolicyEnforceResponse {
136
141
  score: number;
137
142
 
138
143
  /**
139
- * Evidence or reasoning threads generated by the guardrail.
144
+ * Additional guardrail-specific metadata.
140
145
  */
141
- threads: Array<ContentSafetyEvaluationResponseSchema.Thread>;
146
+ metadata?: { [key: string]: unknown };
142
147
 
143
148
  /**
144
- * Additional guardrail-specific metadata.
149
+ * Evidence or reasoning threads generated by the guardrail.
145
150
  */
146
- metadata?: { [key: string]: unknown };
151
+ threads?: Array<ContentSafetyEvaluation.Thread>;
147
152
  }
148
153
 
149
- export namespace ContentSafetyEvaluationResponseSchema {
154
+ export namespace ContentSafetyEvaluation {
150
155
  /**
151
156
  * Thread details for content safety guardrail.
152
157
  */
@@ -176,16 +181,16 @@ export namespace PolicyEnforceResponse {
176
181
  /**
177
182
  * Evaluation payload for data leakage guardrail.
178
183
  */
179
- export interface DataLeakageEvaluationResponseSchema {
184
+ export interface DataLeakageEvaluation {
180
185
  /**
181
186
  * Action suggested by this guardrail (allow, detect, redact, block).
182
187
  */
183
- action: PoliciesAPI.PolicyEnforcementResultActionValue;
188
+ action: PoliciesAPI.PolicyEnforcementResultAction;
184
189
 
185
190
  /**
186
191
  * Guardrail key that produced this evaluation.
187
192
  */
188
- guardrailKey: 'data_leakage_protection';
193
+ guardrailKey: 'data-leakage-prevention';
189
194
 
190
195
  /**
191
196
  * Overall confidence score.
@@ -193,17 +198,17 @@ export namespace PolicyEnforceResponse {
193
198
  score: number;
194
199
 
195
200
  /**
196
- * Evidence or reasoning threads generated by the guardrail.
201
+ * Additional guardrail-specific metadata.
197
202
  */
198
- threads: Array<DataLeakageEvaluationResponseSchema.Thread>;
203
+ metadata?: { [key: string]: unknown };
199
204
 
200
205
  /**
201
- * Additional guardrail-specific metadata.
206
+ * Evidence or reasoning threads generated by the guardrail.
202
207
  */
203
- metadata?: { [key: string]: unknown };
208
+ threads?: Array<DataLeakageEvaluation.Thread>;
204
209
  }
205
210
 
206
- export namespace DataLeakageEvaluationResponseSchema {
211
+ export namespace DataLeakageEvaluation {
207
212
  /**
208
213
  * Thread details for data leakage guardrail.
209
214
  */
@@ -255,16 +260,16 @@ export namespace PolicyEnforceResponse {
255
260
  /**
256
261
  * Evaluation payload for context safety guardrail.
257
262
  */
258
- export interface ContextSafetyEvaluationResponseSchema {
263
+ export interface ContextSafetyEvaluation {
259
264
  /**
260
265
  * Action suggested by this guardrail (allow, detect, redact, block).
261
266
  */
262
- action: PoliciesAPI.PolicyEnforcementResultActionValue;
267
+ action: PoliciesAPI.PolicyEnforcementResultAction;
263
268
 
264
269
  /**
265
270
  * Guardrail key that produced this evaluation.
266
271
  */
267
- guardrailKey: 'context_safety_filtering';
272
+ guardrailKey: 'topic-control';
268
273
 
269
274
  /**
270
275
  * Overall confidence score.
@@ -272,17 +277,17 @@ export namespace PolicyEnforceResponse {
272
277
  score: number;
273
278
 
274
279
  /**
275
- * Evidence or reasoning threads generated by the guardrail.
280
+ * Additional guardrail-specific metadata.
276
281
  */
277
- threads: Array<ContextSafetyEvaluationResponseSchema.Thread>;
282
+ metadata?: { [key: string]: unknown };
278
283
 
279
284
  /**
280
- * Additional guardrail-specific metadata.
285
+ * Evidence or reasoning threads generated by the guardrail.
281
286
  */
282
- metadata?: { [key: string]: unknown };
287
+ threads?: Array<ContextSafetyEvaluation.Thread>;
283
288
  }
284
289
 
285
- export namespace ContextSafetyEvaluationResponseSchema {
290
+ export namespace ContextSafetyEvaluation {
286
291
  /**
287
292
  * Thread details for context safety guardrail.
288
293
  */
@@ -321,6 +326,11 @@ export interface PolicyEnforceParams {
321
326
  */
322
327
  messages: Array<PolicyEnforceParams.Message>;
323
328
 
329
+ /**
330
+ * Whether to include evaluation details in the response.
331
+ */
332
+ includeEvaluations?: boolean;
333
+
324
334
  /**
325
335
  * Optional contextual metadata forwarded to guardrails.
326
336
  */
@@ -340,7 +350,7 @@ export namespace PolicyEnforceParams {
340
350
  /**
341
351
  * Message role within the conversation.
342
352
  */
343
- role: 'system' | 'user' | 'assistant';
353
+ role: 'system' | 'user' | 'assistant' | 'tool';
344
354
  }
345
355
 
346
356
  export namespace Message {
@@ -363,7 +373,7 @@ export namespace PolicyEnforceParams {
363
373
 
364
374
  export declare namespace Policies {
365
375
  export {
366
- type PolicyEnforcementResultActionValue as PolicyEnforcementResultActionValue,
376
+ type PolicyEnforcementResultAction as PolicyEnforcementResultAction,
367
377
  type PolicyEnforceResponse as PolicyEnforceResponse,
368
378
  type PolicyEnforceParams as PolicyEnforceParams,
369
379
  };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.0.2'; // x-release-please-version
1
+ export const VERSION = '0.2.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.0.2";
1
+ export declare const VERSION = "0.2.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.0.2";
1
+ export declare const VERSION = "0.2.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.0.2'; // x-release-please-version
4
+ exports.VERSION = '0.2.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.0.2'; // x-release-please-version
1
+ export const VERSION = '0.2.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map