fnloom 0.1.0 → 0.2.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 (113) hide show
  1. package/README.md +31 -18
  2. package/package.json +2 -7
  3. package/packages/build/package.json +1 -1
  4. package/packages/cli/package.json +1 -1
  5. package/packages/cli/src/commands/available.ts +63 -22
  6. package/packages/cli/src/commands/install.ts +86 -28
  7. package/packages/cli/src/index.ts +3 -2
  8. package/packages/cli/src/local.ts +6 -0
  9. package/packages/cli/src/premade.ts +80 -0
  10. package/packages/core/package.json +1 -1
  11. package/packages/hub/package.json +1 -1
  12. package/packages/hub/src/link/process.ts +6 -1
  13. package/packages/sdk/package.json +1 -1
  14. package/packages/web/package.json +1 -1
  15. package/premade/claude.zip +0 -0
  16. package/premade/database.zip +0 -0
  17. package/premade/web.zip +0 -0
  18. package/scripts/dev-env.ts +4 -4
  19. package/scripts/stack.ts +42 -27
  20. package/scripts/start.ts +26 -16
  21. package/systems/api/package.json +1 -1
  22. package/systems/code/package.json +1 -1
  23. package/systems/embedder/package.json +1 -1
  24. package/systems/fs/package.json +1 -1
  25. package/systems/google-calendar/package.json +1 -1
  26. package/systems/input/package.json +1 -1
  27. package/systems/mcp/package.json +1 -1
  28. package/systems/ollama/package.json +1 -1
  29. package/systems/schedule/package.json +1 -1
  30. package/systems/template/package.json +1 -1
  31. package/systems/widgets/package.json +1 -1
  32. package/systems/claude/client/FleetPage.vue +0 -132
  33. package/systems/claude/client/NewSessionForm.vue +0 -62
  34. package/systems/claude/client/SessionList.vue +0 -64
  35. package/systems/claude/client/SessionPage.vue +0 -199
  36. package/systems/claude/client/TaskList.vue +0 -61
  37. package/systems/claude/client/fakes.ts +0 -186
  38. package/systems/claude/client/host.ts +0 -23
  39. package/systems/claude/client/index.ts +0 -15
  40. package/systems/claude/client/logic.ts +0 -270
  41. package/systems/claude/client/state.ts +0 -344
  42. package/systems/claude/package.json +0 -23
  43. package/systems/claude/server/agent-sdk.ts +0 -379
  44. package/systems/claude/server/driver.ts +0 -153
  45. package/systems/claude/server/env.ts +0 -64
  46. package/systems/claude/server/fake-driver.ts +0 -112
  47. package/systems/claude/server/fleet.ts +0 -376
  48. package/systems/claude/server/impl.ts +0 -568
  49. package/systems/claude/server/index.ts +0 -8
  50. package/systems/claude/server/main.ts +0 -38
  51. package/systems/claude/server/preview.ts +0 -76
  52. package/systems/claude/server/questions.ts +0 -117
  53. package/systems/claude/server/transcript.ts +0 -83
  54. package/systems/claude/shared/index.ts +0 -262
  55. package/systems/claude/shared/session.ts +0 -284
  56. package/systems/claude/shared/shapes.ts +0 -106
  57. package/systems/claude/system.json +0 -18
  58. package/systems/claude/tsconfig.json +0 -6
  59. package/systems/database/package.json +0 -25
  60. package/systems/database/server/author.ts +0 -41
  61. package/systems/database/server/authoring.ts +0 -322
  62. package/systems/database/server/catalog.ts +0 -117
  63. package/systems/database/server/compile.ts +0 -332
  64. package/systems/database/server/dialects.ts +0 -17
  65. package/systems/database/server/drivers/database.ts +0 -71
  66. package/systems/database/server/drivers/index.ts +0 -23
  67. package/systems/database/server/drivers/postgres.ts +0 -157
  68. package/systems/database/server/drivers/sqlite.ts +0 -151
  69. package/systems/database/server/drivers/sqlserver.ts +0 -176
  70. package/systems/database/server/env.ts +0 -35
  71. package/systems/database/server/fixture.ts +0 -169
  72. package/systems/database/server/impl.ts +0 -793
  73. package/systems/database/server/index.ts +0 -7
  74. package/systems/database/server/instance.ts +0 -398
  75. package/systems/database/server/main.ts +0 -47
  76. package/systems/database/server/pick.ts +0 -97
  77. package/systems/database/server/queries.ts +0 -390
  78. package/systems/database/server/results.ts +0 -39
  79. package/systems/database/server/schema.ts +0 -59
  80. package/systems/database/server/table-fns.ts +0 -237
  81. package/systems/database/server/types.ts +0 -253
  82. package/systems/database/shared/index.ts +0 -544
  83. package/systems/database/shared/shapes.ts +0 -413
  84. package/systems/database/system.json +0 -14
  85. package/systems/database/tsconfig.json +0 -6
  86. package/systems/web/client/ReadView.vue +0 -110
  87. package/systems/web/client/SearchView.vue +0 -215
  88. package/systems/web/client/StatusChip.vue +0 -38
  89. package/systems/web/client/fakes.ts +0 -48
  90. package/systems/web/client/index.ts +0 -15
  91. package/systems/web/client/view.ts +0 -131
  92. package/systems/web/package.json +0 -22
  93. package/systems/web/server/chrome.ts +0 -121
  94. package/systems/web/server/crawl.ts +0 -333
  95. package/systems/web/server/env.ts +0 -63
  96. package/systems/web/server/guard.ts +0 -60
  97. package/systems/web/server/http.ts +0 -89
  98. package/systems/web/server/impl.ts +0 -203
  99. package/systems/web/server/index.ts +0 -71
  100. package/systems/web/server/loader.ts +0 -104
  101. package/systems/web/server/main.ts +0 -70
  102. package/systems/web/server/mentions.ts +0 -111
  103. package/systems/web/server/problem.ts +0 -72
  104. package/systems/web/server/renderer.ts +0 -243
  105. package/systems/web/server/robots.ts +0 -75
  106. package/systems/web/server/searches.ts +0 -29
  107. package/systems/web/server/tavily.ts +0 -144
  108. package/systems/web/server/testing.ts +0 -165
  109. package/systems/web/server/uploads.ts +0 -33
  110. package/systems/web/shared/index.ts +0 -343
  111. package/systems/web/shared/urls.ts +0 -60
  112. package/systems/web/system.json +0 -15
  113. package/systems/web/tsconfig.json +0 -6
@@ -1,413 +0,0 @@
1
- /**
2
- * The database system's shapes, zod first: its config, the query kind's payload, and everything its fns hand the
3
- * model. The contract (`index.ts`) carries each as gin (`ginAs`), and the server parses with these, so each shape has
4
- * one source.
5
- */
6
- import { FnNameValue, GinObjTypeDef, Json, ResultTable, ShareRule } from '@harness/core';
7
- import { ResultBlock, ResultFn } from '@harness/sdk';
8
- import { a } from '@aeye/schema';
9
- import { z } from 'zod';
10
-
11
- // ─── Config ──────────────────────────────────────────────────────────────────
12
-
13
- /**
14
- * A connection with exactly the fields its kind needs: a new SQLite file in the instance's data folder, an existing
15
- * SQLite file, Postgres or SQL Server. The config form shows one kind at a time, labelled by its `kind` description,
16
- * with only that kind's fields; each secret (`url`, `password`) still has one path.
17
- */
18
- export const Connection = z.discriminatedUnion('kind', [
19
- z.object({
20
- kind: z.literal('sqlite-new').describe('New SQLite file'),
21
- path: z.string().min(1).regex(/^[^/\\:]+$/, 'A new SQLite file is a plain file name inside the data folder.').describe("A file name inside the instance's data folder (`shop.db`)."),
22
- }),
23
- z.object({
24
- kind: z.literal('sqlite-file').describe('Existing SQLite file'),
25
- path: z.string().min(1).describe("The SQLite file's full path."),
26
- }),
27
- z.object({
28
- kind: z.literal('postgres').describe('Postgres'),
29
- url: z.string().min(1).describe('The connection URL (`postgres://user:password@host:5432/db`). Kept as a secret.'),
30
- }),
31
- z.object({
32
- kind: z.literal('sqlserver').describe('SQL Server'),
33
- host: z.string().min(1).describe('The host name.'),
34
- port: z.number().int().min(1).max(65535).optional().describe('The port (1433 when empty).'),
35
- database: z.string().min(1).describe('The database name.'),
36
- user: z.string().min(1).describe('The user name.'),
37
- password: z.string().min(1).describe('The password. Kept as a secret.'),
38
- encrypt: z.boolean().optional().describe('Encrypt the connection (on when empty).'),
39
- }),
40
- ]);
41
- export type Connection = z.infer<typeof Connection>;
42
-
43
- /** The kinds of connection. */
44
- export type ConnectionKind = Connection['kind'];
45
-
46
- /** The dialects the system speaks, by connection kind. */
47
- export const DIALECT_NAMES = ['sqlite', 'postgres', 'sqlserver'] as const;
48
- export const DialectName = z.enum(DIALECT_NAMES);
49
- export type DialectName = z.infer<typeof DialectName>;
50
-
51
- /** The dialect a connection speaks. */
52
- export function dialectOf(kind: ConnectionKind): DialectName {
53
- return kind === 'sqlite-new' || kind === 'sqlite-file' ? 'sqlite' : kind;
54
- }
55
-
56
- /** One instance's config: one database. */
57
- export const DatabaseConfig = z.object({
58
- label: z.string().min(1).describe('What this database is, as people and the model read it ("Shop orders").'),
59
- connection: Connection,
60
- data: z.enum(['read-only', 'read-write']).describe('`read-write` lets queries insert, update and delete rows, each only after the person approves it.'),
61
- schema: z.enum(['none', 'allowed']).describe('`allowed` lets the chat create and change tables from types, each only after approval.'),
62
- enrich: z.object({
63
- on: z.boolean().describe('Have a model refine each table\'s type (choices, formats, ranges, descriptions) when its schema changes.'),
64
- model: z.string().min(1).optional().describe('The model for it (`openrouter/...`); the hub\'s default when empty.'),
65
- }),
66
- audience: ShareRule.describe('Who may use this database\'s query fns.'),
67
- });
68
- export type DatabaseConfig = z.infer<typeof DatabaseConfig>;
69
-
70
- /** The config's secret fields. */
71
- export const CONFIG_SECRETS = ['connection.url', 'connection.password'] as const;
72
-
73
- // ─── The query kind ──────────────────────────────────────────────────────────
74
-
75
- /** How a generated fn's query is built (`@aeye/query`'s `TableFnOp`, which `toTableFnOp` turns it back into): JSON, so it is stored and rebuilt. */
76
- export const TableFnOpSchema = z.object({
77
- kind: z.enum([
78
- 'create', 'update', 'updateWhere', 'remove', 'removeWhere', 'selectOne', 'selectPage',
79
- 'countBy', 'stats', 'buckets', 'exists', 'findOrCreate', 'childrenOf', 'countPerParent', 'derived',
80
- ]),
81
- table: z.string().min(1),
82
- column: z.string().min(1).optional(),
83
- child: z.string().min(1).optional(),
84
- bucket: z.enum(['day', 'week', 'month']).optional(),
85
- derived: z.array(z.string().min(1)).optional(),
86
- });
87
- export type TableFnOpValue = z.infer<typeof TableFnOpSchema>;
88
-
89
- /** What a generated query fn was made from: its op, and the hash of its table's schema then. */
90
- export const GeneratedFrom = z.object({
91
- op: TableFnOpSchema,
92
- hash: z.string().min(1).describe('The table schema hash (`tableSchemaHash`) it was generated for.'),
93
- });
94
- export type GeneratedFrom = z.infer<typeof GeneratedFrom>;
95
-
96
- /** A saved query: an `@aeye/query` query over this database's table types, and how callers may page and sort it. */
97
- export const QueryPayload = z.object({
98
- /** The database instance it runs on. */
99
- instance: z.string().min(1),
100
- /** What it answers, in words: what the model matches later requests against. */
101
- description: z.string().min(1),
102
- /** The query, as `@aeye/query` JSON (`{ kind: 'select', … }`). */
103
- query: Json,
104
- /** Output columns a caller may sort by (`sort` arg); empty for none. */
105
- sorters: z.array(z.string().min(1)),
106
- /** Whether it returns a list of rows that pages with `limit` / `offset`. */
107
- list: z.boolean(),
108
- /** Params a caller may leave out, bound as NULL (no filter, no change); every other param is required. */
109
- optional: z.array(z.string().min(1)).optional(),
110
- /** Set when `table_fns_generate` made it: what it was generated from, so it is rebuilt when the table changes. */
111
- generated: GeneratedFrom.optional(),
112
- });
113
- export type QueryPayload = z.infer<typeof QueryPayload>;
114
-
115
- /** A sort a caller asks for. */
116
- export const SortArg = z.array(z.object({ column: z.string().min(1), dir: z.enum(['asc', 'desc']) }));
117
- export type SortArg = z.infer<typeof SortArg>;
118
-
119
- // ─── What the model reads ────────────────────────────────────────────────────
120
-
121
- /** What a write did once approved. */
122
- export const WriteResult = z.object({
123
- shown: z.string(),
124
- affected: z.number().int().min(0).describe('Rows inserted, changed or deleted.'),
125
- returned: ResultBlock.optional().describe('Rows the write returned (`returning`), when it asked for any.'),
126
- });
127
- export type WriteResult = z.infer<typeof WriteResult>;
128
-
129
- /** The database a fn ran on. */
130
- export const DatabaseInfo = z.object({ instance: z.string(), label: z.string(), dialect: DialectName });
131
- export type DatabaseInfo = z.infer<typeof DatabaseInfo>;
132
-
133
- /** How a query was come by. */
134
- export const QueryHow = z.enum(['reused', 'created', 'edited']);
135
- export type QueryHow = z.infer<typeof QueryHow>;
136
-
137
- /** Where a write or schema change stands with its approval. */
138
- export const ApprovalState = z.object({
139
- run: z.string().describe('The run waiting for approval.'),
140
- state: z.enum(['waiting', 'approved', 'declined']),
141
- says: z.string().describe('What happens now, in words.'),
142
- });
143
- export type ApprovalState = z.infer<typeof ApprovalState>;
144
-
145
- /** A query's param values, by param name (`{ "status": "paid" }`). */
146
- export const ParamValues = z.record(z.string(), Json);
147
- export type ParamValues = z.infer<typeof ParamValues>;
148
-
149
- /** What `run_query` gives: the database, the fn, the query as it ran, and its result or where its approval is. */
150
- export const QueryRun = z.object({
151
- database: DatabaseInfo,
152
- fn: ResultFn,
153
- query: z.object({
154
- sql: z.string().describe('The SQL it runs, readable.'),
155
- structured: Json.describe('The `@aeye/query` JSON, to change it with edit_query.'),
156
- params: ParamValues.describe('The values it ran with.'),
157
- writes: z.boolean(),
158
- }),
159
- result: ResultBlock.optional(),
160
- approval: ApprovalState.optional(),
161
- });
162
- export type QueryRun = z.infer<typeof QueryRun>;
163
-
164
- // ─── The query agent's tools ─────────────────────────────────────────────────
165
-
166
- /**
167
- * A query the agent wrote, before it is checked and saved, as the model writes it (the authoring agent's draft extends
168
- * it with `query` typed by the loaded tables and this request's `args`).
169
- */
170
- export const QueryDraft = a.object({
171
- name: a.string().pattern(/^[a-z][a-z0-9_]{0,47}$/).describe('A snake_case name (`overdue_invoices`); it is saved as a fn of the database (`database/main.overdue_invoices`).'),
172
- title: a.string().min(1).describe('A short title (`Overdue invoices`).'),
173
- description: a.string().min(1).describe('One sentence: what it returns (or changes) and what its params are for. Later requests are matched against it.'),
174
- query: a.json().describe('The query as `@aeye/query` JSON (`{ "kind": "select", … }`).'),
175
- sorters: a.array(a.string().min(1)).optional().describe('Output columns a caller may sort by.'),
176
- });
177
- export type QueryDraft = a.infer<typeof QueryDraft>;
178
-
179
- /** What the draft check says about a draft: whether it runs here, its SQL and signature, or what to fix. */
180
- export const QueryCheck = z.object({
181
- ok: z.boolean(),
182
- problems: z.array(z.string()).describe('Each problem, with what to change; empty when `ok`.'),
183
- sql: z.string().optional().describe('The SQL it would run.'),
184
- signature: z.string().optional().describe('The fn it would be, as one line: its args and what it returns.'),
185
- writes: z.boolean().optional(),
186
- });
187
- export type QueryCheck = z.infer<typeof QueryCheck>;
188
-
189
- /** What `tables` gives: one database's tables, columns and relations, and the query language, as the agent writes against. */
190
- export const TablesInfo = z.object({
191
- database: DatabaseInfo,
192
- writes: z.boolean().describe('Whether rows can be written: added, changed and removed, each after approval. False means rows can only be read, whatever `schemaChanges` says.'),
193
- schemaChanges: z.boolean().describe('Whether tables can be made and changed (create_table, alter_table), each after approval. A table can be made where rows can\'t be written.'),
194
- schema: z.string().describe('The table types, their columns (with choices, formats and ranges where known), relations, and how to write queries.'),
195
- });
196
- export type TablesInfo = z.infer<typeof TablesInfo>;
197
-
198
- /** A query the authoring agent kept in the hub. */
199
- export const SavedQueryRef = z.object({
200
- /** The saved fn (`database/main.overdue_invoices`); a fn name, so the model reads it as its tools spell it. */
201
- fn: FnNameValue,
202
- signature: z.string(),
203
- version: z.number().int().min(1).describe('1 for a new query; more when an edit replaced an earlier version (kept in its history).'),
204
- created: z.boolean(),
205
- });
206
- export type SavedQueryRef = z.infer<typeof SavedQueryRef>;
207
-
208
- /** One database as `databases` lists it. */
209
- export const DatabaseSummary = z.object({
210
- instance: z.string(),
211
- label: z.string(),
212
- tables: z.array(z.string()).describe('Its tables, each with what it holds when known.'),
213
- writes: z.boolean().optional().describe('Whether rows can be written (added, changed, removed), each after approval.'),
214
- schemaChanges: z.boolean().optional().describe('Whether tables can be made and changed, each after approval; one can be allowed without the other.'),
215
- });
216
- export type DatabaseSummary = z.infer<typeof DatabaseSummary>;
217
-
218
- /**
219
- * The query fn an authoring fn answered with (`get_query`, `edit_query`): the SDK's authored-fn answer (its version,
220
- * what it does, how to call it again) with its name and signature as a result names them, and how it was come by.
221
- */
222
- export const QueryAnswerFn = ResultFn.extend({
223
- version: z.number().int().min(1).describe('1 for a new query; more after edits (the old versions are kept).'),
224
- about: z.string().describe('What it returns or changes, in one sentence.'),
225
- call: z.string().describe('How to call it again directly, with the args of this request.'),
226
- how: QueryHow,
227
- why: z.string().min(1).describe('Why this query: the saved one that fit, or what was written or changed.'),
228
- });
229
- export type QueryAnswerFn = z.infer<typeof QueryAnswerFn>;
230
-
231
- /**
232
- * What `get_query` and `edit_query` answer with: the saved query's run (the database, the query as it ran, and its
233
- * result or where its approval is) and its fn with how and why. Never the authoring agent's working context.
234
- */
235
- export const QueryAnswer = QueryRun.extend({ fn: QueryAnswerFn });
236
- export type QueryAnswer = z.infer<typeof QueryAnswer>;
237
-
238
- /** `get_query`'s answer when the request could be for more than one database and doesn't say which. */
239
- export const AskWhichDatabase = z.object({
240
- ask: z.string().min(1).describe('The question for the person: which database they mean, by label.'),
241
- databases: z.array(z.string().min(1)).min(2).describe('The database instances it could be.'),
242
- });
243
- export type AskWhichDatabase = z.infer<typeof AskWhichDatabase>;
244
-
245
- /** `get_query`'s question back when the database is unclear: which one, and what the caller does now. */
246
- export const AskDatabase = AskWhichDatabase.extend({
247
- next: z.string().describe('What to do now: ask the person with input/ask_choice and call get_query again with their pick (or, with nobody watching, say which databases could answer).'),
248
- });
249
- export type AskDatabase = z.infer<typeof AskDatabase>;
250
-
251
- /** What `get_query` answers: the query it ran, or which database to use. */
252
- export const QueryAgentAnswer = z.union([QueryAnswer, AskDatabase]);
253
- export type QueryAgentAnswer = z.infer<typeof QueryAgentAnswer>;
254
-
255
- /** A table made or changed from a type (`create_table`, `alter_table`, `apply_type_changes`). */
256
- export const SchemaChanged = z.object({
257
- database: DatabaseInfo,
258
- shown: z.string(),
259
- steps: z.array(z.object({ sql: z.string(), irreversible: z.boolean() })),
260
- types: z.array(z.string()).describe('The table types now in the hub.'),
261
- });
262
- export type SchemaChanged = z.infer<typeof SchemaChanged>;
263
-
264
- /** `create_table` / `alter_table` args: a table's name and its row type. */
265
- export const TableArgs = z.object({
266
- table: z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/).describe('The table\'s name (`invoices`).'),
267
- type: GinObjTypeDef.describe('The row type: a gin `obj` type whose props are the columns. An `id` column (or `key`) is the primary key; an `optional` column may be empty.'),
268
- database: z.string().min(1).optional().describe('The database instance; the only one when empty.'),
269
- });
270
- export type TableArgs = z.infer<typeof TableArgs>;
271
-
272
- /** `change_schema` args: `create_table` / `alter_table`'s, with what to do and on which instance. */
273
- export const SchemaArgs = TableArgs.extend({ action: z.enum(['create', 'alter']), database: z.string().min(1) });
274
- export type SchemaArgs = z.infer<typeof SchemaArgs>;
275
-
276
- /** `apply_type_changes` args: the rescan whose changes an admin approves. */
277
- export const ApplyArgs = z.object({ scan: z.string().min(1).describe('The rescan these changes came from.') });
278
- export type ApplyArgs = z.infer<typeof ApplyArgs>;
279
-
280
- /** `pick_database` args: the request, and the database it names, if any. */
281
- export const PickArgs = z.object({
282
- detailedDescription: z.string().min(1).describe('The request, as get_query was given it.'),
283
- database: z.string().min(1).optional().describe('The database instance the request names, if any.'),
284
- });
285
- export type PickArgs = z.infer<typeof PickArgs>;
286
-
287
- /** How a database was picked: named in the request, the only one, by the decision model, or by its tables' match. */
288
- export const PickedBy = z.enum(['asked', 'only', 'decision', 'score']);
289
- export type PickedBy = z.infer<typeof PickedBy>;
290
-
291
- /** The database a request is for, and why. */
292
- export const PickedDatabase = z.object({
293
- database: z.string().min(1).describe('The database instance to use.'),
294
- label: z.string(),
295
- by: PickedBy,
296
- why: z.string().describe('Why this database, in one sentence.'),
297
- });
298
- export type PickedDatabase = z.infer<typeof PickedDatabase>;
299
-
300
- /** What `pick_database` answers: the database, or the question for the person when it stays unclear. */
301
- export const DatabasePick = z.union([PickedDatabase, AskWhichDatabase]);
302
- export type DatabasePick = z.infer<typeof DatabasePick>;
303
-
304
- // ─── Generated table fns ─────────────────────────────────────────────────────
305
-
306
- /** What a `table` arg tells the model: the table's plain name, with what else it takes. */
307
- export const TABLE_ARG_DOCS = 'The table\'s name as database/databases and database/tables list it (`projects`), with `database` when there are several databases. Its type, as a result gave it, is taken too.';
308
-
309
- /** `table_fns_available` args. */
310
- export const TableFnsArgs = z.object({
311
- table: z.string().min(1).describe(TABLE_ARG_DOCS),
312
- database: z.string().min(1).optional().describe('The database instance (`main`), as database/databases lists it; the only one when empty.'),
313
- });
314
- export type TableFnsArgs = z.infer<typeof TableFnsArgs>;
315
-
316
- /** How a listed fn stands in the hub: not made yet, made for this schema, or made for an older one (regenerate it). */
317
- export const TableFnState = z.enum(['new', 'current', 'stale']);
318
- export type TableFnState = z.infer<typeof TableFnState>;
319
-
320
- /** One fn a table could have. */
321
- export const TableFnEntry = z.object({
322
- name: z.string().describe('Its name within the table (`selectPage`, `projectCount`): what `table_fns_generate` takes.'),
323
- /** The fn it is, or would be once generated (`database/main.projects_selectPage`); a fn name, so the model reads it as its tools spell it. */
324
- fn: FnNameValue,
325
- about: z.string(),
326
- signature: z.string(),
327
- mode: z.enum(['read', 'write', 'delete']).describe('Whether it reads, writes (after approval) or deletes rows. Fns that write rows are listed only where rows can be written.'),
328
- state: TableFnState,
329
- version: z.number().int().min(1).optional().describe('The saved version, when it exists.'),
330
- });
331
- export type TableFnEntry = z.infer<typeof TableFnEntry>;
332
-
333
- /** A table's fns from one place: `crud`, `columns`, `table`, or the relation they come from. */
334
- export const TableFnGroup = z.object({ group: z.string(), fns: z.array(TableFnEntry) });
335
- export type TableFnGroup = z.infer<typeof TableFnGroup>;
336
-
337
- /** What `table_fns_available` lists: the table's fns by group, the most useful first, and how many more there are. */
338
- export const TableFnsList = z.object({
339
- database: DatabaseInfo,
340
- table: z.string(),
341
- type: z.string().describe('The table\'s type in the hub, for hub/fns_search\'s `types` filter; give `table` args the table\'s name instead.'),
342
- hash: z.string().describe('The schema hash of the table now.'),
343
- groups: z.array(TableFnGroup),
344
- more: z.number().int().min(0).describe('Fns left out past the cap.'),
345
- });
346
- export type TableFnsList = z.infer<typeof TableFnsList>;
347
-
348
- /** `table_fns_generate` args. */
349
- export const TableFnsGenerateArgs = TableFnsArgs.extend({
350
- names: z.array(z.string().min(1)).min(1).max(50).describe('The fns to make or bring up to date, by their names in `table_fns_available`.'),
351
- derived: z.array(z.string().min(1)).optional().describe('Derived fields `selectPage` also shows, sorts and filters on (`projectCount`).'),
352
- });
353
- export type TableFnsGenerateArgs = z.infer<typeof TableFnsGenerateArgs>;
354
-
355
- /** One fn `table_fns_generate` made: its name, signature and version, and what happened to it. */
356
- export const GeneratedTableFn = z.object({
357
- fn: FnNameValue,
358
- signature: z.string(),
359
- version: z.number().int().min(1),
360
- status: z.enum(['created', 'updated', 'unchanged']),
361
- });
362
- export type GeneratedTableFn = z.infer<typeof GeneratedTableFn>;
363
-
364
- /** What `table_fns_generate` gives. */
365
- export const TableFnsGenerated = z.object({ database: DatabaseInfo, table: z.string(), fns: z.array(GeneratedTableFn) });
366
- export type TableFnsGenerated = z.infer<typeof TableFnsGenerated>;
367
-
368
- /**
369
- * `drill_down`'s args: a saved grouped read, the args it ran with, and the group clicked (each group key column's
370
- * value), with the page of the rows behind it. A result table of a query that can be drilled into says so
371
- * (`ResultTable.drill`), with these args but the group and the page.
372
- */
373
- export const DrillArgs = z.object({
374
- fn: z.string().min(1).describe('The saved query fn whose result was clicked (`database/main.orders_by_status`).'),
375
- args: z.record(z.string(), Json).optional().describe('The args it ran with: its params (no paging or sort).'),
376
- group: z.record(z.string(), Json).describe('The clicked group: the value of each group key column, by column name.'),
377
- limit: z.number().int().min(1).optional().describe('How many rows (the page size when empty).'),
378
- offset: z.number().int().min(0).optional().describe('How many rows to skip, for the next page.'),
379
- });
380
- export type DrillArgs = z.infer<typeof DrillArgs>;
381
-
382
- /** What one instance is asked to read for a tool another instance answered (`read_at_instance`, declared read). */
383
- export const ReadInstanceOp = z.discriminatedUnion('op', [
384
- z.object({ op: z.literal('tables') }),
385
- z.object({ op: z.literal('table-fns'), table: z.string().min(1) }),
386
- z.object({ op: z.literal('drill'), drill: DrillArgs }),
387
- ]);
388
- export type ReadInstanceOp = z.infer<typeof ReadInstanceOp>;
389
-
390
- /** What one instance is asked to do for a tool another instance answered (`at_instance`): the reads and the writes. */
391
- export const InstanceOp = z.discriminatedUnion('op', [
392
- ...ReadInstanceOp.options,
393
- z.object({ op: z.literal('run'), fn: z.string().min(1), args: ParamValues.optional() }),
394
- z.object({ op: z.literal('table-fns-generate'), table: z.string().min(1), names: z.array(z.string().min(1)).min(1), derived: z.array(z.string().min(1)).optional() }),
395
- ]);
396
- export type InstanceOp = z.infer<typeof InstanceOp>;
397
-
398
- /** What an instance answers an `InstanceOp` with, by the same `op`. */
399
- export const InstanceAnswer = z.discriminatedUnion('op', [
400
- z.object({ op: z.literal('tables'), tables: TablesInfo }),
401
- z.object({ op: z.literal('run'), run: QueryRun }),
402
- z.object({ op: z.literal('table-fns'), list: TableFnsList }),
403
- z.object({ op: z.literal('table-fns-generate'), generated: TableFnsGenerated }),
404
- z.object({ op: z.literal('drill'), table: ResultTable }),
405
- ]);
406
- export type InstanceAnswer = z.infer<typeof InstanceAnswer>;
407
-
408
- /** `author_query`'s args: the request, and the saved query to change (`edit_query`). */
409
- export const AuthorArgs = z.object({
410
- request: z.string().min(1).describe('What the query should do, as the caller described it.'),
411
- edit: z.string().min(1).optional().describe('The saved query fn to change (`database/main.orders_by_status`); absent to find or write one.'),
412
- });
413
- export type AuthorArgs = z.infer<typeof AuthorArgs>;
@@ -1,14 +0,0 @@
1
- {
2
- "format": 1,
3
- "name": "database",
4
- "version": "0.1.0",
5
- "description": "Query and change SQL databases (SQLite, Postgres, SQL Server): every table is a type, and every query asked for is kept as a fn for next time.",
6
- "protocol": 1,
7
- "server": {
8
- "entry": "server/main.ts",
9
- "external": {
10
- "better-sqlite3": "^12.4.1"
11
- }
12
- },
13
- "instances": "many"
14
- }
@@ -1,6 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": { "rootDir": ".", "outDir": "../../.types/system-database", "tsBuildInfoFile": "../../.types/system-database.tsbuildinfo", "types": ["node"] },
4
- "include": ["shared", "server"],
5
- "references": [{ "path": "../../packages/core" }, { "path": "../../packages/sdk" }]
6
- }
@@ -1,110 +0,0 @@
1
- <script setup lang="ts">
2
- /**
3
- * The page card for `web/read`: the page's title and site, where it ended up, whether the browser rendered it and
4
- * whether the text was cut, every URL it fetched (redirects included), and a compact preview of the hub resource it was kept as (the chat's `ResourceViewer`,
5
- * which draws its markdown form). Before the hub's viewer is there (or without one) it shows the start of the text.
6
- */
7
- import { RESOURCE_VIEWER, type FnViewOf } from '@harness/sdk';
8
- import StatusChip from './StatusChip.vue';
9
- import { computed, inject } from 'vue';
10
- import type { web } from '../shared/index.ts';
11
- import { pageFacts, statusChip } from './view.ts';
12
-
13
- const view = defineProps<FnViewOf<typeof web, 'read'>>();
14
-
15
- /** Characters of text shown when there is no resource viewer. */
16
- const EXCERPT = 600;
17
-
18
- const viewer = inject(RESOURCE_VIEWER, undefined);
19
- const chip = computed(() => statusChip(view.status, view.error));
20
- const running = computed(() => view.status === 'running' || view.status === 'queued');
21
- const facts = computed(() => pageFacts(view.args.url, view.result));
22
- const excerpt = computed(() => {
23
- const text = view.result?.text.trim() ?? '';
24
- return text.length > EXCERPT ? `${text.slice(0, EXCERPT).trimEnd()}…` : text;
25
- });
26
- const chars = computed(() => new Intl.NumberFormat(navigator.language).format(facts.value.chars));
27
- </script>
28
-
29
- <template>
30
- <article class="page" :data-tone="chip.tone" :aria-busy="running">
31
- <header class="head">
32
- <span class="badge" aria-hidden="true">{{ facts.domain.charAt(0).toUpperCase() }}</span>
33
- <div class="names">
34
- <h3 class="title" :title="facts.title">{{ facts.title }}</h3>
35
- <a v-if="facts.href" class="url" :href="facts.href" target="_blank" rel="noopener noreferrer" :title="facts.shown">{{ facts.shown }}</a>
36
- <span v-else class="url" :title="facts.shown">{{ facts.shown }}</span>
37
- </div>
38
- <StatusChip :chip="chip" />
39
- </header>
40
-
41
- <ul v-if="view.result" class="facts" aria-label="About this page">
42
- <li v-if="facts.rendered" class="fact rendered" title="It was built by scripts, so it was run in a headless browser first">Rendered</li>
43
- <li v-if="facts.moved" class="fact">Redirected</li>
44
- <li class="fact">{{ chars }} characters{{ facts.truncated ? ', cut short' : '' }}</li>
45
- </ul>
46
-
47
- <p v-if="view.result && view.result.fetched.length > 0" class="fetched" data-testid="web-fetched"><span class="label">Fetched:</span> <code v-for="(url, at) in view.result.fetched" :key="at" class="hop">{{ url }}</code></p>
48
-
49
- <div v-if="running" class="progress" role="progressbar" aria-label="Reading the page"><div class="bar" /></div>
50
-
51
- <div v-if="view.result" class="preview">
52
- <component :is="viewer" v-if="viewer" :uri="view.result.uri" compact />
53
- <p v-else-if="excerpt" class="excerpt">{{ excerpt }}</p>
54
- </div>
55
-
56
- <p v-if="view.error" class="problem" role="alert">{{ view.error.message }}</p>
57
- </article>
58
- </template>
59
-
60
- <style scoped>
61
- .page {
62
- display: grid;
63
- gap: var(--space-2);
64
- min-width: 0;
65
- padding: var(--space-3);
66
- border: 1px solid var(--border);
67
- border-radius: var(--radius);
68
- background: var(--surface);
69
- transition: border-color var(--slow) var(--ease);
70
- }
71
- .page[data-tone='busy'] { border-color: color-mix(in oklab, var(--accent) 45%, var(--border)); }
72
- .page[data-tone='bad'] { border-color: color-mix(in oklab, var(--danger) 35%, var(--border)); }
73
- .head { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
74
- .badge {
75
- flex: none;
76
- display: grid;
77
- place-items: center;
78
- width: 28px;
79
- height: 28px;
80
- border-radius: var(--radius-sm);
81
- background: var(--accent-soft);
82
- color: var(--accent);
83
- font-size: var(--text-sm);
84
- font-weight: var(--weight-strong);
85
- }
86
- .names { display: grid; flex: 1 1 auto; min-width: 0; }
87
- .title { margin: 0; font-size: var(--text-sm); font-weight: var(--weight-strong); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
88
- .url { color: var(--text-dim); font: var(--text-xs)/1.4 var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
89
- .url:hover { color: var(--accent); text-decoration: underline; }
90
- .facts { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
91
- .fact { padding: 1px var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-full); color: var(--text-dim); font-size: var(--text-xs); }
92
- .fact.rendered { color: var(--accent); border-color: color-mix(in oklab, var(--accent) 35%, var(--border)); }
93
- .fetched { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1); margin: 0; color: var(--text-dim); font-size: var(--text-xs); }
94
- .hop { font: var(--text-xs)/1.4 var(--mono); overflow-wrap: anywhere; }
95
- .progress { height: 3px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
96
- .bar {
97
- width: 40%;
98
- height: 100%;
99
- border-radius: inherit;
100
- background: var(--accent);
101
- animation: slide 1.2s var(--ease) infinite;
102
- }
103
- .preview { min-width: 0; max-height: 320px; overflow: auto; border-radius: var(--radius-sm); }
104
- .excerpt { margin: 0; color: var(--text); font-size: var(--text-sm); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
105
- .problem { margin: 0; color: var(--danger); font-size: var(--text-sm); }
106
- @keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
107
- @media (prefers-reduced-motion: reduce) {
108
- .bar { animation: none; }
109
- }
110
- </style>