dwelldelta-mcp 0.8.0 → 0.10.0
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/README.md +63 -5
- package/area-rents-tool.mjs +143 -52
- package/contribute-tool.mjs +9 -3
- package/output-schemas.mjs +268 -0
- package/package.json +3 -1
- package/register-tools.mjs +242 -0
- package/sale-prices-tool.mjs +48 -12
- package/server.mjs +25 -156
- package/tools.mjs +354 -22
- package/vendor/contribute.mjs +1 -1
- package/vendor/indicators.json +7 -7
- package/vendor/qld-rents.json +2689 -2689
- package/vic-rents-tool.mjs +39 -16
package/README.md
CHANGED
|
@@ -12,15 +12,15 @@ Six read-only tools, and one that adds the user's own rent when they ask:
|
|
|
12
12
|
| `market_indicators` | the latest RBA cash rate, unemployment, wage growth, rents for all eight capitals, NSW lending, lending standards and arrears, approvals and completions - each with period, source, licence and limits; filter by `geography` |
|
|
13
13
|
| `vic_rents` | Victorian rents by suburb group from Homes Victoria's Rental Report: the median weekly rent of new leases, the lease count and the change on a year before, for 146 suburb groups and 13 regions; filter by `suburb_group` or `region` (from 0.5.0) |
|
|
14
14
|
| `area_rents` | median weekly rent of new bonds, all dwellings together, with the bond count and the change on a year before, for one state per call: NSW by postcode or council (NSW Department of Communities and Justice), Queensland by suburb or council (Residential Tenancies Authority), WA by locality (calculated by DwellDelta from the Government of Western Australia's bond records); each CC BY 4.0 (from 0.6.0) |
|
|
15
|
-
| `nsw_sale_prices` | NSW median sale prices by postcode or council from the NSW Department of Communities and Justice's Rent and Sales Report (CC BY 4.0): the median, the quartiles, the number of sales and the change on a year before, each for all dwellings, houses (non-strata) and units and town houses (strata). Medians of homes sold - never what any one home sold for; a line a few very large sales
|
|
15
|
+
| `nsw_sale_prices` | NSW median sale prices by postcode or council from the NSW Department of Communities and Justice's Rent and Sales Report (CC BY 4.0): the median, the quartiles, the number of sales and the change on a year before, each for all dwellings, houses (non-strata) and units and town houses (strata). Medians of homes sold - never what any one home sold for; a line set by a few very large sales or by many sales at one identical price is marked UNUSUAL (from 0.7.0), and is not a going price |
|
|
16
16
|
| `data_sources` | the sources, their licences, and what DwellDelta cannot answer |
|
|
17
17
|
| `contribute_rent` | adds the user's own rent, anonymously, to DwellDelta's suburb benchmarks - only when the user asks, and only after they have read and agreed to the consent wording (from 0.5.0) |
|
|
18
18
|
|
|
19
19
|
It runs on your own machine over stdio. It records nothing and sends nothing about you unless you choose to add
|
|
20
20
|
your rent. At start it fetches DwellDelta's published files from tools.dwelldelta.com.au - the week's indicators,
|
|
21
|
-
the rents and sale prices it answers from,
|
|
22
|
-
your questions is sent - and otherwise uses the copies it
|
|
23
|
-
|
|
21
|
+
the rents and sale prices it answers from, and (from 0.9.0) the ABS rents index behind `rent_check`, nine public
|
|
22
|
+
files in all, the same for everyone; nothing about you or your questions is sent - and otherwise uses the copies it
|
|
23
|
+
ships with. Set `DWELLDELTA_OFFLINE=1` and none of those nine files is fetched; adding a rent with `contribute_rent` still sends it, as you asked. Nothing it says is a
|
|
24
24
|
forecast, a valuation or advice.
|
|
25
25
|
|
|
26
26
|
## Adding a rent (from 0.5.0)
|
|
@@ -115,6 +115,63 @@ ships with, and the bundled copy when offline. Once a snapshot is more than 10 d
|
|
|
115
115
|
words and in the structured result, rather than passing an old figure off as current. Set `DWELLDELTA_INDICATORS`
|
|
116
116
|
to read another snapshot file.
|
|
117
117
|
|
|
118
|
+
The ABS rents index behind `rent_check` is DwellDelta's copy at
|
|
119
|
+
https://tools.dwelldelta.com.au/rent/data/rents-index.json, updated with each monthly ABS release. Up to 0.8.0 the
|
|
120
|
+
server read only the copy bundled when the package was made, so `rent_check` answered only to that copy's latest
|
|
121
|
+
month and nothing in the answer said the index had moved on. From 0.9.0 it fetches the published copy once at
|
|
122
|
+
start, like every other file, and uses it when it is well formed (source, attribution, licence and release named;
|
|
123
|
+
every city the bundled copy has, each a run of contiguous months with positive index values), covers the bundled
|
|
124
|
+
copy city by city (each city's series starts no later and ends no earlier than in the bundled copy) and has no month
|
|
125
|
+
later than the current one; otherwise, or with `DWELLDELTA_OFFLINE=1`, the bundled copy answers.
|
|
126
|
+
`data_as_of` and the `Cite:` line's period say which month the answer runs to.
|
|
127
|
+
|
|
128
|
+
### Checkable provenance (from 0.9.0)
|
|
129
|
+
|
|
130
|
+
Every answer that gives a figure ends with a `Cite:` line to quote with it: the source, the period, the licence id
|
|
131
|
+
(SPDX, e.g. `CC-BY-4.0`), n (the number of bonds, leases or sales the figure rests on, or why there is none), the
|
|
132
|
+
source's URL (or, where the file names only one, the publisher's copyright notice, labelled so), and DwellDelta's
|
|
133
|
+
published data file. The structured result says the same, in new fields; every field above keeps its meaning:
|
|
134
|
+
|
|
135
|
+
- each entry of `sources` adds `licence_id`, `licence_url`, `source_url`, `source_notice_url`, `feed_url` and
|
|
136
|
+
`period`. `source_url` is only ever an address of the data's own page that the data file itself holds: for WA
|
|
137
|
+
the National Housing Data Exchange dataset page, for Victoria the DataVic page in its source line. It is null
|
|
138
|
+
where the file holds none - DCJ's files (NSW rents, rents by type, sale prices), the RTA's (Queensland), the ABS
|
|
139
|
+
rents index and the indicators snapshot. DCJ's and the RTA's files name only a copyright notice
|
|
140
|
+
(https://dcj.nsw.gov.au/statements/copyright-and-disclaimer.html, which DCJ's attribution also names, and
|
|
141
|
+
https://www.rta.qld.gov.au/copyright; the RTA's attribution names no URL): that is `source_notice_url`, and the
|
|
142
|
+
`Cite:` line labels it `copyright notice`, never `source URL`. `feed_url` is the file at tools.dwelldelta.com.au
|
|
143
|
+
the figure came from, to fetch and check.
|
|
144
|
+
- `stale` and `stale_reason` keep the meaning they have had since 0.2.0: the weekly indicators snapshot is more
|
|
145
|
+
than 10 days old. They are `false` / `null` on every answer without a snapshot (rents, sale prices,
|
|
146
|
+
`rent_check`). `stale_after` is the day the snapshot turns stale (null without one); `cadence` is `weekly`,
|
|
147
|
+
`quarterly` or `monthly`.
|
|
148
|
+
- `period_due_by`, `period_overdue` and `period_overdue_reason` (new) come from the data's own release cadence:
|
|
149
|
+
`period_due_by` is the day by which the release after this period was due, and `period_overdue` is true once it
|
|
150
|
+
has passed with no newer file. A quarterly rents file is overdue once its quarter ended more than seven months
|
|
151
|
+
ago (the next quarter, plus the publisher's lag), NSW sale prices after ten (DCJ's sales run a quarter behind its
|
|
152
|
+
rents), and the ABS monthly rents index two months after its latest month. An overdue answer opens with a
|
|
153
|
+
`STALE:` line giving the reason, and its `Cite:` line ends `; STALE.` - as an old snapshot's does.
|
|
154
|
+
- `figures` (`area_rents`, with or without `dwelling_type` and `bedrooms`, `vic_rents`, `nsw_sale_prices`): one
|
|
155
|
+
entry per figure of the answer, with `n`, `n_band` (where the publisher withholds the exact count), `unit`,
|
|
156
|
+
`small_sample` and `refusal`. `refusals` lists the refused ones, `all_refused` says whether anything may be
|
|
157
|
+
quoted, and `sample_rule` is the publisher's rule.
|
|
158
|
+
- A figure that rests on too few records is a refusal, never a weak number: `{ refused: true, type:
|
|
159
|
+
"too_few_records", reason, n, n_band, unit, min_n, rule }` (`type` is `not_published` for a combination the
|
|
160
|
+
publisher does not list). The rules are each file's own: DCJ reports nothing for 10 or fewer bonds or sales
|
|
161
|
+
(`min_n` 11), a WA locality needs 10 bonds, and the RTA and Homes Victoria withhold small medians without
|
|
162
|
+
stating a number. A median the file gives below its rule is refused in the text as well; the file's own figure
|
|
163
|
+
is left as it is in the structured rows.
|
|
164
|
+
- Each structured row says on itself whether the text refused its figure (from 0.9.0; additions only - no field a
|
|
165
|
+
row had is changed or removed): `refused: true` and `refusal_type` (`too_few_records` or `not_published`, the same
|
|
166
|
+
as the refusal's `type`) on a refused row, `refused: false` and `refusal_type: null` on a row whose figure is
|
|
167
|
+
given. The rows are `area_rents`' `state_total`, `regions`, `councils` and `areas` (every state), its by-type
|
|
168
|
+
`rows` (NSW and Queensland), `vic_rents`' `regions` and `suburb_groups`, and in `nsw_sale_prices` each place's
|
|
169
|
+
`total`, `non_strata` and `strata` row. So a refused row's weak `median_weekly_rent_aud` (or `median_price_k_aud`)
|
|
170
|
+
is never read as a figure by an agent that reads only the rows. A sale-prices dwelling type with no row in DCJ's
|
|
171
|
+
table stays `null`, as the file has it - there is no figure on it to misread - and its `not_published` refusal is
|
|
172
|
+
in `refusals`.
|
|
173
|
+
- `rent_check` and `market_indicators` say `sample_size: null` and why: an index and these indicators have no count.
|
|
174
|
+
|
|
118
175
|
## Licence
|
|
119
176
|
|
|
120
177
|
The code is MIT (see LICENSE). The data is not: each figure keeps its source's licence and attribution, which every
|
|
@@ -123,5 +180,6 @@ answer states - for example ABS data is CC BY 4.0, "Based on Australian Bureau o
|
|
|
123
180
|
## Development
|
|
124
181
|
|
|
125
182
|
`npm test` here starts the server and calls the six read-only tools, and the first (consent) call of
|
|
126
|
-
`contribute_rent`, over MCP
|
|
183
|
+
`contribute_rent`, over MCP, and `test/provenance.test.mjs` holds the provenance above on the vendored files and
|
|
184
|
+
fixtures; the repository's root `npm test` holds the
|
|
127
185
|
tool answers themselves and checks that `vendor/` matches its sources. `npm pack` runs `scripts/vendor.mjs` first.
|
package/area-rents-tool.mjs
CHANGED
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
import { existsSync } from "node:fs";
|
|
19
19
|
import { fileURLToPath } from "node:url";
|
|
20
20
|
import { dirname, join } from "node:path";
|
|
21
|
-
import { loadJson, envelope, ToolError, FOOTER, FETCH_TIMEOUT_MS
|
|
21
|
+
import { loadJson, envelope, ToolError, FOOTER, FETCH_TIMEOUT_MS, feedSource, CADENCE, SAMPLE_RULES, judgeFigure,
|
|
22
|
+
figureFields, nWords, citeLine, staleNote, flagged, refusalMark, isRecord, passes, readChecked, quiet,
|
|
23
|
+
warnPublished, fromCopy } from "./tools.mjs";
|
|
22
24
|
import { quarterKey } from "./vic-rents-tool.mjs";
|
|
23
25
|
|
|
24
26
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
@@ -31,31 +33,41 @@ export const STATES = {
|
|
|
31
33
|
QLD: { file: "qld-rents.json", name: "Queensland",
|
|
32
34
|
hint: "Queensland rents are by suburb, as the RTA names it (area: \"Acacia Ridge\"; part of a name works), " +
|
|
33
35
|
"or by council (council: \"Brisbane\")." },
|
|
34
|
-
WA
|
|
36
|
+
// WA's source_notice is the Housing Data Exchange page of the bond records themselves, so it is the source's URL.
|
|
37
|
+
// NSW's and Queensland's are DCJ's and the RTA's copyright notices: a notice, never called the source URL.
|
|
38
|
+
WA: { file: "wa-rents.json", name: "Western Australia", notice_is_data: true,
|
|
35
39
|
hint: "WA rents are by locality (area: \"Fremantle\"; part of a name works). There are no councils in the " +
|
|
36
40
|
"bond records." },
|
|
37
41
|
};
|
|
42
|
+
/** Each state's small-sample rule (tools.mjs SAMPLE_RULES): below it a figure is refused, never given. */
|
|
43
|
+
export const RULES = { NSW: SAMPLE_RULES.NSW_RENTS, QLD: SAMPLE_RULES.QLD_RENTS, WA: SAMPLE_RULES.WA_RENTS };
|
|
38
44
|
/** Rows shown in one answer; a wider match says how many more there are instead of dropping them silently. */
|
|
39
45
|
export const MAX_ROWS = 25;
|
|
40
46
|
|
|
47
|
+
// A row of its lists that is not a row is skipped where the tool reads them, and a row's name of another type matches
|
|
48
|
+
// nothing (tools.mjs, "What a copy must be before it answers"): the checks here are the ones the feed always had.
|
|
41
49
|
const wellFormed = (f, state) => f && f.state === state && quarterKey(f.quarter) > 0
|
|
42
50
|
&& Array.isArray(f.areas) && f.areas.length > 0 && Array.isArray(f.councils) && Array.isArray(f.regions)
|
|
43
51
|
&& f.state_total && Array.isArray(f.limits) && f.licence && f.attribution && f.changes_made;
|
|
44
52
|
|
|
45
53
|
/** One state's feed and where it came from ("env", "live", "published" or "bundled"); { feed: null } if none. */
|
|
46
54
|
export async function loadAreaRents(state, { env = process.env, fetchImpl = globalThis.fetch, liveDir = LIVE_DIR,
|
|
47
|
-
bundledDir = BUNDLED_DIR } = {}) {
|
|
55
|
+
bundledDir = BUNDLED_DIR, warn = quiet } = {}) {
|
|
48
56
|
const { file } = STATES[state];
|
|
57
|
+
const what = `the ${STATES[state].name} rents feed`;
|
|
49
58
|
// A copy that is not this state's feed is no copy: the wrong file under the right name must never answer.
|
|
50
|
-
const read = (path) =>
|
|
51
|
-
if (env.DWELLDELTA_STATE_RENTS_DIR)
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
const read = (path, variable) => readChecked(path, (f) => wellFormed(f, state), what, variable, warn);
|
|
60
|
+
if (env.DWELLDELTA_STATE_RENTS_DIR) {
|
|
61
|
+
return fromCopy(await read(join(env.DWELLDELTA_STATE_RENTS_DIR, file), "DWELLDELTA_STATE_RENTS_DIR"), "feed", "env");
|
|
62
|
+
}
|
|
63
|
+
if (existsSync(join(liveDir, file))) return fromCopy(await read(join(liveDir, file)), "feed", "live");
|
|
64
|
+
const shipped = (await read(join(bundledDir, file))).copy;
|
|
54
65
|
if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
|
|
55
66
|
try {
|
|
56
67
|
const res = await fetchImpl(PUBLISHED_BASE + file, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
57
68
|
const got = res.ok ? await res.json() : null;
|
|
58
|
-
if (wellFormed
|
|
69
|
+
if (got != null && !passes(wellFormed, got, state)) warnPublished(warn, what, PUBLISHED_BASE + file, shipped);
|
|
70
|
+
if (passes(wellFormed, got, state) && (!shipped || quarterKey(got.quarter) >= quarterKey(shipped.quarter))) {
|
|
59
71
|
return { feed: got, origin: "published" };
|
|
60
72
|
}
|
|
61
73
|
} catch {
|
|
@@ -65,11 +77,21 @@ export async function loadAreaRents(state, { env = process.env, fetchImpl = glob
|
|
|
65
77
|
return { feed: shipped, origin: shipped ? "bundled" : null };
|
|
66
78
|
}
|
|
67
79
|
|
|
68
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* Every state's feed, loaded together at start: { NSW: feed-with-origin | null, QLD: ..., WA: ... }. A state whose copy
|
|
82
|
+
* was refused is named, with that copy, in its refused property - not enumerable, so the states are all there is to
|
|
83
|
+
* list - for the tool to say that copy could not be used (withRefused).
|
|
84
|
+
*/
|
|
69
85
|
export async function loadAllAreaRents(opts) {
|
|
70
86
|
const loaded = await Promise.all(Object.keys(STATES).map((s) => loadAreaRents(s, opts)));
|
|
71
|
-
return Object.fromEntries(Object.keys(STATES).map((s, i) =>
|
|
72
|
-
[s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null]));
|
|
87
|
+
return withRefused(Object.fromEntries(Object.keys(STATES).map((s, i) =>
|
|
88
|
+
[s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null])), Object.keys(STATES), loaded);
|
|
89
|
+
}
|
|
90
|
+
/** feeds, with the refused copies of states[i] (loaded[i].refused) as a property that is not enumerable. */
|
|
91
|
+
export function withRefused(feeds, states, loaded) {
|
|
92
|
+
const refused = Object.fromEntries(states.map((s, i) => [s, loaded[i]?.refused ?? null]).filter(([, r]) => r));
|
|
93
|
+
if (Object.keys(refused).length) Object.defineProperty(feeds, "refused", { value: refused, enumerable: false });
|
|
94
|
+
return feeds;
|
|
73
95
|
}
|
|
74
96
|
|
|
75
97
|
// Exported for sale-prices-tool.mjs (0.7.0), which matches names and words figures the same way.
|
|
@@ -79,12 +101,19 @@ export const norm = (s) => String(s).trim().toLowerCase();
|
|
|
79
101
|
export const dollars = (v) => { const n = Number(v); return `$${n.toLocaleString("en-AU", Number.isInteger(n) ? {} : { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; };
|
|
80
102
|
export const signed = (v) => `${v >= 0 ? "+" : ""}${v}%`;
|
|
81
103
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
/** Why a row has no median, in the words the answer has always used. */
|
|
105
|
+
const whyNone = (r) => r.withheld ?? (r.new_bonds == null ? "too few bonds"
|
|
106
|
+
: `${r.new_bonds} new bond${r.new_bonds === 1 ? "" : "s"} - too few for a median`);
|
|
107
|
+
|
|
108
|
+
/** One figure's sample and, if it rests on too few bonds, its refusal (see judgeFigure in tools.mjs). */
|
|
109
|
+
export const rentFigure = (r, name, rule) => judgeFigure(r, { name, median: "median_weekly_rent_aud", count: "new_bonds",
|
|
110
|
+
band: "new_bonds_band", rule, why: r && r.median_weekly_rent_aud == null ? whyNone(r) : null });
|
|
111
|
+
|
|
112
|
+
function line(r, name, rule = null) {
|
|
113
|
+
if (r.median_weekly_rent_aud == null) return `${name}: no median (${whyNone(r)}).`;
|
|
114
|
+
// A median below the publisher's own rule is refused, not printed: never a weak number.
|
|
115
|
+
const refusal = rule ? rentFigure(r, name, rule).refusal : null;
|
|
116
|
+
if (refusal) return `${name}: no median (${refusal.reason}).`;
|
|
88
117
|
const bonds = r.new_bonds_band ? ` from ${r.new_bonds_band} new bonds (the publisher withholds the count)`
|
|
89
118
|
: r.new_bonds == null ? "" : ` from ${r.new_bonds.toLocaleString("en-AU")} new bonds`;
|
|
90
119
|
const change = r.change_pct == null ? ""
|
|
@@ -98,8 +127,10 @@ function line(r, name) {
|
|
|
98
127
|
|
|
99
128
|
/** Exact name first, so "Brighton" does not drag in "Brighton East"; otherwise every name containing the words. */
|
|
100
129
|
export function match(rows, key, wanted) {
|
|
101
|
-
|
|
102
|
-
|
|
130
|
+
// A row that is not a row is skipped (tools.mjs, "What a copy must be before it answers").
|
|
131
|
+
const real = rows.filter(isRecord);
|
|
132
|
+
const exact = real.filter((r) => norm(r[key]) === norm(wanted));
|
|
133
|
+
return exact.length ? exact : real.filter((r) => norm(r[key]).includes(norm(wanted)));
|
|
103
134
|
}
|
|
104
135
|
|
|
105
136
|
/**
|
|
@@ -108,7 +139,7 @@ export function match(rows, key, wanted) {
|
|
|
108
139
|
* holds - offered as the next step, never answered silently, because a postcode's median is not a suburb's.
|
|
109
140
|
*/
|
|
110
141
|
export function nswPostcodes(wanted, suburbs, feed) {
|
|
111
|
-
const held = new Set(feed.areas.map((r) => r.area));
|
|
142
|
+
const held = new Set(feed.areas.filter(isRecord).map((r) => r.area));
|
|
112
143
|
const named = suburbs.map((s) => /^(.*) \((\d{4})\)$/.exec(s)).filter((m) => m && held.has(m[2]));
|
|
113
144
|
const exact = named.filter((m) => norm(m[1]) === norm(wanted));
|
|
114
145
|
const found = exact.length ? exact : named.filter((m) => norm(m[1]).includes(norm(wanted)));
|
|
@@ -121,7 +152,7 @@ export function nswPostcodes(wanted, suburbs, feed) {
|
|
|
121
152
|
* start by loadAllRentsByType) - see byTypeResult below.
|
|
122
153
|
*/
|
|
123
154
|
export function areaRentsResult({ state, area, council, dwelling_type, bedrooms } = {}, feeds, now = new Date(),
|
|
124
|
-
{ nswSuburbs = [], byType = {} } = {}) {
|
|
155
|
+
{ nswSuburbs = [], byType = {}, hosted = false } = {}) {
|
|
125
156
|
const info = STATES[state];
|
|
126
157
|
if (!info) {
|
|
127
158
|
throw new ToolError(`No area rents for ${JSON.stringify(state)}.`,
|
|
@@ -129,6 +160,10 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
129
160
|
`the Northern Territory are not covered.`);
|
|
130
161
|
}
|
|
131
162
|
const feed = feeds[state];
|
|
163
|
+
if (!feed && feeds.refused?.[state]) {
|
|
164
|
+
throw new ToolError(`The ${info.name} rents feed could not be used: ${feeds.refused[state]} failed the check of the file.`,
|
|
165
|
+
`Point DWELLDELTA_STATE_RENTS_DIR at a folder holding a good copy of ${PUBLISHED_BASE}${info.file}.`);
|
|
166
|
+
}
|
|
132
167
|
if (!feed) {
|
|
133
168
|
throw new ToolError(`The ${info.name} rents feed is not on this machine.`,
|
|
134
169
|
`Point DWELLDELTA_STATE_RENTS_DIR at a folder holding a copy of ${PUBLISHED_BASE}${info.file}.`);
|
|
@@ -154,24 +189,34 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
154
189
|
}
|
|
155
190
|
const whole = !areas.length && !councils.length;
|
|
156
191
|
if (wantsByType({ dwelling_type, bedrooms })) {
|
|
157
|
-
return byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state]
|
|
192
|
+
return byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file: byType[state],
|
|
193
|
+
refusedFile: byType.refused?.[state] ?? null, hosted }, now);
|
|
158
194
|
}
|
|
159
|
-
if (whole) regions = feed.regions;
|
|
195
|
+
if (whole) regions = feed.regions.filter(isRecord);
|
|
160
196
|
const dropped = [];
|
|
161
197
|
for (const [label, rows] of [[kind, areas], ["council", councils]]) {
|
|
162
198
|
if (rows.length > MAX_ROWS) dropped.push(`${rows.length - MAX_ROWS} more ${label} rows match: narrow the name.`);
|
|
163
199
|
}
|
|
164
200
|
areas = areas.slice(0, MAX_ROWS);
|
|
165
201
|
councils = councils.slice(0, MAX_ROWS);
|
|
166
|
-
const
|
|
167
|
-
|
|
202
|
+
const rule = RULES[state];
|
|
203
|
+
const feedUrl = PUBLISHED_BASE + info.file;
|
|
204
|
+
const env = envelope({ sources: [feedSource(feed, feedUrl, feed.quarter, { noticeIsData: info.notice_is_data === true })],
|
|
205
|
+
dataAsOf: feed.quarter,
|
|
206
|
+
origin: feed.origin ?? null, cadence: CADENCE.rents_quarterly }, now);
|
|
207
|
+
// Every line, in the order the answer gives them: its name, its row.
|
|
208
|
+
const shown = [...(whole ? [[`${info.name} (whole state)`, feed.state_total]] : []),
|
|
209
|
+
...regions.map((r) => [`${r.region} (region)`, r]), ...councils.map((r) => [`${r.council} (council)`, r]),
|
|
210
|
+
...areas.map((r) => [`${r.area} (${kind})`, r])];
|
|
211
|
+
const figures = shown.map(([name, r]) => rentFigure(r, name, rule));
|
|
212
|
+
// Each row as the file gives it, plus its own refusal marker (a copy: the loaded feed is never written to).
|
|
213
|
+
const judged = new Map(shown.map(([, r], i) => [r, figures[i]]));
|
|
214
|
+
const marked = (r) => ({ ...r, ...refusalMark(judged.get(r)) });
|
|
168
215
|
const text = [
|
|
216
|
+
...staleNote(env),
|
|
169
217
|
`${feed.what}. Quarter: ${feed.quarter}, against ${feed.compared_with}.`,
|
|
170
218
|
"",
|
|
171
|
-
...(
|
|
172
|
-
...regions.map((r) => line(r, `${r.region} (region)`)),
|
|
173
|
-
...councils.map((r) => line(r, `${r.council} (council)`)),
|
|
174
|
-
...areas.map((r) => line(r, `${r.area} (${kind})`)),
|
|
219
|
+
...shown.map(([name, r]) => line(r, name, rule)),
|
|
175
220
|
...dropped,
|
|
176
221
|
...(whole ? ["", `${feed.areas.length.toLocaleString("en-AU")} ${kind} rows` +
|
|
177
222
|
`${feed.councils.length ? ` and ${feed.councils.length} councils` : ""} are available: call again with area` +
|
|
@@ -182,16 +227,21 @@ export function areaRentsResult({ state, area, council, dwelling_type, bedrooms
|
|
|
182
227
|
"",
|
|
183
228
|
`Source: ${feed.attribution}`,
|
|
184
229
|
`What DwellDelta changed: ${feed.changes_made}`,
|
|
230
|
+
citeLine({ source: feed.source, period: `${feed.quarter} (against ${feed.compared_with})`, licence: feed.licence,
|
|
231
|
+
n: nWords(figures, rule.unit), url: env.sources[0].source_url, notice: env.sources[0].source_notice_url,
|
|
232
|
+
feedUrl, stale: flagged(env) }),
|
|
185
233
|
FOOTER,
|
|
186
234
|
].join("\n");
|
|
187
235
|
return { text, structured: { ...env, state, state_name: info.name, area_kind: kind, quarter: feed.quarter,
|
|
188
236
|
compared_with: feed.compared_with, derived: feed.derived === true,
|
|
189
|
-
state_total: whole ? feed.state_total : null, regions
|
|
190
|
-
|
|
237
|
+
state_total: whole ? marked(feed.state_total) : null, regions: regions.map(marked),
|
|
238
|
+
councils: councils.map(marked), areas: areas.map(marked),
|
|
239
|
+
truncated: dropped.length > 0, limits: feed.limits, changes_made: feed.changes_made,
|
|
240
|
+
...figureFields(figures), sample_rule: rule } };
|
|
191
241
|
}
|
|
192
242
|
|
|
193
243
|
// --- by dwelling type and bedrooms --------------------------------------------------------------------------------
|
|
194
|
-
//
|
|
244
|
+
// From 0.8.0 (prepared 2026-10-10; not in 0.7.0). "What does a two-bedroom unit rent for there?" is the
|
|
195
245
|
// question people ask, and the feeds above answer only for all dwellings together. NSW and Queensland publish a
|
|
196
246
|
// companion file each (market/{nsw,qld}-rents-by-type.json); WA's bond records carry neither dwelling type nor
|
|
197
247
|
// bedrooms, so WA has none.
|
|
@@ -214,34 +264,52 @@ export const MAX_TYPE_PLACES = 5;
|
|
|
214
264
|
export const wantsByType = ({ dwelling_type, bedrooms } = {}) =>
|
|
215
265
|
[dwelling_type, bedrooms].some((v) => v != null && String(v).trim() !== "");
|
|
216
266
|
|
|
267
|
+
// The labels a question can name are read from the state's breakdown: the publisher's labels, each to a cell
|
|
268
|
+
// (Queensland) or to a row of sizes, each to a cell (NSW). So the breakdown is an object, and no NSW type's sizes are
|
|
269
|
+
// null (the sizes of each are listed); a place row that is not a row is skipped (tools.mjs).
|
|
217
270
|
const wellFormedByType = (f, state) => f && f.state === state && f.detail === "dwelling_type_and_bedrooms"
|
|
218
271
|
&& quarterKey(f.quarter) > 0 && Array.isArray(f.areas) && f.areas.length > 0 && Array.isArray(f.councils)
|
|
219
|
-
&& f.state_total && f.state_total.breakdown
|
|
220
|
-
&&
|
|
272
|
+
&& f.state_total && isRecord(f.state_total.breakdown)
|
|
273
|
+
&& (state !== "NSW" || Object.values(f.state_total.breakdown).every((sizes) => sizes !== null))
|
|
274
|
+
&& Array.isArray(f.limits) && f.licence && f.attribution && f.changes_made && f.absent_means && f.labels;
|
|
221
275
|
|
|
222
|
-
/**
|
|
223
|
-
|
|
276
|
+
/**
|
|
277
|
+
* One state's by-type file and where it came from ("env", "live", "published" or "bundled"); { feed: null } if none.
|
|
278
|
+
* byTypeDir: a folder holding bundled copies. The npm package has none (the files are large), so the stdio server
|
|
279
|
+
* passes none; the hosted server's deploy package carries them (infra/mcp-remote/build.py, remote/data.mjs), and
|
|
280
|
+
* there, as for every other feed, the published copy answers only when it is well formed and not older.
|
|
281
|
+
*/
|
|
282
|
+
export async function loadRentsByType(state, { env = process.env, fetchImpl = globalThis.fetch, liveDir = LIVE_DIR,
|
|
283
|
+
byTypeDir = null, warn = quiet } = {}) {
|
|
224
284
|
const file = BY_TYPE[state];
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
if (
|
|
285
|
+
const what = `the ${STATES[state].name} rents by dwelling type file`;
|
|
286
|
+
const read = (path, variable) => readChecked(path, (f) => wellFormedByType(f, state), what, variable, warn);
|
|
287
|
+
if (env.DWELLDELTA_STATE_RENTS_DIR) {
|
|
288
|
+
return fromCopy(await read(join(env.DWELLDELTA_STATE_RENTS_DIR, file), "DWELLDELTA_STATE_RENTS_DIR"), "feed", "env");
|
|
289
|
+
}
|
|
290
|
+
if (existsSync(join(liveDir, file))) return fromCopy(await read(join(liveDir, file)), "feed", "live");
|
|
291
|
+
const shipped = byTypeDir ? (await read(join(byTypeDir, file))).copy : null;
|
|
228
292
|
if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
|
|
229
293
|
try {
|
|
230
294
|
const res = await fetchImpl(PUBLISHED_BASE + file, { signal: AbortSignal.timeout(BY_TYPE_TIMEOUT_MS) });
|
|
231
295
|
const got = res.ok ? await res.json() : null;
|
|
232
|
-
if (wellFormedByType
|
|
296
|
+
if (passes(wellFormedByType, got, state) && (!shipped || quarterKey(got.quarter) >= quarterKey(shipped.quarter))) {
|
|
297
|
+
return { feed: got, origin: "published" };
|
|
298
|
+
}
|
|
299
|
+
if (got != null && !passes(wellFormedByType, got, state)) warnPublished(warn, what, PUBLISHED_BASE + file, shipped);
|
|
233
300
|
} catch {
|
|
234
|
-
// Offline, blocked or slow: there is
|
|
301
|
+
// Offline, blocked or slow: the bundled copy answers where there is one; else a by-type question says what to do.
|
|
235
302
|
}
|
|
236
303
|
}
|
|
237
|
-
return { feed:
|
|
304
|
+
return { feed: shipped, origin: shipped ? "bundled" : null };
|
|
238
305
|
}
|
|
239
306
|
|
|
240
307
|
/** Both states' by-type files: { NSW: file-with-origin | null, QLD: ... }. It never rejects. */
|
|
241
308
|
export async function loadAllRentsByType(opts) {
|
|
242
309
|
const states = Object.keys(BY_TYPE);
|
|
243
310
|
const loaded = await Promise.all(states.map((s) => loadRentsByType(s, opts).catch(() => ({ feed: null }))));
|
|
244
|
-
return Object.fromEntries(states.map((s, i) => [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null]))
|
|
311
|
+
return withRefused(Object.fromEntries(states.map((s, i) => [s, loaded[i].feed ? { ...loaded[i].feed, origin: loaded[i].origin } : null])),
|
|
312
|
+
states, loaded);
|
|
245
313
|
}
|
|
246
314
|
|
|
247
315
|
const NSW_TYPES = ["House", "Townhouse", "Flat/Unit", "Other", "Total"];
|
|
@@ -369,12 +437,24 @@ function qldAsked(file, dwelling_type, bedrooms) {
|
|
|
369
437
|
}
|
|
370
438
|
|
|
371
439
|
/** area_rents with dwelling_type or bedrooms: the publisher's own cells for the places matched, and no others. */
|
|
372
|
-
function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file
|
|
440
|
+
function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas, councils, file, refusedFile = null,
|
|
441
|
+
hosted = false }, now) {
|
|
373
442
|
if (!BY_TYPE[state]) {
|
|
374
443
|
throw new ToolError(`${info.name} rents are not published by dwelling type or bedrooms.`,
|
|
375
444
|
"WA's bond records carry neither. Call area_rents for WA without dwelling_type and bedrooms: every WA figure " +
|
|
376
445
|
"is all dwellings together.");
|
|
377
446
|
}
|
|
447
|
+
// On the hosted server (hosted: remote/endpoint.mjs) the user can set no variable on it: the error says the server
|
|
448
|
+
// could not load the file, and what to ask instead.
|
|
449
|
+
if (!file && hosted) {
|
|
450
|
+
throw new ToolError(`This server could not load the ${info.name} rents by dwelling type file just now.`,
|
|
451
|
+
"Try again later. Without dwelling_type and bedrooms, area_rents answers now for all dwellings together.");
|
|
452
|
+
}
|
|
453
|
+
if (!file && refusedFile) {
|
|
454
|
+
throw new ToolError(`The ${info.name} rents by dwelling type file could not be used: ${refusedFile} failed the check of the file.`,
|
|
455
|
+
`Point DWELLDELTA_STATE_RENTS_DIR at a folder holding a good copy of ${PUBLISHED_BASE}${BY_TYPE[state]}. Without ` +
|
|
456
|
+
"dwelling_type and bedrooms, area_rents still answers for all dwellings together.");
|
|
457
|
+
}
|
|
378
458
|
if (!file) {
|
|
379
459
|
throw new ToolError(`The ${info.name} rents by dwelling type file is not on this machine.`,
|
|
380
460
|
`It is read once at start from ${PUBLISHED_BASE}${BY_TYPE[state]}. Offline, point DWELLDELTA_STATE_RENTS_DIR at ` +
|
|
@@ -389,27 +469,35 @@ function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas
|
|
|
389
469
|
const kind = feed.area_kind;
|
|
390
470
|
const places = whole ? [{ name: `${info.name} (whole state)`, place: info.name, place_kind: "state", group: file.state_total }]
|
|
391
471
|
: [...councils.map((r) => ({ name: `${r.council} (council)`, place: r.council, place_kind: "council",
|
|
392
|
-
group: file.councils.find((g) => g.council === r.council) })),
|
|
472
|
+
group: file.councils.find((g) => isRecord(g) && g.council === r.council) })),
|
|
393
473
|
...areas.map((r) => ({ name: `${r.area} (${kind})`, place: r.area, place_kind: kind,
|
|
394
|
-
group: file.areas.find((g) => g.area === r.area) }))];
|
|
474
|
+
group: file.areas.find((g) => isRecord(g) && g.area === r.area) }))];
|
|
395
475
|
const shown = places.slice(0, MAX_TYPE_PLACES);
|
|
396
|
-
const
|
|
476
|
+
const rule = RULES[state];
|
|
477
|
+
const lines = [], rows = [], figures = [];
|
|
397
478
|
for (const p of shown) {
|
|
398
479
|
const absent = [];
|
|
399
480
|
for (const w of wanted) {
|
|
400
481
|
const cell = w.cell(p.group);
|
|
482
|
+
const name = `${p.name}, ${w.words}`;
|
|
483
|
+
const fig = cell ? rentFigure(cell, name, rule)
|
|
484
|
+
: judgeFigure(null, { name, median: "median_weekly_rent_aud", count: "new_bonds", rule, why: file.absent_means });
|
|
485
|
+
figures.push(fig);
|
|
401
486
|
rows.push({ place: p.place, place_kind: p.place_kind,
|
|
402
|
-
...(state === "NSW" ? { dwelling_type: w.dwelling_type, bedrooms: w.bedrooms } : { label: w.label }), figure: cell
|
|
403
|
-
|
|
487
|
+
...(state === "NSW" ? { dwelling_type: w.dwelling_type, bedrooms: w.bedrooms } : { label: w.label }), figure: cell,
|
|
488
|
+
...refusalMark(fig) });
|
|
489
|
+
if (cell) lines.push(line(cell, name, rule));
|
|
404
490
|
else absent.push(w.words);
|
|
405
491
|
}
|
|
406
492
|
if (absent.length) lines.push(`${p.name}: no published median for ${absent.join("; ")}.`);
|
|
407
493
|
}
|
|
408
494
|
const truncated = places.length > shown.length;
|
|
409
495
|
if (truncated) lines.push(`${places.length - shown.length} more places match: narrow the name.`);
|
|
410
|
-
const
|
|
411
|
-
|
|
496
|
+
const feedUrl = PUBLISHED_BASE + BY_TYPE[state];
|
|
497
|
+
const env = envelope({ sources: [feedSource(file, feedUrl, file.quarter)], dataAsOf: file.quarter,
|
|
498
|
+
origin: file.origin ?? null, cadence: CADENCE.rents_quarterly }, now);
|
|
412
499
|
const text = [
|
|
500
|
+
...staleNote(env),
|
|
413
501
|
`${file.what}. Quarter: ${file.quarter}, against ${file.compared_with}.`,
|
|
414
502
|
"",
|
|
415
503
|
...notes.flatMap((n) => [n, ""]),
|
|
@@ -425,10 +513,13 @@ function byTypeResult({ state, info, feed, dwelling_type, bedrooms, whole, areas
|
|
|
425
513
|
"",
|
|
426
514
|
`Source: ${file.attribution}`,
|
|
427
515
|
`What DwellDelta changed: ${file.changes_made}`,
|
|
516
|
+
citeLine({ source: file.source, period: `${file.quarter} (against ${file.compared_with})`, licence: file.licence,
|
|
517
|
+
n: nWords(figures, rule.unit), url: env.sources[0].source_url, notice: env.sources[0].source_notice_url,
|
|
518
|
+
feedUrl, stale: flagged(env) }),
|
|
428
519
|
FOOTER,
|
|
429
520
|
].join("\n");
|
|
430
521
|
return { text, structured: { ...env, state, state_name: info.name, area_kind: kind, quarter: file.quarter,
|
|
431
522
|
compared_with: file.compared_with, detail: file.detail, asked, notes, rows, truncated,
|
|
432
523
|
absent_means: file.absent_means, labels: file.labels, limits: file.limits,
|
|
433
|
-
changes_made: file.changes_made } };
|
|
524
|
+
changes_made: file.changes_made, ...figureFields(figures), sample_rule: rule } };
|
|
434
525
|
}
|
package/contribute-tool.mjs
CHANGED
|
@@ -34,9 +34,15 @@ export const NOT_COLLECTING = "Contributions are not being collected yet, so not
|
|
|
34
34
|
export const WHOSE_REFUSAL = "Only the user's own rent can be added: their own tenancy, or a property they own. " +
|
|
35
35
|
"A figure read on a website, in a listing or from anyone else cannot be added.";
|
|
36
36
|
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// What the tool is for, closing its description (server.mjs). Until 2026-10-20 this was INSTRUCTION, worded as an
|
|
38
|
+
// instruction to the assistant ("Call only when...", "Never add..."); the directories' reviews read tool
|
|
39
|
+
// descriptions that instruct the model as a risk, so it now states the same limits as facts, every one kept: the
|
|
40
|
+
// user asks or agrees first; never on the user's behalf by default; one rent, for one consent, never a batch of rents
|
|
41
|
+
// ("never batch" - not merely one rent per call, which a loop of calls would meet); never a figure found online.
|
|
42
|
+
// mcp/test/output-schema.test.mjs holds the registered description to all four.
|
|
43
|
+
export const INTENDED_USE = "The tool is for a rent the user has asked to add, or has agreed to add on seeing the " +
|
|
44
|
+
"consent text - one rent, for one consent, never a batch of rents; never added on the user's behalf by default; " +
|
|
45
|
+
"and never a figure found online.";
|
|
40
46
|
|
|
41
47
|
/** The details as the page would record them, from the tool's argument names. */
|
|
42
48
|
function toRecordInput(a) {
|