@deepnote/blocks 4.3.0 → 4.5.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 +73 -0
- package/dist/index.d.cts +1742 -76
- package/dist/index.d.ts +1742 -76
- package/dist/index.js +70 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -85,6 +85,17 @@ var InvalidValueError = class extends DeepnoteError {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/blocks/agent-blocks.ts
|
|
90
|
+
function createPythonCodeForAgentBlock(block) {
|
|
91
|
+
const prompt = block.content ?? "";
|
|
92
|
+
if (!prompt.trim()) return "# [agent block] (empty system prompt)";
|
|
93
|
+
return `# [agent block] System prompt:\n${prompt.split("\n").map((line) => `# ${line}`).join("\n")}`;
|
|
94
|
+
}
|
|
95
|
+
function isAgentBlock(block) {
|
|
96
|
+
return block.type === "agent";
|
|
97
|
+
}
|
|
98
|
+
|
|
88
99
|
//#endregion
|
|
89
100
|
//#region src/blocks/executable-blocks.ts
|
|
90
101
|
/**
|
|
@@ -102,6 +113,7 @@ const INPUT_BLOCK_TYPES = new Set([
|
|
|
102
113
|
"input-file"
|
|
103
114
|
]);
|
|
104
115
|
const executableBlockTypes = new Set([
|
|
116
|
+
"agent",
|
|
105
117
|
"code",
|
|
106
118
|
"sql",
|
|
107
119
|
"notebook-function",
|
|
@@ -340,6 +352,21 @@ const bigNumberBlockSchema = zod.z.object({
|
|
|
340
352
|
deepnote_big_number_comparison_format: zod.z.string().optional()
|
|
341
353
|
}).default({})
|
|
342
354
|
});
|
|
355
|
+
const mcpServerSchema = zod.z.object({
|
|
356
|
+
name: zod.z.string(),
|
|
357
|
+
command: zod.z.string(),
|
|
358
|
+
args: zod.z.array(zod.z.string()).optional(),
|
|
359
|
+
env: zod.z.record(zod.z.string()).optional()
|
|
360
|
+
});
|
|
361
|
+
const agentBlockSchema = zod.z.object({
|
|
362
|
+
...executableBlockFields,
|
|
363
|
+
type: zod.z.literal("agent"),
|
|
364
|
+
content: zod.z.string().optional(),
|
|
365
|
+
metadata: executableBlockMetadataSchema.extend({
|
|
366
|
+
deepnote_agent_model: zod.z.string().default("auto"),
|
|
367
|
+
deepnote_mcp_servers: zod.z.array(mcpServerSchema).optional()
|
|
368
|
+
}).default({})
|
|
369
|
+
});
|
|
343
370
|
const inputTextBlockSchema = zod.z.object({
|
|
344
371
|
...executableBlockFields,
|
|
345
372
|
type: zod.z.literal("input-text"),
|
|
@@ -435,6 +462,7 @@ const deepnoteBlockSchema = zod.z.discriminatedUnion("type", [
|
|
|
435
462
|
textCellBulletBlockSchema,
|
|
436
463
|
textCellTodoBlockSchema,
|
|
437
464
|
textCellCalloutBlockSchema,
|
|
465
|
+
agentBlockSchema,
|
|
438
466
|
codeBlockSchema,
|
|
439
467
|
sqlBlockSchema,
|
|
440
468
|
notebookFunctionBlockSchema,
|
|
@@ -521,6 +549,7 @@ const deepnoteFileSchema = zod.z.object({
|
|
|
521
549
|
customImage: zod.z.string().optional(),
|
|
522
550
|
pythonVersion: zod.z.string().optional()
|
|
523
551
|
}).optional(),
|
|
552
|
+
mcpServers: zod.z.array(mcpServerSchema).optional(),
|
|
524
553
|
requirements: zod.z.array(zod.z.string()).optional(),
|
|
525
554
|
sqlCacheMaxAge: zod.z.number().optional()
|
|
526
555
|
}).optional()
|
|
@@ -769,6 +798,45 @@ function stripMarkdown(block) {
|
|
|
769
798
|
throw new UnsupportedBlockTypeError(`Stripping markdown from block type ${block.type} is not supported yet.`);
|
|
770
799
|
}
|
|
771
800
|
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region src/output-text.ts
|
|
803
|
+
const unknownObjectSchema = zod.z.object({}).passthrough();
|
|
804
|
+
/**
|
|
805
|
+
* Extract a human-readable text string from a single Jupyter-style output object.
|
|
806
|
+
* Returns null if the output type is unrecognized or has no textual representation.
|
|
807
|
+
*/
|
|
808
|
+
function extractOutputText(output, options) {
|
|
809
|
+
const outResult = unknownObjectSchema.safeParse(output);
|
|
810
|
+
if (!outResult.success) return null;
|
|
811
|
+
const out = outResult.data;
|
|
812
|
+
if (out.output_type === "stream" && typeof out.text === "string") return out.text;
|
|
813
|
+
if (out.output_type === "execute_result" || out.output_type === "display_data") {
|
|
814
|
+
const dataResult = unknownObjectSchema.safeParse(out.data);
|
|
815
|
+
const data = dataResult.success ? dataResult.data : void 0;
|
|
816
|
+
if (data?.["text/plain"]) return String(data["text/plain"]);
|
|
817
|
+
if (data?.["text/html"]) return "[HTML output]";
|
|
818
|
+
if (data?.["image/png"] || data?.["image/jpeg"]) return "[Image output]";
|
|
819
|
+
}
|
|
820
|
+
if (out.output_type === "error") {
|
|
821
|
+
let text = `Error: ${String(out.ename || "Error")}: ${String(out.evalue || "")}`;
|
|
822
|
+
if (options?.includeTraceback && Array.isArray(out.traceback)) text += "\n" + out.traceback.map((line) => line.replace(/\x1b\[[0-9;]*m/g, "")).join("\n");
|
|
823
|
+
return text;
|
|
824
|
+
}
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Extract human-readable text from an array of Jupyter-style output objects.
|
|
829
|
+
* Joins non-null results with newlines.
|
|
830
|
+
*/
|
|
831
|
+
function extractOutputsText(outputs, options) {
|
|
832
|
+
const texts = [];
|
|
833
|
+
for (const output of outputs) {
|
|
834
|
+
const text = extractOutputText(output, options);
|
|
835
|
+
if (text != null) texts.push(text);
|
|
836
|
+
}
|
|
837
|
+
return texts.join("\n");
|
|
838
|
+
}
|
|
839
|
+
|
|
772
840
|
//#endregion
|
|
773
841
|
//#region src/blocks/python-utils.ts
|
|
774
842
|
function escapePythonString(value) {
|
|
@@ -1188,6 +1256,7 @@ function isVisualizationBlock(block) {
|
|
|
1188
1256
|
//#endregion
|
|
1189
1257
|
//#region src/python-code.ts
|
|
1190
1258
|
function createPythonCode(block, executionContext) {
|
|
1259
|
+
if (isAgentBlock(block)) return createPythonCodeForAgentBlock(block);
|
|
1191
1260
|
if (isCodeBlock(block)) return createPythonCodeForCodeBlock(block);
|
|
1192
1261
|
if (isSqlBlock(block)) return createPythonCodeForSqlBlock(block);
|
|
1193
1262
|
if (isInputTextBlock(block)) return createPythonCodeForInputTextBlock(block);
|
|
@@ -1227,10 +1296,14 @@ exports.environmentSchema = environmentSchema;
|
|
|
1227
1296
|
exports.executionErrorSchema = executionErrorSchema;
|
|
1228
1297
|
exports.executionSchema = executionSchema;
|
|
1229
1298
|
exports.executionSummarySchema = executionSummarySchema;
|
|
1299
|
+
exports.extractOutputText = extractOutputText;
|
|
1300
|
+
exports.extractOutputsText = extractOutputsText;
|
|
1230
1301
|
exports.generateSortingKey = generateSortingKey;
|
|
1231
1302
|
exports.getSqlEnvVarName = getSqlEnvVarName;
|
|
1303
|
+
exports.isAgentBlock = isAgentBlock;
|
|
1232
1304
|
exports.isExecutableBlock = isExecutableBlock;
|
|
1233
1305
|
exports.isExecutableBlockType = isExecutableBlockType;
|
|
1306
|
+
exports.mcpServerSchema = mcpServerSchema;
|
|
1234
1307
|
exports.parseYaml = parseYaml;
|
|
1235
1308
|
exports.serializeDeepnoteFile = serializeDeepnoteFile;
|
|
1236
1309
|
exports.serializeDeepnoteSnapshot = serializeDeepnoteSnapshot;
|