easy-email-pro-core 1.57.13 → 1.58.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.
- package/lib/index.cjs.js +1 -1
- package/lib/index.es.js +40 -39
- package/lib/typings/__tests__/ai.test.d.ts +1 -0
- package/lib/typings/__tests__/validation.test.d.ts +1 -0
- package/lib/typings/ai/editor-context.d.ts +18 -0
- package/lib/typings/ai/index.d.ts +4 -0
- package/lib/typings/ai/protocol.d.ts +7 -0
- package/lib/typings/ai/tools.d.ts +108 -0
- package/lib/typings/ai/types.d.ts +179 -0
- package/lib/typings/index.d.ts +1 -0
- package/lib/typings/validation/index.d.ts +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AiDecisionChoice, AiEditorContextPayload, EasyEmailImageResultPayload } from "./types";
|
|
2
|
+
import { type AiToolTarget } from "./tools";
|
|
3
|
+
export declare function selectedTargetFromContext(editorContext: AiEditorContextPayload | undefined): AiToolTarget | null;
|
|
4
|
+
export declare function canReplaceTargetImage(target: AiToolTarget | null, selectedType: string | null): boolean;
|
|
5
|
+
export declare function imageReplacementTarget(activeRun: Pick<{
|
|
6
|
+
selectedTarget: AiToolTarget | null;
|
|
7
|
+
selectedType: string | null;
|
|
8
|
+
}, "selectedTarget" | "selectedType">, resultTarget?: AiToolTarget | null): AiToolTarget | null;
|
|
9
|
+
export declare function isHighConfidenceImageTarget(target: AiToolTarget | null | undefined, confidence?: EasyEmailImageResultPayload["confidence"]): boolean;
|
|
10
|
+
export declare function targetsSameBlock(a: AiToolTarget | null, b: AiToolTarget | null): boolean;
|
|
11
|
+
export declare function canAutoReplaceImageTarget(activeRun: Pick<{
|
|
12
|
+
selectedTarget: AiToolTarget | null;
|
|
13
|
+
selectedType: string | null;
|
|
14
|
+
}, "selectedTarget" | "selectedType">, target: AiToolTarget | null | undefined, confidence?: EasyEmailImageResultPayload["confidence"]): boolean;
|
|
15
|
+
export declare function imageChoiceDescription(image: NonNullable<AiEditorContextPayload["images"]>[number]): string | undefined;
|
|
16
|
+
export declare function imageDecisionChoices(payload: EasyEmailImageResultPayload, editorImages: AiEditorContextPayload["images"], imageLabel?: string): AiDecisionChoice[];
|
|
17
|
+
export declare function imageTargetAttributeKey(editorImages: AiEditorContextPayload["images"], target: AiToolTarget | null | undefined): string;
|
|
18
|
+
export declare function choiceImageAttributeKey(choice: AiDecisionChoice): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AiAgentEvent, AiChatResult } from "./types";
|
|
2
|
+
export declare const AI_AGENT_FEATURE = "AI_AGENT";
|
|
3
|
+
export declare function assertAiAgentFeatureEnabled(): void;
|
|
4
|
+
export declare function readEasyEmailAiError(response: Response): Promise<string>;
|
|
5
|
+
export declare function parseEasyEmailSseMessage(rawMessage: string): AiAgentEvent | null;
|
|
6
|
+
export declare function parseEasyEmailAiStream(stream: ReadableStream<Uint8Array>, onEvent?: (event: AiAgentEvent) => void): Promise<AiAgentEvent[]>;
|
|
7
|
+
export declare function resolveAiChatResult(result: AiChatResult | undefined, onEvent?: (event: AiAgentEvent) => void): Promise<AiAgentEvent[]>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export type AiToolTarget = {
|
|
2
|
+
selected: true;
|
|
3
|
+
} | {
|
|
4
|
+
id: string;
|
|
5
|
+
} | {
|
|
6
|
+
uid: string;
|
|
7
|
+
} | {
|
|
8
|
+
type: string;
|
|
9
|
+
index?: number;
|
|
10
|
+
};
|
|
11
|
+
export type AiToolCall = {
|
|
12
|
+
name: "update_text";
|
|
13
|
+
target: AiToolTarget;
|
|
14
|
+
text: string;
|
|
15
|
+
} | {
|
|
16
|
+
name: "update_attribute";
|
|
17
|
+
target: AiToolTarget;
|
|
18
|
+
key: string;
|
|
19
|
+
value: unknown;
|
|
20
|
+
} | {
|
|
21
|
+
name: "update_mobile_attribute";
|
|
22
|
+
target: AiToolTarget;
|
|
23
|
+
key: string;
|
|
24
|
+
value: unknown;
|
|
25
|
+
} | {
|
|
26
|
+
name: "update_attributes";
|
|
27
|
+
target: AiToolTarget;
|
|
28
|
+
attributes: Record<string, unknown>;
|
|
29
|
+
scope?: "desktop" | "mobile";
|
|
30
|
+
} | {
|
|
31
|
+
name: "update_data";
|
|
32
|
+
target: AiToolTarget;
|
|
33
|
+
key: string;
|
|
34
|
+
value: unknown;
|
|
35
|
+
} | {
|
|
36
|
+
name: "replace_children";
|
|
37
|
+
target: AiToolTarget;
|
|
38
|
+
children: unknown[];
|
|
39
|
+
} | {
|
|
40
|
+
name: "set_visibility";
|
|
41
|
+
target: AiToolTarget;
|
|
42
|
+
desktop: boolean;
|
|
43
|
+
mobile: boolean;
|
|
44
|
+
} | {
|
|
45
|
+
name: "replace_block";
|
|
46
|
+
target: AiToolTarget;
|
|
47
|
+
block: unknown;
|
|
48
|
+
} | {
|
|
49
|
+
name: "update_link";
|
|
50
|
+
target: AiToolTarget;
|
|
51
|
+
href: string;
|
|
52
|
+
blank?: boolean;
|
|
53
|
+
title?: string;
|
|
54
|
+
} | {
|
|
55
|
+
name: "move_up" | "move_down" | "duplicate" | "delete_node";
|
|
56
|
+
target: AiToolTarget;
|
|
57
|
+
} | {
|
|
58
|
+
name: "add_block_after";
|
|
59
|
+
target: AiToolTarget;
|
|
60
|
+
block: unknown;
|
|
61
|
+
} | {
|
|
62
|
+
name: "add_block_before";
|
|
63
|
+
target: AiToolTarget;
|
|
64
|
+
block: unknown;
|
|
65
|
+
} | {
|
|
66
|
+
name: "select_node";
|
|
67
|
+
target: AiToolTarget;
|
|
68
|
+
} | {
|
|
69
|
+
name: "apply_template";
|
|
70
|
+
template: unknown;
|
|
71
|
+
};
|
|
72
|
+
export type AiAppliedChange = {
|
|
73
|
+
id: string;
|
|
74
|
+
label: string;
|
|
75
|
+
description: string;
|
|
76
|
+
target: AiToolTarget;
|
|
77
|
+
path?: number[];
|
|
78
|
+
};
|
|
79
|
+
export type EasyEmailToolCallsPayload = {
|
|
80
|
+
summary?: string | null;
|
|
81
|
+
toolCalls: AiToolCall[];
|
|
82
|
+
fallbackTemplate?: unknown | null;
|
|
83
|
+
};
|
|
84
|
+
export type EasyEmailToolCallsPayloadInput = Partial<EasyEmailToolCallsPayload> & {
|
|
85
|
+
summary?: string | null;
|
|
86
|
+
toolCalls?: AiToolCall[];
|
|
87
|
+
fallbackTemplate?: unknown | null;
|
|
88
|
+
tool_calls?: AiToolCall[];
|
|
89
|
+
fallback_template?: unknown | null;
|
|
90
|
+
};
|
|
91
|
+
export type AiToolApplyResult = {
|
|
92
|
+
applied: number;
|
|
93
|
+
skipped: number;
|
|
94
|
+
errors: string[];
|
|
95
|
+
changes?: AiAppliedChange[];
|
|
96
|
+
};
|
|
97
|
+
export declare const missingInitialSelectionTarget: {
|
|
98
|
+
id: string;
|
|
99
|
+
};
|
|
100
|
+
export declare function isSelectedTarget(target: AiToolTarget): boolean;
|
|
101
|
+
export declare function normalizeToolCallsPayload(payload: EasyEmailToolCallsPayloadInput): {
|
|
102
|
+
toolCalls: AiToolCall[];
|
|
103
|
+
fallbackTemplate: unknown;
|
|
104
|
+
summary?: string | null;
|
|
105
|
+
tool_calls?: AiToolCall[];
|
|
106
|
+
fallback_template?: unknown | null;
|
|
107
|
+
};
|
|
108
|
+
export declare function freezeSelectedTargets(toolCalls: AiToolCall[], selectedTarget: AiToolTarget | null): AiToolCall[];
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { AiToolTarget, EasyEmailToolCallsPayload } from "./tools";
|
|
2
|
+
export type AiAgentStatus = "RUNNING" | "FINISHED" | "ERROR";
|
|
3
|
+
export type AiAgentImageAttachment = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
mimeType: string;
|
|
7
|
+
dataUrl?: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
size?: number;
|
|
10
|
+
};
|
|
11
|
+
export type AiDecisionChoice = {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
value?: unknown;
|
|
16
|
+
target?: AiToolTarget;
|
|
17
|
+
thumbnail?: string;
|
|
18
|
+
prompt?: string;
|
|
19
|
+
};
|
|
20
|
+
export type AiDecisionRequestPayload = {
|
|
21
|
+
id: string;
|
|
22
|
+
kind: "style_direction" | "target_block" | "missing_detail";
|
|
23
|
+
title: string;
|
|
24
|
+
message: string;
|
|
25
|
+
choices: AiDecisionChoice[];
|
|
26
|
+
allowCustom?: boolean;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
image?: AiAgentImageAttachment;
|
|
29
|
+
};
|
|
30
|
+
export type AiDecisionResponsePayload = {
|
|
31
|
+
decisionId: string;
|
|
32
|
+
choiceId?: string;
|
|
33
|
+
label?: string;
|
|
34
|
+
value?: unknown;
|
|
35
|
+
customText?: string;
|
|
36
|
+
};
|
|
37
|
+
export type AiEditorContextPayload = {
|
|
38
|
+
selected?: {
|
|
39
|
+
id?: string;
|
|
40
|
+
uid?: string;
|
|
41
|
+
type?: string;
|
|
42
|
+
path?: number[];
|
|
43
|
+
title?: string;
|
|
44
|
+
attributes?: Record<string, unknown>;
|
|
45
|
+
data?: Record<string, unknown>;
|
|
46
|
+
layout?: {
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
};
|
|
50
|
+
descendants?: Array<{
|
|
51
|
+
id?: string;
|
|
52
|
+
uid?: string;
|
|
53
|
+
type?: string;
|
|
54
|
+
path?: number[];
|
|
55
|
+
title?: string;
|
|
56
|
+
text?: string;
|
|
57
|
+
}>;
|
|
58
|
+
} | null;
|
|
59
|
+
images?: Array<{
|
|
60
|
+
id?: string;
|
|
61
|
+
uid?: string;
|
|
62
|
+
type?: string;
|
|
63
|
+
path?: number[];
|
|
64
|
+
title?: string;
|
|
65
|
+
src?: string;
|
|
66
|
+
source?: "image" | "background";
|
|
67
|
+
attributeKey?: string;
|
|
68
|
+
width?: number;
|
|
69
|
+
height?: number;
|
|
70
|
+
index?: number;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
export type EasyEmailResultPayload = {
|
|
74
|
+
valid: boolean;
|
|
75
|
+
errors: string[];
|
|
76
|
+
template: unknown | null;
|
|
77
|
+
commitSha?: string | null;
|
|
78
|
+
branchName?: string | null;
|
|
79
|
+
summary?: string | null;
|
|
80
|
+
};
|
|
81
|
+
export type EasyEmailAnswerPayload = {
|
|
82
|
+
answer: string;
|
|
83
|
+
};
|
|
84
|
+
export type EasyEmailImageResultPayload = {
|
|
85
|
+
summary?: string | null;
|
|
86
|
+
images: AiAgentImageAttachment[];
|
|
87
|
+
target?: AiToolTarget | null;
|
|
88
|
+
confidence?: "high" | "low" | "ambiguous" | null;
|
|
89
|
+
candidates?: AiDecisionChoice[];
|
|
90
|
+
intent?: "replace" | "insert" | "attach" | null;
|
|
91
|
+
revisedPrompt?: string | null;
|
|
92
|
+
model?: string | null;
|
|
93
|
+
size?: string | null;
|
|
94
|
+
};
|
|
95
|
+
export type AiTokenUsage = {
|
|
96
|
+
model?: string;
|
|
97
|
+
inputTokens?: number;
|
|
98
|
+
outputTokens?: number;
|
|
99
|
+
totalTokens?: number;
|
|
100
|
+
cachedInputTokens?: number;
|
|
101
|
+
reasoningTokens?: number;
|
|
102
|
+
};
|
|
103
|
+
export type AiWebSource = {
|
|
104
|
+
url: string;
|
|
105
|
+
title?: string;
|
|
106
|
+
};
|
|
107
|
+
export type AiAgentEvent = {
|
|
108
|
+
seq: number;
|
|
109
|
+
type: "status";
|
|
110
|
+
payload: {
|
|
111
|
+
status: AiAgentStatus;
|
|
112
|
+
exitCode?: number | null;
|
|
113
|
+
};
|
|
114
|
+
createdAt: string;
|
|
115
|
+
} | {
|
|
116
|
+
seq: number;
|
|
117
|
+
type: "input";
|
|
118
|
+
payload: {
|
|
119
|
+
text: string;
|
|
120
|
+
};
|
|
121
|
+
createdAt: string;
|
|
122
|
+
} | {
|
|
123
|
+
seq: number;
|
|
124
|
+
type: "error";
|
|
125
|
+
payload: {
|
|
126
|
+
message: string;
|
|
127
|
+
};
|
|
128
|
+
createdAt: string;
|
|
129
|
+
} | {
|
|
130
|
+
seq: number;
|
|
131
|
+
type: "easy_email_result";
|
|
132
|
+
payload: EasyEmailResultPayload;
|
|
133
|
+
createdAt: string;
|
|
134
|
+
} | {
|
|
135
|
+
seq: number;
|
|
136
|
+
type: "easy_email_answer";
|
|
137
|
+
payload: EasyEmailAnswerPayload;
|
|
138
|
+
createdAt: string;
|
|
139
|
+
} | {
|
|
140
|
+
seq: number;
|
|
141
|
+
type: "easy_email_tool_calls";
|
|
142
|
+
payload: EasyEmailToolCallsPayload;
|
|
143
|
+
createdAt: string;
|
|
144
|
+
} | {
|
|
145
|
+
seq: number;
|
|
146
|
+
type: "image_result";
|
|
147
|
+
payload: EasyEmailImageResultPayload;
|
|
148
|
+
createdAt: string;
|
|
149
|
+
} | {
|
|
150
|
+
seq: number;
|
|
151
|
+
type: "decision_request";
|
|
152
|
+
payload: AiDecisionRequestPayload;
|
|
153
|
+
createdAt: string;
|
|
154
|
+
} | {
|
|
155
|
+
seq: number;
|
|
156
|
+
type: "usage";
|
|
157
|
+
payload: AiTokenUsage;
|
|
158
|
+
createdAt: string;
|
|
159
|
+
} | {
|
|
160
|
+
seq: number;
|
|
161
|
+
type: "sources";
|
|
162
|
+
payload: {
|
|
163
|
+
sources: AiWebSource[];
|
|
164
|
+
};
|
|
165
|
+
createdAt: string;
|
|
166
|
+
};
|
|
167
|
+
export type RespondEasyEmailBody = {
|
|
168
|
+
message: string;
|
|
169
|
+
template?: unknown;
|
|
170
|
+
history?: unknown;
|
|
171
|
+
images?: AiAgentImageAttachment[];
|
|
172
|
+
editorContext?: AiEditorContextPayload;
|
|
173
|
+
decisionResponse?: AiDecisionResponsePayload;
|
|
174
|
+
};
|
|
175
|
+
export type AiChatRequest = RespondEasyEmailBody & {
|
|
176
|
+
signal?: AbortSignal;
|
|
177
|
+
};
|
|
178
|
+
export type AiChatResult = AiAgentEvent[] | ReadableStream<Uint8Array> | Response;
|
|
179
|
+
export type AiChatHandler = (request: AiChatRequest) => Promise<AiChatResult>;
|
package/lib/typings/index.d.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ValidationErrorCode = "invalid_element" | "invalid_text" | "missing_field" | "unknown_type" | "invalid_parent" | "duplicate_id" | "duplicate_uid";
|
|
2
|
+
export type ValidationError = {
|
|
3
|
+
path: string;
|
|
4
|
+
code: ValidationErrorCode;
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
export type ValidationResult = {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
errors: ValidationError[];
|
|
10
|
+
};
|
|
11
|
+
export declare function validateEasyEmailElement(value: unknown, context?: {
|
|
12
|
+
path?: string;
|
|
13
|
+
parentType?: string;
|
|
14
|
+
}): ValidationResult;
|
|
15
|
+
export declare function validateEasyEmailTemplate(value: unknown): ValidationResult;
|
|
16
|
+
export declare function normalizeEasyEmailTemplateShape<T>(value: T): T;
|
|
17
|
+
export declare function repairEasyEmailTemplateNesting<T>(value: T): T;
|