Skip to content

feat(typescript-client): add AbortSignal support to all HindsightClient methods#1198

Open
harryplusplus wants to merge 2 commits intovectorize-io:mainfrom
harryplusplus:feat/typescript-client-abort-signal
Open

feat(typescript-client): add AbortSignal support to all HindsightClient methods#1198
harryplusplus wants to merge 2 commits intovectorize-io:mainfrom
harryplusplus:feat/typescript-client-abort-signal

Conversation

@harryplusplus
Copy link
Copy Markdown
Contributor

Summary

Expose per-request AbortSignal support on every public method of the TypeScript HindsightClient. The generated @hey-api/openapi-ts SDK already accepts signal on each request call (its RequestOptions type extends RequestInit), but the high-level HindsightClient wrapper did not surface it to callers.

Motivation

In an agent harness, Hindsight calls (retain, recall, reflect) run under a time budget — best-effort before the next LLM invocation. When a call exceeds the budget, the caller moves on — but without AbortSignal, the HTTP request continues in the background on both the client and server, wasting resources. Cancelling early on the client side lets the server stop unnecessary computation (fact extraction, embedding, consolidation) as well. Without this change, the only way to pass an AbortSignal is to drop down to the low-level generated sdk namespace.

Changes

hindsight-clients/typescript/src/index.ts

Note: The first commit (style) reformats these files with the client-local .prettierrc — they were previously unformatted. The root .prettierrc.json uses different settings; happy to align with the root config if maintainers prefer.

Added signal?: AbortSignal to the options bag of all public methods and forwarded it to the underlying generated SDK call:

  • Core operations: retain, retainBatch, retainFiles, recall, reflect
  • Bank management: createBank, setMission, getBankProfile, getBankConfig, updateBankConfig, resetBankConfig, deleteBank
  • Directives: createDirective, listDirectives, getDirective, updateDirective, deleteDirective
  • Mental models: createMentalModel, listMentalModels, getMentalModel, refreshMentalModel, updateMentalModel, deleteMentalModel, getMentalModelHistory
  • Documents: getDocument, listDocuments, deleteDocument, updateDocument
  • List: listMemories

Methods that already had a required options parameter (e.g., createBank, updateBankConfig, updateDirective, updateMentalModel, updateDocument) keep it required — signal is added as an optional field inside the existing options object.

hindsight-clients/typescript/tests/main_operations.test.ts

Added TestAbortSignal suite with 3 unit tests that mock the generated SDK and verify the signal is passed through:

  • retain passes abort signal to SDK
  • recall passes abort signal to SDK
  • getBankProfile passes abort signal to SDK

These tests do not require a running Hindsight API server.

Usage Example

import { HindsightClient } from "@vectorize-io/hindsight-client";

const client = new HindsightClient({ baseUrl: "http://localhost:8888" });

// Cancel a long-running retain
const controller = new AbortController();
setTimeout(() => controller.abort(), 5000);

await client.retain("alice", "Alice loves AI", {
  signal: controller.signal,
});

Checklist

  • Branch created from latest main
  • npm run build passes
  • prettier --write applied
  • ./scripts/hooks/lint.sh passes
  • Tests added for new behavior
  • No generated code modified (only src/index.ts)
  • No OpenAPI spec changes (no client regeneration needed)

Reformat src/index.ts and tests/main_operations.test.ts with the
client-local .prettierrc. These files were previously unformatted.
No functional changes.
…nt methods

Expose per-request AbortSignal on every public method of HindsightClient.
The generated @hey-api/openapi-ts SDK already accepts signal on each
request call (its RequestOptions type extends RequestInit), but the
high-level wrapper did not surface it.

Added signal?: AbortSignal to the options bag of all 29 public methods
and forwarded it to the underlying generated SDK call.

Added TestAbortSignal suite with 3 unit tests that mock the generated
SDK and verify the signal is passed through (retain, recall,
getBankProfile). These tests do not require a running API server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant