@cloudflare/think 0.11.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +9 -14
  2. package/dist/{chat-sdk-D6cUghsQ.js → chat-sdk-iuBa-CGM.js} +62 -7
  3. package/dist/chat-sdk-iuBa-CGM.js.map +1 -0
  4. package/dist/cli/index.js +6 -15
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/{index-CR4-ffm_.d.ts → index-Cm0jriTY.d.ts} +332 -141
  7. package/dist/messengers/index.d.ts +44 -38
  8. package/dist/messengers/index.js +2 -2
  9. package/dist/messengers/telegram.d.ts +2 -2
  10. package/dist/messengers/telegram.js +1 -1
  11. package/dist/studio/assets/{angular-html-D27LthTc.js → angular-html--XgCyfPu.js} +1 -1
  12. package/dist/studio/assets/{angular-ts-DtNL2gQ7.js → angular-ts-Dt-feQIe.js} +1 -1
  13. package/dist/studio/assets/{apl-BgEcDqM0.js → apl-B7ymkyp4.js} +1 -1
  14. package/dist/studio/assets/{astro-CstbRF9e.js → astro-Ce5cw2JI.js} +1 -1
  15. package/dist/studio/assets/{blade-CLG-7epG.js → blade-DL-aXwjv.js} +1 -1
  16. package/dist/studio/assets/{c-CssQqwxO.js → c-CFfr09UF.js} +1 -1
  17. package/dist/studio/assets/{cobol-CjmzHCjg.js → cobol-Ba1f5ZqR.js} +1 -1
  18. package/dist/studio/assets/{coffee-B_rqYPkp.js → coffee-BG2_viYI.js} +1 -1
  19. package/dist/studio/assets/{cpp-5YyZJlb7.js → cpp-pU5HgBva.js} +1 -1
  20. package/dist/studio/assets/{crystal-D7uKze0i.js → crystal-Dlm_uR4r.js} +1 -1
  21. package/dist/studio/assets/{css-k9oPgg7G.js → css-tUC4TMTn.js} +1 -1
  22. package/dist/studio/assets/{edge-CGgsSt0x.js → edge-CQuSKMUt.js} +1 -1
  23. package/dist/studio/assets/{elixir-BX_d5Evo.js → elixir-BmIB-Wi1.js} +1 -1
  24. package/dist/studio/assets/{elm-DENxDm5e.js → elm-ByVNCtDB.js} +1 -1
  25. package/dist/studio/assets/{erb-DvYOup03.js → erb-DO4uDxTq.js} +1 -1
  26. package/dist/studio/assets/{git-rebase-BsAdTS5A.js → git-rebase-CT8LXapC.js} +1 -1
  27. package/dist/studio/assets/{glimmer-js-e0h98Z67.js → glimmer-js-DzIT0v-m.js} +1 -1
  28. package/dist/studio/assets/{glimmer-ts-C9s5Kv8m.js → glimmer-ts-znG2j9R4.js} +1 -1
  29. package/dist/studio/assets/{glsl-CCiyeTRs.js → glsl-C1p8U_gW.js} +1 -1
  30. package/dist/studio/assets/{graphql-BRtHwsqk.js → graphql-CFqegryf.js} +1 -1
  31. package/dist/studio/assets/{hack-Dnt0QXHh.js → hack-BfVsNhqs.js} +1 -1
  32. package/dist/studio/assets/{haml-EXGmzuB1.js → haml-DVcEksY5.js} +1 -1
  33. package/dist/studio/assets/{handlebars-CzyBIDJE.js → handlebars-DSWgWCJ4.js} +1 -1
  34. package/dist/studio/assets/{highlighted-body-OFNGDK62-CQUFKLNu.js → highlighted-body-OFNGDK62-BIm4UpTS.js} +1 -1
  35. package/dist/studio/assets/{html-BAT8b_VM.js → html-C-lP7-T4.js} +1 -1
  36. package/dist/studio/assets/{html-derivative-7tkS-r6F.js → html-derivative-ByukJopb.js} +1 -1
  37. package/dist/studio/assets/{http-Cgka02Qq.js → http-Bax2fYIk.js} +1 -1
  38. package/dist/studio/assets/{hurl-Cbkh8WEw.js → hurl-BrI2qfvy.js} +1 -1
  39. package/dist/studio/assets/{index-D6n8vpkp.js → index-DNSTOyBe.js} +5 -5
  40. package/dist/studio/assets/{java-DrRKiUno.js → java-ZiR-uym-.js} +1 -1
  41. package/dist/studio/assets/{javascript-9LAnHOxD.js → javascript-Dhhw85Vr.js} +1 -1
  42. package/dist/studio/assets/{jinja-CqRt4prs.js → jinja-DqSGkgE4.js} +1 -1
  43. package/dist/studio/assets/{jison-BX-IOQpJ.js → jison-CwQ0BO-q.js} +1 -1
  44. package/dist/studio/assets/{json-dOrE-En8.js → json-Je3YfUTE.js} +1 -1
  45. package/dist/studio/assets/{jsx-BSTPfqWX.js → jsx-Da-dLbW1.js} +1 -1
  46. package/dist/studio/assets/{julia-Dvz-BPmf.js → julia-CBJ0H-0z.js} +1 -1
  47. package/dist/studio/assets/{just-BHQm0Atq.js → just-CnuRC_nd.js} +1 -1
  48. package/dist/studio/assets/{latex-CxdhxuXv.js → latex-gZANCito.js} +1 -1
  49. package/dist/studio/assets/{liquid-D-hM-Q_F.js → liquid-0U9aXoFI.js} +1 -1
  50. package/dist/studio/assets/{lua-5qtqjLHq.js → lua-CX_TqMxt.js} +1 -1
  51. package/dist/studio/assets/{marko-5FJaM2co.js → marko-StSURz0o.js} +1 -1
  52. package/dist/studio/assets/{mdc-BhYW7lCG.js → mdc-CXZpf9k1.js} +1 -1
  53. package/dist/studio/assets/mermaid-GHXKKRXX-CqDQH2-r.js +1 -0
  54. package/dist/studio/assets/{nginx-rtAXrRye.js → nginx-3Q2L4366.js} +1 -1
  55. package/dist/studio/assets/{nim-DQSmaN9U.js → nim-CqX_5eXP.js} +1 -1
  56. package/dist/studio/assets/{perl-B54AdcaE.js → perl-CLOu1GnZ.js} +1 -1
  57. package/dist/studio/assets/{php-DpvTxCny.js → php-C1vkiu4h.js} +1 -1
  58. package/dist/studio/assets/{pug-Cyffw0Ho.js → pug-Cg3cFp5y.js} +1 -1
  59. package/dist/studio/assets/{qml-CxRetSkO.js → qml-DhKeHMwt.js} +1 -1
  60. package/dist/studio/assets/{r-CXWRxrXc.js → r--Lg2-Sir.js} +1 -1
  61. package/dist/studio/assets/{razor-BJzI-zc9.js → razor-Cjptf146.js} +1 -1
  62. package/dist/studio/assets/{regexp-dqxdfrnE.js → regexp-fS0DAwei.js} +1 -1
  63. package/dist/studio/assets/{rst-BW7eKYj4.js → rst-BBajBzk-.js} +1 -1
  64. package/dist/studio/assets/{ruby-D5Npyj8-.js → ruby-KvFedogM.js} +1 -1
  65. package/dist/studio/assets/{sas-DZLppjul.js → sas-D6p27LWr.js} +1 -1
  66. package/dist/studio/assets/{scss-CbqoxyAe.js → scss-6jXfJVsd.js} +1 -1
  67. package/dist/studio/assets/{shellscript-CFHqBeXu.js → shellscript-BK0Qbt1B.js} +1 -1
  68. package/dist/studio/assets/{shellsession-CbZDA4Bf.js → shellsession-BsXmVRU4.js} +1 -1
  69. package/dist/studio/assets/{soy-PImjtV58.js → soy-BKtGCXkJ.js} +1 -1
  70. package/dist/studio/assets/{sql-DhGo8urW.js → sql-vSUKslBj.js} +1 -1
  71. package/dist/studio/assets/{stata-CjHWbU2v.js → stata-BQ0iXcs9.js} +1 -1
  72. package/dist/studio/assets/{surrealql-o8Qr4t56.js → surrealql-v5pXHIwP.js} +1 -1
  73. package/dist/studio/assets/{svelte-DlSIyEV1.js → svelte-BMFjqgJb.js} +1 -1
  74. package/dist/studio/assets/{templ-qizfwU1w.js → templ-DYMTOmIJ.js} +1 -1
  75. package/dist/studio/assets/{tex-Ca7T661H.js → tex-BoQem9gj.js} +1 -1
  76. package/dist/studio/assets/{ts-tags-DUmjLkgl.js → ts-tags-Kp2pAlsd.js} +1 -1
  77. package/dist/studio/assets/{tsx-CfwgIqHW.js → tsx-DaB2J5uo.js} +1 -1
  78. package/dist/studio/assets/{twig-D7NAYUBY.js → twig-DohCGJPH.js} +1 -1
  79. package/dist/studio/assets/{typescript-Bbz9oX-P.js → typescript-BGG-5I-T.js} +1 -1
  80. package/dist/studio/assets/{vue-vYpz06zQ.js → vue-CCDLUl9R.js} +1 -1
  81. package/dist/studio/assets/{vue-html-CcxTb_Jn.js → vue-html-et9GYlaF.js} +1 -1
  82. package/dist/studio/assets/{vue-vine-DW4RqCKF.js → vue-vine-C561z6bx.js} +1 -1
  83. package/dist/studio/assets/{xml-R4LZ_u4f.js → xml-CJBA1ZPm.js} +1 -1
  84. package/dist/studio/assets/{xsl-CS-xzp3L.js → xsl-De-lf9XG.js} +1 -1
  85. package/dist/studio/assets/{yaml-CqDWbYXd.js → yaml-BcMKxf75.js} +1 -1
  86. package/dist/studio/index.html +1 -1
  87. package/dist/think.d.ts +2 -2
  88. package/dist/think.js +176 -44
  89. package/dist/think.js.map +1 -1
  90. package/dist/workflows.d.ts +1 -1
  91. package/docs/getting-started.md +11 -11
  92. package/docs/index.md +10 -13
  93. package/docs/lifecycle-hooks.md +14 -12
  94. package/docs/messengers.md +52 -0
  95. package/package.json +8 -7
  96. package/dist/chat-sdk-D6cUghsQ.js.map +0 -1
  97. package/dist/studio/assets/mermaid-GHXKKRXX-CWM2EB-u.js +0 -1
@@ -309,6 +309,20 @@ interface ChatOptions {
309
309
  onClientToolCall?: ClientToolExecutor;
310
310
  /** Channel id this turn belongs to. See {@link RunTurnBase.channel}. */
311
311
  channel?: string;
312
+ /**
313
+ * Server-supplied metadata for this turn. Persisted on the turn's user
314
+ * message alongside {@link ChatOptions.channel} (as `metadata.turnMetadata`)
315
+ * so a recovered/continued turn re-resolves it from durable history, and
316
+ * readable during the turn via {@link Think.activeTurnMetadata}.
317
+ *
318
+ * Trust contract mirrors the channel stamp: only server-side callers can set
319
+ * it — reserved metadata keys on client-supplied messages are stripped at
320
+ * intake. This gives messenger/RPC entry points (e.g.
321
+ * {@link Think.chatWithMessengerContext}) a per-turn, recovery-safe carrier
322
+ * for facts like "which authenticated principal initiated this turn" without
323
+ * resorting to mutable agent-wide state.
324
+ */
325
+ metadata?: Record<string, unknown>;
312
326
  }
313
327
  /** Input accepted by {@link Think.runTurn}. */
314
328
  type TurnInputMessages =
@@ -745,8 +759,12 @@ interface TurnContext {
745
759
  * All fields are optional — return only what you want to change.
746
760
  */
747
761
  interface TurnConfig {
748
- /** Override the model for this turn (e.g. cheap model for continuations). */
749
- model?: LanguageModel;
762
+ /**
763
+ * Override the model for this turn (e.g. cheap model for continuations).
764
+ * Accepts a model id string (resolved via the built-in provider, same rules
765
+ * as {@link Think.getModel}) or a `LanguageModel`.
766
+ */
767
+ model?: ThinkModel;
750
768
  /** Override the assembled system prompt. */
751
769
  system?: string;
752
770
  /** Override the assembled messages. */
@@ -973,8 +991,17 @@ type PrepareStepContext<TOOLS extends ToolSet = ToolSet> = Parameters<
973
991
  * return only the fields you want to override (`model`, `toolChoice`,
974
992
  * `activeTools`, `system`, `messages`, `experimental_context`,
975
993
  * `providerOptions`).
994
+ *
995
+ * `model` is widened to {@link ThinkModel}: like {@link Think.getModel}, you
996
+ * can return a model id string (resolved via the built-in provider) instead of
997
+ * a `LanguageModel`. Think resolves it before handing the step to the AI SDK.
976
998
  */
977
- type StepConfig<TOOLS extends ToolSet = ToolSet> = PrepareStepResult<TOOLS>;
999
+ type StepConfig<TOOLS extends ToolSet = ToolSet> = Omit<
1000
+ PrepareStepResult<TOOLS>,
1001
+ "model"
1002
+ > & {
1003
+ model?: ThinkModel;
1004
+ };
978
1005
  /**
979
1006
  * Context passed to the `beforeToolCall` hook **before** the tool's
980
1007
  * `execute` function runs.
@@ -1168,6 +1195,36 @@ interface ExtensionConfig {
1168
1195
  *
1169
1196
  * @experimental The API surface may change before stabilizing.
1170
1197
  */
1198
+ /**
1199
+ * Keys of the global `AiModels` interface (from `@cloudflare/workers-types`)
1200
+ * whose model type extends `T`. Mirrors the derivation `workers-ai-provider`
1201
+ * uses, so the set stays in sync with the installed workers-types version.
1202
+ */
1203
+ type WorkersAIModelIdsExtending<T> = {
1204
+ [K in keyof AiModels]: AiModels[K] extends T ? K : never;
1205
+ }[keyof AiModels];
1206
+ /**
1207
+ * A model id accepted by {@link Think.getModel}.
1208
+ *
1209
+ * Provides editor autocomplete for the Workers AI text-generation catalog
1210
+ * (`@cf/...`) while still accepting **any** string — including
1211
+ * `"<provider>/<model>"` AI Gateway slugs like `"openai/gpt-5.5"`, whose
1212
+ * validity is only known at runtime (the catalog is server-side and changes
1213
+ * independently of these types). The `(string & {})` arm is what keeps
1214
+ * arbitrary strings assignable without collapsing the autocomplete union.
1215
+ */
1216
+ type ThinkModelId =
1217
+ | Exclude<
1218
+ WorkersAIModelIdsExtending<BaseAiTextGeneration>,
1219
+ WorkersAIModelIdsExtending<BaseAiTextToImage>
1220
+ >
1221
+ | (string & {});
1222
+ /**
1223
+ * What {@link Think.getModel} may return: either a fully-constructed AI SDK
1224
+ * `LanguageModel`, or a {@link ThinkModelId} string resolved through Think's
1225
+ * built-in `workers-ai-provider`. Also the input type of {@link Think.resolveModel}.
1226
+ */
1227
+ type ThinkModel = LanguageModel | ThinkModelId;
1171
1228
  declare class Think<
1172
1229
  Env extends Cloudflare.Env = Cloudflare.Env,
1173
1230
  State = unknown,
@@ -1707,10 +1764,69 @@ declare class Think<
1707
1764
  private _configGet;
1708
1765
  private _configDelete;
1709
1766
  /**
1710
- * Return the language model to use for inference.
1711
- * Must be overridden by subclasses.
1767
+ * Return the model to use for inference. Must be overridden by subclasses.
1768
+ *
1769
+ * The return value can be either:
1770
+ *
1771
+ * - A **string** model id, resolved through the built-in
1772
+ * {@link https://www.npmjs.com/package/workers-ai-provider | workers-ai-provider}
1773
+ * off your `AI` binding (see {@link getAIBinding}). A `@cf/...` id hits
1774
+ * Workers AI directly; any other `"<provider>/<model>"` slug — e.g.
1775
+ * `"openai/gpt-5.5"`, `"anthropic/claude-sonnet-4-5"`, `"google/gemini-2.5-pro"`
1776
+ * — is routed through AI Gateway with resumable streaming on by default.
1777
+ * This is the common case: no extra package to install, no provider to wire.
1778
+ * - A fully-constructed AI SDK `LanguageModel`, for any other provider or for
1779
+ * full control over provider/gateway options.
1780
+ *
1781
+ * @example String (Workers AI)
1782
+ * ```typescript
1783
+ * getModel() {
1784
+ * return "@cf/moonshotai/kimi-k2.7-code";
1785
+ * }
1786
+ * ```
1787
+ *
1788
+ * @example String (third-party via AI Gateway)
1789
+ * ```typescript
1790
+ * getModel() {
1791
+ * return "openai/gpt-5.5";
1792
+ * }
1793
+ * ```
1794
+ *
1795
+ * @example Bring your own provider
1796
+ * ```typescript
1797
+ * import { createOpenAI } from "@ai-sdk/openai";
1798
+ * getModel() {
1799
+ * return createOpenAI({ apiKey: this.env.OPENAI_API_KEY })("gpt-5.5");
1800
+ * }
1801
+ * ```
1802
+ */
1803
+ getModel(): ThinkModel;
1804
+ /**
1805
+ * Return the Workers AI binding used by the built-in default provider when
1806
+ * {@link getModel} returns a string. Defaults to `this.env.AI`. Override if
1807
+ * your binding is named something other than `AI`.
1712
1808
  */
1713
- getModel(): LanguageModel;
1809
+ getAIBinding(): Ai;
1810
+ /**
1811
+ * Lazily-constructed, instance-cached default provider. Bundles the `openai`
1812
+ * and `anthropic` wire-format plugins so a `"<provider>/<model>"` slug routes
1813
+ * through AI Gateway out of the box (covers OpenAI, Anthropic, Google,
1814
+ * xAI/Grok, Groq, and the OpenAI-compatible long tail).
1815
+ *
1816
+ * Cached per instance, which assumes {@link getAIBinding} is stable for the
1817
+ * lifetime of the agent (the default `this.env.AI` always is).
1818
+ */
1819
+ private _defaultProvider?;
1820
+ /**
1821
+ * Resolve a model value into a concrete AI SDK `LanguageModel`.
1822
+ *
1823
+ * Defaults to resolving {@link getModel}. A `LanguageModel` is returned as-is;
1824
+ * a string is built through the bundled default provider (see {@link getModel}
1825
+ * for the slug rules). Use this whenever you need a usable model outside the
1826
+ * main turn — e.g. a side `generateText` call for summarization/compaction —
1827
+ * since `getModel()` may return a bare string.
1828
+ */
1829
+ resolveModel(model?: ThinkModel): LanguageModel;
1714
1830
  /**
1715
1831
  * Return the system prompt for the assistant.
1716
1832
  * Used as fallback when no context blocks are configured via `configureSession`.
@@ -1750,6 +1866,14 @@ declare class Think<
1750
1866
  * Readable from tools/hooks during a turn (e.g. to branch on `kind`).
1751
1867
  */
1752
1868
  get activeChannel(): ChannelContext | undefined;
1869
+ /**
1870
+ * The server-supplied metadata stamped on the active turn's user message
1871
+ * ({@link ChatOptions.metadata}). Like the channel stamp, it is persisted on
1872
+ * the durable user message, so recovered/continued turns re-resolve the same
1873
+ * value; client-supplied message metadata can never populate it (reserved
1874
+ * keys are stripped at intake). `undefined` when the turn carried none.
1875
+ */
1876
+ get activeTurnMetadata(): Record<string, unknown> | undefined;
1753
1877
  /** Resolve a channel id to a turn-scoped {@link ChannelContext}, if registered. */
1754
1878
  private _resolveChannelContext;
1755
1879
  /**
@@ -1759,12 +1883,17 @@ declare class Think<
1759
1883
  */
1760
1884
  private _withChannelContext;
1761
1885
  /**
1762
- * Stamp the channel id onto user messages so a recovered/continued turn can
1763
- * re-resolve the channel from durable history.
1886
+ * Stamp the channel id — and, when supplied, the caller's turn metadata —
1887
+ * onto user messages so a recovered/continued turn can re-resolve both from
1888
+ * durable history.
1764
1889
  */
1765
1890
  private _stampChannel;
1891
+ /** Metadata of the latest user message in the given list, if any. */
1892
+ private _latestUserMessageMetadata;
1766
1893
  /** The channel stamped on the latest user message in the given list, if any. */
1767
1894
  private _channelFromMessages;
1895
+ /** The turn metadata stamped on the latest user message, if any. */
1896
+ private _turnMetadataFromMessages;
1768
1897
  /** Re-resolve the channel for a continuation from the latest user message. */
1769
1898
  private _channelFromLatestUserMessage;
1770
1899
  /**
@@ -3011,6 +3140,13 @@ declare class Think<
3011
3140
  * instead of inserting an orphan duplicate.
3012
3141
  */
3013
3142
  private _persistIncomingMessage;
3143
+ /**
3144
+ * Strip {@link RESERVED_MESSAGE_METADATA_KEYS} from a client-supplied message
3145
+ * at intake. Those keys are server-written turn context (stamped by
3146
+ * `_stampChannel`) that hooks and recovery re-resolve and trust, so a client
3147
+ * must never be able to forge them.
3148
+ */
3149
+ private _stripReservedMessageMetadata;
3014
3150
  private _persistClientTools;
3015
3151
  private _restoreClientTools;
3016
3152
  private _persistBody;
@@ -3697,6 +3833,14 @@ interface MessengerAuthor {
3697
3833
  interface MessengerAttachment {
3698
3834
  data?: ArrayBuffer;
3699
3835
  fetch?: () => Promise<ArrayBuffer>;
3836
+ /**
3837
+ * Platform-specific metadata needed to re-fetch the attachment after the
3838
+ * event has been serialized (e.g. across a sub-agent Durable Object hop).
3839
+ * Adapters store identifiers here — Telegram `fileId`, WhatsApp `mediaId`,
3840
+ * etc. — that survive serialization even when `fetch`, `data`, and `raw`
3841
+ * cannot, so a downstream agent can reconstruct the download closure.
3842
+ */
3843
+ fetchMetadata?: Record<string, string>;
3700
3844
  id?: string;
3701
3845
  mediaType?: string;
3702
3846
  name?: string;
@@ -3757,7 +3901,23 @@ declare function messengerContextFromEvent(
3757
3901
  declare function serializableMessengerEvent(
3758
3902
  event: MessengerEvent
3759
3903
  ): MessengerEvent;
3760
- declare function toMessengerUserMessage(event: MessengerEvent): UIMessage;
3904
+ /**
3905
+ * Customizes how channel (non-DM) speaker names are prefixed onto model-facing
3906
+ * text. By default, speaker labels use `fullName || userName || userId`.
3907
+ * Direct messages never get a speaker prefix, regardless of this setting.
3908
+ * Return `null`/empty to suppress the prefix for that author.
3909
+ */
3910
+ type ChannelSpeakerLabel = (
3911
+ author: MessengerAuthor
3912
+ ) => string | null | undefined;
3913
+ declare function resolveChannelSpeakerLabel(
3914
+ author: MessengerAuthor | undefined,
3915
+ channelSpeakerLabel?: ChannelSpeakerLabel
3916
+ ): string | undefined;
3917
+ declare function toMessengerUserMessage(
3918
+ event: MessengerEvent,
3919
+ channelSpeakerLabel?: ChannelSpeakerLabel
3920
+ ): UIMessage;
3761
3921
  //#endregion
3762
3922
  //#region src/messengers/delivery.d.ts
3763
3923
  declare const MESSENGER_REPLY_FIBER_NAME = "think:messenger-reply";
@@ -3933,6 +4093,14 @@ interface MessengerDefinition {
3933
4093
  adapter: Adapter;
3934
4094
  adapterName: string;
3935
4095
  capabilities?: MessengerCapabilities;
4096
+ /**
4097
+ * Customizes how non-DM channel messages are labelled for the model.
4098
+ *
4099
+ * Channel (group) messages use `fullName || userName || userId` by default and
4100
+ * are rendered as `SpeakerName: text` so the model can attribute multi-user
4101
+ * traffic. Direct messages never get a prefix.
4102
+ */
4103
+ channelSpeakerLabel?: ChannelSpeakerLabel;
3936
4104
  conversation?: MessengerConversationMode | MessengerConversationResolver;
3937
4105
  delivery?: MessengerDeliveryPolicy;
3938
4106
  keyShard?: ChatSdkStateAdapterOptions["keyShard"];
@@ -4061,6 +4229,24 @@ declare function defaultChatSdkEvent(
4061
4229
  definition: NormalizedMessengerDefinition,
4062
4230
  input: ChatSdkMessengerEventInput
4063
4231
  ): MessengerEvent;
4232
+ /**
4233
+ * Rewrite the bot's own unresolved self-mention to `@<userName>`.
4234
+ *
4235
+ * Adapters resolve every user's `<@id>` mention to a readable `@DisplayName`
4236
+ * except the bot's own, which is deliberately left as a raw id token so mention
4237
+ * detection can still find it. That raw id is therefore the only unresolved
4238
+ * mention that can survive in the text, so once it has served its purpose we
4239
+ * replace it with the bot's configured handle before the model sees it —
4240
+ * reconstructing the readable `@handle` the sender originally typed. Handles
4241
+ * both the angle-bracket form (`<@U123>` / `<@!U123>`, Slack/Discord) and the
4242
+ * bare `@U123` form some adapters normalize to. No-op when the adapter does not
4243
+ * expose a `botUserId`.
4244
+ */
4245
+ declare function resolveSelfMention(
4246
+ text: string,
4247
+ botUserId: string | undefined,
4248
+ userName: string
4249
+ ): string;
4064
4250
  declare function toMessengerThread(thread: Thread): MessengerThread;
4065
4251
  declare function toMessengerMessage(message: Message): MessengerMessage;
4066
4252
  declare function toMessengerAuthor(author: Author): MessengerAuthor;
@@ -4069,154 +4255,159 @@ declare function toMessengerAttachment(
4069
4255
  ): MessengerAttachment;
4070
4256
  //#endregion
4071
4257
  export {
4072
- messengerContextFromEvent as $,
4073
- StepResult as $t,
4074
- MessengerDeliveryPolicy as A,
4075
- skills as An,
4076
- FiberRecoveryContext$1 as At,
4077
- messengerReplyRecoveryMode as B,
4078
- messengerChannel as Bn,
4079
- RunTurnBase as Bt,
4080
- DeliverMessengerReplyOptions as C,
4081
- TurnResult as Cn,
4082
- ChunkContext as Ct,
4083
- ERROR_MESSENGER_RESPONSE as D,
4084
- action as Dn,
4085
- DeliverNoticeOptions as Dt,
4086
- EMPTY_MESSENGER_RESPONSE as E,
4087
- Workspace$1 as En,
4088
- DeleteSubmissionsOptions as Et,
4089
- TextStreamCallback as F,
4090
- ChannelDeliverySurface as Fn,
4091
- PrepareStepContext as Ft,
4092
- MessengerAttachment as G,
4093
- SaveMessagesOptions$1 as Gt,
4094
- parseMessengerReplySnapshot as H,
4095
- RunTurnStream as Ht,
4096
- TextStreamCallbackOptions as I,
4097
- ChannelIngress as In,
4098
- PrepareStepFunction$1 as It,
4099
- MessengerContext as J,
4100
- SessionMessage$1 as Jt,
4101
- MessengerAuthor as K,
4102
- SaveMessagesResult$1 as Kt,
4103
- defaultDeliveryTag as L,
4104
- ChannelKind as Ln,
4105
- PrepareStepResult$1 as Lt,
4106
- MessengerDeliveryTarget as M,
4107
- ChannelContext as Mn,
4108
- MessageConcurrency$1 as Mt,
4109
- MessengerReplySnapshot as N,
4110
- ChannelDefinition as Nn,
4111
- OnStartDegradation as Nt,
4112
- INTERRUPTED_MESSENGER_RESPONSE as O,
4113
- defaultContextOverflowClassifier as On,
4114
- ExtensionConfig as Ot,
4115
- MessengerReplyStage as P,
4116
- ChannelDeliveryPolicy as Pn,
4117
- PendingApproval as Pt,
4118
- MessengerThread as Q,
4119
- StepContext as Qt,
4120
- deliverMessengerReply as R,
4121
- NormalizedChannelDefinition as Rn,
4122
- ReplyAttachment as Rt,
4123
- toMessengerThread as S,
4124
- TurnInputMessages as Sn,
4125
- ChatStartEvent as St,
4126
- DeliveryTag as T,
4127
- TypedToolResult as Tn,
4128
- ContextOverflowConfig as Tt,
4129
- textDeltaFromStreamChunk as U,
4130
- RunTurnSubmit as Ut,
4131
- messengerReplySnapshot as V,
4132
- MediaEvictionConfig as Vn,
4133
- RunTurnOptions as Vt,
4134
- MessengerAction as W,
4135
- RunTurnWait as Wt,
4136
- MessengerEventKind as X,
4137
- SkillSource$1 as Xt,
4138
- MessengerEvent as Y,
4139
- SkillRunContext as Yt,
4140
- MessengerMessage as Z,
4141
- StepConfig as Zt,
4258
+ MessengerMessage as $,
4259
+ SkillSource$1 as $t,
4260
+ MESSENGER_REPLY_FIBER_NAME as A,
4261
+ TypedToolResult as An,
4262
+ DeliverNoticeOptions as At,
4263
+ messengerReplyFailureMode as B,
4264
+ ChannelDeliverySurface as Bn,
4265
+ PrepareStepResult$1 as Bt,
4266
+ toMessengerThread as C,
4267
+ ToolCallResultContext as Cn,
4268
+ ChatRecoveryProgressContext as Ct,
4269
+ EMPTY_MESSENGER_RESPONSE as D,
4270
+ TurnInputMessages as Dn,
4271
+ ChunkPart as Dt,
4272
+ DeliveryTag as E,
4273
+ TurnInput as En,
4274
+ ChunkContext as Et,
4275
+ MessengerReplyStage as F,
4276
+ skills as Fn,
4277
+ MessageConcurrency$1 as Ft,
4278
+ ChannelSpeakerLabel as G,
4279
+ messengerChannel as Gn,
4280
+ RunTurnStream as Gt,
4281
+ messengerReplySnapshot as H,
4282
+ ChannelKind as Hn,
4283
+ ResolvedChatRecoveryConfig as Ht,
4284
+ TextStreamCallback as I,
4285
+ ChannelCapabilities as In,
4286
+ OnStartDegradation as It,
4287
+ MessengerAuthor as J,
4288
+ SaveMessagesOptions$1 as Jt,
4289
+ MessengerAction as K,
4290
+ MediaEvictionConfig as Kn,
4291
+ RunTurnSubmit as Kt,
4292
+ TextStreamCallbackOptions as L,
4293
+ ChannelContext as Ln,
4294
+ PendingApproval as Lt,
4295
+ MessengerDeliverySurface as M,
4296
+ action as Mn,
4297
+ FiberContext$1 as Mt,
4298
+ MessengerDeliveryTarget as N,
4299
+ defaultContextOverflowClassifier as Nn,
4300
+ FiberRecoveryContext$1 as Nt,
4301
+ ERROR_MESSENGER_RESPONSE as O,
4302
+ TurnResult as On,
4303
+ ContextOverflowConfig as Ot,
4304
+ MessengerReplySnapshot as P,
4305
+ isAction as Pn,
4306
+ ListSubmissionsOptions as Pt,
4307
+ MessengerEventKind as Q,
4308
+ SkillRunContext as Qt,
4309
+ defaultDeliveryTag as R,
4310
+ ChannelDefinition as Rn,
4311
+ PrepareStepContext as Rt,
4312
+ toMessengerMessage as S,
4313
+ ToolCallDecision as Sn,
4314
+ ChatRecoveryOptions$1 as St,
4315
+ DeliveryKind as T,
4316
+ TurnContext as Tn,
4317
+ ChatStartEvent as Tt,
4318
+ parseMessengerReplySnapshot as U,
4319
+ NormalizedChannelDefinition as Un,
4320
+ RunTurnBase as Ut,
4321
+ messengerReplyRecoveryMode as V,
4322
+ ChannelIngress as Vn,
4323
+ ReplyAttachment as Vt,
4324
+ textDeltaFromStreamChunk as W,
4325
+ ThinkChannels as Wn,
4326
+ RunTurnOptions as Wt,
4327
+ MessengerContext as X,
4328
+ Session$1 as Xt,
4329
+ MessengerCapabilities as Y,
4330
+ SaveMessagesResult$1 as Yt,
4331
+ MessengerEvent as Z,
4332
+ SessionMessage$1 as Zt,
4142
4333
  idempotencyKeyForEvent as _,
4143
- ToolCallDecision as _n,
4144
- ChatRecoveryContext$1 as _t,
4334
+ ThinkSubmissionInspection as _n,
4335
+ ChatErrorContext as _t,
4145
4336
  MessengerConversationTarget as a,
4146
- TextStreamPart as an,
4147
- ActionAuthorizationContext as at,
4148
- toMessengerAuthor as b,
4149
- TurnContext as bn,
4150
- ChatRecoveryProgressContext as bt,
4337
+ StreamableResult as an,
4338
+ Action as at,
4339
+ toMessengerAttachment as b,
4340
+ ThinkWallClockSchedule as bn,
4341
+ ChatRecoveryContext$1 as bt,
4151
4342
  MessengerThinkHost as c,
4152
- ThinkScheduledTask as cn,
4153
- ActionContext as ct,
4343
+ TextStreamPart as cn,
4344
+ ActionAuthorizationContext as ct,
4154
4345
  ThinkMessengerRuntime as d,
4155
- ThinkScheduledTasks as dn,
4156
- ActionPermissionSpec as dt,
4157
- StopCondition$1 as en,
4158
- serializableMessengerEvent as et,
4346
+ ThinkModel as dn,
4347
+ ActionContext as dt,
4348
+ StepConfig as en,
4349
+ MessengerThread as et,
4159
4350
  ThinkMessengerStateAgent as f,
4160
- ThinkSubmissionInspection as fn,
4161
- AddMessagesOptions as ft,
4351
+ ThinkModelId as fn,
4352
+ ActionIdempotencyKey as ft,
4162
4353
  defaultConversationName as g,
4163
- ToolCallContext as gn,
4164
- ChatRecoveryConfig$1 as gt,
4354
+ ThinkScheduledTasks as gn,
4355
+ ChatErrorClassification as gt,
4165
4356
  defaultChatSdkEvent as h,
4166
- ThinkWallClockSchedule as hn,
4167
- ChatOptions as ht,
4357
+ ThinkScheduledTaskSchedule as hn,
4358
+ AddMessagesOptions as ht,
4168
4359
  MessengerConversationResolver as i,
4169
- SubmitMessagesResult as in,
4170
- ActionApprovalPolicy as it,
4171
- MessengerDeliverySurface as j,
4172
- ChannelCapabilities as jn,
4173
- ListSubmissionsOptions as jt,
4174
- MESSENGER_REPLY_FIBER_NAME as k,
4175
- isAction as kn,
4176
- FiberContext$1 as kt,
4360
+ StreamCallback as in,
4361
+ toMessengerUserMessage as it,
4362
+ MessengerDeliveryPolicy as j,
4363
+ Workspace$1 as jn,
4364
+ ExtensionConfig as jt,
4365
+ INTERRUPTED_MESSENGER_RESPONSE as k,
4366
+ TypedToolCall$1 as kn,
4367
+ DeleteSubmissionsOptions as kt,
4177
4368
  MessengerThinkTarget as l,
4178
- ThinkScheduledTaskContext as ln,
4179
- ActionIdempotencyKey as lt,
4369
+ Think as ln,
4370
+ ActionAuthorizationDecision as lt,
4180
4371
  chatSdkMessenger as m,
4181
- ThinkTime as mn,
4182
- ChatErrorContext as mt,
4372
+ ThinkScheduledTaskContext as mn,
4373
+ ActionPermissionSpec as mt,
4183
4374
  ChatSdkMessengerOptions as n,
4184
- StreamableResult as nn,
4185
- Action as nt,
4375
+ StepResult as nn,
4376
+ resolveChannelSpeakerLabel as nt,
4186
4377
  MessengerDefinition as o,
4187
- Think as on,
4188
- ActionAuthorizationDecision as ot,
4378
+ SubmitMessagesOptions as on,
4379
+ ActionApprovalDescriptor as ot,
4189
4380
  ThinkMessengers as p,
4190
- ThinkSubmissionStatus as pn,
4191
- ChatErrorClassification as pt,
4192
- MessengerCapabilities as q,
4193
- Session$1 as qt,
4381
+ ThinkScheduledTask as pn,
4382
+ ActionKind as pt,
4383
+ MessengerAttachment as q,
4384
+ RunTurnWait as qt,
4194
4385
  MessengerConversationMode as r,
4195
- SubmitMessagesOptions as rn,
4196
- ActionApprovalDescriptor as rt,
4386
+ StopCondition$1 as rn,
4387
+ serializableMessengerEvent as rt,
4197
4388
  MessengerRespondTo as s,
4198
- ThinkIntervalSchedule as sn,
4199
- ActionConfig as st,
4389
+ SubmitMessagesResult as sn,
4390
+ ActionApprovalPolicy as st,
4200
4391
  ChatSdkMessengerEventInput as t,
4201
- StreamCallback as tn,
4202
- toMessengerUserMessage as tt,
4392
+ StepContext as tn,
4393
+ messengerContextFromEvent as tt,
4203
4394
  NormalizedMessengerDefinition as u,
4204
- ThinkScheduledTaskSchedule as un,
4205
- ActionKind as ut,
4395
+ ThinkIntervalSchedule as un,
4396
+ ActionConfig as ut,
4206
4397
  normalizeMessengers as v,
4207
- ToolCallResultContext as vn,
4208
- ChatRecoveryExhaustedContext as vt,
4209
- DeliveryKind as w,
4210
- TypedToolCall$1 as wn,
4211
- ChunkPart as wt,
4212
- toMessengerMessage as x,
4213
- TurnInput as xn,
4214
- ChatResponseResult$1 as xt,
4215
- toMessengerAttachment as y,
4216
- TurnConfig as yn,
4217
- ChatRecoveryOptions$1 as yt,
4218
- messengerReplyFailureMode as z,
4219
- ThinkChannels as zn,
4220
- ResolvedChatRecoveryConfig as zt
4398
+ ThinkSubmissionStatus as vn,
4399
+ ChatOptions as vt,
4400
+ DeliverMessengerReplyOptions as w,
4401
+ TurnConfig as wn,
4402
+ ChatResponseResult$1 as wt,
4403
+ toMessengerAuthor as x,
4404
+ ToolCallContext as xn,
4405
+ ChatRecoveryExhaustedContext as xt,
4406
+ resolveSelfMention as y,
4407
+ ThinkTime as yn,
4408
+ ChatRecoveryConfig$1 as yt,
4409
+ deliverMessengerReply as z,
4410
+ ChannelDeliveryPolicy as zn,
4411
+ PrepareStepFunction$1 as zt
4221
4412
  };
4222
- //# sourceMappingURL=index-CR4-ffm_.d.ts.map
4413
+ //# sourceMappingURL=index-Cm0jriTY.d.ts.map