Skip to content

[AI-3411] JS: keep speakingFor off Backend's published type - #2154

Merged
kanat merged 5 commits into
mainfrom
kanat/ai-3411-js-hide-speaking-for
Nov 20, 2026
Merged

kanat merged 5 commits into
mainfrom
kanat/ai-3411-js-hide-speaking-for

Conversation

@kanat

@kanat kanat commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Backend.speakingFor (added in #2110) is tagged @internal, but the package has no stripInternal, so dist/backend.d.ts published it as a method of the public Backend, beside the deprecated actingFor it duplicates. AI-3411.

stripInternal was not used. It would hide the 15 @internal symbols that the published 0.5.0 .d.ts already exposes (onRetry, Tools.of, Conversation.said/observe, Session.cameraFrames, LiveUI.observeTurns, ...), which breaks published types. speakingFor itself is not in 0.5.0.

Checked: npm pack @stream-io/stream-agents@0.5.0, then grep -rl @internal dist --include=*.d.ts finds 15 tags.

How it works

before: Backend.speakingFor(userId)      -> on the type, autocompleted
after:  speakingFor(backend, userId)     -> module function in backend.ts, no entry point re-exports it
        Backend.actingFor(userId)        -> calls it, same copy, same request
  • speakingFor is a module function in sdks/js/src/backend.ts. No entry point re-exports it: the test covers the five entry points (., ./node, ./chat, ./video, ./react) and Backend's statics.
  • package.json exports has only those five paths, so a consumer cannot import dist/backend.js. The copy is the same code; its private fields are reached by name (acting["fetched"]).

Changes

  • sdks/js/src/backend.ts: speakingFor becomes a module function; actingFor calls it. The actsFor and actingForValue docs name actingFor.
  • sdks/js/src/connections.ts, dispatch.ts: call the function.
  • sdks/js/tests/backend.test.ts: @ts-expect-error on backend.speakingFor; actingFor still works; speakingFor absent from all five entry points and from Backend'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.md line 789 (AI-3413): a user's team is no longer said to be for_user(team=). It names create_user_token(..., team=) and user_id= on Client.agent/Client.router of a client built with team=/usage_categories=; for_user is deprecated ([AI-3379] Python SDK: a connections resource and an optional user_id #2103). Line 936: speakingFor is named as a module function in backend.ts.
  • No CHANGELOG entry: speakingFor was never released, so nothing user-visible changes.

Review rounds

Round Verdict Findings Fixed in
R1 NO-GO R1.1 no test that keeps speakingFor off the exports; R1.2 actsFor/actingForValue docs named speakingFor; R1.3 SKILL.md:936 still called it a Backend method 5430d99
R2 NO-GO R2.1 test checked two of the five entry points; chat, video and react re-exports survived 788302d
R3 GO Orchestrator check: delta 5430d99..788302d is test-only (+6); chat, video and react re-export mutants each fail; head 50/50 (no change)

Follow-ups: Tools.failure, ToolCalls.observe, offerTool are unreleased and published the same way, ticketed as AI-3451.

Validation

  • cd sdks/js && npm run types -- --check && npm test on 788302d: 794 pass, 0 fail.
  • CI on 788302d: sdks pass, plus CodeQL, Analyze (actions/go/python), GitGuardian and labeler, all pass.
  • Mutations, each killed by a test: re-adding the method (tsc: unused @ts-expect-error); a re-export of speakingFor from index, node, chat, video or react; a static speakingFor on Backend; dropping the userIdValue, user, fetched or fetching reset; each of the three call sites (connections.ts x2, dispatch.ts).

AI-3411, AI-3413.

🤖 Generated with Claude Code

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>
@github-actions github-actions Bot added the docs label Nov 20, 2026

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.speakingFor is 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, from df65f05, 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:404 passes. The mutants actingFor -> this and actingFor -> 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:789 matches plugins/stream/.../client.py on base: create_user_token(..., team=), user_id= on agent/router, Client(team=, usage_categories=), and for_user deprecated 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);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in eee97d0: "exports speakingFor from no entry point and as no static of Backend" (backend.test.ts). Under a re-export from src/index.ts and under a static Backend.speakingFor it fails (793 pass, 1 fail each). R1.2 is fixed in 14b9a8f and R1.3 in 5430d99 (docs only).

kanat and others added 3 commits November 20, 2026 16:17
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 kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 speakingFor on 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 built backend.d.ts does too.
  • R1.3 fixed: .claude/skills/sdk/SKILL.md:936 names the module function speakingFor(backend, userId) in backend.ts, kept off Backend'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", () => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@kanat
kanat marked this pull request as ready for review November 20, 2026 15:27
@kanat
kanat merged commit 18eb148 into main Nov 20, 2026
8 checks passed
@kanat
kanat deleted the kanat/ai-3411-js-hide-speaking-for branch November 20, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant