@cosmoops/connect-sdk 0.9.0 → 0.16.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 (155) hide show
  1. package/CHANGELOG.md +566 -0
  2. package/README.md +113 -42
  3. package/dist/cjs/cli/doctor.js +3 -3
  4. package/dist/cjs/cli/init.js +3 -3
  5. package/dist/cjs/client/components/access-gate.js +20 -1
  6. package/dist/cjs/client/components/ai-screens.js +73 -0
  7. package/dist/cjs/client/components/ai-widgets.js +37 -0
  8. package/dist/cjs/client/components/app-shell.js +75 -41
  9. package/dist/cjs/client/components/apps-grid.js +3 -2
  10. package/dist/cjs/client/components/ask-ai.js +50 -5
  11. package/dist/cjs/client/components/confirm-dialog.js +40 -0
  12. package/dist/cjs/client/components/cursor-pagination.js +22 -0
  13. package/dist/cjs/client/components/filter-tabs.js +24 -0
  14. package/dist/cjs/client/components/grievance-notice.js +30 -0
  15. package/dist/cjs/client/components/link-button.js +17 -10
  16. package/dist/cjs/client/components/logo.js +4 -3
  17. package/dist/cjs/client/components/nav.js +41 -0
  18. package/dist/cjs/client/components/plan-pricing.js +27 -0
  19. package/dist/cjs/client/components/plans.js +1 -1
  20. package/dist/cjs/client/components/platform-gate.js +48 -0
  21. package/dist/cjs/client/components/shell-context.js +149 -0
  22. package/dist/cjs/client/components/side-nav.js +49 -23
  23. package/dist/cjs/client/components/sidebar.js +127 -0
  24. package/dist/cjs/client/components/subscribe-dialog.js +2 -2
  25. package/dist/cjs/client/components/subscription.js +1 -1
  26. package/dist/cjs/client/components/user-menu.js +96 -37
  27. package/dist/cjs/client/components/workspace-switcher.js +100 -0
  28. package/dist/cjs/client/index.js +72 -2
  29. package/dist/cjs/client/provider.js +57 -2
  30. package/dist/cjs/client/use-checkout.js +9 -5
  31. package/dist/cjs/errors.js +1 -1
  32. package/dist/cjs/index.js +16 -1
  33. package/dist/cjs/mcp/index.js +90 -0
  34. package/dist/cjs/mcp/tools.js +369 -0
  35. package/dist/cjs/next/index.js +2 -2
  36. package/dist/cjs/server/client.js +25 -2
  37. package/dist/cjs/server/handler.js +203 -18
  38. package/dist/cjs/server/http.js +6 -2
  39. package/dist/cjs/server/resources/acting-as.js +16 -0
  40. package/dist/cjs/server/resources/ai.js +22 -2
  41. package/dist/cjs/server/resources/data.js +374 -0
  42. package/dist/cjs/server/resources/identity.js +7 -3
  43. package/dist/cjs/server/resources/kv.js +84 -0
  44. package/dist/cjs/server/resources/platform.js +43 -0
  45. package/dist/cjs/server/resources/sessions.js +1 -1
  46. package/dist/cjs/server/resources/workspaces.js +74 -0
  47. package/dist/cjs/store-schema.js +66 -0
  48. package/dist/cjs/store.js +152 -0
  49. package/dist/cjs/ui/empty-state.js +28 -0
  50. package/dist/cjs/ui/index.js +44 -0
  51. package/dist/cjs/ui/page-header.js +27 -0
  52. package/dist/cjs/ui/page-shell.js +44 -0
  53. package/dist/cjs/ui/section.js +20 -0
  54. package/dist/cjs/ui/setting-row.js +14 -0
  55. package/dist/cjs/ui/status-chip.js +17 -0
  56. package/dist/esm/cli/doctor.js +3 -3
  57. package/dist/esm/cli/init.js +3 -3
  58. package/dist/esm/client/components/access-gate.js +20 -1
  59. package/dist/esm/client/components/ai-screens.js +69 -0
  60. package/dist/esm/client/components/ai-widgets.js +37 -1
  61. package/dist/esm/client/components/app-shell.js +81 -47
  62. package/dist/esm/client/components/apps-grid.js +3 -2
  63. package/dist/esm/client/components/ask-ai.js +51 -6
  64. package/dist/esm/client/components/confirm-dialog.js +37 -0
  65. package/dist/esm/client/components/cursor-pagination.js +19 -0
  66. package/dist/esm/client/components/filter-tabs.js +21 -0
  67. package/dist/esm/client/components/grievance-notice.js +27 -0
  68. package/dist/esm/client/components/link-button.js +17 -10
  69. package/dist/esm/client/components/logo.js +4 -3
  70. package/dist/esm/client/components/nav.js +40 -0
  71. package/dist/esm/client/components/plan-pricing.js +25 -0
  72. package/dist/esm/client/components/plans.js +2 -2
  73. package/dist/esm/client/components/platform-gate.js +45 -0
  74. package/dist/esm/client/components/shell-context.js +141 -0
  75. package/dist/esm/client/components/side-nav.js +48 -21
  76. package/dist/esm/client/components/sidebar.js +120 -0
  77. package/dist/esm/client/components/subscribe-dialog.js +3 -3
  78. package/dist/esm/client/components/subscription.js +2 -2
  79. package/dist/esm/client/components/user-menu.js +95 -38
  80. package/dist/esm/client/components/workspace-switcher.js +97 -0
  81. package/dist/esm/client/index.js +47 -4
  82. package/dist/esm/client/provider.js +53 -2
  83. package/dist/esm/client/use-checkout.js +9 -5
  84. package/dist/esm/errors.js +1 -1
  85. package/dist/esm/index.js +4 -0
  86. package/dist/esm/mcp/index.js +85 -0
  87. package/dist/esm/mcp/tools.js +366 -0
  88. package/dist/esm/next/index.js +2 -2
  89. package/dist/esm/server/client.js +25 -2
  90. package/dist/esm/server/handler.js +203 -18
  91. package/dist/esm/server/http.js +6 -2
  92. package/dist/esm/server/resources/acting-as.js +13 -0
  93. package/dist/esm/server/resources/ai.js +22 -2
  94. package/dist/esm/server/resources/data.js +369 -0
  95. package/dist/esm/server/resources/identity.js +7 -3
  96. package/dist/esm/server/resources/kv.js +80 -0
  97. package/dist/esm/server/resources/platform.js +39 -0
  98. package/dist/esm/server/resources/sessions.js +1 -1
  99. package/dist/esm/server/resources/workspaces.js +70 -0
  100. package/dist/esm/store-schema.js +62 -0
  101. package/dist/esm/store.js +141 -0
  102. package/dist/esm/ui/empty-state.js +25 -0
  103. package/dist/esm/ui/index.js +34 -0
  104. package/dist/esm/ui/page-header.js +24 -0
  105. package/dist/esm/ui/page-shell.js +41 -0
  106. package/dist/esm/ui/section.js +17 -0
  107. package/dist/esm/ui/setting-row.js +11 -0
  108. package/dist/esm/ui/status-chip.js +14 -0
  109. package/dist/types/client/components/ai-screens.d.ts +25 -0
  110. package/dist/types/client/components/ai-widgets.d.ts +34 -1
  111. package/dist/types/client/components/app-shell.d.ts +65 -27
  112. package/dist/types/client/components/apps-grid.d.ts +11 -2
  113. package/dist/types/client/components/ask-ai.d.ts +47 -1
  114. package/dist/types/client/components/confirm-dialog.d.ts +34 -0
  115. package/dist/types/client/components/cursor-pagination.d.ts +27 -0
  116. package/dist/types/client/components/filter-tabs.d.ts +26 -0
  117. package/dist/types/client/components/grievance-notice.d.ts +31 -0
  118. package/dist/types/client/components/link-button.d.ts +32 -9
  119. package/dist/types/client/components/logo.d.ts +18 -2
  120. package/dist/types/client/components/nav.d.ts +24 -0
  121. package/dist/types/client/components/plan-pricing.d.ts +10 -0
  122. package/dist/types/client/components/platform-gate.d.ts +53 -0
  123. package/dist/types/client/components/shell-context.d.ts +116 -0
  124. package/dist/types/client/components/side-nav.d.ts +27 -13
  125. package/dist/types/client/components/sidebar.d.ts +95 -0
  126. package/dist/types/client/components/user-menu.d.ts +68 -22
  127. package/dist/types/client/components/workspace-switcher.d.ts +49 -0
  128. package/dist/types/client/index.d.ts +29 -5
  129. package/dist/types/client/provider.d.ts +109 -6
  130. package/dist/types/client/use-checkout.d.ts +8 -4
  131. package/dist/types/errors.d.ts +1 -1
  132. package/dist/types/index.d.ts +6 -0
  133. package/dist/types/mcp/index.d.ts +74 -0
  134. package/dist/types/mcp/tools.d.ts +107 -0
  135. package/dist/types/next/index.d.ts +1 -1
  136. package/dist/types/server/client.d.ts +25 -2
  137. package/dist/types/server/http.d.ts +8 -2
  138. package/dist/types/server/index.d.ts +4 -0
  139. package/dist/types/server/resources/acting-as.d.ts +11 -0
  140. package/dist/types/server/resources/ai.d.ts +20 -2
  141. package/dist/types/server/resources/data.d.ts +258 -0
  142. package/dist/types/server/resources/kv.d.ts +63 -0
  143. package/dist/types/server/resources/platform.d.ts +32 -0
  144. package/dist/types/server/resources/workspaces.d.ts +55 -0
  145. package/dist/types/store-schema.d.ts +52 -0
  146. package/dist/types/store.d.ts +96 -0
  147. package/dist/types/types.d.ts +369 -16
  148. package/dist/types/ui/empty-state.d.ts +34 -0
  149. package/dist/types/ui/index.d.ts +40 -0
  150. package/dist/types/ui/page-header.d.ts +34 -0
  151. package/dist/types/ui/page-shell.d.ts +39 -0
  152. package/dist/types/ui/section.d.ts +26 -0
  153. package/dist/types/ui/setting-row.d.ts +18 -0
  154. package/dist/types/ui/status-chip.d.ts +36 -0
  155. package/package.json +15 -2
@@ -0,0 +1,366 @@
1
+ import { storeIndexSignature } from "../store.js";
2
+ import { describeQueryRejection } from "../store-schema.js";
3
+ /**
4
+ * The store, as tools a model can call.
5
+ *
6
+ * ## Why a declaration is enough
7
+ *
8
+ * `Application.storeSchema` already answers every question a tool definition
9
+ * asks. It names the collection and says what it holds (`description`), which
10
+ * fields may be filtered or ordered on (`queryableFields`), which query shapes
11
+ * the database can actually serve (`indexes`), and whether the collection
12
+ * refuses everything but a create (`appendOnly`). Writing those tools by hand
13
+ * means maintaining a second copy of all of it, and the copy is wrong the first
14
+ * time a filter is added to a screen.
15
+ *
16
+ * So they are derived. Adding a queryable field to the declaration and
17
+ * re-seeding widens the tools on the next boot, with no tool code to touch.
18
+ *
19
+ * ## What this is not
20
+ *
21
+ * **It is not an authorization boundary.** Connect is. Every call here goes out
22
+ * with the end user's session token (`asUser`), and Connect resolves it to a
23
+ * member and checks the collection's declared `readPermission`/`writePermission`
24
+ * against that member's live roles - so a tool can never reach further than the
25
+ * person on whose behalf it runs, and a permission revoked in the console is
26
+ * gone from the next call. The shaping done here - omitting write tools for an
27
+ * `appendOnly` collection, refusing an unservable query - is there so a model
28
+ * fails fast and legibly, not because it protects anything. Connect refuses the
29
+ * same things independently.
30
+ *
31
+ * **There is no `scan` tool, deliberately.** `data.scan` reads a collection
32
+ * across every workspace and, for exactly that reason, takes no `asUser` - a
33
+ * workspace admin is an admin of their own workspace and not of a partner's
34
+ * other customers. A toolset that runs on behalf of a signed-in user therefore
35
+ * has nothing to derive from `crossWorkspace`, and generating a scan tool would
36
+ * mean running that one call under the application's own key while every tool
37
+ * beside it ran under the user's. Cross-tenant reads belong in a back-office
38
+ * surface with its own gate.
39
+ *
40
+ * **`kv` collections are skipped.** The key/value store is addressed by
41
+ * namespace and key rather than queried, so it derives nothing from
42
+ * `queryableFields` or `indexes` and the tools it wants are a different shape.
43
+ *
44
+ * ## Deriving over every collection is usually wrong
45
+ *
46
+ * Measured on the two reference applications: club's fifteen collections yield
47
+ * 45 read tools and 88 with writes on; CRM's seven yield 21 and 40. Those are
48
+ * whole-catalogue numbers, and a model offered them chooses worse than one
49
+ * offered a handful - the ceiling is tool-choice accuracy, which degrades well
50
+ * before a context window fills. Connect's own assistant bounds each turn to
51
+ * the capabilities the current screen promotes for exactly this reason.
52
+ *
53
+ * So `include` is the normal way to call this, not a refinement: name the
54
+ * collections the surface at hand is about. Nothing here enforces a cap,
55
+ * because the right number depends on the surface and a silent truncation
56
+ * would be worse than a large list.
57
+ */
58
+ /** Connect's own ceilings, mirrored so a tool can describe them before the call. */
59
+ const MAX_QUERY_LIMIT = 200;
60
+ const DEFAULT_QUERY_LIMIT = 50;
61
+ const QUERY_OPERATORS = [
62
+ "==",
63
+ "!=",
64
+ "<",
65
+ "<=",
66
+ ">",
67
+ ">=",
68
+ "in",
69
+ "not-in",
70
+ "array-contains",
71
+ ];
72
+ /**
73
+ * MCP tool names are `[a-z0-9_-]`; collection names additionally allow capitals.
74
+ * Lowercasing and folding `-` to `_` is what makes `dues-demands` addressable,
75
+ * and is also how two collections can collide - which is caught, not resolved,
76
+ * because silently renaming one would make the tool a model calls depend on
77
+ * declaration order.
78
+ */
79
+ function toolBaseName(collection) {
80
+ return collection.toLowerCase().replace(/-/g, "_");
81
+ }
82
+ /**
83
+ * How many index shapes are worth spelling out before the listing costs more
84
+ * than it teaches.
85
+ *
86
+ * A real declaration is not a handful. club's ledger declares around forty
87
+ * shapes, and writing all of them into both the list and aggregate tools was
88
+ * most of a 79 KB `tools/list` on its own - paid on every turn, for a listing a
89
+ * model reads poorly anyway. Past this many, the description states the rule
90
+ * and leaves the specifics to the refusal, which names the exact index a
91
+ * rejected query needed and costs no round trip to get.
92
+ */
93
+ const MAX_DESCRIBED_INDEXES = 12;
94
+ /** The servable query shapes, spelled out for the model rather than left to be discovered. */
95
+ function describeIndexes(collection) {
96
+ if (collection.indexes.length === 0) {
97
+ return "No composite indexes are declared, so a query may use at most one filter, ordered only by that same field.";
98
+ }
99
+ const preamble = "A query using more than one filter, or ordering by a field it does not filter on, must match a declared composite index";
100
+ if (collection.indexes.length > MAX_DESCRIBED_INDEXES) {
101
+ return `${preamble}. ${collection.indexes.length} are declared - too many to list here. Issue the query you want: if no index covers it you get back the exact index it would need, before anything is read.`;
102
+ }
103
+ const shapes = collection.indexes.map((index) => ` - ${storeIndexSignature(index.fields)}`).join("\n");
104
+ return `${preamble}:\n${shapes}`;
105
+ }
106
+ function readDescription(collection, verb) {
107
+ const head = `${verb} ${collection.name}. ${collection.description}`;
108
+ // Nothing declared queryable means the collection can only be read whole -
109
+ // which is the right shape for the one-document-per-key collections (a
110
+ // settings block, a counter), and saying so beats offering a filter argument
111
+ // that has no legal value.
112
+ if (collection.queryableFields.length === 0) {
113
+ return `${head}\n\nThis collection declares no queryable fields, so it cannot be filtered or ordered - it is read whole.`;
114
+ }
115
+ return [head, "", `Queryable fields: ${collection.queryableFields.join(", ")}.`, describeIndexes(collection)].join("\n");
116
+ }
117
+ const filtersSchema = (collection) => ({
118
+ type: "array",
119
+ description: "Filters, ANDed together.",
120
+ items: {
121
+ type: "object",
122
+ properties: {
123
+ field: { type: "string", enum: [...collection.queryableFields] },
124
+ op: { type: "string", enum: QUERY_OPERATORS },
125
+ value: {
126
+ description: "The value to compare against. Dates are ISO-8601 strings; a calendar day is YYYY-MM-DD.",
127
+ },
128
+ },
129
+ required: ["field", "op", "value"],
130
+ additionalProperties: false,
131
+ },
132
+ });
133
+ /**
134
+ * Documents come back with Connect's `_`-prefixed bookkeeping on them, and
135
+ * every write refuses those fields. Saying so on the write tools is what stops
136
+ * a model reading a document, editing one field and posting the whole thing
137
+ * back - which fails, correctly, but wastes a turn learning it.
138
+ */
139
+ const WRITE_DATA_NOTE = "Fields beginning with `_` are written by Connect and are refused here - strip `_createdAt`, `_updatedAt`, `_createdBy`, `_updatedBy` and `_updateTime` from a document you read before writing it back.";
140
+ function buildReadTools(collection, base, call, data, workspaceId) {
141
+ return [
142
+ {
143
+ name: `${base}_get`,
144
+ title: `Get one ${collection.name} document`,
145
+ description: `Read one document from ${collection.name} by id. ${collection.description}`,
146
+ inputSchema: {
147
+ type: "object",
148
+ properties: { id: { type: "string", description: "The document id." } },
149
+ required: ["id"],
150
+ additionalProperties: false,
151
+ },
152
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
153
+ execute: (args) => call((asUser) => data.get({ workspaceId, collection: collection.name, id: String(args.id), asUser })),
154
+ },
155
+ {
156
+ name: `${base}_list`,
157
+ title: `List ${collection.name}`,
158
+ description: readDescription(collection, "List documents in"),
159
+ inputSchema: {
160
+ type: "object",
161
+ properties: {
162
+ ...(collection.queryableFields.length > 0
163
+ ? {
164
+ filters: filtersSchema(collection),
165
+ orderBy: {
166
+ type: "object",
167
+ properties: {
168
+ field: { type: "string", enum: [...collection.queryableFields] },
169
+ direction: { type: "string", enum: ["asc", "desc"] },
170
+ },
171
+ required: ["field", "direction"],
172
+ additionalProperties: false,
173
+ },
174
+ }
175
+ : {}),
176
+ limit: {
177
+ type: "integer",
178
+ minimum: 1,
179
+ maximum: MAX_QUERY_LIMIT,
180
+ description: `Page size. Defaults to ${DEFAULT_QUERY_LIMIT}, caps at ${MAX_QUERY_LIMIT}.`,
181
+ },
182
+ cursor: {
183
+ type: "string",
184
+ description: "The previous page's nextCursor. A null nextCursor is the end of the collection.",
185
+ },
186
+ },
187
+ additionalProperties: false,
188
+ },
189
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
190
+ execute: async (args) => {
191
+ const filters = args.filters ?? [];
192
+ const orderBy = args.orderBy ?? null;
193
+ const rejection = describeQueryRejection(collection, { filters, orderBy });
194
+ if (rejection)
195
+ throw new Error(rejection);
196
+ return call((asUser) => data.query({
197
+ workspaceId,
198
+ collection: collection.name,
199
+ filters,
200
+ orderBy: orderBy ?? undefined,
201
+ limit: args.limit,
202
+ cursor: args.cursor ?? null,
203
+ asUser,
204
+ }));
205
+ },
206
+ },
207
+ {
208
+ name: `${base}_aggregate`,
209
+ title: `Count, sum or average ${collection.name}`,
210
+ description: [
211
+ readDescription(collection, "Aggregate"),
212
+ "",
213
+ "Counts, sums and averages are computed in the database rather than by reading rows back, so prefer this over listing a collection to add it up. A sum or average over nothing answers null, not 0.",
214
+ ].join("\n"),
215
+ inputSchema: {
216
+ type: "object",
217
+ properties: {
218
+ aggregations: {
219
+ type: "array",
220
+ minItems: 1,
221
+ items: {
222
+ type: "object",
223
+ properties: {
224
+ op: {
225
+ type: "string",
226
+ // `sum` and `avg` need a field, and every field they could
227
+ // name must be queryable - so a collection declaring none can
228
+ // only be counted.
229
+ enum: collection.queryableFields.length > 0 ? ["count", "sum", "avg"] : ["count"],
230
+ },
231
+ ...(collection.queryableFields.length > 0
232
+ ? {
233
+ field: {
234
+ type: "string",
235
+ enum: [...collection.queryableFields],
236
+ description: "Required for sum and avg; omitted for count, which counts documents.",
237
+ },
238
+ }
239
+ : {}),
240
+ alias: { type: "string", description: "What the result is keyed by." },
241
+ },
242
+ required: ["op", "alias"],
243
+ additionalProperties: false,
244
+ },
245
+ },
246
+ ...(collection.queryableFields.length > 0 ? { filters: filtersSchema(collection) } : {}),
247
+ },
248
+ required: ["aggregations"],
249
+ additionalProperties: false,
250
+ },
251
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
252
+ execute: async (args) => {
253
+ const filters = args.filters ?? [];
254
+ // An aggregation has no ordering, so the index it needs is the one its
255
+ // filters need - the same check `list` makes, minus the sort.
256
+ const rejection = describeQueryRejection(collection, { filters, orderBy: null });
257
+ if (rejection)
258
+ throw new Error(rejection);
259
+ return call((asUser) => data.aggregate({
260
+ workspaceId,
261
+ collection: collection.name,
262
+ aggregations: args.aggregations,
263
+ filters,
264
+ asUser,
265
+ }));
266
+ },
267
+ },
268
+ ];
269
+ }
270
+ function buildWriteTools(collection, base, call, data, workspaceId, writes) {
271
+ if (writes === "none")
272
+ return [];
273
+ const tools = [
274
+ {
275
+ name: `${base}_create`,
276
+ title: `Create a ${collection.name} document`,
277
+ description: `Create a document in ${collection.name}. ${collection.description}\n\n${WRITE_DATA_NOTE}`,
278
+ inputSchema: {
279
+ type: "object",
280
+ properties: {
281
+ data: { type: "object", description: "The document's fields." },
282
+ id: { type: "string", description: "Choose the id, or omit for an allocated one. An existing id is a conflict." },
283
+ },
284
+ required: ["data"],
285
+ additionalProperties: false,
286
+ },
287
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
288
+ execute: (args) => call((asUser) => data.create({
289
+ workspaceId,
290
+ collection: collection.name,
291
+ data: args.data,
292
+ id: args.id,
293
+ asUser,
294
+ })),
295
+ },
296
+ ];
297
+ // An append-only collection refuses a merge and a delete for every caller,
298
+ // this application's own key included, so deriving those tools would offer a
299
+ // model two calls that can only ever fail.
300
+ if (writes === "all" && !collection.appendOnly) {
301
+ tools.push({
302
+ name: `${base}_update`,
303
+ title: `Update a ${collection.name} document`,
304
+ description: `Merge top-level fields into an existing ${collection.name} document. Fields not named are left alone.\n\n${WRITE_DATA_NOTE}`,
305
+ inputSchema: {
306
+ type: "object",
307
+ properties: {
308
+ id: { type: "string" },
309
+ data: { type: "object", description: "The fields to merge." },
310
+ },
311
+ required: ["id", "data"],
312
+ additionalProperties: false,
313
+ },
314
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
315
+ execute: (args) => call((asUser) => data.update({
316
+ workspaceId,
317
+ collection: collection.name,
318
+ id: String(args.id),
319
+ data: args.data,
320
+ asUser,
321
+ })),
322
+ }, {
323
+ name: `${base}_delete`,
324
+ title: `Delete a ${collection.name} document`,
325
+ description: `Delete one document from ${collection.name}. Idempotent - deleting a document that is not there succeeds.`,
326
+ inputSchema: {
327
+ type: "object",
328
+ properties: { id: { type: "string" } },
329
+ required: ["id"],
330
+ additionalProperties: false,
331
+ },
332
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true },
333
+ execute: (args) => call((asUser) => data
334
+ .delete({ workspaceId, collection: collection.name, id: String(args.id), asUser })
335
+ .then(() => ({ deleted: String(args.id) }))),
336
+ });
337
+ }
338
+ return tools;
339
+ }
340
+ /** Every tool one declaration yields, in a stable order. */
341
+ export function deriveStoreTools(options) {
342
+ const { collections, data, workspaceId, writes = "none", prefix = "", include } = options;
343
+ const resolveUser = typeof options.asUser === "function" ? options.asUser : () => options.asUser;
344
+ const call = async (run) => run(await resolveUser());
345
+ const wanted = include ? new Set(include) : null;
346
+ const selected = collections.filter((collection) => collection.kind === "data" && (!wanted || wanted.has(collection.name)));
347
+ if (wanted) {
348
+ const declared = new Set(collections.map((collection) => collection.name));
349
+ const missing = [...wanted].filter((name) => !declared.has(name));
350
+ if (missing.length > 0) {
351
+ throw new Error(`No declaration for ${missing.join(", ")}. Declared collections: ${[...declared].join(", ")}.`);
352
+ }
353
+ }
354
+ const byBaseName = new Map();
355
+ const tools = [];
356
+ for (const collection of selected) {
357
+ const base = `${prefix}${toolBaseName(collection.name)}`;
358
+ const clash = byBaseName.get(base);
359
+ if (clash) {
360
+ throw new Error(`"${collection.name}" and "${clash}" both derive the tool prefix "${base}". Rename one, or give one its own toolset with a prefix.`);
361
+ }
362
+ byBaseName.set(base, collection.name);
363
+ tools.push(...buildReadTools(collection, base, call, data, workspaceId), ...buildWriteTools(collection, base, call, data, workspaceId, writes));
364
+ }
365
+ return tools;
366
+ }
@@ -38,7 +38,7 @@ import { createConnectHandler } from "../server/handler.js";
38
38
  * | `CONNECT_SESSION_COOKIE` | no | session cookie name |
39
39
  *
40
40
  * Register `{your origin}/api/connect/callback` as a redirect URI in the
41
- * application's Integration tab. That is the only step this cannot do for you.
41
+ * application's Connect client section. That is the only step this cannot do for you.
42
42
  *
43
43
  * No `next.config.ts` changes needed either, including `transpilePackages`:
44
44
  * `dist/` is already ES2022 with `"use client"` hoisted to the top of every
@@ -287,7 +287,7 @@ export async function getConnectSession(request, options = {}) {
287
287
  * A thin wrapper, not a framework of its own - reach for `getConnectSession`
288
288
  * plus your own check when "not signed in" isn't "redirect to sign-in"
289
289
  * (an API route returning 401, say). Role and entitlement checks stay
290
- * outside this function on purpose: `session.applicationRole.granted` and
290
+ * outside this function on purpose: `session.permissions` and
291
291
  * `connect.entitlements.*` are one line each on top of the session this
292
292
  * already gives you, and where that line redirects (a plans page, a
293
293
  * "forbidden" screen) is a decision only your app can make - see
@@ -1,6 +1,9 @@
1
1
  import { AccessResource } from "./resources/access.js";
2
2
  import { AppsResource } from "./resources/apps.js";
3
3
  import { AiResource } from "./resources/ai.js";
4
+ import { DataResource, storePassthrough } from "./resources/data.js";
5
+ import { WorkspacesResource } from "./resources/workspaces.js";
6
+ import { KvResource } from "./resources/kv.js";
4
7
  import { BillingResource } from "./resources/billing.js";
5
8
  import { DriveResource } from "./resources/drive.js";
6
9
  import { EntitlementsResource } from "./resources/entitlements.js";
@@ -10,6 +13,7 @@ import { LogsResource } from "./resources/logs.js";
10
13
  import { AnalyticsResource } from "./resources/analytics.js";
11
14
  import { OtpResource } from "./resources/otp.js";
12
15
  import { SessionsResource } from "./resources/sessions.js";
16
+ import { PlatformResource } from "./resources/platform.js";
13
17
  export const DEFAULT_BASE_URL = "https://connect.cosmoops.com";
14
18
  const APPLICATION_API_PREFIX = "/api/v1/application";
15
19
  /**
@@ -74,6 +78,10 @@ export class ConnectClient {
74
78
  drive;
75
79
  /** RAG chat and structured extraction. */
76
80
  ai;
81
+ /** Your application's own document store - see `DataResource`. */
82
+ data;
83
+ /** Your application's key/value store - see `KvResource`. */
84
+ kv;
77
85
  /** WhatsApp/SMS phone verification. */
78
86
  otp;
79
87
  /** Feature events into the Console's audit log, filterable to your application. */
@@ -84,10 +92,20 @@ export class ConnectClient {
84
92
  sessions;
85
93
  /** Composio-hosted third-party connections (Google Calendar, Slack, ...) a workspace has connected. */
86
94
  integrations;
95
+ /** Which workspaces the signed-in user belongs to, switching between them, and the team - see `WorkspacesResource`. */
96
+ workspaces;
97
+ /** The platform's own legal identity and DPDP grievance channel - see `PlatformResource`. */
98
+ platform;
99
+ /**
100
+ * Relays one `/data/*` or `/kv/*` request verbatim - `createConnectHandler`'s
101
+ * store route and nothing else. See `storePassthrough`.
102
+ * @internal
103
+ */
104
+ storeRelay;
87
105
  constructor(options) {
88
106
  assertNotBrowser();
89
107
  if (!options.apiKey) {
90
- throw new TypeError("ConnectClient requires `apiKey` - the plaintext shown once in the Integration tab.");
108
+ throw new TypeError("ConnectClient requires `apiKey` - the plaintext shown once in the Connect client section.");
91
109
  }
92
110
  const appBaseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
93
111
  const transport = {
@@ -107,12 +125,17 @@ export class ConnectClient {
107
125
  this.billing = new BillingResource(transport);
108
126
  this.drive = new DriveResource(transport);
109
127
  this.ai = new AiResource(transport);
128
+ this.data = new DataResource(transport);
129
+ this.kv = new KvResource(transport);
110
130
  this.otp = new OtpResource(transport);
111
131
  this.logs = new LogsResource(transport);
112
132
  this.analytics = new AnalyticsResource(transport);
113
133
  this.sessions = new SessionsResource(transport, options.clientId ?? null);
114
134
  this.integrations = new IntegrationsResource(transport);
135
+ this.workspaces = new WorkspacesResource(transport);
136
+ this.platform = new PlatformResource(transport);
137
+ this.storeRelay = (spec) => storePassthrough(transport, spec);
115
138
  }
116
139
  }
117
140
  /** Kept in step with `package.json` by `sdk.test.ts`. */
118
- export const SDK_VERSION = "0.9.0";
141
+ export const SDK_VERSION = "0.16.0";