@crowdstrike/aidr 1.0.2

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 (51) hide show
  1. package/.editorconfig +9 -0
  2. package/.github/CODEOWNERS +1 -0
  3. package/.github/workflows/ci.yml +128 -0
  4. package/.pnpmfile.cjs +17 -0
  5. package/.releaserc.json +21 -0
  6. package/LICENSE.txt +21 -0
  7. package/README.md +3 -0
  8. package/biome.json +67 -0
  9. package/dist/chunk.cjs +34 -0
  10. package/dist/index.cjs +356 -0
  11. package/dist/index.d.cts +2347 -0
  12. package/dist/index.d.mts +2347 -0
  13. package/dist/index.mjs +354 -0
  14. package/dist/schemas/ai-guard.cjs +1000 -0
  15. package/dist/schemas/ai-guard.d.cts +1232 -0
  16. package/dist/schemas/ai-guard.d.mts +1232 -0
  17. package/dist/schemas/ai-guard.mjs +907 -0
  18. package/dist/schemas/index.cjs +7 -0
  19. package/dist/schemas/index.d.cts +64 -0
  20. package/dist/schemas/index.d.mts +64 -0
  21. package/dist/schemas/index.mjs +3 -0
  22. package/dist/schemas.cjs +139 -0
  23. package/dist/schemas.mjs +108 -0
  24. package/flake.lock +59 -0
  25. package/flake.nix +26 -0
  26. package/openapi-ts.config.ts +15 -0
  27. package/package.json +55 -0
  28. package/pnpm-workspace.yaml +3 -0
  29. package/scripts/generate-models +15 -0
  30. package/scripts/test +10 -0
  31. package/specs/ai-guard.openapi.json +3721 -0
  32. package/src/client.ts +441 -0
  33. package/src/core/error.ts +78 -0
  34. package/src/index.ts +2 -0
  35. package/src/internal/builtin-types.ts +18 -0
  36. package/src/internal/errors.ts +34 -0
  37. package/src/internal/headers.ts +100 -0
  38. package/src/internal/parse.ts +30 -0
  39. package/src/internal/request-options.ts +57 -0
  40. package/src/internal/types.ts +3 -0
  41. package/src/internal/utils/sleep.ts +3 -0
  42. package/src/internal/utils/values.ts +38 -0
  43. package/src/schemas/ai-guard.ts +1215 -0
  44. package/src/schemas/index.ts +114 -0
  45. package/src/services/ai-guard.ts +27 -0
  46. package/src/types/ai-guard.ts +2276 -0
  47. package/src/types/index.ts +161 -0
  48. package/tests/ai-guard.test.ts +29 -0
  49. package/tsconfig.json +26 -0
  50. package/tsdown.config.mts +14 -0
  51. package/vitest.config.mts +4 -0
@@ -0,0 +1,114 @@
1
+ import * as v from 'valibot';
2
+
3
+ const BaseAPIResponseSchema = {
4
+ request_id: v.string(),
5
+ request_time: v.string(),
6
+ response_time: v.string(),
7
+ status: v.string(),
8
+ };
9
+
10
+ export const ErrorCodeSchema = v.picklist([
11
+ 'FieldRequired',
12
+ 'InvalidString',
13
+ 'InvalidNumber',
14
+ 'InvalidInteger',
15
+ 'InvalidObject',
16
+ 'InvalidArray',
17
+ 'InvalidNull',
18
+ 'InvalidBool',
19
+ 'BadFormat',
20
+ 'BadFormatPangeaDuration',
21
+ 'BadFormatDateTime',
22
+ 'BadFormatTime',
23
+ 'BadFormatDate',
24
+ 'BadFormatEmail',
25
+ 'BadFormatHostname',
26
+ 'BadFormatIPv4',
27
+ 'BadFormatIPv6',
28
+ 'BadFormatIPAddress',
29
+ 'BadFormatUUID',
30
+ 'BadFormatURI',
31
+ 'BadFormatURIReference',
32
+ 'BadFormatIRI',
33
+ 'BadFormatIRIReference',
34
+ 'BadFormatJSONPointer',
35
+ 'BadFormatRelativeJSONPointer',
36
+ 'BadFormatRegex',
37
+ 'BadFormatJSONPath',
38
+ 'BadFormatBase64',
39
+ 'DoesNotMatchPattern',
40
+ 'DoesNotMatchPatternProperties',
41
+ 'NotEnumMember',
42
+ 'AboveMaxLength',
43
+ 'BelowMinLength',
44
+ 'AboveMaxItems',
45
+ 'BelowMinItems',
46
+ 'NotMultipleOf',
47
+ 'NotWithinRange',
48
+ 'UnexpectedProperty',
49
+ 'InvalidPropertyName',
50
+ 'AboveMaxProperties',
51
+ 'BelowMinProperties',
52
+ 'NotContains',
53
+ 'ContainsTooMany',
54
+ 'ContainsTooFew',
55
+ 'ItemNotUnique',
56
+ 'UnexpectedAdditionalItem',
57
+ 'InvalidConst',
58
+ 'IsDependentOn',
59
+ 'IsTooBig',
60
+ 'IsTooSmall',
61
+ 'ShouldNotBeValid',
62
+ 'NoUnevaluatedItems',
63
+ 'NoUnevaluatedProperties',
64
+ 'DoesNotExist',
65
+ 'IsReadOnly',
66
+ 'CannotAddToDefault',
67
+ 'MustProvideOne',
68
+ 'MutuallyExclusive',
69
+ 'BadState',
70
+ 'InaccessibleURI',
71
+ 'ProviderDisabled',
72
+ 'ConfigProjectMismatch',
73
+ 'ConfigServiceMismatch',
74
+ 'ConfigNotExist',
75
+ ]);
76
+
77
+ const ErrorDetailSchema = v.object({
78
+ code: ErrorCodeSchema,
79
+ detail: v.string(),
80
+ source: v.string(),
81
+ path: v.optional(v.string()),
82
+ });
83
+
84
+ export const AcceptedResponseSchema = v.object({
85
+ ...BaseAPIResponseSchema,
86
+ status: v.literal('Accepted'),
87
+ result: v.object({
88
+ ttl_mins: v.number(),
89
+ retry_counter: v.number(),
90
+ location: v.string(),
91
+ }),
92
+ });
93
+
94
+ export const ErrorResponseSchema = v.object({
95
+ ...BaseAPIResponseSchema,
96
+ status: v.string(),
97
+ result: v.nullable(v.array(ErrorDetailSchema)),
98
+ });
99
+
100
+ export const SuccessResponseSchema = <T extends v.GenericSchema>(
101
+ resultSchema: T
102
+ ) =>
103
+ v.object({
104
+ ...BaseAPIResponseSchema,
105
+ status: v.literal('Success'),
106
+ result: resultSchema,
107
+ });
108
+
109
+ export const APIResponseSchema = <T extends v.GenericSchema>(resultSchema: T) =>
110
+ v.union([
111
+ AcceptedResponseSchema,
112
+ SuccessResponseSchema(resultSchema),
113
+ ErrorResponseSchema,
114
+ ]);
@@ -0,0 +1,27 @@
1
+ import { Client } from '../client';
2
+ import type { RequestOptions } from '../internal/request-options';
3
+ import type { MaybeAcceptedResponse } from '../types';
4
+ import type {
5
+ AidrPostV1GuardChatCompletionsResponse,
6
+ ChatCompletionsGuard,
7
+ } from '../types/ai-guard';
8
+
9
+ export class AIGuard extends Client {
10
+ serviceName = 'aiguard';
11
+
12
+ /**
13
+ * Analyze and redact content to avoid manipulation of the model, addition of
14
+ * malicious content, and other undesirable data transfers.
15
+ */
16
+ guardChatCompletions(
17
+ body: ChatCompletionsGuard,
18
+ options?: RequestOptions
19
+ ): Promise<
20
+ MaybeAcceptedResponse<AidrPostV1GuardChatCompletionsResponse['result']>
21
+ > {
22
+ return this.post('/v1/guard_chat_completions', {
23
+ body,
24
+ ...options,
25
+ });
26
+ }
27
+ }