plugin-sensitive-filter-xr 0.0.5 → 0.0.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"sensitiveFilter.d.ts","sourceRoot":"","sources":["../../src/lib/sensitiveFilter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAa,oBAAoB,EAA8B,MAAM,kBAAkB,CAAA;AAGnG,OAAO,EACL,eAAe,EAGf,uBAAuB,EACvB,wBAAwB,EAEzB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAOL,qBAAqB,EAMtB,MAAM,YAAY,CAAA;AAienB,qBAEa,yBAA0B,YAAW,wBAAwB,CAAC,qBAAqB,CAAC;IAE/F,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IAEvC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAqRlC;IAEK,gBAAgB,CACpB,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,eAAe,CAAC;IAa3B,OAAO,CAAC,wBAAwB;IAqOhC,OAAO,CAAC,uBAAuB;CA8YhC;AAED,YAAY,EAAE,qBAAqB,EAAE,CAAA"}
1
+ {"version":3,"file":"sensitiveFilter.d.ts","sourceRoot":"","sources":["../../src/lib/sensitiveFilter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAa,oBAAoB,EAA8B,MAAM,kBAAkB,CAAA;AAGnG,OAAO,EACL,eAAe,EAGf,uBAAuB,EACvB,wBAAwB,EAEzB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAOL,qBAAqB,EAMtB,MAAM,YAAY,CAAA;AAofnB,qBAEa,yBAA0B,YAAW,wBAAwB,CAAC,qBAAqB,CAAC;IAE/F,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IAEvC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAqRlC;IAEK,gBAAgB,CACpB,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,eAAe,CAAC;IAa3B,OAAO,CAAC,wBAAwB;IA+OhC,OAAO,CAAC,uBAAuB;CAwahC;AAED,YAAY,EAAE,qBAAqB,EAAE,CAAA"}
@@ -347,6 +347,21 @@ function isUnsupportedStructuredOutputError(error) {
347
347
  ];
348
348
  return patterns.some((pattern) => message.includes(pattern));
349
349
  }
350
+ function isMissingWrapWorkflowHandlerError(error) {
351
+ const message = getErrorText(error).toLowerCase();
352
+ return message.includes('no handler found') && message.includes('wrapworkflownodeexecutioncommand');
353
+ }
354
+ async function runWithWrapWorkflowFallback(runTracked, runFallback) {
355
+ try {
356
+ return await runTracked();
357
+ }
358
+ catch (error) {
359
+ if (isMissingWrapWorkflowHandlerError(error)) {
360
+ return runFallback();
361
+ }
362
+ throw error;
363
+ }
364
+ }
350
365
  let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
351
366
  constructor() {
352
367
  this.meta = {
@@ -719,28 +734,35 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
719
734
  }
720
735
  const { thread_id, checkpoint_ns, checkpoint_id, subscriber, executionId } = configurable;
721
736
  const snapshot = buildAuditSnapshot();
722
- await this.commandBus.execute(new WrapWorkflowNodeExecutionCommand(async () => {
737
+ const writeSnapshot = async () => {
723
738
  return {
724
739
  state: snapshot,
725
740
  output: snapshot,
726
741
  };
727
- }, {
728
- execution: {
729
- category: 'workflow',
730
- type: 'middleware',
731
- title: `${context.node.title} Audit`,
732
- inputs: {
733
- mode: snapshot.mode,
734
- total: snapshot.summary.total,
742
+ };
743
+ await runWithWrapWorkflowFallback(async () => {
744
+ await this.commandBus.execute(new WrapWorkflowNodeExecutionCommand(writeSnapshot, {
745
+ execution: {
746
+ category: 'workflow',
747
+ type: 'middleware',
748
+ title: `${context.node.title} Audit`,
749
+ inputs: {
750
+ mode: snapshot.mode,
751
+ total: snapshot.summary.total,
752
+ },
753
+ parentId: executionId,
754
+ threadId: thread_id,
755
+ checkpointNs: checkpoint_ns,
756
+ checkpointId: checkpoint_id,
757
+ agentKey: context.node.key,
735
758
  },
736
- parentId: executionId,
737
- threadId: thread_id,
738
- checkpointNs: checkpoint_ns,
739
- checkpointId: checkpoint_id,
740
- agentKey: context.node.key,
741
- },
742
- subscriber,
743
- }));
759
+ subscriber,
760
+ }));
761
+ return undefined;
762
+ }, async () => {
763
+ await writeSnapshot();
764
+ return undefined;
765
+ });
744
766
  };
745
767
  return {
746
768
  name: SENSITIVE_FILTER_MIDDLEWARE_NAME,
@@ -930,28 +952,35 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
930
952
  }
931
953
  const { thread_id, checkpoint_ns, checkpoint_id, subscriber, executionId } = configurable;
932
954
  const snapshot = buildAuditSnapshot();
933
- await this.commandBus.execute(new WrapWorkflowNodeExecutionCommand(async () => {
955
+ const writeSnapshot = async () => {
934
956
  return {
935
957
  state: snapshot,
936
958
  output: snapshot,
937
959
  };
938
- }, {
939
- execution: {
940
- category: 'workflow',
941
- type: 'middleware',
942
- title: `${context.node.title} Audit`,
943
- inputs: {
944
- mode: snapshot.mode,
945
- total: snapshot.summary.total,
960
+ };
961
+ await runWithWrapWorkflowFallback(async () => {
962
+ await this.commandBus.execute(new WrapWorkflowNodeExecutionCommand(writeSnapshot, {
963
+ execution: {
964
+ category: 'workflow',
965
+ type: 'middleware',
966
+ title: `${context.node.title} Audit`,
967
+ inputs: {
968
+ mode: snapshot.mode,
969
+ total: snapshot.summary.total,
970
+ },
971
+ parentId: executionId,
972
+ threadId: thread_id,
973
+ checkpointNs: checkpoint_ns,
974
+ checkpointId: checkpoint_id,
975
+ agentKey: context.node.key,
946
976
  },
947
- parentId: executionId,
948
- threadId: thread_id,
949
- checkpointNs: checkpoint_ns,
950
- checkpointId: checkpoint_id,
951
- agentKey: context.node.key,
952
- },
953
- subscriber,
954
- }));
977
+ subscriber,
978
+ }));
979
+ return undefined;
980
+ }, async () => {
981
+ await writeSnapshot();
982
+ return undefined;
983
+ });
955
984
  };
956
985
  const buildEvaluationMessages = (phase, text, llmConfig) => {
957
986
  return [
@@ -1017,30 +1046,41 @@ let SensitiveFilterMiddleware = class SensitiveFilterMiddleware {
1017
1046
  if (!thread_id || !executionId) {
1018
1047
  return parseCore();
1019
1048
  }
1020
- const tracked = await this.commandBus.execute(new WrapWorkflowNodeExecutionCommand(async () => {
1021
- const decision = await parseCore();
1022
- return {
1023
- state: decision,
1024
- output: decision,
1025
- };
1026
- }, {
1027
- execution: {
1028
- category: 'workflow',
1029
- type: 'middleware',
1030
- inputs: {
1031
- phase,
1032
- text,
1049
+ let trackedDecision = null;
1050
+ await runWithWrapWorkflowFallback(async () => {
1051
+ await this.commandBus.execute(new WrapWorkflowNodeExecutionCommand(async () => {
1052
+ const decision = await parseCore();
1053
+ trackedDecision = decision;
1054
+ return {
1055
+ state: decision,
1056
+ output: decision,
1057
+ };
1058
+ }, {
1059
+ execution: {
1060
+ category: 'workflow',
1061
+ type: 'middleware',
1062
+ inputs: {
1063
+ phase,
1064
+ text,
1065
+ },
1066
+ parentId: executionId,
1067
+ threadId: thread_id,
1068
+ checkpointNs: checkpoint_ns,
1069
+ checkpointId: checkpoint_id,
1070
+ agentKey: context.node.key,
1071
+ title: context.node.title,
1033
1072
  },
1034
- parentId: executionId,
1035
- threadId: thread_id,
1036
- checkpointNs: checkpoint_ns,
1037
- checkpointId: checkpoint_id,
1038
- agentKey: context.node.key,
1039
- title: context.node.title,
1040
- },
1041
- subscriber,
1042
- }));
1043
- return tracked;
1073
+ subscriber,
1074
+ }));
1075
+ return undefined;
1076
+ }, async () => {
1077
+ trackedDecision = await parseCore();
1078
+ return undefined;
1079
+ });
1080
+ if (!trackedDecision) {
1081
+ throw new Error('LLM decision tracking failed: no decision resolved');
1082
+ }
1083
+ return trackedDecision;
1044
1084
  };
1045
1085
  const resolveOnErrorDecision = (llmConfig, error) => {
1046
1086
  const reason = `llm-error:${error instanceof Error ? error.message : String(error)}`;
@@ -65,17 +65,17 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
65
65
  action: z.ZodNullable<z.ZodOptional<z.ZodEnum<["block", "rewrite"]>>>;
66
66
  replacementText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
67
67
  }, "strip", z.ZodTypeAny, {
68
- type?: "keyword" | "regex";
69
68
  id?: string;
70
69
  pattern?: string;
70
+ type?: "keyword" | "regex";
71
71
  scope?: "input" | "output" | "both";
72
72
  severity?: "high" | "medium";
73
73
  action?: "block" | "rewrite";
74
74
  replacementText?: string;
75
75
  }, {
76
- type?: "keyword" | "regex";
77
76
  id?: string;
78
77
  pattern?: string;
78
+ type?: "keyword" | "regex";
79
79
  scope?: "input" | "output" | "both";
80
80
  severity?: "high" | "medium";
81
81
  action?: "block" | "rewrite";
@@ -95,13 +95,11 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
95
95
  normalize: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
96
96
  llm: z.ZodOptional<z.ZodUnknown>;
97
97
  }, "strip", z.ZodTypeAny, {
98
- normalize?: boolean;
99
- llm?: unknown;
100
98
  mode?: "rule";
101
99
  rules?: {
102
- type?: "keyword" | "regex";
103
100
  id?: string;
104
101
  pattern?: string;
102
+ type?: "keyword" | "regex";
105
103
  scope?: "input" | "output" | "both";
106
104
  severity?: "high" | "medium";
107
105
  action?: "block" | "rewrite";
@@ -112,14 +110,14 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
112
110
  profile?: "strict" | "balanced";
113
111
  };
114
112
  caseSensitive?: boolean;
115
- }, {
116
113
  normalize?: boolean;
117
114
  llm?: unknown;
115
+ }, {
118
116
  mode?: "rule";
119
117
  rules?: {
120
- type?: "keyword" | "regex";
121
118
  id?: string;
122
119
  pattern?: string;
120
+ type?: "keyword" | "regex";
123
121
  scope?: "input" | "output" | "both";
124
122
  severity?: "high" | "medium";
125
123
  action?: "block" | "rewrite";
@@ -130,6 +128,8 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
130
128
  profile?: "strict" | "balanced";
131
129
  };
132
130
  caseSensitive?: boolean;
131
+ normalize?: boolean;
132
+ llm?: unknown;
133
133
  }>, z.ZodObject<{
134
134
  mode: z.ZodLiteral<"llm">;
135
135
  llm: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodObject<{
@@ -144,8 +144,8 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
144
144
  rewriteFallbackText: z.ZodNullable<z.ZodOptional<z.ZodString>>;
145
145
  timeoutMs: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
146
146
  }, "strip", z.ZodTypeAny, {
147
- model?: ICopilotModel;
148
147
  scope?: "input" | "output" | "both";
148
+ model?: ICopilotModel;
149
149
  rulePrompt?: string;
150
150
  systemPrompt?: string;
151
151
  outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
@@ -155,8 +155,8 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
155
155
  rewriteFallbackText?: string;
156
156
  timeoutMs?: number;
157
157
  }, {
158
- model?: ICopilotModel;
159
158
  scope?: "input" | "output" | "both";
159
+ model?: ICopilotModel;
160
160
  rulePrompt?: string;
161
161
  systemPrompt?: string;
162
162
  outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
@@ -171,10 +171,14 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
171
171
  caseSensitive: z.ZodOptional<z.ZodUnknown>;
172
172
  normalize: z.ZodOptional<z.ZodUnknown>;
173
173
  }, "strip", z.ZodTypeAny, {
174
+ mode?: "llm";
175
+ rules?: unknown;
176
+ generalPack?: unknown;
177
+ caseSensitive?: unknown;
174
178
  normalize?: unknown;
175
179
  llm?: {
176
- model?: ICopilotModel;
177
180
  scope?: "input" | "output" | "both";
181
+ model?: ICopilotModel;
178
182
  rulePrompt?: string;
179
183
  systemPrompt?: string;
180
184
  outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
@@ -184,15 +188,15 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
184
188
  rewriteFallbackText?: string;
185
189
  timeoutMs?: number;
186
190
  };
191
+ }, {
187
192
  mode?: "llm";
188
193
  rules?: unknown;
189
194
  generalPack?: unknown;
190
195
  caseSensitive?: unknown;
191
- }, {
192
196
  normalize?: unknown;
193
197
  llm?: {
194
- model?: ICopilotModel;
195
198
  scope?: "input" | "output" | "both";
199
+ model?: ICopilotModel;
196
200
  rulePrompt?: string;
197
201
  systemPrompt?: string;
198
202
  outputMethod?: "functionCalling" | "jsonMode" | "jsonSchema";
@@ -202,10 +206,6 @@ export declare const sensitiveFilterConfigSchema: z.ZodUnion<[z.ZodObject<{
202
206
  rewriteFallbackText?: string;
203
207
  timeoutMs?: number;
204
208
  };
205
- mode?: "llm";
206
- rules?: unknown;
207
- generalPack?: unknown;
208
- caseSensitive?: unknown;
209
209
  }>]>;
210
210
  export declare const llmDecisionSchema: z.ZodObject<{
211
211
  matched: z.ZodBoolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plugin-sensitive-filter-xr",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "author": {
5
5
  "name": "XpertAI",
6
6
  "url": "https://xpertai.cn"