@telemai/opencode-plugin 0.2.2 → 0.2.4
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.
- package/LICENSE +201 -120
- package/README.md +24 -4
- package/dist/index.js +1 -1
- package/package.json +6 -5
package/LICENSE
CHANGED
|
@@ -1,121 +1,202 @@
|
|
|
1
|
-
Telem AI Proprietary Software License
|
|
2
|
-
Version 1.0, 2026
|
|
3
1
|
|
|
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
|
-
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
# @telemai/opencode-plugin
|
|
2
2
|
|
|
3
|
-
Telem web search (telem_search) and page fetch (telem_fetch) tools for
|
|
3
|
+
Telem web search (telem_search) and page fetch (telem_fetch) tools for OpenCode. Searches show up in the Telem console as live session trajectories.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The guided installer is the quickest path — it configures the plugin and captures
|
|
8
|
+
your API key from [app.telem.ai](https://app.telem.ai) in one pass:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm create @telemai
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Pick **OpenCode** when it asks, or skip the interview entirely:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm create @telemai -- --client opencode
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### By hand
|
|
21
|
+
|
|
22
|
+
Set the endpoint and your key explicitly — `npm create @telemai` writes both for you:
|
|
8
23
|
|
|
9
24
|
```bash
|
|
10
25
|
opencode plugin @telemai/opencode-plugin --global
|
|
11
|
-
export
|
|
26
|
+
export TELEM_BASE_URL=https://router.telem.ai
|
|
27
|
+
export TELEM_API_KEY=... # from https://app.telem.ai
|
|
12
28
|
```
|
|
13
29
|
|
|
14
|
-
This writes the plugin entry to
|
|
30
|
+
This writes the plugin entry to OpenCode's config file (`opencode.jsonc`,
|
|
15
31
|
despite the `.json`-sounding name) and materializes the package — one command
|
|
16
32
|
for both.
|
|
17
33
|
|
|
@@ -36,3 +52,7 @@ export TELEM_API_KEY="your-api-key-here"
|
|
|
36
52
|
The plugin will use this key to authenticate with the Telem service for all search and fetch operations.
|
|
37
53
|
|
|
38
54
|
See [docs.telem.ai](https://docs.telem.ai) for more information.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
Copyright (c) 2026 Telem AI. Licensed under the [Apache License, Version 2.0](LICENSE).
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import{tool}from"@opencode-ai/plugin";import{createHash,randomUUID}from"node:crypto";var BLANK_CHARS=new Set([32,9,10,13,11,12,160,65279,12288]);function trimBlank(value){let start=0,end=value.length;for(;start<end&&BLANK_CHARS.has(value.charCodeAt(start));)start+=1;for(;end>start&&BLANK_CHARS.has(value.charCodeAt(end-1));)end-=1;return start===0&&end===value.length?value:value.slice(start,end)}function normalizeEmpty(value){if(value!=null)return typeof value=="string"?trimBlank(value)?value:void 0:Array.isArray(value)?value.length?value:void 0:typeof value=="object"?Object.keys(value).length?value:void 0:value}function isPlainObject(value){return typeof value=="object"&&value!==null&&!Array.isArray(value)}function asName(value){let raw=normalizeEmpty(value);if(typeof raw=="string")return trimBlank(raw)||void 0}function asNameList(value){let raw=normalizeEmpty(value);if(!Array.isArray(raw))return;let names=raw.map(item=>typeof item=="string"?trimBlank(item):"").filter(Boolean);return names.length?names:void 0}function asFlag(value){let raw=normalizeEmpty(value);return typeof raw=="boolean"?raw:void 0}function asOverridesMap(value){let raw=normalizeEmpty(value);if(!isPlainObject(raw))return;let out=Object.create(null);for(let[name,params]of Object.entries(raw)){let provider=trimBlank(name);provider&&isPlainObject(params)&&(out[provider]=params)}return Object.keys(out).length?out:void 0}var COERCERS={name:asName,nameList:asNameList,flag:asFlag,overridesMap:asOverridesMap},TELEM_OPTIONS=[{key:"tier",jsonType:"string",coercion:"name",env:"TELEM_TIER",envAliases:[],description:"Normalized field tier for search results: minimalist, default, extended, or max. Mutually exclusive with `fields` \u2014 a request may carry only one."},{key:"fields",jsonType:"array",coercion:"nameList",env:"TELEM_FIELDS",envAliases:[],description:"Explicit list of normalized result fields to request (e.g. title, url, summary). Replaces `tier` when both are configured."},{key:"providersInclude",jsonType:"array",coercion:"nameList",env:"TELEM_PROVIDERS_INCLUDE",envAliases:["TELEM_PROVIDERS"],description:"Search providers to run, REPLACING the deployment's default set (e.g. exa, tavily)."},{key:"providersExclude",jsonType:"array",coercion:"nameList",env:"TELEM_PROVIDERS_EXCLUDE",envAliases:[],description:"Search providers to drop from the set that would otherwise run."},{key:"fullContent",jsonType:"boolean",coercion:"flag",env:"TELEM_FULL_CONTENT",envAliases:[],description:"Ask providers for each result's full page content instead of a summary. Slower and more expensive; off unless set."},{key:"providerOverrides",jsonType:"object",coercion:"overridesMap",env:null,envAliases:[],description:`Raw per-provider request parameters, merged into that provider's request only: {"exa": {"numResults": 2}}. Unvalidated passthrough \u2014 the server owns the names.`}],TELEM_OPTION_KEYS=TELEM_OPTIONS.map(option=>option.key);function csvValue(raw){return raw===void 0?void 0:asNameList(raw.split(","))}function optionFromEnv(spec,env){let names=spec.env===null?[]:[spec.env,...spec.envAliases];for(let name of names){let raw=env[name];if(raw===void 0)continue;let value=spec.coercion==="nameList"?csvValue(raw):spec.coercion==="flag"?raw==="1"||void 0:spec.coercion==="name"?asName(raw):void 0;if(value!==void 0)return value}}import{readFileSync,statSync}from"node:fs";import{homedir}from"node:os";import{isAbsolute,join,resolve,sep}from"node:path";var TELEM_DIR_NAME=".telem",CONFIG_FILE_NAME="telem.json",CREDENTIALS_FILE_NAME="credentials.json",CONFIG_DIR_ENV="TELEM_CONFIG_DIR";function homeDir(env){return env.HOME||env.USERPROFILE||homedir()}function isInside(candidate,projectRoot){let root=resolve(projectRoot),target=resolve(candidate);return target===root||target.startsWith(root+sep)}function resolveTelemDir(env,projectRoot){let fallback=join(homeDir(env),TELEM_DIR_NAME),raw=env[CONFIG_DIR_ENV],requested=raw===void 0?"":trimBlank(raw);return requested?projectRoot&&isInside(requested,projectRoot)?{dir:fallback,warning:`[telem] ignoring ${CONFIG_DIR_ENV}=${requested}: it points inside the project (${resolve(projectRoot)}); using ${fallback} instead`}:{dir:isAbsolute(requested)?requested:resolve(requested)}:{dir:fallback}}function projectConfigPath(projectRoot){return join(projectRoot,TELEM_DIR_NAME,CONFIG_FILE_NAME)}function credentialsPath(env,projectRoot){let{dir,warning}=resolveTelemDir(env,projectRoot);return warning===void 0?{path:join(dir,CREDENTIALS_FILE_NAME)}:{path:join(dir,CREDENTIALS_FILE_NAME),warning}}function readCredentials(env,projectRoot){let data;try{data=readTelemFile(credentialsPath(env,projectRoot).path).data}catch{return{}}if(typeof data!="object"||data===null)return{};let record=data,out={};return typeof record.apiKey=="string"&&record.apiKey&&(out.apiKey=record.apiKey),typeof record.baseUrl=="string"&&record.baseUrl&&(out.baseUrl=record.baseUrl),out}var UTF8=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});function readTelemFile(path){let bytes;try{bytes=readFileSync(path)}catch(error){let code=error?.code;return code==="ENOENT"||code==="ENOTDIR"?{data:null}:{data:null,warning:`[telem] ignoring ${path}: ${errorText(error)}`}}let raw;try{raw=UTF8.decode(bytes)}catch{return{data:null,warning:`[telem] ignoring ${path}: not valid UTF-8`}}raw.charCodeAt(0)===65279&&(raw=raw.slice(1));let parsed;try{parsed=JSON.parse(raw)}catch(error){return{data:null,warning:`[telem] ignoring ${path}: ${errorText(error)}`}}return typeof parsed!="object"||parsed===null||Array.isArray(parsed)?{data:null,warning:`[telem] ignoring ${path}: expected a JSON object`}:{data:parsed}}function errorText(error){let message=error?.message;return message||"unreadable"}function fileSignature(path){try{let stat=statSync(path);return`${stat.mtimeMs}:${stat.size}`}catch{return null}}import{join as join2}from"node:path";var LAYER_LEVELS=["host","project","legacyProject","legacyUser","user","env"];function layerRank(level){return LAYER_LEVELS.indexOf(level)}function createConfigReader(warn){let cache=new Map;return function(path){let signature=fileSignature(path);if(signature===null)return cache.delete(path),{data:null,signature:null};let cached=cache.get(path);if(cached&&cached.signature===signature)return cached;let file=readTelemFile(path);file.warning&&warn(file.warning);let entry={data:file.data,signature};return cache.set(path,entry),entry}}function createNoticeSink(warn){let said=new Map;return function(notices){for(let notice of notices)said.get(notice.channel)!==notice.key&&(said.set(notice.channel,notice.key),warn(notice.message))}}function plainObject(value){return typeof value=="object"&&value!==null&&!Array.isArray(value)?value:null}function safely(fn){try{return fn()}catch{return}}function resolveHarnessOptions(input){let notices=[],layers=[],data=new Map;data.set("host",plainObject(input.hostOptions));let projectRoot=input.projectRoot||void 0,projectLayers=input.projectLayers!==!1;function addFile(level,path){if(path===void 0)return;let read=input.read(path);layers.push({level,path,signature:read.signature,present:read.data!==null}),data.set(level,read.data)}projectRoot!==void 0&&projectLayers&&(addFile("project",safely(()=>projectConfigPath(projectRoot))),addFile("legacyProject",safely(()=>join2(projectRoot,...input.legacyProject)))),addFile("legacyUser",safely(()=>join2(homeDir(input.env),...input.legacyUser)));let telemDir=safely(()=>resolveTelemDir(input.env,projectRoot));telemDir?.warning!==void 0&¬ices.push({channel:"config-dir",key:telemDir.warning,message:telemDir.warning}),addFile("user",telemDir===void 0?void 0:safely(()=>join2(telemDir.dir,CONFIG_FILE_NAME)));let values={},sources={};for(let spec of TELEM_OPTIONS){let coerce=COERCERS[spec.coercion],resolved,level;for(let candidateLevel of LAYER_LEVELS){if(candidateLevel==="env")break;let layer=data.get(candidateLevel);if(!layer||!Object.prototype.hasOwnProperty.call(layer,spec.key))continue;let candidate=coerce(layer[spec.key]);if(candidate!==void 0){resolved=candidate,level=candidateLevel;break}}if(level===void 0){let fromEnv=optionFromEnv(spec,input.env);fromEnv!==void 0&&(resolved=fromEnv,level="env")}level!==void 0&&(values[spec.key]=resolved,sources[spec.key]=level)}notices.push(...legacyNotices(layers,projectRoot));let project=projectNotice(layers,sources);project&¬ices.push(project);let composition=composeTierFields(values,sources);composition&¬ices.push(composition);let providers=composeProviders(values);providers&¬ices.push(providers);let guard=guardProviderOverrides(values);return guard&¬ices.push(guard),{values,sources,layers,notices}}function unifiedTargetFor(level,layers,projectRoot){if(level==="legacyProject"){let project=layers.find(layer=>layer.level==="project");return project?project.path:projectRoot===void 0?`.telem/${CONFIG_FILE_NAME}`:safely(()=>projectConfigPath(projectRoot))??`.telem/${CONFIG_FILE_NAME}`}let user=layers.find(layer=>layer.level==="user");return user?user.path:`~/.telem/${CONFIG_FILE_NAME}`}function legacyNotices(layers,projectRoot){let notices=[];for(let layer of layers){if(layer.level!=="legacyProject"&&layer.level!=="legacyUser"||!layer.present)continue;let target=unifiedTargetFor(layer.level,layers,projectRoot);notices.push({channel:`legacy:${layer.path}`,key:layer.signature??"gone",message:`[telem] ${layer.path} is deprecated: move these settings into ${target}, the one Telem config every harness reads. It still applies until you do \u2014 above the user-level files, so nothing changes while you migrate.`})}return notices}function projectNotice(layers,sources){let keys=[],paths=new Set,signatures=[];for(let key of["providersInclude","providerOverrides"]){let level=sources[key];if(level!=="project"&&level!=="legacyProject")continue;let layer=layers.find(entry=>entry.level===level);keys.push(key),layer&&!paths.has(layer.path)&&(paths.add(layer.path),signatures.push(`${layer.path}@${layer.signature??"gone"}`))}if(!keys.length)return;let where=[...paths].join(" and ")||"the project config";return{channel:"project-providers",key:`${signatures.join("|")}|${keys.join(",")}`,message:`[telem] ${where} (in this project) is choosing search providers: ${keys.join(", ")}. Project config decides which providers run, and therefore what a search costs.`}}function composeTierFields(values,sources){let tier=values.tier,fields=values.fields;if(typeof tier!="string"||!Array.isArray(fields))return;let tierRank=layerRank(sources.tier),fieldsRank=layerRank(sources.fields),keepTier=tierRank<fieldsRank;return keepTier?delete values.fields:delete values.tier,{channel:"tier-fields",key:`${tier}@${tierRank}|${fields.join(",")}@${fieldsRank}`,message:`[telem] both tier (${tier}) and fields (${fields.join(", ")}) are configured, but a request may carry only one \u2014 `+(keepTier?"keeping tier, ignoring fields":"keeping fields, ignoring tier")+" (the more specific source wins; on a tie, fields)."}}function composeProviders(values){let include=values.providersInclude,exclude=values.providersExclude;if(include===void 0||exclude===void 0)return;let excluded=new Set(exclude),kept=include.filter(name=>!excluded.has(name)),dropped=include.filter(name=>excluded.has(name));delete values.providersExclude;let key=`${include.join(",")}|${exclude.join(",")}`;return kept.length?(values.providersInclude=kept,dropped.length?{channel:"providers-compose",key,message:`[telem] providersExclude removes ${dropped.join(", ")} from providersInclude: this search runs ${kept.join(", ")}. A request may not name the same provider in both halves, so the exclusion is applied to the config and only providersInclude is sent.`}:void 0):(delete values.providersInclude,{channel:"providers-compose",key,message:`[telem] providersExclude (${exclude.join(", ")}) removes every provider in providersInclude (${include.join(", ")}): this config resolves to an EMPTY provider set, which no search can run, so BOTH halves are dropped and the deployment's default provider set is running instead.`})}function guardProviderOverrides(values){let overrides=values.providerOverrides;if(overrides===void 0)return;let include=values.providersInclude,selected=new Set(include??[]),kept=Object.create(null),dropped=[];for(let name of Object.keys(overrides))selected.has(name)?kept[name]=overrides[name]:dropped.push(name);if(!dropped.length)return;Object.keys(kept).length?values.providerOverrides=kept:delete values.providerOverrides;let because=include===void 0?"providerOverrides applies only alongside providersInclude, and providersInclude is not set, so the deployment's own default provider set is running":`providerOverrides applies only to providers named in the resolved providersInclude (${include.join(", ")})`,plural=dropped.length>1;return{channel:"provider-overrides",key:`${dropped.join(",")}|${include===void 0?"":include.join(",")}`,message:`[telem] ignoring providerOverrides for ${dropped.join(", ")}: ${because}. Add ${dropped.map(name=>JSON.stringify(name)).join(", ")} to providersInclude in the same config to use ${plural?"them":"it"} \u2014 noting that providersInclude REPLACES the deployment's default provider set with exactly the providers you list, rather than adding to it.`}}var HISTORY_TEXT_CAP=128e3,TOOL_INPUT_CAP=128e3,FETCH_MAX_URLS=5,FETCH_CONTENT_CAP=2e4,LEGACY_PROJECT_CONFIG_PATH=[".opencode","telem.json"],LEGACY_USER_CONFIG_PATH=[".config","opencode","telem.json"],readConfigFile=createConfigReader(message=>console.warn(message)),emitNotices=createNoticeSink(message=>console.warn(message));function resolveTelemConfig(projectRoot,hostOptions){let root;try{root=projectRoot??process.cwd()}catch{root=void 0}let resolved=resolveHarnessOptions({env:process.env,hostOptions,projectRoot:root,legacyProject:LEGACY_PROJECT_CONFIG_PATH,legacyUser:LEGACY_USER_CONFIG_PATH,read:readConfigFile});emitNotices(resolved.notices);let creds=readCredentials(process.env,root),config={...resolved.values,baseUrl:(process.env.TELEM_BASE_URL??creds.baseUrl??"https://router.telem.ai").replace(/\/+$/,"")},apiKey=process.env.TELEM_API_KEY??creds.apiKey;return apiKey&&(config.apiKey=apiKey),config}function buildSearchBlock(options){let block={};options.tier!==void 0&&(block.tier=options.tier),options.fields!==void 0&&(block.fields=options.fields);let providers={};return options.providersInclude!==void 0&&(providers.include=options.providersInclude),options.providersExclude!==void 0&&(providers.exclude=options.providersExclude),Object.keys(providers).length&&(block.providers=providers),options.fullContent!==void 0&&(block.include_full_content=options.fullContent),options.providerOverrides!==void 0&&(block.provider_overrides={...options.providerOverrides}),Object.keys(block).length?block:null}var HARNESS_ID="opencode",NS_TRAJECTORY="443866ab-1b45-5ed8-979e-52fdad07b810",NONE="none";function sha256hex(x){return createHash("sha256").update(x).digest("hex")}function lp(s){return String(Buffer.byteLength(s,"utf8"))+":"+s}function uuid5(namespace,name){let nsb=Buffer.from(namespace.replace(/-/g,""),"hex"),hash=createHash("sha1").update(nsb).update(Buffer.from(name,"utf8")).digest(),b=Buffer.from(hash.subarray(0,16));b[6]=b[6]&15|80,b[8]=b[8]&63|128;let x=b.toString("hex");return`${x.slice(0,8)}-${x.slice(8,12)}-${x.slice(12,16)}-${x.slice(16,20)}-${x.slice(20,32)}`}function contextWindowHash(sid){return sha256hex(sid)}function sessionKey(sid,comp,rev){return uuid5(NS_TRAJECTORY,lp(HARNESS_ID)+lp(contextWindowHash(sid))+lp(comp)+lp(rev))}function fingerprint(sid){return sha256hex(lp(HARNESS_ID)+lp(sid))}function snapshotNodeKey(sid,msg){return uuid5(NS_TRAJECTORY,lp(HARNESS_ID)+lp(contextWindowHash(sid))+lp(msg)+lp("snap"))}function lastCompactionId(msgs){let last=NONE;for(let message of msgs??[])for(let part of message?.parts??[])part?.type==="compaction"&&typeof part.id=="string"&&(last=part.id);return last}function lastAssistantMessage(msgs){let found;for(let message of msgs??[])if(message?.info?.role==="assistant"&&typeof message.info.id=="string"){let t=message.info.time?.created;found={id:message.info.id,timeMs:typeof t=="number"?t:void 0}}return found}function toolMarker(part,override){let status=override?.status??part?.state?.status??"unknown",input="";try{let raw=override?override.input:part?.state?.input;raw!==void 0&&(input=" "+JSON.stringify(raw).slice(0,TOOL_INPUT_CAP))}catch{}return`[tool ${part?.tool??"?"}: ${status}${input}]`}function isEmptyInput(input){return input===void 0||typeof input=="object"&&input!==null&&Object.keys(input).length===0}function flattenMessages(data,opts){let history=[];for(let message of data??[]){let role=message?.info?.role;if(role!=="user"&&role!=="assistant")continue;let claimed;if(opts?.currentCall&&message?.info?.id===opts.currentCall.messageID){let candidates=(message?.parts??[]).filter(p=>p?.type==="tool"&&p?.tool===opts.currentCall.tool&&p?.state?.status==="pending"&&isEmptyInput(p?.state?.input));candidates.length===1&&(claimed=candidates[0])}let contentPieces=[],reasoningPieces=[];for(let part of message?.parts??[])if(part?.type==="text"&&typeof part.text=="string")contentPieces.push(part.text);else if(part?.type==="reasoning"){let stored=typeof part.text=="string"?part.text:"",streamed=opts?.streamedReasoning?.get(part.id)??"",text=streamed.length>stored.length?streamed:stored;text&&reasoningPieces.push(text)}else part?.type==="tool"&&contentPieces.push(part===claimed?toolMarker(part,{status:"running",input:opts.currentCall.args}):toolMarker(part));let content=contentPieces.join(`
|
|
2
2
|
`).slice(0,HISTORY_TEXT_CAP),reasoning=reasoningPieces.join(`
|
|
3
|
-
`).slice(0,HISTORY_TEXT_CAP);if(!content&&!reasoning)continue;let entry={role,content};reasoning&&(entry.reasoning=reasoning),history.push(entry)}return history}function assertV2Envelope(interaction){let version=interaction?.normalized_schema_version;if(!Number.isInteger(version)||version<2)throw new Error(`Telem server answered without the
|
|
3
|
+
`).slice(0,HISTORY_TEXT_CAP);if(!content&&!reasoning)continue;let entry={role,content};reasoning&&(entry.reasoning=reasoning),history.push(entry)}return history}function assertV2Envelope(interaction){let version=interaction?.normalized_schema_version;if(!Number.isInteger(version)||version<2)throw new Error(`Telem server answered without the normalized search envelope (normalized_schema_version=${version}); upgrade the backend or point TELEM_BASE_URL at a current deployment`)}var RENDER_EXCERPT_MAX_ENTRIES=4,RENDER_EXCERPT_MAX_CHARS=1e3,RENDER_RELATED_MAX_ITEMS=6,RENDER_TOTAL_CAP=128e3;function line(value){return typeof value=="string"?value.trim().replace(/\s*\n\s*/g," "):""}function renderRow(provider,row){let lines=[`[${provider}] URL: ${line(row?.url)}`],title=line(row?.title);title&&lines.push(`Title: ${title}`);let summary=line(row?.summary);summary&&lines.push(`Summary: ${summary}`);let entries=(Array.isArray(row?.excerpt)?row.excerpt:[]).map(entry=>line(entry)).filter(Boolean);if(entries.length){lines.push("Excerpt:");for(let entry of entries.slice(0,RENDER_EXCERPT_MAX_ENTRIES)){let cut=entry.length>RENDER_EXCERPT_MAX_CHARS;lines.push(`- ${cut?entry.slice(0,RENDER_EXCERPT_MAX_CHARS)+"\u2026":entry}`)}let dropped=entries.length-RENDER_EXCERPT_MAX_ENTRIES;dropped>0&&lines.push(`\u2026(${dropped} more excerpt entries)`)}let published=line(row?.publish_date);published&&lines.push(`Published: ${published}`);let source=row?.source;if(source&&typeof source=="object"){let name=line(source.name)||line(source.domain),author=line(source.author);author?lines.push(`Source: ${name?`${name} by ${author}`:`by ${author}`}`):line(source.name)&&lines.push(`Source: ${name}`)}return lines.join(`
|
|
4
4
|
`)}function renderQueryBlock(runs){let lines=[],answer="",questions=[],searches=[];for(let run of runs){let payload=run?.output_payload;if(!payload||typeof payload!="object")continue;answer||(answer=line(payload.answer));let related2=payload.related;if(!(!related2||typeof related2!="object")){for(let item of Array.isArray(related2.questions)?related2.questions:[]){let text=line(item);text&&questions.push(text)}for(let item of Array.isArray(related2.searches)?related2.searches:[]){let text=line(item);text&&searches.push(text)}}}answer&&lines.push(`Answer: ${answer}`);let related=[...new Set([...questions,...searches])].slice(0,RENDER_RELATED_MAX_ITEMS);return related.length&&lines.push(`Related: ${related.join(", ")}`),lines}function renderQuerySection(runs){let blocks=[],rowBlocks=[];for(let run of runs){let provider=line(run?.preprocessor_name)||"unknown",payload=run?.output_payload,rows=Array.isArray(payload?.results)?payload.results:null,error=run?.error;if(run?.status==="failed"||!rows&&error){let message=line(error?.message)||line(error?.type)||"unknown error";rowBlocks.push(`[${provider}] failed: ${message}`);continue}if(!rows?.length){let degraded=(Array.isArray(payload?.warnings)?payload.warnings:[]).find(warning=>warning?.code==="normalize_failed");if(degraded){let message=line(degraded.message)||"normalize_failed";rowBlocks.push(`[${provider}] no rows (${message})`)}continue}for(let row of rows)rowBlocks.push(renderRow(provider,row))}let head=renderQueryBlock(runs);return head.length&&blocks.push(head.join(`
|
|
5
5
|
`)),blocks.push(...rowBlocks.length?rowBlocks:["No results found."]),blocks.join(`
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemai/opencode-plugin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Telem web search (telem_search) and page fetch (telem_fetch) tools for opencode, with trajectory v5 session recording.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
7
|
"publishConfig": {
|
|
8
|
-
"access": "
|
|
8
|
+
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"exports": {
|
|
@@ -17,14 +17,15 @@
|
|
|
17
17
|
"README.md"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "esbuild
|
|
20
|
+
"build": "esbuild src/index.ts --bundle --platform=node --format=esm --external:@opencode-ai/plugin --outfile=dist/index.js --minify-whitespace --minify-syntax --legal-comments=none",
|
|
21
21
|
"prepack": "npm run build",
|
|
22
|
-
"test": "node
|
|
22
|
+
"test": "node scripts/smoke.mjs"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@opencode-ai/plugin": ">=1.17.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
+
"@opencode-ai/plugin": "1.17.15",
|
|
28
29
|
"esbuild": "^0.24.0"
|
|
29
30
|
}
|
|
30
31
|
}
|