@kindgi/api 0.1.3 → 0.1.4-rc.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 (193) hide show
  1. package/dist/agent-binding.d.ts +18 -4
  2. package/dist/agent-binding.d.ts.map +1 -1
  3. package/dist/agent-pins.d.ts +48 -0
  4. package/dist/agent-pins.d.ts.map +1 -0
  5. package/dist/agent-pins.js +102 -0
  6. package/dist/agent-pins.js.map +1 -0
  7. package/dist/app.d.ts +22 -0
  8. package/dist/app.d.ts.map +1 -1
  9. package/dist/app.js +20 -2
  10. package/dist/app.js.map +1 -1
  11. package/dist/block-binding.d.ts +132 -0
  12. package/dist/block-binding.d.ts.map +1 -0
  13. package/dist/block-binding.js +4 -0
  14. package/dist/block-binding.js.map +1 -0
  15. package/dist/block-pins.d.ts +22 -0
  16. package/dist/block-pins.d.ts.map +1 -0
  17. package/dist/block-pins.js +112 -0
  18. package/dist/block-pins.js.map +1 -0
  19. package/dist/cost-binding.d.ts +20 -1
  20. package/dist/cost-binding.d.ts.map +1 -1
  21. package/dist/cost-binding.js +4 -0
  22. package/dist/cost-binding.js.map +1 -1
  23. package/dist/deploy-versions.d.ts +58 -0
  24. package/dist/deploy-versions.d.ts.map +1 -0
  25. package/dist/deploy-versions.js +91 -0
  26. package/dist/deploy-versions.js.map +1 -0
  27. package/dist/deployment-binding.d.ts +24 -3
  28. package/dist/deployment-binding.d.ts.map +1 -1
  29. package/dist/derive-agent-version.d.ts +69 -0
  30. package/dist/derive-agent-version.d.ts.map +1 -0
  31. package/dist/derive-agent-version.js +139 -0
  32. package/dist/derive-agent-version.js.map +1 -0
  33. package/dist/errors.d.ts.map +1 -1
  34. package/dist/errors.js +17 -0
  35. package/dist/errors.js.map +1 -1
  36. package/dist/eval-case-binding.d.ts +65 -0
  37. package/dist/eval-case-binding.d.ts.map +1 -0
  38. package/dist/eval-case-binding.js +4 -0
  39. package/dist/eval-case-binding.js.map +1 -0
  40. package/dist/eval-run-binding.d.ts +30 -0
  41. package/dist/eval-run-binding.d.ts.map +1 -1
  42. package/dist/eval-run-dispatcher.d.ts +38 -3
  43. package/dist/eval-run-dispatcher.d.ts.map +1 -1
  44. package/dist/eval-run-dispatcher.js +21 -15
  45. package/dist/eval-run-dispatcher.js.map +1 -1
  46. package/dist/eval-suite-binding.d.ts +1 -1
  47. package/dist/eval-suite-binding.d.ts.map +1 -1
  48. package/dist/eval-suite-binding.js +2 -0
  49. package/dist/eval-suite-binding.js.map +1 -1
  50. package/dist/flow-binding.d.ts +10 -4
  51. package/dist/flow-binding.d.ts.map +1 -1
  52. package/dist/flow-pins.d.ts +36 -0
  53. package/dist/flow-pins.d.ts.map +1 -0
  54. package/dist/flow-pins.js +81 -0
  55. package/dist/flow-pins.js.map +1 -0
  56. package/dist/index.d.ts +17 -6
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +8 -2
  59. package/dist/index.js.map +1 -1
  60. package/dist/judged-dispatcher.d.ts +134 -0
  61. package/dist/judged-dispatcher.d.ts.map +1 -0
  62. package/dist/judged-dispatcher.js +297 -0
  63. package/dist/judged-dispatcher.js.map +1 -0
  64. package/dist/judged-items.d.ts +86 -0
  65. package/dist/judged-items.d.ts.map +1 -0
  66. package/dist/judged-items.js +184 -0
  67. package/dist/judged-items.js.map +1 -0
  68. package/dist/judgment-binding.d.ts +316 -0
  69. package/dist/judgment-binding.d.ts.map +1 -0
  70. package/dist/judgment-binding.js +19 -0
  71. package/dist/judgment-binding.js.map +1 -0
  72. package/dist/openapi/generate.d.ts.map +1 -1
  73. package/dist/openapi/generate.js +4 -1
  74. package/dist/openapi/generate.js.map +1 -1
  75. package/dist/openapi/operations.d.ts.map +1 -1
  76. package/dist/openapi/operations.js +461 -7
  77. package/dist/openapi/operations.js.map +1 -1
  78. package/dist/openapi/schemas.d.ts +40 -0
  79. package/dist/openapi/schemas.d.ts.map +1 -1
  80. package/dist/openapi/schemas.js +843 -7
  81. package/dist/openapi/schemas.js.map +1 -1
  82. package/dist/provider-binding.d.ts +12 -7
  83. package/dist/provider-binding.d.ts.map +1 -1
  84. package/dist/routes/agents.d.ts +9 -1
  85. package/dist/routes/agents.d.ts.map +1 -1
  86. package/dist/routes/agents.js +175 -11
  87. package/dist/routes/agents.js.map +1 -1
  88. package/dist/routes/blocks.d.ts +19 -0
  89. package/dist/routes/blocks.d.ts.map +1 -0
  90. package/dist/routes/blocks.js +281 -0
  91. package/dist/routes/blocks.js.map +1 -0
  92. package/dist/routes/cost.d.ts.map +1 -1
  93. package/dist/routes/cost.js +47 -2
  94. package/dist/routes/cost.js.map +1 -1
  95. package/dist/routes/deployments.d.ts +3 -0
  96. package/dist/routes/deployments.d.ts.map +1 -1
  97. package/dist/routes/deployments.js +208 -55
  98. package/dist/routes/deployments.js.map +1 -1
  99. package/dist/routes/eval-comparison.d.ts +14 -0
  100. package/dist/routes/eval-comparison.d.ts.map +1 -0
  101. package/dist/routes/eval-comparison.js +87 -0
  102. package/dist/routes/eval-comparison.js.map +1 -0
  103. package/dist/routes/eval-runs.d.ts.map +1 -1
  104. package/dist/routes/eval-runs.js +8 -0
  105. package/dist/routes/eval-runs.js.map +1 -1
  106. package/dist/routes/flows.d.ts +13 -1
  107. package/dist/routes/flows.d.ts.map +1 -1
  108. package/dist/routes/flows.js +44 -3
  109. package/dist/routes/flows.js.map +1 -1
  110. package/dist/routes/hierarchy-errors.d.ts +35 -0
  111. package/dist/routes/hierarchy-errors.d.ts.map +1 -0
  112. package/dist/routes/hierarchy-errors.js +39 -0
  113. package/dist/routes/hierarchy-errors.js.map +1 -0
  114. package/dist/routes/judged-suites.d.ts +20 -0
  115. package/dist/routes/judged-suites.d.ts.map +1 -0
  116. package/dist/routes/judged-suites.js +272 -0
  117. package/dist/routes/judged-suites.js.map +1 -0
  118. package/dist/routes/judgment-context.d.ts +22 -0
  119. package/dist/routes/judgment-context.d.ts.map +1 -0
  120. package/dist/routes/judgment-context.js +88 -0
  121. package/dist/routes/judgment-context.js.map +1 -0
  122. package/dist/routes/judgment-flow-context.d.ts +32 -0
  123. package/dist/routes/judgment-flow-context.d.ts.map +1 -0
  124. package/dist/routes/judgment-flow-context.js +195 -0
  125. package/dist/routes/judgment-flow-context.js.map +1 -0
  126. package/dist/routes/judgments.d.ts +41 -0
  127. package/dist/routes/judgments.d.ts.map +1 -0
  128. package/dist/routes/judgments.js +566 -0
  129. package/dist/routes/judgments.js.map +1 -0
  130. package/dist/routes/orgs.d.ts +5 -2
  131. package/dist/routes/orgs.d.ts.map +1 -1
  132. package/dist/routes/orgs.js +38 -22
  133. package/dist/routes/orgs.js.map +1 -1
  134. package/dist/routes/policies.d.ts.map +1 -1
  135. package/dist/routes/policies.js +12 -1
  136. package/dist/routes/policies.js.map +1 -1
  137. package/dist/routes/projects.d.ts +10 -2
  138. package/dist/routes/projects.d.ts.map +1 -1
  139. package/dist/routes/projects.js +87 -79
  140. package/dist/routes/projects.js.map +1 -1
  141. package/dist/routes/providers.d.ts.map +1 -1
  142. package/dist/routes/providers.js +6 -1
  143. package/dist/routes/providers.js.map +1 -1
  144. package/dist/routes/runs.js +24 -3
  145. package/dist/routes/runs.js.map +1 -1
  146. package/dist/routes/teams.d.ts +6 -2
  147. package/dist/routes/teams.d.ts.map +1 -1
  148. package/dist/routes/teams.js +77 -73
  149. package/dist/routes/teams.js.map +1 -1
  150. package/openapi.json +13545 -10103
  151. package/package.json +21 -21
  152. package/src/agent-binding.ts +19 -4
  153. package/src/agent-pins.ts +147 -0
  154. package/src/app.ts +71 -2
  155. package/src/block-binding.ts +137 -0
  156. package/src/block-pins.ts +148 -0
  157. package/src/cost-binding.ts +21 -1
  158. package/src/deploy-versions.ts +157 -0
  159. package/src/deployment-binding.ts +27 -3
  160. package/src/derive-agent-version.ts +206 -0
  161. package/src/errors.ts +17 -0
  162. package/src/eval-case-binding.ts +71 -0
  163. package/src/eval-run-binding.ts +33 -0
  164. package/src/eval-run-dispatcher.ts +57 -16
  165. package/src/eval-suite-binding.ts +2 -0
  166. package/src/flow-binding.ts +11 -4
  167. package/src/flow-pins.ts +113 -0
  168. package/src/index.ts +85 -2
  169. package/src/judged-dispatcher.ts +507 -0
  170. package/src/judged-items.ts +263 -0
  171. package/src/judgment-binding.ts +349 -0
  172. package/src/openapi/generate.ts +7 -1
  173. package/src/openapi/operations.ts +523 -7
  174. package/src/openapi/schemas.ts +1009 -88
  175. package/src/provider-binding.ts +12 -7
  176. package/src/routes/agents.ts +243 -19
  177. package/src/routes/blocks.ts +362 -0
  178. package/src/routes/cost.ts +55 -1
  179. package/src/routes/deployments.ts +266 -56
  180. package/src/routes/eval-comparison.ts +101 -0
  181. package/src/routes/eval-runs.ts +11 -0
  182. package/src/routes/flows.ts +63 -5
  183. package/src/routes/hierarchy-errors.ts +51 -0
  184. package/src/routes/judged-suites.ts +363 -0
  185. package/src/routes/judgment-context.ts +128 -0
  186. package/src/routes/judgment-flow-context.ts +245 -0
  187. package/src/routes/judgments.ts +743 -0
  188. package/src/routes/orgs.ts +44 -27
  189. package/src/routes/policies.ts +19 -0
  190. package/src/routes/projects.ts +106 -95
  191. package/src/routes/providers.ts +5 -0
  192. package/src/routes/runs.ts +28 -3
  193. package/src/routes/teams.ts +96 -90
@@ -19,6 +19,7 @@ import type { Cursor, OrgId, TeamId, TenantId, UserId } from '@kindgi/types';
19
19
  import { statusFor, toWireError } from '../errors.js';
20
20
  import type { Authorizer } from '../middleware/authorize.js';
21
21
  import type { AppEnv } from '../types.js';
22
+ import { slugConflictError } from './hierarchy-errors.js';
22
23
  import { clampLimit } from './pagination.js';
23
24
 
24
25
  /**
@@ -29,9 +30,13 @@ import { clampLimit } from './pagination.js';
29
30
  * `?limit=` / `?cursor=` / `?orgId=` /
30
31
  * `?nameContains=`.
31
32
  * - `POST /` — create; body `{ name, slug,
32
- * description?, orgId? }`; 201 `{ id }`.
33
+ * description?, orgId? }`; 201 `{ id }`;
34
+ * 409 `slug-conflict` when the tenant
35
+ * has a team with that slug.
33
36
  * - `GET /:teamId` — get; 200 or 404 `team-not-found`.
34
- * - `PATCH /:teamId` — partial update; 204 or 404.
37
+ * - `PATCH /:teamId` — partial update; 204, 404
38
+ * `team-not-found` or 409
39
+ * `slug-conflict`.
35
40
  * - `DELETE /:teamId` — 204 idempotent.
36
41
  * - `GET /:teamId/memberships` — list; cursor-paginated.
37
42
  * - `POST /:teamId/memberships` — add member; body `{ userId, role }`;
@@ -193,17 +198,24 @@ export function teamsRouter(
193
198
  : ('00000000-0000-0000-0000-000000000000' as UserId);
194
199
  const result = await tenantHierarchy.createTeam({ tenantId, creatorUserId, spec });
195
200
  if (result.kind === 'err') {
196
- const code =
197
- result.error.code === 'slug-conflict' ? 'slug-conflict' : 'internal-server-error';
198
- c.status(statusFor(code) as never);
199
- return c.json(toWireError({ code, message: result.error.message }, requestId));
201
+ const error =
202
+ result.error.code === 'slug-conflict'
203
+ ? slugConflictError('team', spec.slug)
204
+ : { code: 'internal-server-error', message: result.error.message };
205
+ c.status(statusFor(error.code) as never);
206
+ return c.json(toWireError(error, requestId));
200
207
  }
201
208
  c.status(201);
202
209
  return c.json({ id: result.value.teamId as unknown as string });
203
210
  }
204
- const id = await binding.create(tenantId, spec);
211
+ const outcome = await binding.create(tenantId, spec);
212
+ if (outcome.kind === 'slug-conflict') {
213
+ const error = slugConflictError('team', outcome.slug);
214
+ c.status(statusFor(error.code) as never);
215
+ return c.json(toWireError(error, requestId));
216
+ }
205
217
  c.status(201);
206
- return c.json({ id: id as unknown as string });
218
+ return c.json({ id: outcome.teamId as unknown as string });
207
219
  });
208
220
 
209
221
  // ---------- GET /:teamId/memberships ----------
@@ -300,39 +312,38 @@ export function teamsRouter(
300
312
  ),
301
313
  );
302
314
  }
303
- try {
304
- if (authorizer !== undefined) {
305
- const res = await tenantHierarchy.addTeamMember({
306
- tenantId,
307
- teamId,
308
- userId: b.userId as unknown as UserId,
309
- role: b.role as TeamRole,
310
- });
311
- if (res.kind === 'err') throw new Error(res.error.message);
312
- } else {
313
- await membershipBinding.add(tenantId, {
314
- teamId,
315
- userId: b.userId as unknown as UserId,
316
- role: b.role,
317
- });
318
- }
319
- } catch (cause) {
320
- const message = cause instanceof Error ? cause.message : String(cause);
321
- if (message.startsWith('team-not-found')) {
322
- // Racy — team was deleted between the preliminary get and the add.
323
- c.status(statusFor('team-not-found') as never);
324
- return c.json(
325
- toWireError(
326
- {
327
- code: 'team-not-found',
328
- message: `No team with id "${teamId as unknown as string}"`,
329
- teamId: teamId as unknown as string,
330
- },
331
- requestId,
332
- ),
333
- );
315
+ // Racy — the team can be deleted between the preliminary get and the add.
316
+ const teamGone = () => {
317
+ c.status(statusFor('team-not-found') as never);
318
+ return c.json(
319
+ toWireError(
320
+ {
321
+ code: 'team-not-found',
322
+ message: `No team with id "${teamId as unknown as string}"`,
323
+ teamId: teamId as unknown as string,
324
+ },
325
+ requestId,
326
+ ),
327
+ );
328
+ };
329
+ if (authorizer !== undefined) {
330
+ const res = await tenantHierarchy.addTeamMember({
331
+ tenantId,
332
+ teamId,
333
+ userId: b.userId as unknown as UserId,
334
+ role: b.role as TeamRole,
335
+ });
336
+ if (res.kind === 'err') {
337
+ if (res.error.code === 'team-not-found') return teamGone();
338
+ throw new Error(res.error.message, { cause: res.error });
334
339
  }
335
- throw cause;
340
+ } else {
341
+ const outcome = await membershipBinding.add(tenantId, {
342
+ teamId,
343
+ userId: b.userId as unknown as UserId,
344
+ role: b.role,
345
+ });
346
+ if (outcome.kind === 'team-not-found') return teamGone();
336
347
  }
337
348
  c.status(201);
338
349
  return c.json({
@@ -387,38 +398,33 @@ export function teamsRouter(
387
398
  ),
388
399
  );
389
400
  }
390
- try {
391
- await membershipBinding.updateRole(tenantId, teamId, userId, b.role);
392
- } catch (cause) {
393
- const message = cause instanceof Error ? cause.message : String(cause);
394
- if (message.startsWith('team-membership-not-found')) {
395
- c.status(statusFor('team-membership-not-found') as never);
396
- return c.json(
397
- toWireError(
398
- {
399
- code: 'team-membership-not-found',
400
- message: `No membership for team "${teamId as unknown as string}" + user "${userId as unknown as string}"`,
401
- teamId: teamId as unknown as string,
402
- userId: userId as unknown as string,
403
- },
404
- requestId,
405
- ),
406
- );
407
- }
408
- if (message.startsWith('team-not-found')) {
409
- c.status(statusFor('team-not-found') as never);
410
- return c.json(
411
- toWireError(
412
- {
413
- code: 'team-not-found',
414
- message: `No team with id "${teamId as unknown as string}"`,
415
- teamId: teamId as unknown as string,
416
- },
417
- requestId,
418
- ),
419
- );
420
- }
421
- throw cause;
401
+ const outcome = await membershipBinding.updateRole(tenantId, teamId, userId, b.role);
402
+ if (outcome.kind === 'team-membership-not-found') {
403
+ c.status(statusFor('team-membership-not-found') as never);
404
+ return c.json(
405
+ toWireError(
406
+ {
407
+ code: 'team-membership-not-found',
408
+ message: `No membership for team "${teamId as unknown as string}" + user "${userId as unknown as string}"`,
409
+ teamId: teamId as unknown as string,
410
+ userId: userId as unknown as string,
411
+ },
412
+ requestId,
413
+ ),
414
+ );
415
+ }
416
+ if (outcome.kind === 'team-not-found') {
417
+ c.status(statusFor('team-not-found') as never);
418
+ return c.json(
419
+ toWireError(
420
+ {
421
+ code: 'team-not-found',
422
+ message: `No team with id "${teamId as unknown as string}"`,
423
+ teamId: teamId as unknown as string,
424
+ },
425
+ requestId,
426
+ ),
427
+ );
422
428
  }
423
429
  c.status(204);
424
430
  return c.body(null);
@@ -522,24 +528,24 @@ export function teamsRouter(
522
528
  );
523
529
  }
524
530
  }
525
- try {
526
- await binding.update(tenantId, teamId, shaped);
527
- } catch (cause) {
528
- const message = cause instanceof Error ? cause.message : String(cause);
529
- if (message.startsWith('team-not-found')) {
530
- c.status(statusFor('team-not-found') as never);
531
- return c.json(
532
- toWireError(
533
- {
534
- code: 'team-not-found',
535
- message: `No team with id "${teamId as unknown as string}"`,
536
- teamId: teamId as unknown as string,
537
- },
538
- requestId,
539
- ),
540
- );
541
- }
542
- throw cause;
531
+ const outcome = await binding.update(tenantId, teamId, shaped);
532
+ if (outcome.kind === 'team-not-found') {
533
+ c.status(statusFor('team-not-found') as never);
534
+ return c.json(
535
+ toWireError(
536
+ {
537
+ code: 'team-not-found',
538
+ message: `No team with id "${teamId as unknown as string}"`,
539
+ teamId: teamId as unknown as string,
540
+ },
541
+ requestId,
542
+ ),
543
+ );
544
+ }
545
+ if (outcome.kind === 'slug-conflict') {
546
+ const error = slugConflictError('team', outcome.slug);
547
+ c.status(statusFor(error.code) as never);
548
+ return c.json(toWireError(error, requestId));
543
549
  }
544
550
  c.status(204);
545
551
  return c.body(null);