conversationalist 0.0.7 → 0.0.8

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 (97) hide show
  1. package/README.md +150 -90
  2. package/dist/adapters/anthropic/index.d.ts +11 -6
  3. package/dist/adapters/anthropic/index.d.ts.map +1 -1
  4. package/dist/adapters/anthropic/index.js +16 -3
  5. package/dist/adapters/anthropic/index.js.map +5 -4
  6. package/dist/adapters/gemini/index.d.ts +2 -2
  7. package/dist/adapters/gemini/index.d.ts.map +1 -1
  8. package/dist/adapters/gemini/index.js +52 -9
  9. package/dist/adapters/gemini/index.js.map +5 -4
  10. package/dist/adapters/openai/index.d.ts +32 -5
  11. package/dist/adapters/openai/index.d.ts.map +1 -1
  12. package/dist/adapters/openai/index.js +30 -8
  13. package/dist/adapters/openai/index.js.map +5 -4
  14. package/dist/context.d.ts.map +1 -1
  15. package/dist/conversation/append.d.ts +4 -4
  16. package/dist/conversation/append.d.ts.map +1 -1
  17. package/dist/conversation/create.d.ts +2 -3
  18. package/dist/conversation/create.d.ts.map +1 -1
  19. package/dist/conversation/index.d.ts +2 -2
  20. package/dist/conversation/index.d.ts.map +1 -1
  21. package/dist/conversation/modify.d.ts.map +1 -1
  22. package/dist/conversation/query.d.ts +9 -5
  23. package/dist/conversation/query.d.ts.map +1 -1
  24. package/dist/conversation/serialization.d.ts +6 -28
  25. package/dist/conversation/serialization.d.ts.map +1 -1
  26. package/dist/conversation/system-messages.d.ts +3 -3
  27. package/dist/conversation/system-messages.d.ts.map +1 -1
  28. package/dist/conversation/transform.d.ts.map +1 -1
  29. package/dist/conversation.d.ts +74 -18
  30. package/dist/conversation.d.ts.map +1 -1
  31. package/dist/export/index.d.ts +7 -0
  32. package/dist/export/index.d.ts.map +1 -0
  33. package/dist/export/index.js +3762 -0
  34. package/dist/export/index.js.map +62 -0
  35. package/dist/history.d.ts +102 -24
  36. package/dist/history.d.ts.map +1 -1
  37. package/dist/index.d.ts +7 -8
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +392 -4075
  40. package/dist/index.js.map +15 -60
  41. package/dist/markdown/index.d.ts +15 -0
  42. package/dist/markdown/index.d.ts.map +1 -0
  43. package/dist/markdown/index.js +4969 -0
  44. package/dist/markdown/index.js.map +69 -0
  45. package/dist/message.d.ts +1 -1
  46. package/dist/message.d.ts.map +1 -1
  47. package/dist/multi-modal.d.ts +3 -0
  48. package/dist/multi-modal.d.ts.map +1 -1
  49. package/dist/plugins/index.d.ts +1 -1
  50. package/dist/plugins/index.d.ts.map +1 -1
  51. package/dist/plugins/index.js +59 -0
  52. package/dist/plugins/index.js.map +10 -0
  53. package/dist/plugins/pii-redaction.d.ts +10 -1
  54. package/dist/plugins/pii-redaction.d.ts.map +1 -1
  55. package/dist/redaction/index.d.ts +2 -0
  56. package/dist/redaction/index.d.ts.map +1 -0
  57. package/dist/redaction/index.js +59 -0
  58. package/dist/redaction/index.js.map +10 -0
  59. package/dist/schemas/index.d.ts +2 -0
  60. package/dist/schemas/index.d.ts.map +1 -0
  61. package/dist/schemas/index.js +114 -0
  62. package/dist/schemas/index.js.map +10 -0
  63. package/dist/schemas.d.ts +324 -15
  64. package/dist/schemas.d.ts.map +1 -1
  65. package/dist/sort/index.d.ts +2 -0
  66. package/dist/sort/index.d.ts.map +1 -0
  67. package/dist/sort/index.js +32 -0
  68. package/dist/sort/index.js.map +10 -0
  69. package/dist/streaming.d.ts +3 -3
  70. package/dist/streaming.d.ts.map +1 -1
  71. package/dist/types.d.ts +72 -50
  72. package/dist/types.d.ts.map +1 -1
  73. package/dist/utilities/index.d.ts +1 -3
  74. package/dist/utilities/index.d.ts.map +1 -1
  75. package/dist/utilities/line-endings.d.ts +5 -0
  76. package/dist/utilities/line-endings.d.ts.map +1 -0
  77. package/dist/utilities/markdown.d.ts +1 -1
  78. package/dist/utilities/markdown.d.ts.map +1 -1
  79. package/dist/utilities/message-store.d.ts +6 -0
  80. package/dist/utilities/message-store.d.ts.map +1 -0
  81. package/dist/utilities/message.d.ts +9 -3
  82. package/dist/utilities/message.d.ts.map +1 -1
  83. package/dist/utilities/tool-calls.d.ts +4 -4
  84. package/dist/utilities/tool-calls.d.ts.map +1 -1
  85. package/dist/utilities/tool-results.d.ts +10 -0
  86. package/dist/utilities/tool-results.d.ts.map +1 -0
  87. package/dist/utilities/transient.d.ts +2 -2
  88. package/dist/utilities/transient.d.ts.map +1 -1
  89. package/dist/utilities.d.ts +3 -5
  90. package/dist/utilities.d.ts.map +1 -1
  91. package/dist/versioning/index.d.ts +3 -0
  92. package/dist/versioning/index.d.ts.map +1 -0
  93. package/dist/versioning/index.js +58 -0
  94. package/dist/versioning/index.js.map +11 -0
  95. package/dist/with-conversation.d.ts +8 -8
  96. package/dist/with-conversation.d.ts.map +1 -1
  97. package/package.json +26 -1
package/dist/message.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { createMessage, messageHasImages, messageParts, messageText, messageToJSON, messageToString, } from './utilities';
1
+ export { createMessage, isAssistantMessage, messageHasImages, messageParts, messageText, messageToJSON, messageToString, } from './utilities';
2
2
  //# sourceMappingURL=message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,aAAa,CAAC"}
@@ -10,6 +10,9 @@ export interface TextContent {
10
10
  type: 'text';
11
11
  text: string;
12
12
  }
13
+ /**
14
+ * ImageContent is a convenience type for image parts in multi-modal content.
15
+ */
13
16
  export interface ImageContent {
14
17
  type: 'image';
15
18
  url: string;
@@ -1 +1 @@
1
- {"version":3,"file":"multi-modal.d.ts","sourceRoot":"","sources":["../src/multi-modal.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,CAWhF;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC,iBAAiB,CAAC,GACjD,MAAM,GAAG,iBAAiB,EAAE,CAK9B"}
1
+ {"version":3,"file":"multi-modal.d.ts","sourceRoot":"","sources":["../src/multi-modal.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,CAWhF;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,GAAG,aAAa,CAAC,iBAAiB,CAAC,GACjD,MAAM,GAAG,iBAAiB,EAAE,CAK9B"}
@@ -1,2 +1,2 @@
1
- export { createPIIRedaction, createPIIRedactionPlugin, piiRedactionPlugin, } from './pii-redaction';
1
+ export { createPIIRedaction, createPIIRedactionPlugin, DEFAULT_PII_RULES, redactPii, } from './pii-redaction';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,SAAS,GACV,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,59 @@
1
+ // src/plugins/pii-redaction.ts
2
+ var DEFAULT_PII_RULES = {
3
+ email: {
4
+ regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
5
+ replace: "[EMAIL_REDACTED]"
6
+ },
7
+ phone: {
8
+ regex: /\b(?:\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g,
9
+ replace: "[PHONE_REDACTED]"
10
+ },
11
+ apiKey: {
12
+ regex: /(?:[a-zA-Z0-9_-]*(?:api|key|secret|token|password|auth)[a-zA-Z0-9_-]*[:=]\s*["']?)([a-zA-Z0-9._-]{16,})(?:["']?)/gi,
13
+ replace: (match, key) => match.replace(key, "[KEY_REDACTED]")
14
+ }
15
+ };
16
+ function createPIIRedaction(options = {}) {
17
+ const rules = { ...DEFAULT_PII_RULES, ...options.rules ?? {} };
18
+ const activeRules = Object.entries(rules).filter(([name]) => !options.excludeRules?.includes(name));
19
+ return (text) => {
20
+ let result = text;
21
+ for (const [, rule] of activeRules) {
22
+ const replacer = rule.replace;
23
+ result = result.replace(rule.regex, replacer);
24
+ }
25
+ return result;
26
+ };
27
+ }
28
+ function createPIIRedactionPlugin(options = {}) {
29
+ const redact = createPIIRedaction(options);
30
+ return (input) => {
31
+ if (typeof input.content === "string") {
32
+ return {
33
+ ...input,
34
+ content: redact(input.content)
35
+ };
36
+ }
37
+ return {
38
+ ...input,
39
+ content: input.content.map((part) => {
40
+ if (part.type === "text" && part.text) {
41
+ return {
42
+ ...part,
43
+ text: redact(part.text)
44
+ };
45
+ }
46
+ return part;
47
+ })
48
+ };
49
+ };
50
+ }
51
+ var redactPii = createPIIRedactionPlugin();
52
+ export {
53
+ redactPii,
54
+ createPIIRedactionPlugin,
55
+ createPIIRedaction,
56
+ DEFAULT_PII_RULES
57
+ };
58
+
59
+ //# debugId=33F7792274EAA47664756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/plugins/pii-redaction.ts"],
4
+ "sourcesContent": [
5
+ "import type { MessageInput, MessagePlugin } from '../types';\n\n/**\n * Default regex rules for redacting common PII.\n */\nexport const DEFAULT_PII_RULES = {\n email: {\n regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/g,\n replace: '[EMAIL_REDACTED]',\n },\n phone: {\n regex: /\\b(?:\\+?\\d{1,3}[-.\\s]?)?\\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4}\\b/g,\n replace: '[PHONE_REDACTED]',\n },\n apiKey: {\n regex:\n /(?:[a-zA-Z0-9_-]*(?:api|key|secret|token|password|auth)[a-zA-Z0-9_-]*[:=]\\s*[\"']?)([a-zA-Z0-9._-]{16,})(?:[\"']?)/gi,\n replace: (match: string, key: string) => match.replace(key, '[KEY_REDACTED]'),\n },\n} as const;\n\n/**\n * A single PII redaction rule.\n */\nexport interface PIIRedactionRule {\n regex: RegExp;\n replace: string | ((match: string, ...groups: string[]) => string);\n}\n\n/**\n * Options for configuring PII redaction.\n */\nexport interface PIIRedactionOptions {\n rules?: Record<string, PIIRedactionRule>;\n excludeRules?: string[];\n}\n\n/**\n * Creates a PII redaction function with custom rules.\n */\nexport function createPIIRedaction(\n options: PIIRedactionOptions = {},\n): (text: string) => string {\n const rules = { ...DEFAULT_PII_RULES, ...(options.rules ?? {}) };\n const activeRules = Object.entries(rules).filter(\n ([name]) => !options.excludeRules?.includes(name),\n );\n\n return (text: string): string => {\n let result = text;\n for (const [, rule] of activeRules) {\n const replacer = rule.replace;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument\n result = result.replace(rule.regex, replacer as any);\n }\n return result;\n };\n}\n\n/**\n * Creates a PII redaction plugin with custom rules.\n */\nexport function createPIIRedactionPlugin(\n options: PIIRedactionOptions = {},\n): MessagePlugin {\n const redact = createPIIRedaction(options);\n\n return (input: MessageInput): MessageInput => {\n if (typeof input.content === 'string') {\n return {\n ...input,\n content: redact(input.content),\n };\n }\n\n return {\n ...input,\n content: input.content.map((part) => {\n if (part.type === 'text' && part.text) {\n return {\n ...part,\n text: redact(part.text),\n };\n }\n return part;\n }),\n };\n };\n}\n\n/**\n * Default PII redaction plugin instance.\n */\nexport const redactPii = createPIIRedactionPlugin();\n"
6
+ ],
7
+ "mappings": ";AAKO,IAAM,oBAAoB;AAAA,EAC/B,OAAO;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA,IACN,OACE;AAAA,IACF,SAAS,CAAC,OAAe,QAAgB,MAAM,QAAQ,KAAK,gBAAgB;AAAA,EAC9E;AACF;AAqBO,SAAS,kBAAkB,CAChC,UAA+B,CAAC,GACN;AAAA,EAC1B,MAAM,QAAQ,KAAK,sBAAuB,QAAQ,SAAS,CAAC,EAAG;AAAA,EAC/D,MAAM,cAAc,OAAO,QAAQ,KAAK,EAAE,OACxC,EAAE,UAAU,CAAC,QAAQ,cAAc,SAAS,IAAI,CAClD;AAAA,EAEA,OAAO,CAAC,SAAyB;AAAA,IAC/B,IAAI,SAAS;AAAA,IACb,cAAc,SAAS,aAAa;AAAA,MAClC,MAAM,WAAW,KAAK;AAAA,MAEtB,SAAS,OAAO,QAAQ,KAAK,OAAO,QAAe;AAAA,IACrD;AAAA,IACA,OAAO;AAAA;AAAA;AAOJ,SAAS,wBAAwB,CACtC,UAA+B,CAAC,GACjB;AAAA,EACf,MAAM,SAAS,mBAAmB,OAAO;AAAA,EAEzC,OAAO,CAAC,UAAsC;AAAA,IAC5C,IAAI,OAAO,MAAM,YAAY,UAAU;AAAA,MACrC,OAAO;AAAA,WACF;AAAA,QACH,SAAS,OAAO,MAAM,OAAO;AAAA,MAC/B;AAAA,IACF;AAAA,IAEA,OAAO;AAAA,SACF;AAAA,MACH,SAAS,MAAM,QAAQ,IAAI,CAAC,SAAS;AAAA,QACnC,IAAI,KAAK,SAAS,UAAU,KAAK,MAAM;AAAA,UACrC,OAAO;AAAA,eACF;AAAA,YACH,MAAM,OAAO,KAAK,IAAI;AAAA,UACxB;AAAA,QACF;AAAA,QACA,OAAO;AAAA,OACR;AAAA,IACH;AAAA;AAAA;AAOG,IAAM,YAAY,yBAAyB;",
8
+ "debugId": "33F7792274EAA47664756E2164756E21",
9
+ "names": []
10
+ }
@@ -1,4 +1,7 @@
1
1
  import type { MessagePlugin } from '../types';
2
+ /**
3
+ * Default regex rules for redacting common PII.
4
+ */
2
5
  export declare const DEFAULT_PII_RULES: {
3
6
  readonly email: {
4
7
  readonly regex: RegExp;
@@ -13,10 +16,16 @@ export declare const DEFAULT_PII_RULES: {
13
16
  readonly replace: (match: string, key: string) => string;
14
17
  };
15
18
  };
19
+ /**
20
+ * A single PII redaction rule.
21
+ */
16
22
  export interface PIIRedactionRule {
17
23
  regex: RegExp;
18
24
  replace: string | ((match: string, ...groups: string[]) => string);
19
25
  }
26
+ /**
27
+ * Options for configuring PII redaction.
28
+ */
20
29
  export interface PIIRedactionOptions {
21
30
  rules?: Record<string, PIIRedactionRule>;
22
31
  excludeRules?: string[];
@@ -32,5 +41,5 @@ export declare function createPIIRedactionPlugin(options?: PIIRedactionOptions):
32
41
  /**
33
42
  * Default PII redaction plugin instance.
34
43
  */
35
- export declare const piiRedactionPlugin: MessagePlugin;
44
+ export declare const redactPii: MessagePlugin;
36
45
  //# sourceMappingURL=pii-redaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pii-redaction.d.ts","sourceRoot":"","sources":["../../src/plugins/pii-redaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,UAAU,CAAC;AAE5D,eAAO,MAAM,iBAAiB;;;;;;;;;;;kCAYT,MAAM,OAAO,MAAM;;CAE9B,CAAC;AAEX,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,CAAC;CACpE;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,mBAAwB,GAChC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAe1B;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,mBAAwB,GAChC,aAAa,CAwBf;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,eAA6B,CAAC"}
1
+ {"version":3,"file":"pii-redaction.d.ts","sourceRoot":"","sources":["../../src/plugins/pii-redaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,UAAU,CAAC;AAE5D;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;kCAYT,MAAM,OAAO,MAAM;;CAE9B,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC,CAAC;CACpE;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,mBAAwB,GAChC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAe1B;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,mBAAwB,GAChC,aAAa,CAwBf;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,eAA6B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createPIIRedaction, createPIIRedactionPlugin, DEFAULT_PII_RULES, redactPii, } from '../plugins/pii-redaction';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,SAAS,GACV,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,59 @@
1
+ // src/plugins/pii-redaction.ts
2
+ var DEFAULT_PII_RULES = {
3
+ email: {
4
+ regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
5
+ replace: "[EMAIL_REDACTED]"
6
+ },
7
+ phone: {
8
+ regex: /\b(?:\+?\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b/g,
9
+ replace: "[PHONE_REDACTED]"
10
+ },
11
+ apiKey: {
12
+ regex: /(?:[a-zA-Z0-9_-]*(?:api|key|secret|token|password|auth)[a-zA-Z0-9_-]*[:=]\s*["']?)([a-zA-Z0-9._-]{16,})(?:["']?)/gi,
13
+ replace: (match, key) => match.replace(key, "[KEY_REDACTED]")
14
+ }
15
+ };
16
+ function createPIIRedaction(options = {}) {
17
+ const rules = { ...DEFAULT_PII_RULES, ...options.rules ?? {} };
18
+ const activeRules = Object.entries(rules).filter(([name]) => !options.excludeRules?.includes(name));
19
+ return (text) => {
20
+ let result = text;
21
+ for (const [, rule] of activeRules) {
22
+ const replacer = rule.replace;
23
+ result = result.replace(rule.regex, replacer);
24
+ }
25
+ return result;
26
+ };
27
+ }
28
+ function createPIIRedactionPlugin(options = {}) {
29
+ const redact = createPIIRedaction(options);
30
+ return (input) => {
31
+ if (typeof input.content === "string") {
32
+ return {
33
+ ...input,
34
+ content: redact(input.content)
35
+ };
36
+ }
37
+ return {
38
+ ...input,
39
+ content: input.content.map((part) => {
40
+ if (part.type === "text" && part.text) {
41
+ return {
42
+ ...part,
43
+ text: redact(part.text)
44
+ };
45
+ }
46
+ return part;
47
+ })
48
+ };
49
+ };
50
+ }
51
+ var redactPii = createPIIRedactionPlugin();
52
+ export {
53
+ redactPii,
54
+ createPIIRedactionPlugin,
55
+ createPIIRedaction,
56
+ DEFAULT_PII_RULES
57
+ };
58
+
59
+ //# debugId=E234DE4AB91D6ABC64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/plugins/pii-redaction.ts"],
4
+ "sourcesContent": [
5
+ "import type { MessageInput, MessagePlugin } from '../types';\n\n/**\n * Default regex rules for redacting common PII.\n */\nexport const DEFAULT_PII_RULES = {\n email: {\n regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/g,\n replace: '[EMAIL_REDACTED]',\n },\n phone: {\n regex: /\\b(?:\\+?\\d{1,3}[-.\\s]?)?\\(?\\d{3}\\)?[-.\\s]?\\d{3}[-.\\s]?\\d{4}\\b/g,\n replace: '[PHONE_REDACTED]',\n },\n apiKey: {\n regex:\n /(?:[a-zA-Z0-9_-]*(?:api|key|secret|token|password|auth)[a-zA-Z0-9_-]*[:=]\\s*[\"']?)([a-zA-Z0-9._-]{16,})(?:[\"']?)/gi,\n replace: (match: string, key: string) => match.replace(key, '[KEY_REDACTED]'),\n },\n} as const;\n\n/**\n * A single PII redaction rule.\n */\nexport interface PIIRedactionRule {\n regex: RegExp;\n replace: string | ((match: string, ...groups: string[]) => string);\n}\n\n/**\n * Options for configuring PII redaction.\n */\nexport interface PIIRedactionOptions {\n rules?: Record<string, PIIRedactionRule>;\n excludeRules?: string[];\n}\n\n/**\n * Creates a PII redaction function with custom rules.\n */\nexport function createPIIRedaction(\n options: PIIRedactionOptions = {},\n): (text: string) => string {\n const rules = { ...DEFAULT_PII_RULES, ...(options.rules ?? {}) };\n const activeRules = Object.entries(rules).filter(\n ([name]) => !options.excludeRules?.includes(name),\n );\n\n return (text: string): string => {\n let result = text;\n for (const [, rule] of activeRules) {\n const replacer = rule.replace;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument\n result = result.replace(rule.regex, replacer as any);\n }\n return result;\n };\n}\n\n/**\n * Creates a PII redaction plugin with custom rules.\n */\nexport function createPIIRedactionPlugin(\n options: PIIRedactionOptions = {},\n): MessagePlugin {\n const redact = createPIIRedaction(options);\n\n return (input: MessageInput): MessageInput => {\n if (typeof input.content === 'string') {\n return {\n ...input,\n content: redact(input.content),\n };\n }\n\n return {\n ...input,\n content: input.content.map((part) => {\n if (part.type === 'text' && part.text) {\n return {\n ...part,\n text: redact(part.text),\n };\n }\n return part;\n }),\n };\n };\n}\n\n/**\n * Default PII redaction plugin instance.\n */\nexport const redactPii = createPIIRedactionPlugin();\n"
6
+ ],
7
+ "mappings": ";AAKO,IAAM,oBAAoB;AAAA,EAC/B,OAAO;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA,IACN,OACE;AAAA,IACF,SAAS,CAAC,OAAe,QAAgB,MAAM,QAAQ,KAAK,gBAAgB;AAAA,EAC9E;AACF;AAqBO,SAAS,kBAAkB,CAChC,UAA+B,CAAC,GACN;AAAA,EAC1B,MAAM,QAAQ,KAAK,sBAAuB,QAAQ,SAAS,CAAC,EAAG;AAAA,EAC/D,MAAM,cAAc,OAAO,QAAQ,KAAK,EAAE,OACxC,EAAE,UAAU,CAAC,QAAQ,cAAc,SAAS,IAAI,CAClD;AAAA,EAEA,OAAO,CAAC,SAAyB;AAAA,IAC/B,IAAI,SAAS;AAAA,IACb,cAAc,SAAS,aAAa;AAAA,MAClC,MAAM,WAAW,KAAK;AAAA,MAEtB,SAAS,OAAO,QAAQ,KAAK,OAAO,QAAe;AAAA,IACrD;AAAA,IACA,OAAO;AAAA;AAAA;AAOJ,SAAS,wBAAwB,CACtC,UAA+B,CAAC,GACjB;AAAA,EACf,MAAM,SAAS,mBAAmB,OAAO;AAAA,EAEzC,OAAO,CAAC,UAAsC;AAAA,IAC5C,IAAI,OAAO,MAAM,YAAY,UAAU;AAAA,MACrC,OAAO;AAAA,WACF;AAAA,QACH,SAAS,OAAO,MAAM,OAAO;AAAA,MAC/B;AAAA,IACF;AAAA,IAEA,OAAO;AAAA,SACF;AAAA,MACH,SAAS,MAAM,QAAQ,IAAI,CAAC,SAAS;AAAA,QACnC,IAAI,KAAK,SAAS,UAAU,KAAK,MAAM;AAAA,UACrC,OAAO;AAAA,eACF;AAAA,YACH,MAAM,OAAO,KAAK,IAAI;AAAA,UACxB;AAAA,QACF;AAAA,QACA,OAAO;AAAA,OACR;AAAA,IACH;AAAA;AAAA;AAOG,IAAM,YAAY,yBAAyB;",
8
+ "debugId": "E234DE4AB91D6ABC64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,2 @@
1
+ export { conversationSchema, conversationShape, jsonValueSchema, messageInputSchema, messageJSONSchema, messageRoleSchema, multiModalContentSchema, tokenUsageSchema, toolCallSchema, toolResultSchema, } from '../schemas';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,114 @@
1
+ // src/schemas.ts
2
+ import { z } from "zod";
3
+ function toMultiModalContent(value) {
4
+ const result = { type: value.type };
5
+ if (value.text !== undefined)
6
+ result.text = value.text;
7
+ if (value.url !== undefined)
8
+ result.url = value.url;
9
+ if (value.mimeType !== undefined)
10
+ result.mimeType = value.mimeType;
11
+ return result;
12
+ }
13
+ var jsonValueSchema = z.lazy(() => z.union([
14
+ z.string(),
15
+ z.number(),
16
+ z.boolean(),
17
+ z.null(),
18
+ z.array(jsonValueSchema),
19
+ z.record(z.string(), jsonValueSchema)
20
+ ]));
21
+ var multiModalContentSchema = z.discriminatedUnion("type", [
22
+ z.object({
23
+ type: z.literal("text"),
24
+ text: z.string()
25
+ }),
26
+ z.object({
27
+ type: z.literal("image"),
28
+ url: z.string().url(),
29
+ mimeType: z.string().optional(),
30
+ text: z.string().optional()
31
+ })
32
+ ]).transform(toMultiModalContent);
33
+ var messageRoleSchema = z.enum([
34
+ "user",
35
+ "assistant",
36
+ "system",
37
+ "developer",
38
+ "tool-use",
39
+ "tool-result",
40
+ "snapshot"
41
+ ]);
42
+ var toolCallSchema = z.object({
43
+ id: z.string(),
44
+ name: z.string(),
45
+ arguments: jsonValueSchema
46
+ });
47
+ var toolResultSchema = z.object({
48
+ callId: z.string(),
49
+ outcome: z.enum(["success", "error"]),
50
+ content: jsonValueSchema,
51
+ toolCallId: z.string().optional(),
52
+ toolName: z.string().optional(),
53
+ result: jsonValueSchema.optional(),
54
+ error: z.string().optional()
55
+ });
56
+ var tokenUsageSchema = z.object({
57
+ prompt: z.number().int().min(0),
58
+ completion: z.number().int().min(0),
59
+ total: z.number().int().min(0)
60
+ });
61
+ var messageInputSchema = z.object({
62
+ role: messageRoleSchema,
63
+ content: z.union([z.string(), z.array(multiModalContentSchema)]),
64
+ metadata: z.record(z.string(), jsonValueSchema).optional(),
65
+ hidden: z.boolean().optional(),
66
+ toolCall: toolCallSchema.optional(),
67
+ toolResult: toolResultSchema.optional(),
68
+ tokenUsage: tokenUsageSchema.optional(),
69
+ goalCompleted: z.boolean().optional()
70
+ });
71
+ var messageJSONSchema = z.object({
72
+ id: z.string(),
73
+ role: messageRoleSchema,
74
+ content: z.union([z.string(), z.array(multiModalContentSchema)]),
75
+ position: z.number().int().min(0),
76
+ createdAt: z.string(),
77
+ metadata: z.record(z.string(), jsonValueSchema),
78
+ hidden: z.boolean(),
79
+ toolCall: toolCallSchema.optional(),
80
+ toolResult: toolResultSchema.optional(),
81
+ tokenUsage: tokenUsageSchema.optional(),
82
+ goalCompleted: z.boolean().optional()
83
+ }).loose();
84
+ var conversationStatusSchema = z.enum([
85
+ "active",
86
+ "archived",
87
+ "deleted"
88
+ ]);
89
+ var conversationShape = {
90
+ schemaVersion: z.number().int().min(1),
91
+ id: z.string(),
92
+ title: z.string().optional(),
93
+ status: conversationStatusSchema,
94
+ metadata: z.record(z.string(), jsonValueSchema),
95
+ ids: z.array(z.string()),
96
+ messages: z.record(z.string(), messageJSONSchema),
97
+ createdAt: z.string(),
98
+ updatedAt: z.string()
99
+ };
100
+ var conversationSchema = z.object(conversationShape);
101
+ export {
102
+ toolResultSchema,
103
+ toolCallSchema,
104
+ tokenUsageSchema,
105
+ multiModalContentSchema,
106
+ messageRoleSchema,
107
+ messageJSONSchema,
108
+ messageInputSchema,
109
+ jsonValueSchema,
110
+ conversationShape,
111
+ conversationSchema
112
+ };
113
+
114
+ //# debugId=D0E86BB95AFAE92264756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/schemas.ts"],
4
+ "sourcesContent": [
5
+ "import type { MultiModalContent } from '@lasercat/homogenaize';\nimport { z } from 'zod';\n\nimport type {\n Conversation,\n ConversationStatus,\n JSONValue,\n Message,\n MessageInput,\n MessageRole,\n TokenUsage,\n ToolCall,\n ToolResult,\n} from './types';\n\ntype RawMultiModalContent = {\n type: 'text' | 'image';\n text?: string | undefined;\n url?: string | undefined;\n mimeType?: string | undefined;\n};\n\nfunction toMultiModalContent(value: RawMultiModalContent): MultiModalContent {\n const result: MultiModalContent = { type: value.type };\n if (value.text !== undefined) result.text = value.text;\n if (value.url !== undefined) result.url = value.url;\n if (value.mimeType !== undefined) result.mimeType = value.mimeType;\n return result;\n}\n\n/**\n * Zod schema for JSON-serializable values.\n */\nexport const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.null(),\n z.array(jsonValueSchema),\n z.record(z.string(), jsonValueSchema),\n ]),\n) satisfies z.ZodType<JSONValue>;\n\n/**\n * Zod schema for multi-modal content parts (text or image).\n */\nexport const multiModalContentSchema = z\n .discriminatedUnion('type', [\n z.object({\n type: z.literal('text'),\n text: z.string(),\n }),\n z.object({\n type: z.literal('image'),\n url: z.string().url(),\n mimeType: z.string().optional(),\n text: z.string().optional(),\n }),\n ])\n .transform(toMultiModalContent) satisfies z.ZodType<MultiModalContent>;\n\n/**\n * Zod schema for valid message roles.\n */\nexport const messageRoleSchema = z.enum([\n 'user',\n 'assistant',\n 'system',\n 'developer',\n 'tool-use',\n 'tool-result',\n 'snapshot',\n]) satisfies z.ZodType<MessageRole>;\n\n/**\n * Zod schema for tool call metadata.\n */\nexport const toolCallSchema = z.object({\n id: z.string(),\n name: z.string(),\n arguments: jsonValueSchema,\n}) satisfies z.ZodType<ToolCall>;\n\n/**\n * Zod schema for tool result metadata.\n */\nexport const toolResultSchema = z.object({\n callId: z.string(),\n outcome: z.enum(['success', 'error']),\n content: jsonValueSchema,\n toolCallId: z.string().optional(),\n toolName: z.string().optional(),\n result: jsonValueSchema.optional(),\n error: z.string().optional(),\n}) satisfies z.ZodType<ToolResult>;\n\n/**\n * Zod schema for token usage accounting.\n */\nexport const tokenUsageSchema = z.object({\n prompt: z.number().int().min(0),\n completion: z.number().int().min(0),\n total: z.number().int().min(0),\n}) satisfies z.ZodType<TokenUsage>;\n\n/**\n * Zod schema for message input payloads.\n */\nexport const messageInputSchema = z.object({\n role: messageRoleSchema,\n content: z.union([z.string(), z.array(multiModalContentSchema)]),\n metadata: z.record(z.string(), jsonValueSchema).optional(),\n hidden: z.boolean().optional(),\n toolCall: toolCallSchema.optional(),\n toolResult: toolResultSchema.optional(),\n tokenUsage: tokenUsageSchema.optional(),\n goalCompleted: z.boolean().optional(),\n}) satisfies z.ZodType<MessageInput>;\n\n/**\n * Zod schema for serialized messages.\n */\nexport const messageJSONSchema = z\n .object({\n id: z.string(),\n role: messageRoleSchema,\n content: z.union([z.string(), z.array(multiModalContentSchema)]),\n position: z.number().int().min(0),\n createdAt: z.string(),\n metadata: z.record(z.string(), jsonValueSchema),\n hidden: z.boolean(),\n toolCall: toolCallSchema.optional(),\n toolResult: toolResultSchema.optional(),\n tokenUsage: tokenUsageSchema.optional(),\n goalCompleted: z.boolean().optional(),\n })\n .loose() satisfies z.ZodType<Message>;\n\n/**\n * Zod schema for conversation status values.\n */\nexport const conversationStatusSchema = z.enum([\n 'active',\n 'archived',\n 'deleted',\n]) satisfies z.ZodType<ConversationStatus>;\n\n/**\n * Raw conversation shape for storage systems that need direct access to fields.\n */\nexport const conversationShape = {\n schemaVersion: z.number().int().min(1),\n id: z.string(),\n title: z.string().optional(),\n status: conversationStatusSchema,\n metadata: z.record(z.string(), jsonValueSchema),\n ids: z.array(z.string()),\n messages: z.record(z.string(), messageJSONSchema),\n createdAt: z.string(),\n updatedAt: z.string(),\n} as const;\n\n/**\n * Zod schema for serialized conversations.\n */\nexport const conversationSchema = z.object(\n conversationShape,\n) satisfies z.ZodType<Conversation>;\n"
6
+ ],
7
+ "mappings": ";AACA;AAqBA,SAAS,mBAAmB,CAAC,OAAgD;AAAA,EAC3E,MAAM,SAA4B,EAAE,MAAM,MAAM,KAAK;AAAA,EACrD,IAAI,MAAM,SAAS;AAAA,IAAW,OAAO,OAAO,MAAM;AAAA,EAClD,IAAI,MAAM,QAAQ;AAAA,IAAW,OAAO,MAAM,MAAM;AAAA,EAChD,IAAI,MAAM,aAAa;AAAA,IAAW,OAAO,WAAW,MAAM;AAAA,EAC1D,OAAO;AAAA;AAMF,IAAM,kBAAwC,EAAE,KAAK,MAC1D,EAAE,MAAM;AAAA,EACN,EAAE,OAAO;AAAA,EACT,EAAE,OAAO;AAAA,EACT,EAAE,QAAQ;AAAA,EACV,EAAE,KAAK;AAAA,EACP,EAAE,MAAM,eAAe;AAAA,EACvB,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe;AACtC,CAAC,CACH;AAKO,IAAM,0BAA0B,EACpC,mBAAmB,QAAQ;AAAA,EAC1B,EAAE,OAAO;AAAA,IACP,MAAM,EAAE,QAAQ,MAAM;AAAA,IACtB,MAAM,EAAE,OAAO;AAAA,EACjB,CAAC;AAAA,EACD,EAAE,OAAO;AAAA,IACP,MAAM,EAAE,QAAQ,OAAO;AAAA,IACvB,KAAK,EAAE,OAAO,EAAE,IAAI;AAAA,IACpB,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA,IAC9B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,CAAC;AACH,CAAC,EACA,UAAU,mBAAmB;AAKzB,IAAM,oBAAoB,EAAE,KAAK;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAKM,IAAM,iBAAiB,EAAE,OAAO;AAAA,EACrC,IAAI,EAAE,OAAO;AAAA,EACb,MAAM,EAAE,OAAO;AAAA,EACf,WAAW;AACb,CAAC;AAKM,IAAM,mBAAmB,EAAE,OAAO;AAAA,EACvC,QAAQ,EAAE,OAAO;AAAA,EACjB,SAAS,EAAE,KAAK,CAAC,WAAW,OAAO,CAAC;AAAA,EACpC,SAAS;AAAA,EACT,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,QAAQ,gBAAgB,SAAS;AAAA,EACjC,OAAO,EAAE,OAAO,EAAE,SAAS;AAC7B,CAAC;AAKM,IAAM,mBAAmB,EAAE,OAAO;AAAA,EACvC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAAA,EAC9B,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAAA,EAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAC/B,CAAC;AAKM,IAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,MAAM;AAAA,EACN,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,MAAM,uBAAuB,CAAC,CAAC;AAAA,EAC/D,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe,EAAE,SAAS;AAAA,EACzD,QAAQ,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC7B,UAAU,eAAe,SAAS;AAAA,EAClC,YAAY,iBAAiB,SAAS;AAAA,EACtC,YAAY,iBAAiB,SAAS;AAAA,EACtC,eAAe,EAAE,QAAQ,EAAE,SAAS;AACtC,CAAC;AAKM,IAAM,oBAAoB,EAC9B,OAAO;AAAA,EACN,IAAI,EAAE,OAAO;AAAA,EACb,MAAM;AAAA,EACN,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,MAAM,uBAAuB,CAAC,CAAC;AAAA,EAC/D,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAAA,EAChC,WAAW,EAAE,OAAO;AAAA,EACpB,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe;AAAA,EAC9C,QAAQ,EAAE,QAAQ;AAAA,EAClB,UAAU,eAAe,SAAS;AAAA,EAClC,YAAY,iBAAiB,SAAS;AAAA,EACtC,YAAY,iBAAiB,SAAS;AAAA,EACtC,eAAe,EAAE,QAAQ,EAAE,SAAS;AACtC,CAAC,EACA,MAAM;AAKF,IAAM,2BAA2B,EAAE,KAAK;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAKM,IAAM,oBAAoB;AAAA,EAC/B,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;AAAA,EACrC,IAAI,EAAE,OAAO;AAAA,EACb,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,QAAQ;AAAA,EACR,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,eAAe;AAAA,EAC9C,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,EACvB,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,iBAAiB;AAAA,EAChD,WAAW,EAAE,OAAO;AAAA,EACpB,WAAW,EAAE,OAAO;AACtB;AAKO,IAAM,qBAAqB,EAAE,OAClC,iBACF;",
8
+ "debugId": "D0E86BB95AFAE92264756E2164756E21",
9
+ "names": []
10
+ }