Add AgentMemoryNamespace types scaffold#6628
Conversation
Adds minimal type declarations for the AgentMemoryNamespace binding so user-facing `wrangler types` output in workers-sdk can reference them. The real runtime API surface is owned by the Agent Memory team and is expected to extend this scaffold. Related: cloudflare/workers-sdk#13610
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
Adds scaffold type declarations for AgentMemoryNamespace, AgentMemoryContext, and AgentMemoryContextSummary to unblock wrangler types in workers-sdk.
Overall this looks clean — naming follows the AgentMemory* prefix convention, the declare abstract class pattern matches other binding types (e.g., AiSearchNamespace, Workflow), and the generated snapshots are consistent with the source.
One issue:
- Missing type tests (low).
types/AGENTS.mdasks for type-level compile checks intest/types/when adding new types. A minimal test exercising thegetContext→getSummarychain would catch regressions if this scaffold is later extended or replaced. Something like:
// test/types/agent-memory.ts
const ns = {} as AgentMemoryNamespace;
const ctx: AgentMemoryContext = ns.getContext("id");
const summary: AgentMemoryContextSummary = await ctx.getSummary();
void summary;I understand this is a draft and the types may be replaced entirely, so I'll leave this to your judgment on whether it's worth adding now or deferring until the real API shape lands.
|
Review posted on PR #6628. The PR is well-structured with only one low-severity suggestion about adding type tests in |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6628 +/- ##
==========================================
- Coverage 70.89% 66.51% -4.39%
==========================================
Files 438 405 -33
Lines 123821 115815 -8006
Branches 19486 19381 -105
==========================================
- Hits 87785 77032 -10753
- Misses 24486 27208 +2722
- Partials 11550 11575 +25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Rename emitted ambient type AgentMemory to AgentMemoryNamespace to match the type declared in workerd (cloudflare/workerd#6628) and follow the AiSearchNamespace precedent. - Consolidate the AgentMemoryNamespace interface by importing it from agent-memory/client.ts in agent-memory/provisioning.ts instead of redeclaring a narrower shape there. - Split agent-memory/client.ts into two layers: low-level helpers that take (complianceConfig, accountId, ...) and high-level wrappers that resolve auth via requireAuth. agent-memory/provisioning.ts now delegates to the low-level helpers, removing the duplicated fetch calls. - Reorder the agent_memory block in deploy/config-diffs.ts so it sits alongside the related ai_search blocks.
- Rename emitted ambient type AgentMemory to AgentMemoryNamespace to match the type declared in workerd (cloudflare/workerd#6628) and follow the AiSearchNamespace precedent. - Consolidate the AgentMemoryNamespace interface by importing it from agent-memory/client.ts in agent-memory/provisioning.ts instead of redeclaring a narrower shape there. - Split agent-memory/client.ts into two layers: low-level helpers that take (complianceConfig, accountId, ...) and high-level wrappers that resolve auth via requireAuth. agent-memory/provisioning.ts now delegates to the low-level helpers, removing the duplicated fetch calls. - Reorder the agent_memory block in deploy/config-diffs.ts so it sits alongside the related ai_search blocks.
- Rename emitted ambient type AgentMemory to AgentMemoryNamespace to match the type declared in workerd (cloudflare/workerd#6628) and follow the AiSearchNamespace precedent. - Consolidate the AgentMemoryNamespace interface by importing it from agent-memory/client.ts in agent-memory/provisioning.ts instead of redeclaring a narrower shape there. - Split agent-memory/client.ts into two layers: low-level helpers that take (complianceConfig, accountId, ...) and high-level wrappers that resolve auth via requireAuth. agent-memory/provisioning.ts now delegates to the low-level helpers, removing the duplicated fetch calls. - Reorder the agent_memory block in deploy/config-diffs.ts so it sits alongside the related ai_search blocks.
Summary
Adds minimal scaffold type declarations for the
AgentMemoryNamespacebinding class. This unblockswrangler typesoutput in workers-sdk PR cloudflare/workers-sdk#13610, which currently emits a reference toAgentMemoryNamespacethat does not resolve in@cloudflare/workers-types.Scope
This PR intentionally only declares the minimum surface visible from the workers-sdk e2e test (
packages/wrangler/e2e/remote-binding/workers/agent-memory.js):AgentMemoryNamespace.getContext(contextId: string): AgentMemoryContextAgentMemoryContext.getSummary(): Promise<AgentMemoryContextSummary>AgentMemoryContextSummary— an open record ([key: string]: unknown) with a@todonoting the real shape has not yet been declaredThe real runtime API surface is owned by the Agent Memory product team. They should extend
types/defines/agent-memory.d.tswith the complete API before the workers-sdk PR ships, or replace the scaffold with generated types from a C++ JSG resource.Changes
types/defines/agent-memory.d.ts— new file, scaffold class declarationstypes/generated-snapshot/experimental/index.d.ts— regeneratedtypes/generated-snapshot/experimental/index.ts— regeneratedtypes/generated-snapshot/latest/index.d.ts— regeneratedtypes/generated-snapshot/latest/index.ts— regeneratedTest plan
just generate-typesruns cleanly against the new defines file locally.Reviewer notes
Keeping this PR as a draft until:
cc @cloudflare/workers-sdk