@whitewall/blip-sdk 0.0.191 → 0.0.193

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 (42) hide show
  1. package/dist/cjs/client.js.map +1 -1
  2. package/dist/cjs/index.js +2 -0
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/flow.js +46 -8
  5. package/dist/cjs/types/flow.js.map +1 -1
  6. package/dist/cjs/utils/builder.js +34 -34
  7. package/dist/cjs/utils/builder.js.map +1 -1
  8. package/dist/cjs/utils/flow-rules.js +304 -0
  9. package/dist/cjs/utils/flow-rules.js.map +1 -0
  10. package/dist/cjs/utils/minifier.js +410 -0
  11. package/dist/cjs/utils/minifier.js.map +1 -0
  12. package/dist/esm/client.js.map +1 -1
  13. package/dist/esm/index.js +2 -0
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/types/flow.js +40 -6
  16. package/dist/esm/types/flow.js.map +1 -1
  17. package/dist/esm/utils/builder.js +31 -30
  18. package/dist/esm/utils/builder.js.map +1 -1
  19. package/dist/esm/utils/flow-rules.js +297 -0
  20. package/dist/esm/utils/flow-rules.js.map +1 -0
  21. package/dist/esm/utils/minifier.js +405 -0
  22. package/dist/esm/utils/minifier.js.map +1 -0
  23. package/dist/types/client.d.ts +2 -1
  24. package/dist/types/client.d.ts.map +1 -1
  25. package/dist/types/index.d.ts +2 -0
  26. package/dist/types/index.d.ts.map +1 -1
  27. package/dist/types/namespaces/account.d.ts +20 -20
  28. package/dist/types/types/flow.d.ts +286 -96
  29. package/dist/types/types/flow.d.ts.map +1 -1
  30. package/dist/types/utils/builder.d.ts +33 -30
  31. package/dist/types/utils/builder.d.ts.map +1 -1
  32. package/dist/types/utils/flow-rules.d.ts +50 -0
  33. package/dist/types/utils/flow-rules.d.ts.map +1 -0
  34. package/dist/types/utils/minifier.d.ts +2857 -0
  35. package/dist/types/utils/minifier.d.ts.map +1 -0
  36. package/package.json +1 -1
  37. package/src/client.ts +2 -1
  38. package/src/index.ts +2 -0
  39. package/src/types/flow.ts +52 -6
  40. package/src/utils/builder.ts +61 -73
  41. package/src/utils/flow-rules.ts +453 -0
  42. package/src/utils/minifier.ts +505 -0
@@ -1,16 +1,24 @@
1
- import type { Action, ContentActionItem, State } from '../types/flow.ts';
2
- export type MinifiedAction = {
1
+ /**
2
+ * Lossy, read-only projection of a builder flow, meant for presenting a state to
3
+ * a human or an LLM. It renames the `$`-prefixed keys to readable ones, drops
4
+ * layout metadata and denormalizes state names, so it cannot be pushed back to
5
+ * the builder. For the round-trippable format, see `./minifier.ts`.
6
+ *
7
+ * Typed over `MinifiedState`, which a full `State` satisfies, so both a pulled
8
+ * flow and a minified one digest without casts.
9
+ */
10
+ import { type Condition } from '../types/flow.ts';
11
+ import type { MinifiedAction, MinifiedState } from './minifier.ts';
12
+ /** A `Condition` with the builder's nullish bookkeeping dropped. */
13
+ export type ConditionDigest = Omit<Condition, 'variable'> & {
14
+ variable?: string;
15
+ };
16
+ export type ActionDigest = {
3
17
  type: string;
4
18
  settings: Record<string, unknown>;
5
- conditions?: Array<{
6
- source: string;
7
- variable?: string;
8
- comparison: string;
9
- operator?: string;
10
- values: Array<string>;
11
- }>;
19
+ conditions?: Array<ConditionDigest>;
12
20
  };
13
- export type MinifiedInput = {
21
+ export type InputDigest = {
14
22
  bypass: boolean;
15
23
  variable?: string;
16
24
  validation?: {
@@ -20,35 +28,30 @@ export type MinifiedInput = {
20
28
  error: string;
21
29
  };
22
30
  expiration?: string;
23
- conditions?: MinifiedAction['conditions'];
31
+ conditions?: Array<ConditionDigest>;
24
32
  };
25
- export type MinifiedOutput = {
33
+ export type OutputDigest = {
26
34
  stateId: string;
27
35
  stateName?: string;
28
36
  typeOfStateId?: string;
29
- conditions?: MinifiedAction['conditions'];
37
+ conditions?: Array<ConditionDigest>;
30
38
  };
31
- export type MinifiedState = {
39
+ export type StateDigest = {
32
40
  id: string;
33
41
  name: string;
34
42
  root?: boolean;
35
- enteringActions?: Array<MinifiedAction>;
43
+ enteringActions?: Array<ActionDigest>;
36
44
  contentActions?: Array<{
37
- action?: MinifiedAction;
38
- input?: MinifiedInput;
45
+ action?: ActionDigest;
46
+ input?: InputDigest;
39
47
  }>;
40
- leavingActions?: Array<MinifiedAction>;
41
- outputs?: Array<MinifiedOutput>;
42
- defaultOutput: {
43
- stateId: string;
44
- stateName?: string;
45
- typeOfStateId?: string;
46
- };
47
- afterStateChangedActions?: Array<MinifiedAction>;
48
- localActions?: Array<MinifiedAction>;
48
+ leavingActions?: Array<ActionDigest>;
49
+ outputs?: Array<OutputDigest>;
50
+ defaultOutput: OutputDigest;
51
+ afterStateChangedActions?: Array<ActionDigest>;
52
+ localActions?: Array<ActionDigest>;
49
53
  };
50
- export declare function minifyAction(action: Action): MinifiedAction;
51
- export declare function isChatStateSendMessage(item: ContentActionItem): boolean;
52
- export declare function resolveStateName(stateId: string, flow: Record<string, State>): string | undefined;
53
- export declare function minifyState(stateId: string, state: State, flow: Record<string, State>): MinifiedState;
54
+ export declare function digestAction(action: MinifiedAction): ActionDigest;
55
+ export declare function resolveStateName(stateId: string, flow: Record<string, MinifiedState>): string | undefined;
56
+ export declare function digestState(stateId: string, state: MinifiedState, flow: Record<string, MinifiedState>): StateDigest;
54
57
  //# sourceMappingURL=builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/utils/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAExE,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,UAAU,CAAC,EAAE,KAAK,CAAC;QACf,MAAM,EAAE,MAAM,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,EAAE,MAAM,CAAA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,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,WAAW,CAqCnH"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Everything the Builder runtime refuses to run, checked against a minified flow.
3
+ *
4
+ * A port of the runtime's own validation — `Models/Flow.cs::Validate`,
5
+ * `Models/Condition.cs::Validate`, `Models/Input.cs::Validate` and the media type
6
+ * each action deserializes. All of them throw at load or mid-turn, and the runtime
7
+ * validates the whole flow on every message, so one of these takes the bot down
8
+ * for every user rather than breaking one branch.
9
+ *
10
+ * The line is deliberate: this file only holds what makes the runtime throw. A
11
+ * flow that is merely suspect — a quick reply nothing matches, a variable nobody
12
+ * writes — parses fine here, because that is a linter's job and a schema can only
13
+ * say "invalid" where a linter can say "warning".
14
+ *
15
+ * It is one pass over the whole flow, wired into `minifiedFlowSchema` alone. Zod
16
+ * skips a `.check()` on a value that already has issues, so a check per action and
17
+ * a check per state would report the innermost problem and hide the rest.
18
+ */
19
+ import type { MinifiedState } from './minifier.ts';
20
+ /** Every rule this file can report. */
21
+ export type FlowRule = 'missing-root-state' | 'root-must-wait' | 'dangling-output' | 'input-less-loop' | 'transition-loop' | 'shadowed-output' | 'invalid-condition' | 'invalid-input-validation' | 'invalid-regex' | 'invalid-variable-name' | 'unreadable-variable' | 'malformed-placeholder' | 'missing-media-type' | 'content-type-mismatch' | 'duplicate-title';
22
+ /** Reports a failure, tagged with the rule so a caller can group or suppress. */
23
+ export type ReportRule = (rule: FlowRule, path: Array<string | number>, message: string) => void;
24
+ /**
25
+ * The rule a zod issue came from, if it came from one of these checks.
26
+ *
27
+ * The id travels in the issue's `params`, which zod types as `Record<string, any>`,
28
+ * so reading it through here is what keeps `FlowRule` meaning anything on the way
29
+ * out — a caller that reaches into `params` itself gets `any` back.
30
+ */
31
+ export declare function flowRuleOf(issue: {
32
+ code: string;
33
+ params?: Record<string, unknown>;
34
+ }): FlowRule | undefined;
35
+ export declare const VARIABLE_NAME: RegExp;
36
+ /** `Variables/VariableSource.cs`: a name whose first segment is one of these reads a provider. */
37
+ export declare const PROVIDER_NAMESPACES: Set<string>;
38
+ /** `Models/Flow.cs`: an output names a state, or a `{{variable}}` resolved at runtime. */
39
+ export declare const isVariableOutput: (stateId: string) => boolean;
40
+ /**
41
+ * `Models/Flow.cs::Validate`, walked in one pass so every problem in the flow is
42
+ * reported at once.
43
+ */
44
+ export declare function checkFlow(flow: Record<string, MinifiedState>, report: ReportRule): void;
45
+ /**
46
+ * Every `{{reference}}` a state carries, deduped, with script sources masked out:
47
+ * a script's braces are a doc comment or a nested object literal, not a read.
48
+ */
49
+ export declare function placeholderReadsOf(state: MinifiedState): Array<string>;
50
+ //# sourceMappingURL=flow-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-rules.d.ts","sourceRoot":"","sources":["../../../src/utils/flow-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAiC,aAAa,EAAE,MAAM,eAAe,CAAA;AAEjF,uCAAuC;AACvC,MAAM,MAAM,QAAQ,GACd,oBAAoB,GACpB,gBAAgB,GAChB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,mBAAmB,GACnB,0BAA0B,GAC1B,eAAe,GACf,uBAAuB,GACvB,qBAAqB,GACrB,uBAAuB,GACvB,oBAAoB,GACpB,uBAAuB,GACvB,iBAAiB,CAAA;AAEvB,iFAAiF;AACjF,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;AAEhG;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,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