@papr/memory 1.8.3 → 1.10.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 (85) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -2
  3. package/client.d.mts +17 -5
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +17 -5
  6. package/client.d.ts.map +1 -1
  7. package/client.js +24 -11
  8. package/client.js.map +1 -1
  9. package/client.mjs +24 -11
  10. package/client.mjs.map +1 -1
  11. package/index.d.mts +1 -0
  12. package/index.d.ts +1 -0
  13. package/index.js +2 -0
  14. package/index.js.map +1 -1
  15. package/index.mjs +1 -0
  16. package/internal/request-options.d.mts +42 -0
  17. package/internal/request-options.d.mts.map +1 -1
  18. package/internal/request-options.d.ts +42 -0
  19. package/internal/request-options.d.ts.map +1 -1
  20. package/internal/request-options.js.map +1 -1
  21. package/internal/request-options.mjs.map +1 -1
  22. package/internal/uploads.js +1 -1
  23. package/internal/uploads.js.map +1 -1
  24. package/internal/uploads.mjs +1 -1
  25. package/internal/uploads.mjs.map +1 -1
  26. package/internal/utils/log.d.mts.map +1 -1
  27. package/internal/utils/log.d.ts.map +1 -1
  28. package/internal/utils/log.js +4 -3
  29. package/internal/utils/log.js.map +1 -1
  30. package/internal/utils/log.mjs +4 -3
  31. package/internal/utils/log.mjs.map +1 -1
  32. package/internal/utils/path.d.mts.map +1 -1
  33. package/internal/utils/path.d.ts.map +1 -1
  34. package/internal/utils/path.js +26 -5
  35. package/internal/utils/path.js.map +1 -1
  36. package/internal/utils/path.mjs +26 -5
  37. package/internal/utils/path.mjs.map +1 -1
  38. package/package.json +1 -1
  39. package/resources/feedback.d.mts +333 -0
  40. package/resources/feedback.d.mts.map +1 -0
  41. package/resources/feedback.d.ts +333 -0
  42. package/resources/feedback.d.ts.map +1 -0
  43. package/resources/feedback.js +108 -0
  44. package/resources/feedback.js.map +1 -0
  45. package/resources/feedback.mjs +104 -0
  46. package/resources/feedback.mjs.map +1 -0
  47. package/resources/index.d.mts +1 -0
  48. package/resources/index.d.mts.map +1 -1
  49. package/resources/index.d.ts +1 -0
  50. package/resources/index.d.ts.map +1 -1
  51. package/resources/index.js +3 -1
  52. package/resources/index.js.map +1 -1
  53. package/resources/index.mjs +1 -0
  54. package/resources/index.mjs.map +1 -1
  55. package/resources/memory.d.mts +66 -12
  56. package/resources/memory.d.mts.map +1 -1
  57. package/resources/memory.d.ts +66 -12
  58. package/resources/memory.d.ts.map +1 -1
  59. package/resources/memory.js +11 -0
  60. package/resources/memory.js.map +1 -1
  61. package/resources/memory.mjs +11 -0
  62. package/resources/memory.mjs.map +1 -1
  63. package/resources/user.d.mts +12 -4
  64. package/resources/user.d.mts.map +1 -1
  65. package/resources/user.d.ts +12 -4
  66. package/resources/user.d.ts.map +1 -1
  67. package/src/client.ts +55 -14
  68. package/src/index.ts +2 -0
  69. package/src/internal/request-options.ts +53 -0
  70. package/src/internal/uploads.ts +1 -1
  71. package/src/internal/utils/log.ts +3 -2
  72. package/src/internal/utils/path.ts +32 -7
  73. package/src/resources/feedback.ts +424 -0
  74. package/src/resources/index.ts +9 -0
  75. package/src/resources/memory.ts +74 -13
  76. package/src/resources/user.ts +4 -4
  77. package/src/version.ts +1 -1
  78. package/version.d.mts +1 -1
  79. package/version.d.mts.map +1 -1
  80. package/version.d.ts +1 -1
  81. package/version.d.ts.map +1 -1
  82. package/version.js +1 -1
  83. package/version.js.map +1 -1
  84. package/version.mjs +1 -1
  85. package/version.mjs.map +1 -1
@@ -9,17 +9,70 @@ import { type HeadersLike } from './headers';
9
9
  export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };
10
10
 
11
11
  export type RequestOptions = {
12
+ /**
13
+ * The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
14
+ */
12
15
  method?: HTTPMethod;
16
+
17
+ /**
18
+ * The URL path for the request.
19
+ *
20
+ * @example "/v1/foo"
21
+ */
13
22
  path?: string;
23
+
24
+ /**
25
+ * Query parameters to include in the request URL.
26
+ */
14
27
  query?: object | undefined | null;
28
+
29
+ /**
30
+ * The request body. Can be a string, JSON object, FormData, or other supported types.
31
+ */
15
32
  body?: unknown;
33
+
34
+ /**
35
+ * HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
36
+ */
16
37
  headers?: HeadersLike;
38
+
39
+ /**
40
+ * The maximum number of times that the client will retry a request in case of a
41
+ * temporary failure, like a network error or a 5XX error from the server.
42
+ *
43
+ * @default 2
44
+ */
17
45
  maxRetries?: number;
46
+
18
47
  stream?: boolean | undefined;
48
+
49
+ /**
50
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
51
+ * from the server before timing out a single request.
52
+ *
53
+ * @unit milliseconds
54
+ */
19
55
  timeout?: number;
56
+
57
+ /**
58
+ * Additional `RequestInit` options to be passed to the underlying `fetch` call.
59
+ * These options will be merged with the client's default fetch options.
60
+ */
20
61
  fetchOptions?: MergedRequestInit;
62
+
63
+ /**
64
+ * An AbortSignal that can be used to cancel the request.
65
+ */
21
66
  signal?: AbortSignal | undefined | null;
67
+
68
+ /**
69
+ * A unique key for this request to enable idempotency.
70
+ */
22
71
  idempotencyKey?: string;
72
+
73
+ /**
74
+ * Override the default base URL for this specific request.
75
+ */
23
76
  defaultBaseURL?: string | undefined;
24
77
 
25
78
  __binaryResponse?: boolean | undefined;
@@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
90
90
  return { ...opts, body: await createForm(opts.body, fetch) };
91
91
  };
92
92
 
93
- const supportsFormDataMap = /** @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
93
+ const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
94
94
 
95
95
  /**
96
96
  * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
@@ -58,7 +58,7 @@ const noopLogger = {
58
58
  debug: noop,
59
59
  };
60
60
 
61
- let cachedLoggers = /** @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
61
+ let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
62
62
 
63
63
  export function loggerFor(client: Papr): Logger {
64
64
  const logger = client.logger;
@@ -106,8 +106,9 @@ export const formatRequestDetails = (details: {
106
106
  ([name, value]) => [
107
107
  name,
108
108
  (
109
- name.toLowerCase() === 'x-api-key' ||
110
109
  name.toLowerCase() === 'authorization' ||
110
+ name.toLowerCase() === 'x-session-token' ||
111
+ name.toLowerCase() === 'x-api-key' ||
111
112
  name.toLowerCase() === 'cookie' ||
112
113
  name.toLowerCase() === 'set-cookie'
113
114
  ) ?
@@ -12,25 +12,43 @@ export function encodeURIPath(str: string) {
12
12
  return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
13
13
  }
14
14
 
15
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
16
+
15
17
  export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
16
18
  function path(statics: readonly string[], ...params: readonly unknown[]): string {
17
19
  // If there are no params, no processing is needed.
18
20
  if (statics.length === 1) return statics[0]!;
19
21
 
20
22
  let postPath = false;
23
+ const invalidSegments = [];
21
24
  const path = statics.reduce((previousValue, currentValue, index) => {
22
25
  if (/[?#]/.test(currentValue)) {
23
26
  postPath = true;
24
27
  }
25
- return (
26
- previousValue +
27
- currentValue +
28
- (index === params.length ? '' : (postPath ? encodeURIComponent : pathEncoder)(String(params[index])))
29
- );
28
+ const value = params[index];
29
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
30
+ if (
31
+ index !== params.length &&
32
+ (value == null ||
33
+ (typeof value === 'object' &&
34
+ // handle values from other realms
35
+ value.toString ===
36
+ Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
37
+ ?.toString))
38
+ ) {
39
+ encoded = value + '';
40
+ invalidSegments.push({
41
+ start: previousValue.length + currentValue.length,
42
+ length: encoded.length,
43
+ error: `Value of type ${Object.prototype.toString
44
+ .call(value)
45
+ .slice(8, -1)} is not a valid path parameter`,
46
+ });
47
+ }
48
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
30
49
  }, '');
31
50
 
32
51
  const pathOnly = path.split(/[?#]/, 1)[0]!;
33
- const invalidSegments = [];
34
52
  const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
35
53
  let match;
36
54
 
@@ -39,9 +57,12 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
39
57
  invalidSegments.push({
40
58
  start: match.index,
41
59
  length: match[0].length,
60
+ error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
42
61
  });
43
62
  }
44
63
 
64
+ invalidSegments.sort((a, b) => a.start - b.start);
65
+
45
66
  if (invalidSegments.length > 0) {
46
67
  let lastEnd = 0;
47
68
  const underline = invalidSegments.reduce((acc, segment) => {
@@ -51,7 +72,11 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
51
72
  return acc + spaces + arrows;
52
73
  }, '');
53
74
 
54
- throw new PaprError(`Path parameters result in path with invalid segments:\n${path}\n${underline}`);
75
+ throw new PaprError(
76
+ `Path parameters result in path with invalid segments:\n${invalidSegments
77
+ .map((e) => e.error)
78
+ .join('\n')}\n${path}\n${underline}`,
79
+ );
55
80
  }
56
81
 
57
82
  return path;
@@ -0,0 +1,424 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import { APIPromise } from '../core/api-promise';
5
+ import { RequestOptions } from '../internal/request-options';
6
+ import { path } from '../internal/utils/path';
7
+
8
+ export class Feedback extends APIResource {
9
+ /**
10
+ * Retrieve feedback by ID.
11
+ *
12
+ * This endpoint allows developers to fetch feedback details by feedback ID.
13
+ * Only the user who created the feedback or users with appropriate permissions can access it.
14
+ *
15
+ * **Authentication Required**:
16
+ * One of the following authentication methods must be used:
17
+ * - Bearer token in `Authorization` header
18
+ * - API Key in `X-API-Key` header
19
+ * - Session token in `X-Session-Token` header
20
+ *
21
+ * **Required Headers**:
22
+ * - X-Client-Type: (e.g., 'papr_plugin', 'browser_extension')
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const feedbackResponse = await client.feedback.getByID(
27
+ * 'feedback_id',
28
+ * );
29
+ * ```
30
+ */
31
+ getByID(feedbackID: string, options?: RequestOptions): APIPromise<FeedbackResponse> {
32
+ return this._client.get(path`/v1/feedback/${feedbackID}`, options);
33
+ }
34
+
35
+ /**
36
+ * Submit feedback on search results to help improve model performance.
37
+ *
38
+ * This endpoint allows developers to provide feedback on:
39
+ * - Overall answer quality (thumbs up/down, ratings)
40
+ * - Specific memory relevance and accuracy
41
+ * - User engagement signals (copy, save, create document actions)
42
+ * - Corrections and improvements
43
+ *
44
+ * The feedback is used to train and improve:
45
+ * - Router model tier predictions
46
+ * - Memory retrieval ranking
47
+ * - Answer generation quality
48
+ * - Agentic graph search performance
49
+ *
50
+ * **Authentication Required**:
51
+ * One of the following authentication methods must be used:
52
+ * - Bearer token in `Authorization` header
53
+ * - API Key in `X-API-Key` header
54
+ * - Session token in `X-Session-Token` header
55
+ *
56
+ * **Required Headers**:
57
+ * - Content-Type: application/json
58
+ * - X-Client-Type: (e.g., 'papr_plugin', 'browser_extension')
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const feedbackResponse = await client.feedback.submit({
63
+ * feedbackData: {
64
+ * feedbackSource: 'inline',
65
+ * feedbackType: 'thumbs_up',
66
+ * },
67
+ * search_id: 'abc123def456',
68
+ * });
69
+ * ```
70
+ */
71
+ submit(body: FeedbackSubmitParams, options?: RequestOptions): APIPromise<FeedbackResponse> {
72
+ return this._client.post('/v1/feedback', { body, ...options });
73
+ }
74
+
75
+ /**
76
+ * Submit multiple feedback items in a single request.
77
+ *
78
+ * Useful for submitting session-end feedback or bulk feedback collection.
79
+ * Each feedback item is processed independently, so partial success is possible.
80
+ *
81
+ * **Authentication Required**:
82
+ * One of the following authentication methods must be used:
83
+ * - Bearer token in `Authorization` header
84
+ * - API Key in `X-API-Key` header
85
+ * - Session token in `X-Session-Token` header
86
+ *
87
+ * **Required Headers**:
88
+ * - Content-Type: application/json
89
+ * - X-Client-Type: (e.g., 'papr_plugin', 'browser_extension')
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const batchResponse = await client.feedback.submitBatch({
94
+ * feedback_items: [
95
+ * {
96
+ * feedbackData: {
97
+ * feedbackSource: 'inline',
98
+ * feedbackType: 'thumbs_up',
99
+ * },
100
+ * search_id: 'abc123def456',
101
+ * },
102
+ * ],
103
+ * });
104
+ * ```
105
+ */
106
+ submitBatch(body: FeedbackSubmitBatchParams, options?: RequestOptions): APIPromise<BatchResponse> {
107
+ return this._client.post('/v1/feedback/batch', { body, ...options });
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Request model for submitting multiple feedback items
113
+ */
114
+ export interface BatchRequest {
115
+ /**
116
+ * List of feedback items to submit
117
+ */
118
+ feedback_items: Array<FeedbackRequest>;
119
+
120
+ /**
121
+ * Session-level context for batch feedback
122
+ */
123
+ session_context?: { [key: string]: unknown } | null;
124
+ }
125
+
126
+ /**
127
+ * Response model for batch feedback submission
128
+ */
129
+ export interface BatchResponse {
130
+ /**
131
+ * HTTP status code
132
+ */
133
+ code: number;
134
+
135
+ /**
136
+ * Human-readable message
137
+ */
138
+ message: string;
139
+
140
+ /**
141
+ * 'success' or 'error'
142
+ */
143
+ status: string;
144
+
145
+ /**
146
+ * Error message if status is 'error'
147
+ */
148
+ error?: string | null;
149
+
150
+ /**
151
+ * List of error details
152
+ */
153
+ errors?: Array<{ [key: string]: unknown }>;
154
+
155
+ /**
156
+ * Number of failed feedback items
157
+ */
158
+ failed_count?: number;
159
+
160
+ /**
161
+ * List of feedback IDs
162
+ */
163
+ feedback_ids?: Array<string>;
164
+
165
+ /**
166
+ * Number of successfully processed feedback items
167
+ */
168
+ successful_count?: number;
169
+ }
170
+
171
+ /**
172
+ * Request model for submitting feedback on search results
173
+ */
174
+ export interface FeedbackRequest {
175
+ /**
176
+ * The feedback data containing all feedback information
177
+ */
178
+ feedbackData: FeedbackRequest.FeedbackData;
179
+
180
+ /**
181
+ * The search_id from SearchResponse that this feedback relates to
182
+ */
183
+ search_id: string;
184
+
185
+ /**
186
+ * External user ID for developer API keys acting on behalf of end users
187
+ */
188
+ external_user_id?: string | null;
189
+
190
+ /**
191
+ * Internal user ID (if not provided, will be resolved from authentication)
192
+ */
193
+ user_id?: string | null;
194
+ }
195
+
196
+ export namespace FeedbackRequest {
197
+ /**
198
+ * The feedback data containing all feedback information
199
+ */
200
+ export interface FeedbackData {
201
+ /**
202
+ * Where the feedback was provided from
203
+ */
204
+ feedbackSource: 'inline' | 'post_query' | 'session_end' | 'memory_citation' | 'answer_panel';
205
+
206
+ /**
207
+ * Types of feedback that can be provided
208
+ */
209
+ feedbackType:
210
+ | 'thumbs_up'
211
+ | 'thumbs_down'
212
+ | 'rating'
213
+ | 'correction'
214
+ | 'report'
215
+ | 'copy_action'
216
+ | 'save_action'
217
+ | 'create_document'
218
+ | 'memory_relevance'
219
+ | 'answer_quality';
220
+
221
+ /**
222
+ * A pointer to a Parse object
223
+ */
224
+ assistantMessage?: FeedbackData.AssistantMessage | null;
225
+
226
+ citedMemoryIds?: Array<string> | null;
227
+
228
+ citedNodeIds?: Array<string> | null;
229
+
230
+ feedbackImpact?: string | null;
231
+
232
+ feedbackProcessed?: boolean | null;
233
+
234
+ feedbackScore?: number | null;
235
+
236
+ feedbackText?: string | null;
237
+
238
+ feedbackValue?: string | null;
239
+
240
+ /**
241
+ * A pointer to a Parse object
242
+ */
243
+ userMessage?: FeedbackData.UserMessage | null;
244
+ }
245
+
246
+ export namespace FeedbackData {
247
+ /**
248
+ * A pointer to a Parse object
249
+ */
250
+ export interface AssistantMessage {
251
+ className: string;
252
+
253
+ objectId: string;
254
+
255
+ __type?: string;
256
+ }
257
+
258
+ /**
259
+ * A pointer to a Parse object
260
+ */
261
+ export interface UserMessage {
262
+ className: string;
263
+
264
+ objectId: string;
265
+
266
+ __type?: string;
267
+ }
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Response model for feedback submission
273
+ */
274
+ export interface FeedbackResponse {
275
+ /**
276
+ * HTTP status code
277
+ */
278
+ code: number;
279
+
280
+ /**
281
+ * Human-readable message
282
+ */
283
+ message: string;
284
+
285
+ /**
286
+ * 'success' or 'error'
287
+ */
288
+ status: string;
289
+
290
+ /**
291
+ * Additional error details
292
+ */
293
+ details?: { [key: string]: unknown } | null;
294
+
295
+ /**
296
+ * Error message if status is 'error'
297
+ */
298
+ error?: string | null;
299
+
300
+ /**
301
+ * Unique feedback ID
302
+ */
303
+ feedback_id?: string | null;
304
+ }
305
+
306
+ export interface FeedbackSubmitParams {
307
+ /**
308
+ * The feedback data containing all feedback information
309
+ */
310
+ feedbackData: FeedbackSubmitParams.FeedbackData;
311
+
312
+ /**
313
+ * The search_id from SearchResponse that this feedback relates to
314
+ */
315
+ search_id: string;
316
+
317
+ /**
318
+ * External user ID for developer API keys acting on behalf of end users
319
+ */
320
+ external_user_id?: string | null;
321
+
322
+ /**
323
+ * Internal user ID (if not provided, will be resolved from authentication)
324
+ */
325
+ user_id?: string | null;
326
+ }
327
+
328
+ export namespace FeedbackSubmitParams {
329
+ /**
330
+ * The feedback data containing all feedback information
331
+ */
332
+ export interface FeedbackData {
333
+ /**
334
+ * Where the feedback was provided from
335
+ */
336
+ feedbackSource: 'inline' | 'post_query' | 'session_end' | 'memory_citation' | 'answer_panel';
337
+
338
+ /**
339
+ * Types of feedback that can be provided
340
+ */
341
+ feedbackType:
342
+ | 'thumbs_up'
343
+ | 'thumbs_down'
344
+ | 'rating'
345
+ | 'correction'
346
+ | 'report'
347
+ | 'copy_action'
348
+ | 'save_action'
349
+ | 'create_document'
350
+ | 'memory_relevance'
351
+ | 'answer_quality';
352
+
353
+ /**
354
+ * A pointer to a Parse object
355
+ */
356
+ assistantMessage?: FeedbackData.AssistantMessage | null;
357
+
358
+ citedMemoryIds?: Array<string> | null;
359
+
360
+ citedNodeIds?: Array<string> | null;
361
+
362
+ feedbackImpact?: string | null;
363
+
364
+ feedbackProcessed?: boolean | null;
365
+
366
+ feedbackScore?: number | null;
367
+
368
+ feedbackText?: string | null;
369
+
370
+ feedbackValue?: string | null;
371
+
372
+ /**
373
+ * A pointer to a Parse object
374
+ */
375
+ userMessage?: FeedbackData.UserMessage | null;
376
+ }
377
+
378
+ export namespace FeedbackData {
379
+ /**
380
+ * A pointer to a Parse object
381
+ */
382
+ export interface AssistantMessage {
383
+ className: string;
384
+
385
+ objectId: string;
386
+
387
+ __type?: string;
388
+ }
389
+
390
+ /**
391
+ * A pointer to a Parse object
392
+ */
393
+ export interface UserMessage {
394
+ className: string;
395
+
396
+ objectId: string;
397
+
398
+ __type?: string;
399
+ }
400
+ }
401
+ }
402
+
403
+ export interface FeedbackSubmitBatchParams {
404
+ /**
405
+ * List of feedback items to submit
406
+ */
407
+ feedback_items: Array<FeedbackRequest>;
408
+
409
+ /**
410
+ * Session-level context for batch feedback
411
+ */
412
+ session_context?: { [key: string]: unknown } | null;
413
+ }
414
+
415
+ export declare namespace Feedback {
416
+ export {
417
+ type BatchRequest as BatchRequest,
418
+ type BatchResponse as BatchResponse,
419
+ type FeedbackRequest as FeedbackRequest,
420
+ type FeedbackResponse as FeedbackResponse,
421
+ type FeedbackSubmitParams as FeedbackSubmitParams,
422
+ type FeedbackSubmitBatchParams as FeedbackSubmitBatchParams,
423
+ };
424
+ }
@@ -1,5 +1,14 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
+ export {
4
+ Feedback,
5
+ type BatchRequest,
6
+ type BatchResponse,
7
+ type FeedbackRequest,
8
+ type FeedbackResponse,
9
+ type FeedbackSubmitParams,
10
+ type FeedbackSubmitBatchParams,
11
+ } from './feedback';
3
12
  export {
4
13
  Memory,
5
14
  type AddMemory,