Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ai): include images when reading markdown via Read tool (#4174)

Eric Hayesae446878c5f4
diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts b/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts
index 99f5bea66f..bcca21f510 100644
--- a/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts
@@ -1677,11 +1677,33 @@ export const ReadContentResponse = z.object({
z
.object({
markdown: z.array(
- z.object({
- content: z.string(),
- nodeId: z.string(),
- rawContent: z.string(),
- type: z.string(),
+ z.any().superRefine((x, ctx) => {
+ const schemas = [
+ z.object({
+ content: z.string(),
+ nodeId: z.string(),
+ tag: z.string(),
+ type: z.literal('generic'),
+ }),
+ z.object({ type: z.literal('staticImage'), url: z.string() }),
+ z.object({ id: z.string(), type: z.literal('dssImage') }),
+ ];
+ const errors = schemas.reduce<z.ZodError[]>(
+ (errors, schema) =>
+ ((result) =>
+ result.error ? [...errors, result.error] : errors)(
+ schema.safeParse(x)
+ ),
+ []
+ );
+ if (schemas.length - errors.length !== 1) {
+ ctx.addIssue({
+ path: ctx.path,
+ code: 'invalid_union',
+ unionErrors: errors,
+ message: 'Invalid input: Should pass single schema',
+ });
+ }
})
),
})
diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
index 070bce3275..f3fdccc9a1 100644
--- a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
+++ b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts
@@ -66,6 +66,39 @@ export type Content =
| {
markdown: MarkdownNode[];
};
+/**
+ * A single node of a markdown document as seen by the AI.
+ */
+export type MarkdownNode =
+ | {
+ /**
+ * Human readable content
+ */
+ content: string;
+ /**
+ * The node id
+ */
+ nodeId: string;
+ /**
+ * The style on the node, h1, paragraph, code, etc.
+ */
+ tag: string;
+ type: 'generic';
+ }
+ | {
+ type: 'staticImage';
+ /**
+ * URL the image can be fetched from.
+ */
+ url: string;
+ }
+ | {
+ /**
+ * The DSS id of the image. Use the read tool with this id to read it.
+ */
+ id: string;
+ type: 'dssImage';
+ };
export type UnifiedSearchIndex =
| 'documents'
| 'chats'
@@ -742,27 +775,6 @@ export interface Thread {
*/
updatedAt?: string | null;
}
-/**
- * Markdown node
- */
-export interface MarkdownNode {
- /**
- * Human readable content
- */
- content: string;
- /**
- * The node id
- */
- nodeId: string;
- /**
- * Json respresentation
- */
- rawContent: string;
- /**
- * The style on the node, H1, em, code, etc.
- */
- type: string;
-}
/**
* Search items by their content: document body text; email subject/body/sender/recipient/cc/bcc and the display names on those addresses; chat messages; call transcripts. This is keyword search, not semantic search: queries only match literal words/tokens, prefixes, or exact quoted terms that appear in the indexed content. Use this for targeted keyword/content lookup, not for activity-summary questions like "what happened today", "what's going on", "catch me up", or "what happened in standup today"; those should start with ListEntities using time/type/channel filters. Whitespace-separated terms are ANDed. For documents and emails, every term must match somewhere in the document — different terms can appear in different chunks/pages or different fields. For documents and emails specifically, each single-word term is matched as a prefix (so `scri` matches `script`); for emails the prefix expansion also runs against the local-part of address fields. For chats, channels, and call transcripts the whole query is matched as a single adjacent phrase prefix — so pass 1-3 targeted keywords drawn from words that would literally appear in the content, not the user's natural-language description; long phrases will not match. Wrap a term in double quotes (e.g. `"deal review"` or `"[email protected]"`) to force exact-token / exact-phrase matching instead of prefix. If the user's request combines a person with a topic, run separate searches rather than one combined query. Leave entityTypes empty by default; only filter when the user explicitly scopes to a type.
*/
diff --git a/rust/cloud-storage/documents/src/inbound/toolset/read_content.rs b/rust/cloud-storage/documents/src/inbound/toolset/read_content.rs
index b63fd33bc5..0c01214475 100644
--- a/rust/cloud-storage/documents/src/inbound/toolset/read_content.rs
+++ b/rust/cloud-storage/documents/src/inbound/toolset/read_content.rs
@@ -21,27 +21,43 @@ use uuid::Uuid;
use super::DocumentToolContext;
-/// Markdown node
+/// A single node of a markdown document as seen by the AI.
#[derive(Debug, Serialize, JsonSchema)]
-#[serde(rename_all = "camelCase")]
-pub struct MarkdownNode {
- /// The node id
- pub node_id: String,
- /// Human readable content
- pub content: String,
- /// Json respresentation
- pub raw_content: String,
- /// The style on the node, H1, em, code, etc.
- pub r#type: String,
+#[serde(tag = "type", rename_all = "camelCase")]
+pub enum MarkdownNode {
+ /// A textual content node (paragraph, heading, list, code block, etc.).
+ #[serde(rename_all = "camelCase")]
+ Generic {
+ /// The node id
+ node_id: String,
+ /// Human readable content
+ content: String,
+ /// The style on the node, h1, paragraph, code, etc.
+ tag: String,
+ },
+ /// An image hosted at a publicly fetchable URL. Fetch the URL to view it.
+ StaticImage {
+ /// URL the image can be fetched from.
+ url: String,
+ },
+ /// An image stored in DSS. Pass this id to the read tool to view the image.
+ DssImage {
+ /// The DSS id of the image. Use the read tool with this id to read it.
+ id: String,
+ },
}
-impl From<lexical_client::types::MarkdownNode> for MarkdownNode {
- fn from(value: lexical_client::types::MarkdownNode) -> Self {
- Self {
- node_id: value.node_id,
- content: value.content,
- raw_content: value.raw_content,
- r#type: value.r#type,
+impl From<lexical_client::types::NewMdNode> for MarkdownNode {
+ fn from(value: lexical_client::types::NewMdNode) -> Self {
+ use lexical_client::types::NewMdNode;
+ match value {
+ NewMdNode::Generic(node) => MarkdownNode::Generic {
+ node_id: node.node_id,
+ content: node.content,
+ tag: node.tag,
+ },
+ NewMdNode::StaticImage { url } => MarkdownNode::StaticImage { url },
+ NewMdNode::DssImage { id } => MarkdownNode::DssImage { id },
}
}
}
@@ -142,7 +158,7 @@ where
FileAssociation::Md(_) => Content::Markdown(
service_context
.lexical_client
- .parse_markdown_for_ai(&self.document_id.to_string())
+ .parse_cognition_v2(&self.document_id.to_string())
.await
.map_err(|e| ToolCallError {
description: "unable to parse markdown".to_string(),