@contractspec/example.agent-console 1.44.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.
Files changed (168) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +133 -0
  2. package/.turbo/turbo-build.log +134 -0
  3. package/CHANGELOG.md +212 -0
  4. package/LICENSE +21 -0
  5. package/README.md +86 -0
  6. package/dist/agent/agent.entity.d.ts +55 -0
  7. package/dist/agent/agent.entity.d.ts.map +1 -0
  8. package/dist/agent/agent.entity.js +136 -0
  9. package/dist/agent/agent.entity.js.map +1 -0
  10. package/dist/agent/agent.enum.d.ts +18 -0
  11. package/dist/agent/agent.enum.d.ts.map +1 -0
  12. package/dist/agent/agent.enum.js +34 -0
  13. package/dist/agent/agent.enum.js.map +1 -0
  14. package/dist/agent/agent.event.d.ts +128 -0
  15. package/dist/agent/agent.event.d.ts.map +1 -0
  16. package/dist/agent/agent.event.js +210 -0
  17. package/dist/agent/agent.event.js.map +1 -0
  18. package/dist/agent/agent.handler.d.ts +100 -0
  19. package/dist/agent/agent.handler.d.ts.map +1 -0
  20. package/dist/agent/agent.handler.js +84 -0
  21. package/dist/agent/agent.handler.js.map +1 -0
  22. package/dist/agent/agent.operation.d.ts +471 -0
  23. package/dist/agent/agent.operation.d.ts.map +1 -0
  24. package/dist/agent/agent.operation.js +486 -0
  25. package/dist/agent/agent.operation.js.map +1 -0
  26. package/dist/agent/agent.presentation.d.ts +19 -0
  27. package/dist/agent/agent.presentation.d.ts.map +1 -0
  28. package/dist/agent/agent.presentation.js +89 -0
  29. package/dist/agent/agent.presentation.js.map +1 -0
  30. package/dist/agent/agent.schema.d.ts +401 -0
  31. package/dist/agent/agent.schema.d.ts.map +1 -0
  32. package/dist/agent/agent.schema.js +406 -0
  33. package/dist/agent/agent.schema.js.map +1 -0
  34. package/dist/agent/index.d.ts +8 -0
  35. package/dist/agent/index.js +9 -0
  36. package/dist/agent.feature.d.ts +12 -0
  37. package/dist/agent.feature.d.ts.map +1 -0
  38. package/dist/agent.feature.js +303 -0
  39. package/dist/agent.feature.js.map +1 -0
  40. package/dist/docs/agent-console.docblock.d.ts +1 -0
  41. package/dist/docs/agent-console.docblock.js +113 -0
  42. package/dist/docs/agent-console.docblock.js.map +1 -0
  43. package/dist/docs/index.d.ts +1 -0
  44. package/dist/docs/index.js +1 -0
  45. package/dist/example.d.ts +40 -0
  46. package/dist/example.d.ts.map +1 -0
  47. package/dist/example.js +51 -0
  48. package/dist/example.js.map +1 -0
  49. package/dist/handlers/index.d.ts +4 -0
  50. package/dist/handlers/index.js +5 -0
  51. package/dist/index.d.ts +30 -0
  52. package/dist/index.js +32 -0
  53. package/dist/presentations/index.d.ts +4 -0
  54. package/dist/presentations/index.js +5 -0
  55. package/dist/run/index.d.ts +8 -0
  56. package/dist/run/index.js +9 -0
  57. package/dist/run/run.entity.d.ts +82 -0
  58. package/dist/run/run.entity.d.ts.map +1 -0
  59. package/dist/run/run.entity.js +205 -0
  60. package/dist/run/run.entity.js.map +1 -0
  61. package/dist/run/run.enum.d.ts +22 -0
  62. package/dist/run/run.enum.d.ts.map +1 -0
  63. package/dist/run/run.enum.js +45 -0
  64. package/dist/run/run.enum.js.map +1 -0
  65. package/dist/run/run.event.d.ts +290 -0
  66. package/dist/run/run.event.d.ts.map +1 -0
  67. package/dist/run/run.event.js +434 -0
  68. package/dist/run/run.event.js.map +1 -0
  69. package/dist/run/run.handler.d.ts +203 -0
  70. package/dist/run/run.handler.d.ts.map +1 -0
  71. package/dist/run/run.handler.js +83 -0
  72. package/dist/run/run.handler.js.map +1 -0
  73. package/dist/run/run.operation.d.ts +720 -0
  74. package/dist/run/run.operation.d.ts.map +1 -0
  75. package/dist/run/run.operation.js +626 -0
  76. package/dist/run/run.operation.js.map +1 -0
  77. package/dist/run/run.presentation.d.ts +15 -0
  78. package/dist/run/run.presentation.d.ts.map +1 -0
  79. package/dist/run/run.presentation.js +65 -0
  80. package/dist/run/run.presentation.js.map +1 -0
  81. package/dist/run/run.schema.d.ts +416 -0
  82. package/dist/run/run.schema.d.ts.map +1 -0
  83. package/dist/run/run.schema.js +338 -0
  84. package/dist/run/run.schema.js.map +1 -0
  85. package/dist/shared/index.d.ts +4 -0
  86. package/dist/shared/index.js +5 -0
  87. package/dist/shared/mock-agents.d.ts +88 -0
  88. package/dist/shared/mock-agents.d.ts.map +1 -0
  89. package/dist/shared/mock-agents.js +94 -0
  90. package/dist/shared/mock-agents.js.map +1 -0
  91. package/dist/shared/mock-runs.d.ts +120 -0
  92. package/dist/shared/mock-runs.d.ts.map +1 -0
  93. package/dist/shared/mock-runs.js +118 -0
  94. package/dist/shared/mock-runs.js.map +1 -0
  95. package/dist/shared/mock-tools.d.ts +244 -0
  96. package/dist/shared/mock-tools.d.ts.map +1 -0
  97. package/dist/shared/mock-tools.js +181 -0
  98. package/dist/shared/mock-tools.js.map +1 -0
  99. package/dist/tool/index.d.ts +8 -0
  100. package/dist/tool/index.js +9 -0
  101. package/dist/tool/tool.entity.d.ts +42 -0
  102. package/dist/tool/tool.entity.d.ts.map +1 -0
  103. package/dist/tool/tool.entity.js +105 -0
  104. package/dist/tool/tool.entity.js.map +1 -0
  105. package/dist/tool/tool.enum.d.ts +18 -0
  106. package/dist/tool/tool.enum.d.ts.map +1 -0
  107. package/dist/tool/tool.enum.js +35 -0
  108. package/dist/tool/tool.enum.js.map +1 -0
  109. package/dist/tool/tool.event.d.ts +103 -0
  110. package/dist/tool/tool.event.d.ts.map +1 -0
  111. package/dist/tool/tool.event.js +159 -0
  112. package/dist/tool/tool.event.js.map +1 -0
  113. package/dist/tool/tool.handler.d.ts +315 -0
  114. package/dist/tool/tool.handler.d.ts.map +1 -0
  115. package/dist/tool/tool.handler.js +87 -0
  116. package/dist/tool/tool.handler.js.map +1 -0
  117. package/dist/tool/tool.operation.d.ts +411 -0
  118. package/dist/tool/tool.operation.d.ts.map +1 -0
  119. package/dist/tool/tool.operation.js +406 -0
  120. package/dist/tool/tool.operation.js.map +1 -0
  121. package/dist/tool/tool.presentation.d.ts +15 -0
  122. package/dist/tool/tool.presentation.d.ts.map +1 -0
  123. package/dist/tool/tool.presentation.js +65 -0
  124. package/dist/tool/tool.presentation.js.map +1 -0
  125. package/dist/tool/tool.schema.d.ts +218 -0
  126. package/dist/tool/tool.schema.d.ts.map +1 -0
  127. package/dist/tool/tool.schema.js +236 -0
  128. package/dist/tool/tool.schema.js.map +1 -0
  129. package/example.ts +1 -0
  130. package/package.json +123 -0
  131. package/src/agent/agent.entity.ts +137 -0
  132. package/src/agent/agent.enum.ts +31 -0
  133. package/src/agent/agent.event.ts +142 -0
  134. package/src/agent/agent.handler.ts +178 -0
  135. package/src/agent/agent.operation.ts +444 -0
  136. package/src/agent/agent.presentation.ts +81 -0
  137. package/src/agent/agent.schema.ts +214 -0
  138. package/src/agent/index.ts +67 -0
  139. package/src/agent.feature.ts +146 -0
  140. package/src/docs/agent-console.docblock.ts +97 -0
  141. package/src/docs/index.ts +1 -0
  142. package/src/example.ts +34 -0
  143. package/src/handlers/index.ts +27 -0
  144. package/src/index.ts +27 -0
  145. package/src/presentations/index.ts +26 -0
  146. package/src/run/index.ts +68 -0
  147. package/src/run/run.entity.ts +175 -0
  148. package/src/run/run.enum.ts +43 -0
  149. package/src/run/run.event.ts +264 -0
  150. package/src/run/run.handler.ts +138 -0
  151. package/src/run/run.operation.ts +524 -0
  152. package/src/run/run.presentation.ts +55 -0
  153. package/src/run/run.schema.ts +169 -0
  154. package/src/shared/index.ts +6 -0
  155. package/src/shared/mock-agents.ts +81 -0
  156. package/src/shared/mock-runs.ts +107 -0
  157. package/src/shared/mock-tools.ts +145 -0
  158. package/src/tool/index.ts +60 -0
  159. package/src/tool/tool.entity.ts +99 -0
  160. package/src/tool/tool.enum.ts +32 -0
  161. package/src/tool/tool.event.ts +119 -0
  162. package/src/tool/tool.handler.ts +154 -0
  163. package/src/tool/tool.operation.ts +366 -0
  164. package/src/tool/tool.presentation.ts +56 -0
  165. package/src/tool/tool.schema.ts +133 -0
  166. package/tsconfig.json +10 -0
  167. package/tsconfig.tsbuildinfo +1 -0
  168. package/tsdown.config.js +7 -0
@@ -0,0 +1,119 @@
1
+ import { defineEvent, defineSchemaModel } from '@contractspec/lib.contracts';
2
+ import { ScalarTypeEnum } from '@contractspec/lib.schema';
3
+
4
+ const OWNERS = ['@agent-console-team'] as const;
5
+
6
+ /**
7
+ * Payload for tool created event.
8
+ */
9
+ const ToolCreatedPayload = defineSchemaModel({
10
+ name: 'ToolCreatedPayload',
11
+ description: 'Payload for tool created event',
12
+ fields: {
13
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
14
+ organizationId: {
15
+ type: ScalarTypeEnum.String_unsecure(),
16
+ isOptional: false,
17
+ },
18
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
19
+ slug: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
20
+ category: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
21
+ implementationType: {
22
+ type: ScalarTypeEnum.String_unsecure(),
23
+ isOptional: false,
24
+ },
25
+ createdById: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
26
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
27
+ },
28
+ });
29
+
30
+ /**
31
+ * ToolCreatedEvent - A new tool was created.
32
+ */
33
+ export const ToolCreatedEvent = defineEvent({
34
+ meta: {
35
+ key: 'agent.tool.created',
36
+ version: 1,
37
+ description: 'A new AI tool was created.',
38
+ stability: 'stable',
39
+ owners: [...OWNERS],
40
+ tags: ['tool', 'created'],
41
+ },
42
+ payload: ToolCreatedPayload,
43
+ });
44
+
45
+ /**
46
+ * Payload for tool updated event.
47
+ */
48
+ const ToolUpdatedPayload = defineSchemaModel({
49
+ name: 'ToolUpdatedPayload',
50
+ description: 'Payload for tool updated event',
51
+ fields: {
52
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
53
+ organizationId: {
54
+ type: ScalarTypeEnum.String_unsecure(),
55
+ isOptional: false,
56
+ },
57
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
58
+ status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
+ updatedFields: {
60
+ type: ScalarTypeEnum.String_unsecure(),
61
+ isArray: true,
62
+ isOptional: false,
63
+ },
64
+ updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
65
+ },
66
+ });
67
+
68
+ /**
69
+ * ToolUpdatedEvent - A tool was updated.
70
+ */
71
+ export const ToolUpdatedEvent = defineEvent({
72
+ meta: {
73
+ key: 'agent.tool.updated',
74
+ version: 1,
75
+ description: 'An AI tool configuration was updated.',
76
+ stability: 'stable',
77
+ owners: [...OWNERS],
78
+ tags: ['tool', 'updated'],
79
+ },
80
+ payload: ToolUpdatedPayload,
81
+ });
82
+
83
+ /**
84
+ * Payload for tool status changed event.
85
+ */
86
+ const ToolStatusChangedPayload = defineSchemaModel({
87
+ name: 'ToolStatusChangedPayload',
88
+ description: 'Payload for tool status changed event',
89
+ fields: {
90
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
91
+ organizationId: {
92
+ type: ScalarTypeEnum.String_unsecure(),
93
+ isOptional: false,
94
+ },
95
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
96
+ previousStatus: {
97
+ type: ScalarTypeEnum.String_unsecure(),
98
+ isOptional: false,
99
+ },
100
+ newStatus: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
101
+ changedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
102
+ },
103
+ });
104
+
105
+ /**
106
+ * ToolStatusChangedEvent - A tool's status was changed.
107
+ */
108
+ export const ToolStatusChangedEvent = defineEvent({
109
+ meta: {
110
+ key: 'agent.tool.statusChanged',
111
+ version: 1,
112
+ description:
113
+ 'An AI tool status was changed (activated, deprecated, disabled).',
114
+ stability: 'stable',
115
+ owners: [...OWNERS],
116
+ tags: ['tool', 'status'],
117
+ },
118
+ payload: ToolStatusChangedPayload,
119
+ });
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Mock handlers for Tool contracts.
3
+ */
4
+ import { MOCK_TOOLS } from '../shared/mock-tools';
5
+
6
+ export interface ListToolsInput {
7
+ organizationId: string;
8
+ category?:
9
+ | 'RETRIEVAL'
10
+ | 'COMPUTATION'
11
+ | 'COMMUNICATION'
12
+ | 'INTEGRATION'
13
+ | 'UTILITY'
14
+ | 'CUSTOM';
15
+ status?: 'DRAFT' | 'ACTIVE' | 'DEPRECATED' | 'DISABLED';
16
+ search?: string;
17
+ limit?: number;
18
+ offset?: number;
19
+ }
20
+
21
+ export interface ToolSummary {
22
+ id: string;
23
+ name: string;
24
+ slug: string;
25
+ description: string;
26
+ category:
27
+ | 'RETRIEVAL'
28
+ | 'COMPUTATION'
29
+ | 'COMMUNICATION'
30
+ | 'INTEGRATION'
31
+ | 'UTILITY'
32
+ | 'CUSTOM';
33
+ status: 'DRAFT' | 'ACTIVE' | 'DEPRECATED' | 'DISABLED';
34
+ version: string;
35
+ createdAt: Date;
36
+ }
37
+
38
+ export interface ListToolsOutput {
39
+ items: ToolSummary[];
40
+ total: number;
41
+ hasMore: boolean;
42
+ }
43
+
44
+ /**
45
+ * Mock handler for ListToolsQuery.
46
+ */
47
+ export async function mockListToolsHandler(
48
+ input: ListToolsInput
49
+ ): Promise<ListToolsOutput> {
50
+ const {
51
+ organizationId,
52
+ category,
53
+ status,
54
+ search,
55
+ limit = 20,
56
+ offset = 0,
57
+ } = input;
58
+
59
+ let filtered = MOCK_TOOLS.filter((t) => t.organizationId === organizationId);
60
+ if (category) filtered = filtered.filter((t) => t.category === category);
61
+ if (status) filtered = filtered.filter((t) => t.status === status);
62
+ if (search) {
63
+ const q = search.toLowerCase();
64
+ filtered = filtered.filter(
65
+ (t) =>
66
+ t.name.toLowerCase().includes(q) ||
67
+ t.description.toLowerCase().includes(q)
68
+ );
69
+ }
70
+
71
+ const total = filtered.length;
72
+ const items = filtered.slice(offset, offset + limit).map((t) => ({
73
+ id: t.id,
74
+ name: t.name,
75
+ slug: t.slug,
76
+ description: t.description,
77
+ category: t.category,
78
+ status: t.status,
79
+ version: t.version,
80
+ createdAt: t.createdAt,
81
+ }));
82
+
83
+ return { items, total, hasMore: offset + limit < total };
84
+ }
85
+
86
+ /**
87
+ * Mock handler for GetToolQuery.
88
+ */
89
+ export async function mockGetToolHandler(input: { toolId: string }) {
90
+ const tool = MOCK_TOOLS.find((t) => t.id === input.toolId);
91
+ if (!tool) throw new Error('TOOL_NOT_FOUND');
92
+ return tool;
93
+ }
94
+
95
+ /**
96
+ * Mock handler for CreateToolCommand.
97
+ */
98
+ export async function mockCreateToolHandler(input: {
99
+ organizationId: string;
100
+ name: string;
101
+ slug: string;
102
+ description: string;
103
+ implementationType: 'http' | 'function' | 'workflow';
104
+ }) {
105
+ const exists = MOCK_TOOLS.some(
106
+ (t) => t.organizationId === input.organizationId && t.slug === input.slug
107
+ );
108
+ if (exists) throw new Error('SLUG_EXISTS');
109
+ return {
110
+ id: `tool-${Date.now()}`,
111
+ name: input.name,
112
+ slug: input.slug,
113
+ status: 'DRAFT' as const,
114
+ };
115
+ }
116
+
117
+ /**
118
+ * Mock handler for UpdateToolCommand.
119
+ */
120
+ export async function mockUpdateToolHandler(input: {
121
+ toolId: string;
122
+ name?: string;
123
+ status?: 'DRAFT' | 'ACTIVE' | 'DEPRECATED' | 'DISABLED';
124
+ }) {
125
+ const tool = MOCK_TOOLS.find((t) => t.id === input.toolId);
126
+ if (!tool) throw new Error('TOOL_NOT_FOUND');
127
+ return {
128
+ id: tool.id,
129
+ name: input.name ?? tool.name,
130
+ status: input.status ?? tool.status,
131
+ updatedAt: new Date(),
132
+ };
133
+ }
134
+
135
+ /**
136
+ * Mock handler for TestToolCommand.
137
+ */
138
+ export async function mockTestToolHandler(input: {
139
+ toolId: string;
140
+ testInput: Record<string, unknown>;
141
+ }) {
142
+ const tool = MOCK_TOOLS.find((t) => t.id === input.toolId);
143
+ if (!tool) throw new Error('TOOL_NOT_FOUND');
144
+
145
+ // Simulate tool execution
146
+ const startTime = Date.now();
147
+ await new Promise((resolve) => setTimeout(resolve, 100));
148
+
149
+ return {
150
+ success: true,
151
+ output: { result: 'Test successful', input: input.testInput },
152
+ durationMs: Date.now() - startTime,
153
+ };
154
+ }
@@ -0,0 +1,366 @@
1
+ import {
2
+ defineCommand,
3
+ defineQuery,
4
+ } from '@contractspec/lib.contracts/operations';
5
+ import { defineSchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';
6
+ import { ToolCategoryEnum, ToolStatusEnum } from './tool.enum';
7
+ import {
8
+ CreateToolInputModel,
9
+ ToolModel,
10
+ ToolSummaryModel,
11
+ UpdateToolInputModel,
12
+ } from './tool.schema';
13
+
14
+ const OWNERS = ['@agent-console-team'] as const;
15
+
16
+ /**
17
+ * CreateToolCommand - Creates a new tool definition.
18
+ */
19
+ export const CreateToolCommand = defineCommand({
20
+ meta: {
21
+ key: 'agent.tool.create',
22
+ version: 1,
23
+ stability: 'stable',
24
+ owners: [...OWNERS],
25
+ tags: ['tool', 'create'],
26
+ description: 'Creates a new AI tool definition.',
27
+ goal: 'Allow users to define new tools that agents can use.',
28
+ context: 'Called from the tool builder UI when creating a new tool.',
29
+ },
30
+ io: {
31
+ input: CreateToolInputModel,
32
+ output: defineSchemaModel({
33
+ name: 'CreateToolOutput',
34
+ fields: {
35
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
36
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
37
+ slug: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
38
+ status: { type: ToolStatusEnum, isOptional: false },
39
+ },
40
+ }),
41
+ errors: {
42
+ SLUG_EXISTS: {
43
+ description: 'A tool with this slug already exists in the organization',
44
+ http: 409,
45
+ gqlCode: 'SLUG_EXISTS',
46
+ when: 'Slug is already taken',
47
+ },
48
+ },
49
+ },
50
+ policy: { auth: 'user' },
51
+ sideEffects: {
52
+ emits: [
53
+ {
54
+ key: 'tool.created',
55
+ version: 1,
56
+ stability: 'stable',
57
+ owners: [...OWNERS],
58
+ tags: ['tool', 'created'],
59
+ when: 'Tool is successfully created',
60
+ payload: ToolSummaryModel,
61
+ },
62
+ ],
63
+ audit: ['tool.created'],
64
+ },
65
+ acceptance: {
66
+ scenarios: [
67
+ {
68
+ key: 'create-tool-happy-path',
69
+ given: ['User is authenticated', 'Organization exists'],
70
+ when: ['User submits valid tool configuration'],
71
+ then: ['New tool is created', 'ToolCreated event is emitted'],
72
+ },
73
+ {
74
+ key: 'create-tool-slug-conflict',
75
+ given: ['Tool with same slug exists'],
76
+ when: ['User submits tool with duplicate slug'],
77
+ then: ['SLUG_EXISTS error is returned'],
78
+ },
79
+ ],
80
+ examples: [
81
+ {
82
+ key: 'create-api-tool',
83
+ input: {
84
+ name: 'Weather API',
85
+ slug: 'weather-api',
86
+ category: 'api',
87
+ description: 'Fetches weather data',
88
+ },
89
+ output: {
90
+ id: 'tool-123',
91
+ name: 'Weather API',
92
+ slug: 'weather-api',
93
+ status: 'draft',
94
+ },
95
+ },
96
+ ],
97
+ },
98
+ });
99
+
100
+ /**
101
+ * UpdateToolCommand - Updates an existing tool.
102
+ */
103
+ export const UpdateToolCommand = defineCommand({
104
+ meta: {
105
+ key: 'agent.tool.update',
106
+ version: 1,
107
+ stability: 'stable',
108
+ owners: [...OWNERS],
109
+ tags: ['tool', 'update'],
110
+ description: 'Updates an existing AI tool definition.',
111
+ goal: 'Allow users to modify tool settings and configuration.',
112
+ context: 'Called from the tool settings UI.',
113
+ },
114
+ io: {
115
+ input: UpdateToolInputModel,
116
+ output: defineSchemaModel({
117
+ name: 'UpdateToolOutput',
118
+ fields: {
119
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
120
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
121
+ status: { type: ToolStatusEnum, isOptional: false },
122
+ updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
123
+ },
124
+ }),
125
+ errors: {
126
+ TOOL_NOT_FOUND: {
127
+ description: 'The specified tool does not exist',
128
+ http: 404,
129
+ gqlCode: 'TOOL_NOT_FOUND',
130
+ when: 'Tool ID is invalid',
131
+ },
132
+ },
133
+ },
134
+ policy: { auth: 'user' },
135
+ sideEffects: {
136
+ emits: [
137
+ {
138
+ key: 'tool.updated',
139
+ version: 1,
140
+ stability: 'stable',
141
+ owners: [...OWNERS],
142
+ tags: ['tool', 'updated'],
143
+ when: 'Tool is updated',
144
+ payload: ToolSummaryModel,
145
+ },
146
+ ],
147
+ audit: ['tool.updated'],
148
+ },
149
+ acceptance: {
150
+ scenarios: [
151
+ {
152
+ key: 'update-tool-happy-path',
153
+ given: ['Tool exists', 'User owns the tool'],
154
+ when: ['User submits updated configuration'],
155
+ then: ['Tool is updated', 'ToolUpdated event is emitted'],
156
+ },
157
+ ],
158
+ examples: [
159
+ {
160
+ key: 'update-description',
161
+ input: { toolId: 'tool-123', description: 'Updated weather API tool' },
162
+ output: {
163
+ id: 'tool-123',
164
+ name: 'Weather API',
165
+ status: 'draft',
166
+ updatedAt: '2025-01-01T00:00:00Z',
167
+ },
168
+ },
169
+ ],
170
+ },
171
+ });
172
+
173
+ /**
174
+ * GetToolQuery - Retrieves a tool by ID.
175
+ */
176
+ export const GetToolQuery = defineQuery({
177
+ meta: {
178
+ key: 'agent.tool.get',
179
+ version: 1,
180
+ stability: 'stable',
181
+ owners: [...OWNERS],
182
+ tags: ['tool', 'get'],
183
+ description: 'Retrieves a tool by its ID.',
184
+ goal: 'View detailed tool configuration.',
185
+ context: 'Called when viewing tool details or editing.',
186
+ },
187
+ io: {
188
+ input: defineSchemaModel({
189
+ name: 'GetToolInput',
190
+ fields: {
191
+ toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
192
+ },
193
+ }),
194
+ output: ToolModel,
195
+ errors: {
196
+ TOOL_NOT_FOUND: {
197
+ description: 'The specified tool does not exist',
198
+ http: 404,
199
+ gqlCode: 'TOOL_NOT_FOUND',
200
+ when: 'Tool ID is invalid',
201
+ },
202
+ },
203
+ },
204
+ policy: { auth: 'user' },
205
+ acceptance: {
206
+ scenarios: [
207
+ {
208
+ key: 'get-tool-happy-path',
209
+ given: ['Tool exists'],
210
+ when: ['User requests tool by ID'],
211
+ then: ['Tool details are returned'],
212
+ },
213
+ ],
214
+ examples: [
215
+ {
216
+ key: 'get-basic',
217
+ input: { toolId: 'tool-123' },
218
+ output: {
219
+ id: 'tool-123',
220
+ name: 'Weather API',
221
+ status: 'active',
222
+ category: 'api',
223
+ },
224
+ },
225
+ ],
226
+ },
227
+ });
228
+
229
+ /**
230
+ * ListToolsQuery - Lists tools for an organization.
231
+ */
232
+ export const ListToolsQuery = defineQuery({
233
+ meta: {
234
+ key: 'agent.tool.list',
235
+ version: 1,
236
+ stability: 'stable',
237
+ owners: [...OWNERS],
238
+ tags: ['tool', 'list'],
239
+ description: 'Lists tools for an organization with optional filtering.',
240
+ goal: 'Browse and search available tools.',
241
+ context: 'Tool list/dashboard view.',
242
+ },
243
+ io: {
244
+ input: defineSchemaModel({
245
+ name: 'ListToolsInput',
246
+ fields: {
247
+ organizationId: {
248
+ type: ScalarTypeEnum.String_unsecure(),
249
+ isOptional: false,
250
+ },
251
+ category: { type: ToolCategoryEnum, isOptional: true },
252
+ status: { type: ToolStatusEnum, isOptional: true },
253
+ search: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
254
+ limit: {
255
+ type: ScalarTypeEnum.Int_unsecure(),
256
+ isOptional: true,
257
+ defaultValue: 20,
258
+ },
259
+ offset: {
260
+ type: ScalarTypeEnum.Int_unsecure(),
261
+ isOptional: true,
262
+ defaultValue: 0,
263
+ },
264
+ },
265
+ }),
266
+ output: defineSchemaModel({
267
+ name: 'ListToolsOutput',
268
+ fields: {
269
+ items: { type: ToolSummaryModel, isArray: true, isOptional: false },
270
+ total: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
271
+ hasMore: { type: ScalarTypeEnum.Boolean(), isOptional: false },
272
+ },
273
+ }),
274
+ },
275
+ policy: { auth: 'user' },
276
+ acceptance: {
277
+ scenarios: [
278
+ {
279
+ key: 'list-tools-happy-path',
280
+ given: ['Organization has tools'],
281
+ when: ['User lists tools'],
282
+ then: ['Paginated list of tools is returned'],
283
+ },
284
+ ],
285
+ examples: [
286
+ {
287
+ key: 'list-by-category',
288
+ input: { organizationId: 'org-123', category: 'api', limit: 10 },
289
+ output: { items: [], total: 0, hasMore: false },
290
+ },
291
+ ],
292
+ },
293
+ });
294
+
295
+ /**
296
+ * TestToolCommand - Tests a tool with sample input.
297
+ */
298
+ export const TestToolCommand = defineCommand({
299
+ meta: {
300
+ key: 'agent.tool.test',
301
+ version: 1,
302
+ stability: 'stable',
303
+ owners: [...OWNERS],
304
+ tags: ['tool', 'test'],
305
+ description: 'Tests a tool with sample input to verify it works correctly.',
306
+ goal: 'Validate tool configuration before deployment.',
307
+ context: 'Tool builder UI - test panel.',
308
+ },
309
+ io: {
310
+ input: defineSchemaModel({
311
+ name: 'TestToolInput',
312
+ fields: {
313
+ toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
314
+ testInput: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
315
+ },
316
+ }),
317
+ output: defineSchemaModel({
318
+ name: 'TestToolOutput',
319
+ fields: {
320
+ success: { type: ScalarTypeEnum.Boolean(), isOptional: false },
321
+ output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
322
+ error: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
323
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
324
+ },
325
+ }),
326
+ errors: {
327
+ TOOL_NOT_FOUND: {
328
+ description: 'The specified tool does not exist',
329
+ http: 404,
330
+ gqlCode: 'TOOL_NOT_FOUND',
331
+ when: 'Tool ID is invalid',
332
+ },
333
+ TOOL_EXECUTION_ERROR: {
334
+ description: 'Tool execution failed',
335
+ http: 500,
336
+ gqlCode: 'TOOL_EXECUTION_ERROR',
337
+ when: 'Tool returns an error',
338
+ },
339
+ },
340
+ },
341
+ policy: { auth: 'user' },
342
+ sideEffects: { audit: ['tool.tested'] },
343
+ acceptance: {
344
+ scenarios: [
345
+ {
346
+ key: 'test-tool-success',
347
+ given: ['Tool exists', 'Tool is configured correctly'],
348
+ when: ['User runs test with valid input'],
349
+ then: ['Tool executes successfully', 'Output is returned'],
350
+ },
351
+ {
352
+ key: 'test-tool-failure',
353
+ given: ['Tool exists', 'Tool has configuration error'],
354
+ when: ['User runs test'],
355
+ then: ['TOOL_EXECUTION_ERROR is returned'],
356
+ },
357
+ ],
358
+ examples: [
359
+ {
360
+ key: 'test-weather-api',
361
+ input: { toolId: 'tool-123', testInput: { city: 'Paris' } },
362
+ output: { success: true, output: { temperature: 22 }, durationMs: 150 },
363
+ },
364
+ ],
365
+ },
366
+ });
@@ -0,0 +1,56 @@
1
+ import type { PresentationSpec } from '@contractspec/lib.contracts';
2
+ import { StabilityEnum } from '@contractspec/lib.contracts';
3
+ import { ToolSummaryModel } from './tool.schema';
4
+
5
+ /**
6
+ * Presentation for displaying a list of tools.
7
+ */
8
+ export const ToolListPresentation: PresentationSpec = {
9
+ meta: {
10
+ key: 'agent-console.tool.list',
11
+ version: 1,
12
+ title: 'Tool List',
13
+ description:
14
+ 'List view of AI tools with category, status, and version info',
15
+ goal: 'Provide an overview of all available tools for agents.',
16
+ context: 'Tool management dashboard.',
17
+ domain: 'agent-console',
18
+ owners: ['@agent-console-team'],
19
+ tags: ['tool', 'list', 'dashboard'],
20
+ stability: StabilityEnum.Experimental,
21
+ },
22
+ source: {
23
+ type: 'component',
24
+ framework: 'react',
25
+ componentKey: 'ToolListView',
26
+ props: ToolSummaryModel,
27
+ },
28
+ targets: ['react', 'markdown', 'application/json'],
29
+ policy: { flags: ['agent-console.enabled'] },
30
+ };
31
+
32
+ /**
33
+ * Presentation for tool detail view.
34
+ */
35
+ export const ToolDetailPresentation: PresentationSpec = {
36
+ meta: {
37
+ key: 'agent-console.tool.detail',
38
+ version: 1,
39
+ title: 'Tool Details',
40
+ description:
41
+ 'Detailed view of an AI tool with configuration and test panel',
42
+ goal: 'Allow users to inspect and test a specific tool.',
43
+ context: 'Detailed view of a tool.',
44
+ domain: 'agent-console',
45
+ owners: ['@agent-console-team'],
46
+ tags: ['tool', 'detail'],
47
+ stability: StabilityEnum.Experimental,
48
+ },
49
+ source: {
50
+ type: 'component',
51
+ framework: 'react',
52
+ componentKey: 'ToolDetailView',
53
+ },
54
+ targets: ['react', 'markdown'],
55
+ policy: { flags: ['agent-console.enabled'] },
56
+ };