dwelldelta-mcp 0.8.0 → 0.9.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 +62 -4
- package/area-rents-tool.mjs +60 -23
- package/package.json +1 -1
- package/sale-prices-tool.mjs +32 -5
- package/server.mjs +6 -3
- package/tools.mjs +280 -11
- package/vendor/indicators.json +7 -7
- package/vendor/qld-rents.json +2689 -2689
- package/vic-rents-tool.mjs +22 -5
package/tools.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { fileURLToPath } from "node:url";
|
|
|
17
17
|
import { dirname, join } from "node:path";
|
|
18
18
|
// 0.3.0: the package is self-contained. vendor/ holds copies of the rent check's arithmetic and ABS data, and the
|
|
19
19
|
// latest indicators snapshot, made by scripts/vendor.mjs before every pack; a repo test fails if a copy drifts.
|
|
20
|
-
import { assess, sentences, LIMITS } from "./vendor/rent-check.mjs";
|
|
20
|
+
import { assess, sentences, LIMITS, isMonth } from "./vendor/rent-check.mjs";
|
|
21
21
|
|
|
22
22
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
23
23
|
export const RENTS_PATH = join(HERE, "vendor", "rents-index.json");
|
|
@@ -62,7 +62,7 @@ export async function loadSnapshot({ env = process.env, fetchImpl = globalThis.f
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export const FOOTER = "Information, not advice. From DwellDelta (dwelldelta.com.au), built on public data.";
|
|
65
|
-
export const SERVER_VERSION = "0.
|
|
65
|
+
export const SERVER_VERSION = "0.9.0";
|
|
66
66
|
// The indicators snapshot is rebuilt every Monday. Older than this and the answer says so, in words and in the
|
|
67
67
|
// structured result, rather than serving a stale figure as current.
|
|
68
68
|
export const STALE_DAYS = 10;
|
|
@@ -71,6 +71,227 @@ export async function loadJson(path) {
|
|
|
71
71
|
return JSON.parse(await readFile(path, "utf8"));
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
// --- provenance an agent can check (from 0.9.0; prepared 2026-10-20) ---------------------------------------------
|
|
75
|
+
// Control advisory 2026-10-20 (competitor research), recommendation 2, "make the edge checkable": every figure carries
|
|
76
|
+
// its source with a URL (or, where the file names only a copyright notice, that notice, called so), its period, a
|
|
77
|
+
// licence id, its as-at date, its sample size where the data has one, and an overdue flag from the data's own release
|
|
78
|
+
// cadence (period_overdue); a figure that rests on too few records is a typed refusal, never a weak number. Every
|
|
79
|
+
// field below is NEW: the fields answers carried before keep their meaning - stale is still only the weekly snapshot.
|
|
80
|
+
|
|
81
|
+
/** DwellDelta's published copy of the rents index - the file an agent can fetch to check a rent check. */
|
|
82
|
+
export const RENTS_FEED_URL = "https://tools.dwelldelta.com.au/rent/data/rents-index.json";
|
|
83
|
+
|
|
84
|
+
// From 0.9.0 rent_check reads that published copy like every other feed. Up to 0.8.0 it read
|
|
85
|
+
// only the copy bundled at pack time and answered to that copy's latest month, never saying the index had moved on. The
|
|
86
|
+
// ABS releases a month at a time; the site's copy (rent/data/rents-index.json) is updated with each release.
|
|
87
|
+
/** The month after a YYYY-MM month. */
|
|
88
|
+
const nextMonth = (ym) => {
|
|
89
|
+
const [y, m] = ym.split("-").map(Number);
|
|
90
|
+
return m === 12 ? `${y + 1}-01` : `${y}-${String(m + 1).padStart(2, "0")}`;
|
|
91
|
+
};
|
|
92
|
+
/** The latest month of a rents index: the last month any city's series reaches ("" if none). */
|
|
93
|
+
export const rentsLatest = (r) => Object.values(r?.cities ?? {})
|
|
94
|
+
.map((c) => Object.keys(c?.points ?? {}).sort().at(-1) ?? "").sort().at(-1) ?? "";
|
|
95
|
+
/**
|
|
96
|
+
* Well formed, as the shipped file is held to (tests/rent-check.test.mjs): its source, attribution, licence and
|
|
97
|
+
* release named; every city a run of contiguous months, each with a positive index value; and, beside a bundled copy,
|
|
98
|
+
* every city that copy has - rent_check's list of cities is built from this file, and a copy that dropped one would
|
|
99
|
+
* take it away.
|
|
100
|
+
*/
|
|
101
|
+
const rentsWellFormed = (r, shipped = null) => r && typeof r === "object"
|
|
102
|
+
&& ["source", "attribution", "licence", "release"].every((k) => typeof r[k] === "string" && r[k].trim() !== "")
|
|
103
|
+
&& r.cities && typeof r.cities === "object" && Object.keys(r.cities).length > 0
|
|
104
|
+
&& Object.values(r.cities).every((c) => {
|
|
105
|
+
const months = c && c.points && typeof c.points === "object" ? Object.keys(c.points).sort() : [];
|
|
106
|
+
return months.length > 0 && months.every((m, i) => isMonth(m) && (i === 0 || nextMonth(months[i - 1]) === m))
|
|
107
|
+
&& Object.values(c.points).every((v) => Number.isFinite(v) && v > 0);
|
|
108
|
+
})
|
|
109
|
+
&& (!shipped || Object.keys(shipped.cities).every((city) => city in r.cities));
|
|
110
|
+
/** A city's months, in order. */
|
|
111
|
+
const monthsOf = (c) => Object.keys(c?.points ?? {}).sort();
|
|
112
|
+
/**
|
|
113
|
+
* Covers the bundled copy city by city: for every city the bundled copy has, the published series starts no later
|
|
114
|
+
* and ends no earlier. A copy that is newer overall can still end one city early, or start later and drop the older
|
|
115
|
+
* months a lease start needs; either answers worse than the bundle, so the bundle answers instead.
|
|
116
|
+
*/
|
|
117
|
+
const rentsCover = (r, shipped) => Object.entries(shipped.cities).every(([city, c]) => {
|
|
118
|
+
const have = monthsOf(r.cities[city]), want = monthsOf(c);
|
|
119
|
+
return have.length > 0 && want.length > 0 && have[0] <= want[0] && have.at(-1) >= want.at(-1);
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* No month later than the current one (UTC), read from the clock every answer's staleness is read from: a copy
|
|
123
|
+
* that runs into the future is not an ABS release, whatever else is right with it.
|
|
124
|
+
*/
|
|
125
|
+
const rentsNotAhead = (r, now) => {
|
|
126
|
+
const month = now.toISOString().slice(0, 7);
|
|
127
|
+
return Object.values(r.cities).every((c) => (monthsOf(c).at(-1) ?? "") <= month);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The rents index and where it came from: "published" (DwellDelta's copy at RENTS_FEED_URL, fetched once at start -
|
|
132
|
+
* a plain request for one public file; nothing about the user or their questions is sent - and used only if it is
|
|
133
|
+
* well formed, covers every city of the bundled copy from that city's first month to its last, and has no month
|
|
134
|
+
* later than the current one) or "bundled" (the copy shipped in the package). DWELLDELTA_OFFLINE=1 never fetches.
|
|
135
|
+
* Never throws for a failed fetch; { rents: null } only when no copy can be read at all.
|
|
136
|
+
*/
|
|
137
|
+
export async function loadRentsIndex({ env = process.env, fetchImpl = globalThis.fetch, bundled = RENTS_PATH,
|
|
138
|
+
now = new Date() } = {}) {
|
|
139
|
+
const shipped = await loadJson(bundled).then((r) => (rentsWellFormed(r) ? r : null)).catch(() => null);
|
|
140
|
+
if (env.DWELLDELTA_OFFLINE !== "1" && typeof fetchImpl === "function") {
|
|
141
|
+
try {
|
|
142
|
+
const res = await fetchImpl(RENTS_FEED_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
143
|
+
const got = res.ok ? await res.json() : null;
|
|
144
|
+
if (rentsWellFormed(got, shipped) && rentsNotAhead(got, now) && (!shipped || rentsCover(got, shipped))) {
|
|
145
|
+
return { rents: got, origin: "published" };
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
// Offline, blocked or slow: the bundled copy answers, and the overdue flag says how old it is.
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { rents: shipped, origin: shipped ? "bundled" : null };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** SPDX ids for the licences the data files name. Any other licence (the RBA's permission) has no id: null. */
|
|
155
|
+
const SPDX = { "CC BY 4.0": "CC-BY-4.0", "CC BY 3.0 AU": "CC-BY-3.0-AU" };
|
|
156
|
+
export const licenceId = (licence) => SPDX[String(licence ?? "").trim()] ?? null;
|
|
157
|
+
|
|
158
|
+
const httpUrl = (v) => (typeof v === "string" && /^https?:\/\/\S+$/.test(v) ? v : null);
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The address of the data's own page, as the data file gives it, and never made up: its source_url or url field,
|
|
162
|
+
* else an address written in its source line (Homes Victoria's "via DataVic (discover.data.vic.gov.au/dataset/...)",
|
|
163
|
+
* given https://). Null when the file has none. A file's source_notice is NOT read here: for DCJ and the RTA it is
|
|
164
|
+
* the publisher's copyright notice, which is not where the data is (see feedSource).
|
|
165
|
+
*/
|
|
166
|
+
export function sourceUrl(s) {
|
|
167
|
+
for (const key of ["source_url", "url"]) {
|
|
168
|
+
if (httpUrl(s?.[key])) return s[key];
|
|
169
|
+
}
|
|
170
|
+
const m = /\b((?:https?:\/\/)?(?:[a-z0-9-]+\.)+(?:au|org|com|net)\/[^\s)]+)/i.exec(String(s?.source ?? ""));
|
|
171
|
+
if (!m) return null;
|
|
172
|
+
const found = m[1].replace(/[.,;]+$/, "");
|
|
173
|
+
return /^https?:\/\//.test(found) ? found : `https://${found}`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A data file as the one source of an answer: what envelope() needs to say where its figures come from.
|
|
178
|
+
* The files' source_notice is the page their attribution rests on. For DCJ (NSW rents, rents by type, sale prices)
|
|
179
|
+
* and the RTA (Queensland) that is a copyright notice, not a page of the data: it is source_notice_url, labelled
|
|
180
|
+
* "copyright notice" in the Cite line, and source_url stays null. Only a tool that knows its file's notice IS the
|
|
181
|
+
* data's page (WA: the Housing Data Exchange dataset page) passes noticeIsData, and then it is the source_url.
|
|
182
|
+
*/
|
|
183
|
+
export const feedSource = (f, feedUrl, period, { noticeIsData = false } = {}) => ({
|
|
184
|
+
source: f.source, licence: f.licence, attribution: f.attribution, licence_url: f.licence_url,
|
|
185
|
+
source_url: f.source_url ?? (noticeIsData ? f.source_notice : null), url: f.url,
|
|
186
|
+
source_notice_url: noticeIsData ? null : f.source_notice ?? null, feed_url: feedUrl, period,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Release cadence, and when a figure is overdue for replacing. months: from the end of the data's latest period
|
|
191
|
+
* to the end of the month by which the next release was due.
|
|
192
|
+
* - The ABS monthly CPI comes out about four weeks after each month, so the month after the latest is due within
|
|
193
|
+
* two months of the latest month's end.
|
|
194
|
+
* - A quarterly rents feed: one quarter for the next quarter, then up to four months for the publisher to release
|
|
195
|
+
* it (DCJ's June 2026 rents reached the feed on 2026-10-10).
|
|
196
|
+
* - NSW sale prices: three months more, because DCJ's sales quarter runs one quarter behind its rents quarter in
|
|
197
|
+
* the same report (March 2026 sales came with June 2026 rents).
|
|
198
|
+
*/
|
|
199
|
+
export const CADENCE = {
|
|
200
|
+
abs_monthly: { cadence: "monthly", months: 2 },
|
|
201
|
+
rents_quarterly: { cadence: "quarterly", months: 7 },
|
|
202
|
+
sales_quarterly: { cadence: "quarterly", months: 10 },
|
|
203
|
+
};
|
|
204
|
+
const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The last day of the month `months` after a period - "Jun 2026" or "2026-08" - as YYYY-MM-DD; null if unreadable.
|
|
208
|
+
* That is the day by which the release after the period was due: past it, the period is overdue (period_overdue).
|
|
209
|
+
*/
|
|
210
|
+
export function periodDueBy(period, months) {
|
|
211
|
+
const p = String(period ?? "");
|
|
212
|
+
let y, m;
|
|
213
|
+
const iso = /^(\d{4})-(\d{2})$/.exec(p);
|
|
214
|
+
if (iso) { y = Number(iso[1]); m = Number(iso[2]); }
|
|
215
|
+
else {
|
|
216
|
+
const [mon, yr] = p.split(" ");
|
|
217
|
+
m = MON.indexOf(String(mon ?? "").slice(0, 3)) + 1;
|
|
218
|
+
y = Number(yr);
|
|
219
|
+
if (!m || !/^\d{4}$/.test(yr ?? "")) return null;
|
|
220
|
+
}
|
|
221
|
+
return new Date(Date.UTC(y, m + months, 0)).toISOString().slice(0, 10);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The publishers' own small-sample rules: below them there is no median, and the answer is a refusal. Each is the
|
|
226
|
+
* rule its data file states in its limits, and a test holds the vendored files to them. min_n is the fewest records
|
|
227
|
+
* a median may rest on; null where the publisher withholds medians but states no number.
|
|
228
|
+
*/
|
|
229
|
+
export const SAMPLE_RULES = {
|
|
230
|
+
NSW_RENTS: { unit: "new bonds", min_n: 11, rule: "DCJ reports nothing where 10 or fewer new bonds were lodged" },
|
|
231
|
+
QLD_RENTS: { unit: "new bonds", min_n: null, rule: "the RTA publishes no median where too few bonds were lodged, and states no number" },
|
|
232
|
+
WA_RENTS: { unit: "new bonds", min_n: 10, rule: "a locality needs 10 bonds in the quarter for a median (DwellDelta's rule for its own calculation)" },
|
|
233
|
+
VIC_RENTS: { unit: "new leases", min_n: null, rule: "Homes Victoria publishes no median where too few leases began, and states no number" },
|
|
234
|
+
NSW_SALES: { unit: "sales", min_n: 11, rule: "DCJ reports nothing where 10 or fewer dwellings sold" },
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* One figure's sample and, if it rests on too few records, its refusal. median and count name the row's fields;
|
|
239
|
+
* why is the reason the answer already gives for a missing median, and missing its type. A median below the rule's
|
|
240
|
+
* min_n is refused too: the published files have none, so this guards against a builder that ever lets one
|
|
241
|
+
* through. No figure is changed here.
|
|
242
|
+
*/
|
|
243
|
+
export function judgeFigure(r, { name, median, count, band = null, rule, why = null, missing = "too_few_records" }) {
|
|
244
|
+
const n = Number.isFinite(r?.[count]) ? r[count] : null;
|
|
245
|
+
const nBand = band && r?.[band] ? r[band] : null;
|
|
246
|
+
const base = { n, n_band: nBand, unit: rule.unit, min_n: rule.min_n, rule: rule.rule };
|
|
247
|
+
let refusal = null;
|
|
248
|
+
if (r == null) refusal = { refused: true, type: "not_published", reason: why ?? "no row in the publisher's table", ...base };
|
|
249
|
+
else if (r[median] == null) refusal = { refused: true, type: missing, reason: why ?? `too few ${rule.unit}`, ...base };
|
|
250
|
+
else if (rule.min_n != null && n != null && n < rule.min_n) {
|
|
251
|
+
refusal = { refused: true, type: "too_few_records",
|
|
252
|
+
reason: `${n} ${rule.unit}, fewer than the ${rule.min_n} a published median needs (${rule.rule})`, ...base };
|
|
253
|
+
}
|
|
254
|
+
return { name, n, n_band: nBand, unit: rule.unit, small_sample: r?.small_sample === true, refusal };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* The marker each structured row carries for its own figure (from 0.9.0; additions only): refused, and the
|
|
259
|
+
* refusal's type (too_few_records or not_published, as in refusals[]) - false and null for a figure that is given.
|
|
260
|
+
* A refused row keeps every field the file gives it, the weak median included; this says the text refused it, on
|
|
261
|
+
* the row itself, so an agent reading the rows need not match them to figures[] by name.
|
|
262
|
+
*/
|
|
263
|
+
export const refusalMark = (figure) => ({ refused: Boolean(figure?.refusal), refusal_type: figure?.refusal?.type ?? null });
|
|
264
|
+
|
|
265
|
+
/** The structured fields every figure-giving answer adds: each figure's sample, and the refusals among them. */
|
|
266
|
+
export function figureFields(figures) {
|
|
267
|
+
const refusals = figures.filter((f) => f.refusal).map((f) => ({ name: f.name, ...f.refusal }));
|
|
268
|
+
return { figures, refusals, all_refused: figures.length > 0 && refusals.length === figures.length };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const sampleWords = (f) => (f.refusal
|
|
272
|
+
? `none: ${f.refusal.type === "too_few_records" ? "too few records" : "not published"} (${f.refusal.reason})`
|
|
273
|
+
: f.n != null ? `${f.n.toLocaleString("en-AU")} ${f.unit}`
|
|
274
|
+
: f.n_band ? `${f.n_band} ${f.unit} (the publisher withholds the exact count)` : `not published (${f.unit})`);
|
|
275
|
+
|
|
276
|
+
/** What n is, in words, for the Cite line: one figure's own count, or how the lines above give it. */
|
|
277
|
+
export function nWords(figures, unit) {
|
|
278
|
+
if (figures.length === 1) return sampleWords(figures[0]);
|
|
279
|
+
const refused = figures.filter((f) => f.refusal).length;
|
|
280
|
+
return `on each line above, in ${unit}` +
|
|
281
|
+
(refused ? `; ${refused} of ${figures.length} refused (too few records, or not published)` : "");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The quotable provenance line: source, period, licence, n, the source's URL (or the copyright notice the
|
|
286
|
+
* publisher's attribution rests on, called that and nothing else) and DwellDelta's data file. stale: the answer
|
|
287
|
+
* opens with a STALE line (staleNote) - the weekly snapshot is old, or the period is overdue.
|
|
288
|
+
*/
|
|
289
|
+
export function citeLine({ source, period, licence, n, url, notice = null, feedUrl, stale }) {
|
|
290
|
+
return `Cite: ${String(source ?? "").replace(/[.\s]+$/, "")}; period ${period}; licence ${licenceId(licence) ?? licence}; ` +
|
|
291
|
+
`n ${n}; source URL ${url ?? "none in the data file"}${notice ? `; copyright notice ${notice}` : ""}; ` +
|
|
292
|
+
`data file ${feedUrl}${stale ? "; STALE" : ""}.`;
|
|
293
|
+
}
|
|
294
|
+
|
|
74
295
|
/** A failed call: marked as an error so an agent cannot mistake it for data, with the next step to take. */
|
|
75
296
|
export class ToolError extends Error {
|
|
76
297
|
constructor(message, recovery) {
|
|
@@ -83,9 +304,15 @@ export class ToolError extends Error {
|
|
|
83
304
|
* The provenance that travels WITH every answer, as structured data an agent can carry into its own output.
|
|
84
305
|
* "The attribution must travel with the data" - the principle, from abs-mcp's DataResponse.
|
|
85
306
|
*/
|
|
86
|
-
export function envelope({ sources, dataAsOf, built = null, origin = null }, now = new Date()) {
|
|
307
|
+
export function envelope({ sources, dataAsOf, built = null, origin = null, cadence = null }, now = new Date()) {
|
|
308
|
+
// stale and stale_reason mean what they have meant since 0.2.0: the weekly indicators snapshot is more than
|
|
309
|
+
// STALE_DAYS old. They are false and null for every answer without a snapshot (rents, sale prices, rent_check).
|
|
87
310
|
const age = built ? Math.floor((now - new Date(built + "T00:00:00Z")) / 86400000) : null;
|
|
88
311
|
const stale = age !== null && age > STALE_DAYS;
|
|
312
|
+
// New in 0.9.0, in fields of their own: from the data's own release cadence, whether the release after this
|
|
313
|
+
// period was due and has not reached the file (period_overdue). A released field keeps its meaning.
|
|
314
|
+
const dueBy = cadence ? periodDueBy(dataAsOf, cadence.months) : null;
|
|
315
|
+
const overdue = dueBy !== null && now.toISOString().slice(0, 10) > dueBy;
|
|
89
316
|
return {
|
|
90
317
|
publisher: "DwellDelta, a service of Xcelerent Pty Ltd",
|
|
91
318
|
server_version: SERVER_VERSION,
|
|
@@ -95,12 +322,34 @@ export function envelope({ sources, dataAsOf, built = null, origin = null }, now
|
|
|
95
322
|
snapshot_origin: origin,
|
|
96
323
|
stale,
|
|
97
324
|
stale_reason: stale ? `the indicators snapshot was built ${built}, ${age} days ago; it is rebuilt weekly` : null,
|
|
98
|
-
|
|
325
|
+
stale_after: built ? isoDay(new Date(built + "T00:00:00Z"), STALE_DAYS) : null,
|
|
326
|
+
cadence: cadence ? cadence.cadence : built ? "weekly" : null,
|
|
327
|
+
period_due_by: dueBy,
|
|
328
|
+
period_overdue: overdue,
|
|
329
|
+
period_overdue_reason: overdue ? `these figures are for ${dataAsOf}; they are published ${cadence.cadence}, and ` +
|
|
330
|
+
`the release after them was due by ${dueBy}` : null,
|
|
331
|
+
sources: sources.map((s) => ({ source: s.source, licence: s.licence, attribution: s.attribution ?? null,
|
|
332
|
+
...pickProvenance(s) })),
|
|
99
333
|
advice: false,
|
|
100
334
|
};
|
|
101
335
|
}
|
|
102
336
|
|
|
103
|
-
const
|
|
337
|
+
const isoDay = (d, plusDays) => new Date(d.getTime() + plusDays * 86400000).toISOString().slice(0, 10);
|
|
338
|
+
/** The new provenance fields of a source, filled from the source itself where the caller did not. */
|
|
339
|
+
function pickProvenance(s) {
|
|
340
|
+
return { licence_id: s.licence_id ?? licenceId(s.licence), licence_url: s.licence_url ?? null,
|
|
341
|
+
source_url: sourceUrl(s), source_notice_url: httpUrl(s.source_notice_url), feed_url: s.feed_url ?? null,
|
|
342
|
+
period: s.period ?? null };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** True when the answer opens with a STALE line: the weekly snapshot is old, or the data's period is overdue. */
|
|
346
|
+
export const flagged = (env) => env.stale || env.period_overdue === true;
|
|
347
|
+
|
|
348
|
+
export const staleNote = (env) => [
|
|
349
|
+
...(env.stale ? [`STALE: ${env.stale_reason}. Say so if you quote these figures.`] : []),
|
|
350
|
+
...(env.period_overdue ? [`STALE: ${env.period_overdue_reason}. Say so if you quote these figures.`] : []),
|
|
351
|
+
...(flagged(env) ? [""] : []),
|
|
352
|
+
];
|
|
104
353
|
|
|
105
354
|
/** rent_check: the public rent check's own arithmetic, unchanged, with its limits every time. */
|
|
106
355
|
export function rentCheck(args, rents) {
|
|
@@ -117,19 +366,27 @@ export function rentCheckResult({ city, lease_start, current_rent, proposed_rent
|
|
|
117
366
|
: "Use a lease start on or before the latest month of the index; call data_sources for coverage.";
|
|
118
367
|
throw new ToolError(err.message, recovery);
|
|
119
368
|
}
|
|
120
|
-
const
|
|
369
|
+
const period = `${r.startUsed} to ${r.latest}`;
|
|
370
|
+
const env = envelope({ sources: [{ ...rents, feed_url: RENTS_FEED_URL, period }], dataAsOf: r.latest,
|
|
371
|
+
cadence: CADENCE.abs_monthly }, now);
|
|
121
372
|
const text = [
|
|
373
|
+
...staleNote(env),
|
|
122
374
|
...sentences(r),
|
|
123
375
|
"",
|
|
124
376
|
"Limits:",
|
|
125
377
|
...LIMITS.map((l) => "- " + l),
|
|
126
378
|
"",
|
|
127
379
|
`Source: ${rents.source} ${rents.attribution}, ${rents.licence}. ABS release ${rents.release}.`,
|
|
380
|
+
citeLine({ source: rents.source.split(". ")[0], period: `${period} (ABS release ${rents.release})`, licence: rents.licence,
|
|
381
|
+
n: `not applicable (${INDEX_N})`, url: env.sources[0].source_url, feedUrl: RENTS_FEED_URL, stale: flagged(env) }),
|
|
128
382
|
FOOTER,
|
|
129
383
|
].join("\n");
|
|
130
|
-
return { text, structured: { ...env, result: r, limits: LIMITS } };
|
|
384
|
+
return { text, structured: { ...env, result: r, limits: LIMITS, sample_size: null, sample_size_note: INDEX_N } };
|
|
131
385
|
}
|
|
132
386
|
|
|
387
|
+
const INDEX_N = "an index of what tenants pay, not a count of leases; the ABS publishes no sample size with it";
|
|
388
|
+
const INDICATOR_N = "these sources publish no sample size with these figures";
|
|
389
|
+
|
|
133
390
|
function describe(i) {
|
|
134
391
|
const change = i.change
|
|
135
392
|
? `, ${i.change.value >= 0 ? "+" : ""}${i.change.value} ${i.change.unit} over the ${i.change.over}`
|
|
@@ -137,7 +394,7 @@ function describe(i) {
|
|
|
137
394
|
return [
|
|
138
395
|
`${i.name} - ${i.geography}, ${i.period}: ${i.value} ${i.unit}${change}.`,
|
|
139
396
|
i.limit ? ` Limit: ${i.limit}` : null,
|
|
140
|
-
` Source: ${i.source}${i.attribution ? " " + i.attribution + "," : ""} ${i.licence}
|
|
397
|
+
` Source: ${i.source}${i.attribution ? " " + i.attribution + "," : ""} ${i.licence}.${sourceUrl(i) ? " " + sourceUrl(i) : ""}`,
|
|
141
398
|
].filter(Boolean).join("\n");
|
|
142
399
|
}
|
|
143
400
|
|
|
@@ -155,7 +412,10 @@ export function marketIndicatorsResult({ geography } = {}, snapshot, now = new D
|
|
|
155
412
|
throw new ToolError(`No indicators for "${geography}".`,
|
|
156
413
|
`Call market_indicators again with one of: ${GEOGRAPHIES(snapshot).join(", ")}; or with no geography for all.`);
|
|
157
414
|
}
|
|
158
|
-
|
|
415
|
+
// Each source's period is the latest period of the figures shown from it (null for a source none of them uses).
|
|
416
|
+
const latestFrom = (s) => items.filter((i) => i.source === s.source).map((i) => i.period).sort().at(-1) ?? null;
|
|
417
|
+
const env = envelope({ sources: snapshot.sources.map((s) => ({ ...s, feed_url: PUBLISHED_URL, period: latestFrom(s) })),
|
|
418
|
+
dataAsOf: items.map((i) => i.period).sort().at(-1),
|
|
159
419
|
built: snapshot.built, origin: snapshot.origin ?? null }, now);
|
|
160
420
|
const text = [
|
|
161
421
|
...staleNote(env),
|
|
@@ -164,9 +424,15 @@ export function marketIndicatorsResult({ geography } = {}, snapshot, now = new D
|
|
|
164
424
|
"",
|
|
165
425
|
...items.map(describe),
|
|
166
426
|
"",
|
|
427
|
+
citeLine({ source: "each figure's source, as on its line", period: "each figure's own, as on its line" +
|
|
428
|
+
` (latest ${env.data_as_of}; snapshot built ${snapshot.built})`,
|
|
429
|
+
licence: "each figure's own, as on its line", n: `not applicable (${INDICATOR_N})`,
|
|
430
|
+
url: items.some((i) => sourceUrl(i)) ? "each figure's own, as on its line" : null, feedUrl: PUBLISHED_URL, stale: flagged(env) }),
|
|
167
431
|
FOOTER,
|
|
168
432
|
].join("\n");
|
|
169
|
-
|
|
433
|
+
// Each indicator as the snapshot gives it, plus its licence id, its source's URL (none in today's snapshot) and n.
|
|
434
|
+
const indicators = items.map((i) => ({ ...i, licence_id: licenceId(i.licence), source_url: sourceUrl(i), sample_size: null }));
|
|
435
|
+
return { text, structured: { ...env, indicators, sample_size: null, sample_size_note: INDICATOR_N } };
|
|
170
436
|
}
|
|
171
437
|
|
|
172
438
|
/** data_sources: what DwellDelta covers, under which licences, and what it cannot answer. */
|
|
@@ -182,12 +448,15 @@ export function dataSourcesResult(snapshot, now = new Date()) {
|
|
|
182
448
|
`Publisher: ${snapshot.publisher}.`,
|
|
183
449
|
"",
|
|
184
450
|
"Sources:",
|
|
185
|
-
...snapshot.sources.map((s) => `- ${s.source} ${s.attribution ? s.attribution + ", " : ""}${s.licence}`
|
|
451
|
+
...snapshot.sources.map((s) => `- ${s.source} ${s.attribution ? s.attribution + ", " : ""}${s.licence}` +
|
|
452
|
+
(sourceUrl(s) ? ` (${sourceUrl(s)})` : "")),
|
|
186
453
|
"",
|
|
187
454
|
"Cannot answer:",
|
|
188
455
|
...snapshot.cannot_answer.map((c) => "- " + c),
|
|
189
456
|
"",
|
|
190
457
|
snapshot.rules,
|
|
458
|
+
"Every answer that gives a figure ends with a Cite line: its source, period, licence, sample size (n), the " +
|
|
459
|
+
"source's URL and DwellDelta's data file. A figure that rests on too few records is refused, never given.",
|
|
191
460
|
FOOTER,
|
|
192
461
|
].join("\n");
|
|
193
462
|
return { text, structured: { ...env, cannot_answer: snapshot.cannot_answer, rules: snapshot.rules } };
|
package/vendor/indicators.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"publisher": "DwellDelta, a service of Xcelerent Pty Ltd",
|
|
3
|
-
"built": "2026-10-
|
|
3
|
+
"built": "2026-10-19",
|
|
4
4
|
"indicators": [
|
|
5
5
|
{
|
|
6
6
|
"id": "cash_rate",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"id": "unemployment_rate_nsw",
|
|
23
23
|
"name": "Unemployment rate, seasonally adjusted",
|
|
24
24
|
"geography": "NSW",
|
|
25
|
-
"value": 4.
|
|
25
|
+
"value": 4.71,
|
|
26
26
|
"unit": "percent",
|
|
27
|
-
"period": "2026-
|
|
27
|
+
"period": "2026-09",
|
|
28
28
|
"source": "ABS Labour Force, Australia (6202.0), Table 10: labour force status by state, monthly, seasonally adjusted.",
|
|
29
29
|
"licence": "CC BY 4.0",
|
|
30
30
|
"attribution": "Based on Australian Bureau of Statistics data",
|
|
31
31
|
"change": {
|
|
32
|
-
"value": 0.
|
|
32
|
+
"value": 0.49,
|
|
33
33
|
"unit": "points",
|
|
34
34
|
"over": "year"
|
|
35
35
|
},
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"id": "unemployment_rate_australia",
|
|
40
40
|
"name": "Unemployment rate, seasonally adjusted",
|
|
41
41
|
"geography": "Australia",
|
|
42
|
-
"value": 4.
|
|
42
|
+
"value": 4.72,
|
|
43
43
|
"unit": "percent",
|
|
44
|
-
"period": "2026-
|
|
44
|
+
"period": "2026-09",
|
|
45
45
|
"source": "ABS Labour Force, Australia (6202.0), Table 10: labour force status by state, monthly, seasonally adjusted.",
|
|
46
46
|
"licence": "CC BY 4.0",
|
|
47
47
|
"attribution": "Based on Australian Bureau of Statistics data",
|
|
48
48
|
"change": {
|
|
49
|
-
"value": 0.
|
|
49
|
+
"value": 0.29,
|
|
50
50
|
"unit": "points",
|
|
51
51
|
"over": "year"
|
|
52
52
|
},
|