OpenAI ChatGPT browser and device authentication, token refresh and model connections.

Part of the [FlexHarness toolbox](https://code.foss.global/modelprofile.com/flexharness).
Install the components your project uses. Provider adapters are registered explicitly;
the agent and harness do not install or register vendor SDKs.

```sh
pnpm add @modelprofile.com/flexharness-providers
```

See the [toolbox usage and migration guide](https://code.foss.global/modelprofile.com/flexharness#readme)
for composition examples and the SmartAI/SmartAgent migration map.

The refresh helper preserves safe request-outcome metadata on
`OpenAiChatGptAuthError`: `requestOutcome` is `notSent` only before the HTTP
request is handed to `fetch`, and `outcomeUnknown` afterward. An observed
response can also supply `status` and a bounded `retryAfterMs`. A 429 response
does not prove that a rotating grant remained usable. The default safe-error
mode omits provider response bodies.

`createOpenAiChatGptModelConnection()` derives account and FedRAMP headers from
the current access token. The token must contain an unexpired `exp` claim;
supplied `accountId`, `isFedrampAccount`, and `tokenInfo` must agree with its
claims. A saved ID-token snapshot cannot override current access-token facts.

Use `createOpenAiChatGptDynamicModelConnection()` for delegated access owned by
an external authority. Pin its exact account and FedRAMP identity, then provide
an async `resolveAccess({ signal })` callback. The connection resolves and
validates current access immediately before every provider HTTP request, so
multi-step tool runs do not retain the token that admitted the run. Resolution,
identity, expiry, endpoint, redirect, and abort failures stop before the
underlying transport is called.

Both ChatGPT connections classify Codex limits with `classifyOpenAiChatGptLimit`:
`usage_limit_reached` and `usage_not_included`, from a 429 body or a failed stream,
fail as a `ModelLimitError` of kind `usage_limit`. Its reset comes from `resets_at`,
then `resets_in_seconds`, then the exhausted `x-codex-primary` or `x-codex-secondary`
window, which also names the `window` (for example `5h`); `plan_type` becomes `planType`.

## Issue Reporting and Security

Report issues and security concerns through [community.foss.global](https://community.foss.global).

## License and Legal Information

This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.

**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

### Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.

Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.

### Company Information

Task Venture Capital GmbH<br>
Registered at District Court Bremen HRB 35230 HB, Germany

For any legal inquiries or further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
