fix(ts-sdk): send null instead of undefined when includeEntities is false (#476)

* fix(ts-sdk): send null instead of undefined when includeEntities is false

When `includeEntities: false` was passed, the client serialized `entities`
as `undefined`, which is stripped from JSON. The API then applied its
default (`EntityIncludeOptions()` — enabled), silently ignoring the flag.

Fix: send `null` explicitly when `includeEntities === false` so the API
correctly interprets it as "disable entities".

chunks and source_facts are unaffected since their API defaults are null
(disabled), so omitting them from JSON produces the correct behaviour.

Also adds integration tests covering all three states of includeEntities.

* fix(ts-sdk): use toBeFalsy for null entity check in test
This commit is contained in:
Nicolò Boschi 2026-03-03 14:54:48 +01:00 committed by GitHub
parent 61bf428ba9
commit 15f4b8769b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 1 deletions

View file

@ -286,7 +286,7 @@ export class HindsightClient {
trace: options?.trace, trace: options?.trace,
query_timestamp: options?.queryTimestamp, query_timestamp: options?.queryTimestamp,
include: { include: {
entities: options?.includeEntities ? { max_tokens: options?.maxEntityTokens ?? 500 } : undefined, entities: options?.includeEntities === false ? null : options?.includeEntities ? { max_tokens: options?.maxEntityTokens ?? 500 } : undefined,
chunks: options?.includeChunks ? { max_tokens: options?.maxChunkTokens ?? 8192 } : undefined, chunks: options?.includeChunks ? { max_tokens: options?.maxChunkTokens ?? 8192 } : undefined,
source_facts: options?.includeSourceFacts ? { max_tokens: options?.maxSourceFactsTokens ?? 4096 } : undefined, source_facts: options?.includeSourceFacts ? { max_tokens: options?.maxSourceFactsTokens ?? 4096 } : undefined,
}, },

View file

@ -413,6 +413,48 @@ describe('TestDeleteBank', () => {
}); });
}); });
describe('TestRecallIncludeOptions', () => {
let bankId: string;
beforeAll(async () => {
bankId = randomBankId();
await client.retainBatch(bankId, [
{ content: 'Alice works at Google as a software engineer' },
{ content: 'Bob is a researcher at OpenAI' },
]);
});
test('entities included by default', async () => {
const response = await client.recall(bankId, 'Where does Alice work?');
expect(response).not.toBeNull();
expect(response.results!.length).toBeGreaterThan(0);
// entities should be present when includeEntities is not specified (default: true)
expect(response.entities).toBeDefined();
});
test('entities excluded when includeEntities is false', async () => {
const response = await client.recall(bankId, 'Where does Alice work?', {
includeEntities: false,
});
expect(response).not.toBeNull();
expect(response.results!.length).toBeGreaterThan(0);
// entities should be absent when explicitly disabled
expect(response.entities).toBeFalsy();
});
test('entities included when includeEntities is true', async () => {
const response = await client.recall(bankId, 'Where does Alice work?', {
includeEntities: true,
});
expect(response).not.toBeNull();
expect(response.results!.length).toBeGreaterThan(0);
expect(response.entities).toBeDefined();
});
});
describe('TestMission', () => { describe('TestMission', () => {
test('set mission', async () => { test('set mission', async () => {
const bankId = randomBankId(); const bankId = randomBankId();