rivet-design 0.17.5 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/dist/agent-variants/SessionStore.d.ts +5 -1
  2. package/dist/agent-variants/SessionStore.d.ts.map +1 -1
  3. package/dist/agent-variants/SessionStore.js +32 -3
  4. package/dist/agent-variants/SessionStore.js.map +1 -1
  5. package/dist/agent-variants/WorktreeOrchestrator.d.ts +6 -1
  6. package/dist/agent-variants/WorktreeOrchestrator.d.ts.map +1 -1
  7. package/dist/agent-variants/WorktreeOrchestrator.js +51 -15
  8. package/dist/agent-variants/WorktreeOrchestrator.js.map +1 -1
  9. package/dist/agent-variants/contracts.d.ts +2012 -108
  10. package/dist/agent-variants/contracts.d.ts.map +1 -1
  11. package/dist/agent-variants/contracts.js +10 -9
  12. package/dist/agent-variants/contracts.js.map +1 -1
  13. package/dist/agent-variants/variantContext.d.ts +6 -1
  14. package/dist/agent-variants/variantContext.d.ts.map +1 -1
  15. package/dist/agent-variants/variantContext.js +69 -1
  16. package/dist/agent-variants/variantContext.js.map +1 -1
  17. package/dist/cli/commandNames.d.ts.map +1 -1
  18. package/dist/cli/commandNames.js +1 -0
  19. package/dist/cli/commandNames.js.map +1 -1
  20. package/dist/cli/commands/mcpServe.d.ts.map +1 -1
  21. package/dist/cli/commands/mcpServe.js +95 -4
  22. package/dist/cli/commands/mcpServe.js.map +1 -1
  23. package/dist/cli/commands/profile.d.ts +3 -0
  24. package/dist/cli/commands/profile.d.ts.map +1 -0
  25. package/dist/cli/commands/profile.js +192 -0
  26. package/dist/cli/commands/profile.js.map +1 -0
  27. package/dist/cli/commands/reference.d.ts.map +1 -1
  28. package/dist/cli/commands/reference.js +4 -0
  29. package/dist/cli/commands/reference.js.map +1 -1
  30. package/dist/cli/commands/variants.d.ts.map +1 -1
  31. package/dist/cli/commands/variants.js +13 -1
  32. package/dist/cli/commands/variants.js.map +1 -1
  33. package/dist/cli/router.d.ts.map +1 -1
  34. package/dist/cli/router.js +8 -0
  35. package/dist/cli/router.js.map +1 -1
  36. package/dist/library/HubClient.d.ts +1 -0
  37. package/dist/library/HubClient.d.ts.map +1 -1
  38. package/dist/library/HubClient.js +11 -1
  39. package/dist/library/HubClient.js.map +1 -1
  40. package/dist/library/HubServer.d.ts.map +1 -1
  41. package/dist/library/HubServer.js +19 -0
  42. package/dist/library/HubServer.js.map +1 -1
  43. package/dist/routes/agentVariants.d.ts.map +1 -1
  44. package/dist/routes/agentVariants.js +126 -9
  45. package/dist/routes/agentVariants.js.map +1 -1
  46. package/dist/routes/library/app.d.ts.map +1 -1
  47. package/dist/routes/library/app.js +1 -2
  48. package/dist/routes/library/app.js.map +1 -1
  49. package/dist/routes/library/index.d.ts.map +1 -1
  50. package/dist/routes/library/index.js +3 -0
  51. package/dist/routes/library/index.js.map +1 -1
  52. package/dist/routes/library/profiles.d.ts +5 -0
  53. package/dist/routes/library/profiles.d.ts.map +1 -0
  54. package/dist/routes/library/profiles.js +182 -0
  55. package/dist/routes/library/profiles.js.map +1 -0
  56. package/dist/routes/library/schemas.d.ts +2 -2
  57. package/dist/routes/library/types.d.ts +2 -0
  58. package/dist/routes/library/types.d.ts.map +1 -1
  59. package/dist/services/IntegrationsClient.d.ts +20 -4
  60. package/dist/services/IntegrationsClient.d.ts.map +1 -1
  61. package/dist/services/IntegrationsClient.js +71 -4
  62. package/dist/services/IntegrationsClient.js.map +1 -1
  63. package/dist/services/ProjectRegistry.d.ts +2 -2
  64. package/dist/services/TelemetryService.d.ts +9 -0
  65. package/dist/services/TelemetryService.d.ts.map +1 -1
  66. package/dist/services/TelemetryService.js +11 -2
  67. package/dist/services/TelemetryService.js.map +1 -1
  68. package/dist/services/VariantGenerationService.d.ts +1 -0
  69. package/dist/services/VariantGenerationService.d.ts.map +1 -1
  70. package/dist/services/VariantGenerationService.js +31 -4
  71. package/dist/services/VariantGenerationService.js.map +1 -1
  72. package/dist/services/VariantHistoryService.d.ts +12 -0
  73. package/dist/services/VariantHistoryService.d.ts.map +1 -1
  74. package/dist/services/VariantHistoryService.js +54 -0
  75. package/dist/services/VariantHistoryService.js.map +1 -1
  76. package/dist/services/VariantRunService.d.ts +6 -0
  77. package/dist/services/VariantRunService.d.ts.map +1 -1
  78. package/dist/services/VariantRunService.js +86 -2
  79. package/dist/services/VariantRunService.js.map +1 -1
  80. package/dist/services/VariantsRuntime.d.ts.map +1 -1
  81. package/dist/services/VariantsRuntime.js +2 -0
  82. package/dist/services/VariantsRuntime.js.map +1 -1
  83. package/dist/services/profiles/DesignProfiles.d.ts +446 -0
  84. package/dist/services/profiles/DesignProfiles.d.ts.map +1 -0
  85. package/dist/services/profiles/DesignProfiles.js +552 -0
  86. package/dist/services/profiles/DesignProfiles.js.map +1 -0
  87. package/dist/services/profiles/MemoryModelService.d.ts +14 -0
  88. package/dist/services/profiles/MemoryModelService.d.ts.map +1 -0
  89. package/dist/services/profiles/MemoryModelService.js +113 -0
  90. package/dist/services/profiles/MemoryModelService.js.map +1 -0
  91. package/dist/services/profiles/MemoryRuntime.d.ts +26 -0
  92. package/dist/services/profiles/MemoryRuntime.d.ts.map +1 -0
  93. package/dist/services/profiles/MemoryRuntime.js +192 -0
  94. package/dist/services/profiles/MemoryRuntime.js.map +1 -0
  95. package/dist/services/profiles/ProfileAgent.d.ts +20 -0
  96. package/dist/services/profiles/ProfileAgent.d.ts.map +1 -0
  97. package/dist/services/profiles/ProfileAgent.js +196 -0
  98. package/dist/services/profiles/ProfileAgent.js.map +1 -0
  99. package/dist/services/profiles/ProfileAnalysis.d.ts +23 -0
  100. package/dist/services/profiles/ProfileAnalysis.d.ts.map +1 -0
  101. package/dist/services/profiles/ProfileAnalysis.js +114 -0
  102. package/dist/services/profiles/ProfileAnalysis.js.map +1 -0
  103. package/dist/services/profiles/ProfileImportSchedule.d.ts +15 -0
  104. package/dist/services/profiles/ProfileImportSchedule.d.ts.map +1 -0
  105. package/dist/services/profiles/ProfileImportSchedule.js +40 -0
  106. package/dist/services/profiles/ProfileImportSchedule.js.map +1 -0
  107. package/dist/services/profiles/ProfileImports.d.ts +47 -0
  108. package/dist/services/profiles/ProfileImports.d.ts.map +1 -0
  109. package/dist/services/profiles/ProfileImports.js +248 -0
  110. package/dist/services/profiles/ProfileImports.js.map +1 -0
  111. package/dist/services/profiles/ProfileIndex.d.ts +18 -0
  112. package/dist/services/profiles/ProfileIndex.d.ts.map +1 -0
  113. package/dist/services/profiles/ProfileIndex.js +119 -0
  114. package/dist/services/profiles/ProfileIndex.js.map +1 -0
  115. package/dist/services/profiles/ProfileMedia.d.ts +10 -0
  116. package/dist/services/profiles/ProfileMedia.d.ts.map +1 -0
  117. package/dist/services/profiles/ProfileMedia.js +76 -0
  118. package/dist/services/profiles/ProfileMedia.js.map +1 -0
  119. package/dist/services/profiles/ProfilePreparation.d.ts +17 -0
  120. package/dist/services/profiles/ProfilePreparation.d.ts.map +1 -0
  121. package/dist/services/profiles/ProfilePreparation.js +214 -0
  122. package/dist/services/profiles/ProfilePreparation.js.map +1 -0
  123. package/dist/services/profiles/ProfileVariants.d.ts +33 -0
  124. package/dist/services/profiles/ProfileVariants.d.ts.map +1 -0
  125. package/dist/services/profiles/ProfileVariants.js +129 -0
  126. package/dist/services/profiles/ProfileVariants.js.map +1 -0
  127. package/dist/services/profiles/analysisBatch.d.ts +53 -0
  128. package/dist/services/profiles/analysisBatch.d.ts.map +1 -0
  129. package/dist/services/profiles/analysisBatch.js +86 -0
  130. package/dist/services/profiles/analysisBatch.js.map +1 -0
  131. package/dist/services/profiles/boardPage.d.ts +12 -0
  132. package/dist/services/profiles/boardPage.d.ts.map +1 -0
  133. package/dist/services/profiles/boardPage.js +156 -0
  134. package/dist/services/profiles/boardPage.js.map +1 -0
  135. package/dist/services/profiles/engineAccess.d.ts +2 -0
  136. package/dist/services/profiles/engineAccess.d.ts.map +1 -0
  137. package/dist/services/profiles/engineAccess.js +55 -0
  138. package/dist/services/profiles/engineAccess.js.map +1 -0
  139. package/dist/services/profiles/memoryComponents.d.ts +7 -0
  140. package/dist/services/profiles/memoryComponents.d.ts.map +1 -0
  141. package/dist/services/profiles/memoryComponents.js +105 -0
  142. package/dist/services/profiles/memoryComponents.js.map +1 -0
  143. package/dist/services/profiles/modelContract.d.ts +14 -0
  144. package/dist/services/profiles/modelContract.d.ts.map +1 -0
  145. package/dist/services/profiles/modelContract.js +124 -0
  146. package/dist/services/profiles/modelContract.js.map +1 -0
  147. package/dist/services/profiles/nativeImages.d.ts +3 -0
  148. package/dist/services/profiles/nativeImages.d.ts.map +1 -0
  149. package/dist/services/profiles/nativeImages.js +72 -0
  150. package/dist/services/profiles/nativeImages.js.map +1 -0
  151. package/dist/services/profiles/profileAccount.d.ts +4 -0
  152. package/dist/services/profiles/profileAccount.d.ts.map +1 -0
  153. package/dist/services/profiles/profileAccount.js +21 -0
  154. package/dist/services/profiles/profileAccount.js.map +1 -0
  155. package/dist/services/profiles/profileContext.d.ts +18 -0
  156. package/dist/services/profiles/profileContext.d.ts.map +1 -0
  157. package/dist/services/profiles/profileContext.js +189 -0
  158. package/dist/services/profiles/profileContext.js.map +1 -0
  159. package/dist/services/profiles/profileEvidence.d.ts +3 -0
  160. package/dist/services/profiles/profileEvidence.d.ts.map +1 -0
  161. package/dist/services/profiles/profileEvidence.js +15 -0
  162. package/dist/services/profiles/profileEvidence.js.map +1 -0
  163. package/dist/services/profiles/profileQueries.d.ts +2 -0
  164. package/dist/services/profiles/profileQueries.d.ts.map +1 -0
  165. package/dist/services/profiles/profileQueries.js +23 -0
  166. package/dist/services/profiles/profileQueries.js.map +1 -0
  167. package/dist/services/profiles/profileSelection.d.ts +29 -0
  168. package/dist/services/profiles/profileSelection.d.ts.map +1 -0
  169. package/dist/services/profiles/profileSelection.js +43 -0
  170. package/dist/services/profiles/profileSelection.js.map +1 -0
  171. package/dist/services/profiles/xPage.d.ts +4 -0
  172. package/dist/services/profiles/xPage.d.ts.map +1 -0
  173. package/dist/services/profiles/xPage.js +58 -0
  174. package/dist/services/profiles/xPage.js.map +1 -0
  175. package/dist/services/referenceImages.d.ts +17 -0
  176. package/dist/services/referenceImages.d.ts.map +1 -0
  177. package/dist/services/referenceImages.js +138 -0
  178. package/dist/services/referenceImages.js.map +1 -0
  179. package/dist/storage/profiles/ProfileRecords.d.ts +199 -0
  180. package/dist/storage/profiles/ProfileRecords.d.ts.map +1 -0
  181. package/dist/storage/profiles/ProfileRecords.js +659 -0
  182. package/dist/storage/profiles/ProfileRecords.js.map +1 -0
  183. package/dist/storage/profiles/contextReceipts.d.ts +14 -0
  184. package/dist/storage/profiles/contextReceipts.d.ts.map +1 -0
  185. package/dist/storage/profiles/contextReceipts.js +52 -0
  186. package/dist/storage/profiles/contextReceipts.js.map +1 -0
  187. package/dist/storage/profiles/migrations.d.ts +4 -0
  188. package/dist/storage/profiles/migrations.d.ts.map +1 -0
  189. package/dist/storage/profiles/migrations.js +41 -0
  190. package/dist/storage/profiles/migrations.js.map +1 -0
  191. package/dist/storage/profiles/schema.d.ts +961 -0
  192. package/dist/storage/profiles/schema.d.ts.map +1 -0
  193. package/dist/storage/profiles/schema.js +102 -0
  194. package/dist/storage/profiles/schema.js.map +1 -0
  195. package/dist/types/change-request-types.d.ts +5 -0
  196. package/dist/types/change-request-types.d.ts.map +1 -1
  197. package/dist/types/design-profile.d.ts +570 -0
  198. package/dist/types/design-profile.d.ts.map +1 -0
  199. package/dist/types/design-profile.js +127 -0
  200. package/dist/types/design-profile.js.map +1 -0
  201. package/dist/types/variant-history.d.ts +3 -0
  202. package/dist/types/variant-history.d.ts.map +1 -1
  203. package/dist/types/variant-reference.d.ts +46 -0
  204. package/dist/types/variant-reference.d.ts.map +1 -0
  205. package/dist/types/variant-reference.js +58 -0
  206. package/dist/types/variant-reference.js.map +1 -0
  207. package/dist/types/x-bookmarks.d.ts +352 -0
  208. package/dist/types/x-bookmarks.d.ts.map +1 -0
  209. package/dist/types/x-bookmarks.js +56 -0
  210. package/dist/types/x-bookmarks.js.map +1 -0
  211. package/dist/utils/ProviderRateLimit.d.ts +7 -0
  212. package/dist/utils/ProviderRateLimit.d.ts.map +1 -0
  213. package/dist/utils/ProviderRateLimit.js +36 -0
  214. package/dist/utils/ProviderRateLimit.js.map +1 -0
  215. package/dist/utils/skills/cli-guidance.d.ts +1 -1
  216. package/dist/utils/skills/cli-guidance.d.ts.map +1 -1
  217. package/dist/utils/skills/cli-guidance.js +6 -2
  218. package/dist/utils/skills/cli-guidance.js.map +1 -1
  219. package/package.json +2 -1
  220. package/src/ui/dist/assets/{LibraryApp-x6PbzlGr.js → LibraryApp-Bu7hVbt_.js} +1 -1
  221. package/src/ui/dist/assets/main-CHyx_rEa.css +1 -0
  222. package/src/ui/dist/assets/main-CuiPb_rl.js +438 -0
  223. package/src/ui/dist/index.html +2 -2
  224. package/src/ui/dist/assets/main-BW1Odsqp.js +0 -438
  225. package/src/ui/dist/assets/main-DDQRZm89.css +0 -1
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analysisUsage = exports.analysisDescription = exports.prepareAnalysisBatch = exports.fitsAnalysisBatch = void 0;
4
+ const zod_1 = require("zod");
5
+ const MAX_REFERENCES = 4;
6
+ const MAX_IMAGES = 6;
7
+ const MAX_BYTES = 20 * 1024 * 1024;
8
+ const MAX_TEXT_CHARACTERS = 16_000;
9
+ const descriptionSchema = {
10
+ type: 'object',
11
+ properties: { description: { type: 'string' } },
12
+ required: ['description'],
13
+ additionalProperties: false,
14
+ };
15
+ const observationsSchema = {
16
+ type: 'object',
17
+ properties: {
18
+ observations: {
19
+ type: 'array',
20
+ items: {
21
+ type: 'object',
22
+ properties: { id: { type: 'string' }, description: { type: 'string' } },
23
+ required: ['id', 'description'],
24
+ additionalProperties: false,
25
+ },
26
+ },
27
+ },
28
+ required: ['observations'],
29
+ additionalProperties: false,
30
+ };
31
+ const description = zod_1.z.object({
32
+ description: zod_1.z.string().trim().min(1).max(8000),
33
+ });
34
+ const fitsAnalysisBatch = (references) => references.length <= MAX_REFERENCES &&
35
+ references.reduce((sum, item) => sum + item.media.length, 0) <= MAX_IMAGES &&
36
+ references.reduce((sum, item) => sum + item.text.length, 0) <=
37
+ MAX_TEXT_CHARACTERS &&
38
+ references.reduce((sum, item) => sum + item.media.reduce((bytes, media) => bytes + media.bytes, 0), 0) <= MAX_BYTES;
39
+ exports.fitsAnalysisBatch = fitsAnalysisBatch;
40
+ const prepareAnalysisBatch = (inputs) => {
41
+ const images = inputs.flatMap((input) => input.images);
42
+ const instruction = 'Describe the visible design of this reference in at most 100 words: layout, typography, color, material, and specific controls or imagery. Ground every claim in the actual image or supplied text. This is an observation, not a confirmed user preference.';
43
+ if (inputs.length === 1)
44
+ return {
45
+ images,
46
+ schema: descriptionSchema,
47
+ prompt: `${instruction} Reference text: ${inputs[0].reference.text}`,
48
+ };
49
+ let offset = 0;
50
+ const references = inputs.map(({ reference, images: paths }) => {
51
+ const imageIndexes = paths.map((_, index) => offset + index);
52
+ offset += paths.length;
53
+ return { id: reference.id, text: reference.text, imageIndexes };
54
+ });
55
+ return {
56
+ images,
57
+ schema: observationsSchema,
58
+ prompt: `Analyze each reference independently. For each reference: ${instruction} Return one observation per reference ID. Do not transfer details between references. imageIndexes are zero-based positions in the Reference files array; inspect only those images for that reference. When imageIndexes is empty, summarize only the supplied text and state that visual styling is unavailable; do not infer alignment, layout, typography, colors, materials, controls, or imagery. References: ${JSON.stringify(references)}`,
59
+ };
60
+ };
61
+ exports.prepareAnalysisBatch = prepareAnalysisBatch;
62
+ const analysisDescription = ({ value, referenceId, count, }) => {
63
+ if (count === 1)
64
+ return description.parse(value).description;
65
+ const { observations } = zod_1.z
66
+ .object({ observations: zod_1.z.array(zod_1.z.unknown()) })
67
+ .parse(value);
68
+ const matches = observations.filter((item) => zod_1.z.object({ id: zod_1.z.literal(referenceId) }).safeParse(item).success);
69
+ if (matches.length !== 1)
70
+ throw new Error('Reference analysis must contain exactly one result for its ID');
71
+ return description.parse(matches[0]).description;
72
+ };
73
+ exports.analysisDescription = analysisDescription;
74
+ const analysisUsage = (usage, count) => {
75
+ if (count === 1)
76
+ return usage;
77
+ const share = (tokens) => tokens === undefined ? undefined : tokens / count;
78
+ return {
79
+ inputTokens: share(usage.inputTokens),
80
+ outputTokens: share(usage.outputTokens),
81
+ cachedInputTokens: share(usage.cachedInputTokens),
82
+ allocation: 'equal-share',
83
+ };
84
+ };
85
+ exports.analysisUsage = analysisUsage;
86
+ //# sourceMappingURL=analysisBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analysisBatch.js","sourceRoot":"","sources":["../../../src/services/profiles/analysisBatch.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAUxB,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACnC,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,MAAM,iBAAiB,GAAG;IACxB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAC/C,QAAQ,EAAE,CAAC,aAAa,CAAC;IACzB,oBAAoB,EAAE,KAAK;CAC5B,CAAC;AACF,MAAM,kBAAkB,GAAG;IACzB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,YAAY,EAAE;YACZ,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;gBACvE,QAAQ,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC;gBAC/B,oBAAoB,EAAE,KAAK;aAC5B;SACF;KACF;IACD,QAAQ,EAAE,CAAC,cAAc,CAAC;IAC1B,oBAAoB,EAA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C3E,CAAC;IACF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;IACJ,OAAO,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;AACnD,CAAC,CAAC;AArBW,QAAA,mBAAmB,uBAqB9B;AAEK,MAAM,aAAa,GAAG,CAC3B,KAAmB,EACnB,KAAa,EACC,EAAE;IAChB,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9B,MAAM,KAAK,GAAG,CAAC,MAA0B,EAAE,EAAE,CAC3C,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC;IACpD,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC;QACrC,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC;QACvC,iBAAiB,EAAE,KAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC;QACjD,UAAU,EAAE,aAAa;KAC1B,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,aAAa,iBAaxB"}
@@ -0,0 +1,12 @@
1
+ import type { ProfileReferenceInput } from '../../types/design-profile';
2
+ export interface BoardPage {
3
+ remoteId: string;
4
+ title: string;
5
+ references: ProfileReferenceInput[];
6
+ cursor: string | null;
7
+ isComplete: boolean;
8
+ total?: number;
9
+ }
10
+ export declare const pinterestPage: (input: unknown, cursor: string | null) => BoardPage;
11
+ export declare const arenaPage: (input: unknown, cursor: string | null) => BoardPage;
12
+ //# sourceMappingURL=boardPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boardPage.d.ts","sourceRoot":"","sources":["../../../src/services/profiles/boardPage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,qBAAqB,EAAE,CAAC;IACpC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA6FD,eAAO,MAAM,aAAa,GACxB,OAAO,OAAO,EACd,QAAQ,MAAM,GAAG,IAAI,KACpB,SAiCF,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,EAAE,QAAQ,MAAM,GAAG,IAAI,KAAG,SAsCjE,CAAC"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.arenaPage = exports.pinterestPage = void 0;
4
+ const zod_1 = require("zod");
5
+ const optionalText = zod_1.z.string().nullable().optional();
6
+ const pin = zod_1.z.object({
7
+ id: zod_1.z.string().min(1),
8
+ image_urls: zod_1.z.array(zod_1.z.string().url()),
9
+ title: optionalText,
10
+ description: optionalText,
11
+ alt_text: optionalText,
12
+ });
13
+ const block = zod_1.z.object({
14
+ id: zod_1.z.string().min(1),
15
+ kind: zod_1.z.enum(['block', 'channel']),
16
+ block_type: optionalText,
17
+ title: optionalText,
18
+ description: optionalText,
19
+ content: optionalText,
20
+ image_urls: zod_1.z.array(zod_1.z.string().url()),
21
+ attachment_url: optionalText,
22
+ });
23
+ const pinterestResponse = zod_1.z.discriminatedUnion('type', [
24
+ zod_1.z.object({
25
+ status: zod_1.z.literal('ok'),
26
+ type: zod_1.z.literal('pin'),
27
+ pins: zod_1.z.tuple([pin]),
28
+ }),
29
+ zod_1.z.object({
30
+ status: zod_1.z.literal('ok'),
31
+ type: zod_1.z.literal('board'),
32
+ board: zod_1.z.object({ id: zod_1.z.string().min(1), name: optionalText }),
33
+ pins: zod_1.z.array(pin),
34
+ page: zod_1.z.object({
35
+ nextCursor: zod_1.z.string().min(1).nullable(),
36
+ isComplete: zod_1.z.boolean(),
37
+ }),
38
+ }),
39
+ ]);
40
+ const arenaResponse = zod_1.z.discriminatedUnion('type', [
41
+ zod_1.z.object({
42
+ status: zod_1.z.literal('ok'),
43
+ type: zod_1.z.literal('block'),
44
+ contents: zod_1.z.tuple([block.extend({ kind: zod_1.z.literal('block') })]),
45
+ }),
46
+ zod_1.z.object({
47
+ status: zod_1.z.literal('ok'),
48
+ type: zod_1.z.literal('channel'),
49
+ channel: zod_1.z.object({ id: zod_1.z.string().min(1), title: optionalText }),
50
+ contents: zod_1.z.array(block),
51
+ meta: zod_1.z.object({
52
+ current_page: zod_1.z.number().int().positive(),
53
+ total_pages: zod_1.z.number().int().nonnegative(),
54
+ total_count: zod_1.z.number().int().nonnegative().nullable().optional(),
55
+ has_more_pages: zod_1.z.boolean(),
56
+ }),
57
+ }),
58
+ ]);
59
+ const pinReference = (item) => ({
60
+ provider: 'pinterest',
61
+ remoteId: item.id,
62
+ title: item.title ?? 'Pinterest reference',
63
+ text: [item.description, item.alt_text].filter(Boolean).join('\n'),
64
+ media: [],
65
+ remoteImages: item.image_urls.length
66
+ ? [item.image_urls[item.image_urls.length - 1]]
67
+ : [],
68
+ url: `https://www.pinterest.com/pin/${item.id}/`,
69
+ });
70
+ const arenaReference = (item) => ({
71
+ provider: 'arena',
72
+ remoteId: item.kind === 'channel' ? `channel:${item.id}` : item.id,
73
+ title: item.title ?? 'Are.na reference',
74
+ text: [item.content, item.description].filter(Boolean).join('\n'),
75
+ media: [],
76
+ remoteImages: item.image_urls.length ? [item.image_urls[0]] : [],
77
+ url: `https://www.are.na/${item.kind === 'channel' ? 'channel' : 'block'}/${item.id}`,
78
+ ...(item.kind === 'channel'
79
+ ? {
80
+ unsupportedReason: 'Nested channel; connect it separately to import its contents',
81
+ }
82
+ : {}),
83
+ ...(item.kind !== 'channel' && !item.image_urls.length && !item.content
84
+ ? {
85
+ unsupportedReason: item.attachment_url
86
+ ? 'Attachment requires a supported document import'
87
+ : 'No supported image or text representation',
88
+ }
89
+ : {}),
90
+ });
91
+ const pinterestPage = (input, cursor) => {
92
+ const parsed = pinterestResponse.safeParse(input);
93
+ if (!parsed.success)
94
+ throw new Error('Pinterest must return one complete pin or a board with complete pagination metadata. The Rivet proxy must support board paging; public boards may be blocked by provider access.');
95
+ const data = parsed.data;
96
+ if (data.type === 'pin') {
97
+ if (cursor !== null)
98
+ throw new Error('Pinterest returned a pin during board continuation');
99
+ const reference = pinReference(data.pins[0]);
100
+ return {
101
+ remoteId: `pin:${reference.remoteId}`,
102
+ title: reference.title,
103
+ references: [reference],
104
+ cursor: null,
105
+ isComplete: true,
106
+ total: 1,
107
+ };
108
+ }
109
+ if (data.page.nextCursor === cursor && !data.page.isComplete)
110
+ throw new Error('Pinterest returned a repeated page cursor');
111
+ if (data.page.isComplete !== (data.page.nextCursor === null))
112
+ throw new Error('Pinterest pagination returned inconsistent exhaustion metadata');
113
+ return {
114
+ remoteId: data.board.id,
115
+ title: data.board.name ?? 'Pinterest board',
116
+ cursor: data.page.nextCursor,
117
+ isComplete: data.page.isComplete,
118
+ references: data.pins.map(pinReference),
119
+ };
120
+ };
121
+ exports.pinterestPage = pinterestPage;
122
+ const arenaPage = (input, cursor) => {
123
+ const data = arenaResponse.parse(input);
124
+ if (data.type === 'block') {
125
+ if (cursor !== null)
126
+ throw new Error('Are.na returned a block during channel continuation');
127
+ const reference = arenaReference(data.contents[0]);
128
+ return {
129
+ remoteId: `block:${reference.remoteId}`,
130
+ title: reference.title,
131
+ references: [reference],
132
+ cursor: null,
133
+ isComplete: true,
134
+ total: 1,
135
+ };
136
+ }
137
+ const page = Number(cursor ?? 1);
138
+ if (data.meta.current_page !== page)
139
+ throw new Error('Are.na returned a different page; the Rivet proxy must support channel paging');
140
+ const isComplete = !data.meta.has_more_pages;
141
+ if (data.meta.has_more_pages !== page < data.meta.total_pages ||
142
+ page > Math.max(1, data.meta.total_pages))
143
+ throw new Error('Are.na pagination returned inconsistent exhaustion metadata');
144
+ return {
145
+ remoteId: data.channel.id,
146
+ title: data.channel.title ?? 'Are.na channel',
147
+ cursor: isComplete ? null : String(page + 1),
148
+ isComplete,
149
+ ...(data.meta.total_count !== null && data.meta.total_count !== undefined
150
+ ? { total: data.meta.total_count }
151
+ : {}),
152
+ references: data.contents.map(arenaReference),
153
+ };
154
+ };
155
+ exports.arenaPage = arenaPage;
156
+ //# sourceMappingURL=boardPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boardPage.js","sourceRoot":"","sources":["../../../src/services/profiles/boardPage.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAWxB,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC;AACtD,MAAM,GAAG,GAAG,OAAC,CAAC,MAAM,CAAC;IACnB,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,UAAU,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;IACrC,KAAK,EAAE,YAAY;IACnB,WAAW,EAAE,YAAY;IACzB,QAAQ,EAAE,YAAY;CACvB,CAAC,CAAC;AACH,MAAM,KAAK,GAAG,OAAC,CAAC,MAAM,CAAC;IACrB,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAClC,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,YAAY;IACnB,WAAW,EAAE,YAAY;IACzB,OAAO,EAAE,YAAY;IACrB,UAAU,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;IACrC,cAAc,EAAE,YAAY;CAC7B,CAAC,CAAC;AACH,MAAM,iBAAiB,GAAG,OAAC,CAAC,kBAAkB,C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AAC,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;QAC5C,UAAU;QACV,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,KAAK,SAAS;YACvE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YAClC,CAAC,CAAC,EAAE,CAAC;QACP,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC;KAC9C,CAAC;AACJ,CAAC,CAAC;AAtCW,QAAA,SAAS,aAsCpB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=engineAccess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineAccess.d.ts","sourceRoot":"","sources":["../../../src/services/profiles/engineAccess.ts"],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_crypto_1 = require("node:crypto");
4
+ const node_net_1 = require("node:net");
5
+ const LOOPBACK_HOST = '127.0.0.1';
6
+ const MINIMUM_TOKEN_LENGTH = 32;
7
+ const token = process.env.RIVET_MEMORY_ACCESS_TOKEN;
8
+ const port = Number(process.env.SUPERMEMORY_PORT);
9
+ if (!token ||
10
+ token.length < MINIMUM_TOKEN_LENGTH ||
11
+ !Number.isInteger(port) ||
12
+ port <= 0) {
13
+ throw new Error('Engine access configuration is missing or invalid');
14
+ }
15
+ const expectedAuthorization = Buffer.from(`Bearer ${token}`);
16
+ const serve = Bun.serve.bind(Bun);
17
+ node_net_1.Server.prototype.listen = new Proxy(node_net_1.Server.prototype.listen, {
18
+ apply: (target, receiver, args) => {
19
+ const isEnginePortCheck = args[0] === port && args[1] === '0.0.0.0';
20
+ const parameters = isEnginePortCheck
21
+ ? [args[0], LOOPBACK_HOST, ...args.slice(2)]
22
+ : args;
23
+ return Reflect.apply(target, receiver, parameters);
24
+ },
25
+ });
26
+ Bun.serve = (options) => {
27
+ if (options.port !== port || typeof options.fetch !== 'function') {
28
+ throw new Error('Unexpected engine HTTP server configuration');
29
+ }
30
+ return serve({
31
+ ...options,
32
+ hostname: LOOPBACK_HOST,
33
+ fetch: (request, server) => {
34
+ const authorization = Buffer.from(request.headers.get('authorization') ?? '');
35
+ const isAuthorized = authorization.length === expectedAuthorization.length &&
36
+ (0, node_crypto_1.timingSafeEqual)(authorization, expectedAuthorization);
37
+ if (!isAuthorized) {
38
+ return Response.json({
39
+ error: {
40
+ code: 'AUTH_REQUIRED',
41
+ message: 'Engine authentication required',
42
+ },
43
+ }, { status: 401, headers: { 'Cache-Control': 'no-store' } });
44
+ }
45
+ return options.fetch(request, server);
46
+ },
47
+ });
48
+ };
49
+ const ownerPid = process.ppid;
50
+ const OWNER_CHECK_INTERVAL_MS = 2_000;
51
+ setInterval(() => {
52
+ if (process.ppid !== ownerPid)
53
+ process.exit(0);
54
+ }, OWNER_CHECK_INTERVAL_MS).unref();
55
+ //# sourceMappingURL=engineAccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineAccess.js","sourceRoot":"","sources":["../../../src/services/profiles/engineAccess.ts"],"names":[],"mappings":";;AAAA,6CAA8C;AAC9C,uCAAkC;AAUlC,MAAM,aAAa,GAAG,WAAW,CAAC;AAClC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;AACpD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAElD,IACE,CAAC,KAAK;IACN,KAAK,CAAC,MAAM,GAAG,oBAAoB;IACnC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;IACvB,IAAI,IAAI,CAAC,EACT,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,qBA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ACrD,IAAA,6BAAe,EAAC,aAAa,EAAE,qBAAqB,CAAC,CAAC;YACxD,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,QAAQ,CAAC,IAAI,CAClB;oBACE,KAAK,EAAE;wBACL,IAAI,EAAE,eAAe;wBACrB,OAAO,EAAE,gCAAgC;qBAC1C;iBACF,EACD,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE,EAAE,CAC1D,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;AAC9B,MAAM,uBAAuB,GAAG,KAAK,CAAC;AACtC,WAAW,CAAC,GAAG,EAAE;IACf,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC,EAAE,uBAAuB,CAAC,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const ENGINE_VERSION = "0.0.8";
2
+ export declare const EMBEDDING_REVISION = "4d6cd88e18e51a5e020c2c305726d76ada9c03cf";
3
+ export declare const installMemoryComponents: (root: string, cancellation?: AbortSignal) => Promise<{
4
+ binary: string;
5
+ models: string;
6
+ }>;
7
+ //# sourceMappingURL=memoryComponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryComponents.d.ts","sourceRoot":"","sources":["../../../src/services/profiles/memoryComponents.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc,UAAU,CAAC;AAGtC,eAAO,MAAM,kBAAkB,6CAA6C,CAAC;AA6E7E,eAAO,MAAM,uBAAuB,GAClC,MAAM,MAAM,EACZ,eAAe,WAAW,KACzB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CA+B5C,CAAC"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.installMemoryComponents = exports.EMBEDDING_REVISION = exports.ENGINE_VERSION = void 0;
7
+ const crypto_1 = require("crypto");
8
+ const fs_1 = require("fs");
9
+ const promises_1 = __importDefault(require("fs/promises"));
10
+ const path_1 = __importDefault(require("path"));
11
+ exports.ENGINE_VERSION = '0.0.8';
12
+ const ENGINE_HASH = '12b7817a105ed0a9e70f96c461fb6f8dded5d70eaeb6034e774778c257bed78a';
13
+ exports.EMBEDDING_REVISION = '4d6cd88e18e51a5e020c2c305726d76ada9c03cf';
14
+ const EMBEDDING_FILES = [
15
+ [
16
+ 'config.json',
17
+ 'd83c21fa7366994560727112ef0a31d8a2ec1c280c2a3e66326fdb877f64c91e',
18
+ ],
19
+ [
20
+ 'tokenizer_config.json',
21
+ '9261e7d79b44c8195c1cada2b453e55b00aeb81e907a6664974b4d7776172ab3',
22
+ ],
23
+ [
24
+ 'tokenizer.json',
25
+ 'd241a60d5e8f04cc1b2b3e9ef7a4921b27bf526d9f6050ab90f9267a1f9e5c66',
26
+ ],
27
+ [
28
+ 'onnx/model_quantized.onnx',
29
+ 'c9729cc84cbd0e9fecc759505d2be65916c9fe05222d7ea26c65fcb3382af38d',
30
+ ],
31
+ ];
32
+ const DOWNLOAD_TIMEOUT_MS = 10 * 60_000;
33
+ const MAX_COMPONENT_BYTES = 600 * 1024 * 1024;
34
+ const digest = async (file) => {
35
+ try {
36
+ const hash = (0, crypto_1.createHash)('sha256');
37
+ for await (const chunk of (0, fs_1.createReadStream)(file))
38
+ hash.update(chunk);
39
+ return hash.digest('hex');
40
+ }
41
+ catch (error) {
42
+ if (error.code === 'ENOENT')
43
+ return null;
44
+ throw error;
45
+ }
46
+ };
47
+ const install = async ({ file, url, hash, signal, }) => {
48
+ if ((await digest(file)) === hash)
49
+ return;
50
+ await promises_1.default.mkdir(path_1.default.dirname(file), { recursive: true, mode: 0o700 });
51
+ const staging = `${file}.${(0, crypto_1.randomUUID)()}.partial`;
52
+ const handle = await promises_1.default.open(staging, 'wx', 0o600);
53
+ try {
54
+ const response = await fetch(url, { signal });
55
+ if (!response.ok || !response.body)
56
+ throw new Error(`Profile component download failed (${response.status}); retry profile setup`);
57
+ let size = 0;
58
+ const reader = response.body.getReader();
59
+ while (true) {
60
+ const next = await reader.read();
61
+ if (next.done)
62
+ break;
63
+ const chunk = next.value;
64
+ size += chunk.length;
65
+ if (size > MAX_COMPONENT_BYTES)
66
+ throw new Error('Profile component exceeded its download limit');
67
+ await handle.writeFile(chunk);
68
+ }
69
+ await handle.close();
70
+ if ((await digest(staging)) !== hash)
71
+ throw new Error('Profile component checksum did not match the pinned release');
72
+ await promises_1.default.rename(staging, file);
73
+ }
74
+ finally {
75
+ await handle.close();
76
+ await promises_1.default.rm(staging, { force: true });
77
+ }
78
+ };
79
+ const installMemoryComponents = async (root, cancellation) => {
80
+ if (process.platform !== 'darwin' || process.arch !== 'arm64')
81
+ throw new Error('Design profiles are currently available on macOS Apple silicon; this platform has not been validated yet');
82
+ const signal = AbortSignal.any([
83
+ AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS),
84
+ ...(cancellation ? [cancellation] : []),
85
+ ]);
86
+ const binary = path_1.default.join(root, 'supermemory', exports.ENGINE_VERSION, 'supermemory-server-darwin-arm64');
87
+ await install({
88
+ file: binary,
89
+ url: `https://github.com/supermemoryai/supermemory/releases/download/server-v${exports.ENGINE_VERSION}/supermemory-server-darwin-arm64`,
90
+ hash: ENGINE_HASH,
91
+ signal,
92
+ });
93
+ await promises_1.default.chmod(binary, 0o700);
94
+ const models = path_1.default.join(root, 'embeddings', exports.EMBEDDING_REVISION);
95
+ for (const [name, hash] of EMBEDDING_FILES)
96
+ await install({
97
+ file: path_1.default.join(models, 'Xenova/bge-base-en-v1.5', name),
98
+ url: `https://huggingface.co/Xenova/bge-base-en-v1.5/resolve/${exports.EMBEDDING_REVISION}/${name}`,
99
+ hash,
100
+ signal,
101
+ });
102
+ return { binary, models };
103
+ };
104
+ exports.installMemoryComponents = installMemoryComponents;
105
+ //# sourceMappingURL=memoryComponents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryComponents.js","sourceRoot":"","sources":["../../../src/services/profiles/memoryComponents.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgD;AAChD,2BAAsC;AACtC,2DAA6B;AAC7B,gDAAwB;AAEX,QAAA,cAAc,GAAG,OAAO,CAAC;AACtC,MAAM,WAAW,GACf,kEAAkE,CAAC;AACxD,QAAA,kBAAkB,GAAG,0CAA0C,CAAC;AAC7E,MAAM,eAAe,GAAG;IACtB;QACE,aAAa;QACb,kEAAkE;KACnE;IACD;QACE,uBAAuB;QACvB,kEAAkE;KACnE;IACD;QACE,gBAAgB;QAChB,kEAAkE;KACnE;IACD;QACE,2BAA2B;QAC3B,kEAAkE;KACnE;CACO,CAAC;AACX,MAAM,mBAAmB,GAAG,EAAE,GAAG,MAAM,CAAC;AACxC,MAAM,mBAAmB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9C,MAAM,MAAM,GAAG,KAAK,EAAE,IAAY,EAA0B,EAAE;IAC5D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC;QAClC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAA,qBAAgB,EAAC,IAAI,CAAC;YAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACpE,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AY,EAAE,0BAAkB,CAAC,CAAC;IACjE,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,eAAe;QACxC,MAAM,OAAO,CAAC;YACZ,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,yBAAyB,EAAE,IAAI,CAAC;YACxD,GAAG,EAAE,0DAA0D,0BAAkB,IAAI,IAAI,EAAE;YAC3F,IAAI;YACJ,MAAM;SACP,CAAC,CAAC;IACL,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC,CAAC;AAlCW,QAAA,uBAAuB,2BAkClC"}
@@ -0,0 +1,14 @@
1
+ import type { ProfileUsage, ProfileRuntime } from '../../types/design-profile';
2
+ export interface ProfileAgentResult {
3
+ value: unknown;
4
+ usage: Record<string, unknown>;
5
+ inspectedImages: string[];
6
+ }
7
+ export declare const prepareModelRequest: (input: unknown) => {
8
+ prompt: string;
9
+ schema: Record<string, unknown>;
10
+ };
11
+ export declare const validateModelResult: (schema: Record<string, unknown>, value: unknown) => unknown;
12
+ export declare const readAgentResult: (runtime: ProfileRuntime, stdout: string, answer?: string) => ProfileAgentResult;
13
+ export declare const reportedProfileUsage: (usage: Record<string, unknown>) => ProfileUsage;
14
+ //# sourceMappingURL=modelContract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modelContract.d.ts","sourceRoot":"","sources":["../../../src/services/profiles/modelContract.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAyB/E,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,eAAO,MAAM,mBAAmB,GAC9B,OAAO,OAAO,KACb;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAenD,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,OAAO,KACb,OAUF,CAAC;AAmBF,eAAO,MAAM,eAAe,GAC1B,SAAS,cAAc,EACvB,QAAQ,MAAM,EACd,SAAS,MAAM,KACd,kBAqCF,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,YAeF,CAAC"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.reportedProfileUsage = exports.readAgentResult = exports.validateModelResult = exports.prepareModelRequest = void 0;
7
+ const ajv_1 = __importDefault(require("ajv"));
8
+ const zod_1 = require("zod");
9
+ const nativeImages_1 = require("./nativeImages");
10
+ const textBlock = zod_1.z.object({ type: zod_1.z.literal('text'), text: zod_1.z.string() });
11
+ const content = zod_1.z.union([zod_1.z.string(), zod_1.z.array(textBlock)]);
12
+ const modelRequest = zod_1.z
13
+ .object({
14
+ model: zod_1.z.string(),
15
+ max_tokens: zod_1.z.number().positive(),
16
+ stream: zod_1.z.literal(false).optional(),
17
+ system: content.optional(),
18
+ messages: zod_1.z
19
+ .array(zod_1.z.object({ role: zod_1.z.enum(['user', 'assistant']), content }))
20
+ .min(1),
21
+ output_config: zod_1.z.object({
22
+ format: zod_1.z.object({
23
+ type: zod_1.z.literal('json_schema'),
24
+ schema: zod_1.z.record(zod_1.z.unknown()),
25
+ }),
26
+ }),
27
+ temperature: zod_1.z.number().optional(),
28
+ top_p: zod_1.z.number().optional(),
29
+ })
30
+ .strict();
31
+ const prepareModelRequest = (input) => {
32
+ const request = modelRequest.parse(input);
33
+ const text = (value) => typeof value === 'string'
34
+ ? value
35
+ : value.map((block) => block.text).join('\n');
36
+ const prompt = [
37
+ request.system ? text(request.system) : '',
38
+ ...request.messages.map((message) => `${message.role}: ${text(message.content)}`),
39
+ ]
40
+ .filter(Boolean)
41
+ .join('\n\n');
42
+ return { prompt, schema: request.output_config.format.schema };
43
+ };
44
+ exports.prepareModelRequest = prepareModelRequest;
45
+ const validateModelResult = (schema, value) => {
46
+ const ajv = new ajv_1.default({
47
+ strict: false,
48
+ validateFormats: false,
49
+ ownProperties: true,
50
+ });
51
+ const validate = ajv.compile(schema);
52
+ if (!validate(value))
53
+ throw new Error('Agent result does not match the requested schema');
54
+ return value;
55
+ };
56
+ exports.validateModelResult = validateModelResult;
57
+ const answerObject = (answer) => {
58
+ try {
59
+ return JSON.parse(answer);
60
+ }
61
+ catch {
62
+ const fences = [...answer.matchAll(/```(?:json)?\s*([\s\S]*?)\s*```/g)];
63
+ if (!answer.includes('```')) {
64
+ const start = answer.indexOf('{');
65
+ const end = answer.lastIndexOf('}');
66
+ if (start >= 0 && end > start)
67
+ return JSON.parse(answer.slice(start, end + 1));
68
+ }
69
+ if (fences.length !== 1 || (answer.match(/```/g) ?? []).length !== 2)
70
+ throw new Error('Agent did not return one unambiguous JSON answer');
71
+ return JSON.parse(fences[0][1]);
72
+ }
73
+ };
74
+ const readAgentResult = (runtime, stdout, answer) => {
75
+ const events = stdout
76
+ .split('\n')
77
+ .flatMap((line) => {
78
+ try {
79
+ return [zod_1.z.record(zod_1.z.unknown()).parse(JSON.parse(line))];
80
+ }
81
+ catch {
82
+ return [];
83
+ }
84
+ });
85
+ if (events.some((event) => event.type === 'turn.failed' || event.is_error === true))
86
+ throw new Error(`${runtime} could not complete the profile task`);
87
+ if (runtime === 'codex') {
88
+ const finished = events.find((event) => event.type === 'turn.completed');
89
+ if (!finished || !answer)
90
+ throw new Error('Codex did not return a completed profile task');
91
+ return {
92
+ value: answerObject(answer),
93
+ usage: zod_1.z.record(zod_1.z.unknown()).parse(finished.usage ?? {}),
94
+ inspectedImages: [],
95
+ };
96
+ }
97
+ const results = events.filter((event) => event.type === 'result');
98
+ const finished = results[results.length - 1];
99
+ if (!finished)
100
+ throw new Error(`${runtime} did not return a completed profile task`);
101
+ return {
102
+ value: finished.structured_output ??
103
+ answerObject(zod_1.z.string().parse(finished.result)),
104
+ usage: zod_1.z.record(zod_1.z.unknown()).parse(finished.usage ?? {}),
105
+ inspectedImages: (0, nativeImages_1.readNativeImagePaths)(runtime, events),
106
+ };
107
+ };
108
+ exports.readAgentResult = readAgentResult;
109
+ const reportedProfileUsage = (usage) => {
110
+ const count = (key) => typeof usage[key] === 'number' &&
111
+ Number.isFinite(usage[key]) &&
112
+ usage[key] >= 0
113
+ ? usage[key]
114
+ : undefined;
115
+ return {
116
+ inputTokens: count('input_tokens') ?? count('inputTokens'),
117
+ outputTokens: count('output_tokens') ?? count('outputTokens'),
118
+ cachedInputTokens: count('cached_input_tokens') ??
119
+ count('cache_read_input_tokens') ??
120
+ count('cacheReadTokens'),
121
+ };
122
+ };
123
+ exports.reportedProfileUsage = reportedProfileUsage;
124
+ //# sourceMappingURL=modelContract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modelContract.js","sourceRoot":"","sources":["../../../src/services/profiles/modelContract.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,6BAAwB;AAExB,iDAAsD;AAEtD,MAAM,SAAS,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC1E,MAAM,OAAO,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC1D,MAAM,YAAY,GAAG,OAAC;KACnB,MAAM,CAAC;IACN,KAAK,EAAE,OAAC,CAAC,MAAM,EA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,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3B,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QACb,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC;QACZ,CAAC,CAAC,SAAS,CAAC;IAChB,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC;QAC1D,YAAY,EAAE,KAAK,CAAC,eAAe,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC;QAC7D,iBAAiB,EACf,KAAK,CAAC,qBAAqB,CAAC;YAC5B,KAAK,CAAC,yBAAyB,CAAC;YAChC,KAAK,CAAC,iBAAiB,CAAC;KAC3B,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,oBAAoB,wBAiB/B"}
@@ -0,0 +1,3 @@
1
+ import type { ProfileRuntime } from '../../types/design-profile';
2
+ export declare const readNativeImagePaths: (runtime: ProfileRuntime, events: Array<Record<string, unknown>>) => string[];
3
+ //# sourceMappingURL=nativeImages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeImages.d.ts","sourceRoot":"","sources":["../../../src/services/profiles/nativeImages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AA+BjE,eAAO,MAAM,oBAAoB,GAC/B,SAAS,cAAc,EACvB,QAAQ,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KACrC,MAAM,EAkCR,CAAC"}