-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtyped.ts
More file actions
115 lines (104 loc) · 3.06 KB
/
Copy pathtyped.ts
File metadata and controls
115 lines (104 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Typed-result helpers for the rita MCP server.
*
* The agent's `src/mcp/results.ts` parses each MCP text content item; if it parses as JSON
* with `$rita_kind`, it dispatches as artifact / citation / sqlite_table. Otherwise the text
* is injected into the model's context as plain text.
*
* Each helper returns a single MCP `{ type: "text", text: <json> }` content item.
*/
import { z } from "zod";
export interface ContentItem {
type: "text";
text: string;
}
export function textItem(content: string): ContentItem {
return { type: "text", text: content };
}
export function artifactItem(artifact: Record<string, unknown>): ContentItem {
return {
type: "text",
text: JSON.stringify({ $rita_kind: "artifact", artifact }),
};
}
export function webCitationItem(args: { url: string; title: string; id?: string }): ContentItem {
return {
type: "text",
text: JSON.stringify({
$rita_kind: "citation",
citation: {
type: "web",
url: args.url,
title: args.title,
...(args.id ? { id: args.id } : {}),
},
}),
};
}
export function documentCitationItem(args: {
uri: string;
title: string;
page?: number;
id?: string;
}): ContentItem {
return {
type: "text",
text: JSON.stringify({
$rita_kind: "citation",
citation: {
type: "document",
uri: args.uri,
title: args.title,
...(args.page != null ? { page: args.page } : {}),
...(args.id ? { id: args.id } : {}),
},
}),
};
}
export function sqliteTableItem(name: string, rows: Record<string, unknown>[]): ContentItem {
return {
type: "text",
text: JSON.stringify({ $rita_kind: "sqlite_table", name, rows }),
};
}
export function errorItem(args: {
code: string;
message: string;
retryable?: boolean;
}): ContentItem {
return {
type: "text",
text: JSON.stringify({
$rita_kind: "error",
error: {
code: args.code,
message: args.message,
retryable: args.retryable ?? false,
},
}),
};
}
export function modelContextItem(summary: string): ContentItem {
return {
type: "text",
text: JSON.stringify({ $rita_kind: "model_context", summary }),
};
}
/**
* Per-conversation Daytona sandbox identity. Emitted by `execute_code` after a
* successful `prepareCompute` so the agent can detect sandbox recreation
* (auto-stop → fresh sandbox) and invalidate its `tablesShipped` set.
* The agent dispatches this kind silently — no model-facing text.
*
* min(1): an empty sandbox_id would pass emission here but be dropped by the
* agent-side parser (src/mcp/results.ts mirrors this schema), silently forcing
* a conservative tablesShipped.clear() on every call. Reject it at the source.
*/
export const sandboxMetaPayloadSchema = z.object({ sandbox_id: z.string().min(1) });
export type SandboxMetaPayload = z.infer<typeof sandboxMetaPayloadSchema>;
export function sandboxMetaItem(sandboxId: string): ContentItem {
return {
type: "text",
text: JSON.stringify({ $rita_kind: "sandbox_meta", sandbox_id: sandboxId }),
};
}