From a692f6199d4794a37ecdd006d7cc7dafcba9592a Mon Sep 17 00:00:00 2001 From: AI 13rac1 Date: Sat, 14 Nov 2026 03:30:28 +0000 Subject: [PATCH] Revert "Merge pull request #220 from ai-13rac1/neardirect-extra-models" This reverts commit 839342d3, reversing changes made to 64a134ab. NEAR AI direct answers 404 for z-ai/glm-5.3-flash-long since 2026-11-14 about 03:00Z while /endpoints still lists it. Co-Authored-By: Claude Opus 5.5 --- docs/api_support.md | 5 +- internal/provider/neardirect/models.go | 95 --------------------- internal/provider/neardirect/models_test.go | 91 -------------------- internal/proxy/proxy.go | 4 +- 4 files changed, 3 insertions(+), 192 deletions(-) delete mode 100644 internal/provider/neardirect/models.go delete mode 100644 internal/provider/neardirect/models_test.go diff --git a/docs/api_support.md b/docs/api_support.md index 1a0fa25e..db0f3b21 100644 --- a/docs/api_support.md +++ b/docs/api_support.md @@ -237,10 +237,7 @@ With `base_url = "https://completions.near.ai"` (the default), or `/endpoints`. Set `[providers.neardirect].base_url` to an explicit HTTPS backend origin to disable endpoint discovery in both commands. That origin is used for attestation and inference for every requested model; all attestation, TLS, and -E2EE checks still apply. The `/v1/models` catalog remains gateway-provided: -it lists the models that `cloud-api.near.ai/v1/models` returns with `owned_by` `"nearai"`. -It also lists `z-ai/glm-5.3-flash-long`, which that catalog does not list, -while `/endpoints` serves it; with an explicit backend origin it does not. +E2EE checks still apply. The `/v1/models` catalog remains gateway-provided. `teep verify` does not send its chat probe to the five NEAR models that serve another endpoint; see [models the probe does not cover](providers/near/near_attestation.md#models-the-probe-does-not-cover). diff --git a/internal/provider/neardirect/models.go b/internal/provider/neardirect/models.go deleted file mode 100644 index 6a3cb2d6..00000000 --- a/internal/provider/neardirect/models.go +++ /dev/null @@ -1,95 +0,0 @@ -package neardirect - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "log/slog" - "slices" - - "github.com/13rac1/teep/internal/provider" - "github.com/13rac1/teep/internal/provider/nearroute" -) - -// extraModels holds the models that teep lists for neardirect although -// the NEAR AI catalog (cloud-api.near.ai/v1/models) does not list them with -// owned_by "nearai". Teep lists each one only while the endpoint list of -// completions.near.ai serves it. -// -// z-ai/glm-5.3-flash-long, 2026-11-13: the endpoint list serves it on a NEAR -// AI TEE endpoint and it passed verification with no enforced failure, but -// the catalog does not list it. -var extraModels = []string{"z-ai/glm-5.3-flash-long"} - -// modelLister adds the extra models that the endpoint list serves to the -// catalog models of owned_by "nearai". -type modelLister struct { - inner provider.ModelLister - attester *Attester -} - -// NewModelLister returns the neardirect model lister: the models of inner, -// and each extra model that the attester's endpoint list serves. -func NewModelLister(inner provider.ModelLister, attester *Attester) provider.ModelLister { - return &modelLister{inner: inner, attester: attester} -} - -// ListModels returns the inner models and the served extra models that the -// inner models do not hold. The inner lister decodes each entry and -// requires its id, so every entry here is a JSON object with an id; an -// entry that does not decode is an error of that guarantee. -func (l *modelLister) ListModels(ctx context.Context) ([]json.RawMessage, error) { - models, err := l.inner.ListModels(ctx) - if err != nil { - return nil, err - } - ids := make([]string, 0, len(models)) - for _, raw := range models { - var entry struct { - ID string `json:"id"` - } - if err := json.Unmarshal(raw, &entry); err != nil { - return nil, fmt.Errorf("models: read model id: %w", err) - } - ids = append(ids, entry.ID) - } - for _, model := range extraModels { - if slices.Contains(ids, model) || !l.attester.servesModel(ctx, model) { - continue - } - raw, err := json.Marshal(map[string]string{"id": model, "object": "model"}) - if err != nil { - return nil, fmt.Errorf("models: encode %s: %w", model, err) - } - models = append(models, raw) - } - return models, nil -} - -// CloseIdleConnections forwards cleanup to the wrapped lister. -func (l *modelLister) CloseIdleConnections() { - if closer, ok := l.inner.(interface{ CloseIdleConnections() }); ok { - closer.CloseIdleConnections() - } -} - -// servesModel reports whether the endpoint list serves model. A configured -// static origin has no endpoint list, so it serves no extra model. An error -// other than an unknown model, such as an endpoint list outage, is logged -// at debug level and reads as not served. -func (a *Attester) servesModel(ctx context.Context, model string) bool { - if a.origin.Static { - return false - } - resolver, ok := a.resolver.(*EndpointResolver) - if !ok { - return false - } - _, err := resolver.mappingForModel(ctx, model) - var routeErr *nearroute.Error - if err != nil && (!errors.As(err, &routeErr) || routeErr.Kind != nearroute.UnknownModel) { - slog.DebugContext(ctx, "endpoint list lookup failed; extra model not listed", "model", model, "err", err) - } - return err == nil -} diff --git a/internal/provider/neardirect/models_test.go b/internal/provider/neardirect/models_test.go deleted file mode 100644 index 9e6f7d48..00000000 --- a/internal/provider/neardirect/models_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package neardirect - -import ( - "context" - "encoding/json" - "net/http" - "net/http/httptest" - "slices" - "testing" -) - -type staticLister []string - -func (l staticLister) ListModels(context.Context) ([]json.RawMessage, error) { - out := make([]json.RawMessage, 0, len(l)) - for _, id := range l { - out = append(out, json.RawMessage(`{"id":"`+id+`","object":"model","owned_by":"nearai"}`)) - } - return out, nil -} - -func listedIDs(t *testing.T, l *modelLister) []string { - t.Helper() - models, err := l.ListModels(t.Context()) - if err != nil { - t.Fatal(err) - } - ids := make([]string, 0, len(models)) - for _, raw := range models { - var e struct { - ID string `json:"id"` - } - if err := json.Unmarshal(raw, &e); err != nil { - t.Fatal(err) - } - ids = append(ids, e.ID) - } - return ids -} - -// The endpoint list of 2026-11-13 serves z-ai/glm-5.3-flash-long, which the -// catalog does not list; teep lists it while the endpoint list serves it. -func TestModelListerExtraModels(t *testing.T) { - if !slices.Contains(extraModels, "z-ai/glm-5.3-flash-long") { - t.Fatalf("extra models = %v", extraModels) - } - endpoints := func(models ...string) *Attester { - t.Helper() - body, err := json.Marshal(map[string]any{"endpoints": []any{ - map[string]any{"domain": "glm-5-3-flash-i0.completions.near.ai", "models": models}, - }}) - if err != nil { - t.Fatal(err) - } - srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.Header().Set("Content-Type", "application/json") - _, _ = w.Write(body) - })) - t.Cleanup(srv.Close) - r := newEndpointResolverForTest(srv.URL) - r.client = srv.Client() - t.Cleanup(r.Stop) - return NewAttesterWithResolver("https://completions.near.ai", "key", r) - } - for _, tc := range []struct { - name string - inner staticLister - want []string - attester func() *Attester - }{ - {"served", staticLister{"z-ai/glm-5.3-flash"}, - []string{"z-ai/glm-5.3-flash", "z-ai/glm-5.3-flash-long"}, - func() *Attester { return endpoints("z-ai/glm-5.3-flash", "z-ai/glm-5.3-flash-long") }}, - {"not served", staticLister{"z-ai/glm-5.3-flash"}, - []string{"z-ai/glm-5.3-flash"}, - func() *Attester { return endpoints("z-ai/glm-5.3-flash") }}, - {"already in the catalog", staticLister{"z-ai/glm-5.3-flash-long"}, - []string{"z-ai/glm-5.3-flash-long"}, - func() *Attester { return endpoints("z-ai/glm-5.3-flash-long") }}, - {"static origin", staticLister{"m"}, - []string{"m"}, - func() *Attester { return NewAttester("https://backend.example:8443", "key") }}, - } { - t.Run(tc.name, func(t *testing.T) { - l := NewModelLister(tc.inner, tc.attester()).(*modelLister) - if got := listedIDs(t, l); !slices.Equal(got, tc.want) { - t.Errorf("models = %v, want %v", got, tc.want) - } - }) - } -} diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 59f840ad..0f8daabc 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -755,10 +755,10 @@ func fromConfig( p.Preparer = neardirect.NewPreparer(cp.APIKey) p.ReportDataVerifier = rdVerifier p.SupplyChainPolicy = neardirect.SupplyChainPolicy() - p.ModelLister = neardirect.NewModelLister(provider.NewOwnedByModelLister( + p.ModelLister = provider.NewOwnedByModelLister( "https://"+nearcloud.GatewayHost(), cp.APIKey, config.NewAttestationClient(offline), "nearai", - ), attester) + ) case "nearcloud": p.ChatPath = "/v1/chat/completions" p.ImagesPath = "/v1/images/generations"