@anycon/protocol 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,6 +51,7 @@ import type {
51
51
  NodeSetEnrollEnabledParams,
52
52
  NodeSetEnrollPasswordParams,
53
53
  NodeStats,
54
+ NodeTwinLinkCodeResult,
54
55
  PairAck,
55
56
  PermissionListParams,
56
57
  PermissionListResult,
@@ -65,6 +66,33 @@ import type {
65
66
  PreviewPortsResult,
66
67
  Project,
67
68
  RenamedProject,
69
+ RepeatStateChanged,
70
+ RepeatStateClearParams,
71
+ RepeatStateClearResult,
72
+ RepeatStateDeleteParams,
73
+ RepeatStateDeleteResult,
74
+ RepeatStateGetParams,
75
+ RepeatStateGetResult,
76
+ RepeatStateListParams,
77
+ RepeatStateListResult,
78
+ RepeatStateSetParams,
79
+ RepeatStateSetResult,
80
+ RepeatStateUnseenParams,
81
+ RepeatStateUnseenResult,
82
+ Rule,
83
+ RuleAddParams,
84
+ RuleChanged,
85
+ RuleDeleteParams,
86
+ RuleExtractDone,
87
+ RuleExtractParams,
88
+ RuleExtractResult,
89
+ RuleExtractRunsParams,
90
+ RuleExtractRunsResult,
91
+ RuleListParams,
92
+ RuleListResult,
93
+ RulePreviewParams,
94
+ RulePreviewResult,
95
+ RuleUpdateParams,
68
96
  SessionArchiveParams,
69
97
  SessionChanged,
70
98
  SessionCreateParams,
@@ -79,18 +107,56 @@ import type {
79
107
  SessionIdParams,
80
108
  SessionListParams,
81
109
  SessionListResult,
110
+ SessionMarkReadParams,
82
111
  SessionPromoteParams,
83
112
  SessionRenameParams,
84
113
  SessionSearchParams,
85
114
  SessionSearchResult,
86
115
  SessionSendParams,
87
116
  SessionSendResult,
117
+ SessionSetMarksParams,
88
118
  SessionSetSettingsParams,
89
119
  SessionSetSettingsResult,
90
120
  SessionSummary,
91
121
  SessionSyncBaseParams,
92
122
  SessionSyncBaseResult,
123
+ Todo,
124
+ TodoAddParams,
125
+ TodoChanged,
126
+ TodoDeleteParams,
127
+ TodoDispatchParams,
128
+ TodoDispatchPreviewParams,
129
+ TodoDispatchPreviewResult,
130
+ TodoDispatchResult,
131
+ TodoEventNotice,
132
+ TodoHistoryParams,
133
+ TodoHistoryResult,
134
+ TodoIdParams,
135
+ TodoListParams,
136
+ TodoListResult,
137
+ TodoRepeatPreviewParams,
138
+ TodoRepeatPreviewResult,
139
+ TodoUpdateParams,
93
140
  TrashEntry,
141
+ TwinAnswerParams,
142
+ TwinChanged,
143
+ TwinDryRunResult,
144
+ TwinGetParams,
145
+ TwinGetResult,
146
+ TwinLink,
147
+ TwinLinkParams,
148
+ TwinLinksResult,
149
+ TwinPeerStatus,
150
+ TwinQuestion,
151
+ TwinQuestionNotice,
152
+ TwinQuestionsParams,
153
+ TwinQuestionsResult,
154
+ TwinRunsParams,
155
+ TwinRunsResult,
156
+ TwinSetParams,
157
+ TwinStatsParams,
158
+ TwinStatsResult,
159
+ TwinUnlinkParams,
94
160
  WorkspaceBranchesParams,
95
161
  WorkspaceBranchesResult,
96
162
  WorkspaceBrowseParams,
@@ -119,6 +185,7 @@ export interface RequestMethods {
119
185
  'node.doctor': { params: Empty; result: NodeDoctorResult }
120
186
  'node.audit': { params: NodeAuditParams; result: NodeAuditResult }
121
187
  'node.set_agent_defaults': { params: NodeSetAgentDefaultsParams; result: Empty }
188
+ 'node.twin_link_code': { params: Empty; result: NodeTwinLinkCodeResult }
122
189
  'node.get_config': { params: Empty; result: NodeConfigResult }
123
190
  'node.set_config': { params: NodeSetConfigParams; result: NodeConfigResult }
124
191
  'node.logs': { params: NodeLogsParams; result: NodeLogsResult }
@@ -160,6 +227,8 @@ export interface RequestMethods {
160
227
  'session.rename': { params: SessionRenameParams; result: Empty }
161
228
  'session.archive': { params: SessionArchiveParams; result: Empty }
162
229
  'session.unarchive': { params: SessionIdParams; result: Empty }
230
+ 'session.set_marks': { params: SessionSetMarksParams; result: Empty }
231
+ 'session.mark_read': { params: SessionMarkReadParams; result: Empty }
163
232
  'session.delete': { params: SessionDeleteParams; result: Empty }
164
233
  'session.restart': { params: SessionIdParams; result: Empty }
165
234
  'session.search': { params: SessionSearchParams; result: SessionSearchResult }
@@ -167,6 +236,41 @@ export interface RequestMethods {
167
236
  'session.git_status': { params: SessionGitStatusParams; result: SessionGitStatus }
168
237
  'session.diff': { params: SessionDiffParams; result: SessionDiffResult }
169
238
  'session.sync_base': { params: SessionSyncBaseParams; result: SessionSyncBaseResult }
239
+ 'todo.list': { params: TodoListParams; result: TodoListResult }
240
+ 'todo.get': { params: TodoIdParams; result: Todo }
241
+ 'todo.add': { params: TodoAddParams; result: Todo }
242
+ 'todo.update': { params: TodoUpdateParams; result: Todo }
243
+ 'todo.delete': { params: TodoDeleteParams; result: Empty }
244
+ 'todo.dispatch_preview': { params: TodoDispatchPreviewParams; result: TodoDispatchPreviewResult }
245
+ 'todo.dispatch': { params: TodoDispatchParams; result: TodoDispatchResult }
246
+ 'todo.repeat_now': { params: TodoIdParams; result: Todo }
247
+ 'todo.history': { params: TodoHistoryParams; result: TodoHistoryResult }
248
+ 'todo.repeat_preview': { params: TodoRepeatPreviewParams; result: TodoRepeatPreviewResult }
249
+ 'todo.state_get': { params: RepeatStateGetParams; result: RepeatStateGetResult }
250
+ 'todo.state_set': { params: RepeatStateSetParams; result: RepeatStateSetResult }
251
+ 'todo.state_delete': { params: RepeatStateDeleteParams; result: RepeatStateDeleteResult }
252
+ 'todo.state_list': { params: RepeatStateListParams; result: RepeatStateListResult }
253
+ 'todo.state_unseen': { params: RepeatStateUnseenParams; result: RepeatStateUnseenResult }
254
+ 'todo.state_clear': { params: RepeatStateClearParams; result: RepeatStateClearResult }
255
+ 'rule.list': { params: RuleListParams; result: RuleListResult }
256
+ 'rule.add': { params: RuleAddParams; result: Rule }
257
+ 'rule.update': { params: RuleUpdateParams; result: Rule }
258
+ 'rule.delete': { params: RuleDeleteParams; result: Empty }
259
+ 'rule.preview': { params: RulePreviewParams; result: RulePreviewResult }
260
+ 'rule.extract': { params: RuleExtractParams; result: RuleExtractResult }
261
+ 'rule.extract_runs': { params: RuleExtractRunsParams; result: RuleExtractRunsResult }
262
+ 'twin.get': { params: TwinGetParams; result: TwinGetResult }
263
+ 'twin.set': { params: TwinSetParams; result: TwinGetResult }
264
+ 'twin.wake': { params: Empty; result: Empty }
265
+ 'twin.dry_run': { params: Empty; result: TwinDryRunResult }
266
+ 'twin.runs': { params: TwinRunsParams; result: TwinRunsResult }
267
+ 'twin.stats': { params: TwinStatsParams; result: TwinStatsResult }
268
+ 'twin.questions': { params: TwinQuestionsParams; result: TwinQuestionsResult }
269
+ 'twin.answer': { params: TwinAnswerParams; result: TwinQuestion }
270
+ 'twin.link': { params: TwinLinkParams; result: TwinLink }
271
+ 'twin.links': { params: Empty; result: TwinLinksResult }
272
+ 'twin.unlink': { params: TwinUnlinkParams; result: Empty }
273
+ 'twin.peer_status': { params: Empty; result: TwinPeerStatus }
170
274
  'blob.put_begin': { params: BlobPutBeginParams; result: BlobPutBeginResult }
171
275
  'blob.put_chunk': { params: BlobPutChunkParams; result: Empty }
172
276
  'blob.put_end': { params: BlobIdParams; result: AttachmentRef }
@@ -192,6 +296,13 @@ export interface NotificationMethods {
192
296
  'job.done': { params: JobDone }
193
297
  'session.event': { params: SessionEvent }
194
298
  'session.changed': { params: SessionChanged }
299
+ 'todo.changed': { params: TodoChanged }
300
+ 'todo.event': { params: TodoEventNotice }
301
+ 'todo.state_changed': { params: RepeatStateChanged }
302
+ 'rule.changed': { params: RuleChanged }
303
+ 'rule.extract_done': { params: RuleExtractDone }
304
+ 'twin.changed': { params: TwinChanged }
305
+ 'twin.question': { params: TwinQuestionNotice }
195
306
  'permission.request': { params: PermissionRequest }
196
307
  'permission.resolved': { params: PermissionResolved }
197
308
  }
package/src/preview.ts CHANGED
@@ -76,9 +76,23 @@ function hasForbiddenPathChar(path: string): boolean {
76
76
  const HEX32 = /^[0-9a-f]{32}$/
77
77
  const HEX64 = /^[0-9a-f]{64}$/
78
78
 
79
+ /** 目录预览的目录名最多这么多个 UTF-8 字节(一个项目名,或 `.scratch`)。 */
80
+ export const PREVIEW_DIR_MAX_BYTES = 255
81
+
82
+ /**
83
+ * 目录预览的目录(`PreviewLaunch.dir`)是否合法:非空、不超过 `PREVIEW_DIR_MAX_BYTES` 个 UTF-8 字节,
84
+ * 只有一段(不含 `/` 和 `\`,也不是 `.` / `..`),不含控制字符。是不是真有这个项目由 daemon 判断。
85
+ */
86
+ export function isValidPreviewDir(dir: string): boolean {
87
+ if (dir.length === 0 || new TextEncoder().encode(dir).length > PREVIEW_DIR_MAX_BYTES) return false
88
+ if (dir === '.' || dir === '..') return false
89
+ return !dir.includes('/') && !hasForbiddenPathChar(dir)
90
+ }
91
+
79
92
  /**
80
93
  * URL fragment(可以带或不带开头的 `#`)→ `PreviewLaunch`。格式不对一律抛 `ProtocolError`:
81
- * 版本、label、id 和密钥的格式、端口范围、`path` 以 `/` 开头且不是 `//`(协议相对 URL)、不含 `\` 和控制字符。
94
+ * 版本、label、id 和密钥的格式、目标(`port` 在 1–65535,或者 `dir` 是合法的目录名,两者正好一个)、
95
+ * `path` 以 `/` 开头且不是 `//`(协议相对 URL)、不含 `\` 和控制字符。
82
96
  */
83
97
  export function decodePreviewLaunch(fragment: string): PreviewLaunch {
84
98
  const text = fragment.startsWith('#') ? fragment.slice(1) : fragment
@@ -105,12 +119,24 @@ export function decodePreviewLaunch(fragment: string): PreviewLaunch {
105
119
  }
106
120
  return x
107
121
  }
122
+ // 目标:端口或目录,正好一个(`null` 和缺省一样算没给)
123
+ const hasPort = v.port !== undefined && v.port !== null
124
+ const hasDir = v.dir !== undefined && v.dir !== null
125
+ if (hasPort === hasDir)
126
+ throw new ProtocolError('preview launch: needs exactly one of port and dir')
127
+ let target: { port: number } | { dir: string }
128
+ if (hasPort) target = { port: int('port', 1, 65535) }
129
+ else {
130
+ const dir = str('dir')
131
+ if (!isValidPreviewDir(dir)) throw new ProtocolError('preview launch: invalid dir')
132
+ target = { dir }
133
+ }
108
134
  const launch: PreviewLaunch = {
109
135
  v: int('v', 0, Number.MAX_SAFE_INTEGER),
110
136
  node: str('node'),
111
137
  node_public: str('node_public'),
112
138
  label: str('label'),
113
- port: int('port', 1, 65535),
139
+ ...target,
114
140
  ticket_id: str('ticket_id'),
115
141
  psk: str('psk'),
116
142
  token: str('token'),
package/src/rpc.ts CHANGED
@@ -81,6 +81,9 @@ function canonicalError(err: RpcError): RpcError {
81
81
  if (isSet(data.field)) d.field = data.field
82
82
  if (isSet(data.reason)) d.reason = data.reason
83
83
  if (isSet(data.retry_after_ms)) d.retry_after_ms = data.retry_after_ms
84
+ if (isSet(data.updated_ms)) d.updated_ms = data.updated_ms
85
+ if (isSet(data.bytes)) d.bytes = data.bytes
86
+ if (isSet(data.cap)) d.cap = data.cap
84
87
  out.data = d
85
88
  }
86
89
  return out
@@ -155,6 +158,18 @@ export class AnyconRpcError extends Error {
155
158
  get retryAfterMs(): number | undefined {
156
159
  return this.data?.retry_after_ms ?? undefined
157
160
  }
161
+ /** 带条件的写被拒(`todo.delete` 的 `ifUpdatedMs` 对不上,`reason = 'changed'`)时,那一项现在的 `updated_ms`。 */
162
+ get updatedMs(): number | undefined {
163
+ return this.data?.updated_ms ?? undefined
164
+ }
165
+ /** 规则超出注入的字数上限(`reason = 'over_budget'`)时,这次改动之后一个会话拿到的规则文字的字节数。 */
166
+ get bytes(): number | undefined {
167
+ return this.data?.bytes ?? undefined
168
+ }
169
+ /** 同上:上限。 */
170
+ get cap(): number | undefined {
171
+ return this.data?.cap ?? undefined
172
+ }
158
173
 
159
174
  static fromWire(err: RpcError): AnyconRpcError {
160
175
  return new AnyconRpcError(err.code, err.message, err.data)
@@ -17,7 +17,7 @@ Used by:
17
17
  cmov 0.5.4 <https://github.com/RustCrypto/utils>
18
18
  ctutils 0.4.3 <https://github.com/RustCrypto/utils>
19
19
  tinyvec 1.13.3 <https://github.com/Lokathor/tinyvec>
20
- zeroize 1.9.1 <https://github.com/RustCrypto/utils>
20
+ zeroize 1.9.2 <https://github.com/RustCrypto/utils>
21
21
 
22
22
 
23
23
  Apache License
@@ -1705,13 +1705,13 @@ limitations under the License.
1705
1705
  Apache License 2.0 (Apache-2.0)
1706
1706
 
1707
1707
  Used by:
1708
- anycon-crypto 0.3.1
1708
+ anycon-crypto 0.4.1
1709
1709
  pin-project-lite 0.2.17 <https://github.com/taiki-e/pin-project-lite>
1710
1710
  proc-macro2 1.0.107 <https://github.com/dtolnay/proc-macro2>
1711
1711
  quote 1.0.47 <https://github.com/dtolnay/quote>
1712
1712
  rand 0.8.8 <https://github.com/rust-random/rand>
1713
1713
  snow 0.10.0 <https://github.com/mcginty/snow>
1714
- syn 3.0.7 <https://github.com/dtolnay/syn>
1714
+ syn 3.0.10 <https://github.com/dtolnay/syn>
1715
1715
  thiserror-impl 2.0.21 <https://github.com/dtolnay/thiserror>
1716
1716
  thiserror 2.0.21 <https://github.com/dtolnay/thiserror>
1717
1717
  unicode-ident 1.0.26 <https://github.com/dtolnay/unicode-ident>
Binary file