@sixb/server 0.1.20 → 0.1.22

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 (179) hide show
  1. package/dist/artifacts/frame.d.ts +18 -0
  2. package/dist/artifacts/frame.d.ts.map +1 -0
  3. package/dist/auth/browser-origin.d.ts +10 -1
  4. package/dist/auth/browser-origin.d.ts.map +1 -1
  5. package/dist/auth/experience.d.ts +1 -0
  6. package/dist/auth/experience.d.ts.map +1 -1
  7. package/dist/auth/public-routes.d.ts.map +1 -1
  8. package/dist/auth/responses.d.ts +1 -1
  9. package/dist/auth/responses.d.ts.map +1 -1
  10. package/dist/auth/scope.d.ts +19 -3
  11. package/dist/auth/scope.d.ts.map +1 -1
  12. package/dist/files/content.d.ts +2 -3
  13. package/dist/files/content.d.ts.map +1 -1
  14. package/dist/index.js +10636 -7071
  15. package/dist/index.js.map +56 -38
  16. package/dist/models/display.d.ts +27 -0
  17. package/dist/models/display.d.ts.map +1 -1
  18. package/dist/openapi/components.d.ts +14 -0
  19. package/dist/openapi/components.d.ts.map +1 -0
  20. package/dist/openapi/tags.d.ts +22 -2
  21. package/dist/openapi/tags.d.ts.map +1 -1
  22. package/dist/registerRoutes.d.ts +3 -0
  23. package/dist/registerRoutes.d.ts.map +1 -1
  24. package/dist/routes/actions.d.ts +5 -5
  25. package/dist/routes/activity.d.ts +35 -0
  26. package/dist/routes/activity.d.ts.map +1 -0
  27. package/dist/routes/agent-api-gateway.d.ts.map +1 -1
  28. package/dist/routes/agent-approval-gate.d.ts +27 -0
  29. package/dist/routes/agent-approval-gate.d.ts.map +1 -0
  30. package/dist/routes/agent-approvals.d.ts +599 -0
  31. package/dist/routes/agent-approvals.d.ts.map +1 -0
  32. package/dist/routes/agent-children.d.ts +318 -0
  33. package/dist/routes/agent-children.d.ts.map +1 -0
  34. package/dist/routes/agent-memory.d.ts +267 -0
  35. package/dist/routes/agent-memory.d.ts.map +1 -0
  36. package/dist/routes/agents.d.ts +1008 -98
  37. package/dist/routes/agents.d.ts.map +1 -1
  38. package/dist/routes/ai-accounting.d.ts.map +1 -1
  39. package/dist/routes/artifact-frames.d.ts +98 -0
  40. package/dist/routes/artifact-frames.d.ts.map +1 -0
  41. package/dist/routes/artifacts.d.ts +1508 -0
  42. package/dist/routes/artifacts.d.ts.map +1 -0
  43. package/dist/routes/auth.d.ts +117 -11
  44. package/dist/routes/auth.d.ts.map +1 -1
  45. package/dist/routes/connector-connection-runs.d.ts +84 -84
  46. package/dist/routes/connector-connections.d.ts +2 -2
  47. package/dist/routes/connectors.d.ts +2 -2
  48. package/dist/routes/datasets.d.ts +27 -27
  49. package/dist/routes/events.d.ts +5 -5
  50. package/dist/routes/files.d.ts +14 -14
  51. package/dist/routes/files.d.ts.map +1 -1
  52. package/dist/routes/links.d.ts +2 -2
  53. package/dist/routes/logs.d.ts +5 -5
  54. package/dist/routes/model-calls.d.ts +155 -0
  55. package/dist/routes/model-calls.d.ts.map +1 -0
  56. package/dist/routes/model-generations.d.ts +400 -0
  57. package/dist/routes/model-generations.d.ts.map +1 -0
  58. package/dist/routes/models.d.ts +434 -1
  59. package/dist/routes/models.d.ts.map +1 -1
  60. package/dist/routes/objects.d.ts +71 -40
  61. package/dist/routes/objects.d.ts.map +1 -1
  62. package/dist/routes/observed-agent-threads.d.ts +682 -0
  63. package/dist/routes/observed-agent-threads.d.ts.map +1 -0
  64. package/dist/routes/ontology.d.ts +66 -62
  65. package/dist/routes/ontology.d.ts.map +1 -1
  66. package/dist/routes/pipelines.d.ts +53 -53
  67. package/dist/routes/projections.d.ts +63 -63
  68. package/dist/routes/rules.d.ts +2 -2
  69. package/dist/routes/share-grants.d.ts +4 -4
  70. package/dist/routes/syncs.d.ts +18 -18
  71. package/dist/routes/users.d.ts +117 -0
  72. package/dist/routes/users.d.ts.map +1 -0
  73. package/dist/routes/webhook-runs.d.ts +1 -1
  74. package/dist/routes/workflows.d.ts +142 -76
  75. package/dist/routes/workflows.d.ts.map +1 -1
  76. package/dist/routes/ws/agents.d.ts +7 -2
  77. package/dist/routes/ws/agents.d.ts.map +1 -1
  78. package/dist/routes/ws/events.d.ts +6 -6
  79. package/dist/routes/ws/events.d.ts.map +1 -1
  80. package/dist/routes/ws/logs.d.ts +14 -14
  81. package/dist/routes/ws/subscription-hub.d.ts +8 -3
  82. package/dist/routes/ws/subscription-hub.d.ts.map +1 -1
  83. package/dist/schemas/actions.d.ts +15 -15
  84. package/dist/schemas/activity.d.ts +1298 -0
  85. package/dist/schemas/activity.d.ts.map +1 -0
  86. package/dist/schemas/agent-approvals.d.ts +1091 -0
  87. package/dist/schemas/agent-approvals.d.ts.map +1 -0
  88. package/dist/schemas/agent-memory.d.ts +250 -0
  89. package/dist/schemas/agent-memory.d.ts.map +1 -0
  90. package/dist/schemas/agents.d.ts +5485 -460
  91. package/dist/schemas/agents.d.ts.map +1 -1
  92. package/dist/schemas/ai-accounting.d.ts +1315 -436
  93. package/dist/schemas/ai-accounting.d.ts.map +1 -1
  94. package/dist/schemas/ai-limits.d.ts +36 -36
  95. package/dist/schemas/ai-usage.d.ts +12 -0
  96. package/dist/schemas/ai-usage.d.ts.map +1 -1
  97. package/dist/schemas/artifacts.d.ts +1857 -0
  98. package/dist/schemas/artifacts.d.ts.map +1 -0
  99. package/dist/schemas/auth.d.ts +125 -52
  100. package/dist/schemas/auth.d.ts.map +1 -1
  101. package/dist/schemas/connectors.d.ts +42 -42
  102. package/dist/schemas/datasets.d.ts +108 -108
  103. package/dist/schemas/event-payloads.d.ts +6 -6
  104. package/dist/schemas/events.d.ts +32 -32
  105. package/dist/schemas/events.d.ts.map +1 -1
  106. package/dist/schemas/files.d.ts +24 -24
  107. package/dist/schemas/links.d.ts +2 -2
  108. package/dist/schemas/logs.d.ts +32 -32
  109. package/dist/schemas/models.d.ts +8889 -10
  110. package/dist/schemas/models.d.ts.map +1 -1
  111. package/dist/schemas/objects.d.ts +48 -12
  112. package/dist/schemas/objects.d.ts.map +1 -1
  113. package/dist/schemas/ontology.d.ts +127 -104
  114. package/dist/schemas/ontology.d.ts.map +1 -1
  115. package/dist/schemas/pipelines.d.ts +166 -166
  116. package/dist/schemas/projections.d.ts +346 -346
  117. package/dist/schemas/rules.d.ts +4 -4
  118. package/dist/schemas/share-grants.d.ts +14 -14
  119. package/dist/schemas/syncs.d.ts +40 -40
  120. package/dist/schemas/users.d.ts +72 -0
  121. package/dist/schemas/users.d.ts.map +1 -0
  122. package/dist/schemas/webhook-runs.d.ts +6 -6
  123. package/dist/schemas/workflows.d.ts +769 -254
  124. package/dist/schemas/workflows.d.ts.map +1 -1
  125. package/dist/server.d.ts +1 -0
  126. package/dist/server.d.ts.map +1 -1
  127. package/dist/utils/http.d.ts.map +1 -1
  128. package/package.json +7 -7
  129. package/src/artifacts/frame.ts +51 -0
  130. package/src/auth/browser-origin.ts +20 -5
  131. package/src/auth/experience.ts +1 -1
  132. package/src/auth/guard.ts +2 -2
  133. package/src/auth/public-routes.ts +16 -0
  134. package/src/auth/responses.ts +7 -6
  135. package/src/auth/scope.ts +32 -3
  136. package/src/files/content.ts +9 -13
  137. package/src/models/display.ts +61 -16
  138. package/src/openapi/components.ts +54 -0
  139. package/src/openapi/tags.ts +20 -0
  140. package/src/registerRoutes.ts +23 -0
  141. package/src/routes/activity.ts +327 -0
  142. package/src/routes/agent-api-gateway.ts +115 -91
  143. package/src/routes/agent-approval-gate.ts +213 -0
  144. package/src/routes/agent-approvals.ts +299 -0
  145. package/src/routes/agent-children.ts +209 -0
  146. package/src/routes/agent-memory.ts +210 -0
  147. package/src/routes/agents.ts +364 -143
  148. package/src/routes/ai-accounting.ts +4 -0
  149. package/src/routes/artifact-frames.ts +144 -0
  150. package/src/routes/artifacts.ts +717 -0
  151. package/src/routes/auth.ts +306 -13
  152. package/src/routes/file-downloads.ts +1 -3
  153. package/src/routes/files.ts +6 -7
  154. package/src/routes/model-calls.ts +120 -0
  155. package/src/routes/model-generations.ts +245 -0
  156. package/src/routes/models.ts +116 -9
  157. package/src/routes/objects.ts +55 -61
  158. package/src/routes/observed-agent-threads.ts +253 -0
  159. package/src/routes/ontology.ts +1 -0
  160. package/src/routes/users.ts +73 -0
  161. package/src/routes/workflows.ts +6 -9
  162. package/src/routes/ws/agents.ts +10 -5
  163. package/src/routes/ws/events.ts +3 -2
  164. package/src/routes/ws/subscription-hub.ts +53 -20
  165. package/src/schemas/activity.ts +287 -0
  166. package/src/schemas/agent-approvals.ts +129 -0
  167. package/src/schemas/agent-memory.ts +96 -0
  168. package/src/schemas/agents.ts +240 -2
  169. package/src/schemas/ai-accounting.ts +40 -4
  170. package/src/schemas/ai-usage.ts +10 -0
  171. package/src/schemas/artifacts.ts +246 -0
  172. package/src/schemas/auth.ts +25 -0
  173. package/src/schemas/models.ts +197 -1
  174. package/src/schemas/objects.ts +181 -0
  175. package/src/schemas/ontology.ts +1 -0
  176. package/src/schemas/users.ts +24 -0
  177. package/src/schemas/workflows.ts +2 -0
  178. package/src/server.ts +34 -19
  179. package/src/utils/http.ts +2 -0
@@ -63,6 +63,10 @@ function serializeOverview(overview: AiAccountingOverview) {
63
63
  modelId: model.modelId,
64
64
  ...serializeAggregate(model),
65
65
  })),
66
+ kinds: overview.kinds.map((kind) => ({
67
+ ...(kind.modelKind === undefined ? {} : { modelKind: kind.modelKind }),
68
+ ...serializeAggregate(kind),
69
+ })),
66
70
  agents: overview.agents.map((agent) => ({
67
71
  kind: agent.kind,
68
72
  ...(agent.kind === "workflowAgent"
@@ -0,0 +1,144 @@
1
+ import type { SixbHostView } from "@sixb/core"
2
+ import { parseArtifactAddress } from "@sixb/core/artifacts"
3
+ import {
4
+ ARTIFACT_FRAME_ROUTE_PREFIX,
5
+ FRAME_ASSETS,
6
+ FRAME_REFERENCE_PREFIX,
7
+ frameEntries,
8
+ frameLayout,
9
+ injectFrameAssets,
10
+ resolveArtifactFrame,
11
+ rewriteFrameReferences,
12
+ } from "@sixb/core/internal/artifacts/frames"
13
+ import { openFileRef } from "@sixb/core/internal/blob-storage"
14
+ import type { Elysia } from "elysia"
15
+ import { frameContentSecurityPolicy } from "../artifacts/frame"
16
+ import type { ResolvedSixbApiBrowserPolicy } from "../auth/browser-origin"
17
+ import { createFileContentResponse } from "../files/content"
18
+
19
+ interface FrameContext {
20
+ readonly params: { readonly token: string; readonly "*": string }
21
+ readonly request: Request
22
+ }
23
+
24
+ /**
25
+ * Serves a version's files to its sandboxed frame, under the token a frame link carries: the token
26
+ * is the credential, so the route is public. Each entry gets its layout's kit and the runtime,
27
+ * which are served beside the files. Hidden from OpenAPI: clients receive frame links, they
28
+ * never build them.
29
+ */
30
+ export function registerArtifactFrameRoutes(
31
+ app: Elysia,
32
+ host: SixbHostView,
33
+ policy: ResolvedSixbApiBrowserPolicy
34
+ ) {
35
+ const path = `${ARTIFACT_FRAME_ROUTE_PREFIX}:token/*`
36
+ return app
37
+ .get(path, (context) => frameResponse(host, policy, context), { detail: { hide: true } })
38
+ .head(path, (context) => frameResponse(host, policy, context, { head: true }), {
39
+ detail: { hide: true },
40
+ })
41
+ }
42
+
43
+ async function frameResponse(
44
+ host: SixbHostView,
45
+ policy: ResolvedSixbApiBrowserPolicy,
46
+ { params, request }: FrameContext,
47
+ options: { readonly head?: boolean } = {}
48
+ ): Promise<Response> {
49
+ const headers = new Headers({
50
+ "content-security-policy": frameContentSecurityPolicy({ policy, request, token: params.token }),
51
+ // The frame's origin is opaque, so its module scripts and fonts arrive with `Origin: null`.
52
+ // Nothing here depends on cookies: the token is the credential.
53
+ "access-control-allow-origin": "*",
54
+ "x-content-type-options": "nosniff",
55
+ "referrer-policy": "no-referrer",
56
+ })
57
+ const notFound = () => {
58
+ headers.set("content-type", "text/plain; charset=utf-8")
59
+ headers.set("cache-control", "no-store")
60
+ return new Response(options.head ? null : "Not found", { status: 404, headers })
61
+ }
62
+
63
+ // A frame link opens only in a frame. Opened as a page on the API's origin, its sandbox would
64
+ // still let it show dialogs under the API's address, with no app policy to hold where it goes.
65
+ if (request.headers.get("sec-fetch-dest") === "document") return notFound()
66
+
67
+ const storage = host.storage.artifacts
68
+ if (!storage) return notFound()
69
+ // An unknown or expired token, a deleted version, and a kind with no frame all answer one 404.
70
+ const frame = await resolveArtifactFrame({
71
+ projectId: host.id,
72
+ storage,
73
+ token: params.token,
74
+ })
75
+ if (!frame) return notFound()
76
+ let version = frame.version
77
+
78
+ let path = decodePath(params["*"])
79
+ const asset = path === null ? undefined : FRAME_ASSETS[path]
80
+ if (asset) {
81
+ headers.set("content-type", asset.type)
82
+ headers.set("cache-control", "private, max-age=3600")
83
+ return new Response(options.head ? null : asset.body, { headers })
84
+ }
85
+ let lent = false
86
+ if (path?.startsWith(FRAME_REFERENCE_PREFIX)) {
87
+ // A file another artifact lends this one: only one its frame was issued with, at that version.
88
+ const match = /^([^/@]+)@(\d+)\/(.+)$/.exec(path.slice(FRAME_REFERENCE_PREFIX.length))
89
+ const target = frame.targets.find(
90
+ (candidate) =>
91
+ candidate.artifactId === match?.[1] &&
92
+ candidate.version === Number(match?.[2]) &&
93
+ parseArtifactAddress(candidate.address)?.path === match?.[3]
94
+ )
95
+ const lender = target
96
+ ? await storage.getVersion({
97
+ projectId: host.id,
98
+ artifactId: target.artifactId,
99
+ version: target.version,
100
+ })
101
+ : null
102
+ if (!lender || !match) return notFound()
103
+ version = lender
104
+ path = match[3] ?? null
105
+ lent = true
106
+ }
107
+ const file = version.files.find((candidate) => candidate.path === path)
108
+ if (!file) return notFound()
109
+
110
+ const layout = frameLayout(version.outline.kind)
111
+ if (!lent && layout && frameEntries(version).includes(file.path)) {
112
+ const opened = await openFileRef(host.blobStorage, file.file)
113
+ if (!opened) return notFound()
114
+ headers.set("content-type", "text/html; charset=utf-8")
115
+ headers.set("cache-control", "private, no-cache")
116
+ if (options.head) return new Response(null, { headers })
117
+ const text = await new Response(opened.body).text()
118
+ return new Response(
119
+ injectFrameAssets(rewriteFrameReferences(text, frame.targets, file.path), layout, file.path),
120
+ { headers }
121
+ )
122
+ }
123
+
124
+ const response = await createFileContentResponse({
125
+ blobStorage: host.blobStorage,
126
+ fileRef: file.file,
127
+ disposition: "inline",
128
+ head: options.head,
129
+ request,
130
+ })
131
+ if (!response) return notFound()
132
+ // A frame loads its files as the page's parts: inline, under the frame's own policy.
133
+ for (const [name, value] of headers) response.headers.set(name, value)
134
+ response.headers.set("content-disposition", "inline")
135
+ return response
136
+ }
137
+
138
+ function decodePath(raw: string | undefined): string | null {
139
+ try {
140
+ return decodeURIComponent(raw ?? "")
141
+ } catch {
142
+ return null
143
+ }
144
+ }