@safenest/sdk 1.0.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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +601 -0
  3. package/dist/client.d.ts +228 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +536 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/constants.d.ts +127 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +160 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/errors.d.ts +52 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +87 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +5 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +7 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/types/analysis.d.ts +39 -0
  20. package/dist/types/analysis.d.ts.map +1 -0
  21. package/dist/types/analysis.js +4 -0
  22. package/dist/types/analysis.js.map +1 -0
  23. package/dist/types/guidance.d.ts +33 -0
  24. package/dist/types/guidance.d.ts.map +1 -0
  25. package/dist/types/guidance.js +2 -0
  26. package/dist/types/guidance.js.map +1 -0
  27. package/dist/types/index.d.ts +55 -0
  28. package/dist/types/index.d.ts.map +1 -0
  29. package/dist/types/index.js +7 -0
  30. package/dist/types/index.js.map +1 -0
  31. package/dist/types/policy.d.ts +54 -0
  32. package/dist/types/policy.d.ts.map +1 -0
  33. package/dist/types/policy.js +5 -0
  34. package/dist/types/policy.js.map +1 -0
  35. package/dist/types/reports.d.ts +42 -0
  36. package/dist/types/reports.d.ts.map +1 -0
  37. package/dist/types/reports.js +2 -0
  38. package/dist/types/reports.js.map +1 -0
  39. package/dist/types/safety.d.ts +135 -0
  40. package/dist/types/safety.d.ts.map +1 -0
  41. package/dist/types/safety.js +4 -0
  42. package/dist/types/safety.js.map +1 -0
  43. package/dist/utils/retry.d.ts +17 -0
  44. package/dist/utils/retry.d.ts.map +1 -0
  45. package/dist/utils/retry.js +61 -0
  46. package/dist/utils/retry.js.map +1 -0
  47. package/package.json +67 -0
@@ -0,0 +1,228 @@
1
+ import { SafeNestOptions, Usage, DetectBullyingInput, BullyingResult, DetectGroomingInput, GroomingResult, DetectUnsafeInput, UnsafeResult, AnalyzeInput, AnalyzeResult, ContextInput, AnalyzeEmotionsInput, EmotionsResult, GetActionPlanInput, ActionPlanResult, GenerateReportInput, ReportResult, PolicyConfig, PolicyConfigResponse } from './types/index.js';
2
+ /**
3
+ * SafeNest - AI-powered child safety analysis
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import { SafeNest } from '@safenest/sdk'
8
+ *
9
+ * const safenest = new SafeNest(process.env.SAFENEST_API_KEY)
10
+ *
11
+ * // Detect bullying
12
+ * const result = await safenest.detectBullying({
13
+ * content: "You're not welcome here",
14
+ * context: 'chat'
15
+ * })
16
+ *
17
+ * if (result.is_bullying) {
18
+ * console.log('Severity:', result.severity)
19
+ * console.log('Rationale:', result.rationale)
20
+ * }
21
+ *
22
+ * // Check usage
23
+ * console.log(safenest.usage) // { limit: 10000, used: 5234, remaining: 4766 }
24
+ * ```
25
+ */
26
+ export declare class SafeNest {
27
+ private readonly apiKey;
28
+ private readonly timeout;
29
+ private readonly retries;
30
+ private readonly retryDelay;
31
+ private _usage;
32
+ private _lastRequestId;
33
+ private _lastLatencyMs;
34
+ /**
35
+ * Create a new SafeNest client
36
+ *
37
+ * @param apiKey - Your SafeNest API key
38
+ * @param options - Optional configuration
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * // Simple usage
43
+ * const safenest = new SafeNest('your-api-key')
44
+ *
45
+ * // With options
46
+ * const safenest = new SafeNest('your-api-key', {
47
+ * timeout: 10000
48
+ * })
49
+ * ```
50
+ */
51
+ constructor(apiKey: string, options?: SafeNestOptions);
52
+ /**
53
+ * Get current usage stats from the last request
54
+ */
55
+ get usage(): Usage | null;
56
+ /**
57
+ * Get the request ID from the last request
58
+ */
59
+ get lastRequestId(): string | null;
60
+ /**
61
+ * Get the latency from the last request in milliseconds
62
+ */
63
+ get lastLatencyMs(): number | null;
64
+ /**
65
+ * Validate content length to prevent abuse
66
+ */
67
+ private validateContent;
68
+ /**
69
+ * Validate messages array
70
+ */
71
+ private validateMessages;
72
+ /**
73
+ * Normalize context input to API format
74
+ */
75
+ private normalizeContext;
76
+ /**
77
+ * Make an authenticated request to the API
78
+ */
79
+ private request;
80
+ /**
81
+ * Handle error responses from the API
82
+ */
83
+ private handleErrorResponse;
84
+ /**
85
+ * Make a request with retry logic
86
+ */
87
+ private requestWithRetry;
88
+ /**
89
+ * Detect bullying in content
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const result = await safenest.detectBullying({
94
+ * content: "Nobody likes you, loser",
95
+ * context: 'chat'
96
+ * })
97
+ *
98
+ * if (result.is_bullying && result.severity === 'high') {
99
+ * console.log('High severity bullying detected')
100
+ * console.log('Rationale:', result.rationale)
101
+ * }
102
+ * ```
103
+ */
104
+ detectBullying(input: DetectBullyingInput): Promise<BullyingResult>;
105
+ /**
106
+ * Detect grooming patterns in a conversation
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const result = await safenest.detectGrooming({
111
+ * messages: [
112
+ * { role: 'adult', content: "Don't tell your parents" },
113
+ * { role: 'child', content: "Ok" }
114
+ * ],
115
+ * childAge: 12
116
+ * })
117
+ *
118
+ * if (result.grooming_risk === 'high') {
119
+ * console.log('Flags:', result.flags)
120
+ * }
121
+ * ```
122
+ */
123
+ detectGrooming(input: DetectGroomingInput): Promise<GroomingResult>;
124
+ /**
125
+ * Detect unsafe content (self-harm, violence, hate speech, etc.)
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const result = await safenest.detectUnsafe({
130
+ * content: "I want to hurt myself"
131
+ * })
132
+ *
133
+ * if (result.unsafe && result.categories.includes('self_harm')) {
134
+ * console.log('Show crisis resources')
135
+ * }
136
+ * ```
137
+ */
138
+ detectUnsafe(input: DetectUnsafeInput): Promise<UnsafeResult>;
139
+ /**
140
+ * Quick analysis - runs bullying and unsafe detection, returns combined result
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const result = await safenest.analyze("Some user message")
145
+ *
146
+ * if (result.risk_level !== 'safe') {
147
+ * console.log('Risk:', result.risk_level)
148
+ * console.log('Summary:', result.summary)
149
+ * }
150
+ * ```
151
+ */
152
+ analyze(content: string, context?: ContextInput): Promise<AnalyzeResult>;
153
+ analyze(input: AnalyzeInput): Promise<AnalyzeResult>;
154
+ /**
155
+ * Analyze emotions in content or conversation
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const result = await safenest.analyzeEmotions({
160
+ * content: "I'm so stressed about everything"
161
+ * })
162
+ *
163
+ * console.log('Emotions:', result.dominant_emotions)
164
+ * console.log('Trend:', result.trend)
165
+ * ```
166
+ */
167
+ analyzeEmotions(input: AnalyzeEmotionsInput): Promise<EmotionsResult>;
168
+ /**
169
+ * Get age-appropriate action guidance for a situation
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * const plan = await safenest.getActionPlan({
174
+ * situation: 'Someone is spreading rumors about me',
175
+ * childAge: 12,
176
+ * audience: 'child'
177
+ * })
178
+ *
179
+ * console.log('Steps:', plan.steps)
180
+ * ```
181
+ */
182
+ getActionPlan(input: GetActionPlanInput): Promise<ActionPlanResult>;
183
+ /**
184
+ * Generate an incident report from messages
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const report = await safenest.generateReport({
189
+ * messages: [
190
+ * { sender: 'user1', content: 'Harmful message' },
191
+ * { sender: 'child', content: 'Response' }
192
+ * ],
193
+ * childAge: 14
194
+ * })
195
+ *
196
+ * console.log('Summary:', report.summary)
197
+ * console.log('Risk:', report.risk_level)
198
+ * console.log('Next steps:', report.recommended_next_steps)
199
+ * ```
200
+ */
201
+ generateReport(input: GenerateReportInput): Promise<ReportResult>;
202
+ /**
203
+ * Get the current policy configuration
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const policy = await safenest.getPolicy()
208
+ * console.log('Bullying enabled:', policy.config?.bullying.enabled)
209
+ * ```
210
+ */
211
+ getPolicy(): Promise<PolicyConfigResponse>;
212
+ /**
213
+ * Update the policy configuration
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * await safenest.setPolicy({
218
+ * bullying: {
219
+ * enabled: true,
220
+ * minRiskScoreToFlag: 0.5
221
+ * }
222
+ * })
223
+ * ```
224
+ */
225
+ setPolicy(config: PolicyConfig): Promise<PolicyConfigResponse>;
226
+ }
227
+ export { SafeNest as SafeNestClient };
228
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,KAAK,EAGL,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EAEZ,oBAAoB,EACpB,cAAc,EAEd,kBAAkB,EAClB,gBAAgB,EAEhB,mBAAmB,EACnB,YAAY,EAEZ,YAAY,EACZ,oBAAoB,EACvB,MAAM,kBAAkB,CAAC;AA0B1B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,QAAQ;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAEpC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,cAAc,CAAuB;IAE7C;;;;;;;;;;;;;;;;OAgBG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;IAuBzD;;OAEG;IACH,IAAI,KAAK,IAAI,KAAK,GAAG,IAAI,CAExB;IAED;;OAEG;IACH,IAAI,aAAa,IA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