Repository navigation
[AI-3411] JS: keep speakingFor off Backend's published type - #2154
Conversation
speakingFor was marked @internal but dist/backend.d.ts published it as a Backend method. stripInternal would also hide the @internal symbols 0.5.0 already published, so it becomes a function of backend.ts, which the package exports no path to; actingFor calls it and sends what it sent before. [AI-3413] sdk skill: name the current Python shape for a user's team, not for_user(team=). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
Reviewed #2154 at d3768df (base main at 2d236ed, no newer base). CI: draft, SDK jobs run at gh pr ready. npm run types -- --check is in step with the spec, and npm test passes 793 of 793.
[Should fix] R1.2 sdks/js/src/backend.ts:428 (and :350): the doc comment of the public getter actsFor reads "The end user speakingFor named". It ships in the packed dist/backend.d.ts:247, and :235 holds the same text on actingForValue. So hover text on the published type now names a symbol that users cannot reach. Published 0.5.0 said actingFor here. Fix: name actingFor again, or write "the user a call names".
[Should fix] R1.3 .claude/skills/sdk/SKILL.md:936 still says "an internal Backend.speakingFor, which Dispatch's answer also uses". After this PR it is a module function, not a method. Fix: "an internal speakingFor(backend, userId) in backend.ts, kept off Backend's type".
Checked and sound:
- Deprecate, never break. I compared the public type surface across all entries, with the TS compiler API: exports, members and statics. Between base and head the only change is that
Backend.speakingForis gone, and 0.5.0 never had it. Five symbols are missing compared with 0.5.0 (AgentHandle.tools,HostingRefusedError.agentId,ToolCallContext.say/update,ToolLine.update). They were already gone on base, fromdf65f05, not from this PR. - Requests are unchanged. The function body matches the base method; only the private fields are now reached by name. The control test
connections.test.ts:404passes. The mutantsactingFor->thisandactingFor-> user""are killed. - I reran the author's 11 mutants and 6 of my own on the call sites, the copy and
actingFor: all killed. Two survive, see R1.1. SKILL.md:789matchesplugins/stream/.../client.pyon base:create_user_token(..., team=),user_id=onagent/router,Client(team=, usage_categories=), andfor_userdeprecated in #2103.
Verdict: request changes (NO-GO), for R1.1-R1.3 (Should fix).
| it("offers acting for a user only through the deprecated actingFor, not a second method", () => { | ||
| const backend = new Backend({ url: router.url, apiKey: "vak_live_x" }); | ||
| // @ts-expect-error speakingFor is not on Backend's published type | ||
| assert.equal(backend.speakingFor, undefined); |
There was a problem hiding this comment.
[Should fix] R1.1 No test pins the rule that no package export reaches speakingFor. Two mutants survive all 793 tests: adding speakingFor to the export list in src/index.ts, and adding static speakingFor(b, u) to Backend. Both put it back on the published API. Add these checks to this suite. I checked that they pass on head and fail under each mutant:
import * as root from "../src/index.js";
import * as node from "../src/node.js";
assert.equal("speakingFor" in root, false);
assert.equal("speakingFor" in node, false);
assert.equal(Object.getOwnPropertyNames(Backend).includes("speakingFor"), false);There was a problem hiding this comment.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
[reviewer R2] NO-GO: delta round 2 at 5430d99 (previous reviewed d3768df), base 2d236ed.
Prior findings:
- R1.1 open (partial): the two mutants named in the round-1 finding (a re-export from src/index.ts, a static
speakingForon Backend) now fail the new test. Re-exports from src/chat.ts, src/video.ts and src/react.ts still pass it; see R2.1. - R1.2 fixed: src/backend.ts:350 and :428 now say
actingFor, and the builtbackend.d.tsdoes too. - R1.3 fixed: .claude/skills/sdk/SKILL.md:936 names the module function
speakingFor(backend, userId)inbackend.ts, kept offBackend's type.
New findings:
- R2.1 [Should fix] sdks/js/tests/backend.test.ts:51 (inline): the test checks two of the five package entry points.
Checks: npm run types -- --check in step with the spec; npm test 794/794 on head and on head merged with origin/main 8e68a6c. Mutants: 6 checked, 3 survived (chat, video and react re-exports). Probe: the extended test passes on head and fails under each re-export.
| assert.equal(backend.actingFor("ana").actsFor, "ana"); | ||
| }); | ||
|
|
||
| it("exports speakingFor from no entry point and as no static of Backend", () => { |
There was a problem hiding this comment.
[Should fix] R2.1 This test pins two of the five package entry points (., ./node, ./chat, ./video, ./react). A re-export of speakingFor from src/chat.ts, src/video.ts or src/react.ts still passes all tests. Fix: import ../src/chat.js, ../src/video.js and ../src/react.js as namespaces and assert "speakingFor" in chat === false (and for video and react) beside the root and node lines. Checked: the extended test passes on this head (50 of 50) and fails under each of the three re-exports (49 pass, 1 fail).
There was a problem hiding this comment.
Fixed in 788302d: "exports speakingFor from no entry point and as no static of Backend" (backend.test.ts). Now also asserts the chat, video and react namespaces. A re-export of speakingFor from each of src/chat.ts, src/video.ts, src/react.ts, src/index.ts and src/node.ts fails it; the suite passes on 788302d (794/794).
The no-export test checked two of the five package entry points. A re-export from chat, video or react would have passed it. Add the three missing namespaces to the same assertion set.
Why
Backend.speakingFor(added in #2110) is tagged@internal, but the package has nostripInternal, sodist/backend.d.tspublished it as a method of the publicBackend, beside the deprecatedactingForit duplicates. AI-3411.stripInternalwas not used. It would hide the 15@internalsymbols that the published 0.5.0.d.tsalready exposes (onRetry,Tools.of,Conversation.said/observe,Session.cameraFrames,LiveUI.observeTurns, ...), which breaks published types.speakingForitself is not in 0.5.0.Checked:
npm pack @stream-io/stream-agents@0.5.0, thengrep -rl @internal dist --include=*.d.tsfinds 15 tags.How it works
speakingForis a module function insdks/js/src/backend.ts. No entry point re-exports it: the test covers the five entry points (.,./node,./chat,./video,./react) andBackend's statics.package.jsonexportshas only those five paths, so a consumer cannot importdist/backend.js. The copy is the same code; its private fields are reached by name (acting["fetched"]).Changes
sdks/js/src/backend.ts:speakingForbecomes a module function;actingForcalls it. The actsFor and actingForValue docs nameactingFor.sdks/js/src/connections.ts,dispatch.ts: call the function.sdks/js/tests/backend.test.ts:@ts-expect-erroronbackend.speakingFor;actingForstill works;speakingForabsent from all five entry points and fromBackend's statics.sdks/js/tests/token.test.ts: a copy acting for another user carries neither the original's fetched token nor its user..claude/skills/sdk/SKILL.mdline 789 (AI-3413): a user's team is no longer said to befor_user(team=). It namescreate_user_token(..., team=)anduser_id=onClient.agent/Client.routerof a client built withteam=/usage_categories=;for_useris deprecated ([AI-3379] Python SDK: a connections resource and an optional user_id #2103). Line 936:speakingForis named as a module function inbackend.ts.speakingForwas never released, so nothing user-visible changes.Review rounds
speakingForoff the exports; R1.2 actsFor/actingForValue docs namedspeakingFor; R1.3 SKILL.md:936 still called it aBackendmethodFollow-ups:
Tools.failure,ToolCalls.observe,offerToolare unreleased and published the same way, ticketed as AI-3451.Validation
cd sdks/js && npm run types -- --check && npm teston 788302d: 794 pass, 0 fail.sdkspass, plus CodeQL, Analyze (actions/go/python), GitGuardian and labeler, all pass.@ts-expect-error); a re-export ofspeakingForfromindex,node,chat,videoorreact; astatic speakingForonBackend; dropping theuserIdValue,user,fetchedorfetchingreset; each of the three call sites (connections.tsx2,dispatch.ts).AI-3411, AI-3413.
🤖 Generated with Claude Code