@daf-sdk/runtime 1.0.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/dist/chunk-4H6PEYL7.mjs +1221 -0
- package/dist/chunk-HGSJ2UZZ.mjs +625 -0
- package/dist/chunk-HT5X5ZSB.mjs +7231 -0
- package/dist/encryption-5J2VZDSY.mjs +11 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +9336 -0
- package/dist/index.mjs +318 -0
- package/dist/mongodbService-PJCZZWQ3.mjs +23 -0
- package/dist/notion-3VBQFXSQ.mjs +52 -0
- package/dist/protocol/index.d.mts +589 -0
- package/dist/protocol/index.d.ts +589 -0
- package/dist/protocol/index.js +735 -0
- package/dist/protocol/index.mjs +174 -0
- package/dist/runtime/index.d.mts +957 -0
- package/dist/runtime/index.d.ts +957 -0
- package/dist/runtime/index.js +8628 -0
- package/dist/runtime/index.mjs +146 -0
- package/package.json +64 -0
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/protocol/index.ts
|
|
21
|
+
var protocol_exports = {};
|
|
22
|
+
__export(protocol_exports, {
|
|
23
|
+
ACTION_TYPES: () => ACTION_TYPES,
|
|
24
|
+
DAFDocumentBuilder: () => DAFDocumentBuilder,
|
|
25
|
+
DAF_VERSION: () => DAF_VERSION,
|
|
26
|
+
DEFAULT_SCRAPE_TIMEOUT: () => DEFAULT_SCRAPE_TIMEOUT,
|
|
27
|
+
DEFAULT_SEARCH_LIMIT: () => DEFAULT_SEARCH_LIMIT,
|
|
28
|
+
EDITOR_ACTION_TYPES: () => EDITOR_ACTION_TYPES,
|
|
29
|
+
LOOP_TYPES: () => LOOP_TYPES,
|
|
30
|
+
MAX_PROCESS_DEPTH: () => MAX_PROCESS_DEPTH,
|
|
31
|
+
PROCESS_TYPES: () => PROCESS_TYPES,
|
|
32
|
+
ProcessBuilder: () => ProcessBuilder,
|
|
33
|
+
RESOURCE_TYPES: () => RESOURCE_TYPES,
|
|
34
|
+
STEP_TYPES: () => STEP_TYPES,
|
|
35
|
+
SUPPORTED_VERSIONS: () => SUPPORTED_VERSIONS,
|
|
36
|
+
WRITE_OPERATIONS: () => WRITE_OPERATIONS,
|
|
37
|
+
actionSchema: () => actionSchema,
|
|
38
|
+
addDocumentAction: () => addDocumentAction,
|
|
39
|
+
addFolderAction: () => addFolderAction,
|
|
40
|
+
completeSentenceAction: () => completeSentenceAction,
|
|
41
|
+
completionWithoutPromptStep: () => completionWithoutPromptStep,
|
|
42
|
+
conditionalLoopStep: () => conditionalLoopStep,
|
|
43
|
+
createDatabaseAction: () => createDatabaseAction,
|
|
44
|
+
dafDocumentSchema: () => dafDocumentSchema,
|
|
45
|
+
deleteDatabaseAction: () => deleteDatabaseAction,
|
|
46
|
+
directiveAction: () => directiveAction,
|
|
47
|
+
directiveParamsSchema: () => directiveParamsSchema,
|
|
48
|
+
duplicateDatabaseAction: () => duplicateDatabaseAction,
|
|
49
|
+
duplicateDocumentAction: () => duplicateDocumentAction,
|
|
50
|
+
editorActionBaseParamsSchema: () => editorActionBaseParamsSchema,
|
|
51
|
+
editorActionSchema: () => editorActionSchema,
|
|
52
|
+
extendTextAction: () => extendTextAction,
|
|
53
|
+
fixSpellingGrammarAction: () => fixSpellingGrammarAction,
|
|
54
|
+
fixedLoopStep: () => fixedLoopStep,
|
|
55
|
+
formatDocumentAction: () => formatDocumentAction,
|
|
56
|
+
formatTextAction: () => formatTextAction,
|
|
57
|
+
googleDocResource: () => googleDocResource,
|
|
58
|
+
googleDriveFolderResource: () => googleDriveFolderResource,
|
|
59
|
+
isValidAction: () => isValidAction,
|
|
60
|
+
isValidDAFDocument: () => isValidDAFDocument,
|
|
61
|
+
isValidEditorAction: () => isValidEditorAction,
|
|
62
|
+
isValidProcess: () => isValidProcess,
|
|
63
|
+
isValidResource: () => isValidResource,
|
|
64
|
+
isValidStep: () => isValidStep,
|
|
65
|
+
newsSearchAction: () => newsSearchAction,
|
|
66
|
+
newsSearchParamsSchema: () => newsSearchParamsSchema,
|
|
67
|
+
notionPageResource: () => notionPageResource,
|
|
68
|
+
previewSearchAction: () => previewSearchAction,
|
|
69
|
+
previewSearchParamsSchema: () => previewSearchParamsSchema,
|
|
70
|
+
processSchema: () => processSchema,
|
|
71
|
+
processStep: () => processStep,
|
|
72
|
+
promptStep: () => promptStep,
|
|
73
|
+
readDatabaseAction: () => readDatabaseAction,
|
|
74
|
+
readDocumentAction: () => readDocumentAction,
|
|
75
|
+
readDocumentParamsSchema: () => readDocumentParamsSchema,
|
|
76
|
+
readFolderAction: () => readFolderAction,
|
|
77
|
+
reduceTextAction: () => reduceTextAction,
|
|
78
|
+
removeDocumentAction: () => removeDocumentAction,
|
|
79
|
+
removeFolderAction: () => removeFolderAction,
|
|
80
|
+
renameDocumentAction: () => renameDocumentAction,
|
|
81
|
+
renameFolderAction: () => renameFolderAction,
|
|
82
|
+
resourceSchema: () => resourceSchema,
|
|
83
|
+
rewriteAction: () => rewriteAction,
|
|
84
|
+
scrapeAction: () => scrapeAction,
|
|
85
|
+
scrapeParamsSchema: () => scrapeParamsSchema,
|
|
86
|
+
searchAction: () => searchAction,
|
|
87
|
+
searchParamsSchema: () => searchParamsSchema,
|
|
88
|
+
sendEmailAction: () => sendEmailAction,
|
|
89
|
+
sendEmailParamsSchema: () => sendEmailParamsSchema,
|
|
90
|
+
simplifyAction: () => simplifyAction,
|
|
91
|
+
skipCompletionStep: () => skipCompletionStep,
|
|
92
|
+
stepSchema: () => stepSchema,
|
|
93
|
+
tavilySearchAction: () => tavilySearchAction,
|
|
94
|
+
tavilySearchParamsSchema: () => tavilySearchParamsSchema,
|
|
95
|
+
translateAction: () => translateAction,
|
|
96
|
+
translateParamsSchema: () => translateParamsSchema,
|
|
97
|
+
updateDatabaseAction: () => updateDatabaseAction,
|
|
98
|
+
userFeedbackStep: () => userFeedbackStep,
|
|
99
|
+
validateAction: () => validateAction,
|
|
100
|
+
validateDAFDocument: () => validateDAFDocument,
|
|
101
|
+
validateEditorAction: () => validateEditorAction,
|
|
102
|
+
validateProcess: () => validateProcess,
|
|
103
|
+
validateResource: () => validateResource,
|
|
104
|
+
validateStep: () => validateStep,
|
|
105
|
+
writeDatabaseAction: () => writeDatabaseAction,
|
|
106
|
+
writeDocumentAction: () => writeDocumentAction,
|
|
107
|
+
writeDocumentParamsSchema: () => writeDocumentParamsSchema
|
|
108
|
+
});
|
|
109
|
+
module.exports = __toCommonJS(protocol_exports);
|
|
110
|
+
|
|
111
|
+
// src/protocol/constants.ts
|
|
112
|
+
var DAF_VERSION = "1.2.0";
|
|
113
|
+
var SUPPORTED_VERSIONS = ["1.0.0", "1.1.0", "1.2.0"];
|
|
114
|
+
var PROCESS_TYPES = {
|
|
115
|
+
STATIC_DIALOGUE: "STATIC_DIALOGUE",
|
|
116
|
+
ADVANCED_DIALOGUE: "ADVANCED_DIALOGUE"
|
|
117
|
+
};
|
|
118
|
+
var STEP_TYPES = {
|
|
119
|
+
PROMPT: "prompt",
|
|
120
|
+
PROCESS: "process",
|
|
121
|
+
USER_FEEDBACK: "userFeedback",
|
|
122
|
+
COMPLETION_WITHOUT_PROMPT: "completionWithoutPrompt"
|
|
123
|
+
};
|
|
124
|
+
var LOOP_TYPES = {
|
|
125
|
+
FIXED: "fixed",
|
|
126
|
+
STOP_ON: "stopOn"
|
|
127
|
+
};
|
|
128
|
+
var ACTION_TYPES = {
|
|
129
|
+
SEND_EMAIL: "sendEmail",
|
|
130
|
+
SCRAPE: "scrape",
|
|
131
|
+
SEARCH: "search",
|
|
132
|
+
NEWS_SEARCH: "newsSearch",
|
|
133
|
+
PREVIEW_SEARCH: "previewSearch",
|
|
134
|
+
TAVILY_SEARCH: "tavilySearch",
|
|
135
|
+
READ_DOCUMENT: "readDocument",
|
|
136
|
+
WRITE_DOCUMENT: "writeDocument",
|
|
137
|
+
FORMAT_DOCUMENT: "formatDocument",
|
|
138
|
+
REMOVE_DOCUMENT: "removeDocument",
|
|
139
|
+
RENAME_DOCUMENT: "renameDocument",
|
|
140
|
+
DUPLICATE_DOCUMENT: "duplicateDocument",
|
|
141
|
+
ADD_DOCUMENT: "addDocument",
|
|
142
|
+
ADD_FOLDER: "addFolder",
|
|
143
|
+
REMOVE_FOLDER: "removeFolder",
|
|
144
|
+
READ_FOLDER: "readFolder",
|
|
145
|
+
RENAME_FOLDER: "renameFolder",
|
|
146
|
+
CREATE_DATABASE: "createDatabase",
|
|
147
|
+
READ_DATABASE: "readDatabase",
|
|
148
|
+
UPDATE_DATABASE: "updateDatabase",
|
|
149
|
+
DELETE_DATABASE: "deleteDatabase",
|
|
150
|
+
WRITE_DATABASE: "writeDatabase",
|
|
151
|
+
DUPLICATE_DATABASE: "duplicateDatabase"
|
|
152
|
+
};
|
|
153
|
+
var EDITOR_ACTION_TYPES = {
|
|
154
|
+
FIX_SPELLING_GRAMMAR: "fixSpellingGrammar",
|
|
155
|
+
REWRITE: "rewrite",
|
|
156
|
+
EXTEND_TEXT: "extendText",
|
|
157
|
+
REDUCE_TEXT: "reduceText",
|
|
158
|
+
SIMPLIFY: "simplify",
|
|
159
|
+
COMPLETE_SENTENCE: "completeSentence",
|
|
160
|
+
TRANSLATE: "translate",
|
|
161
|
+
FORMAT_TEXT: "formatText",
|
|
162
|
+
DIRECTIVE: "directive"
|
|
163
|
+
};
|
|
164
|
+
var RESOURCE_TYPES = {
|
|
165
|
+
GOOGLE_DOC: "google_doc",
|
|
166
|
+
NOTION_PAGE: "notion_page",
|
|
167
|
+
GOOGLE_DRIVE_FOLDER: "google_drive_folder"
|
|
168
|
+
};
|
|
169
|
+
var WRITE_OPERATIONS = {
|
|
170
|
+
REPLACE: "replace",
|
|
171
|
+
APPEND: "append",
|
|
172
|
+
SELECTIVE: "selective"
|
|
173
|
+
};
|
|
174
|
+
var MAX_PROCESS_DEPTH = 10;
|
|
175
|
+
var DEFAULT_SCRAPE_TIMEOUT = 3e4;
|
|
176
|
+
var DEFAULT_SEARCH_LIMIT = 5;
|
|
177
|
+
|
|
178
|
+
// src/protocol/schemas.ts
|
|
179
|
+
var import_zod = require("zod");
|
|
180
|
+
var resourceSchema = import_zod.z.object({
|
|
181
|
+
name: import_zod.z.string().min(1, "Resource name is required"),
|
|
182
|
+
type: import_zod.z.enum([
|
|
183
|
+
RESOURCE_TYPES.GOOGLE_DOC,
|
|
184
|
+
RESOURCE_TYPES.NOTION_PAGE,
|
|
185
|
+
RESOURCE_TYPES.GOOGLE_DRIVE_FOLDER
|
|
186
|
+
]),
|
|
187
|
+
url: import_zod.z.url("Resource URL must be valid"),
|
|
188
|
+
isGlobal: import_zod.z.boolean()
|
|
189
|
+
});
|
|
190
|
+
var stepSchema = import_zod.z.object({
|
|
191
|
+
type: import_zod.z.enum([
|
|
192
|
+
STEP_TYPES.PROMPT,
|
|
193
|
+
STEP_TYPES.PROCESS,
|
|
194
|
+
STEP_TYPES.USER_FEEDBACK,
|
|
195
|
+
STEP_TYPES.COMPLETION_WITHOUT_PROMPT
|
|
196
|
+
]),
|
|
197
|
+
prompt: import_zod.z.string().optional(),
|
|
198
|
+
processId: import_zod.z.string().optional(),
|
|
199
|
+
loopType: import_zod.z.enum([LOOP_TYPES.FIXED, LOOP_TYPES.STOP_ON]).optional(),
|
|
200
|
+
forLoopCount: import_zod.z.int().positive().optional(),
|
|
201
|
+
stopOnKeyword: import_zod.z.string().optional(),
|
|
202
|
+
stopOnMaxLoops: import_zod.z.int().positive().optional(),
|
|
203
|
+
skipCompletion: import_zod.z.boolean().optional()
|
|
204
|
+
}).refine(
|
|
205
|
+
(data) => {
|
|
206
|
+
if (data.type === STEP_TYPES.PROMPT && !data.prompt) return false;
|
|
207
|
+
if (data.type === STEP_TYPES.PROCESS && !data.processId) return false;
|
|
208
|
+
if (data.loopType === LOOP_TYPES.FIXED && !data.forLoopCount) return false;
|
|
209
|
+
if (data.loopType === LOOP_TYPES.STOP_ON && !data.stopOnKeyword) return false;
|
|
210
|
+
return true;
|
|
211
|
+
},
|
|
212
|
+
{ error: "Invalid step configuration" }
|
|
213
|
+
);
|
|
214
|
+
var processSchema = import_zod.z.object({
|
|
215
|
+
name: import_zod.z.string().min(1, "Process name is required"),
|
|
216
|
+
description: import_zod.z.string().optional(),
|
|
217
|
+
processType: import_zod.z.enum([PROCESS_TYPES.STATIC_DIALOGUE, PROCESS_TYPES.ADVANCED_DIALOGUE]),
|
|
218
|
+
stopProcessKeyword: import_zod.z.string().optional(),
|
|
219
|
+
resources: import_zod.z.array(resourceSchema).optional(),
|
|
220
|
+
steps: import_zod.z.array(stepSchema).min(1, "Process must have at least one step")
|
|
221
|
+
}).refine(
|
|
222
|
+
(data) => {
|
|
223
|
+
if (data.stopProcessKeyword && data.processType !== PROCESS_TYPES.ADVANCED_DIALOGUE) return false;
|
|
224
|
+
return true;
|
|
225
|
+
},
|
|
226
|
+
{ error: "stopProcessKeyword is only valid for ADVANCED_DIALOGUE processes" }
|
|
227
|
+
);
|
|
228
|
+
var dafDocumentSchema = import_zod.z.object({
|
|
229
|
+
dafVersion: import_zod.z.enum(SUPPORTED_VERSIONS, {
|
|
230
|
+
message: `DAF version must be one of: ${SUPPORTED_VERSIONS.join(", ")}`
|
|
231
|
+
}),
|
|
232
|
+
variables: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).optional(),
|
|
233
|
+
resources: import_zod.z.array(resourceSchema).optional(),
|
|
234
|
+
processes: import_zod.z.array(processSchema).min(1, "At least one process is required")
|
|
235
|
+
});
|
|
236
|
+
var sendEmailParamsSchema = import_zod.z.object({
|
|
237
|
+
to: import_zod.z.email("Invalid email address"),
|
|
238
|
+
subject: import_zod.z.string().min(1, "Subject is required"),
|
|
239
|
+
content: import_zod.z.string().min(1, "Content is required")
|
|
240
|
+
});
|
|
241
|
+
var scrapeParamsSchema = import_zod.z.object({
|
|
242
|
+
url: import_zod.z.url("Invalid URL"),
|
|
243
|
+
timeout: import_zod.z.int().positive().optional()
|
|
244
|
+
});
|
|
245
|
+
var searchParamsSchema = import_zod.z.object({
|
|
246
|
+
query: import_zod.z.string().min(1, "Query is required"),
|
|
247
|
+
limit: import_zod.z.int().positive().optional()
|
|
248
|
+
});
|
|
249
|
+
var readDocumentParamsSchema = import_zod.z.object({
|
|
250
|
+
resourceName: import_zod.z.string().min(1, "Resource name is required")
|
|
251
|
+
});
|
|
252
|
+
var writeDocumentParamsSchema = import_zod.z.object({
|
|
253
|
+
resourceName: import_zod.z.string().min(1, "Resource name is required"),
|
|
254
|
+
operation: import_zod.z.enum([WRITE_OPERATIONS.REPLACE, WRITE_OPERATIONS.APPEND, WRITE_OPERATIONS.SELECTIVE]),
|
|
255
|
+
content: import_zod.z.string().min(1, "Content is required"),
|
|
256
|
+
findText: import_zod.z.string().optional(),
|
|
257
|
+
replaceText: import_zod.z.string().optional(),
|
|
258
|
+
replaceWithContent: import_zod.z.boolean().optional()
|
|
259
|
+
}).refine(
|
|
260
|
+
(data) => {
|
|
261
|
+
if (data.operation === WRITE_OPERATIONS.SELECTIVE && !data.findText) return false;
|
|
262
|
+
return true;
|
|
263
|
+
},
|
|
264
|
+
{ error: "Selective operation requires findText parameter" }
|
|
265
|
+
);
|
|
266
|
+
var newsSearchParamsSchema = import_zod.z.object({
|
|
267
|
+
query: import_zod.z.string().min(1, "Query is required"),
|
|
268
|
+
limit: import_zod.z.int().positive().optional(),
|
|
269
|
+
ignoreInvalidURLs: import_zod.z.boolean().optional(),
|
|
270
|
+
tbs: import_zod.z.string().optional(),
|
|
271
|
+
location: import_zod.z.string().optional()
|
|
272
|
+
});
|
|
273
|
+
var previewSearchParamsSchema = import_zod.z.object({
|
|
274
|
+
query: import_zod.z.string().min(1, "Query is required"),
|
|
275
|
+
limit: import_zod.z.int().positive().optional(),
|
|
276
|
+
sources: import_zod.z.array(import_zod.z.enum(["web", "news"])).optional()
|
|
277
|
+
});
|
|
278
|
+
var tavilySearchParamsSchema = import_zod.z.object({
|
|
279
|
+
query: import_zod.z.string().min(1, "Query is required"),
|
|
280
|
+
maxResults: import_zod.z.int().positive().optional(),
|
|
281
|
+
searchDepth: import_zod.z.enum(["basic", "advanced"]).optional(),
|
|
282
|
+
includeAnswer: import_zod.z.boolean().optional()
|
|
283
|
+
});
|
|
284
|
+
var editorActionBaseParamsSchema = import_zod.z.object({
|
|
285
|
+
selectedText: import_zod.z.string().min(1, "selectedText is required"),
|
|
286
|
+
from: import_zod.z.int().nonnegative().optional(),
|
|
287
|
+
to: import_zod.z.int().nonnegative().optional()
|
|
288
|
+
});
|
|
289
|
+
var translateParamsSchema = editorActionBaseParamsSchema.extend({
|
|
290
|
+
language: import_zod.z.string().min(1, "language is required")
|
|
291
|
+
});
|
|
292
|
+
var directiveParamsSchema = editorActionBaseParamsSchema.extend({
|
|
293
|
+
directive: import_zod.z.string().min(1, "directive is required")
|
|
294
|
+
});
|
|
295
|
+
var actionSchema = import_zod.z.object({
|
|
296
|
+
type: import_zod.z.literal("action"),
|
|
297
|
+
variant: import_zod.z.enum([
|
|
298
|
+
ACTION_TYPES.SEND_EMAIL,
|
|
299
|
+
ACTION_TYPES.SCRAPE,
|
|
300
|
+
ACTION_TYPES.SEARCH,
|
|
301
|
+
ACTION_TYPES.NEWS_SEARCH,
|
|
302
|
+
ACTION_TYPES.PREVIEW_SEARCH,
|
|
303
|
+
ACTION_TYPES.TAVILY_SEARCH,
|
|
304
|
+
ACTION_TYPES.READ_DOCUMENT,
|
|
305
|
+
ACTION_TYPES.WRITE_DOCUMENT,
|
|
306
|
+
ACTION_TYPES.FORMAT_DOCUMENT,
|
|
307
|
+
ACTION_TYPES.REMOVE_DOCUMENT,
|
|
308
|
+
ACTION_TYPES.RENAME_DOCUMENT,
|
|
309
|
+
ACTION_TYPES.DUPLICATE_DOCUMENT,
|
|
310
|
+
ACTION_TYPES.ADD_DOCUMENT,
|
|
311
|
+
ACTION_TYPES.ADD_FOLDER,
|
|
312
|
+
ACTION_TYPES.REMOVE_FOLDER,
|
|
313
|
+
ACTION_TYPES.READ_FOLDER,
|
|
314
|
+
ACTION_TYPES.RENAME_FOLDER,
|
|
315
|
+
ACTION_TYPES.CREATE_DATABASE,
|
|
316
|
+
ACTION_TYPES.READ_DATABASE,
|
|
317
|
+
ACTION_TYPES.UPDATE_DATABASE,
|
|
318
|
+
ACTION_TYPES.DELETE_DATABASE,
|
|
319
|
+
ACTION_TYPES.WRITE_DATABASE,
|
|
320
|
+
ACTION_TYPES.DUPLICATE_DATABASE
|
|
321
|
+
]),
|
|
322
|
+
parameters: import_zod.z.record(import_zod.z.string(), import_zod.z.any())
|
|
323
|
+
});
|
|
324
|
+
var editorActionSchema = import_zod.z.object({
|
|
325
|
+
type: import_zod.z.literal("editorAction"),
|
|
326
|
+
variant: import_zod.z.enum([
|
|
327
|
+
EDITOR_ACTION_TYPES.FIX_SPELLING_GRAMMAR,
|
|
328
|
+
EDITOR_ACTION_TYPES.REWRITE,
|
|
329
|
+
EDITOR_ACTION_TYPES.EXTEND_TEXT,
|
|
330
|
+
EDITOR_ACTION_TYPES.REDUCE_TEXT,
|
|
331
|
+
EDITOR_ACTION_TYPES.SIMPLIFY,
|
|
332
|
+
EDITOR_ACTION_TYPES.COMPLETE_SENTENCE,
|
|
333
|
+
EDITOR_ACTION_TYPES.TRANSLATE,
|
|
334
|
+
EDITOR_ACTION_TYPES.FORMAT_TEXT,
|
|
335
|
+
EDITOR_ACTION_TYPES.DIRECTIVE
|
|
336
|
+
]),
|
|
337
|
+
parameters: import_zod.z.record(import_zod.z.string(), import_zod.z.any())
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// src/protocol/validators.ts
|
|
341
|
+
var import_zod2 = require("zod");
|
|
342
|
+
function zodToValidationErrors(error) {
|
|
343
|
+
return error.issues.map((issue) => ({
|
|
344
|
+
path: issue.path.join("."),
|
|
345
|
+
message: issue.message,
|
|
346
|
+
code: issue.code
|
|
347
|
+
}));
|
|
348
|
+
}
|
|
349
|
+
function validateDAFDocument(doc) {
|
|
350
|
+
try {
|
|
351
|
+
dafDocumentSchema.parse(doc);
|
|
352
|
+
return { valid: true, errors: [] };
|
|
353
|
+
} catch (error) {
|
|
354
|
+
if (error instanceof import_zod2.ZodError) return { valid: false, errors: zodToValidationErrors(error) };
|
|
355
|
+
return { valid: false, errors: [{ path: "", message: "Unknown validation error" }] };
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function validateProcess(process) {
|
|
359
|
+
try {
|
|
360
|
+
processSchema.parse(process);
|
|
361
|
+
return { valid: true, errors: [] };
|
|
362
|
+
} catch (error) {
|
|
363
|
+
if (error instanceof import_zod2.ZodError) return { valid: false, errors: zodToValidationErrors(error) };
|
|
364
|
+
return { valid: false, errors: [{ path: "", message: "Unknown validation error" }] };
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function validateStep(step) {
|
|
368
|
+
try {
|
|
369
|
+
stepSchema.parse(step);
|
|
370
|
+
return { valid: true, errors: [] };
|
|
371
|
+
} catch (error) {
|
|
372
|
+
if (error instanceof import_zod2.ZodError) return { valid: false, errors: zodToValidationErrors(error) };
|
|
373
|
+
return { valid: false, errors: [{ path: "", message: "Unknown validation error" }] };
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function validateResource(resource) {
|
|
377
|
+
try {
|
|
378
|
+
resourceSchema.parse(resource);
|
|
379
|
+
return { valid: true, errors: [] };
|
|
380
|
+
} catch (error) {
|
|
381
|
+
if (error instanceof import_zod2.ZodError) return { valid: false, errors: zodToValidationErrors(error) };
|
|
382
|
+
return { valid: false, errors: [{ path: "", message: "Unknown validation error" }] };
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function validateAction(action) {
|
|
386
|
+
try {
|
|
387
|
+
const validAction = actionSchema.parse(action);
|
|
388
|
+
switch (validAction.variant) {
|
|
389
|
+
case "sendEmail":
|
|
390
|
+
sendEmailParamsSchema.parse(validAction.parameters);
|
|
391
|
+
break;
|
|
392
|
+
case "scrape":
|
|
393
|
+
scrapeParamsSchema.parse(validAction.parameters);
|
|
394
|
+
break;
|
|
395
|
+
case "search":
|
|
396
|
+
searchParamsSchema.parse(validAction.parameters);
|
|
397
|
+
break;
|
|
398
|
+
case "newsSearch":
|
|
399
|
+
newsSearchParamsSchema.parse(validAction.parameters);
|
|
400
|
+
break;
|
|
401
|
+
case "previewSearch":
|
|
402
|
+
previewSearchParamsSchema.parse(validAction.parameters);
|
|
403
|
+
break;
|
|
404
|
+
case "tavilySearch":
|
|
405
|
+
tavilySearchParamsSchema.parse(validAction.parameters);
|
|
406
|
+
break;
|
|
407
|
+
case "readDocument":
|
|
408
|
+
readDocumentParamsSchema.parse(validAction.parameters);
|
|
409
|
+
break;
|
|
410
|
+
case "writeDocument":
|
|
411
|
+
writeDocumentParamsSchema.parse(validAction.parameters);
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
return { valid: true, errors: [] };
|
|
415
|
+
} catch (error) {
|
|
416
|
+
if (error instanceof import_zod2.ZodError) return { valid: false, errors: zodToValidationErrors(error) };
|
|
417
|
+
return { valid: false, errors: [{ path: "", message: "Unknown validation error" }] };
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function validateEditorAction(action) {
|
|
421
|
+
try {
|
|
422
|
+
const validAction = editorActionSchema.parse(action);
|
|
423
|
+
switch (validAction.variant) {
|
|
424
|
+
case "translate":
|
|
425
|
+
translateParamsSchema.parse(validAction.parameters);
|
|
426
|
+
break;
|
|
427
|
+
case "directive":
|
|
428
|
+
directiveParamsSchema.parse(validAction.parameters);
|
|
429
|
+
break;
|
|
430
|
+
default:
|
|
431
|
+
editorActionBaseParamsSchema.parse(validAction.parameters);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
return { valid: true, errors: [] };
|
|
435
|
+
} catch (error) {
|
|
436
|
+
if (error instanceof import_zod2.ZodError) return { valid: false, errors: zodToValidationErrors(error) };
|
|
437
|
+
return { valid: false, errors: [{ path: "", message: "Unknown validation error" }] };
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function isValidDAFDocument(doc) {
|
|
441
|
+
return validateDAFDocument(doc).valid;
|
|
442
|
+
}
|
|
443
|
+
function isValidProcess(process) {
|
|
444
|
+
return validateProcess(process).valid;
|
|
445
|
+
}
|
|
446
|
+
function isValidStep(step) {
|
|
447
|
+
return validateStep(step).valid;
|
|
448
|
+
}
|
|
449
|
+
function isValidResource(resource) {
|
|
450
|
+
return validateResource(resource).valid;
|
|
451
|
+
}
|
|
452
|
+
function isValidAction(action) {
|
|
453
|
+
return validateAction(action).valid;
|
|
454
|
+
}
|
|
455
|
+
function isValidEditorAction(action) {
|
|
456
|
+
return validateEditorAction(action).valid;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/protocol/builders.ts
|
|
460
|
+
var DAFDocumentBuilder = class {
|
|
461
|
+
constructor() {
|
|
462
|
+
this.doc = { dafVersion: DAF_VERSION, processes: [] };
|
|
463
|
+
}
|
|
464
|
+
variables(vars) {
|
|
465
|
+
this.doc.variables = vars;
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
variable(name, value) {
|
|
469
|
+
if (!this.doc.variables) this.doc.variables = {};
|
|
470
|
+
this.doc.variables[name] = value;
|
|
471
|
+
return this;
|
|
472
|
+
}
|
|
473
|
+
resources(resources) {
|
|
474
|
+
this.doc.resources = resources;
|
|
475
|
+
return this;
|
|
476
|
+
}
|
|
477
|
+
resource(resource) {
|
|
478
|
+
if (!this.doc.resources) this.doc.resources = [];
|
|
479
|
+
this.doc.resources.push(resource);
|
|
480
|
+
return this;
|
|
481
|
+
}
|
|
482
|
+
process(process) {
|
|
483
|
+
this.doc.processes.push(process);
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
486
|
+
build() {
|
|
487
|
+
return this.doc;
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
var ProcessBuilder = class {
|
|
491
|
+
constructor(name, processType = "STATIC_DIALOGUE") {
|
|
492
|
+
this.process = { name, processType, steps: [] };
|
|
493
|
+
}
|
|
494
|
+
description(desc) {
|
|
495
|
+
this.process.description = desc;
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
stopKeyword(keyword) {
|
|
499
|
+
this.process.stopProcessKeyword = keyword;
|
|
500
|
+
return this;
|
|
501
|
+
}
|
|
502
|
+
resources(resources) {
|
|
503
|
+
this.process.resources = resources;
|
|
504
|
+
return this;
|
|
505
|
+
}
|
|
506
|
+
resource(resource) {
|
|
507
|
+
if (!this.process.resources) this.process.resources = [];
|
|
508
|
+
this.process.resources.push(resource);
|
|
509
|
+
return this;
|
|
510
|
+
}
|
|
511
|
+
step(step) {
|
|
512
|
+
this.process.steps.push(step);
|
|
513
|
+
return this;
|
|
514
|
+
}
|
|
515
|
+
build() {
|
|
516
|
+
return this.process;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
function promptStep(prompt) {
|
|
520
|
+
return { type: "prompt", prompt };
|
|
521
|
+
}
|
|
522
|
+
function processStep(processId) {
|
|
523
|
+
return { type: "process", processId };
|
|
524
|
+
}
|
|
525
|
+
function fixedLoopStep(prompt, count) {
|
|
526
|
+
return { type: "prompt", prompt, loopType: "fixed", forLoopCount: count };
|
|
527
|
+
}
|
|
528
|
+
function conditionalLoopStep(prompt, stopKeyword, maxLoops) {
|
|
529
|
+
return { type: "prompt", prompt, loopType: "stopOn", stopOnKeyword: stopKeyword, stopOnMaxLoops: maxLoops };
|
|
530
|
+
}
|
|
531
|
+
function skipCompletionStep(prompt) {
|
|
532
|
+
return { type: "prompt", prompt, skipCompletion: true };
|
|
533
|
+
}
|
|
534
|
+
function userFeedbackStep() {
|
|
535
|
+
return { type: "userFeedback" };
|
|
536
|
+
}
|
|
537
|
+
function completionWithoutPromptStep() {
|
|
538
|
+
return { type: "completionWithoutPrompt" };
|
|
539
|
+
}
|
|
540
|
+
function googleDocResource(name, url, isGlobal = false) {
|
|
541
|
+
return { name, type: "google_doc", url, isGlobal };
|
|
542
|
+
}
|
|
543
|
+
function notionPageResource(name, url, isGlobal = false) {
|
|
544
|
+
return { name, type: "notion_page", url, isGlobal };
|
|
545
|
+
}
|
|
546
|
+
function googleDriveFolderResource(name, url, isGlobal = false) {
|
|
547
|
+
return { name, type: "google_drive_folder", url, isGlobal };
|
|
548
|
+
}
|
|
549
|
+
function sendEmailAction(to, subject, content) {
|
|
550
|
+
return { type: "action", variant: "sendEmail", parameters: { to, subject, content } };
|
|
551
|
+
}
|
|
552
|
+
function scrapeAction(url, timeout) {
|
|
553
|
+
return { type: "action", variant: "scrape", parameters: { url, timeout } };
|
|
554
|
+
}
|
|
555
|
+
function searchAction(query, limit) {
|
|
556
|
+
return { type: "action", variant: "search", parameters: { query, limit } };
|
|
557
|
+
}
|
|
558
|
+
function readDocumentAction(resourceName) {
|
|
559
|
+
return { type: "action", variant: "readDocument", parameters: { resourceName } };
|
|
560
|
+
}
|
|
561
|
+
function writeDocumentAction(resourceName, operation, content, options) {
|
|
562
|
+
return { type: "action", variant: "writeDocument", parameters: { resourceName, operation, content, ...options } };
|
|
563
|
+
}
|
|
564
|
+
function formatDocumentAction(resourceUrl, formatting, range) {
|
|
565
|
+
return { type: "action", variant: "formatDocument", parameters: { resourceUrl, formatting, range } };
|
|
566
|
+
}
|
|
567
|
+
function removeDocumentAction(resourceUrl) {
|
|
568
|
+
return { type: "action", variant: "removeDocument", parameters: { resourceUrl } };
|
|
569
|
+
}
|
|
570
|
+
function renameDocumentAction(resourceUrl, newName) {
|
|
571
|
+
return { type: "action", variant: "renameDocument", parameters: { resourceUrl, newName } };
|
|
572
|
+
}
|
|
573
|
+
function duplicateDocumentAction(resourceUrl, newName) {
|
|
574
|
+
return { type: "action", variant: "duplicateDocument", parameters: { resourceUrl, newName } };
|
|
575
|
+
}
|
|
576
|
+
function addFolderAction(folderName, provider, parentUrl) {
|
|
577
|
+
return { type: "action", variant: "addFolder", parameters: { folderName, provider, parentUrl } };
|
|
578
|
+
}
|
|
579
|
+
function removeFolderAction(folderUrl) {
|
|
580
|
+
return { type: "action", variant: "removeFolder", parameters: { folderUrl } };
|
|
581
|
+
}
|
|
582
|
+
function readFolderAction(folderUrl) {
|
|
583
|
+
return { type: "action", variant: "readFolder", parameters: { folderUrl } };
|
|
584
|
+
}
|
|
585
|
+
function renameFolderAction(folderUrl, newName) {
|
|
586
|
+
return { type: "action", variant: "renameFolder", parameters: { folderUrl, newName } };
|
|
587
|
+
}
|
|
588
|
+
function addDocumentAction(documentName, provider, locationUrl, content) {
|
|
589
|
+
return { type: "action", variant: "addDocument", parameters: { documentName, provider, locationUrl, content } };
|
|
590
|
+
}
|
|
591
|
+
function createDatabaseAction(databaseName, parentPageUrl) {
|
|
592
|
+
return { type: "action", variant: "createDatabase", parameters: { databaseName, parentPageUrl } };
|
|
593
|
+
}
|
|
594
|
+
function readDatabaseAction(databaseUrl) {
|
|
595
|
+
return { type: "action", variant: "readDatabase", parameters: { databaseUrl } };
|
|
596
|
+
}
|
|
597
|
+
function updateDatabaseAction(databaseUrl, options) {
|
|
598
|
+
return { type: "action", variant: "updateDatabase", parameters: { databaseUrl, ...options } };
|
|
599
|
+
}
|
|
600
|
+
function deleteDatabaseAction(databaseUrl) {
|
|
601
|
+
return { type: "action", variant: "deleteDatabase", parameters: { databaseUrl } };
|
|
602
|
+
}
|
|
603
|
+
function writeDatabaseAction(databaseUrl, properties, content) {
|
|
604
|
+
return { type: "action", variant: "writeDatabase", parameters: { databaseUrl, properties, content } };
|
|
605
|
+
}
|
|
606
|
+
function duplicateDatabaseAction(databaseUrl, newDatabaseName) {
|
|
607
|
+
return { type: "action", variant: "duplicateDatabase", parameters: { databaseUrl, newDatabaseName } };
|
|
608
|
+
}
|
|
609
|
+
function newsSearchAction(query, options) {
|
|
610
|
+
return { type: "action", variant: "newsSearch", parameters: { query, ...options } };
|
|
611
|
+
}
|
|
612
|
+
function previewSearchAction(query, options) {
|
|
613
|
+
return { type: "action", variant: "previewSearch", parameters: { query, ...options } };
|
|
614
|
+
}
|
|
615
|
+
function tavilySearchAction(query, options) {
|
|
616
|
+
return { type: "action", variant: "tavilySearch", parameters: { query, ...options } };
|
|
617
|
+
}
|
|
618
|
+
function editorAction(variant, params) {
|
|
619
|
+
return { type: "editorAction", variant, parameters: params };
|
|
620
|
+
}
|
|
621
|
+
function fixSpellingGrammarAction(selectedText, options) {
|
|
622
|
+
return editorAction("fixSpellingGrammar", { selectedText, ...options });
|
|
623
|
+
}
|
|
624
|
+
function rewriteAction(selectedText, options) {
|
|
625
|
+
return editorAction("rewrite", { selectedText, ...options });
|
|
626
|
+
}
|
|
627
|
+
function extendTextAction(selectedText, options) {
|
|
628
|
+
return editorAction("extendText", { selectedText, ...options });
|
|
629
|
+
}
|
|
630
|
+
function reduceTextAction(selectedText, options) {
|
|
631
|
+
return editorAction("reduceText", { selectedText, ...options });
|
|
632
|
+
}
|
|
633
|
+
function simplifyAction(selectedText, options) {
|
|
634
|
+
return editorAction("simplify", { selectedText, ...options });
|
|
635
|
+
}
|
|
636
|
+
function completeSentenceAction(selectedText, options) {
|
|
637
|
+
return editorAction("completeSentence", { selectedText, ...options });
|
|
638
|
+
}
|
|
639
|
+
function translateAction(selectedText, language, options) {
|
|
640
|
+
return editorAction("translate", { selectedText, language, ...options });
|
|
641
|
+
}
|
|
642
|
+
function formatTextAction(selectedText, options) {
|
|
643
|
+
return editorAction("formatText", { selectedText, ...options });
|
|
644
|
+
}
|
|
645
|
+
function directiveAction(selectedText, directive, options) {
|
|
646
|
+
return editorAction("directive", { selectedText, directive, ...options });
|
|
647
|
+
}
|
|
648
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
649
|
+
0 && (module.exports = {
|
|
650
|
+
ACTION_TYPES,
|
|
651
|
+
DAFDocumentBuilder,
|
|
652
|
+
DAF_VERSION,
|
|
653
|
+
DEFAULT_SCRAPE_TIMEOUT,
|
|
654
|
+
DEFAULT_SEARCH_LIMIT,
|
|
655
|
+
EDITOR_ACTION_TYPES,
|
|
656
|
+
LOOP_TYPES,
|
|
657
|
+
MAX_PROCESS_DEPTH,
|
|
658
|
+
PROCESS_TYPES,
|
|
659
|
+
ProcessBuilder,
|
|
660
|
+
RESOURCE_TYPES,
|
|
661
|
+
STEP_TYPES,
|
|
662
|
+
SUPPORTED_VERSIONS,
|
|
663
|
+
WRITE_OPERATIONS,
|
|
664
|
+
actionSchema,
|
|
665
|
+
addDocumentAction,
|
|
666
|
+
addFolderAction,
|
|
667
|
+
completeSentenceAction,
|
|
668
|
+
completionWithoutPromptStep,
|
|
669
|
+
conditionalLoopStep,
|
|
670
|
+
createDatabaseAction,
|
|
671
|
+
dafDocumentSchema,
|
|
672
|
+
deleteDatabaseAction,
|
|
673
|
+
directiveAction,
|
|
674
|
+
directiveParamsSchema,
|
|
675
|
+
duplicateDatabaseAction,
|
|
676
|
+
duplicateDocumentAction,
|
|
677
|
+
editorActionBaseParamsSchema,
|
|
678
|
+
editorActionSchema,
|
|
679
|
+
extendTextAction,
|
|
680
|
+
fixSpellingGrammarAction,
|
|
681
|
+
fixedLoopStep,
|
|
682
|
+
formatDocumentAction,
|
|
683
|
+
formatTextAction,
|
|
684
|
+
googleDocResource,
|
|
685
|
+
googleDriveFolderResource,
|
|
686
|
+
isValidAction,
|
|
687
|
+
isValidDAFDocument,
|
|
688
|
+
isValidEditorAction,
|
|
689
|
+
isValidProcess,
|
|
690
|
+
isValidResource,
|
|
691
|
+
isValidStep,
|
|
692
|
+
newsSearchAction,
|
|
693
|
+
newsSearchParamsSchema,
|
|
694
|
+
notionPageResource,
|
|
695
|
+
previewSearchAction,
|
|
696
|
+
previewSearchParamsSchema,
|
|
697
|
+
processSchema,
|
|
698
|
+
processStep,
|
|
699
|
+
promptStep,
|
|
700
|
+
readDatabaseAction,
|
|
701
|
+
readDocumentAction,
|
|
702
|
+
readDocumentParamsSchema,
|
|
703
|
+
readFolderAction,
|
|
704
|
+
reduceTextAction,
|
|
705
|
+
removeDocumentAction,
|
|
706
|
+
removeFolderAction,
|
|
707
|
+
renameDocumentAction,
|
|
708
|
+
renameFolderAction,
|
|
709
|
+
resourceSchema,
|
|
710
|
+
rewriteAction,
|
|
711
|
+
scrapeAction,
|
|
712
|
+
scrapeParamsSchema,
|
|
713
|
+
searchAction,
|
|
714
|
+
searchParamsSchema,
|
|
715
|
+
sendEmailAction,
|
|
716
|
+
sendEmailParamsSchema,
|
|
717
|
+
simplifyAction,
|
|
718
|
+
skipCompletionStep,
|
|
719
|
+
stepSchema,
|
|
720
|
+
tavilySearchAction,
|
|
721
|
+
tavilySearchParamsSchema,
|
|
722
|
+
translateAction,
|
|
723
|
+
translateParamsSchema,
|
|
724
|
+
updateDatabaseAction,
|
|
725
|
+
userFeedbackStep,
|
|
726
|
+
validateAction,
|
|
727
|
+
validateDAFDocument,
|
|
728
|
+
validateEditorAction,
|
|
729
|
+
validateProcess,
|
|
730
|
+
validateResource,
|
|
731
|
+
validateStep,
|
|
732
|
+
writeDatabaseAction,
|
|
733
|
+
writeDocumentAction,
|
|
734
|
+
writeDocumentParamsSchema
|
|
735
|
+
});
|