@voicethere/agent 0.23.1 → 0.24.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 +2 -0
- package/dist/agent.js +29 -1
- package/dist/llm/agent/create-llm-agent.d.ts.map +1 -1
- package/dist/llm/agent/create-llm-agent.js +2 -1
- package/dist/llm/agent/create-llm-agent.js.map +1 -1
- package/dist/llm/agent/link-extractor.d.ts +21 -3
- package/dist/llm/agent/link-extractor.d.ts.map +1 -1
- package/dist/llm/agent/link-extractor.js +139 -15
- package/dist/llm/agent/link-extractor.js.map +1 -1
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +40 -3
- package/dist/runtime.js.map +1 -1
- package/dist/sandbox/loader-entry.js +21 -1
- package/dist/templates/echo/agent.js +29 -1
- package/dist/templates/echo-dc/agent.js +29 -1
- package/dist/templates/game-sync/agent.js +29 -1
- package/dist/templates/language-switch/agent.js +29 -1
- package/dist/templates/llm-agent/agent.js +151 -15
- package/dist/templates/llm-docs-rag/agent.js +151 -15
- package/dist/templates/llm-mcp-service/agent.js +151 -15
- package/dist/templates/positional-tts/agent.js +29 -1
- package/dist/templates/recording-consent/agent.js +29 -1
- package/dist/templates/spatial-showcase/agent.js +29 -1
- package/dist/templates/voice-showcase/agent.js +29 -1
- package/dist/templates/voice-starter/agent.js +29 -1
- package/dist/templates/webhooks/agent.js +29 -1
- package/dist/templates/webhooks-redis/agent.js +29 -1
- package/dist/templates/world-sync/agent.js +29 -1
- package/dist/templates/world-sync-binary/agent.js +29 -1
- package/eject/llm/loop.ts +6 -2
- package/package.json +1 -1
|
@@ -635,6 +635,34 @@ function isVoicethereAgentChild() {
|
|
|
635
635
|
}
|
|
636
636
|
var sessionExecutionContext = new AsyncLocalStorage();
|
|
637
637
|
var agentLogSessionContext = new AsyncLocalStorage();
|
|
638
|
+
var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
|
|
639
|
+
function currentHandlerSessionId() {
|
|
640
|
+
const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
|
|
641
|
+
return id ? id : void 0;
|
|
642
|
+
}
|
|
643
|
+
var previousSessionIdGetter;
|
|
644
|
+
function stringOrUndefined(value) {
|
|
645
|
+
return typeof value === "string" && value ? value : void 0;
|
|
646
|
+
}
|
|
647
|
+
function currentSessionIdGetter() {
|
|
648
|
+
const own = currentHandlerSessionId();
|
|
649
|
+
if (own)
|
|
650
|
+
return own;
|
|
651
|
+
try {
|
|
652
|
+
return stringOrUndefined(previousSessionIdGetter?.());
|
|
653
|
+
} catch {
|
|
654
|
+
return void 0;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function installCurrentSessionIdGetter() {
|
|
658
|
+
const g = globalThis;
|
|
659
|
+
const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
|
|
660
|
+
if (previous === currentSessionIdGetter)
|
|
661
|
+
return;
|
|
662
|
+
g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
|
|
663
|
+
previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
|
|
664
|
+
}
|
|
665
|
+
installCurrentSessionIdGetter();
|
|
638
666
|
var inboundQueueAuthority = null;
|
|
639
667
|
var childUnhandledRejectionGuardInstalled = false;
|
|
640
668
|
function normalizeRejectionReason(reason) {
|
|
@@ -1367,7 +1395,7 @@ function sanitizeAgentLogFields(fields) {
|
|
|
1367
1395
|
}
|
|
1368
1396
|
}
|
|
1369
1397
|
function buildAgentLogPayload(level, message, fields, sessionId) {
|
|
1370
|
-
const resolvedSessionId = sessionId ??
|
|
1398
|
+
const resolvedSessionId = sessionId ?? currentHandlerSessionId();
|
|
1371
1399
|
const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
|
|
1372
1400
|
return {
|
|
1373
1401
|
type: "log",
|
|
@@ -31205,6 +31205,34 @@ function isVoicethereAgentChild() {
|
|
|
31205
31205
|
}
|
|
31206
31206
|
var sessionExecutionContext = new AsyncLocalStorage();
|
|
31207
31207
|
var agentLogSessionContext = new AsyncLocalStorage();
|
|
31208
|
+
var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
|
|
31209
|
+
function currentHandlerSessionId() {
|
|
31210
|
+
const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
|
|
31211
|
+
return id ? id : void 0;
|
|
31212
|
+
}
|
|
31213
|
+
var previousSessionIdGetter;
|
|
31214
|
+
function stringOrUndefined(value) {
|
|
31215
|
+
return typeof value === "string" && value ? value : void 0;
|
|
31216
|
+
}
|
|
31217
|
+
function currentSessionIdGetter() {
|
|
31218
|
+
const own2 = currentHandlerSessionId();
|
|
31219
|
+
if (own2)
|
|
31220
|
+
return own2;
|
|
31221
|
+
try {
|
|
31222
|
+
return stringOrUndefined(previousSessionIdGetter?.());
|
|
31223
|
+
} catch {
|
|
31224
|
+
return void 0;
|
|
31225
|
+
}
|
|
31226
|
+
}
|
|
31227
|
+
function installCurrentSessionIdGetter() {
|
|
31228
|
+
const g = globalThis;
|
|
31229
|
+
const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
|
|
31230
|
+
if (previous === currentSessionIdGetter)
|
|
31231
|
+
return;
|
|
31232
|
+
g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
|
|
31233
|
+
previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
|
|
31234
|
+
}
|
|
31235
|
+
installCurrentSessionIdGetter();
|
|
31208
31236
|
var inboundQueueAuthority = null;
|
|
31209
31237
|
var childUnhandledRejectionGuardInstalled = false;
|
|
31210
31238
|
function normalizeRejectionReason(reason) {
|
|
@@ -31858,7 +31886,7 @@ function sanitizeAgentLogFields(fields) {
|
|
|
31858
31886
|
}
|
|
31859
31887
|
}
|
|
31860
31888
|
function buildAgentLogPayload(level, message, fields, sessionId) {
|
|
31861
|
-
const resolvedSessionId = sessionId ??
|
|
31889
|
+
const resolvedSessionId = sessionId ?? currentHandlerSessionId();
|
|
31862
31890
|
const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
|
|
31863
31891
|
return {
|
|
31864
31892
|
type: "log",
|
|
@@ -34962,6 +34990,24 @@ var ConversationHistory = class {
|
|
|
34962
34990
|
|
|
34963
34991
|
// dist/llm/agent/link-extractor.js
|
|
34964
34992
|
var LINK_MARK = "\uE000";
|
|
34993
|
+
var BARE_DOMAIN_TLDS = /* @__PURE__ */ new Set([
|
|
34994
|
+
"com",
|
|
34995
|
+
"org",
|
|
34996
|
+
"net",
|
|
34997
|
+
"dev",
|
|
34998
|
+
"io",
|
|
34999
|
+
"ai",
|
|
35000
|
+
"app",
|
|
35001
|
+
"co",
|
|
35002
|
+
"cloud",
|
|
35003
|
+
"eu",
|
|
35004
|
+
"de",
|
|
35005
|
+
"uk",
|
|
35006
|
+
"us"
|
|
35007
|
+
]);
|
|
35008
|
+
var DOMAIN_RE = /^((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+([a-z]{2,63}))(\/[^\s]*)?/i;
|
|
35009
|
+
var DOMAIN_PREFIX_RE = /^[a-z0-9][a-z0-9.-]*$/i;
|
|
35010
|
+
var ALNUM_RE = /[\p{L}\p{N}]/u;
|
|
34965
35011
|
var SCHEMES = ["https://", "http://"];
|
|
34966
35012
|
var START_RE = /\[|https?:\/\//i;
|
|
34967
35013
|
var BARE_RE = /^https?:\/\/\S*/i;
|
|
@@ -35027,6 +35073,85 @@ function hasHost(url2) {
|
|
|
35027
35073
|
var LinkExtractor = class {
|
|
35028
35074
|
buf = "";
|
|
35029
35075
|
links = [];
|
|
35076
|
+
/**
|
|
35077
|
+
* The emitted tail of the current word when it is made only of host
|
|
35078
|
+
* characters (`[a-z0-9.-]`), and the character before that word. A word
|
|
35079
|
+
* such as "voicethere" is spoken before ".dev" arrives; the lead lets the
|
|
35080
|
+
* domain still be recognised, so streaming gives the same result as one push.
|
|
35081
|
+
*/
|
|
35082
|
+
lead = "";
|
|
35083
|
+
leadPrev = "";
|
|
35084
|
+
consume(n) {
|
|
35085
|
+
const taken = this.buf.slice(0, n);
|
|
35086
|
+
this.buf = this.buf.slice(n);
|
|
35087
|
+
const s = this.lead + taken;
|
|
35088
|
+
let k = -1;
|
|
35089
|
+
for (let j = s.length - 1; j >= 0; j -= 1) {
|
|
35090
|
+
if (!/[a-z0-9.-]/i.test(s[j])) {
|
|
35091
|
+
k = j;
|
|
35092
|
+
break;
|
|
35093
|
+
}
|
|
35094
|
+
}
|
|
35095
|
+
if (k >= 0) {
|
|
35096
|
+
this.leadPrev = s[k];
|
|
35097
|
+
this.lead = s.slice(k + 1);
|
|
35098
|
+
} else {
|
|
35099
|
+
this.lead = s;
|
|
35100
|
+
}
|
|
35101
|
+
if (this.lead.length > MAX_HOLD) {
|
|
35102
|
+
this.lead = "";
|
|
35103
|
+
this.leadPrev = "x";
|
|
35104
|
+
}
|
|
35105
|
+
return taken;
|
|
35106
|
+
}
|
|
35107
|
+
/** After a link: the text now ends in a mark, so no word is open. */
|
|
35108
|
+
closeWord() {
|
|
35109
|
+
this.lead = "";
|
|
35110
|
+
this.leadPrev = LINK_MARK;
|
|
35111
|
+
}
|
|
35112
|
+
/** The first bare domain (or possible start of one at the tail) in the buffer. */
|
|
35113
|
+
scanDomain(final) {
|
|
35114
|
+
const off = this.lead.length;
|
|
35115
|
+
const ctx = this.lead + this.buf;
|
|
35116
|
+
for (let i = 0; i < ctx.length; i += 1) {
|
|
35117
|
+
if (!/[a-z0-9]/i.test(ctx[i]))
|
|
35118
|
+
continue;
|
|
35119
|
+
const before = i === 0 ? this.leadPrev : ctx[i - 1];
|
|
35120
|
+
if (!(before === "" || /[\s("']/.test(before)))
|
|
35121
|
+
continue;
|
|
35122
|
+
const rest = ctx.slice(i);
|
|
35123
|
+
const m = DOMAIN_RE.exec(rest);
|
|
35124
|
+
if (!m) {
|
|
35125
|
+
if (!final && rest.length <= MAX_HOLD && rest.includes(".") && DOMAIN_PREFIX_RE.test(rest)) {
|
|
35126
|
+
return { index: i, hold: true, off };
|
|
35127
|
+
}
|
|
35128
|
+
continue;
|
|
35129
|
+
}
|
|
35130
|
+
const host = m[1];
|
|
35131
|
+
const path2 = m[3] ?? "";
|
|
35132
|
+
const end = m[0].length;
|
|
35133
|
+
if (!final && end === rest.length && end <= MAX_HOLD) {
|
|
35134
|
+
return { index: i, hold: true, off };
|
|
35135
|
+
}
|
|
35136
|
+
const next = rest[end] ?? "";
|
|
35137
|
+
if (!final && !path2 && next === "." && end + 1 === rest.length) {
|
|
35138
|
+
return { index: i, hold: true, off };
|
|
35139
|
+
}
|
|
35140
|
+
if (!BARE_DOMAIN_TLDS.has(m[2].toLowerCase()))
|
|
35141
|
+
continue;
|
|
35142
|
+
if (!path2) {
|
|
35143
|
+
if (next && /[\p{L}\p{N}@_-]/u.test(next))
|
|
35144
|
+
continue;
|
|
35145
|
+
if (next === "." && ALNUM_RE.test(rest[end + 1] ?? ""))
|
|
35146
|
+
continue;
|
|
35147
|
+
}
|
|
35148
|
+
const { url: url2 } = trimUrl(host + path2);
|
|
35149
|
+
if (i < off && host.length < off - i)
|
|
35150
|
+
continue;
|
|
35151
|
+
return { index: i, hold: false, off, host, url: url2 };
|
|
35152
|
+
}
|
|
35153
|
+
return void 0;
|
|
35154
|
+
}
|
|
35030
35155
|
push(delta) {
|
|
35031
35156
|
this.buf += delta;
|
|
35032
35157
|
return this.drain(false);
|
|
@@ -35044,54 +35169,65 @@ var LinkExtractor = class {
|
|
|
35044
35169
|
this.links = [];
|
|
35045
35170
|
return all;
|
|
35046
35171
|
}
|
|
35047
|
-
add(url2, label) {
|
|
35172
|
+
add(url2, label, sourceText) {
|
|
35048
35173
|
const trimmed = label?.trim();
|
|
35049
35174
|
this.links.push({
|
|
35050
35175
|
url: url2,
|
|
35051
35176
|
...trimmed ? { label: trimmed } : {},
|
|
35052
|
-
secure: /^https:\/\//i.test(url2)
|
|
35177
|
+
secure: /^https:\/\//i.test(url2),
|
|
35178
|
+
...sourceText ? { sourceText } : {}
|
|
35053
35179
|
});
|
|
35054
35180
|
}
|
|
35055
35181
|
drain(final) {
|
|
35056
35182
|
let out = "";
|
|
35057
35183
|
for (; ; ) {
|
|
35058
35184
|
const m = START_RE.exec(this.buf);
|
|
35185
|
+
const d = this.scanDomain(final);
|
|
35186
|
+
if (d && (!m || Math.max(0, d.index - d.off) < m.index)) {
|
|
35187
|
+
const spoken = Math.max(0, d.off - d.index);
|
|
35188
|
+
out += this.consume(Math.max(0, d.index - d.off));
|
|
35189
|
+
if (d.hold)
|
|
35190
|
+
return out;
|
|
35191
|
+
this.add("https://" + d.url, d.host, d.url);
|
|
35192
|
+
this.consume(d.url.length - spoken);
|
|
35193
|
+
out += d.host.slice(spoken) + LINK_MARK;
|
|
35194
|
+
this.closeWord();
|
|
35195
|
+
continue;
|
|
35196
|
+
}
|
|
35059
35197
|
if (!m) {
|
|
35060
35198
|
const hold = final ? 0 : partialSchemeSuffix(this.buf);
|
|
35061
|
-
out += this.
|
|
35062
|
-
this.buf = this.buf.slice(this.buf.length - hold);
|
|
35199
|
+
out += this.consume(this.buf.length - hold);
|
|
35063
35200
|
return out;
|
|
35064
35201
|
}
|
|
35065
|
-
out += this.
|
|
35066
|
-
this.buf = this.buf.slice(m.index);
|
|
35202
|
+
out += this.consume(m.index);
|
|
35067
35203
|
if (this.buf[0] === "[") {
|
|
35068
35204
|
const md = MARKDOWN_RE.exec(this.buf);
|
|
35069
35205
|
if (md && hasHost(md[2])) {
|
|
35070
35206
|
this.add(md[2], md[1]);
|
|
35071
35207
|
out += `${md[1]}${LINK_MARK}`;
|
|
35072
|
-
this.
|
|
35208
|
+
this.consume(md[0].length);
|
|
35209
|
+
this.closeWord();
|
|
35073
35210
|
continue;
|
|
35074
35211
|
}
|
|
35075
35212
|
if (!final && this.buf.length <= MAX_HOLD && MARKDOWN_PREFIX_RE.test(this.buf)) {
|
|
35076
35213
|
return out;
|
|
35077
35214
|
}
|
|
35078
|
-
out +=
|
|
35079
|
-
this.buf = this.buf.slice(1);
|
|
35215
|
+
out += this.consume(1);
|
|
35080
35216
|
continue;
|
|
35081
35217
|
}
|
|
35082
35218
|
const bare = BARE_RE.exec(this.buf);
|
|
35083
35219
|
if (!final && bare[0].length === this.buf.length && this.buf.length <= MAX_HOLD) {
|
|
35084
35220
|
return out;
|
|
35085
35221
|
}
|
|
35086
|
-
const { url: url2
|
|
35222
|
+
const { url: url2 } = trimUrl(bare[0]);
|
|
35087
35223
|
if (!hasHost(url2)) {
|
|
35088
|
-
out += bare[0];
|
|
35089
|
-
this.buf = this.buf.slice(bare[0].length);
|
|
35224
|
+
out += this.consume(bare[0].length);
|
|
35090
35225
|
continue;
|
|
35091
35226
|
}
|
|
35092
35227
|
this.add(url2);
|
|
35093
35228
|
out += LINK_MARK;
|
|
35094
|
-
this.
|
|
35229
|
+
this.consume(url2.length);
|
|
35230
|
+
this.closeWord();
|
|
35095
35231
|
}
|
|
35096
35232
|
}
|
|
35097
35233
|
};
|
|
@@ -35423,7 +35559,7 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
35423
35559
|
t.linksDropped += 1;
|
|
35424
35560
|
return;
|
|
35425
35561
|
}
|
|
35426
|
-
if (linksRequireToolSource && !t.toolResults.some((r) => r.includes(link.url))) {
|
|
35562
|
+
if (linksRequireToolSource && !t.toolResults.some((r) => r.includes(link.url) || link.sourceText !== void 0 && r.includes(link.sourceText))) {
|
|
35427
35563
|
t.linksDropped += 1;
|
|
35428
35564
|
return;
|
|
35429
35565
|
}
|
|
@@ -31205,6 +31205,34 @@ function isVoicethereAgentChild() {
|
|
|
31205
31205
|
}
|
|
31206
31206
|
var sessionExecutionContext = new AsyncLocalStorage();
|
|
31207
31207
|
var agentLogSessionContext = new AsyncLocalStorage();
|
|
31208
|
+
var CURRENT_SESSION_ID_GETTER_KEY = Symbol.for("voicethere.agent.currentSessionId");
|
|
31209
|
+
function currentHandlerSessionId() {
|
|
31210
|
+
const id = sessionExecutionContext.getStore()?.sessionId ?? agentLogSessionContext.getStore();
|
|
31211
|
+
return id ? id : void 0;
|
|
31212
|
+
}
|
|
31213
|
+
var previousSessionIdGetter;
|
|
31214
|
+
function stringOrUndefined(value) {
|
|
31215
|
+
return typeof value === "string" && value ? value : void 0;
|
|
31216
|
+
}
|
|
31217
|
+
function currentSessionIdGetter() {
|
|
31218
|
+
const own2 = currentHandlerSessionId();
|
|
31219
|
+
if (own2)
|
|
31220
|
+
return own2;
|
|
31221
|
+
try {
|
|
31222
|
+
return stringOrUndefined(previousSessionIdGetter?.());
|
|
31223
|
+
} catch {
|
|
31224
|
+
return void 0;
|
|
31225
|
+
}
|
|
31226
|
+
}
|
|
31227
|
+
function installCurrentSessionIdGetter() {
|
|
31228
|
+
const g = globalThis;
|
|
31229
|
+
const previous = g[CURRENT_SESSION_ID_GETTER_KEY];
|
|
31230
|
+
if (previous === currentSessionIdGetter)
|
|
31231
|
+
return;
|
|
31232
|
+
g[CURRENT_SESSION_ID_GETTER_KEY] = currentSessionIdGetter;
|
|
31233
|
+
previousSessionIdGetter = typeof previous === "function" ? previous : void 0;
|
|
31234
|
+
}
|
|
31235
|
+
installCurrentSessionIdGetter();
|
|
31208
31236
|
var inboundQueueAuthority = null;
|
|
31209
31237
|
var childUnhandledRejectionGuardInstalled = false;
|
|
31210
31238
|
function normalizeRejectionReason(reason) {
|
|
@@ -31858,7 +31886,7 @@ function sanitizeAgentLogFields(fields) {
|
|
|
31858
31886
|
}
|
|
31859
31887
|
}
|
|
31860
31888
|
function buildAgentLogPayload(level, message, fields, sessionId) {
|
|
31861
|
-
const resolvedSessionId = sessionId ??
|
|
31889
|
+
const resolvedSessionId = sessionId ?? currentHandlerSessionId();
|
|
31862
31890
|
const sanitizedFields = fields ? sanitizeAgentLogFields(fields) : void 0;
|
|
31863
31891
|
return {
|
|
31864
31892
|
type: "log",
|
|
@@ -34962,6 +34990,24 @@ var ConversationHistory = class {
|
|
|
34962
34990
|
|
|
34963
34991
|
// dist/llm/agent/link-extractor.js
|
|
34964
34992
|
var LINK_MARK = "\uE000";
|
|
34993
|
+
var BARE_DOMAIN_TLDS = /* @__PURE__ */ new Set([
|
|
34994
|
+
"com",
|
|
34995
|
+
"org",
|
|
34996
|
+
"net",
|
|
34997
|
+
"dev",
|
|
34998
|
+
"io",
|
|
34999
|
+
"ai",
|
|
35000
|
+
"app",
|
|
35001
|
+
"co",
|
|
35002
|
+
"cloud",
|
|
35003
|
+
"eu",
|
|
35004
|
+
"de",
|
|
35005
|
+
"uk",
|
|
35006
|
+
"us"
|
|
35007
|
+
]);
|
|
35008
|
+
var DOMAIN_RE = /^((?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+([a-z]{2,63}))(\/[^\s]*)?/i;
|
|
35009
|
+
var DOMAIN_PREFIX_RE = /^[a-z0-9][a-z0-9.-]*$/i;
|
|
35010
|
+
var ALNUM_RE = /[\p{L}\p{N}]/u;
|
|
34965
35011
|
var SCHEMES = ["https://", "http://"];
|
|
34966
35012
|
var START_RE = /\[|https?:\/\//i;
|
|
34967
35013
|
var BARE_RE = /^https?:\/\/\S*/i;
|
|
@@ -35027,6 +35073,85 @@ function hasHost(url2) {
|
|
|
35027
35073
|
var LinkExtractor = class {
|
|
35028
35074
|
buf = "";
|
|
35029
35075
|
links = [];
|
|
35076
|
+
/**
|
|
35077
|
+
* The emitted tail of the current word when it is made only of host
|
|
35078
|
+
* characters (`[a-z0-9.-]`), and the character before that word. A word
|
|
35079
|
+
* such as "voicethere" is spoken before ".dev" arrives; the lead lets the
|
|
35080
|
+
* domain still be recognised, so streaming gives the same result as one push.
|
|
35081
|
+
*/
|
|
35082
|
+
lead = "";
|
|
35083
|
+
leadPrev = "";
|
|
35084
|
+
consume(n) {
|
|
35085
|
+
const taken = this.buf.slice(0, n);
|
|
35086
|
+
this.buf = this.buf.slice(n);
|
|
35087
|
+
const s = this.lead + taken;
|
|
35088
|
+
let k = -1;
|
|
35089
|
+
for (let j = s.length - 1; j >= 0; j -= 1) {
|
|
35090
|
+
if (!/[a-z0-9.-]/i.test(s[j])) {
|
|
35091
|
+
k = j;
|
|
35092
|
+
break;
|
|
35093
|
+
}
|
|
35094
|
+
}
|
|
35095
|
+
if (k >= 0) {
|
|
35096
|
+
this.leadPrev = s[k];
|
|
35097
|
+
this.lead = s.slice(k + 1);
|
|
35098
|
+
} else {
|
|
35099
|
+
this.lead = s;
|
|
35100
|
+
}
|
|
35101
|
+
if (this.lead.length > MAX_HOLD) {
|
|
35102
|
+
this.lead = "";
|
|
35103
|
+
this.leadPrev = "x";
|
|
35104
|
+
}
|
|
35105
|
+
return taken;
|
|
35106
|
+
}
|
|
35107
|
+
/** After a link: the text now ends in a mark, so no word is open. */
|
|
35108
|
+
closeWord() {
|
|
35109
|
+
this.lead = "";
|
|
35110
|
+
this.leadPrev = LINK_MARK;
|
|
35111
|
+
}
|
|
35112
|
+
/** The first bare domain (or possible start of one at the tail) in the buffer. */
|
|
35113
|
+
scanDomain(final) {
|
|
35114
|
+
const off = this.lead.length;
|
|
35115
|
+
const ctx = this.lead + this.buf;
|
|
35116
|
+
for (let i = 0; i < ctx.length; i += 1) {
|
|
35117
|
+
if (!/[a-z0-9]/i.test(ctx[i]))
|
|
35118
|
+
continue;
|
|
35119
|
+
const before = i === 0 ? this.leadPrev : ctx[i - 1];
|
|
35120
|
+
if (!(before === "" || /[\s("']/.test(before)))
|
|
35121
|
+
continue;
|
|
35122
|
+
const rest = ctx.slice(i);
|
|
35123
|
+
const m = DOMAIN_RE.exec(rest);
|
|
35124
|
+
if (!m) {
|
|
35125
|
+
if (!final && rest.length <= MAX_HOLD && rest.includes(".") && DOMAIN_PREFIX_RE.test(rest)) {
|
|
35126
|
+
return { index: i, hold: true, off };
|
|
35127
|
+
}
|
|
35128
|
+
continue;
|
|
35129
|
+
}
|
|
35130
|
+
const host = m[1];
|
|
35131
|
+
const path2 = m[3] ?? "";
|
|
35132
|
+
const end = m[0].length;
|
|
35133
|
+
if (!final && end === rest.length && end <= MAX_HOLD) {
|
|
35134
|
+
return { index: i, hold: true, off };
|
|
35135
|
+
}
|
|
35136
|
+
const next = rest[end] ?? "";
|
|
35137
|
+
if (!final && !path2 && next === "." && end + 1 === rest.length) {
|
|
35138
|
+
return { index: i, hold: true, off };
|
|
35139
|
+
}
|
|
35140
|
+
if (!BARE_DOMAIN_TLDS.has(m[2].toLowerCase()))
|
|
35141
|
+
continue;
|
|
35142
|
+
if (!path2) {
|
|
35143
|
+
if (next && /[\p{L}\p{N}@_-]/u.test(next))
|
|
35144
|
+
continue;
|
|
35145
|
+
if (next === "." && ALNUM_RE.test(rest[end + 1] ?? ""))
|
|
35146
|
+
continue;
|
|
35147
|
+
}
|
|
35148
|
+
const { url: url2 } = trimUrl(host + path2);
|
|
35149
|
+
if (i < off && host.length < off - i)
|
|
35150
|
+
continue;
|
|
35151
|
+
return { index: i, hold: false, off, host, url: url2 };
|
|
35152
|
+
}
|
|
35153
|
+
return void 0;
|
|
35154
|
+
}
|
|
35030
35155
|
push(delta) {
|
|
35031
35156
|
this.buf += delta;
|
|
35032
35157
|
return this.drain(false);
|
|
@@ -35044,54 +35169,65 @@ var LinkExtractor = class {
|
|
|
35044
35169
|
this.links = [];
|
|
35045
35170
|
return all;
|
|
35046
35171
|
}
|
|
35047
|
-
add(url2, label) {
|
|
35172
|
+
add(url2, label, sourceText) {
|
|
35048
35173
|
const trimmed = label?.trim();
|
|
35049
35174
|
this.links.push({
|
|
35050
35175
|
url: url2,
|
|
35051
35176
|
...trimmed ? { label: trimmed } : {},
|
|
35052
|
-
secure: /^https:\/\//i.test(url2)
|
|
35177
|
+
secure: /^https:\/\//i.test(url2),
|
|
35178
|
+
...sourceText ? { sourceText } : {}
|
|
35053
35179
|
});
|
|
35054
35180
|
}
|
|
35055
35181
|
drain(final) {
|
|
35056
35182
|
let out = "";
|
|
35057
35183
|
for (; ; ) {
|
|
35058
35184
|
const m = START_RE.exec(this.buf);
|
|
35185
|
+
const d = this.scanDomain(final);
|
|
35186
|
+
if (d && (!m || Math.max(0, d.index - d.off) < m.index)) {
|
|
35187
|
+
const spoken = Math.max(0, d.off - d.index);
|
|
35188
|
+
out += this.consume(Math.max(0, d.index - d.off));
|
|
35189
|
+
if (d.hold)
|
|
35190
|
+
return out;
|
|
35191
|
+
this.add("https://" + d.url, d.host, d.url);
|
|
35192
|
+
this.consume(d.url.length - spoken);
|
|
35193
|
+
out += d.host.slice(spoken) + LINK_MARK;
|
|
35194
|
+
this.closeWord();
|
|
35195
|
+
continue;
|
|
35196
|
+
}
|
|
35059
35197
|
if (!m) {
|
|
35060
35198
|
const hold = final ? 0 : partialSchemeSuffix(this.buf);
|
|
35061
|
-
out += this.
|
|
35062
|
-
this.buf = this.buf.slice(this.buf.length - hold);
|
|
35199
|
+
out += this.consume(this.buf.length - hold);
|
|
35063
35200
|
return out;
|
|
35064
35201
|
}
|
|
35065
|
-
out += this.
|
|
35066
|
-
this.buf = this.buf.slice(m.index);
|
|
35202
|
+
out += this.consume(m.index);
|
|
35067
35203
|
if (this.buf[0] === "[") {
|
|
35068
35204
|
const md = MARKDOWN_RE.exec(this.buf);
|
|
35069
35205
|
if (md && hasHost(md[2])) {
|
|
35070
35206
|
this.add(md[2], md[1]);
|
|
35071
35207
|
out += `${md[1]}${LINK_MARK}`;
|
|
35072
|
-
this.
|
|
35208
|
+
this.consume(md[0].length);
|
|
35209
|
+
this.closeWord();
|
|
35073
35210
|
continue;
|
|
35074
35211
|
}
|
|
35075
35212
|
if (!final && this.buf.length <= MAX_HOLD && MARKDOWN_PREFIX_RE.test(this.buf)) {
|
|
35076
35213
|
return out;
|
|
35077
35214
|
}
|
|
35078
|
-
out +=
|
|
35079
|
-
this.buf = this.buf.slice(1);
|
|
35215
|
+
out += this.consume(1);
|
|
35080
35216
|
continue;
|
|
35081
35217
|
}
|
|
35082
35218
|
const bare = BARE_RE.exec(this.buf);
|
|
35083
35219
|
if (!final && bare[0].length === this.buf.length && this.buf.length <= MAX_HOLD) {
|
|
35084
35220
|
return out;
|
|
35085
35221
|
}
|
|
35086
|
-
const { url: url2
|
|
35222
|
+
const { url: url2 } = trimUrl(bare[0]);
|
|
35087
35223
|
if (!hasHost(url2)) {
|
|
35088
|
-
out += bare[0];
|
|
35089
|
-
this.buf = this.buf.slice(bare[0].length);
|
|
35224
|
+
out += this.consume(bare[0].length);
|
|
35090
35225
|
continue;
|
|
35091
35226
|
}
|
|
35092
35227
|
this.add(url2);
|
|
35093
35228
|
out += LINK_MARK;
|
|
35094
|
-
this.
|
|
35229
|
+
this.consume(url2.length);
|
|
35230
|
+
this.closeWord();
|
|
35095
35231
|
}
|
|
35096
35232
|
}
|
|
35097
35233
|
};
|
|
@@ -35423,7 +35559,7 @@ ${validated.errors.map((e) => `${e.path || "(root)"}: ${e.message}`).join("\n")}
|
|
|
35423
35559
|
t.linksDropped += 1;
|
|
35424
35560
|
return;
|
|
35425
35561
|
}
|
|
35426
|
-
if (linksRequireToolSource && !t.toolResults.some((r) => r.includes(link.url))) {
|
|
35562
|
+
if (linksRequireToolSource && !t.toolResults.some((r) => r.includes(link.url) || link.sourceText !== void 0 && r.includes(link.sourceText))) {
|
|
35427
35563
|
t.linksDropped += 1;
|
|
35428
35564
|
return;
|
|
35429
35565
|
}
|