From a8ed4e8a2324e15412d6d1ded281c240a438b070 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 12:18:14 +0000 Subject: [PATCH 001/154] chore: configure new SDK language --- .github/actions/setup-go/action.yml | 29 + .github/workflows/ci.yml | 116 ++ .github/workflows/publish-release.yml | 32 + .github/workflows/release-doctor.yml | 19 + .gitignore | 5 + .goreleaser.yml | 80 ++ .release-please-manifest.json | 3 + .stats.yml | 4 + LICENSE | 201 +++ README.md | 131 +- SECURITY.md | 27 + bin/check-release-environment | 17 + cmd/context-dev/main.go | 74 + go.mod | 46 + go.sum | 89 ++ internal/apiform/encoder.go | 236 ++++ internal/apiform/form.go | 20 + internal/apiform/form_test.go | 113 ++ internal/apiquery/encoder.go | 166 +++ internal/apiquery/query.go | 53 + internal/apiquery/query_test.go | 132 ++ internal/autocomplete/autocomplete.go | 361 +++++ internal/autocomplete/autocomplete_test.go | 433 ++++++ .../shellscripts/bash_autocomplete.bash | 59 + .../shellscripts/fish_autocomplete.fish | 51 + .../shellscripts/pwsh_autocomplete.ps1 | 97 ++ .../shellscripts/zsh_autocomplete.zsh | 56 + internal/binaryparam/binary_param.go | 30 + internal/binaryparam/binary_param_test.go | 59 + internal/debugmiddleware/debug_middleware.go | 132 ++ .../debugmiddleware/debug_middleware_test.go | 201 +++ internal/jsonview/explorer.go | 807 +++++++++++ internal/jsonview/explorer_test.go | 66 + internal/jsonview/staticdisplay.go | 135 ++ internal/mocktest/mocktest.go | 101 ++ internal/requestflag/innerflag.go | 289 ++++ internal/requestflag/innerflag_test.go | 347 +++++ internal/requestflag/requestflag.go | 992 +++++++++++++ internal/requestflag/requestflag_test.go | 1227 ++++++++++++++++ pkg/cmd/ai.go | 313 +++++ pkg/cmd/ai_test.go | 141 ++ pkg/cmd/brand.go | 581 ++++++++ pkg/cmd/brand_test.go | 125 ++ pkg/cmd/cmd.go | 227 +++ pkg/cmd/cmdutil.go | 525 +++++++ pkg/cmd/cmdutil_test.go | 388 ++++++ pkg/cmd/cmdutil_unix.go | 127 ++ pkg/cmd/cmdutil_windows.go | 35 + pkg/cmd/flagoptions.go | 692 +++++++++ pkg/cmd/flagoptions_test.go | 392 ++++++ pkg/cmd/industry.go | 169 +++ pkg/cmd/industry_test.go | 40 + pkg/cmd/suggest.go | 126 ++ pkg/cmd/utility.go | 139 ++ pkg/cmd/utility_test.go | 59 + pkg/cmd/version.go | 5 + pkg/cmd/web.go | 1237 +++++++++++++++++ pkg/cmd/web_test.go | 496 +++++++ release-please-config.json | 67 + scripts/bootstrap | 22 + scripts/build | 11 + scripts/format | 8 + scripts/link | 17 + scripts/lint | 11 + scripts/run | 10 + scripts/test | 18 + scripts/unlink | 8 + scripts/utils/upload-artifact.sh | 59 + 68 files changed, 13083 insertions(+), 1 deletion(-) create mode 100644 .github/actions/setup-go/action.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish-release.yml create mode 100644 .github/workflows/release-doctor.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yml create mode 100644 .release-please-manifest.json create mode 100644 .stats.yml create mode 100644 LICENSE create mode 100644 SECURITY.md create mode 100644 bin/check-release-environment create mode 100644 cmd/context-dev/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/apiform/encoder.go create mode 100644 internal/apiform/form.go create mode 100644 internal/apiform/form_test.go create mode 100644 internal/apiquery/encoder.go create mode 100644 internal/apiquery/query.go create mode 100644 internal/apiquery/query_test.go create mode 100644 internal/autocomplete/autocomplete.go create mode 100644 internal/autocomplete/autocomplete_test.go create mode 100755 internal/autocomplete/shellscripts/bash_autocomplete.bash create mode 100644 internal/autocomplete/shellscripts/fish_autocomplete.fish create mode 100644 internal/autocomplete/shellscripts/pwsh_autocomplete.ps1 create mode 100644 internal/autocomplete/shellscripts/zsh_autocomplete.zsh create mode 100644 internal/binaryparam/binary_param.go create mode 100644 internal/binaryparam/binary_param_test.go create mode 100644 internal/debugmiddleware/debug_middleware.go create mode 100644 internal/debugmiddleware/debug_middleware_test.go create mode 100644 internal/jsonview/explorer.go create mode 100644 internal/jsonview/explorer_test.go create mode 100644 internal/jsonview/staticdisplay.go create mode 100644 internal/mocktest/mocktest.go create mode 100644 internal/requestflag/innerflag.go create mode 100644 internal/requestflag/innerflag_test.go create mode 100644 internal/requestflag/requestflag.go create mode 100644 internal/requestflag/requestflag_test.go create mode 100644 pkg/cmd/ai.go create mode 100644 pkg/cmd/ai_test.go create mode 100644 pkg/cmd/brand.go create mode 100644 pkg/cmd/brand_test.go create mode 100644 pkg/cmd/cmd.go create mode 100644 pkg/cmd/cmdutil.go create mode 100644 pkg/cmd/cmdutil_test.go create mode 100644 pkg/cmd/cmdutil_unix.go create mode 100644 pkg/cmd/cmdutil_windows.go create mode 100644 pkg/cmd/flagoptions.go create mode 100644 pkg/cmd/flagoptions_test.go create mode 100644 pkg/cmd/industry.go create mode 100644 pkg/cmd/industry_test.go create mode 100644 pkg/cmd/suggest.go create mode 100644 pkg/cmd/utility.go create mode 100644 pkg/cmd/utility_test.go create mode 100644 pkg/cmd/version.go create mode 100644 pkg/cmd/web.go create mode 100644 pkg/cmd/web_test.go create mode 100644 release-please-config.json create mode 100755 scripts/bootstrap create mode 100755 scripts/build create mode 100755 scripts/format create mode 100755 scripts/link create mode 100755 scripts/lint create mode 100755 scripts/run create mode 100755 scripts/test create mode 100755 scripts/unlink create mode 100755 scripts/utils/upload-artifact.sh diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml new file mode 100644 index 0000000..0b2f3fa --- /dev/null +++ b/.github/actions/setup-go/action.yml @@ -0,0 +1,29 @@ +name: Setup Go +description: 'Sets up Go environment with private modules' +inputs: + stainless-api-key: + required: false + description: the value of the STAINLESS_API_KEY secret +runs: + using: composite + steps: + - uses: stainless-api/retrieve-github-access-token@1f03f929b746c5b03dcdafa2bebbb18ca5672e1a # v1.0.0 + if: github.repository == 'stainless-sdks/context.dev-cli' + id: get_token + with: + repo: stainless-sdks/context.dev-go + stainless-api-key: ${{ inputs.stainless-api-key }} + + - name: Configure Git for access to the Go SDK's staging repo + if: github.repository == 'stainless-sdks/context.dev-cli' + shell: bash + run: git config --global url."https://x-access-token:${{ steps.get_token.outputs.github_access_token }}@github.com/stainless-sdks/context.dev-go".insteadOf "https://github.com/stainless-sdks/context.dev-go" + + - name: Setup go + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version-file: ./go.mod + + - name: Bootstrap + shell: bash + run: ./scripts/bootstrap diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e4c6d5c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,116 @@ +name: CI +on: + push: + branches: + - '**' + - '!integrated/**' + - '!stl-preview-head/**' + - '!stl-preview-base/**' + - '!generated' + - '!codegen/**' + - 'codegen/stl/**' + pull_request: + branches-ignore: + - 'stl-preview-head/**' + - 'stl-preview-base/**' + +env: + GOPRIVATE: github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go + +jobs: + lint: + timeout-minutes: 10 + name: lint + runs-on: ${{ github.repository == 'stainless-sdks/context.dev-cli' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - uses: ./.github/actions/setup-go + with: + stainless-api-key: ${{ secrets.STAINLESS_API_KEY }} + + - name: Link staging branch + if: github.repository == 'stainless-sdks/context.dev-cli' + run: | + ./scripts/link 'github.com/stainless-sdks/context.dev-go@${{ github.ref_name }}' || true + + - name: Bootstrap + run: ./scripts/bootstrap + + - name: Run lints + run: ./scripts/lint + + build: + timeout-minutes: 10 + name: build + permissions: + contents: read + id-token: write + runs-on: ${{ github.repository == 'stainless-sdks/context.dev-cli' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - uses: ./.github/actions/setup-go + with: + stainless-api-key: ${{ secrets.STAINLESS_API_KEY }} + + - name: Link staging branch + if: github.repository == 'stainless-sdks/context.dev-cli' + run: | + ./scripts/link 'github.com/stainless-sdks/context.dev-go@${{ github.ref_name }}' || true + + - name: Bootstrap + run: ./scripts/bootstrap + + - name: Run goreleaser + uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0 + with: + version: latest + args: release --snapshot --clean --skip=publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Get GitHub OIDC Token + if: |- + github.repository == 'stainless-sdks/context.dev-cli' && + !startsWith(github.ref, 'refs/heads/stl/') + id: github-oidc + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 + with: + script: core.setOutput('github_token', await core.getIDToken()); + + - name: Upload tarball + if: |- + github.repository == 'stainless-sdks/context.dev-cli' && + !startsWith(github.ref, 'refs/heads/stl/') + env: + URL: https://pkg.stainless.com/s + AUTH: ${{ steps.github-oidc.outputs.github_token }} + SHA: ${{ github.sha }} + run: ./scripts/utils/upload-artifact.sh + + test: + timeout-minutes: 10 + name: test + runs-on: ${{ github.repository == 'stainless-sdks/context.dev-cli' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - uses: ./.github/actions/setup-go + with: + stainless-api-key: ${{ secrets.STAINLESS_API_KEY }} + + - name: Link staging branch + if: github.repository == 'stainless-sdks/context.dev-cli' + run: | + ./scripts/link 'github.com/stainless-sdks/context.dev-go@${{ github.ref_name }}' || true + + - name: Bootstrap + run: ./scripts/bootstrap + + - name: Run tests + run: ./scripts/test diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000..6b026e0 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,32 @@ +--- +name: Publish Release +permissions: + contents: write + +concurrency: + group: publish + +on: + push: + tags: + - "v*" + workflow_dispatch: {} +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version-file: "go.mod" + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml new file mode 100644 index 0000000..861de6b --- /dev/null +++ b/.github/workflows/release-doctor.yml @@ -0,0 +1,19 @@ +name: Release Doctor +on: + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + release_doctor: + name: release doctor + runs-on: ubuntu-latest + if: github.repository == 'stainless-sdks/context.dev-cli' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next') + + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Check release environment + run: | + bash ./bin/check-release-environment diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3006e55 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.prism.log +.stdy.log +dist/ +/context-dev +*.exe diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..87fb1b3 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,80 @@ +project_name: context-dev +version: 2 + +before: + hooks: + - mkdir -p completions + - sh -c "go run ./cmd/context-dev/main.go @completion bash > completions/context-dev.bash" + - sh -c "go run ./cmd/context-dev/main.go @completion zsh > completions/context-dev.zsh" + - sh -c "go run ./cmd/context-dev/main.go @completion fish > completions/context-dev.fish" + - sh -c "go run ./cmd/context-dev/main.go @manpages -o man" + +builds: + - id: macos + goos: [darwin] + goarch: [amd64, arm64] + binary: '{{ .ProjectName }}' + main: ./cmd/context-dev/main.go + mod_timestamp: '{{ .CommitTimestamp }}' + ldflags: + - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' + + - id: linux + goos: [linux] + goarch: ['386', arm, amd64, arm64] + env: + - CGO_ENABLED=0 + binary: '{{ .ProjectName }}' + main: ./cmd/context-dev/main.go + mod_timestamp: '{{ .CommitTimestamp }}' + ldflags: + - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' + + - id: windows + goos: [windows] + goarch: ['386', amd64, arm64] + binary: '{{ .ProjectName }}' + main: ./cmd/context-dev/main.go + mod_timestamp: '{{ .CommitTimestamp }}' + ldflags: + - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' + +archives: + - id: linux-archive + ids: [linux] + name_template: '{{ .ProjectName }}_{{ .Version }}_linux_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + formats: [tar.gz] + files: + - completions/* + - man/*/* + - id: macos-archive + ids: [macos] + name_template: '{{ .ProjectName }}_{{ .Version }}_macos_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + formats: [zip] + files: + - completions/* + - man/*/* + - id: windows-archive + ids: [windows] + name_template: '{{ .ProjectName }}_{{ .Version }}_windows_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + formats: [zip] + files: + - completions/* + - man/*/* + +snapshot: + version_template: '{{ .Tag }}-next' + +nfpms: + - license: Apache-2.0 + maintainer: hello@context.dev + bindir: /usr + formats: + - apk + - deb + - rpm + - termux.deb + - archlinux + contents: + - src: man/man1/*.1.gz + dst: /usr/share/man/man1/ diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..1332969 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.1" +} \ No newline at end of file diff --git a/.stats.yml b/.stats.yml new file mode 100644 index 0000000..db7c82e --- /dev/null +++ b/.stats.yml @@ -0,0 +1,4 @@ +configured_endpoints: 25 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-0253523aec437a0e9c67c3386fa25ed52ebbcc0073c907f0aa3586d8010d2e9d.yml +openapi_spec_hash: 5cf86ed865b01dfe3a159a45315ebb49 +config_hash: 2b6e4424b446fe1bf93359ba758c83ed diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dde764d --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2026 Context Dev + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 9aab08b..abca44f 100644 --- a/README.md +++ b/README.md @@ -1 +1,130 @@ -# context.dev-cli \ No newline at end of file +# Context Dev CLI + +The official CLI for the [Context Dev REST API](https://docs.context.dev/). + +It is generated with [Stainless](https://www.stainless.com/). + +## Installation + +### Installing with Go + +To test or install the CLI locally, you need [Go](https://go.dev/doc/install) version 1.22 or later installed. + +```sh +go install 'github.com/stainless-sdks/context.dev-cli/cmd/context-dev@latest' +``` + +Once you have run `go install`, the binary is placed in your Go bin directory: + +- **Default location**: `$HOME/go/bin` (or `$GOPATH/bin` if GOPATH is set) +- **Check your path**: Run `go env GOPATH` to see the base directory + +If commands aren't found after installation, add the Go bin directory to your PATH: + +```sh +# Add to your shell profile (.zshrc, .bashrc, etc.) +export PATH="$PATH:$(go env GOPATH)/bin" +``` + +### Running Locally + +After cloning the git repository for this project, you can use the +`scripts/run` script to run the tool locally: + +```sh +./scripts/run args... +``` + +## Usage + +The CLI follows a resource-based command structure: + +```sh +context-dev [resource] [flags...] +``` + +```sh +context-dev brand retrieve \ + --api-key 'My API Key' \ + --domain REPLACE_ME +``` + +For details about specific commands, use the `--help` flag. + +### Environment variables + +| Environment variable | Required | +| --------------------- | -------- | +| `CONTEXT_DEV_API_KEY` | yes | + +### Global flags + +- `--api-key` (can also be set with `CONTEXT_DEV_API_KEY` env var) +- `--help` - Show command line usage +- `--debug` - Enable debug logging (includes HTTP request/response details) +- `--version`, `-v` - Show the CLI version +- `--base-url` - Use a custom API backend URL +- `--format` - Change the output format (`auto`, `explore`, `json`, `jsonl`, `pretty`, `raw`, `yaml`) +- `--format-error` - Change the output format for errors (`auto`, `explore`, `json`, `jsonl`, `pretty`, `raw`, `yaml`) +- `--transform` - Transform the data output using [GJSON syntax](https://github.com/tidwall/gjson/blob/master/SYNTAX.md) +- `--transform-error` - Transform the error output using [GJSON syntax](https://github.com/tidwall/gjson/blob/master/SYNTAX.md) + +### Passing files as arguments + +To pass files to your API, you can use the `@myfile.ext` syntax: + +```bash +context-dev --arg @abe.jpg +``` + +Files can also be passed inside JSON or YAML blobs: + +```bash +context-dev --arg '{image: "@abe.jpg"}' +# Equivalent: +context-dev < --username '\@abe' +``` + +#### Explicit encoding + +For JSON endpoints, the CLI tool does filetype sniffing to determine whether the +file contents should be sent as a string literal (for plain text files) or as a +base64-encoded string literal (for binary files). If you need to explicitly send +the file as either plain text or base64-encoded data, you can use +`@file://myfile.txt` (for string encoding) or `@data://myfile.dat` (for +base64-encoding). Note that absolute paths will begin with `@file://` or +`@data://`, followed by a third `/` (for example, `@file:///tmp/file.txt`). + +```bash +context-dev --arg @data://file.txt +``` + +## Linking different Go SDK versions + +You can link the CLI against a different version of the Context Dev Go SDK +for development purposes using the `./scripts/link` script. + +To link to a specific version from a repository (version can be a branch, +git tag, or commit hash): + +```bash +./scripts/link github.com/org/repo@version +``` + +To link to a local copy of the SDK: + +```bash +./scripts/link ../path/to/contextdev-go +``` + +If you run the link script without any arguments, it will default to `../contextdev-go`. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..22d7755 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,27 @@ +# Security Policy + +## Reporting Security Issues + +This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken. + +To report a security issue, please contact the Stainless team at security@stainless.com. + +## Responsible Disclosure + +We appreciate the efforts of security researchers and individuals who help us maintain the security of +SDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible +disclosure practices by allowing us a reasonable amount of time to investigate and address the issue +before making any information public. + +## Reporting Non-SDK Related Security Issues + +If you encounter security issues that are not directly related to SDKs but pertain to the services +or products provided by Context Dev, please follow the respective company's security reporting guidelines. + +### Context Dev Terms and Policies + +Please contact hello@context.dev for any questions or concerns regarding the security of our services. + +--- + +Thank you for helping us keep the SDKs and systems they interact with secure. diff --git a/bin/check-release-environment b/bin/check-release-environment new file mode 100644 index 0000000..1e951e9 --- /dev/null +++ b/bin/check-release-environment @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +errors=() + +lenErrors=${#errors[@]} + +if [[ lenErrors -gt 0 ]]; then + echo -e "Found the following errors in the release environment:\n" + + for error in "${errors[@]}"; do + echo -e "- $error\n" + done + + exit 1 +fi + +echo "The environment is ready to push releases!" diff --git a/cmd/context-dev/main.go b/cmd/context-dev/main.go new file mode 100644 index 0000000..3fff3f8 --- /dev/null +++ b/cmd/context-dev/main.go @@ -0,0 +1,74 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package main + +import ( + "context" + "errors" + "fmt" + "net/http" + "os" + "slices" + + "github.com/context-dot-dev/context-go-sdk" + "github.com/stainless-sdks/context.dev-cli/pkg/cmd" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +func main() { + app := cmd.Command + + if slices.Contains(os.Args, "__complete") { + prepareForAutocomplete(app) + } + + if baseURL, ok := os.LookupEnv("CONTEXT_DEV_BASE_URL"); ok { + if err := cmd.ValidateBaseURL(baseURL, "CONTEXT_DEV_BASE_URL"); err != nil { + fmt.Fprintf(os.Stderr, "%s\n", err.Error()) + os.Exit(1) + } + } + + if err := app.Run(context.Background(), os.Args); err != nil { + exitCode := 1 + + // Check if error has a custom exit code + if exitErr, ok := err.(cli.ExitCoder); ok { + exitCode = exitErr.ExitCode() + } + + var apierr *contextdev.Error + if errors.As(err, &apierr) { + fmt.Fprintf(os.Stderr, "%s %q: %d %s\n", apierr.Request.Method, apierr.Request.URL, apierr.Response.StatusCode, http.StatusText(apierr.Response.StatusCode)) + format := app.String("format-error") + json := gjson.Parse(apierr.RawJSON()) + show_err := cmd.ShowJSON(json, cmd.ShowJSONOpts{ + ExplicitFormat: app.IsSet("format-error"), + Format: format, + Title: "Error", + Transform: app.String("transform-error"), + }) + if show_err != nil { + // Just print the original error: + fmt.Fprintf(os.Stderr, "%s\n", err.Error()) + } + } else { + if cmd.CommandErrorBuffer.Len() > 0 { + os.Stderr.Write(cmd.CommandErrorBuffer.Bytes()) + } else { + fmt.Fprintf(os.Stderr, "%s\n", err.Error()) + } + } + os.Exit(exitCode) + } +} + +func prepareForAutocomplete(cmd *cli.Command) { + // urfave/cli does not handle flag completions and will print an error if we inspect a command with invalid flags. + // This skips that sort of validation + cmd.SkipFlagParsing = true + for _, child := range cmd.Commands { + prepareForAutocomplete(child) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5eccdd4 --- /dev/null +++ b/go.mod @@ -0,0 +1,46 @@ +module github.com/stainless-sdks/context.dev-cli + +go 1.25 + +require ( + github.com/charmbracelet/bubbles v0.21.0 + github.com/charmbracelet/bubbletea v1.3.6 + github.com/charmbracelet/lipgloss v1.1.0 + github.com/charmbracelet/x/term v0.2.1 + github.com/context-dot-dev/context-go-sdk v0.12.0 + github.com/goccy/go-yaml v1.18.0 + github.com/itchyny/json2yaml v0.1.4 + github.com/muesli/reflow v0.3.0 + github.com/stretchr/testify v1.10.0 + github.com/tidwall/gjson v1.18.0 + github.com/tidwall/pretty v1.2.1 + github.com/urfave/cli-docs/v3 v3.0.0-alpha6 + github.com/urfave/cli/v3 v3.3.2 + golang.org/x/sys v0.38.0 +) + +require ( + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect + github.com/charmbracelet/x/ansi v0.9.3 // indirect + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-localereader v0.0.1 // indirect + github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect + github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/termenv v0.16.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/sjson v1.2.5 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + golang.org/x/sync v0.15.0 // indirect + golang.org/x/text v0.3.8 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ded57b2 --- /dev/null +++ b/go.sum @@ -0,0 +1,89 @@ +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8= +github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA= +github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs= +github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg= +github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU= +github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc= +github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= +github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= +github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= +github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= +github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0= +github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= +github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8= +github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= +github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ= +github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= +github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= +github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= +github.com/context-dot-dev/context-go-sdk v0.12.0 h1:6OPISoUaLtSt+uDW+HTkzApLf9Q+OTNKbUwYdM6JeSU= +github.com/context-dot-dev/context-go-sdk v0.12.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= +github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= +github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= +github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= +github.com/itchyny/json2yaml v0.1.4 h1:/pErVOXGG5iTyXHi/QKR4y3uzhLjGTEmmJIy97YT+k8= +github.com/itchyny/json2yaml v0.1.4/go.mod h1:6iudhBZdarpjLFRNj+clWLAkGft+9uCcjAZYXUH9eGI= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= +github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= +github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= +github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= +github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= +github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= +github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= +github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= +github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= +github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= +github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= +github.com/urfave/cli-docs/v3 v3.0.0-alpha6 h1:w/l/N0xw1rO/aHRIGXJ0lDwwYFOzilup1qGvIytP3BI= +github.com/urfave/cli-docs/v3 v3.0.0-alpha6/go.mod h1:p7Z4lg8FSTrPB9GTaNyTrK3ygffHZcK3w0cU2VE+mzU= +github.com/urfave/cli/v3 v3.3.2 h1:BYFVnhhZ8RqT38DxEYVFPPmGFTEf7tJwySTXsVRrS/o= +github.com/urfave/cli/v3 v3.3.2/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= +golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= +golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/apiform/encoder.go b/internal/apiform/encoder.go new file mode 100644 index 0000000..857fe14 --- /dev/null +++ b/internal/apiform/encoder.go @@ -0,0 +1,236 @@ +package apiform + +import ( + "fmt" + "io" + "mime/multipart" + "net/textproto" + "path" + "reflect" + "sort" + "strconv" + "strings" +) + +// Marshal encodes a value as multipart form data using default settings +func Marshal(value any, writer *multipart.Writer) error { + e := &encoder{ + format: FormatRepeat, + } + return e.marshal(value, writer) +} + +// MarshalWithSettings encodes a value with custom array format +func MarshalWithSettings(value any, writer *multipart.Writer, arrayFormat FormFormat) error { + e := &encoder{ + format: arrayFormat, + } + return e.marshal(value, writer) +} + +type encoder struct { + format FormFormat +} + +func (e *encoder) marshal(value any, writer *multipart.Writer) error { + val := reflect.ValueOf(value) + if !val.IsValid() { + return nil + } + return e.encodeValue("", val, writer) +} + +func (e *encoder) encodeValue(key string, val reflect.Value, writer *multipart.Writer) error { + if !val.IsValid() { + return writer.WriteField(key, "") + } + + t := val.Type() + + if t.Implements(reflect.TypeOf((*io.Reader)(nil)).Elem()) { + return e.encodeReader(key, val, writer) + } + + switch t.Kind() { + case reflect.Pointer: + if val.IsNil() || !val.IsValid() { + return writer.WriteField(key, "") + } + return e.encodeValue(key, val.Elem(), writer) + + case reflect.Slice, reflect.Array: + return e.encodeArray(key, val, writer) + + case reflect.Map: + return e.encodeMap(key, val, writer) + + case reflect.Interface: + if val.IsNil() { + return writer.WriteField(key, "") + } + return e.encodeValue(key, val.Elem(), writer) + + case reflect.String: + return writer.WriteField(key, val.String()) + + case reflect.Bool: + if val.Bool() { + return writer.WriteField(key, "true") + } + return writer.WriteField(key, "false") + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return writer.WriteField(key, strconv.FormatInt(val.Int(), 10)) + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return writer.WriteField(key, strconv.FormatUint(val.Uint(), 10)) + + case reflect.Float32: + return writer.WriteField(key, strconv.FormatFloat(val.Float(), 'f', -1, 32)) + + case reflect.Float64: + return writer.WriteField(key, strconv.FormatFloat(val.Float(), 'f', -1, 64)) + + default: + return fmt.Errorf("unknown type: %s", t.String()) + } +} + +func (e *encoder) encodeArray(key string, val reflect.Value, writer *multipart.Writer) error { + if e.format == FormatComma { + var values []string + for i := 0; i < val.Len(); i++ { + item := val.Index(i) + if (item.Kind() == reflect.Pointer || item.Kind() == reflect.Interface) && item.IsNil() { + // Null values are sent as an empty string + values = append(values, "") + continue + } + // If item is an interface, reduce it to the concrete type + if item.Kind() == reflect.Interface { + item = item.Elem() + } + var strValue string + switch item.Kind() { + case reflect.String: + strValue = item.String() + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + strValue = strconv.FormatInt(item.Int(), 10) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + strValue = strconv.FormatUint(item.Uint(), 10) + case reflect.Float32, reflect.Float64: + strValue = strconv.FormatFloat(item.Float(), 'f', -1, 64) + case reflect.Bool: + strValue = strconv.FormatBool(item.Bool()) + default: + return fmt.Errorf("comma format not supported for complex array elements") + } + values = append(values, strValue) + } + return writer.WriteField(key, strings.Join(values, ",")) + } + + for i := 0; i < val.Len(); i++ { + var formattedKey string + switch e.format { + case FormatRepeat: + formattedKey = key + case FormatBrackets: + formattedKey = key + "[]" + case FormatIndicesDots: + if key == "" { + formattedKey = strconv.Itoa(i) + } else { + formattedKey = key + "." + strconv.Itoa(i) + } + case FormatIndicesBrackets: + if key == "" { + formattedKey = strconv.Itoa(i) + } else { + formattedKey = key + "[" + strconv.Itoa(i) + "]" + } + default: + return fmt.Errorf("apiform: unsupported array format") + } + + if err := e.encodeValue(formattedKey, val.Index(i), writer); err != nil { + return err + } + } + return nil +} + +var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"") + +func escapeQuotes(s string) string { + return quoteEscaper.Replace(s) +} + +func (e *encoder) encodeReader(key string, val reflect.Value, writer *multipart.Writer) error { + reader, ok := val.Convert(reflect.TypeOf((*io.Reader)(nil)).Elem()).Interface().(io.Reader) + if !ok { + return nil + } + + // Set defaults + filename := "anonymous_file" + contentType := "application/octet-stream" + + // Get filename if available + if named, ok := reader.(interface{ Filename() string }); ok { + filename = named.Filename() + } else if named, ok := reader.(interface{ Name() string }); ok { + filename = path.Base(named.Name()) + } + + // Get content type if available + if typed, ok := reader.(interface{ ContentType() string }); ok { + contentType = typed.ContentType() + } + + h := make(textproto.MIMEHeader) + h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, + escapeQuotes(key), escapeQuotes(filename))) + h.Set("Content-Type", contentType) + + filewriter, err := writer.CreatePart(h) + if err != nil { + return err + } + _, err = io.Copy(filewriter, reader) + return err +} + +func (e *encoder) encodeMap(key string, val reflect.Value, writer *multipart.Writer) error { + type mapPair struct { + key string + value reflect.Value + } + + if key != "" { + key = key + "." + } + + // Collect and sort map entries for deterministic output + pairs := []mapPair{} + iter := val.MapRange() + for iter.Next() { + if iter.Key().Type().Kind() != reflect.String { + return fmt.Errorf("cannot encode a map with a non string key") + } + pairs = append(pairs, mapPair{key: iter.Key().String(), value: iter.Value()}) + } + + sort.Slice(pairs, func(i, j int) bool { + return pairs[i].key < pairs[j].key + }) + + // Process sorted pairs + for _, p := range pairs { + if err := e.encodeValue(key+p.key, p.value, writer); err != nil { + return err + } + } + + return nil +} diff --git a/internal/apiform/form.go b/internal/apiform/form.go new file mode 100644 index 0000000..024de27 --- /dev/null +++ b/internal/apiform/form.go @@ -0,0 +1,20 @@ +package apiform + +type Marshaler interface { + MarshalMultipart() ([]byte, string, error) +} + +type FormFormat int + +const ( + // FormatRepeat represents arrays as repeated keys with the same value + FormatRepeat FormFormat = iota + // Comma-separated values 1,2,3 + FormatComma + // FormatBrackets uses the key[] notation for arrays + FormatBrackets + // FormatIndicesDots uses key.0, key.1, etc. notation + FormatIndicesDots + // FormatIndicesBrackets uses key[0], key[1], etc. notation + FormatIndicesBrackets +) diff --git a/internal/apiform/form_test.go b/internal/apiform/form_test.go new file mode 100644 index 0000000..f68cfd1 --- /dev/null +++ b/internal/apiform/form_test.go @@ -0,0 +1,113 @@ +package apiform + +import ( + "bytes" + "mime/multipart" + "testing" +) + +// Define test cases +var tests = map[string]struct { + value any + format FormFormat + expected string +}{ + "nil": { + value: nil, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\n\r\n--xxx--\r\n", + }, + "string": { + value: "hello", + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nhello\r\n--xxx--\r\n", + }, + "int": { + value: 42, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\n42\r\n--xxx--\r\n", + }, + "float": { + value: 3.14, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\n3.14\r\n--xxx--\r\n", + }, + "bool": { + value: true, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\ntrue\r\n--xxx--\r\n", + }, + "empty slice": { + value: []string{}, + expected: "\r\n--xxx--\r\n", + }, + "nil slice": { + value: []string(nil), + expected: "\r\n--xxx--\r\n", + }, + "slice with dot indices": { + value: []string{"a", "b", "c"}, + format: FormatIndicesDots, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo.0\"\r\n\r\na\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo.1\"\r\n\r\nb\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo.2\"\r\n\r\nc\r\n--xxx--\r\n", + }, + "slice with bracket indices": { + value: []int{10, 20, 30}, + format: FormatIndicesBrackets, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo[0]\"\r\n\r\n10\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo[1]\"\r\n\r\n20\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo[2]\"\r\n\r\n30\r\n--xxx--\r\n", + }, + "slice with repeat": { + value: []int{10, 20, 30}, + format: FormatRepeat, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\n10\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\n20\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\n30\r\n--xxx--\r\n", + }, + "slice with commas": { + value: []int{10, 20, 30}, + format: FormatComma, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\n10,20,30\r\n--xxx--\r\n", + }, + "empty map": { + value: map[string]any{}, + expected: "\r\n--xxx--\r\n", + }, + "nil map": { + value: map[string]any(nil), + expected: "\r\n--xxx--\r\n", + }, + "map": { + value: map[string]any{"key1": "value1", "key2": "value2"}, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo.key1\"\r\n\r\nvalue1\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo.key2\"\r\n\r\nvalue2\r\n--xxx--\r\n", + }, + "nested_map": { + value: map[string]any{"outer": map[string]int{"inner1": 10, "inner2": 20}}, + format: FormatIndicesDots, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo.outer.inner1\"\r\n\r\n10\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo.outer.inner2\"\r\n\r\n20\r\n--xxx--\r\n", + }, + "mixed_map": { + value: map[string]any{"name": "John", "ages": []int{25, 30, 35}}, + format: FormatIndicesDots, + expected: "--xxx\r\nContent-Disposition: form-data; name=\"foo.ages.0\"\r\n\r\n25\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo.ages.1\"\r\n\r\n30\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo.ages.2\"\r\n\r\n35\r\n--xxx\r\nContent-Disposition: form-data; name=\"foo.name\"\r\n\r\nJohn\r\n--xxx--\r\n", + }, +} + +func TestEncode(t *testing.T) { + t.Parallel() + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + t.Parallel() + + buf := bytes.NewBuffer(nil) + writer := multipart.NewWriter(buf) + writer.SetBoundary("xxx") + + form := map[string]any{"foo": test.value} + err := MarshalWithSettings(form, writer, test.format) + if err != nil { + t.Errorf("serialization of %v failed with error %v", test.value, err) + } + err = writer.Close() + if err != nil { + t.Errorf("serialization of %v failed with error %v", test.value, err) + } + result := buf.String() + if result != test.expected { + t.Errorf("expected %+#v to serialize to:\n\t%q\nbut got:\n\t%q", test.value, test.expected, result) + } + }) + } +} diff --git a/internal/apiquery/encoder.go b/internal/apiquery/encoder.go new file mode 100644 index 0000000..0d09dee --- /dev/null +++ b/internal/apiquery/encoder.go @@ -0,0 +1,166 @@ +package apiquery + +import ( + "fmt" + "reflect" + "strconv" + "strings" +) + +type encoder struct { + settings QuerySettings +} + +type Pair struct { + key string + value string +} + +func (e *encoder) Encode(key string, value reflect.Value) ([]Pair, error) { + t := value.Type() + switch t.Kind() { + case reflect.Pointer: + if value.IsNil() || !value.IsValid() { + return []Pair{{key, ""}}, nil + } + return e.Encode(key, value.Elem()) + + case reflect.Array, reflect.Slice: + return e.encodeArray(key, value) + + case reflect.Map: + return e.encodeMap(key, value) + + case reflect.Interface: + if !value.Elem().IsValid() { + return []Pair{{key, ""}}, nil + } + return e.Encode(key, value.Elem()) + + default: + return e.encodePrimitive(key, value) + } +} + +func (e *encoder) encodeMap(key string, value reflect.Value) ([]Pair, error) { + var pairs []Pair + iter := value.MapRange() + for iter.Next() { + subkey := iter.Key().String() + keyPath := subkey + if len(key) > 0 { + if e.settings.NestedFormat == NestedQueryFormatDots { + keyPath = fmt.Sprintf("%s.%s", key, subkey) + } else { + keyPath = fmt.Sprintf("%s[%s]", key, subkey) + } + } + + subpairs, err := e.Encode(keyPath, iter.Value()) + if err != nil { + return nil, err + } + pairs = append(pairs, subpairs...) + } + return pairs, nil +} + +func (e *encoder) encodeArray(key string, value reflect.Value) ([]Pair, error) { + switch e.settings.ArrayFormat { + case ArrayQueryFormatComma: + elements := []string{} + for i := 0; i < value.Len(); i++ { + innerPairs, err := e.Encode("", value.Index(i)) + if err != nil { + return nil, err + } + for _, pair := range innerPairs { + elements = append(elements, pair.value) + } + } + return []Pair{{key, strings.Join(elements, ",")}}, nil + + case ArrayQueryFormatRepeat: + var pairs []Pair + for i := 0; i < value.Len(); i++ { + subpairs, err := e.Encode(key, value.Index(i)) + if err != nil { + return nil, err + } + pairs = append(pairs, subpairs...) + } + return pairs, nil + + case ArrayQueryFormatIndices: + var pairs []Pair + for i := 0; i < value.Len(); i++ { + subpairs, err := e.Encode(fmt.Sprintf("%s[%d]", key, i), value.Index(i)) + if err != nil { + return nil, err + } + pairs = append(pairs, subpairs...) + } + return pairs, nil + + case ArrayQueryFormatBrackets: + var pairs []Pair + for i := 0; i < value.Len(); i++ { + subpairs, err := e.Encode(key+"[]", value.Index(i)) + if err != nil { + return nil, err + } + pairs = append(pairs, subpairs...) + } + return pairs, nil + + default: + panic(fmt.Sprintf("Unknown ArrayFormat value: %d", e.settings.ArrayFormat)) + } +} + +func (e *encoder) encodePrimitive(key string, value reflect.Value) ([]Pair, error) { + switch value.Kind() { + case reflect.Pointer: + if !value.IsValid() || value.IsNil() { + return nil, nil + } + return e.encodePrimitive(key, value.Elem()) + + case reflect.String: + return []Pair{{key, value.String()}}, nil + + case reflect.Bool: + if value.Bool() { + return []Pair{{key, "true"}}, nil + } + return []Pair{{key, "false"}}, nil + + case reflect.Int, reflect.Int16, reflect.Int32, reflect.Int64: + return []Pair{{key, strconv.FormatInt(value.Int(), 10)}}, nil + + case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return []Pair{{key, strconv.FormatUint(value.Uint(), 10)}}, nil + + case reflect.Float32, reflect.Float64: + return []Pair{{key, strconv.FormatFloat(value.Float(), 'f', -1, 64)}}, nil + + default: + return nil, nil + } +} + +func (e *encoder) encodeField(key string, value reflect.Value) ([]Pair, error) { + present := value.FieldByName("Present") + if !present.Bool() { + return nil, nil + } + null := value.FieldByName("Null") + if null.Bool() { + return nil, fmt.Errorf("apiquery: field cannot be null") + } + raw := value.FieldByName("Raw") + if !raw.IsNil() { + return e.Encode(key, raw) + } + return e.Encode(key, value.FieldByName("Value")) +} diff --git a/internal/apiquery/query.go b/internal/apiquery/query.go new file mode 100644 index 0000000..fd07a2f --- /dev/null +++ b/internal/apiquery/query.go @@ -0,0 +1,53 @@ +package apiquery + +import ( + "net/url" + "reflect" +) + +func MarshalWithSettings(value any, settings QuerySettings) (url.Values, error) { + val := reflect.ValueOf(value) + if !val.IsValid() { + return nil, nil + } + + e := encoder{settings} + pairs, err := e.Encode("", val) + if err != nil { + return nil, err + } + + kv := url.Values{} + for _, pair := range pairs { + kv.Add(pair.key, pair.value) + } + return kv, nil +} +func Marshal(value any) (url.Values, error) { + return MarshalWithSettings(value, QuerySettings{}) +} + +type Queryer interface { + URLQuery() (url.Values, error) +} + +type NestedQueryFormat int + +const ( + NestedQueryFormatBrackets NestedQueryFormat = iota + NestedQueryFormatDots +) + +type ArrayQueryFormat int + +const ( + ArrayQueryFormatComma ArrayQueryFormat = iota + ArrayQueryFormatRepeat + ArrayQueryFormatIndices + ArrayQueryFormatBrackets +) + +type QuerySettings struct { + NestedFormat NestedQueryFormat + ArrayFormat ArrayQueryFormat +} diff --git a/internal/apiquery/query_test.go b/internal/apiquery/query_test.go new file mode 100644 index 0000000..3791ec9 --- /dev/null +++ b/internal/apiquery/query_test.go @@ -0,0 +1,132 @@ +package apiquery + +import ( + "net/url" + "testing" +) + +func TestEncode(t *testing.T) { + t.Parallel() + + tests := map[string]struct { + val any + settings QuerySettings + enc string + }{ + "null": { + val: nil, + enc: "query=", + }, + "string": { + val: "hello world", + enc: "query=hello world", + }, + "int": { + val: 42, + enc: "query=42", + }, + "float": { + val: 3.14, + enc: "query=3.14", + }, + "bool": { + val: true, + enc: "query=true", + }, + "empty_slice": { + val: []any{}, + settings: QuerySettings{ArrayFormat: ArrayQueryFormatComma}, + enc: "query=", + }, + "nil_slice": { + val: []any(nil), + settings: QuerySettings{ArrayFormat: ArrayQueryFormatComma}, + enc: "query=", + }, + "slice_of_ints": { + val: []any{10, 20, 30}, + settings: QuerySettings{ArrayFormat: ArrayQueryFormatComma}, + enc: "query=10,20,30", + }, + "slice_of_ints_repeat": { + val: []any{10, 20, 30}, + settings: QuerySettings{ArrayFormat: ArrayQueryFormatRepeat}, + enc: "query=10&query=20&query=30", + }, + "slice_of_ints_indices": { + val: []any{10, 20, 30}, + settings: QuerySettings{ArrayFormat: ArrayQueryFormatIndices}, + enc: "query[0]=10&query[1]=20&query[2]=30", + }, + "slice_of_ints_brackets": { + val: []any{10, 20, 30}, + settings: QuerySettings{ArrayFormat: ArrayQueryFormatBrackets}, + enc: "query[]=10&query[]=20&query[]=30", + }, + "slice_of_strings": { + val: []any{"a", "b", "c"}, + settings: QuerySettings{}, + enc: "query=a,b,c", + }, + "empty_map": { + val: map[string]any{}, + settings: QuerySettings{NestedFormat: NestedQueryFormatBrackets}, + enc: "", + }, + "nil_map": { + val: map[string]any(nil), + settings: QuerySettings{NestedFormat: NestedQueryFormatBrackets}, + enc: "", + }, + "map_string_to_int_brackets": { + val: map[string]any{"one": 1, "two": 2}, + settings: QuerySettings{NestedFormat: NestedQueryFormatBrackets}, + enc: "query[one]=1&query[two]=2", + }, + "map_string_to_int_dots": { + val: map[string]any{"one": 1, "two": 2}, + settings: QuerySettings{NestedFormat: NestedQueryFormatDots}, + enc: "query.one=1&query.two=2", + }, + "map_string_to_slice": { + val: map[string][]any{"nums": {10, 20, 30}}, + settings: QuerySettings{}, + enc: "query[nums]=10,20,30", + }, + "map_string_to_slice_repeat_dots": { + val: map[string][]any{"nums": {10, 20, 30}}, + settings: QuerySettings{ArrayFormat: ArrayQueryFormatRepeat, NestedFormat: NestedQueryFormatDots}, + enc: "query.nums=10&query.nums=20&query.nums=30", + }, + "map_with_empties": { + val: map[string]any{ + "empty-array": []any{}, + "nil-array": []any(nil), + "null": nil, + }, + settings: QuerySettings{ArrayFormat: ArrayQueryFormatComma, NestedFormat: NestedQueryFormatDots}, + enc: "query.empty-array=&query.nil-array=&query.null=", + }, + "nested_map": { + val: map[string]map[string]any{"outer": {"inner": 42}}, + settings: QuerySettings{}, + enc: "query[outer][inner]=42", + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + t.Parallel() + + query := map[string]any{"query": test.val} + values, err := MarshalWithSettings(query, test.settings) + if err != nil { + t.Fatalf("failed to marshal url %s", err) + } + str, _ := url.QueryUnescape(values.Encode()) + if str != test.enc { + t.Fatalf("expected %+#v to serialize to:\n\t%q\nbut got:\n\t%q", test.val, test.enc, str) + } + }) + } +} diff --git a/internal/autocomplete/autocomplete.go b/internal/autocomplete/autocomplete.go new file mode 100644 index 0000000..97fe1a8 --- /dev/null +++ b/internal/autocomplete/autocomplete.go @@ -0,0 +1,361 @@ +package autocomplete + +import ( + "context" + "embed" + "fmt" + "os" + "slices" + "strings" + + "github.com/urfave/cli/v3" +) + +type CompletionStyle string + +const ( + CompletionStyleZsh CompletionStyle = "zsh" + CompletionStyleBash CompletionStyle = "bash" + CompletionStylePowershell CompletionStyle = "pwsh" + CompletionStyleFish CompletionStyle = "fish" +) + +type renderCompletion func(cmd *cli.Command, appName string) (string, error) + +var ( + //go:embed shellscripts + autoCompleteFS embed.FS + + shellCompletions = map[CompletionStyle]renderCompletion{ + "bash": func(c *cli.Command, appName string) (string, error) { + b, err := autoCompleteFS.ReadFile("shellscripts/bash_autocomplete.bash") + return strings.ReplaceAll(string(b), "__APPNAME__", appName), err + }, + "fish": func(c *cli.Command, appName string) (string, error) { + b, err := autoCompleteFS.ReadFile("shellscripts/fish_autocomplete.fish") + return strings.ReplaceAll(string(b), "__APPNAME__", appName), err + }, + "pwsh": func(c *cli.Command, appName string) (string, error) { + b, err := autoCompleteFS.ReadFile("shellscripts/pwsh_autocomplete.ps1") + return strings.ReplaceAll(string(b), "__APPNAME__", appName), err + }, + "zsh": func(c *cli.Command, appName string) (string, error) { + b, err := autoCompleteFS.ReadFile("shellscripts/zsh_autocomplete.zsh") + return strings.ReplaceAll(string(b), "__APPNAME__", appName), err + }, + } +) + +func OutputCompletionScript(ctx context.Context, cmd *cli.Command) error { + shells := make([]CompletionStyle, 0, len(shellCompletions)) + for k := range shellCompletions { + shells = append(shells, k) + } + + if cmd.Args().Len() == 0 { + return cli.Exit(fmt.Sprintf("no shell provided for completion command. available shells are %+v", shells), 1) + } + s := CompletionStyle(cmd.Args().First()) + + renderCompletion, ok := shellCompletions[s] + if !ok { + return cli.Exit(fmt.Sprintf("unknown shell %s, available shells are %+v", s, shells), 1) + } + + completionScript, err := renderCompletion(cmd, cmd.Root().Name) + if err != nil { + return cli.Exit(err, 1) + } + + _, err = cmd.Writer.Write([]byte(completionScript)) + if err != nil { + return cli.Exit(err, 1) + } + + return nil +} + +type ShellCompletion struct { + Name string + Usage string +} + +func NewShellCompletion(name string, usage string) ShellCompletion { + return ShellCompletion{Name: name, Usage: usage} +} + +type ShellCompletionBehavior int + +const ( + ShellCompletionBehaviorDefault ShellCompletionBehavior = iota + ShellCompletionBehaviorFile = 10 + ShellCompletionBehaviorNoComplete +) + +type CompletionResult struct { + Completions []ShellCompletion + Behavior ShellCompletionBehavior +} + +func isFlag(arg string) bool { + return strings.HasPrefix(arg, "-") +} + +func findFlag(cmd *cli.Command, arg string) *cli.Flag { + name := strings.TrimLeft(arg, "-") + for _, flag := range cmd.Flags { + if vf, ok := flag.(cli.VisibleFlag); ok && !vf.IsVisible() { + continue + } + + if slices.Contains(flag.Names(), name) { + return &flag + } + } + return nil +} + +func findChild(cmd *cli.Command, name string) *cli.Command { + for _, c := range cmd.Commands { + if !c.Hidden && c.Name == name { + return c + } + } + return nil +} + +type shellCompletionBuilder struct { + completionStyle CompletionStyle +} + +func (scb *shellCompletionBuilder) createFromCommand(input string, command *cli.Command, result []ShellCompletion) []ShellCompletion { + matchingNames := make([]string, 0, len(command.Names())) + + for _, name := range command.Names() { + if strings.HasPrefix(name, input) { + matchingNames = append(matchingNames, name) + } + } + + if scb.completionStyle == CompletionStyleBash { + index := strings.LastIndex(input, ":") + 1 + if index > 0 { + for _, name := range matchingNames { + result = append(result, NewShellCompletion(name[index:], command.Usage)) + } + return result + } + } + + for _, name := range matchingNames { + result = append(result, NewShellCompletion(name, command.Usage)) + } + return result +} + +func (scb *shellCompletionBuilder) createFromFlag(input string, flag *cli.Flag, result []ShellCompletion) []ShellCompletion { + matchingNames := make([]string, 0, len((*flag).Names())) + + for _, name := range (*flag).Names() { + withPrefix := "" + if len(name) == 1 { + withPrefix = "-" + name + } else { + withPrefix = "--" + name + } + + if strings.HasPrefix(withPrefix, input) { + matchingNames = append(matchingNames, withPrefix) + } + } + + usage := "" + if dgf, ok := (*flag).(cli.DocGenerationFlag); ok { + usage = dgf.GetUsage() + } + + for _, name := range matchingNames { + result = append(result, NewShellCompletion(name, usage)) + } + + return result +} + +func GetCompletions(completionStyle CompletionStyle, root *cli.Command, args []string) CompletionResult { + result := getAllPossibleCompletions(completionStyle, root, args) + + // If the user has not put in a colon, filter out colon commands + if len(args) > 0 && !strings.Contains(args[len(args)-1], ":") { + // Nothing with anything after a colon. Create a single entry for groups with the same colon subset + foundNames := make([]string, 0, len(result.Completions)) + filteredCompletions := make([]ShellCompletion, 0, len(result.Completions)) + + for _, completion := range result.Completions { + name := completion.Name + firstColonIndex := strings.Index(name, ":") + if firstColonIndex > -1 { + name = name[0:firstColonIndex] + completion.Name = name + completion.Usage = "" + } + + if !slices.Contains(foundNames, name) { + foundNames = append(foundNames, name) + filteredCompletions = append(filteredCompletions, completion) + } + } + + result.Completions = filteredCompletions + } + + return result +} + +func getAllPossibleCompletions(completionStyle CompletionStyle, root *cli.Command, args []string) CompletionResult { + builder := shellCompletionBuilder{completionStyle: completionStyle} + completions := make([]ShellCompletion, 0) + if len(args) == 0 { + for _, child := range root.Commands { + completions = builder.createFromCommand("", child, completions) + } + return CompletionResult{Completions: completions, Behavior: ShellCompletionBehaviorDefault} + } + + current := args[len(args)-1] + preceding := args[0 : len(args)-1] + cmd := root + i := 0 + for i < len(preceding) { + arg := preceding[i] + + if isFlag(arg) { + flag := findFlag(cmd, arg) + if flag == nil { + i++ + } else if docFlag, ok := (*flag).(cli.DocGenerationFlag); ok && docFlag.TakesValue() { + // All flags except for bool flags take values + i += 2 + } else { + i++ + } + } else { + child := findChild(cmd, arg) + if child != nil { + cmd = child + } + i++ + } + } + + // Check if the previous arg was a flag expecting a value + if len(preceding) > 0 { + prev := preceding[len(preceding)-1] + if isFlag(prev) { + flag := findFlag(cmd, prev) + if flag != nil { + if fb, ok := (*flag).(*cli.StringFlag); ok && fb.TakesFile { + return CompletionResult{Completions: completions, Behavior: ShellCompletionBehaviorFile} + } else if docFlag, ok := (*flag).(cli.DocGenerationFlag); ok && docFlag.TakesValue() { + return CompletionResult{Completions: completions, Behavior: ShellCompletionBehaviorNoComplete} + } + } + } + } + + // Completing a flag name + if isFlag(current) { + for _, flag := range cmd.Flags { + completions = builder.createFromFlag(current, &flag, completions) + } + } + + for _, child := range cmd.Commands { + if !child.Hidden { + completions = builder.createFromCommand(current, child, completions) + } + } + + return CompletionResult{ + Completions: completions, + Behavior: ShellCompletionBehaviorDefault, + } +} + +func ExecuteShellCompletion(ctx context.Context, cmd *cli.Command) error { + root := cmd.Root() + args := rebuildColonSeparatedArgs(root.Args().Slice()[1:]) + + var completionStyle CompletionStyle + if style, ok := os.LookupEnv("COMPLETION_STYLE"); ok { + switch style { + case "bash": + completionStyle = CompletionStyleBash + case "zsh": + completionStyle = CompletionStyleZsh + case "pwsh": + completionStyle = CompletionStylePowershell + case "fish": + completionStyle = CompletionStyleFish + default: + return cli.Exit("COMPLETION_STYLE must be set to 'bash', 'zsh', 'pwsh', or 'fish'", 1) + } + } else { + return cli.Exit("COMPLETION_STYLE must be set to 'bash', 'zsh', 'pwsh', 'fish'", 1) + } + + result := GetCompletions(completionStyle, root, args) + + for _, completion := range result.Completions { + name := completion.Name + if completionStyle == CompletionStyleZsh { + name = strings.ReplaceAll(name, ":", "\\:") + } + if completionStyle == CompletionStyleZsh && len(completion.Usage) > 0 { + _, _ = fmt.Fprintf(cmd.Writer, "%s:%s\n", name, completion.Usage) + } else if completionStyle == CompletionStyleFish && len(completion.Usage) > 0 { + _, _ = fmt.Fprintf(cmd.Writer, "%s\t%s\n", name, completion.Usage) + } else { + _, _ = fmt.Fprintf(cmd.Writer, "%s\n", name) + } + } + return cli.Exit("", int(result.Behavior)) +} + +// When CLI arguments are passed in, they are separated on word barriers. +// Most commonly this is whitespace but in some cases that may also be colons. +// We wish to allow arguments with colons. To handle this, we append/prepend colons to their neighboring +// arguments. +// +// Example: `rebuildColonSeparatedArgs(["a", "b", ":", "c", "d"])` => `["a", "b:c", "d"]` +func rebuildColonSeparatedArgs(args []string) []string { + if len(args) == 0 { + return args + } + + result := []string{} + i := 0 + + for i < len(args) { + current := args[i] + + // Keep joining while the next element is ":" or the current element ends with ":" + for i+1 < len(args) && (args[i+1] == ":" || strings.HasSuffix(current, ":")) { + if args[i+1] == ":" { + current += ":" + i++ + // Check if there's a following element after the ":" + if i+1 < len(args) && args[i+1] != ":" { + current += args[i+1] + i++ + } + } else { + break + } + } + + result = append(result, current) + i++ + } + + return result +} diff --git a/internal/autocomplete/autocomplete_test.go b/internal/autocomplete/autocomplete_test.go new file mode 100644 index 0000000..2338924 --- /dev/null +++ b/internal/autocomplete/autocomplete_test.go @@ -0,0 +1,433 @@ +package autocomplete + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/urfave/cli/v3" +) + +func TestGetCompletions_EmptyArgs(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "generate", Usage: "Generate SDK"}, + {Name: "test", Usage: "Run tests"}, + {Name: "build", Usage: "Build project"}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{}) + + assert.Equal(t, ShellCompletionBehaviorDefault, result.Behavior) + assert.Len(t, result.Completions, 3) + assert.Contains(t, result.Completions, ShellCompletion{Name: "generate", Usage: "Generate SDK"}) + assert.Contains(t, result.Completions, ShellCompletion{Name: "test", Usage: "Run tests"}) + assert.Contains(t, result.Completions, ShellCompletion{Name: "build", Usage: "Build project"}) +} + +func TestGetCompletions_SubcommandPrefix(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "generate", Usage: "Generate SDK"}, + {Name: "test", Usage: "Run tests"}, + {Name: "build", Usage: "Build project"}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"ge"}) + + assert.Equal(t, ShellCompletionBehaviorDefault, result.Behavior) + assert.Len(t, result.Completions, 1) + assert.Equal(t, "generate", result.Completions[0].Name) + assert.Equal(t, "Generate SDK", result.Completions[0].Usage) +} + +func TestGetCompletions_HiddenCommand(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "visible", Usage: "Visible command"}, + {Name: "hidden", Usage: "Hidden command", Hidden: true}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{""}) + + assert.Len(t, result.Completions, 1) + assert.Equal(t, "visible", result.Completions[0].Name) +} + +func TestGetCompletions_NestedSubcommand(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "config", + Usage: "Configuration commands", + Commands: []*cli.Command{ + {Name: "get", Usage: "Get config value"}, + {Name: "set", Usage: "Set config value"}, + }, + }, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"config", "s"}) + + assert.Equal(t, ShellCompletionBehaviorDefault, result.Behavior) + assert.Len(t, result.Completions, 1) + assert.Equal(t, "set", result.Completions[0].Name) + assert.Equal(t, "Set config value", result.Completions[0].Usage) +} + +func TestGetCompletions_FlagCompletion(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "generate", + Usage: "Generate SDK", + Flags: []cli.Flag{ + &cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "Output directory"}, + &cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}, Usage: "Verbose output"}, + &cli.StringFlag{Name: "format", Usage: "Output format"}, + }, + }, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"generate", "--o"}) + + assert.Equal(t, ShellCompletionBehaviorDefault, result.Behavior) + assert.Len(t, result.Completions, 1) + assert.Equal(t, "--output", result.Completions[0].Name) + assert.Equal(t, "Output directory", result.Completions[0].Usage) +} + +func TestGetCompletions_ShortFlagCompletion(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "generate", + Usage: "Generate SDK", + Flags: []cli.Flag{ + &cli.StringFlag{Name: "output", Aliases: []string{"o"}, Usage: "Output directory"}, + &cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}, Usage: "Verbose output"}, + }, + }, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"generate", "-v"}) + + assert.Equal(t, ShellCompletionBehaviorDefault, result.Behavior) + assert.Len(t, result.Completions, 1) + assert.Equal(t, "-v", result.Completions[0].Name) +} + +func TestGetCompletions_FileFlagBehavior(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "generate", + Usage: "Generate SDK", + Flags: []cli.Flag{ + &cli.StringFlag{Name: "config", Aliases: []string{"c"}, Usage: "Config file", TakesFile: true}, + }, + }, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"generate", "--config", ""}) + + assert.EqualValues(t, ShellCompletionBehaviorFile, result.Behavior) + assert.Empty(t, result.Completions) +} + +func TestGetCompletions_NonBoolFlagValue(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "generate", + Usage: "Generate SDK", + Flags: []cli.Flag{ + &cli.StringFlag{Name: "format", Usage: "Output format"}, + }, + }, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"generate", "--format", ""}) + + assert.EqualValues(t, ShellCompletionBehaviorNoComplete, result.Behavior) + assert.Empty(t, result.Completions) +} + +func TestGetCompletions_BoolFlagDoesNotBlockCompletion(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "generate", + Usage: "Generate SDK", + Flags: []cli.Flag{ + &cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}, Usage: "Verbose output"}, + }, + Commands: []*cli.Command{ + {Name: "typescript", Usage: "Generate TypeScript SDK"}, + {Name: "python", Usage: "Generate Python SDK"}, + }, + }, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"generate", "--verbose", "ty"}) + + assert.Equal(t, ShellCompletionBehaviorDefault, result.Behavior) + assert.Len(t, result.Completions, 1) + assert.Equal(t, "typescript", result.Completions[0].Name) +} + +func TestGetCompletions_ColonCommands_NoColonTyped(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "config:get", Usage: "Get config value"}, + {Name: "config:set", Usage: "Set config value"}, + {Name: "config:list", Usage: "List config values"}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"co"}) + + // Should collapse to single "config" entry without usage + assert.Len(t, result.Completions, 1) + assert.Equal(t, "config", result.Completions[0].Name) + assert.Equal(t, "", result.Completions[0].Usage) +} + +func TestGetCompletions_ColonCommands_ColonTyped_Bash(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "config:get", Usage: "Get config value"}, + {Name: "config:set", Usage: "Set config value"}, + {Name: "config:list", Usage: "List config values"}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"config:"}) + + // For bash, should show suffixes only + assert.Len(t, result.Completions, 3) + names := []string{result.Completions[0].Name, result.Completions[1].Name, result.Completions[2].Name} + assert.Contains(t, names, "get") + assert.Contains(t, names, "set") + assert.Contains(t, names, "list") +} + +func TestGetCompletions_ColonCommands_ColonTyped_Zsh(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "config:get", Usage: "Get config value"}, + {Name: "config:set", Usage: "Set config value"}, + {Name: "config:list", Usage: "List config values"}, + }, + } + + result := GetCompletions(CompletionStyleZsh, root, []string{"config:"}) + + // For zsh, should show full names + assert.Len(t, result.Completions, 3) + names := []string{result.Completions[0].Name, result.Completions[1].Name, result.Completions[2].Name} + assert.Contains(t, names, "config:get") + assert.Contains(t, names, "config:set") + assert.Contains(t, names, "config:list") +} + +func TestGetCompletions_BashStyleColonCompletion(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "config:get", Usage: "Get config value"}, + {Name: "config:set", Usage: "Set config value"}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"config:g"}) + + // For bash, should return suffix from after the colon in the input + // Input "config:g" has colon at index 6, so we take name[7:] from matched commands + assert.Len(t, result.Completions, 1) + assert.Equal(t, "get", result.Completions[0].Name) + assert.Equal(t, "Get config value", result.Completions[0].Usage) +} + +func TestGetCompletions_BashStyleColonCompletion_NoMatch(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "config:get", Usage: "Get config value"}, + {Name: "config:set", Usage: "Set config value"}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"other:g"}) + + // No matches + assert.Len(t, result.Completions, 0) +} + +func TestGetCompletions_ZshStyleColonCompletion(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "config:get", Usage: "Get config value"}, + {Name: "config:set", Usage: "Set config value"}, + }, + } + + result := GetCompletions(CompletionStyleZsh, root, []string{"config:g"}) + + // For zsh, should return full name + assert.Len(t, result.Completions, 1) + assert.Equal(t, "config:get", result.Completions[0].Name) + assert.Equal(t, "Get config value", result.Completions[0].Usage) +} + +func TestGetCompletions_MixedColonAndRegularCommands(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "generate", Usage: "Generate SDK"}, + {Name: "config:get", Usage: "Get config value"}, + {Name: "config:set", Usage: "Set config value"}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{""}) + + // Should show "generate" and "config" (collapsed) + assert.Len(t, result.Completions, 2) + names := []string{result.Completions[0].Name, result.Completions[1].Name} + assert.Contains(t, names, "generate") + assert.Contains(t, names, "config") +} + +func TestGetCompletions_FlagWithBoolFlagSkipsValue(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "generate", + Usage: "Generate SDK", + Flags: []cli.Flag{ + &cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}}, + &cli.StringFlag{Name: "output", Aliases: []string{"o"}}, + }, + Commands: []*cli.Command{ + {Name: "typescript", Usage: "TypeScript SDK"}, + }, + }, + }, + } + + // Bool flag should not consume the next arg as a value + result := GetCompletions(CompletionStyleBash, root, []string{"generate", "-v", "ty"}) + + assert.Len(t, result.Completions, 1) + assert.Equal(t, "typescript", result.Completions[0].Name) +} + +func TestGetCompletions_MultipleFlagsBeforeSubcommand(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "generate", + Usage: "Generate SDK", + Flags: []cli.Flag{ + &cli.StringFlag{Name: "config", Aliases: []string{"c"}}, + &cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}}, + }, + Commands: []*cli.Command{ + {Name: "typescript", Usage: "TypeScript SDK"}, + {Name: "python", Usage: "Python SDK"}, + }, + }, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"generate", "-c", "config.yml", "-v", "py"}) + + assert.Len(t, result.Completions, 1) + assert.Equal(t, "python", result.Completions[0].Name) +} + +func TestGetCompletions_CommandAliases(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + {Name: "generate", Aliases: []string{"gen", "g"}, Usage: "Generate SDK"}, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"g"}) + + // Should match all aliases that start with "g" + assert.GreaterOrEqual(t, len(result.Completions), 2) // "generate" and "gen", possibly "g" too + names := []string{} + for _, c := range result.Completions { + names = append(names, c.Name) + } + assert.Contains(t, names, "generate") + assert.Contains(t, names, "gen") +} + +func TestGetCompletions_AllFlagsWhenNoPrefix(t *testing.T) { + t.Parallel() + + root := &cli.Command{ + Commands: []*cli.Command{ + { + Name: "generate", + Usage: "Generate SDK", + Flags: []cli.Flag{ + &cli.StringFlag{Name: "output", Aliases: []string{"o"}}, + &cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}}, + &cli.StringFlag{Name: "format", Aliases: []string{"f"}}, + }, + }, + }, + } + + result := GetCompletions(CompletionStyleBash, root, []string{"generate", "-"}) + + // Should show all flag variations + assert.GreaterOrEqual(t, len(result.Completions), 6) // -o, --output, -v, --verbose, -f, --format +} diff --git a/internal/autocomplete/shellscripts/bash_autocomplete.bash b/internal/autocomplete/shellscripts/bash_autocomplete.bash new file mode 100755 index 0000000..8fb7b0b --- /dev/null +++ b/internal/autocomplete/shellscripts/bash_autocomplete.bash @@ -0,0 +1,59 @@ +#!/bin/bash + +____APPNAME___bash_autocomplete() { + if [[ "${COMP_WORDS[0]}" != "source" ]]; then + local cur completions exit_code + local IFS=$'\n' + cur="${COMP_WORDS[COMP_CWORD]}" + + completions=$(COMPLETION_STYLE=bash "${COMP_WORDS[0]}" __complete -- "${COMP_WORDS[@]:1:$COMP_CWORD-1}" "$cur" 2>/dev/null) + exit_code=$? + + local last_token="$cur" + + # If the last token has been split apart by a ':', join it back together. + # Ex: 'a:b' will be represented in COMP_WORDS as 'a', ':', 'b' + if [[ $COMP_CWORD -ge 2 ]]; then + local prev2="${COMP_WORDS[COMP_CWORD - 2]}" + local prev1="${COMP_WORDS[COMP_CWORD - 1]}" + if [[ "$prev2" =~ ^@(file|data)$ && "$prev1" == ":" && "$cur" =~ ^// ]]; then + last_token="$prev2:$cur" + fi + fi + + # Check for custom file completion patterns + local prefix="" + local file_part="$cur" + local force_file_completion=false + if [[ "$last_token" =~ (.*)@(file://|data://)?(.*)$ ]]; then + local before_at="${BASH_REMATCH[1]}" + local protocol="${BASH_REMATCH[2]}" + file_part="${BASH_REMATCH[3]}" + + if [[ "$protocol" == "" ]]; then + prefix="$before_at@" + else + if [[ "$before_at" == "" ]]; then + prefix="//" + else + prefix="$before_at@$protocol" + fi + fi + + force_file_completion=true + fi + + if [[ "$force_file_completion" == true ]]; then + mapfile -t COMPREPLY < <(compgen -f -- "$file_part" | sed "s|^|$prefix|") + else + case $exit_code in + 10) mapfile -t COMPREPLY < <(compgen -f -- "$cur") ;; # file completion + 11) COMPREPLY=() ;; # no completion + 0) mapfile -t COMPREPLY <<<"$completions" ;; # use returned completions + esac + fi + return 0 + fi +} + +complete -F ____APPNAME___bash_autocomplete __APPNAME__ diff --git a/internal/autocomplete/shellscripts/fish_autocomplete.fish b/internal/autocomplete/shellscripts/fish_autocomplete.fish new file mode 100644 index 0000000..b853057 --- /dev/null +++ b/internal/autocomplete/shellscripts/fish_autocomplete.fish @@ -0,0 +1,51 @@ +#!/usr/bin/env fish + +function ____APPNAME___fish_autocomplete + set -l tokens (commandline -xpc) + set -l current (commandline -ct) + + set -l cmd $tokens[1] + set -l args $tokens[2..-1] + + set -l completions (env COMPLETION_STYLE=fish $cmd __complete -- $args $current 2>>/tmp/fish-debug.log) + set -l exit_code $status + + # Check for custom file completion patterns + # Patterns can appear anywhere in the word (e.g., inside quotes: 'my file is @file://path') + set -l prefix "" + set -l file_part "$current" + set -l force_file_completion 0 + + if string match -gqr '^(?.*)@(?file://|data://)?(?.*)$' -- $current + if string match -qr '^[\'"]' -- $before + # Ensures we don't insert an extra quote when the user is building an argument in quotes + set before (string sub -s 2 -- $before) + end + + set prefix "$before@$protocol" + set force_file_completion 1 + end + + if test $force_file_completion -eq 1 + for path in (__fish_complete_path "$file_part") + echo $prefix$path + end + else + switch $exit_code + case 10 + # File completion + __fish_complete_path "$current" + case 11 + # No completion + return 0 + case 0 + # Use returned completions + for completion in $completions + echo $completion + end + end + end +end + +complete -c __APPNAME__ -f -a '(____APPNAME___fish_autocomplete)' + diff --git a/internal/autocomplete/shellscripts/pwsh_autocomplete.ps1 b/internal/autocomplete/shellscripts/pwsh_autocomplete.ps1 new file mode 100644 index 0000000..7cd6e62 --- /dev/null +++ b/internal/autocomplete/shellscripts/pwsh_autocomplete.ps1 @@ -0,0 +1,97 @@ +Register-ArgumentCompleter -Native -CommandName __APPNAME__ -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + + $elements = $commandAst.CommandElements + $completionArgs = @() + + # Extract each of the arguments + for ($i = 0; $i -lt $elements.Count; $i++) { + $completionArgs += $elements[$i].Extent.Text + } + + # Add empty string if there's a trailing space (wordToComplete is empty but cursor is after space) + # Necessary for differentiating between getting completions for namespaced commands vs. subcommands + if ($wordToComplete.Length -eq 0 -and $elements.Count -gt 0) { + $completionArgs += "" + } + + $output = & { + $env:COMPLETION_STYLE = 'pwsh' + __APPNAME__ __complete @completionArgs 2>&1 + } + $exitCode = $LASTEXITCODE + + # Check for custom file completion patterns + # Patterns can appear anywhere in the word (e.g., inside quotes: 'my file is @file://path') + $prefix = "" + $filePart = $wordToComplete + $forceFileCompletion = $false + + # PowerShell includes quotes in $wordToComplete - strip them for pattern matching + # but preserve them in the prefix for the completion result + $wordContent = $wordToComplete + $leadingQuote = "" + if ($wordToComplete -match '^([''"])(.*)(\1)$') { + # Fully quoted: "content" or 'content' + $leadingQuote = $Matches[1] + $wordContent = $Matches[2] + } elseif ($wordToComplete -match '^([''"])(.*)$') { + # Opening quote only: "content or 'content + $leadingQuote = $Matches[1] + $wordContent = $Matches[2] + } + + if ($wordContent -match '^(.*)@(file://|data://)?(.*)$') { + $prefix = $leadingQuote + $Matches[1] + '@' + $Matches[2] + $filePart = $Matches[3] + $forceFileCompletion = $true + } + + if ($forceFileCompletion) { + # Handle empty filePart (e.g., "@" or "@file://") by listing current directory + $items = if ([string]::IsNullOrEmpty($filePart)) { + Get-ChildItem -ErrorAction SilentlyContinue + } else { + Get-ChildItem -Path "$filePart*" -ErrorAction SilentlyContinue + } + $items | ForEach-Object { + $completionText = if ($_.PSIsContainer) { $prefix + $_.Name + "/" } else { $prefix + $_.Name } + [System.Management.Automation.CompletionResult]::new( + $completionText, + $completionText, + 'ProviderItem', + $completionText + ) + } + } else { + switch ($exitCode) { + 10 { + # File completion behavior + $items = if ([string]::IsNullOrEmpty($wordToComplete)) { + Get-ChildItem -ErrorAction SilentlyContinue + } else { + Get-ChildItem -Path "$wordToComplete*" -ErrorAction SilentlyContinue + } + $items | ForEach-Object { + $completionText = if ($_.PSIsContainer) { $_.Name + "/" } else { $_.Name } + [System.Management.Automation.CompletionResult]::new( + $completionText, + $completionText, + 'ProviderItem', + $completionText + ) + } + } + 11 { + # No reasonable suggestions + [System.Management.Automation.CompletionResult]::new(' ', ' ', 'ParameterValue', ' ') + } + default { + # Default behavior - show command completions + $output | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } + } + } + } +} diff --git a/internal/autocomplete/shellscripts/zsh_autocomplete.zsh b/internal/autocomplete/shellscripts/zsh_autocomplete.zsh new file mode 100644 index 0000000..d937171 --- /dev/null +++ b/internal/autocomplete/shellscripts/zsh_autocomplete.zsh @@ -0,0 +1,56 @@ +#compdef __APPNAME__ + +____APPNAME___zsh_autocomplete() { + + local -a opts + local temp + local exit_code + + temp=$(COMPLETION_STYLE=zsh "${words[1]}" __complete "${words[@]:1}") + exit_code=$? + + # Check for custom file completion patterns + # Patterns can appear anywhere in the word (e.g., inside quotes: 'my file is @file://path') + local cur="${words[CURRENT]}" + + if [[ "$cur" = *'@'* ]]; then + # Extract everything after the last @ + local after_last_at="${cur##*@}" + + if [[ $after_last_at =~ ^(file://|data://) ]]; then + compset -P "*$MATCH" + _files + else + compset -P '*@' + _files + fi + return + fi + + case $exit_code in + 10) + # File completion behavior + _files + ;; + 11) + # No completion behavior - return nothing + return 1 + ;; + 0) + # Default behavior - show command completions + opts=("${(@f)temp}") + _describe 'values' opts + ;; + esac +} + +# When installed in fpath (e.g., via Homebrew's zsh_completion stanza), this file +# is autoloaded as the function ___APPNAME__ and its body becomes that function's +# body. Detect that case via funcstack and dispatch to the completion function. +# When sourced (e.g., `source <(__APPNAME__ @completion zsh)`), register the +# function with compdef instead. +if [[ "${funcstack[1]}" = "___APPNAME__" ]]; then + ____APPNAME___zsh_autocomplete "$@" +else + compdef ____APPNAME___zsh_autocomplete __APPNAME__ +fi diff --git a/internal/binaryparam/binary_param.go b/internal/binaryparam/binary_param.go new file mode 100644 index 0000000..40d4ecf --- /dev/null +++ b/internal/binaryparam/binary_param.go @@ -0,0 +1,30 @@ +package binaryparam + +import ( + "io" + "os" +) + +const stdinGlyph = "-" + +// FileOrStdin opens the file at the given path for reading. If the path is "-", stdin is returned instead. +// +// It's the caller's responsibility to close the returned ReadCloser (usually with `defer`). +// +// Returns a boolean indicating whether stdin is being used. If true, no other components of the calling +// program should attempt to read from stdin for anything else. +func FileOrStdin(stdin io.ReadCloser, path string) (io.ReadCloser, bool, error) { + // When the special glyph "-" is used, read from stdin. Although probably less necessary, also support + // special Unix files that refer to stdin. + switch path { + case "", stdinGlyph, "/dev/fd/0", "/dev/stdin": + return stdin, true, nil + } + + readCloser, err := os.Open(path) + if err != nil { + return nil, false, err + } + + return readCloser, false, err +} diff --git a/internal/binaryparam/binary_param_test.go b/internal/binaryparam/binary_param_test.go new file mode 100644 index 0000000..7a66682 --- /dev/null +++ b/internal/binaryparam/binary_param_test.go @@ -0,0 +1,59 @@ +package binaryparam + +import ( + "io" + "os" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestFileOrStdin(t *testing.T) { + t.Parallel() + + const expectedContents = "test file contents" + + t.Run("WithFile", func(t *testing.T) { + tempFile := t.TempDir() + "/test_file.txt" + require.NoError(t, os.WriteFile(tempFile, []byte(expectedContents), 0600)) + + readCloser, stdinInUse, err := FileOrStdin(os.Stdin, tempFile) + require.NoError(t, err) + t.Cleanup(func() { require.NoError(t, readCloser.Close()) }) + + actualContents, err := io.ReadAll(readCloser) + require.NoError(t, err) + require.Equal(t, expectedContents, string(actualContents)) + + require.False(t, stdinInUse) + }) + + stdinTests := []struct { + testName string + path string + }{ + {"TestEmptyString", ""}, + {"TestDash", "-"}, + {"TestDevStdin", "/dev/stdin"}, + {"TestDevFD0", "/dev/fd/0"}, + } + for _, test := range stdinTests { + t.Run(test.testName, func(t *testing.T) { + tempFile := t.TempDir() + "/test_file.txt" + require.NoError(t, os.WriteFile(tempFile, []byte(expectedContents), 0600)) + + stubStdin, err := os.Open(tempFile) + require.NoError(t, err) + t.Cleanup(func() { require.NoError(t, stubStdin.Close()) }) + + readCloser, stdinInUse, err := FileOrStdin(stubStdin, test.path) + require.NoError(t, err) + + actualContents, err := io.ReadAll(readCloser) + require.NoError(t, err) + require.Equal(t, expectedContents, string(actualContents)) + + require.True(t, stdinInUse) + }) + } +} diff --git a/internal/debugmiddleware/debug_middleware.go b/internal/debugmiddleware/debug_middleware.go new file mode 100644 index 0000000..647f1de --- /dev/null +++ b/internal/debugmiddleware/debug_middleware.go @@ -0,0 +1,132 @@ +package debugmiddleware + +import ( + "bytes" + "io" + "log" + "net/http" + "net/http/httputil" + "reflect" + "strings" +) + +// For the time being these type definitions are duplicated here so that we can +// test this file in a non-generated context. +type ( + Middleware = func(*http.Request, MiddlewareNext) (*http.Response, error) + MiddlewareNext = func(*http.Request) (*http.Response, error) +) + +const redactedPlaceholder = "" + +// Headers known to contain sensitive information like an API key. Note that this exclude `Authorization`, +// which is handled specially in `redactRequest` below. +var sensitiveHeaders = []string{ + "api-key", + "x-api-key", + "cookie", + "set-cookie", +} + +// RequestLogger is a middleware that logs HTTP requests and responses. +type RequestLogger struct { + logger interface{ Printf(string, ...any) } // field for testability; usually log.Default() + sensitiveHeaders []string // field for testability; usually sensitiveHeaders +} + +// NewRequestLogger returns a new RequestLogger instance with default options. +func NewRequestLogger() *RequestLogger { + return &RequestLogger{ + logger: log.Default(), + sensitiveHeaders: sensitiveHeaders, + } +} + +func (m *RequestLogger) Middleware() Middleware { + return func(req *http.Request, mn MiddlewareNext) (*http.Response, error) { + redacted, err := m.redactRequest(req) + if err != nil { + return nil, err + } + if reqBytes, err := httputil.DumpRequest(redacted, true); err == nil { + m.logger.Printf("Request Content:\n%s\n", reqBytes) + } + + resp, err := mn(req) + if err != nil { + return resp, err + } + + if respBytes, err := httputil.DumpResponse(resp, true); err == nil { + m.logger.Printf("Response Content:\n%s\n", respBytes) + } + + return resp, err + } +} + +// redactRequest redacts sensitive information from the request for logging +// purposes. If redaction is necessary, the request is cloned before mutating +// the original and that clone is returned. As a small optimization, the +// original is request is returned unchanged if no redaction is necessary. +func (m *RequestLogger) redactRequest(req *http.Request) (*http.Request, error) { + redactedHeaders := req.Header.Clone() + + // Notably, the clauses below are written so they can redact multiple + // headers of the same name if necessary. + if values := redactedHeaders.Values("Authorization"); len(values) > 0 { + redactedHeaders.Del("Authorization") + + for _, value := range values { + // In case we're using something like a bearer token (e.g. `Bearer + // `), keep the `Bearer` part for more debugging + // information. + if authKind, _, ok := strings.Cut(value, " "); ok { + redactedHeaders.Add("Authorization", authKind+" "+redactedPlaceholder) + } else { + redactedHeaders.Add("Authorization", redactedPlaceholder) + } + } + } + + for _, header := range m.sensitiveHeaders { + values := redactedHeaders.Values(header) + if len(values) == 0 { + continue + } + + redactedHeaders.Del(header) + + for range values { + redactedHeaders.Add(header, redactedPlaceholder) + } + } + + if reflect.DeepEqual(req.Header, redactedHeaders) { + return req, nil + } + + redacted := req.Clone(req.Context()) + redacted.Header = redactedHeaders + var err error + redacted.Body, req.Body, err = cloneBody(req.Body) + return redacted, err +} + +// This function returns two copies of an HTTP request body that can each be +// read independently without affecting the other. +// This logic is taken from `drainBody` in net/http/httputil. +func cloneBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err error) { + if b == nil || b == http.NoBody { + // No copying needed. Preserve the magic sentinel meaning of NoBody. + return http.NoBody, http.NoBody, nil + } + var buf bytes.Buffer + if _, err = buf.ReadFrom(b); err != nil { + return nil, b, err + } + if err = b.Close(); err != nil { + return nil, b, err + } + return io.NopCloser(&buf), io.NopCloser(bytes.NewReader(buf.Bytes())), nil +} diff --git a/internal/debugmiddleware/debug_middleware_test.go b/internal/debugmiddleware/debug_middleware_test.go new file mode 100644 index 0000000..4e46fbc --- /dev/null +++ b/internal/debugmiddleware/debug_middleware_test.go @@ -0,0 +1,201 @@ +package debugmiddleware + +import ( + "bytes" + "io" + "log" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDebugMiddleware(t *testing.T) { + t.Parallel() + + setup := func() (*RequestLogger, *bytes.Buffer) { + var ( + logBuf bytes.Buffer + middleware = NewRequestLogger() + ) + middleware.logger = log.New(&logBuf, "", 0) + return middleware, &logBuf + } + + t.Run("DoesNotRedactMostHeaders", func(t *testing.T) { + t.Parallel() + + middleware, logBuf := setup() + + const stainlessUserAgent = "Stainless" + + req := httptest.NewRequest("GET", "https://example.com", nil) + req.Header.Set("User-Agent", stainlessUserAgent) + + var nextMiddlewareRan bool + middleware.Middleware()(req, func(req *http.Request) (*http.Response, error) { + nextMiddlewareRan = true + + // The request sent down through middleware shouldn't be mutated. + require.Equal(t, stainlessUserAgent, req.Header.Get("User-Agent")) + + return &http.Response{}, nil + }) + + require.True(t, nextMiddlewareRan) + require.Contains(t, logBuf.String(), "User-Agent: "+stainlessUserAgent) + }) + + const secretToken = "secret-token" + + t.Run("RedactsAuthorizationHeader", func(t *testing.T) { + t.Parallel() + + middleware, logBuf := setup() + + req := httptest.NewRequest("GET", "https://example.com", nil) + req.Header.Set("Authorization", secretToken) + + var nextMiddlewareRan bool + middleware.Middleware()(req, func(req *http.Request) (*http.Response, error) { + nextMiddlewareRan = true + + // The request sent down through middleware shouldn't be mutated. + require.Equal(t, secretToken, req.Header.Get("Authorization")) + + return &http.Response{}, nil + }) + + require.True(t, nextMiddlewareRan) + require.Contains(t, logBuf.String(), "Authorization: "+redactedPlaceholder) + }) + + t.Run("RedactsOnlySecretInAuthorizationHeader", func(t *testing.T) { + t.Parallel() + + middleware, logBuf := setup() + + req := httptest.NewRequest("GET", "https://example.com", nil) + req.Header.Set("Authorization", "Bearer "+secretToken) + + var nextMiddlewareRan bool + middleware.Middleware()(req, func(req *http.Request) (*http.Response, error) { + nextMiddlewareRan = true + + return &http.Response{}, nil + }) + + require.True(t, nextMiddlewareRan) + require.Contains(t, logBuf.String(), "Authorization: Bearer "+redactedPlaceholder) + }) + + t.Run("RedactsMultipleAuthorizationHeaders", func(t *testing.T) { + t.Parallel() + + middleware, logBuf := setup() + + req := httptest.NewRequest("GET", "https://example.com", nil) + req.Header.Add("Authorization", secretToken+"1") + req.Header.Add("Authorization", secretToken+"2") + + var nextMiddlewareRan bool + middleware.Middleware()(req, func(req *http.Request) (*http.Response, error) { + nextMiddlewareRan = true + + // The request sent down through middleware shouldn't be mutated. + require.Equal(t, []string{secretToken + "1", secretToken + "2"}, req.Header.Values("Authorization")) + + return &http.Response{}, nil + }) + + require.True(t, nextMiddlewareRan) + + if strings.Count(logBuf.String(), "Authorization: "+redactedPlaceholder) != 2 { + t.Error("expected exactly two redacted placeholders in authorization headers") + } + }) + + const customAPIKeyHeader = "X-My-Api-Key" + + t.Run("RedactsSensitiveHeaders", func(t *testing.T) { + t.Parallel() + + middleware, logBuf := setup() + + middleware.sensitiveHeaders = []string{customAPIKeyHeader} + + req := httptest.NewRequest("GET", "https://example.com", nil) + req.Header.Set(customAPIKeyHeader, secretToken) + + var nextMiddlewareRan bool + middleware.Middleware()(req, func(req *http.Request) (*http.Response, error) { + nextMiddlewareRan = true + + // The request sent down through middleware shouldn't be mutated. + require.Equal(t, secretToken, req.Header.Get(customAPIKeyHeader)) + + return &http.Response{}, nil + }) + + require.True(t, nextMiddlewareRan) + require.Contains(t, logBuf.String(), customAPIKeyHeader+": "+redactedPlaceholder) + }) + + t.Run("RedactsMultipleSensitiveHeaders", func(t *testing.T) { + t.Parallel() + + middleware, logBuf := setup() + + middleware.sensitiveHeaders = []string{customAPIKeyHeader} + + req := httptest.NewRequest("GET", "https://example.com", nil) + req.Header.Add(customAPIKeyHeader, secretToken+"1") + req.Header.Add(customAPIKeyHeader, secretToken+"2") + + var nextMiddlewareRan bool + middleware.Middleware()(req, func(req *http.Request) (*http.Response, error) { + nextMiddlewareRan = true + + // The request sent down through middleware shouldn't be mutated. + require.Equal(t, []string{secretToken + "1", secretToken + "2"}, req.Header.Values(customAPIKeyHeader)) + + return &http.Response{}, nil + }) + + require.True(t, nextMiddlewareRan) + require.Equal(t, 2, strings.Count(logBuf.String(), customAPIKeyHeader+": "+redactedPlaceholder)) + }) + + t.Run("DoesNotConsumeRequestBodyWhenIoReader", func(t *testing.T) { + t.Parallel() + + middleware, logBuf := setup() + middleware.sensitiveHeaders = []string{customAPIKeyHeader} + + const bodyContent = "test request body content" + bodyReader := strings.NewReader(bodyContent) + + req := httptest.NewRequest("POST", "https://example.com", bodyReader) + req.Header.Set("Authorization", secretToken) + + var nextMiddlewareRan bool + middleware.Middleware()(req, func(req *http.Request) (*http.Response, error) { + nextMiddlewareRan = true + + // The request body should still be fully readable after the middleware runs + body, err := io.ReadAll(req.Body) + require.NoError(t, err) + require.Equal(t, bodyContent, string(body)) + + // The request sent down through middleware shouldn't be mutated. + require.Equal(t, secretToken, req.Header.Get("Authorization")) + + return &http.Response{}, nil + }) + + require.True(t, nextMiddlewareRan) + require.Contains(t, logBuf.String(), "Authorization: "+redactedPlaceholder) + }) +} diff --git a/internal/jsonview/explorer.go b/internal/jsonview/explorer.go new file mode 100644 index 0000000..836bb2c --- /dev/null +++ b/internal/jsonview/explorer.go @@ -0,0 +1,807 @@ +package jsonview + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "math" + "os" + "strings" + + "github.com/charmbracelet/bubbles/help" + "github.com/charmbracelet/bubbles/key" + "github.com/charmbracelet/bubbles/table" + "github.com/charmbracelet/bubbles/viewport" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/x/term" + "github.com/muesli/reflow/truncate" + "github.com/muesli/reflow/wordwrap" + "github.com/tidwall/gjson" +) + +const ( + // UI layout constants + borderPadding = 2 + heightOffset = 5 + tableMinHeight = 2 + titlePaddingLeft = 2 + titlePaddingTop = 0 + footerPaddingLeft = 1 + + // Column width constants + defaultColumnWidth = 10 + keyColumnWidth = 3 + valueColumnWidth = 5 + + // String formatting constants + maxStringLength = 100 + maxPreviewLength = 24 + + arrayColor = lipgloss.Color("1") + stringColor = lipgloss.Color("5") + objectColor = lipgloss.Color("4") +) + +type keyMap struct { + Up key.Binding + Down key.Binding + Enter key.Binding + Back key.Binding + PrintValue key.Binding + Raw key.Binding + Quit key.Binding +} + +func (k keyMap) ShortHelp() []key.Binding { + return []key.Binding{k.Quit, k.Up, k.Down, k.Back, k.Enter, k.PrintValue, k.Raw} +} + +func (k keyMap) FullHelp() [][]key.Binding { + return [][]key.Binding{k.ShortHelp()} +} + +var keys = keyMap{ + Up: key.NewBinding( + key.WithKeys("up", "k"), + key.WithHelp("↑/k", "up"), + ), + Down: key.NewBinding( + key.WithKeys("down", "j"), + key.WithHelp("↓/j", "down"), + ), + Back: key.NewBinding( + key.WithKeys("left", "h", "backspace"), + key.WithHelp("←/h", "go back"), + ), + Enter: key.NewBinding( + key.WithKeys("right", "l"), + key.WithHelp("→/l", "expand"), + ), + PrintValue: key.NewBinding( + key.WithKeys("p"), + key.WithHelp("p", "print and exit"), + ), + Raw: key.NewBinding( + key.WithKeys("r"), + key.WithHelp("r", "toggle raw JSON"), + ), + Quit: key.NewBinding( + key.WithKeys("q", "esc", "ctrl+c", "enter"), + key.WithHelp("q/enter", "quit"), + ), +} + +var ( + titleStyle = lipgloss.NewStyle().Bold(true).PaddingLeft(titlePaddingLeft).PaddingTop(titlePaddingTop) + arrayStyle = lipgloss.NewStyle().BorderStyle(lipgloss.RoundedBorder()).BorderForeground(arrayColor) + stringStyle = lipgloss.NewStyle().BorderStyle(lipgloss.RoundedBorder()).BorderForeground(stringColor) + objectStyle = lipgloss.NewStyle().BorderStyle(lipgloss.RoundedBorder()).BorderForeground(objectColor) + stringLiteralStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("2")) +) + +type JSONView interface { + GetPath() string + GetData() gjson.Result + Update(tea.Msg, bool) tea.Cmd + View() string + Resize(width, height int) +} + +type TableView struct { + width int + height int + path string + data gjson.Result + table table.Model + rowData []gjson.Result + iterator AnyIterator + isLoading bool + columns []table.Column +} + +func (tv *TableView) GetPath() string { return tv.path } +func (tv *TableView) GetData() gjson.Result { return tv.data } +func (tv *TableView) View() string { return tv.table.View() } + +func (tv *TableView) Update(msg tea.Msg, raw bool) tea.Cmd { + var cmd tea.Cmd + tv.table, cmd = tv.table.Update(msg) + + // Check if we need to load more data + if tv.iterator != nil && !tv.isLoading && tv.data.IsArray() { + cursor := tv.table.Cursor() + totalRows := len(tv.table.Rows()) + + // Load more when we're at the last row + if cursor == totalRows-1 { + tv.isLoading = true + return tv.loadMoreData(raw) + } + } + + return cmd +} + +func (tv *TableView) loadMoreData(raw bool) tea.Cmd { + return func() tea.Msg { + if tv.iterator == nil { + return nil + } + + if !tv.iterator.Next() { + tv.isLoading = false + return tv.iterator.Err() + } + + obj := tv.iterator.Current() + var result gjson.Result + if jsonBytes, err := json.Marshal(obj); err != nil { + return err + } else { + result = gjson.ParseBytes(jsonBytes) + } + + if !result.Exists() { + tv.isLoading = false + return nil + } + + // Add the new item to our data + tv.rowData = append(tv.rowData, result) + + // Add new row to the table + newRow := table.Row{formatValue(result, raw)} + + // For array of objects, we need to format according to columns + if len(tv.columns) > 1 && result.IsObject() { + newRow = make(table.Row, len(tv.columns)) + for i, col := range tv.columns { + newRow[i] = formatValue(result.Get(col.Title), raw) + } + } + + rows := tv.table.Rows() + rows = append(rows, newRow) + tv.table.SetRows(rows) + + // Resize columns to accommodate the new data + tv.Resize(tv.width, tv.height) + + tv.isLoading = false + return nil + } +} + +func (tv *TableView) Resize(width, height int) { + tv.width = width + tv.height = height + tv.updateColumnWidths(width) + tv.table.SetHeight(min(height-heightOffset, tableMinHeight+len(tv.table.Rows()))) +} + +func (tv *TableView) updateColumnWidths(width int) { + columns := tv.table.Columns() + widths := make([]int, len(columns)) + + // Calculate required widths from headers and content + for i, col := range columns { + widths[i] = lipgloss.Width(col.Title) + } + + for _, row := range tv.table.Rows() { + for i, cell := range row { + if i < len(widths) { + widths[i] = max(widths[i], lipgloss.Width(cell)) + } + } + } + + totalWidth := sum(widths) + available := width - borderPadding*len(columns) + + if totalWidth <= available { + for i, w := range widths { + columns[i].Width = w + } + return + } + + fairShare := float64(available) / float64(len(columns)) + shrinkable := 0.0 + + for _, w := range widths { + if float64(w) > fairShare { + shrinkable += float64(w) - fairShare + } + } + + if shrinkable > 0 { + excess := float64(totalWidth - available) + for i, w := range widths { + if float64(w) > fairShare { + reduction := (float64(w) - fairShare) * (excess / shrinkable) + widths[i] = int(math.Round(float64(w) - reduction)) + } + } + } + + for i, w := range widths { + columns[i].Width = w + } + + tv.table.SetColumns(columns) +} + +type TextView struct { + path string + data gjson.Result + viewport viewport.Model + ready bool +} + +func (tv *TextView) GetPath() string { return tv.path } +func (tv *TextView) GetData() gjson.Result { return tv.data } +func (tv *TextView) View() string { return tv.viewport.View() } + +func (tv *TextView) Update(msg tea.Msg, raw bool) tea.Cmd { + var cmd tea.Cmd + tv.viewport, cmd = tv.viewport.Update(msg) + return cmd +} + +func (tv *TextView) Resize(width, height int) { + h := height - heightOffset + if !tv.ready { + tv.viewport = viewport.New(width, h) + tv.viewport.SetContent(wordwrap.String(tv.data.String(), width)) + tv.ready = true + return + } + tv.viewport.Width = width + tv.viewport.Height = h +} + +type JSONViewer struct { + stack []JSONView + root string + width int + height int + rawMode bool + message string + help help.Model +} + +// ExploreJSON explores a single JSON value known ahead of time +func ExploreJSON(title string, json gjson.Result) error { + view, err := newView("", json, false) + if err != nil { + return err + } + + viewer := &JSONViewer{stack: []JSONView{view}, root: title, rawMode: false, help: help.New()} + + _, err = tea.NewProgram(viewer).Run() + if viewer.message != "" { + _, msgErr := fmt.Println("\n" + viewer.message) + err = errors.Join(err, msgErr) + } + return err +} + +type hasRawJSON interface { + RawJSON() string +} + +// ExploreJSONStream explores JSON data loaded incrementally via an iterator +func ExploreJSONStream[T any](title string, it Iterator[T]) error { + anyIt := genericToAnyIterator(it) + + preloadCount := 20 + if termHeight, _, err := term.GetSize(os.Stdout.Fd()); err == nil { + preloadCount = termHeight + } + + items := make([]any, 0, preloadCount) + for i := 0; i < preloadCount && anyIt.Next(); i++ { + items = append(items, anyIt.Current()) + } + + if err := anyIt.Err(); err != nil { + return err + } + + arrayJSONBytes, err := marshalItemsToJSONArray(items) + if err != nil { + return err + } + + arrayJSON := gjson.ParseBytes(arrayJSONBytes) + view, err := newTableView("", arrayJSON, false) + if err != nil { + return err + } + + // Set iterator if there might be more data + if len(items) == preloadCount { + view.iterator = anyIt + } + + viewer := &JSONViewer{stack: []JSONView{view}, root: title, rawMode: false, help: help.New()} + _, err = tea.NewProgram(viewer).Run() + if viewer.message != "" { + _, msgErr := fmt.Println("\n" + viewer.message) + err = errors.Join(err, msgErr) + } + return err +} + +func marshalItemsToJSONArray(items []any) ([]byte, error) { + var buf bytes.Buffer + buf.WriteByte('[') + + for i, item := range items { + if i > 0 { + buf.WriteByte(',') + } + if hasRaw, ok := item.(hasRawJSON); ok { + buf.WriteString(hasRaw.RawJSON()) + } else { + jsonData, err := json.Marshal(item) + if err != nil { + return nil, err + } + buf.Write(jsonData) + } + } + + buf.WriteByte(']') + return buf.Bytes(), nil +} + +func (v *JSONViewer) current() JSONView { return v.stack[len(v.stack)-1] } +func (v *JSONViewer) Init() tea.Cmd { return nil } + +func (v *JSONViewer) resize(width, height int) { + v.width, v.height = width, height + v.help.Width = width + for i := range v.stack { + v.stack[i].Resize(width, height) + } +} + +func (v *JSONViewer) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.WindowSizeMsg: + v.resize(msg.Width-borderPadding, msg.Height) + return v, nil + case tea.KeyMsg: + switch { + case key.Matches(msg, keys.Quit): + return v, tea.Quit + case key.Matches(msg, keys.Enter): + return v.navigateForward() + case key.Matches(msg, keys.Back): + return v.navigateBack() + case key.Matches(msg, keys.Raw): + return v.toggleRaw() + case key.Matches(msg, keys.PrintValue): + v.message = v.getSelectedContent() + return v, tea.Quit + } + } + + return v, v.current().Update(msg, v.rawMode) +} + +func (v *JSONViewer) getSelectedContent() string { + tableView, ok := v.current().(*TableView) + if !ok { + return v.current().GetData().Raw + } + + selected := tableView.rowData[tableView.table.Cursor()] + if selected.Type == gjson.String { + return selected.String() + } + return selected.Raw +} + +func (v *JSONViewer) navigateForward() (tea.Model, tea.Cmd) { + tableView, ok := v.current().(*TableView) + if !ok { + return v, nil + } + + if len(tableView.rowData) < 1 { + return v, nil + } + + cursor := tableView.table.Cursor() + selected := tableView.rowData[cursor] + if !v.canNavigateInto(selected) { + return v, nil + } + + path := v.buildNavigationPath(tableView, cursor) + forwardView, err := newView(path, selected, v.rawMode) + if err != nil { + return v, nil + } + + v.stack = append(v.stack, forwardView) + v.resize(v.width, v.height) + return v, nil +} + +func (v *JSONViewer) buildNavigationPath(tableView *TableView, cursor int) string { + if tableView.data.IsArray() { + return fmt.Sprintf("%s[%d]", tableView.path, cursor) + } + key := tableView.data.Get("@keys").Array()[cursor].Str + return fmt.Sprintf("%s[%s]", tableView.path, quoteString(key)) +} + +func quoteString(s string) string { + // Replace backslashes and quotes with escaped versions + s = strings.ReplaceAll(s, "\\", "\\\\") + s = strings.ReplaceAll(s, "\"", "\\\"") + return stringLiteralStyle.Render("\"" + s + "\"") +} + +func (v *JSONViewer) canNavigateInto(data gjson.Result) bool { + switch { + case data.IsArray(): + return len(data.Array()) > 0 + case data.IsObject(): + return len(data.Map()) > 0 + case data.Type == gjson.String: + str := data.String() + return strings.Contains(str, "\n") || lipgloss.Width(str) >= maxStringLength + } + return false +} + +func (v *JSONViewer) navigateBack() (tea.Model, tea.Cmd) { + if len(v.stack) > 1 { + v.stack = v.stack[:len(v.stack)-1] + } + return v, nil +} + +func (v *JSONViewer) toggleRaw() (tea.Model, tea.Cmd) { + v.rawMode = !v.rawMode + + for i, view := range v.stack { + viewWithRaw, err := newView(view.GetPath(), view.GetData(), v.rawMode) + if err != nil { + return v, tea.Printf("Error: %s", err) + } + if newTV, ok := viewWithRaw.(*TableView); ok { + if tv, ok := view.(*TableView); ok && tv.iterator != nil { + newTV.iterator = tv.iterator + } + } + v.stack[i] = viewWithRaw + } + + v.resize(v.width, v.height) + return v, nil +} + +func (v *JSONViewer) View() string { + view := v.current() + title := v.buildTitle(view) + content := titleStyle.Render(title) + style := v.getStyleForData(view.GetData()) + content += "\n" + style.Render(view.View()) + content += "\n" + v.help.View(keys) + return content +} + +func (v *JSONViewer) buildTitle(view JSONView) string { + title := v.root + if len(view.GetPath()) > 0 { + title += " → " + view.GetPath() + } + if v.rawMode { + title += " (JSON)" + } + return title +} + +func (v *JSONViewer) getStyleForData(data gjson.Result) lipgloss.Style { + switch { + case data.Type == gjson.String: + return stringStyle + case data.IsArray(): + return arrayStyle + default: + return objectStyle + } +} + +func newView(path string, data gjson.Result, raw bool) (JSONView, error) { + if data.Type == gjson.String { + return newTextView(path, data) + } + return newTableView(path, data, raw) +} + +func newTextView(path string, data gjson.Result) (*TextView, error) { + if !data.Exists() || data.Type != gjson.String { + return nil, fmt.Errorf("invalid text JSON") + } + return &TextView{path: path, data: data}, nil +} + +func newTableView(path string, data gjson.Result, raw bool) (*TableView, error) { + if !data.Exists() || data.Type != gjson.JSON { + return nil, fmt.Errorf("invalid table JSON") + } + + switch { + case data.IsArray(): + array := data.Array() + if isArrayOfObjects(array) { + return newArrayOfObjectsTableView(path, data, array, raw), nil + } else { + return newArrayTableView(path, data, array, raw), nil + } + case data.IsObject(): + return newObjectTableView(path, data, raw), nil + default: + return nil, fmt.Errorf("unsupported JSON type") + } +} + +func newArrayTableView(path string, data gjson.Result, array []gjson.Result, raw bool) *TableView { + columns := []table.Column{{Title: "Items", Width: defaultColumnWidth}} + rows := make([]table.Row, 0, len(array)) + rowData := make([]gjson.Result, 0, len(array)) + + for _, item := range array { + rows = append(rows, table.Row{formatValue(item, raw)}) + rowData = append(rowData, item) + } + + t := createTable(columns, rows, arrayColor) + return &TableView{ + path: path, + data: data, + table: t, + rowData: rowData, + columns: columns, + } +} + +func newArrayOfObjectsTableView(path string, data gjson.Result, array []gjson.Result, raw bool) *TableView { + // Collect unique keys + keySet := make(map[string]struct{}) + var columns []table.Column + + for _, item := range array { + for _, key := range item.Get("@keys").Array() { + if _, exists := keySet[key.Str]; !exists { + keySet[key.Str] = struct{}{} + title := key.Str + columns = append(columns, table.Column{Title: title, Width: defaultColumnWidth}) + } + } + } + + rows := make([]table.Row, 0, len(array)) + rowData := make([]gjson.Result, 0, len(array)) + + for _, item := range array { + row := make(table.Row, len(columns)) + for i, col := range columns { + row[i] = formatValue(item.Get(col.Title), raw) + } + rows = append(rows, row) + rowData = append(rowData, item) + } + + t := createTable(columns, rows, arrayColor) + return &TableView{ + path: path, + data: data, + table: t, + rowData: rowData, + columns: columns, + } +} + +func newObjectTableView(path string, data gjson.Result, raw bool) *TableView { + columns := []table.Column{{Title: "Object"}, {}} + + keys := data.Get("@keys").Array() + rows := make([]table.Row, 0, len(keys)) + rowData := make([]gjson.Result, 0, len(keys)) + + for _, key := range keys { + value := data.Get(key.Str) + title := key.Str + rows = append(rows, table.Row{title, formatValue(value, raw)}) + rowData = append(rowData, value) + } + + // Adjust column widths based on content + for _, row := range rows { + for i, cell := range row { + if i < len(columns) { + columns[i].Width = max(columns[i].Width, lipgloss.Width(cell)) + } + } + } + + t := createTable(columns, rows, objectColor) + return &TableView{ + path: path, + data: data, + table: t, + rowData: rowData, + columns: columns, + } +} + +func createTable(columns []table.Column, rows []table.Row, bgColor lipgloss.Color) table.Model { + t := table.New( + table.WithColumns(columns), + table.WithRows(rows), + table.WithFocused(true), + ) + + // Set common table styles + s := table.DefaultStyles() + s.Header = s.Header. + BorderStyle(lipgloss.NormalBorder()). + BorderForeground(lipgloss.Color("240")). + BorderBottom(true). + Bold(true) + s.Selected = s.Selected. + Foreground(lipgloss.Color("229")). + Background(bgColor). + Bold(false) + t.SetStyles(s) + + return t +} + +func formatValue(value gjson.Result, raw bool) string { + if raw { + return value.Get("@ugly").Raw + } + + switch { + case value.IsObject(): + return formatObject(value) + case value.IsArray(): + return formatArray(value) + case value.Type == gjson.String: + return value.Str + default: + return value.Raw + } +} + +func formatObject(value gjson.Result) string { + keys := value.Get("@keys").Array() + keyStrs := make([]string, len(keys)) + + for i, key := range keys { + val := value.Get(key.Str) + keyStrs[i] = formatObjectKey(key.Str, val) + } + + return "{" + strings.Join(keyStrs, ", ") + "}" +} + +func formatObjectKey(key string, val gjson.Result) string { + switch { + case val.IsObject(): + return key + ":{…}" + case val.IsArray(): + return key + ":[…]" + case val.Type == gjson.String: + str := val.Str + if lipgloss.Width(str) <= maxPreviewLength { + return fmt.Sprintf(`%s:"%s"`, key, str) + } + return fmt.Sprintf(`%s:"%s…"`, key, truncate.String(str, uint(maxPreviewLength))) + default: + return key + ":" + val.Raw + } +} + +func formatArray(value gjson.Result) string { + switch count := len(value.Array()); count { + case 0: + return "[]" + case 1: + return "[...1 item...]" + default: + return fmt.Sprintf("[...%d items...]", count) + } +} + +func isArrayOfObjects(array []gjson.Result) bool { + for _, item := range array { + if !item.IsObject() { + return false + } + } + return len(array) > 0 +} + +func sum(ints []int) int { + total := 0 + for _, n := range ints { + total += n + } + return total +} + +// An iterator over `any` values +type AnyIterator interface { + Next() bool + Err() error + Current() any +} + +// A generic iterator interface that is used by the `genericIterator` struct +// below to convert iterators over specific types to an AnyIterator +type Iterator[T any] interface { + Next() bool + Err() error + Current() T +} + +// genericIterator adapts a generic Iterator[T] to an AnyIterator. +type genericIterator[T any] struct { + iterator Iterator[T] + current any +} + +func (g *genericIterator[T]) Next() bool { + if !g.iterator.Next() { + return false + } + g.current = g.iterator.Current() + return true +} + +func (g *genericIterator[T]) Err() error { + return g.iterator.Err() +} + +func (g *genericIterator[T]) Current() any { + return g.current +} + +func genericToAnyIterator[T any](it Iterator[T]) AnyIterator { + return &genericIterator[T]{ + iterator: it, + } +} diff --git a/internal/jsonview/explorer_test.go b/internal/jsonview/explorer_test.go new file mode 100644 index 0000000..67ee730 --- /dev/null +++ b/internal/jsonview/explorer_test.go @@ -0,0 +1,66 @@ +package jsonview + +import ( + "testing" + + "github.com/charmbracelet/bubbles/help" + "github.com/tidwall/gjson" + + "github.com/stretchr/testify/require" +) + +func TestNavigateForward_EmptyRowData(t *testing.T) { + t.Parallel() + + // An empty JSON array produces a TableView with no rows. + emptyArray := gjson.Parse("[]") + view, err := newTableView("", emptyArray, false) + require.NoError(t, err) + + viewer := &JSONViewer{ + stack: []JSONView{view}, + root: "test", + help: help.New(), + } + + // Should return without panicking despite the empty data set. + model, cmd := viewer.navigateForward() + require.Equal(t, model, viewer, "expected same viewer model returned") + require.Nil(t, cmd) + + // Stack should remain unchanged (no new view pushed). + require.Equal(t, 1, len(viewer.stack), "expected stack length 1, got %d", len(viewer.stack)) +} + +// rawJSONItem implements HasRawJSON, returning pre-built JSON. +type rawJSONItem struct { + raw string +} + +func (r rawJSONItem) RawJSON() string { return r.raw } + +func TestMarshalItemsToJSONArray_WithHasRawJSON(t *testing.T) { + t.Parallel() + + items := []any{ + rawJSONItem{raw: `{"id":1,"name":"alice"}`}, + rawJSONItem{raw: `{"id":2,"name":"bob"}`}, + } + + got, err := marshalItemsToJSONArray(items) + require.NoError(t, err) + require.JSONEq(t, `[{"id":1,"name":"alice"},{"id":2,"name":"bob"}]`, string(got)) +} + +func TestMarshalItemsToJSONArray_WithoutHasRawJSON(t *testing.T) { + t.Parallel() + + items := []any{ + map[string]any{"id": 1, "name": "alice"}, + map[string]any{"id": 2, "name": "bob"}, + } + + got, err := marshalItemsToJSONArray(items) + require.NoError(t, err) + require.JSONEq(t, `[{"id":1,"name":"alice"},{"id":2,"name":"bob"}]`, string(got)) +} diff --git a/internal/jsonview/staticdisplay.go b/internal/jsonview/staticdisplay.go new file mode 100644 index 0000000..768ea34 --- /dev/null +++ b/internal/jsonview/staticdisplay.go @@ -0,0 +1,135 @@ +package jsonview + +import ( + "fmt" + "os" + "strings" + + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/x/term" + "github.com/muesli/reflow/truncate" + "github.com/tidwall/gjson" +) + +const ( + tabWidth = 2 +) + +var ( + keyStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("75")).Bold(false) + stringValueStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("113")) + numberValueStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("215")) + boolValueStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("207")) + nullValueStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("245")).Italic(true) + bulletStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("242")) + containerStyle = lipgloss.NewStyle(). + Border(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("63")). + Padding(0, 1) +) + +func formatJSON(json gjson.Result, width int) string { + if !json.Exists() { + return nullValueStyle.Render("Invalid JSON") + } + return formatResult(json, 0, width) +} + +func formatResult(result gjson.Result, indent, width int) string { + switch result.Type { + case gjson.String: + str := result.Str + if str == "" { + return nullValueStyle.Render("(empty)") + } + if lipgloss.Width(str) > width { + str = truncate.String(str, uint(width-1)) + "…" + } + return stringValueStyle.Render(str) + case gjson.Number: + return numberValueStyle.Render(result.Raw) + case gjson.True: + return boolValueStyle.Render("yes") + case gjson.False: + return boolValueStyle.Render("no") + case gjson.Null: + return nullValueStyle.Render("null") + case gjson.JSON: + if result.IsArray() { + return formatJSONArray(result, indent, width) + } + return formatJSONObject(result, indent, width) + default: + return stringValueStyle.Render(result.String()) + } +} + +func isSingleLine(result gjson.Result, indent int) bool { + return !(result.IsObject() || result.IsArray()) +} + +func formatJSONArray(result gjson.Result, indent, width int) string { + items := result.Array() + if len(items) == 0 { + return nullValueStyle.Render(" (none)") + } + + numberWidth := lipgloss.Width(fmt.Sprintf("%d. ", len(items))) + + var formattedItems []string + for i, item := range items { + number := fmt.Sprintf("%d.", i+1) + numbering := getIndent(indent) + bulletStyle.Render(number) + + // If the item will be a one-liner, put it inline after the numbering, + // otherwise it starts with a newline and goes below the numbering. + itemWidth := width + if isSingleLine(item, indent+1) { + // Add right-padding: + numbering += strings.Repeat(" ", numberWidth-lipgloss.Width(number)) + itemWidth = width - lipgloss.Width(numbering) + } + value := formatResult(item, indent+1, itemWidth) + formattedItems = append(formattedItems, numbering+value) + } + return "\n" + strings.Join(formattedItems, "\n") +} + +func formatJSONObject(result gjson.Result, indent, width int) string { + keys := result.Get("@keys").Array() + if len(keys) == 0 { + return nullValueStyle.Render("(empty)") + } + + var items []string + for _, key := range keys { + value := result.Get(key.String()) + keyStr := getIndent(indent) + keyStyle.Render(key.String()+":") + // If item will be a one-liner, put it inline after the key, otherwise + // it starts with a newline and goes below the key. + itemWidth := width + if isSingleLine(value, indent+1) { + keyStr += " " + itemWidth = width - lipgloss.Width(keyStr) + } + formattedValue := formatResult(value, indent+1, itemWidth) + items = append(items, keyStr+formattedValue) + } + + return "\n" + strings.Join(items, "\n") +} + +func getIndent(indent int) string { + return strings.Repeat(" ", indent*tabWidth) +} + +func RenderJSON(title string, json gjson.Result) string { + width, _, err := term.GetSize(os.Stdout.Fd()) + if err != nil { + width = 80 + } + width -= containerStyle.GetBorderLeftSize() + containerStyle.GetBorderRightSize() + + containerStyle.GetPaddingLeft() + containerStyle.GetPaddingRight() + content := strings.TrimLeft(formatJSON(json, width), "\n") + return titleStyle.Render(title) + "\n" + containerStyle.Render(content) +} diff --git a/internal/mocktest/mocktest.go b/internal/mocktest/mocktest.go new file mode 100644 index 0000000..40b5fe5 --- /dev/null +++ b/internal/mocktest/mocktest.go @@ -0,0 +1,101 @@ +package mocktest + +import ( + "bytes" + "context" + "fmt" + "net" + "net/http" + "net/url" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +var mockServerURL *url.URL + +func init() { + mockServerURL, _ = url.Parse("http://localhost:4010") + if testURL := os.Getenv("TEST_API_BASE_URL"); testURL != "" { + if parsed, err := url.Parse(testURL); err == nil { + mockServerURL = parsed + } + } +} + +// OnlyMockServerDialer only allows network connections to the mock server +type OnlyMockServerDialer struct{} + +func (d *OnlyMockServerDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) { + if address == mockServerURL.Host { + return (&net.Dialer{}).DialContext(ctx, network, address) + } + + return nil, fmt.Errorf("BLOCKED: connection to %s not allowed (only allowed: %s)", address, mockServerURL.Host) +} + +func blockNetworkExceptMockServer() (http.RoundTripper, http.RoundTripper) { + restricted := &http.Transport{ + DialContext: (&OnlyMockServerDialer{}).DialContext, + } + + origClient, origDefault := http.DefaultClient.Transport, http.DefaultTransport + http.DefaultClient.Transport, http.DefaultTransport = restricted, restricted + return origClient, origDefault +} + +func restoreNetwork(origClient, origDefault http.RoundTripper) { + http.DefaultClient.Transport, http.DefaultTransport = origClient, origDefault +} + +// TestRunMockTestWithFlags runs a test against a mock server with the provided +// CLI args and ensures it succeeds +func TestRunMockTestWithFlags(t *testing.T, args ...string) { + TestRunMockTestWithPipeAndFlags(t, nil, args...) +} + +// TestRunMockTestWithPipeAndFlags runs a test against a mock server with the provided +// data piped over stdin and CLI args and ensures it succeeds +func TestRunMockTestWithPipeAndFlags(t *testing.T, pipeData []byte, args ...string) { + origClient, origDefault := blockNetworkExceptMockServer() + defer restoreNetwork(origClient, origDefault) + + // Check if mock server is running + conn, err := net.DialTimeout("tcp", mockServerURL.Host, 2*time.Second) + if err != nil { + require.Fail(t, "Mock server is not running on "+mockServerURL.Host+". Please start the mock server before running tests.") + } else { + conn.Close() + } + + // Get the path to the main command + _, filename, _, ok := runtime.Caller(0) + require.True(t, ok, "Could not get current file path") + dirPath := filepath.Dir(filename) + project := filepath.Join(dirPath, "..", "..", "cmd", "context-dev") + + args = append([]string{"run", project, "--base-url", mockServerURL.String()}, args...) + + t.Logf("Testing command: go run ./cmd/context-dev %s", strings.Join(args[2:], " ")) + + cmd := exec.Command("go", args...) + cmd.Stdin = bytes.NewReader(pipeData) + output, err := cmd.CombinedOutput() + assert.NoError(t, err, "Test failed\nError: %v\nOutput: %s", err, output) + + t.Logf("Test passed successfully\nOutput:\n%s", string(output)) +} + +func TestFile(t *testing.T, contents string) string { + tmpDir := t.TempDir() + filename := filepath.Join(tmpDir, "file.txt") + require.NoError(t, os.WriteFile(filename, []byte(contents), 0644)) + return filename +} diff --git a/internal/requestflag/innerflag.go b/internal/requestflag/innerflag.go new file mode 100644 index 0000000..528915f --- /dev/null +++ b/internal/requestflag/innerflag.go @@ -0,0 +1,289 @@ +package requestflag + +import ( + "fmt" + "reflect" + "strings" + + "github.com/urfave/cli/v3" +) + +// InnerFlag[T] represents a CLI flag for the urfave/cli package that allows setting +// nested fields within other flags. For example, using `--foo.baz` will set the "baz" +// field on a parent flag named `--foo`. +type InnerFlag[ + T []any | []map[string]any | []DateTimeValue | []DateValue | []TimeValue | []string | + []float64 | []int64 | []bool | any | map[string]any | DateTimeValue | DateValue | TimeValue | + string | float64 | int64 | bool | + *string | *float64 | *int64 | *bool | *DateTimeValue | *DateValue | *TimeValue, +] struct { + Name string // name of the flag + DefaultText string // default text of the flag for usage purposes + Usage string // usage string for help output + Aliases []string // aliases that are allowed for this flag + Validator func(T) error // custom function to validate this flag value + + OuterFlag cli.Flag // The flag on which this inner flag will set values + InnerField string // The inner field which this flag will set + DataAliases []string // alternate names recognized in YAML values passed as the outer flag + + // OuterIsArrayOfObjects tells an untyped outer flag (Flag[any], used for nullable + // complex schemas) to seed its underlying value as []map[string]any rather than + // map[string]any before SetInnerField runs. The hint is ignored for typed outer + // flags whose zero value already carries a dispatchable reflect.Kind. + OuterIsArrayOfObjects bool +} + +// GetDataAliases returns the aliases recognized when parsing inner field keys from piped or flag YAML. +func (f *InnerFlag[T]) GetDataAliases() []string { + return f.DataAliases +} + +// GetInnerField returns the API field name that this inner flag sets on its outer flag's value. +// For example, the flag --parent.foo targeting a parameter whose OpenAPI property name is "foo" +// would return "foo". This is distinct from the flag's CLI name and from any DataAliases entries. +func (f *InnerFlag[T]) GetInnerField() string { + return f.InnerField +} + +type HasOuterFlag interface { + cli.Flag + SetOuterFlag(cli.Flag) + GetOuterFlag() cli.Flag + GetInnerField() string + GetDataAliases() []string +} + +func (f *InnerFlag[T]) SetOuterFlag(flag cli.Flag) { + f.OuterFlag = flag +} + +func (f *InnerFlag[T]) GetOuterFlag() cli.Flag { + return f.OuterFlag +} + +// Implementation of the cli.Flag interface +var _ cli.Flag = (*InnerFlag[any])(nil) // Type assertion to ensure interface compliance + +func (f *InnerFlag[T]) PreParse() error { + return nil +} + +func (f *InnerFlag[T]) PostParse() error { + return nil +} + +func (f *InnerFlag[T]) Set(name string, rawVal string) error { + if parsedValue, err := parseCLIArg[T](rawVal); err != nil { + return err + } else { + if f.Validator != nil { + if err := f.Validator(parsedValue); err != nil { + return err + } + } + + if seeder, ok := f.OuterFlag.(InnerFieldSeeder); ok { + seeder.SeedInnerCollection(f.OuterIsArrayOfObjects) + } + + if settableInnerField, ok := f.OuterFlag.(SettableInnerField); ok { + settableInnerField.SetInnerField(f.InnerField, parsedValue) + } else { + return fmt.Errorf("Cannot set inner field on %v", f.OuterFlag) + } + return nil + } +} + +func (f *InnerFlag[T]) Get() any { + var zeroValue T + return zeroValue +} + +func (f *InnerFlag[T]) String() string { + return cli.FlagStringer(f) +} + +func (f *InnerFlag[T]) IsSet() bool { + return false +} + +func (f *InnerFlag[T]) Names() []string { + return cli.FlagNames(f.Name, f.Aliases) +} + +// Implementation for the cli.DocGenerationFlag interface +var _ cli.DocGenerationFlag = (*InnerFlag[any])(nil) // Type assertion to ensure interface compliance + +func (f *InnerFlag[T]) TakesValue() bool { + var t T + return reflect.TypeOf(t) == nil || reflect.TypeOf(t).Kind() != reflect.Bool +} + +func (f *InnerFlag[T]) GetUsage() string { + return f.Usage +} + +func (f *InnerFlag[T]) GetValue() string { + return "" +} + +func (f *InnerFlag[T]) GetDefaultText() string { + return f.DefaultText +} + +func (f *InnerFlag[T]) GetEnvVars() []string { + return nil +} + +func (f *InnerFlag[T]) IsDefaultVisible() bool { + return false +} + +func (f *InnerFlag[T]) TypeName() string { + var zeroValue T + ty := reflect.TypeOf(zeroValue) + if ty == nil { + return "" + } + if ty.Kind() == reflect.Pointer { + ty = ty.Elem() + } + + // Get base type name with special handling for built-in types + getTypeName := func(t reflect.Type) string { + switch t.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, + reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return "int" + case reflect.Float32, reflect.Float64: + return "float" + case reflect.Bool: + return "boolean" + case reflect.String: + switch t.Name() { + case "DateTimeValue": + return "datetime" + case "DateValue": + return "date" + case "TimeValue": + return "time" + default: + return "string" + } + default: + if t.Name() == "" { + return "any" + } + return strings.ToLower(t.Name()) + } + } + + switch ty.Kind() { + case reflect.Slice: + elemType := ty.Elem() + return getTypeName(elemType) + case reflect.Map: + keyType := ty.Key() + valueType := ty.Elem() + return fmt.Sprintf("%s=%s", getTypeName(keyType), getTypeName(valueType)) + default: + return getTypeName(ty) + } +} + +// Implementation for the cli.DocGenerationMultiValueFlag interface +var _ cli.DocGenerationMultiValueFlag = (*InnerFlag[any])(nil) // Type assertion to ensure interface compliance + +func (f *InnerFlag[T]) IsMultiValueFlag() bool { + return false +} + +func (f *InnerFlag[T]) IsBoolFlag() bool { + var zeroValue T + _, isBool := any(zeroValue).(bool) + return isBool +} + +// WithInnerFlags takes a command and a map of flag names to inner flags, +// and returns a modified command with the appropriate inner flags set. +func WithInnerFlags(cmd cli.Command, innerFlagMap map[string][]HasOuterFlag) cli.Command { + if len(innerFlagMap) == 0 { + return cmd + } + + // If any keys are unused by the end, we know that they were not valid + unusedInnerFlagKeys := make(map[string]struct{}) + for name := range innerFlagMap { + unusedInnerFlagKeys[name] = struct{}{} + } + + updatedFlags := make([]cli.Flag, 0, len(cmd.Flags)) + for _, flag := range cmd.Flags { + updatedFlags = append(updatedFlags, flag) + for _, name := range flag.Names() { + // Check if this flag has inner flags in our map + innerFlags, hasInnerFlags := innerFlagMap[name] + if !hasInnerFlags { + continue + } + + // Mark this inner flag key as used + delete(unusedInnerFlagKeys, name) + + for _, innerFlag := range innerFlags { + innerFlag.SetOuterFlag(flag) + updatedFlags = append(updatedFlags, innerFlag) + } + } + } + + // If there are inner flags that don't correspond to any valid outer flag + // names, then panic because the user probably made a typo or forgot to + // delete inner flags that correspond to missing outer flags. + if len(unusedInnerFlagKeys) > 0 { + unusedKeys := make([]string, 0, len(unusedInnerFlagKeys)) + for key := range unusedInnerFlagKeys { + unusedKeys = append(unusedKeys, key) + } + panic(fmt.Sprintf("Missing outer flags to use with inner flags: %v", unusedKeys)) + } + + result := cmd + result.Flags = updatedFlags + return result +} + +// Helper function to verify that all inner flags have an outer flag set and +// follow the --foo.baz prefix format +func CheckInnerFlags(cmd cli.Command) error { + var errors []string + for _, flag := range cmd.Flags { + if innerFlag, ok := flag.(HasOuterFlag); ok { + outerFlag := innerFlag.GetOuterFlag() + if outerFlag == nil { + errors = append(errors, fmt.Sprintf("inner flag %s is missing an outer flag", flag.Names())) + continue + } + + innerFlagName := flag.Names()[0] + valid := false + for _, outerName := range outerFlag.Names() { + if strings.HasPrefix(innerFlagName, outerName+".") { + valid = true + break + } + } + + if !valid { + errors = append(errors, fmt.Sprintf("inner flag %s must start with one of its outer flag's names followed by a dot", innerFlagName)) + } + } + } + + if len(errors) > 0 { + return fmt.Errorf("%s", strings.Join(errors, "; ")) + } + return nil +} diff --git a/internal/requestflag/innerflag_test.go b/internal/requestflag/innerflag_test.go new file mode 100644 index 0000000..133e8b4 --- /dev/null +++ b/internal/requestflag/innerflag_test.go @@ -0,0 +1,347 @@ +package requestflag + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/urfave/cli/v3" +) + +func TestInnerFlagSet(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + flagType string + inputVal string + expected any + expectErr bool + }{ + {"string", "string", "hello", "hello", false}, + {"int64", "int64", "42", int64(42), false}, + {"float64", "float64", "3.14", float64(3.14), false}, + {"bool", "bool", "true", true, false}, + {"invalid int", "int64", "not-a-number", nil, true}, + {"invalid float", "float64", "not-a-float", nil, true}, + {"invalid bool", "bool", "not-a-bool", nil, true}, + {"yaml map", "map", "key: value", map[string]any{"key": "value"}, false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + outerFlag := &Flag[map[string]any]{ + Name: "test-flag", + } + + var innerFlag cli.Flag + switch tt.flagType { + case "string": + innerFlag = &InnerFlag[string]{ + Name: "test-flag.test-field", + OuterFlag: outerFlag, + InnerField: "test_field", + } + case "int64": + innerFlag = &InnerFlag[int64]{ + Name: "test-flag.test-field", + OuterFlag: outerFlag, + InnerField: "test_field", + } + case "float64": + innerFlag = &InnerFlag[float64]{ + Name: "test-flag.test-field", + OuterFlag: outerFlag, + InnerField: "test_field", + } + case "bool": + innerFlag = &InnerFlag[bool]{ + Name: "test-flag.test-field", + OuterFlag: outerFlag, + InnerField: "test_field", + } + case "map": + innerFlag = &InnerFlag[map[string]any]{ + Name: "test-flag.test-field", + OuterFlag: outerFlag, + InnerField: "test_field", + } + } + + err := innerFlag.Set(innerFlag.Names()[0], tt.inputVal) + + if tt.expectErr { + assert.Error(t, err) + return + } + + assert.NoError(t, err) + actual, ok := outerFlag.Get().(map[string]any)["test_field"] + assert.True(t, ok, "Field 'test_field' should exist in the map") + assert.Equal(t, tt.expected, actual, "Expected %v (%T), got %v (%T)", tt.expected, tt.expected, actual, actual) + }) + } +} + +func TestInnerFlagValidator(t *testing.T) { + t.Parallel() + + outerFlag := &Flag[map[string]any]{Name: "test-flag"} + + innerFlag := &InnerFlag[int64]{ + Name: "test-flag.test-field", + OuterFlag: outerFlag, + InnerField: "test_field", + Validator: func(val int64) error { + if val < 0 { + return cli.Exit("Value must be non-negative", 1) + } + return nil + }, + } + + // Valid case + err := innerFlag.Set(innerFlag.Name, "42") + assert.NoError(t, err, "Expected no error for valid value, got: %v", err) + + // Should trigger validator error + err = innerFlag.Set(innerFlag.Name, "-5") + assert.Error(t, err, "Expected error for invalid value, got none") +} + +func TestWithInnerFlags(t *testing.T) { + t.Parallel() + + outerFlag := &Flag[map[string]any]{Name: "outer"} + innerFlag := &InnerFlag[string]{ + Name: "outer.baz", + InnerField: "baz", + } + + cmd := WithInnerFlags(cli.Command{ + Name: "test-command", + Flags: []cli.Flag{outerFlag}, + }, map[string][]HasOuterFlag{ + "outer": {innerFlag}, + }) + + // Verify that the command now has both the original flag and inner flag + assert.Len(t, cmd.Flags, 2, "Expected 2 flags, got %d", len(cmd.Flags)) + assert.Equal(t, outerFlag, cmd.Flags[0], "First flag should be outerFlag") + assert.Equal(t, innerFlag, cmd.Flags[1], "Second flag should be innerFlag") + assert.Same(t, outerFlag, innerFlag.OuterFlag, "innerFlag.OuterFlag should point to outerFlag") +} + +func TestInnerFlagTypeNames(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + flag cli.DocGenerationFlag + expected string + }{ + {"string", &InnerFlag[string]{}, "string"}, + {"int64", &InnerFlag[int64]{}, "int"}, + {"float64", &InnerFlag[float64]{}, "float"}, + {"bool", &InnerFlag[bool]{}, "boolean"}, + {"string slice", &InnerFlag[[]string]{}, "string"}, + {"date", &InnerFlag[DateValue]{}, "date"}, + {"datetime", &InnerFlag[DateTimeValue]{}, "datetime"}, + {"time", &InnerFlag[TimeValue]{}, "time"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + typeName := tt.flag.TypeName() + assert.Equal(t, tt.expected, typeName, "Expected type name %q, got %q", tt.expected, typeName) + }) + } +} + +func TestInnerYamlHandling(t *testing.T) { + t.Parallel() + + // Test with map value + t.Run("Parse YAML to map", func(t *testing.T) { + t.Parallel() + + outerFlag := &Flag[map[string]any]{Name: "outer"} + innerFlag := &InnerFlag[map[string]any]{ + Name: "outer.baz", + OuterFlag: outerFlag, + InnerField: "baz", + } + + err := innerFlag.Set(innerFlag.Name, "{name: test, value: 42}") + assert.NoError(t, err) + + // Retrieve and check the parsed YAML map + result, ok := outerFlag.Get().(map[string]any) + assert.True(t, ok, "Expected map[string]any from outerFlag.Get()") + yamlField, ok := result["baz"].(map[string]any) + assert.True(t, ok, "Expected map[string]any, got %T", result["baz"]) + val := yamlField + + if ok { + assert.Equal(t, map[string]any{"name": "test", "value": uint64(42)}, val) + } + }) + + // Test with invalid YAML + t.Run("Parse invalid YAML", func(t *testing.T) { + t.Parallel() + + outerFlag := &Flag[map[string]any]{Name: "outer"} + innerFlag := &InnerFlag[map[string]any]{ + Name: "outer.baz", + OuterFlag: outerFlag, + InnerField: "baz", + } + + invalidYaml := `[not closed` + err := innerFlag.Set(innerFlag.Name, invalidYaml) + assert.Error(t, err) + }) + + // Test setting inner flags on a map multiple times + t.Run("Set inner flags on map multiple times", func(t *testing.T) { + t.Parallel() + + outerFlag := &Flag[map[string]any]{Name: "outer"} + + // Set first inner flag + firstInnerFlag := &InnerFlag[string]{ + Name: "outer.first-flag", + OuterFlag: outerFlag, + InnerField: "first_field", + } + + err := firstInnerFlag.Set(firstInnerFlag.Name, "first-value") + assert.NoError(t, err) + + // Set second inner flag + secondInnerFlag := &InnerFlag[int64]{ + Name: "outer.second-flag", + OuterFlag: outerFlag, + InnerField: "second_field", + } + + err = secondInnerFlag.Set(secondInnerFlag.Name, "42") + assert.NoError(t, err) + + // Verify both fields are set correctly + result := outerFlag.Get().(map[string]any) + assert.Equal(t, map[string]any{"first_field": "first-value", "second_field": int64(42)}, result) + }) + + // Test setting YAML and then an inner flag + t.Run("Set YAML and then inner flag", func(t *testing.T) { + t.Parallel() + + outerFlag := &Flag[map[string]any]{Name: "outer"} + + // First set the outer flag with YAML + err := outerFlag.Set(outerFlag.Name, `{existing: value, another: field}`) + assert.NoError(t, err) + + // Then set an inner flag + innerFlag := &InnerFlag[string]{ + Name: "outer.inner-flag", + OuterFlag: outerFlag, + InnerField: "new_field", + } + + err = innerFlag.Set(innerFlag.Name, "inner-value") + assert.NoError(t, err) + + // Verify both the YAML content and inner flag value + result := outerFlag.Get().(map[string]any) + assert.Equal(t, map[string]any{ + "existing": "value", + "another": "field", + "new_field": "inner-value", + }, result) + }) +} + +func TestInnerFlagWithSliceType(t *testing.T) { + t.Parallel() + + t.Run("Setting inner flags on slice of maps", func(t *testing.T) { + t.Parallel() + + outerFlag := &Flag[[]map[string]any]{Name: "outer"} + + // Set first inner flag (should create first item) + firstInnerFlag := &InnerFlag[string]{ + Name: "outer.name-flag", + OuterFlag: outerFlag, + InnerField: "name", + } + + err := firstInnerFlag.Set(firstInnerFlag.Name, "item1") + assert.NoError(t, err) + + // Set second inner flag (should modify first item) + secondInnerFlag := &InnerFlag[int64]{ + Name: "outer.count-flag", + OuterFlag: outerFlag, + InnerField: "count", + } + + err = secondInnerFlag.Set(secondInnerFlag.Name, "42") + assert.NoError(t, err) + + // Set name flag again (should create second item) + err = firstInnerFlag.Set(firstInnerFlag.Name, "item2") + assert.NoError(t, err) + + // Verify the slice has two items with correct values + result := outerFlag.Get().([]map[string]any) + + assert.Equal(t, []map[string]any{ + {"name": "item1", "count": int64(42)}, + {"name": "item2"}, + }, result) + assert.Nil(t, result[1]["count"], "Second item should not have count field") + }) + + t.Run("Appending to existing slice", func(t *testing.T) { + t.Parallel() + + // Initialize with existing items + outerFlag := &Flag[[]map[string]any]{Name: "outer"} + err := outerFlag.Set(outerFlag.Name, `{name: initial}`) + assert.NoError(t, err) + + // Set inner flag to modify existing item + modifyFlag := &InnerFlag[string]{ + Name: "outer.value-flag", + OuterFlag: outerFlag, + InnerField: "value", + } + + err = modifyFlag.Set(modifyFlag.Name, "updated") + assert.NoError(t, err) + + // Set inner flag to create new item + newItemFlag := &InnerFlag[string]{ + Name: "outer.name-flag", + OuterFlag: outerFlag, + InnerField: "name", + } + + err = newItemFlag.Set(newItemFlag.Name, "second") + assert.NoError(t, err) + + // Verify both items + result := outerFlag.Get().([]map[string]any) + assert.Equal(t, []map[string]any{ + {"name": "initial", "value": "updated"}, + {"name": "second"}, + }, result) + }) +} diff --git a/internal/requestflag/requestflag.go b/internal/requestflag/requestflag.go new file mode 100644 index 0000000..77c4f1f --- /dev/null +++ b/internal/requestflag/requestflag.go @@ -0,0 +1,992 @@ +package requestflag + +import ( + "encoding/json" + "fmt" + "reflect" + "strconv" + "strings" + "time" + "unicode" + + "github.com/goccy/go-yaml" + "github.com/urfave/cli/v3" +) + +// formatForFlagSet converts a Go value parsed from YAML/JSON stdin data into a string +// that flag.Set (and thus parseCLIArg) can parse correctly for each flag type. +// Strings are returned as-is (parseCLIArg[string] assigns the raw value directly, so +// JSON-quoting must be avoided). Scalars use %v. Complex types (maps, slices) are +// JSON-encoded, which the yaml.Unmarshal default branch in parseCLIArg can parse. +func formatForFlagSet(val any) (string, error) { + switch v := val.(type) { + case string: + return v, nil + case bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64: + return fmt.Sprintf("%v", val), nil + default: + b, err := json.Marshal(val) + if err != nil { + return "", fmt.Errorf("cannot format value %T for flag.Set: %w", val, err) + } + return string(b), nil + } +} + +// Flag [T] is a generic flag base which can be used to implement the most +// common interfaces used by urfave/cli. Additionally, it allows specifying +// where in an HTTP request the flag values should be placed (e.g. query, body, etc.). +// +// Pointer-to-primitive type parameters (e.g. *string) are used for flags whose underlying +// schema is nullable. They give flags a tri-state: unset (excluded from the request), +// set to the literal "null" (nil pointer → JSON null), or set to a value (*v → JSON value). +type Flag[ + T []any | []map[string]any | []DateTimeValue | []DateValue | []TimeValue | []string | + []float64 | []int64 | []bool | any | map[string]any | DateTimeValue | DateValue | TimeValue | + string | float64 | int64 | bool | + *string | *float64 | *int64 | *bool | *DateTimeValue | *DateValue | *TimeValue, +] struct { + Name string // name of the flag + Category string // category of the flag, if any + DefaultText string // default text of the flag for usage purposes + HideDefault bool // whether to hide the default value in output + Usage string // usage string for help output + Sources cli.ValueSourceChain // sources to load flag value from + Required bool // whether the flag is required or not + Hidden bool // whether to hide the flag in help output + Default T // default value for this flag if not set by from any source + Aliases []string // aliases that are allowed for this flag + Validator func(T) error // custom function to validate this flag value + + QueryPath string // location in the request query string to put this flag's value + HeaderPath string // location in the request header to put this flag's value + BodyPath string // location in the request body to put this flag's value + BodyRoot bool // if true, then use this value as the entire request body + PathParam string // name of the URL path parameter this flag's value maps to + + // Const, when true, marks this flag as a constant. The flag's Default value is used as the fixed value + // and always included in the request (IsSet returns true). The user can still see and override the flag, + // but isn't required to provide it. This is used for single-value enums and `x-stainless-const` + // parameters. + Const bool + + // FileInput, when true, indicates that the flag value is always treated as a file path. The file is read + // automatically without requiring the "@" prefix. This is used for parameters with `type: string, format: + // binary` in the OpenAPI spec. + FileInput bool + + // DataAliases is a list of alternate names for this parameter recognized when parsing piped YAML/JSON + // input. Values keyed by any alias are translated to the canonical API name before being sent. + DataAliases []string + + // unexported fields for internal use + count int // number of times the flag has been set + hasBeenSet bool // whether the flag has been set from env or file + applied bool // whether the flag has been applied to a flag set already + value cli.Value // value representing this flag's value +} + +// Type assertions to verify we implement the relevant urfave/cli interfaces +var _ cli.CategorizableFlag = (*Flag[any])(nil) + +// InRequest interface for flags that should be included in HTTP requests +type InRequest interface { + GetQueryPath() string + GetHeaderPath() string + GetBodyPath() string + GetPathParam() string + IsBodyRoot() bool + IsFileInput() bool + GetDataAliases() []string +} + +func (f Flag[T]) GetQueryPath() string { + return f.QueryPath +} + +func (f Flag[T]) GetHeaderPath() string { + return f.HeaderPath +} + +func (f Flag[T]) GetBodyPath() string { + return f.BodyPath +} + +func (f Flag[T]) GetPathParam() string { + return f.PathParam +} + +func (f Flag[T]) IsBodyRoot() bool { + return f.BodyRoot +} + +func (f Flag[T]) IsFileInput() bool { + return f.FileInput +} + +func (f Flag[T]) GetDataAliases() []string { + return f.DataAliases +} + +// The values that will be sent in different parts of a request. +type RequestContents struct { + Queries map[string]any + Headers map[string]any + Body any +} + +// ApplyStdinDataToFlags sets flag values from a parsed stdin data map for flags that have not already been +// set via the command line. This allows piped YAML/JSON data to satisfy path, query, and header parameters. +// Body parameters are excluded: they are already handled by the maps.Copy merge in flagOptions. +// For each unset flag, if the parsed data map contains a key matching the flag's QueryPath, HeaderPath, or +// PathParam (or any of its DataAliases), the flag is set to that value via flag.Set. +// +// Inner flags (those with an outer flag) are also handled: if the outer flag's body path key exists in the +// data map and contains a nested map with a key matching the inner flag's field (or aliases), the inner +// flag is set from that nested value. +func ApplyStdinDataToFlags(cmd *cli.Command, data map[string]any) error { + for _, flag := range cmd.Flags { + if flag.IsSet() { + continue + } + + // Handle inner flags: look for their value nested under the outer flag's body path. + if inner, ok := flag.(HasOuterFlag); ok { + outer, outerOk := inner.GetOuterFlag().(InRequest) + if !outerOk || outer.GetBodyPath() == "" { + continue + } + nested, ok := data[outer.GetBodyPath()].(map[string]any) + if !ok { + continue + } + innerField := inner.GetInnerField() + val, found := nested[innerField] + if !found { + for _, alias := range inner.GetDataAliases() { + if alias != "" && alias != innerField { + if v, ok := nested[alias]; ok { + val, found = v, true + break + } + } + } + } + if !found { + continue + } + setVal, err := formatForFlagSet(val) + if err != nil { + return fmt.Errorf("cannot format piped value for flag %q: %w", flag.Names()[0], err) + } + if err := flag.Set(flag.Names()[0], setVal); err != nil { + return fmt.Errorf("cannot set flag %q from piped data: %w", flag.Names()[0], err) + } + continue + } + + inReq, ok := flag.(InRequest) + if !ok { + continue + } + + // Try each request location in turn, checking the canonical path key and all aliases. + // Body params are excluded: they are already handled by the maps.Copy merge in flagOptions. + for _, path := range []string{inReq.GetQueryPath(), inReq.GetHeaderPath(), inReq.GetPathParam()} { + if path == "" { + continue + } + var val any + var found bool + for _, key := range append([]string{path}, inReq.GetDataAliases()...) { + if v, ok := data[key]; ok { + val, found = v, true + break + } + } + if !found { + continue + } + setVal, err := formatForFlagSet(val) + if err != nil { + return fmt.Errorf("cannot format piped value for flag %q: %w", flag.Names()[0], err) + } + if err := flag.Set(flag.Names()[0], setVal); err != nil { + return fmt.Errorf("cannot set flag %q from piped data: %w", flag.Names()[0], err) + } + break + } + } + return nil +} + +func ExtractRequestContents(cmd *cli.Command) RequestContents { + bodyMap := make(map[string]any) + res := RequestContents{ + Queries: make(map[string]any), + Headers: make(map[string]any), + Body: bodyMap, + } + + for _, flag := range cmd.Flags { + if !flag.IsSet() { + continue + } + + value := flag.Get() + if toSend, ok := flag.(InRequest); ok { + if queryPath := toSend.GetQueryPath(); queryPath != "" { + res.Queries[queryPath] = value + } + if headerPath := toSend.GetHeaderPath(); headerPath != "" { + res.Headers[headerPath] = value + } + if toSend.IsBodyRoot() { + res.Body = value + } else if bodyPath := toSend.GetBodyPath(); bodyPath != "" { + bodyMap[bodyPath] = value + } + } + } + return res +} + +func GetMissingRequiredFlags(cmd *cli.Command, body any) []cli.Flag { + missing := []cli.Flag{} + for _, flag := range cmd.Flags { + if flag.IsSet() { + continue + } + + if required, ok := flag.(cli.RequiredFlag); ok && required.IsRequired() { + missing = append(missing, flag) + continue + } + + if r, ok := flag.(RequiredFlagOrStdin); !ok || !r.IsRequiredAsFlagOrStdin() { + continue + } + + if toSend, ok := flag.(InRequest); ok { + if toSend.IsBodyRoot() { + if body != nil { + continue + } + } else if bodyPath := toSend.GetBodyPath(); bodyPath != "" { + if bodyMap, ok := body.(map[string]any); ok { + if _, found := bodyMap[bodyPath]; found { + continue + } + } + } + } + missing = append(missing, flag) + } + return missing +} + +// Implementation of the cli.Flag interface +var _ cli.Flag = (*Flag[any])(nil) // Type assertion to ensure interface compliance + +func (f *Flag[T]) PreParse() error { + newVal := f.Default + f.value = &cliValue[T]{newVal} + + // Validate the given default or values set from external sources as well + if f.Validator != nil { + if err := f.Validator(f.value.Get().(T)); err != nil { + return err + } + } + f.applied = true + return nil +} + +func (f *Flag[T]) PostParse() error { + if !f.hasBeenSet { + if val, source, found := f.Sources.LookupWithSource(); found { + if val != "" || reflect.TypeOf(f.value).Kind() == reflect.String { + if err := f.Set(f.Name, val); err != nil { + return fmt.Errorf( + "could not parse %[1]q as %[2]T value from %[3]s for flag %[4]s: %[5]s", + val, f.value, source, f.Name, err, + ) + } + } else if val == "" && reflect.TypeOf(f.value).Kind() == reflect.Bool { + _ = f.Set(f.Name, "false") + } + + f.hasBeenSet = true + } + } + return nil +} + +func (f *Flag[T]) Set(name string, val string) error { + // Initialize flag if needed + if !f.applied { + if err := f.PreParse(); err != nil { + return err + } + f.applied = true + } + + f.count++ + + // If this is the first time setting a slice type, reset it to empty + // to avoid appending to the default value + if f.count == 1 && f.value != nil { + typ := reflect.TypeOf(f.Default) + if typ != nil && typ.Kind() == reflect.Slice { + // Create a new empty slice of the same type and set it + emptySlice := reflect.MakeSlice(typ, 0, 0).Interface() + f.value = &cliValue[T]{emptySlice.(T)} + } + } + + if err := f.value.Set(val); err != nil { + return err + } + + f.hasBeenSet = true + + if f.Validator != nil { + if err := f.Validator(f.value.Get().(T)); err != nil { + return err + } + } + return nil +} + +func (f *Flag[T]) Get() any { + if f.value != nil { + return f.value.Get() + } + return f.Default +} + +func (f *Flag[T]) String() string { + return cli.FlagStringer(f) +} + +func (f *Flag[T]) IsSet() bool { + return f.hasBeenSet || f.Const +} + +func (f *Flag[T]) Names() []string { + return cli.FlagNames(f.Name, f.Aliases) +} + +// Implementation for the cli.VisibleFlag interface +var _ cli.VisibleFlag = (*Flag[any])(nil) // Type assertion to ensure interface compliance + +func (f *Flag[T]) IsVisible() bool { + return !f.Hidden +} + +func (f *Flag[T]) GetCategory() string { + return f.Category +} + +func (f *Flag[T]) SetCategory(c string) { + f.Category = c +} + +// Implementation for the cli.RequiredFlag interface +var _ cli.RequiredFlag = (*Flag[any])(nil) // Type assertion to ensure interface compliance + +func (f *Flag[T]) IsRequired() bool { + // Const flags are always auto-set, so never required from the user. + if f.Const { + return false + } + // Intentionally don't use `f.Required`, because request flags may be passed + // over stdin as well as by flag. + if f.BodyPath != "" || f.BodyRoot || f.PathParam != "" || f.QueryPath != "" || f.HeaderPath != "" { + return false + } + return f.Required +} + +type RequiredFlagOrStdin interface { + IsRequiredAsFlagOrStdin() bool +} + +func (f *Flag[T]) IsRequiredAsFlagOrStdin() bool { + // Const flags are always auto-set, so never required from the user. + if f.Const { + return false + } + return f.Required +} + +// Implementation for the cli.DocGenerationFlag interface +var _ cli.DocGenerationFlag = (*Flag[any])(nil) // Type assertion to ensure interface compliance + +func (f *Flag[T]) TakesValue() bool { + var t T + return reflect.TypeOf(t) == nil || reflect.TypeOf(t).Kind() != reflect.Bool +} + +func (f *Flag[T]) GetUsage() string { + return f.Usage +} + +func (f *Flag[T]) GetValue() string { + if f.value == nil { + return "" + } + return f.value.String() +} + +func (f *Flag[T]) GetDefaultText() string { + return f.DefaultText +} + +// GetEnvVars returns the env vars for this flag +func (f *Flag[T]) GetEnvVars() []string { + return f.Sources.EnvKeys() +} + +func (f *Flag[T]) IsDefaultVisible() bool { + return !f.HideDefault +} + +func (f *Flag[T]) TypeName() string { + ty := reflect.TypeOf(f.Default) + if ty == nil { + return "" + } + // Deref pointer-typed flags so --help surfaces the pointee kind (e.g. "string"), not + // Go's pointer syntax. + if ty.Kind() == reflect.Pointer { + ty = ty.Elem() + } + + // Get base type name with special handling for built-in types + getTypeName := func(t reflect.Type) string { + switch t.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, + reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return "int" + case reflect.Float32, reflect.Float64: + return "float" + case reflect.Bool: + return "boolean" + case reflect.String: + switch t.Name() { + case "DateTimeValue": + return "datetime" + case "DateValue": + return "date" + case "TimeValue": + return "time" + default: + return "string" + } + default: + if t.Name() == "" { + return "any" + } + return strings.ToLower(t.Name()) + } + } + + switch ty.Kind() { + case reflect.Slice: + elemType := ty.Elem() + return getTypeName(elemType) + case reflect.Map: + keyType := ty.Key() + valueType := ty.Elem() + return fmt.Sprintf("%s=%s", getTypeName(keyType), getTypeName(valueType)) + default: + return getTypeName(ty) + } +} + +// Implementation for the cli.DocGenerationMultiValueFlag interface +var _ cli.DocGenerationMultiValueFlag = (*Flag[any])(nil) // Type assertion to ensure interface compliance + +func (f *Flag[T]) IsMultiValueFlag() bool { + if reflect.TypeOf(f.Default) == nil { + return false + } + kind := reflect.TypeOf(f.Default).Kind() + return kind == reflect.Slice || kind == reflect.Map +} + +func (f *Flag[T]) IsBoolFlag() bool { + // Flag[*bool] is deliberately not treated as a bool flag — the pointer form needs an + // explicit value (`--foo true`, `--foo null`) to disambiguate the tri-state. + _, isBool := any(f.Default).(bool) + return isBool +} + +// Implementation for the cli.Countable interface +var _ cli.Countable = (*Flag[any])(nil) // Type assertion to ensure interface compliance + +func (f *Flag[T]) Count() int { + return f.count +} + +// Implementation for the cli.LocalFlag interface +var _ cli.LocalFlag = (*Flag[any])(nil) // Type assertion to ensure interface compliance + +func (f Flag[T]) IsLocal() bool { + // By default, all request flags are local, i.e. can be provided at any part of the CLI command. + return true +} + +// cliValue is a generic implementation of cli.Value for common types +type cliValue[ + T []any | []map[string]any | []DateTimeValue | []DateValue | []TimeValue | []string | []float64 | + []int64 | []bool | any | map[string]any | DateTimeValue | DateValue | TimeValue | string | + float64 | int64 | bool | + *string | *float64 | *int64 | *bool | *DateTimeValue | *DateValue | *TimeValue, +] struct { + value T +} + +// Take an argument string for a single argument and convert it into a typed +// value for one of the supported CLI argument types +func parseCLIArg[ + T []any | []map[string]any | []DateTimeValue | []DateValue | []TimeValue | []string | []float64 | + []int64 | []bool | any | map[string]any | DateTimeValue | DateValue | TimeValue | string | + float64 | int64 | bool | + *string | *float64 | *int64 | *bool | *DateTimeValue | *DateValue | *TimeValue, +](value string) (T, error) { + var parsedValue any + var err error + + var empty T + + if value == "null" { + switch any(empty).(type) { + // Pointer-to-primitive: explicit nil gives the tri-state its "null" state + // (unset / null / value). Without this, numeric flags would fail to parse + // "null" and string flags would accept the literal word as a raw value. + case *string, *int64, *float64, *bool, *DateValue, *DateTimeValue, *TimeValue: + return empty, nil + // Maps marshal nil as JSON null natively; short-circuit avoids a YAML round-trip. + case map[string]any: + return empty, nil + } + } + + switch any(empty).(type) { + case string: + parsedValue = value + case int64: + parsedValue, err = strconv.ParseInt(value, 0, 64) + case float64: + parsedValue, err = strconv.ParseFloat(value, 64) + case bool: + parsedValue, err = strconv.ParseBool(value) + case DateTimeValue: + var dt DateTimeValue + err = (&dt).Parse(value) + if err == nil { + parsedValue = dt + } + + case DateValue: + var d DateValue + err = (&d).Parse(value) + if err == nil { + parsedValue = d + } + + case TimeValue: + var t TimeValue + err = (&t).Parse(value) + if err == nil { + parsedValue = t + } + + // Pointer-to-primitive flags reach here only when `value != "null"`; we parse the + // pointee type and return its address so JSON marshaling emits the underlying value. + case *string: + v := value + parsedValue = &v + case *int64: + var v int64 + v, err = strconv.ParseInt(value, 0, 64) + if err == nil { + parsedValue = &v + } + case *float64: + var v float64 + v, err = strconv.ParseFloat(value, 64) + if err == nil { + parsedValue = &v + } + case *bool: + var v bool + v, err = strconv.ParseBool(value) + if err == nil { + parsedValue = &v + } + case *DateTimeValue: + var dt DateTimeValue + err = (&dt).Parse(value) + if err == nil { + parsedValue = &dt + } + case *DateValue: + var d DateValue + err = (&d).Parse(value) + if err == nil { + parsedValue = &d + } + case *TimeValue: + var t TimeValue + err = (&t).Parse(value) + if err == nil { + parsedValue = &t + } + + default: + if strings.HasPrefix(value, "@") { + // File literals like @file.txt should work here + parsedValue = value + } else { + var yamlValue T + err = yaml.Unmarshal([]byte(value), &yamlValue) + if err == nil { + parsedValue = yamlValue + } else if allowAsLiteralString(value) { + parsedValue = value + } else { + parsedValue = nil + err = fmt.Errorf("failed to parse as YAML: %w", err) + } + } + } + + // Nil needs to be handled specially because unmarshalling a YAML `null` + // causes problems when doing type assertions. + if parsedValue == nil { + parsedValue = (*struct{})(nil) + } + + if err == nil { + if typedValue, ok := parsedValue.(T); ok { + return typedValue, nil + } else { + expectedType := reflect.TypeFor[T]() + err = fmt.Errorf("Couldn't convert %q (%v) to expected type %v", value, parsedValue, expectedType) + } + } + return empty, err + +} + +// Ptr returns a pointer to its argument. It is used to initialize `Default` on pointer-typed +// Flag values, since Go does not allow taking the address of a composite literal's element +// or of an untyped constant. +func Ptr[T any](v T) *T { + return &v +} + +// Assuming this string failed to parse as valid YAML, this function will +// return true for strings that can reasonably be interpreted as a string literal, +// like identifiers (`foo_bar`), UUIDs (`945b2f0c-8e89-487a-b02c-f851c69ea459`), +// base64 (`aGVsbG8=`), and qualified identifiers (`color.Red`). This should +// not include strings that look like mistyped YAML (e.g. `{key:`) +func allowAsLiteralString(s string) bool { + for _, c := range s { + if !unicode.IsLetter(c) && !unicode.IsDigit(c) && + c != '_' && c != '-' && c != '.' && c != '=' { + return false + } + } + return true +} + +// Parse the input string and set result as the cliValue's value +func (c *cliValue[T]) Set(value string) error { + valueType := reflect.TypeOf(c.value) + // When setting slice values, we append to the existing values + // e.g. --foo 10 --foo 20 --foo 30 => [10, 20, 30] + if valueType != nil && valueType.Kind() == reflect.Slice { + elemType := valueType.Elem() + + var singleElem any + var err error + switch elemType.Kind() { + case reflect.String: + singleElem, err = parseCLIArg[string](value) + case reflect.Int64: + singleElem, err = parseCLIArg[int64](value) + case reflect.Float64: + singleElem, err = parseCLIArg[float64](value) + case reflect.Bool: + singleElem, err = parseCLIArg[bool](value) + default: + // Check for special types by name + switch elemType.Name() { + case "DateTimeValue": + singleElem, err = parseCLIArg[DateTimeValue](value) + case "DateValue": + singleElem, err = parseCLIArg[DateValue](value) + case "TimeValue": + singleElem, err = parseCLIArg[TimeValue](value) + default: + // This handles []map[string]any + if elemType.Kind() == reflect.Map && elemType.Key().Kind() == reflect.String { + singleElem, err = parseCLIArg[map[string]any](value) + } else { + singleElem, err = parseCLIArg[any](value) + } + } + } + + if err != nil { + return err + } + + // Append the new element to the slice + sliceValue := reflect.ValueOf(c.value) + if !sliceValue.IsValid() || sliceValue.IsNil() { + // Create a new slice if the current one is nil + sliceValue = reflect.MakeSlice(valueType, 0, 1) + } + + // Append the new element + newElem := reflect.ValueOf(singleElem) + sliceValue = reflect.Append(sliceValue, newElem) + + // Set the updated slice back to c.value + c.value = sliceValue.Interface().(T) + } else { + // For non-slice types, simply parse and set the value + if parsedValue, err := parseCLIArg[T](value); err != nil { + return err + } else { + c.value = parsedValue + } + } + + return nil +} + +func (c *cliValue[T]) Get() any { + return c.value +} + +func (c *cliValue[T]) String() string { + switch v := any(c.value).(type) { + case string, int, int64, float64, bool, DateTimeValue, DateValue, TimeValue, + []string, []int, []int64, []float64, []bool, []DateTimeValue, []DateValue, []TimeValue: + // For basic types, use standard string representation + return fmt.Sprintf("%v", v) + + case *string, *int64, *float64, *bool, *DateTimeValue, *DateValue, *TimeValue: + // Pointer-to-primitive: nil renders as "null" (the CLI literal that produces it); + // non-nil derefs to the pointee's standard representation. + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "null" + } + return fmt.Sprintf("%v", rv.Elem().Interface()) + + default: + // For complex types, convert to YAML + yamlBytes, err := yaml.MarshalWithOptions(c.value, yaml.Flow(true)) + if err != nil { + // Fall back to standard format if YAML conversion fails + return fmt.Sprintf("%v", c.value) + } + return string(yamlBytes) + } +} + +func (c *cliValue[T]) IsBoolFlag() bool { + _, ok := any(c.value).(bool) + return ok +} + +// Time-related value types +type DateValue string +type DateTimeValue string +type TimeValue string + +// String methods for time-related types +func (d DateValue) String() string { + return string(d) +} + +func (d DateTimeValue) String() string { + return string(d) +} + +func (t TimeValue) String() string { + return string(t) +} + +// parseTimeWithFormats attempts to parse a string using multiple formats +func parseTimeWithFormats(s string, formats []string) (time.Time, error) { + var lastErr error + for _, format := range formats { + t, err := time.Parse(format, s) + if err == nil { + return t, nil + } + lastErr = err + } + return time.Time{}, lastErr +} + +// Parse methods for time-related types +func (d *DateValue) Parse(s string) error { + formats := []string{ + "2006-01-02", + "01/02/2006", + "Jan 2, 2006", + "January 2, 2006", + "2-Jan-2006", + } + + t, err := parseTimeWithFormats(s, formats) + if err != nil { + return fmt.Errorf("unable to parse date: %v", err) + } + + *d = DateValue(t.Format("2006-01-02")) + return nil +} + +func (d *DateTimeValue) Parse(s string) error { + formats := []string{ + time.RFC3339, + time.RFC3339Nano, + "2006-01-02T15:04:05", + "2006-01-02 15:04:05", + time.RFC1123, + time.RFC822, + time.ANSIC, + } + + t, err := parseTimeWithFormats(s, formats) + if err != nil { + return fmt.Errorf("unable to parse datetime: %v", err) + } + + *d = DateTimeValue(t.Format(time.RFC3339)) + return nil +} + +func (t *TimeValue) Parse(s string) error { + formats := []string{ + "15:04:05", + "15:04:05.999999999Z07:00", + "3:04:05PM", + "3:04 PM", + "15:04", + time.Kitchen, + } + + parsedTime, err := parseTimeWithFormats(s, formats) + if err != nil { + return fmt.Errorf("unable to parse time: %v", err) + } + + *t = TimeValue(parsedTime.Format("15:04:05")) + return nil +} + +// Allow setting inner fields on other flags (e.g. --foo.baz can set the "baz" +// field on the --foo flag) +type SettableInnerField interface { + SetInnerField(string, any) +} + +// InnerFieldSeeder lets an InnerFlag prepare its outer flag's underlying value +// before dispatching SetInnerField. This is only meaningful for Flag[any] — +// the codegen output for nullable complex schemas — whose untyped-nil zero +// value would otherwise have no reflect.Kind for the inner-field switch to +// dispatch on. +type InnerFieldSeeder interface { + SeedInnerCollection(isArrayOfObjects bool) +} + +func (f *Flag[T]) SetInnerField(field string, val any) { + if f.value == nil { + f.value = &cliValue[T]{} + } + + if settableInnerField, ok := f.value.(SettableInnerField); ok { + settableInnerField.SetInnerField(field, val) + f.hasBeenSet = true + } else { + panic(fmt.Sprintf("Cannot set inner field: %v", f.value)) + } +} + +// SeedInnerCollection initializes a Flag[any]'s underlying value as an empty +// map[string]any or []map[string]any so subsequent SetInnerField calls have a +// dispatchable reflect.Kind. For typed Flag[T] this is a no-op: the type +// assertion fails and the existing reflect.Kind on the typed-nil zero value +// already routes correctly. +func (f *Flag[T]) SeedInnerCollection(isArrayOfObjects bool) { + if f.value == nil { + f.value = &cliValue[T]{} + } + cv, ok := f.value.(*cliValue[T]) + if !ok { + return + } + if reflect.ValueOf(cv.value).Kind() != reflect.Invalid { + return + } + if isArrayOfObjects { + if seed, ok := any([]map[string]any{}).(T); ok { + cv.value = seed + } + return + } + if seed, ok := any(map[string]any{}).(T); ok { + cv.value = seed + } +} + +func (c *cliValue[T]) SetInnerField(field string, val any) { + flagVal := c.value + flagValReflect := reflect.ValueOf(flagVal) + switch flagValReflect.Kind() { + case reflect.Slice: + if flagValReflect.Type().Elem().Kind() != reflect.Map { + return + } + + sliceLen := flagValReflect.Len() + if sliceLen > 0 { + // Check if the last element already has the InnerField + lastElement := flagValReflect.Index(sliceLen - 1).Interface().(map[string]any) + if _, hasInnerField := lastElement[field]; !hasInnerField { + // Last element doesn't have the field, set it + lastElement[field] = val + return + } + } + + // Create a new map and append it to the slice + newMap := map[string]any{field: val} + switch sliceVal := any(c.value).(type) { + case []map[string]any: + c.value = any(append(sliceVal, newMap)).(T) + case []any: + c.value = any(append(sliceVal, newMap)).(T) + } + + case reflect.Map: + mapVal, ok := any(flagVal).(map[string]any) + if !ok || mapVal == nil { + mapVal = map[string]any{field: val} + c.value = any(mapVal).(T) + } else { + mapVal[field] = val + } + } +} diff --git a/internal/requestflag/requestflag_test.go b/internal/requestflag/requestflag_test.go new file mode 100644 index 0000000..779bd57 --- /dev/null +++ b/internal/requestflag/requestflag_test.go @@ -0,0 +1,1227 @@ +package requestflag + +import ( + "encoding/json" + "fmt" + "testing" + "time" + + "github.com/goccy/go-yaml" + "github.com/stretchr/testify/assert" + "github.com/urfave/cli/v3" +) + +func TestDateValueParse(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + input string + want string + wantErr bool + }{ + { + name: "ISO format", + input: "2023-05-15", + want: "2023-05-15", + wantErr: false, + }, + { + name: "US format", + input: "05/15/2023", + want: "2023-05-15", + wantErr: false, + }, + { + name: "Short month format", + input: "May 15, 2023", + want: "2023-05-15", + wantErr: false, + }, + { + name: "Long month format", + input: "January 15, 2023", + want: "2023-01-15", + wantErr: false, + }, + { + name: "British format", + input: "15-Jan-2023", + want: "2023-01-15", + wantErr: false, + }, + { + name: "Invalid format", + input: "not a date", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var d DateValue + err := d.Parse(tt.input) + + if tt.wantErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.want, d.String()) + } + }) + } +} + +func TestDateTimeValueParse(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + input string + wantErr bool + }{ + { + name: "RFC3339", + input: "2023-05-15T14:30:45Z", + wantErr: false, + }, + { + name: "ISO with timezone", + input: "2023-05-15T14:30:45+02:00", + wantErr: false, + }, + { + name: "ISO without timezone", + input: "2023-05-15T14:30:45", + wantErr: false, + }, + { + name: "Space separated", + input: "2023-05-15 14:30:45", + wantErr: false, + }, + { + name: "RFC1123", + input: "Mon, 15 May 2023 14:30:45 GMT", + wantErr: false, + }, + { + name: "RFC822", + input: "15 May 23 14:30 GMT", + wantErr: false, + }, + { + name: "ANSIC", + input: "Mon Jan 2 15:04:05 2006", + wantErr: false, + }, + { + name: "Invalid format", + input: "not a datetime", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var d DateTimeValue + err := d.Parse(tt.input) + + if tt.wantErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + + // Parse the string back to ensure it's valid RFC3339 + _, parseErr := time.Parse(time.RFC3339, d.String()) + assert.NoError(t, parseErr) + } + }) + } +} + +func TestTimeValueParse(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + input string + want string + wantErr bool + }{ + { + name: "24-hour format", + input: "14:30:45", + want: "14:30:45", + wantErr: false, + }, + { + name: "12-hour format with seconds", + input: "2:30:45PM", + want: "14:30:45", + wantErr: false, + }, + { + name: "12-hour format without seconds", + input: "2:30 PM", + want: "14:30:00", + wantErr: false, + }, + { + name: "24-hour without seconds", + input: "14:30", + want: "14:30:00", + wantErr: false, + }, + { + name: "Kitchen format", + input: "2:30PM", + want: "14:30:00", + wantErr: false, + }, + { + name: "Invalid format", + input: "not a time", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + var tv TimeValue + err := tv.Parse(tt.input) + + if tt.wantErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.want, tv.String()) + } + }) + } +} + +func TestRequestParams(t *testing.T) { + t.Parallel() + + t.Run("map body type", func(t *testing.T) { + t.Parallel() + + // Create a mock command with flags + cmd := &cli.Command{ + Name: "test", + } + + // Create string flag with body path + stringFlag := &Flag[string]{ + Name: "string-flag", + Default: "default-string", + BodyPath: "string_field", + value: &cliValue[string]{value: "test-value"}, + hasBeenSet: true, + } + + // Create int flag with header path + intFlag := &Flag[int64]{ + Name: "int-flag", + Default: 42, + HeaderPath: "X-Int-Value", + value: &cliValue[int64]{value: 99}, + hasBeenSet: true, + } + + // Create bool flag with query path + boolFlag := &Flag[bool]{ + Name: "bool-flag", + Default: false, + QueryPath: "include_details", + value: &cliValue[bool]{value: true}, + hasBeenSet: true, + } + + // Create date flag with multiple paths + dateFlag := &Flag[DateValue]{ + Name: "date-flag", + Default: DateValue("2023-01-01"), + BodyPath: "effective_date", + HeaderPath: "X-Effective-Date", + QueryPath: "as_of_date", + value: &cliValue[DateValue]{value: DateValue("2023-05-15")}, + hasBeenSet: true, + } + + // Create flag with no path + noPathFlag := &Flag[string]{ + Name: "no-path-flag", + Default: "no-path", + value: &cliValue[string]{value: "no-path-value"}, + hasBeenSet: true, + } + + // Create unset flag + unsetFlag := &Flag[string]{ + Name: "unset-flag", + Default: "unset", + BodyPath: "should_not_appear", + value: &cliValue[string]{value: "unset-value"}, + hasBeenSet: false, + } + + cmd.Flags = []cli.Flag{stringFlag, intFlag, boolFlag, dateFlag, noPathFlag, unsetFlag} + + // Test the RequestParams function + contents := ExtractRequestContents(cmd) + + // Verify query parameters + assert.Equal(t, true, contents.Queries["include_details"]) + assert.Equal(t, DateValue("2023-05-15"), contents.Queries["as_of_date"]) + assert.Len(t, contents.Queries, 2) + + // Verify headers + assert.Equal(t, int64(99), contents.Headers["X-Int-Value"]) + assert.Equal(t, DateValue("2023-05-15"), contents.Headers["X-Effective-Date"]) + assert.Len(t, contents.Headers, 2) + + // Verify body + bodyMap, ok := contents.Body.(map[string]any) + assert.True(t, ok, "Expected body to be map[string]any, got %T", contents.Body) + assert.Equal(t, "test-value", bodyMap["string_field"]) + assert.Equal(t, DateValue("2023-05-15"), bodyMap["effective_date"]) + assert.Len(t, bodyMap, 2) + + // Verify the unset flag didn't make it into the maps + assert.NotContains(t, contents.Body, "should_not_appear") + }) + + t.Run("non-map body type", func(t *testing.T) { + t.Parallel() + + // Create a mock command with flags + cmd := &cli.Command{ + Name: "test", + Flags: []cli.Flag{ + &Flag[int64]{ + Name: "int-body-flag", + Default: 0, + BodyRoot: true, + }, + }, + } + cmd.Set("int-body-flag", "42") + + contents := ExtractRequestContents(cmd) + intBody, ok := contents.Body.(int64) + assert.True(t, ok, "Expected body to be int64, got %T", contents.Body) + assert.Equal(t, int64(42), intBody) + }) +} + +func TestFlagSet(t *testing.T) { + t.Parallel() + + strFlag := &Flag[string]{ + Name: "string-flag", + Default: "default-string", + } + + superstitiousIntFlag := &Flag[int64]{ + Name: "int-flag", + Default: 42, + Validator: func(val int64) error { + if val == 13 { + return fmt.Errorf("Unlucky number!") + } + return nil + }, + } + + boolFlag := &Flag[bool]{ + Name: "bool-flag", + Default: false, + } + + // Test initialization and setting + t.Run("PreParse initialization", func(t *testing.T) { + t.Parallel() + + assert.NoError(t, strFlag.PreParse()) + assert.True(t, strFlag.applied) + assert.Equal(t, "default-string", strFlag.Get()) + }) + + t.Run("Set string flag", func(t *testing.T) { + t.Parallel() + + assert.NoError(t, strFlag.Set("string-flag", "new-value")) + assert.Equal(t, "new-value", strFlag.Get()) + assert.True(t, strFlag.IsSet()) + }) + + t.Run("Set int flag with valid value", func(t *testing.T) { + t.Parallel() + + assert.NoError(t, superstitiousIntFlag.Set("int-flag", "100")) + assert.Equal(t, int64(100), superstitiousIntFlag.Get()) + assert.True(t, superstitiousIntFlag.IsSet()) + }) + + t.Run("Set int flag with invalid value", func(t *testing.T) { + t.Parallel() + + assert.Error(t, superstitiousIntFlag.Set("int-flag", "not-an-int")) + }) + + t.Run("Set int flag with validator failing", func(t *testing.T) { + t.Parallel() + + assert.Error(t, superstitiousIntFlag.Set("int-flag", "13")) + }) + + t.Run("Set bool flag", func(t *testing.T) { + t.Parallel() + + assert.NoError(t, boolFlag.Set("bool-flag", "true")) + assert.Equal(t, true, boolFlag.Get()) + assert.True(t, boolFlag.IsSet()) + }) + + t.Run("Set slice flag with multiple values", func(t *testing.T) { + t.Parallel() + + sliceFlag := &Flag[[]int64]{ + Name: "slice-flag", + Default: []int64{}, + } + + // Initialize the flag + assert.NoError(t, sliceFlag.PreParse()) + + // First set + assert.NoError(t, sliceFlag.Set("slice-flag", "10")) + + // Subsequent setting should append, not replace + assert.NoError(t, sliceFlag.Set("slice-flag", "20")) + assert.NoError(t, sliceFlag.Set("slice-flag", "30")) + + // Verify that we have both values in the slice + result := sliceFlag.Get() + assert.Equal(t, []int64{10, 20, 30}, result) + assert.True(t, sliceFlag.IsSet()) + }) + + t.Run("Set slice flag with a nonempty default", func(t *testing.T) { + t.Parallel() + + sliceFlag := &Flag[[]int64]{ + Name: "slice-flag", + Default: []int64{99, 100}, + } + + assert.NoError(t, sliceFlag.PreParse()) + assert.NoError(t, sliceFlag.Set("slice-flag", "10")) + assert.NoError(t, sliceFlag.Set("slice-flag", "20")) + assert.NoError(t, sliceFlag.Set("slice-flag", "30")) + + // Verify that we have clobbered the default value instead of appending + // to it. + result := sliceFlag.Get() + assert.Equal(t, []int64{10, 20, 30}, result) + assert.True(t, sliceFlag.IsSet()) + }) +} + +func TestParseTimeWithFormats(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + input string + formats []string + wantTime time.Time + wantErr bool + }{ + { + name: "RFC3339 format", + input: "2023-05-15T14:30:45Z", + formats: []string{time.RFC3339}, + wantTime: time.Date(2023, 5, 15, 14, 30, 45, 0, time.UTC), + wantErr: false, + }, + { + name: "Multiple formats - first matches", + input: "2023-05-15", + formats: []string{"2006-01-02", time.RFC3339}, + wantTime: time.Date(2023, 5, 15, 0, 0, 0, 0, time.UTC), + wantErr: false, + }, + { + name: "Multiple formats - second matches", + input: "15/05/2023", + formats: []string{"2006-01-02", "02/01/2006"}, + wantTime: time.Date(2023, 5, 15, 0, 0, 0, 0, time.UTC), + wantErr: false, + }, + { + name: "No matching format", + input: "not a date", + formats: []string{"2006-01-02", time.RFC3339}, + wantTime: time.Time{}, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + got, err := parseTimeWithFormats(tt.input, tt.formats) + + if tt.wantErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.True(t, tt.wantTime.Equal(got), "Expected %v, got %v", tt.wantTime, got) + } + }) + } +} + +func TestYamlHandling(t *testing.T) { + t.Parallel() + + // Test with any value + t.Run("Parse YAML to any", func(t *testing.T) { + t.Parallel() + + cv := &cliValue[any]{} + err := cv.Set("name: test\nvalue: 42\n") + assert.NoError(t, err) + + // The value should be a map + val, ok := cv.Get().(map[string]any) + assert.True(t, ok, "Expected map[string]any, got %T", cv.Get()) + + if ok { + assert.Equal(t, "test", val["name"]) + assert.Equal(t, uint64(42), val["value"]) + } + + // The string representation should be valid YAML + strVal := cv.String() + var parsed map[string]any + err = yaml.Unmarshal([]byte(strVal), &parsed) + assert.NoError(t, err) + assert.Equal(t, "test", parsed["name"]) + assert.Equal(t, uint64(42), parsed["value"]) + }) + + // Test with array + t.Run("Parse YAML array", func(t *testing.T) { + t.Parallel() + + cv := &cliValue[any]{} + err := cv.Set("- item1\n- item2\n- item3\n") + assert.NoError(t, err) + + // The value should be a slice + val, ok := cv.Get().([]any) + assert.True(t, ok, "Expected []any, got %T", cv.Get()) + + if ok { + assert.Len(t, val, 3) + assert.Equal(t, "item1", val[0]) + assert.Equal(t, "item2", val[1]) + assert.Equal(t, "item3", val[2]) + } + }) + + t.Run("Parse @file.txt as YAML", func(t *testing.T) { + t.Parallel() + + flag := &Flag[any]{ + Name: "file-flag", + Default: nil, + } + assert.NoError(t, flag.PreParse()) + assert.NoError(t, flag.Set("file-flag", "@file.txt")) + + val := flag.Get() + assert.Equal(t, "@file.txt", val) + }) + + t.Run("Parse @file.txt list as YAML", func(t *testing.T) { + t.Parallel() + + flag := &Flag[[]any]{ + Name: "file-flag", + Default: nil, + } + assert.NoError(t, flag.PreParse()) + assert.NoError(t, flag.Set("file-flag", "@file1.txt")) + assert.NoError(t, flag.Set("file-flag", "@file2.txt")) + + val := flag.Get() + assert.Equal(t, []any{"@file1.txt", "@file2.txt"}, val) + }) + + t.Run("Parse identifiers as YAML", func(t *testing.T) { + t.Parallel() + + tests := []string{ + "hello", + "e4e355fa-b03b-4c57-a73d-25c9733eec79", + "foo_bar", + "Color.Red", + "aGVsbG8=", + } + for _, test := range tests { + flag := &Flag[any]{ + Name: "flag", + Default: nil, + } + assert.NoError(t, flag.PreParse()) + assert.NoError(t, flag.Set("flag", test)) + + val := flag.Get() + assert.Equal(t, test, val) + } + + for _, test := range tests { + flag := &Flag[[]any]{ + Name: "identifier", + Default: nil, + } + assert.NoError(t, flag.PreParse()) + assert.NoError(t, flag.Set("identifier", test)) + assert.NoError(t, flag.Set("identifier", test)) + + val := flag.Get() + assert.Equal(t, []any{test, test}, val) + } + }) + + // Test with invalid YAML + t.Run("Parse invalid YAML", func(t *testing.T) { + t.Parallel() + + invalidYaml := `[not closed` + cv := &cliValue[any]{} + err := cv.Set(invalidYaml) + assert.Error(t, err) + }) +} + +// TestNullLiteralHandling pins how each Flag[T] type handles the literal value "null" +// when passed via the CLI. Pointer-typed flags serialize nil as JSON null, which is how +// nullable body fields (`anyOf: [T, null]` / `{nullable: true}`) let users clear a field +// via `--foo null`. Non-pointer primitive flags treat "null" as a raw value — these are +// non-nullable schemas where explicit null has no API semantics anyway. +func TestNullLiteralHandling(t *testing.T) { + t.Parallel() + + assertJSONBody := func(t *testing.T, value any, expected string) { + t.Helper() + body, err := json.Marshal(map[string]any{"foo": value}) + assert.NoError(t, err) + assert.JSONEq(t, expected, string(body)) + } + + t.Run("Flag[any] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[any]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) + + t.Run("Flag[string] null is the raw string \"null\"", func(t *testing.T) { + t.Parallel() + cv := &cliValue[string]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":"null"}`) + }) + + t.Run("Flag[int64] null errors", func(t *testing.T) { + t.Parallel() + cv := &cliValue[int64]{} + assert.Error(t, cv.Set("null")) + }) + + t.Run("Flag[*string] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*string]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) + + t.Run("Flag[*string] value sends the string", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*string]{} + assert.NoError(t, cv.Set("1.1")) + assertJSONBody(t, cv.Get(), `{"foo":"1.1"}`) + }) + + t.Run("Flag[*int64] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*int64]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) + + t.Run("Flag[*int64] value sends the integer", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*int64]{} + assert.NoError(t, cv.Set("42")) + assertJSONBody(t, cv.Get(), `{"foo":42}`) + }) + + t.Run("Flag[*int64] invalid value errors", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*int64]{} + assert.Error(t, cv.Set("not-an-int")) + }) + + t.Run("Flag[*bool] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*bool]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) + + t.Run("Flag[*bool] value sends the boolean", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*bool]{} + assert.NoError(t, cv.Set("true")) + assertJSONBody(t, cv.Get(), `{"foo":true}`) + }) + + t.Run("Flag[*float64] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*float64]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) + + t.Run("Flag[*float64] value sends the float", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*float64]{} + assert.NoError(t, cv.Set("1.5")) + assertJSONBody(t, cv.Get(), `{"foo":1.5}`) + }) + + t.Run("Flag[*float64] invalid value errors", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*float64]{} + assert.Error(t, cv.Set("not-a-float")) + }) + + t.Run("Flag[*DateValue] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*DateValue]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) + + t.Run("Flag[*DateValue] value sends the date", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*DateValue]{} + assert.NoError(t, cv.Set("2023-05-15")) + assertJSONBody(t, cv.Get(), `{"foo":"2023-05-15"}`) + }) + + t.Run("Flag[*DateValue] invalid value errors", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*DateValue]{} + assert.Error(t, cv.Set("not-a-date")) + }) + + t.Run("Flag[*DateTimeValue] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*DateTimeValue]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) + + t.Run("Flag[*DateTimeValue] value sends the datetime", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*DateTimeValue]{} + assert.NoError(t, cv.Set("2023-05-15T14:30:45Z")) + assertJSONBody(t, cv.Get(), `{"foo":"2023-05-15T14:30:45Z"}`) + }) + + t.Run("Flag[*DateTimeValue] invalid value errors", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*DateTimeValue]{} + assert.Error(t, cv.Set("not-a-datetime")) + }) + + t.Run("Flag[*TimeValue] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*TimeValue]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) + + t.Run("Flag[*TimeValue] value sends the time", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*TimeValue]{} + assert.NoError(t, cv.Set("14:30:45")) + assertJSONBody(t, cv.Get(), `{"foo":"14:30:45"}`) + }) + + t.Run("Flag[*TimeValue] invalid value errors", func(t *testing.T) { + t.Parallel() + cv := &cliValue[*TimeValue]{} + assert.Error(t, cv.Set("not-a-time")) + }) + + // Nullable maps don't need pointer wrapping — a nil map already marshals as JSON null. + t.Run("Flag[map[string]any] null sends JSON null", func(t *testing.T) { + t.Parallel() + cv := &cliValue[map[string]any]{} + assert.NoError(t, cv.Set("null")) + assertJSONBody(t, cv.Get(), `{"foo":null}`) + }) +} + +func TestFlagTypeNames(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + flag cli.DocGenerationFlag + expected string + }{ + {"string", &Flag[string]{}, "string"}, + {"int64", &Flag[int64]{}, "int"}, + {"float64", &Flag[float64]{}, "float"}, + {"bool", &Flag[bool]{}, "boolean"}, + {"string slice", &Flag[[]string]{}, "string"}, + {"date", &Flag[DateValue]{}, "date"}, + {"datetime", &Flag[DateTimeValue]{}, "datetime"}, + {"time", &Flag[TimeValue]{}, "time"}, + {"date slice", &Flag[[]DateValue]{}, "date"}, + {"datetime slice", &Flag[[]DateTimeValue]{}, "datetime"}, + {"time slice", &Flag[[]TimeValue]{}, "time"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + typeName := tt.flag.TypeName() + assert.Equal(t, tt.expected, typeName, "Expected type name %q, got %q", tt.expected, typeName) + }) + } +} + +// TestInnerFlagDispatchOnUntypedFlag pins inner-flag behavior for `Flag[any]`, +// which is the codegen output for nullable complex schemas (`anyOf: [T, null]` +// or `{nullable: true}`). The untyped-nil zero value carries no reflect.Kind, +// so SetInnerField has nowhere to dispatch the assignment — without explicit +// help the inner-field value silently drops. +func TestInnerFlagDispatchOnUntypedFlag(t *testing.T) { + t.Parallel() + + t.Run("nullable array of objects appends element from inner flag", func(t *testing.T) { + t.Parallel() + outer := &Flag[any]{Name: "mcp-server"} + assert.NoError(t, outer.PreParse()) + + nameFlag := &InnerFlag[string]{ + Name: "mcp-server.name", InnerField: "name", + OuterFlag: outer, OuterIsArrayOfObjects: true, + } + assert.NoError(t, nameFlag.Set("mcp-server.name", "first")) + + body, err := json.Marshal(map[string]any{"foo": outer.Get()}) + assert.NoError(t, err) + assert.JSONEq(t, `{"foo":[{"name":"first"}]}`, string(body)) + }) + + t.Run("nullable object sets field from inner flag", func(t *testing.T) { + t.Parallel() + outer := &Flag[any]{Name: "metadata"} + assert.NoError(t, outer.PreParse()) + + keyFlag := &InnerFlag[string]{ + Name: "metadata.key", InnerField: "key", OuterFlag: outer, + } + assert.NoError(t, keyFlag.Set("metadata.key", "value")) + + body, err := json.Marshal(map[string]any{"foo": outer.Get()}) + assert.NoError(t, err) + assert.JSONEq(t, `{"foo":{"key":"value"}}`, string(body)) + }) + + t.Run("multiple inner flags merge into the trailing element", func(t *testing.T) { + t.Parallel() + outer := &Flag[any]{Name: "mcp-server"} + assert.NoError(t, outer.PreParse()) + + nameFlag := &InnerFlag[string]{ + Name: "mcp-server.name", InnerField: "name", + OuterFlag: outer, OuterIsArrayOfObjects: true, + } + urlFlag := &InnerFlag[string]{ + Name: "mcp-server.url", InnerField: "url", + OuterFlag: outer, OuterIsArrayOfObjects: true, + } + assert.NoError(t, nameFlag.Set("mcp-server.name", "first")) + assert.NoError(t, urlFlag.Set("mcp-server.url", "https://example.com")) + + body, err := json.Marshal(map[string]any{"foo": outer.Get()}) + assert.NoError(t, err) + assert.JSONEq(t, `{"foo":[{"name":"first","url":"https://example.com"}]}`, string(body)) + }) +} + +func TestApplyStdinDataToFlags(t *testing.T) { + t.Parallel() + + t.Run("sets query path flag from piped data", func(t *testing.T) { + t.Parallel() + + flag := &Flag[string]{ + Name: "account-id", + QueryPath: "account_id", + } + assert.NoError(t, flag.PreParse()) + + data := map[string]any{"account_id": "acct_123"} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.True(t, flag.IsSet()) + assert.Equal(t, "acct_123", flag.Get()) + }) + + t.Run("sets header path flag from piped data", func(t *testing.T) { + t.Parallel() + + flag := &Flag[string]{ + Name: "idempotency-key", + HeaderPath: "Idempotency-Key", + } + assert.NoError(t, flag.PreParse()) + + data := map[string]any{"Idempotency-Key": "key-xyz"} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.True(t, flag.IsSet()) + assert.Equal(t, "key-xyz", flag.Get()) + }) + + t.Run("does not set body path flag from piped data", func(t *testing.T) { + t.Parallel() + + // Body params are handled by the maps.Copy merge in flagOptions, not by ApplyStdinDataToFlags. + flag := &Flag[string]{ + Name: "message", + BodyPath: "message", + } + assert.NoError(t, flag.PreParse()) + + data := map[string]any{"message": "hello world"} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.False(t, flag.IsSet()) + }) + + t.Run("does not override flag already set via CLI", func(t *testing.T) { + t.Parallel() + + flag := &Flag[string]{ + Name: "account-id", + QueryPath: "account_id", + } + assert.NoError(t, flag.PreParse()) + assert.NoError(t, flag.Set("account-id", "explicit_value")) + + data := map[string]any{"account_id": "piped_value"} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + // The explicitly-set value should win. + assert.Equal(t, "explicit_value", flag.Get()) + }) + + t.Run("sets integer query flag from piped data", func(t *testing.T) { + t.Parallel() + + flag := &Flag[int64]{ + Name: "page-size", + QueryPath: "page_size", + } + assert.NoError(t, flag.PreParse()) + + data := map[string]any{"page_size": int64(50)} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.True(t, flag.IsSet()) + assert.Equal(t, int64(50), flag.Get()) + }) + + t.Run("sets boolean query flag from piped data", func(t *testing.T) { + t.Parallel() + + flag := &Flag[bool]{ + Name: "include-deleted", + QueryPath: "include_deleted", + } + assert.NoError(t, flag.PreParse()) + + data := map[string]any{"include_deleted": true} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.True(t, flag.IsSet()) + assert.Equal(t, true, flag.Get()) + }) + + t.Run("resolves query path flag via data alias", func(t *testing.T) { + t.Parallel() + + flag := &Flag[string]{ + Name: "account-id", + QueryPath: "account_id", + DataAliases: []string{"accountId", "account"}, + } + assert.NoError(t, flag.PreParse()) + + // Use one of the aliases as the key in piped data. + data := map[string]any{"accountId": "acct_alias"} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.True(t, flag.IsSet()) + assert.Equal(t, "acct_alias", flag.Get()) + }) + + t.Run("does not set body path flag via data alias", func(t *testing.T) { + t.Parallel() + + // Body params are handled by the maps.Copy merge in flagOptions, not by ApplyStdinDataToFlags. + flag := &Flag[string]{ + Name: "user-name", + BodyPath: "user_name", + DataAliases: []string{"userName", "username"}, + } + assert.NoError(t, flag.PreParse()) + + data := map[string]any{"userName": "alice"} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.False(t, flag.IsSet()) + }) + + t.Run("ignores flags with no matching key in piped data", func(t *testing.T) { + t.Parallel() + + flag := &Flag[string]{ + Name: "account-id", + QueryPath: "account_id", + } + assert.NoError(t, flag.PreParse()) + + data := map[string]any{"other_key": "value"} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.False(t, flag.IsSet()) + }) + + t.Run("ignores flags with no path set", func(t *testing.T) { + t.Parallel() + + flag := &Flag[string]{ + Name: "some-flag", + // No QueryPath, HeaderPath, or BodyPath + } + assert.NoError(t, flag.PreParse()) + + data := map[string]any{"some-flag": "value"} + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.False(t, flag.IsSet()) + }) + + t.Run("handles multiple flags from piped data", func(t *testing.T) { + t.Parallel() + + accountFlag := &Flag[string]{ + Name: "account-id", + QueryPath: "account_id", + } + limitFlag := &Flag[int64]{ + Name: "limit", + QueryPath: "limit", + } + assert.NoError(t, accountFlag.PreParse()) + assert.NoError(t, limitFlag.PreParse()) + + data := map[string]any{ + "account_id": "acct_abc", + "limit": int64(25), + } + cmd := &cli.Command{Flags: []cli.Flag{accountFlag, limitFlag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.True(t, accountFlag.IsSet()) + assert.Equal(t, "acct_abc", accountFlag.Get()) + assert.True(t, limitFlag.IsSet()) + assert.Equal(t, int64(25), limitFlag.Get()) + }) + + t.Run("sets inner flag from nested piped data under outer body path", func(t *testing.T) { + t.Parallel() + + outer := &Flag[map[string]any]{ + Name: "address", + BodyPath: "address", + } + assert.NoError(t, outer.PreParse()) + + cityInner := &InnerFlag[string]{ + Name: "address.city", + InnerField: "city", + OuterFlag: outer, + } + + data := map[string]any{ + "address": map[string]any{"city": "San Francisco"}, + } + cmd := &cli.Command{Flags: []cli.Flag{outer, cityInner}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + // InnerFlag.IsSet() is always false by design; verify the value was written + // into the outer flag's underlying map instead. + outerVal, ok := outer.Get().(map[string]any) + assert.True(t, ok, "expected outer flag value to be map[string]any, got %T", outer.Get()) + assert.Equal(t, "San Francisco", outerVal["city"]) + }) + + t.Run("sets inner flag via data alias in nested piped data", func(t *testing.T) { + t.Parallel() + + outer := &Flag[map[string]any]{ + Name: "address", + BodyPath: "address", + } + assert.NoError(t, outer.PreParse()) + + cityInner := &InnerFlag[string]{ + Name: "address.city", + InnerField: "city", + DataAliases: []string{"cityName"}, + OuterFlag: outer, + } + + // Use the alias in piped data. + data := map[string]any{ + "address": map[string]any{"cityName": "Portland"}, + } + cmd := &cli.Command{Flags: []cli.Flag{outer, cityInner}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + // InnerFlag.IsSet() is always false by design; verify the value was written + // into the outer flag's underlying map instead. + outerVal, ok := outer.Get().(map[string]any) + assert.True(t, ok, "expected outer flag value to be map[string]any, got %T", outer.Get()) + assert.Equal(t, "Portland", outerVal["city"]) + }) + + t.Run("does not set inner flag when outer flag has no body path", func(t *testing.T) { + t.Parallel() + + outer := &Flag[map[string]any]{ + Name: "options", + // No BodyPath set + } + assert.NoError(t, outer.PreParse()) + + inner := &InnerFlag[string]{ + Name: "options.key", + InnerField: "key", + OuterFlag: outer, + } + + data := map[string]any{ + "options": map[string]any{"key": "value"}, + } + cmd := &cli.Command{Flags: []cli.Flag{outer, inner}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.False(t, inner.IsSet()) + }) + + t.Run("does not set inner flag when piped data has no nested map for outer path", func(t *testing.T) { + t.Parallel() + + outer := &Flag[map[string]any]{ + Name: "address", + BodyPath: "address", + } + assert.NoError(t, outer.PreParse()) + + inner := &InnerFlag[string]{ + Name: "address.city", + InnerField: "city", + OuterFlag: outer, + } + + // The outer body path key is missing from the piped data. + data := map[string]any{"other": "value"} + cmd := &cli.Command{Flags: []cli.Flag{outer, inner}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.False(t, inner.IsSet()) + }) + + t.Run("canonical path key takes precedence over alias when both are present", func(t *testing.T) { + t.Parallel() + + flag := &Flag[string]{ + Name: "account-id", + QueryPath: "account_id", + DataAliases: []string{"accountId"}, + } + assert.NoError(t, flag.PreParse()) + + // Both canonical and alias present — canonical should win because it's checked first. + data := map[string]any{ + "account_id": "canonical_value", + "accountId": "alias_value", + } + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, data)) + + assert.True(t, flag.IsSet()) + assert.Equal(t, "canonical_value", flag.Get()) + }) + + t.Run("empty data map does not set any flags", func(t *testing.T) { + t.Parallel() + + flag := &Flag[string]{ + Name: "account-id", + QueryPath: "account_id", + } + assert.NoError(t, flag.PreParse()) + + cmd := &cli.Command{Flags: []cli.Flag{flag}} + assert.NoError(t, ApplyStdinDataToFlags(cmd, map[string]any{})) + + assert.False(t, flag.IsSet()) + }) +} diff --git a/pkg/cmd/ai.go b/pkg/cmd/ai.go new file mode 100644 index 0000000..5f782ff --- /dev/null +++ b/pkg/cmd/ai.go @@ -0,0 +1,313 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-go-sdk" + "github.com/context-dot-dev/context-go-sdk/option" + "github.com/stainless-sdks/context.dev-cli/internal/apiquery" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var aiAIQuery = requestflag.WithInnerFlags(cli.Command{ + Name: "ai-query", + Usage: "Use AI to extract specific data points from a brand's website. The AI will crawl\nthe website and extract the requested information based on the provided data\npoints.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[[]map[string]any]{ + Name: "data-to-extract", + Usage: "Array of data points to extract from the website", + Required: true, + BodyPath: "data_to_extract", + }, + &requestflag.Flag[string]{ + Name: "domain", + Usage: "The domain name to analyze", + Required: true, + BodyPath: "domain", + }, + &requestflag.Flag[map[string]any]{ + Name: "specific-pages", + Usage: "Optional object specifying which pages to analyze", + BodyPath: "specific_pages", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + }, + Action: handleAIAIQuery, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "data-to-extract": { + &requestflag.InnerFlag[string]{ + Name: "data-to-extract.datapoint-description", + Usage: "Description of what to extract", + InnerField: "datapoint_description", + }, + &requestflag.InnerFlag[string]{ + Name: "data-to-extract.datapoint-example", + Usage: "Example of the expected value", + InnerField: "datapoint_example", + }, + &requestflag.InnerFlag[string]{ + Name: "data-to-extract.datapoint-name", + Usage: "Name of the data point to extract", + InnerField: "datapoint_name", + }, + &requestflag.InnerFlag[string]{ + Name: "data-to-extract.datapoint-type", + Usage: "Type of the data point", + InnerField: "datapoint_type", + }, + &requestflag.InnerFlag[string]{ + Name: "data-to-extract.datapoint-list-type", + Usage: "Type of items in the list when datapoint_type is 'list'. Defaults to 'string'. Use 'object' to extract an array of objects matching a schema.", + InnerField: "datapoint_list_type", + }, + &requestflag.InnerFlag[map[string]any]{ + Name: "data-to-extract.datapoint-object-schema", + Usage: "Schema definition for objects when datapoint_list_type is 'object'. Provide a map of field names to their scalar types.", + InnerField: "datapoint_object_schema", + }, + }, + "specific-pages": { + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.about-us", + Usage: "Whether to analyze the about us page", + InnerField: "about_us", + }, + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.blog", + Usage: "Whether to analyze the blog", + InnerField: "blog", + }, + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.careers", + Usage: "Whether to analyze the careers page", + InnerField: "careers", + }, + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.contact-us", + Usage: "Whether to analyze the contact us page", + InnerField: "contact_us", + }, + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.faq", + Usage: "Whether to analyze the FAQ page", + InnerField: "faq", + }, + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.home-page", + Usage: "Whether to analyze the home page", + InnerField: "home_page", + }, + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.pricing", + Usage: "Whether to analyze the pricing page", + InnerField: "pricing", + }, + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.privacy-policy", + Usage: "Whether to analyze the privacy policy page", + InnerField: "privacy_policy", + }, + &requestflag.InnerFlag[bool]{ + Name: "specific-pages.terms-and-conditions", + Usage: "Whether to analyze the terms and conditions page", + InnerField: "terms_and_conditions", + }, + }, +}) + +var aiExtractProduct = cli.Command{ + Name: "extract-product", + Usage: "Given a single URL, determines if it is a product page and extracts the product\ninformation.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "url", + Usage: "The product page URL to extract product data from.", + Required: true, + BodyPath: "url", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 7 days (604800000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh.", + Default: 604800000, + BodyPath: "maxAgeMs", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + }, + Action: handleAIExtractProduct, + HideHelpCommand: true, +} + +var aiExtractProducts = cli.Command{ + Name: "extract-products", + Usage: "Extract product information from a brand's website. We will analyze the website\nand return a list of products with details such as name, description, image,\npricing, features, and more.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "domain", + Usage: "The domain name to analyze.", + BodyPath: "domain", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 7 days (604800000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh.", + Default: 604800000, + BodyPath: "maxAgeMs", + }, + &requestflag.Flag[int64]{ + Name: "max-products", + Usage: "Maximum number of products to extract.", + BodyPath: "maxProducts", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + &requestflag.Flag[string]{ + Name: "direct-url", + Usage: "A specific URL to use directly as the starting point for extraction without domain resolution.", + BodyPath: "directUrl", + }, + }, + Action: handleAIExtractProducts, + HideHelpCommand: true, +} + +func handleAIAIQuery(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.AIAIQueryParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.AI.AIQuery(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "ai ai-query", + Transform: transform, + }) +} + +func handleAIExtractProduct(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.AIExtractProductParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.AI.ExtractProduct(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "ai extract-product", + Transform: transform, + }) +} + +func handleAIExtractProducts(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.AIExtractProductsParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.AI.ExtractProducts(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "ai extract-products", + Transform: transform, + }) +} diff --git a/pkg/cmd/ai_test.go b/pkg/cmd/ai_test.go new file mode 100644 index 0000000..8a5a1ac --- /dev/null +++ b/pkg/cmd/ai_test.go @@ -0,0 +1,141 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/stainless-sdks/context.dev-cli/internal/mocktest" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" +) + +func TestAIAIQuery(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "ai", "ai-query", + "--data-to-extract", "{datapoint_description: datapoint_description, datapoint_example: datapoint_example, datapoint_name: datapoint_name, datapoint_type: text, datapoint_list_type: string, datapoint_object_schema: {testimonial_text: string, testimonial_author: string}}", + "--domain", "domain", + "--specific-pages", "{about_us: true, blog: true, careers: true, contact_us: true, faq: true, home_page: true, pricing: true, privacy_policy: true, terms_and_conditions: true}", + "--timeout-ms", "1000", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(aiAIQuery) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "ai", "ai-query", + "--data-to-extract.datapoint-description", "datapoint_description", + "--data-to-extract.datapoint-example", "datapoint_example", + "--data-to-extract.datapoint-name", "datapoint_name", + "--data-to-extract.datapoint-type", "text", + "--data-to-extract.datapoint-list-type", "string", + "--data-to-extract.datapoint-object-schema", "{testimonial_text: string, testimonial_author: string}", + "--domain", "domain", + "--specific-pages.about-us=true", + "--specific-pages.blog=true", + "--specific-pages.careers=true", + "--specific-pages.contact-us=true", + "--specific-pages.faq=true", + "--specific-pages.home-page=true", + "--specific-pages.pricing=true", + "--specific-pages.privacy-policy=true", + "--specific-pages.terms-and-conditions=true", + "--timeout-ms", "1000", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "data_to_extract:\n" + + " - datapoint_description: datapoint_description\n" + + " datapoint_example: datapoint_example\n" + + " datapoint_name: datapoint_name\n" + + " datapoint_type: text\n" + + " datapoint_list_type: string\n" + + " datapoint_object_schema:\n" + + " testimonial_text: string\n" + + " testimonial_author: string\n" + + "domain: domain\n" + + "specific_pages:\n" + + " about_us: true\n" + + " blog: true\n" + + " careers: true\n" + + " contact_us: true\n" + + " faq: true\n" + + " home_page: true\n" + + " pricing: true\n" + + " privacy_policy: true\n" + + " terms_and_conditions: true\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "ai", "ai-query", + ) + }) +} + +func TestAIExtractProduct(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "ai", "extract-product", + "--url", "https://example.com", + "--max-age-ms", "0", + "--timeout-ms", "1000", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "url: https://example.com\n" + + "maxAgeMs: 0\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "ai", "extract-product", + ) + }) +} + +func TestAIExtractProducts(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "ai", "extract-products", + "--domain", "domain", + "--max-age-ms", "0", + "--max-products", "1", + "--timeout-ms", "1000", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "domain: domain\n" + + "maxAgeMs: 0\n" + + "maxProducts: 1\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "ai", "extract-products", + ) + }) +} diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go new file mode 100644 index 0000000..ea76221 --- /dev/null +++ b/pkg/cmd/brand.go @@ -0,0 +1,581 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-go-sdk" + "github.com/context-dot-dev/context-go-sdk/option" + "github.com/stainless-sdks/context.dev-cli/internal/apiquery" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var brandRetrieve = cli.Command{ + Name: "retrieve", + Usage: "Retrieve logos, backdrops, colors, industry, description, and more from any\ndomain", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "domain", + Usage: "Domain name to retrieve brand data for (e.g., 'example.com', 'google.com'). Cannot be used with name or ticker parameters.", + Required: true, + QueryPath: "domain", + }, + &requestflag.Flag[string]{ + Name: "force-language", + Usage: "Optional parameter to force the language of the retrieved brand data.", + QueryPath: "force_language", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: 7776000000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[bool]{ + Name: "max-speed", + Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data. Works with all three lookup methods.", + QueryPath: "maxSpeed", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleBrandRetrieve, + HideHelpCommand: true, +} + +var brandIdentifyFromTransaction = cli.Command{ + Name: "identify-from-transaction", + Usage: "Endpoint specially designed for platforms that want to identify transaction data\nby the transaction title.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "transaction-info", + Usage: "Transaction information to identify the brand", + Required: true, + QueryPath: "transaction_info", + }, + &requestflag.Flag[string]{ + Name: "city", + Usage: "Optional city name to prioritize when searching for the brand.", + QueryPath: "city", + }, + &requestflag.Flag[string]{ + Name: "country-gl", + Usage: "Optional country code (GL parameter) to specify the country. This affects the geographic location used for search queries.", + QueryPath: "country_gl", + }, + &requestflag.Flag[string]{ + Name: "force-language", + Usage: "Optional parameter to force the language of the retrieved brand data.", + QueryPath: "force_language", + }, + &requestflag.Flag[bool]{ + Name: "high-confidence-only", + Usage: "When set to true, the API will perform an additional verification steps to ensure the identified brand matches the transaction with high confidence.", + Default: false, + QueryPath: "high_confidence_only", + }, + &requestflag.Flag[bool]{ + Name: "max-speed", + Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", + QueryPath: "maxSpeed", + }, + &requestflag.Flag[string]{ + Name: "mcc", + Usage: "Optional Merchant Category Code (MCC) to help identify the business category/industry. ", + QueryPath: "mcc", + }, + &requestflag.Flag[float64]{ + Name: "phone", + Usage: "Optional phone number from the transaction to help verify brand match.", + QueryPath: "phone", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleBrandIdentifyFromTransaction, + HideHelpCommand: true, +} + +var brandRetrieveByEmail = cli.Command{ + Name: "retrieve-by-email", + Usage: "Retrieve brand information using an email address while detecting disposable and\nfree email addresses. Disposable and free email addresses (like gmail.com,\nyahoo.com) will throw a 422 error.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "email", + Usage: "Email address to retrieve brand data for (e.g., 'contact@example.com'). The domain will be extracted from the email. Free email providers (gmail.com, yahoo.com, etc.) and disposable email addresses are not allowed.", + Required: true, + QueryPath: "email", + }, + &requestflag.Flag[string]{ + Name: "force-language", + Usage: "Optional parameter to force the language of the retrieved brand data.", + QueryPath: "force_language", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: 7776000000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[bool]{ + Name: "max-speed", + Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", + QueryPath: "maxSpeed", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleBrandRetrieveByEmail, + HideHelpCommand: true, +} + +var brandRetrieveByIsin = cli.Command{ + Name: "retrieve-by-isin", + Usage: "Retrieve brand information using an ISIN (International Securities\nIdentification Number).", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "isin", + Usage: "ISIN (International Securities Identification Number) to retrieve brand data for (e.g., 'AU000000IMD5', 'US0378331005'). Must be exactly 12 characters: 2 letters followed by 9 alphanumeric characters and ending with a digit.", + Required: true, + QueryPath: "isin", + }, + &requestflag.Flag[string]{ + Name: "force-language", + Usage: "Optional parameter to force the language of the retrieved brand data.", + QueryPath: "force_language", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: 7776000000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[bool]{ + Name: "max-speed", + Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", + QueryPath: "maxSpeed", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleBrandRetrieveByIsin, + HideHelpCommand: true, +} + +var brandRetrieveByName = cli.Command{ + Name: "retrieve-by-name", + Usage: "Retrieve brand information using a company name.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "name", + Usage: "Company name to retrieve brand data for (e.g., 'Apple Inc', 'Microsoft Corporation'). Must be 3-30 characters.", + Required: true, + QueryPath: "name", + }, + &requestflag.Flag[string]{ + Name: "country-gl", + Usage: "Optional country code hint (GL parameter) to specify the country for the company name.", + QueryPath: "country_gl", + }, + &requestflag.Flag[string]{ + Name: "force-language", + Usage: "Optional parameter to force the language of the retrieved brand data.", + QueryPath: "force_language", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: 7776000000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[bool]{ + Name: "max-speed", + Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", + QueryPath: "maxSpeed", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleBrandRetrieveByName, + HideHelpCommand: true, +} + +var brandRetrieveByTicker = cli.Command{ + Name: "retrieve-by-ticker", + Usage: "Retrieve brand information using a stock ticker symbol.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "ticker", + Usage: "Stock ticker symbol to retrieve brand data for (e.g., 'AAPL', 'GOOGL', 'BRK.A'). Must be 1-15 characters, letters/numbers/dots only.", + Required: true, + QueryPath: "ticker", + }, + &requestflag.Flag[string]{ + Name: "force-language", + Usage: "Optional parameter to force the language of the retrieved brand data.", + QueryPath: "force_language", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: 7776000000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[bool]{ + Name: "max-speed", + Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", + QueryPath: "maxSpeed", + }, + &requestflag.Flag[string]{ + Name: "ticker-exchange", + Usage: "Optional stock exchange for the ticker. Defaults to NASDAQ if not specified.", + QueryPath: "ticker_exchange", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleBrandRetrieveByTicker, + HideHelpCommand: true, +} + +var brandRetrieveSimplified = cli.Command{ + Name: "retrieve-simplified", + Usage: "Returns a simplified version of brand data containing only essential\ninformation: domain, title, colors, logos, and backdrops. Optimized for faster\nresponses and reduced data transfer.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "domain", + Usage: "Domain name to retrieve simplified brand data for", + Required: true, + QueryPath: "domain", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: 7776000000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleBrandRetrieveSimplified, + HideHelpCommand: true, +} + +func handleBrandRetrieve(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BrandGetParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Brand.Get(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "brand retrieve", + Transform: transform, + }) +} + +func handleBrandIdentifyFromTransaction(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BrandIdentifyFromTransactionParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Brand.IdentifyFromTransaction(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "brand identify-from-transaction", + Transform: transform, + }) +} + +func handleBrandRetrieveByEmail(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BrandGetByEmailParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Brand.GetByEmail(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "brand retrieve-by-email", + Transform: transform, + }) +} + +func handleBrandRetrieveByIsin(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BrandGetByIsinParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Brand.GetByIsin(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "brand retrieve-by-isin", + Transform: transform, + }) +} + +func handleBrandRetrieveByName(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BrandGetByNameParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Brand.GetByName(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "brand retrieve-by-name", + Transform: transform, + }) +} + +func handleBrandRetrieveByTicker(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BrandGetByTickerParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Brand.GetByTicker(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "brand retrieve-by-ticker", + Transform: transform, + }) +} + +func handleBrandRetrieveSimplified(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BrandGetSimplifiedParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Brand.GetSimplified(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "brand retrieve-simplified", + Transform: transform, + }) +} diff --git a/pkg/cmd/brand_test.go b/pkg/cmd/brand_test.go new file mode 100644 index 0000000..99c40c2 --- /dev/null +++ b/pkg/cmd/brand_test.go @@ -0,0 +1,125 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/stainless-sdks/context.dev-cli/internal/mocktest" +) + +func TestBrandRetrieve(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "brand", "retrieve", + "--domain", "domain", + "--force-language", "afrikaans", + "--max-age-ms", "86400000", + "--max-speed=true", + "--timeout-ms", "1000", + ) + }) +} + +func TestBrandIdentifyFromTransaction(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "brand", "identify-from-transaction", + "--transaction-info", "transaction_info", + "--city", "city", + "--country-gl", "ad", + "--force-language", "afrikaans", + "--high-confidence-only=true", + "--max-speed=true", + "--mcc", "mcc", + "--phone", "0", + "--timeout-ms", "1000", + ) + }) +} + +func TestBrandRetrieveByEmail(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "brand", "retrieve-by-email", + "--email", "dev@stainless.com", + "--force-language", "afrikaans", + "--max-age-ms", "86400000", + "--max-speed=true", + "--timeout-ms", "1000", + ) + }) +} + +func TestBrandRetrieveByIsin(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "brand", "retrieve-by-isin", + "--isin", "SE60513A9993", + "--force-language", "afrikaans", + "--max-age-ms", "86400000", + "--max-speed=true", + "--timeout-ms", "1000", + ) + }) +} + +func TestBrandRetrieveByName(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "brand", "retrieve-by-name", + "--name", "xxx", + "--country-gl", "ad", + "--force-language", "afrikaans", + "--max-age-ms", "86400000", + "--max-speed=true", + "--timeout-ms", "1000", + ) + }) +} + +func TestBrandRetrieveByTicker(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "brand", "retrieve-by-ticker", + "--ticker", "ticker", + "--force-language", "afrikaans", + "--max-age-ms", "86400000", + "--max-speed=true", + "--ticker-exchange", "AMEX", + "--timeout-ms", "1000", + ) + }) +} + +func TestBrandRetrieveSimplified(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "brand", "retrieve-simplified", + "--domain", "domain", + "--max-age-ms", "86400000", + "--timeout-ms", "1000", + ) + }) +} diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go new file mode 100644 index 0000000..4e153e1 --- /dev/null +++ b/pkg/cmd/cmd.go @@ -0,0 +1,227 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "bytes" + "compress/gzip" + "context" + "fmt" + "os" + "path/filepath" + "slices" + "strings" + + "github.com/stainless-sdks/context.dev-cli/internal/autocomplete" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + docs "github.com/urfave/cli-docs/v3" + "github.com/urfave/cli/v3" +) + +var ( + Command *cli.Command + CommandErrorBuffer bytes.Buffer +) + +func init() { + Command = &cli.Command{ + Name: "context-dev", + Usage: "CLI for the context.dev API", + Suggest: true, + Version: Version, + ErrWriter: &CommandErrorBuffer, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "debug", + Usage: "Enable debug logging", + }, + &cli.StringFlag{ + Name: "base-url", + DefaultText: "url", + Usage: "Override the base URL for API requests", + Validator: func(baseURL string) error { + return ValidateBaseURL(baseURL, "--base-url") + }, + }, + &cli.StringFlag{ + Name: "format", + Usage: "The format for displaying response data (one of: " + strings.Join(OutputFormats, ", ") + ")", + Value: "auto", + Validator: func(format string) error { + if !slices.Contains(OutputFormats, strings.ToLower(format)) { + return fmt.Errorf("format must be one of: %s", strings.Join(OutputFormats, ", ")) + } + return nil + }, + }, + &cli.StringFlag{ + Name: "format-error", + Usage: "The format for displaying error data (one of: " + strings.Join(OutputFormats, ", ") + ")", + Value: "auto", + Validator: func(format string) error { + if !slices.Contains(OutputFormats, strings.ToLower(format)) { + return fmt.Errorf("format must be one of: %s", strings.Join(OutputFormats, ", ")) + } + return nil + }, + }, + &cli.StringFlag{ + Name: "transform", + Usage: "The GJSON transformation for data output.", + }, + &cli.StringFlag{ + Name: "transform-error", + Usage: "The GJSON transformation for errors.", + }, + &cli.BoolFlag{ + Name: "raw-output", + Aliases: []string{"r"}, + Usage: "If the result is a string, print it without JSON quotes. This can be useful for making output transforms talk to non-JSON-based systems.", + }, + &requestflag.Flag[string]{ + Name: "api-key", + Sources: cli.EnvVars("CONTEXT_DEV_API_KEY"), + }, + }, + Commands: []*cli.Command{ + { + Name: "web", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &webExtract, + &webExtractCompetitors, + &webExtractFonts, + &webExtractStyleguide, + &webScreenshot, + &webSearch, + &webWebCrawlMd, + &webWebScrapeHTML, + &webWebScrapeImages, + &webWebScrapeMd, + &webWebScrapeSitemap, + }, + }, + { + Name: "ai", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &aiAIQuery, + &aiExtractProduct, + &aiExtractProducts, + }, + }, + { + Name: "brand", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &brandRetrieve, + &brandIdentifyFromTransaction, + &brandRetrieveByEmail, + &brandRetrieveByIsin, + &brandRetrieveByName, + &brandRetrieveByTicker, + &brandRetrieveSimplified, + }, + }, + { + Name: "industry", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &industryRetrieveNaics, + &industryRetrieveSic, + }, + }, + { + Name: "utility", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &utilityPrefetch, + &utilityPrefetchByEmail, + }, + }, + { + Name: "@manpages", + Usage: "Generate documentation for 'man'", + UsageText: "context-dev @manpages [-o context-dev.1] [--gzip]", + Hidden: true, + Action: generateManpages, + HideHelpCommand: true, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "output", + Aliases: []string{"o"}, + Usage: "write manpages to the given folder", + Value: "man", + }, + &cli.BoolFlag{ + Name: "gzip", + Aliases: []string{"z"}, + Usage: "output gzipped manpage files to .gz", + Value: true, + }, + &cli.BoolFlag{ + Name: "text", + Aliases: []string{"z"}, + Usage: "output uncompressed text files", + Value: false, + }, + }, + }, + { + Name: "__complete", + Hidden: true, + HideHelpCommand: true, + Action: autocomplete.ExecuteShellCompletion, + }, + { + Name: "@completion", + Hidden: true, + HideHelpCommand: true, + Action: autocomplete.OutputCompletionScript, + }, + }, + HideHelpCommand: true, + } +} + +func generateManpages(ctx context.Context, c *cli.Command) error { + manpage, err := docs.ToManWithSection(Command, 1) + if err != nil { + return err + } + dir := c.String("output") + err = os.MkdirAll(filepath.Join(dir, "man1"), 0755) + if err != nil { + // handle error + } + if c.Bool("text") { + file, err := os.Create(filepath.Join(dir, "man1", "context-dev.1")) + if err != nil { + return err + } + defer file.Close() + if _, err := file.WriteString(manpage); err != nil { + return err + } + } + if c.Bool("gzip") { + file, err := os.Create(filepath.Join(dir, "man1", "context-dev.1.gz")) + if err != nil { + return err + } + defer file.Close() + gzWriter := gzip.NewWriter(file) + defer gzWriter.Close() + _, err = gzWriter.Write([]byte(manpage)) + if err != nil { + return err + } + } + fmt.Printf("Wrote manpages to %s\n", dir) + return nil +} diff --git a/pkg/cmd/cmdutil.go b/pkg/cmd/cmdutil.go new file mode 100644 index 0000000..87208ae --- /dev/null +++ b/pkg/cmd/cmdutil.go @@ -0,0 +1,525 @@ +package cmd + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "log" + "mime" + "net/http" + "net/http/httputil" + "os" + "os/exec" + "os/signal" + "path/filepath" + "strings" + "syscall" + + "github.com/context-dot-dev/context-go-sdk/option" + "github.com/stainless-sdks/context.dev-cli/internal/jsonview" + + "github.com/charmbracelet/x/term" + "github.com/itchyny/json2yaml" + "github.com/muesli/reflow/wrap" + "github.com/tidwall/gjson" + "github.com/tidwall/pretty" + "github.com/urfave/cli/v3" +) + +var OutputFormats = []string{"auto", "explore", "json", "jsonl", "pretty", "raw", "yaml"} + +// ValidateBaseURL checks that a base URL is correctly prefixed with a protocol scheme and produces a better +// error message than the person would see otherwise if it doesn't. +func ValidateBaseURL(value, source string) error { + if value != "" && !strings.HasPrefix(value, "http://") && !strings.HasPrefix(value, "https://") { + return fmt.Errorf("%s %q is missing a scheme (expected http:// or https://)", source, value) + } + return nil +} + +func getDefaultRequestOptions(cmd *cli.Command) []option.RequestOption { + opts := []option.RequestOption{ + option.WithHeader("User-Agent", fmt.Sprintf("ContextDev/CLI %s", Version)), + option.WithHeader("X-Stainless-Lang", "cli"), + option.WithHeader("X-Stainless-Package-Version", Version), + option.WithHeader("X-Stainless-Runtime", "cli"), + option.WithHeader("X-Stainless-CLI-Command", cmd.FullName()), + } + if cmd.IsSet("api-key") { + opts = append(opts, option.WithAPIKey(cmd.String("api-key"))) + } + + // Override base URL if the --base-url flag is provided + if baseURL := cmd.String("base-url"); baseURL != "" { + opts = append(opts, option.WithBaseURL(baseURL)) + } + + return opts +} + +var debugMiddlewareOption = option.WithMiddleware( + func(r *http.Request, mn option.MiddlewareNext) (*http.Response, error) { + logger := log.Default() + + if reqBytes, err := httputil.DumpRequest(r, true); err == nil { + logger.Printf("Request Content:\n%s\n", reqBytes) + } + + resp, err := mn(r) + if err != nil { + return resp, err + } + + if respBytes, err := httputil.DumpResponse(resp, true); err == nil { + logger.Printf("Response Content:\n%s\n", respBytes) + } + + return resp, err + }, +) + +// isInputPiped tries to check for input being piped into the CLI which tells us that we should try to read +// from stdin. This can be a bit tricky in some cases like when an stdin is connected to a pipe but nothing is +// being piped in (this may happen in some environments like Cursor's integration terminal or CI), which is +// why this function is a little more elaborate than it'd be otherwise. +func isInputPiped() bool { + stat, err := os.Stdin.Stat() + if err != nil { + return false + } + + mode := stat.Mode() + + // Regular file (redirect like < file.txt) — only if non-empty. + // + // Notably, on Unix the case like `< /dev/null` is handled below because `/dev/null` is not a regular + // file. On Windows, NUL appears as a regular file with size 0, so it's also handled correctly. + if mode.IsRegular() && stat.Size() > 0 { + return true + } + + // For pipes/sockets (e.g. `echo foo | stainlesscli`), use an OS-specific check to determine whether + // data is actually available. Some environments like Cursor's integrated terminal connect stdin as a + // pipe even when nothing is being piped. + if mode&(os.ModeNamedPipe|os.ModeSocket) != 0 { + // Defined in either cmdutil_unix.go or cmdutil_windows.go. + return isPipedDataAvailableOSSpecific() + } + + return false +} + +func isTerminal(w io.Writer) bool { + switch v := w.(type) { + case *os.File: + return term.IsTerminal(v.Fd()) + default: + return false + } +} + +func streamOutput(label string, generateOutput func(w *os.File) error) error { + // For non-tty output (probably a pipe), write directly to stdout + if !isTerminal(os.Stdout) { + return streamToStdout(generateOutput) + } + + // When streaming output on Unix-like systems, there's a special trick involving creating two socket pairs + // that we prefer because it supports small buffer sizes which results in less pagination per buffer. The + // constructs needed to run it don't exist on Windows builds, so we have this function broken up into + // OS-specific files with conditional build comments. Under Windows (and in case our fancy constructs fail + // on Unix), we fall back to using pipes (`streamToPagerWithPipe`), which are OS agnostic. + // + // Defined in either cmdutil_unix.go or cmdutil_windows.go. + return streamOutputOSSpecific(label, generateOutput) +} + +func streamToPagerWithPipe(label string, generateOutput func(w *os.File) error) error { + r, w, err := os.Pipe() + if err != nil { + return err + } + defer r.Close() + defer w.Close() + + pagerProgram := os.Getenv("PAGER") + if pagerProgram == "" { + pagerProgram = "less" + } + + if _, err := exec.LookPath(pagerProgram); err != nil { + return err + } + + cmd := exec.Command(pagerProgram) + cmd.Stdin = r + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Env = append(os.Environ(), + "LESS=-X -r -P "+label, + "MORE=-r -P "+label, + ) + + if err := cmd.Start(); err != nil { + return err + } + + if err := r.Close(); err != nil { + return err + } + + // If we would be streaming to a terminal and aren't forcing color one way + // or the other, we should configure things to use color so the pager gets + // colorized input. + if isTerminal(os.Stdout) && os.Getenv("FORCE_COLOR") == "" { + os.Setenv("FORCE_COLOR", "1") + } + + if err := generateOutput(w); err != nil && !strings.Contains(err.Error(), "broken pipe") { + return err + } + + w.Close() + return cmd.Wait() +} + +func streamToStdout(generateOutput func(w *os.File) error) error { + signal.Ignore(syscall.SIGPIPE) + err := generateOutput(os.Stdout) + if err != nil && strings.Contains(err.Error(), "broken pipe") { + return nil + } + return err +} + +// writeBinaryResponse writes a binary response to stdout or a file. +// +// Takes in a stdout reference so we can test this function without overriding os.Stdout in tests. +func writeBinaryResponse(response *http.Response, stdout io.Writer, outfile string) (string, error) { + defer response.Body.Close() + body, err := io.ReadAll(response.Body) + if err != nil { + return "", err + } + switch outfile { + case "-", "/dev/stdout": + _, err := stdout.Write(body) + return "", err + case "": + // If output file is unspecified, then print to stdout for plain text or + // if stdout is not a terminal: + if !isTerminal(os.Stdout) || isUTF8TextFile(body) { + _, err := stdout.Write(body) + return "", err + } + + // If response has a suggested filename in the content-disposition + // header, then use that (with an optional suffix to ensure uniqueness): + file, err := createDownloadFile(response, body) + if err != nil { + return "", err + } + defer file.Close() + if _, err := file.Write(body); err != nil { + return "", err + } + return fmt.Sprintf("Wrote output to: %s", file.Name()), nil + default: + if err := os.WriteFile(outfile, body, 0644); err != nil { + return "", err + } + return fmt.Sprintf("Wrote output to: %s", outfile), nil + } +} + +// Return a writable file handle to a new file, which attempts to choose a good filename +// based on the Content-Disposition header or sniffing the MIME filetype of the response. +func createDownloadFile(response *http.Response, data []byte) (*os.File, error) { + filename := "file" + // If the header provided an output filename, use that + disp := response.Header.Get("Content-Disposition") + _, params, err := mime.ParseMediaType(disp) + if err == nil { + if dispFilename, ok := params["filename"]; ok { + // Only use the last path component to prevent directory traversal + filename = filepath.Base(dispFilename) + // Try to create the file with exclusive flag to avoid race conditions + file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644) + if err == nil { + return file, nil + } + } + } + + // If file already exists, create a unique filename using CreateTemp + ext := filepath.Ext(filename) + if ext == "" { + ext = guessExtension(data) + } + base := strings.TrimSuffix(filename, ext) + return os.CreateTemp(".", base+"-*"+ext) +} + +func guessExtension(data []byte) string { + ct := http.DetectContentType(data) + + // Prefer common extensions over obscure ones + switch ct { + case "application/gzip": + return ".gz" + case "application/pdf": + return ".pdf" + case "application/zip": + return ".zip" + case "audio/mpeg": + return ".mp3" + case "image/bmp": + return ".bmp" + case "image/gif": + return ".gif" + case "image/jpeg": + return ".jpg" + case "image/png": + return ".png" + case "image/webp": + return ".webp" + case "video/mp4": + return ".mp4" + } + + exts, err := mime.ExtensionsByType(ct) + if err == nil && len(exts) > 0 { + return exts[0] + } else if isUTF8TextFile(data) { + return ".txt" + } else { + return ".bin" + } +} + +func shouldUseColors(w io.Writer) bool { + force, ok := os.LookupEnv("FORCE_COLOR") + if ok { + if force == "1" { + return true + } + if force == "0" { + return false + } + } + return isTerminal(w) +} + +func formatJSON(res gjson.Result, opts ShowJSONOpts) ([]byte, error) { + if opts.Transform != "" { + transformed := res.Get(opts.Transform) + if transformed.Exists() { + res = transformed + } + } + // Modeled after `jq -r` (`--raw-output`): if the result is a string, print it without JSON quotes so that + // it's easier to pipe into other programs. + if opts.RawOutput && res.Type == gjson.String { + return []byte(res.Str + "\n"), nil + } + switch strings.ToLower(opts.Format) { + case "auto": + autoOpts := opts + autoOpts.Format = "json" + autoOpts.Transform = "" + return formatJSON(res, autoOpts) + case "pretty": + return []byte(jsonview.RenderJSON(opts.Title, res) + "\n"), nil + case "json": + prettyJSON := pretty.Pretty([]byte(res.Raw)) + if shouldUseColors(opts.Stdout) { + return pretty.Color(prettyJSON, pretty.TerminalStyle), nil + } else { + return prettyJSON, nil + } + case "jsonl": + // @ugly is gjson syntax for "no whitespace", so it fits on one line + oneLineJSON := res.Get("@ugly").Raw + if shouldUseColors(opts.Stdout) { + bytes := append(pretty.Color([]byte(oneLineJSON), pretty.TerminalStyle), '\n') + return bytes, nil + } else { + return []byte(oneLineJSON + "\n"), nil + } + case "raw": + return []byte(res.Raw + "\n"), nil + case "yaml": + input := strings.NewReader(res.Raw) + var yaml strings.Builder + if err := json2yaml.Convert(&yaml, input); err != nil { + return nil, err + } + _, err := opts.Stdout.Write([]byte(yaml.String())) + return nil, err + default: + return nil, fmt.Errorf("Invalid format: %s, valid formats are: %s", opts.Format, strings.Join(OutputFormats, ", ")) + } +} + +const warningExploreNotSupported = "Warning: Output format 'explore' not supported for non-terminal output; falling back to 'json'\n" + +// ShowJSONOpts configures how JSON output is displayed. +type ShowJSONOpts struct { + ExplicitFormat bool // true if the user explicitly passed --format + Format string // output format (auto, explore, json, jsonl, pretty, raw, yaml) + RawOutput bool // like jq -r: print strings without JSON quotes + Stderr io.Writer // stderr for warnings; injectable for testing; defaults to os.Stderr + Stdout *os.File // stdout (or pager); injectable for testing; defaults to os.Stdout + Title string // display title + Transform string // GJSON path to extract before displaying +} + +func (o *ShowJSONOpts) setDefaults() { + if o.Stderr == nil { + o.Stderr = os.Stderr + } + if o.Stdout == nil { + o.Stdout = os.Stdout + } +} + +// ShowJSON displays a single JSON result to the user. +func ShowJSON(res gjson.Result, opts ShowJSONOpts) error { + opts.setDefaults() + + switch strings.ToLower(opts.Format) { + case "auto": + autoOpts := opts + autoOpts.Format = "json" + return ShowJSON(res, autoOpts) + case "explore": + if !isTerminal(opts.Stdout) { + if opts.ExplicitFormat { + fmt.Fprint(opts.Stderr, warningExploreNotSupported) + } + jsonOpts := opts + jsonOpts.Format = "json" + return ShowJSON(res, jsonOpts) + } + if opts.Transform != "" { + transformed := res.Get(opts.Transform) + if transformed.Exists() { + res = transformed + } + } + return jsonview.ExploreJSON(opts.Title, res) + default: + bytes, err := formatJSON(res, opts) + if err != nil { + return err + } + + _, err = opts.Stdout.Write(bytes) + return err + } +} + +// Get the number of lines that would be output by writing the data to the terminal +func countTerminalLines(data []byte, terminalWidth int) int { + return bytes.Count([]byte(wrap.String(string(data), terminalWidth)), []byte("\n")) +} + +type hasRawJSON interface { + RawJSON() string +} + +// ShowJSONIterator displays an iterator of values to the user. Use itemsToDisplay = -1 for no limit. +func ShowJSONIterator[T any](iter jsonview.Iterator[T], itemsToDisplay int64, opts ShowJSONOpts) error { + opts.setDefaults() + + if opts.Format == "explore" { + if isTerminal(opts.Stdout) { + return jsonview.ExploreJSONStream(opts.Title, iter) + } + if opts.ExplicitFormat { + fmt.Fprint(opts.Stderr, warningExploreNotSupported) + } + opts.Format = "json" + } + + terminalWidth, terminalHeight, err := term.GetSize(os.Stdout.Fd()) + if err != nil { + terminalWidth = 100 + terminalHeight = 40 + } + + // Decide whether or not to use a pager based on whether it's a short output or a long output + usePager := false + output := []byte{} + numberOfNewlines := 0 + // -1 is used to signal no limit of items to display + for itemsToDisplay != 0 && iter.Next() { + item := iter.Current() + var obj gjson.Result + if hasRaw, ok := any(item).(hasRawJSON); ok { + obj = gjson.Parse(hasRaw.RawJSON()) + } else { + jsonData, err := json.Marshal(item) + if err != nil { + return err + } + obj = gjson.ParseBytes(jsonData) + } + json, err := formatJSON(obj, opts) + if err != nil { + return err + } + + output = append(output, json...) + itemsToDisplay -= 1 + numberOfNewlines += countTerminalLines(json, terminalWidth) + + // If the output won't fit in the terminal window, stream it to a pager + if numberOfNewlines >= terminalHeight-3 { + usePager = true + break + } + } + + if !usePager { + _, err := opts.Stdout.Write(output) + if err != nil { + return err + } + + return iter.Err() + } + + return streamOutput(opts.Title, func(pager *os.File) error { + _, err := pager.Write(output) + if err != nil { + return err + } + + pagerOpts := opts + pagerOpts.Stdout = pager + + for iter.Next() { + if itemsToDisplay == 0 { + break + } + item := iter.Current() + var obj gjson.Result + if hasRaw, ok := any(item).(hasRawJSON); ok { + obj = gjson.Parse(hasRaw.RawJSON()) + } else { + jsonData, err := json.Marshal(item) + if err != nil { + return err + } + obj = gjson.ParseBytes(jsonData) + } + if err := ShowJSON(obj, pagerOpts); err != nil { + return err + } + itemsToDisplay -= 1 + } + return iter.Err() + }) +} diff --git a/pkg/cmd/cmdutil_test.go b/pkg/cmd/cmdutil_test.go new file mode 100644 index 0000000..f2eadae --- /dev/null +++ b/pkg/cmd/cmdutil_test.go @@ -0,0 +1,388 @@ +package cmd + +import ( + "bytes" + "io" + "net/http" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/tidwall/gjson" + + "github.com/stainless-sdks/context.dev-cli/internal/jsonview" +) + +func TestStreamOutput(t *testing.T) { + t.Setenv("PAGER", "cat") + err := streamOutput("stream test", func(w *os.File) error { + _, writeErr := w.WriteString("Hello world\n") + return writeErr + }) + if err != nil { + t.Errorf("streamOutput failed: %v", err) + } +} + +func TestWriteBinaryResponse(t *testing.T) { + t.Run("write to explicit file", func(t *testing.T) { + tmpDir := t.TempDir() + outfile := tmpDir + "/output.txt" + body := []byte("test content") + resp := &http.Response{ + Body: io.NopCloser(bytes.NewReader(body)), + } + + msg, err := writeBinaryResponse(resp, os.Stdout, outfile) + + require.NoError(t, err) + assert.Contains(t, msg, outfile) + + content, err := os.ReadFile(outfile) + require.NoError(t, err) + assert.Equal(t, body, content) + }) + + t.Run("write to stdout", func(t *testing.T) { + t.Parallel() + + var buf bytes.Buffer + body := []byte("stdout content") + resp := &http.Response{ + Body: io.NopCloser(bytes.NewReader(body)), + } + msg, err := writeBinaryResponse(resp, &buf, "-") + + require.NoError(t, err) + assert.Empty(t, msg) + assert.Equal(t, body, buf.Bytes()) + }) +} + +func TestCreateDownloadFile(t *testing.T) { + t.Run("creates file with filename from header", func(t *testing.T) { + t.Chdir(t.TempDir()) + + resp := &http.Response{ + Header: http.Header{ + "Content-Disposition": []string{`attachment; filename="test.txt"`}, + }, + } + file, err := createDownloadFile(resp, []byte("test content")) + require.NoError(t, err) + defer file.Close() + assert.Equal(t, "test.txt", filepath.Base(file.Name())) + + // Create a second file with the same name to ensure it doesn't clobber the first + resp2 := &http.Response{ + Header: http.Header{ + "Content-Disposition": []string{`attachment; filename="test.txt"`}, + }, + } + file2, err := createDownloadFile(resp2, []byte("second content")) + require.NoError(t, err) + defer file2.Close() + assert.NotEqual(t, file.Name(), file2.Name(), "second file should have a different name") + assert.Contains(t, filepath.Base(file2.Name()), "test") + }) + + t.Run("creates temp file when no header", func(t *testing.T) { + t.Chdir(t.TempDir()) + + resp := &http.Response{Header: http.Header{}} + file, err := createDownloadFile(resp, []byte("test content")) + require.NoError(t, err) + defer file.Close() + assert.Contains(t, filepath.Base(file.Name()), "file-") + }) + + t.Run("prevents directory traversal", func(t *testing.T) { + t.Chdir(t.TempDir()) + + resp := &http.Response{ + Header: http.Header{ + "Content-Disposition": []string{`attachment; filename="../../../etc/passwd"`}, + }, + } + file, err := createDownloadFile(resp, []byte("test content")) + require.NoError(t, err) + defer file.Close() + assert.Equal(t, "passwd", filepath.Base(file.Name())) + }) +} + +func TestValidateBaseURL(t *testing.T) { + t.Parallel() + + t.Run("ValidHTTPS", func(t *testing.T) { + t.Parallel() + + require.NoError(t, ValidateBaseURL("https://api.example.com", "--base-url")) + }) + + t.Run("ValidHTTP", func(t *testing.T) { + t.Parallel() + + require.NoError(t, ValidateBaseURL("http://localhost:8080", "--base-url")) + }) + + t.Run("Empty", func(t *testing.T) { + t.Parallel() + + require.NoError(t, ValidateBaseURL("", "MY_BASE_URL")) + }) + + t.Run("MissingScheme", func(t *testing.T) { + t.Parallel() + + err := ValidateBaseURL("localhost:8080", "MY_BASE_URL") + require.Error(t, err) + assert.Contains(t, err.Error(), "MY_BASE_URL") + assert.Contains(t, err.Error(), "missing a scheme") + }) + + t.Run("HostOnly", func(t *testing.T) { + t.Parallel() + + err := ValidateBaseURL("api.example.com", "--base-url") + require.Error(t, err) + assert.Contains(t, err.Error(), "--base-url") + }) +} + +func TestFormatJSON(t *testing.T) { + t.Parallel() + + t.Run("RawWithTransform", func(t *testing.T) { + t.Parallel() + + res := gjson.Parse(`{"id":"abc123","name":"test"}`) + formatted, err := formatJSON(res, ShowJSONOpts{Format: "raw", Stdout: os.Stdout, Transform: "id"}) + require.NoError(t, err) + require.Equal(t, `"abc123"`+"\n", string(formatted)) + }) + + t.Run("RawWithoutTransform", func(t *testing.T) { + t.Parallel() + + res := gjson.Parse(`{"id":"abc123","name":"test"}`) + formatted, err := formatJSON(res, ShowJSONOpts{Format: "raw", Stdout: os.Stdout}) + require.NoError(t, err) + require.Equal(t, `{"id":"abc123","name":"test"}`+"\n", string(formatted)) + }) + + t.Run("RawWithNestedTransform", func(t *testing.T) { + t.Parallel() + + res := gjson.Parse(`{"data":{"items":[1,2,3]}}`) + formatted, err := formatJSON(res, ShowJSONOpts{Format: "raw", Stdout: os.Stdout, Transform: "data.items"}) + require.NoError(t, err) + require.Equal(t, "[1,2,3]\n", string(formatted)) + }) + + t.Run("RawWithNonexistentTransform", func(t *testing.T) { + t.Parallel() + + res := gjson.Parse(`{"id":"abc123"}`) + formatted, err := formatJSON(res, ShowJSONOpts{Format: "raw", Stdout: os.Stdout, Transform: "missing"}) + require.NoError(t, err) + // Transform path doesn't exist, so original result is returned + require.Equal(t, `{"id":"abc123"}`+"\n", string(formatted)) + }) + + t.Run("RawOutputString", func(t *testing.T) { + t.Parallel() + + res := gjson.Parse(`{"id":"abc123","name":"test"}`) + formatted, err := formatJSON(res, ShowJSONOpts{Format: "json", Stdout: os.Stdout, Transform: "id", RawOutput: true}) + require.NoError(t, err) + require.Equal(t, "abc123\n", string(formatted)) + }) + + t.Run("RawOutputNonString", func(t *testing.T) { + t.Parallel() + + // --raw-output has no effect on non-string values + res := gjson.Parse(`{"count":42}`) + formatted, err := formatJSON(res, ShowJSONOpts{Format: "raw", Stdout: os.Stdout, Transform: "count", RawOutput: true}) + require.NoError(t, err) + require.Equal(t, "42\n", string(formatted)) + }) + + t.Run("RawOutputObject", func(t *testing.T) { + t.Parallel() + + // --raw-output has no effect on objects + res := gjson.Parse(`{"nested":{"a":1}}`) + formatted, err := formatJSON(res, ShowJSONOpts{Format: "raw", Stdout: os.Stdout, Transform: "nested", RawOutput: true}) + require.NoError(t, err) + require.Equal(t, `{"a":1}`+"\n", string(formatted)) + }) +} + +func TestShowJSONIterator(t *testing.T) { + t.Parallel() + + t.Run("RawMultipleItems", func(t *testing.T) { + t.Parallel() + + iter := &sliceIterator[map[string]any]{items: []map[string]any{ + {"id": "abc", "name": "first"}, + {"id": "def", "name": "second"}, + }} + captured := captureShowJSONIterator(t, iter, "raw", "", -1) + assert.Equal(t, `{"id":"abc","name":"first"}`+"\n"+`{"id":"def","name":"second"}`+"\n", captured) + }) + + t.Run("RawWithTransform", func(t *testing.T) { + t.Parallel() + + iter := &sliceIterator[map[string]any]{items: []map[string]any{ + {"id": "abc", "name": "first"}, + {"id": "def", "name": "second"}, + }} + captured := captureShowJSONIterator(t, iter, "raw", "id", -1) + assert.Equal(t, `"abc"`+"\n"+`"def"`+"\n", captured) + }) + + t.Run("LimitItems", func(t *testing.T) { + t.Parallel() + + iter := &sliceIterator[map[string]any]{items: []map[string]any{ + {"id": "abc"}, + {"id": "def"}, + {"id": "ghi"}, + }} + captured := captureShowJSONIterator(t, iter, "raw", "", 2) + assert.Equal(t, `{"id":"abc"}`+"\n"+`{"id":"def"}`+"\n", captured) + }) +} + +func TestExploreFallback(t *testing.T) { + t.Parallel() + + t.Run("ShowJSONFallsBackToJsonOnNonTTY", func(t *testing.T) { + t.Parallel() + + // os.Pipe() produces a *os.File that isn't a terminal, so explore should fall back. + r, w, err := os.Pipe() + require.NoError(t, err) + defer r.Close() + + var stderr bytes.Buffer + res := gjson.Parse(`{"id":"abc"}`) + err = ShowJSON(res, ShowJSONOpts{ + Format: "explore", + Stderr: &stderr, + Stdout: w, + Title: "test", + }) + w.Close() + require.NoError(t, err) + + var buf bytes.Buffer + _, _ = buf.ReadFrom(r) + assert.Contains(t, buf.String(), `"id"`) + assert.Contains(t, buf.String(), `"abc"`) + }) + + t.Run("ShowJSONIteratorFallsBackToJsonOnNonTTY", func(t *testing.T) { + t.Parallel() + + iter := &sliceIterator[map[string]any]{items: []map[string]any{ + {"id": "abc"}, + }} + captured := captureShowJSONIterator(t, iter, "explore", "", -1) + assert.Contains(t, captured, `"id"`) + assert.Contains(t, captured, `"abc"`) + }) + + t.Run("ShowJSONWarnsWhenExplicitFormatOnNonTTY", func(t *testing.T) { + t.Parallel() + + r, w, err := os.Pipe() + require.NoError(t, err) + defer r.Close() + + var stderr bytes.Buffer + res := gjson.Parse(`{"id":"abc"}`) + err = ShowJSON(res, ShowJSONOpts{ + ExplicitFormat: true, + Format: "explore", + Stderr: &stderr, + Stdout: w, + Title: "test", + }) + w.Close() + require.NoError(t, err) + + assert.Equal(t, warningExploreNotSupported, stderr.String()) + }) + + t.Run("ShowJSONSilentWhenDefaultFormatOnNonTTY", func(t *testing.T) { + t.Parallel() + + r, w, err := os.Pipe() + require.NoError(t, err) + defer r.Close() + + var stderr bytes.Buffer + res := gjson.Parse(`{"id":"abc"}`) + err = ShowJSON(res, ShowJSONOpts{ + Format: "explore", + Stderr: &stderr, + Stdout: w, + Title: "test", + }) + w.Close() + require.NoError(t, err) + + assert.Empty(t, stderr.String(), "no warning expected when format was not explicit") + }) +} + +// sliceIterator is a simple iterator over a slice for testing. +type sliceIterator[T any] struct { + index int + items []T +} + +func (it *sliceIterator[T]) Next() bool { + it.index++ + return it.index <= len(it.items) +} + +func (it *sliceIterator[T]) Current() T { + return it.items[it.index-1] +} + +func (it *sliceIterator[T]) Err() error { + return nil +} + +var _ jsonview.Iterator[any] = (*sliceIterator[any])(nil) + +// captureShowJSONIterator runs ShowJSONIterator and captures the output written to a file. +func captureShowJSONIterator[T any](t *testing.T, iter jsonview.Iterator[T], format, transform string, itemsToDisplay int64) string { + t.Helper() + + r, w, err := os.Pipe() + require.NoError(t, err) + defer r.Close() + + err = ShowJSONIterator(iter, itemsToDisplay, ShowJSONOpts{ + Format: format, + Stderr: io.Discard, + Stdout: w, + Title: "test", + Transform: transform, + }) + w.Close() + require.NoError(t, err) + + var buf bytes.Buffer + _, _ = buf.ReadFrom(r) + return buf.String() +} diff --git a/pkg/cmd/cmdutil_unix.go b/pkg/cmd/cmdutil_unix.go new file mode 100644 index 0000000..edefcd7 --- /dev/null +++ b/pkg/cmd/cmdutil_unix.go @@ -0,0 +1,127 @@ +//go:build !windows + +package cmd + +import ( + "fmt" + "os" + "os/exec" + "strings" + "syscall" + + "golang.org/x/sys/unix" +) + +func isPipedDataAvailableOSSpecific() bool { + // Try to determine if there's non-empty data being piped into the command by polling for data for a short + // amount of time. This is necessary because some environments (e.g. Cursor's integrated terminal) connect + // stdin as a pipe even when nothing is being piped, which would cause the command to block indefinitely + // waiting for input that will never come. The 10 ms timeout is arbitrary -- designed to be long enough to + // allow data to be detected, but short enough that it shouldn't cause a noticeable delay in command runs. + fds := []unix.PollFd{{Fd: int32(os.Stdin.Fd()), Events: unix.POLLIN}} + n, _ := unix.Poll(fds, 10 /* ms */) + return n > 0 +} + +func streamOutputOSSpecific(label string, generateOutput func(w *os.File) error) error { + // Try to use socket pair for better buffer control + pagerInput, pid, err := openSocketPairPager(label) + if err != nil || pagerInput == nil { + // Fall back to pipe if socket setup fails + return streamToPagerWithPipe(label, generateOutput) + } + defer pagerInput.Close() + + // If we would be streaming to a terminal and aren't forcing color one way + // or the other, we should configure things to use color so the pager gets + // colorized input. + if isTerminal(os.Stdout) && os.Getenv("FORCE_COLOR") == "" { + os.Setenv("FORCE_COLOR", "1") + } + + // If the pager exits before reading all input, then generateOutput() will + // produce a broken pipe error, which is fine and we don't want to propagate it. + if err := generateOutput(pagerInput); err != nil && + !strings.Contains(err.Error(), "broken pipe") { + return err + } + + // Close the file NOW before we wait for the child process to terminate. + // This way, the child will receive the end-of-file signal and know that + // there is no more input. Otherwise the child process may block + // indefinitely waiting for another line (this can happen when streaming + // less than a screenful of data to a pager). + pagerInput.Close() + + // Wait for child process to exit + var wstatus syscall.WaitStatus + _, err = syscall.Wait4(pid, &wstatus, 0, nil) + if wstatus.ExitStatus() != 0 { + return fmt.Errorf("Pager exited with non-zero exit status: %d", wstatus.ExitStatus()) + } + return err +} + +func openSocketPairPager(label string) (*os.File, int, error) { + fds, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0) + if err != nil { + return nil, 0, err + } + + // The child file descriptor will be sent to the child process through + // ProcAttr and ForkExec(), while the parent process will always close the + // child file descriptor. + // The parent file descriptor will be wrapped in an os.File wrapper and + // returned from this function, or closed if something goes wrong. + parentFd, childFd := fds[0], fds[1] + defer unix.Close(childFd) + + // Use small buffer sizes so we don't ask the server for more paginated + // values than we actually need. + if err := unix.SetsockoptInt(parentFd, unix.SOL_SOCKET, unix.SO_SNDBUF, 128); err != nil { + unix.Close(parentFd) + return nil, 0, err + } + if err := unix.SetsockoptInt(childFd, unix.SOL_SOCKET, unix.SO_RCVBUF, 128); err != nil { + unix.Close(parentFd) + return nil, 0, err + } + + // Set CLOEXEC on the parent file descriptor so it doesn't leak to child + syscall.CloseOnExec(parentFd) + + parentConn := os.NewFile(uintptr(parentFd), "parent-socket") + + pagerProgram := os.Getenv("PAGER") + if pagerProgram == "" { + pagerProgram = "less" + } + + pagerPath, err := exec.LookPath(pagerProgram) + if err != nil { + unix.Close(parentFd) + return nil, 0, err + } + + env := os.Environ() + env = append(env, "LESS=-r -P "+label) + env = append(env, "MORE=-r -P "+label) + + procAttr := &syscall.ProcAttr{ + Dir: "", + Env: env, + Files: []uintptr{ + uintptr(childFd), // stdin (fd 0) + uintptr(syscall.Stdout), // stdout (fd 1) + uintptr(syscall.Stderr), // stderr (fd 2) + }, + } + + pid, err := syscall.ForkExec(pagerPath, []string{pagerProgram}, procAttr) + if err != nil { + unix.Close(parentFd) + return nil, 0, err + } + + return parentConn, pid, nil +} diff --git a/pkg/cmd/cmdutil_windows.go b/pkg/cmd/cmdutil_windows.go new file mode 100644 index 0000000..49b025e --- /dev/null +++ b/pkg/cmd/cmdutil_windows.go @@ -0,0 +1,35 @@ +//go:build windows + +package cmd + +import ( + "os" + "syscall" + "unsafe" +) + +var ( + kernel32 = syscall.NewLazyDLL("kernel32.dll") + procPeekNamedPipe = kernel32.NewProc("PeekNamedPipe") +) + +func isPipedDataAvailableOSSpecific() bool { + // On Windows, unix.Poll is not available. Use PeekNamedPipe to check if data is available + // on the pipe without consuming it. + var available uint32 + r, _, _ := procPeekNamedPipe.Call( + os.Stdin.Fd(), + 0, + 0, + 0, + uintptr(unsafe.Pointer(&available)), + 0, + ) + return r != 0 && available > 0 +} + +func streamOutputOSSpecific(label string, generateOutput func(w *os.File) error) error { + // We have a trick with sockets that we use when possible on Unix-like systems. Those APIs aren't + // available on Windows, so we fall back to using pipes. + return streamToPagerWithPipe(label, generateOutput) +} diff --git a/pkg/cmd/flagoptions.go b/pkg/cmd/flagoptions.go new file mode 100644 index 0000000..e21dadd --- /dev/null +++ b/pkg/cmd/flagoptions.go @@ -0,0 +1,692 @@ +package cmd + +import ( + "bytes" + "encoding/base64" + "encoding/json" + "fmt" + "io" + "maps" + "mime" + "mime/multipart" + "net/http" + "os" + "path/filepath" + "reflect" + "strings" + "unicode/utf8" + + "github.com/context-dot-dev/context-go-sdk/option" + "github.com/stainless-sdks/context.dev-cli/internal/apiform" + "github.com/stainless-sdks/context.dev-cli/internal/apiquery" + "github.com/stainless-sdks/context.dev-cli/internal/debugmiddleware" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + + "github.com/goccy/go-yaml" + "github.com/urfave/cli/v3" +) + +type BodyContentType int + +const ( + EmptyBody BodyContentType = iota + MultipartFormEncoded + ApplicationJSON + ApplicationOctetStream +) + +type FileEmbedStyle int + +const ( + // EmbedText reads referenced files fully into memory and substitutes the file's contents back into the + // value as a string. Binary files are base64-encoded. Used for JSON request bodies and for headers and + // query parameters, where the file contents need to be serialized inline. + EmbedText FileEmbedStyle = iota + + // EmbedIOReader replaces file references with an io.Reader that streams the file's contents. Used for + // `multipart/form-data` and `application/octet-stream` request bodies, where files are uploaded as binary + // parts rather than embedded into a text value. + EmbedIOReader +) + +// onceStdinReader wraps an io.Reader that can only be consumed once, used to ensure stdin is read by at most +// one parameter (or only for a body root parameter or only for YAML parameter input). If reason is set, stdin +// is unavailable and read() returns an error explaining why. +type onceStdinReader struct { + stdinReader io.Reader + failureReason string +} + +func (o *onceStdinReader) read() (io.Reader, error) { + if o.failureReason != "" { + return nil, fmt.Errorf("cannot read from stdin: %s", o.failureReason) + } + if o.stdinReader == nil { + return nil, fmt.Errorf("stdin has already been read by another parameter; it can only be read once") + } + r := o.stdinReader + o.stdinReader = nil + return r, nil +} + +func (o *onceStdinReader) readAll() ([]byte, error) { + r, err := o.read() + if err != nil { + return nil, err + } + return io.ReadAll(r) +} + +func isStdinPath(s string) bool { + switch s { + case "-", "/dev/fd/0", "/dev/stdin": + return true + } + return false +} + +func embedFiles(obj any, embedStyle FileEmbedStyle, stdin *onceStdinReader) (any, error) { + if obj == nil { + return obj, nil + } + v := reflect.ValueOf(obj) + result, err := embedFilesValue(v, embedStyle, stdin) + if err != nil { + return nil, err + } + return result.Interface(), nil +} + +// Replace "@file.txt" with the file's contents inside a value +func embedFilesValue(v reflect.Value, embedStyle FileEmbedStyle, stdin *onceStdinReader) (reflect.Value, error) { + // Unwrap interface values to get the concrete type + if v.Kind() == reflect.Interface { + if v.IsNil() { + return v, nil + } + v = v.Elem() + } + + switch v.Kind() { + case reflect.Map: + if v.Len() == 0 { + return v, nil + } + // Always create map[string]any to handle potential type changes when embedding files + result := reflect.MakeMap(reflect.TypeOf(map[string]any{})) + + iter := v.MapRange() + for iter.Next() { + key := iter.Key() + val := iter.Value() + newVal, err := embedFilesValue(val, embedStyle, stdin) + if err != nil { + return reflect.Value{}, err + } + result.SetMapIndex(key, newVal) + } + return result, nil + + case reflect.Slice, reflect.Array: + if v.Len() == 0 { + return v, nil + } + // Use `[]any` to allow for types to change when embedding files + result := reflect.MakeSlice(reflect.TypeOf([]any{}), v.Len(), v.Len()) + for i := 0; i < v.Len(); i++ { + newVal, err := embedFilesValue(v.Index(i), embedStyle, stdin) + if err != nil { + return reflect.Value{}, err + } + result.Index(i).Set(newVal) + } + return result, nil + + case reflect.String: + // FilePathValue is always treated as a file path without needing the "@" prefix. + // These only appear on binary upload parameters (multipart/octet-stream), which + // always use EmbedIOReader. + if v.Type() == reflect.TypeOf(FilePathValue("")) { + s := v.String() + if s == "" { + return v, nil + } + if embedStyle == EmbedIOReader { + if isStdinPath(s) { + r, err := stdin.read() + if err != nil { + return v, err + } + return reflect.ValueOf(io.NopCloser(r)), nil + } + upload, err := openFileUpload(s) + if err != nil { + return v, err + } + return reflect.ValueOf(upload), nil + } + if isStdinPath(s) { + content, err := stdin.readAll() + if err != nil { + return v, err + } + return reflect.ValueOf(string(content)), nil + } + content, err := os.ReadFile(s) + if err != nil { + return v, err + } + return reflect.ValueOf(string(content)), nil + } + + s := v.String() + if literal, ok := strings.CutPrefix(s, "\\@"); ok { + // Allow for escaped @ signs if you don't want them to be treated as files + return reflect.ValueOf("@" + literal), nil + } + + if embedStyle == EmbedText { + if filename, ok := strings.CutPrefix(s, "@data://"); ok { + // The "@data://" prefix is for files you explicitly want to upload + // as base64-encoded (even if the file itself is plain text) + if isStdinPath(filename) { + content, err := stdin.readAll() + if err != nil { + return v, err + } + return reflect.ValueOf(base64.StdEncoding.EncodeToString(content)), nil + } + content, err := os.ReadFile(filename) + if err != nil { + return v, err + } + return reflect.ValueOf(base64.StdEncoding.EncodeToString(content)), nil + } else if filename, ok := strings.CutPrefix(s, "@file://"); ok { + // The "@file://" prefix is for files that you explicitly want to + // upload as a string literal with backslash escapes (not base64 + // encoded) + if isStdinPath(filename) { + content, err := stdin.readAll() + if err != nil { + return v, err + } + return reflect.ValueOf(string(content)), nil + } + content, err := os.ReadFile(filename) + if err != nil { + return v, err + } + return reflect.ValueOf(string(content)), nil + } else if filename, ok := strings.CutPrefix(s, "@"); ok { + if isStdinPath(filename) { + content, err := stdin.readAll() + if err != nil { + return v, err + } + if isUTF8TextFile(content) { + return reflect.ValueOf(string(content)), nil + } + return reflect.ValueOf(base64.StdEncoding.EncodeToString(content)), nil + } + content, err := os.ReadFile(filename) + if err != nil { + // If the string is "@username", it's probably supposed to be a + // string literal and not a file reference. However, if the + // string looks like "@file.txt" or "@/tmp/file", then it's + // probably supposed to be a file. + probablyFile := strings.Contains(filename, ".") || strings.Contains(filename, "/") + if probablyFile { + // Give a useful error message if the user tried to upload a + // file, but the file couldn't be read (e.g. mistyped + // filename or permission error) + return v, err + } + // Fall back to the raw value if the user provided something + // like "@username" that's not intended to be a file. + return v, nil + } + // If the file looks like a plain text UTF8 file format, then use the contents directly. + if isUTF8TextFile(content) { + return reflect.ValueOf(string(content)), nil + } + // Otherwise it's a binary file, so encode it with base64 + return reflect.ValueOf(base64.StdEncoding.EncodeToString(content)), nil + } + } else { + if filename, ok := strings.CutPrefix(s, "@"); ok { + // Behavior is the same for @file, @data://file, and @file://file, except that + // @username will be treated as a literal string if no "username" file exists + expectsFile := true + if withoutPrefix, ok := strings.CutPrefix(filename, "data://"); ok { + filename = withoutPrefix + } else if withoutPrefix, ok := strings.CutPrefix(filename, "file://"); ok { + filename = withoutPrefix + } else { + expectsFile = strings.Contains(filename, ".") || strings.Contains(filename, "/") + } + + if isStdinPath(filename) { + r, err := stdin.read() + if err != nil { + return v, err + } + return reflect.ValueOf(io.NopCloser(r)), nil + } + + upload, err := openFileUpload(filename) + if err != nil { + if !expectsFile { + // For strings that start with "@" and don't look like a filename, return the string + return v, nil + } + return v, err + } + return reflect.ValueOf(upload), nil + } + } + return v, nil + + default: + return v, nil + } +} + +// Guess whether a file's contents are binary (e.g. a .jpg or .mp3), as opposed +// to plain text (e.g. .txt or .md). +func isUTF8TextFile(content []byte) bool { + // Go's DetectContentType follows https://mimesniff.spec.whatwg.org/ and + // these are the sniffable content types that are plain text: + textTypes := []string{ + "text/", + "application/json", + "application/xml", + "application/javascript", + "application/x-javascript", + "application/ecmascript", + "application/x-ecmascript", + } + + contentType := http.DetectContentType(content) + for _, prefix := range textTypes { + if strings.HasPrefix(contentType, prefix) { + return utf8.Valid(content) + } + } + return false +} + +func flagOptions( + cmd *cli.Command, + nestedFormat apiquery.NestedQueryFormat, + arrayFormat apiquery.ArrayQueryFormat, + bodyType BodyContentType, + + // This parameter is true if stdin is already in use to pass a binary parameter by using the special value + // "-". In this case, we won't attempt to read it as a JSON/YAML blob for options setting. + ignoreStdin bool, +) ([]option.RequestOption, error) { + var options []option.RequestOption + if cmd.Bool("debug") { + options = append(options, option.WithMiddleware(debugmiddleware.NewRequestLogger().Middleware())) + } + + requestContents := requestflag.ExtractRequestContents(cmd) + + // Translate inner-field aliases in YAML values that came from flags (e.g. + // `--parent '{"alias": val}'` resolving to the canonical inner field). + if bodyMap, ok := requestContents.Body.(map[string]any); ok { + applyDataAliases(cmd, bodyMap) + } + + stdinConsumedByPipe := false + if bodyType != ApplicationOctetStream && !ignoreStdin && isInputPiped() { + pipeData, err := io.ReadAll(os.Stdin) + if err != nil { + return nil, err + } + + if len(pipeData) > 0 { + stdinConsumedByPipe = true + var bodyData any + if err := yaml.Unmarshal(pipeData, &bodyData); err != nil { + return nil, fmt.Errorf("Failed to parse piped data as YAML/JSON:\n%w", err) + } + if bodyMap, ok := bodyData.(map[string]any); ok { + applyDataAliases(cmd, bodyMap) + // Apply any matching keys from the piped data to path, query, and header flags + // that have not already been set via the command line. + if err := requestflag.ApplyStdinDataToFlags(cmd, bodyMap); err != nil { + return nil, err + } + // Re-extract request contents now that flags may have been updated. + requestContents = requestflag.ExtractRequestContents(cmd) + // Remove keys that were consumed as query, header, or path params so they + // don't also leak into the request body via the maps.Copy merge below. + // We delete both the canonical key and any aliases since the user may have + // piped data using an alias name rather than the canonical API name. + for _, flag := range cmd.Flags { + inReq, ok := flag.(requestflag.InRequest) + if !ok || !flag.IsSet() { + continue + } + if inReq.GetQueryPath() != "" || inReq.GetHeaderPath() != "" || inReq.GetPathParam() != "" { + delete(bodyMap, inReq.GetQueryPath()) + delete(bodyMap, inReq.GetHeaderPath()) + delete(bodyMap, inReq.GetPathParam()) + for _, alias := range inReq.GetDataAliases() { + delete(bodyMap, alias) + } + } + } + if bodyType != EmptyBody { + if flagMap, ok := requestContents.Body.(map[string]any); ok { + maps.Copy(bodyMap, flagMap) + requestContents.Body = bodyMap + } else { + bodyData = requestContents.Body + } + } + } else if bodyType != EmptyBody { + if flagMap, ok := requestContents.Body.(map[string]any); ok && len(flagMap) > 0 { + return nil, fmt.Errorf("Cannot merge flags with a body that is not a map: %v", bodyData) + } else { + requestContents.Body = bodyData + } + } + } + } + + if missingFlags := requestflag.GetMissingRequiredFlags(cmd, requestContents.Body); len(missingFlags) > 0 { + if len(missingFlags) == 1 { + return nil, fmt.Errorf("Required flag %q not set\nRun '%s --help' for usage information", missingFlags[0].Names()[0], cmd.FullName()) + } else { + names := []string{} + for _, flag := range missingFlags { + names = append(names, flag.Names()[0]) + } + return nil, fmt.Errorf("Required flags %q not set\nRun '%s --help' for usage information", strings.Join(names, ", "), cmd.FullName()) + } + } + + // For flags marked as FileInput (type: string, format: binary), the value is always + // a file path. Wrap with FilePathValue so embedFiles reads the file automatically + // without requiring the user to type the "@" prefix. This handles both values set + // via explicit CLI flags and values that arrived via piped YAML/JSON data. + wrapFileInputValues(cmd, &requestContents) + + // Determine stdin availability for FileInput params that use "-". + var stdinReader onceStdinReader + if ignoreStdin { + stdinReader = onceStdinReader{failureReason: "stdin is already being used for the request body"} + } else if stdinConsumedByPipe { + stdinReader = onceStdinReader{failureReason: "stdin was already consumed by piped YAML/JSON input"} + } else { + stdinReader = onceStdinReader{stdinReader: os.Stdin} + } + + // Embed files passed as "@file.jpg" in the request body, headers, and query: + embedStyle := EmbedText + if bodyType == ApplicationOctetStream || bodyType == MultipartFormEncoded { + embedStyle = EmbedIOReader + } + + if embedded, err := embedFiles(requestContents.Body, embedStyle, &stdinReader); err != nil { + return nil, err + } else { + requestContents.Body = embedded + } + + if headersWithFiles, err := embedFiles(requestContents.Headers, EmbedText, &stdinReader); err != nil { + return nil, err + } else { + requestContents.Headers = headersWithFiles.(map[string]any) + } + if queriesWithFiles, err := embedFiles(requestContents.Queries, EmbedText, &stdinReader); err != nil { + return nil, err + } else { + requestContents.Queries = queriesWithFiles.(map[string]any) + } + + querySettings := apiquery.QuerySettings{ + NestedFormat: nestedFormat, + ArrayFormat: arrayFormat, + } + + // Add query parameters: + if values, err := apiquery.MarshalWithSettings(requestContents.Queries, querySettings); err != nil { + return nil, err + } else { + for k, vs := range values { + if len(vs) == 0 { + options = append(options, option.WithQueryDel(k)) + } else { + options = append(options, option.WithQuery(k, vs[0])) + for _, v := range vs[1:] { + options = append(options, option.WithQueryAdd(k, v)) + } + } + } + } + + // Add header parameters + headerSettings := apiquery.QuerySettings{ + NestedFormat: apiquery.NestedQueryFormatDots, + ArrayFormat: apiquery.ArrayQueryFormatRepeat, + } + if values, err := apiquery.MarshalWithSettings(requestContents.Headers, headerSettings); err != nil { + return nil, err + } else { + for k, vs := range values { + if len(vs) == 0 { + options = append(options, option.WithHeaderDel(k)) + } else { + options = append(options, option.WithHeader(k, vs[0])) + for _, v := range vs[1:] { + options = append(options, option.WithHeaderAdd(k, v)) + } + } + } + } + + switch bodyType { + case EmptyBody: + break + case MultipartFormEncoded: + buf := new(bytes.Buffer) + writer := multipart.NewWriter(buf) + + // For multipart/form-encoded, we need a map structure + bodyMap, ok := requestContents.Body.(map[string]any) + if !ok { + return nil, fmt.Errorf("Cannot send a non-map value to a form-encoded endpoint: %v\n", requestContents.Body) + } + encodingFormat := apiform.FormatComma + if err := apiform.MarshalWithSettings(bodyMap, writer, encodingFormat); err != nil { + return nil, err + } + if err := writer.Close(); err != nil { + return nil, err + } + options = append(options, option.WithRequestBody(writer.FormDataContentType(), buf)) + + case ApplicationJSON: + bodyBytes, err := json.Marshal(requestContents.Body) + if err != nil { + return nil, err + } + options = append(options, option.WithRequestBody("application/json", bodyBytes)) + + case ApplicationOctetStream: + // If there is a body root parameter, that will handle setting the request body, we don't need to do it here. + for _, flag := range cmd.Flags { + if toSend, ok := flag.(requestflag.InRequest); ok && toSend.IsBodyRoot() { + return options, nil + } + } + if bodyBytes, ok := requestContents.Body.([]byte); ok { + options = append(options, option.WithRequestBody("application/octet-stream", bodyBytes)) + } else if bodyStr, ok := requestContents.Body.(string); ok { + options = append(options, option.WithRequestBody("application/octet-stream", []byte(bodyStr))) + } else { + return nil, fmt.Errorf("Unsupported body for application/octet-stream: %v", requestContents.Body) + } + + default: + panic("Invalid body content type!") + } + + return options, nil +} + +// FilePathValue is a string wrapper that marks a value as a file path whose contents should be read +// and embedded in the request. Unlike a regular string, embedFilesValue always treats a FilePathValue +// as a file path without needing the "@" prefix. +type FilePathValue string + +// fileUpload wraps an io.Reader with filename and content-type metadata for +// use as a multipart form part. The apiform encoder detects the Filename and +// ContentType methods and uses them to populate the Content-Disposition +// filename and the Content-Type header on the part. +type fileUpload struct { + io.Reader // apiform checks for reader and reads its contents during encode + filename string + contentType string +} + +func (f fileUpload) Filename() string { return f.filename } +func (f fileUpload) ContentType() string { return f.contentType } +func (f fileUpload) Close() error { + if c, ok := f.Reader.(io.Closer); ok { + return c.Close() + } + return nil +} + +// openFileUpload opens the file at path and returns a fileUpload whose filename +// is the path's basename and whose content type is derived from the file +// extension (falling back to application/octet-stream when unknown). +func openFileUpload(path string) (fileUpload, error) { + file, err := os.Open(path) + if err != nil { + return fileUpload{}, err + } + contentType := mime.TypeByExtension(filepath.Ext(path)) + if contentType == "" { + contentType = "application/octet-stream" + } + return fileUpload{ + Reader: file, + filename: filepath.Base(path), + contentType: contentType, + }, nil +} + +// applyDataAliases rewrites keys in a body map based on flag `DataAliases` metadata. For top-level flags, +// `{alias: value}` becomes `{canonical: value}`. For inner flags (those registered under an outer flag +// via WithInnerFlags), the alias translation is also applied to the nested map under the outer flag's +// body path, so values like `--parent '{"alias": val}'` resolve to the canonical inner field name. +func applyDataAliases(cmd *cli.Command, bodyMap map[string]any) { + for _, flag := range cmd.Flags { + // Inner flags: rewrite aliases inside the nested map under the outer flag's body path. + if inner, ok := flag.(requestflag.HasOuterFlag); ok { + outer, outerOk := inner.GetOuterFlag().(requestflag.InRequest) + if !outerOk { + continue + } + if nested, ok := bodyMap[outer.GetBodyPath()].(map[string]any); ok && inner.GetInnerField() != "" { + rewriteAliases(nested, inner.GetInnerField(), inner.GetDataAliases()) + } + continue + } + // Top-level flags: rewrite aliases in the body map. + if inReq, ok := flag.(requestflag.InRequest); ok && inReq.GetBodyPath() != "" { + rewriteAliases(bodyMap, inReq.GetBodyPath(), inReq.GetDataAliases()) + } + } +} + +// rewriteAliases replaces each alias key in m with the canonical key, preserving the value. The +// "canonical" key is the name the API itself expects (the OpenAPI property/field name) — e.g. for +// a top-level flag, the parameter's BodyPath; for an inner flag, the inner field name. Aliases are +// the user-facing alternate names declared via x-stainless-cli-data-alias. +func rewriteAliases(m map[string]any, canonical string, aliases []string) { + for _, alias := range aliases { + if alias == "" || alias == canonical { + continue + } + if val, exists := m[alias]; exists { + m[canonical] = val + delete(m, alias) + } + } +} + +// wrapFileInputValues replaces string values for FileInput flags (type: string, format: binary) with +// FilePathValue sentinel values. embedFilesValue recognizes FilePathValue and reads the file contents +// directly, so the user doesn't need to type the "@" prefix. This handles both values set via explicit +// CLI flags and values that arrived via piped YAML/JSON data. +func wrapFileInputValues(cmd *cli.Command, contents *requestflag.RequestContents) { + bodyMap, _ := contents.Body.(map[string]any) + + for _, flag := range cmd.Flags { + inReq, ok := flag.(requestflag.InRequest) + if !ok || !inReq.IsFileInput() || inReq.IsBodyRoot() { + continue + } + + // Wrap values set via explicit CLI flags. + if flag.IsSet() { + if wrapped, changed := wrapFileInputValue(flag.Get()); changed { + if bodyPath := inReq.GetBodyPath(); bodyPath != "" { + if bodyMap != nil { + bodyMap[bodyPath] = wrapped + } + } else if queryPath := inReq.GetQueryPath(); queryPath != "" { + contents.Queries[queryPath] = wrapped + } else if headerPath := inReq.GetHeaderPath(); headerPath != "" { + contents.Headers[headerPath] = wrapped + } + } + } + + // Wrap values that arrived via piped YAML/JSON data in the body map. + if bodyPath := inReq.GetBodyPath(); bodyPath != "" && bodyMap != nil { + if value, exists := bodyMap[bodyPath]; exists { + if wrapped, changed := wrapFileInputValue(value); changed { + bodyMap[bodyPath] = wrapped + } + } + } + } +} + +func wrapFileInputValue(value any) (any, bool) { + switch v := value.(type) { + case string: + if v == "" { + return value, false + } + return FilePathValue(v), true + + case []string: + result := make([]any, len(v)) + for i, s := range v { + result[i] = FilePathValue(s) + } + return result, true + + case []any: + result := make([]any, len(v)) + for i, elem := range v { + if s, ok := elem.(string); ok { + result[i] = FilePathValue(s) + } else { + result[i] = elem + } + } + return result, true + + default: + return value, false + } +} diff --git a/pkg/cmd/flagoptions_test.go b/pkg/cmd/flagoptions_test.go new file mode 100644 index 0000000..00734ca --- /dev/null +++ b/pkg/cmd/flagoptions_test.go @@ -0,0 +1,392 @@ +package cmd + +import ( + "encoding/base64" + "io" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIsUTF8TextFile(t *testing.T) { + t.Parallel() + + tests := []struct { + content []byte + expected bool + }{ + {[]byte("Hello, world!"), true}, + {[]byte(`{"key": "value"}`), true}, + {[]byte(``), true}, + {[]byte(`function test() {}`), true}, + {[]byte{0xFF, 0xD8, 0xFF, 0xE0}, false}, // JPEG header + {[]byte{0x00, 0x01, 0xFF, 0xFE}, false}, // binary + {[]byte("Hello \xFF\xFE"), false}, // invalid UTF-8 + {[]byte("Hello ☺️"), true}, // emoji + {[]byte{}, true}, // empty + } + + for _, tt := range tests { + require.Equal(t, tt.expected, isUTF8TextFile(tt.content)) + } +} + +func TestEmbedFiles(t *testing.T) { + t.Parallel() + + // Create temporary directory for test files + tmpDir := t.TempDir() + + // Create test files + configContent := "host=localhost\nport=8080" + templateContent := "Hello" + dataContent := `{"key": "value"}` + + writeTestFile(t, tmpDir, "config.txt", configContent) + writeTestFile(t, tmpDir, "template.html", templateContent) + writeTestFile(t, tmpDir, "data.json", dataContent) + jpegHeader := []byte{0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46} + writeTestFile(t, tmpDir, "image.jpg", string(jpegHeader)) + + tests := []struct { + name string + input any + want any + wantErr bool + }{ + { + name: "map[string]any with file references", + input: map[string]any{ + "config": "@" + filepath.Join(tmpDir, "config.txt"), + "template": "@file://" + filepath.Join(tmpDir, "template.html"), + "count": 42, + }, + want: map[string]any{ + "config": configContent, + "template": templateContent, + "count": 42, + }, + wantErr: false, + }, + { + name: "map[string]string with file references", + input: map[string]any{ + "config": "@" + filepath.Join(tmpDir, "config.txt"), + "name": "test", + }, + want: map[string]any{ + "config": configContent, + "name": "test", + }, + wantErr: false, + }, + { + name: "[]any with file references", + input: []any{ + "@" + filepath.Join(tmpDir, "config.txt"), + 42, + true, + "@file://" + filepath.Join(tmpDir, "data.json"), + }, + want: []any{ + configContent, + 42, + true, + dataContent, + }, + wantErr: false, + }, + { + name: "[]string with file references", + input: []any{ + "@" + filepath.Join(tmpDir, "config.txt"), + "normal string", + }, + want: []any{ + configContent, + "normal string", + }, + wantErr: false, + }, + { + name: "nested structures", + input: map[string]any{ + "outer": map[string]any{ + "inner": []any{ + "@" + filepath.Join(tmpDir, "config.txt"), + map[string]any{ + "data": "@" + filepath.Join(tmpDir, "data.json"), + }, + }, + }, + }, + want: map[string]any{ + "outer": map[string]any{ + "inner": []any{ + configContent, + map[string]any{ + "data": dataContent, + }, + }, + }, + }, + wantErr: false, + }, + { + name: "base64 encoding", + input: map[string]any{ + "encoded": "@data://" + filepath.Join(tmpDir, "config.txt"), + "image": "@" + filepath.Join(tmpDir, "image.jpg"), + }, + want: map[string]any{ + "encoded": base64.StdEncoding.EncodeToString([]byte(configContent)), + "image": base64.StdEncoding.EncodeToString(jpegHeader), + }, + wantErr: false, + }, + { + name: "non-existent file with @ prefix", + input: map[string]any{ + "missing": "@file.txt", + }, + want: nil, + wantErr: true, + }, + { + name: "non-file-like thing with @ prefix", + input: map[string]any{ + "username": "@user", + "favorite_symbol": "@", + }, + want: map[string]any{ + "username": "@user", + "favorite_symbol": "@", + }, + wantErr: false, + }, + { + name: "non-existent file with @file:// prefix (error)", + input: map[string]any{ + "missing": "@file:///nonexistent/file.txt", + }, + want: nil, + wantErr: true, + }, + { + name: "escaping", + input: map[string]any{ + "simple": "\\@file.txt", + "file": "\\@file://file.txt", + "data": "\\@data://file.txt", + "keep_escape": "user\\@example.com", + }, + want: map[string]any{ + "simple": "@file.txt", + "file": "@file://file.txt", + "data": "@data://file.txt", + "keep_escape": "user\\@example.com", + }, + wantErr: false, + }, + { + name: "primitive types", + input: map[string]any{ + "int": 123, + "float": 45.67, + "bool": true, + "null": nil, + "string": "no prefix", + "email": "user@example.com", + }, + want: map[string]any{ + "int": 123, + "float": 45.67, + "bool": true, + "null": nil, + "string": "no prefix", + "email": "user@example.com", + }, + wantErr: false, + }, + { + name: "[]int values unchanged", + input: []int{1, 2, 3, 4, 5}, + want: []any{1, 2, 3, 4, 5}, + wantErr: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name+" text", func(t *testing.T) { + t.Parallel() + + got, err := embedFiles(tt.input, EmbedText, nil) + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Equal(t, tt.want, got) + } + }) + + t.Run(tt.name+" io.Reader", func(t *testing.T) { + t.Parallel() + + _, err := embedFiles(tt.input, EmbedIOReader, nil) + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} + +func TestEmbedFilesStdin(t *testing.T) { + t.Parallel() + + t.Run("FilePathValueDash", func(t *testing.T) { + t.Parallel() + + stdin := &onceStdinReader{stdinReader: strings.NewReader("stdin content")} + + withEmbedded, err := embedFiles(map[string]any{"file": FilePathValue("-")}, EmbedText, stdin) + require.NoError(t, err) + require.Equal(t, map[string]any{"file": "stdin content"}, withEmbedded) + }) + + t.Run("FilePathValueDevStdin", func(t *testing.T) { + t.Parallel() + + stdin := &onceStdinReader{stdinReader: strings.NewReader("stdin content")} + + withEmbedded, err := embedFiles(map[string]any{"file": FilePathValue("/dev/stdin")}, EmbedText, stdin) + require.NoError(t, err) + require.Equal(t, map[string]any{"file": "stdin content"}, withEmbedded) + }) + + t.Run("MultipleFilePathValueDashesError", func(t *testing.T) { + t.Parallel() + + stdin := &onceStdinReader{stdinReader: strings.NewReader("stdin content")} + + _, err := embedFiles(map[string]any{ + "file1": FilePathValue("-"), + "file2": FilePathValue("-"), + }, EmbedText, stdin) + require.Error(t, err) + require.Contains(t, err.Error(), "already been read") + }) + + t.Run("FilePathValueDashUnavailableStdin", func(t *testing.T) { + t.Parallel() + + stdin := &onceStdinReader{failureReason: "stdin is already being used for the request body"} + + _, err := embedFiles(map[string]any{"file": FilePathValue("-")}, EmbedText, stdin) + require.Error(t, err) + require.Contains(t, err.Error(), "cannot read from stdin") + require.Contains(t, err.Error(), "request body") + }) + + t.Run("AtDashEmbedText", func(t *testing.T) { + t.Parallel() + + stdin := &onceStdinReader{stdinReader: strings.NewReader("piped content")} + + withEmbedded, err := embedFiles(map[string]any{"data": "@-"}, EmbedText, stdin) + require.NoError(t, err) + require.Equal(t, map[string]any{"data": "piped content"}, withEmbedded) + }) + + t.Run("AtDashEmbedIOReader", func(t *testing.T) { + t.Parallel() + + stdin := &onceStdinReader{stdinReader: strings.NewReader("piped content")} + + withEmbedded, err := embedFiles(map[string]any{"data": "@-"}, EmbedIOReader, stdin) + require.NoError(t, err) + + withEmbeddedMap := withEmbedded.(map[string]any) + r := withEmbeddedMap["data"].(io.ReadCloser) + + content, err := io.ReadAll(r) + require.NoError(t, err) + require.Equal(t, "piped content", string(content)) + }) + + t.Run("FilePathValueRealFile", func(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + writeTestFile(t, tmpDir, "test.txt", "file content") + + stdin := &onceStdinReader{stdinReader: strings.NewReader("unused stdin")} + + withEmbedded, err := embedFiles(map[string]any{"file": FilePathValue(filepath.Join(tmpDir, "test.txt"))}, EmbedText, stdin) + require.NoError(t, err) + require.Equal(t, map[string]any{"file": "file content"}, withEmbedded) + }) +} + +// TestEmbedFilesUploadMetadata verifies that EmbedIOReader mode wraps file readers with filename and +// content-type metadata so the multipart encoder populates `Content-Disposition` and `Content-Type` headers. +func TestEmbedFilesUploadMetadata(t *testing.T) { + t.Parallel() + + tmpDir := t.TempDir() + writeTestFile(t, tmpDir, "hello.txt", "hi") + writeTestFile(t, tmpDir, "page.html", "") + writeTestFile(t, tmpDir, "blob.bin", "\x00\x01") + + cases := []struct { + basename string + wantContentType string + }{ + {"hello.txt", "text/plain; charset=utf-8"}, + {"page.html", "text/html; charset=utf-8"}, + {"blob.bin", "application/octet-stream"}, + } + + for _, tc := range cases { + t.Run("AtPrefix_"+tc.basename, func(t *testing.T) { + t.Parallel() + + path := filepath.Join(tmpDir, tc.basename) + withEmbedded, err := embedFiles(map[string]any{"file": "@" + path}, EmbedIOReader, nil) + require.NoError(t, err) + + upload, ok := withEmbedded.(map[string]any)["file"].(fileUpload) + require.True(t, ok, "expected fileUpload, got %T", withEmbedded.(map[string]any)["file"]) + require.Equal(t, tc.basename, upload.Filename()) + require.Equal(t, upload.ContentType(), tc.wantContentType) + require.NoError(t, upload.Close()) + }) + + t.Run("FilePathValue_"+tc.basename, func(t *testing.T) { + t.Parallel() + + path := filepath.Join(tmpDir, tc.basename) + withEmbedded, err := embedFiles(map[string]any{"file": FilePathValue(path)}, EmbedIOReader, nil) + require.NoError(t, err) + + upload, ok := withEmbedded.(map[string]any)["file"].(fileUpload) + require.True(t, ok, "expected fileUpload, got %T", withEmbedded.(map[string]any)["file"]) + require.Equal(t, tc.basename, upload.Filename()) + require.Equal(t, upload.ContentType(), tc.wantContentType) + require.NoError(t, upload.Close()) + }) + } +} + +func writeTestFile(t *testing.T, dir, filename, content string) { + t.Helper() + + path := filepath.Join(dir, filename) + + err := os.WriteFile(path, []byte(content), 0644) + require.NoError(t, err, "failed to write test file %s", path) +} diff --git a/pkg/cmd/industry.go b/pkg/cmd/industry.go new file mode 100644 index 0000000..68861ee --- /dev/null +++ b/pkg/cmd/industry.go @@ -0,0 +1,169 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-go-sdk" + "github.com/context-dot-dev/context-go-sdk/option" + "github.com/stainless-sdks/context.dev-cli/internal/apiquery" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var industryRetrieveNaics = cli.Command{ + Name: "retrieve-naics", + Usage: "Classify any brand into 2022 NAICS industry codes from its domain or name.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "input", + Usage: "Brand domain or title to retrieve NAICS code for. If a valid domain is provided, it will be used for classification, otherwise, we will search for the brand using the provided title.", + Required: true, + QueryPath: "input", + }, + &requestflag.Flag[int64]{ + Name: "max-results", + Usage: "Maximum number of NAICS codes to return. Must be between 1 and 10. Defaults to 5.", + Default: 5, + QueryPath: "maxResults", + }, + &requestflag.Flag[int64]{ + Name: "min-results", + Usage: "Minimum number of NAICS codes to return. Must be at least 1. Defaults to 1.", + Default: 1, + QueryPath: "minResults", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleIndustryRetrieveNaics, + HideHelpCommand: true, +} + +var industryRetrieveSic = cli.Command{ + Name: "retrieve-sic", + Usage: "Classify any brand into Standard Industrial Classification (SIC) codes from its\ndomain or name. Choose between the original SIC system (`original_sic`) or the\nlatest SIC list maintained by the SEC (`latest_sec`).", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "input", + Usage: "Brand domain or title to retrieve SIC code for. If a valid domain is provided, it will be used for classification, otherwise, we will search for the brand using the provided title.", + Required: true, + QueryPath: "input", + }, + &requestflag.Flag[int64]{ + Name: "max-results", + Usage: "Maximum number of SIC codes to return. Must be between 1 and 10. Defaults to 5.", + Default: 5, + QueryPath: "maxResults", + }, + &requestflag.Flag[int64]{ + Name: "min-results", + Usage: "Minimum number of SIC codes to return. Must be at least 1. Defaults to 1.", + Default: 1, + QueryPath: "minResults", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + &requestflag.Flag[string]{ + Name: "type", + Usage: "Which SIC dataset to classify against. `original_sic` uses the 1987 Standard Industrial Classification system; `latest_sec` uses the current SIC list as published by the SEC. Defaults to `original_sic`.", + Default: "original_sic", + QueryPath: "type", + }, + }, + Action: handleIndustryRetrieveSic, + HideHelpCommand: true, +} + +func handleIndustryRetrieveNaics(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.IndustryGetNaicsParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Industry.GetNaics(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "industry retrieve-naics", + Transform: transform, + }) +} + +func handleIndustryRetrieveSic(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.IndustryGetSicParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Industry.GetSic(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "industry retrieve-sic", + Transform: transform, + }) +} diff --git a/pkg/cmd/industry_test.go b/pkg/cmd/industry_test.go new file mode 100644 index 0000000..709922c --- /dev/null +++ b/pkg/cmd/industry_test.go @@ -0,0 +1,40 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/stainless-sdks/context.dev-cli/internal/mocktest" +) + +func TestIndustryRetrieveNaics(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "industry", "retrieve-naics", + "--input", "input", + "--max-results", "1", + "--min-results", "1", + "--timeout-ms", "1000", + ) + }) +} + +func TestIndustryRetrieveSic(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "industry", "retrieve-sic", + "--input", "input", + "--max-results", "1", + "--min-results", "1", + "--timeout-ms", "1000", + "--type", "original_sic", + ) + }) +} diff --git a/pkg/cmd/suggest.go b/pkg/cmd/suggest.go new file mode 100644 index 0000000..b4b637c --- /dev/null +++ b/pkg/cmd/suggest.go @@ -0,0 +1,126 @@ +package cmd + +import ( + "fmt" + "math" + "slices" + "strings" + + "github.com/urfave/cli/v3" +) + +// This entire file is mostly taken from urfave/cli/v3's source, with the exception of suggestCommand which is +// modified for a nicer error message. + +// jaroDistance is the measure of similarity between two strings. It returns a +// value between 0 and 1, where 1 indicates identical strings and 0 indicates +// completely different strings. +// +// Adapted from https://github.com/xrash/smetrics/blob/5f08fbb34913bc8ab95bb4f2a89a0637ca922666/jaro.go. +func jaroDistance(a, b string) float64 { + if len(a) == 0 && len(b) == 0 { + return 1 + } + if len(a) == 0 || len(b) == 0 { + return 0 + } + + lenA := float64(len(a)) + lenB := float64(len(b)) + hashA := make([]bool, len(a)) + hashB := make([]bool, len(b)) + maxDistance := int(math.Max(0, math.Floor(math.Max(lenA, lenB)/2.0)-1)) + + var matches float64 + for i := 0; i < len(a); i++ { + start := int(math.Max(0, float64(i-maxDistance))) + end := int(math.Min(lenB-1, float64(i+maxDistance))) + + for j := start; j <= end; j++ { + if hashB[j] { + continue + } + if a[i] == b[j] { + hashA[i] = true + hashB[j] = true + matches++ + break + } + } + } + if matches == 0 { + return 0 + } + + var transpositions float64 + var j int + for i := 0; i < len(a); i++ { + if !hashA[i] { + continue + } + for !hashB[j] { + j++ + } + if a[i] != b[j] { + transpositions++ + } + j++ + } + + transpositions /= 2 + return ((matches / lenA) + (matches / lenB) + ((matches - transpositions) / matches)) / 3.0 +} + +// jaroWinkler is more accurate when strings have a common prefix up to a +// defined maximum length. +// +// Adapted from https://github.com/xrash/smetrics/blob/5f08fbb34913bc8ab95bb4f2a89a0637ca922666/jaro-winkler.go. +func jaroWinkler(a, b string) float64 { + const ( + boostThreshold = 0.7 + prefixSize = 4 + ) + jaroDist := jaroDistance(a, b) + if jaroDist <= boostThreshold { + return jaroDist + } + + prefix := int(math.Min(float64(len(a)), math.Min(float64(prefixSize), float64(len(b))))) + + var prefixMatch float64 + for i := 0; i < prefix; i++ { + if a[i] == b[i] { + prefixMatch++ + } else { + break + } + } + return jaroDist + 0.1*prefixMatch*(1.0-jaroDist) +} + +// suggestCommand takes a list of commands and a provided string to suggest a +// command name +func suggestCommand(commands []*cli.Command, provided string) string { + distance := 0.0 + var lineage []*cli.Command + for _, command := range commands { + for _, name := range command.Names() { + newDistance := jaroWinkler(name, provided) + if newDistance > distance { + distance = newDistance + lineage = command.Lineage() + } + } + } + + var parts []string + for _, command := range lineage { + parts = append(parts, command.Name) + } + slices.Reverse(parts) + return fmt.Sprintf("Did you mean '%s'?", strings.Join(parts, " ")) +} + +func init() { + cli.SuggestCommand = suggestCommand +} diff --git a/pkg/cmd/utility.go b/pkg/cmd/utility.go new file mode 100644 index 0000000..b2812ec --- /dev/null +++ b/pkg/cmd/utility.go @@ -0,0 +1,139 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-go-sdk" + "github.com/context-dot-dev/context-go-sdk/option" + "github.com/stainless-sdks/context.dev-cli/internal/apiquery" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var utilityPrefetch = cli.Command{ + Name: "prefetch", + Usage: "Signal that you may fetch brand data for a particular domain soon to improve\nlatency.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "domain", + Usage: "Domain name to prefetch brand data for", + Required: true, + BodyPath: "domain", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + }, + Action: handleUtilityPrefetch, + HideHelpCommand: true, +} + +var utilityPrefetchByEmail = cli.Command{ + Name: "prefetch-by-email", + Usage: "Signal that you may fetch brand data for a particular domain soon to improve\nlatency. This endpoint accepts an email address, extracts the domain from it,\nvalidates that it's not a disposable or free email provider, and queues the\ndomain for prefetching.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "email", + Usage: "Email address to prefetch brand data for. The domain will be extracted from the email. Free email providers (gmail.com, yahoo.com, etc.) and disposable email addresses are not allowed.", + Required: true, + BodyPath: "email", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + }, + Action: handleUtilityPrefetchByEmail, + HideHelpCommand: true, +} + +func handleUtilityPrefetch(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.UtilityPrefetchParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Utility.Prefetch(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "utility prefetch", + Transform: transform, + }) +} + +func handleUtilityPrefetchByEmail(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.UtilityPrefetchByEmailParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Utility.PrefetchByEmail(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "utility prefetch-by-email", + Transform: transform, + }) +} diff --git a/pkg/cmd/utility_test.go b/pkg/cmd/utility_test.go new file mode 100644 index 0000000..72d48cf --- /dev/null +++ b/pkg/cmd/utility_test.go @@ -0,0 +1,59 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/stainless-sdks/context.dev-cli/internal/mocktest" +) + +func TestUtilityPrefetch(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "utility", "prefetch", + "--domain", "domain", + "--timeout-ms", "1000", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "domain: domain\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "utility", "prefetch", + ) + }) +} + +func TestUtilityPrefetchByEmail(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "utility", "prefetch-by-email", + "--email", "dev@stainless.com", + "--timeout-ms", "1000", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "email: dev@stainless.com\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "utility", "prefetch-by-email", + ) + }) +} diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go new file mode 100644 index 0000000..ad586f4 --- /dev/null +++ b/pkg/cmd/version.go @@ -0,0 +1,5 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +const Version = "0.0.1" diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go new file mode 100644 index 0000000..8a9249b --- /dev/null +++ b/pkg/cmd/web.go @@ -0,0 +1,1237 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-go-sdk" + "github.com/context-dot-dev/context-go-sdk/option" + "github.com/stainless-sdks/context.dev-cli/internal/apiquery" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var webExtract = requestflag.WithInnerFlags(cli.Command{ + Name: "extract", + Usage: "Crawl a website, use the provided JSON Schema and instructions to prioritize\nrelevant internal links, and extract structured data from the selected pages.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[map[string]any]{ + Name: "schema", + Usage: "JSON Schema for the returned data object. TypeScript Zod users can pass a JSON Schema generated from a Zod object; Python users can pass the equivalent JSON Schema object.", + Required: true, + BodyPath: "schema", + }, + &requestflag.Flag[string]{ + Name: "url", + Usage: "The starting website URL to crawl and extract from. Must include http:// or https://.", + Required: true, + BodyPath: "url", + }, + &requestflag.Flag[bool]{ + Name: "fact-check", + Usage: "When true, every returned value must be grounded in facts stated on the page; fields that cannot be supported by the page are returned as null/empty. When false (default), the model may make reasonable inferences and derivations from the page content (e.g. ideal customer, competitor analysis, recommendations) while keeping verifiable specifics (names, quotes, URLs, dates, metrics) faithful to the source.", + Default: false, + BodyPath: "factCheck", + }, + &requestflag.Flag[bool]{ + Name: "follow-subdomains", + Usage: "When true, follow links on subdomains of the starting URL's domain.", + Default: false, + BodyPath: "followSubdomains", + }, + &requestflag.Flag[bool]{ + Name: "include-frames", + Usage: "When true, iframe contents are included in Markdown before extraction.", + Default: false, + BodyPath: "includeFrames", + }, + &requestflag.Flag[string]{ + Name: "instructions", + Usage: "Optional extraction guidance, such as which facts to prioritize or how to interpret fields in the schema.", + BodyPath: "instructions", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Return cached scrape results if a prior scrape for the same parameters is younger than this many milliseconds. Defaults to 7 days (604800000 ms).", + Default: 604800000, + BodyPath: "maxAgeMs", + }, + &requestflag.Flag[int64]{ + Name: "max-depth", + Usage: "Optional maximum link depth from the starting URL (0 = only the starting page). If omitted, there is no crawl depth limit.", + BodyPath: "maxDepth", + }, + &requestflag.Flag[int64]{ + Name: "max-pages", + Usage: "Maximum number of pages to analyze for extraction. Hard cap: 50. Defaults to 5.", + Default: 5, + BodyPath: "maxPages", + }, + &requestflag.Flag[map[string]any]{ + Name: "pdf", + Default: map[string]any{"shouldParse": true}, + BodyPath: "pdf", + }, + &requestflag.Flag[int64]{ + Name: "stop-after-ms", + Usage: "Soft time budget for the crawl in milliseconds. Min: 10000 (10s). Max: 110000 (110s). Default: 80000 (80s).", + Default: 80000, + BodyPath: "stopAfterMs", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + &requestflag.Flag[int64]{ + Name: "wait-for-ms", + Usage: "Optional browser wait time in milliseconds after initial page load for each crawled page.", + BodyPath: "waitForMs", + }, + }, + Action: handleWebExtract, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "pdf": { + &requestflag.InnerFlag[int64]{ + Name: "pdf.end", + Usage: "Last 1-based PDF page to parse. Must be greater than or equal to start when both are provided.", + InnerField: "end", + }, + &requestflag.InnerFlag[bool]{ + Name: "pdf.should-parse", + Usage: "When true, PDF pages are fetched and parsed. When false, PDF pages are skipped.", + InnerField: "shouldParse", + }, + &requestflag.InnerFlag[int64]{ + Name: "pdf.start", + Usage: "First 1-based PDF page to parse.", + InnerField: "start", + }, + }, +}) + +var webExtractCompetitors = cli.Command{ + Name: "extract-competitors", + Usage: "Analyze a company's landing page and web search evidence to return direct\ncompetitors for the same product or market.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "domain", + Usage: "Company domain to analyze, such as `stripe.com`. Full http(s) URLs are accepted and normalized to their domain.", + Required: true, + QueryPath: "domain", + }, + &requestflag.Flag[int64]{ + Name: "num-competitors", + Usage: "Exact number of direct competitors to return. Defaults to 5.", + Default: 5, + QueryPath: "numCompetitors", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleWebExtractCompetitors, + HideHelpCommand: true, +} + +var webExtractFonts = cli.Command{ + Name: "extract-fonts", + Usage: "Scrape font information from a website including font families, usage\nstatistics, fallbacks, and element/word counts.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "direct-url", + Usage: "A specific URL to fetch fonts from directly, bypassing domain resolution (e.g., 'https://example.com/design-system'). When provided, fonts are extracted from this exact URL. You must provide either 'domain' or 'directUrl', but not both.", + QueryPath: "directUrl", + }, + &requestflag.Flag[string]{ + Name: "domain", + Usage: "Domain name to extract fonts from (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both.", + QueryPath: "domain", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: 7776000000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleWebExtractFonts, + HideHelpCommand: true, +} + +var webExtractStyleguide = cli.Command{ + Name: "extract-styleguide", + Usage: "Extract a comprehensive design system from a website including colors,\ntypography, spacing, shadows, and UI components.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "direct-url", + Usage: "A specific URL to fetch the styleguide from directly, bypassing domain resolution (e.g., 'https://example.com/design-system'). When provided, the styleguide is extracted from this exact URL. You must provide either 'domain' or 'directUrl', but not both.", + QueryPath: "directUrl", + }, + &requestflag.Flag[string]{ + Name: "domain", + Usage: "Domain name to extract styleguide from (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both.", + QueryPath: "domain", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: 7776000000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + }, + Action: handleWebExtractStyleguide, + HideHelpCommand: true, +} + +var webScreenshot = requestflag.WithInnerFlags(cli.Command{ + Name: "screenshot", + Usage: "Capture a screenshot of a website.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "direct-url", + Usage: "A specific URL to screenshot directly, bypassing domain resolution (e.g., 'https://example.com/pricing'). When provided, the screenshot is taken of this exact URL. You must provide either 'domain' or 'directUrl', but not both.", + QueryPath: "directUrl", + }, + &requestflag.Flag[string]{ + Name: "domain", + Usage: "Domain name to take screenshot of (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both.", + QueryPath: "domain", + }, + &requestflag.Flag[string]{ + Name: "full-screenshot", + Usage: "Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view).", + QueryPath: "fullScreenshot", + }, + &requestflag.Flag[string]{ + Name: "handle-cookie-popup", + Usage: "Optional parameter to control cookie/consent popup handling. If 'true', we dismiss cookie banner before capture. If 'false' or not provided, captures the page without that step.", + Default: "false", + QueryPath: "handleCookiePopup", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Return a cached screenshot if a prior screenshot for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.", + Default: 86400000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[string]{ + Name: "page", + Usage: "Optional parameter to specify which page type to screenshot. If provided, the system will scrape the domain's links and use heuristics to find the most appropriate URL for the specified page type (30 supported languages). If not provided, screenshots the main domain landing page. Only applicable when using 'domain', not 'directUrl'.", + QueryPath: "page", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + &requestflag.Flag[map[string]any]{ + Name: "viewport", + Usage: "Optional browser viewport dimensions for the screenshot. Defaults to 1920x1080.", + Default: map[string]any{"width": 1920, "height": 1080}, + QueryPath: "viewport", + }, + &requestflag.Flag[int64]{ + Name: "wait-for-ms", + Usage: "Optional browser wait time in milliseconds after initial page load before taking the screenshot. Min: 0. Max: 30000 (30 seconds). Defaults to 3000 ms when omitted.", + Default: 3000, + QueryPath: "waitForMs", + }, + }, + Action: handleWebScreenshot, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "viewport": { + &requestflag.InnerFlag[int64]{ + Name: "viewport.height", + Usage: "Viewport height in pixels.", + InnerField: "height", + }, + &requestflag.InnerFlag[int64]{ + Name: "viewport.width", + Usage: "Viewport width in pixels.", + InnerField: "width", + }, + }, +}) + +var webSearch = requestflag.WithInnerFlags(cli.Command{ + Name: "search", + Usage: "Search the web and optionally scrape each result to Markdown in one round-trip.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "query", + Usage: "Natural-language search query.", + Required: true, + BodyPath: "query", + }, + &requestflag.Flag[[]string]{ + Name: "exclude-domain", + Usage: `Blocklist — drop results from these domains. Example: ["pinterest.com", "reddit.com"].`, + BodyPath: "excludeDomains", + }, + &requestflag.Flag[string]{ + Name: "freshness", + Usage: "Restrict results to content published within this window.", + BodyPath: "freshness", + }, + &requestflag.Flag[[]string]{ + Name: "include-domain", + Usage: `Allowlist — only return results from these domains. Example: ["arxiv.org", "github.com"].`, + BodyPath: "includeDomains", + }, + &requestflag.Flag[map[string]any]{ + Name: "markdown-options", + Usage: "Inline Markdown scraping for each result. Set `enabled: true` to activate.", + BodyPath: "markdownOptions", + }, + &requestflag.Flag[bool]{ + Name: "query-fanout", + Usage: "Expand the query into multiple parallel variants for broader recall.", + BodyPath: "queryFanout", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + }, + Action: handleWebSearch, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "markdown-options": { + &requestflag.InnerFlag[bool]{ + Name: "markdown-options.enabled", + Usage: "Scrape each result to Markdown. Off by default to keep search cheap and fast.", + InnerField: "enabled", + }, + &requestflag.InnerFlag[bool]{ + Name: "markdown-options.include-frames", + Usage: "Render iframe contents into the Markdown.", + InnerField: "includeFrames", + }, + &requestflag.InnerFlag[bool]{ + Name: "markdown-options.include-images", + Usage: "Emit image references in the Markdown.", + InnerField: "includeImages", + }, + &requestflag.InnerFlag[bool]{ + Name: "markdown-options.include-links", + Usage: "Keep hyperlinks in the Markdown.", + InnerField: "includeLinks", + }, + &requestflag.InnerFlag[int64]{ + Name: "markdown-options.max-age-ms", + Usage: "Cache TTL in ms for scraped Markdown keyed by URL + options. Default 1 day, max 30 days. Set to 0 to force a fresh scrape.", + InnerField: "maxAgeMs", + }, + &requestflag.InnerFlag[map[string]any]{ + Name: "markdown-options.pdf", + Usage: "PDF handling. Use start/end to bound text extraction and OCR to a page range.", + InnerField: "pdf", + }, + &requestflag.InnerFlag[bool]{ + Name: "markdown-options.shorten-base64-images", + Usage: "Truncate inline base64 image payloads to keep responses small.", + InnerField: "shortenBase64Images", + }, + &requestflag.InnerFlag[int64]{ + Name: "markdown-options.timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + InnerField: "timeoutMS", + }, + &requestflag.InnerFlag[bool]{ + Name: "markdown-options.use-main-content-only", + Usage: "Strip nav, header, footer, and sidebar — keep only the primary article content.", + InnerField: "useMainContentOnly", + }, + &requestflag.InnerFlag[int64]{ + Name: "markdown-options.wait-for-ms", + Usage: "Extra wait after page load before rendering, in ms (0–30000). Useful for JS-heavy pages.", + InnerField: "waitForMs", + }, + }, +}) + +var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ + Name: "web-crawl-md", + Usage: "Performs a crawl starting from a given URL, extracts page content as Markdown,\nand returns results for all crawled pages.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "url", + Usage: "The starting URL for the crawl (must include http:// or https:// protocol)", + Required: true, + BodyPath: "url", + }, + &requestflag.Flag[[]string]{ + Name: "exclude-selector", + Usage: `CSS selectors to remove before each crawled page is converted to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`, + BodyPath: "excludeSelectors", + }, + &requestflag.Flag[bool]{ + Name: "follow-subdomains", + Usage: "When true, follow links on subdomains of the starting URL's domain (e.g. docs.example.com when starting from example.com). www and apex are always treated as equivalent.", + Default: false, + BodyPath: "followSubdomains", + }, + &requestflag.Flag[bool]{ + Name: "include-frames", + Usage: "When true, the contents of iframes are rendered to Markdown for each crawled page.", + Default: false, + BodyPath: "includeFrames", + }, + &requestflag.Flag[bool]{ + Name: "include-images", + Usage: "Include image references in the Markdown output", + Default: false, + BodyPath: "includeImages", + }, + &requestflag.Flag[bool]{ + Name: "include-links", + Usage: "Preserve hyperlinks in the Markdown output", + Default: true, + BodyPath: "includeLinks", + }, + &requestflag.Flag[[]string]{ + Name: "include-selector", + Usage: `CSS selectors. When provided, only matching HTML subtrees (and their descendants) are kept before each crawled page is converted to Markdown. When omitted, the entire document is kept. Examples: "article.main", "#content", "[role=main]".`, + BodyPath: "includeSelectors", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh.", + Default: 86400000, + BodyPath: "maxAgeMs", + }, + &requestflag.Flag[int64]{ + Name: "max-depth", + Usage: "Maximum link depth from the starting URL (0 = only the starting page)", + BodyPath: "maxDepth", + }, + &requestflag.Flag[int64]{ + Name: "max-pages", + Usage: "Maximum number of pages to crawl. Hard cap: 500.", + Default: 100, + BodyPath: "maxPages", + }, + &requestflag.Flag[map[string]any]{ + Name: "pdf", + Usage: "PDF parsing controls. Use start/end to limit text extraction and OCR to an inclusive 1-based page range.", + Default: map[string]any{"shouldParse": true}, + BodyPath: "pdf", + }, + &requestflag.Flag[bool]{ + Name: "shorten-base64-images", + Usage: "Truncate base64-encoded image data in the Markdown output", + Default: true, + BodyPath: "shortenBase64Images", + }, + &requestflag.Flag[int64]{ + Name: "stop-after-ms", + Usage: "Soft time budget for the crawl in milliseconds. After each scrape, the crawler checks the elapsed time and, if exceeded, returns the pages collected so far instead of continuing. Min: 10000 (10s). Max: 110000 (110s). Default: 80000 (80s).", + Default: 80000, + BodyPath: "stopAfterMs", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + &requestflag.Flag[string]{ + Name: "url-regex", + Usage: "Regex pattern. Only URLs matching this pattern will be followed and scraped.", + BodyPath: "urlRegex", + }, + &requestflag.Flag[bool]{ + Name: "use-main-content-only", + Usage: "Extract only the main content, stripping headers, footers, sidebars, and navigation", + Default: false, + BodyPath: "useMainContentOnly", + }, + &requestflag.Flag[int64]{ + Name: "wait-for-ms", + Usage: "Optional browser wait time in milliseconds after initial page load for each crawled page. Min: 0. Max: 30000 (30 seconds). ", + BodyPath: "waitForMs", + }, + }, + Action: handleWebWebCrawlMd, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "pdf": { + &requestflag.InnerFlag[int64]{ + Name: "pdf.end", + Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", + InnerField: "end", + }, + &requestflag.InnerFlag[bool]{ + Name: "pdf.should-parse", + Usage: "When true, PDF pages are fetched and parsed. When false, PDF pages are skipped entirely (not included in results and not counted as failures).", + InnerField: "shouldParse", + }, + &requestflag.InnerFlag[int64]{ + Name: "pdf.start", + Usage: "First 1-based PDF page to parse. When omitted, parsing starts at the first page.", + InnerField: "start", + }, + }, +}) + +var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ + Name: "web-scrape-html", + Usage: "Scrapes the given URL and returns the raw HTML content of the page.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "url", + Usage: "Full URL to scrape (must include http:// or https:// protocol)", + Required: true, + QueryPath: "url", + }, + &requestflag.Flag[[]string]{ + Name: "exclude-selector", + Usage: `CSS selectors to remove from the result. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`, + QueryPath: "excludeSelectors", + }, + &requestflag.Flag[map[string]any]{ + Name: "headers", + Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", + QueryPath: "headers", + }, + &requestflag.Flag[bool]{ + Name: "include-frames", + Usage: "When true, iframes are rendered inline into the returned HTML.", + Default: false, + QueryPath: "includeFrames", + }, + &requestflag.Flag[[]string]{ + Name: "include-selector", + Usage: `CSS selectors. When provided, only matching subtrees (and their descendants) are kept and everything else is dropped. When omitted, the entire document is kept. Examples: "article.main", "#content", "[role=main]".`, + QueryPath: "includeSelectors", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh.", + Default: 86400000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[map[string]any]{ + Name: "pdf", + Usage: "PDF parsing controls. Use start/end to limit text extraction and OCR to an inclusive 1-based page range.", + Default: map[string]any{"shouldParse": true}, + QueryPath: "pdf", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + &requestflag.Flag[bool]{ + Name: "use-main-content-only", + Usage: "When true, return only the page's main content in the HTML response, excluding headers, footers, sidebars, and navigation when detectable.", + Default: false, + QueryPath: "useMainContentOnly", + }, + &requestflag.Flag[int64]{ + Name: "wait-for-ms", + Usage: "Optional browser wait time in milliseconds after initial page load. Min: 0. Max: 30000 (30 seconds). ", + QueryPath: "waitForMs", + }, + }, + Action: handleWebWebScrapeHTML, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "pdf": { + &requestflag.InnerFlag[int64]{ + Name: "pdf.end", + Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", + InnerField: "end", + }, + &requestflag.InnerFlag[bool]{ + Name: "pdf.should-parse", + Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned.", + InnerField: "shouldParse", + }, + &requestflag.InnerFlag[int64]{ + Name: "pdf.start", + Usage: "First 1-based PDF page to parse. When omitted, parsing starts at the first page.", + InnerField: "start", + }, + }, +}) + +var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ + Name: "web-scrape-images", + Usage: "Extract image assets from a web page, including standard URLs, inline SVGs, data\nURIs, responsive image sources, metadata, CSS backgrounds, video posters, and\nembeds. The base request costs 1 credit. When enrichment is enabled, the entire\ncall costs 5 credits.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "url", + Usage: "Page URL to inspect. Must include http:// or https://.", + Required: true, + QueryPath: "url", + }, + &requestflag.Flag[map[string]any]{ + Name: "enrichment", + Usage: "Optional per-image processing, sent as deep-object query params such as enrichment[resolution]=true.", + QueryPath: "enrichment", + }, + &requestflag.Flag[map[string]any]{ + Name: "headers", + Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", + QueryPath: "headers", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Reuse a cached result this many milliseconds old or newer. Default: 86400000 (1 day). Set to 0 to bypass cache. Maximum: 2592000000 (30 days).", + Default: 86400000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + &requestflag.Flag[int64]{ + Name: "wait-for-ms", + Usage: "Optional browser wait time in milliseconds after initial page load before collecting images. Min: 0. Max: 30000 (30 seconds). ", + QueryPath: "waitForMs", + }, + }, + Action: handleWebWebScrapeImages, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "enrichment": { + &requestflag.InnerFlag[bool]{ + Name: "enrichment.classification", + Usage: "Classify each image by visual asset type.", + InnerField: "classification", + }, + &requestflag.InnerFlag[bool]{ + Name: "enrichment.hosted-url", + Usage: "Host materializable images on the Brand.dev CDN and return their URL and MIME type.", + InnerField: "hostedUrl", + }, + &requestflag.InnerFlag[int64]{ + Name: "enrichment.max-time-per-ms", + Usage: "Per-image enrichment timeout in milliseconds. Default: 30000. Maximum: 60000.", + InnerField: "maxTimePerMs", + }, + &requestflag.InnerFlag[bool]{ + Name: "enrichment.resolution", + Usage: "Measure image width and height when possible.", + InnerField: "resolution", + }, + }, +}) + +var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ + Name: "web-scrape-md", + Usage: "Scrapes the given URL into LLM usable Markdown.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "url", + Usage: "Full URL to scrape into LLM usable Markdown (must include http:// or https:// protocol)", + Required: true, + QueryPath: "url", + }, + &requestflag.Flag[[]string]{ + Name: "exclude-selector", + Usage: `CSS selectors to remove before conversion to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`, + QueryPath: "excludeSelectors", + }, + &requestflag.Flag[map[string]any]{ + Name: "headers", + Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", + QueryPath: "headers", + }, + &requestflag.Flag[bool]{ + Name: "include-frames", + Usage: "When true, the contents of iframes are rendered to Markdown.", + Default: false, + QueryPath: "includeFrames", + }, + &requestflag.Flag[bool]{ + Name: "include-images", + Usage: "Include image references in Markdown output", + Default: false, + QueryPath: "includeImages", + }, + &requestflag.Flag[bool]{ + Name: "include-links", + Usage: "Preserve hyperlinks in Markdown output", + Default: true, + QueryPath: "includeLinks", + }, + &requestflag.Flag[[]string]{ + Name: "include-selector", + Usage: `CSS selectors. When provided, only matching HTML subtrees (and their descendants) are kept before conversion to Markdown. When omitted, the entire document is kept. Examples: "article.main", "#content", "[role=main]".`, + QueryPath: "includeSelectors", + }, + &requestflag.Flag[int64]{ + Name: "max-age-ms", + Usage: "Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh.", + Default: 86400000, + QueryPath: "maxAgeMs", + }, + &requestflag.Flag[map[string]any]{ + Name: "pdf", + Usage: "PDF parsing controls. Use start/end to limit text extraction and OCR to an inclusive 1-based page range.", + Default: map[string]any{"shouldParse": true}, + QueryPath: "pdf", + }, + &requestflag.Flag[bool]{ + Name: "shorten-base64-images", + Usage: "Shorten base64-encoded image data in the Markdown output", + Default: true, + QueryPath: "shortenBase64Images", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + &requestflag.Flag[bool]{ + Name: "use-main-content-only", + Usage: "Extract only the main content of the page, excluding headers, footers, sidebars, and navigation", + Default: false, + QueryPath: "useMainContentOnly", + }, + &requestflag.Flag[int64]{ + Name: "wait-for-ms", + Usage: "Optional browser wait time in milliseconds after initial page load before converting the page to Markdown. Min: 0. Max: 30000 (30 seconds). ", + QueryPath: "waitForMs", + }, + }, + Action: handleWebWebScrapeMd, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "pdf": { + &requestflag.InnerFlag[int64]{ + Name: "pdf.end", + Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", + InnerField: "end", + }, + &requestflag.InnerFlag[bool]{ + Name: "pdf.should-parse", + Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned.", + InnerField: "shouldParse", + }, + &requestflag.InnerFlag[int64]{ + Name: "pdf.start", + Usage: "First 1-based PDF page to parse. When omitted, parsing starts at the first page.", + InnerField: "start", + }, + }, +}) + +var webWebScrapeSitemap = cli.Command{ + Name: "web-scrape-sitemap", + Usage: "Crawl an entire website's sitemap and return all discovered page URLs.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "domain", + Usage: "Domain to build a sitemap for", + Required: true, + QueryPath: "domain", + }, + &requestflag.Flag[map[string]any]{ + Name: "headers", + Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", + QueryPath: "headers", + }, + &requestflag.Flag[int64]{ + Name: "max-links", + Usage: "Maximum number of links to return from the sitemap crawl. Defaults to 10,000. Minimum is 1, maximum is 100,000.", + Default: 10000, + QueryPath: "maxLinks", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + QueryPath: "timeoutMS", + }, + &requestflag.Flag[string]{ + Name: "url-regex", + Usage: "Optional RE2-compatible regex pattern. Only URLs matching this pattern are returned and counted against maxLinks.", + QueryPath: "urlRegex", + }, + }, + Action: handleWebWebScrapeSitemap, + HideHelpCommand: true, +} + +func handleWebExtract(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebExtractParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.Extract(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web extract", + Transform: transform, + }) +} + +func handleWebExtractCompetitors(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebExtractCompetitorsParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.ExtractCompetitors(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web extract-competitors", + Transform: transform, + }) +} + +func handleWebExtractFonts(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebExtractFontsParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.ExtractFonts(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web extract-fonts", + Transform: transform, + }) +} + +func handleWebExtractStyleguide(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebExtractStyleguideParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.ExtractStyleguide(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web extract-styleguide", + Transform: transform, + }) +} + +func handleWebScreenshot(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebScreenshotParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.Screenshot(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web screenshot", + Transform: transform, + }) +} + +func handleWebSearch(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebSearchParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.Search(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web search", + Transform: transform, + }) +} + +func handleWebWebCrawlMd(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebWebCrawlMdParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.WebCrawlMd(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web web-crawl-md", + Transform: transform, + }) +} + +func handleWebWebScrapeHTML(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebWebScrapeHTMLParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.WebScrapeHTML(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web web-scrape-html", + Transform: transform, + }) +} + +func handleWebWebScrapeImages(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebWebScrapeImagesParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.WebScrapeImages(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web web-scrape-images", + Transform: transform, + }) +} + +func handleWebWebScrapeMd(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebWebScrapeMdParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.WebScrapeMd(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web web-scrape-md", + Transform: transform, + }) +} + +func handleWebWebScrapeSitemap(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.WebWebScrapeSitemapParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Web.WebScrapeSitemap(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "web web-scrape-sitemap", + Transform: transform, + }) +} diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go new file mode 100644 index 0000000..586e952 --- /dev/null +++ b/pkg/cmd/web_test.go @@ -0,0 +1,496 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/stainless-sdks/context.dev-cli/internal/mocktest" + "github.com/stainless-sdks/context.dev-cli/internal/requestflag" +) + +func TestWebExtract(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "extract", + "--schema", "{type: bar, properties: bar, required: bar, additionalProperties: bar}", + "--url", "https://example.com", + "--fact-check=true", + "--follow-subdomains=true", + "--include-frames=true", + "--instructions", "instructions", + "--max-age-ms", "0", + "--max-depth", "0", + "--max-pages", "1", + "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--stop-after-ms", "10000", + "--timeout-ms", "1000", + "--wait-for-ms", "0", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(webExtract) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "extract", + "--schema", "{type: bar, properties: bar, required: bar, additionalProperties: bar}", + "--url", "https://example.com", + "--fact-check=true", + "--follow-subdomains=true", + "--include-frames=true", + "--instructions", "instructions", + "--max-age-ms", "0", + "--max-depth", "0", + "--max-pages", "1", + "--pdf.end", "1", + "--pdf.should-parse=true", + "--pdf.start", "1", + "--stop-after-ms", "10000", + "--timeout-ms", "1000", + "--wait-for-ms", "0", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "schema:\n" + + " type: bar\n" + + " properties: bar\n" + + " required: bar\n" + + " additionalProperties: bar\n" + + "url: https://example.com\n" + + "factCheck: true\n" + + "followSubdomains: true\n" + + "includeFrames: true\n" + + "instructions: instructions\n" + + "maxAgeMs: 0\n" + + "maxDepth: 0\n" + + "maxPages: 1\n" + + "pdf:\n" + + " end: 1\n" + + " shouldParse: true\n" + + " start: 1\n" + + "stopAfterMs: 10000\n" + + "timeoutMS: 1000\n" + + "waitForMs: 0\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "web", "extract", + ) + }) +} + +func TestWebExtractCompetitors(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "extract-competitors", + "--domain", "xxx", + "--num-competitors", "1", + "--timeout-ms", "1000", + ) + }) +} + +func TestWebExtractFonts(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "extract-fonts", + "--direct-url", "https://example.com", + "--domain", "domain", + "--max-age-ms", "86400000", + "--timeout-ms", "1000", + ) + }) +} + +func TestWebExtractStyleguide(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "extract-styleguide", + "--direct-url", "https://example.com", + "--domain", "domain", + "--max-age-ms", "86400000", + "--timeout-ms", "1000", + ) + }) +} + +func TestWebScreenshot(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "screenshot", + "--direct-url", "https://example.com", + "--domain", "domain", + "--full-screenshot", "true", + "--handle-cookie-popup", "true", + "--max-age-ms", "0", + "--page", "login", + "--timeout-ms", "1000", + "--viewport", "{height: 240, width: 240}", + "--wait-for-ms", "0", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(webScreenshot) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "screenshot", + "--direct-url", "https://example.com", + "--domain", "domain", + "--full-screenshot", "true", + "--handle-cookie-popup", "true", + "--max-age-ms", "0", + "--page", "login", + "--timeout-ms", "1000", + "--viewport.height", "240", + "--viewport.width", "240", + "--wait-for-ms", "0", + ) + }) +} + +func TestWebSearch(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "search", + "--query", "x", + "--exclude-domain", "string", + "--freshness", "last_24_hours", + "--include-domain", "string", + "--markdown-options", "{enabled: true, includeFrames: true, includeImages: true, includeLinks: true, maxAgeMs: 0, pdf: {end: 1, shouldParse: true, start: 1}, shortenBase64Images: true, timeoutMS: 1000, useMainContentOnly: true, waitForMs: 0}", + "--query-fanout=true", + "--timeout-ms", "1000", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(webSearch) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "search", + "--query", "x", + "--exclude-domain", "string", + "--freshness", "last_24_hours", + "--include-domain", "string", + "--markdown-options.enabled=true", + "--markdown-options.include-frames=true", + "--markdown-options.include-images=true", + "--markdown-options.include-links=true", + "--markdown-options.max-age-ms", "0", + "--markdown-options.pdf", "{end: 1, shouldParse: true, start: 1}", + "--markdown-options.shorten-base64-images=true", + "--markdown-options.timeout-ms", "1000", + "--markdown-options.use-main-content-only=true", + "--markdown-options.wait-for-ms", "0", + "--query-fanout=true", + "--timeout-ms", "1000", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "query: x\n" + + "excludeDomains:\n" + + " - string\n" + + "freshness: last_24_hours\n" + + "includeDomains:\n" + + " - string\n" + + "markdownOptions:\n" + + " enabled: true\n" + + " includeFrames: true\n" + + " includeImages: true\n" + + " includeLinks: true\n" + + " maxAgeMs: 0\n" + + " pdf:\n" + + " end: 1\n" + + " shouldParse: true\n" + + " start: 1\n" + + " shortenBase64Images: true\n" + + " timeoutMS: 1000\n" + + " useMainContentOnly: true\n" + + " waitForMs: 0\n" + + "queryFanout: true\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "web", "search", + ) + }) +} + +func TestWebWebCrawlMd(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-crawl-md", + "--url", "https://example.com", + "--exclude-selector", "string", + "--follow-subdomains=true", + "--include-frames=true", + "--include-images=true", + "--include-links=true", + "--include-selector", "string", + "--max-age-ms", "0", + "--max-depth", "0", + "--max-pages", "1", + "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--shorten-base64-images=true", + "--stop-after-ms", "10000", + "--timeout-ms", "1000", + "--url-regex", "^https?://[^/]+/blog/", + "--use-main-content-only=true", + "--wait-for-ms", "0", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(webWebCrawlMd) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-crawl-md", + "--url", "https://example.com", + "--exclude-selector", "string", + "--follow-subdomains=true", + "--include-frames=true", + "--include-images=true", + "--include-links=true", + "--include-selector", "string", + "--max-age-ms", "0", + "--max-depth", "0", + "--max-pages", "1", + "--pdf.end", "1", + "--pdf.should-parse=true", + "--pdf.start", "1", + "--shorten-base64-images=true", + "--stop-after-ms", "10000", + "--timeout-ms", "1000", + "--url-regex", "^https?://[^/]+/blog/", + "--use-main-content-only=true", + "--wait-for-ms", "0", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "url: https://example.com\n" + + "excludeSelectors:\n" + + " - string\n" + + "followSubdomains: true\n" + + "includeFrames: true\n" + + "includeImages: true\n" + + "includeLinks: true\n" + + "includeSelectors:\n" + + " - string\n" + + "maxAgeMs: 0\n" + + "maxDepth: 0\n" + + "maxPages: 1\n" + + "pdf:\n" + + " end: 1\n" + + " shouldParse: true\n" + + " start: 1\n" + + "shortenBase64Images: true\n" + + "stopAfterMs: 10000\n" + + "timeoutMS: 1000\n" + + "urlRegex: ^https?://[^/]+/blog/\n" + + "useMainContentOnly: true\n" + + "waitForMs: 0\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "web", "web-crawl-md", + ) + }) +} + +func TestWebWebScrapeHTML(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-scrape-html", + "--url", "https://example.com", + "--exclude-selector", "string", + "--headers", "{foo: J!}", + "--include-frames=true", + "--include-selector", "string", + "--max-age-ms", "0", + "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--timeout-ms", "1000", + "--use-main-content-only=true", + "--wait-for-ms", "0", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(webWebScrapeHTML) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-scrape-html", + "--url", "https://example.com", + "--exclude-selector", "string", + "--headers", "{foo: J!}", + "--include-frames=true", + "--include-selector", "string", + "--max-age-ms", "0", + "--pdf.end", "1", + "--pdf.should-parse=true", + "--pdf.start", "1", + "--timeout-ms", "1000", + "--use-main-content-only=true", + "--wait-for-ms", "0", + ) + }) +} + +func TestWebWebScrapeImages(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-scrape-images", + "--url", "https://example.com", + "--enrichment", "{classification: true, hostedUrl: true, maxTimePerMs: 1, resolution: true}", + "--headers", "{foo: J!}", + "--max-age-ms", "0", + "--timeout-ms", "1000", + "--wait-for-ms", "0", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(webWebScrapeImages) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-scrape-images", + "--url", "https://example.com", + "--enrichment.classification=true", + "--enrichment.hosted-url=true", + "--enrichment.max-time-per-ms", "1", + "--enrichment.resolution=true", + "--headers", "{foo: J!}", + "--max-age-ms", "0", + "--timeout-ms", "1000", + "--wait-for-ms", "0", + ) + }) +} + +func TestWebWebScrapeMd(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-scrape-md", + "--url", "https://example.com", + "--exclude-selector", "string", + "--headers", "{foo: J!}", + "--include-frames=true", + "--include-images=true", + "--include-links=true", + "--include-selector", "string", + "--max-age-ms", "0", + "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--shorten-base64-images=true", + "--timeout-ms", "1000", + "--use-main-content-only=true", + "--wait-for-ms", "0", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(webWebScrapeMd) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-scrape-md", + "--url", "https://example.com", + "--exclude-selector", "string", + "--headers", "{foo: J!}", + "--include-frames=true", + "--include-images=true", + "--include-links=true", + "--include-selector", "string", + "--max-age-ms", "0", + "--pdf.end", "1", + "--pdf.should-parse=true", + "--pdf.start", "1", + "--shorten-base64-images=true", + "--timeout-ms", "1000", + "--use-main-content-only=true", + "--wait-for-ms", "0", + ) + }) +} + +func TestWebWebScrapeSitemap(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "web", "web-scrape-sitemap", + "--domain", "domain", + "--headers", "{foo: J!}", + "--max-links", "1", + "--timeout-ms", "1000", + "--url-regex", "^https?://[^/]+/blog/", + ) + }) +} diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..53619de --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,67 @@ +{ + "packages": { + ".": {} + }, + "$schema": "https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json", + "include-v-in-tag": true, + "include-component-in-tag": false, + "versioning": "prerelease", + "prerelease": true, + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": false, + "pull-request-header": "Automated Release PR", + "pull-request-title-pattern": "release: ${version}", + "changelog-sections": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "perf", + "section": "Performance Improvements" + }, + { + "type": "revert", + "section": "Reverts" + }, + { + "type": "chore", + "section": "Chores" + }, + { + "type": "docs", + "section": "Documentation" + }, + { + "type": "style", + "section": "Styles" + }, + { + "type": "refactor", + "section": "Refactors" + }, + { + "type": "test", + "section": "Tests", + "hidden": true + }, + { + "type": "build", + "section": "Build System" + }, + { + "type": "ci", + "section": "Continuous Integration", + "hidden": true + } + ], + "release-type": "simple", + "extra-files": [ + "pkg/cmd/version.go", + "README.md" + ] +} \ No newline at end of file diff --git a/scripts/bootstrap b/scripts/bootstrap new file mode 100755 index 0000000..bbc786d --- /dev/null +++ b/scripts/bootstrap @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "${SKIP_BREW:-}" != "1" ] && [ -t 0 ]; then + brew bundle check >/dev/null 2>&1 || { + echo -n "==> Install Homebrew dependencies? (y/N): " + read -r response + case "$response" in + [yY][eE][sS]|[yY]) + brew bundle + ;; + *) + ;; + esac + echo + } +fi +echo "==> Installing Go dependencies…" +go mod tidy -e || true diff --git a/scripts/build b/scripts/build new file mode 100755 index 0000000..9ca42cd --- /dev/null +++ b/scripts/build @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" + +echo "==> Building context-dev" +go build ./cmd/context-dev diff --git a/scripts/format b/scripts/format new file mode 100755 index 0000000..db2a3fa --- /dev/null +++ b/scripts/format @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +echo "==> Running gofmt -s -w" +gofmt -s -w . diff --git a/scripts/link b/scripts/link new file mode 100755 index 0000000..8519bd7 --- /dev/null +++ b/scripts/link @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" + +REPLACEMENT="${1:-"../context.dev-go"}" +echo "==> Replacing Go SDK with $REPLACEMENT" +if [[ -d "$REPLACEMENT" ]] || go list -m "$REPLACEMENT" >/dev/null; then + go mod edit -replace github.com/context-dot-dev/context-go-sdk="$REPLACEMENT" + go mod tidy -e +else + echo "Skipping Go SDK replacement (branch may not exist on Go SDK)" +fi diff --git a/scripts/lint b/scripts/lint new file mode 100755 index 0000000..096034e --- /dev/null +++ b/scripts/lint @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" + +echo "==> Running Go build" +go build ./... diff --git a/scripts/run b/scripts/run new file mode 100755 index 0000000..192c0c6 --- /dev/null +++ b/scripts/run @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" + +go run ./cmd/context-dev "$@" diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..3cbf5d8 --- /dev/null +++ b/scripts/test @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +# Mark the necessary Go modules as private to avoid Go's proxy +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" + + + +echo "==> Running tests" +go test ./... "$@" + +echo "==> Checking tests on Windows" +GOARCH=amd64 GOOS=windows go test -c ./... "$@" +# `go test -c` produces a bunch of .exe files; make sure to clean those up +find . -name "*.test.exe" -exec rm {} \; diff --git a/scripts/unlink b/scripts/unlink new file mode 100755 index 0000000..6b26500 --- /dev/null +++ b/scripts/unlink @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e + +cd "$(dirname "$0")/.." + +echo "==> Unlinking with local directory" +go mod edit -dropreplace github.com/context-dot-dev/context-go-sdk diff --git a/scripts/utils/upload-artifact.sh b/scripts/utils/upload-artifact.sh new file mode 100755 index 0000000..ae9f330 --- /dev/null +++ b/scripts/utils/upload-artifact.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +set -exuo pipefail + +BINARY_NAME="context-dev" +DIST_DIR="dist" +FILENAME="dist.zip" + +files=() +while IFS= read -r -d '' file; do + files+=("$file") +done < <(find "$DIST_DIR" -type f \( \ + -path "*amd64*/$BINARY_NAME" -o \ + -path "*arm64*/$BINARY_NAME" -o \ + -path "*amd64*/${BINARY_NAME}.exe" -o \ + -path "*arm64*/${BINARY_NAME}.exe" \ + \) -print0) + +if [[ ${#files[@]} -eq 0 ]]; then + echo -e "\033[31mNo binaries found for packaging.\033[0m" + exit 1 +fi + +rm -f "${DIST_DIR}/${FILENAME}" + +while IFS= read -r -d '' dir; do + printf "Remove the quarantine attribute before running the executable:\n\nxattr -d com.apple.quarantine %s\n" \ + "$BINARY_NAME" >"${dir}/README.txt" + files+=("${dir}/README.txt") +done < <(find "$DIST_DIR" -type d -path '*macos*' -print0) + +relative_files=() +for file in "${files[@]}"; do + relative_files+=("${file#"${DIST_DIR}"/}") +done + +(cd "$DIST_DIR" && zip -r "$FILENAME" "${relative_files[@]}") + +RESPONSE=$(curl -X POST "$URL?filename=$FILENAME" \ + -H "Authorization: Bearer $AUTH" \ + -H "Content-Type: application/json") + +SIGNED_URL=$(echo "$RESPONSE" | jq -r '.url') + +if [[ "$SIGNED_URL" == "null" ]]; then + echo -e "\033[31mFailed to get signed URL.\033[0m" + exit 1 +fi + +UPLOAD_RESPONSE=$(curl -v -X PUT \ + -H "Content-Type: application/zip" \ + --data-binary "@${DIST_DIR}/${FILENAME}" "$SIGNED_URL" 2>&1) + +if echo "$UPLOAD_RESPONSE" | grep -q "HTTP/[0-9.]* 200"; then + echo -e "\033[32mUploaded build to Stainless storage.\033[0m" + echo -e "\033[32mInstallation: Download and unzip: 'https://pkg.stainless.com/s/context.dev-cli/$SHA'. On macOS, run 'xattr -d com.apple.quarantine {executable name}'.\033[0m" +else + echo -e "\033[31mFailed to upload artifact.\033[0m" + exit 1 +fi From bdffb7dfaf6c96ceb65d3881b3b2737572f2a0a0 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 12:20:25 +0000 Subject: [PATCH 002/154] chore: update SDK settings --- .github/workflows/release-doctor.yml | 2 +- .stats.yml | 4 ++-- README.md | 6 +++++- cmd/context-dev/main.go | 2 +- go.mod | 2 +- pkg/cmd/ai.go | 4 ++-- pkg/cmd/ai_test.go | 4 ++-- pkg/cmd/brand.go | 4 ++-- pkg/cmd/brand_test.go | 2 +- pkg/cmd/cmd.go | 4 ++-- pkg/cmd/cmdutil.go | 2 +- pkg/cmd/cmdutil_test.go | 2 +- pkg/cmd/flagoptions.go | 8 ++++---- pkg/cmd/industry.go | 4 ++-- pkg/cmd/industry_test.go | 2 +- pkg/cmd/utility.go | 4 ++-- pkg/cmd/utility_test.go | 2 +- pkg/cmd/version.go | 2 +- pkg/cmd/web.go | 4 ++-- pkg/cmd/web_test.go | 4 ++-- 20 files changed, 36 insertions(+), 32 deletions(-) diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index 861de6b..6b1e45d 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -9,7 +9,7 @@ jobs: release_doctor: name: release doctor runs-on: ubuntu-latest - if: github.repository == 'stainless-sdks/context.dev-cli' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next') + if: github.repository == 'context-dot-dev/context-dev-cli' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next') steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 diff --git a/.stats.yml b/.stats.yml index db7c82e..784ab77 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-0253523aec437a0e9c67c3386fa25ed52ebbcc0073c907f0aa3586d8010d2e9d.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-508b6e971e1d1da37221163ee6625a7f348c96a0ddbf1ea2a8dc17b6cdfb74c3.yml openapi_spec_hash: 5cf86ed865b01dfe3a159a45315ebb49 -config_hash: 2b6e4424b446fe1bf93359ba758c83ed +config_hash: eebf67a9c2ccfe2641980c154d7a698e diff --git a/README.md b/README.md index abca44f..fa92c25 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ The official CLI for the [Context Dev REST API](https://docs.context.dev/). It is generated with [Stainless](https://www.stainless.com/). + + ## Installation ### Installing with Go @@ -11,7 +13,7 @@ It is generated with [Stainless](https://www.stainless.com/). To test or install the CLI locally, you need [Go](https://go.dev/doc/install) version 1.22 or later installed. ```sh -go install 'github.com/stainless-sdks/context.dev-cli/cmd/context-dev@latest' +go install 'github.com/context-dot-dev/context-dev-cli/cmd/context-dev@latest' ``` Once you have run `go install`, the binary is placed in your Go bin directory: @@ -26,6 +28,8 @@ If commands aren't found after installation, add the Go bin directory to your PA export PATH="$PATH:$(go env GOPATH)/bin" ``` + + ### Running Locally After cloning the git repository for this project, you can use the diff --git a/cmd/context-dev/main.go b/cmd/context-dev/main.go index 3fff3f8..43678b5 100644 --- a/cmd/context-dev/main.go +++ b/cmd/context-dev/main.go @@ -10,8 +10,8 @@ import ( "os" "slices" + "github.com/context-dot-dev/context-dev-cli/pkg/cmd" "github.com/context-dot-dev/context-go-sdk" - "github.com/stainless-sdks/context.dev-cli/pkg/cmd" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/go.mod b/go.mod index 5eccdd4..f4a4eaf 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/stainless-sdks/context.dev-cli +module github.com/context-dot-dev/context-dev-cli go 1.25 diff --git a/pkg/cmd/ai.go b/pkg/cmd/ai.go index 5f782ff..87b1b1d 100644 --- a/pkg/cmd/ai.go +++ b/pkg/cmd/ai.go @@ -6,10 +6,10 @@ import ( "context" "fmt" + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" "github.com/context-dot-dev/context-go-sdk" "github.com/context-dot-dev/context-go-sdk/option" - "github.com/stainless-sdks/context.dev-cli/internal/apiquery" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/ai_test.go b/pkg/cmd/ai_test.go index 8a5a1ac..5ae0952 100644 --- a/pkg/cmd/ai_test.go +++ b/pkg/cmd/ai_test.go @@ -5,8 +5,8 @@ package cmd import ( "testing" - "github.com/stainless-sdks/context.dev-cli/internal/mocktest" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" ) func TestAIAIQuery(t *testing.T) { diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index ea76221..ba96e74 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -6,10 +6,10 @@ import ( "context" "fmt" + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" "github.com/context-dot-dev/context-go-sdk" "github.com/context-dot-dev/context-go-sdk/option" - "github.com/stainless-sdks/context.dev-cli/internal/apiquery" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/brand_test.go b/pkg/cmd/brand_test.go index 99c40c2..ffc41a8 100644 --- a/pkg/cmd/brand_test.go +++ b/pkg/cmd/brand_test.go @@ -5,7 +5,7 @@ package cmd import ( "testing" - "github.com/stainless-sdks/context.dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" ) func TestBrandRetrieve(t *testing.T) { diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 4e153e1..c8145a2 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -12,8 +12,8 @@ import ( "slices" "strings" - "github.com/stainless-sdks/context.dev-cli/internal/autocomplete" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + "github.com/context-dot-dev/context-dev-cli/internal/autocomplete" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" docs "github.com/urfave/cli-docs/v3" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/cmdutil.go b/pkg/cmd/cmdutil.go index 87208ae..7ffa0f7 100644 --- a/pkg/cmd/cmdutil.go +++ b/pkg/cmd/cmdutil.go @@ -16,8 +16,8 @@ import ( "strings" "syscall" + "github.com/context-dot-dev/context-dev-cli/internal/jsonview" "github.com/context-dot-dev/context-go-sdk/option" - "github.com/stainless-sdks/context.dev-cli/internal/jsonview" "github.com/charmbracelet/x/term" "github.com/itchyny/json2yaml" diff --git a/pkg/cmd/cmdutil_test.go b/pkg/cmd/cmdutil_test.go index f2eadae..1ecb22c 100644 --- a/pkg/cmd/cmdutil_test.go +++ b/pkg/cmd/cmdutil_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tidwall/gjson" - "github.com/stainless-sdks/context.dev-cli/internal/jsonview" + "github.com/context-dot-dev/context-dev-cli/internal/jsonview" ) func TestStreamOutput(t *testing.T) { diff --git a/pkg/cmd/flagoptions.go b/pkg/cmd/flagoptions.go index e21dadd..9f23588 100644 --- a/pkg/cmd/flagoptions.go +++ b/pkg/cmd/flagoptions.go @@ -16,11 +16,11 @@ import ( "strings" "unicode/utf8" + "github.com/context-dot-dev/context-dev-cli/internal/apiform" + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/debugmiddleware" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" "github.com/context-dot-dev/context-go-sdk/option" - "github.com/stainless-sdks/context.dev-cli/internal/apiform" - "github.com/stainless-sdks/context.dev-cli/internal/apiquery" - "github.com/stainless-sdks/context.dev-cli/internal/debugmiddleware" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" "github.com/goccy/go-yaml" "github.com/urfave/cli/v3" diff --git a/pkg/cmd/industry.go b/pkg/cmd/industry.go index 68861ee..0b150b5 100644 --- a/pkg/cmd/industry.go +++ b/pkg/cmd/industry.go @@ -6,10 +6,10 @@ import ( "context" "fmt" + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" "github.com/context-dot-dev/context-go-sdk" "github.com/context-dot-dev/context-go-sdk/option" - "github.com/stainless-sdks/context.dev-cli/internal/apiquery" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/industry_test.go b/pkg/cmd/industry_test.go index 709922c..d74383e 100644 --- a/pkg/cmd/industry_test.go +++ b/pkg/cmd/industry_test.go @@ -5,7 +5,7 @@ package cmd import ( "testing" - "github.com/stainless-sdks/context.dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" ) func TestIndustryRetrieveNaics(t *testing.T) { diff --git a/pkg/cmd/utility.go b/pkg/cmd/utility.go index b2812ec..a690ee0 100644 --- a/pkg/cmd/utility.go +++ b/pkg/cmd/utility.go @@ -6,10 +6,10 @@ import ( "context" "fmt" + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" "github.com/context-dot-dev/context-go-sdk" "github.com/context-dot-dev/context-go-sdk/option" - "github.com/stainless-sdks/context.dev-cli/internal/apiquery" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/utility_test.go b/pkg/cmd/utility_test.go index 72d48cf..f1670ea 100644 --- a/pkg/cmd/utility_test.go +++ b/pkg/cmd/utility_test.go @@ -5,7 +5,7 @@ package cmd import ( "testing" - "github.com/stainless-sdks/context.dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" ) func TestUtilityPrefetch(t *testing.T) { diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index ad586f4..1f71453 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.0.1" +const Version = "0.0.1" // x-release-please-version diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 8a9249b..3ec5c57 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -6,10 +6,10 @@ import ( "context" "fmt" + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" "github.com/context-dot-dev/context-go-sdk" "github.com/context-dot-dev/context-go-sdk/option" - "github.com/stainless-sdks/context.dev-cli/internal/apiquery" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 586e952..5df8b61 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -5,8 +5,8 @@ package cmd import ( "testing" - "github.com/stainless-sdks/context.dev-cli/internal/mocktest" - "github.com/stainless-sdks/context.dev-cli/internal/requestflag" + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" ) func TestWebExtract(t *testing.T) { From ece91e49b704b78bd898acea00cbb753d2f5a463 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 12:22:05 +0000 Subject: [PATCH 003/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 1332969..c7159c1 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.0.1" + ".": "0.0.2" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 1f71453..20f136d 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.0.1" // x-release-please-version +const Version = "0.0.2" // x-release-please-version From 55346a29864bf42671e30729f9d98bc4b9177a23 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2026 23:12:11 +0000 Subject: [PATCH 004/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 784ab77..ec04fe4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-508b6e971e1d1da37221163ee6625a7f348c96a0ddbf1ea2a8dc17b6cdfb74c3.yml -openapi_spec_hash: 5cf86ed865b01dfe3a159a45315ebb49 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2a217dd4edf98594fcf6d1e70d84c7305eec80cea96318dfe08a743cbd2468a5.yml +openapi_spec_hash: 1f32b54c3c7623d246c5c90e4300e068 config_hash: eebf67a9c2ccfe2641980c154d7a698e From f9d793c9ceab94a6e489efe2c4b6b16931c60eab Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 18 Jun 2026 12:07:43 +0000 Subject: [PATCH 005/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index ec04fe4..4a04c1d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2a217dd4edf98594fcf6d1e70d84c7305eec80cea96318dfe08a743cbd2468a5.yml -openapi_spec_hash: 1f32b54c3c7623d246c5c90e4300e068 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-aea83574a2e2963acf3791ff66f3b2d552e8b07ff00e2705ccd9a96cb3756a6e.yml +openapi_spec_hash: 3a11cd57f8e308484a461522a7f634ee config_hash: eebf67a9c2ccfe2641980c154d7a698e From 44a59276e5bca0e50a14f97c7e57b9c86b04dbc5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 18 Jun 2026 13:52:38 +0000 Subject: [PATCH 006/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f4a4eaf..a54ff06 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk v0.12.0 + github.com/context-dot-dev/context-go-sdk v1.0.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index ded57b2..80efc0b 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk v0.12.0 h1:6OPISoUaLtSt+uDW+HTkzApLf9Q+OTNKbUwYdM6JeSU= -github.com/context-dot-dev/context-go-sdk v0.12.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= +github.com/context-dot-dev/context-go-sdk v1.0.0 h1:UtV1z6YJwKoDPdjRtavedwyryKCgyTQ7pRbxcs+KWfY= +github.com/context-dot-dev/context-go-sdk v1.0.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 8c0559488bba180fd6eb9b86892646b306a0ae3b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 18 Jun 2026 23:54:35 +0000 Subject: [PATCH 007/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 4a04c1d..190887f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-aea83574a2e2963acf3791ff66f3b2d552e8b07ff00e2705ccd9a96cb3756a6e.yml -openapi_spec_hash: 3a11cd57f8e308484a461522a7f634ee +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5dd4350dcb0dd55c4d01d9e44409675c68aa3ec2ec993138e100ab3a63c22e4f.yml +openapi_spec_hash: 65a950a043be9ffbab0f0cffa8985401 config_hash: eebf67a9c2ccfe2641980c154d7a698e From f3a2872b7e914140059f8a0ed3ecad01f49d0265 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2026 14:44:39 +0000 Subject: [PATCH 008/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 190887f..657544e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5dd4350dcb0dd55c4d01d9e44409675c68aa3ec2ec993138e100ab3a63c22e4f.yml -openapi_spec_hash: 65a950a043be9ffbab0f0cffa8985401 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ccc3d15a43be0505cabc52b9bd35e75ebdf072246b1563eab29e644bfc21e766.yml +openapi_spec_hash: ab3a6473e575381cacd245bf54dcf0f7 config_hash: eebf67a9c2ccfe2641980c154d7a698e From dc1b9af7faaa4729f99e8b9b89129ce339cb895d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2026 14:58:02 +0000 Subject: [PATCH 009/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index c7159c1..3d2ac0b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.0.2" + ".": "0.1.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 20f136d..9bb8168 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.0.2" // x-release-please-version +const Version = "0.1.0" // x-release-please-version From e6a0301bc74d498479a32376bd9117a9d218ba28 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2026 16:52:13 +0000 Subject: [PATCH 010/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a54ff06..7f8a744 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk v1.0.0 + github.com/context-dot-dev/context-go-sdk v1.1.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 80efc0b..299a540 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk v1.0.0 h1:UtV1z6YJwKoDPdjRtavedwyryKCgyTQ7pRbxcs+KWfY= -github.com/context-dot-dev/context-go-sdk v1.0.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= +github.com/context-dot-dev/context-go-sdk v1.1.0 h1:CwBPH2p3b2eA3euoV3h9wFNT7/obkeXeGXrCWPKv9tc= +github.com/context-dot-dev/context-go-sdk v1.1.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 55fadaec047367f447eb5e620d9f616c2ec450cb Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 19 Jun 2026 20:59:59 +0000 Subject: [PATCH 011/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 657544e..052ef10 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ccc3d15a43be0505cabc52b9bd35e75ebdf072246b1563eab29e644bfc21e766.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e10718ebeb5bc263af75fe2341f7d1e91442f3e64b703bf7d416f8e7f328d2f9.yml openapi_spec_hash: ab3a6473e575381cacd245bf54dcf0f7 -config_hash: eebf67a9c2ccfe2641980c154d7a698e +config_hash: 48c9231dff85f546e8210338751ccb41 From d1cc2d2b09e68bf7cc584a421de7e0968726c0b4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 21 Jun 2026 23:48:05 +0000 Subject: [PATCH 012/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 052ef10..2a9603a 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e10718ebeb5bc263af75fe2341f7d1e91442f3e64b703bf7d416f8e7f328d2f9.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-af8edc351fec4471435b010cd9b7ccfabf2c2ccef20e6404ad2516a0be212645.yml openapi_spec_hash: ab3a6473e575381cacd245bf54dcf0f7 -config_hash: 48c9231dff85f546e8210338751ccb41 +config_hash: f5846595c44dc42376e820c14465a4c6 From 9e3024663e35abd2656b1668553d96ea8100cbdd Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 21 Jun 2026 23:53:35 +0000 Subject: [PATCH 013/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 2a9603a..bacd568 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-af8edc351fec4471435b010cd9b7ccfabf2c2ccef20e6404ad2516a0be212645.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-3024c2681b0acf12535d68f39c1b49113330548513a54b276116cd3f2eda182e.yml openapi_spec_hash: ab3a6473e575381cacd245bf54dcf0f7 -config_hash: f5846595c44dc42376e820c14465a4c6 +config_hash: b0f343b2ab3baebad7b0d6d51f0f16fc From 6e765e205259846b735a8856bb69226f8865052a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 21 Jun 2026 23:59:10 +0000 Subject: [PATCH 014/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 3d2ac0b..10f3091 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0" + ".": "0.2.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 9bb8168..10d2893 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.1.0" // x-release-please-version +const Version = "0.2.0" // x-release-please-version From 7d87aa70ad836ef9aa72dae58f6bc9a5aee60de2 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 22 Jun 2026 00:07:08 +0000 Subject: [PATCH 015/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index bacd568..99ba378 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-3024c2681b0acf12535d68f39c1b49113330548513a54b276116cd3f2eda182e.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2460611c25145e2ca049b14c32be0f9ac9f4ded0b95154d29a83b4a6c1453f3e.yml openapi_spec_hash: ab3a6473e575381cacd245bf54dcf0f7 -config_hash: b0f343b2ab3baebad7b0d6d51f0f16fc +config_hash: c7b0cdaba3b9797b77efd89e1754d803 From 1613198e7f8315cb2e27e37e84ec76e6a9c01a72 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 25 Jun 2026 08:40:03 +0000 Subject: [PATCH 016/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 5 +++++ pkg/cmd/web_test.go | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 99ba378..e34b116 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2460611c25145e2ca049b14c32be0f9ac9f4ded0b95154d29a83b4a6c1453f3e.yml -openapi_spec_hash: ab3a6473e575381cacd245bf54dcf0f7 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4903d5902cec6a80f42b9adaa9cf0defa9805ff22d7ae96970d209a4f867e195.yml +openapi_spec_hash: 1097891c23530dfe0155f23170daf973 config_hash: c7b0cdaba3b9797b77efd89e1754d803 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 3ec5c57..2a4e194 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -241,6 +241,11 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional parameter to specify which page type to screenshot. If provided, the system will scrape the domain's links and use heuristics to find the most appropriate URL for the specified page type (30 supported languages). If not provided, screenshots the main domain landing page. Only applicable when using 'domain', not 'directUrl'.", QueryPath: "page", }, + &requestflag.Flag[int64]{ + Name: "scroll-offset", + Usage: "Optional vertical scroll offset in pixels for capturing a long page in viewport-sized chunks. When provided, the full page is captured once and the returned image is the viewport-sized slice that begins at this Y offset (e.g. request scrollOffset=0, then 1080, then 2160 to walk a 1920x1080 landing page top to bottom). The final slice may be shorter than the viewport height. Takes precedence over fullScreenshot. Max: 100000.", + QueryPath: "scrollOffset", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 5df8b61..9fec097 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -147,6 +147,7 @@ func TestWebScreenshot(t *testing.T) { "--handle-cookie-popup", "true", "--max-age-ms", "0", "--page", "login", + "--scroll-offset", "0", "--timeout-ms", "1000", "--viewport", "{height: 240, width: 240}", "--wait-for-ms", "0", @@ -168,6 +169,7 @@ func TestWebScreenshot(t *testing.T) { "--handle-cookie-popup", "true", "--max-age-ms", "0", "--page", "login", + "--scroll-offset", "0", "--timeout-ms", "1000", "--viewport.height", "240", "--viewport.width", "240", From df23809b91acfa909330cbc516e7efff29628601 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 25 Jun 2026 08:52:55 +0000 Subject: [PATCH 017/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 10f3091..6b7b74c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0" + ".": "0.3.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 10d2893..5266c84 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.2.0" // x-release-please-version +const Version = "0.3.0" // x-release-please-version From bf89fd7c8a5043a2d0f8b00ec9792c2105496998 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 25 Jun 2026 18:11:22 +0000 Subject: [PATCH 018/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7f8a744..2e84305 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk v1.1.0 + github.com/context-dot-dev/context-go-sdk v1.2.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 299a540..f3cb7d4 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk v1.1.0 h1:CwBPH2p3b2eA3euoV3h9wFNT7/obkeXeGXrCWPKv9tc= -github.com/context-dot-dev/context-go-sdk v1.1.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= +github.com/context-dot-dev/context-go-sdk v1.2.0 h1:fFXWrYeZK8WFJhrGLEm3XSHomUMJwLYT9p9H5stJ1m4= +github.com/context-dot-dev/context-go-sdk v1.2.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 5ba270df632c86b0a175e70aafa1b4a166e597c7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2026 16:47:12 +0000 Subject: [PATCH 019/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 20 ++++++++++++++++++++ pkg/cmd/web_test.go | 9 +++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index e34b116..24c57ba 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4903d5902cec6a80f42b9adaa9cf0defa9805ff22d7ae96970d209a4f867e195.yml -openapi_spec_hash: 1097891c23530dfe0155f23170daf973 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-00c5b8f1ebfe212bc8fb46204f5c05507630afa55b10f77e3a43c66d21edbb77.yml +openapi_spec_hash: 8bf4489b9bce0e52a89480109ffc5257 config_hash: c7b0cdaba3b9797b77efd89e1754d803 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 2a4e194..4b302cd 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -209,6 +209,11 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Usage: "Capture a screenshot of a website.", Suggest: true, Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "country", + Usage: "Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country.", + QueryPath: "country", + }, &requestflag.Flag[string]{ Name: "direct-url", Usage: "A specific URL to screenshot directly, bypassing domain resolution (e.g., 'https://example.com/pricing'). When provided, the screenshot is taken of this exact URL. You must provide either 'domain' or 'directUrl', but not both.", @@ -391,6 +396,11 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ Required: true, BodyPath: "url", }, + &requestflag.Flag[string]{ + Name: "country", + Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", + BodyPath: "country", + }, &requestflag.Flag[[]string]{ Name: "exclude-selector", Usage: `CSS selectors to remove before each crawled page is converted to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`, @@ -515,6 +525,11 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Required: true, QueryPath: "url", }, + &requestflag.Flag[string]{ + Name: "country", + Usage: "Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country.", + QueryPath: "country", + }, &requestflag.Flag[[]string]{ Name: "exclude-selector", Usage: `CSS selectors to remove from the result. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`, @@ -663,6 +678,11 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Required: true, QueryPath: "url", }, + &requestflag.Flag[string]{ + Name: "country", + Usage: "Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country.", + QueryPath: "country", + }, &requestflag.Flag[[]string]{ Name: "exclude-selector", Usage: `CSS selectors to remove before conversion to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`, diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 9fec097..4c9a09b 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -141,6 +141,7 @@ func TestWebScreenshot(t *testing.T) { t, "--api-key", "string", "web", "screenshot", + "--country", "de", "--direct-url", "https://example.com", "--domain", "domain", "--full-screenshot", "true", @@ -163,6 +164,7 @@ func TestWebScreenshot(t *testing.T) { t, "--api-key", "string", "web", "screenshot", + "--country", "de", "--direct-url", "https://example.com", "--domain", "domain", "--full-screenshot", "true", @@ -264,6 +266,7 @@ func TestWebWebCrawlMd(t *testing.T) { "--api-key", "string", "web", "web-crawl-md", "--url", "https://example.com", + "--country", "de", "--exclude-selector", "string", "--follow-subdomains=true", "--include-frames=true", @@ -293,6 +296,7 @@ func TestWebWebCrawlMd(t *testing.T) { "--api-key", "string", "web", "web-crawl-md", "--url", "https://example.com", + "--country", "de", "--exclude-selector", "string", "--follow-subdomains=true", "--include-frames=true", @@ -318,6 +322,7 @@ func TestWebWebCrawlMd(t *testing.T) { // Test piping YAML data over stdin pipeData := []byte("" + "url: https://example.com\n" + + "country: de\n" + "excludeSelectors:\n" + " - string\n" + "followSubdomains: true\n" + @@ -355,6 +360,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--api-key", "string", "web", "web-scrape-html", "--url", "https://example.com", + "--country", "de", "--exclude-selector", "string", "--headers", "{foo: J!}", "--include-frames=true", @@ -377,6 +383,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--api-key", "string", "web", "web-scrape-html", "--url", "https://example.com", + "--country", "de", "--exclude-selector", "string", "--headers", "{foo: J!}", "--include-frames=true", @@ -438,6 +445,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--api-key", "string", "web", "web-scrape-md", "--url", "https://example.com", + "--country", "de", "--exclude-selector", "string", "--headers", "{foo: J!}", "--include-frames=true", @@ -463,6 +471,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--api-key", "string", "web", "web-scrape-md", "--url", "https://example.com", + "--country", "de", "--exclude-selector", "string", "--headers", "{foo: J!}", "--include-frames=true", From b7e2fbc6c162bb27e7c56814fcace47337349cc9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2026 21:26:53 +0000 Subject: [PATCH 020/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 13 ++++++++++++- pkg/cmd/web_test.go | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index 24c57ba..9dc6067 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-00c5b8f1ebfe212bc8fb46204f5c05507630afa55b10f77e3a43c66d21edbb77.yml -openapi_spec_hash: 8bf4489b9bce0e52a89480109ffc5257 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d3da262409c68576e457536f6c0e7ecc538219e0af19df415111c18f8fe92cfd.yml +openapi_spec_hash: 25009575202702d24bc6672472eb8506 config_hash: c7b0cdaba3b9797b77efd89e1754d803 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 4b302cd..64db635 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -293,10 +293,15 @@ var webSearch = requestflag.WithInnerFlags(cli.Command{ Flags: []cli.Flag{ &requestflag.Flag[string]{ Name: "query", - Usage: "Natural-language search query.", + Usage: "Search query. Accepts natural language as well as Google-style search operators such as `site:`, `-site:`, `inurl:`, `intitle:`, quoted phrases, and `OR`.", Required: true, BodyPath: "query", }, + &requestflag.Flag[string]{ + Name: "country", + Usage: "Two-letter ISO 3166-1 alpha-2 country code to localize results to a specific country (maps to Google's `gl` parameter). Example: \"us\", \"gb\", \"de\".", + BodyPath: "country", + }, &requestflag.Flag[[]string]{ Name: "exclude-domain", Usage: `Blocklist — drop results from these domains. Example: ["pinterest.com", "reddit.com"].`, @@ -317,6 +322,12 @@ var webSearch = requestflag.WithInnerFlags(cli.Command{ Usage: "Inline Markdown scraping for each result. Set `enabled: true` to activate.", BodyPath: "markdownOptions", }, + &requestflag.Flag[int64]{ + Name: "num-results", + Usage: "Number of results to request and return (10–100). Defaults to 10.", + Default: 10, + BodyPath: "numResults", + }, &requestflag.Flag[bool]{ Name: "query-fanout", Usage: "Expand the query into multiple parallel variants for broader recall.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 4c9a09b..740ca97 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -188,10 +188,12 @@ func TestWebSearch(t *testing.T) { "--api-key", "string", "web", "search", "--query", "x", + "--country", "af", "--exclude-domain", "string", "--freshness", "last_24_hours", "--include-domain", "string", "--markdown-options", "{enabled: true, includeFrames: true, includeImages: true, includeLinks: true, maxAgeMs: 0, pdf: {end: 1, shouldParse: true, start: 1}, shortenBase64Images: true, timeoutMS: 1000, useMainContentOnly: true, waitForMs: 0}", + "--num-results", "10", "--query-fanout=true", "--timeout-ms", "1000", ) @@ -207,6 +209,7 @@ func TestWebSearch(t *testing.T) { "--api-key", "string", "web", "search", "--query", "x", + "--country", "af", "--exclude-domain", "string", "--freshness", "last_24_hours", "--include-domain", "string", @@ -220,6 +223,7 @@ func TestWebSearch(t *testing.T) { "--markdown-options.timeout-ms", "1000", "--markdown-options.use-main-content-only=true", "--markdown-options.wait-for-ms", "0", + "--num-results", "10", "--query-fanout=true", "--timeout-ms", "1000", ) @@ -229,6 +233,7 @@ func TestWebSearch(t *testing.T) { // Test piping YAML data over stdin pipeData := []byte("" + "query: x\n" + + "country: af\n" + "excludeDomains:\n" + " - string\n" + "freshness: last_24_hours\n" + @@ -248,6 +253,7 @@ func TestWebSearch(t *testing.T) { " timeoutMS: 1000\n" + " useMainContentOnly: true\n" + " waitForMs: 0\n" + + "numResults: 10\n" + "queryFanout: true\n" + "timeoutMS: 1000\n") mocktest.TestRunMockTestWithPipeAndFlags( From 3a3f58d97a1ccf6df1e3a4ed685302442945077c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 27 Jun 2026 20:25:25 +0000 Subject: [PATCH 021/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 5 +++++ pkg/cmd/web_test.go | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 9dc6067..0e801d6 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d3da262409c68576e457536f6c0e7ecc538219e0af19df415111c18f8fe92cfd.yml -openapi_spec_hash: 25009575202702d24bc6672472eb8506 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a4f78808dc23a76896b451576b3b44b0d663977f2032eaed0271dd386b20c43c.yml +openapi_spec_hash: 01f9e1ae0d635f8b874f48e3ba461476 config_hash: c7b0cdaba3b9797b77efd89e1754d803 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 64db635..72bb0f8 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -209,6 +209,11 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Usage: "Capture a screenshot of a website.", Suggest: true, Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "color-scheme", + Usage: "Optional parameter to choose the site's visual theme in the screenshot. Use 'light' or 'dark' when the site offers both appearances.", + QueryPath: "colorScheme", + }, &requestflag.Flag[string]{ Name: "country", Usage: "Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 740ca97..9c4bab4 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -141,6 +141,7 @@ func TestWebScreenshot(t *testing.T) { t, "--api-key", "string", "web", "screenshot", + "--color-scheme", "light", "--country", "de", "--direct-url", "https://example.com", "--domain", "domain", @@ -164,6 +165,7 @@ func TestWebScreenshot(t *testing.T) { t, "--api-key", "string", "web", "screenshot", + "--color-scheme", "light", "--country", "de", "--direct-url", "https://example.com", "--domain", "domain", From 392c5fb970ff27ac084edc052e4eb91082b3376c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 27 Jun 2026 21:20:30 +0000 Subject: [PATCH 022/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 5 +++++ pkg/cmd/web_test.go | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 0e801d6..5bb2078 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a4f78808dc23a76896b451576b3b44b0d663977f2032eaed0271dd386b20c43c.yml -openapi_spec_hash: 01f9e1ae0d635f8b874f48e3ba461476 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-021b48afe1d6e3f54c4ebe3d0da4beb3fb8b69a6d384a4aeadbc5bab7f967603.yml +openapi_spec_hash: 2aa5b59d78c708b094acf29cc0d9a68a config_hash: c7b0cdaba3b9797b77efd89e1754d803 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 72bb0f8..a2ad59e 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -178,6 +178,11 @@ var webExtractStyleguide = cli.Command{ Usage: "Extract a comprehensive design system from a website including colors,\ntypography, spacing, shadows, and UI components.", Suggest: true, Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "color-scheme", + Usage: "Optional browser color scheme to emulate for websites that respond to prefers-color-scheme. This value is part of the styleguide cache key.", + QueryPath: "colorScheme", + }, &requestflag.Flag[string]{ Name: "direct-url", Usage: "A specific URL to fetch the styleguide from directly, bypassing domain resolution (e.g., 'https://example.com/design-system'). When provided, the styleguide is extracted from this exact URL. You must provide either 'domain' or 'directUrl', but not both.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 9c4bab4..735f56f 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -126,6 +126,7 @@ func TestWebExtractStyleguide(t *testing.T) { t, "--api-key", "string", "web", "extract-styleguide", + "--color-scheme", "light", "--direct-url", "https://example.com", "--domain", "domain", "--max-age-ms", "86400000", From 0f697570f7da0058180c4dae8f70fac59345c15c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 27 Jun 2026 22:00:49 +0000 Subject: [PATCH 023/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6b7b74c..da59f99 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.3.0" + ".": "0.4.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 5266c84..b113456 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.3.0" // x-release-please-version +const Version = "0.4.0" // x-release-please-version From 47ee6edcea7957c02fcf360a6b7cc5c82f92d096 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 28 Jun 2026 18:46:56 +0000 Subject: [PATCH 024/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2e84305..2c82bc4 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk v1.2.0 + github.com/context-dot-dev/context-go-sdk v1.3.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index f3cb7d4..e806734 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk v1.2.0 h1:fFXWrYeZK8WFJhrGLEm3XSHomUMJwLYT9p9H5stJ1m4= -github.com/context-dot-dev/context-go-sdk v1.2.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= +github.com/context-dot-dev/context-go-sdk v1.3.0 h1:OyRxjHshWXnF8At15QOLpYJ5913Ytt7az7PviGVxbJA= +github.com/context-dot-dev/context-go-sdk v1.3.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 8b894054d08be2ab0324d185ad3871fc0117fd85 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2026 05:36:34 +0000 Subject: [PATCH 025/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 5bb2078..0a0c76c 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-021b48afe1d6e3f54c4ebe3d0da4beb3fb8b69a6d384a4aeadbc5bab7f967603.yml -openapi_spec_hash: 2aa5b59d78c708b094acf29cc0d9a68a +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d04e3c285c2f57723b288ee69b1d78b7bb928aae403203b2cdd524dd195e55b2.yml +openapi_spec_hash: e33db883d584bc8573897391f3edb105 config_hash: c7b0cdaba3b9797b77efd89e1754d803 From 7b93fa8590d48b1f58e80ee38fde6dff81e72001 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2026 05:42:06 +0000 Subject: [PATCH 026/154] feat(api): manual updates --- .stats.yml | 6 +- pkg/cmd/cmd.go | 18 + pkg/cmd/monitor.go | 902 ++++++++++++++++++++++++++++++++++++++++ pkg/cmd/monitor_test.go | 278 +++++++++++++ 4 files changed, 1201 insertions(+), 3 deletions(-) create mode 100644 pkg/cmd/monitor.go create mode 100644 pkg/cmd/monitor_test.go diff --git a/.stats.yml b/.stats.yml index 0a0c76c..2f86aeb 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d04e3c285c2f57723b288ee69b1d78b7bb928aae403203b2cdd524dd195e55b2.yml +configured_endpoints: 36 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8667763c416101820f5086c97d542bf13bb3bb12b57f5f604da671d9dcea0599.yml openapi_spec_hash: e33db883d584bc8573897391f3edb105 -config_hash: c7b0cdaba3b9797b77efd89e1754d803 +config_hash: 7ec4851ee8d93177947e95df5ae897b5 diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index c8145a2..c651ff5 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -144,6 +144,24 @@ func init() { &utilityPrefetchByEmail, }, }, + { + Name: "monitors", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &monitorsCreate, + &monitorsRetrieve, + &monitorsUpdate, + &monitorsList, + &monitorsDelete, + &monitorsListAccountChanges, + &monitorsListAccountRuns, + &monitorsListChanges, + &monitorsListRuns, + &monitorsRetrieveChange, + &monitorsRun, + }, + }, { Name: "@manpages", Usage: "Generate documentation for 'man'", diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go new file mode 100644 index 0000000..a66a8ee --- /dev/null +++ b/pkg/cmd/monitor.go @@ -0,0 +1,902 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" + "github.com/context-dot-dev/context-go-sdk" + "github.com/context-dot-dev/context-go-sdk/option" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var monitorsCreate = requestflag.WithInnerFlags(cli.Command{ + Name: "create", + Usage: "Creates a monitor. The request body is a union of the supported target/change\ndetection combinations. The monitor runs immediately after creation to create\nits initial baseline.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[map[string]any]{ + Name: "change-detection", + Usage: "Detect exact changes. For page targets, this means visible text diffs. For sitemap targets, this means URL additions and removals.", + Required: true, + BodyPath: "change_detection", + }, + &requestflag.Flag[string]{ + Name: "name", + Required: true, + BodyPath: "name", + }, + &requestflag.Flag[map[string]any]{ + Name: "schedule", + Usage: "Run the monitor on a fixed interval defined by a frequency and a unit, e.g. every 6 hours or every 2 days. The total interval (frequency × unit) must be between 10 minutes and 1 year.", + Required: true, + BodyPath: "schedule", + }, + &requestflag.Flag[map[string]any]{ + Name: "target", + Required: true, + BodyPath: "target", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "User-defined tags for grouping and filtering monitors and their changes.", + BodyPath: "tags", + }, + &requestflag.Flag[map[string]any]{ + Name: "webhook", + BodyPath: "webhook", + }, + }, + Action: handleMonitorsCreate, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "change-detection": { + &requestflag.InnerFlag[string]{ + Name: "change-detection.type", + Usage: `Allowed values: "exact".`, + InnerField: "type", + }, + }, + "schedule": { + &requestflag.InnerFlag[int64]{ + Name: "schedule.frequency", + Usage: "Number of units between runs. The resulting interval (frequency × unit) must be at least 10 minutes and at most 1 year (e.g. minimum 10 when unit is minutes; maximum 365 when unit is days).", + InnerField: "frequency", + }, + &requestflag.InnerFlag[string]{ + Name: "schedule.type", + Usage: `Allowed values: "interval".`, + InnerField: "type", + }, + &requestflag.InnerFlag[string]{ + Name: "schedule.unit", + Usage: `Allowed values: "minutes", "hours", "days".`, + InnerField: "unit", + }, + }, + "target": { + &requestflag.InnerFlag[string]{ + Name: "target.type", + Usage: `Allowed values: "page".`, + InnerField: "type", + }, + &requestflag.InnerFlag[string]{ + Name: "target.url", + InnerField: "url", + }, + &requestflag.InnerFlag[bool]{ + Name: "target.normalize-whitespace", + Usage: "Normalize whitespace before comparing or analyzing text.", + InnerField: "normalize_whitespace", + }, + }, + "webhook": { + &requestflag.InnerFlag[string]{ + Name: "webhook.url", + Usage: "Webhook URL called when a change is detected.", + InnerField: "url", + }, + &requestflag.InnerFlag[string]{ + Name: "webhook.secret", + Usage: "Signing secret used to verify webhook authenticity. Each delivery includes an `X-Context-Signature: t=,v1=` header, where the HMAC is SHA-256 over `\"{t}.{rawRequestBody}\"` keyed by this secret. Recompute it with a constant-time compare and reject stale timestamps to prevent replay. Generated by the API; cannot be set by clients.", + InnerField: "secret", + }, + }, +}) + +var monitorsRetrieve = cli.Command{ + Name: "retrieve", + Usage: "Get a monitor", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "monitor-id", + Required: true, + PathParam: "monitor_id", + }, + }, + Action: handleMonitorsRetrieve, + HideHelpCommand: true, +} + +var monitorsUpdate = requestflag.WithInnerFlags(cli.Command{ + Name: "update", + Usage: "Updates a monitor. If `target` or `change_detection` changes, the monitor\ncreates a new baseline. Unsupported target/change detection combinations are\nrejected.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "monitor-id", + Required: true, + PathParam: "monitor_id", + }, + &requestflag.Flag[map[string]any]{ + Name: "change-detection", + Usage: "Discriminated union describing how changes are detected.", + BodyPath: "change_detection", + }, + &requestflag.Flag[string]{ + Name: "name", + BodyPath: "name", + }, + &requestflag.Flag[map[string]any]{ + Name: "schedule", + Usage: "Run the monitor on a fixed interval defined by a frequency and a unit, e.g. every 6 hours or every 2 days. The total interval (frequency × unit) must be between 10 minutes and 1 year.", + BodyPath: "schedule", + }, + &requestflag.Flag[string]{ + Name: "status", + Usage: `Allowed values: "active", "paused".`, + BodyPath: "status", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "User-defined tags for grouping and filtering monitors and their changes.", + BodyPath: "tags", + }, + &requestflag.Flag[map[string]any]{ + Name: "target", + Usage: "Discriminated union describing what the monitor watches.", + BodyPath: "target", + }, + &requestflag.Flag[map[string]any]{ + Name: "webhook", + Usage: "Set to null to remove the webhook.", + BodyPath: "webhook", + }, + }, + Action: handleMonitorsUpdate, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "schedule": { + &requestflag.InnerFlag[int64]{ + Name: "schedule.frequency", + Usage: "Number of units between runs. The resulting interval (frequency × unit) must be at least 10 minutes and at most 1 year (e.g. minimum 10 when unit is minutes; maximum 365 when unit is days).", + InnerField: "frequency", + }, + &requestflag.InnerFlag[string]{ + Name: "schedule.type", + Usage: `Allowed values: "interval".`, + InnerField: "type", + }, + &requestflag.InnerFlag[string]{ + Name: "schedule.unit", + Usage: `Allowed values: "minutes", "hours", "days".`, + InnerField: "unit", + }, + }, + "webhook": { + &requestflag.InnerFlag[string]{ + Name: "webhook.url", + Usage: "Webhook URL called when a change is detected.", + InnerField: "url", + }, + &requestflag.InnerFlag[string]{ + Name: "webhook.secret", + Usage: "Signing secret used to verify webhook authenticity. Each delivery includes an `X-Context-Signature: t=,v1=` header, where the HMAC is SHA-256 over `\"{t}.{rawRequestBody}\"` keyed by this secret. Recompute it with a constant-time compare and reject stale timestamps to prevent replay. Generated by the API; cannot be set by clients.", + InnerField: "secret", + }, + }, +}) + +var monitorsList = cli.Command{ + Name: "list", + Usage: "List monitors", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "change-detection-type", + Usage: `Allowed values: "exact", "semantic".`, + QueryPath: "change_detection_type", + }, + &requestflag.Flag[string]{ + Name: "cursor", + QueryPath: "cursor", + }, + &requestflag.Flag[int64]{ + Name: "limit", + Default: 25, + QueryPath: "limit", + }, + &requestflag.Flag[string]{ + Name: "status", + Usage: `Allowed values: "active", "paused", "failed".`, + QueryPath: "status", + }, + &requestflag.Flag[string]{ + Name: "tag", + Usage: "Filter to items that have this tag.", + QueryPath: "tag", + }, + &requestflag.Flag[string]{ + Name: "target-type", + Usage: `Allowed values: "page", "sitemap", "extract".`, + QueryPath: "target_type", + }, + }, + Action: handleMonitorsList, + HideHelpCommand: true, +} + +var monitorsDelete = cli.Command{ + Name: "delete", + Usage: "Delete a monitor", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "monitor-id", + Required: true, + PathParam: "monitor_id", + }, + }, + Action: handleMonitorsDelete, + HideHelpCommand: true, +} + +var monitorsListAccountChanges = cli.Command{ + Name: "list-account-changes", + Usage: "Returns an account-wide feed of detected changes across monitors.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "change-detection-type", + Usage: `Allowed values: "exact", "semantic".`, + QueryPath: "change_detection_type", + }, + &requestflag.Flag[string]{ + Name: "cursor", + QueryPath: "cursor", + }, + &requestflag.Flag[int64]{ + Name: "limit", + Default: 25, + QueryPath: "limit", + }, + &requestflag.Flag[string]{ + Name: "monitor-id", + QueryPath: "monitor_id", + }, + &requestflag.Flag[any]{ + Name: "since", + QueryPath: "since", + }, + &requestflag.Flag[string]{ + Name: "tag", + Usage: "Filter to items that have this tag.", + QueryPath: "tag", + }, + &requestflag.Flag[string]{ + Name: "target-type", + Usage: `Allowed values: "page", "sitemap", "extract".`, + QueryPath: "target_type", + }, + &requestflag.Flag[any]{ + Name: "until", + QueryPath: "until", + }, + }, + Action: handleMonitorsListAccountChanges, + HideHelpCommand: true, +} + +var monitorsListAccountRuns = cli.Command{ + Name: "list-account-runs", + Usage: "Returns an account-wide feed of monitor runs across all monitors.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "cursor", + QueryPath: "cursor", + }, + &requestflag.Flag[int64]{ + Name: "limit", + Default: 25, + QueryPath: "limit", + }, + &requestflag.Flag[string]{ + Name: "status", + Usage: `Allowed values: "queued", "running", "completed", "failed".`, + QueryPath: "status", + }, + }, + Action: handleMonitorsListAccountRuns, + HideHelpCommand: true, +} + +var monitorsListChanges = cli.Command{ + Name: "list-changes", + Usage: "List changes for a monitor", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "monitor-id", + Required: true, + PathParam: "monitor_id", + }, + &requestflag.Flag[string]{ + Name: "cursor", + QueryPath: "cursor", + }, + &requestflag.Flag[int64]{ + Name: "limit", + Default: 25, + QueryPath: "limit", + }, + &requestflag.Flag[any]{ + Name: "since", + QueryPath: "since", + }, + &requestflag.Flag[string]{ + Name: "tag", + Usage: "Filter to items that have this tag.", + QueryPath: "tag", + }, + &requestflag.Flag[any]{ + Name: "until", + QueryPath: "until", + }, + }, + Action: handleMonitorsListChanges, + HideHelpCommand: true, +} + +var monitorsListRuns = cli.Command{ + Name: "list-runs", + Usage: "List monitor runs", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "monitor-id", + Required: true, + PathParam: "monitor_id", + }, + &requestflag.Flag[string]{ + Name: "cursor", + QueryPath: "cursor", + }, + &requestflag.Flag[int64]{ + Name: "limit", + Default: 25, + QueryPath: "limit", + }, + &requestflag.Flag[string]{ + Name: "status", + Usage: `Allowed values: "queued", "running", "completed", "failed".`, + QueryPath: "status", + }, + }, + Action: handleMonitorsListRuns, + HideHelpCommand: true, +} + +var monitorsRetrieveChange = cli.Command{ + Name: "retrieve-change", + Usage: "Get a change", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "change-id", + Required: true, + PathParam: "change_id", + }, + }, + Action: handleMonitorsRetrieveChange, + HideHelpCommand: true, +} + +var monitorsRun = cli.Command{ + Name: "run", + Usage: "Triggers an immediate run of the monitor outside its normal schedule. The run is\nqueued and processed asynchronously.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "monitor-id", + Required: true, + PathParam: "monitor_id", + }, + }, + Action: handleMonitorsRun, + HideHelpCommand: true, +} + +func handleMonitorsCreate(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.MonitorNewParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.New(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors create", + Transform: transform, + }) +} + +func handleMonitorsRetrieve(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("monitor-id") && len(unusedArgs) > 0 { + cmd.Set("monitor-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.Get(ctx, cmd.Value("monitor-id").(string), options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors retrieve", + Transform: transform, + }) +} + +func handleMonitorsUpdate(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("monitor-id") && len(unusedArgs) > 0 { + cmd.Set("monitor-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.MonitorUpdateParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.Update( + ctx, + cmd.Value("monitor-id").(string), + params, + options..., + ) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors update", + Transform: transform, + }) +} + +func handleMonitorsList(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.MonitorListParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.List(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors list", + Transform: transform, + }) +} + +func handleMonitorsDelete(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("monitor-id") && len(unusedArgs) > 0 { + cmd.Set("monitor-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.Delete(ctx, cmd.Value("monitor-id").(string), options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors delete", + Transform: transform, + }) +} + +func handleMonitorsListAccountChanges(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.MonitorListAccountChangesParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.ListAccountChanges(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors list-account-changes", + Transform: transform, + }) +} + +func handleMonitorsListAccountRuns(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.MonitorListAccountRunsParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.ListAccountRuns(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors list-account-runs", + Transform: transform, + }) +} + +func handleMonitorsListChanges(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("monitor-id") && len(unusedArgs) > 0 { + cmd.Set("monitor-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.MonitorListChangesParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.ListChanges( + ctx, + cmd.Value("monitor-id").(string), + params, + options..., + ) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors list-changes", + Transform: transform, + }) +} + +func handleMonitorsListRuns(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("monitor-id") && len(unusedArgs) > 0 { + cmd.Set("monitor-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.MonitorListRunsParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.ListRuns( + ctx, + cmd.Value("monitor-id").(string), + params, + options..., + ) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors list-runs", + Transform: transform, + }) +} + +func handleMonitorsRetrieveChange(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("change-id") && len(unusedArgs) > 0 { + cmd.Set("change-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.GetChange(ctx, cmd.Value("change-id").(string), options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors retrieve-change", + Transform: transform, + }) +} + +func handleMonitorsRun(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("monitor-id") && len(unusedArgs) > 0 { + cmd.Set("monitor-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.Run(ctx, cmd.Value("monitor-id").(string), options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors run", + Transform: transform, + }) +} diff --git a/pkg/cmd/monitor_test.go b/pkg/cmd/monitor_test.go new file mode 100644 index 0000000..6c2dd0d --- /dev/null +++ b/pkg/cmd/monitor_test.go @@ -0,0 +1,278 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" +) + +func TestMonitorsCreate(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "create", + "--change-detection", "{type: exact}", + "--name", "Acme pricing monitor", + "--schedule", "{frequency: 6, type: interval, unit: hours}", + "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--tag", "pricing", + "--tag", "competitor", + "--webhook", "{url: https://example.com/webhook}", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(monitorsCreate) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "create", + "--change-detection.type", "exact", + "--name", "Acme pricing monitor", + "--schedule.frequency", "6", + "--schedule.type", "interval", + "--schedule.unit", "hours", + "--target.type", "page", + "--target.url", "https://acme.com/pricing", + "--target.normalize-whitespace=true", + "--tag", "pricing", + "--tag", "competitor", + "--webhook.url", "https://example.com/webhook", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "change_detection:\n" + + " type: exact\n" + + "name: Acme pricing monitor\n" + + "schedule:\n" + + " frequency: 6\n" + + " type: interval\n" + + " unit: hours\n" + + "target:\n" + + " type: page\n" + + " url: https://acme.com/pricing\n" + + " normalize_whitespace: true\n" + + "tags:\n" + + " - pricing\n" + + " - competitor\n" + + "webhook:\n" + + " url: https://example.com/webhook\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "monitors", "create", + ) + }) +} + +func TestMonitorsRetrieve(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "retrieve", + "--monitor-id", "mon_123", + ) + }) +} + +func TestMonitorsUpdate(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "update", + "--monitor-id", "mon_123", + "--change-detection", "{type: exact}", + "--name", "Acme pricing monitor", + "--schedule", "{frequency: 1, type: interval, unit: hours}", + "--status", "active", + "--tag", "pricing", + "--tag", "competitor", + "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--webhook", "{url: https://example.com/webhook}", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(monitorsUpdate) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "update", + "--monitor-id", "mon_123", + "--change-detection", "{type: exact}", + "--name", "Acme pricing monitor", + "--schedule.frequency", "1", + "--schedule.type", "interval", + "--schedule.unit", "hours", + "--status", "active", + "--tag", "pricing", + "--tag", "competitor", + "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--webhook.url", "https://example.com/webhook", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "change_detection:\n" + + " type: exact\n" + + "name: Acme pricing monitor\n" + + "schedule:\n" + + " frequency: 1\n" + + " type: interval\n" + + " unit: hours\n" + + "status: active\n" + + "tags:\n" + + " - pricing\n" + + " - competitor\n" + + "target:\n" + + " type: page\n" + + " url: https://acme.com/pricing\n" + + " normalize_whitespace: true\n" + + "webhook:\n" + + " url: https://example.com/webhook\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "monitors", "update", + "--monitor-id", "mon_123", + ) + }) +} + +func TestMonitorsList(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "list", + "--change-detection-type", "exact", + "--cursor", "cursor", + "--limit", "1", + "--status", "active", + "--tag", "tag", + "--target-type", "page", + ) + }) +} + +func TestMonitorsDelete(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "delete", + "--monitor-id", "mon_123", + ) + }) +} + +func TestMonitorsListAccountChanges(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "list-account-changes", + "--change-detection-type", "exact", + "--cursor", "cursor", + "--limit", "1", + "--monitor-id", "monitor_id", + "--since", "'2019-12-27T18:11:19.117Z'", + "--tag", "tag", + "--target-type", "page", + "--until", "'2019-12-27T18:11:19.117Z'", + ) + }) +} + +func TestMonitorsListAccountRuns(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "list-account-runs", + "--cursor", "cursor", + "--limit", "1", + "--status", "queued", + ) + }) +} + +func TestMonitorsListChanges(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "list-changes", + "--monitor-id", "mon_123", + "--cursor", "cursor", + "--limit", "1", + "--since", "'2019-12-27T18:11:19.117Z'", + "--tag", "tag", + "--until", "'2019-12-27T18:11:19.117Z'", + ) + }) +} + +func TestMonitorsListRuns(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "list-runs", + "--monitor-id", "mon_123", + "--cursor", "cursor", + "--limit", "1", + "--status", "queued", + ) + }) +} + +func TestMonitorsRetrieveChange(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "retrieve-change", + "--change-id", "chg_123", + ) + }) +} + +func TestMonitorsRun(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "run", + "--monitor-id", "mon_123", + ) + }) +} From 5de3fcdcb4937b61ed27379b8ac3b1ee7fb6ae42 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2026 05:42:47 +0000 Subject: [PATCH 027/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index da59f99..2aca35a 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.4.0" + ".": "0.5.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index b113456..86845a8 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.4.0" // x-release-please-version +const Version = "0.5.0" // x-release-please-version From 07b5ee1efb8ac4e4397b801d7042d43cd927970f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2026 05:51:19 +0000 Subject: [PATCH 028/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2aca35a..4208b5c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.5.0" + ".": "0.6.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 86845a8..c1f2884 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.5.0" // x-release-please-version +const Version = "0.6.0" // x-release-please-version From 9b04ffb9c6f6efee7d6413479a31eb0d6c1022d7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 29 Jun 2026 21:27:36 +0000 Subject: [PATCH 029/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2c82bc4..a986fba 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk v1.3.0 + github.com/context-dot-dev/context-go-sdk v1.4.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index e806734..4ca6f33 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk v1.3.0 h1:OyRxjHshWXnF8At15QOLpYJ5913Ytt7az7PviGVxbJA= -github.com/context-dot-dev/context-go-sdk v1.3.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= +github.com/context-dot-dev/context-go-sdk v1.4.0 h1:UiQeIP5oCFIRpgklVo+tlZahUh9AsqVi3vek2kLYqSE= +github.com/context-dot-dev/context-go-sdk v1.4.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 3d926f9794496bc09a80c58ed0b4712d829e820c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 01:13:55 +0000 Subject: [PATCH 030/154] feat(api): api update --- .stats.yml | 4 +-- pkg/cmd/monitor.go | 54 ++++++++++++++++++++++------------------- pkg/cmd/monitor_test.go | 19 +++++++++------ 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/.stats.yml b/.stats.yml index 2f86aeb..0115b3b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8667763c416101820f5086c97d542bf13bb3bb12b57f5f604da671d9dcea0599.yml -openapi_spec_hash: e33db883d584bc8573897391f3edb105 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-66a3bf68b47ba61c9b61406d36f614a079ff752b8964a8df8062e485391d5598.yml +openapi_spec_hash: b17d6cfe3710dd0605078f3907a1a419 config_hash: 7ec4851ee8d93177947e95df5ae897b5 diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index a66a8ee..8754aff 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -21,7 +21,7 @@ var monitorsCreate = requestflag.WithInnerFlags(cli.Command{ Flags: []cli.Flag{ &requestflag.Flag[map[string]any]{ Name: "change-detection", - Usage: "Detect exact changes. For page targets, this means visible text diffs. For sitemap targets, this means URL additions and removals.", + Usage: "Discriminated union describing how changes are detected.", Required: true, BodyPath: "change_detection", }, @@ -38,9 +38,15 @@ var monitorsCreate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[map[string]any]{ Name: "target", + Usage: "Discriminated union describing what the monitor watches.", Required: true, BodyPath: "target", }, + &requestflag.Flag[string]{ + Name: "mode", + Usage: "Top-level monitor category. Always `web` today; the concrete behavior is described by `target` and `change_detection`.", + BodyPath: "mode", + }, &requestflag.Flag[[]string]{ Name: "tag", Usage: "User-defined tags for grouping and filtering monitors and their changes.", @@ -54,13 +60,6 @@ var monitorsCreate = requestflag.WithInnerFlags(cli.Command{ Action: handleMonitorsCreate, HideHelpCommand: true, }, map[string][]requestflag.HasOuterFlag{ - "change-detection": { - &requestflag.InnerFlag[string]{ - Name: "change-detection.type", - Usage: `Allowed values: "exact".`, - InnerField: "type", - }, - }, "schedule": { &requestflag.InnerFlag[int64]{ Name: "schedule.frequency", @@ -78,22 +77,6 @@ var monitorsCreate = requestflag.WithInnerFlags(cli.Command{ InnerField: "unit", }, }, - "target": { - &requestflag.InnerFlag[string]{ - Name: "target.type", - Usage: `Allowed values: "page".`, - InnerField: "type", - }, - &requestflag.InnerFlag[string]{ - Name: "target.url", - InnerField: "url", - }, - &requestflag.InnerFlag[bool]{ - Name: "target.normalize-whitespace", - Usage: "Normalize whitespace before comparing or analyzing text.", - InnerField: "normalize_whitespace", - }, - }, "webhook": { &requestflag.InnerFlag[string]{ Name: "webhook.url", @@ -204,7 +187,7 @@ var monitorsUpdate = requestflag.WithInnerFlags(cli.Command{ var monitorsList = cli.Command{ Name: "list", - Usage: "List monitors", + Usage: "Lists monitors for the authenticated organization. Supports free-text search\n(`q` over `search_by` fields, `prefix` or `exact` via `search_type`) plus\nstatus/type/tag filters. Results are paginated via the opaque `cursor`.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ @@ -221,6 +204,22 @@ var monitorsList = cli.Command{ Default: 25, QueryPath: "limit", }, + &requestflag.Flag[string]{ + Name: "q", + Usage: "Free-text search term, matched against the fields named in `search_by`.", + QueryPath: "q", + }, + &requestflag.Flag[[]string]{ + Name: "search-by", + Usage: "Comma-separated fields to search with `q`. Defaults to all of them. Note `query` only exists on semantic monitors.", + QueryPath: "search_by", + }, + &requestflag.Flag[string]{ + Name: "search-type", + Usage: "`prefix` for as-you-type prefix matching (default), `exact` for full-token matching.", + Default: "prefix", + QueryPath: "search_type", + }, &requestflag.Flag[string]{ Name: "status", Usage: `Allowed values: "active", "paused", "failed".`, @@ -231,6 +230,11 @@ var monitorsList = cli.Command{ Usage: "Filter to items that have this tag.", QueryPath: "tag", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Comma-separated list of tags to filter by (matches monitors having any of them).", + QueryPath: "tags", + }, &requestflag.Flag[string]{ Name: "target-type", Usage: `Allowed values: "page", "sitemap", "extract".`, diff --git a/pkg/cmd/monitor_test.go b/pkg/cmd/monitor_test.go index 6c2dd0d..5745c6a 100644 --- a/pkg/cmd/monitor_test.go +++ b/pkg/cmd/monitor_test.go @@ -17,9 +17,10 @@ func TestMonitorsCreate(t *testing.T) { "--api-key", "string", "monitors", "create", "--change-detection", "{type: exact}", - "--name", "Acme pricing monitor", + "--name", "Acme pricing page", "--schedule", "{frequency: 6, type: interval, unit: hours}", "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--mode", "web", "--tag", "pricing", "--tag", "competitor", "--webhook", "{url: https://example.com/webhook}", @@ -35,14 +36,13 @@ func TestMonitorsCreate(t *testing.T) { t, "--api-key", "string", "monitors", "create", - "--change-detection.type", "exact", - "--name", "Acme pricing monitor", + "--change-detection", "{type: exact}", + "--name", "Acme pricing page", "--schedule.frequency", "6", "--schedule.type", "interval", "--schedule.unit", "hours", - "--target.type", "page", - "--target.url", "https://acme.com/pricing", - "--target.normalize-whitespace=true", + "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--mode", "web", "--tag", "pricing", "--tag", "competitor", "--webhook.url", "https://example.com/webhook", @@ -54,7 +54,7 @@ func TestMonitorsCreate(t *testing.T) { pipeData := []byte("" + "change_detection:\n" + " type: exact\n" + - "name: Acme pricing monitor\n" + + "name: Acme pricing page\n" + "schedule:\n" + " frequency: 6\n" + " type: interval\n" + @@ -63,6 +63,7 @@ func TestMonitorsCreate(t *testing.T) { " type: page\n" + " url: https://acme.com/pricing\n" + " normalize_whitespace: true\n" + + "mode: web\n" + "tags:\n" + " - pricing\n" + " - competitor\n" + @@ -169,8 +170,12 @@ func TestMonitorsList(t *testing.T) { "--change-detection-type", "exact", "--cursor", "cursor", "--limit", "1", + "--q", "q", + "--search-by", "name", + "--search-type", "exact", "--status", "active", "--tag", "tag", + "--tag", "string", "--target-type", "page", ) }) From c728f4251ab6faf9de0fd83a2a1eaf09febbf902 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 01:32:22 +0000 Subject: [PATCH 031/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 4208b5c..1b77f50 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.0" + ".": "0.7.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index c1f2884..f37c8ca 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.6.0" // x-release-please-version +const Version = "0.7.0" // x-release-please-version From 7bb95f6d3ced3c8fc644be350a18bb2f8bb743b4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 01:36:06 +0000 Subject: [PATCH 032/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 1b77f50..1bc5713 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.7.0" + ".": "0.7.1" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index f37c8ca..5c28322 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.7.0" // x-release-please-version +const Version = "0.7.1" // x-release-please-version From e062dcc1b0b33b3e086ea44f4bf63d5b75fd5453 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 02:04:25 +0000 Subject: [PATCH 033/154] chore(internal): codegen related update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a986fba..7380821 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk v1.4.0 + github.com/context-dot-dev/context-go-sdk v1.5.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 4ca6f33..09ce704 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk v1.4.0 h1:UiQeIP5oCFIRpgklVo+tlZahUh9AsqVi3vek2kLYqSE= -github.com/context-dot-dev/context-go-sdk v1.4.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= +github.com/context-dot-dev/context-go-sdk v1.5.0 h1:9c726cgqHfD+6AzoBXvQDYFGL8GysVViEGfHwuR1w4A= +github.com/context-dot-dev/context-go-sdk v1.5.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From ffbd12b14a4b0659aec737576b3cb5834c6a93e5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 03:56:05 +0000 Subject: [PATCH 034/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 18 ++++++++++++++++++ pkg/cmd/web_test.go | 7 +++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 0115b3b..f52ab5d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-66a3bf68b47ba61c9b61406d36f614a079ff752b8964a8df8062e485391d5598.yml -openapi_spec_hash: b17d6cfe3710dd0605078f3907a1a419 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d71b08e421ccdda9a2754c307e97df0ee7444926306a00624dca2bc7d56548ac.yml +openapi_spec_hash: ebfbed20b5837ccf8db8bb40ab23baac config_hash: 7ec4851ee8d93177947e95df5ae897b5 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index a2ad59e..658febc 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -479,6 +479,12 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"shouldParse": true}, BodyPath: "pdf", }, + &requestflag.Flag[bool]{ + Name: "settle-animations", + Usage: "When true, waits briefly for CSS and transition animations to settle before extracting each crawled page. Defaults to false. This adds a bit of latency in exchange for more stable output on animated pages.", + Default: false, + BodyPath: "settleAnimations", + }, &requestflag.Flag[bool]{ Name: "shorten-base64-images", Usage: "Truncate base64-encoded image data in the Markdown output", @@ -584,6 +590,12 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"shouldParse": true}, QueryPath: "pdf", }, + &requestflag.Flag[bool]{ + Name: "settle-animations", + Usage: "When true, waits briefly for CSS and transition animations to settle before extracting HTML. Defaults to false. This adds a bit of latency in exchange for more stable output on animated pages.", + Default: false, + QueryPath: "settleAnimations", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -749,6 +761,12 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"shouldParse": true}, QueryPath: "pdf", }, + &requestflag.Flag[bool]{ + Name: "settle-animations", + Usage: "When true, waits briefly for CSS and transition animations to settle before converting to Markdown. Defaults to false. This adds a bit of latency in exchange for more stable output on animated pages.", + Default: false, + QueryPath: "settleAnimations", + }, &requestflag.Flag[bool]{ Name: "shorten-base64-images", Usage: "Shorten base64-encoded image data in the Markdown output", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 735f56f..9d71c30 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -286,6 +286,7 @@ func TestWebWebCrawlMd(t *testing.T) { "--max-depth", "0", "--max-pages", "1", "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--settle-animations=true", "--shorten-base64-images=true", "--stop-after-ms", "10000", "--timeout-ms", "1000", @@ -318,6 +319,7 @@ func TestWebWebCrawlMd(t *testing.T) { "--pdf.end", "1", "--pdf.should-parse=true", "--pdf.start", "1", + "--settle-animations=true", "--shorten-base64-images=true", "--stop-after-ms", "10000", "--timeout-ms", "1000", @@ -347,6 +349,7 @@ func TestWebWebCrawlMd(t *testing.T) { " end: 1\n" + " shouldParse: true\n" + " start: 1\n" + + "settleAnimations: true\n" + "shortenBase64Images: true\n" + "stopAfterMs: 10000\n" + "timeoutMS: 1000\n" + @@ -376,6 +379,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--include-selector", "string", "--max-age-ms", "0", "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--settle-animations=true", "--timeout-ms", "1000", "--use-main-content-only=true", "--wait-for-ms", "0", @@ -401,6 +405,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--pdf.end", "1", "--pdf.should-parse=true", "--pdf.start", "1", + "--settle-animations=true", "--timeout-ms", "1000", "--use-main-content-only=true", "--wait-for-ms", "0", @@ -463,6 +468,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--include-selector", "string", "--max-age-ms", "0", "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--settle-animations=true", "--shorten-base64-images=true", "--timeout-ms", "1000", "--use-main-content-only=true", @@ -491,6 +497,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--pdf.end", "1", "--pdf.should-parse=true", "--pdf.start", "1", + "--settle-animations=true", "--shorten-base64-images=true", "--timeout-ms", "1000", "--use-main-content-only=true", From 3efebf6541481b3d8053984abda91ec9d7ec7284 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 01:47:01 +0000 Subject: [PATCH 035/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index f52ab5d..75582f8 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d71b08e421ccdda9a2754c307e97df0ee7444926306a00624dca2bc7d56548ac.yml -openapi_spec_hash: ebfbed20b5837ccf8db8bb40ab23baac +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c7625b4a7beb9e7d9827f3b836e6539cbc5f26b6754891d4352716e38cdecd73.yml +openapi_spec_hash: cbee9cf164cc6704a6febb4d9737e83e config_hash: 7ec4851ee8d93177947e95df5ae897b5 From 828521e6cda79fca9e4af53d558f7341c0464040 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 05:14:41 +0000 Subject: [PATCH 036/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/monitor.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.stats.yml b/.stats.yml index 75582f8..3e4f564 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c7625b4a7beb9e7d9827f3b836e6539cbc5f26b6754891d4352716e38cdecd73.yml -openapi_spec_hash: cbee9cf164cc6704a6febb4d9737e83e +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-09b6020939995033719a53b988fb00bdb20c42d87070975a8d6b469fa18128fb.yml +openapi_spec_hash: ba3e471937a679e2c45c0b9a115fca5c config_hash: 7ec4851ee8d93177947e95df5ae897b5 diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index 8754aff..5aff9fe 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -222,7 +222,7 @@ var monitorsList = cli.Command{ }, &requestflag.Flag[string]{ Name: "status", - Usage: `Allowed values: "active", "paused", "failed".`, + Usage: "Monitor lifecycle status. `failed` means the most recent run failed (see the monitor's `last_error`); failed monitors keep running on schedule and flip back to `active` on the next successful run. Monitors are auto-`paused` after repeated consecutive failures or insufficient-credit skips; resume by PATCHing status to `active`.", QueryPath: "status", }, &requestflag.Flag[string]{ @@ -322,7 +322,7 @@ var monitorsListAccountRuns = cli.Command{ }, &requestflag.Flag[string]{ Name: "status", - Usage: `Allowed values: "queued", "running", "completed", "failed".`, + Usage: "Lifecycle status of a run. `skipped` runs never executed — see `skip_reason` (insufficient credits, monitor paused, or superseded by a concurrent run).", QueryPath: "status", }, }, @@ -388,7 +388,7 @@ var monitorsListRuns = cli.Command{ }, &requestflag.Flag[string]{ Name: "status", - Usage: `Allowed values: "queued", "running", "completed", "failed".`, + Usage: "Lifecycle status of a run. `skipped` runs never executed — see `skip_reason` (insufficient credits, monitor paused, or superseded by a concurrent run).", QueryPath: "status", }, }, From 0542df1cc92df2a16ceb4f3b16cacdc78d22c552 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 3 Jul 2026 05:13:27 +0000 Subject: [PATCH 037/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 3e4f564..7e51832 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-09b6020939995033719a53b988fb00bdb20c42d87070975a8d6b469fa18128fb.yml -openapi_spec_hash: ba3e471937a679e2c45c0b9a115fca5c +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-6320934d3b42a03cc52429218247595c7119e91a615db570070f71849aaa74de.yml +openapi_spec_hash: c63aeaa0fdcc422e8ad59c9fb30d2476 config_hash: 7ec4851ee8d93177947e95df5ae897b5 From dffacc69770e28e69b5b273c8c9b4c2b9ce80833 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 4 Jul 2026 18:58:59 +0000 Subject: [PATCH 038/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 7e51832..3840f48 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-6320934d3b42a03cc52429218247595c7119e91a615db570070f71849aaa74de.yml -openapi_spec_hash: c63aeaa0fdcc422e8ad59c9fb30d2476 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-171b4c39eb26210aad8afd74d63d620bf45f7e0b7f2de3938c7239741ea3f2f4.yml +openapi_spec_hash: 752c05fc817dc766061bd4357bd327ba config_hash: 7ec4851ee8d93177947e95df5ae897b5 From f5572e1b2f6cf2bb8092124dbceef33de79641cd Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 4 Jul 2026 21:59:12 +0000 Subject: [PATCH 039/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 6 ++++++ pkg/cmd/web_test.go | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 3840f48..e7ac969 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-171b4c39eb26210aad8afd74d63d620bf45f7e0b7f2de3938c7239741ea3f2f4.yml -openapi_spec_hash: 752c05fc817dc766061bd4357bd327ba +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-633097a61ae4e029434e5af07efa3017301fe8b391c27ada3eb68b61d798ef33.yml +openapi_spec_hash: 051b08a4c6530546d520aa7ec18f8123 config_hash: 7ec4851ee8d93177947e95df5ae897b5 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 658febc..f531054 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -646,6 +646,12 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Required: true, QueryPath: "url", }, + &requestflag.Flag[bool]{ + Name: "dedupe", + Usage: "When true, visually duplicate images are removed: every image is loaded and perceptually hashed, and only the highest-resolution copy of each duplicate group is kept. Images that cannot be downloaded or hashed are kept. Default: false.", + Default: false, + QueryPath: "dedupe", + }, &requestflag.Flag[map[string]any]{ Name: "enrichment", Usage: "Optional per-image processing, sent as deep-object query params such as enrichment[resolution]=true.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 9d71c30..7280e80 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -421,6 +421,7 @@ func TestWebWebScrapeImages(t *testing.T) { "--api-key", "string", "web", "web-scrape-images", "--url", "https://example.com", + "--dedupe=true", "--enrichment", "{classification: true, hostedUrl: true, maxTimePerMs: 1, resolution: true}", "--headers", "{foo: J!}", "--max-age-ms", "0", @@ -439,6 +440,7 @@ func TestWebWebScrapeImages(t *testing.T) { "--api-key", "string", "web", "web-scrape-images", "--url", "https://example.com", + "--dedupe=true", "--enrichment.classification=true", "--enrichment.hosted-url=true", "--enrichment.max-time-per-ms", "1", From 71003b2c2a9ace41b9d6be728bd63d2aa0f76073 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 01:39:10 +0000 Subject: [PATCH 040/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index e7ac969..ea3b8ae 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-633097a61ae4e029434e5af07efa3017301fe8b391c27ada3eb68b61d798ef33.yml -openapi_spec_hash: 051b08a4c6530546d520aa7ec18f8123 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-3bbf1a39f32a13c350bdbc1e8a98ebd3753ec54f70d75cd4656c1773b2d2ecad.yml +openapi_spec_hash: 69beb23616fa92b1c1f6a2a4f7a36390 config_hash: 7ec4851ee8d93177947e95df5ae897b5 From 0ea190486973147bbfd2bde6504700ce19a10491 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 03:17:47 +0000 Subject: [PATCH 041/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index ea3b8ae..77807ba 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-3bbf1a39f32a13c350bdbc1e8a98ebd3753ec54f70d75cd4656c1773b2d2ecad.yml -openapi_spec_hash: 69beb23616fa92b1c1f6a2a4f7a36390 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4b24bfbe3d1371e5ce175d71f9074b6f6aec35d4c3438013af2a54b776f8f126.yml +openapi_spec_hash: d3b67756889b03f77efaf8571bb09d59 config_hash: 7ec4851ee8d93177947e95df5ae897b5 From eaba101f2b967cdcc0a90f07f001091515a9ea6e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 04:28:09 +0000 Subject: [PATCH 042/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 77807ba..cb8d47f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4b24bfbe3d1371e5ce175d71f9074b6f6aec35d4c3438013af2a54b776f8f126.yml -openapi_spec_hash: d3b67756889b03f77efaf8571bb09d59 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-77005ca6ad90dc48689fe056a1dbd63f8eefb0224dc88530dd921a784a7b0185.yml +openapi_spec_hash: 8f3189c550a36de0ca5e1b032298acfd config_hash: 7ec4851ee8d93177947e95df5ae897b5 From d3017ac7e1e7857b84346e1c48a44c54c1a0cd42 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 05:12:35 +0000 Subject: [PATCH 043/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index cb8d47f..a272343 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-77005ca6ad90dc48689fe056a1dbd63f8eefb0224dc88530dd921a784a7b0185.yml -openapi_spec_hash: 8f3189c550a36de0ca5e1b032298acfd +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-654e47d50a02e8b12f4f035b1a8ec6e864557fed57b744c909ca85127739cc30.yml +openapi_spec_hash: a44b7d4172c8c7cd395237738867d5cb config_hash: 7ec4851ee8d93177947e95df5ae897b5 From 3478e73dbfbec2aa21e0652b960527921bc82884 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 05:31:07 +0000 Subject: [PATCH 044/154] feat(api): manual updates --- .stats.yml | 6 +- README.md | 5 +- pkg/cmd/ai.go | 153 ------------- pkg/cmd/ai_test.go | 76 ------- pkg/cmd/brand.go | 470 +++++----------------------------------- pkg/cmd/brand_test.go | 95 +------- pkg/cmd/cmd.go | 7 - pkg/cmd/utility.go | 87 ++------ pkg/cmd/utility_test.go | 36 ++- 9 files changed, 105 insertions(+), 830 deletions(-) diff --git a/.stats.yml b/.stats.yml index a272343..151723e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 36 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-654e47d50a02e8b12f4f035b1a8ec6e864557fed57b744c909ca85127739cc30.yml +configured_endpoints: 29 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2e40370ce4d7d019b30d43020674bb02aaaf2a67a8916772084815c874f99950.yml openapi_spec_hash: a44b7d4172c8c7cd395237738867d5cb -config_hash: 7ec4851ee8d93177947e95df5ae897b5 +config_hash: 472cc1adb51663e5b3d8dce16f6d29d9 diff --git a/README.md b/README.md index fa92c25..246f1dd 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,10 @@ context-dev [resource] [flags...] ``` ```sh -context-dev brand retrieve \ +context-dev web extract \ --api-key 'My API Key' \ - --domain REPLACE_ME + --schema '{type: bar, properties: bar, required: bar, additionalProperties: bar}' \ + --url https://example.com ``` For details about specific commands, use the `--help` flag. diff --git a/pkg/cmd/ai.go b/pkg/cmd/ai.go index 87b1b1d..ba0107b 100644 --- a/pkg/cmd/ai.go +++ b/pkg/cmd/ai.go @@ -14,118 +14,6 @@ import ( "github.com/urfave/cli/v3" ) -var aiAIQuery = requestflag.WithInnerFlags(cli.Command{ - Name: "ai-query", - Usage: "Use AI to extract specific data points from a brand's website. The AI will crawl\nthe website and extract the requested information based on the provided data\npoints.", - Suggest: true, - Flags: []cli.Flag{ - &requestflag.Flag[[]map[string]any]{ - Name: "data-to-extract", - Usage: "Array of data points to extract from the website", - Required: true, - BodyPath: "data_to_extract", - }, - &requestflag.Flag[string]{ - Name: "domain", - Usage: "The domain name to analyze", - Required: true, - BodyPath: "domain", - }, - &requestflag.Flag[map[string]any]{ - Name: "specific-pages", - Usage: "Optional object specifying which pages to analyze", - BodyPath: "specific_pages", - }, - &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - BodyPath: "timeoutMS", - }, - }, - Action: handleAIAIQuery, - HideHelpCommand: true, -}, map[string][]requestflag.HasOuterFlag{ - "data-to-extract": { - &requestflag.InnerFlag[string]{ - Name: "data-to-extract.datapoint-description", - Usage: "Description of what to extract", - InnerField: "datapoint_description", - }, - &requestflag.InnerFlag[string]{ - Name: "data-to-extract.datapoint-example", - Usage: "Example of the expected value", - InnerField: "datapoint_example", - }, - &requestflag.InnerFlag[string]{ - Name: "data-to-extract.datapoint-name", - Usage: "Name of the data point to extract", - InnerField: "datapoint_name", - }, - &requestflag.InnerFlag[string]{ - Name: "data-to-extract.datapoint-type", - Usage: "Type of the data point", - InnerField: "datapoint_type", - }, - &requestflag.InnerFlag[string]{ - Name: "data-to-extract.datapoint-list-type", - Usage: "Type of items in the list when datapoint_type is 'list'. Defaults to 'string'. Use 'object' to extract an array of objects matching a schema.", - InnerField: "datapoint_list_type", - }, - &requestflag.InnerFlag[map[string]any]{ - Name: "data-to-extract.datapoint-object-schema", - Usage: "Schema definition for objects when datapoint_list_type is 'object'. Provide a map of field names to their scalar types.", - InnerField: "datapoint_object_schema", - }, - }, - "specific-pages": { - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.about-us", - Usage: "Whether to analyze the about us page", - InnerField: "about_us", - }, - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.blog", - Usage: "Whether to analyze the blog", - InnerField: "blog", - }, - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.careers", - Usage: "Whether to analyze the careers page", - InnerField: "careers", - }, - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.contact-us", - Usage: "Whether to analyze the contact us page", - InnerField: "contact_us", - }, - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.faq", - Usage: "Whether to analyze the FAQ page", - InnerField: "faq", - }, - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.home-page", - Usage: "Whether to analyze the home page", - InnerField: "home_page", - }, - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.pricing", - Usage: "Whether to analyze the pricing page", - InnerField: "pricing", - }, - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.privacy-policy", - Usage: "Whether to analyze the privacy policy page", - InnerField: "privacy_policy", - }, - &requestflag.InnerFlag[bool]{ - Name: "specific-pages.terms-and-conditions", - Usage: "Whether to analyze the terms and conditions page", - InnerField: "terms_and_conditions", - }, - }, -}) - var aiExtractProduct = cli.Command{ Name: "extract-product", Usage: "Given a single URL, determines if it is a product page and extracts the product\ninformation.", @@ -189,47 +77,6 @@ var aiExtractProducts = cli.Command{ HideHelpCommand: true, } -func handleAIAIQuery(ctx context.Context, cmd *cli.Command) error { - client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) - unusedArgs := cmd.Args().Slice() - - if len(unusedArgs) > 0 { - return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) - } - - options, err := flagOptions( - cmd, - apiquery.NestedQueryFormatBrackets, - apiquery.ArrayQueryFormatComma, - ApplicationJSON, - false, - ) - if err != nil { - return err - } - - params := contextdev.AIAIQueryParams{} - - var res []byte - options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.AI.AIQuery(ctx, params, options...) - if err != nil { - return err - } - - obj := gjson.ParseBytes(res) - format := cmd.Root().String("format") - explicitFormat := cmd.Root().IsSet("format") - transform := cmd.Root().String("transform") - return ShowJSON(obj, ShowJSONOpts{ - ExplicitFormat: explicitFormat, - Format: format, - RawOutput: cmd.Root().Bool("raw-output"), - Title: "ai ai-query", - Transform: transform, - }) -} - func handleAIExtractProduct(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) unusedArgs := cmd.Args().Slice() diff --git a/pkg/cmd/ai_test.go b/pkg/cmd/ai_test.go index 5ae0952..d690bef 100644 --- a/pkg/cmd/ai_test.go +++ b/pkg/cmd/ai_test.go @@ -6,84 +6,8 @@ import ( "testing" "github.com/context-dot-dev/context-dev-cli/internal/mocktest" - "github.com/context-dot-dev/context-dev-cli/internal/requestflag" ) -func TestAIAIQuery(t *testing.T) { - t.Skip("Mock server tests are disabled") - t.Run("regular flags", func(t *testing.T) { - mocktest.TestRunMockTestWithFlags( - t, - "--api-key", "string", - "ai", "ai-query", - "--data-to-extract", "{datapoint_description: datapoint_description, datapoint_example: datapoint_example, datapoint_name: datapoint_name, datapoint_type: text, datapoint_list_type: string, datapoint_object_schema: {testimonial_text: string, testimonial_author: string}}", - "--domain", "domain", - "--specific-pages", "{about_us: true, blog: true, careers: true, contact_us: true, faq: true, home_page: true, pricing: true, privacy_policy: true, terms_and_conditions: true}", - "--timeout-ms", "1000", - ) - }) - - t.Run("inner flags", func(t *testing.T) { - // Check that inner flags have been set up correctly - requestflag.CheckInnerFlags(aiAIQuery) - - // Alternative argument passing style using inner flags - mocktest.TestRunMockTestWithFlags( - t, - "--api-key", "string", - "ai", "ai-query", - "--data-to-extract.datapoint-description", "datapoint_description", - "--data-to-extract.datapoint-example", "datapoint_example", - "--data-to-extract.datapoint-name", "datapoint_name", - "--data-to-extract.datapoint-type", "text", - "--data-to-extract.datapoint-list-type", "string", - "--data-to-extract.datapoint-object-schema", "{testimonial_text: string, testimonial_author: string}", - "--domain", "domain", - "--specific-pages.about-us=true", - "--specific-pages.blog=true", - "--specific-pages.careers=true", - "--specific-pages.contact-us=true", - "--specific-pages.faq=true", - "--specific-pages.home-page=true", - "--specific-pages.pricing=true", - "--specific-pages.privacy-policy=true", - "--specific-pages.terms-and-conditions=true", - "--timeout-ms", "1000", - ) - }) - - t.Run("piping data", func(t *testing.T) { - // Test piping YAML data over stdin - pipeData := []byte("" + - "data_to_extract:\n" + - " - datapoint_description: datapoint_description\n" + - " datapoint_example: datapoint_example\n" + - " datapoint_name: datapoint_name\n" + - " datapoint_type: text\n" + - " datapoint_list_type: string\n" + - " datapoint_object_schema:\n" + - " testimonial_text: string\n" + - " testimonial_author: string\n" + - "domain: domain\n" + - "specific_pages:\n" + - " about_us: true\n" + - " blog: true\n" + - " careers: true\n" + - " contact_us: true\n" + - " faq: true\n" + - " home_page: true\n" + - " pricing: true\n" + - " privacy_policy: true\n" + - " terms_and_conditions: true\n" + - "timeoutMS: 1000\n") - mocktest.TestRunMockTestWithPipeAndFlags( - t, pipeData, - "--api-key", "string", - "ai", "ai-query", - ) - }) -} - func TestAIExtractProduct(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index ba96e74..d13f608 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -16,253 +16,86 @@ import ( var brandRetrieve = cli.Command{ Name: "retrieve", - Usage: "Retrieve logos, backdrops, colors, industry, description, and more from any\ndomain", + Usage: "Retrieve logos, backdrops, colors, industry, description, and more. Provide\nexactly one lookup identifier in the request body: a domain, company name, email\naddress, stock ticker, or transaction descriptor.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ - Name: "domain", - Usage: "Domain name to retrieve brand data for (e.g., 'example.com', 'google.com'). Cannot be used with name or ticker parameters.", - Required: true, - QueryPath: "domain", + Name: "domain", + Usage: "Domain name to retrieve brand data for (e.g., 'stripe.com').", + BodyPath: "domain", }, &requestflag.Flag[string]{ - Name: "force-language", - Usage: "Optional parameter to force the language of the retrieved brand data.", - QueryPath: "force_language", + Name: "force-language", + Usage: `Allowed values: "afrikaans", "albanian", "amharic", "arabic", "armenian", "assamese", "aymara", "azeri", "basque", "belarusian", "bengali", "bosnian", "bulgarian", "burmese", "cantonese", "catalan", "cebuano", "chinese", "corsican", "croatian", "czech", "danish", "dutch", "english", "esperanto", "estonian", "farsi", "fijian", "finnish", "french", "galician", "georgian", "german", "greek", "guarani", "gujarati", "haitian-creole", "hausa", "hawaiian", "hebrew", "hindi", "hmong", "hungarian", "icelandic", "igbo", "indonesian", "irish", "italian", "japanese", "javanese", "kannada", "kazakh", "khmer", "kinyarwanda", "korean", "kurdish", "kyrgyz", "lao", "latin", "latvian", "lingala", "lithuanian", "luxembourgish", "macedonian", "malagasy", "malay", "malayalam", "maltese", "maori", "marathi", "mongolian", "nepali", "norwegian", "odia", "oromo", "pashto", "pidgin", "polish", "portuguese", "punjabi", "quechua", "romanian", "russian", "samoan", "scottish-gaelic", "serbian", "sesotho", "shona", "sindhi", "sinhala", "slovak", "slovene", "somali", "spanish", "sundanese", "swahili", "swedish", "tagalog", "tajik", "tamil", "tatar", "telugu", "thai", "tibetan", "tigrinya", "tongan", "tswana", "turkish", "turkmen", "ukrainian", "urdu", "uyghur", "uzbek", "vietnamese", "welsh", "wolof", "xhosa", "yiddish", "yoruba", "zulu".`, + BodyPath: "force_language", }, &requestflag.Flag[int64]{ - Name: "max-age-ms", - Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", - Default: 7776000000, - QueryPath: "maxAgeMs", + Name: "max-age-ms", + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + BodyPath: "maxAgeMs", }, &requestflag.Flag[bool]{ - Name: "max-speed", - Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data. Works with all three lookup methods.", - QueryPath: "maxSpeed", + Name: "max-speed", + Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", + BodyPath: "maxSpeed", }, &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - QueryPath: "timeoutMS", - }, - }, - Action: handleBrandRetrieve, - HideHelpCommand: true, -} - -var brandIdentifyFromTransaction = cli.Command{ - Name: "identify-from-transaction", - Usage: "Endpoint specially designed for platforms that want to identify transaction data\nby the transaction title.", - Suggest: true, - Flags: []cli.Flag{ - &requestflag.Flag[string]{ - Name: "transaction-info", - Usage: "Transaction information to identify the brand", - Required: true, - QueryPath: "transaction_info", + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", }, &requestflag.Flag[string]{ - Name: "city", - Usage: "Optional city name to prioritize when searching for the brand.", - QueryPath: "city", + Name: "name", + Usage: "Company name to retrieve brand data for (e.g., 'Apple Inc').", + BodyPath: "name", }, &requestflag.Flag[string]{ - Name: "country-gl", - Usage: "Optional country code (GL parameter) to specify the country. This affects the geographic location used for search queries.", - QueryPath: "country_gl", + Name: "country-gl", + Usage: "Optional country code hint (GL parameter) to specify the country when looking up by company name.", + BodyPath: "country_gl", }, &requestflag.Flag[string]{ - Name: "force-language", - Usage: "Optional parameter to force the language of the retrieved brand data.", - QueryPath: "force_language", + Name: "email", + Usage: "Email address to retrieve brand data for (e.g., 'jane@stripe.com').", + BodyPath: "email", }, - &requestflag.Flag[bool]{ - Name: "high-confidence-only", - Usage: "When set to true, the API will perform an additional verification steps to ensure the identified brand matches the transaction with high confidence.", - Default: false, - QueryPath: "high_confidence_only", - }, - &requestflag.Flag[bool]{ - Name: "max-speed", - Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", - QueryPath: "maxSpeed", - }, - &requestflag.Flag[string]{ - Name: "mcc", - Usage: "Optional Merchant Category Code (MCC) to help identify the business category/industry. ", - QueryPath: "mcc", - }, - &requestflag.Flag[float64]{ - Name: "phone", - Usage: "Optional phone number from the transaction to help verify brand match.", - QueryPath: "phone", - }, - &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - QueryPath: "timeoutMS", - }, - }, - Action: handleBrandIdentifyFromTransaction, - HideHelpCommand: true, -} - -var brandRetrieveByEmail = cli.Command{ - Name: "retrieve-by-email", - Usage: "Retrieve brand information using an email address while detecting disposable and\nfree email addresses. Disposable and free email addresses (like gmail.com,\nyahoo.com) will throw a 422 error.", - Suggest: true, - Flags: []cli.Flag{ &requestflag.Flag[string]{ - Name: "email", - Usage: "Email address to retrieve brand data for (e.g., 'contact@example.com'). The domain will be extracted from the email. Free email providers (gmail.com, yahoo.com, etc.) and disposable email addresses are not allowed.", - Required: true, - QueryPath: "email", - }, - &requestflag.Flag[string]{ - Name: "force-language", - Usage: "Optional parameter to force the language of the retrieved brand data.", - QueryPath: "force_language", - }, - &requestflag.Flag[int64]{ - Name: "max-age-ms", - Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", - Default: 7776000000, - QueryPath: "maxAgeMs", - }, - &requestflag.Flag[bool]{ - Name: "max-speed", - Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", - QueryPath: "maxSpeed", - }, - &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - QueryPath: "timeoutMS", - }, - }, - Action: handleBrandRetrieveByEmail, - HideHelpCommand: true, -} - -var brandRetrieveByIsin = cli.Command{ - Name: "retrieve-by-isin", - Usage: "Retrieve brand information using an ISIN (International Securities\nIdentification Number).", - Suggest: true, - Flags: []cli.Flag{ - &requestflag.Flag[string]{ - Name: "isin", - Usage: "ISIN (International Securities Identification Number) to retrieve brand data for (e.g., 'AU000000IMD5', 'US0378331005'). Must be exactly 12 characters: 2 letters followed by 9 alphanumeric characters and ending with a digit.", - Required: true, - QueryPath: "isin", - }, - &requestflag.Flag[string]{ - Name: "force-language", - Usage: "Optional parameter to force the language of the retrieved brand data.", - QueryPath: "force_language", - }, - &requestflag.Flag[int64]{ - Name: "max-age-ms", - Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", - Default: 7776000000, - QueryPath: "maxAgeMs", - }, - &requestflag.Flag[bool]{ - Name: "max-speed", - Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", - QueryPath: "maxSpeed", - }, - &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - QueryPath: "timeoutMS", + Name: "ticker", + Usage: "Stock ticker symbol to retrieve brand data for (e.g., 'AAPL').", + BodyPath: "ticker", }, - }, - Action: handleBrandRetrieveByIsin, - HideHelpCommand: true, -} - -var brandRetrieveByName = cli.Command{ - Name: "retrieve-by-name", - Usage: "Retrieve brand information using a company name.", - Suggest: true, - Flags: []cli.Flag{ &requestflag.Flag[string]{ - Name: "name", - Usage: "Company name to retrieve brand data for (e.g., 'Apple Inc', 'Microsoft Corporation'). Must be 3-30 characters.", - Required: true, - QueryPath: "name", + Name: "ticker-exchange", + Usage: "Optional stock exchange for the ticker. Defaults to NASDAQ if not specified.", + BodyPath: "ticker_exchange", }, &requestflag.Flag[string]{ - Name: "country-gl", - Usage: "Optional country code hint (GL parameter) to specify the country for the company name.", - QueryPath: "country_gl", + Name: "transaction-info", + Usage: "Transaction information to identify the brand.", + BodyPath: "transaction_info", }, &requestflag.Flag[string]{ - Name: "force-language", - Usage: "Optional parameter to force the language of the retrieved brand data.", - QueryPath: "force_language", - }, - &requestflag.Flag[int64]{ - Name: "max-age-ms", - Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", - Default: 7776000000, - QueryPath: "maxAgeMs", + Name: "city", + Usage: "Optional city name to prioritize when searching for the brand.", + BodyPath: "city", }, &requestflag.Flag[bool]{ - Name: "max-speed", - Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", - QueryPath: "maxSpeed", + Name: "high-confidence-only", + Usage: "When set to true, the API performs additional verification to ensure the identified brand matches the transaction with high confidence.", + BodyPath: "high_confidence_only", }, &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - QueryPath: "timeoutMS", - }, - }, - Action: handleBrandRetrieveByName, - HideHelpCommand: true, -} - -var brandRetrieveByTicker = cli.Command{ - Name: "retrieve-by-ticker", - Usage: "Retrieve brand information using a stock ticker symbol.", - Suggest: true, - Flags: []cli.Flag{ - &requestflag.Flag[string]{ - Name: "ticker", - Usage: "Stock ticker symbol to retrieve brand data for (e.g., 'AAPL', 'GOOGL', 'BRK.A'). Must be 1-15 characters, letters/numbers/dots only.", - Required: true, - QueryPath: "ticker", - }, - &requestflag.Flag[string]{ - Name: "force-language", - Usage: "Optional parameter to force the language of the retrieved brand data.", - QueryPath: "force_language", - }, - &requestflag.Flag[int64]{ - Name: "max-age-ms", - Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", - Default: 7776000000, - QueryPath: "maxAgeMs", - }, - &requestflag.Flag[bool]{ - Name: "max-speed", - Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", - QueryPath: "maxSpeed", - }, - &requestflag.Flag[string]{ - Name: "ticker-exchange", - Usage: "Optional stock exchange for the ticker. Defaults to NASDAQ if not specified.", - QueryPath: "ticker_exchange", + Name: "mcc", + Usage: "Optional Merchant Category Code (MCC) to help identify the business category or industry.", + BodyPath: "mcc", }, - &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - QueryPath: "timeoutMS", + &requestflag.Flag[float64]{ + Name: "phone", + Usage: "Optional phone number from the transaction to help verify brand match.", + BodyPath: "phone", }, }, - Action: handleBrandRetrieveByTicker, + Action: handleBrandRetrieve, HideHelpCommand: true, } @@ -305,7 +138,7 @@ func handleBrandRetrieve(ctx context.Context, cmd *cli.Command) error { cmd, apiquery.NestedQueryFormatBrackets, apiquery.ArrayQueryFormatComma, - EmptyBody, + ApplicationJSON, false, ) if err != nil { @@ -334,211 +167,6 @@ func handleBrandRetrieve(ctx context.Context, cmd *cli.Command) error { }) } -func handleBrandIdentifyFromTransaction(ctx context.Context, cmd *cli.Command) error { - client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) - unusedArgs := cmd.Args().Slice() - - if len(unusedArgs) > 0 { - return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) - } - - options, err := flagOptions( - cmd, - apiquery.NestedQueryFormatBrackets, - apiquery.ArrayQueryFormatComma, - EmptyBody, - false, - ) - if err != nil { - return err - } - - params := contextdev.BrandIdentifyFromTransactionParams{} - - var res []byte - options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.Brand.IdentifyFromTransaction(ctx, params, options...) - if err != nil { - return err - } - - obj := gjson.ParseBytes(res) - format := cmd.Root().String("format") - explicitFormat := cmd.Root().IsSet("format") - transform := cmd.Root().String("transform") - return ShowJSON(obj, ShowJSONOpts{ - ExplicitFormat: explicitFormat, - Format: format, - RawOutput: cmd.Root().Bool("raw-output"), - Title: "brand identify-from-transaction", - Transform: transform, - }) -} - -func handleBrandRetrieveByEmail(ctx context.Context, cmd *cli.Command) error { - client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) - unusedArgs := cmd.Args().Slice() - - if len(unusedArgs) > 0 { - return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) - } - - options, err := flagOptions( - cmd, - apiquery.NestedQueryFormatBrackets, - apiquery.ArrayQueryFormatComma, - EmptyBody, - false, - ) - if err != nil { - return err - } - - params := contextdev.BrandGetByEmailParams{} - - var res []byte - options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.Brand.GetByEmail(ctx, params, options...) - if err != nil { - return err - } - - obj := gjson.ParseBytes(res) - format := cmd.Root().String("format") - explicitFormat := cmd.Root().IsSet("format") - transform := cmd.Root().String("transform") - return ShowJSON(obj, ShowJSONOpts{ - ExplicitFormat: explicitFormat, - Format: format, - RawOutput: cmd.Root().Bool("raw-output"), - Title: "brand retrieve-by-email", - Transform: transform, - }) -} - -func handleBrandRetrieveByIsin(ctx context.Context, cmd *cli.Command) error { - client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) - unusedArgs := cmd.Args().Slice() - - if len(unusedArgs) > 0 { - return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) - } - - options, err := flagOptions( - cmd, - apiquery.NestedQueryFormatBrackets, - apiquery.ArrayQueryFormatComma, - EmptyBody, - false, - ) - if err != nil { - return err - } - - params := contextdev.BrandGetByIsinParams{} - - var res []byte - options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.Brand.GetByIsin(ctx, params, options...) - if err != nil { - return err - } - - obj := gjson.ParseBytes(res) - format := cmd.Root().String("format") - explicitFormat := cmd.Root().IsSet("format") - transform := cmd.Root().String("transform") - return ShowJSON(obj, ShowJSONOpts{ - ExplicitFormat: explicitFormat, - Format: format, - RawOutput: cmd.Root().Bool("raw-output"), - Title: "brand retrieve-by-isin", - Transform: transform, - }) -} - -func handleBrandRetrieveByName(ctx context.Context, cmd *cli.Command) error { - client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) - unusedArgs := cmd.Args().Slice() - - if len(unusedArgs) > 0 { - return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) - } - - options, err := flagOptions( - cmd, - apiquery.NestedQueryFormatBrackets, - apiquery.ArrayQueryFormatComma, - EmptyBody, - false, - ) - if err != nil { - return err - } - - params := contextdev.BrandGetByNameParams{} - - var res []byte - options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.Brand.GetByName(ctx, params, options...) - if err != nil { - return err - } - - obj := gjson.ParseBytes(res) - format := cmd.Root().String("format") - explicitFormat := cmd.Root().IsSet("format") - transform := cmd.Root().String("transform") - return ShowJSON(obj, ShowJSONOpts{ - ExplicitFormat: explicitFormat, - Format: format, - RawOutput: cmd.Root().Bool("raw-output"), - Title: "brand retrieve-by-name", - Transform: transform, - }) -} - -func handleBrandRetrieveByTicker(ctx context.Context, cmd *cli.Command) error { - client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) - unusedArgs := cmd.Args().Slice() - - if len(unusedArgs) > 0 { - return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) - } - - options, err := flagOptions( - cmd, - apiquery.NestedQueryFormatBrackets, - apiquery.ArrayQueryFormatComma, - EmptyBody, - false, - ) - if err != nil { - return err - } - - params := contextdev.BrandGetByTickerParams{} - - var res []byte - options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.Brand.GetByTicker(ctx, params, options...) - if err != nil { - return err - } - - obj := gjson.ParseBytes(res) - format := cmd.Root().String("format") - explicitFormat := cmd.Root().IsSet("format") - transform := cmd.Root().String("transform") - return ShowJSON(obj, ShowJSONOpts{ - ExplicitFormat: explicitFormat, - Format: format, - RawOutput: cmd.Root().Bool("raw-output"), - Title: "brand retrieve-by-ticker", - Transform: transform, - }) -} - func handleBrandRetrieveSimplified(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) unusedArgs := cmd.Args().Slice() diff --git a/pkg/cmd/brand_test.go b/pkg/cmd/brand_test.go index ffc41a8..7a0c886 100644 --- a/pkg/cmd/brand_test.go +++ b/pkg/cmd/brand_test.go @@ -17,95 +17,24 @@ func TestBrandRetrieve(t *testing.T) { "brand", "retrieve", "--domain", "domain", "--force-language", "afrikaans", - "--max-age-ms", "86400000", - "--max-speed=true", - "--timeout-ms", "1000", - ) - }) -} - -func TestBrandIdentifyFromTransaction(t *testing.T) { - t.Skip("Mock server tests are disabled") - t.Run("regular flags", func(t *testing.T) { - mocktest.TestRunMockTestWithFlags( - t, - "--api-key", "string", - "brand", "identify-from-transaction", - "--transaction-info", "transaction_info", - "--city", "city", - "--country-gl", "ad", - "--force-language", "afrikaans", - "--high-confidence-only=true", - "--max-speed=true", - "--mcc", "mcc", - "--phone", "0", - "--timeout-ms", "1000", - ) - }) -} - -func TestBrandRetrieveByEmail(t *testing.T) { - t.Skip("Mock server tests are disabled") - t.Run("regular flags", func(t *testing.T) { - mocktest.TestRunMockTestWithFlags( - t, - "--api-key", "string", - "brand", "retrieve-by-email", - "--email", "dev@stainless.com", - "--force-language", "afrikaans", - "--max-age-ms", "86400000", - "--max-speed=true", - "--timeout-ms", "1000", - ) - }) -} - -func TestBrandRetrieveByIsin(t *testing.T) { - t.Skip("Mock server tests are disabled") - t.Run("regular flags", func(t *testing.T) { - mocktest.TestRunMockTestWithFlags( - t, - "--api-key", "string", - "brand", "retrieve-by-isin", - "--isin", "SE60513A9993", - "--force-language", "afrikaans", - "--max-age-ms", "86400000", + "--max-age-ms", "0", "--max-speed=true", "--timeout-ms", "1000", ) }) -} -func TestBrandRetrieveByName(t *testing.T) { - t.Skip("Mock server tests are disabled") - t.Run("regular flags", func(t *testing.T) { - mocktest.TestRunMockTestWithFlags( - t, + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "domain: domain\n" + + "force_language: afrikaans\n" + + "maxAgeMs: 0\n" + + "maxSpeed: true\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, "--api-key", "string", - "brand", "retrieve-by-name", - "--name", "xxx", - "--country-gl", "ad", - "--force-language", "afrikaans", - "--max-age-ms", "86400000", - "--max-speed=true", - "--timeout-ms", "1000", - ) - }) -} - -func TestBrandRetrieveByTicker(t *testing.T) { - t.Skip("Mock server tests are disabled") - t.Run("regular flags", func(t *testing.T) { - mocktest.TestRunMockTestWithFlags( - t, - "--api-key", "string", - "brand", "retrieve-by-ticker", - "--ticker", "ticker", - "--force-language", "afrikaans", - "--max-age-ms", "86400000", - "--max-speed=true", - "--ticker-exchange", "AMEX", - "--timeout-ms", "1000", + "brand", "retrieve", ) }) } diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index c651ff5..85854aa 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -107,7 +107,6 @@ func init() { Category: "API RESOURCE", Suggest: true, Commands: []*cli.Command{ - &aiAIQuery, &aiExtractProduct, &aiExtractProducts, }, @@ -118,11 +117,6 @@ func init() { Suggest: true, Commands: []*cli.Command{ &brandRetrieve, - &brandIdentifyFromTransaction, - &brandRetrieveByEmail, - &brandRetrieveByIsin, - &brandRetrieveByName, - &brandRetrieveByTicker, &brandRetrieveSimplified, }, }, @@ -141,7 +135,6 @@ func init() { Suggest: true, Commands: []*cli.Command{ &utilityPrefetch, - &utilityPrefetchByEmail, }, }, { diff --git a/pkg/cmd/utility.go b/pkg/cmd/utility.go index a690ee0..486bc1a 100644 --- a/pkg/cmd/utility.go +++ b/pkg/cmd/utility.go @@ -14,16 +14,22 @@ import ( "github.com/urfave/cli/v3" ) -var utilityPrefetch = cli.Command{ +var utilityPrefetch = requestflag.WithInnerFlags(cli.Command{ Name: "prefetch", - Usage: "Signal that you may fetch brand data for a particular domain soon to improve\nlatency.", + Usage: "Signal that you may fetch brand data soon to improve latency. The type field\nselects what to prefetch (currently only 'brand') and identifier carries exactly\none lookup key: a domain, or an email whose domain is extracted and validated\n(free email providers and disposable email addresses are not allowed).", Suggest: true, Flags: []cli.Flag{ + &requestflag.Flag[map[string]any]{ + Name: "identifier", + Usage: "Identifier of the brand to prefetch. Provide exactly one of domain or email.", + Required: true, + BodyPath: "identifier", + }, &requestflag.Flag[string]{ - Name: "domain", - Usage: "Domain name to prefetch brand data for", + Name: "type", + Usage: "What to prefetch. Currently only 'brand' is supported.", Required: true, - BodyPath: "domain", + BodyPath: "type", }, &requestflag.Flag[int64]{ Name: "timeout-ms", @@ -33,28 +39,20 @@ var utilityPrefetch = cli.Command{ }, Action: handleUtilityPrefetch, HideHelpCommand: true, -} - -var utilityPrefetchByEmail = cli.Command{ - Name: "prefetch-by-email", - Usage: "Signal that you may fetch brand data for a particular domain soon to improve\nlatency. This endpoint accepts an email address, extracts the domain from it,\nvalidates that it's not a disposable or free email provider, and queues the\ndomain for prefetching.", - Suggest: true, - Flags: []cli.Flag{ - &requestflag.Flag[string]{ - Name: "email", - Usage: "Email address to prefetch brand data for. The domain will be extracted from the email. Free email providers (gmail.com, yahoo.com, etc.) and disposable email addresses are not allowed.", - Required: true, - BodyPath: "email", +}, map[string][]requestflag.HasOuterFlag{ + "identifier": { + &requestflag.InnerFlag[string]{ + Name: "identifier.domain", + Usage: "Domain name to prefetch brand data for", + InnerField: "domain", }, - &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - BodyPath: "timeoutMS", + &requestflag.InnerFlag[string]{ + Name: "identifier.email", + Usage: "Email address to prefetch brand data for. The domain will be extracted from the email. Free email providers (gmail.com, yahoo.com, etc.) and disposable email addresses are not allowed.", + InnerField: "email", }, }, - Action: handleUtilityPrefetchByEmail, - HideHelpCommand: true, -} +}) func handleUtilityPrefetch(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) @@ -96,44 +94,3 @@ func handleUtilityPrefetch(ctx context.Context, cmd *cli.Command) error { Transform: transform, }) } - -func handleUtilityPrefetchByEmail(ctx context.Context, cmd *cli.Command) error { - client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) - unusedArgs := cmd.Args().Slice() - - if len(unusedArgs) > 0 { - return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) - } - - options, err := flagOptions( - cmd, - apiquery.NestedQueryFormatBrackets, - apiquery.ArrayQueryFormatComma, - ApplicationJSON, - false, - ) - if err != nil { - return err - } - - params := contextdev.UtilityPrefetchByEmailParams{} - - var res []byte - options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.Utility.PrefetchByEmail(ctx, params, options...) - if err != nil { - return err - } - - obj := gjson.ParseBytes(res) - format := cmd.Root().String("format") - explicitFormat := cmd.Root().IsSet("format") - transform := cmd.Root().String("transform") - return ShowJSON(obj, ShowJSONOpts{ - ExplicitFormat: explicitFormat, - Format: format, - RawOutput: cmd.Root().Bool("raw-output"), - Title: "utility prefetch-by-email", - Transform: transform, - }) -} diff --git a/pkg/cmd/utility_test.go b/pkg/cmd/utility_test.go index f1670ea..58c2e25 100644 --- a/pkg/cmd/utility_test.go +++ b/pkg/cmd/utility_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/context-dot-dev/context-dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" ) func TestUtilityPrefetch(t *testing.T) { @@ -15,32 +16,24 @@ func TestUtilityPrefetch(t *testing.T) { t, "--api-key", "string", "utility", "prefetch", - "--domain", "domain", + "--identifier", "{domain: domain, email: dev@stainless.com}", + "--type", "brand", "--timeout-ms", "1000", ) }) - t.Run("piping data", func(t *testing.T) { - // Test piping YAML data over stdin - pipeData := []byte("" + - "domain: domain\n" + - "timeoutMS: 1000\n") - mocktest.TestRunMockTestWithPipeAndFlags( - t, pipeData, - "--api-key", "string", - "utility", "prefetch", - ) - }) -} + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(utilityPrefetch) -func TestUtilityPrefetchByEmail(t *testing.T) { - t.Skip("Mock server tests are disabled") - t.Run("regular flags", func(t *testing.T) { + // Alternative argument passing style using inner flags mocktest.TestRunMockTestWithFlags( t, "--api-key", "string", - "utility", "prefetch-by-email", - "--email", "dev@stainless.com", + "utility", "prefetch", + "--identifier.domain", "domain", + "--identifier.email", "dev@stainless.com", + "--type", "brand", "--timeout-ms", "1000", ) }) @@ -48,12 +41,15 @@ func TestUtilityPrefetchByEmail(t *testing.T) { t.Run("piping data", func(t *testing.T) { // Test piping YAML data over stdin pipeData := []byte("" + - "email: dev@stainless.com\n" + + "identifier:\n" + + " domain: domain\n" + + " email: dev@stainless.com\n" + + "type: brand\n" + "timeoutMS: 1000\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, "--api-key", "string", - "utility", "prefetch-by-email", + "utility", "prefetch", ) }) } From c208c21d1a942cd10f6d50691fcaa10942569f7d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 05:33:28 +0000 Subject: [PATCH 045/154] feat(api): manual updates --- .stats.yml | 4 ++-- README.md | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.stats.yml b/.stats.yml index 151723e..0ae96ea 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2e40370ce4d7d019b30d43020674bb02aaaf2a67a8916772084815c874f99950.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-9de98d1d4d2c9a431961599cb54716212c06200a919e09adedd42244038ec07b.yml openapi_spec_hash: a44b7d4172c8c7cd395237738867d5cb -config_hash: 472cc1adb51663e5b3d8dce16f6d29d9 +config_hash: ff35e224e809656528c44163aa41bebd diff --git a/README.md b/README.md index 246f1dd..fa92c25 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,9 @@ context-dev [resource] [flags...] ``` ```sh -context-dev web extract \ +context-dev brand retrieve \ --api-key 'My API Key' \ - --schema '{type: bar, properties: bar, required: bar, additionalProperties: bar}' \ - --url https://example.com + --domain REPLACE_ME ``` For details about specific commands, use the `--help` flag. From 52b848ca0bacea3907d2d71b207ff5d3e12f7c46 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 05:45:16 +0000 Subject: [PATCH 046/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/utility.go | 17 ++--------------- pkg/cmd/utility_test.go | 20 +------------------- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/.stats.yml b/.stats.yml index 0ae96ea..c36fec2 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-9de98d1d4d2c9a431961599cb54716212c06200a919e09adedd42244038ec07b.yml -openapi_spec_hash: a44b7d4172c8c7cd395237738867d5cb +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5280c0f42603633a06d2404b120b98d0d9aa43256d13680bbdead7579a90452a.yml +openapi_spec_hash: 34869d638c12bf076949bb7e050dd634 config_hash: ff35e224e809656528c44163aa41bebd diff --git a/pkg/cmd/utility.go b/pkg/cmd/utility.go index 486bc1a..a98eac1 100644 --- a/pkg/cmd/utility.go +++ b/pkg/cmd/utility.go @@ -14,7 +14,7 @@ import ( "github.com/urfave/cli/v3" ) -var utilityPrefetch = requestflag.WithInnerFlags(cli.Command{ +var utilityPrefetch = cli.Command{ Name: "prefetch", Usage: "Signal that you may fetch brand data soon to improve latency. The type field\nselects what to prefetch (currently only 'brand') and identifier carries exactly\none lookup key: a domain, or an email whose domain is extracted and validated\n(free email providers and disposable email addresses are not allowed).", Suggest: true, @@ -39,20 +39,7 @@ var utilityPrefetch = requestflag.WithInnerFlags(cli.Command{ }, Action: handleUtilityPrefetch, HideHelpCommand: true, -}, map[string][]requestflag.HasOuterFlag{ - "identifier": { - &requestflag.InnerFlag[string]{ - Name: "identifier.domain", - Usage: "Domain name to prefetch brand data for", - InnerField: "domain", - }, - &requestflag.InnerFlag[string]{ - Name: "identifier.email", - Usage: "Email address to prefetch brand data for. The domain will be extracted from the email. Free email providers (gmail.com, yahoo.com, etc.) and disposable email addresses are not allowed.", - InnerField: "email", - }, - }, -}) +} func handleUtilityPrefetch(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) diff --git a/pkg/cmd/utility_test.go b/pkg/cmd/utility_test.go index 58c2e25..f9d5b35 100644 --- a/pkg/cmd/utility_test.go +++ b/pkg/cmd/utility_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/context-dot-dev/context-dev-cli/internal/mocktest" - "github.com/context-dot-dev/context-dev-cli/internal/requestflag" ) func TestUtilityPrefetch(t *testing.T) { @@ -16,23 +15,7 @@ func TestUtilityPrefetch(t *testing.T) { t, "--api-key", "string", "utility", "prefetch", - "--identifier", "{domain: domain, email: dev@stainless.com}", - "--type", "brand", - "--timeout-ms", "1000", - ) - }) - - t.Run("inner flags", func(t *testing.T) { - // Check that inner flags have been set up correctly - requestflag.CheckInnerFlags(utilityPrefetch) - - // Alternative argument passing style using inner flags - mocktest.TestRunMockTestWithFlags( - t, - "--api-key", "string", - "utility", "prefetch", - "--identifier.domain", "domain", - "--identifier.email", "dev@stainless.com", + "--identifier", "{domain: domain}", "--type", "brand", "--timeout-ms", "1000", ) @@ -43,7 +26,6 @@ func TestUtilityPrefetch(t *testing.T) { pipeData := []byte("" + "identifier:\n" + " domain: domain\n" + - " email: dev@stainless.com\n" + "type: brand\n" + "timeoutMS: 1000\n") mocktest.TestRunMockTestWithPipeAndFlags( From 770243de823c1daa45647d614c01750e27611457 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 07:05:39 +0000 Subject: [PATCH 047/154] feat(api): api update --- .stats.yml | 4 ++-- README.md | 3 ++- pkg/cmd/brand.go | 6 ++++++ pkg/cmd/brand_test.go | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index c36fec2..f52f430 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5280c0f42603633a06d2404b120b98d0d9aa43256d13680bbdead7579a90452a.yml -openapi_spec_hash: 34869d638c12bf076949bb7e050dd634 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-7dbd739a81e6aaf7fc7ef1858606e7d572d309af55082a66431d9292e655e66f.yml +openapi_spec_hash: a6374d5d718a7bd9d3d54fb657e2bd9d config_hash: ff35e224e809656528c44163aa41bebd diff --git a/README.md b/README.md index fa92c25..b36987c 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,8 @@ context-dev [resource] [flags...] ```sh context-dev brand retrieve \ --api-key 'My API Key' \ - --domain REPLACE_ME + --domain REPLACE_ME \ + --type by_domain ``` For details about specific commands, use the `--help` flag. diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index d13f608..c840c53 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -24,6 +24,12 @@ var brandRetrieve = cli.Command{ Usage: "Domain name to retrieve brand data for (e.g., 'stripe.com').", BodyPath: "domain", }, + &requestflag.Flag[string]{ + Name: "type", + Usage: "Discriminator for domain-based brand retrieval.", + Required: true, + BodyPath: "type", + }, &requestflag.Flag[string]{ Name: "force-language", Usage: `Allowed values: "afrikaans", "albanian", "amharic", "arabic", "armenian", "assamese", "aymara", "azeri", "basque", "belarusian", "bengali", "bosnian", "bulgarian", "burmese", "cantonese", "catalan", "cebuano", "chinese", "corsican", "croatian", "czech", "danish", "dutch", "english", "esperanto", "estonian", "farsi", "fijian", "finnish", "french", "galician", "georgian", "german", "greek", "guarani", "gujarati", "haitian-creole", "hausa", "hawaiian", "hebrew", "hindi", "hmong", "hungarian", "icelandic", "igbo", "indonesian", "irish", "italian", "japanese", "javanese", "kannada", "kazakh", "khmer", "kinyarwanda", "korean", "kurdish", "kyrgyz", "lao", "latin", "latvian", "lingala", "lithuanian", "luxembourgish", "macedonian", "malagasy", "malay", "malayalam", "maltese", "maori", "marathi", "mongolian", "nepali", "norwegian", "odia", "oromo", "pashto", "pidgin", "polish", "portuguese", "punjabi", "quechua", "romanian", "russian", "samoan", "scottish-gaelic", "serbian", "sesotho", "shona", "sindhi", "sinhala", "slovak", "slovene", "somali", "spanish", "sundanese", "swahili", "swedish", "tagalog", "tajik", "tamil", "tatar", "telugu", "thai", "tibetan", "tigrinya", "tongan", "tswana", "turkish", "turkmen", "ukrainian", "urdu", "uyghur", "uzbek", "vietnamese", "welsh", "wolof", "xhosa", "yiddish", "yoruba", "zulu".`, diff --git a/pkg/cmd/brand_test.go b/pkg/cmd/brand_test.go index 7a0c886..e3a79c7 100644 --- a/pkg/cmd/brand_test.go +++ b/pkg/cmd/brand_test.go @@ -16,6 +16,7 @@ func TestBrandRetrieve(t *testing.T) { "--api-key", "string", "brand", "retrieve", "--domain", "domain", + "--type", "by_domain", "--force-language", "afrikaans", "--max-age-ms", "0", "--max-speed=true", @@ -27,6 +28,7 @@ func TestBrandRetrieve(t *testing.T) { // Test piping YAML data over stdin pipeData := []byte("" + "domain: domain\n" + + "type: by_domain\n" + "force_language: afrikaans\n" + "maxAgeMs: 0\n" + "maxSpeed: true\n" + From 6eccda385dfa145b0bdd4b6578a4cfec6629289e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 07:11:22 +0000 Subject: [PATCH 048/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 1bc5713..6538ca9 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.7.1" + ".": "0.8.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 5c28322..f838a39 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.7.1" // x-release-please-version +const Version = "0.8.0" // x-release-please-version From e51f1259adeb4811efc7b9c29912c8525462158e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 14:57:23 +0000 Subject: [PATCH 049/154] feat(api): api update --- .github/workflows/ci.yml | 8 ++++---- cmd/context-dev/main.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- pkg/cmd/ai.go | 4 ++-- pkg/cmd/brand.go | 4 ++-- pkg/cmd/cmdutil.go | 2 +- pkg/cmd/flagoptions.go | 2 +- pkg/cmd/industry.go | 4 ++-- pkg/cmd/monitor.go | 4 ++-- pkg/cmd/utility.go | 4 ++-- pkg/cmd/web.go | 4 ++-- scripts/build | 2 +- scripts/link | 4 ++-- scripts/lint | 2 +- scripts/run | 2 +- scripts/test | 2 +- scripts/unlink | 2 +- 18 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4c6d5c..29c1f5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ on: - 'stl-preview-base/**' env: - GOPRIVATE: github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go + GOPRIVATE: github.com/context-dot-dev/context-go-sdk/v2,github.com/stainless-sdks/context.dev-go/v2 jobs: lint: @@ -34,7 +34,7 @@ jobs: - name: Link staging branch if: github.repository == 'stainless-sdks/context.dev-cli' run: | - ./scripts/link 'github.com/stainless-sdks/context.dev-go@${{ github.ref_name }}' || true + ./scripts/link 'github.com/stainless-sdks/context.dev-go/v2@${{ github.ref_name }}' || true - name: Bootstrap run: ./scripts/bootstrap @@ -60,7 +60,7 @@ jobs: - name: Link staging branch if: github.repository == 'stainless-sdks/context.dev-cli' run: | - ./scripts/link 'github.com/stainless-sdks/context.dev-go@${{ github.ref_name }}' || true + ./scripts/link 'github.com/stainless-sdks/context.dev-go/v2@${{ github.ref_name }}' || true - name: Bootstrap run: ./scripts/bootstrap @@ -107,7 +107,7 @@ jobs: - name: Link staging branch if: github.repository == 'stainless-sdks/context.dev-cli' run: | - ./scripts/link 'github.com/stainless-sdks/context.dev-go@${{ github.ref_name }}' || true + ./scripts/link 'github.com/stainless-sdks/context.dev-go/v2@${{ github.ref_name }}' || true - name: Bootstrap run: ./scripts/bootstrap diff --git a/cmd/context-dev/main.go b/cmd/context-dev/main.go index 43678b5..7631be3 100644 --- a/cmd/context-dev/main.go +++ b/cmd/context-dev/main.go @@ -11,7 +11,7 @@ import ( "slices" "github.com/context-dot-dev/context-dev-cli/pkg/cmd" - "github.com/context-dot-dev/context-go-sdk" + "github.com/context-dot-dev/context-go-sdk/v2" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/go.mod b/go.mod index 7380821..2741028 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk v1.5.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.0.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 09ce704..1be65a5 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk v1.5.0 h1:9c726cgqHfD+6AzoBXvQDYFGL8GysVViEGfHwuR1w4A= -github.com/context-dot-dev/context-go-sdk v1.5.0/go.mod h1:YwbwUXSpQRB5LdVmgyIyZhIgKyulaeQmVWxylI4KE54= +github.com/context-dot-dev/context-go-sdk/v2 v2.0.0 h1:3ENF1kNV5f5eoP+wB2K00nZAzRXW4ytPvP3NPVQSFSs= +github.com/context-dot-dev/context-go-sdk/v2 v2.0.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/pkg/cmd/ai.go b/pkg/cmd/ai.go index ba0107b..138afcf 100644 --- a/pkg/cmd/ai.go +++ b/pkg/cmd/ai.go @@ -8,8 +8,8 @@ import ( "github.com/context-dot-dev/context-dev-cli/internal/apiquery" "github.com/context-dot-dev/context-dev-cli/internal/requestflag" - "github.com/context-dot-dev/context-go-sdk" - "github.com/context-dot-dev/context-go-sdk/option" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index c840c53..c884908 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -8,8 +8,8 @@ import ( "github.com/context-dot-dev/context-dev-cli/internal/apiquery" "github.com/context-dot-dev/context-dev-cli/internal/requestflag" - "github.com/context-dot-dev/context-go-sdk" - "github.com/context-dot-dev/context-go-sdk/option" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/cmdutil.go b/pkg/cmd/cmdutil.go index 7ffa0f7..0867816 100644 --- a/pkg/cmd/cmdutil.go +++ b/pkg/cmd/cmdutil.go @@ -17,7 +17,7 @@ import ( "syscall" "github.com/context-dot-dev/context-dev-cli/internal/jsonview" - "github.com/context-dot-dev/context-go-sdk/option" + "github.com/context-dot-dev/context-go-sdk/v2/option" "github.com/charmbracelet/x/term" "github.com/itchyny/json2yaml" diff --git a/pkg/cmd/flagoptions.go b/pkg/cmd/flagoptions.go index 9f23588..1879fc1 100644 --- a/pkg/cmd/flagoptions.go +++ b/pkg/cmd/flagoptions.go @@ -20,7 +20,7 @@ import ( "github.com/context-dot-dev/context-dev-cli/internal/apiquery" "github.com/context-dot-dev/context-dev-cli/internal/debugmiddleware" "github.com/context-dot-dev/context-dev-cli/internal/requestflag" - "github.com/context-dot-dev/context-go-sdk/option" + "github.com/context-dot-dev/context-go-sdk/v2/option" "github.com/goccy/go-yaml" "github.com/urfave/cli/v3" diff --git a/pkg/cmd/industry.go b/pkg/cmd/industry.go index 0b150b5..ed317cf 100644 --- a/pkg/cmd/industry.go +++ b/pkg/cmd/industry.go @@ -8,8 +8,8 @@ import ( "github.com/context-dot-dev/context-dev-cli/internal/apiquery" "github.com/context-dot-dev/context-dev-cli/internal/requestflag" - "github.com/context-dot-dev/context-go-sdk" - "github.com/context-dot-dev/context-go-sdk/option" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index 5aff9fe..53548d9 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -8,8 +8,8 @@ import ( "github.com/context-dot-dev/context-dev-cli/internal/apiquery" "github.com/context-dot-dev/context-dev-cli/internal/requestflag" - "github.com/context-dot-dev/context-go-sdk" - "github.com/context-dot-dev/context-go-sdk/option" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/utility.go b/pkg/cmd/utility.go index a98eac1..ac0a997 100644 --- a/pkg/cmd/utility.go +++ b/pkg/cmd/utility.go @@ -8,8 +8,8 @@ import ( "github.com/context-dot-dev/context-dev-cli/internal/apiquery" "github.com/context-dot-dev/context-dev-cli/internal/requestflag" - "github.com/context-dot-dev/context-go-sdk" - "github.com/context-dot-dev/context-go-sdk/option" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index f531054..03a3e3e 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -8,8 +8,8 @@ import ( "github.com/context-dot-dev/context-dev-cli/internal/apiquery" "github.com/context-dot-dev/context-dev-cli/internal/requestflag" - "github.com/context-dot-dev/context-go-sdk" - "github.com/context-dot-dev/context-go-sdk/option" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" "github.com/tidwall/gjson" "github.com/urfave/cli/v3" ) diff --git a/scripts/build b/scripts/build index 9ca42cd..499fe73 100755 --- a/scripts/build +++ b/scripts/build @@ -5,7 +5,7 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk/v2,github.com/stainless-sdks/context.dev-go/v2" echo "==> Building context-dev" go build ./cmd/context-dev diff --git a/scripts/link b/scripts/link index 8519bd7..abb68d9 100755 --- a/scripts/link +++ b/scripts/link @@ -5,12 +5,12 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk/v2,github.com/stainless-sdks/context.dev-go/v2" REPLACEMENT="${1:-"../context.dev-go"}" echo "==> Replacing Go SDK with $REPLACEMENT" if [[ -d "$REPLACEMENT" ]] || go list -m "$REPLACEMENT" >/dev/null; then - go mod edit -replace github.com/context-dot-dev/context-go-sdk="$REPLACEMENT" + go mod edit -replace github.com/context-dot-dev/context-go-sdk/v2="$REPLACEMENT" go mod tidy -e else echo "Skipping Go SDK replacement (branch may not exist on Go SDK)" diff --git a/scripts/lint b/scripts/lint index 096034e..6abbdeb 100755 --- a/scripts/lint +++ b/scripts/lint @@ -5,7 +5,7 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk/v2,github.com/stainless-sdks/context.dev-go/v2" echo "==> Running Go build" go build ./... diff --git a/scripts/run b/scripts/run index 192c0c6..4826ab6 100755 --- a/scripts/run +++ b/scripts/run @@ -5,6 +5,6 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk/v2,github.com/stainless-sdks/context.dev-go/v2" go run ./cmd/context-dev "$@" diff --git a/scripts/test b/scripts/test index 3cbf5d8..ba3a3c7 100755 --- a/scripts/test +++ b/scripts/test @@ -5,7 +5,7 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk,github.com/stainless-sdks/context.dev-go" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/context-dot-dev/context-go-sdk/v2,github.com/stainless-sdks/context.dev-go/v2" diff --git a/scripts/unlink b/scripts/unlink index 6b26500..4cda132 100755 --- a/scripts/unlink +++ b/scripts/unlink @@ -5,4 +5,4 @@ set -e cd "$(dirname "$0")/.." echo "==> Unlinking with local directory" -go mod edit -dropreplace github.com/context-dot-dev/context-go-sdk +go mod edit -dropreplace github.com/context-dot-dev/context-go-sdk/v2 From 3846643b158fdc60e5ce5c3fbb736adf14fc58dd Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 7 Jul 2026 04:22:58 +0000 Subject: [PATCH 050/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index f52f430..df5918b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-7dbd739a81e6aaf7fc7ef1858606e7d572d309af55082a66431d9292e655e66f.yml -openapi_spec_hash: a6374d5d718a7bd9d3d54fb657e2bd9d +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-6fd8cb15c904d1befd41a85ef8ffa3dfda11e60d560e466857e331e177e0c1e1.yml +openapi_spec_hash: 0f969f518e16e4fc41d00a5229705f5f config_hash: ff35e224e809656528c44163aa41bebd From 4f650342d92a3420d9b17d98ec34134eab2d2cfd Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 8 Jul 2026 00:10:06 +0000 Subject: [PATCH 051/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/brand.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index df5918b..5321a02 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-6fd8cb15c904d1befd41a85ef8ffa3dfda11e60d560e466857e331e177e0c1e1.yml -openapi_spec_hash: 0f969f518e16e4fc41d00a5229705f5f +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-fa5c7cd62da1c7cb2eddf8c6bb1f32ca7f958be5c3c315ade6ca0a669814d75a.yml +openapi_spec_hash: 8358c1a467ab971afd59d615d1e731ee config_hash: ff35e224e809656528c44163aa41bebd diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index c884908..ea4e594 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -16,7 +16,7 @@ import ( var brandRetrieve = cli.Command{ Name: "retrieve", - Usage: "Retrieve logos, backdrops, colors, industry, description, and more. Provide\nexactly one lookup identifier in the request body: a domain, company name, email\naddress, stock ticker, or transaction descriptor.", + Usage: "Retrieve logos, backdrops, colors, industry, description, and more. Provide\nexactly one lookup identifier in the request body: a domain, company name, email\naddress, stock ticker, transaction descriptor, or direct URL. Note:\n`by_direct_url` fetches brand data only from the provided URL — not from the\nentire internet.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ @@ -75,6 +75,11 @@ var brandRetrieve = cli.Command{ Usage: "Optional stock exchange for the ticker. Defaults to NASDAQ if not specified.", BodyPath: "ticker_exchange", }, + &requestflag.Flag[string]{ + Name: "direct-url", + Usage: "Full http(s) URL to fetch brand data from (e.g., 'https://stripe.com/enterprise'). Only this URL is fetched — not the entire internet.", + BodyPath: "direct_url", + }, &requestflag.Flag[string]{ Name: "transaction-info", Usage: "Transaction information to identify the brand.", From b84ddcb89e954d983e9d33552c8b6fd7b25df40f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 8 Jul 2026 00:36:14 +0000 Subject: [PATCH 052/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/monitor.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index 5321a02..085d46d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-fa5c7cd62da1c7cb2eddf8c6bb1f32ca7f958be5c3c315ade6ca0a669814d75a.yml -openapi_spec_hash: 8358c1a467ab971afd59d615d1e731ee +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-b075e5704110b3c03bd81b41f62b836d7624eceed7feb0ac63720dec9a4cbba4.yml +openapi_spec_hash: 5efb926e6e99163e3e42a98986da8335 config_hash: ff35e224e809656528c44163aa41bebd diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index 53548d9..ffd0568 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -211,7 +211,7 @@ var monitorsList = cli.Command{ }, &requestflag.Flag[[]string]{ Name: "search-by", - Usage: "Comma-separated fields to search with `q`. Defaults to all of them. Note `query` only exists on semantic monitors.", + Usage: "Comma-separated fields to search with `q`. Defaults to all of them. Note `instructions` only exists on extract monitors.", QueryPath: "search_by", }, &requestflag.Flag[string]{ From 1c750cb13847a5d9705f4f2256472862e32560fc Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 8 Jul 2026 01:35:34 +0000 Subject: [PATCH 053/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 085d46d..6b4e1c4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-b075e5704110b3c03bd81b41f62b836d7624eceed7feb0ac63720dec9a4cbba4.yml -openapi_spec_hash: 5efb926e6e99163e3e42a98986da8335 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-51ebe668b198157ccb18984017dd2fe35f7675220e8b933b03325b3c459ef2a6.yml +openapi_spec_hash: b3ed94bd6b59d4e32fc2c5aa8187d6b2 config_hash: ff35e224e809656528c44163aa41bebd From c7b6787d984401bdb0a183c2fea47dfa98715708 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 00:33:18 +0000 Subject: [PATCH 054/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6538ca9..6d78745 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.8.0" + ".": "0.9.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index f838a39..8791541 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.8.0" // x-release-please-version +const Version = "0.9.0" // x-release-please-version From 4d7a8a042e19c323a736fb57a8afef4a68796db0 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 04:33:26 +0000 Subject: [PATCH 055/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2741028..f0d5d12 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.0.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.1.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 1be65a5..919a559 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.0.0 h1:3ENF1kNV5f5eoP+wB2K00nZAzRXW4ytPvP3NPVQSFSs= -github.com/context-dot-dev/context-go-sdk/v2 v2.0.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.1.0 h1:Npy3In0Wda7r+TPlvjnoErIe/6s4qZ80uymsC6QCrUQ= +github.com/context-dot-dev/context-go-sdk/v2 v2.1.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 397138bc210a3c8cd553f3187bc7bfdfe58aa358 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 16:48:13 +0000 Subject: [PATCH 056/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6b4e1c4..9768c4b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-51ebe668b198157ccb18984017dd2fe35f7675220e8b933b03325b3c459ef2a6.yml -openapi_spec_hash: b3ed94bd6b59d4e32fc2c5aa8187d6b2 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ea4f36d262d32250c0626d46b9df01e15fd17dec54928c712284693c8be487d2.yml +openapi_spec_hash: 33fe53c36120b880472d3743ba2bd898 config_hash: ff35e224e809656528c44163aa41bebd From f4015ba5f056c601f67700af96b87eeec65851c2 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 20:15:58 +0000 Subject: [PATCH 057/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 9768c4b..6343a8a 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ea4f36d262d32250c0626d46b9df01e15fd17dec54928c712284693c8be487d2.yml -openapi_spec_hash: 33fe53c36120b880472d3743ba2bd898 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-190c8939f11afec54c1c0303cb21e7164a350fb66c5fe8fb5ae970e809dfb066.yml +openapi_spec_hash: 65e3c8513e047a95bcf276b6f88045a6 config_hash: ff35e224e809656528c44163aa41bebd From aed496639ab635adf0b038f138d6b94b0827089f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 00:56:38 +0000 Subject: [PATCH 058/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6343a8a..c2cc39a 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-190c8939f11afec54c1c0303cb21e7164a350fb66c5fe8fb5ae970e809dfb066.yml -openapi_spec_hash: 65e3c8513e047a95bcf276b6f88045a6 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ecb277557634e2f0838ea196e2b21f11924f65e133c7977e8c2e1a603b8df466.yml +openapi_spec_hash: 798ce4cb042389a1179bf9af6fc1173d config_hash: ff35e224e809656528c44163aa41bebd From 3e8867d62bce60ac08c453bd35cfab0091511a7a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 01:02:01 +0000 Subject: [PATCH 059/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 6d78745..091cfb1 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.9.0" + ".": "0.10.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 8791541..e942183 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.9.0" // x-release-please-version +const Version = "0.10.0" // x-release-please-version From 15bcd7871e5ddc61afdbc30fc70b087517dd9dd5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 03:45:54 +0000 Subject: [PATCH 060/154] feat(api): api update --- .stats.yml | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.stats.yml b/.stats.yml index c2cc39a..6f63fc8 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ecb277557634e2f0838ea196e2b21f11924f65e133c7977e8c2e1a603b8df466.yml -openapi_spec_hash: 798ce4cb042389a1179bf9af6fc1173d +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-de547897d4a30447212ce36430a932cf186efd91844bd8ea0757a1cde4ce40e1.yml +openapi_spec_hash: efa1b29865560c7817495b20c1b62fad config_hash: ff35e224e809656528c44163aa41bebd diff --git a/go.mod b/go.mod index f0d5d12..e43b180 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.1.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.2.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 919a559..669bf87 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.1.0 h1:Npy3In0Wda7r+TPlvjnoErIe/6s4qZ80uymsC6QCrUQ= -github.com/context-dot-dev/context-go-sdk/v2 v2.1.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.2.0 h1:4jIQ8PVy5Q27H/50je4gSrt5GwO4cpaRyy6idy2ZbCA= +github.com/context-dot-dev/context-go-sdk/v2 v2.2.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 614aece55b390c05d062c5ffd7ba748787717c2f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 10 Jul 2026 23:22:05 +0000 Subject: [PATCH 061/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6f63fc8..a9bd7b9 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-de547897d4a30447212ce36430a932cf186efd91844bd8ea0757a1cde4ce40e1.yml -openapi_spec_hash: efa1b29865560c7817495b20c1b62fad +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e3b1fd2a6aecb6cac87a0a2f4f811dedc261ae162cceced0841b5184ba609308.yml +openapi_spec_hash: 28e4c0d0599e1f7153838a465f9cf5b5 config_hash: ff35e224e809656528c44163aa41bebd From 8350e63cd11cf78f6347c63f7bb07246de3f0feb Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 11 Jul 2026 02:22:35 +0000 Subject: [PATCH 062/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index a9bd7b9..c1de7fe 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e3b1fd2a6aecb6cac87a0a2f4f811dedc261ae162cceced0841b5184ba609308.yml -openapi_spec_hash: 28e4c0d0599e1f7153838a465f9cf5b5 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d60fed3d26479d1ee76b77df8415390504542522e7188792a23bf77b9f37ed63.yml +openapi_spec_hash: 263672c59d9b01c50f7d2307fbd82ec0 config_hash: ff35e224e809656528c44163aa41bebd From 15ed998202bab7e82b8b1a54c1458ee0cbe2b1aa Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 11 Jul 2026 22:00:38 +0000 Subject: [PATCH 063/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index c1de7fe..a5e7807 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d60fed3d26479d1ee76b77df8415390504542522e7188792a23bf77b9f37ed63.yml -openapi_spec_hash: 263672c59d9b01c50f7d2307fbd82ec0 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-adab8df19dce27396e4a0e698287f083e1f932e63b85fd8dd4d54f80f0e0b5a8.yml +openapi_spec_hash: 717fea46f446ff97bad627f200963fd7 config_hash: ff35e224e809656528c44163aa41bebd diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 03a3e3e..29a5b13 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -708,7 +708,7 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Name: "web-scrape-md", - Usage: "Scrapes the given URL into LLM usable Markdown.", + Usage: "Scrapes the given URL into LLM usable Markdown. Inspect key_metadata on JSON\nresponses from a recognized API key; use error_code to distinguish stable\nfailure categories.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ From cc1d9c81ffb450fdbe979ed0df3debed5cc00f0a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 11 Jul 2026 22:21:36 +0000 Subject: [PATCH 064/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/monitor.go | 14 ++++++++++++-- pkg/cmd/monitor_test.go | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.stats.yml b/.stats.yml index a5e7807..951a04e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-adab8df19dce27396e4a0e698287f083e1f932e63b85fd8dd4d54f80f0e0b5a8.yml -openapi_spec_hash: 717fea46f446ff97bad627f200963fd7 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ecf38e27f0c2544a8965f6cee827927343a926e1ab511aa7b34e8aa7d1866c8e.yml +openapi_spec_hash: c5767791a19b95c52ef073902fa5da77 config_hash: ff35e224e809656528c44163aa41bebd diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index ffd0568..5729a84 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -80,9 +80,14 @@ var monitorsCreate = requestflag.WithInnerFlags(cli.Command{ "webhook": { &requestflag.InnerFlag[string]{ Name: "webhook.url", - Usage: "Webhook URL called when a change is detected.", + Usage: "Webhook URL events are delivered to.", InnerField: "url", }, + &requestflag.InnerFlag[[]string]{ + Name: "webhook.events", + Usage: "Events delivered to this endpoint. `change.detected` fires only when a run detects a change; `run.completed` fires on every completed run — including runs that detected no change — and embeds the change when one was detected. Defaults to `[\"change.detected\"]` when omitted.", + InnerField: "events", + }, &requestflag.InnerFlag[string]{ Name: "webhook.secret", Usage: "Signing secret used to verify webhook authenticity. Each delivery includes an `X-Context-Signature: t=,v1=` header, where the HMAC is SHA-256 over `\"{t}.{rawRequestBody}\"` keyed by this secret. Recompute it with a constant-time compare and reject stale timestamps to prevent replay. Generated by the API; cannot be set by clients.", @@ -174,9 +179,14 @@ var monitorsUpdate = requestflag.WithInnerFlags(cli.Command{ "webhook": { &requestflag.InnerFlag[string]{ Name: "webhook.url", - Usage: "Webhook URL called when a change is detected.", + Usage: "Webhook URL events are delivered to.", InnerField: "url", }, + &requestflag.InnerFlag[[]string]{ + Name: "webhook.events", + Usage: "Events delivered to this endpoint. `change.detected` fires only when a run detects a change; `run.completed` fires on every completed run — including runs that detected no change — and embeds the change when one was detected. Defaults to `[\"change.detected\"]` when omitted.", + InnerField: "events", + }, &requestflag.InnerFlag[string]{ Name: "webhook.secret", Usage: "Signing secret used to verify webhook authenticity. Each delivery includes an `X-Context-Signature: t=,v1=` header, where the HMAC is SHA-256 over `\"{t}.{rawRequestBody}\"` keyed by this secret. Recompute it with a constant-time compare and reject stale timestamps to prevent replay. Generated by the API; cannot be set by clients.", diff --git a/pkg/cmd/monitor_test.go b/pkg/cmd/monitor_test.go index 5745c6a..a307b8c 100644 --- a/pkg/cmd/monitor_test.go +++ b/pkg/cmd/monitor_test.go @@ -23,7 +23,7 @@ func TestMonitorsCreate(t *testing.T) { "--mode", "web", "--tag", "pricing", "--tag", "competitor", - "--webhook", "{url: https://example.com/webhook}", + "--webhook", "{url: https://example.com/webhook, events: [change.detected, run.completed]}", ) }) @@ -46,6 +46,7 @@ func TestMonitorsCreate(t *testing.T) { "--tag", "pricing", "--tag", "competitor", "--webhook.url", "https://example.com/webhook", + "--webhook.events", "[change.detected, run.completed]", ) }) @@ -68,7 +69,10 @@ func TestMonitorsCreate(t *testing.T) { " - pricing\n" + " - competitor\n" + "webhook:\n" + - " url: https://example.com/webhook\n") + " url: https://example.com/webhook\n" + + " events:\n" + + " - change.detected\n" + + " - run.completed\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, "--api-key", "string", @@ -104,7 +108,7 @@ func TestMonitorsUpdate(t *testing.T) { "--tag", "pricing", "--tag", "competitor", "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", - "--webhook", "{url: https://example.com/webhook}", + "--webhook", "{url: https://example.com/webhook, events: [change.detected, run.completed]}", ) }) @@ -128,6 +132,7 @@ func TestMonitorsUpdate(t *testing.T) { "--tag", "competitor", "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", "--webhook.url", "https://example.com/webhook", + "--webhook.events", "[change.detected, run.completed]", ) }) @@ -150,7 +155,10 @@ func TestMonitorsUpdate(t *testing.T) { " url: https://acme.com/pricing\n" + " normalize_whitespace: true\n" + "webhook:\n" + - " url: https://example.com/webhook\n") + " url: https://example.com/webhook\n" + + " events:\n" + + " - change.detected\n" + + " - run.completed\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, "--api-key", "string", From 6cbc16f778f93f2ad009465f6952e331e71f4467 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 11 Jul 2026 23:27:31 +0000 Subject: [PATCH 065/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 951a04e..26e1f0f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ecf38e27f0c2544a8965f6cee827927343a926e1ab511aa7b34e8aa7d1866c8e.yml -openapi_spec_hash: c5767791a19b95c52ef073902fa5da77 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-21b399a0388f04e48b9d8d95f51f622088c5b15b1e17d2988c38583902b9f685.yml +openapi_spec_hash: 6952c95545d272388a655652fc8e7662 config_hash: ff35e224e809656528c44163aa41bebd From d07dc67657a4d0149e6ce3b6a03f12133bb17fce Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 06:05:21 +0000 Subject: [PATCH 066/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 27 +++++++++++++++++++++------ pkg/cmd/web_test.go | 10 +++++++--- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.stats.yml b/.stats.yml index 26e1f0f..f0f1a28 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-21b399a0388f04e48b9d8d95f51f622088c5b15b1e17d2988c38583902b9f685.yml -openapi_spec_hash: 6952c95545d272388a655652fc8e7662 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-48b7ece3103b7778fbb3fc822ac3e28f8758a220f16a9a74383a0e15f2a381e2.yml +openapi_spec_hash: b1dcb462be67fc1ad751463f01d21d21 config_hash: ff35e224e809656528c44163aa41bebd diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 29a5b13..4d16c84 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -475,8 +475,8 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[map[string]any]{ Name: "pdf", - Usage: "PDF parsing controls. Use start/end to limit text extraction and OCR to an inclusive 1-based page range.", - Default: map[string]any{"shouldParse": true}, + Usage: "PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range.", + Default: map[string]any{"shouldParse": true, "ocr": false}, BodyPath: "pdf", }, &requestflag.Flag[bool]{ @@ -528,6 +528,11 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", InnerField: "end", }, + &requestflag.InnerFlag[bool]{ + Name: "pdf.ocr", + Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback.", + InnerField: "ocr", + }, &requestflag.InnerFlag[bool]{ Name: "pdf.should-parse", Usage: "When true, PDF pages are fetched and parsed. When false, PDF pages are skipped entirely (not included in results and not counted as failures).", @@ -586,8 +591,8 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[map[string]any]{ Name: "pdf", - Usage: "PDF parsing controls. Use start/end to limit text extraction and OCR to an inclusive 1-based page range.", - Default: map[string]any{"shouldParse": true}, + Usage: "PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range.", + Default: map[string]any{"shouldParse": true, "ocr": false}, QueryPath: "pdf", }, &requestflag.Flag[bool]{ @@ -622,6 +627,11 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", InnerField: "end", }, + &requestflag.InnerFlag[bool]{ + Name: "pdf.ocr", + Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback.", + InnerField: "ocr", + }, &requestflag.InnerFlag[bool]{ Name: "pdf.should-parse", Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned.", @@ -763,8 +773,8 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[map[string]any]{ Name: "pdf", - Usage: "PDF parsing controls. Use start/end to limit text extraction and OCR to an inclusive 1-based page range.", - Default: map[string]any{"shouldParse": true}, + Usage: "PDF parsing controls. Use start/end to limit text extraction and embedded-image detection/OCR to an inclusive 1-based page range.", + Default: map[string]any{"shouldParse": true, "ocr": false}, QueryPath: "pdf", }, &requestflag.Flag[bool]{ @@ -805,6 +815,11 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", InnerField: "end", }, + &requestflag.InnerFlag[bool]{ + Name: "pdf.ocr", + Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback.", + InnerField: "ocr", + }, &requestflag.InnerFlag[bool]{ Name: "pdf.should-parse", Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 7280e80..ab8545d 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -285,7 +285,7 @@ func TestWebWebCrawlMd(t *testing.T) { "--max-age-ms", "0", "--max-depth", "0", "--max-pages", "1", - "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", "--settle-animations=true", "--shorten-base64-images=true", "--stop-after-ms", "10000", @@ -317,6 +317,7 @@ func TestWebWebCrawlMd(t *testing.T) { "--max-depth", "0", "--max-pages", "1", "--pdf.end", "1", + "--pdf.ocr=true", "--pdf.should-parse=true", "--pdf.start", "1", "--settle-animations=true", @@ -347,6 +348,7 @@ func TestWebWebCrawlMd(t *testing.T) { "maxPages: 1\n" + "pdf:\n" + " end: 1\n" + + " ocr: true\n" + " shouldParse: true\n" + " start: 1\n" + "settleAnimations: true\n" + @@ -378,7 +380,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--include-frames=true", "--include-selector", "string", "--max-age-ms", "0", - "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", "--settle-animations=true", "--timeout-ms", "1000", "--use-main-content-only=true", @@ -403,6 +405,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--include-selector", "string", "--max-age-ms", "0", "--pdf.end", "1", + "--pdf.ocr=true", "--pdf.should-parse=true", "--pdf.start", "1", "--settle-animations=true", @@ -469,7 +472,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--include-links=true", "--include-selector", "string", "--max-age-ms", "0", - "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", "--settle-animations=true", "--shorten-base64-images=true", "--timeout-ms", "1000", @@ -497,6 +500,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--include-selector", "string", "--max-age-ms", "0", "--pdf.end", "1", + "--pdf.ocr=true", "--pdf.should-parse=true", "--pdf.start", "1", "--settle-animations=true", From 2ccbe3a4c620bc1dd520edfa35164efa8058a0ea Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 06:53:01 +0000 Subject: [PATCH 067/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index f0f1a28..66d8d6b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-48b7ece3103b7778fbb3fc822ac3e28f8758a220f16a9a74383a0e15f2a381e2.yml -openapi_spec_hash: b1dcb462be67fc1ad751463f01d21d21 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2b4fb3b310c35a1036b88e33c7252f42716d05ef19ea4d462426e0a28e0294a3.yml +openapi_spec_hash: cda6b6aaf724e39575e1848f3ea6eb10 config_hash: ff35e224e809656528c44163aa41bebd From d7f27d6bbda5fd361ff11cc8c6501c16f484192e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 07:51:44 +0000 Subject: [PATCH 068/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 66d8d6b..3d6d2e8 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2b4fb3b310c35a1036b88e33c7252f42716d05ef19ea4d462426e0a28e0294a3.yml -openapi_spec_hash: cda6b6aaf724e39575e1848f3ea6eb10 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-27dde3a14459d2e2ade277b142906f33c1b9e04c05b91ae9eb10b798eb82eb0b.yml +openapi_spec_hash: bf7879be38ebf3397a939c80b261a47a config_hash: ff35e224e809656528c44163aa41bebd From 06b488a0232e91ef830af33bae8606c5854cbe5c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 07:57:06 +0000 Subject: [PATCH 069/154] feat(api): manual updates --- .stats.yml | 6 +- pkg/cmd/cmd.go | 8 +++ pkg/cmd/parse.go | 143 ++++++++++++++++++++++++++++++++++++++++++ pkg/cmd/parse_test.go | 51 +++++++++++++++ 4 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 pkg/cmd/parse.go create mode 100644 pkg/cmd/parse_test.go diff --git a/.stats.yml b/.stats.yml index 3d6d2e8..1ba5348 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-27dde3a14459d2e2ade277b142906f33c1b9e04c05b91ae9eb10b798eb82eb0b.yml +configured_endpoints: 30 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c90f13e3cf4b9ae6a1d8f22c0e7285ab12d412d3a659a51a247a97adc7f08121.yml openapi_spec_hash: bf7879be38ebf3397a939c80b261a47a -config_hash: ff35e224e809656528c44163aa41bebd +config_hash: daabb160675d86b354711da1e77e5129 diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 85854aa..841a1e6 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -84,6 +84,14 @@ func init() { }, }, Commands: []*cli.Command{ + { + Name: "parse", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &parseHandle, + }, + }, { Name: "web", Category: "API RESOURCE", diff --git a/pkg/cmd/parse.go b/pkg/cmd/parse.go new file mode 100644 index 0000000..c34be84 --- /dev/null +++ b/pkg/cmd/parse.go @@ -0,0 +1,143 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + "os" + + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/binaryparam" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var parseHandle = cli.Command{ + Name: "handle", + Usage: "Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes\ninto LLM-usable Markdown.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "body", + Required: true, + BodyRoot: true, + FileInput: true, + }, + &requestflag.Flag[string]{ + Name: "base-url", + Usage: "Optional HTTP(S) source document URL used to resolve relative links and image references. Relative references remain relative when omitted.", + QueryPath: "baseUrl", + }, + &requestflag.Flag[string]{ + Name: "extension", + Usage: "Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, md, py, rtf, jpg, png, or txt.", + QueryPath: "extension", + }, + &requestflag.Flag[string]{ + Name: "filename", + Usage: "Optional filename hint used to infer the extension when extension is omitted.", + QueryPath: "filename", + }, + &requestflag.Flag[bool]{ + Name: "include-images", + Usage: "Include image references in Markdown output", + Default: false, + QueryPath: "includeImages", + }, + &requestflag.Flag[bool]{ + Name: "include-links", + Usage: "Preserve hyperlinks in Markdown output", + Default: true, + QueryPath: "includeLinks", + }, + &requestflag.Flag[bool]{ + Name: "ocr", + Usage: "When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range. This is separate from automatic scanned-PDF OCR fallback.", + Default: false, + QueryPath: "ocr", + }, + &requestflag.Flag[int64]{ + Name: "pdf-end", + Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to pdfStart when both are provided.", + QueryPath: "pdfEnd", + }, + &requestflag.Flag[int64]{ + Name: "pdf-start", + Usage: "First 1-based PDF page to parse. When omitted, parsing starts at the first page.", + QueryPath: "pdfStart", + }, + &requestflag.Flag[bool]{ + Name: "shorten-base64-images", + Usage: "Shorten base64-encoded image data in the Markdown output", + Default: true, + QueryPath: "shortenBase64Images", + }, + &requestflag.Flag[bool]{ + Name: "use-main-content-only", + Usage: "Extract only the main content from HTML-like inputs", + Default: false, + QueryPath: "useMainContentOnly", + }, + }, + Action: handleParseHandle, + HideHelpCommand: true, +} + +func handleParseHandle(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("body") && len(unusedArgs) > 0 { + cmd.Set("body", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + bodyReader, stdinInUse, err := binaryparam.FileOrStdin(os.Stdin, cmd.Value("body").(string)) + if err != nil { + return fmt.Errorf("Failed on param '%s': %w", "body", err) + } + defer bodyReader.Close() + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationOctetStream, + stdinInUse, + ) + if err != nil { + return err + } + + params := contextdev.ParseHandleParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Parse.Handle( + ctx, + bodyReader, + params, + options..., + ) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "parse handle", + Transform: transform, + }) +} diff --git a/pkg/cmd/parse_test.go b/pkg/cmd/parse_test.go new file mode 100644 index 0000000..0612807 --- /dev/null +++ b/pkg/cmd/parse_test.go @@ -0,0 +1,51 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" +) + +func TestParseHandle(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "parse", "handle", + "--body", mocktest.TestFile(t, "Example data"), + "--base-url", "https://example.com", + "--extension", "extension", + "--filename", "filename", + "--include-images=true", + "--include-links=true", + "--ocr=true", + "--pdf-end", "1", + "--pdf-start", "1", + "--shorten-base64-images=true", + "--use-main-content-only=true", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("Example data") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "parse", "handle", + "--base-url", "https://example.com", + "--extension", "extension", + "--filename", "filename", + "--include-images=true", + "--include-links=true", + "--ocr=true", + "--pdf-end", "1", + "--pdf-start", "1", + "--shorten-base64-images=true", + "--use-main-content-only=true", + ) + }) +} From 403d45e13367705871a79d2b2ef38c67d0c4c390 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 07:59:31 +0000 Subject: [PATCH 070/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 091cfb1..f7014c3 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.10.0" + ".": "0.11.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index e942183..c3995df 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.10.0" // x-release-please-version +const Version = "0.11.0" // x-release-please-version From 27232a474114414c6de5b84576c5edbdb421b7ae Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 19:47:43 +0000 Subject: [PATCH 071/154] feat(api): api update --- .stats.yml | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- pkg/cmd/parse.go | 47 +++++++++++++++++++++---------------------- pkg/cmd/parse_test.go | 36 ++++++++++++++++++++++++--------- 5 files changed, 54 insertions(+), 39 deletions(-) diff --git a/.stats.yml b/.stats.yml index 1ba5348..7cfdbba 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c90f13e3cf4b9ae6a1d8f22c0e7285ab12d412d3a659a51a247a97adc7f08121.yml -openapi_spec_hash: bf7879be38ebf3397a939c80b261a47a +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-fb56935a194e69348fecd985f7cf8b249795b46af2fb32f6c5c8ef648cf10c15.yml +openapi_spec_hash: 7260a560474283b7ad6ac5d426058ac9 config_hash: daabb160675d86b354711da1e77e5129 diff --git a/go.mod b/go.mod index e43b180..a6da4f9 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.2.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.3.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 669bf87..42e69ea 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.2.0 h1:4jIQ8PVy5Q27H/50je4gSrt5GwO4cpaRyy6idy2ZbCA= -github.com/context-dot-dev/context-go-sdk/v2 v2.2.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.3.0 h1:5EJ87AXgixxMYsmwd5mlz/4NeW3qDmdPsKCDOAg58Ik= +github.com/context-dot-dev/context-go-sdk/v2 v2.3.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/pkg/cmd/parse.go b/pkg/cmd/parse.go index c34be84..9cc7a65 100644 --- a/pkg/cmd/parse.go +++ b/pkg/cmd/parse.go @@ -16,9 +16,9 @@ import ( "github.com/urfave/cli/v3" ) -var parseHandle = cli.Command{ +var parseHandle = requestflag.WithInnerFlags(cli.Command{ Name: "handle", - Usage: "Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes\ninto LLM-usable Markdown.", + Usage: "Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes\ninto LLM-usable Markdown. The base request costs 1 credit. When OCR runs\n(requires ocr=true), the entire call costs 5 credits; ocr=true requests where no\nOCR ends up running still cost 1 credit.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ @@ -27,21 +27,11 @@ var parseHandle = cli.Command{ BodyRoot: true, FileInput: true, }, - &requestflag.Flag[string]{ - Name: "base-url", - Usage: "Optional HTTP(S) source document URL used to resolve relative links and image references. Relative references remain relative when omitted.", - QueryPath: "baseUrl", - }, &requestflag.Flag[string]{ Name: "extension", - Usage: "Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, md, py, rtf, jpg, png, or txt.", + Usage: `Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. ".pdf").`, QueryPath: "extension", }, - &requestflag.Flag[string]{ - Name: "filename", - Usage: "Optional filename hint used to infer the extension when extension is omitted.", - QueryPath: "filename", - }, &requestflag.Flag[bool]{ Name: "include-images", Usage: "Include image references in Markdown output", @@ -56,19 +46,15 @@ var parseHandle = cli.Command{ }, &requestflag.Flag[bool]{ Name: "ocr", - Usage: "When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdfStart/pdfEnd limit the inclusive page range. This is separate from automatic scanned-PDF OCR fallback.", + Usage: "Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted at each image's position in page reading order, preserving the text layer; pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get full-document OCR, and raster images get their visible text transcribed. When false, no OCR runs: scanned PDFs may yield no content and images return only format/dimension metadata. Calls where OCR actually runs cost 5 credits instead of 1.", Default: false, QueryPath: "ocr", }, - &requestflag.Flag[int64]{ - Name: "pdf-end", - Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to pdfStart when both are provided.", - QueryPath: "pdfEnd", - }, - &requestflag.Flag[int64]{ - Name: "pdf-start", - Usage: "First 1-based PDF page to parse. When omitted, parsing starts at the first page.", - QueryPath: "pdfStart", + &requestflag.Flag[map[string]any]{ + Name: "pdf", + Usage: "PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) to an inclusive 1-based page range.", + Default: map[string]any{}, + QueryPath: "pdf", }, &requestflag.Flag[bool]{ Name: "shorten-base64-images", @@ -85,7 +71,20 @@ var parseHandle = cli.Command{ }, Action: handleParseHandle, HideHelpCommand: true, -} +}, map[string][]requestflag.HasOuterFlag{ + "pdf": { + &requestflag.InnerFlag[int64]{ + Name: "pdf.end", + Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", + InnerField: "end", + }, + &requestflag.InnerFlag[int64]{ + Name: "pdf.start", + Usage: "First 1-based PDF page to parse. When omitted, parsing starts at the first page.", + InnerField: "start", + }, + }, +}) func handleParseHandle(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) diff --git a/pkg/cmd/parse_test.go b/pkg/cmd/parse_test.go index 0612807..11b4e77 100644 --- a/pkg/cmd/parse_test.go +++ b/pkg/cmd/parse_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/context-dot-dev/context-dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" ) func TestParseHandle(t *testing.T) { @@ -16,14 +17,32 @@ func TestParseHandle(t *testing.T) { "--api-key", "string", "parse", "handle", "--body", mocktest.TestFile(t, "Example data"), - "--base-url", "https://example.com", - "--extension", "extension", - "--filename", "filename", + "--extension", "txt", "--include-images=true", "--include-links=true", "--ocr=true", - "--pdf-end", "1", - "--pdf-start", "1", + "--pdf", "{end: 1, start: 1}", + "--shorten-base64-images=true", + "--use-main-content-only=true", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(parseHandle) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "parse", "handle", + "--body", mocktest.TestFile(t, "Example data"), + "--extension", "txt", + "--include-images=true", + "--include-links=true", + "--ocr=true", + "--pdf.end", "1", + "--pdf.start", "1", "--shorten-base64-images=true", "--use-main-content-only=true", ) @@ -36,14 +55,11 @@ func TestParseHandle(t *testing.T) { t, pipeData, "--api-key", "string", "parse", "handle", - "--base-url", "https://example.com", - "--extension", "extension", - "--filename", "filename", + "--extension", "txt", "--include-images=true", "--include-links=true", "--ocr=true", - "--pdf-end", "1", - "--pdf-start", "1", + "--pdf", "{end: 1, start: 1}", "--shorten-base64-images=true", "--use-main-content-only=true", ) From 9bf956eaa43bfbfdd80d257c832eae8d64016fd4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 19:57:36 +0000 Subject: [PATCH 072/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index f7014c3..fea3454 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.11.0" + ".": "1.0.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index c3995df..d47a190 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "0.11.0" // x-release-please-version +const Version = "1.0.0" // x-release-please-version From 63fd095d53286c402f12dc322127b32d3d73b049 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 12 Jul 2026 23:37:38 +0000 Subject: [PATCH 073/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a6da4f9..a000854 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.3.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.4.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 42e69ea..e9ff7cd 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.3.0 h1:5EJ87AXgixxMYsmwd5mlz/4NeW3qDmdPsKCDOAg58Ik= -github.com/context-dot-dev/context-go-sdk/v2 v2.3.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.4.0 h1:mehuyGuUzgflR7rQpSlPaH7lNj2A8hdtf1+WG4U4h1I= +github.com/context-dot-dev/context-go-sdk/v2 v2.4.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 15f114c606dd3fc29a5f63cc17d221051af1ed5d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 13 Jul 2026 01:22:31 +0000 Subject: [PATCH 074/154] feat(api): api update --- .stats.yml | 4 +-- pkg/cmd/ai.go | 10 ++++++++ pkg/cmd/ai_test.go | 10 ++++++++ pkg/cmd/brand.go | 10 ++++++++ pkg/cmd/brand_test.go | 7 +++++ pkg/cmd/industry.go | 10 ++++++++ pkg/cmd/industry_test.go | 4 +++ pkg/cmd/parse.go | 5 ++++ pkg/cmd/parse_test.go | 6 +++++ pkg/cmd/utility.go | 5 ++++ pkg/cmd/utility_test.go | 5 ++++ pkg/cmd/web.go | 55 ++++++++++++++++++++++++++++++++++++++++ pkg/cmd/web_test.go | 45 ++++++++++++++++++++++++++++++++ 13 files changed, 174 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 7cfdbba..8e4b560 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-fb56935a194e69348fecd985f7cf8b249795b46af2fb32f6c5c8ef648cf10c15.yml -openapi_spec_hash: 7260a560474283b7ad6ac5d426058ac9 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-98c2abed2e726f7e5006cd4ef2ce9a56e84470d1fead500f7f3d46ed47f5af8b.yml +openapi_spec_hash: 921fc4db282f59e416e3c95d14d534f2 config_hash: daabb160675d86b354711da1e77e5129 diff --git a/pkg/cmd/ai.go b/pkg/cmd/ai.go index 138afcf..dff2922 100644 --- a/pkg/cmd/ai.go +++ b/pkg/cmd/ai.go @@ -31,6 +31,11 @@ var aiExtractProduct = cli.Command{ Default: 604800000, BodyPath: "maxAgeMs", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + BodyPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -62,6 +67,11 @@ var aiExtractProducts = cli.Command{ Usage: "Maximum number of products to extract.", BodyPath: "maxProducts", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + BodyPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", diff --git a/pkg/cmd/ai_test.go b/pkg/cmd/ai_test.go index d690bef..e6ed136 100644 --- a/pkg/cmd/ai_test.go +++ b/pkg/cmd/ai_test.go @@ -17,6 +17,8 @@ func TestAIExtractProduct(t *testing.T) { "ai", "extract-product", "--url", "https://example.com", "--max-age-ms", "0", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -26,6 +28,9 @@ func TestAIExtractProduct(t *testing.T) { pipeData := []byte("" + "url: https://example.com\n" + "maxAgeMs: 0\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + "timeoutMS: 1000\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, @@ -45,6 +50,8 @@ func TestAIExtractProducts(t *testing.T) { "--domain", "domain", "--max-age-ms", "0", "--max-products", "1", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -55,6 +62,9 @@ func TestAIExtractProducts(t *testing.T) { "domain: domain\n" + "maxAgeMs: 0\n" + "maxProducts: 1\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + "timeoutMS: 1000\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index ea4e594..19f8630 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -45,6 +45,11 @@ var brandRetrieve = cli.Command{ Usage: "Optional parameter to optimize the API call for maximum speed. When set to true, the API will skip time-consuming operations for faster response at the cost of less comprehensive data.", BodyPath: "maxSpeed", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + BodyPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -127,6 +132,11 @@ var brandRetrieveSimplified = cli.Command{ Default: 7776000000, QueryPath: "maxAgeMs", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", diff --git a/pkg/cmd/brand_test.go b/pkg/cmd/brand_test.go index e3a79c7..c740970 100644 --- a/pkg/cmd/brand_test.go +++ b/pkg/cmd/brand_test.go @@ -20,6 +20,8 @@ func TestBrandRetrieve(t *testing.T) { "--force-language", "afrikaans", "--max-age-ms", "0", "--max-speed=true", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -32,6 +34,9 @@ func TestBrandRetrieve(t *testing.T) { "force_language: afrikaans\n" + "maxAgeMs: 0\n" + "maxSpeed: true\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + "timeoutMS: 1000\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, @@ -50,6 +55,8 @@ func TestBrandRetrieveSimplified(t *testing.T) { "brand", "retrieve-simplified", "--domain", "domain", "--max-age-ms", "86400000", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) diff --git a/pkg/cmd/industry.go b/pkg/cmd/industry.go index ed317cf..4fd74f4 100644 --- a/pkg/cmd/industry.go +++ b/pkg/cmd/industry.go @@ -37,6 +37,11 @@ var industryRetrieveNaics = cli.Command{ Default: 1, QueryPath: "minResults", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -70,6 +75,11 @@ var industryRetrieveSic = cli.Command{ Default: 1, QueryPath: "minResults", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", diff --git a/pkg/cmd/industry_test.go b/pkg/cmd/industry_test.go index d74383e..e3e8243 100644 --- a/pkg/cmd/industry_test.go +++ b/pkg/cmd/industry_test.go @@ -18,6 +18,8 @@ func TestIndustryRetrieveNaics(t *testing.T) { "--input", "input", "--max-results", "1", "--min-results", "1", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -33,6 +35,8 @@ func TestIndustryRetrieveSic(t *testing.T) { "--input", "input", "--max-results", "1", "--min-results", "1", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--type", "original_sic", ) diff --git a/pkg/cmd/parse.go b/pkg/cmd/parse.go index 9cc7a65..7901f61 100644 --- a/pkg/cmd/parse.go +++ b/pkg/cmd/parse.go @@ -62,6 +62,11 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ Default: true, QueryPath: "shortenBase64Images", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[bool]{ Name: "use-main-content-only", Usage: "Extract only the main content from HTML-like inputs", diff --git a/pkg/cmd/parse_test.go b/pkg/cmd/parse_test.go index 11b4e77..cf28a63 100644 --- a/pkg/cmd/parse_test.go +++ b/pkg/cmd/parse_test.go @@ -23,6 +23,8 @@ func TestParseHandle(t *testing.T) { "--ocr=true", "--pdf", "{end: 1, start: 1}", "--shorten-base64-images=true", + "--tag", "production", + "--tag", "team-alpha", "--use-main-content-only=true", ) }) @@ -44,6 +46,8 @@ func TestParseHandle(t *testing.T) { "--pdf.end", "1", "--pdf.start", "1", "--shorten-base64-images=true", + "--tag", "production", + "--tag", "team-alpha", "--use-main-content-only=true", ) }) @@ -61,6 +65,8 @@ func TestParseHandle(t *testing.T) { "--ocr=true", "--pdf", "{end: 1, start: 1}", "--shorten-base64-images=true", + "--tag", "production", + "--tag", "team-alpha", "--use-main-content-only=true", ) }) diff --git a/pkg/cmd/utility.go b/pkg/cmd/utility.go index ac0a997..8ef1876 100644 --- a/pkg/cmd/utility.go +++ b/pkg/cmd/utility.go @@ -31,6 +31,11 @@ var utilityPrefetch = cli.Command{ Required: true, BodyPath: "type", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + BodyPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", diff --git a/pkg/cmd/utility_test.go b/pkg/cmd/utility_test.go index f9d5b35..336384d 100644 --- a/pkg/cmd/utility_test.go +++ b/pkg/cmd/utility_test.go @@ -17,6 +17,8 @@ func TestUtilityPrefetch(t *testing.T) { "utility", "prefetch", "--identifier", "{domain: domain}", "--type", "brand", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -27,6 +29,9 @@ func TestUtilityPrefetch(t *testing.T) { "identifier:\n" + " domain: domain\n" + "type: brand\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + "timeoutMS: 1000\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 4d16c84..268097c 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -82,6 +82,11 @@ var webExtract = requestflag.WithInnerFlags(cli.Command{ Default: 80000, BodyPath: "stopAfterMs", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + BodyPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -132,6 +137,11 @@ var webExtractCompetitors = cli.Command{ Default: 5, QueryPath: "numCompetitors", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -163,6 +173,11 @@ var webExtractFonts = cli.Command{ Default: 7776000000, QueryPath: "maxAgeMs", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -199,6 +214,11 @@ var webExtractStyleguide = cli.Command{ Default: 7776000000, QueryPath: "maxAgeMs", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -261,6 +281,11 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional vertical scroll offset in pixels for capturing a long page in viewport-sized chunks. When provided, the full page is captured once and the returned image is the viewport-sized slice that begins at this Y offset (e.g. request scrollOffset=0, then 1080, then 2160 to walk a 1920x1080 landing page top to bottom). The final slice may be shorter than the viewport height. Takes precedence over fullScreenshot. Max: 100000.", QueryPath: "scrollOffset", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -343,6 +368,11 @@ var webSearch = requestflag.WithInnerFlags(cli.Command{ Usage: "Expand the query into multiple parallel variants for broader recall.", BodyPath: "queryFanout", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + BodyPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -497,6 +527,11 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ Default: 80000, BodyPath: "stopAfterMs", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + BodyPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -601,6 +636,11 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Default: false, QueryPath: "settleAnimations", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -678,6 +718,11 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Default: 86400000, QueryPath: "maxAgeMs", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -789,6 +834,11 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Default: true, QueryPath: "shortenBase64Images", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", @@ -855,6 +905,11 @@ var webWebScrapeSitemap = cli.Command{ Default: 10000, QueryPath: "maxLinks", }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index ab8545d..7732656 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -27,6 +27,8 @@ func TestWebExtract(t *testing.T) { "--max-pages", "1", "--pdf", "{end: 1, shouldParse: true, start: 1}", "--stop-after-ms", "10000", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--wait-for-ms", "0", ) @@ -54,6 +56,8 @@ func TestWebExtract(t *testing.T) { "--pdf.should-parse=true", "--pdf.start", "1", "--stop-after-ms", "10000", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--wait-for-ms", "0", ) @@ -80,6 +84,9 @@ func TestWebExtract(t *testing.T) { " shouldParse: true\n" + " start: 1\n" + "stopAfterMs: 10000\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + "timeoutMS: 1000\n" + "waitForMs: 0\n") mocktest.TestRunMockTestWithPipeAndFlags( @@ -99,6 +106,8 @@ func TestWebExtractCompetitors(t *testing.T) { "web", "extract-competitors", "--domain", "xxx", "--num-competitors", "1", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -114,6 +123,8 @@ func TestWebExtractFonts(t *testing.T) { "--direct-url", "https://example.com", "--domain", "domain", "--max-age-ms", "86400000", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -130,6 +141,8 @@ func TestWebExtractStyleguide(t *testing.T) { "--direct-url", "https://example.com", "--domain", "domain", "--max-age-ms", "86400000", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -151,6 +164,8 @@ func TestWebScreenshot(t *testing.T) { "--max-age-ms", "0", "--page", "login", "--scroll-offset", "0", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--viewport", "{height: 240, width: 240}", "--wait-for-ms", "0", @@ -175,6 +190,8 @@ func TestWebScreenshot(t *testing.T) { "--max-age-ms", "0", "--page", "login", "--scroll-offset", "0", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--viewport.height", "240", "--viewport.width", "240", @@ -198,6 +215,8 @@ func TestWebSearch(t *testing.T) { "--markdown-options", "{enabled: true, includeFrames: true, includeImages: true, includeLinks: true, maxAgeMs: 0, pdf: {end: 1, shouldParse: true, start: 1}, shortenBase64Images: true, timeoutMS: 1000, useMainContentOnly: true, waitForMs: 0}", "--num-results", "10", "--query-fanout=true", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -228,6 +247,8 @@ func TestWebSearch(t *testing.T) { "--markdown-options.wait-for-ms", "0", "--num-results", "10", "--query-fanout=true", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", ) }) @@ -258,6 +279,9 @@ func TestWebSearch(t *testing.T) { " waitForMs: 0\n" + "numResults: 10\n" + "queryFanout: true\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + "timeoutMS: 1000\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, @@ -289,6 +313,8 @@ func TestWebWebCrawlMd(t *testing.T) { "--settle-animations=true", "--shorten-base64-images=true", "--stop-after-ms", "10000", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--url-regex", "^https?://[^/]+/blog/", "--use-main-content-only=true", @@ -323,6 +349,8 @@ func TestWebWebCrawlMd(t *testing.T) { "--settle-animations=true", "--shorten-base64-images=true", "--stop-after-ms", "10000", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--url-regex", "^https?://[^/]+/blog/", "--use-main-content-only=true", @@ -354,6 +382,9 @@ func TestWebWebCrawlMd(t *testing.T) { "settleAnimations: true\n" + "shortenBase64Images: true\n" + "stopAfterMs: 10000\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + "timeoutMS: 1000\n" + "urlRegex: ^https?://[^/]+/blog/\n" + "useMainContentOnly: true\n" + @@ -382,6 +413,8 @@ func TestWebWebScrapeHTML(t *testing.T) { "--max-age-ms", "0", "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", "--settle-animations=true", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--use-main-content-only=true", "--wait-for-ms", "0", @@ -409,6 +442,8 @@ func TestWebWebScrapeHTML(t *testing.T) { "--pdf.should-parse=true", "--pdf.start", "1", "--settle-animations=true", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--use-main-content-only=true", "--wait-for-ms", "0", @@ -428,6 +463,8 @@ func TestWebWebScrapeImages(t *testing.T) { "--enrichment", "{classification: true, hostedUrl: true, maxTimePerMs: 1, resolution: true}", "--headers", "{foo: J!}", "--max-age-ms", "0", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--wait-for-ms", "0", ) @@ -450,6 +487,8 @@ func TestWebWebScrapeImages(t *testing.T) { "--enrichment.resolution=true", "--headers", "{foo: J!}", "--max-age-ms", "0", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--wait-for-ms", "0", ) @@ -475,6 +514,8 @@ func TestWebWebScrapeMd(t *testing.T) { "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", "--settle-animations=true", "--shorten-base64-images=true", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--use-main-content-only=true", "--wait-for-ms", "0", @@ -505,6 +546,8 @@ func TestWebWebScrapeMd(t *testing.T) { "--pdf.start", "1", "--settle-animations=true", "--shorten-base64-images=true", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--use-main-content-only=true", "--wait-for-ms", "0", @@ -522,6 +565,8 @@ func TestWebWebScrapeSitemap(t *testing.T) { "--domain", "domain", "--headers", "{foo: J!}", "--max-links", "1", + "--tag", "production", + "--tag", "team-alpha", "--timeout-ms", "1000", "--url-regex", "^https?://[^/]+/blog/", ) From fd0039fa2ce839a61b2c357934e0c2f691c532b4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 14 Jul 2026 00:10:57 +0000 Subject: [PATCH 075/154] feat(api): api update --- .stats.yml | 4 +- pkg/cmd/brand.go | 15 ++++-- pkg/cmd/brand_test.go | 9 ++-- pkg/cmd/industry_test.go | 4 +- pkg/cmd/monitor.go | 39 ++++++++------ pkg/cmd/monitor_test.go | 22 ++++---- pkg/cmd/parse.go | 23 ++++---- pkg/cmd/parse_test.go | 33 ++++++------ pkg/cmd/utility_test.go | 4 +- pkg/cmd/web.go | 105 +++++++++++++++++++----------------- pkg/cmd/web_test.go | 113 ++++++++++++++++++++------------------- 11 files changed, 200 insertions(+), 171 deletions(-) diff --git a/.stats.yml b/.stats.yml index 8e4b560..b9d1d30 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-98c2abed2e726f7e5006cd4ef2ce9a56e84470d1fead500f7f3d46ed47f5af8b.yml -openapi_spec_hash: 921fc4db282f59e416e3c95d14d534f2 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d49b84cf1125618f171698ff1ee4ff9a8d04151619cb4a56d650103869834465.yml +openapi_spec_hash: 49b7a6f59dcdff1e2bf88feb6474a562 config_hash: daabb160675d86b354711da1e77e5129 diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index 19f8630..a453f90 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -30,7 +30,7 @@ var brandRetrieve = cli.Command{ Required: true, BodyPath: "type", }, - &requestflag.Flag[string]{ + &requestflag.Flag[*string]{ Name: "force-language", Usage: `Allowed values: "afrikaans", "albanian", "amharic", "arabic", "armenian", "assamese", "aymara", "azeri", "basque", "belarusian", "bengali", "bosnian", "bulgarian", "burmese", "cantonese", "catalan", "cebuano", "chinese", "corsican", "croatian", "czech", "danish", "dutch", "english", "esperanto", "estonian", "farsi", "fijian", "finnish", "french", "galician", "georgian", "german", "greek", "guarani", "gujarati", "haitian-creole", "hausa", "hawaiian", "hebrew", "hindi", "hmong", "hungarian", "icelandic", "igbo", "indonesian", "irish", "italian", "japanese", "javanese", "kannada", "kazakh", "khmer", "kinyarwanda", "korean", "kurdish", "kyrgyz", "lao", "latin", "latvian", "lingala", "lithuanian", "luxembourgish", "macedonian", "malagasy", "malay", "malayalam", "maltese", "maori", "marathi", "mongolian", "nepali", "norwegian", "odia", "oromo", "pashto", "pidgin", "polish", "portuguese", "punjabi", "quechua", "romanian", "russian", "samoan", "scottish-gaelic", "serbian", "sesotho", "shona", "sindhi", "sinhala", "slovak", "slovene", "somali", "spanish", "sundanese", "swahili", "swedish", "tagalog", "tajik", "tamil", "tatar", "telugu", "thai", "tibetan", "tigrinya", "tongan", "tswana", "turkish", "turkmen", "ukrainian", "urdu", "uyghur", "uzbek", "vietnamese", "welsh", "wolof", "xhosa", "yiddish", "yoruba", "zulu".`, BodyPath: "force_language", @@ -100,12 +100,12 @@ var brandRetrieve = cli.Command{ Usage: "When set to true, the API performs additional verification to ensure the identified brand matches the transaction with high confidence.", BodyPath: "high_confidence_only", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[any]{ Name: "mcc", Usage: "Optional Merchant Category Code (MCC) to help identify the business category or industry.", BodyPath: "mcc", }, - &requestflag.Flag[float64]{ + &requestflag.Flag[any]{ Name: "phone", Usage: "Optional phone number from the transaction to help verify brand match.", BodyPath: "phone", @@ -126,10 +126,10 @@ var brandRetrieveSimplified = cli.Command{ Required: true, QueryPath: "domain", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "max-age-ms", Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", - Default: 7776000000, + Default: requestflag.Ptr[int64](7776000000), QueryPath: "maxAgeMs", }, &requestflag.Flag[[]string]{ @@ -137,6 +137,11 @@ var brandRetrieveSimplified = cli.Command{ Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", QueryPath: "tags", }, + &requestflag.Flag[string]{ + Name: "theme", + Usage: "Optional theme preference used when selecting brand assets.", + QueryPath: "theme", + }, &requestflag.Flag[int64]{ Name: "timeout-ms", Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", diff --git a/pkg/cmd/brand_test.go b/pkg/cmd/brand_test.go index c740970..55c691d 100644 --- a/pkg/cmd/brand_test.go +++ b/pkg/cmd/brand_test.go @@ -15,7 +15,7 @@ func TestBrandRetrieve(t *testing.T) { t, "--api-key", "string", "brand", "retrieve", - "--domain", "domain", + "--domain", "xxx", "--type", "by_domain", "--force-language", "afrikaans", "--max-age-ms", "0", @@ -29,7 +29,7 @@ func TestBrandRetrieve(t *testing.T) { t.Run("piping data", func(t *testing.T) { // Test piping YAML data over stdin pipeData := []byte("" + - "domain: domain\n" + + "domain: xxx\n" + "type: by_domain\n" + "force_language: afrikaans\n" + "maxAgeMs: 0\n" + @@ -53,10 +53,11 @@ func TestBrandRetrieveSimplified(t *testing.T) { t, "--api-key", "string", "brand", "retrieve-simplified", - "--domain", "domain", - "--max-age-ms", "86400000", + "--domain", "xxx", + "--max-age-ms", "0", "--tag", "production", "--tag", "team-alpha", + "--theme", "light", "--timeout-ms", "1000", ) }) diff --git a/pkg/cmd/industry_test.go b/pkg/cmd/industry_test.go index e3e8243..b7f6329 100644 --- a/pkg/cmd/industry_test.go +++ b/pkg/cmd/industry_test.go @@ -15,7 +15,7 @@ func TestIndustryRetrieveNaics(t *testing.T) { t, "--api-key", "string", "industry", "retrieve-naics", - "--input", "input", + "--input", "xxxx", "--max-results", "1", "--min-results", "1", "--tag", "production", @@ -32,7 +32,7 @@ func TestIndustryRetrieveSic(t *testing.T) { t, "--api-key", "string", "industry", "retrieve-sic", - "--input", "input", + "--input", "xxxx", "--max-results", "1", "--min-results", "1", "--tag", "production", diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index 5729a84..40641f1 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -202,16 +202,17 @@ var monitorsList = cli.Command{ Flags: []cli.Flag{ &requestflag.Flag[string]{ Name: "change-detection-type", - Usage: `Allowed values: "exact", "semantic".`, + Usage: "Filter by change detection type.", QueryPath: "change_detection_type", }, &requestflag.Flag[string]{ Name: "cursor", + Usage: "Opaque pagination cursor from a previous response.", QueryPath: "cursor", }, &requestflag.Flag[int64]{ Name: "limit", - Default: 25, + Usage: "Maximum number of items to return per page (1-100). Defaults to 25.", QueryPath: "limit", }, &requestflag.Flag[string]{ @@ -219,7 +220,7 @@ var monitorsList = cli.Command{ Usage: "Free-text search term, matched against the fields named in `search_by`.", QueryPath: "q", }, - &requestflag.Flag[[]string]{ + &requestflag.Flag[any]{ Name: "search-by", Usage: "Comma-separated fields to search with `q`. Defaults to all of them. Note `instructions` only exists on extract monitors.", QueryPath: "search_by", @@ -227,12 +228,11 @@ var monitorsList = cli.Command{ &requestflag.Flag[string]{ Name: "search-type", Usage: "`prefix` for as-you-type prefix matching (default), `exact` for full-token matching.", - Default: "prefix", QueryPath: "search_type", }, &requestflag.Flag[string]{ Name: "status", - Usage: "Monitor lifecycle status. `failed` means the most recent run failed (see the monitor's `last_error`); failed monitors keep running on schedule and flip back to `active` on the next successful run. Monitors are auto-`paused` after repeated consecutive failures or insufficient-credit skips; resume by PATCHing status to `active`.", + Usage: "Filter monitors by lifecycle status.", QueryPath: "status", }, &requestflag.Flag[string]{ @@ -240,14 +240,14 @@ var monitorsList = cli.Command{ Usage: "Filter to items that have this tag.", QueryPath: "tag", }, - &requestflag.Flag[[]string]{ + &requestflag.Flag[any]{ Name: "tag", Usage: "Comma-separated list of tags to filter by (matches monitors having any of them).", QueryPath: "tags", }, &requestflag.Flag[string]{ Name: "target-type", - Usage: `Allowed values: "page", "sitemap", "extract".`, + Usage: "Filter by target type.", QueryPath: "target_type", }, }, @@ -277,24 +277,27 @@ var monitorsListAccountChanges = cli.Command{ Flags: []cli.Flag{ &requestflag.Flag[string]{ Name: "change-detection-type", - Usage: `Allowed values: "exact", "semantic".`, + Usage: "Filter by change detection type.", QueryPath: "change_detection_type", }, &requestflag.Flag[string]{ Name: "cursor", + Usage: "Opaque pagination cursor from a previous response.", QueryPath: "cursor", }, &requestflag.Flag[int64]{ Name: "limit", - Default: 25, + Usage: "Maximum number of items to return per page (1-100). Defaults to 25.", QueryPath: "limit", }, &requestflag.Flag[string]{ Name: "monitor-id", + Usage: "Filter changes to a single monitor.", QueryPath: "monitor_id", }, &requestflag.Flag[any]{ Name: "since", + Usage: "Only include items at or after this ISO 8601 timestamp.", QueryPath: "since", }, &requestflag.Flag[string]{ @@ -304,11 +307,12 @@ var monitorsListAccountChanges = cli.Command{ }, &requestflag.Flag[string]{ Name: "target-type", - Usage: `Allowed values: "page", "sitemap", "extract".`, + Usage: "Filter by target type.", QueryPath: "target_type", }, &requestflag.Flag[any]{ Name: "until", + Usage: "Only include items before this ISO 8601 timestamp.", QueryPath: "until", }, }, @@ -323,16 +327,17 @@ var monitorsListAccountRuns = cli.Command{ Flags: []cli.Flag{ &requestflag.Flag[string]{ Name: "cursor", + Usage: "Opaque pagination cursor from a previous response.", QueryPath: "cursor", }, &requestflag.Flag[int64]{ Name: "limit", - Default: 25, + Usage: "Maximum number of items to return per page (1-100). Defaults to 25.", QueryPath: "limit", }, &requestflag.Flag[string]{ Name: "status", - Usage: "Lifecycle status of a run. `skipped` runs never executed — see `skip_reason` (insufficient credits, monitor paused, or superseded by a concurrent run).", + Usage: "Filter runs by lifecycle status.", QueryPath: "status", }, }, @@ -352,15 +357,17 @@ var monitorsListChanges = cli.Command{ }, &requestflag.Flag[string]{ Name: "cursor", + Usage: "Opaque pagination cursor from a previous response.", QueryPath: "cursor", }, &requestflag.Flag[int64]{ Name: "limit", - Default: 25, + Usage: "Maximum number of items to return per page (1-100). Defaults to 25.", QueryPath: "limit", }, &requestflag.Flag[any]{ Name: "since", + Usage: "Only include items at or after this ISO 8601 timestamp.", QueryPath: "since", }, &requestflag.Flag[string]{ @@ -370,6 +377,7 @@ var monitorsListChanges = cli.Command{ }, &requestflag.Flag[any]{ Name: "until", + Usage: "Only include items before this ISO 8601 timestamp.", QueryPath: "until", }, }, @@ -389,16 +397,17 @@ var monitorsListRuns = cli.Command{ }, &requestflag.Flag[string]{ Name: "cursor", + Usage: "Opaque pagination cursor from a previous response.", QueryPath: "cursor", }, &requestflag.Flag[int64]{ Name: "limit", - Default: 25, + Usage: "Maximum number of items to return per page (1-100). Defaults to 25.", QueryPath: "limit", }, &requestflag.Flag[string]{ Name: "status", - Usage: "Lifecycle status of a run. `skipped` runs never executed — see `skip_reason` (insufficient credits, monitor paused, or superseded by a concurrent run).", + Usage: "Filter runs by lifecycle status.", QueryPath: "status", }, }, diff --git a/pkg/cmd/monitor_test.go b/pkg/cmd/monitor_test.go index a307b8c..6e69e16 100644 --- a/pkg/cmd/monitor_test.go +++ b/pkg/cmd/monitor_test.go @@ -178,12 +178,12 @@ func TestMonitorsList(t *testing.T) { "--change-detection-type", "exact", "--cursor", "cursor", "--limit", "1", - "--q", "q", - "--search-by", "name", + "--q", "pricing", + "--search-by", "[name]", "--search-type", "exact", "--status", "active", - "--tag", "tag", - "--tag", "string", + "--tag", "pricing", + "--tag", "[x]", "--target-type", "page", ) }) @@ -211,11 +211,11 @@ func TestMonitorsListAccountChanges(t *testing.T) { "--change-detection-type", "exact", "--cursor", "cursor", "--limit", "1", - "--monitor-id", "monitor_id", - "--since", "'2019-12-27T18:11:19.117Z'", - "--tag", "tag", + "--monitor-id", "mon_123", + "--since", "'2026-06-01T00:00:00Z'", + "--tag", "pricing", "--target-type", "page", - "--until", "'2019-12-27T18:11:19.117Z'", + "--until", "'2026-06-28T00:00:00Z'", ) }) } @@ -244,9 +244,9 @@ func TestMonitorsListChanges(t *testing.T) { "--monitor-id", "mon_123", "--cursor", "cursor", "--limit", "1", - "--since", "'2019-12-27T18:11:19.117Z'", - "--tag", "tag", - "--until", "'2019-12-27T18:11:19.117Z'", + "--since", "'2026-06-01T00:00:00Z'", + "--tag", "pricing", + "--until", "'2026-06-28T00:00:00Z'", ) }) } diff --git a/pkg/cmd/parse.go b/pkg/cmd/parse.go index 7901f61..a4e7301 100644 --- a/pkg/cmd/parse.go +++ b/pkg/cmd/parse.go @@ -18,7 +18,7 @@ import ( var parseHandle = requestflag.WithInnerFlags(cli.Command{ Name: "handle", - Usage: "Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes\ninto LLM-usable Markdown. The base request costs 1 credit. When OCR runs\n(requires ocr=true), the entire call costs 5 credits; ocr=true requests where no\nOCR ends up running still cost 1 credit.", + Usage: "Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes\ninto LLM-usable Markdown.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ @@ -27,36 +27,41 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ BodyRoot: true, FileInput: true, }, + &requestflag.Flag[string]{ + Name: "client", + Usage: "Optional client identifier used for usage attribution.", + QueryPath: "client", + }, &requestflag.Flag[string]{ Name: "extension", - Usage: `Optional file extension hint. Case-insensitive; a leading dot is accepted (e.g. ".pdf").`, + Usage: "Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, md, py, rtf, jpg, png, or txt.", QueryPath: "extension", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "include-images", Usage: "Include image references in Markdown output", Default: false, QueryPath: "includeImages", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "include-links", Usage: "Preserve hyperlinks in Markdown output", Default: true, QueryPath: "includeLinks", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "ocr", - Usage: "Gates all OCR. When true, PDFs get embedded-image OCR (recognized text inserted at each image's position in page reading order, preserving the text layer; pdf.start/pdf.end limit the page range), scanned PDFs with no text layer get full-document OCR, and raster images get their visible text transcribed. When false, no OCR runs: scanned PDFs may yield no content and images return only format/dimension metadata. Calls where OCR actually runs cost 5 credits instead of 1.", + Usage: "When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, all OCR is disabled, including the automatic scanned-PDF fallback.", Default: false, QueryPath: "ocr", }, &requestflag.Flag[map[string]any]{ Name: "pdf", - Usage: "PDF page-range controls. Use start/end to limit parsing (and OCR when ocr=true) to an inclusive 1-based page range.", + Usage: `PDF page-range options as a JSON object, e.g. {"start": 2, "end": 5}.`, Default: map[string]any{}, QueryPath: "pdf", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "shorten-base64-images", Usage: "Shorten base64-encoded image data in the Markdown output", Default: true, @@ -67,7 +72,7 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", QueryPath: "tags", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "use-main-content-only", Usage: "Extract only the main content from HTML-like inputs", Default: false, diff --git a/pkg/cmd/parse_test.go b/pkg/cmd/parse_test.go index cf28a63..5f09301 100644 --- a/pkg/cmd/parse_test.go +++ b/pkg/cmd/parse_test.go @@ -17,15 +17,16 @@ func TestParseHandle(t *testing.T) { "--api-key", "string", "parse", "handle", "--body", mocktest.TestFile(t, "Example data"), + "--client", "x", "--extension", "txt", - "--include-images=true", - "--include-links=true", - "--ocr=true", + "--include-images", "'true'", + "--include-links", "'true'", + "--ocr", "'true'", "--pdf", "{end: 1, start: 1}", - "--shorten-base64-images=true", + "--shorten-base64-images", "'true'", "--tag", "production", "--tag", "team-alpha", - "--use-main-content-only=true", + "--use-main-content-only", "'true'", ) }) @@ -39,16 +40,17 @@ func TestParseHandle(t *testing.T) { "--api-key", "string", "parse", "handle", "--body", mocktest.TestFile(t, "Example data"), + "--client", "x", "--extension", "txt", - "--include-images=true", - "--include-links=true", - "--ocr=true", + "--include-images", "'true'", + "--include-links", "'true'", + "--ocr", "'true'", "--pdf.end", "1", "--pdf.start", "1", - "--shorten-base64-images=true", + "--shorten-base64-images", "'true'", "--tag", "production", "--tag", "team-alpha", - "--use-main-content-only=true", + "--use-main-content-only", "'true'", ) }) @@ -59,15 +61,16 @@ func TestParseHandle(t *testing.T) { t, pipeData, "--api-key", "string", "parse", "handle", + "--client", "x", "--extension", "txt", - "--include-images=true", - "--include-links=true", - "--ocr=true", + "--include-images", "'true'", + "--include-links", "'true'", + "--ocr", "'true'", "--pdf", "{end: 1, start: 1}", - "--shorten-base64-images=true", + "--shorten-base64-images", "'true'", "--tag", "production", "--tag", "team-alpha", - "--use-main-content-only=true", + "--use-main-content-only", "'true'", ) }) } diff --git a/pkg/cmd/utility_test.go b/pkg/cmd/utility_test.go index 336384d..8f43739 100644 --- a/pkg/cmd/utility_test.go +++ b/pkg/cmd/utility_test.go @@ -15,7 +15,7 @@ func TestUtilityPrefetch(t *testing.T) { t, "--api-key", "string", "utility", "prefetch", - "--identifier", "{domain: domain}", + "--identifier", "{domain: xxx}", "--type", "brand", "--tag", "production", "--tag", "team-alpha", @@ -27,7 +27,7 @@ func TestUtilityPrefetch(t *testing.T) { // Test piping YAML data over stdin pipeData := []byte("" + "identifier:\n" + - " domain: domain\n" + + " domain: xxx\n" + "type: brand\n" + "tags:\n" + " - production\n" + diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 268097c..9ddb7c8 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -167,10 +167,10 @@ var webExtractFonts = cli.Command{ Usage: "Domain name to extract fonts from (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both.", QueryPath: "domain", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "max-age-ms", - Usage: "Maximum age in milliseconds for cached data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", - Default: 7776000000, + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: requestflag.Ptr[int64](7776000000), QueryPath: "maxAgeMs", }, &requestflag.Flag[[]string]{ @@ -208,10 +208,10 @@ var webExtractStyleguide = cli.Command{ Usage: "Domain name to extract styleguide from (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both.", QueryPath: "domain", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "max-age-ms", - Usage: "Maximum age in milliseconds for cached data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", - Default: 7776000000, + Usage: "Maximum age in milliseconds for cached brand data before the API performs a hard refresh. Defaults to 3 months (7776000000 ms). Values below 1 day (86400000 ms) are clamped to 1 day; values above 1 year (31536000000 ms) are clamped to 1 year.", + Default: requestflag.Ptr[int64](7776000000), QueryPath: "maxAgeMs", }, &requestflag.Flag[[]string]{ @@ -241,7 +241,7 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[string]{ Name: "country", - Usage: "Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country.", + Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", QueryPath: "country", }, &requestflag.Flag[string]{ @@ -259,16 +259,16 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view).", QueryPath: "fullScreenshot", }, - &requestflag.Flag[string]{ + &requestflag.Flag[any]{ Name: "handle-cookie-popup", Usage: "Optional parameter to control cookie/consent popup handling. If 'true', we dismiss cookie banner before capture. If 'false' or not provided, captures the page without that step.", - Default: "false", + Default: false, QueryPath: "handleCookiePopup", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "max-age-ms", Usage: "Return a cached screenshot if a prior screenshot for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.", - Default: 86400000, + Default: requestflag.Ptr[int64](86400000), QueryPath: "maxAgeMs", }, &requestflag.Flag[string]{ @@ -276,7 +276,7 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional parameter to specify which page type to screenshot. If provided, the system will scrape the domain's links and use heuristics to find the most appropriate URL for the specified page type (30 supported languages). If not provided, screenshots the main domain landing page. Only applicable when using 'domain', not 'directUrl'.", QueryPath: "page", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "scroll-offset", Usage: "Optional vertical scroll offset in pixels for capturing a long page in viewport-sized chunks. When provided, the full page is captured once and the returned image is the viewport-sized slice that begins at this Y offset (e.g. request scrollOffset=0, then 1080, then 2160 to walk a 1920x1080 landing page top to bottom). The final slice may be shorter than the viewport height. Takes precedence over fullScreenshot. Max: 100000.", QueryPath: "scrollOffset", @@ -297,10 +297,10 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"width": 1920, "height": 1080}, QueryPath: "viewport", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "wait-for-ms", - Usage: "Optional browser wait time in milliseconds after initial page load before taking the screenshot. Min: 0. Max: 30000 (30 seconds). Defaults to 3000 ms when omitted.", - Default: 3000, + Usage: "Optional browser wait time in milliseconds after initial page load before taking the screenshot. Min: 0. Max: 30000 (30 seconds). Defaults to 3000 ms when omitted.", + Default: requestflag.Ptr[int64](3000), QueryPath: "waitForMs", }, }, @@ -594,10 +594,10 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[string]{ Name: "country", - Usage: "Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country.", + Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", QueryPath: "country", }, - &requestflag.Flag[[]string]{ + &requestflag.Flag[any]{ Name: "exclude-selector", Usage: `CSS selectors to remove from the result. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`, QueryPath: "excludeSelectors", @@ -607,21 +607,21 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", QueryPath: "headers", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "include-frames", Usage: "When true, iframes are rendered inline into the returned HTML.", Default: false, QueryPath: "includeFrames", }, - &requestflag.Flag[[]string]{ + &requestflag.Flag[any]{ Name: "include-selector", Usage: `CSS selectors. When provided, only matching subtrees (and their descendants) are kept and everything else is dropped. When omitted, the entire document is kept. Examples: "article.main", "#content", "[role=main]".`, QueryPath: "includeSelectors", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "max-age-ms", Usage: "Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh.", - Default: 86400000, + Default: requestflag.Ptr[int64](86400000), QueryPath: "maxAgeMs", }, &requestflag.Flag[map[string]any]{ @@ -630,7 +630,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"shouldParse": true, "ocr": false}, QueryPath: "pdf", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "settle-animations", Usage: "When true, waits briefly for CSS and transition animations to settle before extracting HTML. Defaults to false. This adds a bit of latency in exchange for more stable output on animated pages.", Default: false, @@ -646,15 +646,15 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", QueryPath: "timeoutMS", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "use-main-content-only", Usage: "When true, return only the page's main content in the HTML response, excluding headers, footers, sidebars, and navigation when detectable.", Default: false, QueryPath: "useMainContentOnly", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "wait-for-ms", - Usage: "Optional browser wait time in milliseconds after initial page load. Min: 0. Max: 30000 (30 seconds). ", + Usage: "Optional browser wait time in milliseconds after initial page load. Min: 0. Max: 30000 (30 seconds).", QueryPath: "waitForMs", }, }, @@ -667,12 +667,12 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", InnerField: "end", }, - &requestflag.InnerFlag[bool]{ + &requestflag.InnerFlag[any]{ Name: "pdf.ocr", Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback.", InnerField: "ocr", }, - &requestflag.InnerFlag[bool]{ + &requestflag.InnerFlag[any]{ Name: "pdf.should-parse", Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned.", InnerField: "shouldParse", @@ -696,7 +696,7 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Required: true, QueryPath: "url", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "dedupe", Usage: "When true, visually duplicate images are removed: every image is loaded and perceptually hashed, and only the highest-resolution copy of each duplicate group is kept. Images that cannot be downloaded or hashed are kept. Default: false.", Default: false, @@ -712,10 +712,10 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", QueryPath: "headers", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "max-age-ms", Usage: "Reuse a cached result this many milliseconds old or newer. Default: 86400000 (1 day). Set to 0 to bypass cache. Maximum: 2592000000 (30 days).", - Default: 86400000, + Default: requestflag.Ptr[int64](86400000), QueryPath: "maxAgeMs", }, &requestflag.Flag[[]string]{ @@ -728,9 +728,9 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", QueryPath: "timeoutMS", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "wait-for-ms", - Usage: "Optional browser wait time in milliseconds after initial page load before collecting images. Min: 0. Max: 30000 (30 seconds). ", + Usage: "Optional browser wait time in milliseconds after initial page load before collecting images. Min: 0. Max: 30000 (30 seconds).", QueryPath: "waitForMs", }, }, @@ -738,12 +738,12 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ HideHelpCommand: true, }, map[string][]requestflag.HasOuterFlag{ "enrichment": { - &requestflag.InnerFlag[bool]{ + &requestflag.InnerFlag[any]{ Name: "enrichment.classification", Usage: "Classify each image by visual asset type.", InnerField: "classification", }, - &requestflag.InnerFlag[bool]{ + &requestflag.InnerFlag[any]{ Name: "enrichment.hosted-url", Usage: "Host materializable images on the Brand.dev CDN and return their URL and MIME type.", InnerField: "hostedUrl", @@ -753,7 +753,7 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Usage: "Per-image enrichment timeout in milliseconds. Default: 30000. Maximum: 60000.", InnerField: "maxTimePerMs", }, - &requestflag.InnerFlag[bool]{ + &requestflag.InnerFlag[any]{ Name: "enrichment.resolution", Usage: "Measure image width and height when possible.", InnerField: "resolution", @@ -774,10 +774,10 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[string]{ Name: "country", - Usage: "Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country.", + Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", QueryPath: "country", }, - &requestflag.Flag[[]string]{ + &requestflag.Flag[any]{ Name: "exclude-selector", Usage: `CSS selectors to remove before conversion to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]".`, QueryPath: "excludeSelectors", @@ -787,33 +787,33 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", QueryPath: "headers", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "include-frames", Usage: "When true, the contents of iframes are rendered to Markdown.", Default: false, QueryPath: "includeFrames", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "include-images", Usage: "Include image references in Markdown output", Default: false, QueryPath: "includeImages", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "include-links", Usage: "Preserve hyperlinks in Markdown output", Default: true, QueryPath: "includeLinks", }, - &requestflag.Flag[[]string]{ + &requestflag.Flag[any]{ Name: "include-selector", Usage: `CSS selectors. When provided, only matching HTML subtrees (and their descendants) are kept before conversion to Markdown. When omitted, the entire document is kept. Examples: "article.main", "#content", "[role=main]".`, QueryPath: "includeSelectors", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "max-age-ms", Usage: "Return a cached result if a prior scrape for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always scrape fresh.", - Default: 86400000, + Default: requestflag.Ptr[int64](86400000), QueryPath: "maxAgeMs", }, &requestflag.Flag[map[string]any]{ @@ -822,13 +822,13 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"shouldParse": true, "ocr": false}, QueryPath: "pdf", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "settle-animations", Usage: "When true, waits briefly for CSS and transition animations to settle before converting to Markdown. Defaults to false. This adds a bit of latency in exchange for more stable output on animated pages.", Default: false, QueryPath: "settleAnimations", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "shorten-base64-images", Usage: "Shorten base64-encoded image data in the Markdown output", Default: true, @@ -844,15 +844,15 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", QueryPath: "timeoutMS", }, - &requestflag.Flag[bool]{ + &requestflag.Flag[any]{ Name: "use-main-content-only", Usage: "Extract only the main content of the page, excluding headers, footers, sidebars, and navigation", Default: false, QueryPath: "useMainContentOnly", }, - &requestflag.Flag[int64]{ + &requestflag.Flag[*int64]{ Name: "wait-for-ms", - Usage: "Optional browser wait time in milliseconds after initial page load before converting the page to Markdown. Min: 0. Max: 30000 (30 seconds). ", + Usage: "Optional browser wait time in milliseconds after initial page load before converting the page to Markdown. Min: 0. Max: 30000 (30 seconds).", QueryPath: "waitForMs", }, }, @@ -865,12 +865,12 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", InnerField: "end", }, - &requestflag.InnerFlag[bool]{ + &requestflag.InnerFlag[any]{ Name: "pdf.ocr", Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback.", InnerField: "ocr", }, - &requestflag.InnerFlag[bool]{ + &requestflag.InnerFlag[any]{ Name: "pdf.should-parse", Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned.", InnerField: "shouldParse", @@ -905,6 +905,11 @@ var webWebScrapeSitemap = cli.Command{ Default: 10000, QueryPath: "maxLinks", }, + &requestflag.Flag[string]{ + Name: "sitemap-url", + Usage: "Optional explicit sitemap URL. When provided, exactly this sitemap is crawled instead of discovering the domain's sitemaps.", + QueryPath: "sitemapUrl", + }, &requestflag.Flag[[]string]{ Name: "tag", Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 7732656..60fa65a 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -121,8 +121,8 @@ func TestWebExtractFonts(t *testing.T) { "--api-key", "string", "web", "extract-fonts", "--direct-url", "https://example.com", - "--domain", "domain", - "--max-age-ms", "86400000", + "--domain", "xxx", + "--max-age-ms", "0", "--tag", "production", "--tag", "team-alpha", "--timeout-ms", "1000", @@ -139,8 +139,8 @@ func TestWebExtractStyleguide(t *testing.T) { "web", "extract-styleguide", "--color-scheme", "light", "--direct-url", "https://example.com", - "--domain", "domain", - "--max-age-ms", "86400000", + "--domain", "xxx", + "--max-age-ms", "0", "--tag", "production", "--tag", "team-alpha", "--timeout-ms", "1000", @@ -158,15 +158,15 @@ func TestWebScreenshot(t *testing.T) { "--color-scheme", "light", "--country", "de", "--direct-url", "https://example.com", - "--domain", "domain", + "--domain", "xxx", "--full-screenshot", "true", - "--handle-cookie-popup", "true", + "--handle-cookie-popup", "'true'", "--max-age-ms", "0", "--page", "login", "--scroll-offset", "0", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", + "--timeout-ms", "1", "--viewport", "{height: 240, width: 240}", "--wait-for-ms", "0", ) @@ -184,15 +184,15 @@ func TestWebScreenshot(t *testing.T) { "--color-scheme", "light", "--country", "de", "--direct-url", "https://example.com", - "--domain", "domain", + "--domain", "xxx", "--full-screenshot", "true", - "--handle-cookie-popup", "true", + "--handle-cookie-popup", "'true'", "--max-age-ms", "0", "--page", "login", "--scroll-offset", "0", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", + "--timeout-ms", "1", "--viewport.height", "240", "--viewport.width", "240", "--wait-for-ms", "0", @@ -406,17 +406,17 @@ func TestWebWebScrapeHTML(t *testing.T) { "web", "web-scrape-html", "--url", "https://example.com", "--country", "de", - "--exclude-selector", "string", + "--exclude-selector", "[x]", "--headers", "{foo: J!}", - "--include-frames=true", - "--include-selector", "string", + "--include-frames", "'true'", + "--include-selector", "[x]", "--max-age-ms", "0", - "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", - "--settle-animations=true", + "--pdf", "{end: 1, ocr: 'true', shouldParse: 'true', start: 1}", + "--settle-animations", "'true'", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", - "--use-main-content-only=true", + "--timeout-ms", "1", + "--use-main-content-only", "'true'", "--wait-for-ms", "0", ) }) @@ -432,20 +432,20 @@ func TestWebWebScrapeHTML(t *testing.T) { "web", "web-scrape-html", "--url", "https://example.com", "--country", "de", - "--exclude-selector", "string", + "--exclude-selector", "[x]", "--headers", "{foo: J!}", - "--include-frames=true", - "--include-selector", "string", + "--include-frames", "'true'", + "--include-selector", "[x]", "--max-age-ms", "0", "--pdf.end", "1", - "--pdf.ocr=true", - "--pdf.should-parse=true", + "--pdf.ocr", "true", + "--pdf.should-parse", "true", "--pdf.start", "1", - "--settle-animations=true", + "--settle-animations", "'true'", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", - "--use-main-content-only=true", + "--timeout-ms", "1", + "--use-main-content-only", "'true'", "--wait-for-ms", "0", ) }) @@ -459,13 +459,13 @@ func TestWebWebScrapeImages(t *testing.T) { "--api-key", "string", "web", "web-scrape-images", "--url", "https://example.com", - "--dedupe=true", - "--enrichment", "{classification: true, hostedUrl: true, maxTimePerMs: 1, resolution: true}", + "--dedupe", "'true'", + "--enrichment", "{classification: 'true', hostedUrl: 'true', maxTimePerMs: 1, resolution: 'true'}", "--headers", "{foo: J!}", "--max-age-ms", "0", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", + "--timeout-ms", "1", "--wait-for-ms", "0", ) }) @@ -480,16 +480,16 @@ func TestWebWebScrapeImages(t *testing.T) { "--api-key", "string", "web", "web-scrape-images", "--url", "https://example.com", - "--dedupe=true", - "--enrichment.classification=true", - "--enrichment.hosted-url=true", + "--dedupe", "'true'", + "--enrichment.classification", "true", + "--enrichment.hosted-url", "true", "--enrichment.max-time-per-ms", "1", - "--enrichment.resolution=true", + "--enrichment.resolution", "true", "--headers", "{foo: J!}", "--max-age-ms", "0", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", + "--timeout-ms", "1", "--wait-for-ms", "0", ) }) @@ -504,20 +504,20 @@ func TestWebWebScrapeMd(t *testing.T) { "web", "web-scrape-md", "--url", "https://example.com", "--country", "de", - "--exclude-selector", "string", + "--exclude-selector", "[x]", "--headers", "{foo: J!}", - "--include-frames=true", - "--include-images=true", - "--include-links=true", - "--include-selector", "string", + "--include-frames", "'true'", + "--include-images", "'true'", + "--include-links", "'true'", + "--include-selector", "[x]", "--max-age-ms", "0", - "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", - "--settle-animations=true", - "--shorten-base64-images=true", + "--pdf", "{end: 1, ocr: 'true', shouldParse: 'true', start: 1}", + "--settle-animations", "'true'", + "--shorten-base64-images", "'true'", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", - "--use-main-content-only=true", + "--timeout-ms", "1", + "--use-main-content-only", "'true'", "--wait-for-ms", "0", ) }) @@ -533,23 +533,23 @@ func TestWebWebScrapeMd(t *testing.T) { "web", "web-scrape-md", "--url", "https://example.com", "--country", "de", - "--exclude-selector", "string", + "--exclude-selector", "[x]", "--headers", "{foo: J!}", - "--include-frames=true", - "--include-images=true", - "--include-links=true", - "--include-selector", "string", + "--include-frames", "'true'", + "--include-images", "'true'", + "--include-links", "'true'", + "--include-selector", "[x]", "--max-age-ms", "0", "--pdf.end", "1", - "--pdf.ocr=true", - "--pdf.should-parse=true", + "--pdf.ocr", "true", + "--pdf.should-parse", "true", "--pdf.start", "1", - "--settle-animations=true", - "--shorten-base64-images=true", + "--settle-animations", "'true'", + "--shorten-base64-images", "'true'", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", - "--use-main-content-only=true", + "--timeout-ms", "1", + "--use-main-content-only", "'true'", "--wait-for-ms", "0", ) }) @@ -562,12 +562,13 @@ func TestWebWebScrapeSitemap(t *testing.T) { t, "--api-key", "string", "web", "web-scrape-sitemap", - "--domain", "domain", + "--domain", "xxx", "--headers", "{foo: J!}", "--max-links", "1", + "--sitemap-url", "https://example.com", "--tag", "production", "--tag", "team-alpha", - "--timeout-ms", "1000", + "--timeout-ms", "1", "--url-regex", "^https?://[^/]+/blog/", ) }) From 185655481f9a3ea1bc3cd0ebd72a9f7a965cd0cf Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 18 Jul 2026 02:03:13 +0000 Subject: [PATCH 076/154] feat(stlc): configurable CI runner and private-production-repo support in workflow templates --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29c1f5c..556a5f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: lint: timeout-minutes: 10 name: lint - runs-on: ${{ github.repository == 'stainless-sdks/context.dev-cli' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + runs-on: ${{ startsWith(github.repository, 'stainless-sdks/') && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: @@ -48,7 +48,7 @@ jobs: permissions: contents: read id-token: write - runs-on: ${{ github.repository == 'stainless-sdks/context.dev-cli' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + runs-on: ${{ startsWith(github.repository, 'stainless-sdks/') && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -95,7 +95,7 @@ jobs: test: timeout-minutes: 10 name: test - runs-on: ${{ github.repository == 'stainless-sdks/context.dev-cli' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + runs-on: ${{ startsWith(github.repository, 'stainless-sdks/') && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: github.event_name == 'push' || github.event.pull_request.head.repo.fork steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 From fbba0b80550f676d5d7ec14dc5aec80ae7722793 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 19 Jul 2026 19:36:09 +0000 Subject: [PATCH 077/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/ai.go | 4 ++-- pkg/cmd/brand.go | 2 +- pkg/cmd/utility.go | 2 +- pkg/cmd/web.go | 12 +++++++++--- pkg/cmd/web_test.go | 3 +++ 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.stats.yml b/.stats.yml index b9d1d30..91b45dc 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d49b84cf1125618f171698ff1ee4ff9a8d04151619cb4a56d650103869834465.yml -openapi_spec_hash: 49b7a6f59dcdff1e2bf88feb6474a562 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8cd70a2b5bd380b75e5f94dc376bd8c704ee0431bdfe8af1b017facc2b883097.yml +openapi_spec_hash: bb1d32ae5c46be85ee8bb3b13f5b1150 config_hash: daabb160675d86b354711da1e77e5129 diff --git a/pkg/cmd/ai.go b/pkg/cmd/ai.go index dff2922..34a436a 100644 --- a/pkg/cmd/ai.go +++ b/pkg/cmd/ai.go @@ -33,7 +33,7 @@ var aiExtractProduct = cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", BodyPath: "tags", }, &requestflag.Flag[int64]{ @@ -69,7 +69,7 @@ var aiExtractProducts = cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", BodyPath: "tags", }, &requestflag.Flag[int64]{ diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index a453f90..c90f30d 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -47,7 +47,7 @@ var brandRetrieve = cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", BodyPath: "tags", }, &requestflag.Flag[int64]{ diff --git a/pkg/cmd/utility.go b/pkg/cmd/utility.go index 8ef1876..5376d1b 100644 --- a/pkg/cmd/utility.go +++ b/pkg/cmd/utility.go @@ -33,7 +33,7 @@ var utilityPrefetch = cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", BodyPath: "tags", }, &requestflag.Flag[int64]{ diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 9ddb7c8..378b195 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -76,6 +76,12 @@ var webExtract = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"shouldParse": true}, BodyPath: "pdf", }, + &requestflag.Flag[bool]{ + Name: "settle-animations", + Usage: "When true, waits briefly for CSS and transition animations to settle before extracting each crawled page. Defaults to false. This adds a bit of latency in exchange for more stable output on animated pages.", + Default: false, + BodyPath: "settleAnimations", + }, &requestflag.Flag[int64]{ Name: "stop-after-ms", Usage: "Soft time budget for the crawl in milliseconds. Min: 10000 (10s). Max: 110000 (110s). Default: 80000 (80s).", @@ -84,7 +90,7 @@ var webExtract = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", BodyPath: "tags", }, &requestflag.Flag[int64]{ @@ -370,7 +376,7 @@ var webSearch = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", BodyPath: "tags", }, &requestflag.Flag[int64]{ @@ -529,7 +535,7 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "Optional caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", BodyPath: "tags", }, &requestflag.Flag[int64]{ diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 60fa65a..b0a4735 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -26,6 +26,7 @@ func TestWebExtract(t *testing.T) { "--max-depth", "0", "--max-pages", "1", "--pdf", "{end: 1, shouldParse: true, start: 1}", + "--settle-animations=true", "--stop-after-ms", "10000", "--tag", "production", "--tag", "team-alpha", @@ -55,6 +56,7 @@ func TestWebExtract(t *testing.T) { "--pdf.end", "1", "--pdf.should-parse=true", "--pdf.start", "1", + "--settle-animations=true", "--stop-after-ms", "10000", "--tag", "production", "--tag", "team-alpha", @@ -83,6 +85,7 @@ func TestWebExtract(t *testing.T) { " end: 1\n" + " shouldParse: true\n" + " start: 1\n" + + "settleAnimations: true\n" + "stopAfterMs: 10000\n" + "tags:\n" + " - production\n" + From 217e49ba296104bcb977efbeb8f882cf4e1f70e0 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 21 Jul 2026 17:28:20 +0000 Subject: [PATCH 078/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/parse.go | 6 ++++++ pkg/cmd/parse_test.go | 3 +++ pkg/cmd/web.go | 30 ++++++++++++++++++++++++++++++ pkg/cmd/web_test.go | 12 +++++++++++- 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index 91b45dc..231a6da 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8cd70a2b5bd380b75e5f94dc376bd8c704ee0431bdfe8af1b017facc2b883097.yml -openapi_spec_hash: bb1d32ae5c46be85ee8bb3b13f5b1150 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-42c531dcf60b5d35e3996c1a669a3fe2de19d8caedf2bfd69e4864a1041c9bfa.yml +openapi_spec_hash: e43dd84c75e6d710c7346b9f12c34738 config_hash: daabb160675d86b354711da1e77e5129 diff --git a/pkg/cmd/parse.go b/pkg/cmd/parse.go index a4e7301..5403297 100644 --- a/pkg/cmd/parse.go +++ b/pkg/cmd/parse.go @@ -78,6 +78,12 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ Default: false, QueryPath: "useMainContentOnly", }, + &requestflag.Flag[string]{ + Name: "zdr", + Usage: "Set to enabled to bypass shared caches and omit request and response content from retained usage logs. Requires zero data retention to be enabled for your organization (contact support@context.dev), otherwise the request fails with ZDR_NOT_ENABLED. Successful ZDR responses include X-Context-ZDR: true.", + Default: "disabled", + QueryPath: "zdr", + }, }, Action: handleParseHandle, HideHelpCommand: true, diff --git a/pkg/cmd/parse_test.go b/pkg/cmd/parse_test.go index 5f09301..8177b5d 100644 --- a/pkg/cmd/parse_test.go +++ b/pkg/cmd/parse_test.go @@ -27,6 +27,7 @@ func TestParseHandle(t *testing.T) { "--tag", "production", "--tag", "team-alpha", "--use-main-content-only", "'true'", + "--zdr", "enabled", ) }) @@ -51,6 +52,7 @@ func TestParseHandle(t *testing.T) { "--tag", "production", "--tag", "team-alpha", "--use-main-content-only", "'true'", + "--zdr", "enabled", ) }) @@ -71,6 +73,7 @@ func TestParseHandle(t *testing.T) { "--tag", "production", "--tag", "team-alpha", "--use-main-content-only", "'true'", + "--zdr", "enabled", ) }) } diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 378b195..badb4c2 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -309,6 +309,12 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Default: requestflag.Ptr[int64](3000), QueryPath: "waitForMs", }, + &requestflag.Flag[string]{ + Name: "zdr", + Usage: "Set to enabled to bypass shared caches and omit request and response content from retained usage logs. Requires zero data retention to be enabled for your organization (contact support@context.dev), otherwise the request fails with ZDR_NOT_ENABLED. Successful ZDR responses include X-Context-ZDR: true.", + Default: "disabled", + QueryPath: "zdr", + }, }, Action: handleWebScreenshot, HideHelpCommand: true, @@ -559,6 +565,12 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional browser wait time in milliseconds after initial page load for each crawled page. Min: 0. Max: 30000 (30 seconds). ", BodyPath: "waitForMs", }, + &requestflag.Flag[string]{ + Name: "zdr", + Usage: "Set to enabled to bypass shared caches and omit request and response content from retained usage logs. Requires zero data retention to be enabled for your organization (contact support@context.dev), otherwise the request fails with ZDR_NOT_ENABLED. Successful ZDR responses include X-Context-ZDR: true.", + Default: "disabled", + BodyPath: "zdr", + }, }, Action: handleWebWebCrawlMd, HideHelpCommand: true, @@ -663,6 +675,12 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional browser wait time in milliseconds after initial page load. Min: 0. Max: 30000 (30 seconds).", QueryPath: "waitForMs", }, + &requestflag.Flag[string]{ + Name: "zdr", + Usage: "Set to enabled to bypass shared caches and omit request and response content from retained usage logs. Requires zero data retention to be enabled for your organization (contact support@context.dev), otherwise the request fails with ZDR_NOT_ENABLED. Successful ZDR responses include X-Context-ZDR: true.", + Default: "disabled", + QueryPath: "zdr", + }, }, Action: handleWebWebScrapeHTML, HideHelpCommand: true, @@ -861,6 +879,12 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional browser wait time in milliseconds after initial page load before converting the page to Markdown. Min: 0. Max: 30000 (30 seconds).", QueryPath: "waitForMs", }, + &requestflag.Flag[string]{ + Name: "zdr", + Usage: "Set to enabled to bypass shared caches and omit request and response content from retained usage logs. Requires zero data retention to be enabled for your organization (contact support@context.dev), otherwise the request fails with ZDR_NOT_ENABLED. Successful ZDR responses include X-Context-ZDR: true.", + Default: "disabled", + QueryPath: "zdr", + }, }, Action: handleWebWebScrapeMd, HideHelpCommand: true, @@ -931,6 +955,12 @@ var webWebScrapeSitemap = cli.Command{ Usage: "Optional RE2-compatible regex pattern. Only URLs matching this pattern are returned and counted against maxLinks.", QueryPath: "urlRegex", }, + &requestflag.Flag[string]{ + Name: "zdr", + Usage: "Set to enabled to bypass shared caches and omit request and response content from retained usage logs. Requires zero data retention to be enabled for your organization (contact support@context.dev), otherwise the request fails with ZDR_NOT_ENABLED. Successful ZDR responses include X-Context-ZDR: true.", + Default: "disabled", + QueryPath: "zdr", + }, }, Action: handleWebWebScrapeSitemap, HideHelpCommand: true, diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index b0a4735..0c53a19 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -172,6 +172,7 @@ func TestWebScreenshot(t *testing.T) { "--timeout-ms", "1", "--viewport", "{height: 240, width: 240}", "--wait-for-ms", "0", + "--zdr", "enabled", ) }) @@ -199,6 +200,7 @@ func TestWebScreenshot(t *testing.T) { "--viewport.height", "240", "--viewport.width", "240", "--wait-for-ms", "0", + "--zdr", "enabled", ) }) } @@ -322,6 +324,7 @@ func TestWebWebCrawlMd(t *testing.T) { "--url-regex", "^https?://[^/]+/blog/", "--use-main-content-only=true", "--wait-for-ms", "0", + "--zdr", "enabled", ) }) @@ -358,6 +361,7 @@ func TestWebWebCrawlMd(t *testing.T) { "--url-regex", "^https?://[^/]+/blog/", "--use-main-content-only=true", "--wait-for-ms", "0", + "--zdr", "enabled", ) }) @@ -391,7 +395,8 @@ func TestWebWebCrawlMd(t *testing.T) { "timeoutMS: 1000\n" + "urlRegex: ^https?://[^/]+/blog/\n" + "useMainContentOnly: true\n" + - "waitForMs: 0\n") + "waitForMs: 0\n" + + "zdr: enabled\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, "--api-key", "string", @@ -421,6 +426,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--timeout-ms", "1", "--use-main-content-only", "'true'", "--wait-for-ms", "0", + "--zdr", "enabled", ) }) @@ -450,6 +456,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--timeout-ms", "1", "--use-main-content-only", "'true'", "--wait-for-ms", "0", + "--zdr", "enabled", ) }) } @@ -522,6 +529,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--timeout-ms", "1", "--use-main-content-only", "'true'", "--wait-for-ms", "0", + "--zdr", "enabled", ) }) @@ -554,6 +562,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--timeout-ms", "1", "--use-main-content-only", "'true'", "--wait-for-ms", "0", + "--zdr", "enabled", ) }) } @@ -573,6 +582,7 @@ func TestWebWebScrapeSitemap(t *testing.T) { "--tag", "team-alpha", "--timeout-ms", "1", "--url-regex", "^https?://[^/]+/blog/", + "--zdr", "enabled", ) }) } From 3df1221e63cedfde00fdc850306eea13e02c0c55 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 08:05:42 +0000 Subject: [PATCH 079/154] feat(api): manual updates --- .stats.yml | 6 +-- pkg/cmd/cmd.go | 2 + pkg/cmd/monitor.go | 109 ++++++++++++++++++++++++++++++++++++++++ pkg/cmd/monitor_test.go | 24 +++++++++ 4 files changed, 138 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index 231a6da..674523c 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 30 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-42c531dcf60b5d35e3996c1a669a3fe2de19d8caedf2bfd69e4864a1041c9bfa.yml +configured_endpoints: 32 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d25300a20809f87d2069c1f4417b158b2e2d1cef3ca9b6bf7653e02233deba2c.yml openapi_spec_hash: e43dd84c75e6d710c7346b9f12c34738 -config_hash: daabb160675d86b354711da1e77e5129 +config_hash: 70e7e80b5e87f94981bee396c6cd41e8 diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 841a1e6..c17a6f6 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -155,6 +155,8 @@ func init() { &monitorsUpdate, &monitorsList, &monitorsDelete, + &monitorsGetCreditUsage, + &monitorsGetLimits, &monitorsListAccountChanges, &monitorsListAccountRuns, &monitorsListChanges, diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index 40641f1..1eca429 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -270,6 +270,35 @@ var monitorsDelete = cli.Command{ HideHelpCommand: true, } +var monitorsGetCreditUsage = cli.Command{ + Name: "get-credit-usage", + Usage: "Returns credits charged per monitor over an optional [since, until] window,\nnewest spenders first.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[any]{ + Name: "since", + Usage: "Only include items at or after this ISO 8601 timestamp.", + QueryPath: "since", + }, + &requestflag.Flag[any]{ + Name: "until", + Usage: "Only include items before this ISO 8601 timestamp.", + QueryPath: "until", + }, + }, + Action: handleMonitorsGetCreditUsage, + HideHelpCommand: true, +} + +var monitorsGetLimits = cli.Command{ + Name: "get-limits", + Usage: "Returns how many monitors the account has and the maximum it allows.", + Suggest: true, + Flags: []cli.Flag{}, + Action: handleMonitorsGetLimits, + HideHelpCommand: true, +} + var monitorsListAccountChanges = cli.Command{ Name: "list-account-changes", Usage: "Returns an account-wide feed of detected changes across monitors.", @@ -660,6 +689,86 @@ func handleMonitorsDelete(ctx context.Context, cmd *cli.Command) error { }) } +func handleMonitorsGetCreditUsage(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.MonitorGetCreditUsageParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.GetCreditUsage(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors get-credit-usage", + Transform: transform, + }) +} + +func handleMonitorsGetLimits(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Monitors.GetLimits(ctx, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "monitors get-limits", + Transform: transform, + }) +} + func handleMonitorsListAccountChanges(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) unusedArgs := cmd.Args().Slice() diff --git a/pkg/cmd/monitor_test.go b/pkg/cmd/monitor_test.go index 6e69e16..40e2c3c 100644 --- a/pkg/cmd/monitor_test.go +++ b/pkg/cmd/monitor_test.go @@ -201,6 +201,30 @@ func TestMonitorsDelete(t *testing.T) { }) } +func TestMonitorsGetCreditUsage(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "get-credit-usage", + "--since", "'2026-06-01T00:00:00Z'", + "--until", "'2026-06-28T00:00:00Z'", + ) + }) +} + +func TestMonitorsGetLimits(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "monitors", "get-limits", + ) + }) +} + func TestMonitorsListAccountChanges(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { From 80e1666211f4dfc18b41522f31fbaf9d69c3ac2b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 08:18:17 +0000 Subject: [PATCH 080/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 674523c..1a4b898 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d25300a20809f87d2069c1f4417b158b2e2d1cef3ca9b6bf7653e02233deba2c.yml -openapi_spec_hash: e43dd84c75e6d710c7346b9f12c34738 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-65d8d9d461368f72da68cd7606e0498cde07b586235769d8e3e04b7a3c42858d.yml +openapi_spec_hash: 048da2b1bfe8095b6c2e805c515e20e2 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 From 6dc3087be6ba4eddac5a99938b098996c124ab98 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 08:32:06 +0000 Subject: [PATCH 081/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/monitor.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.stats.yml b/.stats.yml index 1a4b898..d1ed301 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-65d8d9d461368f72da68cd7606e0498cde07b586235769d8e3e04b7a3c42858d.yml -openapi_spec_hash: 048da2b1bfe8095b6c2e805c515e20e2 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-48449a9e476c712dc65557934c8b97ac9708b06b7f96fa5c22d135037eeb9ce5.yml +openapi_spec_hash: 6a0575b3dc2ea3e5d47c4961f0251213 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index 1eca429..1842db3 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -49,7 +49,7 @@ var monitorsCreate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "User-defined tags for grouping and filtering monitors and their changes.", + Usage: "User-defined tags for grouping and filtering monitors and their changes. Duplicates are removed.", BodyPath: "tags", }, &requestflag.Flag[map[string]any]{ @@ -142,7 +142,7 @@ var monitorsUpdate = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "User-defined tags for grouping and filtering monitors and their changes.", + Usage: "User-defined tags for grouping and filtering monitors and their changes. Duplicates are removed.", BodyPath: "tags", }, &requestflag.Flag[map[string]any]{ From 88c3bc23c818591a08ba0c38e96068aa79094e89 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 08:56:04 +0000 Subject: [PATCH 082/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 19 +++++++++++++++++-- pkg/cmd/web_test.go | 6 ++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.stats.yml b/.stats.yml index d1ed301..f41ab2e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-48449a9e476c712dc65557934c8b97ac9708b06b7f96fa5c22d135037eeb9ce5.yml -openapi_spec_hash: 6a0575b3dc2ea3e5d47c4961f0251213 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-1ad134d4ef2ddefee790dc464dd2da3e4c0614652620b25fbb1379d8f5676526.yml +openapi_spec_hash: 24809b018c6869838112f064e5558509 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index badb4c2..483c012 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -601,7 +601,7 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Name: "web-scrape-html", - Usage: "Scrapes the given URL and returns the raw HTML content of the page.", + Usage: "Scrapes the given URL and returns the raw HTML content of the page. The base\nrequest costs 1 credit; requests with browser actions cost 2 credits.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ @@ -610,6 +610,11 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Required: true, QueryPath: "url", }, + &requestflag.Flag[any]{ + Name: "action", + Usage: "Optional browser actions executed in array order after the page loads and before content is captured. Requires a paid plan. Send a JSON array in the query parameter. Maximum: 5 actions.", + QueryPath: "actions", + }, &requestflag.Flag[string]{ Name: "country", Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", @@ -711,7 +716,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Name: "web-scrape-images", - Usage: "Extract image assets from a web page, including standard URLs, inline SVGs, data\nURIs, responsive image sources, metadata, CSS backgrounds, video posters, and\nembeds. The base request costs 1 credit. When enrichment is enabled, the entire\ncall costs 5 credits.", + Usage: "Extract image assets from a web page, including standard URLs, inline SVGs, data\nURIs, responsive image sources, metadata, CSS backgrounds, video posters, and\nembeds. The base request costs 1 credit, or 2 credits with browser actions. When\nenrichment is enabled, the entire call costs 5 credits, including requests that\nalso use actions.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ @@ -720,6 +725,11 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Required: true, QueryPath: "url", }, + &requestflag.Flag[any]{ + Name: "action", + Usage: "Optional browser actions executed in array order after the page loads and before content is captured. Requires a paid plan. Send a JSON array in the query parameter. Maximum: 5 actions.", + QueryPath: "actions", + }, &requestflag.Flag[any]{ Name: "dedupe", Usage: "When true, visually duplicate images are removed: every image is loaded and perceptually hashed, and only the highest-resolution copy of each duplicate group is kept. Images that cannot be downloaded or hashed are kept. Default: false.", @@ -796,6 +806,11 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Required: true, QueryPath: "url", }, + &requestflag.Flag[any]{ + Name: "action", + Usage: "Optional browser actions executed in array order after the page loads and before content is captured. Requires a paid plan. Send a JSON array in the query parameter. Maximum: 5 actions.", + QueryPath: "actions", + }, &requestflag.Flag[string]{ Name: "country", Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 0c53a19..8eda947 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -413,6 +413,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--api-key", "string", "web", "web-scrape-html", "--url", "https://example.com", + "--action", "[{do: wait, timeMs: 0}]", "--country", "de", "--exclude-selector", "[x]", "--headers", "{foo: J!}", @@ -440,6 +441,7 @@ func TestWebWebScrapeHTML(t *testing.T) { "--api-key", "string", "web", "web-scrape-html", "--url", "https://example.com", + "--action", "[{do: wait, timeMs: 0}]", "--country", "de", "--exclude-selector", "[x]", "--headers", "{foo: J!}", @@ -469,6 +471,7 @@ func TestWebWebScrapeImages(t *testing.T) { "--api-key", "string", "web", "web-scrape-images", "--url", "https://example.com", + "--action", "[{do: wait, timeMs: 0}]", "--dedupe", "'true'", "--enrichment", "{classification: 'true', hostedUrl: 'true', maxTimePerMs: 1, resolution: 'true'}", "--headers", "{foo: J!}", @@ -490,6 +493,7 @@ func TestWebWebScrapeImages(t *testing.T) { "--api-key", "string", "web", "web-scrape-images", "--url", "https://example.com", + "--action", "[{do: wait, timeMs: 0}]", "--dedupe", "'true'", "--enrichment.classification", "true", "--enrichment.hosted-url", "true", @@ -513,6 +517,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--api-key", "string", "web", "web-scrape-md", "--url", "https://example.com", + "--action", "[{do: wait, timeMs: 0}]", "--country", "de", "--exclude-selector", "[x]", "--headers", "{foo: J!}", @@ -543,6 +548,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--api-key", "string", "web", "web-scrape-md", "--url", "https://example.com", + "--action", "[{do: wait, timeMs: 0}]", "--country", "de", "--exclude-selector", "[x]", "--headers", "{foo: J!}", From 97a27f5f45c5ddbd86e29530898d8d8117f9f785 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 09:18:18 +0000 Subject: [PATCH 083/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index f41ab2e..dd88a66 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-1ad134d4ef2ddefee790dc464dd2da3e4c0614652620b25fbb1379d8f5676526.yml -openapi_spec_hash: 24809b018c6869838112f064e5558509 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4dea765de04ef16556290055d83312b58e0dc16586e9a717d378dc451f068113.yml +openapi_spec_hash: e4c702985962f8e35fffffcc821700b6 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 From f28a5c9300de36063fadaa4d386255b80a571dbb Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 18:06:34 +0000 Subject: [PATCH 084/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index dd88a66..53999f4 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4dea765de04ef16556290055d83312b58e0dc16586e9a717d378dc451f068113.yml -openapi_spec_hash: e4c702985962f8e35fffffcc821700b6 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ce19e3abfe1f07d4a615d2fb35666e99f7918b821dfc270b38bfd9c0de39fc4e.yml +openapi_spec_hash: 71623548f792037a7f13fb693b41e217 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 From cb151df24df2f8030d2c8f72de12c04872b42d8b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 18:45:48 +0000 Subject: [PATCH 085/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 53999f4..0ac1eb3 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-ce19e3abfe1f07d4a615d2fb35666e99f7918b821dfc270b38bfd9c0de39fc4e.yml -openapi_spec_hash: 71623548f792037a7f13fb693b41e217 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-242450ea46eb8c3e843fd6c4bf87e73192b5f62f6da697cd091d13c6aa7a991b.yml +openapi_spec_hash: c1c561976de1abcacede71fd5ab9b3d9 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 From 878c2554553a6508473c031892e70562fae366d7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jul 2026 18:48:53 +0000 Subject: [PATCH 086/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index fea3454..2601677 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.0.0" + ".": "1.1.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index d47a190..a47345e 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.0.0" // x-release-please-version +const Version = "1.1.0" // x-release-please-version From 1969f7fdfeb34c56e3c90069643790656103632b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 02:03:34 +0000 Subject: [PATCH 087/154] chore(internal): codegen related update --- go.mod | 2 -- go.sum | 5 ----- 2 files changed, 7 deletions(-) diff --git a/go.mod b/go.mod index a000854..05dad28 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.4.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 @@ -38,7 +37,6 @@ require ( github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/tidwall/match v1.1.1 // indirect - github.com/tidwall/sjson v1.2.5 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/sync v0.15.0 // indirect golang.org/x/text v0.3.8 // indirect diff --git a/go.sum b/go.sum index e9ff7cd..4b63f4b 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,6 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.4.0 h1:mehuyGuUzgflR7rQpSlPaH7lNj2A8hdtf1+WG4U4h1I= -github.com/context-dot-dev/context-go-sdk/v2 v2.4.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -57,7 +55,6 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= @@ -65,8 +62,6 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= -github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/urfave/cli-docs/v3 v3.0.0-alpha6 h1:w/l/N0xw1rO/aHRIGXJ0lDwwYFOzilup1qGvIytP3BI= github.com/urfave/cli-docs/v3 v3.0.0-alpha6/go.mod h1:p7Z4lg8FSTrPB9GTaNyTrK3ygffHZcK3w0cU2VE+mzU= github.com/urfave/cli/v3 v3.3.2 h1:BYFVnhhZ8RqT38DxEYVFPPmGFTEf7tJwySTXsVRrS/o= From 31af70b5321e2fa5e11a77ef028fad3ed0174368 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 23 Jul 2026 04:09:54 +0000 Subject: [PATCH 088/154] feat(api): api update --- go.mod | 2 ++ go.sum | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/go.mod b/go.mod index 05dad28..12f3f67 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 + github.com/context-dot-dev/context-go-sdk/v2 v2.5.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 @@ -37,6 +38,7 @@ require ( github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/sjson v1.2.5 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/sync v0.15.0 // indirect golang.org/x/text v0.3.8 // indirect diff --git a/go.sum b/go.sum index 4b63f4b..2e31ee8 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= +github.com/context-dot-dev/context-go-sdk/v2 v2.5.0 h1:FK79MDMznyABXAUjRGO44Xmvl6Bi0nz1HBSlwYyMU6U= +github.com/context-dot-dev/context-go-sdk/v2 v2.5.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -55,6 +57,7 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= @@ -62,6 +65,8 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/urfave/cli-docs/v3 v3.0.0-alpha6 h1:w/l/N0xw1rO/aHRIGXJ0lDwwYFOzilup1qGvIytP3BI= github.com/urfave/cli-docs/v3 v3.0.0-alpha6/go.mod h1:p7Z4lg8FSTrPB9GTaNyTrK3ygffHZcK3w0cU2VE+mzU= github.com/urfave/cli/v3 v3.3.2 h1:BYFVnhhZ8RqT38DxEYVFPPmGFTEf7tJwySTXsVRrS/o= From c4810df8d19b5135d8b7895ec73185495cce6d66 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 25 Jul 2026 07:12:58 +0000 Subject: [PATCH 089/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/monitor.go | 22 ++++++++++------------ pkg/cmd/monitor_test.go | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/.stats.yml b/.stats.yml index 0ac1eb3..6da4682 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-242450ea46eb8c3e843fd6c4bf87e73192b5f62f6da697cd091d13c6aa7a991b.yml -openapi_spec_hash: c1c561976de1abcacede71fd5ab9b3d9 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2bf2b44f6593c44b2948683469bbb2b09cd8e90c97b12057fac6220cf0d2eee7.yml +openapi_spec_hash: ae8b5109ec997cac8d3e6ec96040f6c8 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 diff --git a/pkg/cmd/monitor.go b/pkg/cmd/monitor.go index 1842db3..fac0f1c 100644 --- a/pkg/cmd/monitor.go +++ b/pkg/cmd/monitor.go @@ -19,34 +19,32 @@ var monitorsCreate = requestflag.WithInnerFlags(cli.Command{ Usage: "Creates a monitor. The request body is a union of the supported target/change\ndetection combinations. The monitor runs immediately after creation to create\nits initial baseline.", Suggest: true, Flags: []cli.Flag{ - &requestflag.Flag[map[string]any]{ - Name: "change-detection", - Usage: "Discriminated union describing how changes are detected.", - Required: true, - BodyPath: "change_detection", - }, &requestflag.Flag[string]{ Name: "name", Required: true, BodyPath: "name", }, - &requestflag.Flag[map[string]any]{ - Name: "schedule", - Usage: "Run the monitor on a fixed interval defined by a frequency and a unit, e.g. every 6 hours or every 2 days. The total interval (frequency × unit) must be between 10 minutes and 1 year.", - Required: true, - BodyPath: "schedule", - }, &requestflag.Flag[map[string]any]{ Name: "target", Usage: "Discriminated union describing what the monitor watches.", Required: true, BodyPath: "target", }, + &requestflag.Flag[map[string]any]{ + Name: "change-detection", + Usage: "Discriminated union describing how changes are detected.", + BodyPath: "change_detection", + }, &requestflag.Flag[string]{ Name: "mode", Usage: "Top-level monitor category. Always `web` today; the concrete behavior is described by `target` and `change_detection`.", BodyPath: "mode", }, + &requestflag.Flag[map[string]any]{ + Name: "schedule", + Usage: "Run the monitor on a fixed interval defined by a frequency and a unit, e.g. every 6 hours or every 2 days. The total interval (frequency × unit) must be between 10 minutes and 1 year.", + BodyPath: "schedule", + }, &requestflag.Flag[[]string]{ Name: "tag", Usage: "User-defined tags for grouping and filtering monitors and their changes. Duplicates are removed.", diff --git a/pkg/cmd/monitor_test.go b/pkg/cmd/monitor_test.go index 40e2c3c..ddfa7fb 100644 --- a/pkg/cmd/monitor_test.go +++ b/pkg/cmd/monitor_test.go @@ -16,11 +16,11 @@ func TestMonitorsCreate(t *testing.T) { t, "--api-key", "string", "monitors", "create", - "--change-detection", "{type: exact}", "--name", "Acme pricing page", - "--schedule", "{frequency: 6, type: interval, unit: hours}", "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--change-detection", "{type: exact}", "--mode", "web", + "--schedule", "{frequency: 6, type: interval, unit: hours}", "--tag", "pricing", "--tag", "competitor", "--webhook", "{url: https://example.com/webhook, events: [change.detected, run.completed]}", @@ -36,13 +36,13 @@ func TestMonitorsCreate(t *testing.T) { t, "--api-key", "string", "monitors", "create", - "--change-detection", "{type: exact}", "--name", "Acme pricing page", + "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--change-detection", "{type: exact}", + "--mode", "web", "--schedule.frequency", "6", "--schedule.type", "interval", "--schedule.unit", "hours", - "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", - "--mode", "web", "--tag", "pricing", "--tag", "competitor", "--webhook.url", "https://example.com/webhook", @@ -53,18 +53,18 @@ func TestMonitorsCreate(t *testing.T) { t.Run("piping data", func(t *testing.T) { // Test piping YAML data over stdin pipeData := []byte("" + - "change_detection:\n" + - " type: exact\n" + "name: Acme pricing page\n" + - "schedule:\n" + - " frequency: 6\n" + - " type: interval\n" + - " unit: hours\n" + "target:\n" + " type: page\n" + " url: https://acme.com/pricing\n" + " normalize_whitespace: true\n" + + "change_detection:\n" + + " type: exact\n" + "mode: web\n" + + "schedule:\n" + + " frequency: 6\n" + + " type: interval\n" + + " unit: hours\n" + "tags:\n" + " - pricing\n" + " - competitor\n" + From 37a485f8acca2c9e348d9d3040084ef42a0fe5c2 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 06:43:28 +0000 Subject: [PATCH 090/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/monitor_test.go | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6da4682..3f4cd2e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2bf2b44f6593c44b2948683469bbb2b09cd8e90c97b12057fac6220cf0d2eee7.yml -openapi_spec_hash: ae8b5109ec997cac8d3e6ec96040f6c8 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-91f4286859fc23813c5255b877395c87dd81520c3913fdfdae3cfa343e1a4873.yml +openapi_spec_hash: 71746b5b65f20617ee021e071d5f7f92 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 diff --git a/pkg/cmd/monitor_test.go b/pkg/cmd/monitor_test.go index ddfa7fb..983650e 100644 --- a/pkg/cmd/monitor_test.go +++ b/pkg/cmd/monitor_test.go @@ -17,7 +17,7 @@ func TestMonitorsCreate(t *testing.T) { "--api-key", "string", "monitors", "create", "--name", "Acme pricing page", - "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--target", "{type: page, url: https://acme.com/pricing, instructions: 'Report pricing or plan availability changes. Ignore counters, timestamps, testimonials, and navigation.', normalize_whitespace: true}", "--change-detection", "{type: exact}", "--mode", "web", "--schedule", "{frequency: 6, type: interval, unit: hours}", @@ -37,7 +37,7 @@ func TestMonitorsCreate(t *testing.T) { "--api-key", "string", "monitors", "create", "--name", "Acme pricing page", - "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--target", "{type: page, url: https://acme.com/pricing, instructions: 'Report pricing or plan availability changes. Ignore counters, timestamps, testimonials, and navigation.', normalize_whitespace: true}", "--change-detection", "{type: exact}", "--mode", "web", "--schedule.frequency", "6", @@ -57,6 +57,9 @@ func TestMonitorsCreate(t *testing.T) { "target:\n" + " type: page\n" + " url: https://acme.com/pricing\n" + + " instructions: >-\n" + + " Report pricing or plan availability changes. Ignore counters, timestamps,\n" + + " testimonials, and navigation.\n" + " normalize_whitespace: true\n" + "change_detection:\n" + " type: exact\n" + @@ -107,7 +110,7 @@ func TestMonitorsUpdate(t *testing.T) { "--status", "active", "--tag", "pricing", "--tag", "competitor", - "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--target", "{type: page, url: https://acme.com/pricing, instructions: 'Report pricing or plan availability changes. Ignore counters, timestamps, testimonials, and navigation.', normalize_whitespace: true}", "--webhook", "{url: https://example.com/webhook, events: [change.detected, run.completed]}", ) }) @@ -130,7 +133,7 @@ func TestMonitorsUpdate(t *testing.T) { "--status", "active", "--tag", "pricing", "--tag", "competitor", - "--target", "{type: page, url: https://acme.com/pricing, normalize_whitespace: true}", + "--target", "{type: page, url: https://acme.com/pricing, instructions: 'Report pricing or plan availability changes. Ignore counters, timestamps, testimonials, and navigation.', normalize_whitespace: true}", "--webhook.url", "https://example.com/webhook", "--webhook.events", "[change.detected, run.completed]", ) @@ -153,6 +156,9 @@ func TestMonitorsUpdate(t *testing.T) { "target:\n" + " type: page\n" + " url: https://acme.com/pricing\n" + + " instructions: >-\n" + + " Report pricing or plan availability changes. Ignore counters, timestamps,\n" + + " testimonials, and navigation.\n" + " normalize_whitespace: true\n" + "webhook:\n" + " url: https://example.com/webhook\n" + From 640358b96b42865c87503f9c96abac1974b1898b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 07:19:05 +0000 Subject: [PATCH 091/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 3f4cd2e..6183d03 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-91f4286859fc23813c5255b877395c87dd81520c3913fdfdae3cfa343e1a4873.yml -openapi_spec_hash: 71746b5b65f20617ee021e071d5f7f92 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-9ee1d9a454772b4cd978d5e0ad8ead21d732fa559686130daf0540084b5f6be5.yml +openapi_spec_hash: fb66e1f80fb2aad8adc4ae37d69bdc02 config_hash: 70e7e80b5e87f94981bee396c6cd41e8 From ced32c6b8f378472eb7bdadffd944477931461d4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 07:57:46 +0000 Subject: [PATCH 092/154] feat(api): manual updates --- .stats.yml | 6 +- pkg/cmd/batch.go | 381 ++++++++++++++++++++++++++++++++++++++++++ pkg/cmd/batch_test.go | 117 +++++++++++++ pkg/cmd/cmd.go | 12 ++ 4 files changed, 513 insertions(+), 3 deletions(-) create mode 100644 pkg/cmd/batch.go create mode 100644 pkg/cmd/batch_test.go diff --git a/.stats.yml b/.stats.yml index 6183d03..a173ebe 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 32 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-9ee1d9a454772b4cd978d5e0ad8ead21d732fa559686130daf0540084b5f6be5.yml +configured_endpoints: 37 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-6dfc33639ef5ad1fd0fa05f9f00fcdd59940188ef625252c6ee9db85c6f8fc59.yml openapi_spec_hash: fb66e1f80fb2aad8adc4ae37d69bdc02 -config_hash: 70e7e80b5e87f94981bee396c6cd41e8 +config_hash: 2bea1743c84d63bd61f8501a6ea63065 diff --git a/pkg/cmd/batch.go b/pkg/cmd/batch.go new file mode 100644 index 0000000..8da539c --- /dev/null +++ b/pkg/cmd/batch.go @@ -0,0 +1,381 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var batchRetrieve = cli.Command{ + Name: "retrieve", + Usage: "Check progress and get download links when the batch finishes. Also returns the\nrejected-URL list and webhook signing secret from submission, so nothing is lost\nif the submit response was dropped.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "batch-id", + Usage: "ID of the batch to retrieve or cancel.", + Required: true, + PathParam: "batch_id", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, + }, + Action: handleBatchRetrieve, + HideHelpCommand: true, +} + +var batchList = cli.Command{ + Name: "list", + Usage: "List your batches from newest to oldest. Filter by status or continue with a\ncursor.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "cursor", + Usage: "Cursor from the previous page.", + QueryPath: "cursor", + }, + &requestflag.Flag[int64]{ + Name: "limit", + Usage: "Batches per page. Defaults to 25.", + QueryPath: "limit", + }, + &requestflag.Flag[string]{ + Name: "status", + Usage: "Filter by status.", + QueryPath: "status", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, + }, + Action: handleBatchList, + HideHelpCommand: true, +} + +var batchCancel = cli.Command{ + Name: "cancel", + Usage: "Stop a batch from starting new pages. In-progress pages finish, and unused\ncredits are refunded.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "batch-id", + Usage: "ID of the batch to retrieve or cancel.", + Required: true, + PathParam: "batch_id", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, + }, + Action: handleBatchCancel, + HideHelpCommand: true, +} + +var batchGetResults = cli.Command{ + Name: "get-results", + Usage: "Page through the result records of a finished batch as JSON, in the same order\nas the downloadable result files. Use this instead of downloading and parsing\nthe NDJSON files yourself.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "batch-id", + Usage: "ID of the batch to retrieve or cancel.", + Required: true, + PathParam: "batch_id", + }, + &requestflag.Flag[string]{ + Name: "cursor", + Usage: "next_cursor from the previous page.", + QueryPath: "cursor", + }, + &requestflag.Flag[int64]{ + Name: "limit", + Usage: "Records per page. Defaults to 25. A page can close early so its payload stays under ~8 MB; rely on next_cursor rather than counting records.", + QueryPath: "limit", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, + }, + Action: handleBatchGetResults, + HideHelpCommand: true, +} + +var batchSubmit = requestflag.WithInnerFlags(cli.Command{ + Name: "submit", + Usage: "Retrieve and normalize a person profile from identifiers.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[map[string]any]{ + Name: "identifiers", + Usage: "Known identifiers for the person. At least one identifier is required.", + Required: true, + BodyPath: "identifiers", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", + BodyPath: "tags", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + }, + Action: handleBatchSubmit, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "identifiers": { + &requestflag.InnerFlag[string]{ + Name: "identifiers.linkedin-url", + Usage: "LinkedIn profile URL, e.g. https://www.linkedin.com/in/yahia-bakour/.", + InnerField: "linkedinUrl", + }, + }, +}) + +func handleBatchRetrieve(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("batch-id") && len(unusedArgs) > 0 { + cmd.Set("batch-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BatchGetParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Batch.Get( + ctx, + cmd.Value("batch-id").(string), + params, + options..., + ) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "batch retrieve", + Transform: transform, + }) +} + +func handleBatchList(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BatchListParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Batch.List(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "batch list", + Transform: transform, + }) +} + +func handleBatchCancel(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("batch-id") && len(unusedArgs) > 0 { + cmd.Set("batch-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BatchCancelParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Batch.Cancel( + ctx, + cmd.Value("batch-id").(string), + params, + options..., + ) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "batch cancel", + Transform: transform, + }) +} + +func handleBatchGetResults(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("batch-id") && len(unusedArgs) > 0 { + cmd.Set("batch-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BatchGetResultsParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Batch.GetResults( + ctx, + cmd.Value("batch-id").(string), + params, + options..., + ) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "batch get-results", + Transform: transform, + }) +} + +func handleBatchSubmit(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.BatchSubmitParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Batch.Submit(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "batch submit", + Transform: transform, + }) +} diff --git a/pkg/cmd/batch_test.go b/pkg/cmd/batch_test.go new file mode 100644 index 0000000..84173a8 --- /dev/null +++ b/pkg/cmd/batch_test.go @@ -0,0 +1,117 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" +) + +func TestBatchRetrieve(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "batch", "retrieve", + "--batch-id", "batch_9f2c8a", + "--tag", "production", + "--tag", "team-alpha", + ) + }) +} + +func TestBatchList(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "batch", "list", + "--cursor", "cursor", + "--limit", "1", + "--status", "queued", + "--tag", "production", + "--tag", "team-alpha", + ) + }) +} + +func TestBatchCancel(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "batch", "cancel", + "--batch-id", "batch_9f2c8a", + "--tag", "production", + "--tag", "team-alpha", + ) + }) +} + +func TestBatchGetResults(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "batch", "get-results", + "--batch-id", "batch_9f2c8a", + "--cursor", "cursor", + "--limit", "1", + "--tag", "production", + "--tag", "team-alpha", + ) + }) +} + +func TestBatchSubmit(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "batch", "submit", + "--identifiers", "{linkedinUrl: https://www.linkedin.com/in/yahia-bakour/}", + "--tag", "production", + "--tag", "team-alpha", + "--timeout-ms", "1000", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(batchSubmit) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "batch", "submit", + "--identifiers.linkedin-url", "https://www.linkedin.com/in/yahia-bakour/", + "--tag", "production", + "--tag", "team-alpha", + "--timeout-ms", "1000", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "identifiers:\n" + + " linkedinUrl: https://www.linkedin.com/in/yahia-bakour/\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "batch", "submit", + ) + }) +} diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index c17a6f6..a90d921 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -165,6 +165,18 @@ func init() { &monitorsRun, }, }, + { + Name: "batch", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &batchRetrieve, + &batchList, + &batchCancel, + &batchGetResults, + &batchSubmit, + }, + }, { Name: "@manpages", Usage: "Generate documentation for 'man'", From f7cadd6b024c865a760723edd6096bda856796e8 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:32:36 +0000 Subject: [PATCH 093/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/batch.go | 49 +++++++++++++------------------------------ pkg/cmd/batch_test.go | 11 +++------- 3 files changed, 20 insertions(+), 44 deletions(-) diff --git a/.stats.yml b/.stats.yml index a173ebe..86253ea 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-6dfc33639ef5ad1fd0fa05f9f00fcdd59940188ef625252c6ee9db85c6f8fc59.yml -openapi_spec_hash: fb66e1f80fb2aad8adc4ae37d69bdc02 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-cdff38301573d05fdad8416847402472ff6cb1ce75a9de9f99e8673ddec7c4a6.yml +openapi_spec_hash: 387fe6f53599abb0341764e00bcd0b26 config_hash: 2bea1743c84d63bd61f8501a6ea63065 diff --git a/pkg/cmd/batch.go b/pkg/cmd/batch.go index 8da539c..d95a1ff 100644 --- a/pkg/cmd/batch.go +++ b/pkg/cmd/batch.go @@ -25,11 +25,6 @@ var batchRetrieve = cli.Command{ Required: true, PathParam: "batch_id", }, - &requestflag.Flag[[]string]{ - Name: "tag", - Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", - QueryPath: "tags", - }, }, Action: handleBatchRetrieve, HideHelpCommand: true, @@ -50,14 +45,24 @@ var batchList = cli.Command{ Usage: "Batches per page. Defaults to 25.", QueryPath: "limit", }, + &requestflag.Flag[string]{ + Name: "q", + Usage: "Free-text search term, matched against the batch id, crawl source (start URL or sitemap domain), and tags.", + QueryPath: "q", + }, + &requestflag.Flag[string]{ + Name: "search-type", + Usage: "`prefix` for as-you-type prefix matching (default), `exact` for full-token matching.", + QueryPath: "search_type", + }, &requestflag.Flag[string]{ Name: "status", Usage: "Filter by status.", QueryPath: "status", }, - &requestflag.Flag[[]string]{ - Name: "tag", - Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + &requestflag.Flag[string]{ + Name: "tags", + Usage: "Comma-separated list of tags to filter by (matches batches having any of them).", QueryPath: "tags", }, }, @@ -76,11 +81,6 @@ var batchCancel = cli.Command{ Required: true, PathParam: "batch_id", }, - &requestflag.Flag[[]string]{ - Name: "tag", - Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", - QueryPath: "tags", - }, }, Action: handleBatchCancel, HideHelpCommand: true, @@ -107,11 +107,6 @@ var batchGetResults = cli.Command{ Usage: "Records per page. Defaults to 25. A page can close early so its payload stays under ~8 MB; rely on next_cursor rather than counting records.", QueryPath: "limit", }, - &requestflag.Flag[[]string]{ - Name: "tag", - Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", - QueryPath: "tags", - }, }, Action: handleBatchGetResults, HideHelpCommand: true, @@ -173,16 +168,9 @@ func handleBatchRetrieve(ctx context.Context, cmd *cli.Command) error { return err } - params := contextdev.BatchGetParams{} - var res []byte options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.Batch.Get( - ctx, - cmd.Value("batch-id").(string), - params, - options..., - ) + _, err = client.Batch.Get(ctx, cmd.Value("batch-id").(string), options...) if err != nil { return err } @@ -263,16 +251,9 @@ func handleBatchCancel(ctx context.Context, cmd *cli.Command) error { return err } - params := contextdev.BatchCancelParams{} - var res []byte options = append(options, option.WithResponseBodyInto(&res)) - _, err = client.Batch.Cancel( - ctx, - cmd.Value("batch-id").(string), - params, - options..., - ) + _, err = client.Batch.Cancel(ctx, cmd.Value("batch-id").(string), options...) if err != nil { return err } diff --git a/pkg/cmd/batch_test.go b/pkg/cmd/batch_test.go index 84173a8..a14073e 100644 --- a/pkg/cmd/batch_test.go +++ b/pkg/cmd/batch_test.go @@ -17,8 +17,6 @@ func TestBatchRetrieve(t *testing.T) { "--api-key", "string", "batch", "retrieve", "--batch-id", "batch_9f2c8a", - "--tag", "production", - "--tag", "team-alpha", ) }) } @@ -32,9 +30,10 @@ func TestBatchList(t *testing.T) { "batch", "list", "--cursor", "cursor", "--limit", "1", + "--q", "batch_1a2b", + "--search-type", "exact", "--status", "queued", - "--tag", "production", - "--tag", "team-alpha", + "--tags", "docs,competitor", ) }) } @@ -47,8 +46,6 @@ func TestBatchCancel(t *testing.T) { "--api-key", "string", "batch", "cancel", "--batch-id", "batch_9f2c8a", - "--tag", "production", - "--tag", "team-alpha", ) }) } @@ -63,8 +60,6 @@ func TestBatchGetResults(t *testing.T) { "--batch-id", "batch_9f2c8a", "--cursor", "cursor", "--limit", "1", - "--tag", "production", - "--tag", "team-alpha", ) }) } From 030eb6d9ef8041a0ee7bb0a852a12153ca7feb3c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 23:26:24 +0000 Subject: [PATCH 094/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 86253ea..eec42c9 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-cdff38301573d05fdad8416847402472ff6cb1ce75a9de9f99e8673ddec7c4a6.yml -openapi_spec_hash: 387fe6f53599abb0341764e00bcd0b26 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-1b0d50368dea5273a516e385bba67202320cc9692bbeba21735cd615e380c375.yml +openapi_spec_hash: e55a3d1cc7217e874931a231d180c247 config_hash: 2bea1743c84d63bd61f8501a6ea63065 From e1e83062ef217e31885088556c86451a59c8ffd4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 05:57:02 +0000 Subject: [PATCH 095/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index eec42c9..e8bb28d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-1b0d50368dea5273a516e385bba67202320cc9692bbeba21735cd615e380c375.yml -openapi_spec_hash: e55a3d1cc7217e874931a231d180c247 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-31c3cdf42b1a2e726724539dd613d902c72afdf75fa8da028c79eee9d6d71ea4.yml +openapi_spec_hash: 409abf0799543827d54ea7293ffa5b74 config_hash: 2bea1743c84d63bd61f8501a6ea63065 From a59a3e35ba77b26ff61502d453be021e3bccc3e8 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 06:35:17 +0000 Subject: [PATCH 096/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index e8bb28d..75e4f88 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-31c3cdf42b1a2e726724539dd613d902c72afdf75fa8da028c79eee9d6d71ea4.yml -openapi_spec_hash: 409abf0799543827d54ea7293ffa5b74 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c7e18da06db76bc8a22f2466e13b1958aedf1791ae3310e289f4c5a3dd522936.yml +openapi_spec_hash: 17d1ac64568e4f0ef529692cd3667175 config_hash: 2bea1743c84d63bd61f8501a6ea63065 From 28bb2e23544928e35893bcbe742a26730d59ae52 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 07:58:24 +0000 Subject: [PATCH 097/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 75e4f88..b3a442f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c7e18da06db76bc8a22f2466e13b1958aedf1791ae3310e289f4c5a3dd522936.yml -openapi_spec_hash: 17d1ac64568e4f0ef529692cd3667175 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-67d0edd5da21ac5e53c3d1f82d60e5f71a160938ed0e8f2e567b042978792405.yml +openapi_spec_hash: d52bec73da0d689ecce7b95235fc6846 config_hash: 2bea1743c84d63bd61f8501a6ea63065 From 028a252e17774b4bb521358c8c3a9c1a7b083af9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 08:04:18 +0000 Subject: [PATCH 098/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index b3a442f..33b7080 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-67d0edd5da21ac5e53c3d1f82d60e5f71a160938ed0e8f2e567b042978792405.yml -openapi_spec_hash: d52bec73da0d689ecce7b95235fc6846 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-960cb623c7ec84bf4dc0f5945cbc19eec9cca48271071f400d96066eaa55dbd6.yml +openapi_spec_hash: 84fd39e3f4dc964bf0c32d4e95da1b34 config_hash: 2bea1743c84d63bd61f8501a6ea63065 From ef422160c4cfe9a82fa8a16d590959e4f413c876 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 08:30:44 +0000 Subject: [PATCH 099/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2601677..d0ab664 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.1.0" + ".": "1.2.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index a47345e..a9464c4 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.1.0" // x-release-please-version +const Version = "1.2.0" // x-release-please-version From 780615f07d2b4e942d07282a2da77cf4a7e54fe3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:16:50 +0000 Subject: [PATCH 100/154] feat(api): api update --- .stats.yml | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- pkg/cmd/batch.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.stats.yml b/.stats.yml index 33b7080..963533f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-960cb623c7ec84bf4dc0f5945cbc19eec9cca48271071f400d96066eaa55dbd6.yml -openapi_spec_hash: 84fd39e3f4dc964bf0c32d4e95da1b34 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-838f03b1c3584485eeded993459e6bbae058da9f6df16b7967980fbba98cc748.yml +openapi_spec_hash: 4a9db9cd9eac4ae4e2694b3d835a772f config_hash: 2bea1743c84d63bd61f8501a6ea63065 diff --git a/go.mod b/go.mod index 12f3f67..b627f73 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.5.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.6.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 2e31ee8..e08a61b 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.5.0 h1:FK79MDMznyABXAUjRGO44Xmvl6Bi0nz1HBSlwYyMU6U= -github.com/context-dot-dev/context-go-sdk/v2 v2.5.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.6.0 h1:Ek9DAp3uuXNZRKojMOf4Y6I11PHnXuQQFtvT4vi0BDE= +github.com/context-dot-dev/context-go-sdk/v2 v2.6.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/pkg/cmd/batch.go b/pkg/cmd/batch.go index d95a1ff..9bd5480 100644 --- a/pkg/cmd/batch.go +++ b/pkg/cmd/batch.go @@ -16,7 +16,7 @@ import ( var batchRetrieve = cli.Command{ Name: "retrieve", - Usage: "Check progress and get download links when the batch finishes. Also returns the\nrejected-URL list and webhook signing secret from submission, so nothing is lost\nif the submit response was dropped.", + Usage: "Check progress and get download links when the batch finishes. Also returns the\nrejected-URL list from submission. The webhook signing secret is not repeated\nhere — it is returned once, by the submit response.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ From 08724a68a9a528b5ae03da3c84bed88d0d384430 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:45:58 +0000 Subject: [PATCH 101/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 963533f..06846fb 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-838f03b1c3584485eeded993459e6bbae058da9f6df16b7967980fbba98cc748.yml -openapi_spec_hash: 4a9db9cd9eac4ae4e2694b3d835a772f +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-21a0195dcea548066fd6c227d634217b897900a6732a688e41c83344c2e92c94.yml +openapi_spec_hash: 388f5780dc9bf205c04b6a6214e4fafc config_hash: 2bea1743c84d63bd61f8501a6ea63065 From bb630a57e645750b309a4b864bb18e50b64ef22e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 1 Aug 2026 00:43:07 +0000 Subject: [PATCH 102/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/batch.go | 4 ++-- pkg/cmd/web.go | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.stats.yml b/.stats.yml index 06846fb..3b484e3 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-21a0195dcea548066fd6c227d634217b897900a6732a688e41c83344c2e92c94.yml -openapi_spec_hash: 388f5780dc9bf205c04b6a6214e4fafc +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-758c3a2fbd5b7be61c8e6e0ad2e6a5ec30695747bb675960d888c497647d13d7.yml +openapi_spec_hash: 00002d90bde02f67e174368ae470c597 config_hash: 2bea1743c84d63bd61f8501a6ea63065 diff --git a/pkg/cmd/batch.go b/pkg/cmd/batch.go index 9bd5480..74c4a5b 100644 --- a/pkg/cmd/batch.go +++ b/pkg/cmd/batch.go @@ -16,7 +16,7 @@ import ( var batchRetrieve = cli.Command{ Name: "retrieve", - Usage: "Check progress and get download links when the batch finishes. Also returns the\nrejected-URL list from submission. The webhook signing secret is not repeated\nhere — it is returned once, by the submit response.", + Usage: "Check progress, and get download links once the batch finishes.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ @@ -88,7 +88,7 @@ var batchCancel = cli.Command{ var batchGetResults = cli.Command{ Name: "get-results", - Usage: "Page through the result records of a finished batch as JSON, in the same order\nas the downloadable result files. Use this instead of downloading and parsing\nthe NDJSON files yourself.", + Usage: "Page through a finished batch's results as JSON instead of downloading the\nNDJSON files.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 483c012..9f5b105 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -247,7 +247,7 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[string]{ Name: "country", - Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", + Usage: "Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2).", QueryPath: "country", }, &requestflag.Flag[string]{ @@ -461,7 +461,7 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[string]{ Name: "country", - Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", + Usage: "Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2).", BodyPath: "country", }, &requestflag.Flag[[]string]{ @@ -617,7 +617,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[string]{ Name: "country", - Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", + Usage: "Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2).", QueryPath: "country", }, &requestflag.Flag[any]{ @@ -813,7 +813,7 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[string]{ Name: "country", - Usage: "Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country.", + Usage: "Fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2).", QueryPath: "country", }, &requestflag.Flag[any]{ From ae7f6f4bb38bf305fe251e5e4432e394d67c6c94 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 1 Aug 2026 01:03:05 +0000 Subject: [PATCH 103/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index d0ab664..2a8f4ff 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.2.0" + ".": "1.3.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index a9464c4..dcf0774 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.2.0" // x-release-please-version +const Version = "1.3.0" // x-release-please-version From 5f2a53a03d881c2f83d3f4cd194f69cf5f660b5c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 1 Aug 2026 23:36:49 +0000 Subject: [PATCH 104/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b627f73..349bddd 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.6.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.7.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index e08a61b..b30c4e4 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.6.0 h1:Ek9DAp3uuXNZRKojMOf4Y6I11PHnXuQQFtvT4vi0BDE= -github.com/context-dot-dev/context-go-sdk/v2 v2.6.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.7.0 h1:zc4xevss1ms1jge3wTn0qgynanmORhvFJav8eLfaiIY= +github.com/context-dot-dev/context-go-sdk/v2 v2.7.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From cf3da162b0208352e10dc4a8ee2a1de940c5a2f7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 1 Aug 2026 23:38:52 +0000 Subject: [PATCH 105/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 3b484e3..2aeac55 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-758c3a2fbd5b7be61c8e6e0ad2e6a5ec30695747bb675960d888c497647d13d7.yml -openapi_spec_hash: 00002d90bde02f67e174368ae470c597 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-85694668707cde32f7d8472660bc5760a2f369751d8cf19690778ffad767b0fa.yml +openapi_spec_hash: 5b688312bf5e9a5468a83618ec635ada config_hash: 2bea1743c84d63bd61f8501a6ea63065 From 7a5264668b64083b4f334e225980aa01f70e7676 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 2 Aug 2026 08:32:37 +0000 Subject: [PATCH 106/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 2aeac55..490472d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-85694668707cde32f7d8472660bc5760a2f369751d8cf19690778ffad767b0fa.yml -openapi_spec_hash: 5b688312bf5e9a5468a83618ec635ada +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-386f0ec51516e1f060c82287c99be4ecdee9eb4753e1375b6c5b27488e63d4c7.yml +openapi_spec_hash: b514ae48cf1c7bcb2ed3a4d7853cbfb5 config_hash: 2bea1743c84d63bd61f8501a6ea63065 From 3037cb0468fcd5790417981aac295ed661a2f312 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 03:23:51 +0000 Subject: [PATCH 107/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 490472d..790f64f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-386f0ec51516e1f060c82287c99be4ecdee9eb4753e1375b6c5b27488e63d4c7.yml -openapi_spec_hash: b514ae48cf1c7bcb2ed3a4d7853cbfb5 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-0c273d87106b3f8920d529d9964d7be6a23613c7553f48d67732e24571fbbf7b.yml +openapi_spec_hash: f1fb4082f153c9195fee451ebf5d46ba config_hash: 2bea1743c84d63bd61f8501a6ea63065 From b50326f6e82cbf95940143d501e803a842f14a34 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2026 08:41:10 +0000 Subject: [PATCH 108/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 790f64f..29f15de 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-0c273d87106b3f8920d529d9964d7be6a23613c7553f48d67732e24571fbbf7b.yml -openapi_spec_hash: f1fb4082f153c9195fee451ebf5d46ba +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-f2101addc171cf732a879e4bcad5bc6cfe8cec4349c62617c12c09331a883a22.yml +openapi_spec_hash: a143e7e4842279a61807b433ef17e261 config_hash: 2bea1743c84d63bd61f8501a6ea63065 From f61bea286379f89f98bb2897c16c99cc287c2632 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2026 09:40:49 +0000 Subject: [PATCH 109/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 29f15de..8e45986 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-f2101addc171cf732a879e4bcad5bc6cfe8cec4349c62617c12c09331a883a22.yml -openapi_spec_hash: a143e7e4842279a61807b433ef17e261 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-eac90d0a78d6166dc64c49ad4cd44883ab0bd357063ff09e60ed78085e2bde3c.yml +openapi_spec_hash: ab91f77e7c9d992400cbc7fc8a9e76c1 config_hash: 2bea1743c84d63bd61f8501a6ea63065 From 6bfb59d1025e98165955607950e9995d39a5055b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2026 10:12:49 +0000 Subject: [PATCH 110/154] feat(api): manual updates --- .stats.yml | 6 ++--- pkg/cmd/brand.go | 62 +++++++++++++++++++++++++++++++++++++++++++ pkg/cmd/brand_test.go | 14 ++++++++++ pkg/cmd/cmd.go | 1 + 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index 8e45986..74e73bc 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-eac90d0a78d6166dc64c49ad4cd44883ab0bd357063ff09e60ed78085e2bde3c.yml +configured_endpoints: 38 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-155e4761d62255841349c0f8a01b0a9c463ea1d1f2d6c4fd8d1a75c8bef6f226.yml openapi_spec_hash: ab91f77e7c9d992400cbc7fc8a9e76c1 -config_hash: 2bea1743c84d63bd61f8501a6ea63065 +config_hash: bff282047fafdad771fb7ec685f56944 diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index c90f30d..742bfe7 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -152,6 +152,27 @@ var brandRetrieveSimplified = cli.Command{ HideHelpCommand: true, } +var brandSearch = cli.Command{ + Name: "search", + Usage: "Search brands by name or domain and get back up to 10 lightweight matches\n(domain, name, logo), most popular first: by Tranco rank, then market cap for\nbrands outside the Tranco list, with text relevance breaking ties. Matching is\nprefix-based with no typo tolerance, so it is suited to autocomplete. Only\nbrands already in the Context.dev index are returned — use /brand/retrieve to\nfetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit\nper request on the Free and Starter plans.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "query", + Usage: "Search term, matched against brand names and domains by prefix (e.g. 'nike', 'nike.com', 'nik').", + Required: true, + QueryPath: "query", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", + QueryPath: "tags", + }, + }, + Action: handleBrandSearch, + HideHelpCommand: true, +} + func handleBrandRetrieve(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) unusedArgs := cmd.Args().Slice() @@ -233,3 +254,44 @@ func handleBrandRetrieveSimplified(ctx context.Context, cmd *cli.Command) error Transform: transform, }) } + +func handleBrandSearch(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + params := contextdev.BrandSearchParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Brand.Search(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "brand search", + Transform: transform, + }) +} diff --git a/pkg/cmd/brand_test.go b/pkg/cmd/brand_test.go index 55c691d..3a844ba 100644 --- a/pkg/cmd/brand_test.go +++ b/pkg/cmd/brand_test.go @@ -62,3 +62,17 @@ func TestBrandRetrieveSimplified(t *testing.T) { ) }) } + +func TestBrandSearch(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "brand", "search", + "--query", "x", + "--tag", "production", + "--tag", "team-alpha", + ) + }) +} diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index a90d921..4db4f54 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -126,6 +126,7 @@ func init() { Commands: []*cli.Command{ &brandRetrieve, &brandRetrieveSimplified, + &brandSearch, }, }, { From 62bf93b17e7c6c8f5dad8f019229f8f15aa7f31d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2026 10:21:28 +0000 Subject: [PATCH 111/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 2a8f4ff..3e9af1b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.3.0" + ".": "1.4.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index dcf0774..a2e6c7d 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.3.0" // x-release-please-version +const Version = "1.4.0" // x-release-please-version From ab1d2246c48e24b0786679ce5d5385ac47310d3b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:32:39 +0000 Subject: [PATCH 112/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 349bddd..a5e14f2 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.7.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.8.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index b30c4e4..738ff27 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.7.0 h1:zc4xevss1ms1jge3wTn0qgynanmORhvFJav8eLfaiIY= -github.com/context-dot-dev/context-go-sdk/v2 v2.7.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.8.0 h1:K7a/NQIXa4C3VLiF+1cCDyAMGIEnsva2CdkKaYqzC5Q= +github.com/context-dot-dev/context-go-sdk/v2 v2.8.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 2632b21bcf96d956ad41ba1374097ed6cb616eb2 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 5 Aug 2026 18:49:28 +0000 Subject: [PATCH 113/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 74e73bc..9ea03e0 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-155e4761d62255841349c0f8a01b0a9c463ea1d1f2d6c4fd8d1a75c8bef6f226.yml -openapi_spec_hash: ab91f77e7c9d992400cbc7fc8a9e76c1 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8a92cb064637006331b2910caedca8512290c1d8cc75eb91218393cc1581e59c.yml +openapi_spec_hash: c811ec47143ad01cdbcbd8324caa4eda config_hash: bff282047fafdad771fb7ec685f56944 From 29a0fab2a78dbdb1a3fe1d18146b34436a0514fa Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 03:09:13 +0000 Subject: [PATCH 114/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.stats.yml b/.stats.yml index 9ea03e0..9a1a53d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8a92cb064637006331b2910caedca8512290c1d8cc75eb91218393cc1581e59c.yml -openapi_spec_hash: c811ec47143ad01cdbcbd8324caa4eda +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e6a3365124af52952a85c8af5a09d6fdc02a686db7949985d0a6313dfad8dee5.yml +openapi_spec_hash: d7d0e17252f6f5665fb1698e37e09fe2 config_hash: bff282047fafdad771fb7ec685f56944 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 9f5b105..86de982 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -703,7 +703,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[any]{ Name: "pdf.should-parse", - Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned.", + Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned.", InnerField: "shouldParse", }, &requestflag.InnerFlag[int64]{ @@ -917,7 +917,7 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[any]{ Name: "pdf.should-parse", - Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 WEBSITE_ACCESS_ERROR is returned.", + Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned.", InnerField: "shouldParse", }, &requestflag.InnerFlag[int64]{ From 07f0a25068c45f9512f9c09808fb7732ce2582c4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 05:46:27 +0000 Subject: [PATCH 115/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/parse.go | 2 +- pkg/cmd/web.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.stats.yml b/.stats.yml index 9a1a53d..f57748b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e6a3365124af52952a85c8af5a09d6fdc02a686db7949985d0a6313dfad8dee5.yml -openapi_spec_hash: d7d0e17252f6f5665fb1698e37e09fe2 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-b73de7a5f87b3bed7d9e4259bd109cd62f4eb5f61fa082f31fc22d5bf8e69bcc.yml +openapi_spec_hash: 5dcb5ba9b8487329adc2f89eeb4df7c4 config_hash: bff282047fafdad771fb7ec685f56944 diff --git a/pkg/cmd/parse.go b/pkg/cmd/parse.go index 5403297..92f2356 100644 --- a/pkg/cmd/parse.go +++ b/pkg/cmd/parse.go @@ -51,7 +51,7 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[any]{ Name: "ocr", - Usage: "When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, all OCR is disabled, including the automatic scanned-PDF fallback.", + Usage: "When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, no OCR runs.", Default: false, QueryPath: "ocr", }, diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 86de982..a8c8e03 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -698,7 +698,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[any]{ Name: "pdf.ocr", - Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback.", + Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. When false, no OCR runs.", InnerField: "ocr", }, &requestflag.InnerFlag[any]{ @@ -912,7 +912,7 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[any]{ Name: "pdf.ocr", - Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback.", + Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. When false, no OCR runs.", InnerField: "ocr", }, &requestflag.InnerFlag[any]{ From 47e55c143a2fc917fbef75b1ce234b8d1b090f41 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 07:45:58 +0000 Subject: [PATCH 116/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 7 ++++++- pkg/cmd/web_test.go | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index f57748b..15a2673 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-b73de7a5f87b3bed7d9e4259bd109cd62f4eb5f61fa082f31fc22d5bf8e69bcc.yml -openapi_spec_hash: 5dcb5ba9b8487329adc2f89eeb4df7c4 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-b5a46cf886759797353b250da971e46cf66804b825ded9c51609f34d72d1169c.yml +openapi_spec_hash: 1947de2a731ddab05bfb781f37cd42b6 config_hash: bff282047fafdad771fb7ec685f56944 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index a8c8e03..7b1229e 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -930,7 +930,7 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ var webWebScrapeSitemap = cli.Command{ Name: "web-scrape-sitemap", - Usage: "Crawl an entire website's sitemap and return all discovered page URLs.", + Usage: "Crawl an entire website's sitemap and return all discovered page URLs. Pass\n`search` to have the crawled sitemap filtered down to the pages about a phrase\n(for example `pricing and plans` or `api authentication docs`), most relevant\nfirst — a searched crawl scans the whole sitemap and costs 2 credits instead\nof 1.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ @@ -950,6 +950,11 @@ var webWebScrapeSitemap = cli.Command{ Default: 10000, QueryPath: "maxLinks", }, + &requestflag.Flag[string]{ + Name: "search", + Usage: "Optional search phrase. When provided, the crawled sitemap is filtered to the pages whose URLs are about that phrase, most relevant first, and the request costs 2 credits instead of 1.", + QueryPath: "search", + }, &requestflag.Flag[string]{ Name: "sitemap-url", Usage: "Optional explicit sitemap URL. When provided, exactly this sitemap is crawled instead of discovering the domain's sitemaps.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 8eda947..3505637 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -583,6 +583,7 @@ func TestWebWebScrapeSitemap(t *testing.T) { "--domain", "xxx", "--headers", "{foo: J!}", "--max-links", "1", + "--search", "help center and troubleshooting articles", "--sitemap-url", "https://example.com", "--tag", "production", "--tag", "team-alpha", From ba24e2b113eb6d5243c63f6f84d25e64b9b825e6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 20:23:50 +0000 Subject: [PATCH 117/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/brand.go | 2 +- pkg/cmd/parse.go | 2 +- pkg/cmd/web.go | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.stats.yml b/.stats.yml index 15a2673..3eddd36 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-b5a46cf886759797353b250da971e46cf66804b825ded9c51609f34d72d1169c.yml -openapi_spec_hash: 1947de2a731ddab05bfb781f37cd42b6 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-3ecc6285243f60f7619d543cac59991015fbb0a156648741e7e42e619e0cbc5c.yml +openapi_spec_hash: 0130f29a501366c63cbd3a446c5eb109 config_hash: bff282047fafdad771fb7ec685f56944 diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index 742bfe7..ba05fd9 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -154,7 +154,7 @@ var brandRetrieveSimplified = cli.Command{ var brandSearch = cli.Command{ Name: "search", - Usage: "Search brands by name or domain and get back up to 10 lightweight matches\n(domain, name, logo), most popular first: by Tranco rank, then market cap for\nbrands outside the Tranco list, with text relevance breaking ties. Matching is\nprefix-based with no typo tolerance, so it is suited to autocomplete. Only\nbrands already in the Context.dev index are returned — use /brand/retrieve to\nfetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit\nper request on the Free and Starter plans.", + Usage: "Search brands by name or domain and get back up to 10 lightweight matches\n(domain, name, logo). Name matches rank ahead of domain matches; within each\ngroup the most popular brands come first: by Tranco rank, then market cap for\nbrands outside the Tranco list, with text relevance breaking ties. Matching is\nprefix-based with no typo tolerance, so it is suited to autocomplete. Only\nbrands already in the Context.dev index are returned — use /brand/retrieve to\nfetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit\nper request on the Free and Starter plans.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ diff --git a/pkg/cmd/parse.go b/pkg/cmd/parse.go index 92f2356..c047893 100644 --- a/pkg/cmd/parse.go +++ b/pkg/cmd/parse.go @@ -51,7 +51,7 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[any]{ Name: "ocr", - Usage: "When true for PDF inputs, detect and OCR images embedded in the selected pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. pdf.start/pdf.end limit the inclusive page range. When false, no OCR runs.", + Usage: "When true for PDF inputs, OCR the selected pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. pdf.start/pdf.end limit the inclusive page range. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs.", Default: false, QueryPath: "ocr", }, diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 7b1229e..04af894 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -583,7 +583,7 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[bool]{ Name: "pdf.ocr", - Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. This is separate from automatic scanned-PDF OCR fallback.", + Usage: "When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost.", InnerField: "ocr", }, &requestflag.InnerFlag[bool]{ @@ -698,7 +698,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[any]{ Name: "pdf.ocr", - Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. When false, no OCR runs.", + Usage: "When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs.", InnerField: "ocr", }, &requestflag.InnerFlag[any]{ @@ -912,7 +912,7 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.InnerFlag[any]{ Name: "pdf.ocr", - Usage: "When true, detect and OCR images embedded in the selected PDF pages, inserting recognized text at each image's position in page reading order while preserving the PDF text layer. When false, no OCR runs.", + Usage: "When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs.", InnerField: "ocr", }, &requestflag.InnerFlag[any]{ From ef7ba76a00614a1986714d69ad959991057cb189 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 23:35:59 +0000 Subject: [PATCH 118/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 3eddd36..2c6e57f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-3ecc6285243f60f7619d543cac59991015fbb0a156648741e7e42e619e0cbc5c.yml -openapi_spec_hash: 0130f29a501366c63cbd3a446c5eb109 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2f28cd1bf5b88305989d68dc55037fe25bdba2800d61c071a848cc1eb1ccb225.yml +openapi_spec_hash: 6dd2807c7804e08c1d49479c0ff82e47 config_hash: bff282047fafdad771fb7ec685f56944 From 6540b0bb5d22ea479cb4d346378ede1d0007d661 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2026 23:45:51 +0000 Subject: [PATCH 119/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 2c6e57f..b90c8da 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2f28cd1bf5b88305989d68dc55037fe25bdba2800d61c071a848cc1eb1ccb225.yml -openapi_spec_hash: 6dd2807c7804e08c1d49479c0ff82e47 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c1b6ca84f9bec1b1936cebb61f058924c3d7a5f6977e4cd76cf0544c4c7d8737.yml +openapi_spec_hash: 141bfa8430ddccfb5a37c4bd703d163b config_hash: bff282047fafdad771fb7ec685f56944 From c0c2e28ca68ec814f22089fa5ba6e6094bc62230 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 7 Aug 2026 00:28:32 +0000 Subject: [PATCH 120/154] feat(api): manual updates --- .stats.yml | 6 +- pkg/cmd/batch.go | 93 ++++++++++++++++++++----- pkg/cmd/batch_test.go | 78 ++++++++++++++------- pkg/cmd/cmd.go | 9 +++ pkg/cmd/person.go | 153 +++++++++++++++++++++++++++++++++++++++++ pkg/cmd/person_test.go | 92 +++++++++++++++++++++++++ 6 files changed, 383 insertions(+), 48 deletions(-) create mode 100644 pkg/cmd/person.go create mode 100644 pkg/cmd/person_test.go diff --git a/.stats.yml b/.stats.yml index b90c8da..ca57822 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 38 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c1b6ca84f9bec1b1936cebb61f058924c3d7a5f6977e4cd76cf0544c4c7d8737.yml +configured_endpoints: 40 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e2ba5381de3010ee53f27388aa6727ad567eb18e4b0b4eb1c4c66402bfea64cc.yml openapi_spec_hash: 141bfa8430ddccfb5a37c4bd703d163b -config_hash: bff282047fafdad771fb7ec685f56944 +config_hash: 920678668dd2da6f8966fbf1b8fde4e2 diff --git a/pkg/cmd/batch.go b/pkg/cmd/batch.go index 74c4a5b..1eff5c6 100644 --- a/pkg/cmd/batch.go +++ b/pkg/cmd/batch.go @@ -70,6 +70,22 @@ var batchList = cli.Command{ HideHelpCommand: true, } +var batchDelete = cli.Command{ + Name: "delete", + Usage: "Permanently delete a finished batch and its stored results. Active batches must\nsettle first.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "batch-id", + Usage: "ID of the batch to retrieve or cancel.", + Required: true, + PathParam: "batch_id", + }, + }, + Action: handleBatchDelete, + HideHelpCommand: true, +} + var batchCancel = cli.Command{ Name: "cancel", Usage: "Stop a batch from starting new pages. In-progress pages finish, and unused\ncredits are refunded.", @@ -112,39 +128,36 @@ var batchGetResults = cli.Command{ HideHelpCommand: true, } -var batchSubmit = requestflag.WithInnerFlags(cli.Command{ +var batchSubmit = cli.Command{ Name: "submit", - Usage: "Retrieve and normalize a person profile from identifiers.", + Usage: "Scrape 25K URLs or crawl large websites asynchronously.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[map[string]any]{ - Name: "identifiers", - Usage: "Known identifiers for the person. At least one identifier is required.", + Name: "input", + Usage: "Choose a URL list or a site crawl.", Required: true, - BodyPath: "identifiers", + BodyPath: "input", }, &requestflag.Flag[[]string]{ Name: "tag", - Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", + Usage: "Tags stored on the batch. Filter the batch list by them later.", BodyPath: "tags", }, - &requestflag.Flag[int64]{ - Name: "timeout-ms", - Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", - BodyPath: "timeoutMS", + &requestflag.Flag[string]{ + Name: "webhook-url", + Usage: "URL notified when the batch finishes.", + BodyPath: "webhookUrl", + }, + &requestflag.Flag[string]{ + Name: "idempotency-key", + Usage: "Any string unique to this submission. Retries with the same key return the original batch.", + HeaderPath: "Idempotency-Key", }, }, Action: handleBatchSubmit, HideHelpCommand: true, -}, map[string][]requestflag.HasOuterFlag{ - "identifiers": { - &requestflag.InnerFlag[string]{ - Name: "identifiers.linkedin-url", - Usage: "LinkedIn profile URL, e.g. https://www.linkedin.com/in/yahia-bakour/.", - InnerField: "linkedinUrl", - }, - }, -}) +} func handleBatchRetrieve(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) @@ -229,6 +242,48 @@ func handleBatchList(ctx context.Context, cmd *cli.Command) error { }) } +func handleBatchDelete(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("batch-id") && len(unusedArgs) > 0 { + cmd.Set("batch-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Batch.Delete(ctx, cmd.Value("batch-id").(string), options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "batch delete", + Transform: transform, + }) +} + func handleBatchCancel(ctx context.Context, cmd *cli.Command) error { client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) unusedArgs := cmd.Args().Slice() diff --git a/pkg/cmd/batch_test.go b/pkg/cmd/batch_test.go index a14073e..123f80d 100644 --- a/pkg/cmd/batch_test.go +++ b/pkg/cmd/batch_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/context-dot-dev/context-dev-cli/internal/mocktest" - "github.com/context-dot-dev/context-dev-cli/internal/requestflag" ) func TestBatchRetrieve(t *testing.T) { @@ -38,6 +37,18 @@ func TestBatchList(t *testing.T) { }) } +func TestBatchDelete(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "batch", "delete", + "--batch-id", "batch_9f2c8a", + ) + }) +} + func TestBatchCancel(t *testing.T) { t.Skip("Mock server tests are disabled") t.Run("regular flags", func(t *testing.T) { @@ -71,42 +82,57 @@ func TestBatchSubmit(t *testing.T) { t, "--api-key", "string", "batch", "submit", - "--identifiers", "{linkedinUrl: https://www.linkedin.com/in/yahia-bakour/}", - "--tag", "production", - "--tag", "team-alpha", - "--timeout-ms", "1000", - ) - }) - - t.Run("inner flags", func(t *testing.T) { - // Check that inner flags have been set up correctly - requestflag.CheckInnerFlags(batchSubmit) - - // Alternative argument passing style using inner flags - mocktest.TestRunMockTestWithFlags( - t, - "--api-key", "string", - "batch", "submit", - "--identifiers.linkedin-url", "https://www.linkedin.com/in/yahia-bakour/", - "--tag", "production", - "--tag", "team-alpha", - "--timeout-ms", "1000", + "--input", "{data: {format: markdown, urls: [{url: https://example.com/products/anvil, itemId: sku-1, meta: {category: bar}}, {url: https://example.com/products/hammer, itemId: sku-2, meta: {foo: bar}}], options: {country: de, excludeSelectors: [x], includeImages: true, includeLinks: true, includeSelectors: [x], maxAgeMs: 0, pdf: {end: 1, ocr: 'true', shouldParse: 'true', start: 1}, settleAnimations: true, shortenBase64Images: true, useMainContentOnly: true, waitForMs: 0}}, mode: scrape}", + "--tag", "docs", + "--tag", "competitor", + "--webhook-url", "webhookUrl", + "--idempotency-key", "Idempotency-Key", ) }) t.Run("piping data", func(t *testing.T) { // Test piping YAML data over stdin pipeData := []byte("" + - "identifiers:\n" + - " linkedinUrl: https://www.linkedin.com/in/yahia-bakour/\n" + + "input:\n" + + " data:\n" + + " format: markdown\n" + + " urls:\n" + + " - url: https://example.com/products/anvil\n" + + " itemId: sku-1\n" + + " meta:\n" + + " category: bar\n" + + " - url: https://example.com/products/hammer\n" + + " itemId: sku-2\n" + + " meta:\n" + + " foo: bar\n" + + " options:\n" + + " country: de\n" + + " excludeSelectors:\n" + + " - x\n" + + " includeImages: true\n" + + " includeLinks: true\n" + + " includeSelectors:\n" + + " - x\n" + + " maxAgeMs: 0\n" + + " pdf:\n" + + " end: 1\n" + + " ocr: 'true'\n" + + " shouldParse: 'true'\n" + + " start: 1\n" + + " settleAnimations: true\n" + + " shortenBase64Images: true\n" + + " useMainContentOnly: true\n" + + " waitForMs: 0\n" + + " mode: scrape\n" + "tags:\n" + - " - production\n" + - " - team-alpha\n" + - "timeoutMS: 1000\n") + " - docs\n" + + " - competitor\n" + + "webhookUrl: webhookUrl\n") mocktest.TestRunMockTestWithPipeAndFlags( t, pipeData, "--api-key", "string", "batch", "submit", + "--idempotency-key", "Idempotency-Key", ) }) } diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 4db4f54..c2f399f 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -173,11 +173,20 @@ func init() { Commands: []*cli.Command{ &batchRetrieve, &batchList, + &batchDelete, &batchCancel, &batchGetResults, &batchSubmit, }, }, + { + Name: "people", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &peopleEnrich, + }, + }, { Name: "@manpages", Usage: "Generate documentation for 'man'", diff --git a/pkg/cmd/person.go b/pkg/cmd/person.go new file mode 100644 index 0000000..a677477 --- /dev/null +++ b/pkg/cmd/person.go @@ -0,0 +1,153 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var peopleEnrich = requestflag.WithInnerFlags(cli.Command{ + Name: "enrich", + Usage: "Finds and normalizes the best available person candidate from additive identity\nclues, then assigns an identity match score from 0 to 100. Available on Pro and\nScale plans. Successful requests cost 20 credits. Disposable and free email\naddresses (like gmail.com, yahoo.com) will throw a 422 error.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[map[string]any]{ + Name: "company", + BodyPath: "company", + }, + &requestflag.Flag[[]map[string]any]{ + Name: "education", + BodyPath: "education", + }, + &requestflag.Flag[string]{ + Name: "email", + BodyPath: "email", + }, + &requestflag.Flag[map[string]any]{ + Name: "location", + BodyPath: "location", + }, + &requestflag.Flag[map[string]any]{ + Name: "name", + BodyPath: "name", + }, + &requestflag.Flag[[]string]{ + Name: "social-url", + BodyPath: "social_urls", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", + BodyPath: "tags", + }, + &requestflag.Flag[int64]{ + Name: "timeout-ms", + Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", + BodyPath: "timeoutMS", + }, + }, + Action: handlePeopleEnrich, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "company": { + &requestflag.InnerFlag[string]{ + Name: "company.domain", + InnerField: "domain", + }, + &requestflag.InnerFlag[string]{ + Name: "company.name", + InnerField: "name", + }, + }, + "education": { + &requestflag.InnerFlag[string]{ + Name: "education.degree", + InnerField: "degree", + }, + &requestflag.InnerFlag[string]{ + Name: "education.field-of-study", + InnerField: "field_of_study", + }, + &requestflag.InnerFlag[int64]{ + Name: "education.graduation-year", + InnerField: "graduation_year", + }, + &requestflag.InnerFlag[map[string]any]{ + Name: "education.institution", + InnerField: "institution", + }, + }, + "location": { + &requestflag.InnerFlag[string]{ + Name: "location.city", + InnerField: "city", + }, + &requestflag.InnerFlag[string]{ + Name: "location.country", + InnerField: "country", + }, + &requestflag.InnerFlag[string]{ + Name: "location.region", + InnerField: "region", + }, + }, + "name": { + &requestflag.InnerFlag[string]{ + Name: "name.first", + InnerField: "first", + }, + &requestflag.InnerFlag[string]{ + Name: "name.last", + InnerField: "last", + }, + }, +}) + +func handlePeopleEnrich(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.PersonEnrichParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.People.Enrich(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "people enrich", + Transform: transform, + }) +} diff --git a/pkg/cmd/person_test.go b/pkg/cmd/person_test.go new file mode 100644 index 0000000..2a1a4b1 --- /dev/null +++ b/pkg/cmd/person_test.go @@ -0,0 +1,92 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" +) + +func TestPeopleEnrich(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "people", "enrich", + "--company", "{domain: analyticalengines.example, name: Analytical Engines}", + "--education", "{degree: x, field_of_study: x, graduation_year: 1900, institution: {domain: x, name: x}}", + "--email", "dev@stainless.com", + "--location", "{city: x, country: x, region: x}", + "--name", "{first: Ada, last: Lovelace}", + "--social-url", "https://www.linkedin.com/in/ada-lovelace/", + "--tag", "production", + "--tag", "team-alpha", + "--timeout-ms", "1000", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(peopleEnrich) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "people", "enrich", + "--company.domain", "analyticalengines.example", + "--company.name", "Analytical Engines", + "--education.degree", "x", + "--education.field-of-study", "x", + "--education.graduation-year", "1900", + "--education.institution", "{domain: x, name: x}", + "--email", "dev@stainless.com", + "--location.city", "x", + "--location.country", "x", + "--location.region", "x", + "--name.first", "Ada", + "--name.last", "Lovelace", + "--social-url", "https://www.linkedin.com/in/ada-lovelace/", + "--tag", "production", + "--tag", "team-alpha", + "--timeout-ms", "1000", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "company:\n" + + " domain: analyticalengines.example\n" + + " name: Analytical Engines\n" + + "education:\n" + + " - degree: x\n" + + " field_of_study: x\n" + + " graduation_year: 1900\n" + + " institution:\n" + + " domain: x\n" + + " name: x\n" + + "email: dev@stainless.com\n" + + "location:\n" + + " city: x\n" + + " country: x\n" + + " region: x\n" + + "name:\n" + + " first: Ada\n" + + " last: Lovelace\n" + + "social_urls:\n" + + " - https://www.linkedin.com/in/ada-lovelace/\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n" + + "timeoutMS: 1000\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "people", "enrich", + ) + }) +} From 816543606b5172240e53f2ebae0d3a23d5d72f7e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 7 Aug 2026 01:03:17 +0000 Subject: [PATCH 121/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/person.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index ca57822..97db86d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-e2ba5381de3010ee53f27388aa6727ad567eb18e4b0b4eb1c4c66402bfea64cc.yml -openapi_spec_hash: 141bfa8430ddccfb5a37c4bd703d163b +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a0dda03bbb600917cfb9add468cc4c8c84351a8dbbf61644dbc353263ca1748f.yml +openapi_spec_hash: c24264f32a46d9317aac5af9d6a396f7 config_hash: 920678668dd2da6f8966fbf1b8fde4e2 diff --git a/pkg/cmd/person.go b/pkg/cmd/person.go index a677477..efc6e30 100644 --- a/pkg/cmd/person.go +++ b/pkg/cmd/person.go @@ -16,7 +16,7 @@ import ( var peopleEnrich = requestflag.WithInnerFlags(cli.Command{ Name: "enrich", - Usage: "Finds and normalizes the best available person candidate from additive identity\nclues, then assigns an identity match score from 0 to 100. Available on Pro and\nScale plans. Successful requests cost 20 credits. Disposable and free email\naddresses (like gmail.com, yahoo.com) will throw a 422 error.", + Usage: "Finds and normalizes the best available person candidate from additive identity\nclues, then assigns an identity match score from 0 to 100. Available on all paid\nplans. Successful requests cost 20 credits. Disposable and free email addresses\n(like gmail.com, yahoo.com) will throw a 422 error.", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[map[string]any]{ From a531ffcfb2a4f2a84fbd011448a2740ce2fe4114 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 7 Aug 2026 01:15:49 +0000 Subject: [PATCH 122/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 3e9af1b..fbd9082 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.4.0" + ".": "1.5.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index a2e6c7d..cf77cd0 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.4.0" // x-release-please-version +const Version = "1.5.0" // x-release-please-version From c2508534d81dba1d1b2b6dbab607a04be718636e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 7 Aug 2026 21:18:24 +0000 Subject: [PATCH 123/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a5e14f2..63f9b32 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.8.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.9.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 738ff27..3554fa9 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.8.0 h1:K7a/NQIXa4C3VLiF+1cCDyAMGIEnsva2CdkKaYqzC5Q= -github.com/context-dot-dev/context-go-sdk/v2 v2.8.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.9.0 h1:Lv27NRJ1PyQF9QKNjMLYvrc1uRKaBjFD3sj7YHOnGgw= +github.com/context-dot-dev/context-go-sdk/v2 v2.9.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 3382e8a61d98622cc45fc4bc2a9504a7c5444712 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 8 Aug 2026 06:57:09 +0000 Subject: [PATCH 124/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 97db86d..90b5514 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a0dda03bbb600917cfb9add468cc4c8c84351a8dbbf61644dbc353263ca1748f.yml -openapi_spec_hash: c24264f32a46d9317aac5af9d6a396f7 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-1c93116e47cab52ea63490f5bca186ed3acda8bbd7f0ce5a320effb9f5b72b1f.yml +openapi_spec_hash: f56204d55bd4bffb6e4d50d6a5d9471a config_hash: 920678668dd2da6f8966fbf1b8fde4e2 From be5868b99792822e51e7807fbfa047563e2ac080 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 10 Aug 2026 09:04:48 +0000 Subject: [PATCH 125/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/batch_test.go | 3 ++- pkg/cmd/utility.go | 6 +++--- pkg/cmd/web.go | 6 ++++++ pkg/cmd/web_test.go | 2 ++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.stats.yml b/.stats.yml index 90b5514..f9b95cb 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-1c93116e47cab52ea63490f5bca186ed3acda8bbd7f0ce5a320effb9f5b72b1f.yml -openapi_spec_hash: f56204d55bd4bffb6e4d50d6a5d9471a +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-7f75f39699c1298d16691b5a58b1312a229b78288fba6e2de4040ba1422e530f.yml +openapi_spec_hash: b3ad781596e4c52fde918cfaae54a5d4 config_hash: 920678668dd2da6f8966fbf1b8fde4e2 diff --git a/pkg/cmd/batch_test.go b/pkg/cmd/batch_test.go index 123f80d..bbafe6f 100644 --- a/pkg/cmd/batch_test.go +++ b/pkg/cmd/batch_test.go @@ -82,7 +82,7 @@ func TestBatchSubmit(t *testing.T) { t, "--api-key", "string", "batch", "submit", - "--input", "{data: {format: markdown, urls: [{url: https://example.com/products/anvil, itemId: sku-1, meta: {category: bar}}, {url: https://example.com/products/hammer, itemId: sku-2, meta: {foo: bar}}], options: {country: de, excludeSelectors: [x], includeImages: true, includeLinks: true, includeSelectors: [x], maxAgeMs: 0, pdf: {end: 1, ocr: 'true', shouldParse: 'true', start: 1}, settleAnimations: true, shortenBase64Images: true, useMainContentOnly: true, waitForMs: 0}}, mode: scrape}", + "--input", "{data: {format: markdown, urls: [{url: https://example.com/products/anvil, itemId: sku-1, meta: {category: bar}}, {url: https://example.com/products/hammer, itemId: sku-2, meta: {foo: bar}}], options: {country: de, excludeSelectors: [x], includeHTML: true, includeImages: true, includeLinks: true, includeSelectors: [x], maxAgeMs: 0, pdf: {end: 1, ocr: 'true', shouldParse: 'true', start: 1}, settleAnimations: true, shortenBase64Images: true, useMainContentOnly: true, waitForMs: 0}}, mode: scrape}", "--tag", "docs", "--tag", "competitor", "--webhook-url", "webhookUrl", @@ -109,6 +109,7 @@ func TestBatchSubmit(t *testing.T) { " country: de\n" + " excludeSelectors:\n" + " - x\n" + + " includeHTML: true\n" + " includeImages: true\n" + " includeLinks: true\n" + " includeSelectors:\n" + diff --git a/pkg/cmd/utility.go b/pkg/cmd/utility.go index 5376d1b..4173edf 100644 --- a/pkg/cmd/utility.go +++ b/pkg/cmd/utility.go @@ -16,18 +16,18 @@ import ( var utilityPrefetch = cli.Command{ Name: "prefetch", - Usage: "Signal that you may fetch brand data soon to improve latency. The type field\nselects what to prefetch (currently only 'brand') and identifier carries exactly\none lookup key: a domain, or an email whose domain is extracted and validated\n(free email providers and disposable email addresses are not allowed).", + Usage: "Signal that you may fetch data soon to improve latency. The type field selects\nwhat to prefetch ('brand' queues a brand data fetch, 'styleguide' queues a\nstyleguide extraction) and identifier carries exactly one lookup key: a domain,\nor an email whose domain is extracted and validated (free email providers and\ndisposable email addresses are not allowed).", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[map[string]any]{ Name: "identifier", - Usage: "Identifier of the brand to prefetch. Provide exactly one of domain or email.", + Usage: "Identifier of the target to prefetch. Provide exactly one of domain or email.", Required: true, BodyPath: "identifier", }, &requestflag.Flag[string]{ Name: "type", - Usage: "What to prefetch. Currently only 'brand' is supported.", + Usage: "What to prefetch: 'brand' warms the brand data cache, 'styleguide' warms the styleguide cache.", Required: true, BodyPath: "type", }, diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 04af894..4db1274 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -832,6 +832,12 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Default: false, QueryPath: "includeFrames", }, + &requestflag.Flag[any]{ + Name: "include-html", + Usage: "When true, the response also includes an `html` field with the page HTML the Markdown was converted from — the same body the Scrape HTML endpoint returns for the equivalent request.", + Default: false, + QueryPath: "includeHTML", + }, &requestflag.Flag[any]{ Name: "include-images", Usage: "Include image references in Markdown output", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 3505637..0c173b3 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -522,6 +522,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--exclude-selector", "[x]", "--headers", "{foo: J!}", "--include-frames", "'true'", + "--include-html", "'true'", "--include-images", "'true'", "--include-links", "'true'", "--include-selector", "[x]", @@ -553,6 +554,7 @@ func TestWebWebScrapeMd(t *testing.T) { "--exclude-selector", "[x]", "--headers", "{foo: J!}", "--include-frames", "'true'", + "--include-html", "'true'", "--include-images", "'true'", "--include-links", "'true'", "--include-selector", "[x]", From c80a4e5b00ff0067d37a16409280fe4def45d078 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 11 Aug 2026 07:47:15 +0000 Subject: [PATCH 126/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index f9b95cb..0829be8 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-7f75f39699c1298d16691b5a58b1312a229b78288fba6e2de4040ba1422e530f.yml -openapi_spec_hash: b3ad781596e4c52fde918cfaae54a5d4 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5a88256ce88b7bc7854211e67446bc71bc52975a2d62263e1194bec7cf6c2f16.yml +openapi_spec_hash: f5011cea07c6c4a7d2984d6be85ffe49 config_hash: 920678668dd2da6f8966fbf1b8fde4e2 From d156e6495a3012005dc2036b959fc85a7474b0c3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 12 Aug 2026 09:21:28 +0000 Subject: [PATCH 127/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 0829be8..9ed440e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5a88256ce88b7bc7854211e67446bc71bc52975a2d62263e1194bec7cf6c2f16.yml -openapi_spec_hash: f5011cea07c6c4a7d2984d6be85ffe49 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c0a0223a614d6793c76c77cb5443276adf09ffa1a4d6761aae240d30a65d71e6.yml +openapi_spec_hash: 1aa54f261fd2238035711a73618c51cd config_hash: 920678668dd2da6f8966fbf1b8fde4e2 From aa9059fd80a503b93a0489dcf3ce241028c880eb Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 12 Aug 2026 20:44:07 +0000 Subject: [PATCH 128/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 9ed440e..3f88b9d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c0a0223a614d6793c76c77cb5443276adf09ffa1a4d6761aae240d30a65d71e6.yml -openapi_spec_hash: 1aa54f261fd2238035711a73618c51cd +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-662e436bab5a74933ca1d08ac370c34ef632285b7aec23d95b1b442b2291d589.yml +openapi_spec_hash: 34399fa7028ac361abee1a0a4f139093 config_hash: 920678668dd2da6f8966fbf1b8fde4e2 From 7390012b2bdc07767ba6f3d90d21e1d78e08371d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 13 Aug 2026 20:44:19 +0000 Subject: [PATCH 129/154] feat(api): api update --- .stats.yml | 4 +-- pkg/cmd/batch_test.go | 6 ++-- pkg/cmd/parse.go | 10 +++---- pkg/cmd/parse_test.go | 30 +++++++++---------- pkg/cmd/web.go | 38 ++++++++++++------------ pkg/cmd/web_test.go | 68 +++++++++++++++++++++---------------------- 6 files changed, 78 insertions(+), 78 deletions(-) diff --git a/.stats.yml b/.stats.yml index 3f88b9d..ef63af1 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-662e436bab5a74933ca1d08ac370c34ef632285b7aec23d95b1b442b2291d589.yml -openapi_spec_hash: 34399fa7028ac361abee1a0a4f139093 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d31d405927ec58ac97c0a9732130aea18209c65a0f2f0a348aa91c333535305e.yml +openapi_spec_hash: 0ede81f7fd98f41bc6bbc4167300bfb9 config_hash: 920678668dd2da6f8966fbf1b8fde4e2 diff --git a/pkg/cmd/batch_test.go b/pkg/cmd/batch_test.go index bbafe6f..82a5e97 100644 --- a/pkg/cmd/batch_test.go +++ b/pkg/cmd/batch_test.go @@ -82,7 +82,7 @@ func TestBatchSubmit(t *testing.T) { t, "--api-key", "string", "batch", "submit", - "--input", "{data: {format: markdown, urls: [{url: https://example.com/products/anvil, itemId: sku-1, meta: {category: bar}}, {url: https://example.com/products/hammer, itemId: sku-2, meta: {foo: bar}}], options: {country: de, excludeSelectors: [x], includeHTML: true, includeImages: true, includeLinks: true, includeSelectors: [x], maxAgeMs: 0, pdf: {end: 1, ocr: 'true', shouldParse: 'true', start: 1}, settleAnimations: true, shortenBase64Images: true, useMainContentOnly: true, waitForMs: 0}}, mode: scrape}", + "--input", "{data: {format: markdown, urls: [{url: https://example.com/products/anvil, itemId: sku-1, meta: {category: bar}}, {url: https://example.com/products/hammer, itemId: sku-2, meta: {foo: bar}}], options: {country: de, excludeSelectors: [x], includeHTML: true, includeImages: true, includeLinks: true, includeSelectors: [x], maxAgeMs: 0, pdf: {end: 1, ocr: true, shouldParse: true, start: 1}, settleAnimations: true, shortenBase64Images: true, useMainContentOnly: true, waitForMs: 0}}, mode: scrape}", "--tag", "docs", "--tag", "competitor", "--webhook-url", "webhookUrl", @@ -117,8 +117,8 @@ func TestBatchSubmit(t *testing.T) { " maxAgeMs: 0\n" + " pdf:\n" + " end: 1\n" + - " ocr: 'true'\n" + - " shouldParse: 'true'\n" + + " ocr: true\n" + + " shouldParse: true\n" + " start: 1\n" + " settleAnimations: true\n" + " shortenBase64Images: true\n" + diff --git a/pkg/cmd/parse.go b/pkg/cmd/parse.go index c047893..7f53188 100644 --- a/pkg/cmd/parse.go +++ b/pkg/cmd/parse.go @@ -37,19 +37,19 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional file extension hint, such as pdf, docx, xlsx, pptx, html, json, csv, md, py, rtf, jpg, png, or txt.", QueryPath: "extension", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "include-images", Usage: "Include image references in Markdown output", Default: false, QueryPath: "includeImages", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "include-links", Usage: "Preserve hyperlinks in Markdown output", Default: true, QueryPath: "includeLinks", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "ocr", Usage: "When true for PDF inputs, OCR the selected pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. pdf.start/pdf.end limit the inclusive page range. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs.", Default: false, @@ -61,7 +61,7 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{}, QueryPath: "pdf", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "shorten-base64-images", Usage: "Shorten base64-encoded image data in the Markdown output", Default: true, @@ -72,7 +72,7 @@ var parseHandle = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", QueryPath: "tags", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "use-main-content-only", Usage: "Extract only the main content from HTML-like inputs", Default: false, diff --git a/pkg/cmd/parse_test.go b/pkg/cmd/parse_test.go index 8177b5d..fd11604 100644 --- a/pkg/cmd/parse_test.go +++ b/pkg/cmd/parse_test.go @@ -19,14 +19,14 @@ func TestParseHandle(t *testing.T) { "--body", mocktest.TestFile(t, "Example data"), "--client", "x", "--extension", "txt", - "--include-images", "'true'", - "--include-links", "'true'", - "--ocr", "'true'", + "--include-images=true", + "--include-links=true", + "--ocr=true", "--pdf", "{end: 1, start: 1}", - "--shorten-base64-images", "'true'", + "--shorten-base64-images=true", "--tag", "production", "--tag", "team-alpha", - "--use-main-content-only", "'true'", + "--use-main-content-only=true", "--zdr", "enabled", ) }) @@ -43,15 +43,15 @@ func TestParseHandle(t *testing.T) { "--body", mocktest.TestFile(t, "Example data"), "--client", "x", "--extension", "txt", - "--include-images", "'true'", - "--include-links", "'true'", - "--ocr", "'true'", + "--include-images=true", + "--include-links=true", + "--ocr=true", "--pdf.end", "1", "--pdf.start", "1", - "--shorten-base64-images", "'true'", + "--shorten-base64-images=true", "--tag", "production", "--tag", "team-alpha", - "--use-main-content-only", "'true'", + "--use-main-content-only=true", "--zdr", "enabled", ) }) @@ -65,14 +65,14 @@ func TestParseHandle(t *testing.T) { "parse", "handle", "--client", "x", "--extension", "txt", - "--include-images", "'true'", - "--include-links", "'true'", - "--ocr", "'true'", + "--include-images=true", + "--include-links=true", + "--ocr=true", "--pdf", "{end: 1, start: 1}", - "--shorten-base64-images", "'true'", + "--shorten-base64-images=true", "--tag", "production", "--tag", "team-alpha", - "--use-main-content-only", "'true'", + "--use-main-content-only=true", "--zdr", "enabled", ) }) diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 4db1274..52420fa 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -265,7 +265,7 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view).", QueryPath: "fullScreenshot", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "handle-cookie-popup", Usage: "Optional parameter to control cookie/consent popup handling. If 'true', we dismiss cookie banner before capture. If 'false' or not provided, captures the page without that step.", Default: false, @@ -630,7 +630,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", QueryPath: "headers", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "include-frames", Usage: "When true, iframes are rendered inline into the returned HTML.", Default: false, @@ -653,7 +653,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"shouldParse": true, "ocr": false}, QueryPath: "pdf", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "settle-animations", Usage: "When true, waits briefly for CSS and transition animations to settle before extracting HTML. Defaults to false. This adds a bit of latency in exchange for more stable output on animated pages.", Default: false, @@ -669,7 +669,7 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", QueryPath: "timeoutMS", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "use-main-content-only", Usage: "When true, return only the page's main content in the HTML response, excluding headers, footers, sidebars, and navigation when detectable.", Default: false, @@ -696,12 +696,12 @@ var webWebScrapeHTML = requestflag.WithInnerFlags(cli.Command{ Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", InnerField: "end", }, - &requestflag.InnerFlag[any]{ + &requestflag.InnerFlag[bool]{ Name: "pdf.ocr", Usage: "When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs.", InnerField: "ocr", }, - &requestflag.InnerFlag[any]{ + &requestflag.InnerFlag[bool]{ Name: "pdf.should-parse", Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned.", InnerField: "shouldParse", @@ -730,7 +730,7 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional browser actions executed in array order after the page loads and before content is captured. Requires a paid plan. Send a JSON array in the query parameter. Maximum: 5 actions.", QueryPath: "actions", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "dedupe", Usage: "When true, visually duplicate images are removed: every image is loaded and perceptually hashed, and only the highest-resolution copy of each duplicate group is kept. Images that cannot be downloaded or hashed are kept. Default: false.", Default: false, @@ -772,12 +772,12 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ HideHelpCommand: true, }, map[string][]requestflag.HasOuterFlag{ "enrichment": { - &requestflag.InnerFlag[any]{ + &requestflag.InnerFlag[bool]{ Name: "enrichment.classification", Usage: "Classify each image by visual asset type.", InnerField: "classification", }, - &requestflag.InnerFlag[any]{ + &requestflag.InnerFlag[bool]{ Name: "enrichment.hosted-url", Usage: "Host materializable images on the Brand.dev CDN and return their URL and MIME type.", InnerField: "hostedUrl", @@ -787,7 +787,7 @@ var webWebScrapeImages = requestflag.WithInnerFlags(cli.Command{ Usage: "Per-image enrichment timeout in milliseconds. Default: 30000. Maximum: 60000.", InnerField: "maxTimePerMs", }, - &requestflag.InnerFlag[any]{ + &requestflag.InnerFlag[bool]{ Name: "enrichment.resolution", Usage: "Measure image width and height when possible.", InnerField: "resolution", @@ -826,25 +826,25 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache.", QueryPath: "headers", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "include-frames", Usage: "When true, the contents of iframes are rendered to Markdown.", Default: false, QueryPath: "includeFrames", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "include-html", Usage: "When true, the response also includes an `html` field with the page HTML the Markdown was converted from — the same body the Scrape HTML endpoint returns for the equivalent request.", Default: false, QueryPath: "includeHTML", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "include-images", Usage: "Include image references in Markdown output", Default: false, QueryPath: "includeImages", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "include-links", Usage: "Preserve hyperlinks in Markdown output", Default: true, @@ -867,13 +867,13 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Default: map[string]any{"shouldParse": true, "ocr": false}, QueryPath: "pdf", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "settle-animations", Usage: "When true, waits briefly for CSS and transition animations to settle before converting to Markdown. Defaults to false. This adds a bit of latency in exchange for more stable output on animated pages.", Default: false, QueryPath: "settleAnimations", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "shorten-base64-images", Usage: "Shorten base64-encoded image data in the Markdown output", Default: true, @@ -889,7 +889,7 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes).", QueryPath: "timeoutMS", }, - &requestflag.Flag[any]{ + &requestflag.Flag[bool]{ Name: "use-main-content-only", Usage: "Extract only the main content of the page, excluding headers, footers, sidebars, and navigation", Default: false, @@ -916,12 +916,12 @@ var webWebScrapeMd = requestflag.WithInnerFlags(cli.Command{ Usage: "Last 1-based PDF page to parse. When omitted, parsing ends at the last page. Must be greater than or equal to start when both are provided.", InnerField: "end", }, - &requestflag.InnerFlag[any]{ + &requestflag.InnerFlag[bool]{ Name: "pdf.ocr", Usage: "When true, OCR the selected PDF pages that have no usable text layer (scans), replacing each recovered page's text with the OCR result while pages with a real text layer keep it. Billed at 1 credit per page OCR actually recovered, on top of the base request cost. When false, no OCR runs.", InnerField: "ocr", }, - &requestflag.InnerFlag[any]{ + &requestflag.InnerFlag[bool]{ Name: "pdf.should-parse", Usage: "When true, PDF URLs are fetched and parsed. When false, PDF URLs are skipped and a 400 PDF_SKIPPED is returned.", InnerField: "shouldParse", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 0c173b3..7c6cf11 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -163,7 +163,7 @@ func TestWebScreenshot(t *testing.T) { "--direct-url", "https://example.com", "--domain", "xxx", "--full-screenshot", "true", - "--handle-cookie-popup", "'true'", + "--handle-cookie-popup=true", "--max-age-ms", "0", "--page", "login", "--scroll-offset", "0", @@ -190,7 +190,7 @@ func TestWebScreenshot(t *testing.T) { "--direct-url", "https://example.com", "--domain", "xxx", "--full-screenshot", "true", - "--handle-cookie-popup", "'true'", + "--handle-cookie-popup=true", "--max-age-ms", "0", "--page", "login", "--scroll-offset", "0", @@ -417,15 +417,15 @@ func TestWebWebScrapeHTML(t *testing.T) { "--country", "de", "--exclude-selector", "[x]", "--headers", "{foo: J!}", - "--include-frames", "'true'", + "--include-frames=true", "--include-selector", "[x]", "--max-age-ms", "0", - "--pdf", "{end: 1, ocr: 'true', shouldParse: 'true', start: 1}", - "--settle-animations", "'true'", + "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", + "--settle-animations=true", "--tag", "production", "--tag", "team-alpha", "--timeout-ms", "1", - "--use-main-content-only", "'true'", + "--use-main-content-only=true", "--wait-for-ms", "0", "--zdr", "enabled", ) @@ -445,18 +445,18 @@ func TestWebWebScrapeHTML(t *testing.T) { "--country", "de", "--exclude-selector", "[x]", "--headers", "{foo: J!}", - "--include-frames", "'true'", + "--include-frames=true", "--include-selector", "[x]", "--max-age-ms", "0", "--pdf.end", "1", - "--pdf.ocr", "true", - "--pdf.should-parse", "true", + "--pdf.ocr=true", + "--pdf.should-parse=true", "--pdf.start", "1", - "--settle-animations", "'true'", + "--settle-animations=true", "--tag", "production", "--tag", "team-alpha", "--timeout-ms", "1", - "--use-main-content-only", "'true'", + "--use-main-content-only=true", "--wait-for-ms", "0", "--zdr", "enabled", ) @@ -472,8 +472,8 @@ func TestWebWebScrapeImages(t *testing.T) { "web", "web-scrape-images", "--url", "https://example.com", "--action", "[{do: wait, timeMs: 0}]", - "--dedupe", "'true'", - "--enrichment", "{classification: 'true', hostedUrl: 'true', maxTimePerMs: 1, resolution: 'true'}", + "--dedupe=true", + "--enrichment", "{classification: true, hostedUrl: true, maxTimePerMs: 1, resolution: true}", "--headers", "{foo: J!}", "--max-age-ms", "0", "--tag", "production", @@ -494,11 +494,11 @@ func TestWebWebScrapeImages(t *testing.T) { "web", "web-scrape-images", "--url", "https://example.com", "--action", "[{do: wait, timeMs: 0}]", - "--dedupe", "'true'", - "--enrichment.classification", "true", - "--enrichment.hosted-url", "true", + "--dedupe=true", + "--enrichment.classification=true", + "--enrichment.hosted-url=true", "--enrichment.max-time-per-ms", "1", - "--enrichment.resolution", "true", + "--enrichment.resolution=true", "--headers", "{foo: J!}", "--max-age-ms", "0", "--tag", "production", @@ -521,19 +521,19 @@ func TestWebWebScrapeMd(t *testing.T) { "--country", "de", "--exclude-selector", "[x]", "--headers", "{foo: J!}", - "--include-frames", "'true'", - "--include-html", "'true'", - "--include-images", "'true'", - "--include-links", "'true'", + "--include-frames=true", + "--include-html=true", + "--include-images=true", + "--include-links=true", "--include-selector", "[x]", "--max-age-ms", "0", - "--pdf", "{end: 1, ocr: 'true', shouldParse: 'true', start: 1}", - "--settle-animations", "'true'", - "--shorten-base64-images", "'true'", + "--pdf", "{end: 1, ocr: true, shouldParse: true, start: 1}", + "--settle-animations=true", + "--shorten-base64-images=true", "--tag", "production", "--tag", "team-alpha", "--timeout-ms", "1", - "--use-main-content-only", "'true'", + "--use-main-content-only=true", "--wait-for-ms", "0", "--zdr", "enabled", ) @@ -553,22 +553,22 @@ func TestWebWebScrapeMd(t *testing.T) { "--country", "de", "--exclude-selector", "[x]", "--headers", "{foo: J!}", - "--include-frames", "'true'", - "--include-html", "'true'", - "--include-images", "'true'", - "--include-links", "'true'", + "--include-frames=true", + "--include-html=true", + "--include-images=true", + "--include-links=true", "--include-selector", "[x]", "--max-age-ms", "0", "--pdf.end", "1", - "--pdf.ocr", "true", - "--pdf.should-parse", "true", + "--pdf.ocr=true", + "--pdf.should-parse=true", "--pdf.start", "1", - "--settle-animations", "'true'", - "--shorten-base64-images", "'true'", + "--settle-animations=true", + "--shorten-base64-images=true", "--tag", "production", "--tag", "team-alpha", "--timeout-ms", "1", - "--use-main-content-only", "'true'", + "--use-main-content-only=true", "--wait-for-ms", "0", "--zdr", "enabled", ) From 0d2e4449a35353c3f08b1fbc89f0d007481fa136 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2026 01:59:50 +0000 Subject: [PATCH 130/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index ef63af1..f194dd9 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d31d405927ec58ac97c0a9732130aea18209c65a0f2f0a348aa91c333535305e.yml -openapi_spec_hash: 0ede81f7fd98f41bc6bbc4167300bfb9 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-01745494602c4845bf7cf84a8f7449d8e53546eb096e3aa6949b89b452c5c90e.yml +openapi_spec_hash: dd4856e9595fab7a4aaa32a040c3060c config_hash: 920678668dd2da6f8966fbf1b8fde4e2 From 45cfdef812cca7f7b7b49a0a6cd41d825fcb059c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 15:49:12 +0000 Subject: [PATCH 131/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index f194dd9..2039ac3 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-01745494602c4845bf7cf84a8f7449d8e53546eb096e3aa6949b89b452c5c90e.yml -openapi_spec_hash: dd4856e9595fab7a4aaa32a040c3060c +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c99300223257d60d7614e76585c62cfea40f43df0547db63c952b20c52f209f4.yml +openapi_spec_hash: 1d4e473f3c566b7a1c3def11b6d84fe0 config_hash: 920678668dd2da6f8966fbf1b8fde4e2 From 98847ded33b187b8e08eb385d95a38010842c7c4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 03:53:03 +0000 Subject: [PATCH 132/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/brand.go | 22 ++++++++++++++++++++-- pkg/cmd/brand_test.go | 3 +++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.stats.yml b/.stats.yml index 2039ac3..983602e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-c99300223257d60d7614e76585c62cfea40f43df0547db63c952b20c52f209f4.yml -openapi_spec_hash: 1d4e473f3c566b7a1c3def11b6d84fe0 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4f279e7b1f0a52f5c917d4256e17188dfe330ddf7495146e2b1611e812605fdc.yml +openapi_spec_hash: 53a74c4cccbdec8590db38183840a446 config_hash: 920678668dd2da6f8966fbf1b8fde4e2 diff --git a/pkg/cmd/brand.go b/pkg/cmd/brand.go index ba05fd9..249d26f 100644 --- a/pkg/cmd/brand.go +++ b/pkg/cmd/brand.go @@ -154,20 +154,38 @@ var brandRetrieveSimplified = cli.Command{ var brandSearch = cli.Command{ Name: "search", - Usage: "Search brands by name or domain and get back up to 10 lightweight matches\n(domain, name, logo). Name matches rank ahead of domain matches; within each\ngroup the most popular brands come first: by Tranco rank, then market cap for\nbrands outside the Tranco list, with text relevance breaking ties. Matching is\nprefix-based with no typo tolerance, so it is suited to autocomplete. Only\nbrands already in the Context.dev index are returned — use /brand/retrieve to\nfetch (and index) a specific domain. Free on Pro and Scale plans; costs 1 credit\nper request on the Free and Starter plans.", + Usage: "Search indexed brands by name or domain", Suggest: true, Flags: []cli.Flag{ &requestflag.Flag[string]{ Name: "query", - Usage: "Search term, matched against brand names and domains by prefix (e.g. 'nike', 'nike.com', 'nik').", + Usage: "Search term, matched against the fields selected by queryBy (e.g. 'nike', 'nike.com', 'nik').", Required: true, QueryPath: "query", }, + &requestflag.Flag[bool]{ + Name: "autocomplete", + Usage: "Whether the search term matches by prefix, so partial words match as they are typed (e.g. 'nik' matches Nike). Set to false to match whole words only.", + Default: true, + QueryPath: "autocomplete", + }, + &requestflag.Flag[[]string]{ + Name: "query-by", + Usage: "Fields to match the search term against, as a comma-separated list or repeated parameter: 'name', 'domain', or both. Defaults to both.", + Default: []string{"name", "domain"}, + QueryPath: "queryBy", + }, &requestflag.Flag[[]string]{ Name: "tag", Usage: "Optional comma-separated caller-defined tags for tracking this request. Tags are recorded on the request's usage log and can be used to filter usage on the dashboard usage page. Up to 20 tags, each 1-50 characters.", QueryPath: "tags", }, + &requestflag.Flag[int64]{ + Name: "typo-tolerance", + Usage: "Maximum number of typos tolerated when matching, from 0 to 2. Defaults to 0 (no typo tolerance).", + Default: 0, + QueryPath: "typoTolerance", + }, }, Action: handleBrandSearch, HideHelpCommand: true, diff --git a/pkg/cmd/brand_test.go b/pkg/cmd/brand_test.go index 3a844ba..a46bd9c 100644 --- a/pkg/cmd/brand_test.go +++ b/pkg/cmd/brand_test.go @@ -71,8 +71,11 @@ func TestBrandSearch(t *testing.T) { "--api-key", "string", "brand", "search", "--query", "x", + "--autocomplete=true", + "--query-by", "name", "--tag", "production", "--tag", "team-alpha", + "--typo-tolerance", "0", ) }) } From 337b3a479841059d43edb1aaeedba132a0d98ca6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 04:30:04 +0000 Subject: [PATCH 133/154] feat(api): manual updates --- .stats.yml | 6 +- pkg/cmd/cmd.go | 8 +++ pkg/cmd/news.go | 147 +++++++++++++++++++++++++++++++++++++++++++ pkg/cmd/news_test.go | 86 +++++++++++++++++++++++++ 4 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 pkg/cmd/news.go create mode 100644 pkg/cmd/news_test.go diff --git a/.stats.yml b/.stats.yml index 983602e..4b9b1cb 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 40 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4f279e7b1f0a52f5c917d4256e17188dfe330ddf7495146e2b1611e812605fdc.yml +configured_endpoints: 41 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5dbe631ce516ca688273053ddcb58870561bd6dc76fa75df354c954d7af65a3c.yml openapi_spec_hash: 53a74c4cccbdec8590db38183840a446 -config_hash: 920678668dd2da6f8966fbf1b8fde4e2 +config_hash: 0fb0ceca5946298c416cec0cca5260c7 diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index c2f399f..673b8eb 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -187,6 +187,14 @@ func init() { &peopleEnrich, }, }, + { + Name: "news", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &newsSearch, + }, + }, { Name: "@manpages", Usage: "Generate documentation for 'man'", diff --git a/pkg/cmd/news.go b/pkg/cmd/news.go new file mode 100644 index 0000000..e9f54cc --- /dev/null +++ b/pkg/cmd/news.go @@ -0,0 +1,147 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/context-dot-dev/context-dev-cli/internal/apiquery" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" + "github.com/context-dot-dev/context-go-sdk/v2" + "github.com/context-dot-dev/context-go-sdk/v2/option" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var newsSearch = requestflag.WithInnerFlags(cli.Command{ + Name: "search", + Usage: "Searches live and historical company news for one company, identified in\nsearchBy by name, domain, ticker (optionally disambiguated by exchange), or\nISIN. Results can be filtered by publisher domain, publisher country, article\nlanguage, article type, and published-at date, and include stable story IDs,\nsource metadata, verified entity relevance, and cursor pagination.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[map[string]any]{ + Name: "search-by", + Usage: "What to search for.", + Required: true, + BodyPath: "searchBy", + }, + &requestflag.Flag[*string]{ + Name: "cursor", + Usage: "Opaque next_cursor from the previous response, or null for the first page.", + BodyPath: "cursor", + }, + &requestflag.Flag[map[string]any]{ + Name: "filter-by", + Usage: "Optional result filters.", + Default: map[string]any{}, + BodyPath: "filterBy", + }, + &requestflag.Flag[int64]{ + Name: "limit", + Usage: "Maximum results to return. Defaults to 10.", + Default: 10, + BodyPath: "limit", + }, + &requestflag.Flag[map[string]any]{ + Name: "sort-by", + Usage: "Result ordering. Defaults to newest.", + Default: map[string]any{"type": "newest"}, + BodyPath: "sortBy", + }, + &requestflag.Flag[[]string]{ + Name: "tag", + Usage: "Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters.", + BodyPath: "tags", + }, + }, + Action: handleNewsSearch, + HideHelpCommand: true, +}, map[string][]requestflag.HasOuterFlag{ + "search-by": { + &requestflag.InnerFlag[map[string]any]{ + Name: "search-by.entity", + Usage: "The company to search news for, identified by name, domain, ticker, or ISIN.", + InnerField: "entity", + }, + &requestflag.InnerFlag[string]{ + Name: "search-by.type", + Usage: "How to search. Only entity search is supported.", + InnerField: "type", + }, + }, + "filter-by": { + &requestflag.InnerFlag[[]string]{ + Name: "filter-by.article-language", + Usage: "Article languages to include. Up to 3.", + InnerField: "articleLanguage", + }, + &requestflag.InnerFlag[[]string]{ + Name: "filter-by.article-type", + Usage: "Article types to include. Up to 3.", + InnerField: "articleType", + }, + &requestflag.InnerFlag[map[string]any]{ + Name: "filter-by.date", + Usage: "Published-at window in epoch milliseconds.", + InnerField: "date", + }, + &requestflag.InnerFlag[[]string]{ + Name: "filter-by.source-country", + Usage: "Publisher countries to include, as lowercase ISO 3166-1 alpha-2 codes. Up to 3.", + InnerField: "sourceCountry", + }, + &requestflag.InnerFlag[[]string]{ + Name: "filter-by.source-domain", + Usage: "Publisher domains to include. Up to 3.", + InnerField: "sourceDomain", + }, + }, + "sort-by": { + &requestflag.InnerFlag[string]{ + Name: "sort-by.type", + Usage: "Result ordering.", + InnerField: "type", + }, + }, +}) + +func handleNewsSearch(ctx context.Context, cmd *cli.Command) error { + client := contextdev.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := contextdev.NewsSearchParams{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.News.Search(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "news search", + Transform: transform, + }) +} diff --git a/pkg/cmd/news_test.go b/pkg/cmd/news_test.go new file mode 100644 index 0000000..5260a23 --- /dev/null +++ b/pkg/cmd/news_test.go @@ -0,0 +1,86 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/context-dot-dev/context-dev-cli/internal/mocktest" + "github.com/context-dot-dev/context-dev-cli/internal/requestflag" +) + +func TestNewsSearch(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "news", "search", + "--search-by", "{entity: {name: xx, type: name}, type: entity}", + "--cursor", "cursor", + "--filter-by", "{articleLanguage: [ar], articleType: [editorial], date: {from: 0, to: 0}, sourceCountry: [ae], sourceDomain: [x]}", + "--limit", "1", + "--sort-by", "{type: relevance}", + "--tag", "production", + "--tag", "team-alpha", + ) + }) + + t.Run("inner flags", func(t *testing.T) { + // Check that inner flags have been set up correctly + requestflag.CheckInnerFlags(newsSearch) + + // Alternative argument passing style using inner flags + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "news", "search", + "--search-by.entity", "{name: xx, type: name}", + "--search-by.type", "entity", + "--cursor", "cursor", + "--filter-by.article-language", "[ar]", + "--filter-by.article-type", "[editorial]", + "--filter-by.date", "{from: 0, to: 0}", + "--filter-by.source-country", "[ae]", + "--filter-by.source-domain", "[x]", + "--limit", "1", + "--sort-by.type", "relevance", + "--tag", "production", + "--tag", "team-alpha", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "searchBy:\n" + + " entity:\n" + + " name: xx\n" + + " type: name\n" + + " type: entity\n" + + "cursor: cursor\n" + + "filterBy:\n" + + " articleLanguage:\n" + + " - ar\n" + + " articleType:\n" + + " - editorial\n" + + " date:\n" + + " from: 0\n" + + " to: 0\n" + + " sourceCountry:\n" + + " - ae\n" + + " sourceDomain:\n" + + " - x\n" + + "limit: 1\n" + + "sortBy:\n" + + " type: relevance\n" + + "tags:\n" + + " - production\n" + + " - team-alpha\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "news", "search", + ) + }) +} From b04b0f5e74f8c864f81f9d4dc80874c41f4c7aeb Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 04:37:35 +0000 Subject: [PATCH 134/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index fbd9082..7deae33 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.5.0" + ".": "1.6.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index cf77cd0..855000d 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.5.0" // x-release-please-version +const Version = "1.6.0" // x-release-please-version From abd2f960991c3f68ea17b1ccd723b840ceca61bd Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 05:38:58 +0000 Subject: [PATCH 135/154] feat(api): api update --- .stats.yml | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.stats.yml b/.stats.yml index 4b9b1cb..f9f986b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5dbe631ce516ca688273053ddcb58870561bd6dc76fa75df354c954d7af65a3c.yml -openapi_spec_hash: 53a74c4cccbdec8590db38183840a446 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5e890b591fcd62757c51fa1decc2cccc3d52d5a83097b10775507e3485776f73.yml +openapi_spec_hash: 432ee63a7d4ffca7d5993dc0853d9c81 config_hash: 0fb0ceca5946298c416cec0cca5260c7 diff --git a/go.mod b/go.mod index 63f9b32..af46123 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.9.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.10.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 3554fa9..cc4035d 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.9.0 h1:Lv27NRJ1PyQF9QKNjMLYvrc1uRKaBjFD3sj7YHOnGgw= -github.com/context-dot-dev/context-go-sdk/v2 v2.9.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.10.0 h1:gw/QnKENZ8seyEPI9t9f7MjbtQGK392WFalNUKS3Xs4= +github.com/context-dot-dev/context-go-sdk/v2 v2.10.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From de7fe049f93d2339c9c9149b686dcfe84cb1e5c7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 06:44:21 +0000 Subject: [PATCH 136/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index f9f986b..65e1e03 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5e890b591fcd62757c51fa1decc2cccc3d52d5a83097b10775507e3485776f73.yml -openapi_spec_hash: 432ee63a7d4ffca7d5993dc0853d9c81 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a93ee49f1b1f7a2d95a79fa63dba0c825dcc664198a8d6d42a71c4577342cb3b.yml +openapi_spec_hash: 62ec48956bfb06100953840ac780e93f config_hash: 0fb0ceca5946298c416cec0cca5260c7 From 926d0bda1728cabdfc03342865b32c9f192009af Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 17 Aug 2026 06:59:12 +0000 Subject: [PATCH 137/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 65e1e03..01e56c8 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a93ee49f1b1f7a2d95a79fa63dba0c825dcc664198a8d6d42a71c4577342cb3b.yml -openapi_spec_hash: 62ec48956bfb06100953840ac780e93f +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-f23ab92b85d838bfa0c2741f96f4bf7acf09a22cc17aa88d78ae8a1cafb0c7f0.yml +openapi_spec_hash: 641b62af26fa7bc744bbebc50aeb2ac6 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From 62839af19c316d38063df90c11c5d5dc54c31d5e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2026 03:25:17 +0000 Subject: [PATCH 138/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 6 ++++++ pkg/cmd/web_test.go | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 01e56c8..5c58535 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-f23ab92b85d838bfa0c2741f96f4bf7acf09a22cc17aa88d78ae8a1cafb0c7f0.yml -openapi_spec_hash: 641b62af26fa7bc744bbebc50aeb2ac6 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a0e9f5a245a9ad4bf712a35826463af573957da6d3714136cfab643140664566.yml +openapi_spec_hash: 20f2776cd458320c8b66fec4ec4f9332 config_hash: 0fb0ceca5946298c416cec0cca5260c7 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 52420fa..37230d3 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -240,6 +240,12 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{ Usage: "Capture a screenshot of a website.", Suggest: true, Flags: []cli.Flag{ + &requestflag.Flag[bool]{ + Name: "clear-popups", + Usage: "Optional parameter for comprehensive popup cleanup. If 'true', the browser dismisses detected cookie/consent UI and clears other detected obstructive popups and overlays before capture. If 'false' or not provided, this parameter requests no cleanup; handleCookiePopup can still request cookie/consent handling independently.", + Default: false, + QueryPath: "clearPopups", + }, &requestflag.Flag[string]{ Name: "color-scheme", Usage: "Optional parameter to choose the site's visual theme in the screenshot. Use 'light' or 'dark' when the site offers both appearances.", diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index 7c6cf11..d8202fb 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -158,6 +158,7 @@ func TestWebScreenshot(t *testing.T) { t, "--api-key", "string", "web", "screenshot", + "--clear-popups=true", "--color-scheme", "light", "--country", "de", "--direct-url", "https://example.com", @@ -185,6 +186,7 @@ func TestWebScreenshot(t *testing.T) { t, "--api-key", "string", "web", "screenshot", + "--clear-popups=true", "--color-scheme", "light", "--country", "de", "--direct-url", "https://example.com", From c97cd37e365dfc6546dca201e43bcb435fd6a044 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2026 04:35:06 +0000 Subject: [PATCH 139/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 5c58535..60361a5 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-a0e9f5a245a9ad4bf712a35826463af573957da6d3714136cfab643140664566.yml -openapi_spec_hash: 20f2776cd458320c8b66fec4ec4f9332 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-813f97d04b6924bbbeb1a89dd8f0d7b38d3241bd0126338fa00ddcb094ab6893.yml +openapi_spec_hash: 3fee1c958d5414b88e964062ea4cc808 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From 4580e4b7d422c7359985b5a0e456286bcc3145b6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2026 06:17:11 +0000 Subject: [PATCH 140/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 60361a5..9673209 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-813f97d04b6924bbbeb1a89dd8f0d7b38d3241bd0126338fa00ddcb094ab6893.yml -openapi_spec_hash: 3fee1c958d5414b88e964062ea4cc808 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-b0c72d2fe5911c9ce155275b954198bf2152e915a7e5b9f719aad50e222b9ef8.yml +openapi_spec_hash: 5cf943ea5718059b7975417b012cee28 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From 72f32aa4f177bbc99847c6234015717e263d8f29 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2026 08:00:21 +0000 Subject: [PATCH 141/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 7deae33..cce9d1c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.6.0" + ".": "1.7.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 855000d..560ca21 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.6.0" // x-release-please-version +const Version = "1.7.0" // x-release-please-version From 08ff5ff3eea90e95230ca576469aafb326a3a1e9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2026 09:03:07 +0000 Subject: [PATCH 142/154] feat(api): api update --- .stats.yml | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.stats.yml b/.stats.yml index 9673209..21c2cfc 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-b0c72d2fe5911c9ce155275b954198bf2152e915a7e5b9f719aad50e222b9ef8.yml -openapi_spec_hash: 5cf943ea5718059b7975417b012cee28 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5f711a43f60f18016c38794f4dbd4fa86221e2ac2e50f9875ae84f5a247db136.yml +openapi_spec_hash: 1000553b31fbfe8574b5c7ed47b2166e config_hash: 0fb0ceca5946298c416cec0cca5260c7 diff --git a/go.mod b/go.mod index af46123..e834f3d 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.10.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.11.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index cc4035d..68d8032 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.10.0 h1:gw/QnKENZ8seyEPI9t9f7MjbtQGK392WFalNUKS3Xs4= -github.com/context-dot-dev/context-go-sdk/v2 v2.10.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.11.0 h1:SsEX/lciOcEwANUhkEs6iJoEtSD2oZmnmslHtlio/Cc= +github.com/context-dot-dev/context-go-sdk/v2 v2.11.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From 9403e674c48d78f3037d4a4474fde38dd8ad41ca Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2026 09:40:25 +0000 Subject: [PATCH 143/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 21c2cfc..ab4d401 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-5f711a43f60f18016c38794f4dbd4fa86221e2ac2e50f9875ae84f5a247db136.yml -openapi_spec_hash: 1000553b31fbfe8574b5c7ed47b2166e +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-f6a6ca581fd279a5c8028e3e00d84fd5114c0ba206f15e84c24d8abeedbf47d9.yml +openapi_spec_hash: 07010001ef5726f6f0f6ecdea1b36b51 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From f04a8381733c66a365c23f00f493db8e520c95e9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 18 Aug 2026 12:28:49 +0000 Subject: [PATCH 144/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index ab4d401..91ac12d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-f6a6ca581fd279a5c8028e3e00d84fd5114c0ba206f15e84c24d8abeedbf47d9.yml -openapi_spec_hash: 07010001ef5726f6f0f6ecdea1b36b51 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-29a5e9392b60f02d4c19d457b92666bf54d49479670e719f36f23a5d3943f188.yml +openapi_spec_hash: 8a9c44d740853834fb6d7174013c1984 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From f2483eadc4eacb888ba9b53d25cf01b4b0242f9c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 19 Aug 2026 02:21:42 +0000 Subject: [PATCH 145/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.stats.yml b/.stats.yml index 91ac12d..44d1600 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-29a5e9392b60f02d4c19d457b92666bf54d49479670e719f36f23a5d3943f188.yml -openapi_spec_hash: 8a9c44d740853834fb6d7174013c1984 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d4c568ebc1a0f853b02c55ba800c7d7b66189bc6dd22c3cb565a81361c832e2b.yml +openapi_spec_hash: 9a0ecdc06874eee29a3a58a699923405 config_hash: 0fb0ceca5946298c416cec0cca5260c7 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 37230d3..7ea5e0c 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -557,7 +557,7 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[string]{ Name: "url-regex", - Usage: "Regex pattern. Only URLs matching this pattern will be followed and scraped.", + Usage: "Regex pattern. Only URLs matching this pattern will be followed and scraped. An automatic prefix scope in the form ^ follows a redirect of the starting page.", BodyPath: "urlRegex", }, &requestflag.Flag[bool]{ @@ -568,7 +568,8 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[int64]{ Name: "wait-for-ms", - Usage: "Optional browser wait time in milliseconds after initial page load for each crawled page. Min: 0. Max: 30000 (30 seconds). ", + Usage: "Browser wait time in milliseconds after initial page load for each crawled page. Defaults to 3500 (3.5 seconds). Min: 0. Max: 30000 (30 seconds).", + Default: 3500, BodyPath: "waitForMs", }, &requestflag.Flag[string]{ From 90b24a267523ad262b7889bb96d96eae8619fc7a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 21 Aug 2026 07:22:14 +0000 Subject: [PATCH 146/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 44d1600..e115f20 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d4c568ebc1a0f853b02c55ba800c7d7b66189bc6dd22c3cb565a81361c832e2b.yml -openapi_spec_hash: 9a0ecdc06874eee29a3a58a699923405 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-7e6b2353ee8631f506bd8ef7657f1684cddf84805c01d89c691d7f98c42127f7.yml +openapi_spec_hash: b63b980d90fc9c2b896b2739a8e15a59 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From a1e1e4b762fb1e6bf69b8aa36668d734154ac217 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 21 Aug 2026 10:55:15 +0000 Subject: [PATCH 147/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 9 +++++++-- pkg/cmd/web_test.go | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.stats.yml b/.stats.yml index e115f20..4aa99bd 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-7e6b2353ee8631f506bd8ef7657f1684cddf84805c01d89c691d7f98c42127f7.yml -openapi_spec_hash: b63b980d90fc9c2b896b2739a8e15a59 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-bf7ffa610bd4a02ea5bcb157521d17a041a48f78d87bf8fe8d812d3cbb87b489.yml +openapi_spec_hash: 90142d96969dea44c46a01abb683c426 config_hash: 0fb0ceca5946298c416cec0cca5260c7 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 7ea5e0c..6273254 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -21,7 +21,7 @@ var webExtract = requestflag.WithInnerFlags(cli.Command{ Flags: []cli.Flag{ &requestflag.Flag[map[string]any]{ Name: "schema", - Usage: "JSON Schema for the returned data object. TypeScript Zod users can pass a JSON Schema generated from a Zod object; Python users can pass the equivalent JSON Schema object.", + Usage: "JSON Schema for the returned data object. Image fields such as `image_urls` or `product_photos` automatically make page image references available to extraction, so product data and photos can be returned in one call. TypeScript Zod users can pass a JSON Schema generated from a Zod object; Python users can pass the equivalent JSON Schema object.", Required: true, BodyPath: "schema", }, @@ -31,6 +31,11 @@ var webExtract = requestflag.WithInnerFlags(cli.Command{ Required: true, BodyPath: "url", }, + &requestflag.Flag[[]map[string]any]{ + Name: "action", + Usage: "Optional browser actions executed in order on the requested page after it loads and before extraction. Requires a paid plan. When actions are provided and stopAfterMs is omitted, the crawl budget defaults to 110000 ms.", + BodyPath: "actions", + }, &requestflag.Flag[bool]{ Name: "fact-check", Usage: "When true, every returned value must be grounded in facts stated on the page; fields that cannot be supported by the page are returned as null/empty. When false (default), the model may make reasonable inferences and derivations from the page content (e.g. ideal customer, competitor analysis, recommendations) while keeping verifiable specifics (names, quotes, URLs, dates, metrics) faithful to the source.", @@ -84,7 +89,7 @@ var webExtract = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[int64]{ Name: "stop-after-ms", - Usage: "Soft time budget for the crawl in milliseconds. Min: 10000 (10s). Max: 110000 (110s). Default: 80000 (80s).", + Usage: "Soft time budget for the crawl in milliseconds. Min: 10000 (10s). Max: 110000 (110s). Defaults to 80000 (80s), or 110000 (110s) when browser actions are provided.", Default: 80000, BodyPath: "stopAfterMs", }, diff --git a/pkg/cmd/web_test.go b/pkg/cmd/web_test.go index d8202fb..acbcf47 100644 --- a/pkg/cmd/web_test.go +++ b/pkg/cmd/web_test.go @@ -18,6 +18,7 @@ func TestWebExtract(t *testing.T) { "web", "extract", "--schema", "{type: bar, properties: bar, required: bar, additionalProperties: bar}", "--url", "https://example.com", + "--action", "{do: wait, timeMs: 0}", "--fact-check=true", "--follow-subdomains=true", "--include-frames=true", @@ -46,6 +47,7 @@ func TestWebExtract(t *testing.T) { "web", "extract", "--schema", "{type: bar, properties: bar, required: bar, additionalProperties: bar}", "--url", "https://example.com", + "--action", "{do: wait, timeMs: 0}", "--fact-check=true", "--follow-subdomains=true", "--include-frames=true", @@ -74,6 +76,9 @@ func TestWebExtract(t *testing.T) { " required: bar\n" + " additionalProperties: bar\n" + "url: https://example.com\n" + + "actions:\n" + + " - do: wait\n" + + " timeMs: 0\n" + "factCheck: true\n" + "followSubdomains: true\n" + "includeFrames: true\n" + From 75e4c25d24d3da7d563a510dc1a25a2ba03ae491 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 23 Aug 2026 19:12:56 +0000 Subject: [PATCH 148/154] feat(api): api update --- .stats.yml | 4 ++-- pkg/cmd/web.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.stats.yml b/.stats.yml index 4aa99bd..ad6cd80 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-bf7ffa610bd4a02ea5bcb157521d17a041a48f78d87bf8fe8d812d3cbb87b489.yml -openapi_spec_hash: 90142d96969dea44c46a01abb683c426 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2c3f4e4b357ca78c019a3aacd006e2bb8b332d4172a300ee6c46c076a216ed3f.yml +openapi_spec_hash: b89be415cf6ee594b521885a9deb25ac config_hash: 0fb0ceca5946298c416cec0cca5260c7 diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go index 6273254..bd2b64d 100644 --- a/pkg/cmd/web.go +++ b/pkg/cmd/web.go @@ -33,7 +33,7 @@ var webExtract = requestflag.WithInnerFlags(cli.Command{ }, &requestflag.Flag[[]map[string]any]{ Name: "action", - Usage: "Optional browser actions executed in order on the requested page after it loads and before extraction. Requires a paid plan. When actions are provided and stopAfterMs is omitted, the crawl budget defaults to 110000 ms.", + Usage: "Optional browser actions executed in order on the requested page after it loads, before links are discovered or additional pages are crawled. Requires a paid plan. When actions are provided and stopAfterMs is omitted, the crawl budget defaults to 110000 ms.", BodyPath: "actions", }, &requestflag.Flag[bool]{ From 5f30c42446aa7877c652fa5033173f2336c3f956 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 23 Aug 2026 19:16:33 +0000 Subject: [PATCH 149/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- pkg/cmd/version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index cce9d1c..c523ce1 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.7.0" + ".": "1.8.0" } \ No newline at end of file diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 560ca21..237efb5 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.7.0" // x-release-please-version +const Version = "1.8.0" // x-release-please-version From 6720d8600416777cc946c476f2808d676f815be3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 24 Aug 2026 00:48:28 +0000 Subject: [PATCH 150/154] feat(api): api update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e834f3d..e8318bb 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.11.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.12.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 68d8032..8aeb563 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.11.0 h1:SsEX/lciOcEwANUhkEs6iJoEtSD2oZmnmslHtlio/Cc= -github.com/context-dot-dev/context-go-sdk/v2 v2.11.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.12.0 h1:cA6jbkTtWal7kfdGDi0Km1ABgAD4sjmKayD8HttGil0= +github.com/context-dot-dev/context-go-sdk/v2 v2.12.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= From a76b5ba01dc1c56ad60b742b0b6351a64126f9a7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 24 Aug 2026 16:11:48 +0000 Subject: [PATCH 151/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index ad6cd80..60019de 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-2c3f4e4b357ca78c019a3aacd006e2bb8b332d4172a300ee6c46c076a216ed3f.yml -openapi_spec_hash: b89be415cf6ee594b521885a9deb25ac +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-05ba8ca01ab3b765bfdca4cdc99248d3169cf4fef049d0ddcf11a807cbf72a08.yml +openapi_spec_hash: 565724dda1e870c0d0469953514ca767 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From 1c0a245889825f8de1e67edd137f36b1171aabbc Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 24 Aug 2026 22:06:29 +0000 Subject: [PATCH 152/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 60019de..56757d6 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-05ba8ca01ab3b765bfdca4cdc99248d3169cf4fef049d0ddcf11a807cbf72a08.yml -openapi_spec_hash: 565724dda1e870c0d0469953514ca767 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8be9b7cfe70702af909241420da1c61ba6b248345c5faec3b472df540bc6a553.yml +openapi_spec_hash: f98fb82a9ad562fc04d32f7063182de8 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From c1aca879286dacfac071da643f9f789ffda23f99 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 27 Aug 2026 02:55:41 +0000 Subject: [PATCH 153/154] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 56757d6..9aabd7d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 41 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8be9b7cfe70702af909241420da1c61ba6b248345c5faec3b472df540bc6a553.yml -openapi_spec_hash: f98fb82a9ad562fc04d32f7063182de8 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-dc61df29e1b6282f9df685fadd65f3683afe352deccae94d0c080092e0eae4b3.yml +openapi_spec_hash: 258caa98cd0de5f7149f6937d071c912 config_hash: 0fb0ceca5946298c416cec0cca5260c7 From 92cb26232bc56a3228cfc1b2baad19a59294f80a Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 27 Aug 2026 14:14:06 +0000 Subject: [PATCH 154/154] chore(internal): version bump --- .release-please-manifest.json | 2 +- go.mod | 2 +- go.sum | 4 ++-- pkg/cmd/version.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index c523ce1..c3c9552 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.8.0" + ".": "1.9.0" } \ No newline at end of file diff --git a/go.mod b/go.mod index e8318bb..8604556 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbletea v1.3.6 github.com/charmbracelet/lipgloss v1.1.0 github.com/charmbracelet/x/term v0.2.1 - github.com/context-dot-dev/context-go-sdk/v2 v2.12.0 + github.com/context-dot-dev/context-go-sdk/v2 v2.13.0 github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 diff --git a/go.sum b/go.sum index 8aeb563..5415828 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payR github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/context-dot-dev/context-go-sdk/v2 v2.12.0 h1:cA6jbkTtWal7kfdGDi0Km1ABgAD4sjmKayD8HttGil0= -github.com/context-dot-dev/context-go-sdk/v2 v2.12.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= +github.com/context-dot-dev/context-go-sdk/v2 v2.13.0 h1:4XJmz1E3jso9ngv8WEN0sfQmp5+2tgDT2xl4GVTu0Ug= +github.com/context-dot-dev/context-go-sdk/v2 v2.13.0/go.mod h1:CvRANWLP0FHj5XyUwzEVX79ujdwr/2Jy375UVzKNQm8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index 237efb5..a82500c 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -2,4 +2,4 @@ package cmd -const Version = "1.8.0" // x-release-please-version +const Version = "1.9.0" // x-release-please-version