返回 DeepSeek-Reasonix
dto_lifecycle.go
根目录 / internal / extension / protocol / dto_lifecycle.go
1 package protocol
2
3 import "encoding/json"
4
5 // Lifecycle DTOs: initialize handshake, initialized notification, graceful
6 // shutdown, event observation, and resource change notification.
7
8 // DependencySchemaVersion is the host/sidecar shared dependency identity
9 // schema revision carried in the initialize handshake.
10 const DependencySchemaVersion = 1
11
12 // CapabilityWire is the protocol form of a namespaced capability identity.
13 type CapabilityWire struct {
14 Namespace string `json:"namespace" validate:"nonempty"`
15 Kind string `json:"kind" validate:"nonempty"`
16 ID string `json:"id" validate:"nonempty"`
17 Version string `json:"version,omitempty"`
18 SchemaHash string `json:"schemaHash,omitempty"`
19 }
20
21 // RequirementWire is a dependency requirement on the wire.
22 type RequirementWire struct {
23 Namespace string `json:"namespace" validate:"nonempty"`
24 Kind string `json:"kind" validate:"nonempty"`
25 ID string `json:"id" validate:"nonempty"`
26 Version string `json:"version,omitempty"`
27 SchemaHash string `json:"schemaHash,omitempty"`
28 VersionRange string `json:"versionRange,omitempty"`
29 Optional bool `json:"optional,omitempty"`
30 }
31
32 // InitializeParams is the host's opening handshake. The sidecar must answer
33 // with InitializeResult before any other method runs.
34 type InitializeParams struct {
35 ProtocolVersion string `json:"protocolVersion" validate:"nonempty"`
36 ProtocolID string `json:"protocolId" validate:"nonempty"`
37 Manifest ManifestExpectation `json:"manifest"`
38 Session SessionContext `json:"session"`
39 Capabilities HostCapabilities `json:"capabilities"`
40 DependencySchemaVersion int `json:"dependencySchemaVersion,omitempty" validate:"min=0"`
41 }
42
43 // ManifestExpectation is what the host will accept from this extension,
44 // derived from its installed manifest. The sidecar must not use anything
45 // outside this set; doing so fails with capability_not_declared.
46 type ManifestExpectation struct {
47 Intercepts []string `json:"intercepts,omitempty"`
48 Replaces []string `json:"replaces,omitempty"`
49 Providers []string `json:"providers,omitempty"`
50 UIActions []string `json:"uiActions,omitempty"`
51 Capabilities []string `json:"capabilities,omitempty"`
52 Requires []RequirementWire `json:"requires,omitempty"`
53 Provides []CapabilityWire `json:"provides,omitempty"`
54 }
55
56 // SessionContext identifies the session the extension serves.
57 type SessionContext struct {
58 SessionID string `json:"sessionId" validate:"nonempty"`
59 WorkspaceRoot string `json:"workspaceRoot" validate:"nonempty"`
60 Generation uint64 `json:"generation"`
61 // Epoch is the dependency-identity fingerprint for this component generation.
62 Epoch string `json:"epoch,omitempty"`
63 }
64
65 // HostCapabilities tells the sidecar what this host supports.
66 type HostCapabilities struct {
67 ContentRefs bool `json:"contentRefs"`
68 UIHost UIHostKind `json:"uiHost"`
69 ProtocolVersion string `json:"protocolVersion" validate:"nonempty"`
70 DependencySchemaVersion int `json:"dependencySchemaVersion,omitempty" validate:"min=0"`
71 }
72
73 // InitializeResult is the sidecar's handshake answer: its identity plus the
74 // contributions it actually activated for this session.
75 type InitializeResult struct {
76 ProtocolVersion string `json:"protocolVersion" validate:"nonempty"`
77 Name string `json:"name" validate:"nonempty"`
78 Version string `json:"version" validate:"nonempty"`
79 ComponentID string `json:"componentId,omitempty"`
80 Subscriptions []string `json:"subscriptions,omitempty"`
81 Replaces []string `json:"replaces,omitempty"`
82 Providers []ProviderDescriptor `json:"providers,omitempty"`
83 UIActions []UIActionDecl `json:"uiActions,omitempty"`
84 Requires []RequirementWire `json:"requires,omitempty"`
85 Provides []CapabilityWire `json:"provides,omitempty"`
86 StateSchemaVersion int `json:"stateSchemaVersion" validate:"min=0"`
87 }
88
89 // InitializedParams carries no payload; the notification only signals the
90 // sidecar may start receiving intercepts and events.
91 type InitializedParams struct{}
92
93 // ShutdownParams requests a graceful stop. The sidecar must answer within
94 // TimeoutMillis or the host reports shutdown_timeout and kills the process.
95 type ShutdownParams struct {
96 TimeoutMillis int `json:"timeoutMillis" validate:"min=0"`
97 }
98
99 // ShutdownResult acknowledges the shutdown request.
100 type ShutdownResult struct {
101 Accepted bool `json:"accepted"`
102 }
103
104 // EventParams is the fire-and-forget observation of one of the 17 hook
105 // points. Unlike extension/intercept, the extension's answer (if any) is
106 // discarded and cannot change host behavior. When Payload exceeds
107 // ExternalizeFieldBytes it travels as null and Externalized carries its
108 // content-ref descriptor.
109 type EventParams struct {
110 Event InterceptEvent `json:"event"`
111 Payload json.RawMessage `json:"payload" externalizable:"true"`
112 Externalized []ExternalizedField `json:"externalized,omitempty"`
113 }
114
115 // ResourcesChangedParams notifies the extension that watched resources
116 // (skills, commands, prompts, themes, …) changed on disk.
117 type ResourcesChangedParams struct {
118 Paths []string `json:"paths"`
119 }
120
120 lines GO