@cartanova/qgrid-cli 2.11.1 → 2.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/bundle/dist/_virtual/{_@oxc-project_runtime@0.140.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/decorate.js +1 -1
- package/bundle/dist/_virtual/{_@oxc-project_runtime@0.140.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/decorateMetadata.js +1 -1
- package/bundle/dist/_virtual/_rolldown/runtime.js +2 -2
- package/bundle/dist/application/monit/monit.frame.js +2 -2
- package/bundle/dist/application/qgrid/qgrid-response-format.js +9 -1
- package/bundle/dist/application/qgrid/qgrid-run-lifecycle.js +30 -6
- package/bundle/dist/application/qgrid/qgrid.dispatcher.js +7 -4
- package/bundle/dist/application/qgrid/qgrid.frame.js +30 -9
- package/bundle/dist/application/qgrid/qgrid.types.js +8 -8
- package/bundle/dist/application/qgrid/token-death.js +3 -2
- package/bundle/dist/application/qgrid/token-subscriber.js +2 -2
- package/bundle/dist/application/qgrid/token-window-keepalive.js +2 -2
- package/bundle/dist/application/qgrid/tool-emulation-schema.js +5 -3
- package/bundle/dist/application/qgrid/tool-emulation.js +2 -2
- package/bundle/dist/application/request-log/request-log.model.js +13 -7
- package/bundle/dist/application/request-log-step/request-log-step.model.js +11 -7
- package/bundle/dist/application/setting/setting.model.js +11 -7
- package/bundle/dist/application/token/token.model.js +15 -11
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/code.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/scope.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/errors.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/names.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/ref_error.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/resolve.js +7 -5
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/rules.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/util.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/applicability.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/boolSchema.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/defaults.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/keyword.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/subschema.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/core.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/data.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/applicator.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/content.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/core.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/format-annotation.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/meta-data.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/unevaluated.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/schema.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/equal.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/ucs2length.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/uri.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/validation_error.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/allOf.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/contains.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/if.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items2020.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/not.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/properties.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/code.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/id.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/ref.js +15 -11
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/types.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/draft2020.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/format.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/metadata.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/next.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/const.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/dependentRequired.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/enum.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitContains.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitItems.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitLength.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/pattern.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/required.js +1 -1
- package/bundle/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +1 -1
- package/bundle/dist/node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js +1 -1
- package/bundle/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/index.js +18 -12
- package/bundle/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/schemes.js +1 -1
- package/bundle/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/utils.js +16 -13
- package/bundle/dist/node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js +1 -1
- package/bundle/dist/sonamu.config.js +11 -11
- package/bundle/dist/startup-migrations.js +1 -1
- package/bundle/dist/utils/providers/anthropic/anthropic-dispatcher.js +9 -3
- package/bundle/dist/utils/providers/anthropic/anthropic-thinking.js +5 -2
- package/bundle/dist/utils/providers/anthropic/claude-session.js +10 -2
- package/bundle/dist/utils/providers/anthropic/stream-json-adapter.js +9 -7
- package/bundle/dist/utils/providers/common/model-cost.js +7 -5
- package/bundle/dist/utils/providers/common/schema-validation.js +3 -3
- package/bundle/dist/utils/providers/grok/grok-backend-protocol.js +1 -1
- package/bundle/dist/utils/providers/grok/grok-constants.js +1 -1
- package/bundle/dist/utils/providers/grok/grok-dispatcher.js +47 -14
- package/bundle/dist/utils/providers/grok/grok-media-client.js +4 -4
- package/bundle/dist/utils/providers/grok/grok-oauth.js +2 -2
- package/bundle/dist/utils/providers/grok/grok-types.js +2 -2
- package/bundle/dist/utils/providers/openai/openai-dispatcher.js +16 -8
- package/bundle/dist/utils/providers/openai/openai-image-generation.js +4 -4
- package/bundle/src/application/qgrid/qgrid-response-format.ts +9 -0
- package/bundle/src/application/qgrid/qgrid-run-lifecycle.test.ts +63 -0
- package/bundle/src/application/qgrid/qgrid-run-lifecycle.ts +49 -7
- package/bundle/src/application/qgrid/qgrid.dispatcher.ts +6 -0
- package/bundle/src/application/qgrid/qgrid.frame.test.ts +12 -4
- package/bundle/src/application/qgrid/qgrid.frame.ts +39 -3
- package/bundle/src/application/qgrid/qgrid.types.ts +5 -5
- package/bundle/src/application/request-log/request-log.model.ts +12 -1
- package/bundle/src/sonamu.config.ts +14 -14
- package/bundle/src/utils/providers/anthropic/anthropic-dispatcher.ts +2 -0
- package/bundle/src/utils/providers/anthropic/claude-session.ts +15 -1
- package/bundle/src/utils/providers/common/model-cost.ts +8 -6
- package/bundle/src/utils/providers/common/provider-dispatcher.ts +10 -0
- package/bundle/src/utils/providers/grok/grok-backend-protocol.ts +6 -1
- package/bundle/src/utils/providers/grok/grok-constants.ts +7 -8
- package/bundle/src/utils/providers/grok/grok-dispatcher.test.ts +74 -3
- package/bundle/src/utils/providers/grok/grok-dispatcher.ts +66 -18
- package/bundle/src/utils/providers/grok/grok-quota.test.ts +18 -0
- package/bundle/src/utils/providers/grok/grok-types.ts +2 -1
- package/bundle/src/utils/providers/openai/openai-dispatcher.test.ts +18 -0
- package/bundle/src/utils/providers/openai/openai-dispatcher.ts +10 -2
- package/bundle/web-dist/client/assets/clsx-DB0hHKMi.js +1 -0
- package/bundle/web-dist/client/assets/cost-CZzlCFS2.js +1 -0
- package/bundle/web-dist/client/assets/index-DLo1QCw7.css +1 -0
- package/bundle/web-dist/client/assets/index-DplV-wqZ.js +104 -0
- package/bundle/web-dist/client/assets/logs-st46aRba.js +1 -0
- package/bundle/web-dist/client/assets/monit-BMXR2tY2.js +1 -0
- package/bundle/web-dist/client/assets/plus-Bab0ACnC.js +1 -0
- package/bundle/web-dist/client/assets/refresh-cw-BtYoFHVw.js +1 -0
- package/bundle/web-dist/client/assets/request-model-Dl31cZdf.js +1 -0
- package/bundle/web-dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/bundle/web-dist/client/assets/routes-BWPjgvhg.js +5 -0
- package/bundle/web-dist/client/assets/settings-DTXZjDAw.js +1 -0
- package/bundle/web-dist/client/assets/show-CdWNFPyS.js +2 -0
- package/bundle/web-dist/client/assets/tokens-eA34Gw5f.js +1 -0
- package/bundle/web-dist/client/assets/use-oauth-login-flow-CcUdLsa7.js +1 -0
- package/bundle/web-dist/client/assets/use-update-token-mutation-D2r5K5Bz.js +1 -0
- package/bundle/web-dist/client/assets/vendor-react-8xo7RSum.js +9 -0
- package/bundle/web-dist/client/assets/vendor-tanstack-6B86itGS.js +2 -0
- package/bundle/web-dist/client/index.html +5 -7
- package/bundle/web-dist/server/assets/{logs-B7QmGJq3.js → logs-C0md5rmp.js} +67 -37
- package/bundle/web-dist/server/assets/monit-YVvwJuAF.js +479 -0
- package/bundle/web-dist/server/assets/plus-z5Hy__3C.js +26 -0
- package/bundle/web-dist/server/assets/refresh-cw-CNm0CERy.js +30 -0
- package/bundle/web-dist/server/assets/request-model-DIuPZZwu.js +38 -0
- package/bundle/web-dist/server/assets/{routes-_Y-PJfgO.js → routes-CjWxvHAO.js} +1745 -1120
- package/bundle/web-dist/server/assets/{services.generated-CMJ8AHbO.js → services.generated-CqS8DCjT.js} +11973 -6081
- package/bundle/web-dist/server/assets/{settings-JwJKxn2e.js → settings-CXwnKiMG.js} +40 -19
- package/bundle/web-dist/server/assets/{show-BEv6z1v_.js → show-G1t8dOEh.js} +274 -213
- package/bundle/web-dist/server/assets/{tokens-CNT4mI-f.js → tokens-C4D67FBX.js} +41 -18
- package/bundle/web-dist/server/assets/{use-oauth-login-flow-jkAkT3X6.js → use-oauth-login-flow-CFzShQtp.js} +1569 -38
- package/bundle/web-dist/server/assets/{use-update-token-mutation-Sm6kh02m.js → use-update-token-mutation-oH0O0n-g.js} +1 -1
- package/bundle/web-dist/server/entry-server.generated.js +11641 -5075
- package/dist/cli.js +20 -11
- package/package.json +24 -24
- package/skills/qgrid/references/ai-sdk-provider-contract.md +5 -5
- package/skills/qgrid/references/cli-env-and-server-boot.md +4 -3
- package/skills/qgrid/references/decision-rationale.md +5 -1
- package/skills/qgrid/references/grok-runtime.md +7 -1
- package/skills/qgrid/references/repo-map.md +2 -0
- package/skills/qgrid/references/request-log-run-lifecycle.md +6 -1
- package/skills/qgrid/references/tool-calling-and-multiturn.md +2 -2
- package/skills/qgrid/references/verification-and-debugging.md +24 -5
- package/bundle/web-dist/client/assets/clsx-5XM_pHvN.js +0 -1
- package/bundle/web-dist/client/assets/cost-DB3HbU7T.js +0 -1
- package/bundle/web-dist/client/assets/index-Be2qCZmI.css +0 -1
- package/bundle/web-dist/client/assets/index-C96h3feE.js +0 -32
- package/bundle/web-dist/client/assets/logs-DBM6U0QD.js +0 -1
- package/bundle/web-dist/client/assets/monit-BBjXa7vB.js +0 -1
- package/bundle/web-dist/client/assets/plus-BsQdY7PS.js +0 -1
- package/bundle/web-dist/client/assets/preload-helper-DWTEM3RW.js +0 -1
- package/bundle/web-dist/client/assets/refresh-cw-D9IUmT23.js +0 -1
- package/bundle/web-dist/client/assets/request-model-Bpp_rkK8.js +0 -1
- package/bundle/web-dist/client/assets/rolldown-runtime-Dw2cE7zH.js +0 -1
- package/bundle/web-dist/client/assets/routes-Crz_PQzi.js +0 -5
- package/bundle/web-dist/client/assets/services.generated-B5lc3aIC.js +0 -51
- package/bundle/web-dist/client/assets/settings-Cdwm3OBB.js +0 -1
- package/bundle/web-dist/client/assets/show-DBUhALT1.js +0 -2
- package/bundle/web-dist/client/assets/tokens-CVQAVJTo.js +0 -1
- package/bundle/web-dist/client/assets/total-cost-MnfKU8IN.js +0 -1
- package/bundle/web-dist/client/assets/use-oauth-login-flow-BfxYI4Oh.js +0 -1
- package/bundle/web-dist/client/assets/use-update-token-mutation-qKBC2sn7.js +0 -1
- package/bundle/web-dist/client/assets/vendor-react-DH4kUfK2.js +0 -9
- package/bundle/web-dist/client/assets/vendor-tanstack-DRPs09ai.js +0 -1
- package/bundle/web-dist/server/assets/lazyRouteComponent-AKiHfZWp.js +0 -1983
- package/bundle/web-dist/server/assets/monit-DFt7x3bh.js +0 -1652
- package/bundle/web-dist/server/assets/plus-DaYQRpBt.js +0 -19
- package/bundle/web-dist/server/assets/react-dom-Cv23mm1K.js +0 -335
- package/bundle/web-dist/server/assets/refresh-cw-BpXNsAy-.js +0 -23
- package/bundle/web-dist/server/assets/request-model-eHE6YbaF.js +0 -31
- package/bundle/web-dist/server/assets/total-cost-fTE9Xy82.js +0 -18
- /package/bundle/web-dist/server/assets/{clsx-D_N5PN_2.js → clsx-DgIEfj3H.js} +0 -0
- /package/bundle/web-dist/server/assets/{cost-BC9yzyA9.js → cost-oNK0T4Jo.js} +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getLogger } from "@logtape/logtape";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { type GenerateProgress } from "../../utils/providers/common/provider-dispatcher";
|
|
5
|
+
import { RequestLogModel, type RunProgressUpdate } from "../request-log/request-log.model";
|
|
5
6
|
import {
|
|
6
7
|
estimateImageGenerationCostMicroUsd,
|
|
7
8
|
imageGenerationCostMethod,
|
|
@@ -125,6 +126,44 @@ export async function beforeQuery(args: QueryInput): Promise<{
|
|
|
125
126
|
return { requestLogId, stepIndex };
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Returns a dispatcher progress callback that writes the token, serving model, and TTFT onto the
|
|
131
|
+
* running parent row as they become known. Writes run in order, and a failure only logs: progress
|
|
132
|
+
* must never fail the request. afterQuery's final values replace these.
|
|
133
|
+
*/
|
|
134
|
+
export function runProgressRecorder(
|
|
135
|
+
requestLogId: number,
|
|
136
|
+
stepIndex: number,
|
|
137
|
+
args: QueryInput,
|
|
138
|
+
): (progress: GenerateProgress) => void {
|
|
139
|
+
let pending = Promise.resolve();
|
|
140
|
+
|
|
141
|
+
return (progress) => {
|
|
142
|
+
const update: RunProgressUpdate = {};
|
|
143
|
+
|
|
144
|
+
if (progress.tokenName) update.token_name = progress.tokenName;
|
|
145
|
+
|
|
146
|
+
const modelName = withProviderPrefix(args.model, progress.model);
|
|
147
|
+
|
|
148
|
+
if (modelName) update.model_name = modelName;
|
|
149
|
+
|
|
150
|
+
// The run's TTFT is its first generate step's; a continued tool run keeps the stored value.
|
|
151
|
+
if (progress.ttftMs !== undefined && stepIndex === 0) update.ttft_ms = progress.ttftMs;
|
|
152
|
+
|
|
153
|
+
if (Object.keys(update).length === 0) return;
|
|
154
|
+
|
|
155
|
+
pending = pending.then(async () => {
|
|
156
|
+
try {
|
|
157
|
+
await RequestLogModel.recordRunProgress(requestLogId, update);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
logger.warn(
|
|
160
|
+
`run progress update failed for ${requestLogId}: ${e instanceof Error ? e.message : String(e)}`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
128
167
|
async function appendGenerateStep(
|
|
129
168
|
requestLogId: number,
|
|
130
169
|
stepIndex: number,
|
|
@@ -177,10 +216,12 @@ export async function afterQuery(
|
|
|
177
216
|
|
|
178
217
|
const imageParts = getImageParts(result);
|
|
179
218
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
219
|
+
// Grok reports one provider cost for the turn that already includes its image tool calls.
|
|
220
|
+
const imageCostIncluded = args.model?.startsWith("grok/") === true && imageParts.length > 0;
|
|
221
|
+
|
|
222
|
+
const imageCostMicroUsd = imageCostIncluded
|
|
223
|
+
? 0
|
|
224
|
+
: estimateImageGenerationCostMicroUsd(result, args.imageGenerationOptions);
|
|
184
225
|
|
|
185
226
|
for (const step of buildImageGenerationToolSteps(args, imageParts, stepIndex)) {
|
|
186
227
|
await RequestLogModel.appendStep(requestLogId, step);
|
|
@@ -233,8 +274,9 @@ export async function afterQuery(
|
|
|
233
274
|
cost_usd: agg.cost_usd,
|
|
234
275
|
cost_source: agg.cost_source,
|
|
235
276
|
image_cost_usd: imageCostMicroUsd,
|
|
236
|
-
image_cost_method:
|
|
237
|
-
|
|
277
|
+
image_cost_method: imageCostIncluded
|
|
278
|
+
? "included:grok-provider-cost"
|
|
279
|
+
: imageCostMicroUsd !== null
|
|
238
280
|
? imageGenerationCostMethod(args.imageGenerationOptions, result)
|
|
239
281
|
: null,
|
|
240
282
|
history: filterHistoryForStorage(args.history),
|
|
@@ -51,6 +51,7 @@ import { buildToolCallSchema } from "./tool-emulation-schema";
|
|
|
51
51
|
export type InternalQueryInput = QueryInput & {
|
|
52
52
|
preferredTokenId?: number;
|
|
53
53
|
requirePreferredToken?: boolean;
|
|
54
|
+
onProgress?: GenerateRequest["onProgress"];
|
|
54
55
|
};
|
|
55
56
|
|
|
56
57
|
// qgrid 상위가 provider 에 요구하는 실행 계약. 스트리밍은 공통 ProviderDispatcher 에 아직 없어서
|
|
@@ -91,6 +92,8 @@ export interface GrokTokenSink {
|
|
|
91
92
|
/** Observability the concrete Grok dispatcher exposes beyond routing. */
|
|
92
93
|
export interface GrokTokenStateSource {
|
|
93
94
|
tokenStates(): GrokTokenStateSnapshot[];
|
|
95
|
+
/** Refreshes stale settings, subscription, and billing lookups for the usage view. */
|
|
96
|
+
refreshUsage(tokenId: number): Promise<void>;
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
/** Media, voice, and token-state reporting are optional capabilities of a Grok dispatcher. */
|
|
@@ -225,6 +228,7 @@ export class QgridDispatcherClass {
|
|
|
225
228
|
preferredTokenId: input.preferredTokenId,
|
|
226
229
|
imageGeneration: input.imageGeneration,
|
|
227
230
|
imageGenerationOptions: input.imageGenerationOptions,
|
|
231
|
+
onProgress: input.onProgress,
|
|
228
232
|
});
|
|
229
233
|
|
|
230
234
|
this.recordCompleted(provider, result.tokenName);
|
|
@@ -301,6 +305,7 @@ export class QgridDispatcherClass {
|
|
|
301
305
|
abortSignal,
|
|
302
306
|
imageGeneration: input.imageGeneration,
|
|
303
307
|
imageGenerationOptions: input.imageGenerationOptions,
|
|
308
|
+
onProgress: input.onProgress,
|
|
304
309
|
},
|
|
305
310
|
{
|
|
306
311
|
onDelta: emitDelta,
|
|
@@ -391,6 +396,7 @@ function buildDirectRequest(
|
|
|
391
396
|
abortSignal,
|
|
392
397
|
imageGeneration: input.imageGeneration,
|
|
393
398
|
imageGenerationOptions: input.imageGenerationOptions,
|
|
399
|
+
onProgress: input.onProgress,
|
|
394
400
|
};
|
|
395
401
|
|
|
396
402
|
// Opaque namespaces; the Grok dispatcher reads `xai`, OpenAI ignores it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
2
|
|
|
3
|
-
import Fastify from "fastify";
|
|
3
|
+
import Fastify, { type FastifyError } from "fastify";
|
|
4
4
|
import { BadRequestException, ServiceUnavailableException, Sonamu } from "sonamu";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
|
|
@@ -166,6 +166,7 @@ vi.mock("./qgrid-run-lifecycle", () => ({
|
|
|
166
166
|
afterQuery: afterQueryMock,
|
|
167
167
|
finishRunWithError: finishRunWithErrorMock,
|
|
168
168
|
finishRunAborted: finishRunAbortedMock,
|
|
169
|
+
runProgressRecorder: () => () => {},
|
|
169
170
|
}));
|
|
170
171
|
|
|
171
172
|
const tokenEntry = {
|
|
@@ -1724,18 +1725,23 @@ describe("QgridFrame Grok registration and routing", () => {
|
|
|
1724
1725
|
expect(result.text).toBe("grok says hi");
|
|
1725
1726
|
});
|
|
1726
1727
|
|
|
1727
|
-
it("usage
|
|
1728
|
+
it("usage refreshes Grok lookups first and reports billing without keepalive", async () => {
|
|
1728
1729
|
const credentials = grokCredentials();
|
|
1729
1730
|
findManyMock.mockResolvedValueOnce({
|
|
1730
1731
|
rows: [{ ...tokenEntry, id: 9, provider: "grok", name: "grok-a", credentials }],
|
|
1731
1732
|
});
|
|
1733
|
+
let refreshed = false;
|
|
1734
|
+
const refreshUsage = vi.fn(async () => {
|
|
1735
|
+
refreshed = true;
|
|
1736
|
+
});
|
|
1732
1737
|
Object.assign(QgridDispatcher, {
|
|
1733
1738
|
grokDispatcher: {
|
|
1739
|
+
refreshUsage,
|
|
1734
1740
|
tokenStates: () => [
|
|
1735
1741
|
{
|
|
1736
1742
|
id: 9,
|
|
1737
1743
|
name: "grok-a",
|
|
1738
|
-
lastBilling: {
|
|
1744
|
+
lastBilling: refreshed && {
|
|
1739
1745
|
utilizationPct: 42,
|
|
1740
1746
|
periodType: "USAGE_PERIOD_TYPE_WEEKLY",
|
|
1741
1747
|
periodEnd: "2030-01-08T00:00:00Z",
|
|
@@ -1759,6 +1765,7 @@ describe("QgridFrame Grok registration and routing", () => {
|
|
|
1759
1765
|
zdrVideoExcluded: true,
|
|
1760
1766
|
keepaliveApplicable: false,
|
|
1761
1767
|
});
|
|
1768
|
+
expect(refreshUsage).toHaveBeenCalledWith(9);
|
|
1762
1769
|
});
|
|
1763
1770
|
|
|
1764
1771
|
it("usage falls back to the stored tier before the first billing fetch", async () => {
|
|
@@ -2005,7 +2012,8 @@ describe("QgridFrame Grok media and voice (U11)", () => {
|
|
|
2005
2012
|
|
|
2006
2013
|
it("answers an oversize JSON body with a Sonamu 413 instead of a 500", async () => {
|
|
2007
2014
|
const server = Fastify({ bodyLimit: REQUEST_BODY_LIMIT_BYTES });
|
|
2008
|
-
|
|
2015
|
+
// Fastify 5 types handler errors as unknown; Sonamu's lifecycle.onError passes an Error.
|
|
2016
|
+
server.setErrorHandler<FastifyError>((error, _request, reply) => {
|
|
2009
2017
|
handleServerError(mapRequestBodyTooLarge(error), reply);
|
|
2010
2018
|
});
|
|
2011
2019
|
server.post("/media", async () => ({ ok: true }));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
3
|
|
|
3
4
|
import { getLogger } from "@logtape/logtape";
|
|
4
5
|
import { type FastifyReply, type FastifyRequest } from "fastify";
|
|
@@ -104,6 +105,7 @@ import {
|
|
|
104
105
|
beforeQuery,
|
|
105
106
|
finishRunAborted,
|
|
106
107
|
finishRunWithError,
|
|
108
|
+
runProgressRecorder,
|
|
107
109
|
} from "./qgrid-run-lifecycle";
|
|
108
110
|
import {
|
|
109
111
|
buildAndValidateStrictOutputSchema,
|
|
@@ -255,6 +257,27 @@ function grokOAuthBadRequest(cause: unknown): never {
|
|
|
255
257
|
throw cause;
|
|
256
258
|
}
|
|
257
259
|
|
|
260
|
+
// The usage view waits this long for a lookup refresh; a slower one still fills the cache.
|
|
261
|
+
const GROK_USAGE_REFRESH_WAIT_MS = 3_000;
|
|
262
|
+
|
|
263
|
+
async function refreshGrokUsage(tokenId: number): Promise<void> {
|
|
264
|
+
const refresh = QgridDispatcher.grokDispatcher?.refreshUsage?.(tokenId);
|
|
265
|
+
|
|
266
|
+
if (!refresh) return;
|
|
267
|
+
|
|
268
|
+
const settled = (async () => {
|
|
269
|
+
try {
|
|
270
|
+
await refresh;
|
|
271
|
+
} catch (e) {
|
|
272
|
+
logger.warn(
|
|
273
|
+
`grok usage refresh failed for token ${tokenId}: ${e instanceof Error ? e.message : String(e)}`,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
})();
|
|
277
|
+
|
|
278
|
+
await Promise.race([settled, sleep(GROK_USAGE_REFRESH_WAIT_MS)]);
|
|
279
|
+
}
|
|
280
|
+
|
|
258
281
|
function grokTokenSnapshot(tokenId: number): GrokTokenStateSnapshot | undefined {
|
|
259
282
|
// Token-state reporting is optional on the routing port; the concrete GrokDispatcher has it.
|
|
260
283
|
return QgridDispatcher.grokDispatcher?.tokenStates?.().find((state) => state.id === tokenId);
|
|
@@ -1014,7 +1037,13 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
1014
1037
|
let result: QueryOutput;
|
|
1015
1038
|
|
|
1016
1039
|
try {
|
|
1017
|
-
result = await QgridDispatcher.query(
|
|
1040
|
+
result = await QgridDispatcher.query(
|
|
1041
|
+
{
|
|
1042
|
+
...resolvedArgs,
|
|
1043
|
+
onProgress: runProgressRecorder(requestLogId, stepIndex, resolvedArgs),
|
|
1044
|
+
},
|
|
1045
|
+
disconnect.signal,
|
|
1046
|
+
);
|
|
1018
1047
|
} catch (e) {
|
|
1019
1048
|
const completedDriver = completedDriverFromImageFailure(e, resolvedArgs.serviceTier);
|
|
1020
1049
|
|
|
@@ -1120,7 +1149,12 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
1120
1149
|
|
|
1121
1150
|
try {
|
|
1122
1151
|
await QgridDispatcher.queryStream(
|
|
1123
|
-
|
|
1152
|
+
runInfo
|
|
1153
|
+
? {
|
|
1154
|
+
...args,
|
|
1155
|
+
onProgress: runProgressRecorder(runInfo.requestLogId, runInfo.stepIndex, args),
|
|
1156
|
+
}
|
|
1157
|
+
: args,
|
|
1124
1158
|
{
|
|
1125
1159
|
onDelta: (text) => {
|
|
1126
1160
|
if (!clientClosed && !sse.closed) sse.publish("delta", { text });
|
|
@@ -2085,7 +2119,9 @@ class QgridFrameClass extends BaseFrameClass {
|
|
|
2085
2119
|
}
|
|
2086
2120
|
|
|
2087
2121
|
if (entry.provider === "grok") {
|
|
2088
|
-
//
|
|
2122
|
+
// Refresh stale lookups (60 s cache) so a token without traffic still reports usage.
|
|
2123
|
+
if (entry.active) await refreshGrokUsage(entry.id);
|
|
2124
|
+
|
|
2089
2125
|
const snapshot = entry.active ? grokTokenSnapshot(entry.id) : undefined;
|
|
2090
2126
|
const billing = snapshot?.lastBilling;
|
|
2091
2127
|
const storedTier = StoredGrokCredentials.safeParse(entry.credentials).data?.subscriptionTier;
|
|
@@ -341,9 +341,9 @@ function inlineImageBytes(refs: ReadonlyArray<string | undefined>): number {
|
|
|
341
341
|
let total = 0;
|
|
342
342
|
|
|
343
343
|
for (const ref of refs) {
|
|
344
|
-
const
|
|
344
|
+
const base64 = ref === undefined ? undefined : IMAGE_DATA_URL.exec(ref)?.[2];
|
|
345
345
|
|
|
346
|
-
if (
|
|
346
|
+
if (base64 !== undefined) total += base64DecodedBytes(base64);
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
return total;
|
|
@@ -366,14 +366,14 @@ export const MediaImageRef = z
|
|
|
366
366
|
.min(1)
|
|
367
367
|
.superRefine((value, ctx) => {
|
|
368
368
|
if (value.startsWith("data:")) {
|
|
369
|
-
const
|
|
369
|
+
const base64 = IMAGE_DATA_URL.exec(value)?.[2];
|
|
370
370
|
|
|
371
|
-
if (
|
|
371
|
+
if (base64 === undefined || base64.length % 4 !== 0) {
|
|
372
372
|
ctx.addIssue({
|
|
373
373
|
code: "custom",
|
|
374
374
|
message: "image data URLs must be base64 image/png, image/jpeg or image/webp",
|
|
375
375
|
});
|
|
376
|
-
} else if (base64DecodedBytes(
|
|
376
|
+
} else if (base64DecodedBytes(base64) > MEDIA_MAX_INLINE_BYTES) {
|
|
377
377
|
ctx.addIssue({
|
|
378
378
|
code: "custom",
|
|
379
379
|
message: `image data URL exceeds ${MEDIA_MAX_INLINE_LABEL}`,
|
|
@@ -109,8 +109,10 @@ export interface FinishRunParams {
|
|
|
109
109
|
|
|
110
110
|
type FinishRunUpdate = Partial<FinishRunParams> & { id: number; ttft_ms?: number };
|
|
111
111
|
|
|
112
|
+
export type RunProgressUpdate = { token_name?: string; model_name?: string; ttft_ms?: number };
|
|
113
|
+
|
|
112
114
|
/** Copies `key` only when the caller supplied it, so omitted columns stay untouched. */
|
|
113
|
-
function copyDefined<T
|
|
115
|
+
function copyDefined<T>(target: Partial<T>, source: T, key: keyof T): void {
|
|
114
116
|
if (source[key] !== undefined) target[key] = source[key];
|
|
115
117
|
}
|
|
116
118
|
|
|
@@ -654,6 +656,15 @@ class RequestLogModelClass extends BaseModelClass<
|
|
|
654
656
|
});
|
|
655
657
|
}
|
|
656
658
|
|
|
659
|
+
/** Writes facts known mid-run onto a parent that is still running; finished runs stay as is. */
|
|
660
|
+
async recordRunProgress(requestLogId: number, progress: RunProgressUpdate): Promise<void> {
|
|
661
|
+
await this.getPuri("w")
|
|
662
|
+
.from("request_logs")
|
|
663
|
+
.where("id", requestLogId)
|
|
664
|
+
.where("status", "running")
|
|
665
|
+
.update(progress);
|
|
666
|
+
}
|
|
667
|
+
|
|
657
668
|
async finishRun(requestLogId: number, params: FinishRunParams): Promise<void> {
|
|
658
669
|
if (params.status === "succeeded" && !params.token_name) {
|
|
659
670
|
throw new Error("tokenName is required for succeeded runs");
|
|
@@ -43,6 +43,20 @@ const oauthCallbackQuerySchema = z.looseObject({
|
|
|
43
43
|
state: z.string().optional(),
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
async function oauthCallback(request: FastifyRequest, reply: FastifyReply) {
|
|
47
|
+
const { code, state } = oauthCallbackQuerySchema.safeParse(request.query).data ?? {};
|
|
48
|
+
|
|
49
|
+
if (!code || !state) {
|
|
50
|
+
return reply.redirect("/?oauth=error&reason=missing_params");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
return QgridFrame.handleOAuthCallback(code, state, reply);
|
|
55
|
+
} catch {
|
|
56
|
+
return reply.redirect("/?oauth=error&reason=callback_failed");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
46
60
|
const host = process.env.HOST ?? "localhost";
|
|
47
61
|
const port = Number(process.env.PORT ?? 44900);
|
|
48
62
|
|
|
@@ -121,20 +135,6 @@ export default defineConfig({
|
|
|
121
135
|
prefix: "/api/public",
|
|
122
136
|
},
|
|
123
137
|
custom: (server) => {
|
|
124
|
-
const oauthCallback = async (request: FastifyRequest, reply: FastifyReply) => {
|
|
125
|
-
const { code, state } = oauthCallbackQuerySchema.safeParse(request.query).data ?? {};
|
|
126
|
-
|
|
127
|
-
if (!code || !state) {
|
|
128
|
-
return reply.redirect("/?oauth=error&reason=missing_params");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
return QgridFrame.handleOAuthCallback(code, state, reply);
|
|
133
|
-
} catch {
|
|
134
|
-
return reply.redirect("/?oauth=error&reason=callback_failed");
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
138
|
server.get("/callback", oauthCallback);
|
|
139
139
|
server.get("/auth/callback", oauthCallback);
|
|
140
140
|
},
|
|
@@ -276,6 +276,7 @@ export class AnthropicDispatcher implements ProviderDispatcher {
|
|
|
276
276
|
const token = await this.selectToken(model, req.preferredTokenId);
|
|
277
277
|
|
|
278
278
|
if (!token) throw new Error("No anthropic tokens available");
|
|
279
|
+
req.onProgress?.({ tokenName: token.name, model });
|
|
279
280
|
|
|
280
281
|
// 만료 직전에 갱신하되 실패하면 기존 토큰으로 진행한다.
|
|
281
282
|
let accessToken = token.credentials.accessToken;
|
|
@@ -318,6 +319,7 @@ export class AnthropicDispatcher implements ProviderDispatcher {
|
|
|
318
319
|
input: req.coldInput,
|
|
319
320
|
abortSignal: req.abortSignal,
|
|
320
321
|
includePartialMessages: opts?.includePartialMessages,
|
|
322
|
+
onTtft: req.onProgress ? (ttftMs) => req.onProgress?.({ ttftMs }) : undefined,
|
|
321
323
|
},
|
|
322
324
|
onDelta,
|
|
323
325
|
);
|
|
@@ -113,6 +113,8 @@ export interface ClaudeSessionRequest {
|
|
|
113
113
|
input: Array<UserInput>;
|
|
114
114
|
abortSignal?: AbortSignal;
|
|
115
115
|
includePartialMessages?: boolean;
|
|
116
|
+
/** Called once with the measured TTFT when the first delta arrives. */
|
|
117
|
+
onTtft?: (ttftMs: number) => void;
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
export interface ClaudeSessionResult extends ClaudeStreamResult {
|
|
@@ -364,7 +366,19 @@ export function runClaudeSession(
|
|
|
364
366
|
let buffer = "";
|
|
365
367
|
const streamState: ClaudeStreamJsonState = {};
|
|
366
368
|
const ttftTracker = createTtftTracker();
|
|
367
|
-
|
|
369
|
+
let ttftReported = false;
|
|
370
|
+
|
|
371
|
+
const onTrackedDelta = ttftTracker.wrapDelta((text) => {
|
|
372
|
+
const ttftMs = ttftTracker.value();
|
|
373
|
+
|
|
374
|
+
if (!ttftReported && ttftMs !== null) {
|
|
375
|
+
ttftReported = true;
|
|
376
|
+
req.onTtft?.(ttftMs);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
onDelta(text);
|
|
380
|
+
});
|
|
381
|
+
|
|
368
382
|
// bounded stderr 버퍼(최근 ~4KB만 유지 — 무한 누적 방지).
|
|
369
383
|
let stderrBuf = "";
|
|
370
384
|
const STDERR_CAP = 4096;
|
|
@@ -249,14 +249,16 @@ export function usdFromGrokTicks(ticks: number): number {
|
|
|
249
249
|
return ticks / GROK_TICKS_PER_USD;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
// ticks per token -> USD per 1M tokens.
|
|
253
|
+
function usdPerMillionFromGrokTicks(ticks: number): number {
|
|
254
|
+
return (ticks * 1_000_000) / GROK_TICKS_PER_USD;
|
|
255
|
+
}
|
|
255
256
|
|
|
257
|
+
function grokTokenCosts(input: number, cached: number, output: number): ModelCosts {
|
|
256
258
|
return {
|
|
257
|
-
inputTokens:
|
|
258
|
-
cachedInputTokens:
|
|
259
|
-
outputTokens:
|
|
259
|
+
inputTokens: usdPerMillionFromGrokTicks(input),
|
|
260
|
+
cachedInputTokens: usdPerMillionFromGrokTicks(cached),
|
|
261
|
+
outputTokens: usdPerMillionFromGrokTicks(output),
|
|
260
262
|
};
|
|
261
263
|
}
|
|
262
264
|
|
|
@@ -127,6 +127,16 @@ export interface GenerateRequest {
|
|
|
127
127
|
providerOptions?: { [key: string]: JsonValue | undefined };
|
|
128
128
|
// Native tools for providers that accept them on the wire (Grok).
|
|
129
129
|
tools?: ToolDefinition[];
|
|
130
|
+
// Reports run facts as soon as they are known, before the turn completes. Each call carries only
|
|
131
|
+
// the fields that just became known; a failover reports the next token again.
|
|
132
|
+
onProgress?: (progress: GenerateProgress) => void;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface GenerateProgress {
|
|
136
|
+
tokenName?: string;
|
|
137
|
+
/** Serving model without the provider prefix. */
|
|
138
|
+
model?: string;
|
|
139
|
+
ttftMs?: number;
|
|
130
140
|
}
|
|
131
141
|
|
|
132
142
|
export interface GenerateResult {
|
|
@@ -39,7 +39,12 @@ export type GrokFunctionTool = {
|
|
|
39
39
|
strict: boolean;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export type GrokTool =
|
|
42
|
+
export type GrokTool =
|
|
43
|
+
| GrokFunctionTool
|
|
44
|
+
| { type: "web_search" }
|
|
45
|
+
| { type: "x_search" }
|
|
46
|
+
// Server-side Grok Imagine tool; results arrive as `image_generation_call` output items.
|
|
47
|
+
| { type: "image_generation" };
|
|
43
48
|
|
|
44
49
|
export type GrokToolChoice = "auto" | "none" | "required" | { type: "function"; name: string };
|
|
45
50
|
|
|
@@ -81,14 +81,13 @@ export interface GrokSeedModel {
|
|
|
81
81
|
|
|
82
82
|
// U0 capture 2026-10-16 (GET /models: four ids, context_window 256000, default effort high)
|
|
83
83
|
export const GROK_SEED_MODELS: readonly GrokSeedModel[] = Object.freeze(
|
|
84
|
-
["grok-4.7", "grok-4.7-build-fast", "grok-4.6", "grok-4.5"].map(
|
|
85
|
-
(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}),
|
|
84
|
+
["grok-4.7", "grok-4.7-build-fast", "grok-4.6", "grok-4.5"].map((id): GrokSeedModel =>
|
|
85
|
+
Object.freeze({
|
|
86
|
+
id,
|
|
87
|
+
contextWindow: 256_000,
|
|
88
|
+
reasoningEfforts: GROK_REASONING_EFFORTS,
|
|
89
|
+
defaultEffort: "high",
|
|
90
|
+
}),
|
|
92
91
|
),
|
|
93
92
|
);
|
|
94
93
|
|
|
@@ -449,6 +449,17 @@ describe("GrokDispatcher selection", () => {
|
|
|
449
449
|
expect(h.events).toEqual([]);
|
|
450
450
|
});
|
|
451
451
|
|
|
452
|
+
it("refreshUsage reads billing for a token without a quota threshold", async () => {
|
|
453
|
+
const h = createHarness();
|
|
454
|
+
h.add(1);
|
|
455
|
+
h.billing.set(1, billingAt(12));
|
|
456
|
+
|
|
457
|
+
await h.dispatcher.refreshUsage(1);
|
|
458
|
+
|
|
459
|
+
expect(h.dispatcher.tokenStates()[0]?.lastBilling).toMatchObject({ utilizationPct: 12 });
|
|
460
|
+
expect(h.events.some((event) => event.startsWith("/billing"))).toBe(true);
|
|
461
|
+
});
|
|
462
|
+
|
|
452
463
|
it("blocks over-threshold tokens and reports QuotaThresholdExceededError", async () => {
|
|
453
464
|
const h = createHarness();
|
|
454
465
|
h.add(1, 1, 50);
|
|
@@ -529,9 +540,9 @@ describe("GrokDispatcher chat", () => {
|
|
|
529
540
|
it("rejects fields Grok does not support", async () => {
|
|
530
541
|
const h = createHarness();
|
|
531
542
|
h.add(1);
|
|
532
|
-
await expect(
|
|
533
|
-
|
|
534
|
-
);
|
|
543
|
+
await expect(
|
|
544
|
+
h.dispatcher.generate(request({ imageGenerationOptions: { quality: "high" } })),
|
|
545
|
+
).rejects.toBeInstanceOf(GrokInvalidRequestError);
|
|
535
546
|
await expect(h.dispatcher.generate(request({ serviceTier: "fast" }))).rejects.toBeInstanceOf(
|
|
536
547
|
GrokInvalidRequestError,
|
|
537
548
|
);
|
|
@@ -829,6 +840,66 @@ describe("GrokDispatcher chat", () => {
|
|
|
829
840
|
// Media routing
|
|
830
841
|
// ---------------------------------------------------------------------------
|
|
831
842
|
|
|
843
|
+
describe("GrokDispatcher image generation tool", () => {
|
|
844
|
+
it("adds the server-side image tool and returns completed images", async () => {
|
|
845
|
+
const h = createHarness();
|
|
846
|
+
h.add(1);
|
|
847
|
+
const imageItem = {
|
|
848
|
+
type: "image_generation_call",
|
|
849
|
+
id: "ig_1",
|
|
850
|
+
status: "completed",
|
|
851
|
+
result: "/9j/4AAQSkZJRg",
|
|
852
|
+
prompt: "a small red apple",
|
|
853
|
+
};
|
|
854
|
+
h.chat.set(1, [
|
|
855
|
+
{
|
|
856
|
+
kind: "ok",
|
|
857
|
+
body: [
|
|
858
|
+
sseEvent({ type: "response.created", response: { id: "resp_1", model: "grok-4.7" } }),
|
|
859
|
+
sseEvent({ type: "response.output_item.done", item: imageItem }),
|
|
860
|
+
sseEvent({ type: "response.output_text.delta", item_id: "msg_1", delta: "Here it is." }),
|
|
861
|
+
sseEvent({
|
|
862
|
+
type: "response.completed",
|
|
863
|
+
response: { id: "resp_1", model: "grok-4.7", usage: golden.response.terminalUsage },
|
|
864
|
+
}),
|
|
865
|
+
].join(""),
|
|
866
|
+
},
|
|
867
|
+
]);
|
|
868
|
+
|
|
869
|
+
const result = await h.dispatcher.generate(request({ imageGeneration: "auto" }));
|
|
870
|
+
|
|
871
|
+
expect(h.requests[0]?.body).toMatchObject({ tools: [{ type: "image_generation" }] });
|
|
872
|
+
expect(result.text).toBe("Here it is.");
|
|
873
|
+
expect(result.images).toEqual([
|
|
874
|
+
{ data: "/9j/4AAQSkZJRg", mediaType: "image/jpeg", revisedPrompt: "a small red apple" },
|
|
875
|
+
]);
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
it("reports the token, serving model, and TTFT as progress", async () => {
|
|
879
|
+
const h = createHarness();
|
|
880
|
+
h.add(1);
|
|
881
|
+
const progress = vi.fn();
|
|
882
|
+
|
|
883
|
+
await h.dispatcher.generate(request({ onProgress: progress }));
|
|
884
|
+
|
|
885
|
+
expect(progress.mock.calls.map(([update]) => update)).toEqual([
|
|
886
|
+
{ tokenName: "t1" },
|
|
887
|
+
{ model: "grok-4.7" },
|
|
888
|
+
{ ttftMs: expect.any(Number) },
|
|
889
|
+
]);
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
it("sends no image tool without imageGeneration", async () => {
|
|
893
|
+
const h = createHarness();
|
|
894
|
+
h.add(1);
|
|
895
|
+
|
|
896
|
+
const result = await h.dispatcher.generate(request());
|
|
897
|
+
|
|
898
|
+
expect(h.requests[0]?.body).not.toHaveProperty("tools");
|
|
899
|
+
expect(result.images).toBeUndefined();
|
|
900
|
+
});
|
|
901
|
+
});
|
|
902
|
+
|
|
832
903
|
describe("GrokDispatcher media", () => {
|
|
833
904
|
it("blocks the request class on media 403 and fails over once", async () => {
|
|
834
905
|
const seen: string[] = [];
|