@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.js CHANGED
@@ -76,6 +76,7 @@ const INPUT_BLOCK_TYPES = new Set([
76
76
  "input-file"
77
77
  ]);
78
78
  const executableBlockTypes = new Set([
79
+ "agent",
79
80
  "code",
80
81
  "sql",
81
82
  "notebook-function",
@@ -299,6 +300,15 @@ const buttonBlockSchema = z.object({
299
300
  deepnote_variable_name: z.string().optional()
300
301
  }).default({})
301
302
  });
303
+ const agentBlockSchema = z.object({
304
+ ...executableBlockFields,
305
+ type: z.literal("agent"),
306
+ content: z.string().optional(),
307
+ metadata: executableBlockMetadataSchema.extend({
308
+ deepnote_variable_name: z.string().optional(),
309
+ deepnote_agent_model: z.string().optional()
310
+ }).default({})
311
+ });
302
312
  const bigNumberBlockSchema = z.object({
303
313
  ...executableBlockFields,
304
314
  type: z.literal("big-number"),
@@ -409,6 +419,7 @@ const deepnoteBlockSchema = z.discriminatedUnion("type", [
409
419
  textCellBulletBlockSchema,
410
420
  textCellTodoBlockSchema,
411
421
  textCellCalloutBlockSchema,
422
+ agentBlockSchema,
412
423
  codeBlockSchema,
413
424
  sqlBlockSchema,
414
425
  notebookFunctionBlockSchema,
@@ -629,17 +640,37 @@ const yamlOptions = {
629
640
  defaultStringType: "PLAIN",
630
641
  defaultKeyType: "PLAIN"
631
642
  };
643
+ function generateSortingKey(index) {
644
+ return String(index).padStart(6, "0");
645
+ }
646
+ function normalizeSortingKeys(data) {
647
+ return {
648
+ ...data,
649
+ project: {
650
+ ...data.project,
651
+ notebooks: data.project.notebooks.map((notebook) => ({
652
+ ...notebook,
653
+ blocks: notebook.blocks.map((block, index) => ({
654
+ ...block,
655
+ sortingKey: generateSortingKey(index)
656
+ }))
657
+ }))
658
+ }
659
+ };
660
+ }
632
661
  /**
633
662
  * Serialize a DeepnoteFile to a YAML string.
634
663
  */
635
664
  function serializeDeepnoteFile(file) {
636
- return stringify(deepnoteFileSchema.parse(file), yamlOptions);
665
+ const withNormalizedSortingKeys = normalizeSortingKeys(file);
666
+ return stringify(deepnoteFileSchema.parse(withNormalizedSortingKeys), yamlOptions);
637
667
  }
638
668
  /**
639
669
  * Serialize a DeepnoteSnapshot to a YAML string.
640
670
  */
641
671
  function serializeDeepnoteSnapshot(snapshot) {
642
- return stringify(deepnoteSnapshotSchema.parse(snapshot), yamlOptions);
672
+ const withNormalizedSortingKeys = normalizeSortingKeys(snapshot);
673
+ return stringify(deepnoteSnapshotSchema.parse(withNormalizedSortingKeys), yamlOptions);
643
674
  }
644
675
 
645
676
  //#endregion
@@ -723,6 +754,17 @@ function stripMarkdown(block) {
723
754
  throw new UnsupportedBlockTypeError(`Stripping markdown from block type ${block.type} is not supported yet.`);
724
755
  }
725
756
 
757
+ //#endregion
758
+ //#region src/blocks/agent-blocks.ts
759
+ function createPythonCodeForAgentBlock(block) {
760
+ const prompt = block.content ?? "";
761
+ if (!prompt.trim()) return "# [agent block] (empty system prompt)";
762
+ return `# [agent block] System prompt:\n${prompt.split("\n").map((line) => `# ${line}`).join("\n")}`;
763
+ }
764
+ function isAgentBlock(block) {
765
+ return block.type === "agent";
766
+ }
767
+
726
768
  //#endregion
727
769
  //#region src/blocks/python-utils.ts
728
770
  function escapePythonString(value) {
@@ -1142,6 +1184,7 @@ function isVisualizationBlock(block) {
1142
1184
  //#endregion
1143
1185
  //#region src/python-code.ts
1144
1186
  function createPythonCode(block, executionContext) {
1187
+ if (isAgentBlock(block)) return createPythonCodeForAgentBlock(block);
1145
1188
  if (isCodeBlock(block)) return createPythonCodeForCodeBlock(block);
1146
1189
  if (isSqlBlock(block)) return createPythonCodeForSqlBlock(block);
1147
1190
  if (isInputTextBlock(block)) return createPythonCodeForInputTextBlock(block);
@@ -1160,4 +1203,4 @@ function createPythonCode(block, executionContext) {
1160
1203
  }
1161
1204
 
1162
1205
  //#endregion
1163
- export { DeepnoteError, EncodingError, INPUT_BLOCK_TYPES, InvalidValueError, ParseError, ProhibitedYamlFeatureError, SchemaValidationError, UnsupportedBlockTypeError, YamlParseError, convertToEnvironmentVariableName, createMarkdown, createPythonCode, decodeUtf8NoBom, deepnoteBlockSchema, deepnoteFileSchema, deepnoteSnapshotSchema, deserializeDeepnoteFile, environmentSchema, executionErrorSchema, executionSchema, executionSummarySchema, getSqlEnvVarName, isExecutableBlock, isExecutableBlockType, parseYaml, serializeDeepnoteFile, serializeDeepnoteSnapshot, stripMarkdown };
1206
+ export { DeepnoteError, EncodingError, INPUT_BLOCK_TYPES, InvalidValueError, ParseError, ProhibitedYamlFeatureError, SchemaValidationError, UnsupportedBlockTypeError, YamlParseError, convertToEnvironmentVariableName, createMarkdown, createPythonCode, decodeUtf8NoBom, deepnoteBlockSchema, deepnoteFileSchema, deepnoteSnapshotSchema, deserializeDeepnoteFile, environmentSchema, executionErrorSchema, executionSchema, executionSummarySchema, generateSortingKey, getSqlEnvVarName, isExecutableBlock, isExecutableBlockType, parseYaml, serializeDeepnoteFile, serializeDeepnoteSnapshot, stripMarkdown };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepnote/blocks",
3
- "version": "4.2.0",
3
+ "version": "4.4.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {