@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.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
|
/**
|
|
@@ -300,15 +311,6 @@ const buttonBlockSchema = z.object({
|
|
|
300
311
|
deepnote_variable_name: z.string().optional()
|
|
301
312
|
}).default({})
|
|
302
313
|
});
|
|
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
|
-
});
|
|
312
314
|
const bigNumberBlockSchema = z.object({
|
|
313
315
|
...executableBlockFields,
|
|
314
316
|
type: z.literal("big-number"),
|
|
@@ -324,6 +326,21 @@ const bigNumberBlockSchema = z.object({
|
|
|
324
326
|
deepnote_big_number_comparison_format: z.string().optional()
|
|
325
327
|
}).default({})
|
|
326
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
|
+
});
|
|
327
344
|
const inputTextBlockSchema = z.object({
|
|
328
345
|
...executableBlockFields,
|
|
329
346
|
type: z.literal("input-text"),
|
|
@@ -506,6 +523,7 @@ const deepnoteFileSchema = z.object({
|
|
|
506
523
|
customImage: z.string().optional(),
|
|
507
524
|
pythonVersion: z.string().optional()
|
|
508
525
|
}).optional(),
|
|
526
|
+
mcpServers: z.array(mcpServerSchema).optional(),
|
|
509
527
|
requirements: z.array(z.string()).optional(),
|
|
510
528
|
sqlCacheMaxAge: z.number().optional()
|
|
511
529
|
}).optional()
|
|
@@ -755,14 +773,42 @@ function stripMarkdown(block) {
|
|
|
755
773
|
}
|
|
756
774
|
|
|
757
775
|
//#endregion
|
|
758
|
-
//#region src/
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
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;
|
|
763
800
|
}
|
|
764
|
-
|
|
765
|
-
|
|
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");
|
|
766
812
|
}
|
|
767
813
|
|
|
768
814
|
//#endregion
|
|
@@ -1203,4 +1249,4 @@ function createPythonCode(block, executionContext) {
|
|
|
1203
1249
|
}
|
|
1204
1250
|
|
|
1205
1251
|
//#endregion
|
|
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 };
|
|
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 };
|