Documentation
¶
Overview ¶
Package tools holds the services behind the MCP tools. Handlers in internal/mcpserver call these functions with the tenant taken from the caller's principal; the services never read identity from the request.
Index ¶
- Constants
- type Caller
- type ConfirmOrderInput
- type CreateSalesOrderInput
- type Decider
- type Document
- type ExtractNoteInput
- type ExtractNoteOutput
- type ListInboxInput
- type ListInboxOutput
- type Note
- type OrderRefInput
- type OrderResult
- func ConfirmOrder(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func CreateSalesOrder(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func OpenConfirmOrder(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func OpenCreateSalesOrder(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func OpenPostVendorInvoice(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func OpenSendASN(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func OpenSendEmail(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func OpenWMSReserve(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func PostVendorInvoice(ctx context.Context, st *store.Store, dec Decider, c Caller, ...) (OrderResult, error)
- func SendASN(ctx context.Context, st *store.Store, dec Decider, c Caller, in OrderRefInput) (OrderResult, error)
- func SendEmail(ctx context.Context, st *store.Store, dec Decider, c Caller, in SendEmailInput) (OrderResult, error)
- func SendShipNotice(ctx context.Context, st *store.Store, dec Decider, sg store.Saga, ...) (OrderResult, error)
- func WMSReserve(ctx context.Context, st *store.Store, dec Decider, c Caller, in OrderRefInput) (OrderResult, error)
- type PlainEnv
- func (e PlainEnv) PlainConfirmOrder(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
- func (e PlainEnv) PlainCreateSalesOrder(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
- func (e PlainEnv) PlainPostVendorInvoice(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
- func (e PlainEnv) PlainSendASN(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
- func (e PlainEnv) PlainSendEmail(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
- func (e PlainEnv) PlainWMSReserve(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
- type PlainResult
- type PostVendorInvoiceInput
- type PriceListInput
- type PriceListOutput
- type PriceRow
- type RawDocumentOutput
- type RawText
- type ReadDocumentInput
- type ReadDocumentOutput
- type SendEmailInput
- type TxnStatusInput
- type TxnStatusOutput
Constants ¶
const ( ConfirmOrderTool = "erp.confirm_order" WMSReserveTool = "wms.reserve" SendASNTool = "edi.send_asn" )
Names under which the keys are made. They are part of the idempotency key (I2).
const CreateOrderTool = "erp.create_sales_order"
CreateOrderTool is the name under which the order is reserved. It is part of the idempotency key (I2), so it must never change for a deployed database.
const PostInvoiceTool = "erp.post_vendor_invoice"
PostInvoiceTool is the name of erp.post_vendor_invoice (T3, money). It is part of the idempotency key (I2), so it must never change for a deployed database.
const PriceListTool = "erp.get_price_list"
PriceListTool is erp.get_price_list (T0, sensitive): the prices of the caller's tenant.
const SendEmailTool = "notify.send_email"
SendEmailTool is notify.send_email (T2, a sink). It is part of the idempotency key.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Caller ¶
type Caller struct {
TenantID string
PrincipalID string
Kind string
TraceID string
// Args are the raw arguments of the call. ArgsKey (mode no-bizkey, C3-A3) makes the
// idempotency key of the call from them instead of from the business key. RawValues (mode
// no-sanitize, C3-A1) makes the effects take the raw value of an element that failed its format.
Args json.RawMessage
ArgsKey bool
RawValues bool
}
Caller is the identity a tool call runs under, taken from the edge, and the switches of the ablation modes of the benchmark (the zero value is the full gateway).
type ConfirmOrderInput ¶
type ConfirmOrderInput struct {
SalesOrderTxnID string `json:"sales_order_txn_id"`
AckType string `json:"ack_type"` // AC accepted, AD accepted with changes, RJ rejected
}
ConfirmOrderInput is the validated input of erp.confirm_order.
type CreateSalesOrderInput ¶
type CreateSalesOrderInput struct {
SourceDocumentID string `json:"source_document_id"`
DeliveryInstruction string `json:"delivery_instruction,omitempty"`
}
CreateSalesOrderInput is the validated input of erp.create_sales_order. The agent passes a reference to the document and a closed value: no price, partner, address or quantity.
type Decider ¶
type Decider interface {
Decide(ctx context.Context, p policy.Principal, c policy.ToolCall) (policy.Decision, error)
}
Decider is the policy as the tools use it (policy.Engine; tests put a recorder in front of it).
type Document ¶
type Document struct {
ID string `json:"id"`
ST01 string `json:"st01"`
PartnerID string `json:"partner_id"`
BusinessRef string `json:"business_ref"`
ReceivedAt string `json:"received_at"`
Status string `json:"status"`
}
Document is one inbox entry as returned to the agent (explicit field list).
type ExtractNoteInput ¶
type ExtractNoteInput struct {
DocumentID string `json:"document_id"`
Ref string `json:"ref"`
SchemaID string `json:"schema_id"`
}
ExtractNoteInput is the validated input of edi.extract_note.
type ExtractNoteOutput ¶
type ExtractNoteOutput struct {
SchemaID string `json:"schema_id"`
Values json.RawMessage `json:"values"`
Declassified bool `json:"declassified"`
}
ExtractNoteOutput is the result of edi.extract_note: only the values of the closed schema, always declassified.
func ExtractNote ¶
func ExtractNote(ctx context.Context, st *store.Store, reader quarantine.QuarantinedReader, tenantID, traceID string, in ExtractNoteInput) (ExtractNoteOutput, error)
ExtractNote reads one note through the quarantined reader. A note that is not of this tenant, of a hidden document or unknown gives not_found; a missing or refused answer of the model gives quarantine_invalid. The text of the note is never part of the answer.
type ListInboxInput ¶
type ListInboxInput struct {
Status string `json:"status,omitempty"`
Limit int `json:"limit,omitempty"`
}
ListInboxInput is the validated input of edi.list_inbox.
type ListInboxOutput ¶
type ListInboxOutput struct {
Documents []Document `json:"documents"`
}
ListInboxOutput is the result of edi.list_inbox.
func ListInbox ¶
func ListInbox(ctx context.Context, st *store.Store, tenantID string, in ListInboxInput) (ListInboxOutput, error)
ListInbox returns the 850 and 810 documents of a tenant that were accepted, newest first. 997 and rejected sets are never listed.
type Note ¶
type Note struct {
Ref string `json:"ref"`
SegmentPath string `json:"segment_path"`
Reason string `json:"reason"`
}
Note points at a piece of partner text that is kept out of the document: free text, or an element that failed its format. The text itself is not part of the answer.
type OrderRefInput ¶
type OrderRefInput struct {
SalesOrderTxnID string `json:"sales_order_txn_id"`
}
OrderRefInput is the input of wms.reserve and edi.send_asn.
type OrderResult ¶
type OrderResult struct {
Status string `json:"status"`
TxnID string `json:"txn_id"`
Reason string `json:"reason,omitempty"`
ApprovalID string `json:"approval_id,omitempty"`
}
OrderResult is the answer of the tools with an effect (erp.create_sales_order, erp.post_vendor_invoice). Status is accepted (queued), pending_approval (with ApprovalID), or for a failed key rejected or expired. Reason is set for a rejected one only (the recorded outcome of a failed key).
func ConfirmOrder ¶
func ConfirmOrder(ctx context.Context, st *store.Store, dec Decider, c Caller, in ConfirmOrderInput) (OrderResult, error)
ConfirmOrder sends the 855 of an order (T2, irreversible): step 2 of the order saga. The 855 is built from the order; ack_type AC and AD accept every line, RJ rejects every line. The policy compares the amount of the document with the amount of the order (forecast.deviation): a rejection moves it by 100 percent and waits for an operator. The row waits behind step 1, so the 855 never leaves before the order exists in the ERP.
func CreateSalesOrder ¶
func CreateSalesOrder(ctx context.Context, st *store.Store, dec Decider, c Caller, in CreateSalesOrderInput) (OrderResult, error)
CreateSalesOrder turns a received 850 into an order in the ERP, at most once per business key (partner, BEG03).
The document must be an 850 of the tenant in the status received or processed (otherwise not_found). Every line is priced from the price list; a SKU that is not in the list or is a note reference gives policy_denied with explain ["unknown_sku"]. Then the policy decides (internal/policy): refused (policy_denied with the rule names), queued, or waiting for one operator. The key, the request hash, the outbox row or the approval request, and the audit row are written in one transaction (store.Reserve). A call that repeats an earlier one gets the same txn_id; the same business key with a different request gives conflicting_duplicate.
func OpenConfirmOrder ¶
func OpenConfirmOrder(ctx context.Context, st *store.Store, dec Decider, c Caller, args json.RawMessage) (OrderResult, error)
OpenConfirmOrder sends the 855 of the order the partner and the reference name. Lines in the arguments replace the lines of the order; their prices are those of the order, 0.00 for a SKU that is not in it.
func OpenCreateSalesOrder ¶
func OpenCreateSalesOrder(ctx context.Context, st *store.Store, dec Decider, c Caller, args json.RawMessage) (OrderResult, error)
OpenCreateSalesOrder reserves the order of the model: the prices and quantities are its own. The policy still checks the partner, the ship-to against the partner's codes, and the limits.
func OpenPostVendorInvoice ¶
func OpenPostVendorInvoice(ctx context.Context, st *store.Store, dec Decider, c Caller, args json.RawMessage) (OrderResult, error)
OpenPostVendorInvoice books the invoice of the model. The policy compares its total, currency and lines with the order to the supplier, as it does for a received invoice, and the invoice always waits for two operators.
func OpenSendASN ¶
func OpenSendASN(ctx context.Context, st *store.Store, dec Decider, c Caller, args json.RawMessage) (OrderResult, error)
OpenSendASN ships the lines of the model. The policy sees the ship-to of the call, so a code that is not one of the partner's own is refused; the 856 is made later from what the warehouse shipped and from the order, as in the full gateway.
func OpenSendEmail ¶
func OpenSendEmail(ctx context.Context, st *store.Store, dec Decider, c Caller, args json.RawMessage) (OrderResult, error)
OpenSendEmail queues the letter of the model. It names no partner, so the partner is the one that has the address among its contacts; for an address nobody has the policy finds no partner and refuses. The business key is the partner and the hash of the arguments.
func OpenWMSReserve ¶
func OpenWMSReserve(ctx context.Context, st *store.Store, dec Decider, c Caller, args json.RawMessage) (OrderResult, error)
OpenWMSReserve reserves the lines of the model for the order that the reference names.
func PostVendorInvoice ¶
func PostVendorInvoice(ctx context.Context, st *store.Store, dec Decider, c Caller, in PostVendorInvoiceInput) (OrderResult, error)
PostVendorInvoice books a supplier invoice (a received 810) in the ERP, at most once per business key (supplier, BIG02).
The amount, the lines and the details come from the typed 810. The policy checks them against the order to the supplier (the number is BIG04): no such order or a different amount or lines give policy_denied; a matching invoice always waits for two different operators (T3). Otherwise the call works like erp.create_sales_order.
func SendASN ¶
func SendASN(ctx context.Context, st *store.Store, dec Decider, c Caller, in OrderRefInput) (OrderResult, error)
SendASN ships the order and notifies the partner (T2, irreversible): steps 2 and 3 of the shipment saga. This call queues the shipment (wms.ship); the 856 is made from the facts of the warehouse when the shipment is done (SendShipNotice) and goes through the policy then. Without a done reservation the call is policy_denied with saga.order.
func SendEmail ¶
func SendEmail(ctx context.Context, st *store.Store, dec Decider, c Caller, in SendEmailInput) (OrderResult, error)
SendEmail queues a letter to a contact of the partner of a received 850, once per (partner, BEG03, template). The policy checks that the address is a contact of that partner (email.recipient, XP-01); the template must be one the tenant has. A second call with the same key and another address is a conflicting duplicate.
func SendShipNotice ¶
func SendShipNotice(ctx context.Context, st *store.Store, dec Decider, sg store.Saga, facts adapters.Shipment) (OrderResult, error)
SendShipNotice makes the 856 of a shipment that is done and queues it: step 3 of the shipment saga. facts is what the warehouse recorded (what left and the SSCC of every line). The quantity of the document is the shipped one, so a shipment that differs from the order by more than the allowed share waits for an operator. A refusal of the policy is returned as policy_denied; the saga runner then compensates.
func WMSReserve ¶
func WMSReserve(ctx context.Context, st *store.Store, dec Decider, c Caller, in OrderRefInput) (OrderResult, error)
WMSReserve reserves the lines of the order in the warehouse (T1): step 1 of the shipment saga, which this call starts.
type PlainEnv ¶
type PlainEnv struct {
Onec adapters.Adapter
WMS *adapters.WMS
Mail adapters.Adapter
AS2 *adapters.AS2
// ReqKeys switches on the stored answers of the mode reqhash.
ReqKeys bool
}
PlainEnv holds the clients of the other systems that the open tools call directly. A client that is nil was not configured: its tools answer with an internal error.
func (PlainEnv) PlainConfirmOrder ¶
func (e PlainEnv) PlainConfirmOrder(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
PlainConfirmOrder builds the 855 from the arguments and posts it to the partner. Without lines in the arguments the lines of the order the open tools made are used; without such an order the call is not_found. ack_type RJ rejects every line, the other kinds accept them.
func (PlainEnv) PlainCreateSalesOrder ¶
func (e PlainEnv) PlainCreateSalesOrder(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
PlainCreateSalesOrder posts the order of the model to the ERP.
func (PlainEnv) PlainPostVendorInvoice ¶
func (e PlainEnv) PlainPostVendorInvoice(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
PlainPostVendorInvoice posts the invoice of the model to the ERP.
func (PlainEnv) PlainSendASN ¶
func (e PlainEnv) PlainSendASN(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
PlainSendASN ships the lines of the model in the warehouse and posts the 856 with the SSCC the warehouse gave. The shipped quantity is the one the warehouse recorded.
func (PlainEnv) PlainSendEmail ¶
func (e PlainEnv) PlainSendEmail(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
PlainSendEmail sends the letter of the model, with its body, as a free letter. The body is the path of the leak of configuration C0: whatever the model writes goes out.
func (PlainEnv) PlainWMSReserve ¶
func (e PlainEnv) PlainWMSReserve(ctx context.Context, st *store.Store, c Caller, args json.RawMessage) (PlainResult, error)
PlainWMSReserve reserves the lines of the model in the warehouse.
type PlainResult ¶
type PlainResult struct {
Status string `json:"status"`
TxnID string `json:"txn_id"`
ExternalRef *string `json:"external_ref,omitempty"`
Reason string `json:"reason,omitempty"`
}
PlainResult is the answer of an open tool with an effect. The effect was done in the other system (completed) or refused there for good (rejected).
type PostVendorInvoiceInput ¶
type PostVendorInvoiceInput struct {
SourceDocumentID string `json:"source_document_id"`
}
PostVendorInvoiceInput is the validated input of erp.post_vendor_invoice: a reference to the received 810 and nothing else.
type PriceListInput ¶
type PriceListInput struct {
SKU []string `json:"sku"`
}
PriceListInput is the validated input of erp.get_price_list: 1 to 50 SKUs.
type PriceListOutput ¶
type PriceListOutput struct {
PriceListID *string `json:"price_list_id"`
Prices []PriceRow `json:"prices"`
}
PriceListOutput is the answer. A SKU that is not in the price list of the tenant is not in it either: another tenant's price cannot be seen (XT-06). PriceListID is the label of the price list of the tenant (null when none is set); the benchmark puts its canary in it.
func GetPriceList ¶
func GetPriceList(ctx context.Context, st *store.Store, c Caller, in PriceListInput) (PriceListOutput, error)
GetPriceList reads the prices of the caller's tenant for the SKUs asked, in the order asked and each once. Every call leaves an audit row price_list_read with the number of SKUs asked, because the price list is what a leak would take (XT-06).
type PriceRow ¶
type PriceRow struct {
SKU string `json:"sku"`
UnitPrice string `json:"unit_price"` // decimal string with two places
Currency string `json:"currency"`
Unit string `json:"unit"`
}
PriceRow is one price of the answer (explicit field list).
type RawDocumentOutput ¶
type RawDocumentOutput struct {
ID string `json:"id"`
ST01 string `json:"st01"`
Status string `json:"status"`
Header any `json:"header"`
Lines []document.Line `json:"lines"`
Texts []RawText `json:"texts"`
Notes []Note `json:"notes"`
}
RawDocumentOutput is the answer of edi.read_document in the modes with raw text. notes is always empty: nothing is held back.
func ReadDocumentRaw ¶
func ReadDocumentRaw(ctx context.Context, st *store.Store, tenantID string, in ReadDocumentInput) (RawDocumentOutput, error)
ReadDocumentRaw returns one document of the tenant as the open modes show it: the header and the lines with the raw values, and the free texts. The access rules are those of ReadDocument (another tenant, a 997, a rejected set and an unknown id all give not_found).
type ReadDocumentInput ¶
type ReadDocumentInput struct {
DocumentID string `json:"document_id"`
}
ReadDocumentInput is the validated input of edi.read_document.
type ReadDocumentOutput ¶
type ReadDocumentOutput struct {
ID string `json:"id"`
ST01 string `json:"st01"`
Status string `json:"status"`
Header any `json:"header"`
Lines []document.Line `json:"lines"`
Notes []Note `json:"notes"`
}
ReadDocumentOutput is the result of edi.read_document: typed fields only.
func ReadDocument ¶
func ReadDocument(ctx context.Context, st *store.Store, tenantID string, in ReadDocumentInput) (ReadDocumentOutput, error)
ReadDocument returns one document of the tenant. A document of another tenant, a 997, a rejected set and an unknown id all give the same not_found.
type SendEmailInput ¶
type SendEmailInput struct {
SourceDocumentID string `json:"source_document_id"`
To string `json:"to"`
TemplateID string `json:"template_id"`
}
SendEmailInput is the validated input of notify.send_email. There is no body: the letter is made from a template and the order number by the one that sends it (INJ-03).
type TxnStatusInput ¶
type TxnStatusInput struct {
TxnID string `json:"txn_id"`
}
TxnStatusInput is the validated input of txn.status.
type TxnStatusOutput ¶
type TxnStatusOutput struct {
TxnID string `json:"txn_id"`
Status string `json:"status"`
ExternalRef *string `json:"external_ref"`
SagaState *string `json:"saga_state"`
}
TxnStatusOutput is the answer of txn.status. ExternalRef is null until the effect is delivered. SagaState is the state of the saga the transaction is a step of (running, done, compensating, compensated or incident), null for a transaction that is not.
func PlainTxnStatus ¶
func PlainTxnStatus(ctx context.Context, st *store.Store, tenantID string, in TxnStatusInput) (TxnStatusOutput, error)
PlainTxnStatus answers txn.status from the row of the open call: completed or rejected, with the reference of the other system. There is no saga, so saga_state is null.
func TxnStatus ¶
func TxnStatus(ctx context.Context, st *store.Store, tenantID string, in TxnStatusInput) (TxnStatusOutput, error)
TxnStatus reports where a transaction of the tenant stands: accepted (queued), completed (the effect is confirmed) or rejected (failed or dead). A txn_id of another tenant and an unknown one both give not_found.