@ouro.bot/cli 0.1.0-alpha.1086 → 0.1.0-alpha.1088
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/changelog.json +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/orientation-frame.js +9 -4
- package/dist/repertoire/ado-semantic.js +3 -2
- package/dist/repertoire/auth-required.js +21 -0
- package/dist/repertoire/guardrails.js +29 -3
- package/dist/repertoire/tools-github.js +2 -1
- package/dist/repertoire/tools-teams.js +7 -6
- package/dist/repertoire/tools.js +3 -1
- package/dist/senses/pipeline.js +1 -0
- package/dist/senses/teams.js +86 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1088",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Teams says exactly why OAuth sign-in can't start; typing stays visible during long tools"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1087",
|
|
12
|
+
"changes": [
|
|
13
|
+
"Owner's explicit asks are not refused: advisory correction hold for family; literal shell variables resolved"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1086",
|
|
6
18
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1088</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -162,6 +162,7 @@ function deriveSignals(currentUserSpeech, priorAssistantReferents, latestStructu
|
|
|
162
162
|
*/
|
|
163
163
|
const TERSE_CORRECTION_MAX_WORDS = 12;
|
|
164
164
|
const CORRECTION_HOLD_CLEARED_BY = "Resolve the referent (orientation_get lists the candidates) or restate the request as a standalone, correction-free instruction. The policy is recomputed from each user turn, so it never carries past this turn.";
|
|
165
|
+
const CORRECTION_HOLD_ADVISORY = "Advisory only: tools are not blocked. Read the referent first (orientation_get lists the candidates); if the request is clear, do it now without asking for confirmation. Ask only when two readings would lead to different actions.";
|
|
165
166
|
function countWords(text) {
|
|
166
167
|
return text.trim().split(/\s+/).filter(Boolean).length;
|
|
167
168
|
}
|
|
@@ -171,7 +172,7 @@ function correctionMarkerArmsHold(combinedSpeech, priorAssistantReferents, lates
|
|
|
171
172
|
// Long speech still holds when there is something concrete to disambiguate.
|
|
172
173
|
return priorAssistantReferents.length > 0 || Boolean(latestStructuredOutput);
|
|
173
174
|
}
|
|
174
|
-
function deriveActionPolicy(signals, combinedSpeech, priorAssistantReferents, latestStructuredOutput) {
|
|
175
|
+
function deriveActionPolicy(signals, combinedSpeech, priorAssistantReferents, latestStructuredOutput, familySpeaker) {
|
|
175
176
|
const holdSignals = signals.filter((signal) => signal !== "correction_marker"
|
|
176
177
|
|| correctionMarkerArmsHold(combinedSpeech, priorAssistantReferents, latestStructuredOutput));
|
|
177
178
|
if (holdSignals.length === 0)
|
|
@@ -186,7 +187,8 @@ function deriveActionPolicy(signals, combinedSpeech, priorAssistantReferents, la
|
|
|
186
187
|
: "Current user speech appears to correct or revise prior understanding; inspect orientation before mutating durable state.",
|
|
187
188
|
blockedMutationKinds: ["durable_state_write", "external_side_effect"],
|
|
188
189
|
...(triggeredBy ? { triggeredBy } : {}),
|
|
189
|
-
clearedBy: CORRECTION_HOLD_CLEARED_BY,
|
|
190
|
+
clearedBy: familySpeaker ? CORRECTION_HOLD_ADVISORY : CORRECTION_HOLD_CLEARED_BY,
|
|
191
|
+
...(familySpeaker ? { advisory: true } : {}),
|
|
190
192
|
};
|
|
191
193
|
}
|
|
192
194
|
// A reply names the message it answers. The sense stamps that message's text on the
|
|
@@ -233,7 +235,7 @@ function buildOrientationFrame(input) {
|
|
|
233
235
|
const latestStructuredOutput = candidateStructuredOutput && shouldAttachStructuredOutput(combinedSpeech, signals)
|
|
234
236
|
? candidateStructuredOutput
|
|
235
237
|
: undefined;
|
|
236
|
-
const actionPolicy = deriveActionPolicy(signals, combinedSpeech, priorAssistantReferents, candidateStructuredOutput);
|
|
238
|
+
const actionPolicy = deriveActionPolicy(signals, combinedSpeech, priorAssistantReferents, candidateStructuredOutput, input.familySpeaker === true);
|
|
237
239
|
const frame = {
|
|
238
240
|
schemaVersion: 1,
|
|
239
241
|
channel: input.channel,
|
|
@@ -270,6 +272,7 @@ function buildOrientationFrame(input) {
|
|
|
270
272
|
speechKind,
|
|
271
273
|
signals,
|
|
272
274
|
blockedMutationKinds: actionPolicy.blockedMutationKinds,
|
|
275
|
+
advisory: actionPolicy.advisory === true,
|
|
273
276
|
triggeredBy: actionPolicy.triggeredBy ?? null,
|
|
274
277
|
referentCount: priorAssistantReferents.length,
|
|
275
278
|
structuredOutput: candidateStructuredOutput?.id ?? null,
|
|
@@ -288,7 +291,9 @@ function renderOrientationFrame(frame) {
|
|
|
288
291
|
];
|
|
289
292
|
if (frame.actionPolicy.mode === "correction_hold") {
|
|
290
293
|
lines.push(`policy reason: ${frame.actionPolicy.reason}`);
|
|
291
|
-
lines.push(
|
|
294
|
+
lines.push(frame.actionPolicy.advisory
|
|
295
|
+
? `policy is advisory: nothing is blocked; check before ${frame.actionPolicy.blockedMutationKinds.join(", ")}`
|
|
296
|
+
: `policy blocks: ${frame.actionPolicy.blockedMutationKinds.join(", ")}`);
|
|
292
297
|
if (frame.actionPolicy.triggeredBy) {
|
|
293
298
|
lines.push(`policy trigger: correction marker "${frame.actionPolicy.triggeredBy}" in current user speech`);
|
|
294
299
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.adoSemanticToolDefinitions = void 0;
|
|
6
6
|
const runtime_1 = require("../nerves/runtime");
|
|
7
|
+
const auth_required_1 = require("./auth-required");
|
|
7
8
|
const ado_client_1 = require("./ado-client");
|
|
8
9
|
const ado_context_1 = require("./ado-context");
|
|
9
10
|
const ado_templates_1 = require("./ado-templates");
|
|
@@ -85,7 +86,7 @@ function buildReparentPatch(newParentId) {
|
|
|
85
86
|
}
|
|
86
87
|
async function checkAuth(ctx) {
|
|
87
88
|
if (!ctx?.adoToken) {
|
|
88
|
-
return "
|
|
89
|
+
return (0, auth_required_1.authRequired)(ctx, "ado", "I need access to Azure DevOps.");
|
|
89
90
|
}
|
|
90
91
|
return null;
|
|
91
92
|
}
|
|
@@ -238,7 +239,7 @@ exports.adoSemanticToolDefinitions = [
|
|
|
238
239
|
},
|
|
239
240
|
handler: async (args, ctx) => {
|
|
240
241
|
if (!ctx?.adoToken) {
|
|
241
|
-
return "
|
|
242
|
+
return (0, auth_required_1.authRequired)(ctx, "ado", "I need access to Azure DevOps.");
|
|
242
243
|
}
|
|
243
244
|
(0, runtime_1.emitNervesEvent)({
|
|
244
245
|
component: "repertoire",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authRequired = authRequired;
|
|
4
|
+
const runtime_1 = require("../nerves/runtime");
|
|
5
|
+
/**
|
|
6
|
+
* The result a tool returns when it has no token for an OAuth connection. When the sense already knows sign-in
|
|
7
|
+
* cannot start for that connection (for example the bot has no such OAuth connection), the result says exactly
|
|
8
|
+
* that instead of promising a sign-in prompt that will never appear.
|
|
9
|
+
*/
|
|
10
|
+
function authRequired(ctx, connection, need) {
|
|
11
|
+
const unavailable = ctx?.oauthUnavailable?.[connection];
|
|
12
|
+
(0, runtime_1.emitNervesEvent)({
|
|
13
|
+
component: "repertoire",
|
|
14
|
+
event: "repertoire.auth_required",
|
|
15
|
+
message: "tool needs an OAuth token it does not have",
|
|
16
|
+
meta: { connection, signinAvailable: !unavailable },
|
|
17
|
+
});
|
|
18
|
+
return unavailable
|
|
19
|
+
? `AUTH_UNAVAILABLE:${connection} -- ${need} Sign-in can't start here: ${unavailable}`
|
|
20
|
+
: `AUTH_REQUIRED:${connection} -- ${need} Please sign in when prompted.`;
|
|
21
|
+
}
|
|
@@ -271,10 +271,35 @@ const SEGMENT_OPERATORS = new Set(["&&", "||", ";", "|"]);
|
|
|
271
271
|
// shell could resolve it into one. A word like that counts as mentioning the folder when its directory part can match the folder's
|
|
272
272
|
// path, so the read-only rule below applies to the command.
|
|
273
273
|
const EXPANSION = "\u0001";
|
|
274
|
+
// Marks a word built from a same-command literal, so the word is still checked though it shows no glob or expansion.
|
|
275
|
+
const SUBSTITUTED = "\u0002";
|
|
274
276
|
const STABLE_VARIABLES = ["HOME", "TMPDIR", "USER"];
|
|
277
|
+
// Builtins that can set a variable other than by NAME=value; with any of them present no assignment is trusted.
|
|
278
|
+
const OTHER_VARIABLE_SETTERS = /(?:^|[\s;&|(])(?:read|for|select|declare|typeset|local|readonly|eval|getopts|mapfile|readarray|printf|source|\.|let|export\s+-|unset)(?=$|[\s;&|)])/;
|
|
279
|
+
/**
|
|
280
|
+
* Variables this command sets exactly once to a plain literal (`R=gim-home/CIT; gh pr view 1 -R $R`), with where the
|
|
281
|
+
* assignment ends. Uses after that point are that literal, so they need not count as "could be anything". Quoted values,
|
|
282
|
+
* expansions in the value, a second assignment to the same name or any other way of setting a variable leave it unknown.
|
|
283
|
+
*/
|
|
284
|
+
function literalAssignments(command) {
|
|
285
|
+
const found = new Map();
|
|
286
|
+
if (OTHER_VARIABLE_SETTERS.test(command))
|
|
287
|
+
return found;
|
|
288
|
+
for (const match of command.matchAll(/(?:^|[\s;&|(])(?:export\s+)?([A-Za-z_]\w*)=([^\s;&|()<>`$'"\\{}*?[\]~]+)(?=$|[\s;&|)])/g)) {
|
|
289
|
+
const name = match[1];
|
|
290
|
+
// Counts every NAME= in the command, including the one just matched.
|
|
291
|
+
if (command.match(new RegExp(`(?:^|[^\\w$])${name}=`, "g")).length === 1)
|
|
292
|
+
found.set(name, { value: match[2], end: match.index + match[0].length });
|
|
293
|
+
}
|
|
294
|
+
return found;
|
|
295
|
+
}
|
|
275
296
|
function neutraliseExpansions(command) {
|
|
276
|
-
|
|
297
|
+
const literals = literalAssignments(command);
|
|
298
|
+
return command.replace(/\$\([^)]*\)|`[^`]*`|\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)|\$\{[^}]*\}/g, (_match, braced, plain, offset) => {
|
|
277
299
|
const name = braced ?? plain;
|
|
300
|
+
const literal = name === undefined ? undefined : literals.get(name);
|
|
301
|
+
if (literal && offset >= literal.end)
|
|
302
|
+
return `${SUBSTITUTED}${literal.value}`;
|
|
278
303
|
if (name !== undefined && STABLE_VARIABLES.includes(name) && !new RegExp(`\\b${name}=`).test(command) && process.env[name])
|
|
279
304
|
return process.env[name];
|
|
280
305
|
return EXPANSION;
|
|
@@ -288,8 +313,9 @@ function wordPattern(word) {
|
|
|
288
313
|
return new RegExp(`^${source}$`);
|
|
289
314
|
}
|
|
290
315
|
function globOrExpansionCouldReach(command, folder, agentRoot) {
|
|
291
|
-
const tokens = neutraliseExpansions(command).split(/[\s<>|;&()'"]+/).filter((token) => /[*?[{\u0001]/.test(token));
|
|
292
|
-
return tokens.some((
|
|
316
|
+
const tokens = neutraliseExpansions(command).split(/[\s<>|;&()'"]+/).filter((token) => /[*?[{\u0001\u0002]/.test(token));
|
|
317
|
+
return tokens.some((marked) => {
|
|
318
|
+
const token = marked.replaceAll(SUBSTITUTED, "");
|
|
293
319
|
const word = token.startsWith("~") ? expandHome(token) : token;
|
|
294
320
|
const absolute = word.startsWith("/") || word.startsWith(EXPANSION) ? word : `${agentRoot}/${word}`;
|
|
295
321
|
const dir = absolute.slice(0, Math.max(absolute.lastIndexOf("/"), 0));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.githubToolDefinitions = void 0;
|
|
4
|
+
const auth_required_1 = require("./auth-required");
|
|
4
5
|
const github_client_1 = require("./github-client");
|
|
5
6
|
const runtime_1 = require("../nerves/runtime");
|
|
6
7
|
exports.githubToolDefinitions = [
|
|
@@ -29,7 +30,7 @@ exports.githubToolDefinitions = [
|
|
|
29
30
|
meta: {},
|
|
30
31
|
});
|
|
31
32
|
if (!ctx?.githubToken) {
|
|
32
|
-
return "
|
|
33
|
+
return (0, auth_required_1.authRequired)(ctx, "github", "I need access to GitHub.");
|
|
33
34
|
}
|
|
34
35
|
const owner = "ourostack";
|
|
35
36
|
const repo = "ouroboros";
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.teamsToolDefinitions = void 0;
|
|
7
|
+
const auth_required_1 = require("./auth-required");
|
|
7
8
|
const graph_client_1 = require("./graph-client");
|
|
8
9
|
const ado_client_1 = require("./ado-client");
|
|
9
10
|
const graph_endpoints_json_1 = __importDefault(require("./data/graph-endpoints.json"));
|
|
@@ -31,7 +32,7 @@ exports.teamsToolDefinitions = [
|
|
|
31
32
|
},
|
|
32
33
|
handler: async (args, ctx) => {
|
|
33
34
|
if (!ctx?.graphToken) {
|
|
34
|
-
return "
|
|
35
|
+
return (0, auth_required_1.authRequired)(ctx, "graph", "I need access to Microsoft Graph.");
|
|
35
36
|
}
|
|
36
37
|
return (0, graph_client_1.graphRequest)(ctx.graphToken, "GET", args.path);
|
|
37
38
|
},
|
|
@@ -57,7 +58,7 @@ exports.teamsToolDefinitions = [
|
|
|
57
58
|
},
|
|
58
59
|
handler: async (args, ctx) => {
|
|
59
60
|
if (!ctx?.graphToken) {
|
|
60
|
-
return "
|
|
61
|
+
return (0, auth_required_1.authRequired)(ctx, "graph", "I need access to Microsoft Graph.");
|
|
61
62
|
}
|
|
62
63
|
if (!MUTATE_METHODS.includes(args.method)) {
|
|
63
64
|
return `Invalid method "${args.method}". Must be one of: ${MUTATE_METHODS.join(", ")}`;
|
|
@@ -90,7 +91,7 @@ exports.teamsToolDefinitions = [
|
|
|
90
91
|
},
|
|
91
92
|
handler: async (args, ctx) => {
|
|
92
93
|
if (!ctx?.adoToken) {
|
|
93
|
-
return "
|
|
94
|
+
return (0, auth_required_1.authRequired)(ctx, "ado", "I need access to Azure DevOps.");
|
|
94
95
|
}
|
|
95
96
|
const method = args.method || "GET";
|
|
96
97
|
return (0, ado_client_1.adoRequest)(ctx.adoToken, method, args.organization, args.path, args.body, args.host);
|
|
@@ -119,7 +120,7 @@ exports.teamsToolDefinitions = [
|
|
|
119
120
|
},
|
|
120
121
|
handler: async (args, ctx) => {
|
|
121
122
|
if (!ctx?.adoToken) {
|
|
122
|
-
return "
|
|
123
|
+
return (0, auth_required_1.authRequired)(ctx, "ado", "I need access to Azure DevOps.");
|
|
123
124
|
}
|
|
124
125
|
if (!MUTATE_METHODS.includes(args.method)) {
|
|
125
126
|
return `Invalid method "${args.method}". Must be one of: ${MUTATE_METHODS.join(", ")}`;
|
|
@@ -142,7 +143,7 @@ exports.teamsToolDefinitions = [
|
|
|
142
143
|
},
|
|
143
144
|
handler: async (_args, ctx) => {
|
|
144
145
|
if (!ctx?.graphToken) {
|
|
145
|
-
return "
|
|
146
|
+
return (0, auth_required_1.authRequired)(ctx, "graph", "I need access to your Microsoft 365 profile.");
|
|
146
147
|
}
|
|
147
148
|
return (0, graph_client_1.getProfile)(ctx.graphToken);
|
|
148
149
|
},
|
|
@@ -166,7 +167,7 @@ exports.teamsToolDefinitions = [
|
|
|
166
167
|
},
|
|
167
168
|
handler: async (args, ctx) => {
|
|
168
169
|
if (!ctx?.adoToken) {
|
|
169
|
-
return "
|
|
170
|
+
return (0, auth_required_1.authRequired)(ctx, "ado", "I need access to your Azure DevOps account.");
|
|
170
171
|
}
|
|
171
172
|
let org = args.organization;
|
|
172
173
|
if (!org) {
|
package/dist/repertoire/tools.js
CHANGED
|
@@ -429,7 +429,9 @@ async function preflightToolCall(name, args, ctx) {
|
|
|
429
429
|
return { kind: "ready" };
|
|
430
430
|
const risk = riskProfileForTool(def, name, args);
|
|
431
431
|
const orientationPolicy = ctx?.orientationFrame?.actionPolicy;
|
|
432
|
-
|
|
432
|
+
// A family speaker's hold is advice; a relationship-scoped turn (Sanctuary) always enforces it.
|
|
433
|
+
if (orientationPolicy?.mode === "correction_hold" && (!orientationPolicy.advisory || ctx?.relationshipAuthorization)
|
|
434
|
+
&& orientationPolicyBlocks(risk, orientationPolicy.blockedMutationKinds)) {
|
|
433
435
|
(0, runtime_1.emitNervesEvent)({
|
|
434
436
|
level: "warn", event: "tool.orientation_hold_block", component: "tools",
|
|
435
437
|
message: "orientation hold blocked high-risk tool execution",
|
package/dist/senses/pipeline.js
CHANGED
|
@@ -913,6 +913,7 @@ async function handleInboundTurnExclusive(input) {
|
|
|
913
913
|
messages: sessionMessages,
|
|
914
914
|
currentUserMessages,
|
|
915
915
|
structuredOutputs: session.structuredOutputs ?? [],
|
|
916
|
+
familySpeaker: resolvedContext.friend.trustLevel === "family",
|
|
916
917
|
})
|
|
917
918
|
: undefined);
|
|
918
919
|
// Step 4b: Continuity pipeline — derive tempo, build start-of-turn packet, snapshot obligations
|
package/dist/senses/teams.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.DEFAULT_FLUSH_INTERVAL_MS = void 0;
|
|
36
|
+
exports.TYPING_KEEPALIVE_MS = exports.DEFAULT_FLUSH_INTERVAL_MS = void 0;
|
|
37
37
|
exports.aiLabelEntities = aiLabelEntities;
|
|
38
38
|
exports.stripMentions = stripMentions;
|
|
39
39
|
exports.splitMessage = splitMessage;
|
|
@@ -44,6 +44,10 @@ exports.createTeamsCallbacks = createTeamsCallbacks;
|
|
|
44
44
|
exports.reasoningStatus = reasoningStatus;
|
|
45
45
|
exports.withConversationLock = withConversationLock;
|
|
46
46
|
exports.parseTeamsQuotedReply = parseTeamsQuotedReply;
|
|
47
|
+
exports.oauthSigninUnavailableReason = oauthSigninUnavailableReason;
|
|
48
|
+
exports.recordOAuthSigninFailure = recordOAuthSigninFailure;
|
|
49
|
+
exports.oauthSigninUnavailableNotice = oauthSigninUnavailableNotice;
|
|
50
|
+
exports.resetOAuthSigninFailures = resetOAuthSigninFailures;
|
|
47
51
|
exports.handleTeamsMessage = handleTeamsMessage;
|
|
48
52
|
exports.createTeamsSdkLogger = createTeamsSdkLogger;
|
|
49
53
|
exports.sendProactiveTeamsMessageToSession = sendProactiveTeamsMessageToSession;
|
|
@@ -121,6 +125,9 @@ const RECOVERY_CHUNK_SIZE = 4000;
|
|
|
121
125
|
// At 1000ms (1 req/sec), we stay at the Teams throttle floor while keeping the
|
|
122
126
|
// stream alive well within the 15s Copilot timeout. Tune up if 429s observed.
|
|
123
127
|
exports.DEFAULT_FLUSH_INTERVAL_MS = 1_000;
|
|
128
|
+
// Teams shows a typing indicator for only a few seconds. While a tool runs nothing else refreshes it, so a long
|
|
129
|
+
// shell or session call looked like silence; this repeats the current status until the tool ends.
|
|
130
|
+
exports.TYPING_KEEPALIVE_MS = 3_000;
|
|
124
131
|
// Split text into chunks that fit within maxLen, breaking at paragraph
|
|
125
132
|
// boundaries (\n\n), then line boundaries (\n), then word boundaries.
|
|
126
133
|
// Never loses content — all text is preserved across chunks.
|
|
@@ -219,6 +226,22 @@ function createTeamsCallbacks(stream, controller, sendMessage, options) {
|
|
|
219
226
|
let lastPhrase = "";
|
|
220
227
|
let flushTimer = null;
|
|
221
228
|
const flushInterval = options?.flushIntervalMs ?? exports.DEFAULT_FLUSH_INTERVAL_MS;
|
|
229
|
+
let keepaliveTimer = null;
|
|
230
|
+
let toolsRunning = 0;
|
|
231
|
+
let toolStatus = "";
|
|
232
|
+
const keepaliveInterval = options?.typingKeepaliveMs ?? exports.TYPING_KEEPALIVE_MS;
|
|
233
|
+
function startTypingKeepalive() {
|
|
234
|
+
if (keepaliveTimer)
|
|
235
|
+
return;
|
|
236
|
+
keepaliveTimer = setInterval(() => safeUpdate(toolStatus || "working..."), keepaliveInterval);
|
|
237
|
+
}
|
|
238
|
+
function stopTypingKeepalive() {
|
|
239
|
+
toolsRunning = 0;
|
|
240
|
+
if (keepaliveTimer) {
|
|
241
|
+
clearInterval(keepaliveTimer);
|
|
242
|
+
keepaliveTimer = null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
222
245
|
// The SDK merges every chunk's entities into the final message, and Teams rejects a final
|
|
223
246
|
// message with more than one root message entity (400 BadSyntax), so only the first chunk
|
|
224
247
|
// carries the AI label.
|
|
@@ -271,12 +294,14 @@ function createTeamsCallbacks(stream, controller, sendMessage, options) {
|
|
|
271
294
|
stopped = true;
|
|
272
295
|
stopPhraseRotation();
|
|
273
296
|
stopFlushTimer();
|
|
297
|
+
stopTypingKeepalive();
|
|
274
298
|
controller.abort();
|
|
275
299
|
}
|
|
276
300
|
// Clean up timers when the controller is aborted externally
|
|
277
301
|
controller.signal.addEventListener("abort", () => {
|
|
278
302
|
stopPhraseRotation();
|
|
279
303
|
stopFlushTimer();
|
|
304
|
+
stopTypingKeepalive();
|
|
280
305
|
});
|
|
281
306
|
// Handle the result of a stream call: if it returns a Promise (the Teams SDK
|
|
282
307
|
// does async HTTP under the hood even though the interface types it as void),
|
|
@@ -545,7 +570,7 @@ function createTeamsCallbacks(stream, controller, sendMessage, options) {
|
|
|
545
570
|
},
|
|
546
571
|
...(() => {
|
|
547
572
|
const toolCbs = (0, tool_activity_callbacks_1.createToolActivityCallbacks)({
|
|
548
|
-
onDescription: (text) => safeUpdate(text),
|
|
573
|
+
onDescription: (text) => { toolStatus = text; safeUpdate(text); },
|
|
549
574
|
/* v8 ignore next -- onResult only called in debug mode; tested via tool-activity-callbacks.test.ts @preserve */
|
|
550
575
|
onResult: (text) => safeUpdate(text),
|
|
551
576
|
/* v8 ignore next -- onFailure tested via onToolEnd failure test @preserve */
|
|
@@ -567,6 +592,8 @@ function createTeamsCallbacks(stream, controller, sendMessage, options) {
|
|
|
567
592
|
flushTextBuffer();
|
|
568
593
|
toolCbs.onToolStart(name, args);
|
|
569
594
|
hadToolRun = true;
|
|
595
|
+
toolsRunning++;
|
|
596
|
+
startTypingKeepalive();
|
|
570
597
|
},
|
|
571
598
|
onToolEnd: (name, summary, success) => {
|
|
572
599
|
// speak is flow-control: skip phrase-rotation stop and tool-activity end
|
|
@@ -577,6 +604,9 @@ function createTeamsCallbacks(stream, controller, sendMessage, options) {
|
|
|
577
604
|
return;
|
|
578
605
|
stopPhraseRotation();
|
|
579
606
|
toolCbs.onToolEnd(name, summary, success);
|
|
607
|
+
toolsRunning = Math.max(0, toolsRunning - 1);
|
|
608
|
+
if (toolsRunning === 0)
|
|
609
|
+
stopTypingKeepalive();
|
|
580
610
|
},
|
|
581
611
|
};
|
|
582
612
|
})(),
|
|
@@ -604,6 +634,7 @@ function createTeamsCallbacks(stream, controller, sendMessage, options) {
|
|
|
604
634
|
flush: async () => {
|
|
605
635
|
stopFlushTimer();
|
|
606
636
|
stopPhraseRotation();
|
|
637
|
+
stopTypingKeepalive();
|
|
607
638
|
if (textBuffer) {
|
|
608
639
|
// Bypass MIN_INITIAL_CHARS threshold — flush delivers all remaining content
|
|
609
640
|
firstContentEmitted = true;
|
|
@@ -785,6 +816,44 @@ function parseTeamsQuotedReply(attachments, ids) {
|
|
|
785
816
|
}
|
|
786
817
|
return undefined;
|
|
787
818
|
}
|
|
819
|
+
const OAUTH_SERVICE_LABELS = { graph: "Microsoft Graph", ado: "Azure DevOps", github: "GitHub" };
|
|
820
|
+
const OAUTH_UNAVAILABLE_TTL_MS = 60 * 60 * 1000;
|
|
821
|
+
// Sign-ins that could not start, by OAuth connection name. Kept for an hour so every turn in between can say why
|
|
822
|
+
// instead of promising a prompt, and so the person hears about it once, not on every turn.
|
|
823
|
+
const oauthSigninUnavailable = new Map();
|
|
824
|
+
/** Why sign-in for this connection can't start, when a recent attempt showed it; undefined when it may work. */
|
|
825
|
+
function oauthSigninUnavailableReason(connectionName, now = Date.now()) {
|
|
826
|
+
const entry = oauthSigninUnavailable.get(connectionName);
|
|
827
|
+
if (!entry)
|
|
828
|
+
return undefined;
|
|
829
|
+
if (entry.until <= now) {
|
|
830
|
+
oauthSigninUnavailable.delete(connectionName);
|
|
831
|
+
return undefined;
|
|
832
|
+
}
|
|
833
|
+
return entry.reason;
|
|
834
|
+
}
|
|
835
|
+
/** Records a sign-in that failed to start and returns the reason in words the person can act on. */
|
|
836
|
+
function recordOAuthSigninFailure(connectionName, error, now = Date.now()) {
|
|
837
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
838
|
+
const reason = /status code 400\b/.test(message)
|
|
839
|
+
? `Bot Service rejected the sign-in request (HTTP 400). The usual cause is that this bot registration has no OAuth connection named "${connectionName}"; it has to be added on the Azure Bot before sign-in can work.`
|
|
840
|
+
: `the sign-in request failed (${message.slice(0, 160)}).`;
|
|
841
|
+
oauthSigninUnavailable.set(connectionName, { reason, until: now + OAUTH_UNAVAILABLE_TTL_MS });
|
|
842
|
+
(0, runtime_1.emitNervesEvent)({
|
|
843
|
+
level: "warn", component: "channels", event: "channel.oauth_signin_unavailable",
|
|
844
|
+
message: "OAuth sign-in cannot start for this connection", meta: { connectionName, reason },
|
|
845
|
+
});
|
|
846
|
+
return reason;
|
|
847
|
+
}
|
|
848
|
+
/** The one-line notice the person gets when a sign-in they needed could not start. */
|
|
849
|
+
function oauthSigninUnavailableNotice(service, reason) {
|
|
850
|
+
const label = OAUTH_SERVICE_LABELS[service] ?? service;
|
|
851
|
+
return `I couldn't start the ${label} sign-in, so I can't use ${label} here: ${reason}`;
|
|
852
|
+
}
|
|
853
|
+
/** For tests: forget every recorded sign-in failure. */
|
|
854
|
+
function resetOAuthSigninFailures() {
|
|
855
|
+
oauthSigninUnavailable.clear();
|
|
856
|
+
}
|
|
788
857
|
function reportTeamsRequest(stage, conversationId, context, details = {}) {
|
|
789
858
|
if (!context?.inboundActivityId)
|
|
790
859
|
return;
|
|
@@ -892,6 +961,7 @@ async function handleTeamsMessage(text, stream, conversationId, teamsContext, se
|
|
|
892
961
|
graphToken: teamsContext.graphToken,
|
|
893
962
|
adoToken: teamsContext.adoToken,
|
|
894
963
|
githubToken: teamsContext.githubToken,
|
|
964
|
+
...(teamsContext.oauthUnavailable ? { oauthUnavailable: teamsContext.oauthUnavailable } : {}),
|
|
895
965
|
signin: teamsContext.signin,
|
|
896
966
|
summarize: (0, core_1.createSummarize)("human"),
|
|
897
967
|
tenantId: teamsContext.tenantId,
|
|
@@ -1420,6 +1490,10 @@ function registerBotHandlers(app, label) {
|
|
|
1420
1490
|
}
|
|
1421
1491
|
catch { /* no token yet — tool handler will trigger signin */ }
|
|
1422
1492
|
(0, runtime_1.emitNervesEvent)({ level: "info", event: "channel.token_status", component: "channels", message: "oauth token availability", meta: { graph: !!graphToken, ado: !!adoToken, github: !!githubToken, tenantId } });
|
|
1493
|
+
const unavailableEntries = [["graph", tenantOAuth.graphConnectionName], ["ado", tenantOAuth.adoConnectionName], ["github", tenantOAuth.githubConnectionName]]
|
|
1494
|
+
.map(([service, cn]) => [service, oauthSigninUnavailableReason(cn)])
|
|
1495
|
+
.filter((entry) => entry[1] !== undefined);
|
|
1496
|
+
const oauthUnavailable = unavailableEntries.length > 0 ? Object.fromEntries(unavailableEntries) : undefined;
|
|
1423
1497
|
const teamsContext = {
|
|
1424
1498
|
inboundActivityId: activity.id,
|
|
1425
1499
|
replyToId: activity.replyToId,
|
|
@@ -1427,7 +1501,11 @@ function registerBotHandlers(app, label) {
|
|
|
1427
1501
|
graphToken,
|
|
1428
1502
|
adoToken,
|
|
1429
1503
|
githubToken,
|
|
1504
|
+
...(oauthUnavailable ? { oauthUnavailable } : {}),
|
|
1430
1505
|
signin: async (cn) => {
|
|
1506
|
+
// Already known not to start: don't send the person another card that can't appear.
|
|
1507
|
+
if (oauthSigninUnavailableReason(cn))
|
|
1508
|
+
return undefined;
|
|
1431
1509
|
try {
|
|
1432
1510
|
const result = await signin({ connectionName: cn });
|
|
1433
1511
|
(0, runtime_1.emitNervesEvent)({ level: "info", event: "channel.signin_result", component: "channels", message: `signin(${cn}): ${result ? "token received" : "no token"}`, meta: { connectionName: cn, hasToken: !!result } });
|
|
@@ -1436,6 +1514,12 @@ function registerBotHandlers(app, label) {
|
|
|
1436
1514
|
catch (e) {
|
|
1437
1515
|
const msg = e instanceof Error ? e.message : String(e);
|
|
1438
1516
|
(0, runtime_1.emitNervesEvent)({ level: "error", event: "channel.signin_error", component: "channels", message: `signin(${cn}) failed`, meta: { connectionName: cn, reason: msg.slice(0, 100) } });
|
|
1517
|
+
const reason = recordOAuthSigninFailure(cn, e);
|
|
1518
|
+
const service = Object.entries(tenantOAuth).find(([, name]) => name === cn)?.[0]?.replace(/ConnectionName$/, "") ?? cn;
|
|
1519
|
+
try {
|
|
1520
|
+
await sendText(oauthSigninUnavailableNotice(service, reason));
|
|
1521
|
+
}
|
|
1522
|
+
catch { /* the failure is already logged */ }
|
|
1439
1523
|
return undefined;
|
|
1440
1524
|
}
|
|
1441
1525
|
},
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1088",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1088",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
12
12
|
"@ouro.bot/friends": "0.1.0-alpha.18",
|