@framers/agentos-ext-weather 1.0.0 → 1.0.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.
- package/LICENSE +96 -21
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/services/weatherService.d.ts +62 -0
- package/dist/services/weatherService.d.ts.map +1 -0
- package/dist/services/weatherService.js +206 -0
- package/dist/services/weatherService.js.map +1 -0
- package/dist/tools/weatherLookup.d.ts +26 -0
- package/dist/tools/weatherLookup.d.ts.map +1 -0
- package/dist/tools/weatherLookup.js +57 -0
- package/dist/tools/weatherLookup.js.map +1 -0
- package/manifest.json +1 -1
- package/package.json +14 -6
- package/src/index.ts +0 -60
- package/src/services/weatherService.ts +0 -275
- package/src/tools/weatherLookup.ts +0 -77
- package/test/weatherLookup.spec.ts +0 -270
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -10
package/LICENSE
CHANGED
|
@@ -1,23 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License.
|
|
30
|
+
|
|
31
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License.
|
|
34
|
+
|
|
35
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
36
|
+
|
|
37
|
+
4. Redistribution.
|
|
38
|
+
|
|
39
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
40
|
+
|
|
41
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
42
|
+
|
|
43
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
44
|
+
|
|
45
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
46
|
+
|
|
47
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
48
|
+
|
|
49
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
50
|
+
|
|
51
|
+
5. Submission of Contributions.
|
|
52
|
+
|
|
53
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
54
|
+
|
|
55
|
+
6. Trademarks.
|
|
56
|
+
|
|
57
|
+
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
58
|
+
|
|
59
|
+
7. Disclaimer of Warranty.
|
|
60
|
+
|
|
61
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
62
|
+
|
|
63
|
+
8. Limitation of Liability.
|
|
64
|
+
|
|
65
|
+
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
66
|
+
|
|
67
|
+
9. Accepting Warranty or Additional Liability.
|
|
68
|
+
|
|
69
|
+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
70
|
+
|
|
71
|
+
END OF TERMS AND CONDITIONS
|
|
72
|
+
|
|
73
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
74
|
+
|
|
75
|
+
To apply the Apache License to your work, attach the following
|
|
76
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
77
|
+
replaced with your own identifying information. (Don't include
|
|
78
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
79
|
+
comment syntax for the file format. We also recommend that a
|
|
80
|
+
file or class name and description of purpose be included on the
|
|
81
|
+
same "printed page" as the copyright notice for easier
|
|
82
|
+
identification within third-party archives.
|
|
83
|
+
|
|
84
|
+
Copyright (c) 2025 Framers
|
|
85
|
+
|
|
86
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
87
|
+
you may not use this file except in compliance with the License.
|
|
88
|
+
You may obtain a copy of the License at
|
|
89
|
+
|
|
90
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
91
|
+
|
|
92
|
+
Unless required by applicable law or agreed to in writing, software
|
|
93
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
94
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
95
|
+
See the License for the specific language governing permissions and
|
|
96
|
+
limitations under the License.
|
|
22
97
|
|
|
23
98
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExtensionPackContext, ExtensionPack } from '@framers/agentos';
|
|
2
|
+
export interface WeatherExtensionOptions {
|
|
3
|
+
weatherApiKey?: string;
|
|
4
|
+
priority?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function createExtensionPack(context: ExtensionPackContext): ExtensionPack;
|
|
7
|
+
export { WeatherService } from './services/weatherService.js';
|
|
8
|
+
export { WeatherLookupTool } from './tools/weatherLookup.js';
|
|
9
|
+
export type { WeatherResult, GeoLocation, CurrentWeather, ForecastDay, WeatherAlert, } from './services/weatherService.js';
|
|
10
|
+
export type { WeatherLookupInput } from './tools/weatherLookup.js';
|
|
11
|
+
export default createExtensionPack;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAK1B,MAAM,WAAW,uBAAuB;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAiChF;AAED,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EACV,aAAa,EACb,WAAW,EACX,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,eAAe,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { WeatherService } from './services/weatherService.js';
|
|
2
|
+
import { WeatherLookupTool } from './tools/weatherLookup.js';
|
|
3
|
+
export function createExtensionPack(context) {
|
|
4
|
+
const options = (context.options ?? {});
|
|
5
|
+
const weatherApiKey = options.weatherApiKey ||
|
|
6
|
+
context.getSecret?.('weather.weatherApiKey') ||
|
|
7
|
+
process.env.WEATHERAPI_KEY;
|
|
8
|
+
const service = new WeatherService(weatherApiKey);
|
|
9
|
+
const tool = new WeatherLookupTool(service);
|
|
10
|
+
return {
|
|
11
|
+
name: '@framers/agentos-ext-weather',
|
|
12
|
+
version: '1.0.0',
|
|
13
|
+
descriptors: [
|
|
14
|
+
{
|
|
15
|
+
id: tool.name,
|
|
16
|
+
kind: 'tool',
|
|
17
|
+
priority: options.priority ?? 50,
|
|
18
|
+
payload: tool,
|
|
19
|
+
requiredSecrets: [{ id: 'weather.weatherApiKey', optional: true }],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
onActivate: async (lc) => {
|
|
23
|
+
const provider = service.hasWeatherApiKey
|
|
24
|
+
? 'WeatherAPI.com (preferred) + Open-Meteo fallback'
|
|
25
|
+
: 'Open-Meteo only (set WEATHERAPI_KEY for WeatherAPI.com)';
|
|
26
|
+
lc?.logger?.info(`Weather Extension activated — ${provider}`);
|
|
27
|
+
},
|
|
28
|
+
onDeactivate: async (lc) => {
|
|
29
|
+
lc?.logger?.info('Weather Extension deactivated');
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { WeatherService } from './services/weatherService.js';
|
|
34
|
+
export { WeatherLookupTool } from './tools/weatherLookup.js';
|
|
35
|
+
export default createExtensionPack;
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAO7D,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAA4B,CAAC;IAEnE,MAAM,aAAa,GACjB,OAAO,CAAC,aAAa;QACrB,OAAO,CAAC,SAAS,EAAE,CAAC,uBAAuB,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAE7B,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAE5C,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE;YACX;gBACE,EAAE,EAAE,IAAI,CAAC,IAAI;gBACb,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE;gBAChC,OAAO,EAAE,IAAI;gBACb,eAAe,EAAE,CAAC,EAAE,EAAE,EAAE,uBAAuB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;aACnE;SACF;QACD,UAAU,EAAE,KAAK,EAAE,EAA8B,EAAE,EAAE;YACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB;gBACvC,CAAC,CAAC,kDAAkD;gBACpD,CAAC,CAAC,yDAAyD,CAAC;YAC9D,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,iCAAiC,QAAQ,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,YAAY,EAAE,KAAK,EAAE,EAA8B,EAAE,EAAE;YACrD,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,+BAA+B,CAAC,CAAC;QACpD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAS7D,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dual-provider weather service.
|
|
3
|
+
*
|
|
4
|
+
* Provider priority:
|
|
5
|
+
* 1. WeatherAPI.com — preferred when WEATHERAPI_KEY is configured
|
|
6
|
+
* 2. Open-Meteo — always-available fallback (no key required)
|
|
7
|
+
*
|
|
8
|
+
* Geocoding is handled by the Open-Meteo Geocoding API (free, no key).
|
|
9
|
+
*/
|
|
10
|
+
export interface GeoLocation {
|
|
11
|
+
name: string;
|
|
12
|
+
region: string;
|
|
13
|
+
country: string;
|
|
14
|
+
lat: number;
|
|
15
|
+
lon: number;
|
|
16
|
+
timezone: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CurrentWeather {
|
|
19
|
+
temp_f: number;
|
|
20
|
+
temp_c: number;
|
|
21
|
+
condition: string;
|
|
22
|
+
humidity: number;
|
|
23
|
+
wind_mph: number;
|
|
24
|
+
wind_dir: string;
|
|
25
|
+
uv: number;
|
|
26
|
+
feels_like_f: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ForecastDay {
|
|
29
|
+
date: string;
|
|
30
|
+
max_f: number;
|
|
31
|
+
min_f: number;
|
|
32
|
+
max_c: number;
|
|
33
|
+
min_c: number;
|
|
34
|
+
condition: string;
|
|
35
|
+
precip_chance: number;
|
|
36
|
+
wind_max_mph: number;
|
|
37
|
+
uv_max: number;
|
|
38
|
+
}
|
|
39
|
+
export interface WeatherAlert {
|
|
40
|
+
headline: string;
|
|
41
|
+
severity: string;
|
|
42
|
+
description: string;
|
|
43
|
+
}
|
|
44
|
+
export interface WeatherResult {
|
|
45
|
+
provider: 'weatherapi' | 'open-meteo';
|
|
46
|
+
location: GeoLocation;
|
|
47
|
+
current?: CurrentWeather;
|
|
48
|
+
forecast: ForecastDay[];
|
|
49
|
+
alerts?: WeatherAlert[];
|
|
50
|
+
}
|
|
51
|
+
export declare class WeatherService {
|
|
52
|
+
private readonly weatherApiKey?;
|
|
53
|
+
constructor(weatherApiKey?: string | undefined);
|
|
54
|
+
get hasWeatherApiKey(): boolean;
|
|
55
|
+
/** Geocode a location string to coordinates via Open-Meteo. */
|
|
56
|
+
geocode(location: string): Promise<GeoLocation>;
|
|
57
|
+
/** Main entry: get weather for a location string. */
|
|
58
|
+
getWeather(location: string, days?: number): Promise<WeatherResult>;
|
|
59
|
+
private fetchWeatherApi;
|
|
60
|
+
private fetchOpenMeteo;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=weatherService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weatherService.d.ts","sourceRoot":"","sources":["../../src/services/weatherService.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAIH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,YAAY,GAAG,YAAY,CAAC;IACtC,QAAQ,EAAE,WAAW,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACzB;AA8CD,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC;gBAAd,aAAa,CAAC,EAAE,MAAM,YAAA;IAEnD,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED,+DAA+D;IACzD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAwBrD,qDAAqD;IAC/C,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,MAAU,GAAG,OAAO,CAAC,aAAa,CAAC;YAiB9D,eAAe;YA2Df,cAAc;CA+D7B"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Dual-provider weather service.
|
|
4
|
+
*
|
|
5
|
+
* Provider priority:
|
|
6
|
+
* 1. WeatherAPI.com — preferred when WEATHERAPI_KEY is configured
|
|
7
|
+
* 2. Open-Meteo — always-available fallback (no key required)
|
|
8
|
+
*
|
|
9
|
+
* Geocoding is handled by the Open-Meteo Geocoding API (free, no key).
|
|
10
|
+
*/
|
|
11
|
+
// ── WMO weather code → human-readable condition ────────────────────────────
|
|
12
|
+
const WMO_CODES = {
|
|
13
|
+
0: 'Clear sky',
|
|
14
|
+
1: 'Mainly clear',
|
|
15
|
+
2: 'Partly cloudy',
|
|
16
|
+
3: 'Overcast',
|
|
17
|
+
45: 'Fog',
|
|
18
|
+
48: 'Depositing rime fog',
|
|
19
|
+
51: 'Light drizzle',
|
|
20
|
+
53: 'Moderate drizzle',
|
|
21
|
+
55: 'Dense drizzle',
|
|
22
|
+
56: 'Light freezing drizzle',
|
|
23
|
+
57: 'Dense freezing drizzle',
|
|
24
|
+
61: 'Slight rain',
|
|
25
|
+
63: 'Moderate rain',
|
|
26
|
+
65: 'Heavy rain',
|
|
27
|
+
66: 'Light freezing rain',
|
|
28
|
+
67: 'Heavy freezing rain',
|
|
29
|
+
71: 'Slight snow',
|
|
30
|
+
73: 'Moderate snow',
|
|
31
|
+
75: 'Heavy snow',
|
|
32
|
+
77: 'Snow grains',
|
|
33
|
+
80: 'Slight rain showers',
|
|
34
|
+
81: 'Moderate rain showers',
|
|
35
|
+
82: 'Violent rain showers',
|
|
36
|
+
85: 'Slight snow showers',
|
|
37
|
+
86: 'Heavy snow showers',
|
|
38
|
+
95: 'Thunderstorm',
|
|
39
|
+
96: 'Thunderstorm with slight hail',
|
|
40
|
+
99: 'Thunderstorm with heavy hail',
|
|
41
|
+
};
|
|
42
|
+
function wmoToCondition(code) {
|
|
43
|
+
return WMO_CODES[code] ?? `Unknown (${code})`;
|
|
44
|
+
}
|
|
45
|
+
/** Convert Fahrenheit to Celsius, rounded to 1 decimal. */
|
|
46
|
+
function fToC(f) {
|
|
47
|
+
return Math.round(((f - 32) * 5) / 9 * 10) / 10;
|
|
48
|
+
}
|
|
49
|
+
// ── Service ────────────────────────────────────────────────────────────────
|
|
50
|
+
export class WeatherService {
|
|
51
|
+
weatherApiKey;
|
|
52
|
+
constructor(weatherApiKey) {
|
|
53
|
+
this.weatherApiKey = weatherApiKey;
|
|
54
|
+
}
|
|
55
|
+
get hasWeatherApiKey() {
|
|
56
|
+
return !!this.weatherApiKey;
|
|
57
|
+
}
|
|
58
|
+
/** Geocode a location string to coordinates via Open-Meteo. */
|
|
59
|
+
async geocode(location) {
|
|
60
|
+
const url = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1&language=en&format=json`;
|
|
61
|
+
const res = await fetch(url);
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
throw new Error(`Geocoding failed (${res.status}): ${res.statusText}`);
|
|
64
|
+
}
|
|
65
|
+
const data = (await res.json());
|
|
66
|
+
const results = data.results;
|
|
67
|
+
if (!results || results.length === 0) {
|
|
68
|
+
throw new Error(`Location not found: "${location}"`);
|
|
69
|
+
}
|
|
70
|
+
const r = results[0];
|
|
71
|
+
return {
|
|
72
|
+
name: r.name,
|
|
73
|
+
region: r.admin1 ?? '',
|
|
74
|
+
country: r.country ?? '',
|
|
75
|
+
lat: r.latitude,
|
|
76
|
+
lon: r.longitude,
|
|
77
|
+
timezone: r.timezone ?? 'UTC',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Main entry: get weather for a location string. */
|
|
81
|
+
async getWeather(location, days = 3) {
|
|
82
|
+
const geo = await this.geocode(location);
|
|
83
|
+
// Try WeatherAPI.com first if key is available
|
|
84
|
+
if (this.weatherApiKey) {
|
|
85
|
+
try {
|
|
86
|
+
return await this.fetchWeatherApi(geo, days);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Fall through to Open-Meteo
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return this.fetchOpenMeteo(geo, days);
|
|
93
|
+
}
|
|
94
|
+
// ── WeatherAPI.com ─────────────────────────────────────────────────────
|
|
95
|
+
async fetchWeatherApi(geo, days) {
|
|
96
|
+
const clampedDays = Math.min(days, 3); // free tier = 3 days max
|
|
97
|
+
const q = `${geo.lat},${geo.lon}`;
|
|
98
|
+
const url = `https://api.weatherapi.com/v1/forecast.json?key=${this.weatherApiKey}&q=${q}&days=${clampedDays}&aqi=no&alerts=yes`;
|
|
99
|
+
const res = await fetch(url);
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
const body = await res.text().catch(() => '');
|
|
102
|
+
throw new Error(`WeatherAPI error (${res.status}): ${body}`);
|
|
103
|
+
}
|
|
104
|
+
const data = (await res.json());
|
|
105
|
+
const loc = data.location ?? {};
|
|
106
|
+
const cur = data.current ?? {};
|
|
107
|
+
const forecastDays = (data.forecast?.forecastday ?? []).map((fd) => ({
|
|
108
|
+
date: fd.date,
|
|
109
|
+
max_f: fd.day?.maxtemp_f ?? 0,
|
|
110
|
+
min_f: fd.day?.mintemp_f ?? 0,
|
|
111
|
+
max_c: fd.day?.maxtemp_c ?? 0,
|
|
112
|
+
min_c: fd.day?.mintemp_c ?? 0,
|
|
113
|
+
condition: fd.day?.condition?.text ?? 'Unknown',
|
|
114
|
+
precip_chance: fd.day?.daily_chance_of_rain ?? 0,
|
|
115
|
+
wind_max_mph: fd.day?.maxwind_mph ?? 0,
|
|
116
|
+
uv_max: fd.day?.uv ?? 0,
|
|
117
|
+
}));
|
|
118
|
+
const alerts = (data.alerts?.alert ?? []).map((a) => ({
|
|
119
|
+
headline: a.headline ?? '',
|
|
120
|
+
severity: a.severity ?? '',
|
|
121
|
+
description: a.desc ?? a.event ?? '',
|
|
122
|
+
}));
|
|
123
|
+
return {
|
|
124
|
+
provider: 'weatherapi',
|
|
125
|
+
location: {
|
|
126
|
+
name: loc.name ?? geo.name,
|
|
127
|
+
region: loc.region ?? geo.region,
|
|
128
|
+
country: loc.country ?? geo.country,
|
|
129
|
+
lat: loc.lat ?? geo.lat,
|
|
130
|
+
lon: loc.lon ?? geo.lon,
|
|
131
|
+
timezone: loc.tz_id ?? geo.timezone,
|
|
132
|
+
},
|
|
133
|
+
current: {
|
|
134
|
+
temp_f: cur.temp_f ?? 0,
|
|
135
|
+
temp_c: cur.temp_c ?? 0,
|
|
136
|
+
condition: cur.condition?.text ?? 'Unknown',
|
|
137
|
+
humidity: cur.humidity ?? 0,
|
|
138
|
+
wind_mph: cur.wind_mph ?? 0,
|
|
139
|
+
wind_dir: cur.wind_dir ?? '',
|
|
140
|
+
uv: cur.uv ?? 0,
|
|
141
|
+
feels_like_f: cur.feelslike_f ?? 0,
|
|
142
|
+
},
|
|
143
|
+
forecast: forecastDays,
|
|
144
|
+
alerts: alerts.length > 0 ? alerts : undefined,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// ── Open-Meteo ─────────────────────────────────────────────────────────
|
|
148
|
+
async fetchOpenMeteo(geo, days) {
|
|
149
|
+
const clampedDays = Math.min(days, 16);
|
|
150
|
+
const hourlyVars = 'temperature_2m,relative_humidity_2m,wind_speed_10m,precipitation_probability,weather_code';
|
|
151
|
+
const dailyVars = 'weather_code,temperature_2m_max,temperature_2m_min,precipitation_sum,precipitation_probability_max,wind_speed_10m_max,uv_index_max';
|
|
152
|
+
const url = `https://api.open-meteo.com/v1/forecast` +
|
|
153
|
+
`?latitude=${geo.lat}&longitude=${geo.lon}` +
|
|
154
|
+
`&hourly=${hourlyVars}` +
|
|
155
|
+
`&daily=${dailyVars}` +
|
|
156
|
+
`¤t=temperature_2m,relative_humidity_2m,wind_speed_10m,wind_direction_10m,weather_code` +
|
|
157
|
+
`&temperature_unit=fahrenheit` +
|
|
158
|
+
`&wind_speed_unit=mph` +
|
|
159
|
+
`&timezone=auto` +
|
|
160
|
+
`&forecast_days=${clampedDays}`;
|
|
161
|
+
const res = await fetch(url);
|
|
162
|
+
if (!res.ok) {
|
|
163
|
+
throw new Error(`Open-Meteo error (${res.status}): ${res.statusText}`);
|
|
164
|
+
}
|
|
165
|
+
const data = (await res.json());
|
|
166
|
+
const cur = data.current ?? {};
|
|
167
|
+
const daily = data.daily ?? {};
|
|
168
|
+
const forecastDays = [];
|
|
169
|
+
const dates = daily.time ?? [];
|
|
170
|
+
for (let i = 0; i < dates.length; i++) {
|
|
171
|
+
const maxF = daily.temperature_2m_max?.[i] ?? 0;
|
|
172
|
+
const minF = daily.temperature_2m_min?.[i] ?? 0;
|
|
173
|
+
forecastDays.push({
|
|
174
|
+
date: dates[i],
|
|
175
|
+
max_f: maxF,
|
|
176
|
+
min_f: minF,
|
|
177
|
+
max_c: fToC(maxF),
|
|
178
|
+
min_c: fToC(minF),
|
|
179
|
+
condition: wmoToCondition(daily.weather_code?.[i] ?? 0),
|
|
180
|
+
precip_chance: daily.precipitation_probability_max?.[i] ?? 0,
|
|
181
|
+
wind_max_mph: daily.wind_speed_10m_max?.[i] ?? 0,
|
|
182
|
+
uv_max: daily.uv_index_max?.[i] ?? 0,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const tempF = cur.temperature_2m ?? 0;
|
|
186
|
+
const windDir = cur.wind_direction_10m ?? 0;
|
|
187
|
+
const cardinals = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'];
|
|
188
|
+
const windDirStr = cardinals[Math.round(windDir / 22.5) % 16];
|
|
189
|
+
return {
|
|
190
|
+
provider: 'open-meteo',
|
|
191
|
+
location: geo,
|
|
192
|
+
current: {
|
|
193
|
+
temp_f: tempF,
|
|
194
|
+
temp_c: fToC(tempF),
|
|
195
|
+
condition: wmoToCondition(cur.weather_code ?? 0),
|
|
196
|
+
humidity: cur.relative_humidity_2m ?? 0,
|
|
197
|
+
wind_mph: cur.wind_speed_10m ?? 0,
|
|
198
|
+
wind_dir: windDirStr,
|
|
199
|
+
uv: forecastDays[0]?.uv_max ?? 0,
|
|
200
|
+
feels_like_f: tempF, // Open-Meteo free doesn't provide feels-like
|
|
201
|
+
},
|
|
202
|
+
forecast: forecastDays,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=weatherService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weatherService.js","sourceRoot":"","sources":["../../src/services/weatherService.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;;;GAQG;AAkDH,8EAA8E;AAE9E,MAAM,SAAS,GAA2B;IACxC,CAAC,EAAE,WAAW;IACd,CAAC,EAAE,cAAc;IACjB,CAAC,EAAE,eAAe;IAClB,CAAC,EAAE,UAAU;IACb,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,qBAAqB;IACzB,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,kBAAkB;IACtB,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,wBAAwB;IAC5B,EAAE,EAAE,wBAAwB;IAC5B,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,eAAe;IACnB,EAAE,EAAE,YAAY;IAChB,EAAE,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AAC,CAAC;QAE9D,OAAO;YACL,QAAQ,EAAE,YAAY;YACtB,QAAQ,EAAE,GAAG;YACb,OAAO,EAAE;gBACP,MAAM,EAAE,KAAK;gBACb,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;gBACnB,SAAS,EAAE,cAAc,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,CAAC;gBAChD,QAAQ,EAAE,GAAG,CAAC,oBAAoB,IAAI,CAAC;gBACvC,QAAQ,EAAE,GAAG,CAAC,cAAc,IAAI,CAAC;gBACjC,QAAQ,EAAE,UAAU;gBACpB,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC;gBAChC,YAAY,EAAE,KAAK,EAAE,6CAA6C;aACnE;YACD,QAAQ,EAAE,YAAY;SACvB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ITool, ToolExecutionContext, ToolExecutionResult, JSONSchemaObject } from '@framers/agentos';
|
|
2
|
+
import { WeatherService } from '../services/weatherService.js';
|
|
3
|
+
import type { WeatherResult } from '../services/weatherService.js';
|
|
4
|
+
export interface WeatherLookupInput {
|
|
5
|
+
location: string;
|
|
6
|
+
days?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class WeatherLookupTool implements ITool<WeatherLookupInput, WeatherResult> {
|
|
9
|
+
private readonly service;
|
|
10
|
+
readonly id = "weather-lookup-v1";
|
|
11
|
+
readonly name = "weather_lookup";
|
|
12
|
+
readonly displayName = "Weather Lookup";
|
|
13
|
+
readonly description = "Check the weather for any city or location. Use this when the user asks \"what's the weather\", \"will it rain\", \"is it cold\", \"forecast for\", \"temperature in\", or any weather-related question. Returns current conditions and forecasts including temperature (F/C), humidity, wind, precipitation, UV index, and severe weather alerts.";
|
|
14
|
+
readonly category = "research";
|
|
15
|
+
readonly version = "1.0.0";
|
|
16
|
+
readonly hasSideEffects = false;
|
|
17
|
+
readonly inputSchema: JSONSchemaObject;
|
|
18
|
+
readonly requiredCapabilities: string[];
|
|
19
|
+
constructor(service: WeatherService);
|
|
20
|
+
execute(args: WeatherLookupInput, _context: ToolExecutionContext): Promise<ToolExecutionResult<WeatherResult>>;
|
|
21
|
+
validateArgs(input: Record<string, any>): {
|
|
22
|
+
isValid: boolean;
|
|
23
|
+
errors?: any[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=weatherLookup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weatherLookup.d.ts","sourceRoot":"","sources":["../../src/tools/weatherLookup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EACL,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,iBAAkB,YAAW,KAAK,CAAC,kBAAkB,EAAE,aAAa,CAAC;IA+BpE,OAAO,CAAC,QAAQ,CAAC,OAAO;IA9BpC,QAAQ,CAAC,EAAE,uBAAuB;IAClC,QAAQ,CAAC,IAAI,oBAAoB;IACjC,QAAQ,CAAC,WAAW,oBAAoB;IACxC,QAAQ,CAAC,WAAW,wVAC0T;IAC9U,QAAQ,CAAC,QAAQ,cAAc;IAC/B,QAAQ,CAAC,OAAO,WAAW;IAC3B,QAAQ,CAAC,cAAc,SAAS;IAEhC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAiBpC;IAEF,QAAQ,CAAC,oBAAoB,WAA6B;gBAE7B,OAAO,EAAE,cAAc;IAE9C,OAAO,CACX,IAAI,EAAE,kBAAkB,EACxB,QAAQ,EAAE,oBAAoB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAa9C,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAA;KAAE;CAY/E"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export class WeatherLookupTool {
|
|
2
|
+
service;
|
|
3
|
+
id = 'weather-lookup-v1';
|
|
4
|
+
name = 'weather_lookup';
|
|
5
|
+
displayName = 'Weather Lookup';
|
|
6
|
+
description = 'Check the weather for any city or location. Use this when the user asks "what\'s the weather", "will it rain", "is it cold", "forecast for", "temperature in", or any weather-related question. Returns current conditions and forecasts including temperature (F/C), humidity, wind, precipitation, UV index, and severe weather alerts.';
|
|
7
|
+
category = 'research';
|
|
8
|
+
version = '1.0.0';
|
|
9
|
+
hasSideEffects = false;
|
|
10
|
+
inputSchema = {
|
|
11
|
+
type: 'object',
|
|
12
|
+
required: ['location'],
|
|
13
|
+
properties: {
|
|
14
|
+
location: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'City name, zip code, or lat,lon coordinates (e.g. "Las Vegas", "90210", "36.17,-115.14")',
|
|
17
|
+
},
|
|
18
|
+
days: {
|
|
19
|
+
type: 'integer',
|
|
20
|
+
minimum: 1,
|
|
21
|
+
maximum: 14,
|
|
22
|
+
default: 3,
|
|
23
|
+
description: 'Number of forecast days (1-14, default 3)',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
};
|
|
28
|
+
requiredCapabilities = ['capability:web_access'];
|
|
29
|
+
constructor(service) {
|
|
30
|
+
this.service = service;
|
|
31
|
+
}
|
|
32
|
+
async execute(args, _context) {
|
|
33
|
+
if (!args.location || args.location.trim().length === 0) {
|
|
34
|
+
return { success: false, error: 'Location is required.' };
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const result = await this.service.getWeather(args.location.trim(), args.days ?? 3);
|
|
38
|
+
return { success: true, output: result };
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return { success: false, error: `Weather lookup failed: ${err.message}` };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
validateArgs(input) {
|
|
45
|
+
const errors = [];
|
|
46
|
+
if (!input.location || typeof input.location !== 'string') {
|
|
47
|
+
errors.push('location is required and must be a string');
|
|
48
|
+
}
|
|
49
|
+
if (input.days !== undefined) {
|
|
50
|
+
if (typeof input.days !== 'number' || input.days < 1 || input.days > 14) {
|
|
51
|
+
errors.push('days must be an integer between 1 and 14');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { isValid: errors.length === 0, errors: errors.length ? errors : undefined };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=weatherLookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weatherLookup.js","sourceRoot":"","sources":["../../src/tools/weatherLookup.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,iBAAiB;IA+BC;IA9BpB,EAAE,GAAG,mBAAmB,CAAC;IACzB,IAAI,GAAG,gBAAgB,CAAC;IACxB,WAAW,GAAG,gBAAgB,CAAC;IAC/B,WAAW,GAClB,2UAA2U,CAAC;IACrU,QAAQ,GAAG,UAAU,CAAC;IACtB,OAAO,GAAG,OAAO,CAAC;IAClB,cAAc,GAAG,KAAK,CAAC;IAEvB,WAAW,GAAqB;QACvC,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC;QACtB,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,0FAA0F;aACxG;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,EAAE;gBACX,OAAO,EAAE,CAAC;gBACV,WAAW,EAAE,2CAA2C;aACzD;SACF;QACD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AAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IACtF,CAAC;CACF"}
|
package/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://agentos.sh/schemas/extension-manifest-v1.json",
|
|
3
3
|
"id": "com.framers.research.weather",
|
|
4
4
|
"name": "Weather Extension",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.1",
|
|
6
6
|
"description": "Weather lookup via WeatherAPI.com (preferred) with Open-Meteo fallback (no key required)",
|
|
7
7
|
"author": { "name": "Rabbit Hole Inc" },
|
|
8
8
|
"license": "MIT",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@framers/agentos-ext-weather",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Weather lookup via WeatherAPI.com (preferred) with Open-Meteo fallback for AgentOS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
"./package.json": "./package.json"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@framers/agentos": "^0.
|
|
18
|
+
"@framers/agentos": "^0.10.28"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@framers/agentos": "^0.1.0",
|
|
22
21
|
"@types/node": "^20.12.12",
|
|
23
22
|
"typescript": "^5.4.5",
|
|
24
|
-
"vitest": "^1.6.0"
|
|
23
|
+
"vitest": "^1.6.0",
|
|
24
|
+
"@framers/agentos": "^0.10.28"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
|
-
"url": "https://github.com/
|
|
28
|
+
"url": "git+https://github.com/framerslab/agentos-extensions.git",
|
|
29
29
|
"directory": "registry/curated/research/weather"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
@@ -39,9 +39,17 @@
|
|
|
39
39
|
"open-meteo",
|
|
40
40
|
"weatherapi"
|
|
41
41
|
],
|
|
42
|
+
"homepage": "https://github.com/framerslab/agentos-extensions/tree/master/registry/curated/research/weather#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/framerslab/agentos-extensions/issues"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"manifest.json"
|
|
49
|
+
],
|
|
42
50
|
"scripts": {
|
|
43
51
|
"build": "tsc",
|
|
44
|
-
"test": "vitest run",
|
|
52
|
+
"test": "vitest run --passWithNoTests",
|
|
45
53
|
"test:watch": "vitest",
|
|
46
54
|
"typecheck": "tsc --noEmit",
|
|
47
55
|
"clean": "rimraf dist"
|