|
4 | 4 | AuthOrchestrationOperateScope, |
5 | 5 | AuthSettingsWriteScope, |
6 | 6 | type AuthEnvironmentScope, |
| 7 | + EnvironmentAuthenticatedPrincipal, |
7 | 8 | EnvironmentHttpApi, |
| 9 | + type EnvironmentSpeechModels, |
8 | 10 | EnvironmentVoiceBodyLimit, |
9 | 11 | SPEECH_MAX_OPTIONS_BYTES, |
10 | 12 | } from "@t3tools/contracts"; |
@@ -54,6 +56,14 @@ const mapSpeechError = <A, R>(effect: Effect.Effect<A, SpeechService.SpeechError |
54 | 56 | }), |
55 | 57 | ); |
56 | 58 |
|
| 59 | +// A linked model's origin is a path on this machine; only filesystem readers may see it. |
| 60 | +// Untraced: it runs inside each handler's own span. |
| 61 | +const withoutHostPaths = Effect.fnUntraced(function* (result: EnvironmentSpeechModels) { |
| 62 | + const session = yield* EnvironmentAuthenticatedPrincipal; |
| 63 | + if (session.scopes.has(AuthFilesystemReadScope)) return result; |
| 64 | + return { models: result.models.map(({ linkedFrom: _, ...model }) => model) }; |
| 65 | +}); |
| 66 | + |
57 | 67 | export const speechHttpApiLayer = HttpApiBuilder.group( |
58 | 68 | EnvironmentHttpApi, |
59 | 69 | "voice", |
@@ -134,35 +144,45 @@ export const speechHttpApiLayer = HttpApiBuilder.group( |
134 | 144 | "models", |
135 | 145 | Effect.fn("environment.voice.models")(function* (args) { |
136 | 146 | yield* guard(args.endpoint.name); |
137 | | - return yield* speech.models(args.query.benchmarks === "1").pipe(mapSpeechError); |
| 147 | + return yield* speech |
| 148 | + .models(args.query.benchmarks === "1") |
| 149 | + .pipe(mapSpeechError, Effect.flatMap(withoutHostPaths)); |
138 | 150 | }), |
139 | 151 | ) |
140 | 152 | .handle( |
141 | 153 | "downloadModel", |
142 | 154 | Effect.fn("environment.voice.downloadModel")(function* (args) { |
143 | 155 | yield* guard(args.endpoint.name, AuthSettingsWriteScope); |
144 | | - return yield* speech.downloadModel(args.payload.modelId).pipe(mapSpeechError); |
| 156 | + return yield* speech |
| 157 | + .downloadModel(args.payload.modelId) |
| 158 | + .pipe(mapSpeechError, Effect.flatMap(withoutHostPaths)); |
145 | 159 | }), |
146 | 160 | ) |
147 | 161 | .handle( |
148 | 162 | "selectModel", |
149 | 163 | Effect.fn("environment.voice.selectModel")(function* (args) { |
150 | 164 | yield* guard(args.endpoint.name, AuthSettingsWriteScope); |
151 | | - return yield* speech.selectModel(args.payload.modelId).pipe(mapSpeechError); |
| 165 | + return yield* speech |
| 166 | + .selectModel(args.payload.modelId) |
| 167 | + .pipe(mapSpeechError, Effect.flatMap(withoutHostPaths)); |
152 | 168 | }), |
153 | 169 | ) |
154 | 170 | .handle( |
155 | 171 | "cancelModelDownload", |
156 | 172 | Effect.fn("environment.voice.cancelModelDownload")(function* (args) { |
157 | 173 | yield* guard(args.endpoint.name, AuthSettingsWriteScope); |
158 | | - return yield* speech.cancelDownload(args.payload.modelId).pipe(mapSpeechError); |
| 174 | + return yield* speech |
| 175 | + .cancelDownload(args.payload.modelId) |
| 176 | + .pipe(mapSpeechError, Effect.flatMap(withoutHostPaths)); |
159 | 177 | }), |
160 | 178 | ) |
161 | 179 | .handle( |
162 | 180 | "removeModel", |
163 | 181 | Effect.fn("environment.voice.removeModel")(function* (args) { |
164 | 182 | yield* guard(args.endpoint.name, AuthSettingsWriteScope); |
165 | | - return yield* speech.removeModel(args.payload.modelId).pipe(mapSpeechError); |
| 183 | + return yield* speech |
| 184 | + .removeModel(args.payload.modelId) |
| 185 | + .pipe(mapSpeechError, Effect.flatMap(withoutHostPaths)); |
166 | 186 | }), |
167 | 187 | ) |
168 | 188 | .handle( |
|
0 commit comments