mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-16 00:31:02 +02:00
Simplify text completion generator boundary
This commit is contained in:
parent
bfb5494552
commit
b3aaa9a4af
3 changed files with 56 additions and 8 deletions
|
|
@ -13,11 +13,11 @@ Verified source roots:
|
||||||
- Installed Effect beta used by this workspace: `ts/node_modules/effect`
|
- Installed Effect beta used by this workspace: `ts/node_modules/effect`
|
||||||
|
|
||||||
Current signal counts from `ts/packages` after the 2026-06-02 Text completion
|
Current signal counts from `ts/packages` after the 2026-06-02 Text completion
|
||||||
stream sentinel slice:
|
generator boundary slice:
|
||||||
|
|
||||||
| Signal | Count |
|
| Signal | Count |
|
||||||
| --- | ---: |
|
| --- | ---: |
|
||||||
| `Effect.runPromise` | 169 |
|
| `Effect.runPromise` | 168 |
|
||||||
| `Map<` | 88 |
|
| `Map<` | 88 |
|
||||||
| `WebSocket` | 72 |
|
| `WebSocket` | 72 |
|
||||||
| `new Map` | 62 |
|
| `new Map` | 62 |
|
||||||
|
|
@ -72,6 +72,10 @@ Notes:
|
||||||
`Effect.void as Effect.Effect<undefined>` assertions from provider stream
|
`Effect.void as Effect.Effect<undefined>` assertions from provider stream
|
||||||
unfold branches. Counts are unchanged because this was an Effect diagnostic
|
unfold branches. Counts are unchanged because this was an Effect diagnostic
|
||||||
and type-channel cleanup.
|
and type-channel cleanup.
|
||||||
|
- The text completion generator boundary slice removed the
|
||||||
|
`Effect.runPromise(Effect.fail(...))` fallback and the related
|
||||||
|
`AsyncGenerator`/`IteratorResult` assertions from
|
||||||
|
`model/text-completion/common.ts`.
|
||||||
- `Record<string, any>` and `throwLibrarianServiceError` are now clean in
|
- `Record<string, any>` and `throwLibrarianServiceError` are now clean in
|
||||||
`ts/packages`.
|
`ts/packages`.
|
||||||
|
|
||||||
|
|
@ -565,6 +569,26 @@ Notes:
|
||||||
- `cd ts && bun run test`
|
- `cd ts && bun run test`
|
||||||
- `git diff --check`
|
- `git diff --check`
|
||||||
|
|
||||||
|
### 2026-06-02: Text Completion Generator Boundary Slice
|
||||||
|
|
||||||
|
- Status: migrated and root-verified.
|
||||||
|
- Completed:
|
||||||
|
- `ts/packages/flow/src/model/text-completion/common.ts` now rejects
|
||||||
|
fallback `AsyncGenerator.throw(...)` calls with the mapped tagged provider
|
||||||
|
error directly instead of running `Effect.fail(...)` through
|
||||||
|
`Effect.runPromise`.
|
||||||
|
- The custom generator object no longer uses `as AsyncGenerator`,
|
||||||
|
`as Promise<IteratorResult<LlmChunk>>`, or `as LlmChunk` assertions.
|
||||||
|
- Added a focused unit test for fallback throw mapping.
|
||||||
|
- Verification:
|
||||||
|
- `bun run --cwd ts/packages/flow test -- src/__tests__/text-completion-common.test.ts`
|
||||||
|
- `bun run --cwd ts/packages/flow build`
|
||||||
|
- `cd ts && bun run check`
|
||||||
|
- `bun run --cwd ts/packages/flow test`
|
||||||
|
- `cd ts && bun run build`
|
||||||
|
- `cd ts && bun run test`
|
||||||
|
- `git diff --check`
|
||||||
|
|
||||||
## Subagent Findings To Preserve
|
## Subagent Findings To Preserve
|
||||||
|
|
||||||
- MCP/workbench:
|
- MCP/workbench:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { describe, expect, it } from "@effect/vitest";
|
||||||
|
import type { LlmChunk } from "@trustgraph/base";
|
||||||
|
import { providerRuntimeError, toAsyncGenerator } from "../model/text-completion/common.js";
|
||||||
|
|
||||||
|
const emptyChunkIterator = (): AsyncIterable<LlmChunk> => ({
|
||||||
|
[Symbol.asyncIterator]: () => ({
|
||||||
|
next: () => Promise.resolve({ done: true, value: undefined }),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("text completion common helpers", () => {
|
||||||
|
it("maps fallback generator throw failures into tagged provider errors", async () => {
|
||||||
|
const generator = toAsyncGenerator(
|
||||||
|
emptyChunkIterator(),
|
||||||
|
(error) => providerRuntimeError("test-provider", error),
|
||||||
|
);
|
||||||
|
|
||||||
|
await expect(generator.throw("provider failed")).rejects.toMatchObject({
|
||||||
|
_tag: "TextCompletionProviderError",
|
||||||
|
provider: "test-provider",
|
||||||
|
message: "provider failed",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -86,16 +86,16 @@ export const toAsyncGenerator = (
|
||||||
const iterator = iterable[Symbol.asyncIterator]();
|
const iterator = iterable[Symbol.asyncIterator]();
|
||||||
let generator: AsyncGenerator<LlmChunk>;
|
let generator: AsyncGenerator<LlmChunk>;
|
||||||
generator = {
|
generator = {
|
||||||
next: (value?: unknown) => iterator.next(value as never),
|
next: (value?: unknown) => iterator.next(value),
|
||||||
return: (value?: unknown) =>
|
return: (value?: unknown) =>
|
||||||
iterator.return === undefined
|
iterator.return === undefined
|
||||||
? Promise.resolve({ done: true, value: value as LlmChunk })
|
? Promise.resolve({ done: true, value })
|
||||||
: iterator.return(value as never) as Promise<IteratorResult<LlmChunk>>,
|
: iterator.return(value),
|
||||||
throw: (error?: unknown) =>
|
throw: (error?: unknown) =>
|
||||||
iterator.throw === undefined
|
iterator.throw === undefined
|
||||||
? Effect.runPromise(Effect.fail(mapError(error))) as Promise<IteratorResult<LlmChunk>>
|
? Promise.reject(mapError(error))
|
||||||
: iterator.throw(error) as Promise<IteratorResult<LlmChunk>>,
|
: iterator.throw(error),
|
||||||
[Symbol.asyncIterator]: () => generator,
|
[Symbol.asyncIterator]: () => generator,
|
||||||
} as AsyncGenerator<LlmChunk>;
|
};
|
||||||
return generator;
|
return generator;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue