@deepnote/blocks 4.2.0 → 4.4.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/index.cjs +46 -2
- package/dist/index.d.cts +1193 -46
- package/dist/index.d.ts +1193 -46
- package/dist/index.js +46 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -102,6 +102,7 @@ const INPUT_BLOCK_TYPES = new Set([
|
|
|
102
102
|
"input-file"
|
|
103
103
|
]);
|
|
104
104
|
const executableBlockTypes = new Set([
|
|
105
|
+
"agent",
|
|
105
106
|
"code",
|
|
106
107
|
"sql",
|
|
107
108
|
"notebook-function",
|
|
@@ -325,6 +326,15 @@ const buttonBlockSchema = zod.z.object({
|
|
|
325
326
|
deepnote_variable_name: zod.z.string().optional()
|
|
326
327
|
}).default({})
|
|
327
328
|
});
|
|
329
|
+
const agentBlockSchema = zod.z.object({
|
|
330
|
+
...executableBlockFields,
|
|
331
|
+
type: zod.z.literal("agent"),
|
|
332
|
+
content: zod.z.string().optional(),
|
|
333
|
+
metadata: executableBlockMetadataSchema.extend({
|
|
334
|
+
deepnote_variable_name: zod.z.string().optional(),
|
|
335
|
+
deepnote_agent_model: zod.z.string().optional()
|
|
336
|
+
}).default({})
|
|
337
|
+
});
|
|
328
338
|
const bigNumberBlockSchema = zod.z.object({
|
|
329
339
|
...executableBlockFields,
|
|
330
340
|
type: zod.z.literal("big-number"),
|
|
@@ -435,6 +445,7 @@ const deepnoteBlockSchema = zod.z.discriminatedUnion("type", [
|
|
|
435
445
|
textCellBulletBlockSchema,
|
|
436
446
|
textCellTodoBlockSchema,
|
|
437
447
|
textCellCalloutBlockSchema,
|
|
448
|
+
agentBlockSchema,
|
|
438
449
|
codeBlockSchema,
|
|
439
450
|
sqlBlockSchema,
|
|
440
451
|
notebookFunctionBlockSchema,
|
|
@@ -655,17 +666,37 @@ const yamlOptions = {
|
|
|
655
666
|
defaultStringType: "PLAIN",
|
|
656
667
|
defaultKeyType: "PLAIN"
|
|
657
668
|
};
|
|
669
|
+
function generateSortingKey(index) {
|
|
670
|
+
return String(index).padStart(6, "0");
|
|
671
|
+
}
|
|
672
|
+
function normalizeSortingKeys(data) {
|
|
673
|
+
return {
|
|
674
|
+
...data,
|
|
675
|
+
project: {
|
|
676
|
+
...data.project,
|
|
677
|
+
notebooks: data.project.notebooks.map((notebook) => ({
|
|
678
|
+
...notebook,
|
|
679
|
+
blocks: notebook.blocks.map((block, index) => ({
|
|
680
|
+
...block,
|
|
681
|
+
sortingKey: generateSortingKey(index)
|
|
682
|
+
}))
|
|
683
|
+
}))
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
}
|
|
658
687
|
/**
|
|
659
688
|
* Serialize a DeepnoteFile to a YAML string.
|
|
660
689
|
*/
|
|
661
690
|
function serializeDeepnoteFile(file) {
|
|
662
|
-
|
|
691
|
+
const withNormalizedSortingKeys = normalizeSortingKeys(file);
|
|
692
|
+
return (0, yaml.stringify)(deepnoteFileSchema.parse(withNormalizedSortingKeys), yamlOptions);
|
|
663
693
|
}
|
|
664
694
|
/**
|
|
665
695
|
* Serialize a DeepnoteSnapshot to a YAML string.
|
|
666
696
|
*/
|
|
667
697
|
function serializeDeepnoteSnapshot(snapshot) {
|
|
668
|
-
|
|
698
|
+
const withNormalizedSortingKeys = normalizeSortingKeys(snapshot);
|
|
699
|
+
return (0, yaml.stringify)(deepnoteSnapshotSchema.parse(withNormalizedSortingKeys), yamlOptions);
|
|
669
700
|
}
|
|
670
701
|
|
|
671
702
|
//#endregion
|
|
@@ -749,6 +780,17 @@ function stripMarkdown(block) {
|
|
|
749
780
|
throw new UnsupportedBlockTypeError(`Stripping markdown from block type ${block.type} is not supported yet.`);
|
|
750
781
|
}
|
|
751
782
|
|
|
783
|
+
//#endregion
|
|
784
|
+
//#region src/blocks/agent-blocks.ts
|
|
785
|
+
function createPythonCodeForAgentBlock(block) {
|
|
786
|
+
const prompt = block.content ?? "";
|
|
787
|
+
if (!prompt.trim()) return "# [agent block] (empty system prompt)";
|
|
788
|
+
return `# [agent block] System prompt:\n${prompt.split("\n").map((line) => `# ${line}`).join("\n")}`;
|
|
789
|
+
}
|
|
790
|
+
function isAgentBlock(block) {
|
|
791
|
+
return block.type === "agent";
|
|
792
|
+
}
|
|
793
|
+
|
|
752
794
|
//#endregion
|
|
753
795
|
//#region src/blocks/python-utils.ts
|
|
754
796
|
function escapePythonString(value) {
|
|
@@ -1168,6 +1210,7 @@ function isVisualizationBlock(block) {
|
|
|
1168
1210
|
//#endregion
|
|
1169
1211
|
//#region src/python-code.ts
|
|
1170
1212
|
function createPythonCode(block, executionContext) {
|
|
1213
|
+
if (isAgentBlock(block)) return createPythonCodeForAgentBlock(block);
|
|
1171
1214
|
if (isCodeBlock(block)) return createPythonCodeForCodeBlock(block);
|
|
1172
1215
|
if (isSqlBlock(block)) return createPythonCodeForSqlBlock(block);
|
|
1173
1216
|
if (isInputTextBlock(block)) return createPythonCodeForInputTextBlock(block);
|
|
@@ -1207,6 +1250,7 @@ exports.environmentSchema = environmentSchema;
|
|
|
1207
1250
|
exports.executionErrorSchema = executionErrorSchema;
|
|
1208
1251
|
exports.executionSchema = executionSchema;
|
|
1209
1252
|
exports.executionSummarySchema = executionSummarySchema;
|
|
1253
|
+
exports.generateSortingKey = generateSortingKey;
|
|
1210
1254
|
exports.getSqlEnvVarName = getSqlEnvVarName;
|
|
1211
1255
|
exports.isExecutableBlock = isExecutableBlock;
|
|
1212
1256
|
exports.isExecutableBlockType = isExecutableBlockType;
|