MCPcopy
hub / github.com/TanStack/ai / updateOptions

Method updateOptions

packages/ai-client/src/chat-client.ts:1440–1518  ·  view source on GitHub ↗
(
    options: ChatClientUpdateOptionsWithoutContext<TTools> & {
      context?: TContext | undefined
    },
  )

Source from the content-addressed store, hash-verified

1438 Pick<ChatClientOptions<TTools, TContext>, 'context'>,
1439 ): void
1440 updateOptions(
1441 options: ChatClientUpdateOptionsWithoutContext<TTools> & {
1442 context?: TContext | undefined
1443 },
1444 ): void {
1445 if (options.connection !== undefined || options.fetcher !== undefined) {
1446 const wasSubscribed = this.isSubscribed
1447
1448 if (this.isLoading) {
1449 this.cancelInFlightStream({
1450 setReadyStatus: true,
1451 abortSubscription: true,
1452 })
1453 } else if (wasSubscribed) {
1454 this.abortSubscriptionLoop()
1455 }
1456
1457 this.resetSessionGenerating()
1458 this.setIsSubscribed(false)
1459 this.setConnectionStatus('disconnected')
1460 this.connection = normalizeConnectionAdapter(
1461 resolveTransport({
1462 connection: options.connection,
1463 fetcher: options.fetcher,
1464 }),
1465 )
1466
1467 if (wasSubscribed) {
1468 this.subscribe()
1469 }
1470 }
1471 // Replace each wire-payload slot independently so callers can update one
1472 // without wiping the other. Passing `undefined` for `body` or
1473 // `forwardedProps` leaves that slot unchanged; context is cleared when the
1474 // key is present with an `undefined` value.
1475 if (options.body !== undefined) {
1476 this.bodyOption = options.body
1477 }
1478 if (options.forwardedProps !== undefined) {
1479 this.forwardedPropsOption = options.forwardedProps
1480 }
1481 if ('context' in options) {
1482 this.context = options.context
1483 }
1484 if (options.tools !== undefined) {
1485 this.clientToolsRef.current = new Map()
1486 for (const tool of options.tools) {
1487 this.clientToolsRef.current.set(tool.name, tool)
1488 }
1489 this.devtoolsBridge.notifyToolsChanged()
1490 }
1491 if (options.onResponse !== undefined) {
1492 this.callbacksRef.current.onResponse = options.onResponse
1493 }
1494 if (options.onChunk !== undefined) {
1495 this.callbacksRef.current.onChunk = options.onChunk
1496 }
1497 if (options.onFinish !== undefined) {

Callers 15

injectChatFunction · 0.95
useChatFunction · 0.95
injectGenerationFunction · 0.45
injectGenerateVideoFunction · 0.45
useGenerationFunction · 0.45
useGenerateVideoFunction · 0.45
useGenerationFunction · 0.45
useChatFunction · 0.45
useGenerateVideoFunction · 0.45
tool-types.test.tsFile · 0.45

Calls 10

cancelInFlightStreamMethod · 0.95
abortSubscriptionLoopMethod · 0.95
setIsSubscribedMethod · 0.95
setConnectionStatusMethod · 0.95
subscribeMethod · 0.95
resolveTransportFunction · 0.70
setMethod · 0.65
notifyToolsChangedMethod · 0.45

Tested by

no test coverage detected