987 lines
22 KiB
JSON
987 lines
22 KiB
JSON
{
|
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
"$id": "https://aios.imruyi.top/contracts/personal-weixin/v1/golden-contract.schema.json",
|
|
"title": "AIOS Personal Weixin Golden Contract v1",
|
|
"oneOf": [
|
|
{
|
|
"$ref": "#/$defs/entitlement"
|
|
},
|
|
{
|
|
"$ref": "#/$defs/readiness"
|
|
},
|
|
{
|
|
"$ref": "#/$defs/startRequest"
|
|
},
|
|
{
|
|
"$ref": "#/$defs/waitRequest"
|
|
},
|
|
{
|
|
"$ref": "#/$defs/loginResult"
|
|
},
|
|
{
|
|
"$ref": "#/$defs/inboundEvent"
|
|
},
|
|
{
|
|
"$ref": "#/$defs/unbindResult"
|
|
}
|
|
],
|
|
"$defs": {
|
|
"identifier": {
|
|
"type": "string",
|
|
"minLength": 1,
|
|
"maxLength": 128,
|
|
"pattern": "^[A-Za-z0-9._~:@-]+$"
|
|
},
|
|
"sessionKey": {
|
|
"type": "string",
|
|
"minLength": 1,
|
|
"maxLength": 256,
|
|
"pattern": "^[A-Za-z0-9._~:-]+$"
|
|
},
|
|
"schemaVersion": {
|
|
"const": "aios.personal-weixin.golden.v1"
|
|
},
|
|
"entitlement": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"schemaVersion",
|
|
"kind",
|
|
"tenantId",
|
|
"accountId",
|
|
"effect",
|
|
"policyVersion",
|
|
"issuedAtMs"
|
|
],
|
|
"properties": {
|
|
"schemaVersion": {
|
|
"$ref": "#/$defs/schemaVersion"
|
|
},
|
|
"kind": {
|
|
"const": "tenant.account.entitlement"
|
|
},
|
|
"tenantId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"accountId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"effect": {
|
|
"const": "allow"
|
|
},
|
|
"policyVersion": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"issuedAtMs": {
|
|
"type": "integer",
|
|
"minimum": 0
|
|
}
|
|
}
|
|
},
|
|
"readinessReason": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"code",
|
|
"field"
|
|
],
|
|
"properties": {
|
|
"code": {
|
|
"enum": [
|
|
"field_missing",
|
|
"snapshot_stale",
|
|
"plugin_digest_mismatch",
|
|
"account_not_entitled",
|
|
"account_not_running",
|
|
"gateway_error"
|
|
]
|
|
},
|
|
"field": {
|
|
"type": "string",
|
|
"minLength": 1,
|
|
"maxLength": 128
|
|
}
|
|
}
|
|
},
|
|
"readiness": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"schemaVersion",
|
|
"kind",
|
|
"tenantId",
|
|
"selectedAccountId",
|
|
"gateway",
|
|
"plugin",
|
|
"accounts",
|
|
"ready",
|
|
"code",
|
|
"reasons",
|
|
"observedAtMs",
|
|
"freshUntilMs"
|
|
],
|
|
"properties": {
|
|
"schemaVersion": {
|
|
"$ref": "#/$defs/schemaVersion"
|
|
},
|
|
"kind": {
|
|
"const": "personal.weixin.readiness"
|
|
},
|
|
"tenantId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"selectedAccountId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"gateway": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"reachable",
|
|
"errorCode"
|
|
],
|
|
"properties": {
|
|
"reachable": {
|
|
"type": "boolean"
|
|
},
|
|
"errorCode": {
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
],
|
|
"minLength": 1,
|
|
"maxLength": 128
|
|
}
|
|
}
|
|
},
|
|
"plugin": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"id",
|
|
"loaded",
|
|
"version",
|
|
"digestSha256"
|
|
],
|
|
"properties": {
|
|
"id": {
|
|
"const": "openclaw-weixin"
|
|
},
|
|
"loaded": {
|
|
"type": "boolean"
|
|
},
|
|
"version": {
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
],
|
|
"minLength": 1,
|
|
"maxLength": 64
|
|
},
|
|
"digestSha256": {
|
|
"anyOf": [
|
|
{
|
|
"type": "string",
|
|
"pattern": "^[a-f0-9]{64}$"
|
|
},
|
|
{
|
|
"type": "null"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"accounts": {
|
|
"type": "array",
|
|
"minItems": 1,
|
|
"maxItems": 100,
|
|
"items": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"accountId",
|
|
"name",
|
|
"configured",
|
|
"enabled",
|
|
"running",
|
|
"lastError",
|
|
"isDefault",
|
|
"entitled"
|
|
],
|
|
"properties": {
|
|
"accountId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"name": {
|
|
"type": "string",
|
|
"minLength": 1,
|
|
"maxLength": 128
|
|
},
|
|
"configured": {
|
|
"type": "boolean"
|
|
},
|
|
"enabled": {
|
|
"type": "boolean"
|
|
},
|
|
"running": {
|
|
"type": "boolean"
|
|
},
|
|
"lastError": {
|
|
"type": [
|
|
"string",
|
|
"null"
|
|
],
|
|
"minLength": 1,
|
|
"maxLength": 256
|
|
},
|
|
"isDefault": {
|
|
"type": "boolean"
|
|
},
|
|
"entitled": {
|
|
"type": "boolean"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"ready": {
|
|
"type": "boolean"
|
|
},
|
|
"code": {
|
|
"enum": [
|
|
"ready",
|
|
"not_ready",
|
|
"error"
|
|
]
|
|
},
|
|
"reasons": {
|
|
"type": "array",
|
|
"maxItems": 32,
|
|
"items": {
|
|
"$ref": "#/$defs/readinessReason"
|
|
}
|
|
},
|
|
"observedAtMs": {
|
|
"type": "integer",
|
|
"minimum": 0
|
|
},
|
|
"freshUntilMs": {
|
|
"type": "integer",
|
|
"minimum": 0
|
|
}
|
|
},
|
|
"allOf": [
|
|
{
|
|
"if": {
|
|
"properties": {
|
|
"ready": {
|
|
"const": true
|
|
}
|
|
},
|
|
"required": [
|
|
"ready"
|
|
]
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"code": {
|
|
"const": "ready"
|
|
},
|
|
"reasons": {
|
|
"maxItems": 0
|
|
},
|
|
"gateway": {
|
|
"properties": {
|
|
"reachable": {
|
|
"const": true
|
|
},
|
|
"errorCode": {
|
|
"const": null
|
|
}
|
|
}
|
|
},
|
|
"plugin": {
|
|
"properties": {
|
|
"loaded": {
|
|
"const": true
|
|
},
|
|
"version": {
|
|
"type": "string"
|
|
},
|
|
"digestSha256": {
|
|
"type": "string",
|
|
"pattern": "^[a-f0-9]{64}$"
|
|
}
|
|
}
|
|
},
|
|
"accounts": {
|
|
"items": {
|
|
"properties": {
|
|
"configured": {
|
|
"const": true
|
|
},
|
|
"enabled": {
|
|
"const": true
|
|
},
|
|
"running": {
|
|
"const": true
|
|
},
|
|
"lastError": {
|
|
"const": null
|
|
},
|
|
"entitled": {
|
|
"const": true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"else": {
|
|
"properties": {
|
|
"code": {
|
|
"enum": [
|
|
"not_ready",
|
|
"error"
|
|
]
|
|
},
|
|
"reasons": {
|
|
"minItems": 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"startRequest": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"schemaVersion",
|
|
"kind",
|
|
"accountId",
|
|
"force",
|
|
"timeoutMs"
|
|
],
|
|
"properties": {
|
|
"schemaVersion": {
|
|
"$ref": "#/$defs/schemaVersion"
|
|
},
|
|
"kind": {
|
|
"const": "web.login.start.request"
|
|
},
|
|
"accountId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"force": {
|
|
"const": false
|
|
},
|
|
"timeoutMs": {
|
|
"type": "integer",
|
|
"minimum": 1000,
|
|
"maximum": 120000
|
|
}
|
|
}
|
|
},
|
|
"waitRequest": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"schemaVersion",
|
|
"kind",
|
|
"accountId",
|
|
"sessionKey",
|
|
"timeoutMs"
|
|
],
|
|
"properties": {
|
|
"schemaVersion": {
|
|
"$ref": "#/$defs/schemaVersion"
|
|
},
|
|
"kind": {
|
|
"const": "web.login.wait.request"
|
|
},
|
|
"accountId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"sessionKey": {
|
|
"$ref": "#/$defs/sessionKey"
|
|
},
|
|
"verifyCode": {
|
|
"type": "string",
|
|
"pattern": "^[0-9]{4,8}$"
|
|
},
|
|
"currentQrDataUrl": {
|
|
"type": "string",
|
|
"minLength": 1,
|
|
"maxLength": 1048576,
|
|
"pattern": "^data:image/png;base64,"
|
|
},
|
|
"timeoutMs": {
|
|
"type": "integer",
|
|
"minimum": 1000,
|
|
"maximum": 120000
|
|
}
|
|
}
|
|
},
|
|
"loginResult": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"schemaVersion",
|
|
"kind",
|
|
"status",
|
|
"accountId",
|
|
"sessionKey",
|
|
"connected",
|
|
"alreadyConnected",
|
|
"terminal",
|
|
"needsVerifyCode"
|
|
],
|
|
"properties": {
|
|
"schemaVersion": {
|
|
"$ref": "#/$defs/schemaVersion"
|
|
},
|
|
"kind": {
|
|
"const": "web.login.result"
|
|
},
|
|
"status": {
|
|
"enum": [
|
|
"qr_pending",
|
|
"need_verifycode",
|
|
"invalid_verifycode",
|
|
"expired",
|
|
"failed",
|
|
"already_connected",
|
|
"confirmed"
|
|
]
|
|
},
|
|
"accountId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"sessionKey": {
|
|
"$ref": "#/$defs/sessionKey"
|
|
},
|
|
"connected": {
|
|
"type": "boolean"
|
|
},
|
|
"alreadyConnected": {
|
|
"type": "boolean"
|
|
},
|
|
"terminal": {
|
|
"type": "boolean"
|
|
},
|
|
"needsVerifyCode": {
|
|
"type": "boolean"
|
|
},
|
|
"qrDataUrl": {
|
|
"type": "string",
|
|
"minLength": 1,
|
|
"maxLength": 1048576,
|
|
"pattern": "^data:image/png;base64,"
|
|
},
|
|
"userId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"errorCode": {
|
|
"enum": [
|
|
"invalid_verifycode",
|
|
"login_expired",
|
|
"upstream_failed",
|
|
"unknown_upstream_status"
|
|
]
|
|
},
|
|
"upstreamStatus": {
|
|
"type": "string",
|
|
"minLength": 1,
|
|
"maxLength": 128
|
|
}
|
|
},
|
|
"allOf": [
|
|
{
|
|
"if": {
|
|
"properties": {
|
|
"status": {
|
|
"const": "qr_pending"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"required": [
|
|
"qrDataUrl"
|
|
],
|
|
"properties": {
|
|
"connected": {
|
|
"const": false
|
|
},
|
|
"alreadyConnected": {
|
|
"const": false
|
|
},
|
|
"terminal": {
|
|
"const": false
|
|
},
|
|
"needsVerifyCode": {
|
|
"const": false
|
|
}
|
|
},
|
|
"not": {
|
|
"anyOf": [
|
|
{
|
|
"required": [
|
|
"userId"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"errorCode"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"upstreamStatus"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"properties": {
|
|
"status": {
|
|
"const": "need_verifycode"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"connected": {
|
|
"const": false
|
|
},
|
|
"alreadyConnected": {
|
|
"const": false
|
|
},
|
|
"terminal": {
|
|
"const": false
|
|
},
|
|
"needsVerifyCode": {
|
|
"const": true
|
|
}
|
|
},
|
|
"not": {
|
|
"anyOf": [
|
|
{
|
|
"required": [
|
|
"qrDataUrl"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"userId"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"errorCode"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"upstreamStatus"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"properties": {
|
|
"status": {
|
|
"const": "invalid_verifycode"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"required": [
|
|
"errorCode"
|
|
],
|
|
"properties": {
|
|
"errorCode": {
|
|
"const": "invalid_verifycode"
|
|
},
|
|
"connected": {
|
|
"const": false
|
|
},
|
|
"alreadyConnected": {
|
|
"const": false
|
|
},
|
|
"terminal": {
|
|
"const": false
|
|
},
|
|
"needsVerifyCode": {
|
|
"const": true
|
|
}
|
|
},
|
|
"not": {
|
|
"anyOf": [
|
|
{
|
|
"required": [
|
|
"qrDataUrl"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"userId"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"upstreamStatus"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"properties": {
|
|
"status": {
|
|
"const": "expired"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"required": [
|
|
"errorCode"
|
|
],
|
|
"properties": {
|
|
"errorCode": {
|
|
"const": "login_expired"
|
|
},
|
|
"connected": {
|
|
"const": false
|
|
},
|
|
"alreadyConnected": {
|
|
"const": false
|
|
},
|
|
"terminal": {
|
|
"const": true
|
|
},
|
|
"needsVerifyCode": {
|
|
"const": false
|
|
}
|
|
},
|
|
"not": {
|
|
"anyOf": [
|
|
{
|
|
"required": [
|
|
"qrDataUrl"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"userId"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"upstreamStatus"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"properties": {
|
|
"status": {
|
|
"const": "failed"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"required": [
|
|
"errorCode"
|
|
],
|
|
"properties": {
|
|
"connected": {
|
|
"const": false
|
|
},
|
|
"alreadyConnected": {
|
|
"const": false
|
|
},
|
|
"terminal": {
|
|
"const": true
|
|
},
|
|
"needsVerifyCode": {
|
|
"const": false
|
|
}
|
|
},
|
|
"not": {
|
|
"anyOf": [
|
|
{
|
|
"required": [
|
|
"qrDataUrl"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"userId"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"required": [
|
|
"upstreamStatus"
|
|
],
|
|
"properties": {
|
|
"status": {
|
|
"const": "failed"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"properties": {
|
|
"errorCode": {
|
|
"const": "unknown_upstream_status"
|
|
}
|
|
},
|
|
"not": {
|
|
"anyOf": [
|
|
{
|
|
"required": [
|
|
"qrDataUrl"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"userId"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"required": [
|
|
"status",
|
|
"errorCode"
|
|
],
|
|
"properties": {
|
|
"status": {
|
|
"const": "failed"
|
|
},
|
|
"errorCode": {
|
|
"const": "unknown_upstream_status"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"required": [
|
|
"upstreamStatus"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"required": [
|
|
"status",
|
|
"errorCode"
|
|
],
|
|
"properties": {
|
|
"status": {
|
|
"const": "failed"
|
|
},
|
|
"errorCode": {
|
|
"const": "upstream_failed"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"not": {
|
|
"required": [
|
|
"upstreamStatus"
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"properties": {
|
|
"status": {
|
|
"const": "already_connected"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"required": [
|
|
"upstreamStatus"
|
|
],
|
|
"properties": {
|
|
"upstreamStatus": {
|
|
"const": "binded_redirect"
|
|
},
|
|
"connected": {
|
|
"const": false
|
|
},
|
|
"alreadyConnected": {
|
|
"const": true
|
|
},
|
|
"terminal": {
|
|
"const": true
|
|
},
|
|
"needsVerifyCode": {
|
|
"const": false
|
|
}
|
|
},
|
|
"not": {
|
|
"anyOf": [
|
|
{
|
|
"required": [
|
|
"qrDataUrl"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"userId"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"errorCode"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"if": {
|
|
"properties": {
|
|
"status": {
|
|
"const": "confirmed"
|
|
}
|
|
}
|
|
},
|
|
"then": {
|
|
"required": [
|
|
"userId"
|
|
],
|
|
"properties": {
|
|
"connected": {
|
|
"const": true
|
|
},
|
|
"alreadyConnected": {
|
|
"const": false
|
|
},
|
|
"terminal": {
|
|
"const": true
|
|
},
|
|
"needsVerifyCode": {
|
|
"const": false
|
|
}
|
|
},
|
|
"not": {
|
|
"anyOf": [
|
|
{
|
|
"required": [
|
|
"qrDataUrl"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"errorCode"
|
|
]
|
|
},
|
|
{
|
|
"required": [
|
|
"upstreamStatus"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
"inboundEvent": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"eventId",
|
|
"accountId",
|
|
"senderId",
|
|
"chatId",
|
|
"challengeCode",
|
|
"observedAt"
|
|
],
|
|
"properties": {
|
|
"eventId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"accountId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"senderId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"chatId": {
|
|
"$ref": "#/$defs/identifier"
|
|
},
|
|
"challengeCode": {
|
|
"type": "string",
|
|
"minLength": 6,
|
|
"maxLength": 64,
|
|
"pattern": "^[A-Z0-9]+$"
|
|
},
|
|
"observedAt": {
|
|
"type": "integer",
|
|
"minimum": 0
|
|
}
|
|
}
|
|
},
|
|
"unbindResult": {
|
|
"type": "object",
|
|
"additionalProperties": false,
|
|
"required": [
|
|
"schemaVersion",
|
|
"kind",
|
|
"httpStatus",
|
|
"ok",
|
|
"supported",
|
|
"code",
|
|
"mutationCount"
|
|
],
|
|
"properties": {
|
|
"schemaVersion": {
|
|
"$ref": "#/$defs/schemaVersion"
|
|
},
|
|
"kind": {
|
|
"const": "web.unbind.result"
|
|
},
|
|
"httpStatus": {
|
|
"const": 501
|
|
},
|
|
"ok": {
|
|
"const": false
|
|
},
|
|
"supported": {
|
|
"const": false
|
|
},
|
|
"code": {
|
|
"const": "unbind_not_supported"
|
|
},
|
|
"mutationCount": {
|
|
"const": 0
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|