@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.js
CHANGED
|
@@ -59,6 +59,17 @@ var InvalidValueError = class extends DeepnoteError {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/blocks/agent-blocks.ts
|
|
64
|
+
function createPythonCodeForAgentBlock(block) {
|
|
65
|
+
const prompt = block.content ?? "";
|
|
66
|
+
if (!prompt.trim()) return "# [agent block] (empty system prompt)";
|
|
67
|
+
return `# [agent block] System prompt:\n${prompt.split("\n").map((line) => `# ${line}`).join("\n")}`;
|
|
68
|
+
}
|
|
69
|
+
function isAgentBlock(block) {
|
|
70
|
+
return block.type === "agent";
|
|
71
|
+
}
|
|
72
|
+
|
|
62
73
|
//#endregion
|
|
63
74
|
//#region src/blocks/executable-blocks.ts
|
|
64
75
|
/**
|
|
@@ -76,6 +87,7 @@ const INPUT_BLOCK_TYPES = new Set([
|
|
|
76
87
|
"input-file"
|
|
77
88
|
]);
|
|
78
89
|
const executableBlockTypes = new Set([
|
|
90
|
+
"agent",
|
|
79
91
|
"code",
|
|
80
92
|
"sql",
|
|
81
93
|
"notebook-function",
|
|
@@ -314,6 +326,21 @@ const bigNumberBlockSchema = z.object({
|
|
|
314
326
|
deepnote_big_number_comparison_format: z.string().optional()
|
|
315
327
|
}).default({})
|
|
316
328
|
});
|
|
329
|
+
const mcpServerSchema = z.object({
|
|
330
|
+
name: z.string(),
|
|
331
|
+
command: z.string(),
|
|
332
|
+
args: z.array(z.string()).optional(),
|
|
333
|
+
env: z.record(z.string()).optional()
|
|
334
|
+
});
|
|
335
|
+
const agentBlockSchema = z.object({
|
|
336
|
+
...executableBlockFields,
|
|
337
|
+
type: z.literal("agent"),
|
|
338
|
+
content: z.string().optional(),
|
|
339
|
+
metadata: executableBlockMetadataSchema.extend({
|
|
340
|
+
deepnote_agent_model: z.string().default("auto"),
|
|
341
|
+
deepnote_mcp_servers: z.array(mcpServerSchema).optional()
|
|
342
|
+
}).default({})
|
|
343
|
+
});
|
|
317
344
|
const inputTextBlockSchema = z.object({
|
|
318
345
|
...executableBlockFields,
|
|
319
346
|
type: z.literal("input-text"),
|
|
@@ -409,6 +436,7 @@ const deepnoteBlockSchema = z.discriminatedUnion("type", [
|
|
|
409
436
|
textCellBulletBlockSchema,
|
|
410
437
|
textCellTodoBlockSchema,
|
|
411
438
|
textCellCalloutBlockSchema,
|
|
439
|
+
agentBlockSchema,
|
|
412
440
|
codeBlockSchema,
|
|
413
441
|
sqlBlockSchema,
|
|
414
442
|
notebookFunctionBlockSchema,
|
|
@@ -495,6 +523,7 @@ const deepnoteFileSchema = z.object({
|
|
|
495
523
|
customImage: z.string().optional(),
|
|
496
524
|
pythonVersion: z.string().optional()
|
|
497
525
|
}).optional(),
|
|
526
|
+
mcpServers: z.array(mcpServerSchema).optional(),
|
|
498
527
|
requirements: z.array(z.string()).optional(),
|
|
499
528
|
sqlCacheMaxAge: z.number().optional()
|
|
500
529
|
}).optional()
|
|
@@ -743,6 +772,45 @@ function stripMarkdown(block) {
|
|
|
743
772
|
throw new UnsupportedBlockTypeError(`Stripping markdown from block type ${block.type} is not supported yet.`);
|
|
744
773
|
}
|
|
745
774
|
|
|
775
|
+
//#endregion
|
|
776
|
+
//#region src/output-text.ts
|
|
777
|
+
const unknownObjectSchema = z.object({}).passthrough();
|
|
778
|
+
/**
|
|
779
|
+
* Extract a human-readable text string from a single Jupyter-style output object.
|
|
780
|
+
* Returns null if the output type is unrecognized or has no textual representation.
|
|
781
|
+
*/
|
|
782
|
+
function extractOutputText(output, options) {
|
|
783
|
+
const outResult = unknownObjectSchema.safeParse(output);
|
|
784
|
+
if (!outResult.success) return null;
|
|
785
|
+
const out = outResult.data;
|
|
786
|
+
if (out.output_type === "stream" && typeof out.text === "string") return out.text;
|
|
787
|
+
if (out.output_type === "execute_result" || out.output_type === "display_data") {
|
|
788
|
+
const dataResult = unknownObjectSchema.safeParse(out.data);
|
|
789
|
+
const data = dataResult.success ? dataResult.data : void 0;
|
|
790
|
+
if (data?.["text/plain"]) return String(data["text/plain"]);
|
|
791
|
+
if (data?.["text/html"]) return "[HTML output]";
|
|
792
|
+
if (data?.["image/png"] || data?.["image/jpeg"]) return "[Image output]";
|
|
793
|
+
}
|
|
794
|
+
if (out.output_type === "error") {
|
|
795
|
+
let text = `Error: ${String(out.ename || "Error")}: ${String(out.evalue || "")}`;
|
|
796
|
+
if (options?.includeTraceback && Array.isArray(out.traceback)) text += "\n" + out.traceback.map((line) => line.replace(/\x1b\[[0-9;]*m/g, "")).join("\n");
|
|
797
|
+
return text;
|
|
798
|
+
}
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Extract human-readable text from an array of Jupyter-style output objects.
|
|
803
|
+
* Joins non-null results with newlines.
|
|
804
|
+
*/
|
|
805
|
+
function extractOutputsText(outputs, options) {
|
|
806
|
+
const texts = [];
|
|
807
|
+
for (const output of outputs) {
|
|
808
|
+
const text = extractOutputText(output, options);
|
|
809
|
+
if (text != null) texts.push(text);
|
|
810
|
+
}
|
|
811
|
+
return texts.join("\n");
|
|
812
|
+
}
|
|
813
|
+
|
|
746
814
|
//#endregion
|
|
747
815
|
//#region src/blocks/python-utils.ts
|
|
748
816
|
function escapePythonString(value) {
|
|
@@ -1162,6 +1230,7 @@ function isVisualizationBlock(block) {
|
|
|
1162
1230
|
//#endregion
|
|
1163
1231
|
//#region src/python-code.ts
|
|
1164
1232
|
function createPythonCode(block, executionContext) {
|
|
1233
|
+
if (isAgentBlock(block)) return createPythonCodeForAgentBlock(block);
|
|
1165
1234
|
if (isCodeBlock(block)) return createPythonCodeForCodeBlock(block);
|
|
1166
1235
|
if (isSqlBlock(block)) return createPythonCodeForSqlBlock(block);
|
|
1167
1236
|
if (isInputTextBlock(block)) return createPythonCodeForInputTextBlock(block);
|
|
@@ -1180,4 +1249,4 @@ function createPythonCode(block, executionContext) {
|
|
|
1180
1249
|
}
|
|
1181
1250
|
|
|
1182
1251
|
//#endregion
|
|
1183
|
-
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 };
|
|
1252
|
+
export { DeepnoteError, EncodingError, INPUT_BLOCK_TYPES, InvalidValueError, ParseError, ProhibitedYamlFeatureError, SchemaValidationError, UnsupportedBlockTypeError, YamlParseError, convertToEnvironmentVariableName, createMarkdown, createPythonCode, decodeUtf8NoBom, deepnoteBlockSchema, deepnoteFileSchema, deepnoteSnapshotSchema, deserializeDeepnoteFile, environmentSchema, executionErrorSchema, executionSchema, executionSummarySchema, extractOutputText, extractOutputsText, generateSortingKey, getSqlEnvVarName, isAgentBlock, isExecutableBlock, isExecutableBlockType, mcpServerSchema, parseYaml, serializeDeepnoteFile, serializeDeepnoteSnapshot, stripMarkdown };
|