@agentic-kit/pi 0.17.0 → 0.18.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 (136) hide show
  1. package/README.md +5 -7
  2. package/confirm-gate.d.ts +1 -2
  3. package/esm/confirm-gate.d.ts +1 -2
  4. package/esm/host.d.ts +5 -110
  5. package/esm/host.js +5 -18
  6. package/esm/index.d.ts +17 -9
  7. package/esm/index.js +20 -38
  8. package/esm/pi-tool.d.ts +16 -0
  9. package/esm/pi-tool.js +32 -0
  10. package/host.d.ts +5 -110
  11. package/host.js +10 -22
  12. package/index.d.ts +17 -9
  13. package/index.js +47 -62
  14. package/package.json +6 -10
  15. package/pi-tool.d.ts +16 -0
  16. package/pi-tool.js +36 -0
  17. package/app-workspace.d.ts +0 -16
  18. package/app-workspace.js +0 -145
  19. package/context.d.ts +0 -62
  20. package/context.js +0 -282
  21. package/db-probe.d.ts +0 -30
  22. package/db-probe.js +0 -50
  23. package/esm/app-workspace.d.ts +0 -16
  24. package/esm/app-workspace.js +0 -134
  25. package/esm/context.d.ts +0 -62
  26. package/esm/context.js +0 -270
  27. package/esm/db-probe.d.ts +0 -30
  28. package/esm/db-probe.js +0 -47
  29. package/esm/policy/add-policies-to-table.d.ts +0 -26
  30. package/esm/policy/add-policies-to-table.js +0 -66
  31. package/esm/policy/provision-helpers.d.ts +0 -38
  32. package/esm/policy/provision-helpers.js +0 -50
  33. package/esm/provision-database/credential.d.ts +0 -14
  34. package/esm/provision-database/credential.js +0 -19
  35. package/esm/provision-database/env-file.d.ts +0 -37
  36. package/esm/provision-database/env-file.js +0 -85
  37. package/esm/provision-database/manifest.d.ts +0 -10
  38. package/esm/provision-database/manifest.js +0 -48
  39. package/esm/provision-database/pg-fixups.d.ts +0 -16
  40. package/esm/provision-database/pg-fixups.js +0 -132
  41. package/esm/provision-database/preset-match.d.ts +0 -13
  42. package/esm/provision-database/preset-match.js +0 -66
  43. package/esm/provision-database/presets.d.ts +0 -4
  44. package/esm/provision-database/presets.js +0 -13
  45. package/esm/provision-database/request-database.d.ts +0 -61
  46. package/esm/provision-database/request-database.js +0 -130
  47. package/esm/provision-database/resolve.d.ts +0 -27
  48. package/esm/provision-database/resolve.js +0 -49
  49. package/esm/records/meta.d.ts +0 -41
  50. package/esm/records/meta.js +0 -167
  51. package/esm/run-codegen/barrels.d.ts +0 -3
  52. package/esm/run-codegen/barrels.js +0 -48
  53. package/esm/run-codegen/endpoints.d.ts +0 -8
  54. package/esm/run-codegen/endpoints.js +0 -46
  55. package/esm/schema-resolve.d.ts +0 -23
  56. package/esm/schema-resolve.js +0 -69
  57. package/esm/tool-schema.d.ts +0 -3
  58. package/esm/tool-schema.js +0 -10
  59. package/esm/tools/add-policies.d.ts +0 -8
  60. package/esm/tools/add-policies.js +0 -96
  61. package/esm/tools/add-records.d.ts +0 -14
  62. package/esm/tools/add-records.js +0 -124
  63. package/esm/tools/add-relation-schema.d.ts +0 -30
  64. package/esm/tools/add-relation-schema.js +0 -58
  65. package/esm/tools/add-relation.d.ts +0 -10
  66. package/esm/tools/add-relation.js +0 -91
  67. package/esm/tools/create-api-key.d.ts +0 -18
  68. package/esm/tools/create-api-key.js +0 -216
  69. package/esm/tools/describe-schema.d.ts +0 -18
  70. package/esm/tools/describe-schema.js +0 -132
  71. package/esm/tools/manage-entity-types.d.ts +0 -41
  72. package/esm/tools/manage-entity-types.js +0 -203
  73. package/esm/tools/mutations.d.ts +0 -14
  74. package/esm/tools/mutations.js +0 -235
  75. package/esm/tools/provision-blueprint.d.ts +0 -22
  76. package/esm/tools/provision-blueprint.js +0 -111
  77. package/esm/tools/provision-database.d.ts +0 -14
  78. package/esm/tools/provision-database.js +0 -262
  79. package/esm/tools/run-codegen.d.ts +0 -11
  80. package/esm/tools/run-codegen.js +0 -139
  81. package/esm/tools/templates.d.ts +0 -49
  82. package/esm/tools/templates.js +0 -337
  83. package/policy/add-policies-to-table.d.ts +0 -26
  84. package/policy/add-policies-to-table.js +0 -71
  85. package/policy/provision-helpers.d.ts +0 -38
  86. package/policy/provision-helpers.js +0 -58
  87. package/provision-database/credential.d.ts +0 -14
  88. package/provision-database/credential.js +0 -22
  89. package/provision-database/env-file.d.ts +0 -37
  90. package/provision-database/env-file.js +0 -91
  91. package/provision-database/manifest.d.ts +0 -10
  92. package/provision-database/manifest.js +0 -56
  93. package/provision-database/pg-fixups.d.ts +0 -16
  94. package/provision-database/pg-fixups.js +0 -170
  95. package/provision-database/preset-match.d.ts +0 -13
  96. package/provision-database/preset-match.js +0 -70
  97. package/provision-database/presets.d.ts +0 -4
  98. package/provision-database/presets.js +0 -17
  99. package/provision-database/request-database.d.ts +0 -61
  100. package/provision-database/request-database.js +0 -134
  101. package/provision-database/resolve.d.ts +0 -27
  102. package/provision-database/resolve.js +0 -53
  103. package/records/meta.d.ts +0 -41
  104. package/records/meta.js +0 -172
  105. package/run-codegen/barrels.d.ts +0 -3
  106. package/run-codegen/barrels.js +0 -54
  107. package/run-codegen/endpoints.d.ts +0 -8
  108. package/run-codegen/endpoints.js +0 -51
  109. package/schema-resolve.d.ts +0 -23
  110. package/schema-resolve.js +0 -75
  111. package/tool-schema.d.ts +0 -3
  112. package/tool-schema.js +0 -13
  113. package/tools/add-policies.d.ts +0 -8
  114. package/tools/add-policies.js +0 -99
  115. package/tools/add-records.d.ts +0 -14
  116. package/tools/add-records.js +0 -127
  117. package/tools/add-relation-schema.d.ts +0 -30
  118. package/tools/add-relation-schema.js +0 -62
  119. package/tools/add-relation.d.ts +0 -10
  120. package/tools/add-relation.js +0 -94
  121. package/tools/create-api-key.d.ts +0 -18
  122. package/tools/create-api-key.js +0 -222
  123. package/tools/describe-schema.d.ts +0 -18
  124. package/tools/describe-schema.js +0 -135
  125. package/tools/manage-entity-types.d.ts +0 -41
  126. package/tools/manage-entity-types.js +0 -208
  127. package/tools/mutations.d.ts +0 -14
  128. package/tools/mutations.js +0 -238
  129. package/tools/provision-blueprint.d.ts +0 -22
  130. package/tools/provision-blueprint.js +0 -114
  131. package/tools/provision-database.d.ts +0 -14
  132. package/tools/provision-database.js +0 -268
  133. package/tools/run-codegen.d.ts +0 -11
  134. package/tools/run-codegen.js +0 -143
  135. package/tools/templates.d.ts +0 -49
  136. package/tools/templates.js +0 -341
@@ -1,135 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.describeSchemaTool = void 0;
4
- const harness_1 = require("@agentic-kit/harness");
5
- const zod_1 = require("zod");
6
- const context_1 = require("../context");
7
- const tool_schema_1 = require("../tool-schema");
8
- const ParamZod = zod_1.z.object({});
9
- const ParamSchema = (0, tool_schema_1.toolSchema)(ParamZod);
10
- function toDefaultValueString(value) {
11
- if (value == null)
12
- return null;
13
- if (typeof value === 'string')
14
- return value;
15
- return JSON.stringify(value);
16
- }
17
- function formatText(details) {
18
- const lines = [];
19
- if (details.tables.length === 0) {
20
- lines.push('No application tables yet.');
21
- }
22
- else {
23
- lines.push(`Tables (${details.tables.length}):`);
24
- for (const table of details.tables) {
25
- lines.push(` ${table.name}`);
26
- for (const field of table.fields) {
27
- const req = field.isRequired ? ' required' : '';
28
- const def = field.defaultValue != null ? ` default=${field.defaultValue}` : '';
29
- lines.push(` - ${field.name}: ${field.type}${req}${def}`);
30
- }
31
- if (table.policies.length > 0) {
32
- lines.push(` policies: ${table.policies.join(', ')}`);
33
- }
34
- }
35
- }
36
- return lines.join('\n');
37
- }
38
- exports.describeSchemaTool = {
39
- name: 'describe_schema',
40
- label: 'Describe schema',
41
- description: 'Inspect the current Constructive database schema for this project: application tables with their fields (name, type, required, default). Read-only.',
42
- promptSnippet: 'describe_schema: list the project database tables and their fields. Read-only — call before modifying schema.',
43
- parameters: ParamSchema,
44
- async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
45
- const resolved = await (0, context_1.resolveProjectContext)(ctx.cwd);
46
- if (!resolved.context) {
47
- return {
48
- content: [{ type: 'text', text: resolved.reason }],
49
- details: { tables: [] },
50
- };
51
- }
52
- const { api, databaseId } = resolved.context;
53
- const tablesResult = await api.table
54
- .findMany({
55
- select: { id: true, name: true, category: true },
56
- where: {
57
- databaseId: { equalTo: databaseId },
58
- or: [{ category: { equalTo: 'APP' } }, { name: { equalTo: 'users' } }],
59
- },
60
- orderBy: ['NAME_ASC'],
61
- })
62
- .execute();
63
- if (!tablesResult.ok) {
64
- const message = tablesResult.errors.map((e) => e.message).join('; ');
65
- return {
66
- content: [{ type: 'text', text: `Failed to read schema: ${message}` }],
67
- details: { tables: [] },
68
- };
69
- }
70
- const tableNodes = tablesResult.data.tables?.nodes ?? [];
71
- const tableIds = tableNodes.map((t) => t.id);
72
- const fieldsByTable = new Map();
73
- const policiesByTable = new Map();
74
- if (tableIds.length > 0) {
75
- const [fieldsResult, policiesResult] = await Promise.all([
76
- api.field
77
- .findMany({
78
- select: {
79
- name: true,
80
- type: true,
81
- isRequired: true,
82
- defaultValue: true,
83
- tableId: true,
84
- },
85
- where: { tableId: { in: tableIds } },
86
- })
87
- .execute(),
88
- api.policy
89
- .findMany({
90
- select: { tableId: true, policyType: true },
91
- where: { tableId: { in: tableIds } },
92
- })
93
- .execute(),
94
- ]);
95
- if (!fieldsResult.ok) {
96
- const message = fieldsResult.errors.map((e) => e.message).join('; ');
97
- return {
98
- content: [{ type: 'text', text: `Failed to read fields: ${message}` }],
99
- details: { tables: [] },
100
- };
101
- }
102
- for (const field of fieldsResult.data.fields?.nodes ?? []) {
103
- const list = fieldsByTable.get(field.tableId) ?? [];
104
- list.push({
105
- name: field.name,
106
- type: (0, harness_1.fieldTypeToTypeName)(field.type),
107
- isRequired: Boolean(field.isRequired),
108
- defaultValue: toDefaultValueString(field.defaultValue),
109
- });
110
- fieldsByTable.set(field.tableId, list);
111
- }
112
- // One policy spans CRUD as several rows; collapse to distinct types per table.
113
- if (policiesResult.ok) {
114
- for (const policy of policiesResult.data.policies?.nodes ?? []) {
115
- if ((0, harness_1.isInternalPolicy)(policy.policyType))
116
- continue;
117
- const list = policiesByTable.get(policy.tableId) ?? [];
118
- if (!list.includes(policy.policyType))
119
- list.push(policy.policyType);
120
- policiesByTable.set(policy.tableId, list);
121
- }
122
- }
123
- }
124
- const tables = tableNodes.map((table) => ({
125
- name: table.name,
126
- fields: fieldsByTable.get(table.id) ?? [],
127
- policies: policiesByTable.get(table.id) ?? [],
128
- }));
129
- const details = { tables };
130
- return {
131
- content: [{ type: 'text', text: formatText(details) }],
132
- details,
133
- };
134
- },
135
- };
@@ -1,41 +0,0 @@
1
- import type { ToolDefinition } from '@earendil-works/pi-coding-agent';
2
- import { z } from 'zod';
3
- declare const ManageEntityTypesZod: z.ZodObject<{
4
- action: z.ZodEnum<{
5
- create: "create";
6
- delete: "delete";
7
- list: "list";
8
- }>;
9
- name: z.ZodOptional<z.ZodString>;
10
- entity_type_id: z.ZodOptional<z.ZodString>;
11
- description: z.ZodOptional<z.ZodString>;
12
- prefix: z.ZodOptional<z.ZodString>;
13
- parent_entity: z.ZodOptional<z.ZodString>;
14
- is_visible: z.ZodOptional<z.ZodBoolean>;
15
- has_invites: z.ZodOptional<z.ZodBoolean>;
16
- has_profiles: z.ZodOptional<z.ZodBoolean>;
17
- has_limits: z.ZodOptional<z.ZodBoolean>;
18
- has_levels: z.ZodOptional<z.ZodBoolean>;
19
- has_storage: z.ZodOptional<z.ZodBoolean>;
20
- }, z.core.$strip>;
21
- declare const ManageEntityTypesSchema: import("typebox/type").TSchema;
22
- export type EntityTypeSummary = {
23
- id: string;
24
- name: string | null;
25
- description: string | null;
26
- prefix: string | null;
27
- parentEntity: string | null;
28
- isVisible: boolean | null;
29
- entityTableName: string | null;
30
- installedModules: string[] | null;
31
- };
32
- export type ManageEntityTypesDetails = {
33
- success: boolean;
34
- message: string;
35
- entityTypes?: EntityTypeSummary[];
36
- };
37
- export declare function defaultPrefix(name: string): string;
38
- type Params = z.infer<typeof ManageEntityTypesZod>;
39
- export declare function validateManageEntityTypes(params: Params): string | null;
40
- export declare const manageEntityTypesTool: ToolDefinition<typeof ManageEntityTypesSchema, ManageEntityTypesDetails>;
41
- export {};
@@ -1,208 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.manageEntityTypesTool = void 0;
4
- exports.defaultPrefix = defaultPrefix;
5
- exports.validateManageEntityTypes = validateManageEntityTypes;
6
- const zod_1 = require("zod");
7
- const context_1 = require("../context");
8
- const tool_schema_1 = require("../tool-schema");
9
- const ManageEntityTypesZod = zod_1.z.object({
10
- action: zod_1.z
11
- .enum(['list', 'create', 'delete'])
12
- .describe('list: show the entity types provisioned in this database. create: provision a new entity type (creates its entity table + membership wiring). delete: remove the provision registration. Registrations are immutable once provisioned — there is no update; to change one, delete it and create a new one.'),
13
- name: zod_1.z.string().describe('Entity type name. Required for create.').optional(),
14
- entity_type_id: zod_1.z
15
- .string()
16
- .describe('Entity type provision id. Required for delete — get it from action "list".')
17
- .optional(),
18
- description: zod_1.z
19
- .string()
20
- .describe('Human-readable description of the entity type. Create only.')
21
- .optional(),
22
- prefix: zod_1.z
23
- .string()
24
- .describe('Table-name prefix for the provisioned tables (e.g. "org" → org table, org_memberships). Create only; defaults to the snake_case of name.')
25
- .optional(),
26
- parent_entity: zod_1.z
27
- .string()
28
- .describe('Parent entity table name, for hierarchical types (e.g. a "team" under an "org"). Create only; the backend defaults it to the root entity (org).')
29
- .optional(),
30
- is_visible: zod_1.z
31
- .boolean()
32
- .describe('Whether the type shows up in end-user entity listings. Create only.')
33
- .optional(),
34
- has_invites: zod_1.z
35
- .boolean()
36
- .describe('Provision an invites module ({prefix}_invites + claimed invites). Create only.')
37
- .optional(),
38
- has_profiles: zod_1.z
39
- .boolean()
40
- .describe('Provision a profiles table for members of this type. Create only.')
41
- .optional(),
42
- has_limits: zod_1.z
43
- .boolean()
44
- .describe('Provision usage-limits tracking for this type. Create only.')
45
- .optional(),
46
- has_levels: zod_1.z
47
- .boolean()
48
- .describe('Provision levels/achievements support for this type. Create only.')
49
- .optional(),
50
- has_storage: zod_1.z
51
- .boolean()
52
- .describe('Provision a storage module (files + buckets tables) for this type. Create only.')
53
- .optional(),
54
- });
55
- const ManageEntityTypesSchema = (0, tool_schema_1.toolSchema)(ManageEntityTypesZod);
56
- const SUMMARY_SELECT = {
57
- id: true,
58
- name: true,
59
- description: true,
60
- prefix: true,
61
- parentEntity: true,
62
- isVisible: true,
63
- outEntityTableName: true,
64
- outInstalledModules: true,
65
- };
66
- function toSummary(row) {
67
- return {
68
- id: row.id,
69
- name: row.name,
70
- description: row.description,
71
- prefix: row.prefix,
72
- parentEntity: row.parentEntity,
73
- isVisible: row.isVisible,
74
- entityTableName: row.outEntityTableName,
75
- installedModules: row.outInstalledModules,
76
- };
77
- }
78
- function formatSummary(s) {
79
- const parts = [
80
- `- ${s.name ?? '?'} (id: ${s.id})`,
81
- ` table: ${s.entityTableName ?? '?'}, prefix: ${s.prefix ?? '?'}`,
82
- ];
83
- if (s.parentEntity)
84
- parts.push(` parent: ${s.parentEntity}`);
85
- if (s.description)
86
- parts.push(` description: ${s.description}`);
87
- if (s.installedModules?.length)
88
- parts.push(` modules: ${s.installedModules.join(', ')}`);
89
- return parts.join('\n');
90
- }
91
- function defaultPrefix(name) {
92
- return name
93
- .trim()
94
- .toLowerCase()
95
- .replace(/[^a-z0-9]+/g, '_')
96
- .replace(/^_+|_+$/g, '');
97
- }
98
- function validateManageEntityTypes(params) {
99
- switch (params.action) {
100
- case 'create':
101
- if (!params.name?.trim())
102
- return 'create requires "name".';
103
- if (params.entity_type_id)
104
- return 'create does not take "entity_type_id" — it mints a new one.';
105
- return null;
106
- case 'delete':
107
- if (!params.entity_type_id)
108
- return 'delete requires "entity_type_id" (use action "list" to find it).';
109
- return null;
110
- default:
111
- return null;
112
- }
113
- }
114
- exports.manageEntityTypesTool = {
115
- name: 'manage_entity_types',
116
- label: 'Manage entity types',
117
- description: 'List, create, or delete entity types in the project database. An entity type (e.g. organization, team, project) provisions its own entity table plus membership wiring, and is the unit that API keys can be scoped to. Registrations are immutable once provisioned — to change one, delete it and create a new one. Deleting removes the registration; the already-provisioned entity table stays in the API schema.',
118
- promptSnippet: 'manage_entity_types: list/create/delete entity types (orgs, teams, …) in the project database. list is free; create/delete are gated.',
119
- parameters: ManageEntityTypesSchema,
120
- async execute(_id, params, _signal, _onUpdate, ctx) {
121
- const resolved = await (0, context_1.resolveProjectContext)(ctx.cwd);
122
- if (!resolved.context) {
123
- return {
124
- content: [{ type: 'text', text: resolved.reason }],
125
- details: { success: false, message: resolved.reason },
126
- };
127
- }
128
- const invalid = validateManageEntityTypes(params);
129
- if (invalid) {
130
- return {
131
- content: [{ type: 'text', text: invalid }],
132
- details: { success: false, message: invalid },
133
- };
134
- }
135
- const { modules, databaseId } = resolved.context;
136
- try {
137
- switch (params.action) {
138
- case 'list': {
139
- const result = await modules.entityTypeProvision
140
- .findMany({
141
- where: { databaseId: { equalTo: databaseId } },
142
- select: SUMMARY_SELECT,
143
- })
144
- .unwrap();
145
- const entityTypes = result.entityTypeProvisions.nodes.map((row) => toSummary(row));
146
- const message = entityTypes.length === 0
147
- ? 'No entity types are provisioned in this database yet.'
148
- : `${entityTypes.length} entity type${entityTypes.length === 1 ? '' : 's'}:\n${entityTypes.map(formatSummary).join('\n')}`;
149
- return {
150
- content: [{ type: 'text', text: message }],
151
- details: { success: true, message, entityTypes },
152
- };
153
- }
154
- case 'create': {
155
- const name = params.name.trim();
156
- const result = await modules.entityTypeProvision
157
- .create({
158
- data: {
159
- databaseId,
160
- name,
161
- prefix: params.prefix?.trim() || defaultPrefix(name),
162
- ...(params.description !== undefined && { description: params.description }),
163
- ...(params.parent_entity !== undefined && { parentEntity: params.parent_entity }),
164
- ...(params.is_visible !== undefined && { isVisible: params.is_visible }),
165
- ...(params.has_invites !== undefined && { hasInvites: params.has_invites }),
166
- ...(params.has_profiles !== undefined && { hasProfiles: params.has_profiles }),
167
- ...(params.has_limits !== undefined && { hasLimits: params.has_limits }),
168
- ...(params.has_levels !== undefined && { hasLevels: params.has_levels }),
169
- ...(params.has_storage && {
170
- storage: [{}],
171
- }),
172
- },
173
- select: SUMMARY_SELECT,
174
- })
175
- .unwrap();
176
- const row = result.createEntityTypeProvision?.entityTypeProvision;
177
- if (!row)
178
- throw new Error('createEntityTypeProvision returned no row.');
179
- const summary = toSummary(row);
180
- const message = `Created entity type "${summary.name}" (id: ${summary.id}) — entity table "${summary.entityTableName}"${summary.installedModules?.length ? `, modules: ${summary.installedModules.join(', ')}` : ''}. Run run_codegen to pull it into the typed SDK.`;
181
- return {
182
- content: [{ type: 'text', text: message }],
183
- details: { success: true, message, entityTypes: [summary] },
184
- };
185
- }
186
- case 'delete': {
187
- const result = await modules.entityTypeProvision
188
- .delete({
189
- where: { id: params.entity_type_id },
190
- select: { id: true, name: true, outEntityTableName: true },
191
- })
192
- .unwrap();
193
- const row = result.deleteEntityTypeProvision?.entityTypeProvision;
194
- const name = row?.name ?? params.entity_type_id;
195
- const message = `Deleted entity type registration "${name}". Note: the provisioned entity table${row?.outEntityTableName ? ` "${row.outEntityTableName}"` : ''} remains in the API schema with its data.`;
196
- return {
197
- content: [{ type: 'text', text: message }],
198
- details: { success: true, message },
199
- };
200
- }
201
- }
202
- }
203
- catch (err) {
204
- const message = err instanceof Error ? err.message : 'Failed to manage entity types';
205
- return { content: [{ type: 'text', text: message }], details: { success: false, message } };
206
- }
207
- },
208
- };
@@ -1,14 +0,0 @@
1
- import type { ToolDefinition } from '@earendil-works/pi-coding-agent';
2
- export type MutationDetails = {
3
- success: boolean;
4
- message: string;
5
- };
6
- declare const DeleteTableSchema: import("typebox/type").TSchema;
7
- export declare const deleteTableTool: ToolDefinition<typeof DeleteTableSchema, MutationDetails>;
8
- declare const CreateFieldSchema: import("typebox/type").TSchema;
9
- export declare const createFieldTool: ToolDefinition<typeof CreateFieldSchema, MutationDetails>;
10
- declare const UpdateFieldSchema: import("typebox/type").TSchema;
11
- export declare const updateFieldTool: ToolDefinition<typeof UpdateFieldSchema, MutationDetails>;
12
- declare const DeleteFieldSchema: import("typebox/type").TSchema;
13
- export declare const deleteFieldTool: ToolDefinition<typeof DeleteFieldSchema, MutationDetails>;
14
- export {};
@@ -1,238 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteFieldTool = exports.updateFieldTool = exports.createFieldTool = exports.deleteTableTool = void 0;
4
- const harness_1 = require("@agentic-kit/harness");
5
- const zod_1 = require("zod");
6
- const context_1 = require("../context");
7
- const schema_resolve_1 = require("../schema-resolve");
8
- const tool_schema_1 = require("../tool-schema");
9
- function ok(message) {
10
- return {
11
- content: [{ type: 'text', text: message }],
12
- details: { success: true, message },
13
- };
14
- }
15
- function fail(message) {
16
- return {
17
- content: [{ type: 'text', text: message }],
18
- details: { success: false, message },
19
- };
20
- }
21
- // ── delete_table ──────────────────────────────────────────────────────────
22
- const DeleteTableZod = zod_1.z.object({
23
- table_name: zod_1.z.string().describe('Name of the table to delete (snake_case)'),
24
- });
25
- const DeleteTableSchema = (0, tool_schema_1.toolSchema)(DeleteTableZod);
26
- exports.deleteTableTool = {
27
- name: 'delete_table',
28
- label: 'Delete table',
29
- description: 'Permanently delete a table and its data from the project database.',
30
- promptSnippet: 'delete_table: drop an existing table by name. Destructive — gated.',
31
- parameters: DeleteTableSchema,
32
- async execute(_id, params, _signal, _onUpdate, ctx) {
33
- const resolved = await (0, context_1.resolveProjectContext)(ctx.cwd);
34
- if (!resolved.context)
35
- return fail(resolved.reason);
36
- try {
37
- const schema = await (0, schema_resolve_1.resolveSchema)(resolved.context);
38
- const table = (0, schema_resolve_1.resolveTable)(schema, params.table_name);
39
- await resolved.context.api.table
40
- .delete({ where: { id: table.id }, select: { id: true } })
41
- .unwrap();
42
- return ok(`Deleted table ${params.table_name}`);
43
- }
44
- catch (err) {
45
- return fail(err instanceof Error ? err.message : 'Failed to delete table');
46
- }
47
- },
48
- };
49
- // ── create_field ──────────────────────────────────────────────────────────
50
- const CreateFieldZod = zod_1.z.object({
51
- table_name: zod_1.z.string().describe('Name of the table to add the field to'),
52
- field_name: zod_1.z.string().describe('Field name in snake_case'),
53
- type: zod_1.z
54
- .string()
55
- .describe('PostgreSQL type: text, integer, smallint, numeric, boolean, date, timestamp, timestamptz, time, json, jsonb, inet, email, url, image, upload'),
56
- is_required: zod_1.z.boolean().describe('Whether the field is NOT NULL. Defaults to false.').optional(),
57
- default_value: zod_1.z
58
- .union([zod_1.z.string(), zod_1.z.null()])
59
- .describe('SQL default expression, e.g. "now()", "\'draft\'"')
60
- .optional(),
61
- is_unique: zod_1.z
62
- .boolean()
63
- .describe('Whether the field has a unique constraint. Defaults to false.')
64
- .optional(),
65
- });
66
- const CreateFieldSchema = (0, tool_schema_1.toolSchema)(CreateFieldZod);
67
- exports.createFieldTool = {
68
- name: 'create_field',
69
- label: 'Create field',
70
- description: 'Add a new field (column) to an existing table in the project database.',
71
- promptSnippet: 'create_field: add a column to an existing table. Gated.',
72
- parameters: CreateFieldSchema,
73
- async execute(_id, params, _signal, _onUpdate, ctx) {
74
- const resolved = await (0, context_1.resolveProjectContext)(ctx.cwd);
75
- if (!resolved.context)
76
- return fail(resolved.reason);
77
- const { api, databaseId } = resolved.context;
78
- try {
79
- const schema = await (0, schema_resolve_1.resolveSchema)(resolved.context);
80
- const table = (0, schema_resolve_1.resolveTable)(schema, params.table_name);
81
- const result = await api.field
82
- .create({
83
- data: {
84
- name: params.field_name,
85
- type: (0, harness_1.toFieldType)(params.type),
86
- tableId: table.id,
87
- databaseId,
88
- isRequired: params.is_required ?? false,
89
- defaultValue: (0, harness_1.toFieldDefault)(params.default_value),
90
- },
91
- select: { id: true, name: true, type: true },
92
- })
93
- .unwrap();
94
- const createdId = result.createField?.field?.id;
95
- if (params.is_unique && createdId) {
96
- try {
97
- await api.uniqueConstraint
98
- .create({
99
- data: {
100
- tableId: table.id,
101
- databaseId,
102
- fieldIds: [createdId],
103
- name: `${table.name}_${params.field_name}_key`,
104
- type: 'u',
105
- },
106
- select: { id: true },
107
- })
108
- .unwrap();
109
- }
110
- catch (err) {
111
- console.warn('Failed to create unique constraint:', err);
112
- }
113
- }
114
- return ok(`Added field ${params.table_name}.${params.field_name}`);
115
- }
116
- catch (err) {
117
- return fail(err instanceof Error ? err.message : 'Failed to create field');
118
- }
119
- },
120
- };
121
- // ── update_field ──────────────────────────────────────────────────────────
122
- const UpdateFieldZod = zod_1.z.object({
123
- table_name: zod_1.z.string().describe('Name of the table containing the field'),
124
- field_name: zod_1.z.string().describe('Current field name'),
125
- new_name: zod_1.z.string().describe('New field name in snake_case (if renaming)').optional(),
126
- new_type: zod_1.z.string().describe('New PostgreSQL type (if changing type)').optional(),
127
- is_required: zod_1.z.boolean().describe('Set NOT NULL constraint').optional(),
128
- default_value: zod_1.z
129
- .union([zod_1.z.string(), zod_1.z.null()])
130
- .describe('New SQL default expression, or null to remove')
131
- .optional(),
132
- is_unique: zod_1.z.boolean().describe('Set or remove unique constraint').optional(),
133
- });
134
- const UpdateFieldSchema = (0, tool_schema_1.toolSchema)(UpdateFieldZod);
135
- exports.updateFieldTool = {
136
- name: 'update_field',
137
- label: 'Update field',
138
- description: 'Modify an existing field: rename, change type, toggle required/unique, or set default.',
139
- promptSnippet: 'update_field: rename/retype/toggle an existing column. Gated.',
140
- parameters: UpdateFieldSchema,
141
- async execute(_id, params, _signal, _onUpdate, ctx) {
142
- const resolved = await (0, context_1.resolveProjectContext)(ctx.cwd);
143
- if (!resolved.context)
144
- return fail(resolved.reason);
145
- const { api, databaseId } = resolved.context;
146
- try {
147
- const schema = await (0, schema_resolve_1.resolveSchema)(resolved.context);
148
- const table = (0, schema_resolve_1.resolveTable)(schema, params.table_name);
149
- const field = (0, schema_resolve_1.resolveField)(table, params.field_name);
150
- const patch = {};
151
- if (params.new_name)
152
- patch.name = params.new_name;
153
- if (params.new_type)
154
- patch.type = (0, harness_1.toFieldType)(params.new_type);
155
- if (params.is_required !== undefined)
156
- patch.isRequired = params.is_required;
157
- if (params.default_value !== undefined) {
158
- patch.defaultValue =
159
- params.default_value === null ? null : ((0, harness_1.toFieldDefault)(params.default_value) ?? null);
160
- }
161
- if (Object.keys(patch).length > 0) {
162
- await api.field
163
- .update({
164
- where: { id: field.id },
165
- data: patch,
166
- select: { id: true, name: true, type: true },
167
- })
168
- .unwrap();
169
- }
170
- if (params.is_unique !== undefined) {
171
- const existingUniqueId = (0, schema_resolve_1.findUniqueConstraintId)(table, field.id);
172
- if (params.is_unique && !existingUniqueId) {
173
- try {
174
- await api.uniqueConstraint
175
- .create({
176
- data: {
177
- tableId: table.id,
178
- databaseId,
179
- fieldIds: [field.id],
180
- name: `${table.name}_${params.new_name ?? field.name}_key`,
181
- type: 'u',
182
- },
183
- select: { id: true },
184
- })
185
- .unwrap();
186
- }
187
- catch (err) {
188
- console.warn('Failed to create unique constraint:', err);
189
- }
190
- }
191
- else if (!params.is_unique && existingUniqueId) {
192
- try {
193
- await api.uniqueConstraint
194
- .delete({ where: { id: existingUniqueId }, select: { id: true } })
195
- .unwrap();
196
- }
197
- catch (err) {
198
- console.warn('Failed to delete unique constraint:', err);
199
- }
200
- }
201
- }
202
- return ok(`Updated field ${params.table_name}.${params.field_name}`);
203
- }
204
- catch (err) {
205
- return fail(err instanceof Error ? err.message : 'Failed to update field');
206
- }
207
- },
208
- };
209
- // ── delete_field ──────────────────────────────────────────────────────────
210
- const DeleteFieldZod = zod_1.z.object({
211
- table_name: zod_1.z.string().describe('Name of the table containing the field'),
212
- field_name: zod_1.z.string().describe('Name of the field to delete'),
213
- });
214
- const DeleteFieldSchema = (0, tool_schema_1.toolSchema)(DeleteFieldZod);
215
- exports.deleteFieldTool = {
216
- name: 'delete_field',
217
- label: 'Delete field',
218
- description: 'Permanently delete a field (column) from an existing table.',
219
- promptSnippet: 'delete_field: drop a column from a table by name. Destructive — gated.',
220
- parameters: DeleteFieldSchema,
221
- async execute(_id, params, _signal, _onUpdate, ctx) {
222
- const resolved = await (0, context_1.resolveProjectContext)(ctx.cwd);
223
- if (!resolved.context)
224
- return fail(resolved.reason);
225
- try {
226
- const schema = await (0, schema_resolve_1.resolveSchema)(resolved.context);
227
- const table = (0, schema_resolve_1.resolveTable)(schema, params.table_name);
228
- const field = (0, schema_resolve_1.resolveField)(table, params.field_name);
229
- await resolved.context.api.field
230
- .delete({ where: { id: field.id }, select: { id: true } })
231
- .unwrap();
232
- return ok(`Deleted field ${params.table_name}.${params.field_name}`);
233
- }
234
- catch (err) {
235
- return fail(err instanceof Error ? err.message : 'Failed to delete field');
236
- }
237
- },
238
- };
@@ -1,22 +0,0 @@
1
- import type { ToolDefinition } from '@earendil-works/pi-coding-agent';
2
- declare const BlueprintSchema: import("typebox/type").TSchema;
3
- type ProvisionedField = {
4
- name: string;
5
- type: string;
6
- isRequired: boolean;
7
- defaultValue: string | null;
8
- };
9
- type ProvisionedTable = {
10
- name: string;
11
- fields: ProvisionedField[];
12
- policies: string[];
13
- relationCount: number;
14
- };
15
- export type ProvisionBlueprintDetails = {
16
- created: number;
17
- total: number;
18
- tables: ProvisionedTable[];
19
- error: string | null;
20
- };
21
- export declare const provisionBlueprintTool: ToolDefinition<typeof BlueprintSchema, ProvisionBlueprintDetails>;
22
- export {};