@deepnote/blocks 4.4.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 +66 -16
- package/dist/index.d.cts +693 -173
- package/dist/index.d.ts +693 -173
- package/dist/index.js +63 -17
- 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
|
/**
|
|
@@ -326,15 +337,6 @@ const buttonBlockSchema = zod.z.object({
|
|
|
326
337
|
deepnote_variable_name: zod.z.string().optional()
|
|
327
338
|
}).default({})
|
|
328
339
|
});
|
|
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
|
-
});
|
|
338
340
|
const bigNumberBlockSchema = zod.z.object({
|
|
339
341
|
...executableBlockFields,
|
|
340
342
|
type: zod.z.literal("big-number"),
|
|
@@ -350,6 +352,21 @@ const bigNumberBlockSchema = zod.z.object({
|
|
|
350
352
|
deepnote_big_number_comparison_format: zod.z.string().optional()
|
|
351
353
|
}).default({})
|
|
352
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
|
+
});
|
|
353
370
|
const inputTextBlockSchema = zod.z.object({
|
|
354
371
|
...executableBlockFields,
|
|
355
372
|
type: zod.z.literal("input-text"),
|
|
@@ -532,6 +549,7 @@ const deepnoteFileSchema = zod.z.object({
|
|
|
532
549
|
customImage: zod.z.string().optional(),
|
|
533
550
|
pythonVersion: zod.z.string().optional()
|
|
534
551
|
}).optional(),
|
|
552
|
+
mcpServers: zod.z.array(mcpServerSchema).optional(),
|
|
535
553
|
requirements: zod.z.array(zod.z.string()).optional(),
|
|
536
554
|
sqlCacheMaxAge: zod.z.number().optional()
|
|
537
555
|
}).optional()
|
|
@@ -781,14 +799,42 @@ function stripMarkdown(block) {
|
|
|
781
799
|
}
|
|
782
800
|
|
|
783
801
|
//#endregion
|
|
784
|
-
//#region src/
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
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;
|
|
789
826
|
}
|
|
790
|
-
|
|
791
|
-
|
|
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");
|
|
792
838
|
}
|
|
793
839
|
|
|
794
840
|
//#endregion
|
|
@@ -1250,10 +1296,14 @@ exports.environmentSchema = environmentSchema;
|
|
|
1250
1296
|
exports.executionErrorSchema = executionErrorSchema;
|
|
1251
1297
|
exports.executionSchema = executionSchema;
|
|
1252
1298
|
exports.executionSummarySchema = executionSummarySchema;
|
|
1299
|
+
exports.extractOutputText = extractOutputText;
|
|
1300
|
+
exports.extractOutputsText = extractOutputsText;
|
|
1253
1301
|
exports.generateSortingKey = generateSortingKey;
|
|
1254
1302
|
exports.getSqlEnvVarName = getSqlEnvVarName;
|
|
1303
|
+
exports.isAgentBlock = isAgentBlock;
|
|
1255
1304
|
exports.isExecutableBlock = isExecutableBlock;
|
|
1256
1305
|
exports.isExecutableBlockType = isExecutableBlockType;
|
|
1306
|
+
exports.mcpServerSchema = mcpServerSchema;
|
|
1257
1307
|
exports.parseYaml = parseYaml;
|
|
1258
1308
|
exports.serializeDeepnoteFile = serializeDeepnoteFile;
|
|
1259
1309
|
exports.serializeDeepnoteSnapshot = serializeDeepnoteSnapshot;
|