Phase 2: the loop and the model gateway. The composer in the console has
said "Not connected yet" since it was built, because there was no
assistant endpoint anywhere. There is one now.
- utils/chat.go the gateway, a sibling of embedding.go: one small
interface, a provider switch, the shared postJSON, no
framework. Agents name a TIER (fast/balanced/deep) and
config maps tier to model, so changing provider does not
touch an agent.
- services/assistantService.go one loop for every agent. An agent is a
name, a tier, a prompt and an allow-list — data, not a
class — so a sixth is config rather than a subclass.
- the endpoint under /v1/web, inheriting middleware.WebAuth along with
every other console route. The assistant reads the same data the console
does and must read it as the same person.
What the model does not get to decide:
whose data the caller is built from the verified session in the
controller, never from the request body — there is no
tenant field to fill in. A test scripts the model calling
a tool with {"tenantid": 916} and asserts it ran for 1147.
which tools the registry enforces the agent's allow-list; a test
scripts a call to a tool the agent lacks and asserts the
handler never ran.
when to stop steps and tool calls are counted here. A model that keeps
calling tools is stopped by arithmetic, not by being
asked nicely.
Two quiet failures have tests of their own. A finish_reason of "length"
means the provider cut the reply off mid-sentence, which reads exactly
like a complete answer unless it is flagged. And a truncated tool result
reaches the model in words it will repeat — otherwise it describes a
capped list and an empty one identically.
A refused tool goes back as a message, not an error: a model told "that
tool needs a tenant" can explain it, where a model handed nothing says
"something went wrong".
Optional, like the embedder. Without ASSISTANT_PROVIDER the endpoint
answers "not switched on here", the composer stays disabled, and the tools
still work — they are ordinary Go functions, and only turning a sentence
into a tool call needs a model.
14 tests, against a scripted model rather than a live provider: these are
about what the loop refuses to let a model do, and that has to hold for
any model, including one behaving badly.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package routes
|
|
|
|
import (
|
|
"nearle/facade"
|
|
"nearle/middleware"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func RegisterRoutes(app *fiber.App, f *facade.Facade) {
|
|
|
|
api := app.Group("/live/api")
|
|
|
|
// Console sessions.
|
|
//
|
|
// Mounted by PATH rather than on a group object, because the `/v1/web`
|
|
// routes are not one group — a dozen files each create their own
|
|
// (`/v1/web/users`, `/v1/web/orders`, `/v1/web/products`, …). Registered
|
|
// here, ahead of all of them, so a route added later is guarded by default
|
|
// rather than by somebody remembering to.
|
|
//
|
|
// `/v1/pos` is deliberately NOT covered: that is the terminal surface, it
|
|
// carries a different kind of token, and it has its own guard. But
|
|
// `/v1/web/pos` and `/v1/web/tenants` ARE, despite their names — both are
|
|
// console callers, and `createposuser` on the second mints till credentials,
|
|
// which until now it did on the strength of an unauthenticated request. The
|
|
// note above registerPosStaffConsoleRoutes asked for exactly this.
|
|
api.Use("/v1/web", middleware.WebAuth(f.PosService()))
|
|
|
|
RegisterUserRoutes(api, f)
|
|
RegisterProductRoutes(api, f)
|
|
RegisterOrderRoutes(api, f)
|
|
RegisterDeliveriesRoutes(api, f)
|
|
RegisterUtilsRoutes(api, f)
|
|
RegisterTenantRoutes(api, f)
|
|
RegisterPartnerRoutes(api, f)
|
|
RegisterCustomerRoutes(api, f)
|
|
RegisterCatalogueRoutes(api, f)
|
|
RegisterPosRoutes(api, f)
|
|
RegisterUploadRoutes(api, f)
|
|
RegisterScanRoutes(api, f)
|
|
RegisterAssistantRoutes(api, f)
|
|
}
|