-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstrument.clj
More file actions
350 lines (295 loc) · 14.2 KB
/
instrument.clj
File metadata and controls
350 lines (295 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
(ns github.copilot-sdk.instrument
"Spec instrumentation for development/testing.
Require this namespace to enable spec checking on public API functions.
This adds runtime validation which is useful during development but may
impact performance in production.
Usage:
(require '[github.copilot-sdk.instrument])
;; Now all public API calls are spec-checked
To disable:
(require '[clojure.spec.test.alpha :as stest])
(stest/unstrument)"
(:require [clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as stest]
[github.copilot-sdk.specs :as specs]))
;; -----------------------------------------------------------------------------
;; Function specs for client namespace
;; -----------------------------------------------------------------------------
(s/fdef github.copilot-sdk.client/client
:args (s/cat :opts (s/? ::specs/client-options))
:ret ::specs/client)
(s/fdef github.copilot-sdk.client/state
:args (s/cat :client ::specs/client)
:ret ::specs/connection-state)
(s/fdef github.copilot-sdk.client/start!
:args (s/cat :client ::specs/client)
:ret nil?)
(s/fdef github.copilot-sdk.client/approve-all
:args (s/cat :request ::specs/permission-request
:ctx map?)
:ret ::specs/permission-result)
(s/fdef github.copilot-sdk.client/stop!
:args (s/cat :client ::specs/client)
:ret (s/coll-of any?))
(s/fdef github.copilot-sdk.client/ping
:args (s/cat :client ::specs/client
:message (s/? (s/nilable string?)))
:ret (s/keys :opt-un [::specs/message ::specs/timestamp]))
(s/fdef github.copilot-sdk.client/create-session
:args (s/cat :client ::specs/client
:config ::specs/session-config)
:ret ::specs/session)
(s/fdef github.copilot-sdk.client/resume-session
:args (s/cat :client ::specs/client
:session-id ::specs/session-id
:config ::specs/resume-session-config)
:ret ::specs/session)
(s/fdef github.copilot-sdk.client/<create-session
:args (s/cat :client ::specs/client
:config ::specs/session-config)
:ret ::specs/events-ch)
(s/fdef github.copilot-sdk.client/<resume-session
:args (s/cat :client ::specs/client
:session-id ::specs/session-id
:config ::specs/resume-session-config)
:ret ::specs/events-ch)
(s/fdef github.copilot-sdk.client/list-sessions
:args (s/cat :client ::specs/client
:filter (s/? (s/nilable ::specs/session-list-filter)))
:ret (s/coll-of ::specs/session-metadata))
(s/fdef github.copilot-sdk.client/delete-session!
:args (s/cat :client ::specs/client
:session-id ::specs/session-id)
:ret nil?)
(s/fdef github.copilot-sdk.client/get-last-session-id
:args (s/cat :client ::specs/client)
:ret (s/nilable ::specs/session-id))
(s/fdef github.copilot-sdk.client/get-foreground-session-id
:args (s/cat :client ::specs/client)
:ret (s/nilable ::specs/session-id))
(s/fdef github.copilot-sdk.client/set-foreground-session-id!
:args (s/cat :client ::specs/client :session-id ::specs/session-id)
:ret nil?)
(s/fdef github.copilot-sdk.client/get-status
:args (s/cat :client ::specs/client)
:ret (s/keys :req-un [::specs/version ::specs/protocol-version]))
(s/fdef github.copilot-sdk.client/get-auth-status
:args (s/cat :client ::specs/client)
:ret (s/keys :req-un [::specs/authenticated?]
:opt-un [::specs/auth-type ::specs/host ::specs/login ::specs/status-message]))
(s/fdef github.copilot-sdk.client/list-models
:args (s/cat :client ::specs/client)
:ret (s/coll-of ::specs/model-info))
(s/fdef github.copilot-sdk.client/list-tools
:args (s/cat :client ::specs/client
:model (s/? (s/nilable string?)))
:ret (s/coll-of ::specs/tool-info-entry))
(s/fdef github.copilot-sdk.client/get-quota
:args (s/cat :client ::specs/client)
:ret ::specs/quota-snapshots)
(s/fdef github.copilot-sdk.client/force-stop!
:args (s/cat :client ::specs/client)
:ret any?)
(s/fdef github.copilot-sdk.client/notifications
:args (s/cat :client ::specs/client)
:ret any?) ; core.async channel
(s/fdef github.copilot-sdk.client/on-lifecycle-event
:args (s/alt :wildcard (s/cat :client ::specs/client
:handler ::specs/lifecycle-handler)
:typed (s/cat :client ::specs/client
:event-type ::specs/lifecycle-event-type
:handler ::specs/lifecycle-handler))
:ret fn?)
;; -----------------------------------------------------------------------------
;; Function specs for session namespace
;; -----------------------------------------------------------------------------
(s/fdef github.copilot-sdk.session/send!
:args (s/cat :session ::specs/session
:opts ::specs/send-options)
:ret string?) ; message-id
(s/fdef github.copilot-sdk.session/send-and-wait!
:args (s/cat :session ::specs/session
:opts ::specs/send-options
:timeout-ms (s/? ::specs/timeout-ms))
:ret (s/nilable map?))
(s/fdef github.copilot-sdk.session/send-async
:args (s/cat :session ::specs/session
:opts (s/merge ::specs/send-options
(s/keys :opt-un [::specs/timeout-ms])))
:ret any?) ; core.async channel
(s/fdef github.copilot-sdk.session/send-async-with-id
:args (s/cat :session ::specs/session
:opts (s/merge ::specs/send-options
(s/keys :opt-un [::specs/timeout-ms])))
:ret (s/keys :req-un [::specs/message-id ::specs/events-ch]))
(s/fdef github.copilot-sdk.session/<send!
:args (s/cat :session ::specs/session
:opts (s/merge ::specs/send-options
(s/keys :opt-un [::specs/timeout-ms])))
:ret any?) ; core.async channel
(s/fdef github.copilot-sdk.session/abort!
:args (s/cat :session ::specs/session)
:ret nil?)
(s/fdef github.copilot-sdk.session/get-messages
:args (s/cat :session ::specs/session)
:ret (s/coll-of map?))
(s/fdef github.copilot-sdk.session/disconnect!
:args (s/alt :handle (s/cat :session ::specs/session)
:explicit (s/cat :client ::specs/client
:session-id ::specs/session-id))
:ret nil?)
(s/fdef github.copilot-sdk.session/destroy!
:args (s/alt :handle (s/cat :session ::specs/session)
:explicit (s/cat :client ::specs/client
:session-id ::specs/session-id))
:ret nil?)
(s/fdef github.copilot-sdk.session/session-id
:args (s/cat :session ::specs/session)
:ret ::specs/session-id)
(s/fdef github.copilot-sdk.session/workspace-path
:args (s/cat :session ::specs/session)
:ret ::specs/workspace-path)
(s/fdef github.copilot-sdk.session/events
:args (s/cat :session ::specs/session)
:ret any?) ; core.async mult
(s/fdef github.copilot-sdk.session/subscribe-events
:args (s/cat :session ::specs/session)
:ret any?) ; core.async channel
(s/fdef github.copilot-sdk.session/unsubscribe-events
:args (s/cat :session ::specs/session
:ch any?)
:ret nil?)
(s/fdef github.copilot-sdk.session/events->chan
:args (s/cat :session ::specs/session
:opts (s/? (s/keys :opt-un [::specs/buffer ::specs/xf])))
:ret any?) ; core.async channel
(s/fdef github.copilot-sdk.session/get-current-model
:args (s/cat :session ::specs/session)
:ret ::specs/model-id)
(s/fdef github.copilot-sdk.session/switch-model!
:args (s/cat :session ::specs/session
:model-id string?)
:ret ::specs/model-id)
(s/fdef github.copilot-sdk.session/set-model!
:args (s/cat :session ::specs/session
:model-id string?)
:ret ::specs/model-id)
;; -----------------------------------------------------------------------------
;; Function specs for helpers namespace
;; -----------------------------------------------------------------------------
(s/fdef github.copilot-sdk.helpers/query
:args (s/cat :prompt string?
:opts (s/keys* :opt-un [::specs/client ::specs/session ::specs/timeout-ms]))
:ret (s/nilable string?))
(s/fdef github.copilot-sdk.helpers/query-seq!
:args (s/cat :prompt string?
:opts (s/keys* :opt-un [::specs/client ::specs/session ::specs/max-events]))
:ret seqable?)
(s/fdef github.copilot-sdk.helpers/query-chan
:args (s/cat :prompt string?
:opts (s/keys* :opt-un [::specs/client ::specs/session ::specs/buffer]))
:ret any?) ; core.async channel
(s/fdef github.copilot-sdk.helpers/shutdown!
:args (s/cat)
:ret nil?)
;; -----------------------------------------------------------------------------
;; Instrument all public API functions
;; -----------------------------------------------------------------------------
(defn instrument-all!
"Instrument all public API functions with spec checking."
[]
(stest/instrument '[github.copilot-sdk.client/client
github.copilot-sdk.client/state
github.copilot-sdk.client/start!
github.copilot-sdk.client/approve-all
github.copilot-sdk.client/stop!
github.copilot-sdk.client/force-stop!
github.copilot-sdk.client/ping
github.copilot-sdk.client/get-status
github.copilot-sdk.client/get-auth-status
github.copilot-sdk.client/list-models
github.copilot-sdk.client/list-tools
github.copilot-sdk.client/get-quota
github.copilot-sdk.client/create-session
github.copilot-sdk.client/<create-session
github.copilot-sdk.client/resume-session
github.copilot-sdk.client/<resume-session
github.copilot-sdk.client/list-sessions
github.copilot-sdk.client/delete-session!
github.copilot-sdk.client/get-last-session-id
github.copilot-sdk.client/get-foreground-session-id
github.copilot-sdk.client/set-foreground-session-id!
github.copilot-sdk.client/notifications
github.copilot-sdk.client/on-lifecycle-event
github.copilot-sdk.session/send!
github.copilot-sdk.session/send-and-wait!
github.copilot-sdk.session/send-async
github.copilot-sdk.session/send-async-with-id
github.copilot-sdk.session/<send!
github.copilot-sdk.session/abort!
github.copilot-sdk.session/get-messages
github.copilot-sdk.session/disconnect!
github.copilot-sdk.session/destroy!
github.copilot-sdk.session/session-id
github.copilot-sdk.session/workspace-path
github.copilot-sdk.session/get-current-model
github.copilot-sdk.session/switch-model!
github.copilot-sdk.session/set-model!
github.copilot-sdk.session/events
github.copilot-sdk.session/subscribe-events
github.copilot-sdk.session/unsubscribe-events
github.copilot-sdk.session/events->chan
github.copilot-sdk.helpers/query
github.copilot-sdk.helpers/query-seq!
github.copilot-sdk.helpers/query-chan
github.copilot-sdk.helpers/shutdown!]))
(defn unstrument-all!
"Remove instrumentation from all public API functions."
[]
(stest/unstrument '[github.copilot-sdk.client/client
github.copilot-sdk.client/state
github.copilot-sdk.client/start!
github.copilot-sdk.client/approve-all
github.copilot-sdk.client/stop!
github.copilot-sdk.client/force-stop!
github.copilot-sdk.client/ping
github.copilot-sdk.client/get-status
github.copilot-sdk.client/get-auth-status
github.copilot-sdk.client/list-models
github.copilot-sdk.client/list-tools
github.copilot-sdk.client/get-quota
github.copilot-sdk.client/create-session
github.copilot-sdk.client/<create-session
github.copilot-sdk.client/resume-session
github.copilot-sdk.client/<resume-session
github.copilot-sdk.client/list-sessions
github.copilot-sdk.client/delete-session!
github.copilot-sdk.client/get-last-session-id
github.copilot-sdk.client/get-foreground-session-id
github.copilot-sdk.client/set-foreground-session-id!
github.copilot-sdk.client/notifications
github.copilot-sdk.client/on-lifecycle-event
github.copilot-sdk.session/send!
github.copilot-sdk.session/send-and-wait!
github.copilot-sdk.session/send-async
github.copilot-sdk.session/send-async-with-id
github.copilot-sdk.session/<send!
github.copilot-sdk.session/abort!
github.copilot-sdk.session/get-messages
github.copilot-sdk.session/disconnect!
github.copilot-sdk.session/destroy!
github.copilot-sdk.session/session-id
github.copilot-sdk.session/workspace-path
github.copilot-sdk.session/get-current-model
github.copilot-sdk.session/switch-model!
github.copilot-sdk.session/set-model!
github.copilot-sdk.session/events
github.copilot-sdk.session/subscribe-events
github.copilot-sdk.session/unsubscribe-events
github.copilot-sdk.session/events->chan
github.copilot-sdk.helpers/query
github.copilot-sdk.helpers/query-seq!
github.copilot-sdk.helpers/query-chan
github.copilot-sdk.helpers/shutdown!]))
;; Auto-instrument when this namespace is loaded
(instrument-all!)