@dexto/core 1.10.0 → 1.10.2

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.
Files changed (53) hide show
  1. package/dist/approval/schemas.cjs +2 -7
  2. package/dist/approval/schemas.d.ts +508 -5
  3. package/dist/approval/schemas.d.ts.map +1 -1
  4. package/dist/approval/schemas.js +1 -6
  5. package/dist/context/utils.cjs +28 -0
  6. package/dist/context/utils.d.ts.map +1 -1
  7. package/dist/context/utils.js +28 -0
  8. package/dist/index.browser.cjs +6 -0
  9. package/dist/index.browser.d.ts +4 -0
  10. package/dist/index.browser.d.ts.map +1 -1
  11. package/dist/index.browser.js +4 -0
  12. package/dist/llm/errors.d.ts +8 -8
  13. package/dist/llm/formatters/vercel.cjs +59 -24
  14. package/dist/llm/formatters/vercel.d.ts.map +1 -1
  15. package/dist/llm/formatters/vercel.js +59 -24
  16. package/dist/llm/schemas.d.ts +3 -3
  17. package/dist/llm/services/factory.cjs +7 -0
  18. package/dist/llm/services/factory.d.ts.map +1 -1
  19. package/dist/llm/services/factory.js +7 -0
  20. package/dist/session/schemas.d.ts +2 -2
  21. package/dist/storage/tool-executions/types.cjs +2 -1
  22. package/dist/storage/tool-executions/types.d.ts +254 -3
  23. package/dist/storage/tool-executions/types.d.ts.map +1 -1
  24. package/dist/storage/tool-executions/types.js +2 -1
  25. package/dist/systemPrompt/schemas.d.ts +3 -3
  26. package/dist/tools/activity.cjs +341 -0
  27. package/dist/tools/activity.d.ts +70 -0
  28. package/dist/tools/activity.d.ts.map +1 -0
  29. package/dist/tools/activity.js +318 -0
  30. package/dist/tools/display-types.cjs +34 -4
  31. package/dist/tools/display-types.d.ts.map +1 -1
  32. package/dist/tools/display-types.js +34 -4
  33. package/dist/tools/index.cjs +8 -1
  34. package/dist/tools/index.d.ts +3 -0
  35. package/dist/tools/index.d.ts.map +1 -1
  36. package/dist/tools/index.js +8 -1
  37. package/dist/tools/presentation/tool-presentation.cjs +78 -25
  38. package/dist/tools/presentation/tool-presentation.d.ts +2 -1
  39. package/dist/tools/presentation/tool-presentation.d.ts.map +1 -1
  40. package/dist/tools/presentation/tool-presentation.js +78 -25
  41. package/dist/tools/presentation-schema.cjs +118 -0
  42. package/dist/tools/presentation-schema.d.ts +132 -0
  43. package/dist/tools/presentation-schema.d.ts.map +1 -0
  44. package/dist/tools/presentation-schema.js +94 -0
  45. package/dist/tools/presentation.cjs +8 -0
  46. package/dist/tools/presentation.d.ts +4 -0
  47. package/dist/tools/presentation.d.ts.map +1 -1
  48. package/dist/tools/presentation.js +8 -0
  49. package/dist/tools/types.d.ts +12 -79
  50. package/dist/tools/types.d.ts.map +1 -1
  51. package/dist/workspace/types.d.ts +1 -0
  52. package/dist/workspace/types.d.ts.map +1 -1
  53. package/package.json +7 -2
@@ -23,6 +23,7 @@ __export(tool_presentation_exports, {
23
23
  module.exports = __toCommonJS(tool_presentation_exports);
24
24
  var import_errors = require("../../errors/index.js");
25
25
  var import_error_codes = require("../error-codes.js");
26
+ var import_display_types = require("../display-types.js");
26
27
  const MCP_TOOL_PREFIX = "mcp--";
27
28
  class ToolPresentation {
28
29
  constructor(getLocalTool, validateLocalToolArgs, buildToolExecutionContext, logger) {
@@ -58,13 +59,16 @@ class ToolPresentation {
58
59
  return fallback;
59
60
  }
60
61
  const presentation = this.getLocalTool(input.toolName)?.presentation;
61
- if (!presentation?.describeHeader && !presentation?.describeArgs) {
62
+ if (!presentation?.activity && !presentation?.describeHeader && !presentation?.describeArgs) {
62
63
  return fallback;
63
64
  }
65
+ let nextSnapshot = {
66
+ ...fallback,
67
+ ...presentation.activity ? { activity: presentation.activity } : {}
68
+ };
64
69
  try {
65
70
  const validatedArgs = this.validateLocalToolArgs(input.toolName, input.args);
66
71
  const context = this.buildToolExecutionContext(input);
67
- let nextSnapshot = fallback;
68
72
  const header = presentation.describeHeader?.(validatedArgs, context);
69
73
  if (!isPromiseLike(header) && header) {
70
74
  nextSnapshot = {
@@ -84,7 +88,7 @@ class ToolPresentation {
84
88
  this.logger.debug(
85
89
  `Tool presentation snapshot generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
86
90
  );
87
- return fallback;
91
+ return nextSnapshot;
88
92
  }
89
93
  }
90
94
  async snapshotForCall(input) {
@@ -93,51 +97,100 @@ class ToolPresentation {
93
97
  return fallback;
94
98
  }
95
99
  const presentation = this.getLocalTool(input.toolName)?.presentation;
96
- if (!presentation?.describeHeader && !presentation?.describeArgs) {
100
+ if (!presentation?.activity && !presentation?.describeHeader && !presentation?.describeArgs) {
97
101
  return fallback;
98
102
  }
103
+ let nextSnapshot = {
104
+ ...fallback,
105
+ ...presentation.activity ? { activity: presentation.activity } : {}
106
+ };
107
+ let context;
108
+ try {
109
+ context = this.buildToolExecutionContext(input);
110
+ } catch (error) {
111
+ this.logger.debug(
112
+ `Tool presentation snapshot generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
113
+ );
114
+ return nextSnapshot;
115
+ }
99
116
  try {
100
- const context = this.buildToolExecutionContext(input);
101
117
  const describedHeader = presentation.describeHeader ? await Promise.resolve(presentation.describeHeader(input.args, context)) : null;
118
+ if (describedHeader) {
119
+ nextSnapshot = {
120
+ ...nextSnapshot,
121
+ header: { ...nextSnapshot.header, ...describedHeader }
122
+ };
123
+ }
124
+ } catch (error) {
125
+ this.logger.debug(
126
+ `Tool header presentation generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
127
+ );
128
+ }
129
+ try {
102
130
  const describedArgs = presentation.describeArgs ? await Promise.resolve(presentation.describeArgs(input.args, context)) : null;
103
- return {
104
- ...fallback,
105
- ...describedHeader ? { header: { ...fallback.header, ...describedHeader } } : {},
106
- ...describedArgs ? { args: describedArgs } : {}
107
- };
131
+ if (describedArgs) {
132
+ nextSnapshot = { ...nextSnapshot, args: describedArgs };
133
+ }
108
134
  } catch (error) {
109
135
  this.logger.debug(
110
- `Tool presentation snapshot generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
136
+ `Tool argument presentation generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
111
137
  );
112
- return fallback;
113
138
  }
139
+ return nextSnapshot;
114
140
  }
115
141
  async augmentWithResult(input) {
116
142
  if (input.toolName.startsWith(MCP_TOOL_PREFIX)) {
117
143
  return input.snapshot;
118
144
  }
119
- const describeResult = this.getLocalTool(input.toolName)?.presentation?.describeResult;
120
- if (!describeResult) {
145
+ const presentation = this.getLocalTool(input.toolName)?.presentation;
146
+ if (!presentation?.describeResult && !presentation?.describeResultActivity) {
121
147
  return input.snapshot;
122
148
  }
149
+ let context;
123
150
  try {
124
- const context = this.buildToolExecutionContext(input);
125
- const resultPresentation = await Promise.resolve(
126
- describeResult(input.result, input.args, context)
127
- );
128
- if (!resultPresentation) {
129
- return input.snapshot;
130
- }
131
- return {
132
- ...input.snapshot,
133
- result: resultPresentation
134
- };
151
+ context = this.buildToolExecutionContext(input);
135
152
  } catch (error) {
136
153
  this.logger.debug(
137
154
  `Tool result presentation snapshot generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
138
155
  );
139
156
  return input.snapshot;
140
157
  }
158
+ let resultPresentation;
159
+ try {
160
+ resultPresentation = presentation.describeResult ? await Promise.resolve(
161
+ presentation.describeResult(input.result, input.args, context)
162
+ ) ?? void 0 : void 0;
163
+ } catch (error) {
164
+ this.logger.debug(
165
+ `Tool result presentation generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
166
+ );
167
+ }
168
+ let resultActivity;
169
+ try {
170
+ resultActivity = presentation.describeResultActivity ? await Promise.resolve(
171
+ presentation.describeResultActivity(
172
+ this.extractDisplayData(input.result),
173
+ input.args,
174
+ context
175
+ )
176
+ ) ?? void 0 : void 0;
177
+ } catch (error) {
178
+ this.logger.debug(
179
+ `Tool result activity generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
180
+ );
181
+ }
182
+ return {
183
+ ...input.snapshot,
184
+ ...resultActivity ? { activity: resultActivity } : {},
185
+ ...resultPresentation ? { result: resultPresentation } : {}
186
+ };
187
+ }
188
+ extractDisplayData(result) {
189
+ if (result === null || typeof result !== "object" || !("_display" in result)) {
190
+ return void 0;
191
+ }
192
+ const display = result._display;
193
+ return (0, import_display_types.isValidDisplayData)(display) ? display : void 0;
141
194
  }
142
195
  async preview(input) {
143
196
  if (input.toolName.startsWith(MCP_TOOL_PREFIX)) {
@@ -1,7 +1,7 @@
1
1
  import type { Logger } from '../../logger/v2/types.js';
2
2
  import type { AgentRunContext } from '../../runtime/run-context.js';
3
3
  import type { Tool, ToolExecutionContext, ToolPresentationSnapshotV1 } from '../types.js';
4
- import type { ToolDisplayData } from '../display-types.js';
4
+ import { type ToolDisplayData } from '../display-types.js';
5
5
  type BuildToolExecutionContext = (options: {
6
6
  sessionId?: string | undefined;
7
7
  toolCallId?: string | undefined;
@@ -37,6 +37,7 @@ export declare class ToolPresentation {
37
37
  sessionId?: string | undefined;
38
38
  runContext?: AgentRunContext | undefined;
39
39
  }): Promise<ToolPresentationSnapshotV1>;
40
+ private extractDisplayData;
40
41
  preview(input: {
41
42
  toolName: string;
42
43
  args: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-presentation.d.ts","sourceRoot":"","sources":["../../../src/tools/presentation/tool-presentation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,KAAK,EAAE,IAAI,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAI3D,KAAK,yBAAyB,GAAG,CAAC,OAAO,EAAE;IACvC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,CAAC,EAA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C;QACnB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC/B,UAAU,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC;KAC5C,GAAG,OAAO,CAAC,0BAA0B,CAAC;IA+DvC,OAAO,CAAC,kBAAkB;IAQpB,OAAO,CAAC,KAAK,EAAE;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9B,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC/B,UAAU,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC;KAC5C,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAgCxC,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,WAAW;CAQtB"}
@@ -1,6 +1,7 @@
1
1
  import "../../chunk-C6A6W6XS.js";
2
2
  import { DextoRuntimeError } from "../../errors/index.js";
3
3
  import { ToolErrorCode } from "../error-codes.js";
4
+ import { isValidDisplayData } from "../display-types.js";
4
5
  const MCP_TOOL_PREFIX = "mcp--";
5
6
  class ToolPresentation {
6
7
  constructor(getLocalTool, validateLocalToolArgs, buildToolExecutionContext, logger) {
@@ -36,13 +37,16 @@ class ToolPresentation {
36
37
  return fallback;
37
38
  }
38
39
  const presentation = this.getLocalTool(input.toolName)?.presentation;
39
- if (!presentation?.describeHeader && !presentation?.describeArgs) {
40
+ if (!presentation?.activity && !presentation?.describeHeader && !presentation?.describeArgs) {
40
41
  return fallback;
41
42
  }
43
+ let nextSnapshot = {
44
+ ...fallback,
45
+ ...presentation.activity ? { activity: presentation.activity } : {}
46
+ };
42
47
  try {
43
48
  const validatedArgs = this.validateLocalToolArgs(input.toolName, input.args);
44
49
  const context = this.buildToolExecutionContext(input);
45
- let nextSnapshot = fallback;
46
50
  const header = presentation.describeHeader?.(validatedArgs, context);
47
51
  if (!isPromiseLike(header) && header) {
48
52
  nextSnapshot = {
@@ -62,7 +66,7 @@ class ToolPresentation {
62
66
  this.logger.debug(
63
67
  `Tool presentation snapshot generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
64
68
  );
65
- return fallback;
69
+ return nextSnapshot;
66
70
  }
67
71
  }
68
72
  async snapshotForCall(input) {
@@ -71,51 +75,100 @@ class ToolPresentation {
71
75
  return fallback;
72
76
  }
73
77
  const presentation = this.getLocalTool(input.toolName)?.presentation;
74
- if (!presentation?.describeHeader && !presentation?.describeArgs) {
78
+ if (!presentation?.activity && !presentation?.describeHeader && !presentation?.describeArgs) {
75
79
  return fallback;
76
80
  }
81
+ let nextSnapshot = {
82
+ ...fallback,
83
+ ...presentation.activity ? { activity: presentation.activity } : {}
84
+ };
85
+ let context;
86
+ try {
87
+ context = this.buildToolExecutionContext(input);
88
+ } catch (error) {
89
+ this.logger.debug(
90
+ `Tool presentation snapshot generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
91
+ );
92
+ return nextSnapshot;
93
+ }
77
94
  try {
78
- const context = this.buildToolExecutionContext(input);
79
95
  const describedHeader = presentation.describeHeader ? await Promise.resolve(presentation.describeHeader(input.args, context)) : null;
96
+ if (describedHeader) {
97
+ nextSnapshot = {
98
+ ...nextSnapshot,
99
+ header: { ...nextSnapshot.header, ...describedHeader }
100
+ };
101
+ }
102
+ } catch (error) {
103
+ this.logger.debug(
104
+ `Tool header presentation generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
105
+ );
106
+ }
107
+ try {
80
108
  const describedArgs = presentation.describeArgs ? await Promise.resolve(presentation.describeArgs(input.args, context)) : null;
81
- return {
82
- ...fallback,
83
- ...describedHeader ? { header: { ...fallback.header, ...describedHeader } } : {},
84
- ...describedArgs ? { args: describedArgs } : {}
85
- };
109
+ if (describedArgs) {
110
+ nextSnapshot = { ...nextSnapshot, args: describedArgs };
111
+ }
86
112
  } catch (error) {
87
113
  this.logger.debug(
88
- `Tool presentation snapshot generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
114
+ `Tool argument presentation generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
89
115
  );
90
- return fallback;
91
116
  }
117
+ return nextSnapshot;
92
118
  }
93
119
  async augmentWithResult(input) {
94
120
  if (input.toolName.startsWith(MCP_TOOL_PREFIX)) {
95
121
  return input.snapshot;
96
122
  }
97
- const describeResult = this.getLocalTool(input.toolName)?.presentation?.describeResult;
98
- if (!describeResult) {
123
+ const presentation = this.getLocalTool(input.toolName)?.presentation;
124
+ if (!presentation?.describeResult && !presentation?.describeResultActivity) {
99
125
  return input.snapshot;
100
126
  }
127
+ let context;
101
128
  try {
102
- const context = this.buildToolExecutionContext(input);
103
- const resultPresentation = await Promise.resolve(
104
- describeResult(input.result, input.args, context)
105
- );
106
- if (!resultPresentation) {
107
- return input.snapshot;
108
- }
109
- return {
110
- ...input.snapshot,
111
- result: resultPresentation
112
- };
129
+ context = this.buildToolExecutionContext(input);
113
130
  } catch (error) {
114
131
  this.logger.debug(
115
132
  `Tool result presentation snapshot generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
116
133
  );
117
134
  return input.snapshot;
118
135
  }
136
+ let resultPresentation;
137
+ try {
138
+ resultPresentation = presentation.describeResult ? await Promise.resolve(
139
+ presentation.describeResult(input.result, input.args, context)
140
+ ) ?? void 0 : void 0;
141
+ } catch (error) {
142
+ this.logger.debug(
143
+ `Tool result presentation generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
144
+ );
145
+ }
146
+ let resultActivity;
147
+ try {
148
+ resultActivity = presentation.describeResultActivity ? await Promise.resolve(
149
+ presentation.describeResultActivity(
150
+ this.extractDisplayData(input.result),
151
+ input.args,
152
+ context
153
+ )
154
+ ) ?? void 0 : void 0;
155
+ } catch (error) {
156
+ this.logger.debug(
157
+ `Tool result activity generation failed for '${input.toolName}': ${error instanceof Error ? error.message : String(error)}`
158
+ );
159
+ }
160
+ return {
161
+ ...input.snapshot,
162
+ ...resultActivity ? { activity: resultActivity } : {},
163
+ ...resultPresentation ? { result: resultPresentation } : {}
164
+ };
165
+ }
166
+ extractDisplayData(result) {
167
+ if (result === null || typeof result !== "object" || !("_display" in result)) {
168
+ return void 0;
169
+ }
170
+ const display = result._display;
171
+ return isValidDisplayData(display) ? display : void 0;
119
172
  }
120
173
  async preview(input) {
121
174
  if (input.toolName.startsWith(MCP_TOOL_PREFIX)) {
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var presentation_schema_exports = {};
20
+ __export(presentation_schema_exports, {
21
+ ToolPresentationSnapshotV1Schema: () => ToolPresentationSnapshotV1Schema,
22
+ isToolPresentationSnapshotV1: () => isToolPresentationSnapshotV1
23
+ });
24
+ module.exports = __toCommonJS(presentation_schema_exports);
25
+ var import_zod = require("zod");
26
+ const ToolActivityPresentationSchema = import_zod.z.object({
27
+ category: import_zod.z.string().min(1),
28
+ label: import_zod.z.object({
29
+ running: import_zod.z.string().min(1),
30
+ completed: import_zod.z.string().min(1)
31
+ }).strict(),
32
+ summary: import_zod.z.object({
33
+ verb: import_zod.z.string().min(1),
34
+ singular: import_zod.z.string().min(1),
35
+ plural: import_zod.z.string().min(1)
36
+ }).strict()
37
+ }).strict();
38
+ const PresentationValueSchema = import_zod.z.object({
39
+ label: import_zod.z.string(),
40
+ display: import_zod.z.string(),
41
+ kind: import_zod.z.enum(["path", "command", "url", "text", "json"]).optional(),
42
+ sensitive: import_zod.z.boolean().optional()
43
+ }).strict();
44
+ const UiEffectSchema = import_zod.z.discriminatedUnion("type", [
45
+ import_zod.z.object({
46
+ type: import_zod.z.literal("setFlag"),
47
+ flag: import_zod.z.enum(["autoApproveEdits", "planModeActive", "planModeInitialized"]),
48
+ value: import_zod.z.boolean()
49
+ }).strict(),
50
+ import_zod.z.object({
51
+ type: import_zod.z.literal("toast"),
52
+ kind: import_zod.z.enum(["info", "warning", "success", "error"]),
53
+ message: import_zod.z.string()
54
+ }).strict()
55
+ ]);
56
+ const ApprovalActionSchema = import_zod.z.union([
57
+ import_zod.z.object({
58
+ id: import_zod.z.string(),
59
+ label: import_zod.z.string(),
60
+ kind: import_zod.z.enum(["primary", "secondary", "danger"]).optional(),
61
+ responseData: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
62
+ uiEffects: import_zod.z.array(UiEffectSchema).optional()
63
+ }).strict(),
64
+ import_zod.z.object({
65
+ id: import_zod.z.string(),
66
+ label: import_zod.z.string(),
67
+ kind: import_zod.z.literal("danger").optional(),
68
+ denyWithFeedback: import_zod.z.object({
69
+ placeholder: import_zod.z.string().optional(),
70
+ messageTemplate: import_zod.z.string().optional()
71
+ }).strict()
72
+ }).strict()
73
+ ]);
74
+ const ToolPresentationSnapshotV1Schema = import_zod.z.object({
75
+ version: import_zod.z.literal(1),
76
+ activity: ToolActivityPresentationSchema.optional(),
77
+ source: import_zod.z.object({
78
+ type: import_zod.z.enum(["local", "mcp"]),
79
+ mcpServerName: import_zod.z.string().optional()
80
+ }).strict().optional(),
81
+ header: import_zod.z.object({
82
+ title: import_zod.z.string().optional(),
83
+ argsText: import_zod.z.string().optional()
84
+ }).strict().optional(),
85
+ chips: import_zod.z.array(
86
+ import_zod.z.object({
87
+ kind: import_zod.z.enum(["neutral", "info", "warning", "danger", "success"]),
88
+ text: import_zod.z.string()
89
+ }).strict()
90
+ ).optional(),
91
+ args: import_zod.z.object({
92
+ summary: import_zod.z.array(PresentationValueSchema).optional(),
93
+ groups: import_zod.z.array(
94
+ import_zod.z.object({
95
+ id: import_zod.z.string(),
96
+ label: import_zod.z.string(),
97
+ collapsedByDefault: import_zod.z.boolean().optional(),
98
+ items: import_zod.z.array(PresentationValueSchema)
99
+ }).strict()
100
+ ).optional()
101
+ }).strict().optional(),
102
+ capabilities: import_zod.z.array(import_zod.z.string()).optional(),
103
+ approval: import_zod.z.object({
104
+ actions: import_zod.z.array(ApprovalActionSchema).optional()
105
+ }).strict().optional(),
106
+ result: import_zod.z.object({
107
+ summaryText: import_zod.z.string().optional(),
108
+ uiEffects: import_zod.z.array(UiEffectSchema).optional()
109
+ }).strict().optional()
110
+ }).strict();
111
+ function isToolPresentationSnapshotV1(value) {
112
+ return ToolPresentationSnapshotV1Schema.safeParse(value).success;
113
+ }
114
+ // Annotate the CommonJS export names for ESM import in node:
115
+ 0 && (module.exports = {
116
+ ToolPresentationSnapshotV1Schema,
117
+ isToolPresentationSnapshotV1
118
+ });
@@ -0,0 +1,132 @@
1
+ import { z } from 'zod';
2
+ /** Runtime validator for persisted and transported tool presentation snapshots. */
3
+ export declare const ToolPresentationSnapshotV1Schema: z.ZodObject<{
4
+ version: z.ZodLiteral<1>;
5
+ activity: z.ZodOptional<z.ZodObject<{
6
+ category: z.ZodString;
7
+ label: z.ZodObject<{
8
+ running: z.ZodString;
9
+ completed: z.ZodString;
10
+ }, z.core.$strict>;
11
+ summary: z.ZodObject<{
12
+ verb: z.ZodString;
13
+ singular: z.ZodString;
14
+ plural: z.ZodString;
15
+ }, z.core.$strict>;
16
+ }, z.core.$strict>>;
17
+ source: z.ZodOptional<z.ZodObject<{
18
+ type: z.ZodEnum<{
19
+ mcp: "mcp";
20
+ local: "local";
21
+ }>;
22
+ mcpServerName: z.ZodOptional<z.ZodString>;
23
+ }, z.core.$strict>>;
24
+ header: z.ZodOptional<z.ZodObject<{
25
+ title: z.ZodOptional<z.ZodString>;
26
+ argsText: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strict>>;
28
+ chips: z.ZodOptional<z.ZodArray<z.ZodObject<{
29
+ kind: z.ZodEnum<{
30
+ info: "info";
31
+ warning: "warning";
32
+ success: "success";
33
+ danger: "danger";
34
+ neutral: "neutral";
35
+ }>;
36
+ text: z.ZodString;
37
+ }, z.core.$strict>>>;
38
+ args: z.ZodOptional<z.ZodObject<{
39
+ summary: z.ZodOptional<z.ZodArray<z.ZodObject<{
40
+ label: z.ZodString;
41
+ display: z.ZodString;
42
+ kind: z.ZodOptional<z.ZodEnum<{
43
+ path: "path";
44
+ command: "command";
45
+ url: "url";
46
+ text: "text";
47
+ json: "json";
48
+ }>>;
49
+ sensitive: z.ZodOptional<z.ZodBoolean>;
50
+ }, z.core.$strict>>>;
51
+ groups: z.ZodOptional<z.ZodArray<z.ZodObject<{
52
+ id: z.ZodString;
53
+ label: z.ZodString;
54
+ collapsedByDefault: z.ZodOptional<z.ZodBoolean>;
55
+ items: z.ZodArray<z.ZodObject<{
56
+ label: z.ZodString;
57
+ display: z.ZodString;
58
+ kind: z.ZodOptional<z.ZodEnum<{
59
+ path: "path";
60
+ command: "command";
61
+ url: "url";
62
+ text: "text";
63
+ json: "json";
64
+ }>>;
65
+ sensitive: z.ZodOptional<z.ZodBoolean>;
66
+ }, z.core.$strict>>;
67
+ }, z.core.$strict>>>;
68
+ }, z.core.$strict>>;
69
+ capabilities: z.ZodOptional<z.ZodArray<z.ZodString>>;
70
+ approval: z.ZodOptional<z.ZodObject<{
71
+ actions: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
72
+ id: z.ZodString;
73
+ label: z.ZodString;
74
+ kind: z.ZodOptional<z.ZodEnum<{
75
+ primary: "primary";
76
+ secondary: "secondary";
77
+ danger: "danger";
78
+ }>>;
79
+ responseData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
80
+ uiEffects: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
81
+ type: z.ZodLiteral<"setFlag">;
82
+ flag: z.ZodEnum<{
83
+ autoApproveEdits: "autoApproveEdits";
84
+ planModeActive: "planModeActive";
85
+ planModeInitialized: "planModeInitialized";
86
+ }>;
87
+ value: z.ZodBoolean;
88
+ }, z.core.$strict>, z.ZodObject<{
89
+ type: z.ZodLiteral<"toast">;
90
+ kind: z.ZodEnum<{
91
+ info: "info";
92
+ error: "error";
93
+ warning: "warning";
94
+ success: "success";
95
+ }>;
96
+ message: z.ZodString;
97
+ }, z.core.$strict>], "type">>>;
98
+ }, z.core.$strict>, z.ZodObject<{
99
+ id: z.ZodString;
100
+ label: z.ZodString;
101
+ kind: z.ZodOptional<z.ZodLiteral<"danger">>;
102
+ denyWithFeedback: z.ZodObject<{
103
+ placeholder: z.ZodOptional<z.ZodString>;
104
+ messageTemplate: z.ZodOptional<z.ZodString>;
105
+ }, z.core.$strict>;
106
+ }, z.core.$strict>]>>>;
107
+ }, z.core.$strict>>;
108
+ result: z.ZodOptional<z.ZodObject<{
109
+ summaryText: z.ZodOptional<z.ZodString>;
110
+ uiEffects: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
111
+ type: z.ZodLiteral<"setFlag">;
112
+ flag: z.ZodEnum<{
113
+ autoApproveEdits: "autoApproveEdits";
114
+ planModeActive: "planModeActive";
115
+ planModeInitialized: "planModeInitialized";
116
+ }>;
117
+ value: z.ZodBoolean;
118
+ }, z.core.$strict>, z.ZodObject<{
119
+ type: z.ZodLiteral<"toast">;
120
+ kind: z.ZodEnum<{
121
+ info: "info";
122
+ error: "error";
123
+ warning: "warning";
124
+ success: "success";
125
+ }>;
126
+ message: z.ZodString;
127
+ }, z.core.$strict>], "type">>>;
128
+ }, z.core.$strict>>;
129
+ }, z.core.$strict>;
130
+ export type ToolPresentationSnapshotV1 = z.output<typeof ToolPresentationSnapshotV1Schema>;
131
+ export declare function isToolPresentationSnapshotV1(value: unknown): value is ToolPresentationSnapshotV1;
132
+ //# sourceMappingURL=presentation-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presentation-schema.d.ts","sourceRoot":"","sources":["../../src/tools/presentation-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAwExB,mFAAmF;AACnF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA6DhC,CAAC;AAEd,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gCAAgC,CAAC,CAAC;AAE3F,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,0BAA0B,CAEhG"}